|
|
@ -13,14 +13,18 @@ var Bitcore = WalletUtils.Bitcore; |
|
|
|
var HDPublicKey = Bitcore.HDPublicKey; |
|
|
|
|
|
|
|
function Copayer() { |
|
|
|
this.version = '1.0.0'; |
|
|
|
this.version = '2'; |
|
|
|
}; |
|
|
|
|
|
|
|
Copayer.getVersion = function() { |
|
|
|
return parseInt(this.version); |
|
|
|
}; |
|
|
|
|
|
|
|
Copayer.create = function(opts) { |
|
|
|
opts = opts || {}; |
|
|
|
$.checkArgument(opts.xPubKey, 'Missing copayer extended public key'); |
|
|
|
$.checkArgument(opts.requestPubKey || opts.requestPubKeys, 'Missing copayer request public key'); |
|
|
|
$.checkArgument(opts.xPubKey, 'Missing copayer extended public key') |
|
|
|
.checkArgument(opts.requestPubKey, 'Missing copayer request public key') |
|
|
|
.checkArgument(opts.signature, 'Missing copayer request public key signature'); |
|
|
|
|
|
|
|
opts.copayerIndex = opts.copayerIndex || 0; |
|
|
|
|
|
|
@ -32,19 +36,14 @@ Copayer.create = function(opts) { |
|
|
|
x.id = WalletUtils.xPubToCopayerId(x.xPubKey); |
|
|
|
x.name = opts.name; |
|
|
|
|
|
|
|
if (!opts.requestPubKeys) { |
|
|
|
x.requestPubKeys = [{ |
|
|
|
key: opts.requestPubKey, |
|
|
|
signature: opts.signature, |
|
|
|
}]; |
|
|
|
} |
|
|
|
|
|
|
|
x.requestPubKey = opts.requestPubKey; |
|
|
|
x.signature = opts.signature; |
|
|
|
|
|
|
|
x.requestPubKeys = opts.requestPubKeys; |
|
|
|
Copayer.expandForCompat(x); |
|
|
|
|
|
|
|
x.requestPubKeys = [{ |
|
|
|
key: opts.requestPubKey, |
|
|
|
signature: opts.signature, |
|
|
|
}]; |
|
|
|
|
|
|
|
x.addressManager = AddressManager.create({ |
|
|
|
copayerIndex: opts.copayerIndex |
|
|
|
}); |
|
|
@ -52,21 +51,6 @@ Copayer.create = function(opts) { |
|
|
|
return x; |
|
|
|
}; |
|
|
|
|
|
|
|
Copayer.expandForCompat = function(x) { |
|
|
|
if (!x.requestPubKeys) { |
|
|
|
x.requestPubKeys = [{ |
|
|
|
key: x.requestPubKey, |
|
|
|
signature: x.signature, |
|
|
|
}]; |
|
|
|
} |
|
|
|
// For backcompat
|
|
|
|
if (!x.requestPubKey) { |
|
|
|
var l = _.last(x.requestPubKeys); |
|
|
|
x.requestPubKey = l.key; |
|
|
|
x.signature = l.signature; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
Copayer.fromObj = function(obj) { |
|
|
|
var x = new Copayer(); |
|
|
|
|
|
|
@ -78,9 +62,16 @@ Copayer.fromObj = function(obj) { |
|
|
|
x.requestPubKey = obj.requestPubKey; |
|
|
|
x.signature = obj.signature; |
|
|
|
|
|
|
|
x.requestPubKeys = obj.requestPubKeys; |
|
|
|
Copayer.expandForCompat(x); |
|
|
|
|
|
|
|
if (this.getVersion() == 1) { |
|
|
|
x.requestPubKeys = [{ |
|
|
|
key: x.requestPubKey, |
|
|
|
signature: x.signature, |
|
|
|
}]; |
|
|
|
x.version = 2; |
|
|
|
} else { |
|
|
|
x.requestPubKeys = obj.requestPubKeys; |
|
|
|
} |
|
|
|
|
|
|
|
x.addressManager = AddressManager.fromObj(obj.addressManager); |
|
|
|
return x; |
|
|
|
}; |
|
|
|