@ar.io/sdk 3.9.1 → 3.10.0-alpha.2

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 (51) hide show
  1. package/README.md +124 -140
  2. package/bundles/web.bundle.min.js +107 -99
  3. package/lib/cjs/cli/options.js +12 -0
  4. package/lib/cjs/cli/utils.js +33 -11
  5. package/lib/cjs/common/ant-versions.js +5 -5
  6. package/lib/cjs/common/faucet.js +150 -0
  7. package/lib/cjs/common/index.js +1 -0
  8. package/lib/cjs/common/io.js +107 -4
  9. package/lib/cjs/common/turbo.js +134 -0
  10. package/lib/cjs/types/faucet.js +2 -0
  11. package/lib/cjs/types/index.js +1 -0
  12. package/lib/cjs/types/io.js +4 -3
  13. package/lib/cjs/utils/ao.js +2 -0
  14. package/lib/cjs/utils/url.js +28 -0
  15. package/lib/cjs/utils/url.test.js +24 -0
  16. package/lib/cjs/version.js +1 -1
  17. package/lib/esm/cli/options.js +12 -0
  18. package/lib/esm/cli/utils.js +31 -10
  19. package/lib/esm/common/ant-versions.js +5 -5
  20. package/lib/esm/common/faucet.js +145 -0
  21. package/lib/esm/common/index.js +1 -0
  22. package/lib/esm/common/io.js +106 -3
  23. package/lib/esm/common/turbo.js +129 -0
  24. package/lib/esm/types/faucet.js +1 -0
  25. package/lib/esm/types/index.js +1 -0
  26. package/lib/esm/types/io.js +4 -3
  27. package/lib/esm/utils/ao.js +2 -0
  28. package/lib/esm/utils/url.js +24 -0
  29. package/lib/esm/utils/url.test.js +19 -0
  30. package/lib/esm/version.js +1 -1
  31. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  32. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  33. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  34. package/lib/types/cli/commands/readCommands.d.ts +1 -0
  35. package/lib/types/cli/commands/transfer.d.ts +3 -3
  36. package/lib/types/cli/options.d.ts +9 -0
  37. package/lib/types/cli/types.d.ts +3 -0
  38. package/lib/types/cli/utils.d.ts +4 -0
  39. package/lib/types/common/ant-versions.d.ts +3 -6
  40. package/lib/types/common/faucet.d.ts +96 -0
  41. package/lib/types/common/index.d.ts +1 -0
  42. package/lib/types/common/io.d.ts +25 -25
  43. package/lib/types/common/turbo.d.ts +47 -0
  44. package/lib/types/types/common.d.ts +6 -1
  45. package/lib/types/types/faucet.d.ts +82 -0
  46. package/lib/types/types/index.d.ts +1 -0
  47. package/lib/types/types/io.d.ts +9 -8
  48. package/lib/types/utils/url.d.ts +19 -0
  49. package/lib/types/utils/url.test.d.ts +1 -0
  50. package/lib/types/version.d.ts +1 -1
  51. package/package.json +7 -7
@@ -28,18 +28,19 @@ const isValidIntent = (intent) => {
28
28
  return exports.validIntents.indexOf(intent) !== -1;
29
29
  };
30
30
  exports.isValidIntent = isValidIntent;
31
- exports.fundFromOptions = ['balance', 'stakes', 'any'];
31
+ exports.fundFromOptions = ['balance', 'stakes', 'any', 'turbo'];
32
32
  const isValidFundFrom = (fundFrom) => {
33
33
  return exports.fundFromOptions.indexOf(fundFrom) !== -1;
34
34
  };
35
35
  exports.isValidFundFrom = isValidFundFrom;
36
36
  // Type-guard functions
37
37
  function isProcessConfiguration(config) {
38
- return 'process' in config;
38
+ return config !== undefined && 'process' in config;
39
39
  }
40
40
  exports.isProcessConfiguration = isProcessConfiguration;
41
41
  function isProcessIdConfiguration(config) {
42
- return ('processId' in config &&
42
+ return (config !== undefined &&
43
+ 'processId' in config &&
43
44
  typeof config.processId === 'string' &&
44
45
  (0, arweave_js_1.validateArweaveId)(config.processId) === true);
45
46
  }
@@ -137,6 +137,8 @@ function createAoSigner(signer) {
137
137
  }));
138
138
  return signedData;
139
139
  };
140
+ // eslint-disable-next-line
141
+ // @ts-ignore Buffer vs ArrayBuffer type mismatch
140
142
  return aoSigner;
141
143
  }
142
144
  exports.createAoSigner = createAoSigner;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlWithSearchParams = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const urlWithSearchParams = ({ baseUrl, params, }) => {
20
+ const urlObj = new URL(baseUrl);
21
+ Object.entries(params).forEach(([key, value]) => {
22
+ if (value === undefined || value === null)
23
+ return;
24
+ urlObj.searchParams.set(key, value.toString());
25
+ });
26
+ return urlObj.toString();
27
+ };
28
+ exports.urlWithSearchParams = urlWithSearchParams;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const node_test_1 = require("node:test");
8
+ const url_js_1 = require("./url.js");
9
+ (0, node_test_1.test)('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
10
+ const result = (0, url_js_1.urlWithSearchParams)({
11
+ baseUrl: 'https://example.com',
12
+ params: {
13
+ number: 1,
14
+ string: 'string',
15
+ boolean: true,
16
+ empty: '',
17
+ zero: 0,
18
+ false: false,
19
+ null: null,
20
+ undef: undefined,
21
+ },
22
+ });
23
+ node_assert_1.default.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
24
+ });
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.9.1';
20
+ exports.version = '3.10.0-alpha.2';
@@ -49,6 +49,10 @@ export const optionMap = {
49
49
  alias: '--cu-url <cuUrl>',
50
50
  description: 'The URL for a custom compute unit',
51
51
  },
52
+ paymentUrl: {
53
+ alias: '--payment-url <paymentUrl>',
54
+ description: 'The URL for a custom turbo payment service',
55
+ },
52
56
  processId: {
53
57
  alias: '--process-id <processId>',
54
58
  description: 'The process ID to interact with',
@@ -269,9 +273,15 @@ export const optionMap = {
269
273
  alias: '--logo <logo>',
270
274
  description: 'The ANT logo',
271
275
  },
276
+ token: {
277
+ alias: '-t, --token <type>',
278
+ description: 'Crypto token type for wallet or action',
279
+ default: 'arweave',
280
+ },
272
281
  };
273
282
  export const walletOptions = [
274
283
  optionMap.walletFile,
284
+ optionMap.token,
275
285
  // optionMap.mnemonic,
276
286
  optionMap.privateKey,
277
287
  ];
@@ -289,6 +299,7 @@ export const arnsPurchaseOptions = [
289
299
  ...writeActionOptions,
290
300
  optionMap.name,
291
301
  optionMap.fundFrom,
302
+ optionMap.paymentUrl,
292
303
  ];
293
304
  export const epochOptions = [optionMap.epochIndex, optionMap.timestamp];
294
305
  export const addressAndVaultIdOptions = [optionMap.address, optionMap.vaultId];
@@ -312,6 +323,7 @@ export const tokenCostOptions = [
312
323
  optionMap.quantity,
313
324
  optionMap.address,
314
325
  optionMap.fundFrom,
326
+ optionMap.paymentUrl,
315
327
  ];
316
328
  export const transferOptions = [
317
329
  ...writeActionOptions,
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { EthereumSigner } from '@dha-team/arbundles';
16
17
  import { connect } from '@permaweb/aoconnect';
17
18
  import { program } from 'commander';
18
19
  import { readFileSync } from 'fs';
@@ -77,7 +78,7 @@ export function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
77
78
  }
78
79
  return ARIO_MAINNET_PROCESS_ID;
79
80
  }
80
- function jwkFromOptions({ privateKey, walletFile, }) {
81
+ function walletFromOptions({ privateKey, walletFile, }) {
81
82
  if (privateKey !== undefined) {
82
83
  return JSON.parse(privateKey);
83
84
  }
@@ -87,7 +88,7 @@ function jwkFromOptions({ privateKey, walletFile, }) {
87
88
  return undefined;
88
89
  }
89
90
  export function requiredJwkFromOptions(options) {
90
- const jwk = jwkFromOptions(options);
91
+ const jwk = walletFromOptions(options);
91
92
  if (jwk === undefined) {
92
93
  throw new Error('No JWK provided for signing!\nPlease provide a stringified JWK with `--private-key` or the file path of a jwk.json file with `--wallet-file`');
93
94
  }
@@ -117,13 +118,30 @@ export function readARIOFromOptions(options) {
117
118
  setLoggerIfDebug(options);
118
119
  return ARIO.init({
119
120
  process: aoProcessFromOptions(options),
121
+ paymentUrl: options.paymentUrl,
120
122
  });
121
123
  }
122
- export function requiredContractSignerFromOptions(options) {
124
+ export function contractSignerFromOptions(options) {
125
+ const wallet = walletFromOptions(options);
126
+ if (wallet === undefined) {
127
+ return undefined;
128
+ }
129
+ const token = options.token ?? 'arweave';
130
+ if (token === 'ethereum') {
131
+ const signer = new EthereumSigner(wallet);
132
+ // For EthereumSigner, we need to convert the JWK to a string
133
+ return { signer, signerAddress: signer.publicKey.toString('hex') };
134
+ }
123
135
  // TODO: Support other wallet types
124
- const jwk = requiredJwkFromOptions(options);
125
- const signer = new ArweaveSigner(jwk);
126
- return { signer, signerAddress: jwkToAddress(jwk) };
136
+ const signer = new ArweaveSigner(wallet);
137
+ return { signer, signerAddress: jwkToAddress(wallet) };
138
+ }
139
+ export function requiredContractSignerFromOptions(options) {
140
+ const contractSigner = contractSignerFromOptions(options);
141
+ if (contractSigner === undefined) {
142
+ throw new Error('No signer provided for signing!\nPlease provide a stringified JWK or Ethereum private key with `--private-key` or the file path of an arweave.jwk.json or eth.private.key.txt file with `--wallet-file`');
143
+ }
144
+ return contractSigner;
127
145
  }
128
146
  export function requiredAoSignerFromOptions(options) {
129
147
  return createAoSigner(requiredContractSignerFromOptions(options).signer);
@@ -135,6 +153,7 @@ export function writeARIOFromOptions(options) {
135
153
  ario: ARIO.init({
136
154
  process: aoProcessFromOptions(options),
137
155
  signer,
156
+ paymentUrl: options.paymentUrl,
138
157
  }),
139
158
  signerAddress,
140
159
  };
@@ -155,10 +174,9 @@ export function addressFromOptions(options) {
155
174
  if (options.address !== undefined) {
156
175
  return options.address;
157
176
  }
158
- // TODO: Support other wallet types
159
- const jwk = jwkFromOptions(options);
160
- if (jwk !== undefined) {
161
- return jwkToAddress(jwk);
177
+ const signer = contractSignerFromOptions(options);
178
+ if (signer !== undefined) {
179
+ return signer.signerAddress;
162
180
  }
163
181
  return undefined;
164
182
  }
@@ -281,6 +299,9 @@ export function requiredMARIOFromOptions(options, key) {
281
299
  return new ARIOToken(+options[key]).toMARIO();
282
300
  }
283
301
  export async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
302
+ if (costDetailsParams.fundFrom === 'turbo') {
303
+ return;
304
+ }
284
305
  const costDetails = await ario.getCostDetails(costDetailsParams);
285
306
  if (costDetails.fundingPlan) {
286
307
  if (costDetails.fundingPlan.shortfall > 0) {
@@ -70,14 +70,14 @@ export class ANTVersionsWritable extends ANTVersionsReadable {
70
70
  super(config);
71
71
  this.signer = createAoSigner(signer);
72
72
  }
73
- async addVersion(params, { tags }) {
73
+ async addVersion({ version, moduleId, luaSourceId, notes, }, { tags }) {
74
74
  return this.process.send({
75
75
  tags: pruneTags([
76
76
  { name: 'Action', value: 'Add-Version' },
77
- { name: 'Version', value: params.version },
78
- { name: 'Module-Id', value: params.moduleId },
79
- { name: 'Lua-Source-Id', value: params.luaSourceId },
80
- { name: 'Notes', value: params.notes },
77
+ { name: 'Version', value: version },
78
+ { name: 'Module-Id', value: moduleId },
79
+ { name: 'Lua-Source-Id', value: luaSourceId },
80
+ { name: 'Notes', value: notes },
81
81
  ...(tags ?? []),
82
82
  ]),
83
83
  signer: this.signer,
@@ -0,0 +1,145 @@
1
+ const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
2
+ /**
3
+ * Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
4
+ * @param arioInstance - The ARIOReadable instance
5
+ * @param faucetApiUrl - The URL of the faucet API
6
+ * @returns A proxy object that implements the TokenFaucet interface
7
+ */
8
+ export function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, }) {
9
+ const faucet = new ARIOTokenFaucet({
10
+ faucetUrl: faucetApiUrl,
11
+ processId: arioInstance.process.processId,
12
+ });
13
+ const proxy = new Proxy(arioInstance, {
14
+ get(target, prop) {
15
+ if (prop === 'faucet') {
16
+ return faucet;
17
+ }
18
+ if (prop in target) {
19
+ const result = target[prop];
20
+ if (typeof result === 'function') {
21
+ return result.bind(target);
22
+ }
23
+ return result;
24
+ }
25
+ return undefined;
26
+ },
27
+ });
28
+ return proxy;
29
+ }
30
+ export class ARIOTokenFaucet {
31
+ faucetUrl;
32
+ processId;
33
+ constructor({ faucetUrl, processId, }) {
34
+ this.faucetUrl = faucetUrl;
35
+ this.processId = processId;
36
+ }
37
+ /**
38
+ * Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
39
+ * @returns The captcha URL for a process
40
+ */
41
+ async captchaUrl() {
42
+ const res = await fetch(`${this.faucetUrl}/api/captcha/url?process-id=${this.processId}`, {
43
+ method: 'GET',
44
+ });
45
+ if (!res.ok) {
46
+ const body = await res.json().catch(() => ({ error: res.statusText }));
47
+ throw new Error(body.error);
48
+ }
49
+ const data = (await res.json());
50
+ return data;
51
+ }
52
+ /**
53
+ * Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
54
+ * @param captchaResponse - The captcha response
55
+ * @param recipient - The recipient address
56
+ * @param quantity - The quantity of tokens to claim
57
+ * @returns The claim id and success status
58
+ */
59
+ async claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }) {
60
+ const res = await fetch(`${this.faucetUrl}/api/claim/sync`, {
61
+ method: 'POST',
62
+ headers: { 'Content-Type': 'application/json' },
63
+ body: JSON.stringify({
64
+ processId: this.processId,
65
+ recipient,
66
+ quantity,
67
+ captchaResponse,
68
+ }),
69
+ });
70
+ if (!res.ok) {
71
+ const body = await res.json().catch(() => ({ error: res.statusText }));
72
+ throw new Error(body.error);
73
+ }
74
+ const data = (await res.json());
75
+ return data;
76
+ }
77
+ /**
78
+ * Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
79
+ * @param captchaResponse - The captcha response
80
+ * @returns The status of the request, the authorization token, and the expiration time
81
+ */
82
+ async requestAuthToken({ captchaResponse, }) {
83
+ const res = await fetch(`${this.faucetUrl}/api/captcha/verify`, {
84
+ method: 'POST',
85
+ headers: { 'Content-Type': 'application/json' },
86
+ body: JSON.stringify({
87
+ processId: this.processId,
88
+ captchaResponse,
89
+ }),
90
+ });
91
+ if (!res.ok) {
92
+ const body = await res.json().catch(() => ({ error: res.statusText }));
93
+ throw new Error(body.error);
94
+ }
95
+ const data = (await res.json());
96
+ return data;
97
+ }
98
+ /**
99
+ * Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
100
+ * @param authToken - The authorization token
101
+ * @param recipient - The recipient address
102
+ * @param quantity - The quantity of tokens to claim
103
+ * @returns The message id of the transfer and success status
104
+ */
105
+ async claimWithAuthToken({ authToken, recipient, quantity, }) {
106
+ const res = await fetch(`${this.faucetUrl}/api/claim/async`, {
107
+ method: 'POST',
108
+ headers: {
109
+ 'Content-Type': 'application/json',
110
+ Authorization: `Bearer ${authToken}`,
111
+ },
112
+ body: JSON.stringify({
113
+ recipient,
114
+ qty: quantity,
115
+ processId: this.processId,
116
+ }),
117
+ });
118
+ if (!res.ok) {
119
+ const body = await res.json().catch(() => ({ error: res.statusText }));
120
+ throw new Error(body.error);
121
+ }
122
+ const data = (await res.json());
123
+ return data;
124
+ }
125
+ /**
126
+ * Verifies an authorization token is valid.
127
+ * @param authToken - The authorization token
128
+ * @returns The validity of the authorization token and the expiration time
129
+ */
130
+ async verifyAuthToken({ authToken }) {
131
+ const res = await fetch(`${this.faucetUrl}/api/token/verify?process-id=${this.processId}`, {
132
+ method: 'GET',
133
+ headers: {
134
+ 'Content-Type': 'application/json',
135
+ Authorization: `Bearer ${authToken}`,
136
+ },
137
+ });
138
+ if (!res.ok) {
139
+ const body = await res.json().catch(() => ({ error: res.statusText }));
140
+ throw new Error(body.error);
141
+ }
142
+ const data = (await res.json());
143
+ return data;
144
+ }
145
+ }
@@ -18,6 +18,7 @@ export * from './logger.js';
18
18
  export * from './ant.js';
19
19
  export * from './ant-registry.js';
20
20
  export * from './ant-versions.js';
21
+ export * from './faucet.js';
21
22
  // ao
22
23
  export * from './io.js';
23
24
  export * from './contracts/ao-process.js';
@@ -1,10 +1,13 @@
1
- import { ARIO_MAINNET_PROCESS_ID } from '../constants.js';
2
- import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
1
+ import { connect } from '@permaweb/aoconnect';
2
+ import { ARIO_MAINNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, } from '../constants.js';
3
+ import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
3
4
  import { createAoSigner } from '../utils/ao.js';
4
5
  import { getEpochDataFromGqlWithCUFallback, paginationParamsToTags, pruneTags, removeEligibleRewardsFromEpochData, sortAndPaginateEpochDataIntoEligibleDistributions, } from '../utils/arweave.js';
5
6
  import { defaultArweave } from './arweave.js';
6
7
  import { AOProcess } from './contracts/ao-process.js';
7
8
  import { InvalidContractConfigurationError } from './error.js';
9
+ import { createFaucet } from './faucet.js';
10
+ import { TurboArNSPaymentProvider } from './turbo.js';
8
11
  export class ARIO {
9
12
  // Implementation
10
13
  static init(config) {
@@ -13,11 +16,62 @@ export class ARIO {
13
16
  }
14
17
  return new ARIOReadable(config);
15
18
  }
19
+ static mainnet(config) {
20
+ if (config !== undefined && 'signer' in config) {
21
+ return new ARIOWriteable({
22
+ ...config,
23
+ process: new AOProcess({
24
+ processId: ARIO_MAINNET_PROCESS_ID,
25
+ ao: connect({
26
+ CU_URL: 'https://cu.ardrive.io',
27
+ ...config?.process?.ao,
28
+ }),
29
+ }),
30
+ });
31
+ }
32
+ return new ARIOReadable({
33
+ ...config,
34
+ process: new AOProcess({
35
+ processId: ARIO_MAINNET_PROCESS_ID,
36
+ }),
37
+ });
38
+ }
39
+ static testnet(config) {
40
+ if (config !== undefined && 'signer' in config) {
41
+ return createFaucet({
42
+ arioInstance: new ARIOWriteable({
43
+ ...config,
44
+ process: new AOProcess({
45
+ processId: ARIO_TESTNET_PROCESS_ID,
46
+ ao: connect({
47
+ CU_URL: 'https://cu.ardrive.io',
48
+ ...config?.process?.ao,
49
+ }),
50
+ }),
51
+ }),
52
+ faucetApiUrl: config?.faucetUrl,
53
+ });
54
+ }
55
+ return createFaucet({
56
+ arioInstance: new ARIOReadable({
57
+ ...config,
58
+ process: new AOProcess({
59
+ processId: ARIO_TESTNET_PROCESS_ID,
60
+ ao: connect({
61
+ CU_URL: 'https://cu.ardrive.io',
62
+ ...config?.process?.ao,
63
+ }),
64
+ }),
65
+ }),
66
+ faucetApiUrl: config?.faucetUrl,
67
+ });
68
+ }
16
69
  }
17
70
  export class ARIOReadable {
18
71
  process;
19
72
  epochSettings;
20
73
  arweave;
74
+ paymentProvider; // TODO: this could be an array/map of payment providers
21
75
  constructor(config) {
22
76
  this.arweave = config?.arweave ?? defaultArweave;
23
77
  if (config === undefined || Object.keys(config).length === 0) {
@@ -36,6 +90,9 @@ export class ARIOReadable {
36
90
  else {
37
91
  throw new InvalidContractConfigurationError();
38
92
  }
93
+ this.paymentProvider = new TurboArNSPaymentProvider({
94
+ paymentUrl: config?.paymentUrl,
95
+ });
39
96
  }
40
97
  async getInfo() {
41
98
  return this.process.read({
@@ -367,6 +424,20 @@ export class ARIOReadable {
367
424
  // TODO: Can overload this function to refine different types of cost details params
368
425
  async getCostDetails({ intent, type, years, name, quantity, fromAddress, fundFrom, }) {
369
426
  const replacedBuyRecordWithBuyName = intent === 'Buy-Record' ? 'Buy-Name' : intent;
427
+ if (fundFrom === 'turbo') {
428
+ const { mARIO, winc } = await this.paymentProvider.getArNSPriceDetails({
429
+ intent: replacedBuyRecordWithBuyName,
430
+ name,
431
+ quantity,
432
+ type,
433
+ years,
434
+ });
435
+ return {
436
+ tokenCost: +mARIO,
437
+ wincQty: winc,
438
+ discounts: [],
439
+ };
440
+ }
370
441
  const allTags = [
371
442
  { name: 'Action', value: 'Cost-Details' },
372
443
  {
@@ -533,7 +604,8 @@ export class ARIOReadable {
533
604
  }
534
605
  export class ARIOWriteable extends ARIOReadable {
535
606
  signer;
536
- constructor({ signer, ...config }) {
607
+ paymentProvider;
608
+ constructor({ signer, paymentUrl, ...config }) {
537
609
  if (config === undefined) {
538
610
  super({
539
611
  process: new AOProcess({
@@ -545,6 +617,10 @@ export class ARIOWriteable extends ARIOReadable {
545
617
  super(config);
546
618
  }
547
619
  this.signer = createAoSigner(signer);
620
+ this.paymentProvider = new TurboArNSPaymentProvider({
621
+ signer: signer,
622
+ paymentUrl,
623
+ });
548
624
  }
549
625
  async transfer({ target, qty, }, options) {
550
626
  const { tags = [] } = options || {};
@@ -819,6 +895,12 @@ export class ARIOWriteable extends ARIOReadable {
819
895
  });
820
896
  }
821
897
  async buyRecord(params, options) {
898
+ if (params.fundFrom === 'turbo') {
899
+ return this.paymentProvider.initiateArNSPurchase({
900
+ intent: 'Buy-Name',
901
+ ...params,
902
+ });
903
+ }
822
904
  const { tags = [] } = options || {};
823
905
  const allTags = [
824
906
  ...tags,
@@ -843,6 +925,12 @@ export class ARIOWriteable extends ARIOReadable {
843
925
  * @returns {Promise<AoMessageResult>} The result of the upgrade
844
926
  */
845
927
  async upgradeRecord(params, options) {
928
+ if (params.fundFrom === 'turbo') {
929
+ return this.paymentProvider.initiateArNSPurchase({
930
+ intent: 'Upgrade-Name',
931
+ name: params.name,
932
+ });
933
+ }
846
934
  const { tags = [] } = options || {};
847
935
  const allTags = [
848
936
  ...tags,
@@ -865,6 +953,12 @@ export class ARIOWriteable extends ARIOReadable {
865
953
  * @returns {Promise<AoMessageResult>} The result of the extension
866
954
  */
867
955
  async extendLease(params, options) {
956
+ if (params.fundFrom === 'turbo') {
957
+ return this.paymentProvider.initiateArNSPurchase({
958
+ intent: 'Extend-Lease',
959
+ ...params,
960
+ });
961
+ }
868
962
  const { tags = [] } = options || {};
869
963
  const allTags = [
870
964
  ...tags,
@@ -879,6 +973,12 @@ export class ARIOWriteable extends ARIOReadable {
879
973
  });
880
974
  }
881
975
  async increaseUndernameLimit(params, options) {
976
+ if (params.fundFrom === 'turbo') {
977
+ return this.paymentProvider.initiateArNSPurchase({
978
+ intent: 'Increase-Undername-Limit',
979
+ ...params,
980
+ });
981
+ }
882
982
  const { tags = [] } = options || {};
883
983
  const allTags = [
884
984
  ...tags,
@@ -915,6 +1015,9 @@ export class ARIOWriteable extends ARIOReadable {
915
1015
  });
916
1016
  }
917
1017
  async requestPrimaryName(params, options) {
1018
+ if (params.fundFrom === 'turbo') {
1019
+ throw new Error('Turbo funding is not yet supported for primary name requests');
1020
+ }
918
1021
  const { tags = [] } = options || {};
919
1022
  const allTags = [
920
1023
  ...tags,