@metamask/delegation-core 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -10
- package/README.md +1 -1
- package/dist/index.cjs +648 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +188 -5
- package/dist/index.d.ts +188 -5
- package/dist/index.mjs +662 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -12
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/delegation-toolkit/delegation-toolkit/packages/delegation-core/dist/index.cjs","../src/returns.ts","../src/utils.ts","../src/caveats/valueLte.ts","../src/caveats/timestamp.ts","../src/caveats/nativeTokenPeriodTransfer.ts","../src/caveats/exactCalldata.ts","../src/caveats/nativeTokenStreaming.ts","../src/caveats/erc20Streaming.ts","../src/caveats/erc20TokenPeriodTransfer.ts","../src/caveats/nonce.ts","../src/delegation.ts"],"names":["bytesToHex","hexToBytes"],"mappings":"AAAA;ACAA,wCAAuD;AAyBhD,IAAM,eAAA,EAAiB,EAAE,GAAA,EAAK,MAAM,CAAA;AAQpC,SAAS,aAAA,CACd,MAAA,EACA,OAAA,EAC0B;AAC1B,EAAA,GAAA,CAAI,OAAA,CAAQ,IAAA,IAAQ,KAAA,EAAO;AACzB,IAAA,MAAM,SAAA,EAAW,OAAO,OAAA,IAAW,SAAA,EAAW,OAAA,EAAS,+BAAA,MAAiB,CAAA;AAExE,IAAA,OAAO,QAAA,CAAS,UAAA,CAAW,IAAI,EAAA,EAC1B,SAAA,EACA,CAAA,EAAA,EAAK,QAAQ,CAAA,CAAA;AACpB,EAAA;AAC2D,EAAA;AACpD,EAAA;AACT;AAOwD;AACnB,EAAA;AAC1B,IAAA;AACT,EAAA;AAC2B,EAAA;AAC7B;AAO0D;AACrB,EAAA;AACN,IAAA;AAC7B,EAAA;AACO,EAAA;AACT;AD/CgE;AACA;AE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AAA;AACY,EAAA;AACtB,EAAA;AAEa,EAAA;AAChD;AVuKgE;AACA;AW7Pb;AACR;AACH;AAeT;AAM7B;AAQA;AAQA;AAMA;AAwBwC;AAEpC,EAAA;AAE0B,EAAA;AAGF,IAAA;AACb,IAAA;AACR,EAAA;AACgD,IAAA;AAC5C,MAAA;AACA,MAAA;AACA,MAAA;AACwB,MAAA;AACtB,QAAA;AACA,QAAA;AACA,QAAA;AACR,MAAA;AACM,MAAA;AACA,MAAA;AACR,IAAA;AAEiD,IAAA;AACpD,EAAA;AAEoC,EAAA;AACtC;AAUE;AAEsD,EAAA;AAG/C,EAAA;AACuB,IAAA;AACE,IAAA;AACA,IAAA;AACqB,IAAA;AACrB,MAAA;AACN,MAAA;AACF,MAAA;AACpB,IAAA;AACF,IAAA;AAC8B,IAAA;AAChC,EAAA;AACF;AAuC4D;AAKnC,EAAA;AACrB,IAAA;AACA,IAAA;AAAA;AAEF,EAAA;AAE6B,EAAA;AACL,IAAA;AACoB,MAAA;AAC1C,IAAA;AACF,EAAA;AACsB,EAAA;AACoB,IAAA;AAC1C,EAAA;AACF;AA+BoB;AACF,EAAA;AAC0C,IAAA;AACxD,IAAA;AACE,MAAA;AACW,MAAA;AACA,MAAA;AACA,MAAA;AAC2B,MAAA;AAC3B,MAAA;AACb,IAAA;AACF,EAAA;AAC8B,EAAA;AACI,EAAA;AACpC;AAUkE;AAChC,EAAA;AACS,EAAA;AAEA,EAAA;AACf,IAAA;AACX,IAAA;AACyC,MAAA;AACtD,IAAA;AACuC,IAAA;AACT,IAAA;AAChC,EAAA;AAEwB,EAAA;AAC1B;AAOyD;AAElBC,EAAAA;AAEC,EAAA;AAEtB,EAAA;AACkB,IAAA;AACY,IAAA;AAC9C,EAAA;AAC8B,EAAA;AACvB,EAAA;AACT;AXmFgE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/delegation-toolkit/delegation-toolkit/packages/delegation-core/dist/index.cjs","sourcesContent":[null,"import { type BytesLike, bytesToHex, hexToBytes } from '@metamask/utils';\n\nimport type { Hex } from './types';\n\n/**\n * The possible return value types for encoding/decoding operations.\n */\nexport type ResultValue = 'hex' | 'bytes';\n\n/**\n * Utility type for function return types based on ResultValue.\n */\nexport type ResultType<TResultValue extends ResultValue> =\n TResultValue extends 'hex' ? Hex : Uint8Array;\n\n/**\n * Base options interface for operations that can return hex or bytes.\n */\nexport type EncodingOptions<TResultValue extends ResultValue> = {\n out: TResultValue;\n};\n\n/**\n * Default options value with proper typing. Use this as your default parameter.\n */\nexport const defaultOptions = { out: 'hex' } as EncodingOptions<any>;\n\n/**\n * Prepares a result by converting between hex and bytes based on options.\n * @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 * @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) => {\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 * @param bytesLike - The bytes-like value to convert.\n * @returns The Uint8Array representation of the bytes-like value.\n */\nexport const bytesLikeToBytes = (bytesLike: BytesLike) => {\n if (typeof bytesLike === 'string') {\n return hexToBytes(bytesLike);\n }\n return bytesLike;\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","import {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { toHexString } from '../utils';\n\n/**\n * Terms for configuring a ValueLte caveat.\n */\nexport type ValueLteTerms = {\n /** The maximum value allowed for the transaction as a bigint. */\n maxValue: bigint;\n};\n\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxValue } = terms;\n\n if (maxValue < 0n) {\n throw new Error('Invalid maxValue: must be greater than or equal to zero');\n }\n const hexValue = toHexString({ value: maxValue, size: 32 });\n\n return prepareResult(hexValue, options);\n}\n","import {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { toHexString } from '../utils';\n\n// Upper bound for timestamps (equivalent to January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a timestamp threshold for delegation usage.\n */\nexport type TimestampTerms = {\n /** The timestamp (in seconds) after which the delegation can be used. */\n timestampAfterThreshold: number;\n /** The timestamp (in seconds) before which the delegation can be used. */\n timestampBeforeThreshold: number;\n};\n\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each timestamp).\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each timestamp).\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { timestampAfterThreshold, timestampBeforeThreshold } = terms;\n\n if (timestampAfterThreshold < 0) {\n throw new Error(\n 'Invalid timestampAfterThreshold: must be zero or positive',\n );\n }\n\n if (timestampBeforeThreshold < 0) {\n throw new Error(\n 'Invalid timestampBeforeThreshold: must be zero or positive',\n );\n }\n\n if (timestampBeforeThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid timestampBeforeThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (timestampAfterThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid timestampAfterThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (\n timestampBeforeThreshold !== 0 &&\n timestampAfterThreshold >= timestampBeforeThreshold\n ) {\n throw new Error(\n 'Invalid thresholds: timestampBeforeThreshold must be greater than timestampAfterThreshold when both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({\n value: timestampAfterThreshold,\n size: 16,\n });\n const beforeThresholdHex = toHexString({\n value: timestampBeforeThreshold,\n size: 16,\n });\n\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { toHexString } from '../utils';\n\n/**\n * Terms for configuring a periodic transfer allowance of native tokens.\n */\nexport type NativeTokenPeriodTransferTerms = {\n /** The maximum amount that can be transferred within each period (in wei). */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused ETH is forfeited once the period ends.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 96-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 96-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { periodAmount, periodDuration, startDate } = terms;\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `0x${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldata caveat.\n */\nexport type ExactCalldataTerms = {\n /** The expected calldata to match against. */\n calldata: BytesLike;\n};\n\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { calldata } = terms;\n\n if (typeof calldata === 'string' && !calldata.startsWith('0x')) {\n throw new Error('Invalid calldata: must be a hex string starting with 0x');\n }\n\n // For exact calldata, the terms are simply the expected calldata\n return prepareResult(calldata, encodingOptions);\n}\n","import {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { toHexString } from '../utils';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of native tokens.\n */\nexport type NativeTokenStreamingTerms = {\n /** The initial amount available immediately (in wei). */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred (in wei). */\n maxAmount: bigint;\n /** The rate at which allowance increases per second (in wei). */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (128 bytes).\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { initialAmount, maxAmount, amountPerSecond, startTime } = terms;\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `0x${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { type BytesLike, bytesToHex, isHexString } from '@metamask/utils';\n\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { toHexString } from '../utils';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of ERC20 tokens.\n */\nexport type ERC20StreamingTerms = {\n /** The address of the ERC20 token contract. */\n tokenAddress: BytesLike;\n /** The initial amount available immediately. */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred. */\n maxAmount: bigint;\n /** The rate at which allowance increases per second. */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (160 bytes).\n * @throws Error if tokenAddress is invalid.\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 160-byte hex string.\n * @throws Error if any of the parameters are invalid.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, initialAmount, maxAmount, amountPerSecond, startTime } =\n terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { type BytesLike, isHexString, bytesToHex } from '@metamask/utils';\n\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { toHexString } from '../utils';\n\n/**\n * Terms for configuring a periodic transfer allowance of ERC20 tokens.\n */\nexport type ERC20TokenPeriodTransferTerms = {\n /** The address of the ERC20 token. */\n tokenAddress: BytesLike;\n /** The maximum amount that can be transferred within each period. */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused tokens are forfeited once the period ends.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, periodAmount, periodDuration, startDate } = terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { isHexString } from '@metamask/utils';\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// char length of 32 byte hex string (including 0x prefix)\nconst MAX_NONCE_STRING_LENGTH = 66;\n\n/**\n * Terms for configuring a Nonce caveat.\n */\nexport type NonceTerms = {\n /** The nonce as BytesLike (0x-prefixed hex string or Uint8Array) to allow bulk revocation of delegations. */\n nonce: BytesLike;\n};\n\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the nonce is invalid.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte padded value in the specified encoding format.\n * @throws Error if the nonce is invalid or empty.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { nonce } = terms;\n\n // Handle zero-length Uint8Array specifically\n if (nonce instanceof Uint8Array && nonce.length === 0) {\n throw new Error('Invalid nonce: Uint8Array must not be empty');\n }\n\n // Validate that strings have 0x prefix (as required by BytesLike)\n if (typeof nonce === 'string' && !nonce.startsWith('0x')) {\n throw new Error('Invalid nonce: string must have 0x prefix');\n }\n\n // Convert to hex string for consistent processing\n const hexNonce = bytesLikeToHex(nonce);\n\n // Check for empty hex string (0x) first - more specific error\n if (hexNonce === '0x') {\n throw new Error('Invalid nonce: must not be empty');\n }\n\n if (!isHexString(hexNonce)) {\n throw new Error('Invalid nonce: must be a valid BytesLike value');\n }\n\n if (hexNonce.length > MAX_NONCE_STRING_LENGTH) {\n throw new Error('Invalid nonce: must be 32 bytes or less in length');\n }\n\n // Remove '0x' prefix for padding, then add it back\n const nonceWithoutPrefix = hexNonce.slice(2);\n const paddedNonce = nonceWithoutPrefix.padStart(64, '0'); // 64 hex chars = 32 bytes\n const hexValue = `0x${paddedNonce}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { 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 = '0x0000000000000000000000000000000000000a11';\n\n/**\n * To be used on a delegation as the root authority.\n */\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';\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';\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';\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 * Encodes an array of delegations into a permission context.\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 * @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 * Converts a decoded delegation struct to a delegation object using the provided conversion function.\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 * @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 * @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 * 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 * @param caveat - The caveat to hash.\n * @returns The keccak256 hash of the encoded caveat.\n */\nfunction getCaveatHash(caveat: CaveatStruct): Uint8Array {\n const termsBytes =\n typeof caveat.terms === 'string' ? hexToBytes(caveat.terms) : caveat.terms;\n\n const termsHash = keccak256(termsBytes);\n\n const encoded = encode(\n ['bytes32', 'address', 'bytes32'],\n [CAVEAT_TYPEHASH, caveat.enforcer, termsHash],\n );\n const hash = keccak256(encoded);\n return hash;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/delegation-core/dist/index.cjs","../src/internalUtils.ts","../src/returns.ts","../src/caveats/valueLte.ts","../src/caveats/timestamp.ts","../src/caveats/nativeTokenPeriodTransfer.ts","../src/caveats/exactCalldata.ts","../src/caveats/exactCalldataBatch.ts","../src/caveats/exactExecution.ts","../src/caveats/exactExecutionBatch.ts","../src/caveats/nativeTokenStreaming.ts","../src/caveats/nativeTokenTransferAmount.ts","../src/caveats/nativeTokenPayment.ts","../src/caveats/nativeBalanceChange.ts","../src/caveats/erc20Streaming.ts","../src/caveats/erc20TokenPeriodTransfer.ts","../src/caveats/erc20TransferAmount.ts","../src/caveats/erc20BalanceChange.ts","../src/caveats/erc721BalanceChange.ts","../src/caveats/erc721Transfer.ts","../src/caveats/erc1155BalanceChange.ts","../src/caveats/nonce.ts","../src/caveats/allowedCalldata.ts","../src/caveats/allowedMethods.ts","../src/caveats/allowedTargets.ts","../src/caveats/argsEqualityCheck.ts","../src/caveats/blockNumber.ts","../src/caveats/deployed.ts","../src/caveats/id.ts","../src/caveats/limitedCalls.ts","../src/caveats/multiTokenPeriod.ts","../src/caveats/ownershipTransfer.ts","../src/caveats/redeemer.ts","../src/caveats/specificActionERC20TransferBatch.ts","../src/delegation.ts"],"names":["encodeSingle","EXECUTION_ARRAY_ABI","TIMESTAMP_UPPER_BOUND_SECONDS","isHexString","bytesToHex"],"mappings":"AAAA;ACAA;AACE;AACA;AACA;AACA;AAAA,wCAEK;AAeA,IAAM,YAAA,EAAc,CAAC;AAAA,EAC1B,KAAA;AAAA,EACA;AACF,CAAA,EAAA,GAGc;AACZ,EAAA,OAAO,KAAA,CAAM,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,KAAA,EAAO,C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AA;AACzC,EAAA;AACuC,EAAA;AACzC;AA8BE;AAEgB,EAAA;AACoB,IAAA;AAClC,IAAA;AACE,MAAA;AACW,MAAA;AACA,MAAA;AACA,MAAA;AACoB,MAAA;AACpB,MAAA;AACb,IAAA;AACF,EAAA;AAC8B,EAAA;AACI,EAAA;AACpC;AAUkE;AAChC,EAAA;AACS,EAAA;AAEA,EAAA;AACf,IAAA;AACX,IAAA;AACK,MAAA;AAClB,IAAA;AACuC,IAAA;AACT,IAAA;AAChC,EAAA;AAEwB,EAAA;AAC1B;AAQyD;AAEvC,EAAA;AAEsB,EAAA;AAEtB,EAAA;AACkB,IAAA;AACG,IAAA;AACrC,EAAA;AAC8B,EAAA;AACvB,EAAA;AACT;AlCwlB2C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/delegation-core/dist/index.cjs","sourcesContent":[null,"import {\n bytesToHex,\n hexToBytes,\n isHexString,\n remove0x,\n type BytesLike,\n} from '@metamask/utils';\n\n/**\n * Converts a numeric value to a hexadecimal string with zero-padding, without 0x prefix.\n *\n * @param options - The options for the conversion.\n * @param options.value - The numeric value to convert to hex (bigint or number).\n * @param options.size - The size in bytes for the resulting hex string (each byte = 2 hex characters).\n * @returns A hexadecimal string prefixed with zeros to match the specified size.\n * @example\n * ```typescript\n * toHexString({ value: 255, size: 2 }) // Returns \"00ff\"\n * toHexString({ value: 16n, size: 1 }) // Returns \"10\"\n * ```\n */\nexport const toHexString = ({\n value,\n size,\n}: {\n value: bigint | number;\n size: number;\n}): string => {\n return value.toString(16).padStart(size * 2, '0');\n};\n\n/**\n * Normalizes a bytes-like value into a hex string.\n *\n * @param value - The value to normalize.\n * @param errorMessage - Error message used for invalid input.\n * @returns The normalized hex string (0x-prefixed).\n * @throws Error if the input is an invalid hex string.\n */\nexport const normalizeHex = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value)) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Normalizes an address into a hex string without changing casing.\n *\n * @param value - The address as a hex string or bytes.\n * @param errorMessage - Error message used for invalid input.\n * @returns The address as a 0x-prefixed hex string.\n * @throws Error if the input is not a 20-byte address.\n */\nexport const normalizeAddress = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value) || value.length !== 42) {\n throw new Error(errorMessage);\n }\n return value;\n }\n\n if (value.length !== 20) {\n throw new Error(errorMessage);\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Normalizes an address into a lowercased hex string.\n *\n * @param value - The address as a hex string or bytes.\n * @param errorMessage - Error message used for invalid input.\n * @returns The address as a lowercased 0x-prefixed hex string.\n * @throws Error if the input is not a 20-byte address.\n */\nexport const normalizeAddressLowercase = (\n value: BytesLike,\n errorMessage: string,\n): string => {\n if (typeof value === 'string') {\n if (!isHexString(value) || value.length !== 42) {\n throw new Error(errorMessage);\n }\n return bytesToHex(hexToBytes(value));\n }\n\n if (value.length !== 20) {\n throw new Error(errorMessage);\n }\n\n return bytesToHex(value);\n};\n\n/**\n * Concatenates 0x-prefixed hex strings into a single 0x-prefixed hex string.\n *\n * @param parts - The hex string parts to concatenate.\n * @returns The concatenated hex string.\n */\nexport const concatHex = (parts: string[]): string => {\n return `0x${parts.map(remove0x).join('')}`;\n};\n","import { type BytesLike, bytesToHex, hexToBytes } from '@metamask/utils';\n\nimport type { Hex } from './types';\n\n/**\n * The possible return value types for encoding/decoding operations.\n */\nexport type ResultValue = 'hex' | 'bytes';\n\n/**\n * Utility type for function return types based on ResultValue.\n */\nexport type ResultType<TResultValue extends ResultValue> =\n TResultValue extends 'hex' ? Hex : Uint8Array;\n\n/**\n * Base options interface for operations that can return hex or bytes.\n */\nexport type EncodingOptions<TResultValue extends ResultValue> = {\n out: TResultValue;\n};\n\n/**\n * Default options value with proper typing. Use this as your default parameter.\n */\nexport const defaultOptions = { out: 'hex' } as EncodingOptions<any>;\n\n/**\n * Prepares a result by converting between hex and bytes based on options.\n *\n * @param result - The value to convert (either Uint8Array or Hex optionally prefixed with 0x).\n * @param options - The options specifying the desired output format.\n * @returns The converted value with proper type narrowing.\n */\nexport function prepareResult<TResultValue extends ResultValue>(\n result: Uint8Array | Hex | string,\n options: EncodingOptions<TResultValue>,\n): ResultType<TResultValue> {\n if (options.out === 'hex') {\n const hexValue = typeof result === 'string' ? result : bytesToHex(result);\n\n return hexValue.startsWith('0x')\n ? (hexValue as ResultType<TResultValue>)\n : (`0x${hexValue}` as ResultType<TResultValue>);\n }\n const bytesValue = result instanceof Uint8Array ? result : hexToBytes(result);\n return bytesValue as ResultType<TResultValue>;\n}\n\n/**\n * Converts a bytes-like value to a hex string.\n *\n * @param bytesLike - The bytes-like value to convert.\n * @returns The hex string representation of the bytes-like value.\n */\nexport const bytesLikeToHex = (bytesLike: BytesLike): Hex => {\n if (typeof bytesLike === 'string') {\n return bytesLike;\n }\n return bytesToHex(bytesLike);\n};\n\n/**\n * Converts a bytes-like value to a Uint8Array.\n *\n * @param bytesLike - The bytes-like value to convert.\n * @returns The Uint8Array representation of the bytes-like value.\n */\nexport const bytesLikeToBytes = (bytesLike: BytesLike): Uint8Array => {\n if (typeof bytesLike === 'string') {\n return hexToBytes(bytesLike);\n }\n return bytesLike;\n};\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a ValueLte caveat.\n */\nexport type ValueLteTerms = {\n /** The maximum value allowed for the transaction as a bigint. */\n maxValue: bigint;\n};\n\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a ValueLte caveat that limits the maximum value of native tokens that can be spent.\n *\n * @param terms - The terms for the ValueLte caveat.\n * @param options - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the maxValue is negative.\n */\nexport function createValueLteTerms(\n terms: ValueLteTerms,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxValue } = terms;\n\n if (maxValue < 0n) {\n throw new Error('Invalid maxValue: must be greater than or equal to zero');\n }\n const hexValue = toHexString({ value: maxValue, size: 32 });\n\n return prepareResult(hexValue, options);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (equivalent to January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a timestamp threshold for delegation usage.\n */\nexport type TimestampTerms = {\n /** The timestamp (in seconds) after which the delegation can be used. */\n timestampAfterThreshold: number;\n /** The timestamp (in seconds) before which the delegation can be used. */\n timestampBeforeThreshold: number;\n};\n\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each timestamp).\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Timestamp caveat that enforces time-based constraints on delegation usage.\n *\n * @param terms - The terms for the Timestamp caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each timestamp).\n * @throws Error if the timestamps are invalid.\n */\nexport function createTimestampTerms(\n terms: TimestampTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { timestampAfterThreshold, timestampBeforeThreshold } = terms;\n\n if (timestampAfterThreshold < 0) {\n throw new Error(\n 'Invalid timestampAfterThreshold: must be zero or positive',\n );\n }\n\n if (timestampBeforeThreshold < 0) {\n throw new Error(\n 'Invalid timestampBeforeThreshold: must be zero or positive',\n );\n }\n\n if (timestampBeforeThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid timestampBeforeThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (timestampAfterThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n `Invalid timestampAfterThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`,\n );\n }\n\n if (\n timestampBeforeThreshold !== 0 &&\n timestampAfterThreshold >= timestampBeforeThreshold\n ) {\n throw new Error(\n 'Invalid thresholds: timestampBeforeThreshold must be greater than timestampAfterThreshold when both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({\n value: timestampAfterThreshold,\n size: 16,\n });\n const beforeThresholdHex = toHexString({\n value: timestampBeforeThreshold,\n size: 16,\n });\n\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a periodic transfer allowance of native tokens.\n */\nexport type NativeTokenPeriodTransferTerms = {\n /** The maximum amount that can be transferred within each period (in wei). */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused ETH is forfeited once the period ends.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 96-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPeriodTransfer caveat that validates that native token (ETH) transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the NativeTokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 96-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenPeriodTransferTerms(\n terms: NativeTokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { periodAmount, periodDuration, startDate } = terms;\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `0x${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldata caveat.\n */\nexport type ExactCalldataTerms = {\n /** The expected calldata to match against. */\n calldata: BytesLike;\n};\n\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldata caveat that ensures the provided execution calldata\n * matches exactly the expected calldata.\n *\n * @param terms - The terms for the ExactCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createExactCalldataTerms(\n terms: ExactCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { calldata } = terms;\n\n if (calldata === undefined || calldata === null) {\n throw new Error('Invalid calldata: calldata is required');\n }\n\n if (typeof calldata === 'string' && !calldata.startsWith('0x')) {\n throw new Error('Invalid calldata: must be a hex string starting with 0x');\n }\n\n // For exact calldata, the terms are simply the expected calldata\n return prepareResult(calldata, encodingOptions);\n}\n","import { encodeSingle } from '@metamask/abi-utils';\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactCalldataBatch caveat.\n */\nexport type ExactCalldataBatchTerms = {\n /** The executions that must be matched exactly in the batch. */\n executions: {\n target: BytesLike;\n value: bigint;\n callData: BytesLike;\n }[];\n};\n\nconst EXECUTION_ARRAY_ABI = '(address,uint256,bytes)[]';\n\n/**\n * Creates terms for an ExactCalldataBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactCalldataBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactCalldataBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactCalldataBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactCalldataBatchTerms(\n terms: ExactCalldataBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { executions } = terms;\n\n if (executions.length === 0) {\n throw new Error('Invalid executions: array cannot be empty');\n }\n\n const encodableExecutions = executions.map((execution) => {\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n return [targetHex, execution.value, callDataHex];\n });\n\n const hexValue = encodeSingle(EXECUTION_ARRAY_ABI, encodableExecutions);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactExecution caveat.\n */\nexport type ExactExecutionTerms = {\n /** The execution that must be matched exactly. */\n execution: {\n target: BytesLike;\n value: bigint;\n callData: BytesLike;\n };\n};\n\n/**\n * Creates terms for an ExactExecution caveat that matches a single execution.\n *\n * @param terms - The terms for the ExactExecution caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target + value + calldata.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactExecution caveat that matches a single execution.\n *\n * @param terms - The terms for the ExactExecution caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target + value + calldata.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionTerms(\n terms: ExactExecutionTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { execution } = terms;\n\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n const valueHex = `0x${toHexString({ value: execution.value, size: 32 })}`;\n const hexValue = concatHex([targetHex, valueHex, callDataHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { encodeSingle } from '@metamask/abi-utils';\nimport { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ExactExecutionBatch caveat.\n */\nexport type ExactExecutionBatchTerms = {\n /** The executions that must be matched exactly in the batch. */\n executions: {\n target: BytesLike;\n value: bigint;\n callData: BytesLike;\n }[];\n};\n\nconst EXECUTION_ARRAY_ABI = '(address,uint256,bytes)[]';\n\n/**\n * Creates terms for an ExactExecutionBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactExecutionBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ExactExecutionBatch caveat that matches a batch of executions.\n *\n * @param terms - The terms for the ExactExecutionBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as ABI-encoded execution array.\n * @throws Error if any execution parameters are invalid.\n */\nexport function createExactExecutionBatchTerms(\n terms: ExactExecutionBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { executions } = terms;\n\n if (executions.length === 0) {\n throw new Error('Invalid executions: array cannot be empty');\n }\n\n const encodableExecutions = executions.map((execution) => {\n const targetHex = normalizeAddress(\n execution.target,\n 'Invalid target: must be a valid address',\n );\n\n if (execution.value < 0n) {\n throw new Error('Invalid value: must be a non-negative number');\n }\n\n let callDataHex: string;\n if (typeof execution.callData === 'string') {\n if (!execution.callData.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n callDataHex = execution.callData;\n } else {\n callDataHex = bytesToHex(execution.callData);\n }\n\n return [targetHex, execution.value, callDataHex];\n });\n\n const hexValue = encodeSingle(EXECUTION_ARRAY_ABI, encodableExecutions);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of native tokens.\n */\nexport type NativeTokenStreamingTerms = {\n /** The initial amount available immediately (in wei). */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred (in wei). */\n maxAmount: bigint;\n /** The rate at which allowance increases per second (in wei). */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (128 bytes).\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the NativeTokenStreaming caveat, configuring a linear\n * streaming allowance of native tokens.\n *\n * @param terms - The terms for the NativeTokenStreaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string.\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createNativeTokenStreamingTerms(\n terms: NativeTokenStreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { initialAmount, maxAmount, amountPerSecond, startTime } = terms;\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `0x${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a NativeTokenTransferAmount caveat.\n */\nexport type NativeTokenTransferAmountTerms = {\n /** The maximum amount of native tokens that can be transferred. */\n maxAmount: bigint;\n};\n\n/**\n * Creates terms for a NativeTokenTransferAmount caveat that caps native transfers.\n *\n * @param terms - The terms for the NativeTokenTransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if maxAmount is negative.\n */\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenTransferAmount caveat that caps native transfers.\n *\n * @param terms - The terms for the NativeTokenTransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if maxAmount is negative.\n */\nexport function createNativeTokenTransferAmountTerms(\n terms: NativeTokenTransferAmountTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { maxAmount } = terms;\n\n if (maxAmount < 0n) {\n throw new Error('Invalid maxAmount: must be zero or positive');\n }\n\n const hexValue = `0x${toHexString({ value: maxAmount, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a NativeTokenPayment caveat.\n */\nexport type NativeTokenPaymentTerms = {\n /** The recipient address. */\n recipient: BytesLike;\n /** The amount that must be paid. */\n amount: bigint;\n};\n\n/**\n * Creates terms for a NativeTokenPayment caveat that requires a payment to a recipient.\n *\n * @param terms - The terms for the NativeTokenPayment caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as recipient + amount.\n * @throws Error if the recipient address is invalid or amount is not positive.\n */\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeTokenPayment caveat that requires a payment to a recipient.\n *\n * @param terms - The terms for the NativeTokenPayment caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as recipient + amount.\n * @throws Error if the recipient address is invalid or amount is not positive.\n */\nexport function createNativeTokenPaymentTerms(\n terms: NativeTokenPaymentTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { recipient, amount } = terms;\n\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (amount <= 0n) {\n throw new Error('Invalid amount: must be positive');\n }\n\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n const hexValue = concatHex([recipientHex, amountHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring a NativeBalanceChange caveat.\n */\nexport type NativeBalanceChangeTerms = {\n /** The recipient address. */\n recipient: BytesLike;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for a NativeBalanceChange caveat that checks recipient balance changes.\n *\n * @param terms - The terms for the NativeBalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + recipient + balance.\n * @throws Error if the recipient address is invalid or balance/changeType are invalid.\n */\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a NativeBalanceChange caveat that checks recipient balance changes.\n *\n * @param terms - The terms for the NativeBalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + recipient + balance.\n * @throws Error if the recipient address is invalid or balance/changeType are invalid.\n */\nexport function createNativeBalanceChangeTerms(\n terms: NativeBalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { recipient, balance, changeType: changeTypeNumber } = terms;\n\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid Address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([changeTypeHex, recipientHex, balanceHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { type BytesLike, bytesToHex, isHexString } from '@metamask/utils';\n\nimport { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// Upper bound for timestamps (January 1, 10000 CE)\nconst TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;\n\n/**\n * Terms for configuring a linear streaming allowance of ERC20 tokens.\n */\nexport type ERC20StreamingTerms = {\n /** The address of the ERC20 token contract. */\n tokenAddress: BytesLike;\n /** The initial amount available immediately. */\n initialAmount: bigint;\n /** The maximum total amount that can be transferred. */\n maxAmount: bigint;\n /** The rate at which allowance increases per second. */\n amountPerSecond: bigint;\n /** Unix timestamp when streaming begins. */\n startTime: number;\n};\n\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns Hex-encoded terms for the caveat (160 bytes).\n * @throws Error if tokenAddress is invalid.\n * @throws Error if initialAmount is negative.\n * @throws Error if maxAmount is not positive.\n * @throws Error if maxAmount is less than initialAmount.\n * @throws Error if amountPerSecond is not positive.\n * @throws Error if startTime is not positive.\n * @throws Error if startTime exceeds upper bound.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for the ERC20Streaming caveat, configuring a linear\n * streaming allowance of ERC20 tokens.\n *\n * @param terms - The terms for the ERC20Streaming caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 160-byte hex string.\n * @throws Error if any of the parameters are invalid.\n */\nexport function createERC20StreamingTerms(\n terms: ERC20StreamingTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, initialAmount, maxAmount, amountPerSecond, startTime } =\n terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (initialAmount < 0n) {\n throw new Error('Invalid initialAmount: must be greater than zero');\n }\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n if (maxAmount < initialAmount) {\n throw new Error('Invalid maxAmount: must be greater than initialAmount');\n }\n\n if (amountPerSecond <= 0n) {\n throw new Error('Invalid amountPerSecond: must be a positive number');\n }\n\n if (startTime <= 0) {\n throw new Error('Invalid startTime: must be a positive number');\n }\n\n if (startTime > TIMESTAMP_UPPER_BOUND_SECONDS) {\n throw new Error(\n 'Invalid startTime: must be less than or equal to 253402300799',\n );\n }\n\n const initialAmountHex = toHexString({ value: initialAmount, size: 32 });\n const maxAmountHex = toHexString({ value: maxAmount, size: 32 });\n const amountPerSecondHex = toHexString({ value: amountPerSecond, size: 32 });\n const startTimeHex = toHexString({ value: startTime, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { type BytesLike, isHexString, bytesToHex } from '@metamask/utils';\n\nimport { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a periodic transfer allowance of ERC20 tokens.\n */\nexport type ERC20TokenPeriodTransferTerms = {\n /** The address of the ERC20 token. */\n tokenAddress: BytesLike;\n /** The maximum amount that can be transferred within each period. */\n periodAmount: bigint;\n /** The duration of each period in seconds. */\n periodDuration: number;\n /** Unix timestamp when the first period begins. */\n startDate: number;\n};\n\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period. The transferable amount resets at the\n * beginning of each period, and any unused tokens are forfeited once the period ends.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TokenPeriodTransfer caveat that validates that ERC20 token transfers\n * do not exceed a specified amount within a given time period.\n *\n * @param terms - The terms for the ERC20TokenPeriodTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 128-byte hex string (32 bytes for each parameter).\n * @throws Error if any of the numeric parameters are invalid.\n */\nexport function createERC20TokenPeriodTransferTerms(\n terms: ERC20TokenPeriodTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, periodAmount, periodDuration, startDate } = terms;\n\n if (!tokenAddress) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n\n let prefixedTokenAddressHex: string;\n\n if (typeof tokenAddress === 'string') {\n if (!isHexString(tokenAddress) || tokenAddress.length !== 42) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = tokenAddress;\n } else {\n if (tokenAddress.length !== 20) {\n throw new Error('Invalid tokenAddress: must be a valid address');\n }\n prefixedTokenAddressHex = bytesToHex(tokenAddress);\n }\n\n if (periodAmount <= 0n) {\n throw new Error('Invalid periodAmount: must be a positive number');\n }\n\n if (periodDuration <= 0) {\n throw new Error('Invalid periodDuration: must be a positive number');\n }\n\n if (startDate <= 0) {\n throw new Error('Invalid startDate: must be a positive number');\n }\n\n const periodAmountHex = toHexString({ value: periodAmount, size: 32 });\n const periodDurationHex = toHexString({ value: periodDuration, size: 32 });\n const startDateHex = toHexString({ value: startDate, size: 32 });\n\n const hexValue = `${prefixedTokenAddressHex}${periodAmountHex}${periodDurationHex}${startDateHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ERC20TransferAmount caveat.\n */\nexport type ERC20TransferAmountTerms = {\n /** The ERC-20 token address. */\n tokenAddress: BytesLike;\n /** The maximum amount of tokens that can be transferred. */\n maxAmount: bigint;\n};\n\n/**\n * Creates terms for an ERC20TransferAmount caveat that caps transfer amount.\n *\n * @param terms - The terms for the ERC20TransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + maxAmount.\n * @throws Error if the token address is invalid or maxAmount is not positive.\n */\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20TransferAmount caveat that caps transfer amount.\n *\n * @param terms - The terms for the ERC20TransferAmount caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + maxAmount.\n * @throws Error if the token address is invalid or maxAmount is not positive.\n */\nexport function createERC20TransferAmountTerms(\n terms: ERC20TransferAmountTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, maxAmount } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n\n if (maxAmount <= 0n) {\n throw new Error('Invalid maxAmount: must be a positive number');\n }\n\n const maxAmountHex = `0x${toHexString({ value: maxAmount, size: 32 })}`;\n const hexValue = concatHex([tokenAddressHex, maxAmountHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC20BalanceChange caveat.\n */\nexport type ERC20BalanceChangeTerms = {\n /** The ERC-20 token address. */\n tokenAddress: BytesLike;\n /** The recipient address. */\n recipient: BytesLike;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC20BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC20BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC20BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC20BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC20BalanceChangeTerms(\n terms: ERC20BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n balance,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n balanceHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC721BalanceChange caveat.\n */\nexport type ERC721BalanceChangeTerms = {\n /** The ERC-721 token address. */\n tokenAddress: BytesLike;\n /** The recipient address. */\n recipient: BytesLike;\n /** The balance change amount. */\n amount: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC721BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC721BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + amount.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC721BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC721BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + amount.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC721BalanceChangeTerms(\n terms: ERC721BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n amount,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (amount <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n amountHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ERC721Transfer caveat.\n */\nexport type ERC721TransferTerms = {\n /** The ERC-721 token address. */\n tokenAddress: BytesLike;\n /** The token id. */\n tokenId: bigint;\n};\n\n/**\n * Creates terms for an ERC721Transfer caveat that restricts transfers to a token and id.\n *\n * @param terms - The terms for the ERC721Transfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + tokenId.\n * @throws Error if the token address is invalid or tokenId is negative.\n */\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC721Transfer caveat that restricts transfers to a token and id.\n *\n * @param terms - The terms for the ERC721Transfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as tokenAddress + tokenId.\n * @throws Error if the token address is invalid or tokenId is negative.\n */\nexport function createERC721TransferTerms(\n terms: ERC721TransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, tokenId } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n\n if (tokenId < 0n) {\n throw new Error('Invalid tokenId: must be a non-negative number');\n }\n\n const tokenIdHex = `0x${toHexString({ value: tokenId, size: 32 })}`;\n const hexValue = concatHex([tokenAddressHex, tokenIdHex]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport {\n concatHex,\n normalizeAddressLowercase,\n toHexString,\n} from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\nimport { BalanceChangeType } from './types';\n\n/**\n * Terms for configuring an ERC1155BalanceChange caveat.\n */\nexport type ERC1155BalanceChangeTerms = {\n /** The ERC-1155 token address. */\n tokenAddress: BytesLike;\n /** The recipient address. */\n recipient: BytesLike;\n /** The token id. */\n tokenId: bigint;\n /** The balance change amount. */\n balance: bigint;\n /** The balance change type. */\n changeType: number;\n};\n\n/**\n * Creates terms for an ERC1155BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC1155BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + tokenId + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ERC1155BalanceChange caveat that checks token balance changes.\n *\n * @param terms - The terms for the ERC1155BalanceChange caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as changeType + tokenAddress + recipient + tokenId + balance.\n * @throws Error if any parameter is invalid.\n */\nexport function createERC1155BalanceChangeTerms(\n terms: ERC1155BalanceChangeTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const {\n tokenAddress,\n recipient,\n tokenId,\n balance,\n changeType: changeTypeNumber,\n } = terms;\n\n const tokenAddressHex = normalizeAddressLowercase(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddressLowercase(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n\n if (balance <= 0n) {\n throw new Error('Invalid balance: must be a positive number');\n }\n\n if (tokenId < 0n) {\n throw new Error('Invalid tokenId: must be a non-negative number');\n }\n\n const changeType = changeTypeNumber as BalanceChangeType;\n\n if (\n changeType !== BalanceChangeType.Increase &&\n changeType !== BalanceChangeType.Decrease\n ) {\n throw new Error('Invalid changeType: must be either Increase or Decrease');\n }\n\n const changeTypeHex = `0x${toHexString({ value: changeType, size: 1 })}`;\n const tokenIdHex = `0x${toHexString({ value: tokenId, size: 32 })}`;\n const balanceHex = `0x${toHexString({ value: balance, size: 32 })}`;\n const hexValue = concatHex([\n changeTypeHex,\n tokenAddressHex,\n recipientHex,\n tokenIdHex,\n balanceHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { isHexString } from '@metamask/utils';\nimport type { BytesLike } from '@metamask/utils';\n\nimport {\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n// char length of 32 byte hex string (including 0x prefix)\nconst MAX_NONCE_STRING_LENGTH = 66;\n\n/**\n * Terms for configuring a Nonce caveat.\n */\nexport type NonceTerms = {\n /** The nonce as BytesLike (0x-prefixed hex string or Uint8Array) to allow bulk revocation of delegations. */\n nonce: BytesLike;\n};\n\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the nonce is invalid.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Nonce caveat that uses a nonce value for bulk revocation of delegations.\n *\n * @param terms - The terms for the Nonce caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte padded value in the specified encoding format.\n * @throws Error if the nonce is invalid or empty.\n */\nexport function createNonceTerms(\n terms: NonceTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { nonce } = terms;\n\n // Handle zero-length Uint8Array specifically\n if (nonce instanceof Uint8Array && nonce.length === 0) {\n throw new Error('Invalid nonce: Uint8Array must not be empty');\n }\n\n // Validate that strings have 0x prefix (as required by BytesLike)\n if (typeof nonce === 'string' && !nonce.startsWith('0x')) {\n throw new Error('Invalid nonce: string must have 0x prefix');\n }\n\n // Convert to hex string for consistent processing\n const hexNonce = bytesLikeToHex(nonce);\n\n // Check for empty hex string (0x) first - more specific error\n if (hexNonce === '0x') {\n throw new Error('Invalid nonce: must not be empty');\n }\n\n if (!isHexString(hexNonce)) {\n throw new Error('Invalid nonce: must be a valid BytesLike value');\n }\n\n if (hexNonce.length > MAX_NONCE_STRING_LENGTH) {\n throw new Error('Invalid nonce: must be 32 bytes or less in length');\n }\n\n // Remove '0x' prefix for padding, then add it back\n const nonceWithoutPrefix = hexNonce.slice(2);\n const paddedNonce = nonceWithoutPrefix.padStart(64, '0'); // 64 hex chars = 32 bytes\n const hexValue = `0x${paddedNonce}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { bytesToHex, remove0x, type BytesLike } from '@metamask/utils';\n\nimport { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedCalldata caveat.\n */\nexport type AllowedCalldataTerms = {\n startIndex: number;\n value: BytesLike;\n};\n\n/**\n * Creates terms for an AllowedCalldata caveat that ensures the provided execution calldata\n * matches the expected calldata at the specified index.\n *\n * @param terms - The terms for the AllowedCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedCalldata caveat that ensures the provided execution calldata\n * matches the expected calldata at the specified index.\n *\n * @param terms - The terms for the AllowedCalldata caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the calldata itself.\n * @throws Error if the `calldata` is invalid.\n */\nexport function createAllowedCalldataTerms(\n terms: AllowedCalldataTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { startIndex, value } = terms;\n\n if (startIndex < 0) {\n throw new Error('Invalid startIndex: must be zero or positive');\n }\n\n if (!Number.isInteger(startIndex)) {\n throw new Error('Invalid startIndex: must be a whole number');\n }\n\n let unprefixedValue: string;\n\n if (typeof value === 'string') {\n if (!value.startsWith('0x')) {\n throw new Error('Invalid value: must be a hex string starting with 0x');\n }\n unprefixedValue = remove0x(value);\n } else {\n unprefixedValue = remove0x(bytesToHex(value));\n }\n\n const indexHex = toHexString({ value: startIndex, size: 32 });\n\n // The terms are the index encoded as 32 bytes followed by the expected value.\n return prepareResult(`0x${indexHex}${unprefixedValue}`, encodingOptions);\n}\n","import { bytesToHex, isHexString, type BytesLike } from '@metamask/utils';\n\nimport { concatHex } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedMethods caveat.\n */\nexport type AllowedMethodsTerms = {\n /** An array of 4-byte method selectors that the delegate is allowed to call. */\n selectors: BytesLike[];\n};\n\nconst FUNCTION_SELECTOR_STRING_LENGTH = 10; // 0x + 8 hex chars\nconst INVALID_SELECTOR_ERROR =\n 'Invalid selector: must be a 4 byte hex string, abi function signature, or AbiFunction';\n\n/**\n * Creates terms for an AllowedMethods caveat that restricts calls to a set of method selectors.\n *\n * @param terms - The terms for the AllowedMethods caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated method selectors.\n * @throws Error if the selectors array is empty or contains invalid selectors.\n */\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedMethods caveat that restricts calls to a set of method selectors.\n *\n * @param terms - The terms for the AllowedMethods caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated method selectors.\n * @throws Error if the selectors array is empty or contains invalid selectors.\n */\nexport function createAllowedMethodsTerms(\n terms: AllowedMethodsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { selectors } = terms;\n\n if (!selectors || selectors.length === 0) {\n throw new Error('Invalid selectors: must provide at least one selector');\n }\n\n const normalizedSelectors = selectors.map((selector) => {\n if (typeof selector === 'string') {\n if (\n isHexString(selector) &&\n selector.length === FUNCTION_SELECTOR_STRING_LENGTH\n ) {\n return selector;\n }\n throw new Error(INVALID_SELECTOR_ERROR);\n }\n\n if (selector.length !== 4) {\n throw new Error(INVALID_SELECTOR_ERROR);\n }\n\n return bytesToHex(selector);\n });\n\n const hexValue = concatHex(normalizedSelectors);\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an AllowedTargets caveat.\n */\nexport type AllowedTargetsTerms = {\n /** An array of target addresses that the delegate is allowed to call. */\n targets: BytesLike[];\n};\n\n/**\n * Creates terms for an AllowedTargets caveat that restricts calls to a set of target addresses.\n *\n * @param terms - The terms for the AllowedTargets caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target addresses.\n * @throws Error if the targets array is empty or contains invalid addresses.\n */\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an AllowedTargets caveat that restricts calls to a set of target addresses.\n *\n * @param terms - The terms for the AllowedTargets caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated target addresses.\n * @throws Error if the targets array is empty or contains invalid addresses.\n */\nexport function createAllowedTargetsTerms(\n terms: AllowedTargetsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { targets } = terms;\n\n if (!targets || targets.length === 0) {\n throw new Error(\n 'Invalid targets: must provide at least one target address',\n );\n }\n\n const normalizedTargets = targets.map((target) =>\n normalizeAddress(target, 'Invalid targets: must be valid addresses'),\n );\n\n const hexValue = concatHex(normalizedTargets);\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { normalizeHex } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an ArgsEqualityCheck caveat.\n */\nexport type ArgsEqualityCheckTerms = {\n /** The expected args that must match exactly when redeeming the delegation. */\n args: BytesLike;\n};\n\n/**\n * Creates terms for an ArgsEqualityCheck caveat that requires exact args matching.\n *\n * @param terms - The terms for the ArgsEqualityCheck caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the args themselves.\n * @throws Error if args is not a valid hex string.\n */\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an ArgsEqualityCheck caveat that requires exact args matching.\n *\n * @param terms - The terms for the ArgsEqualityCheck caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the args themselves.\n * @throws Error if args is not a valid hex string.\n */\nexport function createArgsEqualityCheckTerms(\n terms: ArgsEqualityCheckTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { args } = terms;\n\n if (typeof args === 'string' && args === '0x') {\n return prepareResult(args, encodingOptions);\n }\n\n const hexValue = normalizeHex(\n args,\n 'Invalid config: args must be a valid hex string',\n );\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a BlockNumber caveat.\n */\nexport type BlockNumberTerms = {\n /** The block number after which the delegation is valid. Set to 0n to disable. */\n afterThreshold: bigint;\n /** The block number before which the delegation is valid. Set to 0n to disable. */\n beforeThreshold: bigint;\n};\n\n/**\n * Creates terms for a BlockNumber caveat that constrains delegation validity by block range.\n *\n * @param terms - The terms for the BlockNumber caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each threshold).\n * @throws Error if both thresholds are zero or if afterThreshold >= beforeThreshold when both are set.\n */\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a BlockNumber caveat that constrains delegation validity by block range.\n *\n * @param terms - The terms for the BlockNumber caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string (16 bytes for each threshold).\n * @throws Error if both thresholds are zero or if afterThreshold >= beforeThreshold when both are set.\n */\nexport function createBlockNumberTerms(\n terms: BlockNumberTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { afterThreshold, beforeThreshold } = terms;\n\n if (afterThreshold < 0n || beforeThreshold < 0n) {\n throw new Error('Invalid thresholds: block numbers must be non-negative');\n }\n\n if (afterThreshold === 0n && beforeThreshold === 0n) {\n throw new Error(\n 'Invalid thresholds: At least one of afterThreshold or beforeThreshold must be specified',\n );\n }\n\n if (beforeThreshold !== 0n && afterThreshold >= beforeThreshold) {\n throw new Error(\n 'Invalid thresholds: afterThreshold must be less than beforeThreshold if both are specified',\n );\n }\n\n const afterThresholdHex = toHexString({ value: afterThreshold, size: 16 });\n const beforeThresholdHex = toHexString({ value: beforeThreshold, size: 16 });\n const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, normalizeHex } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a Deployed caveat.\n */\nexport type DeployedTerms = {\n /** The contract address. */\n contractAddress: BytesLike;\n /** The deployment salt. */\n salt: BytesLike;\n /** The contract bytecode. */\n bytecode: BytesLike;\n};\n\n/**\n * Creates terms for a Deployed caveat that constrains deployments by address, salt, and bytecode.\n *\n * @param terms - The terms for the Deployed caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated contractAddress + salt (32 bytes) + bytecode.\n * @throws Error if the contract address, salt, or bytecode is invalid.\n */\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Deployed caveat that constrains deployments by address, salt, and bytecode.\n *\n * @param terms - The terms for the Deployed caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated contractAddress + salt (32 bytes) + bytecode.\n * @throws Error if the contract address, salt, or bytecode is invalid.\n */\nexport function createDeployedTerms(\n terms: DeployedTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { contractAddress, salt, bytecode } = terms;\n\n const contractAddressHex = normalizeAddress(\n contractAddress,\n 'Invalid contractAddress: must be a valid Ethereum address',\n );\n const saltHex = normalizeHex(\n salt,\n 'Invalid salt: must be a valid hexadecimal string',\n );\n const bytecodeHex = normalizeHex(\n bytecode,\n 'Invalid bytecode: must be a valid hexadecimal string',\n );\n\n const unprefixedSalt = remove0x(saltHex);\n if (unprefixedSalt.length > 64) {\n throw new Error('Invalid salt: must be a valid hexadecimal string');\n }\n const paddedSalt = `0x${unprefixedSalt.padStart(64, '0')}`;\n\n const hexValue = concatHex([contractAddressHex, paddedSalt, bytecodeHex]);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\nconst MAX_UINT256 = BigInt(`0x${'f'.repeat(64)}`);\n\n/**\n * Terms for configuring an Id caveat.\n */\nexport type IdTerms = {\n /** An id for the delegation. Only one delegation may be redeemed with any given id. */\n id: bigint | number;\n};\n\n/**\n * Creates terms for an Id caveat that restricts delegations by unique identifier.\n *\n * @param terms - The terms for the Id caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the id is invalid or out of range.\n */\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an Id caveat that restricts delegations by unique identifier.\n *\n * @param terms - The terms for the Id caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the id is invalid or out of range.\n */\nexport function createIdTerms(\n terms: IdTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { id } = terms;\n\n let idBigInt: bigint;\n\n if (typeof id === 'number') {\n if (!Number.isInteger(id)) {\n throw new Error('Invalid id: must be an integer');\n }\n idBigInt = BigInt(id);\n } else if (typeof id === 'bigint') {\n idBigInt = id;\n } else {\n throw new Error('Invalid id: must be a bigint or number');\n }\n\n if (idBigInt < 0n) {\n throw new Error('Invalid id: must be a non-negative number');\n }\n\n if (idBigInt > MAX_UINT256) {\n throw new Error('Invalid id: must be less than 2^256');\n }\n\n const hexValue = `0x${toHexString({ value: idBigInt, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n","import { toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a LimitedCalls caveat.\n */\nexport type LimitedCallsTerms = {\n /** The maximum number of times this delegation may be redeemed. */\n limit: number;\n};\n\n/**\n * Creates terms for a LimitedCalls caveat that restricts the number of redeems.\n *\n * @param terms - The terms for the LimitedCalls caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the limit is not a positive integer.\n */\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a LimitedCalls caveat that restricts the number of redeems.\n *\n * @param terms - The terms for the LimitedCalls caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as a 32-byte hex string.\n * @throws Error if the limit is not a positive integer.\n */\nexport function createLimitedCallsTerms(\n terms: LimitedCallsTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { limit } = terms;\n\n if (!Number.isInteger(limit)) {\n throw new Error('Invalid limit: must be an integer');\n }\n\n if (limit <= 0) {\n throw new Error('Invalid limit: must be a positive integer');\n }\n\n const hexValue = `0x${toHexString({ value: limit, size: 32 })}`;\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Configuration for a single token in MultiTokenPeriod terms.\n */\nexport type TokenPeriodConfig = {\n token: BytesLike;\n periodAmount: bigint;\n periodDuration: number;\n startDate: number;\n};\n\n/**\n * Terms for configuring a MultiTokenPeriod caveat.\n */\nexport type MultiTokenPeriodTerms = {\n tokenConfigs: TokenPeriodConfig[];\n};\n\n/**\n * Creates terms for a MultiTokenPeriod caveat that configures multiple token periods.\n *\n * @param terms - The terms for the MultiTokenPeriod caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated token period configs.\n * @throws Error if the tokenConfigs array is empty or contains invalid parameters.\n */\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a MultiTokenPeriod caveat that configures multiple token periods.\n *\n * @param terms - The terms for the MultiTokenPeriod caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated token period configs.\n * @throws Error if the tokenConfigs array is empty or contains invalid parameters.\n */\nexport function createMultiTokenPeriodTerms(\n terms: MultiTokenPeriodTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenConfigs } = terms;\n\n if (!tokenConfigs || tokenConfigs.length === 0) {\n throw new Error(\n 'MultiTokenPeriodBuilder: tokenConfigs array cannot be empty',\n );\n }\n\n const hexParts: string[] = [];\n\n for (const tokenConfig of tokenConfigs) {\n const tokenHex = normalizeAddress(\n tokenConfig.token,\n `Invalid token address: ${String(tokenConfig.token)}`,\n );\n\n if (tokenConfig.periodAmount <= 0n) {\n throw new Error('Invalid period amount: must be greater than 0');\n }\n\n if (tokenConfig.periodDuration <= 0) {\n throw new Error('Invalid period duration: must be greater than 0');\n }\n\n if (tokenConfig.startDate <= 0) {\n throw new Error('Invalid start date: must be greater than 0');\n }\n\n hexParts.push(\n tokenHex,\n `0x${toHexString({ value: tokenConfig.periodAmount, size: 32 })}`,\n `0x${toHexString({ value: tokenConfig.periodDuration, size: 32 })}`,\n `0x${toHexString({ value: tokenConfig.startDate, size: 32 })}`,\n );\n }\n\n const hexValue = concatHex(hexParts);\n return prepareResult(hexValue, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring an OwnershipTransfer caveat.\n */\nexport type OwnershipTransferTerms = {\n /** The contract address for which ownership transfers are allowed. */\n contractAddress: BytesLike;\n};\n\n/**\n * Creates terms for an OwnershipTransfer caveat that constrains ownership transfers to a contract.\n *\n * @param terms - The terms for the OwnershipTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the contract address.\n * @throws Error if the contract address is invalid.\n */\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for an OwnershipTransfer caveat that constrains ownership transfers to a contract.\n *\n * @param terms - The terms for the OwnershipTransfer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as the contract address.\n * @throws Error if the contract address is invalid.\n */\nexport function createOwnershipTransferTerms(\n terms: OwnershipTransferTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { contractAddress } = terms;\n\n const contractAddressHex = normalizeAddress(\n contractAddress,\n 'Invalid contractAddress: must be a valid address',\n );\n\n return prepareResult(contractAddressHex, encodingOptions);\n}\n","import type { BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a Redeemer caveat.\n */\nexport type RedeemerTerms = {\n /** An array of addresses allowed to redeem the delegation. */\n redeemers: BytesLike[];\n};\n\n/**\n * Creates terms for a Redeemer caveat that restricts who may redeem.\n *\n * @param terms - The terms for the Redeemer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated redeemer addresses.\n * @throws Error if the redeemers array is empty or contains invalid addresses.\n */\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a Redeemer caveat that restricts who may redeem.\n *\n * @param terms - The terms for the Redeemer caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated redeemer addresses.\n * @throws Error if the redeemers array is empty or contains invalid addresses.\n */\nexport function createRedeemerTerms(\n terms: RedeemerTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { redeemers } = terms;\n\n if (!redeemers || redeemers.length === 0) {\n throw new Error(\n 'Invalid redeemers: must specify at least one redeemer address',\n );\n }\n\n const normalizedRedeemers = redeemers.map((redeemer) =>\n normalizeAddress(redeemer, 'Invalid redeemers: must be a valid address'),\n );\n\n const hexValue = concatHex(normalizedRedeemers);\n return prepareResult(hexValue, encodingOptions);\n}\n","import { bytesToHex, type BytesLike } from '@metamask/utils';\n\nimport { concatHex, normalizeAddress, toHexString } from '../internalUtils';\nimport {\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from '../returns';\nimport type { Hex } from '../types';\n\n/**\n * Terms for configuring a SpecificActionERC20TransferBatch caveat.\n */\nexport type SpecificActionERC20TransferBatchTerms = {\n /** The address of the ERC-20 token contract. */\n tokenAddress: BytesLike;\n /** The recipient of the ERC-20 transfer. */\n recipient: BytesLike;\n /** The amount of tokens to transfer. */\n amount: bigint;\n /** The target address for the first transaction. */\n target: BytesLike;\n /** The calldata for the first transaction. */\n calldata: BytesLike;\n};\n\n/**\n * Creates terms for a SpecificActionERC20TransferBatch caveat that enforces a\n * specific action followed by an ERC20 transfer.\n *\n * @param terms - The terms for the SpecificActionERC20TransferBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated tokenAddress + recipient + amount + target + calldata.\n * @throws Error if any address is invalid or amount is not positive.\n */\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions?: EncodingOptions<'hex'>,\n): Hex;\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Creates terms for a SpecificActionERC20TransferBatch caveat that enforces a\n * specific action followed by an ERC20 transfer.\n *\n * @param terms - The terms for the SpecificActionERC20TransferBatch caveat.\n * @param encodingOptions - The encoding options for the result.\n * @returns The terms as concatenated tokenAddress + recipient + amount + target + calldata.\n * @throws Error if any address is invalid or amount is not positive.\n */\nexport function createSpecificActionERC20TransferBatchTerms(\n terms: SpecificActionERC20TransferBatchTerms,\n encodingOptions: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const { tokenAddress, recipient, amount, target, calldata } = terms;\n\n const tokenAddressHex = normalizeAddress(\n tokenAddress,\n 'Invalid tokenAddress: must be a valid address',\n );\n const recipientHex = normalizeAddress(\n recipient,\n 'Invalid recipient: must be a valid address',\n );\n const targetHex = normalizeAddress(\n target,\n 'Invalid target: must be a valid address',\n );\n\n let calldataHex: string;\n if (typeof calldata === 'string') {\n if (!calldata.startsWith('0x')) {\n throw new Error(\n 'Invalid calldata: must be a hex string starting with 0x',\n );\n }\n calldataHex = calldata;\n } else {\n calldataHex = bytesToHex(calldata);\n }\n\n if (amount <= 0n) {\n throw new Error('Invalid amount: must be a positive number');\n }\n\n const amountHex = `0x${toHexString({ value: amount, size: 32 })}`;\n\n const hexValue = concatHex([\n tokenAddressHex,\n recipientHex,\n amountHex,\n targetHex,\n calldataHex,\n ]);\n\n return prepareResult(hexValue, encodingOptions);\n}\n","import { encode, encodeSingle, decodeSingle } from '@metamask/abi-utils';\nimport { hexToBytes, type BytesLike } from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nimport {\n bytesLikeToBytes,\n bytesLikeToHex,\n defaultOptions,\n prepareResult,\n type EncodingOptions,\n type ResultValue,\n} from './returns';\nimport type { CaveatStruct, DelegationStruct, Hex } from './types';\n\n/**\n * When designated as the delegate address in a delegation, this allows any beneficiary to redeem the delegation.\n */\nexport const ANY_BENEFICIARY =\n '0x0000000000000000000000000000000000000a11' as const;\n\n/**\n * To be used on a delegation as the root authority.\n */\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as const;\n\n/**\n * The typehash for a delegation, used when generating a delegation hash.\n *\n * keccak('Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)')\n */\nexport const DELEGATION_TYPEHASH =\n '0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e' as const;\n\n/**\n * The typehash for a caveat, used when generating a caveat hash.\n *\n * keccak('Caveat(address enforcer,bytes terms)')\n */\nexport const CAVEAT_TYPEHASH =\n '0x80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d' as const;\n\n/**\n * The ABI types for an array of delegations.\n */\nconst DELEGATION_ARRAY_ABI_TYPES =\n '(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)[]' as const;\n\n/**\n * The ABI type for a single delegation.\n */\nconst DELEGATION_ABI_TYPE =\n '(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)' as const;\n\n/**\n * Encodes an array of delegations into a permission context.\n *\n * @param delegations - The delegations to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegations as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Encodes an array of delegations into a permission context.\n *\n * @param delegations - The delegations to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegations as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegations(\n delegations: DelegationStruct[],\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n let result: Uint8Array;\n\n if (delegations.length === 0) {\n // short circuit for empty delegations, derived from\n // `encode(['(address,address,bytes32,(address,bytes,bytes)[],uint256,bytes)[]'],[[]],);`\n result = new Uint8Array(64);\n result[31] = 0x20;\n } else {\n const encodableStructs = delegations.map((struct) => [\n struct.delegate,\n struct.delegator,\n struct.authority,\n struct.caveats.map((caveat) => [\n caveat.enforcer,\n caveat.terms,\n caveat.args,\n ]),\n struct.salt,\n struct.signature,\n ]);\n\n result = encodeSingle(DELEGATION_ARRAY_ABI_TYPES, encodableStructs);\n }\n\n return prepareResult(result, options);\n}\n\n/**\n * Encodes a single delegation.\n *\n * @param delegation - The delegation to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Encodes a single delegation.\n *\n * @param delegation - The delegation to encode.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function encodeDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const encodableStruct = [\n delegation.delegate,\n delegation.delegator,\n delegation.authority,\n delegation.caveats.map((caveat) => [\n caveat.enforcer,\n caveat.terms,\n caveat.args,\n ]),\n delegation.salt,\n delegation.signature,\n ];\n\n const result = encodeSingle(DELEGATION_ABI_TYPE, encodableStruct);\n\n return prepareResult(result, options);\n}\n\n/**\n * Converts a decoded delegation struct to a delegation object using the provided conversion function.\n *\n * @param decodedDelegation - The decoded delegation struct as a tuple.\n * @param convertFn - Function to convert BytesLike values to the desired output type.\n * @returns A delegation object with all bytes-like values converted using the provided function.\n */\nconst delegationFromDecodedDelegation = <TEncoding extends BytesLike>(\n decodedDelegation: DecodedDelegation,\n convertFn: (value: BytesLike) => TEncoding,\n): DelegationStruct<TEncoding> => {\n const [delegate, delegator, authority, caveats, salt, signature] =\n decodedDelegation;\n\n return {\n delegate: convertFn(delegate),\n delegator: convertFn(delegator),\n authority: convertFn(authority),\n caveats: caveats.map(([enforcer, terms, args]) => ({\n enforcer: convertFn(enforcer),\n terms: convertFn(terms),\n args: convertFn(args),\n })),\n salt,\n signature: convertFn(signature),\n };\n};\n\n/**\n * Represents a decoded delegation as a tuple structure.\n * This type defines the structure of a delegation after it has been decoded from\n * an encoded format.\n */\ntype DecodedDelegation = [\n BytesLike,\n BytesLike,\n BytesLike,\n [BytesLike, BytesLike, BytesLike][],\n bigint,\n BytesLike,\n];\n\n/**\n * Decodes an encoded permission context back into an array of delegations.\n *\n * @param encoded - The encoded delegations as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegations array with types resolved based on options.\n */\nexport function decodeDelegations(\n encoded: BytesLike,\n options?: EncodingOptions<'hex'>,\n): DelegationStruct<Hex>[];\nexport function decodeDelegations(\n encoded: BytesLike,\n options: EncodingOptions<'bytes'>,\n): DelegationStruct<Uint8Array>[];\n/**\n * Decodes an encoded permission context back into an array of delegations.\n *\n * @param encoded - The encoded delegations as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegations array with types resolved based on options.\n */\nexport function decodeDelegations(\n encoded: BytesLike,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): DelegationStruct<Hex>[] | DelegationStruct<Uint8Array>[] {\n // it's possible to short circuit for empty delegations, but due to the\n // complexity of the input type, and the relative infrequency of empty delegations,\n // it's not worthwhile.\n\n const decodedStructs = decodeSingle(\n DELEGATION_ARRAY_ABI_TYPES,\n encoded,\n // return types cannot be inferred from complex ABI types, so we must assert the type\n ) as DecodedDelegation[];\n\n if (options.out === 'bytes') {\n return decodedStructs.map((struct) =>\n delegationFromDecodedDelegation(struct, bytesLikeToBytes),\n );\n }\n return decodedStructs.map((struct) =>\n delegationFromDecodedDelegation(struct, bytesLikeToHex),\n );\n}\n\n/**\n * Decodes an encoded single delegation.\n *\n * @param encoded - The encoded delegation as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegation with types resolved based on options.\n */\nexport function decodeDelegation(\n encoded: BytesLike,\n options?: EncodingOptions<'hex'>,\n): DelegationStruct<Hex>;\nexport function decodeDelegation(\n encoded: BytesLike,\n options: EncodingOptions<'bytes'>,\n): DelegationStruct<Uint8Array>;\n/**\n * Decodes an encoded single delegation.\n *\n * @param encoded - The encoded delegation as a hex string or Uint8Array.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The decoded delegation with types resolved based on options.\n */\nexport function decodeDelegation(\n encoded: BytesLike,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): DelegationStruct<Hex> | DelegationStruct<Uint8Array> {\n const decodedStruct = decodeSingle(\n DELEGATION_ABI_TYPE,\n encoded,\n // return types cannot be inferred from complex ABI types, so we must assert the type\n ) as DecodedDelegation;\n\n if (options.out === 'bytes') {\n return delegationFromDecodedDelegation(decodedStruct, bytesLikeToBytes);\n }\n return delegationFromDecodedDelegation(decodedStruct, bytesLikeToHex);\n}\n\n/**\n * Calculates the hash of a delegation for signing purposes.\n * The hash is computed by encoding the delegation parameters with the delegation typehash\n * and then applying keccak256 hashing.\n *\n * @param delegation - The delegation to hash.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The keccak256 hash of the encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function hashDelegation(\n delegation: DelegationStruct,\n options?: EncodingOptions<'hex'>,\n): Hex;\nexport function hashDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<'bytes'>,\n): Uint8Array;\n/**\n * Calculates the hash of a delegation for signing purposes.\n * The hash is computed by encoding the delegation parameters with the delegation typehash\n * and then applying keccak256 hashing.\n *\n * @param delegation - The delegation to hash.\n * @param options - Encoding options. Defaults to { out: 'hex' }.\n * @returns The keccak256 hash of the encoded delegation as a hex string (default) or Uint8Array.\n */\nexport function hashDelegation(\n delegation: DelegationStruct,\n options: EncodingOptions<ResultValue> = defaultOptions,\n): Hex | Uint8Array {\n const encoded = encode(\n ['bytes32', 'address', 'address', 'bytes32', 'bytes32', 'uint256'],\n [\n DELEGATION_TYPEHASH,\n delegation.delegate,\n delegation.delegator,\n delegation.authority,\n getCaveatsArrayHash(delegation.caveats),\n delegation.salt,\n ],\n );\n const hash = keccak256(encoded);\n return prepareResult(hash, options);\n}\n\n/**\n * Calculates the hash of an array of caveats. The caveats are individually abi\n * encoded and hashed, and concatenated. The resulting byte array is then\n * hashed to produce the CaveatsArrayHash.\n *\n * @param caveats - The array of caveats to hash.\n * @returns The keccak256 hash of the encoded caveat array.\n */\nfunction getCaveatsArrayHash(caveats: CaveatStruct[]): Uint8Array {\n const byteLength = 32 * caveats.length;\n const encoded = new Uint8Array(byteLength);\n\n for (let i = 0; i < caveats.length; i++) {\n const caveat = caveats[i];\n if (!caveat) {\n throw new Error(`Caveat was undefined at index ${i}`);\n }\n const caveatHash = getCaveatHash(caveat);\n encoded.set(caveatHash, i * 32);\n }\n\n return keccak256(encoded);\n}\n\n/**\n * Calculates the hash of a single caveat.\n *\n * @param caveat - The caveat to hash.\n * @returns The keccak256 hash of the encoded caveat.\n */\nfunction getCaveatHash(caveat: CaveatStruct): Uint8Array {\n const termsBytes =\n typeof caveat.terms === 'string' ? hexToBytes(caveat.terms) : caveat.terms;\n\n const termsHash = keccak256(termsBytes);\n\n const encoded = encode(\n ['bytes32', 'address', 'bytes32'],\n [CAVEAT_TYPEHASH, caveat.enforcer, termsHash],\n );\n const hash = keccak256(encoded);\n return hash;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -47,6 +47,36 @@ type ExactCalldataTerms = {
|
|
|
47
47
|
declare function createExactCalldataTerms(terms: ExactCalldataTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
48
48
|
declare function createExactCalldataTerms(terms: ExactCalldataTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
49
49
|
|
|
50
|
+
type ExactCalldataBatchTerms = {
|
|
51
|
+
executions: {
|
|
52
|
+
target: BytesLike;
|
|
53
|
+
value: bigint;
|
|
54
|
+
callData: BytesLike;
|
|
55
|
+
}[];
|
|
56
|
+
};
|
|
57
|
+
declare function createExactCalldataBatchTerms(terms: ExactCalldataBatchTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
58
|
+
declare function createExactCalldataBatchTerms(terms: ExactCalldataBatchTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
59
|
+
|
|
60
|
+
type ExactExecutionTerms = {
|
|
61
|
+
execution: {
|
|
62
|
+
target: BytesLike;
|
|
63
|
+
value: bigint;
|
|
64
|
+
callData: BytesLike;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
declare function createExactExecutionTerms(terms: ExactExecutionTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
68
|
+
declare function createExactExecutionTerms(terms: ExactExecutionTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
69
|
+
|
|
70
|
+
type ExactExecutionBatchTerms = {
|
|
71
|
+
executions: {
|
|
72
|
+
target: BytesLike;
|
|
73
|
+
value: bigint;
|
|
74
|
+
callData: BytesLike;
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
declare function createExactExecutionBatchTerms(terms: ExactExecutionBatchTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
78
|
+
declare function createExactExecutionBatchTerms(terms: ExactExecutionBatchTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
79
|
+
|
|
50
80
|
type NativeTokenStreamingTerms = {
|
|
51
81
|
initialAmount: bigint;
|
|
52
82
|
maxAmount: bigint;
|
|
@@ -56,6 +86,27 @@ type NativeTokenStreamingTerms = {
|
|
|
56
86
|
declare function createNativeTokenStreamingTerms(terms: NativeTokenStreamingTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
57
87
|
declare function createNativeTokenStreamingTerms(terms: NativeTokenStreamingTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
58
88
|
|
|
89
|
+
type NativeTokenTransferAmountTerms = {
|
|
90
|
+
maxAmount: bigint;
|
|
91
|
+
};
|
|
92
|
+
declare function createNativeTokenTransferAmountTerms(terms: NativeTokenTransferAmountTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
93
|
+
declare function createNativeTokenTransferAmountTerms(terms: NativeTokenTransferAmountTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
94
|
+
|
|
95
|
+
type NativeTokenPaymentTerms = {
|
|
96
|
+
recipient: BytesLike;
|
|
97
|
+
amount: bigint;
|
|
98
|
+
};
|
|
99
|
+
declare function createNativeTokenPaymentTerms(terms: NativeTokenPaymentTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
100
|
+
declare function createNativeTokenPaymentTerms(terms: NativeTokenPaymentTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
101
|
+
|
|
102
|
+
type NativeBalanceChangeTerms = {
|
|
103
|
+
recipient: BytesLike;
|
|
104
|
+
balance: bigint;
|
|
105
|
+
changeType: number;
|
|
106
|
+
};
|
|
107
|
+
declare function createNativeBalanceChangeTerms(terms: NativeBalanceChangeTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
108
|
+
declare function createNativeBalanceChangeTerms(terms: NativeBalanceChangeTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
109
|
+
|
|
59
110
|
type ERC20StreamingTerms = {
|
|
60
111
|
tokenAddress: BytesLike;
|
|
61
112
|
initialAmount: bigint;
|
|
@@ -75,21 +126,153 @@ type ERC20TokenPeriodTransferTerms = {
|
|
|
75
126
|
declare function createERC20TokenPeriodTransferTerms(terms: ERC20TokenPeriodTransferTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
76
127
|
declare function createERC20TokenPeriodTransferTerms(terms: ERC20TokenPeriodTransferTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
77
128
|
|
|
129
|
+
type ERC20TransferAmountTerms = {
|
|
130
|
+
tokenAddress: BytesLike;
|
|
131
|
+
maxAmount: bigint;
|
|
132
|
+
};
|
|
133
|
+
declare function createERC20TransferAmountTerms(terms: ERC20TransferAmountTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
134
|
+
declare function createERC20TransferAmountTerms(terms: ERC20TransferAmountTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
135
|
+
|
|
136
|
+
type ERC20BalanceChangeTerms = {
|
|
137
|
+
tokenAddress: BytesLike;
|
|
138
|
+
recipient: BytesLike;
|
|
139
|
+
balance: bigint;
|
|
140
|
+
changeType: number;
|
|
141
|
+
};
|
|
142
|
+
declare function createERC20BalanceChangeTerms(terms: ERC20BalanceChangeTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
143
|
+
declare function createERC20BalanceChangeTerms(terms: ERC20BalanceChangeTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
144
|
+
|
|
145
|
+
type ERC721BalanceChangeTerms = {
|
|
146
|
+
tokenAddress: BytesLike;
|
|
147
|
+
recipient: BytesLike;
|
|
148
|
+
amount: bigint;
|
|
149
|
+
changeType: number;
|
|
150
|
+
};
|
|
151
|
+
declare function createERC721BalanceChangeTerms(terms: ERC721BalanceChangeTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
152
|
+
declare function createERC721BalanceChangeTerms(terms: ERC721BalanceChangeTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
153
|
+
|
|
154
|
+
type ERC721TransferTerms = {
|
|
155
|
+
tokenAddress: BytesLike;
|
|
156
|
+
tokenId: bigint;
|
|
157
|
+
};
|
|
158
|
+
declare function createERC721TransferTerms(terms: ERC721TransferTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
159
|
+
declare function createERC721TransferTerms(terms: ERC721TransferTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
160
|
+
|
|
161
|
+
type ERC1155BalanceChangeTerms = {
|
|
162
|
+
tokenAddress: BytesLike;
|
|
163
|
+
recipient: BytesLike;
|
|
164
|
+
tokenId: bigint;
|
|
165
|
+
balance: bigint;
|
|
166
|
+
changeType: number;
|
|
167
|
+
};
|
|
168
|
+
declare function createERC1155BalanceChangeTerms(terms: ERC1155BalanceChangeTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
169
|
+
declare function createERC1155BalanceChangeTerms(terms: ERC1155BalanceChangeTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
170
|
+
|
|
78
171
|
type NonceTerms = {
|
|
79
172
|
nonce: BytesLike;
|
|
80
173
|
};
|
|
81
174
|
declare function createNonceTerms(terms: NonceTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
82
175
|
declare function createNonceTerms(terms: NonceTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
83
176
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
177
|
+
type AllowedCalldataTerms = {
|
|
178
|
+
startIndex: number;
|
|
179
|
+
value: BytesLike;
|
|
180
|
+
};
|
|
181
|
+
declare function createAllowedCalldataTerms(terms: AllowedCalldataTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
182
|
+
declare function createAllowedCalldataTerms(terms: AllowedCalldataTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
183
|
+
|
|
184
|
+
type AllowedMethodsTerms = {
|
|
185
|
+
selectors: BytesLike[];
|
|
186
|
+
};
|
|
187
|
+
declare function createAllowedMethodsTerms(terms: AllowedMethodsTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
188
|
+
declare function createAllowedMethodsTerms(terms: AllowedMethodsTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
189
|
+
|
|
190
|
+
type AllowedTargetsTerms = {
|
|
191
|
+
targets: BytesLike[];
|
|
192
|
+
};
|
|
193
|
+
declare function createAllowedTargetsTerms(terms: AllowedTargetsTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
194
|
+
declare function createAllowedTargetsTerms(terms: AllowedTargetsTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
195
|
+
|
|
196
|
+
type ArgsEqualityCheckTerms = {
|
|
197
|
+
args: BytesLike;
|
|
198
|
+
};
|
|
199
|
+
declare function createArgsEqualityCheckTerms(terms: ArgsEqualityCheckTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
200
|
+
declare function createArgsEqualityCheckTerms(terms: ArgsEqualityCheckTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
201
|
+
|
|
202
|
+
type BlockNumberTerms = {
|
|
203
|
+
afterThreshold: bigint;
|
|
204
|
+
beforeThreshold: bigint;
|
|
205
|
+
};
|
|
206
|
+
declare function createBlockNumberTerms(terms: BlockNumberTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
207
|
+
declare function createBlockNumberTerms(terms: BlockNumberTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
208
|
+
|
|
209
|
+
type DeployedTerms = {
|
|
210
|
+
contractAddress: BytesLike;
|
|
211
|
+
salt: BytesLike;
|
|
212
|
+
bytecode: BytesLike;
|
|
213
|
+
};
|
|
214
|
+
declare function createDeployedTerms(terms: DeployedTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
215
|
+
declare function createDeployedTerms(terms: DeployedTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
216
|
+
|
|
217
|
+
type IdTerms = {
|
|
218
|
+
id: bigint | number;
|
|
219
|
+
};
|
|
220
|
+
declare function createIdTerms(terms: IdTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
221
|
+
declare function createIdTerms(terms: IdTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
222
|
+
|
|
223
|
+
type LimitedCallsTerms = {
|
|
224
|
+
limit: number;
|
|
225
|
+
};
|
|
226
|
+
declare function createLimitedCallsTerms(terms: LimitedCallsTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
227
|
+
declare function createLimitedCallsTerms(terms: LimitedCallsTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
228
|
+
|
|
229
|
+
type TokenPeriodConfig = {
|
|
230
|
+
token: BytesLike;
|
|
231
|
+
periodAmount: bigint;
|
|
232
|
+
periodDuration: number;
|
|
233
|
+
startDate: number;
|
|
234
|
+
};
|
|
235
|
+
type MultiTokenPeriodTerms = {
|
|
236
|
+
tokenConfigs: TokenPeriodConfig[];
|
|
237
|
+
};
|
|
238
|
+
declare function createMultiTokenPeriodTerms(terms: MultiTokenPeriodTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
239
|
+
declare function createMultiTokenPeriodTerms(terms: MultiTokenPeriodTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
240
|
+
|
|
241
|
+
type OwnershipTransferTerms = {
|
|
242
|
+
contractAddress: BytesLike;
|
|
243
|
+
};
|
|
244
|
+
declare function createOwnershipTransferTerms(terms: OwnershipTransferTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
245
|
+
declare function createOwnershipTransferTerms(terms: OwnershipTransferTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
246
|
+
|
|
247
|
+
type RedeemerTerms = {
|
|
248
|
+
redeemers: BytesLike[];
|
|
249
|
+
};
|
|
250
|
+
declare function createRedeemerTerms(terms: RedeemerTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
251
|
+
declare function createRedeemerTerms(terms: RedeemerTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
252
|
+
|
|
253
|
+
type SpecificActionERC20TransferBatchTerms = {
|
|
254
|
+
tokenAddress: BytesLike;
|
|
255
|
+
recipient: BytesLike;
|
|
256
|
+
amount: bigint;
|
|
257
|
+
target: BytesLike;
|
|
258
|
+
calldata: BytesLike;
|
|
259
|
+
};
|
|
260
|
+
declare function createSpecificActionERC20TransferBatchTerms(terms: SpecificActionERC20TransferBatchTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
|
|
261
|
+
declare function createSpecificActionERC20TransferBatchTerms(terms: SpecificActionERC20TransferBatchTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
|
|
262
|
+
|
|
263
|
+
declare const ANY_BENEFICIARY: "0x0000000000000000000000000000000000000a11";
|
|
264
|
+
declare const ROOT_AUTHORITY: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
|
|
265
|
+
declare const DELEGATION_TYPEHASH: "0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e";
|
|
266
|
+
declare const CAVEAT_TYPEHASH: "0x80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d";
|
|
88
267
|
declare function encodeDelegations(delegations: DelegationStruct[], options?: EncodingOptions<'hex'>): Hex;
|
|
89
268
|
declare function encodeDelegations(delegations: DelegationStruct[], options: EncodingOptions<'bytes'>): Uint8Array;
|
|
269
|
+
declare function encodeDelegation(delegation: DelegationStruct, options?: EncodingOptions<'hex'>): Hex;
|
|
270
|
+
declare function encodeDelegation(delegation: DelegationStruct, options: EncodingOptions<'bytes'>): Uint8Array;
|
|
90
271
|
declare function decodeDelegations(encoded: BytesLike, options?: EncodingOptions<'hex'>): DelegationStruct<Hex>[];
|
|
91
272
|
declare function decodeDelegations(encoded: BytesLike, options: EncodingOptions<'bytes'>): DelegationStruct<Uint8Array>[];
|
|
273
|
+
declare function decodeDelegation(encoded: BytesLike, options?: EncodingOptions<'hex'>): DelegationStruct<Hex>;
|
|
274
|
+
declare function decodeDelegation(encoded: BytesLike, options: EncodingOptions<'bytes'>): DelegationStruct<Uint8Array>;
|
|
92
275
|
declare function hashDelegation(delegation: DelegationStruct, options?: EncodingOptions<'hex'>): Hex;
|
|
93
276
|
declare function hashDelegation(delegation: DelegationStruct, options: EncodingOptions<'bytes'>): Uint8Array;
|
|
94
277
|
|
|
95
|
-
export { ANY_BENEFICIARY, CAVEAT_TYPEHASH, type CaveatStruct as Caveat, DELEGATION_TYPEHASH, type DelegationStruct as Delegation, ROOT_AUTHORITY, createERC20StreamingTerms, createERC20TokenPeriodTransferTerms, createExactCalldataTerms, createNativeTokenPeriodTransferTerms, createNativeTokenStreamingTerms, createNonceTerms, createTimestampTerms, createValueLteTerms, decodeDelegations, encodeDelegations, hashDelegation };
|
|
278
|
+
export { ANY_BENEFICIARY, CAVEAT_TYPEHASH, type CaveatStruct as Caveat, DELEGATION_TYPEHASH, type DelegationStruct as Delegation, ROOT_AUTHORITY, createAllowedCalldataTerms, createAllowedMethodsTerms, createAllowedTargetsTerms, createArgsEqualityCheckTerms, createBlockNumberTerms, createDeployedTerms, createERC1155BalanceChangeTerms, createERC20BalanceChangeTerms, createERC20StreamingTerms, createERC20TokenPeriodTransferTerms, createERC20TransferAmountTerms, createERC721BalanceChangeTerms, createERC721TransferTerms, createExactCalldataBatchTerms, createExactCalldataTerms, createExactExecutionBatchTerms, createExactExecutionTerms, createIdTerms, createLimitedCallsTerms, createMultiTokenPeriodTerms, createNativeBalanceChangeTerms, createNativeTokenPaymentTerms, createNativeTokenPeriodTransferTerms, createNativeTokenStreamingTerms, createNativeTokenTransferAmountTerms, createNonceTerms, createOwnershipTransferTerms, createRedeemerTerms, createSpecificActionERC20TransferBatchTerms, createTimestampTerms, createValueLteTerms, decodeDelegation, decodeDelegations, encodeDelegation, encodeDelegations, hashDelegation };
|