@ar.io/sdk 3.11.0-beta.1 → 3.11.1-alpha.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 (81) hide show
  1. package/README.md +2 -0
  2. package/bundles/web.bundle.min.js +258 -170
  3. package/lib/cjs/cli/utils.js +2 -0
  4. package/lib/cjs/common/ant-versions.js +3 -2
  5. package/lib/cjs/common/contracts/ao-process.js +3 -1
  6. package/lib/cjs/common/index.js +0 -2
  7. package/lib/cjs/common/io.js +17 -9
  8. package/lib/cjs/common/turbo.js +1 -1
  9. package/lib/cjs/types/index.js +0 -1
  10. package/lib/cjs/utils/ao.js +8 -3
  11. package/lib/cjs/utils/processes.js +3 -1
  12. package/lib/cjs/version.js +1 -1
  13. package/lib/esm/cli/utils.js +2 -0
  14. package/lib/esm/common/ant-versions.js +3 -2
  15. package/lib/esm/common/contracts/ao-process.js +3 -1
  16. package/lib/esm/common/index.js +0 -2
  17. package/lib/esm/common/io.js +17 -9
  18. package/lib/esm/common/turbo.js +1 -1
  19. package/lib/esm/types/index.js +0 -1
  20. package/lib/esm/utils/ao.js +8 -3
  21. package/lib/esm/utils/processes.js +3 -1
  22. package/lib/esm/version.js +1 -1
  23. package/lib/types/common/ant-versions.d.ts +3 -5
  24. package/lib/types/common/index.d.ts +0 -1
  25. package/lib/types/types/index.d.ts +0 -1
  26. package/lib/types/version.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/lib/cjs/common/wayfinder/gateways/network.js +0 -48
  29. package/lib/cjs/common/wayfinder/gateways/simple-cache.js +0 -35
  30. package/lib/cjs/common/wayfinder/gateways/static.js +0 -13
  31. package/lib/cjs/common/wayfinder/index.js +0 -47
  32. package/lib/cjs/common/wayfinder/routing/strategies/ping.js +0 -72
  33. package/lib/cjs/common/wayfinder/routing/strategies/ping.test.js +0 -156
  34. package/lib/cjs/common/wayfinder/routing/strategies/random.js +0 -13
  35. package/lib/cjs/common/wayfinder/routing/strategies/random.test.js +0 -68
  36. package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +0 -42
  37. package/lib/cjs/common/wayfinder/routing/strategies/round-robin.test.js +0 -78
  38. package/lib/cjs/common/wayfinder/routing/strategies/static.js +0 -29
  39. package/lib/cjs/common/wayfinder/routing/strategies/static.test.js +0 -40
  40. package/lib/cjs/common/wayfinder/verification/strategies/data-root-verifier.js +0 -139
  41. package/lib/cjs/common/wayfinder/verification/strategies/hash-verifier.js +0 -50
  42. package/lib/cjs/common/wayfinder/verification/trusted.js +0 -106
  43. package/lib/cjs/common/wayfinder/wayfinder.js +0 -736
  44. package/lib/cjs/common/wayfinder/wayfinder.test.js +0 -519
  45. package/lib/cjs/types/wayfinder.js +0 -3
  46. package/lib/esm/common/wayfinder/gateways/network.js +0 -44
  47. package/lib/esm/common/wayfinder/gateways/simple-cache.js +0 -31
  48. package/lib/esm/common/wayfinder/gateways/static.js +0 -9
  49. package/lib/esm/common/wayfinder/index.js +0 -31
  50. package/lib/esm/common/wayfinder/routing/strategies/ping.js +0 -68
  51. package/lib/esm/common/wayfinder/routing/strategies/ping.test.js +0 -151
  52. package/lib/esm/common/wayfinder/routing/strategies/random.js +0 -9
  53. package/lib/esm/common/wayfinder/routing/strategies/random.test.js +0 -63
  54. package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +0 -38
  55. package/lib/esm/common/wayfinder/routing/strategies/round-robin.test.js +0 -73
  56. package/lib/esm/common/wayfinder/routing/strategies/static.js +0 -25
  57. package/lib/esm/common/wayfinder/routing/strategies/static.test.js +0 -35
  58. package/lib/esm/common/wayfinder/verification/strategies/data-root-verifier.js +0 -130
  59. package/lib/esm/common/wayfinder/verification/strategies/hash-verifier.js +0 -46
  60. package/lib/esm/common/wayfinder/verification/trusted.js +0 -102
  61. package/lib/esm/common/wayfinder/wayfinder.js +0 -724
  62. package/lib/esm/common/wayfinder/wayfinder.test.js +0 -514
  63. package/lib/esm/types/wayfinder.js +0 -2
  64. package/lib/types/common/wayfinder/gateways/network.d.ts +0 -33
  65. package/lib/types/common/wayfinder/gateways/simple-cache.d.ts +0 -31
  66. package/lib/types/common/wayfinder/gateways/static.d.ts +0 -23
  67. package/lib/types/common/wayfinder/index.d.ts +0 -26
  68. package/lib/types/common/wayfinder/routing/strategies/ping.d.ts +0 -27
  69. package/lib/types/common/wayfinder/routing/strategies/ping.test.d.ts +0 -1
  70. package/lib/types/common/wayfinder/routing/strategies/random.d.ts +0 -21
  71. package/lib/types/common/wayfinder/routing/strategies/random.test.d.ts +0 -1
  72. package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +0 -29
  73. package/lib/types/common/wayfinder/routing/strategies/round-robin.test.d.ts +0 -1
  74. package/lib/types/common/wayfinder/routing/strategies/static.d.ts +0 -29
  75. package/lib/types/common/wayfinder/routing/strategies/static.test.d.ts +0 -1
  76. package/lib/types/common/wayfinder/verification/strategies/data-root-verifier.d.ts +0 -31
  77. package/lib/types/common/wayfinder/verification/strategies/hash-verifier.d.ts +0 -27
  78. package/lib/types/common/wayfinder/verification/trusted.d.ts +0 -51
  79. package/lib/types/common/wayfinder/wayfinder.d.ts +0 -299
  80. package/lib/types/common/wayfinder/wayfinder.test.d.ts +0 -1
  81. package/lib/types/types/wayfinder.d.ts +0 -66
@@ -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
- */