From d61c979de68934f9d2315261fdaa35fa601d7969 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 5 Jun 2018 13:44:03 -0700 Subject: Add validation for importing empty private key Previously importing an empty string would result in a new empty Keyring object to be constructed, with no notification to the user. Now we render a clear error explaining the mistake. --- app/scripts/account-import-strategies/index.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/scripts/account-import-strategies/index.js') diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js index 96e2b5912..9f2703571 100644 --- a/app/scripts/account-import-strategies/index.js +++ b/app/scripts/account-import-strategies/index.js @@ -16,6 +16,9 @@ const accountImporter = { strategies: { 'Private Key': (privateKey) => { + if (!privateKey) { + throw new Error('Cannot import an empty key.') + } const stripped = ethUtil.stripHexPrefix(privateKey) return stripped }, -- cgit v1.2.3 From b24efcb1cd9092dfe131af47639ac75ed9209a4c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 11 Jun 2018 14:58:05 -0700 Subject: Make account import tests much more specific However, they no longer seem to work. I'm unclear why this test is failing. The private key being provided should be valid. --- app/scripts/account-import-strategies/index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/scripts/account-import-strategies/index.js') diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js index 9f2703571..5972cb345 100644 --- a/app/scripts/account-import-strategies/index.js +++ b/app/scripts/account-import-strategies/index.js @@ -19,7 +19,14 @@ const accountImporter = { if (!privateKey) { throw new Error('Cannot import an empty key.') } + const stripped = ethUtil.stripHexPrefix(privateKey) + const buffer = ethUtil.toBuffer(stripped) + + if (!ethUtil.isValidPrivate(buffer)) { + throw new Error('Cannot import invalid private key.') + } + return stripped }, 'JSON File': (input, password) => { -- cgit v1.2.3 From 691ac5d288963f376e34c1711e23bbd58432396f Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 21:06:33 -0700 Subject: account-import-strategies - ensure privateKey is prefixed before converting to buffer --- app/scripts/account-import-strategies/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/scripts/account-import-strategies/index.js') diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js index 5972cb345..16ae224ea 100644 --- a/app/scripts/account-import-strategies/index.js +++ b/app/scripts/account-import-strategies/index.js @@ -20,13 +20,14 @@ const accountImporter = { throw new Error('Cannot import an empty key.') } - const stripped = ethUtil.stripHexPrefix(privateKey) - const buffer = ethUtil.toBuffer(stripped) + const prefixed = ethUtil.addHexPrefix(privateKey) + const buffer = ethUtil.toBuffer(prefixed) if (!ethUtil.isValidPrivate(buffer)) { throw new Error('Cannot import invalid private key.') } + const stripped = ethUtil.stripHexPrefix(prefixed) return stripped }, 'JSON File': (input, password) => { -- cgit v1.2.3