@iexec/web3mail 1.2.2 → 1.3.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 +16 -6
- package/dist/config/config.js +33 -6
- package/dist/config/config.js.map +1 -1
- package/dist/utils/getChainId.d.ts +4 -0
- package/dist/utils/getChainId.js +33 -0
- package/dist/utils/getChainId.js.map +1 -0
- package/dist/utils/getWeb3Provider.d.ts +4 -1
- package/dist/utils/getWeb3Provider.js +7 -1
- package/dist/utils/getWeb3Provider.js.map +1 -1
- package/dist/utils/ipfs-service.d.ts +2 -2
- package/dist/utils/ipfs-service.js +2 -3
- package/dist/utils/ipfs-service.js.map +1 -1
- package/dist/utils/resolveDappAddressFromCompass.d.ts +2 -0
- package/dist/utils/resolveDappAddressFromCompass.js +37 -0
- package/dist/utils/resolveDappAddressFromCompass.js.map +1 -0
- package/dist/utils/subgraphQuery.js +3 -0
- package/dist/utils/subgraphQuery.js.map +1 -1
- package/dist/web3mail/IExecWeb3mail.d.ts +12 -5
- package/dist/web3mail/IExecWeb3mail.js +89 -26
- package/dist/web3mail/IExecWeb3mail.js.map +1 -1
- package/dist/web3mail/sendEmail.js +4 -2
- package/dist/web3mail/sendEmail.js.map +1 -1
- package/dist/web3mail/types.d.ts +6 -0
- package/package.json +7 -7
- package/src/config/config.ts +55 -8
- package/src/utils/getChainId.ts +43 -0
- package/src/utils/getWeb3Provider.ts +10 -2
- package/src/utils/ipfs-service.ts +2 -12
- package/src/utils/resolveDappAddressFromCompass.ts +55 -0
- package/src/utils/subgraphQuery.ts +3 -0
- package/src/web3mail/IExecWeb3mail.ts +132 -43
- package/src/web3mail/sendEmail.ts +4 -2
- package/src/web3mail/types.ts +7 -0
package/dist/config/config.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
export declare const WEB3_MAIL_DAPP_ADDRESS = "web3mail.apps.iexec.eth";
|
|
2
|
-
export declare const PROD_WORKERPOOL_ADDRESS = "prod-v8-bellecour.main.pools.iexec.eth";
|
|
3
|
-
export declare const DATAPROTECTOR_SUBGRAPH_ENDPOINT = "https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2";
|
|
4
1
|
export declare const MAX_DESIRED_DATA_ORDER_PRICE = 0;
|
|
5
2
|
export declare const MAX_DESIRED_APP_ORDER_PRICE = 0;
|
|
6
3
|
export declare const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
|
|
7
4
|
export declare const DEFAULT_CONTENT_TYPE = "text/plain";
|
|
8
|
-
export declare const IPFS_UPLOAD_URL = "/dns4/ipfs-upload.v8-bellecour.iex.ec/https";
|
|
9
|
-
export declare const DEFAULT_IPFS_GATEWAY = "https://ipfs-gateway.v8-bellecour.iex.ec";
|
|
10
|
-
export declare const WHITELIST_SMART_CONTRACT_ADDRESS = "0x781482C39CcE25546583EaC4957Fb7Bf04C277D2";
|
|
11
5
|
export declare const ANY_DATASET_ADDRESS = "any";
|
|
6
|
+
export declare const CALLBACK_WEB3MAIL = "0x5f936db7ad6d29371808e42a87015595d90509ba";
|
|
7
|
+
export declare const DEFAULT_CHAIN_ID = 134;
|
|
8
|
+
interface ChainConfig {
|
|
9
|
+
name: string;
|
|
10
|
+
dappAddress?: string;
|
|
11
|
+
prodWorkerpoolAddress: string;
|
|
12
|
+
dataProtectorSubgraph: string;
|
|
13
|
+
ipfsUploadUrl: string;
|
|
14
|
+
ipfsGateway: string;
|
|
15
|
+
whitelistSmartContract: string;
|
|
16
|
+
isExperimental?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const getChainDefaultConfig: (chainId: number, options?: {
|
|
19
|
+
allowExperimentalNetworks?: boolean;
|
|
20
|
+
}) => ChainConfig | null;
|
|
21
|
+
export {};
|
package/dist/config/config.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
|
-
export const WEB3_MAIL_DAPP_ADDRESS = 'web3mail.apps.iexec.eth';
|
|
2
|
-
export const PROD_WORKERPOOL_ADDRESS = 'prod-v8-bellecour.main.pools.iexec.eth';
|
|
3
|
-
export const DATAPROTECTOR_SUBGRAPH_ENDPOINT = 'https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2';
|
|
4
1
|
export const MAX_DESIRED_DATA_ORDER_PRICE = 0;
|
|
5
2
|
export const MAX_DESIRED_APP_ORDER_PRICE = 0;
|
|
6
3
|
export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
|
|
7
4
|
export const DEFAULT_CONTENT_TYPE = 'text/plain';
|
|
8
|
-
export const IPFS_UPLOAD_URL = '/dns4/ipfs-upload.v8-bellecour.iex.ec/https';
|
|
9
|
-
export const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec';
|
|
10
|
-
export const WHITELIST_SMART_CONTRACT_ADDRESS = '0x781482C39CcE25546583EaC4957Fb7Bf04C277D2';
|
|
11
5
|
export const ANY_DATASET_ADDRESS = 'any';
|
|
6
|
+
export const CALLBACK_WEB3MAIL = '0x5f936db7ad6d29371808e42a87015595d90509ba';
|
|
7
|
+
export const DEFAULT_CHAIN_ID = 134;
|
|
8
|
+
const CHAIN_CONFIG = {
|
|
9
|
+
134: {
|
|
10
|
+
name: 'bellecour',
|
|
11
|
+
dappAddress: 'web3mail.apps.iexec.eth',
|
|
12
|
+
prodWorkerpoolAddress: 'prod-v8-bellecour.main.pools.iexec.eth',
|
|
13
|
+
dataProtectorSubgraph: 'https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2',
|
|
14
|
+
ipfsUploadUrl: '/dns4/ipfs-upload.v8-bellecour.iex.ec/https',
|
|
15
|
+
ipfsGateway: 'https://ipfs-gateway.v8-bellecour.iex.ec',
|
|
16
|
+
whitelistSmartContract: '0x781482C39CcE25546583EaC4957Fb7Bf04C277D2',
|
|
17
|
+
},
|
|
18
|
+
421614: {
|
|
19
|
+
name: 'arbitrum-sepolia-testnet',
|
|
20
|
+
dappAddress: undefined, // ENS not supported on this network, address will be resolved from Compass
|
|
21
|
+
prodWorkerpoolAddress: '0xB967057a21dc6A66A29721d96b8Aa7454B7c383F',
|
|
22
|
+
dataProtectorSubgraph: 'https://thegraph.arbitrum-sepolia-testnet.iex.ec/api/subgraphs/id/5YjRPLtjS6GH6bB4yY55Qg4HzwtRGQ8TaHtGf9UBWWd',
|
|
23
|
+
ipfsGateway: 'https://ipfs-gateway.arbitrum-sepolia-testnet.iex.ec',
|
|
24
|
+
ipfsUploadUrl: 'https://ipfs-upload.arbitrum-sepolia-testnet.iex.ec',
|
|
25
|
+
whitelistSmartContract: '0x8d46d40840f1Aa2264F96184Ffadf04e5D573B9B',
|
|
26
|
+
isExperimental: true,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export const getChainDefaultConfig = (chainId, options) => {
|
|
30
|
+
const config = CHAIN_CONFIG[chainId];
|
|
31
|
+
if (!config) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (config.isExperimental && !options?.allowExperimentalNetworks) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return config;
|
|
38
|
+
};
|
|
12
39
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAC9C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AACjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AACzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,4CAA4C,CAAC;AAE9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAapC,MAAM,YAAY,GAAgC;IAChD,GAAG,EAAE;QACH,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,yBAAyB;QACtC,qBAAqB,EAAE,wCAAwC;QAC/D,qBAAqB,EACnB,mEAAmE;QACrE,aAAa,EAAE,6CAA6C;QAC5D,WAAW,EAAE,0CAA0C;QACvD,sBAAsB,EAAE,4CAA4C;KACrE;IACD,MAAM,EAAE;QACN,IAAI,EAAE,0BAA0B;QAChC,WAAW,EAAE,SAAS,EAAE,2EAA2E;QACnG,qBAAqB,EAAE,4CAA4C;QACnE,qBAAqB,EACnB,+GAA+G;QACjH,WAAW,EAAE,sDAAsD;QACnE,aAAa,EAAE,qDAAqD;QACpE,sBAAsB,EAAE,4CAA4C;QACpE,cAAc,EAAE,IAAI;KACrB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACf,OAAiD,EAC7B,EAAE;IACtB,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAErC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,MAAM,CAAC,cAAc,IAAI,CAAC,OAAO,EAAE,yBAAyB,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AbstractProvider, AbstractSigner, Eip1193Provider } from 'ethers';
|
|
2
|
+
type EthersCompatibleProvider = string | AbstractProvider | AbstractSigner | Eip1193Provider;
|
|
3
|
+
export declare function getChainIdFromProvider(ethProvider: EthersCompatibleProvider): Promise<number>;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { JsonRpcProvider, BrowserProvider, AbstractProvider, AbstractSigner, } from 'ethers';
|
|
2
|
+
import { DEFAULT_CHAIN_ID } from '../config/config.js';
|
|
3
|
+
export async function getChainIdFromProvider(ethProvider) {
|
|
4
|
+
try {
|
|
5
|
+
if (typeof ethProvider === 'string') {
|
|
6
|
+
const provider = new JsonRpcProvider(ethProvider);
|
|
7
|
+
const network = await provider.getNetwork();
|
|
8
|
+
return Number(network.chainId);
|
|
9
|
+
}
|
|
10
|
+
else if (ethProvider instanceof AbstractProvider) {
|
|
11
|
+
const network = await ethProvider.getNetwork();
|
|
12
|
+
return Number(network.chainId);
|
|
13
|
+
}
|
|
14
|
+
else if (ethProvider instanceof AbstractSigner) {
|
|
15
|
+
const { provider } = ethProvider;
|
|
16
|
+
if (!provider) {
|
|
17
|
+
throw Error('Signer is not connected to a provider');
|
|
18
|
+
}
|
|
19
|
+
const network = await provider.getNetwork();
|
|
20
|
+
return Number(network.chainId);
|
|
21
|
+
}
|
|
22
|
+
else if ('request' in ethProvider) {
|
|
23
|
+
const provider = new BrowserProvider(ethProvider);
|
|
24
|
+
const network = await provider.getNetwork();
|
|
25
|
+
return Number(network.chainId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
console.warn('Failed to detect chainId:', e);
|
|
30
|
+
}
|
|
31
|
+
return DEFAULT_CHAIN_ID;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=getChainId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getChainId.js","sourceRoot":"","sources":["../../src/utils/getChainId.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,GAEf,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAQvD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,WAAqC;IAErC,IAAI,CAAC;QACH,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;YAClD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,WAAW,YAAY,gBAAgB,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,CAAC;YAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,WAAW,YAAY,cAAc,EAAE,CAAC;YACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC;YACjC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACvD,CAAC;YACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;aAAM,IAAI,SAAS,IAAI,WAAW,EAAE,CAAC;YACpC,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,WAA8B,CAAC,CAAC;YACrE,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Web3SignerProvider } from '../web3mail/types.js';
|
|
2
|
-
export declare const getWeb3Provider: (privateKey: string
|
|
2
|
+
export declare const getWeb3Provider: (privateKey: string, options?: {
|
|
3
|
+
allowExperimentalNetworks?: boolean;
|
|
4
|
+
host?: number | string;
|
|
5
|
+
}) => Web3SignerProvider;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { getSignerFromPrivateKey } from 'iexec/utils';
|
|
2
|
-
export const getWeb3Provider = (privateKey) =>
|
|
2
|
+
export const getWeb3Provider = (privateKey, options = {}) => {
|
|
3
|
+
const chainHost = options?.host ? `${options.host}` : 'bellecour';
|
|
4
|
+
return getSignerFromPrivateKey(chainHost, privateKey, {
|
|
5
|
+
allowExperimentalNetworks: options?.allowExperimentalNetworks,
|
|
6
|
+
providers: {},
|
|
7
|
+
});
|
|
8
|
+
};
|
|
3
9
|
//# sourceMappingURL=getWeb3Provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWeb3Provider.js","sourceRoot":"","sources":["../../src/utils/getWeb3Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,MAAM,CAAC,MAAM,eAAe,GAAG,
|
|
1
|
+
{"version":3,"file":"getWeb3Provider.js","sourceRoot":"","sources":["../../src/utils/getWeb3Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAGtD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAkB,EAClB,UAA2E,EAAE,EACzD,EAAE;IACtB,MAAM,SAAS,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IAClE,OAAO,uBAAuB,CAAC,SAAS,EAAE,UAAU,EAAE;QACpD,yBAAyB,EAAE,OAAO,EAAE,yBAAyB;QAC7D,SAAS,EAAE,EAAE;KACd,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -4,6 +4,6 @@ interface GetOptions {
|
|
|
4
4
|
interface AddOptions extends GetOptions {
|
|
5
5
|
ipfsNode?: string;
|
|
6
6
|
}
|
|
7
|
-
declare const get: (cid: any, { ipfsGateway }?: GetOptions) => Promise<Uint8Array
|
|
8
|
-
declare const add: (content: any, { ipfsNode, ipfsGateway
|
|
7
|
+
declare const get: (cid: any, { ipfsGateway }?: GetOptions) => Promise<Uint8Array<ArrayBuffer>>;
|
|
8
|
+
declare const add: (content: any, { ipfsNode, ipfsGateway }?: AddOptions) => Promise<string>;
|
|
9
9
|
export { add, get };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { create } from 'kubo-rpc-client';
|
|
2
|
-
|
|
3
|
-
const get = async (cid, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) => {
|
|
2
|
+
const get = async (cid, { ipfsGateway } = {}) => {
|
|
4
3
|
const multiaddr = `/ipfs/${cid.toString()}`;
|
|
5
4
|
const publicUrl = `${ipfsGateway}${multiaddr}`;
|
|
6
5
|
const res = await fetch(publicUrl);
|
|
@@ -10,7 +9,7 @@ const get = async (cid, { ipfsGateway = DEFAULT_IPFS_GATEWAY } = {}) => {
|
|
|
10
9
|
const arrayBuffer = await res.arrayBuffer();
|
|
11
10
|
return new Uint8Array(arrayBuffer);
|
|
12
11
|
};
|
|
13
|
-
const add = async (content, { ipfsNode
|
|
12
|
+
const add = async (content, { ipfsNode, ipfsGateway } = {}) => {
|
|
14
13
|
const ipfsClient = create(ipfsNode);
|
|
15
14
|
const { cid } = await ipfsClient.add(content);
|
|
16
15
|
await get(cid.toString(), { ipfsGateway });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfs-service.js","sourceRoot":"","sources":["../../src/utils/ipfs-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ipfs-service.js","sourceRoot":"","sources":["../../src/utils/ipfs-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AASzC,MAAM,GAAG,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE,WAAW,KAAiB,EAAE,EAAE,EAAE;IAC1D,MAAM,SAAS,GAAG,SAAS,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC5C,MAAM,SAAS,GAAG,GAAG,WAAW,GAAG,SAAS,EAAE,CAAC;IAC/C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC,+BAA+B,SAAS,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC;IAC5C,OAAO,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,GAAG,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,WAAW,KAAiB,EAAE,EAAE,EAAE;IACxE,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CompassCallError } from 'iexec/errors';
|
|
2
|
+
export async function resolveDappAddressFromCompass(compassUrl, chainId) {
|
|
3
|
+
if (!compassUrl) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const address = await fetch(`${compassUrl}/${chainId}/iapps/web3mail`)
|
|
7
|
+
// Handle network errors
|
|
8
|
+
.catch((error) => {
|
|
9
|
+
throw new CompassCallError(`Connection to ${compassUrl} failed with a network error`, error);
|
|
10
|
+
})
|
|
11
|
+
// Handle server errors
|
|
12
|
+
.then((response) => {
|
|
13
|
+
if (response.status >= 500 && response.status <= 599) {
|
|
14
|
+
throw new CompassCallError(`Server at ${compassUrl} encountered an internal error`, Error(`Server internal error: ${response.status} ${response.statusText}`));
|
|
15
|
+
}
|
|
16
|
+
return response;
|
|
17
|
+
})
|
|
18
|
+
// Handle unexpected response formats
|
|
19
|
+
.then((response) => {
|
|
20
|
+
if (response.status !== 200) {
|
|
21
|
+
throw new Error(`Failed to fetch dapp address from compass: ${response.statusText}`);
|
|
22
|
+
}
|
|
23
|
+
const contentType = response.headers.get('Content-Type');
|
|
24
|
+
if (!contentType || contentType.indexOf('application/json') === -1) {
|
|
25
|
+
throw new Error('Failed to fetch dapp address from compass: response is not JSON');
|
|
26
|
+
}
|
|
27
|
+
return response.json();
|
|
28
|
+
})
|
|
29
|
+
.then((data) => {
|
|
30
|
+
if (!data || !data.address) {
|
|
31
|
+
throw new Error(`No dapp address found in compass response`);
|
|
32
|
+
}
|
|
33
|
+
return data.address;
|
|
34
|
+
});
|
|
35
|
+
return address;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=resolveDappAddressFromCompass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDappAddressFromCompass.js","sourceRoot":"","sources":["../../src/utils/resolveDappAddressFromCompass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,UAAkB,EAClB,OAAe;IAEf,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,IAAI,OAAO,iBAAiB,CAAC;QACpE,wBAAwB;SACvB,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,IAAI,gBAAgB,CACxB,iBAAiB,UAAU,8BAA8B,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
|
|
25
25
|
export const getValidContact = async (graphQLClient, contacts) => {
|
|
26
|
+
if (contacts.length === 0) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
26
29
|
try {
|
|
27
30
|
// Contacts addresses
|
|
28
31
|
const contactsAddresses = contacts.map((contact) => contact.address);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subgraphQuery.js","sourceRoot":"","sources":["../../src/utils/subgraphQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,uBAAuB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;CAqBlC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,aAA4B,EAC5B,QAAmB,EACC,EAAE;IACtB,IAAI,CAAC;QACH,qBAAqB;QACrB,MAAM,iBAAiB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAErE,aAAa;QACb,MAAM,iBAAiB,GAAyB,EAAE,CAAC;QACnD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,KAAK,GAAG,IAAI,CAAC;QACnB,IAAI,kBAAkB,GAAG,IAAI,CAAC;QAE9B,GAAG,CAAC;YACF,MAAM,SAAS,GAAG;gBAChB,cAAc,EAAE,CAAC,cAAc,CAAC;gBAChC,EAAE,EAAE,iBAAiB;gBACrB,KAAK;gBACL,KAAK;aACN,CAAC;YAEF,MAAM,wBAAwB,GAC5B,MAAM,aAAa,CAAC,OAAO,CAAC,uBAAuB,EAAE,SAAS,CAAC,CAAC;YAElE,MAAM,EAAE,cAAc,EAAE,GAAG,wBAAwB,CAAC;YACpD,iBAAiB,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;YAE1C,kBAAkB,GAAG,cAAc,CAAC,MAAM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AAC,MAAM,KAAK,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,aAAa,CAAC;YACtB,OAAO,EAAE,0BAA0B;YACnC,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { AbstractProvider, AbstractSigner, Eip1193Provider } from 'ethers';
|
|
2
2
|
import { Contact, FetchUserContactsParams, SendEmailParams, Web3MailConfigOptions, SendEmailResponse, Web3SignerProvider, FetchMyContactsParams } from './types.js';
|
|
3
|
+
type EthersCompatibleProvider = AbstractProvider | AbstractSigner | Eip1193Provider | Web3SignerProvider | string;
|
|
3
4
|
export declare class IExecWeb3mail {
|
|
4
|
-
private iexec;
|
|
5
|
-
private ipfsNode;
|
|
6
|
-
private ipfsGateway;
|
|
7
|
-
private dataProtectorSubgraph;
|
|
8
5
|
private dappAddressOrENS;
|
|
9
6
|
private dappWhitelistAddress;
|
|
10
7
|
private graphQLClient;
|
|
11
|
-
|
|
8
|
+
private ipfsNode;
|
|
9
|
+
private ipfsGateway;
|
|
10
|
+
private defaultWorkerpool;
|
|
11
|
+
private iexec;
|
|
12
|
+
private initPromise;
|
|
13
|
+
private ethProvider;
|
|
14
|
+
private options;
|
|
15
|
+
constructor(ethProvider?: EthersCompatibleProvider, options?: Web3MailConfigOptions);
|
|
16
|
+
init(): Promise<void>;
|
|
12
17
|
fetchMyContacts(args?: FetchMyContactsParams): Promise<Contact[]>;
|
|
13
18
|
fetchUserContacts(args: FetchUserContactsParams): Promise<Contact[]>;
|
|
14
19
|
sendEmail(args: SendEmailParams): Promise<SendEmailResponse>;
|
|
20
|
+
private resolveConfig;
|
|
15
21
|
}
|
|
22
|
+
export {};
|
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
import { IExec } from 'iexec';
|
|
2
|
+
import { GraphQLClient } from 'graphql-request';
|
|
2
3
|
import { fetchUserContacts } from './fetchUserContacts.js';
|
|
3
4
|
import { fetchMyContacts } from './fetchMyContacts.js';
|
|
4
5
|
import { sendEmail } from './sendEmail.js';
|
|
5
|
-
import { GraphQLClient } from 'graphql-request';
|
|
6
|
-
import { WEB3_MAIL_DAPP_ADDRESS, IPFS_UPLOAD_URL, DEFAULT_IPFS_GATEWAY, DATAPROTECTOR_SUBGRAPH_ENDPOINT, WHITELIST_SMART_CONTRACT_ADDRESS, } from '../config/config.js';
|
|
7
6
|
import { isValidProvider } from '../utils/validators.js';
|
|
7
|
+
import { getChainIdFromProvider } from '../utils/getChainId.js';
|
|
8
|
+
import { getChainDefaultConfig } from '../config/config.js';
|
|
9
|
+
import { resolveDappAddressFromCompass } from '../utils/resolveDappAddressFromCompass.js';
|
|
8
10
|
export class IExecWeb3mail {
|
|
9
|
-
iexec;
|
|
10
|
-
ipfsNode;
|
|
11
|
-
ipfsGateway;
|
|
12
|
-
dataProtectorSubgraph;
|
|
13
11
|
dappAddressOrENS;
|
|
14
12
|
dappWhitelistAddress;
|
|
15
13
|
graphQLClient;
|
|
14
|
+
ipfsNode;
|
|
15
|
+
ipfsGateway;
|
|
16
|
+
defaultWorkerpool;
|
|
17
|
+
iexec;
|
|
18
|
+
initPromise = null;
|
|
19
|
+
ethProvider;
|
|
20
|
+
options;
|
|
16
21
|
constructor(ethProvider, options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
this.ethProvider = ethProvider || 'bellecour';
|
|
23
|
+
this.options = options || {};
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
if (!this.initPromise) {
|
|
27
|
+
this.initPromise = this.resolveConfig().then((config) => {
|
|
28
|
+
this.dappAddressOrENS = config.dappAddressOrENS;
|
|
29
|
+
this.dappWhitelistAddress = config.dappWhitelistAddress;
|
|
30
|
+
this.graphQLClient = config.graphQLClient;
|
|
31
|
+
this.ipfsNode = config.ipfsNode;
|
|
32
|
+
this.ipfsGateway = config.ipfsGateway;
|
|
33
|
+
this.defaultWorkerpool = config.defaultWorkerpool;
|
|
34
|
+
this.iexec = config.iexec;
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
|
-
this.
|
|
32
|
-
this.ipfsNode = options?.ipfsNode || IPFS_UPLOAD_URL;
|
|
33
|
-
this.ipfsGateway = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY;
|
|
34
|
-
this.dappWhitelistAddress =
|
|
35
|
-
options?.dappWhitelistAddress || WHITELIST_SMART_CONTRACT_ADDRESS;
|
|
37
|
+
return this.initPromise;
|
|
36
38
|
}
|
|
37
39
|
async fetchMyContacts(args) {
|
|
40
|
+
await this.init();
|
|
38
41
|
await isValidProvider(this.iexec);
|
|
39
42
|
return fetchMyContacts({
|
|
40
43
|
...args,
|
|
@@ -44,7 +47,8 @@ export class IExecWeb3mail {
|
|
|
44
47
|
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
|
-
fetchUserContacts(args) {
|
|
50
|
+
async fetchUserContacts(args) {
|
|
51
|
+
await this.init();
|
|
48
52
|
return fetchUserContacts({
|
|
49
53
|
...args,
|
|
50
54
|
iexec: this.iexec,
|
|
@@ -54,17 +58,76 @@ export class IExecWeb3mail {
|
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
async sendEmail(args) {
|
|
61
|
+
await this.init();
|
|
57
62
|
await isValidProvider(this.iexec);
|
|
58
63
|
return sendEmail({
|
|
59
64
|
...args,
|
|
65
|
+
workerpoolAddressOrEns: args.workerpoolAddressOrEns || this.defaultWorkerpool,
|
|
60
66
|
iexec: this.iexec,
|
|
61
67
|
ipfsNode: this.ipfsNode,
|
|
62
68
|
ipfsGateway: this.ipfsGateway,
|
|
63
69
|
dappAddressOrENS: this.dappAddressOrENS,
|
|
64
70
|
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
65
71
|
graphQLClient: this.graphQLClient,
|
|
66
|
-
useVoucher: args?.useVoucher,
|
|
67
72
|
});
|
|
68
73
|
}
|
|
74
|
+
async resolveConfig() {
|
|
75
|
+
const chainId = await getChainIdFromProvider(this.ethProvider);
|
|
76
|
+
const chainDefaultConfig = getChainDefaultConfig(chainId, {
|
|
77
|
+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
|
|
78
|
+
});
|
|
79
|
+
const ipfsGateway = this.options?.ipfsGateway || chainDefaultConfig?.ipfsGateway;
|
|
80
|
+
let iexec, graphQLClient;
|
|
81
|
+
try {
|
|
82
|
+
iexec = new IExec({ ethProvider: this.ethProvider }, {
|
|
83
|
+
ipfsGatewayURL: ipfsGateway,
|
|
84
|
+
...this.options?.iexecOptions,
|
|
85
|
+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
throw new Error(`Unsupported ethProvider: ${e.message}`);
|
|
90
|
+
}
|
|
91
|
+
const subgraphUrl = this.options?.dataProtectorSubgraph ||
|
|
92
|
+
chainDefaultConfig?.dataProtectorSubgraph;
|
|
93
|
+
const dappAddressOrENS = this.options?.dappAddressOrENS ||
|
|
94
|
+
chainDefaultConfig?.dappAddress ||
|
|
95
|
+
(await resolveDappAddressFromCompass(await iexec.config.resolveCompassURL(), chainId));
|
|
96
|
+
const dappWhitelistAddress = this.options?.dappWhitelistAddress ||
|
|
97
|
+
chainDefaultConfig?.whitelistSmartContract;
|
|
98
|
+
const defaultWorkerpool = chainDefaultConfig?.prodWorkerpoolAddress;
|
|
99
|
+
const ipfsNode = this.options?.ipfsNode || chainDefaultConfig?.ipfsUploadUrl;
|
|
100
|
+
const missing = [];
|
|
101
|
+
if (!subgraphUrl)
|
|
102
|
+
missing.push('dataProtectorSubgraph');
|
|
103
|
+
if (!dappAddressOrENS)
|
|
104
|
+
missing.push('dappAddress');
|
|
105
|
+
if (!dappWhitelistAddress)
|
|
106
|
+
missing.push('whitelistSmartContract');
|
|
107
|
+
if (!ipfsGateway)
|
|
108
|
+
missing.push('ipfsGateway');
|
|
109
|
+
if (!defaultWorkerpool)
|
|
110
|
+
missing.push('prodWorkerpoolAddress');
|
|
111
|
+
if (!ipfsNode)
|
|
112
|
+
missing.push('ipfsUploadUrl');
|
|
113
|
+
if (missing.length > 0) {
|
|
114
|
+
throw new Error(`Missing required configuration for chainId ${chainId}: ${missing.join(', ')}`);
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
graphQLClient = new GraphQLClient(subgraphUrl);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new Error(`Failed to create GraphQLClient: ${error.message}`);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
dappAddressOrENS,
|
|
124
|
+
dappWhitelistAddress: dappWhitelistAddress.toLowerCase(),
|
|
125
|
+
defaultWorkerpool,
|
|
126
|
+
graphQLClient,
|
|
127
|
+
ipfsNode,
|
|
128
|
+
ipfsGateway,
|
|
129
|
+
iexec,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
69
132
|
}
|
|
70
133
|
//# sourceMappingURL=IExecWeb3mail.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IExecWeb3mail.js","sourceRoot":"","sources":["../../src/web3mail/IExecWeb3mail.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAW3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"IExecWeb3mail.js","sourceRoot":"","sources":["../../src/web3mail/IExecWeb3mail.ts"],"names":[],"mappings":"AACA,OAAO,EAA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
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import { DEFAULT_CONTENT_TYPE, MAX_DESIRED_APP_ORDER_PRICE, MAX_DESIRED_DATA_ORDER_PRICE, MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
|
|
2
|
+
import { CALLBACK_WEB3MAIL, 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
4
|
import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
5
5
|
import * as ipfs from '../utils/ipfs-service.js';
|
|
6
6
|
import { checkProtectedDataValidity } from '../utils/subgraphQuery.js';
|
|
7
7
|
import { addressOrEnsSchema, addressSchema, booleanSchema, contentTypeSchema, emailContentSchema, emailSubjectSchema, labelSchema, positiveNumberSchema, senderNameSchema, throwIfMissing, } from '../utils/validators.js';
|
|
8
8
|
import { checkUserVoucher, filterWorkerpoolOrders, } from './sendEmail.models.js';
|
|
9
|
-
export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = throwIfMissing(), workerpoolAddressOrEns
|
|
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
10
|
const vDatasetAddress = addressOrEnsSchema()
|
|
11
11
|
.required()
|
|
12
12
|
.label('protectedData')
|
|
@@ -183,6 +183,7 @@ export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = thro
|
|
|
183
183
|
contentType: vContentType,
|
|
184
184
|
senderName: vSenderName,
|
|
185
185
|
emailContentEncryptionKey,
|
|
186
|
+
useCallback: true,
|
|
186
187
|
}));
|
|
187
188
|
const requestorderToSign = await iexec.order.createRequestorder({
|
|
188
189
|
app: vDappAddressOrENS,
|
|
@@ -193,6 +194,7 @@ export const sendEmail = async ({ graphQLClient = throwIfMissing(), iexec = thro
|
|
|
193
194
|
workerpoolmaxprice: workerpoolorder.workerpoolprice,
|
|
194
195
|
tag: ['tee', 'scone'],
|
|
195
196
|
workerpool: vWorkerpoolAddressOrEns,
|
|
197
|
+
callback: CALLBACK_WEB3MAIL,
|
|
196
198
|
params: {
|
|
197
199
|
iexec_secrets: {
|
|
198
200
|
1: requesterSecretId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,kCAAkC,
|
|
1
|
+
{"version":3,"file":"sendEmail.js","sourceRoot":"","sources":["../../src/web3mail/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,kCAAkC,GACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,aA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AM;aACnB;SACF,CAAC,CAAC;QACH,MAAM,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,CAC9C;YACE,QAAQ,EAAE,QAAQ;YAClB,YAAY,EAAE,YAAY;YAC1B,eAAe,EAAE,eAAe;YAChC,YAAY,EAAE,YAAY;SAC3B,EACD,EAAE,UAAU,EAAE,WAAW,EAAE,CAC5B,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAEzD,OAAO;YACL,MAAM;SACP,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAE7B,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
|
@@ -88,6 +88,12 @@ export type Web3MailConfigOptions = {
|
|
|
88
88
|
* If not provided, the default IPFS gateway URL will be used.
|
|
89
89
|
*/
|
|
90
90
|
ipfsGateway?: string;
|
|
91
|
+
/**
|
|
92
|
+
* if true allows using a provider connected to an experimental networks (default false)
|
|
93
|
+
*
|
|
94
|
+
* ⚠️ experimental networks are networks on which the iExec's stack is partially deployed, experimental networks can be subject to instabilities or discontinuity. Access is provided without warranties.
|
|
95
|
+
*/
|
|
96
|
+
allowExperimentalNetworks?: boolean;
|
|
91
97
|
};
|
|
92
98
|
export type DappAddressConsumer = {
|
|
93
99
|
dappAddressOrENS: AddressOrENS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iexec/web3mail",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --forceExit -b",
|
|
29
29
|
"test:e2e:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --testMatch \"**/tests/**/*.test.ts\" --coverage",
|
|
30
30
|
"lint": "eslint .",
|
|
31
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
32
|
-
"check-format": "prettier --check \"src/**/*.ts\"",
|
|
31
|
+
"format": "prettier --write \"(src|tests)/**/*.ts\"",
|
|
32
|
+
"check-format": "prettier --check \"(src|tests)/**/*.ts\"",
|
|
33
33
|
"stop-test-stack": "cd tests && docker compose down --volumes --remove-orphans",
|
|
34
34
|
"start-test-stack": "cd tests && npm run stop-test-stack && node scripts/prepare-test-env.js && docker compose build && docker compose up -d && node scripts/prepare-bellecour-fork-for-tests.js"
|
|
35
35
|
},
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"buffer": "^6.0.3",
|
|
53
53
|
"ethers": "^6.13.2",
|
|
54
54
|
"graphql-request": "^6.1.0",
|
|
55
|
-
"iexec": "^8.
|
|
55
|
+
"iexec": "^8.17.1",
|
|
56
56
|
"kubo-rpc-client": "^4.1.1",
|
|
57
57
|
"yup": "^1.1.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@iexec/dataprotector": "^2.0.0-beta.
|
|
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",
|
|
@@ -73,6 +73,6 @@
|
|
|
73
73
|
"jest": "^29.7.0",
|
|
74
74
|
"prettier": "^2.8.4",
|
|
75
75
|
"typescript": "^5.5.2",
|
|
76
|
-
"whitelist-smart-contract": "github:iExecBlockchainComputing/whitelist-smart-contract#
|
|
76
|
+
"whitelist-smart-contract": "github:iExecBlockchainComputing/whitelist-smart-contract#v1.1.0"
|
|
77
77
|
}
|
|
78
|
-
}
|
|
78
|
+
}
|
package/src/config/config.ts
CHANGED
|
@@ -1,13 +1,60 @@
|
|
|
1
|
-
export const WEB3_MAIL_DAPP_ADDRESS = 'web3mail.apps.iexec.eth';
|
|
2
|
-
export const PROD_WORKERPOOL_ADDRESS = 'prod-v8-bellecour.main.pools.iexec.eth';
|
|
3
|
-
export const DATAPROTECTOR_SUBGRAPH_ENDPOINT =
|
|
4
|
-
'https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2';
|
|
5
1
|
export const MAX_DESIRED_DATA_ORDER_PRICE = 0;
|
|
6
2
|
export const MAX_DESIRED_APP_ORDER_PRICE = 0;
|
|
7
3
|
export const MAX_DESIRED_WORKERPOOL_ORDER_PRICE = 0;
|
|
8
4
|
export const DEFAULT_CONTENT_TYPE = 'text/plain';
|
|
9
|
-
export const IPFS_UPLOAD_URL = '/dns4/ipfs-upload.v8-bellecour.iex.ec/https';
|
|
10
|
-
export const DEFAULT_IPFS_GATEWAY = 'https://ipfs-gateway.v8-bellecour.iex.ec';
|
|
11
|
-
export const WHITELIST_SMART_CONTRACT_ADDRESS =
|
|
12
|
-
'0x781482C39CcE25546583EaC4957Fb7Bf04C277D2';
|
|
13
5
|
export const ANY_DATASET_ADDRESS = 'any';
|
|
6
|
+
export const CALLBACK_WEB3MAIL = '0x5f936db7ad6d29371808e42a87015595d90509ba';
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_CHAIN_ID = 134;
|
|
9
|
+
|
|
10
|
+
interface ChainConfig {
|
|
11
|
+
name: string;
|
|
12
|
+
dappAddress?: string;
|
|
13
|
+
prodWorkerpoolAddress: string;
|
|
14
|
+
dataProtectorSubgraph: string;
|
|
15
|
+
ipfsUploadUrl: string;
|
|
16
|
+
ipfsGateway: string;
|
|
17
|
+
whitelistSmartContract: string;
|
|
18
|
+
isExperimental?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const CHAIN_CONFIG: Record<number, ChainConfig> = {
|
|
22
|
+
134: {
|
|
23
|
+
name: 'bellecour',
|
|
24
|
+
dappAddress: 'web3mail.apps.iexec.eth',
|
|
25
|
+
prodWorkerpoolAddress: 'prod-v8-bellecour.main.pools.iexec.eth',
|
|
26
|
+
dataProtectorSubgraph:
|
|
27
|
+
'https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2',
|
|
28
|
+
ipfsUploadUrl: '/dns4/ipfs-upload.v8-bellecour.iex.ec/https',
|
|
29
|
+
ipfsGateway: 'https://ipfs-gateway.v8-bellecour.iex.ec',
|
|
30
|
+
whitelistSmartContract: '0x781482C39CcE25546583EaC4957Fb7Bf04C277D2',
|
|
31
|
+
},
|
|
32
|
+
421614: {
|
|
33
|
+
name: 'arbitrum-sepolia-testnet',
|
|
34
|
+
dappAddress: undefined, // ENS not supported on this network, address will be resolved from Compass
|
|
35
|
+
prodWorkerpoolAddress: '0xB967057a21dc6A66A29721d96b8Aa7454B7c383F',
|
|
36
|
+
dataProtectorSubgraph:
|
|
37
|
+
'https://thegraph.arbitrum-sepolia-testnet.iex.ec/api/subgraphs/id/5YjRPLtjS6GH6bB4yY55Qg4HzwtRGQ8TaHtGf9UBWWd',
|
|
38
|
+
ipfsGateway: 'https://ipfs-gateway.arbitrum-sepolia-testnet.iex.ec',
|
|
39
|
+
ipfsUploadUrl: 'https://ipfs-upload.arbitrum-sepolia-testnet.iex.ec',
|
|
40
|
+
whitelistSmartContract: '0x8d46d40840f1Aa2264F96184Ffadf04e5D573B9B',
|
|
41
|
+
isExperimental: true,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const getChainDefaultConfig = (
|
|
46
|
+
chainId: number,
|
|
47
|
+
options?: { allowExperimentalNetworks?: boolean }
|
|
48
|
+
): ChainConfig | null => {
|
|
49
|
+
const config = CHAIN_CONFIG[chainId];
|
|
50
|
+
|
|
51
|
+
if (!config) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (config.isExperimental && !options?.allowExperimentalNetworks) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return config;
|
|
60
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JsonRpcProvider,
|
|
3
|
+
BrowserProvider,
|
|
4
|
+
AbstractProvider,
|
|
5
|
+
AbstractSigner,
|
|
6
|
+
Eip1193Provider,
|
|
7
|
+
} from 'ethers';
|
|
8
|
+
import { DEFAULT_CHAIN_ID } from '../config/config.js';
|
|
9
|
+
|
|
10
|
+
type EthersCompatibleProvider =
|
|
11
|
+
| string
|
|
12
|
+
| AbstractProvider
|
|
13
|
+
| AbstractSigner
|
|
14
|
+
| Eip1193Provider;
|
|
15
|
+
|
|
16
|
+
export async function getChainIdFromProvider(
|
|
17
|
+
ethProvider: EthersCompatibleProvider
|
|
18
|
+
): Promise<number> {
|
|
19
|
+
try {
|
|
20
|
+
if (typeof ethProvider === 'string') {
|
|
21
|
+
const provider = new JsonRpcProvider(ethProvider);
|
|
22
|
+
const network = await provider.getNetwork();
|
|
23
|
+
return Number(network.chainId);
|
|
24
|
+
} else if (ethProvider instanceof AbstractProvider) {
|
|
25
|
+
const network = await ethProvider.getNetwork();
|
|
26
|
+
return Number(network.chainId);
|
|
27
|
+
} else if (ethProvider instanceof AbstractSigner) {
|
|
28
|
+
const { provider } = ethProvider;
|
|
29
|
+
if (!provider) {
|
|
30
|
+
throw Error('Signer is not connected to a provider');
|
|
31
|
+
}
|
|
32
|
+
const network = await provider.getNetwork();
|
|
33
|
+
return Number(network.chainId);
|
|
34
|
+
} else if ('request' in ethProvider) {
|
|
35
|
+
const provider = new BrowserProvider(ethProvider as Eip1193Provider);
|
|
36
|
+
const network = await provider.getNetwork();
|
|
37
|
+
return Number(network.chainId);
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.warn('Failed to detect chainId:', e);
|
|
41
|
+
}
|
|
42
|
+
return DEFAULT_CHAIN_ID;
|
|
43
|
+
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { getSignerFromPrivateKey } from 'iexec/utils';
|
|
2
2
|
import { Web3SignerProvider } from '../web3mail/types.js';
|
|
3
3
|
|
|
4
|
-
export const getWeb3Provider = (
|
|
5
|
-
|
|
4
|
+
export const getWeb3Provider = (
|
|
5
|
+
privateKey: string,
|
|
6
|
+
options: { allowExperimentalNetworks?: boolean; host?: number | string } = {}
|
|
7
|
+
): Web3SignerProvider => {
|
|
8
|
+
const chainHost = options?.host ? `${options.host}` : 'bellecour';
|
|
9
|
+
return getSignerFromPrivateKey(chainHost, privateKey, {
|
|
10
|
+
allowExperimentalNetworks: options?.allowExperimentalNetworks,
|
|
11
|
+
providers: {},
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { create } from 'kubo-rpc-client';
|
|
2
|
-
import { IPFS_UPLOAD_URL, DEFAULT_IPFS_GATEWAY } from '../config/config.js';
|
|
3
2
|
|
|
4
3
|
interface GetOptions {
|
|
5
4
|
ipfsGateway?: string;
|
|
@@ -8,10 +7,7 @@ interface AddOptions extends GetOptions {
|
|
|
8
7
|
ipfsNode?: string;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
const get = async (
|
|
12
|
-
cid,
|
|
13
|
-
{ ipfsGateway = DEFAULT_IPFS_GATEWAY }: GetOptions = {}
|
|
14
|
-
) => {
|
|
10
|
+
const get = async (cid, { ipfsGateway }: GetOptions = {}) => {
|
|
15
11
|
const multiaddr = `/ipfs/${cid.toString()}`;
|
|
16
12
|
const publicUrl = `${ipfsGateway}${multiaddr}`;
|
|
17
13
|
const res = await fetch(publicUrl);
|
|
@@ -22,13 +18,7 @@ const get = async (
|
|
|
22
18
|
return new Uint8Array(arrayBuffer);
|
|
23
19
|
};
|
|
24
20
|
|
|
25
|
-
const add = async (
|
|
26
|
-
content,
|
|
27
|
-
{
|
|
28
|
-
ipfsNode = IPFS_UPLOAD_URL,
|
|
29
|
-
ipfsGateway = DEFAULT_IPFS_GATEWAY,
|
|
30
|
-
}: AddOptions = {}
|
|
31
|
-
) => {
|
|
21
|
+
const add = async (content, { ipfsNode, ipfsGateway }: AddOptions = {}) => {
|
|
32
22
|
const ipfsClient = create(ipfsNode);
|
|
33
23
|
const { cid } = await ipfsClient.add(content);
|
|
34
24
|
await get(cid.toString(), { ipfsGateway });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CompassCallError } from 'iexec/errors';
|
|
2
|
+
import { AddressOrENS } from '../web3mail/types.js';
|
|
3
|
+
|
|
4
|
+
export async function resolveDappAddressFromCompass(
|
|
5
|
+
compassUrl: string,
|
|
6
|
+
chainId: number
|
|
7
|
+
): Promise<AddressOrENS | undefined> {
|
|
8
|
+
if (!compassUrl) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const address = await fetch(`${compassUrl}/${chainId}/iapps/web3mail`)
|
|
13
|
+
// Handle network errors
|
|
14
|
+
.catch((error) => {
|
|
15
|
+
throw new CompassCallError(
|
|
16
|
+
`Connection to ${compassUrl} failed with a network error`,
|
|
17
|
+
error
|
|
18
|
+
);
|
|
19
|
+
})
|
|
20
|
+
// Handle server errors
|
|
21
|
+
.then((response) => {
|
|
22
|
+
if (response.status >= 500 && response.status <= 599) {
|
|
23
|
+
throw new CompassCallError(
|
|
24
|
+
`Server at ${compassUrl} encountered an internal error`,
|
|
25
|
+
Error(
|
|
26
|
+
`Server internal error: ${response.status} ${response.statusText}`
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return response;
|
|
31
|
+
})
|
|
32
|
+
// Handle unexpected response formats
|
|
33
|
+
.then((response) => {
|
|
34
|
+
if (response.status !== 200) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Failed to fetch dapp address from compass: ${response.statusText}`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const contentType = response.headers.get('Content-Type');
|
|
40
|
+
if (!contentType || contentType.indexOf('application/json') === -1) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
'Failed to fetch dapp address from compass: response is not JSON'
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return response.json();
|
|
46
|
+
})
|
|
47
|
+
.then((data) => {
|
|
48
|
+
if (!data || !data.address) {
|
|
49
|
+
throw new Error(`No dapp address found in compass response`);
|
|
50
|
+
}
|
|
51
|
+
return data.address;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return address;
|
|
55
|
+
}
|
|
@@ -29,6 +29,9 @@ export const getValidContact = async (
|
|
|
29
29
|
graphQLClient: GraphQLClient,
|
|
30
30
|
contacts: Contact[]
|
|
31
31
|
): Promise<Contact[]> => {
|
|
32
|
+
if (contacts.length === 0) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
32
35
|
try {
|
|
33
36
|
// Contacts addresses
|
|
34
37
|
const contactsAddresses = contacts.map((contact) => contact.address);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractProvider, AbstractSigner, Eip1193Provider } from 'ethers';
|
|
2
2
|
import { IExec } from 'iexec';
|
|
3
|
+
import { GraphQLClient } from 'graphql-request';
|
|
3
4
|
import { fetchUserContacts } from './fetchUserContacts.js';
|
|
4
5
|
import { fetchMyContacts } from './fetchMyContacts.js';
|
|
5
6
|
import { sendEmail } from './sendEmail.js';
|
|
@@ -13,66 +14,76 @@ import {
|
|
|
13
14
|
Web3SignerProvider,
|
|
14
15
|
FetchMyContactsParams,
|
|
15
16
|
} from './types.js';
|
|
16
|
-
import { GraphQLClient } from 'graphql-request';
|
|
17
|
-
import {
|
|
18
|
-
WEB3_MAIL_DAPP_ADDRESS,
|
|
19
|
-
IPFS_UPLOAD_URL,
|
|
20
|
-
DEFAULT_IPFS_GATEWAY,
|
|
21
|
-
DATAPROTECTOR_SUBGRAPH_ENDPOINT,
|
|
22
|
-
WHITELIST_SMART_CONTRACT_ADDRESS,
|
|
23
|
-
} from '../config/config.js';
|
|
24
17
|
import { isValidProvider } from '../utils/validators.js';
|
|
18
|
+
import { getChainIdFromProvider } from '../utils/getChainId.js';
|
|
19
|
+
import { getChainDefaultConfig } from '../config/config.js';
|
|
20
|
+
import { resolveDappAddressFromCompass } from '../utils/resolveDappAddressFromCompass.js';
|
|
21
|
+
|
|
22
|
+
type EthersCompatibleProvider =
|
|
23
|
+
| AbstractProvider
|
|
24
|
+
| AbstractSigner
|
|
25
|
+
| Eip1193Provider
|
|
26
|
+
| Web3SignerProvider
|
|
27
|
+
| string;
|
|
28
|
+
|
|
29
|
+
interface Web3mailResolvedConfig {
|
|
30
|
+
dappAddressOrENS: AddressOrENS;
|
|
31
|
+
dappWhitelistAddress: AddressOrENS;
|
|
32
|
+
graphQLClient: GraphQLClient;
|
|
33
|
+
ipfsNode: string;
|
|
34
|
+
ipfsGateway: string;
|
|
35
|
+
defaultWorkerpool: string;
|
|
36
|
+
iexec: IExec;
|
|
37
|
+
}
|
|
25
38
|
|
|
26
39
|
export class IExecWeb3mail {
|
|
27
|
-
private
|
|
40
|
+
private dappAddressOrENS!: AddressOrENS;
|
|
41
|
+
|
|
42
|
+
private dappWhitelistAddress!: AddressOrENS;
|
|
43
|
+
|
|
44
|
+
private graphQLClient!: GraphQLClient;
|
|
45
|
+
|
|
46
|
+
private ipfsNode!: string;
|
|
28
47
|
|
|
29
|
-
private
|
|
48
|
+
private ipfsGateway!: string;
|
|
30
49
|
|
|
31
|
-
private
|
|
50
|
+
private defaultWorkerpool!: string;
|
|
32
51
|
|
|
33
|
-
private
|
|
52
|
+
private iexec!: IExec;
|
|
34
53
|
|
|
35
|
-
private
|
|
54
|
+
private initPromise: Promise<void> | null = null;
|
|
36
55
|
|
|
37
|
-
private
|
|
56
|
+
private ethProvider: EthersCompatibleProvider;
|
|
38
57
|
|
|
39
|
-
private
|
|
58
|
+
private options: Web3MailConfigOptions;
|
|
40
59
|
|
|
41
60
|
constructor(
|
|
42
|
-
ethProvider?:
|
|
43
|
-
| Eip1193Provider
|
|
44
|
-
| AbstractProvider
|
|
45
|
-
| AbstractSigner
|
|
46
|
-
| Web3SignerProvider
|
|
47
|
-
| string,
|
|
61
|
+
ethProvider?: EthersCompatibleProvider,
|
|
48
62
|
options?: Web3MailConfigOptions
|
|
49
63
|
) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
options?.iexecOptions
|
|
54
|
-
);
|
|
55
|
-
} catch (e) {
|
|
56
|
-
throw Error('Unsupported ethProvider');
|
|
57
|
-
}
|
|
64
|
+
this.ethProvider = ethProvider || 'bellecour';
|
|
65
|
+
this.options = options || {};
|
|
66
|
+
}
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
async init(): Promise<void> {
|
|
69
|
+
if (!this.initPromise) {
|
|
70
|
+
this.initPromise = this.resolveConfig().then((config) => {
|
|
71
|
+
this.dappAddressOrENS = config.dappAddressOrENS;
|
|
72
|
+
this.dappWhitelistAddress = config.dappWhitelistAddress;
|
|
73
|
+
this.graphQLClient = config.graphQLClient;
|
|
74
|
+
this.ipfsNode = config.ipfsNode;
|
|
75
|
+
this.ipfsGateway = config.ipfsGateway;
|
|
76
|
+
this.defaultWorkerpool = config.defaultWorkerpool;
|
|
77
|
+
this.iexec = config.iexec;
|
|
78
|
+
});
|
|
65
79
|
}
|
|
66
|
-
|
|
67
|
-
this.dappAddressOrENS = options?.dappAddressOrENS || WEB3_MAIL_DAPP_ADDRESS;
|
|
68
|
-
this.ipfsNode = options?.ipfsNode || IPFS_UPLOAD_URL;
|
|
69
|
-
this.ipfsGateway = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY;
|
|
70
|
-
this.dappWhitelistAddress =
|
|
71
|
-
options?.dappWhitelistAddress || WHITELIST_SMART_CONTRACT_ADDRESS;
|
|
80
|
+
return this.initPromise;
|
|
72
81
|
}
|
|
73
82
|
|
|
74
83
|
async fetchMyContacts(args?: FetchMyContactsParams): Promise<Contact[]> {
|
|
84
|
+
await this.init();
|
|
75
85
|
await isValidProvider(this.iexec);
|
|
86
|
+
|
|
76
87
|
return fetchMyContacts({
|
|
77
88
|
...args,
|
|
78
89
|
iexec: this.iexec,
|
|
@@ -82,7 +93,9 @@ export class IExecWeb3mail {
|
|
|
82
93
|
});
|
|
83
94
|
}
|
|
84
95
|
|
|
85
|
-
fetchUserContacts(args: FetchUserContactsParams): Promise<Contact[]> {
|
|
96
|
+
async fetchUserContacts(args: FetchUserContactsParams): Promise<Contact[]> {
|
|
97
|
+
await this.init();
|
|
98
|
+
|
|
86
99
|
return fetchUserContacts({
|
|
87
100
|
...args,
|
|
88
101
|
iexec: this.iexec,
|
|
@@ -93,16 +106,92 @@ export class IExecWeb3mail {
|
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
async sendEmail(args: SendEmailParams): Promise<SendEmailResponse> {
|
|
109
|
+
await this.init();
|
|
96
110
|
await isValidProvider(this.iexec);
|
|
97
111
|
return sendEmail({
|
|
98
112
|
...args,
|
|
113
|
+
workerpoolAddressOrEns:
|
|
114
|
+
args.workerpoolAddressOrEns || this.defaultWorkerpool,
|
|
99
115
|
iexec: this.iexec,
|
|
100
116
|
ipfsNode: this.ipfsNode,
|
|
101
117
|
ipfsGateway: this.ipfsGateway,
|
|
102
118
|
dappAddressOrENS: this.dappAddressOrENS,
|
|
103
119
|
dappWhitelistAddress: this.dappWhitelistAddress,
|
|
104
120
|
graphQLClient: this.graphQLClient,
|
|
105
|
-
useVoucher: args?.useVoucher,
|
|
106
121
|
});
|
|
107
122
|
}
|
|
123
|
+
|
|
124
|
+
private async resolveConfig(): Promise<Web3mailResolvedConfig> {
|
|
125
|
+
const chainId = await getChainIdFromProvider(this.ethProvider);
|
|
126
|
+
const chainDefaultConfig = getChainDefaultConfig(chainId, {
|
|
127
|
+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const ipfsGateway =
|
|
131
|
+
this.options?.ipfsGateway || chainDefaultConfig?.ipfsGateway;
|
|
132
|
+
|
|
133
|
+
let iexec: IExec, graphQLClient: GraphQLClient;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
iexec = new IExec(
|
|
137
|
+
{ ethProvider: this.ethProvider },
|
|
138
|
+
{
|
|
139
|
+
ipfsGatewayURL: ipfsGateway,
|
|
140
|
+
...this.options?.iexecOptions,
|
|
141
|
+
allowExperimentalNetworks: this.options.allowExperimentalNetworks,
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
} catch (e: any) {
|
|
145
|
+
throw new Error(`Unsupported ethProvider: ${e.message}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const subgraphUrl =
|
|
149
|
+
this.options?.dataProtectorSubgraph ||
|
|
150
|
+
chainDefaultConfig?.dataProtectorSubgraph;
|
|
151
|
+
const dappAddressOrENS =
|
|
152
|
+
this.options?.dappAddressOrENS ||
|
|
153
|
+
chainDefaultConfig?.dappAddress ||
|
|
154
|
+
(await resolveDappAddressFromCompass(
|
|
155
|
+
await iexec.config.resolveCompassURL(),
|
|
156
|
+
chainId
|
|
157
|
+
));
|
|
158
|
+
const dappWhitelistAddress =
|
|
159
|
+
this.options?.dappWhitelistAddress ||
|
|
160
|
+
chainDefaultConfig?.whitelistSmartContract;
|
|
161
|
+
const defaultWorkerpool = chainDefaultConfig?.prodWorkerpoolAddress;
|
|
162
|
+
const ipfsNode =
|
|
163
|
+
this.options?.ipfsNode || chainDefaultConfig?.ipfsUploadUrl;
|
|
164
|
+
|
|
165
|
+
const missing = [];
|
|
166
|
+
if (!subgraphUrl) missing.push('dataProtectorSubgraph');
|
|
167
|
+
if (!dappAddressOrENS) missing.push('dappAddress');
|
|
168
|
+
if (!dappWhitelistAddress) missing.push('whitelistSmartContract');
|
|
169
|
+
if (!ipfsGateway) missing.push('ipfsGateway');
|
|
170
|
+
if (!defaultWorkerpool) missing.push('prodWorkerpoolAddress');
|
|
171
|
+
if (!ipfsNode) missing.push('ipfsUploadUrl');
|
|
172
|
+
|
|
173
|
+
if (missing.length > 0) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`Missing required configuration for chainId ${chainId}: ${missing.join(
|
|
176
|
+
', '
|
|
177
|
+
)}`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
graphQLClient = new GraphQLClient(subgraphUrl);
|
|
183
|
+
} catch (error: any) {
|
|
184
|
+
throw new Error(`Failed to create GraphQLClient: ${error.message}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
dappAddressOrENS,
|
|
189
|
+
dappWhitelistAddress: dappWhitelistAddress.toLowerCase(),
|
|
190
|
+
defaultWorkerpool,
|
|
191
|
+
graphQLClient,
|
|
192
|
+
ipfsNode,
|
|
193
|
+
ipfsGateway,
|
|
194
|
+
iexec,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
108
197
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import {
|
|
3
|
+
CALLBACK_WEB3MAIL,
|
|
3
4
|
DEFAULT_CONTENT_TYPE,
|
|
4
5
|
MAX_DESIRED_APP_ORDER_PRICE,
|
|
5
6
|
MAX_DESIRED_DATA_ORDER_PRICE,
|
|
6
7
|
MAX_DESIRED_WORKERPOOL_ORDER_PRICE,
|
|
7
|
-
PROD_WORKERPOOL_ADDRESS,
|
|
8
8
|
} from '../config/config.js';
|
|
9
9
|
import { handleIfProtocolError, WorkflowError } from '../utils/errors.js';
|
|
10
10
|
import { generateSecureUniqueId } from '../utils/generateUniqueId.js';
|
|
@@ -42,7 +42,7 @@ export type SendEmail = typeof sendEmail;
|
|
|
42
42
|
export const sendEmail = async ({
|
|
43
43
|
graphQLClient = throwIfMissing(),
|
|
44
44
|
iexec = throwIfMissing(),
|
|
45
|
-
workerpoolAddressOrEns
|
|
45
|
+
workerpoolAddressOrEns,
|
|
46
46
|
dappAddressOrENS,
|
|
47
47
|
dappWhitelistAddress,
|
|
48
48
|
ipfsNode,
|
|
@@ -269,6 +269,7 @@ export const sendEmail = async ({
|
|
|
269
269
|
contentType: vContentType,
|
|
270
270
|
senderName: vSenderName,
|
|
271
271
|
emailContentEncryptionKey,
|
|
272
|
+
useCallback: true,
|
|
272
273
|
})
|
|
273
274
|
);
|
|
274
275
|
|
|
@@ -281,6 +282,7 @@ export const sendEmail = async ({
|
|
|
281
282
|
workerpoolmaxprice: workerpoolorder.workerpoolprice,
|
|
282
283
|
tag: ['tee', 'scone'],
|
|
283
284
|
workerpool: vWorkerpoolAddressOrEns,
|
|
285
|
+
callback: CALLBACK_WEB3MAIL,
|
|
284
286
|
params: {
|
|
285
287
|
iexec_secrets: {
|
|
286
288
|
1: requesterSecretId,
|
package/src/web3mail/types.ts
CHANGED
|
@@ -108,6 +108,13 @@ export type Web3MailConfigOptions = {
|
|
|
108
108
|
* If not provided, the default IPFS gateway URL will be used.
|
|
109
109
|
*/
|
|
110
110
|
ipfsGateway?: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* if true allows using a provider connected to an experimental networks (default false)
|
|
114
|
+
*
|
|
115
|
+
* ⚠️ experimental networks are networks on which the iExec's stack is partially deployed, experimental networks can be subject to instabilities or discontinuity. Access is provided without warranties.
|
|
116
|
+
*/
|
|
117
|
+
allowExperimentalNetworks?: boolean;
|
|
111
118
|
};
|
|
112
119
|
|
|
113
120
|
export type DappAddressConsumer = {
|