@ardrive/turbo-sdk 1.42.0-alpha.11 → 1.42.0-alpha.13

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/lib/cjs/cli/cli.js +31 -0
  2. package/lib/cjs/cli/commands/arns.js +118 -0
  3. package/lib/cjs/cli/options.js +78 -1
  4. package/lib/cjs/common/chunked.js +51 -1
  5. package/lib/cjs/common/http.js +12 -1
  6. package/lib/cjs/common/payment.js +27 -6
  7. package/lib/cjs/common/turbo.js +13 -5
  8. package/lib/cjs/common/upload.js +23 -12
  9. package/lib/cjs/types.js +1 -1
  10. package/lib/esm/cli/cli.js +33 -2
  11. package/lib/esm/cli/commands/arns.js +111 -0
  12. package/lib/esm/cli/options.js +77 -0
  13. package/lib/esm/common/chunked.js +51 -1
  14. package/lib/esm/common/http.js +12 -1
  15. package/lib/esm/common/payment.js +27 -6
  16. package/lib/esm/common/turbo.js +13 -5
  17. package/lib/esm/common/upload.js +23 -12
  18. package/lib/esm/types.js +1 -1
  19. package/lib/types/cli/commands/arns.d.ts +49 -2
  20. package/lib/types/cli/commands/arns.d.ts.map +1 -1
  21. package/lib/types/cli/options.d.ts +172 -0
  22. package/lib/types/cli/options.d.ts.map +1 -1
  23. package/lib/types/cli/types.d.ts +30 -0
  24. package/lib/types/cli/types.d.ts.map +1 -1
  25. package/lib/types/common/chunked.d.ts +47 -2
  26. package/lib/types/common/chunked.d.ts.map +1 -1
  27. package/lib/types/common/http.d.ts +11 -1
  28. package/lib/types/common/http.d.ts.map +1 -1
  29. package/lib/types/common/payment.d.ts +24 -7
  30. package/lib/types/common/payment.d.ts.map +1 -1
  31. package/lib/types/common/turbo.d.ts +12 -6
  32. package/lib/types/common/turbo.d.ts.map +1 -1
  33. package/lib/types/common/upload.d.ts.map +1 -1
  34. package/lib/types/types.d.ts +22 -1
  35. package/lib/types/types.d.ts.map +1 -1
  36. package/package.json +1 -1
@@ -147,6 +147,37 @@ const utils_js_1 = require("./utils.js");
147
147
  .description('Remove a resolution record (undername) from a Turbo-custodied ANT'), options_js_1.removeArNSRecordOptions).action(async (_commandOptions, command) => {
148
148
  await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecord);
149
149
  });
150
+ (0, utils_js_1.applyOptions)(commander_1.program
151
+ .command('add-arns-controller')
152
+ .description('Grant controller rights on a Turbo-custodied ANT'), options_js_1.addArNSControllerOptions).action(async (_commandOptions, command) => {
153
+ await (0, utils_js_1.runCommand)(command, arns_js_1.addArNSController);
154
+ });
155
+ (0, utils_js_1.applyOptions)(commander_1.program
156
+ .command('remove-arns-controller')
157
+ .description('Revoke controller rights on a Turbo-custodied ANT'), options_js_1.removeArNSControllerOptions).action(async (_commandOptions, command) => {
158
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSController);
159
+ });
160
+ (0, utils_js_1.applyOptions)(commander_1.program
161
+ .command('transfer-arns-record')
162
+ .description('Transfer one record (undername) on a Turbo-custodied ANT to another address'), options_js_1.transferArNSRecordOptions).action(async (_commandOptions, command) => {
163
+ await (0, utils_js_1.runCommand)(command, arns_js_1.transferArNSRecord);
164
+ });
165
+ (0, utils_js_1.applyOptions)(commander_1.program
166
+ .command('set-arns-record-metadata')
167
+ .description("Set a record's display name, logo, description, or keywords on a Turbo-custodied ANT"), options_js_1.setArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
168
+ await (0, utils_js_1.runCommand)(command, arns_js_1.setArNSRecordMetadata);
169
+ });
170
+ (0, utils_js_1.applyOptions)(commander_1.program
171
+ .command('remove-arns-record-metadata')
172
+ .description("Clear a record's metadata on a Turbo-custodied ANT"), options_js_1.removeArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
173
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecordMetadata);
174
+ });
175
+ (0, utils_js_1.applyOptions)(commander_1.program
176
+ .command('arns-action-price')
177
+ .description('Preview the Turbo Credit price of a non-purchase ArNS action (set-record, remove-record, ' +
178
+ 'set-record-metadata, remove-record-metadata, transfer-record, add-controller, remove-controller, transfer)'), options_js_1.arnsActionPriceOptions).action(async (_commandOptions, command) => {
179
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsActionPrice);
180
+ });
150
181
  (0, utils_js_1.applyOptions)(commander_1.program
151
182
  .command('inspect-data-items')
152
183
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), [options_js_1.optionMap.folderPath]).action(async (_commandOptions, command) => {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requiredNameFromOptions = requiredNameFromOptions;
4
4
  exports.positiveIntFromOption = positiveIntFromOption;
5
5
  exports.typeFromOptions = typeFromOptions;
6
+ exports.actionFromOptions = actionFromOptions;
6
7
  exports.paidByFromArNSOptions = paidByFromArNSOptions;
7
8
  exports.arnsPriceParamsFromOptions = arnsPriceParamsFromOptions;
8
9
  exports.arnsPrice = arnsPrice;
@@ -15,6 +16,12 @@ exports.arnsPurchaseStatus = arnsPurchaseStatus;
15
16
  exports.transferArNSAnt = transferArNSAnt;
16
17
  exports.setArNSRecord = setArNSRecord;
17
18
  exports.removeArNSRecord = removeArNSRecord;
19
+ exports.addArNSController = addArNSController;
20
+ exports.removeArNSController = removeArNSController;
21
+ exports.transferArNSRecord = transferArNSRecord;
22
+ exports.setArNSRecordMetadata = setArNSRecordMetadata;
23
+ exports.removeArNSRecordMetadata = removeArNSRecordMetadata;
24
+ exports.arnsActionPrice = arnsActionPrice;
18
25
  /**
19
26
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
20
27
  *
@@ -33,6 +40,7 @@ exports.removeArNSRecord = removeArNSRecord;
33
40
  const bignumber_js_1 = require("bignumber.js");
34
41
  const arnsActions_js_1 = require("../../common/arnsActions.js");
35
42
  const factory_js_1 = require("../../node/factory.js");
43
+ const types_js_1 = require("../../types.js");
36
44
  const errors_js_1 = require("../../utils/errors.js");
37
45
  const constants_js_1 = require("../constants.js");
38
46
  const utils_js_1 = require("../utils.js");
@@ -51,6 +59,13 @@ function ownerFromOptions(options) {
51
59
  }
52
60
  return (0, arnsActions_js_1.solanaOwnerSigner)(options.ownerKey);
53
61
  }
62
+ /** The four ARIO-purchase actions are priced via `arnsPrice`, not this route. */
63
+ const ARNS_PURCHASE_ACTIONS = new Set([
64
+ 'buy-name',
65
+ 'extend-lease',
66
+ 'upgrade-name',
67
+ 'increase-undername-limit',
68
+ ]);
54
69
  function requiredNameFromOptions(options) {
55
70
  if (options.name === undefined || options.name.length === 0) {
56
71
  throw new Error('Must provide an ArNS --name');
@@ -73,6 +88,25 @@ function typeFromOptions(value) {
73
88
  }
74
89
  return value;
75
90
  }
91
+ /** Parses `--action` for `arns-action-price`, rejecting the four purchase actions. */
92
+ function actionFromOptions(options) {
93
+ const { action } = options;
94
+ if (action === undefined || action.length === 0) {
95
+ throw new Error(`Must provide --action. One of: ${types_js_1.arNSActions.join(', ')}`);
96
+ }
97
+ if (!types_js_1.arNSActions.includes(action)) {
98
+ throw new Error(`Invalid --action '${action}'. One of: ${types_js_1.arNSActions.join(', ')}`);
99
+ }
100
+ if (ARNS_PURCHASE_ACTIONS.has(action)) {
101
+ throw new Error(`'${action}' is priced via \`turbo arns-price\`, not \`arns-action-price\` — ` +
102
+ 'it spends ARIO, not just the flat credits margin this route quotes.');
103
+ }
104
+ return action;
105
+ }
106
+ /** `null` clears the field (Set-Record-Metadata's tri-state), `undefined` leaves it unchanged. */
107
+ function metadataFieldFromOptions(value, clear) {
108
+ return clear ? null : value;
109
+ }
76
110
  function paidByFromArNSOptions(paidBy) {
77
111
  return paidBy !== undefined && paidBy.length > 0 ? paidBy : undefined;
78
112
  }
@@ -315,3 +349,87 @@ async function removeArNSRecord(options, turbo) {
315
349
  });
316
350
  console.log(JSON.stringify({ message: 'ArNS record removed!', ...result }, null, 2));
317
351
  }
352
+ async function addArNSController(options, turbo) {
353
+ if (options.antId === undefined) {
354
+ throw new Error('Must provide an --ant-id to add a controller to');
355
+ }
356
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
357
+ const result = await client.addArNSController({
358
+ antId: options.antId,
359
+ owner: ownerFromOptions(options),
360
+ target: options.target,
361
+ });
362
+ console.log(JSON.stringify({ message: 'ArNS controller added!', ...result }, null, 2));
363
+ }
364
+ async function removeArNSController(options, turbo) {
365
+ if (options.antId === undefined) {
366
+ throw new Error('Must provide an --ant-id to remove a controller from');
367
+ }
368
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
369
+ const result = await client.removeArNSController({
370
+ antId: options.antId,
371
+ owner: ownerFromOptions(options),
372
+ target: options.target,
373
+ });
374
+ console.log(JSON.stringify({ message: 'ArNS controller removed!', ...result }, null, 2));
375
+ }
376
+ async function transferArNSRecord(options, turbo) {
377
+ if (options.antId === undefined) {
378
+ throw new Error('Must provide an --ant-id whose record to transfer');
379
+ }
380
+ if (options.undername === undefined || options.undername.length === 0) {
381
+ throw new Error('Must provide an --undername to transfer');
382
+ }
383
+ if (options.target === undefined) {
384
+ throw new Error('Must provide a --target address to transfer the record to');
385
+ }
386
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
387
+ const result = await client.transferArNSRecord({
388
+ antId: options.antId,
389
+ owner: ownerFromOptions(options),
390
+ undername: options.undername,
391
+ target: options.target,
392
+ });
393
+ console.log(JSON.stringify({ message: 'ArNS record transferred!', ...result }, null, 2));
394
+ }
395
+ async function setArNSRecordMetadata(options, turbo) {
396
+ if (options.antId === undefined) {
397
+ throw new Error('Must provide an --ant-id to set record metadata on');
398
+ }
399
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
400
+ const result = await client.setArNSRecordMetadata({
401
+ antId: options.antId,
402
+ owner: ownerFromOptions(options),
403
+ undername: options.undername ?? '@',
404
+ displayName: metadataFieldFromOptions(options.displayName, options.clearDisplayName),
405
+ recordLogo: metadataFieldFromOptions(options.recordLogo, options.clearRecordLogo),
406
+ recordDescription: metadataFieldFromOptions(options.recordDescription, options.clearRecordDescription),
407
+ recordKeywords: metadataFieldFromOptions(options.recordKeywords, options.clearRecordKeywords),
408
+ });
409
+ console.log(JSON.stringify({ message: 'ArNS record metadata set!', ...result }, null, 2));
410
+ }
411
+ async function removeArNSRecordMetadata(options, turbo) {
412
+ if (options.antId === undefined) {
413
+ throw new Error('Must provide an --ant-id to remove record metadata from');
414
+ }
415
+ if (options.undername === undefined || options.undername.length === 0) {
416
+ throw new Error('Must provide an --undername');
417
+ }
418
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
419
+ const result = await client.removeArNSRecordMetadata({
420
+ antId: options.antId,
421
+ owner: ownerFromOptions(options),
422
+ undername: options.undername,
423
+ });
424
+ console.log(JSON.stringify({ message: 'ArNS record metadata removed!', ...result }, null, 2));
425
+ }
426
+ /**
427
+ * Preview what one of the eight non-purchase actions will debit, without
428
+ * creating it.
429
+ */
430
+ async function arnsActionPrice(options, turbo) {
431
+ const action = actionFromOptions(options);
432
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
433
+ const { wincQty } = await client.getArNSActionPrice(action);
434
+ console.log(JSON.stringify({ action, wincQty, credits: creditsFromWinc(wincQty) }, null, 2));
435
+ }
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.removeArNSRecordOptions = exports.setArNSRecordOptions = exports.transferArNSAntOptions = exports.arnsPurchaseStatusOptions = exports.upgradeArNSNameOptions = exports.increaseArNSUndernamesOptions = exports.extendArNSLeaseOptions = exports.buyArNSNameOptions = exports.arnsFiatQuoteOptions = exports.arnsPriceOptions = exports.listSharesOptions = exports.revokeCreditsOptions = exports.shareCreditsOptions = exports.uploadFileOptions = exports.uploadFolderOptions = exports.uploadOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
18
+ exports.arnsActionPriceOptions = exports.removeArNSRecordMetadataOptions = exports.setArNSRecordMetadataOptions = exports.transferArNSRecordOptions = exports.removeArNSControllerOptions = exports.addArNSControllerOptions = exports.removeArNSRecordOptions = exports.setArNSRecordOptions = exports.transferArNSAntOptions = exports.arnsPurchaseStatusOptions = exports.upgradeArNSNameOptions = exports.increaseArNSUndernamesOptions = exports.extendArNSLeaseOptions = exports.buyArNSNameOptions = exports.arnsFiatQuoteOptions = exports.arnsPriceOptions = exports.listSharesOptions = exports.revokeCreditsOptions = exports.shareCreditsOptions = exports.uploadFileOptions = exports.uploadFolderOptions = exports.uploadOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
19
19
  exports.optionMap = {
20
20
  token: {
21
21
  alias: '-t, --token <type>',
@@ -234,6 +234,48 @@ exports.optionMap = {
234
234
  alias: '--ttl-seconds <ttlSeconds>',
235
235
  description: 'TTL in seconds for the ArNS record',
236
236
  },
237
+ arnsDisplayName: {
238
+ alias: '--display-name <displayName>',
239
+ description: 'Display name for the record (Set-Record-Metadata)',
240
+ },
241
+ arnsClearDisplayName: {
242
+ alias: '--clear-display-name',
243
+ description: 'Clear the record display name (Set-Record-Metadata)',
244
+ default: false,
245
+ },
246
+ arnsRecordLogo: {
247
+ alias: '--record-logo <transactionId>',
248
+ description: 'Arweave transaction ID for the record logo (Set-Record-Metadata)',
249
+ },
250
+ arnsClearRecordLogo: {
251
+ alias: '--clear-record-logo',
252
+ description: 'Clear the record logo (Set-Record-Metadata)',
253
+ default: false,
254
+ },
255
+ arnsRecordDescription: {
256
+ alias: '--record-description <description>',
257
+ description: 'Description for the record (Set-Record-Metadata)',
258
+ },
259
+ arnsClearRecordDescription: {
260
+ alias: '--clear-record-description',
261
+ description: 'Clear the record description (Set-Record-Metadata)',
262
+ default: false,
263
+ },
264
+ arnsRecordKeywords: {
265
+ alias: '--record-keywords <keywords...>',
266
+ description: 'Keywords for the record (Set-Record-Metadata)',
267
+ type: 'array',
268
+ },
269
+ arnsClearRecordKeywords: {
270
+ alias: '--clear-record-keywords',
271
+ description: 'Clear the record keywords (Set-Record-Metadata)',
272
+ default: false,
273
+ },
274
+ arnsAction: {
275
+ alias: '--action <action>',
276
+ description: 'ArNS action to price: set-record, remove-record, set-record-metadata, ' +
277
+ 'remove-record-metadata, transfer-record, add-controller, remove-controller, or transfer',
278
+ },
237
279
  // ---- Payment history ----
238
280
  limit: {
239
281
  alias: '--limit <limit>',
@@ -365,3 +407,38 @@ exports.removeArNSRecordOptions = [
365
407
  exports.optionMap.arnsAntId,
366
408
  exports.optionMap.arnsUndername,
367
409
  ];
410
+ exports.addArNSControllerOptions = [
411
+ ...exports.walletOptions,
412
+ exports.optionMap.arnsOwnerKey,
413
+ exports.optionMap.arnsAntId,
414
+ exports.optionMap.arnsTarget,
415
+ ];
416
+ exports.removeArNSControllerOptions = exports.addArNSControllerOptions;
417
+ exports.transferArNSRecordOptions = [
418
+ ...exports.walletOptions,
419
+ exports.optionMap.arnsOwnerKey,
420
+ exports.optionMap.arnsAntId,
421
+ exports.optionMap.arnsUndername,
422
+ exports.optionMap.arnsTarget,
423
+ ];
424
+ exports.setArNSRecordMetadataOptions = [
425
+ ...exports.walletOptions,
426
+ exports.optionMap.arnsOwnerKey,
427
+ exports.optionMap.arnsAntId,
428
+ exports.optionMap.arnsUndername,
429
+ exports.optionMap.arnsDisplayName,
430
+ exports.optionMap.arnsClearDisplayName,
431
+ exports.optionMap.arnsRecordLogo,
432
+ exports.optionMap.arnsClearRecordLogo,
433
+ exports.optionMap.arnsRecordDescription,
434
+ exports.optionMap.arnsClearRecordDescription,
435
+ exports.optionMap.arnsRecordKeywords,
436
+ exports.optionMap.arnsClearRecordKeywords,
437
+ ];
438
+ exports.removeArNSRecordMetadataOptions = [
439
+ ...exports.walletOptions,
440
+ exports.optionMap.arnsOwnerKey,
441
+ exports.optionMap.arnsAntId,
442
+ exports.optionMap.arnsUndername,
443
+ ];
444
+ exports.arnsActionPriceOptions = [exports.optionMap.arnsAction];
@@ -41,7 +41,7 @@ const chunkingHeader = { 'x-chunking-version': '2' };
41
41
  * uploading them in parallel, and emitting progress/error events.
42
42
  */
43
43
  class ChunkedUploader {
44
- constructor({ http, token, maxChunkConcurrency = exports.defaultMaxChunkConcurrency, maxFinalizeMs, chunkByteCount = exports.defaultChunkByteCount, logger = logger_js_1.Logger.default, chunkingMode = 'auto', dataItemByteCount, }) {
44
+ constructor({ http, token, maxChunkConcurrency = exports.defaultMaxChunkConcurrency, maxFinalizeMs, chunkByteCount = exports.defaultChunkByteCount, logger = logger_js_1.Logger.default, chunkingMode = 'auto', dataItemByteCount, x402, x402RefundIdentity, }) {
45
45
  this.assertChunkParams({
46
46
  chunkByteCount,
47
47
  chunkingMode,
@@ -60,6 +60,9 @@ class ChunkedUploader {
60
60
  dataItemByteCount,
61
61
  });
62
62
  this.maxBacklogQueue = this.maxChunkConcurrency * backlogQueueFactor;
63
+ this.x402 = x402;
64
+ this.x402RefundIdentity = x402RefundIdentity;
65
+ this.dataItemByteCount = dataItemByteCount;
63
66
  }
64
67
  shouldChunkUpload({ chunkByteCount, chunkingMode, dataItemByteCount, }) {
65
68
  if (chunkingMode === 'disabled') {
@@ -98,7 +101,54 @@ class ChunkedUploader {
98
101
  /**
99
102
  * Initialize or resume an upload session, returning the upload ID.
100
103
  */
104
+ /**
105
+ * Open a multipart upload paid for with x402.
106
+ *
107
+ * The bundler settles the payment at CREATE, before accepting a single chunk
108
+ * — so an unpaid upload never consumes storage. That is why the size is
109
+ * declared here and the money moves here, not at finalize.
110
+ *
111
+ * The 402 handshake is delegated to `wrapFetchWithPayment`, the same
112
+ * mechanism the single-shot x402 POST already uses, so the signer and the
113
+ * spend cap behave identically on both paths.
114
+ */
115
+ async initPaidUpload(x402) {
116
+ if (this.paidUploadId !== undefined) {
117
+ this.logger.debug('Resuming the already-paid chunked upload', {
118
+ uploadId: this.paidUploadId,
119
+ });
120
+ return this.paidUploadId;
121
+ }
122
+ if (this.x402RefundIdentity === undefined) {
123
+ throw new Error('An x402-paid chunked upload needs a refund identity — it is the Turbo wallet credited if the upload delivers fewer bytes than were paid for.');
124
+ }
125
+ const { address, signatureType } = this.x402RefundIdentity;
126
+ const endpoint = `/chunks/${this.token}/-1/-1?chunkSize=${this.chunkByteCount}` +
127
+ `&totalBytes=${this.dataItemByteCount}` +
128
+ `&address=${encodeURIComponent(address)}` +
129
+ `&signatureType=${signatureType}`;
130
+ this.logger.debug('Opening an x402-paid chunked upload', {
131
+ totalBytes: this.dataItemByteCount,
132
+ });
133
+ const res = await this.http.get({
134
+ endpoint: endpoint,
135
+ headers: chunkingHeader,
136
+ x402Options: x402,
137
+ });
138
+ if (res.chunkSize !== undefined && res.chunkSize !== this.chunkByteCount) {
139
+ this.logger.warn('Chunk size mismatch! Overriding with server value.', {
140
+ clientExpected: this.chunkByteCount,
141
+ serverReturned: res.chunkSize,
142
+ });
143
+ this.chunkByteCount = res.chunkSize;
144
+ }
145
+ this.paidUploadId = res.id;
146
+ return res.id;
147
+ }
101
148
  async initUpload() {
149
+ if (this.x402 !== undefined) {
150
+ return this.initPaidUpload(this.x402);
151
+ }
102
152
  const res = await this.http.get({
103
153
  endpoint: `/chunks/${this.token}/-1/-1?chunkSize=${this.chunkByteCount}`,
104
154
  headers: chunkingHeader,
@@ -52,7 +52,18 @@ class TurboHTTPService {
52
52
  this.baseURL = url;
53
53
  this.retryConfig = retryConfig;
54
54
  }
55
- async get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
55
+ async get({ endpoint, signal, allowedStatuses = [200, 202], headers, x402Options, }) {
56
+ if (x402Options !== undefined) {
57
+ const maxMUSDCAmount = x402Options.maxMUSDCAmount !== undefined
58
+ ? BigInt(x402Options.maxMUSDCAmount.toString())
59
+ : undefined;
60
+ const fetchWithPay = (0, x402_fetch_1.wrapFetchWithPayment)(fetch, x402Options.signer, maxMUSDCAmount);
61
+ return this.tryRequest(async () => fetchWithPay(this.baseURL + endpoint, {
62
+ method: 'GET',
63
+ headers: { ...defaultHeaders, ...headers },
64
+ signal,
65
+ }), allowedStatuses);
66
+ }
56
67
  return this.withRetry(() => fetch(this.baseURL + endpoint, {
57
68
  method: 'GET',
58
69
  headers: { ...defaultHeaders, ...headers },
@@ -140,6 +140,24 @@ class TurboUnauthenticatedPaymentService {
140
140
  wincTotal: price.wincTotalWithAntSpawn ?? price.winc,
141
141
  };
142
142
  }
143
+ /**
144
+ * Preview the flat credits margin one of the eight non-purchase actions
145
+ * (everything except Buy-Name/Extend-Lease/Upgrade-Name/
146
+ * Increase-Undername-Limit) will debit, without creating it. Those four
147
+ * purchase actions are priced by `getArNSPriceForName` instead — their
148
+ * cost is dominated by the ARIO purchase, not this margin, so this route
149
+ * rejects them.
150
+ *
151
+ * No signature required: this mirrors `getArNSPriceForName`'s read-only,
152
+ * unauthenticated shape rather than `getArNSActionStatus`'s (which happens
153
+ * to live on the authenticated client today despite needing no signature
154
+ * either).
155
+ */
156
+ async getArNSActionPrice(action) {
157
+ return this.httpService.get({
158
+ endpoint: `/arns/actions/${action}/price`,
159
+ });
160
+ }
143
161
  /**
144
162
  * Fail fast (client-side) on malformed ArNS requests so JS callers that bypass
145
163
  * the compile-time intent unions get a clear `ProvidedInputError` instead of an
@@ -663,7 +681,7 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
663
681
  /**
664
682
  * Point a name (or undername) at an Arweave transaction.
665
683
  *
666
- * FreeTurbo sponsors the Solana fee. Completes in one call while Turbo is
684
+ * Costs a small credit margin never SOL, which Turbo sponsors. Completes in one call while Turbo is
667
685
  * a controller of the ANT, and returns `awaiting-signature` once the customer
668
686
  * has revoked Turbo, at which point `owner` signs it themselves. Both paths
669
687
  * are handled here.
@@ -687,14 +705,15 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
687
705
  String(ttlSeconds),
688
706
  ]));
689
707
  }
690
- /** Remove a record (an undername). Free; same two-shape rules as setArNSRecord. */
708
+ /** Remove a record (an undername). Costs credits, never SOL. */
691
709
  async removeArNSRecord({ antId, owner, undername, onNonce, }) {
692
710
  return this.completeArNSAction('remove-record', { antId, ownerAddress: await owner.getAddress(), undername }, owner, { onNonce }, (0, arnsActions_js_1.buildArNSCustodyMessage)('remove-record', [antId, undername]));
693
711
  }
694
712
  /**
695
713
  * Edit a RECORD's metadata — its display name, logo, description, keywords.
696
714
  *
697
- * Free, and owner-or-controller on chain, so it behaves exactly like
715
+ * Costs a small credit margin (never SOL), and is owner-or-controller on
716
+ * chain, so it behaves exactly like
698
717
  * {@link setArNSRecord}: Turbo-alone while it is a controller, owner-signed
699
718
  * after a revoke.
700
719
  *
@@ -726,7 +745,7 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
726
745
  (0, arnsActions_js_1.arNSKeywordsField)(recordKeywords),
727
746
  ]));
728
747
  }
729
- /** Clear a record's metadata. Free; same two-shape rules. */
748
+ /** Clear a record's metadata. Costs credits, never SOL; same two-shape rules. */
730
749
  async removeArNSRecordMetadata({ antId, owner, undername, onNonce, }) {
731
750
  return this.completeArNSAction('remove-record-metadata', { antId, ownerAddress: await owner.getAddress(), undername }, owner, { onNonce }, (0, arnsActions_js_1.buildArNSCustodyMessage)('remove-record-metadata', [antId, undername]));
732
751
  }
@@ -744,7 +763,8 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
744
763
  * is what makes `setArNSRecord` a single call.
745
764
  *
746
765
  * Owner-signed: changing an ANT's access control is an owner-only
747
- * instruction. Free to the customer Turbo funds the ACL page growth.
766
+ * instruction. Costs a small credit margin; Turbo funds the ACL page growth
767
+ * in SOL.
748
768
  */
749
769
  async addArNSController({ antId, owner, target, onNonce, }) {
750
770
  return this.completeArNSAction('add-controller', {
@@ -757,7 +777,8 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
757
777
  * Revoke controller rights — the escape hatch that keeps "Turbo is not a
758
778
  * custodian" honest.
759
779
  *
760
- * Always available, always free, and needs nothing from Turbo but the fee.
780
+ * Always available, and needs nothing from Turbo but the fee. Costs a small
781
+ * credit margin rather than SOL.
761
782
  * After revoking, `setArNSRecord` keeps working: it simply starts returning
762
783
  * `awaiting-signature` so the owner signs their own record writes.
763
784
  */
@@ -63,6 +63,14 @@ class TurboUnauthenticatedClient {
63
63
  getArNSPriceForName(params) {
64
64
  return this.paymentService.getArNSPriceForName(params);
65
65
  }
66
+ /**
67
+ * Previews what one of the eight non-purchase ArNS actions will debit,
68
+ * without creating it. Use {@link getArNSPriceForName} for the four
69
+ * ARIO-purchase actions instead.
70
+ */
71
+ getArNSActionPrice(action) {
72
+ return this.paymentService.getArNSActionPrice(action);
73
+ }
66
74
  /**
67
75
  * Returns the status of an ArNS purchase by its nonce.
68
76
  */
@@ -270,11 +278,11 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
270
278
  removeArNSRecord(params) {
271
279
  return this.paymentService.removeArNSRecord(params);
272
280
  }
273
- /** Grant controller rights — omit `target` for Turbo itself. Free. */
281
+ /** Grant controller rights — omit `target` for Turbo itself. Costs credits. */
274
282
  addArNSController(params) {
275
283
  return this.paymentService.addArNSController(params);
276
284
  }
277
- /** Revoke controller rights. Always available, always free. */
285
+ /** Revoke controller rights. Always available; costs credits, never SOL. */
278
286
  removeArNSController(params) {
279
287
  return this.paymentService.removeArNSController(params);
280
288
  }
@@ -286,15 +294,15 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
286
294
  setArNSRecordMetadata(params) {
287
295
  return this.paymentService.setArNSRecordMetadata(params);
288
296
  }
289
- /** Clear a record's metadata. Free; handles both shapes. */
297
+ /** Clear a record's metadata. Costs credits, never SOL; handles both shapes. */
290
298
  removeArNSRecordMetadata(params) {
291
299
  return this.paymentService.removeArNSRecordMetadata(params);
292
300
  }
293
- /** Hand ONE record over — not the whole ANT. Free; handles both shapes. */
301
+ /** Hand ONE record over — not the whole ANT. Costs credits, never SOL. */
294
302
  transferArNSRecord(params) {
295
303
  return this.paymentService.transferArNSRecord(params);
296
304
  }
297
- /** Hand the ANT to a new owner. Irreversible. Free. */
305
+ /** Hand the ANT to a new owner. Irreversible. Costs credits, never SOL. */
298
306
  transferArNSAnt(params) {
299
307
  return this.paymentService.transferArNSAnt(params);
300
308
  }
@@ -225,9 +225,6 @@ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadServ
225
225
  !this.x402EnabledTokens.includes(this.token)) {
226
226
  throw new Error('x402 uploads are not supported for token: ' + this.token);
227
227
  }
228
- if (params.chunkingMode === 'force' && fundingMode instanceof types_js_1.X402Funding) {
229
- throw new Error("Chunking mode 'force' is not supported when x402 is enabled");
230
- }
231
228
  this.logger.debug('Starting file upload', { params });
232
229
  let retries = 0;
233
230
  const maxRetries = this.retryConfig.retries ?? 3;
@@ -263,6 +260,19 @@ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadServ
263
260
  // this result due to the wrapped retry logic of this method.
264
261
  try {
265
262
  const { chunkByteCount, maxChunkConcurrency } = params;
263
+ // Built here rather than after the chunked branch so BOTH paths can
264
+ // pay with it. Chunked x402 uploads used to be impossible — the
265
+ // bundler had no way to charge for a multipart upload — so this branch
266
+ // deliberately fell back to a single request, which capped x402 at the
267
+ // single-item limit no matter how the client chunked. The bundler now
268
+ // settles at create, so the fallback is no longer needed.
269
+ const x402Options = fundingMode instanceof types_js_1.X402Funding
270
+ ? {
271
+ signer: fundingMode.signer ??
272
+ (await (0, signer_js_1.makeX402Signer)(this.signer.signer)),
273
+ maxMUSDCAmount: fundingMode.maxMUSDCAmount,
274
+ }
275
+ : undefined;
266
276
  const chunkedUploader = new chunked_js_1.ChunkedUploader({
267
277
  http: this.httpService,
268
278
  token: this.token,
@@ -272,9 +282,17 @@ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadServ
272
282
  dataItemByteCount: dataItemSizeFactory(),
273
283
  chunkingMode: params.chunkingMode,
274
284
  maxFinalizeMs: params.maxFinalizeMs,
285
+ ...(x402Options ? { x402: x402Options } : {}),
286
+ ...(x402Options
287
+ ? {
288
+ x402RefundIdentity: {
289
+ address: await this.signer.getNativeAddress(),
290
+ signatureType: this.signer.signer.signatureType,
291
+ },
292
+ }
293
+ : {}),
275
294
  });
276
- if (chunkedUploader.shouldUseChunkUploader &&
277
- !(fundingMode instanceof types_js_1.X402Funding)) {
295
+ if (chunkedUploader.shouldUseChunkUploader) {
278
296
  const response = await chunkedUploader.upload({
279
297
  dataItemStreamFactory,
280
298
  dataItemSizeFactory,
@@ -284,13 +302,6 @@ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadServ
284
302
  });
285
303
  return { ...response, cryptoFundResult };
286
304
  }
287
- const x402Options = fundingMode instanceof types_js_1.X402Funding
288
- ? {
289
- signer: fundingMode.signer ??
290
- (await (0, signer_js_1.makeX402Signer)(this.signer.signer)),
291
- maxMUSDCAmount: fundingMode.maxMUSDCAmount,
292
- }
293
- : undefined;
294
305
  const response = await this.uploadSignedDataItem({
295
306
  dataItemStreamFactory,
296
307
  dataItemSizeFactory,
package/lib/cjs/types.js CHANGED
@@ -115,7 +115,7 @@ exports.arNSPurchaseIntents = [
115
115
  ];
116
116
  // ===== ArNS actions (sponsored — the current bundler surface) =====
117
117
  /**
118
- * The nine sponsored ArNS actions.
118
+ * The twelve sponsored ArNS actions.
119
119
  *
120
120
  * Sponsorship covers these twelve and NOTHING else. Everything else in the
121
121
  * ArNS, ANT and core programs stays on the direct-signer path and costs the
@@ -20,7 +20,7 @@ import { DataItem } from '@dha-team/arbundles';
20
20
  import { program } from 'commander';
21
21
  import { readFileSync, readdirSync } from 'fs';
22
22
  import { version } from '../version.js';
23
- import { arnsFiatQuote, arnsPrice, arnsPurchaseStatus, buyArNSName, extendArNSLease, increaseArNSUndernames, removeArNSRecord, setArNSRecord, transferArNSAnt, upgradeArNSName, } from './commands/arns.js';
23
+ import { addArNSController, arnsActionPrice, arnsFiatQuote, arnsPrice, arnsPurchaseStatus, buyArNSName, extendArNSLease, increaseArNSUndernames, removeArNSController, removeArNSRecord, removeArNSRecordMetadata, setArNSRecord, setArNSRecordMetadata, transferArNSAnt, transferArNSRecord, upgradeArNSName, } from './commands/arns.js';
24
24
  import { fiatEstimate } from './commands/fiatEstimate.js';
25
25
  import { balance, cryptoFund, freeStatus, paymentHistory, price, topUp, uploadFile, uploadFolder, } from './commands/index.js';
26
26
  import { listShares } from './commands/listShares.js';
@@ -28,7 +28,7 @@ import { revokeCredits } from './commands/revokeCredits.js';
28
28
  import { shareCredits } from './commands/shareCredits.js';
29
29
  import { tokenPrice } from './commands/tokenPrice.js';
30
30
  import { x402UploadUnsignedFile } from './commands/x402UploadUnsignedData.js';
31
- import { arnsFiatQuoteOptions, arnsPriceOptions, arnsPurchaseStatusOptions, buyArNSNameOptions, extendArNSLeaseOptions, globalOptions, increaseArNSUndernamesOptions, listSharesOptions, optionMap, removeArNSRecordOptions, revokeCreditsOptions, setArNSRecordOptions, shareCreditsOptions, transferArNSAntOptions, upgradeArNSNameOptions, uploadFileOptions, uploadFolderOptions, walletOptions, } from './options.js';
31
+ import { addArNSControllerOptions, arnsActionPriceOptions, arnsFiatQuoteOptions, arnsPriceOptions, arnsPurchaseStatusOptions, buyArNSNameOptions, extendArNSLeaseOptions, globalOptions, increaseArNSUndernamesOptions, listSharesOptions, optionMap, removeArNSControllerOptions, removeArNSRecordMetadataOptions, removeArNSRecordOptions, revokeCreditsOptions, setArNSRecordMetadataOptions, setArNSRecordOptions, shareCreditsOptions, transferArNSAntOptions, transferArNSRecordOptions, upgradeArNSNameOptions, uploadFileOptions, uploadFolderOptions, walletOptions, } from './options.js';
32
32
  import { applyOptions, runCommand } from './utils.js';
33
33
  applyOptions(program
34
34
  .name('turbo')
@@ -145,6 +145,37 @@ applyOptions(program
145
145
  .description('Remove a resolution record (undername) from a Turbo-custodied ANT'), removeArNSRecordOptions).action(async (_commandOptions, command) => {
146
146
  await runCommand(command, removeArNSRecord);
147
147
  });
148
+ applyOptions(program
149
+ .command('add-arns-controller')
150
+ .description('Grant controller rights on a Turbo-custodied ANT'), addArNSControllerOptions).action(async (_commandOptions, command) => {
151
+ await runCommand(command, addArNSController);
152
+ });
153
+ applyOptions(program
154
+ .command('remove-arns-controller')
155
+ .description('Revoke controller rights on a Turbo-custodied ANT'), removeArNSControllerOptions).action(async (_commandOptions, command) => {
156
+ await runCommand(command, removeArNSController);
157
+ });
158
+ applyOptions(program
159
+ .command('transfer-arns-record')
160
+ .description('Transfer one record (undername) on a Turbo-custodied ANT to another address'), transferArNSRecordOptions).action(async (_commandOptions, command) => {
161
+ await runCommand(command, transferArNSRecord);
162
+ });
163
+ applyOptions(program
164
+ .command('set-arns-record-metadata')
165
+ .description("Set a record's display name, logo, description, or keywords on a Turbo-custodied ANT"), setArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
166
+ await runCommand(command, setArNSRecordMetadata);
167
+ });
168
+ applyOptions(program
169
+ .command('remove-arns-record-metadata')
170
+ .description("Clear a record's metadata on a Turbo-custodied ANT"), removeArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
171
+ await runCommand(command, removeArNSRecordMetadata);
172
+ });
173
+ applyOptions(program
174
+ .command('arns-action-price')
175
+ .description('Preview the Turbo Credit price of a non-purchase ArNS action (set-record, remove-record, ' +
176
+ 'set-record-metadata, remove-record-metadata, transfer-record, add-controller, remove-controller, transfer)'), arnsActionPriceOptions).action(async (_commandOptions, command) => {
177
+ await runCommand(command, arnsActionPrice);
178
+ });
148
179
  applyOptions(program
149
180
  .command('inspect-data-items')
150
181
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), [optionMap.folderPath]).action(async (_commandOptions, command) => {