@helia/verified-fetch 2.1.3 → 2.2.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.
@@ -3,11 +3,13 @@
3
3
  *
4
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
- * 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. By default, CIDs are retrieved over HTTP from [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
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
+ *
8
+ * By default, providers for CIDs are found with delegated routers and retrieved over HTTP from [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/), and WebTransport and WebRTC providers if available.
7
9
  *
8
10
  * 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
11
  *
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.
12
+ * 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://ipfs.github.io/helia/) node for complete control over how content is retrieved.
11
13
  *
12
14
  * 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.
13
15
  *
@@ -90,7 +92,7 @@
90
92
  *
91
93
  * 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.
92
94
  *
93
- * You can see variations of Helia and js-libp2p configuration options at <https://helia.io/interfaces/helia.index.HeliaInit.html>.
95
+ * You can see variations of Helia and js-libp2p configuration options at <https://ipfs.github.io/helia/interfaces/helia.HeliaInit.html>.
94
96
  *
95
97
  * ```typescript
96
98
  * import { trustlessGateway } from '@helia/block-brokers'
@@ -593,8 +595,10 @@
593
595
  * 3. `TypeError` - If the options argument is passed and is malformed.
594
596
  * 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal. Note that this is a `AbortError` from `@libp2p/interface` and not the standard `AbortError` from the Fetch API.
595
597
  */
598
+ import { type ResolveDNSLinkProgressEvents } from '@helia/ipns';
599
+ import { type ServiceMap } from '@libp2p/interface';
600
+ import { type Libp2pOptions } from 'libp2p';
596
601
  import type { GetBlockProgressEvents, Helia } from '@helia/interface';
597
- import type { ResolveDNSLinkProgressEvents } from '@helia/ipns';
598
602
  import type { DNSResolvers } from '@multiformats/dns';
599
603
  import type { DNSResolver } from '@multiformats/dns/resolvers';
600
604
  import type { ExporterProgressEvents } from 'ipfs-unixfs-exporter';
@@ -660,6 +664,15 @@ export interface CreateVerifiedFetchInit {
660
664
  * @default false
661
665
  */
662
666
  allowInsecure?: boolean;
667
+ /**
668
+ * We will instantiate a libp2p node for you, but if you want to override the libp2p configuration,
669
+ * you can pass it here.
670
+ *
671
+ * **WARNING**: We use Object.assign to merge the default libp2p configuration from Helia with the one you pass here,
672
+ * which results in a shallow merge. If you need a deep merge, you should do it yourself before passing the
673
+ * configuration here.
674
+ */
675
+ libp2pConfig?: Partial<Libp2pOptions<ServiceMap>>;
663
676
  }
664
677
  export interface CreateVerifiedFetchOptions {
665
678
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;OAaG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,IAAI,CAAC,EAAE,KAAK,GAAG,uBAAuB,EAAE,OAAO,CAAC,EAAE,0BAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CA+C/I;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
package/dist/src/index.js CHANGED
@@ -3,11 +3,13 @@
3
3
  *
4
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
- * 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. By default, CIDs are retrieved over HTTP from [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
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
+ *
8
+ * By default, providers for CIDs are found with delegated routers and retrieved over HTTP from [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/), and WebTransport and WebRTC providers if available.
7
9
  *
8
10
  * 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
11
  *
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.
12
+ * 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://ipfs.github.io/helia/) node for complete control over how content is retrieved.
11
13
  *
12
14
  * 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.
13
15
  *
@@ -90,7 +92,7 @@
90
92
  *
91
93
  * 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.
92
94
  *
93
- * You can see variations of Helia and js-libp2p configuration options at <https://helia.io/interfaces/helia.index.HeliaInit.html>.
95
+ * You can see variations of Helia and js-libp2p configuration options at <https://ipfs.github.io/helia/interfaces/helia.HeliaInit.html>.
94
96
  *
95
97
  * ```typescript
96
98
  * import { trustlessGateway } from '@helia/block-brokers'
@@ -593,38 +595,59 @@
593
595
  * 3. `TypeError` - If the options argument is passed and is malformed.
594
596
  * 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal. Note that this is a `AbortError` from `@libp2p/interface` and not the standard `AbortError` from the Fetch API.
595
597
  */
596
- import { trustlessGateway } from '@helia/block-brokers';
597
- import { createHeliaHTTP } from '@helia/http';
598
- import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers';
598
+ import { bitswap, trustlessGateway } from '@helia/block-brokers';
599
+ import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
600
+ import {} from '@helia/ipns';
601
+ import { httpGatewayRouting, libp2pRouting } from '@helia/routers';
602
+ import {} from '@libp2p/interface';
599
603
  import { dns } from '@multiformats/dns';
604
+ import { createHelia } from 'helia';
605
+ import { createLibp2p } from 'libp2p';
606
+ import { getLibp2pConfig } from './utils/libp2p-defaults.js';
600
607
  import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js';
601
608
  /**
602
609
  * Create and return a Helia node
603
610
  */
604
611
  export async function createVerifiedFetch(init, options) {
612
+ let libp2p;
605
613
  if (!isHelia(init)) {
606
- init = await createHeliaHTTP({
607
- blockBrokers: [
608
- trustlessGateway({
609
- allowInsecure: init?.allowInsecure,
610
- allowLocal: init?.allowLocal
611
- })
612
- ],
613
- routers: [
614
- ...(init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl)),
615
- httpGatewayRouting({
616
- gateways: init?.gateways ?? ['https://trustless-gateway.link']
617
- })
618
- ],
619
- dns: createDns(init?.dnsResolvers)
614
+ const dns = createDns(init?.dnsResolvers);
615
+ const libp2pConfig = getLibp2pConfig();
616
+ libp2pConfig.dns = dns;
617
+ const delegatedRouters = init?.routers ?? ['https://delegated-ipfs.dev'];
618
+ for (let index = 0; index < delegatedRouters.length; index++) {
619
+ const routerUrl = delegatedRouters[index];
620
+ libp2pConfig.services[`delegatedRouting${index}`] = () => createDelegatedRoutingV1HttpApiClient(routerUrl);
621
+ }
622
+ // merge any passed options from init.libp2pConfig into libp2pConfig if it exists
623
+ if (init?.libp2pConfig != null) {
624
+ Object.assign(libp2pConfig, init.libp2pConfig);
625
+ }
626
+ libp2p = await createLibp2p(libp2pConfig);
627
+ const blockBrokers = [
628
+ bitswap()
629
+ ];
630
+ const routers = [
631
+ libp2pRouting(libp2p)
632
+ ];
633
+ if (init?.gateways == null || init.gateways.length > 0) {
634
+ // if gateways is null, or set to a non-empty array, use trustless gateways.
635
+ blockBrokers.push(trustlessGateway({ allowInsecure: init?.allowInsecure, allowLocal: init?.allowLocal }));
636
+ routers.push(httpGatewayRouting({ gateways: init?.gateways ?? ['https://trustless-gateway.link'] }));
637
+ }
638
+ init = await createHelia({
639
+ libp2p,
640
+ blockBrokers,
641
+ dns,
642
+ routers
620
643
  });
621
644
  }
622
645
  const verifiedFetchInstance = new VerifiedFetchClass({ helia: init }, options);
623
646
  async function verifiedFetch(resource, options) {
624
647
  return verifiedFetchInstance.fetch(resource, options);
625
648
  }
626
- verifiedFetch.stop = verifiedFetchInstance.stop.bind(verifiedFetchInstance);
627
649
  verifiedFetch.start = verifiedFetchInstance.start.bind(verifiedFetchInstance);
650
+ verifiedFetch.stop = verifiedFetchInstance.stop.bind(verifiedFetchInstance);
628
651
  return verifiedFetch;
629
652
  }
630
653
  export { verifiedFetch } from './singleton.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAklBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,aAAa,IAAI,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AA0LzE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAE,IAAsC,EAAE,OAA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,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;AAED,SAAS,SAAS,CAAE,SAAwC;IAC1D,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAM;IACR,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;YACT,SAAS,EAAE;gBACT,GAAG,EAAE,SAAS;aACf;SACF,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Libp2pOptions } from 'libp2p';
2
+ export declare function getLibp2pConfig(): Libp2pOptions & Required<Pick<Libp2pOptions, 'services'>>;
3
+ //# sourceMappingURL=libp2p-defaults.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libp2p-defaults.browser.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAI3C,wBAAgB,eAAe,IAAK,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAmB5F"}
@@ -0,0 +1,21 @@
1
+ import { webRTCDirect } from '@libp2p/webrtc';
2
+ import { webSockets } from '@libp2p/websockets';
3
+ import { libp2pDefaults } from 'helia';
4
+ export function getLibp2pConfig() {
5
+ const libp2pDefaultOptions = libp2pDefaults();
6
+ libp2pDefaultOptions.start = false;
7
+ libp2pDefaultOptions.addresses = { listen: [] };
8
+ libp2pDefaultOptions.transports = [webRTCDirect(), webSockets()];
9
+ const services = {
10
+ dcutr: libp2pDefaultOptions.services.dcutr,
11
+ identify: libp2pDefaultOptions.services.identify,
12
+ keychain: libp2pDefaultOptions.services.keychain,
13
+ ping: libp2pDefaultOptions.services.ping
14
+ };
15
+ return {
16
+ ...libp2pDefaultOptions,
17
+ start: false,
18
+ services
19
+ };
20
+ }
21
+ //# sourceMappingURL=libp2p-defaults.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libp2p-defaults.browser.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAA8B,MAAM,OAAO,CAAA;AAMlE,MAAM,UAAU,eAAe;IAC7B,MAAM,oBAAoB,GAAG,cAAc,EAAE,CAAA;IAE7C,oBAAoB,CAAC,KAAK,GAAG,KAAK,CAAA;IAClC,oBAAoB,CAAC,SAAS,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;IAC/C,oBAAoB,CAAC,UAAU,GAAG,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IAEhE,MAAM,QAAQ,GAAkC;QAC9C,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,KAAK;QAC1C,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,IAAI,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI;KACzC,CAAA;IAED,OAAO;QACL,GAAG,oBAAoB;QACvB,KAAK,EAAE,KAAK;QACZ,QAAQ;KACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Libp2pOptions } from 'libp2p';
2
+ export declare function getLibp2pConfig(): Libp2pOptions & Required<Pick<Libp2pOptions, 'services'>>;
3
+ //# sourceMappingURL=libp2p-defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libp2p-defaults.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAI3C,wBAAgB,eAAe,IAAK,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CA4B5F"}
@@ -0,0 +1,31 @@
1
+ import { kadDHT } from '@libp2p/kad-dht';
2
+ import { libp2pDefaults } from 'helia';
3
+ import { ipnsSelector } from 'ipns/selector';
4
+ import { ipnsValidator } from 'ipns/validator';
5
+ export function getLibp2pConfig() {
6
+ const libp2pDefaultOptions = libp2pDefaults();
7
+ libp2pDefaultOptions.start = false;
8
+ const services = {
9
+ autoNAT: libp2pDefaultOptions.services.autoNAT,
10
+ dcutr: libp2pDefaultOptions.services.dcutr,
11
+ dht: kadDHT({
12
+ clientMode: true,
13
+ validators: {
14
+ ipns: ipnsValidator
15
+ },
16
+ selectors: {
17
+ ipns: ipnsSelector
18
+ }
19
+ }),
20
+ identify: libp2pDefaultOptions.services.identify,
21
+ keychain: libp2pDefaultOptions.services.keychain,
22
+ ping: libp2pDefaultOptions.services.ping,
23
+ upnp: libp2pDefaultOptions.services.upnp
24
+ };
25
+ return {
26
+ ...libp2pDefaultOptions,
27
+ start: false,
28
+ services
29
+ };
30
+ }
31
+ //# sourceMappingURL=libp2p-defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libp2p-defaults.js","sourceRoot":"","sources":["../../../src/utils/libp2p-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,cAAc,EAA8B,MAAM,OAAO,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAM9C,MAAM,UAAU,eAAe;IAC7B,MAAM,oBAAoB,GAAG,cAAc,EAAE,CAAA;IAE7C,oBAAoB,CAAC,KAAK,GAAG,KAAK,CAAA;IAElC,MAAM,QAAQ,GAAkC;QAC9C,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,OAAO;QAC9C,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC,KAAK;QAC1C,GAAG,EAAE,MAAM,CAAC;YACV,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE;gBACV,IAAI,EAAE,aAAa;aACpB;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,YAAY;aACnB;SACF,CAAC;QACF,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,CAAC,QAAQ;QAChD,IAAI,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI;QACxC,IAAI,EAAE,oBAAoB,CAAC,QAAQ,CAAC,IAAI;KACzC,CAAA;IAED,OAAO;QACL,GAAG,oBAAoB;QACvB,KAAK,EAAE,KAAK;QACZ,QAAQ;KACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { DelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client';
2
+ import type { ServiceMap } from '@libp2p/interface';
3
+ type DelegatedRoutingServices = Record<`delegatedRouting${number}`, ((components?: unknown) => DelegatedRoutingV1HttpApiClient)>;
4
+ export type ServiceFactoryMap<T extends ServiceMap = ServiceMap> = {
5
+ [Property in keyof T]: (components: any & T) => T[Property];
6
+ } & DelegatedRoutingServices;
7
+ export {};
8
+ //# sourceMappingURL=libp2p-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libp2p-types.d.ts","sourceRoot":"","sources":["../../../src/utils/libp2p-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAA;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,KAAK,wBAAwB,GAAG,MAAM,CAAC,mBAAmB,MAAM,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,OAAO,KAAK,+BAA+B,CAAC,CAAC,CAAA;AAEhI,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI;KAChE,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;CAC5D,GAAG,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=libp2p-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libp2p-types.js","sourceRoot":"","sources":["../../../src/utils/libp2p-types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/verified-fetch",
3
- "version": "2.1.3",
3
+ "version": "2.2.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",
@@ -144,7 +144,7 @@
144
144
  "dependencies": {
145
145
  "@helia/block-brokers": "^4.0.2",
146
146
  "@helia/car": "^4.0.1",
147
- "@helia/http": "^2.0.2",
147
+ "@helia/delegated-routing-v1-http-api-client": "^4.2.1",
148
148
  "@helia/interface": "^5.1.0",
149
149
  "@helia/ipns": "^8.0.1",
150
150
  "@helia/routers": "^2.2.0",
@@ -155,16 +155,21 @@
155
155
  "@libp2p/interface": "^2.2.1",
156
156
  "@libp2p/kad-dht": "^14.1.3",
157
157
  "@libp2p/peer-id": "^5.0.8",
158
+ "@libp2p/webrtc": "^5.0.16",
159
+ "@libp2p/websockets": "^9.0.11",
158
160
  "@multiformats/dns": "^1.0.6",
159
161
  "cborg": "^4.2.4",
160
162
  "hashlru": "^2.3.0",
163
+ "helia": "^5.1.0",
161
164
  "interface-blockstore": "^5.3.1",
162
165
  "interface-datastore": "^8.3.1",
163
166
  "ipfs-unixfs-exporter": "^13.6.1",
167
+ "ipns": "^10.0.0",
164
168
  "it-map": "^3.1.1",
165
169
  "it-pipe": "^3.0.1",
166
170
  "it-tar": "^6.0.5",
167
171
  "it-to-browser-readablestream": "^2.0.9",
172
+ "libp2p": "^2.2.1",
168
173
  "lru-cache": "^11.0.2",
169
174
  "multiformats": "^13.3.1",
170
175
  "progress-events": "^1.0.1",
@@ -173,6 +178,7 @@
173
178
  "devDependencies": {
174
179
  "@helia/dag-cbor": "^4.0.1",
175
180
  "@helia/dag-json": "^4.0.1",
181
+ "@helia/http": "^2.0.1",
176
182
  "@helia/json": "^4.0.1",
177
183
  "@ipld/car": "^5.3.2",
178
184
  "@libp2p/crypto": "^5.0.7",
@@ -185,7 +191,6 @@
185
191
  "datastore-core": "^10.0.2",
186
192
  "helia": "^5.1.1",
187
193
  "ipfs-unixfs-importer": "^15.3.1",
188
- "ipns": "^10.0.0",
189
194
  "it-all": "^3.0.6",
190
195
  "it-drain": "^3.0.7",
191
196
  "it-last": "^3.0.6",
package/src/index.ts CHANGED
@@ -3,11 +3,13 @@
3
3
  *
4
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
- * 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. By default, CIDs are retrieved over HTTP from [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/).
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
+ *
8
+ * By default, providers for CIDs are found with delegated routers and retrieved over HTTP from [trustless gateways](https://specs.ipfs.tech/http-gateways/trustless-gateway/), and WebTransport and WebRTC providers if available.
7
9
  *
8
10
  * 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
11
  *
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.
12
+ * 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://ipfs.github.io/helia/) node for complete control over how content is retrieved.
11
13
  *
12
14
  * 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.
13
15
  *
@@ -90,7 +92,7 @@
90
92
  *
91
93
  * 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.
92
94
  *
93
- * You can see variations of Helia and js-libp2p configuration options at <https://helia.io/interfaces/helia.index.HeliaInit.html>.
95
+ * You can see variations of Helia and js-libp2p configuration options at <https://ipfs.github.io/helia/interfaces/helia.HeliaInit.html>.
94
96
  *
95
97
  * ```typescript
96
98
  * import { trustlessGateway } from '@helia/block-brokers'
@@ -594,13 +596,17 @@
594
596
  * 4. `AbortError` - If the content request is aborted due to user aborting provided AbortSignal. Note that this is a `AbortError` from `@libp2p/interface` and not the standard `AbortError` from the Fetch API.
595
597
  */
596
598
 
597
- import { trustlessGateway } from '@helia/block-brokers'
598
- import { createHeliaHTTP } from '@helia/http'
599
- import { delegatedHTTPRouting, httpGatewayRouting } from '@helia/routers'
599
+ import { bitswap, trustlessGateway } from '@helia/block-brokers'
600
+ import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
601
+ import { type ResolveDNSLinkProgressEvents } from '@helia/ipns'
602
+ import { httpGatewayRouting, libp2pRouting } from '@helia/routers'
603
+ import { type Libp2p, type ServiceMap } from '@libp2p/interface'
600
604
  import { dns } from '@multiformats/dns'
605
+ import { createHelia } from 'helia'
606
+ import { createLibp2p, type Libp2pOptions } from 'libp2p'
607
+ import { getLibp2pConfig } from './utils/libp2p-defaults.js'
601
608
  import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js'
602
- import type { GetBlockProgressEvents, Helia } from '@helia/interface'
603
- import type { ResolveDNSLinkProgressEvents } from '@helia/ipns'
609
+ import type { GetBlockProgressEvents, Helia, Routing } from '@helia/interface'
604
610
  import type { DNSResolvers, DNS } from '@multiformats/dns'
605
611
  import type { DNSResolver } from '@multiformats/dns/resolvers'
606
612
  import type { ExporterProgressEvents } from 'ipfs-unixfs-exporter'
@@ -675,6 +681,16 @@ export interface CreateVerifiedFetchInit {
675
681
  * @default false
676
682
  */
677
683
  allowInsecure?: boolean
684
+
685
+ /**
686
+ * We will instantiate a libp2p node for you, but if you want to override the libp2p configuration,
687
+ * you can pass it here.
688
+ *
689
+ * **WARNING**: We use Object.assign to merge the default libp2p configuration from Helia with the one you pass here,
690
+ * which results in a shallow merge. If you need a deep merge, you should do it yourself before passing the
691
+ * configuration here.
692
+ */
693
+ libp2pConfig?: Partial<Libp2pOptions<ServiceMap>>
678
694
  }
679
695
 
680
696
  export interface CreateVerifiedFetchOptions {
@@ -788,21 +804,41 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledP
788
804
  * Create and return a Helia node
789
805
  */
790
806
  export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchInit, options?: CreateVerifiedFetchOptions): Promise<VerifiedFetch> {
807
+ let libp2p: Libp2p<any> | undefined
791
808
  if (!isHelia(init)) {
792
- init = await createHeliaHTTP({
793
- blockBrokers: [
794
- trustlessGateway({
795
- allowInsecure: init?.allowInsecure,
796
- allowLocal: init?.allowLocal
797
- })
798
- ],
799
- routers: [
800
- ...(init?.routers ?? ['https://delegated-ipfs.dev']).map((routerUrl) => delegatedHTTPRouting(routerUrl)),
801
- httpGatewayRouting({
802
- gateways: init?.gateways ?? ['https://trustless-gateway.link']
803
- })
804
- ],
805
- dns: createDns(init?.dnsResolvers)
809
+ const dns = createDns(init?.dnsResolvers)
810
+
811
+ const libp2pConfig = getLibp2pConfig()
812
+ libp2pConfig.dns = dns
813
+
814
+ const delegatedRouters = init?.routers ?? ['https://delegated-ipfs.dev']
815
+ for (let index = 0; index < delegatedRouters.length; index++) {
816
+ const routerUrl = delegatedRouters[index]
817
+ libp2pConfig.services[`delegatedRouting${index}`] = () => createDelegatedRoutingV1HttpApiClient(routerUrl)
818
+ }
819
+ // merge any passed options from init.libp2pConfig into libp2pConfig if it exists
820
+ if (init?.libp2pConfig != null) {
821
+ Object.assign(libp2pConfig, init.libp2pConfig)
822
+ }
823
+ libp2p = await createLibp2p(libp2pConfig)
824
+
825
+ const blockBrokers = [
826
+ bitswap()
827
+ ]
828
+ const routers: Array<Partial<Routing>> = [
829
+ libp2pRouting(libp2p)
830
+ ]
831
+ if (init?.gateways == null || init.gateways.length > 0) {
832
+ // if gateways is null, or set to a non-empty array, use trustless gateways.
833
+ blockBrokers.push(trustlessGateway({ allowInsecure: init?.allowInsecure, allowLocal: init?.allowLocal }))
834
+ routers.push(httpGatewayRouting({ gateways: init?.gateways ?? ['https://trustless-gateway.link'] }))
835
+ }
836
+
837
+ init = await createHelia({
838
+ libp2p,
839
+ blockBrokers,
840
+ dns,
841
+ routers
806
842
  })
807
843
  }
808
844
 
@@ -810,8 +846,8 @@ export async function createVerifiedFetch (init?: Helia | CreateVerifiedFetchIni
810
846
  async function verifiedFetch (resource: Resource, options?: VerifiedFetchInit): Promise<Response> {
811
847
  return verifiedFetchInstance.fetch(resource, options)
812
848
  }
813
- verifiedFetch.stop = verifiedFetchInstance.stop.bind(verifiedFetchInstance)
814
849
  verifiedFetch.start = verifiedFetchInstance.start.bind(verifiedFetchInstance)
850
+ verifiedFetch.stop = verifiedFetchInstance.stop.bind(verifiedFetchInstance)
815
851
 
816
852
  return verifiedFetch
817
853
  }
@@ -0,0 +1,28 @@
1
+ import { webRTCDirect } from '@libp2p/webrtc'
2
+ import { webSockets } from '@libp2p/websockets'
3
+ import { libp2pDefaults, type DefaultLibp2pServices } from 'helia'
4
+ import type { ServiceFactoryMap } from './libp2p-types'
5
+ import type { Libp2pOptions } from 'libp2p'
6
+
7
+ type ServiceMap = Pick<DefaultLibp2pServices, 'dcutr' | 'identify' | 'keychain' | 'ping'>
8
+
9
+ export function getLibp2pConfig (): Libp2pOptions & Required<Pick<Libp2pOptions, 'services'>> {
10
+ const libp2pDefaultOptions = libp2pDefaults()
11
+
12
+ libp2pDefaultOptions.start = false
13
+ libp2pDefaultOptions.addresses = { listen: [] }
14
+ libp2pDefaultOptions.transports = [webRTCDirect(), webSockets()]
15
+
16
+ const services: ServiceFactoryMap<ServiceMap> = {
17
+ dcutr: libp2pDefaultOptions.services.dcutr,
18
+ identify: libp2pDefaultOptions.services.identify,
19
+ keychain: libp2pDefaultOptions.services.keychain,
20
+ ping: libp2pDefaultOptions.services.ping
21
+ }
22
+
23
+ return {
24
+ ...libp2pDefaultOptions,
25
+ start: false,
26
+ services
27
+ }
28
+ }
@@ -0,0 +1,38 @@
1
+ import { kadDHT } from '@libp2p/kad-dht'
2
+ import { libp2pDefaults, type DefaultLibp2pServices } from 'helia'
3
+ import { ipnsSelector } from 'ipns/selector'
4
+ import { ipnsValidator } from 'ipns/validator'
5
+ import type { ServiceFactoryMap } from './libp2p-types'
6
+ import type { Libp2pOptions } from 'libp2p'
7
+
8
+ type ServiceMap = Pick<DefaultLibp2pServices, 'autoNAT' | 'dcutr' | 'dht' | 'identify' | 'keychain' | 'ping' | 'upnp'>
9
+
10
+ export function getLibp2pConfig (): Libp2pOptions & Required<Pick<Libp2pOptions, 'services'>> {
11
+ const libp2pDefaultOptions = libp2pDefaults()
12
+
13
+ libp2pDefaultOptions.start = false
14
+
15
+ const services: ServiceFactoryMap<ServiceMap> = {
16
+ autoNAT: libp2pDefaultOptions.services.autoNAT,
17
+ dcutr: libp2pDefaultOptions.services.dcutr,
18
+ dht: kadDHT({
19
+ clientMode: true,
20
+ validators: {
21
+ ipns: ipnsValidator
22
+ },
23
+ selectors: {
24
+ ipns: ipnsSelector
25
+ }
26
+ }),
27
+ identify: libp2pDefaultOptions.services.identify,
28
+ keychain: libp2pDefaultOptions.services.keychain,
29
+ ping: libp2pDefaultOptions.services.ping,
30
+ upnp: libp2pDefaultOptions.services.upnp
31
+ }
32
+
33
+ return {
34
+ ...libp2pDefaultOptions,
35
+ start: false,
36
+ services
37
+ }
38
+ }
@@ -0,0 +1,8 @@
1
+ import type { DelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
2
+ import type { ServiceMap } from '@libp2p/interface'
3
+
4
+ type DelegatedRoutingServices = Record<`delegatedRouting${number}`, ((components?: unknown) => DelegatedRoutingV1HttpApiClient)>
5
+
6
+ export type ServiceFactoryMap<T extends ServiceMap = ServiceMap> = {
7
+ [Property in keyof T]: (components: any & T) => T[Property]
8
+ } & DelegatedRoutingServices