Score:1

Convert secp256k1 private key to sr25519 private key

ph flag

Is it possible to convert secp256k1 private key to valid sr25519 key?

Score:3
ng flag

Is it possible to convert secp256k1 private key to valid sr25519 key?

Yes. It's possible to convert any secret piece of data to private or secret key of any cryptosystem, by using that piece of data as seed of a deterministic key generator for said destination cryptosystem. And it's reasonable to do so when there is enough entropy in the source data, including in the case in point since a secp256k1 private key has nearly 256 bits of entropy, when sr25519 is content with a little above 252. Looking at it's spec, it looks like GenPrivKeyFromSecret would do, irrespective of the format of the source key.


Absent a stated purpose, it's hard to be more precise. And it's uncertain the whole endeavor serves a useful purpose. It goes against a common recommendation that I rephrase as:

one use, one key

where you can change use to usage, purpose, website, device… and key to secret, secret key, private key, passphrase, password, PIN…

Maarten Bodewes avatar
in flag
I also included the description of bit clamping, the fact that the public key is not compatible and that you might want to use a KDF (although `GenPrivKeyFromSecret` already does that using SHA-512 basically: see [here](https://github.com/oasisprotocol/curve25519-voi/blob/9075215235b7831a986762f57a46351c473c22b5/primitives/sr25519/keys.go)) in an answer that I was writing. Do you have any idea why SHA-512 is used instead of SHA-256 in that library?
fgrieu avatar
ng flag
@MaartenBodewes : Yes, I (now) see your nice deleted answer. I think using SHA-512 has to do with Ed25519 [traditionally](https://ed25519.cr.yp.to/ed25519-20110926.pdf#page=8) using SHA-512 as a PRF to generate pseudorandom scalars multiplying group elements, with optional reduction modulo prime $\ell=2^{252}+27742317777372353535851937790883648493$ or multiple thereof, in the interest of parameterizable resistance to side-channel attacks.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.