@helia/verified-fetch 2.2.1 → 2.3.0
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.
- package/README.md +27 -1
- package/dist/index.min.js +36 -33
- package/dist/src/index.d.ts +32 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +28 -2
- package/dist/src/index.js.map +1 -1
- package/dist/typedoc-urls.json +25 -25
- package/package.json +3 -2
- package/src/index.ts +36 -4
package/dist/src/index.d.ts
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
*
|
|
6
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
|
-
* By default, providers for CIDs are found
|
|
8
|
+
* By default, providers for CIDs are found using [delegated routing endpoints](https://docs.ipfs.tech/concepts/public-utilities/#delegated-routing).
|
|
9
|
+
*
|
|
10
|
+
* Data is retrieved using the following strategies:
|
|
11
|
+
* - Directly from providers, using [Bitswap](https://docs.ipfs.tech/concepts/bitswap/) over WebSockets and WebRTC if available.
|
|
12
|
+
* - Directly from providers exposing a [trustless gateway](https://specs.ipfs.tech/http-gateways/trustless-gateway/) over HTTPS.
|
|
13
|
+
* - As a fallback, if no providers reachable from a browser are found, data is retrieved using recursive gateways, e.g. `trustless-gateway.link` which can be configured.
|
|
9
14
|
*
|
|
10
15
|
* 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.
|
|
11
16
|
*
|
|
@@ -189,6 +194,25 @@
|
|
|
189
194
|
* }
|
|
190
195
|
* })
|
|
191
196
|
* ```
|
|
197
|
+
* ### Custom Hashers
|
|
198
|
+
*
|
|
199
|
+
* By default, `@helia/verified-fetch` supports `sha256`, `sha512`, and `identity` hashers.
|
|
200
|
+
*
|
|
201
|
+
* If you need to use a different hasher, you can provide a [custom `hasher` function](https://multiformats.github.io/js-multiformats/interfaces/hashes_interface.MultihashHasher.html) as an option to `createVerifiedFetch`.
|
|
202
|
+
*
|
|
203
|
+
* @example Passing a custom hashing function
|
|
204
|
+
*
|
|
205
|
+
* ```typescript
|
|
206
|
+
* import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
207
|
+
* import { blake2b256 } from '@multiformats/blake2/blake2b'
|
|
208
|
+
*
|
|
209
|
+
* const verifiedFetch = await createVerifiedFetch({
|
|
210
|
+
* gateways: ['https://ipfs.io'],
|
|
211
|
+
* hashers: [blake2b256]
|
|
212
|
+
* })
|
|
213
|
+
*
|
|
214
|
+
* const resp = await verifiedFetch('ipfs://cid-using-blake2b256')
|
|
215
|
+
* ```
|
|
192
216
|
*
|
|
193
217
|
* ### IPLD codec handling
|
|
194
218
|
*
|
|
@@ -597,6 +621,7 @@
|
|
|
597
621
|
*/
|
|
598
622
|
import { type ResolveDNSLinkProgressEvents } from '@helia/ipns';
|
|
599
623
|
import { type ServiceMap } from '@libp2p/interface';
|
|
624
|
+
import { type HeliaInit } from 'helia';
|
|
600
625
|
import { type Libp2pOptions } from 'libp2p';
|
|
601
626
|
import type { GetBlockProgressEvents, Helia } from '@helia/interface';
|
|
602
627
|
import type { DNSResolvers } from '@multiformats/dns';
|
|
@@ -641,6 +666,12 @@ export interface CreateVerifiedFetchInit {
|
|
|
641
666
|
* @default [dnsJsonOverHttps('https://cloudflare-dns.com/dns-query'),dnsJsonOverHttps('https://dns.google/resolve')]
|
|
642
667
|
*/
|
|
643
668
|
dnsResolvers?: DNSResolver[] | DNSResolvers;
|
|
669
|
+
/**
|
|
670
|
+
* By default sha256, sha512 and identity hashes are supported for
|
|
671
|
+
* retrieval operations. To retrieve blocks by CIDs using other hashes
|
|
672
|
+
* pass appropriate MultihashHashers here.
|
|
673
|
+
*/
|
|
674
|
+
hashers?: HeliaInit['hashers'];
|
|
644
675
|
/**
|
|
645
676
|
* By default we will not connect to any HTTP Gateways providers over local or
|
|
646
677
|
* loopback addresses, this is because they are typically running on remote
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4mBG;AAIH,OAAO,EAAE,KAAK,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAE/D,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEhE,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,QA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BAAuB,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CAiD/I;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
*
|
|
6
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
|
-
* By default, providers for CIDs are found
|
|
8
|
+
* By default, providers for CIDs are found using [delegated routing endpoints](https://docs.ipfs.tech/concepts/public-utilities/#delegated-routing).
|
|
9
|
+
*
|
|
10
|
+
* Data is retrieved using the following strategies:
|
|
11
|
+
* - Directly from providers, using [Bitswap](https://docs.ipfs.tech/concepts/bitswap/) over WebSockets and WebRTC if available.
|
|
12
|
+
* - Directly from providers exposing a [trustless gateway](https://specs.ipfs.tech/http-gateways/trustless-gateway/) over HTTPS.
|
|
13
|
+
* - As a fallback, if no providers reachable from a browser are found, data is retrieved using recursive gateways, e.g. `trustless-gateway.link` which can be configured.
|
|
9
14
|
*
|
|
10
15
|
* 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.
|
|
11
16
|
*
|
|
@@ -189,6 +194,25 @@
|
|
|
189
194
|
* }
|
|
190
195
|
* })
|
|
191
196
|
* ```
|
|
197
|
+
* ### Custom Hashers
|
|
198
|
+
*
|
|
199
|
+
* By default, `@helia/verified-fetch` supports `sha256`, `sha512`, and `identity` hashers.
|
|
200
|
+
*
|
|
201
|
+
* If you need to use a different hasher, you can provide a [custom `hasher` function](https://multiformats.github.io/js-multiformats/interfaces/hashes_interface.MultihashHasher.html) as an option to `createVerifiedFetch`.
|
|
202
|
+
*
|
|
203
|
+
* @example Passing a custom hashing function
|
|
204
|
+
*
|
|
205
|
+
* ```typescript
|
|
206
|
+
* import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
207
|
+
* import { blake2b256 } from '@multiformats/blake2/blake2b'
|
|
208
|
+
*
|
|
209
|
+
* const verifiedFetch = await createVerifiedFetch({
|
|
210
|
+
* gateways: ['https://ipfs.io'],
|
|
211
|
+
* hashers: [blake2b256]
|
|
212
|
+
* })
|
|
213
|
+
*
|
|
214
|
+
* const resp = await verifiedFetch('ipfs://cid-using-blake2b256')
|
|
215
|
+
* ```
|
|
192
216
|
*
|
|
193
217
|
* ### IPLD codec handling
|
|
194
218
|
*
|
|
@@ -639,8 +663,10 @@ export async function createVerifiedFetch(init, options) {
|
|
|
639
663
|
libp2p,
|
|
640
664
|
blockBrokers,
|
|
641
665
|
dns,
|
|
642
|
-
routers
|
|
666
|
+
routers,
|
|
667
|
+
hashers: init?.hashers
|
|
643
668
|
});
|
|
669
|
+
init.logger.forComponent('helia:verified-fetch').trace('created verified-fetch with libp2p config: %j', libp2pConfig);
|
|
644
670
|
}
|
|
645
671
|
const verifiedFetchInstance = new VerifiedFetchClass({ helia: init }, options);
|
|
646
672
|
async function verifiedFetch(resource, options) {
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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}
|
package/dist/typedoc-urls.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
|
-
"CIDDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
3
|
-
".:CIDDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
4
|
-
"CIDDetailError": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
5
|
-
".:CIDDetailError": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
6
|
-
"ContentTypeParser": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
7
|
-
".:ContentTypeParser": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
8
|
-
"CreateVerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
9
|
-
".:CreateVerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
10
|
-
"CreateVerifiedFetchOptions": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
11
|
-
".:CreateVerifiedFetchOptions": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
12
|
-
"ResourceDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
13
|
-
".:ResourceDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
14
|
-
"VerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
15
|
-
".:VerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
16
|
-
"VerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
17
|
-
".:VerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/
|
|
18
|
-
"BubbledProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/
|
|
19
|
-
".:BubbledProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/
|
|
20
|
-
"Resource": "https://ipfs.github.io/helia-verified-fetch/types/
|
|
21
|
-
".:Resource": "https://ipfs.github.io/helia-verified-fetch/types/
|
|
22
|
-
"VerifiedFetchProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/
|
|
23
|
-
".:VerifiedFetchProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/
|
|
24
|
-
"createVerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/functions/
|
|
25
|
-
".:createVerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/functions/
|
|
26
|
-
"verifiedFetch": "https://ipfs.github.io/helia-verified-fetch/functions/
|
|
2
|
+
"CIDDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/CIDDetail.html",
|
|
3
|
+
".:CIDDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/CIDDetail.html",
|
|
4
|
+
"CIDDetailError": "https://ipfs.github.io/helia-verified-fetch/interfaces/CIDDetailError.html",
|
|
5
|
+
".:CIDDetailError": "https://ipfs.github.io/helia-verified-fetch/interfaces/CIDDetailError.html",
|
|
6
|
+
"ContentTypeParser": "https://ipfs.github.io/helia-verified-fetch/interfaces/ContentTypeParser.html",
|
|
7
|
+
".:ContentTypeParser": "https://ipfs.github.io/helia-verified-fetch/interfaces/ContentTypeParser.html",
|
|
8
|
+
"CreateVerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/CreateVerifiedFetchInit.html",
|
|
9
|
+
".:CreateVerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/CreateVerifiedFetchInit.html",
|
|
10
|
+
"CreateVerifiedFetchOptions": "https://ipfs.github.io/helia-verified-fetch/interfaces/CreateVerifiedFetchOptions.html",
|
|
11
|
+
".:CreateVerifiedFetchOptions": "https://ipfs.github.io/helia-verified-fetch/interfaces/CreateVerifiedFetchOptions.html",
|
|
12
|
+
"ResourceDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/ResourceDetail.html",
|
|
13
|
+
".:ResourceDetail": "https://ipfs.github.io/helia-verified-fetch/interfaces/ResourceDetail.html",
|
|
14
|
+
"VerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/interfaces/VerifiedFetch.html",
|
|
15
|
+
".:VerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/interfaces/VerifiedFetch.html",
|
|
16
|
+
"VerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/VerifiedFetchInit.html",
|
|
17
|
+
".:VerifiedFetchInit": "https://ipfs.github.io/helia-verified-fetch/interfaces/VerifiedFetchInit.html",
|
|
18
|
+
"BubbledProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/BubbledProgressEvents.html",
|
|
19
|
+
".:BubbledProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/BubbledProgressEvents.html",
|
|
20
|
+
"Resource": "https://ipfs.github.io/helia-verified-fetch/types/Resource.html",
|
|
21
|
+
".:Resource": "https://ipfs.github.io/helia-verified-fetch/types/Resource.html",
|
|
22
|
+
"VerifiedFetchProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/VerifiedFetchProgressEvents.html",
|
|
23
|
+
".:VerifiedFetchProgressEvents": "https://ipfs.github.io/helia-verified-fetch/types/VerifiedFetchProgressEvents.html",
|
|
24
|
+
"createVerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/functions/createVerifiedFetch.html",
|
|
25
|
+
".:createVerifiedFetch": "https://ipfs.github.io/helia-verified-fetch/functions/createVerifiedFetch.html",
|
|
26
|
+
"verifiedFetch": "https://ipfs.github.io/helia-verified-fetch/functions/verifiedFetch-1.html"
|
|
27
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/verified-fetch",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A fetch-like API for obtaining verified & trustless IPFS content on the web",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia-verified-fetch/tree/main/packages/verified-fetch#readme",
|
|
@@ -132,6 +132,7 @@
|
|
|
132
132
|
"dep-check": "aegir dep-check",
|
|
133
133
|
"doc-check": "aegir doc-check",
|
|
134
134
|
"build": "aegir build",
|
|
135
|
+
"docs": "aegir docs",
|
|
135
136
|
"test": "aegir test",
|
|
136
137
|
"test:chrome": "aegir test -t browser --cov",
|
|
137
138
|
"test:chrome-webworker": "aegir test -t webworker",
|
|
@@ -185,7 +186,7 @@
|
|
|
185
186
|
"@libp2p/logger": "^5.1.4",
|
|
186
187
|
"@sgtpooki/file-type": "^1.0.1",
|
|
187
188
|
"@types/sinon": "^17.0.3",
|
|
188
|
-
"aegir": "^45.0.
|
|
189
|
+
"aegir": "^45.0.8",
|
|
189
190
|
"blockstore-core": "^5.0.2",
|
|
190
191
|
"browser-readablestream-to-it": "^2.0.7",
|
|
191
192
|
"datastore-core": "^10.0.2",
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
*
|
|
6
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
|
-
* By default, providers for CIDs are found
|
|
8
|
+
* By default, providers for CIDs are found using [delegated routing endpoints](https://docs.ipfs.tech/concepts/public-utilities/#delegated-routing).
|
|
9
|
+
*
|
|
10
|
+
* Data is retrieved using the following strategies:
|
|
11
|
+
* - Directly from providers, using [Bitswap](https://docs.ipfs.tech/concepts/bitswap/) over WebSockets and WebRTC if available.
|
|
12
|
+
* - Directly from providers exposing a [trustless gateway](https://specs.ipfs.tech/http-gateways/trustless-gateway/) over HTTPS.
|
|
13
|
+
* - As a fallback, if no providers reachable from a browser are found, data is retrieved using recursive gateways, e.g. `trustless-gateway.link` which can be configured.
|
|
9
14
|
*
|
|
10
15
|
* 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.
|
|
11
16
|
*
|
|
@@ -189,6 +194,25 @@
|
|
|
189
194
|
* }
|
|
190
195
|
* })
|
|
191
196
|
* ```
|
|
197
|
+
* ### Custom Hashers
|
|
198
|
+
*
|
|
199
|
+
* By default, `@helia/verified-fetch` supports `sha256`, `sha512`, and `identity` hashers.
|
|
200
|
+
*
|
|
201
|
+
* If you need to use a different hasher, you can provide a [custom `hasher` function](https://multiformats.github.io/js-multiformats/interfaces/hashes_interface.MultihashHasher.html) as an option to `createVerifiedFetch`.
|
|
202
|
+
*
|
|
203
|
+
* @example Passing a custom hashing function
|
|
204
|
+
*
|
|
205
|
+
* ```typescript
|
|
206
|
+
* import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
207
|
+
* import { blake2b256 } from '@multiformats/blake2/blake2b'
|
|
208
|
+
*
|
|
209
|
+
* const verifiedFetch = await createVerifiedFetch({
|
|
210
|
+
* gateways: ['https://ipfs.io'],
|
|
211
|
+
* hashers: [blake2b256]
|
|
212
|
+
* })
|
|
213
|
+
*
|
|
214
|
+
* const resp = await verifiedFetch('ipfs://cid-using-blake2b256')
|
|
215
|
+
* ```
|
|
192
216
|
*
|
|
193
217
|
* ### IPLD codec handling
|
|
194
218
|
*
|
|
@@ -602,7 +626,7 @@ import { type ResolveDNSLinkProgressEvents } from '@helia/ipns'
|
|
|
602
626
|
import { httpGatewayRouting, libp2pRouting } from '@helia/routers'
|
|
603
627
|
import { type Libp2p, type ServiceMap } from '@libp2p/interface'
|
|
604
628
|
import { dns } from '@multiformats/dns'
|
|
605
|
-
import { createHelia } from 'helia'
|
|
629
|
+
import { createHelia, type HeliaInit } from 'helia'
|
|
606
630
|
import { createLibp2p, type Libp2pOptions } from 'libp2p'
|
|
607
631
|
import { getLibp2pConfig } from './utils/libp2p-defaults.js'
|
|
608
632
|
import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js'
|
|
@@ -612,7 +636,6 @@ import type { DNSResolver } from '@multiformats/dns/resolvers'
|
|
|
612
636
|
import type { ExporterProgressEvents } from 'ipfs-unixfs-exporter'
|
|
613
637
|
import type { CID } from 'multiformats/cid'
|
|
614
638
|
import type { ProgressEvent, ProgressOptions } from 'progress-events'
|
|
615
|
-
|
|
616
639
|
/**
|
|
617
640
|
* The types for the first argument of the `verifiedFetch` function.
|
|
618
641
|
*/
|
|
@@ -657,6 +680,13 @@ export interface CreateVerifiedFetchInit {
|
|
|
657
680
|
*/
|
|
658
681
|
dnsResolvers?: DNSResolver[] | DNSResolvers
|
|
659
682
|
|
|
683
|
+
/**
|
|
684
|
+
* By default sha256, sha512 and identity hashes are supported for
|
|
685
|
+
* retrieval operations. To retrieve blocks by CIDs using other hashes
|
|
686
|
+
* pass appropriate MultihashHashers here.
|
|
687
|
+
*/
|
|
688
|
+
hashers?: HeliaInit['hashers']
|
|
689
|
+
|
|
660
690
|
/**
|
|
661
691
|
* By default we will not connect to any HTTP Gateways providers over local or
|
|
662
692
|
* loopback addresses, this is because they are typically running on remote
|
|
@@ -838,8 +868,10 @@ export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchIni
|
|
|
838
868
|
libp2p,
|
|
839
869
|
blockBrokers,
|
|
840
870
|
dns,
|
|
841
|
-
routers
|
|
871
|
+
routers,
|
|
872
|
+
hashers: init?.hashers
|
|
842
873
|
})
|
|
874
|
+
init.logger.forComponent('helia:verified-fetch').trace('created verified-fetch with libp2p config: %j', libp2pConfig)
|
|
843
875
|
}
|
|
844
876
|
|
|
845
877
|
const verifiedFetchInstance = new VerifiedFetchClass({ helia: init }, options)
|