@ar.io/sdk 3.11.0-beta.1 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/bundles/web.bundle.min.js +111 -114
  2. package/lib/cjs/common/ant-versions.js +3 -2
  3. package/lib/cjs/common/index.js +0 -2
  4. package/lib/cjs/common/io.js +13 -9
  5. package/lib/cjs/common/turbo.js +1 -1
  6. package/lib/cjs/types/index.js +0 -1
  7. package/lib/cjs/utils/ao.js +2 -1
  8. package/lib/cjs/version.js +1 -1
  9. package/lib/esm/common/ant-versions.js +3 -2
  10. package/lib/esm/common/index.js +0 -2
  11. package/lib/esm/common/io.js +13 -9
  12. package/lib/esm/common/turbo.js +1 -1
  13. package/lib/esm/types/index.js +0 -1
  14. package/lib/esm/utils/ao.js +2 -1
  15. package/lib/esm/version.js +1 -1
  16. package/lib/types/common/ant-versions.d.ts +3 -5
  17. package/lib/types/common/index.d.ts +0 -1
  18. package/lib/types/types/index.d.ts +0 -1
  19. package/lib/types/version.d.ts +1 -1
  20. package/package.json +1 -1
  21. package/lib/cjs/common/wayfinder/gateways/network.js +0 -48
  22. package/lib/cjs/common/wayfinder/gateways/simple-cache.js +0 -35
  23. package/lib/cjs/common/wayfinder/gateways/static.js +0 -13
  24. package/lib/cjs/common/wayfinder/index.js +0 -47
  25. package/lib/cjs/common/wayfinder/routing/strategies/ping.js +0 -72
  26. package/lib/cjs/common/wayfinder/routing/strategies/ping.test.js +0 -156
  27. package/lib/cjs/common/wayfinder/routing/strategies/random.js +0 -13
  28. package/lib/cjs/common/wayfinder/routing/strategies/random.test.js +0 -68
  29. package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +0 -42
  30. package/lib/cjs/common/wayfinder/routing/strategies/round-robin.test.js +0 -78
  31. package/lib/cjs/common/wayfinder/routing/strategies/static.js +0 -29
  32. package/lib/cjs/common/wayfinder/routing/strategies/static.test.js +0 -40
  33. package/lib/cjs/common/wayfinder/verification/strategies/data-root-verifier.js +0 -139
  34. package/lib/cjs/common/wayfinder/verification/strategies/hash-verifier.js +0 -50
  35. package/lib/cjs/common/wayfinder/verification/trusted.js +0 -106
  36. package/lib/cjs/common/wayfinder/wayfinder.js +0 -736
  37. package/lib/cjs/common/wayfinder/wayfinder.test.js +0 -519
  38. package/lib/cjs/types/wayfinder.js +0 -3
  39. package/lib/esm/common/wayfinder/gateways/network.js +0 -44
  40. package/lib/esm/common/wayfinder/gateways/simple-cache.js +0 -31
  41. package/lib/esm/common/wayfinder/gateways/static.js +0 -9
  42. package/lib/esm/common/wayfinder/index.js +0 -31
  43. package/lib/esm/common/wayfinder/routing/strategies/ping.js +0 -68
  44. package/lib/esm/common/wayfinder/routing/strategies/ping.test.js +0 -151
  45. package/lib/esm/common/wayfinder/routing/strategies/random.js +0 -9
  46. package/lib/esm/common/wayfinder/routing/strategies/random.test.js +0 -63
  47. package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +0 -38
  48. package/lib/esm/common/wayfinder/routing/strategies/round-robin.test.js +0 -73
  49. package/lib/esm/common/wayfinder/routing/strategies/static.js +0 -25
  50. package/lib/esm/common/wayfinder/routing/strategies/static.test.js +0 -35
  51. package/lib/esm/common/wayfinder/verification/strategies/data-root-verifier.js +0 -130
  52. package/lib/esm/common/wayfinder/verification/strategies/hash-verifier.js +0 -46
  53. package/lib/esm/common/wayfinder/verification/trusted.js +0 -102
  54. package/lib/esm/common/wayfinder/wayfinder.js +0 -724
  55. package/lib/esm/common/wayfinder/wayfinder.test.js +0 -514
  56. package/lib/esm/types/wayfinder.js +0 -2
  57. package/lib/types/common/wayfinder/gateways/network.d.ts +0 -33
  58. package/lib/types/common/wayfinder/gateways/simple-cache.d.ts +0 -31
  59. package/lib/types/common/wayfinder/gateways/static.d.ts +0 -23
  60. package/lib/types/common/wayfinder/index.d.ts +0 -26
  61. package/lib/types/common/wayfinder/routing/strategies/ping.d.ts +0 -27
  62. package/lib/types/common/wayfinder/routing/strategies/ping.test.d.ts +0 -1
  63. package/lib/types/common/wayfinder/routing/strategies/random.d.ts +0 -21
  64. package/lib/types/common/wayfinder/routing/strategies/random.test.d.ts +0 -1
  65. package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +0 -29
  66. package/lib/types/common/wayfinder/routing/strategies/round-robin.test.d.ts +0 -1
  67. package/lib/types/common/wayfinder/routing/strategies/static.d.ts +0 -29
  68. package/lib/types/common/wayfinder/routing/strategies/static.test.d.ts +0 -1
  69. package/lib/types/common/wayfinder/verification/strategies/data-root-verifier.d.ts +0 -31
  70. package/lib/types/common/wayfinder/verification/strategies/hash-verifier.d.ts +0 -27
  71. package/lib/types/common/wayfinder/verification/trusted.d.ts +0 -51
  72. package/lib/types/common/wayfinder/wayfinder.d.ts +0 -299
  73. package/lib/types/common/wayfinder/wayfinder.test.d.ts +0 -1
  74. package/lib/types/types/wayfinder.d.ts +0 -66
@@ -1,514 +0,0 @@
1
- import axios from 'axios';
2
- import got from 'got';
3
- import assert from 'node:assert';
4
- import { EventEmitter } from 'node:events';
5
- import { Readable } from 'node:stream';
6
- import { buffer } from 'node:stream/consumers';
7
- import { before, describe, it } from 'node:test';
8
- import { Logger } from '../../common/logger.js';
9
- import { RandomRoutingStrategy } from './routing/strategies/random.js';
10
- import { StaticRoutingStrategy } from './routing/strategies/static.js';
11
- import { Wayfinder, tapAndVerifyStream } from './wayfinder.js';
12
- // TODO: replace with locally running gateway
13
- const gatewayUrl = 'permagate.io';
14
- const stubbedGatewaysProvider = {
15
- getGateways: async () => [new URL(`http://${gatewayUrl}`)],
16
- };
17
- Logger.default.setLogLevel('none');
18
- describe('Wayfinder', () => {
19
- describe('http wrapper', () => {
20
- describe('fetch', () => {
21
- let wayfinder;
22
- before(() => {
23
- wayfinder = new Wayfinder({
24
- httpClient: fetch,
25
- routingStrategy: new RandomRoutingStrategy(),
26
- gatewaysProvider: stubbedGatewaysProvider,
27
- });
28
- });
29
- it('should fetch the data using the selected gateway', async () => {
30
- const nativeFetch = await fetch(`https://ao.${gatewayUrl}`);
31
- const response = await wayfinder.request('ar://ao');
32
- assert.strictEqual(response.status, 200);
33
- assert.strictEqual(response.status, nativeFetch.status);
34
- // assert the arns headers are the same
35
- const arnsHeaders = Array.from(response.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
36
- const nativeFetchHeaders = Array.from(nativeFetch.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
37
- assert.deepStrictEqual(arnsHeaders, nativeFetchHeaders);
38
- });
39
- it('should fetch a tx id using the selected gateway', async () => {
40
- const nativeFetch = await fetch(`https://${gatewayUrl}/KKmRbIfrc7wiLcG0zvY1etlO0NBx1926dSCksxCIN3A`,
41
- // follow redirects
42
- { redirect: 'follow' });
43
- const response = await wayfinder.request('ar://KKmRbIfrc7wiLcG0zvY1etlO0NBx1926dSCksxCIN3A', { redirect: 'follow' });
44
- assert.strictEqual(response.status, 200);
45
- assert.strictEqual(response.status, nativeFetch.status);
46
- });
47
- it('should route a non-ar:// url as a normal fetch', async () => {
48
- const [nativeFetch, response] = await Promise.all([
49
- fetch(`https://${gatewayUrl}/`, {
50
- method: 'HEAD',
51
- redirect: 'follow',
52
- }),
53
- wayfinder.request(`https://${gatewayUrl}/`, {
54
- method: 'HEAD',
55
- redirect: 'follow',
56
- }),
57
- ]);
58
- assert.strictEqual(response.status, 200);
59
- assert.strictEqual(response.status, nativeFetch.status);
60
- // TODO: ensure the headers are the same excluding unique headers
61
- });
62
- for (const api of ['/info', '/block/current']) {
63
- it.skip(`supports native arweave node apis ${api}`, async () => {
64
- const [nativeFetch, response] = await Promise.all([
65
- fetch(`https://${gatewayUrl}${api}`, {
66
- redirect: 'follow',
67
- }),
68
- wayfinder.request(`ar://${api}`, {
69
- redirect: 'follow',
70
- }),
71
- ]);
72
- assert.strictEqual(response.status, 200);
73
- assert.strictEqual(response.status, nativeFetch.status);
74
- // TODO: ensure the headers are the same excluding unique headers
75
- });
76
- }
77
- for (const api of ['/ar-io/info']) {
78
- it(`supports native ario node gateway apis ${api}`, async () => {
79
- const [nativeFetch, response] = await Promise.all([
80
- fetch(`https://${gatewayUrl}${api}`),
81
- wayfinder.request(`ar:///${api}`),
82
- ]);
83
- assert.strictEqual(response.status, 200);
84
- assert.strictEqual(response.status, nativeFetch.status);
85
- // TODO: ensure the headers are the same excluding unique headers
86
- });
87
- }
88
- it('supports a post request to graphql', async () => {
89
- const response = await wayfinder.request('ar:///graphql', {
90
- method: 'POST',
91
- redirect: 'follow',
92
- headers: {
93
- 'Content-Type': 'application/json',
94
- },
95
- body: JSON.stringify({
96
- query: `
97
- query {
98
- transactions(
99
- ids: ["xf958qhCNGfDme1FtoiD6DtMfDENDbtxZpjOM_1tsMM"]
100
- ) {
101
- edges {
102
- cursor
103
- node {
104
- id
105
- tags {
106
- name
107
- value
108
- }
109
- block {
110
- height
111
- timestamp
112
- }
113
- }
114
- }
115
- pageInfo {
116
- hasNextPage
117
- }
118
- }
119
- }
120
- `,
121
- }),
122
- });
123
- assert.strictEqual(response.status, 200);
124
- });
125
- it('returns the error from the target gateway if the route is not found', async () => {
126
- const [nativeFetch, response] = await Promise.all([
127
- fetch(`https://${gatewayUrl}/ar-io/not-found`, {
128
- redirect: 'follow',
129
- }),
130
- wayfinder.request('ar:///ar-io/not-found', {
131
- redirect: 'follow',
132
- }),
133
- ]);
134
- assert.strictEqual(response.status, nativeFetch.status);
135
- assert.strictEqual(response.statusText, nativeFetch.statusText);
136
- });
137
- });
138
- describe('axios', () => {
139
- let wayfinder;
140
- before(() => {
141
- wayfinder = new Wayfinder({
142
- httpClient: axios,
143
- routingStrategy: new RandomRoutingStrategy(),
144
- gatewaysProvider: stubbedGatewaysProvider,
145
- });
146
- });
147
- it('should fetch the data using axios default function against the target gateway', async () => {
148
- const [nativeAxios, response] = await Promise.all([
149
- axios(`https://ao.${gatewayUrl}`),
150
- wayfinder.request('ar://ao', {
151
- maxRedirects: 5,
152
- }),
153
- ]);
154
- assert.strictEqual(response.status, nativeAxios.status);
155
- // assert the arns headers are the same
156
- const arnsHeaders = Object.entries(response.headers)
157
- .sort()
158
- .filter(([key]) => key.startsWith('x-arns-'));
159
- const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
160
- assert.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
161
- });
162
- it('should fetch the data using the axios.get method against the target gateway', async () => {
163
- const [nativeAxios, response] = await Promise.all([
164
- axios.get(`https://ao.${gatewayUrl}`),
165
- wayfinder.request.get('ar://ao'),
166
- ]);
167
- assert.strictEqual(response.status, nativeAxios.status);
168
- // assert the arns headers are the same
169
- const arnsHeaders = Object.entries(response.headers)
170
- .sort()
171
- .filter(([key]) => key.startsWith('x-arns-'));
172
- const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
173
- assert.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
174
- });
175
- it('should route a non-ar:// url as a normal axios request', async () => {
176
- const [nativeAxios, response] = await Promise.all([
177
- axios(`https://${gatewayUrl}/`),
178
- wayfinder.request(`https://${gatewayUrl}/`),
179
- ]);
180
- assert.strictEqual(response.status, 200);
181
- assert.strictEqual(response.status, nativeAxios.status);
182
- // TODO: ensure the headers are the same excluding unique headers
183
- });
184
- for (const api of ['/info', '/block/current']) {
185
- it.skip(`supports native arweave node apis ${api}`, async () => {
186
- const [nativeAxios, response] = await Promise.all([
187
- axios(`https://${gatewayUrl}${api}`),
188
- wayfinder.request(`ar://${api}`),
189
- ]);
190
- assert.strictEqual(response.status, 200);
191
- assert.strictEqual(response.status, nativeAxios.status);
192
- // TODO: ensure the headers are the same excluding unique headers
193
- });
194
- }
195
- for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
196
- it(`supports native ario node gateway apis ${api}`, async () => {
197
- const [nativeAxios, response] = await Promise.all([
198
- axios(`https://${gatewayUrl}${api}`),
199
- wayfinder.request(`ar://${api}`),
200
- ]);
201
- assert.strictEqual(response.status, 200);
202
- assert.strictEqual(response.status, nativeAxios.status);
203
- // TODO: ensure the headers are the same excluding unique headers
204
- });
205
- }
206
- it('should return the error from the target gateway if the route is not found', async () => {
207
- const axiosInstance = axios.create({
208
- validateStatus: () => true, // don't throw so we can compare axios result with wrapped axios result
209
- });
210
- const wayfinder = new Wayfinder({
211
- httpClient: axiosInstance,
212
- routingStrategy: new RandomRoutingStrategy(),
213
- });
214
- const [nativeAxios, response] = await Promise.all([
215
- axiosInstance(`https://${gatewayUrl}/ar-io/not-found`),
216
- wayfinder.request('ar:///ar-io/not-found'),
217
- ]);
218
- assert.strictEqual(response.status, nativeAxios.status);
219
- });
220
- });
221
- describe('got', () => {
222
- let wayfinder;
223
- before(() => {
224
- wayfinder = new Wayfinder({
225
- httpClient: got,
226
- routingStrategy: new RandomRoutingStrategy(),
227
- gatewaysProvider: stubbedGatewaysProvider,
228
- });
229
- });
230
- it('should fetch the data using the got default function against the target gateway', async () => {
231
- const [nativeGot, response] = await Promise.all([
232
- got(`https://ao.${gatewayUrl}`),
233
- wayfinder.request('ar://ao'),
234
- ]);
235
- assert.strictEqual(response.statusCode, nativeGot.statusCode);
236
- assert.deepStrictEqual(response.body, nativeGot.body);
237
- });
238
- it('should stream the data using got.stream against the selected target gateway', async () => {
239
- const nativeBuffer = await buffer(await got.stream(`https://ao.${gatewayUrl}`, {
240
- decompress: false,
241
- followRedirect: true,
242
- }));
243
- const wayfinderBuffer = await buffer(await wayfinder.request.stream('ar://ao', {
244
- decompress: false,
245
- followRedirect: true,
246
- }));
247
- assert.deepStrictEqual(wayfinderBuffer, nativeBuffer);
248
- });
249
- });
250
- });
251
- describe('events', () => {
252
- it('should emit events on the wayfinder event emitter', async () => {
253
- const wayfinder = new Wayfinder({
254
- httpClient: fetch,
255
- routingStrategy: new StaticRoutingStrategy({
256
- gateway: `http://${gatewayUrl}`,
257
- }),
258
- verificationStrategy: {
259
- // @ts-expect-error
260
- verifyData: async (params) => {
261
- return;
262
- },
263
- },
264
- });
265
- const events = [];
266
- wayfinder.emitter.on('verification-failed', (event) => {
267
- events.push({ type: 'verification-failed', ...event });
268
- });
269
- wayfinder.emitter.on('verification-progress', (event) => {
270
- events.push({ type: 'verification-progress', ...event });
271
- });
272
- wayfinder.emitter.on('verification-succeeded', (event) => {
273
- events.push({ type: 'verification-succeeded', ...event });
274
- });
275
- // request data and assert the event is emitted
276
- const response = await wayfinder.request('ar://c7wkwt6TKgcWJUfgvpJ5q5qi4DIZyJ1_TqhjXgURh0U', {
277
- redirect: 'follow',
278
- });
279
- // read the full response body to ensure the stream is fully consumed
280
- await response.text();
281
- assert.strictEqual(response.status, 200);
282
- assert.ok(events.find((e) => e.type === 'verification-succeeded'), 'Should emit at least one verification-succeeded');
283
- });
284
- it('should execute callbacks provided to the wayfinder constructor', async () => {
285
- let verificationFailed = false;
286
- let verificationProgress = false;
287
- let verificationPassed = false;
288
- const wayfinder = new Wayfinder({
289
- httpClient: fetch,
290
- routingStrategy: new StaticRoutingStrategy({
291
- gateway: `http://${gatewayUrl}`,
292
- }),
293
- events: {
294
- onVerificationFailed: () => {
295
- verificationFailed = true;
296
- },
297
- onVerificationProgress: () => {
298
- verificationProgress = true;
299
- },
300
- onVerificationPassed: () => {
301
- verificationPassed = true;
302
- },
303
- },
304
- strict: true,
305
- });
306
- const response = await wayfinder.request('ar://c7wkwt6TKgcWJUfgvpJ5q5qi4DIZyJ1_TqhjXgURh0U', {
307
- redirect: 'follow',
308
- });
309
- // read the full response body to ensure the stream is fully consumed
310
- await response.text();
311
- assert.strictEqual(response.status, 200);
312
- assert.ok(verificationFailed === false, 'Should not emit verification-failed');
313
- assert.ok(verificationProgress, 'Should emit verification-progress');
314
- assert.ok(verificationPassed, 'Should emit verification-succeeded');
315
- });
316
- });
317
- describe('tapAndVerifyRequest', () => {
318
- describe('Readable', () => {
319
- describe('strict mode enabled', () => {
320
- it('should duplicate the stream, verify the first and return the second if verification passes', async () => {
321
- // create a simple readable
322
- const chunks = [
323
- Buffer.from('foo'),
324
- Buffer.from('bar'),
325
- Buffer.from('baz'),
326
- ];
327
- const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
328
- // a stream that will emit chunks
329
- const originalStream = Readable.from(chunks);
330
- let seen = Buffer.alloc(0);
331
- const verifyData = async ({ data,
332
- // @ts-expect-error
333
- txId, }) => {
334
- return new Promise((resolve, reject) => {
335
- data.on('data', (chunk) => {
336
- seen = Buffer.concat([seen, chunk]);
337
- });
338
- data.on('end', () => {
339
- // Should have seen exactly the full payload
340
- assert.strictEqual(seen.length, contentLength);
341
- resolve();
342
- });
343
- data.on('error', reject);
344
- });
345
- };
346
- const txId = 'test-tx-1';
347
- const emitter = new EventEmitter();
348
- const events = [];
349
- emitter.on('verification-progress', (e) => {
350
- events.push({ type: 'verification-progress', ...e });
351
- });
352
- emitter.on('verification-succeeded', (e) => events.push({ type: 'verification-succeeded', ...e }));
353
- // tap with verification
354
- const tapped = tapAndVerifyStream({
355
- originalStream,
356
- contentLength,
357
- verifyData,
358
- txId,
359
- emitter,
360
- strict: true,
361
- });
362
- // read the stream
363
- const out = [];
364
- for await (const chunk of tapped) {
365
- out.push(chunk);
366
- }
367
- // assert the stream is the same
368
- assert.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
369
- assert.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
370
- assert.ok(events.find((e) => e.type === 'verification-succeeded' && e.txId === txId), 'Should emit at least one verification-succeeded');
371
- });
372
- it('should throw an error on the client stream if verification fails', async () => {
373
- const chunks = [
374
- Buffer.from('foo'),
375
- Buffer.from('bar'),
376
- Buffer.from('baz'),
377
- ];
378
- const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
379
- // a stream that will emit chunks
380
- const originalStream = Readable.from(chunks);
381
- const verifyData = async ({
382
- // @ts-expect-error
383
- data, txId, }) => {
384
- throw new Error('Verification failed for txId: ' + txId);
385
- };
386
- const txId = 'test-tx-1';
387
- const emitter = new EventEmitter();
388
- const events = [];
389
- emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
390
- emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
391
- // tap with verification (using strict mode)
392
- const tapped = tapAndVerifyStream({
393
- originalStream,
394
- contentLength,
395
- verifyData,
396
- txId,
397
- emitter,
398
- strict: true,
399
- });
400
- // read the stream
401
- try {
402
- const out = [];
403
- for await (const chunk of tapped) {
404
- out.push(chunk);
405
- }
406
- }
407
- catch (error) {
408
- assert.ok(events.find((e) => e.type === 'verification-failed' && e.txId === txId), 'Should emit at least one verification-failed');
409
- // stream should be closed
410
- assert.ok(tapped.closed);
411
- }
412
- });
413
- });
414
- });
415
- describe('ReadableStream', () => {
416
- describe('strict mode enabled', () => {
417
- it('should duplicate the ReadableStream, verify the first and return the second if verification passes', async () => {
418
- // create a simple readable
419
- const chunks = [
420
- Buffer.from('foo'),
421
- Buffer.from('bar'),
422
- Buffer.from('baz'),
423
- ];
424
- const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
425
- // a stream that will emit chunks
426
- const originalStream = ReadableStream.from(chunks);
427
- let seen = Buffer.alloc(0);
428
- const verifyData = async ({ data,
429
- // @ts-expect-error
430
- txId, }) => {
431
- return new Promise(async (resolve, reject) => {
432
- const reader = data.getReader();
433
- while (true) {
434
- try {
435
- const { done, value } = await reader.read();
436
- if (done) {
437
- resolve();
438
- break;
439
- }
440
- seen = Buffer.concat([seen, value]);
441
- }
442
- catch (error) {
443
- reject(error);
444
- }
445
- }
446
- });
447
- };
448
- const txId = 'test-tx-1';
449
- const emitter = new EventEmitter();
450
- const events = [];
451
- emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
452
- emitter.on('verification-succeeded', (e) => events.push({ type: 'verification-succeeded', ...e }));
453
- // tap with verification
454
- const tapped = tapAndVerifyStream({
455
- originalStream,
456
- contentLength,
457
- verifyData,
458
- txId,
459
- emitter,
460
- strict: true,
461
- });
462
- // read the stream
463
- const out = [];
464
- for await (const chunk of tapped) {
465
- out.push(chunk);
466
- }
467
- // assert the stream is the same
468
- assert.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
469
- assert.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
470
- assert.ok(events.find((e) => e.type === 'verification-succeeded' && e.txId === txId), 'Should emit at least one verification-succeeded');
471
- });
472
- it('should throw an error on the client stream if verification fails', async () => {
473
- const chunks = [
474
- Buffer.from('foo'),
475
- Buffer.from('bar'),
476
- Buffer.from('baz'),
477
- ];
478
- const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
479
- // a stream that will emit chunks
480
- const originalStream = ReadableStream.from(chunks);
481
- const verifyData = async ({
482
- // @ts-expect-error
483
- data, txId, }) => {
484
- throw new Error('Verification failed for txId: ' + txId);
485
- };
486
- const txId = 'test-tx-1';
487
- const emitter = new EventEmitter();
488
- const events = [];
489
- emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
490
- emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
491
- // tap with verification (using strict mode)
492
- const tapped = tapAndVerifyStream({
493
- originalStream,
494
- contentLength,
495
- verifyData,
496
- txId,
497
- emitter,
498
- strict: true,
499
- });
500
- // read the stream
501
- try {
502
- const out = [];
503
- for await (const chunk of tapped) {
504
- out.push(chunk);
505
- }
506
- }
507
- catch (error) {
508
- assert.ok(events.find((e) => e.type === 'verification-failed' && e.txId === txId), 'Should emit at least one verification-failed');
509
- }
510
- });
511
- });
512
- });
513
- });
514
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- // TODO: add an offset provider that returns offsets for data items so we can use them to verify the signatures of a data item within a bundle
@@ -1,33 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { AoARIORead, AoGatewayWithAddress } from '../../../types/io.js';
17
- import { GatewaysProvider } from '../../../types/wayfinder.js';
18
- export declare class NetworkGatewaysProvider implements GatewaysProvider {
19
- private ario;
20
- private sortBy;
21
- private sortOrder;
22
- private limit;
23
- private filter;
24
- constructor({ ario, sortBy, sortOrder, limit, filter, }: {
25
- ario?: AoARIORead;
26
- sortBy?: 'totalDelegatedStake' | 'operatorStake' | 'startTimestamp';
27
- sortOrder?: 'asc' | 'desc';
28
- limit?: number;
29
- blocklist?: string[];
30
- filter?: (gateway: AoGatewayWithAddress) => boolean;
31
- });
32
- getGateways(): Promise<URL[]>;
33
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { GatewaysProvider } from '../../../types/wayfinder.js';
17
- import { Logger } from '../../../web/index.js';
18
- export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
19
- private gatewaysProvider;
20
- private ttlSeconds;
21
- private lastUpdated;
22
- private gatewaysCache;
23
- private logger;
24
- constructor({ gatewaysProvider, ttlSeconds, // 1 hour
25
- logger, }: {
26
- gatewaysProvider: GatewaysProvider;
27
- ttlSeconds?: number;
28
- logger?: Logger;
29
- });
30
- getGateways(): Promise<URL[]>;
31
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { GatewaysProvider } from '../../../types/wayfinder.js';
17
- export declare class StaticGatewaysProvider implements GatewaysProvider {
18
- private gateways;
19
- constructor({ gateways }: {
20
- gateways: string[];
21
- });
22
- getGateways(): Promise<URL[]>;
23
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export * from './wayfinder.js';
17
- export * from './routing/strategies/random.js';
18
- export * from './routing/strategies/static.js';
19
- export * from './routing/strategies/ping.js';
20
- export * from './routing/strategies/round-robin.js';
21
- export * from './gateways/network.js';
22
- export * from './gateways/simple-cache.js';
23
- export * from './gateways/static.js';
24
- export * from './verification/trusted.js';
25
- export * from './verification/strategies/data-root-verifier.js';
26
- export * from './verification/strategies/hash-verifier.js';
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { RoutingStrategy } from '../../../../types/wayfinder.js';
17
- export declare class FastestPingRoutingStrategy implements RoutingStrategy {
18
- private timeoutMs;
19
- private probePath;
20
- constructor({ timeoutMs, probePath, }?: {
21
- timeoutMs?: number;
22
- probePath?: string;
23
- });
24
- selectGateway({ gateways }: {
25
- gateways: URL[];
26
- }): Promise<URL>;
27
- }