@ar.io/sdk 2.0.3-alpha.1 → 2.1.0-alpha.10
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 +103 -22
- package/bundles/web.bundle.min.js +104 -104
- package/lib/cjs/common/ant-registry.js +87 -0
- package/lib/cjs/common/ant.js +3 -9
- package/lib/cjs/common/contracts/ao-process.js +2 -19
- package/lib/cjs/common/index.js +1 -0
- package/lib/cjs/common/io.js +14 -12
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/io.js +2 -1
- package/lib/cjs/types.js +0 -1
- package/lib/cjs/utils/ao.js +53 -3
- package/lib/cjs/utils/json.js +3 -2
- package/lib/cjs/utils/processes.js +24 -43
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant-registry.js +81 -0
- package/lib/esm/common/ant.js +3 -9
- package/lib/esm/common/contracts/ao-process.js +2 -19
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/io.js +14 -12
- package/lib/esm/constants.js +2 -1
- package/lib/esm/io.js +2 -1
- package/lib/esm/types.js +0 -1
- package/lib/esm/utils/ao.js +52 -4
- package/lib/esm/utils/json.js +1 -0
- package/lib/esm/utils/processes.js +24 -43
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant-registry.d.ts +26 -0
- package/lib/types/common/ant.d.ts +5 -4
- package/lib/types/common/contracts/ao-process.d.ts +4 -17
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/io.d.ts +9 -12
- package/lib/types/common.d.ts +2 -25
- package/lib/types/constants.d.ts +2 -1
- package/lib/types/io.d.ts +181 -116
- package/lib/types/token.d.ts +13 -0
- package/lib/types/types.d.ts +0 -1
- package/lib/types/utils/ao.d.ts +19 -5
- package/lib/types/utils/processes.d.ts +11 -5
- package/lib/types/version.d.ts +1 -1
- package/package.json +7 -2
- package/lib/cjs/contract-state.js +0 -68
- package/lib/esm/contract-state.js +0 -65
- package/lib/types/contract-state.d.ts +0 -201
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AoANTRegistryWriteable = exports.AoANTRegistryReadable = exports.ANTRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Affero General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
const constants_js_1 = require("../constants.js");
|
|
21
|
+
const types_js_1 = require("../types.js");
|
|
22
|
+
const ao_js_1 = require("../utils/ao.js");
|
|
23
|
+
const index_js_1 = require("./index.js");
|
|
24
|
+
class ANTRegistry {
|
|
25
|
+
static init(config) {
|
|
26
|
+
if (config && config.signer) {
|
|
27
|
+
const { signer, ...rest } = config;
|
|
28
|
+
return new AoANTRegistryWriteable({
|
|
29
|
+
...rest,
|
|
30
|
+
signer,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return new AoANTRegistryReadable(config);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ANTRegistry = ANTRegistry;
|
|
37
|
+
class AoANTRegistryReadable {
|
|
38
|
+
process;
|
|
39
|
+
constructor(config) {
|
|
40
|
+
if (config &&
|
|
41
|
+
((0, types_js_1.isProcessIdConfiguration)(config) || (0, types_js_1.isProcessConfiguration)(config))) {
|
|
42
|
+
if ((0, types_js_1.isProcessConfiguration)(config)) {
|
|
43
|
+
this.process = config.process;
|
|
44
|
+
}
|
|
45
|
+
else if ((0, types_js_1.isProcessIdConfiguration)(config)) {
|
|
46
|
+
this.process = new index_js_1.AOProcess({
|
|
47
|
+
processId: config.processId,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new index_js_1.InvalidContractConfigurationError();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.process = new index_js_1.AOProcess({
|
|
56
|
+
processId: constants_js_1.ANT_REGISTRY_ID,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
|
|
61
|
+
async accessControlList({ address, }) {
|
|
62
|
+
return this.process.read({
|
|
63
|
+
tags: [
|
|
64
|
+
{ name: 'Action', value: 'Access-Control-List' },
|
|
65
|
+
{ name: 'Address', value: address },
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.AoANTRegistryReadable = AoANTRegistryReadable;
|
|
71
|
+
class AoANTRegistryWriteable extends AoANTRegistryReadable {
|
|
72
|
+
signer;
|
|
73
|
+
constructor({ signer, ...config }) {
|
|
74
|
+
super(config);
|
|
75
|
+
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
76
|
+
}
|
|
77
|
+
async register({ processId, }) {
|
|
78
|
+
return this.process.send({
|
|
79
|
+
tags: [
|
|
80
|
+
{ name: 'Action', value: 'Register' },
|
|
81
|
+
{ name: 'Process-Id', value: processId },
|
|
82
|
+
],
|
|
83
|
+
signer: this.signer,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.AoANTRegistryWriteable = AoANTRegistryWriteable;
|
package/lib/cjs/common/ant.js
CHANGED
|
@@ -18,6 +18,7 @@ exports.AoANTWriteable = exports.AoANTReadable = exports.ANT = void 0;
|
|
|
18
18
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
const types_js_1 = require("../types.js");
|
|
21
|
+
const ao_js_1 = require("../utils/ao.js");
|
|
21
22
|
const index_js_1 = require("./index.js");
|
|
22
23
|
class ANT {
|
|
23
24
|
static init({ signer, ...config }) {
|
|
@@ -81,7 +82,7 @@ class AoANTReadable {
|
|
|
81
82
|
return record;
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
|
-
* @returns {Promise<Record<string,
|
|
85
|
+
* @returns {Promise<Record<string, AoANTRecord>>} All the undernames managed by the ANT.
|
|
85
86
|
* @example
|
|
86
87
|
* Get the current records
|
|
87
88
|
* ```ts
|
|
@@ -186,7 +187,7 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
186
187
|
signer;
|
|
187
188
|
constructor({ signer, ...config }) {
|
|
188
189
|
super(config);
|
|
189
|
-
this.signer = signer;
|
|
190
|
+
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
190
191
|
}
|
|
191
192
|
/**
|
|
192
193
|
* @param target @type {string} The address of the account you want to transfer the ANT to.
|
|
@@ -203,7 +204,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
203
204
|
];
|
|
204
205
|
return this.process.send({
|
|
205
206
|
tags,
|
|
206
|
-
data: {},
|
|
207
207
|
signer: this.signer,
|
|
208
208
|
});
|
|
209
209
|
}
|
|
@@ -222,7 +222,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
222
222
|
];
|
|
223
223
|
return this.process.send({
|
|
224
224
|
tags,
|
|
225
|
-
data: {},
|
|
226
225
|
signer: this.signer,
|
|
227
226
|
});
|
|
228
227
|
}
|
|
@@ -241,7 +240,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
241
240
|
];
|
|
242
241
|
return this.process.send({
|
|
243
242
|
tags,
|
|
244
|
-
data: {},
|
|
245
243
|
signer: this.signer,
|
|
246
244
|
});
|
|
247
245
|
}
|
|
@@ -263,7 +261,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
263
261
|
{ name: 'Transaction-Id', value: transactionId },
|
|
264
262
|
{ name: 'TTL-Seconds', value: ttlSeconds.toString() },
|
|
265
263
|
],
|
|
266
|
-
data: { transactionId, ttlSeconds },
|
|
267
264
|
signer: this.signer,
|
|
268
265
|
});
|
|
269
266
|
}
|
|
@@ -281,7 +278,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
281
278
|
{ name: 'Action', value: 'Remove-Record' },
|
|
282
279
|
{ name: 'Sub-Domain', value: undername },
|
|
283
280
|
],
|
|
284
|
-
data: { undername },
|
|
285
281
|
signer: this.signer,
|
|
286
282
|
});
|
|
287
283
|
}
|
|
@@ -299,7 +295,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
299
295
|
{ name: 'Action', value: 'Set-Ticker' },
|
|
300
296
|
{ name: 'Ticker', value: ticker },
|
|
301
297
|
],
|
|
302
|
-
data: { ticker },
|
|
303
298
|
signer: this.signer,
|
|
304
299
|
});
|
|
305
300
|
}
|
|
@@ -317,7 +312,6 @@ class AoANTWriteable extends AoANTReadable {
|
|
|
317
312
|
{ name: 'Action', value: 'Set-Name' },
|
|
318
313
|
{ name: 'Name', value: name },
|
|
319
314
|
],
|
|
320
|
-
data: { name },
|
|
321
315
|
signer: this.signer,
|
|
322
316
|
});
|
|
323
317
|
}
|
|
@@ -18,7 +18,6 @@ exports.AOProcess = void 0;
|
|
|
18
18
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
21
|
-
const arbundles_1 = require("arbundles");
|
|
22
21
|
const json_js_1 = require("../../utils/json.js");
|
|
23
22
|
const version_js_1 = require("../../version.js");
|
|
24
23
|
const error_js_1 = require("../error.js");
|
|
@@ -32,22 +31,6 @@ class AOProcess {
|
|
|
32
31
|
this.logger = logger;
|
|
33
32
|
this.ao = ao;
|
|
34
33
|
}
|
|
35
|
-
// TODO: could abstract into our own interface that constructs different signers
|
|
36
|
-
static async createAoSigner(signer) {
|
|
37
|
-
// ensure appropriate permissions are granted with injected signers.
|
|
38
|
-
if (signer.publicKey === undefined && 'setPublicKey' in signer) {
|
|
39
|
-
await signer.setPublicKey();
|
|
40
|
-
}
|
|
41
|
-
const aoSigner = async ({ data, tags, target, anchor }) => {
|
|
42
|
-
const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
|
|
43
|
-
const signedData = dataItem.sign(signer).then(async () => ({
|
|
44
|
-
id: await dataItem.id,
|
|
45
|
-
raw: await dataItem.getRaw(),
|
|
46
|
-
}));
|
|
47
|
-
return signedData;
|
|
48
|
-
};
|
|
49
|
-
return aoSigner;
|
|
50
|
-
}
|
|
51
34
|
async read({ tags, retries = 3, }) {
|
|
52
35
|
let attempts = 0;
|
|
53
36
|
let lastError;
|
|
@@ -108,8 +91,8 @@ class AOProcess {
|
|
|
108
91
|
process: this.processId,
|
|
109
92
|
// TODO: any other default tags we want to add?
|
|
110
93
|
tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
|
|
111
|
-
data
|
|
112
|
-
signer
|
|
94
|
+
data,
|
|
95
|
+
signer,
|
|
113
96
|
});
|
|
114
97
|
this.logger.debug(`Sent message to process`, {
|
|
115
98
|
messageId,
|
package/lib/cjs/common/index.js
CHANGED
|
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
33
33
|
__exportStar(require("./error.js"), exports);
|
|
34
34
|
__exportStar(require("./logger.js"), exports);
|
|
35
35
|
__exportStar(require("./ant.js"), exports);
|
|
36
|
+
__exportStar(require("./ant-registry.js"), exports);
|
|
36
37
|
// ao
|
|
37
38
|
__exportStar(require("./io.js"), exports);
|
|
38
39
|
__exportStar(require("./contracts/ao-process.js"), exports);
|
package/lib/cjs/common/io.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.IOWriteable = exports.IOReadable = exports.IO = void 0;
|
|
4
4
|
const constants_js_1 = require("../constants.js");
|
|
5
5
|
const io_js_1 = require("../io.js");
|
|
6
|
+
const ao_js_1 = require("../utils/ao.js");
|
|
6
7
|
const arweave_js_1 = require("./arweave.js");
|
|
7
8
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
8
9
|
const error_js_1 = require("./error.js");
|
|
@@ -46,6 +47,11 @@ class IOReadable {
|
|
|
46
47
|
tags: [{ name: 'Action', value: 'Info' }],
|
|
47
48
|
});
|
|
48
49
|
}
|
|
50
|
+
async getTokenSupply() {
|
|
51
|
+
return this.process.read({
|
|
52
|
+
tags: [{ name: 'Action', value: 'Total-Token-Supply' }],
|
|
53
|
+
});
|
|
54
|
+
}
|
|
49
55
|
async getEpochSettings(params) {
|
|
50
56
|
const allTags = [
|
|
51
57
|
{ name: 'Action', value: 'Epoch-Settings' },
|
|
@@ -341,11 +347,11 @@ class IOWriteable extends IOReadable {
|
|
|
341
347
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
342
348
|
}),
|
|
343
349
|
});
|
|
344
|
-
this.signer = signer;
|
|
350
|
+
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
345
351
|
}
|
|
346
352
|
else if ((0, io_js_1.isProcessConfiguration)(config)) {
|
|
347
353
|
super({ process: config.process });
|
|
348
|
-
this.signer = signer;
|
|
354
|
+
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
349
355
|
}
|
|
350
356
|
else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
|
|
351
357
|
super({
|
|
@@ -353,7 +359,7 @@ class IOWriteable extends IOReadable {
|
|
|
353
359
|
processId: config.processId,
|
|
354
360
|
}),
|
|
355
361
|
});
|
|
356
|
-
this.signer = signer;
|
|
362
|
+
this.signer = (0, ao_js_1.createAoSigner)(signer);
|
|
357
363
|
}
|
|
358
364
|
else {
|
|
359
365
|
throw new error_js_1.InvalidContractConfigurationError();
|
|
@@ -388,11 +394,11 @@ class IOWriteable extends IOReadable {
|
|
|
388
394
|
},
|
|
389
395
|
{
|
|
390
396
|
name: 'Allow-Delegated-Staking',
|
|
391
|
-
value: allowDelegatedStaking
|
|
397
|
+
value: allowDelegatedStaking?.toString(),
|
|
392
398
|
},
|
|
393
399
|
{
|
|
394
400
|
name: 'Delegate-Reward-Share-Ratio',
|
|
395
|
-
value: delegateRewardShareRatio
|
|
401
|
+
value: delegateRewardShareRatio?.toString(),
|
|
396
402
|
},
|
|
397
403
|
{
|
|
398
404
|
name: 'FQDN',
|
|
@@ -404,7 +410,7 @@ class IOWriteable extends IOReadable {
|
|
|
404
410
|
},
|
|
405
411
|
{
|
|
406
412
|
name: 'Min-Delegated-Stake',
|
|
407
|
-
value: minDelegatedStake
|
|
413
|
+
value: minDelegatedStake?.valueOf().toString(),
|
|
408
414
|
},
|
|
409
415
|
{
|
|
410
416
|
name: 'Note',
|
|
@@ -412,7 +418,7 @@ class IOWriteable extends IOReadable {
|
|
|
412
418
|
},
|
|
413
419
|
{
|
|
414
420
|
name: 'Port',
|
|
415
|
-
value: port
|
|
421
|
+
value: port?.toString(),
|
|
416
422
|
},
|
|
417
423
|
{
|
|
418
424
|
name: 'Properties',
|
|
@@ -424,7 +430,7 @@ class IOWriteable extends IOReadable {
|
|
|
424
430
|
},
|
|
425
431
|
{
|
|
426
432
|
name: 'Auto-Stake',
|
|
427
|
-
value: autoStake
|
|
433
|
+
value: autoStake?.toString(),
|
|
428
434
|
},
|
|
429
435
|
{
|
|
430
436
|
name: 'Observer-Address',
|
|
@@ -538,10 +544,6 @@ class IOWriteable extends IOReadable {
|
|
|
538
544
|
value: params.failedGateways.join(','),
|
|
539
545
|
},
|
|
540
546
|
],
|
|
541
|
-
data: {
|
|
542
|
-
reportTxId: params.reportTxId,
|
|
543
|
-
failedGateways: params.failedGateways,
|
|
544
|
-
},
|
|
545
547
|
});
|
|
546
548
|
}
|
|
547
549
|
async buyRecord(params, options) {
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MIO_PER_IO = exports.IO_TESTNET_PROCESS_ID = exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
3
|
+
exports.DEFAULT_SCHEDULER_ID = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MIO_PER_IO = exports.ANT_REGISTRY_ID = exports.IO_TESTNET_PROCESS_ID = exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -28,7 +28,8 @@ exports.IO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
|
|
|
28
28
|
// backwards compatibility - TODO: remove in v2.0.0
|
|
29
29
|
exports.ioDevnetProcessId = exports.IO_DEVNET_PROCESS_ID;
|
|
30
30
|
exports.IO_TESTNET_PROCESS_ID = 'agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA';
|
|
31
|
+
exports.ANT_REGISTRY_ID = 'i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc';
|
|
31
32
|
exports.MIO_PER_IO = 1_000_000;
|
|
32
33
|
exports.AOS_MODULE_ID = 'cbn0KKrBZH7hdNkNokuXLtGryrWM--PjSTBqIzw9Kkk';
|
|
33
|
-
exports.ANT_LUA_ID = '
|
|
34
|
+
exports.ANT_LUA_ID = 'Flwio4Lr08g6s6uim6lEJNnVGD9ylvz0_aafvpiL8FI';
|
|
34
35
|
exports.DEFAULT_SCHEDULER_ID = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA';
|
package/lib/cjs/io.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isLeasedArNSRecord = exports.isProcessIdConfiguration = exports.isProcessConfiguration = void 0;
|
|
4
4
|
const arweave_js_1 = require("./utils/arweave.js");
|
|
5
|
+
// Typeguard functions
|
|
5
6
|
function isProcessConfiguration(config) {
|
|
6
7
|
return 'process' in config;
|
|
7
8
|
}
|
|
@@ -13,6 +14,6 @@ function isProcessIdConfiguration(config) {
|
|
|
13
14
|
}
|
|
14
15
|
exports.isProcessIdConfiguration = isProcessIdConfiguration;
|
|
15
16
|
function isLeasedArNSRecord(record) {
|
|
16
|
-
return record.type === 'lease'
|
|
17
|
+
return record.type === 'lease';
|
|
17
18
|
}
|
|
18
19
|
exports.isLeasedArNSRecord = isLeasedArNSRecord;
|
package/lib/cjs/types.js
CHANGED
|
@@ -30,7 +30,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
* You should have received a copy of the GNU Affero General Public License
|
|
31
31
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
32
32
|
*/
|
|
33
|
-
__exportStar(require("./contract-state.js"), exports);
|
|
34
33
|
__exportStar(require("./common.js"), exports);
|
|
35
34
|
__exportStar(require("./token.js"), exports);
|
|
36
35
|
__exportStar(require("./io.js"), exports);
|
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.spawnANT = void 0;
|
|
3
|
+
exports.createAoSigner = exports.evolveANT = exports.spawnANT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -18,10 +18,11 @@ exports.spawnANT = void 0;
|
|
|
18
18
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
21
|
+
const arbundles_1 = require("arbundles");
|
|
21
22
|
const arweave_js_1 = require("../common/arweave.js");
|
|
22
23
|
const index_js_1 = require("../common/index.js");
|
|
23
24
|
const constants_js_1 = require("../constants.js");
|
|
24
|
-
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, }) {
|
|
25
|
+
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, }) {
|
|
25
26
|
//TODO: cache locally and only fetch if not cached
|
|
26
27
|
const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
|
|
27
28
|
decode: true,
|
|
@@ -30,7 +31,13 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
30
31
|
const processId = await ao.spawn({
|
|
31
32
|
module,
|
|
32
33
|
scheduler,
|
|
33
|
-
signer
|
|
34
|
+
signer,
|
|
35
|
+
tags: [
|
|
36
|
+
{
|
|
37
|
+
name: 'ANT-Registry-Id',
|
|
38
|
+
value: antRegistryId,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
34
41
|
});
|
|
35
42
|
const aosClient = new index_js_1.AOProcess({
|
|
36
43
|
processId,
|
|
@@ -60,3 +67,46 @@ async function spawnANT({ signer, module = constants_js_1.AOS_MODULE_ID, luaCode
|
|
|
60
67
|
return processId;
|
|
61
68
|
}
|
|
62
69
|
exports.spawnANT = spawnANT;
|
|
70
|
+
async function evolveANT({ signer, processId, luaCodeTxId = constants_js_1.ANT_LUA_ID, ao = (0, aoconnect_1.connect)(), }) {
|
|
71
|
+
const aosClient = new index_js_1.AOProcess({
|
|
72
|
+
processId,
|
|
73
|
+
ao,
|
|
74
|
+
});
|
|
75
|
+
//TODO: cache locally and only fetch if not cached
|
|
76
|
+
const luaString = (await arweave_js_1.defaultArweave.transactions.getData(luaCodeTxId, {
|
|
77
|
+
decode: true,
|
|
78
|
+
string: true,
|
|
79
|
+
}));
|
|
80
|
+
const { id } = await aosClient.send({
|
|
81
|
+
tags: [
|
|
82
|
+
{ name: 'Action', value: 'Eval' },
|
|
83
|
+
{ name: 'App-Name', value: 'ArNS-ANT' },
|
|
84
|
+
{ name: 'Source-Code-TX-ID', value: luaCodeTxId },
|
|
85
|
+
],
|
|
86
|
+
data: luaString,
|
|
87
|
+
signer,
|
|
88
|
+
});
|
|
89
|
+
return id;
|
|
90
|
+
}
|
|
91
|
+
exports.evolveANT = evolveANT;
|
|
92
|
+
function createAoSigner(signer) {
|
|
93
|
+
if (!('publicKey' in signer)) {
|
|
94
|
+
return (0, aoconnect_1.createDataItemSigner)(signer);
|
|
95
|
+
}
|
|
96
|
+
const aoSigner = async ({ data, tags, target, anchor }) => {
|
|
97
|
+
// ensure appropriate permissions are granted with injected signers.
|
|
98
|
+
if (signer.publicKey === undefined &&
|
|
99
|
+
'setPublicKey' in signer &&
|
|
100
|
+
typeof signer.setPublicKey === 'function') {
|
|
101
|
+
await signer.setPublicKey();
|
|
102
|
+
}
|
|
103
|
+
const dataItem = (0, arbundles_1.createData)(data, signer, { tags, target, anchor });
|
|
104
|
+
const signedData = dataItem.sign(signer).then(async () => ({
|
|
105
|
+
id: await dataItem.id,
|
|
106
|
+
raw: await dataItem.getRaw(),
|
|
107
|
+
}));
|
|
108
|
+
return signedData;
|
|
109
|
+
};
|
|
110
|
+
return aoSigner;
|
|
111
|
+
}
|
|
112
|
+
exports.createAoSigner = createAoSigner;
|
package/lib/cjs/utils/json.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeDecode = void 0;
|
|
4
2
|
/**
|
|
5
3
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
4
|
*
|
|
@@ -17,6 +15,9 @@ exports.safeDecode = void 0;
|
|
|
17
15
|
* You should have received a copy of the GNU Affero General Public License
|
|
18
16
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
17
|
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.safeDecode = void 0;
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
21
|
function safeDecode(data) {
|
|
21
22
|
try {
|
|
22
23
|
return JSON.parse(data);
|
|
@@ -19,37 +19,17 @@ exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcesses
|
|
|
19
19
|
*/
|
|
20
20
|
const eventemitter3_1 = require("eventemitter3");
|
|
21
21
|
const plimit_lit_1 = require("plimit-lit");
|
|
22
|
+
const ant_registry_js_1 = require("../common/ant-registry.js");
|
|
22
23
|
const ant_js_1 = require("../common/ant.js");
|
|
23
24
|
const io_js_1 = require("../common/io.js");
|
|
24
25
|
const logger_js_1 = require("../common/logger.js");
|
|
25
26
|
const constants_js_1 = require("../constants.js");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
contract: contract,
|
|
33
|
-
});
|
|
34
|
-
const uniqueContractProcessIds = Object.values(records)
|
|
35
|
-
.filter((record) => record.processId !== undefined)
|
|
36
|
-
.map((record) => record.processId);
|
|
37
|
-
// check the contract owner and controllers
|
|
38
|
-
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
39
|
-
const ant = ant_js_1.ANT.init({
|
|
40
|
-
processId,
|
|
41
|
-
});
|
|
42
|
-
const { Owner, Controllers } = await ant.getState();
|
|
43
|
-
if (Owner === address || Controllers.includes(address)) {
|
|
44
|
-
return processId;
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
})));
|
|
48
|
-
if (ownedOrControlledByWallet.length === 0) {
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
// TODO: insert gql query to find ANT processes owned by wallet given wallet not currently in the registry
|
|
52
|
-
return [...new Set(ownedOrControlledByWallet)];
|
|
27
|
+
/**
|
|
28
|
+
* @beta This API is in beta and may change in the future.
|
|
29
|
+
*/
|
|
30
|
+
const getANTProcessesOwnedByWallet = async ({ address, registry = ant_registry_js_1.ANTRegistry.init(), }) => {
|
|
31
|
+
const res = await registry.accessControlList({ address });
|
|
32
|
+
return [...new Set([...res.Owned, ...res.Controlled])];
|
|
53
33
|
};
|
|
54
34
|
exports.getANTProcessesOwnedByWallet = getANTProcessesOwnedByWallet;
|
|
55
35
|
function timeout(ms, promise) {
|
|
@@ -82,9 +62,11 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
82
62
|
this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
|
|
83
63
|
this.logger = logger;
|
|
84
64
|
}
|
|
85
|
-
async fetchProcessesOwnedByWallet({ address }) {
|
|
65
|
+
async fetchProcessesOwnedByWallet({ address, pageSize, antRegistry = ant_registry_js_1.ANTRegistry.init(), }) {
|
|
86
66
|
const uniqueContractProcessIds = {};
|
|
87
|
-
|
|
67
|
+
const antIdRes = await antRegistry.accessControlList({ address });
|
|
68
|
+
const antIds = new Set([...antIdRes.Owned, ...antIdRes.Controlled]);
|
|
69
|
+
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract, emitter: this, pageSize }))
|
|
88
70
|
.catch((e) => {
|
|
89
71
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
90
72
|
this.logger.error(`Error getting ArNS records`, {
|
|
@@ -94,19 +76,17 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
94
76
|
return {};
|
|
95
77
|
})
|
|
96
78
|
.then((records) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
79
|
+
Object.entries(records).forEach(([name, arnsRecord]) => {
|
|
80
|
+
if (antIds.has(arnsRecord.processId)) {
|
|
81
|
+
if (uniqueContractProcessIds[arnsRecord.processId] == undefined) {
|
|
82
|
+
uniqueContractProcessIds[arnsRecord.processId] = {
|
|
83
|
+
state: undefined,
|
|
84
|
+
names: {},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
uniqueContractProcessIds[arnsRecord.processId].names[name] =
|
|
88
|
+
arnsRecord;
|
|
108
89
|
}
|
|
109
|
-
uniqueContractProcessIds[record.processId].names[name] = record;
|
|
110
90
|
});
|
|
111
91
|
});
|
|
112
92
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
@@ -137,13 +117,14 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
137
117
|
exports.ArNSEventEmitter = ArNSEventEmitter;
|
|
138
118
|
const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
139
119
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
140
|
-
}), emitter, logger = logger_js_1.Logger.default, }) => {
|
|
120
|
+
}), emitter, logger = logger_js_1.Logger.default, pageSize = 50_000, }) => {
|
|
141
121
|
let cursor;
|
|
142
122
|
const startTimestamp = Date.now();
|
|
143
123
|
const records = {};
|
|
144
124
|
do {
|
|
145
125
|
const pageResult = await contract
|
|
146
|
-
.getArNSRecords({ cursor })
|
|
126
|
+
.getArNSRecords({ cursor, limit: pageSize })
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
147
128
|
.catch((e) => {
|
|
148
129
|
logger?.error(`Error getting ArNS records`, {
|
|
149
130
|
message: e?.message,
|
package/lib/cjs/version.js
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
import { ANT_REGISTRY_ID } from '../constants.js';
|
|
18
|
+
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types.js';
|
|
19
|
+
import { createAoSigner } from '../utils/ao.js';
|
|
20
|
+
import { AOProcess, InvalidContractConfigurationError } from './index.js';
|
|
21
|
+
export class ANTRegistry {
|
|
22
|
+
static init(config) {
|
|
23
|
+
if (config && config.signer) {
|
|
24
|
+
const { signer, ...rest } = config;
|
|
25
|
+
return new AoANTRegistryWriteable({
|
|
26
|
+
...rest,
|
|
27
|
+
signer,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return new AoANTRegistryReadable(config);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class AoANTRegistryReadable {
|
|
34
|
+
process;
|
|
35
|
+
constructor(config) {
|
|
36
|
+
if (config &&
|
|
37
|
+
(isProcessIdConfiguration(config) || isProcessConfiguration(config))) {
|
|
38
|
+
if (isProcessConfiguration(config)) {
|
|
39
|
+
this.process = config.process;
|
|
40
|
+
}
|
|
41
|
+
else if (isProcessIdConfiguration(config)) {
|
|
42
|
+
this.process = new AOProcess({
|
|
43
|
+
processId: config.processId,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
throw new InvalidContractConfigurationError();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.process = new AOProcess({
|
|
52
|
+
processId: ANT_REGISTRY_ID,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
|
|
57
|
+
async accessControlList({ address, }) {
|
|
58
|
+
return this.process.read({
|
|
59
|
+
tags: [
|
|
60
|
+
{ name: 'Action', value: 'Access-Control-List' },
|
|
61
|
+
{ name: 'Address', value: address },
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class AoANTRegistryWriteable extends AoANTRegistryReadable {
|
|
67
|
+
signer;
|
|
68
|
+
constructor({ signer, ...config }) {
|
|
69
|
+
super(config);
|
|
70
|
+
this.signer = createAoSigner(signer);
|
|
71
|
+
}
|
|
72
|
+
async register({ processId, }) {
|
|
73
|
+
return this.process.send({
|
|
74
|
+
tags: [
|
|
75
|
+
{ name: 'Action', value: 'Register' },
|
|
76
|
+
{ name: 'Process-Id', value: processId },
|
|
77
|
+
],
|
|
78
|
+
signer: this.signer,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|