UNPKG

@iexec/web3mail

Version:

This product enables users to confidentially store data–such as mail address, documents, personal information ...

70 lines 2.67 kB
import { IExec } from 'iexec'; import { fetchUserContacts } from './fetchUserContacts.js'; import { fetchMyContacts } from './fetchMyContacts.js'; import { sendEmail } from './sendEmail.js'; import { GraphQLClient } from 'graphql-request'; import { WEB3_MAIL_DAPP_ADDRESS, IPFS_UPLOAD_URL, DEFAULT_IPFS_GATEWAY, DATAPROTECTOR_SUBGRAPH_ENDPOINT, WHITELIST_SMART_CONTRACT_ADDRESS, } from '../config/config.js'; import { isValidProvider } from '../utils/validators.js'; export class IExecWeb3mail { iexec; ipfsNode; ipfsGateway; dataProtectorSubgraph; dappAddressOrENS; dappWhitelistAddress; graphQLClient; constructor(ethProvider, options) { try { this.iexec = new IExec({ ethProvider: ethProvider || 'bellecour' }, options?.iexecOptions); } catch (e) { throw Error('Unsupported ethProvider'); } try { this.dataProtectorSubgraph = options?.dataProtectorSubgraph || DATAPROTECTOR_SUBGRAPH_ENDPOINT; this.graphQLClient = new GraphQLClient(this.dataProtectorSubgraph); } catch (e) { throw Error('Impossible to create GraphQLClient'); } this.dappAddressOrENS = options?.dappAddressOrENS || WEB3_MAIL_DAPP_ADDRESS; this.ipfsNode = options?.ipfsNode || IPFS_UPLOAD_URL; this.ipfsGateway = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY; this.dappWhitelistAddress = options?.dappWhitelistAddress || WHITELIST_SMART_CONTRACT_ADDRESS; } async fetchMyContacts(args) { await isValidProvider(this.iexec); return fetchMyContacts({ ...args, iexec: this.iexec, graphQLClient: this.graphQLClient, dappAddressOrENS: this.dappAddressOrENS, dappWhitelistAddress: this.dappWhitelistAddress, }); } fetchUserContacts(args) { return fetchUserContacts({ ...args, iexec: this.iexec, graphQLClient: this.graphQLClient, dappAddressOrENS: this.dappAddressOrENS, dappWhitelistAddress: this.dappWhitelistAddress, }); } async sendEmail(args) { await isValidProvider(this.iexec); return sendEmail({ ...args, iexec: this.iexec, ipfsNode: this.ipfsNode, ipfsGateway: this.ipfsGateway, dappAddressOrENS: this.dappAddressOrENS, dappWhitelistAddress: this.dappWhitelistAddress, graphQLClient: this.graphQLClient, useVoucher: args?.useVoucher, }); } } //# sourceMappingURL=IExecWeb3mail.js.map