Skip to content

Commit 61f77c9

Browse files
Hotfix/fix process protected data function (#424)
Co-authored-by: abbes benayache <[email protected]>
1 parent f964802 commit 61f77c9

File tree

7 files changed

+70
-27
lines changed

7 files changed

+70
-27
lines changed

.drone.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,8 @@ trigger:
12151215
event:
12161216
- promote
12171217
target:
1218+
# publish the package @iexec/dataprotector on npm with the tag nightly
1219+
- sdk-publish-nightly
12181220
# publish the package @iexec/dataprotector on npm with the tag beta (require sdk version to be [version]-beta.[b])
12191221
- sdk-publish-beta
12201222
# publish the package @iexec/dataprotector on npm with the tag latest
@@ -1251,6 +1253,34 @@ steps:
12511253
- main
12521254
target:
12531255
- sdk-publish-beta
1256+
1257+
- name: set-version-nightly
1258+
image: node:18.19
1259+
commands:
1260+
- cd packages/sdk
1261+
- eval npm pkg set version="$(npm pkg get version)-nightly-$DRONE_COMMIT"
1262+
when:
1263+
target:
1264+
- sdk-publish-nightly
1265+
depends_on:
1266+
- install
1267+
1268+
- name: npm publish nightly
1269+
image: plugins/npm
1270+
settings:
1271+
username:
1272+
from_secret: npm_username
1273+
token:
1274+
from_secret: npm_token
1275+
tag: nightly
1276+
access: public
1277+
folder: packages/sdk
1278+
depends_on:
1279+
- build
1280+
- set-version-nightly
1281+
when:
1282+
target:
1283+
- sdk-publish-nightly
12541284

12551285
- name: npm-publish-beta
12561286
image: plugins/npm

packages/sdk/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.0.0-beta.15] (2025-04-04)
6+
7+
### Changed
8+
9+
- Rename `voucherAddress` to `voucherOwner`
10+
- Fix internal bug
11+
512
## [2.0.0-beta.14] (2025-04-01)
613

714
### Added

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@iexec/dataprotector",
3-
"version": "2.0.0-beta.14",
3+
"version": "2.0.0-beta.15",
44
"description": "This product enables users to confidentially store data–such as mail address, documents, personal information ...",
55
"type": "module",
66
"types": "dist/src/index.d.ts",

packages/sdk/src/lib/dataProtectorCore/processProtectedData.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
ProcessProtectedDataResponse,
3434
ProcessProtectedDataStatuses,
3535
} from '../types/index.js';
36-
import { IExecConsumer } from '../types/internalTypes.js';
36+
import { IExecConsumer, VoucherInfo } from '../types/internalTypes.js';
3737
import { getResultFromCompletedTask } from './getResultFromCompletedTask.js';
3838
import { getWhitelistContract } from './smartContract/getWhitelistContract.js';
3939
import { isAddressInWhitelist } from './smartContract/whitelistContract.read.js';
@@ -52,7 +52,7 @@ export const processProtectedData = async ({
5252
secrets,
5353
workerpool,
5454
useVoucher = false,
55-
voucherAddress,
55+
voucherOwner,
5656
onStatusUpdate = () => {},
5757
}: IExecConsumer &
5858
ProcessProtectedDataParams): Promise<ProcessProtectedDataResponse> => {
@@ -83,9 +83,9 @@ export const processProtectedData = async ({
8383
const vUseVoucher = booleanSchema()
8484
.label('useVoucher')
8585
.validateSync(useVoucher);
86-
const vVoucherAddress = addressOrEnsSchema()
87-
.label('voucherAddress')
88-
.validateSync(voucherAddress);
86+
const vVoucherOwner = addressOrEnsSchema()
87+
.label('voucherOwner')
88+
.validateSync(voucherOwner);
8989
try {
9090
const vOnStatusUpdate =
9191
validateOnStatusUpdateCallback<
@@ -118,10 +118,12 @@ export const processProtectedData = async ({
118118
requester = vUserWhitelist;
119119
}
120120
}
121-
let userVoucher;
121+
let userVoucher: VoucherInfo | undefined;
122122
if (vUseVoucher) {
123123
try {
124-
userVoucher = await iexec.voucher.showUserVoucher(requester);
124+
userVoucher = await iexec.voucher.showUserVoucher(
125+
vVoucherOwner || requester
126+
);
125127
checkUserVoucher({ userVoucher });
126128
} catch (err) {
127129
if (err?.message?.startsWith('No Voucher found for address')) {
@@ -182,8 +184,11 @@ export const processProtectedData = async ({
182184
workerpool: vWorkerpool === ethers.ZeroAddress ? 'any' : vWorkerpool, // if address zero was chosen use any workerpool
183185
app: vApp,
184186
dataset: vProtectedData,
185-
requester: requester, // public orders + user specific orders
186-
isRequesterStrict: useVoucher, // If voucher, we only want user specific orders
187+
requester: requester,
188+
isRequesterStrict:
189+
vVoucherOwner && vVoucherOwner.toLowerCase() !== requester.toLowerCase()
190+
? false
191+
: useVoucher,
187192
minTag: SCONE_TAG,
188193
maxTag: SCONE_TAG,
189194
category: 0,
@@ -240,7 +245,7 @@ export const processProtectedData = async ({
240245
};
241246
const matchOptions: MatchOptions = {
242247
useVoucher: vUseVoucher,
243-
...(vVoucherAddress ? { voucherAddress: vVoucherAddress } : {}),
248+
...(vVoucherOwner ? { voucherAddress: userVoucher?.address } : {}),
244249
};
245250

246251
const estimatedMatchOrderPrice = await iexec.order.estimateMatchOrders(

packages/sdk/src/lib/types/coreTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export type ProcessProtectedDataParams = {
342342
/**
343343
* Override the voucher contract to use, must be combined with useVoucher: true the user must be authorized by the voucher's owner to use it.
344344
*/
345-
voucherAddress?: AddressOrENS;
345+
voucherOwner?: AddressOrENS;
346346

347347
/**
348348
* Callback function that will get called at each step of the process

packages/sdk/src/lib/types/internalTypes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GraphQLClient } from 'graphql-request';
2-
import { IExec } from 'iexec';
2+
import { Address, BN, IExec } from 'iexec';
33
import { AddressOrENS } from './commonTypes.js';
44

55
export type IExecConsumer = {
@@ -20,3 +20,16 @@ export type DataProtectorContractConsumer = {
2020
export type SubgraphConsumer = {
2121
graphQLClient: GraphQLClient;
2222
};
23+
24+
export type VoucherInfo = {
25+
owner: Address;
26+
address: Address;
27+
type: BN;
28+
balance: BN;
29+
expirationTimestamp: BN;
30+
sponsoredApps: Address[];
31+
sponsoredDatasets: Address[];
32+
sponsoredWorkerpools: Address[];
33+
allowanceAmount: BN;
34+
authorizedAccounts: Address[];
35+
};

packages/sdk/src/utils/processProtectedData.models.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import { Address, BN } from 'iexec';
1+
import { BN } from 'iexec';
22
import { PublishedWorkerpoolorder } from 'iexec/IExecOrderbookModule';
3-
4-
type VoucherInfo = {
5-
owner: Address;
6-
address: Address;
7-
type: BN;
8-
balance: BN;
9-
expirationTimestamp: BN;
10-
sponsoredApps: Address[];
11-
sponsoredDatasets: Address[];
12-
sponsoredWorkerpools: Address[];
13-
allowanceAmount: BN;
14-
authorizedAccounts: Address[];
15-
};
3+
import { VoucherInfo } from '../lib/types/internalTypes.js';
164

175
function bnToNumber(bn: BN) {
186
return Number(bn.toString());

0 commit comments

Comments
 (0)