@ar.io/sdk 3.11.0-alpha.7 → 3.11.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/bundles/web.bundle.min.js +119 -116
- package/lib/cjs/cli/cli.js +137 -122
- package/lib/cjs/cli/commands/readCommands.js +6 -0
- package/lib/cjs/common/ant.js +5 -5
- package/lib/cjs/common/io.js +37 -0
- package/lib/cjs/common/wayfinder/gateways/trusted-gateways.js +106 -0
- package/lib/cjs/common/wayfinder/index.js +6 -0
- package/lib/cjs/common/wayfinder/verification/data-root-verifier.js +139 -0
- package/lib/cjs/common/wayfinder/verification/hash-verifier.js +50 -0
- package/lib/cjs/common/wayfinder/wayfinder.js +407 -18
- package/lib/cjs/common/wayfinder/wayfinder.test.js +262 -3
- package/lib/cjs/types/wayfinder.js +1 -0
- package/lib/cjs/utils/hash.js +56 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +138 -123
- package/lib/esm/cli/commands/readCommands.js +5 -0
- package/lib/esm/common/ant.js +5 -5
- package/lib/esm/common/io.js +37 -0
- package/lib/esm/common/wayfinder/gateways/trusted-gateways.js +102 -0
- package/lib/esm/common/wayfinder/index.js +6 -0
- package/lib/esm/common/wayfinder/verification/data-root-verifier.js +130 -0
- package/lib/esm/common/wayfinder/verification/hash-verifier.js +46 -0
- package/lib/esm/common/wayfinder/wayfinder.js +401 -18
- package/lib/esm/common/wayfinder/wayfinder.test.js +263 -4
- package/lib/esm/types/wayfinder.js +1 -0
- package/lib/esm/utils/hash.js +50 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/readCommands.d.ts +1 -0
- package/lib/types/common/io.d.ts +5 -2
- package/lib/types/common/wayfinder/gateways/trusted-gateways.d.ts +51 -0
- package/lib/types/common/wayfinder/index.d.ts +3 -0
- package/lib/types/common/wayfinder/verification/data-root-verifier.d.ts +31 -0
- package/lib/types/common/wayfinder/verification/hash-verifier.d.ts +27 -0
- package/lib/types/common/wayfinder/wayfinder.d.ts +148 -10
- package/lib/types/types/io.d.ts +16 -1
- package/lib/types/types/wayfinder.d.ts +43 -0
- package/lib/types/utils/hash.d.ts +4 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import got from 'got';
|
|
3
3
|
import assert from 'node:assert';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
4
6
|
import { buffer } from 'node:stream/consumers';
|
|
5
7
|
import { before, describe, it } from 'node:test';
|
|
6
8
|
import { Logger } from '../../common/logger.js';
|
|
7
9
|
import { RandomGatewayRouter } from './routers/random.js';
|
|
8
|
-
import {
|
|
10
|
+
import { StaticGatewayRouter } from './routers/static.js';
|
|
11
|
+
import { Wayfinder, tapAndVerifyStream } from './wayfinder.js';
|
|
12
|
+
// TODO: replace with locally running gateway
|
|
9
13
|
const gatewayUrl = 'permagate.io';
|
|
10
14
|
const stubbedGatewaysProvider = {
|
|
11
|
-
getGateways: async () => [new URL(`
|
|
15
|
+
getGateways: async () => [new URL(`http://${gatewayUrl}`)],
|
|
12
16
|
};
|
|
13
|
-
Logger.default.setLogLevel('
|
|
17
|
+
Logger.default.setLogLevel('none');
|
|
14
18
|
describe('Wayfinder', () => {
|
|
15
|
-
describe('http wrapper', () => {
|
|
19
|
+
describe.skip('http wrapper', () => {
|
|
16
20
|
describe('fetch', () => {
|
|
17
21
|
let wayfinder;
|
|
18
22
|
before(() => {
|
|
@@ -233,4 +237,259 @@ describe('Wayfinder', () => {
|
|
|
233
237
|
});
|
|
234
238
|
});
|
|
235
239
|
});
|
|
240
|
+
describe('events', () => {
|
|
241
|
+
it('should emit events on the wayfinder event emitter', async () => {
|
|
242
|
+
const wayfinder = new Wayfinder({
|
|
243
|
+
httpClient: fetch,
|
|
244
|
+
router: new StaticGatewayRouter({
|
|
245
|
+
gateway: `http://${gatewayUrl}`,
|
|
246
|
+
}),
|
|
247
|
+
verifier: {
|
|
248
|
+
// @ts-expect-error
|
|
249
|
+
verifyData: async (params) => {
|
|
250
|
+
return;
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
const events = [];
|
|
255
|
+
wayfinder.emitter.on('verification-failed', (event) => {
|
|
256
|
+
events.push({ type: 'verification-failed', ...event });
|
|
257
|
+
});
|
|
258
|
+
wayfinder.emitter.on('verification-progress', (event) => {
|
|
259
|
+
events.push({ type: 'verification-progress', ...event });
|
|
260
|
+
});
|
|
261
|
+
wayfinder.emitter.on('verification-passed', (event) => {
|
|
262
|
+
events.push({ type: 'verification-passed', ...event });
|
|
263
|
+
});
|
|
264
|
+
// request data and assert the event is emitted
|
|
265
|
+
const response = await wayfinder.request('ar://c7wkwt6TKgcWJUfgvpJ5q5qi4DIZyJ1_TqhjXgURh0U', {
|
|
266
|
+
redirect: 'follow',
|
|
267
|
+
});
|
|
268
|
+
// read the full response body to ensure the stream is fully consumed
|
|
269
|
+
await response.text();
|
|
270
|
+
assert.strictEqual(response.status, 200);
|
|
271
|
+
assert.ok(events.find((e) => e.type === 'verification-passed'), 'Should emit at least one verification-passed');
|
|
272
|
+
});
|
|
273
|
+
it('should execute callbacks provided to the wayfinder constructor', async () => {
|
|
274
|
+
let verificationFailed = false;
|
|
275
|
+
let verificationProgress = false;
|
|
276
|
+
let verificationPassed = false;
|
|
277
|
+
const wayfinder = new Wayfinder({
|
|
278
|
+
httpClient: fetch,
|
|
279
|
+
router: new StaticGatewayRouter({
|
|
280
|
+
gateway: `http://${gatewayUrl}`,
|
|
281
|
+
}),
|
|
282
|
+
events: {
|
|
283
|
+
onVerificationFailed: () => {
|
|
284
|
+
verificationFailed = true;
|
|
285
|
+
},
|
|
286
|
+
onVerificationProgress: () => {
|
|
287
|
+
verificationProgress = true;
|
|
288
|
+
},
|
|
289
|
+
onVerificationPassed: () => {
|
|
290
|
+
verificationPassed = true;
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
const response = await wayfinder.request('ar://c7wkwt6TKgcWJUfgvpJ5q5qi4DIZyJ1_TqhjXgURh0U', {
|
|
295
|
+
redirect: 'follow',
|
|
296
|
+
});
|
|
297
|
+
// read the full response body to ensure the stream is fully consumed
|
|
298
|
+
await response.text();
|
|
299
|
+
assert.strictEqual(response.status, 200);
|
|
300
|
+
assert.ok(verificationFailed === false, 'Should not emit verification-failed');
|
|
301
|
+
assert.ok(verificationProgress, 'Should emit verification-progress');
|
|
302
|
+
assert.ok(verificationPassed, 'Should emit verification-passed');
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
describe.skip('tapAndVerifyRequest', () => {
|
|
306
|
+
describe('Readable', () => {
|
|
307
|
+
it('should duplicate the stream, verify the first and return the second if verification passes', async () => {
|
|
308
|
+
// create a simple readable
|
|
309
|
+
const chunks = [
|
|
310
|
+
Buffer.from('foo'),
|
|
311
|
+
Buffer.from('bar'),
|
|
312
|
+
Buffer.from('baz'),
|
|
313
|
+
];
|
|
314
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
315
|
+
// a stream that will emit chunks
|
|
316
|
+
const originalStream = Readable.from(chunks);
|
|
317
|
+
let seen = Buffer.alloc(0);
|
|
318
|
+
const verifyData = async ({ data,
|
|
319
|
+
// @ts-expect-error
|
|
320
|
+
txId, }) => {
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
data.on('data', (chunk) => {
|
|
323
|
+
seen = Buffer.concat([seen, chunk]);
|
|
324
|
+
});
|
|
325
|
+
data.on('end', () => {
|
|
326
|
+
// Should have seen exactly the full payload
|
|
327
|
+
assert.strictEqual(seen.length, contentLength);
|
|
328
|
+
resolve();
|
|
329
|
+
});
|
|
330
|
+
data.on('error', reject);
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
const txId = 'test-tx-1';
|
|
334
|
+
const emitter = new EventEmitter();
|
|
335
|
+
const events = [];
|
|
336
|
+
emitter.on('verification-progress', (e) => {
|
|
337
|
+
console.log('verification-progress', e);
|
|
338
|
+
events.push({ type: 'verification-progress', ...e });
|
|
339
|
+
});
|
|
340
|
+
emitter.on('verification-passed', (e) => events.push({ type: 'verification-passed', ...e }));
|
|
341
|
+
// tap with verification
|
|
342
|
+
const tapped = tapAndVerifyStream({
|
|
343
|
+
originalStream,
|
|
344
|
+
contentLength,
|
|
345
|
+
verifyData,
|
|
346
|
+
txId,
|
|
347
|
+
emitter,
|
|
348
|
+
});
|
|
349
|
+
// read the stream
|
|
350
|
+
const out = [];
|
|
351
|
+
for await (const chunk of tapped) {
|
|
352
|
+
out.push(chunk);
|
|
353
|
+
}
|
|
354
|
+
// assert the stream is the same
|
|
355
|
+
assert.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
|
|
356
|
+
assert.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
|
|
357
|
+
assert.ok(events.find((e) => e.type === 'verification-passed' && e.txId === txId), 'Should emit at least one verification-passed');
|
|
358
|
+
});
|
|
359
|
+
it('should throw an error on the client stream if verification fails', async () => {
|
|
360
|
+
const chunks = [
|
|
361
|
+
Buffer.from('foo'),
|
|
362
|
+
Buffer.from('bar'),
|
|
363
|
+
Buffer.from('baz'),
|
|
364
|
+
];
|
|
365
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
366
|
+
// a stream that will emit chunks
|
|
367
|
+
const originalStream = Readable.from(chunks);
|
|
368
|
+
const verifyData = async ({
|
|
369
|
+
// @ts-expect-error
|
|
370
|
+
data, txId, }) => {
|
|
371
|
+
throw new Error('Verification failed for txId: ' + txId);
|
|
372
|
+
};
|
|
373
|
+
const txId = 'test-tx-1';
|
|
374
|
+
const emitter = new EventEmitter();
|
|
375
|
+
const events = [];
|
|
376
|
+
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
377
|
+
emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
|
|
378
|
+
// tap with verification
|
|
379
|
+
const tapped = tapAndVerifyStream({
|
|
380
|
+
originalStream,
|
|
381
|
+
contentLength,
|
|
382
|
+
verifyData,
|
|
383
|
+
txId,
|
|
384
|
+
emitter,
|
|
385
|
+
});
|
|
386
|
+
// read the stream
|
|
387
|
+
try {
|
|
388
|
+
const out = [];
|
|
389
|
+
for await (const chunk of tapped) {
|
|
390
|
+
out.push(chunk);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
assert.ok(events.find((e) => e.type === 'verification-failed' && e.txId === txId), 'Should emit at least one verification-failed');
|
|
395
|
+
// stream should be closed
|
|
396
|
+
assert.ok(tapped.closed);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
describe('ReadableStream', () => {
|
|
401
|
+
it('should duplicate the ReadableStream, verify the first and return the second if verification passes', async () => {
|
|
402
|
+
// create a simple readable
|
|
403
|
+
const chunks = [
|
|
404
|
+
Buffer.from('foo'),
|
|
405
|
+
Buffer.from('bar'),
|
|
406
|
+
Buffer.from('baz'),
|
|
407
|
+
];
|
|
408
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
409
|
+
// a stream that will emit chunks
|
|
410
|
+
const originalStream = ReadableStream.from(chunks);
|
|
411
|
+
let seen = Buffer.alloc(0);
|
|
412
|
+
const verifyData = async ({ data,
|
|
413
|
+
// @ts-expect-error
|
|
414
|
+
txId, }) => {
|
|
415
|
+
return new Promise(async (resolve, reject) => {
|
|
416
|
+
const reader = data.getReader();
|
|
417
|
+
while (true) {
|
|
418
|
+
try {
|
|
419
|
+
const { done, value } = await reader.read();
|
|
420
|
+
if (done) {
|
|
421
|
+
resolve();
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
seen = Buffer.concat([seen, value]);
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
reject(error);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
const txId = 'test-tx-1';
|
|
433
|
+
const emitter = new EventEmitter();
|
|
434
|
+
const events = [];
|
|
435
|
+
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
436
|
+
emitter.on('verification-passed', (e) => events.push({ type: 'verification-passed', ...e }));
|
|
437
|
+
// tap with verification
|
|
438
|
+
const tapped = tapAndVerifyStream({
|
|
439
|
+
originalStream,
|
|
440
|
+
contentLength,
|
|
441
|
+
verifyData,
|
|
442
|
+
txId,
|
|
443
|
+
emitter,
|
|
444
|
+
});
|
|
445
|
+
// read the stream
|
|
446
|
+
const out = [];
|
|
447
|
+
for await (const chunk of tapped) {
|
|
448
|
+
out.push(chunk);
|
|
449
|
+
}
|
|
450
|
+
// assert the stream is the same
|
|
451
|
+
assert.strictEqual(Buffer.concat(out).toString(), Buffer.concat(chunks).toString(), 'The tapped stream should emit exactly the original data');
|
|
452
|
+
assert.ok(events.find((e) => e.type === 'verification-progress'), 'Should emit at least one verification-progress');
|
|
453
|
+
assert.ok(events.find((e) => e.type === 'verification-passed' && e.txId === txId), 'Should emit at least one verification-passed');
|
|
454
|
+
});
|
|
455
|
+
it('should throw an error on the client stream if verification fails', async () => {
|
|
456
|
+
const chunks = [
|
|
457
|
+
Buffer.from('foo'),
|
|
458
|
+
Buffer.from('bar'),
|
|
459
|
+
Buffer.from('baz'),
|
|
460
|
+
];
|
|
461
|
+
const contentLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
462
|
+
// a stream that will emit chunks
|
|
463
|
+
const originalStream = ReadableStream.from(chunks);
|
|
464
|
+
const verifyData = async ({
|
|
465
|
+
// @ts-expect-error
|
|
466
|
+
data, txId, }) => {
|
|
467
|
+
throw new Error('Verification failed for txId: ' + txId);
|
|
468
|
+
};
|
|
469
|
+
const txId = 'test-tx-1';
|
|
470
|
+
const emitter = new EventEmitter();
|
|
471
|
+
const events = [];
|
|
472
|
+
emitter.on('verification-progress', (e) => events.push({ type: 'verification-progress', ...e }));
|
|
473
|
+
emitter.on('verification-failed', (e) => events.push({ type: 'verification-failed', ...e }));
|
|
474
|
+
// tap with verification
|
|
475
|
+
const tapped = tapAndVerifyStream({
|
|
476
|
+
originalStream,
|
|
477
|
+
contentLength,
|
|
478
|
+
verifyData,
|
|
479
|
+
txId,
|
|
480
|
+
emitter,
|
|
481
|
+
});
|
|
482
|
+
// read the stream
|
|
483
|
+
try {
|
|
484
|
+
const out = [];
|
|
485
|
+
for await (const chunk of tapped) {
|
|
486
|
+
out.push(chunk);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
assert.ok(events.find((e) => e.type === 'verification-failed' && e.txId === txId), 'Should emit at least one verification-failed');
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
236
495
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 { createHash } from 'crypto';
|
|
17
|
+
import { toB64Url } from './base64.js';
|
|
18
|
+
export const hashReadableToB64Url = (stream, algorithm = 'sha256') => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const hash = createHash(algorithm);
|
|
21
|
+
stream.on('data', (chunk) => hash.update(chunk));
|
|
22
|
+
stream.on('end', () => resolve(toB64Url(hash.digest())));
|
|
23
|
+
stream.on('error', (err) => reject(err));
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export const hashReadableStreamToB64Url = (stream, algorithm = 'sha256') => {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const hash = createHash(algorithm);
|
|
29
|
+
const reader = stream.getReader();
|
|
30
|
+
const read = async () => {
|
|
31
|
+
try {
|
|
32
|
+
const { done, value } = await reader.read();
|
|
33
|
+
if (done) {
|
|
34
|
+
resolve(toB64Url(hash.digest()));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
hash.update(value);
|
|
38
|
+
read();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
reject(err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
read().catch(reject);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export const hashBufferToB64Url = (buffer, algorithm = 'sha256') => {
|
|
49
|
+
return toB64Url(createHash(algorithm).update(buffer).digest());
|
|
50
|
+
};
|
package/lib/esm/version.js
CHANGED
|
@@ -68,3 +68,4 @@ export declare function getAllGatewayVaults(o: PaginationCLIOptions): Promise<im
|
|
|
68
68
|
message: string;
|
|
69
69
|
}>;
|
|
70
70
|
export declare function getVault(o: AddressAndVaultIdCLIOptions): Promise<import("../../types/io.js").AoVaultData>;
|
|
71
|
+
export declare function resolveArNSName(o: NameCLIOptions): Promise<import("../../types/io.js").ArNSNameResolutionData>;
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Arweave from 'arweave';
|
|
2
|
-
import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionData, AoEpochDistributionTotalsData, AoEpochObservationData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGatewayWithAddress, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoJoinNetworkParams, AoMessageResult, AoPaginatedAddressParams, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoRegistrationFees, AoReturnedName, AoRevokeVaultParams, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, AoWeightedObserver, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
|
|
2
|
+
import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionData, AoEpochDistributionTotalsData, AoEpochObservationData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGatewayWithAddress, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoJoinNetworkParams, AoMessageResult, AoPaginatedAddressParams, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoRegistrationFees, AoReturnedName, AoRevokeVaultParams, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, AoWeightedObserver, ArNSNameResolutionData, ArNSNameResolver, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
|
|
3
3
|
import { AOProcess } from './contracts/ao-process.js';
|
|
4
4
|
import { TurboArNSPaymentProviderAuthenticated, TurboArNSPaymentProviderUnauthenticated } from './turbo.js';
|
|
5
5
|
type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>;
|
|
@@ -19,7 +19,7 @@ export declare class ARIO {
|
|
|
19
19
|
faucetUrl?: string;
|
|
20
20
|
}): ARIOWithFaucet<AoARIOWrite>;
|
|
21
21
|
}
|
|
22
|
-
export declare class ARIOReadable implements AoARIORead {
|
|
22
|
+
export declare class ARIOReadable implements AoARIORead, ArNSNameResolver {
|
|
23
23
|
readonly process: AOProcess;
|
|
24
24
|
protected epochSettings: AoEpochSettings | undefined;
|
|
25
25
|
protected arweave: Arweave;
|
|
@@ -135,6 +135,9 @@ export declare class ARIOReadable implements AoARIORead {
|
|
|
135
135
|
getGatewayRegistrySettings(): Promise<AoGatewayRegistrySettings>;
|
|
136
136
|
getAllDelegates(params?: PaginationParams<AoAllDelegates>): Promise<PaginationResult<AoAllDelegates>>;
|
|
137
137
|
getAllGatewayVaults(params?: PaginationParams<AoAllGatewayVaults>): Promise<PaginationResult<AoAllGatewayVaults>>;
|
|
138
|
+
resolveArNSName({ name, }: {
|
|
139
|
+
name: string;
|
|
140
|
+
}): Promise<ArNSNameResolutionData>;
|
|
138
141
|
}
|
|
139
142
|
export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
|
|
140
143
|
private signer;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { DataHashProvider, DataRootProvider } from '../../../types/wayfinder.js';
|
|
17
|
+
import { GatewaysProvider } from '../gateways.js';
|
|
18
|
+
export declare class TrustedGatewaysHashProvider implements DataHashProvider, DataRootProvider {
|
|
19
|
+
private gatewaysProvider;
|
|
20
|
+
constructor({ gatewaysProvider, }: {
|
|
21
|
+
gatewaysProvider: GatewaysProvider;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Gets the digest for a given txId from all trusted gateways and ensures they all match.
|
|
25
|
+
* @param txId - The txId to get the digest for.
|
|
26
|
+
* @returns The digest for the given txId.
|
|
27
|
+
*/
|
|
28
|
+
getHash({ txId, }: {
|
|
29
|
+
txId: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
hash: string;
|
|
32
|
+
algorithm: 'sha256';
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Get the data root for a given txId from all trusted gateways and ensure they all match.
|
|
36
|
+
* @param txId - The txId to get the data root for.
|
|
37
|
+
* @returns The data root for the given txId.
|
|
38
|
+
*/
|
|
39
|
+
getDataRoot({ txId }: {
|
|
40
|
+
txId: string;
|
|
41
|
+
}): Promise<string>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Note from @djwhitt
|
|
45
|
+
*
|
|
46
|
+
* Calculating data roots this way is fine, but it may not reproduce the original data root.
|
|
47
|
+
* We could also implement a data root verifier that pulls all the chunks, checks that they
|
|
48
|
+
* reproduce the expected data root, and then compares the concatenated chunk data to the
|
|
49
|
+
* original data retrieved. That would take a while, but it should be able to verify any L1
|
|
50
|
+
* data where we can find the chunks.
|
|
51
|
+
*/
|
|
@@ -18,3 +18,6 @@ export * from './routers/random.js';
|
|
|
18
18
|
export * from './routers/priority.js';
|
|
19
19
|
export * from './routers/static.js';
|
|
20
20
|
export * from './gateways.js';
|
|
21
|
+
export * from './gateways/trusted-gateways.js';
|
|
22
|
+
export * from './verification/data-root-verifier.js';
|
|
23
|
+
export * from './verification/hash-verifier.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { DataRootProvider, DataVerifier } from '../../../types/wayfinder.js';
|
|
3
|
+
export declare function convertBufferToDataRoot({ buffer, }: {
|
|
4
|
+
buffer: Buffer;
|
|
5
|
+
}): Promise<string>;
|
|
6
|
+
export declare const convertReadableToDataRoot: <T extends AsyncIterable<Uint8Array>>({ iterable, }: {
|
|
7
|
+
iterable: T;
|
|
8
|
+
}) => Promise<string>;
|
|
9
|
+
export declare class DataRootVerifier implements DataVerifier {
|
|
10
|
+
private readonly trustedDataRootProvider;
|
|
11
|
+
constructor({ trustedDataRootProvider, }: {
|
|
12
|
+
trustedDataRootProvider: DataRootProvider;
|
|
13
|
+
});
|
|
14
|
+
verifyData({ data, txId, }: {
|
|
15
|
+
data: Buffer | Readable | ReadableStream;
|
|
16
|
+
txId: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* - when you get a signature of a data item, you can only verify the owner
|
|
21
|
+
* - you still need to verify it's going back to the bundle, unpack it, and verify the data item exists at the offset
|
|
22
|
+
* - you need to the location of the chunks for the data item, and prove it's in the chunk and then prove the data root of the bundle, then you have fully verified the data verifier
|
|
23
|
+
* - how to prove the data item is on arweave - verify the merkle hash that the chunks for the data item, fit within the expected tree of the parent bundle
|
|
24
|
+
*
|
|
25
|
+
* Composite verifier - you'll want to be very efficient with streams
|
|
26
|
+
* - hash verifier
|
|
27
|
+
* - parent chunks verifier --> for any range of data within a single transaction, tell me that it's correct
|
|
28
|
+
* - signature verifier
|
|
29
|
+
* - offset verifier
|
|
30
|
+
* - data item verifier
|
|
31
|
+
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { Readable } from 'node:stream';
|
|
17
|
+
import { DataHashProvider, DataVerifier } from '../../../types/wayfinder.js';
|
|
18
|
+
export declare class HashVerifier implements DataVerifier {
|
|
19
|
+
private readonly trustedHashProvider;
|
|
20
|
+
constructor({ trustedHashProvider, }: {
|
|
21
|
+
trustedHashProvider: DataHashProvider;
|
|
22
|
+
});
|
|
23
|
+
verifyData({ data, txId, }: {
|
|
24
|
+
data: Buffer | Readable | ReadableStream;
|
|
25
|
+
txId: string;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
}
|