use constants form BWU
This commit is contained in:
parent
2048a20ef4
commit
094e19bc31
|
@ -1,12 +1,9 @@
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var $ = require('preconditions').singleton();
|
var $ = require('preconditions').singleton();
|
||||||
|
|
||||||
var STRATEGIES = {
|
var WalletUtils = require('bitcore-wallet-utils');
|
||||||
BIP44: 'BIP44',
|
|
||||||
BIP45: 'BIP45',
|
|
||||||
};
|
|
||||||
|
|
||||||
var SHARED_INDEX = 0x80000000 - 1;
|
var BIP45_SHARED_INDEX = 0x80000000 - 1;
|
||||||
|
|
||||||
function AddressManager() {};
|
function AddressManager() {};
|
||||||
|
|
||||||
|
@ -16,12 +13,12 @@ AddressManager.create = function(opts) {
|
||||||
var x = new AddressManager();
|
var x = new AddressManager();
|
||||||
|
|
||||||
x.version = 2;
|
x.version = 2;
|
||||||
x.derivationStrategy = opts.derivationStrategy || STRATEGIES.BIP44;
|
x.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP44;
|
||||||
$.checkState(_.contains(_.values(STRATEGIES), x.derivationStrategy));
|
$.checkState(_.contains(_.values(WalletUtils.DERIVATION_STRATEGIES), x.derivationStrategy));
|
||||||
|
|
||||||
x.receiveAddressIndex = 0;
|
x.receiveAddressIndex = 0;
|
||||||
x.changeAddressIndex = 0;
|
x.changeAddressIndex = 0;
|
||||||
x.copayerIndex = (opts && _.isNumber(opts.copayerIndex)) ? opts.copayerIndex : SHARED_INDEX;
|
x.copayerIndex = (opts && _.isNumber(opts.copayerIndex)) ? opts.copayerIndex : BIP45_SHARED_INDEX;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +27,7 @@ AddressManager.fromObj = function(obj) {
|
||||||
var x = new AddressManager();
|
var x = new AddressManager();
|
||||||
|
|
||||||
x.version = obj.version;
|
x.version = obj.version;
|
||||||
x.derivationStrategy = obj.derivationStrategy || STRATEGIES.BIP45;
|
x.derivationStrategy = obj.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
x.receiveAddressIndex = obj.receiveAddressIndex;
|
x.receiveAddressIndex = obj.receiveAddressIndex;
|
||||||
x.changeAddressIndex = obj.changeAddressIndex;
|
x.changeAddressIndex = obj.changeAddressIndex;
|
||||||
x.copayerIndex = obj.copayerIndex;
|
x.copayerIndex = obj.copayerIndex;
|
||||||
|
@ -40,7 +37,7 @@ AddressManager.fromObj = function(obj) {
|
||||||
|
|
||||||
AddressManager.prototype.supportsDerivation = function() {
|
AddressManager.prototype.supportsDerivation = function() {
|
||||||
// BIP44 does not support copayer specific indexes
|
// BIP44 does not support copayer specific indexes
|
||||||
return !(this.derivationStrategy == STRATEGIES.BIP44 && this.copayerIndex != SHARED_INDEX);
|
return !(this.derivationStrategy == WalletUtils.DERIVATION_STRATEGIES.BIP44 && this.copayerIndex != BIP45_SHARED_INDEX);
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressManager.prototype._incrementIndex = function(isChange) {
|
AddressManager.prototype._incrementIndex = function(isChange) {
|
||||||
|
@ -62,7 +59,7 @@ AddressManager.prototype.rewindIndex = function(isChange, n) {
|
||||||
|
|
||||||
AddressManager.prototype.getCurrentAddressPath = function(isChange) {
|
AddressManager.prototype.getCurrentAddressPath = function(isChange) {
|
||||||
return 'm/' +
|
return 'm/' +
|
||||||
(this.derivationStrategy == STRATEGIES.BIP45 ? this.copayerIndex + '/' : '') +
|
(this.derivationStrategy == WalletUtils.DERIVATION_STRATEGIES.BIP45 ? this.copayerIndex + '/' : '') +
|
||||||
(isChange ? 1 : 0) + '/' +
|
(isChange ? 1 : 0) + '/' +
|
||||||
(isChange ? this.changeAddressIndex : this.receiveAddressIndex);
|
(isChange ? this.changeAddressIndex : this.receiveAddressIndex);
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@ Copayer.create = function(opts) {
|
||||||
}];
|
}];
|
||||||
|
|
||||||
x.addressManager = AddressManager.create({
|
x.addressManager = AddressManager.create({
|
||||||
derivationStrategy: opts.derivationStrategy || 'BIP45',
|
derivationStrategy: opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45,
|
||||||
copayerIndex: opts.copayerIndex,
|
copayerIndex: opts.copayerIndex,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ TxProposal.create = function(opts) {
|
||||||
x.excludeUnconfirmedUtxos = opts.excludeUnconfirmedUtxos;
|
x.excludeUnconfirmedUtxos = opts.excludeUnconfirmedUtxos;
|
||||||
x.proposalSignaturePubKey = opts.proposalSignaturePubKey;
|
x.proposalSignaturePubKey = opts.proposalSignaturePubKey;
|
||||||
x.proposalSignaturePubKeySig = opts.proposalSignaturePubKeySig;
|
x.proposalSignaturePubKeySig = opts.proposalSignaturePubKeySig;
|
||||||
x.derivationStrategy = opts.derivationStrategy || 'BIP45';
|
x.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
|
|
||||||
if (_.isFunction(TxProposal._create[x.type])) {
|
if (_.isFunction(TxProposal._create[x.type])) {
|
||||||
TxProposal._create[x.type](x, opts);
|
TxProposal._create[x.type](x, opts);
|
||||||
|
@ -118,7 +118,7 @@ TxProposal.fromObj = function(obj) {
|
||||||
x.excludeUnconfirmedUtxos = obj.excludeUnconfirmedUtxos;
|
x.excludeUnconfirmedUtxos = obj.excludeUnconfirmedUtxos;
|
||||||
x.proposalSignaturePubKey = obj.proposalSignaturePubKey;
|
x.proposalSignaturePubKey = obj.proposalSignaturePubKey;
|
||||||
x.proposalSignaturePubKeySig = obj.proposalSignaturePubKeySig;
|
x.proposalSignaturePubKeySig = obj.proposalSignaturePubKeySig;
|
||||||
x.derivationStrategy = obj.derivationStrategy || 'BIP45';
|
x.derivationStrategy = obj.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,8 +29,9 @@ Wallet.create = function(opts) {
|
||||||
x.copayers = [];
|
x.copayers = [];
|
||||||
x.pubKey = opts.pubKey;
|
x.pubKey = opts.pubKey;
|
||||||
x.network = opts.network;
|
x.network = opts.network;
|
||||||
|
x.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
x.addressManager = AddressManager.create({
|
x.addressManager = AddressManager.create({
|
||||||
derivationStrategy: opts.derivationStrategy || 'BIP45',
|
derivationStrategy: x.derivationStrategy,
|
||||||
});
|
});
|
||||||
x.scanStatus = null;
|
x.scanStatus = null;
|
||||||
|
|
||||||
|
@ -53,6 +54,7 @@ Wallet.fromObj = function(obj) {
|
||||||
});
|
});
|
||||||
x.pubKey = obj.pubKey;
|
x.pubKey = obj.pubKey;
|
||||||
x.network = obj.network;
|
x.network = obj.network;
|
||||||
|
x.derivationStrategy = obj.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
x.addressManager = AddressManager.fromObj(obj.addressManager);
|
x.addressManager = AddressManager.fromObj(obj.addressManager);
|
||||||
x.scanStatus = obj.scanStatus;
|
x.scanStatus = obj.scanStatus;
|
||||||
|
|
||||||
|
|
|
@ -220,8 +220,8 @@ WalletService.prototype.createWallet = function(opts, cb) {
|
||||||
if (!_.contains(['livenet', 'testnet'], opts.network))
|
if (!_.contains(['livenet', 'testnet'], opts.network))
|
||||||
return cb(new ClientError('Invalid network'));
|
return cb(new ClientError('Invalid network'));
|
||||||
|
|
||||||
opts.derivationStrategy = opts.derivationStrategy || 'BIP45';
|
opts.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
if (!_.contains(['BIP44', 'BIP45'], opts.derivationStrategy))
|
if (!_.contains(_.values(WalletUtils.DERIVATION_STRATEGIES), opts.derivationStrategy))
|
||||||
return cb(new ClientError('Invalid address derivation strategy'));
|
return cb(new ClientError('Invalid address derivation strategy'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -536,8 +536,8 @@ WalletService.prototype.joinWallet = function(opts, cb) {
|
||||||
if (_.isEmpty(opts.name))
|
if (_.isEmpty(opts.name))
|
||||||
return cb(new ClientError('Invalid copayer name'));
|
return cb(new ClientError('Invalid copayer name'));
|
||||||
|
|
||||||
opts.derivationStrategy = opts.derivationStrategy || 'BIP45';
|
opts.derivationStrategy = opts.derivationStrategy || WalletUtils.DERIVATION_STRATEGIES.BIP45;
|
||||||
if (!_.contains(['BIP44', 'BIP45'], opts.derivationStrategy))
|
if (!_.contains(_.values(WalletUtils.DERIVATION_STRATEGIES), opts.derivationStrategy))
|
||||||
return cb(new ClientError('Invalid address derivation strategy'));
|
return cb(new ClientError('Invalid address derivation strategy'));
|
||||||
|
|
||||||
self.walletId = opts.walletId;
|
self.walletId = opts.walletId;
|
||||||
|
|
Loading…
Reference in New Issue