Nostr WoT

Web of Trust distances

WoT queries the Oracle by default. getDistance returns a number or null; isInMyWoT returns a boolean. getDetails provides hops, a numeric path count, and optional bridges and mutual-follow information. Pass valid 64-character hexadecimal public keys.

Migrating to @nostr-wot/wot 1.0.0

Version 1.0.0 removed browser-extension detection, trust-score methods, and useTrustScore. Use useWoT or useIsInWoT and read their result objects. For local queries, pass a WoTLocalSource, such as WotGraph.asWoTSource() from @nostr-wot/wot/graph. Only getDistance, isInMyWoT, and filterByWoT use that source; other methods still query the Oracle.

Local graph example

Load and crawl a local graph before passing its source to WoT. The React example receives this prepared graph and uses useIsInWoT; useWoT also requests getDetails from the Oracle. @nostr-wot/wot/graph has its own getScore API, separate from the removed WoT score API.

terminal
$npm install @nostr-wot/wot@3.0.0 nostr-wot-sdk@3.0.0 nostr-tools
typescript
import { WotGraph } from "@nostr-wot/wot/graph";
import { WoT } from "@nostr-wot/wot";

async function prepareGraph(myPubkey: string, targetPubkey: string) {
  const graph = new WotGraph({
    namespace: "my-app",
    relays: ["wss://relay.damus.io", "wss://nos.lol"],
  });
  await graph.load();
  await graph.crawl(myPubkey, { maxDepth: 2 });
  const wot = new WoT({ source: graph.asWoTSource(), maxHops: 2 });
  const distance = await wot.getDistance(targetPubkey);
  const inWoT = await wot.isInMyWoT(targetPubkey);
  return { graph, distance, inWoT };
}
tsx
"use client";
import type { WotGraph } from "@nostr-wot/wot/graph";
import { NostrSdkProvider, useIsInWoT } from "nostr-wot-sdk/react";

function FollowBadge({ pubkey }: { pubkey: string }) {
  const { inWoT, loading, error } = useIsInWoT(pubkey, { maxHops: 2 });
  if (loading || error || !inWoT) return null;
  return <span>{pubkey}</span>;
}

function LocalTrust({ graph, pubkey }: { graph: WotGraph; pubkey: string }) {
  return (
    <NostrSdkProvider wot={{ enabled: true, options: { source: graph.asWoTSource() } }}>
      <FollowBadge pubkey={pubkey} />
    </NostrSdkProvider>
  );
}