create, join, status
This commit is contained in:
parent
ce8648a31d
commit
a37f773d88
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var cli = require('../lib/clilib.js');
|
var CliLib = require('../lib/clilib.js');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
.version('0.0.1')
|
||||||
.option('-c,--config [file]', 'Wallet config filename')
|
.option('-c,--config [file]', 'Wallet config filename')
|
||||||
|
.option('-n,--network [networkname]', 'livenet|testnet', String, 'livenet')
|
||||||
.usage('[options] <walletName> <m-n> [copayerName]')
|
.usage('[options] <walletName> <m-n> [copayerName]')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
@ -16,12 +17,14 @@ if (!args[0])
|
||||||
|
|
||||||
var walletName = args[0];
|
var walletName = args[0];
|
||||||
var copayerName = args[2] || process.env.USER;
|
var copayerName = args[2] || process.env.USER;
|
||||||
|
var network = program.network;
|
||||||
|
|
||||||
var mn = common.parseMN(args[1]);
|
var mn = common.parseMN(args[1]);
|
||||||
|
|
||||||
cli.setFilename(program.config);
|
var cli = new CliLib({
|
||||||
|
filename: program.config
|
||||||
cli.createWallet(walletName, copayerName, mn[0], mn[1], function(err, secret) {
|
});
|
||||||
|
cli.createWallet(walletName, copayerName, mn[0], mn[1], network, function(err, secret) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
console.log(' * Wallet Created.');
|
console.log(' * Wallet Created.');
|
||||||
console.log(' - Secret to share:\n\t' + secret);
|
console.log(' - Secret to share:\n\t' + secret);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var cli = require('../lib/clilib.js');
|
var CliLib = require('../lib/clilib.js');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -17,10 +17,11 @@ if (!args[0])
|
||||||
var secret = args[0];
|
var secret = args[0];
|
||||||
var copayerName = args[1] || process.env.USER;
|
var copayerName = args[1] || process.env.USER;
|
||||||
|
|
||||||
cli.setFilename(program.config);
|
var cli = new CliLib({
|
||||||
|
filename: program.config
|
||||||
|
});
|
||||||
|
|
||||||
cli.joinWallet(secret, copayerName, function(err, xx) {
|
cli.joinWallet(secret, copayerName, function(err, xx) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
console.log(' * Wallet Joined.', xx);
|
console.log(' * Wallet Joined.', xx || '');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var cli = require('../lib/clilib.js');
|
var CliLib = require('../lib/clilib.js');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -10,8 +10,9 @@ program
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
var args = program.args;
|
var args = program.args;
|
||||||
|
var cli = new CliLib({
|
||||||
cli.setFilename(program.config);
|
filename: program.config
|
||||||
|
});
|
||||||
|
|
||||||
cli.status(function(err, xx) {
|
cli.status(function(err, xx) {
|
||||||
common.die(err);
|
common.die(err);
|
||||||
|
|
|
@ -30,6 +30,8 @@ function _parseError(body) {
|
||||||
|
|
||||||
function _signRequest(url, args, privKey) {
|
function _signRequest(url, args, privKey) {
|
||||||
var message = url + (args ? '|' + JSON.stringify(args) : '');
|
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);
|
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));
|
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 walletId = body.walletId;
|
||||||
var secret = walletId + '|' + privKey.toString();
|
var secret = walletId + ':' + privKey.toString();
|
||||||
data.secret = secret;
|
data.secret = secret;
|
||||||
|
|
||||||
self._save(data);
|
self._save(data);
|
||||||
|
@ -121,14 +123,15 @@ CliLib.prototype.createWallet = function(walletName, copayerName, m, n, network,
|
||||||
CliLib.prototype._joinWallet = function(data, secret, copayerName, cb) {
|
CliLib.prototype._joinWallet = function(data, secret, copayerName, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var secretSplit = secret.split('|');
|
var secretSplit = secret.split(':');
|
||||||
var walletId = secretSplit[0];
|
var walletId = secretSplit[0];
|
||||||
var privKey = Bitcore.PrivateKey.fromString(secretSplit[1]);
|
var privKey = Bitcore.PrivateKey.fromString(secretSplit[1]);
|
||||||
var pubKey = privKey.toPublicKey();
|
var pubKey = privKey.toPublicKey();
|
||||||
|
|
||||||
var xPubKey = new Bitcore.HDPublicKey(data.xPrivKey);
|
var xPubKey = new Bitcore.HDPublicKey(data.xPrivKey);
|
||||||
var xPubKeySignature = SignUtils.sign(xPubKey.toString(), privKey);
|
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 = {
|
var args = {
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
|
@ -143,7 +146,6 @@ CliLib.prototype._joinWallet = function(data, secret, copayerName, cb) {
|
||||||
body: args,
|
body: args,
|
||||||
json: true,
|
json: true,
|
||||||
}, function(err, res, body) {
|
}, function(err, res, body) {
|
||||||
console.log('[clilib.js.123:err:]',err, body); //TODO
|
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (res.statusCode != 200) {
|
if (res.statusCode != 200) {
|
||||||
_parseError(body);
|
_parseError(body);
|
||||||
|
@ -179,6 +181,7 @@ CliLib.prototype.status = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = this._loadAndCheck();
|
var data = this._loadAndCheck();
|
||||||
|
console.log('[clilib.js.180:data:]',data); //TODO
|
||||||
|
|
||||||
var url = 'v1/wallets/';
|
var url = 'v1/wallets/';
|
||||||
var signature = _signRequest(url, null, data.signingPrivKey);
|
var signature = _signRequest(url, null, data.signingPrivKey);
|
||||||
|
|
Loading…
Reference in New Issue