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.