@ar.io/sdk 3.10.0 → 3.11.0-alpha.2
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/README.md +66 -125
- package/bundles/web.bundle.min.js +130 -125
- package/lib/cjs/cli/options.js +12 -0
- package/lib/cjs/cli/utils.js +32 -10
- package/lib/cjs/cli/wayfinder.js +34 -0
- package/lib/cjs/common/ant-versions.js +5 -5
- package/lib/cjs/common/index.js +2 -0
- package/lib/cjs/common/io.js +64 -1
- package/lib/cjs/common/turbo.js +208 -0
- package/lib/cjs/common/wayfinder/gateways.js +75 -0
- package/lib/cjs/common/wayfinder/index.js +38 -0
- package/lib/cjs/common/wayfinder/routers/fixed.js +14 -0
- package/lib/cjs/common/wayfinder/routers/fixed.test.js +14 -0
- package/lib/cjs/common/wayfinder/routers/priority.js +38 -0
- package/lib/cjs/common/wayfinder/routers/priority.test.js +155 -0
- package/lib/cjs/common/wayfinder/routers/random.js +23 -0
- package/lib/cjs/common/wayfinder/routers/random.test.js +104 -0
- package/lib/cjs/common/wayfinder/routers/simple-cache.js +25 -0
- package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +41 -0
- package/lib/cjs/common/wayfinder/wayfinder.js +174 -0
- package/lib/cjs/common/wayfinder/wayfinder.test.js +253 -0
- package/lib/cjs/types/ant.js +12 -1
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/io.js +1 -1
- package/lib/cjs/types/wayfinder.js +2 -0
- package/lib/cjs/utils/ao.js +5 -0
- package/lib/cjs/utils/random.js +30 -0
- package/lib/cjs/utils/url.js +28 -0
- package/lib/cjs/utils/url.test.js +24 -0
- package/lib/cjs/utils/utils.test.js +8 -8
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/web/index.js +3 -1
- package/lib/esm/cli/options.js +12 -0
- package/lib/esm/cli/utils.js +31 -10
- package/lib/esm/cli/wayfinder.js +32 -0
- package/lib/esm/common/ant-versions.js +5 -5
- package/lib/esm/common/index.js +2 -0
- package/lib/esm/common/io.js +64 -1
- package/lib/esm/common/turbo.js +200 -0
- package/lib/esm/common/wayfinder/gateways.js +69 -0
- package/lib/esm/common/wayfinder/index.js +22 -0
- package/lib/esm/common/wayfinder/routers/fixed.js +10 -0
- package/lib/esm/common/wayfinder/routers/fixed.test.js +12 -0
- package/lib/esm/common/wayfinder/routers/priority.js +34 -0
- package/lib/esm/common/wayfinder/routers/priority.test.js +153 -0
- package/lib/esm/common/wayfinder/routers/random.js +19 -0
- package/lib/esm/common/wayfinder/routers/random.test.js +102 -0
- package/lib/esm/common/wayfinder/routers/simple-cache.js +21 -0
- package/lib/esm/common/wayfinder/routers/simple-cache.test.js +39 -0
- package/lib/esm/common/wayfinder/wayfinder.js +168 -0
- package/lib/esm/common/wayfinder/wayfinder.test.js +248 -0
- package/lib/esm/types/ant.js +11 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/io.js +1 -1
- package/lib/esm/types/wayfinder.js +1 -0
- package/lib/esm/utils/ao.js +5 -0
- package/lib/esm/utils/random.js +26 -0
- package/lib/esm/utils/url.js +24 -0
- package/lib/esm/utils/url.test.js +19 -0
- package/lib/esm/utils/utils.test.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/web/index.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +3 -3
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +1 -1
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +9 -9
- package/lib/types/cli/commands/readCommands.d.ts +1 -0
- package/lib/types/cli/commands/transfer.d.ts +3 -3
- package/lib/types/cli/options.d.ts +9 -0
- package/lib/types/cli/types.d.ts +3 -0
- package/lib/types/cli/utils.d.ts +4 -0
- package/lib/types/cli/wayfinder.d.ts +1 -0
- package/lib/types/common/ant-versions.d.ts +3 -6
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/io.d.ts +9 -7
- package/lib/types/common/turbo.d.ts +62 -0
- package/lib/types/common/wayfinder/gateways.d.ts +44 -0
- package/lib/types/common/wayfinder/index.d.ts +20 -0
- package/lib/types/common/wayfinder/routers/fixed.d.ts +24 -0
- package/lib/types/common/wayfinder/routers/fixed.test.d.ts +1 -0
- package/lib/types/common/wayfinder/routers/priority.d.ts +33 -0
- package/lib/types/common/wayfinder/routers/priority.test.d.ts +1 -0
- package/lib/types/common/wayfinder/routers/random.d.ts +27 -0
- package/lib/types/common/wayfinder/routers/random.test.d.ts +1 -0
- package/lib/types/common/wayfinder/routers/simple-cache.d.ts +28 -0
- package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +1 -0
- package/lib/types/common/wayfinder/wayfinder.d.ts +120 -0
- package/lib/types/common/wayfinder/wayfinder.test.d.ts +1 -0
- package/lib/types/types/ant.d.ts +53 -1
- package/lib/types/types/common.d.ts +7 -2
- package/lib/types/types/index.d.ts +1 -0
- package/lib/types/types/io.d.ts +7 -5
- package/lib/types/types/wayfinder.d.ts +19 -0
- package/lib/types/utils/ao.d.ts +1 -12
- package/lib/types/utils/random.d.ts +7 -0
- package/lib/types/utils/url.d.ts +19 -0
- package/lib/types/utils/url.test.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/lib/types/web/index.d.ts +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const got_1 = __importDefault(require("got"));
|
|
8
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
|
+
const consumers_1 = require("node:stream/consumers");
|
|
10
|
+
const node_test_1 = require("node:test");
|
|
11
|
+
const random_js_1 = require("./routers/random.js");
|
|
12
|
+
const wayfinder_js_1 = require("./wayfinder.js");
|
|
13
|
+
const stubbedGateway = {
|
|
14
|
+
status: 'joined',
|
|
15
|
+
gatewayAddress: 'arweave',
|
|
16
|
+
operatorStake: 1000,
|
|
17
|
+
totalDelegatedStake: 1000,
|
|
18
|
+
startTimestamp: 1000,
|
|
19
|
+
settings: {
|
|
20
|
+
protocol: 'https',
|
|
21
|
+
fqdn: 'arweave.net',
|
|
22
|
+
port: 443,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const stubbedGatewaysProvider = {
|
|
26
|
+
getGateways: async () => [stubbedGateway],
|
|
27
|
+
};
|
|
28
|
+
(0, node_test_1.describe)('Wayfinder', () => {
|
|
29
|
+
(0, node_test_1.describe)('http wrapper', () => {
|
|
30
|
+
(0, node_test_1.describe)('fetch', () => {
|
|
31
|
+
let wayfinder;
|
|
32
|
+
(0, node_test_1.before)(() => {
|
|
33
|
+
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
34
|
+
httpClient: fetch,
|
|
35
|
+
router: new random_js_1.RandomGatewayRouter({
|
|
36
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
(0, node_test_1.it)('should fetch the data using the selected gateway', async () => {
|
|
41
|
+
const nativeFetch = await fetch('https://ao.arweave.net');
|
|
42
|
+
const response = await wayfinder.request('ar://ao');
|
|
43
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
44
|
+
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
45
|
+
// assert the arns headers are the same
|
|
46
|
+
const arnsHeaders = Array.from(response.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
|
|
47
|
+
const nativeFetchHeaders = Array.from(nativeFetch.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
|
|
48
|
+
node_assert_1.default.deepStrictEqual(arnsHeaders, nativeFetchHeaders);
|
|
49
|
+
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
50
|
+
});
|
|
51
|
+
(0, node_test_1.it)('should route a non-ar:// url as a normal fetch', async () => {
|
|
52
|
+
const [nativeFetch, response] = await Promise.all([
|
|
53
|
+
fetch('https://arweave.net/', {
|
|
54
|
+
method: 'HEAD',
|
|
55
|
+
}),
|
|
56
|
+
wayfinder.request('https://arweave.net/', {
|
|
57
|
+
method: 'HEAD',
|
|
58
|
+
}),
|
|
59
|
+
]);
|
|
60
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
61
|
+
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
62
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
63
|
+
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
64
|
+
});
|
|
65
|
+
for (const api of ['/info', '/metrics', '/block/current']) {
|
|
66
|
+
(0, node_test_1.it)(`supports native arweave node apis ${api}`, async () => {
|
|
67
|
+
const [nativeFetch, response] = await Promise.all([
|
|
68
|
+
fetch(`https://arweave.net${api}`),
|
|
69
|
+
wayfinder.request(`ar:///${api}`),
|
|
70
|
+
]);
|
|
71
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
72
|
+
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
73
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
74
|
+
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
|
|
78
|
+
(0, node_test_1.it)(`supports native ario node gateway apis ${api}`, async () => {
|
|
79
|
+
const [nativeFetch, response] = await Promise.all([
|
|
80
|
+
fetch(`https://arweave.net${api}`),
|
|
81
|
+
wayfinder.request(`ar:///${api}`),
|
|
82
|
+
]);
|
|
83
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
84
|
+
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
85
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
86
|
+
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
(0, node_test_1.it)('supports a post request to graphql', async () => {
|
|
90
|
+
const response = await wayfinder.request('ar:///graphql', {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: {
|
|
93
|
+
'Content-Type': 'application/json',
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify({
|
|
96
|
+
query: `
|
|
97
|
+
query {
|
|
98
|
+
transactions(
|
|
99
|
+
ids: ["xf958qhCNGfDme1FtoiD6DtMfDENDbtxZpjOM_1tsMM"]
|
|
100
|
+
) {
|
|
101
|
+
edges {
|
|
102
|
+
cursor
|
|
103
|
+
node {
|
|
104
|
+
id
|
|
105
|
+
tags {
|
|
106
|
+
name
|
|
107
|
+
value
|
|
108
|
+
}
|
|
109
|
+
block {
|
|
110
|
+
height
|
|
111
|
+
timestamp
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
pageInfo {
|
|
116
|
+
hasNextPage
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
`,
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
124
|
+
});
|
|
125
|
+
(0, node_test_1.it)('returns the error from the target gateway if the route is not found', async () => {
|
|
126
|
+
const [nativeFetch, response] = await Promise.all([
|
|
127
|
+
fetch('https://arweave.net/not-found'),
|
|
128
|
+
wayfinder.request('https://arweave.net/not-found'),
|
|
129
|
+
]);
|
|
130
|
+
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
131
|
+
node_assert_1.default.strictEqual(response.statusText, nativeFetch.statusText);
|
|
132
|
+
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
(0, node_test_1.describe)('axios', () => {
|
|
136
|
+
let wayfinder;
|
|
137
|
+
(0, node_test_1.before)(() => {
|
|
138
|
+
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
139
|
+
httpClient: axios_1.default,
|
|
140
|
+
router: new random_js_1.RandomGatewayRouter({
|
|
141
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
(0, node_test_1.it)('should fetch the data using axios default function against the target gateway', async () => {
|
|
146
|
+
const [nativeAxios, response] = await Promise.all([
|
|
147
|
+
(0, axios_1.default)('https://ao.arweave.net'),
|
|
148
|
+
wayfinder.request('ar://ao'),
|
|
149
|
+
]);
|
|
150
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
151
|
+
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
152
|
+
// assert the arns headers are the same
|
|
153
|
+
const arnsHeaders = Object.entries(response.headers)
|
|
154
|
+
.sort()
|
|
155
|
+
.filter(([key]) => key.startsWith('x-arns-'));
|
|
156
|
+
const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
|
|
157
|
+
node_assert_1.default.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
|
|
158
|
+
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
159
|
+
});
|
|
160
|
+
(0, node_test_1.it)('should fetch the data using the axios.get method against the target gateway', async () => {
|
|
161
|
+
const [nativeAxios, response] = await Promise.all([
|
|
162
|
+
axios_1.default.get('https://ao.arweave.net'),
|
|
163
|
+
wayfinder.request.get('ar://ao'),
|
|
164
|
+
]);
|
|
165
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
166
|
+
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
167
|
+
// assert the arns headers are the same
|
|
168
|
+
const arnsHeaders = Object.entries(response.headers)
|
|
169
|
+
.sort()
|
|
170
|
+
.filter(([key]) => key.startsWith('x-arns-'));
|
|
171
|
+
const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
|
|
172
|
+
node_assert_1.default.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
|
|
173
|
+
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
174
|
+
});
|
|
175
|
+
(0, node_test_1.it)('should route a non-ar:// url as a normal axios request', async () => {
|
|
176
|
+
const [nativeAxios, response] = await Promise.all([
|
|
177
|
+
(0, axios_1.default)('https://arweave.net/'),
|
|
178
|
+
wayfinder.request('https://arweave.net/'),
|
|
179
|
+
]);
|
|
180
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
181
|
+
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
182
|
+
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
183
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
184
|
+
});
|
|
185
|
+
for (const api of ['/info', '/metrics', '/block/current']) {
|
|
186
|
+
(0, node_test_1.it)(`supports native arweave node apis ${api}`, async () => {
|
|
187
|
+
const [nativeAxios, response] = await Promise.all([
|
|
188
|
+
(0, axios_1.default)(`https://arweave.net${api}`),
|
|
189
|
+
wayfinder.request(`ar:///${api}`),
|
|
190
|
+
]);
|
|
191
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
192
|
+
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
193
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
194
|
+
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
|
|
198
|
+
(0, node_test_1.it)(`supports native ario node gateway apis ${api}`, async () => {
|
|
199
|
+
const [nativeAxios, response] = await Promise.all([
|
|
200
|
+
(0, axios_1.default)(`https://arweave.net${api}`),
|
|
201
|
+
wayfinder.request(`ar:///${api}`),
|
|
202
|
+
]);
|
|
203
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
204
|
+
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
205
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
206
|
+
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
(0, node_test_1.it)('should return the error from the target gateway if the route is not found', async () => {
|
|
210
|
+
const axiosInstance = axios_1.default.create({
|
|
211
|
+
validateStatus: () => true, // don't throw so we can compare axios result with wrapped axios result
|
|
212
|
+
});
|
|
213
|
+
const wayfinder = new wayfinder_js_1.Wayfinder({
|
|
214
|
+
httpClient: axiosInstance,
|
|
215
|
+
router: new random_js_1.RandomGatewayRouter({
|
|
216
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
217
|
+
}),
|
|
218
|
+
});
|
|
219
|
+
const [nativeAxios, response] = await Promise.all([
|
|
220
|
+
axiosInstance('https://arweave.net/not-found'),
|
|
221
|
+
wayfinder.request('https://arweave.net/not-found'),
|
|
222
|
+
]);
|
|
223
|
+
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
224
|
+
node_assert_1.default.strictEqual(response.data, nativeAxios.data);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
(0, node_test_1.describe)('got', () => {
|
|
228
|
+
let wayfinder;
|
|
229
|
+
(0, node_test_1.before)(() => {
|
|
230
|
+
wayfinder = new wayfinder_js_1.Wayfinder({
|
|
231
|
+
httpClient: got_1.default,
|
|
232
|
+
router: new random_js_1.RandomGatewayRouter({
|
|
233
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
(0, node_test_1.it)('should fetch the data using the got default function against the target gateway', async () => {
|
|
238
|
+
const [nativeGot, response] = await Promise.all([
|
|
239
|
+
(0, got_1.default)('https://ao.arweave.net'),
|
|
240
|
+
wayfinder.request('ar://ao'),
|
|
241
|
+
]);
|
|
242
|
+
node_assert_1.default.strictEqual(response.statusCode, 200);
|
|
243
|
+
node_assert_1.default.strictEqual(response.statusCode, nativeGot.statusCode);
|
|
244
|
+
node_assert_1.default.deepStrictEqual(response.body, nativeGot.body);
|
|
245
|
+
});
|
|
246
|
+
(0, node_test_1.it)('should stream the data using got.stream against the selected target gateway', async () => {
|
|
247
|
+
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream('https://ao.arweave.net', { decompress: false }));
|
|
248
|
+
const wayfinderBuffer = await (0, consumers_1.buffer)(await wayfinder.request.stream('ar://ao', { decompress: false }));
|
|
249
|
+
node_assert_1.default.deepStrictEqual(wayfinderBuffer, nativeBuffer);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
package/lib/cjs/types/ant.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AntInfoSchema = exports.AntHandlersSchema = exports.AntHandlerNames = exports.AntWriteHandlers = exports.AntReadHandlers = exports.AntStateSchema = exports.AntBalancesSchema = exports.AntControllersSchema = exports.AntRecordsSchema = exports.AntRecordSchema = exports.AntKeywordsSchema = exports.AntDescriptionSchema = exports.IntegerStringSchema = exports.AOAddressSchema = exports.ArweaveTxIdSchema = void 0;
|
|
3
|
+
exports.AntInfoSchema = exports.AntHandlersSchema = exports.AntHandlerNames = exports.AntWriteHandlers = exports.AntReadHandlers = exports.SpawnANTStateSchema = exports.AntStateSchema = exports.AntBalancesSchema = exports.AntControllersSchema = exports.AntRecordsSchema = exports.AntRecordSchema = exports.AntKeywordsSchema = exports.AntDescriptionSchema = exports.IntegerStringSchema = exports.AOAddressSchema = exports.ArweaveTxIdSchema = void 0;
|
|
4
4
|
exports.isAoANTState = isAoANTState;
|
|
5
5
|
/**
|
|
6
6
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
@@ -81,6 +81,17 @@ exports.AntStateSchema = zod_1.z.object({
|
|
|
81
81
|
.boolean()
|
|
82
82
|
.describe('Flag indicating whether the ANT has been initialized.'),
|
|
83
83
|
});
|
|
84
|
+
exports.SpawnANTStateSchema = zod_1.z.object({
|
|
85
|
+
name: zod_1.z.string().describe('The name of the ANT.'),
|
|
86
|
+
ticker: zod_1.z.string().describe('The ticker symbol for the ANT.'),
|
|
87
|
+
description: zod_1.z.string().describe('The description for the ANT.'),
|
|
88
|
+
keywords: exports.AntKeywordsSchema.describe('The keywords for the ANT.'),
|
|
89
|
+
owner: exports.AOAddressSchema.describe('The Owners address.'),
|
|
90
|
+
controllers: exports.AntControllersSchema.describe('Controllers of the ANT who have administrative privileges.'),
|
|
91
|
+
records: exports.AntRecordsSchema.describe('Records associated with the ANT.'),
|
|
92
|
+
balances: exports.AntBalancesSchema.describe('Balance details for each address holding the ANT.'),
|
|
93
|
+
logo: exports.ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'),
|
|
94
|
+
});
|
|
84
95
|
exports.AntReadHandlers = [
|
|
85
96
|
'balance',
|
|
86
97
|
'balances',
|
package/lib/cjs/types/index.js
CHANGED
package/lib/cjs/types/io.js
CHANGED
|
@@ -31,7 +31,7 @@ const isValidIntent = (intent) => {
|
|
|
31
31
|
return exports.validIntents.indexOf(intent) !== -1;
|
|
32
32
|
};
|
|
33
33
|
exports.isValidIntent = isValidIntent;
|
|
34
|
-
exports.fundFromOptions = ['balance', 'stakes', 'any'];
|
|
34
|
+
exports.fundFromOptions = ['balance', 'stakes', 'any', 'turbo'];
|
|
35
35
|
const isValidFundFrom = (fundFrom) => {
|
|
36
36
|
return exports.fundFromOptions.indexOf(fundFrom) !== -1;
|
|
37
37
|
};
|
package/lib/cjs/utils/ao.js
CHANGED
|
@@ -30,8 +30,13 @@ const zod_1 = require("zod");
|
|
|
30
30
|
const arweave_js_1 = require("../common/arweave.js");
|
|
31
31
|
const index_js_1 = require("../common/index.js");
|
|
32
32
|
const constants_js_1 = require("../constants.js");
|
|
33
|
+
const ant_js_1 = require("../types/ant.js");
|
|
34
|
+
const schema_js_1 = require("./schema.js");
|
|
33
35
|
async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, ao = (0, aoconnect_1.connect)(), scheduler = constants_js_1.DEFAULT_SCHEDULER_ID, state, antRegistryId = constants_js_1.ANT_REGISTRY_ID, logger = index_js_1.Logger.default, authority = constants_js_1.AO_AUTHORITY, }) {
|
|
34
36
|
// TODO: use On-Boot data handler for bootstrapping state instead of initialize-state
|
|
37
|
+
if (state) {
|
|
38
|
+
(0, schema_js_1.parseSchemaResult)(ant_js_1.SpawnANTStateSchema, state);
|
|
39
|
+
}
|
|
35
40
|
const processId = await ao.spawn({
|
|
36
41
|
module,
|
|
37
42
|
scheduler,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomInt = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const crypto_1 = require("crypto");
|
|
20
|
+
/**
|
|
21
|
+
* Cryptographically secure helper for randomness, does not support seeding
|
|
22
|
+
* @param min - the minimum value
|
|
23
|
+
* @param max - the maximum value
|
|
24
|
+
* @returns a random integer between min and max
|
|
25
|
+
*/
|
|
26
|
+
const randomInt = (min, max) => {
|
|
27
|
+
const [rand] = crypto_1.webcrypto.getRandomValues(new Uint32Array(1));
|
|
28
|
+
return min + (rand % (max - min));
|
|
29
|
+
};
|
|
30
|
+
exports.randomInt = randomInt;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.urlWithSearchParams = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const urlWithSearchParams = ({ baseUrl, params, }) => {
|
|
20
|
+
const urlObj = new URL(baseUrl);
|
|
21
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
22
|
+
if (value === undefined || value === null)
|
|
23
|
+
return;
|
|
24
|
+
urlObj.searchParams.set(key, value.toString());
|
|
25
|
+
});
|
|
26
|
+
return urlObj.toString();
|
|
27
|
+
};
|
|
28
|
+
exports.urlWithSearchParams = urlWithSearchParams;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const url_js_1 = require("./url.js");
|
|
9
|
+
(0, node_test_1.test)('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
|
|
10
|
+
const result = (0, url_js_1.urlWithSearchParams)({
|
|
11
|
+
baseUrl: 'https://example.com',
|
|
12
|
+
params: {
|
|
13
|
+
number: 1,
|
|
14
|
+
string: 'string',
|
|
15
|
+
boolean: true,
|
|
16
|
+
empty: '',
|
|
17
|
+
zero: 0,
|
|
18
|
+
false: false,
|
|
19
|
+
null: null,
|
|
20
|
+
undef: undefined,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
node_assert_1.default.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
|
|
24
|
+
});
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_assert_1 = require("node:assert");
|
|
4
4
|
const node_test_1 = require("node:test");
|
|
5
|
+
const ao_js_1 = require("./ao.js");
|
|
5
6
|
const arweave_js_1 = require("./arweave.js");
|
|
6
|
-
const index_js_1 = require("./index.js");
|
|
7
7
|
(0, node_test_1.describe)('pruneTags', () => {
|
|
8
8
|
(0, node_test_1.it)('should remove tags with undefined values', () => {
|
|
9
9
|
const tags = [
|
|
@@ -45,7 +45,7 @@ const index_js_1 = require("./index.js");
|
|
|
45
45
|
const output = {
|
|
46
46
|
Error: 'Error message',
|
|
47
47
|
};
|
|
48
|
-
const errorMessage = (0,
|
|
48
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
49
49
|
node_assert_1.strict.equal(errorMessage, 'Error message');
|
|
50
50
|
});
|
|
51
51
|
(0, node_test_1.it)('should return error message from Error tag', () => {
|
|
@@ -56,7 +56,7 @@ const index_js_1 = require("./index.js");
|
|
|
56
56
|
},
|
|
57
57
|
],
|
|
58
58
|
};
|
|
59
|
-
const errorMessage = (0,
|
|
59
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
60
60
|
node_assert_1.strict.equal(errorMessage, 'Error message');
|
|
61
61
|
});
|
|
62
62
|
(0, node_test_1.it)('should return error message from Error tag if Error field is undefined', () => {
|
|
@@ -67,7 +67,7 @@ const index_js_1 = require("./index.js");
|
|
|
67
67
|
},
|
|
68
68
|
],
|
|
69
69
|
};
|
|
70
|
-
const errorMessage = (0,
|
|
70
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
71
71
|
node_assert_1.strict.equal(errorMessage, 'Error message');
|
|
72
72
|
});
|
|
73
73
|
(0, node_test_1.it)('should return undefined if no error message is present', () => {
|
|
@@ -78,21 +78,21 @@ const index_js_1 = require("./index.js");
|
|
|
78
78
|
},
|
|
79
79
|
],
|
|
80
80
|
};
|
|
81
|
-
const errorMessage = (0,
|
|
81
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
82
82
|
node_assert_1.strict.equal(errorMessage, undefined);
|
|
83
83
|
});
|
|
84
84
|
(0, node_test_1.it)('should return error message with line number', () => {
|
|
85
85
|
const output = {
|
|
86
86
|
Error: '[string "aos"]:123: Error message',
|
|
87
87
|
};
|
|
88
|
-
const errorMessage = (0,
|
|
88
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
89
89
|
node_assert_1.strict.equal(errorMessage, 'Error message (line 123)');
|
|
90
90
|
});
|
|
91
91
|
(0, node_test_1.it)('should return error message with line number and remove unicode', () => {
|
|
92
92
|
const output = {
|
|
93
93
|
Error: '[string "aos"]:123: Error message\u001b[0m',
|
|
94
94
|
};
|
|
95
|
-
const errorMessage = (0,
|
|
95
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
96
96
|
node_assert_1.strict.equal(errorMessage, 'Error message (line 123)');
|
|
97
97
|
});
|
|
98
98
|
const knownErrorMessages = '\u001b[31mError\u001b[90m handling message with Action = Register\u001b[0m\n\u001b[32m[string ".handlers"]:723: [string "aos"]:128: Already registered\u001b[0m\n\n\u001b[90mstack traceback:\n\t[string ".process"]:871: in function \'.process.handle\'\u001b[0m\n\n\u001b[31merror:\n\u001b[0m[string ".handlers"]:723: [string "aos"]:128: Already registered';
|
|
@@ -100,7 +100,7 @@ const index_js_1 = require("./index.js");
|
|
|
100
100
|
const output = {
|
|
101
101
|
Error: knownErrorMessages,
|
|
102
102
|
};
|
|
103
|
-
const errorMessage = (0,
|
|
103
|
+
const errorMessage = (0, ao_js_1.errorMessageFromOutput)(output);
|
|
104
104
|
node_assert_1.strict.equal(errorMessage, 'Already registered (line 128)');
|
|
105
105
|
});
|
|
106
106
|
});
|
package/lib/cjs/version.js
CHANGED
package/lib/cjs/web/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ArconnectSigner = exports.ArweaveSigner = void 0;
|
|
17
|
+
exports.EthereumSigner = exports.InjectedEthereumSigner = exports.ArconnectSigner = exports.ArweaveSigner = void 0;
|
|
18
18
|
/**
|
|
19
19
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
20
20
|
*
|
|
@@ -33,6 +33,8 @@ exports.ArconnectSigner = exports.ArweaveSigner = void 0;
|
|
|
33
33
|
var arbundles_1 = require("@dha-team/arbundles");
|
|
34
34
|
Object.defineProperty(exports, "ArweaveSigner", { enumerable: true, get: function () { return arbundles_1.ArweaveSigner; } });
|
|
35
35
|
Object.defineProperty(exports, "ArconnectSigner", { enumerable: true, get: function () { return arbundles_1.ArconnectSigner; } });
|
|
36
|
+
Object.defineProperty(exports, "InjectedEthereumSigner", { enumerable: true, get: function () { return arbundles_1.InjectedEthereumSigner; } });
|
|
37
|
+
Object.defineProperty(exports, "EthereumSigner", { enumerable: true, get: function () { return arbundles_1.EthereumSigner; } });
|
|
36
38
|
__exportStar(require("../types/index.js"), exports);
|
|
37
39
|
__exportStar(require("../common/index.js"), exports);
|
|
38
40
|
__exportStar(require("../constants.js"), exports);
|
package/lib/esm/cli/options.js
CHANGED
|
@@ -49,6 +49,10 @@ export const optionMap = {
|
|
|
49
49
|
alias: '--cu-url <cuUrl>',
|
|
50
50
|
description: 'The URL for a custom compute unit',
|
|
51
51
|
},
|
|
52
|
+
paymentUrl: {
|
|
53
|
+
alias: '--payment-url <paymentUrl>',
|
|
54
|
+
description: 'The URL for a custom turbo payment service',
|
|
55
|
+
},
|
|
52
56
|
processId: {
|
|
53
57
|
alias: '--process-id <processId>',
|
|
54
58
|
description: 'The process ID to interact with',
|
|
@@ -269,9 +273,15 @@ export const optionMap = {
|
|
|
269
273
|
alias: '--logo <logo>',
|
|
270
274
|
description: 'The ANT logo',
|
|
271
275
|
},
|
|
276
|
+
token: {
|
|
277
|
+
alias: '-t, --token <type>',
|
|
278
|
+
description: 'Crypto token type for wallet or action',
|
|
279
|
+
default: 'arweave',
|
|
280
|
+
},
|
|
272
281
|
};
|
|
273
282
|
export const walletOptions = [
|
|
274
283
|
optionMap.walletFile,
|
|
284
|
+
optionMap.token,
|
|
275
285
|
// optionMap.mnemonic,
|
|
276
286
|
optionMap.privateKey,
|
|
277
287
|
];
|
|
@@ -289,6 +299,7 @@ export const arnsPurchaseOptions = [
|
|
|
289
299
|
...writeActionOptions,
|
|
290
300
|
optionMap.name,
|
|
291
301
|
optionMap.fundFrom,
|
|
302
|
+
optionMap.paymentUrl,
|
|
292
303
|
];
|
|
293
304
|
export const epochOptions = [optionMap.epochIndex, optionMap.timestamp];
|
|
294
305
|
export const addressAndVaultIdOptions = [optionMap.address, optionMap.vaultId];
|
|
@@ -312,6 +323,7 @@ export const tokenCostOptions = [
|
|
|
312
323
|
optionMap.quantity,
|
|
313
324
|
optionMap.address,
|
|
314
325
|
optionMap.fundFrom,
|
|
326
|
+
optionMap.paymentUrl,
|
|
315
327
|
];
|
|
316
328
|
export const transferOptions = [
|
|
317
329
|
...writeActionOptions,
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { EthereumSigner } from '@dha-team/arbundles';
|
|
16
17
|
import { connect } from '@permaweb/aoconnect';
|
|
17
18
|
import { program } from 'commander';
|
|
18
19
|
import { readFileSync } from 'fs';
|
|
@@ -77,7 +78,7 @@ export function arioProcessIdFromOptions({ arioProcessId, devnet, testnet, }) {
|
|
|
77
78
|
}
|
|
78
79
|
return ARIO_MAINNET_PROCESS_ID;
|
|
79
80
|
}
|
|
80
|
-
function
|
|
81
|
+
function walletFromOptions({ privateKey, walletFile, }) {
|
|
81
82
|
if (privateKey !== undefined) {
|
|
82
83
|
return JSON.parse(privateKey);
|
|
83
84
|
}
|
|
@@ -87,7 +88,7 @@ function jwkFromOptions({ privateKey, walletFile, }) {
|
|
|
87
88
|
return undefined;
|
|
88
89
|
}
|
|
89
90
|
export function requiredJwkFromOptions(options) {
|
|
90
|
-
const jwk =
|
|
91
|
+
const jwk = walletFromOptions(options);
|
|
91
92
|
if (jwk === undefined) {
|
|
92
93
|
throw new Error('No JWK provided for signing!\nPlease provide a stringified JWK with `--private-key` or the file path of a jwk.json file with `--wallet-file`');
|
|
93
94
|
}
|
|
@@ -117,13 +118,30 @@ export function readARIOFromOptions(options) {
|
|
|
117
118
|
setLoggerIfDebug(options);
|
|
118
119
|
return ARIO.init({
|
|
119
120
|
process: aoProcessFromOptions(options),
|
|
121
|
+
paymentUrl: options.paymentUrl,
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
|
-
export function
|
|
124
|
+
export function contractSignerFromOptions(options) {
|
|
125
|
+
const wallet = walletFromOptions(options);
|
|
126
|
+
if (wallet === undefined) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
const token = options.token ?? 'arweave';
|
|
130
|
+
if (token === 'ethereum') {
|
|
131
|
+
const signer = new EthereumSigner(wallet);
|
|
132
|
+
// For EthereumSigner, we need to convert the JWK to a string
|
|
133
|
+
return { signer, signerAddress: signer.publicKey.toString('hex') };
|
|
134
|
+
}
|
|
123
135
|
// TODO: Support other wallet types
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
const signer = new ArweaveSigner(wallet);
|
|
137
|
+
return { signer, signerAddress: jwkToAddress(wallet) };
|
|
138
|
+
}
|
|
139
|
+
export function requiredContractSignerFromOptions(options) {
|
|
140
|
+
const contractSigner = contractSignerFromOptions(options);
|
|
141
|
+
if (contractSigner === undefined) {
|
|
142
|
+
throw new Error('No signer provided for signing!\nPlease provide a stringified JWK or Ethereum private key with `--private-key` or the file path of an arweave.jwk.json or eth.private.key.txt file with `--wallet-file`');
|
|
143
|
+
}
|
|
144
|
+
return contractSigner;
|
|
127
145
|
}
|
|
128
146
|
export function requiredAoSignerFromOptions(options) {
|
|
129
147
|
return createAoSigner(requiredContractSignerFromOptions(options).signer);
|
|
@@ -135,6 +153,7 @@ export function writeARIOFromOptions(options) {
|
|
|
135
153
|
ario: ARIO.init({
|
|
136
154
|
process: aoProcessFromOptions(options),
|
|
137
155
|
signer,
|
|
156
|
+
paymentUrl: options.paymentUrl,
|
|
138
157
|
}),
|
|
139
158
|
signerAddress,
|
|
140
159
|
};
|
|
@@ -155,10 +174,9 @@ export function addressFromOptions(options) {
|
|
|
155
174
|
if (options.address !== undefined) {
|
|
156
175
|
return options.address;
|
|
157
176
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return jwkToAddress(jwk);
|
|
177
|
+
const signer = contractSignerFromOptions(options);
|
|
178
|
+
if (signer !== undefined) {
|
|
179
|
+
return signer.signerAddress;
|
|
162
180
|
}
|
|
163
181
|
return undefined;
|
|
164
182
|
}
|
|
@@ -281,6 +299,9 @@ export function requiredMARIOFromOptions(options, key) {
|
|
|
281
299
|
return new ARIOToken(+options[key]).toMARIO();
|
|
282
300
|
}
|
|
283
301
|
export async function assertEnoughBalanceForArNSPurchase({ ario, address, costDetailsParams, }) {
|
|
302
|
+
if (costDetailsParams.fundFrom === 'turbo') {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
284
305
|
const costDetails = await ario.getCostDetails(costDetailsParams);
|
|
285
306
|
if (costDetails.fundingPlan) {
|
|
286
307
|
if (costDetails.fundingPlan.shortfall > 0) {
|