@ar.io/sdk 3.9.1-alpha.2 → 3.10.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.
Files changed (36) hide show
  1. package/bundles/web.bundle.min.js +99 -94
  2. package/lib/cjs/cli/options.js +12 -0
  3. package/lib/cjs/cli/utils.js +33 -11
  4. package/lib/cjs/common/ant-versions.js +5 -5
  5. package/lib/cjs/common/io.js +52 -1
  6. package/lib/cjs/common/turbo.js +134 -0
  7. package/lib/cjs/types/io.js +1 -1
  8. package/lib/cjs/utils/url.js +28 -0
  9. package/lib/cjs/utils/url.test.js +24 -0
  10. package/lib/cjs/version.js +1 -1
  11. package/lib/esm/cli/options.js +12 -0
  12. package/lib/esm/cli/utils.js +31 -10
  13. package/lib/esm/common/ant-versions.js +5 -5
  14. package/lib/esm/common/io.js +52 -1
  15. package/lib/esm/common/turbo.js +129 -0
  16. package/lib/esm/types/io.js +1 -1
  17. package/lib/esm/utils/url.js +24 -0
  18. package/lib/esm/utils/url.test.js +19 -0
  19. package/lib/esm/version.js +1 -1
  20. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  21. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  22. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  23. package/lib/types/cli/commands/readCommands.d.ts +1 -0
  24. package/lib/types/cli/commands/transfer.d.ts +3 -3
  25. package/lib/types/cli/options.d.ts +9 -0
  26. package/lib/types/cli/types.d.ts +3 -0
  27. package/lib/types/cli/utils.d.ts +5 -1
  28. package/lib/types/common/ant-versions.d.ts +3 -6
  29. package/lib/types/common/io.d.ts +9 -21
  30. package/lib/types/common/turbo.d.ts +47 -0
  31. package/lib/types/types/common.d.ts +6 -1
  32. package/lib/types/types/io.d.ts +7 -6
  33. package/lib/types/utils/url.d.ts +19 -0
  34. package/lib/types/utils/url.test.d.ts +1 -0
  35. package/lib/types/version.d.ts +1 -1
  36. package/package.json +3 -2
@@ -52,6 +52,10 @@ exports.optionMap = {
52
52
  alias: '--cu-url <cuUrl>',
53
53
  description: 'The URL for a custom compute unit',
54
54
  },
55
+ paymentUrl: {
56
+ alias: '--payment-url <paymentUrl>',
57
+ description: 'The URL for a custom turbo payment service',
58
+ },
55
59
  processId: {
56
60
  alias: '--process-id <processId>',
57
61
  description: 'The process ID to interact with',
@@ -272,9 +276,15 @@ exports.optionMap = {
272
276
  alias: '--logo <logo>',
273
277
  description: 'The ANT logo',
274
278
  },
279
+ token: {
280
+ alias: '-t, --token <type>',
281
+ description: 'Crypto token type for wallet or action',
282
+ default: 'arweave',
283
+ },
275
284
  };
276
285
  exports.walletOptions = [
277
286
  exports.optionMap.walletFile,
287
+ exports.optionMap.token,
278
288
  // optionMap.mnemonic,
279
289
  exports.optionMap.privateKey,
280
290
  ];
@@ -292,6 +302,7 @@ exports.arnsPurchaseOptions = [
292
302
  ...exports.writeActionOptions,
293
303
  exports.optionMap.name,
294
304
  exports.optionMap.fundFrom,
305
+ exports.optionMap.paymentUrl,
295
306
  ];
296
307
  exports.epochOptions = [exports.optionMap.epochIndex, exports.optionMap.timestamp];
297
308
  exports.addressAndVaultIdOptions = [exports.optionMap.address, exports.optionMap.vaultId];
@@ -315,6 +326,7 @@ exports.tokenCostOptions = [
315
326
  exports.optionMap.quantity,
316
327
  exports.optionMap.address,
317
328
  exports.optionMap.fundFrom,
329
+ exports.optionMap.paymentUrl,
318
330
  ];
319
331
  exports.transferOptions = [
320
332
  ...exports.writeActionOptions,
@@ -3,7 +3,7 @@ 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.readARIOFromOptions = exports.getLoggerFromOptions = exports.jwkToAddress = exports.requiredJwkFromOptions = exports.arioProcessIdFromOptions = exports.makeCommand = exports.applyOptions = exports.runCommand = exports.stringifyJsonForCLIDisplay = exports.defaultTtlSecondsCLI = void 0;
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;
7
7
  /**
8
8
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
9
9
  *
@@ -19,6 +19,7 @@ exports.assertLockLengthInRange = exports.fundFromFromOptions = exports.getToken
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ const arbundles_1 = require("@dha-team/arbundles");
22
23
  const aoconnect_1 = require("@permaweb/aoconnect");
23
24
  const commander_1 = require("commander");
24
25
  const fs_1 = require("fs");
@@ -88,7 +89,7 @@ function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
88
89
  return index_js_1.ARIO_MAINNET_PROCESS_ID;
89
90
  }
90
91
  exports.arioProcessIdFromOptions = arioProcessIdFromOptions;
91
- function jwkFromOptions({ privateKey, walletFile, }) {
92
+ function walletFromOptions({ privateKey, walletFile, }) {
92
93
  if (privateKey !== undefined) {
93
94
  return JSON.parse(privateKey);
94
95
  }
@@ -98,7 +99,7 @@ function jwkFromOptions({ privateKey, walletFile, }) {
98
99
  return undefined;
99
100
  }
100
101
  function requiredJwkFromOptions(options) {
101
- const jwk = jwkFromOptions(options);
102
+ const jwk = walletFromOptions(options);
102
103
  if (jwk === undefined) {
103
104
  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`');
104
105
  }
@@ -131,14 +132,32 @@ function readARIOFromOptions(options) {
131
132
  setLoggerIfDebug(options);
132
133
  return index_js_1.ARIO.init({
133
134
  process: aoProcessFromOptions(options),
135
+ paymentUrl: options.paymentUrl,
134
136
  });
135
137
  }
136
138
  exports.readARIOFromOptions = readARIOFromOptions;
137
- function requiredContractSignerFromOptions(options) {
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
+ }
138
150
  // TODO: Support other wallet types
139
- const jwk = requiredJwkFromOptions(options);
140
- const signer = new index_js_1.ArweaveSigner(jwk);
141
- return { signer, signerAddress: jwkToAddress(jwk) };
151
+ const signer = new index_js_1.ArweaveSigner(wallet);
152
+ return { signer, signerAddress: jwkToAddress(wallet) };
153
+ }
154
+ exports.contractSignerFromOptions = contractSignerFromOptions;
155
+ 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;
142
161
  }
143
162
  exports.requiredContractSignerFromOptions = requiredContractSignerFromOptions;
144
163
  function requiredAoSignerFromOptions(options) {
@@ -152,6 +171,7 @@ function writeARIOFromOptions(options) {
152
171
  ario: index_js_1.ARIO.init({
153
172
  process: aoProcessFromOptions(options),
154
173
  signer,
174
+ paymentUrl: options.paymentUrl,
155
175
  }),
156
176
  signerAddress,
157
177
  };
@@ -175,10 +195,9 @@ function addressFromOptions(options) {
175
195
  if (options.address !== undefined) {
176
196
  return options.address;
177
197
  }
178
- // TODO: Support other wallet types
179
- const jwk = jwkFromOptions(options);
180
- if (jwk !== undefined) {
181
- return jwkToAddress(jwk);
198
+ const signer = contractSignerFromOptions(options);
199
+ if (signer !== undefined) {
200
+ return signer.signerAddress;
182
201
  }
183
202
  return undefined;
184
203
  }
@@ -312,6 +331,9 @@ function requiredMARIOFromOptions(options, key) {
312
331
  }
313
332
  exports.requiredMARIOFromOptions = requiredMARIOFromOptions;
314
333
  async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
334
+ if (costDetailsParams.fundFrom === 'turbo') {
335
+ return;
336
+ }
315
337
  const costDetails = await ario.getCostDetails(costDetailsParams);
316
338
  if (costDetails.fundingPlan) {
317
339
  if (costDetails.fundingPlan.shortfall > 0) {
@@ -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(params, { tags }) {
78
+ async addVersion({ version, moduleId, luaSourceId, notes, }, { 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: params.version },
83
- { name: 'Module-Id', value: params.moduleId },
84
- { name: 'Lua-Source-Id', value: params.luaSourceId },
85
- { name: 'Notes', value: params.notes },
82
+ { name: 'Version', value: version },
83
+ { name: 'Module-Id', value: moduleId },
84
+ { name: 'Lua-Source-Id', value: luaSourceId },
85
+ { name: 'Notes', value: notes },
86
86
  ...(tags ?? []),
87
87
  ]),
88
88
  signer: this.signer,
@@ -8,6 +8,7 @@ const arweave_js_1 = require("../utils/arweave.js");
8
8
  const arweave_js_2 = require("./arweave.js");
9
9
  const ao_process_js_1 = require("./contracts/ao-process.js");
10
10
  const error_js_1 = require("./error.js");
11
+ const turbo_js_1 = require("./turbo.js");
11
12
  class ARIO {
12
13
  // Implementation
13
14
  static init(config) {
@@ -22,6 +23,7 @@ class ARIOReadable {
22
23
  process;
23
24
  epochSettings;
24
25
  arweave;
26
+ paymentProvider; // TODO: this could be an array/map of payment providers
25
27
  constructor(config) {
26
28
  this.arweave = config?.arweave ?? arweave_js_2.defaultArweave;
27
29
  if (config === undefined || Object.keys(config).length === 0) {
@@ -40,6 +42,9 @@ class ARIOReadable {
40
42
  else {
41
43
  throw new error_js_1.InvalidContractConfigurationError();
42
44
  }
45
+ this.paymentProvider = new turbo_js_1.TurboArNSPaymentProvider({
46
+ paymentUrl: config?.paymentUrl,
47
+ });
43
48
  }
44
49
  async getInfo() {
45
50
  return this.process.read({
@@ -371,6 +376,20 @@ class ARIOReadable {
371
376
  // TODO: Can overload this function to refine different types of cost details params
372
377
  async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
373
378
  const replacedBuyRecordWithBuyName = intent === 'Buy-Record' ? 'Buy-Name' : intent;
379
+ if (fundFrom === 'turbo') {
380
+ const { mARIO, winc } = await this.paymentProvider.getArNSPriceDetails({
381
+ intent: replacedBuyRecordWithBuyName,
382
+ name,
383
+ quantity,
384
+ type,
385
+ years,
386
+ });
387
+ return {
388
+ tokenCost: +mARIO,
389
+ wincQty: winc,
390
+ discounts: [],
391
+ };
392
+ }
374
393
  const allTags = [
375
394
  { name: 'Action', value: 'Cost-Details' },
376
395
  {
@@ -538,7 +557,8 @@ class ARIOReadable {
538
557
  exports.ARIOReadable = ARIOReadable;
539
558
  class ARIOWriteable extends ARIOReadable {
540
559
  signer;
541
- constructor({ signer, ...config }) {
560
+ paymentProvider;
561
+ constructor({ signer, paymentUrl, ...config }) {
542
562
  if (config === undefined) {
543
563
  super({
544
564
  process: new ao_process_js_1.AOProcess({
@@ -550,6 +570,10 @@ class ARIOWriteable extends ARIOReadable {
550
570
  super(config);
551
571
  }
552
572
  this.signer = (0, ao_js_1.createAoSigner)(signer);
573
+ this.paymentProvider = new turbo_js_1.TurboArNSPaymentProvider({
574
+ signer: signer,
575
+ paymentUrl,
576
+ });
553
577
  }
554
578
  async transfer({ target, qty, }, options) {
555
579
  const { tags = [] } = options || {};
@@ -824,6 +848,12 @@ class ARIOWriteable extends ARIOReadable {
824
848
  });
825
849
  }
826
850
  async buyRecord(params, options) {
851
+ if (params.fundFrom === 'turbo') {
852
+ return this.paymentProvider.initiateArNSPurchase({
853
+ intent: 'Buy-Name',
854
+ ...params,
855
+ });
856
+ }
827
857
  const { tags = [] } = options || {};
828
858
  const allTags = [
829
859
  ...tags,
@@ -848,6 +878,12 @@ class ARIOWriteable extends ARIOReadable {
848
878
  * @returns {Promise<AoMessageResult>} The result of the upgrade
849
879
  */
850
880
  async upgradeRecord(params, options) {
881
+ if (params.fundFrom === 'turbo') {
882
+ return this.paymentProvider.initiateArNSPurchase({
883
+ intent: 'Upgrade-Name',
884
+ name: params.name,
885
+ });
886
+ }
851
887
  const { tags = [] } = options || {};
852
888
  const allTags = [
853
889
  ...tags,
@@ -870,6 +906,12 @@ class ARIOWriteable extends ARIOReadable {
870
906
  * @returns {Promise<AoMessageResult>} The result of the extension
871
907
  */
872
908
  async extendLease(params, options) {
909
+ if (params.fundFrom === 'turbo') {
910
+ return this.paymentProvider.initiateArNSPurchase({
911
+ intent: 'Extend-Lease',
912
+ ...params,
913
+ });
914
+ }
873
915
  const { tags = [] } = options || {};
874
916
  const allTags = [
875
917
  ...tags,
@@ -884,6 +926,12 @@ class ARIOWriteable extends ARIOReadable {
884
926
  });
885
927
  }
886
928
  async increaseUndernameLimit(params, options) {
929
+ if (params.fundFrom === 'turbo') {
930
+ return this.paymentProvider.initiateArNSPurchase({
931
+ intent: 'Increase-Undername-Limit',
932
+ ...params,
933
+ });
934
+ }
887
935
  const { tags = [] } = options || {};
888
936
  const allTags = [
889
937
  ...tags,
@@ -920,6 +968,9 @@ class ARIOWriteable extends ARIOReadable {
920
968
  });
921
969
  }
922
970
  async requestPrimaryName(params, options) {
971
+ if (params.fundFrom === 'turbo') {
972
+ throw new Error('Turbo funding is not yet supported for primary name requests');
973
+ }
923
974
  const { tags = [] } = options || {};
924
975
  const allTags = [
925
976
  ...tags,
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TurboArNSPaymentProvider = exports.signedRequestHeadersFromSigner = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const arbundles_1 = require("@dha-team/arbundles");
20
+ const uuid_1 = require("uuid");
21
+ const token_js_1 = require("../types/token.js");
22
+ const base64_js_1 = require("../utils/base64.js");
23
+ const http_client_js_1 = require("../utils/http-client.js");
24
+ const url_js_1 = require("../utils/url.js");
25
+ const logger_js_1 = require("./logger.js");
26
+ async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)(), }) {
27
+ await signer.setPublicKey?.();
28
+ const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
29
+ let publicKey;
30
+ switch (signer.signatureType) {
31
+ case arbundles_1.SignatureConfig.ARWEAVE:
32
+ publicKey = (0, base64_js_1.toB64Url)(signer.publicKey);
33
+ break;
34
+ case arbundles_1.SignatureConfig.ETHEREUM:
35
+ publicKey = '0x' + signer.publicKey.toString('hex');
36
+ break;
37
+ // TODO: solana sig support
38
+ // case SignatureConfig.SOLANA:
39
+ // case SignatureConfig.ED25519:
40
+ default:
41
+ throw new Error(`Unsupported signer type for signing requests: ${signer.signatureType}`);
42
+ }
43
+ return {
44
+ 'x-public-key': publicKey,
45
+ 'x-nonce': nonce,
46
+ 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
47
+ 'x-signature-type': signer.signatureType,
48
+ };
49
+ }
50
+ exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
51
+ class TurboArNSPaymentProvider {
52
+ paymentUrl;
53
+ axios;
54
+ logger;
55
+ signer;
56
+ constructor({ paymentUrl = 'https://payment.ardrive.io', axios = (0, http_client_js_1.createAxiosInstance)(), logger = logger_js_1.Logger.default, signer, }) {
57
+ this.paymentUrl = paymentUrl;
58
+ this.axios = axios;
59
+ this.logger = logger;
60
+ this.signer = signer;
61
+ }
62
+ async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
63
+ const url = (0, url_js_1.urlWithSearchParams)({
64
+ baseUrl: `${this.paymentUrl}/v1/arns/price/${intent}/${name}`,
65
+ params: {
66
+ increaseQty: quantity,
67
+ type,
68
+ years,
69
+ },
70
+ });
71
+ const { data, status } = await this.axios.get(url);
72
+ this.logger.debug('getArNSPriceDetails', {
73
+ intent,
74
+ name,
75
+ quantity,
76
+ type,
77
+ years,
78
+ data,
79
+ status,
80
+ });
81
+ if (status !== 200) {
82
+ throw new Error('Failed to get ArNS purchase price ' + JSON.stringify(data));
83
+ }
84
+ if (!data.winc || !data.mARIO) {
85
+ throw new Error('Invalid response from Turbo ' + JSON.stringify(data));
86
+ }
87
+ return {
88
+ winc: data.winc,
89
+ mARIO: new token_js_1.mARIOToken(+data.mARIO),
90
+ };
91
+ }
92
+ async getPrice(params) {
93
+ const { winc } = await this.getArNSPriceDetails(params);
94
+ return +winc;
95
+ }
96
+ async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
97
+ if (!this.signer) {
98
+ throw new Error('Signer required for initiating ArNS purchase with Turbo');
99
+ }
100
+ const url = (0, url_js_1.urlWithSearchParams)({
101
+ baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
102
+ params: {
103
+ increaseQty: quantity,
104
+ processId,
105
+ type,
106
+ years,
107
+ },
108
+ });
109
+ const headers = await signedRequestHeadersFromSigner({
110
+ signer: this.signer,
111
+ });
112
+ const { data, status } = await this.axios.post(url, null, {
113
+ headers,
114
+ });
115
+ this.logger.debug('Initiated ArNS purchase', {
116
+ intent,
117
+ name,
118
+ quantity,
119
+ processId,
120
+ type,
121
+ years,
122
+ data,
123
+ status,
124
+ });
125
+ if (status !== 200) {
126
+ throw new Error('Failed to initiate ArNS purchase ' + JSON.stringify(data));
127
+ }
128
+ return {
129
+ id: data.arioWriteResult.id,
130
+ result: data.purchaseReceipt,
131
+ };
132
+ }
133
+ }
134
+ exports.TurboArNSPaymentProvider = TurboArNSPaymentProvider;
@@ -28,7 +28,7 @@ const isValidIntent = (intent) => {
28
28
  return exports.validIntents.indexOf(intent) !== -1;
29
29
  };
30
30
  exports.isValidIntent = isValidIntent;
31
- exports.fundFromOptions = ['balance', 'stakes', 'any'];
31
+ exports.fundFromOptions = ['balance', 'stakes', 'any', 'turbo'];
32
32
  const isValidFundFrom = (fundFrom) => {
33
33
  return exports.fundFromOptions.indexOf(fundFrom) !== -1;
34
34
  };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlWithSearchParams = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const urlWithSearchParams = ({ baseUrl, params, }) => {
20
+ const urlObj = new URL(baseUrl);
21
+ Object.entries(params).forEach(([key, value]) => {
22
+ if (value === undefined || value === null)
23
+ return;
24
+ urlObj.searchParams.set(key, value.toString());
25
+ });
26
+ return urlObj.toString();
27
+ };
28
+ exports.urlWithSearchParams = urlWithSearchParams;
@@ -0,0 +1,24 @@
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
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const node_test_1 = require("node:test");
8
+ const url_js_1 = require("./url.js");
9
+ (0, node_test_1.test)('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
10
+ const result = (0, url_js_1.urlWithSearchParams)({
11
+ baseUrl: 'https://example.com',
12
+ params: {
13
+ number: 1,
14
+ string: 'string',
15
+ boolean: true,
16
+ empty: '',
17
+ zero: 0,
18
+ false: false,
19
+ null: null,
20
+ undef: undefined,
21
+ },
22
+ });
23
+ node_assert_1.default.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
24
+ });
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.9.1-alpha.2';
20
+ exports.version = '3.10.0-alpha.1';
@@ -49,6 +49,10 @@ export const optionMap = {
49
49
  alias: '--cu-url <cuUrl>',
50
50
  description: 'The URL for a custom compute unit',
51
51
  },
52
+ paymentUrl: {
53
+ alias: '--payment-url <paymentUrl>',
54
+ description: 'The URL for a custom turbo payment service',
55
+ },
52
56
  processId: {
53
57
  alias: '--process-id <processId>',
54
58
  description: 'The process ID to interact with',
@@ -269,9 +273,15 @@ export const optionMap = {
269
273
  alias: '--logo <logo>',
270
274
  description: 'The ANT logo',
271
275
  },
276
+ token: {
277
+ alias: '-t, --token <type>',
278
+ description: 'Crypto token type for wallet or action',
279
+ default: 'arweave',
280
+ },
272
281
  };
273
282
  export const walletOptions = [
274
283
  optionMap.walletFile,
284
+ optionMap.token,
275
285
  // optionMap.mnemonic,
276
286
  optionMap.privateKey,
277
287
  ];
@@ -289,6 +299,7 @@ export const arnsPurchaseOptions = [
289
299
  ...writeActionOptions,
290
300
  optionMap.name,
291
301
  optionMap.fundFrom,
302
+ optionMap.paymentUrl,
292
303
  ];
293
304
  export const epochOptions = [optionMap.epochIndex, optionMap.timestamp];
294
305
  export const addressAndVaultIdOptions = [optionMap.address, optionMap.vaultId];
@@ -312,6 +323,7 @@ export const tokenCostOptions = [
312
323
  optionMap.quantity,
313
324
  optionMap.address,
314
325
  optionMap.fundFrom,
326
+ optionMap.paymentUrl,
315
327
  ];
316
328
  export const transferOptions = [
317
329
  ...writeActionOptions,
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { EthereumSigner } from '@dha-team/arbundles';
16
17
  import { connect } from '@permaweb/aoconnect';
17
18
  import { program } from 'commander';
18
19
  import { readFileSync } from 'fs';
@@ -77,7 +78,7 @@ export function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
77
78
  }
78
79
  return ARIO_MAINNET_PROCESS_ID;
79
80
  }
80
- function jwkFromOptions({ privateKey, walletFile, }) {
81
+ function walletFromOptions({ privateKey, walletFile, }) {
81
82
  if (privateKey !== undefined) {
82
83
  return JSON.parse(privateKey);
83
84
  }
@@ -87,7 +88,7 @@ function jwkFromOptions({ privateKey, walletFile, }) {
87
88
  return undefined;
88
89
  }
89
90
  export function requiredJwkFromOptions(options) {
90
- const jwk = jwkFromOptions(options);
91
+ const jwk = walletFromOptions(options);
91
92
  if (jwk === undefined) {
92
93
  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`');
93
94
  }
@@ -117,13 +118,30 @@ export function readARIOFromOptions(options) {
117
118
  setLoggerIfDebug(options);
118
119
  return ARIO.init({
119
120
  process: aoProcessFromOptions(options),
121
+ paymentUrl: options.paymentUrl,
120
122
  });
121
123
  }
122
- export function requiredContractSignerFromOptions(options) {
124
+ export function contractSignerFromOptions(options) {
125
+ const wallet = walletFromOptions(options);
126
+ if (wallet === undefined) {
127
+ return undefined;
128
+ }
129
+ const token = options.token ?? 'arweave';
130
+ if (token === 'ethereum') {
131
+ const signer = new EthereumSigner(wallet);
132
+ // For EthereumSigner, we need to convert the JWK to a string
133
+ return { signer, signerAddress: signer.publicKey.toString('hex') };
134
+ }
123
135
  // TODO: Support other wallet types
124
- const jwk = requiredJwkFromOptions(options);
125
- const signer = new ArweaveSigner(jwk);
126
- return { signer, signerAddress: jwkToAddress(jwk) };
136
+ const signer = new ArweaveSigner(wallet);
137
+ return { signer, signerAddress: jwkToAddress(wallet) };
138
+ }
139
+ export function requiredContractSignerFromOptions(options) {
140
+ const contractSigner = contractSignerFromOptions(options);
141
+ if (contractSigner === undefined) {
142
+ 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`');
143
+ }
144
+ return contractSigner;
127
145
  }
128
146
  export function requiredAoSignerFromOptions(options) {
129
147
  return createAoSigner(requiredContractSignerFromOptions(options).signer);
@@ -135,6 +153,7 @@ export function writeARIOFromOptions(options) {
135
153
  ario: ARIO.init({
136
154
  process: aoProcessFromOptions(options),
137
155
  signer,
156
+ paymentUrl: options.paymentUrl,
138
157
  }),
139
158
  signerAddress,
140
159
  };
@@ -155,10 +174,9 @@ export function addressFromOptions(options) {
155
174
  if (options.address !== undefined) {
156
175
  return options.address;
157
176
  }
158
- // TODO: Support other wallet types
159
- const jwk = jwkFromOptions(options);
160
- if (jwk !== undefined) {
161
- return jwkToAddress(jwk);
177
+ const signer = contractSignerFromOptions(options);
178
+ if (signer !== undefined) {
179
+ return signer.signerAddress;
162
180
  }
163
181
  return undefined;
164
182
  }
@@ -281,6 +299,9 @@ export function requiredMARIOFromOptions(options, key) {
281
299
  return new ARIOToken(+options[key]).toMARIO();
282
300
  }
283
301
  export async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
302
+ if (costDetailsParams.fundFrom === 'turbo') {
303
+ return;
304
+ }
284
305
  const costDetails = await ario.getCostDetails(costDetailsParams);
285
306
  if (costDetails.fundingPlan) {
286
307
  if (costDetails.fundingPlan.shortfall > 0) {
@@ -70,14 +70,14 @@ export class ANTVersionsWritable extends ANTVersionsReadable {
70
70
  super(config);
71
71
  this.signer = createAoSigner(signer);
72
72
  }
73
- async addVersion(params, { tags }) {
73
+ async addVersion({ version, moduleId, luaSourceId, notes, }, { tags }) {
74
74
  return this.process.send({
75
75
  tags: pruneTags([
76
76
  { name: 'Action', value: 'Add-Version' },
77
- { name: 'Version', value: params.version },
78
- { name: 'Module-Id', value: params.moduleId },
79
- { name: 'Lua-Source-Id', value: params.luaSourceId },
80
- { name: 'Notes', value: params.notes },
77
+ { name: 'Version', value: version },
78
+ { name: 'Module-Id', value: moduleId },
79
+ { name: 'Lua-Source-Id', value: luaSourceId },
80
+ { name: 'Notes', value: notes },
81
81
  ...(tags ?? []),
82
82
  ]),
83
83
  signer: this.signer,