Governance: Mnemonic import implemented for creating profile.
This commit is contained in:
1 parent
0d2d91ef09
commit
a42a4c025c
6 files changed
+352
-4207
No files matched your search
@@ -8,6 +8,7 @@ exports.newWeb3Server = function newWeb3Server() {
|
||||
getWalletBalances: getWalletBalances,
|
||||
signData: signData,
|
||||
recoverAddress: recoverAddress,
|
||||
mnemonicToPrivateKey: mnemonicToPrivateKey,
|
||||
initialize: initialize,
|
||||
finalize: finalize,
|
||||
run: run
|
||||
@@ -236,4 +237,30 @@ exports.newWeb3Server = function newWeb3Server() {
|
||||
return { error: 'Could not recover address. ' + err.stack }
|
||||
}
|
||||
}
|
||||
|
||||
async function mnemonicToPrivateKey(mnemonic) {
|
||||
try {
|
||||
const ethers = require('ethers')
|
||||
const web3 = new Web3()
|
||||
let wallet = ethers.Wallet.fromMnemonic(mnemonic)
|
||||
|
||||
if (wallet.privateKey !== undefined) {
|
||||
return {
|
||||
address: wallet.address,
|
||||
privateKey: wallet.privateKey,
|
||||
result: 'Ok'
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
address: undefined,
|
||||
privateKey: undefined,
|
||||
result: 'Fail'
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
return { error: 'Could not convert to Private Key. ' + err.stack }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user