@ar.io/sdk 3.10.0-alpha.1 → 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 (63) hide show
  1. package/README.md +124 -140
  2. package/bundles/web.bundle.min.js +150 -126
  3. package/lib/cjs/cli/commands/antCommands.js +3 -4
  4. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -6
  5. package/lib/cjs/cli/commands/gatewayWriteCommands.js +11 -12
  6. package/lib/cjs/cli/commands/readCommands.js +21 -22
  7. package/lib/cjs/cli/commands/transfer.js +6 -7
  8. package/lib/cjs/cli/options.js +0 -12
  9. package/lib/cjs/cli/utils.js +52 -74
  10. package/lib/cjs/common/ant-versions.js +5 -5
  11. package/lib/cjs/common/faucet.js +150 -0
  12. package/lib/cjs/common/index.js +1 -0
  13. package/lib/cjs/common/io.js +71 -55
  14. package/lib/cjs/types/ant.js +2 -2
  15. package/lib/cjs/types/faucet.js +2 -0
  16. package/lib/cjs/types/index.js +1 -0
  17. package/lib/cjs/types/io.js +8 -7
  18. package/lib/cjs/utils/ao.js +11 -9
  19. package/lib/cjs/utils/arweave.js +4 -4
  20. package/lib/cjs/utils/base64.js +4 -5
  21. package/lib/cjs/utils/json.js +1 -2
  22. package/lib/cjs/utils/schema.js +1 -2
  23. package/lib/cjs/version.js +1 -1
  24. package/lib/esm/cli/options.js +0 -12
  25. package/lib/esm/cli/utils.js +10 -31
  26. package/lib/esm/common/ant-versions.js +5 -5
  27. package/lib/esm/common/faucet.js +145 -0
  28. package/lib/esm/common/index.js +1 -0
  29. package/lib/esm/common/io.js +70 -54
  30. package/lib/esm/types/index.js +1 -0
  31. package/lib/esm/types/io.js +4 -3
  32. package/lib/esm/utils/ao.js +2 -0
  33. package/lib/esm/version.js +1 -1
  34. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  35. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  36. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  37. package/lib/types/cli/commands/readCommands.d.ts +3 -4
  38. package/lib/types/cli/commands/transfer.d.ts +3 -3
  39. package/lib/types/cli/options.d.ts +0 -9
  40. package/lib/types/cli/types.d.ts +0 -3
  41. package/lib/types/cli/utils.d.ts +1 -5
  42. package/lib/types/common/ant-versions.d.ts +6 -3
  43. package/lib/types/common/faucet.d.ts +96 -0
  44. package/lib/types/common/http.d.ts +0 -1
  45. package/lib/types/common/index.d.ts +1 -0
  46. package/lib/types/common/io.d.ts +22 -13
  47. package/lib/types/types/common.d.ts +1 -7
  48. package/lib/types/types/faucet.d.ts +82 -0
  49. package/lib/types/types/index.d.ts +1 -0
  50. package/lib/types/types/io.d.ts +9 -10
  51. package/lib/types/types/token.d.ts +0 -1
  52. package/lib/types/utils/base64.d.ts +0 -1
  53. package/lib/types/version.d.ts +1 -1
  54. package/package.json +5 -7
  55. package/lib/cjs/common/turbo.js +0 -134
  56. package/lib/cjs/utils/url.js +0 -28
  57. package/lib/cjs/utils/url.test.js +0 -24
  58. package/lib/esm/common/turbo.js +0 -129
  59. package/lib/esm/utils/url.js +0 -24
  60. package/lib/esm/utils/url.test.js +0 -19
  61. package/lib/types/common/turbo.d.ts +0 -47
  62. package/lib/types/utils/url.d.ts +0 -19
  63. /package/lib/{types/utils/url.test.d.ts → esm/types/faucet.js} +0 -0
@@ -0,0 +1,96 @@
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 { ARIOWithFaucet, TokenFaucet } from '../types/faucet.js';
17
+ import { ARIOReadable, ARIOWriteable } from './io.js';
18
+ /**
19
+ * Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
20
+ * @param arioInstance - The ARIOReadable instance
21
+ * @param faucetApiUrl - The URL of the faucet API
22
+ * @returns A proxy object that implements the TokenFaucet interface
23
+ */
24
+ export declare function createFaucet({ arioInstance, faucetApiUrl, }: {
25
+ arioInstance: ARIOReadable | ARIOWriteable;
26
+ faucetApiUrl?: string;
27
+ }): ARIOWithFaucet<ARIOReadable | ARIOWriteable>;
28
+ export declare class ARIOTokenFaucet implements TokenFaucet {
29
+ private faucetUrl;
30
+ private processId;
31
+ constructor({ faucetUrl, processId, }: {
32
+ faucetUrl: string;
33
+ processId: string;
34
+ });
35
+ /**
36
+ * 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.
37
+ * @returns The captcha URL for a process
38
+ */
39
+ captchaUrl(): Promise<{
40
+ processId: string;
41
+ captchaUrl: string;
42
+ }>;
43
+ /**
44
+ * Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
45
+ * @param captchaResponse - The captcha response
46
+ * @param recipient - The recipient address
47
+ * @param quantity - The quantity of tokens to claim
48
+ * @returns The claim id and success status
49
+ */
50
+ claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }: {
51
+ captchaResponse: string;
52
+ recipient: string;
53
+ quantity: number;
54
+ }): Promise<{
55
+ id: string;
56
+ success: boolean;
57
+ }>;
58
+ /**
59
+ * 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.
60
+ * @param captchaResponse - The captcha response
61
+ * @returns The status of the request, the authorization token, and the expiration time
62
+ */
63
+ requestAuthToken({ captchaResponse, }: {
64
+ captchaResponse: string;
65
+ }): Promise<{
66
+ status: 'success' | 'error';
67
+ token: string;
68
+ expiresAt: number;
69
+ }>;
70
+ /**
71
+ * 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.
72
+ * @param authToken - The authorization token
73
+ * @param recipient - The recipient address
74
+ * @param quantity - The quantity of tokens to claim
75
+ * @returns The message id of the transfer and success status
76
+ */
77
+ claimWithAuthToken({ authToken, recipient, quantity, }: {
78
+ authToken: string;
79
+ recipient: string;
80
+ quantity: number;
81
+ }): Promise<{
82
+ id: string;
83
+ success: boolean;
84
+ }>;
85
+ /**
86
+ * Verifies an authorization token is valid.
87
+ * @param authToken - The authorization token
88
+ * @returns The validity of the authorization token and the expiration time
89
+ */
90
+ verifyAuthToken({ authToken }: {
91
+ authToken: string;
92
+ }): Promise<{
93
+ valid: boolean;
94
+ expiresAt: number;
95
+ }>;
96
+ }
@@ -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 {
@@ -18,5 +18,6 @@ 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
  export * from './io.js';
22
23
  export * from './contracts/ao-process.js';
@@ -1,22 +1,32 @@
1
1
  import Arweave from 'arweave';
2
- import { AoArNSNameDataWithName, AoArNSReservedNameData, AoBalanceWithAddress, AoEpochDistributionData, AoEpochObservationData, AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoReturnedName, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, OptionalArweave, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
3
- import { AoARIORead, AoARIOWrite, AoAllDelegates, AoAllGatewayVaults, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoCreateVaultParams, AoDelegation, AoEligibleDistribution, AoEpochData, AoEpochDistributed, AoEpochDistributionTotalsData, AoEpochSettings, AoExtendLeaseParams, AoExtendVaultParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoIncreaseVaultParams, AoPaginatedAddressParams, AoRegistrationFees, AoRevokeVaultParams, AoVaultData, AoVaultedTransferParams, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
4
- import { mARIOToken } from '../types/token.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';
5
3
  import { AOProcess } from './contracts/ao-process.js';
6
- import { TurboArNSPaymentProvider } from './turbo.js';
7
- type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>;
8
- type ARIOConfigWithSigner = WithSigner<OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>>;
4
+ type ARIOConfigNoSigner = OptionalArweave<ProcessConfiguration>;
5
+ type ARIOConfigWithSigner = WithSigner<OptionalArweave<ProcessConfiguration>>;
9
6
  export declare class ARIO {
10
7
  static init(): AoARIORead;
11
8
  static init(config: ARIOConfigWithSigner): AoARIOWrite;
12
9
  static init(config: ARIOConfigNoSigner): AoARIORead;
10
+ static mainnet(): AoARIORead;
11
+ static mainnet(config: ARIOConfigNoSigner & {
12
+ faucetUrl?: string;
13
+ }): AoARIORead;
14
+ static mainnet(config: ARIOConfigWithSigner & {
15
+ faucetUrl?: string;
16
+ }): AoARIOWrite;
17
+ static testnet(): ARIOWithFaucet<AoARIORead>;
18
+ static testnet(config: ARIOConfigNoSigner & {
19
+ faucetUrl?: string;
20
+ }): ARIOWithFaucet<AoARIORead>;
21
+ static testnet(config: ARIOConfigWithSigner & {
22
+ faucetUrl?: string;
23
+ }): ARIOWithFaucet<AoARIOWrite>;
13
24
  }
14
25
  export declare class ARIOReadable implements AoARIORead {
15
- protected process: AOProcess;
26
+ readonly process: AOProcess;
16
27
  protected epochSettings: AoEpochSettings | undefined;
17
28
  protected arweave: Arweave;
18
- protected paymentProvider: TurboArNSPaymentProvider;
19
- constructor(config?: ARIOConfigNoSigner);
29
+ constructor(config?: OptionalArweave<ProcessConfiguration>);
20
30
  getInfo(): Promise<{
21
31
  Name: string;
22
32
  Ticker: string;
@@ -31,8 +41,8 @@ export declare class ARIOReadable implements AoARIORead {
31
41
  private computeCurrentEpochIndex;
32
42
  private computeEpochIndex;
33
43
  getEpochSettings(): Promise<AoEpochSettings>;
34
- getEpoch(): Promise<AoEpochData<AoEpochDistributionTotalsData>>;
35
44
  getEpoch(epoch: EpochInput): Promise<AoEpochData<AoEpochDistributed>>;
45
+ getEpoch(): Promise<AoEpochData<AoEpochDistributionTotalsData>>;
36
46
  getArNSRecord({ name }: {
37
47
  name: string;
38
48
  }): Promise<AoArNSNameData>;
@@ -129,10 +139,9 @@ export declare class ARIOReadable implements AoARIORead {
129
139
  getAllGatewayVaults(params?: PaginationParams<AoAllGatewayVaults>): Promise<PaginationResult<AoAllGatewayVaults>>;
130
140
  }
131
141
  export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
132
- protected process: AOProcess;
142
+ readonly process: AOProcess;
133
143
  private signer;
134
- protected paymentProvider: TurboArNSPaymentProvider;
135
- constructor({ signer, paymentUrl, ...config }: ARIOConfigWithSigner);
144
+ constructor({ signer, ...config }: ARIOConfigWithSigner);
136
145
  transfer({ target, qty, }: {
137
146
  target: string;
138
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;
@@ -0,0 +1,82 @@
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 { AoARIORead, AoARIOWrite } from './io.js';
17
+ export type ARIOWithFaucet<T extends AoARIORead | AoARIOWrite> = T & {
18
+ faucet: TokenFaucet;
19
+ };
20
+ export interface TokenFaucet {
21
+ /**
22
+ * Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
23
+ * @param captchaResponse - The captcha response
24
+ * @param recipient - The recipient address
25
+ * @param quantity - The quantity of tokens to claim
26
+ * @returns The claim id and success status
27
+ */
28
+ claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }: {
29
+ captchaResponse: string;
30
+ recipient: string;
31
+ quantity: number;
32
+ }): Promise<{
33
+ id: string;
34
+ success: boolean;
35
+ }>;
36
+ /**
37
+ * 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.
38
+ * @returns The captcha URL for a process
39
+ */
40
+ captchaUrl(): Promise<{
41
+ processId: string;
42
+ captchaUrl: string;
43
+ }>;
44
+ /**
45
+ * 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.
46
+ * @param captchaResponse - The captcha response
47
+ * @returns The status of the request, the authorization token, and the expiration time
48
+ */
49
+ requestAuthToken({ captchaResponse }: {
50
+ captchaResponse: string;
51
+ }): Promise<{
52
+ status: 'success' | 'error';
53
+ token: string;
54
+ expiresAt: number;
55
+ }>;
56
+ /**
57
+ * 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.
58
+ * @param authToken - The authorization token
59
+ * @param recipient - The recipient address
60
+ * @param quantity - The quantity of tokens to claim
61
+ * @returns The message id of the transfer and success status
62
+ */
63
+ claimWithAuthToken({ authToken, recipient, quantity, }: {
64
+ authToken: string;
65
+ recipient: string;
66
+ quantity: number;
67
+ }): Promise<{
68
+ id: string;
69
+ success: boolean;
70
+ }>;
71
+ /**
72
+ * Verifies an authorization token is valid.
73
+ * @param authToken - The authorization token
74
+ * @returns The validity of the authorization token and the expiration time
75
+ */
76
+ verifyAuthToken({ authToken }: {
77
+ authToken: string;
78
+ }): Promise<{
79
+ valid: boolean;
80
+ expiresAt: number;
81
+ }>;
82
+ }
@@ -16,5 +16,6 @@
16
16
  export * from './ant-registry.js';
17
17
  export * from './ant.js';
18
18
  export * from './common.js';
19
+ export * from './faucet.js';
19
20
  export * from './io.js';
20
21
  export * from './token.js';
@@ -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;
@@ -535,7 +534,7 @@ export interface AoARIOWrite extends AoARIORead {
535
534
  requestPrimaryName: AoWriteAction<AoArNSPurchaseParams>;
536
535
  redelegateStake: AoWriteAction<AoRedelegateStakeParams>;
537
536
  }
538
- export declare function isProcessConfiguration(config: object): config is Required<ProcessConfiguration> & Record<string, never>;
539
- export declare function isProcessIdConfiguration(config: object): config is Required<ProcessIdConfig> & Record<string, never>;
537
+ export declare function isProcessConfiguration(config: object | undefined): config is Required<ProcessConfiguration> & Record<string, never>;
538
+ export declare function isProcessIdConfiguration(config: object | undefined): config is Required<ProcessIdConfig> & Record<string, never>;
540
539
  export declare function isLeasedArNSRecord(record: AoArNSNameData): record is AoArNSLeaseData;
541
540
  export {};
@@ -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;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.9.1";
16
+ export declare const version = "3.10.0-alpha.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.10.0-alpha.1",
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"
@@ -67,7 +67,7 @@
67
67
  "lint": "eslint src",
68
68
  "lint:fix": "eslint src --fix",
69
69
  "format": "prettier --check .",
70
- "format:fix": "prettier --write .",
70
+ "format:fix": "prettier --write . && yarn docs:update",
71
71
  "test": "yarn test:unit && yarn test:e2e",
72
72
  "test:cjs": "yarn build:cjs && yarn link && cd ./tests/e2e/cjs && yarn && yarn test",
73
73
  "test:esm": "yarn build:esm && yarn link && cd ./tests/e2e/esm && yarn && yarn test",
@@ -77,7 +77,7 @@
77
77
  "test:e2e": "yarn test:cjs && yarn test:esm && yarn test:web",
78
78
  "test:integration": "yarn build:esm && yarn link && cd ./tests/integration && yarn && yarn test",
79
79
  "prepare": "husky install",
80
- "docs:update": "markdown-toc-gen insert README.md",
80
+ "docs:update": "markdown-toc-gen insert README.md --max-depth 2",
81
81
  "example:esm": "cd examples/esm && yarn && node index.mjs",
82
82
  "example:cjs": "yarn build:cjs && yarn link && cd examples/cjs && yarn && node index.cjs",
83
83
  "example:web": "yarn build:web && http-server --port 8080 --host -o examples/web",
@@ -121,8 +121,7 @@
121
121
  "sinon": "^15.2.0",
122
122
  "testcontainers": "^10.13.1",
123
123
  "ts-node": "^10.9.2",
124
- "typescript": "^5.1.6",
125
- "vite-plugin-node-polyfills": "^0.22.0"
124
+ "typescript": "^5.1.6"
126
125
  },
127
126
  "dependencies": {
128
127
  "@dha-team/arbundles": "^1.0.1",
@@ -134,7 +133,6 @@
134
133
  "eventemitter3": "^5.0.1",
135
134
  "plimit-lit": "^3.0.1",
136
135
  "prompts": "^2.4.2",
137
- "uuid": "^11.1.0",
138
136
  "winston": "^3.13.0",
139
137
  "zod": "^3.23.8"
140
138
  },
@@ -143,7 +141,7 @@
143
141
  "prettier --write ."
144
142
  ],
145
143
  "**/README.md": [
146
- "markdown-toc-gen insert"
144
+ "markdown-toc-gen insert --max-depth 2"
147
145
  ]
148
146
  }
149
147
  }
@@ -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
- });