@ar.io/sdk 3.12.0-beta.1 → 3.12.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 (47) hide show
  1. package/bundles/web.bundle.min.js +167 -170
  2. package/lib/cjs/common/index.js +0 -2
  3. package/lib/cjs/version.js +1 -1
  4. package/lib/esm/common/index.js +0 -2
  5. package/lib/esm/version.js +1 -1
  6. package/lib/types/common/index.d.ts +0 -1
  7. package/lib/types/version.d.ts +1 -1
  8. package/package.json +2 -1
  9. package/lib/cjs/common/wayfinder/gateways/network.js +0 -48
  10. package/lib/cjs/common/wayfinder/gateways/simple-cache.js +0 -35
  11. package/lib/cjs/common/wayfinder/gateways/static.js +0 -13
  12. package/lib/cjs/common/wayfinder/index.js +0 -47
  13. package/lib/cjs/common/wayfinder/routing/strategies/ping.js +0 -72
  14. package/lib/cjs/common/wayfinder/routing/strategies/random.js +0 -13
  15. package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +0 -42
  16. package/lib/cjs/common/wayfinder/routing/strategies/static.js +0 -29
  17. package/lib/cjs/common/wayfinder/verification/strategies/data-root-verifier.js +0 -139
  18. package/lib/cjs/common/wayfinder/verification/strategies/hash-verifier.js +0 -50
  19. package/lib/cjs/common/wayfinder/verification/trusted.js +0 -106
  20. package/lib/cjs/common/wayfinder/wayfinder.js +0 -735
  21. package/lib/cjs/types/wayfinder.js +0 -3
  22. package/lib/esm/common/wayfinder/gateways/network.js +0 -44
  23. package/lib/esm/common/wayfinder/gateways/simple-cache.js +0 -31
  24. package/lib/esm/common/wayfinder/gateways/static.js +0 -9
  25. package/lib/esm/common/wayfinder/index.js +0 -31
  26. package/lib/esm/common/wayfinder/routing/strategies/ping.js +0 -68
  27. package/lib/esm/common/wayfinder/routing/strategies/random.js +0 -9
  28. package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +0 -38
  29. package/lib/esm/common/wayfinder/routing/strategies/static.js +0 -25
  30. package/lib/esm/common/wayfinder/verification/strategies/data-root-verifier.js +0 -130
  31. package/lib/esm/common/wayfinder/verification/strategies/hash-verifier.js +0 -46
  32. package/lib/esm/common/wayfinder/verification/trusted.js +0 -102
  33. package/lib/esm/common/wayfinder/wayfinder.js +0 -723
  34. package/lib/esm/types/wayfinder.js +0 -2
  35. package/lib/types/common/wayfinder/gateways/network.d.ts +0 -33
  36. package/lib/types/common/wayfinder/gateways/simple-cache.d.ts +0 -31
  37. package/lib/types/common/wayfinder/gateways/static.d.ts +0 -23
  38. package/lib/types/common/wayfinder/index.d.ts +0 -26
  39. package/lib/types/common/wayfinder/routing/strategies/ping.d.ts +0 -27
  40. package/lib/types/common/wayfinder/routing/strategies/random.d.ts +0 -21
  41. package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +0 -29
  42. package/lib/types/common/wayfinder/routing/strategies/static.d.ts +0 -29
  43. package/lib/types/common/wayfinder/verification/strategies/data-root-verifier.d.ts +0 -31
  44. package/lib/types/common/wayfinder/verification/strategies/hash-verifier.d.ts +0 -27
  45. package/lib/types/common/wayfinder/verification/trusted.d.ts +0 -51
  46. package/lib/types/common/wayfinder/wayfinder.d.ts +0 -299
  47. package/lib/types/types/wayfinder.d.ts +0 -66
@@ -38,5 +38,3 @@ __exportStar(require("./faucet.js"), exports);
38
38
  // ao
39
39
  __exportStar(require("./io.js"), exports);
40
40
  __exportStar(require("./contracts/ao-process.js"), exports);
41
- // wayfinder
42
- __exportStar(require("./wayfinder/index.js"), exports);
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.12.0-beta.1';
20
+ exports.version = '3.12.1';
@@ -22,5 +22,3 @@ export * from './faucet.js';
22
22
  // ao
23
23
  export * from './io.js';
24
24
  export * from './contracts/ao-process.js';
25
- // wayfinder
26
- export * from './wayfinder/index.js';
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.12.0-beta.1';
17
+ export const version = '3.12.1';
@@ -21,4 +21,3 @@ export * from './ant-versions.js';
21
21
  export * from './faucet.js';
22
22
  export * from './io.js';
23
23
  export * from './contracts/ao-process.js';
24
- export * from './wayfinder/index.js';
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.12.0-alpha.2";
16
+ export declare const version = "3.12.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.12.0-beta.1",
3
+ "version": "3.12.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -136,6 +136,7 @@
136
136
  "eventemitter3": "^5.0.1",
137
137
  "plimit-lit": "^3.0.1",
138
138
  "prompts": "^2.4.2",
139
+ "uuid": "^11.1.0",
139
140
  "winston": "^3.13.0",
140
141
  "zod": "^3.23.8"
141
142
  },
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NetworkGatewaysProvider = void 0;
4
- const io_js_1 = require("../../io.js");
5
- class NetworkGatewaysProvider {
6
- ario;
7
- sortBy;
8
- sortOrder;
9
- limit;
10
- filter;
11
- constructor({ ario = io_js_1.ARIO.mainnet(), sortBy = 'operatorStake', sortOrder = 'desc', limit = 1000, filter = (g) => g.status === 'joined', }) {
12
- this.ario = ario;
13
- this.sortBy = sortBy;
14
- this.sortOrder = sortOrder;
15
- this.limit = limit;
16
- this.filter = filter;
17
- }
18
- async getGateways() {
19
- let cursor;
20
- let attempts = 0;
21
- const gateways = [];
22
- do {
23
- try {
24
- const { items: newGateways = [], nextCursor } = await this.ario.getGateways({
25
- limit: 1000,
26
- cursor,
27
- sortBy: this.sortBy,
28
- sortOrder: this.sortOrder,
29
- });
30
- gateways.push(...newGateways);
31
- cursor = nextCursor;
32
- attempts = 0; // reset attempts if we get a new cursor
33
- }
34
- catch (error) {
35
- console.error('Error fetching gateways', {
36
- cursor,
37
- attempts,
38
- error,
39
- });
40
- attempts++;
41
- }
42
- } while (cursor !== undefined && attempts < 3);
43
- // filter out any gateways that are not joined
44
- const filteredGateways = gateways.filter(this.filter).slice(0, this.limit);
45
- return filteredGateways.map((g) => new URL(`${g.settings.protocol}://${g.settings.fqdn}:${g.settings.port}`));
46
- }
47
- }
48
- exports.NetworkGatewaysProvider = NetworkGatewaysProvider;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimpleCacheGatewaysProvider = void 0;
4
- const index_js_1 = require("../../../web/index.js");
5
- class SimpleCacheGatewaysProvider {
6
- gatewaysProvider;
7
- ttlSeconds;
8
- lastUpdated;
9
- gatewaysCache;
10
- logger;
11
- constructor({ gatewaysProvider, ttlSeconds = 60 * 60, // 1 hour
12
- logger = index_js_1.Logger.default, }) {
13
- this.gatewaysCache = [];
14
- this.gatewaysProvider = gatewaysProvider;
15
- this.ttlSeconds = ttlSeconds;
16
- this.logger = logger;
17
- }
18
- async getGateways() {
19
- const now = Date.now();
20
- if (this.gatewaysCache.length === 0 ||
21
- now - this.lastUpdated > this.ttlSeconds * 1000) {
22
- try {
23
- // preserve the cache if the fetch fails
24
- const allGateways = await this.gatewaysProvider.getGateways();
25
- this.gatewaysCache = allGateways;
26
- this.lastUpdated = now;
27
- }
28
- catch (error) {
29
- this.logger.error('Error fetching gateways', error);
30
- }
31
- }
32
- return this.gatewaysCache;
33
- }
34
- }
35
- exports.SimpleCacheGatewaysProvider = SimpleCacheGatewaysProvider;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StaticGatewaysProvider = void 0;
4
- class StaticGatewaysProvider {
5
- gateways;
6
- constructor({ gateways }) {
7
- this.gateways = gateways.map((g) => new URL(g));
8
- }
9
- async getGateways() {
10
- return this.gateways;
11
- }
12
- }
13
- exports.StaticGatewaysProvider = StaticGatewaysProvider;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
19
- *
20
- * Licensed under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License.
22
- * You may obtain a copy of the License at
23
- *
24
- * http://www.apache.org/licenses/LICENSE-2.0
25
- *
26
- * Unless required by applicable law or agreed to in writing, software
27
- * distributed under the License is distributed on an "AS IS" BASIS,
28
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
- * See the License for the specific language governing permissions and
30
- * limitations under the License.
31
- */
32
- __exportStar(require("./wayfinder.js"), exports);
33
- // routing strategies
34
- __exportStar(require("./routing/strategies/random.js"), exports);
35
- __exportStar(require("./routing/strategies/static.js"), exports);
36
- __exportStar(require("./routing/strategies/ping.js"), exports);
37
- __exportStar(require("./routing/strategies/round-robin.js"), exports);
38
- // gateways providers
39
- __exportStar(require("./gateways/network.js"), exports);
40
- __exportStar(require("./gateways/simple-cache.js"), exports);
41
- __exportStar(require("./gateways/static.js"), exports);
42
- // trusted gateways
43
- __exportStar(require("./verification/trusted.js"), exports);
44
- // hash providers
45
- __exportStar(require("./verification/strategies/data-root-verifier.js"), exports);
46
- __exportStar(require("./verification/strategies/hash-verifier.js"), exports);
47
- // TODO: signature verification
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FastestPingRoutingStrategy = void 0;
4
- class FastestPingRoutingStrategy {
5
- timeoutMs;
6
- probePath;
7
- constructor({ timeoutMs = 500, probePath = '/ar-io/info', // TODO: limit to allowed /ar-io and arweave node endpoints
8
- } = {}) {
9
- this.timeoutMs = timeoutMs;
10
- this.probePath = probePath;
11
- }
12
- async selectGateway({ gateways }) {
13
- if (gateways.length === 0) {
14
- throw new Error('No gateways provided');
15
- }
16
- try {
17
- const results = await Promise.allSettled(gateways.map(async (gateway) => {
18
- try {
19
- const startTime = Date.now();
20
- const response = await fetch(`${gateway.toString().replace(/\/$/, '')}${this.probePath}`, {
21
- method: 'HEAD',
22
- signal: AbortSignal.timeout(this.timeoutMs),
23
- });
24
- const endTime = Date.now();
25
- const durationMs = endTime - startTime;
26
- return {
27
- gateway,
28
- status: response.status,
29
- durationMs,
30
- error: null,
31
- };
32
- }
33
- catch (error) {
34
- // Handle network errors
35
- return {
36
- gateway,
37
- status: 'rejected',
38
- durationMs: Infinity,
39
- error,
40
- };
41
- }
42
- }));
43
- // Process results
44
- const processedResults = results.map((result, index) => {
45
- if (result.status === 'fulfilled') {
46
- return result.value;
47
- }
48
- else {
49
- return {
50
- gateway: gateways[index],
51
- status: 'rejected',
52
- durationMs: Infinity,
53
- error: result.reason,
54
- };
55
- }
56
- });
57
- // Filter healthy gateways and sort by latency
58
- const healthyGateways = processedResults
59
- .filter((result) => result.status === 200)
60
- .sort((a, b) => a.durationMs - b.durationMs);
61
- if (healthyGateways.length > 0) {
62
- return healthyGateways[0].gateway;
63
- }
64
- throw new Error('No healthy gateways found');
65
- }
66
- catch (error) {
67
- throw new Error('Failed to ping gateways: ' +
68
- (error instanceof Error ? error.message : String(error)));
69
- }
70
- }
71
- }
72
- exports.FastestPingRoutingStrategy = FastestPingRoutingStrategy;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RandomRoutingStrategy = void 0;
4
- const random_js_1 = require("../../../../utils/random.js");
5
- class RandomRoutingStrategy {
6
- async selectGateway({ gateways }) {
7
- if (gateways.length === 0) {
8
- throw new Error('No gateways available');
9
- }
10
- return gateways[(0, random_js_1.randomInt)(0, gateways.length)];
11
- }
12
- }
13
- exports.RandomRoutingStrategy = RandomRoutingStrategy;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoundRobinRoutingStrategy = void 0;
4
- /**
5
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const logger_js_1 = require("../../../../common/logger.js");
20
- class RoundRobinRoutingStrategy {
21
- gateways;
22
- currentIndex;
23
- logger;
24
- constructor({ gateways, logger = logger_js_1.Logger.default, }) {
25
- this.gateways = gateways;
26
- this.currentIndex = 0;
27
- this.logger = logger;
28
- }
29
- // provided gateways are ignored
30
- async selectGateway({ gateways = [], } = {}) {
31
- if (gateways.length > 0) {
32
- this.logger.warn('RoundRobinRoutingStrategy does not accept provided gateways. Ignoring provided gateways...', {
33
- providedGateways: gateways.length,
34
- internalGateways: this.gateways,
35
- });
36
- }
37
- const gateway = this.gateways[this.currentIndex];
38
- this.currentIndex = (this.currentIndex + 1) % this.gateways.length;
39
- return gateway;
40
- }
41
- }
42
- exports.RoundRobinRoutingStrategy = RoundRobinRoutingStrategy;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StaticRoutingStrategy = void 0;
4
- const logger_js_1 = require("../../../logger.js");
5
- class StaticRoutingStrategy {
6
- name = 'static';
7
- gateway;
8
- logger;
9
- constructor({ gateway, logger = logger_js_1.Logger.default, }) {
10
- try {
11
- this.gateway = new URL(gateway);
12
- }
13
- catch (error) {
14
- throw new Error(`Invalid URL provided for static gateway: ${gateway}`);
15
- }
16
- this.logger = logger;
17
- }
18
- // provided gateways are ignored
19
- async selectGateway({ gateways = [], } = {}) {
20
- if (gateways.length > 0) {
21
- this.logger.warn('StaticRoutingStrategy does not accept provided gateways. Ignoring provided gateways...', {
22
- providedGateways: gateways.length,
23
- internalGateway: this.gateway,
24
- });
25
- }
26
- return this.gateway;
27
- }
28
- }
29
- exports.StaticRoutingStrategy = StaticRoutingStrategy;
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DataRootVerificationStrategy = exports.convertReadableToDataRoot = void 0;
7
- exports.convertBufferToDataRoot = convertBufferToDataRoot;
8
- /**
9
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
- const arweave_1 = __importDefault(require("arweave"));
24
- const merkle_js_1 = require("arweave/node/lib/merkle.js");
25
- const node_stream_1 = require("node:stream");
26
- const base64_js_1 = require("../../../../utils/base64.js");
27
- async function convertBufferToDataRoot({ buffer, }) {
28
- const chunks = [];
29
- let cursor = 0;
30
- let offset = 0;
31
- while (offset < buffer.byteLength) {
32
- let chunkSize = Math.min(merkle_js_1.MAX_CHUNK_SIZE, buffer.byteLength - offset);
33
- const remainder = buffer.byteLength - offset - chunkSize;
34
- if (remainder > 0 && remainder < merkle_js_1.MIN_CHUNK_SIZE) {
35
- chunkSize = Math.ceil((buffer.byteLength - offset) / 2);
36
- }
37
- // subarray does not exist on web Buffer type
38
- const slice = buffer.subarray(offset, offset + chunkSize);
39
- const hash = await crypto.subtle.digest('SHA-256', slice);
40
- const hashArray = new Uint8Array(hash);
41
- chunks.push({
42
- dataHash: hashArray,
43
- minByteRange: cursor,
44
- maxByteRange: cursor + chunkSize,
45
- });
46
- cursor += chunkSize;
47
- offset += chunkSize;
48
- }
49
- const leaves = await (0, merkle_js_1.generateLeaves)(chunks);
50
- const result = await (0, merkle_js_1.buildLayers)(leaves);
51
- return Buffer.from(result.id).toString('base64url');
52
- }
53
- const convertReadableToDataRoot = async ({ iterable, }) => {
54
- const chunks = [];
55
- let leftover = new Uint8Array(0);
56
- let cursor = 0;
57
- for await (const data of iterable) {
58
- const inputChunk = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
59
- const combined = new Uint8Array(leftover.length + inputChunk.length);
60
- combined.set(leftover, 0);
61
- combined.set(inputChunk, leftover.length);
62
- let startIndex = 0;
63
- while (combined.length - startIndex >= merkle_js_1.MAX_CHUNK_SIZE) {
64
- let chunkSize = merkle_js_1.MAX_CHUNK_SIZE;
65
- const remainderAfterThis = combined.length - startIndex - merkle_js_1.MAX_CHUNK_SIZE;
66
- if (remainderAfterThis > 0 && remainderAfterThis < merkle_js_1.MIN_CHUNK_SIZE) {
67
- chunkSize = Math.ceil((combined.length - startIndex) / 2);
68
- }
69
- const chunkData = combined.slice(startIndex, startIndex + chunkSize);
70
- const dataHash = await arweave_1.default.crypto.hash(chunkData);
71
- chunks.push({
72
- dataHash,
73
- minByteRange: cursor,
74
- maxByteRange: cursor + chunkSize,
75
- });
76
- cursor += chunkSize;
77
- startIndex += chunkSize;
78
- }
79
- leftover = combined.slice(startIndex);
80
- }
81
- if (leftover.length > 0) {
82
- const dataHash = await arweave_1.default.crypto.hash(leftover);
83
- chunks.push({
84
- dataHash,
85
- minByteRange: cursor,
86
- maxByteRange: cursor + leftover.length,
87
- });
88
- }
89
- const leaves = await (0, merkle_js_1.generateLeaves)(chunks);
90
- const root = await (0, merkle_js_1.buildLayers)(leaves);
91
- return (0, base64_js_1.toB64Url)(Buffer.from(root.id));
92
- };
93
- exports.convertReadableToDataRoot = convertReadableToDataRoot;
94
- class DataRootVerificationStrategy {
95
- trustedDataRootProvider;
96
- constructor({ trustedDataRootProvider, }) {
97
- this.trustedDataRootProvider = trustedDataRootProvider;
98
- }
99
- async verifyData({ data, txId, }) {
100
- const trustedDataRootPromise = this.trustedDataRootProvider.getDataRoot({
101
- txId,
102
- });
103
- let computedDataRoot;
104
- if (Buffer.isBuffer(data)) {
105
- computedDataRoot = await convertBufferToDataRoot({ buffer: data });
106
- }
107
- else if (data instanceof node_stream_1.Readable || data instanceof ReadableStream) {
108
- computedDataRoot = await (0, exports.convertReadableToDataRoot)({ iterable: data });
109
- }
110
- if (computedDataRoot === undefined) {
111
- throw new Error('Data root could not be computed');
112
- }
113
- const trustedDataRoot = await trustedDataRootPromise;
114
- if (computedDataRoot !== trustedDataRoot) {
115
- throw new Error('Data root does not match', {
116
- cause: { computedDataRoot, trustedDataRoot },
117
- });
118
- }
119
- }
120
- }
121
- exports.DataRootVerificationStrategy = DataRootVerificationStrategy;
122
- // some data item options
123
- // compute and verify data root, use offsets from server and verify the signature that the data item at the offset matches the signature
124
- // does not give you assurance of valid bundle, but gives verification that the data item itself is valid
125
- // reading from offsets is the only way for the client to compute and verify the signature
126
- /**
127
- * - when you get a signature of a data item, you can only verify the owner
128
- * - you still need to verify it's going back to the bundle, unpack it, and verify the data item exists at the offset
129
- * - 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
130
- * - 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
131
- *
132
- * Composite verifier - you'll want to be very efficient with streams
133
- * - hash verifier
134
- * - parent chunks verifier --> for any range of data within a single transaction, tell me that it's correct
135
- * - signature verifier
136
- * - offset verifier
137
- * - data item verifier
138
- */
139
- // introduce a composite verifier that determines where/how to lookup the hash
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HashVerificationStrategy = void 0;
4
- /**
5
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const node_stream_1 = require("node:stream");
20
- const hash_js_1 = require("../../../../utils/hash.js");
21
- class HashVerificationStrategy {
22
- trustedHashProvider;
23
- constructor({ trustedHashProvider, }) {
24
- this.trustedHashProvider = trustedHashProvider;
25
- }
26
- async verifyData({ data, txId, }) {
27
- const hashPromise = this.trustedHashProvider.getHash({ txId });
28
- let computedHash;
29
- if (Buffer.isBuffer(data)) {
30
- computedHash = (0, hash_js_1.hashBufferToB64Url)(data);
31
- }
32
- else if (data instanceof node_stream_1.Readable) {
33
- computedHash = await (0, hash_js_1.hashReadableToB64Url)(data);
34
- }
35
- else if (data instanceof ReadableStream) {
36
- computedHash = await (0, hash_js_1.hashReadableStreamToB64Url)(data);
37
- }
38
- // await on the hash promise and compare to get a little concurrency when computing hashes over larger data
39
- const { hash } = await hashPromise;
40
- if (computedHash === undefined) {
41
- throw new Error('Hash could not be computed');
42
- }
43
- if (computedHash !== hash) {
44
- throw new Error('Hash does not match', {
45
- cause: { computedHash, trustedHash: hash },
46
- });
47
- }
48
- }
49
- }
50
- exports.HashVerificationStrategy = HashVerificationStrategy;
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrustedGatewaysHashProvider = void 0;
4
- const arioGatewayHeaders = {
5
- digest: 'x-ar-io-digest',
6
- verified: 'x-ar-io-verified',
7
- txId: 'x-arns-resolved-tx-id',
8
- processId: 'x-arns-resolved-process-id',
9
- };
10
- class TrustedGatewaysHashProvider {
11
- gatewaysProvider;
12
- constructor({ gatewaysProvider,
13
- // TODO: add threshold for allowed hash difference (i.e. by count or ratio of total gateways checked)
14
- }) {
15
- this.gatewaysProvider = gatewaysProvider;
16
- }
17
- /**
18
- * Gets the digest for a given txId from all trusted gateways and ensures they all match.
19
- * @param txId - The txId to get the digest for.
20
- * @returns The digest for the given txId.
21
- */
22
- async getHash({ txId, }) {
23
- // get the hash from every gateway, and ensure they all match
24
- const hashSet = new Set();
25
- const hashResults = [];
26
- const gateways = await this.gatewaysProvider.getGateways();
27
- const hashes = await Promise.all(gateways.map(async (gateway) => {
28
- const response = await fetch(`${gateway.toString()}${txId}`, {
29
- method: 'HEAD',
30
- redirect: 'follow',
31
- });
32
- if (!response.ok) {
33
- // skip this gateway
34
- return undefined;
35
- }
36
- const txIdHash = response.headers.get(arioGatewayHeaders.digest);
37
- if (txIdHash === null || txIdHash === undefined) {
38
- // skip this gateway
39
- return undefined;
40
- }
41
- hashResults.push({
42
- gateway: gateway.hostname,
43
- txIdHash,
44
- });
45
- return txIdHash;
46
- }));
47
- for (const hash of hashes) {
48
- if (hash !== undefined) {
49
- hashSet.add(hash);
50
- }
51
- }
52
- if (hashSet.size === 0) {
53
- throw new Error(`No trusted gateways returned a hash for txId ${txId}`);
54
- }
55
- if (hashSet.size > 1) {
56
- throw new Error(`Failed to get consistent hash from all trusted gateways. ${JSON.stringify(hashResults)}`);
57
- }
58
- return { hash: hashResults[0].txIdHash, algorithm: 'sha256' };
59
- }
60
- /**
61
- * Get the data root for a given txId from all trusted gateways and ensure they all match.
62
- * @param txId - The txId to get the data root for.
63
- * @returns The data root for the given txId.
64
- */
65
- async getDataRoot({ txId }) {
66
- const dataRootSet = new Set();
67
- const dataRootResults = [];
68
- const gateways = await this.gatewaysProvider.getGateways();
69
- const dataRoots = await Promise.all(gateways.map(async (gateway) => {
70
- const response = await fetch(`${gateway.toString()}tx/${txId}/data_root`);
71
- if (!response.ok) {
72
- // skip this gateway
73
- return undefined;
74
- }
75
- const dataRoot = await response.text();
76
- dataRootResults.push({
77
- gateway: gateway.hostname,
78
- dataRoot,
79
- });
80
- return dataRoot;
81
- }));
82
- for (const dataRoot of dataRoots) {
83
- if (dataRoot !== undefined) {
84
- dataRootSet.add(dataRoot);
85
- }
86
- }
87
- if (dataRootSet.size > 1) {
88
- throw new Error(`Failed to get consistent data root from all trusted gateways. ${JSON.stringify(dataRootResults)}`);
89
- }
90
- return dataRootSet.values().next().value;
91
- }
92
- }
93
- exports.TrustedGatewaysHashProvider = TrustedGatewaysHashProvider;
94
- // client could check hashes of data items, match expected hash
95
- // if the gateway has the hash and they've verified it, you can trust the data item and offset
96
- // you would be only trusting the gateway that it is a valid bundle
97
- // you can request the offset from the gateway to verify the id
98
- /**
99
- * Note from @djwhitt
100
- *
101
- * Calculating data roots this way is fine, but it may not reproduce the original data root.
102
- * We could also implement a data root verifier that pulls all the chunks, checks that they
103
- * reproduce the expected data root, and then compares the concatenated chunk data to the
104
- * original data retrieved. That would take a while, but it should be able to verify any L1
105
- * data where we can find the chunks.
106
- */