@ar.io/sdk 3.10.0-alpha.1 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +124 -140
  2. package/bundles/web.bundle.min.js +150 -126
  3. package/lib/cjs/cli/commands/antCommands.js +3 -4
  4. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -6
  5. package/lib/cjs/cli/commands/gatewayWriteCommands.js +11 -12
  6. package/lib/cjs/cli/commands/readCommands.js +21 -22
  7. package/lib/cjs/cli/commands/transfer.js +6 -7
  8. package/lib/cjs/cli/options.js +0 -12
  9. package/lib/cjs/cli/utils.js +52 -74
  10. package/lib/cjs/common/ant-versions.js +5 -5
  11. package/lib/cjs/common/faucet.js +150 -0
  12. package/lib/cjs/common/index.js +1 -0
  13. package/lib/cjs/common/io.js +71 -55
  14. package/lib/cjs/types/ant.js +2 -2
  15. package/lib/cjs/types/faucet.js +2 -0
  16. package/lib/cjs/types/index.js +1 -0
  17. package/lib/cjs/types/io.js +8 -7
  18. package/lib/cjs/utils/ao.js +11 -9
  19. package/lib/cjs/utils/arweave.js +4 -4
  20. package/lib/cjs/utils/base64.js +4 -5
  21. package/lib/cjs/utils/json.js +1 -2
  22. package/lib/cjs/utils/schema.js +1 -2
  23. package/lib/cjs/version.js +1 -1
  24. package/lib/esm/cli/options.js +0 -12
  25. package/lib/esm/cli/utils.js +10 -31
  26. package/lib/esm/common/ant-versions.js +5 -5
  27. package/lib/esm/common/faucet.js +145 -0
  28. package/lib/esm/common/index.js +1 -0
  29. package/lib/esm/common/io.js +70 -54
  30. package/lib/esm/types/index.js +1 -0
  31. package/lib/esm/types/io.js +4 -3
  32. package/lib/esm/utils/ao.js +2 -0
  33. package/lib/esm/version.js +1 -1
  34. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  35. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  36. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  37. package/lib/types/cli/commands/readCommands.d.ts +3 -4
  38. package/lib/types/cli/commands/transfer.d.ts +3 -3
  39. package/lib/types/cli/options.d.ts +0 -9
  40. package/lib/types/cli/types.d.ts +0 -3
  41. package/lib/types/cli/utils.d.ts +1 -5
  42. package/lib/types/common/ant-versions.d.ts +6 -3
  43. package/lib/types/common/faucet.d.ts +96 -0
  44. package/lib/types/common/http.d.ts +0 -1
  45. package/lib/types/common/index.d.ts +1 -0
  46. package/lib/types/common/io.d.ts +22 -13
  47. package/lib/types/types/common.d.ts +1 -7
  48. package/lib/types/types/faucet.d.ts +82 -0
  49. package/lib/types/types/index.d.ts +1 -0
  50. package/lib/types/types/io.d.ts +9 -10
  51. package/lib/types/types/token.d.ts +0 -1
  52. package/lib/types/utils/base64.d.ts +0 -1
  53. package/lib/types/version.d.ts +1 -1
  54. package/package.json +5 -7
  55. package/lib/cjs/common/turbo.js +0 -134
  56. package/lib/cjs/utils/url.js +0 -28
  57. package/lib/cjs/utils/url.test.js +0 -24
  58. package/lib/esm/common/turbo.js +0 -129
  59. package/lib/esm/utils/url.js +0 -24
  60. package/lib/esm/utils/url.test.js +0 -19
  61. package/lib/types/common/turbo.d.ts +0 -47
  62. package/lib/types/utils/url.d.ts +0 -19
  63. /package/lib/{types/utils/url.test.d.ts → esm/types/faucet.js} +0 -0
@@ -3,7 +3,48 @@ 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.assertLockLengthInRange = exports.fundFromFromOptions = exports.getTokenCostParamsFromOptions = exports.getANTStateFromOptions = exports.requiredPositiveIntegerFromOptions = exports.positiveIntegerFromOptions = exports.requiredStringArrayFromOptions = exports.requiredStringFromOptions = exports.booleanFromOptions = exports.writeANTFromOptions = exports.readANTFromOptions = exports.requiredProcessIdFromOptions = exports.assertConfirmationPrompt = exports.confirmationPrompt = exports.assertEnoughMARIOBalance = exports.assertEnoughBalanceForArNSPurchase = exports.requiredMARIOFromOptions = exports.recordTypeFromOptions = exports.redelegateParamsFromOptions = exports.requiredTargetAndQuantityFromOptions = exports.gatewaySettingsFromOptions = exports.customTagsFromOptions = exports.requiredInitiatorFromOptions = exports.epochInputFromOptions = exports.paginationParamsFromOptions = exports.requiredAddressFromOptions = exports.addressFromOptions = exports.formatMARIOToARIOWithCommas = exports.formatARIOWithCommas = exports.writeARIOFromOptions = exports.requiredAoSignerFromOptions = exports.requiredContractSignerFromOptions = exports.contractSignerFromOptions = exports.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = exports.defaultTtlSecondsCLI = void 0;
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.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
17
+ exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
18
+ exports.writeARIOFromOptions = writeARIOFromOptions;
19
+ exports.formatARIOWithCommas = formatARIOWithCommas;
20
+ exports.formatMARIOToARIOWithCommas = formatMARIOToARIOWithCommas;
21
+ exports.addressFromOptions = addressFromOptions;
22
+ exports.requiredAddressFromOptions = requiredAddressFromOptions;
23
+ exports.paginationParamsFromOptions = paginationParamsFromOptions;
24
+ exports.epochInputFromOptions = epochInputFromOptions;
25
+ exports.requiredInitiatorFromOptions = requiredInitiatorFromOptions;
26
+ exports.customTagsFromOptions = customTagsFromOptions;
27
+ exports.gatewaySettingsFromOptions = gatewaySettingsFromOptions;
28
+ exports.requiredTargetAndQuantityFromOptions = requiredTargetAndQuantityFromOptions;
29
+ exports.redelegateParamsFromOptions = redelegateParamsFromOptions;
30
+ exports.recordTypeFromOptions = recordTypeFromOptions;
31
+ exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
32
+ exports.assertEnoughBalanceForArNSPurchase = assertEnoughBalanceForArNSPurchase;
33
+ exports.assertEnoughMARIOBalance = assertEnoughMARIOBalance;
34
+ exports.confirmationPrompt = confirmationPrompt;
35
+ exports.assertConfirmationPrompt = assertConfirmationPrompt;
36
+ exports.requiredProcessIdFromOptions = requiredProcessIdFromOptions;
37
+ exports.readANTFromOptions = readANTFromOptions;
38
+ exports.writeANTFromOptions = writeANTFromOptions;
39
+ exports.booleanFromOptions = booleanFromOptions;
40
+ exports.requiredStringFromOptions = requiredStringFromOptions;
41
+ exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
42
+ exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
43
+ exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
44
+ exports.getANTStateFromOptions = getANTStateFromOptions;
45
+ exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
46
+ exports.fundFromFromOptions = fundFromFromOptions;
47
+ exports.assertLockLengthInRange = assertLockLengthInRange;
7
48
  /**
8
49
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
9
50
  *
@@ -19,7 +60,6 @@ exports.assertLockLengthInRange = exports.fundFromFromOptions = exports.getToken
19
60
  * See the License for the specific language governing permissions and
20
61
  * limitations under the License.
21
62
  */
22
- const arbundles_1 = require("@dha-team/arbundles");
23
63
  const aoconnect_1 = require("@permaweb/aoconnect");
24
64
  const commander_1 = require("commander");
25
65
  const fs_1 = require("fs");
@@ -30,7 +70,6 @@ exports.defaultTtlSecondsCLI = 3600;
30
70
  function stringifyJsonForCLIDisplay(json) {
31
71
  return JSON.stringify(json, null, 2);
32
72
  }
33
- exports.stringifyJsonForCLIDisplay = stringifyJsonForCLIDisplay;
34
73
  function logCommandOutput(output) {
35
74
  console.log(stringifyJsonForCLIDisplay(output));
36
75
  }
@@ -59,14 +98,12 @@ async function runCommand(command, action) {
59
98
  exitWithErrorLog(error, options.debug);
60
99
  }
61
100
  }
62
- exports.runCommand = runCommand;
63
101
  function applyOptions(command, options) {
64
102
  [...options].forEach((option) => {
65
103
  command.option(option.alias, option.description, option.default);
66
104
  });
67
105
  return command;
68
106
  }
69
- exports.applyOptions = applyOptions;
70
107
  function makeCommand({ description, name, options = [], action, }) {
71
108
  const command = commander_1.program.command(name).description(description);
72
109
  const appliedCommand = applyOptions(command, [...options, ...options_js_1.globalOptions]);
@@ -75,7 +112,6 @@ function makeCommand({ description, name, options = [], action, }) {
75
112
  }
76
113
  return appliedCommand;
77
114
  }
78
- exports.makeCommand = makeCommand;
79
115
  function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
80
116
  if (arioProcessId !== undefined) {
81
117
  return arioProcessId;
@@ -88,8 +124,7 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
88
124
  }
89
125
  return index_js_1.ARIO_MAINNET_PROCESS_ID;
90
126
  }
91
- exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
92
- function walletFromOptions({ privateKey, walletFile, }) {
127
+ function jwkFromOptions({ privateKey, walletFile, }) {
93
128
  if (privateKey !== undefined) {
94
129
  return JSON.parse(privateKey);
95
130
  }
@@ -99,17 +134,15 @@ function walletFromOptions({ privateKey, walletFile, }) {
99
134
  return undefined;
100
135
  }
101
136
  function requiredJwkFromOptions(options) {
102
- const jwk = walletFromOptions(options);
137
+ const jwk = jwkFromOptions(options);
103
138
  if (jwk === undefined) {
104
139
  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`');
105
140
  }
106
141
  return jwk;
107
142
  }
108
- exports.requiredJwkFromOptions = requiredJwkFromOptions;
109
143
  function jwkToAddress(jwk) {
110
144
  return (0, index_js_1.sha256B64Url)((0, index_js_1.fromB64Url)(jwk.n));
111
145
  }
112
- exports.jwkToAddress = jwkToAddress;
113
146
  function setLoggerIfDebug(options) {
114
147
  if (options.debug) {
115
148
  index_js_1.Logger.default.setLogLevel('debug');
@@ -119,7 +152,6 @@ function getLoggerFromOptions(options) {
119
152
  setLoggerIfDebug(options);
120
153
  return index_js_1.Logger.default;
121
154
  }
122
- exports.getLoggerFromOptions = getLoggerFromOptions;
123
155
  function aoProcessFromOptions(options) {
124
156
  return new index_js_1.AOProcess({
125
157
  processId: arioProcessIdFromOptions(options),
@@ -132,38 +164,17 @@ function readARIOFromOptions(options) {
132
164
  setLoggerIfDebug(options);
133
165
  return index_js_1.ARIO.init({
134
166
  process: aoProcessFromOptions(options),
135
- paymentUrl: options.paymentUrl,
136
167
  });
137
168
  }
138
- exports.readARIOFromOptions = readARIOFromOptions;
139
- function contractSignerFromOptions(options) {
140
- const wallet = walletFromOptions(options);
141
- if (wallet === undefined) {
142
- return undefined;
143
- }
144
- const token = options.token ?? 'arweave';
145
- if (token === 'ethereum') {
146
- const signer = new arbundles_1.EthereumSigner(wallet);
147
- // For EthereumSigner, we need to convert the JWK to a string
148
- return { signer, signerAddress: signer.publicKey.toString('hex') };
149
- }
150
- // TODO: Support other wallet types
151
- const signer = new index_js_1.ArweaveSigner(wallet);
152
- return { signer, signerAddress: jwkToAddress(wallet) };
153
- }
154
- exports.contractSignerFromOptions = contractSignerFromOptions;
155
169
  function requiredContractSignerFromOptions(options) {
156
- const contractSigner = contractSignerFromOptions(options);
157
- if (contractSigner === undefined) {
158
- 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`');
159
- }
160
- return contractSigner;
170
+ // TODO: Support other wallet types
171
+ const jwk = requiredJwkFromOptions(options);
172
+ const signer = new index_js_1.ArweaveSigner(jwk);
173
+ return { signer, signerAddress: jwkToAddress(jwk) };
161
174
  }
162
- exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
163
175
  function requiredAoSignerFromOptions(options) {
164
176
  return (0, index_js_1.createAoSigner)(requiredContractSignerFromOptions(options).signer);
165
177
  }
166
- exports.requiredAoSignerFromOptions = requiredAoSignerFromOptions;
167
178
  function writeARIOFromOptions(options) {
168
179
  const { signer, signerAddress } = requiredContractSignerFromOptions(options);
169
180
  setLoggerIfDebug(options);
@@ -171,12 +182,10 @@ function writeARIOFromOptions(options) {
171
182
  ario: index_js_1.ARIO.init({
172
183
  process: aoProcessFromOptions(options),
173
184
  signer,
174
- paymentUrl: options.paymentUrl,
175
185
  }),
176
186
  signerAddress,
177
187
  };
178
188
  }
179
- exports.writeARIOFromOptions = writeARIOFromOptions;
180
189
  function formatARIOWithCommas(value) {
181
190
  const [integerPart, decimalPart] = value.toString().split('.');
182
191
  const integerWithCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
@@ -185,23 +194,21 @@ function formatARIOWithCommas(value) {
185
194
  }
186
195
  return integerWithCommas + '.' + decimalPart;
187
196
  }
188
- exports.formatARIOWithCommas = formatARIOWithCommas;
189
197
  function formatMARIOToARIOWithCommas(value) {
190
198
  return formatARIOWithCommas(value.toARIO());
191
199
  }
192
- exports.formatMARIOToARIOWithCommas = formatMARIOToARIOWithCommas;
193
200
  /** helper to get address from --address option first, then check wallet options */
194
201
  function addressFromOptions(options) {
195
202
  if (options.address !== undefined) {
196
203
  return options.address;
197
204
  }
198
- const signer = contractSignerFromOptions(options);
199
- if (signer !== undefined) {
200
- return signer.signerAddress;
205
+ // TODO: Support other wallet types
206
+ const jwk = jwkFromOptions(options);
207
+ if (jwk !== undefined) {
208
+ return jwkToAddress(jwk);
201
209
  }
202
210
  return undefined;
203
211
  }
204
- exports.addressFromOptions = addressFromOptions;
205
212
  function requiredAddressFromOptions(options) {
206
213
  const address = addressFromOptions(options);
207
214
  if (address !== undefined) {
@@ -209,7 +216,6 @@ function requiredAddressFromOptions(options) {
209
216
  }
210
217
  throw new Error('No address provided. Use --address or --wallet-file');
211
218
  }
212
- exports.requiredAddressFromOptions = requiredAddressFromOptions;
213
219
  const defaultCliPaginationLimit = 10; // more friendly UX than 100
214
220
  function paginationParamsFromOptions(options) {
215
221
  const { cursor, limit, sortBy, sortOrder } = options;
@@ -227,7 +233,6 @@ function paginationParamsFromOptions(options) {
227
233
  sortOrder,
228
234
  };
229
235
  }
230
- exports.paginationParamsFromOptions = paginationParamsFromOptions;
231
236
  function epochInputFromOptions(options) {
232
237
  if (options.epochIndex !== undefined) {
233
238
  return { epochIndex: +options.epochIndex };
@@ -237,14 +242,12 @@ function epochInputFromOptions(options) {
237
242
  }
238
243
  return undefined;
239
244
  }
240
- exports.epochInputFromOptions = epochInputFromOptions;
241
245
  function requiredInitiatorFromOptions(options) {
242
246
  if (options.initiator !== undefined) {
243
247
  return options.initiator;
244
248
  }
245
249
  return requiredAddressFromOptions(options);
246
250
  }
247
- exports.requiredInitiatorFromOptions = requiredInitiatorFromOptions;
248
251
  function customTagsFromOptions(options) {
249
252
  if (options.tags === undefined) {
250
253
  return {};
@@ -269,7 +272,6 @@ function customTagsFromOptions(options) {
269
272
  tags,
270
273
  };
271
274
  }
272
- exports.customTagsFromOptions = customTagsFromOptions;
273
275
  function gatewaySettingsFromOptions({ allowDelegatedStaking, autoStake, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, observerAddress, port, properties, allowedDelegates, }) {
274
276
  return {
275
277
  observerAddress,
@@ -287,7 +289,6 @@ function gatewaySettingsFromOptions({ allowDelegatedStaking, autoStake, delegate
287
289
  properties,
288
290
  };
289
291
  }
290
- exports.gatewaySettingsFromOptions = gatewaySettingsFromOptions;
291
292
  function requiredTargetAndQuantityFromOptions(options) {
292
293
  if (options.target === undefined) {
293
294
  throw new Error('No target provided. Use --target');
@@ -300,7 +301,6 @@ function requiredTargetAndQuantityFromOptions(options) {
300
301
  arioQuantity: new index_js_1.ARIOToken(+options.quantity),
301
302
  };
302
303
  }
303
- exports.requiredTargetAndQuantityFromOptions = requiredTargetAndQuantityFromOptions;
304
304
  function redelegateParamsFromOptions(options) {
305
305
  const { target, arioQuantity: aRIOQuantity } = requiredTargetAndQuantityFromOptions(options);
306
306
  const source = options.source;
@@ -314,7 +314,6 @@ function redelegateParamsFromOptions(options) {
314
314
  stakeQty: aRIOQuantity.toMARIO(),
315
315
  };
316
316
  }
317
- exports.redelegateParamsFromOptions = redelegateParamsFromOptions;
318
317
  function recordTypeFromOptions(options) {
319
318
  options.type ??= 'lease';
320
319
  if (options.type !== 'lease' && options.type !== 'permabuy') {
@@ -322,18 +321,13 @@ function recordTypeFromOptions(options) {
322
321
  }
323
322
  return options.type;
324
323
  }
325
- exports.recordTypeFromOptions = recordTypeFromOptions;
326
324
  function requiredMARIOFromOptions(options, key) {
327
325
  if (options[key] === undefined) {
328
326
  throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
329
327
  }
330
328
  return new index_js_1.ARIOToken(+options[key]).toMARIO();
331
329
  }
332
- exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
333
330
  async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
334
- if (costDetailsParams.fundFrom === 'turbo') {
335
- return;
336
- }
337
331
  const costDetails = await ario.getCostDetails(costDetailsParams);
338
332
  if (costDetails.fundingPlan) {
339
333
  if (costDetails.fundingPlan.shortfall > 0) {
@@ -348,7 +342,6 @@ async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsPa
348
342
  });
349
343
  }
350
344
  }
351
- exports.assertEnoughBalanceForArNSPurchase = assertEnoughBalanceForArNSPurchase;
352
345
  async function assertEnoughMARIOBalance({ address, ario, mARIOQuantity, }) {
353
346
  if (typeof mARIOQuantity === 'number') {
354
347
  mARIOQuantity = new index_js_1.mARIOToken(mARIOQuantity);
@@ -358,7 +351,6 @@ async function assertEnoughMARIOBalance({ address, ario, mARIOQuantity, }) {
358
351
  throw new Error(`Insufficient ARIO balance for action. Balance available: ${formatMARIOToARIOWithCommas(new index_js_1.mARIOToken(balance))} ARIO`);
359
352
  }
360
353
  }
361
- exports.assertEnoughMARIOBalance = assertEnoughMARIOBalance;
362
354
  async function confirmationPrompt(message) {
363
355
  const { confirm } = await (0, prompts_1.default)({
364
356
  type: 'confirm',
@@ -367,21 +359,18 @@ async function confirmationPrompt(message) {
367
359
  });
368
360
  return confirm;
369
361
  }
370
- exports.confirmationPrompt = confirmationPrompt;
371
362
  async function assertConfirmationPrompt(message, options) {
372
363
  if (options.skipConfirmation) {
373
364
  return true;
374
365
  }
375
366
  return confirmationPrompt(message);
376
367
  }
377
- exports.assertConfirmationPrompt = assertConfirmationPrompt;
378
368
  function requiredProcessIdFromOptions(o) {
379
369
  if (o.processId === undefined) {
380
370
  throw new Error('--process-id is required');
381
371
  }
382
372
  return o.processId;
383
373
  }
384
- exports.requiredProcessIdFromOptions = requiredProcessIdFromOptions;
385
374
  function ANTProcessFromOptions(options) {
386
375
  return new index_js_1.AOProcess({
387
376
  processId: requiredProcessIdFromOptions(options),
@@ -395,7 +384,6 @@ function readANTFromOptions(options) {
395
384
  process: ANTProcessFromOptions(options),
396
385
  });
397
386
  }
398
- exports.readANTFromOptions = readANTFromOptions;
399
387
  function writeANTFromOptions(options, signer) {
400
388
  signer ??= requiredContractSignerFromOptions(options).signer;
401
389
  return index_js_1.ANT.init({
@@ -403,11 +391,9 @@ function writeANTFromOptions(options, signer) {
403
391
  signer,
404
392
  });
405
393
  }
406
- exports.writeANTFromOptions = writeANTFromOptions;
407
394
  function booleanFromOptions(options, key) {
408
395
  return !!options[key];
409
396
  }
410
- exports.booleanFromOptions = booleanFromOptions;
411
397
  function requiredStringFromOptions(options, key) {
412
398
  const value = options[key];
413
399
  if (value === undefined) {
@@ -415,7 +401,6 @@ function requiredStringFromOptions(options, key) {
415
401
  }
416
402
  return value;
417
403
  }
418
- exports.requiredStringFromOptions = requiredStringFromOptions;
419
404
  function requiredStringArrayFromOptions(options, key) {
420
405
  const value = options[key];
421
406
  if (value === undefined) {
@@ -426,7 +411,6 @@ function requiredStringArrayFromOptions(options, key) {
426
411
  }
427
412
  return value;
428
413
  }
429
- exports.requiredStringArrayFromOptions = requiredStringArrayFromOptions;
430
414
  function positiveIntegerFromOptions(options, key) {
431
415
  const value = options[key];
432
416
  if (value === undefined) {
@@ -438,7 +422,6 @@ function positiveIntegerFromOptions(options, key) {
438
422
  }
439
423
  return numberValue;
440
424
  }
441
- exports.positiveIntegerFromOptions = positiveIntegerFromOptions;
442
425
  function requiredPositiveIntegerFromOptions(options, key) {
443
426
  const value = positiveIntegerFromOptions(options, key);
444
427
  if (value === undefined) {
@@ -446,7 +429,6 @@ function requiredPositiveIntegerFromOptions(options, key) {
446
429
  }
447
430
  return value;
448
431
  }
449
- exports.requiredPositiveIntegerFromOptions = requiredPositiveIntegerFromOptions;
450
432
  function getANTStateFromOptions(options) {
451
433
  return (0, index_js_1.initANTStateForAddress)({
452
434
  owner: requiredAddressFromOptions(options),
@@ -462,7 +444,6 @@ function getANTStateFromOptions(options) {
462
444
  : exports.defaultTtlSecondsCLI,
463
445
  });
464
446
  }
465
- exports.getANTStateFromOptions = getANTStateFromOptions;
466
447
  function getTokenCostParamsFromOptions(o) {
467
448
  o.intent ??= 'Buy-Name';
468
449
  o.type ??= 'lease';
@@ -482,7 +463,6 @@ function getTokenCostParamsFromOptions(o) {
482
463
  fromAddress: addressFromOptions(o),
483
464
  };
484
465
  }
485
- exports.getTokenCostParamsFromOptions = getTokenCostParamsFromOptions;
486
466
  function fundFromFromOptions(o) {
487
467
  if (o.fundFrom !== undefined) {
488
468
  if (!(0, index_js_1.isValidFundFrom)(o.fundFrom)) {
@@ -491,7 +471,6 @@ function fundFromFromOptions(o) {
491
471
  }
492
472
  return o.fundFrom ?? 'balance';
493
473
  }
494
- exports.fundFromFromOptions = fundFromFromOptions;
495
474
  function assertLockLengthInRange(lockLengthMs, assertMin = true) {
496
475
  const minLockLengthMs = 1209600000; // 14 days
497
476
  const maxLockLengthMs = 378432000000; // ~12 years
@@ -505,4 +484,3 @@ function assertLockLengthInRange(lockLengthMs, assertMin = true) {
505
484
  throw new Error(`Lock length must be at least 14 days (1209600000 ms). Provided lock length: ${lockLengthMs} ms`);
506
485
  }
507
486
  }
508
- exports.assertLockLengthInRange = assertLockLengthInRange;
@@ -75,14 +75,14 @@ class ANTVersionsWritable extends ANTVersionsReadable {
75
75
  super(config);
76
76
  this.signer = (0, ao_js_1.createAoSigner)(signer);
77
77
  }
78
- async addVersion({ version, moduleId, luaSourceId, notes, }, { tags }) {
78
+ async addVersion(params, { tags }) {
79
79
  return this.process.send({
80
80
  tags: (0, arweave_js_1.pruneTags)([
81
81
  { name: 'Action', value: 'Add-Version' },
82
- { name: 'Version', value: version },
83
- { name: 'Module-Id', value: moduleId },
84
- { name: 'Lua-Source-Id', value: luaSourceId },
85
- { name: 'Notes', value: notes },
82
+ { name: 'Version', value: params.version },
83
+ { name: 'Module-Id', value: params.moduleId },
84
+ { name: 'Lua-Source-Id', value: params.luaSourceId },
85
+ { name: 'Notes', value: params.notes },
86
86
  ...(tags ?? []),
87
87
  ]),
88
88
  signer: this.signer,
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ARIOTokenFaucet = void 0;
4
+ exports.createFaucet = createFaucet;
5
+ const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
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.
8
+ * @param arioInstance - The ARIOReadable instance
9
+ * @param faucetApiUrl - The URL of the faucet API
10
+ * @returns A proxy object that implements the TokenFaucet interface
11
+ */
12
+ function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, }) {
13
+ const faucet = new ARIOTokenFaucet({
14
+ faucetUrl: faucetApiUrl,
15
+ processId: arioInstance.process.processId,
16
+ });
17
+ const proxy = new Proxy(arioInstance, {
18
+ get(target, prop) {
19
+ if (prop === 'faucet') {
20
+ return faucet;
21
+ }
22
+ if (prop in target) {
23
+ const result = target[prop];
24
+ if (typeof result === 'function') {
25
+ return result.bind(target);
26
+ }
27
+ return result;
28
+ }
29
+ return undefined;
30
+ },
31
+ });
32
+ return proxy;
33
+ }
34
+ class ARIOTokenFaucet {
35
+ faucetUrl;
36
+ processId;
37
+ constructor({ faucetUrl, processId, }) {
38
+ this.faucetUrl = faucetUrl;
39
+ this.processId = processId;
40
+ }
41
+ /**
42
+ * Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
43
+ * @returns The captcha URL for a process
44
+ */
45
+ async captchaUrl() {
46
+ const res = await fetch(`${this.faucetUrl}/api/captcha/url?process-id=${this.processId}`, {
47
+ method: 'GET',
48
+ });
49
+ if (!res.ok) {
50
+ const body = await res.json().catch(() => ({ error: res.statusText }));
51
+ throw new Error(body.error);
52
+ }
53
+ const data = (await res.json());
54
+ return data;
55
+ }
56
+ /**
57
+ * Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
58
+ * @param captchaResponse - The captcha response
59
+ * @param recipient - The recipient address
60
+ * @param quantity - The quantity of tokens to claim
61
+ * @returns The claim id and success status
62
+ */
63
+ async claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }) {
64
+ const res = await fetch(`${this.faucetUrl}/api/claim/sync`, {
65
+ method: 'POST',
66
+ headers: { 'Content-Type': 'application/json' },
67
+ body: JSON.stringify({
68
+ processId: this.processId,
69
+ recipient,
70
+ quantity,
71
+ captchaResponse,
72
+ }),
73
+ });
74
+ if (!res.ok) {
75
+ const body = await res.json().catch(() => ({ error: res.statusText }));
76
+ throw new Error(body.error);
77
+ }
78
+ const data = (await res.json());
79
+ return data;
80
+ }
81
+ /**
82
+ * Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
83
+ * @param captchaResponse - The captcha response
84
+ * @returns The status of the request, the authorization token, and the expiration time
85
+ */
86
+ async requestAuthToken({ captchaResponse, }) {
87
+ const res = await fetch(`${this.faucetUrl}/api/captcha/verify`, {
88
+ method: 'POST',
89
+ headers: { 'Content-Type': 'application/json' },
90
+ body: JSON.stringify({
91
+ processId: this.processId,
92
+ captchaResponse,
93
+ }),
94
+ });
95
+ if (!res.ok) {
96
+ const body = await res.json().catch(() => ({ error: res.statusText }));
97
+ throw new Error(body.error);
98
+ }
99
+ const data = (await res.json());
100
+ return data;
101
+ }
102
+ /**
103
+ * Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
104
+ * @param authToken - The authorization token
105
+ * @param recipient - The recipient address
106
+ * @param quantity - The quantity of tokens to claim
107
+ * @returns The message id of the transfer and success status
108
+ */
109
+ async claimWithAuthToken({ authToken, recipient, quantity, }) {
110
+ const res = await fetch(`${this.faucetUrl}/api/claim/async`, {
111
+ method: 'POST',
112
+ headers: {
113
+ 'Content-Type': 'application/json',
114
+ Authorization: `Bearer ${authToken}`,
115
+ },
116
+ body: JSON.stringify({
117
+ recipient,
118
+ qty: quantity,
119
+ processId: this.processId,
120
+ }),
121
+ });
122
+ if (!res.ok) {
123
+ const body = await res.json().catch(() => ({ error: res.statusText }));
124
+ throw new Error(body.error);
125
+ }
126
+ const data = (await res.json());
127
+ return data;
128
+ }
129
+ /**
130
+ * Verifies an authorization token is valid.
131
+ * @param authToken - The authorization token
132
+ * @returns The validity of the authorization token and the expiration time
133
+ */
134
+ async verifyAuthToken({ authToken }) {
135
+ const res = await fetch(`${this.faucetUrl}/api/token/verify?process-id=${this.processId}`, {
136
+ method: 'GET',
137
+ headers: {
138
+ 'Content-Type': 'application/json',
139
+ Authorization: `Bearer ${authToken}`,
140
+ },
141
+ });
142
+ if (!res.ok) {
143
+ const body = await res.json().catch(() => ({ error: res.statusText }));
144
+ throw new Error(body.error);
145
+ }
146
+ const data = (await res.json());
147
+ return data;
148
+ }
149
+ }
150
+ exports.ARIOTokenFaucet = ARIOTokenFaucet;
@@ -34,6 +34,7 @@ __exportStar(require("./logger.js"), exports);
34
34
  __exportStar(require("./ant.js"), exports);
35
35
  __exportStar(require("./ant-registry.js"), exports);
36
36
  __exportStar(require("./ant-versions.js"), exports);
37
+ __exportStar(require("./faucet.js"), exports);
37
38
  // ao
38
39
  __exportStar(require("./io.js"), exports);
39
40
  __exportStar(require("./contracts/ao-process.js"), exports);