Skip to content

Commit 3de2767

Browse files
authored
Merge pull request #869 from LIT-Protocol/feature/jss-12-investigate-simple-currentactionipfsidacc-with-rebased-to-naga
refactor(accs): renamed .raw() function and added several new APIs
2 parents 6c254e0 + 2e8f526 commit 3de2767

File tree

3 files changed

+188
-6
lines changed

3 files changed

+188
-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: 82 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,88 @@ 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+
...p,
565+
};
566+
567+
this.setChain(p.chain as EvmChain);
568+
return this;
569+
}
570+
571+
evmContract(
572+
params: Omit<EvmContractAcc, 'conditionType'>
573+
): AccBuilder {
574+
const p = params as Partial<EvmContractAcc>;
575+
576+
// For raw evmContract, chain must be provided in params
577+
if (!p.chain) {
578+
throw new Error('Chain must be specified in params for evmContract method');
579+
}
580+
581+
this.pendingCondition = {
582+
conditionType: 'evmContract',
583+
...p,
584+
};
585+
586+
this.setChain(p.chain as EvmChain);
587+
return this;
588+
}
589+
590+
solRpc(
591+
params: Omit<SolAcc, 'conditionType'>
592+
): AccBuilder {
593+
const p = params as Partial<SolAcc>;
594+
595+
// For raw solRpc, chain must be provided in params
596+
if (!p.chain) {
597+
throw new Error('Chain must be specified in params for solRpc method');
598+
}
599+
600+
this.pendingCondition = {
601+
conditionType: 'solRpc',
602+
...p,
603+
};
604+
605+
this.setChain(p.chain as SolanaChain);
606+
return this;
607+
}
608+
609+
cosmos(
610+
params: Omit<AtomAcc, 'conditionType'>
611+
): AccBuilder {
612+
const p = params as Partial<AtomAcc>;
613+
614+
// For raw cosmos, chain must be provided in params
615+
if (!p.chain) {
616+
throw new Error('Chain must be specified in params for cosmos method');
617+
}
618+
619+
this.pendingCondition = {
620+
conditionType: 'cosmos',
621+
...p,
622+
};
623+
624+
this.setChain(p.chain as CosmosChain);
625+
return this;
626+
}
627+
549628
// ========== Boolean Operations ==========
550629

551630
and(): AccBuilder {
@@ -859,4 +938,4 @@ export const createLitActionCondition = (
859938
comparator: comparator as any,
860939
value: expectedValue,
861940
},
862-
});
941+
});

0 commit comments

Comments
 (0)