@ardrive/turbo-sdk 1.42.0 → 1.43.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 (99) hide show
  1. package/lib/cjs/cli/cli.js +92 -0
  2. package/lib/cjs/cli/commands/arns.js +440 -0
  3. package/lib/cjs/cli/commands/freeStatus.js +47 -0
  4. package/lib/cjs/cli/commands/index.js +3 -0
  5. package/lib/cjs/cli/commands/paymentHistory.js +25 -0
  6. package/lib/cjs/cli/options.js +201 -1
  7. package/lib/cjs/common/arnsActions.js +125 -0
  8. package/lib/cjs/common/chunked.js +51 -1
  9. package/lib/cjs/common/folderIndex.js +394 -0
  10. package/lib/cjs/common/http.js +32 -6
  11. package/lib/cjs/common/index.js +7 -0
  12. package/lib/cjs/common/payment.js +546 -0
  13. package/lib/cjs/common/signer.js +27 -6
  14. package/lib/cjs/common/token/index.js +0 -11
  15. package/lib/cjs/common/turbo.js +162 -0
  16. package/lib/cjs/common/upload.js +314 -31
  17. package/lib/cjs/node/folderIndex.js +132 -0
  18. package/lib/cjs/node/index.js +1 -0
  19. package/lib/cjs/node/upload.js +7 -0
  20. package/lib/cjs/types.js +53 -3
  21. package/lib/cjs/utils/common.js +0 -4
  22. package/lib/cjs/utils/errors.js +38 -1
  23. package/lib/cjs/utils/folderIndex.js +88 -0
  24. package/lib/cjs/utils/uuid.js +31 -0
  25. package/lib/cjs/web/signer.js +4 -2
  26. package/lib/esm/cli/cli.js +94 -2
  27. package/lib/esm/cli/commands/arns.js +416 -0
  28. package/lib/esm/cli/commands/freeStatus.js +44 -0
  29. package/lib/esm/cli/commands/index.js +3 -0
  30. package/lib/esm/cli/commands/paymentHistory.js +22 -0
  31. package/lib/esm/cli/options.js +200 -0
  32. package/lib/esm/common/arnsActions.js +114 -0
  33. package/lib/esm/common/chunked.js +51 -1
  34. package/lib/esm/common/folderIndex.js +389 -0
  35. package/lib/esm/common/http.js +31 -5
  36. package/lib/esm/common/index.js +7 -0
  37. package/lib/esm/common/payment.js +546 -0
  38. package/lib/esm/common/signer.js +28 -7
  39. package/lib/esm/common/token/index.js +1 -12
  40. package/lib/esm/common/turbo.js +162 -0
  41. package/lib/esm/common/upload.js +316 -33
  42. package/lib/esm/node/folderIndex.js +129 -0
  43. package/lib/esm/node/index.js +1 -0
  44. package/lib/esm/node/upload.js +7 -0
  45. package/lib/esm/types.js +52 -2
  46. package/lib/esm/utils/common.js +0 -4
  47. package/lib/esm/utils/errors.js +35 -0
  48. package/lib/esm/utils/folderIndex.js +81 -0
  49. package/lib/esm/utils/uuid.js +28 -0
  50. package/lib/esm/web/signer.js +4 -2
  51. package/lib/types/cli/commands/arns.d.ts +133 -0
  52. package/lib/types/cli/commands/arns.d.ts.map +1 -0
  53. package/lib/types/cli/commands/freeStatus.d.ts +3 -0
  54. package/lib/types/cli/commands/freeStatus.d.ts.map +1 -0
  55. package/lib/types/cli/commands/index.d.ts +3 -0
  56. package/lib/types/cli/commands/index.d.ts.map +1 -1
  57. package/lib/types/cli/commands/paymentHistory.d.ts +18 -0
  58. package/lib/types/cli/commands/paymentHistory.d.ts.map +1 -0
  59. package/lib/types/cli/options.d.ts +410 -0
  60. package/lib/types/cli/options.d.ts.map +1 -1
  61. package/lib/types/cli/types.d.ts +71 -0
  62. package/lib/types/cli/types.d.ts.map +1 -1
  63. package/lib/types/common/arnsActions.d.ts +58 -0
  64. package/lib/types/common/arnsActions.d.ts.map +1 -0
  65. package/lib/types/common/chunked.d.ts +47 -2
  66. package/lib/types/common/chunked.d.ts.map +1 -1
  67. package/lib/types/common/folderIndex.d.ts +54 -0
  68. package/lib/types/common/folderIndex.d.ts.map +1 -0
  69. package/lib/types/common/http.d.ts +25 -2
  70. package/lib/types/common/http.d.ts.map +1 -1
  71. package/lib/types/common/index.d.ts +3 -0
  72. package/lib/types/common/index.d.ts.map +1 -1
  73. package/lib/types/common/payment.d.ts +291 -1
  74. package/lib/types/common/payment.d.ts.map +1 -1
  75. package/lib/types/common/signer.d.ts +12 -6
  76. package/lib/types/common/signer.d.ts.map +1 -1
  77. package/lib/types/common/token/index.d.ts.map +1 -1
  78. package/lib/types/common/turbo.d.ts +183 -1
  79. package/lib/types/common/turbo.d.ts.map +1 -1
  80. package/lib/types/common/upload.d.ts +41 -0
  81. package/lib/types/common/upload.d.ts.map +1 -1
  82. package/lib/types/node/folderIndex.d.ts +28 -0
  83. package/lib/types/node/folderIndex.d.ts.map +1 -0
  84. package/lib/types/node/index.d.ts +1 -0
  85. package/lib/types/node/index.d.ts.map +1 -1
  86. package/lib/types/node/upload.d.ts +1 -0
  87. package/lib/types/node/upload.d.ts.map +1 -1
  88. package/lib/types/types.d.ts +694 -3
  89. package/lib/types/types.d.ts.map +1 -1
  90. package/lib/types/utils/common.d.ts.map +1 -1
  91. package/lib/types/utils/errors.d.ts +29 -0
  92. package/lib/types/utils/errors.d.ts.map +1 -1
  93. package/lib/types/utils/folderIndex.d.ts +47 -0
  94. package/lib/types/utils/folderIndex.d.ts.map +1 -0
  95. package/lib/types/utils/uuid.d.ts +7 -0
  96. package/lib/types/utils/uuid.d.ts.map +1 -0
  97. package/lib/types/web/signer.d.ts +1 -1
  98. package/lib/types/web/signer.d.ts.map +1 -1
  99. package/package.json +1 -1
@@ -22,6 +22,7 @@ const arbundles_1 = require("@dha-team/arbundles");
22
22
  const commander_1 = require("commander");
23
23
  const fs_1 = require("fs");
24
24
  const version_js_1 = require("../version.js");
25
+ const arns_js_1 = require("./commands/arns.js");
25
26
  const fiatEstimate_js_1 = require("./commands/fiatEstimate.js");
26
27
  const index_js_1 = require("./commands/index.js");
27
28
  const listShares_js_1 = require("./commands/listShares.js");
@@ -39,6 +40,16 @@ const utils_js_1 = require("./utils.js");
39
40
  (0, utils_js_1.applyOptions)(commander_1.program.command('balance').description('Get balance of a Turbo address'), [options_js_1.optionMap.address, ...options_js_1.walletOptions]).action(async (_commandOptions, command) => {
40
41
  await (0, utils_js_1.runCommand)(command, index_js_1.balance);
41
42
  });
43
+ (0, utils_js_1.applyOptions)(commander_1.program
44
+ .command('free-status')
45
+ .description('Get the free-tier upload allowance remaining for a Turbo address'), [options_js_1.optionMap.address, ...options_js_1.walletOptions]).action(async (_commandOptions, command) => {
46
+ await (0, utils_js_1.runCommand)(command, index_js_1.freeStatus);
47
+ });
48
+ (0, utils_js_1.applyOptions)(commander_1.program
49
+ .command('payment-history')
50
+ .description("Get the signing wallet's own top-up (payment) history"), [...options_js_1.walletOptions, options_js_1.optionMap.limit, options_js_1.optionMap.cursor]).action(async (_commandOptions, command) => {
51
+ await (0, utils_js_1.runCommand)(command, index_js_1.paymentHistory);
52
+ });
42
53
  (0, utils_js_1.applyOptions)(commander_1.program.command('top-up').description('Top up a Turbo address with Fiat'), [...options_js_1.walletOptions, options_js_1.optionMap.address, options_js_1.optionMap.value, options_js_1.optionMap.currency]).action(async (_commandOptions, command) => {
43
54
  await (0, utils_js_1.runCommand)(command, index_js_1.topUp);
44
55
  });
@@ -86,6 +97,87 @@ const utils_js_1 = require("./utils.js");
86
97
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), options_js_1.listSharesOptions).action(async (_commandOptions, command) => {
87
98
  await (0, utils_js_1.runCommand)(command, listShares_js_1.listShares);
88
99
  });
100
+ (0, utils_js_1.applyOptions)(commander_1.program
101
+ .command('arns-price')
102
+ .description('Get the Turbo Credit (winc + mARIO) price to buy, extend, increase undernames, or upgrade an ArNS name'), options_js_1.arnsPriceOptions).action(async (_commandOptions, command) => {
103
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsPrice);
104
+ });
105
+ (0, utils_js_1.applyOptions)(commander_1.program
106
+ .command('arns-fiat-quote')
107
+ .description('Quote an ArNS purchase paid by credit card (Stripe) - no credits needed'), options_js_1.arnsFiatQuoteOptions).action(async (_commandOptions, command) => {
108
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsFiatQuote);
109
+ });
110
+ (0, utils_js_1.applyOptions)(commander_1.program
111
+ .command('buy-arns-name')
112
+ .description('Buy an ArNS name (lease or permabuy) with Turbo Credits'), options_js_1.buyArNSNameOptions).action(async (_commandOptions, command) => {
113
+ await (0, utils_js_1.runCommand)(command, arns_js_1.buyArNSName);
114
+ });
115
+ (0, utils_js_1.applyOptions)(commander_1.program
116
+ .command('extend-arns-lease')
117
+ .description('Extend an ArNS name lease with Turbo Credits'), options_js_1.extendArNSLeaseOptions).action(async (_commandOptions, command) => {
118
+ await (0, utils_js_1.runCommand)(command, arns_js_1.extendArNSLease);
119
+ });
120
+ (0, utils_js_1.applyOptions)(commander_1.program
121
+ .command('increase-arns-undernames')
122
+ .description('Increase the undername limit of an ArNS name with Turbo Credits'), options_js_1.increaseArNSUndernamesOptions).action(async (_commandOptions, command) => {
123
+ await (0, utils_js_1.runCommand)(command, arns_js_1.increaseArNSUndernames);
124
+ });
125
+ (0, utils_js_1.applyOptions)(commander_1.program
126
+ .command('upgrade-arns-name')
127
+ .description('Upgrade an ArNS leased name to a permabuy with Turbo Credits'), options_js_1.upgradeArNSNameOptions).action(async (_commandOptions, command) => {
128
+ await (0, utils_js_1.runCommand)(command, arns_js_1.upgradeArNSName);
129
+ });
130
+ (0, utils_js_1.applyOptions)(commander_1.program
131
+ .command('arns-purchase-status')
132
+ .description('Get the status of an ArNS purchase by its nonce'), options_js_1.arnsPurchaseStatusOptions).action(async (_commandOptions, command) => {
133
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsPurchaseStatus);
134
+ });
135
+ (0, utils_js_1.applyOptions)(commander_1.program
136
+ .command('transfer-arns-ant')
137
+ .description('Transfer a Turbo-custodied ANT to a Solana pubkey you control'), options_js_1.transferArNSAntOptions).action(async (_commandOptions, command) => {
138
+ await (0, utils_js_1.runCommand)(command, arns_js_1.transferArNSAnt);
139
+ });
140
+ (0, utils_js_1.applyOptions)(commander_1.program
141
+ .command('set-arns-record')
142
+ .description('Set a resolution record on a Turbo-custodied ANT'), options_js_1.setArNSRecordOptions).action(async (_commandOptions, command) => {
143
+ await (0, utils_js_1.runCommand)(command, arns_js_1.setArNSRecord);
144
+ });
145
+ (0, utils_js_1.applyOptions)(commander_1.program
146
+ .command('remove-arns-record')
147
+ .description('Remove a resolution record (undername) from a Turbo-custodied ANT'), options_js_1.removeArNSRecordOptions).action(async (_commandOptions, command) => {
148
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecord);
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
+ });
89
181
  (0, utils_js_1.applyOptions)(commander_1.program
90
182
  .command('inspect-data-items')
91
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) => {
@@ -0,0 +1,440 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requiredNameFromOptions = requiredNameFromOptions;
4
+ exports.positiveIntFromOption = positiveIntFromOption;
5
+ exports.typeFromOptions = typeFromOptions;
6
+ exports.actionFromOptions = actionFromOptions;
7
+ exports.paidByFromArNSOptions = paidByFromArNSOptions;
8
+ exports.arnsPriceParamsFromOptions = arnsPriceParamsFromOptions;
9
+ exports.arnsPrice = arnsPrice;
10
+ exports.arnsFiatQuote = arnsFiatQuote;
11
+ exports.buyArNSName = buyArNSName;
12
+ exports.extendArNSLease = extendArNSLease;
13
+ exports.increaseArNSUndernames = increaseArNSUndernames;
14
+ exports.upgradeArNSName = upgradeArNSName;
15
+ exports.arnsPurchaseStatus = arnsPurchaseStatus;
16
+ exports.transferArNSAnt = transferArNSAnt;
17
+ exports.setArNSRecord = setArNSRecord;
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;
25
+ /**
26
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
27
+ *
28
+ * Licensed under the Apache License, Version 2.0 (the "License");
29
+ * you may not use this file except in compliance with the License.
30
+ * You may obtain a copy of the License at
31
+ *
32
+ * http://www.apache.org/licenses/LICENSE-2.0
33
+ *
34
+ * Unless required by applicable law or agreed to in writing, software
35
+ * distributed under the License is distributed on an "AS IS" BASIS,
36
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37
+ * See the License for the specific language governing permissions and
38
+ * limitations under the License.
39
+ */
40
+ const bignumber_js_1 = require("bignumber.js");
41
+ const arnsActions_js_1 = require("../../common/arnsActions.js");
42
+ const factory_js_1 = require("../../node/factory.js");
43
+ const types_js_1 = require("../../types.js");
44
+ const errors_js_1 = require("../../utils/errors.js");
45
+ const constants_js_1 = require("../constants.js");
46
+ const utils_js_1 = require("../utils.js");
47
+ /**
48
+ * The ANT owner's Solana key.
49
+ *
50
+ * Deliberately separate from the wallet that pays: the payer holds Turbo
51
+ * credits (and may be Arweave or Ethereum), while the owner holds the ANT and
52
+ * must be Solana. The owner needs a key to SIGN with, not a funded account —
53
+ * Turbo is the fee payer on every sponsored action.
54
+ */
55
+ function ownerFromOptions(options) {
56
+ if (options.ownerKey === undefined || options.ownerKey === '') {
57
+ throw new Error('Must provide --owner-key (a base58 Solana secret key) — it owns the ANT and signs for it. ' +
58
+ 'This is separate from the wallet paying in Turbo Credits.');
59
+ }
60
+ return (0, arnsActions_js_1.solanaOwnerSigner)(options.ownerKey);
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
+ ]);
69
+ function requiredNameFromOptions(options) {
70
+ if (options.name === undefined || options.name.length === 0) {
71
+ throw new Error('Must provide an ArNS --name');
72
+ }
73
+ return options.name;
74
+ }
75
+ function positiveIntFromOption(value, flag) {
76
+ if (value === undefined) {
77
+ throw new Error(`Must provide ${flag}`);
78
+ }
79
+ const num = +value;
80
+ if (!Number.isFinite(num) || !Number.isInteger(num) || num <= 0) {
81
+ throw new Error(`${flag} must be a positive integer`);
82
+ }
83
+ return num;
84
+ }
85
+ function typeFromOptions(value) {
86
+ if (value !== 'lease' && value !== 'permabuy') {
87
+ throw new Error("Must provide --type of 'lease' or 'permabuy'");
88
+ }
89
+ return value;
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
+ }
110
+ function paidByFromArNSOptions(paidBy) {
111
+ return paidBy !== undefined && paidBy.length > 0 ? paidBy : undefined;
112
+ }
113
+ // A price quote depends only on the name (length), type, and years — NOT on the
114
+ // ANT the name will resolve to. The service ignores `processId` for pricing, but
115
+ // the SDK's Buy-Name validation still requires a non-empty one, so we substitute
116
+ // this obvious placeholder when the user omits `--process-id` from `arns-price`.
117
+ // (`buy-arns-name` still requires a real `--process-id`.)
118
+ const PRICING_PLACEHOLDER_PROCESS_ID = 'pricing-only-no-process-id';
119
+ /**
120
+ * Infer the ArNS pricing intent from the provided flags:
121
+ * - `--type` present -> Buy-Name (lease needs --years; --process-id optional for pricing)
122
+ * - `--increase-qty` present -> Increase-Undername-Limit
123
+ * - `--years` present (no type) -> Extend-Lease
124
+ * - otherwise -> Upgrade-Name
125
+ */
126
+ function arnsPriceParamsFromOptions(options) {
127
+ const name = requiredNameFromOptions(options);
128
+ if (options.type !== undefined) {
129
+ const type = typeFromOptions(options.type);
130
+ const processId = options.processId ?? PRICING_PLACEHOLDER_PROCESS_ID;
131
+ if (type === 'lease') {
132
+ return {
133
+ intent: 'Buy-Name',
134
+ name,
135
+ type: 'lease',
136
+ years: positiveIntFromOption(options.years, '--years'),
137
+ processId,
138
+ };
139
+ }
140
+ return {
141
+ intent: 'Buy-Name',
142
+ name,
143
+ type: 'permabuy',
144
+ processId,
145
+ };
146
+ }
147
+ if (options.increaseQty !== undefined) {
148
+ return {
149
+ intent: 'Increase-Undername-Limit',
150
+ name,
151
+ increaseQty: positiveIntFromOption(options.increaseQty, '--increase-qty'),
152
+ };
153
+ }
154
+ if (options.years !== undefined) {
155
+ return {
156
+ intent: 'Extend-Lease',
157
+ name,
158
+ years: positiveIntFromOption(options.years, '--years'),
159
+ };
160
+ }
161
+ return { intent: 'Upgrade-Name', name };
162
+ }
163
+ function creditsFromWinc(winc) {
164
+ return new bignumber_js_1.BigNumber(winc).dividedBy(constants_js_1.wincPerCredit).toFixed(12);
165
+ }
166
+ /** Rethrow a 402 as a clear, actionable "top up" message. */
167
+ async function withCreditErrorMapping(fn) {
168
+ try {
169
+ return await fn();
170
+ }
171
+ catch (error) {
172
+ if (error instanceof errors_js_1.InsufficientCreditsError) {
173
+ throw new Error('Insufficient Turbo credits to complete this ArNS purchase. ' +
174
+ 'Top up your balance (e.g. `turbo top-up` or `turbo crypto-fund`) and retry.');
175
+ }
176
+ throw error;
177
+ }
178
+ }
179
+ function logPurchaseResult(action, result) {
180
+ console.log(JSON.stringify({
181
+ message: `${action} completed!`,
182
+ nonce: result.nonce,
183
+ antId: result.antId,
184
+ // Solana transaction id of the on-chain write.
185
+ messageId: result.messageId,
186
+ ...(result.alreadyCompleted === true ? { alreadyCompleted: true } : {}),
187
+ }, null, 2));
188
+ console.log(`\nTrack this purchase with:\n turbo arns-purchase-status --nonce ${result.nonce}`);
189
+ }
190
+ async function arnsPrice(options, turbo) {
191
+ const params = arnsPriceParamsFromOptions(options);
192
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
193
+ const { winc, wincTotal, antSpawnSurchargeWinc, mARIO } = await client.getArNSPriceForName(params);
194
+ // `wincTotal` is the figure to pay. `winc` is the name only and excludes the
195
+ // ANT spawn surcharge, which for a Buy-Name can exceed the name's own price,
196
+ // so printing it as the price under-quotes what `buy-arns-name` then debits.
197
+ console.log(JSON.stringify({
198
+ name: params.name,
199
+ intent: params.intent,
200
+ wincTotal,
201
+ credits: creditsFromWinc(wincTotal),
202
+ nameOnlyWinc: winc,
203
+ antSpawnSurchargeWinc,
204
+ mARIO,
205
+ }, null, 2));
206
+ }
207
+ async function arnsFiatQuote(options, turbo) {
208
+ const params = arnsPriceParamsFromOptions(options);
209
+ // `arnsPriceParamsFromOptions` substitutes PRICING_PLACEHOLDER_PROCESS_ID for
210
+ // an omitted Buy-Name `processId`, which is fine for a price lookup but NOT
211
+ // here: a quote records a real purchase, and that placeholder is not a valid
212
+ // ANT. Send `processId` only when the caller actually supplied one — omitting
213
+ // it is what tells Turbo to custodially provision the ANT.
214
+ if (options.processId === undefined) {
215
+ delete params.processId;
216
+ }
217
+ const address = options.address;
218
+ if (address === undefined) {
219
+ throw new Error('A destination --address is required for a fiat ArNS quote.');
220
+ }
221
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
222
+ try {
223
+ const { purchaseQuote, paymentSession, adjustments, fees } = await client.getArNSFiatPurchaseQuote({
224
+ ...params,
225
+ address,
226
+ currency: (options.currency ?? 'usd'),
227
+ method: options.method,
228
+ promoCodes: options.promoCode,
229
+ });
230
+ console.log(JSON.stringify({
231
+ name: purchaseQuote.name,
232
+ intent: purchaseQuote.intent,
233
+ nonce: purchaseQuote.nonce,
234
+ paymentAmount: purchaseQuote.paymentAmount,
235
+ currency: purchaseQuote.currencyType,
236
+ quoteExpirationDate: purchaseQuote.quoteExpirationDate,
237
+ paymentSessionId: paymentSession.id,
238
+ // Present for a payment intent / embedded checkout; a hosted
239
+ // checkout session returns `url` instead.
240
+ clientSecret: paymentSession.client_secret ?? undefined,
241
+ checkoutUrl: paymentSession.url ?? undefined,
242
+ adjustments,
243
+ fees,
244
+ }, null, 2));
245
+ }
246
+ catch (error) {
247
+ if (error instanceof errors_js_1.FiatPaymentsDisabledError) {
248
+ console.error('Fiat (Stripe) payments are disabled on this payment service. Use the credit-paid commands (buy-arns-name, extend-arns-lease, ...) instead.');
249
+ throw error;
250
+ }
251
+ throw error;
252
+ }
253
+ }
254
+ async function buyArNSName(options, turbo) {
255
+ const name = requiredNameFromOptions(options);
256
+ const type = typeFromOptions(options.type);
257
+ const paidBy = paidByFromArNSOptions(options.paidBy);
258
+ // Every buy mints a fresh ANT straight to `--owner-key`; Turbo never holds
259
+ // it, and there is no bring-your-own-ANT path any more.
260
+ const owner = ownerFromOptions(options);
261
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
262
+ const result = await withCreditErrorMapping(() => type === 'lease'
263
+ ? client.buyArNSName({
264
+ name,
265
+ owner,
266
+ type: 'lease',
267
+ years: positiveIntFromOption(options.years, '--years'),
268
+ paidBy,
269
+ })
270
+ : client.buyArNSName({ name, owner, type: 'permabuy', paidBy }));
271
+ logPurchaseResult('ArNS name purchase', result);
272
+ }
273
+ async function extendArNSLease(options, turbo) {
274
+ const name = requiredNameFromOptions(options);
275
+ const years = positiveIntFromOption(options.years, '--years');
276
+ const paidBy = paidByFromArNSOptions(options.paidBy);
277
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
278
+ const result = await withCreditErrorMapping(() => client.extendArNSLease({ name, years, paidBy }));
279
+ logPurchaseResult('ArNS lease extension', result);
280
+ }
281
+ async function increaseArNSUndernames(options, turbo) {
282
+ const name = requiredNameFromOptions(options);
283
+ const increaseQty = positiveIntFromOption(options.increaseQty, '--increase-qty');
284
+ const paidBy = paidByFromArNSOptions(options.paidBy);
285
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
286
+ const result = await withCreditErrorMapping(() => client.increaseArNSUndernameLimit({ name, increaseQty, paidBy }));
287
+ logPurchaseResult('ArNS undername limit increase', result);
288
+ }
289
+ async function upgradeArNSName(options, turbo) {
290
+ const name = requiredNameFromOptions(options);
291
+ const paidBy = paidByFromArNSOptions(options.paidBy);
292
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
293
+ const result = await withCreditErrorMapping(() => client.upgradeArNSName({ name, paidBy }));
294
+ logPurchaseResult('ArNS name upgrade (to permabuy)', result);
295
+ }
296
+ async function arnsPurchaseStatus(options, turbo) {
297
+ if (options.nonce === undefined || options.nonce.length === 0) {
298
+ throw new Error('Must provide a --nonce to look up purchase status');
299
+ }
300
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
301
+ const status = await client.getArNSPurchaseStatus({ nonce: options.nonce });
302
+ const state = status.failedDate !== undefined
303
+ ? 'failed'
304
+ : status.messageId
305
+ ? 'success'
306
+ : 'pending';
307
+ console.log(JSON.stringify({ state, ...status }, null, 2));
308
+ }
309
+ async function transferArNSAnt(options, turbo) {
310
+ if (options.antId === undefined) {
311
+ throw new Error('Must provide an --ant-id to transfer');
312
+ }
313
+ if (options.target === undefined) {
314
+ throw new Error('Must provide a --target address to transfer the ANT to');
315
+ }
316
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
317
+ const result = await client.transferArNSAnt({
318
+ antId: options.antId,
319
+ owner: ownerFromOptions(options),
320
+ target: options.target,
321
+ });
322
+ console.log(JSON.stringify({ message: 'ANT transfer submitted!', ...result }, null, 2));
323
+ }
324
+ async function setArNSRecord(options, turbo) {
325
+ if (options.antId === undefined) {
326
+ throw new Error('Must provide an --ant-id to set a record on');
327
+ }
328
+ if (options.transactionId === undefined) {
329
+ throw new Error('Must provide a --transaction-id for the record');
330
+ }
331
+ const ttlSeconds = positiveIntFromOption(options.ttlSeconds, '--ttl-seconds');
332
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
333
+ const result = await client.setArNSRecord({
334
+ antId: options.antId,
335
+ owner: ownerFromOptions(options),
336
+ undername: options.undername ?? '@',
337
+ transactionId: options.transactionId,
338
+ ttlSeconds,
339
+ });
340
+ console.log(JSON.stringify({ message: 'ArNS record set!', ...result }, null, 2));
341
+ }
342
+ async function removeArNSRecord(options, turbo) {
343
+ if (options.antId === undefined) {
344
+ throw new Error('Must provide an --ant-id to remove a record from');
345
+ }
346
+ if (options.undername === undefined || options.undername.length === 0) {
347
+ throw new Error('Must provide an --undername to remove');
348
+ }
349
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
350
+ const result = await client.removeArNSRecord({
351
+ antId: options.antId,
352
+ owner: ownerFromOptions(options),
353
+ undername: options.undername,
354
+ });
355
+ console.log(JSON.stringify({ message: 'ArNS record removed!', ...result }, null, 2));
356
+ }
357
+ async function addArNSController(options, turbo) {
358
+ if (options.antId === undefined) {
359
+ throw new Error('Must provide an --ant-id to add a controller to');
360
+ }
361
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
362
+ const result = await client.addArNSController({
363
+ antId: options.antId,
364
+ owner: ownerFromOptions(options),
365
+ target: options.target,
366
+ });
367
+ console.log(JSON.stringify({ message: 'ArNS controller added!', ...result }, null, 2));
368
+ }
369
+ async function removeArNSController(options, turbo) {
370
+ if (options.antId === undefined) {
371
+ throw new Error('Must provide an --ant-id to remove a controller from');
372
+ }
373
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
374
+ const result = await client.removeArNSController({
375
+ antId: options.antId,
376
+ owner: ownerFromOptions(options),
377
+ target: options.target,
378
+ });
379
+ console.log(JSON.stringify({ message: 'ArNS controller removed!', ...result }, null, 2));
380
+ }
381
+ async function transferArNSRecord(options, turbo) {
382
+ if (options.antId === undefined) {
383
+ throw new Error('Must provide an --ant-id whose record to transfer');
384
+ }
385
+ if (options.undername === undefined || options.undername.length === 0) {
386
+ throw new Error('Must provide an --undername to transfer');
387
+ }
388
+ if (options.target === undefined) {
389
+ throw new Error('Must provide a --target address to transfer the record to');
390
+ }
391
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
392
+ const result = await client.transferArNSRecord({
393
+ antId: options.antId,
394
+ owner: ownerFromOptions(options),
395
+ undername: options.undername,
396
+ target: options.target,
397
+ });
398
+ console.log(JSON.stringify({ message: 'ArNS record transferred!', ...result }, null, 2));
399
+ }
400
+ async function setArNSRecordMetadata(options, turbo) {
401
+ if (options.antId === undefined) {
402
+ throw new Error('Must provide an --ant-id to set record metadata on');
403
+ }
404
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
405
+ const result = await client.setArNSRecordMetadata({
406
+ antId: options.antId,
407
+ owner: ownerFromOptions(options),
408
+ undername: options.undername ?? '@',
409
+ displayName: metadataFieldFromOptions(options.displayName, options.clearDisplayName),
410
+ recordLogo: metadataFieldFromOptions(options.recordLogo, options.clearRecordLogo),
411
+ recordDescription: metadataFieldFromOptions(options.recordDescription, options.clearRecordDescription),
412
+ recordKeywords: metadataFieldFromOptions(options.recordKeywords, options.clearRecordKeywords),
413
+ });
414
+ console.log(JSON.stringify({ message: 'ArNS record metadata set!', ...result }, null, 2));
415
+ }
416
+ async function removeArNSRecordMetadata(options, turbo) {
417
+ if (options.antId === undefined) {
418
+ throw new Error('Must provide an --ant-id to remove record metadata from');
419
+ }
420
+ if (options.undername === undefined || options.undername.length === 0) {
421
+ throw new Error('Must provide an --undername');
422
+ }
423
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
424
+ const result = await client.removeArNSRecordMetadata({
425
+ antId: options.antId,
426
+ owner: ownerFromOptions(options),
427
+ undername: options.undername,
428
+ });
429
+ console.log(JSON.stringify({ message: 'ArNS record metadata removed!', ...result }, null, 2));
430
+ }
431
+ /**
432
+ * Preview what one of the eight non-purchase actions will debit, without
433
+ * creating it.
434
+ */
435
+ async function arnsActionPrice(options, turbo) {
436
+ const action = actionFromOptions(options);
437
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
438
+ const { wincQty } = await client.getArNSActionPrice(action);
439
+ console.log(JSON.stringify({ action, wincQty, credits: creditsFromWinc(wincQty) }, null, 2));
440
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.freeStatus = freeStatus;
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 factory_js_1 = require("../../node/factory.js");
20
+ const utils_js_1 = require("../utils.js");
21
+ async function freeStatus(options) {
22
+ const config = (0, utils_js_1.configFromOptions)(options);
23
+ const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
24
+ const { bytesRemaining, nativeAddress } = await (async () => {
25
+ if (address !== undefined) {
26
+ return {
27
+ ...(await factory_js_1.TurboFactory.unauthenticated(config).getFreeStatus(address)),
28
+ nativeAddress: address,
29
+ };
30
+ }
31
+ if (privateKey === undefined) {
32
+ throw new Error('Must provide an (--address) or use a valid wallet');
33
+ }
34
+ const turbo = factory_js_1.TurboFactory.authenticated({
35
+ ...config,
36
+ privateKey,
37
+ });
38
+ return {
39
+ ...(await turbo.getFreeStatus()),
40
+ nativeAddress: await turbo.signer.getNativeAddress(),
41
+ };
42
+ })();
43
+ console.log(`Turbo free-tier allowance for Native Address "${nativeAddress}"\n` +
44
+ (bytesRemaining === null
45
+ ? 'Free bytes remaining: unlimited (exempt/partner wallet)'
46
+ : `Free bytes remaining: ${bytesRemaining}`));
47
+ }
@@ -29,8 +29,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
29
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./arns.js"), exports);
32
33
  __exportStar(require("./balance.js"), exports);
33
34
  __exportStar(require("./cryptoFund.js"), exports);
35
+ __exportStar(require("./freeStatus.js"), exports);
36
+ __exportStar(require("./paymentHistory.js"), exports);
34
37
  __exportStar(require("./price.js"), exports);
35
38
  __exportStar(require("./topUp.js"), exports);
36
39
  __exportStar(require("./uploadFile.js"), exports);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.paymentHistory = paymentHistory;
4
+ const utils_js_1 = require("../utils.js");
5
+ async function paymentHistory(options) {
6
+ // Signature-required and self-scoped: a wallet is mandatory (there is no
7
+ // --address form), and the service returns only this signer's own top-ups.
8
+ const turbo = await (0, utils_js_1.turboFromOptions)(options);
9
+ const limit = options.limit !== undefined ? +options.limit : undefined;
10
+ if (limit !== undefined &&
11
+ (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
12
+ throw new Error('--limit must be an integer between 1 and 100');
13
+ }
14
+ const { payments, hasMore, cursor } = await turbo.getPaymentHistory({
15
+ limit,
16
+ cursor: options.cursor,
17
+ });
18
+ // stdout carries only the JSON page and the next-page hint goes to stderr, so
19
+ // `... | jq` works at the default log level. (--debug intentionally routes SDK
20
+ // logs to stdout and will interleave — expected when you ask for debug output.)
21
+ console.log(JSON.stringify({ payments, hasMore, cursor }, null, 2));
22
+ if (hasMore) {
23
+ console.error(`\nMore results available — fetch the next page with --cursor ${cursor}`);
24
+ }
25
+ }