trezor sign 1-1 working
This commit is contained in:
parent
4c9385f78b
commit
8eecdd1e86
3 changed files with 63 additions and 40 deletions
|
|
@ -110,7 +110,7 @@
|
||||||
|
|
||||||
<label ng-show="1" for="hw-trezor" class="oh">
|
<label ng-show="1" for="hw-trezor" class="oh">
|
||||||
<span translate>Use TREZOR hardware wallet</span>
|
<span translate>Use TREZOR hardware wallet</span>
|
||||||
<switch id="hw-trezor" name="hwTrezor" ng-model="hwTrezor" ng-change="isTestnet=false" class="green right m5t m10b"></switch>
|
<switch id="hw-trezor" name="hwTrezor" ng-model="hwTrezor" class="green right m5t m10b"></switch>
|
||||||
</label>
|
</label>
|
||||||
<!-- TODO account
|
<!-- TODO account
|
||||||
<div ng-show="hwLedger">
|
<div ng-show="hwLedger">
|
||||||
|
|
|
||||||
|
|
@ -552,8 +552,9 @@ console.log('[profileService.js.239:walletClient:]',walletClient); //TODO
|
||||||
$log.info('Requesting Ledger Chrome app to sign the transaction');
|
$log.info('Requesting Ledger Chrome app to sign the transaction');
|
||||||
|
|
||||||
ledger.signTx(txp, 0, function(result) {
|
ledger.signTx(txp, 0, function(result) {
|
||||||
|
$log.debug('Ledger response',result);
|
||||||
if (!result.success)
|
if (!result.success)
|
||||||
return cb(result);
|
return cb(result.message || result.error);
|
||||||
|
|
||||||
txp.signatures = lodash.map(result.signatures, function(s) {
|
txp.signatures = lodash.map(result.signatures, function(s) {
|
||||||
return s.substring(0, s.length - 2);
|
return s.substring(0, s.length - 2);
|
||||||
|
|
@ -568,13 +569,11 @@ console.log('[profileService.js.239:walletClient:]',walletClient); //TODO
|
||||||
$log.info('Requesting Trezor to sign the transaction');
|
$log.info('Requesting Trezor to sign the transaction');
|
||||||
|
|
||||||
trezor.signTx(txp, 0, function(result) {
|
trezor.signTx(txp, 0, function(result) {
|
||||||
console.log('[profileService.js.570:result:]',result); //TODO
|
$log.debug('Trezor response',result);
|
||||||
if (!result.success)
|
if (!result.success)
|
||||||
return cb(result);
|
return cb(result.error || result);
|
||||||
|
|
||||||
txp.signatures = lodash.map(result.signatures, function(s) {
|
txp.signatures = result.signatures;
|
||||||
return s.substring(0, s.length - 2);
|
|
||||||
});
|
|
||||||
return fc.signTxProposal(txp, cb);
|
return fc.signTxProposal(txp, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ angular.module('copayApp.services')
|
||||||
opts.extendedPublicKey = data.xpubkey;
|
opts.extendedPublicKey = data.xpubkey;
|
||||||
opts.externalSource = 'trezor';
|
opts.externalSource = 'trezor';
|
||||||
opts.externalIndex = account;
|
opts.externalIndex = account;
|
||||||
console.log('[trezor.js.51:opts:]', opts); //TODO
|
|
||||||
return callback(null, opts);
|
return callback(null, opts);
|
||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
@ -60,52 +59,77 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
|
|
||||||
root.signTx = function(txp, account, callback) {
|
root.signTx = function(txp, account, callback) {
|
||||||
|
console.log('[trezor.js.66:txp:]', txp); //TODO
|
||||||
|
|
||||||
|
var inputs = [],
|
||||||
|
outputs = [];
|
||||||
|
var tmpOutputs = [];
|
||||||
|
|
||||||
if (txp.type != 'simple')
|
if (txp.type != 'simple')
|
||||||
return callback('Only simple TXs are supported in TREZOR');
|
return callback('Only TXPs type SIMPLE are supported in TREZOR');
|
||||||
|
|
||||||
|
var toScriptType = 'PAYTOADDRESS';
|
||||||
|
if (txp.toAddress.charAt(0) == '2' || txp.toAddress.charAt(0) == '3')
|
||||||
|
toScriptType = 'PAYTOSCRIPTHASH';
|
||||||
|
|
||||||
|
|
||||||
|
// Add to
|
||||||
|
tmpOutputs.push({
|
||||||
|
address: txp.toAddress,
|
||||||
|
amount: txp.amount,
|
||||||
|
script_type: toScriptType,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log('[trezor.js.90:txp:]', txp); //TODO
|
|
||||||
if (txp.addressType == 'P2PKH') {
|
if (txp.addressType == 'P2PKH') {
|
||||||
var tx = bwcService.getUtils().buildTx(txp);
|
|
||||||
|
|
||||||
// spend one change output
|
var inAmount = 0;
|
||||||
var inputs = lodash.map(txp.inputs, function(i){
|
inputs = lodash.map(txp.inputs, function(i) {
|
||||||
var pathArr = i.path.split('/');
|
var pathArr = i.path.split('/');
|
||||||
console.log('[trezor.js.72:pathArr:]',pathArr); //TODO
|
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])];
|
inAmount += i.satoshis;
|
||||||
console.log('[trezor.js.74]', n); //TODO
|
|
||||||
return {
|
return {
|
||||||
address_n: n,
|
address_n: n,
|
||||||
prev_index: i.vout,
|
prev_index: i.vout,
|
||||||
prev_hash: i.txid,
|
prev_hash: i.txid,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
console.log('[trezor.js.68:inputs:]',inputs); //TODO
|
|
||||||
|
|
||||||
var pathArr = txp.changeAddress.path.split('/');
|
var change = inAmount - txp.fee - txp.amount;
|
||||||
console.log('[trezor.js.82:pathArr:]',pathArr); //TODO
|
if (change > 0) {
|
||||||
var n = [44 | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]) , parseInt(pathArr[2])];
|
var pathArr = txp.changeAddress.path.split('/');
|
||||||
// send to 1 address output and one change output
|
var n = [44 | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
||||||
var outputs = [{
|
|
||||||
address_n: n,
|
tmpOutputs.push({
|
||||||
amount: txp.amount - txp.fee,
|
address_n: n,
|
||||||
script_type: 'PAYTOADDRESS'
|
amount: change,
|
||||||
}, {
|
script_type: 'PAYTOADDRESS'
|
||||||
address: txp.toAddress,
|
});
|
||||||
amount: txp.amount,
|
}
|
||||||
script_type: 'PAYTOADDRESS'
|
|
||||||
}];
|
|
||||||
console.log('[trezor.js.84:outputs:]',outputs); //TODO
|
|
||||||
|
|
||||||
TrezorConnect.signTx(inputs, outputs, function(result) {
|
|
||||||
console.log('[trezor.js.78:result:]', result); //TODO
|
|
||||||
callback(result);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
var msg = 'P2SH wallets are not supported with TREZOR';
|
$log.error('TODO: multisig');
|
||||||
$log.error(msg);
|
|
||||||
return callback(msg);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Shuffle outputs for improved privacy
|
||||||
|
if (tmpOutputs.length > 1) {
|
||||||
|
lodash.each(txp.outputOrder, function(order) {
|
||||||
|
outputs[order] = tmpOutputs.shift();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tmpOutputs.length)
|
||||||
|
return cb("Error creating transaction: tmpOutput order");
|
||||||
|
} else {
|
||||||
|
outputs = tmpOutputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$log.debug('Signing with TREZOR', inputs, outputs);
|
||||||
|
TrezorConnect.signTx(inputs, outputs, function(result) {
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
root._getPath = function(account) {
|
root._getPath = function(account) {
|
||||||
return "44'/0'/" + account + "'";
|
return "44'/0'/" + account + "'";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue