@ar.io/sdk 2.1.0-alpha.3 → 2.1.0-alpha.5

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.
@@ -18,6 +18,7 @@ exports.AoANTWriteable = exports.AoANTReadable = exports.ANT = void 0;
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
20
  const types_js_1 = require("../types.js");
21
+ const ao_js_1 = require("../utils/ao.js");
21
22
  const index_js_1 = require("./index.js");
22
23
  class ANT {
23
24
  static init({ signer, ...config }) {
@@ -186,7 +187,7 @@ class AoANTWriteable extends AoANTReadable {
186
187
  signer;
187
188
  constructor({ signer, ...config }) {
188
189
  super(config);
189
- this.signer = signer;
190
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
190
191
  }
191
192
  /**
192
193
  * @param target @type {string} The address of the account you want to transfer the ANT to.
@@ -18,7 +18,6 @@ exports.AOProcess = void 0;
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
20
  const aoconnect_1 = require("@permaweb/aoconnect");
21
- const arbundles_1 = require("arbundles");
22
21
  const json_js_1 = require("../../utils/json.js");
23
22
  const version_js_1 = require("../../version.js");
24
23
  const error_js_1 = require("../error.js");
@@ -32,22 +31,6 @@ class AOProcess {
32
31
  this.logger = logger;
33
32
  this.ao = ao;
34
33
  }
35
- // TODO: could abstract into our own interface that constructs different signers
36
- static async createAoSigner(signer) {
37
- // ensure appropriate permissions are granted with injected signers.
38
- if (signer.publicKey === undefined && 'setPublicKey' in signer) {
39
- await signer.setPublicKey();
40
- }
41
- const aoSigner = async ({ data, tags, target, anchor }) => {
42
- const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
43
- const signedData = dataItem.sign(signer).then(async () => ({
44
- id: await dataItem.id,
45
- raw: await dataItem.getRaw(),
46
- }));
47
- return signedData;
48
- };
49
- return aoSigner;
50
- }
51
34
  async read({ tags, retries = 3, }) {
52
35
  let attempts = 0;
53
36
  let lastError;
@@ -109,7 +92,7 @@ class AOProcess {
109
92
  // TODO: any other default tags we want to add?
110
93
  tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
111
94
  data: typeof data !== 'string' ? JSON.stringify(data) : data,
112
- signer: await AOProcess.createAoSigner(signer),
95
+ signer,
113
96
  });
114
97
  this.logger.debug(`Sent message to process`, {
115
98
  messageId,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IOWriteable = exports.IOReadable = exports.IO = void 0;
4
4
  const constants_js_1 = require("../constants.js");
5
5
  const io_js_1 = require("../io.js");
6
+ const ao_js_1 = require("../utils/ao.js");
6
7
  const arweave_js_1 = require("./arweave.js");
7
8
  const ao_process_js_1 = require("./contracts/ao-process.js");
8
9
  const error_js_1 = require("./error.js");
@@ -346,11 +347,11 @@ class IOWriteable extends IOReadable {
346
347
  processId: constants_js_1.IO_TESTNET_PROCESS_ID,
347
348
  }),
348
349
  });
349
- this.signer = signer;
350
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
350
351
  }
351
352
  else if ((0, io_js_1.isProcessConfiguration)(config)) {
352
353
  super({ process: config.process });
353
- this.signer = signer;
354
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
354
355
  }
355
356
  else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
356
357
  super({
@@ -358,7 +359,7 @@ class IOWriteable extends IOReadable {
358
359
  processId: config.processId,
359
360
  }),
360
361
  });
361
- this.signer = signer;
362
+ this.signer = (0, ao_js_1.createAoSigner)(signer);
362
363
  }
363
364
  else {
364
365
  throw new error_js_1.InvalidContractConfigurationError();
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.evolveANT = exports.spawnANT = void 0;
3
+ exports.createAoSigner = exports.evolveANT = exports.spawnANT = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
@@ -18,6 +18,7 @@ exports.evolveANT = exports.spawnANT = void 0;
18
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  */
20
20
  const aoconnect_1 = require("@permaweb/aoconnect");
21
+ const arbundles_1 = require("arbundles");
21
22
  const arweave_js_1 = require("../common/arweave.js");
22
23
  const index_js_1 = require("../common/index.js");
23
24
  const constants_js_1 = require("../constants.js");
@@ -30,7 +31,7 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
30
31
  const processId = await ao.spawn({
31
32
  module,
32
33
  scheduler,
33
- signer: await index_js_1.AOProcess.createAoSigner(signer),
34
+ signer,
34
35
  });
35
36
  const aosClient = new index_js_1.AOProcess({
36
37
  processId,
@@ -82,3 +83,24 @@ async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_L
82
83
  return id;
83
84
  }
84
85
  exports.evolveANT = evolveANT;
86
+ function createAoSigner(signer) {
87
+ if (!('publicKey' in signer)) {
88
+ return (0, aoconnect_1.createDataItemSigner)(signer);
89
+ }
90
+ const aoSigner = async ({ data, tags, target, anchor }) => {
91
+ // ensure appropriate permissions are granted with injected signers.
92
+ if (signer.publicKey === undefined &&
93
+ 'setPublicKey' in signer &&
94
+ typeof signer.setPublicKey === 'function') {
95
+ await signer.setPublicKey();
96
+ }
97
+ const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
98
+ const signedData = dataItem.sign(signer).then(async () => ({
99
+ id: await dataItem.id,
100
+ raw: await dataItem.getRaw(),
101
+ }));
102
+ return signedData;
103
+ };
104
+ return aoSigner;
105
+ }
106
+ exports.createAoSigner = createAoSigner;
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.version = void 0;
20
20
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
21
- exports.version = '2.1.0-alpha.3';
21
+ exports.version = '2.1.0-alpha.5';
@@ -15,6 +15,7 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  import { isProcessConfiguration, isProcessIdConfiguration, } from '../types.js';
18
+ import { createAoSigner } from '../utils/ao.js';
18
19
  import { AOProcess, InvalidContractConfigurationError } from './index.js';
19
20
  export class ANT {
20
21
  static init({ signer, ...config }) {
@@ -181,7 +182,7 @@ export class AoANTWriteable extends AoANTReadable {
181
182
  signer;
182
183
  constructor({ signer, ...config }) {
183
184
  super(config);
184
- this.signer = signer;
185
+ this.signer = createAoSigner(signer);
185
186
  }
186
187
  /**
187
188
  * @param target @type {string} The address of the account you want to transfer the ANT to.
@@ -15,7 +15,6 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  import { connect } from '@permaweb/aoconnect';
18
- import { createData } from 'arbundles';
19
18
  import { safeDecode } from '../../utils/json.js';
20
19
  import { version } from '../../version.js';
21
20
  import { WriteInteractionError } from '../error.js';
@@ -29,22 +28,6 @@ export class AOProcess {
29
28
  this.logger = logger;
30
29
  this.ao = ao;
31
30
  }
32
- // TODO: could abstract into our own interface that constructs different signers
33
- static async createAoSigner(signer) {
34
- // ensure appropriate permissions are granted with injected signers.
35
- if (signer.publicKey === undefined && 'setPublicKey' in signer) {
36
- await signer.setPublicKey();
37
- }
38
- const aoSigner = async ({ data, tags, target, anchor }) => {
39
- const dataItem = createData(data, signer, { tags, target, anchor });
40
- const signedData = dataItem.sign(signer).then(async () => ({
41
- id: await dataItem.id,
42
- raw: await dataItem.getRaw(),
43
- }));
44
- return signedData;
45
- };
46
- return aoSigner;
47
- }
48
31
  async read({ tags, retries = 3, }) {
49
32
  let attempts = 0;
50
33
  let lastError;
@@ -106,7 +89,7 @@ export class AOProcess {
106
89
  // TODO: any other default tags we want to add?
107
90
  tags: [...tags, { name: 'AR-IO-SDK', value: version }],
108
91
  data: typeof data !== 'string' ? JSON.stringify(data) : data,
109
- signer: await AOProcess.createAoSigner(signer),
92
+ signer,
110
93
  });
111
94
  this.logger.debug(`Sent message to process`, {
112
95
  messageId,
@@ -1,5 +1,6 @@
1
1
  import { IO_TESTNET_PROCESS_ID } from '../constants.js';
2
2
  import { isProcessConfiguration, isProcessIdConfiguration, } from '../io.js';
3
+ import { createAoSigner } from '../utils/ao.js';
3
4
  import { defaultArweave } from './arweave.js';
4
5
  import { AOProcess } from './contracts/ao-process.js';
5
6
  import { InvalidContractConfigurationError } from './error.js';
@@ -341,11 +342,11 @@ export class IOWriteable extends IOReadable {
341
342
  processId: IO_TESTNET_PROCESS_ID,
342
343
  }),
343
344
  });
344
- this.signer = signer;
345
+ this.signer = createAoSigner(signer);
345
346
  }
346
347
  else if (isProcessConfiguration(config)) {
347
348
  super({ process: config.process });
348
- this.signer = signer;
349
+ this.signer = createAoSigner(signer);
349
350
  }
350
351
  else if (isProcessIdConfiguration(config)) {
351
352
  super({
@@ -353,7 +354,7 @@ export class IOWriteable extends IOReadable {
353
354
  processId: config.processId,
354
355
  }),
355
356
  });
356
- this.signer = signer;
357
+ this.signer = createAoSigner(signer);
357
358
  }
358
359
  else {
359
360
  throw new InvalidContractConfigurationError();
@@ -14,7 +14,8 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- import { connect } from '@permaweb/aoconnect';
17
+ import { connect, createDataItemSigner } from '@permaweb/aoconnect';
18
+ import { createData } from 'arbundles';
18
19
  import { defaultArweave } from '../common/arweave.js';
19
20
  import { AOProcess } from '../common/index.js';
20
21
  import { ANT_LUA_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
@@ -27,7 +28,7 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
27
28
  const processId = await ao.spawn({
28
29
  module,
29
30
  scheduler,
30
- signer: await AOProcess.createAoSigner(signer),
31
+ signer,
31
32
  });
32
33
  const aosClient = new AOProcess({
33
34
  processId,
@@ -77,3 +78,23 @@ export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, a
77
78
  });
78
79
  return id;
79
80
  }
81
+ export function createAoSigner(signer) {
82
+ if (!('publicKey' in signer)) {
83
+ return createDataItemSigner(signer);
84
+ }
85
+ const aoSigner = async ({ data, tags, target, anchor }) => {
86
+ // ensure appropriate permissions are granted with injected signers.
87
+ if (signer.publicKey === undefined &&
88
+ 'setPublicKey' in signer &&
89
+ typeof signer.setPublicKey === 'function') {
90
+ await signer.setPublicKey();
91
+ }
92
+ const dataItem = createData(data, signer, { tags, target, anchor });
93
+ const signedData = dataItem.sign(signer).then(async () => ({
94
+ id: await dataItem.id,
95
+ raw: await dataItem.getRaw(),
96
+ }));
97
+ return signedData;
98
+ };
99
+ return aoSigner;
100
+ }
@@ -15,4 +15,4 @@
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
18
- export const version = '2.1.0-alpha.3';
18
+ export const version = '2.1.0-alpha.5';
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import { AOContract, AoClient, ContractSigner } from '../../types.js';
1
+ import { AOContract, AoClient, AoSigner } from '../../types.js';
3
2
  import { ILogger } from '../logger.js';
4
3
  export declare class AOProcess implements AOContract {
5
4
  private logger;
@@ -10,18 +9,6 @@ export declare class AOProcess implements AOContract {
10
9
  ao?: AoClient;
11
10
  logger?: ILogger;
12
11
  });
13
- static createAoSigner(signer: ContractSigner): Promise<(args: {
14
- data: string | Buffer;
15
- tags?: {
16
- name: string;
17
- value: string;
18
- }[];
19
- target?: string;
20
- anchor?: string;
21
- }) => Promise<{
22
- id: string;
23
- raw: ArrayBuffer;
24
- }>>;
25
12
  read<K>({ tags, retries, }: {
26
13
  tags?: Array<{
27
14
  name: string;
@@ -35,7 +22,7 @@ export declare class AOProcess implements AOContract {
35
22
  value: string;
36
23
  }>;
37
24
  data?: I;
38
- signer: ContractSigner;
25
+ signer: AoSigner;
39
26
  retries?: number;
40
27
  }): Promise<{
41
28
  id: string;
@@ -16,7 +16,7 @@
16
16
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
19
- import { ArconnectSigner, ArweaveSigner } from 'arbundles';
19
+ import { Signer } from 'arbundles';
20
20
  import { AllowedProtocols, GatewayConnectionSettings, GatewayMetadata, GatewayStakingSettings } from './contract-state.js';
21
21
  import { mIOToken } from './token.js';
22
22
  export type BlockHeight = number;
@@ -25,7 +25,7 @@ export type Timestamp = number;
25
25
  export type WalletAddress = string;
26
26
  export type TransactionId = string;
27
27
  export type ProcessId = string;
28
- export type ContractSigner = ArweaveSigner | ArconnectSigner;
28
+ export type ContractSigner = Signer | Window['arweaveWallet'];
29
29
  export type WithSigner<T = NonNullable<unknown>> = {
30
30
  signer: ContractSigner;
31
31
  } & T;
@@ -63,11 +63,13 @@ export type GatewayConnectionSettings = {
63
63
  export type GatewaySettings = GatewayConnectionSettings & GatewayStakingSettings & GatewayMetadata;
64
64
  export type AllowedProtocols = 'https';
65
65
  export type GatewayStats = {
66
- failedConsecutiveEpochs: number;
67
- passedEpochCount: number;
68
- submittedEpochCount: number;
66
+ prescribedEpochCount: number;
67
+ observedEpochCount: number;
69
68
  totalEpochCount: number;
70
- totalEpochsPrescribedCount: number;
69
+ passedEpochCount: number;
70
+ failedEpochCount: number;
71
+ failedConsecutiveEpochs: number;
72
+ passedConsecutiveEpochs: number;
71
73
  };
72
74
  export type WeightedObserver = {
73
75
  gatewayAddress: WalletAddress;
package/lib/types/io.d.ts CHANGED
@@ -16,8 +16,8 @@
16
16
  */
17
17
  import { AOProcess } from './common/index.js';
18
18
  import { ANTRecord, ArNSReservedNameData, EpochDistributionData, EpochObservations, GatewayDelegate, GatewaySettings, RegistrationType, VaultData, WeightedObserver } from './contract-state.js';
19
- import { mIOToken } from './token.js';
20
- import { AoMessageResult, BlockHeight, ContractSigner, JoinNetworkParams, ProcessId, Timestamp, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WriteOptions } from './types.js';
19
+ import { AoSigner, mIOToken } from './token.js';
20
+ import { AoMessageResult, BlockHeight, JoinNetworkParams, ProcessId, Timestamp, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WriteOptions } from './types.js';
21
21
  export declare function isProcessConfiguration(config: object): config is {
22
22
  process: AOProcess;
23
23
  };
@@ -63,7 +63,7 @@ export interface AOContract {
63
63
  value: string;
64
64
  }[];
65
65
  data: I;
66
- signer: ContractSigner;
66
+ signer: AoSigner;
67
67
  }): Promise<{
68
68
  id: string;
69
69
  result?: K;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  interface Equatable<T> {
2
3
  equals(other: T): boolean;
3
4
  }
@@ -31,4 +32,16 @@ export declare class mIOToken extends PositiveFiniteInteger {
31
32
  minus(subtractHend: mIOToken): mIOToken;
32
33
  toIO(): IOToken;
33
34
  }
35
+ export type AoSigner = (args: {
36
+ data: string | Buffer;
37
+ tags?: {
38
+ name: string;
39
+ value: string;
40
+ }[];
41
+ target?: string;
42
+ anchor?: string;
43
+ }) => Promise<{
44
+ id: string;
45
+ raw: ArrayBuffer;
46
+ }>;
34
47
  export {};
@@ -1,7 +1,7 @@
1
1
  import { ANTState } from '../contract-state.js';
2
- import { AoClient, ContractSigner } from '../types.js';
2
+ import { AoClient, AoSigner, ContractSigner } from '../types.js';
3
3
  export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, state, stateContractTxId, }: {
4
- signer: ContractSigner;
4
+ signer: AoSigner;
5
5
  module?: string;
6
6
  luaCodeTxId?: string;
7
7
  ao?: AoClient;
@@ -10,8 +10,9 @@ export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, s
10
10
  stateContractTxId?: string;
11
11
  }): Promise<string>;
12
12
  export declare function evolveANT({ signer, processId, luaCodeTxId, ao, }: {
13
- signer: ContractSigner;
13
+ signer: AoSigner;
14
14
  processId: string;
15
15
  luaCodeTxId?: string;
16
16
  ao?: AoClient;
17
17
  }): Promise<string>;
18
+ export declare function createAoSigner(signer: ContractSigner): AoSigner;
@@ -14,4 +14,4 @@
14
14
  * You should have received a copy of the GNU Affero General Public License
15
15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
- export declare const version = "2.1.0-alpha.2";
17
+ export declare const version = "2.1.0-alpha.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "2.1.0-alpha.3",
3
+ "version": "2.1.0-alpha.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -91,6 +91,7 @@
91
91
  "@types/sinon": "^10.0.15",
92
92
  "@typescript-eslint/eslint-plugin": "^5.62.0",
93
93
  "@typescript-eslint/parser": "^6.4.0",
94
+ "arconnect": "^1.0.3",
94
95
  "dotenv": "^16.4.5",
95
96
  "dotenv-cli": "^7.4.2",
96
97
  "esbuild": "^0.19.2",
@@ -118,7 +119,7 @@
118
119
  "vite-plugin-node-polyfills": "^0.22.0"
119
120
  },
120
121
  "dependencies": {
121
- "@permaweb/aoconnect": "^0.0.55",
122
+ "@permaweb/aoconnect": "^0.0.57",
122
123
  "arbundles": "0.11.0",
123
124
  "arweave": "1.14.4",
124
125
  "axios": "1.7.2",