{"version":3,"sources":["../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"],"sourcesContent":["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"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AAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,iCAAiC,CAAC,EAAE;AAAA,IACtD;AACA,UAAM,aAAa,cAAc,MAAM;AACvC,YAAQ,IAAI,YAAY,IAAI,EAAE;AAAA,EAChC;AAEA,SAAO,UAAU,OAAO;AAC1B;AAQA,SAAS,cAAc,QAAkC;AACvD,QAAM,aACJ,OAAO,OAAO,UAAU,WAAWC,YAAW,OAAO,KAAK,IAAI,OAAO;AAEvE,QAAM,YAAY,UAAU,UAAU;AAEtC,QAAM,UAAU;AAAA,IACd,CAAC,WAAW,WAAW,SAAS;AAAA,IAChC,CAAC,iBAAiB,OAAO,UAAU,SAAS;AAAA,EAC9C;AACA,QAAM,OAAO,UAAU,OAAO;AAC9B,SAAO;AACT;","names":["bytesToHex","hexToBytes","bytesToHex","bytesToHex","bytesToHex","bytesToHex","decodeSingle","encodeSingle","bytesToHex","EXECUTION_ARRAY_ABI","bytesToHex","encodeSingle","decodeSingle","TIMESTAMP_UPPER_BOUND_SECONDS","bytesToHex","isHexString","TIMESTAMP_UPPER_BOUND_SECONDS","isHexString","bytesToHex","isHexString","bytesToHex","isHexString","bytesToHex","isHexString","isHexString","bytesToHex","remove0x","remove0x","bytesToHex","bytesToHex","isHexString","isHexString","bytesToHex","remove0x","remove0x","bytesToHex","bytesToHex","encodeSingle","decodeSingle","hexToBytes","encodeSingle","decodeSingle","hexToBytes"]}