@iexec/web3telegram
Version:
Enables secure, blockchain-based messaging by encrypting Telegram user IDs for privacy. It lets users message Ethereum account holders without knowing their Telegram details.
29 lines (24 loc) • 788 B
text/typescript
import { create } from 'kubo-rpc-client';
interface GetOptions {
ipfsGateway?: string;
}
interface AddOptions extends GetOptions {
ipfsNode?: string;
}
const get = async (cid, { ipfsGateway }: GetOptions = {}) => {
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 }: AddOptions = {}) => {
const ipfsClient = create(ipfsNode);
const { cid } = await ipfsClient.add(content);
await get(cid.toString(), { ipfsGateway });
return cid.toString();
};
export { add, get };