Last active
November 28, 2023 11:33
-
-
Save tubackkhoa/50bd287e8e143368614ea9929d72b665 to your computer and use it in GitHub Desktop.
export private key from mnemonic
This file contains hidden or 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
let hd_path = "m/44'/118'/0'/0/0".into_derivation_path().unwrap(); | |
let secp = Secp256k1::new(); | |
let pk = ExtendedPrivKey::new_master(Network::Bitcoin, seed) | |
.unwrap() | |
.derive_priv(&secp, hd_path) | |
.unwrap(); | |
let pubk = ExtendedPubKey::from_private(&secp, &pk); | |
let path = home::home_dir().unwrap().join(".orga-wallet").join("privkey"); | |
std::fs::write(&path, _pk.private_key.to_bytes()).unwrap(); |
This file contains hidden or 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 { stringToPath, EnglishMnemonic, Bip39, Slip10, Slip10Curve } from "@cosmjs/crypto"; | |
import os from "os"; | |
import fs from "fs"; | |
import path from "path"; | |
const hdPath = stringToPath("m/44'/118'/0'/0/0"); | |
const mnemonicChecked = new EnglishMnemonic(process.env.MNEMONIC); | |
const seed = await Bip39.mnemonicToSeed(mnemonicChecked); | |
const { privkey } = Slip10.derivePath(Slip10Curve.Secp256k1, seed, hdPath); | |
fs.writeFileSync(path.join(os.homedir(), ".orga-wallet/privkey"), privkey); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment