@metamask/delegation-core 0.4.0 → 1.1.0

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/delegation-core/dist/index.cjs","../src/internalUtils.ts","../src/returns.ts","../src/caveats/valueLte.ts","../src/caveats/timestamp.ts","../src/caveats/nativeTokenPeriodTransfer.ts","../src/caveats/exactCalldata.ts","../src/caveats/exactCalldataBatch.ts","../src/caveats/exactExecution.ts","../src/caveats/exactExecutionBatch.ts","../src/caveats/nativeTokenStreaming.ts","../src/caveats/nativeTokenTransferAmount.ts","../src/caveats/nativeTokenPayment.ts","../src/caveats/nativeBalanceChange.ts","../src/caveats/erc20Streaming.ts","../src/caveats/erc20TokenPeriodTransfer.ts","../src/caveats/erc20TransferAmount.ts","../src/caveats/erc20BalanceChange.ts","../src/caveats/erc721BalanceChange.ts","../src/caveats/erc721Transfer.ts","../src/caveats/erc1155BalanceChange.ts","../src/caveats/nonce.ts","../src/caveats/allowedCalldata.ts","../src/caveats/allowedMethods.ts","../src/caveats/allowedTargets.ts","../src/caveats/argsEqualityCheck.ts","../src/caveats/blockNumber.ts","../src/caveats/deployed.ts","../src/caveats/id.ts","../src/caveats/limitedCalls.ts","../src/caveats/multiTokenPeriod.ts","../src/caveats/ownershipTransfer.ts","../src/caveats/redeemer.ts","../src/caveats/specificActionERC20TransferBatch.ts","../src/delegation.ts"],"names":["encodeSingle","EXECUTION_ARRAY_ABI","TIMESTAMP_UPPER_BOUND_SECONDS","isHexString","bytesToHex"],"mappings":"AAAA;ACAA;AACE;AACA;AACA;AACA;AAAA,wCAEK;AAeA,IAAM,YAAA,EAAc,CAAC;AAAA,EAC1B,KAAA;AAAA,EACA;AACF,CAAA,EAAA,GAGc;AACZ,EAAA,OAAO,KAAA,CAAM,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,KAAA,EAAO,C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AA;AACzC,EAAA;AACuC,EAAA;AACzC;AA8BE;AAEgB,EAAA;AACoB,IAAA;AAClC,IAAA;AACE,MAAA;AACW,MAAA;AACA,MAAA;AACA,MAAA;AACoB,MAAA;AACpB,MAAA;AACb,IAAA;AACF,EAAA;AAC8B,EAAA;AACI,EAAA;AACpC;AAUkE;AAChC,EAAA;AACS,EAAA;AAEA,EAAA;AACf,IAAA;AACX,IAAA;AACK,MAAA;AAClB,IAAA;AACuC,IAAA;AACT,IAAA;AAChC,EAAA;AAEwB,EAAA;AAC1B;AAQyD;AAEvC,EAAA;AAEsB,EAAA;AAEtB,EAAA;AACkB,IAAA;AACG,IAAA;AACrC,EAAA;AAC8B,EAAA;AACvB,EAAA;AACT;AlCwlB2C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/delegation-core/dist/index.cjs","sourcesContent":[null,"import {\n bytesToHex,\n hexToBytes,\n isHexString,\n remove0x,\n type BytesLike,\n} from '@metamask/utils';\n\n/**\n * Converts a numeric value to a hexadecimal string with zero-padding, without 0x prefix.\n *\n * @param options - The options for the conversion.\n * @param options.value - The numeric value to convert to hex (bigint or number).\n * @param options.size - The size in bytes for the resulting hex string (each byte = 2 hex characters).\n * @returns A hexadecimal string prefixed with zeros to match the specified size.\n * @example\n * ```typescript\n * toHexString({ value: 255, size: 2 }) // Returns \"00ff\"\n * toHexString({ value: 16n, size: 1 }) // Returns \"10\"\n * ```\n */\nexport const toHexString = ({\n value,\n size,\n}: {\n value: bigint | number;\n size: number;\n}): string => {\n return value.toString(16).padStart(size * 2, '0');\n};\n\n/**\n * Normalizes a bytes-like value into a hex string.\n *\n * @param value - The value to normalize.\n * @param errorMessage - Error message used for invalid input.\n * @returns The normalized hex string (0x-prefixed).\n * @throws Error if the input is an invalid hex string.\n */\nexport const normalizeHex = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value)) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Normalizes an address into a hex string without changing casing.\n *\n * @param value - The address as a hex string or bytes.\n * @param errorMessage - Error message used for invalid input.\n * @returns The address as a 0x-prefixed hex string.\n * @throws Error if the input is not a 20-byte address.\n */\nexport const normalizeAddress = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value) || value.length !== 42) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n if (value.length !== 20) {\n throw new Error(errorMessage);\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Normalizes an address into a lowercased hex string.\n *\n * @param value - The address as a hex string or bytes.\n * @param errorMessage - Error message used for invalid input.\n * @returns The address as a lowercased 0x-prefixed hex string.\n * @throws Error if the input is not a 20-byte address.\n */\nexport const normalizeAddressLowercase = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value) || value.length !== 42) {\n throw new Error(errorMessage);\n }\n return bytesToHex(hexToBytes(value));\n }\n\n if (value.length !== 20) {\n throw new Error(errorMessage);\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Concatenates 0x-prefixed hex strings into a single 0x-prefixed hex string.\n *\n * @param parts - The hex string parts to concatenate.\n * @returns The concatenated hex string.\n */\nexport const concatHex = (parts: string[]): string => {\n return `0x${parts.map(remove0x).join('')}`;\n};\n","import { type BytesLike, bytesToHex, hexToBytes } from '@metamask/utils';\n\nimport type { Hex } from './types';\n\n/**\n * The possible return value types for encoding/decoding operations.\n */\nexport type ResultValue = 'hex' | 'bytes';\n\n/**\n * Utility type for function return types based on ResultValue.\n */\nexport type ResultType<TResultValue extends ResultValue> =\n TResultValue extends 'hex' ? Hex : Uint8Array;\n\n/**\n * Base options interface for operations that can return hex or bytes.\n */\nexport type EncodingOptions<TResultValue extends ResultValue> = {\n out: TResultValue;\n};\n\n/**\n * Default options value with proper typing. Use this as your default parameter.\n */\nexport const defaultOptions = { out: 'hex' } as EncodingOptions<any>;\n\n/**\n * Prepares a result by converting between hex and bytes based on options.\n *\n * @param result - The value to convert (either Uint8Array or Hex optionally prefixed with 0x).\n * @param options - The options specifying the desired output format.\n * @returns The converted value with proper type narrowing.\n */\nexport function prepareResult<TResultValue extends ResultValue>(\n result: Uint8Array | Hex | string,\n options: EncodingOptions<TResultValue>,\n): ResultType<TResultValue> {\n if (options.out === 'hex') {\n const hexValue = typeof result === 'string' ? result : bytesToHex(result);\n\n return hexValue.startsWith('0x')\n ? (hexValue as ResultType<TResultValue>)\n : (`0x${hexValue}` as ResultType<TResultValue>);\n }\n const bytesValue = result instanceof Uint8Array ? result : hexToBytes(result);\n return bytesValue as ResultType<TResultValue>;\n}\n\n/**\n * Converts a bytes-like value to a hex string.\n *\n * @param bytesLike - The bytes-like value to convert.\n * @returns The hex string representation of the bytes-like value.\n */\nexport const bytesLikeToHex = (bytesLike: BytesLike): Hex => {\n if (typeof bytesLike === 'string') {\n return bytesLike;\n }\n return bytesToHex(bytesLike);\n};\n\n/**\n * Converts a bytes-like value to a Uint8Array.\n *\n * @param bytesLike - The bytes-like value to convert.\n * @returns The Uint8Array representation of the bytes-like value.\n */\nexport const bytesLikeToBytes = (bytesLike: BytesLike): Uint8Array => {\n if (typeof bytesLike === 'string') {\n return hexToBytes(bytesLike);\n }\n return bytesLike;\n};\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a ValueLte caveat.\n */\nexport type ValueLteTerms = {\n /** The maximum value allowed for the transaction as a bigint. */\n maxValue: bigint;\n};\n\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxValue } = terms;\n\n if (maxValue < 0n) {\n throw new Error('Invalid maxValue: must be greater than or equal to zero');\n }\n const hexValue = toHexString({ value: maxValue, size: 32 });\n\n return prepareResult(hexValue, options);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (equivalent to January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a timestamp threshold for delegation usage.\n */\nexport type TimestampTerms = {\n /** The timestamp (in seconds) after which the delegation can be used. */\n timestampAfterThreshold: number;\n /** The timestamp (in seconds) before which the delegation can be used. */\n timestampBeforeThreshold: number;\n};\n\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each timestamp).\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each timestamp).\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { timestampAfterThreshold, timestampBeforeThreshold } = terms;\n\n if (timestampAfterThreshold < 0) {\n throw new Error(\n 'Invalid timestampAfterThreshold: must be zero or positive',\n );\n }\n\n if (timestampBeforeThreshold < 0) {\n throw new Error(\n 'Invalid timestampBeforeThreshold: must be zero or positive',\n );\n }\n\n if (timestampBeforeThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid timestampBeforeThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (timestampAfterThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid timestampAfterThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (\n timestampBeforeThreshold !== 0 &&\n timestampAfterThreshold >= timestampBeforeThreshold\n ) {\n throw new Error(\n 'Invalid thresholds: timestampBeforeThreshold must be greater than timestampAfterThreshold when both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({\n value: timestampAfterThreshold,\n size: 16,\n });\n const beforeThresholdHex = toHexString({\n value: timestampBeforeThreshold,\n size: 16,\n });\n\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a periodic transfer allowance of native tokens.\n */\nexport type NativeTokenPeriodTransferTerms = {\n /** The maximum amount that can be transferred within each period (in wei). */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused ETH is forfeited once the period ends.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 96-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 96-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { periodAmount, periodDuration, startDate } = terms;\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `0x${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldata caveat.\n */\nexport type ExactCalldataTerms = {\n /** The expected calldata to match against. */\n calldata: BytesLike;\n};\n\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { calldata } = terms;\n\n if (calldata === undefined || calldata === null) {\n throw new Error('Invalid calldata: calldata is required');\n }\n\n if (typeof calldata === 'string' && !calldata.startsWith('0x')) {\n throw new Error('Invalid calldata: must be a hex string starting with 0x');\n }\n\n // For exact calldata, the terms are simply the expected calldata\n return prepareResult(calldata, encodingOptions);\n}\n","import { encodeSingle } from '@metamask/abi-utils';\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldataBatch caveat.\n */\nexport type ExactCalldataBatchTerms = {\n /** The executions that must be matched exactly in the batch. */\n executions: {\n target: BytesLike;\n value: bigint;\n callData: BytesLike;\n }[];\n};\n\nconst EXECUTION_ARRAY_ABI = '(address,uint256,bytes)[]';\n\n/**\n * Creates terms for an ExactCalldataBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactCalldataBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldataBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactCalldataBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { executions } = terms;\n\n if (executions.length === 0) {\n throw new Error('Invalid executions: array cannot be empty');\n }\n\n const encodableExecutions = executions.map((execution) => {\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n return [targetHex, execution.value, callDataHex];\n });\n\n const hexValue = encodeSingle(EXECUTION_ARRAY_ABI, encodableExecutions);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactExecution caveat.\n */\nexport type ExactExecutionTerms = {\n /** The execution that must be matched exactly. */\n execution: {\n target: BytesLike;\n value: bigint;\n callData: BytesLike;\n };\n};\n\n/**\n * Creates terms for an ExactExecution caveat that matches a single execution.\n *\n * @param terms - The terms for the ExactExecution caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target + value + calldata.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactExecution caveat that matches a single execution.\n *\n * @param terms - The terms for the ExactExecution caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target + value + calldata.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { execution } = terms;\n\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n const valueHex = `0x${toHexString({ value: execution.value, size: 32 })}`;\n const hexValue = concatHex([targetHex, valueHex, callDataHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { encodeSingle } from '@metamask/abi-utils';\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactExecutionBatch caveat.\n */\nexport type ExactExecutionBatchTerms = {\n /** The executions that must be matched exactly in the batch. */\n executions: {\n target: BytesLike;\n value: bigint;\n callData: BytesLike;\n }[];\n};\n\nconst EXECUTION_ARRAY_ABI = '(address,uint256,bytes)[]';\n\n/**\n * Creates terms for an ExactExecutionBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactExecutionBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactExecutionBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactExecutionBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { executions } = terms;\n\n if (executions.length === 0) {\n throw new Error('Invalid executions: array cannot be empty');\n }\n\n const encodableExecutions = executions.map((execution) => {\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n return [targetHex, execution.value, callDataHex];\n });\n\n const hexValue = encodeSingle(EXECUTION_ARRAY_ABI, encodableExecutions);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of native tokens.\n */\nexport type NativeTokenStreamingTerms = {\n /** The initial amount available immediately (in wei). */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred (in wei). */\n maxAmount: bigint;\n /** The rate at which allowance increases per second (in wei). */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (128 bytes).\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { initialAmount, maxAmount, amountPerSecond, startTime } = terms;\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `0x${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a NativeTokenTransferAmount caveat.\n */\nexport type NativeTokenTransferAmountTerms = {\n /** The maximum amount of native tokens that can be transferred. */\n maxAmount: bigint;\n};\n\n/**\n * Creates terms for a NativeTokenTransferAmount caveat that caps native transfers.\n *\n * @param terms - The terms for the NativeTokenTransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if maxAmount is negative.\n */\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenTransferAmount caveat that caps native transfers.\n *\n * @param terms - The terms for the NativeTokenTransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if maxAmount is negative.\n */\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxAmount } = terms;\n\n if (maxAmount < 0n) {\n throw new Error('Invalid maxAmount: must be zero or positive');\n }\n\n const hexValue = `0x${toHexString({ value: maxAmount, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a NativeTokenPayment caveat.\n */\nexport type NativeTokenPaymentTerms = {\n /** The recipient address. */\n recipient: BytesLike;\n /** The amount that must be paid. */\n amount: bigint;\n};\n\n/**\n * Creates terms for a NativeTokenPayment caveat that requires a payment to a recipient.\n *\n * @param terms - The terms for the NativeTokenPayment caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as recipient + amount.\n * @throws Error if the recipient address is invalid or amount is not positive.\n */\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPayment caveat that requires a payment to a recipient.\n *\n * @param terms - The terms for the NativeTokenPayment caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as recipient + amount.\n * @throws Error if the recipient address is invalid or amount is not positive.\n */\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { recipient, amount } = terms;\n\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (amount <= 0n) {\n throw new Error('Invalid amount: must be positive');\n }\n\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n const hexValue = concatHex([recipientHex, amountHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring a NativeBalanceChange caveat.\n */\nexport type NativeBalanceChangeTerms = {\n /** The recipient address. */\n recipient: BytesLike;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for a NativeBalanceChange caveat that checks recipient balance changes.\n *\n * @param terms - The terms for the NativeBalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + recipient + balance.\n * @throws Error if the recipient address is invalid or balance/changeType are invalid.\n */\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeBalanceChange caveat that checks recipient balance changes.\n *\n * @param terms - The terms for the NativeBalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + recipient + balance.\n * @throws Error if the recipient address is invalid or balance/changeType are invalid.\n */\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { recipient, balance, changeType: changeTypeNumber } = terms;\n\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid Address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([changeTypeHex, recipientHex, balanceHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { type BytesLike, bytesToHex, isHexString } from '@metamask/utils';\n\nimport { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of ERC20 tokens.\n */\nexport type ERC20StreamingTerms = {\n /** The address of the ERC20 token contract. */\n tokenAddress: BytesLike;\n /** The initial amount available immediately. */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred. */\n maxAmount: bigint;\n /** The rate at which allowance increases per second. */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (160 bytes).\n * @throws Error if tokenAddress is invalid.\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 160-byte hex string.\n * @throws Error if any of the parameters are invalid.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, initialAmount, maxAmount, amountPerSecond, startTime } =\n terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { type BytesLike, isHexString, bytesToHex } from '@metamask/utils';\n\nimport { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a periodic transfer allowance of ERC20 tokens.\n */\nexport type ERC20TokenPeriodTransferTerms = {\n /** The address of the ERC20 token. */\n tokenAddress: BytesLike;\n /** The maximum amount that can be transferred within each period. */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused tokens are forfeited once the period ends.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, periodAmount, periodDuration, startDate } = terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ERC20TransferAmount caveat.\n */\nexport type ERC20TransferAmountTerms = {\n /** The ERC-20 token address. */\n tokenAddress: BytesLike;\n /** The maximum amount of tokens that can be transferred. */\n maxAmount: bigint;\n};\n\n/**\n * Creates terms for an ERC20TransferAmount caveat that caps transfer amount.\n *\n * @param terms - The terms for the ERC20TransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + maxAmount.\n * @throws Error if the token address is invalid or maxAmount is not positive.\n */\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TransferAmount caveat that caps transfer amount.\n *\n * @param terms - The terms for the ERC20TransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + maxAmount.\n * @throws Error if the token address is invalid or maxAmount is not positive.\n */\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, maxAmount } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n const maxAmountHex = `0x${toHexString({ value: maxAmount, size: 32 })}`;\n const hexValue = concatHex([tokenAddressHex, maxAmountHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC20BalanceChange caveat.\n */\nexport type ERC20BalanceChangeTerms = {\n /** The ERC-20 token address. */\n tokenAddress: BytesLike;\n /** The recipient address. */\n recipient: BytesLike;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC20BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC20BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC20BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n balance,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n balanceHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC721BalanceChange caveat.\n */\nexport type ERC721BalanceChangeTerms = {\n /** The ERC-721 token address. */\n tokenAddress: BytesLike;\n /** The recipient address. */\n recipient: BytesLike;\n /** The balance change amount. */\n amount: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC721BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC721BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + amount.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC721BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC721BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + amount.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n amount,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (amount <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n amountHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ERC721Transfer caveat.\n */\nexport type ERC721TransferTerms = {\n /** The ERC-721 token address. */\n tokenAddress: BytesLike;\n /** The token id. */\n tokenId: bigint;\n};\n\n/**\n * Creates terms for an ERC721Transfer caveat that restricts transfers to a token and id.\n *\n * @param terms - The terms for the ERC721Transfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + tokenId.\n * @throws Error if the token address is invalid or tokenId is negative.\n */\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC721Transfer caveat that restricts transfers to a token and id.\n *\n * @param terms - The terms for the ERC721Transfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + tokenId.\n * @throws Error if the token address is invalid or tokenId is negative.\n */\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, tokenId } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n\n if (tokenId < 0n) {\n throw new Error('Invalid tokenId: must be a non-negative number');\n }\n\n const tokenIdHex = `0x${toHexString({ value: tokenId, size: 32 })}`;\n const hexValue = concatHex([tokenAddressHex, tokenIdHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC1155BalanceChange caveat.\n */\nexport type ERC1155BalanceChangeTerms = {\n /** The ERC-1155 token address. */\n tokenAddress: BytesLike;\n /** The recipient address. */\n recipient: BytesLike;\n /** The token id. */\n tokenId: bigint;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC1155BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC1155BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + tokenId + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC1155BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC1155BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + tokenId + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n tokenId,\n balance,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n if (tokenId < 0n) {\n throw new Error('Invalid tokenId: must be a non-negative number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const tokenIdHex = `0x${toHexString({ value: tokenId, size: 32 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n tokenIdHex,\n balanceHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { isHexString } from '@metamask/utils';\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// char length of 32 byte hex string (including 0x prefix)\nconst MAX_NONCE_STRING_LENGTH = 66;\n\n/**\n * Terms for configuring a Nonce caveat.\n */\nexport type NonceTerms = {\n /** The nonce as BytesLike (0x-prefixed hex string or Uint8Array) to allow bulk revocation of delegations. */\n nonce: BytesLike;\n};\n\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the nonce is invalid.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte padded value in the specified encoding format.\n * @throws Error if the nonce is invalid or empty.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { nonce } = terms;\n\n // Handle zero-length Uint8Array specifically\n if (nonce instanceof Uint8Array && nonce.length === 0) {\n throw new Error('Invalid nonce: Uint8Array must not be empty');\n }\n\n // Validate that strings have 0x prefix (as required by BytesLike)\n if (typeof nonce === 'string' && !nonce.startsWith('0x')) {\n throw new Error('Invalid nonce: string must have 0x prefix');\n }\n\n // Convert to hex string for consistent processing\n const hexNonce = bytesLikeToHex(nonce);\n\n // Check for empty hex string (0x) first - more specific error\n if (hexNonce === '0x') {\n throw new Error('Invalid nonce: must not be empty');\n }\n\n if (!isHexString(hexNonce)) {\n throw new Error('Invalid nonce: must be a valid BytesLike value');\n }\n\n if (hexNonce.length > MAX_NONCE_STRING_LENGTH) {\n throw new Error('Invalid nonce: must be 32 bytes or less in length');\n }\n\n // Remove '0x' prefix for padding, then add it back\n const nonceWithoutPrefix = hexNonce.slice(2);\n const paddedNonce = nonceWithoutPrefix.padStart(64, '0'); // 64 hex chars = 32 bytes\n const hexValue = `0x${paddedNonce}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { bytesToHex, remove0x, type BytesLike } from '@metamask/utils';\n\nimport { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedCalldata caveat.\n */\nexport type AllowedCalldataTerms = {\n startIndex: number;\n value: BytesLike;\n};\n\n/**\n * Creates terms for an AllowedCalldata caveat that ensures the provided execution calldata\n * matches the expected calldata at the specified index.\n *\n * @param terms - The terms for the AllowedCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedCalldata caveat that ensures the provided execution calldata\n * matches the expected calldata at the specified index.\n *\n * @param terms - The terms for the AllowedCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { startIndex, value } = terms;\n\n if (startIndex < 0) {\n throw new Error('Invalid startIndex: must be zero or positive');\n }\n\n if (!Number.isInteger(startIndex)) {\n throw new Error('Invalid startIndex: must be a whole number');\n }\n\n let unprefixedValue: string;\n\n if (typeof value === 'string') {\n if (!value.startsWith('0x')) {\n throw new Error('Invalid value: must be a hex string starting with 0x');\n }\n unprefixedValue = remove0x(value);\n } else {\n unprefixedValue = remove0x(bytesToHex(value));\n }\n\n const indexHex = toHexString({ value: startIndex, size: 32 });\n\n // The terms are the index encoded as 32 bytes followed by the expected value.\n return prepareResult(`0x${indexHex}${unprefixedValue}`, encodingOptions);\n}\n","import { bytesToHex, isHexString, type BytesLike } from '@metamask/utils';\n\nimport { concatHex } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedMethods caveat.\n */\nexport type AllowedMethodsTerms = {\n /** An array of 4-byte method selectors that the delegate is allowed to call. */\n selectors: BytesLike[];\n};\n\nconst FUNCTION_SELECTOR_STRING_LENGTH = 10; // 0x + 8 hex chars\nconst INVALID_SELECTOR_ERROR =\n 'Invalid selector: must be a 4 byte hex string, abi function signature, or AbiFunction';\n\n/**\n * Creates terms for an AllowedMethods caveat that restricts calls to a set of method selectors.\n *\n * @param terms - The terms for the AllowedMethods caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated method selectors.\n * @throws Error if the selectors array is empty or contains invalid selectors.\n */\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedMethods caveat that restricts calls to a set of method selectors.\n *\n * @param terms - The terms for the AllowedMethods caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated method selectors.\n * @throws Error if the selectors array is empty or contains invalid selectors.\n */\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { selectors } = terms;\n\n if (!selectors || selectors.length === 0) {\n throw new Error('Invalid selectors: must provide at least one selector');\n }\n\n const normalizedSelectors = selectors.map((selector) => {\n if (typeof selector === 'string') {\n if (\n isHexString(selector) &&\n selector.length === FUNCTION_SELECTOR_STRING_LENGTH\n ) {\n return selector;\n }\n throw new Error(INVALID_SELECTOR_ERROR);\n }\n\n if (selector.length !== 4) {\n throw new Error(INVALID_SELECTOR_ERROR);\n }\n\n return bytesToHex(selector);\n });\n\n const hexValue = concatHex(normalizedSelectors);\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedTargets caveat.\n */\nexport type AllowedTargetsTerms = {\n /** An array of target addresses that the delegate is allowed to call. */\n targets: BytesLike[];\n};\n\n/**\n * Creates terms for an AllowedTargets caveat that restricts calls to a set of target addresses.\n *\n * @param terms - The terms for the AllowedTargets caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target addresses.\n * @throws Error if the targets array is empty or contains invalid addresses.\n */\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedTargets caveat that restricts calls to a set of target addresses.\n *\n * @param terms - The terms for the AllowedTargets caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target addresses.\n * @throws Error if the targets array is empty or contains invalid addresses.\n */\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { targets } = terms;\n\n if (!targets || targets.length === 0) {\n throw new Error(\n 'Invalid targets: must provide at least one target address',\n );\n }\n\n const normalizedTargets = targets.map((target) =>\n normalizeAddress(target, 'Invalid targets: must be valid addresses'),\n );\n\n const hexValue = concatHex(normalizedTargets);\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { normalizeHex } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ArgsEqualityCheck caveat.\n */\nexport type ArgsEqualityCheckTerms = {\n /** The expected args that must match exactly when redeeming the delegation. */\n args: BytesLike;\n};\n\n/**\n * Creates terms for an ArgsEqualityCheck caveat that requires exact args matching.\n *\n * @param terms - The terms for the ArgsEqualityCheck caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the args themselves.\n * @throws Error if args is not a valid hex string.\n */\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ArgsEqualityCheck caveat that requires exact args matching.\n *\n * @param terms - The terms for the ArgsEqualityCheck caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the args themselves.\n * @throws Error if args is not a valid hex string.\n */\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { args } = terms;\n\n if (typeof args === 'string' && args === '0x') {\n return prepareResult(args, encodingOptions);\n }\n\n const hexValue = normalizeHex(\n args,\n 'Invalid config: args must be a valid hex string',\n );\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a BlockNumber caveat.\n */\nexport type BlockNumberTerms = {\n /** The block number after which the delegation is valid. Set to 0n to disable. */\n afterThreshold: bigint;\n /** The block number before which the delegation is valid. Set to 0n to disable. */\n beforeThreshold: bigint;\n};\n\n/**\n * Creates terms for a BlockNumber caveat that constrains delegation validity by block range.\n *\n * @param terms - The terms for the BlockNumber caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each threshold).\n * @throws Error if both thresholds are zero or if afterThreshold >= beforeThreshold when both are set.\n */\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a BlockNumber caveat that constrains delegation validity by block range.\n *\n * @param terms - The terms for the BlockNumber caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each threshold).\n * @throws Error if both thresholds are zero or if afterThreshold >= beforeThreshold when both are set.\n */\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { afterThreshold, beforeThreshold } = terms;\n\n if (afterThreshold < 0n || beforeThreshold < 0n) {\n throw new Error('Invalid thresholds: block numbers must be non-negative');\n }\n\n if (afterThreshold === 0n && beforeThreshold === 0n) {\n throw new Error(\n 'Invalid thresholds: At least one of afterThreshold or beforeThreshold must be specified',\n );\n }\n\n if (beforeThreshold !== 0n && afterThreshold >= beforeThreshold) {\n throw new Error(\n 'Invalid thresholds: afterThreshold must be less than beforeThreshold if both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({ value: afterThreshold, size: 16 });\n const beforeThresholdHex = toHexString({ value: beforeThreshold, size: 16 });\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, normalizeHex } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a Deployed caveat.\n */\nexport type DeployedTerms = {\n /** The contract address. */\n contractAddress: BytesLike;\n /** The deployment salt. */\n salt: BytesLike;\n /** The contract bytecode. */\n bytecode: BytesLike;\n};\n\n/**\n * Creates terms for a Deployed caveat that constrains deployments by address, salt, and bytecode.\n *\n * @param terms - The terms for the Deployed caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated contractAddress + salt (32 bytes) + bytecode.\n * @throws Error if the contract address, salt, or bytecode is invalid.\n */\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Deployed caveat that constrains deployments by address, salt, and bytecode.\n *\n * @param terms - The terms for the Deployed caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated contractAddress + salt (32 bytes) + bytecode.\n * @throws Error if the contract address, salt, or bytecode is invalid.\n */\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { contractAddress, salt, bytecode } = terms;\n\n const contractAddressHex = normalizeAddress(\n contractAddress,\n 'Invalid contractAddress: must be a valid Ethereum address',\n );\n const saltHex = normalizeHex(\n salt,\n 'Invalid salt: must be a valid hexadecimal string',\n );\n const bytecodeHex = normalizeHex(\n bytecode,\n 'Invalid bytecode: must be a valid hexadecimal string',\n );\n\n const unprefixedSalt = remove0x(saltHex);\n if (unprefixedSalt.length > 64) {\n throw new Error('Invalid salt: must be a valid hexadecimal string');\n }\n const paddedSalt = `0x${unprefixedSalt.padStart(64, '0')}`;\n\n const hexValue = concatHex([contractAddressHex, paddedSalt, bytecodeHex]);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\nconst MAX_UINT256 = BigInt(`0x${'f'.repeat(64)}`);\n\n/**\n * Terms for configuring an Id caveat.\n */\nexport type IdTerms = {\n /** An id for the delegation. Only one delegation may be redeemed with any given id. */\n id: bigint | number;\n};\n\n/**\n * Creates terms for an Id caveat that restricts delegations by unique identifier.\n *\n * @param terms - The terms for the Id caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the id is invalid or out of range.\n */\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an Id caveat that restricts delegations by unique identifier.\n *\n * @param terms - The terms for the Id caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the id is invalid or out of range.\n */\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { id } = terms;\n\n let idBigInt: bigint;\n\n if (typeof id === 'number') {\n if (!Number.isInteger(id)) {\n throw new Error('Invalid id: must be an integer');\n }\n idBigInt = BigInt(id);\n } else if (typeof id === 'bigint') {\n idBigInt = id;\n } else {\n throw new Error('Invalid id: must be a bigint or number');\n }\n\n if (idBigInt < 0n) {\n throw new Error('Invalid id: must be a non-negative number');\n }\n\n if (idBigInt > MAX_UINT256) {\n throw new Error('Invalid id: must be less than 2^256');\n }\n\n const hexValue = `0x${toHexString({ value: idBigInt, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a LimitedCalls caveat.\n */\nexport type LimitedCallsTerms = {\n /** The maximum number of times this delegation may be redeemed. */\n limit: number;\n};\n\n/**\n * Creates terms for a LimitedCalls caveat that restricts the number of redeems.\n *\n * @param terms - The terms for the LimitedCalls caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the limit is not a positive integer.\n */\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a LimitedCalls caveat that restricts the number of redeems.\n *\n * @param terms - The terms for the LimitedCalls caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the limit is not a positive integer.\n */\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { limit } = terms;\n\n if (!Number.isInteger(limit)) {\n throw new Error('Invalid limit: must be an integer');\n }\n\n if (limit <= 0) {\n throw new Error('Invalid limit: must be a positive integer');\n }\n\n const hexValue = `0x${toHexString({ value: limit, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Configuration for a single token in MultiTokenPeriod terms.\n */\nexport type TokenPeriodConfig = {\n token: BytesLike;\n periodAmount: bigint;\n periodDuration: number;\n startDate: number;\n};\n\n/**\n * Terms for configuring a MultiTokenPeriod caveat.\n */\nexport type MultiTokenPeriodTerms = {\n tokenConfigs: TokenPeriodConfig[];\n};\n\n/**\n * Creates terms for a MultiTokenPeriod caveat that configures multiple token periods.\n *\n * @param terms - The terms for the MultiTokenPeriod caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated token period configs.\n * @throws Error if the tokenConfigs array is empty or contains invalid parameters.\n */\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a MultiTokenPeriod caveat that configures multiple token periods.\n *\n * @param terms - The terms for the MultiTokenPeriod caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated token period configs.\n * @throws Error if the tokenConfigs array is empty or contains invalid parameters.\n */\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenConfigs } = terms;\n\n if (!tokenConfigs || tokenConfigs.length === 0) {\n throw new Error(\n 'MultiTokenPeriodBuilder: tokenConfigs array cannot be empty',\n );\n }\n\n const hexParts: string[] = [];\n\n for (const tokenConfig of tokenConfigs) {\n const tokenHex = normalizeAddress(\n tokenConfig.token,\n `Invalid token address: ${String(tokenConfig.token)}`,\n );\n\n if (tokenConfig.periodAmount <= 0n) {\n throw new Error('Invalid period amount: must be greater than 0');\n }\n\n if (tokenConfig.periodDuration <= 0) {\n throw new Error('Invalid period duration: must be greater than 0');\n }\n\n if (tokenConfig.startDate <= 0) {\n throw new Error('Invalid start date: must be greater than 0');\n }\n\n hexParts.push(\n tokenHex,\n `0x${toHexString({ value: tokenConfig.periodAmount, size: 32 })}`,\n `0x${toHexString({ value: tokenConfig.periodDuration, size: 32 })}`,\n `0x${toHexString({ value: tokenConfig.startDate, size: 32 })}`,\n );\n }\n\n const hexValue = concatHex(hexParts);\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an OwnershipTransfer caveat.\n */\nexport type OwnershipTransferTerms = {\n /** The contract address for which ownership transfers are allowed. */\n contractAddress: BytesLike;\n};\n\n/**\n * Creates terms for an OwnershipTransfer caveat that constrains ownership transfers to a contract.\n *\n * @param terms - The terms for the OwnershipTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the contract address.\n * @throws Error if the contract address is invalid.\n */\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an OwnershipTransfer caveat that constrains ownership transfers to a contract.\n *\n * @param terms - The terms for the OwnershipTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the contract address.\n * @throws Error if the contract address is invalid.\n */\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { contractAddress } = terms;\n\n const contractAddressHex = normalizeAddress(\n contractAddress,\n 'Invalid contractAddress: must be a valid address',\n );\n\n return prepareResult(contractAddressHex, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a Redeemer caveat.\n */\nexport type RedeemerTerms = {\n /** An array of addresses allowed to redeem the delegation. */\n redeemers: BytesLike[];\n};\n\n/**\n * Creates terms for a Redeemer caveat that restricts who may redeem.\n *\n * @param terms - The terms for the Redeemer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated redeemer addresses.\n * @throws Error if the redeemers array is empty or contains invalid addresses.\n */\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Redeemer caveat that restricts who may redeem.\n *\n * @param terms - The terms for the Redeemer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated redeemer addresses.\n * @throws Error if the redeemers array is empty or contains invalid addresses.\n */\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { redeemers } = terms;\n\n if (!redeemers || redeemers.length === 0) {\n throw new Error(\n 'Invalid redeemers: must specify at least one redeemer address',\n );\n }\n\n const normalizedRedeemers = redeemers.map((redeemer) =>\n normalizeAddress(redeemer, 'Invalid redeemers: must be a valid address'),\n );\n\n const hexValue = concatHex(normalizedRedeemers);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a SpecificActionERC20TransferBatch caveat.\n */\nexport type SpecificActionERC20TransferBatchTerms = {\n /** The address of the ERC-20 token contract. */\n tokenAddress: BytesLike;\n /** The recipient of the ERC-20 transfer. */\n recipient: BytesLike;\n /** The amount of tokens to transfer. */\n amount: bigint;\n /** The target address for the first transaction. */\n target: BytesLike;\n /** The calldata for the first transaction. */\n calldata: BytesLike;\n};\n\n/**\n * Creates terms for a SpecificActionERC20TransferBatch caveat that enforces a\n * specific action followed by an ERC20 transfer.\n *\n * @param terms - The terms for the SpecificActionERC20TransferBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated tokenAddress + recipient + amount + target + calldata.\n * @throws Error if any address is invalid or amount is not positive.\n */\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a SpecificActionERC20TransferBatch caveat that enforces a\n * specific action followed by an ERC20 transfer.\n *\n * @param terms - The terms for the SpecificActionERC20TransferBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated tokenAddress + recipient + amount + target + calldata.\n * @throws Error if any address is invalid or amount is not positive.\n */\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, recipient, amount, target, calldata } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddress(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n const targetHex = normalizeAddress(\n target,\n 'Invalid target: must be a valid address',\n );\n\n let calldataHex: string;\n if (typeof calldata === 'string') {\n if (!calldata.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n calldataHex = calldata;\n } else {\n calldataHex = bytesToHex(calldata);\n }\n\n if (amount <= 0n) {\n throw new Error('Invalid amount: must be a positive number');\n }\n\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n\n const hexValue = concatHex([\n tokenAddressHex,\n recipientHex,\n amountHex,\n targetHex,\n calldataHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { encode, encodeSingle, decodeSingle } from '@metamask/abi-utils';\nimport { hexToBytes, type BytesLike } from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nimport {\n bytesLikeToBytes,\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from './returns';\nimport type { CaveatStruct, DelegationStruct, Hex } from './types';\n\n/**\n * When designated as the delegate address in a delegation, this allows any beneficiary to redeem the delegation.\n */\nexport const ANY_BENEFICIARY =\n '0x0000000000000000000000000000000000000a11' as const;\n\n/**\n * To be used on a delegation as the root authority.\n */\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as const;\n\n/**\n * The typehash for a delegation, used when generating a delegation hash.\n *\n * keccak('Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)')\n */\nexport const DELEGATION_TYPEHASH =\n '0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e' as const;\n\n/**\n * The typehash for a caveat, used when generating a caveat hash.\n *\n * keccak('Caveat(address enforcer,bytes terms)')\n */\nexport const CAVEAT_TYPEHASH =\n '0x80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d' as const;\n\n/**\n * The ABI types for an array of delegations.\n */\nconst DELEGATION_ARRAY_ABI_TYPES =\n '(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)[]' as const;\n\n/**\n * The ABI type for a single delegation.\n */\nconst DELEGATION_ABI_TYPE =\n '(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)' as const;\n\n/**\n * Encodes an array of delegations into a permission context.\n *\n * @param delegations - The delegations to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegations as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Encodes an array of delegations into a permission context.\n *\n * @param delegations - The delegations to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegations as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n let result: Uint8Array;\n\n if (delegations.length === 0) {\n // short circuit for empty delegations, derived from\n // `encode(['(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)[]'],[[]],);`\n result = new Uint8Array(64);\n result[31] = 0x20;\n } else {\n const encodableStructs = delegations.map((struct) => [\n struct.delegate,\n struct.delegator,\n struct.authority,\n struct.caveats.map((caveat) => [\n caveat.enforcer,\n caveat.terms,\n caveat.args,\n ]),\n struct.salt,\n struct.signature,\n ]);\n\n result = encodeSingle(DELEGATION_ARRAY_ABI_TYPES, encodableStructs);\n }\n\n return prepareResult(result, options);\n}\n\n/**\n * Encodes a single delegation.\n *\n * @param delegation - The delegation to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Encodes a single delegation.\n *\n * @param delegation - The delegation to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const encodableStruct = [\n delegation.delegate,\n delegation.delegator,\n delegation.authority,\n delegation.caveats.map((caveat) => [\n caveat.enforcer,\n caveat.terms,\n caveat.args,\n ]),\n delegation.salt,\n delegation.signature,\n ];\n\n const result = encodeSingle(DELEGATION_ABI_TYPE, encodableStruct);\n\n return prepareResult(result, options);\n}\n\n/**\n * Converts a decoded delegation struct to a delegation object using the provided conversion function.\n *\n * @param decodedDelegation - The decoded delegation struct as a tuple.\n * @param convertFn - Function to convert BytesLike values to the desired output type.\n * @returns A delegation object with all bytes-like values converted using the provided function.\n */\nconst delegationFromDecodedDelegation = <TEncoding extends BytesLike>(\n decodedDelegation: DecodedDelegation,\n convertFn: (value: BytesLike) => TEncoding,\n): DelegationStruct<TEncoding> => {\n const [delegate, delegator, authority, caveats, salt, signature] =\n decodedDelegation;\n\n return {\n delegate: convertFn(delegate),\n delegator: convertFn(delegator),\n authority: convertFn(authority),\n caveats: caveats.map(([enforcer, terms, args]) => ({\n enforcer: convertFn(enforcer),\n terms: convertFn(terms),\n args: convertFn(args),\n })),\n salt,\n signature: convertFn(signature),\n };\n};\n\n/**\n * Represents a decoded delegation as a tuple structure.\n * This type defines the structure of a delegation after it has been decoded from\n * an encoded format.\n */\ntype DecodedDelegation = [\n BytesLike,\n BytesLike,\n BytesLike,\n [BytesLike, BytesLike, BytesLike][],\n bigint,\n BytesLike,\n];\n\n/**\n * Decodes an encoded permission context back into an array of delegations.\n *\n * @param encoded - The encoded delegations as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegations array with types resolved based on options.\n */\nexport function decodeDelegations(\n encoded: BytesLike,\n options?: EncodingOptions<'hex'>,\n): DelegationStruct<Hex>[];\nexport function decodeDelegations(\n encoded: BytesLike,\n options: EncodingOptions<'bytes'>,\n): DelegationStruct<Uint8Array>[];\n/**\n * Decodes an encoded permission context back into an array of delegations.\n *\n * @param encoded - The encoded delegations as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegations array with types resolved based on options.\n */\nexport function decodeDelegations(\n encoded: BytesLike,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): DelegationStruct<Hex>[] | DelegationStruct<Uint8Array>[] {\n // it's possible to short circuit for empty delegations, but due to the\n // complexity of the input type, and the relative infrequency of empty delegations,\n // it's not worthwhile.\n\n const decodedStructs = decodeSingle(\n DELEGATION_ARRAY_ABI_TYPES,\n encoded,\n // return types cannot be inferred from complex ABI types, so we must assert the type\n ) as DecodedDelegation[];\n\n if (options.out === 'bytes') {\n return decodedStructs.map((struct) =>\n delegationFromDecodedDelegation(struct, bytesLikeToBytes),\n );\n }\n return decodedStructs.map((struct) =>\n delegationFromDecodedDelegation(struct, bytesLikeToHex),\n );\n}\n\n/**\n * Decodes an encoded single delegation.\n *\n * @param encoded - The encoded delegation as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegation with types resolved based on options.\n */\nexport function decodeDelegation(\n encoded: BytesLike,\n options?: EncodingOptions<'hex'>,\n): DelegationStruct<Hex>;\nexport function decodeDelegation(\n encoded: BytesLike,\n options: EncodingOptions<'bytes'>,\n): DelegationStruct<Uint8Array>;\n/**\n * Decodes an encoded single delegation.\n *\n * @param encoded - The encoded delegation as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegation with types resolved based on options.\n */\nexport function decodeDelegation(\n encoded: BytesLike,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): DelegationStruct<Hex> | DelegationStruct<Uint8Array> {\n const decodedStruct = decodeSingle(\n DELEGATION_ABI_TYPE,\n encoded,\n // return types cannot be inferred from complex ABI types, so we must assert the type\n ) as DecodedDelegation;\n\n if (options.out === 'bytes') {\n return delegationFromDecodedDelegation(decodedStruct, bytesLikeToBytes);\n }\n return delegationFromDecodedDelegation(decodedStruct, bytesLikeToHex);\n}\n\n/**\n * Calculates the hash of a delegation for signing purposes.\n * The hash is computed by encoding the delegation parameters with the delegation typehash\n * and then applying keccak256 hashing.\n *\n * @param delegation - The delegation to hash.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The keccak256 hash of the encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function hashDelegation(\n delegation: DelegationStruct,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function hashDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Calculates the hash of a delegation for signing purposes.\n * The hash is computed by encoding the delegation parameters with the delegation typehash\n * and then applying keccak256 hashing.\n *\n * @param delegation - The delegation to hash.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The keccak256 hash of the encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function hashDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const encoded = encode(\n ['bytes32', 'address', 'address', 'bytes32', 'bytes32', 'uint256'],\n [\n DELEGATION_TYPEHASH,\n delegation.delegate,\n delegation.delegator,\n delegation.authority,\n getCaveatsArrayHash(delegation.caveats),\n delegation.salt,\n ],\n );\n const hash = keccak256(encoded);\n return prepareResult(hash, options);\n}\n\n/**\n * Calculates the hash of an array of caveats. The caveats are individually abi\n * encoded and hashed, and concatenated. The resulting byte array is then\n * hashed to produce the CaveatsArrayHash.\n *\n * @param caveats - The array of caveats to hash.\n * @returns The keccak256 hash of the encoded caveat array.\n */\nfunction getCaveatsArrayHash(caveats: CaveatStruct[]): Uint8Array {\n const byteLength = 32 * caveats.length;\n const encoded = new Uint8Array(byteLength);\n\n for (let i = 0; i < caveats.length; i++) {\n const caveat = caveats[i];\n if (!caveat) {\n throw new Error(`Caveat was undefined at index ${i}`);\n }\n const caveatHash = getCaveatHash(caveat);\n encoded.set(caveatHash, i * 32);\n }\n\n return keccak256(encoded);\n}\n\n/**\n * Calculates the hash of a single caveat.\n *\n * @param caveat - The caveat to hash.\n * @returns The keccak256 hash of the encoded caveat.\n */\nfunction getCaveatHash(caveat: CaveatStruct): Uint8Array {\n const termsBytes =\n typeof caveat.terms === 'string' ? hexToBytes(caveat.terms) : caveat.terms;\n\n const termsHash = keccak256(termsBytes);\n\n const encoded = encode(\n ['bytes32', 'address', 'bytes32'],\n [CAVEAT_TYPEHASH, caveat.enforcer, termsHash],\n );\n const hash = keccak256(encoded);\n return hash;\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/delegation-core/dist/index.cjs","../src/internalUtils.ts","../src/returns.ts","../src/caveats/valueLte.ts","../src/caveats/timestamp.ts","../src/caveats/nativeTokenPeriodTransfer.ts","../src/caveats/exactCalldata.ts","../src/caveats/exactCalldataBatch.ts","../src/caveats/exactExecution.ts","../src/caveats/exactExecutionBatch.ts","../src/caveats/nativeTokenStreaming.ts","../src/caveats/nativeTokenTransferAmount.ts","../src/caveats/nativeTokenPayment.ts","../src/caveats/nativeBalanceChange.ts","../src/caveats/erc20Streaming.ts","../src/caveats/erc20TokenPeriodTransfer.ts","../src/caveats/erc20TransferAmount.ts","../src/caveats/erc20BalanceChange.ts","../src/caveats/erc721BalanceChange.ts","../src/caveats/erc721Transfer.ts","../src/caveats/erc1155BalanceChange.ts","../src/caveats/nonce.ts","../src/caveats/allowedCalldata.ts","../src/caveats/allowedMethods.ts","../src/caveats/allowedTargets.ts","../src/caveats/argsEqualityCheck.ts","../src/caveats/blockNumber.ts","../src/caveats/deployed.ts","../src/caveats/id.ts","../src/caveats/limitedCalls.ts","../src/caveats/multiTokenPeriod.ts","../src/caveats/ownershipTransfer.ts","../src/caveats/redeemer.ts","../src/caveats/specificActionERC20TransferBatch.ts","../src/delegation.ts"],"names":["EXECUTION_ARRAY_ABI","TIMESTAMP_UPPER_BOUND_SECONDS","isHexString","bytesToHex","encodeSingle","decodeSingle"],"mappings":"AAAA;ACAA;AACE;AACA;AACA;AACA;AAAA,wCAGK;AAeA,IAAM,YAAA,EAAc,CAAC;AAAA,EAC1B,KAAA;AAAA,EACA;AACF,CAAA,EAAA,GAGc;AACZ,EAAA,OAAO,KAAA,CAAM,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,KAAA,EAAO,CAAA,EAAG,GAAG,CAAA;AAClD,CAAA;AAUO,IAAM,aAAA,EAAe,CAC1B,KAAA,EACA,YAAA,EAAA,GACW;AACX,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,QAAA,EAAU;AAC7B,IAAA,GAAA,CAAI,CAAC,gCAAA,KAAiB,CAAA,EAAG;AACvB,MAAA,MAAM,IAAI,KAAA,CAAM,YAAY,CAAA;AAAA,IAC9B;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,+BAAA,KAAgB,CAAA;AACzB,CAAA;AAUO,IAAM,iBAAA,EAAmB,CAC9B,KAAA,EACA,YAAA,EAAA,GACW;AACX,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,QAAA,EAAU;AAC7B,IAAA,GAAA,CAAI,CAAC,gCAAA,KAAiB,EAAA,GAAK,KAAA,CAAM,OAAA,IAAW,EAAA,EAAI;AAC9C,MAAA,MAAM,IAAI,KAAA,CAAM,YAAY,CAAA;AAAA,IAC9B;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,IAAW,EAAA,EAAI;AACvB,IAAA,MAAM,IAAI,KAAA,CAAM,YAAY,C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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/delegation-core/dist/index.cjs","sourcesContent":[null,"import {\n bytesToHex,\n hexToBytes,\n isHexString,\n remove0x,\n type Hex,\n type BytesLike,\n} from '@metamask/utils';\n\n/**\n * Converts a numeric value to a hexadecimal string with zero-padding, without 0x prefix.\n *\n * @param options - The options for the conversion.\n * @param options.value - The numeric value to convert to hex (bigint or number).\n * @param options.size - The size in bytes for the resulting hex string (each byte = 2 hex characters).\n * @returns A hexadecimal string prefixed with zeros to match the specified size.\n * @example\n * ```typescript\n * toHexString({ value: 255, size: 2 }) // Returns \"00ff\"\n * toHexString({ value: 16n, size: 1 }) // Returns \"10\"\n * ```\n */\nexport const toHexString = ({\n value,\n size,\n}: {\n value: bigint | number;\n size: number;\n}): string => {\n return value.toString(16).padStart(size * 2, '0');\n};\n\n/**\n * Normalizes a bytes-like value into a hex string.\n *\n * @param value - The value to normalize.\n * @param errorMessage - Error message used for invalid input.\n * @returns The normalized hex string (0x-prefixed).\n * @throws Error if the input is an invalid hex string.\n */\nexport const normalizeHex = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value)) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Normalizes an address into a hex string without changing casing.\n *\n * @param value - The address as a hex string or bytes.\n * @param errorMessage - Error message used for invalid input.\n * @returns The address as a 0x-prefixed hex string.\n * @throws Error if the input is not a 20-byte address.\n */\nexport const normalizeAddress = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value) || value.length !== 42) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n if (value.length !== 20) {\n throw new Error(errorMessage);\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Normalizes an address into a lowercased hex string.\n *\n * @param value - The address as a hex string or bytes.\n * @param errorMessage - Error message used for invalid input.\n * @returns The address as a lowercased 0x-prefixed hex string.\n * @throws Error if the input is not a 20-byte address.\n */\nexport const normalizeAddressLowercase = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value) || value.length !== 42) {\n throw new Error(errorMessage);\n }\n return bytesToHex(hexToBytes(value));\n }\n\n if (value.length !== 20) {\n throw new Error(errorMessage);\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Concatenates 0x-prefixed hex strings into a single 0x-prefixed hex string.\n *\n * @param parts - The hex string parts to concatenate.\n * @returns The concatenated hex string.\n */\nexport const concatHex = (parts: string[]): string => {\n return `0x${parts.map(remove0x).join('')}`;\n};\n\n/**\n * Extracts a bigint value from a hex string at a specific byte offset.\n *\n * @param value - The hex string to extract from.\n * @param offset - The byte offset to start extraction.\n * @param size - The number of bytes to extract.\n * @returns The extracted bigint value.\n */\nexport const extractBigInt = (\n value: Hex,\n offset: number,\n size: number,\n): bigint => {\n const start = 2 + offset * 2;\n const end = start + size * 2;\n const slice = value.slice(start, end);\n\n return BigInt(`0x${slice}`);\n};\n\n/**\n * Extracts a number value from a hex string at a specific byte offset.\n *\n * @param value - The hex string to extract from.\n * @param offset - The byte offset to start extraction.\n * @param size - The number of bytes to extract.\n * @returns The extracted number value.\n */\nexport const extractNumber = (\n value: Hex,\n offset: number,\n size: number,\n): number => {\n const bigIntValue = extractBigInt(value, offset, size);\n\n if (bigIntValue > Number.MAX_SAFE_INTEGER) {\n throw new Error('Number is too large');\n }\n\n return Number(bigIntValue);\n};\n\n/**\n * Extracts an address from a hex string at a specific byte offset.\n *\n * @param value - The hex string to extract from.\n * @param offset - The byte offset to start extraction.\n * @returns The extracted address as a 0x-prefixed hex string.\n */\nexport const extractAddress = (value: Hex, offset: number): Hex => {\n const start = 2 + offset * 2;\n const end = start + 40;\n\n return `0x${value.slice(start, end)}`;\n};\n\n/**\n * Extracts a hex slice from a hex string at a specific byte offset.\n *\n * @param value - The hex string to extract from.\n * @param offset - The byte offset to start extraction.\n * @param size - The number of bytes to extract.\n * @returns The extracted hex string (0x-prefixed).\n */\nexport const extractHex = (value: Hex, offset: number, size: number): Hex => {\n const start = 2 + offset * 2;\n const end = start + size * 2;\n\n return `0x${value.slice(start, end)}`;\n};\n\n/**\n * Extracts the remaining hex data from a hex string starting at a specific byte offset.\n *\n * @param value - The hex string to extract from.\n * @param offset - The byte offset to start extraction.\n * @returns The extracted hex string (0x-prefixed).\n */\nexport const extractRemainingHex = (value: Hex, offset: number): Hex => {\n const start = 2 + offset * 2;\n\n return `0x${value.slice(start)}`;\n};\n\n/**\n * @param value - `0x`-prefixed hex string.\n * @returns Byte length of the hex data (excluding the `0x` prefix).\n */\nexport function getByteLength(value: Hex): number {\n return (value.length - 2) / 2;\n}\n\n/**\n * @param hexTerms - `0x`-prefixed hex string (encoded caveat terms).\n * @param expectedBytes - Required payload length in bytes.\n * @param errorMessage - Message for the thrown `Error` when length does not match.\n * @throws Error if the payload is not exactly `expectedBytes` long.\n */\nexport function assertHexByteExactLength(\n hexTerms: Hex,\n expectedBytes: number,\n errorMessage: string,\n): void {\n if (getByteLength(hexTerms) !== expectedBytes) {\n throw new Error(errorMessage);\n }\n}\n\n/**\n * @param hexTerms - `0x`-prefixed hex string (encoded caveat terms).\n * @param unitBytes - Payload length must be divisible by this many bytes.\n * @param errorMessage - Message for the thrown `Error` when length is not a multiple.\n * @throws Error if the payload length is not (at least one) a multiple of `unitBytes`.\n */\nexport function assertHexByteLengthAtLeastOneMultipleOf(\n hexTerms: Hex,\n unitBytes: number,\n errorMessage: string,\n): void {\n const byteLength = getByteLength(hexTerms);\n if (byteLength === 0 || byteLength % unitBytes !== 0) {\n throw new Error(errorMessage);\n }\n}\n\n/**\n * @param hexTerms - `0x`-prefixed hex string (encoded caveat terms).\n * @param minBytes - Minimum payload length in bytes (inclusive).\n * @param errorMessage - Message for the thrown `Error` when payload is too short.\n * @throws Error if the payload is shorter than `minBytes`.\n */\nexport function assertHexBytesMinLength(\n hexTerms: Hex,\n minBytes: number,\n errorMessage: string,\n): void {\n if (getByteLength(hexTerms) < minBytes) {\n throw new Error(errorMessage);\n }\n}\n","import { type BytesLike, bytesToHex, hexToBytes } from '@metamask/utils';\n\nimport type { Hex } from './types';\n\n/**\n * The possible return value types for encoding/decoding operations.\n */\nexport type ResultValue = 'hex' | 'bytes';\n\n/**\n * Utility type for function return types based on ResultValue.\n */\nexport type ResultType<TResultValue extends ResultValue> =\n TResultValue extends 'hex' ? Hex : Uint8Array;\n\n/**\n * Concrete type for a decoded Bytes-like field when using {@link EncodingOptions}.\n * Matches {@link ResultType}; alias for readability on `*Terms` generics.\n */\nexport type DecodedBytesLike<TResultValue extends ResultValue> =\n ResultType<TResultValue>;\n\n/**\n * Base options interface for operations that can return hex or bytes.\n */\nexport type EncodingOptions<TResultValue extends ResultValue> = {\n out: TResultValue;\n};\n\n/**\n * Default options value with proper typing. Use this as your default parameter.\n */\nexport const defaultOptions = { out: 'hex' } as EncodingOptions<'hex'>;\n\n/**\n * Prepares a result by converting between hex and bytes based on options.\n *\n * @param result - The value to convert (either Uint8Array or Hex optionally prefixed with 0x).\n * @param options - The options specifying the desired output format.\n * @returns The converted value with proper type narrowing.\n */\nexport function prepareResult<TResultValue extends ResultValue>(\n result: Uint8Array | Hex | string,\n options: EncodingOptions<TResultValue>,\n): ResultType<TResultValue> {\n if (options.out === 'hex') {\n const hexValue = typeof result === 'string' ? result : bytesToHex(result);\n\n return hexValue.startsWith('0x')\n ? (hexValue as ResultType<TResultValue>)\n : (`0x${hexValue}` as ResultType<TResultValue>);\n }\n const bytesValue = result instanceof Uint8Array ? result : hexToBytes(result);\n return bytesValue as ResultType<TResultValue>;\n}\n\n/**\n * Converts a bytes-like value to a hex string.\n *\n * @param bytesLike - The bytes-like value to convert.\n * @returns The hex string representation of the bytes-like value.\n */\nexport const bytesLikeToHex = (bytesLike: BytesLike): Hex => {\n if (typeof bytesLike === 'string') {\n return bytesLike;\n }\n return bytesToHex(bytesLike);\n};\n\n/**\n * Converts a bytes-like value to a Uint8Array.\n *\n * @param bytesLike - The bytes-like value to convert.\n * @returns The Uint8Array representation of the bytes-like value.\n */\nexport const bytesLikeToBytes = (bytesLike: BytesLike): Uint8Array => {\n if (typeof bytesLike === 'string') {\n return hexToBytes(bytesLike);\n }\n return bytesLike;\n};\n","/**\n * ## ValueLteEnforcer\n *\n * Limits the native token (wei) value allowed per execution.\n *\n * Terms are encoded as a single 32-byte big-endian uint256 max value.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractBigInt,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a ValueLte caveat.\n */\nexport type ValueLteTerms = {\n /** The maximum value allowed for the transaction as a bigint. */\n maxValue: bigint;\n};\n\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxValue } = terms;\n\n if (maxValue < 0n) {\n throw new Error('Invalid maxValue: must be greater than or equal to zero');\n }\n const hexValue = toHexString({ value: maxValue, size: 32 });\n\n return prepareResult(hexValue, options);\n}\n\n/**\n * Decodes terms for a ValueLte caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded ValueLteTerms object.\n */\nexport function decodeValueLteTerms(terms: BytesLike): ValueLteTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid ValueLte terms: must be exactly 32 bytes',\n );\n const maxValue = extractBigInt(hexTerms, 0, 32);\n return { maxValue };\n}\n","/**\n * ## TimestampEnforcer\n *\n * Restricts redemption to a unix timestamp window (strict inequalities on-chain: valid when `block.timestamp > afterThreshold` if after is set, and `block.timestamp < beforeThreshold` if before is set).\n *\n * Terms are encoded as two 16-byte big-endian fields: timestamp after, then timestamp before (each zero-padded; interpreted as `uint128`).\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractNumber,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (equivalent to January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a timestamp threshold for delegation usage.\n */\nexport type TimestampTerms = {\n /** The timestamp (in seconds) after which the delegation can be used. */\n afterThreshold: number;\n /** The timestamp (in seconds) before which the delegation can be used. */\n beforeThreshold: number;\n};\n\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { afterThreshold, beforeThreshold } = terms;\n\n if (afterThreshold < 0) {\n throw new Error('Invalid afterThreshold: must be zero or positive');\n }\n\n if (beforeThreshold < 0) {\n throw new Error('Invalid beforeThreshold: must be zero or positive');\n }\n\n if (beforeThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid beforeThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (afterThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid afterThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (beforeThreshold !== 0 && afterThreshold >= beforeThreshold) {\n throw new Error(\n 'Invalid thresholds: beforeThreshold must be greater than afterThreshold when both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({\n value: afterThreshold,\n size: 16,\n });\n const beforeThresholdHex = toHexString({\n value: beforeThreshold,\n size: 16,\n });\n\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a Timestamp caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded TimestampTerms object.\n */\nexport function decodeTimestampTerms(terms: BytesLike): TimestampTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid Timestamp terms: must be exactly 32 bytes',\n );\n const afterThreshold = extractNumber(hexTerms, 0, 16);\n const beforeThreshold = extractNumber(hexTerms, 16, 16);\n return { afterThreshold, beforeThreshold };\n}\n","/**\n * ## NativeTokenPeriodTransferEnforcer\n *\n * Limits periodic native token transfers using amount, period length, and start date.\n *\n * Terms are encoded as three consecutive 32-byte big-endian uint256 words: period amount, period duration, start date.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractBigInt,\n extractNumber,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a periodic transfer allowance of native tokens.\n */\nexport type NativeTokenPeriodTransferTerms = {\n /** The maximum amount that can be transferred within each period (in wei). */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused ETH is forfeited once the period ends.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { periodAmount, periodDuration, startDate } = terms;\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `0x${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a NativeTokenPeriodTransfer caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded NativeTokenPeriodTransferTerms object.\n */\nexport function decodeNativeTokenPeriodTransferTerms(\n terms: BytesLike,\n): NativeTokenPeriodTransferTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 96,\n 'Invalid NativeTokenPeriodTransfer terms: must be exactly 96 bytes',\n );\n\n const periodAmount = extractBigInt(hexTerms, 0, 32);\n const periodDuration = extractNumber(hexTerms, 32, 32);\n const startDate = extractNumber(hexTerms, 64, 32);\n\n return { periodAmount, periodDuration, startDate };\n}\n","/**\n * ## ExactCalldataEnforcer\n *\n * Requires the full execution calldata to match exactly.\n *\n * Terms are encoded as the calldata bytes only with no additional encoding.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldata caveat.\n */\nexport type ExactCalldataTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The expected calldata to match against. */\n calldata: TBytesLike;\n};\n\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { calldata } = terms;\n\n if (calldata === undefined || calldata === null) {\n throw new Error('Invalid calldata: calldata is required');\n }\n\n if (typeof calldata === 'string' && !calldata.startsWith('0x')) {\n throw new Error('Invalid calldata: must be a hex string starting with 0x');\n }\n\n return prepareResult(calldata, encodingOptions);\n}\n\n/**\n * Decodes terms for an ExactCalldata caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded calldata is returned as hex or bytes.\n * @returns The decoded ExactCalldataTerms object.\n */\nexport function decodeExactCalldataTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ExactCalldataTerms<DecodedBytesLike<'hex'>>;\nexport function decodeExactCalldataTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ExactCalldataTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded calldata is returned as hex or bytes.\n * @returns The decoded ExactCalldataTerms object.\n */\nexport function decodeExactCalldataTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ExactCalldataTerms<DecodedBytesLike<'hex'>>\n | ExactCalldataTerms<DecodedBytesLike<'bytes'>> {\n const calldataHex = bytesLikeToHex(terms);\n const calldata = prepareResult(calldataHex, encodingOptions);\n return { calldata } as\n | ExactCalldataTerms<DecodedBytesLike<'hex'>>\n | ExactCalldataTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ExactCalldataBatchEnforcer\n *\n * Requires each execution in a batch to match the corresponding expected calldata (the enforcer compares only `callData`; target and value in terms must still align with `Execution[]` layout used by `decodeBatch`).\n *\n * Terms are encoded as ABI-encoded `(address,uint256,bytes)[]`, i.e. the same tuple-array shape as batch executions.\n */\n\nimport { decodeSingle, encodeSingle } from '@metamask/abi-utils';\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldataBatch caveat.\n */\nexport type ExactCalldataBatchTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The executions that must be matched exactly in the batch. */\n executions: {\n target: TBytesLike;\n value: bigint;\n callData: TBytesLike;\n }[];\n };\n\nconst EXECUTION_ARRAY_ABI = '(address,uint256,bytes)[]';\n\n/**\n * Creates terms for an ExactCalldataBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactCalldataBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldataBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactCalldataBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { executions } = terms;\n\n if (executions.length === 0) {\n throw new Error('Invalid executions: array cannot be empty');\n }\n\n const encodableExecutions = executions.map((execution) => {\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n return [targetHex, execution.value, callDataHex];\n });\n\n const hexValue = encodeSingle(EXECUTION_ARRAY_ABI, encodableExecutions);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ExactCalldataBatch caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded targets and calldata are returned as hex or bytes.\n * @returns The decoded ExactCalldataBatchTerms object.\n */\nexport function decodeExactCalldataBatchTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ExactCalldataBatchTerms<DecodedBytesLike<'hex'>>;\nexport function decodeExactCalldataBatchTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ExactCalldataBatchTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded targets and calldata are returned as hex or bytes.\n * @returns The decoded ExactCalldataBatchTerms object.\n */\nexport function decodeExactCalldataBatchTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ExactCalldataBatchTerms<DecodedBytesLike<'hex'>>\n | ExactCalldataBatchTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n\n const decoded = decodeSingle(EXECUTION_ARRAY_ABI, hexTerms);\n\n const executions = (decoded as [string, bigint, Uint8Array][]).map(\n ([target, value, callData]) => ({\n target: prepareResult(target, encodingOptions),\n value,\n callData: prepareResult(bytesToHex(callData), encodingOptions),\n }),\n );\n\n return { executions } as\n | ExactCalldataBatchTerms<DecodedBytesLike<'hex'>>\n | ExactCalldataBatchTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ExactExecutionEnforcer\n *\n * Requires a single execution (target, value, calldata) to match exactly.\n *\n * Terms are encoded as 20-byte target, 32-byte big-endian value, then calldata bytes.\n */\n\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport {\n assertHexBytesMinLength,\n concatHex,\n extractAddress,\n extractBigInt,\n extractRemainingHex,\n normalizeAddress,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactExecution caveat.\n */\nexport type ExactExecutionTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The execution that must be matched exactly. */\n execution: {\n target: TBytesLike;\n value: bigint;\n callData: TBytesLike;\n };\n};\n\n/**\n * Creates terms for an ExactExecution caveat that matches a single execution.\n *\n * @param terms - The terms for the ExactExecution caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactExecution caveat that matches a single execution.\n *\n * @param terms - The terms for the ExactExecution caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { execution } = terms;\n\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n const valueHex = `0x${toHexString({ value: execution.value, size: 32 })}`;\n const hexValue = concatHex([targetHex, valueHex, callDataHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ExactExecution caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded target and calldata are returned as hex or bytes.\n * @returns The decoded ExactExecutionTerms object.\n */\nexport function decodeExactExecutionTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ExactExecutionTerms<DecodedBytesLike<'hex'>>;\nexport function decodeExactExecutionTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ExactExecutionTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded target and calldata are returned as hex or bytes.\n * @returns The decoded ExactExecutionTerms object.\n */\nexport function decodeExactExecutionTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ExactExecutionTerms<DecodedBytesLike<'hex'>>\n | ExactExecutionTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexBytesMinLength(\n hexTerms,\n 52,\n 'Invalid ExactExecution terms: must be at least 52 bytes',\n );\n\n const targetHex = extractAddress(hexTerms, 0);\n const value = extractBigInt(hexTerms, 20, 32);\n const callDataHex = extractRemainingHex(hexTerms, 52);\n\n return {\n execution: {\n target: prepareResult(targetHex, encodingOptions),\n value,\n callData: prepareResult(callDataHex, encodingOptions),\n },\n } as\n | ExactExecutionTerms<DecodedBytesLike<'hex'>>\n | ExactExecutionTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ExactExecutionBatchEnforcer\n *\n * Requires a batch of executions to match exactly on target, value, and calldata.\n *\n * Terms are encoded as ABI-encoded (address,uint256,bytes)[].\n */\n\nimport { decodeSingle, encodeSingle } from '@metamask/abi-utils';\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactExecutionBatch caveat.\n */\nexport type ExactExecutionBatchTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The executions that must be matched exactly in the batch. */\n executions: {\n target: TBytesLike;\n value: bigint;\n callData: TBytesLike;\n }[];\n };\n\nconst EXECUTION_ARRAY_ABI = '(address,uint256,bytes)[]';\n\n/**\n * Creates terms for an ExactExecutionBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactExecutionBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactExecutionBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactExecutionBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { executions } = terms;\n\n if (executions.length === 0) {\n throw new Error('Invalid executions: array cannot be empty');\n }\n\n const encodableExecutions = executions.map((execution) => {\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n return [targetHex, execution.value, callDataHex];\n });\n\n const hexValue = encodeSingle(EXECUTION_ARRAY_ABI, encodableExecutions);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ExactExecutionBatch caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded targets and calldata are returned as hex or bytes.\n * @returns The decoded ExactExecutionBatchTerms object.\n */\nexport function decodeExactExecutionBatchTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ExactExecutionBatchTerms<DecodedBytesLike<'hex'>>;\nexport function decodeExactExecutionBatchTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ExactExecutionBatchTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded targets and calldata are returned as hex or bytes.\n * @returns The decoded ExactExecutionBatchTerms object.\n */\nexport function decodeExactExecutionBatchTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ExactExecutionBatchTerms<DecodedBytesLike<'hex'>>\n | ExactExecutionBatchTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n\n const decoded = decodeSingle(EXECUTION_ARRAY_ABI, hexTerms);\n\n const executions = (decoded as [string, bigint, Uint8Array][]).map(\n ([target, value, callData]) => ({\n target: prepareResult(target, encodingOptions),\n value,\n callData: prepareResult(bytesToHex(callData), encodingOptions),\n }),\n );\n\n return { executions } as\n | ExactExecutionBatchTerms<DecodedBytesLike<'hex'>>\n | ExactExecutionBatchTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## NativeTokenStreamingEnforcer\n *\n * Configures a linear streaming allowance of native token over time.\n *\n * Terms are encoded as four consecutive 32-byte big-endian uint256 words: initial amount, max amount, amount per second, start time.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractBigInt,\n extractNumber,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of native tokens.\n */\nexport type NativeTokenStreamingTerms = {\n /** The initial amount available immediately (in wei). */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred (in wei). */\n maxAmount: bigint;\n /** The rate at which allowance increases per second (in wei). */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (128 bytes).\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { initialAmount, maxAmount, amountPerSecond, startTime } = terms;\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `0x${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a NativeTokenStreaming caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded NativeTokenStreamingTerms object.\n */\nexport function decodeNativeTokenStreamingTerms(\n terms: BytesLike,\n): NativeTokenStreamingTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 128,\n 'Invalid NativeTokenStreaming terms: must be exactly 128 bytes',\n );\n\n const initialAmount = extractBigInt(hexTerms, 0, 32);\n const maxAmount = extractBigInt(hexTerms, 32, 32);\n const amountPerSecond = extractBigInt(hexTerms, 64, 32);\n const startTime = extractNumber(hexTerms, 96, 32);\n\n return { initialAmount, maxAmount, amountPerSecond, startTime };\n}\n","/**\n * ## NativeTokenTransferAmountEnforcer\n *\n * Limits how much native token (wei) may be transferred in a single execution.\n *\n * Terms are encoded as a single 32-byte big-endian uint256 max amount.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractBigInt,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a NativeTokenTransferAmount caveat.\n */\nexport type NativeTokenTransferAmountTerms = {\n /** The maximum amount of native tokens that can be transferred. */\n maxAmount: bigint;\n};\n\n/**\n * Creates terms for a NativeTokenTransferAmount caveat that caps native transfers.\n *\n * @param terms - The terms for the NativeTokenTransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if maxAmount is negative.\n */\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenTransferAmount caveat that caps native transfers.\n *\n * @param terms - The terms for the NativeTokenTransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if maxAmount is negative.\n */\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxAmount } = terms;\n\n if (maxAmount < 0n) {\n throw new Error('Invalid maxAmount: must be zero or positive');\n }\n\n const hexValue = `0x${toHexString({ value: maxAmount, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a NativeTokenTransferAmount caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded NativeTokenTransferAmountTerms object.\n */\nexport function decodeNativeTokenTransferAmountTerms(\n terms: BytesLike,\n): NativeTokenTransferAmountTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid NativeTokenTransferAmount terms: must be exactly 32 bytes',\n );\n const maxAmount = extractBigInt(hexTerms, 0, 32);\n return { maxAmount };\n}\n","/**\n * ## NativeTokenPaymentEnforcer\n *\n * Requires a fixed native token payment to a recipient.\n *\n * Terms are encoded as 20-byte recipient followed by a 32-byte big-endian uint256 amount in wei.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a NativeTokenPayment caveat.\n */\nexport type NativeTokenPaymentTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The recipient address. */\n recipient: TBytesLike;\n /** The amount that must be paid. */\n amount: bigint;\n };\n\n/**\n * Creates terms for a NativeTokenPayment caveat that requires a payment to a recipient.\n *\n * @param terms - The terms for the NativeTokenPayment caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the recipient address is invalid or amount is not positive.\n */\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPayment caveat that requires a payment to a recipient.\n *\n * @param terms - The terms for the NativeTokenPayment caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the recipient address is invalid or amount is not positive.\n */\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { recipient, amount } = terms;\n\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (amount <= 0n) {\n throw new Error('Invalid amount: must be positive');\n }\n\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n const hexValue = concatHex([recipientHex, amountHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a NativeTokenPayment caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded recipient is returned as hex or bytes.\n * @returns The decoded NativeTokenPaymentTerms object.\n */\nexport function decodeNativeTokenPaymentTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): NativeTokenPaymentTerms<DecodedBytesLike<'hex'>>;\nexport function decodeNativeTokenPaymentTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): NativeTokenPaymentTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded recipient is returned as hex or bytes.\n * @returns The decoded NativeTokenPaymentTerms object.\n */\nexport function decodeNativeTokenPaymentTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | NativeTokenPaymentTerms<DecodedBytesLike<'hex'>>\n | NativeTokenPaymentTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 52,\n 'Invalid NativeTokenPayment terms: must be exactly 52 bytes',\n );\n\n const recipientHex = extractAddress(hexTerms, 0);\n const amount = extractBigInt(hexTerms, 20, 32);\n\n return {\n recipient: prepareResult(recipientHex, encodingOptions),\n amount,\n } as\n | NativeTokenPaymentTerms<DecodedBytesLike<'hex'>>\n | NativeTokenPaymentTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## NativeBalanceChangeEnforcer\n *\n * Constrains native balance change for a recipient relative to a reference balance.\n *\n * Terms are encoded as 1-byte direction (`0x00` = minimum increase, any non-zero e.g. `0x01` = maximum decrease), 20-byte recipient, then 32-byte big-endian balance in wei.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n extractNumber,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring a NativeBalanceChange caveat.\n */\nexport type NativeBalanceChangeTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The recipient address. */\n recipient: TBytesLike;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n };\n\n/**\n * Creates terms for a NativeBalanceChange caveat that checks recipient balance changes.\n *\n * @param terms - The terms for the NativeBalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the recipient address is invalid or balance/changeType are invalid.\n */\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeBalanceChange caveat that checks recipient balance changes.\n *\n * @param terms - The terms for the NativeBalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the recipient address is invalid or balance/changeType are invalid.\n */\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { recipient, balance, changeType: changeTypeNumber } = terms;\n\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid Address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([changeTypeHex, recipientHex, balanceHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a NativeBalanceChange caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded recipient is returned as hex or bytes.\n * @returns The decoded NativeBalanceChangeTerms object.\n */\nexport function decodeNativeBalanceChangeTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): NativeBalanceChangeTerms<DecodedBytesLike<'hex'>>;\nexport function decodeNativeBalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): NativeBalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded recipient is returned as hex or bytes.\n * @returns The decoded NativeBalanceChangeTerms object.\n */\nexport function decodeNativeBalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | NativeBalanceChangeTerms<DecodedBytesLike<'hex'>>\n | NativeBalanceChangeTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 53,\n 'Invalid NativeBalanceChange terms: must be exactly 53 bytes',\n );\n\n const changeType = extractNumber(hexTerms, 0, 1);\n const recipientHex = extractAddress(hexTerms, 1);\n const balance = extractBigInt(hexTerms, 21, 32);\n\n return {\n changeType,\n recipient: prepareResult(recipientHex, encodingOptions),\n balance,\n } as\n | NativeBalanceChangeTerms<DecodedBytesLike<'hex'>>\n | NativeBalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC20StreamingEnforcer\n *\n * Configures a linear streaming allowance for an ERC-20 token over time.\n *\n * Terms are encoded as 20-byte token address then four 32-byte big-endian uint256 words: initial amount, max amount, amount per second, start time.\n */\n\nimport { type BytesLike, bytesToHex, isHexString } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractAddress,\n extractBigInt,\n extractNumber,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of ERC20 tokens.\n */\nexport type ERC20StreamingTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The address of the ERC20 token contract. */\n tokenAddress: TBytesLike;\n /** The initial amount available immediately. */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred. */\n maxAmount: bigint;\n /** The rate at which allowance increases per second. */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (160 bytes).\n * @throws Error if tokenAddress is invalid.\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any of the parameters are invalid.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, initialAmount, maxAmount, amountPerSecond, startTime } =\n terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC20Streaming caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC20StreamingTerms object.\n */\nexport function decodeERC20StreamingTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC20StreamingTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC20StreamingTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC20StreamingTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC20StreamingTerms object.\n */\nexport function decodeERC20StreamingTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC20StreamingTerms<DecodedBytesLike<'hex'>>\n | ERC20StreamingTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 148,\n 'Invalid ERC20Streaming terms: must be exactly 148 bytes',\n );\n\n const tokenAddressHex = extractAddress(hexTerms, 0);\n const initialAmount = extractBigInt(hexTerms, 20, 32);\n const maxAmount = extractBigInt(hexTerms, 52, 32);\n const amountPerSecond = extractBigInt(hexTerms, 84, 32);\n const startTime = extractNumber(hexTerms, 116, 32);\n\n return {\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n } as\n | ERC20StreamingTerms<DecodedBytesLike<'hex'>>\n | ERC20StreamingTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC20TokenPeriodTransferEnforcer\n *\n * Limits periodic ERC-20 transfers for a token using amount, period length, and start date.\n *\n * Terms are encoded as 20-byte token address then three 32-byte big-endian uint256 words: period amount, period duration, start date.\n */\n\nimport { type BytesLike, isHexString, bytesToHex } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractAddress,\n extractBigInt,\n extractNumber,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a periodic transfer allowance of ERC20 tokens.\n */\nexport type ERC20TokenPeriodTransferTerms<\n TBytesLike extends BytesLike = BytesLike,\n> = {\n /** The address of the ERC20 token. */\n tokenAddress: TBytesLike;\n /** The maximum amount that can be transferred within each period. */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused tokens are forfeited once the period ends.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, periodAmount, periodDuration, startDate } = terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC20TokenPeriodTransfer caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC20TokenPeriodTransferTerms object.\n */\nexport function decodeERC20TokenPeriodTransferTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC20TokenPeriodTransferTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC20TokenPeriodTransferTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC20TokenPeriodTransferTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC20TokenPeriodTransferTerms object.\n */\nexport function decodeERC20TokenPeriodTransferTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC20TokenPeriodTransferTerms<DecodedBytesLike<'hex'>>\n | ERC20TokenPeriodTransferTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 116,\n 'Invalid ERC20TokenPeriodTransfer terms: must be exactly 116 bytes',\n );\n\n const tokenAddressHex = extractAddress(hexTerms, 0);\n const periodAmount = extractBigInt(hexTerms, 20, 32);\n const periodDuration = extractNumber(hexTerms, 52, 32);\n const startDate = extractNumber(hexTerms, 84, 32);\n\n return {\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n periodAmount,\n periodDuration,\n startDate,\n } as\n | ERC20TokenPeriodTransferTerms<DecodedBytesLike<'hex'>>\n | ERC20TokenPeriodTransferTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC20TransferAmountEnforcer\n *\n * Limits the amount of a given ERC-20 token that may be transferred.\n *\n * Terms are encoded as 20-byte token address followed by a 32-byte big-endian uint256 max amount.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n normalizeAddress,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ERC20TransferAmount caveat.\n */\nexport type ERC20TransferAmountTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The ERC-20 token address. */\n tokenAddress: TBytesLike;\n /** The maximum amount of tokens that can be transferred. */\n maxAmount: bigint;\n };\n\n/**\n * Creates terms for an ERC20TransferAmount caveat that caps transfer amount.\n *\n * @param terms - The terms for the ERC20TransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the token address is invalid or maxAmount is not positive.\n */\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TransferAmount caveat that caps transfer amount.\n *\n * @param terms - The terms for the ERC20TransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the token address is invalid or maxAmount is not positive.\n */\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, maxAmount } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n const maxAmountHex = `0x${toHexString({ value: maxAmount, size: 32 })}`;\n const hexValue = concatHex([tokenAddressHex, maxAmountHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC20TransferAmount caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC20TransferAmountTerms object.\n */\nexport function decodeERC20TransferAmountTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC20TransferAmountTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC20TransferAmountTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC20TransferAmountTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC20TransferAmountTerms object.\n */\nexport function decodeERC20TransferAmountTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC20TransferAmountTerms<DecodedBytesLike<'hex'>>\n | ERC20TransferAmountTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 52,\n 'Invalid ERC20TransferAmount terms: must be exactly 52 bytes',\n );\n\n const tokenAddressHex = extractAddress(hexTerms, 0);\n const maxAmount = extractBigInt(hexTerms, 20, 32);\n\n return {\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n maxAmount,\n } as\n | ERC20TransferAmountTerms<DecodedBytesLike<'hex'>>\n | ERC20TransferAmountTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC20BalanceChangeEnforcer\n *\n * Constrains ERC-20 balance change for a recipient relative to a reference balance.\n *\n * Terms are encoded as 1-byte direction (`0x00` = minimum increase, any non-zero e.g. `0x01` = maximum decrease), 20-byte token address, 20-byte recipient, then 32-byte big-endian balance amount.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n extractNumber,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC20BalanceChange caveat.\n */\nexport type ERC20BalanceChangeTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The ERC-20 token address. */\n tokenAddress: TBytesLike;\n /** The recipient address. */\n recipient: TBytesLike;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n };\n\n/**\n * Creates terms for an ERC20BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC20BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC20BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n balance,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n balanceHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC20BalanceChange caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded ERC20BalanceChangeTerms object.\n */\nexport function decodeERC20BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC20BalanceChangeTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC20BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC20BalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded ERC20BalanceChangeTerms object.\n */\nexport function decodeERC20BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC20BalanceChangeTerms<DecodedBytesLike<'hex'>>\n | ERC20BalanceChangeTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 73,\n 'Invalid ERC20BalanceChange terms: must be exactly 73 bytes',\n );\n\n const changeType = extractNumber(hexTerms, 0, 1);\n const tokenAddressHex = extractAddress(hexTerms, 1);\n const recipientHex = extractAddress(hexTerms, 21);\n const balance = extractBigInt(hexTerms, 41, 32);\n\n return {\n changeType,\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n recipient: prepareResult(recipientHex, encodingOptions),\n balance,\n } as\n | ERC20BalanceChangeTerms<DecodedBytesLike<'hex'>>\n | ERC20BalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC721BalanceChangeEnforcer\n *\n * Constrains ERC-721 balance (id count) change for a recipient.\n *\n * Terms are encoded as 1-byte direction (`0x00` = minimum increase, any non-zero e.g. `0x01` = maximum decrease), 20-byte token address, 20-byte recipient, then 32-byte big-endian amount.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n extractNumber,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC721BalanceChange caveat.\n */\nexport type ERC721BalanceChangeTerms<TBytesLike extends BytesLike = BytesLike> =\n {\n /** The ERC-721 token address. */\n tokenAddress: TBytesLike;\n /** The recipient address. */\n recipient: TBytesLike;\n /** The balance change amount. */\n amount: bigint;\n /** The balance change type. */\n changeType: number;\n };\n\n/**\n * Creates terms for an ERC721BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC721BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC721BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC721BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n amount,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (amount <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n amountHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC721BalanceChange caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded ERC721BalanceChangeTerms object.\n */\nexport function decodeERC721BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC721BalanceChangeTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC721BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC721BalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded ERC721BalanceChangeTerms object.\n */\nexport function decodeERC721BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC721BalanceChangeTerms<DecodedBytesLike<'hex'>>\n | ERC721BalanceChangeTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 73,\n 'Invalid ERC721BalanceChange terms: must be exactly 73 bytes',\n );\n\n const changeType = extractNumber(hexTerms, 0, 1);\n const tokenAddressHex = extractAddress(hexTerms, 1);\n const recipientHex = extractAddress(hexTerms, 21);\n const amount = extractBigInt(hexTerms, 41, 32);\n\n return {\n changeType,\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n recipient: prepareResult(recipientHex, encodingOptions),\n amount,\n } as\n | ERC721BalanceChangeTerms<DecodedBytesLike<'hex'>>\n | ERC721BalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC721TransferEnforcer\n *\n * Constrains transfer of a specific ERC-721 token id for a collection.\n *\n * Terms are encoded as 20-byte token address followed by a 32-byte big-endian uint256 token id.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n normalizeAddress,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ERC721Transfer caveat.\n */\nexport type ERC721TransferTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The ERC-721 token address. */\n tokenAddress: TBytesLike;\n /** The token id. */\n tokenId: bigint;\n};\n\n/**\n * Creates terms for an ERC721Transfer caveat that restricts transfers to a token and id.\n *\n * @param terms - The terms for the ERC721Transfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the token address is invalid or tokenId is negative.\n */\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC721Transfer caveat that restricts transfers to a token and id.\n *\n * @param terms - The terms for the ERC721Transfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the token address is invalid or tokenId is negative.\n */\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, tokenId } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n\n if (tokenId < 0n) {\n throw new Error('Invalid tokenId: must be a non-negative number');\n }\n\n const tokenIdHex = `0x${toHexString({ value: tokenId, size: 32 })}`;\n const hexValue = concatHex([tokenAddressHex, tokenIdHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC721Transfer caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC721TransferTerms object.\n */\nexport function decodeERC721TransferTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC721TransferTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC721TransferTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC721TransferTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token address is returned as hex or bytes.\n * @returns The decoded ERC721TransferTerms object.\n */\nexport function decodeERC721TransferTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC721TransferTerms<DecodedBytesLike<'hex'>>\n | ERC721TransferTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 52,\n 'Invalid ERC721Transfer terms: must be exactly 52 bytes',\n );\n\n const tokenAddressHex = extractAddress(hexTerms, 0);\n const tokenId = extractBigInt(hexTerms, 20, 32);\n\n return {\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n tokenId,\n } as\n | ERC721TransferTerms<DecodedBytesLike<'hex'>>\n | ERC721TransferTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ERC1155BalanceChangeEnforcer\n *\n * Constrains ERC-1155 balance change for a token id and recipient.\n *\n * Terms are encoded as 1-byte direction (`0x00` = minimum increase, any non-zero e.g. `0x01` = maximum decrease), 20-byte token address, 20-byte recipient, then 32-byte token id and 32-byte balance (each big-endian uint256).\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n concatHex,\n extractAddress,\n extractBigInt,\n extractNumber,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC1155BalanceChange caveat.\n */\nexport type ERC1155BalanceChangeTerms<\n TBytesLike extends BytesLike = BytesLike,\n> = {\n /** The ERC-1155 token address. */\n tokenAddress: TBytesLike;\n /** The recipient address. */\n recipient: TBytesLike;\n /** The token id. */\n tokenId: bigint;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC1155BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC1155BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC1155BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC1155BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n tokenId,\n balance,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n if (tokenId < 0n) {\n throw new Error('Invalid tokenId: must be a non-negative number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const tokenIdHex = `0x${toHexString({ value: tokenId, size: 32 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n tokenIdHex,\n balanceHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ERC1155BalanceChange caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded ERC1155BalanceChangeTerms object.\n */\nexport function decodeERC1155BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ERC1155BalanceChangeTerms<DecodedBytesLike<'hex'>>;\nexport function decodeERC1155BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ERC1155BalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded ERC1155BalanceChangeTerms object.\n */\nexport function decodeERC1155BalanceChangeTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ERC1155BalanceChangeTerms<DecodedBytesLike<'hex'>>\n | ERC1155BalanceChangeTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 105,\n 'Invalid ERC1155BalanceChange terms: must be exactly 105 bytes',\n );\n\n const changeType = extractNumber(hexTerms, 0, 1);\n const tokenAddressHex = extractAddress(hexTerms, 1);\n const recipientHex = extractAddress(hexTerms, 21);\n const tokenId = extractBigInt(hexTerms, 41, 32);\n const balance = extractBigInt(hexTerms, 73, 32);\n\n return {\n changeType,\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n recipient: prepareResult(recipientHex, encodingOptions),\n tokenId,\n balance,\n } as\n | ERC1155BalanceChangeTerms<DecodedBytesLike<'hex'>>\n | ERC1155BalanceChangeTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## NonceEnforcer\n *\n * Binds the delegation to a nonce word for revocation and replay semantics.\n *\n * Terms are encoded as one 32-byte word with the nonce right-aligned and zero-padded on the left.\n */\n\nimport { isHexString } from '@metamask/utils';\nimport type { BytesLike } from '@metamask/utils';\n\nimport { assertHexByteExactLength } from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// char length of 32 byte hex string (including 0x prefix)\nconst MAX_NONCE_STRING_LENGTH = 66;\n\n/**\n * Terms for configuring a Nonce caveat.\n */\nexport type NonceTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The nonce as BytesLike (0x-prefixed hex string or Uint8Array) to allow bulk revocation of delegations. */\n nonce: TBytesLike;\n};\n\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the nonce is invalid.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the nonce is invalid or empty.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { nonce } = terms;\n\n // Handle zero-length Uint8Array specifically\n if (nonce instanceof Uint8Array && nonce.length === 0) {\n throw new Error('Invalid nonce: Uint8Array must not be empty');\n }\n\n // Validate that strings have 0x prefix (as required by BytesLike)\n if (typeof nonce === 'string' && !nonce.startsWith('0x')) {\n throw new Error('Invalid nonce: string must have 0x prefix');\n }\n\n // Convert to hex string for consistent processing\n const hexNonce = bytesLikeToHex(nonce);\n\n // Check for empty hex string (0x) first - more specific error\n if (hexNonce === '0x') {\n throw new Error('Invalid nonce: must not be empty');\n }\n\n if (!isHexString(hexNonce)) {\n throw new Error('Invalid nonce: must be a valid BytesLike value');\n }\n\n if (hexNonce.length > MAX_NONCE_STRING_LENGTH) {\n throw new Error('Invalid nonce: must be 32 bytes or less in length');\n }\n\n // Remove '0x' prefix for padding, then add it back\n const nonceWithoutPrefix = hexNonce.slice(2);\n const paddedNonce = nonceWithoutPrefix.padStart(64, '0'); // 64 hex chars = 32 bytes\n const hexValue = `0x${paddedNonce}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a Nonce caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded nonce is returned as hex or bytes.\n * @returns The decoded NonceTerms object.\n */\nexport function decodeNonceTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): NonceTerms<DecodedBytesLike<'hex'>>;\nexport function decodeNonceTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): NonceTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded nonce is returned as hex or bytes.\n * @returns The decoded NonceTerms object.\n */\nexport function decodeNonceTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): NonceTerms<DecodedBytesLike<'hex'>> | NonceTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid Nonce terms: must be exactly 32 bytes',\n );\n\n const nonce = prepareResult(hexTerms, encodingOptions);\n\n return { nonce } as\n | NonceTerms<DecodedBytesLike<'hex'>>\n | NonceTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## AllowedCalldataEnforcer\n *\n * Constrains the calldata bytes starting at a given byte offset to match an expected fragment.\n *\n * Terms are encoded as a 32-byte big-endian start index followed by the expected calldata bytes (not ABI-wrapped).\n */\n\nimport { bytesToHex, remove0x, type BytesLike } from '@metamask/utils';\n\nimport {\n assertHexBytesMinLength,\n extractNumber,\n extractRemainingHex,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedCalldata caveat.\n */\nexport type AllowedCalldataTerms<TBytesLike extends BytesLike = BytesLike> = {\n startIndex: number;\n value: TBytesLike;\n};\n\n/**\n * Creates terms for an AllowedCalldata caveat that ensures the provided execution calldata\n * matches the expected calldata at the specified index.\n *\n * @param terms - The terms for the AllowedCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedCalldata caveat that ensures the provided execution calldata\n * matches the expected calldata at the specified index.\n *\n * @param terms - The terms for the AllowedCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { startIndex, value } = terms;\n\n if (startIndex < 0) {\n throw new Error('Invalid startIndex: must be zero or positive');\n }\n\n if (!Number.isInteger(startIndex)) {\n throw new Error('Invalid startIndex: must be a whole number');\n }\n\n let unprefixedValue: string;\n\n if (typeof value === 'string') {\n if (!value.startsWith('0x')) {\n throw new Error('Invalid value: must be a hex string starting with 0x');\n }\n unprefixedValue = remove0x(value);\n } else {\n unprefixedValue = remove0x(bytesToHex(value));\n }\n\n const indexHex = toHexString({ value: startIndex, size: 32 });\n\n return prepareResult(`0x${indexHex}${unprefixedValue}`, encodingOptions);\n}\n\n/**\n * Decodes terms for an AllowedCalldata caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether the decoded value fragment is returned as hex or bytes.\n * @returns The decoded AllowedCalldataTerms object.\n */\nexport function decodeAllowedCalldataTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): AllowedCalldataTerms<DecodedBytesLike<'hex'>>;\nexport function decodeAllowedCalldataTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): AllowedCalldataTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether the decoded value fragment is returned as hex or bytes.\n * @returns The decoded AllowedCalldataTerms object.\n */\nexport function decodeAllowedCalldataTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | AllowedCalldataTerms<DecodedBytesLike<'hex'>>\n | AllowedCalldataTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexBytesMinLength(\n hexTerms,\n 32,\n 'Invalid AllowedCalldata terms: must be at least 32 bytes',\n );\n\n const startIndex = extractNumber(hexTerms, 0, 32);\n const valueHex = extractRemainingHex(hexTerms, 32);\n const value = prepareResult(valueHex, encodingOptions);\n\n return { startIndex, value } as\n | AllowedCalldataTerms<DecodedBytesLike<'hex'>>\n | AllowedCalldataTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## AllowedMethodsEnforcer\n *\n * Specifies 4 byte method selectors that the delegate is allowed to call.\n *\n * Terms are encoded as a concatenation of 4-byte function selectors with no padding between selectors.\n */\n\nimport { bytesToHex, isHexString, type BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteLengthAtLeastOneMultipleOf,\n concatHex,\n extractHex,\n getByteLength,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedMethods caveat.\n */\nexport type AllowedMethodsTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** An array of 4-byte method selectors that the delegate is allowed to call. */\n selectors: TBytesLike[];\n};\n\nconst FUNCTION_SELECTOR_STRING_LENGTH = 10; // 0x + 8 hex chars\nconst INVALID_SELECTOR_ERROR =\n 'Invalid selector: must be a 4 byte hex string, abi function signature, or AbiFunction';\n\n/**\n * Creates terms for an AllowedMethods caveat that restricts calls to a set of method selectors.\n *\n * @param terms - The terms for the AllowedMethods caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the selectors array is empty or contains invalid selectors.\n */\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedMethods caveat that restricts calls to a set of method selectors.\n *\n * @param terms - The terms for the AllowedMethods caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the selectors array is empty or contains invalid selectors.\n */\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { selectors } = terms;\n\n if (!selectors || selectors.length === 0) {\n throw new Error('Invalid selectors: must provide at least one selector');\n }\n\n const normalizedSelectors = selectors.map((selector) => {\n if (typeof selector === 'string') {\n if (\n isHexString(selector) &&\n selector.length === FUNCTION_SELECTOR_STRING_LENGTH\n ) {\n return selector;\n }\n throw new Error(INVALID_SELECTOR_ERROR);\n }\n\n if (selector.length !== 4) {\n throw new Error(INVALID_SELECTOR_ERROR);\n }\n\n return bytesToHex(selector);\n });\n\n const hexValue = concatHex(normalizedSelectors);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an AllowedMethods caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded selector values are returned as hex or bytes.\n * @returns The decoded AllowedMethodsTerms object.\n */\nexport function decodeAllowedMethodsTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): AllowedMethodsTerms<DecodedBytesLike<'hex'>>;\nexport function decodeAllowedMethodsTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): AllowedMethodsTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded selector values are returned as hex or bytes.\n * @returns The decoded AllowedMethodsTerms object.\n */\nexport function decodeAllowedMethodsTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | AllowedMethodsTerms<DecodedBytesLike<'hex'>>\n | AllowedMethodsTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n\n const selectorSize = 4;\n assertHexByteLengthAtLeastOneMultipleOf(\n hexTerms,\n selectorSize,\n 'Invalid selectors: must be a multiple of 4',\n );\n const selectorCount = getByteLength(hexTerms) / selectorSize;\n\n const selectors: (Hex | Uint8Array)[] = [];\n for (let i = 0; i < selectorCount; i++) {\n const selector = extractHex(hexTerms, i * selectorSize, selectorSize);\n selectors.push(prepareResult(selector, encodingOptions));\n }\n\n return { selectors } as\n | AllowedMethodsTerms<DecodedBytesLike<'hex'>>\n | AllowedMethodsTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## AllowedTargetsEnforcer\n *\n * Restricts which contract addresses the delegate may call.\n *\n * Terms are encoded as the concatenation of 20-byte addresses in order with no padding between addresses.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteLengthAtLeastOneMultipleOf,\n concatHex,\n extractAddress,\n getByteLength,\n normalizeAddress,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedTargets caveat.\n */\nexport type AllowedTargetsTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** An array of target addresses that the delegate is allowed to call. */\n targets: TBytesLike[];\n};\n\n/**\n * Creates terms for an AllowedTargets caveat that restricts calls to a set of target addresses.\n *\n * @param terms - The terms for the AllowedTargets caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the targets array is empty or contains invalid addresses.\n */\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedTargets caveat that restricts calls to a set of target addresses.\n *\n * @param terms - The terms for the AllowedTargets caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the targets array is empty or contains invalid addresses.\n */\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { targets } = terms;\n\n if (!targets || targets.length === 0) {\n throw new Error(\n 'Invalid targets: must provide at least one target address',\n );\n }\n\n const normalizedTargets = targets.map((target) =>\n normalizeAddress(target, 'Invalid targets: must be valid addresses'),\n );\n\n const hexValue = concatHex(normalizedTargets);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an AllowedTargets caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded AllowedTargetsTerms object.\n */\nexport function decodeAllowedTargetsTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): AllowedTargetsTerms<DecodedBytesLike<'hex'>>;\nexport function decodeAllowedTargetsTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): AllowedTargetsTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded AllowedTargetsTerms object.\n */\nexport function decodeAllowedTargetsTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | AllowedTargetsTerms<DecodedBytesLike<'hex'>>\n | AllowedTargetsTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n\n const addressSize = 20;\n assertHexByteLengthAtLeastOneMultipleOf(\n hexTerms,\n addressSize,\n 'Invalid targets: must be a multiple of 20',\n );\n const addressCount = getByteLength(hexTerms) / addressSize;\n\n const targets: (Hex | Uint8Array)[] = [];\n for (let i = 0; i < addressCount; i++) {\n const target = extractAddress(hexTerms, i * addressSize);\n targets.push(prepareResult(target, encodingOptions));\n }\n\n return { targets } as\n | AllowedTargetsTerms<DecodedBytesLike<'hex'>>\n | AllowedTargetsTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## ArgsEqualityCheckEnforcer\n *\n * Requires args on the caveat to equal an expected byte sequence.\n *\n * Terms are encoded as the raw expected args hex.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport { normalizeHex } from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ArgsEqualityCheck caveat.\n */\nexport type ArgsEqualityCheckTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The expected args that must match exactly when redeeming the delegation. */\n args: TBytesLike;\n};\n\n/**\n * Creates terms for an ArgsEqualityCheck caveat that requires exact args matching.\n *\n * @param terms - The terms for the ArgsEqualityCheck caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if args is not a valid hex string.\n */\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ArgsEqualityCheck caveat that requires exact args matching.\n *\n * @param terms - The terms for the ArgsEqualityCheck caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if args is not a valid hex string.\n */\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { args } = terms;\n\n if (typeof args === 'string' && args === '0x') {\n return prepareResult(args, encodingOptions);\n }\n\n const hexValue = normalizeHex(\n args,\n 'Invalid config: args must be a valid hex string',\n );\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an ArgsEqualityCheck caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded args are returned as hex or bytes.\n * @returns The decoded ArgsEqualityCheckTerms object.\n */\nexport function decodeArgsEqualityCheckTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): ArgsEqualityCheckTerms<DecodedBytesLike<'hex'>>;\nexport function decodeArgsEqualityCheckTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): ArgsEqualityCheckTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded args are returned as hex or bytes.\n * @returns The decoded ArgsEqualityCheckTerms object.\n */\nexport function decodeArgsEqualityCheckTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | ArgsEqualityCheckTerms<DecodedBytesLike<'hex'>>\n | ArgsEqualityCheckTerms<DecodedBytesLike<'bytes'>> {\n const argsHex = bytesLikeToHex(terms);\n const args = prepareResult(argsHex, encodingOptions);\n return { args } as\n | ArgsEqualityCheckTerms<DecodedBytesLike<'hex'>>\n | ArgsEqualityCheckTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## BlockNumberEnforcer\n *\n * Restricts redemption to a block number range (strict inequalities on-chain: valid when `block.number > afterThreshold` if after is set, and `block.number < beforeThreshold` if before is set).\n *\n * Terms are encoded as a 16-byte after threshold followed by a 16-byte before threshold (each big-endian, zero-padded; interpreted as `uint128`).\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractBigInt,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a BlockNumber caveat.\n */\nexport type BlockNumberTerms = {\n /** The block number after which the delegation is valid. Set to 0n to disable. */\n afterThreshold: bigint;\n /** The block number before which the delegation is valid. Set to 0n to disable. */\n beforeThreshold: bigint;\n};\n\n/**\n * Creates terms for a BlockNumber caveat that constrains delegation validity by block range.\n *\n * @param terms - The terms for the BlockNumber caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if both thresholds are zero or if afterThreshold >= beforeThreshold when both are set.\n */\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a BlockNumber caveat that constrains delegation validity by block range.\n *\n * @param terms - The terms for the BlockNumber caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if both thresholds are zero or if afterThreshold >= beforeThreshold when both are set.\n */\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { afterThreshold, beforeThreshold } = terms;\n\n if (afterThreshold < 0n || beforeThreshold < 0n) {\n throw new Error('Invalid thresholds: block numbers must be non-negative');\n }\n\n if (afterThreshold === 0n && beforeThreshold === 0n) {\n throw new Error(\n 'Invalid thresholds: At least one of afterThreshold or beforeThreshold must be specified',\n );\n }\n\n if (beforeThreshold !== 0n && afterThreshold >= beforeThreshold) {\n throw new Error(\n 'Invalid thresholds: afterThreshold must be less than beforeThreshold if both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({ value: afterThreshold, size: 16 });\n const beforeThresholdHex = toHexString({ value: beforeThreshold, size: 16 });\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a BlockNumber caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded BlockNumberTerms object.\n */\nexport function decodeBlockNumberTerms(terms: BytesLike): BlockNumberTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid BlockNumber terms: must be exactly 32 bytes',\n );\n const afterThreshold = extractBigInt(hexTerms, 0, 16);\n const beforeThreshold = extractBigInt(hexTerms, 16, 16);\n return { afterThreshold, beforeThreshold };\n}\n","/**\n * ## DeployedEnforcer\n *\n * Constrains contract deployment to a specific address, salt, and bytecode.\n *\n * Terms are encoded as 20-byte contract address, 32-byte left-padded salt, then creation bytecode bytes.\n */\n\nimport type { BytesLike } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\n\nimport {\n assertHexBytesMinLength,\n concatHex,\n extractAddress,\n extractHex,\n extractRemainingHex,\n normalizeAddress,\n normalizeHex,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a Deployed caveat.\n */\nexport type DeployedTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The contract address. */\n contractAddress: TBytesLike;\n /** The deployment salt. */\n salt: TBytesLike;\n /** The contract bytecode. */\n bytecode: TBytesLike;\n};\n\n/**\n * Creates terms for a Deployed caveat that constrains deployments by address, salt, and bytecode.\n *\n * @param terms - The terms for the Deployed caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the contract address, salt, or bytecode is invalid.\n */\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Deployed caveat that constrains deployments by address, salt, and bytecode.\n *\n * @param terms - The terms for the Deployed caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the contract address, salt, or bytecode is invalid.\n */\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { contractAddress, salt, bytecode } = terms;\n\n const contractAddressHex = normalizeAddress(\n contractAddress,\n 'Invalid contractAddress: must be a valid Ethereum address',\n );\n const saltHex = normalizeHex(\n salt,\n 'Invalid salt: must be a valid hexadecimal string',\n );\n const bytecodeHex = normalizeHex(\n bytecode,\n 'Invalid bytecode: must be a valid hexadecimal string',\n );\n\n const unprefixedSalt = remove0x(saltHex);\n if (unprefixedSalt.length > 64) {\n throw new Error('Invalid salt: must be a valid hexadecimal string');\n }\n const paddedSalt = `0x${unprefixedSalt.padStart(64, '0')}`;\n\n const hexValue = concatHex([contractAddressHex, paddedSalt, bytecodeHex]);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a Deployed caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded address, salt, and bytecode are returned as hex or bytes.\n * @returns The decoded DeployedTerms object.\n */\nexport function decodeDeployedTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): DeployedTerms<DecodedBytesLike<'hex'>>;\nexport function decodeDeployedTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): DeployedTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded address, salt, and bytecode are returned as hex or bytes.\n * @returns The decoded DeployedTerms object.\n */\nexport function decodeDeployedTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | DeployedTerms<DecodedBytesLike<'hex'>>\n | DeployedTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexBytesMinLength(\n hexTerms,\n 52,\n 'Invalid Deployed terms: must be at least 52 bytes',\n );\n\n const contractAddressHex = extractAddress(hexTerms, 0);\n const saltHex = extractHex(hexTerms, 20, 32);\n const bytecodeHex = extractRemainingHex(hexTerms, 52);\n\n return {\n contractAddress: prepareResult(contractAddressHex, encodingOptions),\n salt: prepareResult(saltHex, encodingOptions),\n bytecode: prepareResult(bytecodeHex, encodingOptions),\n } as\n | DeployedTerms<DecodedBytesLike<'hex'>>\n | DeployedTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## IdEnforcer\n *\n * Ensures each delegation redemption uses a unique numeric id.\n *\n * Terms are encoded as a single 32-byte big-endian uint256 id.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractBigInt,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\nconst MAX_UINT256 = BigInt(`0x${'f'.repeat(64)}`);\n\n/**\n * Terms for configuring an Id caveat.\n */\nexport type IdTerms = {\n /** An id for the delegation. Only one delegation may be redeemed with any given id. */\n id: bigint | number;\n};\n\n/**\n * Creates terms for an Id caveat that restricts delegations by unique identifier.\n *\n * @param terms - The terms for the Id caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the id is invalid or out of range.\n */\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an Id caveat that restricts delegations by unique identifier.\n *\n * @param terms - The terms for the Id caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the id is invalid or out of range.\n */\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { id } = terms;\n\n let idBigInt: bigint;\n\n if (typeof id === 'number') {\n if (!Number.isInteger(id)) {\n throw new Error('Invalid id: must be an integer');\n }\n idBigInt = BigInt(id);\n } else if (typeof id === 'bigint') {\n idBigInt = id;\n } else {\n throw new Error('Invalid id: must be a bigint or number');\n }\n\n if (idBigInt < 0n) {\n throw new Error('Invalid id: must be a non-negative number');\n }\n\n if (idBigInt > MAX_UINT256) {\n throw new Error('Invalid id: must be less than 2^256');\n }\n\n const hexValue = `0x${toHexString({ value: idBigInt, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for an Id caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded IdTerms object.\n */\nexport function decodeIdTerms(terms: BytesLike): IdTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid Id terms: must be exactly 32 bytes',\n );\n const id = extractBigInt(hexTerms, 0, 32);\n return { id };\n}\n","/**\n * ## LimitedCallsEnforcer\n *\n * Caps how many times the delegation may be redeemed.\n *\n * Terms are encoded as a single 32-byte big-endian uint256 call limit.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractNumber,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a LimitedCalls caveat.\n */\nexport type LimitedCallsTerms = {\n /** The maximum number of times this delegation may be redeemed. */\n limit: number;\n};\n\n/**\n * Creates terms for a LimitedCalls caveat that restricts the number of redeems.\n *\n * @param terms - The terms for the LimitedCalls caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the limit is not a positive integer.\n */\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a LimitedCalls caveat that restricts the number of redeems.\n *\n * @param terms - The terms for the LimitedCalls caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the limit is not a positive integer.\n */\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { limit } = terms;\n\n if (!Number.isInteger(limit)) {\n throw new Error('Invalid limit: must be an integer');\n }\n\n if (limit <= 0) {\n throw new Error('Invalid limit: must be a positive integer');\n }\n\n const hexValue = `0x${toHexString({ value: limit, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a LimitedCalls caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @returns The decoded LimitedCallsTerms object.\n */\nexport function decodeLimitedCallsTerms(terms: BytesLike): LimitedCallsTerms {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 32,\n 'Invalid LimitedCalls terms: must be exactly 32 bytes',\n );\n const limit = extractNumber(hexTerms, 0, 32);\n return { limit };\n}\n","/**\n * ## MultiTokenPeriodEnforcer\n *\n * Sets independent periodic transfer limits for multiple tokens (ERC-20 or native).\n *\n * Terms are encoded by repeating, per entry: 20-byte token address (`address(0)` denotes native token) then three 32-byte big-endian uint256 words (period amount, period duration, start date).\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteLengthAtLeastOneMultipleOf,\n concatHex,\n extractAddress,\n extractBigInt,\n extractNumber,\n getByteLength,\n normalizeAddress,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Configuration for a single token in MultiTokenPeriod terms.\n */\nexport type TokenPeriodConfig<TBytesLike extends BytesLike = BytesLike> = {\n token: TBytesLike;\n periodAmount: bigint;\n periodDuration: number;\n startDate: number;\n};\n\n/**\n * Terms for configuring a MultiTokenPeriod caveat.\n */\nexport type MultiTokenPeriodTerms<TBytesLike extends BytesLike = BytesLike> = {\n tokenConfigs: TokenPeriodConfig<TBytesLike>[];\n};\n\n/**\n * Creates terms for a MultiTokenPeriod caveat that configures multiple token periods.\n *\n * @param terms - The terms for the MultiTokenPeriod caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the tokenConfigs array is empty or contains invalid parameters.\n */\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a MultiTokenPeriod caveat that configures multiple token periods.\n *\n * @param terms - The terms for the MultiTokenPeriod caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the tokenConfigs array is empty or contains invalid parameters.\n */\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenConfigs } = terms;\n\n if (!tokenConfigs || tokenConfigs.length === 0) {\n throw new Error(\n 'MultiTokenPeriodBuilder: tokenConfigs array cannot be empty',\n );\n }\n\n const hexParts: string[] = [];\n\n for (const tokenConfig of tokenConfigs) {\n const tokenHex = normalizeAddress(\n tokenConfig.token,\n `Invalid token address: ${String(tokenConfig.token)}`,\n );\n\n if (tokenConfig.periodAmount <= 0n) {\n throw new Error('Invalid period amount: must be greater than 0');\n }\n\n if (tokenConfig.periodDuration <= 0) {\n throw new Error('Invalid period duration: must be greater than 0');\n }\n\n if (tokenConfig.startDate <= 0) {\n throw new Error('Invalid start date: must be greater than 0');\n }\n\n hexParts.push(\n tokenHex,\n `0x${toHexString({ value: tokenConfig.periodAmount, size: 32 })}`,\n `0x${toHexString({ value: tokenConfig.periodDuration, size: 32 })}`,\n `0x${toHexString({ value: tokenConfig.startDate, size: 32 })}`,\n );\n }\n\n const hexValue = concatHex(hexParts);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a MultiTokenPeriod caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token addresses are returned as hex or bytes.\n * @returns The decoded MultiTokenPeriodTerms object.\n */\nexport function decodeMultiTokenPeriodTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): MultiTokenPeriodTerms<DecodedBytesLike<'hex'>>;\nexport function decodeMultiTokenPeriodTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): MultiTokenPeriodTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded token addresses are returned as hex or bytes.\n * @returns The decoded MultiTokenPeriodTerms object.\n */\nexport function decodeMultiTokenPeriodTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | MultiTokenPeriodTerms<DecodedBytesLike<'hex'>>\n | MultiTokenPeriodTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n\n const configSize = 116;\n assertHexByteLengthAtLeastOneMultipleOf(\n hexTerms,\n configSize,\n 'Invalid MultiTokenPeriod terms: must be a multiple of 116 bytes',\n );\n const configCount = getByteLength(hexTerms) / configSize;\n\n const tokenConfigs: TokenPeriodConfig[] = [];\n for (let i = 0; i < configCount; i++) {\n const offset = i * configSize;\n const tokenHex = extractAddress(hexTerms, offset);\n const periodAmount = extractBigInt(hexTerms, offset + 20, 32);\n const periodDuration = extractNumber(hexTerms, offset + 52, 32);\n const startDate = extractNumber(hexTerms, offset + 84, 32);\n\n tokenConfigs.push({\n token: prepareResult(tokenHex, encodingOptions),\n periodAmount,\n periodDuration,\n startDate,\n });\n }\n\n return { tokenConfigs } as\n | MultiTokenPeriodTerms<DecodedBytesLike<'hex'>>\n | MultiTokenPeriodTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## OwnershipTransferEnforcer\n *\n * Constrains ownership transfer for a specific contract.\n *\n * Terms are encoded as the 20-byte contract address only.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteExactLength,\n extractAddress,\n normalizeAddress,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an OwnershipTransfer caveat.\n */\nexport type OwnershipTransferTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** The contract address for which ownership transfers are allowed. */\n contractAddress: TBytesLike;\n};\n\n/**\n * Creates terms for an OwnershipTransfer caveat that constrains ownership transfers to a contract.\n *\n * @param terms - The terms for the OwnershipTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the contract address is invalid.\n */\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an OwnershipTransfer caveat that constrains ownership transfers to a contract.\n *\n * @param terms - The terms for the OwnershipTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the contract address is invalid.\n */\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { contractAddress } = terms;\n\n const contractAddressHex = normalizeAddress(\n contractAddress,\n 'Invalid contractAddress: must be a valid address',\n );\n\n return prepareResult(contractAddressHex, encodingOptions);\n}\n\n/**\n * Decodes terms for an OwnershipTransfer caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded contract address is returned as hex or bytes.\n * @returns The decoded OwnershipTransferTerms object.\n */\nexport function decodeOwnershipTransferTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): OwnershipTransferTerms<DecodedBytesLike<'hex'>>;\nexport function decodeOwnershipTransferTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): OwnershipTransferTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded contract address is returned as hex or bytes.\n * @returns The decoded OwnershipTransferTerms object.\n */\nexport function decodeOwnershipTransferTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | OwnershipTransferTerms<DecodedBytesLike<'hex'>>\n | OwnershipTransferTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexByteExactLength(\n hexTerms,\n 20,\n 'Invalid OwnershipTransfer terms: must be exactly 20 bytes',\n );\n const contractAddressHex = extractAddress(hexTerms, 0);\n return {\n contractAddress: prepareResult(contractAddressHex, encodingOptions),\n } as\n | OwnershipTransferTerms<DecodedBytesLike<'hex'>>\n | OwnershipTransferTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## RedeemerEnforcer\n *\n * Restricts which addresses may redeem the delegation.\n *\n * Terms are encoded as the concatenation of 20-byte redeemer addresses in order with no padding between addresses.\n */\n\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n assertHexByteLengthAtLeastOneMultipleOf,\n concatHex,\n extractAddress,\n getByteLength,\n normalizeAddress,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a Redeemer caveat.\n */\nexport type RedeemerTerms<TBytesLike extends BytesLike = BytesLike> = {\n /** An array of addresses allowed to redeem the delegation. */\n redeemers: TBytesLike[];\n};\n\n/**\n * Creates terms for a Redeemer caveat that restricts who may redeem.\n *\n * @param terms - The terms for the Redeemer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the redeemers array is empty or contains invalid addresses.\n */\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Redeemer caveat that restricts who may redeem.\n *\n * @param terms - The terms for the Redeemer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if the redeemers array is empty or contains invalid addresses.\n */\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { redeemers } = terms;\n\n if (!redeemers || redeemers.length === 0) {\n throw new Error(\n 'Invalid redeemers: must specify at least one redeemer address',\n );\n }\n\n const normalizedRedeemers = redeemers.map((redeemer) =>\n normalizeAddress(redeemer, 'Invalid redeemers: must be a valid address'),\n );\n\n const hexValue = concatHex(normalizedRedeemers);\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a Redeemer caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded RedeemerTerms object.\n */\nexport function decodeRedeemerTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): RedeemerTerms<DecodedBytesLike<'hex'>>;\nexport function decodeRedeemerTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): RedeemerTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses are returned as hex or bytes.\n * @returns The decoded RedeemerTerms object.\n */\nexport function decodeRedeemerTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | RedeemerTerms<DecodedBytesLike<'hex'>>\n | RedeemerTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n\n const addressSize = 20;\n assertHexByteLengthAtLeastOneMultipleOf(\n hexTerms,\n addressSize,\n 'Invalid redeemers: must be a multiple of 20',\n );\n const addressCount = getByteLength(hexTerms) / addressSize;\n\n const redeemers: (Hex | Uint8Array)[] = [];\n for (let i = 0; i < addressCount; i++) {\n const redeemer = extractAddress(hexTerms, i * addressSize);\n redeemers.push(prepareResult(redeemer, encodingOptions));\n }\n\n return { redeemers } as\n | RedeemerTerms<DecodedBytesLike<'hex'>>\n | RedeemerTerms<DecodedBytesLike<'bytes'>>;\n}\n","/**\n * ## SpecificActionERC20TransferBatchEnforcer\n *\n * Encodes caveat terms for a batch of exactly two executions: first call must match\n * `target` + `calldata`; second must be `IERC20.transfer` to `recipient` for `amount`\n * on `tokenAddress` (see on-chain `beforeHook`).\n *\n * - bytes 0–19: ERC-20 token address\n * - bytes 20–39: transfer recipient\n * - bytes 40–71: transfer amount (uint256, 32 bytes)\n * - bytes 72–91: first execution target (`firstTarget` in Enforcer)\n * - bytes 92–end: first execution calldata, raw body only (no ABI length prefix; `firstCalldata` in Enforcer)\n */\n\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport {\n assertHexBytesMinLength,\n concatHex,\n extractAddress,\n extractBigInt,\n extractRemainingHex,\n normalizeAddress,\n toHexString,\n} from '../internalUtils';\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type DecodedBytesLike,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a SpecificActionERC20TransferBatch caveat.\n */\nexport type SpecificActionERC20TransferBatchTerms<\n TBytesLike extends BytesLike = BytesLike,\n> = {\n /** The address of the ERC-20 token contract. */\n tokenAddress: TBytesLike;\n /** The recipient of the ERC-20 transfer. */\n recipient: TBytesLike;\n /** The amount of tokens to transfer. */\n amount: bigint;\n /** The target address for the first batch execution (`firstTarget` in the enforcer). */\n target: TBytesLike;\n /** Calldata for the first execution only, without an ABI length prefix (`firstCalldata` on-chain). */\n calldata: TBytesLike;\n};\n\n/**\n * Creates terms for a SpecificActionERC20TransferBatch caveat that enforces a\n * specific action followed by an ERC20 transfer.\n *\n * @param terms - The terms for the SpecificActionERC20TransferBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any address is invalid or amount is not positive.\n */\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a SpecificActionERC20TransferBatch caveat that enforces a\n * specific action followed by an ERC20 transfer.\n *\n * @param terms - The terms for the SpecificActionERC20TransferBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Encoded terms.\n * @throws Error if any address is invalid or amount is not positive.\n */\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, recipient, amount, target, calldata } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddress(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n const targetHex = normalizeAddress(\n target,\n 'Invalid target: must be a valid address',\n );\n\n let calldataHex: string;\n if (typeof calldata === 'string') {\n if (!calldata.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n calldataHex = calldata;\n } else {\n calldataHex = bytesToHex(calldata);\n }\n\n if (amount <= 0n) {\n throw new Error('Invalid amount: must be a positive number');\n }\n\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n\n const hexValue = concatHex([\n tokenAddressHex,\n recipientHex,\n amountHex,\n targetHex,\n calldataHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n\n/**\n * Decodes terms for a SpecificActionERC20TransferBatch caveat from encoded hex data.\n *\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses and calldata are returned as hex or bytes.\n * @returns The decoded SpecificActionERC20TransferBatchTerms object.\n */\nexport function decodeSpecificActionERC20TransferBatchTerms(\n terms: BytesLike,\n encodingOptions?: EncodingOptions<'hex'>,\n): SpecificActionERC20TransferBatchTerms<DecodedBytesLike<'hex'>>;\nexport function decodeSpecificActionERC20TransferBatchTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<'bytes'>,\n): SpecificActionERC20TransferBatchTerms<DecodedBytesLike<'bytes'>>;\n/**\n * @param terms - The encoded terms as a hex string or Uint8Array.\n * @param encodingOptions - Whether decoded addresses and calldata are returned as hex or bytes.\n * @returns The decoded SpecificActionERC20TransferBatchTerms object.\n */\nexport function decodeSpecificActionERC20TransferBatchTerms(\n terms: BytesLike,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n):\n | SpecificActionERC20TransferBatchTerms<DecodedBytesLike<'hex'>>\n | SpecificActionERC20TransferBatchTerms<DecodedBytesLike<'bytes'>> {\n const hexTerms = bytesLikeToHex(terms);\n assertHexBytesMinLength(\n hexTerms,\n 92,\n 'Invalid SpecificActionERC20TransferBatch terms: must be at least 92 bytes',\n );\n\n const tokenAddressHex = extractAddress(hexTerms, 0);\n const recipientHex = extractAddress(hexTerms, 20);\n const amount = extractBigInt(hexTerms, 40, 32);\n const targetHex = extractAddress(hexTerms, 72);\n const calldataHex = extractRemainingHex(hexTerms, 92);\n\n return {\n tokenAddress: prepareResult(tokenAddressHex, encodingOptions),\n recipient: prepareResult(recipientHex, encodingOptions),\n amount,\n target: prepareResult(targetHex, encodingOptions),\n calldata: prepareResult(calldataHex, encodingOptions),\n } as\n | SpecificActionERC20TransferBatchTerms<DecodedBytesLike<'hex'>>\n | SpecificActionERC20TransferBatchTerms<DecodedBytesLike<'bytes'>>;\n}\n","import { encode, encodeSingle, decodeSingle } from '@metamask/abi-utils';\nimport { hexToBytes, type BytesLike } from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nimport {\n bytesLikeToBytes,\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from './returns';\nimport type { CaveatStruct, DelegationStruct, Hex } from './types';\n\n/**\n * When designated as the delegate address in a delegation, this allows any beneficiary to redeem the delegation.\n */\nexport const ANY_BENEFICIARY =\n '0x0000000000000000000000000000000000000a11' as const;\n\n/**\n * To be used on a delegation as the root authority.\n */\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as const;\n\n/**\n * The typehash for a delegation, used when generating a delegation hash.\n *\n * keccak('Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)')\n */\nexport const DELEGATION_TYPEHASH =\n '0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e' as const;\n\n/**\n * The typehash for a caveat, used when generating a caveat hash.\n *\n * keccak('Caveat(address enforcer,bytes terms)')\n */\nexport const CAVEAT_TYPEHASH =\n '0x80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d' as const;\n\n/**\n * The ABI types for an array of delegations.\n */\nconst DELEGATION_ARRAY_ABI_TYPES =\n '(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)[]' as const;\n\n/**\n * The ABI type for a single delegation.\n */\nconst DELEGATION_ABI_TYPE =\n '(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)' as const;\n\n/**\n * Encodes an array of delegations into a permission context.\n *\n * @param delegations - The delegations to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegations as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Encodes an array of delegations into a permission context.\n *\n * @param delegations - The delegations to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegations as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n let result: Uint8Array;\n\n if (delegations.length === 0) {\n // short circuit for empty delegations, derived from\n // `encode(['(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)[]'],[[]],);`\n result = new Uint8Array(64);\n result[31] = 0x20;\n } else {\n const encodableStructs = delegations.map((struct) => [\n struct.delegate,\n struct.delegator,\n struct.authority,\n struct.caveats.map((caveat) => [\n caveat.enforcer,\n caveat.terms,\n caveat.args,\n ]),\n struct.salt,\n struct.signature,\n ]);\n\n result = encodeSingle(DELEGATION_ARRAY_ABI_TYPES, encodableStructs);\n }\n\n return prepareResult(result, options);\n}\n\n/**\n * Encodes a single delegation.\n *\n * @param delegation - The delegation to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Encodes a single delegation.\n *\n * @param delegation - The delegation to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const encodableStruct = [\n delegation.delegate,\n delegation.delegator,\n delegation.authority,\n delegation.caveats.map((caveat) => [\n caveat.enforcer,\n caveat.terms,\n caveat.args,\n ]),\n delegation.salt,\n delegation.signature,\n ];\n\n const result = encodeSingle(DELEGATION_ABI_TYPE, encodableStruct);\n\n return prepareResult(result, options);\n}\n\n/**\n * Converts a decoded delegation struct to a delegation object using the provided conversion function.\n *\n * @param decodedDelegation - The decoded delegation struct as a tuple.\n * @param convertFn - Function to convert BytesLike values to the desired output type.\n * @returns A delegation object with all bytes-like values converted using the provided function.\n */\nconst delegationFromDecodedDelegation = <TEncoding extends BytesLike>(\n decodedDelegation: DecodedDelegation,\n convertFn: (value: BytesLike) => TEncoding,\n): DelegationStruct<TEncoding> => {\n const [delegate, delegator, authority, caveats, salt, signature] =\n decodedDelegation;\n\n return {\n delegate: convertFn(delegate),\n delegator: convertFn(delegator),\n authority: convertFn(authority),\n caveats: caveats.map(([enforcer, terms, args]) => ({\n enforcer: convertFn(enforcer),\n terms: convertFn(terms),\n args: convertFn(args),\n })),\n salt,\n signature: convertFn(signature),\n };\n};\n\n/**\n * Represents a decoded delegation as a tuple structure.\n * This type defines the structure of a delegation after it has been decoded from\n * an encoded format.\n */\ntype DecodedDelegation = [\n BytesLike,\n BytesLike,\n BytesLike,\n [BytesLike, BytesLike, BytesLike][],\n bigint,\n BytesLike,\n];\n\n/**\n * Decodes an encoded permission context back into an array of delegations.\n *\n * @param encoded - The encoded delegations as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegations array with types resolved based on options.\n */\nexport function decodeDelegations(\n encoded: BytesLike,\n options?: EncodingOptions<'hex'>,\n): DelegationStruct<Hex>[];\nexport function decodeDelegations(\n encoded: BytesLike,\n options: EncodingOptions<'bytes'>,\n): DelegationStruct<Uint8Array>[];\n/**\n * Decodes an encoded permission context back into an array of delegations.\n *\n * @param encoded - The encoded delegations as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegations array with types resolved based on options.\n */\nexport function decodeDelegations(\n encoded: BytesLike,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): DelegationStruct<Hex>[] | DelegationStruct<Uint8Array>[] {\n // it's possible to short circuit for empty delegations, but due to the\n // complexity of the input type, and the relative infrequency of empty delegations,\n // it's not worthwhile.\n\n const decodedStructs = decodeSingle(\n DELEGATION_ARRAY_ABI_TYPES,\n encoded,\n // return types cannot be inferred from complex ABI types, so we must assert the type\n ) as DecodedDelegation[];\n\n if (options.out === 'bytes') {\n return decodedStructs.map((struct) =>\n delegationFromDecodedDelegation(struct, bytesLikeToBytes),\n );\n }\n return decodedStructs.map((struct) =>\n delegationFromDecodedDelegation(struct, bytesLikeToHex),\n );\n}\n\n/**\n * Decodes an encoded single delegation.\n *\n * @param encoded - The encoded delegation as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegation with types resolved based on options.\n */\nexport function decodeDelegation(\n encoded: BytesLike,\n options?: EncodingOptions<'hex'>,\n): DelegationStruct<Hex>;\nexport function decodeDelegation(\n encoded: BytesLike,\n options: EncodingOptions<'bytes'>,\n): DelegationStruct<Uint8Array>;\n/**\n * Decodes an encoded single delegation.\n *\n * @param encoded - The encoded delegation as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegation with types resolved based on options.\n */\nexport function decodeDelegation(\n encoded: BytesLike,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): DelegationStruct<Hex> | DelegationStruct<Uint8Array> {\n const decodedStruct = decodeSingle(\n DELEGATION_ABI_TYPE,\n encoded,\n // return types cannot be inferred from complex ABI types, so we must assert the type\n ) as DecodedDelegation;\n\n if (options.out === 'bytes') {\n return delegationFromDecodedDelegation(decodedStruct, bytesLikeToBytes);\n }\n return delegationFromDecodedDelegation(decodedStruct, bytesLikeToHex);\n}\n\n/**\n * Calculates the hash of a delegation for signing purposes.\n * The hash is computed by encoding the delegation parameters with the delegation typehash\n * and then applying keccak256 hashing.\n *\n * @param delegation - The delegation to hash.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The keccak256 hash of the encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function hashDelegation(\n delegation: DelegationStruct,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function hashDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Calculates the hash of a delegation for signing purposes.\n * The hash is computed by encoding the delegation parameters with the delegation typehash\n * and then applying keccak256 hashing.\n *\n * @param delegation - The delegation to hash.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The keccak256 hash of the encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function hashDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const encoded = encode(\n ['bytes32', 'address', 'address', 'bytes32', 'bytes32', 'uint256'],\n [\n DELEGATION_TYPEHASH,\n delegation.delegate,\n delegation.delegator,\n delegation.authority,\n getCaveatsArrayHash(delegation.caveats),\n delegation.salt,\n ],\n );\n const hash = keccak256(encoded);\n return prepareResult(hash, options);\n}\n\n/**\n * Calculates the hash of an array of caveats. The caveats are individually abi\n * encoded and hashed, and concatenated. The resulting byte array is then\n * hashed to produce the CaveatsArrayHash.\n *\n * @param caveats - The array of caveats to hash.\n * @returns The keccak256 hash of the encoded caveat array.\n */\nfunction getCaveatsArrayHash(caveats: CaveatStruct[]): Uint8Array {\n const byteLength = 32 * caveats.length;\n const encoded = new Uint8Array(byteLength);\n\n for (let i = 0; i < caveats.length; i++) {\n const caveat = caveats[i];\n if (!caveat) {\n throw new Error(`Caveat was undefined at index ${i}`);\n }\n const caveatHash = getCaveatHash(caveat);\n encoded.set(caveatHash, i * 32);\n }\n\n return keccak256(encoded);\n}\n\n/**\n * Calculates the hash of a single caveat.\n *\n * @param caveat - The caveat to hash.\n * @returns The keccak256 hash of the encoded caveat.\n */\nfunction getCaveatHash(caveat: CaveatStruct): Uint8Array {\n const termsBytes =\n typeof caveat.terms === 'string' ? hexToBytes(caveat.terms) : caveat.terms;\n\n const termsHash = keccak256(termsBytes);\n\n const encoded = encode(\n ['bytes32', 'address', 'bytes32'],\n [CAVEAT_TYPEHASH, caveat.enforcer, termsHash],\n );\n const hash = keccak256(encoded);\n return hash;\n}\n"]}