Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"build": "rimraf dist && tsc --project tsconfig.build.json",
"build:watch": "npm run build -- --watch",
"check-types": "tsc --noEmit",
"test:prepare": "node tests/prepare-iexec.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\"",
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --coverage",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/unit/**/*.test.ts\"",
Expand All @@ -32,7 +33,7 @@
"generate:abi": "rimraf generated/abis && node tools/generateAbiModules.mjs",
"refresh-abis": "mkdir -p .tmp && cp -r abis/core/registry .tmp/ 2>/dev/null || true && rm -rf abis && mkdir -p abis/core && cp -r ../smart-contract/abis/. ./abis/core/ && if [ -d .tmp/registry ]; then mkdir -p abis/core/registry && cp -r .tmp/registry/. ./abis/core/registry/ && rm -rf .tmp; fi",
"stop-test-stack": "cd tests && docker compose --project-name dataprotector-sdk down --volumes --remove-orphans",
"start-test-stack": "cd tests && npm run stop-test-stack && node prepare-test-env.js && docker compose --project-name dataprotector-sdk build && docker compose --project-name dataprotector-sdk up -d"
"start-test-stack": "cd tests && npm run stop-test-stack && node prepare-test-env.js && docker compose --project-name dataprotector-sdk build && docker compose --project-name dataprotector-sdk up -d && npm run test:prepare"
},
"repository": {
"type": "git",
Expand Down
16 changes: 15 additions & 1 deletion packages/sdk/src/lib/IExecDataProtectorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type EthersCompatibleProvider =
interface IExecDataProtectorResolvedConfig {
dataprotectorContractAddress: AddressOrENS;
graphQLClient: GraphQLClient;
pocoSubgraphClient: GraphQLClient;
ipfsNode: string;
ipfsGateway: string;
defaultWorkerpool: string;
Expand All @@ -33,6 +34,8 @@ abstract class IExecDataProtectorModule {

protected graphQLClient!: GraphQLClient;

protected pocoSubgraphClient!: GraphQLClient;

protected ipfsNode!: string;

protected ipfsGateway!: string;
Expand Down Expand Up @@ -62,6 +65,7 @@ abstract class IExecDataProtectorModule {
this.initPromise = this.resolveConfig().then((config) => {
this.dataprotectorContractAddress = config.dataprotectorContractAddress;
this.graphQLClient = config.graphQLClient;
this.pocoSubgraphClient = config.pocoSubgraphClient;
this.ipfsNode = config.ipfsNode;
this.ipfsGateway = config.ipfsGateway;
this.defaultWorkerpool = config.defaultWorkerpool;
Expand Down Expand Up @@ -103,7 +107,9 @@ abstract class IExecDataProtectorModule {
);
}

let iexec: IExec, graphQLClient: GraphQLClient;
let iexec: IExec,
graphQLClient: GraphQLClient,
pocoSubgraphClient: GraphQLClient;

try {
iexec = new IExec(
Expand All @@ -125,13 +131,21 @@ abstract class IExecDataProtectorModule {
throw new Error(`Failed to create GraphQLClient: ${error.message}`);
}

try {
const pocoSubgraphURL = await iexec.config.resolvePocoSubgraphURL();
pocoSubgraphClient = new GraphQLClient(pocoSubgraphURL);
} catch (error: any) {
throw new Error(`Failed to create PoCo GraphQLClient: ${error.message}`);
}

return {
dataprotectorContractAddress: dataprotectorContractAddress.toLowerCase(),
defaultWorkerpool,
graphQLClient,
ipfsNode,
ipfsGateway,
iexec,
pocoSubgraphClient,
};
}
}
Expand Down
35 changes: 24 additions & 11 deletions packages/sdk/src/lib/dataProtectorCore/IExecDataProtectorCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isValidProvider } from '../../utils/validators.js';
import { isValidSigner } from '../../utils/validators.js';
import { IExecDataProtectorModule } from '../IExecDataProtectorModule.js';
import {
GetGrantedAccessParams,
Expand All @@ -23,11 +23,14 @@ import {
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';
Expand All @@ -42,7 +45,7 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
args: ProtectDataParams
): Promise<ProtectedDataWithSecretProps> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(this.iexec);
return protectData({
...args,
dataprotectorContractAddress: this.dataprotectorContractAddress,
Expand All @@ -55,33 +58,33 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {

async grantAccess(args: GrantAccessParams): Promise<GrantedAccess> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(this.iexec);
return grantAccess({ ...args, iexec: this.iexec });
}

async revokeOneAccess(args: GrantedAccess): Promise<RevokedAccess> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(this.iexec);
return revokeOneAccess({ ...args, iexec: this.iexec });
}

async revokeAllAccess(args: RevokeAllAccessParams): Promise<RevokedAccess[]> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(this.iexec);
return revokeAllAccess({ ...args, iexec: this.iexec });
}

async transferOwnership(args: TransferParams): Promise<TransferResponse> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(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);
await isValidSigner(this.iexec);
return processProtectedData({
...args,
iexec: this.iexec,
Expand All @@ -93,7 +96,7 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
args: PrepareBulkRequestParams
): Promise<PrepareBulkRequestResponse> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(this.iexec);
return prepareBulkRequest({
...args,
iexec: this.iexec,
Expand All @@ -104,7 +107,7 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
args: Params
): Promise<ProcessBulkRequestResponse<Params>> {
await this.init();
await isValidProvider(this.iexec);
await isValidSigner(this.iexec);
return processBulkRequest({
...args,
iexec: this.iexec,
Expand All @@ -131,11 +134,22 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
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();
await isValidProvider(this.iexec);
return waitForTaskCompletion({
...args,
iexec: this.iexec,
Expand All @@ -146,7 +160,6 @@ class IExecDataProtectorCore extends IExecDataProtectorModule {
args: GetResultFromCompletedTaskParams
): Promise<GetResultFromCompletedTaskResponse> {
await this.init();
await isValidProvider(this.iexec);
return getResultFromCompletedTask({
...args,
iexec: this.iexec,
Expand Down
41 changes: 41 additions & 0 deletions packages/sdk/src/lib/dataProtectorCore/getProtectedDataInBulk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { WorkflowError } from '../../utils/errors.js';
import { throwIfMissing } from '../../utils/validators.js';
import { PocoSubgraphConsumer } from '../types/internalTypes.js';
import { getProtectedDataInBulkByBulkRequestHash } from './subgraph/getProtectedDataInBulkByBulkRequestHash.js';

export async function getProtectedDataInBulk({
pocoSubgraphClient = throwIfMissing(),
bulkRequestHash = throwIfMissing(),
}: PocoSubgraphConsumer & {
bulkRequestHash: string;
}): Promise<
Record<string, { dealId: string; protectedDataAddresses: string[] }>
> {
try {
const result = await getProtectedDataInBulkByBulkRequestHash({
pocoSubgraphClient,
bulkRequestHash,
});

const tasks: Record<
string,
{ dealId: string; protectedDataAddresses: string[] }
> = {};
result.deals.forEach((deal) => {
deal.tasks.forEach((task) => {
tasks[task.taskId] = {
dealId: deal.dealId,
protectedDataAddresses:
task.bulkSlice?.datasets.map((dataset) => dataset.id) ?? undefined,
};
});
});
return tasks;
} catch (e) {
console.log('[getProtectedDataInBulk] ERROR', e);
throw new WorkflowError({
message: 'Failed to get protected data in bulk',
errorCause: e,
});
}
}
Loading