@rhinestone/sdk 1.0.43 → 1.1.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.
- package/dist/src/accounts/index.d.ts +2 -5
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +0 -37
- package/dist/src/accounts/kernel.d.ts +2 -4
- package/dist/src/accounts/kernel.d.ts.map +1 -1
- package/dist/src/accounts/kernel.js +0 -16
- package/dist/src/accounts/nexus.d.ts +2 -4
- package/dist/src/accounts/nexus.d.ts.map +1 -1
- package/dist/src/accounts/nexus.js +0 -16
- package/dist/src/accounts/passport.d.ts +4 -7
- package/dist/src/accounts/passport.d.ts.map +1 -1
- package/dist/src/accounts/passport.js +0 -91
- package/dist/src/accounts/safe.d.ts +2 -4
- package/dist/src/accounts/safe.d.ts.map +1 -1
- package/dist/src/accounts/safe.js +0 -16
- package/dist/src/accounts/signing/common.d.ts +3 -3
- package/dist/src/accounts/signing/common.d.ts.map +1 -1
- package/dist/src/accounts/signing/common.js +18 -2
- package/dist/src/accounts/signing/message.js +2 -2
- package/dist/src/accounts/signing/typedData.d.ts.map +1 -1
- package/dist/src/accounts/signing/typedData.js +3 -3
- package/dist/src/accounts/startale.d.ts +2 -4
- package/dist/src/accounts/startale.d.ts.map +1 -1
- package/dist/src/accounts/startale.js +0 -4
- package/dist/src/actions/compact.d.ts +3 -2
- package/dist/src/actions/compact.d.ts.map +1 -1
- package/dist/src/actions/compact.js +1 -0
- package/dist/src/actions/smart-sessions.d.ts +7 -8
- package/dist/src/actions/smart-sessions.d.ts.map +1 -1
- package/dist/src/actions/smart-sessions.js +7 -4
- package/dist/src/execution/error.d.ts +1 -8
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +1 -10
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +3 -12
- package/dist/src/execution/utils.d.ts +1 -1
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +9 -17
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -4
- package/dist/src/modules/abi/smart-session-emissary.d.ts +696 -0
- package/dist/src/modules/abi/smart-session-emissary.d.ts.map +1 -0
- package/dist/src/modules/abi/smart-session-emissary.js +565 -0
- package/dist/src/modules/index.d.ts +2 -1
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +3 -1
- package/dist/src/modules/validators/core.d.ts.map +1 -1
- package/dist/src/modules/validators/core.js +2 -0
- package/dist/src/modules/validators/index.d.ts +2 -2
- package/dist/src/modules/validators/index.d.ts.map +1 -1
- package/dist/src/modules/validators/index.js +1 -6
- package/dist/src/modules/validators/smart-sessions.d.ts +105 -20
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +199 -439
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +1 -1
- package/dist/src/types.d.ts +8 -15
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/src/execution/smart-session.d.ts +0 -13
- package/dist/src/execution/smart-session.d.ts.map +0 -1
- package/dist/src/execution/smart-session.js +0 -178
- package/dist/src/modules/validators/smart-sessions.test.d.ts +0 -2
- package/dist/src/modules/validators/smart-sessions.test.d.ts.map +0 -1
- package/dist/src/modules/validators/smart-sessions.test.js +0 -219
|
@@ -1,481 +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.
|
|
4
|
-
exports.
|
|
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.
|
|
10
|
-
|
|
10
|
+
exports.getSmartSessionValidator = getSmartSessionValidator;
|
|
11
|
+
exports.getSessionDetails = getSessionDetails;
|
|
11
12
|
const viem_1 = require("viem");
|
|
12
|
-
const
|
|
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
|
|
16
|
-
|
|
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
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.experimental_sessions) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
const { enabled, module } = config.experimental_sessions;
|
|
108
|
-
if (!enabled) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
107
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
additionalContext: '0x',
|
|
116
|
-
type: common_1.MODULE_TYPE_ID_VALIDATOR,
|
|
108
|
+
nonces: sessionNonces,
|
|
109
|
+
hashesAndChainIds,
|
|
110
|
+
data,
|
|
117
111
|
};
|
|
118
112
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
case 'universal-action': {
|
|
127
|
-
function getCondition(condition) {
|
|
128
|
-
switch (condition) {
|
|
129
|
-
case 'equal':
|
|
130
|
-
return ACTION_CONDITION_EQUAL;
|
|
131
|
-
case 'greaterThan':
|
|
132
|
-
return ACTION_CONDITION_GREATER_THAN;
|
|
133
|
-
case 'lessThan':
|
|
134
|
-
return ACTION_CONDITION_LESS_THAN;
|
|
135
|
-
case 'greaterThanOrEqual':
|
|
136
|
-
return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
|
|
137
|
-
case 'lessThanOrEqual':
|
|
138
|
-
return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
|
|
139
|
-
case 'notEqual':
|
|
140
|
-
return ACTION_CONDITION_NOT_EQUAL;
|
|
141
|
-
case 'inRange':
|
|
142
|
-
return ACTION_CONDITION_IN_RANGE;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const MAX_RULES = 16;
|
|
146
|
-
const rules = createFixedArray(MAX_RULES, () => ({
|
|
147
|
-
condition: ACTION_CONDITION_EQUAL,
|
|
148
|
-
offset: 0n,
|
|
149
|
-
isLimited: false,
|
|
150
|
-
ref: viem_1.zeroHash,
|
|
151
|
-
usage: { limit: 0n, used: 0n },
|
|
152
|
-
}));
|
|
153
|
-
for (let i = 0; i < policy.rules.length; i++) {
|
|
154
|
-
const rule = policy.rules[i];
|
|
155
|
-
const ref = (0, viem_1.isHex)(rule.referenceValue)
|
|
156
|
-
? (0, viem_1.padHex)(rule.referenceValue)
|
|
157
|
-
: (0, viem_1.toHex)(rule.referenceValue, { size: 32 });
|
|
158
|
-
rules[i] = {
|
|
159
|
-
condition: getCondition(rule.condition),
|
|
160
|
-
offset: rule.calldataOffset,
|
|
161
|
-
isLimited: rule.usageLimit !== undefined,
|
|
162
|
-
ref,
|
|
163
|
-
usage: {
|
|
164
|
-
limit: rule.usageLimit ? rule.usageLimit : 0n,
|
|
165
|
-
used: 0n,
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
policy: UNIVERSAL_ACTION_POLICY_ADDRESS,
|
|
171
|
-
initData: (0, viem_1.encodeAbiParameters)([
|
|
172
|
-
{
|
|
173
|
-
components: [
|
|
174
|
-
{
|
|
175
|
-
name: 'valueLimitPerUse',
|
|
176
|
-
type: 'uint256',
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
components: [
|
|
180
|
-
{
|
|
181
|
-
name: 'length',
|
|
182
|
-
type: 'uint256',
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
components: [
|
|
186
|
-
{
|
|
187
|
-
name: 'condition',
|
|
188
|
-
type: 'uint8',
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: 'offset',
|
|
192
|
-
type: 'uint64',
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: 'isLimited',
|
|
196
|
-
type: 'bool',
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: 'ref',
|
|
200
|
-
type: 'bytes32',
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
components: [
|
|
204
|
-
{
|
|
205
|
-
name: 'limit',
|
|
206
|
-
type: 'uint256',
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
name: 'used',
|
|
210
|
-
type: 'uint256',
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
name: 'usage',
|
|
214
|
-
type: 'tuple',
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
name: 'rules',
|
|
218
|
-
type: 'tuple[16]',
|
|
219
|
-
},
|
|
220
|
-
],
|
|
221
|
-
name: 'paramRules',
|
|
222
|
-
type: 'tuple',
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
name: 'ActionConfig',
|
|
226
|
-
type: 'tuple',
|
|
227
|
-
},
|
|
228
|
-
], [
|
|
229
|
-
{
|
|
230
|
-
valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
|
|
231
|
-
paramRules: {
|
|
232
|
-
length: BigInt(policy.rules.length),
|
|
233
|
-
rules: rules,
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
]),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
case 'spending-limits': {
|
|
240
|
-
const tokens = policy.limits.map(({ token }) => token);
|
|
241
|
-
const limits = policy.limits.map(({ amount }) => amount);
|
|
242
|
-
return {
|
|
243
|
-
policy: SPENDING_LIMITS_POLICY_ADDRESS,
|
|
244
|
-
initData: (0, viem_1.encodeAbiParameters)([{ type: 'address[]' }, { type: 'uint256[]' }], [tokens, limits]),
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
case 'time-frame': {
|
|
248
|
-
return {
|
|
249
|
-
policy: TIME_FRAME_POLICY_ADDRESS,
|
|
250
|
-
initData: (0, viem_1.encodePacked)(['uint48', 'uint48'], [
|
|
251
|
-
Math.floor(policy.validUntil / 1000),
|
|
252
|
-
Math.floor(policy.validAfter / 1000),
|
|
253
|
-
]),
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
case 'usage-limit': {
|
|
257
|
-
return {
|
|
258
|
-
policy: USAGE_LIMIT_POLICY_ADDRESS,
|
|
259
|
-
initData: (0, viem_1.encodePacked)(['uint128'], [policy.limit]),
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
case 'value-limit': {
|
|
263
|
-
return {
|
|
264
|
-
policy: VALUE_LIMIT_POLICY_ADDRESS,
|
|
265
|
-
initData: (0, viem_1.encodeAbiParameters)([{ type: 'uint256' }], [policy.limit]),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function createFixedArray(length, getValue) {
|
|
271
|
-
return Array.from({ length }, (_, i) => getValue(i));
|
|
272
|
-
}
|
|
273
|
-
async function isSessionEnabled(client, address, permissionId) {
|
|
274
|
-
return await client.readContract({
|
|
275
|
-
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,
|
|
276
120
|
abi: [
|
|
277
121
|
{
|
|
122
|
+
type: 'function',
|
|
123
|
+
name: 'getNonce',
|
|
278
124
|
inputs: [
|
|
279
|
-
{
|
|
280
|
-
|
|
281
|
-
name: 'permissionId',
|
|
282
|
-
type: 'bytes32',
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
internalType: 'address',
|
|
286
|
-
name: 'account',
|
|
287
|
-
type: 'address',
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
|
-
name: 'isPermissionEnabled',
|
|
291
|
-
outputs: [
|
|
292
|
-
{
|
|
293
|
-
internalType: 'bool',
|
|
294
|
-
name: '',
|
|
295
|
-
type: 'bool',
|
|
296
|
-
},
|
|
125
|
+
{ name: 'sponsor', type: 'address', internalType: 'address' },
|
|
126
|
+
{ name: 'lockTag', type: 'bytes12', internalType: 'bytes12' },
|
|
297
127
|
],
|
|
128
|
+
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
|
|
298
129
|
stateMutability: 'view',
|
|
299
|
-
type: 'function',
|
|
300
130
|
},
|
|
301
131
|
],
|
|
302
|
-
functionName: '
|
|
303
|
-
args: [
|
|
132
|
+
functionName: 'getNonce',
|
|
133
|
+
args: [account, lockTag],
|
|
304
134
|
});
|
|
135
|
+
return nonce;
|
|
305
136
|
}
|
|
306
|
-
function
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
+
};
|
|
322
164
|
}
|
|
323
|
-
function
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
components: [
|
|
334
|
-
{
|
|
335
|
-
internalType: 'uint64',
|
|
336
|
-
name: 'chainId',
|
|
337
|
-
type: 'uint64',
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
internalType: 'bytes32',
|
|
341
|
-
name: 'sessionDigest',
|
|
342
|
-
type: 'bytes32',
|
|
343
|
-
},
|
|
344
|
-
],
|
|
345
|
-
name: 'hashesAndChainIds',
|
|
346
|
-
},
|
|
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,
|
|
347
175
|
{
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
type: 'address',
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
internalType: 'bytes',
|
|
356
|
-
name: 'sessionValidatorInitData',
|
|
357
|
-
type: 'bytes',
|
|
358
|
-
},
|
|
359
|
-
{ internalType: 'bytes32', name: 'salt', type: 'bytes32' },
|
|
360
|
-
{
|
|
361
|
-
components: [
|
|
362
|
-
{ internalType: 'address', name: 'policy', type: 'address' },
|
|
363
|
-
{ internalType: 'bytes', name: 'initData', type: 'bytes' },
|
|
364
|
-
],
|
|
365
|
-
internalType: 'struct PolicyData[]',
|
|
366
|
-
name: 'userOpPolicies',
|
|
367
|
-
type: 'tuple[]',
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
components: [
|
|
371
|
-
{
|
|
372
|
-
components: [
|
|
373
|
-
{
|
|
374
|
-
internalType: 'bytes32',
|
|
375
|
-
name: 'appDomainSeparator',
|
|
376
|
-
type: 'bytes32',
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
internalType: 'string[]',
|
|
380
|
-
name: 'contentName',
|
|
381
|
-
type: 'string[]',
|
|
382
|
-
},
|
|
383
|
-
],
|
|
384
|
-
internalType: 'struct ERC7739Context[]',
|
|
385
|
-
name: 'allowedERC7739Content',
|
|
386
|
-
type: 'tuple[]',
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
components: [
|
|
390
|
-
{
|
|
391
|
-
internalType: 'address',
|
|
392
|
-
name: 'policy',
|
|
393
|
-
type: 'address',
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
internalType: 'bytes',
|
|
397
|
-
name: 'initData',
|
|
398
|
-
type: 'bytes',
|
|
399
|
-
},
|
|
400
|
-
],
|
|
401
|
-
internalType: 'struct PolicyData[]',
|
|
402
|
-
name: 'erc1271Policies',
|
|
403
|
-
type: 'tuple[]',
|
|
404
|
-
},
|
|
405
|
-
],
|
|
406
|
-
internalType: 'struct ERC7739Data',
|
|
407
|
-
name: 'erc7739Policies',
|
|
408
|
-
type: 'tuple',
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
components: [
|
|
412
|
-
{
|
|
413
|
-
internalType: 'bytes4',
|
|
414
|
-
name: 'actionTargetSelector',
|
|
415
|
-
type: 'bytes4',
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
internalType: 'address',
|
|
419
|
-
name: 'actionTarget',
|
|
420
|
-
type: 'address',
|
|
421
|
-
},
|
|
422
|
-
{
|
|
423
|
-
components: [
|
|
424
|
-
{
|
|
425
|
-
internalType: 'address',
|
|
426
|
-
name: 'policy',
|
|
427
|
-
type: 'address',
|
|
428
|
-
},
|
|
429
|
-
{
|
|
430
|
-
internalType: 'bytes',
|
|
431
|
-
name: 'initData',
|
|
432
|
-
type: 'bytes',
|
|
433
|
-
},
|
|
434
|
-
],
|
|
435
|
-
internalType: 'struct PolicyData[]',
|
|
436
|
-
name: 'actionPolicies',
|
|
437
|
-
type: 'tuple[]',
|
|
438
|
-
},
|
|
439
|
-
],
|
|
440
|
-
internalType: 'struct ActionData[]',
|
|
441
|
-
name: 'actions',
|
|
442
|
-
type: 'tuple[]',
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
internalType: 'bool',
|
|
446
|
-
name: 'permitERC4337Paymaster',
|
|
447
|
-
type: 'bool',
|
|
448
|
-
},
|
|
449
|
-
],
|
|
450
|
-
internalType: 'struct Session',
|
|
451
|
-
name: 'sessionToEnable',
|
|
452
|
-
type: 'tuple',
|
|
176
|
+
scope: SCOPE_MULTICHAIN,
|
|
177
|
+
resetPeriod: RESET_PERIOD_ONE_WEEK,
|
|
178
|
+
allocator: viem_1.zeroAddress,
|
|
179
|
+
permissionId,
|
|
453
180
|
},
|
|
454
181
|
{
|
|
455
|
-
|
|
456
|
-
|
|
182
|
+
allocatorSig: viem_1.zeroHash,
|
|
183
|
+
userSig: enableSessionSignature,
|
|
184
|
+
expires: viem_1.maxUint256,
|
|
185
|
+
session: {
|
|
186
|
+
chainDigestIndex: sessionToEnableIndex,
|
|
187
|
+
hashesAndChainIds,
|
|
188
|
+
sessionToEnable: sessionData,
|
|
189
|
+
},
|
|
457
190
|
},
|
|
458
191
|
],
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
name: 'signature',
|
|
466
|
-
},
|
|
467
|
-
], [
|
|
192
|
+
}),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function getSessionData(session) {
|
|
196
|
+
const validator = (0, core_1.getValidator)(session.owners);
|
|
197
|
+
const allowedContent = [
|
|
468
198
|
{
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
sessionToEnable: enableSessionData.sessionToEnable,
|
|
472
|
-
permissionEnableSig: enableSessionData.signature,
|
|
199
|
+
contentNames: [''],
|
|
200
|
+
appDomainSeparator: viem_1.zeroHash,
|
|
473
201
|
},
|
|
474
|
-
|
|
475
|
-
|
|
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
|
+
};
|
|
476
220
|
}
|
|
477
221
|
function getPermissionId(session) {
|
|
478
|
-
const
|
|
222
|
+
const sessionData = getSessionData(session);
|
|
479
223
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
|
|
480
224
|
{
|
|
481
225
|
type: 'address',
|
|
@@ -490,8 +234,24 @@ function getPermissionId(session) {
|
|
|
490
234
|
name: 'salt',
|
|
491
235
|
},
|
|
492
236
|
], [
|
|
493
|
-
sessionValidator
|
|
494
|
-
|
|
495
|
-
|
|
237
|
+
sessionData.sessionValidator,
|
|
238
|
+
sessionData.sessionValidatorInitData,
|
|
239
|
+
sessionData.salt,
|
|
496
240
|
]));
|
|
497
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
|
+
}
|