@helia/verified-fetch 0.0.0-8a5bc6f → 0.0.0-9b1ddf8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +80 -43
  2. package/dist/index.min.js +4 -29
  3. package/dist/src/index.d.ts +114 -52
  4. package/dist/src/index.d.ts.map +1 -1
  5. package/dist/src/index.js +87 -48
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/singleton.d.ts +3 -0
  8. package/dist/src/singleton.d.ts.map +1 -0
  9. package/dist/src/singleton.js +15 -0
  10. package/dist/src/singleton.js.map +1 -0
  11. package/dist/src/utils/get-stream-from-async-iterable.d.ts +10 -0
  12. package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +1 -0
  13. package/dist/src/utils/{get-stream-and-content-type.js → get-stream-from-async-iterable.js} +10 -9
  14. package/dist/src/utils/get-stream-from-async-iterable.js.map +1 -0
  15. package/dist/src/verified-fetch.d.ts +4 -1
  16. package/dist/src/verified-fetch.d.ts.map +1 -1
  17. package/dist/src/verified-fetch.js +46 -18
  18. package/dist/src/verified-fetch.js.map +1 -1
  19. package/package.json +19 -19
  20. package/src/index.ts +120 -53
  21. package/src/singleton.ts +20 -0
  22. package/src/utils/{get-stream-and-content-type.ts → get-stream-from-async-iterable.ts} +9 -8
  23. package/src/verified-fetch.ts +53 -22
  24. package/dist/src/utils/get-content-type.d.ts +0 -11
  25. package/dist/src/utils/get-content-type.d.ts.map +0 -1
  26. package/dist/src/utils/get-content-type.js +0 -43
  27. package/dist/src/utils/get-content-type.js.map +0 -1
  28. package/dist/src/utils/get-stream-and-content-type.d.ts +0 -10
  29. package/dist/src/utils/get-stream-and-content-type.d.ts.map +0 -1
  30. package/dist/src/utils/get-stream-and-content-type.js.map +0 -1
  31. package/src/utils/get-content-type.ts +0 -55
@@ -1,57 +1,49 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * `@helia/verified-fetch` is a library that provides a fetch-like API for fetching trustless content from IPFS and verifying it.
4
+ * `@helia/verified-fetch` provides a [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-like API for retrieving content from the [IPFS](https://ipfs.tech/) network.
5
5
  *
6
- * This library should act as a replacement for the `fetch()` API for fetching content from IPFS, and will return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object that can be used in a similar manner to the `fetch()` API. This means browser and HTTP caching inside browser main threads, web-workers, and service workers, as well as other features of the `fetch()` API should work in a way familiar to developers.
6
+ * All content is retrieved in a [trustless manner](https://www.techopedia.com/definition/trustless), and the integrity of all bytes are verified by comparing hashes of the data.
7
7
  *
8
- * Exports a `createVerifiedFetch` function that returns a `fetch()` like API method {@link Helia} for fetching IPFS content.
8
+ * This is a marked improvement over `fetch` which offers no such protections and is vulnerable to all sorts of attacks like [Content Spoofing](https://owasp.org/www-community/attacks/Content_Spoofing), [DNS Hijacking](https://en.wikipedia.org/wiki/DNS_hijacking), etc.
9
+ *
10
+ * A `verifiedFetch` function is exported to get up and running quickly, and a `createVerifiedFetch` function is also available that allows customizing the underlying [Helia](https://helia.io/) node for complete control over how content is retrieved.
11
+ *
12
+ * Browser-cache-friendly [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects are returned which should be instantly familiar to web developers.
9
13
  *
10
14
  * You may use any supported resource argument to fetch content:
11
15
  *
12
- * - CID instance
16
+ * - [CID](https://multiformats.github.io/js-multiformats/classes/cid.CID.html) instance
13
17
  * - IPFS URL
14
18
  * - IPNS URL
15
19
  *
16
- * @example
20
+ * @example Getting started
17
21
  *
18
22
  * ```typescript
19
- * import { createVerifiedFetch } from '@helia/verified-fetch'
23
+ * import { verifiedFetch } from '@helia/verified-fetch'
20
24
  *
21
- * const fetch = await createVerifiedFetch({
22
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
23
- *})
24
- *
25
- * const resp = await fetch('ipfs://bafy...')
25
+ * const resp = await verifiedFetch('ipfs://bafy...')
26
26
  *
27
27
  * const json = await resp.json()
28
28
  *```
29
29
  *
30
- *
31
30
  * @example Using a CID instance to fetch JSON
32
31
  *
33
32
  * ```typescript
34
- * import { createVerifiedFetch } from '@helia/verified-fetch'
33
+ * import { verifiedFetch } from '@helia/verified-fetch'
35
34
  * import { CID } from 'multiformats/cid'
36
35
  *
37
- * const fetch = await createVerifiedFetch({
38
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
39
- * })
40
- *
41
36
  * const cid = CID.parse('bafyFoo') // some image file
42
- * const response = await fetch(cid)
37
+ * const response = await verifiedFetch(cid)
43
38
  * const json = await response.json()
44
39
  * ```
45
40
  *
46
41
  * @example Using IPFS protocol to fetch an image
47
42
  *
48
43
  * ```typescript
49
- * import { createVerifiedFetch } from '@helia/verified-fetch'
44
+ * import { verifiedFetch } from '@helia/verified-fetch'
50
45
  *
51
- * const fetch = await createVerifiedFetch({
52
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
53
- * })
54
- * const response = await fetch('ipfs://bafyFoo') // CID for some image file
46
+ * const response = await verifiedFetch('ipfs://bafyFoo') // CID for some image file
55
47
  * const blob = await response.blob()
56
48
  * const image = document.createElement('img')
57
49
  * image.src = URL.createObjectURL(blob)
@@ -61,22 +53,42 @@
61
53
  * @example Using IPNS protocol to stream a big file
62
54
  *
63
55
  * ```typescript
56
+ * import { verifiedFetch } from '@helia/verified-fetch'
57
+ *
58
+ * const response = await verifiedFetch('ipns://mydomain.com/path/to/very-long-file.log')
59
+ * const bigFileStreamReader = await response.body.getReader()
60
+ * ```
61
+ *
62
+ * ## Configuration
63
+ *
64
+ * ### Custom HTTP gateways and routers
65
+ *
66
+ * Out of the box `@helia/verified-fetch` uses a default set of [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/) for fetching blocks and [HTTP delegated routers](https://specs.ipfs.tech/routing/http-routing-v1/) for performing routing tasks - looking up peers, resolving/publishing [IPNS](https://docs.ipfs.tech/concepts/ipns/) names, etc.
67
+ *
68
+ * It's possible to override these by passing `gateways` and `routers` keys to the `createVerifiedFetch` function:
69
+ *
70
+ * @example Configuring gateways and routers
71
+ *
72
+ * ```typescript
64
73
  * import { createVerifiedFetch } from '@helia/verified-fetch'
65
74
  *
66
75
  * const fetch = await createVerifiedFetch({
67
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
76
+ * gateways: ['https://trustless-gateway.link'],
77
+ * routers: ['http://delegated-ipfs.dev']
68
78
  * })
69
- * const response = await fetch('ipns://mydomain.com/path/to/very-long-file.log')
70
- * const bigFileStreamReader = await response.body.getReader()
71
- * ```
72
79
  *
73
- * ### Configuration
80
+ * const resp = await fetch('ipfs://bafy...')
74
81
  *
75
- * #### Usage with customized Helia
82
+ * const json = await resp.json()
83
+ *```
76
84
  *
77
- * You can see variations of Helia and js-libp2p configuration options at https://helia.io/interfaces/helia.index.HeliaInit.html.
85
+ * ### Usage with customized Helia
86
+ *
87
+ * For full control of how `@helia/verified-fetch` fetches content from the distributed web you can pass a preconfigured Helia node to `createVerifiedFetch`.
78
88
  *
79
- * The `@helia/http` module is currently in-progress, but the init options should be a subset of the `helia` module's init options. See https://github.com/ipfs/helia/issues/289 for more information.
89
+ * The [helia](https://www.npmjs.com/package/helia) module is configured with a libp2p node that is suited for decentralized applications, alternatively [@helia/http](https://www.npmjs.com/package/@helia/http) is available which uses HTTP gateways for all network operations.
90
+ *
91
+ * You can see variations of Helia and js-libp2p configuration options at https://helia.io/interfaces/helia.index.HeliaInit.html.
80
92
  *
81
93
  * ```typescript
82
94
  * import { trustlessGateway } from '@helia/block-brokers'
@@ -100,28 +112,54 @@
100
112
  * const json = await resp.json()
101
113
  * ```
102
114
  *
103
- * ### Comparison to fetch
115
+ * ### Custom content-type parsing
116
+ *
117
+ * By default, `@helia/verified-fetch` sets the `Content-Type` header as `application/octet-stream` - this is because the `.json()`, `.text()`, `.blob()`, and `.arrayBuffer()` methods will usually work as expected without a detailed content type.
118
+ *
119
+ * If you require an accurate content-type you can provide a `contentTypeParser` function as an option to `createVerifiedFetch` to handle parsing the content type.
104
120
  *
105
- * First, this library will require instantiation in order to configure the gateways and delegated routers, or potentially a custom Helia instance. Secondly, once your verified-fetch method is created, it will act as similar to the `fetch()` API as possible.
121
+ * The function you provide will be called with the first chunk of bytes from the file and should return a string or a promise of a string.
122
+ *
123
+ * @example Customizing content-type parsing
124
+ *
125
+ * ```typescript
126
+ * import { createVerifiedFetch } from '@helia/verified-fetch'
127
+ * import { fileTypeFromBuffer } from '@sgtpooki/file-type'
128
+ *
129
+ * const fetch = await createVerifiedFetch({
130
+ * gateways: ['https://trustless-gateway.link'],
131
+ * routers: ['http://delegated-ipfs.dev']
132
+ * }, {
133
+ * contentTypeParser: async (bytes) => {
134
+ * // call to some magic-byte recognition library like magic-bytes, file-type, or your own custom byte recognition
135
+ * const result = await fileTypeFromBuffer(bytes)
136
+ * return result?.mime
137
+ * }
138
+ * })
139
+ * ```
140
+ *
141
+ * ## Comparison to fetch
142
+ *
143
+ * This module attempts to act as similarly to the `fetch()` API as possible.
106
144
  *
107
145
  * [The `fetch()` API](https://developer.mozilla.org/en-US/docs/Web/API/fetch) takes two parameters:
108
146
  *
109
147
  * 1. A [resource](https://developer.mozilla.org/en-US/docs/Web/API/fetch#resource)
110
148
  * 2. An [options object](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options)
111
149
  *
112
- * #### Resource argument
150
+ * ### Resource argument
113
151
  *
114
- * This library intends to support the following methods of fetching web3 content from IPFS:
152
+ * This library supports the following methods of fetching web3 content from IPFS:
115
153
  *
116
154
  * 1. IPFS protocol: `ipfs://<cidv0>` & `ipfs://<cidv0>`
117
155
  * 2. IPNS protocol: `ipns://<peerId>` & `ipns://<publicKey>` & `ipns://<hostUri_Supporting_DnsLink_TxtRecords>`
118
156
  * 3. CID instances: An actual CID instance `CID.parse('bafy...')`
119
157
  *
120
- * As well as support for pathing & params for item 1&2 above according to [IPFS - Path Gateway Specification](https://specs.ipfs.tech/http-gateways/path-gateway) & [IPFS - Trustless Gateway Specification](https://specs.ipfs.tech/http-gateways/trustless-gateway/). Further refinement of those specifications specifically for web-based scenarios can be found in the [Web Pathing Specification IPIP](https://github.com/ipfs/specs/pull/453).
158
+ * As well as support for pathing & params for item 1 & 2 above according to [IPFS - Path Gateway Specification](https://specs.ipfs.tech/http-gateways/path-gateway) & [IPFS - Trustless Gateway Specification](https://specs.ipfs.tech/http-gateways/trustless-gateway/). Further refinement of those specifications specifically for web-based scenarios can be found in the [Web Pathing Specification IPIP](https://github.com/ipfs/specs/pull/453).
121
159
  *
122
- * If you pass a CID instance, we assume you want the content for that specific CID only, and do not support pathing or params for that CID.
160
+ * If you pass a CID instance, it assumes you want the content for that specific CID only, and does not support pathing or params for that CID.
123
161
  *
124
- * #### Options argument
162
+ * ### Options argument
125
163
  *
126
164
  * This library does not plan to support the exact Fetch API options object, as some of the arguments don't make sense. Instead, it will only support options necessary to meet [IPFS specs](https://specs.ipfs.tech/) related to specifying the resultant shape of desired content.
127
165
  *
@@ -146,7 +184,6 @@
146
184
  * 5. `body` - An object that specifies the body of the request. Best effort to adhere to the [Fetch API body](https://developer.mozilla.org/en-US/docs/Web/API/fetch#body) parameter.
147
185
  * 6. `cache` - Will basically act as `force-cache` for the request. Best effort to adhere to the [Fetch API cache](https://developer.mozilla.org/en-US/docs/Web/API/fetch#cache) parameter.
148
186
  *
149
- *
150
187
  * Non-Fetch API options that will be supported:
151
188
  *
152
189
  * 1. `onProgress` - Similar to Helia `onProgress` options, this will be a function that will be called with a progress event. Supported progress events are:
@@ -167,7 +204,7 @@
167
204
  * 4. [IPIP-0328: JSON and CBOR Response Formats on HTTP Gateways](https://specs.ipfs.tech/ipips/ipip-0328/)
168
205
  * 5. [IPIP-0288: TAR Response Format on HTTP Gateways](https://specs.ipfs.tech/ipips/ipip-0288/)
169
206
  *
170
- * #### Response types
207
+ * ### Response types
171
208
  *
172
209
  * This library's purpose is to return reasonably representable content from IPFS. In other words, fetching content is intended for leaf-node content -- such as images/videos/audio & other assets, or other IPLD content (with link) -- that can be represented by https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods. The content type you receive back will depend upon the CID you request as well as the `Accept` header value you provide.
173
210
  *
@@ -175,7 +212,7 @@
175
212
  *
176
213
  * If your content doesn't have a mime-type or an [IPFS spec](https://specs.ipfs.tech), this library will not support it, but you can use the [`helia`](https://github.com/ipfs/helia) library directly for those use cases. See [Unsupported response types](#unsupported-response-types) for more information.
177
214
  *
178
- * ##### Handling response types
215
+ * #### Handling response types
179
216
  *
180
217
  * For handling responses we want to follow conventions/abstractions from Fetch API where possible:
181
218
  *
@@ -184,12 +221,12 @@
184
221
  * - For plain text in utf-8, you would call `.text()`
185
222
  * - For streaming response data, use something like `response.body.getReader()` to get a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#consuming_a_fetch_as_a_stream).
186
223
  *
187
- * ##### Unsupported response types
224
+ * #### Unsupported response types
188
225
  *
189
226
  * * Returning IPLD nodes or DAGs as JS objects is not supported, as there is no currently well-defined structure for representing this data in an [HTTP Response](https://developer.mozilla.org/en-US/docs/Web/API/Response). Instead, users should request `aplication/vnd.ipld.car` or use the [`helia`](https://github.com/ipfs/helia) library directly for this use case.
190
227
  * * Others? Open an issue or PR!
191
228
  *
192
- * #### Response headers
229
+ * ### Response headers
193
230
  *
194
231
  * This library will set the [HTTP Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) headers to the appropriate values for the content type according to the appropriate [IPFS Specifications](https://specs.ipfs.tech/).
195
232
  *
@@ -199,13 +236,13 @@
199
236
  * * https://specs.ipfs.tech/http-gateways/trustless-gateway/#response-headers
200
237
  * * https://specs.ipfs.tech/http-gateways/subdomain-gateway/#response-headers
201
238
  *
202
- * #### Possible Scenarios that could cause confusion
239
+ * ### Possible Scenarios that could cause confusion
203
240
  *
204
- * ##### Attempting to fetch the CID for content that does not make sense
241
+ * #### Attempting to fetch the CID for content that does not make sense
205
242
  *
206
243
  * If you request `bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze`, which points to the root of the en.wikipedia.org mirror, a response object does not make sense.
207
244
  *
208
- * #### Errors
245
+ * ### Errors
209
246
  *
210
247
  * Known Errors that can be thrown:
211
248
  *
@@ -224,7 +261,7 @@ import type { ProgressEvent, ProgressOptions } from 'progress-events';
224
261
  */
225
262
  export type Resource = string | CID;
226
263
  export interface CIDDetail {
227
- cid: string;
264
+ cid: CID;
228
265
  path: string;
229
266
  }
230
267
  export interface CIDDetailError extends CIDDetail {
@@ -236,24 +273,49 @@ export interface VerifiedFetch {
236
273
  stop(): Promise<void>;
237
274
  }
238
275
  /**
239
- * Instead of passing a Helia instance, you can pass a list of gateways and routers, and a HeliaHTTP instance will be created for you.
276
+ * Instead of passing a Helia instance, you can pass a list of gateways and
277
+ * routers, and a HeliaHTTP instance will be created for you.
240
278
  */
241
- export interface CreateVerifiedFetchWithOptions {
279
+ export interface CreateVerifiedFetchInit {
242
280
  gateways: string[];
243
281
  routers?: string[];
244
282
  }
283
+ export interface CreateVerifiedFetchOptions {
284
+ /**
285
+ * A function to handle parsing content type from bytes. The function you
286
+ * provide will be passed the first set of bytes we receive from the network,
287
+ * and should return a string that will be used as the value for the
288
+ * `Content-Type` header in the response.
289
+ */
290
+ contentTypeParser?: ContentTypeParser;
291
+ }
292
+ /**
293
+ * A ContentTypeParser attempts to return the mime type of a given file. It
294
+ * receives the first chunk of the file data and the file name, if it is
295
+ * available. The function can be sync or async and if it returns/resolves to
296
+ * `undefined`, `application/octet-stream` will be used.
297
+ */
298
+ export interface ContentTypeParser {
299
+ /**
300
+ * Attempt to determine a mime type, either via of the passed bytes or the
301
+ * filename if it is available.
302
+ */
303
+ (bytes: Uint8Array, fileName?: string): Promise<string | undefined> | string | undefined;
304
+ }
245
305
  export type BubbledProgressEvents = GetEvents | ResolveProgressEvents | ResolveDnsLinkProgressEvents | IPNSRoutingEvents;
246
306
  export type VerifiedFetchProgressEvents = ProgressEvent<'verified-fetch:request:start', CIDDetail> | ProgressEvent<'verified-fetch:request:info', string> | ProgressEvent<'verified-fetch:request:progress:chunk', CIDDetail> | ProgressEvent<'verified-fetch:request:end', CIDDetail> | ProgressEvent<'verified-fetch:request:error', CIDDetailError>;
247
307
  /**
248
308
  * Options for the `fetch` function returned by `createVerifiedFetch`.
249
309
  *
250
- * This method accepts all the same options as the `fetch` function in the browser, plus an `onProgress` option to
251
- * listen for progress events.
310
+ * This interface contains all the same fields as the [options object](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options)
311
+ * passed to `fetch` in browsers, plus an `onProgress` option to listen for
312
+ * progress events.
252
313
  */
253
314
  export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledProgressEvents | VerifiedFetchProgressEvents> {
254
315
  }
255
316
  /**
256
317
  * Create and return a Helia node
257
318
  */
258
- export declare function createVerifiedFetch(init?: Helia | CreateVerifiedFetchWithOptions): Promise<VerifiedFetch>;
319
+ export declare function createVerifiedFetch(init?: Helia | CreateVerifiedFetchInit, options?: CreateVerifiedFetchOptions): Promise<VerifiedFetch>;
320
+ export { verifiedFetch } from './singleton.js';
259
321
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuNG;AAMH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACzG,OAAO,KAAK,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AAC,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;CACtC;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAA;CACzF;AAED,MAAM,MAAM,qBAAqB,GAE/B,SAAS,GAET,qBAAqB,GAAG,4BAA4B,GAAG,iBAAiB,CAAA;AAE1E,MAAM,MAAM,2BAA2B,GACrC,aAAa,CAAC,8BAA8B,EAAE,SAAS,CAAC,GACxD,aAAa,CAAC,6BAA6B,EAAE,MAAM,CAAC,GACpD,aAAa,CAAC,uCAAuC,EAAE,SAAS,CAAC,GACjE,aAAa,CAAC,4BAA4B,EAAE,SAAS,CAAC,GACtD,aAAa,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAA;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW,EAAE,eAAe,CAAC,qBAAqB,GAAG,2BAA2B,CAAC;CAC3H;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,IAAI,CAAC,EAAE,KAAK,GAAG,uBAAuB,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CAsB/I;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
package/dist/src/index.js CHANGED
@@ -1,57 +1,49 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * `@helia/verified-fetch` is a library that provides a fetch-like API for fetching trustless content from IPFS and verifying it.
4
+ * `@helia/verified-fetch` provides a [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-like API for retrieving content from the [IPFS](https://ipfs.tech/) network.
5
5
  *
6
- * This library should act as a replacement for the `fetch()` API for fetching content from IPFS, and will return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object that can be used in a similar manner to the `fetch()` API. This means browser and HTTP caching inside browser main threads, web-workers, and service workers, as well as other features of the `fetch()` API should work in a way familiar to developers.
6
+ * All content is retrieved in a [trustless manner](https://www.techopedia.com/definition/trustless), and the integrity of all bytes are verified by comparing hashes of the data.
7
7
  *
8
- * Exports a `createVerifiedFetch` function that returns a `fetch()` like API method {@link Helia} for fetching IPFS content.
8
+ * This is a marked improvement over `fetch` which offers no such protections and is vulnerable to all sorts of attacks like [Content Spoofing](https://owasp.org/www-community/attacks/Content_Spoofing), [DNS Hijacking](https://en.wikipedia.org/wiki/DNS_hijacking), etc.
9
+ *
10
+ * A `verifiedFetch` function is exported to get up and running quickly, and a `createVerifiedFetch` function is also available that allows customizing the underlying [Helia](https://helia.io/) node for complete control over how content is retrieved.
11
+ *
12
+ * Browser-cache-friendly [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects are returned which should be instantly familiar to web developers.
9
13
  *
10
14
  * You may use any supported resource argument to fetch content:
11
15
  *
12
- * - CID instance
16
+ * - [CID](https://multiformats.github.io/js-multiformats/classes/cid.CID.html) instance
13
17
  * - IPFS URL
14
18
  * - IPNS URL
15
19
  *
16
- * @example
20
+ * @example Getting started
17
21
  *
18
22
  * ```typescript
19
- * import { createVerifiedFetch } from '@helia/verified-fetch'
23
+ * import { verifiedFetch } from '@helia/verified-fetch'
20
24
  *
21
- * const fetch = await createVerifiedFetch({
22
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
23
- *})
24
- *
25
- * const resp = await fetch('ipfs://bafy...')
25
+ * const resp = await verifiedFetch('ipfs://bafy...')
26
26
  *
27
27
  * const json = await resp.json()
28
28
  *```
29
29
  *
30
- *
31
30
  * @example Using a CID instance to fetch JSON
32
31
  *
33
32
  * ```typescript
34
- * import { createVerifiedFetch } from '@helia/verified-fetch'
33
+ * import { verifiedFetch } from '@helia/verified-fetch'
35
34
  * import { CID } from 'multiformats/cid'
36
35
  *
37
- * const fetch = await createVerifiedFetch({
38
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
39
- * })
40
- *
41
36
  * const cid = CID.parse('bafyFoo') // some image file
42
- * const response = await fetch(cid)
37
+ * const response = await verifiedFetch(cid)
43
38
  * const json = await response.json()
44
39
  * ```
45
40
  *
46
41
  * @example Using IPFS protocol to fetch an image
47
42
  *
48
43
  * ```typescript
49
- * import { createVerifiedFetch } from '@helia/verified-fetch'
44
+ * import { verifiedFetch } from '@helia/verified-fetch'
50
45
  *
51
- * const fetch = await createVerifiedFetch({
52
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
53
- * })
54
- * const response = await fetch('ipfs://bafyFoo') // CID for some image file
46
+ * const response = await verifiedFetch('ipfs://bafyFoo') // CID for some image file
55
47
  * const blob = await response.blob()
56
48
  * const image = document.createElement('img')
57
49
  * image.src = URL.createObjectURL(blob)
@@ -61,22 +53,42 @@
61
53
  * @example Using IPNS protocol to stream a big file
62
54
  *
63
55
  * ```typescript
56
+ * import { verifiedFetch } from '@helia/verified-fetch'
57
+ *
58
+ * const response = await verifiedFetch('ipns://mydomain.com/path/to/very-long-file.log')
59
+ * const bigFileStreamReader = await response.body.getReader()
60
+ * ```
61
+ *
62
+ * ## Configuration
63
+ *
64
+ * ### Custom HTTP gateways and routers
65
+ *
66
+ * Out of the box `@helia/verified-fetch` uses a default set of [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/) for fetching blocks and [HTTP delegated routers](https://specs.ipfs.tech/routing/http-routing-v1/) for performing routing tasks - looking up peers, resolving/publishing [IPNS](https://docs.ipfs.tech/concepts/ipns/) names, etc.
67
+ *
68
+ * It's possible to override these by passing `gateways` and `routers` keys to the `createVerifiedFetch` function:
69
+ *
70
+ * @example Configuring gateways and routers
71
+ *
72
+ * ```typescript
64
73
  * import { createVerifiedFetch } from '@helia/verified-fetch'
65
74
  *
66
75
  * const fetch = await createVerifiedFetch({
67
- * gateways: ['https://mygateway.example.net', 'https://trustless-gateway.link']
76
+ * gateways: ['https://trustless-gateway.link'],
77
+ * routers: ['http://delegated-ipfs.dev']
68
78
  * })
69
- * const response = await fetch('ipns://mydomain.com/path/to/very-long-file.log')
70
- * const bigFileStreamReader = await response.body.getReader()
71
- * ```
72
79
  *
73
- * ### Configuration
80
+ * const resp = await fetch('ipfs://bafy...')
81
+ *
82
+ * const json = await resp.json()
83
+ *```
84
+ *
85
+ * ### Usage with customized Helia
74
86
  *
75
- * #### Usage with customized Helia
87
+ * For full control of how `@helia/verified-fetch` fetches content from the distributed web you can pass a preconfigured Helia node to `createVerifiedFetch`.
76
88
  *
77
- * You can see variations of Helia and js-libp2p configuration options at https://helia.io/interfaces/helia.index.HeliaInit.html.
89
+ * The [helia](https://www.npmjs.com/package/helia) module is configured with a libp2p node that is suited for decentralized applications, alternatively [@helia/http](https://www.npmjs.com/package/@helia/http) is available which uses HTTP gateways for all network operations.
78
90
  *
79
- * The `@helia/http` module is currently in-progress, but the init options should be a subset of the `helia` module's init options. See https://github.com/ipfs/helia/issues/289 for more information.
91
+ * You can see variations of Helia and js-libp2p configuration options at https://helia.io/interfaces/helia.index.HeliaInit.html.
80
92
  *
81
93
  * ```typescript
82
94
  * import { trustlessGateway } from '@helia/block-brokers'
@@ -100,28 +112,54 @@
100
112
  * const json = await resp.json()
101
113
  * ```
102
114
  *
103
- * ### Comparison to fetch
115
+ * ### Custom content-type parsing
116
+ *
117
+ * By default, `@helia/verified-fetch` sets the `Content-Type` header as `application/octet-stream` - this is because the `.json()`, `.text()`, `.blob()`, and `.arrayBuffer()` methods will usually work as expected without a detailed content type.
118
+ *
119
+ * If you require an accurate content-type you can provide a `contentTypeParser` function as an option to `createVerifiedFetch` to handle parsing the content type.
104
120
  *
105
- * First, this library will require instantiation in order to configure the gateways and delegated routers, or potentially a custom Helia instance. Secondly, once your verified-fetch method is created, it will act as similar to the `fetch()` API as possible.
121
+ * The function you provide will be called with the first chunk of bytes from the file and should return a string or a promise of a string.
122
+ *
123
+ * @example Customizing content-type parsing
124
+ *
125
+ * ```typescript
126
+ * import { createVerifiedFetch } from '@helia/verified-fetch'
127
+ * import { fileTypeFromBuffer } from '@sgtpooki/file-type'
128
+ *
129
+ * const fetch = await createVerifiedFetch({
130
+ * gateways: ['https://trustless-gateway.link'],
131
+ * routers: ['http://delegated-ipfs.dev']
132
+ * }, {
133
+ * contentTypeParser: async (bytes) => {
134
+ * // call to some magic-byte recognition library like magic-bytes, file-type, or your own custom byte recognition
135
+ * const result = await fileTypeFromBuffer(bytes)
136
+ * return result?.mime
137
+ * }
138
+ * })
139
+ * ```
140
+ *
141
+ * ## Comparison to fetch
142
+ *
143
+ * This module attempts to act as similarly to the `fetch()` API as possible.
106
144
  *
107
145
  * [The `fetch()` API](https://developer.mozilla.org/en-US/docs/Web/API/fetch) takes two parameters:
108
146
  *
109
147
  * 1. A [resource](https://developer.mozilla.org/en-US/docs/Web/API/fetch#resource)
110
148
  * 2. An [options object](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options)
111
149
  *
112
- * #### Resource argument
150
+ * ### Resource argument
113
151
  *
114
- * This library intends to support the following methods of fetching web3 content from IPFS:
152
+ * This library supports the following methods of fetching web3 content from IPFS:
115
153
  *
116
154
  * 1. IPFS protocol: `ipfs://<cidv0>` & `ipfs://<cidv0>`
117
155
  * 2. IPNS protocol: `ipns://<peerId>` & `ipns://<publicKey>` & `ipns://<hostUri_Supporting_DnsLink_TxtRecords>`
118
156
  * 3. CID instances: An actual CID instance `CID.parse('bafy...')`
119
157
  *
120
- * As well as support for pathing & params for item 1&2 above according to [IPFS - Path Gateway Specification](https://specs.ipfs.tech/http-gateways/path-gateway) & [IPFS - Trustless Gateway Specification](https://specs.ipfs.tech/http-gateways/trustless-gateway/). Further refinement of those specifications specifically for web-based scenarios can be found in the [Web Pathing Specification IPIP](https://github.com/ipfs/specs/pull/453).
158
+ * As well as support for pathing & params for item 1 & 2 above according to [IPFS - Path Gateway Specification](https://specs.ipfs.tech/http-gateways/path-gateway) & [IPFS - Trustless Gateway Specification](https://specs.ipfs.tech/http-gateways/trustless-gateway/). Further refinement of those specifications specifically for web-based scenarios can be found in the [Web Pathing Specification IPIP](https://github.com/ipfs/specs/pull/453).
121
159
  *
122
- * If you pass a CID instance, we assume you want the content for that specific CID only, and do not support pathing or params for that CID.
160
+ * If you pass a CID instance, it assumes you want the content for that specific CID only, and does not support pathing or params for that CID.
123
161
  *
124
- * #### Options argument
162
+ * ### Options argument
125
163
  *
126
164
  * This library does not plan to support the exact Fetch API options object, as some of the arguments don't make sense. Instead, it will only support options necessary to meet [IPFS specs](https://specs.ipfs.tech/) related to specifying the resultant shape of desired content.
127
165
  *
@@ -146,7 +184,6 @@
146
184
  * 5. `body` - An object that specifies the body of the request. Best effort to adhere to the [Fetch API body](https://developer.mozilla.org/en-US/docs/Web/API/fetch#body) parameter.
147
185
  * 6. `cache` - Will basically act as `force-cache` for the request. Best effort to adhere to the [Fetch API cache](https://developer.mozilla.org/en-US/docs/Web/API/fetch#cache) parameter.
148
186
  *
149
- *
150
187
  * Non-Fetch API options that will be supported:
151
188
  *
152
189
  * 1. `onProgress` - Similar to Helia `onProgress` options, this will be a function that will be called with a progress event. Supported progress events are:
@@ -167,7 +204,7 @@
167
204
  * 4. [IPIP-0328: JSON and CBOR Response Formats on HTTP Gateways](https://specs.ipfs.tech/ipips/ipip-0328/)
168
205
  * 5. [IPIP-0288: TAR Response Format on HTTP Gateways](https://specs.ipfs.tech/ipips/ipip-0288/)
169
206
  *
170
- * #### Response types
207
+ * ### Response types
171
208
  *
172
209
  * This library's purpose is to return reasonably representable content from IPFS. In other words, fetching content is intended for leaf-node content -- such as images/videos/audio & other assets, or other IPLD content (with link) -- that can be represented by https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods. The content type you receive back will depend upon the CID you request as well as the `Accept` header value you provide.
173
210
  *
@@ -175,7 +212,7 @@
175
212
  *
176
213
  * If your content doesn't have a mime-type or an [IPFS spec](https://specs.ipfs.tech), this library will not support it, but you can use the [`helia`](https://github.com/ipfs/helia) library directly for those use cases. See [Unsupported response types](#unsupported-response-types) for more information.
177
214
  *
178
- * ##### Handling response types
215
+ * #### Handling response types
179
216
  *
180
217
  * For handling responses we want to follow conventions/abstractions from Fetch API where possible:
181
218
  *
@@ -184,12 +221,12 @@
184
221
  * - For plain text in utf-8, you would call `.text()`
185
222
  * - For streaming response data, use something like `response.body.getReader()` to get a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#consuming_a_fetch_as_a_stream).
186
223
  *
187
- * ##### Unsupported response types
224
+ * #### Unsupported response types
188
225
  *
189
226
  * * Returning IPLD nodes or DAGs as JS objects is not supported, as there is no currently well-defined structure for representing this data in an [HTTP Response](https://developer.mozilla.org/en-US/docs/Web/API/Response). Instead, users should request `aplication/vnd.ipld.car` or use the [`helia`](https://github.com/ipfs/helia) library directly for this use case.
190
227
  * * Others? Open an issue or PR!
191
228
  *
192
- * #### Response headers
229
+ * ### Response headers
193
230
  *
194
231
  * This library will set the [HTTP Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) headers to the appropriate values for the content type according to the appropriate [IPFS Specifications](https://specs.ipfs.tech/).
195
232
  *
@@ -199,13 +236,13 @@
199
236
  * * https://specs.ipfs.tech/http-gateways/trustless-gateway/#response-headers
200
237
  * * https://specs.ipfs.tech/http-gateways/subdomain-gateway/#response-headers
201
238
  *
202
- * #### Possible Scenarios that could cause confusion
239
+ * ### Possible Scenarios that could cause confusion
203
240
  *
204
- * ##### Attempting to fetch the CID for content that does not make sense
241
+ * #### Attempting to fetch the CID for content that does not make sense
205
242
  *
206
243
  * If you request `bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze`, which points to the root of the en.wikipedia.org mirror, a response object does not make sense.
207
244
  *
208
- * #### Errors
245
+ * ### Errors
209
246
  *
210
247
  * Known Errors that can be thrown:
211
248
  *
@@ -221,7 +258,8 @@ import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js';
221
258
  /**
222
259
  * Create and return a Helia node
223
260
  */
224
- export async function createVerifiedFetch(init) {
261
+ export async function createVerifiedFetch(init, options) {
262
+ const contentTypeParser = options?.contentTypeParser;
225
263
  if (!isHelia(init)) {
226
264
  init = await createHeliaHTTP({
227
265
  blockBrokers: [
@@ -232,7 +270,7 @@ export async function createVerifiedFetch(init) {
232
270
  routers: (init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl))
233
271
  });
234
272
  }
235
- const verifiedFetchInstance = new VerifiedFetchClass({ helia: init });
273
+ const verifiedFetchInstance = new VerifiedFetchClass({ helia: init }, { contentTypeParser });
236
274
  async function verifiedFetch(resource, options) {
237
275
  return verifiedFetchInstance.fetch(resource, options);
238
276
  }
@@ -240,6 +278,7 @@ export async function createVerifiedFetch(init) {
240
278
  verifiedFetch.start = verifiedFetchInstance.start.bind(verifiedFetchInstance);
241
279
  return verifiedFetch;
242
280
  }
281
+ export { verifiedFetch } from './singleton.js';
243
282
  function isHelia(obj) {
244
283
  // test for the presence of known Helia properties, return a boolean value
245
284
  return obj?.blockstore != null &&
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuNG;AAEH,OAAO,EAAE,gBAAgB,EAAE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AAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAA;IAC5F,KAAK,UAAU,aAAa,CAAE,QAAkB,EAAE,OAA2B;QAC3E,OAAO,qBAAqB,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC;IACD,aAAa,CAAC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IAC3E,aAAa,CAAC,KAAK,GAAG,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;IAE7E,OAAO,aAAa,CAAA;AACtB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,SAAS,OAAO,CAAE,GAAQ;IACxB,0EAA0E;IAC1E,OAAO,GAAG,EAAE,UAAU,IAAI,IAAI;QAC5B,GAAG,EAAE,SAAS,IAAI,IAAI;QACtB,GAAG,EAAE,EAAE,IAAI,IAAI;QACf,GAAG,EAAE,IAAI,IAAI,IAAI;QACjB,GAAG,EAAE,KAAK,IAAI,IAAI,CAAA;AACtB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { VerifiedFetch } from './index.js';
2
+ export declare const verifiedFetch: VerifiedFetch;
3
+ //# sourceMappingURL=singleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../src/singleton.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,aAAa,EAAqB,MAAM,YAAY,CAAA;AAI5E,eAAO,MAAM,aAAa,EAAE,aAM3B,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { createVerifiedFetch } from './index.js';
2
+ let impl;
3
+ export const verifiedFetch = async function verifiedFetch(resource, options) {
4
+ if (impl == null) {
5
+ impl = await createVerifiedFetch();
6
+ }
7
+ return impl(resource, options);
8
+ };
9
+ verifiedFetch.start = async function () {
10
+ await impl?.start();
11
+ };
12
+ verifiedFetch.stop = async function () {
13
+ await impl?.stop();
14
+ };
15
+ //# sourceMappingURL=singleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.js","sourceRoot":"","sources":["../../src/singleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGhD,IAAI,IAA+B,CAAA;AAEnC,MAAM,CAAC,MAAM,aAAa,GAAkB,KAAK,UAAU,aAAa,CAAE,QAAkB,EAAE,OAA2B;IACvH,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACjB,IAAI,GAAG,MAAM,mBAAmB,EAAE,CAAA;IACpC,CAAC;IAED,OAAO,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAChC,CAAC,CAAA;AAED,aAAa,CAAC,KAAK,GAAG,KAAK;IACzB,MAAM,IAAI,EAAE,KAAK,EAAE,CAAA;AACrB,CAAC,CAAA;AAED,aAAa,CAAC,IAAI,GAAG,KAAK;IACxB,MAAM,IAAI,EAAE,IAAI,EAAE,CAAA;AACpB,CAAC,CAAA"}