-
Notifications
You must be signed in to change notification settings - Fork 26
feat!: opt-in V2-only records, IPIP-428 verification #234
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b329147
feat: v2-only creation, relaxed verification
hacdias e2fca17
chore: apply review suggestions
hacdias d04f96f
refactor: rename signature to signatureV1
hacdias 9997cc1
test: should validate a V2 and V1+V2 records
hacdias b6566f7
refactor: change value from bytes array to string
hacdias ba7e65c
feat: normalize value at creation and read time
hacdias 2817e33
refactor using interfaces
hacdias cedb3f2
fix!: only accept CIDs, PeerIds or strings as values (#255)
achingbrain a56357d
Merge remote-tracking branch 'origin/master' into validate-v2
achingbrain a073704
Merge remote-tracking branch 'origin/master' into validate-v2
achingbrain 354d62a
test: add conformance tests
achingbrain 0f6c4c2
test: add validation to conformance tests
achingbrain 0e081e7
chore: rename type
achingbrain 108a839
chore: update type
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* eslint-env mocha */ | ||
|
|
||
| import { unmarshalPublicKey } from '@libp2p/crypto/keys' | ||
| import { peerIdFromCID } from '@libp2p/peer-id' | ||
| import { expect } from 'aegir/chai' | ||
| import loadFixture from 'aegir/fixtures' | ||
| import { base36 } from 'multiformats/bases/base36' | ||
| import { CID } from 'multiformats/cid' | ||
| import * as ERRORS from '../src/errors.js' | ||
| import * as ipns from '../src/index.js' | ||
| import { validate } from '../src/validator.js' | ||
|
|
||
| describe('conformance', function () { | ||
| it('should reject a v1 only record', async () => { | ||
| const buf = loadFixture('test/fixtures/k51qzi5uqu5dm4tm0wt8srkg9h9suud4wuiwjimndrkydqm81cqtlb5ak6p7ku_v1.ipns-record') | ||
|
|
||
| expect(() => ipns.unmarshal(buf)).to.throw(/missing data or signatureV2/) | ||
| .with.property('code', ERRORS.ERR_SIGNATURE_VERIFICATION) | ||
| }) | ||
|
|
||
| it('should validate a record with v1 and v2 signatures', async () => { | ||
| const buf = loadFixture('test/fixtures/k51qzi5uqu5dlkw8pxuw9qmqayfdeh4kfebhmreauqdc6a7c3y7d5i9fi8mk9w_v1-v2.ipns-record') | ||
| const record = ipns.unmarshal(buf) | ||
|
|
||
| const cid = CID.parse('k51qzi5uqu5dlkw8pxuw9qmqayfdeh4kfebhmreauqdc6a7c3y7d5i9fi8mk9w', base36) | ||
| const peerId = peerIdFromCID(cid) | ||
| const publicKey = unmarshalPublicKey(peerId.publicKey ?? new Uint8Array()) | ||
| await validate(publicKey, buf) | ||
|
|
||
| expect(record.value).to.equal('/ipfs/bafkqaddwgevxmmraojswg33smq') | ||
| }) | ||
|
|
||
| it('should reject a record with inconsistent value fields', async () => { | ||
| const buf = loadFixture('test/fixtures/k51qzi5uqu5dlmit2tuwdvnx4sbnyqgmvbxftl0eo3f33wwtb9gr7yozae9kpw_v1-v2-broken-v1-value.ipns-record') | ||
|
|
||
| expect(() => ipns.unmarshal(buf)).to.throw(/Field "value" did not match/) | ||
| .with.property('code', ERRORS.ERR_SIGNATURE_VERIFICATION) | ||
| }) | ||
|
|
||
| it('should reject a record with v1 and v2 signatures but invalid v2', async () => { | ||
| const buf = loadFixture('test/fixtures/k51qzi5uqu5diamp7qnnvs1p1gzmku3eijkeijs3418j23j077zrkok63xdm8c_v1-v2-broken-signature-v2.ipns-record') | ||
| const cid = CID.parse('k51qzi5uqu5diamp7qnnvs1p1gzmku3eijkeijs3418j23j077zrkok63xdm8c', base36) | ||
| const peerId = peerIdFromCID(cid) | ||
| const publicKey = unmarshalPublicKey(peerId.publicKey ?? new Uint8Array()) | ||
|
|
||
| await expect(validate(publicKey, buf)).to.eventually.be.rejectedWith(/record signature verification failed/) | ||
| .with.property('code', ERRORS.ERR_SIGNATURE_VERIFICATION) | ||
| }) | ||
|
|
||
| it('should reject a record with v1 and v2 signatures but invalid v1', async () => { | ||
| const buf = loadFixture('test/fixtures/k51qzi5uqu5dilgf7gorsh9vcqqq4myo6jd4zmqkuy9pxyxi5fua3uf7axph4y_v1-v2-broken-signature-v1.ipns-record') | ||
| const record = ipns.unmarshal(buf) | ||
|
|
||
| expect(record.value).to.equal('/ipfs/bafkqahtwgevxmmrao5uxi2bamjzg623fnyqhg2lhnzqxi5lsmuqhmmi') | ||
| }) | ||
|
|
||
| it('should validate a record with only v2 signature', async () => { | ||
| const buf = loadFixture('test/fixtures/k51qzi5uqu5dit2ku9mutlfgwyz8u730on38kd10m97m36bjt66my99hb6103f_v2.ipns-record') | ||
| const record = ipns.unmarshal(buf) | ||
|
|
||
| const cid = CID.parse('k51qzi5uqu5dit2ku9mutlfgwyz8u730on38kd10m97m36bjt66my99hb6103f', base36) | ||
| const peerId = peerIdFromCID(cid) | ||
| const publicKey = unmarshalPublicKey(peerId.publicKey ?? new Uint8Array()) | ||
| await validate(publicKey, buf) | ||
|
|
||
| expect(record.value).to.equal('/ipfs/bafkqadtwgiww63tmpeqhezldn5zgi') | ||
| }) | ||
| }) |
Binary file added
BIN
+334 Bytes
...diamp7qnnvs1p1gzmku3eijkeijs3418j23j077zrkok63xdm8c_v1-v2-broken-signature-v2.ipns-record
Binary file not shown.
Binary file added
BIN
+334 Bytes
...dilgf7gorsh9vcqqq4myo6jd4zmqkuy9pxyxi5fua3uf7axph4y_v1-v2-broken-signature-v1.ipns-record
Binary file not shown.
Binary file added
BIN
+188 Bytes
test/fixtures/k51qzi5uqu5dit2ku9mutlfgwyz8u730on38kd10m97m36bjt66my99hb6103f_v2.ipns-record
Binary file not shown.
Binary file added
BIN
+326 Bytes
...fixtures/k51qzi5uqu5dlkw8pxuw9qmqayfdeh4kfebhmreauqdc6a7c3y7d5i9fi8mk9w_v1-v2.ipns-record
Binary file not shown.
Binary file added
BIN
+377 Bytes
...uqu5dlmit2tuwdvnx4sbnyqgmvbxftl0eo3f33wwtb9gr7yozae9kpw_v1-v2-broken-v1-value.ipns-record
Binary file not shown.
Binary file added
BIN
+144 Bytes
test/fixtures/k51qzi5uqu5dm4tm0wt8srkg9h9suud4wuiwjimndrkydqm81cqtlb5ak6p7ku_v1.ipns-record
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.