@iexec/web3mail 1.4.0 → 1.6.0-nightly-8729cd2
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.
- package/dist/config/config.js +9 -1
- package/dist/config/config.js.map +1 -1
- package/dist/utils/subgraphQuery.js +6 -2
- package/dist/utils/subgraphQuery.js.map +1 -1
- package/dist/web3mail/IExecWeb3mail.d.ts +4 -2
- package/dist/web3mail/IExecWeb3mail.js +15 -0
- package/dist/web3mail/IExecWeb3mail.js.map +1 -1
- package/dist/web3mail/fetchMyContacts.d.ts +1 -1
- package/dist/web3mail/fetchMyContacts.js +2 -1
- package/dist/web3mail/fetchMyContacts.js.map +1 -1
- package/dist/web3mail/fetchUserContacts.d.ts +1 -1
- package/dist/web3mail/fetchUserContacts.js +20 -3
- package/dist/web3mail/fetchUserContacts.js.map +1 -1
- package/dist/web3mail/internalTypes.d.ts +4 -0
- package/dist/web3mail/sendEmail.d.ts +4 -3
- package/dist/web3mail/sendEmail.js +129 -187
- package/dist/web3mail/sendEmail.js.map +1 -1
- package/dist/web3mail/types.d.ts +24 -3
- package/package.json +3 -3
- package/src/config/config.ts +10 -1
- package/src/utils/subgraphQuery.ts +18 -14
- package/src/web3mail/IExecWeb3mail.ts +25 -2
- package/src/web3mail/fetchMyContacts.ts +2 -0
- package/src/web3mail/fetchUserContacts.ts +30 -15
- package/src/web3mail/internalTypes.ts +3 -0
- package/src/web3mail/sendEmail.ts +145 -219
- package/src/web3mail/types.ts +25 -3
|
@@ -1,161 +1,53 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_DATA_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE, } from '../config/config.js';
|
|
3
3
|
import { handleIfProtocolError, WorkflowError } from '../utils/errors.js';
|
|
4
|
-
import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
5
4
|
import * as ipfs from '../utils/ipfs-service.js';
|
|
6
5
|
import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
|
|
7
|
-
import { addressOrEnsSchema,
|
|
8
|
-
|
|
9
|
-
export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), workerpoolAddressOrEns, 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, useVoucher = false, }) => {
|
|
10
|
-
const vDatasetAddress = addressOrEnsSchema()
|
|
11
|
-
.required()
|
|
12
|
-
.label('protectedData')
|
|
13
|
-
.validateSync(protectedData);
|
|
14
|
-
const vEmailSubject = emailSubjectSchema()
|
|
15
|
-
.required()
|
|
16
|
-
.label('emailSubject')
|
|
17
|
-
.validateSync(emailSubject);
|
|
18
|
-
const vEmailContent = emailContentSchema()
|
|
19
|
-
.required()
|
|
20
|
-
.label('emailContent')
|
|
21
|
-
.validateSync(emailContent);
|
|
22
|
-
const vContentType = contentTypeSchema()
|
|
23
|
-
.required()
|
|
24
|
-
.label('contentType')
|
|
25
|
-
.validateSync(contentType);
|
|
26
|
-
const vSenderName = senderNameSchema()
|
|
27
|
-
.label('senderName')
|
|
28
|
-
.validateSync(senderName);
|
|
29
|
-
const vLabel = labelSchema().label('label').validateSync(label);
|
|
30
|
-
const vWorkerpoolAddressOrEns = addressOrEnsSchema()
|
|
31
|
-
.required()
|
|
32
|
-
.label('WorkerpoolAddressOrEns')
|
|
33
|
-
.validateSync(workerpoolAddressOrEns);
|
|
34
|
-
const vDappAddressOrENS = addressOrEnsSchema()
|
|
35
|
-
.required()
|
|
36
|
-
.label('dappAddressOrENS')
|
|
37
|
-
.validateSync(dappAddressOrENS);
|
|
38
|
-
const vDappWhitelistAddress = addressSchema()
|
|
39
|
-
.required()
|
|
40
|
-
.label('dappWhitelistAddress')
|
|
41
|
-
.validateSync(dappWhitelistAddress);
|
|
42
|
-
const vDataMaxPrice = positiveNumberSchema()
|
|
43
|
-
.label('dataMaxPrice')
|
|
44
|
-
.validateSync(dataMaxPrice);
|
|
45
|
-
const vAppMaxPrice = positiveNumberSchema()
|
|
46
|
-
.label('appMaxPrice')
|
|
47
|
-
.validateSync(appMaxPrice);
|
|
48
|
-
const vWorkerpoolMaxPrice = positiveNumberSchema()
|
|
49
|
-
.label('workerpoolMaxPrice')
|
|
50
|
-
.validateSync(workerpoolMaxPrice);
|
|
51
|
-
const vUseVoucher = booleanSchema()
|
|
52
|
-
.label('useVoucher')
|
|
53
|
-
.validateSync(useVoucher);
|
|
54
|
-
// Check protected data schema through subgraph
|
|
55
|
-
const isValidProtectedData = await checkProtectedDataValidity(graphQLClient, vDatasetAddress);
|
|
56
|
-
if (!isValidProtectedData) {
|
|
57
|
-
throw new Error('This protected data does not contain "email:string" in its schema.');
|
|
58
|
-
}
|
|
59
|
-
const requesterAddress = await iexec.wallet.getAddress();
|
|
60
|
-
let userVoucher;
|
|
61
|
-
if (vUseVoucher) {
|
|
62
|
-
try {
|
|
63
|
-
userVoucher = await iexec.voucher.showUserVoucher(requesterAddress);
|
|
64
|
-
checkUserVoucher({ userVoucher });
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
if (err?.message?.startsWith('No Voucher found for address')) {
|
|
68
|
-
throw new Error('Oops, it seems your wallet is not associated with any voucher. Check on https://builder.iex.ec/');
|
|
69
|
-
}
|
|
70
|
-
throw err;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
6
|
+
import { addressOrEnsSchema, booleanSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, labelSchema, positiveNumberSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
|
|
7
|
+
export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), dataProtector = throwIfMissing(), workerpoolAddressOrEns = throwIfMissing(), dappAddressOrENS, 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, grantedAccess, maxProtectedDataPerTask, useVoucher = false, }) => {
|
|
73
8
|
try {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
dataset: vDatasetAddress,
|
|
117
|
-
requester: requesterAddress, // public orders + user specific orders
|
|
118
|
-
isRequesterStrict: useVoucher, // If voucher, we only want user specific orders
|
|
119
|
-
minTag: ['tee', 'scone'],
|
|
120
|
-
maxTag: ['tee', 'scone'],
|
|
121
|
-
category: 0,
|
|
122
|
-
}),
|
|
123
|
-
// for app whitelist
|
|
124
|
-
iexec.orderbook.fetchWorkerpoolOrderbook({
|
|
125
|
-
workerpool: workerpoolAddressOrEns,
|
|
126
|
-
app: vDappWhitelistAddress,
|
|
127
|
-
dataset: vDatasetAddress,
|
|
128
|
-
requester: requesterAddress, // public orders + user specific orders
|
|
129
|
-
isRequesterStrict: useVoucher, // If voucher, we only want user specific orders
|
|
130
|
-
minTag: ['tee', 'scone'],
|
|
131
|
-
maxTag: ['tee', 'scone'],
|
|
132
|
-
category: 0,
|
|
133
|
-
}),
|
|
134
|
-
]).then(([workerpoolOrderbookForApp, workerpoolOrderbookForAppWhitelist]) => {
|
|
135
|
-
const desiredPriceWorkerpoolOrder = filterWorkerpoolOrders({
|
|
136
|
-
workerpoolOrders: [
|
|
137
|
-
...workerpoolOrderbookForApp.orders,
|
|
138
|
-
...workerpoolOrderbookForAppWhitelist.orders,
|
|
139
|
-
],
|
|
140
|
-
workerpoolMaxPrice: vWorkerpoolMaxPrice,
|
|
141
|
-
useVoucher: vUseVoucher,
|
|
142
|
-
userVoucher,
|
|
143
|
-
});
|
|
144
|
-
if (!desiredPriceWorkerpoolOrder) {
|
|
145
|
-
throw new Error('No Workerpool order found for the desired price');
|
|
146
|
-
}
|
|
147
|
-
return desiredPriceWorkerpoolOrder;
|
|
148
|
-
}),
|
|
149
|
-
]);
|
|
150
|
-
if (!workerpoolorder) {
|
|
151
|
-
throw new Error('No Workerpool order found for the desired price');
|
|
152
|
-
}
|
|
153
|
-
const datasetorder = datasetorderForApp || datasetorderForWhitelist;
|
|
154
|
-
if (!datasetorder) {
|
|
155
|
-
throw new Error('No Dataset order found for the desired price');
|
|
156
|
-
}
|
|
157
|
-
// Push requester secrets
|
|
158
|
-
const requesterSecretId = generateSecureUniqueId(16);
|
|
9
|
+
const vUseVoucher = booleanSchema()
|
|
10
|
+
.label('useVoucher')
|
|
11
|
+
.validateSync(useVoucher);
|
|
12
|
+
const vWorkerpoolAddressOrEns = addressOrEnsSchema()
|
|
13
|
+
.required()
|
|
14
|
+
.label('WorkerpoolAddressOrEns')
|
|
15
|
+
.validateSync(workerpoolAddressOrEns);
|
|
16
|
+
const vSenderName = senderNameSchema()
|
|
17
|
+
.label('senderName')
|
|
18
|
+
.validateSync(senderName);
|
|
19
|
+
const vEmailSubject = emailSubjectSchema()
|
|
20
|
+
.required()
|
|
21
|
+
.label('emailSubject')
|
|
22
|
+
.validateSync(emailSubject);
|
|
23
|
+
const vEmailContent = emailContentSchema()
|
|
24
|
+
.required()
|
|
25
|
+
.label('emailContent')
|
|
26
|
+
.validateSync(emailContent);
|
|
27
|
+
const vContentType = contentTypeSchema()
|
|
28
|
+
.required()
|
|
29
|
+
.label('contentType')
|
|
30
|
+
.validateSync(contentType);
|
|
31
|
+
const vLabel = labelSchema().label('label').validateSync(label);
|
|
32
|
+
const vDappAddressOrENS = addressOrEnsSchema()
|
|
33
|
+
.required()
|
|
34
|
+
.label('dappAddressOrENS')
|
|
35
|
+
.validateSync(dappAddressOrENS);
|
|
36
|
+
// TODO: remove this once we have a way to pass appWhitelist to processProtectedData function
|
|
37
|
+
// const vDappWhitelistAddress = addressSchema()
|
|
38
|
+
// .required()
|
|
39
|
+
// .label('dappWhitelistAddress')
|
|
40
|
+
// .validateSync(dappWhitelistAddress);
|
|
41
|
+
const vDataMaxPrice = positiveNumberSchema()
|
|
42
|
+
.label('dataMaxPrice')
|
|
43
|
+
.validateSync(dataMaxPrice);
|
|
44
|
+
const vAppMaxPrice = positiveNumberSchema()
|
|
45
|
+
.label('appMaxPrice')
|
|
46
|
+
.validateSync(appMaxPrice);
|
|
47
|
+
const vWorkerpoolMaxPrice = positiveNumberSchema()
|
|
48
|
+
.label('workerpoolMaxPrice')
|
|
49
|
+
.validateSync(workerpoolMaxPrice);
|
|
50
|
+
// Encrypt email content
|
|
159
51
|
const emailContentEncryptionKey = iexec.dataset.generateEncryptionKey();
|
|
160
52
|
const encryptedFile = await iexec.dataset
|
|
161
53
|
.encrypt(Buffer.from(vEmailContent, 'utf8'), emailContentEncryptionKey)
|
|
@@ -165,10 +57,11 @@ export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = thro
|
|
|
165
57
|
errorCause: e,
|
|
166
58
|
});
|
|
167
59
|
});
|
|
60
|
+
// Push email message to IPFS
|
|
168
61
|
const cid = await ipfs
|
|
169
62
|
.add(encryptedFile, {
|
|
170
|
-
ipfsNode
|
|
171
|
-
ipfsGateway
|
|
63
|
+
ipfsNode,
|
|
64
|
+
ipfsGateway,
|
|
172
65
|
})
|
|
173
66
|
.catch((e) => {
|
|
174
67
|
throw new WorkflowError({
|
|
@@ -177,46 +70,95 @@ export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = thro
|
|
|
177
70
|
});
|
|
178
71
|
});
|
|
179
72
|
const multiaddr = `/ipfs/${cid}`;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
73
|
+
// Prepare secrets for the requester
|
|
74
|
+
// Use a positive integer as secret ID (required by iexec)
|
|
75
|
+
// Using "1" as a fixed ID for the requester secret
|
|
76
|
+
const requesterSecretId = 1;
|
|
77
|
+
const secrets = {
|
|
78
|
+
[requesterSecretId]: JSON.stringify({
|
|
79
|
+
senderName: vSenderName,
|
|
80
|
+
emailSubject: vEmailSubject,
|
|
81
|
+
emailContentMultiAddr: multiaddr,
|
|
82
|
+
contentType: vContentType,
|
|
83
|
+
emailContentEncryptionKey,
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
// Bulk processing
|
|
87
|
+
if (grantedAccess) {
|
|
88
|
+
const vMaxProtectedDataPerTask = positiveNumberSchema()
|
|
89
|
+
.label('maxProtectedDataPerTask')
|
|
90
|
+
.validateSync(maxProtectedDataPerTask);
|
|
91
|
+
const bulkRequest = await dataProtector.prepareBulkRequest({
|
|
92
|
+
app: vDappAddressOrENS,
|
|
93
|
+
appMaxPrice: vAppMaxPrice,
|
|
94
|
+
workerpoolMaxPrice: vWorkerpoolMaxPrice,
|
|
95
|
+
workerpool: vWorkerpoolAddressOrEns,
|
|
96
|
+
args: vLabel,
|
|
97
|
+
inputFiles: [],
|
|
98
|
+
secrets,
|
|
99
|
+
bulkOrders: grantedAccess,
|
|
100
|
+
maxProtectedDataPerTask: vMaxProtectedDataPerTask,
|
|
101
|
+
});
|
|
102
|
+
const processBulkRequestResponse = await dataProtector.processBulkRequest({
|
|
103
|
+
bulkRequest: bulkRequest.bulkRequest,
|
|
104
|
+
useVoucher: vUseVoucher,
|
|
105
|
+
workerpool: vWorkerpoolAddressOrEns,
|
|
106
|
+
});
|
|
107
|
+
return processBulkRequestResponse;
|
|
108
|
+
}
|
|
109
|
+
// Single processing mode - protectedData is required
|
|
110
|
+
const vDatasetAddress = addressOrEnsSchema()
|
|
111
|
+
.required()
|
|
112
|
+
.label('protectedData')
|
|
113
|
+
.validateSync(protectedData);
|
|
114
|
+
// Check protected data validity through subgraph
|
|
115
|
+
const isValidProtectedData = await checkProtectedDataValidity(graphQLClient, vDatasetAddress);
|
|
116
|
+
if (!isValidProtectedData) {
|
|
117
|
+
throw new Error('This protected data does not contain "email:string" in its schema.');
|
|
118
|
+
}
|
|
119
|
+
// Use processProtectedData from dataprotector
|
|
120
|
+
const result = await dataProtector.processProtectedData({
|
|
121
|
+
defaultWorkerpool: vWorkerpoolAddressOrEns,
|
|
122
|
+
protectedData: vDatasetAddress,
|
|
189
123
|
app: vDappAddressOrENS,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
workerpoolmaxprice: workerpoolorder.workerpoolprice,
|
|
195
|
-
tag: ['tee', 'scone'],
|
|
124
|
+
// userWhitelist: vDappWhitelistAddress, // Removed due to bug in dataprotector v2.0.0-beta.20
|
|
125
|
+
dataMaxPrice: vDataMaxPrice,
|
|
126
|
+
appMaxPrice: vAppMaxPrice,
|
|
127
|
+
workerpoolMaxPrice: vWorkerpoolMaxPrice,
|
|
196
128
|
workerpool: vWorkerpoolAddressOrEns,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
iexec_args: vLabel,
|
|
203
|
-
},
|
|
129
|
+
args: vLabel,
|
|
130
|
+
inputFiles: [],
|
|
131
|
+
secrets,
|
|
132
|
+
useVoucher: vUseVoucher,
|
|
133
|
+
waitForResult: false,
|
|
204
134
|
});
|
|
205
|
-
const requestorder = await iexec.order.signRequestorder(requestorderToSign);
|
|
206
|
-
// Match orders and compute task ID
|
|
207
|
-
const { dealid } = await iexec.order.matchOrders({
|
|
208
|
-
apporder: apporder,
|
|
209
|
-
datasetorder: datasetorder,
|
|
210
|
-
workerpoolorder: workerpoolorder,
|
|
211
|
-
requestorder: requestorder,
|
|
212
|
-
}, { useVoucher: vUseVoucher });
|
|
213
|
-
const taskId = await iexec.deal.computeTaskId(dealid, 0);
|
|
214
135
|
return {
|
|
215
|
-
taskId,
|
|
136
|
+
taskId: result.taskId,
|
|
216
137
|
};
|
|
217
138
|
}
|
|
218
139
|
catch (error) {
|
|
140
|
+
// Protocol error detected, re-throwing as-is
|
|
141
|
+
if (error?.isProtocolError === true) {
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
// Handle protocol errors - this will throw if it's an ApiCallError
|
|
145
|
+
// handleIfProtocolError transforms ApiCallError into a WorkflowError with isProtocolError=true
|
|
219
146
|
handleIfProtocolError(error);
|
|
147
|
+
// If we reach here, it's not a protocol error
|
|
148
|
+
// Check if it's a WorkflowError from processProtectedData by checking the message
|
|
149
|
+
const isProcessProtectedDataError = error instanceof Error &&
|
|
150
|
+
error.message === 'Failed to process protected data';
|
|
151
|
+
if (isProcessProtectedDataError) {
|
|
152
|
+
const cause = error?.cause;
|
|
153
|
+
// Return unwrapped cause (the actual Error object)
|
|
154
|
+
// error.cause should be an Error, but ensure it is
|
|
155
|
+
const unwrappedCause = cause instanceof Error ? cause : error;
|
|
156
|
+
throw new WorkflowError({
|
|
157
|
+
message: 'Failed to sendEmail',
|
|
158
|
+
errorCause: unwrappedCause,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// For all other errors
|
|
220
162
|
throw new WorkflowError({
|
|
221
163
|
message: 'Failed to sendEmail',
|
|
222
164
|
errorCause: error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,kCAAkC,GACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAchC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,EAC9B,aAAa,GAAG,cAAc,EAAE,EAChC,KAAK,GAAG,cAAc,EAAE,EACxB,aAAa,GAAG,cAAc,EAAE,EAChC,sBAAsB,GAAG,cAAc,EAAE,EACzC,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GAAG,oBAAoB,EAClC,KAAK,EACL,YAAY,GAAG,4BAA4B,EAC3C,WAAW,GAAG,2BAA2B,EACzC,kBAAkB,GAAG,kCAAkC,EACvD,UAAU,EACV,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,UAAU,GAAG,KAAK,GAQG,EAErB,EAAE;IACF,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,aAAa,EAAE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AAE,KAAK;SACrB,CAAC,CAAC;QAEH,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,8CAA8C;QAC9C,IAAK,KAAa,EAAE,eAAe,KAAK,IAAI,EAAE,CAAC;YAC7C,MAAM,KAAK,CAAC;QACd,CAAC;QAED,mEAAmE;QACnE,+FAA+F;QAC/F,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAE7B,8CAA8C;QAC9C,kFAAkF;QAClF,MAAM,2BAA2B,GAC/B,KAAK,YAAY,KAAK;YACtB,KAAK,CAAC,OAAO,KAAK,kCAAkC,CAAC;QAEvD,IAAI,2BAA2B,EAAE,CAAC;YAChC,MAAM,KAAK,GAAI,KAAa,EAAE,KAAK,CAAC;YACpC,mDAAmD;YACnD,mDAAmD;YACnD,MAAM,cAAc,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;YAC9D,MAAM,IAAI,aAAa,CAAC;gBACtB,OAAO,EAAE,qBAAqB;gBAC9B,UAAU,EAAE,cAAc;aAC3B,CAAC,CAAC;QACL,CAAC;QAED,uBAAuB;QACvB,MAAM,IAAI,aAAa,CAAC;YACtB,OAAO,EAAE,qBAAqB;YAC9B,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
package/dist/web3mail/types.d.ts
CHANGED
|
@@ -5,19 +5,39 @@ export type ENS = string;
|
|
|
5
5
|
export type AddressOrENS = Address | ENS;
|
|
6
6
|
export type Address = string;
|
|
7
7
|
export type TimeStamp = string;
|
|
8
|
+
export type GrantedAccess = {
|
|
9
|
+
dataset: string;
|
|
10
|
+
datasetprice: string;
|
|
11
|
+
volume: string;
|
|
12
|
+
tag: string;
|
|
13
|
+
apprestrict: string;
|
|
14
|
+
workerpoolrestrict: string;
|
|
15
|
+
requesterrestrict: string;
|
|
16
|
+
salt: string;
|
|
17
|
+
sign: string;
|
|
18
|
+
remainingAccess: number;
|
|
19
|
+
};
|
|
8
20
|
export type Contact = {
|
|
9
21
|
address: Address;
|
|
10
22
|
owner: Address;
|
|
11
23
|
accessGrantTimestamp: TimeStamp;
|
|
12
24
|
isUserStrict: boolean;
|
|
13
|
-
name
|
|
25
|
+
name?: string;
|
|
14
26
|
remainingAccess: number;
|
|
15
27
|
accessPrice: number;
|
|
28
|
+
grantedAccess: GrantedAccess;
|
|
16
29
|
};
|
|
17
30
|
export type SendEmailParams = {
|
|
18
31
|
emailSubject: string;
|
|
19
32
|
emailContent: string;
|
|
20
|
-
protectedData
|
|
33
|
+
protectedData?: Address;
|
|
34
|
+
/**
|
|
35
|
+
* Granted access to process.
|
|
36
|
+
* use prepareBulkRequest of dataprotector to create a bulk request.
|
|
37
|
+
* if not provided, the single message will be processed.
|
|
38
|
+
*/
|
|
39
|
+
grantedAccess?: GrantedAccess[];
|
|
40
|
+
maxProtectedDataPerTask?: number;
|
|
21
41
|
contentType?: string;
|
|
22
42
|
senderName?: string;
|
|
23
43
|
label?: string;
|
|
@@ -32,6 +52,7 @@ export type FetchMyContactsParams = {
|
|
|
32
52
|
* Get contacts for this specific user only
|
|
33
53
|
*/
|
|
34
54
|
isUserStrict?: boolean;
|
|
55
|
+
bulkOnly?: boolean;
|
|
35
56
|
};
|
|
36
57
|
export type FetchUserContactsParams = {
|
|
37
58
|
/**
|
|
@@ -39,7 +60,7 @@ export type FetchUserContactsParams = {
|
|
|
39
60
|
*/
|
|
40
61
|
userAddress: Address;
|
|
41
62
|
} & FetchMyContactsParams;
|
|
42
|
-
export type
|
|
63
|
+
export type SendEmailSingleResponse = {
|
|
43
64
|
taskId: string;
|
|
44
65
|
};
|
|
45
66
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iexec/web3mail",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-nightly-8729cd2",
|
|
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",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@ethersproject/bytes": "^5.7.0",
|
|
51
51
|
"@ethersproject/random": "^5.7.0",
|
|
52
|
+
"@iexec/dataprotector": "2.0.0-beta.20-feat-add-bulk-processing-support-094df1e",
|
|
52
53
|
"buffer": "^6.0.3",
|
|
53
54
|
"ethers": "^6.13.2",
|
|
54
55
|
"graphql-request": "^6.1.0",
|
|
55
|
-
"iexec": "
|
|
56
|
+
"iexec": "8.20.0-feat-bulk-processing-62e7c5f",
|
|
56
57
|
"kubo-rpc-client": "^4.1.1",
|
|
57
58
|
"yup": "^1.1.1"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@iexec/dataprotector": "^2.0.0-beta.18",
|
|
61
61
|
"@jest/globals": "^29.7.0",
|
|
62
62
|
"@swc/core": "^1.3.96",
|
|
63
63
|
"@swc/jest": "^0.2.29",
|
package/src/config/config.ts
CHANGED
|
@@ -38,7 +38,16 @@ const CHAIN_CONFIG: Record<number, ChainConfig> = {
|
|
|
38
38
|
ipfsGateway: 'https://ipfs-gateway.arbitrum-sepolia-testnet.iex.ec',
|
|
39
39
|
ipfsUploadUrl: 'https://ipfs-upload.arbitrum-sepolia-testnet.iex.ec',
|
|
40
40
|
whitelistSmartContract: '0x8d46d40840f1Aa2264F96184Ffadf04e5D573B9B',
|
|
41
|
-
|
|
41
|
+
},
|
|
42
|
+
42161: {
|
|
43
|
+
name: 'arbitrum-mainnet',
|
|
44
|
+
dappAddress: undefined, // ENS not supported on this network, address will be resolved from Compass
|
|
45
|
+
prodWorkerpoolAddress: '0x2C06263943180Cc024dAFfeEe15612DB6e5fD248',
|
|
46
|
+
dataProtectorSubgraph:
|
|
47
|
+
'https://thegraph.arbitrum.iex.ec/api/subgraphs/id/Ep5zs5zVr4tDiVuQJepUu51e5eWYJpka624X4DMBxe3u',
|
|
48
|
+
ipfsGateway: 'https://ipfs-gateway.arbitrum-mainnet.iex.ec',
|
|
49
|
+
ipfsUploadUrl: 'https://ipfs-upload.arbitrum-mainnet.iex.ec',
|
|
50
|
+
whitelistSmartContract: '0xD5054a18565c4a9E5c1aa3cEB53258bd59d4c78C',
|
|
42
51
|
},
|
|
43
52
|
};
|
|
44
53
|
|
|
@@ -71,20 +71,24 @@ export const getValidContact = async (
|
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
// Convert protectedData[] into Contact[] using the map for constant time lookups
|
|
74
|
-
return protectedDataList
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
return protectedDataList
|
|
75
|
+
.map(({ id, name }) => {
|
|
76
|
+
const contact = contactsMap.get(id);
|
|
77
|
+
if (contact) {
|
|
78
|
+
return {
|
|
79
|
+
address: id,
|
|
80
|
+
name: name,
|
|
81
|
+
remainingAccess: contact.remainingAccess,
|
|
82
|
+
accessPrice: contact.accessPrice,
|
|
83
|
+
owner: contact.owner,
|
|
84
|
+
accessGrantTimestamp: contact.accessGrantTimestamp,
|
|
85
|
+
isUserStrict: contact.isUserStrict,
|
|
86
|
+
grantedAccess: contact.grantedAccess,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
})
|
|
91
|
+
.filter((contact) => contact !== null && contact !== undefined);
|
|
88
92
|
} catch (error) {
|
|
89
93
|
throw new WorkflowError({
|
|
90
94
|
message: 'Failed to fetch subgraph',
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { AbstractProvider, AbstractSigner, Eip1193Provider } from 'ethers';
|
|
2
2
|
import { IExec } from 'iexec';
|
|
3
|
+
import {
|
|
4
|
+
IExecDataProtectorCore,
|
|
5
|
+
ProcessBulkRequestResponse,
|
|
6
|
+
} from '@iexec/dataprotector';
|
|
3
7
|
import { GraphQLClient } from 'graphql-request';
|
|
4
8
|
import { fetchUserContacts } from './fetchUserContacts.js';
|
|
5
9
|
import { fetchMyContacts } from './fetchMyContacts.js';
|
|
@@ -10,7 +14,7 @@ import {
|
|
|
10
14
|
SendEmailParams,
|
|
11
15
|
AddressOrENS,
|
|
12
16
|
Web3MailConfigOptions,
|
|
13
|
-
|
|
17
|
+
SendEmailSingleResponse,
|
|
14
18
|
Web3SignerProvider,
|
|
15
19
|
FetchMyContactsParams,
|
|
16
20
|
} from './types.js';
|
|
@@ -34,6 +38,7 @@ interface Web3mailResolvedConfig {
|
|
|
34
38
|
ipfsGateway: string;
|
|
35
39
|
defaultWorkerpool: string;
|
|
36
40
|
iexec: IExec;
|
|
41
|
+
dataProtector: IExecDataProtectorCore;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export class IExecWeb3mail {
|
|
@@ -51,6 +56,8 @@ export class IExecWeb3mail {
|
|
|
51
56
|
|
|
52
57
|
private iexec!: IExec;
|
|
53
58
|
|
|
59
|
+
private dataProtector!: IExecDataProtectorCore;
|
|
60
|
+
|
|
54
61
|
private initPromise: Promise<void> | null = null;
|
|
55
62
|
|
|
56
63
|
private ethProvider: EthersCompatibleProvider;
|
|
@@ -75,6 +82,7 @@ export class IExecWeb3mail {
|
|
|
75
82
|
this.ipfsGateway = config.ipfsGateway;
|
|
76
83
|
this.defaultWorkerpool = config.defaultWorkerpool;
|
|
77
84
|
this.iexec = config.iexec;
|
|
85
|
+
this.dataProtector = config.dataProtector;
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
88
|
return this.initPromise;
|
|
@@ -105,7 +113,9 @@ export class IExecWeb3mail {
|
|
|
105
113
|
});
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
async sendEmail(
|
|
116
|
+
async sendEmail(
|
|
117
|
+
args: SendEmailParams
|
|
118
|
+
): Promise<ProcessBulkRequestResponse | SendEmailSingleResponse> {
|
|
109
119
|
await this.init();
|
|
110
120
|
await isValidProvider(this.iexec);
|
|
111
121
|
return sendEmail({
|
|
@@ -113,6 +123,7 @@ export class IExecWeb3mail {
|
|
|
113
123
|
workerpoolAddressOrEns:
|
|
114
124
|
args.workerpoolAddressOrEns || this.defaultWorkerpool,
|
|
115
125
|
iexec: this.iexec,
|
|
126
|
+
dataProtector: this.dataProtector,
|
|
116
127
|
ipfsNode: this.ipfsNode,
|
|
117
128
|
ipfsGateway: this.ipfsGateway,
|
|
118
129
|
dappAddressOrENS: this.dappAddressOrENS,
|
|
@@ -184,6 +195,17 @@ export class IExecWeb3mail {
|
|
|
184
195
|
throw new Error(`Failed to create GraphQLClient: ${error.message}`);
|
|
185
196
|
}
|
|
186
197
|
|
|
198
|
+
const dataProtector = new IExecDataProtectorCore(this.ethProvider, {
|
|
199
|
+
iexecOptions: {
|
|
200
|
+
ipfsGatewayURL: ipfsGateway,
|
|
201
|
+
...this.options?.iexecOptions,
|
|
202
|
+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
|
|
203
|
+
},
|
|
204
|
+
ipfsGateway,
|
|
205
|
+
ipfsNode,
|
|
206
|
+
subgraphUrl,
|
|
207
|
+
});
|
|
208
|
+
|
|
187
209
|
return {
|
|
188
210
|
dappAddressOrENS,
|
|
189
211
|
dappWhitelistAddress: dappWhitelistAddress.toLowerCase(),
|
|
@@ -192,6 +214,7 @@ export class IExecWeb3mail {
|
|
|
192
214
|
ipfsNode,
|
|
193
215
|
ipfsGateway,
|
|
194
216
|
iexec,
|
|
217
|
+
dataProtector,
|
|
195
218
|
};
|
|
196
219
|
}
|
|
197
220
|
}
|
|
@@ -16,6 +16,7 @@ export const fetchMyContacts = async ({
|
|
|
16
16
|
dappAddressOrENS = throwIfMissing(),
|
|
17
17
|
dappWhitelistAddress = throwIfMissing(),
|
|
18
18
|
isUserStrict = false,
|
|
19
|
+
bulkOnly = false,
|
|
19
20
|
}: IExecConsumer &
|
|
20
21
|
SubgraphConsumer &
|
|
21
22
|
DappAddressConsumer &
|
|
@@ -33,5 +34,6 @@ export const fetchMyContacts = async ({
|
|
|
33
34
|
dappWhitelistAddress,
|
|
34
35
|
userAddress,
|
|
35
36
|
isUserStrict: vIsUserStrict,
|
|
37
|
+
bulkOnly,
|
|
36
38
|
});
|
|
37
39
|
};
|