@ar.io/sdk 3.11.0-alpha.9 → 3.11.0

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 (72) hide show
  1. package/bundles/web.bundle.min.js +120 -123
  2. package/lib/cjs/cli/utils.js +4 -1
  3. package/lib/cjs/common/ant-versions.js +3 -2
  4. package/lib/cjs/common/contracts/ao-process.js +2 -1
  5. package/lib/cjs/common/index.js +0 -2
  6. package/lib/cjs/common/io.js +13 -9
  7. package/lib/cjs/common/turbo.js +1 -1
  8. package/lib/cjs/types/index.js +0 -1
  9. package/lib/cjs/utils/ao.js +2 -1
  10. package/lib/cjs/version.js +1 -1
  11. package/lib/esm/cli/utils.js +4 -1
  12. package/lib/esm/common/ant-versions.js +3 -2
  13. package/lib/esm/common/contracts/ao-process.js +2 -1
  14. package/lib/esm/common/index.js +0 -2
  15. package/lib/esm/common/io.js +13 -9
  16. package/lib/esm/common/turbo.js +1 -1
  17. package/lib/esm/types/index.js +0 -1
  18. package/lib/esm/utils/ao.js +2 -1
  19. package/lib/esm/version.js +1 -1
  20. package/lib/types/common/ant-versions.d.ts +3 -5
  21. package/lib/types/common/index.d.ts +0 -1
  22. package/lib/types/types/index.d.ts +0 -1
  23. package/lib/types/version.d.ts +1 -1
  24. package/package.json +1 -1
  25. package/lib/cjs/common/wayfinder/gateways/trusted-gateways.js +0 -106
  26. package/lib/cjs/common/wayfinder/gateways.js +0 -86
  27. package/lib/cjs/common/wayfinder/index.js +0 -44
  28. package/lib/cjs/common/wayfinder/routers/priority.js +0 -29
  29. package/lib/cjs/common/wayfinder/routers/priority.test.js +0 -155
  30. package/lib/cjs/common/wayfinder/routers/random.js +0 -23
  31. package/lib/cjs/common/wayfinder/routers/random.test.js +0 -25
  32. package/lib/cjs/common/wayfinder/routers/simple-cache.js +0 -25
  33. package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +0 -41
  34. package/lib/cjs/common/wayfinder/routers/static.js +0 -14
  35. package/lib/cjs/common/wayfinder/routers/static.test.js +0 -14
  36. package/lib/cjs/common/wayfinder/verification/data-root-verifier.js +0 -139
  37. package/lib/cjs/common/wayfinder/verification/hash-verifier.js +0 -50
  38. package/lib/cjs/common/wayfinder/wayfinder.js +0 -596
  39. package/lib/cjs/common/wayfinder/wayfinder.test.js +0 -500
  40. package/lib/cjs/types/wayfinder.js +0 -3
  41. package/lib/esm/common/wayfinder/gateways/trusted-gateways.js +0 -102
  42. package/lib/esm/common/wayfinder/gateways.js +0 -80
  43. package/lib/esm/common/wayfinder/index.js +0 -28
  44. package/lib/esm/common/wayfinder/routers/priority.js +0 -25
  45. package/lib/esm/common/wayfinder/routers/priority.test.js +0 -153
  46. package/lib/esm/common/wayfinder/routers/random.js +0 -19
  47. package/lib/esm/common/wayfinder/routers/random.test.js +0 -23
  48. package/lib/esm/common/wayfinder/routers/simple-cache.js +0 -21
  49. package/lib/esm/common/wayfinder/routers/simple-cache.test.js +0 -39
  50. package/lib/esm/common/wayfinder/routers/static.js +0 -10
  51. package/lib/esm/common/wayfinder/routers/static.test.js +0 -12
  52. package/lib/esm/common/wayfinder/verification/data-root-verifier.js +0 -130
  53. package/lib/esm/common/wayfinder/verification/hash-verifier.js +0 -46
  54. package/lib/esm/common/wayfinder/wayfinder.js +0 -584
  55. package/lib/esm/common/wayfinder/wayfinder.test.js +0 -495
  56. package/lib/esm/types/wayfinder.js +0 -2
  57. package/lib/types/common/wayfinder/gateways/trusted-gateways.d.ts +0 -51
  58. package/lib/types/common/wayfinder/gateways.d.ts +0 -53
  59. package/lib/types/common/wayfinder/index.d.ts +0 -23
  60. package/lib/types/common/wayfinder/routers/priority.d.ts +0 -29
  61. package/lib/types/common/wayfinder/routers/priority.test.d.ts +0 -1
  62. package/lib/types/common/wayfinder/routers/random.d.ts +0 -27
  63. package/lib/types/common/wayfinder/routers/random.test.d.ts +0 -1
  64. package/lib/types/common/wayfinder/routers/simple-cache.d.ts +0 -28
  65. package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +0 -1
  66. package/lib/types/common/wayfinder/routers/static.d.ts +0 -24
  67. package/lib/types/common/wayfinder/routers/static.test.d.ts +0 -1
  68. package/lib/types/common/wayfinder/verification/data-root-verifier.d.ts +0 -31
  69. package/lib/types/common/wayfinder/verification/hash-verifier.d.ts +0 -27
  70. package/lib/types/common/wayfinder/wayfinder.d.ts +0 -265
  71. package/lib/types/common/wayfinder/wayfinder.test.d.ts +0 -1
  72. package/lib/types/types/wayfinder.d.ts +0 -62
@@ -165,7 +165,10 @@ function aoProcessFromOptions(options) {
165
165
  function readARIOFromOptions(options) {
166
166
  setLoggerIfDebug(options);
167
167
  return index_js_1.ARIO.init({
168
- process: aoProcessFromOptions(options),
168
+ process: aoProcessFromOptions({
169
+ cuUrl: 'https://cu.ardrive.io', // default to ardrive cu for ARIO process
170
+ ...options,
171
+ }),
169
172
  paymentUrl: options.paymentUrl,
170
173
  });
171
174
  }
@@ -75,7 +75,8 @@ class ANTVersionsWritable extends ANTVersionsReadable {
75
75
  super(config);
76
76
  this.signer = (0, ao_js_1.createAoSigner)(signer);
77
77
  }
78
- async addVersion({ version, moduleId, luaSourceId, notes, }, { tags }) {
78
+ async addVersion(params, options) {
79
+ const { version, moduleId, luaSourceId, notes } = params;
79
80
  return this.process.send({
80
81
  tags: (0, arweave_js_1.pruneTags)([
81
82
  { name: 'Action', value: 'Add-Version' },
@@ -83,7 +84,7 @@ class ANTVersionsWritable extends ANTVersionsReadable {
83
84
  { name: 'Module-Id', value: moduleId },
84
85
  { name: 'Lua-Source-Id', value: luaSourceId },
85
86
  { name: 'Notes', value: notes },
86
- ...(tags ?? []),
87
+ ...(options?.tags ?? []),
87
88
  ]),
88
89
  signer: this.signer,
89
90
  });
@@ -98,7 +98,8 @@ class AOProcess {
98
98
  tags,
99
99
  processId: this.processId,
100
100
  });
101
- throw new Error(`Process ${this.processId} does not support provided action.`);
101
+ throw new Error(result.message ||
102
+ `Process ${this.processId} did not return a valid response. Response: ${JSON.stringify(result)}`);
102
103
  }
103
104
  const messageData = result.Messages?.[0]?.Data;
104
105
  // return undefined if no data is returned
@@ -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);
@@ -457,7 +457,7 @@ class ARIOReadable {
457
457
  years,
458
458
  });
459
459
  return {
460
- tokenCost: +mARIO,
460
+ tokenCost: mARIO.valueOf(),
461
461
  wincQty: winc,
462
462
  discounts: [],
463
463
  };
@@ -626,12 +626,15 @@ class ARIOReadable {
626
626
  });
627
627
  }
628
628
  async resolveArNSName({ name, }) {
629
- const baseName = name.split('_').pop();
630
- if (baseName === undefined) {
631
- throw new Error('Invalid name');
632
- }
633
- const undername = name === baseName ? '@' : name.replace(`_${baseName}`, '');
629
+ // derive baseName & undername using last underscore
630
+ const lastUnderscore = name.lastIndexOf('_');
631
+ const baseName = lastUnderscore === -1 ? name : name.slice(lastUnderscore + 1);
632
+ const undername = lastUnderscore === -1 ? '@' : name.slice(0, lastUnderscore);
633
+ // guard against missing or unregistered ARNS record
634
634
  const nameData = await this.getArNSRecord({ name: baseName });
635
+ if (nameData === undefined || nameData.processId === undefined) {
636
+ throw new Error(`Base ArNS name ${baseName} not found on ARIO contract (${this.process.processId}).`);
637
+ }
635
638
  const ant = ant_js_1.ANT.init({
636
639
  process: new ao_process_js_1.AOProcess({
637
640
  ao: this.process.ao,
@@ -650,12 +653,13 @@ class ARIOReadable {
650
653
  throw new Error(`Invalid record on ANT. Must have ttlSeconds and transactionId. Record: ${JSON.stringify(antRecord)}`);
651
654
  }
652
655
  return {
653
- name: name,
654
- owner: owner,
656
+ name,
657
+ owner,
655
658
  txId: antRecord.transactionId,
656
659
  ttlSeconds: antRecord.ttlSeconds,
657
660
  priority: antRecord.priority,
658
- // NOTE: we may want return the actual index of the record based on sorting in case ANT tries to set duplicate priority values to get around undername limits
661
+ // NOTE: we may want return the actual index of the record based on sorting
662
+ // in case ANT tries to set duplicate priority values to get around undername limits
659
663
  processId: nameData.processId,
660
664
  undernameLimit: nameData.undernameLimit,
661
665
  type: nameData.type,
@@ -77,7 +77,7 @@ async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)()
77
77
  'x-public-key': publicKey,
78
78
  'x-nonce': nonce,
79
79
  'x-signature': signature,
80
- 'x-signature-type': signatureType,
80
+ 'x-signature-type': signatureType.toString(),
81
81
  };
82
82
  }
83
83
  class TurboArNSPaymentFactory {
@@ -35,4 +35,3 @@ __exportStar(require("./common.js"), exports);
35
35
  __exportStar(require("./faucet.js"), exports);
36
36
  __exportStar(require("./io.js"), exports);
37
37
  __exportStar(require("./token.js"), exports);
38
- __exportStar(require("./wayfinder.js"), exports);
@@ -77,8 +77,9 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, ao = (0
77
77
  }
78
78
  }
79
79
  if (bootRes === undefined ||
80
- bootRes.Messages.find((m) => m.Tags.find((t) => t.value === 'Invalid-Boot-Notice'))) {
80
+ bootRes.Messages?.some((m) => m?.Tags?.some((t) => t.value === 'Invalid-Boot-Notice'))) {
81
81
  if (bootRes === undefined) {
82
+ // …
82
83
  throw new Error('Failed to get boot result');
83
84
  }
84
85
  const bootError = errorMessageFromOutput(bootRes);
@@ -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.11.0-alpha.9';
20
+ exports.version = '3.11.0';
@@ -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(options),
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
  }
@@ -70,7 +70,8 @@ export class ANTVersionsWritable extends ANTVersionsReadable {
70
70
  super(config);
71
71
  this.signer = createAoSigner(signer);
72
72
  }
73
- async addVersion({ version, moduleId, luaSourceId, notes, }, { tags }) {
73
+ async addVersion(params, options) {
74
+ const { version, moduleId, luaSourceId, notes } = params;
74
75
  return this.process.send({
75
76
  tags: pruneTags([
76
77
  { name: 'Action', value: 'Add-Version' },
@@ -78,7 +79,7 @@ export class ANTVersionsWritable extends ANTVersionsReadable {
78
79
  { name: 'Module-Id', value: moduleId },
79
80
  { name: 'Lua-Source-Id', value: luaSourceId },
80
81
  { name: 'Notes', value: notes },
81
- ...(tags ?? []),
82
+ ...(options?.tags ?? []),
82
83
  ]),
83
84
  signer: this.signer,
84
85
  });
@@ -95,7 +95,8 @@ export class AOProcess {
95
95
  tags,
96
96
  processId: this.processId,
97
97
  });
98
- throw new Error(`Process ${this.processId} does not support provided action.`);
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
@@ -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';
@@ -453,7 +453,7 @@ export class ARIOReadable {
453
453
  years,
454
454
  });
455
455
  return {
456
- tokenCost: +mARIO,
456
+ tokenCost: mARIO.valueOf(),
457
457
  wincQty: winc,
458
458
  discounts: [],
459
459
  };
@@ -622,12 +622,15 @@ export class ARIOReadable {
622
622
  });
623
623
  }
624
624
  async resolveArNSName({ name, }) {
625
- const baseName = name.split('_').pop();
626
- if (baseName === undefined) {
627
- throw new Error('Invalid name');
628
- }
629
- const undername = name === baseName ? '@' : name.replace(`_${baseName}`, '');
625
+ // derive baseName & undername using last underscore
626
+ const lastUnderscore = name.lastIndexOf('_');
627
+ const baseName = lastUnderscore === -1 ? name : name.slice(lastUnderscore + 1);
628
+ const undername = lastUnderscore === -1 ? '@' : name.slice(0, lastUnderscore);
629
+ // guard against missing or unregistered ARNS record
630
630
  const nameData = await this.getArNSRecord({ name: baseName });
631
+ if (nameData === undefined || nameData.processId === undefined) {
632
+ throw new Error(`Base ArNS name ${baseName} not found on ARIO contract (${this.process.processId}).`);
633
+ }
631
634
  const ant = ANT.init({
632
635
  process: new AOProcess({
633
636
  ao: this.process.ao,
@@ -646,12 +649,13 @@ export class ARIOReadable {
646
649
  throw new Error(`Invalid record on ANT. Must have ttlSeconds and transactionId. Record: ${JSON.stringify(antRecord)}`);
647
650
  }
648
651
  return {
649
- name: name,
650
- owner: owner,
652
+ name,
653
+ owner,
651
654
  txId: antRecord.transactionId,
652
655
  ttlSeconds: antRecord.ttlSeconds,
653
656
  priority: antRecord.priority,
654
- // NOTE: we may want return the actual index of the record based on sorting in case ANT tries to set duplicate priority values to get around undername limits
657
+ // NOTE: we may want return the actual index of the record based on sorting
658
+ // in case ANT tries to set duplicate priority values to get around undername limits
655
659
  processId: nameData.processId,
656
660
  undernameLimit: nameData.undernameLimit,
657
661
  type: nameData.type,
@@ -72,7 +72,7 @@ export async function signedRequestHeadersFromSigner({ signer, nonce = uuidv4(),
72
72
  'x-public-key': publicKey,
73
73
  'x-nonce': nonce,
74
74
  'x-signature': signature,
75
- 'x-signature-type': signatureType,
75
+ 'x-signature-type': signatureType.toString(),
76
76
  };
77
77
  }
78
78
  export class TurboArNSPaymentFactory {
@@ -19,4 +19,3 @@ export * from './common.js';
19
19
  export * from './faucet.js';
20
20
  export * from './io.js';
21
21
  export * from './token.js';
22
- export * from './wayfinder.js';
@@ -66,8 +66,9 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, ao = connect(),
66
66
  }
67
67
  }
68
68
  if (bootRes === undefined ||
69
- bootRes.Messages.find((m) => m.Tags.find((t) => t.value === 'Invalid-Boot-Notice'))) {
69
+ bootRes.Messages?.some((m) => m?.Tags?.some((t) => t.value === 'Invalid-Boot-Notice'))) {
70
70
  if (bootRes === undefined) {
71
+ // …
71
72
  throw new Error('Failed to get boot result');
72
73
  }
73
74
  const bootError = errorMessageFromOutput(bootRes);
@@ -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.11.0-alpha.9';
17
+ export const version = '3.11.0';
@@ -1,5 +1,5 @@
1
1
  import { AoANTVersionsRead, AoANTVersionsWrite } from '../types/ant.js';
2
- import { AoMessageResult, WithSigner } from '../types/common.js';
2
+ import { AoMessageResult, WithSigner, WriteOptions } from '../types/common.js';
3
3
  import { ProcessConfiguration } from '../types/io.js';
4
4
  import { AOProcess } from './contracts/ao-process.js';
5
5
  type ANTVersionsNoSigner = ProcessConfiguration;
@@ -27,13 +27,11 @@ export declare class ANTVersionsReadable implements AoANTVersionsRead {
27
27
  export declare class ANTVersionsWritable extends ANTVersionsReadable implements AoANTVersionsWrite {
28
28
  private signer;
29
29
  constructor({ signer, ...config }: WithSigner<ProcessConfiguration>);
30
- addVersion({ version, moduleId, luaSourceId, notes, }: {
30
+ addVersion(params: {
31
31
  version: string;
32
32
  moduleId: string;
33
33
  luaSourceId?: string;
34
34
  notes?: string;
35
- }, { tags }: {
36
- tags: any;
37
- }): Promise<AoMessageResult>;
35
+ }, options?: WriteOptions): Promise<AoMessageResult>;
38
36
  }
39
37
  export {};
@@ -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';
@@ -19,4 +19,3 @@ export * from './common.js';
19
19
  export * from './faucet.js';
20
20
  export * from './io.js';
21
21
  export * from './token.js';
22
- export * from './wayfinder.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.11.0-alpha.8";
16
+ export declare const version = "3.11.0-alpha.14";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.11.0-alpha.9",
3
+ "version": "3.11.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -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 found 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
- */
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimpleCacheGatewaysProvider = exports.StaticGatewaysProvider = exports.NetworkGatewaysProvider = void 0;
4
- class NetworkGatewaysProvider {
5
- ario;
6
- sortBy;
7
- sortOrder;
8
- limit;
9
- filter;
10
- constructor({ ario, sortBy = 'operatorStake', sortOrder = 'desc', limit = 1000, filter = (g) => g.status === 'joined', }) {
11
- this.ario = ario;
12
- this.sortBy = sortBy;
13
- this.sortOrder = sortOrder;
14
- this.limit = limit;
15
- this.filter = filter;
16
- }
17
- async getGateways() {
18
- let cursor;
19
- let attempts = 0;
20
- const gateways = [];
21
- do {
22
- try {
23
- const { items: newGateways = [], nextCursor } = await this.ario.getGateways({
24
- limit: 1000,
25
- cursor,
26
- sortBy: this.sortBy,
27
- sortOrder: this.sortOrder,
28
- });
29
- gateways.push(...newGateways);
30
- cursor = nextCursor;
31
- attempts = 0; // reset attempts if we get a new cursor
32
- }
33
- catch (error) {
34
- console.error('Error fetching gateways', {
35
- cursor,
36
- attempts,
37
- error,
38
- });
39
- attempts++;
40
- }
41
- } while (cursor !== undefined && attempts < 3);
42
- // filter out any gateways that are not joined
43
- const filteredGateways = gateways.filter(this.filter).slice(0, this.limit);
44
- return filteredGateways.map((g) => new URL(`${g.settings.protocol}://${g.settings.fqdn}:${g.settings.port}`));
45
- }
46
- }
47
- exports.NetworkGatewaysProvider = NetworkGatewaysProvider;
48
- class StaticGatewaysProvider {
49
- gateways;
50
- constructor({ gateways }) {
51
- this.gateways = gateways.map((g) => new URL(g));
52
- }
53
- async getGateways() {
54
- return this.gateways;
55
- }
56
- }
57
- exports.StaticGatewaysProvider = StaticGatewaysProvider;
58
- class SimpleCacheGatewaysProvider {
59
- gatewaysProvider;
60
- ttlSeconds;
61
- lastUpdated;
62
- gatewaysCache;
63
- constructor({ gatewaysProvider, ttlSeconds = 5 * 60, // 5 minutes
64
- }) {
65
- this.gatewaysCache = [];
66
- this.gatewaysProvider = gatewaysProvider;
67
- this.ttlSeconds = ttlSeconds;
68
- }
69
- async getGateways() {
70
- const now = Date.now();
71
- if (this.gatewaysCache.length === 0 ||
72
- now - this.lastUpdated > this.ttlSeconds * 1000) {
73
- try {
74
- // preserve the cache if the fetch fails
75
- const allGateways = await this.gatewaysProvider.getGateways();
76
- this.gatewaysCache = allGateways;
77
- this.lastUpdated = now;
78
- }
79
- catch (error) {
80
- console.error('Error fetching gateways', error);
81
- }
82
- }
83
- return this.gatewaysCache;
84
- }
85
- }
86
- exports.SimpleCacheGatewaysProvider = SimpleCacheGatewaysProvider;
@@ -1,44 +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
- // routers
34
- __exportStar(require("./routers/random.js"), exports);
35
- __exportStar(require("./routers/priority.js"), exports);
36
- __exportStar(require("./routers/static.js"), exports);
37
- // gateways providers
38
- __exportStar(require("./gateways.js"), exports);
39
- // trusted gateways
40
- __exportStar(require("./gateways/trusted-gateways.js"), exports);
41
- // hash providers
42
- __exportStar(require("./verification/data-root-verifier.js"), exports);
43
- __exportStar(require("./verification/hash-verifier.js"), exports);
44
- // TODO: signature verification
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PriorityGatewayRouter = void 0;
4
- const random_js_1 = require("../../../utils/random.js");
5
- const gateways_js_1 = require("../gateways.js");
6
- // TODO: one of N where N are in the last time window have met certain performance thresholds
7
- // TODO: look at bitorrent routing protocols for inspiration
8
- // TODO: router that looks at local stats/metrics and adjusts based on those
9
- class PriorityGatewayRouter {
10
- name = 'priority';
11
- gatewaysProvider;
12
- constructor({ ario, sortBy, sortOrder, limit, }) {
13
- this.gatewaysProvider = new gateways_js_1.NetworkGatewaysProvider({
14
- ario,
15
- sortBy,
16
- sortOrder,
17
- limit,
18
- });
19
- }
20
- async getTargetGateway() {
21
- const gateways = await this.gatewaysProvider.getGateways();
22
- const targetGateway = gateways[(0, random_js_1.randomInt)(0, gateways.length)];
23
- if (targetGateway === undefined) {
24
- throw new Error('No target gateway found');
25
- }
26
- return targetGateway;
27
- }
28
- }
29
- exports.PriorityGatewayRouter = PriorityGatewayRouter;