-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a secp256r1 resolution method #1261
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is completely right. From the other examples we always just include the X value in the public key part of the did string. Seems like you are including both X and Y.
describe('Secp256r1 mapper', () => { | ||
|
||
it('successfully resolves the document from did', async () => { | ||
const id = "zruuPojWkzGPb8sVc42f2YxcTXKUTpAUbdrzVovaTBmGGNyK6cGFaA4Kp7SSLKecrxYz8Sc9d77Rss7rayYt1oFCaNJ" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik the Key DIDs should only contain the X value (see secp256k1 and ed25519 examples).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the transmute-industries/did-key.js also use this format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so this should be alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transmute industries may be inconsistent with the present state. I believe Orie is updating a part before becoming consistent with the did method key spec and this issue.
w3c-ccg/did-method-key#29 (comment)
However, the did key is the same length as in: https://w3c-ccg.github.io/did-method-key/#p-256 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: Orie is waiting on bls12381 which is not working with node 15. transmute-industries/did-key.js#78 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I include a library, or should I add a function for implementing BigInt to my code?
Which library are you referring to? If it's not too big then I think it's fine to include.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh...line 61 was for the function ECPointDecompress . I added an extra test by taking a compressed public key and flipping the first byte from 03 to 02 and feeding it in to ECPointDecompress. Line 61 looks to be covered by this. The conditional if block that line 61 is in only executes if the parity of the compressed key is opposite (of what is should be?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I need to address the pubKeyBytesToXY function. This is hinted at with the yellow colored 113 and 121 in the uncovered line #s column. I believe the function will fail if the bytesCount is 65 and the 1st byte is not 03, the bytes count is 33 and the 1st bytes is not 03 or 02, or the bytes count is not 64, 65, or 33. I guess I could have the function return null if this is the case. I am not sure how the did:key document will resolve if the function returns null. I could try to report null in place of the key, or give an error message instead of resolving the document will nulls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have full coverage. Unfortunately, I found some tests that I can create that can fail. I have not included them yet since they use functions included to enable the tests, not functions that are in the code. I think that the same bug may be in the code too. I am going to try to see if I can fix the bug in the test function and the code functions.
test that fail:
test('test a hex string shorter than 33 bytes', () => {
const inputPublicKeyHex = '36f8964623378bdc068d4bce07ed17c8fa486f9ac0c2613ca3c8c306d7bb6'
const publicKey_u8a = pubKeyHexToUint8Array(inputPublicKeyHex);
const pubKeyBytesToXY = mapper.pubKeyBytesToXY(publicKey_u8a);
expect(pubKeyBytesToXY).toEqual(null);
});
test('test a hex string between 64 and 33 bytes', () => {
const inputPublicKeyHex = '36f8964623378bdc068d4bce07ed17c8fa486f9ac0c2613ca3c8c306d7bb61cd36717b8ac5e4fea8ad23dc8d0783c2318ee4ad7a80db6e0026ad0b072a24f'
const publicKey_u8a = pubKeyHexToUint8Array(inputPublicKeyHex);
const pubKeyBytesToXY = mapper.pubKeyBytesToXY(publicKey_u8a);
expect(pubKeyBytesToXY).toEqual(null);
});
I suspect these both fail since the hex string has (I'm guessing) an odd number of characters.
@bshambaugh please let us know when this is ready for a full review again :) |
I'm dipping my toes into the case where I have nulls coming into the functions: https://gist.github.com/bshambaugh/333a4d28e3fdb275ed20422e97030e04 |
There's something wrong with this PR theres 269 changed files. Looks like you included build outputs in the src folder somehow. Please fix this and I'll do a final review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Just add the missing dependency bigint-mod-arith
to the package.json. Will merge after this is done.
Tests are passing locally when adding the missing dependency.
} | ||
} | ||
|
||
return XYpairObject; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe throw an error if this is null?
Still seeing issues with this branch. Can you try to do the following: Merge develop into this branch:
Make sure build and lint passes:
That should be it. |
…rors for functions that are dependencies
yes, I still need to work through lint and build. update: they both work without errors or warnings.
|
… additional tests to null. Assume this covers undefined.
To my knowledge, everything looks good. |
…ile. Fix functions to allow undefined cases to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 👍
Btw, I made a PR to the multicodecs table to clarify that the compressed format should be used: multiformats/multicodec#214
@bshambaugh looks like the docs are not building. My bad for not mentioning this to you. Could you make another PR to make sure that |
key-did-resolver$ npm run docs npm ERR! A complete log of this run can be found in: |
@bshambaugh you need to run it in the root directory! |
@bshambaugh We had to revert the change because the docs script didn't pass. Can you please submit a new PR for this feature which includes working docs? 🙏 |
I used JsonWebKey2020 which uses publicJwk to map to an object? This is the first use of publicJwk. secp256k1 and ed25519 uses publicKeyBase58 which uses a string.