@ar.io/sdk 2.2.0-alpha.2 → 2.2.0-alpha.4

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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
3
+ exports.isAoANTState = exports.AntStateSchema = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
@@ -24,10 +24,12 @@ const arweave_js_1 = require("../common/arweave.js");
24
24
  const index_js_1 = require("../common/index.js");
25
25
  const constants_js_1 = require("../constants.js");
26
26
  async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = constants_js_1.ANT_REGISTRY_ID, }) {
27
- // AoSigner is not a Contract Signer - should probably add that to the contract signer type
28
- const registryClient = new index_js_1.AOProcess({
29
- processId: antRegistryId,
30
- ao,
27
+ const registryClient = index_js_1.ANTRegistry.init({
28
+ process: new index_js_1.AOProcess({
29
+ processId: antRegistryId,
30
+ ao,
31
+ }),
32
+ signer: signer,
31
33
  });
32
34
  //TODO: cache locally and only fetch if not cached
33
35
  const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
@@ -70,13 +72,7 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
70
72
  signer,
71
73
  });
72
74
  }
73
- await registryClient.send({
74
- tags: [
75
- { name: 'Action', value: 'Register' },
76
- { name: 'Process-Id', value: processId },
77
- ],
78
- signer,
79
- });
75
+ await registryClient.register({ processId });
80
76
  return processId;
81
77
  }
82
78
  exports.spawnANT = spawnANT;
@@ -152,3 +148,36 @@ function createAoSigner(signer) {
152
148
  return aoSigner;
153
149
  }
154
150
  exports.createAoSigner = createAoSigner;
151
+ // using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc)
152
+ exports.AntStateSchema = zod_1.z
153
+ .object({
154
+ Name: zod_1.z.string(),
155
+ Ticker: zod_1.z.string(),
156
+ Owner: zod_1.z.string(),
157
+ Controllers: zod_1.z.array(zod_1.z.string()),
158
+ Records: zod_1.z.record(zod_1.z.string(), zod_1.z
159
+ .object({
160
+ transactionId: zod_1.z.string(),
161
+ ttlSeconds: zod_1.z.number(),
162
+ })
163
+ .passthrough()),
164
+ Balances: zod_1.z.record(zod_1.z.string(), zod_1.z.number()),
165
+ })
166
+ .passthrough();
167
+ /**
168
+ * @param state
169
+ * @returns {boolean}
170
+ * @throws {z.ZodError} if the state object does not match the expected schema
171
+ */
172
+ function isAoANTState(state, logger = index_js_1.Logger.default) {
173
+ try {
174
+ exports.AntStateSchema.parse(state);
175
+ return true;
176
+ }
177
+ catch (error) {
178
+ // this allows us to see the path of the error in the object as well as the expected schema on invalid fields
179
+ logger.error(error.issues);
180
+ return false;
181
+ }
182
+ }
183
+ exports.isAoANTState = isAoANTState;
@@ -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.2.0-alpha.2';
21
+ exports.version = '2.2.0-alpha.4';
@@ -18,13 +18,15 @@ import { connect, createDataItemSigner } from '@permaweb/aoconnect';
18
18
  import { createData } from 'arbundles';
19
19
  import { z } from 'zod';
20
20
  import { defaultArweave } from '../common/arweave.js';
21
- import { AOProcess } from '../common/index.js';
21
+ import { ANTRegistry, AOProcess, Logger } from '../common/index.js';
22
22
  import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
23
23
  export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = ANT_LUA_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, stateContractTxId, antRegistryId = ANT_REGISTRY_ID, }) {
24
- // AoSigner is not a Contract Signer - should probably add that to the contract signer type
25
- const registryClient = new AOProcess({
26
- processId: antRegistryId,
27
- ao,
24
+ const registryClient = ANTRegistry.init({
25
+ process: new AOProcess({
26
+ processId: antRegistryId,
27
+ ao,
28
+ }),
29
+ signer: signer,
28
30
  });
29
31
  //TODO: cache locally and only fetch if not cached
30
32
  const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
@@ -67,13 +69,7 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
67
69
  signer,
68
70
  });
69
71
  }
70
- await registryClient.send({
71
- tags: [
72
- { name: 'Action', value: 'Register' },
73
- { name: 'Process-Id', value: processId },
74
- ],
75
- signer,
76
- });
72
+ await registryClient.register({ processId });
77
73
  return processId;
78
74
  }
79
75
  export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, ao = connect(), }) {
@@ -145,3 +141,35 @@ export function createAoSigner(signer) {
145
141
  };
146
142
  return aoSigner;
147
143
  }
144
+ // using passThrough to require the minimum fields and allow others (eg TotalSupply, Logo, etc)
145
+ export const AntStateSchema = z
146
+ .object({
147
+ Name: z.string(),
148
+ Ticker: z.string(),
149
+ Owner: z.string(),
150
+ Controllers: z.array(z.string()),
151
+ Records: z.record(z.string(), z
152
+ .object({
153
+ transactionId: z.string(),
154
+ ttlSeconds: z.number(),
155
+ })
156
+ .passthrough()),
157
+ Balances: z.record(z.string(), z.number()),
158
+ })
159
+ .passthrough();
160
+ /**
161
+ * @param state
162
+ * @returns {boolean}
163
+ * @throws {z.ZodError} if the state object does not match the expected schema
164
+ */
165
+ export function isAoANTState(state, logger = Logger.default) {
166
+ try {
167
+ AntStateSchema.parse(state);
168
+ return true;
169
+ }
170
+ catch (error) {
171
+ // this allows us to see the path of the error in the object as well as the expected schema on invalid fields
172
+ logger.error(error.issues);
173
+ return false;
174
+ }
175
+ }
@@ -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.2.0-alpha.2';
18
+ export const version = '2.2.0-alpha.4';
@@ -5,7 +5,7 @@ export declare class ANTRegistry {
5
5
  static init(config: Required<ProcessConfiguration> & {
6
6
  signer?: undefined;
7
7
  }): AoANTRegistryRead;
8
- static init({ signer, ...config }: WithSigner<Required<ProcessConfiguration>>): AoANTRegistryRead;
8
+ static init({ signer, ...config }: WithSigner<Required<ProcessConfiguration>>): AoANTRegistryWrite;
9
9
  }
10
10
  export declare class AoANTRegistryReadable implements AoANTRegistryRead {
11
11
  protected process: AOProcess;
@@ -1,4 +1,6 @@
1
- import { AoANTRecord, AoClient, AoSigner, ContractSigner, WalletAddress } from '../types.js';
1
+ import { z } from 'zod';
2
+ import { Logger } from '../common/index.js';
3
+ import { AoANTRecord, AoANTState, AoClient, AoSigner, ContractSigner, WalletAddress } from '../types.js';
2
4
  export declare function spawnANT({ signer, module, luaCodeTxId, ao, scheduler, state, stateContractTxId, antRegistryId, }: {
3
5
  signer: AoSigner;
4
6
  module?: string;
@@ -24,3 +26,58 @@ export declare function evolveANT({ signer, processId, luaCodeTxId, ao, }: {
24
26
  }): Promise<string>;
25
27
  export declare function isAoSigner(value: unknown): value is AoSigner;
26
28
  export declare function createAoSigner(signer: ContractSigner): AoSigner;
29
+ export declare const AntStateSchema: z.ZodObject<{
30
+ Name: z.ZodString;
31
+ Ticker: z.ZodString;
32
+ Owner: z.ZodString;
33
+ Controllers: z.ZodArray<z.ZodString, "many">;
34
+ Records: z.ZodRecord<z.ZodString, z.ZodObject<{
35
+ transactionId: z.ZodString;
36
+ ttlSeconds: z.ZodNumber;
37
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
38
+ transactionId: z.ZodString;
39
+ ttlSeconds: z.ZodNumber;
40
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
41
+ transactionId: z.ZodString;
42
+ ttlSeconds: z.ZodNumber;
43
+ }, z.ZodTypeAny, "passthrough">>>;
44
+ Balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
45
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
46
+ Name: z.ZodString;
47
+ Ticker: z.ZodString;
48
+ Owner: z.ZodString;
49
+ Controllers: z.ZodArray<z.ZodString, "many">;
50
+ Records: z.ZodRecord<z.ZodString, z.ZodObject<{
51
+ transactionId: z.ZodString;
52
+ ttlSeconds: z.ZodNumber;
53
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
54
+ transactionId: z.ZodString;
55
+ ttlSeconds: z.ZodNumber;
56
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
57
+ transactionId: z.ZodString;
58
+ ttlSeconds: z.ZodNumber;
59
+ }, z.ZodTypeAny, "passthrough">>>;
60
+ Balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
61
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
62
+ Name: z.ZodString;
63
+ Ticker: z.ZodString;
64
+ Owner: z.ZodString;
65
+ Controllers: z.ZodArray<z.ZodString, "many">;
66
+ Records: z.ZodRecord<z.ZodString, z.ZodObject<{
67
+ transactionId: z.ZodString;
68
+ ttlSeconds: z.ZodNumber;
69
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
70
+ transactionId: z.ZodString;
71
+ ttlSeconds: z.ZodNumber;
72
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
73
+ transactionId: z.ZodString;
74
+ ttlSeconds: z.ZodNumber;
75
+ }, z.ZodTypeAny, "passthrough">>>;
76
+ Balances: z.ZodRecord<z.ZodString, z.ZodNumber>;
77
+ }, z.ZodTypeAny, "passthrough">>;
78
+ /**
79
+ * @param state
80
+ * @returns {boolean}
81
+ * @throws {z.ZodError} if the state object does not match the expected schema
82
+ */
83
+ export declare function isAoANTState(state: object, logger?: Logger): state is AoANTState;
@@ -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.2.0-alpha.1";
17
+ export declare const version = "2.2.0-alpha.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "2.2.0-alpha.2",
3
+ "version": "2.2.0-alpha.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"