Browse Source

add recreate

activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
ac3037f1d4
  1. 1
      bit-wallet/bit
  2. 25
      bit-wallet/bit-recreate
  3. 35
      lib/client/api.js

1
bit-wallet/bit

@ -18,6 +18,7 @@ program
.command('export', 'export wallet critical data') .command('export', 'export wallet critical data')
.command('import', 'import wallet critical data') .command('import', 'import wallet critical data')
.command('confirm', 'show copayer\'s data for confirmation') .command('confirm', 'show copayer\'s data for confirmation')
.command('recreate', 'recreate a wallet on a remove server given local infomation')
.parse(process.argv); .parse(process.argv);

25
bit-wallet/bit-recreate

@ -0,0 +1,25 @@
#!/usr/bin/env node
var _ = require('lodash');
var program = require('commander');
var ClientLib = 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')
.usage('[options] walletname')
.description('Creates a wallet on the remove server given the local information')
.parse(process.argv);
var args = program.args;
if (!args[0])
program.help();
var walletName = args[0];
var client = utils.getClient(program);
client.reCreateWallet(walletName, function(err) {
utils.die(err);
console.log(' * Wallet Created.');
});

35
lib/client/api.js

@ -215,6 +215,39 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb
}); });
}; };
API.prototype.reCreateWallet = function(walletName, cb) {
var self = this;
this._loadAndCheck(function(err, data) {
if (err) return cb(err);
var walletPrivKey = new Bitcore.PrivateKey();
var args = {
name: walletName,
m: data.m,
n: data.n,
pubKey: walletPrivKey.toPublicKey().toString(),
network: data.network,
};
var url = '/v1/wallets/';
self._doPostRequest(url, args, {}, function(err, body) {
if (err) return cb(err);
var walletId = body.walletId;
var secret = WalletUtils.toSecret(walletId, walletPrivKey, data.network);
var i = 0;
async.each(data.publicKeyRing, function(xpub, next) {
var copayerName = 'recovered Copayer #' + i;
self._doJoinWallet(walletId, walletPrivKey, data.publicKeyRing[i++], copayerName, next);
}, function(err) {
return cb(err);
});
});
});
};
API.prototype.joinWallet = function(secret, copayerName, cb) { API.prototype.joinWallet = function(secret, copayerName, cb) {
var self = this; var self = this;
@ -345,7 +378,7 @@ API.prototype.import = function(str, cb) {
data.publicKeyRing.push(xPubKey); data.publicKeyRing.push(xPubKey);
data.copayerId = WalletUtils.xPubToCopayerId(xPubKey); data.copayerId = WalletUtils.xPubToCopayerId(xPubKey);
data.m = data.publicKeyRing.length; data.n = data.publicKeyRing.length;
data.signingPrivKey = (new Bitcore.HDPrivateKey(data.xPrivKey)).derive('m/1/0').privateKey.toWIF(); data.signingPrivKey = (new Bitcore.HDPrivateKey(data.xPrivKey)).derive('m/1/0').privateKey.toWIF();
data.network = data.xPrivKey.substr(0, 4) === 'tprv' ? 'testnet' : 'livenet'; data.network = data.xPrivKey.substr(0, 4) === 'tprv' ? 'testnet' : 'livenet';
self.storage.save(data, cb); self.storage.save(data, cb);

Loading…
Cancel
Save