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
@@ -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)
|
||||
}
|
||||
|
||||
Generated
+274
-4190
File diff suppressed because it is too large.
Load diff
+3
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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