@@ -43,7 +43,9 @@ import { isAddressInWhitelist } from './smartContract/whitelistContract.read.js'
4343
4444export type ProcessProtectedData = typeof processProtectedData ;
4545
46- export const processProtectedData = async ( {
46+ export const processProtectedData = async <
47+ Params extends ProcessProtectedDataParams
48+ > ( {
4749 iexec = throwIfMissing ( ) ,
4850 defaultWorkerpool,
4951 protectedData,
@@ -61,10 +63,11 @@ export const processProtectedData = async ({
6163 voucherOwner,
6264 encryptResult = false ,
6365 pemPrivateKey,
66+ waitForResult = true ,
6467 onStatusUpdate = ( ) => { } ,
65- } : IExecConsumer &
66- DefaultWorkerpoolConsumer &
67- ProcessProtectedDataParams ) : Promise < ProcessProtectedDataResponse > => {
68+ } : IExecConsumer & DefaultWorkerpoolConsumer & Params ) : Promise <
69+ ProcessProtectedDataResponse < Params >
70+ > => {
6871 const vProtectedData = addressOrEnsSchema ( )
6972 . required ( )
7073 . label ( 'protectedData' )
@@ -107,6 +110,9 @@ export const processProtectedData = async ({
107110 const vPemPrivateKey = stringSchema ( )
108111 . label ( 'pemPrivateKey' )
109112 . validateSync ( pemPrivateKey ) ;
113+ const vWaitForResult = booleanSchema ( )
114+ . label ( 'waitForResult' )
115+ . validateSync ( waitForResult ) ;
110116
111117 // Validate that if pemPrivateKey is provided, encryptResult must be true
112118 if ( vPemPrivateKey && ! vEncryptResult ) {
@@ -282,37 +288,39 @@ export const processProtectedData = async ({
282288 isDone : true ,
283289 } ) ;
284290
285- vOnStatusUpdate ( {
286- title : 'GENERATE_ENCRYPTION_KEY' ,
287- isDone : false ,
288- } ) ;
289-
290291 // Handle result encryption
291292 let privateKey : string | undefined ;
292293 if ( vEncryptResult ) {
294+ if ( ! vPemPrivateKey ) {
295+ vOnStatusUpdate ( {
296+ title : 'GENERATE_ENCRYPTION_KEY' ,
297+ isDone : false ,
298+ } ) ;
299+ }
293300 const { publicKey, privateKey : generatedPrivateKey } =
294301 await getFormattedKeyPair ( {
295302 pemPrivateKey : vPemPrivateKey ,
296303 } ) ;
297304 privateKey = generatedPrivateKey ;
298-
299305 // Notify user if a new key was generated
300306 if ( ! vPemPrivateKey ) {
301307 vOnStatusUpdate ( {
302308 title : 'GENERATE_ENCRYPTION_KEY' ,
303309 isDone : true ,
304310 payload : {
305- message : 'New encryption key pair generated' ,
306311 pemPrivateKey : generatedPrivateKey ,
307312 } ,
308313 } ) ;
309- } else {
310- vOnStatusUpdate ( {
311- title : 'PUSH_ENCRYPTION_KEY' ,
312- isDone : false ,
313- } ) ;
314314 }
315315
316+ vOnStatusUpdate ( {
317+ title : 'PUSH_ENCRYPTION_KEY' ,
318+ isDone : false ,
319+ payload : {
320+ publicKey,
321+ } ,
322+ } ) ;
323+
316324 await iexec . result . pushResultEncryptionKey ( publicKey , {
317325 forceUpdate : true ,
318326 } ) ;
@@ -375,6 +383,15 @@ export const processProtectedData = async ({
375383 } ,
376384 } ) ;
377385
386+ if ( vWaitForResult === false ) {
387+ return {
388+ txHash : txHash ,
389+ dealId : dealid ,
390+ taskId,
391+ ...( privateKey ? { pemPrivateKey : privateKey } : { } ) ,
392+ } as ProcessProtectedDataResponse < Params > ;
393+ }
394+
378395 vOnStatusUpdate ( {
379396 title : 'CONSUME_TASK' ,
380397 isDone : false ,
@@ -415,7 +432,7 @@ export const processProtectedData = async ({
415432 taskId,
416433 result,
417434 ...( privateKey ? { pemPrivateKey : privateKey } : { } ) ,
418- } ;
435+ } as ProcessProtectedDataResponse < Params > ;
419436 } catch ( error ) {
420437 console . error ( '[processProtectedData] ERROR' , error ) ;
421438 handleIfProtocolError ( error ) ;
0 commit comments