MCPcopy Create free account
hub / github.com/bitpay/bitcore / joinWallet

Method joinWallet

packages/bitcore-wallet-client/src/lib/api.ts:1108–1180  ·  view source on GitHub ↗

* Join an existent wallet

(
    /** The wallet join secret */
    secret: string,
    /** The copayer name */
    copayerName: string,
    opts?: {
      /** The expected coin for this wallet. Usually same as `chain` except on L2 chains when the base currency is different. Default: btc */
      coin?: string;
      /** The expected chain for this wallet (e.g. btc, bch, eth, arb). Default: btc */
      chain?: string;
      /** Simulate wallet join. Default: false */
      dryRun?: boolean;
    },
    /**
     * @deprecated
     */
    cb?: (err?: Error, wallet?: any) => void
  )

Source from the content-addressed store, hash-verified

1106 * Join an existent wallet
1107 */
1108 async joinWallet(
1109 /** The wallet join secret */
1110 secret: string,
1111 /** The copayer name */
1112 copayerName: string,
1113 opts?: {
1114 /** The expected coin for this wallet. Usually same as `chain` except on L2 chains when the base currency is different. Default: btc */
1115 coin?: string;
1116 /** The expected chain for this wallet (e.g. btc, bch, eth, arb). Default: btc */
1117 chain?: string;
1118 /** Simulate wallet join. Default: false */
1119 dryRun?: boolean;
1120 },
1121 /**
1122 * @deprecated
1123 */
1124 cb?: (err?: Error, wallet?: any) => void
1125 ) {
1126 if (cb) {
1127 log.warn('DEPRECATED: joinWallet will remove callback support in the future.');
1128 }
1129
1130 try {
1131 if (!this._checkKeyDerivation()) throw new Error('Cannot join wallet');
1132
1133 opts = opts || {};
1134
1135 const coin = opts.coin || 'btc';
1136 const chain = opts.chain || coin;
1137
1138 if (!Constants.CHAINS.includes(chain))
1139 throw new Error('Invalid chain');
1140
1141 const secretData = API.parseSecret(secret);
1142
1143 if (!this.credentials) {
1144 throw new Error('Import credentials first with setCredentials()');
1145 }
1146
1147 this.credentials.addWalletPrivateKey(secretData.walletPrivKey.toString());
1148 const wallet = await this._doJoinWallet(
1149 secretData.walletId,
1150 secretData.walletPrivKey,
1151 this.credentials.xPubKey,
1152 this.credentials.requestPubKey,
1153 copayerName,
1154 {
1155 coin,
1156 chain,
1157 dryRun: !!opts.dryRun
1158 }
1159 );
1160 if (!opts.dryRun) {
1161 this.credentials.addWalletInfo(
1162 wallet.id,
1163 wallet.name,
1164 wallet.m,
1165 wallet.n,

Callers 4

createMethod · 0.45
cli.tsFile · 0.45
api.test.tsFile · 0.45
helpers.tsFile · 0.45

Calls 9

_checkKeyDerivationMethod · 0.95
_doJoinWalletMethod · 0.95
warnMethod · 0.80
parseSecretMethod · 0.80
addWalletPrivateKeyMethod · 0.80
addWalletInfoMethod · 0.80
isNativeSegwitMethod · 0.80
getSegwitVersionMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected