Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15203d4

Browse files
authored
Merge pull request #880 from LIT-Protocol/naga_add_hardcoded_keysets-3
⭐️ [BREAKING/Feature] Naga add hardcoded keysets 3
2 parents b722ecc + aec35a7 commit 15203d4

File tree

39 files changed

+21572
-153
lines changed

39 files changed

+21572
-153
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ 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

e2e/src/e2e.spec.ts

Lines changed: 158 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,29 @@ import {
1919
} from './helper/tests';
2020
import { init } from './init';
2121

22+
const RPC_OVERRIDE = process.env['LIT_YELLOWSTONE_PRIVATE_RPC_URL'];
23+
if (RPC_OVERRIDE) {
24+
console.log(
25+
'🧪 E2E: Using RPC override (LIT_YELLOWSTONE_PRIVATE_RPC_URL):',
26+
RPC_OVERRIDE
27+
);
28+
}
29+
2230
describe('all', () => {
2331
// Singleton baby
2432
let ctx: Awaited<ReturnType<typeof init>>;
2533

2634
// Auth contexts for testing
2735
let alicePkpAuthContext: any;
28-
let aliceCustomAuthContext: any;
36+
let eveCustomAuthContext: any;
2937

3038
beforeAll(async () => {
3139
try {
3240
ctx = await init();
3341

3442
// Create PKP and custom auth contexts using helper functions
3543
// alicePkpAuthContext = await createPkpAuthContext(ctx);
36-
aliceCustomAuthContext = await createCustomAuthContext(ctx);
44+
eveCustomAuthContext = await createCustomAuthContext(ctx);
3745
} catch (e) {
3846
console.error(e);
3947
process.exit(1);
@@ -124,34 +132,51 @@ describe('all', () => {
124132

125133
describe('endpoints', () => {
126134
it('pkpSign', () =>
127-
createPkpSignTest(ctx, () => aliceCustomAuthContext)());
135+
createPkpSignTest(
136+
ctx,
137+
() => eveCustomAuthContext,
138+
ctx.eveViemAccountPkp.pubkey
139+
)());
128140
it('executeJs', () =>
129-
createExecuteJsTest(ctx, () => aliceCustomAuthContext)());
130-
it('viewPKPsByAddress', () =>
131-
createViewPKPsByAddressTest(ctx, () => aliceCustomAuthContext)());
141+
createExecuteJsTest(
142+
ctx,
143+
() => eveCustomAuthContext,
144+
ctx.eveViemAccountPkp.pubkey
145+
)());
146+
it('viewPKPsByAddress', () => createViewPKPsByAddressTest(ctx)());
132147
it('viewPKPsByAuthData', () =>
133-
createViewPKPsByAuthDataTest(ctx, () => aliceCustomAuthContext)());
148+
createViewPKPsByAuthDataTest(ctx, ctx.eveCustomAuthData)());
134149
it('pkpEncryptDecrypt', () =>
135-
createPkpEncryptDecryptTest(ctx, () => aliceCustomAuthContext)());
150+
createPkpEncryptDecryptTest(
151+
ctx,
152+
() => eveCustomAuthContext,
153+
ctx.eveViemAccountPkp.ethAddress
154+
)());
136155
it('encryptDecryptFlow', () =>
137-
createEncryptDecryptFlowTest(ctx, () => aliceCustomAuthContext)());
138-
it('pkpPermissionsManagerFlow', () =>
139-
createPkpPermissionsManagerFlowTest(
156+
createEncryptDecryptFlowTest(
140157
ctx,
141-
() => aliceCustomAuthContext
158+
() => eveCustomAuthContext,
159+
ctx.eveViemAccountPkp.pubkey
142160
)());
143-
});
144161

145-
describe('integrations', () => {
146-
describe('pkp viem account', () => {
147-
it('sign message', () =>
148-
createViemSignMessageTest(ctx, () => aliceCustomAuthContext)());
149-
it('sign transaction', () =>
150-
createViemSignTransactionTest(ctx, () => aliceCustomAuthContext)());
151-
it('sign typed data', () =>
152-
createViemSignTypedDataTest(ctx, () => aliceCustomAuthContext)());
153-
});
162+
// Disable for now because it requires a different flow
163+
// it('pkpPermissionsManagerFlow', () =>
164+
// createPkpPermissionsManagerFlowTest(
165+
// ctx,
166+
// () => eveCustomAuthContext, ctx.eveViemAccountPkp.pubkey
167+
// )());
154168
});
169+
170+
// describe('integrations', () => {
171+
// describe('pkp viem account', () => {
172+
// it('sign message', () =>
173+
// createViemSignMessageTest(ctx, () => eveCustomAuthContext, ctx.eveViemAccountPkp.pubkey)());
174+
// it('sign transaction', () =>
175+
// createViemSignTransactionTest(ctx, () => eveCustomAuthContext, ctx.eveViemAccountPkp.pubkey)());
176+
// it('sign typed data', () =>
177+
// createViemSignTypedDataTest(ctx, () => eveCustomAuthContext, ctx.eveViemAccountPkp.pubkey)());
178+
// });
179+
// });
155180
});
156181

157182
describe('EOA Native', () => {
@@ -161,3 +186,114 @@ describe('all', () => {
161186
});
162187
});
163188
});
189+
190+
describe('rpc override', () => {
191+
const TEST_RPC = process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL;
192+
// const TEST_RPC = 'https://yellowstone-override.example';
193+
194+
// beforeAll(() => {
195+
// process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = TEST_RPC;
196+
// });
197+
198+
// afterAll(() => {
199+
// process.env.LIT_YELLOWSTONE_PRIVATE_RPC_URL = ORIGINAL_RPC;
200+
// });
201+
202+
it('applies env rpc override to module and client', async () => {
203+
const networks = await import('@lit-protocol/networks');
204+
205+
// choose module by NETWORK env (same way init.ts does)
206+
const network = process.env.NETWORK || 'naga-dev';
207+
const importNameMap: Record<string, string> = {
208+
'naga-dev': 'nagaDev',
209+
'naga-test': 'nagaTest',
210+
'naga-local': 'nagaLocal',
211+
'naga-staging': 'nagaStaging',
212+
};
213+
const importName = importNameMap[network];
214+
const baseModule: any = (networks as any)[importName];
215+
216+
// apply override
217+
const mod =
218+
typeof baseModule.withOverrides === 'function'
219+
? baseModule.withOverrides({ rpcUrl: TEST_RPC })
220+
: baseModule;
221+
222+
// log for verification
223+
// base vs effective (when override is supported)
224+
const baseRpcUrl =
225+
typeof baseModule.getRpcUrl === 'function'
226+
? baseModule.getRpcUrl()
227+
: 'n/a';
228+
const effRpcUrl =
229+
typeof mod.getRpcUrl === 'function' ? mod.getRpcUrl() : 'n/a';
230+
// eslint-disable-next-line no-console
231+
console.log('[rpc-override] TEST_RPC:', TEST_RPC);
232+
// eslint-disable-next-line no-console
233+
console.log(
234+
'[rpc-override] module rpc (base → effective):',
235+
baseRpcUrl,
236+
'→',
237+
effRpcUrl
238+
);
239+
try {
240+
const baseChain =
241+
typeof baseModule.getChainConfig === 'function'
242+
? baseModule.getChainConfig()
243+
: null;
244+
const effChain =
245+
typeof mod.getChainConfig === 'function' ? mod.getChainConfig() : null;
246+
if (baseChain && effChain) {
247+
// eslint-disable-next-line no-console
248+
console.log(
249+
'[rpc-override] module chain id/name (base → effective):',
250+
`${baseChain.id}/${baseChain.name}`,
251+
'→',
252+
`${effChain.id}/${effChain.name}`
253+
);
254+
// eslint-disable-next-line no-console
255+
console.log(
256+
'[rpc-override] module rpcUrls.default.http (base → effective):',
257+
baseChain.rpcUrls.default.http,
258+
'→',
259+
effChain.rpcUrls.default.http
260+
);
261+
// eslint-disable-next-line no-console
262+
console.log(
263+
'[rpc-override] module rpcUrls.public.http (base → effective):',
264+
(baseChain.rpcUrls as any)['public']?.http,
265+
'→',
266+
(effChain.rpcUrls as any)['public']?.http
267+
);
268+
}
269+
} catch {}
270+
271+
// module reflects override
272+
expect(mod.getRpcUrl()).toBe(TEST_RPC);
273+
const chain = mod.getChainConfig();
274+
expect(chain.rpcUrls.default.http[0]).toBe(TEST_RPC);
275+
expect((chain.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC);
276+
277+
// client reflects override
278+
const { createLitClient } = await import('@lit-protocol/lit-client');
279+
const client = await createLitClient({ network: mod });
280+
const cc = client.getChainConfig();
281+
282+
// eslint-disable-next-line no-console
283+
console.log('[rpc-override] client rpcUrl:', cc.rpcUrl);
284+
// eslint-disable-next-line no-console
285+
console.log(
286+
'[rpc-override] client viem rpcUrls.default:',
287+
cc.viemConfig.rpcUrls.default.http
288+
);
289+
// eslint-disable-next-line no-console
290+
console.log(
291+
'[rpc-override] client viem rpcUrls.public:',
292+
(cc.viemConfig.rpcUrls as any)['public']?.http
293+
);
294+
295+
expect(cc.rpcUrl).toBe(TEST_RPC);
296+
expect(cc.viemConfig.rpcUrls.default.http[0]).toBe(TEST_RPC);
297+
expect((cc.viemConfig.rpcUrls as any)['public'].http[0]).toBe(TEST_RPC);
298+
});
299+
});

e2e/src/helper/auth-contexts.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,12 @@ export const createCustomAuthContext = async (
3939
ctx: Awaited<ReturnType<typeof init>>
4040
) => {
4141
console.log('🔁 Creating Custom Auth Context');
42+
4243
try {
4344
// Set up custom auth method type and validation IPFS CID (from custom-auth-flow example)
44-
const uniqueDappName = 'e2e-test-dapp';
45-
const uniqueAuthMethodType = hexToBigInt(
46-
keccak256(toBytes(uniqueDappName))
47-
);
48-
const uniqueUserId = `${uniqueDappName}-alice`;
49-
const authMethodId = keccak256(toBytes(uniqueUserId));
50-
const validationIpfsCid = 'QmYLeVmwJPVs7Uebk85YdVPivMyrvoeKR6X37kyVRZUXW4';
5145

5246
const customAuthContext = await ctx.authManager.createCustomAuthContext({
53-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
47+
pkpPublicKey: ctx.eveViemAccountPkp.pubkey,
5448
authConfig: {
5549
resources: [
5650
['pkp-signing', '*'],
@@ -61,17 +55,17 @@ export const createCustomAuthContext = async (
6155
},
6256
litClient: ctx.litClient,
6357
customAuthParams: {
64-
litActionIpfsId: validationIpfsCid,
58+
litActionIpfsId: ctx.eveValidationIpfsCid,
6559
jsParams: {
66-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
67-
username: 'alice',
60+
pkpPublicKey: ctx.eveViemAccountPkp.pubkey,
61+
username: 'eve',
6862
password: 'lit',
69-
authMethodId: authMethodId,
63+
authMethodId: ctx.eveCustomAuthData.authMethodId,
7064
},
7165
},
7266
});
7367

74-
console.log('✅ Custom Auth Context created');
68+
console.log('✅ Custom Auth Context created', customAuthContext);
7569
return customAuthContext;
7670
} catch (e) {
7771
console.error('❌ Error creating Custom Auth Context', e);

e2e/src/helper/tests/encrypt-decrypt-flow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { assert } from '../assertions';
33

44
export const createEncryptDecryptFlowTest = (
55
ctx: Awaited<ReturnType<typeof init>>,
6-
getAuthContext: () => any
6+
getAuthContext: () => any,
7+
address?: string
78
) => {
89
return async () => {
910
const { createAccBuilder } = await import(
@@ -17,7 +18,7 @@ export const createEncryptDecryptFlowTest = (
1718
if (authContext === ctx.aliceEoaAuthContext) {
1819
aliceAddress = ctx.aliceViemAccount.address;
1920
} else {
20-
aliceAddress = ctx.aliceViemAccountPkp.ethAddress;
21+
aliceAddress = address || ctx.aliceViemAccountPkp.ethAddress;
2122
}
2223

2324
// Set up access control conditions requiring Bob's wallet ownership

e2e/src/helper/tests/execute-js.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { assert } from '../assertions';
33

44
export const createExecuteJsTest = (
55
ctx: Awaited<ReturnType<typeof init>>,
6-
getAuthContext: () => any
6+
getAuthContext: () => any,
7+
pubkey?: string
78
) => {
89
return async () => {
910
const litActionCode = `
@@ -29,7 +30,7 @@ export const createExecuteJsTest = (
2930
message: 'Test message from e2e executeJs',
3031
sigName: 'e2e-test-sig',
3132
toSign: 'Test message from e2e executeJs',
32-
publicKey: ctx.aliceViemAccountPkp.publicKey,
33+
publicKey: pubkey || ctx.aliceViemAccountPkp.publicKey,
3334
},
3435
});
3536

e2e/src/helper/tests/pkp-encrypt-decrypt.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { assert } from '../assertions';
33

44
export const createPkpEncryptDecryptTest = (
55
ctx: Awaited<ReturnType<typeof init>>,
6-
getAuthContext: () => any
6+
getAuthContext: () => any,
7+
address?: string
78
) => {
89
return async () => {
910
const { createAccBuilder } = await import(
@@ -19,7 +20,7 @@ export const createPkpEncryptDecryptTest = (
1920
addressToUse = ctx.aliceViemAccount.address;
2021
} else {
2122
// PKP or Custom auth contexts
22-
addressToUse = ctx.aliceViemAccountPkp.ethAddress;
23+
addressToUse = address || ctx.aliceViemAccountPkp.ethAddress;
2324
}
2425

2526
// Set up access control conditions requiring wallet ownership

e2e/src/helper/tests/pkp-sign.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { assert } from '../assertions';
33

44
export const createPkpSignTest = (
55
ctx: Awaited<ReturnType<typeof init>>,
6-
getAuthContext: () => any
6+
getAuthContext: () => any,
7+
pubkey?: string
78
) => {
89
return async () => {
910
const res = await ctx.litClient.chain.ethereum.pkpSign({
1011
authContext: getAuthContext(),
11-
pubKey: ctx.aliceViemAccountPkp.publicKey,
12+
pubKey: pubkey || ctx.aliceViemAccountPkp.publicKey,
1213
toSign: 'Hello, world!',
1314
});
1415

e2e/src/helper/tests/view-pkps-by-address.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { init } from '../../init';
22
import { assert } from '../assertions';
33

44
export const createViewPKPsByAddressTest = (
5-
ctx: Awaited<ReturnType<typeof init>>,
6-
getAuthContext: () => any
5+
ctx: Awaited<ReturnType<typeof init>>
76
) => {
87
return async () => {
98
const pkps = await ctx.litClient.viewPKPsByAddress({

e2e/src/helper/tests/view-pkps-by-auth-data.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import { assert } from '../assertions';
33

44
export const createViewPKPsByAuthDataTest = (
55
ctx: Awaited<ReturnType<typeof init>>,
6-
getAuthContext: () => any
6+
authData?: any
77
) => {
88
return async () => {
99
const { ViemAccountAuthenticator } = await import('@lit-protocol/auth');
10-
const authData = await ViemAccountAuthenticator.authenticate(
11-
ctx.aliceViemAccount
12-
);
10+
const _authData =
11+
authData ||
12+
(await ViemAccountAuthenticator.authenticate(ctx.aliceViemAccount));
1313

1414
const pkps = await ctx.litClient.viewPKPsByAuthData({
1515
authData: {
16-
authMethodType: authData.authMethodType,
17-
authMethodId: authData.authMethodId,
16+
authMethodType: _authData.authMethodType,
17+
authMethodId: _authData.authMethodId,
1818
},
1919
pagination: {
2020
limit: 10,

0 commit comments

Comments
 (0)