Skip to content

Commit 965c117

Browse files
committed
refactor(auth, e2e):
- Update type definitions to replace deprecated PKPInfo with PKPData across auth and e2e packages. - Modify Jest configuration to match all spec files in e2e tests. - Add .e2e to .gitignore for better file management. - Enhance e2e package structure with new types and utility functions for improved clarity and maintainability.
1 parent 0a1d6fb commit 965c117

File tree

27 files changed

+249
-799
lines changed

27 files changed

+249
-799
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ lit-cache
9090
lit-auth-local
9191
artillery-state.json
9292
artillery-pkp-tokens
93-
lit-auth-artillery
93+
lit-auth-artillery
94+
alice-auth-manager-data
95+
96+
.plans
97+
.e2e

jest.e2e.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const localPackages = [
2121

2222
const config: Config = {
2323
testEnvironment: 'node',
24-
testMatch: ['<rootDir>/packages/e2e/src/e2e.spec.ts'],
24+
testMatch: ['<rootDir>/packages/e2e/src/**/*.spec.ts'],
2525

2626
// Use Babel for everything; simple and robust with TS + ESM
2727
transform: {

packages/auth/src/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ViemAccountAuthenticator } from './lib/authenticators/ViemAccountAuthen
1313
import { WalletClientAuthenticator } from './lib/authenticators/WalletClientAuthenticator';
1414
// import { GetAuthContext } from './lib/AuthManager/getAuthContext';
1515
import { localStorage, localStorageNode } from './lib/storage';
16-
import type { LitAuthStorageProvider, PKPInfo } from './lib/storage/types';
16+
import type { LitAuthStorageProvider } from './lib/storage/types';
1717
import type { LitAuthData } from './lib/types';
1818

1919
// -- exports
@@ -24,11 +24,6 @@ export { JsonSignSessionKeyRequestForPkpReturnSchema } from '@lit-protocol/schem
2424
*/
2525
export type { LitAuthStorageProvider };
2626

27-
/**
28-
* Type definition for PKP information used for caching
29-
*/
30-
export type { PKPInfo };
31-
3227
/**
3328
* Type definition for the structure of authentication data used within the Lit Auth client.
3429
*/

packages/auth/src/lib/storage/localStorage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { LitAuthStorageProvider, PKPInfo } from './types';
1+
import type { LitAuthStorageProvider } from './types';
22
import type { LitAuthData } from '../types';
33
import { getGlobal } from '@lit-protocol/constants';
4+
import { PKPData } from '@lit-protocol/schemas';
45

56
const LOCALSTORAGE_LIT_AUTH_PREFIX = 'lit-auth';
67
const LOCALSTORAGE_LIT_PKP_PREFIX = 'lit-pkp-tokens';
@@ -309,7 +310,7 @@ export function localStorage({
309310
async readPKPs({
310311
authMethodType,
311312
authMethodId,
312-
}): Promise<PKPInfo[] | null> {
313+
}): Promise<PKPData[] | null> {
313314
const cacheKey = buildPKPFullCacheKey({
314315
appName,
315316
networkName,

packages/auth/src/lib/storage/localStorageNode.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* // Use nodeStorage.write(...) and nodeStorage.read(...)
1515
*/
1616

17+
import { PKPData } from '@lit-protocol/schemas';
1718
import type { LitAuthData } from '../types';
18-
import type { LitAuthStorageProvider, PKPInfo } from './types';
19+
import type { LitAuthStorageProvider } from './types';
1920

2021
const LOCALSTORAGE_LIT_AUTH_PREFIX = 'lit-auth';
2122
const LOCALSTORAGE_LIT_PKP_PREFIX = 'lit-pkp-tokens';
@@ -223,7 +224,7 @@ export function localStorageNode({
223224
async readPKPs({
224225
authMethodType,
225226
authMethodId,
226-
}): Promise<PKPInfo[] | null> {
227+
}): Promise<PKPData[] | null> {
227228
console.warn('localStorageNode (stub): readPKPs called in browser.');
228229
return null;
229230
},
@@ -442,7 +443,7 @@ export function localStorageNode({
442443
async readPKPs({
443444
authMethodType,
444445
authMethodId,
445-
}): Promise<PKPInfo[] | null> {
446+
}): Promise<PKPData[] | null> {
446447
const store = await getMemoisedStorageInstance();
447448
const cacheKey = buildPKPFullCacheKey({
448449
appName,

packages/auth/src/lib/storage/types.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1+
import { PKPData } from '@lit-protocol/schemas';
12
import type { LitAuthData } from '../types';
23

3-
/**
4-
* @deprecated Use the PKPInfo type from @lit-protocol/types instead
5-
*/
6-
export interface PKPInfo {
7-
tokenId: string;
8-
publicKey: string;
9-
ethAddress: string;
10-
}
11-
124
export interface LitAuthStorageProvider {
135
config: unknown;
146

@@ -92,7 +84,7 @@ export interface LitAuthStorageProvider {
9284
writePKPs?(params: {
9385
authMethodType: number | bigint;
9486
authMethodId: string;
95-
pkps: PKPInfo[];
87+
pkps: PKPData[];
9688
}): Promise<void>;
9789

9890
/**
@@ -102,5 +94,5 @@ export interface LitAuthStorageProvider {
10294
readPKPs?(params: {
10395
authMethodType: number | bigint;
10496
authMethodId: string;
105-
}): Promise<PKPInfo[] | null>;
97+
}): Promise<PKPData[] | null>;
10698
}

packages/e2e/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"description": "Lit Protocol E2E testing package for running comprehensive integration tests",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
7+
"type": "module",
8+
"types": "dist/index.d.ts",
79
"exports": {
810
".": {
911
"import": "./dist/index.mjs",

packages/e2e/src/helper/auth-contexts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const createPkpAuthContext = async (
1010
try {
1111
const pkpAuthContext = await ctx.authManager.createPkpAuthContext({
1212
authData: ctx.aliceViemAccountAuthData,
13-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
13+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
1414
authConfig: {
1515
resources: [
1616
['pkp-signing', '*'],

packages/e2e/src/helper/pkp-utils.ts

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
/**
2-
* PKP Utilities
3-
*
4-
* This module provides utility functions for managing Programmable Key Pairs (PKPs)
5-
* in the Lit Protocol ecosystem. It handles the common pattern of checking for
6-
* existing PKPs and creating new ones when necessary.
7-
*
8-
* Usage:
9-
* import { getOrCreatePkp } from './helper/pkp-utils';
10-
* const pkp = await getOrCreatePkp(litClient, authData, account, storagePath, networkName);
11-
*/
12-
13-
import { storagePlugins } from '@lit-protocol/auth';
1+
import type { AuthData, PKPData } from '@lit-protocol/schemas';
2+
import type { PrivateKeyAccount } from 'viem/accounts';
3+
import { LitClientInstance } from '../types';
144

155
// Configuration constants
166
const PAGINATION_LIMIT = 5;
@@ -28,23 +18,16 @@ const PKP_SCOPES = ['sign-anything'];
2818
* @returns Promise<PKP> - The existing or newly created PKP
2919
*/
3020
export const getOrCreatePkp = async (
31-
litClient: any,
32-
authData: any,
33-
account: any,
34-
storagePath: string,
35-
networkName: string
36-
) => {
21+
litClient: LitClientInstance,
22+
authData: AuthData,
23+
account: PrivateKeyAccount
24+
): Promise<PKPData> => {
3725
// Check for existing PKPs
3826
const { pkps } = await litClient.viewPKPsByAuthData({
3927
authData,
4028
pagination: {
4129
limit: PAGINATION_LIMIT,
4230
},
43-
storageProvider: storagePlugins.localStorageNode({
44-
appName: APP_NAME,
45-
networkName,
46-
storagePath,
47-
}),
4831
});
4932

5033
// If PKP exists, return it
@@ -53,23 +36,22 @@ export const getOrCreatePkp = async (
5336
}
5437

5538
// Otherwise mint new PKP
56-
const mintResult = await litClient.mintWithAuth({
57-
authData,
58-
account,
59-
scopes: PKP_SCOPES,
60-
});
39+
try {
40+
await litClient.mintWithAuth({
41+
authData,
42+
account,
43+
scopes: PKP_SCOPES,
44+
});
45+
} catch (e) {
46+
throw new Error(`❌ Error minting PKP: ${e}`);
47+
}
6148

6249
// Query again to get the newly minted PKP in the expected format
6350
const { pkps: newPkps } = await litClient.viewPKPsByAuthData({
6451
authData,
6552
pagination: {
6653
limit: PAGINATION_LIMIT,
6754
},
68-
storageProvider: storagePlugins.localStorageNode({
69-
appName: APP_NAME,
70-
networkName,
71-
storagePath,
72-
}),
7355
});
7456

7557
return newPkps[0];

0 commit comments

Comments
 (0)