From 4859fc8769508a288c28219dc06e241c9942161e Mon Sep 17 00:00:00 2001 From: Anson Date: Thu, 21 Aug 2025 17:00:33 +0100 Subject: [PATCH 1/2] feat(accs): - renamed `.raw` to `.unified` - added `.evmBasic`, `.cosmos`, and `solRpc` APIs --- e2e/src/v7-compatability.spec.ts | 103 ++++++++++++++++++ .../src/lib/createAccBuilder.spec.ts | 6 +- .../src/lib/createAccBuilder.ts | 76 ++++++++++++- 3 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 e2e/src/v7-compatability.spec.ts diff --git a/e2e/src/v7-compatability.spec.ts b/e2e/src/v7-compatability.spec.ts new file mode 100644 index 0000000000..fa99d30c42 --- /dev/null +++ b/e2e/src/v7-compatability.spec.ts @@ -0,0 +1,103 @@ +import { createAuthManager, storagePlugins, ViemAccountAuthenticator } from "@lit-protocol/auth"; +import { createLitClient } from "@lit-protocol/lit-client"; +import { nagaDev } from "@lit-protocol/networks"; +import { privateKeyToAccount } from "viem/accounts"; + + +describe('v7 compatability', () => { + it('should be able to use the v7 api', async () => { + + + const liveMasterAccount = privateKeyToAccount( + process.env['LIVE_MASTER_ACCOUNT'] as `0x${string}` + ); + + + const litClient = await createLitClient({ network: nagaDev }); + + const authManager = createAuthManager({ + storage: storagePlugins.localStorageNode({ + appName: 'v7-compatability', + networkName: 'naga-dev', + storagePath: './lit-auth-local', + }), + }); + + /** + * ==================================== + * Create the auth context + * ==================================== + */ + const aliceEoaAuthContext = await authManager.createEoaAuthContext({ + config: { + account: liveMasterAccount, + }, + authConfig: { + statement: 'I authorize the Lit Protocol to execute this Lit Action.', + domain: 'example.com', + resources: [ + ['lit-action-execution', '*'], + ['pkp-signing', '*'], + ['access-control-condition-decryption', '*'], + ], + capabilityAuthSigs: [], + expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(), + }, + litClient: litClient, + }); + + + + + const { createAccBuilder } = await import( + '@lit-protocol/access-control-conditions' + ); + + + const unifiedAccs = createAccBuilder().unifiedAccs({ + conditionType: 'evmBasic', + contractAddress: '', + standardContractType: '', + chain: 'ethereum', + method: '', + parameters: [':userAddress'], + returnValueTest: { + comparator: '=', + value: liveMasterAccount.address, + }, + }).build(); + + + const accs = createAccBuilder().evmBasic({ + contractAddress: '', + standardContractType: '', + chain: 'ethereum', + method: '', + parameters: [':userAddress'], + returnValueTest: { + comparator: '=', + value: liveMasterAccount.address, + }, + }).build(); + + + const stringData = 'Hello from encrypt-decrypt flow test!'; + const encryptedStringData = await litClient.encrypt({ + dataToEncrypt: stringData, + unifiedAccessControlConditions: unifiedAccs, + chain: 'ethereum', + }); + + + console.log(encryptedStringData); + + + const decryptedStringResponse = await litClient.decrypt({ + data: encryptedStringData, + unifiedAccessControlConditions: accs, + chain: 'ethereum', + authContext: aliceEoaAuthContext, + }); + console.log(decryptedStringResponse); + }); +}); \ No newline at end of file diff --git a/packages/access-control-conditions/src/lib/createAccBuilder.spec.ts b/packages/access-control-conditions/src/lib/createAccBuilder.spec.ts index e84bc55bf6..99b4d21973 100644 --- a/packages/access-control-conditions/src/lib/createAccBuilder.spec.ts +++ b/packages/access-control-conditions/src/lib/createAccBuilder.spec.ts @@ -455,7 +455,7 @@ describe('Access Control Conditions Builder', () => { }, }; - const conditions = createAccBuilder().raw(rawCondition).build(); + const conditions = createAccBuilder().unifiedAccs(rawCondition).build(); expect(conditions).toHaveLength(1); // Should be canonically formatted @@ -480,7 +480,7 @@ describe('Access Control Conditions Builder', () => { .requireEthBalance('1000000000000000000') .on('ethereum') .or() - .raw(customCondition) + .unifiedAccs(customCondition) .build(); expect(conditions).toHaveLength(3); @@ -852,4 +852,4 @@ describe('Access Control Conditions Builder', () => { expect(condition.parameters).toEqual(['param1', 'param2', 'param3']); }); }); -}); +}); \ No newline at end of file diff --git a/packages/access-control-conditions/src/lib/createAccBuilder.ts b/packages/access-control-conditions/src/lib/createAccBuilder.ts index 727bd4d32a..2e025e63cd 100644 --- a/packages/access-control-conditions/src/lib/createAccBuilder.ts +++ b/packages/access-control-conditions/src/lib/createAccBuilder.ts @@ -194,7 +194,10 @@ export interface AccBuilder { custom( condition: Partial ): AccBuilder; - raw(condition: UnifiedAccessControlCondition): AccBuilder; + unifiedAccs(condition: UnifiedAccessControlCondition): AccBuilder; + evmBasic(params: Omit): AccBuilder; + solRpc(params: Omit): AccBuilder; + cosmos(params: Omit): AccBuilder; // ========== Boolean Operations ========== and(): AccBuilder; @@ -540,12 +543,79 @@ class AccessControlConditionBuilder implements AccBuilder { return this; } - raw(condition: UnifiedAccessControlCondition): AccBuilder { + unifiedAccs(condition: UnifiedAccessControlCondition): AccBuilder { this.commitPendingCondition(); this.conditions.push(condition); return this; } + evmBasic( + params: Omit + ): AccBuilder { + const p = params as Partial; + + // For raw evmBasic, chain must be provided in params + if (!p.chain) { + throw new Error('Chain must be specified in params for evmBasic method'); + } + + this.pendingCondition = { + conditionType: 'evmBasic', + contractAddress: p.contractAddress as string, + standardContractType: p.standardContractType as StandardContractType, + method: p.method as string, + parameters: p.parameters as string[], + returnValueTest: p.returnValueTest as any, + } as Partial; + + this.setChain(p.chain as EvmChain); + return this; + } + + solRpc( + params: Omit + ): AccBuilder { + const p = params as Partial; + + // For raw solRpc, chain must be provided in params + if (!p.chain) { + throw new Error('Chain must be specified in params for solRpc method'); + } + + this.pendingCondition = { + conditionType: 'solRpc', + method: p.method as string, + params: p.params as string[], + pdaParams: p.pdaParams as string[], + pdaInterface: p.pdaInterface as any, + pdaKey: p.pdaKey as string, + returnValueTest: p.returnValueTest as any, + } as Partial; + + this.setChain(p.chain as SolanaChain); + return this; + } + + cosmos( + params: Omit + ): AccBuilder { + const p = params as Partial; + + // For raw cosmos, chain must be provided in params + if (!p.chain) { + throw new Error('Chain must be specified in params for cosmos method'); + } + + this.pendingCondition = { + conditionType: 'cosmos', + path: p.path as string, + returnValueTest: p.returnValueTest as any, + } as Partial; + + this.setChain(p.chain as CosmosChain); + return this; + } + // ========== Boolean Operations ========== and(): AccBuilder { @@ -859,4 +929,4 @@ export const createLitActionCondition = ( comparator: comparator as any, value: expectedValue, }, -}); +}); \ No newline at end of file From 2e8f526947531f537ed5e964eba1a4f4918a4b6c Mon Sep 17 00:00:00 2001 From: Anson Date: Thu, 21 Aug 2025 17:17:29 +0100 Subject: [PATCH 2/2] feat(accs): add `.evmContract` function and simply the APIs --- .../src/lib/createAccBuilder.ts | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/access-control-conditions/src/lib/createAccBuilder.ts b/packages/access-control-conditions/src/lib/createAccBuilder.ts index 2e025e63cd..894581eb1f 100644 --- a/packages/access-control-conditions/src/lib/createAccBuilder.ts +++ b/packages/access-control-conditions/src/lib/createAccBuilder.ts @@ -561,12 +561,27 @@ class AccessControlConditionBuilder implements AccBuilder { this.pendingCondition = { conditionType: 'evmBasic', - contractAddress: p.contractAddress as string, - standardContractType: p.standardContractType as StandardContractType, - method: p.method as string, - parameters: p.parameters as string[], - returnValueTest: p.returnValueTest as any, - } as Partial; + ...p, + }; + + this.setChain(p.chain as EvmChain); + return this; + } + + evmContract( + params: Omit + ): AccBuilder { + const p = params as Partial; + + // For raw evmContract, chain must be provided in params + if (!p.chain) { + throw new Error('Chain must be specified in params for evmContract method'); + } + + this.pendingCondition = { + conditionType: 'evmContract', + ...p, + }; this.setChain(p.chain as EvmChain); return this; @@ -584,13 +599,8 @@ class AccessControlConditionBuilder implements AccBuilder { this.pendingCondition = { conditionType: 'solRpc', - method: p.method as string, - params: p.params as string[], - pdaParams: p.pdaParams as string[], - pdaInterface: p.pdaInterface as any, - pdaKey: p.pdaKey as string, - returnValueTest: p.returnValueTest as any, - } as Partial; + ...p, + }; this.setChain(p.chain as SolanaChain); return this; @@ -608,9 +618,8 @@ class AccessControlConditionBuilder implements AccBuilder { this.pendingCondition = { conditionType: 'cosmos', - path: p.path as string, - returnValueTest: p.returnValueTest as any, - } as Partial; + ...p, + }; this.setChain(p.chain as CosmosChain); return this;