@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,248 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import got from 'got';
|
|
3
|
+
import assert from 'node:assert';
|
|
4
|
+
import { buffer } from 'node:stream/consumers';
|
|
5
|
+
import { before, describe, it } from 'node:test';
|
|
6
|
+
import { RandomGatewayRouter } from './routers/random.js';
|
|
7
|
+
import { Wayfinder } from './wayfinder.js';
|
|
8
|
+
const stubbedGateway = {
|
|
9
|
+
status: 'joined',
|
|
10
|
+
gatewayAddress: 'arweave',
|
|
11
|
+
operatorStake: 1000,
|
|
12
|
+
totalDelegatedStake: 1000,
|
|
13
|
+
startTimestamp: 1000,
|
|
14
|
+
settings: {
|
|
15
|
+
protocol: 'https',
|
|
16
|
+
fqdn: 'arweave.net',
|
|
17
|
+
port: 443,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const stubbedGatewaysProvider = {
|
|
21
|
+
getGateways: async () => [stubbedGateway],
|
|
22
|
+
};
|
|
23
|
+
describe('Wayfinder', () => {
|
|
24
|
+
describe('http wrapper', () => {
|
|
25
|
+
describe('fetch', () => {
|
|
26
|
+
let wayfinder;
|
|
27
|
+
before(() => {
|
|
28
|
+
wayfinder = new Wayfinder({
|
|
29
|
+
httpClient: fetch,
|
|
30
|
+
router: new RandomGatewayRouter({
|
|
31
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
it('should fetch the data using the selected gateway', async () => {
|
|
36
|
+
const nativeFetch = await fetch('https://ao.arweave.net');
|
|
37
|
+
const response = await wayfinder.request('ar://ao');
|
|
38
|
+
assert.strictEqual(response.status, 200);
|
|
39
|
+
assert.strictEqual(response.status, nativeFetch.status);
|
|
40
|
+
// assert the arns headers are the same
|
|
41
|
+
const arnsHeaders = Array.from(response.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
|
|
42
|
+
const nativeFetchHeaders = Array.from(nativeFetch.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
|
|
43
|
+
assert.deepStrictEqual(arnsHeaders, nativeFetchHeaders);
|
|
44
|
+
assert.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
45
|
+
});
|
|
46
|
+
it('should route a non-ar:// url as a normal fetch', async () => {
|
|
47
|
+
const [nativeFetch, response] = await Promise.all([
|
|
48
|
+
fetch('https://arweave.net/', {
|
|
49
|
+
method: 'HEAD',
|
|
50
|
+
}),
|
|
51
|
+
wayfinder.request('https://arweave.net/', {
|
|
52
|
+
method: 'HEAD',
|
|
53
|
+
}),
|
|
54
|
+
]);
|
|
55
|
+
assert.strictEqual(response.status, 200);
|
|
56
|
+
assert.strictEqual(response.status, nativeFetch.status);
|
|
57
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
58
|
+
assert.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
59
|
+
});
|
|
60
|
+
for (const api of ['/info', '/metrics', '/block/current']) {
|
|
61
|
+
it(`supports native arweave node apis ${api}`, async () => {
|
|
62
|
+
const [nativeFetch, response] = await Promise.all([
|
|
63
|
+
fetch(`https://arweave.net${api}`),
|
|
64
|
+
wayfinder.request(`ar:///${api}`),
|
|
65
|
+
]);
|
|
66
|
+
assert.strictEqual(response.status, 200);
|
|
67
|
+
assert.strictEqual(response.status, nativeFetch.status);
|
|
68
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
69
|
+
assert.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
|
|
73
|
+
it(`supports native ario node gateway apis ${api}`, async () => {
|
|
74
|
+
const [nativeFetch, response] = await Promise.all([
|
|
75
|
+
fetch(`https://arweave.net${api}`),
|
|
76
|
+
wayfinder.request(`ar:///${api}`),
|
|
77
|
+
]);
|
|
78
|
+
assert.strictEqual(response.status, 200);
|
|
79
|
+
assert.strictEqual(response.status, nativeFetch.status);
|
|
80
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
81
|
+
assert.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
it('supports a post request to graphql', async () => {
|
|
85
|
+
const response = await wayfinder.request('ar:///graphql', {
|
|
86
|
+
method: 'POST',
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': 'application/json',
|
|
89
|
+
},
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
query: `
|
|
92
|
+
query {
|
|
93
|
+
transactions(
|
|
94
|
+
ids: ["xf958qhCNGfDme1FtoiD6DtMfDENDbtxZpjOM_1tsMM"]
|
|
95
|
+
) {
|
|
96
|
+
edges {
|
|
97
|
+
cursor
|
|
98
|
+
node {
|
|
99
|
+
id
|
|
100
|
+
tags {
|
|
101
|
+
name
|
|
102
|
+
value
|
|
103
|
+
}
|
|
104
|
+
block {
|
|
105
|
+
height
|
|
106
|
+
timestamp
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
pageInfo {
|
|
111
|
+
hasNextPage
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
}),
|
|
117
|
+
});
|
|
118
|
+
assert.strictEqual(response.status, 200);
|
|
119
|
+
});
|
|
120
|
+
it('returns the error from the target gateway if the route is not found', async () => {
|
|
121
|
+
const [nativeFetch, response] = await Promise.all([
|
|
122
|
+
fetch('https://arweave.net/not-found'),
|
|
123
|
+
wayfinder.request('https://arweave.net/not-found'),
|
|
124
|
+
]);
|
|
125
|
+
assert.strictEqual(response.status, nativeFetch.status);
|
|
126
|
+
assert.strictEqual(response.statusText, nativeFetch.statusText);
|
|
127
|
+
assert.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('axios', () => {
|
|
131
|
+
let wayfinder;
|
|
132
|
+
before(() => {
|
|
133
|
+
wayfinder = new Wayfinder({
|
|
134
|
+
httpClient: axios,
|
|
135
|
+
router: new RandomGatewayRouter({
|
|
136
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it('should fetch the data using axios default function against the target gateway', async () => {
|
|
141
|
+
const [nativeAxios, response] = await Promise.all([
|
|
142
|
+
axios('https://ao.arweave.net'),
|
|
143
|
+
wayfinder.request('ar://ao'),
|
|
144
|
+
]);
|
|
145
|
+
assert.strictEqual(response.status, 200);
|
|
146
|
+
assert.strictEqual(response.status, nativeAxios.status);
|
|
147
|
+
// assert the arns headers are the same
|
|
148
|
+
const arnsHeaders = Object.entries(response.headers)
|
|
149
|
+
.sort()
|
|
150
|
+
.filter(([key]) => key.startsWith('x-arns-'));
|
|
151
|
+
const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
|
|
152
|
+
assert.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
|
|
153
|
+
assert.deepStrictEqual(response.data, nativeAxios.data);
|
|
154
|
+
});
|
|
155
|
+
it('should fetch the data using the axios.get method against the target gateway', async () => {
|
|
156
|
+
const [nativeAxios, response] = await Promise.all([
|
|
157
|
+
axios.get('https://ao.arweave.net'),
|
|
158
|
+
wayfinder.request.get('ar://ao'),
|
|
159
|
+
]);
|
|
160
|
+
assert.strictEqual(response.status, 200);
|
|
161
|
+
assert.strictEqual(response.status, nativeAxios.status);
|
|
162
|
+
// assert the arns headers are the same
|
|
163
|
+
const arnsHeaders = Object.entries(response.headers)
|
|
164
|
+
.sort()
|
|
165
|
+
.filter(([key]) => key.startsWith('x-arns-'));
|
|
166
|
+
const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
|
|
167
|
+
assert.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
|
|
168
|
+
assert.deepStrictEqual(response.data, nativeAxios.data);
|
|
169
|
+
});
|
|
170
|
+
it('should route a non-ar:// url as a normal axios request', async () => {
|
|
171
|
+
const [nativeAxios, response] = await Promise.all([
|
|
172
|
+
axios('https://arweave.net/'),
|
|
173
|
+
wayfinder.request('https://arweave.net/'),
|
|
174
|
+
]);
|
|
175
|
+
assert.strictEqual(response.status, 200);
|
|
176
|
+
assert.strictEqual(response.status, nativeAxios.status);
|
|
177
|
+
assert.deepStrictEqual(response.data, nativeAxios.data);
|
|
178
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
179
|
+
});
|
|
180
|
+
for (const api of ['/info', '/metrics', '/block/current']) {
|
|
181
|
+
it(`supports native arweave node apis ${api}`, async () => {
|
|
182
|
+
const [nativeAxios, response] = await Promise.all([
|
|
183
|
+
axios(`https://arweave.net${api}`),
|
|
184
|
+
wayfinder.request(`ar:///${api}`),
|
|
185
|
+
]);
|
|
186
|
+
assert.strictEqual(response.status, 200);
|
|
187
|
+
assert.strictEqual(response.status, nativeAxios.status);
|
|
188
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
189
|
+
assert.deepStrictEqual(response.data, nativeAxios.data);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
|
|
193
|
+
it(`supports native ario node gateway apis ${api}`, async () => {
|
|
194
|
+
const [nativeAxios, response] = await Promise.all([
|
|
195
|
+
axios(`https://arweave.net${api}`),
|
|
196
|
+
wayfinder.request(`ar:///${api}`),
|
|
197
|
+
]);
|
|
198
|
+
assert.strictEqual(response.status, 200);
|
|
199
|
+
assert.strictEqual(response.status, nativeAxios.status);
|
|
200
|
+
// TODO: ensure the headers are the same excluding unique headers
|
|
201
|
+
assert.deepStrictEqual(response.data, nativeAxios.data);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
it('should return the error from the target gateway if the route is not found', async () => {
|
|
205
|
+
const axiosInstance = axios.create({
|
|
206
|
+
validateStatus: () => true, // don't throw so we can compare axios result with wrapped axios result
|
|
207
|
+
});
|
|
208
|
+
const wayfinder = new Wayfinder({
|
|
209
|
+
httpClient: axiosInstance,
|
|
210
|
+
router: new RandomGatewayRouter({
|
|
211
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
const [nativeAxios, response] = await Promise.all([
|
|
215
|
+
axiosInstance('https://arweave.net/not-found'),
|
|
216
|
+
wayfinder.request('https://arweave.net/not-found'),
|
|
217
|
+
]);
|
|
218
|
+
assert.strictEqual(response.status, nativeAxios.status);
|
|
219
|
+
assert.strictEqual(response.data, nativeAxios.data);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
describe('got', () => {
|
|
223
|
+
let wayfinder;
|
|
224
|
+
before(() => {
|
|
225
|
+
wayfinder = new Wayfinder({
|
|
226
|
+
httpClient: got,
|
|
227
|
+
router: new RandomGatewayRouter({
|
|
228
|
+
gatewaysProvider: stubbedGatewaysProvider,
|
|
229
|
+
}),
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
it('should fetch the data using the got default function against the target gateway', async () => {
|
|
233
|
+
const [nativeGot, response] = await Promise.all([
|
|
234
|
+
got('https://ao.arweave.net'),
|
|
235
|
+
wayfinder.request('ar://ao'),
|
|
236
|
+
]);
|
|
237
|
+
assert.strictEqual(response.statusCode, 200);
|
|
238
|
+
assert.strictEqual(response.statusCode, nativeGot.statusCode);
|
|
239
|
+
assert.deepStrictEqual(response.body, nativeGot.body);
|
|
240
|
+
});
|
|
241
|
+
it('should stream the data using got.stream against the selected target gateway', async () => {
|
|
242
|
+
const nativeBuffer = await buffer(await got.stream('https://ao.arweave.net', { decompress: false }));
|
|
243
|
+
const wayfinderBuffer = await buffer(await wayfinder.request.stream('ar://ao', { decompress: false }));
|
|
244
|
+
assert.deepStrictEqual(wayfinderBuffer, nativeBuffer);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
package/lib/esm/types/ant.js
CHANGED
|
@@ -77,6 +77,17 @@ export const AntStateSchema = z.object({
|
|
|
77
77
|
.boolean()
|
|
78
78
|
.describe('Flag indicating whether the ANT has been initialized.'),
|
|
79
79
|
});
|
|
80
|
+
export const SpawnANTStateSchema = z.object({
|
|
81
|
+
name: z.string().describe('The name of the ANT.'),
|
|
82
|
+
ticker: z.string().describe('The ticker symbol for the ANT.'),
|
|
83
|
+
description: z.string().describe('The description for the ANT.'),
|
|
84
|
+
keywords: AntKeywordsSchema.describe('The keywords for the ANT.'),
|
|
85
|
+
owner: AOAddressSchema.describe('The Owners address.'),
|
|
86
|
+
controllers: AntControllersSchema.describe('Controllers of the ANT who have administrative privileges.'),
|
|
87
|
+
records: AntRecordsSchema.describe('Records associated with the ANT.'),
|
|
88
|
+
balances: AntBalancesSchema.describe('Balance details for each address holding the ANT.'),
|
|
89
|
+
logo: ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'),
|
|
90
|
+
});
|
|
80
91
|
export const AntReadHandlers = [
|
|
81
92
|
'balance',
|
|
82
93
|
'balances',
|
package/lib/esm/types/index.js
CHANGED
package/lib/esm/types/io.js
CHANGED
|
@@ -22,7 +22,7 @@ export const intentsUsingYears = [
|
|
|
22
22
|
export const isValidIntent = (intent) => {
|
|
23
23
|
return validIntents.indexOf(intent) !== -1;
|
|
24
24
|
};
|
|
25
|
-
export const fundFromOptions = ['balance', 'stakes', 'any'];
|
|
25
|
+
export const fundFromOptions = ['balance', 'stakes', 'any', 'turbo'];
|
|
26
26
|
export const isValidFundFrom = (fundFrom) => {
|
|
27
27
|
return fundFromOptions.indexOf(fundFrom) !== -1;
|
|
28
28
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/utils/ao.js
CHANGED
|
@@ -19,8 +19,13 @@ import { z } from 'zod';
|
|
|
19
19
|
import { defaultArweave } from '../common/arweave.js';
|
|
20
20
|
import { AOProcess, Logger } from '../common/index.js';
|
|
21
21
|
import { ANT_LUA_ID, ANT_REGISTRY_ID, AOS_MODULE_ID, AO_AUTHORITY, DEFAULT_SCHEDULER_ID, } from '../constants.js';
|
|
22
|
+
import { SpawnANTStateSchema } from '../types/ant.js';
|
|
23
|
+
import { parseSchemaResult } from './schema.js';
|
|
22
24
|
export async function spawnANT({ signer, module = AOS_MODULE_ID, ao = connect(), scheduler = DEFAULT_SCHEDULER_ID, state, antRegistryId = ANT_REGISTRY_ID, logger = Logger.default, authority = AO_AUTHORITY, }) {
|
|
23
25
|
// TODO: use On-Boot data handler for bootstrapping state instead of initialize-state
|
|
26
|
+
if (state) {
|
|
27
|
+
parseSchemaResult(SpawnANTStateSchema, state);
|
|
28
|
+
}
|
|
24
29
|
const processId = await ao.spawn({
|
|
25
30
|
module,
|
|
26
31
|
scheduler,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { webcrypto } from 'crypto';
|
|
17
|
+
/**
|
|
18
|
+
* Cryptographically secure helper for randomness, does not support seeding
|
|
19
|
+
* @param min - the minimum value
|
|
20
|
+
* @param max - the maximum value
|
|
21
|
+
* @returns a random integer between min and max
|
|
22
|
+
*/
|
|
23
|
+
export const randomInt = (min, max) => {
|
|
24
|
+
const [rand] = webcrypto.getRandomValues(new Uint32Array(1));
|
|
25
|
+
return min + (rand % (max - min));
|
|
26
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export const urlWithSearchParams = ({ baseUrl, params, }) => {
|
|
17
|
+
const urlObj = new URL(baseUrl);
|
|
18
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
19
|
+
if (value === undefined || value === null)
|
|
20
|
+
return;
|
|
21
|
+
urlObj.searchParams.set(key, value.toString());
|
|
22
|
+
});
|
|
23
|
+
return urlObj.toString();
|
|
24
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { urlWithSearchParams } from './url.js';
|
|
4
|
+
test('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
|
|
5
|
+
const result = urlWithSearchParams({
|
|
6
|
+
baseUrl: 'https://example.com',
|
|
7
|
+
params: {
|
|
8
|
+
number: 1,
|
|
9
|
+
string: 'string',
|
|
10
|
+
boolean: true,
|
|
11
|
+
empty: '',
|
|
12
|
+
zero: 0,
|
|
13
|
+
false: false,
|
|
14
|
+
null: null,
|
|
15
|
+
undef: undefined,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
assert.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
|
|
19
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { strict as assert } from 'node:assert';
|
|
2
2
|
import { describe, it } from 'node:test';
|
|
3
|
+
import { errorMessageFromOutput } from './ao.js';
|
|
3
4
|
import { pruneTags, sortAndPaginateEpochDataIntoEligibleDistributions, } from './arweave.js';
|
|
4
|
-
import { errorMessageFromOutput } from './index.js';
|
|
5
5
|
describe('pruneTags', () => {
|
|
6
6
|
it('should remove tags with undefined values', () => {
|
|
7
7
|
const tags = [
|
package/lib/esm/version.js
CHANGED
package/lib/esm/web/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { ArweaveSigner, ArconnectSigner } from '@dha-team/arbundles';
|
|
16
|
+
export { ArweaveSigner, ArconnectSigner, InjectedEthereumSigner, EthereumSigner, } from '@dha-team/arbundles';
|
|
17
17
|
export * from '../types/index.js';
|
|
18
18
|
export * from '../common/index.js';
|
|
19
19
|
export * from '../constants.js';
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
import { AoANTSetBaseNameRecordParams, AoANTSetUndernameRecordParams } from '../../types/ant.js';
|
|
17
17
|
import { CLIWriteOptionsFromAoAntParams } from '../types.js';
|
|
18
18
|
/** @deprecated -- use set-ant-base-name and set-ant-undername */
|
|
19
|
-
export declare function setAntRecordCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
20
|
-
export declare function setAntBaseNameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetBaseNameRecordParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
21
|
-
export declare function setAntUndernameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
19
|
+
export declare function setAntRecordCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
20
|
+
export declare function setAntBaseNameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetBaseNameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
21
|
+
export declare function setAntUndernameCLICommand(o: CLIWriteOptionsFromAoAntParams<AoANTSetUndernameRecordParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
@@ -19,4 +19,4 @@ export declare function buyRecordCLICommand(o: CLIWriteOptionsFromAoParams<AoBuy
|
|
|
19
19
|
export declare function upgradeRecordCLICommand(o: CLIWriteOptionsFromAoParams<AoArNSPurchaseParams>): Promise<import("../../types/common.js").AoMessageResult>;
|
|
20
20
|
export declare function extendLeaseCLICommand(o: CLIWriteOptionsFromAoParams<AoExtendLeaseParams>): Promise<import("../../types/common.js").AoMessageResult>;
|
|
21
21
|
export declare function increaseUndernameLimitCLICommand(o: CLIWriteOptionsFromAoParams<AoIncreaseUndernameLimitParams>): Promise<import("../../types/common.js").AoMessageResult>;
|
|
22
|
-
export declare function requestPrimaryNameCLICommand(o: CLIWriteOptionsFromAoParams<AoArNSPurchaseParams>): Promise<import("../../types/common.js").AoMessageResult
|
|
22
|
+
export declare function requestPrimaryNameCLICommand(o: CLIWriteOptionsFromAoParams<AoArNSPurchaseParams>): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AddressAndVaultIdCLIWriteOptions, DecreaseDelegateStakeCLIOptions, JoinNetworkCLIOptions, OperatorStakeCLIOptions, RedelegateStakeCLIOptions, TransferCLIOptions, UpdateGatewaySettingsCLIOptions, WriteActionCLIOptions } from '../types.js';
|
|
2
2
|
export declare function joinNetwork(options: JoinNetworkCLIOptions): Promise<{
|
|
3
|
-
joinNetworkResult: import("../../types/common.js").AoMessageResult
|
|
3
|
+
joinNetworkResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
4
4
|
joinedAddress: string;
|
|
5
5
|
message: string;
|
|
6
6
|
}>;
|
|
7
7
|
export declare function updateGatewaySettings(options: UpdateGatewaySettingsCLIOptions): Promise<{
|
|
8
|
-
updateGatewaySettingsResult: import("../../types/common.js").AoMessageResult
|
|
8
|
+
updateGatewaySettingsResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
9
9
|
updatedGatewayAddress: string;
|
|
10
10
|
message: string;
|
|
11
11
|
}>;
|
|
@@ -13,26 +13,26 @@ export declare function leaveNetwork(options: WriteActionCLIOptions): Promise<im
|
|
|
13
13
|
export declare function saveObservations(o: WriteActionCLIOptions & {
|
|
14
14
|
failedGateways?: string[];
|
|
15
15
|
transactionId?: string;
|
|
16
|
-
}): Promise<import("../../types/common.js").AoMessageResult
|
|
16
|
+
}): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
17
17
|
export declare function increaseOperatorStake(o: OperatorStakeCLIOptions): Promise<import("../../types/common.js").WriteOptions>;
|
|
18
|
-
export declare function decreaseOperatorStake(o: OperatorStakeCLIOptions): Promise<import("../../types/common.js").AoMessageResult
|
|
19
|
-
export declare function instantWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult
|
|
20
|
-
export declare function cancelWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult
|
|
18
|
+
export declare function decreaseOperatorStake(o: OperatorStakeCLIOptions): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
19
|
+
export declare function instantWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
20
|
+
export declare function cancelWithdrawal(o: AddressAndVaultIdCLIWriteOptions): Promise<import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>>;
|
|
21
21
|
export declare function delegateStake(options: TransferCLIOptions): Promise<{
|
|
22
22
|
senderAddress: string;
|
|
23
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
23
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
24
24
|
message: string;
|
|
25
25
|
} | {
|
|
26
26
|
message: string;
|
|
27
27
|
}>;
|
|
28
28
|
export declare function decreaseDelegateStake(options: DecreaseDelegateStakeCLIOptions): Promise<{
|
|
29
29
|
targetGateway: string;
|
|
30
|
-
decreaseDelegateStakeResult: import("../../types/common.js").AoMessageResult
|
|
30
|
+
decreaseDelegateStakeResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
31
31
|
message: string;
|
|
32
32
|
}>;
|
|
33
33
|
export declare function redelegateStake(options: RedelegateStakeCLIOptions): Promise<{
|
|
34
34
|
sourceGateway: string;
|
|
35
35
|
targetGateway: string;
|
|
36
|
-
redelegateStakeResult: import("../../types/common.js").AoMessageResult
|
|
36
|
+
redelegateStakeResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
37
37
|
message: string;
|
|
38
38
|
}>;
|
|
@@ -58,6 +58,7 @@ export declare function getCostDetails(o: GlobalCLIOptions & CLIOptionsFromAoPar
|
|
|
58
58
|
basePrice: number;
|
|
59
59
|
};
|
|
60
60
|
fundingPlan?: import("../../types/io.js").AoFundingPlan;
|
|
61
|
+
wincQty?: string;
|
|
61
62
|
}>;
|
|
62
63
|
export declare function getPrimaryName(o: AddressAndNameCLIOptions): Promise<import("../../types/common.js").AoPrimaryName>;
|
|
63
64
|
export declare function getGatewayVaults(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoGatewayVault> | {
|
|
@@ -17,7 +17,7 @@ import { AoCreateVaultParams, AoExtendVaultParams, AoIncreaseVaultParams, AoRevo
|
|
|
17
17
|
import { CLIWriteOptionsFromAoParams, JsonSerializable, TransferCLIOptions } from '../types.js';
|
|
18
18
|
export declare function transferCLICommand(options: TransferCLIOptions): Promise<{
|
|
19
19
|
senderAddress: string;
|
|
20
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
20
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
21
21
|
message: string;
|
|
22
22
|
} | {
|
|
23
23
|
message: string;
|
|
@@ -27,14 +27,14 @@ export declare function revokeVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoR
|
|
|
27
27
|
export declare function createVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoCreateVaultParams>): Promise<JsonSerializable>;
|
|
28
28
|
export declare function extendVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoExtendVaultParams>): Promise<{
|
|
29
29
|
senderAddress: string;
|
|
30
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
30
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
31
31
|
message: string;
|
|
32
32
|
} | {
|
|
33
33
|
message: string;
|
|
34
34
|
}>;
|
|
35
35
|
export declare function increaseVaultCLICommand(o: CLIWriteOptionsFromAoParams<AoIncreaseVaultParams>): Promise<{
|
|
36
36
|
senderAddress: string;
|
|
37
|
-
transferResult: import("../../types/common.js").AoMessageResult
|
|
37
|
+
transferResult: import("../../types/common.js").AoMessageResult<Record<string, string | number | boolean | null>>;
|
|
38
38
|
message: string;
|
|
39
39
|
} | {
|
|
40
40
|
message: string;
|
|
@@ -45,6 +45,10 @@ export declare const optionMap: {
|
|
|
45
45
|
alias: string;
|
|
46
46
|
description: string;
|
|
47
47
|
};
|
|
48
|
+
paymentUrl: {
|
|
49
|
+
alias: string;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
48
52
|
processId: {
|
|
49
53
|
alias: string;
|
|
50
54
|
description: string;
|
|
@@ -265,6 +269,11 @@ export declare const optionMap: {
|
|
|
265
269
|
alias: string;
|
|
266
270
|
description: string;
|
|
267
271
|
};
|
|
272
|
+
token: {
|
|
273
|
+
alias: string;
|
|
274
|
+
description: string;
|
|
275
|
+
default: string;
|
|
276
|
+
};
|
|
268
277
|
};
|
|
269
278
|
export declare const walletOptions: {
|
|
270
279
|
alias: string;
|
package/lib/types/cli/types.d.ts
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { AoAddressParams, AoArNSNameParams, AoGetVaultParams, AoJoinNetworkParams, AoTokenCostParams, PaginationParams } from '../types/io.js';
|
|
17
|
+
export type SupportedCLITokenType = 'ethereum' | 'arweave';
|
|
17
18
|
export type WalletCLIOptions = {
|
|
18
19
|
walletFile?: string;
|
|
20
|
+
token?: SupportedCLITokenType;
|
|
19
21
|
privateKey?: string;
|
|
20
22
|
};
|
|
21
23
|
export type GlobalCLIOptions = WalletCLIOptions & {
|
|
@@ -25,6 +27,7 @@ export type GlobalCLIOptions = WalletCLIOptions & {
|
|
|
25
27
|
debug: boolean;
|
|
26
28
|
arioProcessId?: string;
|
|
27
29
|
cuUrl?: string;
|
|
30
|
+
paymentUrl?: string;
|
|
28
31
|
};
|
|
29
32
|
export type WriteActionCLIOptions = GlobalCLIOptions & {
|
|
30
33
|
tags?: string[];
|
package/lib/types/cli/utils.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export declare function requiredJwkFromOptions(options: WalletCLIOptions): JWKIn
|
|
|
22
22
|
export declare function jwkToAddress(jwk: JWKInterface): string;
|
|
23
23
|
export declare function getLoggerFromOptions(options: GlobalCLIOptions): Logger;
|
|
24
24
|
export declare function readARIOFromOptions(options: GlobalCLIOptions): AoARIORead;
|
|
25
|
+
export declare function contractSignerFromOptions(options: WalletCLIOptions): {
|
|
26
|
+
signer: ContractSigner;
|
|
27
|
+
signerAddress: string;
|
|
28
|
+
} | undefined;
|
|
25
29
|
export declare function requiredContractSignerFromOptions(options: WalletCLIOptions): {
|
|
26
30
|
signer: ContractSigner;
|
|
27
31
|
signerAddress: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AoANTVersionsRead, AoANTVersionsWrite } from '../types/ant.js';
|
|
2
|
-
import { WithSigner } from '../types/common.js';
|
|
2
|
+
import { AoMessageResult, WithSigner } from '../types/common.js';
|
|
3
3
|
import { ProcessConfiguration } from '../types/io.js';
|
|
4
4
|
import { AOProcess } from './contracts/ao-process.js';
|
|
5
5
|
type ANTVersionsNoSigner = ProcessConfiguration;
|
|
@@ -27,16 +27,13 @@ export declare class ANTVersionsReadable implements AoANTVersionsRead {
|
|
|
27
27
|
export declare class ANTVersionsWritable extends ANTVersionsReadable implements AoANTVersionsWrite {
|
|
28
28
|
private signer;
|
|
29
29
|
constructor({ signer, ...config }: WithSigner<ProcessConfiguration>);
|
|
30
|
-
addVersion(
|
|
30
|
+
addVersion({ version, moduleId, luaSourceId, notes, }: {
|
|
31
31
|
version: string;
|
|
32
32
|
moduleId: string;
|
|
33
33
|
luaSourceId?: string;
|
|
34
34
|
notes?: string;
|
|
35
35
|
}, { tags }: {
|
|
36
36
|
tags: any;
|
|
37
|
-
}): Promise<
|
|
38
|
-
id: string;
|
|
39
|
-
result?: unknown;
|
|
40
|
-
}>;
|
|
37
|
+
}): Promise<AoMessageResult>;
|
|
41
38
|
}
|
|
42
39
|
export {};
|