@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,102 +0,0 @@
1
- const arioGatewayHeaders = {
2
- digest: 'x-ar-io-digest',
3
- verified: 'x-ar-io-verified',
4
- txId: 'x-arns-resolved-tx-id',
5
- processId: 'x-arns-resolved-process-id',
6
- };
7
- export class TrustedGatewaysHashProvider {
8
- gatewaysProvider;
9
- constructor({ gatewaysProvider,
10
- // TODO: add threshold for allowed hash difference (i.e. by count or ratio of total gateways checked)
11
- }) {
12
- this.gatewaysProvider = gatewaysProvider;
13
- }
14
- /**
15
- * Gets the digest for a given txId from all trusted gateways and ensures they all match.
16
- * @param txId - The txId to get the digest for.
17
- * @returns The digest for the given txId.
18
- */
19
- async getHash({ txId, }) {
20
- // get the hash from every gateway, and ensure they all match
21
- const hashSet = new Set();
22
- const hashResults = [];
23
- const gateways = await this.gatewaysProvider.getGateways();
24
- const hashes = await Promise.all(gateways.map(async (gateway) => {
25
- const response = await fetch(`${gateway.toString()}${txId}`, {
26
- method: 'HEAD',
27
- redirect: 'follow',
28
- });
29
- if (!response.ok) {
30
- // skip this gateway
31
- return undefined;
32
- }
33
- const txIdHash = response.headers.get(arioGatewayHeaders.digest);
34
- if (txIdHash === null || txIdHash === undefined) {
35
- // skip this gateway
36
- return undefined;
37
- }
38
- hashResults.push({
39
- gateway: gateway.hostname,
40
- txIdHash,
41
- });
42
- return txIdHash;
43
- }));
44
- for (const hash of hashes) {
45
- if (hash !== undefined) {
46
- hashSet.add(hash);
47
- }
48
- }
49
- if (hashSet.size === 0) {
50
- throw new Error(`No trusted gateways returned a hash for txId ${txId}`);
51
- }
52
- if (hashSet.size > 1) {
53
- throw new Error(`Failed to get consistent hash from all trusted gateways. ${JSON.stringify(hashResults)}`);
54
- }
55
- return { hash: hashResults[0].txIdHash, algorithm: 'sha256' };
56
- }
57
- /**
58
- * Get the data root for a given txId from all trusted gateways and ensure they all match.
59
- * @param txId - The txId to get the data root for.
60
- * @returns The data root for the given txId.
61
- */
62
- async getDataRoot({ txId }) {
63
- const dataRootSet = new Set();
64
- const dataRootResults = [];
65
- const gateways = await this.gatewaysProvider.getGateways();
66
- const dataRoots = await Promise.all(gateways.map(async (gateway) => {
67
- const response = await fetch(`${gateway.toString()}tx/${txId}/data_root`);
68
- if (!response.ok) {
69
- // skip this gateway
70
- return undefined;
71
- }
72
- const dataRoot = await response.text();
73
- dataRootResults.push({
74
- gateway: gateway.hostname,
75
- dataRoot,
76
- });
77
- return dataRoot;
78
- }));
79
- for (const dataRoot of dataRoots) {
80
- if (dataRoot !== undefined) {
81
- dataRootSet.add(dataRoot);
82
- }
83
- }
84
- if (dataRootSet.size > 1) {
85
- throw new Error(`Failed to get consistent data root from all trusted gateways. ${JSON.stringify(dataRootResults)}`);
86
- }
87
- return dataRootSet.values().next().value;
88
- }
89
- }
90
- // client could check hashes of data items, match expected hash
91
- // if the gateway has the hash and they've verified it, you can trust the data item and offset
92
- // you would be only trusting the gateway that it is a valid bundle
93
- // you can request the offset from the gateway to verify the id
94
- /**
95
- * Note from @djwhitt
96
- *
97
- * Calculating data roots this way is fine, but it may not reproduce the original data root.
98
- * We could also implement a data root verifier that pulls all the chunks, checks that they
99
- * reproduce the expected data root, and then compares the concatenated chunk data to the
100
- * original data retrieved. That would take a while, but it should be able to verify any L1
101
- * data where we can find the chunks.
102
- */