@charterlabs/rhinestone-sdk 0.3.0 → 0.3.1

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 (123) hide show
  1. package/dist/src/accounts/error.d.ts +8 -1
  2. package/dist/src/accounts/error.d.ts.map +1 -1
  3. package/dist/src/accounts/error.js +10 -1
  4. package/dist/src/accounts/index.d.ts +9 -9
  5. package/dist/src/accounts/index.d.ts.map +1 -1
  6. package/dist/src/accounts/index.js +65 -44
  7. package/dist/src/accounts/kernel.d.ts +3 -5
  8. package/dist/src/accounts/kernel.d.ts.map +1 -1
  9. package/dist/src/accounts/kernel.js +8 -17
  10. package/dist/src/accounts/kernel.test.js +10 -3
  11. package/dist/src/accounts/nexus.d.ts +3 -5
  12. package/dist/src/accounts/nexus.d.ts.map +1 -1
  13. package/dist/src/accounts/nexus.js +108 -57
  14. package/dist/src/accounts/nexus.test.js +10 -3
  15. package/dist/src/accounts/passport.d.ts +4 -7
  16. package/dist/src/accounts/passport.d.ts.map +1 -1
  17. package/dist/src/accounts/passport.js +0 -91
  18. package/dist/src/accounts/safe.d.ts +9 -4
  19. package/dist/src/accounts/safe.d.ts.map +1 -1
  20. package/dist/src/accounts/safe.js +108 -38
  21. package/dist/src/accounts/safe.test.js +10 -3
  22. package/dist/src/accounts/signing/common.d.ts +3 -3
  23. package/dist/src/accounts/signing/common.d.ts.map +1 -1
  24. package/dist/src/accounts/signing/common.js +36 -3
  25. package/dist/src/accounts/signing/message.js +2 -2
  26. package/dist/src/accounts/signing/typedData.d.ts.map +1 -1
  27. package/dist/src/accounts/signing/typedData.js +3 -3
  28. package/dist/src/accounts/startale.d.ts +2 -4
  29. package/dist/src/accounts/startale.d.ts.map +1 -1
  30. package/dist/src/accounts/startale.js +0 -4
  31. package/dist/src/accounts/utils.d.ts.map +1 -1
  32. package/dist/src/accounts/utils.js +10 -3
  33. package/dist/src/accounts/walletClient.d.ts.map +1 -1
  34. package/dist/src/accounts/walletClient.js +6 -0
  35. package/dist/src/actions/compact.d.ts +3 -2
  36. package/dist/src/actions/compact.d.ts.map +1 -1
  37. package/dist/src/actions/compact.js +1 -0
  38. package/dist/src/actions/deployment.d.ts +19 -0
  39. package/dist/src/actions/deployment.d.ts.map +1 -0
  40. package/dist/src/actions/deployment.js +78 -0
  41. package/dist/src/actions/index.d.ts +3 -1
  42. package/dist/src/actions/index.d.ts.map +1 -1
  43. package/dist/src/actions/index.js +12 -0
  44. package/dist/src/actions/smart-sessions.d.ts +7 -8
  45. package/dist/src/actions/smart-sessions.d.ts.map +1 -1
  46. package/dist/src/actions/smart-sessions.js +7 -4
  47. package/dist/src/errors/index.d.ts +2 -2
  48. package/dist/src/errors/index.d.ts.map +1 -1
  49. package/dist/src/errors/index.js +2 -1
  50. package/dist/src/execution/compact.d.ts +12 -17
  51. package/dist/src/execution/compact.d.ts.map +1 -1
  52. package/dist/src/execution/compact.js +10 -16
  53. package/dist/src/execution/error.d.ts +1 -8
  54. package/dist/src/execution/error.d.ts.map +1 -1
  55. package/dist/src/execution/error.js +1 -10
  56. package/dist/src/execution/index.d.ts +3 -3
  57. package/dist/src/execution/index.d.ts.map +1 -1
  58. package/dist/src/execution/index.js +10 -21
  59. package/dist/src/execution/permit2.d.ts +12 -17
  60. package/dist/src/execution/permit2.d.ts.map +1 -1
  61. package/dist/src/execution/permit2.js +10 -16
  62. package/dist/src/execution/singleChainOps.d.ts +15 -3
  63. package/dist/src/execution/singleChainOps.d.ts.map +1 -1
  64. package/dist/src/execution/singleChainOps.js +17 -3
  65. package/dist/src/execution/utils.d.ts +29 -7
  66. package/dist/src/execution/utils.d.ts.map +1 -1
  67. package/dist/src/execution/utils.js +103 -127
  68. package/dist/src/index.d.ts +22 -6
  69. package/dist/src/index.d.ts.map +1 -1
  70. package/dist/src/index.js +36 -5
  71. package/dist/src/modules/abi/smart-session-emissary.d.ts +696 -0
  72. package/dist/src/modules/abi/smart-session-emissary.d.ts.map +1 -0
  73. package/dist/src/modules/abi/smart-session-emissary.js +565 -0
  74. package/dist/src/modules/chain-abstraction.d.ts +5 -0
  75. package/dist/src/modules/chain-abstraction.d.ts.map +1 -0
  76. package/dist/src/modules/chain-abstraction.js +7 -0
  77. package/dist/src/modules/common.d.ts +7 -1
  78. package/dist/src/modules/common.d.ts.map +1 -1
  79. package/dist/src/modules/index.d.ts +3 -9
  80. package/dist/src/modules/index.d.ts.map +1 -1
  81. package/dist/src/modules/index.js +10 -8
  82. package/dist/src/modules/index.test.js +3 -9
  83. package/dist/src/modules/legacy.d.ts +10 -0
  84. package/dist/src/modules/legacy.d.ts.map +1 -0
  85. package/dist/src/modules/legacy.js +65 -0
  86. package/dist/src/modules/validators/core.d.ts.map +1 -1
  87. package/dist/src/modules/validators/core.js +2 -0
  88. package/dist/src/modules/validators/index.d.ts +2 -2
  89. package/dist/src/modules/validators/index.d.ts.map +1 -1
  90. package/dist/src/modules/validators/index.js +1 -6
  91. package/dist/src/modules/validators/smart-sessions.d.ts +105 -20
  92. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
  93. package/dist/src/modules/validators/smart-sessions.js +199 -435
  94. package/dist/src/orchestrator/client.d.ts +7 -3
  95. package/dist/src/orchestrator/client.d.ts.map +1 -1
  96. package/dist/src/orchestrator/client.js +3 -13
  97. package/dist/src/orchestrator/index.d.ts +2 -2
  98. package/dist/src/orchestrator/index.d.ts.map +1 -1
  99. package/dist/src/orchestrator/index.js +2 -1
  100. package/dist/src/orchestrator/registry.d.ts +2 -1
  101. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  102. package/dist/src/orchestrator/registry.js +12 -0
  103. package/dist/src/orchestrator/registry.test.js +13 -0
  104. package/dist/src/orchestrator/types.d.ts +8 -5
  105. package/dist/src/orchestrator/types.d.ts.map +1 -1
  106. package/dist/src/types.d.ts +31 -21
  107. package/dist/src/types.d.ts.map +1 -1
  108. package/dist/src/utils/index.d.ts +14 -2
  109. package/dist/src/utils/index.d.ts.map +1 -1
  110. package/dist/src/utils/index.js +46 -4
  111. package/dist/test/utils/utils.d.ts +5 -0
  112. package/dist/test/utils/utils.d.ts.map +1 -0
  113. package/dist/test/utils/utils.js +20 -0
  114. package/package.json +32 -2
  115. package/dist/src/execution/smart-session.d.ts +0 -13
  116. package/dist/src/execution/smart-session.d.ts.map +0 -1
  117. package/dist/src/execution/smart-session.js +0 -178
  118. package/dist/src/modules/omni-account.d.ts +0 -8
  119. package/dist/src/modules/omni-account.d.ts.map +0 -1
  120. package/dist/src/modules/omni-account.js +0 -13
  121. package/dist/src/modules/validators/smart-sessions.test.d.ts +0 -2
  122. package/dist/src/modules/validators/smart-sessions.test.d.ts.map +0 -1
  123. package/dist/src/modules/validators/smart-sessions.test.js +0 -222
@@ -1,477 +1,225 @@
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.getSessionData = getSessionData;
6
8
  exports.getEnableSessionCall = getEnableSessionCall;
7
- exports.encodeSmartSessionSignature = encodeSmartSessionSignature;
8
9
  exports.getPermissionId = getPermissionId;
9
- exports.isSessionEnabled = isSessionEnabled;
10
- const solady_1 = require("solady");
10
+ exports.getSmartSessionValidator = getSmartSessionValidator;
11
+ exports.getSessionDetails = getSessionDetails;
11
12
  const viem_1 = require("viem");
12
- const smart_sessions_1 = require("../abi/smart-sessions");
13
+ const compact_1 = require("../../actions/compact");
14
+ const smart_session_emissary_1 = __importDefault(require("../abi/smart-session-emissary"));
13
15
  const common_1 = require("../common");
14
16
  const core_1 = require("./core");
15
- const SMART_SESSIONS_VALIDATOR_ADDRESS = '0x00000000008bdaba73cd9815d79069c247eb4bda';
16
- exports.SMART_SESSIONS_VALIDATOR_ADDRESS = SMART_SESSIONS_VALIDATOR_ADDRESS;
17
+ const types = {
18
+ PolicyData: [
19
+ { name: 'policy', type: 'address' },
20
+ { name: 'initData', type: 'bytes' },
21
+ ],
22
+ ActionData: [
23
+ { name: 'actionTargetSelector', type: 'bytes4' },
24
+ { name: 'actionTarget', type: 'address' },
25
+ { name: 'actionPolicies', type: 'PolicyData[]' },
26
+ ],
27
+ ERC7739Context: [
28
+ { name: 'appDomainSeparator', type: 'bytes32' },
29
+ { name: 'contentName', type: 'string[]' },
30
+ ],
31
+ ERC7739Data: [
32
+ { name: 'allowedERC7739Content', type: 'ERC7739Context[]' },
33
+ { name: 'erc1271Policies', type: 'PolicyData[]' },
34
+ ],
35
+ LockTagData: [
36
+ { name: 'lockTag', type: 'bytes12' },
37
+ { name: 'claimPolicies', type: 'PolicyData[]' },
38
+ ],
39
+ SignedPermissions: [
40
+ { name: 'actions', type: 'ActionData[]' },
41
+ { name: 'erc7739Policies', type: 'ERC7739Data' },
42
+ { name: 'lockTagPolicies', type: 'LockTagData' },
43
+ { name: 'permitGenericPolicy', type: 'bool' },
44
+ ],
45
+ SignedSession: [
46
+ { name: 'account', type: 'address' },
47
+ { name: 'expires', type: 'uint256' },
48
+ { name: 'nonce', type: 'uint256' },
49
+ { name: 'permissions', type: 'SignedPermissions' },
50
+ { name: 'salt', type: 'bytes32' },
51
+ { name: 'sessionValidator', type: 'address' },
52
+ { name: 'sessionValidatorInitData', type: 'bytes' },
53
+ { name: 'smartSessionEmissary', type: 'address' },
54
+ ],
55
+ ChainSession: [
56
+ { name: 'chainId', type: 'uint64' },
57
+ { name: 'session', type: 'SignedSession' },
58
+ ],
59
+ MultiChainSession: [{ name: 'sessionsAndChainIds', type: 'ChainSession[]' }],
60
+ };
61
+ const SMART_SESSION_EMISSARY_ADDRESS = '0x4411abbbede0215626284d0385dd55b4303012b7';
62
+ exports.SMART_SESSION_EMISSARY_ADDRESS = SMART_SESSION_EMISSARY_ADDRESS;
17
63
  const SMART_SESSION_MODE_USE = '0x00';
18
- exports.SMART_SESSION_MODE_USE = SMART_SESSION_MODE_USE;
19
64
  const SMART_SESSION_MODE_ENABLE = '0x01';
20
- exports.SMART_SESSION_MODE_ENABLE = SMART_SESSION_MODE_ENABLE;
21
65
  const SMART_SESSION_MODE_UNSAFE_ENABLE = '0x02';
22
- const SPENDING_LIMITS_POLICY_ADDRESS = '0x00000088D48cF102A8Cdb0137A9b173f957c6343';
23
- const TIME_FRAME_POLICY_ADDRESS = '0x8177451511dE0577b911C254E9551D981C26dc72';
24
66
  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
67
  const SMART_SESSIONS_FALLBACK_TARGET_FLAG = '0x0000000000000000000000000000000000000001';
29
68
  exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = SMART_SESSIONS_FALLBACK_TARGET_FLAG;
30
69
  const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = '0x00000001';
31
70
  exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG;
32
71
  const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = '0x00000002';
33
72
  exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION;
34
- const ACTION_CONDITION_EQUAL = 0;
35
- const ACTION_CONDITION_GREATER_THAN = 1;
36
- const ACTION_CONDITION_LESS_THAN = 2;
37
- const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
38
- const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
39
- const ACTION_CONDITION_NOT_EQUAL = 5;
40
- 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]],
73
+ const SCOPE_MULTICHAIN = 0;
74
+ const RESET_PERIOD_ONE_WEEK = 6;
75
+ async function getSessionDetails(account, sessions) {
76
+ const lockTag = (0, compact_1.lockTag)();
77
+ const sessionNonces = await Promise.all(sessions.map((session) => getSessionNonce(account, session, lockTag)));
78
+ const sessionDatas = sessions.map((session) => getSessionData(session));
79
+ const signedSessions = sessionDatas.map((session, index) => getSignedSession(account, lockTag, session, sessionNonces[index]));
80
+ const chains = sessions.map((session) => session.chain);
81
+ const chainDigests = signedSessions.map((session, index) => ({
82
+ chainId: BigInt(chains[index].id),
83
+ sessionDigest: (0, viem_1.hashStruct)({
84
+ types: types,
85
+ primaryType: 'SignedSession',
86
+ data: session,
49
87
  }),
50
- };
51
- }
52
- function getSmartSessionData(session) {
53
- const sessionValidator = (0, core_1.getValidator)(session.owners);
54
- const userOpPolicies = (session.policies || [
55
- {
56
- type: 'sudo',
88
+ }));
89
+ const hashesAndChainIds = chainDigests.map((chainDigest) => ({
90
+ chainId: BigInt(chainDigest.chainId),
91
+ sessionDigest: chainDigest.sessionDigest,
92
+ }));
93
+ const data = {
94
+ domain: {
95
+ name: 'SmartSessionEmissary',
96
+ version: '1.0.0',
97
+ },
98
+ types: types,
99
+ primaryType: 'MultiChainSession',
100
+ message: {
101
+ sessionsAndChainIds: signedSessions.map((session, index) => ({
102
+ chainId: BigInt(chains[index].id),
103
+ session,
104
+ })),
57
105
  },
58
- ]).map((policy) => {
59
- return getPolicyData(policy);
60
- });
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 || [
68
- {
69
- target: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
70
- selector: SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
71
- },
72
- ]).map((action) => {
73
- const actionPolicies = (action.policies || [
74
- {
75
- type: 'sudo',
76
- },
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',
93
- },
94
- ]).map((policy) => getPolicyData(policy)),
95
- }
96
- : {
97
- allowedERC7739Content: [],
98
- erc1271Policies: [],
99
- },
100
- permitERC4337Paymaster: true,
101
106
  };
102
- }
103
- function getSmartSessionValidator(config) {
104
- if (!config.sessions) {
105
- return null;
106
- }
107
107
  return {
108
- address: SMART_SESSIONS_VALIDATOR_ADDRESS,
109
- initData: '0x',
110
- deInitData: '0x',
111
- additionalContext: '0x',
112
- type: common_1.MODULE_TYPE_ID_VALIDATOR,
108
+ nonces: sessionNonces,
109
+ hashesAndChainIds,
110
+ data,
113
111
  };
114
112
  }
115
- function getPolicyData(policy) {
116
- switch (policy.type) {
117
- case 'sudo':
118
- return {
119
- policy: SUDO_POLICY_ADDRESS,
120
- initData: '0x',
121
- };
122
- case 'universal-action': {
123
- function getCondition(condition) {
124
- switch (condition) {
125
- case 'equal':
126
- return ACTION_CONDITION_EQUAL;
127
- case 'greaterThan':
128
- return ACTION_CONDITION_GREATER_THAN;
129
- case 'lessThan':
130
- return ACTION_CONDITION_LESS_THAN;
131
- case 'greaterThanOrEqual':
132
- return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
133
- case 'lessThanOrEqual':
134
- return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
135
- case 'notEqual':
136
- return ACTION_CONDITION_NOT_EQUAL;
137
- case 'inRange':
138
- return ACTION_CONDITION_IN_RANGE;
139
- }
140
- }
141
- const MAX_RULES = 16;
142
- const rules = createFixedArray(MAX_RULES, () => ({
143
- condition: ACTION_CONDITION_EQUAL,
144
- offset: 0n,
145
- isLimited: false,
146
- ref: viem_1.zeroHash,
147
- usage: { limit: 0n, used: 0n },
148
- }));
149
- for (let i = 0; i < policy.rules.length; i++) {
150
- const rule = policy.rules[i];
151
- const ref = (0, viem_1.isHex)(rule.referenceValue)
152
- ? (0, viem_1.padHex)(rule.referenceValue)
153
- : (0, viem_1.toHex)(rule.referenceValue, { size: 32 });
154
- rules[i] = {
155
- condition: getCondition(rule.condition),
156
- offset: rule.calldataOffset,
157
- isLimited: rule.usageLimit !== undefined,
158
- ref,
159
- usage: {
160
- limit: rule.usageLimit ? rule.usageLimit : 0n,
161
- used: 0n,
162
- },
163
- };
164
- }
165
- return {
166
- policy: UNIVERSAL_ACTION_POLICY_ADDRESS,
167
- initData: (0, viem_1.encodeAbiParameters)([
168
- {
169
- components: [
170
- {
171
- name: 'valueLimitPerUse',
172
- type: 'uint256',
173
- },
174
- {
175
- components: [
176
- {
177
- name: 'length',
178
- type: 'uint256',
179
- },
180
- {
181
- components: [
182
- {
183
- name: 'condition',
184
- type: 'uint8',
185
- },
186
- {
187
- name: 'offset',
188
- type: 'uint64',
189
- },
190
- {
191
- name: 'isLimited',
192
- type: 'bool',
193
- },
194
- {
195
- name: 'ref',
196
- type: 'bytes32',
197
- },
198
- {
199
- components: [
200
- {
201
- name: 'limit',
202
- type: 'uint256',
203
- },
204
- {
205
- name: 'used',
206
- type: 'uint256',
207
- },
208
- ],
209
- name: 'usage',
210
- type: 'tuple',
211
- },
212
- ],
213
- name: 'rules',
214
- type: 'tuple[16]',
215
- },
216
- ],
217
- name: 'paramRules',
218
- type: 'tuple',
219
- },
220
- ],
221
- name: 'ActionConfig',
222
- type: 'tuple',
223
- },
224
- ], [
225
- {
226
- valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
227
- paramRules: {
228
- length: BigInt(policy.rules.length),
229
- rules: rules,
230
- },
231
- },
232
- ]),
233
- };
234
- }
235
- case 'spending-limits': {
236
- const tokens = policy.limits.map(({ token }) => token);
237
- const limits = policy.limits.map(({ amount }) => amount);
238
- return {
239
- policy: SPENDING_LIMITS_POLICY_ADDRESS,
240
- initData: (0, viem_1.encodeAbiParameters)([{ type: 'address[]' }, { type: 'uint256[]' }], [tokens, limits]),
241
- };
242
- }
243
- case 'time-frame': {
244
- return {
245
- policy: TIME_FRAME_POLICY_ADDRESS,
246
- initData: (0, viem_1.encodePacked)(['uint48', 'uint48'], [
247
- Math.floor(policy.validUntil / 1000),
248
- Math.floor(policy.validAfter / 1000),
249
- ]),
250
- };
251
- }
252
- case 'usage-limit': {
253
- return {
254
- policy: USAGE_LIMIT_POLICY_ADDRESS,
255
- initData: (0, viem_1.encodePacked)(['uint128'], [policy.limit]),
256
- };
257
- }
258
- case 'value-limit': {
259
- return {
260
- policy: VALUE_LIMIT_POLICY_ADDRESS,
261
- initData: (0, viem_1.encodeAbiParameters)([{ type: 'uint256' }], [policy.limit]),
262
- };
263
- }
264
- }
265
- }
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,
113
+ async function getSessionNonce(account, session, lockTag) {
114
+ const publicClient = (0, viem_1.createPublicClient)({
115
+ chain: session.chain,
116
+ transport: (0, viem_1.http)(),
117
+ });
118
+ const nonce = await publicClient.readContract({
119
+ address: SMART_SESSION_EMISSARY_ADDRESS,
272
120
  abi: [
273
121
  {
122
+ type: 'function',
123
+ name: 'getNonce',
274
124
  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
- },
125
+ { name: 'sponsor', type: 'address', internalType: 'address' },
126
+ { name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
293
127
  ],
128
+ outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
294
129
  stateMutability: 'view',
295
- type: 'function',
296
130
  },
297
131
  ],
298
- functionName: 'isPermissionEnabled',
299
- args: [permissionId, address],
132
+ functionName: 'getNonce',
133
+ args: [account, lockTag],
300
134
  });
135
+ return nonce;
301
136
  }
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}`);
317
- }
137
+ function getSignedSession(account, lockTag, session, nonce) {
138
+ return {
139
+ account,
140
+ permissions: {
141
+ permitGenericPolicy: session.actions.some((action) => action.actionTarget === SMART_SESSIONS_FALLBACK_TARGET_FLAG &&
142
+ action.actionTargetSelector ===
143
+ SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG),
144
+ lockTagPolicies: {
145
+ lockTag,
146
+ claimPolicies: session.claimPolicies,
147
+ },
148
+ erc7739Policies: {
149
+ allowedERC7739Content: session.erc7739Policies.allowedERC7739Content.map((content) => ({
150
+ contentName: content.contentNames,
151
+ appDomainSeparator: content.appDomainSeparator,
152
+ })),
153
+ erc1271Policies: session.erc7739Policies.erc1271Policies,
154
+ },
155
+ actions: session.actions,
156
+ },
157
+ sessionValidator: session.sessionValidator,
158
+ sessionValidatorInitData: session.sessionValidatorInitData,
159
+ salt: session.salt,
160
+ smartSessionEmissary: SMART_SESSION_EMISSARY_ADDRESS,
161
+ expires: viem_1.maxUint256,
162
+ nonce,
163
+ };
318
164
  }
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
- },
165
+ async function getEnableSessionCall(account, session, enableSessionSignature, hashesAndChainIds, sessionToEnableIndex) {
166
+ const sessionData = getSessionData(session);
167
+ const permissionId = getPermissionId(session);
168
+ return {
169
+ to: SMART_SESSION_EMISSARY_ADDRESS,
170
+ data: (0, viem_1.encodeFunctionData)({
171
+ abi: smart_session_emissary_1.default,
172
+ functionName: 'setConfig',
173
+ args: [
174
+ account,
343
175
  {
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',
176
+ scope: SCOPE_MULTICHAIN,
177
+ resetPeriod: RESET_PERIOD_ONE_WEEK,
178
+ allocator: viem_1.zeroAddress,
179
+ permissionId,
449
180
  },
450
181
  {
451
- type: 'bytes',
452
- name: 'permissionEnableSig',
182
+ allocatorSig: viem_1.zeroHash,
183
+ userSig: enableSessionSignature,
184
+ expires: viem_1.maxUint256,
185
+ session: {
186
+ chainDigestIndex: sessionToEnableIndex,
187
+ hashesAndChainIds,
188
+ sessionToEnable: sessionData,
189
+ },
453
190
  },
454
191
  ],
455
- internalType: 'struct EnableSession',
456
- name: 'enableSession',
457
- type: 'tuple',
458
- },
459
- {
460
- type: 'bytes',
461
- name: 'signature',
462
- },
463
- ], [
192
+ }),
193
+ };
194
+ }
195
+ function getSessionData(session) {
196
+ const validator = (0, core_1.getValidator)(session.owners);
197
+ const allowedContent = [
464
198
  {
465
- chainDigestIndex: enableSessionData.chainDigestIndex,
466
- hashesAndChainIds: enableSessionData.hashesAndChainIds,
467
- sessionToEnable: enableSessionData.sessionToEnable,
468
- permissionEnableSig: enableSessionData.signature,
199
+ contentNames: [''],
200
+ appDomainSeparator: viem_1.zeroHash,
469
201
  },
470
- signature,
471
- ]);
202
+ ];
203
+ const erc7739Data = {
204
+ allowedERC7739Content: allowedContent,
205
+ erc1271Policies: [
206
+ {
207
+ policy: SUDO_POLICY_ADDRESS,
208
+ initData: '0x',
209
+ },
210
+ ],
211
+ };
212
+ return {
213
+ sessionValidator: validator.address,
214
+ salt: viem_1.zeroHash,
215
+ sessionValidatorInitData: validator.initData,
216
+ erc7739Policies: erc7739Data,
217
+ actions: [],
218
+ claimPolicies: [],
219
+ };
472
220
  }
473
221
  function getPermissionId(session) {
474
- const sessionValidator = (0, core_1.getValidator)(session.owners);
222
+ const sessionData = getSessionData(session);
475
223
  return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
476
224
  {
477
225
  type: 'address',
@@ -486,8 +234,24 @@ function getPermissionId(session) {
486
234
  name: 'salt',
487
235
  },
488
236
  ], [
489
- sessionValidator.address,
490
- sessionValidator.initData,
491
- session.salt ?? viem_1.zeroHash,
237
+ sessionData.sessionValidator,
238
+ sessionData.sessionValidatorInitData,
239
+ sessionData.salt,
492
240
  ]));
493
241
  }
242
+ function getSmartSessionValidator(config) {
243
+ if (!config.experimental_sessions) {
244
+ return null;
245
+ }
246
+ const { enabled, module } = config.experimental_sessions;
247
+ if (!enabled) {
248
+ return null;
249
+ }
250
+ return {
251
+ address: module ?? SMART_SESSION_EMISSARY_ADDRESS,
252
+ initData: '0x',
253
+ deInitData: '0x',
254
+ additionalContext: '0x',
255
+ type: common_1.MODULE_TYPE_ID_VALIDATOR,
256
+ };
257
+ }