@ar.io/wayfinder-core 0.0.2 → 0.0.3-alpha.1
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 +15 -1
- package/dist/gateways/network.d.ts +4 -1
- package/dist/gateways/network.d.ts.map +1 -1
- package/dist/gateways/network.js +1 -1
- package/dist/gateways/simple-cache.d.ts +4 -1
- package/dist/gateways/simple-cache.d.ts.map +1 -1
- package/dist/gateways/simple-cache.js +2 -2
- package/dist/gateways/static.d.ts +4 -1
- package/dist/gateways/static.d.ts.map +1 -1
- package/dist/gateways/static.js +1 -1
- package/dist/routing/ping.d.ts +4 -5
- package/dist/routing/ping.d.ts.map +1 -1
- package/dist/routing/ping.js +9 -8
- package/dist/routing/preferred-with-fallback.d.ts +3 -1
- package/dist/routing/preferred-with-fallback.d.ts.map +1 -1
- package/dist/routing/preferred-with-fallback.js +12 -3
- package/dist/routing/random.d.ts +3 -1
- package/dist/routing/random.d.ts.map +1 -1
- package/dist/routing/random.js +1 -1
- package/dist/routing/round-robin.d.ts +2 -0
- package/dist/routing/round-robin.d.ts.map +1 -1
- package/dist/routing/static.d.ts +2 -0
- package/dist/routing/static.d.ts.map +1 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -174,7 +174,7 @@ Wayfinder includes verification mechanisms to ensure the integrity of retrieved
|
|
|
174
174
|
| ------------------------------- | ---------- | ----------- | -------- | ------------------------------------------------------------------------------------------------------------ |
|
|
175
175
|
| `HashVerificationStrategy` | Low | High | Low | Verifies data integrity using SHA-256 hash comparison of the returned data |
|
|
176
176
|
| `DataRootVerificationStrategy` | Medium | Medium | Low | Verifies data using Arweave by computing the data root for the transaction (most useful for L1 transactions) |
|
|
177
|
-
| `SignatureVerificationStrategy` | Medium | Medium | Medium | Verifies signature of an Arweave transaction or data item using
|
|
177
|
+
| `SignatureVerificationStrategy` | Medium | Medium | Medium | Verifies signature of an Arweave transaction or data item using signature data provided by the Arweave network, or trusted gateways|
|
|
178
178
|
|
|
179
179
|
### HashVerificationStrategy
|
|
180
180
|
|
|
@@ -204,6 +204,20 @@ const wayfinder = new Wayfinder({
|
|
|
204
204
|
});
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
+
### SignatureVerificationStrategy
|
|
208
|
+
|
|
209
|
+
Verifies signatures of Arweave transactions and data items. Headers are retrieved from trusted gateways for use during verification. For a transaction, its data root is computed while streaming its data and then utilized alongside its headers for verification. For data items, the ANS-104 deep hash method of signature verification is used.
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
import { Wayfinder, SignatureVerificationStrategy } from '@ar-io/sdk';
|
|
213
|
+
|
|
214
|
+
const wayfinder = new Wayfinder({
|
|
215
|
+
verificationStrategy: new SignatureVerificationStrategy({
|
|
216
|
+
trustedGateways: ['https://permagate.io'],
|
|
217
|
+
}),
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
207
221
|
## Monitoring and Events
|
|
208
222
|
|
|
209
223
|
Wayfinder emits events during the routing and verification process, allowing you to monitor its operation.
|
|
@@ -33,6 +33,9 @@ export declare class NetworkGatewaysProvider implements GatewaysProvider {
|
|
|
33
33
|
filter?: (gateway: any) => boolean;
|
|
34
34
|
logger?: Logger;
|
|
35
35
|
});
|
|
36
|
-
getGateways(
|
|
36
|
+
getGateways(_params?: {
|
|
37
|
+
path?: string;
|
|
38
|
+
subdomain?: string;
|
|
39
|
+
}): Promise<URL[]>;
|
|
37
40
|
}
|
|
38
41
|
//# sourceMappingURL=network.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/gateways/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,MAAM,CAA6D;IAC3E,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,IAAI,EACJ,MAAwB,EACxB,SAAkB,EAClB,KAAY,EACZ,MAAqC,EACrC,MAAsB,GACvB,EAAE;QACD,IAAI,EAAE,YAAY,CAAC;QACnB,MAAM,CAAC,EAAE,qBAAqB,GAAG,eAAe,GAAG,gBAAgB,CAAC;QACpE,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;QAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;QACnC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IASK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/gateways/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,uBAAwB,YAAW,gBAAgB;IAC9D,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,MAAM,CAA6D;IAC3E,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,IAAI,EACJ,MAAwB,EACxB,SAAkB,EAClB,KAAY,EACZ,MAAqC,EACrC,MAAsB,GACvB,EAAE;QACD,IAAI,EAAE,YAAY,CAAC;QACnB,MAAM,CAAC,EAAE,qBAAqB,GAAG,eAAe,GAAG,gBAAgB,CAAC;QACpE,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;QAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;QACnC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IASK,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CA0DnF"}
|
package/dist/gateways/network.js
CHANGED
|
@@ -45,6 +45,9 @@ export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
|
|
|
45
45
|
ttlSeconds?: number;
|
|
46
46
|
logger?: Logger;
|
|
47
47
|
});
|
|
48
|
-
getGateways(
|
|
48
|
+
getGateways(params?: {
|
|
49
|
+
path?: string;
|
|
50
|
+
subdomain?: string;
|
|
51
|
+
}): Promise<URL[]>;
|
|
49
52
|
}
|
|
50
53
|
//# sourceMappingURL=simple-cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-cache.d.ts","sourceRoot":"","sources":["../../src/gateways/simple-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,2BAA4B,YAAW,gBAAgB;IAClE,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,gBAAgB,EAChB,UAAoB,EAAE,SAAS;IAC/B,MAAsB,GACvB,EAAE;QACD,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAQK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"simple-cache.d.ts","sourceRoot":"","sources":["../../src/gateways/simple-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,2BAA4B,YAAW,gBAAgB;IAClE,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,gBAAgB,EAChB,UAAoB,EAAE,SAAS;IAC/B,MAAsB,GACvB,EAAE;QACD,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAQK,WAAW,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CAmClF"}
|
|
@@ -30,7 +30,7 @@ export class SimpleCacheGatewaysProvider {
|
|
|
30
30
|
this.lastUpdated = 0;
|
|
31
31
|
this.logger = logger;
|
|
32
32
|
}
|
|
33
|
-
async getGateways() {
|
|
33
|
+
async getGateways(params) {
|
|
34
34
|
const now = Date.now();
|
|
35
35
|
if (this.gatewaysCache.length === 0 ||
|
|
36
36
|
now - this.lastUpdated > this.ttlSeconds * 1000) {
|
|
@@ -40,7 +40,7 @@ export class SimpleCacheGatewaysProvider {
|
|
|
40
40
|
ttlSeconds: this.ttlSeconds,
|
|
41
41
|
});
|
|
42
42
|
// preserve the cache if the fetch fails
|
|
43
|
-
const allGateways = await this.gatewaysProvider.getGateways();
|
|
43
|
+
const allGateways = await this.gatewaysProvider.getGateways(params);
|
|
44
44
|
this.gatewaysCache = allGateways;
|
|
45
45
|
this.lastUpdated = now;
|
|
46
46
|
this.logger.debug('Updated gateways cache', {
|
|
@@ -20,6 +20,9 @@ export declare class StaticGatewaysProvider implements GatewaysProvider {
|
|
|
20
20
|
constructor({ gateways }: {
|
|
21
21
|
gateways: string[];
|
|
22
22
|
});
|
|
23
|
-
getGateways(
|
|
23
|
+
getGateways(_params?: {
|
|
24
|
+
path?: string;
|
|
25
|
+
subdomain?: string;
|
|
26
|
+
}): Promise<URL[]>;
|
|
24
27
|
}
|
|
25
28
|
//# sourceMappingURL=static.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/gateways/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,QAAQ,CAAQ;gBACZ,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;IAI1C,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/gateways/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,QAAQ,CAAQ;gBACZ,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;IAI1C,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CAGnF"}
|
package/dist/gateways/static.js
CHANGED
package/dist/routing/ping.d.ts
CHANGED
|
@@ -2,18 +2,17 @@ import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
|
2
2
|
import { Logger } from '../wayfinder.js';
|
|
3
3
|
export declare class FastestPingRoutingStrategy implements RoutingStrategy {
|
|
4
4
|
private timeoutMs;
|
|
5
|
-
private probePath;
|
|
6
5
|
private logger;
|
|
7
6
|
private maxConcurrency;
|
|
8
|
-
constructor({ timeoutMs, maxConcurrency,
|
|
9
|
-
logger, }?: {
|
|
7
|
+
constructor({ timeoutMs, maxConcurrency, logger, }?: {
|
|
10
8
|
timeoutMs?: number;
|
|
11
9
|
maxConcurrency?: number;
|
|
12
|
-
probePath?: string;
|
|
13
10
|
logger?: Logger;
|
|
14
11
|
});
|
|
15
|
-
selectGateway({ gateways }: {
|
|
12
|
+
selectGateway({ gateways, path, subdomain, }: {
|
|
16
13
|
gateways: URL[];
|
|
14
|
+
path?: string;
|
|
15
|
+
subdomain?: string;
|
|
17
16
|
}): Promise<URL>;
|
|
18
17
|
}
|
|
19
18
|
//# sourceMappingURL=ping.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/routing/ping.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/routing/ping.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAS;gBAEnB,EACV,SAAe,EACf,cAAmB,EACnB,MAAsB,GACvB,GAAE;QACD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ;IAMA,aAAa,CAAC,EAClB,QAAQ,EACR,IAAS,EACT,SAAS,GACV,EAAE;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC;CA+DjB"}
|
package/dist/routing/ping.js
CHANGED
|
@@ -18,17 +18,14 @@ import { pLimit } from 'plimit-lit';
|
|
|
18
18
|
import { defaultLogger } from '../wayfinder.js';
|
|
19
19
|
export class FastestPingRoutingStrategy {
|
|
20
20
|
timeoutMs;
|
|
21
|
-
probePath;
|
|
22
21
|
logger;
|
|
23
22
|
maxConcurrency;
|
|
24
|
-
constructor({ timeoutMs = 500, maxConcurrency = 50,
|
|
25
|
-
logger = defaultLogger, } = {}) {
|
|
23
|
+
constructor({ timeoutMs = 500, maxConcurrency = 50, logger = defaultLogger, } = {}) {
|
|
26
24
|
this.timeoutMs = timeoutMs;
|
|
27
|
-
this.probePath = probePath;
|
|
28
25
|
this.logger = logger;
|
|
29
26
|
this.maxConcurrency = maxConcurrency;
|
|
30
27
|
}
|
|
31
|
-
async selectGateway({ gateways }) {
|
|
28
|
+
async selectGateway({ gateways, path = '', subdomain, }) {
|
|
32
29
|
if (gateways.length === 0) {
|
|
33
30
|
const error = new Error('No gateways provided');
|
|
34
31
|
this.logger.error('Failed to select gateway', { error: error.message });
|
|
@@ -37,12 +34,16 @@ export class FastestPingRoutingStrategy {
|
|
|
37
34
|
this.logger.debug(`Pinging ${gateways.length} gateways with timeout ${this.timeoutMs}ms`, {
|
|
38
35
|
gateways: gateways.map((g) => g.toString()),
|
|
39
36
|
timeoutMs: this.timeoutMs,
|
|
40
|
-
probePath:
|
|
37
|
+
probePath: path,
|
|
41
38
|
});
|
|
42
39
|
const throttle = pLimit(Math.min(this.maxConcurrency, gateways.length));
|
|
43
40
|
const pingPromises = gateways.map(async (gateway) => {
|
|
44
41
|
return throttle(async () => {
|
|
45
|
-
const
|
|
42
|
+
const url = new URL(gateway.toString());
|
|
43
|
+
if (subdomain) {
|
|
44
|
+
url.hostname = `${subdomain}.${url.hostname}`;
|
|
45
|
+
}
|
|
46
|
+
const pingUrl = new URL(path.replace(/^\//, ''), url).toString();
|
|
46
47
|
this.logger.debug(`Pinging gateway ${gateway.toString()}`, {
|
|
47
48
|
gateway: gateway.toString(),
|
|
48
49
|
pingUrl,
|
|
@@ -60,7 +61,7 @@ export class FastestPingRoutingStrategy {
|
|
|
60
61
|
throw new Error('Failed to ping gateway', {
|
|
61
62
|
cause: {
|
|
62
63
|
gateway: gateway.toString(),
|
|
63
|
-
probePath:
|
|
64
|
+
probePath: path,
|
|
64
65
|
status: response.status,
|
|
65
66
|
},
|
|
66
67
|
});
|
|
@@ -26,8 +26,10 @@ export declare class PreferredWithFallbackRoutingStrategy implements RoutingStra
|
|
|
26
26
|
fallbackStrategy?: RoutingStrategy;
|
|
27
27
|
logger?: Logger;
|
|
28
28
|
});
|
|
29
|
-
selectGateway({ gateways }: {
|
|
29
|
+
selectGateway({ gateways, path, subdomain, }: {
|
|
30
30
|
gateways: URL[];
|
|
31
|
+
path?: string;
|
|
32
|
+
subdomain?: string;
|
|
31
33
|
}): Promise<URL>;
|
|
32
34
|
}
|
|
33
35
|
//# sourceMappingURL=preferred-with-fallback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preferred-with-fallback.d.ts","sourceRoot":"","sources":["../../src/routing/preferred-with-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAGxD,qBAAa,oCAAqC,YAAW,eAAe;IAC1E,SAAgB,IAAI,6BAA6B;IACjD,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,gBAAgB,EAChB,gBAAmD,EACnD,MAAsB,GACvB,EAAE;QACD,gBAAgB,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,eAAe,CAAC;QACnC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAMK,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"preferred-with-fallback.d.ts","sourceRoot":"","sources":["../../src/routing/preferred-with-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAGxD,qBAAa,oCAAqC,YAAW,eAAe;IAC1E,SAAgB,IAAI,6BAA6B;IACjD,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,gBAAgB,EAChB,gBAAmD,EACnD,MAAsB,GACvB,EAAE;QACD,gBAAgB,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,eAAe,CAAC;QACnC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAMK,aAAa,CAAC,EAClB,QAAa,EACb,IAAS,EACT,SAAS,GACV,EAAE;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC;CA6CjB"}
|
|
@@ -10,13 +10,18 @@ export class PreferredWithFallbackRoutingStrategy {
|
|
|
10
10
|
this.fallbackStrategy = fallbackStrategy;
|
|
11
11
|
this.preferredGateway = new URL(preferredGateway);
|
|
12
12
|
}
|
|
13
|
-
async selectGateway({ gateways = [] }) {
|
|
13
|
+
async selectGateway({ gateways = [], path = '', subdomain, }) {
|
|
14
14
|
this.logger.debug('Attempting to connect to preferred gateway', {
|
|
15
15
|
preferredGateway: this.preferredGateway.toString(),
|
|
16
16
|
});
|
|
17
17
|
try {
|
|
18
18
|
// Check if the preferred gateway is responsive
|
|
19
|
-
const
|
|
19
|
+
const url = new URL(this.preferredGateway.toString());
|
|
20
|
+
if (subdomain) {
|
|
21
|
+
url.hostname = `${subdomain}.${url.hostname}`;
|
|
22
|
+
}
|
|
23
|
+
const probeUrl = path ? new URL(path.replace(/^\//, ''), url) : url;
|
|
24
|
+
const response = await fetch(probeUrl.toString(), {
|
|
20
25
|
method: 'HEAD',
|
|
21
26
|
signal: AbortSignal.timeout(1000),
|
|
22
27
|
});
|
|
@@ -35,7 +40,11 @@ export class PreferredWithFallbackRoutingStrategy {
|
|
|
35
40
|
fallbackStrategy: this.fallbackStrategy.constructor.name,
|
|
36
41
|
});
|
|
37
42
|
// Fall back to the provided routing strategy
|
|
38
|
-
return this.fallbackStrategy.selectGateway({
|
|
43
|
+
return this.fallbackStrategy.selectGateway({
|
|
44
|
+
gateways,
|
|
45
|
+
path,
|
|
46
|
+
subdomain,
|
|
47
|
+
});
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
}
|
package/dist/routing/random.d.ts
CHANGED
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
18
18
|
export declare class RandomRoutingStrategy implements RoutingStrategy {
|
|
19
|
-
selectGateway({ gateways }: {
|
|
19
|
+
selectGateway({ gateways, }: {
|
|
20
20
|
gateways: URL[];
|
|
21
|
+
path?: string;
|
|
22
|
+
subdomain?: string;
|
|
21
23
|
}): Promise<URL>;
|
|
22
24
|
}
|
|
23
25
|
//# sourceMappingURL=random.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/routing/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3D,qBAAa,qBAAsB,YAAW,eAAe;IACrD,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/routing/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3D,qBAAa,qBAAsB,YAAW,eAAe;IACrD,aAAa,CAAC,EAClB,QAAQ,GACT,EAAE;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC;CAMjB"}
|
package/dist/routing/random.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"round-robin.d.ts","sourceRoot":"","sources":["../../src/routing/round-robin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,yBAA0B,YAAW,eAAe;IAC/D,SAAgB,IAAI,iBAAiB;IACrC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,QAAQ,EACR,MAAsB,GACvB,EAAE;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,aAAa,CAAC,EAClB,QAAa,GACd,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"round-robin.d.ts","sourceRoot":"","sources":["../../src/routing/round-robin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,yBAA0B,YAAW,eAAe;IAC/D,SAAgB,IAAI,iBAAiB;IACrC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,QAAQ,EACR,MAAsB,GACvB,EAAE;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,aAAa,CAAC,EAClB,QAAa,GACd,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,GAAG,CAAC;CActB"}
|
package/dist/routing/static.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/routing/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,SAAgB,IAAI,YAAY;IAChC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,OAAO,EACP,MAAsB,GACvB,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,aAAa,CAAC,EAClB,QAAa,GACd,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/routing/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,SAAgB,IAAI,YAAY;IAChC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,OAAO,EACP,MAAsB,GACvB,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,aAAa,CAAC,EAClB,QAAa,GACd,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,GAAG,CAAC;CAYtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/wayfinder-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-alpha.1",
|
|
4
4
|
"description": "WayFinder core library for intelligently routing to optimal AR.IO gateways",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
"wayfinder",
|
|
14
14
|
"ar://"
|
|
15
15
|
],
|
|
16
|
-
"author":
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Permanent Data Solutions Inc",
|
|
18
|
+
"email": "info@ar.io",
|
|
19
|
+
"website": "https://ar.io"
|
|
20
|
+
},
|
|
17
21
|
"publishConfig": {
|
|
18
22
|
"access": "public"
|
|
19
23
|
},
|
|
@@ -36,6 +40,7 @@
|
|
|
36
40
|
"scripts": {
|
|
37
41
|
"build": "npm run clean && tsc",
|
|
38
42
|
"clean": "rimraf dist",
|
|
43
|
+
"test": "npm run test:unit",
|
|
39
44
|
"test:unit": "c8 node --import=../../register.mjs --test --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
|
|
40
45
|
"lint:fix": "biome check --write --unsafe",
|
|
41
46
|
"lint:check": "biome check --unsafe",
|
|
@@ -43,6 +48,7 @@
|
|
|
43
48
|
"format:check": "biome format"
|
|
44
49
|
},
|
|
45
50
|
"dependencies": {
|
|
51
|
+
"@dha-team/arbundles": "^1.0.3",
|
|
46
52
|
"arweave": "^1.14.0",
|
|
47
53
|
"eventemitter3": "^5.0.1",
|
|
48
54
|
"plimit-lit": "^3.0.1",
|