1
0
forked from Kieran/snort
snort4/packages/worker-relay
2024-01-30 20:38:48 +00:00
..
src chore: add worker-relay readme 2024-01-30 20:32:43 +00:00
package.json chore: add worker-relay readme 2024-01-30 20:32:43 +00:00
README.md chore: Update translations 2024-01-30 20:38:48 +00:00
tsconfig.json chore: publish worker-relay 2024-01-30 20:09:38 +00:00
typedoc.json feat: worker-relay pkg 2024-01-15 16:57:20 +00:00

Worker Relay

Worker relay is a Nostr relay built on sqlite-wasm

WorkerRelayInterface is the class which accepts the URL of the worker script

sqlite-wasm uses OFPS in order to persist the database.

OPFS requires special headers to be present when serving your application. Read more about it here

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

Usage (Vite)

import WorkerRelayPath from "@snort/worker-relay/dist/worker?worker&url";

Example

const relay = new WorkerRelayInterface(WorkerRelayPath);

// load sqlite database and run migrations
await relay.init();

// Query worker relay with regular nostr REQ command
const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);

// publish a new event to the relay
const myEvent = {
  kind: 1,
  content: "test",
};
if (await relay.event(myEvent)) {
  console.log("Success");
}