cardano-serialization-lib
cardano-serialization-lib copied to clipboard
How to get the '.skey' from PrivateKey object using '@emurgo/cardano-serialization-lib' ?
Use cardano-serialization-lib, we can derive spend/signing key, just as:
const deriveRootKey = (mnemonic) =>
Bip32PrivateKey.from_bip39_entropy(Buffer.from(mnemonicToEntropy(mnemonic), "hex"), Buffer.from(""));
const deriveAccountKey = (rootKey, account_index) =>
rootKey
.derive(harden(SHELLEY_COIN_PURPOSE)) // CIP1852
.derive(harden(SHELLEY_COIN_TYPE))
.derive(harden(account_index))
let account = deriveAccountKey(rootKey, 0)
let spendKey = accountKey.derive(0).derive(0) // then how to generate key string as '.skey' that created by cardano-cli
But, then, can spendKey
be convert to the cbor_hex string (leading with '58') like value in xxx.vkey that generate by cardano-cli ?
if can, then how to this '58' leading cbor_hex string?
Thanks
Hi code-brewer. Here you go:
.skey: spendKey.to_128_xprv()
.vkey: spendKey.to_public().as_bytes()