@iexec/web3mail 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/config/config.d.ts +3 -1
  2. package/dist/config/config.js +3 -1
  3. package/dist/config/config.js.map +1 -1
  4. package/dist/utils/errors.d.ts +1 -2
  5. package/dist/utils/errors.js +1 -2
  6. package/dist/utils/errors.js.map +1 -1
  7. package/dist/utils/ipfs-service.d.ts +7 -5
  8. package/dist/utils/ipfs-service.js +3 -3
  9. package/dist/utils/ipfs-service.js.map +1 -1
  10. package/dist/utils/subgraphQuery.js +2 -3
  11. package/dist/utils/subgraphQuery.js.map +1 -1
  12. package/dist/utils/validators.d.ts +4 -0
  13. package/dist/utils/validators.js +9 -4
  14. package/dist/utils/validators.js.map +1 -1
  15. package/dist/web3mail/IExecWeb3mail.d.ts +13 -8
  16. package/dist/web3mail/IExecWeb3mail.js +21 -8
  17. package/dist/web3mail/IExecWeb3mail.js.map +1 -1
  18. package/dist/web3mail/fetchMyContacts.d.ts +2 -2
  19. package/dist/web3mail/fetchMyContacts.js +8 -39
  20. package/dist/web3mail/fetchMyContacts.js.map +1 -1
  21. package/dist/web3mail/fetchUserContacts.d.ts +2 -0
  22. package/dist/web3mail/fetchUserContacts.js +82 -0
  23. package/dist/web3mail/fetchUserContacts.js.map +1 -0
  24. package/dist/web3mail/sendEmail.d.ts +2 -2
  25. package/dist/web3mail/sendEmail.js +103 -54
  26. package/dist/web3mail/sendEmail.js.map +1 -1
  27. package/dist/web3mail/types.d.ts +58 -7
  28. package/package.json +17 -16
  29. package/src/config/config.ts +3 -1
  30. package/src/utils/errors.ts +2 -3
  31. package/src/utils/ipfs-service.ts +20 -4
  32. package/src/utils/subgraphQuery.ts +2 -4
  33. package/src/utils/validators.ts +20 -6
  34. package/src/web3mail/IExecWeb3mail.ts +65 -23
  35. package/src/web3mail/fetchMyContacts.ts +15 -58
  36. package/src/web3mail/fetchUserContacts.ts +105 -0
  37. package/src/web3mail/sendEmail.ts +138 -73
  38. package/src/web3mail/types.ts +72 -7
@@ -7,14 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, WEB3_MAIL_DAPP_ADDRESS, WORKERPOOL_ADDRESS, } from '../config/config.js';
10
+ import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_DATA_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, PROD_WORKERPOOL_ADDRESS, } from '../config/config.js';
11
11
  import { WorkflowError } from '../utils/errors.js';
12
12
  import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
13
+ import * as ipfs from '../utils/ipfs-service.js';
13
14
  import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
14
- import { addressOrEnsSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
15
- import * as ipfs from './../utils/ipfs-service.js';
16
- export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), emailSubject, emailContent, contentType = DEFAULT_CONTENT_TYPE, senderName, protectedData, }) => __awaiter(void 0, void 0, void 0, function* () {
17
- var _a, _b, _c, _d, _e;
15
+ import { addressOrEnsSchema, addressSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, labelSchema, positiveNumberSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
16
+ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), workerpoolAddressOrEns = PROD_WORKERPOOL_ADDRESS, dappAddressOrENS, dappWhitelistAddress, ipfsNode, ipfsGateway, emailSubject, emailContent, contentType = DEFAULT_CONTENT_TYPE, label, dataMaxPrice = MAX_DESIRED_DATA_ORDER_PRICE, appMaxPrice = MAX_DESIRED_APP_ORDER_PRICE, workerpoolMaxPrice = MAX_DESIRED_WORKERPOOL_ORDER_PRICE, senderName, protectedData, }) => __awaiter(void 0, void 0, void 0, function* () {
18
17
  try {
19
18
  const vDatasetAddress = addressOrEnsSchema()
20
19
  .required()
@@ -35,6 +34,28 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
35
34
  const vSenderName = senderNameSchema()
36
35
  .label('senderName')
37
36
  .validateSync(senderName);
37
+ const vLabel = labelSchema().label('label').validateSync(label);
38
+ const vWorkerpoolAddressOrEns = addressOrEnsSchema()
39
+ .required()
40
+ .label('WorkerpoolAddressOrEns')
41
+ .validateSync(workerpoolAddressOrEns);
42
+ const vDappAddressOrENS = addressOrEnsSchema()
43
+ .required()
44
+ .label('dappAddressOrENS')
45
+ .validateSync(dappAddressOrENS);
46
+ const vDappWhitelistAddress = addressSchema()
47
+ .required()
48
+ .label('dappWhitelistAddress')
49
+ .validateSync(dappWhitelistAddress);
50
+ const vDataMaxPrice = positiveNumberSchema()
51
+ .label('dataMaxPrice')
52
+ .validateSync(dataMaxPrice);
53
+ const vAppMaxPrice = positiveNumberSchema()
54
+ .label('appMaxPrice')
55
+ .validateSync(appMaxPrice);
56
+ const vWorkerpoolMaxPrice = positiveNumberSchema()
57
+ .label('workerpoolMaxPrice')
58
+ .validateSync(workerpoolMaxPrice);
38
59
  // Check protected data validity through subgraph
39
60
  const isValidProtectedData = yield checkProtectedDataValidity(graphQLClient, vDatasetAddress);
40
61
  if (!isValidProtectedData) {
@@ -47,48 +68,69 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
47
68
  const token = yield iexec.storage.defaultStorageLogin();
48
69
  yield iexec.storage.pushStorageToken(token);
49
70
  }
50
- // Fetch dataset order
51
- const datasetOrderbook = yield iexec.orderbook.fetchDatasetOrderbook(vDatasetAddress, {
52
- app: WEB3_MAIL_DAPP_ADDRESS,
53
- requester: requesterAddress,
54
- });
55
- const datasetorder = (_a = datasetOrderbook === null || datasetOrderbook === void 0 ? void 0 : datasetOrderbook.orders[0]) === null || _a === void 0 ? void 0 : _a.order;
71
+ const [datasetorderForApp, datasetorderForWhitelist, apporder, workerpoolorder,] = yield Promise.all([
72
+ // Fetch dataset order for web3mail app
73
+ iexec.orderbook
74
+ .fetchDatasetOrderbook(vDatasetAddress, {
75
+ app: dappAddressOrENS,
76
+ requester: requesterAddress,
77
+ })
78
+ .then((datasetOrderbook) => {
79
+ var _a;
80
+ const desiredPriceDataOrderbook = datasetOrderbook.orders.filter((order) => order.order.datasetprice <= vDataMaxPrice);
81
+ return (_a = desiredPriceDataOrderbook[0]) === null || _a === void 0 ? void 0 : _a.order; // may be undefined
82
+ }),
83
+ // Fetch dataset order for web3mail whitelist
84
+ iexec.orderbook
85
+ .fetchDatasetOrderbook(vDatasetAddress, {
86
+ app: vDappWhitelistAddress,
87
+ requester: requesterAddress,
88
+ })
89
+ .then((datasetOrderbook) => {
90
+ var _a;
91
+ const desiredPriceDataOrderbook = datasetOrderbook.orders.filter((order) => order.order.datasetprice <= vDataMaxPrice);
92
+ return (_a = desiredPriceDataOrderbook[0]) === null || _a === void 0 ? void 0 : _a.order; // may be undefined
93
+ }),
94
+ // Fetch app order
95
+ iexec.orderbook
96
+ .fetchAppOrderbook(dappAddressOrENS, {
97
+ minTag: ['tee', 'scone'],
98
+ maxTag: ['tee', 'scone'],
99
+ workerpool: workerpoolAddressOrEns,
100
+ })
101
+ .then((appOrderbook) => {
102
+ var _a;
103
+ const desiredPriceAppOrderbook = appOrderbook.orders.filter((order) => order.order.appprice <= vAppMaxPrice);
104
+ const desiredPriceAppOrder = (_a = desiredPriceAppOrderbook[0]) === null || _a === void 0 ? void 0 : _a.order;
105
+ if (!desiredPriceAppOrder) {
106
+ throw new Error('No App order found for the desired price');
107
+ }
108
+ return desiredPriceAppOrder;
109
+ }),
110
+ // Fetch workerpool order
111
+ iexec.orderbook
112
+ .fetchWorkerpoolOrderbook({
113
+ workerpool: workerpoolAddressOrEns,
114
+ app: dappAddressOrENS,
115
+ dataset: vDatasetAddress,
116
+ minTag: ['tee', 'scone'],
117
+ maxTag: ['tee', 'scone'],
118
+ category: 0,
119
+ })
120
+ .then((workerpoolOrderbook) => {
121
+ var _a;
122
+ const desiredPriceWorkerpoolOrderbook = workerpoolOrderbook.orders.filter((order) => order.order.workerpoolprice <= vWorkerpoolMaxPrice);
123
+ const randomIndex = Math.floor(Math.random() * desiredPriceWorkerpoolOrderbook.length);
124
+ const desiredPriceWorkerpoolOrder = (_a = desiredPriceWorkerpoolOrderbook[randomIndex]) === null || _a === void 0 ? void 0 : _a.order;
125
+ if (!desiredPriceWorkerpoolOrder) {
126
+ throw new Error('No Workerpool order found for the desired price');
127
+ }
128
+ return desiredPriceWorkerpoolOrder;
129
+ }),
130
+ ]);
131
+ const datasetorder = datasetorderForApp || datasetorderForWhitelist;
56
132
  if (!datasetorder) {
57
- throw new Error('Dataset order not found');
58
- }
59
- // Fetch app order
60
- const appOrderbook = yield iexec.orderbook.fetchAppOrderbook(WEB3_MAIL_DAPP_ADDRESS, {
61
- minTag: ['tee', 'scone'],
62
- maxTag: ['tee', 'scone'],
63
- workerpool: WORKERPOOL_ADDRESS,
64
- });
65
- const appOrder = (_b = appOrderbook === null || appOrderbook === void 0 ? void 0 : appOrderbook.orders[0]) === null || _b === void 0 ? void 0 : _b.order;
66
- if (!appOrder) {
67
- throw new Error('App order not found');
68
- }
69
- const desiredPriceAppOrderbook = appOrderbook.orders.filter((order) => order.order.appprice <= MAX_DESIRED_APP_ORDER_PRICE);
70
- const desiredPriceAppOrder = (_c = desiredPriceAppOrderbook[0]) === null || _c === void 0 ? void 0 : _c.order;
71
- if (!desiredPriceAppOrder) {
72
- throw new Error('No App order found for the desired price');
73
- }
74
- // Fetch workerpool order
75
- const workerpoolOrderbook = yield iexec.orderbook.fetchWorkerpoolOrderbook({
76
- workerpool: WORKERPOOL_ADDRESS,
77
- app: WEB3_MAIL_DAPP_ADDRESS,
78
- dataset: vDatasetAddress,
79
- minTag: ['tee', 'scone'],
80
- maxTag: ['tee', 'scone'],
81
- category: 0,
82
- });
83
- const workerpoolorder = (_d = workerpoolOrderbook === null || workerpoolOrderbook === void 0 ? void 0 : workerpoolOrderbook.orders[0]) === null || _d === void 0 ? void 0 : _d.order;
84
- if (!workerpoolorder) {
85
- throw new Error('Workerpool order not found');
86
- }
87
- const desiredPriceWorkerpoolOrderbook = workerpoolOrderbook.orders.filter((order) => order.order.workerpoolprice <= MAX_DESIRED_WORKERPOOL_ORDER_PRICE);
88
- const randomIndex = Math.floor(Math.random() * desiredPriceWorkerpoolOrderbook.length);
89
- const desiredPriceWorkerpoolOrder = (_e = desiredPriceWorkerpoolOrderbook[randomIndex]) === null || _e === void 0 ? void 0 : _e.order;
90
- if (!desiredPriceWorkerpoolOrder) {
91
- throw new Error('No Workerpool order found for the desired price');
133
+ throw new Error('No Dataset order found for the desired price');
92
134
  }
93
135
  // Push requester secrets
94
136
  const requesterSecretId = generateSecureUniqueId(16);
@@ -98,7 +140,12 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
98
140
  .catch((e) => {
99
141
  throw new WorkflowError('Failed to encrypt email content', e);
100
142
  });
101
- const cid = yield ipfs.add(encryptedFile).catch((e) => {
143
+ const cid = yield ipfs
144
+ .add(encryptedFile, {
145
+ ipfsNode: ipfsNode,
146
+ ipfsGateway: ipfsGateway,
147
+ })
148
+ .catch((e) => {
102
149
  throw new WorkflowError('Failed to upload encrypted email content', e);
103
150
  });
104
151
  const multiaddr = `/ipfs/${cid}`;
@@ -110,26 +157,28 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
110
157
  emailContentEncryptionKey,
111
158
  }));
112
159
  const requestorderToSign = yield iexec.order.createRequestorder({
113
- app: WEB3_MAIL_DAPP_ADDRESS,
114
- category: desiredPriceWorkerpoolOrder.category,
160
+ app: vDappAddressOrENS,
161
+ category: workerpoolorder.category,
115
162
  dataset: vDatasetAddress,
116
- appmaxprice: desiredPriceAppOrder.appprice,
117
- workerpoolmaxprice: desiredPriceWorkerpoolOrder.workerpoolprice,
163
+ datasetmaxprice: datasetorder.datasetprice,
164
+ appmaxprice: apporder.appprice,
165
+ workerpoolmaxprice: workerpoolorder.workerpoolprice,
118
166
  tag: ['tee', 'scone'],
119
- workerpool: WORKERPOOL_ADDRESS,
167
+ workerpool: vWorkerpoolAddressOrEns,
120
168
  params: {
121
169
  iexec_developer_logger: true,
122
170
  iexec_secrets: {
123
171
  1: requesterSecretId,
124
172
  },
173
+ iexec_args: vLabel,
125
174
  },
126
175
  });
127
176
  const requestorder = yield iexec.order.signRequestorder(requestorderToSign);
128
177
  // Match orders and compute task ID
129
178
  const { dealid } = yield iexec.order.matchOrders({
130
- apporder: desiredPriceAppOrder,
179
+ apporder: apporder,
131
180
  datasetorder: datasetorder,
132
- workerpoolorder: desiredPriceWorkerpoolOrder,
181
+ workerpoolorder: workerpoolorder,
133
182
  requestorder: requestorder,
134
183
  });
135
184
  const taskId = yield iexec.deal.computeTaskId(dealid, 0);
@@ -1 +1 @@
1
- {"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,kCAAkC,EAClC,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAOhC,OAAO,KAAK,IAAI,MAAM,4BAA4B,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,CAAC;QAE5E,mCAAmC;QACnC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC;YAC/C,QAAQ,EAAE,QAAQ;YAClB,YAAY,EAAE,YAAY;YAC1B,eAAe,EAAE,eAAe;YAChC,YAAY,EAAE,YAAY;SAC3B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAEzD,OAAO;YACL,MAAM;SACP,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,aAAa,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;KACpD;AACH,CAAC,CAAA,CAAC"}
@@ -1,9 +1,12 @@
1
1
  import { GraphQLClient } from 'graphql-request';
2
2
  import { EnhancedWallet, IExec } from 'iexec';
3
+ import { IExecConfigOptions } from 'iexec/IExecConfig';
3
4
  export type Web3SignerProvider = EnhancedWallet;
4
5
  export type IExecConsumer = {
5
6
  iexec: IExec;
6
7
  };
8
+ export type ENS = string;
9
+ export type AddressOrENS = Address | ENS;
7
10
  export type Address = string;
8
11
  export type TimeStamp = string;
9
12
  export type Contact = {
@@ -17,16 +20,17 @@ export type SendEmailParams = {
17
20
  protectedData: Address;
18
21
  contentType?: string;
19
22
  senderName?: string;
23
+ label?: string;
24
+ workerpoolAddressOrEns?: AddressOrENS;
25
+ dataMaxPrice?: number;
26
+ appMaxPrice?: number;
27
+ workerpoolMaxPrice?: number;
20
28
  };
21
- export type FetchContactsParams = {
29
+ export type FetchUserContactsParams = {
22
30
  /**
23
- * Index of the page to fetch
31
+ * Address of the user
24
32
  */
25
- page?: number;
26
- /**
27
- * Size of the page to fetch
28
- */
29
- pageSize?: number;
33
+ userAddress: Address;
30
34
  };
31
35
  export type SendEmailResponse = {
32
36
  taskId: Address;
@@ -43,3 +47,50 @@ export type GraphQLResponse = {
43
47
  export type SubgraphConsumer = {
44
48
  graphQLClient: GraphQLClient;
45
49
  };
50
+ /**
51
+ * Configuration options for Web3Mail.
52
+ */
53
+ export type Web3MailConfigOptions = {
54
+ /**
55
+ * The Ethereum contract address or ENS (Ethereum Name Service) for the email sender dapp.
56
+ * If not provided, the default web3mail address will be used.
57
+ */
58
+ dappAddressOrENS?: AddressOrENS;
59
+ /**
60
+ * The Ethereum contract address for the whitelist.
61
+ * If not provided, the default whitelist smart contract address will be used.
62
+ */
63
+ dappWhitelistAddress?: Address;
64
+ /**
65
+ * The subgraph URL for querying data.
66
+ * If not provided, the default data protector subgraph URL will be used.
67
+ */
68
+ dataProtectorSubgraph?: string;
69
+ /**
70
+ * Options specific to iExec integration.
71
+ * If not provided, default iexec options will be used.
72
+ */
73
+ iexecOptions?: IExecConfigOptions;
74
+ /**
75
+ * The IPFS node URL.
76
+ * If not provided, the default IPFS node URL will be used.
77
+ */
78
+ ipfsNode?: string;
79
+ /**
80
+ * The IPFS gateway URL.
81
+ * If not provided, the default IPFS gateway URL will be used.
82
+ */
83
+ ipfsGateway?: string;
84
+ };
85
+ export type DappAddressConsumer = {
86
+ dappAddressOrENS: AddressOrENS;
87
+ };
88
+ export type IpfsNodeConfigConsumer = {
89
+ ipfsNode: string;
90
+ };
91
+ export type IpfsGatewayConfigConsumer = {
92
+ ipfsGateway: string;
93
+ };
94
+ export type DappWhitelistAddressConsumer = {
95
+ dappWhitelistAddress: string;
96
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iexec/web3mail",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "This product enables users to confidentially store data–such as mail address, documents, personal information ...",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -18,8 +18,9 @@
18
18
  "dist"
19
19
  ],
20
20
  "scripts": {
21
- "build": "rm -rf dist && tsc",
22
- "test": "rm -rf dist && tsc && NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
21
+ "build": "rm -rf dist && tsc --project tsconfig.build.json",
22
+ "check-types": "tsc --noEmit",
23
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --coverage",
23
24
  "lint": "eslint .",
24
25
  "format": "prettier --write \"src/**/*.ts\"",
25
26
  "check-format": "prettier --check \"src/**/*.ts\""
@@ -37,9 +38,20 @@
37
38
  "url": "https://github.com/iExecBlockchainComputing/web3mail-sdk/issues"
38
39
  },
39
40
  "homepage": "https://github.com/iExecBlockchainComputing/web3mail-sdk#readme",
41
+ "dependencies": {
42
+ "@ethersproject/bytes": "^5.7.0",
43
+ "@ethersproject/random": "^5.7.0",
44
+ "ethers": "^6.8.1",
45
+ "graphql-request": "^6.1.0",
46
+ "iexec": "^8.5.0",
47
+ "kubo-rpc-client": "^3.0.1",
48
+ "yup": "^1.1.1"
49
+ },
40
50
  "devDependencies": {
41
- "@iexec/dataprotector": "^0.2.0",
51
+ "@iexec/dataprotector": "^0.4.1",
42
52
  "@jest/globals": "^29.7.0",
53
+ "@swc/core": "^1.3.96",
54
+ "@swc/jest": "^0.2.29",
43
55
  "@types/jest": "^29.5.4",
44
56
  "@typescript-eslint/eslint-plugin": "^6.7.5",
45
57
  "@typescript-eslint/parser": "^6.7.5",
@@ -49,20 +61,9 @@
49
61
  "eslint-plugin-import": "^2.28.1",
50
62
  "eslint-plugin-jest": "^27.4.2",
51
63
  "eslint-plugin-sonarjs": "^0.21.0",
52
- "jest": "^29.5.0",
64
+ "jest": "^29.7.0",
53
65
  "prettier": "^2.8.4",
54
- "ts-jest": "^29.1.0",
55
- "ts-loader": "^9.4.2",
56
66
  "typescript": "^4.9.5",
57
67
  "whitelist-smart-contract": "github:iExecBlockchainComputing/whitelist-smart-contract#0.2.0"
58
- },
59
- "dependencies": {
60
- "@ethersproject/bytes": "^5.7.0",
61
- "@ethersproject/random": "^5.7.0",
62
- "ethers": "^5.7.2",
63
- "graphql-request": "^6.1.0",
64
- "iexec": "^8.4.0",
65
- "kubo-rpc-client": "^3.0.1",
66
- "yup": "^1.1.1"
67
68
  }
68
69
  }
@@ -1,7 +1,8 @@
1
1
  export const WEB3_MAIL_DAPP_ADDRESS = 'web3mail.apps.iexec.eth';
2
- export const WORKERPOOL_ADDRESS = 'prod-v8-bellecour.main.pools.iexec.eth';
2
+ export const PROD_WORKERPOOL_ADDRESS = 'prod-v8-bellecour.main.pools.iexec.eth';
3
3
  export const DATAPROTECTOR_SUBGRAPH_ENDPOINT =
4
4
  'https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector';
5
+ export const MAX_DESIRED_DATA_ORDER_PRICE = 0;
5
6
  export const MAX_DESIRED_APP_ORDER_PRICE = 0;
6
7
  export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
7
8
  export const DEFAULT_CONTENT_TYPE = 'text/plain';
@@ -9,3 +10,4 @@ export const IPFS_UPLOAD_URL = '/dns4/ipfs-upload.v8-bellecour.iex.ec/https';
9
10
  export const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec';
10
11
  export const WHITELIST_SMART_CONTRACT_ADDRESS =
11
12
  '0x781482C39CcE25546583EaC4957Fb7Bf04C277D2';
13
+ export const ANY_DATASET_ADDRESS = 'any';
@@ -1,5 +1,3 @@
1
- import { ValidationError } from 'yup';
2
-
3
1
  class WorkflowError extends Error {
4
2
  originalError: Error;
5
3
 
@@ -9,4 +7,5 @@ class WorkflowError extends Error {
9
7
  this.originalError = originalError;
10
8
  }
11
9
  }
12
- export { WorkflowError, ValidationError };
10
+
11
+ export { WorkflowError };
@@ -1,7 +1,17 @@
1
1
  import { create } from 'kubo-rpc-client';
2
- import { DEFAULT_IPFS_GATEWAY, IPFS_UPLOAD_URL } from './../config/config.js';
2
+ import { IPFS_UPLOAD_URL, DEFAULT_IPFS_GATEWAY } from '../config/config.js';
3
3
 
4
- const get = async (cid, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) => {
4
+ interface GetOptions {
5
+ ipfsGateway?: string;
6
+ }
7
+ interface AddOptions extends GetOptions {
8
+ ipfsNode?: string;
9
+ }
10
+
11
+ const get = async (
12
+ cid,
13
+ { ipfsGateway = DEFAULT_IPFS_GATEWAY }: GetOptions = {}
14
+ ) => {
5
15
  const multiaddr = `/ipfs/${cid.toString()}`;
6
16
  const publicUrl = `${ipfsGateway}${multiaddr}`;
7
17
  const res = await fetch(publicUrl);
@@ -12,8 +22,14 @@ const get = async (cid, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) => {
12
22
  return new Uint8Array(arrayBuffer);
13
23
  };
14
24
 
15
- const add = async (content, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) => {
16
- const ipfsClient = create(IPFS_UPLOAD_URL);
25
+ const add = async (
26
+ content,
27
+ {
28
+ ipfsNode = IPFS_UPLOAD_URL,
29
+ ipfsGateway = DEFAULT_IPFS_GATEWAY,
30
+ }: AddOptions = {}
31
+ ) => {
32
+ const ipfsClient = create(ipfsNode);
17
33
  const { cid } = await ipfsClient.add(content);
18
34
  await get(cid.toString(), { ipfsGateway });
19
35
  return cid.toString();
@@ -34,7 +34,7 @@ export const getValidContact = async (
34
34
  const contactsAddresses = contacts.map((contact) => contact.address);
35
35
 
36
36
  // Pagination
37
- let protectedDataList: ProtectedDataQuery[] = [];
37
+ const protectedDataList: ProtectedDataQuery[] = [];
38
38
  let start = 0;
39
39
  const range = 1000;
40
40
  let continuePagination = true;
@@ -63,7 +63,7 @@ export const getValidContact = async (
63
63
  );
64
64
 
65
65
  // Convert protectedData[] into Contact[] using the map for constant time lookups
66
- const validContacts = protectedDataList.map(({ id }) => {
66
+ return protectedDataList.map(({ id }) => {
67
67
  const contact = contactsMap.get(id);
68
68
  if (contact) {
69
69
  return {
@@ -73,8 +73,6 @@ export const getValidContact = async (
73
73
  };
74
74
  }
75
75
  });
76
-
77
- return validContacts;
78
76
  } catch (error) {
79
77
  throw new WorkflowError(
80
78
  `Failed to fetch subgraph: ${error.message}`,
@@ -1,15 +1,14 @@
1
- import { utils } from 'ethers';
2
- import { ValidationError, string } from 'yup';
3
-
4
- const { isAddress } = utils;
1
+ import { isAddress } from 'ethers';
2
+ import { ValidationError, number, string } from 'yup';
5
3
 
6
4
  export const throwIfMissing = (): never => {
7
5
  throw new ValidationError('Missing parameter');
8
6
  };
9
7
 
10
- const isUndefined = (value: any) => value === undefined;
8
+ const isUndefined = (value: unknown) => value === undefined;
11
9
  const isAddressTest = (value: string) => isAddress(value);
12
- const isEnsTest = (value: string) => value.endsWith('.eth') && value.length > 6;
10
+ export const isEnsTest = (value: string) =>
11
+ value.endsWith('.eth') && value.length > 6;
13
12
 
14
13
  export const addressOrEnsSchema = () =>
15
14
  string()
@@ -20,6 +19,15 @@ export const addressOrEnsSchema = () =>
20
19
  (value) => isUndefined(value) || isAddressTest(value) || isEnsTest(value)
21
20
  );
22
21
 
22
+ export const addressSchema = () =>
23
+ string()
24
+ .transform((value: string) => value?.toLowerCase() || value)
25
+ .test(
26
+ 'is-address',
27
+ '${path} should be an ethereum address',
28
+ (value) => isUndefined(value) || isAddressTest(value)
29
+ );
30
+
23
31
  // 78 char length for email subject (rfc2822)
24
32
  export const emailSubjectSchema = () => string().max(78).strict();
25
33
 
@@ -34,3 +42,9 @@ export const contentTypeSchema = () =>
34
42
 
35
43
  // Minimum of 3 characters and max of 20 to avoid sender being flagged as spam
36
44
  export const senderNameSchema = () => string().trim().min(3).max(20).optional();
45
+
46
+ // Used to identify the email campaign, minimum of 3 characters and max of 10
47
+ export const labelSchema = () => string().trim().min(3).max(10).optional();
48
+
49
+ export const positiveNumberSchema = () =>
50
+ number().integer().min(0).typeError('${path} must be a non-negative number');
@@ -1,49 +1,91 @@
1
- import { providers } from 'ethers';
1
+ import { Eip1193Provider } from 'ethers';
2
2
  import { IExec } from 'iexec';
3
- import { IExecConfigOptions } from 'iexec/IExecConfig';
3
+ import { fetchUserContacts } from './fetchUserContacts.js';
4
4
  import { fetchMyContacts } from './fetchMyContacts.js';
5
5
  import { sendEmail } from './sendEmail.js';
6
6
  import {
7
7
  Contact,
8
- FetchContactsParams,
8
+ FetchUserContactsParams,
9
9
  SendEmailParams,
10
- SendEmailResponse,
11
10
  Web3SignerProvider,
11
+ AddressOrENS,
12
+ Web3MailConfigOptions,
12
13
  } from './types.js';
13
14
  import { GraphQLClient } from 'graphql-request';
14
- import { DATAPROTECTOR_SUBGRAPH_ENDPOINT } from '../config/config.js';
15
+ import {
16
+ WEB3_MAIL_DAPP_ADDRESS,
17
+ IPFS_UPLOAD_URL,
18
+ DEFAULT_IPFS_GATEWAY,
19
+ DATAPROTECTOR_SUBGRAPH_ENDPOINT,
20
+ WHITELIST_SMART_CONTRACT_ADDRESS,
21
+ } from '../config/config.js';
15
22
 
16
23
  export class IExecWeb3mail {
17
- fetchMyContacts: (args?: FetchContactsParams) => Promise<Contact[]>;
18
- sendEmail: (args: SendEmailParams) => Promise<SendEmailResponse>;
24
+ private iexec: IExec;
25
+
26
+ private ipfsNode: string;
27
+
28
+ private ipfsGateway: string;
29
+
30
+ private dataProtectorSubgraph: string;
31
+
32
+ private dappAddressOrENS: AddressOrENS;
33
+
34
+ private dappWhitelistAddress: AddressOrENS;
35
+
36
+ private graphQLClient: GraphQLClient;
19
37
 
20
38
  constructor(
21
- ethProvider: providers.ExternalProvider | Web3SignerProvider,
22
- options?: {
23
- iexecOptions?: IExecConfigOptions;
24
- }
39
+ ethProvider: Eip1193Provider | Web3SignerProvider,
40
+ options?: Web3MailConfigOptions
25
41
  ) {
26
- let iexec: IExec;
27
- let graphQLClient: GraphQLClient;
28
42
  try {
29
- iexec = new IExec({ ethProvider }, options?.iexecOptions);
43
+ this.iexec = new IExec({ ethProvider }, options?.iexecOptions);
30
44
  } catch (e) {
31
45
  throw Error('Unsupported ethProvider');
32
46
  }
33
47
 
34
48
  try {
35
- graphQLClient = new GraphQLClient(DATAPROTECTOR_SUBGRAPH_ENDPOINT);
49
+ this.dataProtectorSubgraph =
50
+ options?.dataProtectorSubgraph || DATAPROTECTOR_SUBGRAPH_ENDPOINT;
51
+ this.graphQLClient = new GraphQLClient(this.dataProtectorSubgraph);
36
52
  } catch (e) {
37
53
  throw Error('Impossible to create GraphQLClient');
38
54
  }
39
55
 
40
- this.fetchMyContacts = (args?: FetchContactsParams) =>
41
- fetchMyContacts({ ...args, iexec, graphQLClient });
42
- this.sendEmail = (args: SendEmailParams) =>
43
- sendEmail({
44
- ...args,
45
- iexec,
46
- graphQLClient,
47
- });
56
+ this.dappAddressOrENS = options?.dappAddressOrENS || WEB3_MAIL_DAPP_ADDRESS;
57
+ this.ipfsNode = options?.ipfsNode || IPFS_UPLOAD_URL;
58
+ this.ipfsGateway = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY;
59
+ this.dappWhitelistAddress =
60
+ options?.dappWhitelistAddress || WHITELIST_SMART_CONTRACT_ADDRESS;
61
+ }
62
+
63
+ fetchMyContacts = () =>
64
+ fetchMyContacts({
65
+ iexec: this.iexec,
66
+ graphQLClient: this.graphQLClient,
67
+ dappAddressOrENS: this.dappAddressOrENS,
68
+ dappWhitelistAddress: this.dappWhitelistAddress,
69
+ });
70
+
71
+ fetchUserContacts(args?: FetchUserContactsParams): Promise<Contact[]> {
72
+ return fetchUserContacts({
73
+ ...args,
74
+ iexec: this.iexec,
75
+ graphQLClient: this.graphQLClient,
76
+ dappAddressOrENS: this.dappAddressOrENS,
77
+ dappWhitelistAddress: this.dappWhitelistAddress,
78
+ });
48
79
  }
80
+
81
+ sendEmail = (args: SendEmailParams) =>
82
+ sendEmail({
83
+ ...args,
84
+ iexec: this.iexec,
85
+ ipfsNode: this.ipfsNode,
86
+ ipfsGateway: this.ipfsGateway,
87
+ dappAddressOrENS: this.dappAddressOrENS,
88
+ dappWhitelistAddress: this.dappWhitelistAddress,
89
+ graphQLClient: this.graphQLClient,
90
+ });
49
91
  }