UNPKG

@iexec/dataprotector

Version:

This product enables users to confidentially store data–such as mail address, documents, personal information ...

158 lines (144 loc) 4.73 kB
import { isValidProvider } from '../../utils/validators.js'; import { IExecDataProtectorModule } from '../IExecDataProtectorModule.js'; import { GetGrantedAccessParams, GetProtectedDataParams, GrantAccessParams, GrantedAccess, GrantedAccessResponse, ProcessProtectedDataParams, ProcessProtectedDataResponse, ProcessBulkRequestParams, ProcessBulkRequestResponse, ProtectDataParams, ProtectedData, GetResultFromCompletedTaskParams, GetResultFromCompletedTaskResponse, ProtectedDataWithSecretProps, RevokeAllAccessParams, RevokedAccess, TransferParams, TransferResponse, WaitForTaskCompletionResponse, WaitForTaskCompletionParams, PrepareBulkRequestParams, PrepareBulkRequestResponse, } from '../types/index.js'; import { getGrantedAccess } from './getGrantedAccess.js'; import { getProtectedData } from './getProtectedData.js'; import { getResultFromCompletedTask } from './getResultFromCompletedTask.js'; import { grantAccess } from './grantAccess.js'; import { prepareBulkRequest } from './prepareBulkRequest.js'; import { processBulkRequest } from './processBulkRequest.js'; import { processProtectedData } from './processProtectedData.js'; import { protectData } from './protectData.js'; import { revokeAllAccess } from './revokeAllAccess.js'; import { revokeOneAccess } from './revokeOneAccess.js'; import { transferOwnership } from './transferOwnership.js'; import { waitForTaskCompletion } from './waitForTaskCompletion.js'; class IExecDataProtectorCore extends IExecDataProtectorModule { async protectData( args: ProtectDataParams ): Promise<ProtectedDataWithSecretProps> { await this.init(); await isValidProvider(this.iexec); return protectData({ ...args, dataprotectorContractAddress: this.dataprotectorContractAddress, ipfsNode: this.ipfsNode, ipfsGateway: this.ipfsGateway, arweaveUploadApi: this.arweaveUploadApi, iexec: this.iexec, }); } async grantAccess(args: GrantAccessParams): Promise<GrantedAccess> { await this.init(); await isValidProvider(this.iexec); return grantAccess({ ...args, iexec: this.iexec }); } async revokeOneAccess(args: GrantedAccess): Promise<RevokedAccess> { await this.init(); await isValidProvider(this.iexec); return revokeOneAccess({ ...args, iexec: this.iexec }); } async revokeAllAccess(args: RevokeAllAccessParams): Promise<RevokedAccess[]> { await this.init(); await isValidProvider(this.iexec); return revokeAllAccess({ ...args, iexec: this.iexec }); } async transferOwnership(args: TransferParams): Promise<TransferResponse> { await this.init(); await isValidProvider(this.iexec); return transferOwnership({ ...args, iexec: this.iexec }); } async processProtectedData<Params extends ProcessProtectedDataParams>( args: Params ): Promise<ProcessProtectedDataResponse<Params>> { await this.init(); await isValidProvider(this.iexec); return processProtectedData({ ...args, iexec: this.iexec, defaultWorkerpool: this.defaultWorkerpool, }); } async prepareBulkRequest( args: PrepareBulkRequestParams ): Promise<PrepareBulkRequestResponse> { await this.init(); await isValidProvider(this.iexec); return prepareBulkRequest({ ...args, iexec: this.iexec, }); } async processBulkRequest<Params extends ProcessBulkRequestParams>( args: Params ): Promise<ProcessBulkRequestResponse<Params>> { await this.init(); await isValidProvider(this.iexec); return processBulkRequest({ ...args, iexec: this.iexec, defaultWorkerpool: this.defaultWorkerpool, }); } // ----- READ METHODS ----- async getProtectedData( args?: GetProtectedDataParams ): Promise<ProtectedData[]> { await this.init(); return getProtectedData({ ...args, iexec: this.iexec, graphQLClient: this.graphQLClient, }); } async getGrantedAccess( args: GetGrantedAccessParams ): Promise<GrantedAccessResponse> { await this.init(); return getGrantedAccess({ ...args, iexec: this.iexec }); } async waitForTaskCompletion( args: WaitForTaskCompletionParams ): Promise<WaitForTaskCompletionResponse> { await this.init(); await isValidProvider(this.iexec); return waitForTaskCompletion({ ...args, iexec: this.iexec, }); } async getResultFromCompletedTask( args: GetResultFromCompletedTaskParams ): Promise<GetResultFromCompletedTaskResponse> { await this.init(); await isValidProvider(this.iexec); return getResultFromCompletedTask({ ...args, iexec: this.iexec, }); } } export { IExecDataProtectorCore };