|
|
@ -30,6 +30,8 @@ function _parseError(body) { |
|
|
|
|
|
|
|
function _signRequest(url, args, privKey) { |
|
|
|
var message = url + (args ? '|' + JSON.stringify(args) : ''); |
|
|
|
console.log('[clilib.js.32:message:]',message); //TODO
|
|
|
|
console.log('[clilib.js.34:privKey:]',privKey); //TODO
|
|
|
|
return SignUtils.sign(message, privKey); |
|
|
|
}; |
|
|
|
|
|
|
@ -45,7 +47,7 @@ function CliLib(opts) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
CliLib.prototype_save = function (data) { |
|
|
|
CliLib.prototype._save = function (data) { |
|
|
|
fs.writeFileSync(this.filename, JSON.stringify(data)); |
|
|
|
}; |
|
|
|
|
|
|
@ -105,7 +107,7 @@ CliLib.prototype.createWallet = function(walletName, copayerName, m, n, network, |
|
|
|
} |
|
|
|
|
|
|
|
var walletId = body.walletId; |
|
|
|
var secret = walletId + '|' + privKey.toString(); |
|
|
|
var secret = walletId + ':' + privKey.toString(); |
|
|
|
data.secret = secret; |
|
|
|
|
|
|
|
self._save(data); |
|
|
@ -121,14 +123,15 @@ CliLib.prototype.createWallet = function(walletName, copayerName, m, n, network, |
|
|
|
CliLib.prototype._joinWallet = function(data, secret, copayerName, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var secretSplit = secret.split('|'); |
|
|
|
var secretSplit = secret.split(':'); |
|
|
|
var walletId = secretSplit[0]; |
|
|
|
var privKey = Bitcore.PrivateKey.fromString(secretSplit[1]); |
|
|
|
var pubKey = privKey.toPublicKey(); |
|
|
|
|
|
|
|
var xPubKey = new Bitcore.HDPublicKey(data.xPrivKey); |
|
|
|
var xPubKeySignature = SignUtils.sign(xPubKey.toString(), privKey); |
|
|
|
var signingPrivKey = xPubKey.derive('m/1/0'); |
|
|
|
|
|
|
|
var signingPrivKey = (new Bitcore.HDPrivateKey(data.xPrivKey)).derive('m/1/0').privateKey; |
|
|
|
|
|
|
|
var args = { |
|
|
|
walletId: walletId, |
|
|
@ -143,7 +146,6 @@ CliLib.prototype._joinWallet = function(data, secret, copayerName, cb) { |
|
|
|
body: args, |
|
|
|
json: true, |
|
|
|
}, function(err, res, body) { |
|
|
|
console.log('[clilib.js.123:err:]',err, body); //TODO
|
|
|
|
if (err) return cb(err); |
|
|
|
if (res.statusCode != 200) { |
|
|
|
_parseError(body); |
|
|
@ -179,6 +181,7 @@ CliLib.prototype.status = function(cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var data = this._loadAndCheck(); |
|
|
|
console.log('[clilib.js.180:data:]',data); //TODO
|
|
|
|
|
|
|
|
var url = 'v1/wallets/'; |
|
|
|
var signature = _signRequest(url, null, data.signingPrivKey); |
|
|
|