@ar.io/sdk 3.24.0 → 4.0.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 +757 -589
- package/lib/esm/cli/cli.js +188 -152
- package/lib/esm/cli/commands/antCommands.js +23 -58
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
- package/lib/esm/cli/commands/escrowCommands.js +227 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +140 -23
- package/lib/esm/cli/commands/pruneCommands.js +154 -0
- package/lib/esm/cli/commands/readCommands.js +22 -3
- package/lib/esm/cli/commands/transfer.js +6 -6
- package/lib/esm/cli/options.js +124 -58
- package/lib/esm/cli/utils.js +303 -175
- package/lib/esm/common/ant-registry.js +17 -143
- package/lib/esm/common/ant.js +44 -1167
- package/lib/esm/common/faucet.js +17 -6
- package/lib/esm/common/index.js +0 -4
- package/lib/esm/common/io.js +25 -1412
- package/lib/esm/constants.js +13 -19
- package/lib/esm/solana/ant-readable.js +724 -0
- package/lib/esm/solana/ant-registry-readable.js +133 -0
- package/lib/esm/solana/ant-registry-writeable.js +472 -0
- package/lib/esm/solana/ant-writeable.js +384 -0
- package/lib/esm/solana/ata.js +70 -0
- package/lib/esm/solana/canonical-message.js +128 -0
- package/lib/esm/solana/clusters.js +111 -0
- package/lib/esm/solana/constants.js +146 -0
- package/lib/esm/solana/delegation-math.js +112 -0
- package/lib/esm/solana/deserialize.js +711 -0
- package/lib/esm/solana/escrow.js +839 -0
- package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
- package/lib/esm/solana/funding-plan.js +699 -0
- package/lib/esm/solana/index.js +126 -0
- package/lib/esm/solana/instruction.js +39 -0
- package/lib/esm/solana/io-readable.js +2182 -0
- package/lib/esm/solana/io-writeable.js +3196 -0
- package/lib/esm/solana/json-rpc.js +90 -0
- package/lib/esm/solana/metadata.js +81 -0
- package/lib/esm/solana/mpl-core.js +192 -0
- package/lib/esm/solana/pda.js +332 -0
- package/lib/esm/solana/predict-prescribed-observers.js +110 -0
- package/lib/esm/solana/retry.js +117 -0
- package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
- package/lib/esm/solana/send.js +372 -0
- package/lib/esm/solana/spawn-ant.js +224 -0
- package/lib/esm/solana/types.js +1 -0
- package/lib/esm/types/ant.js +27 -15
- package/lib/esm/types/io.js +8 -11
- package/lib/esm/utils/ant.js +0 -63
- package/lib/esm/utils/index.js +0 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +5 -13
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
- package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
- package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
- package/lib/types/cli/commands/readCommands.d.ts +27 -22
- package/lib/types/cli/commands/transfer.d.ts +9 -9
- package/lib/types/cli/options.d.ts +76 -21
- package/lib/types/cli/types.d.ts +11 -13
- package/lib/types/cli/utils.d.ts +71 -31
- package/lib/types/common/ant-registry.d.ts +49 -47
- package/lib/types/common/ant.d.ts +54 -539
- package/lib/types/common/faucet.d.ts +20 -8
- package/lib/types/common/index.d.ts +0 -3
- package/lib/types/common/io.d.ts +66 -258
- package/lib/types/constants.d.ts +11 -18
- package/lib/types/solana/ant-readable.d.ts +180 -0
- package/lib/types/solana/ant-registry-readable.d.ts +105 -0
- package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
- package/lib/types/solana/ant-writeable.d.ts +177 -0
- package/lib/types/solana/ata.d.ts +44 -0
- package/lib/types/solana/canonical-message.d.ts +121 -0
- package/lib/types/solana/clusters.d.ts +109 -0
- package/lib/types/solana/constants.d.ts +119 -0
- package/lib/types/solana/delegation-math.d.ts +45 -0
- package/lib/types/solana/deserialize.d.ts +262 -0
- package/lib/types/solana/escrow.d.ts +480 -0
- package/lib/types/solana/events.d.ts +38 -0
- package/lib/types/solana/funding-plan.d.ts +225 -0
- package/lib/types/solana/index.d.ts +87 -0
- package/lib/types/solana/instruction.d.ts +39 -0
- package/lib/types/solana/io-readable.d.ts +499 -0
- package/lib/types/solana/io-writeable.d.ts +893 -0
- package/lib/types/solana/json-rpc.d.ts +47 -0
- package/lib/types/solana/metadata.d.ts +84 -0
- package/lib/types/solana/mpl-core.d.ts +120 -0
- package/lib/types/solana/pda.d.ts +95 -0
- package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
- package/lib/types/solana/retry.d.ts +62 -0
- package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
- package/lib/types/solana/send.d.ts +94 -0
- package/lib/types/solana/spawn-ant.d.ts +145 -0
- package/lib/types/solana/types.d.ts +82 -0
- package/lib/types/types/ant-registry.d.ts +43 -4
- package/lib/types/types/ant.d.ts +114 -96
- package/lib/types/types/common.d.ts +18 -74
- package/lib/types/types/faucet.d.ts +2 -2
- package/lib/types/types/io.d.ts +244 -158
- package/lib/types/types/token.d.ts +0 -12
- package/lib/types/utils/ant.d.ts +1 -12
- package/lib/types/utils/index.d.ts +0 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +36 -33
- package/lib/cjs/cli/cli.js +0 -822
- package/lib/cjs/cli/commands/antCommands.js +0 -113
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
- package/lib/cjs/cli/commands/readCommands.js +0 -215
- package/lib/cjs/cli/commands/transfer.js +0 -159
- package/lib/cjs/cli/options.js +0 -470
- package/lib/cjs/cli/types.js +0 -2
- package/lib/cjs/cli/utils.js +0 -639
- package/lib/cjs/common/ant-registry.js +0 -155
- package/lib/cjs/common/ant-versions.js +0 -93
- package/lib/cjs/common/ant.js +0 -1182
- package/lib/cjs/common/arweave.js +0 -27
- package/lib/cjs/common/contracts/ao-process.js +0 -224
- package/lib/cjs/common/error.js +0 -64
- package/lib/cjs/common/faucet.js +0 -150
- package/lib/cjs/common/hyperbeam/hb.js +0 -173
- package/lib/cjs/common/index.js +0 -42
- package/lib/cjs/common/io.js +0 -1423
- package/lib/cjs/common/logger.js +0 -83
- package/lib/cjs/common/loggers/winston.js +0 -68
- package/lib/cjs/common/marketplace.js +0 -731
- package/lib/cjs/common/turbo.js +0 -223
- package/lib/cjs/constants.js +0 -41
- package/lib/cjs/node/index.js +0 -39
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/types/ant-registry.js +0 -2
- package/lib/cjs/types/ant.js +0 -168
- package/lib/cjs/types/common.js +0 -2
- package/lib/cjs/types/faucet.js +0 -2
- package/lib/cjs/types/index.js +0 -37
- package/lib/cjs/types/io.js +0 -51
- package/lib/cjs/types/token.js +0 -116
- package/lib/cjs/utils/ant.js +0 -108
- package/lib/cjs/utils/ao.js +0 -432
- package/lib/cjs/utils/arweave.js +0 -285
- package/lib/cjs/utils/base64.js +0 -62
- package/lib/cjs/utils/hash.js +0 -56
- package/lib/cjs/utils/index.js +0 -38
- package/lib/cjs/utils/processes.js +0 -173
- package/lib/cjs/utils/random.js +0 -30
- package/lib/cjs/utils/schema.js +0 -15
- package/lib/cjs/utils/url.js +0 -37
- package/lib/cjs/version.js +0 -20
- package/lib/cjs/web/index.js +0 -41
- package/lib/esm/common/ant-versions.js +0 -87
- package/lib/esm/common/arweave.js +0 -21
- package/lib/esm/common/contracts/ao-process.js +0 -220
- package/lib/esm/common/hyperbeam/hb.js +0 -169
- package/lib/esm/common/marketplace.js +0 -724
- package/lib/esm/common/turbo.js +0 -215
- package/lib/esm/node/index.js +0 -20
- package/lib/esm/utils/ao.js +0 -420
- package/lib/esm/utils/arweave.js +0 -271
- package/lib/esm/utils/processes.js +0 -167
- package/lib/esm/web/index.js +0 -20
- package/lib/types/common/ant-versions.d.ts +0 -39
- package/lib/types/common/arweave.d.ts +0 -17
- package/lib/types/common/contracts/ao-process.d.ts +0 -47
- package/lib/types/common/hyperbeam/hb.d.ts +0 -88
- package/lib/types/common/marketplace.d.ts +0 -568
- package/lib/types/common/turbo.d.ts +0 -61
- package/lib/types/node/index.d.ts +0 -20
- package/lib/types/utils/ao.d.ts +0 -80
- package/lib/types/utils/arweave.d.ts +0 -79
- package/lib/types/utils/processes.d.ts +0 -39
- package/lib/types/web/index.d.ts +0 -20
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
exports.defaultArweave = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License.
|
|
12
|
-
* You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
const index_js_1 = __importDefault(require("arweave/node/index.js"));
|
|
23
|
-
exports.defaultArweave = index_js_1.default.init({
|
|
24
|
-
host: 'arweave.net',
|
|
25
|
-
port: 443,
|
|
26
|
-
protocol: 'https',
|
|
27
|
-
});
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AOProcess = 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 aoconnect_1 = require("@permaweb/aoconnect");
|
|
20
|
-
const base64_js_1 = require("../../utils/base64.js");
|
|
21
|
-
const index_js_1 = require("../../utils/index.js");
|
|
22
|
-
const json_js_1 = require("../../utils/json.js");
|
|
23
|
-
const version_js_1 = require("../../version.js");
|
|
24
|
-
const error_js_1 = require("../error.js");
|
|
25
|
-
const logger_js_1 = require("../logger.js");
|
|
26
|
-
class AOProcess {
|
|
27
|
-
logger;
|
|
28
|
-
ao;
|
|
29
|
-
processId;
|
|
30
|
-
constructor({ processId, ao = (0, aoconnect_1.connect)({
|
|
31
|
-
MODE: 'legacy',
|
|
32
|
-
}), logger = logger_js_1.Logger.default, }) {
|
|
33
|
-
this.processId = processId;
|
|
34
|
-
this.logger = logger;
|
|
35
|
-
this.ao = ao;
|
|
36
|
-
}
|
|
37
|
-
isMessageDataEmpty(messageData) {
|
|
38
|
-
return (messageData === undefined ||
|
|
39
|
-
messageData === 'null' || // This is what the CU returns for 'nil' values that are json.encoded
|
|
40
|
-
messageData === '' ||
|
|
41
|
-
messageData === null);
|
|
42
|
-
}
|
|
43
|
-
async read({ tags, retries = 3, fromAddress, select, }) {
|
|
44
|
-
this.logger.debug(`Evaluating read interaction on process`, {
|
|
45
|
-
tags,
|
|
46
|
-
processId: this.processId,
|
|
47
|
-
});
|
|
48
|
-
// map tags to inputs
|
|
49
|
-
const dryRunInput = {
|
|
50
|
-
process: this.processId,
|
|
51
|
-
tags,
|
|
52
|
-
};
|
|
53
|
-
if (fromAddress !== undefined) {
|
|
54
|
-
dryRunInput['Owner'] = fromAddress;
|
|
55
|
-
}
|
|
56
|
-
let attempts = 0;
|
|
57
|
-
let result = undefined;
|
|
58
|
-
while (attempts < retries) {
|
|
59
|
-
try {
|
|
60
|
-
result = await this.ao.dryrun(dryRunInput);
|
|
61
|
-
// break on successful return of result
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
attempts++;
|
|
66
|
-
this.logger.debug(`Read attempt ${attempts} failed`, {
|
|
67
|
-
error: error?.message,
|
|
68
|
-
stack: error?.stack,
|
|
69
|
-
tags,
|
|
70
|
-
processId: this.processId,
|
|
71
|
-
});
|
|
72
|
-
if (attempts >= retries) {
|
|
73
|
-
this.logger.debug(`Maximum read attempts exceeded`, {
|
|
74
|
-
error: error?.message,
|
|
75
|
-
stack: error?.stack,
|
|
76
|
-
tags,
|
|
77
|
-
processId: this.processId,
|
|
78
|
-
ao: JSON.stringify(this.ao),
|
|
79
|
-
});
|
|
80
|
-
throw new Error(`Failed to evaluate dry-run on process ${this.processId}.`, {
|
|
81
|
-
cause: error,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
// exponential backoff
|
|
85
|
-
await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (result === undefined) {
|
|
89
|
-
throw new Error('Unexpected error when evaluating read interaction');
|
|
90
|
-
}
|
|
91
|
-
this.logger.debug(`Read interaction result`, {
|
|
92
|
-
result,
|
|
93
|
-
processId: this.processId,
|
|
94
|
-
});
|
|
95
|
-
const error = (0, index_js_1.errorMessageFromOutput)(result);
|
|
96
|
-
if (error !== undefined) {
|
|
97
|
-
throw new Error(error);
|
|
98
|
-
}
|
|
99
|
-
if (result.Messages === undefined || result.Messages.length === 0) {
|
|
100
|
-
this.logger.debug(`Empty result - process ${this.processId} does not support provided action.`, {
|
|
101
|
-
result,
|
|
102
|
-
tags,
|
|
103
|
-
processId: this.processId,
|
|
104
|
-
});
|
|
105
|
-
throw new Error(result.message ||
|
|
106
|
-
`Process ${this.processId} did not return a valid response. Response: ${JSON.stringify(result)}`);
|
|
107
|
-
}
|
|
108
|
-
const messageData = select
|
|
109
|
-
? result.Messages.find(select)?.Data
|
|
110
|
-
: result.Messages?.[0]?.Data;
|
|
111
|
-
// return undefined if no data is returned
|
|
112
|
-
if (this.isMessageDataEmpty(messageData)) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
const response = (0, json_js_1.safeDecode)(messageData);
|
|
116
|
-
return response;
|
|
117
|
-
}
|
|
118
|
-
async send({ tags, data, signer, retries = 3, select, }) {
|
|
119
|
-
let messageId;
|
|
120
|
-
const anchor = (0, base64_js_1.getRandomText)(32); // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
|
|
121
|
-
try {
|
|
122
|
-
this.logger.debug(`Evaluating send interaction on contract`, {
|
|
123
|
-
tags,
|
|
124
|
-
data,
|
|
125
|
-
processId: this.processId,
|
|
126
|
-
});
|
|
127
|
-
/**
|
|
128
|
-
* DO NOT retry messaging if a message was already sent.
|
|
129
|
-
* This could result in a double entry-like condition when sending tokens for example.
|
|
130
|
-
* If the message fails to send we will throw an error and the caller can retry.
|
|
131
|
-
*/
|
|
132
|
-
messageId = await this.ao.message({
|
|
133
|
-
process: this.processId,
|
|
134
|
-
tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
|
|
135
|
-
data,
|
|
136
|
-
signer,
|
|
137
|
-
anchor,
|
|
138
|
-
});
|
|
139
|
-
this.logger.debug(`Sent message to process`, {
|
|
140
|
-
messageId,
|
|
141
|
-
processId: this.processId,
|
|
142
|
-
anchor,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
this.logger.debug('Error sending message to process', {
|
|
147
|
-
error: error?.message,
|
|
148
|
-
stack: error?.stack,
|
|
149
|
-
processId: this.processId,
|
|
150
|
-
tags,
|
|
151
|
-
});
|
|
152
|
-
// throw the error so it can be handled by the caller
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
if (messageId === undefined) {
|
|
156
|
-
throw new Error('Failed to send message to process.');
|
|
157
|
-
}
|
|
158
|
-
// get the result of the message before returning, using retries to handle network errors/new process delays
|
|
159
|
-
let result = undefined;
|
|
160
|
-
let attempts = 0;
|
|
161
|
-
while (attempts < retries) {
|
|
162
|
-
try {
|
|
163
|
-
result = await this.ao.result({
|
|
164
|
-
message: messageId,
|
|
165
|
-
process: this.processId,
|
|
166
|
-
});
|
|
167
|
-
this.logger.debug('Message result', {
|
|
168
|
-
result,
|
|
169
|
-
messageId,
|
|
170
|
-
processId: this.processId,
|
|
171
|
-
});
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
attempts++;
|
|
176
|
-
this.logger.debug('Retrying send interaction', {
|
|
177
|
-
attempts,
|
|
178
|
-
retries,
|
|
179
|
-
error: error?.message,
|
|
180
|
-
processId: this.processId,
|
|
181
|
-
});
|
|
182
|
-
if (attempts >= retries) {
|
|
183
|
-
this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but result was not returned. Review transactions for more details.`, {
|
|
184
|
-
error: error?.message,
|
|
185
|
-
stack: error?.stack,
|
|
186
|
-
tags,
|
|
187
|
-
processId: this.processId,
|
|
188
|
-
messageId,
|
|
189
|
-
});
|
|
190
|
-
return { id: messageId };
|
|
191
|
-
}
|
|
192
|
-
// exponential backoff
|
|
193
|
-
await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (result === undefined) {
|
|
197
|
-
this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but the result was not returned. Review transactions for more details.`, {
|
|
198
|
-
tags,
|
|
199
|
-
processId: this.processId,
|
|
200
|
-
messageId,
|
|
201
|
-
});
|
|
202
|
-
return { id: messageId };
|
|
203
|
-
}
|
|
204
|
-
const error = (0, index_js_1.errorMessageFromOutput)(result);
|
|
205
|
-
if (error !== undefined) {
|
|
206
|
-
throw new error_js_1.WriteInteractionError(error);
|
|
207
|
-
}
|
|
208
|
-
// check if there are any Messages in the output
|
|
209
|
-
if (result.Messages?.length === 0 || result.Messages === undefined) {
|
|
210
|
-
return { id: messageId };
|
|
211
|
-
}
|
|
212
|
-
if (this.isMessageDataEmpty(result.Messages[0].Data)) {
|
|
213
|
-
return { id: messageId };
|
|
214
|
-
}
|
|
215
|
-
const resultData = (0, json_js_1.safeDecode)(select ? result.Messages.find(select)?.Data : result.Messages[0].Data);
|
|
216
|
-
this.logger.debug('Message result data', {
|
|
217
|
-
resultData,
|
|
218
|
-
messageId,
|
|
219
|
-
processId: this.processId,
|
|
220
|
-
});
|
|
221
|
-
return { id: messageId, result: resultData };
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.AOProcess = AOProcess;
|
package/lib/cjs/common/error.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbortError = exports.InvalidProcessConfigurationError = exports.InvalidContractConfigurationError = exports.InvalidSignerError = exports.WriteInteractionError = exports.UnknownError = exports.FailedRequestError = exports.BadRequest = exports.NotFound = exports.BaseError = 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
|
-
class BaseError extends Error {
|
|
20
|
-
constructor(message) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.name = this.constructor.name;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.BaseError = BaseError;
|
|
26
|
-
class NotFound extends BaseError {
|
|
27
|
-
}
|
|
28
|
-
exports.NotFound = NotFound;
|
|
29
|
-
class BadRequest extends BaseError {
|
|
30
|
-
}
|
|
31
|
-
exports.BadRequest = BadRequest;
|
|
32
|
-
class FailedRequestError extends BaseError {
|
|
33
|
-
constructor(status, message) {
|
|
34
|
-
super(`Failed request: ${status}: ${message}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.FailedRequestError = FailedRequestError;
|
|
38
|
-
class UnknownError extends BaseError {
|
|
39
|
-
}
|
|
40
|
-
exports.UnknownError = UnknownError;
|
|
41
|
-
class WriteInteractionError extends BaseError {
|
|
42
|
-
}
|
|
43
|
-
exports.WriteInteractionError = WriteInteractionError;
|
|
44
|
-
class InvalidSignerError extends BaseError {
|
|
45
|
-
constructor() {
|
|
46
|
-
super('Invalid signer. Please provide a valid signer to interact with the contract.');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.InvalidSignerError = InvalidSignerError;
|
|
50
|
-
class InvalidContractConfigurationError extends BaseError {
|
|
51
|
-
constructor() {
|
|
52
|
-
super('Invalid contract configuration');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.InvalidContractConfigurationError = InvalidContractConfigurationError;
|
|
56
|
-
class InvalidProcessConfigurationError extends BaseError {
|
|
57
|
-
constructor() {
|
|
58
|
-
super('Invalid process configuration');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.InvalidProcessConfigurationError = InvalidProcessConfigurationError;
|
|
62
|
-
class AbortError extends BaseError {
|
|
63
|
-
}
|
|
64
|
-
exports.AbortError = AbortError;
|
package/lib/cjs/common/faucet.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ARIOTokenFaucet = void 0;
|
|
4
|
-
exports.createFaucet = createFaucet;
|
|
5
|
-
const DEFAULT_FAUCET_API_URL = 'https://faucet.ario.permaweb.services';
|
|
6
|
-
/**
|
|
7
|
-
* Creates a proxy object that implements the TokenFaucet interface. It wraps the ARIOReadable instance and adds methods for claiming tokens from the faucet API.
|
|
8
|
-
* @param arioInstance - The ARIOReadable instance
|
|
9
|
-
* @param faucetApiUrl - The URL of the faucet API
|
|
10
|
-
* @returns A proxy object that implements the TokenFaucet interface
|
|
11
|
-
*/
|
|
12
|
-
function createFaucet({ arioInstance, faucetApiUrl = DEFAULT_FAUCET_API_URL, }) {
|
|
13
|
-
const faucet = new ARIOTokenFaucet({
|
|
14
|
-
faucetUrl: faucetApiUrl,
|
|
15
|
-
processId: arioInstance.process.processId,
|
|
16
|
-
});
|
|
17
|
-
const proxy = new Proxy(arioInstance, {
|
|
18
|
-
get(target, prop) {
|
|
19
|
-
if (prop === 'faucet') {
|
|
20
|
-
return faucet;
|
|
21
|
-
}
|
|
22
|
-
if (prop in target) {
|
|
23
|
-
const result = target[prop];
|
|
24
|
-
if (typeof result === 'function') {
|
|
25
|
-
return result.bind(target);
|
|
26
|
-
}
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
return proxy;
|
|
33
|
-
}
|
|
34
|
-
class ARIOTokenFaucet {
|
|
35
|
-
faucetUrl;
|
|
36
|
-
processId;
|
|
37
|
-
constructor({ faucetUrl, processId, }) {
|
|
38
|
-
this.faucetUrl = faucetUrl;
|
|
39
|
-
this.processId = processId;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Returns the captcha URL for a process. The captcha is used to verify a human is solving the captcha. Once you have a captcha response, you can use it to request an authorization token via the requestAuthToken method.
|
|
43
|
-
* @returns The captcha URL for a process
|
|
44
|
-
*/
|
|
45
|
-
async captchaUrl() {
|
|
46
|
-
const res = await fetch(`${this.faucetUrl}/api/captcha/url?process-id=${this.processId}`, {
|
|
47
|
-
method: 'GET',
|
|
48
|
-
});
|
|
49
|
-
if (!res.ok) {
|
|
50
|
-
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
51
|
-
throw new Error(body.error);
|
|
52
|
-
}
|
|
53
|
-
const data = (await res.json());
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Claim tokens for a process using a captcha response. This method is used to synchronously claim tokens for a process using a captcha response.
|
|
58
|
-
* @param captchaResponse - The captcha response
|
|
59
|
-
* @param recipient - The recipient address
|
|
60
|
-
* @param quantity - The quantity of tokens to claim
|
|
61
|
-
* @returns The claim id and success status
|
|
62
|
-
*/
|
|
63
|
-
async claimWithCaptchaResponse({ captchaResponse, recipient, quantity, }) {
|
|
64
|
-
const res = await fetch(`${this.faucetUrl}/api/claim/sync`, {
|
|
65
|
-
method: 'POST',
|
|
66
|
-
headers: { 'Content-Type': 'application/json' },
|
|
67
|
-
body: JSON.stringify({
|
|
68
|
-
processId: this.processId,
|
|
69
|
-
recipient,
|
|
70
|
-
quantity,
|
|
71
|
-
captchaResponse,
|
|
72
|
-
}),
|
|
73
|
-
});
|
|
74
|
-
if (!res.ok) {
|
|
75
|
-
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
76
|
-
throw new Error(body.error);
|
|
77
|
-
}
|
|
78
|
-
const data = (await res.json());
|
|
79
|
-
return data;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Requests an authorization token for a process. The captcha response is used to verify a human is solving the captcha. Once you have an authorization token, you can use it to claim tokens from the faucet via the claimWithAuthToken method.
|
|
83
|
-
* @param captchaResponse - The captcha response
|
|
84
|
-
* @returns The status of the request, the authorization token, and the expiration time
|
|
85
|
-
*/
|
|
86
|
-
async requestAuthToken({ captchaResponse, }) {
|
|
87
|
-
const res = await fetch(`${this.faucetUrl}/api/captcha/verify`, {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
headers: { 'Content-Type': 'application/json' },
|
|
90
|
-
body: JSON.stringify({
|
|
91
|
-
processId: this.processId,
|
|
92
|
-
captchaResponse,
|
|
93
|
-
}),
|
|
94
|
-
});
|
|
95
|
-
if (!res.ok) {
|
|
96
|
-
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
97
|
-
throw new Error(body.error);
|
|
98
|
-
}
|
|
99
|
-
const data = (await res.json());
|
|
100
|
-
return data;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Transfers tokens from the faucet wallet to a recipient address using an authorization token. To request an authorization token, solve the captcha from the captchaUrl method.
|
|
104
|
-
* @param authToken - The authorization token
|
|
105
|
-
* @param recipient - The recipient address
|
|
106
|
-
* @param quantity - The quantity of tokens to claim
|
|
107
|
-
* @returns The message id of the transfer and success status
|
|
108
|
-
*/
|
|
109
|
-
async claimWithAuthToken({ authToken, recipient, quantity, }) {
|
|
110
|
-
const res = await fetch(`${this.faucetUrl}/api/claim/async`, {
|
|
111
|
-
method: 'POST',
|
|
112
|
-
headers: {
|
|
113
|
-
'Content-Type': 'application/json',
|
|
114
|
-
Authorization: `Bearer ${authToken}`,
|
|
115
|
-
},
|
|
116
|
-
body: JSON.stringify({
|
|
117
|
-
recipient,
|
|
118
|
-
qty: quantity,
|
|
119
|
-
processId: this.processId,
|
|
120
|
-
}),
|
|
121
|
-
});
|
|
122
|
-
if (!res.ok) {
|
|
123
|
-
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
124
|
-
throw new Error(body.error);
|
|
125
|
-
}
|
|
126
|
-
const data = (await res.json());
|
|
127
|
-
return data;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Verifies an authorization token is valid.
|
|
131
|
-
* @param authToken - The authorization token
|
|
132
|
-
* @returns The validity of the authorization token and the expiration time
|
|
133
|
-
*/
|
|
134
|
-
async verifyAuthToken({ authToken }) {
|
|
135
|
-
const res = await fetch(`${this.faucetUrl}/api/token/verify?process-id=${this.processId}`, {
|
|
136
|
-
method: 'GET',
|
|
137
|
-
headers: {
|
|
138
|
-
'Content-Type': 'application/json',
|
|
139
|
-
Authorization: `Bearer ${authToken}`,
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
if (!res.ok) {
|
|
143
|
-
const body = await res.json().catch(() => ({ error: res.statusText }));
|
|
144
|
-
throw new Error(body.error);
|
|
145
|
-
}
|
|
146
|
-
const data = (await res.json());
|
|
147
|
-
return data;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
exports.ARIOTokenFaucet = ARIOTokenFaucet;
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HB = void 0;
|
|
4
|
-
const logger_js_1 = require("../logger.js");
|
|
5
|
-
class HB {
|
|
6
|
-
url;
|
|
7
|
-
processId;
|
|
8
|
-
isHyperBeamCompatible;
|
|
9
|
-
checkHyperBeamPromise;
|
|
10
|
-
logger;
|
|
11
|
-
hbTimeoutMs;
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.url = config.url;
|
|
14
|
-
this.processId = config.processId;
|
|
15
|
-
this.logger = config.logger ?? logger_js_1.Logger.default;
|
|
16
|
-
this.hbTimeoutMs = config.hbTimeoutMs ?? 5000;
|
|
17
|
-
this.isHyperBeamCompatible = undefined;
|
|
18
|
-
this.checkHyperBeamPromise = this.checkHyperBeamCompatibility();
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* fetches the meta data for the process
|
|
22
|
-
*
|
|
23
|
-
* @returns The meta data for the process
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
|
|
27
|
-
* const meta = await hyperbeam.meta();
|
|
28
|
-
* console.log(meta);
|
|
29
|
-
*/
|
|
30
|
-
async meta() {
|
|
31
|
-
const url = new URL(`${this.url}/${this.processId}~process@1.0/meta`);
|
|
32
|
-
return this.fetchHyperbeamPath({
|
|
33
|
-
path: url.toString(),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* calls the process device /now function, which evaluates the current process state pulling new messages
|
|
38
|
-
* to get the latest state
|
|
39
|
-
*
|
|
40
|
-
* @param path - The path to the hb state
|
|
41
|
-
* @param json - Whether to return the result as JSON, defaults to true
|
|
42
|
-
* @returns The result of the compute operation
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
|
|
46
|
-
* const result = await hyperbeam.now({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
|
|
47
|
-
* console.log(result);
|
|
48
|
-
*/
|
|
49
|
-
async now({ path, json = false, }) {
|
|
50
|
-
return this.fetchHyperbeamPath({
|
|
51
|
-
path: `${this.url}/${this.processId}~process@1.0/now/${path}`,
|
|
52
|
-
json,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* calls the process device /compute function, which uses the currently evaluated state in the node
|
|
57
|
-
*
|
|
58
|
-
* @param path - The path to the compute resource
|
|
59
|
-
* @param json - Whether to return the result as JSON, defaults to true
|
|
60
|
-
* @returns The result of the compute operation
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* const hyperbeam = new Hyperbeam({ url: 'https://hyperbeam.ario.permaweb.services', processId: 'qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE' });
|
|
64
|
-
* const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
|
|
65
|
-
* console.log(result);
|
|
66
|
-
*/
|
|
67
|
-
async compute({ path, json = true, }) {
|
|
68
|
-
return this.fetchHyperbeamPath({
|
|
69
|
-
path: `${this.url}/${this.processId}~process@1.0/compute/${path}`,
|
|
70
|
-
json,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Checks if the process is HyperBeam compatible and caches the result.
|
|
75
|
-
*
|
|
76
|
-
* @returns {Promise<boolean>} True if the process is HyperBeam compatible, false otherwise.
|
|
77
|
-
*/
|
|
78
|
-
async checkHyperBeamCompatibility({ minSlot, } = {}) {
|
|
79
|
-
// refetch if min slot is provided
|
|
80
|
-
if (minSlot !== undefined) {
|
|
81
|
-
this.isHyperBeamCompatible = undefined;
|
|
82
|
-
this.checkHyperBeamPromise = undefined;
|
|
83
|
-
}
|
|
84
|
-
if (this.checkHyperBeamPromise !== undefined) {
|
|
85
|
-
return this.checkHyperBeamPromise;
|
|
86
|
-
}
|
|
87
|
-
if (this.isHyperBeamCompatible !== undefined) {
|
|
88
|
-
return Promise.resolve(this.isHyperBeamCompatible);
|
|
89
|
-
}
|
|
90
|
-
const result = fetch(
|
|
91
|
-
// use /now to force a refresh of the cache state, then compute when calling it for keys
|
|
92
|
-
`${this.url.toString()}/${this.processId}~process@1.0/now`, {
|
|
93
|
-
method: 'HEAD',
|
|
94
|
-
signal: AbortSignal.timeout(this.hbTimeoutMs),
|
|
95
|
-
})
|
|
96
|
-
.then(async (res) => {
|
|
97
|
-
if (res.ok) {
|
|
98
|
-
if (minSlot !== undefined) {
|
|
99
|
-
const slotRes = await this.compute({
|
|
100
|
-
path: 'at-slot',
|
|
101
|
-
json: false,
|
|
102
|
-
});
|
|
103
|
-
const slot = Number(slotRes);
|
|
104
|
-
if (slot < minSlot) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
this.isHyperBeamCompatible = true;
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
this.isHyperBeamCompatible = false;
|
|
112
|
-
return false;
|
|
113
|
-
})
|
|
114
|
-
.catch((error) => {
|
|
115
|
-
this.logger.error('Failed to check HyperBeam compatibility', {
|
|
116
|
-
cause: error,
|
|
117
|
-
});
|
|
118
|
-
this.isHyperBeamCompatible = false;
|
|
119
|
-
return false;
|
|
120
|
-
});
|
|
121
|
-
this.checkHyperBeamPromise = result;
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
async fetchHyperbeamPath({ path, json = true, }) {
|
|
125
|
-
try {
|
|
126
|
-
const url = new URL(path);
|
|
127
|
-
if (json) {
|
|
128
|
-
this.logger.debug('Fetching path as JSON', { path });
|
|
129
|
-
/**
|
|
130
|
-
* This is the (current) way to access data as json
|
|
131
|
-
* the old way is /~json@1.0/serialize path
|
|
132
|
-
*/
|
|
133
|
-
url.searchParams.set('require-codec', 'application/json');
|
|
134
|
-
url.searchParams.set('accept-bundle', 'true');
|
|
135
|
-
const res = await fetch(url);
|
|
136
|
-
if (!res.ok) {
|
|
137
|
-
throw new Error(`Failed to fetch path as JSON: ${res.statusText}`);
|
|
138
|
-
}
|
|
139
|
-
const jsonResult = await res
|
|
140
|
-
.json()
|
|
141
|
-
.then((json) => json)
|
|
142
|
-
.catch((error) => {
|
|
143
|
-
this.logger.error('Failed to parse JSON', {
|
|
144
|
-
cause: error,
|
|
145
|
-
});
|
|
146
|
-
throw new Error(`Received response but failed to parse JSON: ${error.message}`);
|
|
147
|
-
});
|
|
148
|
-
if (typeof jsonResult !== 'object' ||
|
|
149
|
-
jsonResult === null ||
|
|
150
|
-
!('body' in jsonResult)) {
|
|
151
|
-
throw new Error('Response body missing in JSON response');
|
|
152
|
-
}
|
|
153
|
-
return jsonResult.body;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
this.logger.debug('Fetching path as text', { path });
|
|
157
|
-
const res = await fetch(url);
|
|
158
|
-
if (!res.ok) {
|
|
159
|
-
throw new Error(`Failed to fetch path: ${res.statusText}`);
|
|
160
|
-
}
|
|
161
|
-
const body = await res.text();
|
|
162
|
-
return body;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
this.logger.error('Failed to fetch path as JSON', {
|
|
167
|
-
cause: error,
|
|
168
|
-
});
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
exports.HB = HB;
|
package/lib/cjs/common/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/**
|
|
18
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
19
|
-
*
|
|
20
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
-
* you may not use this file except in compliance with the License.
|
|
22
|
-
* You may obtain a copy of the License at
|
|
23
|
-
*
|
|
24
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
-
*
|
|
26
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
-
* See the License for the specific language governing permissions and
|
|
30
|
-
* limitations under the License.
|
|
31
|
-
*/
|
|
32
|
-
__exportStar(require("./error.js"), exports);
|
|
33
|
-
__exportStar(require("./logger.js"), exports);
|
|
34
|
-
__exportStar(require("./loggers/winston.js"), exports);
|
|
35
|
-
__exportStar(require("./ant.js"), exports);
|
|
36
|
-
__exportStar(require("./ant-registry.js"), exports);
|
|
37
|
-
__exportStar(require("./ant-versions.js"), exports);
|
|
38
|
-
__exportStar(require("./faucet.js"), exports);
|
|
39
|
-
__exportStar(require("./marketplace.js"), exports);
|
|
40
|
-
// ao
|
|
41
|
-
__exportStar(require("./io.js"), exports);
|
|
42
|
-
__exportStar(require("./contracts/ao-process.js"), exports);
|