Created
May 29, 2021 20:57
-
-
Save cgcardona/fcfb70aeec43e350d9adfcebed32ec3e to your computer and use it in GitHub Desktop.
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
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