Skip to content

Instantly share code, notes, and snippets.

@harsh-98
Created January 11, 2022 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harsh-98/5224908313339232893b852c34faca39 to your computer and use it in GitHub Desktop.
Save harsh-98/5224908313339232893b852c34faca39 to your computer and use it in GitHub Desktop.
Trezor script to generate the private keys from seed.
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()
{
"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