@metamask/smart-accounts-kit 1.1.0 → 1.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 +19 -1
- package/README.md +34 -2
- package/dist/actions/index.cjs +5 -5
- package/dist/actions/index.d.cts +2 -2
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.mjs +4 -4
- package/dist/{smartAccountsEnvironment-BIcho7e0.d.cts → caveats-CQbtzOKm.d.ts} +9 -2
- package/dist/{smartAccountsEnvironment-Bso0CIWt.d.ts → caveats-Cey0wm33.d.cts} +9 -2
- package/dist/{chunk-YSBBRLMT.mjs → chunk-26PADMXR.mjs} +5 -5
- package/dist/{chunk-BYWRJGSK.cjs → chunk-3PBVHNYP.cjs} +16 -16
- package/dist/{chunk-BYWRJGSK.cjs.map → chunk-3PBVHNYP.cjs.map} +1 -1
- package/dist/{chunk-TPBFVDVM.mjs → chunk-4QXIOE7F.mjs} +8 -6
- package/dist/chunk-4QXIOE7F.mjs.map +1 -0
- package/dist/{chunk-F2RG26RH.cjs → chunk-57I2FJY7.cjs} +105 -105
- package/dist/{chunk-F2RG26RH.cjs.map → chunk-57I2FJY7.cjs.map} +1 -1
- package/dist/{chunk-YTELOQ4I.mjs → chunk-AC2BQSYP.mjs} +2 -2
- package/dist/{chunk-QMRKCB7T.cjs → chunk-AJWMPR7X.cjs} +146 -48
- package/dist/chunk-AJWMPR7X.cjs.map +1 -0
- package/dist/{chunk-23YXLKTX.cjs → chunk-DLCTHNAE.cjs} +14 -14
- package/dist/{chunk-23YXLKTX.cjs.map → chunk-DLCTHNAE.cjs.map} +1 -1
- package/dist/{chunk-NOCLGZGB.mjs → chunk-FKI4OME5.mjs} +109 -11
- package/dist/chunk-FKI4OME5.mjs.map +1 -0
- package/dist/{chunk-UUOH2WAW.cjs → chunk-GZ7HHI2D.cjs} +12 -12
- package/dist/{chunk-UUOH2WAW.cjs.map → chunk-GZ7HHI2D.cjs.map} +1 -1
- package/dist/{chunk-WV2R7BXP.mjs → chunk-KBSFVKUB.mjs} +3 -3
- package/dist/{chunk-45GHWVQA.mjs → chunk-LQXOM3TA.mjs} +4 -4
- package/dist/{chunk-VLKX4BR6.cjs → chunk-MOHCTPYQ.cjs} +8 -6
- package/dist/chunk-MOHCTPYQ.cjs.map +1 -0
- package/dist/{chunk-YDLLC6PP.cjs → chunk-SZOX7K2V.cjs} +519 -16
- package/dist/chunk-SZOX7K2V.cjs.map +1 -0
- package/dist/{chunk-C5ZEEH2Z.mjs → chunk-Z4D7ZWVB.mjs} +517 -14
- package/dist/chunk-Z4D7ZWVB.mjs.map +1 -0
- package/dist/contracts/index.cjs +6 -6
- package/dist/contracts/index.d.cts +2 -2
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.mjs +5 -5
- package/dist/{delegation-DgmIOh21.d.ts → delegation-Bx4FEAIU.d.ts} +1 -1
- package/dist/{delegation-Ci3me5Rg.d.cts → delegation-KbWHzRxV.d.cts} +1 -1
- package/dist/experimental/index.cjs +36 -4
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/index.d.cts +4 -1
- package/dist/experimental/index.d.ts +4 -1
- package/dist/experimental/index.mjs +35 -3
- package/dist/experimental/index.mjs.map +1 -1
- package/dist/{index-Uj_xXVko.d.cts → index-BDC55AA9.d.cts} +5 -3
- package/dist/{index-UF6eCzBC.d.ts → index-D2THBlfm.d.ts} +1 -1
- package/dist/{index-CSjEW7MJ.d.cts → index-DE87r5KY.d.cts} +1 -1
- package/dist/{index-D7fBuNV-.d.ts → index-DhG2lH80.d.ts} +5 -3
- package/dist/index.cjs +33 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -11
- package/dist/index.d.ts +9 -11
- package/dist/index.mjs +24 -8
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.cjs +7 -5
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.mjs +6 -4
- package/package.json +5 -4
- package/dist/chunk-C5ZEEH2Z.mjs.map +0 -1
- package/dist/chunk-NOCLGZGB.mjs.map +0 -1
- package/dist/chunk-QMRKCB7T.cjs.map +0 -1
- package/dist/chunk-TPBFVDVM.mjs.map +0 -1
- package/dist/chunk-VLKX4BR6.cjs.map +0 -1
- package/dist/chunk-YDLLC6PP.cjs.map +0 -1
- /package/dist/{chunk-YSBBRLMT.mjs.map → chunk-26PADMXR.mjs.map} +0 -0
- /package/dist/{chunk-YTELOQ4I.mjs.map → chunk-AC2BQSYP.mjs.map} +0 -0
- /package/dist/{chunk-WV2R7BXP.mjs.map → chunk-KBSFVKUB.mjs.map} +0 -0
- /package/dist/{chunk-45GHWVQA.mjs.map → chunk-LQXOM3TA.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- feat: add redeemer rule ([#212](https://github.com/metamask/smart-accounts-kit/pull/212))
|
|
15
|
+
- Optional `redeemer` on `PermissionRequestParameter` maps to a `redeemer` execution rule; granted permission responses checksum-normalize redeemer addresses in `rules`.
|
|
16
|
+
|
|
17
|
+
## [1.2.0]
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- `decodeCaveat` util function ([#191](https://github.com/metamask/smart-accounts-kit/pull/191))
|
|
22
|
+
- Chain deployment for Katana mainnet and Katana Bokuto ([#203](https://github.com/MetaMask/smart-accounts-kit/pull/203))
|
|
23
|
+
- Anonymous usage statistics to help improve the SDK ([#185](https://github.com/metamask/smart-accounts-kit/pull/185))
|
|
24
|
+
- Opt out by setting environment variables `CI` or `DO_NOT_TRACK`, or `navigator.doNotTrack` or `window.doNotTrack` to either '1', 'true', or 'yes'
|
|
25
|
+
|
|
10
26
|
## [1.1.0]
|
|
11
27
|
|
|
12
28
|
### Added
|
|
@@ -105,7 +121,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
105
121
|
|
|
106
122
|
- Promote readable permissions actions (`requestExecutionPermissions`, `sendTransactionWithDelegation`, and `sendUserOperationWithDelegation`) from experimental ([#91](https://github.com/MetaMask/smart-accounts-kit/pull/91))
|
|
107
123
|
|
|
108
|
-
[Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.
|
|
124
|
+
[Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.3.0...HEAD
|
|
125
|
+
[1.3.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.2.0...@metamask/smart-accounts-kit@1.3.0
|
|
126
|
+
[1.2.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.1.0...@metamask/smart-accounts-kit@1.2.0
|
|
109
127
|
[1.1.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.0.0...@metamask/smart-accounts-kit@1.1.0
|
|
110
128
|
[1.0.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.4.0-beta.2...@metamask/smart-accounts-kit@1.0.0
|
|
111
129
|
[0.4.0-beta.2]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.4.0-beta.1...@metamask/smart-accounts-kit@0.4.0-beta.2
|
package/README.md
CHANGED
|
@@ -19,15 +19,17 @@ The MetaMask Smart Accounts Kit is a [Viem](https://viem.sh)-based collection of
|
|
|
19
19
|
Yarn:
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
yarn add @metamask/smart-accounts-kit
|
|
22
|
+
yarn add @metamask/smart-accounts-kit viem
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Npm:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
|
-
npm install @metamask/smart-accounts-kit
|
|
28
|
+
npm install @metamask/smart-accounts-kit viem
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
`viem` is a peer dependency; install a compatible version alongside the kit.
|
|
32
|
+
|
|
31
33
|
## Overview
|
|
32
34
|
|
|
33
35
|
---
|
|
@@ -63,6 +65,36 @@ const smartAccount = await toMetaMaskSmartAccount({
|
|
|
63
65
|
|
|
64
66
|
[Head to our documentation](https://docs.gator.metamask.io) to learn more about the MetaMask Smart Accounts Kit.
|
|
65
67
|
|
|
68
|
+
## Analytics
|
|
69
|
+
|
|
70
|
+
This package collects anonymous usage analytics to help us understand how it's being used and prioritize improvements. No personal information is collected. **[Analytics can be disabled](#disabling-analytics)**.
|
|
71
|
+
|
|
72
|
+
### What's collected
|
|
73
|
+
|
|
74
|
+
Two event types are sent (namespace `metamask/smart-accounts-kit`): a one-time **initialized** event when the first instrumented API runs (just before the first **function called** event), and **function called** events when those APIs run afterward. Both include a small **session base**; function events add which API was used and optional **parameters**.
|
|
75
|
+
|
|
76
|
+
- **`sdk_version`** — Kit version.
|
|
77
|
+
- **`anon_id`** — Random id regenerated on each SDK initialization for correlating events within that session. It is not derived from wallet or personal data, is not written to local storage or cookies for tracking purposes, and is not used to identify or track a user across sites or apps.
|
|
78
|
+
- **`platform`** — Coarse runtime (`web-desktop`, `web-mobile`, or `nodejs`).
|
|
79
|
+
- **`domain`** *(web only, when available)* — Current page hostname.
|
|
80
|
+
|
|
81
|
+
- **`function_name`** — Stable internal name of the API that was called.
|
|
82
|
+
- **`parameters`** *(optional)* — Only coarse, non-identifying data: things like numeric **chain id**, **counts** (e.g. calls, caveats, signatures), **booleans** (whether optional inputs were present), **implementation or scope _type_** from fixed enums, and **high-level labels** (e.g. which known delegation-storage tier or filter mode). No raw addresses, hashes, calldata, keys, or permission payloads.
|
|
83
|
+
|
|
84
|
+
### What's NOT collected
|
|
85
|
+
|
|
86
|
+
- **Secrets and credentials** — Private keys, API keys, bearer tokens, RPC or bundler URLs, and similar.
|
|
87
|
+
- **On-chain identifiers and payloads** — Account or contract addresses, transaction `to` / `data` / `value`, user operation calldata, delegation bodies, delegation hashes, permission request or response payloads, and signature bytes.
|
|
88
|
+
- **Personal information** — No names, emails, or other PII is sent as part of this analytics design.
|
|
89
|
+
|
|
90
|
+
### Disabling analytics
|
|
91
|
+
|
|
92
|
+
Analytics is not initialized when any of the following is set to: `1`, or `yes` / `true` (case-insensitive):
|
|
93
|
+
|
|
94
|
+
- **`CI`** environment variable (Node.js)
|
|
95
|
+
- **`DO_NOT_TRACK`** environment variable (Node.js)
|
|
96
|
+
- **`navigator.doNotTrack`** or **`window.doNotTrack`** (in browsers).
|
|
97
|
+
|
|
66
98
|
## Contributing
|
|
67
99
|
|
|
68
100
|
---
|
package/dist/actions/index.cjs
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
20
|
-
require('../chunk-
|
|
19
|
+
var _chunkAJWMPR7Xcjs = require('../chunk-AJWMPR7X.cjs');
|
|
20
|
+
require('../chunk-GZ7HHI2D.cjs');
|
|
21
21
|
require('../chunk-SOFB2MXG.cjs');
|
|
22
|
-
require('../chunk-
|
|
23
|
-
require('../chunk-
|
|
22
|
+
require('../chunk-MOHCTPYQ.cjs');
|
|
23
|
+
require('../chunk-SZOX7K2V.cjs');
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
@@ -39,5 +39,5 @@ require('../chunk-YDLLC6PP.cjs');
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
exports.caveatEnforcerActions =
|
|
42
|
+
exports.caveatEnforcerActions = _chunkAJWMPR7Xcjs.caveatEnforcerActions; exports.erc7710BundlerActions = _chunkAJWMPR7Xcjs.erc7710BundlerActions; exports.erc7710WalletActions = _chunkAJWMPR7Xcjs.erc7710WalletActions; exports.erc7715ProviderActions = _chunkAJWMPR7Xcjs.erc7715ProviderActions; exports.getErc20PeriodTransferEnforcerAvailableAmount = _chunkAJWMPR7Xcjs.getErc20PeriodTransferEnforcerAvailableAmount; exports.getErc20StreamingEnforcerAvailableAmount = _chunkAJWMPR7Xcjs.getErc20StreamingEnforcerAvailableAmount; exports.getGrantedExecutionPermissions = _chunkAJWMPR7Xcjs.erc7715GetGrantedExecutionPermissionsAction; exports.getMultiTokenPeriodEnforcerAvailableAmount = _chunkAJWMPR7Xcjs.getMultiTokenPeriodEnforcerAvailableAmount; exports.getNativeTokenPeriodTransferEnforcerAvailableAmount = _chunkAJWMPR7Xcjs.getNativeTokenPeriodTransferEnforcerAvailableAmount; exports.getNativeTokenStreamingEnforcerAvailableAmount = _chunkAJWMPR7Xcjs.getNativeTokenStreamingEnforcerAvailableAmount; exports.getSupportedExecutionPermissions = _chunkAJWMPR7Xcjs.erc7715GetSupportedExecutionPermissionsAction; exports.isValid7702Implementation = _chunkAJWMPR7Xcjs.isValid7702Implementation; exports.requestExecutionPermissions = _chunkAJWMPR7Xcjs.erc7715RequestExecutionPermissionsAction; exports.signDelegation = _chunkAJWMPR7Xcjs.signDelegation; exports.signDelegationActions = _chunkAJWMPR7Xcjs.signDelegationActions; exports.signUserOperation = _chunkAJWMPR7Xcjs.signUserOperation; exports.signUserOperationActions = _chunkAJWMPR7Xcjs.signUserOperationActions;
|
|
43
43
|
//# sourceMappingURL=index.cjs.map
|
package/dist/actions/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CaveatEnforcerParams, D as DelegatedCall, E as Erc20TokenPeriodicPermission, a as Erc20TokenRevocationPermission, b as Erc20TokenStreamPermission, d as Erc7715Client, G as GetGrantedExecutionPermissionsResult, e as GetSupportedExecutionPermissionsResult, M as MetaMaskExtensionClient, f as MetaMaskExtensionSchema, N as NativeTokenPeriodicPermission, g as NativeTokenStreamPermission, P as PeriodTransferResult, h as PermissionRequestParameter, j as PermissionTypes, R as RequestExecutionPermissionsParameters, k as RequestExecutionPermissionsReturnType, l as RpcGetGrantedExecutionPermissionsResult, m as RpcGetSupportedExecutionPermissionsResult, n as RpcSupportedPermissionInfo, S as SignDelegationParameters, o as SignDelegationReturnType, p as SignUserOperationParameters, q as SignUserOperationReturnType, r as StreamingResult, s as SupportedPermissionInfo, c as caveatEnforcerActions, t as erc7710BundlerActions, u as erc7710WalletActions, v as erc7715ProviderActions, w as getErc20PeriodTransferEnforcerAvailableAmount, x as getErc20StreamingEnforcerAvailableAmount, y as getGrantedExecutionPermissions, z as getMultiTokenPeriodEnforcerAvailableAmount, A as getNativeTokenPeriodTransferEnforcerAvailableAmount, B as getNativeTokenStreamingEnforcerAvailableAmount, F as getSupportedExecutionPermissions, H as isValid7702Implementation, I as requestExecutionPermissions, J as signDelegation, K as signDelegationActions, L as signUserOperation, O as signUserOperationActions } from '../index-
|
|
1
|
+
export { C as CaveatEnforcerParams, D as DelegatedCall, E as Erc20TokenPeriodicPermission, a as Erc20TokenRevocationPermission, b as Erc20TokenStreamPermission, d as Erc7715Client, G as GetGrantedExecutionPermissionsResult, e as GetSupportedExecutionPermissionsResult, M as MetaMaskExtensionClient, f as MetaMaskExtensionSchema, N as NativeTokenPeriodicPermission, g as NativeTokenStreamPermission, P as PeriodTransferResult, h as PermissionRequestParameter, j as PermissionTypes, R as RequestExecutionPermissionsParameters, k as RequestExecutionPermissionsReturnType, l as RpcGetGrantedExecutionPermissionsResult, m as RpcGetSupportedExecutionPermissionsResult, n as RpcSupportedPermissionInfo, S as SignDelegationParameters, o as SignDelegationReturnType, p as SignUserOperationParameters, q as SignUserOperationReturnType, r as StreamingResult, s as SupportedPermissionInfo, c as caveatEnforcerActions, t as erc7710BundlerActions, u as erc7710WalletActions, v as erc7715ProviderActions, w as getErc20PeriodTransferEnforcerAvailableAmount, x as getErc20StreamingEnforcerAvailableAmount, y as getGrantedExecutionPermissions, z as getMultiTokenPeriodEnforcerAvailableAmount, A as getNativeTokenPeriodTransferEnforcerAvailableAmount, B as getNativeTokenStreamingEnforcerAvailableAmount, F as getSupportedExecutionPermissions, H as isValid7702Implementation, I as requestExecutionPermissions, J as signDelegation, K as signDelegationActions, L as signUserOperation, O as signUserOperationActions } from '../index-BDC55AA9.cjs';
|
|
2
2
|
import 'viem';
|
|
3
|
-
|
|
3
|
+
export { Rule } from '@metamask/7715-permission-types';
|
|
4
4
|
import 'viem/account-abstraction';
|
|
5
5
|
import '../types-BWaH4KH1.cjs';
|
|
6
6
|
import '@metamask/delegation-abis';
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CaveatEnforcerParams, D as DelegatedCall, E as Erc20TokenPeriodicPermission, a as Erc20TokenRevocationPermission, b as Erc20TokenStreamPermission, d as Erc7715Client, G as GetGrantedExecutionPermissionsResult, e as GetSupportedExecutionPermissionsResult, M as MetaMaskExtensionClient, f as MetaMaskExtensionSchema, N as NativeTokenPeriodicPermission, g as NativeTokenStreamPermission, P as PeriodTransferResult, h as PermissionRequestParameter, j as PermissionTypes, R as RequestExecutionPermissionsParameters, k as RequestExecutionPermissionsReturnType, l as RpcGetGrantedExecutionPermissionsResult, m as RpcGetSupportedExecutionPermissionsResult, n as RpcSupportedPermissionInfo, S as SignDelegationParameters, o as SignDelegationReturnType, p as SignUserOperationParameters, q as SignUserOperationReturnType, r as StreamingResult, s as SupportedPermissionInfo, c as caveatEnforcerActions, t as erc7710BundlerActions, u as erc7710WalletActions, v as erc7715ProviderActions, w as getErc20PeriodTransferEnforcerAvailableAmount, x as getErc20StreamingEnforcerAvailableAmount, y as getGrantedExecutionPermissions, z as getMultiTokenPeriodEnforcerAvailableAmount, A as getNativeTokenPeriodTransferEnforcerAvailableAmount, B as getNativeTokenStreamingEnforcerAvailableAmount, F as getSupportedExecutionPermissions, H as isValid7702Implementation, I as requestExecutionPermissions, J as signDelegation, K as signDelegationActions, L as signUserOperation, O as signUserOperationActions } from '../index-
|
|
1
|
+
export { C as CaveatEnforcerParams, D as DelegatedCall, E as Erc20TokenPeriodicPermission, a as Erc20TokenRevocationPermission, b as Erc20TokenStreamPermission, d as Erc7715Client, G as GetGrantedExecutionPermissionsResult, e as GetSupportedExecutionPermissionsResult, M as MetaMaskExtensionClient, f as MetaMaskExtensionSchema, N as NativeTokenPeriodicPermission, g as NativeTokenStreamPermission, P as PeriodTransferResult, h as PermissionRequestParameter, j as PermissionTypes, R as RequestExecutionPermissionsParameters, k as RequestExecutionPermissionsReturnType, l as RpcGetGrantedExecutionPermissionsResult, m as RpcGetSupportedExecutionPermissionsResult, n as RpcSupportedPermissionInfo, S as SignDelegationParameters, o as SignDelegationReturnType, p as SignUserOperationParameters, q as SignUserOperationReturnType, r as StreamingResult, s as SupportedPermissionInfo, c as caveatEnforcerActions, t as erc7710BundlerActions, u as erc7710WalletActions, v as erc7715ProviderActions, w as getErc20PeriodTransferEnforcerAvailableAmount, x as getErc20StreamingEnforcerAvailableAmount, y as getGrantedExecutionPermissions, z as getMultiTokenPeriodEnforcerAvailableAmount, A as getNativeTokenPeriodTransferEnforcerAvailableAmount, B as getNativeTokenStreamingEnforcerAvailableAmount, F as getSupportedExecutionPermissions, H as isValid7702Implementation, I as requestExecutionPermissions, J as signDelegation, K as signDelegationActions, L as signUserOperation, O as signUserOperationActions } from '../index-DhG2lH80.js';
|
|
2
2
|
import 'viem';
|
|
3
|
-
|
|
3
|
+
export { Rule } from '@metamask/7715-permission-types';
|
|
4
4
|
import 'viem/account-abstraction';
|
|
5
5
|
import '../types-BWaH4KH1.js';
|
|
6
6
|
import '@metamask/delegation-abis';
|
package/dist/actions/index.mjs
CHANGED
|
@@ -16,11 +16,11 @@ import {
|
|
|
16
16
|
signDelegationActions,
|
|
17
17
|
signUserOperation,
|
|
18
18
|
signUserOperationActions
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
19
|
+
} from "../chunk-FKI4OME5.mjs";
|
|
20
|
+
import "../chunk-AC2BQSYP.mjs";
|
|
21
21
|
import "../chunk-QCULIK3O.mjs";
|
|
22
|
-
import "../chunk-
|
|
23
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-4QXIOE7F.mjs";
|
|
23
|
+
import "../chunk-Z4D7ZWVB.mjs";
|
|
24
24
|
export {
|
|
25
25
|
caveatEnforcerActions,
|
|
26
26
|
erc7710BundlerActions,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Chain, Hex } from 'viem';
|
|
2
|
-
import { S as SmartAccountsEnvironment } from './types-BWaH4KH1.
|
|
2
|
+
import { S as SmartAccountsEnvironment, C as Caveat } from './types-BWaH4KH1.js';
|
|
3
|
+
import { A as CoreCaveatConfiguration } from './delegation-Bx4FEAIU.js';
|
|
3
4
|
|
|
4
5
|
type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
|
|
5
6
|
declare const PREFERRED_VERSION: SupportedVersion;
|
|
@@ -9,4 +10,10 @@ declare function deploySmartAccountsEnvironment(walletClient: WalletClient, publ
|
|
|
9
10
|
[contract: string]: Hex;
|
|
10
11
|
}): Promise<SmartAccountsEnvironment>;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
declare const createCaveat: (enforcer: Hex, terms: Hex, args?: Hex) => Caveat;
|
|
14
|
+
declare const decodeCaveat: ({ caveat: { enforcer, terms }, environment: { caveatEnforcers }, }: {
|
|
15
|
+
caveat: Caveat;
|
|
16
|
+
environment: SmartAccountsEnvironment;
|
|
17
|
+
}) => CoreCaveatConfiguration;
|
|
18
|
+
|
|
19
|
+
export { PREFERRED_VERSION as P, deploySmartAccountsEnvironment as a, createCaveat as c, decodeCaveat as d, getSmartAccountsEnvironment as g, overrideDeployedEnvironment as o };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Chain, Hex } from 'viem';
|
|
2
|
-
import { S as SmartAccountsEnvironment } from './types-BWaH4KH1.
|
|
2
|
+
import { S as SmartAccountsEnvironment, C as Caveat } from './types-BWaH4KH1.cjs';
|
|
3
|
+
import { A as CoreCaveatConfiguration } from './delegation-KbWHzRxV.cjs';
|
|
3
4
|
|
|
4
5
|
type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
|
|
5
6
|
declare const PREFERRED_VERSION: SupportedVersion;
|
|
@@ -9,4 +10,10 @@ declare function deploySmartAccountsEnvironment(walletClient: WalletClient, publ
|
|
|
9
10
|
[contract: string]: Hex;
|
|
10
11
|
}): Promise<SmartAccountsEnvironment>;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
declare const createCaveat: (enforcer: Hex, terms: Hex, args?: Hex) => Caveat;
|
|
14
|
+
declare const decodeCaveat: ({ caveat: { enforcer, terms }, environment: { caveatEnforcers }, }: {
|
|
15
|
+
caveat: Caveat;
|
|
16
|
+
environment: SmartAccountsEnvironment;
|
|
17
|
+
}) => CoreCaveatConfiguration;
|
|
18
|
+
|
|
19
|
+
export { PREFERRED_VERSION as P, deploySmartAccountsEnvironment as a, createCaveat as c, decodeCaveat as d, getSmartAccountsEnvironment as g, overrideDeployedEnvironment as o };
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MultiTokenPeriodEnforcer_exports,
|
|
5
5
|
NativeTokenPeriodTransferEnforcer_exports,
|
|
6
6
|
NativeTokenStreamingEnforcer_exports
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AC2BQSYP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
encodeProxyCreationCode,
|
|
10
10
|
encode_exports,
|
|
@@ -38,17 +38,17 @@ import {
|
|
|
38
38
|
simulate7,
|
|
39
39
|
simulate8,
|
|
40
40
|
simulate9
|
|
41
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-KBSFVKUB.mjs";
|
|
42
42
|
import {
|
|
43
43
|
encodeExecutionCalldatas
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-4QXIOE7F.mjs";
|
|
45
45
|
import {
|
|
46
46
|
ANY_BENEFICIARY,
|
|
47
47
|
ROOT_AUTHORITY,
|
|
48
48
|
__export,
|
|
49
49
|
encodeDelegations,
|
|
50
50
|
toDelegationStruct
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-Z4D7ZWVB.mjs";
|
|
52
52
|
|
|
53
53
|
// src/contracts/index.ts
|
|
54
54
|
var contracts_exports = {};
|
|
@@ -1318,4 +1318,4 @@ export {
|
|
|
1318
1318
|
SpecificActionERC20TransferBatchEnforcer_exports,
|
|
1319
1319
|
contracts_exports
|
|
1320
1320
|
};
|
|
1321
|
-
//# sourceMappingURL=chunk-
|
|
1321
|
+
//# sourceMappingURL=chunk-26PADMXR.mjs.map
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkDLCTHNAEcjs = require('./chunk-DLCTHNAE.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkMOHCTPYQcjs = require('./chunk-MOHCTPYQ.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkSZOX7K2Vcjs = require('./chunk-SZOX7K2V.cjs');
|
|
16
16
|
|
|
17
17
|
// src/counterfactualAccountData.ts
|
|
18
18
|
var _viem = require('viem');
|
|
@@ -48,7 +48,7 @@ var getCounterfactualAccountData = async ({
|
|
|
48
48
|
y: yValue
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
|
-
initcode =
|
|
51
|
+
initcode = _chunkDLCTHNAEcjs.encode.call(void 0, { eoaOwner: owner, p256Owners });
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
54
|
case "MultiSig" /* MultiSig */: {
|
|
@@ -59,7 +59,7 @@ var getCounterfactualAccountData = async ({
|
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
implementationAddress = implementations.MultiSigDeleGatorImpl;
|
|
62
|
-
initcode =
|
|
62
|
+
initcode = _chunkDLCTHNAEcjs.encode2.call(void 0, { owners, threshold });
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
65
|
case "Stateless7702" /* Stateless7702 */:
|
|
@@ -67,7 +67,7 @@ var getCounterfactualAccountData = async ({
|
|
|
67
67
|
throw new Error(`Implementation type '${implementation}' not supported`);
|
|
68
68
|
}
|
|
69
69
|
const salt = _viem.pad.call(void 0, deploySalt, { dir: "left", size: 32 });
|
|
70
|
-
const proxyCreationCode =
|
|
70
|
+
const proxyCreationCode = _chunkDLCTHNAEcjs.encodeProxyCreationCode.call(void 0, {
|
|
71
71
|
implementationAddress,
|
|
72
72
|
initcode
|
|
73
73
|
});
|
|
@@ -77,7 +77,7 @@ var getCounterfactualAccountData = async ({
|
|
|
77
77
|
opcode: "CREATE2",
|
|
78
78
|
salt
|
|
79
79
|
});
|
|
80
|
-
const factoryData =
|
|
80
|
+
const factoryData = _chunkDLCTHNAEcjs.encode3.call(void 0, proxyCreationCode, salt);
|
|
81
81
|
return {
|
|
82
82
|
factoryData,
|
|
83
83
|
address
|
|
@@ -98,21 +98,21 @@ var processDelegatedCall = (call) => {
|
|
|
98
98
|
value,
|
|
99
99
|
data: callData
|
|
100
100
|
} = call;
|
|
101
|
-
const callAsExecution =
|
|
101
|
+
const callAsExecution = _chunkMOHCTPYQcjs.createExecution.call(void 0, { target, value, callData });
|
|
102
102
|
if (!permissionContext) {
|
|
103
103
|
return callAsExecution;
|
|
104
104
|
}
|
|
105
|
-
const encodedPermissionsContext =
|
|
105
|
+
const encodedPermissionsContext = _chunkSZOX7K2Vcjs.encodeDelegations.call(void 0, permissionContext);
|
|
106
106
|
const redeemCalldata = _viem.encodeFunctionData.call(void 0, {
|
|
107
107
|
abi: _delegationabis.DelegationManager,
|
|
108
108
|
functionName: "redeemDelegations",
|
|
109
109
|
args: [
|
|
110
110
|
[encodedPermissionsContext],
|
|
111
111
|
["0x0000000000000000000000000000000000000000000000000000000000000000" /* SingleDefault */],
|
|
112
|
-
|
|
112
|
+
_chunkMOHCTPYQcjs.encodeExecutionCalldatas.call(void 0, [[callAsExecution]])
|
|
113
113
|
]
|
|
114
114
|
});
|
|
115
|
-
return
|
|
115
|
+
return _chunkMOHCTPYQcjs.createExecution.call(void 0, {
|
|
116
116
|
target: delegationManager,
|
|
117
117
|
callData: redeemCalldata
|
|
118
118
|
});
|
|
@@ -122,8 +122,8 @@ var encodeCalls = (calls) => {
|
|
|
122
122
|
const call = calls[0];
|
|
123
123
|
if (call && !isDelegatedCall(call)) {
|
|
124
124
|
const { to: target, value, data: callData } = call;
|
|
125
|
-
const execution =
|
|
126
|
-
return
|
|
125
|
+
const execution = _chunkMOHCTPYQcjs.createExecution.call(void 0, { target, value, callData });
|
|
126
|
+
return _chunkDLCTHNAEcjs.encode4.call(void 0, { execution });
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
const executions = calls.map((call) => {
|
|
@@ -131,10 +131,10 @@ var encodeCalls = (calls) => {
|
|
|
131
131
|
return processDelegatedCall(call);
|
|
132
132
|
}
|
|
133
133
|
const { to: target, value, data: callData } = call;
|
|
134
|
-
return
|
|
134
|
+
return _chunkMOHCTPYQcjs.createExecution.call(void 0, { target, value, callData });
|
|
135
135
|
});
|
|
136
136
|
const mode = calls.length === 1 ? "0x0000000000000000000000000000000000000000000000000000000000000000" /* SingleDefault */ : "0x0100000000000000000000000000000000000000000000000000000000000000" /* BatchDefault */;
|
|
137
|
-
return
|
|
137
|
+
return _chunkDLCTHNAEcjs.encode5.call(void 0, { mode, executions });
|
|
138
138
|
};
|
|
139
139
|
var encodeCallsForCaller = async (caller, calls) => {
|
|
140
140
|
if (calls.length === 1) {
|
|
@@ -255,4 +255,4 @@ var createDummyWebAuthnSignature = (keyId) => {
|
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
exports.getCounterfactualAccountData = getCounterfactualAccountData; exports.encodeCalls = encodeCalls; exports.encodeCallsForCaller = encodeCallsForCaller; exports.SIGNATURE_ABI_PARAMS = SIGNATURE_ABI_PARAMS; exports.encodeDeleGatorSignature = encodeDeleGatorSignature; exports.createDummyWebAuthnSignature = createDummyWebAuthnSignature;
|
|
258
|
-
//# sourceMappingURL=chunk-
|
|
258
|
+
//# sourceMappingURL=chunk-3PBVHNYP.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-BYWRJGSK.cjs","../src/counterfactualAccountData.ts","../src/encodeCalls.ts","../src/webAuthn.ts"],"names":[],"mappings":"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","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-BYWRJGSK.cjs","sourcesContent":[null,"import type { Address, Hex } from 'viem';\nimport { getContractAddress, pad } from 'viem';\n\nimport { Implementation } from './constants';\nimport { initializeHybridDeleGator } from './DelegationFramework/HybridDeleGator/encode';\nimport { initializeMultiSigDeleGator } from './DelegationFramework/MultiSigDeleGator/encode';\nimport { create2Deploy as encodeCreate2Deploy } from './DelegationFramework/SimpleFactory/encode';\nimport { encodeProxyCreationCode } from './DelegationFramework/utils';\nimport type {\n SmartAccountsEnvironment,\n HybridDeleGatorDeployParams,\n MultiSigDeleGatorDeployParams,\n DeployParams,\n} from './types';\n\n/**\n * Infers counterfactual account data for a DeleGator smart account.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @template TDeployParams - The type of deployment parameters, defaults to DeployParams<Implementation>.\n * @param options - The options for generating counterfactual account data.\n * @param options.factory - The address of the SimpleFactory contract.\n * @param options.implementations - The DeleGator implementation contracts.\n * @param options.implementation - The implementation type to use.\n * @param options.deployParams - The deployment parameters for the specified implementation.\n * @param options.deploySalt - The salt to use for CREATE2 address computation.\n * @returns An object containing the counterfactual address and factory calldata.\n * @description This function calculates the address a DeleGator contract would have if deployed,\n * and provides the calldata needed to deploy it.\n */\nexport const getCounterfactualAccountData = async <\n TImplementation extends Implementation,\n>({\n factory,\n implementations,\n implementation,\n deployParams,\n deploySalt,\n}: {\n factory: Address;\n implementations: SmartAccountsEnvironment['implementations'];\n implementation: TImplementation;\n deployParams: DeployParams<TImplementation>;\n deploySalt: Hex;\n}): Promise<{ factoryData: Hex; address: Address }> => {\n let implementationAddress: Address;\n let initcode: Hex;\n\n switch (implementation) {\n case Implementation.Hybrid: {\n const [owner, keyIds, xValues, yValues] =\n deployParams as HybridDeleGatorDeployParams;\n\n if (!implementations.HybridDeleGatorImpl) {\n throw new Error(\n 'HybridDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.HybridDeleGatorImpl;\n\n const p256Owners = keyIds.map((keyId, index) => {\n const xValue = xValues[index];\n const yValue = yValues[index];\n\n if (!xValue || !yValue) {\n throw new Error(\n `Missing X or Y value for keyId ${keyId} at index ${index}`,\n );\n }\n\n return {\n keyId,\n x: xValue,\n y: yValue,\n };\n });\n\n initcode = initializeHybridDeleGator({ eoaOwner: owner, p256Owners });\n break;\n }\n case Implementation.MultiSig: {\n const [owners, threshold] = deployParams as MultiSigDeleGatorDeployParams;\n\n if (!implementations.MultiSigDeleGatorImpl) {\n throw new Error(\n 'MultiSigDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.MultiSigDeleGatorImpl;\n initcode = initializeMultiSigDeleGator({ owners, threshold });\n break;\n }\n case Implementation.Stateless7702:\n default:\n throw new Error(`Implementation type '${implementation}' not supported`);\n }\n\n const salt = pad(deploySalt, { dir: 'left', size: 32 });\n\n const proxyCreationCode = encodeProxyCreationCode({\n implementationAddress,\n initcode,\n });\n\n const address = getContractAddress({\n bytecode: proxyCreationCode,\n from: factory,\n opcode: 'CREATE2',\n salt,\n });\n\n const factoryData = encodeCreate2Deploy(proxyCreationCode, salt);\n\n return {\n factoryData,\n address,\n };\n};\n","import { DelegationManager } from '@metamask/delegation-abis';\nimport { encodeFunctionData } from 'viem';\nimport type { Address, Hex } from 'viem';\n\nimport type { DelegatedCall } from './actions/erc7710RedeemDelegationAction';\nimport { encodeDelegations } from './delegation';\nimport {\n execute,\n executeWithMode,\n} from './DelegationFramework/DeleGatorCore/encode';\nimport {\n ExecutionMode,\n createExecution,\n encodeExecutionCalldatas,\n} from './executions';\nimport type { Call } from './types';\n\n/**\n * Checks if a call is a delegated call by checking for the presence of permissionContext and delegationManager.\n *\n * @param call - The call to check.\n * @returns True if the call is a delegated call, false otherwise.\n */\nconst isDelegatedCall = (call: Call): call is DelegatedCall => {\n return 'permissionContext' in call && 'delegationManager' in call;\n};\n\n/**\n * If there's a single call with permissionContext and delegationManager,\n * processes it as a delegated call.\n *\n * @param call - The call to process.\n * @returns The execution object for the delegated call.\n * @description\n * This function creates an execution that calls redeemDelegations on the delegation manager.\n */\nconst processDelegatedCall = (call: DelegatedCall) => {\n const {\n permissionContext,\n delegationManager,\n to: target,\n value,\n data: callData,\n } = call;\n\n const callAsExecution = createExecution({ target, value, callData });\n\n if (!permissionContext) {\n return callAsExecution;\n }\n\n const encodedPermissionsContext = encodeDelegations(permissionContext);\n\n const redeemCalldata = encodeFunctionData({\n abi: DelegationManager,\n functionName: 'redeemDelegations',\n args: [\n [encodedPermissionsContext],\n [ExecutionMode.SingleDefault],\n encodeExecutionCalldatas([[callAsExecution]]),\n ],\n });\n\n return createExecution({\n target: delegationManager,\n callData: redeemCalldata,\n });\n};\n\n/**\n * If there's a single call, encode the shorthand `execute` function. Otherwise, encode the `executeWithMode` function. Execution type will always be \"default\".\n *\n * @param calls - The calls to execute.\n * @returns The encoded calldata for the DeleGator to execute the calls.\n * @description\n * This function supports both single and batch execution modes.\n * For single calls, it uses the gas-efficient execute function.\n */\nexport const encodeCalls = (calls: readonly Call[]) => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call && !isDelegatedCall(call)) {\n const { to: target, value, data: callData } = call;\n const execution = createExecution({ target, value, callData });\n return execute({ execution });\n }\n }\n\n const executions = calls.map((call) => {\n if (isDelegatedCall(call)) {\n return processDelegatedCall(call);\n }\n const { to: target, value, data: callData } = call;\n return createExecution({ target, value, callData });\n });\n\n const mode =\n calls.length === 1\n ? ExecutionMode.SingleDefault\n : ExecutionMode.BatchDefault;\n return executeWithMode({ mode, executions });\n};\n\n/**\n * Encodes calls for execution by a DeleGator smart contract.\n *\n * @param caller - The address of the DeleGator contract.\n * @param calls - An array of Call objects, each containing 'to', optional 'data', and optional 'value'.\n * @returns A promise that resolves to the encoded function data as a hexadecimal string.\n * @description\n * - If there's a single call directly to the delegator, it returns the call data directly.\n * - For multiple calls or calls to other addresses, it creates executions and encodes them for the DeleGator's execute function.\n * - The execution mode is set to ExecutionMode.SingleDefault for a single call, or ExecutionMode.BatchDefault for multiple calls.\n *\n * todo: This doesn't fully expose the flexibility of the DeleGator's execute function, but it's a start.\n * maybe we add a mechanism where individual calls passed to this function can be encoded batches.\n */\nexport const encodeCallsForCaller = async (\n caller: Address,\n calls: readonly Call[],\n): Promise<Hex> => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call?.to === caller && !isDelegatedCall(call)) {\n // if there's a single call, and it's to the delegator, we can just return the calldata directly.\n return call.data ?? '0x';\n }\n }\n return encodeCalls(calls);\n};\n","import { Signature } from 'ox';\nimport {\n parseAbiParameters,\n encodeAbiParameters,\n type Hex,\n encodePacked,\n keccak256,\n concat,\n hexToBytes,\n} from 'viem';\n\nexport const FIELD_MODULUS =\n 115792089210356248762697446949407573529996955224135760342422259061068512044369n;\nexport const MALLEABILITY_THRESHOLD = FIELD_MODULUS / 2n;\n\nexport const SIGNATURE_ABI_PARAMS = parseAbiParameters(\n 'bytes32, uint256, uint256, bytes, bool, string, string, uint256',\n);\n\n/**\n * This function is used to convert the client data returned from the\n * credentials API into a format that can be consumed by the DeleGator\n * contracts. We need the flattend JSON strings before and after the\n * userOpHash/challenge. This function provides those two client data string\n * slices.\n *\n * @param clientDataJson - The client data JSON string.\n * @returns Returns [clientDataJSONPrefix and clientDataJSONSuffix]\n * ClientDataJSONPrefix contains the client data till the challengeHash\n * ClientDataJSONSuffix contains the client data after the challengeHash.\n */\nexport const splitOnChallenge = (\n clientDataJson: string,\n): [clientDataJSONPrefix: string, clientDataJSONSuffix: string] => {\n /*\n CientData looks like this:\n {\n \"type\": \"webauthn.create\" | \"webauthn.get\",\n \"challenge\": \"{userOpHash}\",\n \"origin\": \"{Domain}\",\n \"crossOrigin\": boolean\n }\n */\n try {\n const { challenge } = JSON.parse(clientDataJson);\n if (challenge === undefined) {\n throw new Error('No \"challenge\" found in the input string');\n }\n return clientDataJson.split(challenge) as [string, string];\n } catch (error) {\n throw new Error('No \"challenge\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Returns the index of '\"type\":' in the ClientData.\n *\n * @param clientDataJson - Stringified ClientDataJSON.\n * @returns The index of '\"type\":' in the ClientData.\n */\nexport const getResponseTypeLocation = (clientDataJson: string): bigint => {\n try {\n // Find the index of the `\"type\":` key in the JSON string directly\n const typeIndex = clientDataJson.indexOf('\"type\":');\n\n if (typeIndex === -1) {\n throw new Error('No \"type\" found in the input string');\n }\n // Return the index of the `\"type\":` key\n return BigInt(typeIndex);\n } catch (error) {\n // Handle any errors that occur during the search\n throw new Error('No \"type\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Encodes a signature to a hexadecimal signature that will be accepted\n * by the DeleGator contracts.\n *\n * @param keyId - The key used for the signature, represented as a hexadecimal string.\n * @param signature - The signature to convert, as Hex.\n * @param clientDataJSON - The client data used in the creation of the signature.\n * @param authenticatorData - The authenticator data used in the creation of the signature.\n * @returns The signature as a valid DeleGator signature encoded as Hexadecimal string.\n */\nexport function encodeDeleGatorSignature(\n keyId: string,\n signature: Hex,\n clientDataJSON: string,\n authenticatorData: Hex,\n): Hex {\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n\n const { r: rValue, s: sValue } = Signature.fromHex(signature);\n\n let normalizedS = sValue;\n\n while (normalizedS > MALLEABILITY_THRESHOLD) {\n normalizedS = FIELD_MODULUS - normalizedS;\n }\n\n const [clientDataComponent1, clientDataComponent2] =\n splitOnChallenge(clientDataJSON);\n\n const { userVerified } = parseAuthenticatorFlags(authenticatorData);\n\n const responseTypeLocation = getResponseTypeLocation(clientDataJSON);\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n rValue,\n normalizedS,\n authenticatorData,\n userVerified,\n clientDataComponent1,\n clientDataComponent2,\n responseTypeLocation,\n ]);\n return encodedSignature;\n}\n\nconst AUTHENTICATOR_DATA_FLAGS_OFFSET = 32;\n// We have all of the flag bits defined here for completeness, even though we only extract the userVerified flag.\nenum AuthenticatorDataFlagBitIndex {\n UserPresence = 0,\n UserVerified = 2,\n BackupEligibility = 3,\n BackupState = 4,\n AttestedCredentialData = 6,\n ExtensionData = 7,\n}\n\nexport type AuthenticatorFlags = {\n userVerified: boolean;\n};\n\n/**\n * Parses the authenticator data and returns an authenticator flags object with the `userVerified` flag.\n * See https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data.\n *\n * @param authenticatorData - The authenticator data to parse.\n * @returns An object representing the parsed authenticator flags.\n */\nexport function parseAuthenticatorFlags(\n authenticatorData: Hex,\n): AuthenticatorFlags {\n const authenticatorDataBuffer = hexToBytes(authenticatorData);\n const dataBufferUint8 = new Uint8Array(authenticatorDataBuffer);\n const flags = dataBufferUint8[AUTHENTICATOR_DATA_FLAGS_OFFSET];\n if (flags === undefined) {\n throw new Error('Authenticator flags not found in authenticator data');\n }\n\n // Bit 0 is the least significant bit in the flags byte, so we left shift 0b1 by the bit index\n // eslint-disable-next-line no-bitwise\n const bitMask = 0b1 << AuthenticatorDataFlagBitIndex.UserVerified;\n\n return {\n // eslint-disable-next-line no-bitwise\n userVerified: (flags & bitMask) !== 0x0,\n };\n}\n\n/**\n * Creates a dummy signature.\n * This must meet all early-failure conditions of the real signature, but does not need to be a valid signature.\n *\n * @param keyId - The key ID to use for the dummy signature.\n * @returns The encoded signature.\n */\nexport const createDummyWebAuthnSignature = (keyId: Hex) => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data#data_structure\n const rpIdHash = keccak256(encodePacked(['string'], ['AuthenticatorData']));\n const flags = '0x05';\n const signCount = '0x00000000';\n const authenticatorData = concat([rpIdHash, flags, signCount]);\n\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n const rs =\n 57896044605178124381348723474703786764998477612067880171211129530534256022184n;\n const userVerification = true;\n const clientDataPrefix = '{\"type\":\"webauthn.get\",\"challenge\":\"';\n const clientDataSuffix = '\",\"origin\":\"passkey-domain\",\"crossOrigin\":false}';\n const responseTypeLocation = 1n;\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n rs,\n rs,\n authenticatorData,\n userVerification,\n clientDataPrefix,\n clientDataSuffix,\n responseTypeLocation,\n ]);\n\n return encodedSignature;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-3PBVHNYP.cjs","../src/counterfactualAccountData.ts","../src/encodeCalls.ts","../src/webAuthn.ts"],"names":[],"mappings":"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","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-3PBVHNYP.cjs","sourcesContent":[null,"import type { Address, Hex } from 'viem';\nimport { getContractAddress, pad } from 'viem';\n\nimport { Implementation } from './constants';\nimport { initializeHybridDeleGator } from './DelegationFramework/HybridDeleGator/encode';\nimport { initializeMultiSigDeleGator } from './DelegationFramework/MultiSigDeleGator/encode';\nimport { create2Deploy as encodeCreate2Deploy } from './DelegationFramework/SimpleFactory/encode';\nimport { encodeProxyCreationCode } from './DelegationFramework/utils';\nimport type {\n SmartAccountsEnvironment,\n HybridDeleGatorDeployParams,\n MultiSigDeleGatorDeployParams,\n DeployParams,\n} from './types';\n\n/**\n * Infers counterfactual account data for a DeleGator smart account.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @template TDeployParams - The type of deployment parameters, defaults to DeployParams<Implementation>.\n * @param options - The options for generating counterfactual account data.\n * @param options.factory - The address of the SimpleFactory contract.\n * @param options.implementations - The DeleGator implementation contracts.\n * @param options.implementation - The implementation type to use.\n * @param options.deployParams - The deployment parameters for the specified implementation.\n * @param options.deploySalt - The salt to use for CREATE2 address computation.\n * @returns An object containing the counterfactual address and factory calldata.\n * @description This function calculates the address a DeleGator contract would have if deployed,\n * and provides the calldata needed to deploy it.\n */\nexport const getCounterfactualAccountData = async <\n TImplementation extends Implementation,\n>({\n factory,\n implementations,\n implementation,\n deployParams,\n deploySalt,\n}: {\n factory: Address;\n implementations: SmartAccountsEnvironment['implementations'];\n implementation: TImplementation;\n deployParams: DeployParams<TImplementation>;\n deploySalt: Hex;\n}): Promise<{ factoryData: Hex; address: Address }> => {\n let implementationAddress: Address;\n let initcode: Hex;\n\n switch (implementation) {\n case Implementation.Hybrid: {\n const [owner, keyIds, xValues, yValues] =\n deployParams as HybridDeleGatorDeployParams;\n\n if (!implementations.HybridDeleGatorImpl) {\n throw new Error(\n 'HybridDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.HybridDeleGatorImpl;\n\n const p256Owners = keyIds.map((keyId, index) => {\n const xValue = xValues[index];\n const yValue = yValues[index];\n\n if (!xValue || !yValue) {\n throw new Error(\n `Missing X or Y value for keyId ${keyId} at index ${index}`,\n );\n }\n\n return {\n keyId,\n x: xValue,\n y: yValue,\n };\n });\n\n initcode = initializeHybridDeleGator({ eoaOwner: owner, p256Owners });\n break;\n }\n case Implementation.MultiSig: {\n const [owners, threshold] = deployParams as MultiSigDeleGatorDeployParams;\n\n if (!implementations.MultiSigDeleGatorImpl) {\n throw new Error(\n 'MultiSigDeleGatorImpl address not provided in environment',\n );\n }\n\n implementationAddress = implementations.MultiSigDeleGatorImpl;\n initcode = initializeMultiSigDeleGator({ owners, threshold });\n break;\n }\n case Implementation.Stateless7702:\n default:\n throw new Error(`Implementation type '${implementation}' not supported`);\n }\n\n const salt = pad(deploySalt, { dir: 'left', size: 32 });\n\n const proxyCreationCode = encodeProxyCreationCode({\n implementationAddress,\n initcode,\n });\n\n const address = getContractAddress({\n bytecode: proxyCreationCode,\n from: factory,\n opcode: 'CREATE2',\n salt,\n });\n\n const factoryData = encodeCreate2Deploy(proxyCreationCode, salt);\n\n return {\n factoryData,\n address,\n };\n};\n","import { DelegationManager } from '@metamask/delegation-abis';\nimport { encodeFunctionData } from 'viem';\nimport type { Address, Hex } from 'viem';\n\nimport type { DelegatedCall } from './actions/erc7710RedeemDelegationAction';\nimport { encodeDelegations } from './delegation';\nimport {\n execute,\n executeWithMode,\n} from './DelegationFramework/DeleGatorCore/encode';\nimport {\n ExecutionMode,\n createExecution,\n encodeExecutionCalldatas,\n} from './executions';\nimport type { Call } from './types';\n\n/**\n * Checks if a call is a delegated call by checking for the presence of permissionContext and delegationManager.\n *\n * @param call - The call to check.\n * @returns True if the call is a delegated call, false otherwise.\n */\nconst isDelegatedCall = (call: Call): call is DelegatedCall => {\n return 'permissionContext' in call && 'delegationManager' in call;\n};\n\n/**\n * If there's a single call with permissionContext and delegationManager,\n * processes it as a delegated call.\n *\n * @param call - The call to process.\n * @returns The execution object for the delegated call.\n * @description\n * This function creates an execution that calls redeemDelegations on the delegation manager.\n */\nconst processDelegatedCall = (call: DelegatedCall) => {\n const {\n permissionContext,\n delegationManager,\n to: target,\n value,\n data: callData,\n } = call;\n\n const callAsExecution = createExecution({ target, value, callData });\n\n if (!permissionContext) {\n return callAsExecution;\n }\n\n const encodedPermissionsContext = encodeDelegations(permissionContext);\n\n const redeemCalldata = encodeFunctionData({\n abi: DelegationManager,\n functionName: 'redeemDelegations',\n args: [\n [encodedPermissionsContext],\n [ExecutionMode.SingleDefault],\n encodeExecutionCalldatas([[callAsExecution]]),\n ],\n });\n\n return createExecution({\n target: delegationManager,\n callData: redeemCalldata,\n });\n};\n\n/**\n * If there's a single call, encode the shorthand `execute` function. Otherwise, encode the `executeWithMode` function. Execution type will always be \"default\".\n *\n * @param calls - The calls to execute.\n * @returns The encoded calldata for the DeleGator to execute the calls.\n * @description\n * This function supports both single and batch execution modes.\n * For single calls, it uses the gas-efficient execute function.\n */\nexport const encodeCalls = (calls: readonly Call[]) => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call && !isDelegatedCall(call)) {\n const { to: target, value, data: callData } = call;\n const execution = createExecution({ target, value, callData });\n return execute({ execution });\n }\n }\n\n const executions = calls.map((call) => {\n if (isDelegatedCall(call)) {\n return processDelegatedCall(call);\n }\n const { to: target, value, data: callData } = call;\n return createExecution({ target, value, callData });\n });\n\n const mode =\n calls.length === 1\n ? ExecutionMode.SingleDefault\n : ExecutionMode.BatchDefault;\n return executeWithMode({ mode, executions });\n};\n\n/**\n * Encodes calls for execution by a DeleGator smart contract.\n *\n * @param caller - The address of the DeleGator contract.\n * @param calls - An array of Call objects, each containing 'to', optional 'data', and optional 'value'.\n * @returns A promise that resolves to the encoded function data as a hexadecimal string.\n * @description\n * - If there's a single call directly to the delegator, it returns the call data directly.\n * - For multiple calls or calls to other addresses, it creates executions and encodes them for the DeleGator's execute function.\n * - The execution mode is set to ExecutionMode.SingleDefault for a single call, or ExecutionMode.BatchDefault for multiple calls.\n *\n * todo: This doesn't fully expose the flexibility of the DeleGator's execute function, but it's a start.\n * maybe we add a mechanism where individual calls passed to this function can be encoded batches.\n */\nexport const encodeCallsForCaller = async (\n caller: Address,\n calls: readonly Call[],\n): Promise<Hex> => {\n if (calls.length === 1) {\n const call = calls[0];\n if (call?.to === caller && !isDelegatedCall(call)) {\n // if there's a single call, and it's to the delegator, we can just return the calldata directly.\n return call.data ?? '0x';\n }\n }\n return encodeCalls(calls);\n};\n","import { Signature } from 'ox';\nimport {\n parseAbiParameters,\n encodeAbiParameters,\n type Hex,\n encodePacked,\n keccak256,\n concat,\n hexToBytes,\n} from 'viem';\n\nexport const FIELD_MODULUS =\n 115792089210356248762697446949407573529996955224135760342422259061068512044369n;\nexport const MALLEABILITY_THRESHOLD = FIELD_MODULUS / 2n;\n\nexport const SIGNATURE_ABI_PARAMS = parseAbiParameters(\n 'bytes32, uint256, uint256, bytes, bool, string, string, uint256',\n);\n\n/**\n * This function is used to convert the client data returned from the\n * credentials API into a format that can be consumed by the DeleGator\n * contracts. We need the flattend JSON strings before and after the\n * userOpHash/challenge. This function provides those two client data string\n * slices.\n *\n * @param clientDataJson - The client data JSON string.\n * @returns Returns [clientDataJSONPrefix and clientDataJSONSuffix]\n * ClientDataJSONPrefix contains the client data till the challengeHash\n * ClientDataJSONSuffix contains the client data after the challengeHash.\n */\nexport const splitOnChallenge = (\n clientDataJson: string,\n): [clientDataJSONPrefix: string, clientDataJSONSuffix: string] => {\n /*\n CientData looks like this:\n {\n \"type\": \"webauthn.create\" | \"webauthn.get\",\n \"challenge\": \"{userOpHash}\",\n \"origin\": \"{Domain}\",\n \"crossOrigin\": boolean\n }\n */\n try {\n const { challenge } = JSON.parse(clientDataJson);\n if (challenge === undefined) {\n throw new Error('No \"challenge\" found in the input string');\n }\n return clientDataJson.split(challenge) as [string, string];\n } catch (error) {\n throw new Error('No \"challenge\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Returns the index of '\"type\":' in the ClientData.\n *\n * @param clientDataJson - Stringified ClientDataJSON.\n * @returns The index of '\"type\":' in the ClientData.\n */\nexport const getResponseTypeLocation = (clientDataJson: string): bigint => {\n try {\n // Find the index of the `\"type\":` key in the JSON string directly\n const typeIndex = clientDataJson.indexOf('\"type\":');\n\n if (typeIndex === -1) {\n throw new Error('No \"type\" found in the input string');\n }\n // Return the index of the `\"type\":` key\n return BigInt(typeIndex);\n } catch (error) {\n // Handle any errors that occur during the search\n throw new Error('No \"type\" found in the input string', {\n cause: error,\n });\n }\n};\n\n/**\n * Encodes a signature to a hexadecimal signature that will be accepted\n * by the DeleGator contracts.\n *\n * @param keyId - The key used for the signature, represented as a hexadecimal string.\n * @param signature - The signature to convert, as Hex.\n * @param clientDataJSON - The client data used in the creation of the signature.\n * @param authenticatorData - The authenticator data used in the creation of the signature.\n * @returns The signature as a valid DeleGator signature encoded as Hexadecimal string.\n */\nexport function encodeDeleGatorSignature(\n keyId: string,\n signature: Hex,\n clientDataJSON: string,\n authenticatorData: Hex,\n): Hex {\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n\n const { r: rValue, s: sValue } = Signature.fromHex(signature);\n\n let normalizedS = sValue;\n\n while (normalizedS > MALLEABILITY_THRESHOLD) {\n normalizedS = FIELD_MODULUS - normalizedS;\n }\n\n const [clientDataComponent1, clientDataComponent2] =\n splitOnChallenge(clientDataJSON);\n\n const { userVerified } = parseAuthenticatorFlags(authenticatorData);\n\n const responseTypeLocation = getResponseTypeLocation(clientDataJSON);\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n rValue,\n normalizedS,\n authenticatorData,\n userVerified,\n clientDataComponent1,\n clientDataComponent2,\n responseTypeLocation,\n ]);\n return encodedSignature;\n}\n\nconst AUTHENTICATOR_DATA_FLAGS_OFFSET = 32;\n// We have all of the flag bits defined here for completeness, even though we only extract the userVerified flag.\nenum AuthenticatorDataFlagBitIndex {\n UserPresence = 0,\n UserVerified = 2,\n BackupEligibility = 3,\n BackupState = 4,\n AttestedCredentialData = 6,\n ExtensionData = 7,\n}\n\nexport type AuthenticatorFlags = {\n userVerified: boolean;\n};\n\n/**\n * Parses the authenticator data and returns an authenticator flags object with the `userVerified` flag.\n * See https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data.\n *\n * @param authenticatorData - The authenticator data to parse.\n * @returns An object representing the parsed authenticator flags.\n */\nexport function parseAuthenticatorFlags(\n authenticatorData: Hex,\n): AuthenticatorFlags {\n const authenticatorDataBuffer = hexToBytes(authenticatorData);\n const dataBufferUint8 = new Uint8Array(authenticatorDataBuffer);\n const flags = dataBufferUint8[AUTHENTICATOR_DATA_FLAGS_OFFSET];\n if (flags === undefined) {\n throw new Error('Authenticator flags not found in authenticator data');\n }\n\n // Bit 0 is the least significant bit in the flags byte, so we left shift 0b1 by the bit index\n // eslint-disable-next-line no-bitwise\n const bitMask = 0b1 << AuthenticatorDataFlagBitIndex.UserVerified;\n\n return {\n // eslint-disable-next-line no-bitwise\n userVerified: (flags & bitMask) !== 0x0,\n };\n}\n\n/**\n * Creates a dummy signature.\n * This must meet all early-failure conditions of the real signature, but does not need to be a valid signature.\n *\n * @param keyId - The key ID to use for the dummy signature.\n * @returns The encoded signature.\n */\nexport const createDummyWebAuthnSignature = (keyId: Hex) => {\n // https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data#data_structure\n const rpIdHash = keccak256(encodePacked(['string'], ['AuthenticatorData']));\n const flags = '0x05';\n const signCount = '0x00000000';\n const authenticatorData = concat([rpIdHash, flags, signCount]);\n\n const keyIdHash = keccak256(encodePacked(['string'], [keyId]));\n const rs =\n 57896044605178124381348723474703786764998477612067880171211129530534256022184n;\n const userVerification = true;\n const clientDataPrefix = '{\"type\":\"webauthn.get\",\"challenge\":\"';\n const clientDataSuffix = '\",\"origin\":\"passkey-domain\",\"crossOrigin\":false}';\n const responseTypeLocation = 1n;\n\n const encodedSignature = encodeAbiParameters(SIGNATURE_ABI_PARAMS, [\n keyIdHash,\n rs,\n rs,\n authenticatorData,\n userVerification,\n clientDataPrefix,\n clientDataSuffix,\n responseTypeLocation,\n ]);\n\n return encodedSignature;\n};\n"]}
|
|
@@ -7,11 +7,13 @@ var createExecution = ({
|
|
|
7
7
|
target,
|
|
8
8
|
value = 0n,
|
|
9
9
|
callData = "0x"
|
|
10
|
-
}) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
}) => {
|
|
11
|
+
return {
|
|
12
|
+
target,
|
|
13
|
+
value,
|
|
14
|
+
callData
|
|
15
|
+
};
|
|
16
|
+
};
|
|
15
17
|
var ExecutionMode = /* @__PURE__ */ ((ExecutionMode2) => {
|
|
16
18
|
ExecutionMode2["SingleDefault"] = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
17
19
|
ExecutionMode2["SingleTry"] = "0x0001000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -74,4 +76,4 @@ export {
|
|
|
74
76
|
encodeExecutionCalldata,
|
|
75
77
|
encodeExecutionCalldatas
|
|
76
78
|
};
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-4QXIOE7F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/executions.ts"],"sourcesContent":["import {\n type Address,\n type Hex,\n encodeAbiParameters,\n encodePacked,\n} from 'viem';\n\nexport type ExecutionStruct = {\n target: Address;\n value: bigint;\n callData: Hex;\n};\n\nexport type CreateExecutionArgs = {\n target: Address;\n value?: bigint;\n callData?: Hex;\n};\n\n/**\n * Creates an execution data structure.\n *\n * @param args - The arguments for creating an execution.\n * @param args.target - The address to invoke some calldata on.\n * @param args.value - ETH to send to the address.\n * @param args.callData - The calldata to invoke on the address.\n * @returns The created execution data structure.\n */\nexport const createExecution = ({\n target,\n value = 0n,\n callData = '0x',\n}: CreateExecutionArgs): ExecutionStruct => {\n return {\n target,\n value,\n callData,\n };\n};\n\n// Encoded modes\n// https://github.com/erc7579/erc7579-implementation/blob/main/src/lib/ModeLib.sol\nexport enum ExecutionMode {\n SingleDefault = '0x0000000000000000000000000000000000000000000000000000000000000000',\n SingleTry = '0x0001000000000000000000000000000000000000000000000000000000000000',\n BatchDefault = '0x0100000000000000000000000000000000000000000000000000000000000000',\n BatchTry = '0x0101000000000000000000000000000000000000000000000000000000000000',\n}\n\n/**\n * The ABI type components of an Execution.\n */\nexport const EXECUTION_ABI_TYPE_COMPONENTS = [\n { type: 'address', name: 'target' },\n { type: 'uint256', name: 'value' },\n { type: 'bytes', name: 'callData' },\n];\n\n/**\n * Encodes a single Execution. Used for executing a single Execution in a DeleGator SCA.\n *\n * @param execution - The execution to encode.\n * @returns The encoded execution.\n */\nexport const encodeSingleExecution = (execution: ExecutionStruct): Hex => {\n return encodePacked(\n ['address', 'uint256', 'bytes'],\n [execution.target, execution.value, execution.callData],\n );\n};\n\n/**\n * Encodes a batch of Executions. Used for executing a batch of Executions in a DeleGator SCA.\n *\n * @param executions - The executions to encode.\n * @returns The encoded executions.\n */\nexport const encodeBatchExecution = (executions: ExecutionStruct[]): Hex => {\n return encodeAbiParameters(\n [\n {\n components: EXECUTION_ABI_TYPE_COMPONENTS,\n name: 'executions',\n type: 'tuple[]',\n },\n ],\n [executions],\n );\n};\n\n/**\n * Encodes the calldata for interacting with the advanced `execute` DeleGator method.\n *\n * @param executions - The execution(s) to encode.\n * @returns The encoded execution(s).\n */\nexport const encodeExecutionCalldata = (executions: ExecutionStruct[]): Hex => {\n if (executions.length === 0) {\n throw new Error(\n 'Error while getting the execution calldatas, executions is empty',\n );\n }\n if (executions.length === 1) {\n const execution = executions[0];\n if (!execution) {\n throw new Error('Execution not found');\n }\n return encodeSingleExecution(execution);\n }\n\n return encodeBatchExecution(executions);\n};\n\n/**\n * Encodes the calldata for interacting with `redeemDelegations`.\n *\n * @param executionsBatch - The executions to encode.\n * @returns The encoded executions.\n */\nexport const encodeExecutionCalldatas = (\n executionsBatch: ExecutionStruct[][],\n): Hex[] => {\n if (executionsBatch.length === 0) {\n throw new Error(\n 'Error while getting the execution calldatas, executionsBatch is empty',\n );\n }\n return executionsBatch.map(encodeExecutionCalldata);\n};\n"],"mappings":";AAAA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAuBA,IAAM,kBAAkB,CAAC;AAAA,EAC9B;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AACb,MAA4C;AAC1C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAIO,IAAK,gBAAL,kBAAKA,mBAAL;AACL,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,kBAAe;AACf,EAAAA,eAAA,cAAW;AAJD,SAAAA;AAAA,GAAA;AAUL,IAAM,gCAAgC;AAAA,EAC3C,EAAE,MAAM,WAAW,MAAM,SAAS;AAAA,EAClC,EAAE,MAAM,WAAW,MAAM,QAAQ;AAAA,EACjC,EAAE,MAAM,SAAS,MAAM,WAAW;AACpC;AAQO,IAAM,wBAAwB,CAAC,cAAoC;AACxE,SAAO;AAAA,IACL,CAAC,WAAW,WAAW,OAAO;AAAA,IAC9B,CAAC,UAAU,QAAQ,UAAU,OAAO,UAAU,QAAQ;AAAA,EACxD;AACF;AAQO,IAAM,uBAAuB,CAAC,eAAuC;AAC1E,SAAO;AAAA,IACL;AAAA,MACE;AAAA,QACE,YAAY;AAAA,QACZ,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AACF;AAQO,IAAM,0BAA0B,CAAC,eAAuC;AAC7E,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,YAAY,WAAW,CAAC;AAC9B,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AACA,WAAO,sBAAsB,SAAS;AAAA,EACxC;AAEA,SAAO,qBAAqB,UAAU;AACxC;AAQO,IAAM,2BAA2B,CACtC,oBACU;AACV,MAAI,gBAAgB,WAAW,GAAG;AAChC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,gBAAgB,IAAI,uBAAuB;AACpD;","names":["ExecutionMode"]}
|