|
|
@ -228,21 +228,27 @@ API.prototype._initData = function(network, walletPrivKey, m, n) { |
|
|
|
var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString(); |
|
|
|
var roPrivKey = xPrivKey.derive('m/1/0').privateKey; |
|
|
|
var rwPrivKey = xPrivKey.derive('m/1/1').privateKey; |
|
|
|
var sharedEncryptingKey = WalletUtils.privateKeyToAESKey(walletPrivKey); |
|
|
|
var copayerId = WalletUtils.xPubToCopayerId(xPubKey); |
|
|
|
|
|
|
|
|
|
|
|
var data = { |
|
|
|
copayerId: copayerId, |
|
|
|
xPrivKey: xPrivKey.toString(), |
|
|
|
publicKeyRing: [xPubKey], |
|
|
|
network: network, |
|
|
|
m: m, |
|
|
|
n: n, |
|
|
|
roPrivKey: roPrivKey.toWIF(), |
|
|
|
rwPrivKey: rwPrivKey.toWIF(), |
|
|
|
walletPrivKey: walletPrivKey.toWIF(), |
|
|
|
sharedEncryptingKey: sharedEncryptingKey, |
|
|
|
}; |
|
|
|
|
|
|
|
if (walletPrivKey) { |
|
|
|
var sharedEncryptingKey = WalletUtils.privateKeyToAESKey(walletPrivKey); |
|
|
|
data.walletPrivKey = walletPrivKey.toWIF(); |
|
|
|
data.sharedEncryptingKey = sharedEncryptingKey; |
|
|
|
} |
|
|
|
|
|
|
|
if (m) data.m = m; |
|
|
|
if (n) data.n = n; |
|
|
|
|
|
|
|
return data; |
|
|
|
}; |
|
|
|
|
|
|
@ -260,6 +266,22 @@ API.prototype._doJoinWallet = function(walletId, walletPrivKey, xPubKey, copayer |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
API.prototype.generateKey = function(network, cb) { |
|
|
|
var self = this; |
|
|
|
network = network || 'livenet'; |
|
|
|
if (!_.contains(['testnet', 'livenet'], network)) |
|
|
|
return cb('Invalid network'); |
|
|
|
|
|
|
|
this.storage.load(function(err, data) { |
|
|
|
if (data) |
|
|
|
return cb(self.storage.getName() + ' already contains a wallet'); |
|
|
|
|
|
|
|
var data = self._initData(network); |
|
|
|
self.storage.save(data, function(err) { |
|
|
|
return cb(err, null); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb) { |
|
|
|
var self = this; |
|
|
@ -471,7 +493,7 @@ API.prototype.export = function(opts, cb) { |
|
|
|
opts = opts || {}; |
|
|
|
var access = opts.access || 'full'; |
|
|
|
|
|
|
|
this._loadAndCheck({}, function(err, data) { |
|
|
|
this._load(function(err, data) { |
|
|
|
if (err) return cb(err); |
|
|
|
var v = []; |
|
|
|
|
|
|
@ -532,9 +554,12 @@ API.prototype.import = function(str, cb) { |
|
|
|
data.rwPrivKey = xpriv.derive('m/1/1').privateKey.toWIF(); |
|
|
|
} |
|
|
|
|
|
|
|
data.n = data.publicKeyRing.length; |
|
|
|
var dataIsComplete = !!data.m; |
|
|
|
|
|
|
|
if (dataIsComplete) |
|
|
|
data.n = data.publicKeyRing.length; |
|
|
|
|
|
|
|
if (!data.copayerId || !data.n || !data.m) |
|
|
|
if (!data.publicKeyRing) |
|
|
|
return cb('Invalid source data'); |
|
|
|
|
|
|
|
data.network = data.publicKeyRing[0].substr(0, 4) == 'tpub' ? 'testnet' : 'livenet'; |
|
|
|