@ar.io/sdk 3.18.2-alpha.1 → 3.19.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.
@@ -71,7 +71,9 @@ class AoANTRegistryReadable {
71
71
  return this.checkHyperBeamPromise;
72
72
  }
73
73
  this.logger.debug('Checking HyperBeam compatibility');
74
- this.checkHyperBeamPromise = fetch(`${this.hyperbeamUrl.toString()}${this.process.processId}~process@1.0/now/cache/acl`, {
74
+ this.checkHyperBeamPromise = fetch(
75
+ // use /now to force a refresh of the cache state, then compute when calling it for keys
76
+ `${this.hyperbeamUrl.toString()}${this.process.processId}~process@1.0/now/cache/acl`, {
75
77
  method: 'HEAD',
76
78
  signal: AbortSignal.timeout(5000), // 5 second timeout
77
79
  })
@@ -98,7 +100,7 @@ class AoANTRegistryReadable {
98
100
  while (retries < 3) {
99
101
  try {
100
102
  this.logger.debug('Fetching ant registry acl for address from hyperbeam', address);
101
- const res = await fetch(`${this.hyperbeamUrl?.toString()}${this.process.processId}~process@1.0/now/cache/acl/${address}/serialize~json@1.0`);
103
+ const res = await fetch(`${this.hyperbeamUrl?.toString()}${this.process.processId}~process@1.0/compute/cache/acl/${address}/serialize~json@1.0`);
102
104
  if (res.status !== 200) {
103
105
  this.logger.debug('Failed to fetch ant registry acl for address from hyperbeam', address, res.status, res.statusText);
104
106
  throw new Error(`Failed to fetch ant registry acl for address ${address}: ${res?.statusText ?? 'Unknown error'}`);
@@ -37,7 +37,12 @@ class ANT {
37
37
  * Spawn a new ANT.
38
38
  */
39
39
  static spawn = ao_js_1.spawnANT;
40
- // implementation
40
+ /**
41
+ * Fork an ANT to a new process.
42
+ *
43
+ * @param config
44
+ */
45
+ static fork = ao_js_1.forkANT;
41
46
  static init(config) {
42
47
  if (config !== undefined && 'signer' in config) {
43
48
  return new AoANTWriteable(config);
@@ -89,7 +94,9 @@ class AoANTReadable {
89
94
  if (this.checkHyperBeamPromise !== undefined) {
90
95
  return this.checkHyperBeamPromise;
91
96
  }
92
- this.checkHyperBeamPromise = fetch(`${this.hyperbeamUrl.toString()}${this.processId}~process@1.0/now/cache`, {
97
+ this.checkHyperBeamPromise = fetch(
98
+ // use /now to force a refresh of the cache state, then compute when calling it for keys
99
+ `${this.hyperbeamUrl.toString()}${this.processId}~process@1.0/now/cache`, {
93
100
  method: 'HEAD',
94
101
  signal: AbortSignal.timeout(5000), // 5 second timeout
95
102
  })
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_SCHEDULER_ID = exports.AO_AUTHORITY = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MARIO_PER_ARIO = exports.ANT_REGISTRY_ID = exports.ARIO_MAINNET_PROCESS_ID = exports.ARIO_TESTNET_PROCESS_ID = exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID = exports.ARNS_DEVNET_REGISTRY_TX = exports.ARNS_TESTNET_REGISTRY_TX = exports.SORT_KEY_REGEX = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
3
+ exports.DEFAULT_SCHEDULER_ID = exports.AO_AUTHORITY = exports.ANT_LUA_ID = exports.AOS_MODULE_ID = exports.MARIO_PER_ARIO = exports.ANT_REGISTRY_ID = exports.ARIO_MAINNET_PROCESS_ID = exports.ARIO_TESTNET_PROCESS_ID = exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID = exports.FQDN_REGEX = exports.ARWEAVE_TX_REGEX = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
6
  *
@@ -19,10 +19,6 @@ exports.DEFAULT_SCHEDULER_ID = exports.AO_AUTHORITY = exports.ANT_LUA_ID = expor
19
19
  exports.ARWEAVE_TX_REGEX = new RegExp('^[a-zA-Z0-9_-]{43}$');
20
20
  /** FQDN regex that matches the one used in the ArNS contract. */
21
21
  exports.FQDN_REGEX = new RegExp('^(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{1,63}$');
22
- // sortkey: padded blockheight to 12, JS timestamp, hash of transactionID + block hash. Timestamp only applicable to L2 and normally is all zeros.
23
- exports.SORT_KEY_REGEX = new RegExp('^[0-9]{12},[0-9]{13},[a-fA-F0-9]{64}$');
24
- exports.ARNS_TESTNET_REGISTRY_TX = process.env.ARNS_REGISTRY_TX ?? 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
25
- exports.ARNS_DEVNET_REGISTRY_TX = '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8';
26
22
  exports.ARIO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
27
23
  // backwards compatibility - TODO: remove in v2.0.0
28
24
  exports.arioDevnetProcessId = exports.ARIO_DEVNET_PROCESS_ID;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultANTLogoId = exports.defaultTargetManifestId = void 0;
4
4
  exports.spawnANT = spawnANT;
5
+ exports.forkANT = forkANT;
5
6
  exports.evolveANT = evolveANT;
6
7
  exports.isAoSigner = isAoSigner;
7
8
  exports.createAoSigner = createAoSigner;
@@ -222,7 +223,40 @@ async function spawnANT({ signer, module, ao = (0, aoconnect_1.connect)({
222
223
  }
223
224
  return processId;
224
225
  }
225
- // TODO: add a utility for forking an ANT to the latest module that leverages getState and spawnANT
226
+ async function forkANT({ signer, antProcessId, logger = index_js_1.Logger.default, ao, antRegistryId = constants_js_1.ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
227
+ logger.debug('Forking ANT', { name, payload });
228
+ }, }) {
229
+ // get the state of the current ANT and use it to spawn a new ANT
230
+ const ant = index_js_1.ANT.init({
231
+ process: new index_js_1.AOProcess({
232
+ processId: antProcessId,
233
+ ao,
234
+ logger,
235
+ }),
236
+ });
237
+ const state = await ant.getState();
238
+ if (state === undefined) {
239
+ throw new Error(`ANT state (${antProcessId}) is undefined and cannot be upgraded`);
240
+ }
241
+ const forkedProcessId = await spawnANT({
242
+ signer,
243
+ antRegistryId,
244
+ logger,
245
+ onSigningProgress,
246
+ state: {
247
+ owner: state.Owner,
248
+ name: state.Name,
249
+ ticker: state.Ticker,
250
+ description: state.Description,
251
+ keywords: state.Keywords,
252
+ controllers: state.Controllers,
253
+ records: state.Records,
254
+ balances: state.Balances,
255
+ logo: state.Logo,
256
+ },
257
+ });
258
+ return forkedProcessId;
259
+ }
226
260
  /**
227
261
  * @deprecated
228
262
  * Direct Evals are not encouraged when dealing with ANTs.
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.18.2-alpha.1';
20
+ exports.version = '3.19.0-alpha.1';
@@ -67,7 +67,9 @@ export class AoANTRegistryReadable {
67
67
  return this.checkHyperBeamPromise;
68
68
  }
69
69
  this.logger.debug('Checking HyperBeam compatibility');
70
- this.checkHyperBeamPromise = fetch(`${this.hyperbeamUrl.toString()}${this.process.processId}~process@1.0/now/cache/acl`, {
70
+ this.checkHyperBeamPromise = fetch(
71
+ // use /now to force a refresh of the cache state, then compute when calling it for keys
72
+ `${this.hyperbeamUrl.toString()}${this.process.processId}~process@1.0/now/cache/acl`, {
71
73
  method: 'HEAD',
72
74
  signal: AbortSignal.timeout(5000), // 5 second timeout
73
75
  })
@@ -94,7 +96,7 @@ export class AoANTRegistryReadable {
94
96
  while (retries < 3) {
95
97
  try {
96
98
  this.logger.debug('Fetching ant registry acl for address from hyperbeam', address);
97
- const res = await fetch(`${this.hyperbeamUrl?.toString()}${this.process.processId}~process@1.0/now/cache/acl/${address}/serialize~json@1.0`);
99
+ const res = await fetch(`${this.hyperbeamUrl?.toString()}${this.process.processId}~process@1.0/compute/cache/acl/${address}/serialize~json@1.0`);
98
100
  if (res.status !== 200) {
99
101
  this.logger.debug('Failed to fetch ant registry acl for address from hyperbeam', address, res.status, res.statusText);
100
102
  throw new Error(`Failed to fetch ant registry acl for address ${address}: ${res?.statusText ?? 'Unknown error'}`);
@@ -17,7 +17,7 @@ import { z } from 'zod';
17
17
  import { AntBalancesSchema, AntControllersSchema, AntInfoSchema, AntRecordSchema, AntRecordsSchema, AntStateSchema, } from '../types/ant.js';
18
18
  import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
19
19
  import { convertHyperBeamStateToAoANTState, isHyperBeamANTState, sortANTRecords, } from '../utils/ant.js';
20
- import { createAoSigner, spawnANT } from '../utils/ao.js';
20
+ import { createAoSigner, forkANT, spawnANT } from '../utils/ao.js';
21
21
  import { parseSchemaResult } from '../utils/schema.js';
22
22
  import { ANTVersions } from './ant-versions.js';
23
23
  import { AOProcess, InvalidContractConfigurationError, Logger, } from './index.js';
@@ -34,7 +34,12 @@ export class ANT {
34
34
  * Spawn a new ANT.
35
35
  */
36
36
  static spawn = spawnANT;
37
- // implementation
37
+ /**
38
+ * Fork an ANT to a new process.
39
+ *
40
+ * @param config
41
+ */
42
+ static fork = forkANT;
38
43
  static init(config) {
39
44
  if (config !== undefined && 'signer' in config) {
40
45
  return new AoANTWriteable(config);
@@ -85,7 +90,9 @@ export class AoANTReadable {
85
90
  if (this.checkHyperBeamPromise !== undefined) {
86
91
  return this.checkHyperBeamPromise;
87
92
  }
88
- this.checkHyperBeamPromise = fetch(`${this.hyperbeamUrl.toString()}${this.processId}~process@1.0/now/cache`, {
93
+ this.checkHyperBeamPromise = fetch(
94
+ // use /now to force a refresh of the cache state, then compute when calling it for keys
95
+ `${this.hyperbeamUrl.toString()}${this.processId}~process@1.0/now/cache`, {
89
96
  method: 'HEAD',
90
97
  signal: AbortSignal.timeout(5000), // 5 second timeout
91
98
  })
@@ -16,10 +16,6 @@
16
16
  export const ARWEAVE_TX_REGEX = new RegExp('^[a-zA-Z0-9_-]{43}$');
17
17
  /** FQDN regex that matches the one used in the ArNS contract. */
18
18
  export const FQDN_REGEX = new RegExp('^(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{1,63}$');
19
- // sortkey: padded blockheight to 12, JS timestamp, hash of transactionID + block hash. Timestamp only applicable to L2 and normally is all zeros.
20
- export const SORT_KEY_REGEX = new RegExp('^[0-9]{12},[0-9]{13},[a-fA-F0-9]{64}$');
21
- export const ARNS_TESTNET_REGISTRY_TX = process.env.ARNS_REGISTRY_TX ?? 'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
22
- export const ARNS_DEVNET_REGISTRY_TX = '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8';
23
19
  export const ARIO_DEVNET_PROCESS_ID = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc';
24
20
  // backwards compatibility - TODO: remove in v2.0.0
25
21
  export const arioDevnetProcessId = ARIO_DEVNET_PROCESS_ID;
@@ -19,7 +19,7 @@ import { z } from 'zod';
19
19
  import { ANTRegistry } from '../common/ant-registry.js';
20
20
  import { ANTVersions } from '../common/ant-versions.js';
21
21
  import { defaultArweave } from '../common/arweave.js';
22
- import { AOProcess, Logger } from '../common/index.js';
22
+ import { ANT, AOProcess, Logger } from '../common/index.js';
23
23
  import { ANT_LUA_ID, ANT_REGISTRY_ID, AO_AUTHORITY, DEFAULT_SCHEDULER_ID, } from '../constants.js';
24
24
  import { SpawnANTStateSchema } from '../types/ant.js';
25
25
  import { parseSchemaResult } from './schema.js';
@@ -211,7 +211,40 @@ export async function spawnANT({ signer, module, ao = connect({
211
211
  }
212
212
  return processId;
213
213
  }
214
- // TODO: add a utility for forking an ANT to the latest module that leverages getState and spawnANT
214
+ export async function forkANT({ signer, antProcessId, logger = Logger.default, ao, antRegistryId = ANT_REGISTRY_ID, onSigningProgress = (name, payload) => {
215
+ logger.debug('Forking ANT', { name, payload });
216
+ }, }) {
217
+ // get the state of the current ANT and use it to spawn a new ANT
218
+ const ant = ANT.init({
219
+ process: new AOProcess({
220
+ processId: antProcessId,
221
+ ao,
222
+ logger,
223
+ }),
224
+ });
225
+ const state = await ant.getState();
226
+ if (state === undefined) {
227
+ throw new Error(`ANT state (${antProcessId}) is undefined and cannot be upgraded`);
228
+ }
229
+ const forkedProcessId = await spawnANT({
230
+ signer,
231
+ antRegistryId,
232
+ logger,
233
+ onSigningProgress,
234
+ state: {
235
+ owner: state.Owner,
236
+ name: state.Name,
237
+ ticker: state.Ticker,
238
+ description: state.Description,
239
+ keywords: state.Keywords,
240
+ controllers: state.Controllers,
241
+ records: state.Records,
242
+ balances: state.Balances,
243
+ logo: state.Logo,
244
+ },
245
+ });
246
+ return forkedProcessId;
247
+ }
215
248
  /**
216
249
  * @deprecated
217
250
  * Direct Evals are not encouraged when dealing with ANTs.
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.18.2-alpha.1';
17
+ export const version = '3.19.0-alpha.1';
@@ -1,6 +1,6 @@
1
1
  import { AntReadOptions, AoANTHandler, AoANTInfo, AoANTRead, AoANTRecord, AoANTSetBaseNameRecordParams, AoANTSetUndernameRecordParams, AoANTState, AoANTWrite, SortedANTRecords } from '../types/ant.js';
2
2
  import { AoMessageResult, ProcessConfiguration, WalletAddress, WithSigner, WriteOptions } from '../types/index.js';
3
- import { spawnANT } from '../utils/ao.js';
3
+ import { forkANT, spawnANT } from '../utils/ao.js';
4
4
  import { AOProcess } from './index.js';
5
5
  type ANTConfigOptionalStrict = Required<ProcessConfiguration> & {
6
6
  strict?: boolean;
@@ -19,6 +19,17 @@ export declare class ANT {
19
19
  * Spawn a new ANT.
20
20
  */
21
21
  static spawn: typeof spawnANT;
22
+ /**
23
+ * Fork an ANT to a new process.
24
+ *
25
+ * @param config
26
+ */
27
+ static fork: typeof forkANT;
28
+ /**
29
+ * Initialize overloads.
30
+ *
31
+ * @param config
32
+ */
22
33
  static init(config: ANTConfigNoSigner): AoANTRead;
23
34
  static init(config: ANTConfigWithSigner): AoANTWrite;
24
35
  }
@@ -16,9 +16,6 @@
16
16
  export declare const ARWEAVE_TX_REGEX: RegExp;
17
17
  /** FQDN regex that matches the one used in the ArNS contract. */
18
18
  export declare const FQDN_REGEX: RegExp;
19
- export declare const SORT_KEY_REGEX: RegExp;
20
- export declare const ARNS_TESTNET_REGISTRY_TX: string;
21
- export declare const ARNS_DEVNET_REGISTRY_TX = "_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8";
22
19
  export declare const ARIO_DEVNET_PROCESS_ID = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc";
23
20
  export declare const arioDevnetProcessId = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc";
24
21
  export declare const ARIO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA";
@@ -30,6 +30,14 @@ export type SpawnANTParams = {
30
30
  onSigningProgress?: (name: keyof SpawnAntProgressEvent, payload: SpawnAntProgressEvent[keyof SpawnAntProgressEvent]) => void;
31
31
  };
32
32
  export declare function spawnANT({ signer, module, ao, scheduler, state, tags, antRegistryId, logger, authority, onSigningProgress, }: SpawnANTParams): Promise<ProcessId>;
33
+ export declare function forkANT({ signer, antProcessId, logger, ao, antRegistryId, onSigningProgress, }: {
34
+ signer: AoSigner;
35
+ antProcessId: string;
36
+ logger?: Logger;
37
+ ao?: AoClient;
38
+ antRegistryId?: string;
39
+ onSigningProgress?: (name: keyof SpawnAntProgressEvent, payload: SpawnAntProgressEvent[keyof SpawnAntProgressEvent]) => void;
40
+ }): Promise<string>;
33
41
  /**
34
42
  * @deprecated
35
43
  * Direct Evals are not encouraged when dealing with ANTs.
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.18.1";
16
+ export declare const version = "3.18.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.18.2-alpha.1",
3
+ "version": "3.19.0-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"