Skip to content
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

Merged
merged 11 commits into from May 25, 2021
Merged

Conversation

bshambaugh
Copy link
Contributor

@bshambaugh bshambaugh commented Apr 14, 2021

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.

Copy link
Member

@oed oed left a 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.

package.json Outdated Show resolved Hide resolved
packages/key-did-resolver/src/secp256r1.ts Show resolved Hide resolved
describe('Secp256r1 mapper', () => {

it('successfully resolves the document from did', async () => {
const id = "zruuPojWkzGPb8sVc42f2YxcTXKUTpAUbdrzVovaTBmGGNyK6cGFaA4Kp7SSLKecrxYz8Sc9d77Rss7rayYt1oFCaNJ"
Copy link
Member

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).

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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 .

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I handle raw (64 byte), compressed (33 byte), and uncompressed (65 byte) keys in my code now. My tests pass, but I do not have full coverage yet. I am currently trying to figure out what to do.
scr-1620860401

Copy link
Contributor Author

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?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scr-1621014068

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scr-1621027899

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.

packages/key-did-resolver/src/secp256r1.ts Outdated Show resolved Hide resolved
@oed
Copy link
Member

oed commented May 14, 2021

@bshambaugh please let us know when this is ready for a full review again :)

@bshambaugh
Copy link
Contributor Author

@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

@oed
Copy link
Member

oed commented May 20, 2021

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!

@bshambaugh
Copy link
Contributor Author

scr-1621607332
scr-1621607383

There is not full test coverage for index.ts

Copy link
Member

@oed oed left a 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;
Copy link
Member

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?

@oed
Copy link
Member

oed commented May 24, 2021

Still seeing issues with this branch. Can you try to do the following:

Merge develop into this branch:

git merge develop

Make sure build and lint passes:

npm run lint
// and
npm run build

That should be it.

@bshambaugh
Copy link
Contributor Author

bshambaugh commented May 24, 2021

Still seeing issues with this branch. Can you try to do the following:

Merge develop into this branch:

git merge develop

Make sure build and lint passes:

npm run lint
// and
npm run build

yes, I still need to work through lint and build. update: they both work without errors or warnings.

That should be it.

@bshambaugh
Copy link
Contributor Author

bshambaugh commented May 25, 2021

… additional tests to null. Assume this covers undefined.
@bshambaugh
Copy link
Contributor Author

To my knowledge, everything looks good.

…ile. Fix functions to allow undefined cases to pass.
Copy link
Member

@oed oed left a 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

@oed oed merged commit 0df0906 into ceramicnetwork:develop May 25, 2021
@oed
Copy link
Member

oed commented May 25, 2021

@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 npm run docs passes?

@bshambaugh
Copy link
Contributor Author

key-did-resolver$ npm run docs
npm ERR! Missing script: "docs"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2021-05-25T13_23_41_860Z-debug.lo

@oed
Copy link
Member

oed commented May 25, 2021

@bshambaugh you need to run it in the root directory!

stbrody pushed a commit that referenced this pull request May 25, 2021
@oed
Copy link
Member

oed commented May 25, 2021

@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? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants