Skip to content

Instantly share code, notes, and snippets.

@tubackkhoa
Last active November 28, 2023 11:33
Show Gist options
  • Save tubackkhoa/50bd287e8e143368614ea9929d72b665 to your computer and use it in GitHub Desktop.
Save tubackkhoa/50bd287e8e143368614ea9929d72b665 to your computer and use it in GitHub Desktop.
export private key from mnemonic
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();
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