@@ -35,6 +35,7 @@ import {
3535 IexecAccounts ,
3636 PocoMode ,
3737 buildAndSignContributionAuthorizationMessage ,
38+ buildAndSignPocoClassicEnclaveMessage ,
3839 buildResultHashAndResultSeal ,
3940 getDealId ,
4041 getTaskId ,
@@ -345,7 +346,7 @@ export class IexecWrapper {
345346 /**
346347 * Helper function to contribute to a task. The contributor's stake is
347348 * automatically deposited before contributing.
348- * Note: no enclave address is used.
349+ * Note: no enclave is used.
349350 * @param contributor Signer to sign the contribution
350351 * @param dealId id of the deal
351352 * @param taskIndex index of the task.
@@ -358,8 +359,60 @@ export class IexecWrapper {
358359 resultDigest : string ,
359360 contributor : SignerWithAddress ,
360361 ) {
361- const enclaveAddress = AddressZero ;
362- const enclaveSignature = '0x' ;
362+ const { taskId, workerStakePerTask } = await this . _contributeToTask (
363+ dealId ,
364+ taskIndex ,
365+ resultDigest ,
366+ contributor ,
367+ false , // No enclave used
368+ ) ;
369+ return { taskId, workerStakePerTask } ;
370+ }
371+
372+ /**
373+ * Helper function to contribute to a task using a secure enclave. The contributor's stake is
374+ * automatically deposited before contributing.
375+ * This function is used for enclave-based contributions (involving a secure enclave address).
376+ * @param contributor Signer to sign the contribution
377+ * @param dealId id of the deal
378+ * @param taskIndex index of the task.
379+ * @param resultDigest hash of the result
380+ * @returns id of the task
381+ */
382+ async contributeTeeToTask (
383+ dealId : string ,
384+ taskIndex : number ,
385+ resultDigest : string ,
386+ contributor : SignerWithAddress ,
387+ ) {
388+ const { taskId, workerStakePerTask } = await this . _contributeToTask (
389+ dealId ,
390+ taskIndex ,
391+ resultDigest ,
392+ contributor ,
393+ true ,
394+ ) ;
395+ return { taskId, workerStakePerTask } ;
396+ }
397+
398+ /**
399+ * Internal helper function to handle task contributions with optional enclave support.
400+ * Automatically deposits the contributor's stake before contributing and handles
401+ * enclave-related signing and validation if required.
402+ * @param contributor Signer to sign the contribution
403+ * @param dealId id of the deal
404+ * @param taskIndex index of the task.
405+ * @param resultDigest hash of the result
406+ * @param useEnclave - Boolean flag indicating whether an enclave is used for this contribution.
407+ * @returns id of the task
408+ */
409+ async _contributeToTask (
410+ dealId : string ,
411+ taskIndex : number ,
412+ resultDigest : string ,
413+ contributor : SignerWithAddress ,
414+ useEnclave : Boolean ,
415+ ) {
363416 const taskId = getTaskId ( dealId , taskIndex ) ;
364417 const workerStakePerTask = await IexecAccessors__factory . connect (
365418 this . proxyAddress ,
@@ -372,6 +425,14 @@ export class IexecWrapper {
372425 resultDigest ,
373426 contributor ,
374427 ) ;
428+ const enclaveAddress = useEnclave ? this . accounts . enclave . address : AddressZero ;
429+ const enclaveSignature = useEnclave
430+ ? await buildAndSignPocoClassicEnclaveMessage (
431+ resultHash ,
432+ resultSeal ,
433+ this . accounts . enclave ,
434+ )
435+ : '0x' ;
375436 const schedulerSignature = await buildAndSignContributionAuthorizationMessage (
376437 contributor . address ,
377438 taskId ,
0 commit comments