2

I'm trying to new Cardano.Bip32PrivateKey from string cborHex which in file skey generate by cardano-cli

import * as Cardano from "@emurgo/cardano-serialization-lib-nodejs";

function genAccountKey(cborHex: string) {
    return Cardano.Bip32PrivateKey.from_bytes(Buffer.from(cborHex, "hex"))
        .derive(harden(1852)) // purpose
        .derive(harden(1815)) // coin type
        .derive(harden(0)); // account #0

}
genAccountKey("58204022747367deee69f601900e15ddc04fc8024753b6a1539ee2a8bed29832f420");

but I got this err (node:87994) UnhandledPromiseRejectionWarning: Invalid Secret Key size

2
  • Is it possible to use .skey(s) and .vkey(s) to construct transactions with the Cardano Serialisation Library? Based on your response it seems as though it is not possible since one cannot backwards derive the necessary privatekeys ... Jan 23 at 12:40
  • Welcome aboard. Your answer isn't an answer but it would make a good question. Don't forget to check out the tour and read some of the pinned messages in the help center
    – gRebel
    Jan 23 at 22:24

2 Answers 2

3

The CLI key you generate is not the same as Bip32PrivateKey associated with HD Wallet, the Root key you're considering is green box below - while the CLI key is red one. You can derive from parent key to child, but not the other way round.

enter image description here

1

You can derive a private key from skey CBOR using:

    // Sign with the backend wallet
    const signingKeyHexCBOR = 'THISISYUURKEYCBOR'
    const signingKey = this.S.PrivateKey.from_normal_bytes(Buffer.from(signingKeyHexCBOR,'hex'));

    const vkeyWitness2 = this.S.make_vkey_witness(txHash, signingKey);
    vkeysWitnesses.add(vkeyWitness);
    ```
1
  • do you know how to go the other way? Starting from a Bip32PrivateKey to a CBOR string that I can paste into an skey file that can be used to sign a transaction with cardano-cli?
    – grim_i_am
    Feb 14 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.