UNPKG

@iexec/dataprotector

Version:

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

171 lines (156 loc) 5.1 kB
import { isValidSigner } 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, InspectBulkRequestResponse, InspectBulkRequestParams, } 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 { inspectBulkRequest } from './inspectBulkRequest.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 isValidSigner(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 isValidSigner(this.iexec); return grantAccess({ ...args, iexec: this.iexec }); } async revokeOneAccess(args: GrantedAccess): Promise<RevokedAccess> { await this.init(); await isValidSigner(this.iexec); return revokeOneAccess({ ...args, iexec: this.iexec }); } async revokeAllAccess(args: RevokeAllAccessParams): Promise<RevokedAccess[]> { await this.init(); await isValidSigner(this.iexec); return revokeAllAccess({ ...args, iexec: this.iexec }); } async transferOwnership(args: TransferParams): Promise<TransferResponse> { await this.init(); await isValidSigner(this.iexec); return transferOwnership({ ...args, iexec: this.iexec }); } async processProtectedData<Params extends ProcessProtectedDataParams>( args: Params ): Promise<ProcessProtectedDataResponse<Params>> { await this.init(); await isValidSigner(this.iexec); return processProtectedData({ ...args, iexec: this.iexec, defaultWorkerpool: this.defaultWorkerpool, }); } async prepareBulkRequest( args: PrepareBulkRequestParams ): Promise<PrepareBulkRequestResponse> { await this.init(); await isValidSigner(this.iexec); return prepareBulkRequest({ ...args, iexec: this.iexec, }); } async processBulkRequest<Params extends ProcessBulkRequestParams>( args: Params ): Promise<ProcessBulkRequestResponse<Params>> { await this.init(); await isValidSigner(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 inspectBulkRequest<Params extends InspectBulkRequestParams>( args: Params ): Promise<InspectBulkRequestResponse<Params>> { await this.init(); return inspectBulkRequest({ ...args, iexec: this.iexec, pocoSubgraphClient: this.pocoSubgraphClient, defaultWorkerpool: this.defaultWorkerpool, }); } async waitForTaskCompletion( args: WaitForTaskCompletionParams ): Promise<WaitForTaskCompletionResponse> { await this.init(); return waitForTaskCompletion({ ...args, iexec: this.iexec, }); } async getResultFromCompletedTask( args: GetResultFromCompletedTaskParams ): Promise<GetResultFromCompletedTaskResponse> { await this.init(); return getResultFromCompletedTask({ ...args, iexec: this.iexec, }); } } export { IExecDataProtectorCore };