refactor: improve script ux
This commit is contained in:
parent
bd3fd3e218
commit
7896925b9d
1 changed files with 18 additions and 11 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const hdkey = require('ethereumjs-wallet/hdkey')
|
const hdkey = require('ethereumjs-wallet/hdkey')
|
||||||
const hkdf = require('futoin-hkdf')
|
const hkdf = require('futoin-hkdf')
|
||||||
const db = require('../lib/db')
|
const db = require('../lib/db')
|
||||||
|
|
@ -8,19 +10,30 @@ const fs = pify(require('fs'))
|
||||||
|
|
||||||
const options = require('../lib/options')
|
const options = require('../lib/options')
|
||||||
|
|
||||||
const paymentPrefixPath = "m/44'/60'/0'/0'"
|
|
||||||
const defaultPrefixPath = "m/44'/60'/1'/0'"
|
const defaultPrefixPath = "m/44'/60'/1'/0'"
|
||||||
|
|
||||||
const address = process.argv[2]
|
const address = process.argv[2]
|
||||||
|
|
||||||
|
if (!options || !options.mnemonicPath) {
|
||||||
|
console.error(`Unable to fetch mnemonic from your account!`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!address) {
|
||||||
|
console.log('Usage: lamassu-eth-recovery <cash-out address>')
|
||||||
|
process.exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
function run (address) {
|
function run (address) {
|
||||||
Promise.all([fetchMnemonic(), searchForHdIndex(address)])
|
Promise.all([fetchMnemonic(), searchForHdIndex(address)])
|
||||||
.then(([mnemonic, hdIndex]) => {
|
.then(([mnemonic, hdIndex]) => {
|
||||||
if (!mnemonic || !hdIndex) {
|
try {
|
||||||
console.log(`Error while retrieving private key!`)
|
console.log(`Private key: `, defaultHdNode(mnemonic).deriveChild(hdIndex).getWallet().getPrivateKeyString())
|
||||||
return
|
process.exit(0)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error while retrieving private key!`)
|
||||||
|
process.exit(3)
|
||||||
}
|
}
|
||||||
console.log(`Private key: `, paymentHdNode(mnemonic).deriveChild(hdIndex).getWallet().getPrivateKeyString())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,12 +52,6 @@ function computeSeed (seed) {
|
||||||
return hkdf(masterSeed, 32, { salt: 'lamassu-server-salt', info: 'wallet-seed' })
|
return hkdf(masterSeed, 32, { salt: 'lamassu-server-salt', info: 'wallet-seed' })
|
||||||
}
|
}
|
||||||
|
|
||||||
function paymentHdNode (masterSeed) {
|
|
||||||
if (!masterSeed) throw new Error('No master seed!')
|
|
||||||
const key = hdkey.fromMasterSeed(masterSeed)
|
|
||||||
return key.derivePath(paymentPrefixPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
function defaultHdNode (masterSeed) {
|
function defaultHdNode (masterSeed) {
|
||||||
if (!masterSeed) throw new Error('No master seed!')
|
if (!masterSeed) throw new Error('No master seed!')
|
||||||
const key = hdkey.fromMasterSeed(masterSeed)
|
const key = hdkey.fromMasterSeed(masterSeed)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue