Nostr WoT

Distanze della rete di fiducia

WoT interroga l’Oracle per impostazione predefinita. getDistance restituisce un numero o null; isInMyWoT restituisce un booleano. getDetails fornisce i salti, un numero di percorsi e informazioni opzionali sui collegamenti intermedi e sui follow reciproci. Usa chiavi pubbliche esadecimali valide di 64 caratteri.

Migrazione a @nostr-wot/wot 1.0.0

La versione 1.0.0 ha rimosso il rilevamento dell’estensione, i metodi di punteggio di fiducia e useTrustScore. Usa useWoT o useIsInWoT e leggi i loro oggetti risultato. Per query locali, passa una WoTLocalSource, come WotGraph.asWoTSource() di @nostr-wot/wot/graph. Solo getDistance, isInMyWoT e filterByWoT usano questa fonte; gli altri metodi interrogano ancora l’Oracle.

Esempio di grafo locale

Carica ed esplora un grafo locale prima di passarne la fonte a WoT. L’esempio React riceve questo grafo preparato e usa useIsInWoT; useWoT richiede anche getDetails all’Oracle. @nostr-wot/wot/graph ha una propria API getScore, distinta dall’API di punteggio rimossa da WoT.

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