From 0bf15a68425462ca4abe32a0d623b7f6851b16f8 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 17 Feb 2015 21:06:11 -0300 Subject: [PATCH] add copayer confirmation --- bit-wallet/bit-confirm | 34 ++++++++++++++++++++++++++++++++++ bit-wallet/cli-utils.js | 4 ++++ lib/client/api.js | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 bit-wallet/bit-confirm diff --git a/bit-wallet/bit-confirm b/bit-wallet/bit-confirm new file mode 100755 index 0000000..ba5534f --- /dev/null +++ b/bit-wallet/bit-confirm @@ -0,0 +1,34 @@ +#!/usr/bin/env node + +var _ = require('lodash'); +var program = require('commander'); +var Client = require('../lib/client'); +var utils = require('./cli-utils'); + +program + .version('0.0.1') + .option('-c, --config [file]', 'Wallet config filename') + .option('-h, --host [host]', 'Bitcore Wallet Service URL (eg: http://localhost:3001/copay/api') + .option('-v, --verbose', 'be verbose') + .parse(process.argv); +var client = utils.getClient(program); + +client.getStatus(function(err, x, myCopayerId) { + utils.die(err); + console.log('\n To be sure that none Copayer has joined more that once to this wallet, you can asked them their confirmation number. They can grab them using this (bit confirm) command.'); + + console.log('\n * Copayer confirmations ids:'); + + var myConfirmationId; + _.each(x.wallet.copayers, function(x) { + var confirmationId = utils.confirmationId(x); + if (x.id != myCopayerId) + console.log('\t\t* %s : %s', x.name, confirmationId); + else + myConfirmationId = confirmationId; + }); + + + console.log('\t\t---'); + console.log('\t\tYour confirmation ID: %s', myConfirmationId); +}); diff --git a/bit-wallet/cli-utils.js b/bit-wallet/cli-utils.js index fdb25df..0018cfe 100644 --- a/bit-wallet/cli-utils.js +++ b/bit-wallet/cli-utils.js @@ -31,6 +31,10 @@ Utils.shortID = function(id) { return id.substr(id.length - 4); }; +Utils.confirmationId = function(copayer) { + return parseInt(copayer.xPubKeySignature.substr(-4), 16).toString().substr(-4); +} + Utils.getClient = function(args) { var storage = new Client.FileStorage({ filename: args.config || process.env['BIT_FILE'], diff --git a/lib/client/api.js b/lib/client/api.js index d5ab890..d6cc386 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -241,7 +241,7 @@ API.prototype.getStatus = function(cb) { var url = '/v1/wallets/'; self._doGetRequest(url, data, function(err, body) { - return cb(err, body); + return cb(err, body, data.copayerId); }); }); };