@iexec/web3mail 0.5.2 → 0.6.1

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 +12 -7
  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 +83 -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 +104 -54
  26. package/dist/web3mail/sendEmail.js.map +1 -1
  27. package/dist/web3mail/types.d.ts +59 -8
  28. package/package.json +18 -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 +66 -23
  35. package/src/web3mail/fetchMyContacts.ts +15 -58
  36. package/src/web3mail/fetchUserContacts.ts +106 -0
  37. package/src/web3mail/sendEmail.ts +139 -73
  38. package/src/web3mail/types.ts +73 -8
@@ -7,14 +7,14 @@ 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 { Buffer } from 'buffer';
11
+ 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
12
  import { WorkflowError } from '../utils/errors.js';
12
13
  import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
14
+ import * as ipfs from '../utils/ipfs-service.js';
13
15
  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;
16
+ import { addressOrEnsSchema, addressSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, labelSchema, positiveNumberSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
17
+ 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
18
  try {
19
19
  const vDatasetAddress = addressOrEnsSchema()
20
20
  .required()
@@ -35,6 +35,28 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
35
35
  const vSenderName = senderNameSchema()
36
36
  .label('senderName')
37
37
  .validateSync(senderName);
38
+ const vLabel = labelSchema().label('label').validateSync(label);
39
+ const vWorkerpoolAddressOrEns = addressOrEnsSchema()
40
+ .required()
41
+ .label('WorkerpoolAddressOrEns')
42
+ .validateSync(workerpoolAddressOrEns);
43
+ const vDappAddressOrENS = addressOrEnsSchema()
44
+ .required()
45
+ .label('dappAddressOrENS')
46
+ .validateSync(dappAddressOrENS);
47
+ const vDappWhitelistAddress = addressSchema()
48
+ .required()
49
+ .label('dappWhitelistAddress')
50
+ .validateSync(dappWhitelistAddress);
51
+ const vDataMaxPrice = positiveNumberSchema()
52
+ .label('dataMaxPrice')
53
+ .validateSync(dataMaxPrice);
54
+ const vAppMaxPrice = positiveNumberSchema()
55
+ .label('appMaxPrice')
56
+ .validateSync(appMaxPrice);
57
+ const vWorkerpoolMaxPrice = positiveNumberSchema()
58
+ .label('workerpoolMaxPrice')
59
+ .validateSync(workerpoolMaxPrice);
38
60
  // Check protected data validity through subgraph
39
61
  const isValidProtectedData = yield checkProtectedDataValidity(graphQLClient, vDatasetAddress);
40
62
  if (!isValidProtectedData) {
@@ -47,48 +69,69 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
47
69
  const token = yield iexec.storage.defaultStorageLogin();
48
70
  yield iexec.storage.pushStorageToken(token);
49
71
  }
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;
72
+ const [datasetorderForApp, datasetorderForWhitelist, apporder, workerpoolorder,] = yield Promise.all([
73
+ // Fetch dataset order for web3mail app
74
+ iexec.orderbook
75
+ .fetchDatasetOrderbook(vDatasetAddress, {
76
+ app: dappAddressOrENS,
77
+ requester: requesterAddress,
78
+ })
79
+ .then((datasetOrderbook) => {
80
+ var _a;
81
+ const desiredPriceDataOrderbook = datasetOrderbook.orders.filter((order) => order.order.datasetprice <= vDataMaxPrice);
82
+ return (_a = desiredPriceDataOrderbook[0]) === null || _a === void 0 ? void 0 : _a.order; // may be undefined
83
+ }),
84
+ // Fetch dataset order for web3mail whitelist
85
+ iexec.orderbook
86
+ .fetchDatasetOrderbook(vDatasetAddress, {
87
+ app: vDappWhitelistAddress,
88
+ requester: requesterAddress,
89
+ })
90
+ .then((datasetOrderbook) => {
91
+ var _a;
92
+ const desiredPriceDataOrderbook = datasetOrderbook.orders.filter((order) => order.order.datasetprice <= vDataMaxPrice);
93
+ return (_a = desiredPriceDataOrderbook[0]) === null || _a === void 0 ? void 0 : _a.order; // may be undefined
94
+ }),
95
+ // Fetch app order
96
+ iexec.orderbook
97
+ .fetchAppOrderbook(dappAddressOrENS, {
98
+ minTag: ['tee', 'scone'],
99
+ maxTag: ['tee', 'scone'],
100
+ workerpool: workerpoolAddressOrEns,
101
+ })
102
+ .then((appOrderbook) => {
103
+ var _a;
104
+ const desiredPriceAppOrderbook = appOrderbook.orders.filter((order) => order.order.appprice <= vAppMaxPrice);
105
+ const desiredPriceAppOrder = (_a = desiredPriceAppOrderbook[0]) === null || _a === void 0 ? void 0 : _a.order;
106
+ if (!desiredPriceAppOrder) {
107
+ throw new Error('No App order found for the desired price');
108
+ }
109
+ return desiredPriceAppOrder;
110
+ }),
111
+ // Fetch workerpool order
112
+ iexec.orderbook
113
+ .fetchWorkerpoolOrderbook({
114
+ workerpool: workerpoolAddressOrEns,
115
+ app: dappAddressOrENS,
116
+ dataset: vDatasetAddress,
117
+ minTag: ['tee', 'scone'],
118
+ maxTag: ['tee', 'scone'],
119
+ category: 0,
120
+ })
121
+ .then((workerpoolOrderbook) => {
122
+ var _a;
123
+ const desiredPriceWorkerpoolOrderbook = workerpoolOrderbook.orders.filter((order) => order.order.workerpoolprice <= vWorkerpoolMaxPrice);
124
+ const randomIndex = Math.floor(Math.random() * desiredPriceWorkerpoolOrderbook.length);
125
+ const desiredPriceWorkerpoolOrder = (_a = desiredPriceWorkerpoolOrderbook[randomIndex]) === null || _a === void 0 ? void 0 : _a.order;
126
+ if (!desiredPriceWorkerpoolOrder) {
127
+ throw new Error('No Workerpool order found for the desired price');
128
+ }
129
+ return desiredPriceWorkerpoolOrder;
130
+ }),
131
+ ]);
132
+ const datasetorder = datasetorderForApp || datasetorderForWhitelist;
56
133
  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');
134
+ throw new Error('No Dataset order found for the desired price');
92
135
  }
93
136
  // Push requester secrets
94
137
  const requesterSecretId = generateSecureUniqueId(16);
@@ -98,7 +141,12 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
98
141
  .catch((e) => {
99
142
  throw new WorkflowError('Failed to encrypt email content', e);
100
143
  });
101
- const cid = yield ipfs.add(encryptedFile).catch((e) => {
144
+ const cid = yield ipfs
145
+ .add(encryptedFile, {
146
+ ipfsNode: ipfsNode,
147
+ ipfsGateway: ipfsGateway,
148
+ })
149
+ .catch((e) => {
102
150
  throw new WorkflowError('Failed to upload encrypted email content', e);
103
151
  });
104
152
  const multiaddr = `/ipfs/${cid}`;
@@ -110,26 +158,28 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
110
158
  emailContentEncryptionKey,
111
159
  }));
112
160
  const requestorderToSign = yield iexec.order.createRequestorder({
113
- app: WEB3_MAIL_DAPP_ADDRESS,
114
- category: desiredPriceWorkerpoolOrder.category,
161
+ app: vDappAddressOrENS,
162
+ category: workerpoolorder.category,
115
163
  dataset: vDatasetAddress,
116
- appmaxprice: desiredPriceAppOrder.appprice,
117
- workerpoolmaxprice: desiredPriceWorkerpoolOrder.workerpoolprice,
164
+ datasetmaxprice: datasetorder.datasetprice,
165
+ appmaxprice: apporder.appprice,
166
+ workerpoolmaxprice: workerpoolorder.workerpoolprice,
118
167
  tag: ['tee', 'scone'],
119
- workerpool: WORKERPOOL_ADDRESS,
168
+ workerpool: vWorkerpoolAddressOrEns,
120
169
  params: {
121
170
  iexec_developer_logger: true,
122
171
  iexec_secrets: {
123
172
  1: requesterSecretId,
124
173
  },
174
+ iexec_args: vLabel,
125
175
  },
126
176
  });
127
177
  const requestorder = yield iexec.order.signRequestorder(requestorderToSign);
128
178
  // Match orders and compute task ID
129
179
  const { dealid } = yield iexec.order.matchOrders({
130
- apporder: desiredPriceAppOrder,
180
+ apporder: apporder,
131
181
  datasetorder: datasetorder,
132
- workerpoolorder: desiredPriceWorkerpoolOrder,
182
+ workerpoolorder: workerpoolorder,
133
183
  requestorder: requestorder,
134
184
  });
135
185
  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,KAA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M,YAAY,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,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,19 +20,20 @@ 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
- taskId: Address;
36
+ taskId: string;
33
37
  };
34
38
  /**
35
39
  * Internal props for querying the subgraph
@@ -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.1",
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,21 @@
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
+ "buffer": "^6.0.3",
45
+ "ethers": "^6.8.1",
46
+ "graphql-request": "^6.1.0",
47
+ "iexec": "^8.7.0",
48
+ "kubo-rpc-client": "^3.0.1",
49
+ "yup": "^1.1.1"
50
+ },
40
51
  "devDependencies": {
41
- "@iexec/dataprotector": "^0.2.0",
52
+ "@iexec/dataprotector": "^0.4.1",
42
53
  "@jest/globals": "^29.7.0",
54
+ "@swc/core": "^1.3.96",
55
+ "@swc/jest": "^0.2.29",
43
56
  "@types/jest": "^29.5.4",
44
57
  "@typescript-eslint/eslint-plugin": "^6.7.5",
45
58
  "@typescript-eslint/parser": "^6.7.5",
@@ -49,20 +62,9 @@
49
62
  "eslint-plugin-import": "^2.28.1",
50
63
  "eslint-plugin-jest": "^27.4.2",
51
64
  "eslint-plugin-sonarjs": "^0.21.0",
52
- "jest": "^29.5.0",
65
+ "jest": "^29.7.0",
53
66
  "prettier": "^2.8.4",
54
- "ts-jest": "^29.1.0",
55
- "ts-loader": "^9.4.2",
56
67
  "typescript": "^4.9.5",
57
68
  "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
69
  }
68
70
  }
@@ -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,92 @@
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,
13
+ SendEmailResponse,
12
14
  } from './types.js';
13
15
  import { GraphQLClient } from 'graphql-request';
14
- import { DATAPROTECTOR_SUBGRAPH_ENDPOINT } from '../config/config.js';
16
+ import {
17
+ WEB3_MAIL_DAPP_ADDRESS,
18
+ IPFS_UPLOAD_URL,
19
+ DEFAULT_IPFS_GATEWAY,
20
+ DATAPROTECTOR_SUBGRAPH_ENDPOINT,
21
+ WHITELIST_SMART_CONTRACT_ADDRESS,
22
+ } from '../config/config.js';
15
23
 
16
24
  export class IExecWeb3mail {
17
- fetchMyContacts: (args?: FetchContactsParams) => Promise<Contact[]>;
18
- sendEmail: (args: SendEmailParams) => Promise<SendEmailResponse>;
25
+ private iexec: IExec;
26
+
27
+ private ipfsNode: string;
28
+
29
+ private ipfsGateway: string;
30
+
31
+ private dataProtectorSubgraph: string;
32
+
33
+ private dappAddressOrENS: AddressOrENS;
34
+
35
+ private dappWhitelistAddress: AddressOrENS;
36
+
37
+ private graphQLClient: GraphQLClient;
19
38
 
20
39
  constructor(
21
- ethProvider: providers.ExternalProvider | Web3SignerProvider,
22
- options?: {
23
- iexecOptions?: IExecConfigOptions;
24
- }
40
+ ethProvider: Eip1193Provider | Web3SignerProvider,
41
+ options?: Web3MailConfigOptions
25
42
  ) {
26
- let iexec: IExec;
27
- let graphQLClient: GraphQLClient;
28
43
  try {
29
- iexec = new IExec({ ethProvider }, options?.iexecOptions);
44
+ this.iexec = new IExec({ ethProvider }, options?.iexecOptions);
30
45
  } catch (e) {
31
46
  throw Error('Unsupported ethProvider');
32
47
  }
33
48
 
34
49
  try {
35
- graphQLClient = new GraphQLClient(DATAPROTECTOR_SUBGRAPH_ENDPOINT);
50
+ this.dataProtectorSubgraph =
51
+ options?.dataProtectorSubgraph || DATAPROTECTOR_SUBGRAPH_ENDPOINT;
52
+ this.graphQLClient = new GraphQLClient(this.dataProtectorSubgraph);
36
53
  } catch (e) {
37
54
  throw Error('Impossible to create GraphQLClient');
38
55
  }
39
56
 
40
- this.fetchMyContacts = (args?: FetchContactsParams) =>
41
- fetchMyContacts({ ...args, iexec, graphQLClient });
42
- this.sendEmail = (args: SendEmailParams) =>
43
- sendEmail({
44
- ...args,
45
- iexec,
46
- graphQLClient,
47
- });
57
+ this.dappAddressOrENS = options?.dappAddressOrENS || WEB3_MAIL_DAPP_ADDRESS;
58
+ this.ipfsNode = options?.ipfsNode || IPFS_UPLOAD_URL;
59
+ this.ipfsGateway = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY;
60
+ this.dappWhitelistAddress =
61
+ options?.dappWhitelistAddress || WHITELIST_SMART_CONTRACT_ADDRESS;
48
62
  }
63
+
64
+ fetchMyContacts = (): Promise<Contact[]> =>
65
+ fetchMyContacts({
66
+ iexec: this.iexec,
67
+ graphQLClient: this.graphQLClient,
68
+ dappAddressOrENS: this.dappAddressOrENS,
69
+ dappWhitelistAddress: this.dappWhitelistAddress,
70
+ });
71
+
72
+ fetchUserContacts(args?: FetchUserContactsParams): Promise<Contact[]> {
73
+ return fetchUserContacts({
74
+ ...args,
75
+ iexec: this.iexec,
76
+ graphQLClient: this.graphQLClient,
77
+ dappAddressOrENS: this.dappAddressOrENS,
78
+ dappWhitelistAddress: this.dappWhitelistAddress,
79
+ });
80
+ }
81
+
82
+ sendEmail = (args: SendEmailParams): Promise<SendEmailResponse> =>
83
+ sendEmail({
84
+ ...args,
85
+ iexec: this.iexec,
86
+ ipfsNode: this.ipfsNode,
87
+ ipfsGateway: this.ipfsGateway,
88
+ dappAddressOrENS: this.dappAddressOrENS,
89
+ dappWhitelistAddress: this.dappWhitelistAddress,
90
+ graphQLClient: this.graphQLClient,
91
+ });
49
92
  }