fix pubkey order
This commit is contained in:
parent
fb6e72e911
commit
2a1fcf1e5a
1 changed files with 28 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash) {
|
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash, bitcore) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
var SETTLE_TIME = 3000;
|
var SETTLE_TIME = 3000;
|
||||||
|
|
@ -59,8 +59,28 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root._orderPubKeys = function(xPub, np) {
|
||||||
|
var xPubKeys = lodash.clone(xPub);
|
||||||
|
var path = lodash.clone(np);
|
||||||
|
path.unshift('m');
|
||||||
|
path = path.join('/');
|
||||||
|
|
||||||
|
var keys = lodash.map(xPubKeys, function(x) {
|
||||||
|
var pub = (new bitcore.HDPublicKey(x)).derive(path).publicKey;
|
||||||
|
return {
|
||||||
|
xpub: x,
|
||||||
|
pub: pub.toString('hex'),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
var sorted = lodash.sortBy(keys, function(x) {
|
||||||
|
return x.pub;
|
||||||
|
});
|
||||||
|
|
||||||
|
return lodash.pluck(sorted, 'xpub');
|
||||||
|
};
|
||||||
|
|
||||||
root.signTx = function(xPubKeys, txp, account, callback) {
|
root.signTx = function(xPubKeys, txp, account, callback) {
|
||||||
console.log('[trezor.js.66:txp:]', xPubKeys, txp); //TODO
|
|
||||||
|
|
||||||
var inputs = [],
|
var inputs = [],
|
||||||
outputs = [];
|
outputs = [];
|
||||||
|
|
@ -126,12 +146,13 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
inAmount += i.satoshis;
|
inAmount += i.satoshis;
|
||||||
|
|
||||||
var pubkeys = xPubKeys.map(function(v) {
|
var orderedPubKeys = root._orderPubKeys(xPubKeys, np);
|
||||||
|
var pubkeys = lodash(orderedPubKeys.map(function(v) {
|
||||||
return {
|
return {
|
||||||
node: v,
|
node: v,
|
||||||
address_n: np,
|
address_n: np,
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
address_n: n,
|
address_n: n,
|
||||||
|
|
@ -152,12 +173,13 @@ angular.module('copayApp.services')
|
||||||
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 np = n.slice(3);
|
||||||
|
|
||||||
var pubkeys = xPubKeys.map(function(v) {
|
var orderedPubKeys = root._orderPubKeys(xPubKeys, np);
|
||||||
|
var pubkeys = lodash(orderedPubKeys.map(function(v) {
|
||||||
return {
|
return {
|
||||||
node: v,
|
node: v,
|
||||||
address_n: np,
|
address_n: np,
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
|
|
||||||
// 6D
|
// 6D
|
||||||
// 6C
|
// 6C
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue