Nostr WoT

Distanzen im Vertrauensnetzwerk

WoT fragt standardmäßig das Oracle ab. getDistance liefert eine Zahl oder null; isInMyWoT liefert einen booleschen Wert. getDetails liefert die Hop-Anzahl, eine numerische Pfadanzahl und optionale Angaben zu Zwischenverbindungen und gegenseitigen Follows. Verwende gültige öffentliche Schlüssel mit 64 Hexadezimalzeichen.

Migration auf @nostr-wot/wot 1.0.0

Version 1.0.0 entfernte die Erweiterungserkennung, Methoden für Vertrauenswerte und useTrustScore. Verwende useWoT oder useIsInWoT und lies deren Ergebnisobjekte aus. Für lokale Abfragen übergib eine WoTLocalSource, etwa WotGraph.asWoTSource() aus @nostr-wot/wot/graph. Nur getDistance, isInMyWoT und filterByWoT nutzen diese Quelle; andere Methoden fragen weiterhin das Oracle ab.

Beispiel mit lokalem Graphen

Lade und erfasse einen lokalen Graphen, bevor du seine Quelle an WoT übergibst. Das React-Beispiel erhält diesen vorbereiteten Graphen und nutzt useIsInWoT; useWoT fragt zusätzlich getDetails beim Oracle ab. @nostr-wot/wot/graph hat eine eigene getScore-API, getrennt von der entfernten 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>
  );
}