From 79fe914c9680d1a515854f7c3fe197e0c0faf5fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 17:00:16 +0000 Subject: [PATCH 1/4] Initial plan From 582bbc25771900c86d1ba8bbd7dd6d43ef620190 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 17:07:15 +0000 Subject: [PATCH 2/4] Add test for updateEncryptedKey with evmContractConditions Co-authored-by: Ansonhkg <4049673+Ansonhkg@users.noreply.github.com> --- .../src/test-helpers/executeJs/wrappedKeys.ts | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts b/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts index 5a8211c33..55a3af8ba 100644 --- a/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts +++ b/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts @@ -57,6 +57,21 @@ namespace TestHelper { export const randomHash = (input: string) => createHash('sha256').update(input).digest('hex'); + export const createEvmContractConditions = (address: string) => + JSON.stringify([ + { + contractAddress: '', + standardContractType: '', + chain: EVM_CHAIN, + method: '', + parameters: [':userAddress'], + returnValueTest: { + comparator: '=', + value: address, + }, + }, + ]); + export const createStorePayload = (memo = randomMemo('store')) => { const ciphertext = randomCiphertext(); return { @@ -391,6 +406,61 @@ export const registerWrappedKeysTests = () => { expect(fetched.versions?.[0].memo).toBe(initialPayload.memo); }); + test('updateEncryptedKey with evmContractConditions stores conditions in version history', async () => { + const pkpSessionSigs = await TestHelper.createPkpSessionSigs({ + testEnv, + alice, + delegationAuthSig: aliceDelegationAuthSig, + }); + + const initialPayload = TestHelper.createStorePayload( + TestHelper.randomMemo('update-evm-before') + ); + + const { id } = await wrappedKeysApi.storeEncryptedKey({ + pkpSessionSigs, + litClient: testEnv.litClient, + ...initialPayload, + }); + + const newCiphertext = TestHelper.randomCiphertext(); + const newMemo = TestHelper.randomMemo('update-evm-after'); + const evmContractConditions = TestHelper.createEvmContractConditions( + alice.pkp!.ethAddress + ); + + const updateResult = await wrappedKeysApi.updateEncryptedKey({ + pkpSessionSigs, + litClient: testEnv.litClient, + id, + ciphertext: newCiphertext, + memo: newMemo, + evmContractConditions, + }); + + expect(updateResult.id).toBe(id); + expect(updateResult.pkpAddress).toBe(alice.pkp!.ethAddress); + expect(updateResult.updatedAt).toBeTruthy(); + + const fetched = await wrappedKeysApi.getEncryptedKey({ + pkpSessionSigs, + litClient: testEnv.litClient, + id, + includeVersions: true, + }); + + expect(fetched.ciphertext).toBe(newCiphertext); + expect(fetched.memo).toBe(newMemo); + expect(fetched.updatedAt).toBeTruthy(); + expect(fetched.versions).toBeDefined(); + expect(fetched.versions?.length).toBe(1); + expect(fetched.versions?.[0].ciphertext).toBe( + initialPayload.ciphertext + ); + expect(fetched.versions?.[0].memo).toBe(initialPayload.memo); + expect(fetched.versions?.[0].evmContractConditions).toBeUndefined(); + }); + test('importPrivateKey persists an externally generated key', async () => { const pkpSessionSigs = await TestHelper.createPkpSessionSigs({ testEnv, From 7b182131f7e2b1ccd56e98c8eb266a223fab1514 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 17:09:00 +0000 Subject: [PATCH 3/4] Use realistic EVM contract conditions in test helper Co-authored-by: Ansonhkg <4049673+Ansonhkg@users.noreply.github.com> --- packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts b/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts index 55a3af8ba..bde8e9606 100644 --- a/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts +++ b/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts @@ -60,14 +60,14 @@ namespace TestHelper { export const createEvmContractConditions = (address: string) => JSON.stringify([ { - contractAddress: '', - standardContractType: '', + contractAddress: ZERO_ADDRESS, + standardContractType: 'ERC20', chain: EVM_CHAIN, - method: '', + method: 'balanceOf', parameters: [':userAddress'], returnValueTest: { - comparator: '=', - value: address, + comparator: '>=', + value: '0', }, }, ]); From be45d0f402c715c9780aa3abcaa86b4b9053532a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 17:10:49 +0000 Subject: [PATCH 4/4] Remove unused address parameter from createEvmContractConditions Co-authored-by: Ansonhkg <4049673+Ansonhkg@users.noreply.github.com> --- packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts b/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts index bde8e9606..eabfe70fd 100644 --- a/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts +++ b/packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts @@ -57,7 +57,7 @@ namespace TestHelper { export const randomHash = (input: string) => createHash('sha256').update(input).digest('hex'); - export const createEvmContractConditions = (address: string) => + export const createEvmContractConditions = () => JSON.stringify([ { contractAddress: ZERO_ADDRESS, @@ -425,9 +425,7 @@ export const registerWrappedKeysTests = () => { const newCiphertext = TestHelper.randomCiphertext(); const newMemo = TestHelper.randomMemo('update-evm-after'); - const evmContractConditions = TestHelper.createEvmContractConditions( - alice.pkp!.ethAddress - ); + const evmContractConditions = TestHelper.createEvmContractConditions(); const updateResult = await wrappedKeysApi.updateEncryptedKey({ pkpSessionSigs,