@ar.io/sdk 2.1.0-alpha.11 → 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.
- package/bundles/web.bundle.min.js +91 -91
- package/lib/cjs/utils/ao.js +31 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/utils/ao.js +29 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/common.d.ts +2 -1
- package/lib/types/utils/ao.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +3 -2
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.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,6 +19,7 @@ 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");
|
|
@@ -101,7 +102,36 @@ async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_L
|
|
|
101
102
|
return id;
|
|
102
103
|
}
|
|
103
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;
|
|
104
131
|
function createAoSigner(signer) {
|
|
132
|
+
if (isAoSigner(signer)) {
|
|
133
|
+
return signer;
|
|
134
|
+
}
|
|
105
135
|
if (!('publicKey' in signer)) {
|
|
106
136
|
return (0, aoconnect_1.createDataItemSigner)(signer);
|
|
107
137
|
}
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/utils/ao.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
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';
|
|
@@ -96,7 +97,35 @@ export async function evolveANT({ signer, processId, luaCodeTxId = ANT_LUA_ID, a
|
|
|
96
97
|
});
|
|
97
98
|
return id;
|
|
98
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
|
+
}
|
|
99
125
|
export function createAoSigner(signer) {
|
|
126
|
+
if (isAoSigner(signer)) {
|
|
127
|
+
return signer;
|
|
128
|
+
}
|
|
100
129
|
if (!('publicKey' in signer)) {
|
|
101
130
|
return createDataItemSigner(signer);
|
|
102
131
|
}
|
package/lib/esm/version.js
CHANGED
package/lib/types/common.d.ts
CHANGED
|
@@ -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;
|
package/lib/types/utils/ao.d.ts
CHANGED
|
@@ -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;
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/sdk",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
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"
|
|
@@ -127,7 +127,8 @@
|
|
|
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}": [
|