@ar.io/sdk 3.13.0-beta.1 → 3.13.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 (53) hide show
  1. package/bundles/web.bundle.min.js +136 -139
  2. package/lib/cjs/common/index.js +0 -2
  3. package/lib/cjs/utils/hash.js +31 -83
  4. package/lib/cjs/version.js +1 -1
  5. package/lib/esm/common/index.js +0 -2
  6. package/lib/esm/utils/hash.js +27 -74
  7. package/lib/esm/version.js +1 -1
  8. package/lib/types/common/index.d.ts +0 -1
  9. package/lib/types/types/io.d.ts +0 -3
  10. package/lib/types/utils/hash.d.ts +4 -8
  11. package/package.json +1 -2
  12. package/lib/cjs/common/wayfinder/gateways/network.js +0 -48
  13. package/lib/cjs/common/wayfinder/gateways/simple-cache.js +0 -35
  14. package/lib/cjs/common/wayfinder/gateways/static.js +0 -13
  15. package/lib/cjs/common/wayfinder/index.js +0 -48
  16. package/lib/cjs/common/wayfinder/routing/strategies/ping.js +0 -72
  17. package/lib/cjs/common/wayfinder/routing/strategies/preferred-with-fallback.js +0 -50
  18. package/lib/cjs/common/wayfinder/routing/strategies/random.js +0 -13
  19. package/lib/cjs/common/wayfinder/routing/strategies/round-robin.js +0 -42
  20. package/lib/cjs/common/wayfinder/routing/strategies/static.js +0 -29
  21. package/lib/cjs/common/wayfinder/verification/strategies/data-root-verifier.js +0 -110
  22. package/lib/cjs/common/wayfinder/verification/strategies/hash-verifier.js +0 -27
  23. package/lib/cjs/common/wayfinder/verification/trusted.js +0 -125
  24. package/lib/cjs/common/wayfinder/wayfinder.js +0 -508
  25. package/lib/cjs/types/wayfinder.js +0 -3
  26. package/lib/esm/common/wayfinder/gateways/network.js +0 -44
  27. package/lib/esm/common/wayfinder/gateways/simple-cache.js +0 -31
  28. package/lib/esm/common/wayfinder/gateways/static.js +0 -9
  29. package/lib/esm/common/wayfinder/index.js +0 -32
  30. package/lib/esm/common/wayfinder/routing/strategies/ping.js +0 -68
  31. package/lib/esm/common/wayfinder/routing/strategies/preferred-with-fallback.js +0 -46
  32. package/lib/esm/common/wayfinder/routing/strategies/random.js +0 -9
  33. package/lib/esm/common/wayfinder/routing/strategies/round-robin.js +0 -38
  34. package/lib/esm/common/wayfinder/routing/strategies/static.js +0 -25
  35. package/lib/esm/common/wayfinder/verification/strategies/data-root-verifier.js +0 -102
  36. package/lib/esm/common/wayfinder/verification/strategies/hash-verifier.js +0 -23
  37. package/lib/esm/common/wayfinder/verification/trusted.js +0 -121
  38. package/lib/esm/common/wayfinder/wayfinder.js +0 -499
  39. package/lib/esm/types/wayfinder.js +0 -2
  40. package/lib/types/common/wayfinder/gateways/network.d.ts +0 -33
  41. package/lib/types/common/wayfinder/gateways/simple-cache.d.ts +0 -31
  42. package/lib/types/common/wayfinder/gateways/static.d.ts +0 -23
  43. package/lib/types/common/wayfinder/index.d.ts +0 -27
  44. package/lib/types/common/wayfinder/routing/strategies/ping.d.ts +0 -27
  45. package/lib/types/common/wayfinder/routing/strategies/preferred-with-fallback.d.ts +0 -31
  46. package/lib/types/common/wayfinder/routing/strategies/random.d.ts +0 -21
  47. package/lib/types/common/wayfinder/routing/strategies/round-robin.d.ts +0 -29
  48. package/lib/types/common/wayfinder/routing/strategies/static.d.ts +0 -29
  49. package/lib/types/common/wayfinder/verification/strategies/data-root-verifier.d.ts +0 -27
  50. package/lib/types/common/wayfinder/verification/strategies/hash-verifier.d.ts +0 -26
  51. package/lib/types/common/wayfinder/verification/trusted.d.ts +0 -51
  52. package/lib/types/common/wayfinder/wayfinder.d.ts +0 -257
  53. 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);
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.convertDataStreamToDataRoot = exports.hashDataStreamToB64Url = exports.readableStreamToAsyncIterable = exports.isReadableStream = exports.isAsyncIterable = void 0;
3
+ exports.hashBufferToB64Url = exports.hashReadableStreamToB64Url = exports.hashReadableToB64Url = void 0;
7
4
  /**
8
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
9
6
  *
@@ -19,90 +16,41 @@ exports.convertDataStreamToDataRoot = exports.hashDataStreamToB64Url = exports.r
19
16
  * See the License for the specific language governing permissions and
20
17
  * limitations under the License.
21
18
  */
22
- const arweave_1 = __importDefault(require("arweave"));
23
- const merkle_js_1 = require("arweave/node/lib/merkle.js");
24
19
  const crypto_1 = require("crypto");
25
20
  const base64_js_1 = require("./base64.js");
26
- const isAsyncIterable = (x) => {
27
- return x && typeof x[Symbol.asyncIterator] === 'function';
28
- };
29
- exports.isAsyncIterable = isAsyncIterable;
30
- const isReadableStream = (x) => {
31
- return x && typeof x.getReader === 'function';
21
+ const hashReadableToB64Url = (stream, algorithm = 'sha256') => {
22
+ return new Promise((resolve, reject) => {
23
+ const hash = (0, crypto_1.createHash)(algorithm);
24
+ stream.on('data', (chunk) => hash.update(chunk));
25
+ stream.on('end', () => resolve((0, base64_js_1.toB64Url)(hash.digest())));
26
+ stream.on('error', (err) => reject(err));
27
+ });
32
28
  };
33
- exports.isReadableStream = isReadableStream;
34
- // convert ReadableStream to async iterable
35
- const readableStreamToAsyncIterable = (stream) => ({
36
- async *[Symbol.asyncIterator]() {
29
+ exports.hashReadableToB64Url = hashReadableToB64Url;
30
+ const hashReadableStreamToB64Url = (stream, algorithm = 'sha256') => {
31
+ return new Promise((resolve, reject) => {
32
+ const hash = (0, crypto_1.createHash)(algorithm);
37
33
  const reader = stream.getReader();
38
- try {
39
- while (true) {
34
+ const read = async () => {
35
+ try {
40
36
  const { done, value } = await reader.read();
41
- if (done)
42
- break;
43
- if (value !== undefined)
44
- yield value;
37
+ if (done) {
38
+ resolve((0, base64_js_1.toB64Url)(hash.digest()));
39
+ }
40
+ else {
41
+ hash.update(value);
42
+ read();
43
+ }
45
44
  }
46
- }
47
- finally {
48
- reader.releaseLock();
49
- }
50
- },
51
- });
52
- exports.readableStreamToAsyncIterable = readableStreamToAsyncIterable;
53
- const hashDataStreamToB64Url = async (stream, algorithm = 'sha256') => {
54
- const asyncIterable = (0, exports.isAsyncIterable)(stream)
55
- ? stream
56
- : (0, exports.readableStreamToAsyncIterable)(stream);
57
- const hash = (0, crypto_1.createHash)(algorithm);
58
- for await (const chunk of asyncIterable) {
59
- hash.update(chunk);
60
- }
61
- return (0, base64_js_1.toB64Url)(hash.digest());
62
- };
63
- exports.hashDataStreamToB64Url = hashDataStreamToB64Url;
64
- const convertDataStreamToDataRoot = async ({ dataStream, }) => {
65
- const chunks = [];
66
- let leftover = new Uint8Array(0);
67
- let cursor = 0;
68
- const asyncIterable = (0, exports.isAsyncIterable)(dataStream)
69
- ? dataStream
70
- : (0, exports.readableStreamToAsyncIterable)(dataStream);
71
- for await (const data of asyncIterable) {
72
- const inputChunk = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
73
- const combined = new Uint8Array(leftover.length + inputChunk.length);
74
- combined.set(leftover, 0);
75
- combined.set(inputChunk, leftover.length);
76
- let startIndex = 0;
77
- while (combined.length - startIndex >= merkle_js_1.MAX_CHUNK_SIZE) {
78
- let chunkSize = merkle_js_1.MAX_CHUNK_SIZE;
79
- const remainderAfterThis = combined.length - startIndex - merkle_js_1.MAX_CHUNK_SIZE;
80
- if (remainderAfterThis > 0 && remainderAfterThis < merkle_js_1.MIN_CHUNK_SIZE) {
81
- chunkSize = Math.ceil((combined.length - startIndex) / 2);
45
+ catch (err) {
46
+ reject(err);
82
47
  }
83
- const chunkData = combined.slice(startIndex, startIndex + chunkSize);
84
- const dataHash = await arweave_1.default.crypto.hash(chunkData);
85
- chunks.push({
86
- dataHash,
87
- minByteRange: cursor,
88
- maxByteRange: cursor + chunkSize,
89
- });
90
- cursor += chunkSize;
91
- startIndex += chunkSize;
92
- }
93
- leftover = combined.slice(startIndex);
94
- }
95
- if (leftover.length > 0) {
96
- // TODO: ensure a web friendly crypto hash function is used in web
97
- const dataHash = await arweave_1.default.crypto.hash(leftover);
98
- chunks.push({
99
- dataHash,
100
- minByteRange: cursor,
101
- maxByteRange: cursor + leftover.length,
102
- });
103
- }
104
- const leaves = await (0, merkle_js_1.generateLeaves)(chunks);
105
- const root = await (0, merkle_js_1.buildLayers)(leaves);
106
- return (0, base64_js_1.toB64Url)(Buffer.from(root.id));
48
+ };
49
+ read().catch(reject);
50
+ });
51
+ };
52
+ exports.hashReadableStreamToB64Url = hashReadableStreamToB64Url;
53
+ const hashBufferToB64Url = (buffer, algorithm = 'sha256') => {
54
+ return (0, base64_js_1.toB64Url)((0, crypto_1.createHash)(algorithm).update(buffer).digest());
107
55
  };
108
- exports.convertDataStreamToDataRoot = convertDataStreamToDataRoot;
56
+ exports.hashBufferToB64Url = hashBufferToB64Url;
@@ -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.13.0-beta.1';
20
+ exports.version = '3.13.0';
@@ -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';
@@ -13,85 +13,38 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import Arweave from 'arweave';
17
- import { MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, buildLayers, generateLeaves, } from 'arweave/node/lib/merkle.js';
18
16
  import { createHash } from 'crypto';
19
17
  import { toB64Url } from './base64.js';
20
- export const isAsyncIterable = (x) => {
21
- return x && typeof x[Symbol.asyncIterator] === 'function';
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
+ });
22
25
  };
23
- export const isReadableStream = (x) => {
24
- return x && typeof x.getReader === 'function';
25
- };
26
- // convert ReadableStream to async iterable
27
- export const readableStreamToAsyncIterable = (stream) => ({
28
- async *[Symbol.asyncIterator]() {
26
+ export const hashReadableStreamToB64Url = (stream, algorithm = 'sha256') => {
27
+ return new Promise((resolve, reject) => {
28
+ const hash = createHash(algorithm);
29
29
  const reader = stream.getReader();
30
- try {
31
- while (true) {
30
+ const read = async () => {
31
+ try {
32
32
  const { done, value } = await reader.read();
33
- if (done)
34
- break;
35
- if (value !== undefined)
36
- yield value;
33
+ if (done) {
34
+ resolve(toB64Url(hash.digest()));
35
+ }
36
+ else {
37
+ hash.update(value);
38
+ read();
39
+ }
37
40
  }
38
- }
39
- finally {
40
- reader.releaseLock();
41
- }
42
- },
43
- });
44
- export const hashDataStreamToB64Url = async (stream, algorithm = 'sha256') => {
45
- const asyncIterable = isAsyncIterable(stream)
46
- ? stream
47
- : readableStreamToAsyncIterable(stream);
48
- const hash = createHash(algorithm);
49
- for await (const chunk of asyncIterable) {
50
- hash.update(chunk);
51
- }
52
- return toB64Url(hash.digest());
53
- };
54
- export const convertDataStreamToDataRoot = async ({ dataStream, }) => {
55
- const chunks = [];
56
- let leftover = new Uint8Array(0);
57
- let cursor = 0;
58
- const asyncIterable = isAsyncIterable(dataStream)
59
- ? dataStream
60
- : readableStreamToAsyncIterable(dataStream);
61
- for await (const data of asyncIterable) {
62
- const inputChunk = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
63
- const combined = new Uint8Array(leftover.length + inputChunk.length);
64
- combined.set(leftover, 0);
65
- combined.set(inputChunk, leftover.length);
66
- let startIndex = 0;
67
- while (combined.length - startIndex >= MAX_CHUNK_SIZE) {
68
- let chunkSize = MAX_CHUNK_SIZE;
69
- const remainderAfterThis = combined.length - startIndex - MAX_CHUNK_SIZE;
70
- if (remainderAfterThis > 0 && remainderAfterThis < MIN_CHUNK_SIZE) {
71
- chunkSize = Math.ceil((combined.length - startIndex) / 2);
41
+ catch (err) {
42
+ reject(err);
72
43
  }
73
- const chunkData = combined.slice(startIndex, startIndex + chunkSize);
74
- const dataHash = await Arweave.crypto.hash(chunkData);
75
- chunks.push({
76
- dataHash,
77
- minByteRange: cursor,
78
- maxByteRange: cursor + chunkSize,
79
- });
80
- cursor += chunkSize;
81
- startIndex += chunkSize;
82
- }
83
- leftover = combined.slice(startIndex);
84
- }
85
- if (leftover.length > 0) {
86
- // TODO: ensure a web friendly crypto hash function is used in web
87
- const dataHash = await Arweave.crypto.hash(leftover);
88
- chunks.push({
89
- dataHash,
90
- minByteRange: cursor,
91
- maxByteRange: cursor + leftover.length,
92
- });
93
- }
94
- const leaves = await generateLeaves(chunks);
95
- const root = await buildLayers(leaves);
96
- return toB64Url(Buffer.from(root.id));
44
+ };
45
+ read().catch(reject);
46
+ });
47
+ };
48
+ export const hashBufferToB64Url = (buffer, algorithm = 'sha256') => {
49
+ return toB64Url(createHash(algorithm).update(buffer).digest());
97
50
  };
@@ -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.13.0-beta.1';
17
+ export const version = '3.13.0';
@@ -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';
@@ -353,15 +353,12 @@ export type AoBuyRecordParams = AoArNSPurchaseParams & {
353
353
  years?: number;
354
354
  type: 'lease' | 'permabuy';
355
355
  processId: string;
356
- referrer?: string;
357
356
  };
358
357
  export type AoExtendLeaseParams = AoArNSPurchaseParams & {
359
358
  years: number;
360
- referrer?: string;
361
359
  };
362
360
  export type AoIncreaseUndernameLimitParams = AoArNSPurchaseParams & {
363
361
  increaseCount: number;
364
- referrer?: string;
365
362
  };
366
363
  export type AoVaultedTransferParams = {
367
364
  recipient: WalletAddress;
@@ -1,8 +1,4 @@
1
- import { DataStream } from '../types/wayfinder.js';
2
- export declare const isAsyncIterable: <T = unknown>(x: any) => x is AsyncIterable<T>;
3
- export declare const isReadableStream: <T = unknown>(x: any) => x is ReadableStream<T>;
4
- export declare const readableStreamToAsyncIterable: (stream: ReadableStream<Uint8Array>) => AsyncIterable<Uint8Array>;
5
- export declare const hashDataStreamToB64Url: (stream: DataStream, algorithm?: string) => Promise<string>;
6
- export declare const convertDataStreamToDataRoot: ({ dataStream, }: {
7
- dataStream: DataStream;
8
- }) => Promise<string>;
1
+ import { Readable } from 'stream';
2
+ export declare const hashReadableToB64Url: (stream: Readable, algorithm?: string) => Promise<string>;
3
+ export declare const hashReadableStreamToB64Url: (stream: ReadableStream, algorithm?: string) => Promise<string>;
4
+ export declare const hashBufferToB64Url: (buffer: Buffer, algorithm?: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.13.0-beta.1",
3
+ "version": "3.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -136,7 +136,6 @@
136
136
  "eventemitter3": "^5.0.1",
137
137
  "plimit-lit": "^3.0.1",
138
138
  "prompts": "^2.4.2",
139
- "rfc4648": "^1.5.4",
140
139
  "uuid": "^11.1.0",
141
140
  "winston": "^3.13.0",
142
141
  "zod": "^3.23.8"
@@ -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,48 +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
- __exportStar(require("./routing/strategies/preferred-with-fallback.js"), exports);
39
- // gateways providers
40
- __exportStar(require("./gateways/network.js"), exports);
41
- __exportStar(require("./gateways/simple-cache.js"), exports);
42
- __exportStar(require("./gateways/static.js"), exports);
43
- // trusted gateways
44
- __exportStar(require("./verification/trusted.js"), exports);
45
- // hash providers
46
- __exportStar(require("./verification/strategies/data-root-verifier.js"), exports);
47
- __exportStar(require("./verification/strategies/hash-verifier.js"), exports);
48
- // 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,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PreferredWithFallbackRoutingStrategy = void 0;
4
- const logger_js_1 = require("../../../logger.js");
5
- const ping_js_1 = require("./ping.js");
6
- class PreferredWithFallbackRoutingStrategy {
7
- name = 'preferred-with-fallback';
8
- preferredGateway;
9
- fallbackStrategy;
10
- logger;
11
- constructor({ preferredGateway, fallbackStrategy = new ping_js_1.FastestPingRoutingStrategy(), logger = logger_js_1.Logger.default, }) {
12
- try {
13
- this.preferredGateway = new URL(preferredGateway);
14
- }
15
- catch (error) {
16
- throw new Error(`Invalid URL provided for preferred gateway: ${preferredGateway}`);
17
- }
18
- this.fallbackStrategy = fallbackStrategy;
19
- this.logger = logger;
20
- }
21
- async selectGateway({ gateways = [] }) {
22
- this.logger.debug('Attempting to connect to preferred gateway', {
23
- preferredGateway: this.preferredGateway.toString(),
24
- });
25
- try {
26
- // Check if the preferred gateway is responsive
27
- const response = await fetch(this.preferredGateway.toString(), {
28
- method: 'HEAD',
29
- signal: AbortSignal.timeout(1000),
30
- });
31
- if (response.ok) {
32
- this.logger.debug('Successfully connected to preferred gateway', {
33
- preferredGateway: this.preferredGateway.toString(),
34
- });
35
- return this.preferredGateway;
36
- }
37
- throw new Error(`Preferred gateway responded with status: ${response.status}`);
38
- }
39
- catch (error) {
40
- this.logger.warn('Failed to connect to preferred gateway, falling back to alternative strategy', {
41
- preferredGateway: this.preferredGateway.toString(),
42
- error: error instanceof Error ? error.message : String(error),
43
- fallbackStrategy: this.fallbackStrategy.constructor.name,
44
- });
45
- // Fall back to the provided routing strategy
46
- return this.fallbackStrategy.selectGateway({ gateways });
47
- }
48
- }
49
- }
50
- exports.PreferredWithFallbackRoutingStrategy = PreferredWithFallbackRoutingStrategy;
@@ -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;