@lit-protocol/e2e
Version:
Lit Protocol E2E testing package for running comprehensive integration tests
59 lines • 2.78 kB
JavaScript
import { createAuthManager, generateSessionKeyPair, storagePlugins, validateDelegationAuthSig, } from '@lit-protocol/auth';
import { createLitClient } from '@lit-protocol/lit-client';
export const createPregenDelegationServerReuseTest = (params) => {
return async () => {
const { authManager, authData, pkpPublicKey, clientLitClient, resolvedNetwork, } = params;
// 1. Generate session key pair and delegation auth sig
const sessionKeyPair = generateSessionKeyPair();
const delegationAuthSig = await authManager.generatePkpDelegationAuthSig({
pkpPublicKey,
authData,
sessionKeyPair,
authConfig: {
resources: [
['pkp-signing', '*'],
['lit-action-execution', '*'],
['access-control-condition-decryption', '*'],
],
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
},
litClient: clientLitClient,
});
// 2. Create envelope to send over the wire
const envelope = JSON.stringify({
pkpPublicKey,
payload: Buffer.from(JSON.stringify({ sessionKeyPair, delegationAuthSig }), 'utf8').toString('base64url'),
});
// 3. On server side, parse envelope and validate delegation auth sig
const parsedEnvelope = JSON.parse(envelope);
const decodedPayload = JSON.parse(Buffer.from(parsedEnvelope.payload, 'base64url').toString('utf8'));
validateDelegationAuthSig({
delegationAuthSig: decodedPayload.delegationAuthSig,
sessionKeyUri: decodedPayload.sessionKeyPair.publicKey,
});
const litClient = await createLitClient({
network: resolvedNetwork.networkModule,
});
const serverAuthManager = createAuthManager({
storage: storagePlugins.localStorageNode({
appName: 'e2e-server-reuse',
networkName: resolvedNetwork.name,
storagePath: './.e2e/server-reuse-storage',
}),
});
// 4. Recreate auth context on server side
const authContext = await serverAuthManager.createPkpAuthContextFromPreGenerated({
pkpPublicKey: parsedEnvelope.pkpPublicKey,
sessionKeyPair: decodedPayload.sessionKeyPair,
delegationAuthSig: decodedPayload.delegationAuthSig,
});
const result = await litClient.chain.ethereum.pkpSign({
authContext,
pubKey: parsedEnvelope.pkpPublicKey,
toSign: 'hello from server reuse',
});
console.log('result:', result);
expect(result).toBeTruthy();
};
};
//# sourceMappingURL=pregen-delegation.js.map