@rhinestone/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -19
- package/dist/accounts/index.d.ts +15535 -0
- package/dist/accounts/index.d.ts.map +1 -0
- package/dist/accounts/index.js +242 -0
- package/dist/accounts/nexus.d.ts +23281 -0
- package/dist/accounts/nexus.d.ts.map +1 -0
- package/dist/accounts/nexus.js +230 -0
- package/dist/accounts/safe.d.ts +15 -0
- package/dist/accounts/safe.d.ts.map +1 -0
- package/dist/{services/account → accounts}/safe.js +36 -37
- package/dist/accounts/utils.d.ts +27 -0
- package/dist/accounts/utils.d.ts.map +1 -0
- package/dist/accounts/utils.js +155 -0
- package/dist/examples/abi/weth.d.ts +214 -0
- package/dist/examples/abi/weth.d.ts.map +1 -0
- package/dist/examples/abi/weth.js +279 -0
- package/dist/examples/cross-chain-ss.d.ts +1 -0
- package/dist/examples/cross-chain-ss.d.ts.map +1 -0
- package/dist/{example.js → examples/cross-chain-ss.js} +70 -44
- package/dist/examples/omni-account.d.ts +1 -0
- package/dist/examples/omni-account.d.ts.map +1 -0
- package/dist/examples/omni-account.js +169 -0
- package/dist/examples/smart-sessions.d.ts +1 -0
- package/dist/examples/smart-sessions.d.ts.map +1 -0
- package/dist/examples/smart-sessions.js +216 -0
- package/dist/execution/index.d.ts +31 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +222 -0
- package/dist/execution/smart-session.d.ts +14 -0
- package/dist/execution/smart-session.d.ts.map +1 -0
- package/dist/execution/smart-session.js +83 -0
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/dist/modules/abi/smart-sessions.d.ts +42 -0
- package/dist/modules/abi/smart-sessions.d.ts.map +1 -0
- package/dist/modules/abi/smart-sessions.js +128 -0
- package/dist/modules/common.d.ts +16 -0
- package/dist/modules/common.d.ts.map +1 -0
- package/dist/modules/common.js +5 -0
- package/dist/modules/index.d.ts +33 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +129 -0
- package/dist/modules/omni-account.d.ts +9 -0
- package/dist/modules/omni-account.d.ts.map +1 -0
- package/dist/modules/omni-account.js +7 -0
- package/dist/modules/validators.d.ts +31 -0
- package/dist/modules/validators.d.ts.map +1 -0
- package/dist/modules/validators.js +518 -0
- package/dist/{services/orchestrator → orchestrator}/client.d.ts +2 -5
- package/dist/orchestrator/client.d.ts.map +1 -0
- package/dist/orchestrator/consts.d.ts +4 -0
- package/dist/orchestrator/consts.d.ts.map +1 -0
- package/dist/orchestrator/consts.js +3 -0
- package/dist/orchestrator/error.d.ts.map +1 -0
- package/dist/orchestrator/index.d.ts +9 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +10 -0
- package/dist/orchestrator/registry.d.ts +5 -0
- package/dist/orchestrator/registry.d.ts.map +1 -0
- package/dist/orchestrator/registry.js +187 -0
- package/dist/{services/orchestrator → orchestrator}/types.d.ts +39 -23
- package/dist/orchestrator/types.d.ts.map +1 -0
- package/dist/orchestrator/types.js +7 -0
- package/dist/orchestrator/utils.d.ts +11 -0
- package/dist/orchestrator/utils.d.ts.map +1 -0
- package/dist/{services/orchestrator → orchestrator}/utils.js +20 -6
- package/dist/types.d.ts +70 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/example.d.ts +0 -1
- package/dist/example.d.ts.map +0 -1
- package/dist/services/account/index.d.ts +0 -13
- package/dist/services/account/index.d.ts.map +0 -1
- package/dist/services/account/index.js +0 -54
- package/dist/services/account/nexus.d.ts +0 -9
- package/dist/services/account/nexus.d.ts.map +0 -1
- package/dist/services/account/nexus.js +0 -67
- package/dist/services/account/safe.d.ts +0 -9
- package/dist/services/account/safe.d.ts.map +0 -1
- package/dist/services/modules.d.ts +0 -32
- package/dist/services/modules.d.ts.map +0 -1
- package/dist/services/modules.js +0 -166
- package/dist/services/orchestrator/client.d.ts.map +0 -1
- package/dist/services/orchestrator/consts.d.ts +0 -6
- package/dist/services/orchestrator/consts.d.ts.map +0 -1
- package/dist/services/orchestrator/consts.js +0 -4
- package/dist/services/orchestrator/error.d.ts.map +0 -1
- package/dist/services/orchestrator/index.d.ts +0 -8
- package/dist/services/orchestrator/index.d.ts.map +0 -1
- package/dist/services/orchestrator/index.js +0 -9
- package/dist/services/orchestrator/types.d.ts.map +0 -1
- package/dist/services/orchestrator/types.js +0 -6
- package/dist/services/orchestrator/utils.d.ts +0 -7
- package/dist/services/orchestrator/utils.d.ts.map +0 -1
- package/dist/services/transaction.d.ts +0 -6
- package/dist/services/transaction.d.ts.map +0 -1
- package/dist/services/transaction.js +0 -93
- /package/dist/{services/orchestrator → orchestrator}/client.js +0 -0
- /package/dist/{services/orchestrator → orchestrator}/error.d.ts +0 -0
- /package/dist/{services/orchestrator → orchestrator}/error.js +0 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import { bytesToHex, concat, createPublicClient, encodeAbiParameters, encodeFunctionData, encodePacked, hexToBytes, http, keccak256, parseAbi, toHex, zeroHash, isHex, padHex, } from 'viem';
|
|
2
|
+
import { RHINESTONE_SPOKE_POOL_ADDRESS, getWethAddress } from '../orchestrator';
|
|
3
|
+
import { MODULE_TYPE_ID_VALIDATOR } from './common';
|
|
4
|
+
import { enableSessionsAbi } from './abi/smart-sessions';
|
|
5
|
+
import { HOOK_ADDRESS } from './omni-account';
|
|
6
|
+
const OWNABLE_VALIDATOR_ADDRESS = '0x2483DA3A338895199E5e538530213157e931Bf06';
|
|
7
|
+
const WEBAUTHN_VALIDATOR_ADDRESS = '0x2f167e55d42584f65e2e30a748f41ee75a311414';
|
|
8
|
+
const SMART_SESSIONS_VALIDATOR_ADDRESS = '0x00000000002b0ecfbd0496ee71e01257da0e37de';
|
|
9
|
+
const SMART_SESSION_MODE_USE = '0x00';
|
|
10
|
+
const SMART_SESSION_MODE_ENABLE = '0x01';
|
|
11
|
+
const SMART_SESSION_MODE_UNSAFE_ENABLE = '0x02';
|
|
12
|
+
const SPENDING_LIMITS_POLICY_ADDRESS = '0x00000088D48cF102A8Cdb0137A9b173f957c6343';
|
|
13
|
+
const TIME_FRAME_POLICY_ADDRESS = '0x8177451511dE0577b911C254E9551D981C26dc72';
|
|
14
|
+
const SUDO_POLICY_ADDRESS = '0x0000003111cD8e92337C100F22B7A9dbf8DEE301';
|
|
15
|
+
const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000006DDA6c463511C4e9B05CFc34C1247fCF1F';
|
|
16
|
+
const USAGE_LIMIT_POLICY_ADDRESS = '0x1F34eF8311345A3A4a4566aF321b313052F51493';
|
|
17
|
+
const VALUE_LIMIT_POLICY_ADDRESS = '0x730DA93267E7E513e932301B47F2ac7D062abC83';
|
|
18
|
+
const SMART_SESSIONS_FALLBACK_TARGET_FLAG = '0x0000000000000000000000000000000000000001';
|
|
19
|
+
const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = '0x00000001';
|
|
20
|
+
const ACTION_CONDITION_EQUAL = 0;
|
|
21
|
+
const ACTION_CONDITION_GREATER_THAN = 1;
|
|
22
|
+
const ACTION_CONDITION_LESS_THAN = 2;
|
|
23
|
+
const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
|
|
24
|
+
const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
|
|
25
|
+
const ACTION_CONDITION_NOT_EQUAL = 5;
|
|
26
|
+
const ACTION_CONDITION_IN_RANGE = 6;
|
|
27
|
+
const ECDSA_MOCK_SIGNATURE = '0x81d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b';
|
|
28
|
+
const WEBAUTHN_MOCK_SIGNATURE = '0x00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000001635bc6d0f68ff895cae8a288ecf7542a6a9cd555df784b73e1e2ea7e9104b1db15e9015d280cb19527881c625fee43fd3a405d5b0d199a8c8e6589a7381209e40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97631d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f47b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a22746278584e465339585f3442797231634d77714b724947422d5f3330613051685a36793775634d30424f45222c226f726967696e223a22687474703a2f2f6c6f63616c686f73743a33303030222c2263726f73734f726967696e223a66616c73652c20226f746865725f6b6579735f63616e5f62655f61646465645f68657265223a22646f206e6f7420636f6d7061726520636c69656e74446174614a534f4e20616761696e737420612074656d706c6174652e205365652068747470733a2f2f676f6f2e676c2f796162506578227d000000000000000000000000';
|
|
29
|
+
function getOwnerValidator(config) {
|
|
30
|
+
return getValidator(config.owners);
|
|
31
|
+
}
|
|
32
|
+
async function getEnableSessionCall(chain, session) {
|
|
33
|
+
const { appDomainSeparator, contentsType } = await getSessionAllowedERC7739Content(chain);
|
|
34
|
+
const allowedERC7739Content = [
|
|
35
|
+
{
|
|
36
|
+
appDomainSeparator,
|
|
37
|
+
contentName: [contentsType],
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
const sessionData = await getSmartSessionData(chain, session, allowedERC7739Content);
|
|
41
|
+
return {
|
|
42
|
+
to: SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
43
|
+
data: encodeFunctionData({
|
|
44
|
+
abi: enableSessionsAbi,
|
|
45
|
+
functionName: 'enableSessions',
|
|
46
|
+
args: [[sessionData]],
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getOmniAccountActions(chain) {
|
|
51
|
+
const wethAddress = getWethAddress(chain);
|
|
52
|
+
const omniActions = [
|
|
53
|
+
{
|
|
54
|
+
actionTarget: RHINESTONE_SPOKE_POOL_ADDRESS,
|
|
55
|
+
actionTargetSelector: '0xa2418864', // injected execution
|
|
56
|
+
actionPolicies: [getPolicyData({ type: 'sudo' })],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
actionTarget: HOOK_ADDRESS,
|
|
60
|
+
actionTargetSelector: '0x27c777a9', // injected execution
|
|
61
|
+
actionPolicies: [getPolicyData({ type: 'sudo' })],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
actionTarget: wethAddress,
|
|
65
|
+
actionTargetSelector: '0xd0e30db0', // deposit
|
|
66
|
+
actionPolicies: [getPolicyData({ type: 'sudo' })],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
actionTarget: wethAddress,
|
|
70
|
+
actionTargetSelector: '0x2e1a7d4d', // widthdraw
|
|
71
|
+
actionPolicies: [getPolicyData({ type: 'sudo' })],
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
return omniActions;
|
|
75
|
+
}
|
|
76
|
+
async function getSessionAllowedERC7739Content(chain) {
|
|
77
|
+
const publicClient = createPublicClient({
|
|
78
|
+
chain,
|
|
79
|
+
transport: http(),
|
|
80
|
+
});
|
|
81
|
+
const appDomainSeparator = await publicClient.readContract({
|
|
82
|
+
address: HOOK_ADDRESS,
|
|
83
|
+
abi: parseAbi(['function DOMAIN_SEPARATOR() view returns (bytes32)']),
|
|
84
|
+
functionName: 'DOMAIN_SEPARATOR',
|
|
85
|
+
});
|
|
86
|
+
const contentsType = 'MultichainCompact(address sponsor,uint256 nonce,uint256 expires,Segment[] segments)Segment(address arbiter,uint256 chainId,uint256[2][] idsAndAmounts,Witness witness)Witness(address recipient,uint256[2][] tokenOut,uint256 depositId,uint256 targetChain,uint32 fillDeadline,XchainExec[] execs,bytes32 userOpHash,uint32 maxFeeBps)XchainExec(address to,uint256 value,bytes data)';
|
|
87
|
+
return {
|
|
88
|
+
appDomainSeparator,
|
|
89
|
+
contentsType,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function getSmartSessionData(chain, session, allowedERC7739Content) {
|
|
93
|
+
const omniActions = getOmniAccountActions(chain);
|
|
94
|
+
const sessionValidator = getValidator(session.owners);
|
|
95
|
+
const userOpPolicies = (session.policies || [
|
|
96
|
+
{
|
|
97
|
+
type: 'sudo',
|
|
98
|
+
},
|
|
99
|
+
]).map((policy) => {
|
|
100
|
+
return getPolicyData(policy);
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
sessionValidator: sessionValidator.address,
|
|
104
|
+
sessionValidatorInitData: sessionValidator.initData,
|
|
105
|
+
salt: session.salt ?? zeroHash,
|
|
106
|
+
userOpPolicies,
|
|
107
|
+
actions: (session.actions || [
|
|
108
|
+
{
|
|
109
|
+
target: SMART_SESSIONS_FALLBACK_TARGET_FLAG,
|
|
110
|
+
selector: SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG,
|
|
111
|
+
},
|
|
112
|
+
])
|
|
113
|
+
.map((action) => {
|
|
114
|
+
const actionPolicies = (action.policies || [
|
|
115
|
+
{
|
|
116
|
+
type: 'sudo',
|
|
117
|
+
},
|
|
118
|
+
]).map((policy) => {
|
|
119
|
+
return getPolicyData(policy);
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
actionTargetSelector: action.selector,
|
|
123
|
+
actionTarget: action.target,
|
|
124
|
+
actionPolicies,
|
|
125
|
+
};
|
|
126
|
+
})
|
|
127
|
+
.concat(omniActions),
|
|
128
|
+
erc7739Policies: {
|
|
129
|
+
allowedERC7739Content,
|
|
130
|
+
erc1271Policies: [getPolicyData({ type: 'sudo' })],
|
|
131
|
+
},
|
|
132
|
+
permitERC4337Paymaster: true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function getSmartSessionValidator(config) {
|
|
136
|
+
if (!config.sessions) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
address: SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
141
|
+
initData: '0x',
|
|
142
|
+
deInitData: '0x',
|
|
143
|
+
additionalContext: '0x',
|
|
144
|
+
type: MODULE_TYPE_ID_VALIDATOR,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function getValidator(owners) {
|
|
148
|
+
switch (owners.type) {
|
|
149
|
+
case 'ecdsa':
|
|
150
|
+
return getOwnableValidator({
|
|
151
|
+
threshold: owners.threshold ?? 1,
|
|
152
|
+
owners: owners.accounts.map((account) => account.address),
|
|
153
|
+
});
|
|
154
|
+
case 'passkey':
|
|
155
|
+
return getWebAuthnValidator({
|
|
156
|
+
pubKey: owners.account.publicKey,
|
|
157
|
+
authenticatorId: owners.account.id,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function getPolicyData(policy) {
|
|
162
|
+
switch (policy.type) {
|
|
163
|
+
case 'sudo':
|
|
164
|
+
return {
|
|
165
|
+
policy: SUDO_POLICY_ADDRESS,
|
|
166
|
+
initData: '0x',
|
|
167
|
+
};
|
|
168
|
+
case 'universal-action': {
|
|
169
|
+
function getCondition(condition) {
|
|
170
|
+
switch (condition) {
|
|
171
|
+
case 'equal':
|
|
172
|
+
return ACTION_CONDITION_EQUAL;
|
|
173
|
+
case 'greaterThan':
|
|
174
|
+
return ACTION_CONDITION_GREATER_THAN;
|
|
175
|
+
case 'lessThan':
|
|
176
|
+
return ACTION_CONDITION_LESS_THAN;
|
|
177
|
+
case 'greaterThanOrEqual':
|
|
178
|
+
return ACTION_CONDITION_GREATER_THAN_OR_EQUAL;
|
|
179
|
+
case 'lessThanOrEqual':
|
|
180
|
+
return ACTION_CONDITION_LESS_THAN_OR_EQUAL;
|
|
181
|
+
case 'notEqual':
|
|
182
|
+
return ACTION_CONDITION_NOT_EQUAL;
|
|
183
|
+
case 'inRange':
|
|
184
|
+
return ACTION_CONDITION_IN_RANGE;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const MAX_RULES = 16;
|
|
188
|
+
const rules = createFixedArray(MAX_RULES, () => ({
|
|
189
|
+
condition: ACTION_CONDITION_EQUAL,
|
|
190
|
+
offset: 0n,
|
|
191
|
+
isLimited: false,
|
|
192
|
+
ref: zeroHash,
|
|
193
|
+
usage: { limit: 0n, used: 0n },
|
|
194
|
+
}));
|
|
195
|
+
for (let i = 0; i < policy.rules.length; i++) {
|
|
196
|
+
const rule = policy.rules[i];
|
|
197
|
+
const ref = isHex(rule.referenceValue)
|
|
198
|
+
? padHex(rule.referenceValue)
|
|
199
|
+
: toHex(rule.referenceValue, { size: 32 });
|
|
200
|
+
rules[i] = {
|
|
201
|
+
condition: getCondition(rule.condition),
|
|
202
|
+
offset: rule.calldataOffset,
|
|
203
|
+
isLimited: rule.usageLimit !== undefined,
|
|
204
|
+
ref,
|
|
205
|
+
usage: {
|
|
206
|
+
limit: rule.usageLimit ? rule.usageLimit : 0n,
|
|
207
|
+
used: 0n,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
policy: UNIVERSAL_ACTION_POLICY_ADDRESS,
|
|
213
|
+
initData: encodeAbiParameters([
|
|
214
|
+
{
|
|
215
|
+
components: [
|
|
216
|
+
{
|
|
217
|
+
name: 'valueLimitPerUse',
|
|
218
|
+
type: 'uint256',
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
components: [
|
|
222
|
+
{
|
|
223
|
+
name: 'length',
|
|
224
|
+
type: 'uint256',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
components: [
|
|
228
|
+
{
|
|
229
|
+
name: 'condition',
|
|
230
|
+
type: 'uint8',
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'offset',
|
|
234
|
+
type: 'uint64',
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'isLimited',
|
|
238
|
+
type: 'bool',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'ref',
|
|
242
|
+
type: 'bytes32',
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
components: [
|
|
246
|
+
{
|
|
247
|
+
name: 'limit',
|
|
248
|
+
type: 'uint256',
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: 'used',
|
|
252
|
+
type: 'uint256',
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
name: 'usage',
|
|
256
|
+
type: 'tuple',
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
name: 'rules',
|
|
260
|
+
type: 'tuple[16]',
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
name: 'paramRules',
|
|
264
|
+
type: 'tuple',
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
name: 'ActionConfig',
|
|
268
|
+
type: 'tuple',
|
|
269
|
+
},
|
|
270
|
+
], [
|
|
271
|
+
{
|
|
272
|
+
valueLimitPerUse: policy.valueLimitPerUse ?? 0n,
|
|
273
|
+
paramRules: {
|
|
274
|
+
length: BigInt(policy.rules.length),
|
|
275
|
+
rules: rules,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
]),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
case 'spending-limits': {
|
|
282
|
+
const tokens = policy.limits.map(({ token }) => token);
|
|
283
|
+
const limits = policy.limits.map(({ amount }) => amount);
|
|
284
|
+
return {
|
|
285
|
+
policy: SPENDING_LIMITS_POLICY_ADDRESS,
|
|
286
|
+
initData: encodeAbiParameters([{ type: 'address[]' }, { type: 'uint256[]' }], [tokens, limits]),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
case 'time-frame': {
|
|
290
|
+
return {
|
|
291
|
+
policy: TIME_FRAME_POLICY_ADDRESS,
|
|
292
|
+
initData: encodePacked(['uint128', 'uint128'], [BigInt(policy.validUntil), BigInt(policy.validAfter)]),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
case 'usage-limit': {
|
|
296
|
+
return {
|
|
297
|
+
policy: USAGE_LIMIT_POLICY_ADDRESS,
|
|
298
|
+
initData: encodePacked(['uint128'], [policy.limit]),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
case 'value-limit': {
|
|
302
|
+
return {
|
|
303
|
+
policy: VALUE_LIMIT_POLICY_ADDRESS,
|
|
304
|
+
initData: encodeAbiParameters([{ type: 'uint256' }], [policy.limit]),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function createFixedArray(length, getValue) {
|
|
310
|
+
return Array.from({ length }, (_, i) => getValue(i));
|
|
311
|
+
}
|
|
312
|
+
function getOwnableValidator({ threshold, owners, }) {
|
|
313
|
+
return {
|
|
314
|
+
address: OWNABLE_VALIDATOR_ADDRESS,
|
|
315
|
+
initData: encodeAbiParameters([
|
|
316
|
+
{ name: 'threshold', type: 'uint256' },
|
|
317
|
+
{ name: 'owners', type: 'address[]' },
|
|
318
|
+
], [
|
|
319
|
+
BigInt(threshold),
|
|
320
|
+
owners.map((owner) => owner.toLowerCase()).sort(),
|
|
321
|
+
]),
|
|
322
|
+
deInitData: '0x',
|
|
323
|
+
additionalContext: '0x',
|
|
324
|
+
type: MODULE_TYPE_ID_VALIDATOR,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function getWebAuthnValidator(webAuthnCredential) {
|
|
328
|
+
let pubKeyX;
|
|
329
|
+
let pubKeyY;
|
|
330
|
+
// Distinguish between PublicKey and Hex / byte encoded public key
|
|
331
|
+
if (typeof webAuthnCredential.pubKey === 'string' ||
|
|
332
|
+
webAuthnCredential.pubKey instanceof Uint8Array) {
|
|
333
|
+
// It's a P256Credential
|
|
334
|
+
const { x, y, prefix } = parsePublicKey(webAuthnCredential.pubKey);
|
|
335
|
+
pubKeyX = x;
|
|
336
|
+
pubKeyY = y;
|
|
337
|
+
if (prefix && prefix !== 4) {
|
|
338
|
+
throw new Error('Only uncompressed public keys are supported');
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
// It's already a PublicKey
|
|
343
|
+
pubKeyX = webAuthnCredential.pubKey.x;
|
|
344
|
+
pubKeyY = webAuthnCredential.pubKey.y;
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
address: WEBAUTHN_VALIDATOR_ADDRESS,
|
|
348
|
+
initData: encodeAbiParameters([
|
|
349
|
+
{
|
|
350
|
+
components: [
|
|
351
|
+
{
|
|
352
|
+
name: 'pubKeyX',
|
|
353
|
+
type: 'uint256',
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: 'pubKeyY',
|
|
357
|
+
type: 'uint256',
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
type: 'tuple',
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
type: 'bytes32',
|
|
364
|
+
name: 'authenticatorIdHash',
|
|
365
|
+
},
|
|
366
|
+
], [
|
|
367
|
+
{
|
|
368
|
+
pubKeyX,
|
|
369
|
+
pubKeyY,
|
|
370
|
+
},
|
|
371
|
+
keccak256(toHex(webAuthnCredential.authenticatorId)),
|
|
372
|
+
]),
|
|
373
|
+
deInitData: '0x',
|
|
374
|
+
additionalContext: '0x',
|
|
375
|
+
type: MODULE_TYPE_ID_VALIDATOR,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function parsePublicKey(publicKey) {
|
|
379
|
+
const bytes = typeof publicKey === 'string' ? hexToBytes(publicKey) : publicKey;
|
|
380
|
+
const offset = bytes.length === 65 ? 1 : 0;
|
|
381
|
+
const x = bytes.slice(offset, 32 + offset);
|
|
382
|
+
const y = bytes.slice(32 + offset, 64 + offset);
|
|
383
|
+
return {
|
|
384
|
+
prefix: bytes.length === 65 ? bytes[0] : undefined,
|
|
385
|
+
x: BigInt(bytesToHex(x)),
|
|
386
|
+
y: BigInt(bytesToHex(y)),
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
async function isSessionEnabled(client, address, permissionId) {
|
|
390
|
+
return await client.readContract({
|
|
391
|
+
address: SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
392
|
+
abi: [
|
|
393
|
+
{
|
|
394
|
+
inputs: [
|
|
395
|
+
{
|
|
396
|
+
internalType: 'PermissionId',
|
|
397
|
+
name: 'permissionId',
|
|
398
|
+
type: 'bytes32',
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
internalType: 'address',
|
|
402
|
+
name: 'account',
|
|
403
|
+
type: 'address',
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
name: 'isPermissionEnabled',
|
|
407
|
+
outputs: [
|
|
408
|
+
{
|
|
409
|
+
internalType: 'bool',
|
|
410
|
+
name: '',
|
|
411
|
+
type: 'bool',
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
stateMutability: 'view',
|
|
415
|
+
type: 'function',
|
|
416
|
+
},
|
|
417
|
+
],
|
|
418
|
+
functionName: 'isPermissionEnabled',
|
|
419
|
+
args: [permissionId, address],
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
function encodeSmartSessionSignature(mode, permissionId, signature) {
|
|
423
|
+
switch (mode) {
|
|
424
|
+
case SMART_SESSION_MODE_USE:
|
|
425
|
+
return encodePacked(['bytes1', 'bytes32', 'bytes'], [mode, permissionId, signature]);
|
|
426
|
+
case SMART_SESSION_MODE_ENABLE:
|
|
427
|
+
case SMART_SESSION_MODE_UNSAFE_ENABLE:
|
|
428
|
+
throw new Error('Enable mode not implemented');
|
|
429
|
+
default:
|
|
430
|
+
throw new Error(`Unknown mode ${mode}`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function getPermissionId(session) {
|
|
434
|
+
const sessionValidator = getValidator(session.owners);
|
|
435
|
+
return keccak256(encodeAbiParameters([
|
|
436
|
+
{
|
|
437
|
+
type: 'address',
|
|
438
|
+
name: 'sessionValidator',
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
type: 'bytes',
|
|
442
|
+
name: 'sessionValidatorInitData',
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
type: 'bytes32',
|
|
446
|
+
name: 'salt',
|
|
447
|
+
},
|
|
448
|
+
], [
|
|
449
|
+
sessionValidator.address,
|
|
450
|
+
sessionValidator.initData,
|
|
451
|
+
session.salt ?? zeroHash,
|
|
452
|
+
]));
|
|
453
|
+
}
|
|
454
|
+
function getMockSinature(ownerSet) {
|
|
455
|
+
switch (ownerSet.type) {
|
|
456
|
+
case 'ecdsa': {
|
|
457
|
+
const owners = ownerSet.accounts.map((account) => account.address);
|
|
458
|
+
const signatures = owners.map(() => ECDSA_MOCK_SIGNATURE);
|
|
459
|
+
return concat(signatures);
|
|
460
|
+
}
|
|
461
|
+
case 'passkey':
|
|
462
|
+
return WEBAUTHN_MOCK_SIGNATURE;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
async function getAccountEIP712Domain(client, account) {
|
|
466
|
+
const data = await client.readContract({
|
|
467
|
+
address: account,
|
|
468
|
+
abi: [
|
|
469
|
+
{
|
|
470
|
+
type: 'function',
|
|
471
|
+
name: 'eip712Domain',
|
|
472
|
+
inputs: [],
|
|
473
|
+
outputs: [
|
|
474
|
+
{
|
|
475
|
+
type: 'bytes1',
|
|
476
|
+
name: 'fields,',
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
type: 'string',
|
|
480
|
+
name: 'name',
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
type: 'string',
|
|
484
|
+
name: 'version',
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
type: 'uint256',
|
|
488
|
+
name: 'chainId',
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
type: 'address',
|
|
492
|
+
name: 'verifyingContract',
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
type: 'bytes32',
|
|
496
|
+
name: 'salt',
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
type: 'uint256[]',
|
|
500
|
+
name: 'extensions',
|
|
501
|
+
},
|
|
502
|
+
],
|
|
503
|
+
stateMutability: 'view',
|
|
504
|
+
constant: true,
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
functionName: 'eip712Domain',
|
|
508
|
+
args: [],
|
|
509
|
+
});
|
|
510
|
+
return {
|
|
511
|
+
name: data[1],
|
|
512
|
+
version: data[2],
|
|
513
|
+
chainId: data[3],
|
|
514
|
+
verifyingContract: data[4],
|
|
515
|
+
salt: data[5],
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
export { SMART_SESSION_MODE_USE, SMART_SESSION_MODE_ENABLE, SMART_SESSIONS_VALIDATOR_ADDRESS, getOwnerValidator, getSmartSessionValidator, getEnableSessionCall, encodeSmartSessionSignature, getPermissionId, getMockSinature, getAccountEIP712Domain, isSessionEnabled, getSessionAllowedERC7739Content, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address, Hex } from 'viem';
|
|
2
2
|
import { UserOperation } from 'viem/account-abstraction';
|
|
3
|
-
import { type UserTokenBalance, type MetaIntent, type
|
|
3
|
+
import { type UserTokenBalance, type MetaIntent, type SignedMultiChainCompact, type PostOrderBundleResult, type BundleResult, type BundleEvent, type OrderPath } from './types';
|
|
4
4
|
export declare class Orchestrator {
|
|
5
5
|
private serverUrl;
|
|
6
6
|
private apiKey;
|
|
@@ -11,10 +11,7 @@ export declare class Orchestrator {
|
|
|
11
11
|
[chainId: number]: Address[];
|
|
12
12
|
};
|
|
13
13
|
}): Promise<UserTokenBalance[]>;
|
|
14
|
-
getOrderPath(intent: MetaIntent, userAddress: Address): Promise<
|
|
15
|
-
orderBundle: MultiChainCompact;
|
|
16
|
-
injectedExecutions: Execution[];
|
|
17
|
-
}[]>;
|
|
14
|
+
getOrderPath(intent: MetaIntent, userAddress: Address): Promise<OrderPath>;
|
|
18
15
|
postSignedOrderBundle(signedOrderBundles: {
|
|
19
16
|
signedOrderBundle: SignedMultiChainCompact;
|
|
20
17
|
initCode?: Hex;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../orchestrator/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAU,MAAM,MAAM,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,SAAS,CAAA;AAQhB,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,MAAM,CAAQ;gBAEV,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKvC,YAAY,CAChB,WAAW,EAAE,OAAO,EACpB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;QACnB,MAAM,CAAC,EAAE;YACP,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;SAC7B,CAAA;KACF,GACA,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAwCxB,YAAY,CAChB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,SAAS,CAAC;IA+Bf,qBAAqB,CACzB,kBAAkB,EAAE;QAClB,iBAAiB,EAAE,uBAAuB,CAAA;QAC1C,QAAQ,CAAC,EAAE,GAAG,CAAA;QACd,MAAM,CAAC,EAAE,aAAa,CAAA;KACvB,EAAE,GACF,OAAO,CAAC,qBAAqB,CAAC;IA2C3B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAyBxD,iBAAiB,CACrB,KAAK,GAAE,MAAW,EAClB,MAAM,GAAE,MAAU,GACjB,OAAO,CAAC;QAAE,cAAc,EAAE,WAAW,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAuBlE,OAAO,CAAC,UAAU;CA6DnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../orchestrator/consts.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,wCAAwC,CAAA;AAC9D,QAAA,MAAM,6BAA6B,+CACW,CAAA;AAE9C,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../orchestrator/error.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAK;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,GAAG,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB;IAQD,IAAI,OAAO,WAEV;IAED,IAAI,OAAO,QAEV;IAED,IAAI,SAAS,WAEZ;IAED,IAAI,OAAO,WAEV;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OrchestratorError } from './error';
|
|
2
|
+
import { RHINESTONE_SPOKE_POOL_ADDRESS } from './consts';
|
|
3
|
+
import { Orchestrator } from './client';
|
|
4
|
+
import { getEmptyUserOp, getOrderBundleHash } from './utils';
|
|
5
|
+
import { getWethAddress, getTokenBalanceSlot } from './registry';
|
|
6
|
+
declare function getOrchestrator(apiKey: string, orchestratorUrl?: string): Orchestrator;
|
|
7
|
+
export * from './types';
|
|
8
|
+
export { RHINESTONE_SPOKE_POOL_ADDRESS, Orchestrator, OrchestratorError, getOrchestrator, getOrderBundleHash, getEmptyUserOp, getWethAddress, getTokenBalanceSlot, };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../orchestrator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAoB,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAEhE,iBAAS,eAAe,CACtB,MAAM,EAAE,MAAM,EACd,eAAe,CAAC,EAAE,MAAM,GACvB,YAAY,CAEd;AAED,cAAc,SAAS,CAAA;AACvB,OAAO,EACL,6BAA6B,EAC7B,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,mBAAmB,GACpB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OrchestratorError } from './error';
|
|
2
|
+
import { ORCHESTRATOR_URL, RHINESTONE_SPOKE_POOL_ADDRESS } from './consts';
|
|
3
|
+
import { Orchestrator } from './client';
|
|
4
|
+
import { getEmptyUserOp, getOrderBundleHash } from './utils';
|
|
5
|
+
import { getWethAddress, getTokenBalanceSlot } from './registry';
|
|
6
|
+
function getOrchestrator(apiKey, orchestratorUrl) {
|
|
7
|
+
return new Orchestrator(orchestratorUrl ?? ORCHESTRATOR_URL, apiKey);
|
|
8
|
+
}
|
|
9
|
+
export * from './types';
|
|
10
|
+
export { RHINESTONE_SPOKE_POOL_ADDRESS, Orchestrator, OrchestratorError, getOrchestrator, getOrderBundleHash, getEmptyUserOp, getWethAddress, getTokenBalanceSlot, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Address, Chain } from 'viem';
|
|
2
|
+
declare function getWethAddress(chain: Chain): "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" | "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14" | "0x4200000000000000000000000000000000000006" | "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1" | "0x980B62Da83eFf3D4576C647993b0c1D7faf17c73" | "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619" | "0x52eF3d68BaB452a294342DC3e5f464d7f610f72E";
|
|
3
|
+
declare function getTokenBalanceSlot(chain: Chain, tokenAddress: Address): bigint | null;
|
|
4
|
+
export { getTokenBalanceSlot, getWethAddress };
|
|
5
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../orchestrator/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAe,MAAM,MAAM,CAAA;AAclD,iBAAS,cAAc,CAAC,KAAK,EAAE,KAAK,0UAoCnC;AAED,iBAAS,mBAAmB,CAC1B,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,OAAO,GACpB,MAAM,GAAG,IAAI,CAqJf;AAED,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,CAAA"}
|