refactor ledger signature, restrict ledger to m-n, n>1
This commit is contained in:
parent
78e6120e55
commit
7d4fee4aef
7 changed files with 61 additions and 105 deletions
|
|
@ -17,7 +17,7 @@
|
||||||
"ng-lodash": "~0.2.0",
|
"ng-lodash": "~0.2.0",
|
||||||
"angular-moment": "0.10.1",
|
"angular-moment": "0.10.1",
|
||||||
"moment": "2.10.3",
|
"moment": "2.10.3",
|
||||||
"angular-bitcore-wallet-client": "0.2.2",
|
"angular-bitcore-wallet-client": "0.3.0",
|
||||||
"angular-ui-router": "~0.2.13",
|
"angular-ui-router": "~0.2.13",
|
||||||
"qrcode-decoder-js": "*",
|
"qrcode-decoder-js": "*",
|
||||||
"fastclick": "*",
|
"fastclick": "*",
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div ng-hide="hideAdv" class="row">
|
<div ng-hide="hideAdv" class="row">
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<label ng-show="create.isChromeApp()" for="hw-ledger" class="oh">
|
<label ng-show="create.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>
|
||||||
</label>
|
</label>
|
||||||
<!-- account
|
<!-- TODO account
|
||||||
<div ng-show="hwLedger">
|
<div ng-show="hwLedger">
|
||||||
<label class="oh"><span translate>Ledger Slot</span>
|
<label class="oh"><span translate>Ledger Slot</span>
|
||||||
<select class="m10t" ng-model="externalIndex" ng-options="externalIndex as externalIndex for externalIndex in create.externalIndexValues">
|
<select class="m10t" ng-model="externalIndex" ng-options="externalIndex as externalIndex for externalIndex in create.externalIndexValues">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<span ng-show="index.network != 'livenet'"> Testnet </span>
|
<span ng-show="index.network != 'livenet'"> Testnet </span>
|
||||||
<span ng-show="!index.canSign && !index.isPrivKeyExternal" translate>No Private key</span>
|
<span ng-show="!index.canSign && !index.isPrivKeyExternal" translate>No Private key</span>
|
||||||
<span ng-show="index.isPrivKeyExternal" style="text-transform: capitalize">
|
<div ng-show="index.isPrivKeyExternal" style="text-transform: capitalize">
|
||||||
<span translate>External Private Key:</span>
|
<span translate>External Private Key:</span>
|
||||||
{{index.externalSource}}
|
{{index.externalSource}}
|
||||||
</span>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -100,21 +100,21 @@ angular.module('copayApp.controllers').controller('createController',
|
||||||
profileService.createWallet(opts, function(err, secret, walletId) {
|
profileService.createWallet(opts, function(err, secret, walletId) {
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err == "Error creating wallet" && opts.extendedPublicKey) {
|
|
||||||
err = gettext("This xpub index is already used by another wallet. Please select another index.");
|
|
||||||
}
|
|
||||||
$log.warn(err);
|
$log.warn(err);
|
||||||
self.error = err;
|
self.error = err;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
if (opts.n == 1 && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
|
}
|
||||||
|
if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) {
|
||||||
|
if (opts.n == 1) {
|
||||||
$rootScope.$emit('Local/WalletImported', walletId);
|
$rootScope.$emit('Local/WalletImported', walletId);
|
||||||
} else {
|
} else {
|
||||||
go.walletHome();
|
$rootScope.$emit('Local/BackupDone', walletId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
go.walletHome();
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var GLIDERA_LOCK_TIME = 6 * 60 * 60 ;
|
var GLIDERA_LOCK_TIME = 6 * 60 * 60;
|
||||||
// isGlidera flag is a security mesure so glidera status is not
|
// isGlidera flag is a security mesure so glidera status is not
|
||||||
// only determined by the tx.message
|
// only determined by the tx.message
|
||||||
this.openTxpModal = function(tx, copayers, isGlidera) {
|
this.openTxpModal = function(tx, copayers, isGlidera) {
|
||||||
|
|
@ -192,7 +192,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
if (tx.message === 'Glidera transaction' && isGlidera) {
|
if (tx.message === 'Glidera transaction' && isGlidera) {
|
||||||
tx.isGlidera = true;
|
tx.isGlidera = true;
|
||||||
if (tx.canBeRemoved) {
|
if (tx.canBeRemoved) {
|
||||||
tx.canBeRemoved = (Date.now()/1000 - (tx.ts || tx.createdOn)) > GLIDERA_LOCK_TIME;
|
tx.canBeRemoved = (Date.now() / 1000 - (tx.ts || tx.createdOn)) > GLIDERA_LOCK_TIME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$scope.tx = tx;
|
$scope.tx = tx;
|
||||||
|
|
@ -257,41 +257,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
self._setOngoingForSigning();
|
||||||
|
|
||||||
if (fc.isPrivKeyExternal()) {
|
|
||||||
if (fc.getPrivKeyExternalSourceName() == 'ledger') {
|
|
||||||
$log.debug('Requesting Ledger Chrome app to sign the transaction');
|
|
||||||
self.setOngoingProcess(gettext('Requesting Ledger Wallet to sign'));
|
|
||||||
$scope.loading = true;
|
|
||||||
$scope.error = null;
|
|
||||||
// TODO account
|
|
||||||
ledger.signTx(txp, 0, function(result) {
|
|
||||||
if (result.success) {
|
|
||||||
txp.signatures = [];
|
|
||||||
for (var i=0; i<result.signatures.length; i++) {
|
|
||||||
txp.signatures.push(result.signatures[i].substring(0, result.signatures[i].length - 2));
|
|
||||||
}
|
|
||||||
$scope._doSign(txp);
|
|
||||||
} else {
|
|
||||||
$scope.loading = false;
|
|
||||||
$scope.error = result.message;
|
|
||||||
self.setOngoingProcess();
|
|
||||||
$scope.$digest();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$scope._doSign(txp);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope._doSign = function(txp) {
|
|
||||||
self.setOngoingProcess(gettext('Signing payment'));
|
|
||||||
$scope.loading = true;
|
$scope.loading = true;
|
||||||
$scope.error = null;
|
$scope.error = null;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
fc.signTxProposal(txp, function(err, txpsi) {
|
profileService.signTxProposal(txp, function(err, txpsi) {
|
||||||
profileService.lockFC();
|
|
||||||
self.setOngoingProcess();
|
self.setOngoingProcess();
|
||||||
if (err) {
|
if (err) {
|
||||||
$scope.$emit('UpdateTx');
|
$scope.$emit('UpdateTx');
|
||||||
|
|
@ -802,7 +773,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
return self.setSendError(err);
|
return self.setSendError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fc.canSign() && !fc.isPrivKeyExternal()) {
|
if (!fc.canSign() && !fc.isPrivKeyExternal()) {
|
||||||
$log.info('No signing proposal: No private key')
|
$log.info('No signing proposal: No private key')
|
||||||
self.setOngoingProcess();
|
self.setOngoingProcess();
|
||||||
self.resetForm();
|
self.resetForm();
|
||||||
|
|
@ -814,7 +785,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
|
|
||||||
self.signAndBroadcast(txp, function(err) {
|
self.signAndBroadcast(txp, function(err) {
|
||||||
self.setOngoingProcess();
|
self.setOngoingProcess();
|
||||||
profileService.lockFC();
|
|
||||||
self.resetForm();
|
self.resetForm();
|
||||||
if (err) {
|
if (err) {
|
||||||
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
||||||
|
|
@ -829,37 +799,21 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._setOngoingForSigning = function() {
|
||||||
|
var fc = profileService.focusedClient;
|
||||||
|
|
||||||
|
if (fc.isPrivKeyExternal() && fc.getPrivKeyExternalSourceName() == 'ledger') {
|
||||||
|
self.setOngoingProcess(gettext('Requesting Ledger Wallet to sign'));
|
||||||
|
} else {
|
||||||
|
self.setOngoingProcess(gettext('Signing payment'));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.signAndBroadcast = function(txp, cb) {
|
this.signAndBroadcast = function(txp, cb) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
|
|
||||||
if (fc.isPrivKeyExternal()) {
|
this._setOngoingForSigning();
|
||||||
if (fc.getPrivKeyExternalSourceName() == 'ledger') {
|
profileService.signTxProposal(txp, function(err, signedTx) {
|
||||||
$log.debug('Requesting Ledger Chrome app to sign the transaction');
|
|
||||||
self.setOngoingProcess(gettext('Requesting Ledger Wallet to sign'));
|
|
||||||
// TODO account
|
|
||||||
ledger.signTx(txp, 0, function(result) {
|
|
||||||
if (result.success) {
|
|
||||||
txp.signatures = [];
|
|
||||||
for (var i=0; i<result.signatures.length; i++) {
|
|
||||||
txp.signatures.push(result.signatures[i].substring(0, result.signatures[i].length - 2));
|
|
||||||
}
|
|
||||||
self._doSignAndBroadcast(txp, cb);
|
|
||||||
} else {
|
|
||||||
return cb(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self._doSignAndBroadcast(txp, cb);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this._doSignAndBroadcast = function(txp, cb) {
|
|
||||||
var fc = profileService.focusedClient;
|
|
||||||
self.setOngoingProcess(gettext('Signing transaction'));
|
|
||||||
fc.signTxProposal(txp, function(err, signedTx) {
|
|
||||||
profileService.lockFC();
|
|
||||||
self.setOngoingProcess();
|
self.setOngoingProcess();
|
||||||
if (err) {
|
if (err) {
|
||||||
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was created but could not be signed. Please try again from home screen'));
|
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was created but could not be signed. Please try again from home screen'));
|
||||||
|
|
|
||||||
|
|
@ -68,37 +68,6 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
root._signP2PKH = function(txp, account, callback) {
|
|
||||||
root.callbacks["sign_p2sh"] = callback;
|
|
||||||
var redeemScripts = [];
|
|
||||||
var paths = [];
|
|
||||||
var tx = bwcService.getUtils().buildTx(txp);
|
|
||||||
for (var i = 0; i < tx.inputs.length; i++) {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
var splitTransaction = root._splitTransaction(new ByteString(tx.toString(), GP.HEX));
|
|
||||||
var inputs = [];
|
|
||||||
for (var i = 0; i < splitTransaction.inputs.length; i++) {
|
|
||||||
var input = splitTransaction.inputs[i];
|
|
||||||
inputs.push([
|
|
||||||
root._reverseBytestring(input.prevout.bytes(0, 32)).toString(),
|
|
||||||
root._reverseBytestring(input.prevout.bytes(32)).toString()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
$log.debug('Ledger signing paths:', paths);
|
|
||||||
root._messageAfterSession({
|
|
||||||
command: "sign_p2sh",
|
|
||||||
inputs: inputs,
|
|
||||||
scripts: redeemScripts,
|
|
||||||
outputs_number: splitTransaction.outputs.length,
|
|
||||||
outputs_script: splitTransaction.outputScript.toString(),
|
|
||||||
paths: paths
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
root._signP2SH = function(txp, account, callback) {
|
root._signP2SH = function(txp, account, callback) {
|
||||||
root.callbacks["sign_p2sh"] = callback;
|
root.callbacks["sign_p2sh"] = callback;
|
||||||
var redeemScripts = [];
|
var redeemScripts = [];
|
||||||
|
|
@ -129,9 +98,10 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.signTx = function(txp, account, callback) {
|
root.signTx = function(txp, account, callback) {
|
||||||
console.log('[ledger.js.72:txp:]', txp, account); //TODO
|
|
||||||
if (txp.addressType == 'P2PKH') {
|
if (txp.addressType == 'P2PKH') {
|
||||||
root._signP2PKH(txp, account, callback);
|
var msg = 'P2PKH wallets are not supported with ledger';
|
||||||
|
$log.error(msg);
|
||||||
|
return callback(msg);
|
||||||
} else {
|
} else {
|
||||||
root._signP2SH(txp, account, callback);
|
root._signP2SH(txp, account, callback);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ angular.module('copayApp.services')
|
||||||
try {
|
try {
|
||||||
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource);
|
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
$log.warn(ex);
|
$log.warn("Creating wallet from Extended Public Key Arg:", ex, opts);
|
||||||
return cb(gettext('Could not create using the specified extended public key'));
|
return cb(gettext('Could not create using the specified extended public key'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -483,7 +483,7 @@ angular.module('copayApp.services')
|
||||||
$log.debug('Encrypting private key for', fc.credentials.walletName);
|
$log.debug('Encrypting private key for', fc.credentials.walletName);
|
||||||
|
|
||||||
fc.setPrivateKeyEncryption(password);
|
fc.setPrivateKeyEncryption(password);
|
||||||
fc.lock();
|
root.lockFC();
|
||||||
root.updateCredentialsFC(function() {
|
root.updateCredentialsFC(function() {
|
||||||
$log.debug('Wallet encrypted');
|
$log.debug('Wallet encrypted');
|
||||||
return cb();
|
return cb();
|
||||||
|
|
@ -562,7 +562,39 @@ angular.module('copayApp.services')
|
||||||
return lodash.sortBy(ret, 'name');
|
return lodash.sortBy(ret, 'name');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root._signWithLedger = function(txp,cb) {
|
||||||
|
var fc = root.focusedClient;
|
||||||
|
$log.info('Requesting Ledger Chrome app to sign the transaction');
|
||||||
|
|
||||||
|
ledger.signTx(txp, 0, function(result) {
|
||||||
|
if (!result.success)
|
||||||
|
return cb(result);
|
||||||
|
|
||||||
|
txp.signatures = [];
|
||||||
|
for (var i=0; i<result.signatures.length; i++) {
|
||||||
|
txp.signatures.push(result.signatures[i].substring(0, result.signatures[i].length - 2));
|
||||||
|
return fc.signTxProposal(txp, cb);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.signTxProposal = function(txp, cb) {
|
||||||
|
var fc = root.focusedClient;
|
||||||
|
|
||||||
|
if (fc.isPrivKeyExternal()) {
|
||||||
|
if (fc.getPrivKeyExternalSourceName() != 'ledger') {
|
||||||
|
var msg = 'Unsupported External Key:' + fc.getPrivKeyExternalSourceName();
|
||||||
|
$log.error(msg);
|
||||||
|
return cb(msg);
|
||||||
|
}
|
||||||
|
return root._signWithLedger(txp,cb);
|
||||||
|
} else {
|
||||||
|
return fc.signTxProposal(txp, function(err, signedTxp) {
|
||||||
|
root.lockFC();
|
||||||
|
return cb(err, signedTxp);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue