@algorandfoundation/algokit-utils 9.1.2 → 9.2.0-beta.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.
@@ -178,6 +178,7 @@ export declare class AppFactory {
178
178
  appReferences?: bigint[] | undefined;
179
179
  assetReferences?: bigint[] | undefined;
180
180
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
181
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
181
182
  sender?: string | algosdk.Address | undefined;
182
183
  method: string;
183
184
  args?: (algosdk.ABIValue | AppMethodCallTransactionArgument | ABIStruct | undefined)[] | undefined;
@@ -224,6 +225,7 @@ export declare class AppFactory {
224
225
  appReferences?: bigint[] | undefined;
225
226
  assetReferences?: bigint[] | undefined;
226
227
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
228
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
227
229
  sender?: string | algosdk.Address | undefined;
228
230
  method: string;
229
231
  args?: (algosdk.ABIValue | AppMethodCallTransactionArgument | ABIStruct | undefined)[] | undefined;
@@ -252,6 +254,7 @@ export declare class AppFactory {
252
254
  appReferences?: bigint[] | undefined;
253
255
  assetReferences?: bigint[] | undefined;
254
256
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
257
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
255
258
  approvalProgram: string | Uint8Array;
256
259
  clearStateProgram: string | Uint8Array;
257
260
  schema?: {
@@ -280,6 +283,7 @@ export declare class AppFactory {
280
283
  appReferences?: bigint[] | undefined;
281
284
  assetReferences?: bigint[] | undefined;
282
285
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
286
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
283
287
  approvalProgram: string | Uint8Array;
284
288
  clearStateProgram: string | Uint8Array;
285
289
  }> | AppMethodCall<import("./composer").AppMethodCallParams> | undefined)[] | undefined;
@@ -302,6 +306,7 @@ export declare class AppFactory {
302
306
  appReferences?: bigint[] | undefined;
303
307
  assetReferences?: bigint[] | undefined;
304
308
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
309
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
305
310
  sender?: string | algosdk.Address | undefined;
306
311
  method: string;
307
312
  args?: (algosdk.ABIValue | AppMethodCallTransactionArgument | ABIStruct | undefined)[] | undefined;
@@ -321,6 +326,7 @@ export declare class AppFactory {
321
326
  appReferences?: bigint[] | undefined;
322
327
  assetReferences?: bigint[] | undefined;
323
328
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
329
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
324
330
  sender?: string | algosdk.Address | undefined;
325
331
  method: string;
326
332
  args?: (algosdk.ABIValue | AppMethodCallTransactionArgument | ABIStruct | undefined)[] | undefined;
@@ -346,6 +352,7 @@ export declare class AppFactory {
346
352
  appReferences?: bigint[] | undefined;
347
353
  assetReferences?: bigint[] | undefined;
348
354
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
355
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
349
356
  approvalProgram: string | Uint8Array;
350
357
  clearStateProgram: string | Uint8Array;
351
358
  schema?: {
@@ -374,6 +381,7 @@ export declare class AppFactory {
374
381
  appReferences?: bigint[] | undefined;
375
382
  assetReferences?: bigint[] | undefined;
376
383
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
384
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
377
385
  approvalProgram: string | Uint8Array;
378
386
  clearStateProgram: string | Uint8Array;
379
387
  }> | AppMethodCall<import("./composer").AppMethodCallParams> | undefined)[] | undefined;
@@ -396,6 +404,7 @@ export declare class AppFactory {
396
404
  appReferences?: bigint[] | undefined;
397
405
  assetReferences?: bigint[] | undefined;
398
406
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
407
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
399
408
  sender?: string | algosdk.Address | undefined;
400
409
  method: string;
401
410
  args?: (algosdk.ABIValue | AppMethodCallTransactionArgument | ABIStruct | undefined)[] | undefined;
@@ -415,6 +424,7 @@ export declare class AppFactory {
415
424
  appReferences?: bigint[] | undefined;
416
425
  assetReferences?: bigint[] | undefined;
417
426
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
427
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
418
428
  sender?: string | algosdk.Address | undefined;
419
429
  method: string;
420
430
  args?: (algosdk.ABIValue | AppMethodCallTransactionArgument | ABIStruct | undefined)[] | undefined;
@@ -440,6 +450,7 @@ export declare class AppFactory {
440
450
  appReferences?: bigint[] | undefined;
441
451
  assetReferences?: bigint[] | undefined;
442
452
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
453
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
443
454
  approvalProgram: string | Uint8Array;
444
455
  clearStateProgram: string | Uint8Array;
445
456
  schema?: {
@@ -468,6 +479,7 @@ export declare class AppFactory {
468
479
  appReferences?: bigint[] | undefined;
469
480
  assetReferences?: bigint[] | undefined;
470
481
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
482
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
471
483
  approvalProgram: string | Uint8Array;
472
484
  clearStateProgram: string | Uint8Array;
473
485
  }> | AppMethodCall<import("./composer").AppMethodCallParams> | undefined)[] | undefined;
@@ -491,6 +503,7 @@ export declare class AppFactory {
491
503
  appReferences?: bigint[] | undefined;
492
504
  assetReferences?: bigint[] | undefined;
493
505
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
506
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
494
507
  sender?: string | algosdk.Address | undefined;
495
508
  deployTimeParams?: TealTemplateParams | undefined;
496
509
  updatable?: boolean | undefined;
@@ -538,6 +551,7 @@ export declare class AppFactory {
538
551
  appReferences?: bigint[] | undefined;
539
552
  assetReferences?: bigint[] | undefined;
540
553
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
554
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
541
555
  sender?: string | algosdk.Address | undefined;
542
556
  updatable?: boolean | undefined;
543
557
  deletable?: boolean | undefined;
@@ -565,6 +579,7 @@ export declare class AppFactory {
565
579
  appReferences?: bigint[] | undefined;
566
580
  assetReferences?: bigint[] | undefined;
567
581
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
582
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
568
583
  sender?: string | algosdk.Address | undefined;
569
584
  } | undefined) => {
570
585
  maxFee?: import("./amount").AlgoAmount | undefined;
@@ -582,6 +597,7 @@ export declare class AppFactory {
582
597
  appReferences?: bigint[] | undefined;
583
598
  assetReferences?: bigint[] | undefined;
584
599
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
600
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
585
601
  sender?: string | algosdk.Address | undefined;
586
602
  } & {
587
603
  sender: algosdk.Address;
@@ -605,6 +621,7 @@ export declare class AppFactory {
605
621
  appReferences?: bigint[] | undefined;
606
622
  assetReferences?: bigint[] | undefined;
607
623
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
624
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
608
625
  sender?: string | algosdk.Address | undefined;
609
626
  } | undefined) => {
610
627
  maxFee?: import("./amount").AlgoAmount | undefined;
@@ -622,6 +639,7 @@ export declare class AppFactory {
622
639
  appReferences?: bigint[] | undefined;
623
640
  assetReferences?: bigint[] | undefined;
624
641
  boxReferences?: (import("./app-manager").BoxIdentifier | import("./app-manager").BoxReference)[] | undefined;
642
+ accessReferences?: import("./app-manager").AccessReference[] | undefined;
625
643
  sender?: string | algosdk.Address | undefined;
626
644
  } & {
627
645
  sender: algosdk.Address;
@@ -79,6 +79,41 @@ export interface BoxValuesRequestParams {
79
79
  /** The ABI type to decode the value using */
80
80
  type: algosdk.ABIType;
81
81
  }
82
+ /**
83
+ * Defines a holding by referring to an Address and Asset it belongs to.
84
+ */
85
+ export interface HoldingReference {
86
+ /** Asset ID for asset in access list. */
87
+ assetId: bigint;
88
+ /** Address in access list, or the sender of the transaction. */
89
+ address: string | Address;
90
+ }
91
+ /**
92
+ * Defines a local state by referring to an Address and App it belongs to.
93
+ */
94
+ export interface LocalsReference {
95
+ /** Application ID for app in access list, or zero if referring to the called application. */
96
+ appId: bigint;
97
+ /** Address in access list, or the sender of the transaction. */
98
+ address: string | Address;
99
+ }
100
+ /**
101
+ * Names a single resource reference. Only one of the fields should be set.
102
+ */
103
+ export interface AccessReference {
104
+ /** Any account addresses whose balance record is accessible by the executing ApprovalProgram or ClearStateProgram. */
105
+ address?: string | Address;
106
+ /** Application ID whose GlobalState may be read by the executing ApprovalProgram or ClearStateProgram. */
107
+ appId?: bigint;
108
+ /** Asset ID whose AssetParams may be read by the executing ApprovalProgram or ClearStateProgram. */
109
+ assetId?: bigint;
110
+ /** Defines a holding by referring to an Address and Asset it belongs to. */
111
+ holding?: HoldingReference;
112
+ /** Defines a local state by referring to an Address and App it belongs to. */
113
+ locals?: LocalsReference;
114
+ /** Defines a box by its name and the application ID it belongs to. */
115
+ box?: BoxReference;
116
+ }
82
117
  /** Allows management of application information. */
83
118
  export declare class AppManager {
84
119
  private _algod;
@@ -306,3 +341,7 @@ export declare class AppManager {
306
341
  */
307
342
  static stripTealComments(tealCode: string): string;
308
343
  }
344
+ /**
345
+ * Returns an `algosdk.TransactionResourceReference` given a `AccessReference`.
346
+ */
347
+ export declare function getAccessReference(accessReference: AccessReference): algosdk.TransactionResourceReference;
@@ -392,6 +392,31 @@ class AppManager {
392
392
  .join('\n');
393
393
  }
394
394
  }
395
+ function getHoldingReference(holdingReference) {
396
+ return {
397
+ assetIndex: holdingReference.assetId,
398
+ address: typeof holdingReference.address === 'string' ? algosdk.Address.fromString(holdingReference.address) : holdingReference.address,
399
+ };
400
+ }
401
+ function getLocalsReference(localsReference) {
402
+ return {
403
+ appIndex: localsReference.appId,
404
+ address: typeof localsReference.address === 'string' ? algosdk.Address.fromString(localsReference.address) : localsReference.address,
405
+ };
406
+ }
407
+ /**
408
+ * Returns an `algosdk.TransactionResourceReference` given a `AccessReference`.
409
+ */
410
+ function getAccessReference(accessReference) {
411
+ return {
412
+ address: typeof accessReference.address === 'string' ? algosdk.Address.fromString(accessReference.address) : accessReference.address,
413
+ appIndex: accessReference.appId,
414
+ assetIndex: accessReference.assetId,
415
+ holding: accessReference.holding ? getHoldingReference(accessReference.holding) : undefined,
416
+ locals: accessReference.locals ? getLocalsReference(accessReference.locals) : undefined,
417
+ box: accessReference.box ? AppManager.getBoxReference(accessReference.box) : undefined,
418
+ };
419
+ }
395
420
  /**
396
421
  * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.
397
422
  * Returns undefined if not found
@@ -484,4 +509,5 @@ function isValidTokenCharacter(char) {
484
509
  }
485
510
 
486
511
  exports.AppManager = AppManager;
512
+ exports.getAccessReference = getAccessReference;
487
513
  //# sourceMappingURL=app-manager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-manager.js","sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk, { Address, ProgramSourceMap } from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n BoxName,\n DELETABLE_TEMPLATE_NAME,\n UPDATABLE_TEMPLATE_NAME,\n type ABIReturn,\n type AppState,\n type CompiledTeal,\n type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n /** The ID of the app. */\n appId: bigint\n /** The escrow address that the app operates with. */\n appAddress: Address\n /**\n * Approval program.\n */\n approvalProgram: Uint8Array\n /**\n * Clear state program.\n */\n clearStateProgram: Uint8Array\n /**\n * The address that created this application. This is the address where the\n * parameters and global state for this application can be found.\n */\n creator: Address\n /**\n * Current global state values.\n */\n globalState: AppState\n /** The number of allocated ints in per-user local state. */\n localInts: number\n /** The number of allocated byte slices in per-user local state. */\n localByteSlices: number\n /** The number of allocated ints in global state. */\n globalInts: number\n /** The number of allocated byte slices in global state. */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract. */\n extraProgramPages?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n * * `Uint8Array` (the actual binary of the box name)\n * * `string` (that will be encoded to a `Uint8Array`)\n * * `TransactionSignerAccount` (that will be encoded into the\n * public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: bigint\n /**\n * Identifier for a box name\n */\n name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: BoxIdentifier\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: BoxIdentifier[]\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n private _algod: algosdk.Algodv2\n private _compilationResults: Record<string, CompiledTeal> = {}\n\n /**\n * Creates an `AppManager`\n * @param algod An algod instance\n */\n constructor(algod: algosdk.Algodv2) {\n this._algod = algod\n }\n\n /**\n * Compiles the given TEAL using algod and returns the result, including source map.\n *\n * The result of this compilation is also cached keyed by the TEAL\n * code so it can be retrieved via `getCompilationResult`.\n *\n * This function is re-entrant; it will only compile the same code once.\n *\n * @param tealCode The TEAL code\n * @returns The information about the compiled file\n * @example\n * ```typescript\n * const compiled = await appManager.compileTeal(tealProgram)\n * ```\n */\n async compileTeal(tealCode: string): Promise<CompiledTeal> {\n if (this._compilationResults[tealCode]) {\n return this._compilationResults[tealCode]\n }\n\n const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n const result = {\n teal: tealCode,\n compiled: compiled.result,\n compiledHash: compiled.hash,\n compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n sourceMap: new ProgramSourceMap(JSON.parse(algosdk.encodeJSON(compiled.sourcemap!))),\n }\n this._compilationResults[tealCode] = result\n\n return result\n }\n\n /**\n * Performs template substitution of a teal template and compiles it, returning the compiled result.\n *\n * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n * if deployment metadata is specified.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * @param tealTemplateCode The TEAL logic to compile\n * @param templateParams Any parameters to replace in the .teal file before compiling\n * @param deploymentMetadata The deployment metadata the app will be deployed with\n * @returns The information about the compiled code\n * @example\n * ```typescript\n * const compiled = await appManager.compileTealTemplate(tealTemplate, { TMPL_APP_ID: 12345n }, { updatable: true, deletable: false })\n * ```\n */\n async compileTealTemplate(\n tealTemplateCode: string,\n templateParams?: TealTemplateParams,\n deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n ): Promise<CompiledTeal> {\n let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n if (deploymentMetadata) {\n tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n }\n\n return await this.compileTeal(tealCode)\n }\n\n /**\n * Returns a previous compilation result.\n * @param tealCode The TEAL code\n * @returns The information about the previously compiled file\n * or `undefined` if that TEAL code wasn't previously compiled\n * @example\n * ```typescript\n * const compiled = appManager.getCompilationResult(tealProgram)\n * ```\n */\n getCompilationResult(tealCode: string): CompiledTeal | undefined {\n return this._compilationResults[tealCode]\n }\n\n /**\n * Returns the current app information for the app with the given ID.\n *\n * @example\n * ```typescript\n * const appInfo = await appManager.getById(12353n);\n * ```\n *\n * @param appId The ID of the app\n * @returns The app information\n */\n public async getById(appId: bigint): Promise<AppInformation> {\n const app = await this._algod.getApplicationByID(Number(appId)).do()\n return {\n appId: BigInt(app.id),\n appAddress: algosdk.getApplicationAddress(app.id),\n approvalProgram: app.params.approvalProgram,\n clearStateProgram: app.params.clearStateProgram,\n creator: app.params.creator,\n localInts: Number(app.params.localStateSchema?.numUint ?? 0),\n localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),\n globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),\n globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),\n extraProgramPages: Number(app.params.extraProgramPages ?? 0),\n globalState: AppManager.decodeAppState(app.params.globalState ?? []),\n }\n }\n\n /**\n * Returns the current global state values for the given app ID and account address\n *\n * @param appId The ID of the app to return global state for\n * @returns The current global state for the given app\n * @example\n * ```typescript\n * const globalState = await appManager.getGlobalState(12353n);\n * ```\n */\n public async getGlobalState(appId: bigint) {\n return (await this.getById(appId)).globalState\n }\n\n /**\n * Returns the current local state values for the given app ID and account address\n *\n * @param appId The ID of the app to return local state for\n * @param address The string address of the account to get local state for the given app\n * @returns The current local state for the given (app, account) combination\n * @example\n * ```typescript\n * const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');\n * ```\n */\n public async getLocalState(appId: bigint, address: Address | string) {\n const appInfo = await this._algod.accountApplicationInformation(address, appId).do()\n\n if (!appInfo.appLocalState?.keyValue) {\n throw new Error(\"Couldn't find local state\")\n }\n\n return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n }\n\n /**\n * Returns the names of the current boxes for the given app.\n * @param appId The ID of the app return box names for\n * @returns The current box names\n * @example\n * ```typescript\n * const boxNames = await appManager.getBoxNames(12353n);\n * ```\n */\n public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n const boxResult = await this._algod.getApplicationBoxes(appId).do()\n return boxResult.boxes.map((b) => {\n return {\n nameRaw: b.name,\n nameBase64: Buffer.from(b.name).toString('base64'),\n name: Buffer.from(b.name).toString('utf-8'),\n }\n })\n }\n\n /**\n * Returns the value of the given box name for the given app.\n * @param appId The ID of the app return box names for\n * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n * @returns The current box value as a byte array\n * @example\n * ```typescript\n * const boxValue = await appManager.getBoxValue(12353n, 'boxName');\n * ```\n */\n public async getBoxValue(appId: bigint, boxName: BoxIdentifier | BoxName): Promise<Uint8Array> {\n const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName\n const name = AppManager.getBoxReference(boxId).name\n const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n return boxResult.value\n }\n\n /**\n * Returns the value of the given box names for the given app.\n * @param appId The ID of the app return box names for\n * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n * @returns The current box values as a byte array in the same order as the passed in box names\n * @example\n * ```typescript\n * const boxValues = await appManager.getBoxValues(12353n, ['boxName1', 'boxName2']);\n * ```\n */\n public async getBoxValues(appId: bigint, boxNames: (BoxIdentifier | BoxName)[]): Promise<Uint8Array[]> {\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n }\n\n /**\n * Returns the value of the given box name for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box value as an ABI value\n * @example\n * ```typescript\n * const boxValue = await appManager.getBoxValueFromABIType({ appId: 12353n, boxName: 'boxName', type: new ABIUintType(32) });\n * ```\n */\n public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n const { appId, boxName, type } = request\n const value = await this.getBoxValue(appId, boxName)\n return type.decode(value)\n }\n\n /**\n * Returns the value of the given box names for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box values as an ABI value in the same order as the passed in box names\n * @example\n * ```typescript\n * const boxValues = await appManager.getBoxValuesFromABIType({ appId: 12353n, boxNames: ['boxName1', 'boxName2'], type: new ABIUintType(32) });\n * ```\n */\n public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n const { appId, boxNames, type } = request\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n }\n\n /**\n * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n * @param boxId The box to return a reference for\n * @returns The box reference ready to pass into a `algosdk.Transaction`\n * @example\n * ```typescript\n * const boxRef = AppManager.getBoxReference('boxName');\n * ```\n */\n public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n return {\n appIndex: ref.appId,\n name: typeof ref.name === 'string' ? new TextEncoder().encode(ref.name) : 'length' in ref.name ? ref.name : ref.name.addr.publicKey,\n } as algosdk.BoxReference\n }\n\n /**\n * Converts an array of global/local state values from the algod api to a more friendly\n * generic object keyed by the UTF-8 value of the key.\n * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n * @example\n * ```typescript\n * const stateValues = AppManager.decodeAppState(state);\n * ```\n */\n public static decodeAppState(state: { key: Uint8Array; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n const stateValues = {} as AppState\n\n // Start with empty set\n for (const stateVal of state) {\n const keyBase64 = Buffer.from(stateVal.key).toString('base64')\n const keyRaw = stateVal.key\n const key = Buffer.from(stateVal.key).toString('utf-8')\n const tealValue = stateVal.value\n\n const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n let valueBase64: string\n let valueRaw: Buffer\n switch (dataTypeFlag) {\n case 1:\n valueBase64 =\n typeof tealValue.bytes === 'string' ? tealValue.bytes : tealValue.bytes ? Buffer.from(tealValue.bytes).toString('base64') : ''\n valueRaw = Buffer.from(valueBase64, 'base64')\n stateValues[key] = {\n keyRaw,\n keyBase64,\n valueRaw: new Uint8Array(valueRaw),\n valueBase64: valueBase64,\n value: valueRaw.toString('utf-8'),\n }\n break\n case 2: {\n const value = tealValue.uint ?? 0\n stateValues[key] = {\n keyRaw,\n keyBase64,\n value: BigInt(value),\n }\n break\n }\n default:\n throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n }\n }\n\n return stateValues\n }\n\n /**\n * Returns any ABI return values for the given app call arguments and transaction confirmation.\n * @param confirmation The transaction confirmation from algod\n * @param method The ABI method\n * @returns The return value for the method call\n * @example\n * ```typescript\n * const returnValue = AppManager.getABIReturn(confirmation, ABIMethod.fromSignature('hello(string)void'));\n * ```\n */\n public static getABIReturn(\n confirmation: modelsv2.PendingTransactionResponse | undefined,\n method: algosdk.ABIMethod | undefined,\n ): ABIReturn | undefined {\n if (!method || !confirmation || method.returns.type === 'void') {\n return undefined\n }\n\n // The parseMethodResponse method mutates the second parameter :(\n const resultDummy: algosdk.ABIResult = {\n txID: '',\n method,\n rawReturnValue: new Uint8Array(),\n }\n return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation), method.returns.type)\n }\n\n /**\n * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * Note: If these values are defined, but the corresponding `TMPL_*` value\n * isn't in the teal code it will throw an exception.\n *\n * @param tealTemplateCode The TEAL template code to substitute\n * @param params The deploy-time deployment control parameter value to replace\n * @returns The replaced TEAL code\n * @example\n * ```typescript\n * const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false });\n * ```\n */\n static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n if (params.updatable !== undefined) {\n if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n }\n\n if (params.deletable !== undefined) {\n if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n }\n\n return tealTemplateCode\n }\n\n /**\n * Performs template substitution of a teal file.\n *\n * Looks for `TMPL_{parameter}` for template replacements.\n *\n * @param tealTemplateCode The TEAL template code to make parameter replacements in\n * @param templateParams Any parameters to replace in the teal code\n * @returns The TEAL code with replacements\n * @example\n * ```typescript\n * const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });\n * ```\n */\n static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n if (templateParams !== undefined) {\n for (const key in templateParams) {\n const value = templateParams[key]\n const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n // If this is a number, first replace any byte representations of the number\n // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n if (typeof value === 'number' || typeof value === 'bigint') {\n tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n }\n\n tealTemplateCode = replaceTemplateVariable(\n tealTemplateCode,\n token,\n typeof value === 'string'\n ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n : ArrayBuffer.isView(value)\n ? `0x${Buffer.from(value).toString('hex')}`\n : value.toString(),\n )\n }\n }\n\n return tealTemplateCode\n }\n\n /**\n * Remove comments from TEAL code (useful to reduce code size before compilation).\n *\n * @param tealCode The TEAL logic to strip\n * @returns The TEAL without comments\n * @example\n * ```typescript\n * const stripped = AppManager.stripTealComments(tealProgram);\n * ```\n */\n static stripTealComments(tealCode: string) {\n const stripCommentFromLine = (line: string) => {\n const commentIndex = findUnquotedString(line, '//')\n if (commentIndex === undefined) {\n return line\n }\n return line.slice(0, commentIndex).trimEnd()\n }\n\n return tealCode\n .split('\\n')\n .map((line) => stripCommentFromLine(line))\n .join('\\n')\n }\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n let index = startIndex\n let inQuotes = false\n let inBase64 = false\n\n while (index < endIndex) {\n const currentChar = line[index]\n if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n // enter base64\n inBase64 = true\n } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n // exit base64\n inBase64 = false\n } else if (currentChar === '\\\\' && inQuotes) {\n // escaped char, skip next character\n index += 1\n } else if (currentChar === '\"') {\n // quote boundary\n inQuotes = !inQuotes\n } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n // can test for match\n return index\n }\n index += 1\n }\n return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n try {\n const tokens = line.slice(0, index).split(/\\s+/)\n const last = tokens[tokens.length - 1]\n return ['base64', 'b64'].includes(last)\n } catch {\n return false\n }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n const result: string[] = []\n const tokenIndexOffset = replacement.length - token.length\n\n const programLines = program.split('\\n')\n\n for (const line of programLines) {\n const _commentIndex = findUnquotedString(line, '//')\n const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n let code = line.substring(0, commentIndex)\n const comment = line.substring(commentIndex)\n let trailingIndex = 0\n\n while (true) {\n const tokenIndex = findTemplateToken(code, token, trailingIndex)\n if (tokenIndex === undefined) {\n break\n }\n trailingIndex = tokenIndex + token.length\n const prefix = code.substring(0, tokenIndex)\n const suffix = code.substring(trailingIndex)\n code = `${prefix}${replacement}${suffix}`\n trailingIndex += tokenIndexOffset\n }\n result.push(code + comment)\n }\n\n return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n let index = startIndex\n while (index < endIndex) {\n const tokenIndex = findUnquotedString(line, token, index, endIndex)\n if (tokenIndex === undefined) {\n break\n }\n const trailingIndex = tokenIndex + token.length\n if (\n (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n ) {\n return tokenIndex\n }\n index = trailingIndex\n }\n return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"],"names":["ProgramSourceMap","getABIReturnValue","UPDATABLE_TEMPLATE_NAME","DELETABLE_TEMPLATE_NAME"],"mappings":";;;;;;AAgGA;MACa,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,KAAsB,EAAA;QAN1B,IAAmB,CAAA,mBAAA,GAAiC,EAAE;AAO5D,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGrB;;;;;;;;;;;;;;AAcG;IACH,MAAM,WAAW,CAAC,QAAgB,EAAA;AAChC,QAAA,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;AACtC,YAAA,OAAO,IAAI,CAAC,mBA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C,MAAM;AAC/C,QAAA,IACE,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;AACjE,aAAC,aAAa,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAC7E;AACA,YAAA,OAAO,UAAU;;QAEnB,KAAK,GAAG,aAAa;;AAEvB,IAAA,OAAO,SAAS;AAClB,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAY,EAAA;AACzC,IAAA,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,CAAC;AAC/D;;;;"}
1
+ {"version":3,"file":"app-manager.js","sources":["../../src/types/app-manager.ts"],"sourcesContent":["import algosdk, { Address, ProgramSourceMap } from 'algosdk'\nimport { getABIReturnValue } from '../transaction/transaction'\nimport { TransactionSignerAccount } from './account'\nimport {\n BoxName,\n DELETABLE_TEMPLATE_NAME,\n UPDATABLE_TEMPLATE_NAME,\n type ABIReturn,\n type AppState,\n type CompiledTeal,\n type TealTemplateParams,\n} from './app'\nimport modelsv2 = algosdk.modelsv2\n\n/** Information about an app. */\nexport interface AppInformation {\n /** The ID of the app. */\n appId: bigint\n /** The escrow address that the app operates with. */\n appAddress: Address\n /**\n * Approval program.\n */\n approvalProgram: Uint8Array\n /**\n * Clear state program.\n */\n clearStateProgram: Uint8Array\n /**\n * The address that created this application. This is the address where the\n * parameters and global state for this application can be found.\n */\n creator: Address\n /**\n * Current global state values.\n */\n globalState: AppState\n /** The number of allocated ints in per-user local state. */\n localInts: number\n /** The number of allocated byte slices in per-user local state. */\n localByteSlices: number\n /** The number of allocated ints in global state. */\n globalInts: number\n /** The number of allocated byte slices in global state. */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract. */\n extraProgramPages?: number\n}\n\n/**\n * Something that identifies an app box name - either a:\n * * `Uint8Array` (the actual binary of the box name)\n * * `string` (that will be encoded to a `Uint8Array`)\n * * `TransactionSignerAccount` (that will be encoded into the\n * public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | TransactionSignerAccount\n\n/**\n * A grouping of the app ID and name identifier to reference an app box.\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: bigint\n /**\n * Identifier for a box name\n */\n name: BoxIdentifier\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: BoxIdentifier\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: bigint\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: BoxIdentifier[]\n /** The ABI type to decode the value using */\n type: algosdk.ABIType\n}\n\n/**\n * Defines a holding by referring to an Address and Asset it belongs to.\n */\nexport interface HoldingReference {\n /** Asset ID for asset in access list. */\n assetId: bigint\n /** Address in access list, or the sender of the transaction. */\n address: string | Address\n}\n\n/**\n * Defines a local state by referring to an Address and App it belongs to.\n */\nexport interface LocalsReference {\n /** Application ID for app in access list, or zero if referring to the called application. */\n appId: bigint\n /** Address in access list, or the sender of the transaction. */\n address: string | Address\n}\n\n/**\n * Names a single resource reference. Only one of the fields should be set.\n */\nexport interface AccessReference {\n /** Any account addresses whose balance record is accessible by the executing ApprovalProgram or ClearStateProgram. */\n address?: string | Address\n /** Application ID whose GlobalState may be read by the executing ApprovalProgram or ClearStateProgram. */\n appId?: bigint\n /** Asset ID whose AssetParams may be read by the executing ApprovalProgram or ClearStateProgram. */\n assetId?: bigint\n /** Defines a holding by referring to an Address and Asset it belongs to. */\n holding?: HoldingReference\n /** Defines a local state by referring to an Address and App it belongs to. */\n locals?: LocalsReference\n /** Defines a box by its name and the application ID it belongs to. */\n box?: BoxReference\n}\n\n/** Allows management of application information. */\nexport class AppManager {\n private _algod: algosdk.Algodv2\n private _compilationResults: Record<string, CompiledTeal> = {}\n\n /**\n * Creates an `AppManager`\n * @param algod An algod instance\n */\n constructor(algod: algosdk.Algodv2) {\n this._algod = algod\n }\n\n /**\n * Compiles the given TEAL using algod and returns the result, including source map.\n *\n * The result of this compilation is also cached keyed by the TEAL\n * code so it can be retrieved via `getCompilationResult`.\n *\n * This function is re-entrant; it will only compile the same code once.\n *\n * @param tealCode The TEAL code\n * @returns The information about the compiled file\n * @example\n * ```typescript\n * const compiled = await appManager.compileTeal(tealProgram)\n * ```\n */\n async compileTeal(tealCode: string): Promise<CompiledTeal> {\n if (this._compilationResults[tealCode]) {\n return this._compilationResults[tealCode]\n }\n\n const compiled = await this._algod.compile(tealCode).sourcemap(true).do()\n const result = {\n teal: tealCode,\n compiled: compiled.result,\n compiledHash: compiled.hash,\n compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),\n sourceMap: new ProgramSourceMap(JSON.parse(algosdk.encodeJSON(compiled.sourcemap!))),\n }\n this._compilationResults[tealCode] = result\n\n return result\n }\n\n /**\n * Performs template substitution of a teal template and compiles it, returning the compiled result.\n *\n * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters\n * if deployment metadata is specified.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * @param tealTemplateCode The TEAL logic to compile\n * @param templateParams Any parameters to replace in the .teal file before compiling\n * @param deploymentMetadata The deployment metadata the app will be deployed with\n * @returns The information about the compiled code\n * @example\n * ```typescript\n * const compiled = await appManager.compileTealTemplate(tealTemplate, { TMPL_APP_ID: 12345n }, { updatable: true, deletable: false })\n * ```\n */\n async compileTealTemplate(\n tealTemplateCode: string,\n templateParams?: TealTemplateParams,\n deploymentMetadata?: { updatable?: boolean; deletable?: boolean },\n ): Promise<CompiledTeal> {\n let tealCode = AppManager.stripTealComments(tealTemplateCode)\n\n tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams)\n\n if (deploymentMetadata) {\n tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata)\n }\n\n return await this.compileTeal(tealCode)\n }\n\n /**\n * Returns a previous compilation result.\n * @param tealCode The TEAL code\n * @returns The information about the previously compiled file\n * or `undefined` if that TEAL code wasn't previously compiled\n * @example\n * ```typescript\n * const compiled = appManager.getCompilationResult(tealProgram)\n * ```\n */\n getCompilationResult(tealCode: string): CompiledTeal | undefined {\n return this._compilationResults[tealCode]\n }\n\n /**\n * Returns the current app information for the app with the given ID.\n *\n * @example\n * ```typescript\n * const appInfo = await appManager.getById(12353n);\n * ```\n *\n * @param appId The ID of the app\n * @returns The app information\n */\n public async getById(appId: bigint): Promise<AppInformation> {\n const app = await this._algod.getApplicationByID(Number(appId)).do()\n return {\n appId: BigInt(app.id),\n appAddress: algosdk.getApplicationAddress(app.id),\n approvalProgram: app.params.approvalProgram,\n clearStateProgram: app.params.clearStateProgram,\n creator: app.params.creator,\n localInts: Number(app.params.localStateSchema?.numUint ?? 0),\n localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),\n globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),\n globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),\n extraProgramPages: Number(app.params.extraProgramPages ?? 0),\n globalState: AppManager.decodeAppState(app.params.globalState ?? []),\n }\n }\n\n /**\n * Returns the current global state values for the given app ID and account address\n *\n * @param appId The ID of the app to return global state for\n * @returns The current global state for the given app\n * @example\n * ```typescript\n * const globalState = await appManager.getGlobalState(12353n);\n * ```\n */\n public async getGlobalState(appId: bigint) {\n return (await this.getById(appId)).globalState\n }\n\n /**\n * Returns the current local state values for the given app ID and account address\n *\n * @param appId The ID of the app to return local state for\n * @param address The string address of the account to get local state for the given app\n * @returns The current local state for the given (app, account) combination\n * @example\n * ```typescript\n * const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');\n * ```\n */\n public async getLocalState(appId: bigint, address: Address | string) {\n const appInfo = await this._algod.accountApplicationInformation(address, appId).do()\n\n if (!appInfo.appLocalState?.keyValue) {\n throw new Error(\"Couldn't find local state\")\n }\n\n return AppManager.decodeAppState(appInfo.appLocalState.keyValue)\n }\n\n /**\n * Returns the names of the current boxes for the given app.\n * @param appId The ID of the app return box names for\n * @returns The current box names\n * @example\n * ```typescript\n * const boxNames = await appManager.getBoxNames(12353n);\n * ```\n */\n public async getBoxNames(appId: bigint): Promise<BoxName[]> {\n const boxResult = await this._algod.getApplicationBoxes(appId).do()\n return boxResult.boxes.map((b) => {\n return {\n nameRaw: b.name,\n nameBase64: Buffer.from(b.name).toString('base64'),\n name: Buffer.from(b.name).toString('utf-8'),\n }\n })\n }\n\n /**\n * Returns the value of the given box name for the given app.\n * @param appId The ID of the app return box names for\n * @param boxName The name of the box to return either as a string, binary array or `BoxName`\n * @returns The current box value as a byte array\n * @example\n * ```typescript\n * const boxValue = await appManager.getBoxValue(12353n, 'boxName');\n * ```\n */\n public async getBoxValue(appId: bigint, boxName: BoxIdentifier | BoxName): Promise<Uint8Array> {\n const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName\n const name = AppManager.getBoxReference(boxId).name\n const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do()\n return boxResult.value\n }\n\n /**\n * Returns the value of the given box names for the given app.\n * @param appId The ID of the app return box names for\n * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`\n * @returns The current box values as a byte array in the same order as the passed in box names\n * @example\n * ```typescript\n * const boxValues = await appManager.getBoxValues(12353n, ['boxName1', 'boxName2']);\n * ```\n */\n public async getBoxValues(appId: bigint, boxNames: (BoxIdentifier | BoxName)[]): Promise<Uint8Array[]> {\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)))\n }\n\n /**\n * Returns the value of the given box name for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box value as an ABI value\n * @example\n * ```typescript\n * const boxValue = await appManager.getBoxValueFromABIType({ appId: 12353n, boxName: 'boxName', type: new ABIUintType(32) });\n * ```\n */\n public async getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue> {\n const { appId, boxName, type } = request\n const value = await this.getBoxValue(appId, boxName)\n return type.decode(value)\n }\n\n /**\n * Returns the value of the given box names for the given app decoded based on the given ABI type.\n * @param request The parameters for the box value request\n * @returns The current box values as an ABI value in the same order as the passed in box names\n * @example\n * ```typescript\n * const boxValues = await appManager.getBoxValuesFromABIType({ appId: 12353n, boxNames: ['boxName1', 'boxName2'], type: new ABIUintType(32) });\n * ```\n */\n public async getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]> {\n const { appId, boxNames, type } = request\n return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })))\n }\n\n /**\n * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.\n * @param boxId The box to return a reference for\n * @returns The box reference ready to pass into a `algosdk.Transaction`\n * @example\n * ```typescript\n * const boxRef = AppManager.getBoxReference('boxName');\n * ```\n */\n public static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference {\n const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId }\n return {\n appIndex: ref.appId,\n name: typeof ref.name === 'string' ? new TextEncoder().encode(ref.name) : 'length' in ref.name ? ref.name : ref.name.addr.publicKey,\n } as algosdk.BoxReference\n }\n\n /**\n * Converts an array of global/local state values from the algod api to a more friendly\n * generic object keyed by the UTF-8 value of the key.\n * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`\n * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values\n * @example\n * ```typescript\n * const stateValues = AppManager.decodeAppState(state);\n * ```\n */\n public static decodeAppState(state: { key: Uint8Array; value: modelsv2.TealValue | modelsv2.EvalDelta }[]): AppState {\n const stateValues = {} as AppState\n\n // Start with empty set\n for (const stateVal of state) {\n const keyBase64 = Buffer.from(stateVal.key).toString('base64')\n const keyRaw = stateVal.key\n const key = Buffer.from(stateVal.key).toString('utf-8')\n const tealValue = stateVal.value\n\n const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type\n let valueBase64: string\n let valueRaw: Buffer\n switch (dataTypeFlag) {\n case 1:\n valueBase64 =\n typeof tealValue.bytes === 'string' ? tealValue.bytes : tealValue.bytes ? Buffer.from(tealValue.bytes).toString('base64') : ''\n valueRaw = Buffer.from(valueBase64, 'base64')\n stateValues[key] = {\n keyRaw,\n keyBase64,\n valueRaw: new Uint8Array(valueRaw),\n valueBase64: valueBase64,\n value: valueRaw.toString('utf-8'),\n }\n break\n case 2: {\n const value = tealValue.uint ?? 0\n stateValues[key] = {\n keyRaw,\n keyBase64,\n value: BigInt(value),\n }\n break\n }\n default:\n throw new Error(`Received unknown state data type of ${dataTypeFlag}`)\n }\n }\n\n return stateValues\n }\n\n /**\n * Returns any ABI return values for the given app call arguments and transaction confirmation.\n * @param confirmation The transaction confirmation from algod\n * @param method The ABI method\n * @returns The return value for the method call\n * @example\n * ```typescript\n * const returnValue = AppManager.getABIReturn(confirmation, ABIMethod.fromSignature('hello(string)void'));\n * ```\n */\n public static getABIReturn(\n confirmation: modelsv2.PendingTransactionResponse | undefined,\n method: algosdk.ABIMethod | undefined,\n ): ABIReturn | undefined {\n if (!method || !confirmation || method.returns.type === 'void') {\n return undefined\n }\n\n // The parseMethodResponse method mutates the second parameter :(\n const resultDummy: algosdk.ABIResult = {\n txID: '',\n method,\n rawReturnValue: new Uint8Array(),\n }\n return getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation), method.returns.type)\n }\n\n /**\n * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.\n *\n * * `TMPL_UPDATABLE` for updatability / immutability control\n * * `TMPL_DELETABLE` for deletability / permanence control\n *\n * Note: If these values are defined, but the corresponding `TMPL_*` value\n * isn't in the teal code it will throw an exception.\n *\n * @param tealTemplateCode The TEAL template code to substitute\n * @param params The deploy-time deployment control parameter value to replace\n * @returns The replaced TEAL code\n * @example\n * ```typescript\n * const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false });\n * ```\n */\n static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: { updatable?: boolean; deletable?: boolean }) {\n if (params.updatable !== undefined) {\n if (!tealTemplateCode.includes(UPDATABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time updatability control requested for app deployment, but ${UPDATABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString())\n }\n\n if (params.deletable !== undefined) {\n if (!tealTemplateCode.includes(DELETABLE_TEMPLATE_NAME)) {\n throw new Error(\n `Deploy-time deletability control requested for app deployment, but ${DELETABLE_TEMPLATE_NAME} not present in TEAL code`,\n )\n }\n tealTemplateCode = replaceTemplateVariable(tealTemplateCode, DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString())\n }\n\n return tealTemplateCode\n }\n\n /**\n * Performs template substitution of a teal file.\n *\n * Looks for `TMPL_{parameter}` for template replacements.\n *\n * @param tealTemplateCode The TEAL template code to make parameter replacements in\n * @param templateParams Any parameters to replace in the teal code\n * @returns The TEAL code with replacements\n * @example\n * ```typescript\n * const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });\n * ```\n */\n static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams) {\n if (templateParams !== undefined) {\n for (const key in templateParams) {\n const value = templateParams[key]\n const token = `TMPL_${key.replace(/^TMPL_/, '')}`\n\n // If this is a number, first replace any byte representations of the number\n // These may appear in the TEAL in order to circumvent int compression and preserve PC values\n if (typeof value === 'number' || typeof value === 'bigint') {\n tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`)\n\n // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both\n }\n\n tealTemplateCode = replaceTemplateVariable(\n tealTemplateCode,\n token,\n typeof value === 'string'\n ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`\n : ArrayBuffer.isView(value)\n ? `0x${Buffer.from(value).toString('hex')}`\n : value.toString(),\n )\n }\n }\n\n return tealTemplateCode\n }\n\n /**\n * Remove comments from TEAL code (useful to reduce code size before compilation).\n *\n * @param tealCode The TEAL logic to strip\n * @returns The TEAL without comments\n * @example\n * ```typescript\n * const stripped = AppManager.stripTealComments(tealProgram);\n * ```\n */\n static stripTealComments(tealCode: string) {\n const stripCommentFromLine = (line: string) => {\n const commentIndex = findUnquotedString(line, '//')\n if (commentIndex === undefined) {\n return line\n }\n return line.slice(0, commentIndex).trimEnd()\n }\n\n return tealCode\n .split('\\n')\n .map((line) => stripCommentFromLine(line))\n .join('\\n')\n }\n}\n\nfunction getHoldingReference(holdingReference: HoldingReference): algosdk.TransactionHoldingReference {\n return {\n assetIndex: holdingReference.assetId,\n address: typeof holdingReference.address === 'string' ? Address.fromString(holdingReference.address) : holdingReference.address!,\n } satisfies algosdk.TransactionHoldingReference\n}\n\nfunction getLocalsReference(localsReference: LocalsReference): algosdk.TransactionLocalsReference {\n return {\n appIndex: localsReference.appId,\n address: typeof localsReference.address === 'string' ? Address.fromString(localsReference.address) : localsReference.address!,\n } satisfies algosdk.TransactionLocalsReference\n}\n\n/**\n * Returns an `algosdk.TransactionResourceReference` given a `AccessReference`.\n */\nexport function getAccessReference(accessReference: AccessReference): algosdk.TransactionResourceReference {\n return {\n address: typeof accessReference.address === 'string' ? Address.fromString(accessReference.address) : accessReference.address,\n appIndex: accessReference.appId,\n assetIndex: accessReference.assetId,\n holding: accessReference.holding ? getHoldingReference(accessReference.holding) : undefined,\n locals: accessReference.locals ? getLocalsReference(accessReference.locals) : undefined,\n box: accessReference.box ? AppManager.getBoxReference(accessReference.box) : undefined,\n } as algosdk.TransactionResourceReference\n}\n\n/**\n * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.\n * Returns undefined if not found\n */\nconst findUnquotedString = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n let index = startIndex\n let inQuotes = false\n let inBase64 = false\n\n while (index < endIndex) {\n const currentChar = line[index]\n if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {\n // enter base64\n inBase64 = true\n } else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {\n // exit base64\n inBase64 = false\n } else if (currentChar === '\\\\' && inQuotes) {\n // escaped char, skip next character\n index += 1\n } else if (currentChar === '\"') {\n // quote boundary\n inQuotes = !inQuotes\n } else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {\n // can test for match\n return index\n }\n index += 1\n }\n return undefined\n}\n\nconst lastTokenBase64 = (line: string, index: number): boolean => {\n try {\n const tokens = line.slice(0, index).split(/\\s+/)\n const last = tokens[tokens.length - 1]\n return ['base64', 'b64'].includes(last)\n } catch {\n return false\n }\n}\n\nfunction replaceTemplateVariable(program: string, token: string, replacement: string): string {\n const result: string[] = []\n const tokenIndexOffset = replacement.length - token.length\n\n const programLines = program.split('\\n')\n\n for (const line of programLines) {\n const _commentIndex = findUnquotedString(line, '//')\n const commentIndex = _commentIndex === undefined ? line.length : _commentIndex\n let code = line.substring(0, commentIndex)\n const comment = line.substring(commentIndex)\n let trailingIndex = 0\n\n while (true) {\n const tokenIndex = findTemplateToken(code, token, trailingIndex)\n if (tokenIndex === undefined) {\n break\n }\n trailingIndex = tokenIndex + token.length\n const prefix = code.substring(0, tokenIndex)\n const suffix = code.substring(trailingIndex)\n code = `${prefix}${replacement}${suffix}`\n trailingIndex += tokenIndexOffset\n }\n result.push(code + comment)\n }\n\n return result.join('\\n')\n}\n\nconst findTemplateToken = (line: string, token: string, startIndex: number = 0, _endIndex?: number): number | undefined => {\n const endIndex = _endIndex === undefined ? line.length : _endIndex\n\n let index = startIndex\n while (index < endIndex) {\n const tokenIndex = findUnquotedString(line, token, index, endIndex)\n if (tokenIndex === undefined) {\n break\n }\n const trailingIndex = tokenIndex + token.length\n if (\n (tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&\n (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))\n ) {\n return tokenIndex\n }\n index = trailingIndex\n }\n return undefined\n}\n\nfunction isValidTokenCharacter(char: string): boolean {\n return char.length === 1 && (/\\w/.test(char) || char === '_')\n}\n"],"names":["ProgramSourceMap","getABIReturnValue","UPDATABLE_TEMPLATE_NAME","DELETABLE_TEMPLATE_NAME","Address"],"mappings":";;;;;;AAsIA;MACa,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,KAAsB,EAAA;QAN1B,IAAmB,CAAA,mBAAA,GAAiC,EAAE;AAO5D,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGrB;;;;;;;;;;;;;;AAcG;IACH,MAAM,WAAW,CAAC,QAAgB,EAAA;AAChC,QAAA,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,EAAE;AACtC,YAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;;AAG3C,QAAA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE;AACzE,QAAA,MAAM,MAAM,GAAG;AACb,YAAA,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,QAAQ,CAAC,MAAM;YACzB,YAAY,EAAE,QAAQ,CAAC,IAAI;AAC3B,YAAA,qBAAqB,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAA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ourceMap } from 'algosdk';
1
+ import algosdk, { ProgramSourceMap, Address } from 'algosdk';
2
2
  import { getABIReturnValue } from '../transaction/transaction.mjs';
3
3
  import { UPDATABLE_TEMPLATE_NAME, DELETABLE_TEMPLATE_NAME } from './app.mjs';
4
4
 
@@ -390,6 +390,31 @@ class AppManager {
390
390
  .join('\n');
391
391
  }
392
392
  }
393
+ function getHoldingReference(holdingReference) {
394
+ return {
395
+ assetIndex: holdingReference.assetId,
396
+ address: typeof holdingReference.address === 'string' ? Address.fromString(holdingReference.address) : holdingReference.address,
397
+ };
398
+ }
399
+ function getLocalsReference(localsReference) {
400
+ return {
401
+ appIndex: localsReference.appId,
402
+ address: typeof localsReference.address === 'string' ? Address.fromString(localsReference.address) : localsReference.address,
403
+ };
404
+ }
405
+ /**
406
+ * Returns an `algosdk.TransactionResourceReference` given a `AccessReference`.
407
+ */
408
+ function getAccessReference(accessReference) {
409
+ return {
410
+ address: typeof accessReference.address === 'string' ? Address.fromString(accessReference.address) : accessReference.address,
411
+ appIndex: accessReference.appId,
412
+ assetIndex: accessReference.assetId,
413
+ holding: accessReference.holding ? getHoldingReference(accessReference.holding) : undefined,
414
+ locals: accessReference.locals ? getLocalsReference(accessReference.locals) : undefined,
415
+ box: accessReference.box ? AppManager.getBoxReference(accessReference.box) : undefined,
416
+ };
417
+ }
393
418
  /**
394
419
  * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.
395
420
  * Returns undefined if not found
@@ -481,5 +506,5 @@ function isValidTokenCharacter(char) {
481
506
  return char.length === 1 && (/\w/.test(char) || char === '_');
482
507
  }
483
508
 
484
- export { AppManager };
509
+ export { AppManager, getAccessReference };
485
510
  //# sourceMappingURL=app-manager.mjs.map