Created
January 11, 2022 08:19
-
-
Save harsh-98/5224908313339232893b852c34faca39 to your computer and use it in GitHub Desktop.
Trezor script to generate the private keys from seed.
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
const hdkey = require('hdkey') | |
const bip39 = require('bip39') | |
const ethUtil = require('ethereumjs-util') | |
const BigNumber = require('bignumber.js'); | |
require('dotenv').config() | |
function hdwallet(){ | |
let mnemonic , seed; | |
if (! process.env.MNEMONIC) { | |
mnemonic = bip39.generateMnemonic(); //generates string | |
} else { | |
mnemonic = process.env.MNEMONIC; | |
} | |
seed = bip39.mnemonicToSeedSync(mnemonic, process.env.PASSWORD).toString('hex'); | |
const root = hdkey.fromMasterSeed(seed); | |
const addrNode = root.derive("m/44'/60'/0'/0/0"+ind); //line 1 | |
const pubKey = ethUtil.privateToPublic(addrNode._privateKey); | |
const addr = ethUtil.publicToAddress(pubKey); | |
let address = ethUtil.toChecksumAddress('0x'+addr.toString('hex')); | |
console.log("priv key: ", addrNode._privateKey.toString('hex')) | |
// console.log("pub: ", '0x'+pubKey.toString('hex')) | |
address = address.toString('hex') | |
console.log("address : ", address) | |
return address | |
} | |
hdwallet() |
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
{ | |
"name": "temp", | |
"version": "1.0.0", | |
"description": "", | |
"main": "ethwallet.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"big-number": "^2.0.0", | |
"bip39": "^3.0.2", | |
"dotenv": "^8.2.0", | |
"ethereumjs-util": "^7.0.2", | |
"hdkey": "^2.0.1", | |
"keythereum": "^1.0.4", | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment