Skip to content

Commit 4859fc8

Browse files
committed
feat(accs):
- renamed `.raw` to `.unified` - added `.evmBasic`, `.cosmos`, and `solRpc` APIs
1 parent a090098 commit 4859fc8

File tree

3 files changed

+179
-6
lines changed

3 files changed

+179
-6
lines changed

e2e/src/v7-compatability.spec.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { createAuthManager, storagePlugins, ViemAccountAuthenticator } from "@lit-protocol/auth";
2+
import { createLitClient } from "@lit-protocol/lit-client";
3+
import { nagaDev } from "@lit-protocol/networks";
4+
import { privateKeyToAccount } from "viem/accounts";
5+
6+
7+
describe('v7 compatability', () => {
8+
it('should be able to use the v7 api', async () => {
9+
10+
11+
const liveMasterAccount = privateKeyToAccount(
12+
process.env['LIVE_MASTER_ACCOUNT'] as `0x${string}`
13+
);
14+
15+
16+
const litClient = await createLitClient({ network: nagaDev });
17+
18+
const authManager = createAuthManager({
19+
storage: storagePlugins.localStorageNode({
20+
appName: 'v7-compatability',
21+
networkName: 'naga-dev',
22+
storagePath: './lit-auth-local',
23+
}),
24+
});
25+
26+
/**
27+
* ====================================
28+
* Create the auth context
29+
* ====================================
30+
*/
31+
const aliceEoaAuthContext = await authManager.createEoaAuthContext({
32+
config: {
33+
account: liveMasterAccount,
34+
},
35+
authConfig: {
36+
statement: 'I authorize the Lit Protocol to execute this Lit Action.',
37+
domain: 'example.com',
38+
resources: [
39+
['lit-action-execution', '*'],
40+
['pkp-signing', '*'],
41+
['access-control-condition-decryption', '*'],
42+
],
43+
capabilityAuthSigs: [],
44+
expiration: new Date(Date.now() + 1000 * 60 * 15).toISOString(),
45+
},
46+
litClient: litClient,
47+
});
48+
49+
50+
51+
52+
const { createAccBuilder } = await import(
53+
'@lit-protocol/access-control-conditions'
54+
);
55+
56+
57+
const unifiedAccs = createAccBuilder().unifiedAccs({
58+
conditionType: 'evmBasic',
59+
contractAddress: '',
60+
standardContractType: '',
61+
chain: 'ethereum',
62+
method: '',
63+
parameters: [':userAddress'],
64+
returnValueTest: {
65+
comparator: '=',
66+
value: liveMasterAccount.address,
67+
},
68+
}).build();
69+
70+
71+
const accs = createAccBuilder().evmBasic({
72+
contractAddress: '',
73+
standardContractType: '',
74+
chain: 'ethereum',
75+
method: '',
76+
parameters: [':userAddress'],
77+
returnValueTest: {
78+
comparator: '=',
79+
value: liveMasterAccount.address,
80+
},
81+
}).build();
82+
83+
84+
const stringData = 'Hello from encrypt-decrypt flow test!';
85+
const encryptedStringData = await litClient.encrypt({
86+
dataToEncrypt: stringData,
87+
unifiedAccessControlConditions: unifiedAccs,
88+
chain: 'ethereum',
89+
});
90+
91+
92+
console.log(encryptedStringData);
93+
94+
95+
const decryptedStringResponse = await litClient.decrypt({
96+
data: encryptedStringData,
97+
unifiedAccessControlConditions: accs,
98+
chain: 'ethereum',
99+
authContext: aliceEoaAuthContext,
100+
});
101+
console.log(decryptedStringResponse);
102+
});
103+
});

packages/access-control-conditions/src/lib/createAccBuilder.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ describe('Access Control Conditions Builder', () => {
455455
},
456456
};
457457

458-
const conditions = createAccBuilder().raw(rawCondition).build();
458+
const conditions = createAccBuilder().unifiedAccs(rawCondition).build();
459459

460460
expect(conditions).toHaveLength(1);
461461
// Should be canonically formatted
@@ -480,7 +480,7 @@ describe('Access Control Conditions Builder', () => {
480480
.requireEthBalance('1000000000000000000')
481481
.on('ethereum')
482482
.or()
483-
.raw(customCondition)
483+
.unifiedAccs(customCondition)
484484
.build();
485485

486486
expect(conditions).toHaveLength(3);
@@ -852,4 +852,4 @@ describe('Access Control Conditions Builder', () => {
852852
expect(condition.parameters).toEqual(['param1', 'param2', 'param3']);
853853
});
854854
});
855-
});
855+
});

packages/access-control-conditions/src/lib/createAccBuilder.ts

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ export interface AccBuilder {
194194
custom(
195195
condition: Partial<AtomAcc | EvmBasicAcc | EvmContractAcc | SolAcc>
196196
): AccBuilder;
197-
raw(condition: UnifiedAccessControlCondition): AccBuilder;
197+
unifiedAccs(condition: UnifiedAccessControlCondition): AccBuilder;
198+
evmBasic(params: Omit<EvmBasicAcc, 'conditionType'>): AccBuilder;
199+
solRpc(params: Omit<SolAcc, 'conditionType'>): AccBuilder;
200+
cosmos(params: Omit<AtomAcc, 'conditionType'>): AccBuilder;
198201

199202
// ========== Boolean Operations ==========
200203
and(): AccBuilder;
@@ -540,12 +543,79 @@ class AccessControlConditionBuilder implements AccBuilder {
540543
return this;
541544
}
542545

543-
raw(condition: UnifiedAccessControlCondition): AccBuilder {
546+
unifiedAccs(condition: UnifiedAccessControlCondition): AccBuilder {
544547
this.commitPendingCondition();
545548
this.conditions.push(condition);
546549
return this;
547550
}
548551

552+
evmBasic(
553+
params: Omit<EvmBasicAcc, 'conditionType'>
554+
): AccBuilder {
555+
const p = params as Partial<EvmBasicAcc>;
556+
557+
// For raw evmBasic, chain must be provided in params
558+
if (!p.chain) {
559+
throw new Error('Chain must be specified in params for evmBasic method');
560+
}
561+
562+
this.pendingCondition = {
563+
conditionType: 'evmBasic',
564+
contractAddress: p.contractAddress as string,
565+
standardContractType: p.standardContractType as StandardContractType,
566+
method: p.method as string,
567+
parameters: p.parameters as string[],
568+
returnValueTest: p.returnValueTest as any,
569+
} as Partial<EvmBasicAcc>;
570+
571+
this.setChain(p.chain as EvmChain);
572+
return this;
573+
}
574+
575+
solRpc(
576+
params: Omit<SolAcc, 'conditionType'>
577+
): AccBuilder {
578+
const p = params as Partial<SolAcc>;
579+
580+
// For raw solRpc, chain must be provided in params
581+
if (!p.chain) {
582+
throw new Error('Chain must be specified in params for solRpc method');
583+
}
584+
585+
this.pendingCondition = {
586+
conditionType: 'solRpc',
587+
method: p.method as string,
588+
params: p.params as string[],
589+
pdaParams: p.pdaParams as string[],
590+
pdaInterface: p.pdaInterface as any,
591+
pdaKey: p.pdaKey as string,
592+
returnValueTest: p.returnValueTest as any,
593+
} as Partial<SolAcc>;
594+
595+
this.setChain(p.chain as SolanaChain);
596+
return this;
597+
}
598+
599+
cosmos(
600+
params: Omit<AtomAcc, 'conditionType'>
601+
): AccBuilder {
602+
const p = params as Partial<AtomAcc>;
603+
604+
// For raw cosmos, chain must be provided in params
605+
if (!p.chain) {
606+
throw new Error('Chain must be specified in params for cosmos method');
607+
}
608+
609+
this.pendingCondition = {
610+
conditionType: 'cosmos',
611+
path: p.path as string,
612+
returnValueTest: p.returnValueTest as any,
613+
} as Partial<AtomAcc>;
614+
615+
this.setChain(p.chain as CosmosChain);
616+
return this;
617+
}
618+
549619
// ========== Boolean Operations ==========
550620

551621
and(): AccBuilder {
@@ -859,4 +929,4 @@ export const createLitActionCondition = (
859929
comparator: comparator as any,
860930
value: expectedValue,
861931
},
862-
});
932+
});

0 commit comments

Comments
 (0)