@ar.io/sdk 1.2.2 → 2.0.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 +148 -60
- package/bundles/web.bundle.min.js +132 -331
- package/lib/cjs/common/ant.js +147 -206
- package/lib/cjs/common/contracts/ao-process.js +1 -1
- package/lib/cjs/common/http.js +1 -2
- package/lib/cjs/common/index.js +0 -5
- package/lib/cjs/common/io.js +39 -31
- package/lib/cjs/common/logger.js +31 -19
- package/lib/cjs/types.js +0 -1
- package/lib/cjs/utils/arweave.js +1 -15
- package/lib/cjs/utils/http-client.js +1 -1
- package/lib/cjs/utils/index.js +1 -2
- package/lib/cjs/utils/{graphql/processes.js → processes.js} +35 -10
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant.js +144 -203
- package/lib/esm/common/contracts/ao-process.js +2 -2
- package/lib/esm/common/http.js +2 -3
- package/lib/esm/common/index.js +0 -5
- package/lib/esm/common/io.js +39 -28
- package/lib/esm/common/logger.js +29 -14
- package/lib/esm/types.js +0 -1
- package/lib/esm/utils/arweave.js +0 -12
- package/lib/esm/utils/http-client.js +2 -2
- package/lib/esm/utils/index.js +1 -2
- package/lib/esm/utils/{graphql/processes.js → processes.js} +33 -9
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +53 -175
- package/lib/types/common/contracts/ao-process.d.ts +2 -2
- package/lib/types/common/http.d.ts +3 -2
- package/lib/types/common/index.d.ts +0 -4
- package/lib/types/common/io.d.ts +5 -4
- package/lib/types/common/logger.d.ts +10 -3
- package/lib/types/common.d.ts +1 -145
- package/lib/types/io.d.ts +28 -3
- package/lib/types/types.d.ts +0 -1
- package/lib/types/utils/arweave.d.ts +0 -5
- package/lib/types/utils/http-client.d.ts +2 -2
- package/lib/types/utils/index.d.ts +1 -2
- package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +4 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +8 -13
- package/lib/cjs/arns-service.js +0 -2
- package/lib/cjs/common/ant-ao.js +0 -297
- package/lib/cjs/common/ar-io.js +0 -741
- package/lib/cjs/common/contracts/remote-contract.js +0 -55
- package/lib/cjs/common/contracts/warp-contract.js +0 -176
- package/lib/cjs/common/warp.js +0 -25
- package/lib/cjs/utils/graphql/index.js +0 -34
- package/lib/cjs/utils/graphql/smartweave.js +0 -309
- package/lib/cjs/utils/smartweave.js +0 -58
- package/lib/esm/arns-service.js +0 -1
- package/lib/esm/common/ant-ao.js +0 -292
- package/lib/esm/common/ar-io.js +0 -735
- package/lib/esm/common/contracts/remote-contract.js +0 -51
- package/lib/esm/common/contracts/warp-contract.js +0 -172
- package/lib/esm/common/warp.js +0 -22
- package/lib/esm/utils/graphql/index.js +0 -18
- package/lib/esm/utils/graphql/smartweave.js +0 -303
- package/lib/esm/utils/smartweave.js +0 -50
- package/lib/types/arns-service.d.ts +0 -23
- package/lib/types/common/ant-ao.d.ts +0 -194
- package/lib/types/common/ar-io.d.ts +0 -551
- package/lib/types/common/contracts/remote-contract.d.ts +0 -38
- package/lib/types/common/contracts/warp-contract.d.ts +0 -43
- package/lib/types/common/warp.d.ts +0 -1
- package/lib/types/utils/graphql/index.d.ts +0 -18
- package/lib/types/utils/graphql/smartweave.d.ts +0 -47
- package/lib/types/utils/smartweave.d.ts +0 -41
package/lib/cjs/common/io.js
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.IOWriteable = exports.IOReadable = exports.IO = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
9
|
-
*
|
|
10
|
-
* This program is free software: you can redistribute it and/or modify
|
|
11
|
-
* it under the terms of the GNU Affero General Public License as published by
|
|
12
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
13
|
-
* (at your option) any later version.
|
|
14
|
-
*
|
|
15
|
-
* This program is distributed in the hope that it will be useful,
|
|
16
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
-
* GNU Affero General Public License for more details.
|
|
19
|
-
*
|
|
20
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
21
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
-
*/
|
|
23
|
-
const arweave_1 = __importDefault(require("arweave"));
|
|
24
4
|
const constants_js_1 = require("../constants.js");
|
|
25
5
|
const io_js_1 = require("../io.js");
|
|
6
|
+
const arweave_js_1 = require("./arweave.js");
|
|
26
7
|
const ao_process_js_1 = require("./contracts/ao-process.js");
|
|
27
8
|
const error_js_1 = require("./error.js");
|
|
28
|
-
const logger_js_1 = require("./logger.js");
|
|
29
9
|
class IO {
|
|
30
10
|
static init(config) {
|
|
31
11
|
if (config && config.signer) {
|
|
@@ -42,7 +22,7 @@ exports.IO = IO;
|
|
|
42
22
|
class IOReadable {
|
|
43
23
|
process;
|
|
44
24
|
arweave;
|
|
45
|
-
constructor(config, arweave =
|
|
25
|
+
constructor(config, arweave = arweave_js_1.defaultArweave) {
|
|
46
26
|
if (!config) {
|
|
47
27
|
this.process = new ao_process_js_1.AOProcess({
|
|
48
28
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
@@ -54,9 +34,6 @@ class IOReadable {
|
|
|
54
34
|
else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
|
|
55
35
|
this.process = new ao_process_js_1.AOProcess({
|
|
56
36
|
processId: config.processId,
|
|
57
|
-
logger: new logger_js_1.DefaultLogger({
|
|
58
|
-
level: 'info',
|
|
59
|
-
}),
|
|
60
37
|
});
|
|
61
38
|
}
|
|
62
39
|
else {
|
|
@@ -127,9 +104,17 @@ class IOReadable {
|
|
|
127
104
|
],
|
|
128
105
|
});
|
|
129
106
|
}
|
|
130
|
-
async getArNSRecords() {
|
|
107
|
+
async getArNSRecords(pageParams) {
|
|
108
|
+
const allTags = [
|
|
109
|
+
{ name: 'Action', value: 'Paginated-Records' },
|
|
110
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
111
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
112
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
113
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
114
|
+
];
|
|
115
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
131
116
|
return this.process.read({
|
|
132
|
-
tags:
|
|
117
|
+
tags: prunedTags,
|
|
133
118
|
});
|
|
134
119
|
}
|
|
135
120
|
async getArNSReservedNames() {
|
|
@@ -153,9 +138,17 @@ class IOReadable {
|
|
|
153
138
|
],
|
|
154
139
|
});
|
|
155
140
|
}
|
|
156
|
-
async getBalances() {
|
|
141
|
+
async getBalances(pageParams) {
|
|
142
|
+
const allTags = [
|
|
143
|
+
{ name: 'Action', value: 'Paginated-Balances' },
|
|
144
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
145
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
146
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
147
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
148
|
+
];
|
|
149
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
157
150
|
return this.process.read({
|
|
158
|
-
tags:
|
|
151
|
+
tags: prunedTags,
|
|
159
152
|
});
|
|
160
153
|
}
|
|
161
154
|
async getGateway({ address, }) {
|
|
@@ -166,9 +159,17 @@ class IOReadable {
|
|
|
166
159
|
],
|
|
167
160
|
});
|
|
168
161
|
}
|
|
169
|
-
async getGateways() {
|
|
162
|
+
async getGateways(pageParams) {
|
|
163
|
+
const allTags = [
|
|
164
|
+
{ name: 'Action', value: 'Paginated-Gateways' },
|
|
165
|
+
{ name: 'Cursor', value: pageParams?.cursor?.toString() },
|
|
166
|
+
{ name: 'Limit', value: pageParams?.limit?.toString() },
|
|
167
|
+
{ name: 'Sort-By', value: pageParams?.sortBy },
|
|
168
|
+
{ name: 'Sort-Order', value: pageParams?.sortOrder },
|
|
169
|
+
];
|
|
170
|
+
const prunedTags = allTags.filter((tag) => tag.value !== undefined);
|
|
170
171
|
return this.process.read({
|
|
171
|
-
tags:
|
|
172
|
+
tags: prunedTags,
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
async getCurrentEpoch() {
|
|
@@ -436,6 +437,13 @@ class IOWriteable extends IOReadable {
|
|
|
436
437
|
tags: prunedTags,
|
|
437
438
|
});
|
|
438
439
|
}
|
|
440
|
+
async leaveNetwork(options) {
|
|
441
|
+
const { tags = [] } = options || {};
|
|
442
|
+
return this.process.send({
|
|
443
|
+
signer: this.signer,
|
|
444
|
+
tags: [...tags, { name: 'Action', value: 'Leave-Network' }],
|
|
445
|
+
});
|
|
446
|
+
}
|
|
439
447
|
async updateGatewaySettings({ allowDelegatedStaking, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }, options) {
|
|
440
448
|
const { tags = [] } = options || {};
|
|
441
449
|
const allTags = [
|
package/lib/cjs/common/logger.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.Logger = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
9
6
|
*
|
|
@@ -20,49 +17,64 @@ exports.DefaultLogger = void 0;
|
|
|
20
17
|
* You should have received a copy of the GNU Affero General Public License
|
|
21
18
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22
19
|
*/
|
|
23
|
-
const
|
|
20
|
+
const winston_1 = require("winston");
|
|
24
21
|
const version_js_1 = require("../version.js");
|
|
25
|
-
class
|
|
22
|
+
class Logger {
|
|
26
23
|
logger;
|
|
27
24
|
silent = false;
|
|
25
|
+
static default = new Logger();
|
|
28
26
|
constructor({ level = 'info', } = {}) {
|
|
29
27
|
if (level === 'none') {
|
|
30
28
|
this.silent = true;
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
|
-
this.logger =
|
|
31
|
+
this.logger = (0, winston_1.createLogger)({
|
|
34
32
|
level,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
silent: this.silent,
|
|
34
|
+
defaultMeta: {
|
|
35
|
+
name: 'ar-io-sdk',
|
|
36
|
+
version: version_js_1.version,
|
|
37
|
+
},
|
|
38
|
+
format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.json()),
|
|
38
39
|
});
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
if (typeof window !== 'undefined') {
|
|
43
|
+
this.logger = console;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.logger.add(new winston_1.transports.Console({
|
|
47
|
+
format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.json()),
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
51
|
info(message, ...args) {
|
|
41
52
|
if (this.silent)
|
|
42
53
|
return;
|
|
43
|
-
this.logger.info(...args
|
|
54
|
+
this.logger.info(message, ...args);
|
|
44
55
|
}
|
|
45
56
|
warn(message, ...args) {
|
|
46
57
|
if (this.silent)
|
|
47
58
|
return;
|
|
48
|
-
this.logger.warn(...args
|
|
59
|
+
this.logger.warn(message, ...args);
|
|
49
60
|
}
|
|
50
61
|
error(message, ...args) {
|
|
51
62
|
if (this.silent)
|
|
52
63
|
return;
|
|
53
|
-
this.logger.error(...args
|
|
64
|
+
this.logger.error(message, ...args);
|
|
54
65
|
}
|
|
55
66
|
debug(message, ...args) {
|
|
56
67
|
if (this.silent)
|
|
57
68
|
return;
|
|
58
|
-
this.logger.debug(...args
|
|
69
|
+
this.logger.debug(message, ...args);
|
|
59
70
|
}
|
|
60
71
|
setLogLevel(level) {
|
|
61
|
-
if (
|
|
62
|
-
this.silent =
|
|
63
|
-
|
|
72
|
+
if ('silent' in this.logger) {
|
|
73
|
+
this.logger.silent = level === 'none';
|
|
74
|
+
}
|
|
75
|
+
if ('level' in this.logger) {
|
|
76
|
+
this.logger.level = level;
|
|
64
77
|
}
|
|
65
|
-
this.logger.level(level);
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
|
-
exports.
|
|
80
|
+
exports.Logger = Logger;
|
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("./arns-service.js"), exports);
|
|
34
33
|
__exportStar(require("./contract-state.js"), exports);
|
|
35
34
|
__exportStar(require("./common.js"), exports);
|
|
36
35
|
__exportStar(require("./token.js"), exports);
|
package/lib/cjs/utils/arweave.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isBlockHeight = exports.validateArweaveId = void 0;
|
|
4
4
|
const constants_js_1 = require("../constants.js");
|
|
5
5
|
const validateArweaveId = (id) => {
|
|
6
6
|
return constants_js_1.ARWEAVE_TX_REGEX.test(id);
|
|
@@ -10,17 +10,3 @@ function isBlockHeight(height) {
|
|
|
10
10
|
return height !== undefined && !isNaN(parseInt(height.toString()));
|
|
11
11
|
}
|
|
12
12
|
exports.isBlockHeight = isBlockHeight;
|
|
13
|
-
const isTransaction = (tx) => {
|
|
14
|
-
const requiredTxKeys = ['id', 'owner', 'tags', 'signature'];
|
|
15
|
-
return requiredTxKeys.every((key) => key in tx);
|
|
16
|
-
};
|
|
17
|
-
exports.isTransaction = isTransaction;
|
|
18
|
-
function tagsToObject(tags) {
|
|
19
|
-
return tags.reduce((decodedTags, tag) => {
|
|
20
|
-
const key = tag.get('name', { decode: true, string: true });
|
|
21
|
-
const value = tag.get('value', { decode: true, string: true });
|
|
22
|
-
decodedTags[key] = value;
|
|
23
|
-
return decodedTags;
|
|
24
|
-
}, {});
|
|
25
|
-
}
|
|
26
|
-
exports.tagsToObject = tagsToObject;
|
|
@@ -24,7 +24,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
24
24
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
25
25
|
const logger_js_1 = require("../common/logger.js");
|
|
26
26
|
const version_js_1 = require("../version.js");
|
|
27
|
-
const createAxiosInstance = ({ axiosConfig = {}, logger =
|
|
27
|
+
const createAxiosInstance = ({ axiosConfig = {}, logger = logger_js_1.Logger.default, retryConfig = {
|
|
28
28
|
retries: 5,
|
|
29
29
|
retryDelay: axios_retry_1.default.exponentialDelay,
|
|
30
30
|
retryCondition: (error) => axios_retry_1.default.isRetryableError(error),
|
package/lib/cjs/utils/index.js
CHANGED
|
@@ -32,7 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
*/
|
|
33
33
|
__exportStar(require("./arweave.js"), exports);
|
|
34
34
|
__exportStar(require("./http-client.js"), exports);
|
|
35
|
-
__exportStar(require("./smartweave.js"), exports);
|
|
36
|
-
__exportStar(require("./graphql/index.js"), exports);
|
|
37
35
|
__exportStar(require("./ao.js"), exports);
|
|
38
36
|
__exportStar(require("./json.js"), exports);
|
|
37
|
+
__exportStar(require("./processes.js"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
3
|
+
exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -19,19 +19,20 @@ exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
|
|
|
19
19
|
*/
|
|
20
20
|
const eventemitter3_1 = require("eventemitter3");
|
|
21
21
|
const plimit_lit_1 = require("plimit-lit");
|
|
22
|
-
const ant_js_1 = require("
|
|
23
|
-
const io_js_1 = require("
|
|
24
|
-
const constants_js_1 = require("
|
|
22
|
+
const ant_js_1 = require("../common/ant.js");
|
|
23
|
+
const io_js_1 = require("../common/io.js");
|
|
24
|
+
const constants_js_1 = require("../constants.js");
|
|
25
25
|
const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
|
|
26
26
|
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
27
27
|
}), }) => {
|
|
28
28
|
const throttle = (0, plimit_lit_1.pLimit)(50);
|
|
29
29
|
// get the record names of the registry - TODO: this may need to be paginated
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const records = await (0, exports.fetchAllArNSRecords)({
|
|
31
|
+
contract: contract,
|
|
32
|
+
});
|
|
33
|
+
const uniqueContractProcessIds = Object.values(records)
|
|
33
34
|
.filter((record) => record.processId !== undefined)
|
|
34
|
-
.map((record) => record.processId)
|
|
35
|
+
.map((record) => record.processId);
|
|
35
36
|
// check the contract owner and controllers
|
|
36
37
|
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
37
38
|
const ant = ant_js_1.ANT.init({
|
|
@@ -80,10 +81,12 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
80
81
|
}
|
|
81
82
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
82
83
|
const uniqueContractProcessIds = {};
|
|
83
|
-
await timeout(this.timeoutMs, this.contract
|
|
84
|
+
await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract }))
|
|
85
|
+
.catch((e) => {
|
|
84
86
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
85
87
|
return {};
|
|
86
|
-
})
|
|
88
|
+
})
|
|
89
|
+
.then((records) => {
|
|
87
90
|
if (!records)
|
|
88
91
|
return;
|
|
89
92
|
Object.entries(records).forEach(([name, record]) => {
|
|
@@ -125,3 +128,25 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
exports.ArNSEventEmitter = ArNSEventEmitter;
|
|
131
|
+
const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
|
|
132
|
+
processId: constants_js_1.IO_TESTNET_PROCESS_ID,
|
|
133
|
+
}), }) => {
|
|
134
|
+
let cursor;
|
|
135
|
+
const records = {};
|
|
136
|
+
do {
|
|
137
|
+
const pageResult = await contract.getArNSRecords({ cursor }).catch((e) => {
|
|
138
|
+
console.error(`Error getting ArNS records: ${e}`);
|
|
139
|
+
return undefined;
|
|
140
|
+
});
|
|
141
|
+
if (!pageResult) {
|
|
142
|
+
return {};
|
|
143
|
+
}
|
|
144
|
+
pageResult.items.forEach((record) => {
|
|
145
|
+
const { name, ...recordDetails } = record;
|
|
146
|
+
records[name] = recordDetails;
|
|
147
|
+
});
|
|
148
|
+
cursor = pageResult.nextCursor;
|
|
149
|
+
} while (cursor !== undefined);
|
|
150
|
+
return records;
|
|
151
|
+
};
|
|
152
|
+
exports.fetchAllArNSRecords = fetchAllArNSRecords;
|
package/lib/cjs/version.js
CHANGED