@ardrive/turbo-sdk 1.41.3 → 1.42.0-alpha.10

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 (97) hide show
  1. package/lib/cjs/cli/cli.js +61 -0
  2. package/lib/cjs/cli/commands/arns.js +317 -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 +124 -11
  7. package/lib/cjs/cli/utils.js +3 -19
  8. package/lib/cjs/common/arnsActions.js +102 -0
  9. package/lib/cjs/common/factory.js +1 -3
  10. package/lib/cjs/common/http.js +20 -5
  11. package/lib/cjs/common/index.js +6 -0
  12. package/lib/cjs/common/payment.js +482 -3
  13. package/lib/cjs/common/signer.js +27 -6
  14. package/lib/cjs/common/token/ario.js +104 -83
  15. package/lib/cjs/common/token/index.js +0 -11
  16. package/lib/cjs/common/token/solana.js +1 -0
  17. package/lib/cjs/common/turbo.js +131 -0
  18. package/lib/cjs/common/upload.js +3 -2
  19. package/lib/cjs/node/factory.js +1 -3
  20. package/lib/cjs/types.js +44 -3
  21. package/lib/cjs/utils/common.js +5 -21
  22. package/lib/cjs/utils/errors.js +38 -1
  23. package/lib/cjs/utils/uuid.js +31 -0
  24. package/lib/cjs/web/factory.js +1 -3
  25. package/lib/cjs/web/signer.js +4 -2
  26. package/lib/esm/cli/cli.js +63 -2
  27. package/lib/esm/cli/commands/arns.js +300 -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 +123 -10
  32. package/lib/esm/cli/utils.js +4 -20
  33. package/lib/esm/common/arnsActions.js +93 -0
  34. package/lib/esm/common/factory.js +1 -3
  35. package/lib/esm/common/http.js +19 -4
  36. package/lib/esm/common/index.js +6 -0
  37. package/lib/esm/common/payment.js +482 -3
  38. package/lib/esm/common/signer.js +28 -7
  39. package/lib/esm/common/token/ario.js +102 -84
  40. package/lib/esm/common/token/index.js +1 -12
  41. package/lib/esm/common/token/solana.js +1 -0
  42. package/lib/esm/common/turbo.js +131 -0
  43. package/lib/esm/common/upload.js +4 -3
  44. package/lib/esm/node/factory.js +1 -3
  45. package/lib/esm/types.js +43 -2
  46. package/lib/esm/utils/common.js +4 -20
  47. package/lib/esm/utils/errors.js +35 -0
  48. package/lib/esm/utils/uuid.js +28 -0
  49. package/lib/esm/web/factory.js +1 -3
  50. package/lib/esm/web/signer.js +4 -2
  51. package/lib/types/cli/commands/arns.d.ts +86 -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 +238 -10
  60. package/lib/types/cli/options.d.ts.map +1 -1
  61. package/lib/types/cli/types.d.ts +41 -2
  62. package/lib/types/cli/types.d.ts.map +1 -1
  63. package/lib/types/cli/utils.d.ts.map +1 -1
  64. package/lib/types/common/arnsActions.d.ts +43 -0
  65. package/lib/types/common/arnsActions.d.ts.map +1 -0
  66. package/lib/types/common/factory.d.ts +1 -1
  67. package/lib/types/common/factory.d.ts.map +1 -1
  68. package/lib/types/common/http.d.ts +14 -1
  69. package/lib/types/common/http.d.ts.map +1 -1
  70. package/lib/types/common/index.d.ts +2 -0
  71. package/lib/types/common/index.d.ts.map +1 -1
  72. package/lib/types/common/payment.d.ts +230 -1
  73. package/lib/types/common/payment.d.ts.map +1 -1
  74. package/lib/types/common/signer.d.ts +12 -6
  75. package/lib/types/common/signer.d.ts.map +1 -1
  76. package/lib/types/common/token/ario.d.ts +13 -9
  77. package/lib/types/common/token/ario.d.ts.map +1 -1
  78. package/lib/types/common/token/index.d.ts.map +1 -1
  79. package/lib/types/common/token/solana.d.ts.map +1 -1
  80. package/lib/types/common/turbo.d.ts +140 -1
  81. package/lib/types/common/turbo.d.ts.map +1 -1
  82. package/lib/types/common/upload.d.ts.map +1 -1
  83. package/lib/types/node/factory.d.ts +1 -1
  84. package/lib/types/node/factory.d.ts.map +1 -1
  85. package/lib/types/types.d.ts +483 -7
  86. package/lib/types/types.d.ts.map +1 -1
  87. package/lib/types/utils/common.d.ts +0 -12
  88. package/lib/types/utils/common.d.ts.map +1 -1
  89. package/lib/types/utils/errors.d.ts +29 -0
  90. package/lib/types/utils/errors.d.ts.map +1 -1
  91. package/lib/types/utils/uuid.d.ts +7 -0
  92. package/lib/types/utils/uuid.d.ts.map +1 -0
  93. package/lib/types/web/factory.d.ts +1 -1
  94. package/lib/types/web/factory.d.ts.map +1 -1
  95. package/lib/types/web/signer.d.ts +1 -1
  96. package/lib/types/web/signer.d.ts.map +1 -1
  97. package/package.json +3 -2
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.ARIOToTokenAmount = exports.mARIOToTokenAmount = exports.ARIOToken = void 0;
4
7
  /**
@@ -16,68 +19,123 @@ exports.ARIOToTokenAmount = exports.mARIOToTokenAmount = exports.ARIOToken = voi
16
19
  * See the License for the specific language governing permissions and
17
20
  * limitations under the License.
18
21
  */
19
- const arbundles_1 = require("@dha-team/arbundles");
20
- const aoconnect_1 = require("@permaweb/aoconnect");
22
+ const spl_token_1 = require("@solana/spl-token");
23
+ const web3_js_1 = require("@solana/web3.js");
21
24
  const bignumber_js_1 = require("bignumber.js");
25
+ const bs58_1 = __importDefault(require("bs58"));
22
26
  const common_js_1 = require("../../utils/common.js");
23
- const version_js_1 = require("../../version.js");
24
27
  const logger_js_1 = require("../logger.js");
28
+ const solana_js_1 = require("./solana.js");
29
+ const ARIO_SPL_MINT_ADDRESS = 'DcNnMuFxwhgV4WY1HVSaSEgr92bv2b1vUvEKiNxWqHdF';
30
+ const DEVNET_ARIO_SPL_MINT_ADDRESS = '6vTw5CysRXQ4ybbHkDUiisHWVsBeMtUzYvJqs2iqHyaN';
31
+ const ARIO_TOKEN_DECIMALS = 6;
25
32
  class ARIOToken {
26
- constructor({ cuUrl = common_js_1.defaultProdAoConfigs.ario.cuUrl, logger = logger_js_1.Logger.default, pollingOptions = {
33
+ constructor({ gatewayUrl = common_js_1.defaultProdGatewayUrls.solana, logger = logger_js_1.Logger.default, pollingOptions = {
34
+ maxAttempts: 10,
35
+ pollingIntervalMs: 2_500,
27
36
  initialBackoffMs: 500,
28
- pollingIntervalMs: 0, // no polling for ARIO process
29
- maxAttempts: 0, // no polling for ARIO process
30
- }, processId = common_js_1.defaultProdAoConfigs.ario.processId, } = {}) {
31
- this.ao = (0, aoconnect_1.connect)({
32
- CU_URL: cuUrl,
33
- });
34
- this.processId = processId;
37
+ }, } = {}) {
38
+ this.gatewayUrl = gatewayUrl;
39
+ this.connection = new web3_js_1.Connection(gatewayUrl, 'confirmed');
35
40
  this.pollingOptions = pollingOptions;
36
41
  this.logger = logger;
42
+ if (gatewayUrl.includes('devnet')) {
43
+ this.mintAddress = DEVNET_ARIO_SPL_MINT_ADDRESS;
44
+ }
45
+ else {
46
+ this.mintAddress = ARIO_SPL_MINT_ADDRESS;
47
+ }
37
48
  }
38
- async createAndSubmitTx({ target, signer: { signer }, tokenAmount, turboCreditDestinationAddress, }) {
39
- const tags = [
40
- {
41
- name: 'Action',
42
- value: 'Transfer',
43
- },
44
- {
45
- name: 'Recipient',
46
- value: target,
47
- },
48
- {
49
- name: 'Quantity',
50
- value: tokenAmount.toString(),
51
- },
52
- {
53
- name: 'Turbo-SDK',
54
- value: version_js_1.version,
55
- },
56
- ];
49
+ async createAndSubmitTx({ target, signer, tokenAmount, turboCreditDestinationAddress, }) {
50
+ const ownerPublicKey = new web3_js_1.PublicKey(bs58_1.default.encode(Uint8Array.from(await signer.getPublicKey())));
51
+ const recipient = new web3_js_1.PublicKey(target);
52
+ const mint = new web3_js_1.PublicKey(this.mintAddress);
53
+ const fromAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, ownerPublicKey);
54
+ const toAta = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, recipient);
55
+ const tx = new web3_js_1.Transaction({
56
+ feePayer: ownerPublicKey,
57
+ ...(await this.connection.getLatestBlockhash()),
58
+ });
59
+ tx.add((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(ownerPublicKey, toAta, recipient, mint));
60
+ tx.add((0, spl_token_1.createTransferCheckedInstruction)(fromAta, mint, toAta, ownerPublicKey, BigInt(new bignumber_js_1.BigNumber(tokenAmount).toFixed(0)), ARIO_TOKEN_DECIMALS));
57
61
  if (turboCreditDestinationAddress !== undefined) {
58
- tags.push({
59
- name: 'Turbo-Credit-Destination-Address',
60
- value: turboCreditDestinationAddress,
61
- });
62
+ tx.add(new web3_js_1.TransactionInstruction({
63
+ programId: new web3_js_1.PublicKey(solana_js_1.memoProgramId),
64
+ keys: [],
65
+ data: Buffer.from('turboCreditDestinationAddress=' + turboCreditDestinationAddress),
66
+ }));
62
67
  }
63
- const txId = await this.ao.message({
64
- signer: createAoSigner(signer),
65
- process: this.processId,
66
- tags,
67
- });
68
- this.logger.debug('Submitted Transfer message to ARIO process...', {
68
+ const serializedTx = tx.serializeMessage();
69
+ const signature = await signer.signData(Uint8Array.from(serializedTx));
70
+ tx.addSignature(ownerPublicKey, Buffer.from(signature));
71
+ const txId = bs58_1.default.encode(signature);
72
+ await this.submitTx(tx, txId);
73
+ this.logger.debug('Submitted ARIO SPL transfer transaction...', {
69
74
  id: txId,
70
75
  target,
71
76
  tokenAmount,
72
- processId: this.processId,
73
- tags,
77
+ fromAta: fromAta.toBase58(),
78
+ toAta: toAta.toBase58(),
79
+ mint: mint.toBase58(),
74
80
  });
75
81
  return { id: txId, target, reward: '0' };
76
82
  }
77
- async pollTxAvailability() {
78
- // AO finality should be instant -- but we'll wait initial backoff to
79
- // provide infra some time to crank without reading the whole result
80
- return (0, common_js_1.sleep)(this.pollingOptions.initialBackoffMs);
83
+ async submitTx(tx, id) {
84
+ this.logger.debug('Submitting ARIO fund transaction...', { id });
85
+ await this.connection.sendRawTransaction(tx.serialize(), {
86
+ maxRetries: this.pollingOptions.maxAttempts,
87
+ });
88
+ if (tx.recentBlockhash === undefined ||
89
+ tx.lastValidBlockHeight === undefined) {
90
+ throw new Error('Failed to submit Transaction -- missing blockhash or lastValidBlockHeight from transaction creation. Solana Gateway Url:' +
91
+ this.gatewayUrl);
92
+ }
93
+ await this.connection.confirmTransaction({
94
+ signature: id,
95
+ blockhash: tx.recentBlockhash,
96
+ lastValidBlockHeight: tx.lastValidBlockHeight,
97
+ }, 'finalized');
98
+ }
99
+ async pollTxAvailability({ txId }) {
100
+ const { maxAttempts, pollingIntervalMs, initialBackoffMs } = this.pollingOptions;
101
+ this.logger.debug('Polling for ARIO SPL transaction...', {
102
+ txId,
103
+ pollingOptions: this.pollingOptions,
104
+ gatewayUrl: this.gatewayUrl,
105
+ });
106
+ await (0, common_js_1.sleep)(initialBackoffMs);
107
+ let attempts = 0;
108
+ while (attempts < maxAttempts) {
109
+ let status;
110
+ attempts++;
111
+ try {
112
+ const statuses = await this.connection.getSignatureStatuses([txId], {
113
+ searchTransactionHistory: true,
114
+ });
115
+ status = {
116
+ context: statuses.context,
117
+ value: statuses.value[0],
118
+ };
119
+ }
120
+ catch (err) {
121
+ this.logger.debug('Failed to poll ARIO SPL transaction...', { err });
122
+ }
123
+ if (status && status.value && status.value.err !== null) {
124
+ throw new Error(`Transaction failed: ${status.value.err}`);
125
+ }
126
+ if (status && status.value && status.value.slot !== null) {
127
+ this.logger.debug('Transaction found!', { txId, status });
128
+ return;
129
+ }
130
+ this.logger.debug('ARIO SPL transaction not found, polling...', {
131
+ txId,
132
+ attempts,
133
+ maxAttempts,
134
+ pollingIntervalMs,
135
+ });
136
+ await (0, common_js_1.sleep)(pollingIntervalMs);
137
+ }
138
+ throw new Error('Transaction not found after polling, transaction id: ' + txId);
81
139
  }
82
140
  }
83
141
  exports.ARIOToken = ARIOToken;
@@ -85,40 +143,3 @@ const mARIOToTokenAmount = (mARIO) => mARIO;
85
143
  exports.mARIOToTokenAmount = mARIOToTokenAmount;
86
144
  const ARIOToTokenAmount = (ario) => new bignumber_js_1.BigNumber(ario).times(1e6).valueOf();
87
145
  exports.ARIOToTokenAmount = ARIOToTokenAmount;
88
- function createAoSigner(signer) {
89
- if (!('publicKey' in signer)) {
90
- return (0, aoconnect_1.createDataItemSigner)(signer);
91
- }
92
- const aoSigner = async ({ data, tags, target, anchor }) => {
93
- // ensure appropriate permissions are granted with injected signers.
94
- if (signer.publicKey === undefined &&
95
- 'setPublicKey' in signer &&
96
- typeof signer.setPublicKey === 'function') {
97
- await signer.setPublicKey();
98
- }
99
- if (signer instanceof arbundles_1.ArconnectSigner) {
100
- // Sign using Arconnect signDataItem API
101
- const signedDataItem = await signer['signer'].signDataItem({
102
- data,
103
- tags,
104
- target,
105
- anchor,
106
- });
107
- const dataItem = new arbundles_1.DataItem(Buffer.from(signedDataItem));
108
- return {
109
- id: dataItem.id,
110
- raw: dataItem.getRaw(),
111
- };
112
- }
113
- const dataItem = (0, arbundles_1.createData)(data ?? '', signer, { tags, target, anchor });
114
- await dataItem.sign(signer);
115
- const signedData = {
116
- id: dataItem.id,
117
- raw: dataItem.getRaw(),
118
- };
119
- return signedData;
120
- };
121
- // eslint-disable-next-line
122
- // @ts-ignore Buffer vs ArrayBuffer type mismatch
123
- return aoSigner;
124
- }
@@ -17,17 +17,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.tokenToBaseMap = exports.exponentMap = exports.defaultTokenMap = void 0;
18
18
  exports.isTokenType = isTokenType;
19
19
  const types_js_1 = require("../../types.js");
20
- const common_js_1 = require("../../utils/common.js");
21
20
  const ario_js_1 = require("./ario.js");
22
21
  const arweave_js_1 = require("./arweave.js");
23
22
  const baseEth_js_1 = require("./baseEth.js");
24
- const erc20_js_1 = require("./erc20.js");
25
23
  const ethereum_js_1 = require("./ethereum.js");
26
24
  const kyve_js_1 = require("./kyve.js");
27
25
  const polygon_js_1 = require("./polygon.js");
28
26
  const solana_js_1 = require("./solana.js");
29
27
  const usdc_js_1 = require("./usdc.js");
30
- const baseARIOContractAddress = '0x138746adfA52909E5920def027f5a8dc1C7EfFb6';
31
28
  exports.defaultTokenMap = {
32
29
  arweave: (config) => new arweave_js_1.ArweaveToken(config),
33
30
  ario: (config) => new ario_js_1.ARIOToken(config),
@@ -40,12 +37,6 @@ exports.defaultTokenMap = {
40
37
  usdc: (config) => new usdc_js_1.USDCToken({ network: 'ethereum', ...config }),
41
38
  'base-usdc': (config) => new usdc_js_1.USDCToken({ network: 'base', ...config }),
42
39
  'polygon-usdc': (config) => new usdc_js_1.USDCToken({ network: 'polygon', ...config }),
43
- 'base-ario': (config) => new erc20_js_1.ERC20Token({
44
- ...config,
45
- pollingOptions: config.pollingOptions ?? baseEth_js_1.defaultBaseNetworkPollingOptions,
46
- tokenContractAddress: baseARIOContractAddress,
47
- gatewayUrl: config.gatewayUrl ?? common_js_1.defaultProdGatewayUrls['base-ario'],
48
- }),
49
40
  };
50
41
  const ethExponent = 18;
51
42
  const usdcExponent = 6;
@@ -53,7 +44,6 @@ const arioExponent = 6;
53
44
  exports.exponentMap = {
54
45
  arweave: 12,
55
46
  ario: arioExponent,
56
- 'base-ario': arioExponent,
57
47
  solana: 9,
58
48
  ethereum: ethExponent,
59
49
  'base-eth': ethExponent,
@@ -67,7 +57,6 @@ exports.exponentMap = {
67
57
  exports.tokenToBaseMap = {
68
58
  arweave: (a) => (0, arweave_js_1.ARToTokenAmount)(a),
69
59
  ario: (a) => (0, ario_js_1.ARIOToTokenAmount)(a),
70
- 'base-ario': (a) => (0, usdc_js_1.USDCToTokenAmount)(a),
71
60
  solana: (a) => (0, solana_js_1.SOLToTokenAmount)(a),
72
61
  ethereum: (a) => (0, ethereum_js_1.ETHToTokenAmount)(a),
73
62
  'base-eth': (a) => (0, ethereum_js_1.ETHToTokenAmount)(a),
@@ -114,6 +114,7 @@ class SolanaToken {
114
114
  throw new Error(`Transaction failed: ${status.value.err}`);
115
115
  }
116
116
  if (status && status.value && status.value.slot !== null) {
117
+ this.logger.debug('Transaction found!', { txId, status });
117
118
  return;
118
119
  }
119
120
  this.logger.debug('Transaction not found, polling...', {
@@ -54,6 +54,45 @@ class TurboUnauthenticatedClient {
54
54
  getBalance(address) {
55
55
  return this.paymentService.getBalance(address);
56
56
  }
57
+ getFreeStatus(address) {
58
+ return this.paymentService.getFreeStatus(address);
59
+ }
60
+ /**
61
+ * Returns the price in 'winc' (and mARIO) to buy/extend/upgrade an ArNS name.
62
+ */
63
+ getArNSPriceForName(params) {
64
+ return this.paymentService.getArNSPriceForName(params);
65
+ }
66
+ /**
67
+ * Returns the status of an ArNS purchase by its nonce.
68
+ */
69
+ getArNSPurchaseStatus(p) {
70
+ return this.paymentService.getArNSPurchaseStatus(p);
71
+ }
72
+ /**
73
+ * Returns the ArNS names a wallet owns or controls via Turbo's custodial
74
+ * ArNS-with-credits feature. `custodial: true` on a returned name means
75
+ * Turbo still holds/manages its ANT (transfer/manage routes apply);
76
+ * `custodial: false` means self-custody (or an already-completed exit) and
77
+ * is informational only.
78
+ *
79
+ * To read a name's current records or lease/expiration state, use
80
+ * `@ar.io/sdk` directly against the returned `antId`.
81
+ */
82
+ getArNSNames(address) {
83
+ return this.paymentService.getArNSNames(address);
84
+ }
85
+ /**
86
+ * Quote a fiat (Stripe) ArNS purchase — buy a name with a credit card in one
87
+ * step, no Turbo Credits top-up in between. Complete the returned
88
+ * `paymentSession` with Stripe, then poll {@link getArNSPurchaseStatus} using
89
+ * `purchaseQuote.nonce`.
90
+ *
91
+ * Throws `FiatPaymentsDisabledError` when the service has Stripe switched off.
92
+ */
93
+ getArNSFiatPurchaseQuote(params) {
94
+ return this.paymentService.getArNSFiatPurchaseQuote(params);
95
+ }
57
96
  /**
58
97
  * Returns a list of all supported fiat currencies.
59
98
  */
@@ -159,6 +198,98 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
159
198
  getBalance(userAddress) {
160
199
  return this.paymentService.getBalance(userAddress);
161
200
  }
201
+ /**
202
+ * Returns how many free-tier bytes the wallet can still upload for free
203
+ * (`bytesRemaining`), or `null` for an unlimited (exempt/partner) wallet.
204
+ */
205
+ getFreeStatus(userAddress) {
206
+ return this.paymentService.getFreeStatus(userAddress);
207
+ }
208
+ /**
209
+ * Returns the signer's OWN completed top-up history (crypto + fiat), newest
210
+ * first and keyset-paginated. Signature-required and self-scoped: it only ever
211
+ * returns the signing wallet's rows. Pass `cursor` from a prior response's
212
+ * `cursor` field (with `hasMore === true`) to fetch the next page.
213
+ */
214
+ getPaymentHistory(params) {
215
+ return this.paymentService.getPaymentHistory(params);
216
+ }
217
+ // ===== ArNS actions (sponsored) =====
218
+ //
219
+ // Thin delegations. The two-shape branch and the owner-proof construction
220
+ // live in the payment service; see its comments for why callers must branch
221
+ // on `status` rather than on which action they asked for.
222
+ /** Create an action. Debits credits HERE — capture the nonce before signing. */
223
+ createArNSAction(action, params, ownerProof) {
224
+ return this.paymentService.createArNSAction(action, params, ownerProof);
225
+ }
226
+ /** Submit the owner-signed transaction (FULL serialized tx, base64). */
227
+ signArNSAction(nonce, signedTransaction) {
228
+ return this.paymentService.signArNSAction(nonce, signedTransaction);
229
+ }
230
+ /** Status by nonce — open, needs no signature. Use it to resume. */
231
+ getArNSActionStatus(nonce) {
232
+ return this.paymentService.getArNSActionStatus(nonce);
233
+ }
234
+ /**
235
+ * Quote a fiat (Stripe) ArNS purchase for this signer's wallet — a credit-card
236
+ * buy in one step, with no Turbo Credits top-up in between. `address` defaults
237
+ * to the signer's native address; pass one to buy on another wallet's behalf.
238
+ *
239
+ * Complete the returned `paymentSession` with Stripe, then poll
240
+ * {@link getArNSPurchaseStatus} using `purchaseQuote.nonce`. Throws
241
+ * `FiatPaymentsDisabledError` when the service has Stripe switched off.
242
+ */
243
+ getArNSFiatPurchaseQuote(params) {
244
+ return this.paymentService.getArNSFiatPurchaseQuote(params);
245
+ }
246
+ /**
247
+ * Buy a name. The ANT is minted straight to `owner`; Turbo never holds it.
248
+ * The only action that always needs the owner's signature — once, ever.
249
+ */
250
+ buyArNSName(params) {
251
+ return this.paymentService.buyArNSName(params);
252
+ }
253
+ /** Extend a lease. No owner signature needed. */
254
+ extendArNSLease(params) {
255
+ return this.paymentService.extendArNSLease(params);
256
+ }
257
+ /** Raise the undername limit. No owner signature needed. */
258
+ increaseArNSUndernameLimit(params) {
259
+ return this.paymentService.increaseArNSUndernameLimit(params);
260
+ }
261
+ /** Upgrade a lease to a permanent name. No owner signature needed. */
262
+ upgradeArNSName(params) {
263
+ return this.paymentService.upgradeArNSName(params);
264
+ }
265
+ /** Point a name (or undername) at data. Free; handles both shapes. */
266
+ setArNSRecord(params) {
267
+ return this.paymentService.setArNSRecord(params);
268
+ }
269
+ /** Remove a record. Free; handles both shapes. */
270
+ removeArNSRecord(params) {
271
+ return this.paymentService.removeArNSRecord(params);
272
+ }
273
+ /** Grant controller rights — omit `target` for Turbo itself. Free. */
274
+ addArNSController(params) {
275
+ return this.paymentService.addArNSController(params);
276
+ }
277
+ /** Revoke controller rights. Always available, always free. */
278
+ removeArNSController(params) {
279
+ return this.paymentService.removeArNSController(params);
280
+ }
281
+ /** Hand the ANT to a new owner. Irreversible. Free. */
282
+ transferArNSAnt(params) {
283
+ return this.paymentService.transferArNSAnt(params);
284
+ }
285
+ /**
286
+ * Returns the ArNS names owned or controlled by the connected signer's
287
+ * wallet (or the given `userAddress`) via Turbo's custodial
288
+ * ArNS-with-credits feature.
289
+ */
290
+ getArNSNames(userAddress) {
291
+ return this.paymentService.getArNSNames(userAddress);
292
+ }
162
293
  /**
163
294
  * Returns a list of all credit share approvals for the user.
164
295
  */
@@ -123,7 +123,9 @@ class TurboUnauthenticatedUploadService {
123
123
  };
124
124
  return this.httpService.post({
125
125
  data: dataBuffer,
126
- endpoint: '/x402/data-item/unsigned',
126
+ // Only reached when no signer was supplied; the x402 path recomputes this
127
+ // from `unsignedData`. Both must name the same route.
128
+ endpoint: http_js_2.x402UploadEndpoints.unsigned,
127
129
  signal,
128
130
  headers: tags !== undefined
129
131
  ? { 'x-data-item-tags': JSON.stringify(tags) }
@@ -142,7 +144,6 @@ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadServ
142
144
  'solana',
143
145
  'base-eth',
144
146
  'base-usdc',
145
- 'base-ario',
146
147
  ];
147
148
  this.signer = signer;
148
149
  this.paymentService = paymentService;
@@ -37,7 +37,7 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
37
37
  // Import the TurboAuthenticatedUploadService class from the node upload module
38
38
  return new upload_js_1.TurboAuthenticatedUploadService(config);
39
39
  }
40
- static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, tokenMap, gatewayUrl, tokenTools, walletAdapter, cuUrl, processId, }) {
40
+ static authenticated({ privateKey, signer: providedSigner, paymentServiceConfig = {}, uploadServiceConfig = {}, token, tokenMap, gatewayUrl, tokenTools, walletAdapter, }) {
41
41
  return new TurboFactory().getAuthenticatedTurbo({
42
42
  privateKey,
43
43
  signer: providedSigner,
@@ -48,8 +48,6 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
48
48
  gatewayUrl,
49
49
  tokenTools,
50
50
  walletAdapter,
51
- processId,
52
- cuUrl,
53
51
  logger: this.logger,
54
52
  });
55
53
  }
package/lib/cjs/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validChunkingModes = exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.multipartFinalizedStatus = exports.multipartFailedStatus = exports.multipartPendingStatus = exports.X402Funding = exports.OnDemandFunding = exports.ExistingBalanceFunding = exports.supportedEvmSignerTokens = exports.tokenTypes = exports.fiatCurrencyTypes = void 0;
3
+ exports.arNSFiatPurchaseMethods = exports.arNSActions = exports.arNSPurchaseIntents = exports.validChunkingModes = exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.multipartFinalizedStatus = exports.multipartFailedStatus = exports.multipartPendingStatus = exports.X402Funding = exports.OnDemandFunding = exports.ExistingBalanceFunding = exports.supportedEvmSignerTokens = exports.tokenTypes = exports.fiatCurrencyTypes = void 0;
4
4
  exports.isCurrency = isCurrency;
5
5
  exports.isKyvePrivateKey = isKyvePrivateKey;
6
6
  exports.isEthPrivateKey = isEthPrivateKey;
@@ -25,7 +25,6 @@ function isCurrency(currency) {
25
25
  exports.tokenTypes = [
26
26
  'arweave',
27
27
  'ario',
28
- 'base-ario',
29
28
  'solana',
30
29
  'ethereum',
31
30
  'kyve',
@@ -44,7 +43,6 @@ exports.supportedEvmSignerTokens = new Set([
44
43
  'polygon-usdc',
45
44
  'usdc',
46
45
  'base-usdc',
47
- 'base-ario',
48
46
  ]);
49
47
  class ExistingBalanceFunding {
50
48
  }
@@ -108,3 +106,46 @@ function isEthereumWalletAdapter(walletAdapter) {
108
106
  return 'getSigner' in walletAdapter;
109
107
  }
110
108
  exports.validChunkingModes = ['force', 'disabled', 'auto'];
109
+ // ===== ArNS purchases paid with Turbo credits (via the bundler REST API) =====
110
+ exports.arNSPurchaseIntents = [
111
+ 'Buy-Name',
112
+ 'Extend-Lease',
113
+ 'Increase-Undername-Limit',
114
+ 'Upgrade-Name',
115
+ ];
116
+ // ===== ArNS actions (sponsored — the current bundler surface) =====
117
+ /**
118
+ * The nine sponsored ArNS actions.
119
+ *
120
+ * NOT included, because the bundler does not sponsor them: `primary-name`,
121
+ * `release-name`, `reassign`, and ANT metadata (name/description/keywords/logo).
122
+ * Those stay on the direct-signer path and cost the user SOL.
123
+ */
124
+ exports.arNSActions = [
125
+ 'buy-name',
126
+ 'extend-lease',
127
+ 'upgrade-name',
128
+ 'increase-undername-limit',
129
+ 'set-record',
130
+ 'remove-record',
131
+ 'add-controller',
132
+ 'remove-controller',
133
+ 'transfer',
134
+ ];
135
+ // ===== ArNS purchases paid with fiat (Stripe) — no Turbo Credits in between ====
136
+ /**
137
+ * Stripe integration mode for a fiat ArNS purchase quote.
138
+ *
139
+ * - `payment-intent` — returns a Stripe PaymentIntent. Confirm it client-side
140
+ * with `stripe.confirmCardPayment(paymentSession.client_secret, ...)`.
141
+ * - `checkout-session` — returns a Stripe Checkout Session to redirect to
142
+ * (`uiMode: 'hosted'`) or embed (`uiMode: 'embedded'`).
143
+ *
144
+ * Widened with `string & Record<never, never>` so a method added service-side is
145
+ * still callable without an SDK bump, while the known values keep autocomplete.
146
+ * (`string & {}` is the usual idiom but trips the `ban-types` lint rule.)
147
+ */
148
+ exports.arNSFiatPurchaseMethods = [
149
+ 'payment-intent',
150
+ 'checkout-session',
151
+ ];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultProdAoConfigs = exports.defaultProdGatewayUrls = exports.tokenToDevAoConfigMap = exports.tokenToDevGatewayMap = void 0;
3
+ exports.defaultProdGatewayUrls = exports.tokenToDevGatewayMap = void 0;
4
4
  exports.sleep = sleep;
5
5
  exports.isWeb = isWeb;
6
6
  exports.createTurboSigner = createTurboSigner;
@@ -49,8 +49,7 @@ const polygonTestnetRpc = 'https://rpc-amoy.polygon.technology';
49
49
  const baseMainnetRpc = 'https://mainnet.base.org';
50
50
  exports.tokenToDevGatewayMap = {
51
51
  arweave: 'https://turbo-gateway.com', // No arweave test net
52
- ario: 'https://turbo-gateway.com', // No arweave test net
53
- 'base-ario': baseMainnetRpc, // No base-ario test net contract deployed
52
+ ario: 'https://api.devnet.solana.com',
54
53
  solana: 'https://api.devnet.solana.com',
55
54
  ethereum: ethTestnetRpc,
56
55
  'base-eth': baseTestnetRpc,
@@ -61,16 +60,9 @@ exports.tokenToDevGatewayMap = {
61
60
  'base-usdc': baseTestnetRpc,
62
61
  'polygon-usdc': polygonTestnetRpc,
63
62
  };
64
- exports.tokenToDevAoConfigMap = {
65
- ario: {
66
- processId: 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA',
67
- cuUrl: 'https://cu.ardrive.io',
68
- },
69
- };
70
63
  exports.defaultProdGatewayUrls = {
71
64
  arweave: 'https://turbo-gateway.com',
72
- ario: 'https://turbo-gateway.com',
73
- 'base-ario': baseMainnetRpc,
65
+ ario: 'https://api.mainnet-beta.solana.com',
74
66
  solana: 'https://api.mainnet-beta.solana.com',
75
67
  ethereum: 'https://cloudflare-eth.com/',
76
68
  'base-eth': baseMainnetRpc,
@@ -81,12 +73,6 @@ exports.defaultProdGatewayUrls = {
81
73
  'base-usdc': baseMainnetRpc,
82
74
  'polygon-usdc': 'https://polygon-rpc.com/',
83
75
  };
84
- exports.defaultProdAoConfigs = {
85
- ario: {
86
- processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE',
87
- cuUrl: 'https://cu.ardrive.io',
88
- },
89
- };
90
76
  function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientProvidedPrivateKey, token = 'arweave', }) {
91
77
  if (clientProvidedSigner !== undefined) {
92
78
  if (clientProvidedSigner instanceof arbundles_1.InjectedEthereumSigner) {
@@ -106,6 +92,7 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
106
92
  }
107
93
  switch (token) {
108
94
  case 'solana':
95
+ case 'ario':
109
96
  return new arbundles_1.HexSolanaSigner(clientProvidedPrivateKey);
110
97
  case 'ethereum':
111
98
  case 'pol':
@@ -113,7 +100,6 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
113
100
  case 'base-eth':
114
101
  case 'usdc':
115
102
  case 'base-usdc':
116
- case 'base-ario':
117
103
  case 'polygon-usdc':
118
104
  if (!(0, types_js_1.isEthPrivateKey)(clientProvidedPrivateKey)) {
119
105
  throw new Error('A valid Ethereum private key must be provided for EthereumSigner.');
@@ -125,7 +111,6 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
125
111
  }
126
112
  return signerFromKyvePrivateKey(clientProvidedPrivateKey);
127
113
  case 'arweave':
128
- case 'ario':
129
114
  if (!(0, types_js_1.isJWK)(clientProvidedPrivateKey)) {
130
115
  throw new Error('A JWK must be provided for ArweaveSigner.');
131
116
  }
@@ -170,8 +155,8 @@ function isValidKyveAddress(address) {
170
155
  function isValidUserAddress(address, type) {
171
156
  switch (type) {
172
157
  case 'arweave':
173
- case 'ario':
174
158
  return isValidArweaveBase64URL(address);
159
+ case 'ario':
175
160
  case 'solana':
176
161
  return isValidSolanaAddress(address);
177
162
  case 'ethereum':
@@ -179,7 +164,6 @@ function isValidUserAddress(address, type) {
179
164
  case 'matic':
180
165
  case 'pol':
181
166
  case 'base-usdc':
182
- case 'base-ario':
183
167
  case 'usdc':
184
168
  case 'polygon-usdc':
185
169
  return isValidECDSAAddress(address);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbortError = exports.ProvidedInputError = exports.FailedRequestError = exports.UnauthenticatedRequestError = exports.BaseError = void 0;
3
+ exports.AbortError = exports.FiatPaymentsDisabledError = exports.InsufficientCreditsError = exports.ProvidedInputError = exports.FailedRequestError = exports.UnauthenticatedRequestError = exports.BaseError = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
6
  *
@@ -42,6 +42,43 @@ class ProvidedInputError extends BaseError {
42
42
  }
43
43
  }
44
44
  exports.ProvidedInputError = ProvidedInputError;
45
+ /**
46
+ * Raised when a credit-paid operation (e.g. an ArNS purchase) is rejected by the
47
+ * service because the paying wallet does not hold enough Turbo credits. Maps the
48
+ * bundler's HTTP `402 Payment Required` response to a typed, catchable error so
49
+ * callers can prompt a top-up without string-matching on messages.
50
+ *
51
+ * Recovery: top up the balance, then retry the SAME operation reusing the
52
+ * captured `nonce` (the nonce is the idempotency key), or mint a fresh request.
53
+ */
54
+ class InsufficientCreditsError extends BaseError {
55
+ constructor(message) {
56
+ super(message ??
57
+ 'Insufficient Turbo credits to complete this purchase. Top up your balance and retry.');
58
+ /** Always the HTTP status that produced this error. */
59
+ this.status = 402;
60
+ }
61
+ }
62
+ exports.InsufficientCreditsError = InsufficientCreditsError;
63
+ /**
64
+ * Raised when the payment service has fiat (Stripe) payments switched off, which
65
+ * it signals with `503` and the body "Fiat (Stripe) ArNS payments are disabled".
66
+ * This is a normal state in the testnet sandbox, not an outage.
67
+ *
68
+ * Distinguished from a generic `503` deliberately: the same status is also used
69
+ * for internal errors (body "Internal Server Error: ..."), so status alone is
70
+ * ambiguous. Recovery: fall back to the credit-paid path (`buyArNSName` and
71
+ * friends), or surface fiat checkout as unavailable.
72
+ */
73
+ class FiatPaymentsDisabledError extends BaseError {
74
+ constructor(message) {
75
+ super(message ??
76
+ 'Fiat (Stripe) payments are disabled on this payment service. Use the credit-paid purchase path instead.');
77
+ /** Always the HTTP status that produced this error. */
78
+ this.status = 503;
79
+ }
80
+ }
81
+ exports.FiatPaymentsDisabledError = FiatPaymentsDisabledError;
45
82
  class AbortError extends BaseError {
46
83
  constructor(message = 'Request was aborted') {
47
84
  super(message);