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

fix: update record selection rules #134

Merged
merged 2 commits into from
Sep 2, 2021

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Sep 1, 2021

Perform the same validation as go-ipns.

  • If a record has a v2 sig and the other does not, prefer that record
  • If the sequence numbers are not equal, prefer the record with the higher sequence number
  • If the sequence numbers are equal, prefer the record with the longer validity
  • Otherwise prefer the first record

Also validates that embedded keys, where present, match the PeerId from the
IPNS Record.

Also, also: runs the type checker over the tests.

BREAKING CHANGE: extractPublicKey is now async

- If a record has a v2 sig and the other does not, prefer that record
- If the sequence numbers are equal, prefer the record with the longer validity
- Otherwise prefer the first record
Make sure the embedded key, if present, matches the passed IPNS key
as it should be derived from the embedded key.

BREAKING CHANGE: extractPublicKey is now async
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM, added a nit, but feel free to merge/release

expect(entryDataCreated.ttl).to.equal(unmarshalledData.ttl)

if (!unmarshalledData.signatureV2) {
throw new Error('No v2 sig found')
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we expect to have property instead?

Copy link
Member Author

@achingbrain achingbrain Sep 2, 2021

Choose a reason for hiding this comment

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

That would certainly be my preference! The problem here is that the type of .signatureV2 is Uint8Array | undefined and the type of arg in .equalBytes(arg) is ArrayLike<number> | string and the two are incompatible since arg cannot be undefined.

By checking if .signatureV2 has a truthy value tsc knows it's Uint8Array which is then compatible with ArrayLike<number>.

Copy link
Member Author

Choose a reason for hiding this comment

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

@achingbrain achingbrain merged commit fd1481a into master Sep 2, 2021
@achingbrain achingbrain deleted the fix/update-record-selection-rules branch September 2, 2021 07:07
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.

2 participants