Browse Source

add params needed to check proposal on airgapped client

activeAddress
Ivan Socolsky 10 years ago
parent
commit
cabdb35cb1
  1. 6
      lib/client/airgapped.js
  2. 4
      lib/client/credentials.js
  3. 11
      lib/model/copayer.js
  4. 8
      lib/server.js
  5. 3
      lib/storage.js
  6. 9
      test/integration/client.js

6
lib/client/airgapped.js

@ -37,10 +37,14 @@ AirGapped.prototype.getSeed = function() {
}; };
}; };
AirGapped.prototype.signTxProposal = function(txp) { AirGapped.prototype.signTxProposal = function(txp, pkr, m, n) {
var self = this; var self = this;
// TODO: complete credentials // TODO: complete credentials
self.credentials.m = m;
self.credentials.n = n;
self.credentials.addPublicKeyRing(pkr);
if (!Verifier.checkTxProposal(self.credentials, txp)) { if (!Verifier.checkTxProposal(self.credentials, txp)) {
throw new Error('Fake transaction proposal'); throw new Error('Fake transaction proposal');
} }

4
lib/client/credentials.js

@ -9,7 +9,6 @@ var FIELDS = [
'network', 'network',
'xPrivKey', 'xPrivKey',
'xPubKey', 'xPubKey',
// 'roPrivKey',
'requestPrivKey', 'requestPrivKey',
'copayerId', 'copayerId',
'publicKeyRing', 'publicKeyRing',
@ -58,7 +57,6 @@ Credentials.prototype._expand = function() {
if (this.xPrivKey) { if (this.xPrivKey) {
var xPrivKey = new Bitcore.HDPrivateKey.fromString(this.xPrivKey); var xPrivKey = new Bitcore.HDPrivateKey.fromString(this.xPrivKey);
this.xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString(); this.xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString();
// this.roPrivKey = xPrivKey.derive('m/1/0').privateKey.toString();
this.requestPrivKey = xPrivKey.derive('m/1/1').privateKey.toString(); this.requestPrivKey = xPrivKey.derive('m/1/1').privateKey.toString();
} }
this.copayerId = WalletUtils.xPubToCopayerId(this.xPubKey); this.copayerId = WalletUtils.xPubToCopayerId(this.xPubKey);
@ -100,7 +98,7 @@ Credentials.prototype.canSign = function() {
}; };
Credentials.prototype.isComplete = function() { Credentials.prototype.isComplete = function() {
if (!this.walletId) return false; if (!this.m || !this.n) return false;
if (!this.publicKeyRing || this.publicKeyRing.length != this.n) return false; if (!this.publicKeyRing || this.publicKeyRing.length != this.n) return false;
return true; return true;
}; };

11
lib/model/copayer.js

@ -11,8 +11,6 @@ var AddressManager = require('./addressmanager');
var Utils = require('../walletutils'); var Utils = require('../walletutils');
var RW_SIGNING_PATH = "m/1/1";
function Copayer() { function Copayer() {
this.version = '1.0.0'; this.version = '1.0.0';
}; };
@ -30,7 +28,7 @@ Copayer.create = function(opts) {
x.id = Utils.xPubToCopayerId(x.xPubKey); x.id = Utils.xPubToCopayerId(x.xPubKey);
x.name = opts.name; x.name = opts.name;
x.xPubKeySignature = opts.xPubKeySignature; // So third parties can check independently x.xPubKeySignature = opts.xPubKeySignature; // So third parties can check independently
x.rwPubKey = x.getRWPubKey(); x.requestPubKey = x.getRequestPubKey();
x.addressManager = AddressManager.create({ x.addressManager = AddressManager.create({
copayerIndex: opts.copayerIndex copayerIndex: opts.copayerIndex
}); });
@ -46,8 +44,7 @@ Copayer.fromObj = function(obj) {
x.name = obj.name; x.name = obj.name;
x.xPubKey = obj.xPubKey; x.xPubKey = obj.xPubKey;
x.xPubKeySignature = obj.xPubKeySignature; x.xPubKeySignature = obj.xPubKeySignature;
x.roPubKey = obj.roPubKey; x.requestPubKey = obj.requestPubKey;
x.rwPubKey = obj.rwPubKey;
x.addressManager = AddressManager.fromObj(obj.addressManager); x.addressManager = AddressManager.fromObj(obj.addressManager);
return x; return x;
@ -61,8 +58,8 @@ Copayer.prototype.getPublicKey = function(path) {
.toString(); .toString();
}; };
Copayer.prototype.getRWPubKey = function() { Copayer.prototype.getRequestPubKey = function() {
return this.getPublicKey(RW_SIGNING_PATH); return this.getPublicKey('m/1/1');
}; };

8
lib/server.js

@ -66,7 +66,7 @@ WalletService.getInstance = function() {
* @param {Object} opts * @param {Object} opts
* @param {string} opts.copayerId - The copayer id making the request. * @param {string} opts.copayerId - The copayer id making the request.
* @param {string} opts.message - The contents of the request to be signed. * @param {string} opts.message - The contents of the request to be signed.
* @param {string} opts.signature - Signature of message to be verified using the copayer's rwPubKey * @param {string} opts.signature - Signature of message to be verified using the copayer's requestPubKey
*/ */
WalletService.getInstanceWithAuth = function(opts, cb) { WalletService.getInstanceWithAuth = function(opts, cb) {
@ -78,7 +78,7 @@ WalletService.getInstanceWithAuth = function(opts, cb) {
if (err) return cb(err); if (err) return cb(err);
if (!copayer) return cb(new ClientError('NOTAUTHORIZED', 'Copayer not found')); if (!copayer) return cb(new ClientError('NOTAUTHORIZED', 'Copayer not found'));
var isValid = server._verifySignature(opts.message, opts.signature, copayer.rwPubKey); var isValid = server._verifySignature(opts.message, opts.signature, copayer.requestPubKey);
if (!isValid) if (!isValid)
return cb(new ClientError('NOTAUTHORIZED', 'Invalid signature')); return cb(new ClientError('NOTAUTHORIZED', 'Invalid signature'));
@ -312,7 +312,7 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) {
var copayer = wallet.getCopayer(self.copayerId); var copayer = wallet.getCopayer(self.copayerId);
var isValid = self._verifySignature(opts.message, opts.signature, copayer.rwPubKey); var isValid = self._verifySignature(opts.message, opts.signature, copayer.requestPubKey);
return cb(null, isValid); return cb(null, isValid);
}); });
}; };
@ -497,7 +497,7 @@ WalletService.prototype.createTx = function(opts, cb) {
var copayer = wallet.getCopayer(self.copayerId); var copayer = wallet.getCopayer(self.copayerId);
var hash = WalletUtils.getProposalHash(opts.toAddress, opts.amount, opts.message); var hash = WalletUtils.getProposalHash(opts.toAddress, opts.amount, opts.message);
if (!self._verifySignature(hash, opts.proposalSignature, copayer.rwPubKey)) if (!self._verifySignature(hash, opts.proposalSignature, copayer.requestPubKey))
return cb(new ClientError('Invalid proposal signature')); return cb(new ClientError('Invalid proposal signature'));
var toAddress; var toAddress;

3
lib/storage.js

@ -81,8 +81,7 @@ Storage.prototype.storeWalletAndUpdateCopayersLookup = function(wallet, cb) {
_.each(wallet.copayers, function(copayer) { _.each(wallet.copayers, function(copayer) {
var value = { var value = {
walletId: wallet.id, walletId: wallet.id,
roPubKey: copayer.roPubKey, requestPubKey: copayer.requestPubKey,
rwPubKey: copayer.rwPubKey,
}; };
ops.push({ ops.push({
type: 'put', type: 'put',

9
test/integration/client.js

@ -949,7 +949,7 @@ describe('client API ', function() {
}); });
}); });
it.skip('should be able to sign from airgapped client and broadcast from proxy', function(done) { it('should be able to sign from airgapped client and broadcast from proxy', function(done) {
var airgapped = new AirGapped({ var airgapped = new AirGapped({
network: 'testnet' network: 'testnet'
}); });
@ -993,7 +993,12 @@ describe('client API ', function() {
}, next); }, next);
}, },
function(txps, rawTxps, next) { function(txps, rawTxps, next) {
var signatures = airgapped.signTxProposal(rawTxps[0]); // TODO: these params should be grouped, signed, encrypted, etc
var pkr = proxy.credentials.publicKeyRing;
var m = proxy.credentials.m;
var n = proxy.credentials.n;
var signatures = airgapped.signTxProposal(rawTxps[0], pkr, m, n);
next(null, signatures); next(null, signatures);
}, },
function(signatures, next) { function(signatures, next) {

Loading…
Cancel
Save