@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.
Files changed (169) hide show
  1. package/README.md +757 -589
  2. package/lib/esm/cli/cli.js +188 -152
  3. package/lib/esm/cli/commands/antCommands.js +23 -58
  4. package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
  5. package/lib/esm/cli/commands/escrowCommands.js +227 -0
  6. package/lib/esm/cli/commands/gatewayWriteCommands.js +140 -23
  7. package/lib/esm/cli/commands/pruneCommands.js +154 -0
  8. package/lib/esm/cli/commands/readCommands.js +22 -3
  9. package/lib/esm/cli/commands/transfer.js +6 -6
  10. package/lib/esm/cli/options.js +124 -58
  11. package/lib/esm/cli/utils.js +303 -175
  12. package/lib/esm/common/ant-registry.js +17 -143
  13. package/lib/esm/common/ant.js +44 -1167
  14. package/lib/esm/common/faucet.js +17 -6
  15. package/lib/esm/common/index.js +0 -4
  16. package/lib/esm/common/io.js +25 -1412
  17. package/lib/esm/constants.js +13 -19
  18. package/lib/esm/solana/ant-readable.js +724 -0
  19. package/lib/esm/solana/ant-registry-readable.js +133 -0
  20. package/lib/esm/solana/ant-registry-writeable.js +472 -0
  21. package/lib/esm/solana/ant-writeable.js +384 -0
  22. package/lib/esm/solana/ata.js +70 -0
  23. package/lib/esm/solana/canonical-message.js +128 -0
  24. package/lib/esm/solana/clusters.js +111 -0
  25. package/lib/esm/solana/constants.js +146 -0
  26. package/lib/esm/solana/delegation-math.js +112 -0
  27. package/lib/esm/solana/deserialize.js +711 -0
  28. package/lib/esm/solana/escrow.js +839 -0
  29. package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
  30. package/lib/esm/solana/funding-plan.js +699 -0
  31. package/lib/esm/solana/index.js +126 -0
  32. package/lib/esm/solana/instruction.js +39 -0
  33. package/lib/esm/solana/io-readable.js +2182 -0
  34. package/lib/esm/solana/io-writeable.js +3196 -0
  35. package/lib/esm/solana/json-rpc.js +90 -0
  36. package/lib/esm/solana/metadata.js +81 -0
  37. package/lib/esm/solana/mpl-core.js +192 -0
  38. package/lib/esm/solana/pda.js +332 -0
  39. package/lib/esm/solana/predict-prescribed-observers.js +110 -0
  40. package/lib/esm/solana/retry.js +117 -0
  41. package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
  42. package/lib/esm/solana/send.js +372 -0
  43. package/lib/esm/solana/spawn-ant.js +224 -0
  44. package/lib/esm/solana/types.js +1 -0
  45. package/lib/esm/types/ant.js +27 -15
  46. package/lib/esm/types/io.js +8 -11
  47. package/lib/esm/utils/ant.js +0 -63
  48. package/lib/esm/utils/index.js +0 -3
  49. package/lib/esm/version.js +1 -1
  50. package/lib/types/cli/commands/antCommands.d.ts +5 -13
  51. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
  52. package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
  53. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
  54. package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
  55. package/lib/types/cli/commands/readCommands.d.ts +27 -22
  56. package/lib/types/cli/commands/transfer.d.ts +9 -9
  57. package/lib/types/cli/options.d.ts +76 -21
  58. package/lib/types/cli/types.d.ts +11 -13
  59. package/lib/types/cli/utils.d.ts +71 -31
  60. package/lib/types/common/ant-registry.d.ts +49 -47
  61. package/lib/types/common/ant.d.ts +54 -539
  62. package/lib/types/common/faucet.d.ts +20 -8
  63. package/lib/types/common/index.d.ts +0 -3
  64. package/lib/types/common/io.d.ts +66 -258
  65. package/lib/types/constants.d.ts +11 -18
  66. package/lib/types/solana/ant-readable.d.ts +180 -0
  67. package/lib/types/solana/ant-registry-readable.d.ts +105 -0
  68. package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
  69. package/lib/types/solana/ant-writeable.d.ts +177 -0
  70. package/lib/types/solana/ata.d.ts +44 -0
  71. package/lib/types/solana/canonical-message.d.ts +121 -0
  72. package/lib/types/solana/clusters.d.ts +109 -0
  73. package/lib/types/solana/constants.d.ts +119 -0
  74. package/lib/types/solana/delegation-math.d.ts +45 -0
  75. package/lib/types/solana/deserialize.d.ts +262 -0
  76. package/lib/types/solana/escrow.d.ts +480 -0
  77. package/lib/types/solana/events.d.ts +38 -0
  78. package/lib/types/solana/funding-plan.d.ts +225 -0
  79. package/lib/types/solana/index.d.ts +87 -0
  80. package/lib/types/solana/instruction.d.ts +39 -0
  81. package/lib/types/solana/io-readable.d.ts +499 -0
  82. package/lib/types/solana/io-writeable.d.ts +893 -0
  83. package/lib/types/solana/json-rpc.d.ts +47 -0
  84. package/lib/types/solana/metadata.d.ts +84 -0
  85. package/lib/types/solana/mpl-core.d.ts +120 -0
  86. package/lib/types/solana/pda.d.ts +95 -0
  87. package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
  88. package/lib/types/solana/retry.d.ts +62 -0
  89. package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
  90. package/lib/types/solana/send.d.ts +94 -0
  91. package/lib/types/solana/spawn-ant.d.ts +145 -0
  92. package/lib/types/solana/types.d.ts +82 -0
  93. package/lib/types/types/ant-registry.d.ts +43 -4
  94. package/lib/types/types/ant.d.ts +114 -96
  95. package/lib/types/types/common.d.ts +18 -74
  96. package/lib/types/types/faucet.d.ts +2 -2
  97. package/lib/types/types/io.d.ts +244 -158
  98. package/lib/types/types/token.d.ts +0 -12
  99. package/lib/types/utils/ant.d.ts +1 -12
  100. package/lib/types/utils/index.d.ts +0 -3
  101. package/lib/types/version.d.ts +1 -1
  102. package/package.json +36 -33
  103. package/lib/cjs/cli/cli.js +0 -822
  104. package/lib/cjs/cli/commands/antCommands.js +0 -113
  105. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
  106. package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
  107. package/lib/cjs/cli/commands/readCommands.js +0 -215
  108. package/lib/cjs/cli/commands/transfer.js +0 -159
  109. package/lib/cjs/cli/options.js +0 -470
  110. package/lib/cjs/cli/types.js +0 -2
  111. package/lib/cjs/cli/utils.js +0 -639
  112. package/lib/cjs/common/ant-registry.js +0 -155
  113. package/lib/cjs/common/ant-versions.js +0 -93
  114. package/lib/cjs/common/ant.js +0 -1182
  115. package/lib/cjs/common/arweave.js +0 -27
  116. package/lib/cjs/common/contracts/ao-process.js +0 -224
  117. package/lib/cjs/common/error.js +0 -64
  118. package/lib/cjs/common/faucet.js +0 -150
  119. package/lib/cjs/common/hyperbeam/hb.js +0 -173
  120. package/lib/cjs/common/index.js +0 -42
  121. package/lib/cjs/common/io.js +0 -1423
  122. package/lib/cjs/common/logger.js +0 -83
  123. package/lib/cjs/common/loggers/winston.js +0 -68
  124. package/lib/cjs/common/marketplace.js +0 -731
  125. package/lib/cjs/common/turbo.js +0 -223
  126. package/lib/cjs/constants.js +0 -41
  127. package/lib/cjs/node/index.js +0 -39
  128. package/lib/cjs/package.json +0 -1
  129. package/lib/cjs/types/ant-registry.js +0 -2
  130. package/lib/cjs/types/ant.js +0 -168
  131. package/lib/cjs/types/common.js +0 -2
  132. package/lib/cjs/types/faucet.js +0 -2
  133. package/lib/cjs/types/index.js +0 -37
  134. package/lib/cjs/types/io.js +0 -51
  135. package/lib/cjs/types/token.js +0 -116
  136. package/lib/cjs/utils/ant.js +0 -108
  137. package/lib/cjs/utils/ao.js +0 -432
  138. package/lib/cjs/utils/arweave.js +0 -285
  139. package/lib/cjs/utils/base64.js +0 -62
  140. package/lib/cjs/utils/hash.js +0 -56
  141. package/lib/cjs/utils/index.js +0 -38
  142. package/lib/cjs/utils/processes.js +0 -173
  143. package/lib/cjs/utils/random.js +0 -30
  144. package/lib/cjs/utils/schema.js +0 -15
  145. package/lib/cjs/utils/url.js +0 -37
  146. package/lib/cjs/version.js +0 -20
  147. package/lib/cjs/web/index.js +0 -41
  148. package/lib/esm/common/ant-versions.js +0 -87
  149. package/lib/esm/common/arweave.js +0 -21
  150. package/lib/esm/common/contracts/ao-process.js +0 -220
  151. package/lib/esm/common/hyperbeam/hb.js +0 -169
  152. package/lib/esm/common/marketplace.js +0 -724
  153. package/lib/esm/common/turbo.js +0 -215
  154. package/lib/esm/node/index.js +0 -20
  155. package/lib/esm/utils/ao.js +0 -420
  156. package/lib/esm/utils/arweave.js +0 -271
  157. package/lib/esm/utils/processes.js +0 -167
  158. package/lib/esm/web/index.js +0 -20
  159. package/lib/types/common/ant-versions.d.ts +0 -39
  160. package/lib/types/common/arweave.d.ts +0 -17
  161. package/lib/types/common/contracts/ao-process.d.ts +0 -47
  162. package/lib/types/common/hyperbeam/hb.d.ts +0 -88
  163. package/lib/types/common/marketplace.d.ts +0 -568
  164. package/lib/types/common/turbo.d.ts +0 -61
  165. package/lib/types/node/index.d.ts +0 -20
  166. package/lib/types/utils/ao.d.ts +0 -80
  167. package/lib/types/utils/arweave.d.ts +0 -79
  168. package/lib/types/utils/processes.d.ts +0 -39
  169. package/lib/types/web/index.d.ts +0 -20
@@ -1,1182 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AoANTWriteable = exports.AoANTReadable = exports.ANT = 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 zod_1 = require("zod");
20
- const constants_js_1 = require("../constants.js");
21
- const constants_js_2 = require("../constants.js");
22
- const ant_js_1 = require("../types/ant.js");
23
- const index_js_1 = require("../types/index.js");
24
- const ant_js_2 = require("../utils/ant.js");
25
- const ao_js_1 = require("../utils/ao.js");
26
- const schema_js_1 = require("../utils/schema.js");
27
- const ant_versions_js_1 = require("./ant-versions.js");
28
- const index_js_2 = require("./index.js");
29
- class ANT {
30
- /**
31
- * Versions of ANTs according to the ANT registry.
32
- *
33
- * Needs to be wrapped in a getter to avoid circular dependency issues.
34
- */
35
- static get versions() {
36
- return ant_versions_js_1.ANTVersions.init();
37
- }
38
- /**
39
- * Spawn a new ANT.
40
- */
41
- static spawn = ao_js_1.spawnANT;
42
- /**
43
- * Fork an ANT to a new process.
44
- *
45
- * @param config
46
- */
47
- static fork = ao_js_1.forkANT;
48
- /**
49
- * Upgrade an ANT by forking it to the latest version and reassigning names.
50
- *
51
- *
52
- * @param config Configuration object for the upgrade process
53
- * @returns Promise resolving to the forked process ID and successfully reassigned names
54
- */
55
- static async upgrade({ signer, antProcessId, reassignAffiliatedNames = true, names, arioProcessId = constants_js_1.ARIO_MAINNET_PROCESS_ID, antRegistryId = constants_js_2.ANT_REGISTRY_ID, ao, logger = index_js_2.Logger.default, skipVersionCheck = false, onSigningProgress, hyperbeamUrl, }) {
56
- // run time check if names is not empty but reassignAffiliatedNames it true, throw
57
- if (names !== undefined &&
58
- names.length > 0 &&
59
- reassignAffiliatedNames !== undefined &&
60
- reassignAffiliatedNames !== false) {
61
- throw new Error('Cannot reassign all affiliated names and provide specific names');
62
- }
63
- let namesToReassign = names !== undefined && names.length > 0 ? new Set(names) : new Set();
64
- // use reassignAffiliatedNames if names is empty
65
- const shouldReassignAll = names === undefined || names.length === 0
66
- ? (reassignAffiliatedNames ?? true)
67
- : false;
68
- const ario = index_js_2.ARIO.init({
69
- process: new index_js_2.AOProcess({ processId: arioProcessId, ao }),
70
- hyperbeamUrl,
71
- });
72
- const getAllAffiliatedNames = async () => {
73
- let cursor = undefined;
74
- let hasMore = true;
75
- const affiliatedNames = new Set();
76
- while (hasMore) {
77
- const page = await ario.getArNSRecords({
78
- filters: { processId: antProcessId },
79
- cursor,
80
- limit: 100,
81
- });
82
- page.items.forEach((r) => {
83
- affiliatedNames.add(r.name);
84
- });
85
- cursor = page.nextCursor;
86
- hasMore = page.hasMore;
87
- }
88
- return affiliatedNames;
89
- };
90
- // get all the affiliated names if reassign all affiliated names is true
91
- if (shouldReassignAll) {
92
- onSigningProgress?.('fetching-affiliated-names', {
93
- arioProcessId,
94
- antProcessId,
95
- });
96
- namesToReassign = await getAllAffiliatedNames();
97
- }
98
- else {
99
- if (names === undefined || names.length === 0) {
100
- throw new Error('Names are required when reassignAffiliatedNames is false.');
101
- }
102
- onSigningProgress?.('validating-names', {
103
- arioProcessId,
104
- antProcessId,
105
- names,
106
- });
107
- // confirm all names are affiliated with the ANT
108
- const allAffiliatedNames = await getAllAffiliatedNames();
109
- if (!names.every((name) => allAffiliatedNames.has(name))) {
110
- // find any that are not affiliated with the ANT
111
- const notAffiliatedNames = names.filter((name) => !allAffiliatedNames.has(name));
112
- throw new Error(`All names must be affiliated with the ANT on the provided ARIO process. The following names are not affiliated to this ANT: ${notAffiliatedNames.join(', ')}`);
113
- }
114
- }
115
- // if names is empty and reassign all affiliated names is false, throw an error
116
- if (namesToReassign.size === 0) {
117
- throw new Error('There are no names to reassign for this ANT.');
118
- }
119
- const existingAntProcess = ANT.init({
120
- process: new index_js_2.AOProcess({
121
- processId: antProcessId,
122
- ao,
123
- logger,
124
- }),
125
- hyperbeamUrl,
126
- signer,
127
- });
128
- if (!skipVersionCheck) {
129
- onSigningProgress?.('checking-version', {
130
- antProcessId,
131
- antRegistryId,
132
- });
133
- const isLatestVersion = await existingAntProcess.isLatestVersion({
134
- antRegistryId,
135
- });
136
- if (isLatestVersion) {
137
- return {
138
- forkedProcessId: antProcessId,
139
- reassignedNames: {},
140
- failedReassignedNames: {},
141
- };
142
- }
143
- }
144
- const forkedProcessId = await ANT.fork({
145
- signer,
146
- antProcessId,
147
- ao,
148
- logger,
149
- antRegistryId,
150
- onSigningProgress,
151
- hyperbeamUrl,
152
- });
153
- // we could parallelize this, but then signing progress would be harder to track
154
- const reassignedNames = {};
155
- const failedReassignedNames = {};
156
- for (const name of namesToReassign) {
157
- let reassignmentResult;
158
- try {
159
- onSigningProgress?.('reassigning-name', {
160
- name,
161
- arioProcessId,
162
- antProcessId: forkedProcessId,
163
- });
164
- reassignmentResult = await existingAntProcess.reassignName({
165
- name,
166
- arioProcessId,
167
- antProcessId: forkedProcessId,
168
- });
169
- onSigningProgress?.('successfully-reassigned-name', {
170
- name,
171
- arioProcessId,
172
- antProcessId: forkedProcessId,
173
- });
174
- reassignedNames[name] = reassignmentResult;
175
- }
176
- catch (error) {
177
- logger.error(`Failed to reassign name ${name}:`, { error });
178
- onSigningProgress?.('failed-to-reassign-name', {
179
- name,
180
- arioProcessId,
181
- antProcessId: forkedProcessId,
182
- error,
183
- });
184
- // Continue with other names rather than failing completely
185
- failedReassignedNames[name] = {
186
- id: reassignmentResult?.id,
187
- error,
188
- };
189
- }
190
- }
191
- return { forkedProcessId, reassignedNames, failedReassignedNames };
192
- }
193
- static init(config) {
194
- if (config !== undefined && 'signer' in config) {
195
- return new AoANTWriteable(config);
196
- }
197
- return new AoANTReadable(config);
198
- }
199
- }
200
- exports.ANT = ANT;
201
- class AoANTReadable {
202
- process;
203
- processId;
204
- hyperbeamUrl;
205
- strict;
206
- checkHyperBeamPromise;
207
- moduleId;
208
- moduleIdPromise;
209
- logger = index_js_2.Logger.default;
210
- constructor(config) {
211
- this.strict = config.strict || false;
212
- if ((0, index_js_1.isProcessConfiguration)(config)) {
213
- this.process = config.process;
214
- }
215
- else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
216
- this.process = new index_js_2.AOProcess({
217
- processId: config.processId,
218
- });
219
- }
220
- else {
221
- throw new index_js_2.InvalidContractConfigurationError();
222
- }
223
- this.processId = this.process.processId;
224
- // only use hyperbeam if the client has provided a hyperbeamUrl
225
- // this will avoid overwhelming the HyperBeam node with requests
226
- // as we shift using HyperBEAM for all ANT operations
227
- if (config.hyperbeamUrl !== undefined) {
228
- this.hyperbeamUrl = new URL(config.hyperbeamUrl);
229
- this.logger.debug(`Using HyperBEAM node for process ${this.processId}`, {
230
- hyperbeamUrl: this.hyperbeamUrl,
231
- });
232
- }
233
- }
234
- /**
235
- * Check if the process is HyperBeam compatible. If so, we'll use the HyperBeam node to fetch the state.
236
- *
237
- * @returns {Promise<boolean>} True if the process is HyperBeam compatible, false otherwise.
238
- */
239
- checkHyperBeamCompatibility() {
240
- if (this.hyperbeamUrl === undefined) {
241
- return Promise.resolve(false);
242
- }
243
- if (this.checkHyperBeamPromise !== undefined) {
244
- return this.checkHyperBeamPromise;
245
- }
246
- this.checkHyperBeamPromise = fetch(
247
- // use /now to force a refresh of the cache state, then compute when calling it for keys
248
- `${this.hyperbeamUrl.toString()}${this.processId}~process@1.0/now/cache`, {
249
- method: 'HEAD',
250
- signal: AbortSignal.timeout(5000), // 5 second timeout
251
- })
252
- .then((res) => {
253
- if (res.ok) {
254
- return true;
255
- }
256
- return false;
257
- })
258
- .catch((error) => {
259
- this.logger.debug('Failed to check HyperBeam compatibility', {
260
- cause: error,
261
- });
262
- return false;
263
- });
264
- return this.checkHyperBeamPromise;
265
- }
266
- async getState({ strict } = { strict: this.strict }) {
267
- if (await this.checkHyperBeamCompatibility()) {
268
- let retries = 0;
269
- while (retries < 3) {
270
- try {
271
- const res = await fetch(`${this.hyperbeamUrl}${this.processId}~process@1.0/compute/cache/serialize~json@1.0`, {
272
- method: 'GET',
273
- redirect: 'follow',
274
- mode: 'cors',
275
- headers: {
276
- 'Content-Type': 'application/json',
277
- },
278
- });
279
- if (res.status !== 200) {
280
- throw new Error(`Failed to fetch ant state: ${res?.statusText ?? 'Unknown error'}`);
281
- }
282
- const unnormalizedState = (await res.json());
283
- if (!(0, ant_js_2.isHyperBeamANTState)(unnormalizedState)) {
284
- // don't retry if the state is bad, fallback to the CU
285
- break;
286
- }
287
- // normalize and return the state
288
- return (0, ant_js_2.convertHyperBeamStateToAoANTState)(unnormalizedState);
289
- }
290
- catch (error) {
291
- this.logger.error(`Failed to fetch process state from HyperBEAM (attempt ${retries + 1} / 3)`, {
292
- cause: error,
293
- });
294
- retries++;
295
- await new Promise((resolve) => setTimeout(resolve, 1000 * retries ** 2));
296
- }
297
- }
298
- }
299
- const tags = [{ name: 'Action', value: 'State' }];
300
- const res = await this.process.read({
301
- tags,
302
- });
303
- if (strict) {
304
- (0, schema_js_1.parseSchemaResult)(ant_js_1.AntStateSchema.passthrough().and(zod_1.z.object({
305
- Records: zod_1.z.record(zod_1.z.string(), ant_js_1.AntRecordSchema.passthrough()),
306
- })), res);
307
- }
308
- return res;
309
- }
310
- async getInfo({ strict } = { strict: this.strict }) {
311
- if (await this.checkHyperBeamCompatibility()) {
312
- const state = await this.getState();
313
- return {
314
- Name: state.Name,
315
- Ticker: state.Ticker,
316
- Description: state.Description,
317
- Keywords: state.Keywords,
318
- Denomination: state.Denomination.toString(),
319
- Owner: state.Owner,
320
- Logo: state.Logo,
321
- 'Total-Supply': state.TotalSupply.toString(),
322
- Handlers: [], // TODO: support for handler in patched state
323
- };
324
- }
325
- const tags = [{ name: 'Action', value: 'Info' }];
326
- const info = await this.process.read({
327
- tags,
328
- });
329
- if (strict) {
330
- (0, schema_js_1.parseSchemaResult)(ant_js_1.AntInfoSchema.passthrough(), info);
331
- }
332
- return info;
333
- }
334
- /**
335
- * Returns the TX ID of the logo set for the ANT.
336
- */
337
- async getLogo() {
338
- const info = await this.getInfo();
339
- return info.Logo;
340
- }
341
- /**
342
- * Gets the module ID of the current ANT process by querying its spawn transaction tags.
343
- * Results are cached after the first successful fetch.
344
- *
345
- * @param graphqlUrl The GraphQL endpoint URL (defaults to Arweave's GraphQL endpoint)
346
- * @param retries Number of retry attempts (defaults to 3)
347
- * @returns Promise<string> The module ID used to spawn this ANT process
348
- * @example
349
- * ```ts
350
- * const moduleId = await ant.getModuleId();
351
- * console.log(`ANT was spawned with module: ${moduleId}`);
352
- * ```
353
- */
354
- async getModuleId({
355
- // TODO: we could use wayfinder for this
356
- graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
357
- // Return cached result if available
358
- if (this.moduleId !== undefined) {
359
- this.logger.debug('Returning cached module ID', {
360
- processId: this.processId,
361
- moduleId: this.moduleId,
362
- });
363
- return this.moduleId;
364
- }
365
- // Return existing promise if already in flight
366
- if (this.moduleIdPromise) {
367
- this.logger.debug('Returning in-flight module ID promise', {
368
- processId: this.processId,
369
- });
370
- return this.moduleIdPromise;
371
- }
372
- // Create and cache the promise to prevent multiple concurrent requests
373
- this.moduleIdPromise = this.fetchModuleId({ graphqlUrl, retries });
374
- try {
375
- const moduleId = await this.moduleIdPromise;
376
- this.moduleId = moduleId;
377
- this.logger.debug('Successfully fetched and cached module ID', {
378
- processId: this.processId,
379
- moduleId,
380
- });
381
- return moduleId;
382
- }
383
- finally {
384
- // Clear the promise so future calls can retry if this one failed
385
- this.moduleIdPromise = undefined;
386
- }
387
- }
388
- /**
389
- * Internal method to fetch the module ID from GraphQL.
390
- *
391
- * TODO: this could be more like get process headers/metadata and fetch additional details.
392
- *
393
- * It seems like module is the only relevant one, but scheduler and authority are also available.
394
- */
395
- async fetchModuleId({ graphqlUrl, retries, }) {
396
- const query = JSON.stringify({
397
- query: `
398
- query {
399
- transactions(
400
- ids: ["${this.processId}"]
401
- first: 1
402
- ) {
403
- edges {
404
- node {
405
- tags {
406
- name
407
- value
408
- }
409
- }
410
- }
411
- }
412
- }
413
- `,
414
- });
415
- for (let i = 0; i < retries; i++) {
416
- try {
417
- const response = await fetch(graphqlUrl, {
418
- method: 'POST',
419
- body: query,
420
- headers: {
421
- 'Content-Type': 'application/json',
422
- },
423
- signal: AbortSignal.timeout(10_000), // 10 second timeout
424
- });
425
- if (!response.ok) {
426
- throw new Error(`GraphQL request failed: ${response.statusText}`);
427
- }
428
- const result = (await response.json());
429
- if (result.errors) {
430
- throw new Error(`GraphQL errors: ${result.errors.map((e) => e.message).join(', ')}`);
431
- }
432
- const edges = result.data?.transactions?.edges;
433
- if (!edges || edges.length === 0) {
434
- throw new Error(`No transaction found for process ID: ${this.processId}`);
435
- }
436
- const tags = edges[0].node.tags;
437
- const moduleTag = tags.find((tag) => tag.name === 'Module');
438
- if (!moduleTag) {
439
- throw new Error(`No Module tag found for process ID: ${this.processId}`);
440
- }
441
- return moduleTag.value;
442
- }
443
- catch (error) {
444
- if (i === retries - 1) {
445
- // Final attempt failed
446
- this.logger.error('Failed to get ANT module ID after all retries:', {
447
- error,
448
- });
449
- throw new Error(`Unable to determine module ID for ANT process ${this.processId}: ${error.message}`);
450
- }
451
- // Exponential backoff
452
- await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
453
- }
454
- }
455
- throw new Error(`Unexpected error getting module ID for process ${this.processId}`);
456
- }
457
- /**
458
- * Gets the version string of the current ANT by matching its module ID
459
- * with versions from the ANT registry.
460
- *
461
- * @param antRegistryId The ANT registry process ID (defaults to mainnet registry)
462
- * @param graphqlUrl The GraphQL endpoint URL for getModuleId (defaults to Arweave's GraphQL endpoint)
463
- * @param retries Number of retry attempts for getModuleId (defaults to 3)
464
- * @returns Promise<string> The version string (e.g., "1.0.15") or "unknown" if not found
465
- * @example
466
- * ```ts
467
- * const version = await ant.getVersion();
468
- * console.log(`ANT is running version: ${version}`);
469
- * ```
470
- */
471
- async getVersion({ antRegistryId = constants_js_2.ANT_REGISTRY_ID, graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
472
- // Get the current ANT's module ID
473
- const currentModuleId = await this.getModuleId({ graphqlUrl, retries });
474
- // Get all versions from the ANT registry
475
- const antVersions = ant_versions_js_1.ANTVersions.init({
476
- process: new index_js_2.AOProcess({
477
- processId: antRegistryId,
478
- ao: this.process.ao,
479
- }),
480
- });
481
- const versions = await antVersions.getANTVersions();
482
- // Find the version that matches our module ID
483
- for (const [version, versionInfo] of Object.entries(versions)) {
484
- if (versionInfo.moduleId === currentModuleId) {
485
- this.logger.debug('Found matching ANT version', {
486
- processId: this.processId,
487
- moduleId: currentModuleId,
488
- version,
489
- });
490
- return version;
491
- }
492
- }
493
- const versionForModuleId = Object.entries(versions)
494
- .map(([version, versionInfo]) => ({
495
- version,
496
- ...versionInfo,
497
- }))
498
- .find((obj) => obj.moduleId === currentModuleId);
499
- return versionForModuleId?.version ?? 'unknown';
500
- }
501
- /**
502
- * Checks if the current ANT version is the latest according to the ANT registry.
503
- *
504
- * @param antRegistryId Optional ANT registry process ID. Defaults to mainnet ANT registry.
505
- * @param graphqlUrl Optional GraphQL endpoint. Defaults to https://arweave.net/graphql.
506
- * @param retries Optional number of retries for fetching module ID. Defaults to 3.
507
- * @returns {Promise<boolean>} True if current ANT version is the latest, false otherwise.
508
- */
509
- async isLatestVersion({ antRegistryId = constants_js_2.ANT_REGISTRY_ID, graphqlUrl = 'https://arweave.net/graphql', retries = 3, } = {}) {
510
- // Get the current ANT's version
511
- const currentVersion = await this.getVersion({
512
- antRegistryId,
513
- graphqlUrl,
514
- retries,
515
- });
516
- // Get all versions from the ANT registry
517
- const antVersions = ant_versions_js_1.ANTVersions.init({
518
- process: new index_js_2.AOProcess({
519
- processId: antRegistryId,
520
- ao: this.process.ao,
521
- }),
522
- });
523
- const latestVersion = await antVersions.getLatestANTVersion();
524
- return currentVersion === latestVersion.version;
525
- }
526
- /**
527
- * @param undername @type {string} The domain name.
528
- * @returns {Promise<ANTRecord>} The record of the undername domain.
529
- * @example
530
- * Get the current record
531
- * ```ts
532
- * ant.getRecord({ undername: "john" });
533
- * ```
534
- */
535
- async getRecord({ undername }, { strict } = { strict: this.strict }) {
536
- if (await this.checkHyperBeamCompatibility()) {
537
- const records = await this.getRecords();
538
- const cachedRecord = records[undername];
539
- // if the record is not found, throw an error
540
- if (cachedRecord === undefined) {
541
- throw new Error('Record not found');
542
- }
543
- return cachedRecord;
544
- }
545
- // TODO: use sortedANTRecords to get priority on all records, even if ANT does not have a priority set
546
- const record = await this.process.read({
547
- tags: [
548
- { name: 'Action', value: 'Record' },
549
- { name: 'Sub-Domain', value: undername },
550
- ],
551
- });
552
- if (strict)
553
- (0, schema_js_1.parseSchemaResult)(ant_js_1.AntRecordSchema.passthrough(), record);
554
- return record;
555
- }
556
- /**
557
- * @returns {Promise<SortedANTRecords>} All the undernames managed by the ANT.
558
- * @example
559
- * Get the current records
560
- * ```ts
561
- * ant.getRecords();
562
- * ````
563
- */
564
- async getRecords({ strict } = { strict: this.strict }) {
565
- if (await this.checkHyperBeamCompatibility()) {
566
- const state = await this.getState();
567
- return (0, ant_js_2.sortANTRecords)(state.Records);
568
- }
569
- const tags = [{ name: 'Action', value: 'Records' }];
570
- const records = await this.process.read({
571
- tags,
572
- });
573
- if (strict)
574
- (0, schema_js_1.parseSchemaResult)(ant_js_1.AntRecordsSchema, records);
575
- // sort the records using the deterministic sort used by ar-io nodes
576
- return (0, ant_js_2.sortANTRecords)(records);
577
- }
578
- /**
579
- * @returns {Promise<string>} The owner of the ANT.
580
- * @example
581
- * Get the current owner
582
- * ```ts
583
- * ant.getOwner();
584
- * ```
585
- */
586
- async getOwner({ strict } = { strict: this.strict }) {
587
- if (await this.checkHyperBeamCompatibility()) {
588
- const state = await this.getState();
589
- return state.Owner;
590
- }
591
- const info = await this.getInfo({ strict });
592
- return info.Owner;
593
- }
594
- /**
595
- * @returns {Promise<string[]>} The controllers of the ANT.
596
- * @example
597
- * Get the controllers of the ANT.
598
- * ```ts
599
- * ant.getControllers();
600
- * ```
601
- */
602
- async getControllers({ strict } = { strict: this.strict }) {
603
- if (await this.checkHyperBeamCompatibility()) {
604
- const state = await this.getState();
605
- return state.Controllers;
606
- }
607
- const tags = [{ name: 'Action', value: 'Controllers' }];
608
- const controllers = await this.process.read({
609
- tags,
610
- });
611
- if (strict)
612
- (0, schema_js_1.parseSchemaResult)(ant_js_1.AntControllersSchema, controllers);
613
- return controllers;
614
- }
615
- /**
616
- * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
617
- * @example
618
- * Get the current name
619
- * ```ts
620
- * ant.getName();
621
- * ```
622
- */
623
- async getName({ strict } = { strict: this.strict }) {
624
- if (await this.checkHyperBeamCompatibility()) {
625
- const state = await this.getState();
626
- return state.Name;
627
- }
628
- const info = await this.getInfo({ strict });
629
- return info.Name;
630
- }
631
- /**
632
- * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
633
- * @example
634
- * The current ticker of the ANT.
635
- * ```ts
636
- * ant.getTicker();
637
- * ```
638
- */
639
- async getTicker({ strict } = { strict: this.strict }) {
640
- if (await this.checkHyperBeamCompatibility()) {
641
- const state = await this.getState();
642
- return state.Ticker;
643
- }
644
- const info = await this.getInfo({ strict });
645
- return info.Ticker;
646
- }
647
- /**
648
- * @returns {Promise<Record<WalletAddress, number>>} The balances of the ANT
649
- * @example
650
- * The current balances of the ANT.
651
- * ```ts
652
- * ant.getBalances();
653
- * ```
654
- */
655
- async getBalances({ strict } = { strict: this.strict }) {
656
- const state = await this.getState();
657
- const balances = state.Balances;
658
- if (strict)
659
- (0, schema_js_1.parseSchemaResult)(ant_js_1.AntBalancesSchema, balances);
660
- return balances;
661
- }
662
- /**
663
- * @param address @type {string} The address of the account you want the balance of.
664
- * @returns {Promise<number>} The balance of the provided address
665
- * @example
666
- * The current balance of the address.
667
- * ```ts
668
- * ant.getBalance({ address });
669
- * ```
670
- */
671
- async getBalance({ address }, { strict } = { strict: this.strict }) {
672
- if (await this.checkHyperBeamCompatibility()) {
673
- const balances = await this.getBalances();
674
- return balances[address] ?? 0;
675
- }
676
- const tags = [
677
- { name: 'Action', value: 'Balance' },
678
- { name: 'Recipient', value: address },
679
- ];
680
- const balance = await this.process.read({
681
- tags,
682
- });
683
- if (strict)
684
- (0, schema_js_1.parseSchemaResult)(zod_1.z.number(), balance);
685
- return balance;
686
- }
687
- /**
688
- * @returns {Promise<AoANTHandler[]>} The handlers of the ANT.
689
- * @example
690
- * Get the handlers of the ANT.
691
- * ```ts
692
- * const handlers = await ant.getHandlers();
693
- * ```
694
- */
695
- async getHandlers() {
696
- if (await this.checkHyperBeamCompatibility()) {
697
- throw new Error('Handlers are not supported on HyperBeam');
698
- }
699
- const info = await this.getInfo();
700
- return (info.Handlers ?? info.HandlerNames);
701
- }
702
- }
703
- exports.AoANTReadable = AoANTReadable;
704
- class AoANTWriteable extends AoANTReadable {
705
- signer;
706
- constructor({ signer, ...config }) {
707
- super(config);
708
- this.signer = (0, ao_js_1.createAoSigner)(signer);
709
- }
710
- /**
711
- * @param target @type {string} The address of the account you want to transfer the ANT to.
712
- * @param removeControllers @type {boolean} Whether to remove the controllers of the ANT. Default is true.
713
- * @example
714
- * ```ts
715
- * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk", removeControllers: false }); // will not remove the controllers of the ANT and just transfer ownership
716
- * ```
717
- * @returns {Promise<AoMessageResult>} The result of the interaction.
718
- * @example
719
- * ```ts
720
- * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
721
- * ```
722
- */
723
- async transfer({ target, removeControllers = true, }, options) {
724
- const tags = [
725
- ...(options?.tags ?? []),
726
- { name: 'Action', value: 'Transfer' },
727
- { name: 'Recipient', value: target },
728
- {
729
- name: 'Remove-Controllers',
730
- value: removeControllers ? 'true' : 'false',
731
- },
732
- ];
733
- return this.process.send({
734
- tags,
735
- signer: this.signer,
736
- });
737
- }
738
- /**
739
- * @param controller @type {string} The address of the account you want to set as a controller.
740
- * @returns {Promise<AoMessageResult>} The result of the interaction.
741
- * @example
742
- * ```ts
743
- * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
744
- * ```
745
- */
746
- async addController({ controller, }, options) {
747
- const tags = [
748
- ...(options?.tags ?? []),
749
- { name: 'Action', value: 'Add-Controller' },
750
- { name: 'Controller', value: controller },
751
- ];
752
- return this.process.send({
753
- tags,
754
- signer: this.signer,
755
- });
756
- }
757
- /**
758
- * @param controller @type {string} The address of the account you want to remove from the controllers list
759
- * @returns {Promise<AoMessageResult>} The result of the interaction.
760
- * @example
761
- * ```ts
762
- * ant.removeController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
763
- * ```
764
- */
765
- async removeController({ controller, }, options) {
766
- const tags = [
767
- ...(options?.tags ?? []),
768
- { name: 'Action', value: 'Remove-Controller' },
769
- { name: 'Controller', value: controller },
770
- ];
771
- return this.process.send({
772
- tags,
773
- signer: this.signer,
774
- });
775
- }
776
- /**
777
- * Sets the transactionId and ttlSeconds of a record (for updating the top level name, use undername "@".)
778
- *
779
- * @deprecated Use setUndernameRecord instead for undernames, and setBaseNameRecord instead for the top level name (e.g. "@")
780
- * @param undername @type {string} The record you want to set the transactionId and ttlSeconds of.
781
- * @param transactionId @type {string} The transactionId of the record.
782
- * @param ttlSeconds @type {number} The time to live of the record.
783
- * @param owner @type {string} Optional owner address for the record.
784
- * @param displayName @type {string} Optional display name for the record.
785
- * @param logo @type {string} Optional logo transaction ID for the record.
786
- * @param description @type {string} Optional description for the record.
787
- * @param keywords @type {string[]} Optional keywords array for the record.
788
- * @returns {Promise<AoMessageResult>} The result of the interaction.
789
- */
790
- async setRecord({ undername, transactionId, ttlSeconds, owner, displayName, logo, description, keywords, }, options) {
791
- const tags = [
792
- ...(options?.tags ?? []),
793
- { name: 'Action', value: 'Set-Record' },
794
- { name: 'Sub-Domain', value: undername },
795
- { name: 'Transaction-Id', value: transactionId },
796
- { name: 'TTL-Seconds', value: ttlSeconds.toString() },
797
- { name: 'Record-Owner', value: owner },
798
- { name: 'Display-Name', value: displayName },
799
- { name: 'Logo', value: logo },
800
- { name: 'Description', value: description },
801
- {
802
- name: 'Keywords',
803
- value: keywords ? JSON.stringify(keywords) : undefined,
804
- },
805
- ].filter((tag) => tag.value !== undefined);
806
- return this.process.send({
807
- tags,
808
- signer: this.signer,
809
- });
810
- }
811
- /**
812
- * Sets the top level name of the ANT. This is the name that will be used to resolve the ANT (e.g. ardrive.ar.io)
813
- *
814
- * @param transactionId @type {string} The transactionId of the record.
815
- * @param ttlSeconds @type {number} The time to live of the record.
816
- * @param owner @type {string} Optional owner address for the record.
817
- * @param displayName @type {string} Optional display name for the record.
818
- * @param logo @type {string} Optional logo transaction ID for the record.
819
- * @param description @type {string} Optional description for the record.
820
- * @param keywords @type {string[]} Optional keywords array for the record.
821
- * @returns {Promise<AoMessageResult>} The result of the interaction.
822
- * @example
823
- * ```ts
824
- * ant.setBaseNameRecord({ transactionId: "432l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM", ttlSeconds: 100 }); // ardrive.ar.io will resolve to the provided transaction id and be cached for 100 seconds by clients
825
- * ```
826
- */
827
- async setBaseNameRecord({ transactionId, ttlSeconds, owner, displayName, logo, description, keywords, }, options) {
828
- return this.setRecord({
829
- transactionId,
830
- ttlSeconds,
831
- undername: '@',
832
- owner,
833
- displayName,
834
- logo,
835
- description,
836
- keywords,
837
- }, options);
838
- }
839
- /**
840
- * Adds or updates an undername of the ANT. An undername is appended to the base name of the ANT (e.g. ardrive.ar.io) to form a fully qualified name (e.g. dapp_ardrive.ar.io)
841
- *
842
- * @param undername @type {string} The undername of the ANT.
843
- * @param transactionId @type {string} The transactionId of the record.
844
- * @param ttlSeconds @type {number} The time to live of the record.
845
- * @param owner @type {string} Optional owner address for the record.
846
- * @param displayName @type {string} Optional display name for the record.
847
- * @param logo @type {string} Optional logo transaction ID for the record.
848
- * @param description @type {string} Optional description for the record.
849
- * @param keywords @type {string[]} Optional keywords array for the record.
850
- * @returns {Promise<AoMessageResult>} The result of the interaction.
851
- * @example
852
- * ```ts
853
- * ant.setUndernameRecord({ undername: "dapp", transactionId: "432l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM", ttlSeconds: 100 }); // dapp_ardrive.ar.io will resolve to the provided transaction id and be cached for 100 seconds by clients
854
- * ```
855
- */
856
- async setUndernameRecord({ undername, transactionId, ttlSeconds, owner, displayName, logo, description, keywords, }, options) {
857
- return this.setRecord({
858
- undername,
859
- transactionId,
860
- ttlSeconds,
861
- owner,
862
- displayName,
863
- logo,
864
- description,
865
- keywords,
866
- }, options);
867
- }
868
- /**
869
- * Removes an undername from the ANT. This will remove the undername from the ANT.
870
- *
871
- * @param undername @type {string} The undername you want to remove.
872
- * @returns {Promise<AoMessageResult>} The result of the interaction.
873
- * @example
874
- * ```ts
875
- * ant.removeUndernameRecord({ undername: "dapp" }); // removes dapp_ardrive.ar.io
876
- * ```
877
- */
878
- async removeUndernameRecord({ undername, }) {
879
- return this.removeRecord({ undername });
880
- }
881
- /**
882
- * Removes a record from the ANT. This will remove the record from the ANT. If '@' is provided, the top level name will be removed.
883
- *
884
- * @deprecated Use removeUndernameRecord instead.
885
- * @param undername @type {string} The record you want to remove.
886
- * @returns {Promise<AoMessageResult>} The result of the interaction.
887
- * @example
888
- * ```ts
889
- * ant.removeRecord({ undername: "dapp" }); // removes dapp_ardrive.ar.io
890
- * ```
891
- */
892
- async removeRecord({ undername, }, options) {
893
- return this.process.send({
894
- tags: [
895
- ...(options?.tags ?? []),
896
- { name: 'Action', value: 'Remove-Record' },
897
- { name: 'Sub-Domain', value: undername },
898
- ],
899
- signer: this.signer,
900
- });
901
- }
902
- /**
903
- * Sets the ticker of the ANT. This is the abbreviation displayed in ecosystem apps.
904
- *
905
- * @param ticker @type {string} Sets the ANT Ticker.
906
- * @returns {Promise<AoMessageResult>} The result of the interaction.
907
- * @example
908
- * ```ts
909
- * ant.setTicker({ ticker: "KAPOW" });
910
- * ```
911
- */
912
- async setTicker({ ticker }, options) {
913
- return this.process.send({
914
- tags: [
915
- ...(options?.tags ?? []),
916
- { name: 'Action', value: 'Set-Ticker' },
917
- { name: 'Ticker', value: ticker },
918
- ],
919
- signer: this.signer,
920
- });
921
- }
922
- /**
923
- * Sets the name of the ANT. This is the display name of the ANT. This is NOT the base name record.
924
- *
925
- * @param name @type {string} Sets the Name of the ANT.
926
- * @returns {Promise<AoMessageResult>} The result of the interaction.
927
- * @example
928
- * ```ts
929
- * ant.setName({ name: "test" }); // results in the resolution of `test_<apexName>.ar.io`
930
- * ```
931
- */
932
- async setName({ name }, options) {
933
- return this.process.send({
934
- tags: [
935
- ...(options?.tags ?? []),
936
- { name: 'Action', value: 'Set-Name' },
937
- { name: 'Name', value: name },
938
- ],
939
- signer: this.signer,
940
- });
941
- }
942
- /**
943
- * Sets the description of the ANT. This is the description of the ANT displayed in ecosystem apps.
944
- *
945
- * @param description @type {string} Sets the ANT Description.
946
- * @returns {Promise<AoMessageResult>} The result of the interaction.
947
- * @example
948
- * ```ts
949
- * ant.setDescription({ description: "This name is used for the ArDrive" });
950
- * ```
951
- */
952
- async setDescription({ description }, options) {
953
- return this.process.send({
954
- tags: [
955
- ...(options?.tags ?? []),
956
- { name: 'Action', value: 'Set-Description' },
957
- { name: 'Description', value: description },
958
- ],
959
- signer: this.signer,
960
- });
961
- }
962
- /**
963
- * Sets the keywords of the ANT. This is the keywords of the ANT displayed in ecosystem apps.
964
- *
965
- * @param keywords @type {string[]} Sets the ANT Keywords.
966
- * @returns {Promise<AoMessageResult>} The result of the interaction.
967
- * @example
968
- * ```ts
969
- * ant.setKeywords({ keywords: ['keyword1', 'keyword2', 'keyword3']});
970
- * ```
971
- */
972
- async setKeywords({ keywords }, options) {
973
- return this.process.send({
974
- tags: [
975
- ...(options?.tags ?? []),
976
- { name: 'Action', value: 'Set-Keywords' },
977
- { name: 'Keywords', value: JSON.stringify(keywords) },
978
- ],
979
- signer: this.signer,
980
- });
981
- }
982
- /**
983
- * Sets the logo of the ANT. This is the logo of the ANT displayed in ecosystem apps. Additionally, this logo is displayed for any primary names affiliated with the ANT.
984
- *
985
- * @param txId @type {string} - Arweave transaction id of the logo we want to set
986
- * @param options @type {WriteOptions} - additional options to add to the write interaction (optional)
987
- * @returns {Promise<AoMessageResult>} The result of the interaction.
988
- * @example
989
- * ```ts
990
- * ant.setLogo({ logo: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f" });
991
- * ```
992
- */
993
- async setLogo({ txId }, options) {
994
- return this.process.send({
995
- tags: [
996
- ...(options?.tags ?? []),
997
- { name: 'Action', value: 'Set-Logo' },
998
- { name: 'Logo', value: txId },
999
- ],
1000
- signer: this.signer,
1001
- });
1002
- }
1003
- /**
1004
- * Releases an ArNS name associated with the ANT. This will release the name to the public and allow anyone to register it. All primary names must be removed before the name can be released.
1005
- *
1006
- * @param name @type {string} The name you want to release. The name will be put up for as a recently returned name on the ARIO contract. 50% of the winning bid will be distributed to the ANT owner at the time of purchase. If no purchase in the recently returned name period (14 epochs), the name will be released and can be reregistered by anyone.
1007
- * @param arioProcessId @type {string} The processId of the ARIO contract. This is where the ANT will send the message to release the name.
1008
- * @returns {Promise<AoMessageResult>} The result of the interaction.
1009
- * @example
1010
- * ```ts
1011
- * ant.releaseName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID });
1012
- * ```
1013
- */
1014
- async releaseName({ name, arioProcessId }, options) {
1015
- return this.process.send({
1016
- tags: [
1017
- ...(options?.tags ?? []),
1018
- { name: 'Action', value: 'Release-Name' },
1019
- { name: 'Name', value: name },
1020
- { name: 'IO-Process-Id', value: arioProcessId },
1021
- { name: 'ARIO-Process-Id', value: arioProcessId },
1022
- ],
1023
- signer: this.signer,
1024
- });
1025
- }
1026
- /**
1027
- * Sends a message to the ARIO contract to reassign the the base ArNS name to a new ANT. This can only be done by the current owner of the ANT.
1028
- *
1029
- * @param name @type {string} The name you want to reassign.
1030
- * @param arioProcessId @type {string} The processId of the ARIO contract.
1031
- * @param antProcessId @type {string} The processId of the ANT contract.
1032
- * @returns {Promise<AoMessageResult>} The result of the interaction.
1033
- * @example
1034
- * ```ts
1035
- * ant.reassignName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID });
1036
- * ```
1037
- */
1038
- async reassignName({ name, arioProcessId, antProcessId, }, options) {
1039
- return this.process.send({
1040
- tags: [
1041
- ...(options?.tags ?? []),
1042
- { name: 'Action', value: 'Reassign-Name' },
1043
- { name: 'Name', value: name },
1044
- { name: 'IO-Process-Id', value: arioProcessId },
1045
- { name: 'ARIO-Process-Id', value: arioProcessId },
1046
- { name: 'Process-Id', value: antProcessId },
1047
- ],
1048
- signer: this.signer,
1049
- });
1050
- }
1051
- /**
1052
- * Approves a primary name request for a given name or address.
1053
- *
1054
- * @param name @type {string} The name you want to approve.
1055
- * @param address @type {WalletAddress} The address you want to approve.
1056
- * @param arioProcessId @type {string} The processId of the ARIO contract.
1057
- * @returns {Promise<AoMessageResult>} The result of the interaction.
1058
- * @example
1059
- * ```ts
1060
- * ant.approvePrimaryNameRequest({ name: "ardrive", address: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f", arioProcessId: ARIO_MAINNET_PROCESS_ID }); // approves the request for ardrive.ar.io to be registered by the address
1061
- * ```
1062
- */
1063
- async approvePrimaryNameRequest({ name, address, arioProcessId, }, options) {
1064
- return this.process.send({
1065
- tags: [
1066
- ...(options?.tags ?? []),
1067
- { name: 'Action', value: 'Approve-Primary-Name' },
1068
- { name: 'Name', value: name },
1069
- { name: 'Recipient', value: address },
1070
- { name: 'IO-Process-Id', value: arioProcessId },
1071
- { name: 'ARIO-Process-Id', value: arioProcessId },
1072
- ],
1073
- signer: this.signer,
1074
- });
1075
- }
1076
- /**
1077
- * Removes primary names from the ANT. This will remove the primary names associated with the base ArNS name controlled by this ANT. All primary names must be removed before the name can be released.
1078
- *
1079
- * @param names @type {string[]} The names you want to remove.
1080
- * @param arioProcessId @type {string} The processId of the ARIO contract.
1081
- * @param notifyOwners @type {boolean} Whether to notify the owners of the primary names.
1082
- * @returns {Promise<AoMessageResult>} The result of the interaction.
1083
- * @example
1084
- * ```ts
1085
- * ant.removePrimaryNames({ names: ["ardrive", "dapp_ardrive"], arioProcessId: ARIO_MAINNET_PROCESS_ID, notifyOwners: true }); // removes the primary names and associated wallet addresses assigned to "ardrive" and "dapp_ardrive"
1086
- * ```
1087
- */
1088
- async removePrimaryNames({ names, arioProcessId,
1089
- // TODO: remove this param, its not used on the ANT contract
1090
- notifyOwners = false, }, options) {
1091
- return this.process.send({
1092
- tags: [
1093
- ...(options?.tags ?? []),
1094
- { name: 'Action', value: 'Remove-Primary-Names' },
1095
- { name: 'Names', value: names.join(',') },
1096
- { name: 'IO-Process-Id', value: arioProcessId },
1097
- { name: 'ARIO-Process-Id', value: arioProcessId },
1098
- { name: 'Notify-Owners', value: notifyOwners.toString() },
1099
- ],
1100
- signer: this.signer,
1101
- });
1102
- }
1103
- /**
1104
- * Upgrade this ANT by forking it to the latest version and reassigning names.
1105
- *
1106
- * This is a convenience method that calls the static ANT.upgrade() method
1107
- * using this instance's process ID and signer.
1108
- *
1109
- * current version with latest ANT registry version and skip if already up to date.
1110
- *
1111
- * @param names @type {string[]} The ArNS names to reassign to the upgraded ANT.
1112
- * @param arioProcessId @type {string} The processId of the ARIO contract.
1113
- * @param antRegistryId @type {string} Optional ANT registry ID.
1114
- * @param onSigningProgress Progress callback function.
1115
- * @returns {Promise} The upgrade results.
1116
- * @example
1117
- * ```ts
1118
- * const result = await ant.upgrade({
1119
- * names: ["example", "test"],
1120
- * arioProcessId: ARIO_MAINNET_PROCESS_ID
1121
- * });
1122
- * console.log(`Upgraded to process: ${result.forkedProcessId}`);
1123
- * ```
1124
- */
1125
- async upgrade(params) {
1126
- const { names, reassignAffiliatedNames, arioProcessId, antRegistryId, skipVersionCheck, onSigningProgress, } = params ?? {};
1127
- // Determine if we should reassign all names or specific names
1128
- const shouldReassignAll = names === undefined || names.length === 0
1129
- ? (reassignAffiliatedNames ?? true)
1130
- : false;
1131
- if (shouldReassignAll) {
1132
- return ANT.upgrade({
1133
- signer: this.signer,
1134
- antProcessId: this.processId,
1135
- ao: this.process.ao,
1136
- hyperbeamUrl: this.hyperbeamUrl?.toString(),
1137
- reassignAffiliatedNames: true,
1138
- arioProcessId: arioProcessId,
1139
- antRegistryId: antRegistryId,
1140
- onSigningProgress: onSigningProgress,
1141
- skipVersionCheck: skipVersionCheck,
1142
- });
1143
- }
1144
- else {
1145
- return ANT.upgrade({
1146
- signer: this.signer,
1147
- antProcessId: this.processId,
1148
- ao: this.process.ao,
1149
- hyperbeamUrl: this.hyperbeamUrl?.toString(),
1150
- names: names,
1151
- reassignAffiliatedNames: false,
1152
- arioProcessId: arioProcessId,
1153
- antRegistryId: antRegistryId,
1154
- onSigningProgress: onSigningProgress,
1155
- skipVersionCheck: skipVersionCheck,
1156
- });
1157
- }
1158
- }
1159
- /**
1160
- * Transfers ownership of a specific record (undername) to another address. This allows delegation of control for individual records within an ANT while maintaining the ANT owner's ultimate authority.
1161
- *
1162
- * @param undername @type {string} The subdomain/record whose ownership you want to transfer.
1163
- * @param recipient @type {string} The address of the new owner for this record.
1164
- * @returns {Promise<AoMessageResult>} The result of the interaction.
1165
- * @example
1166
- * ```ts
1167
- * ant.transferRecord({ undername: "alice", recipient: "new-owner-address-123..." }); // transfers ownership of the "alice" record to the new owner
1168
- * ```
1169
- */
1170
- async transferRecord({ undername, recipient, }, options) {
1171
- return this.process.send({
1172
- tags: [
1173
- ...(options?.tags ?? []),
1174
- { name: 'Action', value: 'Transfer-Record' },
1175
- { name: 'Sub-Domain', value: undername },
1176
- { name: 'Recipient', value: recipient },
1177
- ],
1178
- signer: this.signer,
1179
- });
1180
- }
1181
- }
1182
- exports.AoANTWriteable = AoANTWriteable;