UNPKG

@iexec/web3mail

Version:

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

19 lines 712 B
import { create } from 'kubo-rpc-client'; const get = async (cid, { ipfsGateway } = {}) => { const multiaddr = `/ipfs/${cid.toString()}`; const publicUrl = `${ipfsGateway}${multiaddr}`; const res = await fetch(publicUrl); if (!res.ok) { throw Error(`Failed to load content from ${publicUrl}`); } const arrayBuffer = await res.arrayBuffer(); return new Uint8Array(arrayBuffer); }; const add = async (content, { ipfsNode, ipfsGateway } = {}) => { const ipfsClient = create(ipfsNode); const { cid } = await ipfsClient.add(content); await get(cid.toString(), { ipfsGateway }); return cid.toString(); }; export { add, get }; //# sourceMappingURL=ipfs-service.js.map