I asked this question on StackOverflow but it seems like it's more appropriate for this Crypto community.
I am using the browser built in SubtleCrypto library in javascript to generate public and private keys as such:
let keyPair = await crypto.subtle.generateKey(
{
name: "ECDSA",
namedCurve: "P-521",
},
true,
['sign', 'verify']
)
console.log(keyPair)
let exportedPublicKey = await crypto.subtle.exportKey("jwk", keyPair.publicKey)
let exportedPrivateKey = await crypto.subtle.exportKey("jwk", keyPair.privateKey)
console.log(exportedPublicKey)
console.log(exportedPrivateKey)
This generates the following (just a test key):
Is there a way to convert the exported keys into a bit more "portable" format? Something which isn't JSON, isn't super long, maybe hex format? Maybe compressed format?
I tried passing "raw" instead of "jwk" for the exportKey
function and that returns an "Operation is not supported"
error because it's probably not supported for this format.
For example, Eth-Crypto has a publicKey.compress()
way to compress the public key into a short enough string: '03a34d6aef3eb42335fb3cacb59478c0b44c0bbeb8bb4ca427dbc7044157a5d24b'
https://github.com/pubkey/eth-crypto#createidentity
Similarly, Schnorr keys are also pretty short.
One of the comments to my question says that I can extract the parameters d, x and y
and With x and y, creating the uncompressed/compressed key is trivial
.
However, I am not sure how to do the second part regarding creating the uncompressed/compressed key from the extracted x, y and d. How can I do that?