cardano-serialization-lib icon indicating copy to clipboard operation
cardano-serialization-lib copied to clipboard

How to get the '.skey' from PrivateKey object using '@emurgo/cardano-serialization-lib' ?

Open code-brewer opened this issue 2 years ago • 1 comments

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

code-brewer avatar Mar 02 '22 16:03 code-brewer

Hi code-brewer. Here you go:

.skey: spendKey.to_128_xprv() .vkey: spendKey.to_public().as_bytes()

grim-i-am avatar Apr 21 '22 10:04 grim-i-am