@omnipin/isheika
v0.1.3
Published
Minimal [Swarm](https://www.ethswarm.org/) (Ethereum Swarm) micro-client for the browser — `discover`, `fetch`, and `upload` over libp2p WebSocket. This is the WebAssembly build of [`omnipin/isheika`](https://github.com/omnipin/isheika); for the native CL
Readme
@omnipin/isheika
Minimal Swarm (Ethereum Swarm) micro-client for the
browser — discover, fetch, and upload over libp2p WebSocket. This is the
WebAssembly build of omnipin/isheika; for
the native CLI, see the repository.
Install
npm install @omnipin/isheikaUsage
ESM, no bundler required (this is a wasm-bindgen --target web build — call the
default init() once to load the wasm module):
import init, { IsheikaClient, initThreadPool } from "@omnipin/isheika";
await init(); // instantiate the wasm
await initThreadPool(navigator.hardwareConcurrency); // optional: parallel hashing
// All constructor args optional: (privateKeyHex?, networkId = 1, dohUrl?, timeoutSecs = 30)
const client = new IsheikaClient();
const peers = await client.discover("/dnsaddr/mainnet.ethswarm.org", 5); // -> peer count
const bytes = await client.fetch(rootHex, /* maxRetries */ 3); // -> Uint8Array
// upload needs a signer key and a postage batch:
const signer = new IsheikaClient(privateKeyHex);
const root = await signer.upload(data, batchIdHex, depth, 3); // -> root hash hexPeer-store helpers: loadPeers(json), exportPeers(), peerCount().
Cross-origin isolation
The module is built with threads (atomics + shared memory), so the page must be
cross-origin isolated
to use SharedArrayBuffer. Serve the page with:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corpLicense
MIT — see omnipin/isheika.
