Created
August 16, 2021 04:24
-
-
Save mesquka/1e0456e7f10825a45e950d4cd6508aea to your computer and use it in GitHub Desktop.
Derive near 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 bip32 = require('ed25519-hd-key'); | |
const nacl = require('tweetnacl'); | |
const bip39 = require('bip39'); | |
const bs58 = require('bs58') | |
const path = "m/44'/397'/0'" | |
const mnemonic = 'test test test test test test test test test test junk'; | |
const seed = bip39.mnemonicToSeedSync(mnemonic); | |
const keySeed = bip32.derivePath(path, seed).key; | |
const { publicKey, secretKey } = nacl.sign.keyPair.fromSeed(keySeed); | |
const privateKeyHex = Buffer.from(secretKey).toString('hex'); | |
const privateKeybs58= bs58.encode(secretKey); | |
const publicKeyHex = Buffer.from(publicKey).toString('hex'); | |
const publicKeybs58 = bs58.encode(publicKey); | |
console.log(`Key (hex): ${privateKeyHex}`); | |
console.log(`Key (bs58): ${privateKeybs58}`); | |
console.log(`Public Key (hex): ${publicKeyHex}`); | |
console.log(`Public Key (bs58): ${publicKeybs58}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment