w3c-ccg / did-method-key

DID (Decentralized Identifier) did:key method for embedding keys in DID urls
https://w3c-ccg.github.io/did-method-key
Other
18 stars 12 forks source link

Incorrect examples for P-256 #37

Closed davidastark closed 2 years ago

davidastark commented 3 years ago

I was looking into using did:key and was testing specifically with P-256. I had some issues with the libraries I tried (golang and rust) and was looking through the spec to understand what was wrong. I see recently the test-vectors were updated for the P-256 (and P-384 and P-521) to what I would expect from reading the spec.

The examples in the specs (e.g. did:key:zrurwcJZss4ruepVNu1H3xmSirvNbzgBk9qrCktB6kaewXnJAhYWwtP3bxACqBpzjZdN7TyHNzzGGSSH5qvZsSDir9z) is the multi codec code for P-256 pub key (0x1200) followed by the raw uncompressed bytes with no octet prefix. The specs for serializing these keys (SEC1 and ANSI x9.62) there is a single byte (0x4) prefix for uncompressed keys (and 0x2 or 0x3 for compressed). Using the golang crypto/elliptic package to unmarshal the key as above leads to errors unless the prefix is added. Additionally the multicodec page describes the 0x1200 code as "P-256 public Key (compressed)" so I would really expect the bytes to be compressed not uncompressed.

The test vectors recently merged (at least for P-256) are what I would expect from reading the spec, they are the multicodec code followed by a prefix indicating compressed serialization followed by the key bytes and can be unmarshalled using the golang crypto/elliptic package.

Is my understanding of the spec correct and if so will the examples in the doc be updated with correct samples for P-256 (and 384, 521)?

OR13 commented 2 years ago

Was this issue addressed in subsequent PRs?

davidastark commented 2 years ago

Was this issue addressed in subsequent PRs?

Yes it has been addressed. Thanks for drawing my attention to it.