@ar.io/sdk 3.10.0 → 3.11.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 (99) hide show
  1. package/README.md +66 -125
  2. package/bundles/web.bundle.min.js +130 -125
  3. package/lib/cjs/cli/options.js +12 -0
  4. package/lib/cjs/cli/utils.js +32 -10
  5. package/lib/cjs/cli/wayfinder.js +34 -0
  6. package/lib/cjs/common/ant-versions.js +5 -5
  7. package/lib/cjs/common/index.js +2 -0
  8. package/lib/cjs/common/io.js +64 -1
  9. package/lib/cjs/common/turbo.js +208 -0
  10. package/lib/cjs/common/wayfinder/gateways.js +75 -0
  11. package/lib/cjs/common/wayfinder/index.js +38 -0
  12. package/lib/cjs/common/wayfinder/routers/fixed.js +14 -0
  13. package/lib/cjs/common/wayfinder/routers/fixed.test.js +14 -0
  14. package/lib/cjs/common/wayfinder/routers/priority.js +38 -0
  15. package/lib/cjs/common/wayfinder/routers/priority.test.js +155 -0
  16. package/lib/cjs/common/wayfinder/routers/random.js +23 -0
  17. package/lib/cjs/common/wayfinder/routers/random.test.js +104 -0
  18. package/lib/cjs/common/wayfinder/routers/simple-cache.js +25 -0
  19. package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +41 -0
  20. package/lib/cjs/common/wayfinder/wayfinder.js +174 -0
  21. package/lib/cjs/common/wayfinder/wayfinder.test.js +253 -0
  22. package/lib/cjs/types/ant.js +12 -1
  23. package/lib/cjs/types/index.js +1 -0
  24. package/lib/cjs/types/io.js +1 -1
  25. package/lib/cjs/types/wayfinder.js +2 -0
  26. package/lib/cjs/utils/ao.js +5 -0
  27. package/lib/cjs/utils/random.js +30 -0
  28. package/lib/cjs/utils/url.js +28 -0
  29. package/lib/cjs/utils/url.test.js +24 -0
  30. package/lib/cjs/utils/utils.test.js +8 -8
  31. package/lib/cjs/version.js +1 -1
  32. package/lib/cjs/web/index.js +3 -1
  33. package/lib/esm/cli/options.js +12 -0
  34. package/lib/esm/cli/utils.js +31 -10
  35. package/lib/esm/cli/wayfinder.js +32 -0
  36. package/lib/esm/common/ant-versions.js +5 -5
  37. package/lib/esm/common/index.js +2 -0
  38. package/lib/esm/common/io.js +64 -1
  39. package/lib/esm/common/turbo.js +200 -0
  40. package/lib/esm/common/wayfinder/gateways.js +69 -0
  41. package/lib/esm/common/wayfinder/index.js +22 -0
  42. package/lib/esm/common/wayfinder/routers/fixed.js +10 -0
  43. package/lib/esm/common/wayfinder/routers/fixed.test.js +12 -0
  44. package/lib/esm/common/wayfinder/routers/priority.js +34 -0
  45. package/lib/esm/common/wayfinder/routers/priority.test.js +153 -0
  46. package/lib/esm/common/wayfinder/routers/random.js +19 -0
  47. package/lib/esm/common/wayfinder/routers/random.test.js +102 -0
  48. package/lib/esm/common/wayfinder/routers/simple-cache.js +21 -0
  49. package/lib/esm/common/wayfinder/routers/simple-cache.test.js +39 -0
  50. package/lib/esm/common/wayfinder/wayfinder.js +168 -0
  51. package/lib/esm/common/wayfinder/wayfinder.test.js +248 -0
  52. package/lib/esm/types/ant.js +11 -0
  53. package/lib/esm/types/index.js +1 -0
  54. package/lib/esm/types/io.js +1 -1
  55. package/lib/esm/types/wayfinder.js +1 -0
  56. package/lib/esm/utils/ao.js +5 -0
  57. package/lib/esm/utils/random.js +26 -0
  58. package/lib/esm/utils/url.js +24 -0
  59. package/lib/esm/utils/url.test.js +19 -0
  60. package/lib/esm/utils/utils.test.js +1 -1
  61. package/lib/esm/version.js +1 -1
  62. package/lib/esm/web/index.js +1 -1
  63. package/lib/types/cli/commands/antCommands.d.ts +3 -3
  64. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
  65. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
  66. package/lib/types/cli/commands/readCommands.d.ts +1 -0
  67. package/lib/types/cli/commands/transfer.d.ts +3 -3
  68. package/lib/types/cli/options.d.ts +9 -0
  69. package/lib/types/cli/types.d.ts +3 -0
  70. package/lib/types/cli/utils.d.ts +4 -0
  71. package/lib/types/cli/wayfinder.d.ts +1 -0
  72. package/lib/types/common/ant-versions.d.ts +3 -6
  73. package/lib/types/common/index.d.ts +1 -0
  74. package/lib/types/common/io.d.ts +9 -7
  75. package/lib/types/common/turbo.d.ts +62 -0
  76. package/lib/types/common/wayfinder/gateways.d.ts +44 -0
  77. package/lib/types/common/wayfinder/index.d.ts +20 -0
  78. package/lib/types/common/wayfinder/routers/fixed.d.ts +24 -0
  79. package/lib/types/common/wayfinder/routers/fixed.test.d.ts +1 -0
  80. package/lib/types/common/wayfinder/routers/priority.d.ts +33 -0
  81. package/lib/types/common/wayfinder/routers/priority.test.d.ts +1 -0
  82. package/lib/types/common/wayfinder/routers/random.d.ts +27 -0
  83. package/lib/types/common/wayfinder/routers/random.test.d.ts +1 -0
  84. package/lib/types/common/wayfinder/routers/simple-cache.d.ts +28 -0
  85. package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +1 -0
  86. package/lib/types/common/wayfinder/wayfinder.d.ts +120 -0
  87. package/lib/types/common/wayfinder/wayfinder.test.d.ts +1 -0
  88. package/lib/types/types/ant.d.ts +53 -1
  89. package/lib/types/types/common.d.ts +7 -2
  90. package/lib/types/types/index.d.ts +1 -0
  91. package/lib/types/types/io.d.ts +7 -5
  92. package/lib/types/types/wayfinder.d.ts +19 -0
  93. package/lib/types/utils/ao.d.ts +1 -12
  94. package/lib/types/utils/random.d.ts +7 -0
  95. package/lib/types/utils/url.d.ts +19 -0
  96. package/lib/types/utils/url.test.d.ts +1 -0
  97. package/lib/types/version.d.ts +1 -1
  98. package/lib/types/web/index.d.ts +1 -1
  99. package/package.json +5 -3
@@ -1,8 +1,9 @@
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, 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, OptionalPaymentUrl, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions, mARIOToken } from '../types/index.js';
3
3
  import { AOProcess } from './contracts/ao-process.js';
4
- type ARIOConfigNoSigner = OptionalArweave<ProcessConfiguration>;
5
- type ARIOConfigWithSigner = WithSigner<OptionalArweave<ProcessConfiguration>>;
4
+ import { TurboArNSPaymentProviderAuthenticated, TurboArNSPaymentProviderUnauthenticated } from './turbo.js';
5
+ type ARIOConfigNoSigner = OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>;
6
+ type ARIOConfigWithSigner = WithSigner<OptionalPaymentUrl<OptionalArweave<ProcessConfiguration>>>;
6
7
  export declare class ARIO {
7
8
  static init(): AoARIORead;
8
9
  static init(config: ARIOConfigWithSigner): AoARIOWrite;
@@ -26,7 +27,8 @@ export declare class ARIOReadable implements AoARIORead {
26
27
  readonly process: AOProcess;
27
28
  protected epochSettings: AoEpochSettings | undefined;
28
29
  protected arweave: Arweave;
29
- constructor(config?: OptionalArweave<ProcessConfiguration>);
30
+ protected paymentProvider: TurboArNSPaymentProviderUnauthenticated;
31
+ constructor(config?: ARIOConfigNoSigner);
30
32
  getInfo(): Promise<{
31
33
  Name: string;
32
34
  Ticker: string;
@@ -41,8 +43,8 @@ export declare class ARIOReadable implements AoARIORead {
41
43
  private computeCurrentEpochIndex;
42
44
  private computeEpochIndex;
43
45
  getEpochSettings(): Promise<AoEpochSettings>;
44
- getEpoch(epoch: EpochInput): Promise<AoEpochData<AoEpochDistributed>>;
45
46
  getEpoch(): Promise<AoEpochData<AoEpochDistributionTotalsData>>;
47
+ getEpoch(epoch: EpochInput): Promise<AoEpochData<AoEpochDistributed>>;
46
48
  getArNSRecord({ name }: {
47
49
  name: string;
48
50
  }): Promise<AoArNSNameData>;
@@ -139,9 +141,9 @@ export declare class ARIOReadable implements AoARIORead {
139
141
  getAllGatewayVaults(params?: PaginationParams<AoAllGatewayVaults>): Promise<PaginationResult<AoAllGatewayVaults>>;
140
142
  }
141
143
  export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
142
- readonly process: AOProcess;
143
144
  private signer;
144
- constructor({ signer, ...config }: ARIOConfigWithSigner);
145
+ protected paymentProvider: TurboArNSPaymentProviderAuthenticated | TurboArNSPaymentProviderUnauthenticated;
146
+ constructor({ signer, paymentUrl, ...config }: ARIOConfigWithSigner);
145
147
  transfer({ target, qty, }: {
146
148
  target: string;
147
149
  qty: number | mARIOToken;
@@ -0,0 +1,62 @@
1
+ import { AxiosInstance, RawAxiosRequestHeaders } from 'axios';
2
+ import { AoMessageResult, TransactionId, TurboArNSSigner } 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 TurboUnauthenticatedConfig {
7
+ paymentUrl?: string;
8
+ logger?: ILogger;
9
+ axios?: AxiosInstance;
10
+ }
11
+ export interface TurboAuthenticatedConfig extends TurboUnauthenticatedConfig {
12
+ signer: TurboArNSSigner;
13
+ }
14
+ export declare function signedRequestHeadersFromSigner({ signer, nonce, }: {
15
+ signer: TurboArNSSigner;
16
+ nonce?: string;
17
+ }): Promise<RawAxiosRequestHeaders>;
18
+ export type ArNSPurchaseReceipt = AoTokenCostParams & {
19
+ wincQty: string;
20
+ mARIOQty: string;
21
+ usdArRate: number;
22
+ createdDate: string;
23
+ };
24
+ export interface ArNSPaymentProvider {
25
+ /** Returns the cost of the action in the Payment Provider's native currency (winc for Turbo) */
26
+ getPrice(params: AoTokenCostParams): Promise<number>;
27
+ getArNSPriceDetails(params: AoTokenCostParams): Promise<{
28
+ winc: string;
29
+ mARIO: mARIOToken;
30
+ }>;
31
+ }
32
+ export interface ArNSAuthenticatedPaymentProvider extends ArNSPaymentProvider {
33
+ initiateArNSPurchase(params: AoTokenCostParams & {
34
+ processId?: TransactionId;
35
+ }): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
36
+ }
37
+ export declare class TurboArNSPaymentFactory {
38
+ static init(): TurboArNSPaymentProviderUnauthenticated;
39
+ static init({ paymentUrl, axios, logger, }: TurboUnauthenticatedConfig & {
40
+ signer?: TurboArNSSigner;
41
+ }): TurboArNSPaymentProviderUnauthenticated;
42
+ static init({ signer, paymentUrl, axios, logger, }: TurboAuthenticatedConfig): TurboArNSPaymentProviderAuthenticated;
43
+ }
44
+ export declare class TurboArNSPaymentProviderUnauthenticated implements ArNSPaymentProvider {
45
+ protected readonly paymentUrl: string;
46
+ protected readonly axios: AxiosInstance;
47
+ protected readonly logger: ILogger;
48
+ constructor({ paymentUrl, axios, logger, }: TurboUnauthenticatedConfig);
49
+ getArNSPriceDetails({ intent, name, quantity, type, years, }: AoTokenCostParams): Promise<{
50
+ winc: string;
51
+ mARIO: mARIOToken;
52
+ }>;
53
+ getPrice(params: AoTokenCostParams): Promise<number>;
54
+ }
55
+ export declare class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnauthenticated implements ArNSAuthenticatedPaymentProvider {
56
+ private readonly signer;
57
+ constructor({ signer, ...restConfig }: TurboAuthenticatedConfig);
58
+ initiateArNSPurchase({ intent, name, quantity, type, processId, years, }: AoTokenCostParams & {
59
+ processId?: TransactionId;
60
+ }): Promise<AoMessageResult<ArNSPurchaseReceipt>>;
61
+ }
62
+ export declare function isTurboArNSSigner(signer: unknown): signer is TurboArNSSigner;
@@ -0,0 +1,44 @@
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, AoGatewayWithAddress } from '../../types/io.js';
17
+ export interface GatewaysProvider {
18
+ getGateways(): Promise<AoGatewayWithAddress[]>;
19
+ }
20
+ export declare class ARIOGatewaysProvider implements GatewaysProvider {
21
+ private ario;
22
+ constructor({ ario }: {
23
+ ario: AoARIORead;
24
+ });
25
+ getGateways(): Promise<AoGatewayWithAddress[]>;
26
+ }
27
+ export declare class StaticGatewaysProvider implements GatewaysProvider {
28
+ private gateways;
29
+ constructor({ gateways }: {
30
+ gateways: AoGatewayWithAddress[];
31
+ });
32
+ getGateways(): Promise<AoGatewayWithAddress[]>;
33
+ }
34
+ export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
35
+ private gatewaysProvider;
36
+ private ttlSeconds;
37
+ private lastUpdated;
38
+ private gatewaysCache;
39
+ constructor({ gatewaysProvider, ttlSeconds, }: {
40
+ gatewaysProvider: GatewaysProvider;
41
+ ttlSeconds?: number;
42
+ });
43
+ getGateways(): Promise<AoGatewayWithAddress[]>;
44
+ }
@@ -0,0 +1,20 @@
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 * from './wayfinder.js';
17
+ export * from './routers/random.js';
18
+ export * from './routers/priority.js';
19
+ export * from './routers/fixed.js';
20
+ export * from './gateways.js';
@@ -0,0 +1,24 @@
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 { WayfinderRouter } from '../../../types/wayfinder.js';
17
+ export declare class FixedGatewayRouter implements WayfinderRouter {
18
+ readonly name = "fixed";
19
+ private gateway;
20
+ constructor({ gateway }: {
21
+ gateway: URL;
22
+ });
23
+ getTargetGateway(): Promise<URL>;
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
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 { WayfinderRouter } from '../../../types/wayfinder.js';
17
+ import { GatewaysProvider } from '../gateways.js';
18
+ export declare class PriorityGatewayRouter implements WayfinderRouter {
19
+ readonly name = "priority";
20
+ private gatewaysProvider;
21
+ private limit;
22
+ private sortBy;
23
+ private sortOrder;
24
+ private blocklist;
25
+ constructor({ gatewaysProvider, limit, sortBy, sortOrder, blocklist, }: {
26
+ gatewaysProvider: GatewaysProvider;
27
+ limit?: number;
28
+ sortBy?: 'totalDelegatedStake' | 'operatorStake' | 'startTimestamp';
29
+ sortOrder?: 'asc' | 'desc';
30
+ blocklist?: string[];
31
+ });
32
+ getTargetGateway(): Promise<URL>;
33
+ }
@@ -0,0 +1,27 @@
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 { WayfinderRouter } from '../../../types/wayfinder.js';
17
+ import { GatewaysProvider } from '../gateways.js';
18
+ export declare class RandomGatewayRouter implements WayfinderRouter {
19
+ readonly name = "random";
20
+ private gatewaysProvider;
21
+ private blocklist;
22
+ constructor({ gatewaysProvider, blocklist, }: {
23
+ gatewaysProvider: GatewaysProvider;
24
+ blocklist?: string[];
25
+ });
26
+ getTargetGateway(): Promise<URL>;
27
+ }
@@ -0,0 +1,28 @@
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 { WayfinderRouter } from '../../../types/wayfinder.js';
17
+ export declare class SimpleCacheRouter implements WayfinderRouter {
18
+ readonly name: 'simple-cache';
19
+ private lastUpdatedTimestamp;
20
+ private ttlSeconds;
21
+ private targetGateway;
22
+ private router;
23
+ constructor({ router, ttlSeconds, }: {
24
+ router: WayfinderRouter;
25
+ ttlSeconds?: number;
26
+ });
27
+ getTargetGateway(): Promise<URL>;
28
+ }
@@ -0,0 +1,120 @@
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 { WayfinderRouter } from '../../types/wayfinder.js';
17
+ type HttpClientFunction = (...args: [string, ...unknown[]]) => unknown;
18
+ type WayfinderHttpClient<T extends HttpClientFunction> = T;
19
+ export declare const arnsRegex: RegExp;
20
+ export declare const txIdRegex: RegExp;
21
+ /**
22
+ * Core function to resolve a wayfinder url against a target gateway
23
+ * @param originalUrl - the wayfinder url to resolve
24
+ * @param targetGateway - the target gateway to resolve the url against
25
+ * @returns the resolved url that can be used to make a request
26
+ */
27
+ export declare const resolveWayfinderUrl: ({ originalUrl, targetGateway, }: {
28
+ originalUrl: string | URL;
29
+ targetGateway: string | URL;
30
+ }) => URL;
31
+ /**
32
+ * Creates a wrapped http client that supports ar:// protocol
33
+ *
34
+ * This function leverages a Proxy to intercept calls to the http client
35
+ * and redirects them to the target gateway using the resolveUrl function url.
36
+ * It also supports the http client methods like get(), post(), put(), delete(), etc.
37
+ *
38
+ * Any URLs provided that are not wayfinder urls will be returned as is.
39
+ *
40
+ * @param httpClient - the http client to wrap (e.g. axios, fetch, got, etc.)
41
+ * @param resolveUrl - the function to construct the redirect url for ar:// requests
42
+ * @returns a wrapped http client that supports ar:// protocol
43
+ */
44
+ export declare const createWayfinderClient: <T extends HttpClientFunction>({ httpClient, resolveUrl, }: {
45
+ httpClient: T;
46
+ resolveUrl: (params: {
47
+ originalUrl: string | URL;
48
+ }) => Promise<URL>;
49
+ }) => WayfinderHttpClient<T>;
50
+ /**
51
+ * The main class for the wayfinder
52
+ * @param router - the router to use for requests
53
+ * @param httpClient - the http client to use for requests
54
+ * @param blocklist - the blocklist of gateways to avoid
55
+ */
56
+ export declare class Wayfinder<T extends HttpClientFunction> {
57
+ /**
58
+ * The router to use for requests
59
+ *
60
+ * @example
61
+ * const wayfinder = new Wayfinder({
62
+ * router: new RandomGatewayRouter({
63
+ * gatewaysProvider: new ARIOGatewaysProvider({ ario: ARIO.mainnet() })
64
+ * }),
65
+ * });
66
+ */
67
+ readonly router: WayfinderRouter;
68
+ /**
69
+ * The http client to use for requests
70
+ *
71
+ * @example
72
+ * const wayfinder = new Wayfinder({
73
+ * router: new RandomGatewayRouter({
74
+ * gatewaysProvider: new ARIOGatewaysProvider({ ario: ARIO.mainnet() })
75
+ * }),
76
+ * httpClient: axios,
77
+ * });
78
+ */
79
+ readonly httpClient: T;
80
+ /**
81
+ * The function that resolves the redirect url for ar:// requests to a target gateway
82
+ *
83
+ * @example
84
+ * const wayfinder = new Wayfinder({
85
+ * router: new RandomGatewayRouter({
86
+ * gatewaysProvider: new ARIOGatewaysProvider({ ario: ARIO.mainnet() })
87
+ * }),
88
+ * httpClient: axios,
89
+ * });
90
+ *
91
+ * const redirectUrl = await wayfinder.resolveUrl({ originalUrl: 'ar://example' });
92
+ */
93
+ readonly resolveUrl: (params: {
94
+ originalUrl: string;
95
+ }) => Promise<URL>;
96
+ /**
97
+ * A wrapped http client that supports ar:// protocol
98
+ *
99
+ * @example
100
+ * const { request: wayfind } = new Wayfinder({
101
+ * router: new RandomGatewayRouter({
102
+ * gatewaysProvider: new ARIOGatewaysProvider({ ario: ARIO.mainnet() })
103
+ * }),
104
+ * httpClient: axios,
105
+ * });;
106
+ *
107
+ * const response = await wayfind('ar://example', {
108
+ * method: 'POST',
109
+ * data: {
110
+ * name: 'John Doe',
111
+ * },
112
+ * })
113
+ */
114
+ readonly request: WayfinderHttpClient<T>;
115
+ constructor({ router, httpClient, }: {
116
+ router: WayfinderRouter;
117
+ httpClient: T;
118
+ });
119
+ }
120
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -127,11 +127,63 @@ export declare const AntStateSchema: z.ZodObject<{
127
127
  Initialized: boolean;
128
128
  }>;
129
129
  export type AoANTState = z.infer<typeof AntStateSchema>;
130
+ export declare const SpawnANTStateSchema: z.ZodObject<{
131
+ name: z.ZodString;
132
+ ticker: z.ZodString;
133
+ description: z.ZodString;
134
+ keywords: z.ZodArray<z.ZodString, "many">;
135
+ owner: z.ZodString;
136
+ controllers: z.ZodArray<z.ZodString, "many">;
137
+ records: z.ZodRecord<z.ZodString, z.ZodObject<{
138
+ transactionId: z.ZodEffects<z.ZodString, string, string>;
139
+ ttlSeconds: z.ZodNumber;
140
+ priority: z.ZodOptional<z.ZodNumber>;
141
+ }, "strip", z.ZodTypeAny, {
142
+ transactionId: string;
143
+ ttlSeconds: number;
144
+ priority?: number | undefined;
145
+ }, {
146
+ transactionId: string;
147
+ ttlSeconds: number;
148
+ priority?: number | undefined;
149
+ }>>;
150
+ balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
151
+ logo: z.ZodEffects<z.ZodString, string, string>;
152
+ }, "strip", z.ZodTypeAny, {
153
+ description: string;
154
+ name: string;
155
+ ticker: string;
156
+ keywords: string[];
157
+ owner: string;
158
+ controllers: string[];
159
+ records: Record<string, {
160
+ transactionId: string;
161
+ ttlSeconds: number;
162
+ priority?: number | undefined;
163
+ }>;
164
+ balances: Record<string, number>;
165
+ logo: string;
166
+ }, {
167
+ description: string;
168
+ name: string;
169
+ ticker: string;
170
+ keywords: string[];
171
+ owner: string;
172
+ controllers: string[];
173
+ records: Record<string, {
174
+ transactionId: string;
175
+ ttlSeconds: number;
176
+ priority?: number | undefined;
177
+ }>;
178
+ balances: Record<string, number>;
179
+ logo: string;
180
+ }>;
181
+ export type SpawnANTState = z.infer<typeof SpawnANTStateSchema>;
130
182
  export declare const AntReadHandlers: readonly ["balance", "balances", "totalSupply", "info", "controllers", "record", "records", "state"];
131
183
  export type AoANTReadHandler = (typeof AntReadHandlers)[number];
132
184
  export declare const AntWriteHandlers: readonly ["_eval", "_default", "transfer", "addController", "removeController", "setRecord", "removeRecord", "setName", "setTicker", "setDescription", "setKeywords", "setLogo", "initializeState", "releaseName", "reassignName", "approvePrimaryName", "removePrimaryNames"];
133
185
  export type AoANTWriteHandler = (typeof AntWriteHandlers)[number];
134
- export declare const AntHandlerNames: ("balance" | "balances" | "totalSupply" | "info" | "controllers" | "record" | "records" | "state" | "_eval" | "_default" | "transfer" | "addController" | "removeController" | "setRecord" | "removeRecord" | "setName" | "setTicker" | "setDescription" | "setKeywords" | "setLogo" | "initializeState" | "releaseName" | "reassignName" | "approvePrimaryName" | "removePrimaryNames")[];
186
+ export declare const AntHandlerNames: ("controllers" | "records" | "balances" | "balance" | "totalSupply" | "info" | "record" | "state" | "_eval" | "_default" | "transfer" | "addController" | "removeController" | "setRecord" | "removeRecord" | "setName" | "setTicker" | "setDescription" | "setKeywords" | "setLogo" | "initializeState" | "releaseName" | "reassignName" | "approvePrimaryName" | "removePrimaryNames")[];
135
187
  export type AoANTHandler = AoANTWriteHandler | AoANTReadHandler;
136
188
  export declare const AntHandlersSchema: z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>;
137
189
  export declare const AntInfoSchema: z.ZodObject<{
@@ -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 { Signer } from '@dha-team/arbundles';
16
+ import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, Signer } from '@dha-team/arbundles';
17
17
  import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
18
18
  import Arweave from 'arweave';
19
19
  import { AoSigner } from './token.js';
@@ -26,6 +26,10 @@ export type ProcessId = string;
26
26
  export type OptionalArweave<T = NonNullable<unknown>> = {
27
27
  arweave?: Arweave;
28
28
  } & T;
29
+ export type OptionalPaymentUrl<T = NonNullable<unknown>> = {
30
+ paymentUrl?: string;
31
+ } & T;
32
+ export type TurboArNSSigner = EthereumSigner | InjectedEthereumSigner | ArweaveSigner | ArconnectSigner | Window['arweaveWallet'];
29
33
  export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
30
34
  export type WithSigner<T = NonNullable<unknown>> = {
31
35
  signer: ContractSigner;
@@ -44,8 +48,9 @@ export type WriteOptions = {
44
48
  }[];
45
49
  };
46
50
  export type WriteParameters<Input> = WithSigner<Required<ReadParameters<Input>>>;
47
- export type AoMessageResult = {
51
+ export type AoMessageResult<T = Record<string, string | number | boolean | null>> = {
48
52
  id: string;
53
+ result?: T;
49
54
  };
50
55
  export type AoPrimaryNameRequest = {
51
56
  name: string;
@@ -19,3 +19,4 @@ export * from './common.js';
19
19
  export * from './faucet.js';
20
20
  export * from './io.js';
21
21
  export * from './token.js';
22
+ export * from './wayfinder.js';
@@ -310,7 +310,7 @@ export type AoTokenCostParams = {
310
310
  quantity?: number;
311
311
  fromAddress?: WalletAddress;
312
312
  };
313
- export declare const fundFromOptions: readonly ["balance", "stakes", "any"];
313
+ export declare const fundFromOptions: readonly ["balance", "stakes", "any", "turbo"];
314
314
  export type FundFrom = (typeof fundFromOptions)[number];
315
315
  export declare const isValidFundFrom: (fundFrom: string) => fundFrom is FundFrom;
316
316
  export type AoGetCostDetailsParams = AoTokenCostParams & {
@@ -338,6 +338,7 @@ export type CostDetailsResult = {
338
338
  basePrice: number;
339
339
  };
340
340
  fundingPlan?: AoFundingPlan;
341
+ wincQty?: string;
341
342
  };
342
343
  export type AoGetVaultParams = {
343
344
  address: WalletAddress;
@@ -420,6 +421,7 @@ export type DemandFactorSettings = {
420
421
  criteria: string;
421
422
  };
422
423
  export interface AoARIORead {
424
+ process: AOProcess;
423
425
  getInfo(): Promise<{
424
426
  Ticker: string;
425
427
  Name: string;
@@ -523,10 +525,10 @@ export interface AoARIOWrite extends AoARIORead {
523
525
  reportTxId: TransactionId;
524
526
  failedGateways: WalletAddress[];
525
527
  }>;
526
- buyRecord: AoWriteAction<AoBuyRecordParams>;
527
- upgradeRecord: AoWriteAction<AoArNSPurchaseParams>;
528
- extendLease: AoWriteAction<AoExtendLeaseParams>;
529
- increaseUndernameLimit: AoWriteAction<AoIncreaseUndernameLimitParams>;
528
+ buyRecord: AoWriteAction<AoBuyRecordParams, AoMessageResult>;
529
+ upgradeRecord: AoWriteAction<AoArNSPurchaseParams, AoMessageResult>;
530
+ extendLease: AoWriteAction<AoExtendLeaseParams, AoMessageResult>;
531
+ increaseUndernameLimit: AoWriteAction<AoIncreaseUndernameLimitParams, AoMessageResult>;
530
532
  cancelWithdrawal: AoWriteAction<{
531
533
  gatewayAddress?: WalletAddress;
532
534
  vaultId: string;
@@ -0,0 +1,19 @@
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 interface WayfinderRouter {
17
+ readonly name: string;
18
+ getTargetGateway: () => Promise<URL>;
19
+ }
@@ -1,18 +1,7 @@
1
1
  import Arweave from 'arweave';
2
2
  import { Logger } from '../common/index.js';
3
- import { AoANTRecord } from '../types/ant.js';
3
+ import { SpawnANTState } from '../types/ant.js';
4
4
  import { AoClient, AoEpochData, AoEpochDistributed, AoSigner, ContractSigner, WalletAddress } from '../types/index.js';
5
- export type SpawnANTState = {
6
- owner: WalletAddress;
7
- controllers: WalletAddress[];
8
- name: string;
9
- description: string;
10
- keywords: string[];
11
- ticker: string;
12
- records: Record<string, AoANTRecord>;
13
- balances: Record<WalletAddress, number>;
14
- logo: string;
15
- };
16
5
  export type SpawnANTParams = {
17
6
  signer: AoSigner;
18
7
  module?: string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Cryptographically secure helper for randomness, does not support seeding
3
+ * @param min - the minimum value
4
+ * @param max - the maximum value
5
+ * @returns a random integer between min and max
6
+ */
7
+ export declare const randomInt: (min: number, max: number) => number;
@@ -0,0 +1,19 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -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.10.0-alpha.1";
16
+ export declare const version = "3.11.0-alpha.1";