allow copayers with same xpub for different coins
This commit is contained in:
parent
ba6fbab240
commit
5fbb262ace
|
@ -10,12 +10,16 @@ var Address = require('./address');
|
|||
var AddressManager = require('./addressmanager');
|
||||
var Bitcore = require('bitcore-lib');
|
||||
|
||||
var Constants = require('../common/constants');
|
||||
var Common = require('../common');
|
||||
var Constants = Common.Constants,
|
||||
Defaults = Common.Defaults,
|
||||
Utils = Common.Utils;
|
||||
|
||||
function Copayer() {};
|
||||
|
||||
Copayer._xPubToCopayerId = function(xpub) {
|
||||
var hash = sjcl.hash.sha256.hash(xpub);
|
||||
Copayer._xPubToCopayerId = function(coin, xpub) {
|
||||
var str = coin == Defaults.COIN ? xpub : coin + xpub;
|
||||
var hash = sjcl.hash.sha256.hash(str);
|
||||
return sjcl.codec.hex.fromBits(hash);
|
||||
};
|
||||
|
||||
|
@ -25,14 +29,17 @@ Copayer.create = function(opts) {
|
|||
.checkArgument(opts.requestPubKey, 'Missing copayer request public key')
|
||||
.checkArgument(opts.signature, 'Missing copayer request public key signature');
|
||||
|
||||
$.checkArgument(Utils.checkValueInCollection(opts.coin, Constants.COINS));
|
||||
|
||||
opts.copayerIndex = opts.copayerIndex || 0;
|
||||
|
||||
var x = new Copayer();
|
||||
|
||||
x.version = 2;
|
||||
x.createdOn = Math.floor(Date.now() / 1000);
|
||||
x.coin = opts.coin;
|
||||
x.xPubKey = opts.xPubKey;
|
||||
x.id = Copayer._xPubToCopayerId(x.xPubKey);
|
||||
x.id = Copayer._xPubToCopayerId(opts.coin, x.xPubKey);
|
||||
x.name = opts.name;
|
||||
x.requestPubKey = opts.requestPubKey;
|
||||
x.signature = opts.signature;
|
||||
|
@ -59,6 +66,7 @@ Copayer.fromObj = function(obj) {
|
|||
|
||||
x.version = obj.version;
|
||||
x.createdOn = obj.createdOn;
|
||||
x.coin = obj.coin || Defaults.COIN;
|
||||
x.id = obj.id;
|
||||
x.name = obj.name;
|
||||
x.xPubKey = obj.xPubKey;
|
||||
|
|
|
@ -112,6 +112,7 @@ Wallet.prototype._updatePublicKeyRing = function() {
|
|||
};
|
||||
|
||||
Wallet.prototype.addCopayer = function(copayer) {
|
||||
$.checkState(copayer.coin == this.coin);
|
||||
|
||||
this.copayers.push(copayer);
|
||||
if (this.copayers.length < this.n) return;
|
||||
|
|
|
@ -641,6 +641,7 @@ WalletService.prototype._addCopayerToWallet = function(wallet, opts, cb) {
|
|||
var self = this;
|
||||
|
||||
var copayer = Model.Copayer.create({
|
||||
coin: wallet.coin,
|
||||
name: opts.name,
|
||||
copayerIndex: wallet.copayers.length,
|
||||
xPubKey: opts.xPubKey,
|
||||
|
@ -649,6 +650,7 @@ WalletService.prototype._addCopayerToWallet = function(wallet, opts, cb) {
|
|||
customData: opts.customData,
|
||||
derivationStrategy: wallet.derivationStrategy,
|
||||
});
|
||||
|
||||
self.storage.fetchCopayerLookup(copayer.id, function(err, res) {
|
||||
if (err) return cb(err);
|
||||
if (res) return cb(Errors.COPAYER_REGISTERED);
|
||||
|
|
|
@ -169,6 +169,7 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
|
|||
n: n,
|
||||
pubKey: TestData.keyPair.pub,
|
||||
singleAddress: !!opts.singleAddress,
|
||||
coin: opts.coin || 'btc',
|
||||
};
|
||||
if (_.isBoolean(opts.supportBIP44AndP2PKH))
|
||||
walletOpts.supportBIP44AndP2PKH = opts.supportBIP44AndP2PKH;
|
||||
|
@ -180,6 +181,7 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
|
|||
var copayerData = TestData.copayers[i + offset];
|
||||
var copayerOpts = helpers.getSignedCopayerOpts({
|
||||
walletId: walletId,
|
||||
coin: opts.coin,
|
||||
name: 'copayer ' + (i + 1),
|
||||
xPubKey: (_.isBoolean(opts.supportBIP44AndP2PKH) && !opts.supportBIP44AndP2PKH) ? copayerData.xPubKey_45H : copayerData.xPubKey_44H_0H_0H,
|
||||
requestPubKey: copayerData.pubKey_1H_0,
|
||||
|
|
|
@ -1671,7 +1671,7 @@ describe('Wallet service', function() {
|
|||
var requestPubKeyStr = requestPubKey.toString();
|
||||
var sig = helpers.signRequestPubKey(requestPubKeyStr, xPrivKey);
|
||||
|
||||
var copayerId = Model.Copayer._xPubToCopayerId(TestData.copayers[0].xPubKey_44H_0H_0H);
|
||||
var copayerId = Model.Copayer._xPubToCopayerId('btc', TestData.copayers[0].xPubKey_44H_0H_0H);
|
||||
opts = {
|
||||
copayerId: copayerId,
|
||||
requestPubKey: requestPubKeyStr,
|
||||
|
|
|
@ -92,6 +92,7 @@ describe('Storage', function() {
|
|||
});
|
||||
_.each(_.range(3), function(i) {
|
||||
var copayer = Model.Copayer.create({
|
||||
coin: 'btc',
|
||||
name: 'copayer ' + i,
|
||||
xPubKey: 'xPubKey ' + i,
|
||||
requestPubKey: 'requestPubKey ' + i,
|
||||
|
@ -136,6 +137,7 @@ describe('Storage', function() {
|
|||
});
|
||||
_.each(_.range(3), function(i) {
|
||||
var copayer = Model.Copayer.create({
|
||||
coin: 'btc',
|
||||
name: 'copayer ' + i,
|
||||
xPubKey: 'xPubKey ' + i,
|
||||
requestPubKey: 'requestPubKey ' + i,
|
||||
|
|
Loading…
Reference in New Issue