-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@metamask/eslint [email protected] (#10358)
* @metamask/[email protected] * Update eslintrc and prettierrc * yarn lint:fix
- Loading branch information
Showing
1,169 changed files
with
32,914 additions
and
32,568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
singleQuote: true | ||
semi: false | ||
trailingComma: all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
import log from 'loglevel' | ||
import Wallet from 'ethereumjs-wallet' | ||
import importers from 'ethereumjs-wallet/thirdparty' | ||
import ethUtil from 'ethereumjs-util' | ||
import { addHexPrefix } from '../lib/util' | ||
import log from 'loglevel'; | ||
import Wallet from 'ethereumjs-wallet'; | ||
import importers from 'ethereumjs-wallet/thirdparty'; | ||
import ethUtil from 'ethereumjs-util'; | ||
import { addHexPrefix } from '../lib/util'; | ||
|
||
const accountImporter = { | ||
importAccount(strategy, args) { | ||
try { | ||
const importer = this.strategies[strategy] | ||
const privateKeyHex = importer(...args) | ||
return Promise.resolve(privateKeyHex) | ||
const importer = this.strategies[strategy]; | ||
const privateKeyHex = importer(...args); | ||
return Promise.resolve(privateKeyHex); | ||
} catch (e) { | ||
return Promise.reject(e) | ||
return Promise.reject(e); | ||
} | ||
}, | ||
|
||
strategies: { | ||
'Private Key': (privateKey) => { | ||
if (!privateKey) { | ||
throw new Error('Cannot import an empty key.') | ||
throw new Error('Cannot import an empty key.'); | ||
} | ||
|
||
const prefixed = addHexPrefix(privateKey) | ||
const buffer = ethUtil.toBuffer(prefixed) | ||
const prefixed = addHexPrefix(privateKey); | ||
const buffer = ethUtil.toBuffer(prefixed); | ||
|
||
if (!ethUtil.isValidPrivate(buffer)) { | ||
throw new Error('Cannot import invalid private key.') | ||
throw new Error('Cannot import invalid private key.'); | ||
} | ||
|
||
const stripped = ethUtil.stripHexPrefix(prefixed) | ||
return stripped | ||
const stripped = ethUtil.stripHexPrefix(prefixed); | ||
return stripped; | ||
}, | ||
'JSON File': (input, password) => { | ||
let wallet | ||
let wallet; | ||
try { | ||
wallet = importers.fromEtherWallet(input, password) | ||
wallet = importers.fromEtherWallet(input, password); | ||
} catch (e) { | ||
log.debug('Attempt to import as EtherWallet format failed, trying V3') | ||
wallet = Wallet.fromV3(input, password, true) | ||
log.debug('Attempt to import as EtherWallet format failed, trying V3'); | ||
wallet = Wallet.fromV3(input, password, true); | ||
} | ||
|
||
return walletToPrivateKey(wallet) | ||
return walletToPrivateKey(wallet); | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
function walletToPrivateKey(wallet) { | ||
const privateKeyBuffer = wallet.getPrivateKey() | ||
return ethUtil.bufferToHex(privateKeyBuffer) | ||
const privateKeyBuffer = wallet.getPrivateKey(); | ||
return ethUtil.bufferToHex(privateKeyBuffer); | ||
} | ||
|
||
export default accountImporter | ||
export default accountImporter; |
Oops, something went wrong.