trezor multisig WIP

This commit is contained in:
Matias Alejo Garcia 2015-10-02 12:01:57 -03:00
parent f2deba10ec
commit fb6e72e911
4 changed files with 38 additions and 16 deletions

View File

@ -73,9 +73,9 @@ angular.module('copayApp.controllers').controller('createController',
}
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Leger' : 'TREZOR';
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? leger : trezor;
var src= form.hwLedger.$modelValue ? ledger : trezor;
// TODO : account
var account = 0;

View File

@ -42,8 +42,8 @@ angular.module('copayApp.controllers').controller('joinController',
}
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
self.hwWallet = form.hwLedger.$modelValue ? 'Leger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? leger : trezor;
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
var src= form.hwLedger.$modelValue ? ledger : trezor;
var account = 0;
src.getInfoForNewWallet(account, function(err, lopts) {

View File

@ -4,6 +4,8 @@ angular.module('copayApp.services')
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash) {
var root = {};
var SETTLE_TIME = 3000;
root.ENTROPY_INDEX_PATH = "0xb11e/";
root.callbacks = {};
@ -53,11 +55,10 @@ angular.module('copayApp.services')
opts.externalIndex = account;
return callback(null, opts);
});
}, 5000);
}, SETTLE_TIME);
});
};
root.signTx = function(xPubKeys, txp, account, callback) {
console.log('[trezor.js.66:txp:]', xPubKeys, txp); //TODO
@ -121,16 +122,16 @@ angular.module('copayApp.services')
inputs = lodash.map(txp.inputs, function(i) {
var pathArr = i.path.split('/');
var n = [44 | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
// var np = [parseInt(pathArr[1]), parseInt(pathArr[2])];
var np = n.slice(3);
inAmount += i.satoshis;
var pubkeys = lodash(xPubKeys.map(function(v) {
var pubkeys = xPubKeys.map(function(v) {
return {
node: v,
address_n: n,
address_n: np,
};
})).reverse().value();
console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
});
return {
address_n: n,
@ -149,13 +150,26 @@ console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
if (change > 0) {
var pathArr = txp.changeAddress.path.split('/');
var n = [44 | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
var np = n.slice(3);
var pubkeys = lodash(xPubKeys.map(function(v) {
var pubkeys = xPubKeys.map(function(v) {
return {
node: v,
address_n: n,
address_n: np,
};
})).reverse().value();
});
// 6D
// 6C
// Addr: 3HFkHufeSaqJtqby8G9RiajaL6HdQDypRT
//
//
//(sin reverse)
// 6C
// 6D
// Addr: 3KCPRDXpmovs9nFvJHJjjsyoBDXXUZ2Frg
// "asm" : "2 03e53b2f69e1705b253029aae2591fbd0e799ed8071c8588a545b2d472dd12df88 0379797abc21d6f82c7f0aba78fd3888d8ae75ec56a10509b20feedbeac20285d9 2 OP_CHECKMULTISIG",
//
tmpOutputs.push({
address_n: n,
@ -172,6 +186,7 @@ console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
// Shuffle outputs for improved privacy
if (tmpOutputs.length > 1) {
outputs = new Array(tmpOutputs.length);
lodash.each(txp.outputOrder, function(order) {
outputs[order] = tmpOutputs.shift();
});
@ -182,6 +197,9 @@ console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
outputs = tmpOutputs;
}
// Prevents: Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned.
inputs = JSON.parse(JSON.stringify(inputs));
outputs = JSON.parse(JSON.stringify(outputs));
$log.debug('Signing with TREZOR', inputs, outputs);
TrezorConnect.signTx(inputs, outputs, function(result) {

View File

@ -49,15 +49,18 @@ window.TrezorConnect = (function () {
* @param {boolean} success
* @param {?string} error
* @param {?string} xpubkey serialized extended public key
* @param {?string} path BIP32 serializd path of the key
*/
/**
* Load BIP32 extended public key by path.
*
* Path can be specified either in the string form ("m/44'/1/0") or as
* raw integer array.
* raw integer array. In case you omit the path, user is asked to select
* a BIP32 account to export, and the result contains m/44'/0'/x' node
* of the account.
*
* @param {string|array<number>} path
* @param {?(string|array<number>)} path
* @param {function(XPubKeyResult)} callback
*/
this.getXPubKey = function (path, callback) {
@ -265,6 +268,7 @@ window.TrezorConnect = (function () {
};
this.send = function (value, callback) {
console.log('[trezor.js.270:value:]',value); //TODO
if (waiting === null) {
waiting = callback;
target.postMessage(value, origin);