@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 CHANGED
@@ -16,7 +16,7 @@ Web3mail is composed of 2 methods:
16
16
 
17
17
  <div align="center">
18
18
 
19
- [![npm](https://img.shields.io/npm/v/web3mail-sdk)](https://www.npmjs.com/package/@iexec/web3mail)[![license](https://img.shields.io/badge/license-Apache%202-blue)](/LICENSE)
19
+ [![npm](https://img.shields.io/npm/v/@iexec/web3mail)](https://www.npmjs.com/package/@iexec/web3mail)[![license](https://img.shields.io/badge/license-Apache%202-blue)](/LICENSE)
20
20
 
21
21
  </div>
22
22
 
@@ -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";
@@ -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: number): string;
1
+ export declare function generateSecureUniqueId(length: any): string;
@@ -1,5 +1,5 @@
1
- import crypto from 'crypto';
1
+ import { randomBytes } from '@ethersproject/random';
2
+ import { hexlify } from '@ethersproject/bytes';
2
3
  export function generateSecureUniqueId(length) {
3
- const buffer = crypto.randomBytes(length);
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, "">;
@@ -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
  });
@@ -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.1.1",
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/bundle.js",
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/bundle.js"
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 && webpack",
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.5",
60
+ "iexec": "^8.2.1",
65
61
  "yup": "^1.1.1"
66
62
  }
67
63
  }
@@ -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 crypto from 'crypto';
1
+ import { randomBytes } from '@ethersproject/random';
2
+ import { hexlify } from '@ethersproject/bytes';
2
3
 
3
- export function generateSecureUniqueId(length: number): string {
4
- const buffer = crypto.randomBytes(length);
5
- return buffer.toString('hex');
4
+ export function generateSecureUniqueId(length) {
5
+ return hexlify(randomBytes(length));
6
6
  }
@@ -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
  });
@@ -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 = {