@charterlabs/rhinestone-sdk 0.0.3 → 0.0.4
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 +6 -0
- package/dist/src/accounts/index.d.ts +10 -6
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +100 -4
- package/dist/src/accounts/kernel.d.ts +22 -0
- package/dist/src/accounts/kernel.d.ts.map +1 -0
- package/dist/src/accounts/kernel.js +252 -0
- package/dist/src/accounts/kernel.test.d.ts +2 -0
- package/dist/src/accounts/kernel.test.d.ts.map +1 -0
- package/dist/src/accounts/kernel.test.js +103 -0
- package/dist/src/accounts/nexus.d.ts +7 -2
- package/dist/src/accounts/nexus.d.ts.map +1 -1
- package/dist/src/accounts/nexus.js +59 -10
- package/dist/src/accounts/nexus.test.js +50 -4
- package/dist/src/accounts/safe.d.ts +7 -2
- package/dist/src/accounts/safe.d.ts.map +1 -1
- package/dist/src/accounts/safe.js +51 -2
- package/dist/src/accounts/safe.test.js +50 -4
- package/dist/src/accounts/utils.d.ts +5 -0
- package/dist/src/accounts/utils.d.ts.map +1 -1
- package/dist/src/actions/index.d.ts +12 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/actions/index.js +165 -0
- package/dist/src/actions/index.test.d.ts +2 -0
- package/dist/src/actions/index.test.d.ts.map +1 -0
- package/dist/src/actions/index.test.js +170 -0
- package/dist/src/execution/index.d.ts +5 -15
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +30 -149
- package/dist/src/execution/smart-session.d.ts.map +1 -1
- package/dist/src/execution/smart-session.js +7 -2
- package/dist/src/execution/smart-session.test.js +3 -0
- package/dist/src/execution/utils.d.ts +68 -0
- package/dist/src/execution/utils.d.ts.map +1 -0
- package/dist/src/execution/utils.js +355 -0
- package/dist/src/index.d.ts +20 -24
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -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 +9 -1
- package/dist/src/modules/registry.d.ts +9 -0
- package/dist/src/modules/registry.d.ts.map +1 -0
- package/dist/src/modules/registry.js +60 -0
- package/dist/src/modules/validators/core.d.ts +4 -2
- package/dist/src/modules/validators/core.d.ts.map +1 -1
- package/dist/src/modules/validators/core.js +24 -0
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.d.ts +1 -1
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +76 -1
- package/dist/src/orchestrator/types.d.ts +24 -3
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/orchestrator/utils.d.ts.map +1 -1
- package/dist/src/orchestrator/utils.js +3 -0
- package/dist/src/types.d.ts +12 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/test/consts.d.ts +2 -1
- package/dist/test/consts.d.ts.map +1 -1
- package/dist/test/consts.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,6 +203,12 @@ const transactionResult = await rhinestoneAccount.sendTransaction({
|
|
|
203
203
|
})
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
+
## Migrating from Orchestrator SDK
|
|
207
|
+
|
|
208
|
+
To migrate from the [Orchestrator SDK](https://github.com/rhinestonewtf/orchestrator-sdk), replace all imports of `@rhinestone/orchestrator-sdk` with `@rhinestone/sdk/orchestrator`.
|
|
209
|
+
|
|
210
|
+
Let us know if you encounter any issues!
|
|
211
|
+
|
|
206
212
|
## Contributing
|
|
207
213
|
|
|
208
214
|
For feature or change requests, feel free to open a PR, start a discussion or get in touch with us.
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { type Chain, type Hex, type PublicClient } from 'viem';
|
|
2
|
-
import
|
|
2
|
+
import { Module } from '../modules/common';
|
|
3
|
+
import type { Call, OwnerSet, RhinestoneAccountConfig, Session } from '../types';
|
|
4
|
+
import { ValidatorConfig } from './utils';
|
|
3
5
|
declare function getDeployArgs(config: RhinestoneAccountConfig): {
|
|
4
6
|
factory: `0x${string}`;
|
|
5
7
|
factoryData: `0x${string}`;
|
|
6
8
|
salt: `0x${string}`;
|
|
7
|
-
hashedInitcode: `0x${string}`;
|
|
8
9
|
implementation: `0x${string}`;
|
|
9
|
-
initializationCallData:
|
|
10
|
+
initializationCallData: null;
|
|
10
11
|
} | {
|
|
11
12
|
factory: `0x${string}`;
|
|
12
13
|
factoryData: `0x${string}`;
|
|
13
14
|
salt: `0x${string}`;
|
|
14
|
-
hashedInitcode: `0x${string}`;
|
|
15
15
|
implementation: `0x${string}`;
|
|
16
|
-
initializationCallData:
|
|
16
|
+
initializationCallData: `0x${string}`;
|
|
17
17
|
};
|
|
18
|
+
declare function getModuleInstallationCalls(config: RhinestoneAccountConfig, module: Module): Call[];
|
|
18
19
|
declare function getAddress(config: RhinestoneAccountConfig): `0x${string}`;
|
|
20
|
+
declare function getPackedSignature(config: RhinestoneAccountConfig, owners: OwnerSet, chain: Chain, validator: ValidatorConfig, hash: Hex, transformSignature?: (signature: Hex) => Hex): Promise<`0x${string}`>;
|
|
19
21
|
declare function isDeployed(chain: Chain, config: RhinestoneAccountConfig): Promise<boolean>;
|
|
22
|
+
declare function deploy(config: RhinestoneAccountConfig, chain: Chain, session?: Session): Promise<void>;
|
|
20
23
|
declare function deploySource(chain: Chain, config: RhinestoneAccountConfig): Promise<void>;
|
|
21
24
|
declare function deployTarget(chain: Chain, config: RhinestoneAccountConfig, asUserOp: boolean): Promise<void>;
|
|
22
25
|
declare function getBundleInitCode(config: RhinestoneAccountConfig): `0x${string}` | undefined;
|
|
23
26
|
declare function getSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
|
|
24
27
|
declare function getSmartSessionSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain, session: Session): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
|
|
28
|
+
declare function getGuardianSmartAccount(config: RhinestoneAccountConfig, client: PublicClient, chain: Chain, guardians: OwnerSet): Promise<import("viem/account-abstraction").SmartAccount<import("viem/account-abstraction").SmartAccountImplementation<import("viem").Abi, "0.7">>>;
|
|
25
29
|
declare function sign(validators: OwnerSet, chain: Chain, hash: Hex): Promise<`0x${string}`>;
|
|
26
|
-
export { getDeployArgs, getBundleInitCode, getAddress, isDeployed, deploySource, deployTarget, getSmartAccount, getSmartSessionSmartAccount, sign, };
|
|
30
|
+
export { getModuleInstallationCalls, getDeployArgs, getBundleInitCode, getAddress, isDeployed, deploy, deploySource, deployTarget, getSmartAccount, getSmartSessionSmartAccount, getGuardianSmartAccount, getPackedSignature, sign, };
|
|
27
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../accounts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAKV,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../accounts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAKV,KAAK,GAAG,EAER,KAAK,YAAY,EAGlB,MAAM,MAAM,CAAA;AAOb,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAM1C,OAAO,KAAK,EAEV,IAAI,EACJ,QAAQ,EACR,uBAAuB,EACvB,OAAO,EACR,MAAM,UAAU,CAAA;AAkCjB,OAAO,EAAoB,eAAe,EAAE,MAAM,SAAS,CAAA;AAE3D,iBAAS,aAAa,CAAC,MAAM,EAAE,uBAAuB;;;;;;;;;;;;EAarD;AAED,iBAAS,0BAA0B,CACjC,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,MAAM,GACb,IAAI,EAAE,CAuBR;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,uBAAuB,iBAmBlD;AAGD,iBAAe,kBAAkB,CAC/B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,QAAQ,EAChB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,eAAe,EAC1B,IAAI,EAAE,GAAG,EACT,kBAAkB,GAAE,CAAC,SAAS,EAAE,GAAG,KAAK,GAA8B,0BA2BvE;AAED,iBAAe,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,oBAiBtE;AAED,iBAAe,MAAM,CACnB,MAAM,EAAE,uBAAuB,EAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE,OAAO,iBAMlB;AAED,iBAAe,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,iBAMxE;AAED,iBAAe,YAAY,CACzB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,uBAAuB,EAC/B,QAAQ,EAAE,OAAO,iBASlB;AAUD,iBAAS,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,6BAUzD;AAgID,iBAAe,eAAe,CAC5B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,sJAmCb;AAED,iBAAe,2BAA2B,CACxC,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,sJAuCjB;AAED,iBAAe,uBAAuB,CACpC,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,QAAQ,sJAwCpB;AAED,iBAAe,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,0BAYhE;AAsED,OAAO,EACL,0BAA0B,EAC1B,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,2BAA2B,EAC3B,uBAAuB,EACvB,kBAAkB,EAClB,IAAI,GACL,CAAA"}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getModuleInstallationCalls = getModuleInstallationCalls;
|
|
3
4
|
exports.getDeployArgs = getDeployArgs;
|
|
4
5
|
exports.getBundleInitCode = getBundleInitCode;
|
|
5
6
|
exports.getAddress = getAddress;
|
|
6
7
|
exports.isDeployed = isDeployed;
|
|
8
|
+
exports.deploy = deploy;
|
|
7
9
|
exports.deploySource = deploySource;
|
|
8
10
|
exports.deployTarget = deployTarget;
|
|
9
11
|
exports.getSmartAccount = getSmartAccount;
|
|
10
12
|
exports.getSmartSessionSmartAccount = getSmartSessionSmartAccount;
|
|
13
|
+
exports.getGuardianSmartAccount = getGuardianSmartAccount;
|
|
14
|
+
exports.getPackedSignature = getPackedSignature;
|
|
11
15
|
exports.sign = sign;
|
|
12
16
|
const viem_1 = require("viem");
|
|
17
|
+
const smart_session_1 = require("../execution/smart-session");
|
|
13
18
|
const modules_1 = require("../modules");
|
|
14
19
|
const validators_1 = require("../modules/validators");
|
|
20
|
+
const core_1 = require("../modules/validators/core");
|
|
21
|
+
const kernel_1 = require("./kernel");
|
|
15
22
|
const nexus_1 = require("./nexus");
|
|
16
23
|
const safe_1 = require("./safe");
|
|
17
24
|
const utils_1 = require("./utils");
|
|
@@ -24,7 +31,32 @@ function getDeployArgs(config) {
|
|
|
24
31
|
case 'nexus': {
|
|
25
32
|
return (0, nexus_1.getDeployArgs)(config);
|
|
26
33
|
}
|
|
34
|
+
case 'kernel': {
|
|
35
|
+
return (0, kernel_1.getDeployArgs)(config);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getModuleInstallationCalls(config, module) {
|
|
40
|
+
const address = getAddress(config);
|
|
41
|
+
function getInstallData() {
|
|
42
|
+
const account = getAccount(config);
|
|
43
|
+
switch (account.type) {
|
|
44
|
+
case 'safe': {
|
|
45
|
+
return [(0, safe_1.getInstallData)(module)];
|
|
46
|
+
}
|
|
47
|
+
case 'nexus': {
|
|
48
|
+
return [(0, nexus_1.getInstallData)(module)];
|
|
49
|
+
}
|
|
50
|
+
case 'kernel': {
|
|
51
|
+
return (0, kernel_1.getInstallData)(module);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
27
54
|
}
|
|
55
|
+
const installData = getInstallData();
|
|
56
|
+
return installData.map((data) => ({
|
|
57
|
+
to: address,
|
|
58
|
+
data,
|
|
59
|
+
}));
|
|
28
60
|
}
|
|
29
61
|
function getAddress(config) {
|
|
30
62
|
if (is7702(config)) {
|
|
@@ -33,10 +65,35 @@ function getAddress(config) {
|
|
|
33
65
|
}
|
|
34
66
|
return config.eoa.address;
|
|
35
67
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
68
|
+
const account = getAccount(config);
|
|
69
|
+
switch (account.type) {
|
|
70
|
+
case 'safe': {
|
|
71
|
+
return (0, safe_1.getAddress)(config);
|
|
72
|
+
}
|
|
73
|
+
case 'nexus': {
|
|
74
|
+
return (0, nexus_1.getAddress)(config);
|
|
75
|
+
}
|
|
76
|
+
case 'kernel': {
|
|
77
|
+
return (0, kernel_1.getAddress)(config);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Signs and packs a signature to be EIP-1271 compatibleAdd commentMore actions
|
|
82
|
+
async function getPackedSignature(config, owners, chain, validator, hash, transformSignature = (signature) => signature) {
|
|
83
|
+
const signFn = (hash) => sign(owners, chain, hash);
|
|
84
|
+
const account = getAccount(config);
|
|
85
|
+
const address = getAddress(config);
|
|
86
|
+
switch (account.type) {
|
|
87
|
+
case 'safe': {
|
|
88
|
+
return (0, safe_1.getPackedSignature)(signFn, hash, validator, transformSignature);
|
|
89
|
+
}
|
|
90
|
+
case 'nexus': {
|
|
91
|
+
return (0, nexus_1.getPackedSignature)(signFn, hash, validator, transformSignature);
|
|
92
|
+
}
|
|
93
|
+
case 'kernel': {
|
|
94
|
+
return (0, kernel_1.getPackedSignature)(signFn, hash, validator, address, transformSignature);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
40
97
|
}
|
|
41
98
|
async function isDeployed(chain, config) {
|
|
42
99
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
@@ -56,6 +113,12 @@ async function isDeployed(chain, config) {
|
|
|
56
113
|
}
|
|
57
114
|
return (0, viem_1.size)(code) > 0;
|
|
58
115
|
}
|
|
116
|
+
async function deploy(config, chain, session) {
|
|
117
|
+
await deploySource(chain, config);
|
|
118
|
+
if (session) {
|
|
119
|
+
await (0, smart_session_1.enableSmartSession)(chain, config, session);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
59
122
|
async function deploySource(chain, config) {
|
|
60
123
|
if (is7702(config)) {
|
|
61
124
|
return deploy7702Self(chain, config);
|
|
@@ -205,6 +268,9 @@ async function getSmartAccount(config, client, chain) {
|
|
|
205
268
|
case 'nexus': {
|
|
206
269
|
return (0, nexus_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
|
|
207
270
|
}
|
|
271
|
+
case 'kernel': {
|
|
272
|
+
return (0, kernel_1.getSmartAccount)(client, address, config.owners, ownerValidator.address, signFn);
|
|
273
|
+
}
|
|
208
274
|
}
|
|
209
275
|
}
|
|
210
276
|
async function getSmartSessionSmartAccount(config, client, chain, session) {
|
|
@@ -222,6 +288,30 @@ async function getSmartSessionSmartAccount(config, client, chain, session) {
|
|
|
222
288
|
case 'nexus': {
|
|
223
289
|
return (0, nexus_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, signFn);
|
|
224
290
|
}
|
|
291
|
+
case 'kernel': {
|
|
292
|
+
return (0, kernel_1.getSessionSmartAccount)(client, address, session, smartSessionValidator.address, signFn);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async function getGuardianSmartAccount(config, client, chain, guardians) {
|
|
297
|
+
const address = getAddress(config);
|
|
298
|
+
const accounts = guardians.type === 'ecdsa' ? guardians.accounts : [];
|
|
299
|
+
const socialRecoveryValidator = (0, core_1.getSocialRecoveryValidator)(accounts);
|
|
300
|
+
if (!socialRecoveryValidator) {
|
|
301
|
+
throw new Error('Social recovery is not enabled for this account');
|
|
302
|
+
}
|
|
303
|
+
const signFn = (hash) => sign(guardians, chain, hash);
|
|
304
|
+
const account = getAccount(config);
|
|
305
|
+
switch (account.type) {
|
|
306
|
+
case 'safe': {
|
|
307
|
+
return (0, safe_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
|
|
308
|
+
}
|
|
309
|
+
case 'nexus': {
|
|
310
|
+
return (0, nexus_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
|
|
311
|
+
}
|
|
312
|
+
case 'kernel': {
|
|
313
|
+
return (0, kernel_1.getGuardianSmartAccount)(client, address, guardians, socialRecoveryValidator.address, signFn);
|
|
314
|
+
}
|
|
225
315
|
}
|
|
226
316
|
}
|
|
227
317
|
async function sign(validators, chain, hash) {
|
|
@@ -263,6 +353,9 @@ async function get7702SmartAccount(config, client) {
|
|
|
263
353
|
case 'nexus': {
|
|
264
354
|
return (0, nexus_1.get7702SmartAccount)(config.eoa, client);
|
|
265
355
|
}
|
|
356
|
+
case 'kernel': {
|
|
357
|
+
return (0, kernel_1.get7702SmartAccount)();
|
|
358
|
+
}
|
|
266
359
|
}
|
|
267
360
|
}
|
|
268
361
|
async function get7702InitCalls(config) {
|
|
@@ -274,6 +367,9 @@ async function get7702InitCalls(config) {
|
|
|
274
367
|
case 'nexus': {
|
|
275
368
|
return (0, nexus_1.get7702InitCalls)(config);
|
|
276
369
|
}
|
|
370
|
+
case 'kernel': {
|
|
371
|
+
return (0, kernel_1.get7702InitCalls)();
|
|
372
|
+
}
|
|
277
373
|
}
|
|
278
374
|
}
|
|
279
375
|
function is7702(config) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Abi, Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
import { SmartAccount, SmartAccountImplementation } from 'viem/account-abstraction';
|
|
3
|
+
import { Module } from '../modules/common';
|
|
4
|
+
import { OwnerSet, RhinestoneAccountConfig, Session } from '../types';
|
|
5
|
+
import { ValidatorConfig } from './utils';
|
|
6
|
+
declare function getDeployArgs(config: RhinestoneAccountConfig): {
|
|
7
|
+
factory: `0x${string}`;
|
|
8
|
+
factoryData: `0x${string}`;
|
|
9
|
+
salt: "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
10
|
+
implementation: `0x${string}`;
|
|
11
|
+
initializationCallData: `0x${string}`;
|
|
12
|
+
};
|
|
13
|
+
declare function getAddress(config: RhinestoneAccountConfig): `0x${string}`;
|
|
14
|
+
declare function getInstallData(module: Module): Hex[];
|
|
15
|
+
declare function get7702InitCalls(): never;
|
|
16
|
+
declare function get7702SmartAccount(): never;
|
|
17
|
+
declare function getPackedSignature(signFn: (message: Hex) => Promise<Hex>, hash: Hex, validator: ValidatorConfig, accountAddress: Address, transformSignature?: (signature: Hex) => Hex): Promise<`0x${string}`>;
|
|
18
|
+
declare function getSmartAccount(client: PublicClient, address: Address, owners: OwnerSet, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
|
|
19
|
+
declare function getSessionSmartAccount(client: PublicClient, address: Address, session: Session, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
|
|
20
|
+
declare function getGuardianSmartAccount(client: PublicClient, address: Address, guardians: OwnerSet, validatorAddress: Address, sign: (hash: Hex) => Promise<Hex>): Promise<SmartAccount<SmartAccountImplementation<Abi, "0.7">>>;
|
|
21
|
+
export { getInstallData, getAddress, getDeployArgs, getSmartAccount, getSessionSmartAccount, getGuardianSmartAccount, get7702InitCalls, get7702SmartAccount, getPackedSignature, };
|
|
22
|
+
//# sourceMappingURL=kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../accounts/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,OAAO,EAQP,GAAG,EAEH,YAAY,EAMb,MAAM,MAAM,CAAA;AACb,OAAO,EAIL,YAAY,EACZ,0BAA0B,EAE3B,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EAKL,MAAM,EACP,MAAM,mBAAmB,CAAA;AAO1B,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EAAoC,eAAe,EAAE,MAAM,SAAS,CAAA;AAgB3E,iBAAS,aAAa,CAAC,MAAM,EAAE,uBAAuB;;;;;;EA4CrD;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,uBAAuB,iBASlD;AAED,iBAAS,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,EAAE,CAsE7C;AAED,iBAAS,gBAAgB,IAAI,KAAK,CAEjC;AAED,iBAAS,mBAAmB,IAAI,KAAK,CAEpC;AAED,iBAAe,kBAAkB,CAC/B,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EACtC,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,eAAe,EAC1B,cAAc,EAAE,OAAO,EACvB,kBAAkB,GAAE,CAAC,SAAS,EAAE,GAAG,KAAK,GAA8B,0BAevE;AAwBD,iBAAe,eAAe,CAC5B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,QAAQ,EAChB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAYlC;AAED,iBAAe,sBAAsB,CACnC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAwBlC;AAED,iBAAe,uBAAuB,CACpC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,QAAQ,EACnB,gBAAgB,EAAE,OAAO,EACzB,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,iEAclC;AA+ED,OAAO,EACL,cAAc,EACd,UAAU,EACV,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GACnB,CAAA"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInstallData = getInstallData;
|
|
4
|
+
exports.getAddress = getAddress;
|
|
5
|
+
exports.getDeployArgs = getDeployArgs;
|
|
6
|
+
exports.getSmartAccount = getSmartAccount;
|
|
7
|
+
exports.getSessionSmartAccount = getSessionSmartAccount;
|
|
8
|
+
exports.getGuardianSmartAccount = getGuardianSmartAccount;
|
|
9
|
+
exports.get7702InitCalls = get7702InitCalls;
|
|
10
|
+
exports.get7702SmartAccount = get7702SmartAccount;
|
|
11
|
+
exports.getPackedSignature = getPackedSignature;
|
|
12
|
+
const viem_1 = require("viem");
|
|
13
|
+
const account_abstraction_1 = require("viem/account-abstraction");
|
|
14
|
+
const modules_1 = require("../modules");
|
|
15
|
+
const common_1 = require("../modules/common");
|
|
16
|
+
const validators_1 = require("../modules/validators");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
const KERNEL_META_FACTORY_ADDRESS = '0xd703aae79538628d27099b8c4f621be4ccd142d5';
|
|
19
|
+
const KERNEL_IMPLEMENTATION_ADDRESS = '0xd6CEDDe84be40893d153Be9d467CD6aD37875b28';
|
|
20
|
+
const KERNEL_FACTORY_ADDRESS = '0x2577507b78c2008ff367261cb6285d44ba5ef2e9';
|
|
21
|
+
const KERNEL_BYTECODE = '0x603d3d8160223d3973d6cedde84be40893d153be9d467cd6ad37875b2860095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3';
|
|
22
|
+
const KERNEL_VERSION = '0.3.3';
|
|
23
|
+
function getDeployArgs(config) {
|
|
24
|
+
const salt = viem_1.zeroHash;
|
|
25
|
+
const moduleSetup = (0, modules_1.getSetup)(config);
|
|
26
|
+
const rootValidator = (0, viem_1.concat)(['0x01', moduleSetup.validators[0].address]);
|
|
27
|
+
const hook = viem_1.zeroAddress;
|
|
28
|
+
const validatorData = moduleSetup.validators[0].initData;
|
|
29
|
+
const hookData = '0x';
|
|
30
|
+
// Install modules via init config
|
|
31
|
+
const spareValidators = moduleSetup.validators.slice(1);
|
|
32
|
+
const initConfig = [];
|
|
33
|
+
for (const module of spareValidators) {
|
|
34
|
+
initConfig.push(...getInstallData(module));
|
|
35
|
+
}
|
|
36
|
+
for (const module of moduleSetup.executors) {
|
|
37
|
+
initConfig.push(...getInstallData(module));
|
|
38
|
+
}
|
|
39
|
+
for (const module of moduleSetup.fallbacks) {
|
|
40
|
+
initConfig.push(...getInstallData(module));
|
|
41
|
+
}
|
|
42
|
+
for (const module of moduleSetup.hooks) {
|
|
43
|
+
initConfig.push(...getInstallData(module));
|
|
44
|
+
}
|
|
45
|
+
const initializationCallData = (0, viem_1.encodeFunctionData)({
|
|
46
|
+
abi: (0, viem_1.parseAbi)(['function initialize(bytes21,address,bytes,bytes,bytes[])']),
|
|
47
|
+
functionName: 'initialize',
|
|
48
|
+
args: [rootValidator, hook, validatorData, hookData, initConfig],
|
|
49
|
+
});
|
|
50
|
+
const factoryData = (0, viem_1.encodeFunctionData)({
|
|
51
|
+
abi: (0, viem_1.parseAbi)(['function deployWithFactory(address,bytes,bytes32)']),
|
|
52
|
+
functionName: 'deployWithFactory',
|
|
53
|
+
args: [KERNEL_FACTORY_ADDRESS, initializationCallData, salt],
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
factory: KERNEL_META_FACTORY_ADDRESS,
|
|
57
|
+
factoryData,
|
|
58
|
+
salt,
|
|
59
|
+
implementation: KERNEL_IMPLEMENTATION_ADDRESS,
|
|
60
|
+
initializationCallData,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function getAddress(config) {
|
|
64
|
+
const { salt, initializationCallData } = getDeployArgs(config);
|
|
65
|
+
const actualSalt = (0, viem_1.keccak256)((0, viem_1.concat)([initializationCallData, salt]));
|
|
66
|
+
return (0, viem_1.getContractAddress)({
|
|
67
|
+
from: KERNEL_FACTORY_ADDRESS,
|
|
68
|
+
opcode: 'CREATE2',
|
|
69
|
+
bytecode: KERNEL_BYTECODE,
|
|
70
|
+
salt: actualSalt,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function getInstallData(module) {
|
|
74
|
+
const HOOK_INSTALLED_ADDRESS = '0x0000000000000000000000000000000000000001';
|
|
75
|
+
switch (module.type) {
|
|
76
|
+
case common_1.MODULE_TYPE_ID_VALIDATOR: {
|
|
77
|
+
const data = (0, viem_1.encodeAbiParameters)([{ type: 'bytes' }, { type: 'bytes' }, { type: 'bytes' }], [module.initData, '0x', '0x']);
|
|
78
|
+
const initData = (0, viem_1.concat)([HOOK_INSTALLED_ADDRESS, data]);
|
|
79
|
+
const validatorId = (0, viem_1.concat)(['0x01', module.address]);
|
|
80
|
+
return [
|
|
81
|
+
(0, viem_1.encodeFunctionData)({
|
|
82
|
+
abi: (0, viem_1.parseAbi)(['function installModule(uint256,address,bytes)']),
|
|
83
|
+
functionName: 'installModule',
|
|
84
|
+
args: [module.type, module.address, initData],
|
|
85
|
+
}),
|
|
86
|
+
(0, viem_1.encodeFunctionData)({
|
|
87
|
+
abi: (0, viem_1.parseAbi)(['function grantAccess(bytes21,bytes4,bool)']),
|
|
88
|
+
functionName: 'grantAccess',
|
|
89
|
+
args: [validatorId, '0xe9ae5c53', true],
|
|
90
|
+
}),
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
case common_1.MODULE_TYPE_ID_EXECUTOR: {
|
|
94
|
+
const data = (0, viem_1.encodeAbiParameters)([{ type: 'bytes' }, { type: 'bytes' }], [module.initData, '0x']);
|
|
95
|
+
const initData = (0, viem_1.concat)([viem_1.zeroAddress, data]);
|
|
96
|
+
return [
|
|
97
|
+
(0, viem_1.encodeFunctionData)({
|
|
98
|
+
abi: (0, viem_1.parseAbi)(['function installModule(uint256,address,bytes)']),
|
|
99
|
+
functionName: 'installModule',
|
|
100
|
+
args: [module.type, module.address, initData],
|
|
101
|
+
}),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
case common_1.MODULE_TYPE_ID_FALLBACK: {
|
|
105
|
+
const [selector, flags, selectorData] = (0, viem_1.decodeAbiParameters)([
|
|
106
|
+
{ name: 'selector', type: 'bytes4' },
|
|
107
|
+
{ name: 'flags', type: 'bytes1' },
|
|
108
|
+
{ name: 'data', type: 'bytes' },
|
|
109
|
+
], module.initData);
|
|
110
|
+
const data = (0, viem_1.encodeAbiParameters)([{ type: 'bytes' }, { type: 'bytes' }], [(0, viem_1.concat)([flags, selectorData]), '0x']);
|
|
111
|
+
const initData = (0, viem_1.concat)([selector, HOOK_INSTALLED_ADDRESS, data]);
|
|
112
|
+
return [
|
|
113
|
+
(0, viem_1.encodeFunctionData)({
|
|
114
|
+
abi: (0, viem_1.parseAbi)(['function installModule(uint256,address,bytes)']),
|
|
115
|
+
functionName: 'installModule',
|
|
116
|
+
args: [module.type, module.address, initData],
|
|
117
|
+
}),
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
case common_1.MODULE_TYPE_ID_HOOK: {
|
|
121
|
+
return [
|
|
122
|
+
(0, viem_1.encodeFunctionData)({
|
|
123
|
+
abi: (0, viem_1.parseAbi)(['function installModule(uint256,address,bytes)']),
|
|
124
|
+
functionName: 'installModule',
|
|
125
|
+
args: [module.type, module.address, module.initData],
|
|
126
|
+
}),
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function get7702InitCalls() {
|
|
132
|
+
throw new Error('EIP-7702 is not yet supported for Kernel accounts');
|
|
133
|
+
}
|
|
134
|
+
function get7702SmartAccount() {
|
|
135
|
+
throw new Error('EIP-7702 is not yet supported for Kernel accounts');
|
|
136
|
+
}
|
|
137
|
+
async function getPackedSignature(signFn, hash, validator, accountAddress, transformSignature = (signature) => signature) {
|
|
138
|
+
const vId = validator.isRoot ? '0x00' : (0, viem_1.concat)(['0x01', validator.address]);
|
|
139
|
+
const signature = validator.isRoot
|
|
140
|
+
? await signFn(wrapMessageHash(hash, accountAddress))
|
|
141
|
+
: await signFn(hash);
|
|
142
|
+
const magicValueSigReplayable = (0, viem_1.keccak256)((0, viem_1.toHex)('kernel.replayable.signature'));
|
|
143
|
+
const packedSig = (0, viem_1.concat)([
|
|
144
|
+
vId,
|
|
145
|
+
magicValueSigReplayable,
|
|
146
|
+
transformSignature(signature),
|
|
147
|
+
]);
|
|
148
|
+
return packedSig;
|
|
149
|
+
}
|
|
150
|
+
function wrapMessageHash(messageHash, accountAddress) {
|
|
151
|
+
const _domainSeparator = (0, viem_1.domainSeparator)({
|
|
152
|
+
domain: {
|
|
153
|
+
name: 'Kernel',
|
|
154
|
+
version: KERNEL_VERSION,
|
|
155
|
+
chainId: 0,
|
|
156
|
+
verifyingContract: accountAddress,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
const kernelTypeHash = (0, viem_1.keccak256)((0, viem_1.stringToHex)('Kernel(bytes32 hash)'));
|
|
160
|
+
const wrappedMessageHash = (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'bytes32' }, { type: 'bytes32' }], [kernelTypeHash, messageHash]));
|
|
161
|
+
const digest = (0, viem_1.keccak256)((0, viem_1.concatHex)(['0x1901', _domainSeparator, wrappedMessageHash]));
|
|
162
|
+
return digest;
|
|
163
|
+
}
|
|
164
|
+
async function getSmartAccount(client, address, owners, validatorAddress, sign) {
|
|
165
|
+
return getBaseSmartAccount(address, client, validatorAddress, 'root', async () => {
|
|
166
|
+
return (0, validators_1.getMockSignature)(owners);
|
|
167
|
+
}, sign);
|
|
168
|
+
}
|
|
169
|
+
async function getSessionSmartAccount(client, address, session, validatorAddress, sign) {
|
|
170
|
+
return await getBaseSmartAccount(address, client, validatorAddress, 'validator', async () => {
|
|
171
|
+
const dummyOpSignature = (0, validators_1.getMockSignature)(session.owners);
|
|
172
|
+
return (0, validators_1.encodeSmartSessionSignature)(validators_1.SMART_SESSION_MODE_USE, (0, validators_1.getPermissionId)(session), dummyOpSignature);
|
|
173
|
+
}, async (hash) => {
|
|
174
|
+
const signature = await sign(hash);
|
|
175
|
+
return (0, validators_1.encodeSmartSessionSignature)(validators_1.SMART_SESSION_MODE_USE, (0, validators_1.getPermissionId)(session), signature);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async function getGuardianSmartAccount(client, address, guardians, validatorAddress, sign) {
|
|
179
|
+
return await getBaseSmartAccount(address, client, validatorAddress, 'validator', async () => {
|
|
180
|
+
return (0, validators_1.getMockSignature)(guardians);
|
|
181
|
+
}, async (hash) => {
|
|
182
|
+
return await sign(hash);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async function getBaseSmartAccount(address, client, validatorAddress, validatorType, getStubSignature, signUserOperation) {
|
|
186
|
+
return await (0, account_abstraction_1.toSmartAccount)({
|
|
187
|
+
client,
|
|
188
|
+
entryPoint: {
|
|
189
|
+
abi: account_abstraction_1.entryPoint07Abi,
|
|
190
|
+
address: account_abstraction_1.entryPoint07Address,
|
|
191
|
+
version: '0.7',
|
|
192
|
+
},
|
|
193
|
+
async decodeCalls() {
|
|
194
|
+
throw new Error('Not implemented');
|
|
195
|
+
},
|
|
196
|
+
async encodeCalls(calls) {
|
|
197
|
+
return (0, utils_1.encode7579Calls)({
|
|
198
|
+
mode: {
|
|
199
|
+
type: calls.length > 1 ? 'batchcall' : 'call',
|
|
200
|
+
revertOnError: false,
|
|
201
|
+
selector: '0x',
|
|
202
|
+
context: '0x',
|
|
203
|
+
},
|
|
204
|
+
callData: calls,
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
async getAddress() {
|
|
208
|
+
return address;
|
|
209
|
+
},
|
|
210
|
+
async getFactoryArgs() {
|
|
211
|
+
return {};
|
|
212
|
+
},
|
|
213
|
+
async getNonce() {
|
|
214
|
+
// Default mode
|
|
215
|
+
const mode = '0x00';
|
|
216
|
+
const type = validatorType === 'root' ? '0x00' : '0x01';
|
|
217
|
+
const identifier = validatorAddress;
|
|
218
|
+
const nonceKey = '0x0000';
|
|
219
|
+
const key = (0, viem_1.concat)([mode, type, identifier, nonceKey]);
|
|
220
|
+
return (0, utils_1.getAccountNonce)(client, {
|
|
221
|
+
address,
|
|
222
|
+
entryPointAddress: account_abstraction_1.entryPoint07Address,
|
|
223
|
+
key: BigInt(key),
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
async getStubSignature() {
|
|
227
|
+
return getStubSignature();
|
|
228
|
+
},
|
|
229
|
+
async signMessage() {
|
|
230
|
+
throw new Error('Not implemented');
|
|
231
|
+
},
|
|
232
|
+
async signTypedData() {
|
|
233
|
+
throw new Error('Not implemented');
|
|
234
|
+
},
|
|
235
|
+
async signUserOperation(parameters) {
|
|
236
|
+
const { chainId = client.chain?.id, ...userOperation } = parameters;
|
|
237
|
+
if (!chainId)
|
|
238
|
+
throw new Error('Chain id not found');
|
|
239
|
+
const hash = (0, account_abstraction_1.getUserOperationHash)({
|
|
240
|
+
userOperation: {
|
|
241
|
+
...userOperation,
|
|
242
|
+
sender: userOperation.sender ?? (await this.getAddress()),
|
|
243
|
+
signature: '0x',
|
|
244
|
+
},
|
|
245
|
+
entryPointAddress: account_abstraction_1.entryPoint07Address,
|
|
246
|
+
entryPointVersion: '0.7',
|
|
247
|
+
chainId: chainId,
|
|
248
|
+
});
|
|
249
|
+
return await signUserOperation(hash);
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.test.d.ts","sourceRoot":"","sources":["../../../accounts/kernel.test.ts"],"names":[],"mappings":""}
|