Skip to content

Commit

Permalink
update ledger gen / send tx
Browse files Browse the repository at this point in the history
fixes:

change HD derivation path - #128

invalid sender / send CLO - #134, #117

changes:

update hd path on change
remove eip155 support ledger w/ clo
update location hash w/ view msg
define wallet props in service
update err message send msg
  • Loading branch information
joe authored and joe committed May 4, 2018
1 parent e7d889f commit f1e6423
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 272 deletions.
3 changes: 1 addition & 2 deletions app/includes/messages-new.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p class="account-help-text" translate="x_AddessDesc">You may know this as your "Account #" or
your "Public Key". It's what you send people so they can send you ETH. That icon is an easy
way to recognize your address.</p>
<h5 translate="Address">Address:</h5>
<h5 translate="SEND_addr">To Address:</h5>
</div>
<div class="col-xs-11">
<input ng-class="validateAddress() ? 'form-control is-valid' : 'form-control is-invalid'"
Expand Down Expand Up @@ -67,7 +67,6 @@


<button
ng-disabled="!wallet.hwType"
class="btn btn-primary"
type="submit"
>
Expand Down
98 changes: 53 additions & 45 deletions app/scripts/controllers/decryptWalletCtrl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
var decryptWalletCtrl = function($scope, $sce, walletService) {
var decryptWalletCtrl = function ($scope, $sce, walletService) {
$scope.walletType = "";
$scope.requireFPass = $scope.requirePPass = $scope.showFDecrypt = $scope.showPDecrypt = $scope.showAOnly = $scope.showParityDecrypt = false;
$scope.filePassword = "";
Expand Down Expand Up @@ -27,14 +27,14 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
};
$scope.HDWallet.dPath = $scope.HDWallet.defaultDPath;
$scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel'));
$scope.$watch('ajaxReq.type', function() {
$scope.$watch('ajaxReq.type', function () {
$scope.nodeType = $scope.ajaxReq.type;
$scope.setdPath();
});
$scope.$watch('walletType', function() {
$scope.$watch('walletType', function () {
$scope.setdPath();
});
$scope.setdPath = function() {
$scope.setdPath = function () {
if ($scope.walletType == "ledger") {
switch ($scope.nodeType) {
case nodes.nodeTypes.ETH:
Expand Down Expand Up @@ -76,7 +76,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.HDWallet.dPath = $scope.HDWallet.defaultDPath;
}
}
$scope.onHDDPathChange = function(password = $scope.mnemonicPassword) {
$scope.onHDDPathChange = function (password = $scope.mnemonicPassword) {
$scope.HDWallet.numWallets = 0;
if ($scope.walletType == 'pastemnemonic') {
$scope.HDWallet.hdk = hd.HDKey.fromMasterSeed(hd.bip39.mnemonicToSeed($scope.manualmnemonic.trim(), password));
Expand All @@ -89,11 +89,13 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.scanDigitalBitbox();
}
}
$scope.onCustomHDDPathChange = function() {


$scope.onCustomHDDPathChange = function () {
$scope.HDWallet.dPath = $scope.HDWallet.customDPath;
$scope.onHDDPathChange();
}
$scope.showContent = function($fileContent) {
$scope.showContent = function ($fileContent) {
$scope.notifier.info(globalFuncs.successMsgs[4] + document.getElementById('fselector').files[0].name);
try {
$scope.requireFPass = Wallet.walletRequirePass($fileContent);
Expand All @@ -103,32 +105,33 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.notifier.danger(e);
}
};
$scope.openFileDialog = function($fileContent) {

$scope.openFileDialog = function ($fileContent) {
document.getElementById('fselector').click();
};
$scope.onFilePassChange = function() {
$scope.onFilePassChange = function () {
$scope.showFDecrypt = $scope.filePassword.length >= 0;
};
$scope.onPrivKeyChange = function() {
$scope.onPrivKeyChange = function () {
const manualprivkey = fixPkey($scope.manualprivkey);

$scope.requirePPass = manualprivkey.length == 128 || manualprivkey.length == 132;
$scope.showPDecrypt = manualprivkey.length == 64;
};
$scope.onPrivKeyPassChange = function() {
$scope.onPrivKeyPassChange = function () {
$scope.showPDecrypt = $scope.privPassword.length > 0;
};
$scope.onMnemonicChange = function() {
$scope.onMnemonicChange = function () {
$scope.showMDecrypt = hd.bip39.validateMnemonic($scope.manualmnemonic);
};
$scope.onParityPhraseChange = function() {
$scope.onParityPhraseChange = function () {
if ($scope.parityPhrase) $scope.showParityDecrypt = true;
else $scope.showParityDecrypt = false;
};
$scope.onAddressChange = function() {
$scope.onAddressChange = function () {
$scope.showAOnly = $scope.Validator.isValidAddress($scope.addressOnly);
};
$scope.setHDAddresses = function(start, limit) {
$scope.setHDAddresses = function (start, limit) {
$scope.HDWallet.wallets = [];
for (var i = start; i < start + limit; i++) {
$scope.HDWallet.wallets.push(new Wallet($scope.HDWallet.hdk.derive($scope.HDWallet.dPath + "/" + i)._privateKey));
Expand All @@ -137,7 +140,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.HDWallet.id = 0;
$scope.HDWallet.numWallets = start + limit;
}
$scope.setHDAddressesHWWallet = function(start, limit, ledger) {
$scope.setHDAddressesHWWallet = function (start, limit, ledger) {
$scope.HDWallet.wallets = [];
for (var i = start; i < start + limit; i++) {
var derivedKey = $scope.HDWallet.hdk.derive("m/" + i);
Expand All @@ -154,7 +157,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.HDWallet.id = 0;
$scope.HDWallet.numWallets = start + limit;
}
$scope.AddRemoveHDAddresses = function(isAdd) {
$scope.AddRemoveHDAddresses = function (isAdd) {
if ($scope.walletType == "ledger" || $scope.walletType == "trezor" || $scope.walletType == "digitalBitbox") {
if (isAdd) $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog);
else $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog);
Expand All @@ -163,12 +166,12 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
else $scope.setHDAddresses($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog);
}
}
$scope.setHDWallet = function() {
$scope.setHDWallet = function () {
walletService.wallet = $scope.wallet = $scope.HDWallet.wallets[$scope.HDWallet.id];
$scope.mnemonicModel.close();
$scope.notifier.info(globalFuncs.successMsgs[1]);
}
$scope.decryptWallet = function() {
$scope.decryptWallet = function () {
$scope.wallet = null;
try {
if ($scope.showPDecrypt && $scope.requirePPass) {
Expand Down Expand Up @@ -197,16 +200,16 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
}
if ($scope.wallet != null) $scope.notifier.info(globalFuncs.successMsgs[1]);
};
$scope.decryptAddressOnly = function() {
$scope.decryptAddressOnly = function () {
if ($scope.Validator.isValidAddress($scope.addressOnly)) {
var tempWallet = new Wallet();
$scope.wallet = {
type: "addressOnly",
address: $scope.addressOnly,
getAddressString: function() {
getAddressString: function () {
return this.address;
},
getChecksumAddressString: function() {
getChecksumAddressString: function () {
return ethUtil.toChecksumAddress(this.getAddressString());
},
setBalance: tempWallet.setBalance,
Expand All @@ -216,7 +219,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
walletService.wallet = $scope.wallet;
}
}
$scope.HWWalletCreate = function(publicKey, chainCode, walletType, path) {
$scope.HWWalletCreate = function (publicKey, chainCode, walletType, path) {
$scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel'));
$scope.mnemonicModel.open();
$scope.HDWallet.hdk = new hd.HDKey();
Expand All @@ -227,17 +230,17 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog, walletType);
walletService.wallet = null;
}
$scope.ledgerCallback = function(result, error) {
if (typeof result != "undefined") {
$scope.HWWalletCreate(result['publicKey'], result['chainCode'], "ledger", $scope.HDWallet.ledgerPath);
$scope.ledgerCallback = function (result, error) {
if (result) {
$scope.HWWalletCreate(result['publicKey'], result['chainCode'], "ledger", $scope.getLedgerPath());
}
else {
$scope.ledgerError = true;
$scope.ledgerErrorString = error;
$scope.$apply();
}
}
$scope.trezorCallback = function(response) {
$scope.trezorCallback = function (response) {
if (response.success) {
$scope.HWWalletCreate(response.publicKey, response.chainCode, "trezor", $scope.getTrezorPath());
} else {
Expand All @@ -246,48 +249,53 @@ var decryptWalletCtrl = function($scope, $sce, walletService) {
$scope.$apply();
}
}
$scope.digitalBitboxCallback = function(result, error) {
$scope.digitalBitboxCallback = function (result, error) {
$scope.HDWallet.digitalBitboxSecret = '';
if (typeof result != "undefined") {
$scope.HWWalletCreate(result['publicKey'], result['chainCode'], "digitalBitbox", $scope.HDWallet.dPath);
$scope.notifier.close();
} else
$scope.notifier.danger(error);
}
$scope.scanLedger = function() {
$scope.scanLedger = function () {
$scope.ledger = new Ledger3("w0w");
var app = new ledgerEth($scope.ledger);


var path = $scope.getLedgerPath();

console.log('path', path);

app.getAddress(path, $scope.ledgerCallback, false, true);
};
$scope.scanDigitalBitbox = function() {
$scope.scanDigitalBitbox = function () {
$scope.digitalBitbox = new DigitalBitboxUsb();
var app = new DigitalBitboxEth($scope.digitalBitbox, $scope.HDWallet.digitalBitboxSecret);
var path = $scope.HDWallet.dPath;
app.getAddress(path, $scope.digitalBitboxCallback);
};
$scope.scanTrezor = function() {
$scope.scanTrezor = function () {
// trezor is using the path without change level id
var path = $scope.getTrezorPath();
TrezorConnect.getXPubKey(path, $scope.trezorCallback, '1.4.0');
};
$scope.getLedgerPath = function() {


$scope.getLedgerPath = $scope.getTrezorPath = function () {
return $scope.HDWallet.dPath;
}
$scope.getTrezorPath = function() {
return $scope.HDWallet.dPath;
};
$scope.scanMetamask = function() {

$scope.scanMetamask = function () {
window.web3.eth.getAccounts(function (err, accounts) {
if (err) $scope.notifier.danger(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?')
var address = accounts[0]
var addressBuffer = Buffer.from(address.slice(2), 'hex');
var wallet = new Web3Wallet(addressBuffer);
wallet.setBalance(false);
// set wallet
$scope.wallet = wallet
walletService.wallet = wallet
$scope.notifier.info(globalFuncs.successMsgs[6])
if (err) $scope.notifier.danger(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?')
var address = accounts[0]
var addressBuffer = Buffer.from(address.slice(2), 'hex');
var wallet = new Web3Wallet(addressBuffer);
wallet.setBalance(false);
// set wallet
$scope.wallet = wallet
walletService.wallet = wallet
$scope.notifier.info(globalFuncs.successMsgs[6])
});
};

Expand Down
20 changes: 13 additions & 7 deletions app/scripts/controllers/messagesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,7 @@ var messagesCtrl = function ($scope,

$scope.notifier.danger(globalFuncs.errorMsgs[5]);

} else if (!$scope.wallet.hwType) {


$scope.notifier.danger(globalFuncs.errorMsgs[9]);
}
else sendMessage(to, text);
} else sendMessage(to, text);

};

Expand Down Expand Up @@ -641,8 +636,19 @@ var messagesCtrl = function ($scope,
$scope.notifier.success(globalFuncs.successMsgs[2] + "<br />" + resp.data + "<br />" + bExStr + contractAddr);
} else {

let response = resp.error;

if (resp.error.includes('Insufficient funds')) {


response = globalFuncs.errorMsgs[17].replace('{}', ajaxReq.type);


}

$scope.notifier.danger(response);


$scope.notifier.danger(typeof resp.error === 'string' && resp.error || globalFuncs.errorMsgs[17].replace('{}', ajaxReq.type));
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/messagesOverviewDrtv.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
>
<div class="col-xs-6">You have:</div>
<div class="col-xs-6">Total:</div>
<a ng-click="globalService.currentTab = globalService.tabs.messages.id">
<a ng-click="viewMessageList()">
<div class="col-xs-6">

<span ng-if="loadingMessages">
Expand Down
19 changes: 14 additions & 5 deletions app/scripts/directives/messagesOverviewDrtv.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
'use strict';

var messagesOverviewDrtv = function() {
return {
restrict : "E",
template : require('./messagesOverviewDrtv.html')
};
var messagesOverviewDrtv = function (globalService) {
return {
restrict: "E",
template: require('./messagesOverviewDrtv.html'),
link: function ($scope, element, attrs) {


$scope.viewMessageList = function viewMessageList() {

globalService.currentTab = globalService.tabs.messages.id;
location.hash = globalService.tabs.messages.url;
}
}
};
};
module.exports = messagesOverviewDrtv;
2 changes: 1 addition & 1 deletion app/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ app.directive('onReadFile', fileReaderDrtv);
app.directive('walletBalanceDrtv', balanceDrtv);
app.directive('walletDecryptDrtv', walletDecryptDrtv);
app.directive('cxWalletDecryptDrtv', cxWalletDecryptDrtv);
app.directive('messagesOverviewDrtv', messagesOverviewDrtv);
app.directive('messagesOverviewDrtv', ['globalService', messagesOverviewDrtv]);
app.directive('arrayInputDrtv', arrayInputDrtv);
app.directive('newMessagesDrtv', ['globalService', newMessagesDrtv]);
app.controller('tabsCtrl', ['$scope', 'globalService', '$translate', '$sce', 'backgroundNodeService', tabsCtrl]);
Expand Down
28 changes: 24 additions & 4 deletions app/scripts/services/walletService.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
'use strict';
var walletService = function() {
return {
var walletService = function () {
return {
wallet: null,
password:''
password: '',
privKey: null,
pubKey: null,
path: null,
hwType: null,
hwTransport: null,
type: null,
gbpBalance: null,
repBalance: null,
chfBalance: null,
btcBalance: null,
eurBalance: null,
usdBalance: null,
balance: null,
tokenObjs: [], // Token {["contractAddress","userAddress","symbol","decimal","type","balance","network","node","balanceBN"]}
usdPrice: null,
gbpPrice: null,
eurPrice: null,
btcPrice: null,
chfPrice: null,
repPrice: null
}
};
module.exports = walletService;
module.exports = walletService;
Loading

0 comments on commit f1e6423

Please sign in to comment.