@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.
- package/dist/config/config.d.ts +3 -1
- package/dist/config/config.js +3 -1
- package/dist/config/config.js.map +1 -1
- package/dist/utils/errors.d.ts +1 -2
- package/dist/utils/errors.js +1 -2
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/ipfs-service.d.ts +7 -5
- package/dist/utils/ipfs-service.js +3 -3
- package/dist/utils/ipfs-service.js.map +1 -1
- package/dist/utils/subgraphQuery.js +2 -3
- package/dist/utils/subgraphQuery.js.map +1 -1
- package/dist/utils/validators.d.ts +4 -0
- package/dist/utils/validators.js +9 -4
- package/dist/utils/validators.js.map +1 -1
- package/dist/web3mail/IExecWeb3mail.d.ts +12 -7
- package/dist/web3mail/IExecWeb3mail.js +21 -8
- package/dist/web3mail/IExecWeb3mail.js.map +1 -1
- package/dist/web3mail/fetchMyContacts.d.ts +2 -2
- package/dist/web3mail/fetchMyContacts.js +8 -39
- package/dist/web3mail/fetchMyContacts.js.map +1 -1
- package/dist/web3mail/fetchUserContacts.d.ts +2 -0
- package/dist/web3mail/fetchUserContacts.js +83 -0
- package/dist/web3mail/fetchUserContacts.js.map +1 -0
- package/dist/web3mail/sendEmail.d.ts +2 -2
- package/dist/web3mail/sendEmail.js +104 -54
- package/dist/web3mail/sendEmail.js.map +1 -1
- package/dist/web3mail/types.d.ts +59 -8
- package/package.json +18 -16
- package/src/config/config.ts +3 -1
- package/src/utils/errors.ts +2 -3
- package/src/utils/ipfs-service.ts +20 -4
- package/src/utils/subgraphQuery.ts +2 -4
- package/src/utils/validators.ts +20 -6
- package/src/web3mail/IExecWeb3mail.ts +66 -23
- package/src/web3mail/fetchMyContacts.ts +15 -58
- package/src/web3mail/fetchUserContacts.ts +106 -0
- package/src/web3mail/sendEmail.ts +139 -73
- package/src/web3mail/types.ts +73 -8
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WEB3_MAIL_DAPP_ADDRESS,
|
|
3
|
-
WHITELIST_SMART_CONTRACT_ADDRESS,
|
|
4
|
-
} from '../config/config.js';
|
|
5
1
|
import { WorkflowError } from '../utils/errors.js';
|
|
6
|
-
import { autoPaginateRequest } from '../utils/paginate.js';
|
|
7
|
-
import { getValidContact } from '../utils/subgraphQuery.js';
|
|
8
2
|
import { throwIfMissing } from '../utils/validators.js';
|
|
3
|
+
import { fetchUserContacts } from './fetchUserContacts.js';
|
|
9
4
|
import {
|
|
10
5
|
Contact,
|
|
11
|
-
|
|
6
|
+
DappAddressConsumer,
|
|
7
|
+
DappWhitelistAddressConsumer,
|
|
12
8
|
IExecConsumer,
|
|
13
9
|
SubgraphConsumer,
|
|
14
10
|
} from './types.js';
|
|
@@ -16,60 +12,21 @@ import {
|
|
|
16
12
|
export const fetchMyContacts = async ({
|
|
17
13
|
graphQLClient = throwIfMissing(),
|
|
18
14
|
iexec = throwIfMissing(),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}: IExecConsumer &
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
dappAddressOrENS = throwIfMissing(),
|
|
16
|
+
dappWhitelistAddress = throwIfMissing(),
|
|
17
|
+
}: IExecConsumer &
|
|
18
|
+
SubgraphConsumer &
|
|
19
|
+
DappAddressConsumer &
|
|
20
|
+
DappWhitelistAddressConsumer): Promise<Contact[]> => {
|
|
24
21
|
try {
|
|
25
22
|
const userAddress = await iexec.wallet.getAddress();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
const datasetOrderbookAuthorizedByENS =
|
|
34
|
-
await iexec.orderbook.fetchDatasetOrderbook('any', {
|
|
35
|
-
app: WEB3_MAIL_DAPP_ADDRESS,
|
|
36
|
-
requester: userAddress,
|
|
37
|
-
page,
|
|
38
|
-
pageSize,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const { orders: ensOrders } = await autoPaginateRequest({
|
|
42
|
-
request: datasetOrderbookAuthorizedByENS,
|
|
43
|
-
});
|
|
44
|
-
const { orders: scOrders } = await autoPaginateRequest({
|
|
45
|
-
request: datasetOrderbookAuthorizedBySC,
|
|
23
|
+
return await fetchUserContacts({
|
|
24
|
+
iexec,
|
|
25
|
+
graphQLClient,
|
|
26
|
+
dappAddressOrENS,
|
|
27
|
+
dappWhitelistAddress,
|
|
28
|
+
userAddress,
|
|
46
29
|
});
|
|
47
|
-
|
|
48
|
-
const orders = ensOrders.concat(scOrders);
|
|
49
|
-
const myContacts: Contact[] = [];
|
|
50
|
-
const web3DappResolvedAddress = await iexec.ens.resolveName(
|
|
51
|
-
WEB3_MAIL_DAPP_ADDRESS
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
orders.forEach((order) => {
|
|
55
|
-
if (
|
|
56
|
-
order.order.apprestrict.toLowerCase() ===
|
|
57
|
-
web3DappResolvedAddress.toLowerCase() ||
|
|
58
|
-
order.order.apprestrict.toLowerCase() ===
|
|
59
|
-
WHITELIST_SMART_CONTRACT_ADDRESS.toLowerCase()
|
|
60
|
-
) {
|
|
61
|
-
const contact = {
|
|
62
|
-
address: order.order.dataset.toLowerCase(),
|
|
63
|
-
owner: order.signer.toLowerCase(),
|
|
64
|
-
accessGrantTimestamp: order.publicationTimestamp,
|
|
65
|
-
};
|
|
66
|
-
myContacts.push(contact);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const validContacts = await getValidContact(graphQLClient, myContacts);
|
|
71
|
-
|
|
72
|
-
return validContacts;
|
|
73
30
|
} catch (error) {
|
|
74
31
|
throw new WorkflowError(
|
|
75
32
|
`Failed to fetch my contacts: ${error.message}`,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { ANY_DATASET_ADDRESS } from '../config/config.js';
|
|
2
|
+
import { WorkflowError } from '../utils/errors.js';
|
|
3
|
+
import { autoPaginateRequest } from '../utils/paginate.js';
|
|
4
|
+
import { getValidContact } from '../utils/subgraphQuery.js';
|
|
5
|
+
import {
|
|
6
|
+
addressOrEnsSchema,
|
|
7
|
+
addressSchema,
|
|
8
|
+
isEnsTest,
|
|
9
|
+
throwIfMissing,
|
|
10
|
+
} from '../utils/validators.js';
|
|
11
|
+
import {
|
|
12
|
+
Contact,
|
|
13
|
+
DappAddressConsumer,
|
|
14
|
+
DappWhitelistAddressConsumer,
|
|
15
|
+
FetchUserContactsParams,
|
|
16
|
+
IExecConsumer,
|
|
17
|
+
SubgraphConsumer,
|
|
18
|
+
} from './types.js';
|
|
19
|
+
|
|
20
|
+
export const fetchUserContacts = async ({
|
|
21
|
+
graphQLClient = throwIfMissing(),
|
|
22
|
+
iexec = throwIfMissing(),
|
|
23
|
+
dappAddressOrENS = throwIfMissing(),
|
|
24
|
+
dappWhitelistAddress = throwIfMissing(),
|
|
25
|
+
userAddress,
|
|
26
|
+
}: IExecConsumer &
|
|
27
|
+
SubgraphConsumer &
|
|
28
|
+
DappAddressConsumer &
|
|
29
|
+
DappWhitelistAddressConsumer &
|
|
30
|
+
FetchUserContactsParams): Promise<Contact[]> => {
|
|
31
|
+
try {
|
|
32
|
+
const vDappAddressOrENS = addressOrEnsSchema()
|
|
33
|
+
.required()
|
|
34
|
+
.label('dappAddressOrENS')
|
|
35
|
+
.validateSync(dappAddressOrENS);
|
|
36
|
+
const vDappWhitelistAddress = addressSchema()
|
|
37
|
+
.required()
|
|
38
|
+
.label('dappWhitelistAddress')
|
|
39
|
+
.validateSync(dappWhitelistAddress);
|
|
40
|
+
const vUserAddress = addressOrEnsSchema()
|
|
41
|
+
.required()
|
|
42
|
+
.label('userAddress')
|
|
43
|
+
.validateSync(userAddress);
|
|
44
|
+
|
|
45
|
+
const [dappOrders, whitelistOrders] = await Promise.all([
|
|
46
|
+
fetchAllOrdersByApp({
|
|
47
|
+
iexec,
|
|
48
|
+
userAddress: vUserAddress,
|
|
49
|
+
appAddress: vDappAddressOrENS,
|
|
50
|
+
}),
|
|
51
|
+
fetchAllOrdersByApp({
|
|
52
|
+
iexec,
|
|
53
|
+
userAddress: vUserAddress,
|
|
54
|
+
appAddress: vDappWhitelistAddress,
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
const orders = dappOrders.concat(whitelistOrders);
|
|
59
|
+
const myContacts: Contact[] = [];
|
|
60
|
+
let web3DappResolvedAddress = vDappAddressOrENS;
|
|
61
|
+
if (isEnsTest(vDappAddressOrENS)) {
|
|
62
|
+
web3DappResolvedAddress = await iexec.ens.resolveName(vDappAddressOrENS);
|
|
63
|
+
}
|
|
64
|
+
orders.forEach((order) => {
|
|
65
|
+
if (
|
|
66
|
+
order.order.apprestrict.toLowerCase() ===
|
|
67
|
+
web3DappResolvedAddress.toLowerCase() ||
|
|
68
|
+
order.order.apprestrict.toLowerCase() ===
|
|
69
|
+
vDappWhitelistAddress.toLowerCase()
|
|
70
|
+
) {
|
|
71
|
+
const contact = {
|
|
72
|
+
address: order.order.dataset.toLowerCase(),
|
|
73
|
+
owner: order.signer.toLowerCase(),
|
|
74
|
+
accessGrantTimestamp: order.publicationTimestamp,
|
|
75
|
+
};
|
|
76
|
+
myContacts.push(contact);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
//getValidContact function remove duplicated contacts for the same protectedData address,
|
|
81
|
+
//keeping the most recent one
|
|
82
|
+
return await getValidContact(graphQLClient, myContacts);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new WorkflowError(
|
|
85
|
+
`Failed to fetch my contacts: ${error.message}`,
|
|
86
|
+
error
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
async function fetchAllOrdersByApp({ iexec, userAddress, appAddress }) {
|
|
92
|
+
const ordersFirstPage = iexec.orderbook.fetchDatasetOrderbook(
|
|
93
|
+
ANY_DATASET_ADDRESS,
|
|
94
|
+
{
|
|
95
|
+
app: appAddress,
|
|
96
|
+
requester: userAddress,
|
|
97
|
+
isAppStrict: true,
|
|
98
|
+
// Use maxPageSize here to avoid too many round-trips (we want everything anyway)
|
|
99
|
+
pageSize: 1000,
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
const { orders: allOrders } = await autoPaginateRequest({
|
|
103
|
+
request: ordersFirstPage,
|
|
104
|
+
});
|
|
105
|
+
return allOrders;
|
|
106
|
+
}
|
|
@@ -1,39 +1,60 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
import {
|
|
2
3
|
DEFAULT_CONTENT_TYPE,
|
|
3
4
|
MAX_DESIRED_APP_ORDER_PRICE,
|
|
5
|
+
MAX_DESIRED_DATA_ORDER_PRICE,
|
|
4
6
|
MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
|
|
5
|
-
|
|
6
|
-
WORKERPOOL_ADDRESS,
|
|
7
|
+
PROD_WORKERPOOL_ADDRESS,
|
|
7
8
|
} from '../config/config.js';
|
|
8
9
|
import { WorkflowError } from '../utils/errors.js';
|
|
9
10
|
import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
11
|
+
import * as ipfs from '../utils/ipfs-service.js';
|
|
10
12
|
import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
|
|
11
13
|
import {
|
|
12
14
|
addressOrEnsSchema,
|
|
15
|
+
addressSchema,
|
|
13
16
|
contentTypeSchema,
|
|
14
17
|
emailContentSchema,
|
|
15
18
|
emailSubjectSchema,
|
|
19
|
+
labelSchema,
|
|
20
|
+
positiveNumberSchema,
|
|
16
21
|
senderNameSchema,
|
|
17
22
|
throwIfMissing,
|
|
18
23
|
} from '../utils/validators.js';
|
|
19
24
|
import {
|
|
25
|
+
DappAddressConsumer,
|
|
26
|
+
DappWhitelistAddressConsumer,
|
|
20
27
|
IExecConsumer,
|
|
28
|
+
IpfsGatewayConfigConsumer,
|
|
29
|
+
IpfsNodeConfigConsumer,
|
|
21
30
|
SendEmailParams,
|
|
22
31
|
SendEmailResponse,
|
|
23
32
|
SubgraphConsumer,
|
|
24
33
|
} from './types.js';
|
|
25
|
-
import * as ipfs from './../utils/ipfs-service.js';
|
|
26
34
|
|
|
27
35
|
export const sendEmail = async ({
|
|
28
36
|
graphQLClient = throwIfMissing(),
|
|
29
37
|
iexec = throwIfMissing(),
|
|
38
|
+
workerpoolAddressOrEns = PROD_WORKERPOOL_ADDRESS,
|
|
39
|
+
dappAddressOrENS,
|
|
40
|
+
dappWhitelistAddress,
|
|
41
|
+
ipfsNode,
|
|
42
|
+
ipfsGateway,
|
|
30
43
|
emailSubject,
|
|
31
44
|
emailContent,
|
|
32
45
|
contentType = DEFAULT_CONTENT_TYPE,
|
|
46
|
+
label,
|
|
47
|
+
dataMaxPrice = MAX_DESIRED_DATA_ORDER_PRICE,
|
|
48
|
+
appMaxPrice = MAX_DESIRED_APP_ORDER_PRICE,
|
|
49
|
+
workerpoolMaxPrice = MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
|
|
33
50
|
senderName,
|
|
34
51
|
protectedData,
|
|
35
52
|
}: IExecConsumer &
|
|
36
53
|
SubgraphConsumer &
|
|
54
|
+
DappAddressConsumer &
|
|
55
|
+
DappWhitelistAddressConsumer &
|
|
56
|
+
IpfsNodeConfigConsumer &
|
|
57
|
+
IpfsGatewayConfigConsumer &
|
|
37
58
|
SendEmailParams): Promise<SendEmailResponse> => {
|
|
38
59
|
try {
|
|
39
60
|
const vDatasetAddress = addressOrEnsSchema()
|
|
@@ -55,6 +76,28 @@ export const sendEmail = async ({
|
|
|
55
76
|
const vSenderName = senderNameSchema()
|
|
56
77
|
.label('senderName')
|
|
57
78
|
.validateSync(senderName);
|
|
79
|
+
const vLabel = labelSchema().label('label').validateSync(label);
|
|
80
|
+
const vWorkerpoolAddressOrEns = addressOrEnsSchema()
|
|
81
|
+
.required()
|
|
82
|
+
.label('WorkerpoolAddressOrEns')
|
|
83
|
+
.validateSync(workerpoolAddressOrEns);
|
|
84
|
+
const vDappAddressOrENS = addressOrEnsSchema()
|
|
85
|
+
.required()
|
|
86
|
+
.label('dappAddressOrENS')
|
|
87
|
+
.validateSync(dappAddressOrENS);
|
|
88
|
+
const vDappWhitelistAddress = addressSchema()
|
|
89
|
+
.required()
|
|
90
|
+
.label('dappWhitelistAddress')
|
|
91
|
+
.validateSync(dappWhitelistAddress);
|
|
92
|
+
const vDataMaxPrice = positiveNumberSchema()
|
|
93
|
+
.label('dataMaxPrice')
|
|
94
|
+
.validateSync(dataMaxPrice);
|
|
95
|
+
const vAppMaxPrice = positiveNumberSchema()
|
|
96
|
+
.label('appMaxPrice')
|
|
97
|
+
.validateSync(appMaxPrice);
|
|
98
|
+
const vWorkerpoolMaxPrice = positiveNumberSchema()
|
|
99
|
+
.label('workerpoolMaxPrice')
|
|
100
|
+
.validateSync(workerpoolMaxPrice);
|
|
58
101
|
|
|
59
102
|
// Check protected data validity through subgraph
|
|
60
103
|
const isValidProtectedData = await checkProtectedDataValidity(
|
|
@@ -75,67 +118,83 @@ export const sendEmail = async ({
|
|
|
75
118
|
await iexec.storage.pushStorageToken(token);
|
|
76
119
|
}
|
|
77
120
|
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
const [
|
|
122
|
+
datasetorderForApp,
|
|
123
|
+
datasetorderForWhitelist,
|
|
124
|
+
apporder,
|
|
125
|
+
workerpoolorder,
|
|
126
|
+
] = await Promise.all([
|
|
127
|
+
// Fetch dataset order for web3mail app
|
|
128
|
+
iexec.orderbook
|
|
129
|
+
.fetchDatasetOrderbook(vDatasetAddress, {
|
|
130
|
+
app: dappAddressOrENS,
|
|
131
|
+
requester: requesterAddress,
|
|
132
|
+
})
|
|
133
|
+
.then((datasetOrderbook) => {
|
|
134
|
+
const desiredPriceDataOrderbook = datasetOrderbook.orders.filter(
|
|
135
|
+
(order) => order.order.datasetprice <= vDataMaxPrice
|
|
136
|
+
);
|
|
137
|
+
return desiredPriceDataOrderbook[0]?.order; // may be undefined
|
|
138
|
+
}),
|
|
139
|
+
// Fetch dataset order for web3mail whitelist
|
|
140
|
+
iexec.orderbook
|
|
141
|
+
.fetchDatasetOrderbook(vDatasetAddress, {
|
|
142
|
+
app: vDappWhitelistAddress,
|
|
143
|
+
requester: requesterAddress,
|
|
144
|
+
})
|
|
145
|
+
.then((datasetOrderbook) => {
|
|
146
|
+
const desiredPriceDataOrderbook = datasetOrderbook.orders.filter(
|
|
147
|
+
(order) => order.order.datasetprice <= vDataMaxPrice
|
|
148
|
+
);
|
|
149
|
+
return desiredPriceDataOrderbook[0]?.order; // may be undefined
|
|
150
|
+
}),
|
|
151
|
+
// Fetch app order
|
|
152
|
+
iexec.orderbook
|
|
153
|
+
.fetchAppOrderbook(dappAddressOrENS, {
|
|
154
|
+
minTag: ['tee', 'scone'],
|
|
155
|
+
maxTag: ['tee', 'scone'],
|
|
156
|
+
workerpool: workerpoolAddressOrEns,
|
|
157
|
+
})
|
|
158
|
+
.then((appOrderbook) => {
|
|
159
|
+
const desiredPriceAppOrderbook = appOrderbook.orders.filter(
|
|
160
|
+
(order) => order.order.appprice <= vAppMaxPrice
|
|
161
|
+
);
|
|
162
|
+
const desiredPriceAppOrder = desiredPriceAppOrderbook[0]?.order;
|
|
163
|
+
if (!desiredPriceAppOrder) {
|
|
164
|
+
throw new Error('No App order found for the desired price');
|
|
165
|
+
}
|
|
166
|
+
return desiredPriceAppOrder;
|
|
167
|
+
}),
|
|
168
|
+
// Fetch workerpool order
|
|
169
|
+
iexec.orderbook
|
|
170
|
+
.fetchWorkerpoolOrderbook({
|
|
171
|
+
workerpool: workerpoolAddressOrEns,
|
|
172
|
+
app: dappAddressOrENS,
|
|
173
|
+
dataset: vDatasetAddress,
|
|
174
|
+
minTag: ['tee', 'scone'],
|
|
175
|
+
maxTag: ['tee', 'scone'],
|
|
176
|
+
category: 0,
|
|
177
|
+
})
|
|
178
|
+
.then((workerpoolOrderbook) => {
|
|
179
|
+
const desiredPriceWorkerpoolOrderbook =
|
|
180
|
+
workerpoolOrderbook.orders.filter(
|
|
181
|
+
(order) => order.order.workerpoolprice <= vWorkerpoolMaxPrice
|
|
182
|
+
);
|
|
183
|
+
const randomIndex = Math.floor(
|
|
184
|
+
Math.random() * desiredPriceWorkerpoolOrderbook.length
|
|
185
|
+
);
|
|
186
|
+
const desiredPriceWorkerpoolOrder =
|
|
187
|
+
desiredPriceWorkerpoolOrderbook[randomIndex]?.order;
|
|
188
|
+
if (!desiredPriceWorkerpoolOrder) {
|
|
189
|
+
throw new Error('No Workerpool order found for the desired price');
|
|
190
|
+
}
|
|
191
|
+
return desiredPriceWorkerpoolOrder;
|
|
192
|
+
}),
|
|
193
|
+
]);
|
|
127
194
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
);
|
|
132
|
-
const randomIndex = Math.floor(
|
|
133
|
-
Math.random() * desiredPriceWorkerpoolOrderbook.length
|
|
134
|
-
);
|
|
135
|
-
const desiredPriceWorkerpoolOrder =
|
|
136
|
-
desiredPriceWorkerpoolOrderbook[randomIndex]?.order;
|
|
137
|
-
if (!desiredPriceWorkerpoolOrder) {
|
|
138
|
-
throw new Error('No Workerpool order found for the desired price');
|
|
195
|
+
const datasetorder = datasetorderForApp || datasetorderForWhitelist;
|
|
196
|
+
if (!datasetorder) {
|
|
197
|
+
throw new Error('No Dataset order found for the desired price');
|
|
139
198
|
}
|
|
140
199
|
|
|
141
200
|
// Push requester secrets
|
|
@@ -146,9 +205,14 @@ export const sendEmail = async ({
|
|
|
146
205
|
.catch((e) => {
|
|
147
206
|
throw new WorkflowError('Failed to encrypt email content', e);
|
|
148
207
|
});
|
|
149
|
-
const cid = await ipfs
|
|
150
|
-
|
|
151
|
-
|
|
208
|
+
const cid = await ipfs
|
|
209
|
+
.add(encryptedFile, {
|
|
210
|
+
ipfsNode: ipfsNode,
|
|
211
|
+
ipfsGateway: ipfsGateway,
|
|
212
|
+
})
|
|
213
|
+
.catch((e) => {
|
|
214
|
+
throw new WorkflowError('Failed to upload encrypted email content', e);
|
|
215
|
+
});
|
|
152
216
|
const multiaddr = `/ipfs/${cid}`;
|
|
153
217
|
|
|
154
218
|
await iexec.secrets.pushRequesterSecret(
|
|
@@ -163,27 +227,29 @@ export const sendEmail = async ({
|
|
|
163
227
|
);
|
|
164
228
|
|
|
165
229
|
const requestorderToSign = await iexec.order.createRequestorder({
|
|
166
|
-
app:
|
|
167
|
-
category:
|
|
230
|
+
app: vDappAddressOrENS,
|
|
231
|
+
category: workerpoolorder.category,
|
|
168
232
|
dataset: vDatasetAddress,
|
|
169
|
-
|
|
170
|
-
|
|
233
|
+
datasetmaxprice: datasetorder.datasetprice,
|
|
234
|
+
appmaxprice: apporder.appprice,
|
|
235
|
+
workerpoolmaxprice: workerpoolorder.workerpoolprice,
|
|
171
236
|
tag: ['tee', 'scone'],
|
|
172
|
-
workerpool:
|
|
237
|
+
workerpool: vWorkerpoolAddressOrEns,
|
|
173
238
|
params: {
|
|
174
239
|
iexec_developer_logger: true,
|
|
175
240
|
iexec_secrets: {
|
|
176
241
|
1: requesterSecretId,
|
|
177
242
|
},
|
|
243
|
+
iexec_args: vLabel,
|
|
178
244
|
},
|
|
179
245
|
});
|
|
180
246
|
const requestorder = await iexec.order.signRequestorder(requestorderToSign);
|
|
181
247
|
|
|
182
248
|
// Match orders and compute task ID
|
|
183
249
|
const { dealid } = await iexec.order.matchOrders({
|
|
184
|
-
apporder:
|
|
250
|
+
apporder: apporder,
|
|
185
251
|
datasetorder: datasetorder,
|
|
186
|
-
workerpoolorder:
|
|
252
|
+
workerpoolorder: workerpoolorder,
|
|
187
253
|
requestorder: requestorder,
|
|
188
254
|
});
|
|
189
255
|
const taskId = await iexec.deal.computeTaskId(dealid, 0);
|
package/src/web3mail/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GraphQLClient } from 'graphql-request';
|
|
2
2
|
import { EnhancedWallet, IExec } from 'iexec';
|
|
3
|
+
import { IExecConfigOptions } from 'iexec/IExecConfig';
|
|
3
4
|
|
|
4
5
|
export type Web3SignerProvider = EnhancedWallet;
|
|
5
6
|
|
|
@@ -7,6 +8,10 @@ export type IExecConsumer = {
|
|
|
7
8
|
iexec: IExec;
|
|
8
9
|
};
|
|
9
10
|
|
|
11
|
+
export type ENS = string;
|
|
12
|
+
|
|
13
|
+
export type AddressOrENS = Address | ENS;
|
|
14
|
+
|
|
10
15
|
export type Address = string;
|
|
11
16
|
|
|
12
17
|
export type TimeStamp = string;
|
|
@@ -16,26 +21,29 @@ export type Contact = {
|
|
|
16
21
|
owner: Address;
|
|
17
22
|
accessGrantTimestamp: TimeStamp;
|
|
18
23
|
};
|
|
24
|
+
|
|
19
25
|
export type SendEmailParams = {
|
|
20
26
|
emailSubject: string;
|
|
21
27
|
emailContent: string;
|
|
22
28
|
protectedData: Address;
|
|
23
29
|
contentType?: string;
|
|
24
30
|
senderName?: string;
|
|
31
|
+
label?: string;
|
|
32
|
+
workerpoolAddressOrEns?: AddressOrENS;
|
|
33
|
+
dataMaxPrice?: number;
|
|
34
|
+
appMaxPrice?: number;
|
|
35
|
+
workerpoolMaxPrice?: number;
|
|
25
36
|
};
|
|
26
37
|
|
|
27
|
-
export type
|
|
28
|
-
/**
|
|
29
|
-
* Index of the page to fetch
|
|
30
|
-
*/
|
|
31
|
-
page?: number;
|
|
38
|
+
export type FetchUserContactsParams = {
|
|
32
39
|
/**
|
|
33
|
-
*
|
|
40
|
+
* Address of the user
|
|
34
41
|
*/
|
|
35
|
-
|
|
42
|
+
userAddress: Address;
|
|
36
43
|
};
|
|
44
|
+
|
|
37
45
|
export type SendEmailResponse = {
|
|
38
|
-
taskId:
|
|
46
|
+
taskId: string;
|
|
39
47
|
};
|
|
40
48
|
|
|
41
49
|
/**
|
|
@@ -52,3 +60,60 @@ export type GraphQLResponse = {
|
|
|
52
60
|
export type SubgraphConsumer = {
|
|
53
61
|
graphQLClient: GraphQLClient;
|
|
54
62
|
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Configuration options for Web3Mail.
|
|
66
|
+
*/
|
|
67
|
+
export type Web3MailConfigOptions = {
|
|
68
|
+
/**
|
|
69
|
+
* The Ethereum contract address or ENS (Ethereum Name Service) for the email sender dapp.
|
|
70
|
+
* If not provided, the default web3mail address will be used.
|
|
71
|
+
*/
|
|
72
|
+
dappAddressOrENS?: AddressOrENS;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The Ethereum contract address for the whitelist.
|
|
76
|
+
* If not provided, the default whitelist smart contract address will be used.
|
|
77
|
+
*/
|
|
78
|
+
dappWhitelistAddress?: Address;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The subgraph URL for querying data.
|
|
82
|
+
* If not provided, the default data protector subgraph URL will be used.
|
|
83
|
+
*/
|
|
84
|
+
dataProtectorSubgraph?: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Options specific to iExec integration.
|
|
88
|
+
* If not provided, default iexec options will be used.
|
|
89
|
+
*/
|
|
90
|
+
iexecOptions?: IExecConfigOptions;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The IPFS node URL.
|
|
94
|
+
* If not provided, the default IPFS node URL will be used.
|
|
95
|
+
*/
|
|
96
|
+
ipfsNode?: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The IPFS gateway URL.
|
|
100
|
+
* If not provided, the default IPFS gateway URL will be used.
|
|
101
|
+
*/
|
|
102
|
+
ipfsGateway?: string;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type DappAddressConsumer = {
|
|
106
|
+
dappAddressOrENS: AddressOrENS;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type IpfsNodeConfigConsumer = {
|
|
110
|
+
ipfsNode: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type IpfsGatewayConfigConsumer = {
|
|
114
|
+
ipfsGateway: string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export type DappWhitelistAddressConsumer = {
|
|
118
|
+
dappWhitelistAddress: string;
|
|
119
|
+
};
|