@@ -6,17 +6,36 @@ import {
66} from '@lit-protocol/auth' ;
77import { createLitClient } from '@lit-protocol/lit-client' ;
88import { resolveNetworkImportName } from '../../helper/network' ;
9- import { initFast } from '../../init' ;
9+ import { AuthData } from '@lit-protocol/schemas' ;
10+ import { AuthManagerInstance , LitClientInstance } from '../../types' ;
1011
11- type PregenContext = Awaited < ReturnType < typeof initFast > > ;
12+ type PregenDelegationParams = {
13+ authManager : AuthManagerInstance ;
14+ authData : AuthData ;
15+ pkpPublicKey : string ;
16+ clientLitClient : LitClientInstance ;
17+ fallbackLitClient ?: LitClientInstance ;
18+ networkName ?: string ;
19+ } ;
1220
13- export const createPregenDelegationServerReuseTest = ( ctx : PregenContext ) => {
21+ export const createPregenDelegationServerReuseTest = (
22+ params : PregenDelegationParams
23+ ) => {
1424 return async ( ) => {
25+ const {
26+ authManager,
27+ authData,
28+ pkpPublicKey,
29+ clientLitClient,
30+ fallbackLitClient,
31+ networkName,
32+ } = params ;
33+
1534 const sessionKeyPair = generateSessionKeyPair ( ) ;
1635 const delegationAuthSig =
17- await ctx . authManager . generatePkpDelegationAuthSig ( {
18- pkpPublicKey : ctx . aliceViemAccountPkp . pubkey ,
19- authData : ctx . aliceViemAccountAuthData ,
36+ await authManager . generatePkpDelegationAuthSig ( {
37+ pkpPublicKey,
38+ authData,
2039 sessionKeyPair,
2140 authConfig : {
2241 resources : [
@@ -26,11 +45,11 @@ export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
2645 ] ,
2746 expiration : new Date ( Date . now ( ) + 1000 * 60 * 15 ) . toISOString ( ) ,
2847 } ,
29- litClient : ctx . litClient ,
48+ litClient : clientLitClient ,
3049 } ) ;
3150
3251 const envelope = JSON . stringify ( {
33- pkpPublicKey : ctx . aliceViemAccountPkp . pubkey ,
52+ pkpPublicKey,
3453 payload : Buffer . from (
3554 JSON . stringify ( { sessionKeyPair, delegationAuthSig } ) ,
3655 'utf8'
@@ -57,7 +76,7 @@ export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
5776 const serverAuthManager = createAuthManager ( {
5877 storage : storagePlugins . localStorageNode ( {
5978 appName : 'e2e-server-reuse' ,
60- networkName : process . env [ 'NETWORK' ] ?? 'naga-dev' ,
79+ networkName : networkName ?? 'naga-dev' ,
6180 storagePath : './.e2e/server-reuse-storage' ,
6281 } ) ,
6382 } ) ;
@@ -72,12 +91,12 @@ export const createPregenDelegationServerReuseTest = (ctx: PregenContext) => {
7291 let litClient ;
7392 try {
7493 const networksModule = await import ( '@lit-protocol/networks' ) ;
75- const importName = resolveNetworkImportName ( process . env [ 'NETWORK' ] ) ;
94+ const importName = resolveNetworkImportName ( networkName ) ;
7695 const networkModule = networksModule [ importName ] ;
7796 litClient = await createLitClient ( { network : networkModule } ) ;
7897 await litClient . connect ( ) ;
7998 } catch {
80- litClient = ctx . litClient ;
99+ litClient = fallbackLitClient ?? clientLitClient ;
81100 }
82101
83102 const result = await litClient . chain . ethereum . pkpSign ( {
0 commit comments