WIP trezor 48
This commit is contained in:
parent
47752fbe1e
commit
d1c1638b14
7 changed files with 141 additions and 104 deletions
|
|
@ -99,8 +99,17 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div ng-hide="hideAdv" class="row">
|
<div ng-hide="hideAdv" class="row">
|
||||||
<div class="large-12 columns">
|
|
||||||
|
|
||||||
|
<div class="large-12 medium-12 columns">
|
||||||
|
<label><span translate>Wallet Seed</span>
|
||||||
|
<select class="m10t" ng-model="seedSource"
|
||||||
|
ng-options="seed as seed.label for seed in create.seedOptions"
|
||||||
|
ng-change="create.setSeedSource()">
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="large-12 columns">
|
||||||
<label ng-show="index.isChromeApp && totalCopayers > 1 " for="hw-ledger" class="oh">
|
<label ng-show="index.isChromeApp && totalCopayers > 1 " for="hw-ledger" class="oh">
|
||||||
<span translate>Use Ledger hardware wallet</span>
|
<span translate>Use Ledger hardware wallet</span>
|
||||||
<switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" ng-change="isTestnet=false" class="green right m5t m10b"></switch>
|
<switch id="hw-ledger" name="hwLedger" ng-model="hwLedger" ng-change="isTestnet=false" class="green right m5t m10b"></switch>
|
||||||
|
|
@ -124,26 +133,21 @@
|
||||||
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
|
<switch id="network-name" name="isTestnet" ng-model="isTestnet" class="green right m5t m10b"></switch>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label ng-show="!hwLedger && !hwTrezor" for="seed" class="oh">
|
<label for="createPassphrase" class="oh" ng-show="create.seedSourceId=='new' " ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small>
|
||||||
<span translate>Specify your wallet seed</span>
|
|
||||||
<switch id="seed" name="setSeed" ng-model="setSeed" class="green right m5t m10b"></switch>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label for="createPassphrase" class="oh" ng-hide="setSeed || hwLedger || hwTrezor" ><span translate>Add a Seed Passphrase</span> <small translate>Add an optional passphrase to secure the seed</small>
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input type="text" class="form-control"
|
<input type="text" class="form-control"
|
||||||
name="createPassphrase" ng-model="createPassphrase">
|
name="createPassphrase" ng-model="createPassphrase">
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label for="ext-master" class="m10t" ng-show="setSeed">
|
<label for="ext-master" class="m10t" ng-show="create.seedSourceId=='set'">
|
||||||
<span translate>Wallet Seed</span>
|
<span translate>Wallet Seed</span>
|
||||||
<small translate>Enter the seed words (BIP39)</small>
|
<small translate>Enter the seed words (BIP39)</small>
|
||||||
<input id="ext-master"
|
<input id="ext-master"
|
||||||
type="text"
|
type="text"
|
||||||
name="privateKey" ng-model="privateKey">
|
name="privateKey" ng-model="privateKey">
|
||||||
</label>
|
</label>
|
||||||
<label for="passphrase" class="oh" ng-show="setSeed"><span translate>Seed Passphrase</span> <small translate>The seed could require a passphrase to be imported</small>
|
<label for="passphrase" class="oh" ng-show="create.seedSourceId=='set'"><span translate>Seed Passphrase</span> <small translate>The seed could require a passphrase to be imported</small>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input type="text" class="form-control" name="passphrase" ng-model="passphrase">
|
<input type="text" class="form-control" name="passphrase" ng-model="passphrase">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('createController',
|
angular.module('copayApp.controllers').controller('createController',
|
||||||
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile) {
|
function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile, isChromeApp) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var defaults = configService.getDefaults();
|
var defaults = configService.getDefaults();
|
||||||
|
|
@ -38,11 +38,48 @@ angular.module('copayApp.controllers').controller('createController',
|
||||||
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var updateSeedSourceSelect = function(n) {
|
||||||
|
|
||||||
|
self.seedOptions = [{
|
||||||
|
id: 'new',
|
||||||
|
label: gettext('New Random Seed'),
|
||||||
|
}, {
|
||||||
|
id: 'set',
|
||||||
|
label: gettext('Specify Seed...'),
|
||||||
|
}];
|
||||||
|
$scope.seedSource = self.seedOptions[0];
|
||||||
|
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// if (!isChromeApp) return;
|
||||||
|
|
||||||
|
if (n > 1)
|
||||||
|
self.seedOptions.push({
|
||||||
|
id: 'ledger',
|
||||||
|
label: gettext('Ledger Hardware Wallet'),
|
||||||
|
});
|
||||||
|
|
||||||
|
self.seedOptions.push({
|
||||||
|
id: 'trezor',
|
||||||
|
label: gettext('Trezor Hardware Wallet'),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
|
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
|
||||||
$scope.totalCopayers = defaults.wallet.totalCopayers;
|
$scope.totalCopayers = defaults.wallet.totalCopayers;
|
||||||
|
|
||||||
this.setTotalCopayers = function(tc) {
|
this.setTotalCopayers = function(tc) {
|
||||||
updateRCSelect(tc);
|
updateRCSelect(tc);
|
||||||
|
updateSeedSourceSelect(tc);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.setSeedSource = function(src) {
|
||||||
|
self.seedSourceId = $scope.seedSource.id;
|
||||||
|
console.log('[create.js.78:seedSourceId:]',self.seedSourceId); //TODO
|
||||||
|
$timeout(function() {
|
||||||
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.create = function(form) {
|
this.create = function(form) {
|
||||||
|
|
@ -81,9 +118,8 @@ angular.module('copayApp.controllers').controller('createController',
|
||||||
|
|
||||||
var src = form.hwLedger.$modelValue ? ledger : trezor;
|
var src = form.hwLedger.$modelValue ? ledger : trezor;
|
||||||
|
|
||||||
// TODO : account
|
var account = form.account.$modelValue;
|
||||||
var account = 0;
|
src.getInfoForNewWallet(opts.n > 1, account, function(err, lopts) {
|
||||||
src.getInfoForNewWallet(account, function(err, lopts) {
|
|
||||||
self.hwWallet = false;
|
self.hwWallet = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
|
|
@ -141,4 +177,5 @@ angular.module('copayApp.controllers').controller('createController',
|
||||||
$scope.$on("$destroy", function() {
|
$scope.$on("$destroy", function() {
|
||||||
$rootScope.hideWalletNavigation = false;
|
$rootScope.hideWalletNavigation = false;
|
||||||
});
|
});
|
||||||
|
updateSeedSourceSelect(1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -188,8 +188,10 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.hwWallet = 'Trezor';
|
self.hwWallet = 'Trezor';
|
||||||
// TODO account
|
var account = form.account.$modelValue;
|
||||||
trezor.getInfoForNewWallet(0, function(err, lopts) {
|
var isMultisig = form.isMultisig.$modelValue;
|
||||||
|
|
||||||
|
trezor.getInfoForNewWallet(isMultisig, account, function(err, lopts) {
|
||||||
self.hwWallet = false;
|
self.hwWallet = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
|
|
@ -227,8 +229,8 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.hwWallet = 'Ledger';
|
self.hwWallet = 'Ledger';
|
||||||
// TODO account
|
var account = form.account.$modelValue;
|
||||||
ledger.getInfoForNewWallet(0, function(err, lopts) {
|
ledger.getInfoForNewWallet(true, account, function(err, lopts) {
|
||||||
self.hwWallet = false;
|
self.hwWallet = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ 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 ? 'Ledger' : 'TREZOR';
|
self.hwWallet = form.hwLedger.$modelValue ? 'Ledger' : 'TREZOR';
|
||||||
var src = form.hwLedger.$modelValue ? ledger : trezor;
|
var src = form.hwLedger.$modelValue ? ledger : trezor;
|
||||||
|
var account = form.account.$modelValue;
|
||||||
|
|
||||||
var account = 0;
|
src.getInfoForNewWallet(true, account, function(err, lopts) {
|
||||||
src.getInfoForNewWallet(account, function(err, lopts) {
|
|
||||||
self.hwWallet = false;
|
self.hwWallet = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err;
|
self.error = err;
|
||||||
|
|
|
||||||
38
src/js/services/hwWallet.js
Normal file
38
src/js/services/hwWallet.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services')
|
||||||
|
.factory('hwWallet', function($log) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
// Ledger magic number to get xPub without user confirmation
|
||||||
|
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
||||||
|
root.UNISIG_ROOTPATH = 44;
|
||||||
|
root.MULTISIG_ROOTPATH = 48;
|
||||||
|
root.LIVENET_PATH = 0;
|
||||||
|
|
||||||
|
root._err = function(data) {
|
||||||
|
var msg = 'HW WALLET Error: ' + (data.error || data.message || 'unknown');
|
||||||
|
$log.warn(msg);
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getAddressPath = function(isMultisig, account) {
|
||||||
|
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH;
|
||||||
|
return rootPath + "'/" + root.LIVENET_PATH + "'/" + account + "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
root.getEntropyPath = function(isMultisig, account) {
|
||||||
|
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH;
|
||||||
|
var path = hwWallet.ENTROPY_INDEX_PATH + rootPath + "'/"
|
||||||
|
account + "'";
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
root.pubKeyToEntropySource = function(xPubKey) {
|
||||||
|
var b = bwcService.getBitcore();
|
||||||
|
var x = b.HDPublicKey(xPubKey);
|
||||||
|
return x.publicKey.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
|
|
@ -7,6 +7,8 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
// Ledger magic number to get xPub without user confirmation
|
// Ledger magic number to get xPub without user confirmation
|
||||||
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
||||||
|
root.UNISIG_ROOTPATH = 44;
|
||||||
|
root.MULTISIG_ROOTPATH = 48;
|
||||||
|
|
||||||
root.callbacks = {};
|
root.callbacks = {};
|
||||||
|
|
||||||
|
|
@ -16,28 +18,17 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
root.getEntropySource = function(account, callback) {
|
|
||||||
var path = root.ENTROPY_INDEX_PATH + account + "'";
|
|
||||||
var xpub = root.getXPubKey(path, function(data) {
|
|
||||||
if (!data.success) {
|
|
||||||
$log.warn(data.message);
|
|
||||||
return callback(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
var b = bwcService.getBitcore();
|
root.getEntropySource = function(isMultisig, account, callback) {
|
||||||
|
root.getXPubKey(hwWallet.getEntropyPath(isMultisig, account), function(data) {
|
||||||
|
if (!data.success)
|
||||||
|
return callback(hwWallet._err(data));
|
||||||
|
|
||||||
var x = b.HDPublicKey(data.xpubkey);
|
return callback(null, hwWallet.pubKeyToEntropySource(data.xpubkey));
|
||||||
data.entropySource = x.publicKey.toString();
|
|
||||||
return callback(data);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getXPubKeyForAddresses = function(account, callback) {
|
|
||||||
return root.getXPubKey(root._getPath(account), callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getXPubKey = function(path, callback) {
|
root.getXPubKey = function(path, callback) {
|
||||||
|
|
||||||
$log.debug('Ledger deriving xPub path:', path);
|
$log.debug('Ledger deriving xPub path:', path);
|
||||||
root.callbacks["get_xpubkey"] = callback;
|
root.callbacks["get_xpubkey"] = callback;
|
||||||
root._messageAfterSession({
|
root._messageAfterSession({
|
||||||
|
|
@ -47,15 +38,13 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root.getInfoForNewWallet = function(account, callback) {
|
root.getInfoForNewWallet = function(isMultisig, account, callback) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
root.getEntropySource(account, function(data) {
|
root.getEntropySource(isMultisig, account, function(entropySource) {
|
||||||
if (!data.success) {
|
if (err) return callback(err);
|
||||||
$log.warn(data.message);
|
|
||||||
return callback(data.message);
|
opts.entropySource = entropySource;
|
||||||
}
|
root.getXPubKey(hwWallet.getAddressPath(isMultisig, account), function(data) {
|
||||||
opts.entropySource = data.entropySource;
|
|
||||||
root.getXPubKeyForAddresses(account, function(data) {
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
$log.warn(data.message);
|
$log.warn(data.message);
|
||||||
return callback(data);
|
return callback(data);
|
||||||
|
|
@ -68,14 +57,15 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root._signP2SH = function(txp, account, callback) {
|
root._signP2SH = function(txp, account, isMultisig, callback) {
|
||||||
root.callbacks["sign_p2sh"] = callback;
|
root.callbacks["sign_p2sh"] = callback;
|
||||||
var redeemScripts = [];
|
var redeemScripts = [];
|
||||||
var paths = [];
|
var paths = [];
|
||||||
|
|
||||||
var tx = bwcService.getUtils().buildTx(txp);
|
var tx = bwcService.getUtils().buildTx(txp);
|
||||||
for (var i = 0; i < tx.inputs.length; i++) {
|
for (var i = 0; i < tx.inputs.length; i++) {
|
||||||
redeemScripts.push(new ByteString(tx.inputs[i].redeemScript.toBuffer().toString('hex'), GP.HEX).toString());
|
redeemScripts.push(new ByteString(tx.inputs[i].redeemScript.toBuffer().toString('hex'), GP.HEX).toString());
|
||||||
paths.push(root._getPath(account) + txp.inputs[i].path.substring(1));
|
paths.push(hwWallet.getAddressPath(isMultisig, account) + txp.inputs[i].path.substring(1));
|
||||||
}
|
}
|
||||||
var splitTransaction = root._splitTransaction(new ByteString(tx.toString(), GP.HEX));
|
var splitTransaction = root._splitTransaction(new ByteString(tx.toString(), GP.HEX));
|
||||||
var inputs = [];
|
var inputs = [];
|
||||||
|
|
@ -98,12 +88,15 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.signTx = function(txp, account, callback) {
|
root.signTx = function(txp, account, callback) {
|
||||||
|
|
||||||
|
// TODO Compat
|
||||||
|
var isMultisig = true;
|
||||||
if (txp.addressType == 'P2PKH') {
|
if (txp.addressType == 'P2PKH') {
|
||||||
var msg = 'P2PKH wallets are not supported with ledger';
|
var msg = 'P2PKH wallets are not supported with ledger';
|
||||||
$log.error(msg);
|
$log.error(msg);
|
||||||
return callback(msg);
|
return callback(msg);
|
||||||
} else {
|
} else {
|
||||||
root._signP2SH(txp, account, callback);
|
root._signP2SH(txp, account, isMultisig, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,10 +147,6 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root._getPath = function(account) {
|
|
||||||
return "44'/0'/" + account + "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
root._splitTransaction = function(transaction) {
|
root._splitTransaction = function(transaction) {
|
||||||
var result = {};
|
var result = {};
|
||||||
var inputs = [];
|
var inputs = [];
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,21 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash, bitcore) {
|
.factory('trezor', function($log, $timeout, bwcService, gettext, lodash, bitcore, hwWallet) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
var SETTLE_TIME = 3000;
|
var SETTLE_TIME = 3000;
|
||||||
|
|
||||||
root.ENTROPY_INDEX_PATH = "0xb11e/";
|
|
||||||
root.callbacks = {};
|
root.callbacks = {};
|
||||||
|
|
||||||
|
root.getEntropySource = function(isMultisig, account, callback) {
|
||||||
|
root.getXPubKey(hwWallet.getEntropyPath(isMultisig, account), function(data) {
|
||||||
|
if (!data.success)
|
||||||
|
return callback(hwWallet._err(data));
|
||||||
|
|
||||||
root._err = function(data) {
|
return callback(null, hwWallet.pubKeyToEntropySource(data.xpubkey));
|
||||||
var msg = 'TREZOR Error: ' + (data.error || data.message || 'unknown');
|
|
||||||
$log.warn(msg);
|
|
||||||
return msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getEntropySource = function(account, callback) {
|
|
||||||
var path = root.ENTROPY_INDEX_PATH + account + "'";
|
|
||||||
var xpub = root.getXPubKey(path, function(data) {
|
|
||||||
if (!data.success) {
|
|
||||||
return callback(root._err(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
var b = bwcService.getBitcore();
|
|
||||||
|
|
||||||
var x = b.HDPublicKey(data.xpubkey);
|
|
||||||
data.entropySource = x.publicKey.toString();
|
|
||||||
return callback(null, data);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getXPubKeyForAddresses = function(account, callback) {
|
|
||||||
return root.getXPubKey(root._getPath(account), callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getXPubKey = function(path, callback) {
|
root.getXPubKey = function(path, callback) {
|
||||||
$log.debug('TREZOR deriving xPub path:', path);
|
$log.debug('TREZOR deriving xPub path:', path);
|
||||||
|
|
@ -41,16 +23,17 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root.getInfoForNewWallet = function(account, callback) {
|
root.getInfoForNewWallet = function(isMultisig, account, callback) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
root.getEntropySource(account, function(err, data) {
|
root.getEntropySource(isMultisig, account, function(err, data) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
opts.entropySource = data.entropySource;
|
opts.entropySource = data.entropySource;
|
||||||
$log.debug('Waiting TREZOR to settle...');
|
$log.debug('Waiting TREZOR to settle...');
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
root.getXPubKeyForAddresses(account, function(data) {
|
|
||||||
|
root.getXPubKey(hwWallet.getAddressPath(isMultisig, account), function(data) {
|
||||||
if (!data.success)
|
if (!data.success)
|
||||||
return callback(root._err(data));
|
return callback(hwWallet._err(data));
|
||||||
|
|
||||||
opts.extendedPublicKey = data.xpubkey;
|
opts.extendedPublicKey = data.xpubkey;
|
||||||
opts.externalSource = 'trezor';
|
opts.externalSource = 'trezor';
|
||||||
|
|
@ -110,7 +93,7 @@ angular.module('copayApp.services')
|
||||||
var inAmount = 0;
|
var inAmount = 0;
|
||||||
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 = [hwWallet.UNISIG_ROOTPATH | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
||||||
inAmount += i.satoshis;
|
inAmount += i.satoshis;
|
||||||
return {
|
return {
|
||||||
address_n: n,
|
address_n: n,
|
||||||
|
|
@ -122,7 +105,7 @@ angular.module('copayApp.services')
|
||||||
var change = inAmount - txp.fee - txp.amount;
|
var change = inAmount - txp.fee - txp.amount;
|
||||||
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 = [hwWallet.UNISIG_ROOTPATH | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
||||||
|
|
||||||
tmpOutputs.push({
|
tmpOutputs.push({
|
||||||
address_n: n,
|
address_n: n,
|
||||||
|
|
@ -133,7 +116,7 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// P2SH Wallet
|
// P2SH Wallet, multisig wallet
|
||||||
var inAmount = 0;
|
var inAmount = 0;
|
||||||
|
|
||||||
var sigs = xPubKeys.map(function(v) {
|
var sigs = xPubKeys.map(function(v) {
|
||||||
|
|
@ -143,7 +126,7 @@ 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 = [hwWallet.MULTISIG_ROOTPATH | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
||||||
var np = n.slice(3);
|
var np = n.slice(3);
|
||||||
|
|
||||||
inAmount += i.satoshis;
|
inAmount += i.satoshis;
|
||||||
|
|
@ -172,7 +155,7 @@ angular.module('copayApp.services')
|
||||||
var change = inAmount - txp.fee - txp.amount;
|
var change = inAmount - txp.fee - txp.amount;
|
||||||
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 = [hwWallet.MULTISIG_ROOTPATH | 0x80000000, 0 | 0x80000000, account | 0x80000000, parseInt(pathArr[1]), parseInt(pathArr[2])];
|
||||||
var np = n.slice(3);
|
var np = n.slice(3);
|
||||||
|
|
||||||
var orderedPubKeys = root._orderPubKeys(xPubKeys, np);
|
var orderedPubKeys = root._orderPubKeys(xPubKeys, np);
|
||||||
|
|
@ -183,18 +166,6 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 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,
|
||||||
amount: change,
|
amount: change,
|
||||||
|
|
@ -228,15 +199,11 @@ angular.module('copayApp.services')
|
||||||
$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) {
|
||||||
if (!data.success)
|
if (!data.success)
|
||||||
return callback(root._err(data));
|
return callback(hwWallet._err(data));
|
||||||
|
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root._getPath = function(account) {
|
|
||||||
return "44'/0'/" + account + "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue