@ar.io/wayfinder-core 0.0.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.
Files changed (51) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +318 -0
  3. package/dist/gateways/network.d.ts +39 -0
  4. package/dist/gateways/network.d.ts.map +1 -0
  5. package/dist/gateways/network.js +62 -0
  6. package/dist/gateways/simple-cache.d.ts +51 -0
  7. package/dist/gateways/simple-cache.d.ts.map +1 -0
  8. package/dist/gateways/simple-cache.js +66 -0
  9. package/dist/gateways/static.d.ts +26 -0
  10. package/dist/gateways/static.d.ts.map +1 -0
  11. package/dist/gateways/static.js +9 -0
  12. package/dist/index.d.ts +29 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +32 -0
  15. package/dist/routing/ping.d.ts +19 -0
  16. package/dist/routing/ping.d.ts.map +1 -0
  17. package/dist/routing/ping.js +77 -0
  18. package/dist/routing/preferred-with-fallback.d.ts +34 -0
  19. package/dist/routing/preferred-with-fallback.d.ts.map +1 -0
  20. package/dist/routing/preferred-with-fallback.js +41 -0
  21. package/dist/routing/random.d.ts +24 -0
  22. package/dist/routing/random.d.ts.map +1 -0
  23. package/dist/routing/random.js +9 -0
  24. package/dist/routing/round-robin.d.ts +50 -0
  25. package/dist/routing/round-robin.d.ts.map +1 -0
  26. package/dist/routing/round-robin.js +41 -0
  27. package/dist/routing/static.d.ts +49 -0
  28. package/dist/routing/static.d.ts.map +1 -0
  29. package/dist/routing/static.js +37 -0
  30. package/dist/utils/ario.d.ts +28 -0
  31. package/dist/utils/ario.d.ts.map +1 -0
  32. package/dist/utils/ario.js +27 -0
  33. package/dist/utils/base64.d.ts +21 -0
  34. package/dist/utils/base64.d.ts.map +1 -0
  35. package/dist/utils/base64.js +51 -0
  36. package/dist/utils/hash.d.ts +10 -0
  37. package/dist/utils/hash.d.ts.map +1 -0
  38. package/dist/utils/hash.js +81 -0
  39. package/dist/utils/random.d.ts +25 -0
  40. package/dist/utils/random.d.ts.map +1 -0
  41. package/dist/utils/random.js +26 -0
  42. package/dist/verification/data-root-verifier.d.ts +28 -0
  43. package/dist/verification/data-root-verifier.d.ts.map +1 -0
  44. package/dist/verification/data-root-verifier.js +129 -0
  45. package/dist/verification/hash-verifier.d.ts +28 -0
  46. package/dist/verification/hash-verifier.d.ts.map +1 -0
  47. package/dist/verification/hash-verifier.js +108 -0
  48. package/dist/wayfinder.d.ts +301 -0
  49. package/dist/wayfinder.d.ts.map +1 -0
  50. package/dist/wayfinder.js +498 -0
  51. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2024] [Permanent Data Solutions, Inc.]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,318 @@
1
+ # Wayfinder Core
2
+
3
+ `@ar.io/wayfinder` is the core library for the Wayfinder project. It provides the core functionality for routing and verifying data through the ar.io network.
4
+
5
+ ## Quick Start
6
+
7
+ ### Installation
8
+
9
+ `@ar.io/wayfinder` is currently available as a beta release. To install the latest version, run:
10
+
11
+ ```bash
12
+ npm install @ar.io/wayfinder@beta
13
+ # or
14
+ yarn add @ar.io/wayfinder@beta
15
+ ```
16
+
17
+ ### Basic Usage
18
+
19
+ ```javascript
20
+ import { Wayfinder } from '@ar.io/wayfinder-core';
21
+
22
+ // create a new Wayfinder instance with default settings
23
+ const wayfinder = new Wayfinder();
24
+
25
+ // use Wayfinder to fetch and verify data using ar:// protocol
26
+ const response = await wayfinder.request('ar://example-name');
27
+ ```
28
+
29
+ ### Custom Configuration
30
+
31
+ You can customize the wayfinder instance with different gateways, verification strategies, and routing strategies based on your use case.
32
+
33
+ Example:
34
+
35
+ > _Wayfinder client that caches the top 10 gateways by operator stake from the ARIO Network for 1 hour and uses the fastest pinging routing strategy to select the fastest gateway for requests._
36
+
37
+ ```javascript
38
+ const wayfinder = new Wayfinder({
39
+ // cache the top 10 gateways by operator stake from the ARIO Network for 1 hour
40
+ gatewaysProvider: new SimpleCacheGatewaysProvider({
41
+ ttlSeconds: 60 * 60, // cache the gateways for 1 hour
42
+ gatewaysProvider: new NetworkGatewaysProvider({
43
+ ario: ARIO.mainnet(),
44
+ sortBy: 'operatorStake',
45
+ sortOrder: 'desc',
46
+ limit: 10,
47
+ }),
48
+ }),
49
+ // use the fastest pinging strategy to select the fastest gateway for requests
50
+ routingStrategy: new FastestPingRoutingStrategy({
51
+ timeoutMs: 1000,
52
+ probePath: '/ar-io/info',
53
+ }),
54
+ // verify the data using the hash of the data against a list of trusted gateways
55
+ verificationStrategy: new HashVerificationStrategy({
56
+ trustedGateways: ['https://permagate.io'],
57
+ }),
58
+ });
59
+ ```
60
+
61
+ ## ar:// Protocol
62
+
63
+ Wayfinder supports several ar:// URL formats:
64
+
65
+ ```bash
66
+ ar://TRANSACTION_ID // Direct transaction ID
67
+ ar://NAME // ArNS name (paths supported)
68
+ ar:///info // Gateway endpoint (/info)
69
+ ```
70
+
71
+ ## Gateway Providers
72
+
73
+ Gateway providers are responsible for providing a list of gateways to Wayfinder to choose from when routing requests. By default, Wayfinder will use the `NetworkGatewaysProvider` to get a list of gateways from the ARIO Network.
74
+
75
+ ### NetworkGatewaysProvider
76
+
77
+ Returns a list of gateways from the ARIO Network based on on-chain metrics. You can specify on-chain metrics for gateways to prioritize the highest quality gateways. This is the default gateway provider and is recommended for most users.
78
+
79
+ ```javascript
80
+ // requests will be routed to one of the top 10 gateways by operator stake
81
+ const gatewayProvider = new NetworkGatewaysProvider({
82
+ ario: ARIO.mainnet(),
83
+ sortBy: 'operatorStake', // sort by operator stake | 'totalDelegatedStake'
84
+ sortOrder: 'desc', // 'asc'
85
+ limit: 10, // number of gateways to return
86
+ });
87
+ ```
88
+
89
+ ### Static Gateway Provider
90
+
91
+ The static gateway provider returns a list of gateways that you provide. This is useful for testing or for users who want to use a specific gateway for all requests.
92
+
93
+ ```javascript
94
+ const gatewayProvider = new StaticGatewaysProvider({
95
+ gateways: ['https://arweave.net'],
96
+ });
97
+ ```
98
+
99
+ ## Routing Strategies
100
+
101
+ Wayfinder supports multiple routing strategies to select target gateways for your requests.
102
+
103
+ | Strategy | Description | Use Case |
104
+ | ---------------------------- | ---------------------------------------------- | --------------------------------------- |
105
+ | `RandomRoutingStrategy` | Selects a random gateway from a list | Good for load balancing and resilience |
106
+ | `StaticRoutingStrategy` | Always uses a single gateway | When you need to use a specific gateway |
107
+ | `RoundRobinRoutingStrategy` | Selects gateways in round-robin order | Good for load balancing and resilience |
108
+ | `FastestPingRoutingStrategy` | Selects the fastest gateway based on ping time | Good for performance and latency |
109
+
110
+ ### RandomRoutingStrategy
111
+
112
+ Selects a random gateway from a list of gateways.
113
+
114
+ ```javascript
115
+ const routingStrategy = new RandomRoutingStrategy();
116
+
117
+ const gateway = await routingStrategy.selectGateway({
118
+ gateways: ['https://arweave.net', 'https://permagate.io'],
119
+ });
120
+ ```
121
+
122
+ ### StaticRoutingStrategy
123
+
124
+ ```javascript
125
+ const routingStrategy = new StaticRoutingStrategy({
126
+ gateway: 'https://arweave.net',
127
+ });
128
+
129
+ const gateway = await routingStrategy.selectGateway(); // always returns the same gateway
130
+ ```
131
+
132
+ ### RoundRobinRoutingStrategy
133
+
134
+ Selects gateways in round-robin order. The gateway list is stored in memory and is not persisted across instances.
135
+
136
+ ```javascript
137
+ const gatewayProvider = new NetworkGatewaysProvider({
138
+ ario: ARIO.mainnet(),
139
+ sortBy: 'operatorStake',
140
+ sortOrder: 'desc',
141
+ limit: 10,
142
+ });
143
+
144
+ // provide the gateways to the routing strategy on initialization to track the request count per gateway.
145
+ // Any additional gateways provided to the selectGateway method will be ignored.
146
+ const routingStrategy = new RoundRobinRoutingStrategy({
147
+ gateways: await gatewayProvider.getGateways(),
148
+ });
149
+
150
+ const gateway = await routingStrategy.selectGateway(); // returns the next gateway in the list
151
+ ```
152
+
153
+ ### FastestPingRoutingStrategy
154
+
155
+ Selects the fastest gateway based simple HEAD request to the specified route.
156
+
157
+ ```javascript
158
+ const routingStrategy = new FastestPingRoutingStrategy({
159
+ timeoutMs: 1000,
160
+ probePath: '/ar-io/info',
161
+ });
162
+
163
+ // will select the fastest gateway from the list based on the ping time of the /ar-io/info route
164
+ const gateway = await routingStrategy.selectGateway({
165
+ gateways: ['https://slow.net', 'https://medium.net', 'https://fast.net'],
166
+ });
167
+ ```
168
+
169
+ ## Verification Strategies
170
+
171
+ Wayfinder includes verification mechanisms to ensure the integrity of retrieved data. Verification strategies offer different trade-offs between complexity, performance, and security.
172
+
173
+ | Verifier | Complexity | Performance | Security | Description |
174
+ | ------------------------------- | ---------- | ----------- | -------- | ------------------------------------------------------------------------------------------------------------ |
175
+ | `HashVerificationStrategy` | Low | High | Low | Verifies data integrity using SHA-256 hash comparison of the returned data |
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 offsets provided by trusted gateway |
178
+
179
+ ### HashVerificationStrategy
180
+
181
+ Verifies data integrity using SHA-256 hash comparison. This is the default verification strategy and is recommended for most users looking for a balance between security and performance.
182
+
183
+ ```javascript
184
+ import { Wayfinder, HashVerificationStrategy } from '@ar.io/wayfinder-core';
185
+
186
+ const wayfinder = new Wayfinder({
187
+ verificationStrategy: new HashVerificationStrategy({
188
+ trustedGateways: ['https://permagate.io'],
189
+ }),
190
+ });
191
+ ```
192
+
193
+ ### DataRootVerificationStrategy
194
+
195
+ Verifies data integrity using Arweave by computing the data root for the transaction. This is useful for L1 transactions and is recommended for users who want to ensure the integrity of their data.
196
+
197
+ ```javascript
198
+ import { Wayfinder, DataRootVerificationStrategy } from '@ar.io/wayfinder-core';
199
+
200
+ const wayfinder = new Wayfinder({
201
+ verificationStrategy: new DataRootVerificationStrategy({
202
+ trustedGateways: ['https://permagate.io'],
203
+ }),
204
+ });
205
+ ```
206
+
207
+ ## Monitoring and Events
208
+
209
+ Wayfinder emits events during the routing and verification process, allowing you to monitor its operation.
210
+
211
+ ```javascript
212
+ const wayfinder = new Wayfinder({
213
+ events: {
214
+ onVerificationPassed: (event) => {
215
+ console.log(`Verification passed for transaction: ${event.txId}`);
216
+ },
217
+ onVerificationFailed: (event) => {
218
+ console.error(
219
+ `Verification failed for transaction: ${event.txId}`,
220
+ event.error,
221
+ );
222
+ },
223
+ onVerificationProgress: (event) => {
224
+ const percentage = (event.processedBytes / event.totalBytes) * 100;
225
+ console.log(
226
+ `Verification progress for ${event.txId}: ${percentage.toFixed(2)}%`,
227
+ );
228
+ },
229
+ },
230
+ });
231
+
232
+ // Or use the event emitter directly
233
+ wayfinder.emitter.on('routing-succeeded', (event) => {
234
+ console.log(`Request routed to: ${event.targetGateway}`);
235
+ });
236
+
237
+ wayfinder.emitter.on('routing-failed', (event) => {
238
+ console.error(`Routing failed: ${event.error.message}`);
239
+ });
240
+ ```
241
+
242
+ ## Advanced Usage
243
+
244
+ ### Custom URL Resolution
245
+
246
+ ```javascript
247
+ // Get the resolved URL without making a request
248
+ const redirectUrl = await wayfinder.resolveUrl({
249
+ originalUrl: 'ar://example-name',
250
+ });
251
+ console.log(`This request would be routed to: ${redirectUrl}`);
252
+ ```
253
+
254
+ ### Using With Different HTTP Clients
255
+
256
+ By default, Wayfinder uses native `fetch` for HTTP requests. You can also use other HTTP clients like `axios` or `node-fetch`. When making a request, Wayfinder will use the HTTP client you provide and any additional configuration you provide.
257
+
258
+ ```javascript
259
+ import axios from 'axios';
260
+
261
+ // create a custom axios instance
262
+ const axios = axios.create({
263
+ timeout: 10000,
264
+ });
265
+ const wayfinderAxios = new Wayfinder({ httpClient: axios });
266
+
267
+ // add custom headers on the request
268
+ const response = await wayfinderAxios.request('ar://example', {
269
+ headers: {
270
+ 'X-Custom-Header': 'test',
271
+ },
272
+ });
273
+ ```
274
+
275
+ ## Request Flow
276
+
277
+ The following sequence diagram illustrates how Wayfinder processes requests:
278
+
279
+ ```mermaid
280
+ sequenceDiagram
281
+ participant Client
282
+ participant Wayfinder
283
+ participant Gateways Provider
284
+ participant Routing Strategy
285
+ participant Selected Gateway
286
+ participant Verification Strategy
287
+ participant Trusted Gateways
288
+
289
+ Client->>Wayfinder: request('ar://example')
290
+ activate Wayfinder
291
+
292
+ Wayfinder->>+Gateways Provider: getGateways()
293
+ Gateways Provider-->>-Wayfinder: List of gateway URLs
294
+
295
+ Wayfinder->>+Routing Strategy: selectGateway() from list of gateways
296
+ Routing Strategy-->>-Wayfinder: Select gateway for request
297
+
298
+ Wayfinder->>+Selected Gateway: Send HTTP request to target gateway
299
+ Selected Gateway-->>-Wayfinder: Response with data & txId
300
+
301
+ activate Verification Strategy
302
+ Wayfinder->>+Verification Strategy: verifyData(responseData, txId)
303
+ Verification Strategy->>Wayfinder: Emit 'verification-progress' events
304
+ Verification Strategy->>Trusted Gateways: Request verification headers
305
+ Trusted Gateways-->>Verification Strategy: Return verification headers
306
+ Verification Strategy->>Verification Strategy: Compare computed vs trusted data
307
+ Verification Strategy-->>-Wayfinder: Return request data with verification result
308
+
309
+ alt Verification passed
310
+ Wayfinder->>Wayfinder: Emit 'verification-passed' event
311
+ Wayfinder-->>Client: Return verified response
312
+ else Verification failed
313
+ Wayfinder->>Wayfinder: Emit 'verification-failed' event
314
+ Wayfinder-->>Client: Throw verification error
315
+ end
316
+
317
+ deactivate Wayfinder
318
+ ```
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WayFinder
3
+ * Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { ARIOReadable } from '@ar.io/sdk';
19
+ import { GatewaysProvider } from '../../types/wayfinder.js';
20
+ import { Logger } from '../wayfinder.js';
21
+ export declare class NetworkGatewaysProvider implements GatewaysProvider {
22
+ private ario;
23
+ private sortBy;
24
+ private sortOrder;
25
+ private limit;
26
+ private filter;
27
+ private logger;
28
+ constructor({ ario, sortBy, sortOrder, limit, filter, logger, }: {
29
+ ario: ARIOReadable;
30
+ sortBy?: 'totalDelegatedStake' | 'operatorStake' | 'startTimestamp';
31
+ sortOrder?: 'asc' | 'desc';
32
+ limit?: number;
33
+ blocklist?: string[];
34
+ filter?: (gateway: any) => boolean;
35
+ logger?: Logger;
36
+ });
37
+ getGateways(): Promise<URL[]>;
38
+ }
39
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/gateways/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;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;CA0DpC"}
@@ -0,0 +1,62 @@
1
+ import { defaultLogger } from '../wayfinder.js';
2
+ export class NetworkGatewaysProvider {
3
+ ario;
4
+ sortBy;
5
+ sortOrder;
6
+ limit;
7
+ filter;
8
+ logger;
9
+ constructor({ ario, sortBy = 'operatorStake', sortOrder = 'desc', limit = 1000, filter = (g) => g.status === 'joined', logger = defaultLogger, }) {
10
+ this.ario = ario;
11
+ this.sortBy = sortBy;
12
+ this.sortOrder = sortOrder;
13
+ this.limit = limit;
14
+ this.filter = filter;
15
+ this.logger = logger;
16
+ }
17
+ async getGateways() {
18
+ let cursor;
19
+ let attempts = 0;
20
+ const gateways = [];
21
+ this.logger.debug('Starting to fetch gateways from AR.IO network', {
22
+ sortBy: this.sortBy,
23
+ sortOrder: this.sortOrder,
24
+ limit: this.limit,
25
+ });
26
+ do {
27
+ try {
28
+ this.logger.debug('Fetching gateways batch', { cursor, attempts });
29
+ const { items: newGateways = [], nextCursor } = await this.ario.getGateways({
30
+ limit: 1000,
31
+ cursor,
32
+ sortBy: this.sortBy,
33
+ sortOrder: this.sortOrder,
34
+ });
35
+ gateways.push(...newGateways);
36
+ cursor = nextCursor;
37
+ attempts = 0; // reset attempts if we get a new cursor
38
+ this.logger.debug('Fetched gateways batch', {
39
+ batchSize: newGateways.length,
40
+ totalFetched: gateways.length,
41
+ nextCursor: cursor,
42
+ });
43
+ }
44
+ catch (error) {
45
+ this.logger.error('Error fetching gateways', {
46
+ cursor,
47
+ attempts,
48
+ error: error.message,
49
+ stack: error.stack,
50
+ });
51
+ attempts++;
52
+ }
53
+ } while (cursor !== undefined && attempts < 3);
54
+ // filter out any gateways that are not joined
55
+ const filteredGateways = gateways.filter(this.filter).slice(0, this.limit);
56
+ this.logger.debug('Finished fetching gateways', {
57
+ totalFetched: gateways.length,
58
+ filteredCount: filteredGateways.length,
59
+ });
60
+ return filteredGateways.map((g) => new URL(`${g.settings.protocol}://${g.settings.fqdn}:${g.settings.port}`));
61
+ }
62
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * WayFinder
3
+ * Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ import { GatewaysProvider } from '../../types/wayfinder.js';
19
+ /**
20
+ * WayFinder
21
+ * Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
22
+ *
23
+ * This program is free software: you can redistribute it and/or modify
24
+ * it under the terms of the GNU Affero General Public License as published by
25
+ * the Free Software Foundation, either version 3 of the License, or
26
+ * (at your option) any later version.
27
+ *
28
+ * This program is distributed in the hope that it will be useful,
29
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
+ * GNU Affero General Public License for more details.
32
+ *
33
+ * You should have received a copy of the GNU Affero General Public License
34
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
35
+ */
36
+ import { Logger } from '../wayfinder.js';
37
+ export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
38
+ private gatewaysProvider;
39
+ private ttlSeconds;
40
+ private lastUpdated;
41
+ private gatewaysCache;
42
+ private logger;
43
+ constructor({ gatewaysProvider, ttlSeconds, // 1 hour
44
+ logger, }: {
45
+ gatewaysProvider: GatewaysProvider;
46
+ ttlSeconds?: number;
47
+ logger?: Logger;
48
+ });
49
+ getGateways(): Promise<URL[]>;
50
+ }
51
+ //# sourceMappingURL=simple-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-cache.d.ts","sourceRoot":"","sources":["../../src/gateways/simple-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;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;CAmCpC"}