Skip to content

Commit 5e064ff

Browse files
authored
Merge pull request #63 from cometh-hq/develop
feat: add global policy
2 parents 3a647c6 + 9181aff commit 5e064ff

File tree

5 files changed

+84
-17
lines changed

5 files changed

+84
-17
lines changed

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "yoanslvy"
77
}
88
],
9-
"version": "1.0.2",
9+
"version": "1.0.3",
1010
"description": "SDK Cometh Connect 4337",
1111
"repository": "https://github.com/cometh-hq/connect-sdk-4337.git",
1212
"keywords": [

packages/sdk/src/constants.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Address } from "viem";
2-
import { muster } from "./customChains";
1+
import type { Address, Hex } from "viem";
2+
import { muster, swisstronikTestnet } from "./customChains";
33

44
const API_URL = "https://api.4337.cometh.io";
55

@@ -13,8 +13,12 @@ const LAUNCHPAD_ADDRESS: Address = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
1313

1414
const add7579FunctionSelector = "0xd78343d9";
1515
const hardcodeVerificationGasLimit7579 = 1000000n;
16+
const FALLBACK_TARGET_FLAG =
17+
"0x0000000000000000000000000000000000000001" as Address;
18+
const FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION =
19+
"0x00000001" as Hex;
1620

17-
const customChains = [muster];
21+
const customChains = [muster, swisstronikTestnet];
1822
const defaultClientConfig = {
1923
cacheTime: 60_000,
2024
batch: {
@@ -28,6 +32,8 @@ export {
2832
SENTINEL_MODULES,
2933
SAFE_7579_ADDRESS,
3034
LAUNCHPAD_ADDRESS,
35+
FALLBACK_TARGET_FLAG,
36+
FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION,
3137
customChains,
3238
add7579FunctionSelector,
3339
hardcodeVerificationGasLimit7579,

packages/sdk/src/core/modules/sessionKey/decorators/preparePermission.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { ComethSafeSmartAccount } from "@/core/accounts/safe/createSafeSmartAccount";
22

3+
import {
4+
FALLBACK_TARGET_FLAG,
5+
FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION,
6+
} from "@/constants";
37
import {
48
type ActionData,
59
type PolicyData,
@@ -84,7 +88,48 @@ export const getPermissionAction = async ({
8488
for (const sessionInfo of sessionRequestedInfo) {
8589
const actionPolicies: ActionData[] = [];
8690

87-
for (const actionPolicyInfo of sessionInfo.actionPoliciesInfo ?? []) {
91+
if (
92+
!sessionInfo.actionPoliciesInfo ||
93+
sessionInfo.actionPoliciesInfo.length === 0
94+
) {
95+
// If no action policies provided, use sudo action
96+
const session = {
97+
chainId: BigInt(client?.chain?.id as number),
98+
sessionValidator: sessionInfo.sessionValidator as Address,
99+
sessionValidatorInitData: encodeValidationData({
100+
threshold: 1,
101+
owners: [sessionInfo.sessionKeyData],
102+
}),
103+
salt: sessionInfo.salt ?? generateSalt(),
104+
userOpPolicies: [getSudoPolicy()],
105+
actions: [
106+
{
107+
actionTarget: FALLBACK_TARGET_FLAG,
108+
actionTargetSelector:
109+
FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION,
110+
actionPolicies: [
111+
{
112+
policy: getSudoPolicy().policy,
113+
initData: "0x" as Hex,
114+
},
115+
],
116+
},
117+
],
118+
erc7739Policies: {
119+
allowedERC7739Content: [],
120+
erc1271Policies: [],
121+
},
122+
permitERC4337Paymaster: true,
123+
};
124+
125+
const permissionId = await getPermissionId({ session });
126+
permissionIds.push(permissionId);
127+
sessions.push(session);
128+
continue;
129+
}
130+
131+
// Existing logic for when actionPoliciesInfo is not empty
132+
for (const actionPolicyInfo of sessionInfo.actionPoliciesInfo) {
88133
if (actionPolicyInfo.abi) {
89134
// Resolve the abi to multiple function selectors...
90135
const resolvedPolicyInfos = abiToPoliciesInfo(actionPolicyInfo);
@@ -116,8 +161,6 @@ export const getPermissionAction = async ({
116161
permitERC4337Paymaster: true,
117162
};
118163

119-
console.log({ session });
120-
121164
const permissionId = await getPermissionId({
122165
session,
123166
});

packages/sdk/src/customChains.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,34 @@ export const muster = defineChain({
1111
},
1212
rpcUrls: {
1313
default: {
14-
http: [
15-
process.env.RPC_URL_MUSTER_TESTNET ||
16-
"https://muster.alt.technology/",
17-
],
14+
http: ["https://muster.alt.technology/"],
1815
},
1916
public: {
20-
http: [
21-
process.env.RPC_URL_MUSTER_TESTNET ||
22-
"https://muster.alt.technology/",
23-
],
17+
http: ["https://muster.alt.technology/"],
18+
},
19+
},
20+
contracts: {
21+
multicall3: {
22+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
23+
},
24+
},
25+
});
26+
27+
export const swisstronikTestnet = defineChain({
28+
id: 1291,
29+
name: "Swisstronik testnet",
30+
network: "swisstronik testnet",
31+
nativeCurrency: {
32+
decimals: 18,
33+
name: "Ether",
34+
symbol: "ETH",
35+
},
36+
rpcUrls: {
37+
default: {
38+
http: ["https://json-rpc.testnet.swisstronik.com/unencrypted/"],
39+
},
40+
public: {
41+
http: ["https://json-rpc.testnet.swisstronik.com/unencrypted/"],
2442
},
2543
},
2644
contracts: {

packages/sdk/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ import { retrieveLegacyWalletAddress } from "./migrationKit/retrieveLegacyWallet
4343

4444
import type { GrantPermissionParameters } from "./core/modules/sessionKey/decorators/grantPermission";
4545

46+
import { SmartSessionMode } from "@rhinestone/module-sdk";
4647
import type { UsePermissionParameters } from "./core/modules/sessionKey/decorators/usePermission";
4748
import type {
4849
CreateSessionDataParams,
4950
GrantPermissionResponse,
5051
} from "./core/modules/sessionKey/types";
51-
import { SmartSessionMode } from "@rhinestone/module-sdk";
5252

5353
export {
5454
createSigner,
@@ -69,7 +69,7 @@ export {
6969
toSmartSessionsSigner,
7070
ENTRYPOINT_ADDRESS_V07,
7171
customChains,
72-
SmartSessionMode
72+
SmartSessionMode,
7373
};
7474

7575
export type {

0 commit comments

Comments
 (0)