|
|
@ -203,7 +203,7 @@ WalletService.prototype._runLocked = function(cb, task) { |
|
|
|
* @param {number} opts.n - Total copayers. |
|
|
|
* @param {string} opts.pubKey - Public key to verify copayers joining have access to the wallet secret. |
|
|
|
* @param {string} [opts.network = 'livenet'] - The Bitcoin network for this wallet. |
|
|
|
* @param {string} [opts.derivationStrategy = 'BIP45'] - Strategy used for address derivation (BIP44, BIP45). |
|
|
|
* @param {string} [opts.supportBIP44 = false] - Client supports BIP44 paths for 1-of-1 wallets. |
|
|
|
*/ |
|
|
|
WalletService.prototype.createWallet = function(opts, cb) { |
|
|
|
var self = this, |
|
|
@ -220,9 +220,8 @@ WalletService.prototype.createWallet = function(opts, cb) { |
|
|
|
if (!_.contains(['livenet', 'testnet'], opts.network)) |
|
|
|
return cb(new ClientError('Invalid network')); |
|
|
|
|
|
|
|
opts.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45; |
|
|
|
if (!_.contains(_.values(WalletUtils.DERIVATION_STRATEGIES), opts.derivationStrategy)) |
|
|
|
return cb(new ClientError('Invalid address derivation strategy')); |
|
|
|
var derivationStrategy = (opts.n == 1 && opts.supportBIP44) ? |
|
|
|
WalletUtils.DERIVATION_STRATEGIES.BIP44 : WalletUtils.DERIVATION_STRATEGIES.BIP45; |
|
|
|
|
|
|
|
try { |
|
|
|
pubKey = new PublicKey.fromString(opts.pubKey); |
|
|
@ -250,7 +249,7 @@ WalletService.prototype.createWallet = function(opts, cb) { |
|
|
|
n: opts.n, |
|
|
|
network: opts.network, |
|
|
|
pubKey: pubKey.toString(), |
|
|
|
derivationStrategy: opts.derivationStrategy, |
|
|
|
derivationStrategy: derivationStrategy, |
|
|
|
}); |
|
|
|
self.storage.storeWallet(wallet, function(err) { |
|
|
|
log.debug('Wallet created', wallet.id, opts.network); |
|
|
@ -417,7 +416,7 @@ WalletService.prototype._addCopayerToWallet = function(wallet, opts, cb) { |
|
|
|
requestPubKey: opts.requestPubKey, |
|
|
|
signature: opts.copayerSignature, |
|
|
|
customData: opts.customData, |
|
|
|
derivationStrategy: opts.derivationStrategy, |
|
|
|
derivationStrategy: wallet.derivationStrategy, |
|
|
|
}); |
|
|
|
self.storage.fetchCopayerLookup(copayer.id, function(err, res) { |
|
|
|
if (err) return cb(err); |
|
|
@ -563,7 +562,6 @@ WalletService.prototype._clientSupportsTXPv2 = function() { |
|
|
|
* @param {string} opts.requestPubKey - Public Key used to check requests from this copayer. |
|
|
|
* @param {string} opts.copayerSignature - S(name|xPubKey|requestPubKey). Used by other copayers to verify that the copayer joining knows the wallet secret. |
|
|
|
* @param {string} opts.customData - (optional) Custom data for this copayer. |
|
|
|
* @param {string} [opts.derivationStrategy = 'BIP45'] - Strategy used for address derivation (BIP44, BIP45). |
|
|
|
*/ |
|
|
|
WalletService.prototype.joinWallet = function(opts, cb) { |
|
|
|
var self = this; |
|
|
@ -574,21 +572,11 @@ WalletService.prototype.joinWallet = function(opts, cb) { |
|
|
|
if (_.isEmpty(opts.name)) |
|
|
|
return cb(new ClientError('Invalid copayer name')); |
|
|
|
|
|
|
|
opts.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45; |
|
|
|
if (!_.contains(_.values(WalletUtils.DERIVATION_STRATEGIES), opts.derivationStrategy)) |
|
|
|
return cb(new ClientError('Invalid address derivation strategy')); |
|
|
|
|
|
|
|
self.walletId = opts.walletId; |
|
|
|
self._runLocked(cb, function(cb) { |
|
|
|
self.storage.fetchWallet(opts.walletId, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (!wallet) return cb(Errors.WALLET_NOT_FOUND); |
|
|
|
if (wallet.addressManager.derivationStrategy != opts.derivationStrategy) { |
|
|
|
if (!self._clientSupportsBIP44()) { |
|
|
|
return cb(new ClientError(Errors.codes.UPGRADE_NEEDED, 'To join this wallet, you need to upgrade your client app.')); |
|
|
|
} |
|
|
|
return cb(new ClientError('Incompatible address derivation strategy')); |
|
|
|
} |
|
|
|
|
|
|
|
var hash = WalletUtils.getCopayerHash(opts.name, opts.xPubKey, opts.requestPubKey); |
|
|
|
if (!self._verifySignature(hash, opts.copayerSignature, wallet.pubKey)) { |
|
|
@ -1222,7 +1210,7 @@ WalletService.prototype.createTx = function(opts, cb) { |
|
|
|
requiredRejections: Math.min(wallet.m, wallet.n - wallet.m + 1), |
|
|
|
walletN: wallet.n, |
|
|
|
excludeUnconfirmedUtxos: !!opts.excludeUnconfirmedUtxos, |
|
|
|
derivationStrategy: wallet.addressManager.derivationStrategy, |
|
|
|
derivationStrategy: wallet.derivationStrategy, |
|
|
|
customData: opts.customData |
|
|
|
}; |
|
|
|
|
|
|
|