@rhinestone/sdk 1.0.8 → 1.0.10
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/signing/message.js +1 -1
- package/dist/src/accounts/walletClient.d.ts +27 -0
- package/dist/src/accounts/walletClient.d.ts.map +1 -1
- package/dist/src/accounts/walletClient.js +77 -0
- package/dist/src/actions/smart-sessions.d.ts +1 -10
- package/dist/src/actions/smart-sessions.d.ts.map +1 -1
- package/dist/src/actions/smart-sessions.js +0 -10
- package/dist/src/execution/smart-session.d.ts +5 -7
- package/dist/src/execution/smart-session.d.ts.map +1 -1
- package/dist/src/execution/smart-session.js +113 -228
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/modules/validators/smart-sessions.d.ts +6 -6
- package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions.js +6 -5
- package/package.json +2 -2
- package/dist/src/execution/smart-session.test.d.ts +0 -2
- package/dist/src/execution/smart-session.test.d.ts.map +0 -1
- package/dist/src/execution/smart-session.test.js +0 -34
|
@@ -14,7 +14,7 @@ async function sign(signers, chain, address, hash, isUserOpHash) {
|
|
|
14
14
|
return (0, common_1.signWithOwners)(signers, chain, address, hash, signingFunctions, isUserOpHash, sign);
|
|
15
15
|
}
|
|
16
16
|
case 'session': {
|
|
17
|
-
return (0, common_1.signWithSession)(signers, chain, address, hash,
|
|
17
|
+
return (0, common_1.signWithSession)(signers, chain, address, hash, false, sign);
|
|
18
18
|
}
|
|
19
19
|
case 'guardians': {
|
|
20
20
|
return (0, common_1.signWithGuardians)(signers, hash, signingFunctions);
|
|
@@ -4,4 +4,31 @@ import type { Account, WalletClient } from 'viem';
|
|
|
4
4
|
* Ensures address is set and routes sign methods through the provided client.
|
|
5
5
|
*/
|
|
6
6
|
export declare function walletClientToAccount(walletClient: WalletClient): Account;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a Para viem account with custom signing for Rhinestone compatibility.
|
|
9
|
+
*
|
|
10
|
+
* Para's MPC signatures use 0/1 v-byte recovery, but Rhinestone/Smart wallets
|
|
11
|
+
* expect 27/28 v-byte recovery. This wrapper adjusts Para signatures automatically.
|
|
12
|
+
*
|
|
13
|
+
* @param viemAccount - The Para viem account to wrap
|
|
14
|
+
* @param walletId - Optional wallet ID for Para signing operations
|
|
15
|
+
* @returns Account compatible with Rhinestone SDK
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const paraAccount = // ... Para viem account
|
|
20
|
+
* const wrappedAccount = wrapParaAccount(paraAccount, wallet.id)
|
|
21
|
+
*
|
|
22
|
+
* const rhinestoneAccount = await rhinestone.createAccount({
|
|
23
|
+
* owners: {
|
|
24
|
+
* type: "ecdsa",
|
|
25
|
+
* accounts: [wrappedAccount],
|
|
26
|
+
* },
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // Also works for EIP-7702 (signAuthorization uses original 0/1 v-byte)
|
|
30
|
+
* const authorization = await wrappedAccount.signAuthorization?.({ ... })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function wrapParaAccount(viemAccount: Account, walletId?: string): Account;
|
|
7
34
|
//# sourceMappingURL=walletClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"walletClient.d.ts","sourceRoot":"","sources":["../../../accounts/walletClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,
|
|
1
|
+
{"version":3,"file":"walletClient.d.ts","sourceRoot":"","sources":["../../../accounts/walletClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOP,YAAY,EACb,MAAM,MAAM,CAAA;AAGb;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CA2CzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,OAAO,EACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAsCT"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.walletClientToAccount = walletClientToAccount;
|
|
4
|
+
exports.wrapParaAccount = wrapParaAccount;
|
|
4
5
|
const error_1 = require("./error");
|
|
5
6
|
/**
|
|
6
7
|
* Adapts a Viem/Wagmi WalletClient into an Account-like signer that the SDK can consume.
|
|
@@ -36,3 +37,79 @@ function walletClientToAccount(walletClient) {
|
|
|
36
37
|
};
|
|
37
38
|
return account;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Wraps a Para viem account with custom signing for Rhinestone compatibility.
|
|
42
|
+
*
|
|
43
|
+
* Para's MPC signatures use 0/1 v-byte recovery, but Rhinestone/Smart wallets
|
|
44
|
+
* expect 27/28 v-byte recovery. This wrapper adjusts Para signatures automatically.
|
|
45
|
+
*
|
|
46
|
+
* @param viemAccount - The Para viem account to wrap
|
|
47
|
+
* @param walletId - Optional wallet ID for Para signing operations
|
|
48
|
+
* @returns Account compatible with Rhinestone SDK
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const paraAccount = // ... Para viem account
|
|
53
|
+
* const wrappedAccount = wrapParaAccount(paraAccount, wallet.id)
|
|
54
|
+
*
|
|
55
|
+
* const rhinestoneAccount = await rhinestone.createAccount({
|
|
56
|
+
* owners: {
|
|
57
|
+
* type: "ecdsa",
|
|
58
|
+
* accounts: [wrappedAccount],
|
|
59
|
+
* },
|
|
60
|
+
* })
|
|
61
|
+
*
|
|
62
|
+
* // Also works for EIP-7702 (signAuthorization uses original 0/1 v-byte)
|
|
63
|
+
* const authorization = await wrappedAccount.signAuthorization?.({ ... })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function wrapParaAccount(viemAccount, walletId) {
|
|
67
|
+
// Store the wallet ID for signing operations (for debugging purposes)
|
|
68
|
+
const effectiveWalletId = walletId || viemAccount.walletId || viemAccount._walletId;
|
|
69
|
+
// Store reference for potential debugging
|
|
70
|
+
if (effectiveWalletId) {
|
|
71
|
+
;
|
|
72
|
+
viemAccount._paraWalletId = effectiveWalletId;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
...viemAccount,
|
|
76
|
+
// Override signMessage to adjust v-byte for smart wallet compatibility
|
|
77
|
+
signMessage: async ({ message }) => {
|
|
78
|
+
if (!viemAccount.signMessage) {
|
|
79
|
+
throw new Error('Account does not support signMessage');
|
|
80
|
+
}
|
|
81
|
+
const originalSignature = await viemAccount.signMessage({ message });
|
|
82
|
+
return adjustVByte(originalSignature);
|
|
83
|
+
},
|
|
84
|
+
// Override signTypedData to adjust v-byte for smart wallet compatibility
|
|
85
|
+
signTypedData: async (typedData) => {
|
|
86
|
+
if (!viemAccount.signTypedData) {
|
|
87
|
+
throw new Error('Account does not support signTypedData');
|
|
88
|
+
}
|
|
89
|
+
const originalSignature = await viemAccount.signTypedData(typedData);
|
|
90
|
+
return adjustVByte(originalSignature);
|
|
91
|
+
},
|
|
92
|
+
// Keep signAuthorization as is for EIP-7702
|
|
93
|
+
signAuthorization: viemAccount.signAuthorization
|
|
94
|
+
? viemAccount.signAuthorization.bind(viemAccount)
|
|
95
|
+
: undefined,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Adjusts the v-byte in a signature from Para's 0/1 format to Ethereum's 27/28 format.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
function adjustVByte(signature) {
|
|
103
|
+
const V_OFFSET_FOR_ETHEREUM = 27;
|
|
104
|
+
const cleanSig = signature.startsWith('0x') ? signature.slice(2) : signature;
|
|
105
|
+
const r = cleanSig.slice(0, 64);
|
|
106
|
+
const s = cleanSig.slice(64, 128);
|
|
107
|
+
let v = parseInt(cleanSig.slice(128, 130), 16);
|
|
108
|
+
if (v < 27) {
|
|
109
|
+
v += V_OFFSET_FOR_ETHEREUM;
|
|
110
|
+
}
|
|
111
|
+
const adjustedSignature = `0x${r}${s}${v
|
|
112
|
+
.toString(16)
|
|
113
|
+
.padStart(2, '0')}`;
|
|
114
|
+
return adjustedSignature;
|
|
115
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Hex } from 'viem';
|
|
2
|
-
import type { SessionDetails } from '../execution/smart-session';
|
|
3
1
|
import type { Session } from '../types';
|
|
4
2
|
/**
|
|
5
3
|
* Enable a smart session
|
|
@@ -12,12 +10,5 @@ declare function enableSession(session: Session): {
|
|
|
12
10
|
data: `0x${string}`;
|
|
13
11
|
}>;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
* Encode a smart session signature
|
|
17
|
-
* @param sessionDetails Session details
|
|
18
|
-
* @param sessionSignature Session signature
|
|
19
|
-
* @returns Encoded smart session signature
|
|
20
|
-
*/
|
|
21
|
-
declare function encodeSmartSessionSignature(sessionDetails: SessionDetails, sessionSignature: Hex): `0x${string}`;
|
|
22
|
-
export { enableSession, encodeSmartSessionSignature };
|
|
13
|
+
export { enableSession };
|
|
23
14
|
//# sourceMappingURL=smart-sessions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-sessions.d.ts","sourceRoot":"","sources":["../../../actions/smart-sessions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"smart-sessions.d.ts","sourceRoot":"","sources":["../../../actions/smart-sessions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEvC;;;;GAIG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,OAAO;;;;;EAMtC;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.enableSession = enableSession;
|
|
4
|
-
exports.encodeSmartSessionSignature = encodeSmartSessionSignature;
|
|
5
4
|
const smart_sessions_1 = require("../modules/validators/smart-sessions");
|
|
6
5
|
/**
|
|
7
6
|
* Enable a smart session
|
|
@@ -15,12 +14,3 @@ function enableSession(session) {
|
|
|
15
14
|
},
|
|
16
15
|
};
|
|
17
16
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Encode a smart session signature
|
|
20
|
-
* @param sessionDetails Session details
|
|
21
|
-
* @param sessionSignature Session signature
|
|
22
|
-
* @returns Encoded smart session signature
|
|
23
|
-
*/
|
|
24
|
-
function encodeSmartSessionSignature(sessionDetails, sessionSignature) {
|
|
25
|
-
return (0, smart_sessions_1.encodeSmartSessionSignature)(sessionDetails.mode, sessionDetails.enableSessionData.permissionId, sessionSignature, sessionDetails.enableSessionData);
|
|
26
|
-
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { type Chain, type Hex } from 'viem';
|
|
2
|
-
import { type
|
|
2
|
+
import { type EnableSessionData } from '../modules/validators/smart-sessions';
|
|
3
3
|
import type { RhinestoneConfig, Session } from '../types';
|
|
4
4
|
interface SessionDetails {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
hashesAndChainIds: ChainDigest[];
|
|
5
|
+
signature: Hex;
|
|
6
|
+
nonces: bigint[];
|
|
8
7
|
enableSessionData: EnableSessionData;
|
|
9
8
|
}
|
|
10
|
-
declare function getSessionDetails(config: RhinestoneConfig, sessions: Session[], sessionIndex: number, signature?: Hex): Promise<SessionDetails>;
|
|
11
|
-
declare function getMultichainDigest(chainDigests: ChainDigest[]): Hex;
|
|
9
|
+
declare function getSessionDetails(config: RhinestoneConfig, sessions: Session[], sessionIndex: number, initialNonces?: bigint[], signature?: Hex): Promise<SessionDetails>;
|
|
12
10
|
declare function enableSmartSession(chain: Chain, config: RhinestoneConfig, session: Session): Promise<void>;
|
|
13
|
-
export { enableSmartSession, getSessionDetails
|
|
11
|
+
export { enableSmartSession, getSessionDetails };
|
|
14
12
|
export type { SessionDetails };
|
|
15
13
|
//# sourceMappingURL=smart-session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-session.d.ts","sourceRoot":"","sources":["../../../execution/smart-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"smart-session.d.ts","sourceRoot":"","sources":["../../../execution/smart-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,EAEV,KAAK,GAAG,EAIT,MAAM,MAAM,CAAA;AAiBb,OAAO,EACL,KAAK,iBAAiB,EAKvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGzD,UAAU,cAAc;IACtB,SAAS,EAAE,GAAG,CAAA;IACd,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,iBAAiB,EAAE,iBAAiB,CAAA;CACrC;AA6CD,iBAAe,iBAAiB,CAC9B,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,OAAO,EAAE,EACnB,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,cAAc,CAAC,CAiHzB;AA+BD,iBAAe,kBAAkB,CAC/B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,OAAO,iBA2BjB;AAED,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -2,113 +2,137 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.enableSmartSession = enableSmartSession;
|
|
4
4
|
exports.getSessionDetails = getSessionDetails;
|
|
5
|
-
exports.getMultichainDigest = getMultichainDigest;
|
|
6
5
|
const viem_1 = require("viem");
|
|
7
6
|
const accounts_1 = require("../accounts");
|
|
8
7
|
const utils_1 = require("../accounts/utils");
|
|
9
8
|
const validators_1 = require("../modules/validators");
|
|
10
9
|
const smart_sessions_1 = require("../modules/validators/smart-sessions");
|
|
11
10
|
const error_1 = require("./error");
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const smartSessionTypes = {
|
|
12
|
+
PolicyData: [
|
|
13
|
+
{ name: 'policy', type: 'address' },
|
|
14
|
+
{ name: 'initData', type: 'bytes' },
|
|
15
|
+
],
|
|
16
|
+
ActionData: [
|
|
17
|
+
{ name: 'actionTargetSelector', type: 'bytes4' },
|
|
18
|
+
{ name: 'actionTarget', type: 'address' },
|
|
19
|
+
{ name: 'actionPolicies', type: 'PolicyData[]' },
|
|
20
|
+
],
|
|
21
|
+
ERC7739Context: [
|
|
22
|
+
{ name: 'appDomainSeparator', type: 'bytes32' },
|
|
23
|
+
{ name: 'contentName', type: 'string[]' },
|
|
24
|
+
],
|
|
25
|
+
ERC7739Data: [
|
|
26
|
+
{ name: 'allowedERC7739Content', type: 'ERC7739Context[]' },
|
|
27
|
+
{ name: 'erc1271Policies', type: 'PolicyData[]' },
|
|
28
|
+
],
|
|
29
|
+
SignedPermissions: [
|
|
30
|
+
{ name: 'permitGenericPolicy', type: 'bool' },
|
|
31
|
+
{ name: 'permitAdminAccess', type: 'bool' },
|
|
32
|
+
{ name: 'ignoreSecurityAttestations', type: 'bool' },
|
|
33
|
+
{ name: 'permitERC4337Paymaster', type: 'bool' },
|
|
34
|
+
{ name: 'userOpPolicies', type: 'PolicyData[]' },
|
|
35
|
+
{ name: 'erc7739Policies', type: 'ERC7739Data' },
|
|
36
|
+
{ name: 'actions', type: 'ActionData[]' },
|
|
37
|
+
],
|
|
38
|
+
SignedSession: [
|
|
39
|
+
{ name: 'account', type: 'address' },
|
|
40
|
+
{ name: 'permissions', type: 'SignedPermissions' },
|
|
41
|
+
{ name: 'sessionValidator', type: 'address' },
|
|
42
|
+
{ name: 'sessionValidatorInitData', type: 'bytes' },
|
|
43
|
+
{ name: 'salt', type: 'bytes32' },
|
|
44
|
+
{ name: 'smartSession', type: 'address' },
|
|
45
|
+
{ name: 'nonce', type: 'uint256' },
|
|
46
|
+
],
|
|
47
|
+
ChainSession: [
|
|
48
|
+
{ name: 'chainId', type: 'uint64' },
|
|
49
|
+
{ name: 'session', type: 'SignedSession' },
|
|
50
|
+
],
|
|
51
|
+
MultiChainSession: [{ name: 'sessionsAndChainIds', type: 'ChainSession[]' }],
|
|
52
|
+
};
|
|
53
|
+
async function getSessionDetails(config, sessions, sessionIndex, initialNonces, signature) {
|
|
54
|
+
const chains = sessions
|
|
55
|
+
.map((session) => session.chain)
|
|
56
|
+
.filter((chain) => !!chain);
|
|
57
|
+
if (chains.length !== sessions.length) {
|
|
58
|
+
throw new error_1.SessionChainRequiredError();
|
|
59
|
+
}
|
|
14
60
|
const accountAddress = (0, accounts_1.getAddress)(config);
|
|
15
|
-
const
|
|
61
|
+
const publicClients = chains.map((chain) => (0, viem_1.createPublicClient)({
|
|
62
|
+
chain,
|
|
63
|
+
transport: (0, utils_1.createTransport)(chain, config.provider),
|
|
64
|
+
}));
|
|
65
|
+
const sessionDatas = sessions.map((session) => (0, smart_sessions_1.getSmartSessionData)(session));
|
|
66
|
+
const sessionNonces = await Promise.all(sessions.map((session, index) => initialNonces?.[index] ??
|
|
67
|
+
getSessionNonce(publicClients[index], accountAddress, (0, validators_1.getPermissionId)(session))));
|
|
68
|
+
const signedSessions = sessionDatas.map((session, index) => ({
|
|
69
|
+
account: accountAddress,
|
|
70
|
+
permissions: {
|
|
71
|
+
permitGenericPolicy: session.actions.some((action) => action.actionTarget === smart_sessions_1.SMART_SESSIONS_FALLBACK_TARGET_FLAG &&
|
|
72
|
+
action.actionTargetSelector ===
|
|
73
|
+
smart_sessions_1.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG),
|
|
74
|
+
permitAdminAccess: session.actions.some((action) => action.actionTargetSelector ===
|
|
75
|
+
smart_sessions_1.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION),
|
|
76
|
+
ignoreSecurityAttestations: false,
|
|
77
|
+
permitERC4337Paymaster: session.permitERC4337Paymaster,
|
|
78
|
+
userOpPolicies: session.userOpPolicies,
|
|
79
|
+
erc7739Policies: session.erc7739Policies,
|
|
80
|
+
actions: session.actions,
|
|
81
|
+
},
|
|
82
|
+
sessionValidator: session.sessionValidator,
|
|
83
|
+
sessionValidatorInitData: session.sessionValidatorInitData,
|
|
84
|
+
salt: session.salt,
|
|
85
|
+
smartSession: validators_1.SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
86
|
+
nonce: sessionNonces[index],
|
|
87
|
+
}));
|
|
88
|
+
const chainDigests = signedSessions.map((session, index) => ({
|
|
89
|
+
chainId: BigInt(chains[index].id),
|
|
90
|
+
sessionDigest: (0, viem_1.hashStruct)({
|
|
91
|
+
types: smartSessionTypes,
|
|
92
|
+
primaryType: 'SignedSession',
|
|
93
|
+
data: session,
|
|
94
|
+
}),
|
|
95
|
+
}));
|
|
96
|
+
const typedData = {
|
|
97
|
+
domain: {
|
|
98
|
+
name: 'SmartSession',
|
|
99
|
+
version: '1',
|
|
100
|
+
},
|
|
101
|
+
types: smartSessionTypes,
|
|
102
|
+
primaryType: 'MultiChainSession',
|
|
103
|
+
message: {
|
|
104
|
+
sessionsAndChainIds: signedSessions.map((session, index) => ({
|
|
105
|
+
chainId: BigInt(chains[index].id),
|
|
106
|
+
session,
|
|
107
|
+
})),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
16
110
|
const chain = sessions[sessionIndex].chain;
|
|
17
111
|
if (!chain) {
|
|
18
112
|
throw new error_1.SessionChainRequiredError();
|
|
19
113
|
}
|
|
20
114
|
const validator = {
|
|
21
|
-
address:
|
|
22
|
-
isRoot:
|
|
115
|
+
address: sessionDatas[sessionIndex].sessionValidator,
|
|
116
|
+
isRoot: false,
|
|
23
117
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(await (0, accounts_1.getPackedSignature)(config, undefined, chain, validator, sessionDetails.permissionEnableHash));
|
|
27
|
-
return sessionDetails;
|
|
28
|
-
}
|
|
29
|
-
async function getEnableSessionDetails(accountType, sessions, sessionIndex, accountAddress, provider) {
|
|
30
|
-
const chainDigests = [];
|
|
31
|
-
const chainSessions = [];
|
|
32
|
-
for (const session of sessions) {
|
|
33
|
-
const permissionId = (0, validators_1.getPermissionId)(session);
|
|
34
|
-
const sessionChain = session.chain;
|
|
35
|
-
if (!sessionChain) {
|
|
36
|
-
throw new error_1.SessionChainRequiredError();
|
|
37
|
-
}
|
|
38
|
-
const publicClient = (0, viem_1.createPublicClient)({
|
|
39
|
-
chain: sessionChain,
|
|
40
|
-
transport: (0, utils_1.createTransport)(sessionChain, provider),
|
|
41
|
-
});
|
|
42
|
-
const sessionNonce = await getSessionNonce(publicClient, accountAddress, permissionId);
|
|
43
|
-
const sessionData = await (0, smart_sessions_1.getSessionData)(session);
|
|
44
|
-
const sessionDigest = await getSessionDigest(publicClient, accountAddress, sessionData, permissionId, validators_1.SMART_SESSION_MODE_ENABLE);
|
|
45
|
-
chainDigests.push({
|
|
46
|
-
chainId: BigInt(sessionChain.id),
|
|
47
|
-
sessionDigest,
|
|
48
|
-
});
|
|
49
|
-
chainSessions.push({
|
|
50
|
-
chainId: BigInt(sessionChain.id),
|
|
51
|
-
session: {
|
|
52
|
-
permissions: {
|
|
53
|
-
permitGenericPolicy: false,
|
|
54
|
-
permitAdminAccess: false,
|
|
55
|
-
ignoreSecurityAttestations: false,
|
|
56
|
-
permitERC4337Paymaster: sessionData.permitERC4337Paymaster,
|
|
57
|
-
userOpPolicies: sessionData.userOpPolicies,
|
|
58
|
-
erc7739Policies: sessionData.erc7739Policies,
|
|
59
|
-
actions: sessionData.actions,
|
|
60
|
-
},
|
|
61
|
-
salt: sessionData.salt,
|
|
62
|
-
sessionValidator: sessionData.sessionValidator,
|
|
63
|
-
sessionValidatorInitData: sessionData.sessionValidatorInitData,
|
|
64
|
-
account: accountAddress,
|
|
65
|
-
smartSession: validators_1.SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
66
|
-
nonce: sessionNonce,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
const permissionEnableHash = getMultichainDigest(chainDigests);
|
|
71
|
-
const sessionToEnable = sessions[sessionIndex || 0];
|
|
72
|
-
const sessionChain = sessionToEnable.chain;
|
|
73
|
-
if (!sessionChain) {
|
|
74
|
-
throw new error_1.SessionChainRequiredError();
|
|
75
|
-
}
|
|
76
|
-
const sessionData = await (0, smart_sessions_1.getSessionData)(sessionToEnable);
|
|
118
|
+
const sessionSignature = signature ??
|
|
119
|
+
(await (0, accounts_1.getTypedDataPackedSignature)(config, undefined, chain, validator, typedData));
|
|
77
120
|
return {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
hashesAndChainIds: chainDigests,
|
|
121
|
+
nonces: sessionNonces,
|
|
122
|
+
signature: sessionSignature,
|
|
81
123
|
enableSessionData: {
|
|
82
|
-
permissionId: (0, validators_1.getPermissionId)(sessionToEnable),
|
|
83
|
-
validator: sessionData.sessionValidator,
|
|
84
|
-
accountType,
|
|
85
124
|
chainDigestIndex: sessionIndex,
|
|
86
|
-
hashesAndChainIds: chainDigests
|
|
87
|
-
|
|
88
|
-
|
|
125
|
+
hashesAndChainIds: chainDigests.map((chainDigest) => ({
|
|
126
|
+
chainId: BigInt(chainDigest.chainId),
|
|
127
|
+
sessionDigest: chainDigest.sessionDigest,
|
|
128
|
+
})),
|
|
129
|
+
sessionToEnable: sessionDatas[sessionIndex],
|
|
130
|
+
signature: sessionSignature,
|
|
89
131
|
},
|
|
90
132
|
};
|
|
91
133
|
}
|
|
92
|
-
function getMultichainDigest(chainDigests) {
|
|
93
|
-
function hashChainDigestMimicRPC(chainDigest) {
|
|
94
|
-
const CHAIN_SESSION_TYPEHASH = '0x1ea7e4bc398fa0ccd68d92b5d8931a3fd93eebe1cf0391b4ba28935801af7c80';
|
|
95
|
-
return (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes32', 'uint256', 'bytes32'], [
|
|
96
|
-
CHAIN_SESSION_TYPEHASH,
|
|
97
|
-
chainDigest.chainId,
|
|
98
|
-
chainDigest.sessionDigest,
|
|
99
|
-
]));
|
|
100
|
-
}
|
|
101
|
-
function hashChainDigestArray(chainDigests) {
|
|
102
|
-
const hashes = chainDigests.map((digest) => hashChainDigestMimicRPC(digest));
|
|
103
|
-
return (0, viem_1.keccak256)((0, viem_1.concat)(hashes));
|
|
104
|
-
}
|
|
105
|
-
const MULTICHAIN_SESSION_TYPEHASH = '0x0c9d02fb89a1da34d66ea2088dc9ee6a58efee71cef6f1bb849ed74fc6003d98';
|
|
106
|
-
const MULTICHAIN_DOMAIN_SEPARATOR = '0x057501e891776d1482927e5f094ae44049a4d893ba2d7b334dd7db8d38d3a0e1';
|
|
107
|
-
const structHash = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes32', 'bytes32'], [MULTICHAIN_SESSION_TYPEHASH, hashChainDigestArray(chainDigests)]));
|
|
108
|
-
return (0, viem_1.keccak256)((0, viem_1.concat)(['0x1901', MULTICHAIN_DOMAIN_SEPARATOR, structHash]));
|
|
109
|
-
}
|
|
110
134
|
async function getSessionNonce(client, account, permissionId) {
|
|
111
|
-
|
|
135
|
+
const nonce = await client.readContract({
|
|
112
136
|
address: validators_1.SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
113
137
|
abi: [
|
|
114
138
|
{
|
|
@@ -128,147 +152,8 @@ async function getSessionNonce(client, account, permissionId) {
|
|
|
128
152
|
],
|
|
129
153
|
functionName: 'getNonce',
|
|
130
154
|
args: [permissionId, account],
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
async function getSessionDigest(client, account, session, permissionId, mode) {
|
|
134
|
-
return (await client.readContract({
|
|
135
|
-
address: validators_1.SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
136
|
-
abi: [
|
|
137
|
-
{
|
|
138
|
-
type: 'function',
|
|
139
|
-
name: 'getSessionDigest',
|
|
140
|
-
inputs: [
|
|
141
|
-
{
|
|
142
|
-
name: 'permissionId',
|
|
143
|
-
type: 'bytes32',
|
|
144
|
-
internalType: 'PermissionId',
|
|
145
|
-
},
|
|
146
|
-
{ name: 'account', type: 'address', internalType: 'address' },
|
|
147
|
-
{
|
|
148
|
-
name: 'data',
|
|
149
|
-
type: 'tuple',
|
|
150
|
-
internalType: 'struct Session',
|
|
151
|
-
components: [
|
|
152
|
-
{
|
|
153
|
-
name: 'sessionValidator',
|
|
154
|
-
type: 'address',
|
|
155
|
-
internalType: 'contract ISessionValidator',
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
name: 'sessionValidatorInitData',
|
|
159
|
-
type: 'bytes',
|
|
160
|
-
internalType: 'bytes',
|
|
161
|
-
},
|
|
162
|
-
{ name: 'salt', type: 'bytes32', internalType: 'bytes32' },
|
|
163
|
-
{
|
|
164
|
-
name: 'userOpPolicies',
|
|
165
|
-
type: 'tuple[]',
|
|
166
|
-
internalType: 'struct PolicyData[]',
|
|
167
|
-
components: [
|
|
168
|
-
{
|
|
169
|
-
name: 'policy',
|
|
170
|
-
type: 'address',
|
|
171
|
-
internalType: 'address',
|
|
172
|
-
},
|
|
173
|
-
{ name: 'initData', type: 'bytes', internalType: 'bytes' },
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: 'erc7739Policies',
|
|
178
|
-
type: 'tuple',
|
|
179
|
-
internalType: 'struct ERC7739Data',
|
|
180
|
-
components: [
|
|
181
|
-
{
|
|
182
|
-
name: 'allowedERC7739Content',
|
|
183
|
-
type: 'tuple[]',
|
|
184
|
-
internalType: 'struct ERC7739Context[]',
|
|
185
|
-
components: [
|
|
186
|
-
{
|
|
187
|
-
name: 'appDomainSeparator',
|
|
188
|
-
type: 'bytes32',
|
|
189
|
-
internalType: 'bytes32',
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: 'contentName',
|
|
193
|
-
type: 'string[]',
|
|
194
|
-
internalType: 'string[]',
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: 'erc1271Policies',
|
|
200
|
-
type: 'tuple[]',
|
|
201
|
-
internalType: 'struct PolicyData[]',
|
|
202
|
-
components: [
|
|
203
|
-
{
|
|
204
|
-
name: 'policy',
|
|
205
|
-
type: 'address',
|
|
206
|
-
internalType: 'address',
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
name: 'initData',
|
|
210
|
-
type: 'bytes',
|
|
211
|
-
internalType: 'bytes',
|
|
212
|
-
},
|
|
213
|
-
],
|
|
214
|
-
},
|
|
215
|
-
],
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
name: 'actions',
|
|
219
|
-
type: 'tuple[]',
|
|
220
|
-
internalType: 'struct ActionData[]',
|
|
221
|
-
components: [
|
|
222
|
-
{
|
|
223
|
-
name: 'actionTargetSelector',
|
|
224
|
-
type: 'bytes4',
|
|
225
|
-
internalType: 'bytes4',
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
name: 'actionTarget',
|
|
229
|
-
type: 'address',
|
|
230
|
-
internalType: 'address',
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
name: 'actionPolicies',
|
|
234
|
-
type: 'tuple[]',
|
|
235
|
-
internalType: 'struct PolicyData[]',
|
|
236
|
-
components: [
|
|
237
|
-
{
|
|
238
|
-
name: 'policy',
|
|
239
|
-
type: 'address',
|
|
240
|
-
internalType: 'address',
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: 'initData',
|
|
244
|
-
type: 'bytes',
|
|
245
|
-
internalType: 'bytes',
|
|
246
|
-
},
|
|
247
|
-
],
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
name: 'permitERC4337Paymaster',
|
|
253
|
-
type: 'bool',
|
|
254
|
-
internalType: 'bool',
|
|
255
|
-
},
|
|
256
|
-
],
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
name: 'mode',
|
|
260
|
-
type: 'uint8',
|
|
261
|
-
internalType: 'enum SmartSessionMode',
|
|
262
|
-
},
|
|
263
|
-
],
|
|
264
|
-
outputs: [{ name: '', type: 'bytes32', internalType: 'bytes32' }],
|
|
265
|
-
stateMutability: 'view',
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
functionName: 'getSessionDigest',
|
|
269
|
-
// @ts-ignore Viem fails to infer the type of "session"
|
|
270
|
-
args: [permissionId, account, session, Number(mode)],
|
|
271
|
-
}));
|
|
155
|
+
});
|
|
156
|
+
return nonce;
|
|
272
157
|
}
|
|
273
158
|
async function enableSmartSession(chain, config, session) {
|
|
274
159
|
const publicClient = (0, viem_1.createPublicClient)({
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address, Chain, HashTypedDataParameters, Hex, SignableMessage, SignedAuthorizationList, TypedData } from 'viem';
|
|
2
2
|
import type { UserOperationReceipt } from 'viem/account-abstraction';
|
|
3
|
-
import { walletClientToAccount } from './accounts/walletClient';
|
|
3
|
+
import { walletClientToAccount, wrapParaAccount } from './accounts/walletClient';
|
|
4
4
|
import { type TransactionResult, type TransactionStatus, type UserOperationResult } from './execution';
|
|
5
5
|
import { type BatchPermit2Result, checkERC20AllowanceDirect, getPermit2Address, type MultiChainPermit2Config, type MultiChainPermit2Result, signPermit2Batch, signPermit2Sequential } from './execution/permit2';
|
|
6
6
|
import { type SessionDetails } from './execution/smart-session';
|
|
@@ -32,7 +32,7 @@ interface RhinestoneAccount {
|
|
|
32
32
|
getAddress: () => Address;
|
|
33
33
|
getPortfolio: (onTestnets?: boolean) => Promise<Portfolio>;
|
|
34
34
|
getMaxSpendableAmount: (chain: Chain, tokenAddress: Address | TokenSymbol, gasUnits: bigint, sponsored?: boolean) => Promise<bigint>;
|
|
35
|
-
getSessionDetails: (sessions: Session[], sessionIndex: number, signature?: Hex) => Promise<SessionDetails>;
|
|
35
|
+
getSessionDetails: (sessions: Session[], sessionIndex: number, initialNonces?: bigint[], signature?: Hex) => Promise<SessionDetails>;
|
|
36
36
|
getOwners: (chain: Chain) => Promise<{
|
|
37
37
|
accounts: Address[];
|
|
38
38
|
threshold: number;
|
|
@@ -58,6 +58,6 @@ declare class RhinestoneSDK {
|
|
|
58
58
|
status: IntentOpStatus["status"];
|
|
59
59
|
}>;
|
|
60
60
|
}
|
|
61
|
-
export { RhinestoneSDK, walletClientToAccount, getSupportedTokens, getTokenAddress, checkERC20AllowanceDirect, getPermit2Address, signPermit2Batch, signPermit2Sequential, };
|
|
61
|
+
export { RhinestoneSDK, walletClientToAccount, wrapParaAccount, getSupportedTokens, getTokenAddress, checkERC20AllowanceDirect, getPermit2Address, signPermit2Batch, signPermit2Sequential, };
|
|
62
62
|
export type { RhinestoneAccount, AccountType, RhinestoneAccountConfig, AccountProviderConfig, ProviderConfig, BundlerConfig, PaymasterConfig, Transaction, TokenSymbol, CallInput, Call, TokenRequest, OwnerSet, OwnableValidatorConfig, WebauthnValidatorConfig, MultiFactorValidatorConfig, SignerSet, Session, Recovery, Policy, UniversalActionPolicyParamCondition, PreparedTransactionData, SignedTransactionData, TransactionResult, PreparedUserOperationData, SignedUserOperationData, UserOperationResult, IntentCost, IntentInput, IntentOp, IntentOpStatus, IntentRoute, SettlementLayer, SignedIntentOp, Portfolio, MultiChainPermit2Config, MultiChainPermit2Result, BatchPermit2Result, };
|
|
63
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,KAAK,EACL,uBAAuB,EACvB,GA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aAAa,EACb,eAAe,EACf,WAAW,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,SAAS,EACT,OAAO,EACP,QAAQ,EACR,MAAM,EACN,mCAAmC,EACnC,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,cAAc,EACd,WAAW,EACX,eAAe,EACf,cAAc,EACd,SAAS,EAET,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,GACnB,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signPermit2Sequential = exports.signPermit2Batch = exports.getPermit2Address = exports.checkERC20AllowanceDirect = exports.getTokenAddress = exports.getSupportedTokens = exports.walletClientToAccount = exports.RhinestoneSDK = void 0;
|
|
3
|
+
exports.signPermit2Sequential = exports.signPermit2Batch = exports.getPermit2Address = exports.checkERC20AllowanceDirect = exports.getTokenAddress = exports.getSupportedTokens = exports.wrapParaAccount = exports.walletClientToAccount = exports.RhinestoneSDK = void 0;
|
|
4
4
|
const accounts_1 = require("./accounts");
|
|
5
5
|
const walletClient_1 = require("./accounts/walletClient");
|
|
6
6
|
Object.defineProperty(exports, "walletClientToAccount", { enumerable: true, get: function () { return walletClient_1.walletClientToAccount; } });
|
|
7
|
+
Object.defineProperty(exports, "wrapParaAccount", { enumerable: true, get: function () { return walletClient_1.wrapParaAccount; } });
|
|
7
8
|
const execution_1 = require("./execution");
|
|
8
9
|
const permit2_1 = require("./execution/permit2");
|
|
9
10
|
Object.defineProperty(exports, "checkERC20AllowanceDirect", { enumerable: true, get: function () { return permit2_1.checkERC20AllowanceDirect; } });
|
|
@@ -208,8 +209,8 @@ async function createRhinestoneAccount(config) {
|
|
|
208
209
|
const account = getAddress();
|
|
209
210
|
return (0, modules_1.getValidators)(accountType, account, chain, config.provider);
|
|
210
211
|
}
|
|
211
|
-
function getSessionDetails(sessions, sessionIndex, signature) {
|
|
212
|
-
return (0, smart_session_1.getSessionDetails)(config, sessions, sessionIndex, signature);
|
|
212
|
+
function getSessionDetails(sessions, sessionIndex, initialNonces, signature) {
|
|
213
|
+
return (0, smart_session_1.getSessionDetails)(config, sessions, sessionIndex, initialNonces, signature);
|
|
213
214
|
}
|
|
214
215
|
/**
|
|
215
216
|
* Check ERC20 allowance for the account owner and token (using Permit2 as spender)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Hex, type PublicClient } from 'viem';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RhinestoneAccountConfig, Session } from '../../types';
|
|
3
3
|
import { type Module } from '../common';
|
|
4
4
|
interface SessionData {
|
|
5
5
|
sessionValidator: Address;
|
|
@@ -70,27 +70,27 @@ interface ERC7739Context {
|
|
|
70
70
|
contentName: readonly string[];
|
|
71
71
|
}
|
|
72
72
|
interface EnableSessionData {
|
|
73
|
-
permissionId: Hex;
|
|
74
|
-
accountType: AccountType;
|
|
75
73
|
chainDigestIndex: number;
|
|
76
74
|
hashesAndChainIds: ChainDigest[];
|
|
77
75
|
sessionToEnable: SessionData;
|
|
78
76
|
signature: Hex;
|
|
79
|
-
validator: Address;
|
|
80
77
|
}
|
|
81
78
|
declare const SMART_SESSIONS_VALIDATOR_ADDRESS: Address;
|
|
82
79
|
declare const SMART_SESSION_MODE_USE = "0x00";
|
|
83
80
|
declare const SMART_SESSION_MODE_ENABLE = "0x01";
|
|
84
81
|
declare const SMART_SESSION_MODE_UNSAFE_ENABLE = "0x02";
|
|
85
|
-
declare
|
|
82
|
+
declare const SMART_SESSIONS_FALLBACK_TARGET_FLAG: Address;
|
|
83
|
+
declare const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG: Hex;
|
|
84
|
+
declare const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION: Hex;
|
|
86
85
|
declare function getEnableSessionCall(session: Session): Promise<{
|
|
87
86
|
to: `0x${string}`;
|
|
88
87
|
data: `0x${string}`;
|
|
89
88
|
}>;
|
|
89
|
+
declare function getSmartSessionData(session: Session): SessionData;
|
|
90
90
|
declare function getSmartSessionValidator(config: RhinestoneAccountConfig): Module | null;
|
|
91
91
|
declare function isSessionEnabled(client: PublicClient, address: Address, permissionId: Hex): Promise<boolean>;
|
|
92
92
|
declare function encodeSmartSessionSignature(mode: SmartSessionModeType, permissionId: Hex, signature: Hex, enableSessionData?: EnableSessionData): `0x${string}`;
|
|
93
93
|
declare function getPermissionId(session: Session): `0x${string}`;
|
|
94
|
-
export { SMART_SESSION_MODE_USE, SMART_SESSION_MODE_ENABLE, SMART_SESSIONS_VALIDATOR_ADDRESS,
|
|
94
|
+
export { SMART_SESSION_MODE_USE, SMART_SESSION_MODE_ENABLE, SMART_SESSIONS_VALIDATOR_ADDRESS, SMART_SESSIONS_FALLBACK_TARGET_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG, SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION, getSmartSessionData, getSmartSessionValidator, getEnableSessionCall, encodeSmartSessionSignature, getPermissionId, isSessionEnabled, };
|
|
95
95
|
export type { EnableSessionData, ChainSession, ChainDigest, SessionData, SmartSessionModeType, };
|
|
96
96
|
//# sourceMappingURL=smart-sessions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-sessions.d.ts","sourceRoot":"","sources":["../../../../modules/validators/smart-sessions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EAIZ,KAAK,GAAG,EAGR,KAAK,YAAY,EAIlB,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"smart-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M,4CAA4C,EAAE,GAAkB,CAAA;AACtE,QAAA,MAAM,2EAA2E,EAAE,GACrE,CAAA;AAUd,iBAAe,oBAAoB,CAAC,OAAO,EAAE,OAAO;;;GAUnD;AAED,iBAAS,mBAAmB,CAAC,OAAO,EAAE,OAAO,GA6CtC,WAAW,CACjB;AAED,iBAAS,wBAAwB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,MAAM,GAAG,IAAI,CAWf;AA8KD,iBAAe,gBAAgB,CAC7B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,GAAG,oBAiClB;AAED,iBAAS,2BAA2B,CAClC,IAAI,EAAE,oBAAoB,EAC1B,YAAY,EAAE,GAAG,EACjB,SAAS,EAAE,GAAG,EACd,iBAAiB,CAAC,EAAE,iBAAiB,iBAyBtC;AAoKD,iBAAS,eAAe,CAAC,OAAO,EAAE,OAAO,iBAyBxC;AAED,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,gCAAgC,EAChC,mCAAmC,EACnC,4CAA4C,EAC5C,2EAA2E,EAC3E,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,GACjB,CAAA;AACD,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,oBAAoB,GACrB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SMART_SESSIONS_VALIDATOR_ADDRESS = exports.SMART_SESSION_MODE_ENABLE = exports.SMART_SESSION_MODE_USE = void 0;
|
|
4
|
-
exports.
|
|
3
|
+
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = exports.SMART_SESSIONS_VALIDATOR_ADDRESS = exports.SMART_SESSION_MODE_ENABLE = exports.SMART_SESSION_MODE_USE = void 0;
|
|
4
|
+
exports.getSmartSessionData = getSmartSessionData;
|
|
5
5
|
exports.getSmartSessionValidator = getSmartSessionValidator;
|
|
6
6
|
exports.getEnableSessionCall = getEnableSessionCall;
|
|
7
7
|
exports.encodeSmartSessionSignature = encodeSmartSessionSignature;
|
|
@@ -26,7 +26,11 @@ const UNIVERSAL_ACTION_POLICY_ADDRESS = '0x0000006DDA6c463511C4e9B05CFc34C1247fC
|
|
|
26
26
|
const USAGE_LIMIT_POLICY_ADDRESS = '0x1F34eF8311345A3A4a4566aF321b313052F51493';
|
|
27
27
|
const VALUE_LIMIT_POLICY_ADDRESS = '0x730DA93267E7E513e932301B47F2ac7D062abC83';
|
|
28
28
|
const SMART_SESSIONS_FALLBACK_TARGET_FLAG = '0x0000000000000000000000000000000000000001';
|
|
29
|
+
exports.SMART_SESSIONS_FALLBACK_TARGET_FLAG = SMART_SESSIONS_FALLBACK_TARGET_FLAG;
|
|
29
30
|
const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = '0x00000001';
|
|
31
|
+
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG;
|
|
32
|
+
const SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = '0x00000002';
|
|
33
|
+
exports.SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION = SMART_SESSIONS_FALLBACK_TARGET_SELECTOR_FLAG_PERMITTED_TO_CALL_SMARTSESSION;
|
|
30
34
|
const ACTION_CONDITION_EQUAL = 0;
|
|
31
35
|
const ACTION_CONDITION_GREATER_THAN = 1;
|
|
32
36
|
const ACTION_CONDITION_LESS_THAN = 2;
|
|
@@ -34,9 +38,6 @@ const ACTION_CONDITION_GREATER_THAN_OR_EQUAL = 3;
|
|
|
34
38
|
const ACTION_CONDITION_LESS_THAN_OR_EQUAL = 4;
|
|
35
39
|
const ACTION_CONDITION_NOT_EQUAL = 5;
|
|
36
40
|
const ACTION_CONDITION_IN_RANGE = 6;
|
|
37
|
-
async function getSessionData(session) {
|
|
38
|
-
return getSmartSessionData(session);
|
|
39
|
-
}
|
|
40
41
|
async function getEnableSessionCall(session) {
|
|
41
42
|
const sessionData = getSmartSessionData(session);
|
|
42
43
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinestone/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "End-to-end chain abstraction and modularity toolkit",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Rhinestone",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"dependencies": {
|
|
129
129
|
"@rhinestone/shared-configs": "^1.4.4",
|
|
130
130
|
"ox": "^0.9.11",
|
|
131
|
-
"solady": "^0.1.
|
|
131
|
+
"solady": "^0.1.26"
|
|
132
132
|
},
|
|
133
133
|
"peerDependencies": {
|
|
134
134
|
"viem": "^2.28.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"smart-session.test.d.ts","sourceRoot":"","sources":["../../../execution/smart-session.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const smart_session_1 = require("./smart-session");
|
|
5
|
-
(0, vitest_1.describe)('Smart Session', () => {
|
|
6
|
-
(0, vitest_1.describe)('Multichain Digest', () => {
|
|
7
|
-
(0, vitest_1.test)('Single', () => {
|
|
8
|
-
const digest = (0, smart_session_1.getMultichainDigest)([
|
|
9
|
-
{
|
|
10
|
-
chainId: 421614n,
|
|
11
|
-
sessionDigest: '0x971daa09e9deb42457fb008fce5a63987379b31fd67ec6c16ff8b52517bfb373',
|
|
12
|
-
},
|
|
13
|
-
]);
|
|
14
|
-
(0, vitest_1.expect)(digest).toEqual('0xc0f5a263b2af5a01bc221835faf49b77459a5696f881c25fea9f8144c43f2326');
|
|
15
|
-
});
|
|
16
|
-
(0, vitest_1.test)('Multiple', () => {
|
|
17
|
-
const digest = (0, smart_session_1.getMultichainDigest)([
|
|
18
|
-
{
|
|
19
|
-
chainId: 84532n,
|
|
20
|
-
sessionDigest: '0xad3139c2b3ca57ba02e86ba3ad86dd18a05ba53650e3088ebd4fed71166d4bdd',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
chainId: 84532n,
|
|
24
|
-
sessionDigest: '0x1e6cc59dee4aca4a0d9b1fccd6fde197c831d5bd51163746f1947b352732f3db',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
chainId: 11155420n,
|
|
28
|
-
sessionDigest: '0x9b14ad37022e97faf4d9824c8d7e85b97f304839d24a3cd582575753df7d9239',
|
|
29
|
-
},
|
|
30
|
-
]);
|
|
31
|
-
(0, vitest_1.expect)(digest).toEqual('0x02f738c7e916839b958b21cbf8bf3697ca06fcb7d5fd5eba85ad49c8f2756adb');
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|