@ar.io/sdk 3.10.0-alpha.6 → 3.11.0-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.
- package/README.md +66 -125
- package/bundles/web.bundle.min.js +148 -122
- package/lib/cjs/cli/commands/antCommands.js +3 -4
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -6
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +11 -12
- package/lib/cjs/cli/commands/readCommands.js +21 -22
- package/lib/cjs/cli/commands/transfer.js +6 -7
- package/lib/cjs/cli/utils.js +43 -43
- package/lib/cjs/common/faucet.js +2 -2
- package/lib/cjs/common/turbo.js +3 -3
- package/lib/cjs/common/wayfinder/routers/priority.js +2 -2
- package/lib/cjs/common/wayfinder/routers/random.js +2 -2
- package/lib/cjs/common/wayfinder/wayfinder.js +1 -28
- package/lib/cjs/common/wayfinder/wayfinder.test.js +23 -24
- package/lib/cjs/types/ant.js +2 -2
- package/lib/cjs/types/io.js +4 -4
- package/lib/cjs/utils/ao.js +9 -9
- package/lib/cjs/utils/arweave.js +4 -4
- package/lib/cjs/utils/base64.js +4 -5
- package/lib/cjs/utils/json.js +1 -2
- package/lib/cjs/utils/random.js +30 -0
- package/lib/cjs/utils/schema.js +1 -2
- package/lib/cjs/utils/utils.test.js +8 -8
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/wayfinder/routers/priority.js +1 -1
- package/lib/esm/common/wayfinder/routers/random.js +1 -1
- package/lib/esm/common/wayfinder/wayfinder.js +0 -26
- package/lib/esm/common/wayfinder/wayfinder.test.js +23 -24
- package/lib/esm/utils/random.js +26 -0
- package/lib/esm/utils/utils.test.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/readCommands.d.ts +4 -4
- package/lib/types/common/http.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/fixed.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/priority.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/random.d.ts +0 -1
- package/lib/types/common/wayfinder/routers/simple-cache.d.ts +0 -1
- package/lib/types/common/wayfinder/wayfinder.d.ts +15 -8
- package/lib/types/types/common.d.ts +0 -1
- package/lib/types/types/io.d.ts +2 -2
- package/lib/types/types/token.d.ts +0 -2
- package/lib/types/types/wayfinder.d.ts +0 -1
- package/lib/types/utils/base64.d.ts +0 -2
- package/lib/types/utils/random.d.ts +7 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +3 -3
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -3,7 +3,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.defaultTtlSecondsCLI = void 0;
|
|
7
|
+
exports.stringifyJsonForCLIDisplay = stringifyJsonForCLIDisplay;
|
|
8
|
+
exports.runCommand = runCommand;
|
|
9
|
+
exports.applyOptions = applyOptions;
|
|
10
|
+
exports.makeCommand = makeCommand;
|
|
11
|
+
exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
|
|
12
|
+
exports.requiredJwkFromOptions = requiredJwkFromOptions;
|
|
13
|
+
exports.jwkToAddress = jwkToAddress;
|
|
14
|
+
exports.getLoggerFromOptions = getLoggerFromOptions;
|
|
15
|
+
exports.readARIOFromOptions = readARIOFromOptions;
|
|
16
|
+
exports.contractSignerFromOptions = contractSignerFromOptions;
|
|
17
|
+
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
18
|
+
exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
|
|
19
|
+
exports.writeARIOFromOptions = writeARIOFromOptions;
|
|
20
|
+
exports.formatARIOWithCommas = formatARIOWithCommas;
|
|
21
|
+
exports.formatMARIOToARIOWithCommas = formatMARIOToARIOWithCommas;
|
|
22
|
+
exports.addressFromOptions = addressFromOptions;
|
|
23
|
+
exports.requiredAddressFromOptions = requiredAddressFromOptions;
|
|
24
|
+
exports.paginationParamsFromOptions = paginationParamsFromOptions;
|
|
25
|
+
exports.epochInputFromOptions = epochInputFromOptions;
|
|
26
|
+
exports.requiredInitiatorFromOptions = requiredInitiatorFromOptions;
|
|
27
|
+
exports.customTagsFromOptions = customTagsFromOptions;
|
|
28
|
+
exports.gatewaySettingsFromOptions = gatewaySettingsFromOptions;
|
|
29
|
+
exports.requiredTargetAndQuantityFromOptions = requiredTargetAndQuantityFromOptions;
|
|
30
|
+
exports.redelegateParamsFromOptions = redelegateParamsFromOptions;
|
|
31
|
+
exports.recordTypeFromOptions = recordTypeFromOptions;
|
|
32
|
+
exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
|
|
33
|
+
exports.assertEnoughBalanceForArNSPurchase = assertEnoughBalanceForArNSPurchase;
|
|
34
|
+
exports.assertEnoughMARIOBalance = assertEnoughMARIOBalance;
|
|
35
|
+
exports.confirmationPrompt = confirmationPrompt;
|
|
36
|
+
exports.assertConfirmationPrompt = assertConfirmationPrompt;
|
|
37
|
+
exports.requiredProcessIdFromOptions = requiredProcessIdFromOptions;
|
|
38
|
+
exports.readANTFromOptions = readANTFromOptions;
|
|
39
|
+
exports.writeANTFromOptions = writeANTFromOptions;
|
|
40
|
+
exports.booleanFromOptions = booleanFromOptions;
|
|
41
|
+
exports.requiredStringFromOptions = requiredStringFromOptions;
|
|
42
|
+
exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
|
|
43
|
+
exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
|
|
44
|
+
exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
|
|
45
|
+
exports.getANTStateFromOptions = getANTStateFromOptions;
|
|
46
|
+
exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
|
|
47
|
+
exports.fundFromFromOptions = fundFromFromOptions;
|
|
48
|
+
exports.assertLockLengthInRange = assertLockLengthInRange;
|
|
7
49
|
/**
|
|
8
50
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
51
|
*
|
|
@@ -30,7 +72,6 @@ exports.defaultTtlSecondsCLI = 3600;
|
|
|
30
72
|
function stringifyJsonForCLIDisplay(json) {
|
|
31
73
|
return JSON.stringify(json, null, 2);
|
|
32
74
|
}
|
|
33
|
-
exports.stringifyJsonForCLIDisplay = stringifyJsonForCLIDisplay;
|
|
34
75
|
function logCommandOutput(output) {
|
|
35
76
|
console.log(stringifyJsonForCLIDisplay(output));
|
|
36
77
|
}
|
|
@@ -59,14 +100,12 @@ async function runCommand(command, action) {
|
|
|
59
100
|
exitWithErrorLog(error, options.debug);
|
|
60
101
|
}
|
|
61
102
|
}
|
|
62
|
-
exports.runCommand = runCommand;
|
|
63
103
|
function applyOptions(command, options) {
|
|
64
104
|
[...options].forEach((option) => {
|
|
65
105
|
command.option(option.alias, option.description, option.default);
|
|
66
106
|
});
|
|
67
107
|
return command;
|
|
68
108
|
}
|
|
69
|
-
exports.applyOptions = applyOptions;
|
|
70
109
|
function makeCommand({ description, name, options = [], action, }) {
|
|
71
110
|
const command = commander_1.program.command(name).description(description);
|
|
72
111
|
const appliedCommand = applyOptions(command, [...options, ...options_js_1.globalOptions]);
|
|
@@ -75,7 +114,6 @@ function makeCommand({ description, name, options = [], action, }) {
|
|
|
75
114
|
}
|
|
76
115
|
return appliedCommand;
|
|
77
116
|
}
|
|
78
|
-
exports.makeCommand = makeCommand;
|
|
79
117
|
function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
80
118
|
if (arioProcessId !== undefined) {
|
|
81
119
|
return arioProcessId;
|
|
@@ -88,7 +126,6 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
|
88
126
|
}
|
|
89
127
|
return index_js_1.ARIO_MAINNET_PROCESS_ID;
|
|
90
128
|
}
|
|
91
|
-
exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
|
|
92
129
|
function walletFromOptions({ privateKey, walletFile, }) {
|
|
93
130
|
if (privateKey !== undefined) {
|
|
94
131
|
return JSON.parse(privateKey);
|
|
@@ -105,11 +142,9 @@ function requiredJwkFromOptions(options) {
|
|
|
105
142
|
}
|
|
106
143
|
return jwk;
|
|
107
144
|
}
|
|
108
|
-
exports.requiredJwkFromOptions = requiredJwkFromOptions;
|
|
109
145
|
function jwkToAddress(jwk) {
|
|
110
146
|
return (0, index_js_1.sha256B64Url)((0, index_js_1.fromB64Url)(jwk.n));
|
|
111
147
|
}
|
|
112
|
-
exports.jwkToAddress = jwkToAddress;
|
|
113
148
|
function setLoggerIfDebug(options) {
|
|
114
149
|
if (options.debug) {
|
|
115
150
|
index_js_1.Logger.default.setLogLevel('debug');
|
|
@@ -119,7 +154,6 @@ function getLoggerFromOptions(options) {
|
|
|
119
154
|
setLoggerIfDebug(options);
|
|
120
155
|
return index_js_1.Logger.default;
|
|
121
156
|
}
|
|
122
|
-
exports.getLoggerFromOptions = getLoggerFromOptions;
|
|
123
157
|
function aoProcessFromOptions(options) {
|
|
124
158
|
return new index_js_1.AOProcess({
|
|
125
159
|
processId: arioProcessIdFromOptions(options),
|
|
@@ -135,7 +169,6 @@ function readARIOFromOptions(options) {
|
|
|
135
169
|
paymentUrl: options.paymentUrl,
|
|
136
170
|
});
|
|
137
171
|
}
|
|
138
|
-
exports.readARIOFromOptions = readARIOFromOptions;
|
|
139
172
|
function contractSignerFromOptions(options) {
|
|
140
173
|
const wallet = walletFromOptions(options);
|
|
141
174
|
if (wallet === undefined) {
|
|
@@ -151,7 +184,6 @@ function contractSignerFromOptions(options) {
|
|
|
151
184
|
const signer = new index_js_1.ArweaveSigner(wallet);
|
|
152
185
|
return { signer, signerAddress: jwkToAddress(wallet) };
|
|
153
186
|
}
|
|
154
|
-
exports.contractSignerFromOptions = contractSignerFromOptions;
|
|
155
187
|
function requiredContractSignerFromOptions(options) {
|
|
156
188
|
const contractSigner = contractSignerFromOptions(options);
|
|
157
189
|
if (contractSigner === undefined) {
|
|
@@ -159,11 +191,9 @@ function requiredContractSignerFromOptions(options) {
|
|
|
159
191
|
}
|
|
160
192
|
return contractSigner;
|
|
161
193
|
}
|
|
162
|
-
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
163
194
|
function requiredAoSignerFromOptions(options) {
|
|
164
195
|
return (0, index_js_1.createAoSigner)(requiredContractSignerFromOptions(options).signer);
|
|
165
196
|
}
|
|
166
|
-
exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
|
|
167
197
|
function writeARIOFromOptions(options) {
|
|
168
198
|
const { signer, signerAddress } = requiredContractSignerFromOptions(options);
|
|
169
199
|
setLoggerIfDebug(options);
|
|
@@ -176,7 +206,6 @@ function writeARIOFromOptions(options) {
|
|
|
176
206
|
signerAddress,
|
|
177
207
|
};
|
|
178
208
|
}
|
|
179
|
-
exports.writeARIOFromOptions = writeARIOFromOptions;
|
|
180
209
|
function formatARIOWithCommas(value) {
|
|
181
210
|
const [integerPart, decimalPart] = value.toString().split('.');
|
|
182
211
|
const integerWithCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
@@ -185,11 +214,9 @@ function formatARIOWithCommas(value) {
|
|
|
185
214
|
}
|
|
186
215
|
return integerWithCommas + '.' + decimalPart;
|
|
187
216
|
}
|
|
188
|
-
exports.formatARIOWithCommas = formatARIOWithCommas;
|
|
189
217
|
function formatMARIOToARIOWithCommas(value) {
|
|
190
218
|
return formatARIOWithCommas(value.toARIO());
|
|
191
219
|
}
|
|
192
|
-
exports.formatMARIOToARIOWithCommas = formatMARIOToARIOWithCommas;
|
|
193
220
|
/** helper to get address from --address option first, then check wallet options */
|
|
194
221
|
function addressFromOptions(options) {
|
|
195
222
|
if (options.address !== undefined) {
|
|
@@ -201,7 +228,6 @@ function addressFromOptions(options) {
|
|
|
201
228
|
}
|
|
202
229
|
return undefined;
|
|
203
230
|
}
|
|
204
|
-
exports.addressFromOptions = addressFromOptions;
|
|
205
231
|
function requiredAddressFromOptions(options) {
|
|
206
232
|
const address = addressFromOptions(options);
|
|
207
233
|
if (address !== undefined) {
|
|
@@ -209,7 +235,6 @@ function requiredAddressFromOptions(options) {
|
|
|
209
235
|
}
|
|
210
236
|
throw new Error('No address provided. Use --address or --wallet-file');
|
|
211
237
|
}
|
|
212
|
-
exports.requiredAddressFromOptions = requiredAddressFromOptions;
|
|
213
238
|
const defaultCliPaginationLimit = 10; // more friendly UX than 100
|
|
214
239
|
function paginationParamsFromOptions(options) {
|
|
215
240
|
const { cursor, limit, sortBy, sortOrder } = options;
|
|
@@ -227,7 +252,6 @@ function paginationParamsFromOptions(options) {
|
|
|
227
252
|
sortOrder,
|
|
228
253
|
};
|
|
229
254
|
}
|
|
230
|
-
exports.paginationParamsFromOptions = paginationParamsFromOptions;
|
|
231
255
|
function epochInputFromOptions(options) {
|
|
232
256
|
if (options.epochIndex !== undefined) {
|
|
233
257
|
return { epochIndex: +options.epochIndex };
|
|
@@ -237,14 +261,12 @@ function epochInputFromOptions(options) {
|
|
|
237
261
|
}
|
|
238
262
|
return undefined;
|
|
239
263
|
}
|
|
240
|
-
exports.epochInputFromOptions = epochInputFromOptions;
|
|
241
264
|
function requiredInitiatorFromOptions(options) {
|
|
242
265
|
if (options.initiator !== undefined) {
|
|
243
266
|
return options.initiator;
|
|
244
267
|
}
|
|
245
268
|
return requiredAddressFromOptions(options);
|
|
246
269
|
}
|
|
247
|
-
exports.requiredInitiatorFromOptions = requiredInitiatorFromOptions;
|
|
248
270
|
function customTagsFromOptions(options) {
|
|
249
271
|
if (options.tags === undefined) {
|
|
250
272
|
return {};
|
|
@@ -269,7 +291,6 @@ function customTagsFromOptions(options) {
|
|
|
269
291
|
tags,
|
|
270
292
|
};
|
|
271
293
|
}
|
|
272
|
-
exports.customTagsFromOptions = customTagsFromOptions;
|
|
273
294
|
function gatewaySettingsFromOptions({ allowDelegatedStaking, autoStake, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, observerAddress, port, properties, allowedDelegates, }) {
|
|
274
295
|
return {
|
|
275
296
|
observerAddress,
|
|
@@ -287,7 +308,6 @@ function gatewaySettingsFromOptions({ allowDelegatedStaking, autoStake, delegate
|
|
|
287
308
|
properties,
|
|
288
309
|
};
|
|
289
310
|
}
|
|
290
|
-
exports.gatewaySettingsFromOptions = gatewaySettingsFromOptions;
|
|
291
311
|
function requiredTargetAndQuantityFromOptions(options) {
|
|
292
312
|
if (options.target === undefined) {
|
|
293
313
|
throw new Error('No target provided. Use --target');
|
|
@@ -300,7 +320,6 @@ function requiredTargetAndQuantityFromOptions(options) {
|
|
|
300
320
|
arioQuantity: new index_js_1.ARIOToken(+options.quantity),
|
|
301
321
|
};
|
|
302
322
|
}
|
|
303
|
-
exports.requiredTargetAndQuantityFromOptions = requiredTargetAndQuantityFromOptions;
|
|
304
323
|
function redelegateParamsFromOptions(options) {
|
|
305
324
|
const { target, arioQuantity: aRIOQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
306
325
|
const source = options.source;
|
|
@@ -314,7 +333,6 @@ function redelegateParamsFromOptions(options) {
|
|
|
314
333
|
stakeQty: aRIOQuantity.toMARIO(),
|
|
315
334
|
};
|
|
316
335
|
}
|
|
317
|
-
exports.redelegateParamsFromOptions = redelegateParamsFromOptions;
|
|
318
336
|
function recordTypeFromOptions(options) {
|
|
319
337
|
options.type ??= 'lease';
|
|
320
338
|
if (options.type !== 'lease' && options.type !== 'permabuy') {
|
|
@@ -322,14 +340,12 @@ function recordTypeFromOptions(options) {
|
|
|
322
340
|
}
|
|
323
341
|
return options.type;
|
|
324
342
|
}
|
|
325
|
-
exports.recordTypeFromOptions = recordTypeFromOptions;
|
|
326
343
|
function requiredMARIOFromOptions(options, key) {
|
|
327
344
|
if (options[key] === undefined) {
|
|
328
345
|
throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
|
|
329
346
|
}
|
|
330
347
|
return new index_js_1.ARIOToken(+options[key]).toMARIO();
|
|
331
348
|
}
|
|
332
|
-
exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
|
|
333
349
|
async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
334
350
|
if (costDetailsParams.fundFrom === 'turbo') {
|
|
335
351
|
return;
|
|
@@ -348,7 +364,6 @@ async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsPa
|
|
|
348
364
|
});
|
|
349
365
|
}
|
|
350
366
|
}
|
|
351
|
-
exports.assertEnoughBalanceForArNSPurchase = assertEnoughBalanceForArNSPurchase;
|
|
352
367
|
async function assertEnoughMARIOBalance({ address, ario, mARIOQuantity, }) {
|
|
353
368
|
if (typeof mARIOQuantity === 'number') {
|
|
354
369
|
mARIOQuantity = new index_js_1.mARIOToken(mARIOQuantity);
|
|
@@ -358,7 +373,6 @@ async function assertEnoughMARIOBalance({ address, ario, mARIOQuantity, }) {
|
|
|
358
373
|
throw new Error(`Insufficient ARIO balance for action. Balance available: ${formatMARIOToARIOWithCommas(new index_js_1.mARIOToken(balance))} ARIO`);
|
|
359
374
|
}
|
|
360
375
|
}
|
|
361
|
-
exports.assertEnoughMARIOBalance = assertEnoughMARIOBalance;
|
|
362
376
|
async function confirmationPrompt(message) {
|
|
363
377
|
const { confirm } = await (0, prompts_1.default)({
|
|
364
378
|
type: 'confirm',
|
|
@@ -367,21 +381,18 @@ async function confirmationPrompt(message) {
|
|
|
367
381
|
});
|
|
368
382
|
return confirm;
|
|
369
383
|
}
|
|
370
|
-
exports.confirmationPrompt = confirmationPrompt;
|
|
371
384
|
async function assertConfirmationPrompt(message, options) {
|
|
372
385
|
if (options.skipConfirmation) {
|
|
373
386
|
return true;
|
|
374
387
|
}
|
|
375
388
|
return confirmationPrompt(message);
|
|
376
389
|
}
|
|
377
|
-
exports.assertConfirmationPrompt = assertConfirmationPrompt;
|
|
378
390
|
function requiredProcessIdFromOptions(o) {
|
|
379
391
|
if (o.processId === undefined) {
|
|
380
392
|
throw new Error('--process-id is required');
|
|
381
393
|
}
|
|
382
394
|
return o.processId;
|
|
383
395
|
}
|
|
384
|
-
exports.requiredProcessIdFromOptions = requiredProcessIdFromOptions;
|
|
385
396
|
function ANTProcessFromOptions(options) {
|
|
386
397
|
return new index_js_1.AOProcess({
|
|
387
398
|
processId: requiredProcessIdFromOptions(options),
|
|
@@ -395,7 +406,6 @@ function readANTFromOptions(options) {
|
|
|
395
406
|
process: ANTProcessFromOptions(options),
|
|
396
407
|
});
|
|
397
408
|
}
|
|
398
|
-
exports.readANTFromOptions = readANTFromOptions;
|
|
399
409
|
function writeANTFromOptions(options, signer) {
|
|
400
410
|
signer ??= requiredContractSignerFromOptions(options).signer;
|
|
401
411
|
return index_js_1.ANT.init({
|
|
@@ -403,11 +413,9 @@ function writeANTFromOptions(options, signer) {
|
|
|
403
413
|
signer,
|
|
404
414
|
});
|
|
405
415
|
}
|
|
406
|
-
exports.writeANTFromOptions = writeANTFromOptions;
|
|
407
416
|
function booleanFromOptions(options, key) {
|
|
408
417
|
return !!options[key];
|
|
409
418
|
}
|
|
410
|
-
exports.booleanFromOptions = booleanFromOptions;
|
|
411
419
|
function requiredStringFromOptions(options, key) {
|
|
412
420
|
const value = options[key];
|
|
413
421
|
if (value === undefined) {
|
|
@@ -415,7 +423,6 @@ function requiredStringFromOptions(options, key) {
|
|
|
415
423
|
}
|
|
416
424
|
return value;
|
|
417
425
|
}
|
|
418
|
-
exports.requiredStringFromOptions = requiredStringFromOptions;
|
|
419
426
|
function requiredStringArrayFromOptions(options, key) {
|
|
420
427
|
const value = options[key];
|
|
421
428
|
if (value === undefined) {
|
|
@@ -426,7 +433,6 @@ function requiredStringArrayFromOptions(options, key) {
|
|
|
426
433
|
}
|
|
427
434
|
return value;
|
|
428
435
|
}
|
|
429
|
-
exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
|
|
430
436
|
function positiveIntegerFromOptions(options, key) {
|
|
431
437
|
const value = options[key];
|
|
432
438
|
if (value === undefined) {
|
|
@@ -438,7 +444,6 @@ function positiveIntegerFromOptions(options, key) {
|
|
|
438
444
|
}
|
|
439
445
|
return numberValue;
|
|
440
446
|
}
|
|
441
|
-
exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
|
|
442
447
|
function requiredPositiveIntegerFromOptions(options, key) {
|
|
443
448
|
const value = positiveIntegerFromOptions(options, key);
|
|
444
449
|
if (value === undefined) {
|
|
@@ -446,7 +451,6 @@ function requiredPositiveIntegerFromOptions(options, key) {
|
|
|
446
451
|
}
|
|
447
452
|
return value;
|
|
448
453
|
}
|
|
449
|
-
exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
|
|
450
454
|
function getANTStateFromOptions(options) {
|
|
451
455
|
return (0, index_js_1.initANTStateForAddress)({
|
|
452
456
|
owner: requiredAddressFromOptions(options),
|
|
@@ -462,7 +466,6 @@ function getANTStateFromOptions(options) {
|
|
|
462
466
|
: exports.defaultTtlSecondsCLI,
|
|
463
467
|
});
|
|
464
468
|
}
|
|
465
|
-
exports.getANTStateFromOptions = getANTStateFromOptions;
|
|
466
469
|
function getTokenCostParamsFromOptions(o) {
|
|
467
470
|
o.intent ??= 'Buy-Name';
|
|
468
471
|
o.type ??= 'lease';
|
|
@@ -482,7 +485,6 @@ function getTokenCostParamsFromOptions(o) {
|
|
|
482
485
|
fromAddress: addressFromOptions(o),
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
|
-
exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
|
|
486
488
|
function fundFromFromOptions(o) {
|
|
487
489
|
if (o.fundFrom !== undefined) {
|
|
488
490
|
if (!(0, index_js_1.isValidFundFrom)(o.fundFrom)) {
|
|
@@ -491,7 +493,6 @@ function fundFromFromOptions(o) {
|
|
|
491
493
|
}
|
|
492
494
|
return o.fundFrom ?? 'balance';
|
|
493
495
|
}
|
|
494
|
-
exports.fundFromFromOptions = fundFromFromOptions;
|
|
495
496
|
function assertLockLengthInRange(lockLengthMs, assertMin = true) {
|
|
496
497
|
const minLockLengthMs = 1209600000; // 14 days
|
|
497
498
|
const maxLockLengthMs = 378432000000; // ~12 years
|
|
@@ -505,4 +506,3 @@ function assertLockLengthInRange(lockLengthMs, assertMin = true) {
|
|
|
505
506
|
throw new Error(`Lock length must be at least 14 days (1209600000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
506
507
|
}
|
|
507
508
|
}
|
|
508
|
-
exports.assertLockLengthInRange = assertLockLengthInRange;
|
package/lib/cjs/common/faucet.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ARIOTokenFaucet =
|
|
3
|
+
exports.ARIOTokenFaucet = void 0;
|
|
4
|
+
exports.createFaucet = createFaucet;
|
|
4
5
|
const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
|
|
5
6
|
/**
|
|
6
7
|
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
@@ -30,7 +31,6 @@ function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, })
|
|
|
30
31
|
});
|
|
31
32
|
return proxy;
|
|
32
33
|
}
|
|
33
|
-
exports.createFaucet = createFaucet;
|
|
34
34
|
class ARIOTokenFaucet {
|
|
35
35
|
faucetUrl;
|
|
36
36
|
processId;
|
package/lib/cjs/common/turbo.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = void 0;
|
|
4
|
+
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
5
|
+
exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
4
6
|
/**
|
|
5
7
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
8
|
*
|
|
@@ -78,7 +80,6 @@ async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)()
|
|
|
78
80
|
'x-signature-type': signatureType,
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
|
-
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
82
83
|
class TurboArNSPaymentFactory {
|
|
83
84
|
static init(config) {
|
|
84
85
|
const { signer, paymentUrl, axios, logger } = config ?? {};
|
|
@@ -205,4 +206,3 @@ function isTurboArNSSigner(signer) {
|
|
|
205
206
|
signer instanceof arbundles_1.ArconnectSigner;
|
|
206
207
|
return isWanderWallet || isSigner;
|
|
207
208
|
}
|
|
208
|
-
exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PriorityGatewayRouter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const random_js_1 = require("../../../utils/random.js");
|
|
5
5
|
// TODO: one of N where N are in the last time window have met certain performance thresholds
|
|
6
6
|
// TODO: look at bitorrent routing protocols for inspiration
|
|
7
7
|
// TODO: router that looks at local stats/metrics and adjusts based on those
|
|
@@ -28,7 +28,7 @@ class PriorityGatewayRouter {
|
|
|
28
28
|
? (a, b) => a[this.sortBy] - b[this.sortBy]
|
|
29
29
|
: (a, b) => b[this.sortBy] - a[this.sortBy])
|
|
30
30
|
.slice(0, this.limit);
|
|
31
|
-
const targetGateway = sortedGateways[(0,
|
|
31
|
+
const targetGateway = sortedGateways[(0, random_js_1.randomInt)(0, sortedGateways.length)];
|
|
32
32
|
if (targetGateway === undefined) {
|
|
33
33
|
throw new Error('No target gateway found');
|
|
34
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RandomGatewayRouter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const random_js_1 = require("../../../utils/random.js");
|
|
5
5
|
class RandomGatewayRouter {
|
|
6
6
|
name = 'random';
|
|
7
7
|
gatewaysProvider;
|
|
@@ -13,7 +13,7 @@ class RandomGatewayRouter {
|
|
|
13
13
|
async getTargetGateway() {
|
|
14
14
|
const allGateways = await this.gatewaysProvider.getGateways();
|
|
15
15
|
const gateways = allGateways.filter((g) => g.status === 'joined' && !this.blocklist.includes(g.settings.fqdn));
|
|
16
|
-
const targetGateway = gateways[(0,
|
|
16
|
+
const targetGateway = gateways[(0, random_js_1.randomInt)(0, gateways.length)];
|
|
17
17
|
if (targetGateway === undefined) {
|
|
18
18
|
throw new Error('No target gateway found');
|
|
19
19
|
}
|
|
@@ -1,39 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Wayfinder = exports.createWayfinderClient = exports.resolveWayfinderUrl = exports.
|
|
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 crypto_1 = require("crypto");
|
|
3
|
+
exports.Wayfinder = exports.createWayfinderClient = exports.resolveWayfinderUrl = exports.txIdRegex = exports.arnsRegex = void 0;
|
|
20
4
|
const io_js_1 = require("../io.js");
|
|
21
5
|
const gateways_js_1 = require("./gateways.js");
|
|
22
6
|
const random_js_1 = require("./routers/random.js");
|
|
23
7
|
// known regexes for wayfinder urls
|
|
24
8
|
exports.arnsRegex = /^[a-z0-9_-]{1,51}$/;
|
|
25
9
|
exports.txIdRegex = /^[a-z0-9]{43}$/;
|
|
26
|
-
/**
|
|
27
|
-
* Cryptographically secure helper for randomness, does not support seeding
|
|
28
|
-
* @param min - the minimum value
|
|
29
|
-
* @param max - the maximum value
|
|
30
|
-
* @returns a random integer between min and max
|
|
31
|
-
*/
|
|
32
|
-
const randomInt = (min, max) => {
|
|
33
|
-
const [rand] = crypto_1.webcrypto.getRandomValues(new Uint32Array(1));
|
|
34
|
-
return min + (rand % (max - min));
|
|
35
|
-
};
|
|
36
|
-
exports.randomInt = randomInt;
|
|
37
10
|
/**
|
|
38
11
|
* Core function to resolve a wayfinder url against a target gateway
|
|
39
12
|
* @param originalUrl - the wayfinder url to resolve
|
|
@@ -224,31 +224,30 @@ const stubbedGatewaysProvider = {
|
|
|
224
224
|
node_assert_1.default.strictEqual(response.data, nativeAxios.data);
|
|
225
225
|
});
|
|
226
226
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
})
|
|
227
|
+
(0, node_test_1.describe)('got', () => {
|
|
228
|
+
let wayfinder;
|
|
229
|
+
(0, node_test_1.before)(() => {
|
|
230
|
+
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
231
|
+
httpClient: got_1.default,
|
|
232
|
+
router: new random_js_1.RandomGatewayRouter({
|
|
233
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
(0, node_test_1.it)('should fetch the data using the got default function against the target gateway', async () => {
|
|
238
|
+
const [nativeGot, response] = await Promise.all([
|
|
239
|
+
(0, got_1.default)('https://ao.arweave.net'),
|
|
240
|
+
wayfinder.request('ar://ao'),
|
|
241
|
+
]);
|
|
242
|
+
node_assert_1.default.strictEqual(response.statusCode, 200);
|
|
243
|
+
node_assert_1.default.strictEqual(response.statusCode, nativeGot.statusCode);
|
|
244
|
+
node_assert_1.default.deepStrictEqual(response.body, nativeGot.body);
|
|
245
|
+
});
|
|
246
|
+
(0, node_test_1.it)('should stream the data using got.stream against the selected target gateway', async () => {
|
|
247
|
+
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream('https://ao.arweave.net', { decompress: false }));
|
|
248
|
+
const wayfinderBuffer = await (0, consumers_1.buffer)(await wayfinder.request.stream('ar://ao', { decompress: false }));
|
|
249
|
+
node_assert_1.default.deepStrictEqual(wayfinderBuffer, nativeBuffer);
|
|
236
250
|
});
|
|
237
|
-
});
|
|
238
|
-
(0, node_test_1.it)('should fetch the data using the got default function against the target gateway', async () => {
|
|
239
|
-
const [nativeGot, response] = await Promise.all([
|
|
240
|
-
(0, got_1.default)('https://ao.arweave.net'),
|
|
241
|
-
wayfinder.request('ar://ao'),
|
|
242
|
-
]);
|
|
243
|
-
node_assert_1.default.strictEqual(response.statusCode, 200);
|
|
244
|
-
node_assert_1.default.strictEqual(response.statusCode, nativeGot.statusCode);
|
|
245
|
-
node_assert_1.default.deepStrictEqual(response.body, nativeGot.body);
|
|
246
|
-
});
|
|
247
|
-
(0, node_test_1.it)('should stream the data using got.stream against the selected target gateway', async () => {
|
|
248
|
-
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream('https://ao.arweave.net', { decompress: false }));
|
|
249
|
-
const wayfinderBuffer = await (0, consumers_1.buffer)(await wayfinder.request.stream('ar://ao', { decompress: false }));
|
|
250
|
-
node_assert_1.default.deepStrictEqual(wayfinderBuffer, nativeBuffer);
|
|
251
251
|
});
|
|
252
252
|
});
|
|
253
|
-
// TODO: streaming support using got.stream and got()
|
|
254
253
|
});
|
package/lib/cjs/types/ant.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AntInfoSchema = exports.AntHandlersSchema = exports.AntHandlerNames = exports.AntWriteHandlers = exports.AntReadHandlers = exports.SpawnANTStateSchema = exports.AntStateSchema = exports.AntBalancesSchema = exports.AntControllersSchema = exports.AntRecordsSchema = exports.AntRecordSchema = exports.AntKeywordsSchema = exports.AntDescriptionSchema = exports.IntegerStringSchema = exports.AOAddressSchema = exports.ArweaveTxIdSchema = void 0;
|
|
4
|
+
exports.isAoANTState = isAoANTState;
|
|
4
5
|
/**
|
|
5
6
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
7
|
*
|
|
@@ -147,4 +148,3 @@ exports.AntInfoSchema = zod_1.z.object({
|
|
|
147
148
|
function isAoANTState(state) {
|
|
148
149
|
return exports.AntStateSchema.safeParse(state).success;
|
|
149
150
|
}
|
|
150
|
-
exports.isAoANTState = isAoANTState;
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isValidFundFrom = exports.fundFromOptions = exports.isValidIntent = exports.intentsUsingYears = exports.validIntents = exports.isDistributedEpoch = exports.isDistributedEpochData = void 0;
|
|
4
|
+
exports.isProcessConfiguration = isProcessConfiguration;
|
|
5
|
+
exports.isProcessIdConfiguration = isProcessIdConfiguration;
|
|
6
|
+
exports.isLeasedArNSRecord = isLeasedArNSRecord;
|
|
4
7
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
5
8
|
const isDistributedEpochData = (data) => {
|
|
6
9
|
return data.distributedTimestamp !== undefined;
|
|
@@ -37,15 +40,12 @@ exports.isValidFundFrom = isValidFundFrom;
|
|
|
37
40
|
function isProcessConfiguration(config) {
|
|
38
41
|
return config !== undefined && 'process' in config;
|
|
39
42
|
}
|
|
40
|
-
exports.isProcessConfiguration = isProcessConfiguration;
|
|
41
43
|
function isProcessIdConfiguration(config) {
|
|
42
44
|
return (config !== undefined &&
|
|
43
45
|
'processId' in config &&
|
|
44
46
|
typeof config.processId === 'string' &&
|
|
45
47
|
(0, arweave_js_1.validateArweaveId)(config.processId) === true);
|
|
46
48
|
}
|
|
47
|
-
exports.isProcessIdConfiguration = isProcessIdConfiguration;
|
|
48
49
|
function isLeasedArNSRecord(record) {
|
|
49
50
|
return record.type === 'lease';
|
|
50
51
|
}
|
|
51
|
-
exports.isLeasedArNSRecord = isLeasedArNSRecord;
|
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defaultANTLogoId = exports.defaultTargetManifestId = void 0;
|
|
4
|
+
exports.spawnANT = spawnANT;
|
|
5
|
+
exports.evolveANT = evolveANT;
|
|
6
|
+
exports.isAoSigner = isAoSigner;
|
|
7
|
+
exports.createAoSigner = createAoSigner;
|
|
8
|
+
exports.initANTStateForAddress = initANTStateForAddress;
|
|
9
|
+
exports.parseAoEpochData = parseAoEpochData;
|
|
10
|
+
exports.errorMessageFromOutput = errorMessageFromOutput;
|
|
11
|
+
exports.removeUnicodeFromError = removeUnicodeFromError;
|
|
4
12
|
/**
|
|
5
13
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
14
|
*
|
|
@@ -53,7 +61,6 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, ao = (0
|
|
|
53
61
|
});
|
|
54
62
|
return processId;
|
|
55
63
|
}
|
|
56
|
-
exports.spawnANT = spawnANT;
|
|
57
64
|
async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), logger = index_js_1.Logger.default, arweave = arweave_js_1.defaultArweave, }) {
|
|
58
65
|
const aosClient = new index_js_1.AOProcess({
|
|
59
66
|
processId,
|
|
@@ -80,7 +87,6 @@ async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_L
|
|
|
80
87
|
});
|
|
81
88
|
return evolveMsgId;
|
|
82
89
|
}
|
|
83
|
-
exports.evolveANT = evolveANT;
|
|
84
90
|
function isAoSigner(value) {
|
|
85
91
|
const TagSchema = zod_1.z.object({
|
|
86
92
|
name: zod_1.z.string(),
|
|
@@ -106,7 +112,6 @@ function isAoSigner(value) {
|
|
|
106
112
|
return false;
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
|
-
exports.isAoSigner = isAoSigner;
|
|
110
115
|
function createAoSigner(signer) {
|
|
111
116
|
if (isAoSigner(signer)) {
|
|
112
117
|
return signer;
|
|
@@ -146,7 +151,6 @@ function createAoSigner(signer) {
|
|
|
146
151
|
// @ts-ignore Buffer vs ArrayBuffer type mismatch
|
|
147
152
|
return aoSigner;
|
|
148
153
|
}
|
|
149
|
-
exports.createAoSigner = createAoSigner;
|
|
150
154
|
exports.defaultTargetManifestId = '-k7t8xMoB8hW482609Z9F4bTFMC3MnuW8bTvTyT8pFI';
|
|
151
155
|
exports.defaultANTLogoId = 'Sie_26dvgyok0PZD_-iQAFOhOd5YxDTkczOLoqTTL_A';
|
|
152
156
|
function initANTStateForAddress({ owner, targetId, ttlSeconds = 3600, keywords = [], controllers = [], description = '', ticker = 'aos', name = 'ANT', logo = exports.defaultANTLogoId, }) {
|
|
@@ -167,7 +171,6 @@ function initANTStateForAddress({ owner, targetId, ttlSeconds = 3600, keywords =
|
|
|
167
171
|
logo,
|
|
168
172
|
};
|
|
169
173
|
}
|
|
170
|
-
exports.initANTStateForAddress = initANTStateForAddress;
|
|
171
174
|
/**
|
|
172
175
|
* Uses zod schema to parse the epoch data
|
|
173
176
|
*/
|
|
@@ -184,7 +187,6 @@ function parseAoEpochData(value) {
|
|
|
184
187
|
});
|
|
185
188
|
return epochDataSchema.parse(value);
|
|
186
189
|
}
|
|
187
|
-
exports.parseAoEpochData = parseAoEpochData;
|
|
188
190
|
function errorMessageFromOutput(output) {
|
|
189
191
|
const errorData = output.Error;
|
|
190
192
|
// Attempt to extract error details from Messages.Tags if Error is undefined
|
|
@@ -203,7 +205,6 @@ function errorMessageFromOutput(output) {
|
|
|
203
205
|
}
|
|
204
206
|
return undefined;
|
|
205
207
|
}
|
|
206
|
-
exports.errorMessageFromOutput = errorMessageFromOutput;
|
|
207
208
|
function removeUnicodeFromError(error) {
|
|
208
209
|
//The regular expression /[\u001b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g is designed to match ANSI escape codes used for terminal formatting. These are sequences that begin with \u001b (ESC character) and are often followed by [ and control codes.
|
|
209
210
|
const ESC = String.fromCharCode(27); // Represents '\u001b' or '\x1b'
|
|
@@ -211,4 +212,3 @@ function removeUnicodeFromError(error) {
|
|
|
211
212
|
.replace(new RegExp(`${ESC}[\\[\\]()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`, 'g'), '')
|
|
212
213
|
.trim();
|
|
213
214
|
}
|
|
214
|
-
exports.removeUnicodeFromError = removeUnicodeFromError;
|