@ar.io/sdk 3.24.0 → 4.0.0-alpha.1

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