Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert from_bech32 #202

Open
rezagazeri opened this issue Sep 16, 2021 · 3 comments
Open

convert from_bech32 #202

rezagazeri opened this issue Sep 16, 2021 · 3 comments
Assignees

Comments

@rezagazeri
Copy link

Hi,
first I want to say thanks due to this library.
I use @emurgo/cardano-serialization-lib-nodejs and created PrivateKey and convert it to bech32 like below:
privKey=PrivateKey { ptr: 1180592 } and privKey.to_bech32()="ed25519e_sk1qqns8r2m54r7u5wtm27......"
and now i need to convert it from_bech32 but i can not find this function
->CardanoWasm.PrivateKey.from_bech32("ed25519e_sk16rl5fq....")
how can I convert from bech32 to privatekey ?
thanks in advance

@SebastienGllmt
Copy link
Contributor

If I recall this was never added because there was no standard for differentiating extended ed25519 keys from non-extended ones. Although serialization-lib ended up using ed25519e and ed25519 as different prefixes to differentiate these cases, I don't remember if cardano-cli ever adopted this standard in the end. Issues like this is what prompted the creation of CIP 5 but I see that neither prefixes are on that registry. There was discussion about standardizing bech32 for keys but as you can see it's not simple

If you want a workaround, you can use your own bech32 parsing library to turn the bech32 string into a byte array and then call the right constructor for PrivateKey yourself.

We could add a from_bech32 function to this library that checks the prefix and if it doesn't match it throws an error. This could be an awkward breaking change in the future though so maybe it's best to add the prefixes to CIP5 first.

@rezagazeri
Copy link
Author

in the lib doc on below address :
https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-transactions.md

you used (const prvKey = CardanoWasm.PrivateKey.from_bech32("ed25519e_sk16rl5fqqf4mg27syjzjrq8h3vq44jnnv52mvyzdttldszjj7a64xtmjwgjtfy25lu0xmv40306lj9pcqpa6slry9eh3mtlqvfjz93vuq0grl80");)
however I need to convert PrivateKey format to string format because I want to save it in db and so read from db and again convert to privateKey.

@jinglescode
Copy link

I have existing wallets and keys generated by cardano-cli stake-address build, which produces .skey and .pkey files.

From this generating-transactions example, we need bech32 like so:

const rootKey = CardanoWasm.BIP32PrivateKey.from_bech32("xprv17qx9vxm6060qjn5fgazfue9nwyf448w7upk60c3epln82vumg9r9kxzsud9uv5rfscxp382j2aku254zj3qfx9fx39t6hjwtmwq85uunsd8x0st3j66lzf5yn30hwq5n75zeuplepx8vxc502txx09ygjgx06n0p");

How do I read and load in these .pkey files into cardano-serialization-lib?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants