88 AuthSig ,
99 LIT_NETWORKS_KEYS ,
1010 AuthCallbackParams ,
11+ StorageProvider ,
1112} from '@lit-protocol/types' ;
1213import {
1314 LitAccessControlConditionResource ,
@@ -16,7 +17,8 @@ import {
1617} from '@lit-protocol/auth-helpers' ;
1718import { Signer } from 'ethers' ;
1819import { LIT_ABILITY } from '@lit-protocol/constants' ;
19- import { disconnectWeb3 , LitNodeClient , LitNodeClientNodeJs } from '@lit-protocol/lit-node-client' ;
20+ import { disconnectWeb3 , LitNodeClient } from '@lit-protocol/lit-node-client' ;
21+ import type { LitNodeClientNodeJs } from '@lit-protocol/lit-node-client' ;
2022
2123/**
2224 * @class LitProvider
@@ -53,7 +55,7 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
5355 /**
5456 * @property {any } storageProvider - The storage provider for the Node.js Lit client.
5557 */
56- private storageProvider : any | null = null ;
58+ private nodeJsStorageProvider : StorageProvider | undefined ;
5759
5860 /**
5961 * @property {boolean } debug - A boolean indicating if debug mode is enabled.
@@ -75,11 +77,13 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
7577 network : LIT_NETWORKS_KEYS ,
7678 nodeConnectionConfig : NodeConnectionConfig ,
7779 debug ?: boolean ,
80+ nodeJsStorageProvider ?: StorageProvider ,
7881 ) {
7982 this . chain = chain ;
8083 this . network = network ;
8184 this . dataAccess = new HttpDataAccess ( { nodeConnectionConfig } ) ;
8285 this . debug = debug || false ;
86+ this . nodeJsStorageProvider = nodeJsStorageProvider ;
8387 }
8488
8589 /**
@@ -98,27 +102,10 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
98102 } ) ;
99103 await this . client . connect ( ) ;
100104 } else {
101- // Evaluate the code in a way that prevents static analysis
102- const getNodeStorage = new Function (
103- `
104- return import('node-localstorage').then(m => m.LocalStorage);
105- ` ,
106- ) ;
107-
108- const LocalStorage = await getNodeStorage ( ) ;
109- const localStorage = new LocalStorage ( './request-network-lit-protocol-cipher' ) ;
110-
111- this . storageProvider = {
112- getItem : ( key : string ) => localStorage . getItem ( key ) ,
113- setItem : ( key : string , value : string ) => localStorage . setItem ( key , value ) ,
114- removeItem : ( key : string ) => localStorage . removeItem ( key ) ,
115- clear : ( ) => localStorage . clear ( ) ,
116- provider : localStorage ,
117- } ;
118-
105+ const { LitNodeClientNodeJs } = await import ( '@lit-protocol/lit-node-client' ) ;
119106 this . client = new LitNodeClientNodeJs ( {
120107 litNetwork : this . network ,
121- storageProvider : this . storageProvider ,
108+ storageProvider : this . nodeJsStorageProvider ,
122109 debug : this . debug ,
123110 } ) ;
124111
@@ -139,8 +126,8 @@ export default class LitProvider implements CipherProviderTypes.ICipherProvider
139126 disconnectWeb3 ( ) ;
140127 }
141128 this . sessionSigs = null ;
142- if ( this . storageProvider ) {
143- this . storageProvider . clear ( ) ;
129+ if ( this . nodeJsStorageProvider ) {
130+ this . nodeJsStorageProvider . provider . clear ( ) ;
144131 }
145132 }
146133
0 commit comments