Open filoozom opened 2 years ago
While it doesn't seem we can use Subtle Crypto for Waku Message 1 cryptographic operations, I think it could be interested to define a new standard that uses modern schemes available in Subtle Crypto to provide a more secure turn key solution for encryption and signing purposes.
Do note that the direction we are currently going towards for encryption is https://rfc.vac.dev/spec/35/ but this does not help for signing.
Right now,
SymEncoder
uses aUint8Array
key to sign messages and encrypt them. It usessecp256k1
and nothing else can be used. This is a perfectly valid choice and I'm not sure it's worth it making the API more complicated as we already have sane defaults. However, in our case we were already usingcrypto.subtle
, and it turns out that those keys cannot be used withSymEncoder
.Two issues:
crypto.subtle
elliptic curve private keys to theraw
format (so we can't get theUint8Array
we need), at least not without hackscrypto.subtle
only implement NIST curves, whichsecp256k1
is notProposed Solutions
Instead of passing a private key directly, it might be more appropriate to pass some object that contains
sign
andpublicKey
properties for the signing, and another object that has anencrypt
function for the encryption.For example, instead of:
have something like:
Alternatively, it would be quite useful to document the algorithms that are used here: https://js.waku.org/classes/lib_waku_message_version_1.SymEncoder.html
I know I should have read the RFC and maybe dived into the code a bit more, but as someone who is not that familiar with cryptography, I wasn't aware that
P-256
was different fromsecp256k1
for example. In hindsight it seems fairly obvious, but I guess I was a bit too naïve. 😅Notes
From what I can see
secp256k1
is the only curve supported by the RFC (https://rfc.vac.dev/spec/26/), so this might be more trouble than it's worth. For now, I'm just going to change everything and get rid ofcrypto.subtle
in order to implement something closer to the eth-pm example.