@ar.io/sdk 2.6.0 → 2.7.0-alpha.2
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 +65 -65
- package/lib/cjs/cli/cli.js +712 -0
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +211 -0
- package/lib/cjs/cli/commands/readCommands.js +219 -0
- package/lib/cjs/cli/commands/transfer.js +26 -0
- package/lib/cjs/cli/options.js +336 -0
- package/lib/cjs/cli/types.js +2 -0
- package/lib/cjs/cli/utils.js +406 -0
- package/lib/cjs/common/io.js +2 -7
- package/lib/cjs/types/io.js +13 -1
- package/lib/cjs/utils/ao.js +32 -13
- package/lib/cjs/utils/base64.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/cli.js +710 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +194 -0
- package/lib/esm/cli/commands/readCommands.js +197 -0
- package/lib/esm/cli/commands/transfer.js +22 -0
- package/lib/esm/cli/options.js +333 -0
- package/lib/esm/cli/types.js +1 -0
- package/lib/esm/cli/utils.js +366 -0
- package/lib/esm/common/io.js +2 -7
- package/lib/esm/types/io.js +11 -0
- package/lib/esm/utils/ao.js +30 -12
- package/lib/esm/utils/base64.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/cli.d.ts +2 -0
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +38 -0
- package/lib/types/cli/commands/readCommands.d.ts +57 -0
- package/lib/types/cli/commands/transfer.d.ts +23 -0
- package/lib/types/cli/options.d.ts +326 -0
- package/lib/types/cli/types.d.ts +106 -0
- package/lib/types/cli/utils.d.ts +66 -0
- package/lib/types/common/io.d.ts +4 -7
- package/lib/types/types/io.d.ts +81 -60
- package/lib/types/utils/ao.d.ts +20 -10
- package/lib/types/version.d.ts +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,406 @@
|
|
|
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.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughBalance = exports.requiredMIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.writeActionTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatIOWithCommas = exports.writeIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.readIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.ioProcessIdFromOptions = exports.makeCommand = exports.runCommand = exports.stringifyJsonForCLIDisplay = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
23
|
+
const commander_1 = require("commander");
|
|
24
|
+
const fs_1 = require("fs");
|
|
25
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
26
|
+
const index_js_1 = require("../node/index.js");
|
|
27
|
+
const options_js_1 = require("./options.js");
|
|
28
|
+
function stringifyJsonForCLIDisplay(json) {
|
|
29
|
+
return JSON.stringify(json, null, 2);
|
|
30
|
+
}
|
|
31
|
+
exports.stringifyJsonForCLIDisplay = stringifyJsonForCLIDisplay;
|
|
32
|
+
function logCommandOutput(output) {
|
|
33
|
+
console.log(stringifyJsonForCLIDisplay(output));
|
|
34
|
+
}
|
|
35
|
+
function exitWithErrorLog(error, debug = false) {
|
|
36
|
+
let errorLog;
|
|
37
|
+
if (error instanceof Error) {
|
|
38
|
+
errorLog = error.message;
|
|
39
|
+
if (debug && error.stack !== undefined) {
|
|
40
|
+
errorLog = error.stack;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
errorLog = stringifyJsonForCLIDisplay(error);
|
|
45
|
+
}
|
|
46
|
+
console.error(errorLog);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
async function runCommand(command, action) {
|
|
50
|
+
const options = command.optsWithGlobals();
|
|
51
|
+
try {
|
|
52
|
+
const output = await action(options);
|
|
53
|
+
logCommandOutput(output);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
exitWithErrorLog(error, options.debug);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.runCommand = runCommand;
|
|
61
|
+
function applyOptions(command, options) {
|
|
62
|
+
[...options].forEach((option) => {
|
|
63
|
+
command.option(option.alias, option.description, option.default);
|
|
64
|
+
});
|
|
65
|
+
return command;
|
|
66
|
+
}
|
|
67
|
+
function makeCommand({ description, name, options = [], action, }) {
|
|
68
|
+
const command = commander_1.program.command(name).description(description);
|
|
69
|
+
const appliedCommand = applyOptions(command, [...options, ...options_js_1.globalOptions]);
|
|
70
|
+
if (action !== undefined) {
|
|
71
|
+
appliedCommand.action(() => runCommand(appliedCommand, action));
|
|
72
|
+
}
|
|
73
|
+
return appliedCommand;
|
|
74
|
+
}
|
|
75
|
+
exports.makeCommand = makeCommand;
|
|
76
|
+
function ioProcessIdFromOptions({ ioProcessId, dev, }) {
|
|
77
|
+
return ioProcessId !== undefined
|
|
78
|
+
? ioProcessId
|
|
79
|
+
: dev
|
|
80
|
+
? index_js_1.IO_DEVNET_PROCESS_ID
|
|
81
|
+
: index_js_1.IO_TESTNET_PROCESS_ID;
|
|
82
|
+
}
|
|
83
|
+
exports.ioProcessIdFromOptions = ioProcessIdFromOptions;
|
|
84
|
+
function jwkFromOptions({ privateKey, walletFile, }) {
|
|
85
|
+
if (privateKey !== undefined) {
|
|
86
|
+
return JSON.parse(privateKey);
|
|
87
|
+
}
|
|
88
|
+
if (walletFile !== undefined) {
|
|
89
|
+
return JSON.parse((0, fs_1.readFileSync)(walletFile, 'utf-8'));
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
function requiredJwkFromOptions(options) {
|
|
94
|
+
const jwk = jwkFromOptions(options);
|
|
95
|
+
if (jwk === undefined) {
|
|
96
|
+
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`');
|
|
97
|
+
}
|
|
98
|
+
return jwk;
|
|
99
|
+
}
|
|
100
|
+
exports.requiredJwkFromOptions = requiredJwkFromOptions;
|
|
101
|
+
function jwkToAddress(jwk) {
|
|
102
|
+
return (0, index_js_1.sha256B64Url)((0, index_js_1.fromB64Url)(jwk.n));
|
|
103
|
+
}
|
|
104
|
+
exports.jwkToAddress = jwkToAddress;
|
|
105
|
+
function setLoggerIfDebug(options) {
|
|
106
|
+
if (options.debug) {
|
|
107
|
+
index_js_1.Logger.default.setLogLevel('debug');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function getLoggerFromOptions(options) {
|
|
111
|
+
setLoggerIfDebug(options);
|
|
112
|
+
return index_js_1.Logger.default;
|
|
113
|
+
}
|
|
114
|
+
exports.getLoggerFromOptions = getLoggerFromOptions;
|
|
115
|
+
function aoProcessFromOptions(options) {
|
|
116
|
+
return new index_js_1.AOProcess({
|
|
117
|
+
processId: ioProcessIdFromOptions(options),
|
|
118
|
+
ao: (0, aoconnect_1.connect)({
|
|
119
|
+
CU_URL: options.cuUrl,
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function readIOFromOptions(options) {
|
|
124
|
+
setLoggerIfDebug(options);
|
|
125
|
+
return index_js_1.IO.init({
|
|
126
|
+
process: aoProcessFromOptions(options),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
exports.readIOFromOptions = readIOFromOptions;
|
|
130
|
+
function requiredContractSignerFromOptions(options) {
|
|
131
|
+
// TODO: Support other wallet types
|
|
132
|
+
const jwk = requiredJwkFromOptions(options);
|
|
133
|
+
const signer = new index_js_1.ArweaveSigner(jwk);
|
|
134
|
+
return { signer, signerAddress: jwkToAddress(jwk) };
|
|
135
|
+
}
|
|
136
|
+
exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
|
|
137
|
+
function requiredAoSignerFromOptions(options) {
|
|
138
|
+
return (0, index_js_1.createAoSigner)(requiredContractSignerFromOptions(options).signer);
|
|
139
|
+
}
|
|
140
|
+
exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
|
|
141
|
+
function writeIOFromOptions(options) {
|
|
142
|
+
const { signer, signerAddress } = requiredContractSignerFromOptions(options);
|
|
143
|
+
setLoggerIfDebug(options);
|
|
144
|
+
return {
|
|
145
|
+
io: index_js_1.IO.init({
|
|
146
|
+
process: aoProcessFromOptions(options),
|
|
147
|
+
signer,
|
|
148
|
+
}),
|
|
149
|
+
signerAddress,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
exports.writeIOFromOptions = writeIOFromOptions;
|
|
153
|
+
function formatIOWithCommas(value) {
|
|
154
|
+
const [integerPart, decimalPart] = value.toString().split('.');
|
|
155
|
+
const integerWithCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
156
|
+
if (decimalPart === undefined) {
|
|
157
|
+
return integerWithCommas;
|
|
158
|
+
}
|
|
159
|
+
return integerWithCommas + '.' + decimalPart;
|
|
160
|
+
}
|
|
161
|
+
exports.formatIOWithCommas = formatIOWithCommas;
|
|
162
|
+
/** helper to get address from --address option first, then check wallet options */
|
|
163
|
+
function addressFromOptions(options) {
|
|
164
|
+
if (options.address !== undefined) {
|
|
165
|
+
return options.address;
|
|
166
|
+
}
|
|
167
|
+
// TODO: Support other wallet types
|
|
168
|
+
const jwk = jwkFromOptions(options);
|
|
169
|
+
if (jwk !== undefined) {
|
|
170
|
+
return jwkToAddress(jwk);
|
|
171
|
+
}
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
exports.addressFromOptions = addressFromOptions;
|
|
175
|
+
function requiredAddressFromOptions(options) {
|
|
176
|
+
const address = addressFromOptions(options);
|
|
177
|
+
if (address !== undefined) {
|
|
178
|
+
return address;
|
|
179
|
+
}
|
|
180
|
+
throw new Error('No address provided. Use --address or --wallet-file');
|
|
181
|
+
}
|
|
182
|
+
exports.requiredAddressFromOptions = requiredAddressFromOptions;
|
|
183
|
+
const defaultCliPaginationLimit = 10; // more friendly UX than 100
|
|
184
|
+
function paginationParamsFromOptions(options) {
|
|
185
|
+
const { cursor, limit, sortBy, sortOrder } = options;
|
|
186
|
+
if (sortOrder !== undefined && !['asc', 'desc'].includes(sortOrder)) {
|
|
187
|
+
throw new Error(`Invalid sort order: ${sortOrder}, must be "asc" or "desc"`);
|
|
188
|
+
}
|
|
189
|
+
const numberLimit = limit !== undefined ? +limit : defaultCliPaginationLimit;
|
|
190
|
+
if (isNaN(numberLimit) || numberLimit <= 0) {
|
|
191
|
+
throw new Error(`Invalid limit: ${numberLimit}, must be a positive number`);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
cursor,
|
|
195
|
+
limit: numberLimit,
|
|
196
|
+
sortBy,
|
|
197
|
+
sortOrder,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
exports.paginationParamsFromOptions = paginationParamsFromOptions;
|
|
201
|
+
function epochInputFromOptions(options) {
|
|
202
|
+
if (options.epochIndex !== undefined) {
|
|
203
|
+
return { epochIndex: +options.epochIndex };
|
|
204
|
+
}
|
|
205
|
+
if (options.timestamp !== undefined) {
|
|
206
|
+
return { timestamp: +options.timestamp };
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
exports.epochInputFromOptions = epochInputFromOptions;
|
|
211
|
+
function requiredInitiatorFromOptions(options) {
|
|
212
|
+
if (options.initiator !== undefined) {
|
|
213
|
+
return options.initiator;
|
|
214
|
+
}
|
|
215
|
+
return requiredAddressFromOptions(options);
|
|
216
|
+
}
|
|
217
|
+
exports.requiredInitiatorFromOptions = requiredInitiatorFromOptions;
|
|
218
|
+
function writeActionTagsFromOptions(options) {
|
|
219
|
+
if (options.tags === undefined) {
|
|
220
|
+
return {};
|
|
221
|
+
}
|
|
222
|
+
if (!Array.isArray(options.tags)) {
|
|
223
|
+
throw new Error('Tags must be an array');
|
|
224
|
+
}
|
|
225
|
+
if (options.tags.length === 0) {
|
|
226
|
+
return {};
|
|
227
|
+
}
|
|
228
|
+
if (options.tags.length % 2 !== 0) {
|
|
229
|
+
throw new Error('Tags must be an array of key-value pairs');
|
|
230
|
+
}
|
|
231
|
+
const tags = [];
|
|
232
|
+
for (let i = 0; i < options.tags.length; i += 2) {
|
|
233
|
+
tags.push({
|
|
234
|
+
name: options.tags[i],
|
|
235
|
+
value: options.tags[i + 1],
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
tags,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
exports.writeActionTagsFromOptions = writeActionTagsFromOptions;
|
|
243
|
+
function gatewaySettingsFromOptions({ allowDelegatedStaking, autoStake, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, observerAddress, port, properties, allowedDelegates, }) {
|
|
244
|
+
return {
|
|
245
|
+
observerAddress,
|
|
246
|
+
allowDelegatedStaking,
|
|
247
|
+
autoStake,
|
|
248
|
+
delegateRewardShareRatio: delegateRewardShareRatio !== undefined
|
|
249
|
+
? +delegateRewardShareRatio
|
|
250
|
+
: undefined,
|
|
251
|
+
allowedDelegates,
|
|
252
|
+
fqdn,
|
|
253
|
+
label,
|
|
254
|
+
minDelegatedStake: minDelegatedStake !== undefined ? +minDelegatedStake : undefined,
|
|
255
|
+
note,
|
|
256
|
+
port: port !== undefined ? +port : undefined,
|
|
257
|
+
properties,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
exports.gatewaySettingsFromOptions = gatewaySettingsFromOptions;
|
|
261
|
+
function requiredTargetAndQuantityFromOptions(options) {
|
|
262
|
+
if (options.target === undefined) {
|
|
263
|
+
throw new Error('No target provided. Use --target');
|
|
264
|
+
}
|
|
265
|
+
if (options.quantity === undefined) {
|
|
266
|
+
throw new Error('No quantity provided. Use --quantity');
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
target: options.target,
|
|
270
|
+
ioQuantity: new index_js_1.IOToken(+options.quantity),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
exports.requiredTargetAndQuantityFromOptions = requiredTargetAndQuantityFromOptions;
|
|
274
|
+
function redelegateParamsFromOptions(options) {
|
|
275
|
+
const { target, ioQuantity } = requiredTargetAndQuantityFromOptions(options);
|
|
276
|
+
const source = options.source;
|
|
277
|
+
if (source === undefined) {
|
|
278
|
+
throw new Error('No source provided. Use --source');
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
target,
|
|
282
|
+
source,
|
|
283
|
+
vaultId: options.vaultId,
|
|
284
|
+
stakeQty: ioQuantity.toMIO(),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
exports.redelegateParamsFromOptions = redelegateParamsFromOptions;
|
|
288
|
+
function recordTypeFromOptions(options) {
|
|
289
|
+
options.type ??= 'lease';
|
|
290
|
+
if (options.type !== 'lease' && options.type !== 'permabuy') {
|
|
291
|
+
throw new Error(`Invalid type. Valid types are: lease, permabuy`);
|
|
292
|
+
}
|
|
293
|
+
return options.type;
|
|
294
|
+
}
|
|
295
|
+
exports.recordTypeFromOptions = recordTypeFromOptions;
|
|
296
|
+
function requiredMIOFromOptions(options, key) {
|
|
297
|
+
if (options[key] === undefined) {
|
|
298
|
+
throw new Error(`No ${key} provided. Use --${key} denominated in IO`);
|
|
299
|
+
}
|
|
300
|
+
return new index_js_1.IOToken(+options[key]).toMIO();
|
|
301
|
+
}
|
|
302
|
+
exports.requiredMIOFromOptions = requiredMIOFromOptions;
|
|
303
|
+
async function assertEnoughBalance(io, address, ioQuantity) {
|
|
304
|
+
const balance = await io.getBalance({ address });
|
|
305
|
+
if (balance < ioQuantity.toMIO().valueOf()) {
|
|
306
|
+
throw new Error(`Insufficient IO balance for action. Balance available: ${new index_js_1.mIOToken(balance).toIO()} IO`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.assertEnoughBalance = assertEnoughBalance;
|
|
310
|
+
async function confirmationPrompt(message) {
|
|
311
|
+
const { confirm } = await (0, prompts_1.default)({
|
|
312
|
+
type: 'confirm',
|
|
313
|
+
name: 'confirm',
|
|
314
|
+
message,
|
|
315
|
+
});
|
|
316
|
+
return confirm;
|
|
317
|
+
}
|
|
318
|
+
exports.confirmationPrompt = confirmationPrompt;
|
|
319
|
+
async function assertConfirmationPrompt(message, options) {
|
|
320
|
+
if (options.skipConfirmation) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
return confirmationPrompt(message);
|
|
324
|
+
}
|
|
325
|
+
exports.assertConfirmationPrompt = assertConfirmationPrompt;
|
|
326
|
+
function requiredProcessIdFromOptions(o) {
|
|
327
|
+
if (o.processId === undefined) {
|
|
328
|
+
throw new Error('--process-id is required');
|
|
329
|
+
}
|
|
330
|
+
return o.processId;
|
|
331
|
+
}
|
|
332
|
+
exports.requiredProcessIdFromOptions = requiredProcessIdFromOptions;
|
|
333
|
+
function ANTProcessFromOptions(options) {
|
|
334
|
+
return new index_js_1.AOProcess({
|
|
335
|
+
processId: requiredProcessIdFromOptions(options),
|
|
336
|
+
ao: (0, aoconnect_1.connect)({
|
|
337
|
+
CU_URL: options.cuUrl,
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function readANTFromOptions(options) {
|
|
342
|
+
return index_js_1.ANT.init({
|
|
343
|
+
process: ANTProcessFromOptions(options),
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
exports.readANTFromOptions = readANTFromOptions;
|
|
347
|
+
function writeANTFromOptions(options, signer) {
|
|
348
|
+
signer ??= requiredContractSignerFromOptions(options).signer;
|
|
349
|
+
return index_js_1.ANT.init({
|
|
350
|
+
process: ANTProcessFromOptions(options),
|
|
351
|
+
signer,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
exports.writeANTFromOptions = writeANTFromOptions;
|
|
355
|
+
function requiredStringFromOptions(options, key) {
|
|
356
|
+
const value = options[key];
|
|
357
|
+
if (value === undefined) {
|
|
358
|
+
throw new Error(`--${key} is required`);
|
|
359
|
+
}
|
|
360
|
+
return value;
|
|
361
|
+
}
|
|
362
|
+
exports.requiredStringFromOptions = requiredStringFromOptions;
|
|
363
|
+
function requiredStringArrayFromOptions(options, key) {
|
|
364
|
+
const value = options[key];
|
|
365
|
+
if (value === undefined) {
|
|
366
|
+
throw new Error(`--${key} is required`);
|
|
367
|
+
}
|
|
368
|
+
if (!Array.isArray(value)) {
|
|
369
|
+
throw new Error(`--${key} must be an array`);
|
|
370
|
+
}
|
|
371
|
+
return value;
|
|
372
|
+
}
|
|
373
|
+
exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
|
|
374
|
+
function positiveIntegerFromOptions(options, key) {
|
|
375
|
+
const value = options[key];
|
|
376
|
+
if (value === undefined) {
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
const numberValue = +value;
|
|
380
|
+
if (isNaN(numberValue) || numberValue <= 0) {
|
|
381
|
+
throw new Error(`Invalid ${key}: ${value}, must be a positive number`);
|
|
382
|
+
}
|
|
383
|
+
return numberValue;
|
|
384
|
+
}
|
|
385
|
+
exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
|
|
386
|
+
function requiredPositiveIntegerFromOptions(options, key) {
|
|
387
|
+
const value = positiveIntegerFromOptions(options, key);
|
|
388
|
+
if (value === undefined) {
|
|
389
|
+
throw new Error(`--${key} is required`);
|
|
390
|
+
}
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
|
|
394
|
+
function getANTStateFromOptions(options) {
|
|
395
|
+
return (0, index_js_1.initANTStateForAddress)({
|
|
396
|
+
owner: requiredAddressFromOptions(options),
|
|
397
|
+
targetId: options.target,
|
|
398
|
+
controllers: options.controllers,
|
|
399
|
+
description: options.description,
|
|
400
|
+
ticker: options.ticker,
|
|
401
|
+
name: options.name,
|
|
402
|
+
keywords: options.keywords,
|
|
403
|
+
ttlSeconds: options.ttlSeconds !== undefined ? +options.ttlSeconds : 0,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
exports.getANTStateFromOptions = getANTStateFromOptions;
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -384,13 +384,7 @@ class IOReadable {
|
|
|
384
384
|
});
|
|
385
385
|
}
|
|
386
386
|
async getAllowedDelegates(params) {
|
|
387
|
-
return this.
|
|
388
|
-
tags: [
|
|
389
|
-
{ name: 'Action', value: 'Paginated-Allowed-Delegates' },
|
|
390
|
-
{ name: 'Address', value: params.address },
|
|
391
|
-
...(0, arweave_js_1.paginationParamsToTags)(params),
|
|
392
|
-
],
|
|
393
|
-
});
|
|
387
|
+
return this.getGatewayDelegateAllowList(params);
|
|
394
388
|
}
|
|
395
389
|
async getGatewayVaults(params) {
|
|
396
390
|
return this.process.read({
|
|
@@ -679,6 +673,7 @@ class IOWriteable extends IOReadable {
|
|
|
679
673
|
...tags,
|
|
680
674
|
{ name: 'Action', value: 'Decrease-Operator-Stake' },
|
|
681
675
|
{ name: 'Quantity', value: params.decreaseQty.valueOf().toString() },
|
|
676
|
+
{ name: 'Instant', value: `${params.instant || false}` },
|
|
682
677
|
],
|
|
683
678
|
});
|
|
684
679
|
}
|
package/lib/cjs/types/io.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = void 0;
|
|
3
|
+
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = exports.isValidIntent = exports.intentsUsingYears = exports.validIntents = void 0;
|
|
4
4
|
const arweave_js_1 = require("../utils/arweave.js");
|
|
5
|
+
exports.validIntents = [
|
|
6
|
+
'Buy-Record',
|
|
7
|
+
'Extend-Lease',
|
|
8
|
+
'Increase-Undername-Limit',
|
|
9
|
+
'Upgrade-Name',
|
|
10
|
+
'Primary-Name-Request',
|
|
11
|
+
];
|
|
12
|
+
exports.intentsUsingYears = ['Buy-Record', 'Extend-Lease'];
|
|
13
|
+
const isValidIntent = (intent) => {
|
|
14
|
+
return exports.validIntents.indexOf(intent) !== -1;
|
|
15
|
+
};
|
|
16
|
+
exports.isValidIntent = isValidIntent;
|
|
5
17
|
// Typeguard functions
|
|
6
18
|
function isProcessConfiguration(config) {
|
|
7
19
|
return 'process' in config;
|
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
3
|
+
exports.initANTStateForAddress = exports.defaultTargetManifestId = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
6
|
*
|
|
@@ -23,14 +23,6 @@ const arweave_js_1 = require("../common/arweave.js");
|
|
|
23
23
|
const index_js_1 = require("../common/index.js");
|
|
24
24
|
const constants_js_1 = require("../constants.js");
|
|
25
25
|
async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, logger = index_js_1.Logger.default, arweave = arweave_js_1.defaultArweave, }) {
|
|
26
|
-
const registryClient = index_js_1.ANTRegistry.init({
|
|
27
|
-
process: new index_js_1.AOProcess({
|
|
28
|
-
processId: antRegistryId,
|
|
29
|
-
ao,
|
|
30
|
-
logger,
|
|
31
|
-
}),
|
|
32
|
-
signer: signer,
|
|
33
|
-
});
|
|
34
26
|
//TODO: cache locally and only fetch if not cached
|
|
35
27
|
const luaString = (await arweave.transactions.getData(luaCodeTxId, {
|
|
36
28
|
decode: true,
|
|
@@ -65,7 +57,7 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
65
57
|
data: luaString,
|
|
66
58
|
signer,
|
|
67
59
|
});
|
|
68
|
-
logger.
|
|
60
|
+
logger.debug(`Spawned ANT`, {
|
|
69
61
|
processId,
|
|
70
62
|
module,
|
|
71
63
|
scheduler,
|
|
@@ -83,17 +75,25 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
83
75
|
data: JSON.stringify(state),
|
|
84
76
|
signer,
|
|
85
77
|
});
|
|
86
|
-
logger.
|
|
78
|
+
logger.debug(`Initialized ANT`, {
|
|
87
79
|
processId,
|
|
88
80
|
module,
|
|
89
81
|
scheduler,
|
|
90
82
|
initializeMsgId,
|
|
91
83
|
});
|
|
92
84
|
}
|
|
85
|
+
const registryClient = index_js_1.ANTRegistry.init({
|
|
86
|
+
process: new index_js_1.AOProcess({
|
|
87
|
+
processId: antRegistryId,
|
|
88
|
+
ao,
|
|
89
|
+
logger,
|
|
90
|
+
}),
|
|
91
|
+
signer: signer,
|
|
92
|
+
});
|
|
93
93
|
const { id: antRegistrationMsgId } = await registryClient.register({
|
|
94
94
|
processId,
|
|
95
95
|
});
|
|
96
|
-
logger.
|
|
96
|
+
logger.debug(`Registered ANT to ANT Registry`, {
|
|
97
97
|
processId,
|
|
98
98
|
module,
|
|
99
99
|
scheduler,
|
|
@@ -123,7 +123,7 @@ async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_L
|
|
|
123
123
|
data: luaString,
|
|
124
124
|
signer,
|
|
125
125
|
});
|
|
126
|
-
logger.
|
|
126
|
+
logger.debug(`Evolved ANT`, {
|
|
127
127
|
processId,
|
|
128
128
|
luaCodeTxId,
|
|
129
129
|
evalMsgId: evolveMsgId,
|
|
@@ -181,3 +181,22 @@ function createAoSigner(signer) {
|
|
|
181
181
|
return aoSigner;
|
|
182
182
|
}
|
|
183
183
|
exports.createAoSigner = createAoSigner;
|
|
184
|
+
exports.defaultTargetManifestId = '-k7t8xMoB8hW482609Z9F4bTFMC3MnuW8bTvTyT8pFI';
|
|
185
|
+
function initANTStateForAddress({ owner, targetId, ttlSeconds = 3600, keywords = [], controllers = [], description = '', ticker = 'aos', name = 'ANT', }) {
|
|
186
|
+
return {
|
|
187
|
+
ticker,
|
|
188
|
+
name,
|
|
189
|
+
description,
|
|
190
|
+
keywords,
|
|
191
|
+
owner,
|
|
192
|
+
controllers: [owner, ...controllers],
|
|
193
|
+
balances: { [owner]: 1 },
|
|
194
|
+
records: {
|
|
195
|
+
['@']: {
|
|
196
|
+
transactionId: targetId ?? exports.defaultTargetManifestId.toString(),
|
|
197
|
+
ttlSeconds,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
exports.initANTStateForAddress = initANTStateForAddress;
|
package/lib/cjs/utils/base64.js
CHANGED
|
@@ -49,6 +49,6 @@ function toB64Url(buffer) {
|
|
|
49
49
|
}
|
|
50
50
|
exports.toB64Url = toB64Url;
|
|
51
51
|
function sha256B64Url(input) {
|
|
52
|
-
return toB64Url((0, crypto_1.createHash)('sha256').update(input).digest());
|
|
52
|
+
return toB64Url((0, crypto_1.createHash)('sha256').update(Uint8Array.from(input)).digest());
|
|
53
53
|
}
|
|
54
54
|
exports.sha256B64Url = sha256B64Url;
|
package/lib/cjs/version.js
CHANGED