Governance: Mnemonic import implemented for creating profile.

This commit is contained in:
Luis Fernando Molina committed 2021-08-18 12:17:29 +02:00
1 parent 0d2d91ef09
commit a42a4c025c
6 files changed
+352 -4207

No files matched your search

+9
View File
@@ -160,6 +160,15 @@ exports.newHttpInterface = function newHttpInterface(
respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
case 'mnemonicToPrivateKey': {
let serverResponse = await WEB3_SERVER.mnemonicToPrivateKey(
params.mnemonic
)
respondWithContent(JSON.stringify(serverResponse), httpResponse)
return
}
default: {
respondWithContent(JSON.stringify({ error: 'Method ' + params.method + ' is invalid.' }), httpResponse)
}
+274 -4190
View File
File diff suppressed because it is too large. Load diff
+3 -2
View File
@@ -10,12 +10,13 @@
"@octokit/rest": "^18.9.0",
"ccxt": "^1.51.98",
"child_process": "^1.0.2",
"ethers": "^5.4.4",
"lookpath": "^1.2.2",
"node-fetch": "2.6.1",
"open": "^6.4.0",
"rimraf": "^3.0.2",
"simple-git": "^2.42.0",
"web3": "^1.5.0",
"ws": "^7.4.6",
"node-fetch": "2.6.1"
"ws": "^7.4.6"
}
}
+27
View File
@@ -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 }
}
}
}