@ar.io/sdk 3.24.0 → 4.0.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 +682 -600
- package/lib/esm/cli/cli.js +188 -152
- package/lib/esm/cli/commands/antCommands.js +23 -58
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
- package/lib/esm/cli/commands/escrowCommands.js +221 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +142 -23
- package/lib/esm/cli/commands/pruneCommands.js +150 -0
- package/lib/esm/cli/commands/readCommands.js +22 -3
- package/lib/esm/cli/commands/transfer.js +6 -6
- package/lib/esm/cli/options.js +124 -58
- package/lib/esm/cli/utils.js +280 -174
- package/lib/esm/common/ant-registry.js +17 -143
- package/lib/esm/common/ant.js +44 -1167
- package/lib/esm/common/faucet.js +11 -6
- package/lib/esm/common/index.js +0 -4
- package/lib/esm/common/io.js +25 -1412
- package/lib/esm/constants.js +13 -19
- package/lib/esm/solana/ant-readable.js +724 -0
- package/lib/esm/solana/ant-registry-readable.js +133 -0
- package/lib/esm/solana/ant-registry-writeable.js +472 -0
- package/lib/esm/solana/ant-writeable.js +384 -0
- package/lib/esm/solana/ata.js +70 -0
- package/lib/esm/solana/canonical-message.js +128 -0
- package/lib/esm/solana/clusters.js +111 -0
- package/lib/esm/solana/constants.js +146 -0
- package/lib/esm/solana/delegation-math.js +112 -0
- package/lib/esm/solana/deserialize.js +711 -0
- package/lib/esm/solana/escrow.js +839 -0
- package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
- package/lib/esm/solana/funding-plan.js +699 -0
- package/lib/esm/solana/index.js +126 -0
- package/lib/esm/solana/instruction.js +39 -0
- package/lib/esm/solana/io-readable.js +2182 -0
- package/lib/esm/solana/io-writeable.js +3196 -0
- package/lib/esm/solana/json-rpc.js +90 -0
- package/lib/esm/solana/metadata.js +81 -0
- package/lib/esm/solana/mpl-core.js +192 -0
- package/lib/esm/solana/pda.js +332 -0
- package/lib/esm/solana/predict-prescribed-observers.js +110 -0
- package/lib/esm/solana/retry.js +117 -0
- package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
- package/lib/esm/solana/send.js +372 -0
- package/lib/esm/solana/spawn-ant.js +224 -0
- package/lib/esm/solana/types.js +1 -0
- package/lib/esm/types/ant.js +27 -15
- package/lib/esm/types/io.js +8 -11
- package/lib/esm/utils/ant.js +0 -63
- package/lib/esm/utils/index.js +0 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +5 -13
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
- package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
- package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
- package/lib/types/cli/commands/readCommands.d.ts +27 -22
- package/lib/types/cli/commands/transfer.d.ts +9 -9
- package/lib/types/cli/options.d.ts +76 -21
- package/lib/types/cli/types.d.ts +11 -13
- package/lib/types/cli/utils.d.ts +71 -31
- package/lib/types/common/ant-registry.d.ts +49 -47
- package/lib/types/common/ant.d.ts +54 -539
- package/lib/types/common/faucet.d.ts +20 -8
- package/lib/types/common/index.d.ts +0 -3
- package/lib/types/common/io.d.ts +51 -263
- package/lib/types/constants.d.ts +11 -18
- package/lib/types/solana/ant-readable.d.ts +180 -0
- package/lib/types/solana/ant-registry-readable.d.ts +105 -0
- package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
- package/lib/types/solana/ant-writeable.d.ts +177 -0
- package/lib/types/solana/ata.d.ts +44 -0
- package/lib/types/solana/canonical-message.d.ts +121 -0
- package/lib/types/solana/clusters.d.ts +109 -0
- package/lib/types/solana/constants.d.ts +119 -0
- package/lib/types/solana/delegation-math.d.ts +45 -0
- package/lib/types/solana/deserialize.d.ts +262 -0
- package/lib/types/solana/escrow.d.ts +480 -0
- package/lib/types/solana/events.d.ts +38 -0
- package/lib/types/solana/funding-plan.d.ts +225 -0
- package/lib/types/solana/index.d.ts +87 -0
- package/lib/types/solana/instruction.d.ts +39 -0
- package/lib/types/solana/io-readable.d.ts +499 -0
- package/lib/types/solana/io-writeable.d.ts +893 -0
- package/lib/types/solana/json-rpc.d.ts +47 -0
- package/lib/types/solana/metadata.d.ts +84 -0
- package/lib/types/solana/mpl-core.d.ts +120 -0
- package/lib/types/solana/pda.d.ts +95 -0
- package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
- package/lib/types/solana/retry.d.ts +62 -0
- package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
- package/lib/types/solana/send.d.ts +94 -0
- package/lib/types/solana/spawn-ant.d.ts +145 -0
- package/lib/types/solana/types.d.ts +82 -0
- package/lib/types/types/ant-registry.d.ts +43 -4
- package/lib/types/types/ant.d.ts +114 -96
- package/lib/types/types/common.d.ts +18 -74
- package/lib/types/types/faucet.d.ts +2 -2
- package/lib/types/types/io.d.ts +244 -158
- package/lib/types/types/token.d.ts +0 -12
- package/lib/types/utils/ant.d.ts +1 -12
- package/lib/types/utils/index.d.ts +0 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +36 -33
- package/lib/cjs/cli/cli.js +0 -822
- package/lib/cjs/cli/commands/antCommands.js +0 -113
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
- package/lib/cjs/cli/commands/readCommands.js +0 -215
- package/lib/cjs/cli/commands/transfer.js +0 -159
- package/lib/cjs/cli/options.js +0 -470
- package/lib/cjs/cli/types.js +0 -2
- package/lib/cjs/cli/utils.js +0 -639
- package/lib/cjs/common/ant-registry.js +0 -155
- package/lib/cjs/common/ant-versions.js +0 -93
- package/lib/cjs/common/ant.js +0 -1182
- package/lib/cjs/common/arweave.js +0 -27
- package/lib/cjs/common/contracts/ao-process.js +0 -224
- package/lib/cjs/common/error.js +0 -64
- package/lib/cjs/common/faucet.js +0 -150
- package/lib/cjs/common/hyperbeam/hb.js +0 -173
- package/lib/cjs/common/index.js +0 -42
- package/lib/cjs/common/io.js +0 -1423
- package/lib/cjs/common/logger.js +0 -83
- package/lib/cjs/common/loggers/winston.js +0 -68
- package/lib/cjs/common/marketplace.js +0 -731
- package/lib/cjs/common/turbo.js +0 -223
- package/lib/cjs/constants.js +0 -41
- package/lib/cjs/node/index.js +0 -39
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/types/ant-registry.js +0 -2
- package/lib/cjs/types/ant.js +0 -168
- package/lib/cjs/types/common.js +0 -2
- package/lib/cjs/types/faucet.js +0 -2
- package/lib/cjs/types/index.js +0 -37
- package/lib/cjs/types/io.js +0 -51
- package/lib/cjs/types/token.js +0 -116
- package/lib/cjs/utils/ant.js +0 -108
- package/lib/cjs/utils/ao.js +0 -432
- package/lib/cjs/utils/arweave.js +0 -285
- package/lib/cjs/utils/base64.js +0 -62
- package/lib/cjs/utils/hash.js +0 -56
- package/lib/cjs/utils/index.js +0 -38
- package/lib/cjs/utils/processes.js +0 -173
- package/lib/cjs/utils/random.js +0 -30
- package/lib/cjs/utils/schema.js +0 -15
- package/lib/cjs/utils/url.js +0 -37
- package/lib/cjs/version.js +0 -20
- package/lib/cjs/web/index.js +0 -41
- package/lib/esm/common/ant-versions.js +0 -87
- package/lib/esm/common/arweave.js +0 -21
- package/lib/esm/common/contracts/ao-process.js +0 -220
- package/lib/esm/common/hyperbeam/hb.js +0 -169
- package/lib/esm/common/marketplace.js +0 -724
- package/lib/esm/common/turbo.js +0 -215
- package/lib/esm/node/index.js +0 -20
- package/lib/esm/utils/ao.js +0 -420
- package/lib/esm/utils/arweave.js +0 -271
- package/lib/esm/utils/processes.js +0 -167
- package/lib/esm/web/index.js +0 -20
- package/lib/types/common/ant-versions.d.ts +0 -39
- package/lib/types/common/arweave.d.ts +0 -17
- package/lib/types/common/contracts/ao-process.d.ts +0 -47
- package/lib/types/common/hyperbeam/hb.d.ts +0 -88
- package/lib/types/common/marketplace.d.ts +0 -568
- package/lib/types/common/turbo.d.ts +0 -61
- package/lib/types/node/index.d.ts +0 -20
- package/lib/types/utils/ao.d.ts +0 -80
- package/lib/types/utils/arweave.d.ts +0 -79
- package/lib/types/utils/processes.d.ts +0 -39
- package/lib/types/web/index.d.ts +0 -20
package/lib/cjs/cli/utils.js
DELETED
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.antRegistryIdFromOptions = antRegistryIdFromOptions;
|
|
13
|
-
exports.requiredJwkFromOptions = requiredJwkFromOptions;
|
|
14
|
-
exports.jwkToAddress = jwkToAddress;
|
|
15
|
-
exports.getLoggerFromOptions = getLoggerFromOptions;
|
|
16
|
-
exports.readARIOFromOptions = readARIOFromOptions;
|
|
17
|
-
exports.readANTRegistryFromOptions = readANTRegistryFromOptions;
|
|
18
|
-
exports.contractSignerFromOptions = contractSignerFromOptions;
|
|
19
|
-
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
20
|
-
exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
|
|
21
|
-
exports.writeARIOFromOptions = writeARIOFromOptions;
|
|
22
|
-
exports.formatARIOWithCommas = formatARIOWithCommas;
|
|
23
|
-
exports.formatMARIOToARIOWithCommas = formatMARIOToARIOWithCommas;
|
|
24
|
-
exports.addressFromOptions = addressFromOptions;
|
|
25
|
-
exports.requiredAddressFromOptions = requiredAddressFromOptions;
|
|
26
|
-
exports.paginationParamsFromOptions = paginationParamsFromOptions;
|
|
27
|
-
exports.epochInputFromOptions = epochInputFromOptions;
|
|
28
|
-
exports.requiredInitiatorFromOptions = requiredInitiatorFromOptions;
|
|
29
|
-
exports.customTagsFromOptions = customTagsFromOptions;
|
|
30
|
-
exports.servicesFromOptions = servicesFromOptions;
|
|
31
|
-
exports.gatewaySettingsFromOptions = gatewaySettingsFromOptions;
|
|
32
|
-
exports.requiredTargetAndQuantityFromOptions = requiredTargetAndQuantityFromOptions;
|
|
33
|
-
exports.redelegateParamsFromOptions = redelegateParamsFromOptions;
|
|
34
|
-
exports.recordTypeFromOptions = recordTypeFromOptions;
|
|
35
|
-
exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
|
|
36
|
-
exports.assertEnoughBalanceForArNSPurchase = assertEnoughBalanceForArNSPurchase;
|
|
37
|
-
exports.assertEnoughMARIOBalance = assertEnoughMARIOBalance;
|
|
38
|
-
exports.confirmationPrompt = confirmationPrompt;
|
|
39
|
-
exports.assertConfirmationPrompt = assertConfirmationPrompt;
|
|
40
|
-
exports.requiredProcessIdFromOptions = requiredProcessIdFromOptions;
|
|
41
|
-
exports.readANTFromOptions = readANTFromOptions;
|
|
42
|
-
exports.writeANTFromOptions = writeANTFromOptions;
|
|
43
|
-
exports.booleanFromOptions = booleanFromOptions;
|
|
44
|
-
exports.requiredStringFromOptions = requiredStringFromOptions;
|
|
45
|
-
exports.stringArrayFromOptions = stringArrayFromOptions;
|
|
46
|
-
exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
|
|
47
|
-
exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
|
|
48
|
-
exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
|
|
49
|
-
exports.getANTStateFromOptions = getANTStateFromOptions;
|
|
50
|
-
exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
|
|
51
|
-
exports.fundFromFromOptions = fundFromFromOptions;
|
|
52
|
-
exports.referrerFromOptions = referrerFromOptions;
|
|
53
|
-
exports.assertLockLengthInRange = assertLockLengthInRange;
|
|
54
|
-
exports.antRecordMetadataFromOptions = antRecordMetadataFromOptions;
|
|
55
|
-
/**
|
|
56
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
57
|
-
*
|
|
58
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
59
|
-
* you may not use this file except in compliance with the License.
|
|
60
|
-
* You may obtain a copy of the License at
|
|
61
|
-
*
|
|
62
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
63
|
-
*
|
|
64
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
65
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
66
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
67
|
-
* See the License for the specific language governing permissions and
|
|
68
|
-
* limitations under the License.
|
|
69
|
-
*/
|
|
70
|
-
const fs_1 = require("fs");
|
|
71
|
-
/**
|
|
72
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
73
|
-
*
|
|
74
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
75
|
-
* you may not use this file except in compliance with the License.
|
|
76
|
-
* You may obtain a copy of the License at
|
|
77
|
-
*
|
|
78
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
79
|
-
*
|
|
80
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
81
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
82
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
83
|
-
* See the License for the specific language governing permissions and
|
|
84
|
-
* limitations under the License.
|
|
85
|
-
*/
|
|
86
|
-
const arbundles_1 = require("@dha-team/arbundles");
|
|
87
|
-
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
88
|
-
const commander_1 = require("commander");
|
|
89
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
90
|
-
const index_js_1 = require("../node/index.js");
|
|
91
|
-
const options_js_1 = require("./options.js");
|
|
92
|
-
exports.defaultTtlSecondsCLI = 3600;
|
|
93
|
-
function stringifyJsonForCLIDisplay(json) {
|
|
94
|
-
return JSON.stringify(json, null, 2);
|
|
95
|
-
}
|
|
96
|
-
function logCommandOutput(output) {
|
|
97
|
-
console.log(stringifyJsonForCLIDisplay(output));
|
|
98
|
-
}
|
|
99
|
-
function exitWithErrorLog(error, debug = false) {
|
|
100
|
-
let errorLog;
|
|
101
|
-
if (error instanceof Error) {
|
|
102
|
-
errorLog = error.message;
|
|
103
|
-
if (debug && error.stack !== undefined) {
|
|
104
|
-
errorLog = error.stack;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
errorLog = stringifyJsonForCLIDisplay(error);
|
|
109
|
-
}
|
|
110
|
-
console.error(errorLog);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
async function runCommand(command, action) {
|
|
114
|
-
const options = command.optsWithGlobals();
|
|
115
|
-
try {
|
|
116
|
-
const output = await action(options);
|
|
117
|
-
logCommandOutput(output);
|
|
118
|
-
process.exit(0);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
exitWithErrorLog(error, options.debug);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function applyOptions(command, options) {
|
|
125
|
-
[...options].forEach((option) => {
|
|
126
|
-
command.option(option.alias, option.description, option.default);
|
|
127
|
-
});
|
|
128
|
-
return command;
|
|
129
|
-
}
|
|
130
|
-
function makeCommand({ description, name, options = [], action, }) {
|
|
131
|
-
const command = commander_1.program.command(name).description(description);
|
|
132
|
-
const appliedCommand = applyOptions(command, [...options, ...options_js_1.globalOptions]);
|
|
133
|
-
if (action !== undefined) {
|
|
134
|
-
appliedCommand.action(() => runCommand(appliedCommand, action));
|
|
135
|
-
}
|
|
136
|
-
return appliedCommand;
|
|
137
|
-
}
|
|
138
|
-
function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
139
|
-
if (arioProcessId !== undefined) {
|
|
140
|
-
return arioProcessId;
|
|
141
|
-
}
|
|
142
|
-
if (devnet) {
|
|
143
|
-
return index_js_1.ARIO_DEVNET_PROCESS_ID;
|
|
144
|
-
}
|
|
145
|
-
if (testnet) {
|
|
146
|
-
return index_js_1.ARIO_TESTNET_PROCESS_ID;
|
|
147
|
-
}
|
|
148
|
-
return index_js_1.ARIO_MAINNET_PROCESS_ID;
|
|
149
|
-
}
|
|
150
|
-
function antRegistryIdFromOptions({ antRegistryProcessId, testnet, }) {
|
|
151
|
-
if (antRegistryProcessId !== undefined) {
|
|
152
|
-
return antRegistryProcessId;
|
|
153
|
-
}
|
|
154
|
-
if (testnet) {
|
|
155
|
-
return index_js_1.ANT_REGISTRY_TESTNET_ID;
|
|
156
|
-
}
|
|
157
|
-
return index_js_1.ANT_REGISTRY_ID;
|
|
158
|
-
}
|
|
159
|
-
function walletFromOptions({ privateKey, walletFile, }) {
|
|
160
|
-
if (privateKey !== undefined) {
|
|
161
|
-
return JSON.parse(privateKey);
|
|
162
|
-
}
|
|
163
|
-
if (walletFile !== undefined) {
|
|
164
|
-
return JSON.parse((0, fs_1.readFileSync)(walletFile, 'utf-8'));
|
|
165
|
-
}
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
function requiredJwkFromOptions(options) {
|
|
169
|
-
const jwk = walletFromOptions(options);
|
|
170
|
-
if (jwk === undefined) {
|
|
171
|
-
throw new Error('No JWK provided for signing!\nPlease provide a stringified JWK with `--private-key` or the file path of a jwk.json file with `--wallet-file`');
|
|
172
|
-
}
|
|
173
|
-
return jwk;
|
|
174
|
-
}
|
|
175
|
-
function jwkToAddress(jwk) {
|
|
176
|
-
return (0, index_js_1.sha256B64Url)((0, index_js_1.fromB64Url)(jwk.n));
|
|
177
|
-
}
|
|
178
|
-
function setLoggerIfDebug(options) {
|
|
179
|
-
if (options.debug) {
|
|
180
|
-
index_js_1.Logger.default.setLogLevel('debug');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function getLoggerFromOptions(options) {
|
|
184
|
-
setLoggerIfDebug(options);
|
|
185
|
-
return index_js_1.Logger.default;
|
|
186
|
-
}
|
|
187
|
-
function aoProcessFromOptions(options) {
|
|
188
|
-
return new index_js_1.AOProcess({
|
|
189
|
-
processId: arioProcessIdFromOptions(options),
|
|
190
|
-
ao: (0, aoconnect_1.connect)({
|
|
191
|
-
MODE: 'legacy',
|
|
192
|
-
CU_URL: options.cuUrl,
|
|
193
|
-
}),
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function readARIOFromOptions(options) {
|
|
197
|
-
setLoggerIfDebug(options);
|
|
198
|
-
return index_js_1.ARIO.init({
|
|
199
|
-
hyperbeamUrl: options.hyperbeamUrl,
|
|
200
|
-
process: aoProcessFromOptions({
|
|
201
|
-
cuUrl: index_js_1.DEFAULT_CU_URL,
|
|
202
|
-
...options,
|
|
203
|
-
}),
|
|
204
|
-
paymentUrl: options.paymentUrl,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
function readANTRegistryFromOptions(options) {
|
|
208
|
-
return index_js_1.ANTRegistry.init({
|
|
209
|
-
process: aoProcessFromOptions(options),
|
|
210
|
-
hyperbeamUrl: options.hyperbeamUrl,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
function contractSignerFromOptions(options) {
|
|
214
|
-
const wallet = walletFromOptions(options);
|
|
215
|
-
if (wallet === undefined) {
|
|
216
|
-
return undefined;
|
|
217
|
-
}
|
|
218
|
-
const token = options.token ?? 'arweave';
|
|
219
|
-
if (token === 'ethereum') {
|
|
220
|
-
const signer = new arbundles_1.EthereumSigner(wallet);
|
|
221
|
-
// For EthereumSigner, we need to convert the JWK to a string
|
|
222
|
-
return { signer, signerAddress: signer.publicKey.toString('hex') };
|
|
223
|
-
}
|
|
224
|
-
// TODO: Support other wallet types
|
|
225
|
-
const signer = new index_js_1.ArweaveSigner(wallet);
|
|
226
|
-
return { signer, signerAddress: jwkToAddress(wallet) };
|
|
227
|
-
}
|
|
228
|
-
function requiredContractSignerFromOptions(options) {
|
|
229
|
-
const contractSigner = contractSignerFromOptions(options);
|
|
230
|
-
if (contractSigner === undefined) {
|
|
231
|
-
throw new Error('No signer provided for signing!\nPlease provide a stringified JWK or Ethereum private key with `--private-key` or the file path of an arweave.jwk.json or eth.private.key.txt file with `--wallet-file`');
|
|
232
|
-
}
|
|
233
|
-
return contractSigner;
|
|
234
|
-
}
|
|
235
|
-
function requiredAoSignerFromOptions(options) {
|
|
236
|
-
return (0, index_js_1.createAoSigner)(requiredContractSignerFromOptions(options).signer);
|
|
237
|
-
}
|
|
238
|
-
function writeARIOFromOptions(options) {
|
|
239
|
-
const { signer, signerAddress } = requiredContractSignerFromOptions(options);
|
|
240
|
-
setLoggerIfDebug(options);
|
|
241
|
-
return {
|
|
242
|
-
ario: index_js_1.ARIO.init({
|
|
243
|
-
process: aoProcessFromOptions(options),
|
|
244
|
-
signer,
|
|
245
|
-
paymentUrl: options.paymentUrl,
|
|
246
|
-
hyperbeamUrl: options.hyperbeamUrl,
|
|
247
|
-
}),
|
|
248
|
-
signerAddress,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
function formatARIOWithCommas(value) {
|
|
252
|
-
const [integerPart, decimalPart] = value.toString().split('.');
|
|
253
|
-
const integerWithCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
254
|
-
if (decimalPart === undefined) {
|
|
255
|
-
return integerWithCommas;
|
|
256
|
-
}
|
|
257
|
-
return integerWithCommas + '.' + decimalPart;
|
|
258
|
-
}
|
|
259
|
-
function formatMARIOToARIOWithCommas(value) {
|
|
260
|
-
return formatARIOWithCommas(value.toARIO());
|
|
261
|
-
}
|
|
262
|
-
/** helper to get address from --address option first, then check wallet options */
|
|
263
|
-
function addressFromOptions(options) {
|
|
264
|
-
if (options.address !== undefined) {
|
|
265
|
-
return options.address;
|
|
266
|
-
}
|
|
267
|
-
const signer = contractSignerFromOptions(options);
|
|
268
|
-
if (signer !== undefined) {
|
|
269
|
-
return signer.signerAddress;
|
|
270
|
-
}
|
|
271
|
-
return undefined;
|
|
272
|
-
}
|
|
273
|
-
function requiredAddressFromOptions(options) {
|
|
274
|
-
const address = addressFromOptions(options);
|
|
275
|
-
if (address !== undefined) {
|
|
276
|
-
return address;
|
|
277
|
-
}
|
|
278
|
-
throw new Error('No address provided. Use --address or --wallet-file');
|
|
279
|
-
}
|
|
280
|
-
const defaultCliPaginationLimit = 10; // more friendly UX than 100
|
|
281
|
-
function paginationParamsFromOptions(options) {
|
|
282
|
-
const { cursor, limit, sortBy, sortOrder, filters } = options;
|
|
283
|
-
if (sortOrder !== undefined && !['asc', 'desc'].includes(sortOrder)) {
|
|
284
|
-
throw new Error(`Invalid sort order: ${sortOrder}, must be "asc" or "desc"`);
|
|
285
|
-
}
|
|
286
|
-
const numberLimit = limit !== undefined ? +limit : defaultCliPaginationLimit;
|
|
287
|
-
if (isNaN(numberLimit) || numberLimit <= 0) {
|
|
288
|
-
throw new Error(`Invalid limit: ${numberLimit}, must be a positive number`);
|
|
289
|
-
}
|
|
290
|
-
const filtersObject = {};
|
|
291
|
-
if (filters !== undefined) {
|
|
292
|
-
if (typeof filters !== 'object') {
|
|
293
|
-
throw new Error('Filters must be an object');
|
|
294
|
-
}
|
|
295
|
-
if (Array.isArray(filters)) {
|
|
296
|
-
// every odd value is a key, every even value is a value for that key
|
|
297
|
-
for (let i = 0; i < filters.length; i += 2) {
|
|
298
|
-
// convert any strings that are numbers to numbers and any 'true'/'false' to booleans
|
|
299
|
-
const value = filters[i + 1].split(',').map((v) => {
|
|
300
|
-
const num = +v;
|
|
301
|
-
if (!isNaN(num))
|
|
302
|
-
return num;
|
|
303
|
-
if (v === 'true')
|
|
304
|
-
return true;
|
|
305
|
-
if (v === 'false')
|
|
306
|
-
return false;
|
|
307
|
-
return v;
|
|
308
|
-
});
|
|
309
|
-
filtersObject[filters[i]] = value;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
cursor,
|
|
315
|
-
limit: numberLimit,
|
|
316
|
-
sortBy: sortBy,
|
|
317
|
-
sortOrder,
|
|
318
|
-
filters: filtersObject,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function epochInputFromOptions(options) {
|
|
322
|
-
if (options.epochIndex !== undefined) {
|
|
323
|
-
return { epochIndex: +options.epochIndex };
|
|
324
|
-
}
|
|
325
|
-
if (options.timestamp !== undefined) {
|
|
326
|
-
return { timestamp: +options.timestamp };
|
|
327
|
-
}
|
|
328
|
-
return undefined;
|
|
329
|
-
}
|
|
330
|
-
function requiredInitiatorFromOptions(options) {
|
|
331
|
-
if (options.initiator !== undefined) {
|
|
332
|
-
return options.initiator;
|
|
333
|
-
}
|
|
334
|
-
return requiredAddressFromOptions(options);
|
|
335
|
-
}
|
|
336
|
-
function customTagsFromOptions(options) {
|
|
337
|
-
if (options.tags === undefined) {
|
|
338
|
-
return {};
|
|
339
|
-
}
|
|
340
|
-
if (!Array.isArray(options.tags)) {
|
|
341
|
-
throw new Error('Tags must be an array');
|
|
342
|
-
}
|
|
343
|
-
if (options.tags.length === 0) {
|
|
344
|
-
return {};
|
|
345
|
-
}
|
|
346
|
-
if (options.tags.length % 2 !== 0) {
|
|
347
|
-
throw new Error('Tags must be an array of key-value pairs');
|
|
348
|
-
}
|
|
349
|
-
const tags = [];
|
|
350
|
-
for (let i = 0; i < options.tags.length; i += 2) {
|
|
351
|
-
tags.push({
|
|
352
|
-
name: options.tags[i],
|
|
353
|
-
value: options.tags[i + 1],
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
return {
|
|
357
|
-
tags,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
function servicesFromOptions(services) {
|
|
361
|
-
if (services === undefined || services === null || services === '') {
|
|
362
|
-
return undefined;
|
|
363
|
-
}
|
|
364
|
-
try {
|
|
365
|
-
const parsed = JSON.parse(services);
|
|
366
|
-
// Validate structure
|
|
367
|
-
if (!parsed.bundlers || !Array.isArray(parsed.bundlers)) {
|
|
368
|
-
throw new Error('Services must have a "bundlers" array');
|
|
369
|
-
}
|
|
370
|
-
if (parsed.bundlers.length > 20) {
|
|
371
|
-
throw new Error('Maximum 20 bundlers allowed');
|
|
372
|
-
}
|
|
373
|
-
// Validate each bundler
|
|
374
|
-
for (const bundler of parsed.bundlers) {
|
|
375
|
-
if (!bundler.fqdn || typeof bundler.fqdn !== 'string') {
|
|
376
|
-
throw new Error('Each bundler must have a valid "fqdn" string');
|
|
377
|
-
}
|
|
378
|
-
if (typeof bundler.port !== 'number' ||
|
|
379
|
-
bundler.port < 0 ||
|
|
380
|
-
bundler.port > 65535) {
|
|
381
|
-
throw new Error('Each bundler must have a valid "port" (0-65535)');
|
|
382
|
-
}
|
|
383
|
-
if (bundler.protocol !== 'https') {
|
|
384
|
-
throw new Error('Each bundler protocol must be "https"');
|
|
385
|
-
}
|
|
386
|
-
if (!bundler.path || typeof bundler.path !== 'string') {
|
|
387
|
-
throw new Error('Each bundler must have a valid "path" string');
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return parsed;
|
|
391
|
-
}
|
|
392
|
-
catch (error) {
|
|
393
|
-
throw new Error(`Invalid services JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function gatewaySettingsFromOptions(options) {
|
|
397
|
-
const { allowDelegatedStaking, autoStake, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, observerAddress, port, properties, allowedDelegates, services, } = options;
|
|
398
|
-
return {
|
|
399
|
-
observerAddress,
|
|
400
|
-
allowDelegatedStaking,
|
|
401
|
-
autoStake,
|
|
402
|
-
delegateRewardShareRatio: delegateRewardShareRatio !== undefined
|
|
403
|
-
? +delegateRewardShareRatio
|
|
404
|
-
: undefined,
|
|
405
|
-
allowedDelegates,
|
|
406
|
-
fqdn,
|
|
407
|
-
label,
|
|
408
|
-
minDelegatedStake: minDelegatedStake !== undefined ? +minDelegatedStake : undefined,
|
|
409
|
-
note,
|
|
410
|
-
port: port !== undefined ? +port : undefined,
|
|
411
|
-
properties,
|
|
412
|
-
services: servicesFromOptions(services),
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
function requiredTargetAndQuantityFromOptions(options) {
|
|
416
|
-
if (options.target === undefined) {
|
|
417
|
-
throw new Error('No target provided. Use --target');
|
|
418
|
-
}
|
|
419
|
-
if (options.quantity === undefined) {
|
|
420
|
-
throw new Error('No quantity provided. Use --quantity');
|
|
421
|
-
}
|
|
422
|
-
return {
|
|
423
|
-
target: options.target,
|
|
424
|
-
arioQuantity: new index_js_1.ARIOToken(+options.quantity),
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
function redelegateParamsFromOptions(options) {
|
|
428
|
-
const { target, arioQuantity: aRIOQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
429
|
-
const source = options.source;
|
|
430
|
-
if (source === undefined) {
|
|
431
|
-
throw new Error('No source provided. Use --source');
|
|
432
|
-
}
|
|
433
|
-
return {
|
|
434
|
-
target,
|
|
435
|
-
source,
|
|
436
|
-
vaultId: options.vaultId,
|
|
437
|
-
stakeQty: aRIOQuantity.toMARIO(),
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
function recordTypeFromOptions(options) {
|
|
441
|
-
options.type ??= 'lease';
|
|
442
|
-
if (options.type !== 'lease' && options.type !== 'permabuy') {
|
|
443
|
-
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
444
|
-
}
|
|
445
|
-
return options.type;
|
|
446
|
-
}
|
|
447
|
-
function requiredMARIOFromOptions(options, key) {
|
|
448
|
-
if (options[key] === undefined) {
|
|
449
|
-
throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
|
|
450
|
-
}
|
|
451
|
-
return new index_js_1.ARIOToken(+options[key]).toMARIO();
|
|
452
|
-
}
|
|
453
|
-
async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
454
|
-
if (costDetailsParams.fundFrom === 'turbo') {
|
|
455
|
-
// TODO: Get turbo balance and assert it is enough -- retain paid-by from balance result and pass to CLI logic
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
const costDetails = await ario.getCostDetails(costDetailsParams);
|
|
459
|
-
if (costDetails.fundingPlan) {
|
|
460
|
-
if (costDetails.fundingPlan.shortfall > 0) {
|
|
461
|
-
throw new Error(`Insufficient balance for action. Shortfall: ${formatMARIOToARIOWithCommas(new index_js_1.mARIOToken(costDetails.fundingPlan.shortfall))}\n${JSON.stringify(costDetails, null, 2)}`);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
await assertEnoughMARIOBalance({
|
|
466
|
-
ario,
|
|
467
|
-
address,
|
|
468
|
-
mARIOQuantity: costDetails.tokenCost,
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
async function assertEnoughMARIOBalance({ address, ario, mARIOQuantity, }) {
|
|
473
|
-
if (typeof mARIOQuantity === 'number') {
|
|
474
|
-
mARIOQuantity = new index_js_1.mARIOToken(mARIOQuantity);
|
|
475
|
-
}
|
|
476
|
-
const balance = await ario.getBalance({ address });
|
|
477
|
-
if (balance < mARIOQuantity.valueOf()) {
|
|
478
|
-
throw new Error(`Insufficient ARIO balance for action. Balance available: ${formatMARIOToARIOWithCommas(new index_js_1.mARIOToken(balance))} ARIO`);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
async function confirmationPrompt(message) {
|
|
482
|
-
const { confirm } = await (0, prompts_1.default)({
|
|
483
|
-
type: 'confirm',
|
|
484
|
-
name: 'confirm',
|
|
485
|
-
message,
|
|
486
|
-
});
|
|
487
|
-
return confirm;
|
|
488
|
-
}
|
|
489
|
-
async function assertConfirmationPrompt(message, options) {
|
|
490
|
-
if (options.skipConfirmation) {
|
|
491
|
-
return true;
|
|
492
|
-
}
|
|
493
|
-
return confirmationPrompt(message);
|
|
494
|
-
}
|
|
495
|
-
function requiredProcessIdFromOptions(o) {
|
|
496
|
-
if (o.processId === undefined) {
|
|
497
|
-
throw new Error('--process-id is required');
|
|
498
|
-
}
|
|
499
|
-
return o.processId;
|
|
500
|
-
}
|
|
501
|
-
function ANTProcessFromOptions(options) {
|
|
502
|
-
return new index_js_1.AOProcess({
|
|
503
|
-
processId: requiredProcessIdFromOptions(options),
|
|
504
|
-
ao: (0, aoconnect_1.connect)({
|
|
505
|
-
MODE: 'legacy',
|
|
506
|
-
CU_URL: options.cuUrl,
|
|
507
|
-
}),
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
function readANTFromOptions(options) {
|
|
511
|
-
return index_js_1.ANT.init({
|
|
512
|
-
process: ANTProcessFromOptions(options),
|
|
513
|
-
hyperbeamUrl: options.hyperbeamUrl,
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
function writeANTFromOptions(options, signer) {
|
|
517
|
-
signer ??= requiredContractSignerFromOptions(options).signer;
|
|
518
|
-
return index_js_1.ANT.init({
|
|
519
|
-
process: ANTProcessFromOptions(options),
|
|
520
|
-
signer,
|
|
521
|
-
hyperbeamUrl: options.hyperbeamUrl,
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
function booleanFromOptions(options, key) {
|
|
525
|
-
return !!options[key];
|
|
526
|
-
}
|
|
527
|
-
function requiredStringFromOptions(options, key) {
|
|
528
|
-
const value = options[key];
|
|
529
|
-
if (value === undefined) {
|
|
530
|
-
throw new Error(`--${key} is required`);
|
|
531
|
-
}
|
|
532
|
-
return value;
|
|
533
|
-
}
|
|
534
|
-
function stringArrayFromOptions(options, key) {
|
|
535
|
-
const value = options[key];
|
|
536
|
-
if (value === undefined) {
|
|
537
|
-
return undefined;
|
|
538
|
-
}
|
|
539
|
-
if (!Array.isArray(value)) {
|
|
540
|
-
throw new Error(`--${key} must be an array`);
|
|
541
|
-
}
|
|
542
|
-
return value;
|
|
543
|
-
}
|
|
544
|
-
function requiredStringArrayFromOptions(options, key) {
|
|
545
|
-
const value = stringArrayFromOptions(options, key);
|
|
546
|
-
if (value === undefined) {
|
|
547
|
-
throw new Error(`--${key} is required`);
|
|
548
|
-
}
|
|
549
|
-
return value;
|
|
550
|
-
}
|
|
551
|
-
function positiveIntegerFromOptions(options, key) {
|
|
552
|
-
const value = options[key];
|
|
553
|
-
if (value === undefined) {
|
|
554
|
-
return undefined;
|
|
555
|
-
}
|
|
556
|
-
const numberValue = +value;
|
|
557
|
-
if (isNaN(numberValue) || numberValue <= 0) {
|
|
558
|
-
throw new Error(`Invalid ${key}: ${value}, must be a positive number`);
|
|
559
|
-
}
|
|
560
|
-
return numberValue;
|
|
561
|
-
}
|
|
562
|
-
function requiredPositiveIntegerFromOptions(options, key) {
|
|
563
|
-
const value = positiveIntegerFromOptions(options, key);
|
|
564
|
-
if (value === undefined) {
|
|
565
|
-
throw new Error(`--${key} is required`);
|
|
566
|
-
}
|
|
567
|
-
return value;
|
|
568
|
-
}
|
|
569
|
-
function getANTStateFromOptions(options) {
|
|
570
|
-
return (0, index_js_1.initANTStateForAddress)({
|
|
571
|
-
owner: requiredAddressFromOptions(options),
|
|
572
|
-
targetId: options.target,
|
|
573
|
-
controllers: options.controllers,
|
|
574
|
-
description: options.description,
|
|
575
|
-
ticker: options.ticker,
|
|
576
|
-
name: options.name,
|
|
577
|
-
keywords: options.keywords,
|
|
578
|
-
logo: options.logo,
|
|
579
|
-
ttlSeconds: options.ttlSeconds !== undefined
|
|
580
|
-
? +options.ttlSeconds
|
|
581
|
-
: exports.defaultTtlSecondsCLI,
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
function getTokenCostParamsFromOptions(o) {
|
|
585
|
-
o.intent ??= 'Buy-Name';
|
|
586
|
-
o.type ??= 'lease';
|
|
587
|
-
o.years ??= '1';
|
|
588
|
-
if (!(0, index_js_1.isValidIntent)(o.intent)) {
|
|
589
|
-
throw new Error(`Invalid intent. Valid intents are: ${index_js_1.validIntents.join(', ')}`);
|
|
590
|
-
}
|
|
591
|
-
if (o.type !== 'lease' && o.type !== 'permabuy') {
|
|
592
|
-
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
type: o.type,
|
|
596
|
-
quantity: o.quantity !== undefined ? +o.quantity : undefined,
|
|
597
|
-
years: +o.years,
|
|
598
|
-
intent: o.intent,
|
|
599
|
-
name: requiredStringFromOptions(o, 'name'),
|
|
600
|
-
fromAddress: addressFromOptions(o),
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
function fundFromFromOptions(o) {
|
|
604
|
-
if (o.fundFrom !== undefined) {
|
|
605
|
-
if (!(0, index_js_1.isValidFundFrom)(o.fundFrom)) {
|
|
606
|
-
throw new Error(`Invalid fund from: ${o.fundFrom}. Please use one of ${index_js_1.fundFromOptions.join(', ')}`);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
return o.fundFrom ?? 'balance';
|
|
610
|
-
}
|
|
611
|
-
function referrerFromOptions(o) {
|
|
612
|
-
return o.referrer;
|
|
613
|
-
}
|
|
614
|
-
function assertLockLengthInRange(lockLengthMs, assertMin = true) {
|
|
615
|
-
const minLockLengthMs = 1209600000; // 14 days
|
|
616
|
-
const maxLockLengthMs = 378432000000; // ~12 years
|
|
617
|
-
if (lockLengthMs > maxLockLengthMs) {
|
|
618
|
-
throw new Error(`Lock length must be at most 12 years (378432000000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
619
|
-
}
|
|
620
|
-
if (!assertMin) {
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
if (lockLengthMs < minLockLengthMs) {
|
|
624
|
-
throw new Error(`Lock length must be at least 14 days (1209600000 ms). Provided lock length: ${lockLengthMs} ms`);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function antRecordMetadataFromOptions(options) {
|
|
628
|
-
return {
|
|
629
|
-
...(options.owner != null &&
|
|
630
|
-
options.owner !== '' && { owner: options.owner }),
|
|
631
|
-
...(options.displayName != null &&
|
|
632
|
-
options.displayName !== '' && { displayName: options.displayName }),
|
|
633
|
-
...(options.logo != null && options.logo !== '' && { logo: options.logo }),
|
|
634
|
-
...(options.description != null &&
|
|
635
|
-
options.description !== '' && { description: options.description }),
|
|
636
|
-
...(options.keywords != null &&
|
|
637
|
-
options.keywords.length > 0 && { keywords: options.keywords }),
|
|
638
|
-
};
|
|
639
|
-
}
|