@ar.io/sdk 3.3.0-alpha.1 → 3.3.0-alpha.10

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.
@@ -1,51 +1,26 @@
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 Arweave from 'arweave';
17
1
  import { ARIO_TESTNET_PROCESS_ID } from '../constants.js';
18
2
  import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/io.js';
19
3
  import { createAoSigner } from '../utils/ao.js';
20
4
  import { getEpochDataFromGql, paginationParamsToTags, pruneTags, } from '../utils/arweave.js';
5
+ import { defaultArweave } from './arweave.js';
21
6
  import { AOProcess } from './contracts/ao-process.js';
22
7
  import { InvalidContractConfigurationError } from './error.js';
23
8
  export class ARIO {
24
- static init({ arweave, ...config } = {}) {
25
- if (config !== undefined && config.signer) {
26
- const { signer, ...rest } = config;
27
- return new ARIOWriteable({
28
- ...rest,
29
- signer,
30
- arweave,
31
- });
9
+ // Implementation
10
+ static init(config) {
11
+ if (config !== undefined && 'signer' in config) {
12
+ return new ARIOWriteable(config);
32
13
  }
33
- return new ARIOReadable({
34
- arweave,
35
- ...config,
36
- });
14
+ return new ARIOReadable(config);
37
15
  }
38
16
  }
39
17
  export class ARIOReadable {
40
18
  process;
41
19
  epochSettings;
42
20
  arweave;
43
- constructor({ arweave = Arweave.init({
44
- host: 'arweave.net',
45
- port: 443,
46
- protocol: 'https',
47
- }), ...config }) {
48
- if (config === undefined) {
21
+ constructor(config) {
22
+ this.arweave = config?.arweave ?? defaultArweave;
23
+ if (config === undefined || Object.keys(config).length === 0) {
49
24
  this.process = new AOProcess({
50
25
  processId: ARIO_TESTNET_PROCESS_ID,
51
26
  });
@@ -61,7 +36,6 @@ export class ARIOReadable {
61
36
  else {
62
37
  throw new InvalidContractConfigurationError();
63
38
  }
64
- this.arweave = arweave;
65
39
  }
66
40
  async getInfo() {
67
41
  return this.process.read({
@@ -463,35 +437,29 @@ export class ARIOReadable {
463
437
  tags: [{ name: 'Action', value: 'Gateway-Registry-Settings' }],
464
438
  });
465
439
  }
440
+ async getAllDelegates(params) {
441
+ return this.process.read({
442
+ tags: [
443
+ { name: 'Action', value: 'All-Paginated-Delegates' },
444
+ ...paginationParamsToTags(params),
445
+ ],
446
+ });
447
+ }
466
448
  }
467
449
  export class ARIOWriteable extends ARIOReadable {
468
450
  signer;
469
- constructor({ signer, arweave, ...config }) {
470
- if (Object.keys(config).length === 0) {
451
+ constructor({ signer, ...config }) {
452
+ if (config === undefined) {
471
453
  super({
472
454
  process: new AOProcess({
473
455
  processId: ARIO_TESTNET_PROCESS_ID,
474
456
  }),
475
- arweave: arweave,
476
457
  });
477
- this.signer = createAoSigner(signer);
478
- }
479
- else if (isProcessConfiguration(config)) {
480
- super({ process: config.process });
481
- this.signer = createAoSigner(signer);
482
- }
483
- else if (isProcessIdConfiguration(config)) {
484
- super({
485
- process: new AOProcess({
486
- processId: config.processId,
487
- }),
488
- arweave: arweave,
489
- });
490
- this.signer = createAoSigner(signer);
491
458
  }
492
459
  else {
493
- throw new InvalidContractConfigurationError();
460
+ super(config);
494
461
  }
462
+ this.signer = createAoSigner(signer);
495
463
  }
496
464
  async transfer({ target, qty, }, options) {
497
465
  const { tags = [] } = options || {};
@@ -26,6 +26,6 @@ export const arioDevnetProcessId = ARIO_DEVNET_PROCESS_ID;
26
26
  export const ARIO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
27
27
  export const ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
28
28
  export const MARIO_PER_ARIO = 1_000_000;
29
- export const AOS_MODULE_ID = 'tyojTpJ9fIva_7BjTA9ruGM4uk2vyTfhVUulnbVxR8I';
30
- export const ANT_LUA_ID = '16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4';
29
+ export const AOS_MODULE_ID = 'BRyNPIJWZaQ4IudfNnsfvMrZBO2YDPjgKqg_wCYT2U8';
30
+ export const ANT_LUA_ID = 'k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg';
31
31
  export const DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
@@ -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 { createData } from '@dha-team/arbundles';
16
+ import { ArconnectSigner, DataItem, createData } from '@dha-team/arbundles';
17
17
  import { connect, createDataItemSigner } from '@permaweb/aoconnect';
18
18
  import { z } from 'zod';
19
19
  import { defaultArweave } from '../common/arweave.js';
@@ -147,6 +147,20 @@ export function createAoSigner(signer) {
147
147
  typeof signer.setPublicKey === 'function') {
148
148
  await signer.setPublicKey();
149
149
  }
150
+ if (signer instanceof ArconnectSigner) {
151
+ // Sign using Arconnect signDataItem API
152
+ const signedDataItem = await signer['signer'].signDataItem({
153
+ data,
154
+ tags,
155
+ target,
156
+ anchor,
157
+ });
158
+ const dataItem = new DataItem(Buffer.from(signedDataItem));
159
+ return {
160
+ id: await dataItem.id,
161
+ raw: await dataItem.getRaw(),
162
+ };
163
+ }
150
164
  const dataItem = createData(data, signer, { tags, target, anchor });
151
165
  const signedData = dataItem.sign(signer).then(async () => ({
152
166
  id: await dataItem.id,
@@ -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.3.0-alpha.1';
17
+ export const version = '3.3.0-alpha.10';
@@ -21,6 +21,9 @@ export declare function getGateway(o: AddressCLIOptions): Promise<import("../../
21
21
  export declare function listGateways(o: PaginationCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoGatewayWithAddress> | {
22
22
  message: string;
23
23
  }>;
24
+ export declare function listAllDelegatesCLICommand(o: PaginationCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoAllDelegates> | {
25
+ message: string;
26
+ }>;
24
27
  export declare function getGatewayDelegates(o: AddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoGatewayDelegateWithAddress> | {
25
28
  message: string;
26
29
  }>;
@@ -1,12 +1,12 @@
1
1
  import { AoANTRegistryRead, AoANTRegistryWrite } from '../types/ant-registry.js';
2
2
  import { AoMessageResult, ProcessConfiguration, WithSigner } from '../types/index.js';
3
3
  import { AOProcess } from './index.js';
4
+ type ANTRegistryNoSigner = ProcessConfiguration;
5
+ type ANTRegistryWithSigner = WithSigner<ProcessConfiguration>;
4
6
  export declare class ANTRegistry {
5
7
  static init(): AoANTRegistryRead;
6
- static init(config: Required<ProcessConfiguration> & {
7
- signer?: undefined;
8
- }): AoANTRegistryRead;
9
- static init({ signer, ...config }: WithSigner<Required<ProcessConfiguration>>): AoANTRegistryWrite;
8
+ static init(config: ANTRegistryNoSigner): AoANTRegistryRead;
9
+ static init(config: ANTRegistryWithSigner): AoANTRegistryWrite;
10
10
  }
11
11
  export declare class AoANTRegistryReadable implements AoANTRegistryRead {
12
12
  protected process: AOProcess;
@@ -25,3 +25,4 @@ export declare class AoANTRegistryWriteable extends AoANTRegistryReadable implem
25
25
  processId: string;
26
26
  }): Promise<AoMessageResult>;
27
27
  }
28
+ export {};
@@ -1,21 +1,19 @@
1
1
  import { AntReadOptions, AoANTHandler, AoANTInfo, AoANTRead, AoANTRecord, AoANTState, AoANTWrite } from '../types/ant.js';
2
2
  import { AoMessageResult, ProcessConfiguration, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
3
3
  import { AOProcess } from './index.js';
4
+ type ANTConfigOptionalStrict = Required<ProcessConfiguration> & {
5
+ strict?: boolean;
6
+ };
7
+ type ANTConfigNoSigner = ANTConfigOptionalStrict;
8
+ type ANTConfigWithSigner = WithSigner<ANTConfigOptionalStrict>;
4
9
  export declare class ANT {
5
- static init(config: Required<ProcessConfiguration> & {
6
- signer?: undefined;
7
- strict?: boolean;
8
- }): AoANTRead;
9
- static init({ signer, ...config }: WithSigner<Required<ProcessConfiguration>> & {
10
- strict?: boolean;
11
- }): AoANTWrite;
10
+ static init(config: ANTConfigNoSigner): AoANTRead;
11
+ static init(config: ANTConfigWithSigner): AoANTWrite;
12
12
  }
13
13
  export declare class AoANTReadable implements AoANTRead {
14
14
  protected process: AOProcess;
15
15
  private strict;
16
- constructor(config: Required<ProcessConfiguration> & {
17
- strict?: boolean;
18
- });
16
+ constructor(config: ANTConfigOptionalStrict);
19
17
  getState({ strict }?: AntReadOptions): Promise<AoANTState>;
20
18
  getInfo({ strict }?: AntReadOptions): Promise<AoANTInfo>;
21
19
  /**
@@ -273,3 +271,4 @@ export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite
273
271
  notifyOwners?: boolean;
274
272
  }, options?: WriteOptions): Promise<AoMessageResult>;
275
273
  }
274
+ export {};
@@ -14,36 +14,22 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import Arweave from 'arweave';
17
- import { AoArNSNameDataWithName, AoArNSReservedNameData, AoBalanceWithAddress, AoEpochDistributionData, AoEpochObservationData, AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoReturnedName, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, ContractSigner, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
18
- import { AoARIORead, AoARIOWrite, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoDelegation, AoEpochData, AoEpochSettings, AoExtendLeaseParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoPaginatedAddressParams, AoRegistrationFees, AoVaultData, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
17
+ import { AoArNSNameDataWithName, AoArNSReservedNameData, AoBalanceWithAddress, AoEpochDistributionData, AoEpochObservationData, AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AoReturnedName, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, OptionalArweave, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
18
+ import { AoARIORead, AoARIOWrite, AoAllDelegates, AoArNSNameData, AoArNSPurchaseParams, AoArNSReservedNameDataWithName, AoBuyRecordParams, AoDelegation, AoEpochData, AoEpochSettings, AoExtendLeaseParams, AoGateway, AoGatewayDelegateWithAddress, AoGatewayRegistrySettings, AoGatewayVault, AoGetCostDetailsParams, AoIncreaseUndernameLimitParams, AoPaginatedAddressParams, AoRegistrationFees, AoVaultData, AoWalletVault, CostDetailsResult, DemandFactorSettings, EpochInput } from '../types/io.js';
19
19
  import { mARIOToken } from '../types/token.js';
20
20
  import { AOProcess } from './contracts/ao-process.js';
21
+ type ARIOConfigNoSigner = OptionalArweave<ProcessConfiguration>;
22
+ type ARIOConfigWithSigner = WithSigner<OptionalArweave<ProcessConfiguration>>;
21
23
  export declare class ARIO {
22
24
  static init(): AoARIORead;
23
- static init({ process }: {
24
- process: AOProcess;
25
- }): AoARIORead;
26
- static init({ process, signer, }: WithSigner<{
27
- process: AOProcess;
28
- }>): AoARIOWrite;
29
- static init({ processId, signer, }: WithSigner<{
30
- processId?: string;
31
- }>): AoARIOWrite;
32
- static init({ processId, signer, }: {
33
- signer?: ContractSigner | undefined;
34
- processId: string;
35
- }): any;
36
- static init({ processId }: {
37
- processId: string;
38
- }): AoARIORead;
25
+ static init(config: ARIOConfigWithSigner): AoARIOWrite;
26
+ static init(config: ARIOConfigNoSigner): AoARIORead;
39
27
  }
40
28
  export declare class ARIOReadable implements AoARIORead {
41
29
  protected process: AOProcess;
42
30
  protected epochSettings: AoEpochSettings | undefined;
43
31
  protected arweave: Arweave;
44
- constructor({ arweave, ...config }: ProcessConfiguration & {
45
- arweave?: Arweave;
46
- });
32
+ constructor(config?: OptionalArweave<ProcessConfiguration>);
47
33
  getInfo(): Promise<{
48
34
  Name: string;
49
35
  Ticker: string;
@@ -150,17 +136,12 @@ export declare class ARIOReadable implements AoARIORead {
150
136
  address: WalletAddress;
151
137
  }): Promise<AoRedelegationFeeInfo>;
152
138
  getGatewayRegistrySettings(): Promise<AoGatewayRegistrySettings>;
139
+ getAllDelegates(params?: PaginationParams<AoAllDelegates>): Promise<PaginationResult<AoAllDelegates>>;
153
140
  }
154
141
  export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
155
142
  protected process: AOProcess;
156
143
  private signer;
157
- constructor({ signer, arweave, ...config }: WithSigner<{
158
- process?: AOProcess;
159
- } | {
160
- processId?: string;
161
- }> & {
162
- arweave?: Arweave;
163
- });
144
+ constructor({ signer, ...config }: ARIOConfigWithSigner);
164
145
  transfer({ target, qty, }: {
165
146
  target: string;
166
147
  qty: number | mARIOToken;
@@ -253,3 +234,4 @@ export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
253
234
  vaultId?: string;
254
235
  }, options?: WriteOptions): Promise<AoMessageResult>;
255
236
  }
237
+ export {};
@@ -24,6 +24,6 @@ export declare const arioDevnetProcessId = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6
24
24
  export declare const ARIO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA";
25
25
  export declare const ANT_REGISTRY_ID = "i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc";
26
26
  export declare const MARIO_PER_ARIO = 1000000;
27
- export declare const AOS_MODULE_ID = "tyojTpJ9fIva_7BjTA9ruGM4uk2vyTfhVUulnbVxR8I";
28
- export declare const ANT_LUA_ID = "16_FyX-V2QU0RPSh1GIaEETSaUjNb0oVjCFpVbAfQq4";
27
+ export declare const AOS_MODULE_ID = "BRyNPIJWZaQ4IudfNnsfvMrZBO2YDPjgKqg_wCYT2U8";
28
+ export declare const ANT_LUA_ID = "k9tQkbnFYZOGp6ist1yFuaqk_wOkzM5KUSNDtWzCLtg";
29
29
  export declare const DEFAULT_SCHEDULER_ID = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA";
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import { Signer } from '@dha-team/arbundles';
18
18
  import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
19
+ import Arweave from 'arweave';
19
20
  import { AoSigner } from './token.js';
20
21
  export type BlockHeight = number;
21
22
  export type SortKey = string;
@@ -23,6 +24,9 @@ export type Timestamp = number;
23
24
  export type WalletAddress = string;
24
25
  export type TransactionId = string;
25
26
  export type ProcessId = string;
27
+ export type OptionalArweave<T = NonNullable<unknown>> = {
28
+ arweave?: Arweave;
29
+ } & T;
26
30
  export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
27
31
  export type WithSigner<T = NonNullable<unknown>> = {
28
32
  signer: ContractSigner;
@@ -31,16 +31,20 @@ export type PaginationResult<T> = {
31
31
  sortOrder: 'asc' | 'desc';
32
32
  hasMore: boolean;
33
33
  };
34
- export type ProcessConfiguration = {
35
- process?: AOProcess;
36
- } | {
34
+ export type ProcessIdConfig = {
37
35
  processId?: string;
38
36
  };
39
- export type EpochInput = {
40
- epochIndex: AoEpochIndex;
41
- } | {
37
+ export type ProcessConfig = {
38
+ process?: AOProcess;
39
+ };
40
+ export type ProcessConfiguration = ProcessConfig | ProcessIdConfig;
41
+ export type EpochTimestampInput = {
42
42
  timestamp: Timestamp;
43
- } | undefined;
43
+ };
44
+ export type EpochIndexInput = {
45
+ epochIndex: AoEpochIndex;
46
+ };
47
+ export type EpochInput = EpochTimestampInput | EpochIndexInput | undefined;
44
48
  export type AoBalances = Record<WalletAddress, number>;
45
49
  export type AoRegistrationFees = Record<number, {
46
50
  lease: Record<number, number>;
@@ -117,6 +121,7 @@ export type AoEpochData = {
117
121
  startTimestamp: Timestamp;
118
122
  endTimestamp: Timestamp;
119
123
  distributionTimestamp: Timestamp;
124
+ /** @deprecated - use `getDistributions` to get distribution data for a given epoch **/
120
125
  distributions: AoEpochDistributionData;
121
126
  };
122
127
  export type AoTokenSupplyData = {
@@ -412,7 +417,16 @@ export interface AoARIORead {
412
417
  address: WalletAddress;
413
418
  }): Promise<AoRedelegationFeeInfo>;
414
419
  getGatewayRegistrySettings(): Promise<AoGatewayRegistrySettings>;
420
+ getAllDelegates(params?: PaginationParams<AoAllDelegates>): Promise<PaginationResult<AoAllDelegates>>;
415
421
  }
422
+ export type AoAllDelegates = {
423
+ address: WalletAddress;
424
+ gatewayAddress: WalletAddress;
425
+ delegatedStake: number;
426
+ startTimestamp: Timestamp;
427
+ vaultedStake: number;
428
+ cursorId: string;
429
+ };
416
430
  export interface AoARIOWrite extends AoARIORead {
417
431
  transfer({ target, qty, }: {
418
432
  target: WalletAddress;
@@ -456,10 +470,6 @@ export interface AoARIOWrite extends AoARIORead {
456
470
  requestPrimaryName(params: AoArNSPurchaseParams, options?: WriteOptions): Promise<AoMessageResult>;
457
471
  redelegateStake(params: AoRedelegateStakeParams, options?: WriteOptions): Promise<AoMessageResult>;
458
472
  }
459
- export declare function isProcessConfiguration(config: object): config is {
460
- process: AOProcess;
461
- };
462
- export declare function isProcessIdConfiguration(config: object): config is {
463
- processId: string;
464
- };
473
+ export declare function isProcessConfiguration(config: object): config is Required<ProcessConfiguration> & Record<string, never>;
474
+ export declare function isProcessIdConfiguration(config: object): config is Required<ProcessIdConfig> & Record<string, never>;
465
475
  export declare function isLeasedArNSRecord(record: AoArNSNameData): record is AoArNSLeaseData;
@@ -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.2.0";
16
+ export declare const version = "3.3.0-alpha.9";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.3.0-alpha.1",
3
+ "version": "3.3.0-alpha.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -126,7 +126,7 @@
126
126
  "dependencies": {
127
127
  "@dha-team/arbundles": "^1.0.1",
128
128
  "@permaweb/aoconnect": "^0.0.57",
129
- "arweave": "1.14.4",
129
+ "arweave": "1.15.5",
130
130
  "axios": "1.7.9",
131
131
  "axios-retry": "^4.3.0",
132
132
  "commander": "^12.1.0",