@ar.io/sdk 2.1.0-alpha.10 → 2.1.0-alpha.12

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.evolveANT = exports.spawnANT = void 0;
3
+ 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
  *
@@ -19,10 +19,16 @@ exports.createAoSigner = exports.evolveANT = exports.spawnANT = void 0;
19
19
  */
20
20
  const aoconnect_1 = require("@permaweb/aoconnect");
21
21
  const arbundles_1 = require("arbundles");
22
+ const zod_1 = require("zod");
22
23
  const arweave_js_1 = require("../common/arweave.js");
23
24
  const index_js_1 = require("../common/index.js");
24
25
  const constants_js_1 = require("../constants.js");
25
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,
31
+ });
26
32
  //TODO: cache locally and only fetch if not cached
27
33
  const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
28
34
  decode: true,
@@ -64,6 +70,13 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
64
70
  signer,
65
71
  });
66
72
  }
73
+ await registryClient.send({
74
+ tags: [
75
+ { name: 'Action', value: 'Register' },
76
+ { name: 'Process-Id', value: processId },
77
+ ],
78
+ signer,
79
+ });
67
80
  return processId;
68
81
  }
69
82
  exports.spawnANT = spawnANT;
@@ -89,7 +102,36 @@ async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_L
89
102
  return id;
90
103
  }
91
104
  exports.evolveANT = evolveANT;
105
+ function isAoSigner(value) {
106
+ const TagSchema = zod_1.z.object({
107
+ name: zod_1.z.string(),
108
+ value: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]),
109
+ });
110
+ const AoSignerSchema = zod_1.z
111
+ .function()
112
+ .args(zod_1.z.object({
113
+ data: zod_1.z.union([zod_1.z.string(), zod_1.z.instanceof(Buffer)]),
114
+ tags: zod_1.z.array(TagSchema).optional(),
115
+ target: zod_1.z.string().optional(),
116
+ anchor: zod_1.z.string().optional(),
117
+ }))
118
+ .returns(zod_1.z.promise(zod_1.z.object({
119
+ id: zod_1.z.string(),
120
+ raw: zod_1.z.instanceof(ArrayBuffer),
121
+ })));
122
+ try {
123
+ AoSignerSchema.parse(value);
124
+ return true;
125
+ }
126
+ catch {
127
+ return false;
128
+ }
129
+ }
130
+ exports.isAoSigner = isAoSigner;
92
131
  function createAoSigner(signer) {
132
+ if (isAoSigner(signer)) {
133
+ return signer;
134
+ }
93
135
  if (!('publicKey' in signer)) {
94
136
  return (0, aoconnect_1.createDataItemSigner)(signer);
95
137
  }
@@ -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.10';
21
+ exports.version = '2.1.0-alpha.12';
@@ -16,10 +16,16 @@
16
16
  */
17
17
  import { connect, createDataItemSigner } from '@permaweb/aoconnect';
18
18
  import { createData } from 'arbundles';
19
+ import { z } from 'zod';
19
20
  import { defaultArweave } from '../common/arweave.js';
20
21
  import { AOProcess } from '../common/index.js';
21
22
  import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, DEFAULT_SCHEDULER_ID, } from '../constants.js';
22
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,
28
+ });
23
29
  //TODO: cache locally and only fetch if not cached
24
30
  const luaString = (await defaultArweave.transactions.getData(luaCodeTxId, {
25
31
  decode: true,
@@ -61,6 +67,13 @@ export async function spawnANT({ signer, module = AOS_MODULE_ID, luaCodeTxId = A
61
67
  signer,
62
68
  });
63
69
  }
70
+ await registryClient.send({
71
+ tags: [
72
+ { name: 'Action', value: 'Register' },
73
+ { name: 'Process-Id', value: processId },
74
+ ],
75
+ signer,
76
+ });
64
77
  return processId;
65
78
  }
66
79
  export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, ao = connect(), }) {
@@ -84,7 +97,35 @@ export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, a
84
97
  });
85
98
  return id;
86
99
  }
100
+ export function isAoSigner(value) {
101
+ const TagSchema = z.object({
102
+ name: z.string(),
103
+ value: z.union([z.string(), z.number()]),
104
+ });
105
+ const AoSignerSchema = z
106
+ .function()
107
+ .args(z.object({
108
+ data: z.union([z.string(), z.instanceof(Buffer)]),
109
+ tags: z.array(TagSchema).optional(),
110
+ target: z.string().optional(),
111
+ anchor: z.string().optional(),
112
+ }))
113
+ .returns(z.promise(z.object({
114
+ id: z.string(),
115
+ raw: z.instanceof(ArrayBuffer),
116
+ })));
117
+ try {
118
+ AoSignerSchema.parse(value);
119
+ return true;
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ }
87
125
  export function createAoSigner(signer) {
126
+ if (isAoSigner(signer)) {
127
+ return signer;
128
+ }
88
129
  if (!('publicKey' in signer)) {
89
130
  return createDataItemSigner(signer);
90
131
  }
@@ -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.10';
18
+ export const version = '2.1.0-alpha.12';
@@ -17,13 +17,14 @@
17
17
  */
18
18
  import { dryrun, message, monitor, result, results, spawn, unmonitor } from '@permaweb/aoconnect';
19
19
  import { Signer } from 'arbundles';
20
+ import { AoSigner } from './token.js';
20
21
  export type BlockHeight = number;
21
22
  export type SortKey = string;
22
23
  export type Timestamp = number;
23
24
  export type WalletAddress = string;
24
25
  export type TransactionId = string;
25
26
  export type ProcessId = string;
26
- export type ContractSigner = Signer | Window['arweaveWallet'];
27
+ export type ContractSigner = Signer | Window['arweaveWallet'] | AoSigner;
27
28
  export type WithSigner<T = NonNullable<unknown>> = {
28
29
  signer: ContractSigner;
29
30
  } & T;
@@ -22,4 +22,5 @@ export declare function evolveANT({ signer, processId, luaCodeTxId, ao, }: {
22
22
  luaCodeTxId?: string;
23
23
  ao?: AoClient;
24
24
  }): Promise<string>;
25
+ export declare function isAoSigner(value: unknown): value is AoSigner;
25
26
  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.9";
17
+ export declare const version = "2.1.0-alpha.11";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "2.1.0-alpha.10",
3
+ "version": "2.1.0-alpha.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -123,17 +123,18 @@
123
123
  "@permaweb/aoconnect": "^0.0.57",
124
124
  "arbundles": "0.11.0",
125
125
  "arweave": "1.14.4",
126
- "axios": "1.7.2",
126
+ "axios": "1.7.3",
127
127
  "axios-retry": "^4.3.0",
128
128
  "eventemitter3": "^5.0.1",
129
129
  "plimit-lit": "^3.0.1",
130
- "winston": "^3.13.0"
130
+ "winston": "^3.13.0",
131
+ "zod": "^3.23.8"
131
132
  },
132
133
  "lint-staged": {
133
134
  "**/*.{ts,js,mjs,cjs,md,json}": [
134
135
  "prettier --write ."
135
136
  ],
136
- "**/*.md": [
137
+ "**/README.md": [
137
138
  "markdown-toc-gen insert"
138
139
  ]
139
140
  }