@ar.io/wayfinder-core 0.0.5-alpha.2 → 0.0.5-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +45 -2
  2. package/dist/classifiers/gql-classifier.d.ts +1 -2
  3. package/dist/classifiers/gql-classifier.d.ts.map +1 -1
  4. package/dist/classifiers/gql-classifier.js +16 -0
  5. package/dist/gateways/network.d.ts +2 -3
  6. package/dist/gateways/network.d.ts.map +1 -1
  7. package/dist/gateways/simple-cache.d.ts +1 -19
  8. package/dist/gateways/simple-cache.d.ts.map +1 -1
  9. package/dist/gateways/simple-cache.js +10 -11
  10. package/dist/gateways/static.d.ts +1 -1
  11. package/dist/gateways/static.d.ts.map +1 -1
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +3 -0
  15. package/dist/logger.d.ts +1 -10
  16. package/dist/logger.d.ts.map +1 -1
  17. package/dist/logger.js +16 -0
  18. package/dist/routing/ping.d.ts +1 -2
  19. package/dist/routing/ping.d.ts.map +1 -1
  20. package/dist/routing/preferred-with-fallback.d.ts +1 -2
  21. package/dist/routing/preferred-with-fallback.d.ts.map +1 -1
  22. package/dist/routing/preferred-with-fallback.js +16 -0
  23. package/dist/routing/random.d.ts +1 -1
  24. package/dist/routing/random.d.ts.map +1 -1
  25. package/dist/routing/round-robin.d.ts +1 -19
  26. package/dist/routing/round-robin.d.ts.map +1 -1
  27. package/dist/routing/round-robin.js +10 -11
  28. package/dist/routing/simple-cache.d.ts +37 -0
  29. package/dist/routing/simple-cache.d.ts.map +1 -0
  30. package/dist/routing/simple-cache.js +72 -0
  31. package/dist/routing/static.d.ts +1 -19
  32. package/dist/routing/static.d.ts.map +1 -1
  33. package/dist/routing/static.js +10 -11
  34. package/dist/types.d.ts +151 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +17 -0
  37. package/dist/utils/hash.d.ts +1 -2
  38. package/dist/utils/hash.d.ts.map +1 -1
  39. package/dist/verification/data-root-verifier.d.ts +1 -2
  40. package/dist/verification/data-root-verifier.d.ts.map +1 -1
  41. package/dist/verification/hash-verifier.d.ts +1 -2
  42. package/dist/verification/hash-verifier.d.ts.map +1 -1
  43. package/dist/verification/signature-verifier.d.ts +1 -2
  44. package/dist/verification/signature-verifier.d.ts.map +1 -1
  45. package/dist/wayfinder.d.ts +17 -111
  46. package/dist/wayfinder.d.ts.map +1 -1
  47. package/dist/wayfinder.js +39 -43
  48. package/package.json +3 -13
@@ -0,0 +1,151 @@
1
+ /**
2
+ * WayFinder
3
+ * Copyright (C) 2022-2025 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * This is an extension of the fetch function that allows for overriding the verification and routing settings for a single request.
19
+ */
20
+ export type WayfinderFetch = (input: URL | RequestInfo, init?: RequestInit & {
21
+ verificationSettings?: WayfinderOptions['verificationSettings'];
22
+ routingSettings?: WayfinderOptions['routingSettings'];
23
+ }) => Promise<Response>;
24
+ export type WayfinderEvent = {
25
+ 'routing-started': {
26
+ originalUrl: string;
27
+ };
28
+ 'routing-skipped': {
29
+ originalUrl: string;
30
+ };
31
+ 'routing-succeeded': {
32
+ originalUrl: string;
33
+ selectedGateway: string;
34
+ redirectUrl: string;
35
+ };
36
+ 'routing-failed': Error;
37
+ 'verification-succeeded': {
38
+ txId: string;
39
+ };
40
+ 'verification-failed': Error;
41
+ 'verification-skipped': {
42
+ originalUrl: string;
43
+ };
44
+ 'verification-progress': {
45
+ txId: string;
46
+ processedBytes: number;
47
+ totalBytes: number;
48
+ };
49
+ };
50
+ /**
51
+ * Simple logger interface that Wayfinder will use
52
+ * This allows users to provide their own logger implementation
53
+ */
54
+ export interface Logger {
55
+ debug: (message: string, ...args: any[]) => void;
56
+ info: (message: string, ...args: any[]) => void;
57
+ warn: (message: string, ...args: any[]) => void;
58
+ error: (message: string, ...args: any[]) => void;
59
+ }
60
+ export interface WayfinderRoutingEventArgs {
61
+ onRoutingStarted?: (payload: WayfinderEvent['routing-started']) => void;
62
+ onRoutingSkipped?: (payload: WayfinderEvent['routing-skipped']) => void;
63
+ onRoutingSucceeded?: (payload: WayfinderEvent['routing-succeeded']) => void;
64
+ }
65
+ export interface WayfinderVerificationEventArgs {
66
+ onVerificationSucceeded?: (payload: WayfinderEvent['verification-succeeded']) => void;
67
+ onVerificationFailed?: (payload: WayfinderEvent['verification-failed']) => void;
68
+ onVerificationProgress?: (payload: WayfinderEvent['verification-progress']) => void;
69
+ }
70
+ export interface WayfinderEventArgs {
71
+ verification?: WayfinderVerificationEventArgs;
72
+ routing?: WayfinderRoutingEventArgs;
73
+ }
74
+ /**
75
+ * Configuration options for the Wayfinder
76
+ */
77
+ export interface WayfinderOptions {
78
+ /**
79
+ * Logger to use for logging
80
+ * @default defaultLogger (standard console logger)
81
+ */
82
+ logger?: Logger;
83
+ /**
84
+ * The gateways provider to use for routing requests.
85
+ */
86
+ gatewaysProvider: GatewaysProvider;
87
+ /**
88
+ * The verification settings to use for verifying data
89
+ */
90
+ verificationSettings?: {
91
+ /**
92
+ * Whether verification is enabled. If false, verification will be skipped for all requests. If true, strategy must be provided.
93
+ * @default true
94
+ */
95
+ enabled?: boolean;
96
+ /**
97
+ * The events to use for verification
98
+ */
99
+ events?: WayfinderVerificationEventArgs | undefined;
100
+ /**
101
+ * The verification strategy to use for verifying data
102
+ */
103
+ strategy?: VerificationStrategy;
104
+ /**
105
+ * Whether verification should be strict (blocking)
106
+ * If true, verification failures will cause requests to fail
107
+ * If false, verification will be performed asynchronously with events emitted
108
+ * @default false
109
+ */
110
+ strict?: boolean;
111
+ };
112
+ /**
113
+ * The routing settings to use for routing requests
114
+ */
115
+ routingSettings?: {
116
+ /**
117
+ * The events to use for routing requests
118
+ */
119
+ events?: WayfinderRoutingEventArgs;
120
+ /**
121
+ * The routing strategy to use for routing requests
122
+ */
123
+ strategy?: RoutingStrategy;
124
+ };
125
+ }
126
+ export type DataStream = ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
127
+ export interface GatewaysProvider {
128
+ getGateways(params?: {
129
+ path?: string;
130
+ subdomain?: string;
131
+ }): Promise<URL[]>;
132
+ }
133
+ export interface RoutingStrategy {
134
+ selectGateway(params: {
135
+ gateways: URL[];
136
+ path?: string;
137
+ subdomain?: string;
138
+ }): Promise<URL>;
139
+ }
140
+ export interface VerificationStrategy {
141
+ verifyData(params: {
142
+ data: DataStream;
143
+ txId: string;
144
+ }): Promise<void>;
145
+ }
146
+ export interface DataClassifier {
147
+ classify(params: {
148
+ txId: string;
149
+ }): Promise<'ans104' | 'transaction'>;
150
+ }
151
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,EAAE,GAAG,GAAG,WAAW,EACxB,IAAI,CAAC,EAAE,WAAW,GAAG;IACnB,oBAAoB,CAAC,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IAChE,eAAe,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CACvD,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG;IAC3B,iBAAiB,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,iBAAiB,EAAE;QAAE,WAAW,EA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,WAAW,eAAe;IAC9B,aAAa,CAAC,MAAM,EAAE;QACpB,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,GAAG,aAAa,CAAC,CAAC;CACvE"}
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * WayFinder
3
+ * Copyright (C) 2022-2025 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export {};
@@ -1,5 +1,4 @@
1
- import { DataStream } from '../../types/wayfinder.js';
2
- import { Logger } from '../logger.js';
1
+ import type { DataStream, Logger } from '../types.js';
3
2
  export declare function isAsyncIterable(obj: unknown): obj is AsyncIterable<Uint8Array>;
4
3
  export declare function readableStreamToAsyncIterable(stream: ReadableStream<Uint8Array>): AsyncIterable<Uint8Array>;
5
4
  export declare function hashDataStreamToB64Url({ stream, algorithm, logger, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAiB,MAAM,cAAc,CAAC;AAGrD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,aAAa,CAAC,UAAU,CAAC,CAQlC;AAED,wBAAuB,6BAA6B,CAClD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,aAAa,CAAC,UAAU,CAAC,CAa3B;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,MAAM,EACN,SAAoB,EACpB,MAAsB,GACvB,EAAE;IACD,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA2C9B"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGtD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,GACX,GAAG,IAAI,aAAa,CAAC,UAAU,CAAC,CAQlC;AAED,wBAAuB,6BAA6B,CAClD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,aAAa,CAAC,UAAU,CAAC,CAa3B;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,MAAM,EACN,SAAoB,EACpB,MAAsB,GACvB,EAAE;IACD,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA2C9B"}
@@ -1,5 +1,4 @@
1
- import { DataClassifier, DataStream, VerificationStrategy } from '../../types/wayfinder.js';
2
- import { Logger } from '../logger.js';
1
+ import { DataClassifier, DataStream, Logger, VerificationStrategy } from '../types.js';
3
2
  export declare const convertDataStreamToDataRoot: ({ stream, }: {
4
3
  stream: DataStream;
5
4
  }) => Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"data-root-verifier.d.ts","sourceRoot":"","sources":["../../src/verification/data-root-verifier.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,cAAc,EACd,UAAU,EACV,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,MAAM,EAAiB,MAAM,cAAc,CAAC;AAOrD,eAAO,MAAM,2BAA2B,GAAU,aAE/C;IACD,MAAM,EAAE,UAAU,CAAC;CACpB,KAAG,OAAO,CAAC,MAAM,CAwDjB,CAAC;AAGF,qBAAa,4BAA6B,YAAW,oBAAoB;IACvE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAChC,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,EACtB,UAA0C,GAC3C,EAAE;QACD,eAAe,EAAE,GAAG,EAAE,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,cAAc,CAAC;KAC7B;IAOD;;;;OAIG;IACG,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAuCxD,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QACD,IAAI,EAAE,UAAU,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;CA0BlB"}
1
+ {"version":3,"file":"data-root-verifier.d.ts","sourceRoot":"","sources":["../../src/verification/data-root-verifier.ts"],"names":[],"mappings":"AA4BA,OAAO,EACL,cAAc,EACd,UAAU,EACV,MAAM,EACN,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAOrB,eAAO,MAAM,2BAA2B,GAAU,aAE/C;IACD,MAAM,EAAE,UAAU,CAAC;CACpB,KAAG,OAAO,CAAC,MAAM,CAwDjB,CAAC;AAGF,qBAAa,4BAA6B,YAAW,oBAAoB;IACvE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAChC,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,EACtB,UAA0C,GAC3C,EAAE;QACD,eAAe,EAAE,GAAG,EAAE,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,cAAc,CAAC;KAC7B;IAOD;;;;OAIG;IACG,WAAW,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAuCxD,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QACD,IAAI,EAAE,UAAU,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;CA0BlB"}
@@ -1,5 +1,4 @@
1
- import { DataStream, VerificationStrategy } from '../../types/wayfinder.js';
2
- import { Logger } from '../logger.js';
1
+ import type { DataStream, Logger, VerificationStrategy } from '../types.js';
3
2
  export declare class HashVerificationStrategy implements VerificationStrategy {
4
3
  private readonly trustedGateways;
5
4
  private readonly maxConcurrency;
@@ -1 +1 @@
1
- {"version":3,"file":"hash-verifier.d.ts","sourceRoot":"","sources":["../../src/verification/hash-verifier.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAiB,MAAM,cAAc,CAAC;AAKrD,qBAAa,wBAAyB,YAAW,oBAAoB;IACnE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBACpB,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,GACvB,EAAE;QACD,eAAe,EAAE,GAAG,EAAE,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAMD;;;;OAIG;IACG,SAAS,CAAC,EACd,IAAI,GACL,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;IAqE5C,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QACD,IAAI,EAAE,UAAU,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBlB"}
1
+ {"version":3,"file":"hash-verifier.d.ts","sourceRoot":"","sources":["../../src/verification/hash-verifier.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAK5E,qBAAa,wBAAyB,YAAW,oBAAoB;IACnE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBACpB,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,GACvB,EAAE;QACD,eAAe,EAAE,GAAG,EAAE,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAMD;;;;OAIG;IACG,SAAS,CAAC,EACd,IAAI,GACL,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,QAAQ,CAAA;KAAE,CAAC;IAqE5C,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QACD,IAAI,EAAE,UAAU,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBlB"}
@@ -1,5 +1,4 @@
1
- import { DataClassifier, DataStream, VerificationStrategy } from '../../types/wayfinder.js';
2
- import { Logger } from '../logger.js';
1
+ import type { DataClassifier, DataStream, Logger, VerificationStrategy } from '../types.js';
3
2
  /**
4
3
  * Implementation of DataVerificationStrategy that verifies data item signatures
5
4
  * using trusted gateways to provide the metadata needed for verification.
@@ -1 +1 @@
1
- {"version":3,"file":"signature-verifier.d.ts","sourceRoot":"","sources":["../../src/verification/signature-verifier.ts"],"names":[],"mappings":"AAyBA,OAAO,EACL,cAAc,EACd,UAAU,EACV,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,MAAM,EAAiB,MAAM,cAAc,CAAC;AASrD;;;GAGG;AACH,qBAAa,mCACX,YAAW,oBAAoB;IAE/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBACpB,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,GACvB,EAAE;QAAE,eAAe,EAAE,GAAG,EAAE,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAMvE;;;;;OAKG;YACW,qBAAqB;IAiH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AAE,CAAC;QACxC,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IA2DI,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAkDtD;AAED,eAAO,MAAM,+BAA+B;;;CAI3C,CAAC;AAEF,qBAAa,6BAA6B;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAC7D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2C;IACvE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAChC,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,EACtB,UAA0C,GAC3C,EAAE;QACD,eAAe,EAAE,GAAG,EAAE,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,cAAc,CAAC;KAC7B;IAaK,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAatD"}
1
+ {"version":3,"file":"signature-verifier.d.ts","sourceRoot":"","sources":["../../src/verification/signature-verifier.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,MAAM,EACN,oBAAoB,EACrB,MAAM,aAAa,CAAC;AASrB;;;GAGG;AACH,qBAAa,mCACX,YAAW,oBAAoB;IAE/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBACpB,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,GACvB,EAAE;QAAE,eAAe,EAAE,GAAG,EAAE,CAAC;QAAC,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MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QACxC,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IA2DI,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAkDtD;AAED,eAAO,MAAM,+BAA+B;;;CAI3C,CAAC;AAEF,qBAAa,6BAA6B;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAC7D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA2C;IACvE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;gBAChC,EACV,eAAe,EACf,cAAkB,EAClB,MAAsB,EACtB,UAA0C,GAC3C,EAAE;QACD,eAAe,EAAE,GAAG,EAAE,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,cAAc,CAAC;KAC7B;IAaK,UAAU,CAAC,EACf,IAAI,EACJ,IAAI,GACL,EAAE;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAatD"}
@@ -15,8 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { EventEmitter } from 'eventemitter3';
18
- import { Logger } from './logger.js';
19
- import { GatewaysProvider, RoutingStrategy, VerificationStrategy, WayfinderFetch } from '../types/wayfinder.js';
18
+ import type { GatewaysProvider, Logger, VerificationStrategy, WayfinderEvent, WayfinderEventArgs, WayfinderFetch, WayfinderOptions } from './types.js';
20
19
  export declare const arnsRegex: RegExp;
21
20
  export declare const txIdRegex: RegExp;
22
21
  /**
@@ -30,54 +29,6 @@ export declare const resolveWayfinderUrl: ({ originalUrl, selectedGateway, logge
30
29
  selectedGateway: URL;
31
30
  logger?: Logger;
32
31
  }) => URL;
33
- /**
34
- * Wayfinder event emitter with verification events
35
- */
36
- export type WayfinderEvent = {
37
- 'verification-succeeded': {
38
- txId: string;
39
- };
40
- 'verification-failed': Error;
41
- 'verification-skipped': {
42
- originalUrl: string;
43
- };
44
- 'verification-progress': {
45
- txId: string;
46
- processedBytes: number;
47
- totalBytes: number;
48
- };
49
- 'routing-started': {
50
- originalUrl: string;
51
- };
52
- 'routing-skipped': {
53
- originalUrl: string;
54
- };
55
- 'routing-succeeded': {
56
- originalUrl: string;
57
- selectedGateway: string;
58
- redirectUrl: string;
59
- };
60
- 'routing-failed': Error;
61
- 'identified-transaction-id': {
62
- originalUrl: string;
63
- selectedGateway: string;
64
- txId: string;
65
- };
66
- };
67
- export interface WayfinderRoutingEventArgs {
68
- onRoutingStarted?: (payload: WayfinderEvent['routing-started']) => void;
69
- onRoutingSkipped?: (payload: WayfinderEvent['routing-skipped']) => void;
70
- onRoutingSucceeded?: (payload: WayfinderEvent['routing-succeeded']) => void;
71
- }
72
- export interface WayfinderVerificationEventArgs {
73
- onVerificationSucceeded?: (payload: WayfinderEvent['verification-succeeded']) => void;
74
- onVerificationFailed?: (payload: WayfinderEvent['verification-failed']) => void;
75
- onVerificationProgress?: (payload: WayfinderEvent['verification-progress']) => void;
76
- }
77
- export interface WayfinderEventArgs {
78
- verification?: WayfinderVerificationEventArgs;
79
- routing?: WayfinderRoutingEventArgs;
80
- }
81
32
  export declare class WayfinderEmitter extends EventEmitter<WayfinderEvent> {
82
33
  constructor({ verification, routing }?: WayfinderEventArgs);
83
34
  }
@@ -100,65 +51,16 @@ export declare function tapAndVerifyReadableStream({ originalStream, contentLeng
100
51
  * @param resolveUrl - the function to construct the redirect url for ar:// requests
101
52
  * @returns a wrapped fetch function that supports ar:// protocol and always returns Response
102
53
  */
103
- export declare const wayfinderFetch: ({ emitter, logger, gatewaysProvider, verificationSettings, routingSettings, }: {
54
+ export declare const wayfinderFetch: ({ logger, gatewaysProvider, verificationSettings, routingSettings, emitter, }: {
104
55
  logger?: Logger;
105
- emitter?: WayfinderEmitter;
106
56
  gatewaysProvider: GatewaysProvider;
107
57
  verificationSettings: NonNullable<WayfinderOptions["verificationSettings"]>;
108
58
  routingSettings: NonNullable<WayfinderOptions["routingSettings"]>;
109
- }) => (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
110
- /**
111
- * Configuration options for the Wayfinder
112
- */
113
- export interface WayfinderOptions {
114
- /**
115
- * Logger to use for logging
116
- * @default defaultLogger (standard console logger)
117
- */
118
- logger?: Logger;
119
- /**
120
- * The gateways provider to use for routing requests.
121
- */
122
- gatewaysProvider: GatewaysProvider;
123
- /**
124
- * The verification settings to use for verifying data
125
- */
126
- verificationSettings?: {
127
- /**
128
- * Whether verification is enabled. If false, verification will be skipped for all requests. If true, strategy must be provided.
129
- * @default true
130
- */
131
- enabled?: boolean;
132
- /**
133
- * The events to use for verification
134
- */
135
- events?: WayfinderVerificationEventArgs | undefined;
136
- /**
137
- * The verification strategy to use for verifying data
138
- */
139
- strategy: VerificationStrategy;
140
- /**
141
- * Whether verification should be strict (blocking)
142
- * If true, verification failures will cause requests to fail
143
- * If false, verification will be performed asynchronously with events emitted
144
- * @default false
145
- */
146
- strict?: boolean;
147
- };
148
- /**
149
- * The routing settings to use for routing requests
150
- */
151
- routingSettings?: {
152
- /**
153
- * The events to use for routing requests
154
- */
155
- events?: WayfinderRoutingEventArgs;
156
- /**
157
- * The routing strategy to use for routing requests
158
- */
159
- strategy: RoutingStrategy;
160
- };
161
- }
59
+ emitter?: WayfinderEmitter;
60
+ }) => (input: URL | RequestInfo, init?: RequestInit & {
61
+ verificationSettings?: NonNullable<WayfinderOptions["verificationSettings"]>;
62
+ routingSettings?: NonNullable<WayfinderOptions["routingSettings"]>;
63
+ }) => Promise<Response>;
162
64
  /**
163
65
  * The main class for the wayfinder
164
66
  */
@@ -180,7 +82,7 @@ export declare class Wayfinder {
180
82
  * This includes the routing strategy and event handlers for routing events.
181
83
  * If not provided, the default FastestPingRoutingStrategy will be used.
182
84
  */
183
- readonly routingSettings: NonNullable<WayfinderOptions['routingSettings']>;
85
+ readonly routingSettings: Required<NonNullable<WayfinderOptions['routingSettings']>>;
184
86
  /**
185
87
  * The verification settings to use when verifying data.
186
88
  */
@@ -239,7 +141,13 @@ export declare class Wayfinder {
239
141
  */
240
142
  protected logger: Logger;
241
143
  /**
242
- * The event emitter for wayfinder that emits routing and verification events.
144
+ * The event emitter for wayfinder that emits routing and verification events for all requests.
145
+ *
146
+ * This is useful for tracking all requests and their statuses, and is updated for each request.
147
+ *
148
+ * If you prefer request-specific events, you can pass in the events to the `request` function.
149
+ *
150
+ * @example
243
151
  *
244
152
  * const wayfinder = new Wayfinder()
245
153
  *
@@ -266,10 +174,8 @@ export declare class Wayfinder {
266
174
  * console.log('Verification passed!', event);
267
175
  * },
268
176
  * onVerificationFailed: (event) => {
269
- * console.log('Verification failed!', event);
270
- * },
271
- * onVerificationProgress: (event) => {
272
- * console.log('Verification progress!', event);
177
+ * console.log('Verification failed!', event);
178
+ * },
273
179
  * },
274
180
  * }
275
181
  * routingSettings: {
@@ -1 +1 @@
1
- {"version":3,"file":"wayfinder.d.ts","sourceRoot":"","sources":["../src/wayfinder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AAEpD,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,cAAc,EACf,MAAM,uBAAuB,CAAC;AAM/B,eAAO,MAAM,SAAS,QAAuB,CAAC;AAC9C,eAAO,MAAM,SAAS,QAAwB,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,2CAIjC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,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
package/dist/wayfinder.js CHANGED
@@ -182,19 +182,36 @@ export function tapAndVerifyReadableStream({ originalStream, contentLength, veri
182
182
  * @param resolveUrl - the function to construct the redirect url for ar:// requests
183
183
  * @returns a wrapped fetch function that supports ar:// protocol and always returns Response
184
184
  */
185
- export const wayfinderFetch = ({ emitter = new WayfinderEmitter(), logger = defaultLogger, gatewaysProvider, verificationSettings, routingSettings, }) => {
185
+ export const wayfinderFetch = ({ logger = defaultLogger, gatewaysProvider, verificationSettings, routingSettings, emitter, }) => {
186
186
  return async (input, init) => {
187
+ const {
188
+ // allows for overriding the verification and routing settings for a single request
189
+ verificationSettings: requestVerificationSettings, routingSettings: requestRoutingSettings, ...restInit } = init ?? {};
190
+ const requestEmitter = new WayfinderEmitter({
191
+ verification: requestVerificationSettings?.events,
192
+ routing: requestRoutingSettings?.events,
193
+ });
194
+ if (emitter) {
195
+ requestEmitter.on('routing-started', (event) => {
196
+ emitter.emit('routing-started', event);
197
+ });
198
+ requestEmitter.on('routing-skipped', (event) => emitter.emit('routing-skipped', event));
199
+ requestEmitter.on('routing-succeeded', (event) => emitter.emit('routing-succeeded', event));
200
+ requestEmitter.on('verification-succeeded', (event) => emitter.emit('verification-succeeded', event));
201
+ requestEmitter.on('verification-failed', (event) => emitter.emit('verification-failed', event));
202
+ requestEmitter.on('verification-progress', (event) => emitter.emit('verification-progress', event));
203
+ }
187
204
  const url = input instanceof URL ? input.toString() : input.toString();
188
205
  if (!url.toString().startsWith('ar://')) {
189
206
  logger?.debug('URL is not a wayfinder url, skipping routing', {
190
207
  input,
191
208
  });
192
- emitter?.emit('routing-skipped', {
209
+ requestEmitter.emit('routing-skipped', {
193
210
  originalUrl: JSON.stringify(input),
194
211
  });
195
212
  return fetch(input, init);
196
213
  }
197
- emitter?.emit('routing-started', {
214
+ requestEmitter.emit('routing-started', {
198
215
  originalUrl: input.toString(),
199
216
  });
200
217
  const maxRetries = 3;
@@ -220,7 +237,7 @@ export const wayfinderFetch = ({ emitter = new WayfinderEmitter(), logger = defa
220
237
  selectedGateway,
221
238
  logger,
222
239
  });
223
- emitter?.emit('routing-succeeded', {
240
+ requestEmitter.emit('routing-succeeded', {
224
241
  originalUrl: url,
225
242
  selectedGateway: selectedGateway.toString(),
226
243
  redirectUrl: redirectUrl.toString(),
@@ -234,7 +251,7 @@ export const wayfinderFetch = ({ emitter = new WayfinderEmitter(), logger = defa
234
251
  // enforce CORS given we're likely going to a different origin, but always allow the client to override
235
252
  redirect: 'follow',
236
253
  mode: 'cors',
237
- ...init,
254
+ ...restInit,
238
255
  });
239
256
  logger?.debug(`Successfully routed request to gateway`, {
240
257
  redirectUrl: redirectUrl.toString(),
@@ -255,16 +272,11 @@ export const wayfinderFetch = ({ emitter = new WayfinderEmitter(), logger = defa
255
272
  redirectUrl: redirectUrl.toString(),
256
273
  originalUrl: url,
257
274
  });
258
- emitter?.emit('verification-skipped', {
275
+ requestEmitter.emit('verification-skipped', {
259
276
  originalUrl: url,
260
277
  });
261
278
  return response;
262
279
  }
263
- emitter?.emit('identified-transaction-id', {
264
- originalUrl: url,
265
- selectedGateway: redirectUrl.toString(),
266
- txId,
267
- });
268
280
  // Check if the response has a body
269
281
  if (response.body) {
270
282
  const newClientStream = tapAndVerifyReadableStream({
@@ -272,7 +284,7 @@ export const wayfinderFetch = ({ emitter = new WayfinderEmitter(), logger = defa
272
284
  contentLength,
273
285
  verifyData: verificationSettings.strategy?.verifyData.bind(verificationSettings.strategy),
274
286
  txId,
275
- emitter,
287
+ emitter: requestEmitter,
276
288
  strict: verificationSettings.strict,
277
289
  });
278
290
  return new Response(newClientStream, {
@@ -392,7 +404,13 @@ export class Wayfinder {
392
404
  */
393
405
  logger;
394
406
  /**
395
- * The event emitter for wayfinder that emits routing and verification events.
407
+ * The event emitter for wayfinder that emits routing and verification events for all requests.
408
+ *
409
+ * This is useful for tracking all requests and their statuses, and is updated for each request.
410
+ *
411
+ * If you prefer request-specific events, you can pass in the events to the `request` function.
412
+ *
413
+ * @example
396
414
  *
397
415
  * const wayfinder = new Wayfinder()
398
416
  *
@@ -419,10 +437,8 @@ export class Wayfinder {
419
437
  * console.log('Verification passed!', event);
420
438
  * },
421
439
  * onVerificationFailed: (event) => {
422
- * console.log('Verification failed!', event);
423
- * },
424
- * onVerificationProgress: (event) => {
425
- * console.log('Verification progress!', event);
440
+ * console.log('Verification failed!', event);
441
+ * },
426
442
  * },
427
443
  * }
428
444
  * routingSettings: {
@@ -454,10 +470,6 @@ export class Wayfinder {
454
470
  verificationSettings, routingSettings, }) {
455
471
  this.logger = logger;
456
472
  this.gatewaysProvider = gatewaysProvider;
457
- this.emitter = new WayfinderEmitter({
458
- verification: verificationSettings?.events,
459
- routing: routingSettings?.events,
460
- });
461
473
  // default verification settings
462
474
  this.verificationSettings = {
463
475
  enabled: verificationSettings?.enabled ??
@@ -465,40 +477,24 @@ export class Wayfinder {
465
477
  strategy: new HashVerificationStrategy({
466
478
  trustedGateways: [new URL('https://permagate.io')],
467
479
  }),
468
- events: {
469
- onVerificationFailed: (event) => {
470
- this.logger.error('Verification failed', event);
471
- },
472
- onVerificationSucceeded: (event) => {
473
- this.logger.info('Verification succeeded', event);
474
- },
475
- onVerificationProgress: (event) => {
476
- this.logger.info('Verification progress', event);
477
- },
478
- },
479
480
  // overwrite the default settings with the provided ones
480
481
  ...verificationSettings,
481
482
  };
482
483
  // default routing settings
483
484
  this.routingSettings = {
485
+ events: {},
484
486
  strategy: new FastestPingRoutingStrategy({
485
487
  timeoutMs: 1000,
488
+ maxConcurrency: 5, // 5 concurrent HEAD requests on the requested path
486
489
  logger: defaultLogger,
487
490
  }),
488
- events: {
489
- onRoutingStarted: (event) => {
490
- this.logger.debug('Routing started', event);
491
- },
492
- onRoutingSkipped: (event) => {
493
- this.logger.debug('Routing skipped', event);
494
- },
495
- onRoutingSucceeded: (event) => {
496
- this.logger.debug('Routing succeeded', event);
497
- },
498
- },
499
491
  // overwrite the default settings with the provided ones
500
492
  ...routingSettings,
501
493
  };
494
+ this.emitter = new WayfinderEmitter({
495
+ verification: this.verificationSettings?.events,
496
+ routing: this.routingSettings?.events,
497
+ });
502
498
  this.request = wayfinderFetch({
503
499
  logger: this.logger,
504
500
  emitter: this.emitter,
package/package.json CHANGED
@@ -1,18 +1,13 @@
1
1
  {
2
2
  "name": "@ar.io/wayfinder-core",
3
- "version": "0.0.5-alpha.2",
3
+ "version": "0.0.5-alpha.3",
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",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
9
  "license": "Apache-2.0",
10
- "keywords": [
11
- "ar-io",
12
- "arweave",
13
- "wayfinder",
14
- "ar://"
15
- ],
10
+ "keywords": ["ar-io", "arweave", "wayfinder", "ar://"],
16
11
  "author": {
17
12
  "name": "Permanent Data Solutions Inc",
18
13
  "email": "info@ar.io",
@@ -21,12 +16,7 @@
21
16
  "publishConfig": {
22
17
  "access": "public"
23
18
  },
24
- "files": [
25
- "dist",
26
- "package.json",
27
- "README.md",
28
- "LICENSE"
29
- ],
19
+ "files": ["dist", "package.json", "README.md", "LICENSE"],
30
20
  "exports": {
31
21
  ".": {
32
22
  "types": "./dist/index.d.ts",