@ar.io/sdk 3.10.0-alpha.1 → 3.10.0-alpha.3

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.
@@ -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,11 +1,28 @@
1
- import { ARIO_MAINNET_PROCESS_ID } from '../constants.js';
2
- import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
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 { connect } from '@permaweb/aoconnect';
17
+ import { ARIO_MAINNET_PROCESS_ID, ARIO_TESTNET_PROCESS_ID, } from '../constants.js';
18
+ import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
3
19
  import { createAoSigner } from '../utils/ao.js';
4
20
  import { getEpochDataFromGqlWithCUFallback, paginationParamsToTags, pruneTags, removeEligibleRewardsFromEpochData, sortAndPaginateEpochDataIntoEligibleDistributions, } from '../utils/arweave.js';
5
21
  import { defaultArweave } from './arweave.js';
6
22
  import { AOProcess } from './contracts/ao-process.js';
7
23
  import { InvalidContractConfigurationError } from './error.js';
8
- import { TurboArNSPaymentProvider } from './turbo.js';
24
+ import { createFaucet } from './faucet.js';
25
+ import { TurboArNSPaymentFactory, TurboArNSPaymentProviderAuthenticated, isTurboArNSSigner, } from './turbo.js';
9
26
  export class ARIO {
10
27
  // Implementation
11
28
  static init(config) {
@@ -14,6 +31,56 @@ export class ARIO {
14
31
  }
15
32
  return new ARIOReadable(config);
16
33
  }
34
+ static mainnet(config) {
35
+ if (config !== undefined && 'signer' in config) {
36
+ return new ARIOWriteable({
37
+ ...config,
38
+ process: new AOProcess({
39
+ processId: ARIO_MAINNET_PROCESS_ID,
40
+ ao: connect({
41
+ CU_URL: 'https://cu.ardrive.io',
42
+ ...config?.process?.ao,
43
+ }),
44
+ }),
45
+ });
46
+ }
47
+ return new ARIOReadable({
48
+ ...config,
49
+ process: new AOProcess({
50
+ processId: ARIO_MAINNET_PROCESS_ID,
51
+ }),
52
+ });
53
+ }
54
+ static testnet(config) {
55
+ if (config !== undefined && 'signer' in config) {
56
+ return createFaucet({
57
+ arioInstance: new ARIOWriteable({
58
+ ...config,
59
+ process: new AOProcess({
60
+ processId: ARIO_TESTNET_PROCESS_ID,
61
+ ao: connect({
62
+ CU_URL: 'https://cu.ardrive.io',
63
+ ...config?.process?.ao,
64
+ }),
65
+ }),
66
+ }),
67
+ faucetApiUrl: config?.faucetUrl,
68
+ });
69
+ }
70
+ return createFaucet({
71
+ arioInstance: new ARIOReadable({
72
+ ...config,
73
+ process: new AOProcess({
74
+ processId: ARIO_TESTNET_PROCESS_ID,
75
+ ao: connect({
76
+ CU_URL: 'https://cu.ardrive.io',
77
+ ...config?.process?.ao,
78
+ }),
79
+ }),
80
+ }),
81
+ faucetApiUrl: config?.faucetUrl,
82
+ });
83
+ }
17
84
  }
18
85
  export class ARIOReadable {
19
86
  process;
@@ -38,7 +105,7 @@ export class ARIOReadable {
38
105
  else {
39
106
  throw new InvalidContractConfigurationError();
40
107
  }
41
- this.paymentProvider = new TurboArNSPaymentProvider({
108
+ this.paymentProvider = TurboArNSPaymentFactory.init({
42
109
  paymentUrl: config?.paymentUrl,
43
110
  });
44
111
  }
@@ -565,8 +632,8 @@ export class ARIOWriteable extends ARIOReadable {
565
632
  super(config);
566
633
  }
567
634
  this.signer = createAoSigner(signer);
568
- this.paymentProvider = new TurboArNSPaymentProvider({
569
- signer: signer,
635
+ this.paymentProvider = TurboArNSPaymentFactory.init({
636
+ signer: isTurboArNSSigner(signer) ? signer : undefined,
570
637
  paymentUrl,
571
638
  });
572
639
  }
@@ -844,6 +911,9 @@ export class ARIOWriteable extends ARIOReadable {
844
911
  }
845
912
  async buyRecord(params, options) {
846
913
  if (params.fundFrom === 'turbo') {
914
+ if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
915
+ throw new Error('Turbo funding is not supported for this payment provider');
916
+ }
847
917
  return this.paymentProvider.initiateArNSPurchase({
848
918
  intent: 'Buy-Name',
849
919
  ...params,
@@ -874,6 +944,9 @@ export class ARIOWriteable extends ARIOReadable {
874
944
  */
875
945
  async upgradeRecord(params, options) {
876
946
  if (params.fundFrom === 'turbo') {
947
+ if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
948
+ throw new Error('Turbo funding is not supported for this payment provider');
949
+ }
877
950
  return this.paymentProvider.initiateArNSPurchase({
878
951
  intent: 'Upgrade-Name',
879
952
  name: params.name,
@@ -902,6 +975,9 @@ export class ARIOWriteable extends ARIOReadable {
902
975
  */
903
976
  async extendLease(params, options) {
904
977
  if (params.fundFrom === 'turbo') {
978
+ if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
979
+ throw new Error('Turbo funding is not supported for this payment provider');
980
+ }
905
981
  return this.paymentProvider.initiateArNSPurchase({
906
982
  intent: 'Extend-Lease',
907
983
  ...params,
@@ -922,6 +998,9 @@ export class ARIOWriteable extends ARIOReadable {
922
998
  }
923
999
  async increaseUndernameLimit(params, options) {
924
1000
  if (params.fundFrom === 'turbo') {
1001
+ if (!(this.paymentProvider instanceof TurboArNSPaymentProviderAuthenticated)) {
1002
+ throw new Error('Turbo funding is not supported for this payment provider');
1003
+ }
925
1004
  return this.paymentProvider.initiateArNSPurchase({
926
1005
  intent: 'Increase-Undername-Limit',
927
1006
  ...params,
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { SignatureConfig } from '@dha-team/arbundles';
16
+ import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, SignatureConfig, } from '@dha-team/arbundles';
17
17
  import { v4 as uuidv4 } from 'uuid';
18
18
  import { mARIOToken } from '../types/token.js';
19
19
  import { toB64Url } from '../utils/base64.js';
@@ -21,39 +21,87 @@ import { createAxiosInstance } from '../utils/http-client.js';
21
21
  import { urlWithSearchParams } from '../utils/url.js';
22
22
  import { Logger } from './logger.js';
23
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) {
24
+ let signature = undefined;
25
+ let publicKey = undefined;
26
+ const signatureType = isWanderArweaveBrowserSigner(signer)
27
+ ? SignatureConfig.ARWEAVE
28
+ : signer.signatureType;
29
+ // equivalent to window.arweaveWallet
30
+ if (isWanderArweaveBrowserSigner(signer)) {
31
+ signature = toB64Url(Buffer.from(await signer.signMessage(Uint8Array.from(Buffer.from(nonce)))));
32
+ }
33
+ else if (signer instanceof ArconnectSigner) {
34
+ signature = toB64Url(Buffer.from(await signer['signer'].signMessage(Uint8Array.from(Buffer.from(nonce)))));
35
+ }
36
+ else if (signer instanceof ArweaveSigner ||
37
+ signer instanceof EthereumSigner ||
38
+ signer instanceof InjectedEthereumSigner) {
39
+ if ('setPublicKey' in signer) {
40
+ await signer.setPublicKey();
41
+ }
42
+ signature = toB64Url(Buffer.from(await signer.sign(Uint8Array.from(Buffer.from(nonce)))));
43
+ }
44
+ switch (signatureType) {
28
45
  case SignatureConfig.ARWEAVE:
29
- publicKey = toB64Url(signer.publicKey);
46
+ if (isWanderArweaveBrowserSigner(signer)) {
47
+ publicKey = await signer.getActivePublicKey();
48
+ }
49
+ else if ('setPublicKey' in signer) {
50
+ await signer.setPublicKey();
51
+ publicKey = toB64Url(signer.publicKey);
52
+ }
30
53
  break;
31
54
  case SignatureConfig.ETHEREUM:
32
- publicKey = '0x' + signer.publicKey.toString('hex');
55
+ if ('publicKey' in signer) {
56
+ publicKey = '0x' + signer.publicKey.toString('hex');
57
+ }
58
+ else {
59
+ throw new Error('Public key not found');
60
+ }
33
61
  break;
34
62
  // TODO: solana sig support
35
63
  // case SignatureConfig.SOLANA:
36
64
  // case SignatureConfig.ED25519:
37
65
  default:
38
- throw new Error(`Unsupported signer type for signing requests: ${signer.signatureType}`);
66
+ throw new Error(`Unsupported signer type for signing requests: ${signatureType}`);
67
+ }
68
+ if (publicKey === undefined || signature === undefined) {
69
+ throw new Error('Public key or signature not found');
39
70
  }
40
71
  return {
41
72
  'x-public-key': publicKey,
42
73
  'x-nonce': nonce,
43
- 'x-signature': toB64Url(Buffer.from(signature)),
44
- 'x-signature-type': signer.signatureType,
74
+ 'x-signature': signature,
75
+ 'x-signature-type': signatureType,
45
76
  };
46
77
  }
47
- export class TurboArNSPaymentProvider {
78
+ export class TurboArNSPaymentFactory {
79
+ static init(config) {
80
+ const { signer, paymentUrl, axios, logger } = config ?? {};
81
+ if (signer !== undefined) {
82
+ return new TurboArNSPaymentProviderAuthenticated({
83
+ signer,
84
+ paymentUrl,
85
+ axios,
86
+ logger,
87
+ });
88
+ }
89
+ return new TurboArNSPaymentProviderUnauthenticated({
90
+ paymentUrl,
91
+ axios,
92
+ logger,
93
+ });
94
+ }
95
+ }
96
+ // Base class for unauthenticated operations
97
+ export class TurboArNSPaymentProviderUnauthenticated {
48
98
  paymentUrl;
49
99
  axios;
50
100
  logger;
51
- signer;
52
- constructor({ paymentUrl = 'https://payment.ardrive.io', axios = createAxiosInstance(), logger = Logger.default, signer, }) {
101
+ constructor({ paymentUrl = 'https://payment.ardrive.io', axios = createAxiosInstance(), logger = Logger.default, }) {
53
102
  this.paymentUrl = paymentUrl;
54
103
  this.axios = axios;
55
104
  this.logger = logger;
56
- this.signer = signer;
57
105
  }
58
106
  async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
59
107
  const url = urlWithSearchParams({
@@ -89,10 +137,19 @@ export class TurboArNSPaymentProvider {
89
137
  const { winc } = await this.getArNSPriceDetails(params);
90
138
  return +winc;
91
139
  }
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');
140
+ }
141
+ // Class for authenticated operations, extending the base class
142
+ export class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated {
143
+ signer;
144
+ constructor({ signer, ...restConfig }) {
145
+ super(restConfig); // Pass unauthenticated config to base class+
146
+ if (!isTurboArNSSigner(signer)) {
147
+ throw new Error('Signer must be a TurboArNSSigner');
95
148
  }
149
+ this.signer = signer;
150
+ }
151
+ async initiateArNSPurchase({ intent, name, quantity, type, processId, years, }) {
152
+ // Signer check is implicitly handled by requiring it in the constructor
96
153
  const url = urlWithSearchParams({
97
154
  baseUrl: `${this.paymentUrl}/v1/arns/purchase/${intent}/${name}`,
98
155
  params: {
@@ -127,3 +184,17 @@ export class TurboArNSPaymentProvider {
127
184
  };
128
185
  }
129
186
  }
187
+ function isWanderArweaveBrowserSigner(signer) {
188
+ return (typeof signer === 'object' &&
189
+ signer !== null &&
190
+ 'signMessage' in signer &&
191
+ 'getActivePublicKey' in signer);
192
+ }
193
+ export function isTurboArNSSigner(signer) {
194
+ const isWanderWallet = isWanderArweaveBrowserSigner(signer);
195
+ const isSigner = signer instanceof EthereumSigner ||
196
+ signer instanceof InjectedEthereumSigner ||
197
+ signer instanceof ArweaveSigner ||
198
+ signer instanceof ArconnectSigner;
199
+ return isWanderWallet || isSigner;
200
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -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';
@@ -28,10 +28,11 @@ export const isValidFundFrom = (fundFrom) => {
28
28
  };
29
29
  // Type-guard functions
30
30
  export function isProcessConfiguration(config) {
31
- return 'process' in config;
31
+ return config !== undefined && 'process' in config;
32
32
  }
33
33
  export function isProcessIdConfiguration(config) {
34
- return ('processId' in config &&
34
+ return (config !== undefined &&
35
+ 'processId' in config &&
35
36
  typeof config.processId === 'string' &&
36
37
  validateArweaveId(config.processId) === true);
37
38
  }
@@ -131,6 +131,8 @@ export function createAoSigner(signer) {
131
131
  }));
132
132
  return signedData;
133
133
  };
134
+ // eslint-disable-next-line
135
+ // @ts-ignore Buffer vs ArrayBuffer type mismatch
134
136
  return aoSigner;
135
137
  }
136
138
  export const defaultTargetManifestId = '-k7t8xMoB8hW482609Z9F4bTFMC3MnuW8bTvTyT8pFI';
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.10.0-alpha.1';
17
+ export const version = '3.10.0-alpha.3';
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { ArweaveSigner, ArconnectSigner } from '@dha-team/arbundles';
16
+ export { ArweaveSigner, ArconnectSigner, InjectedEthereumSigner, EthereumSigner, } from '@dha-team/arbundles';
17
17
  export * from '../types/index.js';
18
18
  export * from '../common/index.js';
19
19
  export * from '../constants.js';
@@ -80,7 +80,7 @@ export declare function positiveIntegerFromOptions<O extends GlobalCLIOptions>(o
80
80
  export declare function requiredPositiveIntegerFromOptions<O extends GlobalCLIOptions>(options: O, key: string): number;
81
81
  export declare function getANTStateFromOptions(options: ANTStateCLIOptions): SpawnANTState;
82
82
  export declare function getTokenCostParamsFromOptions(o: GetTokenCostCLIOptions): {
83
- type: "permabuy" | "lease";
83
+ type: "lease" | "permabuy";
84
84
  quantity: number | undefined;
85
85
  years: number;
86
86
  intent: "Buy-Name" | "Buy-Record" | "Extend-Lease" | "Increase-Undername-Limit" | "Upgrade-Name" | "Primary-Name-Request";
@@ -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
+ }
@@ -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';