@lit-protocol/e2e
Version:
Lit Protocol E2E testing package for running comprehensive integration tests
43 lines • 1.9 kB
JavaScript
import { createAccBuilder } from '@lit-protocol/access-control-conditions';
export const createPkpEncryptDecryptTest = (ctx, getAuthContext, address) => {
return async () => {
const authContext = getAuthContext();
// Determine which address to use based on auth context type
// For EOA auth, use the EOA address; for PKP/Custom auth, use the PKP address
let addressToUse;
if (authContext === ctx.aliceEoaAuthContext) {
addressToUse = ctx.aliceViemAccount.address;
}
else {
// PKP or Custom auth contexts
addressToUse = address || ctx.aliceViemAccountPkp.ethAddress;
}
// Set up access control conditions requiring wallet ownership
const builder = createAccBuilder();
const accs = builder
.requireWalletOwnership(addressToUse)
.on('ethereum')
.build();
// Encrypt data with the access control conditions
const dataToEncrypt = 'Hello from PKP encrypt-decrypt test!';
const encryptedData = await ctx.litClient.encrypt({
dataToEncrypt,
unifiedAccessControlConditions: accs,
chain: 'ethereum',
});
expect(encryptedData).toBeDefined();
expect(encryptedData.ciphertext).toBeDefined();
expect(encryptedData.dataToEncryptHash).toBeDefined();
// Decrypt the data using the appropriate auth context
const decryptedData = await ctx.litClient.decrypt({
data: encryptedData,
unifiedAccessControlConditions: accs,
chain: 'ethereum',
authContext: authContext,
});
expect(decryptedData).toBeDefined();
expect(decryptedData.convertedData).toBeDefined();
expect(decryptedData.convertedData).toBe(dataToEncrypt);
};
};
//# sourceMappingURL=pkp-encrypt-decrypt.js.map