@charterlabs/rhinestone-sdk 0.3.0 → 0.3.2

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.
Files changed (129) hide show
  1. package/README.md +31 -200
  2. package/dist/src/accounts/error.d.ts +8 -1
  3. package/dist/src/accounts/error.d.ts.map +1 -1
  4. package/dist/src/accounts/error.js +10 -1
  5. package/dist/src/accounts/index.d.ts +11 -10
  6. package/dist/src/accounts/index.d.ts.map +1 -1
  7. package/dist/src/accounts/index.js +79 -50
  8. package/dist/src/accounts/kernel.d.ts +3 -5
  9. package/dist/src/accounts/kernel.d.ts.map +1 -1
  10. package/dist/src/accounts/kernel.js +8 -17
  11. package/dist/src/accounts/kernel.test.js +10 -3
  12. package/dist/src/accounts/nexus.d.ts +3 -5
  13. package/dist/src/accounts/nexus.d.ts.map +1 -1
  14. package/dist/src/accounts/nexus.js +108 -57
  15. package/dist/src/accounts/nexus.test.js +10 -3
  16. package/dist/src/accounts/passport.d.ts +4 -7
  17. package/dist/src/accounts/passport.d.ts.map +1 -1
  18. package/dist/src/accounts/passport.js +0 -91
  19. package/dist/src/accounts/safe.d.ts +9 -4
  20. package/dist/src/accounts/safe.d.ts.map +1 -1
  21. package/dist/src/accounts/safe.js +108 -38
  22. package/dist/src/accounts/safe.test.js +10 -3
  23. package/dist/src/accounts/signing/common.d.ts +3 -3
  24. package/dist/src/accounts/signing/common.d.ts.map +1 -1
  25. package/dist/src/accounts/signing/common.js +29 -5
  26. package/dist/src/accounts/signing/message.js +2 -2
  27. package/dist/src/accounts/signing/typedData.d.ts.map +1 -1
  28. package/dist/src/accounts/signing/typedData.js +3 -3
  29. package/dist/src/accounts/startale.d.ts +2 -4
  30. package/dist/src/accounts/startale.d.ts.map +1 -1
  31. package/dist/src/accounts/startale.js +0 -4
  32. package/dist/src/accounts/utils.d.ts.map +1 -1
  33. package/dist/src/accounts/utils.js +10 -3
  34. package/dist/src/accounts/walletClient.d.ts.map +1 -1
  35. package/dist/src/accounts/walletClient.js +6 -0
  36. package/dist/src/actions/compact.d.ts +4 -2
  37. package/dist/src/actions/compact.d.ts.map +1 -1
  38. package/dist/src/actions/compact.js +4 -1
  39. package/dist/src/actions/deployment.d.ts +19 -0
  40. package/dist/src/actions/deployment.d.ts.map +1 -0
  41. package/dist/src/actions/deployment.js +78 -0
  42. package/dist/src/actions/index.d.ts +3 -1
  43. package/dist/src/actions/index.d.ts.map +1 -1
  44. package/dist/src/actions/index.js +12 -0
  45. package/dist/src/actions/smart-sessions.d.ts +17 -8
  46. package/dist/src/actions/smart-sessions.d.ts.map +1 -1
  47. package/dist/src/actions/smart-sessions.js +40 -4
  48. package/dist/src/errors/index.d.ts +3 -3
  49. package/dist/src/errors/index.d.ts.map +1 -1
  50. package/dist/src/errors/index.js +3 -1
  51. package/dist/src/execution/compact.d.ts +15 -18
  52. package/dist/src/execution/compact.d.ts.map +1 -1
  53. package/dist/src/execution/compact.js +15 -17
  54. package/dist/src/execution/error.d.ts +2 -8
  55. package/dist/src/execution/error.d.ts.map +1 -1
  56. package/dist/src/execution/error.js +1 -10
  57. package/dist/src/execution/index.d.ts +6 -6
  58. package/dist/src/execution/index.d.ts.map +1 -1
  59. package/dist/src/execution/index.js +22 -28
  60. package/dist/src/execution/permit2.d.ts +12 -17
  61. package/dist/src/execution/permit2.d.ts.map +1 -1
  62. package/dist/src/execution/permit2.js +10 -16
  63. package/dist/src/execution/singleChainOps.d.ts +15 -3
  64. package/dist/src/execution/singleChainOps.d.ts.map +1 -1
  65. package/dist/src/execution/singleChainOps.js +17 -3
  66. package/dist/src/execution/utils.d.ts +36 -12
  67. package/dist/src/execution/utils.d.ts.map +1 -1
  68. package/dist/src/execution/utils.js +180 -133
  69. package/dist/src/index.d.ts +26 -8
  70. package/dist/src/index.d.ts.map +1 -1
  71. package/dist/src/index.js +49 -16
  72. package/dist/src/modules/abi/smart-session-emissary.d.ts +696 -0
  73. package/dist/src/modules/abi/smart-session-emissary.d.ts.map +1 -0
  74. package/dist/src/modules/abi/smart-session-emissary.js +565 -0
  75. package/dist/src/modules/chain-abstraction.d.ts +5 -0
  76. package/dist/src/modules/chain-abstraction.d.ts.map +1 -0
  77. package/dist/src/modules/chain-abstraction.js +7 -0
  78. package/dist/src/modules/common.d.ts +7 -1
  79. package/dist/src/modules/common.d.ts.map +1 -1
  80. package/dist/src/modules/index.d.ts +3 -9
  81. package/dist/src/modules/index.d.ts.map +1 -1
  82. package/dist/src/modules/index.js +11 -8
  83. package/dist/src/modules/index.test.js +3 -9
  84. package/dist/src/modules/legacy.d.ts +10 -0
  85. package/dist/src/modules/legacy.d.ts.map +1 -0
  86. package/dist/src/modules/legacy.js +65 -0
  87. package/dist/src/modules/validators/core.d.ts +2 -1
  88. package/dist/src/modules/validators/core.d.ts.map +1 -1
  89. package/dist/src/modules/validators/core.js +4 -1
  90. package/dist/src/modules/validators/index.d.ts +2 -2
  91. package/dist/src/modules/validators/index.d.ts.map +1 -1
  92. package/dist/src/modules/validators/index.js +1 -6
  93. package/dist/src/modules/validators/smart-sessions.d.ts +112 -23
  94. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
  95. package/dist/src/modules/validators/smart-sessions.js +426 -301
  96. package/dist/src/orchestrator/client.d.ts +3 -4
  97. package/dist/src/orchestrator/client.d.ts.map +1 -1
  98. package/dist/src/orchestrator/client.js +49 -53
  99. package/dist/src/orchestrator/error.d.ts +11 -1
  100. package/dist/src/orchestrator/error.d.ts.map +1 -1
  101. package/dist/src/orchestrator/error.js +16 -1
  102. package/dist/src/orchestrator/index.d.ts +5 -5
  103. package/dist/src/orchestrator/index.d.ts.map +1 -1
  104. package/dist/src/orchestrator/index.js +3 -1
  105. package/dist/src/orchestrator/registry.d.ts +3 -2
  106. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  107. package/dist/src/orchestrator/registry.js +15 -14
  108. package/dist/src/orchestrator/registry.test.js +18 -1
  109. package/dist/src/orchestrator/types.d.ts +33 -8
  110. package/dist/src/orchestrator/types.d.ts.map +1 -1
  111. package/dist/src/orchestrator/types.js +15 -1
  112. package/dist/src/types.d.ts +57 -28
  113. package/dist/src/types.d.ts.map +1 -1
  114. package/dist/src/utils/index.d.ts +14 -2
  115. package/dist/src/utils/index.d.ts.map +1 -1
  116. package/dist/src/utils/index.js +46 -4
  117. package/dist/test/utils/utils.d.ts +5 -0
  118. package/dist/test/utils/utils.d.ts.map +1 -0
  119. package/dist/test/utils/utils.js +20 -0
  120. package/package.json +33 -3
  121. package/dist/src/execution/smart-session.d.ts +0 -13
  122. package/dist/src/execution/smart-session.d.ts.map +0 -1
  123. package/dist/src/execution/smart-session.js +0 -178
  124. package/dist/src/modules/omni-account.d.ts +0 -8
  125. package/dist/src/modules/omni-account.d.ts.map +0 -1
  126. package/dist/src/modules/omni-account.js +0 -13
  127. package/dist/src/modules/validators/smart-sessions.test.d.ts +0 -2
  128. package/dist/src/modules/validators/smart-sessions.test.d.ts.map +0 -1
  129. package/dist/src/modules/validators/smart-sessions.test.js +0 -222
@@ -1,36 +1,85 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = exports.SMART_SESSIONS_VALIDATOR_ADDRESS = exports.SMART_SESSION_MODE_ENABLE = exports.SMART_SESSION_MODE_USE = void 0;
4
- exports.getSmartSessionData = getSmartSessionData;
5
- exports.getSmartSessionValidator = getSmartSessionValidator;
6
+ exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = exports.SMART_SESSION_EMISSARY_ADDRESS = void 0;
7
+ exports.packSignature = packSignature;
8
+ exports.getSessionData = getSessionData;
6
9
  exports.getEnableSessionCall = getEnableSessionCall;
7
- exports.encodeSmartSessionSignature = encodeSmartSessionSignature;
8
10
  exports.getPermissionId = getPermissionId;
11
+ exports.getSmartSessionValidator = getSmartSessionValidator;
12
+ exports.getSessionDetails = getSessionDetails;
9
13
  exports.isSessionEnabled = isSessionEnabled;
14
+ exports.signEnableSession = signEnableSession;
10
15
  const solady_1 = require("solady");
11
16
  const viem_1 = require("viem");
12
- const smart_sessions_1 = require("../abi/smart-sessions");
17
+ const chains_1 = require("viem/chains");
18
+ const utils_1 = require("../../accounts/utils");
19
+ const compact_1 = require("../../execution/compact");
20
+ const utils_2 = require("../../execution/utils");
21
+ const smart_session_emissary_1 = __importDefault(require("../abi/smart-session-emissary"));
13
22
  const common_1 = require("../common");
14
23
  const core_1 = require("./core");
15
- const SMART_SESSIONS_VALIDATOR_ADDRESS = '0x00000000008bdaba73cd9815d79069c247eb4bda';
16
- exports.SMART_SESSIONS_VALIDATOR_ADDRESS = SMART_SESSIONS_VALIDATOR_ADDRESS;
24
+ Object.defineProperty(exports, "SMART_SESSION_EMISSARY_ADDRESS", { enumerable: true, get: function () { return core_1.SMART_SESSION_EMISSARY_ADDRESS; } });
25
+ const types = {
26
+ PolicyData: [
27
+ { name: 'policy', type: 'address' },
28
+ { name: 'initData', type: 'bytes' },
29
+ ],
30
+ ActionData: [
31
+ { name: 'actionTargetSelector', type: 'bytes4' },
32
+ { name: 'actionTarget', type: 'address' },
33
+ { name: 'actionPolicies', type: 'PolicyData[]' },
34
+ ],
35
+ ERC7739Context: [
36
+ { name: 'appDomainSeparator', type: 'bytes32' },
37
+ { name: 'contentName', type: 'string[]' },
38
+ ],
39
+ ERC7739Data: [
40
+ { name: 'allowedERC7739Content', type: 'ERC7739Context[]' },
41
+ { name: 'erc1271Policies', type: 'PolicyData[]' },
42
+ ],
43
+ LockTagData: [
44
+ { name: 'lockTag', type: 'bytes12' },
45
+ { name: 'claimPolicies', type: 'PolicyData[]' },
46
+ ],
47
+ SignedPermissions: [
48
+ { name: 'actions', type: 'ActionData[]' },
49
+ { name: 'erc7739Policies', type: 'ERC7739Data' },
50
+ { name: 'lockTagPolicies', type: 'LockTagData' },
51
+ { name: 'permitGenericPolicy', type: 'bool' },
52
+ ],
53
+ SignedSession: [
54
+ { name: 'account', type: 'address' },
55
+ { name: 'expires', type: 'uint256' },
56
+ { name: 'nonce', type: 'uint256' },
57
+ { name: 'permissions', type: 'SignedPermissions' },
58
+ { name: 'salt', type: 'bytes32' },
59
+ { name: 'sessionValidator', type: 'address' },
60
+ { name: 'sessionValidatorInitData', type: 'bytes' },
61
+ { name: 'smartSessionEmissary', type: 'address' },
62
+ ],
63
+ ChainSession: [
64
+ { name: 'chainId', type: 'uint64' },
65
+ { name: 'session', type: 'SignedSession' },
66
+ ],
67
+ MultiChainSession: [{ name: 'sessionsAndChainIds', type: 'ChainSession[]' }],
68
+ };
17
69
  const SMART_SESSION_MODE_USE = '0x00';
18
- exports.SMART_SESSION_MODE_USE = SMART_SESSION_MODE_USE;
19
70
  const SMART_SESSION_MODE_ENABLE = '0x01';
20
- exports.SMART_SESSION_MODE_ENABLE = SMART_SESSION_MODE_ENABLE;
21
- const SMART_SESSION_MODE_UNSAFE_ENABLE = '0x02';
22
- const SPENDING_LIMITS_POLICY_ADDRESS = '0x00000088D48cF102A8Cdb0137A9b173f957c6343';
23
- const TIME_FRAME_POLICY_ADDRESS = '0x8177451511dE0577b911C254E9551D981C26dc72';
24
- const SUDO_POLICY_ADDRESS = '0x0000003111cD8e92337C100F22B7A9dbf8DEE301';
25
- const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000006DDA6c463511C4e9B05CFc34C1247fCF1F';
26
- const USAGE_LIMIT_POLICY_ADDRESS = '0x1F34eF8311345A3A4a4566aF321b313052F51493';
27
- const VALUE_LIMIT_POLICY_ADDRESS = '0x730DA93267E7E513e932301B47F2ac7D062abC83';
28
71
  const SMART_SESSIONS_FALLBACK_TARGET_FLAG = '0x0000000000000000000000000000000000000001';
29
72
  exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = SMART_SESSIONS_FALLBACK_TARGET_FLAG;
30
73
  const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = '0x00000001';
31
74
  exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG;
32
75
  const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = '0x00000002';
33
76
  exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION;
77
+ const SPENDING_LIMITS_POLICY_ADDRESS = '0x00000088d48cf102a8cdb0137a9b173f957c6343';
78
+ const TIME_FRAME_POLICY_ADDRESS = '0x8177451511de0577b911c254e9551d981c26dc72';
79
+ const SUDO_POLICY_ADDRESS = '0x0000003111cd8e92337c100f22b7a9dbf8dee301';
80
+ const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000006dda6c463511c4e9b05cfc34c1247fcf1f';
81
+ const USAGE_LIMIT_POLICY_ADDRESS = '0x1f34ef8311345a3a4a4566af321b313052f51493';
82
+ const VALUE_LIMIT_POLICY_ADDRESS = '0x730da93267e7e513e932301b47f2ac7d062abc83';
34
83
  const ACTION_CONDITION_EQUAL = 0;
35
84
  const ACTION_CONDITION_GREATER_THAN = 1;
36
85
  const ACTION_CONDITION_LESS_THAN = 2;
@@ -38,80 +87,365 @@ const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
38
87
  const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
39
88
  const ACTION_CONDITION_NOT_EQUAL = 5;
40
89
  const ACTION_CONDITION_IN_RANGE = 6;
41
- async function getEnableSessionCall(session) {
42
- const sessionData = getSmartSessionData(session);
43
- return {
44
- to: SMART_SESSIONS_VALIDATOR_ADDRESS,
45
- data: (0, viem_1.encodeFunctionData)({
46
- abi: smart_sessions_1.enableSessionsAbi,
47
- functionName: 'enableSessions',
48
- args: [[sessionData]],
90
+ function packSignature(signers, validatorSignature) {
91
+ const session = signers.session;
92
+ const permissionId = getPermissionId(session);
93
+ if (signers.verifyExecutions) {
94
+ const smartSessionMode = signers.enableData
95
+ ? SMART_SESSION_MODE_ENABLE
96
+ : SMART_SESSION_MODE_USE;
97
+ const sessionData = getSessionData(signers.session);
98
+ const packedSignature = signers.enableData
99
+ ? solady_1.LibZip.flzCompress((0, viem_1.encodeAbiParameters)([
100
+ {
101
+ type: 'tuple',
102
+ name: 'enableData',
103
+ components: [
104
+ { type: 'bytes', name: 'allocatorSig' },
105
+ { type: 'bytes', name: 'userSig' },
106
+ { type: 'uint256', name: 'expires' },
107
+ {
108
+ type: 'tuple',
109
+ name: 'enableSession',
110
+ components: [
111
+ {
112
+ type: 'uint8',
113
+ name: 'chainDigestIndex',
114
+ },
115
+ {
116
+ type: 'tuple[]',
117
+ name: 'hashesAndChainIds',
118
+ components: [
119
+ { type: 'uint64', name: 'chainId' },
120
+ { type: 'bytes32', name: 'sessionDigest' },
121
+ ],
122
+ },
123
+ {
124
+ type: 'tuple',
125
+ name: 'session',
126
+ components: [
127
+ { type: 'address', name: 'sessionValidator' },
128
+ { type: 'bytes', name: 'sessionValidatorInitData' },
129
+ { type: 'bytes32', name: 'salt' },
130
+ {
131
+ type: 'tuple[]',
132
+ name: 'actions',
133
+ components: [
134
+ { type: 'bytes4', name: 'actionTargetSelector' },
135
+ { type: 'address', name: 'actionTarget' },
136
+ {
137
+ type: 'tuple[]',
138
+ name: 'actionPolicies',
139
+ components: [
140
+ { type: 'address', name: 'policy' },
141
+ { type: 'bytes', name: 'initData' },
142
+ ],
143
+ },
144
+ ],
145
+ },
146
+ {
147
+ type: 'tuple[]',
148
+ name: 'claimPolicies',
149
+ components: [
150
+ { type: 'address', name: 'policy' },
151
+ { type: 'bytes', name: 'initData' },
152
+ ],
153
+ },
154
+ {
155
+ type: 'tuple',
156
+ name: 'erc7739Policies',
157
+ components: [
158
+ {
159
+ type: 'tuple[]',
160
+ name: 'allowedERC7739Content',
161
+ components: [
162
+ {
163
+ type: 'bytes32',
164
+ name: 'appDomainSeparator',
165
+ },
166
+ { type: 'string[]', name: 'contentNames' },
167
+ ],
168
+ },
169
+ {
170
+ type: 'tuple[]',
171
+ name: 'erc1271Policies',
172
+ components: [
173
+ { type: 'address', name: 'policy' },
174
+ { type: 'bytes', name: 'initData' },
175
+ ],
176
+ },
177
+ ],
178
+ },
179
+ ],
180
+ },
181
+ ],
182
+ },
183
+ ],
184
+ },
185
+ {
186
+ type: 'tuple',
187
+ name: 'config',
188
+ components: [
189
+ { type: 'uint8', name: 'scope' },
190
+ { type: 'uint8', name: 'resetPeriod' },
191
+ { type: 'address', name: 'allocator' },
192
+ { type: 'bytes32', name: 'permissionId' },
193
+ ],
194
+ },
195
+ { type: 'bytes' },
196
+ ], [
197
+ {
198
+ allocatorSig: viem_1.zeroHash,
199
+ userSig: signers.enableData.userSignature,
200
+ expires: viem_1.maxUint256,
201
+ enableSession: {
202
+ chainDigestIndex: signers.enableData.sessionToEnableIndex,
203
+ hashesAndChainIds: signers.enableData.hashesAndChainIds,
204
+ session: sessionData,
205
+ },
206
+ },
207
+ {
208
+ scope: compact_1.SCOPE_MULTICHAIN,
209
+ resetPeriod: compact_1.RESET_PERIOD_ONE_WEEK,
210
+ allocator: viem_1.zeroAddress,
211
+ permissionId: getPermissionId(signers.session),
212
+ },
213
+ validatorSignature,
214
+ ]))
215
+ : validatorSignature;
216
+ return signers.enableData
217
+ ? (0, viem_1.encodePacked)(['bytes1', 'bytes'], [smartSessionMode, packedSignature])
218
+ : (0, viem_1.encodePacked)(['bytes1', 'bytes32', 'bytes'], [smartSessionMode, permissionId, packedSignature]);
219
+ }
220
+ else {
221
+ const SIGNATURE_IS_VALID_SIG_1271 = '0x00';
222
+ const policyDataOffset = BigInt(64 + (0, viem_1.size)(validatorSignature));
223
+ const mode = SIGNATURE_IS_VALID_SIG_1271;
224
+ const policySpecificData = '0x';
225
+ const signature = (0, viem_1.encodePacked)(['bytes1', 'bytes32', 'uint256', 'bytes', 'bytes'], [
226
+ mode,
227
+ permissionId,
228
+ policyDataOffset,
229
+ validatorSignature,
230
+ policySpecificData,
231
+ ]);
232
+ return signature;
233
+ }
234
+ }
235
+ async function getSessionDetails(account, sessions) {
236
+ const lockTag = '0x000000000000000000000000';
237
+ const sessionNonces = await Promise.all(sessions.map((session) => getSessionNonce(account, session, lockTag)));
238
+ const sessionDatas = sessions.map((session) => getSessionData(session));
239
+ const signedSessions = sessionDatas.map((session, index) => getSignedSession(account, lockTag, session, sessionNonces[index]));
240
+ const chains = sessions.map((session) => session.chain);
241
+ const hashesAndChainIds = signedSessions.map((session, index) => ({
242
+ chainId: BigInt(chains[index].id),
243
+ sessionDigest: (0, viem_1.hashStruct)({
244
+ types,
245
+ primaryType: 'SignedSession',
246
+ data: session,
49
247
  }),
248
+ }));
249
+ const data = {
250
+ domain: {
251
+ name: 'SmartSessionEmissary',
252
+ version: '1',
253
+ },
254
+ types: types,
255
+ primaryType: 'MultiChainSession',
256
+ message: {
257
+ sessionsAndChainIds: signedSessions.map((session, index) => ({
258
+ chainId: BigInt(chains[index].id),
259
+ session,
260
+ })),
261
+ },
262
+ };
263
+ return {
264
+ nonces: sessionNonces,
265
+ hashesAndChainIds,
266
+ data,
50
267
  };
51
268
  }
52
- function getSmartSessionData(session) {
53
- const sessionValidator = (0, core_1.getValidator)(session.owners);
54
- const userOpPolicies = (session.policies || [
55
- {
56
- type: 'sudo',
57
- },
58
- ]).map((policy) => {
59
- return getPolicyData(policy);
269
+ async function isSessionEnabled(account, provider, session) {
270
+ const publicClient = (0, viem_1.createPublicClient)({
271
+ chain: session.chain,
272
+ transport: (0, utils_1.createTransport)(session.chain, provider),
60
273
  });
61
- return {
62
- sessionValidator: sessionValidator.address,
63
- sessionValidatorInitData: sessionValidator.initData,
64
- salt: session.salt ?? viem_1.zeroHash,
65
- userOpPolicies,
66
- // Using the fallback action by default (any transaction will pass)
67
- actions: (session.actions || [
274
+ const isEnabled = await publicClient.readContract({
275
+ address: core_1.SMART_SESSION_EMISSARY_ADDRESS,
276
+ abi: [
277
+ {
278
+ type: 'function',
279
+ name: 'isPermissionEnabled',
280
+ inputs: [
281
+ { name: 'account', type: 'address' },
282
+ { name: 'permissionId', type: 'bytes32' },
283
+ ],
284
+ outputs: [{ name: 'isEnabled', type: 'bool' }],
285
+ stateMutability: 'view',
286
+ },
287
+ ],
288
+ functionName: 'isPermissionEnabled',
289
+ args: [account, getPermissionId(session)],
290
+ });
291
+ return isEnabled;
292
+ }
293
+ async function signEnableSession(config, details) {
294
+ return (0, utils_2.signTypedData)(config, details.data, chains_1.mainnet, undefined, {
295
+ skipErc6492: true,
296
+ });
297
+ }
298
+ async function getSessionNonce(account, session, lockTag) {
299
+ const publicClient = (0, viem_1.createPublicClient)({
300
+ chain: session.chain,
301
+ transport: (0, viem_1.http)(),
302
+ });
303
+ const nonce = await publicClient.readContract({
304
+ address: core_1.SMART_SESSION_EMISSARY_ADDRESS,
305
+ abi: [
68
306
  {
69
- target: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
70
- selector: SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
307
+ type: 'function',
308
+ name: 'getNonce',
309
+ inputs: [
310
+ { name: 'sponsor', type: 'address', internalType: 'address' },
311
+ { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
312
+ ],
313
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
314
+ stateMutability: 'view',
71
315
  },
72
- ]).map((action) => {
73
- const actionPolicies = (action.policies || [
316
+ ],
317
+ functionName: 'getNonce',
318
+ args: [account, lockTag],
319
+ });
320
+ return nonce;
321
+ }
322
+ function getSignedSession(account, lockTag, session, nonce) {
323
+ return {
324
+ account,
325
+ permissions: {
326
+ permitGenericPolicy: session.actions.some((action) => action.actionTarget === SMART_SESSIONS_FALLBACK_TARGET_FLAG &&
327
+ action.actionTargetSelector ===
328
+ SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG),
329
+ lockTagPolicies: {
330
+ lockTag,
331
+ claimPolicies: session.claimPolicies,
332
+ },
333
+ erc7739Policies: {
334
+ allowedERC7739Content: session.erc7739Policies.allowedERC7739Content.map((content) => ({
335
+ contentName: content.contentNames,
336
+ appDomainSeparator: content.appDomainSeparator,
337
+ })),
338
+ erc1271Policies: session.erc7739Policies.erc1271Policies,
339
+ },
340
+ actions: session.actions,
341
+ },
342
+ sessionValidator: session.sessionValidator,
343
+ sessionValidatorInitData: session.sessionValidatorInitData,
344
+ salt: session.salt,
345
+ smartSessionEmissary: core_1.SMART_SESSION_EMISSARY_ADDRESS,
346
+ expires: viem_1.maxUint256,
347
+ nonce,
348
+ };
349
+ }
350
+ async function getEnableSessionCall(account, session, enableSessionSignature, hashesAndChainIds, sessionToEnableIndex) {
351
+ const sessionData = getSessionData(session);
352
+ const permissionId = getPermissionId(session);
353
+ return {
354
+ to: core_1.SMART_SESSION_EMISSARY_ADDRESS,
355
+ data: (0, viem_1.encodeFunctionData)({
356
+ abi: smart_session_emissary_1.default,
357
+ functionName: 'setConfig',
358
+ args: [
359
+ account,
74
360
  {
75
- type: 'sudo',
361
+ scope: compact_1.SCOPE_MULTICHAIN,
362
+ resetPeriod: compact_1.RESET_PERIOD_ONE_WEEK,
363
+ allocator: viem_1.zeroAddress,
364
+ permissionId,
76
365
  },
77
- ]).map((policy) => getPolicyData(policy));
78
- return {
79
- actionTargetSelector: action.selector,
80
- actionTarget: action.target,
81
- actionPolicies,
82
- };
83
- }),
84
- erc7739Policies: session.signing
85
- ? {
86
- allowedERC7739Content: session.signing.allowedContent.map((content) => ({
87
- appDomainSeparator: content.domainSeparator,
88
- contentName: content.contentName,
89
- })),
90
- erc1271Policies: (session.signing.policies || [
91
- {
92
- type: 'sudo',
366
+ {
367
+ allocatorSig: viem_1.zeroHash,
368
+ userSig: enableSessionSignature,
369
+ expires: viem_1.maxUint256,
370
+ session: {
371
+ chainDigestIndex: sessionToEnableIndex,
372
+ hashesAndChainIds,
373
+ sessionToEnable: sessionData,
93
374
  },
94
- ]).map((policy) => getPolicyData(policy)),
95
- }
96
- : {
97
- allowedERC7739Content: [],
98
- erc1271Policies: [],
99
- },
100
- permitERC4337Paymaster: true,
375
+ },
376
+ ],
377
+ }),
101
378
  };
102
379
  }
103
- function getSmartSessionValidator(config) {
104
- if (!config.sessions) {
105
- return null;
106
- }
380
+ function getSessionData(session) {
381
+ const validator = (0, core_1.getValidator)(session.owners);
382
+ const allowedContent = [
383
+ {
384
+ contentNames: [''],
385
+ appDomainSeparator: viem_1.zeroHash,
386
+ },
387
+ ];
388
+ const erc7739Data = {
389
+ allowedERC7739Content: allowedContent,
390
+ erc1271Policies: [
391
+ {
392
+ policy: SUDO_POLICY_ADDRESS,
393
+ initData: '0x',
394
+ },
395
+ ],
396
+ };
397
+ const sudoAction = {
398
+ actionTargetSelector: SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
399
+ actionTarget: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
400
+ actionPolicies: [
401
+ {
402
+ policy: SUDO_POLICY_ADDRESS,
403
+ initData: '0x',
404
+ },
405
+ ],
406
+ };
407
+ const actions = session.actions
408
+ ? session.actions.map((action) => ({
409
+ actionTargetSelector: action.selector ?? SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
410
+ actionTarget: action.target ?? SMART_SESSIONS_FALLBACK_TARGET_FLAG,
411
+ actionPolicies: action.policies?.map((policy) => getPolicyData(policy)) ?? [
412
+ {
413
+ policy: SUDO_POLICY_ADDRESS,
414
+ initData: '0x',
415
+ },
416
+ ],
417
+ }))
418
+ : [sudoAction];
107
419
  return {
108
- address: SMART_SESSIONS_VALIDATOR_ADDRESS,
109
- initData: '0x',
110
- deInitData: '0x',
111
- additionalContext: '0x',
112
- type: common_1.MODULE_TYPE_ID_VALIDATOR,
420
+ sessionValidator: validator.address,
421
+ salt: viem_1.zeroHash,
422
+ sessionValidatorInitData: validator.initData,
423
+ erc7739Policies: erc7739Data,
424
+ actions,
425
+ claimPolicies: [],
113
426
  };
114
427
  }
428
+ function getPermissionId(session) {
429
+ const sessionData = getSessionData(session);
430
+ return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
431
+ {
432
+ type: 'address',
433
+ name: 'sessionValidator',
434
+ },
435
+ {
436
+ type: 'bytes',
437
+ name: 'sessionValidatorInitData',
438
+ },
439
+ {
440
+ type: 'bytes32',
441
+ name: 'salt',
442
+ },
443
+ ], [
444
+ sessionData.sessionValidator,
445
+ sessionData.sessionValidatorInitData,
446
+ sessionData.salt,
447
+ ]));
448
+ }
115
449
  function getPolicyData(policy) {
116
450
  switch (policy.type) {
117
451
  case 'sudo':
@@ -263,231 +597,22 @@ function getPolicyData(policy) {
263
597
  }
264
598
  }
265
599
  }
266
- function createFixedArray(length, getValue) {
267
- return Array.from({ length }, (_, i) => getValue(i));
268
- }
269
- async function isSessionEnabled(client, address, permissionId) {
270
- return await client.readContract({
271
- address: SMART_SESSIONS_VALIDATOR_ADDRESS,
272
- abi: [
273
- {
274
- inputs: [
275
- {
276
- internalType: 'PermissionId',
277
- name: 'permissionId',
278
- type: 'bytes32',
279
- },
280
- {
281
- internalType: 'address',
282
- name: 'account',
283
- type: 'address',
284
- },
285
- ],
286
- name: 'isPermissionEnabled',
287
- outputs: [
288
- {
289
- internalType: 'bool',
290
- name: '',
291
- type: 'bool',
292
- },
293
- ],
294
- stateMutability: 'view',
295
- type: 'function',
296
- },
297
- ],
298
- functionName: 'isPermissionEnabled',
299
- args: [permissionId, address],
300
- });
301
- }
302
- function encodeSmartSessionSignature(mode, permissionId, signature, enableSessionData) {
303
- switch (mode) {
304
- case SMART_SESSION_MODE_USE:
305
- return (0, viem_1.encodePacked)(['bytes1', 'bytes32', 'bytes'], [mode, permissionId, signature]);
306
- case SMART_SESSION_MODE_ENABLE:
307
- case SMART_SESSION_MODE_UNSAFE_ENABLE:
308
- if (!enableSessionData) {
309
- throw new Error('enableSession is required for ENABLE mode');
310
- }
311
- return (0, viem_1.encodePacked)(['bytes1', 'bytes'], [
312
- mode,
313
- solady_1.LibZip.flzCompress(encodeEnableSessionSignature(enableSessionData, signature)),
314
- ]);
315
- default:
316
- throw new Error(`Unknown mode ${mode}`);
600
+ function getSmartSessionValidator(config) {
601
+ if (!config.experimental_sessions) {
602
+ return null;
317
603
  }
604
+ const { enabled, module } = config.experimental_sessions;
605
+ if (!enabled) {
606
+ return null;
607
+ }
608
+ return {
609
+ address: module ?? core_1.SMART_SESSION_EMISSARY_ADDRESS,
610
+ initData: '0x',
611
+ deInitData: '0x',
612
+ additionalContext: '0x',
613
+ type: common_1.MODULE_TYPE_ID_VALIDATOR,
614
+ };
318
615
  }
319
- function encodeEnableSessionSignature(enableSessionData, signature) {
320
- return (0, viem_1.encodeAbiParameters)([
321
- {
322
- components: [
323
- {
324
- type: 'uint8',
325
- name: 'chainDigestIndex',
326
- },
327
- {
328
- type: 'tuple[]',
329
- components: [
330
- {
331
- internalType: 'uint64',
332
- name: 'chainId',
333
- type: 'uint64',
334
- },
335
- {
336
- internalType: 'bytes32',
337
- name: 'sessionDigest',
338
- type: 'bytes32',
339
- },
340
- ],
341
- name: 'hashesAndChainIds',
342
- },
343
- {
344
- components: [
345
- {
346
- internalType: 'contract ISessionValidator',
347
- name: 'sessionValidator',
348
- type: 'address',
349
- },
350
- {
351
- internalType: 'bytes',
352
- name: 'sessionValidatorInitData',
353
- type: 'bytes',
354
- },
355
- { internalType: 'bytes32', name: 'salt', type: 'bytes32' },
356
- {
357
- components: [
358
- { internalType: 'address', name: 'policy', type: 'address' },
359
- { internalType: 'bytes', name: 'initData', type: 'bytes' },
360
- ],
361
- internalType: 'struct PolicyData[]',
362
- name: 'userOpPolicies',
363
- type: 'tuple[]',
364
- },
365
- {
366
- components: [
367
- {
368
- components: [
369
- {
370
- internalType: 'bytes32',
371
- name: 'appDomainSeparator',
372
- type: 'bytes32',
373
- },
374
- {
375
- internalType: 'string[]',
376
- name: 'contentName',
377
- type: 'string[]',
378
- },
379
- ],
380
- internalType: 'struct ERC7739Context[]',
381
- name: 'allowedERC7739Content',
382
- type: 'tuple[]',
383
- },
384
- {
385
- components: [
386
- {
387
- internalType: 'address',
388
- name: 'policy',
389
- type: 'address',
390
- },
391
- {
392
- internalType: 'bytes',
393
- name: 'initData',
394
- type: 'bytes',
395
- },
396
- ],
397
- internalType: 'struct PolicyData[]',
398
- name: 'erc1271Policies',
399
- type: 'tuple[]',
400
- },
401
- ],
402
- internalType: 'struct ERC7739Data',
403
- name: 'erc7739Policies',
404
- type: 'tuple',
405
- },
406
- {
407
- components: [
408
- {
409
- internalType: 'bytes4',
410
- name: 'actionTargetSelector',
411
- type: 'bytes4',
412
- },
413
- {
414
- internalType: 'address',
415
- name: 'actionTarget',
416
- type: 'address',
417
- },
418
- {
419
- components: [
420
- {
421
- internalType: 'address',
422
- name: 'policy',
423
- type: 'address',
424
- },
425
- {
426
- internalType: 'bytes',
427
- name: 'initData',
428
- type: 'bytes',
429
- },
430
- ],
431
- internalType: 'struct PolicyData[]',
432
- name: 'actionPolicies',
433
- type: 'tuple[]',
434
- },
435
- ],
436
- internalType: 'struct ActionData[]',
437
- name: 'actions',
438
- type: 'tuple[]',
439
- },
440
- {
441
- internalType: 'bool',
442
- name: 'permitERC4337Paymaster',
443
- type: 'bool',
444
- },
445
- ],
446
- internalType: 'struct Session',
447
- name: 'sessionToEnable',
448
- type: 'tuple',
449
- },
450
- {
451
- type: 'bytes',
452
- name: 'permissionEnableSig',
453
- },
454
- ],
455
- internalType: 'struct EnableSession',
456
- name: 'enableSession',
457
- type: 'tuple',
458
- },
459
- {
460
- type: 'bytes',
461
- name: 'signature',
462
- },
463
- ], [
464
- {
465
- chainDigestIndex: enableSessionData.chainDigestIndex,
466
- hashesAndChainIds: enableSessionData.hashesAndChainIds,
467
- sessionToEnable: enableSessionData.sessionToEnable,
468
- permissionEnableSig: enableSessionData.signature,
469
- },
470
- signature,
471
- ]);
472
- }
473
- function getPermissionId(session) {
474
- const sessionValidator = (0, core_1.getValidator)(session.owners);
475
- return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
476
- {
477
- type: 'address',
478
- name: 'sessionValidator',
479
- },
480
- {
481
- type: 'bytes',
482
- name: 'sessionValidatorInitData',
483
- },
484
- {
485
- type: 'bytes32',
486
- name: 'salt',
487
- },
488
- ], [
489
- sessionValidator.address,
490
- sessionValidator.initData,
491
- session.salt ?? viem_1.zeroHash,
492
- ]));
616
+ function createFixedArray(length, getValue) {
617
+ return Array.from({ length }, (_, i) => getValue(i));
493
618
  }