@@ -37,7 +37,7 @@ const ExecuteJsResultSchema = z.object({
3737 } )
3838 ) ,
3939 response : z . string ( ) ,
40- logs : z . string ( ) ,
40+ logs : z . string ( ) . optional ( ) ,
4141} ) ;
4242
4343// Global variables to cache expensive operations
@@ -243,7 +243,11 @@ export async function runEncryptDecryptTest() {
243243}
244244
245245// test '/web/execute/v2' endpoint
246- export async function runExecuteJSTest ( ) {
246+ export async function runExecuteJSTest ( context : any , _events : any ) {
247+ const variant = context . scenario . variables . variant ;
248+
249+ console . log ( '🔍 variant:' , variant ) ;
250+
247251 const startTime = Date . now ( ) ;
248252
249253 try {
@@ -256,32 +260,37 @@ export async function runExecuteJSTest() {
256260 // Create auth context
257261 const authContext = await createAuthContextFromState ( ) ;
258262
263+ // Set up access control conditions requiring wallet ownership
264+ const builder = createAccBuilder ( ) ;
265+ const accs = builder
266+ . requireWalletOwnership ( state . masterAccount . pkp . ethAddress )
267+ . on ( 'ethereum' )
268+ . build ( ) ;
269+
270+ let encryptedData : any ;
271+ if ( variant === 'decryptToSingleNodeWithoutAuthSig' ) {
272+ // Encrypt data with the access control conditions
273+ const dataToEncrypt = 'Hello from PKP encrypt-decrypt test!' ;
274+ encryptedData = await litClient . encrypt ( {
275+ dataToEncrypt,
276+ unifiedAccessControlConditions : accs ,
277+ chain : 'ethereum' ,
278+ } ) ;
279+ }
280+
259281 // Perform executeJs operation
260- const litActionCode = `
261- (async () => {
262- const { sigName, toSign, publicKey } = jsParams;
263- const { keccak256, arrayify } = ethers.utils;
264-
265- const toSignBytes = new TextEncoder().encode(toSign);
266- const toSignBytes32 = keccak256(toSignBytes);
267- const toSignBytes32Array = arrayify(toSignBytes32);
268-
269- const sigShare = await Lit.Actions.signEcdsa({
270- toSign: toSignBytes32Array,
271- publicKey,
272- sigName,
273- });
274- })();` ;
282+ const { litActionCode, jsParams } = getLitActionCodeAndJsParams (
283+ variant ,
284+ state ,
285+ encryptedData ,
286+ accs ,
287+ await authContext . authNeededCallback ( )
288+ ) ;
275289
276290 const result = await litClient . executeJs ( {
277291 code : litActionCode ,
278292 authContext,
279- jsParams : {
280- message : 'Test message from e2e executeJs' ,
281- sigName : 'e2e-test-sig' ,
282- toSign : 'Test message from e2e executeJs' ,
283- publicKey : state . masterAccount . pkp . pubkey ,
284- } ,
293+ jsParams,
285294 } ) ;
286295
287296 // Validate the result using Zod schema
@@ -355,3 +364,137 @@ export async function runSignSessionKeyTest() {
355364 throw error ;
356365 }
357366}
367+
368+ // String enum for the variant
369+ type Variant =
370+ | 'sign'
371+ | 'broadcastAndCollect'
372+ | 'checkConditionsWithoutAuthSig'
373+ | 'signChildLitAction'
374+ | 'decryptToSingleNode'
375+ | 'runOnce' ;
376+
377+ function getLitActionCodeAndJsParams (
378+ variant : Variant ,
379+ state : any ,
380+ encryptedData ?: any ,
381+ accs ?: any ,
382+ authSig ?: any
383+ ) : {
384+ litActionCode : string ;
385+ jsParams : any ;
386+ } {
387+ switch ( variant ) {
388+ case 'broadcastAndCollect' :
389+ return {
390+ litActionCode : `
391+ (async () => {
392+ const resp = await Lit.Actions.broadcastAndCollect({
393+ name: 'some-name',
394+ value: 'some-value',
395+ });
396+ Lit.Actions.setResponse({ response: JSON.stringify(resp) });
397+ })();` ,
398+ jsParams : undefined ,
399+ } ;
400+ case 'checkConditionsWithoutAuthSig' :
401+ return {
402+ litActionCode : `
403+ (async () => {
404+ const resp = await Lit.Actions.checkConditions({
405+ conditions: accessControlConditions,
406+ chain: 'ethereum',
407+ });
408+ Lit.Actions.setResponse({ response: JSON.stringify(resp.toString()) });
409+ })();` ,
410+ jsParams : {
411+ accessControlConditions :
412+ accs || state . masterAccount . pkp . accessControlConditions ,
413+ } ,
414+ } ;
415+ case 'signChildLitAction' :
416+ return {
417+ litActionCode : `
418+ (async () => {
419+ const { sigName, publicKey } = jsParams;
420+ let utf8Encode = new TextEncoder();
421+ const toSign = utf8Encode.encode('This message is exactly 32 bytes');
422+ const _ = await Lit.Actions.call({ ipfsId: 'QmRwN9GKHvCn4Vk7biqtr6adjXMs7PzzYPCzNCRjPFiDjm', params: {
423+ toSign: Array.from(toSign),
424+ publicKey,
425+ sigName
426+ }});
427+ })();` ,
428+ jsParams : {
429+ sigName : 'e2e-test-sig' ,
430+ publicKey : state . masterAccount . pkp . pubkey ,
431+ } ,
432+ } ;
433+ case 'decryptToSingleNode' :
434+ return {
435+ litActionCode : `
436+ (async () => {
437+ const { accessControlConditions, authSig, ciphertext, dataToEncryptHash } = jsParams;
438+ const resp = await Lit.Actions.decryptAndCombine({
439+ accessControlConditions,
440+ ciphertext,
441+ dataToEncryptHash,
442+ authSig,
443+ chain: 'ethereum',
444+ });
445+ Lit.Actions.setResponse({ response: JSON.stringify(resp) });
446+ })();` ,
447+ jsParams : {
448+ accessControlConditions :
449+ accs || state . masterAccount . pkp . accessControlConditions ,
450+ authSig,
451+ ciphertext : encryptedData ?. ciphertext ,
452+ dataToEncryptHash : encryptedData ?. dataToEncryptHash ,
453+ } ,
454+ } ;
455+ case 'runOnce' :
456+ return {
457+ litActionCode : `
458+ (async () => {
459+ let temp = await Lit.Actions.runOnce(
460+ { waitForResponse: false, name: 'weather' },
461+ async () => {
462+ const url = 'https://api.weather.gov/gridpoints/TOP/31,80/forecast';
463+ const resp = await fetch(url).then((response) => response.json());
464+ const temp = resp.properties.periods[0].temperature;
465+ return temp;
466+ }
467+ );
468+
469+ Lit.Actions.setResponse({ response: JSON.stringify(temp) });
470+ })();` ,
471+ jsParams : undefined ,
472+ } ;
473+ case 'sign' :
474+ return {
475+ litActionCode : `
476+ (async () => {
477+ const { sigName, toSign, publicKey } = jsParams;
478+ const { keccak256, arrayify } = ethers.utils;
479+
480+ const toSignBytes = new TextEncoder().encode(toSign);
481+ const toSignBytes32 = keccak256(toSignBytes);
482+ const toSignBytes32Array = arrayify(toSignBytes32);
483+
484+ const sigShare = await Lit.Actions.signEcdsa({
485+ toSign: toSignBytes32Array,
486+ publicKey,
487+ sigName,
488+ });
489+ })();` ,
490+ jsParams : {
491+ message : 'Test message from e2e executeJs' ,
492+ sigName : 'e2e-test-sig' ,
493+ toSign : 'Test message from e2e executeJs' ,
494+ publicKey : state . masterAccount . pkp . pubkey ,
495+ } ,
496+ } ;
497+ default :
498+ throw new Error ( `Unknown variant: ${ variant } ` ) ;
499+ }
500+ }
0 commit comments