@ar.io/sdk 3.11.0-alpha.9 → 3.11.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/web.bundle.min.js +106 -106
- package/lib/cjs/cli/utils.js +4 -1
- package/lib/cjs/common/contracts/ao-process.js +2 -1
- package/lib/cjs/common/wayfinder/{gateways.js → gateways/network.js} +3 -41
- package/lib/cjs/common/wayfinder/gateways/simple-cache.js +35 -0
- package/lib/cjs/common/wayfinder/gateways/static.js +13 -0
- package/lib/cjs/common/wayfinder/index.js +11 -8
- package/lib/cjs/common/wayfinder/routing/strategies/ping.js +72 -0
- package/lib/cjs/common/wayfinder/routing/strategies/ping.test.js +156 -0
- package/lib/cjs/common/wayfinder/routing/strategies/random.js +13 -0
- package/lib/cjs/common/wayfinder/routing/strategies/random.test.js +68 -0
- package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +42 -0
- package/lib/cjs/common/wayfinder/routing/strategies/round-robin.test.js +78 -0
- package/lib/cjs/common/wayfinder/routing/strategies/static.js +29 -0
- package/lib/cjs/common/wayfinder/routing/strategies/static.test.js +40 -0
- package/lib/cjs/common/wayfinder/verification/{data-root-verifier.js → strategies/data-root-verifier.js} +4 -4
- package/lib/cjs/common/wayfinder/verification/{hash-verifier.js → strategies/hash-verifier.js} +4 -4
- package/lib/cjs/common/wayfinder/{gateways/trusted-gateways.js → verification/trusted.js} +1 -1
- package/lib/cjs/common/wayfinder/wayfinder.js +397 -257
- package/lib/cjs/common/wayfinder/wayfinder.test.js +227 -208
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/utils.js +4 -1
- package/lib/esm/common/contracts/ao-process.js +2 -1
- package/lib/esm/common/wayfinder/{gateways.js → gateways/network.js} +2 -38
- package/lib/esm/common/wayfinder/gateways/simple-cache.js +31 -0
- package/lib/esm/common/wayfinder/gateways/static.js +9 -0
- package/lib/esm/common/wayfinder/index.js +11 -8
- package/lib/esm/common/wayfinder/routing/strategies/ping.js +68 -0
- package/lib/esm/common/wayfinder/routing/strategies/ping.test.js +151 -0
- package/lib/esm/common/wayfinder/routing/strategies/random.js +9 -0
- package/lib/esm/common/wayfinder/routing/strategies/random.test.js +63 -0
- package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +38 -0
- package/lib/esm/common/wayfinder/routing/strategies/round-robin.test.js +73 -0
- package/lib/esm/common/wayfinder/routing/strategies/static.js +25 -0
- package/lib/esm/common/wayfinder/routing/strategies/static.test.js +35 -0
- package/lib/esm/common/wayfinder/verification/{data-root-verifier.js → strategies/data-root-verifier.js} +2 -2
- package/lib/esm/common/wayfinder/verification/{hash-verifier.js → strategies/hash-verifier.js} +2 -2
- package/lib/esm/common/wayfinder/{gateways/trusted-gateways.js → verification/trusted.js} +1 -1
- package/lib/esm/common/wayfinder/wayfinder.js +395 -255
- package/lib/esm/common/wayfinder/wayfinder.test.js +227 -208
- package/lib/esm/version.js +1 -1
- package/lib/types/common/wayfinder/{gateways.d.ts → gateways/network.d.ts} +3 -23
- package/lib/types/common/wayfinder/{routers/random.d.ts → gateways/simple-cache.d.ts} +12 -8
- package/lib/types/common/wayfinder/{routers → gateways}/static.d.ts +6 -7
- package/lib/types/common/wayfinder/index.d.ts +10 -7
- package/lib/types/common/wayfinder/{routers/simple-cache.d.ts → routing/strategies/ping.d.ts} +10 -11
- package/lib/types/common/wayfinder/routing/strategies/random.d.ts +21 -0
- package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +29 -0
- package/lib/types/common/wayfinder/routing/strategies/static.d.ts +29 -0
- package/lib/types/common/wayfinder/verification/{data-root-verifier.d.ts → strategies/data-root-verifier.d.ts} +2 -2
- package/lib/types/common/wayfinder/verification/{hash-verifier.d.ts → strategies/hash-verifier.d.ts} +2 -2
- package/lib/types/common/wayfinder/{gateways/trusted-gateways.d.ts → verification/trusted.d.ts} +1 -1
- package/lib/types/common/wayfinder/wayfinder.d.ts +111 -77
- package/lib/types/types/wayfinder.d.ts +8 -4
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/lib/cjs/common/wayfinder/routers/priority.js +0 -29
- package/lib/cjs/common/wayfinder/routers/priority.test.js +0 -155
- package/lib/cjs/common/wayfinder/routers/random.js +0 -23
- package/lib/cjs/common/wayfinder/routers/random.test.js +0 -25
- package/lib/cjs/common/wayfinder/routers/simple-cache.js +0 -25
- package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +0 -41
- package/lib/cjs/common/wayfinder/routers/static.js +0 -14
- package/lib/cjs/common/wayfinder/routers/static.test.js +0 -14
- package/lib/esm/common/wayfinder/routers/priority.js +0 -25
- package/lib/esm/common/wayfinder/routers/priority.test.js +0 -153
- package/lib/esm/common/wayfinder/routers/random.js +0 -19
- package/lib/esm/common/wayfinder/routers/random.test.js +0 -23
- package/lib/esm/common/wayfinder/routers/simple-cache.js +0 -21
- package/lib/esm/common/wayfinder/routers/simple-cache.test.js +0 -39
- package/lib/esm/common/wayfinder/routers/static.js +0 -10
- package/lib/esm/common/wayfinder/routers/static.test.js +0 -12
- package/lib/types/common/wayfinder/routers/priority.d.ts +0 -29
- /package/lib/types/common/wayfinder/{routers/priority.test.d.ts → routing/strategies/ping.test.d.ts} +0 -0
- /package/lib/types/common/wayfinder/{routers → routing/strategies}/random.test.d.ts +0 -0
- /package/lib/types/common/wayfinder/{routers/simple-cache.test.d.ts → routing/strategies/round-robin.test.d.ts} +0 -0
- /package/lib/types/common/wayfinder/{routers → routing/strategies}/static.test.d.ts +0 -0
|
@@ -11,8 +11,8 @@ const node_stream_1 = require("node:stream");
|
|
|
11
11
|
const consumers_1 = require("node:stream/consumers");
|
|
12
12
|
const node_test_1 = require("node:test");
|
|
13
13
|
const logger_js_1 = require("../../common/logger.js");
|
|
14
|
-
const random_js_1 = require("./
|
|
15
|
-
const static_js_1 = require("./
|
|
14
|
+
const random_js_1 = require("./routing/strategies/random.js");
|
|
15
|
+
const static_js_1 = require("./routing/strategies/static.js");
|
|
16
16
|
const wayfinder_js_1 = require("./wayfinder.js");
|
|
17
17
|
// TODO: replace with locally running gateway
|
|
18
18
|
const gatewayUrl = 'permagate.io';
|
|
@@ -21,15 +21,14 @@ const stubbedGatewaysProvider = {
|
|
|
21
21
|
};
|
|
22
22
|
logger_js_1.Logger.default.setLogLevel('none');
|
|
23
23
|
(0, node_test_1.describe)('Wayfinder', () => {
|
|
24
|
-
node_test_1.describe
|
|
24
|
+
(0, node_test_1.describe)('http wrapper', () => {
|
|
25
25
|
(0, node_test_1.describe)('fetch', () => {
|
|
26
26
|
let wayfinder;
|
|
27
27
|
(0, node_test_1.before)(() => {
|
|
28
28
|
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
29
29
|
httpClient: fetch,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}),
|
|
30
|
+
routingStrategy: new random_js_1.RandomRoutingStrategy(),
|
|
31
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
33
32
|
});
|
|
34
33
|
});
|
|
35
34
|
(0, node_test_1.it)('should fetch the data using the selected gateway', async () => {
|
|
@@ -54,9 +53,11 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
54
53
|
const [nativeFetch, response] = await Promise.all([
|
|
55
54
|
fetch(`https://${gatewayUrl}/`, {
|
|
56
55
|
method: 'HEAD',
|
|
56
|
+
redirect: 'follow',
|
|
57
57
|
}),
|
|
58
58
|
wayfinder.request(`https://${gatewayUrl}/`, {
|
|
59
59
|
method: 'HEAD',
|
|
60
|
+
redirect: 'follow',
|
|
60
61
|
}),
|
|
61
62
|
]);
|
|
62
63
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
@@ -64,10 +65,14 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
64
65
|
// TODO: ensure the headers are the same excluding unique headers
|
|
65
66
|
});
|
|
66
67
|
for (const api of ['/info', '/block/current']) {
|
|
67
|
-
|
|
68
|
+
node_test_1.it.skip(`supports native arweave node apis ${api}`, async () => {
|
|
68
69
|
const [nativeFetch, response] = await Promise.all([
|
|
69
|
-
fetch(`https://${gatewayUrl}${api}
|
|
70
|
-
|
|
70
|
+
fetch(`https://${gatewayUrl}${api}`, {
|
|
71
|
+
redirect: 'follow',
|
|
72
|
+
}),
|
|
73
|
+
wayfinder.request(`ar://${api}`, {
|
|
74
|
+
redirect: 'follow',
|
|
75
|
+
}),
|
|
71
76
|
]);
|
|
72
77
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
73
78
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
@@ -88,6 +93,7 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
88
93
|
(0, node_test_1.it)('supports a post request to graphql', async () => {
|
|
89
94
|
const response = await wayfinder.request('ar:///graphql', {
|
|
90
95
|
method: 'POST',
|
|
96
|
+
redirect: 'follow',
|
|
91
97
|
headers: {
|
|
92
98
|
'Content-Type': 'application/json',
|
|
93
99
|
},
|
|
@@ -121,10 +127,14 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
121
127
|
});
|
|
122
128
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
123
129
|
});
|
|
124
|
-
node_test_1.it
|
|
130
|
+
(0, node_test_1.it)('returns the error from the target gateway if the route is not found', async () => {
|
|
125
131
|
const [nativeFetch, response] = await Promise.all([
|
|
126
|
-
fetch(`https://${gatewayUrl}/ar-io/not-found
|
|
127
|
-
|
|
132
|
+
fetch(`https://${gatewayUrl}/ar-io/not-found`, {
|
|
133
|
+
redirect: 'follow',
|
|
134
|
+
}),
|
|
135
|
+
wayfinder.request('ar:///ar-io/not-found', {
|
|
136
|
+
redirect: 'follow',
|
|
137
|
+
}),
|
|
128
138
|
]);
|
|
129
139
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
130
140
|
node_assert_1.default.strictEqual(response.statusText, nativeFetch.statusText);
|
|
@@ -135,17 +145,17 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
135
145
|
(0, node_test_1.before)(() => {
|
|
136
146
|
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
137
147
|
httpClient: axios_1.default,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}),
|
|
148
|
+
routingStrategy: new random_js_1.RandomRoutingStrategy(),
|
|
149
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
141
150
|
});
|
|
142
151
|
});
|
|
143
152
|
(0, node_test_1.it)('should fetch the data using axios default function against the target gateway', async () => {
|
|
144
153
|
const [nativeAxios, response] = await Promise.all([
|
|
145
154
|
(0, axios_1.default)(`https://ao.${gatewayUrl}`),
|
|
146
|
-
wayfinder.request('ar://ao'
|
|
155
|
+
wayfinder.request('ar://ao', {
|
|
156
|
+
maxRedirects: 5,
|
|
157
|
+
}),
|
|
147
158
|
]);
|
|
148
|
-
node_assert_1.default.strictEqual(response.status, 200);
|
|
149
159
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
150
160
|
// assert the arns headers are the same
|
|
151
161
|
const arnsHeaders = Object.entries(response.headers)
|
|
@@ -159,7 +169,6 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
159
169
|
axios_1.default.get(`https://ao.${gatewayUrl}`),
|
|
160
170
|
wayfinder.request.get('ar://ao'),
|
|
161
171
|
]);
|
|
162
|
-
node_assert_1.default.strictEqual(response.status, 200);
|
|
163
172
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
164
173
|
// assert the arns headers are the same
|
|
165
174
|
const arnsHeaders = Object.entries(response.headers)
|
|
@@ -178,7 +187,7 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
178
187
|
// TODO: ensure the headers are the same excluding unique headers
|
|
179
188
|
});
|
|
180
189
|
for (const api of ['/info', '/block/current']) {
|
|
181
|
-
|
|
190
|
+
node_test_1.it.skip(`supports native arweave node apis ${api}`, async () => {
|
|
182
191
|
const [nativeAxios, response] = await Promise.all([
|
|
183
192
|
(0, axios_1.default)(`https://${gatewayUrl}${api}`),
|
|
184
193
|
wayfinder.request(`ar://${api}`),
|
|
@@ -192,26 +201,24 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
192
201
|
(0, node_test_1.it)(`supports native ario node gateway apis ${api}`, async () => {
|
|
193
202
|
const [nativeAxios, response] = await Promise.all([
|
|
194
203
|
(0, axios_1.default)(`https://${gatewayUrl}${api}`),
|
|
195
|
-
wayfinder.request(`ar
|
|
204
|
+
wayfinder.request(`ar://${api}`),
|
|
196
205
|
]);
|
|
197
206
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
198
207
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
199
208
|
// TODO: ensure the headers are the same excluding unique headers
|
|
200
209
|
});
|
|
201
210
|
}
|
|
202
|
-
node_test_1.it
|
|
211
|
+
(0, node_test_1.it)('should return the error from the target gateway if the route is not found', async () => {
|
|
203
212
|
const axiosInstance = axios_1.default.create({
|
|
204
213
|
validateStatus: () => true, // don't throw so we can compare axios result with wrapped axios result
|
|
205
214
|
});
|
|
206
215
|
const wayfinder = new wayfinder_js_1.Wayfinder({
|
|
207
216
|
httpClient: axiosInstance,
|
|
208
|
-
|
|
209
|
-
gatewaysProvider: stubbedGatewaysProvider,
|
|
210
|
-
}),
|
|
217
|
+
routingStrategy: new random_js_1.RandomRoutingStrategy(),
|
|
211
218
|
});
|
|
212
219
|
const [nativeAxios, response] = await Promise.all([
|
|
213
220
|
axiosInstance(`https://${gatewayUrl}/ar-io/not-found`),
|
|
214
|
-
wayfinder.request('ar:///not-found'),
|
|
221
|
+
wayfinder.request('ar:///ar-io/not-found'),
|
|
215
222
|
]);
|
|
216
223
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
217
224
|
});
|
|
@@ -221,9 +228,8 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
221
228
|
(0, node_test_1.before)(() => {
|
|
222
229
|
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
223
230
|
httpClient: got_1.default,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}),
|
|
231
|
+
routingStrategy: new random_js_1.RandomRoutingStrategy(),
|
|
232
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
227
233
|
});
|
|
228
234
|
});
|
|
229
235
|
(0, node_test_1.it)('should fetch the data using the got default function against the target gateway', async () => {
|
|
@@ -231,13 +237,18 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
231
237
|
(0, got_1.default)(`https://ao.${gatewayUrl}`),
|
|
232
238
|
wayfinder.request('ar://ao'),
|
|
233
239
|
]);
|
|
234
|
-
node_assert_1.default.strictEqual(response.statusCode, 200);
|
|
235
240
|
node_assert_1.default.strictEqual(response.statusCode, nativeGot.statusCode);
|
|
236
241
|
node_assert_1.default.deepStrictEqual(response.body, nativeGot.body);
|
|
237
242
|
});
|
|
238
243
|
(0, node_test_1.it)('should stream the data using got.stream against the selected target gateway', async () => {
|
|
239
|
-
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream(`https://ao.${gatewayUrl}`, {
|
|
240
|
-
|
|
244
|
+
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream(`https://ao.${gatewayUrl}`, {
|
|
245
|
+
decompress: false,
|
|
246
|
+
followRedirect: true,
|
|
247
|
+
}));
|
|
248
|
+
const wayfinderBuffer = await (0, consumers_1.buffer)(await wayfinder.request.stream('ar://ao', {
|
|
249
|
+
decompress: false,
|
|
250
|
+
followRedirect: true,
|
|
251
|
+
}));
|
|
241
252
|
node_assert_1.default.deepStrictEqual(wayfinderBuffer, nativeBuffer);
|
|
242
253
|
});
|
|
243
254
|
});
|
|
@@ -246,10 +257,10 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
246
257
|
(0, node_test_1.it)('should emit events on the wayfinder event emitter', async () => {
|
|
247
258
|
const wayfinder = new wayfinder_js_1.Wayfinder({
|
|
248
259
|
httpClient: fetch,
|
|
249
|
-
|
|
260
|
+
routingStrategy: new static_js_1.StaticRoutingStrategy({
|
|
250
261
|
gateway: `http://${gatewayUrl}`,
|
|
251
262
|
}),
|
|
252
|
-
|
|
263
|
+
verificationStrategy: {
|
|
253
264
|
// @ts-expect-error
|
|
254
265
|
verifyData: async (params) => {
|
|
255
266
|
return;
|
|
@@ -263,8 +274,8 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
263
274
|
wayfinder.emitter.on('verification-progress', (event) => {
|
|
264
275
|
events.push({ type: 'verification-progress', ...event });
|
|
265
276
|
});
|
|
266
|
-
wayfinder.emitter.on('verification-
|
|
267
|
-
events.push({ type: 'verification-
|
|
277
|
+
wayfinder.emitter.on('verification-succeeded', (event) => {
|
|
278
|
+
events.push({ type: 'verification-succeeded', ...event });
|
|
268
279
|
});
|
|
269
280
|
// request data and assert the event is emitted
|
|
270
281
|
const response = await wayfinder.request('ar://c7wkwt6TKgcWJUfgvpJ5q5qi4DIZyJ1_TqhjXgURh0U', {
|
|
@@ -273,7 +284,7 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
273
284
|
// read the full response body to ensure the stream is fully consumed
|
|
274
285
|
await response.text();
|
|
275
286
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
276
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-
|
|
287
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-succeeded'), 'Should emit at least one verification-succeeded');
|
|
277
288
|
});
|
|
278
289
|
(0, node_test_1.it)('should execute callbacks provided to the wayfinder constructor', async () => {
|
|
279
290
|
let verificationFailed = false;
|
|
@@ -281,7 +292,7 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
281
292
|
let verificationPassed = false;
|
|
282
293
|
const wayfinder = new wayfinder_js_1.Wayfinder({
|
|
283
294
|
httpClient: fetch,
|
|
284
|
-
|
|
295
|
+
routingStrategy: new static_js_1.StaticRoutingStrategy({
|
|
285
296
|
gateway: `http://${gatewayUrl}`,
|
|
286
297
|
}),
|
|
287
298
|
events: {
|
|
@@ -295,6 +306,7 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
295
306
|
verificationPassed = true;
|
|
296
307
|
},
|
|
297
308
|
},
|
|
309
|
+
strict: true,
|
|
298
310
|
});
|
|
299
311
|
const response = await wayfinder.request('ar://c7wkwt6TKgcWJUfgvpJ5q5qi4DIZyJ1_TqhjXgURh0U', {
|
|
300
312
|
redirect: 'follow',
|
|
@@ -304,196 +316,203 @@ logger_js_1.Logger.default.setLogLevel('none');
|
|
|
304
316
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
305
317
|
node_assert_1.default.ok(verificationFailed === false, 'Should not emit verification-failed');
|
|
306
318
|
node_assert_1.default.ok(verificationProgress, 'Should emit verification-progress');
|
|
307
|
-
node_assert_1.default.ok(verificationPassed, 'Should emit verification-
|
|
319
|
+
node_assert_1.default.ok(verificationPassed, 'Should emit verification-succeeded');
|
|
308
320
|
});
|
|
309
321
|
});
|
|
310
|
-
node_test_1.describe
|
|
322
|
+
(0, node_test_1.describe)('tapAndVerifyRequest', () => {
|
|
311
323
|
(0, node_test_1.describe)('Readable', () => {
|
|
312
|
-
(0, node_test_1.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
324
|
+
(0, node_test_1.describe)('strict mode enabled', () => {
|
|
325
|
+
(0, node_test_1.it)('should duplicate the stream, verify the first and return the second if verification passes', async () => {
|
|
326
|
+
// create a simple readable
|
|
327
|
+
const chunks = [
|
|
328
|
+
Buffer.from('foo'),
|
|
329
|
+
Buffer.from('bar'),
|
|
330
|
+
Buffer.from('baz'),
|
|
331
|
+
];
|
|
332
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
333
|
+
// a stream that will emit chunks
|
|
334
|
+
const originalStream = node_stream_1.Readable.from(chunks);
|
|
335
|
+
let seen = Buffer.alloc(0);
|
|
336
|
+
const verifyData = async ({ data,
|
|
337
|
+
// @ts-expect-error
|
|
338
|
+
txId, }) => {
|
|
339
|
+
return new Promise((resolve, reject) => {
|
|
340
|
+
data.on('data', (chunk) => {
|
|
341
|
+
seen = Buffer.concat([seen, chunk]);
|
|
342
|
+
});
|
|
343
|
+
data.on('end', () => {
|
|
344
|
+
// Should have seen exactly the full payload
|
|
345
|
+
node_assert_1.default.strictEqual(seen.length, contentLength);
|
|
346
|
+
resolve();
|
|
347
|
+
});
|
|
348
|
+
data.on('error', reject);
|
|
334
349
|
});
|
|
335
|
-
|
|
350
|
+
};
|
|
351
|
+
const txId = 'test-tx-1';
|
|
352
|
+
const emitter = new node_events_1.EventEmitter();
|
|
353
|
+
const events = [];
|
|
354
|
+
emitter.on('verification-progress', (e) => {
|
|
355
|
+
events.push({ type: 'verification-progress', ...e });
|
|
336
356
|
});
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
originalStream,
|
|
349
|
-
contentLength,
|
|
350
|
-
verifyData,
|
|
351
|
-
txId,
|
|
352
|
-
emitter,
|
|
353
|
-
});
|
|
354
|
-
// read the stream
|
|
355
|
-
const out = [];
|
|
356
|
-
for await (const chunk of tapped) {
|
|
357
|
-
out.push(chunk);
|
|
358
|
-
}
|
|
359
|
-
// assert the stream is the same
|
|
360
|
-
node_assert_1.default.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
|
|
361
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
|
|
362
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-passed' && e.txId === txId), 'Should emit at least one verification-passed');
|
|
363
|
-
});
|
|
364
|
-
(0, node_test_1.it)('should throw an error on the client stream if verification fails', async () => {
|
|
365
|
-
const chunks = [
|
|
366
|
-
Buffer.from('foo'),
|
|
367
|
-
Buffer.from('bar'),
|
|
368
|
-
Buffer.from('baz'),
|
|
369
|
-
];
|
|
370
|
-
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
371
|
-
// a stream that will emit chunks
|
|
372
|
-
const originalStream = node_stream_1.Readable.from(chunks);
|
|
373
|
-
const verifyData = async ({
|
|
374
|
-
// @ts-expect-error
|
|
375
|
-
data, txId, }) => {
|
|
376
|
-
throw new Error('Verification failed for txId: ' + txId);
|
|
377
|
-
};
|
|
378
|
-
const txId = 'test-tx-1';
|
|
379
|
-
const emitter = new node_events_1.EventEmitter();
|
|
380
|
-
const events = [];
|
|
381
|
-
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
382
|
-
emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
|
|
383
|
-
// tap with verification
|
|
384
|
-
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
385
|
-
originalStream,
|
|
386
|
-
contentLength,
|
|
387
|
-
verifyData,
|
|
388
|
-
txId,
|
|
389
|
-
emitter,
|
|
390
|
-
});
|
|
391
|
-
// read the stream
|
|
392
|
-
try {
|
|
357
|
+
emitter.on('verification-succeeded', (e) => events.push({ type: 'verification-succeeded', ...e }));
|
|
358
|
+
// tap with verification
|
|
359
|
+
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
360
|
+
originalStream,
|
|
361
|
+
contentLength,
|
|
362
|
+
verifyData,
|
|
363
|
+
txId,
|
|
364
|
+
emitter,
|
|
365
|
+
strict: true,
|
|
366
|
+
});
|
|
367
|
+
// read the stream
|
|
393
368
|
const out = [];
|
|
394
369
|
for await (const chunk of tapped) {
|
|
395
370
|
out.push(chunk);
|
|
396
371
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
372
|
+
// assert the stream is the same
|
|
373
|
+
node_assert_1.default.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
|
|
374
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
|
|
375
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-succeeded' && e.txId === txId), 'Should emit at least one verification-succeeded');
|
|
376
|
+
});
|
|
377
|
+
(0, node_test_1.it)('should throw an error on the client stream if verification fails', async () => {
|
|
378
|
+
const chunks = [
|
|
379
|
+
Buffer.from('foo'),
|
|
380
|
+
Buffer.from('bar'),
|
|
381
|
+
Buffer.from('baz'),
|
|
382
|
+
];
|
|
383
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
384
|
+
// a stream that will emit chunks
|
|
385
|
+
const originalStream = node_stream_1.Readable.from(chunks);
|
|
386
|
+
const verifyData = async ({
|
|
387
|
+
// @ts-expect-error
|
|
388
|
+
data, txId, }) => {
|
|
389
|
+
throw new Error('Verification failed for txId: ' + txId);
|
|
390
|
+
};
|
|
391
|
+
const txId = 'test-tx-1';
|
|
392
|
+
const emitter = new node_events_1.EventEmitter();
|
|
393
|
+
const events = [];
|
|
394
|
+
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
395
|
+
emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
|
|
396
|
+
// tap with verification (using strict mode)
|
|
397
|
+
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
398
|
+
originalStream,
|
|
399
|
+
contentLength,
|
|
400
|
+
verifyData,
|
|
401
|
+
txId,
|
|
402
|
+
emitter,
|
|
403
|
+
strict: true,
|
|
404
|
+
});
|
|
405
|
+
// read the stream
|
|
406
|
+
try {
|
|
407
|
+
const out = [];
|
|
408
|
+
for await (const chunk of tapped) {
|
|
409
|
+
out.push(chunk);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (error) {
|
|
413
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-failed' && e.txId === txId), 'Should emit at least one verification-failed');
|
|
414
|
+
// stream should be closed
|
|
415
|
+
node_assert_1.default.ok(tapped.closed);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
403
418
|
});
|
|
404
419
|
});
|
|
405
420
|
(0, node_test_1.describe)('ReadableStream', () => {
|
|
406
|
-
(0, node_test_1.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
421
|
+
(0, node_test_1.describe)('strict mode enabled', () => {
|
|
422
|
+
(0, node_test_1.it)('should duplicate the ReadableStream, verify the first and return the second if verification passes', async () => {
|
|
423
|
+
// create a simple readable
|
|
424
|
+
const chunks = [
|
|
425
|
+
Buffer.from('foo'),
|
|
426
|
+
Buffer.from('bar'),
|
|
427
|
+
Buffer.from('baz'),
|
|
428
|
+
];
|
|
429
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
430
|
+
// a stream that will emit chunks
|
|
431
|
+
const originalStream = ReadableStream.from(chunks);
|
|
432
|
+
let seen = Buffer.alloc(0);
|
|
433
|
+
const verifyData = async ({ data,
|
|
434
|
+
// @ts-expect-error
|
|
435
|
+
txId, }) => {
|
|
436
|
+
return new Promise(async (resolve, reject) => {
|
|
437
|
+
const reader = data.getReader();
|
|
438
|
+
while (true) {
|
|
439
|
+
try {
|
|
440
|
+
const { done, value } = await reader.read();
|
|
441
|
+
if (done) {
|
|
442
|
+
resolve();
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
seen = Buffer.concat([seen, value]);
|
|
446
|
+
}
|
|
447
|
+
catch (error) {
|
|
448
|
+
reject(error);
|
|
428
449
|
}
|
|
429
|
-
seen = Buffer.concat([seen, value]);
|
|
430
|
-
}
|
|
431
|
-
catch (error) {
|
|
432
|
-
reject(error);
|
|
433
450
|
}
|
|
434
|
-
}
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
const txId = 'test-tx-1';
|
|
454
|
+
const emitter = new node_events_1.EventEmitter();
|
|
455
|
+
const events = [];
|
|
456
|
+
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
457
|
+
emitter.on('verification-succeeded', (e) => events.push({ type: 'verification-succeeded', ...e }));
|
|
458
|
+
// tap with verification
|
|
459
|
+
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
460
|
+
originalStream,
|
|
461
|
+
contentLength,
|
|
462
|
+
verifyData,
|
|
463
|
+
txId,
|
|
464
|
+
emitter,
|
|
465
|
+
strict: true,
|
|
435
466
|
});
|
|
436
|
-
|
|
437
|
-
const txId = 'test-tx-1';
|
|
438
|
-
const emitter = new node_events_1.EventEmitter();
|
|
439
|
-
const events = [];
|
|
440
|
-
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
441
|
-
emitter.on('verification-passed', (e) => events.push({ type: 'verification-passed', ...e }));
|
|
442
|
-
// tap with verification
|
|
443
|
-
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
444
|
-
originalStream,
|
|
445
|
-
contentLength,
|
|
446
|
-
verifyData,
|
|
447
|
-
txId,
|
|
448
|
-
emitter,
|
|
449
|
-
});
|
|
450
|
-
// read the stream
|
|
451
|
-
const out = [];
|
|
452
|
-
for await (const chunk of tapped) {
|
|
453
|
-
out.push(chunk);
|
|
454
|
-
}
|
|
455
|
-
// assert the stream is the same
|
|
456
|
-
node_assert_1.default.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
|
|
457
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
|
|
458
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-passed' && e.txId === txId), 'Should emit at least one verification-passed');
|
|
459
|
-
});
|
|
460
|
-
(0, node_test_1.it)('should throw an error on the client stream if verification fails', async () => {
|
|
461
|
-
const chunks = [
|
|
462
|
-
Buffer.from('foo'),
|
|
463
|
-
Buffer.from('bar'),
|
|
464
|
-
Buffer.from('baz'),
|
|
465
|
-
];
|
|
466
|
-
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
467
|
-
// a stream that will emit chunks
|
|
468
|
-
const originalStream = ReadableStream.from(chunks);
|
|
469
|
-
const verifyData = async ({
|
|
470
|
-
// @ts-expect-error
|
|
471
|
-
data, txId, }) => {
|
|
472
|
-
throw new Error('Verification failed for txId: ' + txId);
|
|
473
|
-
};
|
|
474
|
-
const txId = 'test-tx-1';
|
|
475
|
-
const emitter = new node_events_1.EventEmitter();
|
|
476
|
-
const events = [];
|
|
477
|
-
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
478
|
-
emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
|
|
479
|
-
// tap with verification
|
|
480
|
-
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
481
|
-
originalStream,
|
|
482
|
-
contentLength,
|
|
483
|
-
verifyData,
|
|
484
|
-
txId,
|
|
485
|
-
emitter,
|
|
486
|
-
});
|
|
487
|
-
// read the stream
|
|
488
|
-
try {
|
|
467
|
+
// read the stream
|
|
489
468
|
const out = [];
|
|
490
469
|
for await (const chunk of tapped) {
|
|
491
470
|
out.push(chunk);
|
|
492
471
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
node_assert_1.default.ok(events.find((e) => e.type === 'verification-
|
|
496
|
-
|
|
472
|
+
// assert the stream is the same
|
|
473
|
+
node_assert_1.default.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
|
|
474
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
|
|
475
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-succeeded' && e.txId === txId), 'Should emit at least one verification-succeeded');
|
|
476
|
+
});
|
|
477
|
+
(0, node_test_1.it)('should throw an error on the client stream if verification fails', async () => {
|
|
478
|
+
const chunks = [
|
|
479
|
+
Buffer.from('foo'),
|
|
480
|
+
Buffer.from('bar'),
|
|
481
|
+
Buffer.from('baz'),
|
|
482
|
+
];
|
|
483
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
484
|
+
// a stream that will emit chunks
|
|
485
|
+
const originalStream = ReadableStream.from(chunks);
|
|
486
|
+
const verifyData = async ({
|
|
487
|
+
// @ts-expect-error
|
|
488
|
+
data, txId, }) => {
|
|
489
|
+
throw new Error('Verification failed for txId: ' + txId);
|
|
490
|
+
};
|
|
491
|
+
const txId = 'test-tx-1';
|
|
492
|
+
const emitter = new node_events_1.EventEmitter();
|
|
493
|
+
const events = [];
|
|
494
|
+
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
495
|
+
emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
|
|
496
|
+
// tap with verification (using strict mode)
|
|
497
|
+
const tapped = (0, wayfinder_js_1.tapAndVerifyStream)({
|
|
498
|
+
originalStream,
|
|
499
|
+
contentLength,
|
|
500
|
+
verifyData,
|
|
501
|
+
txId,
|
|
502
|
+
emitter,
|
|
503
|
+
strict: true,
|
|
504
|
+
});
|
|
505
|
+
// read the stream
|
|
506
|
+
try {
|
|
507
|
+
const out = [];
|
|
508
|
+
for await (const chunk of tapped) {
|
|
509
|
+
out.push(chunk);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
catch (error) {
|
|
513
|
+
node_assert_1.default.ok(events.find((e) => e.type === 'verification-failed' && e.txId === txId), 'Should emit at least one verification-failed');
|
|
514
|
+
}
|
|
515
|
+
});
|
|
497
516
|
});
|
|
498
517
|
});
|
|
499
518
|
});
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/cli/utils.js
CHANGED
|
@@ -117,7 +117,10 @@ function aoProcessFromOptions(options) {
|
|
|
117
117
|
export function readARIOFromOptions(options) {
|
|
118
118
|
setLoggerIfDebug(options);
|
|
119
119
|
return ARIO.init({
|
|
120
|
-
process: aoProcessFromOptions(
|
|
120
|
+
process: aoProcessFromOptions({
|
|
121
|
+
cuUrl: 'https://cu.ardrive.io', // default to ardrive cu for ARIO process
|
|
122
|
+
...options,
|
|
123
|
+
}),
|
|
121
124
|
paymentUrl: options.paymentUrl,
|
|
122
125
|
});
|
|
123
126
|
}
|
|
@@ -95,7 +95,8 @@ export class AOProcess {
|
|
|
95
95
|
tags,
|
|
96
96
|
processId: this.processId,
|
|
97
97
|
});
|
|
98
|
-
throw new Error(
|
|
98
|
+
throw new Error(result.message ||
|
|
99
|
+
`Process ${this.processId} did not return a valid response. Response: ${JSON.stringify(result)}`);
|
|
99
100
|
}
|
|
100
101
|
const messageData = result.Messages?.[0]?.Data;
|
|
101
102
|
// return undefined if no data is returned
|