@metamask/delegation-core 0.2.0-rc.1 → 0.3.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 CHANGED
@@ -7,16 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0]
11
+
12
+ ### Added
13
+
14
+ - New `allowedCalldata` terms builder ([#108](https://github.com/MetaMask/smart-accounts-kit/pull/108))
15
+
16
+ ## [0.2.0]
17
+
18
+ ### Added
19
+
20
+ - Added a Nonce caveat enforcer terms builder `createNonceTerms` ([#44](https://github.com/metamask/smart-accounts-kit/pull/44))
21
+
22
+ ### Changed
23
+
24
+ - The configuration parameter `callData` is now `calldata` in `createExactCalldataTerms` argument type. ([#24](https://github.com/metamask/smart-accounts-kit/pull/24))
25
+ - The package is explictly marked as ESM via `type: module`; with CJS compatibility maintained with dual export. ([#27](https://github.com/metamask/smart-accounts-kit/pull/27))
26
+
10
27
  ## [0.2.0-rc.1]
11
28
 
12
29
  ### Added
13
30
 
14
- - Added a Nonce caveat enforcer terms builder `createNonceTerms` ([#44](https://github.com/metamask/delegation-toolkit/pull/44))
31
+ - Added a Nonce caveat enforcer terms builder `createNonceTerms` ([#44](https://github.com/metamask/smart-accounts-kit/pull/44))
15
32
 
16
33
  ### Changed
17
34
 
18
- - The configuration parameter `callData` is now `calldata` in `createExactCalldataTerms` argument type. ([#24](https://github.com/metamask/delegation-toolkit/pull/24))
19
- - The package is explictly marked as ESM via `type: module`; with CJS compatibility maintained with dual export. ([#27](https://github.com/metamask/delegation-toolkit/pull/27))
35
+ - The configuration parameter `callData` is now `calldata` in `createExactCalldataTerms` argument type. ([#24](https://github.com/metamask/smart-accounts-kit/pull/24))
36
+ - The package is explictly marked as ESM via `type: module`; with CJS compatibility maintained with dual export. ([#27](https://github.com/metamask/smart-accounts-kit/pull/27))
20
37
 
21
38
  ## [0.1.0]
22
39
 
@@ -24,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
41
 
25
42
  - Add @metamask/delegation-core package, providing utility types, delegation hashing, and terms encoding for a limited set of caveat enforcers.
26
43
 
27
- [Unreleased]: https://github.com/metamask/delegation-toolkit/compare/@metamask/delegation-core@0.2.0-rc.1...HEAD
28
- [0.2.0-rc.1]: https://github.com/metamask/delegation-toolkit/compare/@metamask/delegation-core@0.1.0...@metamask/delegation-core@0.2.0-rc.1
29
- [0.1.0]: https://github.com/metamask/delegation-toolkit/releases/tag/@metamask/delegation-core@0.1.0
44
+ [Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/delegation-core@0.3.0...HEAD
45
+ [0.3.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/delegation-core@0.2.0...@metamask/delegation-core@0.3.0
46
+ [0.2.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/delegation-core@0.2.0-rc.1...@metamask/delegation-core@0.2.0
47
+ [0.2.0-rc.1]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/delegation-core@0.1.0...@metamask/delegation-core@0.2.0-rc.1
48
+ [0.1.0]: https://github.com/metamask/smart-accounts-kit/releases/tag/@metamask/delegation-core@0.1.0
package/README.md CHANGED
@@ -400,7 +400,7 @@ try {
400
400
 
401
401
  ## Related Packages
402
402
 
403
- - `@metamask/delegation-toolkit` - Higher-level utilities for delegation management
403
+ - `@metamask/smart-accounts-kit` - Higher-level utilities for delegation management
404
404
  - `@metamask/delegation-abis` - Contract ABIs for the delegation framework
405
405
  - `@metamask/delegation-deployments` - Contract deployment addresses
406
406
 
package/dist/index.cjs CHANGED
@@ -251,6 +251,29 @@ function createNonceTerms(terms, encodingOptions = defaultOptions) {
251
251
  return prepareResult(hexValue, encodingOptions);
252
252
  }
253
253
 
254
+ // src/caveats/allowedCalldata.ts
255
+
256
+ function createAllowedCalldataTerms(terms, encodingOptions = defaultOptions) {
257
+ const { startIndex, value } = terms;
258
+ if (startIndex < 0) {
259
+ throw new Error("Invalid startIndex: must be zero or positive");
260
+ }
261
+ if (!Number.isInteger(startIndex)) {
262
+ throw new Error("Invalid startIndex: must be a whole number");
263
+ }
264
+ let unprefixedValue;
265
+ if (typeof value === "string") {
266
+ if (!value.startsWith("0x")) {
267
+ throw new Error("Invalid value: must be a hex string starting with 0x");
268
+ }
269
+ unprefixedValue = _utils.remove0x.call(void 0, value);
270
+ } else {
271
+ unprefixedValue = _utils.remove0x.call(void 0, _utils.bytesToHex.call(void 0, value));
272
+ }
273
+ const indexHex = toHexString({ value: startIndex, size: 32 });
274
+ return prepareResult(`0x${indexHex}${unprefixedValue}`, encodingOptions);
275
+ }
276
+
254
277
  // src/delegation.ts
255
278
  var _abiutils = require('@metamask/abi-utils');
256
279
 
@@ -366,5 +389,6 @@ function getCaveatHash(caveat) {
366
389
 
367
390
 
368
391
 
369
- exports.ANY_BENEFICIARY = ANY_BENEFICIARY; exports.CAVEAT_TYPEHASH = CAVEAT_TYPEHASH; exports.DELEGATION_TYPEHASH = DELEGATION_TYPEHASH; exports.ROOT_AUTHORITY = ROOT_AUTHORITY; exports.createERC20StreamingTerms = createERC20StreamingTerms; exports.createERC20TokenPeriodTransferTerms = createERC20TokenPeriodTransferTerms; exports.createExactCalldataTerms = createExactCalldataTerms; exports.createNativeTokenPeriodTransferTerms = createNativeTokenPeriodTransferTerms; exports.createNativeTokenStreamingTerms = createNativeTokenStreamingTerms; exports.createNonceTerms = createNonceTerms; exports.createTimestampTerms = createTimestampTerms; exports.createValueLteTerms = createValueLteTerms; exports.decodeDelegations = decodeDelegations; exports.encodeDelegations = encodeDelegations; exports.hashDelegation = hashDelegation;
392
+
393
+ exports.ANY_BENEFICIARY = ANY_BENEFICIARY; exports.CAVEAT_TYPEHASH = CAVEAT_TYPEHASH; exports.DELEGATION_TYPEHASH = DELEGATION_TYPEHASH; exports.ROOT_AUTHORITY = ROOT_AUTHORITY; exports.createAllowedCalldataTerms = createAllowedCalldataTerms; exports.createERC20StreamingTerms = createERC20StreamingTerms; exports.createERC20TokenPeriodTransferTerms = createERC20TokenPeriodTransferTerms; exports.createExactCalldataTerms = createExactCalldataTerms; exports.createNativeTokenPeriodTransferTerms = createNativeTokenPeriodTransferTerms; exports.createNativeTokenStreamingTerms = createNativeTokenStreamingTerms; exports.createNonceTerms = createNonceTerms; exports.createTimestampTerms = createTimestampTerms; exports.createValueLteTerms = createValueLteTerms; exports.decodeDelegations = decodeDelegations; exports.encodeDelegations = encodeDelegations; exports.hashDelegation = hashDelegation;
370
394
  //# sourceMappingURL=index.cjs.map
@@ -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;AAC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ACA","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/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/caveats/allowedCalldata.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;AEXpC;AAC1B,EAAA;AACA,EAAA;AAIY;AACoC,EAAA;AAClD;AFUgE;AACA;AGY5C;AACG,EAAA;AAEF,EAAA;AACD,IAAA;AAClB,EAAA;AAC0D,EAAA;AAEpB,EAAA;AACxC;AHZgE;A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ACA;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 { 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 { bytesToHex, remove0x, 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';\nimport { toHexString } from '../utils';\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 * @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 { 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"]}
package/dist/index.d.cts CHANGED
@@ -81,6 +81,13 @@ type NonceTerms = {
81
81
  declare function createNonceTerms(terms: NonceTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
82
82
  declare function createNonceTerms(terms: NonceTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
83
83
 
84
+ type AllowedCalldataTerms = {
85
+ startIndex: number;
86
+ value: BytesLike;
87
+ };
88
+ declare function createAllowedCalldataTerms(terms: AllowedCalldataTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
89
+ declare function createAllowedCalldataTerms(terms: AllowedCalldataTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
90
+
84
91
  declare const ANY_BENEFICIARY = "0x0000000000000000000000000000000000000a11";
85
92
  declare const ROOT_AUTHORITY = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
86
93
  declare const DELEGATION_TYPEHASH = "0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e";
@@ -92,4 +99,4 @@ declare function decodeDelegations(encoded: BytesLike, options: EncodingOptions<
92
99
  declare function hashDelegation(delegation: DelegationStruct, options?: EncodingOptions<'hex'>): Hex;
93
100
  declare function hashDelegation(delegation: DelegationStruct, options: EncodingOptions<'bytes'>): Uint8Array;
94
101
 
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 };
102
+ export { ANY_BENEFICIARY, CAVEAT_TYPEHASH, type CaveatStruct as Caveat, DELEGATION_TYPEHASH, type DelegationStruct as Delegation, ROOT_AUTHORITY, createAllowedCalldataTerms, createERC20StreamingTerms, createERC20TokenPeriodTransferTerms, createExactCalldataTerms, createNativeTokenPeriodTransferTerms, createNativeTokenStreamingTerms, createNonceTerms, createTimestampTerms, createValueLteTerms, decodeDelegations, encodeDelegations, hashDelegation };
package/dist/index.d.ts CHANGED
@@ -81,6 +81,13 @@ type NonceTerms = {
81
81
  declare function createNonceTerms(terms: NonceTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
82
82
  declare function createNonceTerms(terms: NonceTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
83
83
 
84
+ type AllowedCalldataTerms = {
85
+ startIndex: number;
86
+ value: BytesLike;
87
+ };
88
+ declare function createAllowedCalldataTerms(terms: AllowedCalldataTerms, encodingOptions?: EncodingOptions<'hex'>): Hex;
89
+ declare function createAllowedCalldataTerms(terms: AllowedCalldataTerms, encodingOptions: EncodingOptions<'bytes'>): Uint8Array;
90
+
84
91
  declare const ANY_BENEFICIARY = "0x0000000000000000000000000000000000000a11";
85
92
  declare const ROOT_AUTHORITY = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
86
93
  declare const DELEGATION_TYPEHASH = "0x88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e";
@@ -92,4 +99,4 @@ declare function decodeDelegations(encoded: BytesLike, options: EncodingOptions<
92
99
  declare function hashDelegation(delegation: DelegationStruct, options?: EncodingOptions<'hex'>): Hex;
93
100
  declare function hashDelegation(delegation: DelegationStruct, options: EncodingOptions<'bytes'>): Uint8Array;
94
101
 
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 };
102
+ export { ANY_BENEFICIARY, CAVEAT_TYPEHASH, type CaveatStruct as Caveat, DELEGATION_TYPEHASH, type DelegationStruct as Delegation, ROOT_AUTHORITY, createAllowedCalldataTerms, createERC20StreamingTerms, createERC20TokenPeriodTransferTerms, createExactCalldataTerms, createNativeTokenPeriodTransferTerms, createNativeTokenStreamingTerms, createNonceTerms, createTimestampTerms, createValueLteTerms, decodeDelegations, encodeDelegations, hashDelegation };
package/dist/index.mjs CHANGED
@@ -251,6 +251,29 @@ function createNonceTerms(terms, encodingOptions = defaultOptions) {
251
251
  return prepareResult(hexValue, encodingOptions);
252
252
  }
253
253
 
254
+ // src/caveats/allowedCalldata.ts
255
+ import { bytesToHex as bytesToHex4, remove0x } from "@metamask/utils";
256
+ function createAllowedCalldataTerms(terms, encodingOptions = defaultOptions) {
257
+ const { startIndex, value } = terms;
258
+ if (startIndex < 0) {
259
+ throw new Error("Invalid startIndex: must be zero or positive");
260
+ }
261
+ if (!Number.isInteger(startIndex)) {
262
+ throw new Error("Invalid startIndex: must be a whole number");
263
+ }
264
+ let unprefixedValue;
265
+ if (typeof value === "string") {
266
+ if (!value.startsWith("0x")) {
267
+ throw new Error("Invalid value: must be a hex string starting with 0x");
268
+ }
269
+ unprefixedValue = remove0x(value);
270
+ } else {
271
+ unprefixedValue = remove0x(bytesToHex4(value));
272
+ }
273
+ const indexHex = toHexString({ value: startIndex, size: 32 });
274
+ return prepareResult(`0x${indexHex}${unprefixedValue}`, encodingOptions);
275
+ }
276
+
254
277
  // src/delegation.ts
255
278
  import { encode, encodeSingle, decodeSingle } from "@metamask/abi-utils";
256
279
  import { hexToBytes as hexToBytes2 } from "@metamask/utils";
@@ -355,6 +378,7 @@ export {
355
378
  CAVEAT_TYPEHASH,
356
379
  DELEGATION_TYPEHASH,
357
380
  ROOT_AUTHORITY,
381
+ createAllowedCalldataTerms,
358
382
  createERC20StreamingTerms,
359
383
  createERC20TokenPeriodTransferTerms,
360
384
  createExactCalldataTerms,
@@ -1 +1 @@
1
- {"version":3,"sources":["../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"],"sourcesContent":["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"],"mappings":";AAAA,SAAyB,YAAY,kBAAkB;AAyBhD,IAAM,iBAAiB,EAAE,KAAK,MAAM;AAQpC,SAAS,cACd,QACA,SAC0B;AAC1B,MAAI,QAAQ,QAAQ,OAAO;AACzB,UAAM,WAAW,OAAO,WAAW,WAAW,SAAS,WAAW,MAAM;AAExE,WAAO,SAAS,WAAW,IAAI,IAC1B,WACA,KAAK,QAAQ;AAAA,EACpB;AACA,QAAM,aAAa,kBAAkB,aAAa,SAAS,WAAW,MAAM;AAC5E,SAAO;AACT;AAOO,IAAM,iBAAiB,CAAC,cAAyB;AACtD,MAAI,OAAO,cAAc,UAAU;AACjC,WAAO;AAAA,EACT;AACA,SAAO,WAAW,SAAS;AAC7B;AAOO,IAAM,mBAAmB,CAAC,cAAyB;AACxD,MAAI,OAAO,cAAc,UAAU;AACjC,WAAO,WAAW,SAAS;AAAA,EAC7B;AACA,SAAO;AACT;;;ACzDO,IAAM,cAAc,CAAC;AAAA,EAC1B;AAAA,EACA;AACF,MAGc;AACZ,SAAO,MAAM,SAAS,EAAE,EAAE,SAAS,OAAO,GAAG,GAAG;AAClD;;;ACoBO,SAAS,oBACd,OACA,UAAwC,gBACtB;AAClB,QAAM,EAAE,SAAS,IAAI;AA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;AAAA,EACF;AACA,QAAM,OAAO,UAAU,OAAO;AAC9B,SAAO,cAAc,MAAM,OAAO;AACpC;AAUA,SAAS,oBAAoB,SAAqC;AAChE,QAAM,aAAa,KAAK,QAAQ;AAChC,QAAM,UAAU,IAAI,WAAW,UAAU;AAEzC,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,iCAAiC,CAAC,EAAE;AAAA,IACtD;AACA,UAAM,aAAa,cAAc,MAAM;AACvC,YAAQ,IAAI,YAAY,IAAI,EAAE;AAAA,EAChC;AAEA,SAAO,UAAU,OAAO;AAC1B;AAOA,SAAS,cAAc,QAAkC;AACvD,QAAM,aACJ,OAAO,OAAO,UAAU,WAAWC,YAAW,OAAO,KAAK,IAAI,OAAO;AAEvE,QAAM,YAAY,UAAU,UAAU;AAEtC,QAAM,UAAU;AAAA,IACd,CAAC,WAAW,WAAW,SAAS;AAAA,IAChC,CAAC,iBAAiB,OAAO,UAAU,SAAS;AAAA,EAC9C;AACA,QAAM,OAAO,UAAU,OAAO;AAC9B,SAAO;AACT;","names":["TIMESTAMP_UPPER_BOUND_SECONDS","bytesToHex","TIMESTAMP_UPPER_BOUND_SECONDS","bytesToHex","isHexString","bytesToHex","isHexString","bytesToHex","isHexString","isHexString","hexToBytes","hexToBytes"]}
1
+ {"version":3,"sources":["../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/caveats/allowedCalldata.ts","../src/delegation.ts"],"sourcesContent":["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 { bytesToHex, remove0x, 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';\nimport { toHexString } from '../utils';\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 * @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 { 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"],"mappings":";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W,WAAW,SAAS;AAAA,IACjE;AAAA,MACE;AAAA,MACA,WAAW;AAAA,MACX,WAAW;AAAA,MACX,WAAW;AAAA,MACX,oBAAoB,WAAW,OAAO;AAAA,MACtC,WAAW;AAAA,IACb;AAAA,EACF;AACA,QAAM,OAAO,UAAU,OAAO;AAC9B,SAAO,cAAc,MAAM,OAAO;AACpC;AAUA,SAAS,oBAAoB,SAAqC;AAChE,QAAM,aAAa,KAAK,QAAQ;AAChC,QAAM,UAAU,IAAI,WAAW,UAAU;AAEzC,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,iCAAiC,CAAC,EAAE;AAAA,IACtD;AACA,UAAM,aAAa,cAAc,MAAM;AACvC,YAAQ,IAAI,YAAY,IAAI,EAAE;AAAA,EAChC;AAEA,SAAO,UAAU,OAAO;AAC1B;AAOA,SAAS,cAAc,QAAkC;AACvD,QAAM,aACJ,OAAO,OAAO,UAAU,WAAWC,YAAW,OAAO,KAAK,IAAI,OAAO;AAEvE,QAAM,YAAY,UAAU,UAAU;AAEtC,QAAM,UAAU;AAAA,IACd,CAAC,WAAW,WAAW,SAAS;AAAA,IAChC,CAAC,iBAAiB,OAAO,UAAU,SAAS;AAAA,EAC9C;AACA,QAAM,OAAO,UAAU,OAAO;AAC9B,SAAO;AACT;","names":["TIMESTAMP_UPPER_BOUND_SECONDS","bytesToHex","TIMESTAMP_UPPER_BOUND_SECONDS","bytesToHex","isHexString","bytesToHex","isHexString","bytesToHex","isHexString","isHexString","bytesToHex","bytesToHex","hexToBytes","hexToBytes"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/delegation-core",
3
- "version": "0.2.0-rc.1",
3
+ "version": "0.3.0",
4
4
  "description": "Low level core functionality for interacting with the Delegation Framework",
5
5
  "license": "(MIT-0 OR Apache-2.0)",
6
6
  "type": "module",
@@ -8,13 +8,13 @@
8
8
  "MetaMask",
9
9
  "Ethereum"
10
10
  ],
11
- "homepage": "https://github.com/metamask/delegation-toolkit/tree/main/packages/delegation-core#readme",
11
+ "homepage": "https://github.com/metamask/smart-accounts-kit/tree/main/packages/delegation-core#readme",
12
12
  "bugs": {
13
- "url": "https://github.com/metamask/delegation-toolkit/issues"
13
+ "url": "https://github.com/metamask/smart-accounts-kit/issues"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://github.com/metamask/delegation-toolkit.git"
17
+ "url": "https://github.com/metamask/smart-accounts-kit.git"
18
18
  },
19
19
  "author": "MetaMask <hello@metamask.io>",
20
20
  "sideEffects": false,