From dde050c7cb067321153ceee1bbe7ad175d862e1a Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Tue, 20 Feb 2024 13:20:19 +0100 Subject: [PATCH 1/5] feat: add explicit support for subdomain gateways --- .../src/trustless-gateway/broker.ts | 4 +- .../src/trustless-gateway/index.ts | 21 ++++++---- .../trustless-gateway/trustless-gateway.ts | 39 +++++++++++++++---- .../test/trustless-gateway.spec.ts | 15 ++++++- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/packages/block-brokers/src/trustless-gateway/broker.ts b/packages/block-brokers/src/trustless-gateway/broker.ts index 433a690d0..9b851bdfd 100644 --- a/packages/block-brokers/src/trustless-gateway/broker.ts +++ b/packages/block-brokers/src/trustless-gateway/broker.ts @@ -19,8 +19,8 @@ ProgressOptions constructor (components: TrustlessGatewayComponents, init: TrustlessGatewayBlockBrokerInit = {}) { this.log = components.logger.forComponent('helia:trustless-gateway-block-broker') this.gateways = (init.gateways ?? DEFAULT_TRUSTLESS_GATEWAYS) - .map((gatewayOrUrl) => { - return new TrustlessGateway(gatewayOrUrl) + .map((gw) => { + return new TrustlessGateway(gw.url, gw.isSubdomain) }) } diff --git a/packages/block-brokers/src/trustless-gateway/index.ts b/packages/block-brokers/src/trustless-gateway/index.ts index 91dcab15c..80aa8b5d8 100644 --- a/packages/block-brokers/src/trustless-gateway/index.ts +++ b/packages/block-brokers/src/trustless-gateway/index.ts @@ -3,22 +3,27 @@ import type { BlockRetriever } from '@helia/interface/src/blocks.js' import type { ComponentLogger } from '@libp2p/interface' import type { ProgressEvent } from 'progress-events' -export const DEFAULT_TRUSTLESS_GATEWAYS = [ - // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/ - 'https://trustless-gateway.link', +export const DEFAULT_TRUSTLESS_GATEWAYS: TrustlessGatewayUrl[] = [ + // 2024-02-20: IPNS and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ + { url: 'https://trustless-gateway.link', isSubdomain: false }, - // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/ - 'https://cloudflare-ipfs.com', + // 2024-02-20: IPNS and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ + { url: 'https://cloudflare-ipfs.com', isSubdomain: false }, - // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs-public-gateway-checker.on.fleek.co/ - 'https://4everland.io' + // 2024-02-20: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ + { url: 'https://4everland.io', isSubdomain: true }, ] +interface TrustlessGatewayUrl { + url: string | URL + isSubdomain: boolean +} + export type TrustlessGatewayGetBlockProgressEvents = ProgressEvent<'trustless-gateway:get-block:fetch', URL> export interface TrustlessGatewayBlockBrokerInit { - gateways?: Array + gateways?: Array } export interface TrustlessGatewayComponents { diff --git a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts index 352d6ea38..c6a56947f 100644 --- a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts +++ b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts @@ -1,4 +1,5 @@ import type { CID } from 'multiformats/cid' +import { base32 } from 'multiformats/bases/base32' /** * A `TrustlessGateway` keeps track of the number of attempts, errors, and @@ -8,6 +9,12 @@ import type { CID } from 'multiformats/cid' */ export class TrustlessGateway { public readonly url: URL + + /** + * Whether this gateway is a subdomain resolution style gateway + */ + public isSubdomain: boolean + /** * The number of times this gateway has been attempted to be used to fetch a * block. This includes successful, errored, and aborted attempts. By counting @@ -36,24 +43,26 @@ export class TrustlessGateway { */ #successes = 0 - constructor (url: URL | string) { + constructor(url: URL | string, isSubdomain: boolean = false) { this.url = url instanceof URL ? url : new URL(url) + this.isSubdomain = isSubdomain } /** * Fetch a raw block from `this.url` following the specification defined at * https://specs.ipfs.tech/http-gateways/trustless-gateway/ */ - async getRawBlock (cid: CID, signal?: AbortSignal): Promise { - const gwUrl = this.url - gwUrl.pathname = `/ipfs/${cid.toString()}` + async getRawBlock(cid: CID, signal?: AbortSignal): Promise { + const gwUrl = this.getGwUrl(cid) // necessary as not every gateway supports dag-cbor, but every should support // sending raw block as-is gwUrl.search = '?format=raw' if (signal?.aborted === true) { - throw new Error(`Signal to fetch raw block for CID ${cid} from gateway ${this.url} was aborted prior to fetch`) + throw new Error( + `Signal to fetch raw block for CID ${cid} from gateway ${this.url} was aborted prior to fetch`, + ) } try { @@ -61,9 +70,9 @@ export class TrustlessGateway { const res = await fetch(gwUrl.toString(), { signal, headers: { - // also set header, just in case ?format= is filtered out by some - // reverse proxy - Accept: 'application/vnd.ipld.raw' + // also set header, just in case ?format= is filtered out by some + // reverse proxy + Accept: 'application/vnd.ipld.raw', }, cache: 'force-cache' }) @@ -84,6 +93,20 @@ export class TrustlessGateway { } } + /** + * Construct the Gateway URL for a CID + */ + getGwUrl(cid: CID): URL { + const gwUrl = new URL(this.url) + + if (this.isSubdomain) { + gwUrl.hostname = `${cid.toString(base32)}.ipfs.${gwUrl.hostname}` + } else { + gwUrl.pathname = `/ipfs/${cid.toString()}` + } + return gwUrl + } + /** * Encapsulate the logic for determining whether a gateway is considered * reliable, for prioritization. This is based on the number of successful attempts made diff --git a/packages/block-brokers/test/trustless-gateway.spec.ts b/packages/block-brokers/test/trustless-gateway.spec.ts index 481ac6df8..6590393f8 100644 --- a/packages/block-brokers/test/trustless-gateway.spec.ts +++ b/packages/block-brokers/test/trustless-gateway.spec.ts @@ -37,7 +37,7 @@ describe('trustless-gateway-block-broker', () => { gateways = [ stubConstructor(TrustlessGateway, 'http://localhost:8080'), - stubConstructor(TrustlessGateway, 'http://localhost:8081'), + stubConstructor(TrustlessGateway, 'http://localhost:8081', true), stubConstructor(TrustlessGateway, 'http://localhost:8082'), stubConstructor(TrustlessGateway, 'http://localhost:8083') ] @@ -150,4 +150,17 @@ describe('trustless-gateway-block-broker', () => { expect(gateways[1].getRawBlock.calledWith(cid1, Sinon.match.any)).to.be.false() expect(gateways[2].getRawBlock.calledWith(cid1, Sinon.match.any)).to.be.false() }) + + it('constructs the gateway url for the cid for both path and subdomain gateways', async () => { + const pathGw = new TrustlessGateway('http://localhost:8080') + const subdomainGw = new TrustlessGateway('https://dweb.link', true) + + expect(pathGw.getGwUrl(blocks[0].cid).hostname).to.equal(`localhost`) + expect(pathGw.getGwUrl(blocks[0].cid).toString()).to.equal(`http://localhost:8080/ipfs/bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq`) + expect(pathGw.getGwUrl(blocks[1].cid).toString()).to.equal(`http://localhost:8080/ipfs/${blocks[1].cid.toString()}`) + + expect(subdomainGw.getGwUrl(blocks[0].cid).hostname).to.equal(`bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq.ipfs.dweb.link`) + expect(subdomainGw.getGwUrl(blocks[0].cid).toString()).to.equal(`https://bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq.ipfs.dweb.link/`) + expect(subdomainGw.getGwUrl(blocks[1].cid).toString()).to.equal(`https://${blocks[1].cid.toString()}.ipfs.dweb.link/`) + }) }) From 9d77f79036dff46ff4a46b712e3eab7eceb8fb1d Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:00:54 +0100 Subject: [PATCH 2/5] fix: make the api backward compatible --- packages/block-brokers/src/trustless-gateway/broker.ts | 5 +++++ packages/block-brokers/src/trustless-gateway/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-brokers/src/trustless-gateway/broker.ts b/packages/block-brokers/src/trustless-gateway/broker.ts index 9b851bdfd..7e42075ef 100644 --- a/packages/block-brokers/src/trustless-gateway/broker.ts +++ b/packages/block-brokers/src/trustless-gateway/broker.ts @@ -20,6 +20,11 @@ ProgressOptions this.log = components.logger.forComponent('helia:trustless-gateway-block-broker') this.gateways = (init.gateways ?? DEFAULT_TRUSTLESS_GATEWAYS) .map((gw) => { + if(typeof gw === 'string' || gw instanceof URL) { + // backward compatibility defaults to path gateway + return new TrustlessGateway(gw, false) + } + return new TrustlessGateway(gw.url, gw.isSubdomain) }) } diff --git a/packages/block-brokers/src/trustless-gateway/index.ts b/packages/block-brokers/src/trustless-gateway/index.ts index 80aa8b5d8..ec03b81cd 100644 --- a/packages/block-brokers/src/trustless-gateway/index.ts +++ b/packages/block-brokers/src/trustless-gateway/index.ts @@ -23,7 +23,7 @@ export type TrustlessGatewayGetBlockProgressEvents = ProgressEvent<'trustless-gateway:get-block:fetch', URL> export interface TrustlessGatewayBlockBrokerInit { - gateways?: Array + gateways?: Array } export interface TrustlessGatewayComponents { From 2aae3b9232017235c99a3027e49a84ed4c69a38c Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:26:54 +0100 Subject: [PATCH 3/5] chore: fix lint errors --- .../src/trustless-gateway/broker.ts | 4 ++-- .../src/trustless-gateway/index.ts | 8 +++---- .../trustless-gateway/trustless-gateway.ts | 22 +++++++++---------- .../test/trustless-gateway.spec.ts | 8 +++---- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/block-brokers/src/trustless-gateway/broker.ts b/packages/block-brokers/src/trustless-gateway/broker.ts index 7e42075ef..2fdace1b6 100644 --- a/packages/block-brokers/src/trustless-gateway/broker.ts +++ b/packages/block-brokers/src/trustless-gateway/broker.ts @@ -20,12 +20,12 @@ ProgressOptions this.log = components.logger.forComponent('helia:trustless-gateway-block-broker') this.gateways = (init.gateways ?? DEFAULT_TRUSTLESS_GATEWAYS) .map((gw) => { - if(typeof gw === 'string' || gw instanceof URL) { + if (typeof gw === 'string' || gw instanceof URL) { // backward compatibility defaults to path gateway return new TrustlessGateway(gw, false) } - return new TrustlessGateway(gw.url, gw.isSubdomain) + return new TrustlessGateway(gw.url, gw.supportsSubdomains) }) } diff --git a/packages/block-brokers/src/trustless-gateway/index.ts b/packages/block-brokers/src/trustless-gateway/index.ts index ec03b81cd..25c0d9137 100644 --- a/packages/block-brokers/src/trustless-gateway/index.ts +++ b/packages/block-brokers/src/trustless-gateway/index.ts @@ -5,18 +5,18 @@ import type { ProgressEvent } from 'progress-events' export const DEFAULT_TRUSTLESS_GATEWAYS: TrustlessGatewayUrl[] = [ // 2024-02-20: IPNS and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ - { url: 'https://trustless-gateway.link', isSubdomain: false }, + { url: 'https://trustless-gateway.link', supportsSubdomains: false }, // 2024-02-20: IPNS and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ - { url: 'https://cloudflare-ipfs.com', isSubdomain: false }, + { url: 'https://cloudflare-ipfs.com', supportsSubdomains: false }, // 2024-02-20: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ - { url: 'https://4everland.io', isSubdomain: true }, + { url: 'https://4everland.io', supportsSubdomains: true } ] interface TrustlessGatewayUrl { url: string | URL - isSubdomain: boolean + supportsSubdomains: boolean } export type TrustlessGatewayGetBlockProgressEvents = diff --git a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts index c6a56947f..92a3ab4f9 100644 --- a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts +++ b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts @@ -1,5 +1,5 @@ -import type { CID } from 'multiformats/cid' import { base32 } from 'multiformats/bases/base32' +import type { CID } from 'multiformats/cid' /** * A `TrustlessGateway` keeps track of the number of attempts, errors, and @@ -13,7 +13,7 @@ export class TrustlessGateway { /** * Whether this gateway is a subdomain resolution style gateway */ - public isSubdomain: boolean + public supportsSubdomains: boolean /** * The number of times this gateway has been attempted to be used to fetch a @@ -43,16 +43,16 @@ export class TrustlessGateway { */ #successes = 0 - constructor(url: URL | string, isSubdomain: boolean = false) { + constructor (url: URL | string, supportsSubdomains: boolean = false) { this.url = url instanceof URL ? url : new URL(url) - this.isSubdomain = isSubdomain + this.supportsSubdomains = supportsSubdomains } /** * Fetch a raw block from `this.url` following the specification defined at * https://specs.ipfs.tech/http-gateways/trustless-gateway/ */ - async getRawBlock(cid: CID, signal?: AbortSignal): Promise { + async getRawBlock (cid: CID, signal?: AbortSignal): Promise { const gwUrl = this.getGwUrl(cid) // necessary as not every gateway supports dag-cbor, but every should support @@ -60,9 +60,7 @@ export class TrustlessGateway { gwUrl.search = '?format=raw' if (signal?.aborted === true) { - throw new Error( - `Signal to fetch raw block for CID ${cid} from gateway ${this.url} was aborted prior to fetch`, - ) + throw new Error(`Signal to fetch raw block for CID ${cid} from gateway ${this.url} was aborted prior to fetch`) } try { @@ -72,7 +70,7 @@ export class TrustlessGateway { headers: { // also set header, just in case ?format= is filtered out by some // reverse proxy - Accept: 'application/vnd.ipld.raw', + Accept: 'application/vnd.ipld.raw' }, cache: 'force-cache' }) @@ -96,10 +94,10 @@ export class TrustlessGateway { /** * Construct the Gateway URL for a CID */ - getGwUrl(cid: CID): URL { + getGwUrl (cid: CID): URL { const gwUrl = new URL(this.url) - if (this.isSubdomain) { + if (this.supportsSubdomains) { gwUrl.hostname = `${cid.toString(base32)}.ipfs.${gwUrl.hostname}` } else { gwUrl.pathname = `/ipfs/${cid.toString()}` @@ -137,7 +135,7 @@ export class TrustlessGateway { * * Play around with the below reliability function at https://www.desmos.com/calculator/d6hfhf5ukm */ - return this.#successes / (this.#attempts + (this.#errors * 3)) + return this.#successes / (this.#attempts + this.#errors * 3) } /** diff --git a/packages/block-brokers/test/trustless-gateway.spec.ts b/packages/block-brokers/test/trustless-gateway.spec.ts index 6590393f8..cc67d513d 100644 --- a/packages/block-brokers/test/trustless-gateway.spec.ts +++ b/packages/block-brokers/test/trustless-gateway.spec.ts @@ -155,12 +155,12 @@ describe('trustless-gateway-block-broker', () => { const pathGw = new TrustlessGateway('http://localhost:8080') const subdomainGw = new TrustlessGateway('https://dweb.link', true) - expect(pathGw.getGwUrl(blocks[0].cid).hostname).to.equal(`localhost`) - expect(pathGw.getGwUrl(blocks[0].cid).toString()).to.equal(`http://localhost:8080/ipfs/bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq`) + expect(pathGw.getGwUrl(blocks[0].cid).hostname).to.equal('localhost') + expect(pathGw.getGwUrl(blocks[0].cid).toString()).to.equal('http://localhost:8080/ipfs/bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq') expect(pathGw.getGwUrl(blocks[1].cid).toString()).to.equal(`http://localhost:8080/ipfs/${blocks[1].cid.toString()}`) - expect(subdomainGw.getGwUrl(blocks[0].cid).hostname).to.equal(`bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq.ipfs.dweb.link`) - expect(subdomainGw.getGwUrl(blocks[0].cid).toString()).to.equal(`https://bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq.ipfs.dweb.link/`) + expect(subdomainGw.getGwUrl(blocks[0].cid).hostname).to.equal('bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq.ipfs.dweb.link') + expect(subdomainGw.getGwUrl(blocks[0].cid).toString()).to.equal('https://bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq.ipfs.dweb.link/') expect(subdomainGw.getGwUrl(blocks[1].cid).toString()).to.equal(`https://${blocks[1].cid.toString()}.ipfs.dweb.link/`) }) }) From ed761715c546f79eff941226f89a00c8d5df7210 Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Fri, 23 Feb 2024 13:46:41 +0100 Subject: [PATCH 4/5] refactor: use object for subdomain resolution --- .../src/trustless-gateway/broker.ts | 4 ++-- .../block-brokers/src/trustless-gateway/index.ts | 8 ++++---- .../src/trustless-gateway/trustless-gateway.ts | 16 ++++++++++++---- .../block-brokers/test/trustless-gateway.spec.ts | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/block-brokers/src/trustless-gateway/broker.ts b/packages/block-brokers/src/trustless-gateway/broker.ts index 2fdace1b6..ce2330cd0 100644 --- a/packages/block-brokers/src/trustless-gateway/broker.ts +++ b/packages/block-brokers/src/trustless-gateway/broker.ts @@ -22,10 +22,10 @@ ProgressOptions .map((gw) => { if (typeof gw === 'string' || gw instanceof URL) { // backward compatibility defaults to path gateway - return new TrustlessGateway(gw, false) + return new TrustlessGateway(gw, { subdomainResolution: false }) } - return new TrustlessGateway(gw.url, gw.supportsSubdomains) + return new TrustlessGateway(gw.url, { subdomainResolution: gw.subdomainResolution }) }) } diff --git a/packages/block-brokers/src/trustless-gateway/index.ts b/packages/block-brokers/src/trustless-gateway/index.ts index 25c0d9137..e24e1e997 100644 --- a/packages/block-brokers/src/trustless-gateway/index.ts +++ b/packages/block-brokers/src/trustless-gateway/index.ts @@ -5,18 +5,18 @@ import type { ProgressEvent } from 'progress-events' export const DEFAULT_TRUSTLESS_GATEWAYS: TrustlessGatewayUrl[] = [ // 2024-02-20: IPNS and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ - { url: 'https://trustless-gateway.link', supportsSubdomains: false }, + { url: 'https://trustless-gateway.link', subdomainResolution: false }, // 2024-02-20: IPNS and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ - { url: 'https://cloudflare-ipfs.com', supportsSubdomains: false }, + { url: 'https://cloudflare-ipfs.com', subdomainResolution: false }, // 2024-02-20: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/ - { url: 'https://4everland.io', supportsSubdomains: true } + { url: 'https://4everland.io', subdomainResolution: true } ] interface TrustlessGatewayUrl { url: string | URL - supportsSubdomains: boolean + subdomainResolution: boolean } export type TrustlessGatewayGetBlockProgressEvents = diff --git a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts index 92a3ab4f9..4fc6cd47c 100644 --- a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts +++ b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts @@ -1,6 +1,14 @@ import { base32 } from 'multiformats/bases/base32' import type { CID } from 'multiformats/cid' +interface TrustlessGatewayOpts { + + /** + * Determins whether the gateway supports subdomain resolution + */ + subdomainResolution: boolean +} + /** * A `TrustlessGateway` keeps track of the number of attempts, errors, and * successes for a given gateway url so that we can prioritize gateways that @@ -13,7 +21,7 @@ export class TrustlessGateway { /** * Whether this gateway is a subdomain resolution style gateway */ - public supportsSubdomains: boolean + public subdomainResolution: boolean /** * The number of times this gateway has been attempted to be used to fetch a @@ -43,9 +51,9 @@ export class TrustlessGateway { */ #successes = 0 - constructor (url: URL | string, supportsSubdomains: boolean = false) { + constructor (url: URL | string, { subdomainResolution }: TrustlessGatewayOpts = { subdomainResolution: false } ) { this.url = url instanceof URL ? url : new URL(url) - this.supportsSubdomains = supportsSubdomains + this.subdomainResolution = subdomainResolution } /** @@ -97,7 +105,7 @@ export class TrustlessGateway { getGwUrl (cid: CID): URL { const gwUrl = new URL(this.url) - if (this.supportsSubdomains) { + if (this.subdomainResolution) { gwUrl.hostname = `${cid.toString(base32)}.ipfs.${gwUrl.hostname}` } else { gwUrl.pathname = `/ipfs/${cid.toString()}` diff --git a/packages/block-brokers/test/trustless-gateway.spec.ts b/packages/block-brokers/test/trustless-gateway.spec.ts index cc67d513d..1f1626dd7 100644 --- a/packages/block-brokers/test/trustless-gateway.spec.ts +++ b/packages/block-brokers/test/trustless-gateway.spec.ts @@ -37,7 +37,7 @@ describe('trustless-gateway-block-broker', () => { gateways = [ stubConstructor(TrustlessGateway, 'http://localhost:8080'), - stubConstructor(TrustlessGateway, 'http://localhost:8081', true), + stubConstructor(TrustlessGateway, 'http://localhost:8081', { subdomainResolution: true }), stubConstructor(TrustlessGateway, 'http://localhost:8082'), stubConstructor(TrustlessGateway, 'http://localhost:8083') ] @@ -153,7 +153,7 @@ describe('trustless-gateway-block-broker', () => { it('constructs the gateway url for the cid for both path and subdomain gateways', async () => { const pathGw = new TrustlessGateway('http://localhost:8080') - const subdomainGw = new TrustlessGateway('https://dweb.link', true) + const subdomainGw = new TrustlessGateway('https://dweb.link', { subdomainResolution: true }) expect(pathGw.getGwUrl(blocks[0].cid).hostname).to.equal('localhost') expect(pathGw.getGwUrl(blocks[0].cid).toString()).to.equal('http://localhost:8080/ipfs/bafkreiefnkxuhnq3536qo2i2w3tazvifek4mbbzb6zlq3ouhprjce5c3aq') From 43810d33aec04b54f9aa074a804c09eeac4ed08e Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:17:20 +0100 Subject: [PATCH 5/5] chore: fix linting error --- .../block-brokers/src/trustless-gateway/trustless-gateway.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts index 4fc6cd47c..601fdfc75 100644 --- a/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts +++ b/packages/block-brokers/src/trustless-gateway/trustless-gateway.ts @@ -51,7 +51,7 @@ export class TrustlessGateway { */ #successes = 0 - constructor (url: URL | string, { subdomainResolution }: TrustlessGatewayOpts = { subdomainResolution: false } ) { + constructor (url: URL | string, { subdomainResolution }: TrustlessGatewayOpts = { subdomainResolution: false }) { this.url = url instanceof URL ? url : new URL(url) this.subdomainResolution = subdomainResolution }