@ar.io/sdk 3.11.0-alpha.12 → 3.11.0-alpha.14
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.
- package/bundles/web.bundle.min.js +120 -123
- package/lib/cjs/common/ant-versions.js +3 -2
- package/lib/cjs/common/index.js +0 -2
- package/lib/cjs/common/io.js +13 -9
- package/lib/cjs/common/turbo.js +1 -1
- package/lib/cjs/types/index.js +0 -1
- package/lib/cjs/utils/ao.js +2 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant-versions.js +3 -2
- package/lib/esm/common/index.js +0 -2
- package/lib/esm/common/io.js +13 -9
- package/lib/esm/common/turbo.js +1 -1
- package/lib/esm/types/index.js +0 -1
- package/lib/esm/utils/ao.js +2 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant-versions.d.ts +3 -5
- package/lib/types/common/index.d.ts +0 -1
- package/lib/types/types/index.d.ts +0 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/lib/cjs/common/wayfinder/gateways/trusted-gateways.js +0 -106
- package/lib/cjs/common/wayfinder/gateways.js +0 -86
- package/lib/cjs/common/wayfinder/index.js +0 -44
- package/lib/cjs/common/wayfinder/routers/priority.js +0 -29
- package/lib/cjs/common/wayfinder/routers/priority.test.js +0 -155
- package/lib/cjs/common/wayfinder/routers/random.js +0 -23
- package/lib/cjs/common/wayfinder/routers/random.test.js +0 -25
- package/lib/cjs/common/wayfinder/routers/simple-cache.js +0 -25
- package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +0 -41
- package/lib/cjs/common/wayfinder/routers/static.js +0 -14
- package/lib/cjs/common/wayfinder/routers/static.test.js +0 -14
- package/lib/cjs/common/wayfinder/verification/data-root-verifier.js +0 -139
- package/lib/cjs/common/wayfinder/verification/hash-verifier.js +0 -50
- package/lib/cjs/common/wayfinder/wayfinder.js +0 -596
- package/lib/cjs/common/wayfinder/wayfinder.test.js +0 -500
- package/lib/cjs/types/wayfinder.js +0 -3
- package/lib/esm/common/wayfinder/gateways/trusted-gateways.js +0 -102
- package/lib/esm/common/wayfinder/gateways.js +0 -80
- package/lib/esm/common/wayfinder/index.js +0 -28
- package/lib/esm/common/wayfinder/routers/priority.js +0 -25
- package/lib/esm/common/wayfinder/routers/priority.test.js +0 -153
- package/lib/esm/common/wayfinder/routers/random.js +0 -19
- package/lib/esm/common/wayfinder/routers/random.test.js +0 -23
- package/lib/esm/common/wayfinder/routers/simple-cache.js +0 -21
- package/lib/esm/common/wayfinder/routers/simple-cache.test.js +0 -39
- package/lib/esm/common/wayfinder/routers/static.js +0 -10
- package/lib/esm/common/wayfinder/routers/static.test.js +0 -12
- package/lib/esm/common/wayfinder/verification/data-root-verifier.js +0 -130
- package/lib/esm/common/wayfinder/verification/hash-verifier.js +0 -46
- package/lib/esm/common/wayfinder/wayfinder.js +0 -584
- package/lib/esm/common/wayfinder/wayfinder.test.js +0 -495
- package/lib/esm/types/wayfinder.js +0 -2
- package/lib/types/common/wayfinder/gateways/trusted-gateways.d.ts +0 -51
- package/lib/types/common/wayfinder/gateways.d.ts +0 -53
- package/lib/types/common/wayfinder/index.d.ts +0 -23
- package/lib/types/common/wayfinder/routers/priority.d.ts +0 -29
- package/lib/types/common/wayfinder/routers/priority.test.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/random.d.ts +0 -27
- package/lib/types/common/wayfinder/routers/random.test.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/simple-cache.d.ts +0 -28
- package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/static.d.ts +0 -24
- package/lib/types/common/wayfinder/routers/static.test.d.ts +0 -1
- package/lib/types/common/wayfinder/verification/data-root-verifier.d.ts +0 -31
- package/lib/types/common/wayfinder/verification/hash-verifier.d.ts +0 -27
- package/lib/types/common/wayfinder/wayfinder.d.ts +0 -265
- package/lib/types/common/wayfinder/wayfinder.test.d.ts +0 -1
- package/lib/types/types/wayfinder.d.ts +0 -62
|
@@ -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(
|
|
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
|
});
|
package/lib/cjs/common/index.js
CHANGED
package/lib/cjs/common/io.js
CHANGED
|
@@ -457,7 +457,7 @@ class ARIOReadable {
|
|
|
457
457
|
years,
|
|
458
458
|
});
|
|
459
459
|
return {
|
|
460
|
-
tokenCost:
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
|
654
|
-
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
|
|
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,
|
package/lib/cjs/common/turbo.js
CHANGED
|
@@ -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 {
|
package/lib/cjs/types/index.js
CHANGED
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -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
|
|
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);
|
package/lib/cjs/version.js
CHANGED
|
@@ -70,7 +70,8 @@ export class ANTVersionsWritable extends ANTVersionsReadable {
|
|
|
70
70
|
super(config);
|
|
71
71
|
this.signer = createAoSigner(signer);
|
|
72
72
|
}
|
|
73
|
-
async addVersion(
|
|
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
|
});
|
package/lib/esm/common/index.js
CHANGED
package/lib/esm/common/io.js
CHANGED
|
@@ -453,7 +453,7 @@ export class ARIOReadable {
|
|
|
453
453
|
years,
|
|
454
454
|
});
|
|
455
455
|
return {
|
|
456
|
-
tokenCost:
|
|
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
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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
|
|
650
|
-
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
|
|
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,
|
package/lib/esm/common/turbo.js
CHANGED
|
@@ -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 {
|
package/lib/esm/types/index.js
CHANGED
package/lib/esm/utils/ao.js
CHANGED
|
@@ -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
|
|
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);
|
package/lib/esm/version.js
CHANGED
|
@@ -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(
|
|
30
|
+
addVersion(params: {
|
|
31
31
|
version: string;
|
|
32
32
|
moduleId: string;
|
|
33
33
|
luaSourceId?: string;
|
|
34
34
|
notes?: string;
|
|
35
|
-
},
|
|
36
|
-
tags: any;
|
|
37
|
-
}): Promise<AoMessageResult>;
|
|
35
|
+
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
38
36
|
}
|
|
39
37
|
export {};
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -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
|
-
*/
|
|
@@ -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;
|