diff --git a/e2e/src/v7-compatability.spec.ts b/e2e/src/v7-compatability.spec.ts new file mode 100644 index 000000000..fa99d30c4 --- /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 e84bc55bf..99b4d2197 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 727bd4d32..894581eb1 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,88 @@ 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', + ...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; + } + + 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', + ...p, + }; + + 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', + ...p, + }; + + this.setChain(p.chain as CosmosChain); + return this; + } + // ========== Boolean Operations ========== and(): AccBuilder { @@ -859,4 +938,4 @@ export const createLitActionCondition = ( comparator: comparator as any, value: expectedValue, }, -}); +}); \ No newline at end of file