Skip to content

Commit eb2138f

Browse files
committed
feat(ci): add test to ci
1 parent dd2bac9 commit eb2138f

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

packages/e2e/src/e2e.spec.ts

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import {
2020
} from './helper/tests';
2121
import { init } from './init';
2222
import { AuthContext } from './types';
23+
import {
24+
createAuthManager,
25+
storagePlugins,
26+
validateDelegationAuthSig,
27+
generateSessionKeyPair,
28+
} from '@lit-protocol/auth';
29+
import { createLitClient } from '@lit-protocol/lit-client';
30+
import { nagaDev } from '@lit-protocol/networks';
2331

2432
const RPC_OVERRIDE = process.env['LIT_YELLOWSTONE_PRIVATE_RPC_URL'];
2533
if (RPC_OVERRIDE) {
@@ -201,7 +209,7 @@ describe('all', () => {
201209
it('should reject when only sessionKeyPair is provided', async () => {
202210
const tempAuthContext = await ctx.authManager.createPkpAuthContext({
203211
authData: ctx.aliceViemAccountAuthData,
204-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
212+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
205213
authConfig: {
206214
resources: [['pkp-signing', '*']],
207215
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
@@ -214,7 +222,7 @@ describe('all', () => {
214222
await expect(
215223
ctx.authManager.createPkpAuthContext({
216224
authData: ctx.aliceViemAccountAuthData,
217-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
225+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
218226
authConfig: {
219227
resources: [['pkp-signing', '*']],
220228
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
@@ -231,7 +239,7 @@ describe('all', () => {
231239
it('should reject when only delegationAuthSig is provided', async () => {
232240
const tempAuthContext = await ctx.authManager.createPkpAuthContext({
233241
authData: ctx.aliceViemAccountAuthData,
234-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
242+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
235243
authConfig: {
236244
resources: [['pkp-signing', '*']],
237245
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
@@ -244,7 +252,7 @@ describe('all', () => {
244252
await expect(
245253
ctx.authManager.createPkpAuthContext({
246254
authData: ctx.aliceViemAccountAuthData,
247-
pkpPublicKey: ctx.aliceViemAccountPkp.publicKey,
255+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
248256
authConfig: {
249257
resources: [['pkp-signing', '*']],
250258
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
@@ -258,6 +266,70 @@ describe('all', () => {
258266
);
259267
});
260268
});
269+
270+
describe('server reuse flow', () => {
271+
it('should sign using materials shipped over the wire', async () => {
272+
const sessionKeyPair = generateSessionKeyPair();
273+
const delegationAuthSig =
274+
await ctx.authManager.generatePkpDelegationAuthSig({
275+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
276+
authData: ctx.aliceViemAccountAuthData,
277+
sessionKeyPair,
278+
authConfig: {
279+
resources: [
280+
['pkp-signing', '*'],
281+
['lit-action-execution', '*'],
282+
['access-control-condition-decryption', '*'],
283+
],
284+
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
285+
},
286+
litClient: ctx.litClient,
287+
});
288+
289+
const wirePayload = JSON.stringify({
290+
sessionKeyPair,
291+
delegationAuthSig,
292+
});
293+
294+
const {
295+
sessionKeyPair: receivedSessionKeyPair,
296+
delegationAuthSig: receivedDelegation,
297+
} = JSON.parse(wirePayload) as {
298+
sessionKeyPair: typeof sessionKeyPair;
299+
delegationAuthSig: typeof delegationAuthSig;
300+
};
301+
302+
validateDelegationAuthSig({
303+
delegationAuthSig: receivedDelegation,
304+
sessionKeyUri: receivedSessionKeyPair.publicKey,
305+
});
306+
307+
const serverAuthManager = createAuthManager({
308+
storage: storagePlugins.localStorageNode({
309+
appName: 'e2e-server-reuse',
310+
networkName: 'naga-dev',
311+
storagePath: './.e2e/server-reuse-storage',
312+
}),
313+
});
314+
315+
const authContext =
316+
await serverAuthManager.createPkpAuthContextFromPreGenerated({
317+
pkpPublicKey: ctx.aliceViemAccountPkp.pubkey,
318+
sessionKeyPair: receivedSessionKeyPair,
319+
delegationAuthSig: receivedDelegation,
320+
});
321+
322+
const litClient = await createLitClient({ network: nagaDev });
323+
324+
const result = await litClient.chain.ethereum.pkpSign({
325+
authContext,
326+
pubKey: ctx.aliceViemAccountPkp.pubkey,
327+
toSign: 'hello from server reuse',
328+
});
329+
330+
expect(result).toBeTruthy();
331+
});
332+
});
261333
});
262334

263335
describe('EOA Native', () => {

0 commit comments

Comments
 (0)