Browse Source

import working

activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
922e79d34d
  1. 1
      bit-wallet/bit
  2. 45
      lib/client/api.js

1
bit-wallet/bit

@ -16,6 +16,7 @@ program
.command('broadcast <txpId>', 'broadcast a transaction proposal to the Bitcoin network') .command('broadcast <txpId>', 'broadcast a transaction proposal to the Bitcoin network')
.command('rm <txpId>', 'remove a transaction proposal') .command('rm <txpId>', 'remove a transaction proposal')
.command('export', 'export wallet critical data') .command('export', 'export wallet critical data')
.command('import', 'import wallet critical data')
.parse(process.argv); .parse(process.argv);

45
lib/client/api.js

@ -211,12 +211,15 @@ API.prototype._joinWallet = function(secret, copayerName, cb) {
var wallet = body.wallet; var wallet = body.wallet;
var data = { var data = {
copayerId: body.copayerId, copayerId: body.copayerId,
walletPrivKey: walletPrivKey.toWIF(),
signingPrivKey: signingPrivKey.toWIF(),
m: wallet.m,
n: wallet.n,
publicKeyRing: wallet.publicKeyRing, publicKeyRing: wallet.publicKeyRing,
network: wallet.network, network: wallet.network,
m: wallet.m,
n: wallet.n,
xPrivKey: xPrivKey,
walletPrivKey: walletPrivKey.toWIF(),
signingPrivKey: signingPrivKey.toWIF(),
}; };
self.storage.save(data, cb); self.storage.save(data, cb);
}); });
@ -304,8 +307,11 @@ API.prototype.export = function(cb) {
this._loadAndCheck(function(err, data) { this._loadAndCheck(function(err, data) {
if (err) return cb(err); if (err) return cb(err);
var x = _.pick(data, WALLET_CRITICAL_DATA) var v = [];
return cb(null, JSON.stringify(_.values(x))); _.each(WALLET_CRITICAL_DATA, function(k) {
v.push(data[k]);
});
return cb(null, JSON.stringify(v));
}); });
} }
@ -313,16 +319,27 @@ API.prototype.export = function(cb) {
API.prototype.import = function(str, cb) { API.prototype.import = function(str, cb) {
var self = this; var self = this;
var inData = JSON.parse(str); this.storage.load(function(err, data) {
var data = {}, if (data)
i = 0; return cb('Storage already contains a wallet');
_.each(WALLET_CRITICAL_DATA, function(k) { data = {};
data[k] = inData[i++];
});
if (err) return cb(err); var inData = JSON.parse(str);
} var i = 0;
_.each(WALLET_CRITICAL_DATA, function(k) {
data[k] = inData[i++];
if (!data[k])
return cb('Invalid wallet data');
});
data.m = data.publicKeyRing.length;
data.signingPrivKey = (new Bitcore.HDPrivateKey(data.xPrivKey)).derive('m/1/0').privateKey.toWIF();
data.network = data.xPrivKey.substr(0,4) === 'tprv' ? 'testnet' : 'livenet';
self.storage.save(data, cb);
});
};
API.prototype.getTxProposals = function(opts, cb) { API.prototype.getTxProposals = function(opts, cb) {

Loading…
Cancel
Save