trezor multisig WIP
This commit is contained in:
parent
f2deba10ec
commit
fb6e72e911
4 changed files with 38 additions and 16 deletions
|
|
@ -73,9 +73,9 @@ angular.module('copayApp.controllers').controller('createController',
|
||||||
}
|
}
|
||||||
|
|
||||||
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
|
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
|
// TODO : account
|
||||||
var account = 0;
|
var account = 0;
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ angular.module('copayApp.controllers').controller('joinController',
|
||||||
}
|
}
|
||||||
|
|
||||||
if (form.hwLedger.$modelValue || form.hwTrezor.$modelValue) {
|
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;
|
||||||
|
|
||||||
var account = 0;
|
var account = 0;
|
||||||
src.getInfoForNewWallet(account, function(err, lopts) {
|
src.getInfoForNewWallet(account, function(err, lopts) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ angular.module('copayApp.services')
|
||||||
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash) {
|
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
|
var SETTLE_TIME = 3000;
|
||||||
|
|
||||||
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
||||||
root.callbacks = {};
|
root.callbacks = {};
|
||||||
|
|
||||||
|
|
@ -53,11 +55,10 @@ angular.module('copayApp.services')
|
||||||
opts.externalIndex = account;
|
opts.externalIndex = account;
|
||||||
return callback(null, opts);
|
return callback(null, opts);
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, SETTLE_TIME);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root.signTx = function(xPubKeys, txp, account, callback) {
|
root.signTx = function(xPubKeys, txp, account, callback) {
|
||||||
console.log('[trezor.js.66:txp:]', xPubKeys, txp); //TODO
|
console.log('[trezor.js.66:txp:]', xPubKeys, txp); //TODO
|
||||||
|
|
||||||
|
|
@ -121,16 +122,16 @@ angular.module('copayApp.services')
|
||||||
inputs = lodash.map(txp.inputs, function(i) {
|
inputs = lodash.map(txp.inputs, function(i) {
|
||||||
var pathArr = i.path.split('/');
|
var pathArr = i.path.split('/');
|
||||||
var n = [44 | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
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;
|
inAmount += i.satoshis;
|
||||||
|
|
||||||
var pubkeys = lodash(xPubKeys.map(function(v) {
|
var pubkeys = xPubKeys.map(function(v) {
|
||||||
return {
|
return {
|
||||||
node: v,
|
node: v,
|
||||||
address_n: n,
|
address_n: np,
|
||||||
};
|
};
|
||||||
})).reverse().value();
|
});
|
||||||
console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
address_n: n,
|
address_n: n,
|
||||||
|
|
@ -149,13 +150,26 @@ console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
|
||||||
if (change > 0) {
|
if (change > 0) {
|
||||||
var pathArr = txp.changeAddress.path.split('/');
|
var pathArr = txp.changeAddress.path.split('/');
|
||||||
var n = [44 | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
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 {
|
return {
|
||||||
node: v,
|
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({
|
tmpOutputs.push({
|
||||||
address_n: n,
|
address_n: n,
|
||||||
|
|
@ -172,6 +186,7 @@ console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
|
||||||
|
|
||||||
// Shuffle outputs for improved privacy
|
// Shuffle outputs for improved privacy
|
||||||
if (tmpOutputs.length > 1) {
|
if (tmpOutputs.length > 1) {
|
||||||
|
outputs = new Array(tmpOutputs.length);
|
||||||
lodash.each(txp.outputOrder, function(order) {
|
lodash.each(txp.outputOrder, function(order) {
|
||||||
outputs[order] = tmpOutputs.shift();
|
outputs[order] = tmpOutputs.shift();
|
||||||
});
|
});
|
||||||
|
|
@ -182,6 +197,9 @@ console.log('[trezor.js.121:pubkeys:]',pubkeys); //TODO
|
||||||
outputs = tmpOutputs;
|
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);
|
$log.debug('Signing with TREZOR', inputs, outputs);
|
||||||
TrezorConnect.signTx(inputs, outputs, function(result) {
|
TrezorConnect.signTx(inputs, outputs, function(result) {
|
||||||
|
|
|
||||||
|
|
@ -49,15 +49,18 @@ window.TrezorConnect = (function () {
|
||||||
* @param {boolean} success
|
* @param {boolean} success
|
||||||
* @param {?string} error
|
* @param {?string} error
|
||||||
* @param {?string} xpubkey serialized extended public key
|
* @param {?string} xpubkey serialized extended public key
|
||||||
|
* @param {?string} path BIP32 serializd path of the key
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load BIP32 extended public key by path.
|
* Load BIP32 extended public key by path.
|
||||||
*
|
*
|
||||||
* Path can be specified either in the string form ("m/44'/1/0") or as
|
* 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
|
* @param {function(XPubKeyResult)} callback
|
||||||
*/
|
*/
|
||||||
this.getXPubKey = function (path, callback) {
|
this.getXPubKey = function (path, callback) {
|
||||||
|
|
@ -265,6 +268,7 @@ window.TrezorConnect = (function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.send = function (value, callback) {
|
this.send = function (value, callback) {
|
||||||
|
console.log('[trezor.js.270:value:]',value); //TODO
|
||||||
if (waiting === null) {
|
if (waiting === null) {
|
||||||
waiting = callback;
|
waiting = callback;
|
||||||
target.postMessage(value, origin);
|
target.postMessage(value, origin);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue