Nostr WoT

Distances du réseau de confiance

WoT interroge l’Oracle par défaut. getDistance renvoie un nombre ou null ; isInMyWoT renvoie un booléen. getDetails fournit les sauts, un nombre de chemins et des informations optionnelles sur les intermédiaires et les abonnements mutuels. Utilisez des clés publiques hexadécimales valides de 64 caractères.

Migration vers @nostr-wot/wot 1.0.0

La version 1.0.0 a supprimé la détection d’extension, les méthodes de score de confiance et useTrustScore. Utilisez useWoT ou useIsInWoT et lisez leurs objets de résultat. Pour les requêtes locales, fournissez un WoTLocalSource, par exemple WotGraph.asWoTSource() de @nostr-wot/wot/graph. Seuls getDistance, isInMyWoT et filterByWoT utilisent cette source ; les autres méthodes interrogent toujours l’Oracle.

Exemple de graphe local

Chargez et parcourez un graphe local avant de transmettre sa source à WoT. L’exemple React reçoit ce graphe préparé et utilise useIsInWoT ; useWoT demande aussi getDetails à l’Oracle. @nostr-wot/wot/graph possède sa propre API getScore, distincte de l’API de score supprimée de WoT.

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>
  );
}