diff --git a/app/scripts/controllers/decryptWalletCtrl.js b/app/scripts/controllers/decryptWalletCtrl.js index 94c27e06f9..74d7b5f07a 100644 --- a/app/scripts/controllers/decryptWalletCtrl.js +++ b/app/scripts/controllers/decryptWalletCtrl.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; var decryptWalletCtrl = function($scope, $sce, walletService) { $scope.walletType = ""; $scope.requireFPass = $scope.requirePPass = $scope.showFDecrypt = $scope.showPDecrypt = $scope.showAOnly = $scope.showParityDecrypt = false; $scope.filePassword = ""; $scope.fileContent = ""; $scope.Validator = Validator; - $scope.isSSL = window.location.protocol == 'https:'; + $scope.isSSL = window.location.protocol == "https:"; $scope.ajaxReq = ajaxReq; $scope.nodeType = $scope.ajaxReq.type; $scope.HDWallet = { @@ -14,43 +14,43 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { wallets: [], id: 0, hdk: null, - dPath: '', - defaultDPath: "m/44'/60'/0'/0", // first address: m/44'/60'/0'/0/0 - alternativeDPath: "m/44'/60'/0'", // first address: m/44'/60'/0/0 - customDPath: "m/44'/60'/1'/0", // first address: m/44'/60'/1'/0/0 - ledgerPath: "m/44'/60'/0'", // first address: m/44'/60'/0/0 + dPath: "", + defaultDPath: "m/44'/60'/0'/0", // first address: m/44'/60'/0'/0/0 + alternativeDPath: "m/44'/60'/0'", // first address: m/44'/60'/0/0 + customDPath: "m/44'/60'/1'/0", // first address: m/44'/60'/1'/0/0 + ledgerPath: "m/44'/60'/0'", // first address: m/44'/60'/0/0 ledgerClassicPath: "m/44'/60'/160720'/0'", // first address: m/44'/60'/160720'/0/0 - trezorTestnetPath: "m/44'/1'/0'/0", // first address: m/44'/1'/0'/0/0 - trezorClassicPath: "m/44'/61'/0'/0", // first address: m/44'/61'/0'/0/0 - trezorPath: "m/44'/60'/0'/0", // first address: m/44'/60'/0'/0/0 - hwUbqPath: "m/44'/108'/0'/0", // first address: m/44'/40'/0'/0/0 - hwExpansePath: "m/44'/40'/0'/0", // first address: m/44'/40'/0'/0/0 - hwEllaismPath: "m/44'/163'/0'/0", // first address: m/44'/163'/0'/0/0 - hwPirlPath: "m/44'/164'/0'/0", // first address: m/44'/164'/0'/0/0 - hwEtherGemPath: "m/44'/1987'/0'/0", // first address: m/44'/1987'/0'/0/0 - hwCallistoPath: "m/44'/820'/0'/0", // first address: m/44'/820'/0'/0/0 - hwSocialPath: "m/44'/1128'/0'/0", // first address: m/44'/1128'/0'/0/0 - hwMusicoinPath: "m/44'/184'/0'/0", // first address: m/44'/184'/0'/0/0 - singularDTVPath: "m/0'/0'/0'", // first address: m/0'/0'/0'/0 - goPath: "m/44'/6060'/0'/0", // first address: m/44'/6060'/0'/0/0 - hwEOSClassicPath: "m/44'/2018'/0'/0", // first address: m/44'/2018'/0'/0/0 - hwAkromaPath: "m/44'/200625'/0'/0", // first address: m/44'/200625'/0'/0/0 - hwESNetworkPath: "m/44'/31102'/0'/0", // first address: m/44'/31102'/0'/0/0 - hwEther1Path: "m/44'/1313114'/0'/0", // first address: m/44'/1313114'/0'/0/0 - hwAtheiosPath: "m/44'/1620'/0'/0", // first address: m/44'/1620'/0'/0/0 - hwIolitePath: "m/44'/1171337'/0'/0", // first address: m/44'/1171337'/0'/0/0 - tomoPath: "m/44'/889'/0'/0", // first address: m/44'/889'/0'/0/0 - hwMixPath: "m/44'/76'/0'/0", // first address: m/44'/76'/0'/0/0 + trezorTestnetPath: "m/44'/1'/0'/0", // first address: m/44'/1'/0'/0/0 + trezorClassicPath: "m/44'/61'/0'/0", // first address: m/44'/61'/0'/0/0 + trezorPath: "m/44'/60'/0'/0", // first address: m/44'/60'/0'/0/0 + hwUbqPath: "m/44'/108'/0'/0", // first address: m/44'/40'/0'/0/0 + hwExpansePath: "m/44'/40'/0'/0", // first address: m/44'/40'/0'/0/0 + hwEllaismPath: "m/44'/163'/0'/0", // first address: m/44'/163'/0'/0/0 + hwPirlPath: "m/44'/164'/0'/0", // first address: m/44'/164'/0'/0/0 + hwEtherGemPath: "m/44'/1987'/0'/0", // first address: m/44'/1987'/0'/0/0 + hwCallistoPath: "m/44'/820'/0'/0", // first address: m/44'/820'/0'/0/0 + hwSocialPath: "m/44'/1128'/0'/0", // first address: m/44'/1128'/0'/0/0 + hwMusicoinPath: "m/44'/184'/0'/0", // first address: m/44'/184'/0'/0/0 + singularDTVPath: "m/0'/0'/0'", // first address: m/0'/0'/0'/0 + goPath: "m/44'/6060'/0'/0", // first address: m/44'/6060'/0'/0/0 + hwEOSClassicPath: "m/44'/2018'/0'/0", // first address: m/44'/2018'/0'/0/0 + hwAkromaPath: "m/44'/200625'/0'/0", // first address: m/44'/200625'/0'/0/0 + hwESNetworkPath: "m/44'/31102'/0'/0", // first address: m/44'/31102'/0'/0/0 + hwEther1Path: "m/44'/1313114'/0'/0", // first address: m/44'/1313114'/0'/0/0 + hwAtheiosPath: "m/44'/1620'/0'/0", // first address: m/44'/1620'/0'/0/0 + hwIolitePath: "m/44'/1171337'/0'/0", // first address: m/44'/1171337'/0'/0/0 + tomoPath: "m/44'/889'/0'/0", // first address: m/44'/889'/0'/0/0 + hwMixPath: "m/44'/76'/0'/0" // first address: m/44'/76'/0'/0/0 }; $scope.canUseMewConnect = MewConnectEth.checkWebRTCAvailable(); $scope.mewConnectMayFail = MewConnectEth.checkBrowser(); $scope.HDWallet.dPath = $scope.HDWallet.defaultDPath; - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); - $scope.$watch('ajaxReq.type', function() { + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); + $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() { @@ -244,30 +244,38 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { $scope.HDWallet.dPath = $scope.HDWallet.defaultDPath; } } - } + }; $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)); - $scope.setHDAddresses($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog); - } else if ($scope.walletType == 'ledger') { + if ($scope.walletType == "pastemnemonic") { + $scope.HDWallet.hdk = hd.HDKey.fromMasterSeed( + hd.bip39.mnemonicToSeed($scope.manualmnemonic.trim(), password) + ); + $scope.setHDAddresses( + $scope.HDWallet.numWallets, + $scope.HDWallet.walletsPerDialog + ); + } else if ($scope.walletType == "ledger") { $scope.scanLedger(); - } else if ($scope.walletType == 'trezor') { + } else if ($scope.walletType == "trezor") { $scope.scanTrezor(); - } else if ($scope.walletType == 'digitalBitbox') { + } else if ($scope.walletType == "digitalBitbox") { $scope.scanDigitalBitbox(); - } else if ($scope.walletType == 'secalot') { + } else if ($scope.walletType == "secalot") { $scope.scanSecalot(); - } else if ($scope.walletType == 'mewConnect') { - $scope.scanMewConnect() + } else if ($scope.walletType == "mewConnect") { + $scope.scanMewConnect(); } - } + }; $scope.onCustomHDDPathChange = function() { $scope.HDWallet.dPath = $scope.HDWallet.customDPath; $scope.onHDDPathChange(); - } + }; $scope.showContent = function($fileContent) { - $scope.notifier.info(globalFuncs.successMsgs[4] + document.getElementById('fselector').files[0].name); + $scope.notifier.info( + globalFuncs.successMsgs[4] + + document.getElementById("fselector").files[0].name + ); try { $scope.requireFPass = Wallet.walletRequirePass($fileContent); $scope.showFDecrypt = !$scope.requireFPass; @@ -278,7 +286,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { }; $scope.openFileDialog = function($fileContent) { $scope.showAOnly = false; - document.getElementById('fselector').click(); + document.getElementById("fselector").click(); }; $scope.onFilePassChange = function() { $scope.showAOnly = false; @@ -288,7 +296,8 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { $scope.showAOnly = false; const manualprivkey = fixPkey($scope.manualprivkey); - $scope.requirePPass = manualprivkey.length == 128 || manualprivkey.length == 132; + $scope.requirePPass = + manualprivkey.length == 128 || manualprivkey.length == 132; $scope.showPDecrypt = manualprivkey.length == 64; }; $scope.onPrivKeyPassChange = function() { @@ -310,73 +319,157 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { $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)); - $scope.HDWallet.wallets[$scope.HDWallet.wallets.length - 1].setBalance(false); + $scope.HDWallet.wallets.push( + new Wallet( + $scope.HDWallet.hdk.derive( + $scope.HDWallet.dPath + "/" + i + )._privateKey + ) + ); + $scope.HDWallet.wallets[$scope.HDWallet.wallets.length - 1].setBalance( + false + ); } $scope.HDWallet.id = 0; $scope.HDWallet.numWallets = start + limit; - } + }; $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); if ($scope.walletType == "ledger") { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.ledger)); + $scope.HDWallet.wallets.push( + new Wallet( + undefined, + derivedKey.publicKey, + $scope.HDWallet.dPath + "/" + i, + $scope.walletType, + $scope.ledger + ) + ); } else if ($scope.walletType == "digitalBitbox") { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.digitalBitbox)); + $scope.HDWallet.wallets.push( + new Wallet( + undefined, + derivedKey.publicKey, + $scope.HDWallet.dPath + "/" + i, + $scope.walletType, + $scope.digitalBitbox + ) + ); } else if ($scope.walletType == "secalot") { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.secalot)); - } else if ($scope.walletType == 'mewConnect') { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + '/' + i, $scope.walletType, $scope.mewConnect)) + $scope.HDWallet.wallets.push( + new Wallet( + undefined, + derivedKey.publicKey, + $scope.HDWallet.dPath + "/" + i, + $scope.walletType, + $scope.secalot + ) + ); + } else if ($scope.walletType == "mewConnect") { + $scope.HDWallet.wallets.push( + new Wallet( + undefined, + derivedKey.publicKey, + $scope.HDWallet.dPath + "/" + i, + $scope.walletType, + $scope.mewConnect + ) + ); } else { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType)); + $scope.HDWallet.wallets.push( + new Wallet( + undefined, + derivedKey.publicKey, + $scope.HDWallet.dPath + "/" + i, + $scope.walletType + ) + ); } - $scope.HDWallet.wallets[$scope.HDWallet.wallets.length - 1].type = "addressOnly"; - $scope.HDWallet.wallets[$scope.HDWallet.wallets.length - 1].setBalance(false); + $scope.HDWallet.wallets[$scope.HDWallet.wallets.length - 1].type = + "addressOnly"; + $scope.HDWallet.wallets[$scope.HDWallet.wallets.length - 1].setBalance( + false + ); } $scope.HDWallet.id = 0; $scope.HDWallet.numWallets = start + limit; - } + }; $scope.AddRemoveHDAddresses = function(isAdd) { - if ($scope.walletType == "ledger" || $scope.walletType == "trezor" || $scope.walletType == "digitalBitbox" || $scope.walletType == "secalot" || $scope.walletType == 'mewConnect') { - if (isAdd) $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog); - else $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog); + if ( + $scope.walletType == "ledger" || + $scope.walletType == "trezor" || + $scope.walletType == "digitalBitbox" || + $scope.walletType == "secalot" || + $scope.walletType == "mewConnect" + ) { + if (isAdd) + $scope.setHDAddressesHWWallet( + $scope.HDWallet.numWallets, + $scope.HDWallet.walletsPerDialog + ); + else + $scope.setHDAddressesHWWallet( + $scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, + $scope.HDWallet.walletsPerDialog + ); } else { - if (isAdd) $scope.setHDAddresses($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog); - else $scope.setHDAddresses($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog); + if (isAdd) + $scope.setHDAddresses( + $scope.HDWallet.numWallets, + $scope.HDWallet.walletsPerDialog + ); + else + $scope.setHDAddresses( + $scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, + $scope.HDWallet.walletsPerDialog + ); } - } + }; $scope.setHDWallet = function() { - walletService.wallet = $scope.wallet = $scope.HDWallet.wallets[$scope.HDWallet.id]; + walletService.wallet = $scope.wallet = + $scope.HDWallet.wallets[$scope.HDWallet.id]; $scope.mnemonicModel.close(); $scope.notifier.info(globalFuncs.successMsgs[1]); $scope.wallet.type = "default"; - } + }; $scope.decryptWallet = function() { $scope.wallet = null; try { if ($scope.showPDecrypt && $scope.requirePPass) { - $scope.wallet = Wallet.fromMyEtherWalletKey($scope.manualprivkey, $scope.privPassword); + $scope.wallet = Wallet.fromMyEtherWalletKey( + $scope.manualprivkey, + $scope.privPassword + ); walletService.password = $scope.privPassword; } else if ($scope.showPDecrypt && !$scope.requirePPass) { - let privKey = $scope.manualprivkey.indexOf("0x") === 0 ? $scope.manualprivkey : "0x" + $scope.manualprivkey; + let privKey = + $scope.manualprivkey.indexOf("0x") === 0 + ? $scope.manualprivkey + : "0x" + $scope.manualprivkey; if (!$scope.Validator.isValidHex($scope.manualprivkey)) { $scope.notifier.danger(globalFuncs.errorMsgs[37]); return; - } else if(!ethUtil.isValidPrivate(ethUtil.toBuffer(privKey))) { + } else if (!ethUtil.isValidPrivate(ethUtil.toBuffer(privKey))) { $scope.wallet = null; $scope.notifier.danger(globalFuncs.errorMsgs[40]); return; } else { $scope.wallet = new Wallet(fixPkey($scope.manualprivkey)); - walletService.password = ''; + walletService.password = ""; } } else if ($scope.showFDecrypt) { - $scope.wallet = Wallet.getWalletFromPrivKeyFile($scope.fileContent, $scope.filePassword); + $scope.wallet = Wallet.getWalletFromPrivKeyFile( + $scope.fileContent, + $scope.filePassword + ); walletService.password = $scope.filePassword; } else if ($scope.showMDecrypt) { - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); + $scope.mnemonicModel = new Modal( + document.getElementById("mnemonicModel") + ); $scope.mnemonicModel.open(); $scope.onHDDPathChange($scope.mnemonicPassword); } else if ($scope.showParityDecrypt) { @@ -406,45 +499,61 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { }, setBalance: tempWallet.setBalance, setTokens: tempWallet.setTokens - } + }; $scope.notifier.info(globalFuncs.successMsgs[1]); walletService.wallet = $scope.wallet; } - } + }; $scope.HWWalletCreate = function(publicKey, chainCode, walletType, path) { - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); $scope.mnemonicModel.open(); $scope.HDWallet.hdk = new hd.HDKey(); - $scope.HDWallet.hdk.publicKey = new Buffer(publicKey, 'hex'); - $scope.HDWallet.hdk.chainCode = new Buffer(chainCode, 'hex'); + $scope.HDWallet.hdk.publicKey = new Buffer(publicKey, "hex"); + $scope.HDWallet.hdk.chainCode = new Buffer(chainCode, "hex"); $scope.HDWallet.numWallets = 0; $scope.HDWallet.dPath = path; - $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog, walletType); + $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.getLedgerPath()); - } - else { + $scope.HWWalletCreate( + result["publicKey"], + result["chainCode"], + "ledger", + $scope.getLedgerPath() + ); + } else { $scope.ledgerError = true; $scope.ledgerErrorString = error; $scope.$apply(); } - } + }; $scope.digitalBitboxCallback = function(result, error) { - $scope.HDWallet.digitalBitboxSecret = ''; + $scope.HDWallet.digitalBitboxSecret = ""; if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "digitalBitbox", $scope.HDWallet.dPath); - } else - $scope.notifier.danger(error); - } + $scope.HWWalletCreate( + result["publicKey"], + result["chainCode"], + "digitalBitbox", + $scope.HDWallet.dPath + ); + } else $scope.notifier.danger(error); + }; $scope.secalotCallback = function(result, error) { if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "secalot", $scope.HDWallet.dPath); - } else - $scope.notifier.danger(error); - } + $scope.HWWalletCreate( + result["publicKey"], + result["chainCode"], + "secalot", + $scope.HDWallet.dPath + ); + } else $scope.notifier.danger(error); + }; $scope.scanLedger = function() { $scope.ledgerError = false; $scope.ledger = new Ledger3("w0w"); @@ -454,7 +563,10 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { }; $scope.scanDigitalBitbox = function() { $scope.digitalBitbox = new DigitalBitboxUsb(); - var app = new DigitalBitboxEth($scope.digitalBitbox, $scope.HDWallet.digitalBitboxSecret); + var app = new DigitalBitboxEth( + $scope.digitalBitbox, + $scope.HDWallet.digitalBitboxSecret + ); var path = $scope.HDWallet.dPath; app.getAddress(path, $scope.digitalBitboxCallback); }; @@ -507,24 +619,24 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { $scope.mewConnect = MewConnect.init(); - Reflect.defineProperty(MewConnect, 'instance', { + Reflect.defineProperty(MewConnect, "instance", { value: $scope.mewConnect }); - $scope.$on('$destroy', function() { + $scope.$on("$destroy", function() { globalFuncs.MEWconnectStatus.newTabOpenedTrigger(false); globalFuncs.MEWconnectStatus.update(0); $scope.mewConnect.disconnectRTC(); if (MewConnect.instance) { - Reflect.deleteProperty(MewConnect, 'instance'); + Reflect.deleteProperty(MewConnect, "instance"); } }); - $scope.mewConnect.on('codeDisplay', codeDisplay); - $scope.mewConnect.on('RtcConnectedEvent', rtcConnected); - $scope.mewConnect.on('RtcClosedEvent', rtcClosed); - $scope.mewConnect.on('RtcDisconnectEvent', rtcDisconnected); - $scope.mewConnect.on('address', makeWallet); + $scope.mewConnect.on("codeDisplay", codeDisplay); + $scope.mewConnect.on("RtcConnectedEvent", rtcConnected); + $scope.mewConnect.on("RtcClosedEvent", rtcClosed); + $scope.mewConnect.on("RtcDisconnectEvent", rtcDisconnected); + $scope.mewConnect.on("address", makeWallet); app.setMewConnect($scope.mewConnect); app.signalerConnect(); @@ -538,8 +650,8 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { globalFuncs.MEWconnectStatus.update(2); if ($scope.mewConnectionStatus !== 2) { $scope.connectionCodeTimeout = null; - uiFuncs.notifier.info('Connected Via MEWconnect'); - $scope.mewConnect.sendRtcMessage('address', ''); + uiFuncs.notifier.info("Connected Via MEWconnect"); + $scope.mewConnect.sendRtcMessage("address", ""); $scope.mewConnectionStatus = 2; } } @@ -550,7 +662,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { $scope.mewConnectionStatus = 4; $scope.wallet = null; walletService.wallet = null; - uiFuncs.notifier.danger('Disconnected', 10000); + uiFuncs.notifier.danger("Disconnected", 10000); if (!$scope.$$phase) $scope.$apply(); } } @@ -561,7 +673,7 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { $scope.mewConnectionStatus = 4; $scope.wallet = null; walletService.wallet = null; - uiFuncs.notifier.danger('Disconnected', 10000); + uiFuncs.notifier.danger("Disconnected", 10000); if (!$scope.$$phase) $scope.$apply(); } } @@ -592,40 +704,66 @@ var decryptWalletCtrl = function($scope, $sce, walletService) { //= ================ Mew Connect (end)============================== $scope.getLedgerPath = function() { return $scope.HDWallet.dPath; - } + }; $scope.getTrezorPath = function() { return $scope.HDWallet.dPath; }; - $scope.scanMetamask = function() { - if (window.web3 === undefined) { - window.addEventListener('message', ({data}) => { - if (data && data.type && data.type === 'ETHEREUM_PROVIDER_SUCCESS') { - window.web3 = new Web3(ethereum); - } - }); - window.postMessage({ type: 'ETHEREUM_PROVIDER_REQUEST', web3: true }, '*'); - } - window.web3.eth.getAccounts(function (err, accounts) { - if (err) $scope.notifier.danger(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?') + + function setWeb3Wallet() { + window.web3.eth.getAccounts(function(err, accounts) { + if (err) + $scope.notifier.danger( + err + ". Are you sure you are on a secure (SSL / HTTPS) connection?" + ); if (!accounts.length) { - $scope.notifier.danger('Could not read your accounts from MetaMask. Try unlocking it.'); + $scope.notifier.danger( + "Could not read your accounts from MetaMask. Try unlocking it." + ); return; } - var address = accounts[0] - var addressBuffer = Buffer.from(address.slice(2), 'hex'); + 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]) + $scope.wallet = wallet; + walletService.wallet = wallet; + $scope.notifier.info(globalFuncs.successMsgs[6]); $scope.wallet.type = "default"; }); + } + $scope.scanMetamask = async function() { + // if (window.web3 === undefined) { + // window.addEventListener('message', ({data}) => { + // if (data && data.type && data.type === 'ETHEREUM_PROVIDER_SUCCESS') { + // window.web3 = new Web3(ethereum); + // } + // }); + // window.postMessage({ type: 'ETHEREUM_PROVIDER_REQUEST', web3: true }, '*'); + // } + if (window.ethereum) { + window.web3 = new Web3(ethereum); + try { + await ethereum.enable(); + setWeb3Wallet(); + } catch (e) { + $scope.notifier.danger( + "Could not read your accounts from MetaMask. Try unlocking it." + ); + } + } else if (window.web3) { + window.web3 = new Web3(web3.currentProvider); + setWeb3Wallet(); + } else { + $scope.notifier.danger( + "Non-Ethereum browser detected. You should consider trying MetaMask!" + ); + } }; // helper function that removes 0x prefix from strings function fixPkey(key) { - if (key.indexOf('0x') === 0) { + if (key.indexOf("0x") === 0) { return key.slice(2); } return key; diff --git a/chrome-extension/js/etherwallet-master.js b/chrome-extension/js/etherwallet-master.js index 93c0bae2e8..386299ab32 100644 --- a/chrome-extension/js/etherwallet-master.js +++ b/chrome-extension/js/etherwallet-master.js @@ -4772,7 +4772,9 @@ module.exports = contractsCtrl; },{}],35:[function(require,module,exports){ (function (Buffer){ -'use strict'; +"use strict"; + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) { $scope.walletType = ""; @@ -4780,7 +4782,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.filePassword = ""; $scope.fileContent = ""; $scope.Validator = Validator; - $scope.isSSL = window.location.protocol == 'https:'; + $scope.isSSL = window.location.protocol == "https:"; $scope.ajaxReq = ajaxReq; $scope.nodeType = $scope.ajaxReq.type; $scope.HDWallet = { @@ -4789,7 +4791,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) wallets: [], id: 0, hdk: null, - dPath: '', + dPath: "", defaultDPath: "m/44'/60'/0'/0", // first address: m/44'/60'/0'/0/0 alternativeDPath: "m/44'/60'/0'", // first address: m/44'/60'/0/0 customDPath: "m/44'/60'/1'/0", // first address: m/44'/60'/1'/0/0 @@ -4820,12 +4822,12 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.canUseMewConnect = MewConnectEth.checkWebRTCAvailable(); $scope.mewConnectMayFail = MewConnectEth.checkBrowser(); $scope.HDWallet.dPath = $scope.HDWallet.defaultDPath; - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); - $scope.$watch('ajaxReq.type', function () { + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); + $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 () { @@ -5024,18 +5026,18 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) var password = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : $scope.mnemonicPassword; $scope.HDWallet.numWallets = 0; - if ($scope.walletType == 'pastemnemonic') { + if ($scope.walletType == "pastemnemonic") { $scope.HDWallet.hdk = hd.HDKey.fromMasterSeed(hd.bip39.mnemonicToSeed($scope.manualmnemonic.trim(), password)); $scope.setHDAddresses($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog); - } else if ($scope.walletType == 'ledger') { + } else if ($scope.walletType == "ledger") { $scope.scanLedger(); - } else if ($scope.walletType == 'trezor') { + } else if ($scope.walletType == "trezor") { $scope.scanTrezor(); - } else if ($scope.walletType == 'digitalBitbox') { + } else if ($scope.walletType == "digitalBitbox") { $scope.scanDigitalBitbox(); - } else if ($scope.walletType == 'secalot') { + } else if ($scope.walletType == "secalot") { $scope.scanSecalot(); - } else if ($scope.walletType == 'mewConnect') { + } else if ($scope.walletType == "mewConnect") { $scope.scanMewConnect(); } }; @@ -5044,7 +5046,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.onHDDPathChange(); }; $scope.showContent = function ($fileContent) { - $scope.notifier.info(globalFuncs.successMsgs[4] + document.getElementById('fselector').files[0].name); + $scope.notifier.info(globalFuncs.successMsgs[4] + document.getElementById("fselector").files[0].name); try { $scope.requireFPass = Wallet.walletRequirePass($fileContent); $scope.showFDecrypt = !$scope.requireFPass; @@ -5055,7 +5057,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) }; $scope.openFileDialog = function ($fileContent) { $scope.showAOnly = false; - document.getElementById('fselector').click(); + document.getElementById("fselector").click(); }; $scope.onFilePassChange = function () { $scope.showAOnly = false; @@ -5102,8 +5104,8 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.digitalBitbox)); } else if ($scope.walletType == "secalot") { $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.secalot)); - } else if ($scope.walletType == 'mewConnect') { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + '/' + i, $scope.walletType, $scope.mewConnect)); + } else if ($scope.walletType == "mewConnect") { + $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.mewConnect)); } else { $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType)); } @@ -5114,7 +5116,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.HDWallet.numWallets = start + limit; }; $scope.AddRemoveHDAddresses = function (isAdd) { - if ($scope.walletType == "ledger" || $scope.walletType == "trezor" || $scope.walletType == "digitalBitbox" || $scope.walletType == "secalot" || $scope.walletType == 'mewConnect') { + if ($scope.walletType == "ledger" || $scope.walletType == "trezor" || $scope.walletType == "digitalBitbox" || $scope.walletType == "secalot" || $scope.walletType == "mewConnect") { if (isAdd) $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog);else $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog); } else { if (isAdd) $scope.setHDAddresses($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog);else $scope.setHDAddresses($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog); @@ -5144,13 +5146,13 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) return; } else { $scope.wallet = new Wallet(fixPkey($scope.manualprivkey)); - walletService.password = ''; + walletService.password = ""; } } else if ($scope.showFDecrypt) { $scope.wallet = Wallet.getWalletFromPrivKeyFile($scope.fileContent, $scope.filePassword); walletService.password = $scope.filePassword; } else if ($scope.showMDecrypt) { - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); $scope.mnemonicModel.open(); $scope.onHDDPathChange($scope.mnemonicPassword); } else if ($scope.showParityDecrypt) { @@ -5186,11 +5188,11 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) } }; $scope.HWWalletCreate = function (publicKey, chainCode, walletType, path) { - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); $scope.mnemonicModel.open(); $scope.HDWallet.hdk = new hd.HDKey(); - $scope.HDWallet.hdk.publicKey = new Buffer(publicKey, 'hex'); - $scope.HDWallet.hdk.chainCode = new Buffer(chainCode, 'hex'); + $scope.HDWallet.hdk.publicKey = new Buffer(publicKey, "hex"); + $scope.HDWallet.hdk.chainCode = new Buffer(chainCode, "hex"); $scope.HDWallet.numWallets = 0; $scope.HDWallet.dPath = path; $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog, walletType); @@ -5198,7 +5200,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) }; $scope.ledgerCallback = function (result, error) { if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "ledger", $scope.getLedgerPath()); + $scope.HWWalletCreate(result["publicKey"], result["chainCode"], "ledger", $scope.getLedgerPath()); } else { $scope.ledgerError = true; $scope.ledgerErrorString = error; @@ -5206,14 +5208,14 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) } }; $scope.digitalBitboxCallback = function (result, error) { - $scope.HDWallet.digitalBitboxSecret = ''; + $scope.HDWallet.digitalBitboxSecret = ""; if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "digitalBitbox", $scope.HDWallet.dPath); + $scope.HWWalletCreate(result["publicKey"], result["chainCode"], "digitalBitbox", $scope.HDWallet.dPath); } else $scope.notifier.danger(error); }; $scope.secalotCallback = function (result, error) { if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "secalot", $scope.HDWallet.dPath); + $scope.HWWalletCreate(result["publicKey"], result["chainCode"], "secalot", $scope.HDWallet.dPath); } else $scope.notifier.danger(error); }; $scope.scanLedger = function () { @@ -5268,24 +5270,24 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.mewConnect = MewConnect.init(); - Reflect.defineProperty(MewConnect, 'instance', { + Reflect.defineProperty(MewConnect, "instance", { value: $scope.mewConnect }); - $scope.$on('$destroy', function () { + $scope.$on("$destroy", function () { globalFuncs.MEWconnectStatus.newTabOpenedTrigger(false); globalFuncs.MEWconnectStatus.update(0); $scope.mewConnect.disconnectRTC(); if (MewConnect.instance) { - Reflect.deleteProperty(MewConnect, 'instance'); + Reflect.deleteProperty(MewConnect, "instance"); } }); - $scope.mewConnect.on('codeDisplay', codeDisplay); - $scope.mewConnect.on('RtcConnectedEvent', rtcConnected); - $scope.mewConnect.on('RtcClosedEvent', rtcClosed); - $scope.mewConnect.on('RtcDisconnectEvent', rtcDisconnected); - $scope.mewConnect.on('address', makeWallet); + $scope.mewConnect.on("codeDisplay", codeDisplay); + $scope.mewConnect.on("RtcConnectedEvent", rtcConnected); + $scope.mewConnect.on("RtcClosedEvent", rtcClosed); + $scope.mewConnect.on("RtcDisconnectEvent", rtcDisconnected); + $scope.mewConnect.on("address", makeWallet); app.setMewConnect($scope.mewConnect); app.signalerConnect(); @@ -5299,8 +5301,8 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) globalFuncs.MEWconnectStatus.update(2); if ($scope.mewConnectionStatus !== 2) { $scope.connectionCodeTimeout = null; - uiFuncs.notifier.info('Connected Via MEWconnect'); - $scope.mewConnect.sendRtcMessage('address', ''); + uiFuncs.notifier.info("Connected Via MEWconnect"); + $scope.mewConnect.sendRtcMessage("address", ""); $scope.mewConnectionStatus = 2; } } @@ -5311,7 +5313,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.mewConnectionStatus = 4; $scope.wallet = null; walletService.wallet = null; - uiFuncs.notifier.danger('Disconnected', 10000); + uiFuncs.notifier.danger("Disconnected", 10000); if (!$scope.$$phase) $scope.$apply(); } } @@ -5322,7 +5324,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.mewConnectionStatus = 4; $scope.wallet = null; walletService.wallet = null; - uiFuncs.notifier.danger('Disconnected', 10000); + uiFuncs.notifier.danger("Disconnected", 10000); if (!$scope.$$phase) $scope.$apply(); } } @@ -5357,25 +5359,16 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.getTrezorPath = function () { return $scope.HDWallet.dPath; }; - $scope.scanMetamask = function () { - if (window.web3 === undefined) { - window.addEventListener('message', function (_ref2) { - var data = _ref2.data; - if (data && data.type && data.type === 'ETHEREUM_PROVIDER_SUCCESS') { - window.web3 = new Web3(ethereum); - } - }); - window.postMessage({ type: 'ETHEREUM_PROVIDER_REQUEST', web3: true }, '*'); - } + function setWeb3Wallet() { window.web3.eth.getAccounts(function (err, accounts) { - if (err) $scope.notifier.danger(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?'); + if (err) $scope.notifier.danger(err + ". Are you sure you are on a secure (SSL / HTTPS) connection?"); if (!accounts.length) { - $scope.notifier.danger('Could not read your accounts from MetaMask. Try unlocking it.'); + $scope.notifier.danger("Could not read your accounts from MetaMask. Try unlocking it."); return; } var address = accounts[0]; - var addressBuffer = Buffer.from(address.slice(2), 'hex'); + var addressBuffer = Buffer.from(address.slice(2), "hex"); var wallet = new Web3Wallet(addressBuffer); wallet.setBalance(false); // set wallet @@ -5384,11 +5377,56 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.notifier.info(globalFuncs.successMsgs[6]); $scope.wallet.type = "default"; }); - }; + } + $scope.scanMetamask = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!window.ethereum) { + _context.next = 13; + break; + } + + window.web3 = new Web3(ethereum); + _context.prev = 2; + _context.next = 5; + return ethereum.enable(); + + case 5: + setWeb3Wallet(); + _context.next = 11; + break; + + case 8: + _context.prev = 8; + _context.t0 = _context["catch"](2); + + $scope.notifier.danger("Could not read your accounts from MetaMask. Try unlocking it."); + + case 11: + _context.next = 14; + break; + + case 13: + if (window.web3) { + window.web3 = new Web3(web3.currentProvider); + setWeb3Wallet(); + } else { + $scope.notifier.danger("Non-Ethereum browser detected. You should consider trying MetaMask!"); + } + + case 14: + case "end": + return _context.stop(); + } + } + }, _callee, this, [[2, 8]]); + })); // helper function that removes 0x prefix from strings function fixPkey(key) { - if (key.indexOf('0x') === 0) { + if (key.indexOf("0x") === 0) { return key.slice(2); } return key; diff --git a/dist/js/etherwallet-master.js b/dist/js/etherwallet-master.js index 93c0bae2e8..386299ab32 100644 --- a/dist/js/etherwallet-master.js +++ b/dist/js/etherwallet-master.js @@ -4772,7 +4772,9 @@ module.exports = contractsCtrl; },{}],35:[function(require,module,exports){ (function (Buffer){ -'use strict'; +"use strict"; + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) { $scope.walletType = ""; @@ -4780,7 +4782,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.filePassword = ""; $scope.fileContent = ""; $scope.Validator = Validator; - $scope.isSSL = window.location.protocol == 'https:'; + $scope.isSSL = window.location.protocol == "https:"; $scope.ajaxReq = ajaxReq; $scope.nodeType = $scope.ajaxReq.type; $scope.HDWallet = { @@ -4789,7 +4791,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) wallets: [], id: 0, hdk: null, - dPath: '', + dPath: "", defaultDPath: "m/44'/60'/0'/0", // first address: m/44'/60'/0'/0/0 alternativeDPath: "m/44'/60'/0'", // first address: m/44'/60'/0/0 customDPath: "m/44'/60'/1'/0", // first address: m/44'/60'/1'/0/0 @@ -4820,12 +4822,12 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.canUseMewConnect = MewConnectEth.checkWebRTCAvailable(); $scope.mewConnectMayFail = MewConnectEth.checkBrowser(); $scope.HDWallet.dPath = $scope.HDWallet.defaultDPath; - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); - $scope.$watch('ajaxReq.type', function () { + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); + $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 () { @@ -5024,18 +5026,18 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) var password = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : $scope.mnemonicPassword; $scope.HDWallet.numWallets = 0; - if ($scope.walletType == 'pastemnemonic') { + if ($scope.walletType == "pastemnemonic") { $scope.HDWallet.hdk = hd.HDKey.fromMasterSeed(hd.bip39.mnemonicToSeed($scope.manualmnemonic.trim(), password)); $scope.setHDAddresses($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog); - } else if ($scope.walletType == 'ledger') { + } else if ($scope.walletType == "ledger") { $scope.scanLedger(); - } else if ($scope.walletType == 'trezor') { + } else if ($scope.walletType == "trezor") { $scope.scanTrezor(); - } else if ($scope.walletType == 'digitalBitbox') { + } else if ($scope.walletType == "digitalBitbox") { $scope.scanDigitalBitbox(); - } else if ($scope.walletType == 'secalot') { + } else if ($scope.walletType == "secalot") { $scope.scanSecalot(); - } else if ($scope.walletType == 'mewConnect') { + } else if ($scope.walletType == "mewConnect") { $scope.scanMewConnect(); } }; @@ -5044,7 +5046,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.onHDDPathChange(); }; $scope.showContent = function ($fileContent) { - $scope.notifier.info(globalFuncs.successMsgs[4] + document.getElementById('fselector').files[0].name); + $scope.notifier.info(globalFuncs.successMsgs[4] + document.getElementById("fselector").files[0].name); try { $scope.requireFPass = Wallet.walletRequirePass($fileContent); $scope.showFDecrypt = !$scope.requireFPass; @@ -5055,7 +5057,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) }; $scope.openFileDialog = function ($fileContent) { $scope.showAOnly = false; - document.getElementById('fselector').click(); + document.getElementById("fselector").click(); }; $scope.onFilePassChange = function () { $scope.showAOnly = false; @@ -5102,8 +5104,8 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.digitalBitbox)); } else if ($scope.walletType == "secalot") { $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.secalot)); - } else if ($scope.walletType == 'mewConnect') { - $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + '/' + i, $scope.walletType, $scope.mewConnect)); + } else if ($scope.walletType == "mewConnect") { + $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType, $scope.mewConnect)); } else { $scope.HDWallet.wallets.push(new Wallet(undefined, derivedKey.publicKey, $scope.HDWallet.dPath + "/" + i, $scope.walletType)); } @@ -5114,7 +5116,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.HDWallet.numWallets = start + limit; }; $scope.AddRemoveHDAddresses = function (isAdd) { - if ($scope.walletType == "ledger" || $scope.walletType == "trezor" || $scope.walletType == "digitalBitbox" || $scope.walletType == "secalot" || $scope.walletType == 'mewConnect') { + if ($scope.walletType == "ledger" || $scope.walletType == "trezor" || $scope.walletType == "digitalBitbox" || $scope.walletType == "secalot" || $scope.walletType == "mewConnect") { if (isAdd) $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog);else $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog); } else { if (isAdd) $scope.setHDAddresses($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog);else $scope.setHDAddresses($scope.HDWallet.numWallets - 2 * $scope.HDWallet.walletsPerDialog, $scope.HDWallet.walletsPerDialog); @@ -5144,13 +5146,13 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) return; } else { $scope.wallet = new Wallet(fixPkey($scope.manualprivkey)); - walletService.password = ''; + walletService.password = ""; } } else if ($scope.showFDecrypt) { $scope.wallet = Wallet.getWalletFromPrivKeyFile($scope.fileContent, $scope.filePassword); walletService.password = $scope.filePassword; } else if ($scope.showMDecrypt) { - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); $scope.mnemonicModel.open(); $scope.onHDDPathChange($scope.mnemonicPassword); } else if ($scope.showParityDecrypt) { @@ -5186,11 +5188,11 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) } }; $scope.HWWalletCreate = function (publicKey, chainCode, walletType, path) { - $scope.mnemonicModel = new Modal(document.getElementById('mnemonicModel')); + $scope.mnemonicModel = new Modal(document.getElementById("mnemonicModel")); $scope.mnemonicModel.open(); $scope.HDWallet.hdk = new hd.HDKey(); - $scope.HDWallet.hdk.publicKey = new Buffer(publicKey, 'hex'); - $scope.HDWallet.hdk.chainCode = new Buffer(chainCode, 'hex'); + $scope.HDWallet.hdk.publicKey = new Buffer(publicKey, "hex"); + $scope.HDWallet.hdk.chainCode = new Buffer(chainCode, "hex"); $scope.HDWallet.numWallets = 0; $scope.HDWallet.dPath = path; $scope.setHDAddressesHWWallet($scope.HDWallet.numWallets, $scope.HDWallet.walletsPerDialog, walletType); @@ -5198,7 +5200,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) }; $scope.ledgerCallback = function (result, error) { if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "ledger", $scope.getLedgerPath()); + $scope.HWWalletCreate(result["publicKey"], result["chainCode"], "ledger", $scope.getLedgerPath()); } else { $scope.ledgerError = true; $scope.ledgerErrorString = error; @@ -5206,14 +5208,14 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) } }; $scope.digitalBitboxCallback = function (result, error) { - $scope.HDWallet.digitalBitboxSecret = ''; + $scope.HDWallet.digitalBitboxSecret = ""; if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "digitalBitbox", $scope.HDWallet.dPath); + $scope.HWWalletCreate(result["publicKey"], result["chainCode"], "digitalBitbox", $scope.HDWallet.dPath); } else $scope.notifier.danger(error); }; $scope.secalotCallback = function (result, error) { if (typeof result != "undefined") { - $scope.HWWalletCreate(result['publicKey'], result['chainCode'], "secalot", $scope.HDWallet.dPath); + $scope.HWWalletCreate(result["publicKey"], result["chainCode"], "secalot", $scope.HDWallet.dPath); } else $scope.notifier.danger(error); }; $scope.scanLedger = function () { @@ -5268,24 +5270,24 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.mewConnect = MewConnect.init(); - Reflect.defineProperty(MewConnect, 'instance', { + Reflect.defineProperty(MewConnect, "instance", { value: $scope.mewConnect }); - $scope.$on('$destroy', function () { + $scope.$on("$destroy", function () { globalFuncs.MEWconnectStatus.newTabOpenedTrigger(false); globalFuncs.MEWconnectStatus.update(0); $scope.mewConnect.disconnectRTC(); if (MewConnect.instance) { - Reflect.deleteProperty(MewConnect, 'instance'); + Reflect.deleteProperty(MewConnect, "instance"); } }); - $scope.mewConnect.on('codeDisplay', codeDisplay); - $scope.mewConnect.on('RtcConnectedEvent', rtcConnected); - $scope.mewConnect.on('RtcClosedEvent', rtcClosed); - $scope.mewConnect.on('RtcDisconnectEvent', rtcDisconnected); - $scope.mewConnect.on('address', makeWallet); + $scope.mewConnect.on("codeDisplay", codeDisplay); + $scope.mewConnect.on("RtcConnectedEvent", rtcConnected); + $scope.mewConnect.on("RtcClosedEvent", rtcClosed); + $scope.mewConnect.on("RtcDisconnectEvent", rtcDisconnected); + $scope.mewConnect.on("address", makeWallet); app.setMewConnect($scope.mewConnect); app.signalerConnect(); @@ -5299,8 +5301,8 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) globalFuncs.MEWconnectStatus.update(2); if ($scope.mewConnectionStatus !== 2) { $scope.connectionCodeTimeout = null; - uiFuncs.notifier.info('Connected Via MEWconnect'); - $scope.mewConnect.sendRtcMessage('address', ''); + uiFuncs.notifier.info("Connected Via MEWconnect"); + $scope.mewConnect.sendRtcMessage("address", ""); $scope.mewConnectionStatus = 2; } } @@ -5311,7 +5313,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.mewConnectionStatus = 4; $scope.wallet = null; walletService.wallet = null; - uiFuncs.notifier.danger('Disconnected', 10000); + uiFuncs.notifier.danger("Disconnected", 10000); if (!$scope.$$phase) $scope.$apply(); } } @@ -5322,7 +5324,7 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.mewConnectionStatus = 4; $scope.wallet = null; walletService.wallet = null; - uiFuncs.notifier.danger('Disconnected', 10000); + uiFuncs.notifier.danger("Disconnected", 10000); if (!$scope.$$phase) $scope.$apply(); } } @@ -5357,25 +5359,16 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.getTrezorPath = function () { return $scope.HDWallet.dPath; }; - $scope.scanMetamask = function () { - if (window.web3 === undefined) { - window.addEventListener('message', function (_ref2) { - var data = _ref2.data; - if (data && data.type && data.type === 'ETHEREUM_PROVIDER_SUCCESS') { - window.web3 = new Web3(ethereum); - } - }); - window.postMessage({ type: 'ETHEREUM_PROVIDER_REQUEST', web3: true }, '*'); - } + function setWeb3Wallet() { window.web3.eth.getAccounts(function (err, accounts) { - if (err) $scope.notifier.danger(err + '. Are you sure you are on a secure (SSL / HTTPS) connection?'); + if (err) $scope.notifier.danger(err + ". Are you sure you are on a secure (SSL / HTTPS) connection?"); if (!accounts.length) { - $scope.notifier.danger('Could not read your accounts from MetaMask. Try unlocking it.'); + $scope.notifier.danger("Could not read your accounts from MetaMask. Try unlocking it."); return; } var address = accounts[0]; - var addressBuffer = Buffer.from(address.slice(2), 'hex'); + var addressBuffer = Buffer.from(address.slice(2), "hex"); var wallet = new Web3Wallet(addressBuffer); wallet.setBalance(false); // set wallet @@ -5384,11 +5377,56 @@ var decryptWalletCtrl = function decryptWalletCtrl($scope, $sce, walletService) $scope.notifier.info(globalFuncs.successMsgs[6]); $scope.wallet.type = "default"; }); - }; + } + $scope.scanMetamask = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { + return regeneratorRuntime.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!window.ethereum) { + _context.next = 13; + break; + } + + window.web3 = new Web3(ethereum); + _context.prev = 2; + _context.next = 5; + return ethereum.enable(); + + case 5: + setWeb3Wallet(); + _context.next = 11; + break; + + case 8: + _context.prev = 8; + _context.t0 = _context["catch"](2); + + $scope.notifier.danger("Could not read your accounts from MetaMask. Try unlocking it."); + + case 11: + _context.next = 14; + break; + + case 13: + if (window.web3) { + window.web3 = new Web3(web3.currentProvider); + setWeb3Wallet(); + } else { + $scope.notifier.danger("Non-Ethereum browser detected. You should consider trying MetaMask!"); + } + + case 14: + case "end": + return _context.stop(); + } + } + }, _callee, this, [[2, 8]]); + })); // helper function that removes 0x prefix from strings function fixPkey(key) { - if (key.indexOf('0x') === 0) { + if (key.indexOf("0x") === 0) { return key.slice(2); } return key;