Skip to content

Commit 5bf5189

Browse files
authored
Merge pull request #839 from LIT-Protocol/feature/node-4604-fix-litclient-return-type
Feature/node 4604 fix litclient return type
2 parents f3c4ca7 + 017b93b commit 5bf5189

File tree

4 files changed

+51
-38
lines changed

4 files changed

+51
-38
lines changed

e2e/artillery/processors/multi-endpoint.ts

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,42 @@ import {
3838
let sharedContext: any = null;
3939
let alicePkpAuthContext: any = null;
4040
let aliceCustomAuthContext: any = null;
41+
let initializationPromise: Promise<any> | null = null;
4142

4243
/**
4344
* Initialize the shared context once per Artillery run
4445
*/
4546
async function initializeSharedContext() {
4647
if (sharedContext) return sharedContext;
48+
49+
// Prevent race conditions by ensuring only one initialization happens
50+
if (initializationPromise) {
51+
return await initializationPromise;
52+
}
4753

48-
try {
49-
console.log('🚀 Initializing Artillery shared context...');
50-
51-
// Use the same init function as e2e tests
52-
sharedContext = await init();
53-
54-
// Create auth contexts using helper functions
55-
alicePkpAuthContext = await createPkpAuthContext(sharedContext);
56-
aliceCustomAuthContext = await createCustomAuthContext(sharedContext);
54+
initializationPromise = (async () => {
55+
try {
56+
console.log('🚀 Initializing Artillery shared context...');
57+
58+
// Use the same init function as e2e tests
59+
sharedContext = await init();
60+
61+
// Create auth contexts using helper functions
62+
alicePkpAuthContext = await createPkpAuthContext(sharedContext);
63+
aliceCustomAuthContext = await createCustomAuthContext(sharedContext);
64+
65+
console.log('✅ Artillery shared context initialized');
66+
return sharedContext;
67+
} catch (error) {
68+
console.error('❌ Failed to initialize Artillery context:', error);
69+
// Reset state on failure so retry is possible
70+
initializationPromise = null;
71+
sharedContext = null;
72+
throw error;
73+
}
74+
})();
5775

58-
console.log('✅ Artillery shared context initialized');
59-
return sharedContext;
60-
} catch (error) {
61-
console.error('❌ Failed to initialize Artillery context:', error);
62-
throw error;
63-
}
76+
return await initializationPromise;
6477
}
6578

6679
/**
@@ -166,7 +179,7 @@ export async function runMultiEndpointTest(context: any, events: any) {
166179
/**
167180
* PKP Sign test functions
168181
*/
169-
export async function runPkpSignTest(context, events) {
182+
export async function runPkpSignTest(context: any, events: any) {
170183
await initializeSharedContext();
171184

172185
const parallelism = context.vars.parallelism || 5;
@@ -176,7 +189,7 @@ export async function runPkpSignTest(context, events) {
176189
await runTestWithMetrics('pkp_sign', testFn, context, events, parallelism);
177190
}
178191

179-
export async function runPkpSignTestWithEoa(context, events) {
192+
export async function runPkpSignTestWithEoa(context: any, events: any) {
180193
await initializeSharedContext();
181194

182195
const parallelism = context.vars.parallelism || 5;
@@ -192,7 +205,7 @@ export async function runPkpSignTestWithEoa(context, events) {
192205
);
193206
}
194207

195-
export async function runPkpSignTestWithPkp(context, events) {
208+
export async function runPkpSignTestWithPkp(context: any, events: any) {
196209
await initializeSharedContext();
197210

198211
const parallelism = context.vars.parallelism || 5;
@@ -208,7 +221,7 @@ export async function runPkpSignTestWithPkp(context, events) {
208221
);
209222
}
210223

211-
export async function runPkpSignTestWithCustom(context, events) {
224+
export async function runPkpSignTestWithCustom(context: any, events: any) {
212225
await initializeSharedContext();
213226

214227
const parallelism = context.vars.parallelism || 5;
@@ -227,7 +240,7 @@ export async function runPkpSignTestWithCustom(context, events) {
227240
/**
228241
* Encrypt/Decrypt test functions
229242
*/
230-
export async function runEncryptDecryptTest(context, events) {
243+
export async function runEncryptDecryptTest(context: any, events: any) {
231244
await initializeSharedContext();
232245

233246
const parallelism = context.vars.parallelism || 3;
@@ -243,7 +256,7 @@ export async function runEncryptDecryptTest(context, events) {
243256
);
244257
}
245258

246-
export async function runPkpEncryptDecryptTest(context, events) {
259+
export async function runPkpEncryptDecryptTest(context: any, events: any) {
247260
await initializeSharedContext();
248261

249262
const parallelism = context.vars.parallelism || 3;
@@ -259,7 +272,7 @@ export async function runPkpEncryptDecryptTest(context, events) {
259272
);
260273
}
261274

262-
export async function runEncryptDecryptFlowTest(context, events) {
275+
export async function runEncryptDecryptFlowTest(context: any, events: any) {
263276
await initializeSharedContext();
264277

265278
const parallelism = context.vars.parallelism || 3;
@@ -278,7 +291,7 @@ export async function runEncryptDecryptFlowTest(context, events) {
278291
/**
279292
* Execute JS test function
280293
*/
281-
export async function runExecuteJsTest(context, events) {
294+
export async function runExecuteJsTest(context: any, events: any) {
282295
await initializeSharedContext();
283296

284297
const parallelism = context.vars.parallelism || 4;
@@ -291,7 +304,7 @@ export async function runExecuteJsTest(context, events) {
291304
/**
292305
* View PKPs test functions
293306
*/
294-
export async function runViewPkpsTest(context, events) {
307+
export async function runViewPkpsTest(context: any, events: any) {
295308
await initializeSharedContext();
296309

297310
const parallelism = context.vars.parallelism || 5;
@@ -325,7 +338,7 @@ export async function runViewPkpsTest(context, events) {
325338
/**
326339
* Viem integration test functions
327340
*/
328-
export async function runViemSignTest(context, events) {
341+
export async function runViemSignTest(context: any, events: any) {
329342
await initializeSharedContext();
330343

331344
const parallelism = context.vars.parallelism || 3;

e2e/src/init.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const init = async (
5050
const aliceViemAccountAuthData = await ViemAccountAuthenticator.authenticate(
5151
aliceViemAccount
5252
);
53-
53+
5454
const bobViemAccount = privateKeyToAccount(generatePrivateKey());
5555
const bobViemAccountAuthData = await ViemAccountAuthenticator.authenticate(
5656
bobViemAccount
@@ -167,7 +167,7 @@ export const init = async (
167167
},
168168
storageProvider: storagePlugins.localStorageNode({
169169
appName: 'my-app',
170-
networkName: 'naga-dev',
170+
networkName: _network,
171171
storagePath: './pkp-tokens',
172172
}),
173173
});
@@ -180,7 +180,7 @@ export const init = async (
180180
},
181181
storageProvider: storagePlugins.localStorageNode({
182182
appName: 'my-app',
183-
networkName: 'naga-dev',
183+
networkName: _network,
184184
storagePath: './pkp-tokens-bob',
185185
}),
186186
});
@@ -219,7 +219,7 @@ export const init = async (
219219
},
220220
storageProvider: storagePlugins.localStorageNode({
221221
appName: 'my-app',
222-
networkName: 'naga-dev',
222+
networkName: _network,
223223
storagePath: './pkp-tokens',
224224
}),
225225
});
@@ -232,7 +232,7 @@ export const init = async (
232232
},
233233
storageProvider: storagePlugins.localStorageNode({
234234
appName: 'my-app',
235-
networkName: 'naga-dev',
235+
networkName: _network,
236236
storagePath: './pkp-tokens-bob',
237237
}),
238238
});

packages/lit-client/src/lib/LitClient/createLitClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
} from '@lit-protocol/networks';
1717
import {
1818
AuthContextSchema2,
19+
AuthData,
1920
EncryptedVersion1Schema,
2021
HexPrefixedSchema,
2122
JsonSignCustomSessionKeyRequestForPkpReturnSchema,
@@ -50,8 +51,7 @@ import {
5051
MintWithCustomAuthRequest,
5152
MintWithCustomAuthSchema,
5253
} from './schemas/MintWithCustomAuthSchema';
53-
import { LitClient, NagaNetworkModule } from './type';
54-
import { NagaLitClient } from './types/NagaLitClient.type';
54+
import { NagaNetworkModule } from './type';
5555

5656
const _logger = getChildLogger({
5757
module: 'createLitClient',
@@ -84,7 +84,7 @@ export const createLitClient = async ({
8484
network,
8585
}: {
8686
network: SupportedNetworkModule;
87-
}): Promise<LitClient> => {
87+
}) => {
8888
switch (network.id) {
8989
// -- (v8) Naga Network Module
9090
case 'naga':
@@ -144,7 +144,7 @@ export const createLitClient = async ({
144144
*/
145145
export const _createNagaLitClient = async (
146146
networkModule: NagaNetworkModule
147-
): Promise<NagaLitClient> => {
147+
) => {
148148
const _stateManager = await networkModule.createStateManager<
149149
Awaited<ReturnType<typeof orchestrateHandshake>>,
150150
NagaNetworkModule
@@ -702,7 +702,7 @@ export const _createNagaLitClient = async (
702702
return response;
703703
}
704704

705-
const litClient: NagaLitClient = {
705+
const litClient = {
706706
// This function is likely be used by another module to get the current context, eg. auth manager
707707
// only adding what is required by other modules for now.
708708
// maybe you will need connectionInfo: _stateManager.getLatestConnectionInfo(),
@@ -832,7 +832,7 @@ export const _createNagaLitClient = async (
832832
authMethodType: number | bigint;
833833
authMethodId: string;
834834
accessToken?: string;
835-
};
835+
} | AuthData;
836836
pagination?: { limit?: number; offset?: number };
837837
storageProvider?: PKPStorageProvider;
838838
}) => {

packages/lit-client/src/lib/LitClient/type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { NagaLocalModule } from '@lit-protocol/networks';
33
import { NagaDevModule } from '@lit-protocol/networks';
44
import { NagaStagingModule } from '@lit-protocol/networks';
5-
import { NagaLitClient } from './types/NagaLitClient.type';
5+
// import { NagaLitClient } from './types/NagaLitClient.type';
66

77
/**
88
* ========== All Network Modules ==========
@@ -27,5 +27,5 @@ export type NagaNetworkModule =
2727
/**
2828
* Union type for all possible Lit clients
2929
*/
30-
export type LitClient = NagaLitClient;
30+
// export type LitClient = NagaLitClient;
3131
// | DatilLitClient;

0 commit comments

Comments
 (0)