Hi, I’m trying to convert mnemonic to payment and stake private key cbor hex. I know that Cardano have BIP39 words but doesn’t follow it’s algorithm to generate mnemonic and convert it to private key, but what algorithm does it use? and is there a python library that I can use for the help? currently I’m using pycardano.
Generating a root key from the mnemonic would be CIP 3.
Deriving the payment and stake key pairs from it is in CIP 1852 and the BIP32-Ed25519 paper linked in it.
How addresses are constructed from the public key hashes can be found in CIP 19 using the Bech32 encoding.
For Python, you can, for example, use bip_utils to derive keys with quite detailed control: https://github.com/ebellocchia/bip_utils/blob/master/readme/cardano.md#yoroi-icarus
PyCardano should also be able to do it with the HDWallet
class: https://pycardano.readthedocs.io/en/latest/api/pycardano.crypto.html#pycardano.crypto.bip32.HDWallet
For what purpose do you need which CBOR encoding of the result?
thank you for such detailed answer, it’s exactly what I needed. I want CBOR of payment signing key and stake signing key since pycardano imports keys with them. Is there a way to convert private key to CBOR hex of it?
If you derive with PyCardano, you should be able to just use to_primitive()
to get the CBOR that can be read by from_primitive()
: https://pycardano.readthedocs.io/en/latest/api/pycardano.key.html#pycardano.key.Key
When using bip_utils
, you should be able to use https://pypi.org/project/cbor2/ to encode the raw keys.
thank you very much