-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: support requesting raw IPNS records in @helia/verified-fetch #443
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
66c7617
feat: handle Accept header for raw types in @helia/verified-fetch
achingbrain 67ddf99
chore: add docs
achingbrain 97724a7
Merge remote-tracking branch 'origin/main' into feat/handle-accept-he…
achingbrain 19b04a6
feat: convert between types
achingbrain 0ad29ea
chore: update dev deps
achingbrain 9a1849c
feat: support downloading car files from @helia/verified-fetch
achingbrain 8356cf4
chore: fix deps
achingbrain 70f2efa
feat: download tars from @helia/verified-fetch
achingbrain 12a9ca2
feat: support requesting raw IPNS records in @helia/verified-fetch
achingbrain e9935e2
chore: fix linting and tests
achingbrain 117292a
Merge remote-tracking branch 'origin/main' into feat/verified-fetch-i…
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 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 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 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 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 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,89 @@ | ||
import { dagCbor } from '@helia/dag-cbor' | ||
import { ipns } from '@helia/ipns' | ||
import { stop } from '@libp2p/interface' | ||
import { createEd25519PeerId } from '@libp2p/peer-id-factory' | ||
import { expect } from 'aegir/chai' | ||
import { marshal, unmarshal } from 'ipns' | ||
import { VerifiedFetch } from '../src/verified-fetch.js' | ||
import { createHelia } from './fixtures/create-offline-helia.js' | ||
import type { Helia } from '@helia/interface' | ||
import type { IPNS } from '@helia/ipns' | ||
|
||
describe('ipns records', () => { | ||
let helia: Helia | ||
let name: IPNS | ||
let verifiedFetch: VerifiedFetch | ||
|
||
beforeEach(async () => { | ||
helia = await createHelia() | ||
name = ipns(helia) | ||
verifiedFetch = new VerifiedFetch({ | ||
helia | ||
}) | ||
}) | ||
|
||
afterEach(async () => { | ||
await stop(helia, verifiedFetch) | ||
}) | ||
|
||
it('should support fetching a raw IPNS record', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we have this test, we can remove https://github.com/ipfs/helia/blob/main/packages/verified-fetch/test/accept-header.spec.ts#L227-L248 which is skipped anyways |
||
const obj = { | ||
hello: 'world' | ||
} | ||
const c = dagCbor(helia) | ||
const cid = await c.add(obj) | ||
|
||
const peerId = await createEd25519PeerId() | ||
const record = await name.publish(peerId, cid) | ||
|
||
const resp = await verifiedFetch.fetch(`ipns://${peerId}`, { | ||
headers: { | ||
accept: 'application/vnd.ipfs.ipns-record' | ||
} | ||
}) | ||
expect(resp.status).to.equal(200) | ||
expect(resp.headers.get('content-type')).to.equal('application/vnd.ipfs.ipns-record') | ||
|
||
const buf = new Uint8Array(await resp.arrayBuffer()) | ||
expect(marshal(record)).to.equalBytes(buf) | ||
|
||
const output = unmarshal(buf) | ||
expect(output.value).to.deep.equal(`/ipfs/${cid}`) | ||
}) | ||
|
||
it('should reject a request for non-IPNS url', async () => { | ||
const resp = await verifiedFetch.fetch('ipfs://QmbxpRxwKXxnJQjnPqm1kzDJSJ8YgkLxH23mcZURwPHjGv', { | ||
headers: { | ||
accept: 'application/vnd.ipfs.ipns-record' | ||
} | ||
}) | ||
expect(resp.status).to.equal(400) | ||
}) | ||
|
||
it('should reject a request for a DNSLink url', async () => { | ||
const resp = await verifiedFetch.fetch('ipns://ipfs.io', { | ||
headers: { | ||
accept: 'application/vnd.ipfs.ipns-record' | ||
} | ||
}) | ||
expect(resp.status).to.equal(400) | ||
}) | ||
|
||
it('should reject a request for a url with a path component', async () => { | ||
const obj = { | ||
hello: 'world' | ||
} | ||
const c = dagCbor(helia) | ||
const cid = await c.add(obj) | ||
|
||
const peerId = await createEd25519PeerId() | ||
await name.publish(peerId, cid) | ||
|
||
const resp = await verifiedFetch.fetch(`ipns://${peerId}/hello`, { | ||
headers: { | ||
accept: 'application/vnd.ipfs.ipns-record' | ||
} | ||
}) | ||
expect(resp.status).to.equal(400) | ||
}) | ||
}) |
This file contains 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
Oops, something went wrong.
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.
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 is only here to be able to deserialize stored IPNS records that are wrapped in a libp2p record.
Longer term we may wish to split the libp2p record code out of the dht code to make the bundle size a bit smaller.
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.
Do we have a tracking issue for this?