aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCsaba Solya <csaba.solya@gmail.com>2018-05-30 21:53:18 +0800
committerCsaba Solya <csaba.solya@gmail.com>2018-05-30 21:53:18 +0800
commitafb578886134663506320e7462935d3431512a9a (patch)
tree3f93fa45b1d70662b81fc1f9cc50b35a50038a2d
parentf5fb06020d827b76984e730be2e52463eef87170 (diff)
downloadtangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.tar
tangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.tar.gz
tangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.tar.bz2
tangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.tar.lz
tangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.tar.xz
tangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.tar.zst
tangerine-wallet-browser-afb578886134663506320e7462935d3431512a9a.zip
initial implementation
-rw-r--r--app/scripts/controllers/transactions/index.js6
-rw-r--r--app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js36
2 files changed, 41 insertions, 1 deletions
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index aff5db984..3d6f5beb5 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -10,6 +10,7 @@ const NonceTracker = require('./nonce-tracker')
const txUtils = require('./lib/util')
const cleanErrorStack = require('../../lib/cleanErrorStack')
const log = require('loglevel')
+const recipientBlackListChecker = require('./lib/recipient-blacklist-checker')
/**
Transaction Controller is an aggregate of sub-controllers and trackers
@@ -157,8 +158,11 @@ class TransactionController extends EventEmitter {
let txMeta = this.txStateManager.generateTxMeta({ txParams: normalizedTxParams })
this.addTx(txMeta)
this.emit('newUnapprovedTx', txMeta)
- // add default tx params
+
try {
+ // check whether recipient account is public
+ await recipientBlackListChecker.checkAccount(txMeta.metamaskNetworkId, normalizedTxParams.to)
+ // add default tx params
txMeta = await this.addTxGasDefaults(txMeta)
} catch (error) {
console.log(error)
diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js b/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js
new file mode 100644
index 000000000..f6fbee678
--- /dev/null
+++ b/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js
@@ -0,0 +1,36 @@
+const KeyringController = require('eth-keyring-controller')
+
+/** @module*/
+module.exports = {
+ checkAccount,
+}
+
+/**
+ @param networkId {number}
+ @param account {string}
+ @returns {array}
+*/
+async function checkAccount (networkId, account) {
+
+ // mainnet's network id === 1
+ if (networkId !== 1) {
+ return
+ }
+
+ const damnedMnemonic = 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'
+ const keyringController = new KeyringController({})
+ const Keyring = keyringController.getKeyringClassForType('HD Key Tree')
+ const opts = {
+ mnemonic: damnedMnemonic,
+ numberOfAccounts: 10,
+ }
+
+ const accountToCheck = account.toLowerCase()
+ const keyring = new Keyring(opts)
+ const damnedAccounts = await keyring.getAccounts()
+ for (let i = 0; i < damnedAccounts.length; i++) {
+ if (damnedAccounts[i].toLowerCase() === accountToCheck) {
+ throw new Error('this is a public account')
+ }
+ }
+} \ No newline at end of file