@@ -2,47 +2,47 @@ import type { BaseTransactionOptions } from "../../../transaction/types.js";
22import { randomBytesHex } from "../../../utils/random.js" ;
33import type { Account } from "../../../wallets/interfaces/wallet.js" ;
44import {
5- createSessionWithSig ,
6- isCreateSessionWithSigSupported ,
5+ createSessionWithSig ,
6+ isCreateSessionWithSigSupported ,
77} from "../__generated__/MinimalAccount/write/createSessionWithSig.js" ;
88import {
9- type CallSpecInput ,
10- CallSpecRequest ,
11- ConstraintRequest ,
12- SessionSpecRequest ,
13- type TransferSpecInput ,
14- TransferSpecRequest ,
15- UsageLimitRequest ,
9+ type CallSpecInput ,
10+ CallSpecRequest ,
11+ ConstraintRequest ,
12+ SessionSpecRequest ,
13+ type TransferSpecInput ,
14+ TransferSpecRequest ,
15+ UsageLimitRequest ,
1616} from "./types.js" ;
1717
1818/**
1919 * @extension ERC7702
2020 */
2121export type CreateSessionKeyOptions = {
22- /**
23- * The admin account that will perform the operation.
24- */
25- account : Account ;
26- /**
27- * The address to add as a session key.
28- */
29- sessionKeyAddress : string ;
30- /**
31- * How long the session key should be valid for, in seconds.
32- */
33- durationInSeconds : number ;
34- /**
35- * Whether to grant full execution permissions to the session key.
36- */
37- grantFullPermissions ?: boolean ;
38- /**
39- * Smart contract interaction policies to apply to the session key, ignored if grantFullPermissions is true.
40- */
41- callPolicies ?: CallSpecInput [ ] ;
42- /**
43- * Value transfer policies to apply to the session key, ignored if grantFullPermissions is true.
44- */
45- transferPolicies ?: TransferSpecInput [ ] ;
22+ /**
23+ * The admin account that will perform the operation.
24+ */
25+ account : Account ;
26+ /**
27+ * The address to add as a session key.
28+ */
29+ sessionKeyAddress : string ;
30+ /**
31+ * How long the session key should be valid for, in seconds.
32+ */
33+ durationInSeconds : number ;
34+ /**
35+ * Whether to grant full execution permissions to the session key.
36+ */
37+ grantFullPermissions ?: boolean ;
38+ /**
39+ * Smart contract interaction policies to apply to the session key, ignored if grantFullPermissions is true.
40+ */
41+ callPolicies ?: CallSpecInput [ ] ;
42+ /**
43+ * Value transfer policies to apply to the session key, ignored if grantFullPermissions is true.
44+ */
45+ transferPolicies ?: TransferSpecInput [ ] ;
4646} ;
4747
4848/**
@@ -68,100 +68,100 @@ export type CreateSessionKeyOptions = {
6868 * @extension ERC7702
6969 */
7070export function createSessionKey (
71- options : BaseTransactionOptions < CreateSessionKeyOptions > ,
71+ options : BaseTransactionOptions < CreateSessionKeyOptions > ,
7272) {
73- const {
74- contract,
75- account,
76- sessionKeyAddress,
77- durationInSeconds,
78- grantFullPermissions,
79- callPolicies,
80- transferPolicies,
81- } = options ;
73+ const {
74+ contract,
75+ account,
76+ sessionKeyAddress,
77+ durationInSeconds,
78+ grantFullPermissions,
79+ callPolicies,
80+ transferPolicies,
81+ } = options ;
8282
83- if ( durationInSeconds <= 0 ) {
84- throw new Error ( "durationInSeconds must be positive" ) ;
85- }
83+ if ( durationInSeconds <= 0 ) {
84+ throw new Error ( "durationInSeconds must be positive" ) ;
85+ }
8686
87- return createSessionWithSig ( {
88- async asyncParams ( ) {
89- const req = {
90- callPolicies : ( callPolicies || [ ] ) . map ( ( policy ) => ( {
91- constraints : ( policy . constraints || [ ] ) . map ( ( constraint ) => ( {
92- condition : Number ( constraint . condition ) ,
93- index : constraint . index || BigInt ( 0 ) ,
94- limit : constraint . limit
95- ? {
96- limit : constraint . limit . limit ,
97- limitType : Number ( constraint . limit . limitType ) ,
98- period : constraint . limit . period ,
99- }
100- : {
101- limit : BigInt ( 0 ) ,
102- limitType : 0 ,
103- period : BigInt ( 0 ) ,
104- } ,
105- refValue : constraint . refValue || "0x" ,
106- } ) ) ,
107- maxValuePerUse : policy . maxValuePerUse || BigInt ( 0 ) ,
108- selector : policy . selector ,
109- target : policy . target ,
110- valueLimit : policy . valueLimit
111- ? {
112- limit : policy . valueLimit . limit ,
113- limitType : Number ( policy . valueLimit . limitType ) ,
114- period : policy . valueLimit . period ,
115- }
116- : {
117- limit : BigInt ( 0 ) ,
118- limitType : 0 ,
119- period : BigInt ( 0 ) ,
120- } ,
121- } ) ) ,
122- expiresAt : BigInt ( Math . floor ( Date . now ( ) / 1000 ) + durationInSeconds ) ,
123- isWildcard : grantFullPermissions ?? true ,
124- signer : sessionKeyAddress ,
125- transferPolicies : ( transferPolicies || [ ] ) . map ( ( policy ) => ( {
126- maxValuePerUse : policy . maxValuePerUse || BigInt ( 0 ) ,
127- target : policy . target ,
128- valueLimit : policy . valueLimit
129- ? {
130- limit : policy . valueLimit . limit ,
131- limitType : Number ( policy . valueLimit . limitType ) ,
132- period : policy . valueLimit . period ,
133- }
134- : {
135- limit : BigInt ( 0 ) ,
136- limitType : 0 ,
137- period : BigInt ( 0 ) ,
138- } ,
139- } ) ) ,
140- uid : await randomBytesHex ( ) ,
141- } ;
87+ return createSessionWithSig ( {
88+ async asyncParams ( ) {
89+ const req = {
90+ callPolicies : ( callPolicies || [ ] ) . map ( ( policy ) => ( {
91+ constraints : ( policy . constraints || [ ] ) . map ( ( constraint ) => ( {
92+ condition : Number ( constraint . condition ) ,
93+ index : constraint . index || BigInt ( 0 ) ,
94+ limit : constraint . limit
95+ ? {
96+ limit : constraint . limit . limit ,
97+ limitType : Number ( constraint . limit . limitType ) ,
98+ period : constraint . limit . period ,
99+ }
100+ : {
101+ limit : BigInt ( 0 ) ,
102+ limitType : 0 ,
103+ period : BigInt ( 0 ) ,
104+ } ,
105+ refValue : constraint . refValue || "0x" ,
106+ } ) ) ,
107+ maxValuePerUse : policy . maxValuePerUse || BigInt ( 0 ) ,
108+ selector : policy . selector ,
109+ target : policy . target ,
110+ valueLimit : policy . valueLimit
111+ ? {
112+ limit : policy . valueLimit . limit ,
113+ limitType : Number ( policy . valueLimit . limitType ) ,
114+ period : policy . valueLimit . period ,
115+ }
116+ : {
117+ limit : BigInt ( 0 ) ,
118+ limitType : 0 ,
119+ period : BigInt ( 0 ) ,
120+ } ,
121+ } ) ) ,
122+ expiresAt : BigInt ( Math . floor ( Date . now ( ) / 1000 ) + durationInSeconds ) ,
123+ isWildcard : grantFullPermissions ?? true ,
124+ signer : sessionKeyAddress ,
125+ transferPolicies : ( transferPolicies || [ ] ) . map ( ( policy ) => ( {
126+ maxValuePerUse : policy . maxValuePerUse || BigInt ( 0 ) ,
127+ target : policy . target ,
128+ valueLimit : policy . valueLimit
129+ ? {
130+ limit : policy . valueLimit . limit ,
131+ limitType : Number ( policy . valueLimit . limitType ) ,
132+ period : policy . valueLimit . period ,
133+ }
134+ : {
135+ limit : BigInt ( 0 ) ,
136+ limitType : 0 ,
137+ period : BigInt ( 0 ) ,
138+ } ,
139+ } ) ) ,
140+ uid : await randomBytesHex ( ) ,
141+ } ;
142142
143- const signature = await account . signTypedData ( {
144- domain : {
145- chainId : contract . chain . id ,
146- name : "MinimalAccount" ,
147- verifyingContract : contract . address ,
148- version : "1" ,
149- } ,
150- message : req ,
151- primaryType : "SessionSpec" ,
152- types : {
153- CallSpec : CallSpecRequest ,
154- Constraint : ConstraintRequest ,
155- SessionSpec : SessionSpecRequest ,
156- TransferSpec : TransferSpecRequest ,
157- UsageLimit : UsageLimitRequest ,
158- } ,
159- } ) ;
143+ const signature = await account . signTypedData ( {
144+ domain : {
145+ chainId : contract . chain . id ,
146+ name : "MinimalAccount" ,
147+ verifyingContract : contract . address ,
148+ version : "1" ,
149+ } ,
150+ message : req ,
151+ primaryType : "SessionSpec" ,
152+ types : {
153+ CallSpec : CallSpecRequest ,
154+ Constraint : ConstraintRequest ,
155+ SessionSpec : SessionSpecRequest ,
156+ TransferSpec : TransferSpecRequest ,
157+ UsageLimit : UsageLimitRequest ,
158+ } ,
159+ } ) ;
160160
161- return { sessionSpec : req , signature } ;
162- } ,
163- contract,
164- } ) ;
161+ return { sessionSpec : req , signature } ;
162+ } ,
163+ contract,
164+ } ) ;
165165}
166166
167167/**
@@ -177,5 +177,5 @@ export function createSessionKey(
177177 * ```
178178 */
179179export function isCreateSessionKeySupported ( availableSelectors : string [ ] ) {
180- return isCreateSessionWithSigSupported ( availableSelectors ) ;
180+ return isCreateSessionWithSigSupported ( availableSelectors ) ;
181181}
0 commit comments