@iexec/web3mail 0.1.1 → 0.3.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.
- package/README.md +1 -1
- package/dist/config/config.d.ts +1 -0
- package/dist/config/config.js +1 -0
- package/dist/utils/generateUniqueId.d.ts +1 -1
- package/dist/utils/generateUniqueId.js +3 -3
- package/dist/utils/validators.d.ts +2 -0
- package/dist/utils/validators.js +5 -0
- package/dist/web3mail/sendEmail.d.ts +1 -1
- package/dist/web3mail/sendEmail.js +13 -3
- package/dist/web3mail/types.d.ts +3 -1
- package/package.json +8 -12
- package/src/config/config.ts +1 -0
- package/src/utils/generateUniqueId.ts +4 -4
- package/src/utils/validators.ts +9 -0
- package/src/web3mail/sendEmail.ts +18 -1
- package/src/web3mail/types.ts +3 -1
- package/dist/bundle.js +0 -23
- package/dist/bundle.js.LICENSE.txt +0 -35
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Web3mail is composed of 2 methods:
|
|
|
16
16
|
|
|
17
17
|
<div align="center">
|
|
18
18
|
|
|
19
|
-
[](https://www.npmjs.com/package/@iexec/web3mail)[](/LICENSE)
|
|
20
20
|
|
|
21
21
|
</div>
|
|
22
22
|
|
package/dist/config/config.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare const WORKERPOOL_ADDRESS = "prod-v8-bellecour.main.pools.iexec.et
|
|
|
3
3
|
export declare const DATAPROTECTOR_SUBGRAPH_ENDPOINT = "https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector";
|
|
4
4
|
export declare const MAX_DESIRED_APP_ORDER_PRICE = 0;
|
|
5
5
|
export declare const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
|
|
6
|
+
export declare const DEFAULT_CONTENT_TYPE = "text/plain";
|
package/dist/config/config.js
CHANGED
|
@@ -3,3 +3,4 @@ export const WORKERPOOL_ADDRESS = 'prod-v8-bellecour.main.pools.iexec.eth';
|
|
|
3
3
|
export const DATAPROTECTOR_SUBGRAPH_ENDPOINT = 'https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector';
|
|
4
4
|
export const MAX_DESIRED_APP_ORDER_PRICE = 0;
|
|
5
5
|
export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
|
|
6
|
+
export const DEFAULT_CONTENT_TYPE = 'text/plain';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function generateSecureUniqueId(length:
|
|
1
|
+
export declare function generateSecureUniqueId(length: any): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { randomBytes } from '@ethersproject/random';
|
|
2
|
+
import { hexlify } from '@ethersproject/bytes';
|
|
2
3
|
export function generateSecureUniqueId(length) {
|
|
3
|
-
|
|
4
|
-
return buffer.toString('hex');
|
|
4
|
+
return hexlify(randomBytes(length));
|
|
5
5
|
}
|
|
@@ -2,3 +2,5 @@ export declare const throwIfMissing: () => never;
|
|
|
2
2
|
export declare const addressOrEnsSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
3
3
|
export declare const emailSubjectSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
4
4
|
export declare const emailContentSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
5
|
+
export declare const contentTypeSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
6
|
+
export declare const senderNameSchema: () => import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
package/dist/utils/validators.js
CHANGED
|
@@ -14,3 +14,8 @@ export const addressOrEnsSchema = () => string()
|
|
|
14
14
|
export const emailSubjectSchema = () => string().max(78).strict();
|
|
15
15
|
// 4096 bytes is the current max length for iExec SMS secrets
|
|
16
16
|
export const emailContentSchema = () => string().max(4096).strict();
|
|
17
|
+
// Valid content types for the variable 'contentType'
|
|
18
|
+
const validContentTypes = ['text/plain', 'text/html'];
|
|
19
|
+
export const contentTypeSchema = () => string().oneOf(validContentTypes, 'Invalid contentType').optional();
|
|
20
|
+
// Minimum of 3 characters and max of 20 to avoid sender being flagged as spam
|
|
21
|
+
export const senderNameSchema = () => string().trim().min(3).max(20).optional();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IExecConsumer, SendEmailParams, SendEmailResponse, SubgraphConsumer } from './types.js';
|
|
2
|
-
export declare const sendEmail: ({ graphQLClient, iexec, emailSubject, emailContent, protectedData, }: IExecConsumer & SubgraphConsumer & SendEmailParams) => Promise<SendEmailResponse>;
|
|
2
|
+
export declare const sendEmail: ({ graphQLClient, iexec, emailSubject, emailContent, contentType, senderName, protectedData, }: IExecConsumer & SubgraphConsumer & SendEmailParams) => Promise<SendEmailResponse>;
|
|
@@ -7,12 +7,12 @@ 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 { 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_WORKERPOOL_ORDER_PRICE, WEB3_MAIL_DAPP_ADDRESS, WORKERPOOL_ADDRESS, } from '../config/config.js';
|
|
11
11
|
import { WorkflowError } from '../utils/errors.js';
|
|
12
12
|
import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
13
13
|
import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
|
|
14
|
-
import { addressOrEnsSchema, emailContentSchema, emailSubjectSchema, throwIfMissing, } from '../utils/validators.js';
|
|
15
|
-
export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), emailSubject, emailContent, protectedData, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
import { addressOrEnsSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
|
|
15
|
+
export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), emailSubject, emailContent, contentType = DEFAULT_CONTENT_TYPE, senderName, protectedData, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
var _a, _b, _c, _d, _e;
|
|
17
17
|
try {
|
|
18
18
|
const vDatasetAddress = addressOrEnsSchema()
|
|
@@ -27,6 +27,13 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
|
|
|
27
27
|
.required()
|
|
28
28
|
.label('emailContent')
|
|
29
29
|
.validateSync(emailContent);
|
|
30
|
+
const vContentType = contentTypeSchema()
|
|
31
|
+
.required()
|
|
32
|
+
.label('contentType')
|
|
33
|
+
.validateSync(contentType);
|
|
34
|
+
const vSenderName = senderNameSchema()
|
|
35
|
+
.label('senderName')
|
|
36
|
+
.validateSync(senderName);
|
|
30
37
|
// Check protected data validity through subgraph
|
|
31
38
|
const isValidProtectedData = yield checkProtectedDataValidity(graphQLClient, vDatasetAddress);
|
|
32
39
|
if (!isValidProtectedData) {
|
|
@@ -85,8 +92,10 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
|
|
|
85
92
|
// Push requester secrets
|
|
86
93
|
const emailSubjectId = generateSecureUniqueId(16);
|
|
87
94
|
const emailContentId = generateSecureUniqueId(16);
|
|
95
|
+
const optionsId = generateSecureUniqueId(16);
|
|
88
96
|
yield iexec.secrets.pushRequesterSecret(emailSubjectId, vEmailSubject);
|
|
89
97
|
yield iexec.secrets.pushRequesterSecret(emailContentId, vEmailContent);
|
|
98
|
+
yield iexec.secrets.pushRequesterSecret(optionsId, JSON.stringify({ contentType: vContentType, senderName: vSenderName }));
|
|
90
99
|
// Create and sign request order
|
|
91
100
|
const requestorderToSign = yield iexec.order.createRequestorder({
|
|
92
101
|
app: WEB3_MAIL_DAPP_ADDRESS,
|
|
@@ -101,6 +110,7 @@ export const sendEmail = ({ graphQLClient = throwIfMissing(), iexec = throwIfMis
|
|
|
101
110
|
iexec_secrets: {
|
|
102
111
|
1: emailSubjectId,
|
|
103
112
|
2: emailContentId,
|
|
113
|
+
3: optionsId,
|
|
104
114
|
},
|
|
105
115
|
},
|
|
106
116
|
});
|
package/dist/web3mail/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EnhancedWallet, IExec } from 'iexec';
|
|
2
1
|
import { GraphQLClient } from 'graphql-request';
|
|
2
|
+
import { EnhancedWallet, IExec } from 'iexec';
|
|
3
3
|
export type Web3SignerProvider = EnhancedWallet;
|
|
4
4
|
export type IExecConsumer = {
|
|
5
5
|
iexec: IExec;
|
|
@@ -15,6 +15,8 @@ export type SendEmailParams = {
|
|
|
15
15
|
emailSubject: string;
|
|
16
16
|
emailContent: string;
|
|
17
17
|
protectedData: Address;
|
|
18
|
+
contentType?: string;
|
|
19
|
+
senderName?: string;
|
|
18
20
|
};
|
|
19
21
|
export type SendEmailResponse = {
|
|
20
22
|
taskId: Address;
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iexec/web3mail",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "This product enables users to confidentially store data–such as mail address, documents, personal information ...",
|
|
5
|
-
"main": "./dist/
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"node": "./dist/index.js",
|
|
12
|
-
"default": "./dist/
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "rm -rf dist && tsc
|
|
22
|
-
"start": "node dist/bundle.js",
|
|
21
|
+
"build": "rm -rf dist && tsc",
|
|
23
22
|
"test": "rm -rf dist && tsc && NODE_OPTIONS=--experimental-vm-modules npx jest --coverage",
|
|
24
23
|
"lint": "eslint . --ext .ts",
|
|
25
24
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
@@ -42,9 +41,6 @@
|
|
|
42
41
|
"@iexec/dataprotector": "^0.1.0",
|
|
43
42
|
"@types/jest": "^29.5.1",
|
|
44
43
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
45
|
-
"assert": "^2.0.0",
|
|
46
|
-
"constants-browserify": "^1.0.0",
|
|
47
|
-
"crypto-browserify": "^3.12.0",
|
|
48
44
|
"eslint": "^8.35.0",
|
|
49
45
|
"eslint-config-prettier": "^8.6.0",
|
|
50
46
|
"eslint-config-standard-with-typescript": "^34.0.0",
|
|
@@ -53,15 +49,15 @@
|
|
|
53
49
|
"eslint-plugin-promise": "^6.1.1",
|
|
54
50
|
"jest": "^29.5.0",
|
|
55
51
|
"prettier": "^2.8.4",
|
|
56
|
-
"stream-browserify": "^3.0.0",
|
|
57
52
|
"ts-jest": "^29.1.0",
|
|
58
53
|
"ts-loader": "^9.4.2",
|
|
59
|
-
"typescript": "^4.9.5"
|
|
60
|
-
"webpack-cli": "^5.0.1"
|
|
54
|
+
"typescript": "^4.9.5"
|
|
61
55
|
},
|
|
62
56
|
"dependencies": {
|
|
57
|
+
"@ethersproject/bytes": "^5.7.0",
|
|
58
|
+
"@ethersproject/random": "^5.7.0",
|
|
63
59
|
"graphql-request": "^6.1.0",
|
|
64
|
-
"iexec": "^8.1
|
|
60
|
+
"iexec": "^8.2.1",
|
|
65
61
|
"yup": "^1.1.1"
|
|
66
62
|
}
|
|
67
63
|
}
|
package/src/config/config.ts
CHANGED
|
@@ -4,3 +4,4 @@ export const DATAPROTECTOR_SUBGRAPH_ENDPOINT =
|
|
|
4
4
|
'https://thegraph-product.iex.ec/subgraphs/name/bellecour/dataprotector';
|
|
5
5
|
export const MAX_DESIRED_APP_ORDER_PRICE = 0;
|
|
6
6
|
export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
|
|
7
|
+
export const DEFAULT_CONTENT_TYPE = 'text/plain';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { randomBytes } from '@ethersproject/random';
|
|
2
|
+
import { hexlify } from '@ethersproject/bytes';
|
|
2
3
|
|
|
3
|
-
export function generateSecureUniqueId(length
|
|
4
|
-
|
|
5
|
-
return buffer.toString('hex');
|
|
4
|
+
export function generateSecureUniqueId(length) {
|
|
5
|
+
return hexlify(randomBytes(length));
|
|
6
6
|
}
|
package/src/utils/validators.ts
CHANGED
|
@@ -25,3 +25,12 @@ export const emailSubjectSchema = () => string().max(78).strict();
|
|
|
25
25
|
|
|
26
26
|
// 4096 bytes is the current max length for iExec SMS secrets
|
|
27
27
|
export const emailContentSchema = () => string().max(4096).strict();
|
|
28
|
+
|
|
29
|
+
// Valid content types for the variable 'contentType'
|
|
30
|
+
const validContentTypes = ['text/plain', 'text/html'];
|
|
31
|
+
|
|
32
|
+
export const contentTypeSchema = () =>
|
|
33
|
+
string().oneOf(validContentTypes, 'Invalid contentType').optional();
|
|
34
|
+
|
|
35
|
+
// Minimum of 3 characters and max of 20 to avoid sender being flagged as spam
|
|
36
|
+
export const senderNameSchema = () => string().trim().min(3).max(20).optional();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_CONTENT_TYPE,
|
|
2
3
|
MAX_DESIRED_APP_ORDER_PRICE,
|
|
3
4
|
MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
|
|
4
5
|
WEB3_MAIL_DAPP_ADDRESS,
|
|
@@ -9,8 +10,10 @@ import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
|
9
10
|
import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
|
|
10
11
|
import {
|
|
11
12
|
addressOrEnsSchema,
|
|
13
|
+
contentTypeSchema,
|
|
12
14
|
emailContentSchema,
|
|
13
15
|
emailSubjectSchema,
|
|
16
|
+
senderNameSchema,
|
|
14
17
|
throwIfMissing,
|
|
15
18
|
} from '../utils/validators.js';
|
|
16
19
|
import {
|
|
@@ -25,6 +28,8 @@ export const sendEmail = async ({
|
|
|
25
28
|
iexec = throwIfMissing(),
|
|
26
29
|
emailSubject,
|
|
27
30
|
emailContent,
|
|
31
|
+
contentType = DEFAULT_CONTENT_TYPE,
|
|
32
|
+
senderName,
|
|
28
33
|
protectedData,
|
|
29
34
|
}: IExecConsumer &
|
|
30
35
|
SubgraphConsumer &
|
|
@@ -42,6 +47,13 @@ export const sendEmail = async ({
|
|
|
42
47
|
.required()
|
|
43
48
|
.label('emailContent')
|
|
44
49
|
.validateSync(emailContent);
|
|
50
|
+
const vContentType = contentTypeSchema()
|
|
51
|
+
.required()
|
|
52
|
+
.label('contentType')
|
|
53
|
+
.validateSync(contentType);
|
|
54
|
+
const vSenderName = senderNameSchema()
|
|
55
|
+
.label('senderName')
|
|
56
|
+
.validateSync(senderName);
|
|
45
57
|
|
|
46
58
|
// Check protected data validity through subgraph
|
|
47
59
|
const isValidProtectedData = await checkProtectedDataValidity(
|
|
@@ -128,9 +140,13 @@ export const sendEmail = async ({
|
|
|
128
140
|
// Push requester secrets
|
|
129
141
|
const emailSubjectId = generateSecureUniqueId(16);
|
|
130
142
|
const emailContentId = generateSecureUniqueId(16);
|
|
143
|
+
const optionsId = generateSecureUniqueId(16);
|
|
131
144
|
await iexec.secrets.pushRequesterSecret(emailSubjectId, vEmailSubject);
|
|
132
145
|
await iexec.secrets.pushRequesterSecret(emailContentId, vEmailContent);
|
|
133
|
-
|
|
146
|
+
await iexec.secrets.pushRequesterSecret(
|
|
147
|
+
optionsId,
|
|
148
|
+
JSON.stringify({ contentType: vContentType, senderName: vSenderName })
|
|
149
|
+
);
|
|
134
150
|
// Create and sign request order
|
|
135
151
|
const requestorderToSign = await iexec.order.createRequestorder({
|
|
136
152
|
app: WEB3_MAIL_DAPP_ADDRESS,
|
|
@@ -145,6 +161,7 @@ export const sendEmail = async ({
|
|
|
145
161
|
iexec_secrets: {
|
|
146
162
|
1: emailSubjectId,
|
|
147
163
|
2: emailContentId,
|
|
164
|
+
3: optionsId,
|
|
148
165
|
},
|
|
149
166
|
},
|
|
150
167
|
});
|
package/src/web3mail/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EnhancedWallet, IExec } from 'iexec';
|
|
2
1
|
import { GraphQLClient } from 'graphql-request';
|
|
2
|
+
import { EnhancedWallet, IExec } from 'iexec';
|
|
3
3
|
|
|
4
4
|
export type Web3SignerProvider = EnhancedWallet;
|
|
5
5
|
|
|
@@ -20,6 +20,8 @@ export type SendEmailParams = {
|
|
|
20
20
|
emailSubject: string;
|
|
21
21
|
emailContent: string;
|
|
22
22
|
protectedData: Address;
|
|
23
|
+
contentType?: string;
|
|
24
|
+
senderName?: string;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type SendEmailResponse = {
|