Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cgcardona
Created May 29, 2021 20:57
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 cgcardona/fcfb70aeec43e350d9adfcebed32ec3e to your computer and use it in GitHub Desktop.
Save cgcardona/fcfb70aeec43e350d9adfcebed32ec3e to your computer and use it in GitHub Desktop.
import {
Buffer
} from "../../src"
import {
KeyChain,
KeyPair,
} from "../../src/apis/avm"
import * as bip39 from "bip39"
import * as HDKey from "hdkey"
const main = async (): Promise<any> => {
const numberOfAddresses: number = 10
const purpose: number = 44
const coin_type: number = 9000
const account: number = 0
const change: number = 0
const derivationPath: string = `m/${purpose}'/${coin_type}'/${account}'/${change}`
const mnemonic: string = bip39.generateMnemonic(256)
console.log(`Mnemonic: ${mnemonic}`)
const seed: any = bip39.mnemonicToSeedSync(mnemonic)
const hdkey: HDKey = HDKey.fromMasterSeed(seed)
const prefixes: string[] = ["X", "P"]
prefixes.forEach((prefix: string): void => {
console.log(`${prefix} ADDRESSES`)
for (let i: number = 0; i < numberOfAddresses; i++) {
const hdPath: string = `${derivationPath}/${i}`
const hdKey: HDKey = hdkey.derive(hdPath) as HDKey
const keyChain: KeyChain = new KeyChain("avax", prefix)
const pkHex: string = hdKey.privateKey.toString("hex")
const pkBuf: Buffer = new Buffer(pkHex, "hex")
const keyPair: KeyPair = keyChain.importKey(pkBuf)
console.log(`HDPath: ${hdPath}. Address: ${keyPair.getAddressString()}`)
}
})
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment