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

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 (50) hide show
  1. package/bundles/web.bundle.min.js +147 -126
  2. package/lib/cjs/cli/commands/antCommands.js +3 -4
  3. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -6
  4. package/lib/cjs/cli/commands/gatewayWriteCommands.js +11 -12
  5. package/lib/cjs/cli/commands/readCommands.js +21 -22
  6. package/lib/cjs/cli/commands/transfer.js +6 -7
  7. package/lib/cjs/cli/options.js +0 -12
  8. package/lib/cjs/cli/utils.js +52 -74
  9. package/lib/cjs/common/ant-versions.js +5 -5
  10. package/lib/cjs/common/faucet.js +2 -2
  11. package/lib/cjs/common/io.js +16 -52
  12. package/lib/cjs/types/ant.js +2 -2
  13. package/lib/cjs/types/io.js +5 -5
  14. package/lib/cjs/utils/ao.js +9 -9
  15. package/lib/cjs/utils/arweave.js +4 -4
  16. package/lib/cjs/utils/base64.js +4 -5
  17. package/lib/cjs/utils/json.js +1 -2
  18. package/lib/cjs/utils/schema.js +1 -2
  19. package/lib/cjs/version.js +1 -1
  20. package/lib/esm/cli/options.js +0 -12
  21. package/lib/esm/cli/utils.js +10 -31
  22. package/lib/esm/common/ant-versions.js +5 -5
  23. package/lib/esm/common/io.js +16 -52
  24. package/lib/esm/types/io.js +1 -1
  25. package/lib/esm/version.js +1 -1
  26. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  27. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  28. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  29. package/lib/types/cli/commands/readCommands.d.ts +3 -4
  30. package/lib/types/cli/commands/transfer.d.ts +3 -3
  31. package/lib/types/cli/options.d.ts +0 -9
  32. package/lib/types/cli/types.d.ts +0 -3
  33. package/lib/types/cli/utils.d.ts +0 -4
  34. package/lib/types/common/ant-versions.d.ts +6 -3
  35. package/lib/types/common/http.d.ts +0 -1
  36. package/lib/types/common/io.d.ts +6 -9
  37. package/lib/types/types/common.d.ts +1 -7
  38. package/lib/types/types/io.d.ts +7 -8
  39. package/lib/types/types/token.d.ts +0 -1
  40. package/lib/types/utils/base64.d.ts +0 -1
  41. package/package.json +1 -2
  42. package/lib/cjs/common/turbo.js +0 -134
  43. package/lib/cjs/utils/url.js +0 -28
  44. package/lib/cjs/utils/url.test.js +0 -24
  45. package/lib/esm/common/turbo.js +0 -129
  46. package/lib/esm/utils/url.js +0 -24
  47. package/lib/esm/utils/url.test.js +0 -19
  48. package/lib/types/common/turbo.d.ts +0 -47
  49. package/lib/types/utils/url.d.ts +0 -19
  50. package/lib/types/utils/url.test.d.ts +0 -1
@@ -1,5 +1,5 @@
1
1
  import { AoANTVersionsRead, AoANTVersionsWrite } from '../types/ant.js';
2
- import { AoMessageResult, WithSigner } from '../types/common.js';
2
+ import { WithSigner } from '../types/common.js';
3
3
  import { ProcessConfiguration } from '../types/io.js';
4
4
  import { AOProcess } from './contracts/ao-process.js';
5
5
  type ANTVersionsNoSigner = ProcessConfiguration;
@@ -27,13 +27,16 @@ export declare class ANTVersionsReadable implements AoANTVersionsRead {
27
27
  export declare class ANTVersionsWritable extends ANTVersionsReadable implements AoANTVersionsWrite {
28
28
  private signer;
29
29
  constructor({ signer, ...config }: WithSigner<ProcessConfiguration>);
30
- addVersion({ version, moduleId, luaSourceId, notes, }: {
30
+ addVersion(params: {
31
31
  version: string;
32
32
  moduleId: string;
33
33
  luaSourceId?: string;
34
34
  notes?: string;
35
35
  }, { tags }: {
36
36
  tags: any;
37
- }): Promise<AoMessageResult>;
37
+ }): Promise<{
38
+ id: string;
39
+ result?: unknown;
40
+ }>;
38
41
  }
39
42
  export {};
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { HTTPClient } from '../types/index.js';
3
2
  import { ILogger } from './logger.js';
4
3
  export declare class AxiosHTTPService implements HTTPClient {
@@ -1,9 +1,8 @@
1
1
  import Arweave from 'arweave';
2
- import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionData, AoEpochDistributionTotalsData, AoEpochObservationData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGatewayWithAddress, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoJoinNetworkParams, AoMessageResult, AoPaginatedAddressParams, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoRegistrationFees, AoReturnedName, AoRevokeVaultParams, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, AoWeightedObserver, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
2
+ import { ARIOWithFaucet, AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSNameDataWithName, AoArNSPurchaseParams, AoArNSReservedNameData, AoArNSReservedNameDataWithName, AoBalanceWithAddress, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionData, AoEpochDistributionTotalsData, AoEpochObservationData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGatewayWithAddress, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoJoinNetworkParams, AoMessageResult, AoPaginatedAddressParams, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoRegistrationFees, AoReturnedName, AoRevokeVaultParams, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, AoWeightedObserver, CostDetailsResult, DemandFactorSettings, EpochInput, OptionalArweave, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
3
3
  import { AOProcess } from './contracts/ao-process.js';
4
- import { TurboArNSPaymentProvider } from './turbo.js';
5
- type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>;
6
- type ARIOConfigWithSigner = WithSigner<OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>>;
4
+ type ARIOConfigNoSigner = OptionalArweave<ProcessConfiguration>;
5
+ type ARIOConfigWithSigner = WithSigner<OptionalArweave<ProcessConfiguration>>;
7
6
  export declare class ARIO {
8
7
  static init(): AoARIORead;
9
8
  static init(config: ARIOConfigWithSigner): AoARIOWrite;
@@ -27,8 +26,7 @@ export declare class ARIOReadable implements AoARIORead {
27
26
  readonly process: AOProcess;
28
27
  protected epochSettings: AoEpochSettings | undefined;
29
28
  protected arweave: Arweave;
30
- protected paymentProvider: TurboArNSPaymentProvider;
31
- constructor(config?: ARIOConfigNoSigner);
29
+ constructor(config?: OptionalArweave<ProcessConfiguration>);
32
30
  getInfo(): Promise<{
33
31
  Name: string;
34
32
  Ticker: string;
@@ -43,8 +41,8 @@ export declare class ARIOReadable implements AoARIORead {
43
41
  private computeCurrentEpochIndex;
44
42
  private computeEpochIndex;
45
43
  getEpochSettings(): Promise<AoEpochSettings>;
46
- getEpoch(): Promise<AoEpochData<AoEpochDistributionTotalsData>>;
47
44
  getEpoch(epoch: EpochInput): Promise<AoEpochData<AoEpochDistributed>>;
45
+ getEpoch(): Promise<AoEpochData<AoEpochDistributionTotalsData>>;
48
46
  getArNSRecord({ name }: {
49
47
  name: string;
50
48
  }): Promise<AoArNSNameData>;
@@ -143,8 +141,7 @@ export declare class ARIOReadable implements AoARIORead {
143
141
  export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
144
142
  readonly process: AOProcess;
145
143
  private signer;
146
- protected paymentProvider: TurboArNSPaymentProvider;
147
- constructor({ signer, paymentUrl, ...config }: ARIOConfigWithSigner);
144
+ constructor({ signer, ...config }: ARIOConfigWithSigner);
148
145
  transfer({ target, qty, }: {
149
146
  target: string;
150
147
  qty: number | mARIOToken;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
4
3
  *
@@ -27,10 +26,6 @@ export type ProcessId = string;
27
26
  export type OptionalArweave<T = NonNullable<unknown>> = {
28
27
  arweave?: Arweave;
29
28
  } & T;
30
- export type OptionalPaymentUrl<T = NonNullable<unknown>> = {
31
- paymentUrl?: string;
32
- } & T;
33
- export type TurboArNSSigner = Signer;
34
29
  export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
35
30
  export type WithSigner<T = NonNullable<unknown>> = {
36
31
  signer: ContractSigner;
@@ -49,9 +44,8 @@ export type WriteOptions = {
49
44
  }[];
50
45
  };
51
46
  export type WriteParameters<Input> = WithSigner<Required<ReadParameters<Input>>>;
52
- export type AoMessageResult<T = Record<string, string | number | boolean | null>> = {
47
+ export type AoMessageResult = {
53
48
  id: string;
54
- result?: T;
55
49
  };
56
50
  export type AoPrimaryNameRequest = {
57
51
  name: string;
@@ -301,7 +301,7 @@ export type AoRedelegateStakeParams = {
301
301
  export declare const validIntents: readonly ["Buy-Name", "Buy-Record", "Extend-Lease", "Increase-Undername-Limit", "Upgrade-Name", "Primary-Name-Request"];
302
302
  export declare const intentsUsingYears: readonly ["Buy-Record", "Buy-Name", "Extend-Lease"];
303
303
  export type Intent = (typeof validIntents)[number];
304
- export declare const isValidIntent: (intent: string) => intent is "Buy-Name" | "Buy-Record" | "Extend-Lease" | "Increase-Undername-Limit" | "Upgrade-Name" | "Primary-Name-Request";
304
+ export declare const isValidIntent: (intent: string) => intent is Intent;
305
305
  export type AoTokenCostParams = {
306
306
  intent: Intent;
307
307
  type?: 'permabuy' | 'lease';
@@ -310,9 +310,9 @@ export type AoTokenCostParams = {
310
310
  quantity?: number;
311
311
  fromAddress?: WalletAddress;
312
312
  };
313
- export declare const fundFromOptions: readonly ["balance", "stakes", "any", "turbo"];
313
+ export declare const fundFromOptions: readonly ["balance", "stakes", "any"];
314
314
  export type FundFrom = (typeof fundFromOptions)[number];
315
- export declare const isValidFundFrom: (fundFrom: string) => fundFrom is "balance" | "stakes" | "any" | "turbo";
315
+ export declare const isValidFundFrom: (fundFrom: string) => fundFrom is FundFrom;
316
316
  export type AoGetCostDetailsParams = AoTokenCostParams & {
317
317
  fundFrom?: FundFrom;
318
318
  };
@@ -338,7 +338,6 @@ export type CostDetailsResult = {
338
338
  basePrice: number;
339
339
  };
340
340
  fundingPlan?: AoFundingPlan;
341
- wincQty?: string;
342
341
  };
343
342
  export type AoGetVaultParams = {
344
343
  address: WalletAddress;
@@ -524,10 +523,10 @@ export interface AoARIOWrite extends AoARIORead {
524
523
  reportTxId: TransactionId;
525
524
  failedGateways: WalletAddress[];
526
525
  }>;
527
- buyRecord: AoWriteAction<AoBuyRecordParams, AoMessageResult>;
528
- upgradeRecord: AoWriteAction<AoArNSPurchaseParams, AoMessageResult>;
529
- extendLease: AoWriteAction<AoExtendLeaseParams, AoMessageResult>;
530
- increaseUndernameLimit: AoWriteAction<AoIncreaseUndernameLimitParams, AoMessageResult>;
526
+ buyRecord: AoWriteAction<AoBuyRecordParams>;
527
+ upgradeRecord: AoWriteAction<AoArNSPurchaseParams>;
528
+ extendLease: AoWriteAction<AoExtendLeaseParams>;
529
+ increaseUndernameLimit: AoWriteAction<AoIncreaseUndernameLimitParams>;
531
530
  cancelWithdrawal: AoWriteAction<{
532
531
  gatewayAddress?: WalletAddress;
533
532
  vaultId: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  interface Equatable<T> {
3
2
  equals(other: T): boolean;
4
3
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export declare function fromB64Url(str: string): Buffer;
3
2
  export declare function toB64Url(buffer: Buffer): string;
4
3
  export declare function sha256B64Url(input: Buffer): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.10.0-alpha.2",
3
+ "version": "3.10.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -133,7 +133,6 @@
133
133
  "eventemitter3": "^5.0.1",
134
134
  "plimit-lit": "^3.0.1",
135
135
  "prompts": "^2.4.2",
136
- "uuid": "^11.1.0",
137
136
  "winston": "^3.13.0",
138
137
  "zod": "^3.23.8"
139
138
  },
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboArNSPaymentProvider = exports.signedRequestHeadersFromSigner = void 0;
4
- /**
5
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const arbundles_1 = require("@dha-team/arbundles");
20
- const uuid_1 = require("uuid");
21
- const token_js_1 = require("../types/token.js");
22
- const base64_js_1 = require("../utils/base64.js");
23
- const http_client_js_1 = require("../utils/http-client.js");
24
- const url_js_1 = require("../utils/url.js");
25
- const logger_js_1 = require("./logger.js");
26
- async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)(), }) {
27
- await signer.setPublicKey?.();
28
- const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
29
- let publicKey;
30
- switch (signer.signatureType) {
31
- case arbundles_1.SignatureConfig.ARWEAVE:
32
- publicKey = (0, base64_js_1.toB64Url)(signer.publicKey);
33
- break;
34
- case arbundles_1.SignatureConfig.ETHEREUM:
35
- publicKey = '0x' + signer.publicKey.toString('hex');
36
- break;
37
- // TODO: solana sig support
38
- // case SignatureConfig.SOLANA:
39
- // case SignatureConfig.ED25519:
40
- default:
41
- throw new Error(`Unsupported signer type for signing requests: ${signer.signatureType}`);
42
- }
43
- return {
44
- 'x-public-key': publicKey,
45
- 'x-nonce': nonce,
46
- 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
47
- 'x-signature-type': signer.signatureType,
48
- };
49
- }
50
- exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
51
- class TurboArNSPaymentProvider {
52
- paymentUrl;
53
- axios;
54
- logger;
55
- signer;
56
- constructor({ paymentUrl = 'https://payment.ardrive.io', axios = (0, http_client_js_1.createAxiosInstance)(), logger = logger_js_1.Logger.default, signer, }) {
57
- this.paymentUrl = paymentUrl;
58
- this.axios = axios;
59
- this.logger = logger;
60
- this.signer = signer;
61
- }
62
- async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
63
- const url = (0, url_js_1.urlWithSearchParams)({
64
- baseUrl: `${this.paymentUrl}/v1/arns/price/${intent}/${name}`,
65
- params: {
66
- increaseQty: quantity,
67
- type,
68
- years,
69
- },
70
- });
71
- const { data, status } = await this.axios.get(url);
72
- this.logger.debug('getArNSPriceDetails', {
73
- intent,
74
- name,
75
- quantity,
76
- type,
77
- years,
78
- data,
79
- status,
80
- });
81
- if (status !== 200) {
82
- throw new Error('Failed to get ArNS purchase price ' + JSON.stringify(data));
83
- }
84
- if (!data.winc || !data.mARIO) {
85
- throw new Error('Invalid response from Turbo ' + JSON.stringify(data));
86
- }
87
- return {
88
- winc: data.winc,
89
- mARIO: new token_js_1.mARIOToken(+data.mARIO),
90
- };
91
- }
92
- async getPrice(params) {
93
- const { winc } = await this.getArNSPriceDetails(params);
94
- return +winc;
95
- }
96
- async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
97
- if (!this.signer) {
98
- throw new Error('Signer required for initiating ArNS purchase with Turbo');
99
- }
100
- const url = (0, url_js_1.urlWithSearchParams)({
101
- baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
102
- params: {
103
- increaseQty: quantity,
104
- processId,
105
- type,
106
- years,
107
- },
108
- });
109
- const headers = await signedRequestHeadersFromSigner({
110
- signer: this.signer,
111
- });
112
- const { data, status } = await this.axios.post(url, null, {
113
- headers,
114
- });
115
- this.logger.debug('Initiated ArNS purchase', {
116
- intent,
117
- name,
118
- quantity,
119
- processId,
120
- type,
121
- years,
122
- data,
123
- status,
124
- });
125
- if (status !== 200) {
126
- throw new Error('Failed to initiate ArNS purchase ' + JSON.stringify(data));
127
- }
128
- return {
129
- id: data.arioWriteResult.id,
130
- result: data.purchaseReceipt,
131
- };
132
- }
133
- }
134
- exports.TurboArNSPaymentProvider = TurboArNSPaymentProvider;
@@ -1,28 +0,0 @@
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;
@@ -1,24 +0,0 @@
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
- });
@@ -1,129 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { SignatureConfig } from '@dha-team/arbundles';
17
- import { v4 as uuidv4 } from 'uuid';
18
- import { mARIOToken } from '../types/token.js';
19
- import { toB64Url } from '../utils/base64.js';
20
- import { createAxiosInstance } from '../utils/http-client.js';
21
- import { urlWithSearchParams } from '../utils/url.js';
22
- import { Logger } from './logger.js';
23
- export async function signedRequestHeadersFromSigner({ signer, nonce = uuidv4(), }) {
24
- await signer.setPublicKey?.();
25
- const signature = await signer.sign(Uint8Array.from(Buffer.from(nonce)));
26
- let publicKey;
27
- switch (signer.signatureType) {
28
- case SignatureConfig.ARWEAVE:
29
- publicKey = toB64Url(signer.publicKey);
30
- break;
31
- case SignatureConfig.ETHEREUM:
32
- publicKey = '0x' + signer.publicKey.toString('hex');
33
- break;
34
- // TODO: solana sig support
35
- // case SignatureConfig.SOLANA:
36
- // case SignatureConfig.ED25519:
37
- default:
38
- throw new Error(`Unsupported signer type for signing requests: ${signer.signatureType}`);
39
- }
40
- return {
41
- 'x-public-key': publicKey,
42
- 'x-nonce': nonce,
43
- 'x-signature': toB64Url(Buffer.from(signature)),
44
- 'x-signature-type': signer.signatureType,
45
- };
46
- }
47
- export class TurboArNSPaymentProvider {
48
- paymentUrl;
49
- axios;
50
- logger;
51
- signer;
52
- constructor({ paymentUrl = 'https://payment.ardrive.io', axios = createAxiosInstance(), logger = Logger.default, signer, }) {
53
- this.paymentUrl = paymentUrl;
54
- this.axios = axios;
55
- this.logger = logger;
56
- this.signer = signer;
57
- }
58
- async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
59
- const url = urlWithSearchParams({
60
- baseUrl: `${this.paymentUrl}/v1/arns/price/${intent}/${name}`,
61
- params: {
62
- increaseQty: quantity,
63
- type,
64
- years,
65
- },
66
- });
67
- const { data, status } = await this.axios.get(url);
68
- this.logger.debug('getArNSPriceDetails', {
69
- intent,
70
- name,
71
- quantity,
72
- type,
73
- years,
74
- data,
75
- status,
76
- });
77
- if (status !== 200) {
78
- throw new Error('Failed to get ArNS purchase price ' + JSON.stringify(data));
79
- }
80
- if (!data.winc || !data.mARIO) {
81
- throw new Error('Invalid response from Turbo ' + JSON.stringify(data));
82
- }
83
- return {
84
- winc: data.winc,
85
- mARIO: new mARIOToken(+data.mARIO),
86
- };
87
- }
88
- async getPrice(params) {
89
- const { winc } = await this.getArNSPriceDetails(params);
90
- return +winc;
91
- }
92
- async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
93
- if (!this.signer) {
94
- throw new Error('Signer required for initiating ArNS purchase with Turbo');
95
- }
96
- const url = urlWithSearchParams({
97
- baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
98
- params: {
99
- increaseQty: quantity,
100
- processId,
101
- type,
102
- years,
103
- },
104
- });
105
- const headers = await signedRequestHeadersFromSigner({
106
- signer: this.signer,
107
- });
108
- const { data, status } = await this.axios.post(url, null, {
109
- headers,
110
- });
111
- this.logger.debug('Initiated ArNS purchase', {
112
- intent,
113
- name,
114
- quantity,
115
- processId,
116
- type,
117
- years,
118
- data,
119
- status,
120
- });
121
- if (status !== 200) {
122
- throw new Error('Failed to initiate ArNS purchase ' + JSON.stringify(data));
123
- }
124
- return {
125
- id: data.arioWriteResult.id,
126
- result: data.purchaseReceipt,
127
- };
128
- }
129
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export const urlWithSearchParams = ({ baseUrl, params, }) => {
17
- const urlObj = new URL(baseUrl);
18
- Object.entries(params).forEach(([key, value]) => {
19
- if (value === undefined || value === null)
20
- return;
21
- urlObj.searchParams.set(key, value.toString());
22
- });
23
- return urlObj.toString();
24
- };
@@ -1,19 +0,0 @@
1
- import assert from 'node:assert';
2
- import { test } from 'node:test';
3
- import { urlWithSearchParams } from './url.js';
4
- test('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
5
- const result = urlWithSearchParams({
6
- baseUrl: 'https://example.com',
7
- params: {
8
- number: 1,
9
- string: 'string',
10
- boolean: true,
11
- empty: '',
12
- zero: 0,
13
- false: false,
14
- null: null,
15
- undef: undefined,
16
- },
17
- });
18
- assert.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
19
- });
@@ -1,47 +0,0 @@
1
- import { AxiosInstance, RawAxiosRequestHeaders } from 'axios';
2
- import { AoMessageResult, TransactionId, TurboArNSSigner, WriteOptions } from '../types/common.js';
3
- import { AoTokenCostParams } from '../types/io.js';
4
- import { mARIOToken } from '../types/token.js';
5
- import { ILogger } from './logger.js';
6
- export interface TurboConfig {
7
- paymentUrl?: string;
8
- logger?: ILogger;
9
- axios?: AxiosInstance;
10
- signer?: TurboArNSSigner;
11
- }
12
- export declare function signedRequestHeadersFromSigner({ signer, nonce, }: {
13
- signer: TurboArNSSigner;
14
- nonce?: string;
15
- }): Promise<RawAxiosRequestHeaders>;
16
- export type ArNSPurchaseReceipt = AoTokenCostParams & {
17
- wincQty: string;
18
- mARIOQty: string;
19
- usdArRate: number;
20
- createdDate: string;
21
- };
22
- export interface ArNSPaymentProvider {
23
- /** Returns the cost of the action in the Payment Provider's native currency (winc for Turbo) */
24
- getPrice(params: AoTokenCostParams): Promise<number>;
25
- getArNSPriceDetails(params: AoTokenCostParams): Promise<{
26
- winc: string;
27
- mARIO: mARIOToken;
28
- }>;
29
- initiateArNSPurchase(params: AoTokenCostParams & {
30
- processId?: TransactionId;
31
- }, options: WriteOptions): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
32
- }
33
- export declare class TurboArNSPaymentProvider implements ArNSPaymentProvider {
34
- private readonly paymentUrl;
35
- private readonly axios;
36
- private readonly logger;
37
- private readonly signer?;
38
- constructor({ paymentUrl, axios, logger, signer, }: TurboConfig);
39
- getArNSPriceDetails({ intent, name, quantity, type, years, }: AoTokenCostParams): Promise<{
40
- winc: string;
41
- mARIO: mARIOToken;
42
- }>;
43
- getPrice(params: AoTokenCostParams): Promise<number>;
44
- initiateArNSPurchase({ intent, name, quantity, type, processId, years, }: AoTokenCostParams & {
45
- processId?: TransactionId;
46
- }): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
47
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export declare const urlWithSearchParams: ({ baseUrl, params, }: {
17
- baseUrl: string;
18
- params: Record<string, string | number | boolean | null | undefined>;
19
- }) => string;
@@ -1 +0,0 @@
1
- export {};