{"version":3,"file":"app.mjs","sources":["../../src/types/app.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Expand } from './expand'\nimport {\n  SendSingleTransactionResult,\n  SendTransactionFrom,\n  SendTransactionParams,\n  SendTransactionResult,\n  SendTransactionResults,\n  TransactionNote,\n  TransactionToSign,\n} from './transaction'\nimport ABIArgument = algosdk.ABIArgument\nimport ABIMethod = algosdk.ABIMethod\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIType = algosdk.ABIType\nimport ABIValue = algosdk.ABIValue\nimport Address = algosdk.Address\nimport OnApplicationComplete = algosdk.OnApplicationComplete\nimport SourceMap = algosdk.ProgramSourceMap\nimport SuggestedParams = algosdk.SuggestedParams\nimport Transaction = algosdk.Transaction\n\n/** The name of the TEAL template variable for deploy-time immutability control */\nexport const UPDATABLE_TEMPLATE_NAME = 'TMPL_UPDATABLE'\n\n/** The name of the TEAL template variable for deploy-time permanence control */\nexport const DELETABLE_TEMPLATE_NAME = 'TMPL_DELETABLE'\n\n/** The app create/update [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) transaction note prefix */\nexport const APP_DEPLOY_NOTE_DAPP = 'ALGOKIT_DEPLOYER'\n\n/** The maximum number of bytes in a single app code page */\nexport const APP_PAGE_MAX_SIZE = 2048\n\n/** First 4 bytes of SHA-512/256 hash of \"return\" for retrieving ABI return values */\nexport const ABI_RETURN_PREFIX = new Uint8Array([21, 31, 124, 117])\n\n/** Information about an Algorand app */\nexport interface AppReference {\n  /** The id of the app */\n  appId: number | bigint\n  /** The Algorand address of the account associated with the app */\n  appAddress: string\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxReference` instead.\n *\n * A grouping of the app ID and name of the box in an Uint8Array\n */\nexport interface BoxReference {\n  /**\n   * A unique application id\n   */\n  appId: number | bigint\n  /**\n   * Name of box to reference\n   */\n  name: BoxIdentifier\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxIdentifier` instead.\n *\n * Something that identifies a box name - either a:\n *  * `Uint8Array`\n *  * `string` (that will be encoded to a Uint8Array)\n *  * `SendTransactionFrom` (encoded into the public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | SendTransactionFrom\n\n/** Common app call arguments for ABI and non-ABI (raw) calls */\nexport interface CoreAppCallArgs {\n  /** The optional lease for the transaction */\n  lease?: string | Uint8Array\n  /** Any box references to load */\n  boxes?: (algosdk.BoxReference | BoxReference | BoxIdentifier)[]\n  /** The address of any accounts to load in */\n  accounts?: (string | Address)[]\n  /** IDs of any apps to load into the foreignApps array */\n  apps?: number[]\n  /** IDs of any assets to load into the foreignAssets array */\n  assets?: number[]\n  /** Optional account / account address that should be authorised to transact on behalf of the from account the app call is sent from after this transaction.\n   *\n   * **Note:** Use with extreme caution and review the [official rekey guidance](https://dev.algorand.co/concepts/accounts/rekeying) first.\n   */\n  rekeyTo?: SendTransactionFrom | string\n}\n\n/**\n * App call args with non-ABI (raw) values (minus some processing like encoding strings as binary)\n */\nexport interface RawAppCallArgs extends CoreAppCallArgs {\n  /** Any application arguments to pass through */\n  appArgs?: (Uint8Array | string)[]\n  /** Property to aid intellisense */\n  method?: undefined\n}\n\n/** An argument for an ABI method, either a primitive value, or a transaction with or without signer, or the unawaited async return value of an algokit method that returns a `SendTransactionResult` */\nexport type ABIAppCallArg =\n  | ABIArgument\n  | TransactionToSign\n  | Transaction\n  | Promise<SendTransactionResult>\n  | SendTransactionResult\n  | undefined\n\n/**\n * App call args for an ABI call\n */\nexport type ABIAppCallArgs = CoreAppCallArgs & {\n  /** The ABI method to call */\n  method: ABIMethodParams | ABIMethod\n  /** The ABI method args to pass in */\n  methodArgs: ABIAppCallArg[]\n}\n\n/** Arguments to pass to an app call either:\n *   * The raw app call values to pass through into the transaction (after processing); or\n *   * An ABI method definition (method and args)\n **/\nexport type AppCallArgs = RawAppCallArgs | ABIAppCallArgs\n\n/**\n * @deprecated Use `TransactionComposer` to construct create app transactions instead.\n *\n * Base interface for common data passed to an app create or update.\n */\ninterface CreateOrUpdateAppParams extends SendTransactionParams {\n  /** The account (with private key loaded) that will send the transaction */\n  from: SendTransactionFrom\n  /** The approval program as raw teal (string) or compiled teal, base 64 encoded as a byte array (Uint8Array) */\n  approvalProgram: Uint8Array | string\n  /** The clear state program as raw teal (string) or compiled teal, base 64 encoded as a byte array (Uint8Array) */\n  clearStateProgram: Uint8Array | string\n  /** Optional transaction parameters */\n  transactionParams?: SuggestedParams\n  /** The (optional) transaction note */\n  note?: TransactionNote\n  /** The arguments passed in to the app call */\n  args?: AppCallArgs\n}\n\n/**\n * @deprecated Use `TransactionComposer` to construct create app transactions instead.\n *\n * Parameters that are passed in when creating an app. */\nexport interface CreateAppParams extends CreateOrUpdateAppParams {\n  /** The storage schema to request for the created app */\n  schema: AppStorageSchema\n  /** Override the on-completion action for the create call; defaults to NoOp */\n  onCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n}\n\n/**\n * @deprecated Use `TransactionComposer` to construct update app transactions instead.\n *\n * Parameters that are passed in when updating an app. */\nexport interface UpdateAppParams extends CreateOrUpdateAppParams {\n  /** The id of the app to update */\n  appId: number | bigint\n}\n\n/**\n * @deprecated Use `algosdk.OnApplicationComplete` directly instead.\n *\n * The type of call / [on-completion action](https://dev.algorand.co/concepts/smart-contracts/overview#smart-contract-lifecycle) for a smart contract call.\n *\n * Equivalent of `algosdk.OnApplicationComplete`, but as a more convenient string enum.\n *\n * * `no_op`: Normal smart contract call, no special on-complete action\n * * `opt_in`: Opt-in to smart contract local storage\n * * `close_out`: Close-out local storage storage\n * * `clear_state`: Clear local storage state\n * * `update_application`: Update the smart contract\n * * `delete_application`: Delete the smart contract\n */\nexport type AppCallType = 'no_op' | 'opt_in' | 'close_out' | 'clear_state' | 'update_application' | 'delete_application'\n\n/** Parameters representing a call to an app. */\nexport interface AppCallParams extends SendTransactionParams {\n  /** The id of the app to call */\n  appId: number | bigint\n  /** The type of call, everything except create (see `createApp`) and update (see `updateApp`) */\n  callType: Exclude<AppCallType, 'update_application'> | Exclude<OnApplicationComplete, OnApplicationComplete.UpdateApplicationOC>\n  /** The account to make the call from */\n  from: SendTransactionFrom\n  /** Optional transaction parameters */\n  transactionParams?: SuggestedParams\n  /** The (optional) transaction note */\n  note?: TransactionNote\n  /** The arguments passed in to the app call */\n  args?: AppCallArgs\n}\n\n/** Parameters representing the storage schema of an app. */\nexport interface AppStorageSchema {\n  /** Restricts number of ints in per-user local state */\n  localInts: number\n  /** Restricts number of byte slices in per-user local state */\n  localByteSlices: number\n  /** Restricts number of ints in global state */\n  globalInts: number\n  /** Restricts number of byte slices in global state */\n  globalByteSlices: number\n  /** Any extra pages that are needed for the smart contract; if left blank then the right number of pages will be calculated based on the teal code size */\n  extraPages?: number\n}\n\n/** Information about a compiled teal program */\nexport interface CompiledTeal {\n  /** Original TEAL code */\n  teal: string\n  /** The compiled code */\n  compiled: string\n  /** The hash returned by the compiler */\n  compiledHash: string\n  /** The base64 encoded code as a byte array */\n  compiledBase64ToBytes: Uint8Array\n  /** Source map from the compilation */\n  sourceMap: SourceMap\n}\n\nexport interface AppCallTransactionResultOfType<T> extends SendTransactionResults, SendTransactionResult {\n  /** If an ABI method was called the processed return value */\n  return?: T\n}\n\n/** Result from calling an app */\nexport type AppCallTransactionResult = AppCallTransactionResultOfType<ABIReturn>\n\n/** The return value of an ABI method call */\nexport type ABIReturn =\n  | {\n      rawReturnValue: Uint8Array\n      returnValue: ABIValue\n      method: ABIMethod\n      decodeError: undefined\n    }\n  | { rawReturnValue?: undefined; returnValue?: undefined; method?: undefined; decodeError: Error }\n\n/**\n * The payload of the metadata to add to the transaction note when deploying an app, noting it will be prefixed with `APP_DEPLOY_NOTE_PREFIX`.\n */\nexport interface AppDeployMetadata {\n  /** The unique name identifier of the app within the creator account */\n  name: string\n  /** The version of app that is / will be deployed */\n  version: string\n  /** Whether or not the app is deletable / permanent / unspecified */\n  deletable?: boolean\n  /** Whether or not the app is updatable / immutable / unspecified */\n  updatable?: boolean\n}\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppReference, AppDeployMetadata {\n  /** The round the app was created */\n  createdRound: number\n  /** The last round that the app was updated */\n  updatedRound: number\n  /** The metadata when the app was created */\n  createdMetadata: AppDeployMetadata\n  /** Whether or not the app is deleted */\n  deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n  creator: Readonly<string>\n  apps: Readonly<{\n    [name: string]: AppMetadata\n  }>\n}\n\n/** Dictionary of deploy-time parameters to replace in a teal template.\n *\n * Note: Looks for `TMPL_{parameter}` for template replacements i.e. you can leave out the `TMPL_`.\n *\n */\nexport interface TealTemplateParams {\n  [key: string]: string | bigint | number | Uint8Array\n}\n\n/** What action to perform when deploying an app and an update is detected in the TEAL code */\nexport enum OnUpdate {\n  /** Fail the deployment */\n  Fail,\n  /** Update the app */\n  UpdateApp,\n  /** Delete the app and create a new one in its place */\n  ReplaceApp,\n  /** Create a new app */\n  AppendApp,\n}\n\n/** What action to perform when deploying an app and a breaking schema change is detected */\nexport enum OnSchemaBreak {\n  /** Fail the deployment */\n  Fail,\n  /** Delete the app and create a new one in its place */\n  ReplaceApp,\n  /** Create a new app */\n  AppendApp,\n}\n\n/** The parameters to deploy an app */\nexport interface AppDeploymentParams\n  extends Omit<CreateAppParams, 'onCompleteAction' | 'args' | 'note' | 'skipSending' | 'skipWaiting' | 'atc'> {\n  /** The deployment metadata */\n  metadata: AppDeployMetadata\n  /** Any deploy-time parameters to replace in the TEAL code */\n  deployTimeParams?: TealTemplateParams\n  /** What action to perform if a schema break is detected */\n  onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n  /** What action to perform if a TEAL update is detected */\n  onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n  /** Optional cached value of the existing apps for the given creator */\n  existingDeployments?: AppLookup\n  /** Any args to pass to any create transaction that is issued as part of deployment */\n  createArgs?: AppCallArgs\n  /** Override the on-completion action for the create call; defaults to NoOp */\n  createOnCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n  /** Any args to pass to any update transaction that is issued as part of deployment */\n  updateArgs?: AppCallArgs\n  /** Any args to pass to any delete transaction that is issued as part of deployment */\n  deleteArgs?: AppCallArgs\n}\n\n/** The result of compiling the approval and clear state TEAL programs for an app */\nexport interface AppCompilationResult {\n  /** The result of compiling the approval program */\n  compiledApproval: CompiledTeal\n  /** The result of compiling the clear state program */\n  compiledClear: CompiledTeal\n}\n\nexport type AppReturn<TReturn> = {\n  /** The ABI method call return value */\n  return?: TReturn\n}\n\n/** Result from sending a single app transaction. */\nexport type SendAppTransactionResult = Expand<\n  SendSingleTransactionResult & {\n    /** If an ABI method was called the processed return value */\n    return?: ABIReturn\n  }\n>\n\n/** Result from sending a single app transaction. */\nexport type SendAppUpdateTransactionResult = Expand<SendAppTransactionResult & Partial<AppCompilationResult>>\n\n/** Result from sending a single app transaction. */\nexport type SendAppCreateTransactionResult = Expand<\n  SendAppUpdateTransactionResult & {\n    /** The id of the created app */\n    appId: bigint\n    /** The Algorand address of the account associated with the app */\n    appAddress: Address\n  }\n>\n\n/** Object holding app state values */\nexport interface AppState {\n  [key: string]:\n    | {\n        value: bigint\n        keyRaw: Uint8Array\n        keyBase64: string\n      }\n    | {\n        value: string\n        valueRaw: Uint8Array\n        valueBase64: string\n        keyRaw: Uint8Array\n        keyBase64: string\n      }\n}\n\n/**\n * The name of a box storage box */\nexport interface BoxName {\n  /** Name in UTF-8 */\n  name: string\n  /** Name in binary bytes */\n  nameRaw: Uint8Array\n  /** Name in Base64 */\n  nameBase64: string\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxValueRequestParams` instead.\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: number | bigint\n  /** The name of the box to return either as a string, binary array or `BoxName` */\n  boxName: string | Uint8Array | BoxName\n  /** The ABI type to decode the value using */\n  type: ABIType\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxValuesRequestParams` instead.\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: number\n  /** The names of the boxes to return either as a string, binary array or BoxName` */\n  boxNames: (string | Uint8Array | BoxName)[]\n  /** The ABI type to decode the value using */\n  type: ABIType\n}\n"],"names":[],"mappings":"AAsBA;AACO,MAAM,uBAAuB,GAAG;AAEvC;AACO,MAAM,uBAAuB,GAAG;AAEvC;AACO,MAAM,oBAAoB,GAAG;AAEpC;AACO,MAAM,iBAAiB,GAAG;AAEjC;AACa,MAAA,iBAAiB,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC;AA2PlE;IACY;AAAZ,CAAA,UAAY,QAAQ,EAAA;;AAElB,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI;;AAEJ,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS;;AAET,IAAA,QAAA,CAAA,QAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU;;AAEV,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS;AACX,CAAC,EATW,QAAQ,KAAR,QAAQ,GASnB,EAAA,CAAA,CAAA;AAED;IACY;AAAZ,CAAA,UAAY,aAAa,EAAA;;AAEvB,IAAA,aAAA,CAAA,aAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI;;AAEJ,IAAA,aAAA,CAAA,aAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU;;AAEV,IAAA,aAAA,CAAA,aAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS;AACX,CAAC,EAPW,aAAa,KAAb,aAAa,GAOxB,EAAA,CAAA,CAAA;;;;"}