@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.
- package/bundles/web.bundle.min.js +54 -54
- package/lib/cjs/utils/ao.js +41 -12
- package/lib/cjs/version.js +1 -1
- package/lib/esm/utils/ao.js +40 -12
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant-registry.d.ts +1 -1
- package/lib/types/utils/ao.d.ts +58 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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.
|
|
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;
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/utils/ao.js
CHANGED
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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.
|
|
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
|
+
}
|
package/lib/esm/version.js
CHANGED
|
@@ -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>>):
|
|
8
|
+
static init({ signer, ...config }: WithSigner<Required<ProcessConfiguration>>): AoANTRegistryWrite;
|
|
9
9
|
}
|
|
10
10
|
export declare class AoANTRegistryReadable implements AoANTRegistryRead {
|
|
11
11
|
protected process: AOProcess;
|
package/lib/types/utils/ao.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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;
|
package/lib/types/version.d.ts
CHANGED