Nostr WoT

Documentación

Todo lo que necesitas para integrar Web of Trust en tu aplicación.

Inicio Rápido

Get up and running with Web of Trust in just a few minutes.

Client-side (with the SDK)

For client-side applications, use the SDK's Web of Trust module. Install nostr-wot-sdk and query hop distance right in the browser.

1. Install

terminal
$npm install nostr-wot-sdk

2. Query Trust Distance

typescript
import { WoT } from "@nostr-wot/wot";

const wot = new WoT({ rootPubkey: "hex-your-pubkey", maxHops: 2 });

// Get hop distance to a target pubkey
const result = await wot.getDistance("hex-target-pubkey");

if (result && result.hops <= 2) {
  // Within web of trust
  console.log(`Trusted: ${result.hops} hops away`);
} else {
  // Outside web of trust or not connected
  console.log("Not in your web of trust");
}

Tip: Hop values: 0 = yourself, 1 = direct follow, 2 = follow of follow, null = not connected. If the WoT extension is installed, the module answers queries from its locally-cached follow graph automatically.

Servidor (con API Oracle)

For server-side applications, use the Oracle REST API. No extension required.

Using fetch

javascript
const response = await fetch(
  `https://wot-oracle.mappingbitcoin.com/distance?` +
  `from=${fromPubkey}&to=${toPubkey}`
);
const data = await response.json();

console.log(`Distance: ${data.distance}`);
console.log(`Paths: ${data.paths}`);
console.log(`Mutual follow: ${data.mutual}`);

Using cURL

terminal
$curl "https://wot-oracle.mappingbitcoin.com/distance?from=82341f...&to=3bf0c6..."

Using the SDK in React

For React apps, wrap your tree in <NostrSdkProvider> — it wires up the data layer (profiles, notes, threads, engagement) and enables the Web of Trust module when you opt in. Trust hooks are then available anywhere.

tsx
import { NostrSdkProvider, useTrustScore } from "nostr-wot-sdk/react";

function App() {
  return (
    <NostrSdkProvider
      relays={["wss://relay.damus.io", "wss://nos.lol"]}
      wot={{ enabled: true, options: { maxHops: 2 } }}
    >
      <Feed />
    </NostrSdkProvider>
  );
}

function TrustBadge({ pubkey }: { pubkey: string }) {
  const score = useTrustScore(pubkey); // 0..1 or null
  return score !== null ? <span>Trusted</span> : null;
}

Compilar desde el Código Fuente

Clona el repositorio y compila localmente para desarrollo o para verificar el código.

terminal
$git clone https://github.com/nostr-wot/nostr-wot-extension.git
$cd nostr-wot-extension && npm install && npm run build

Ve a chrome://extensions, activa Modo desarrollador, haz clic en Cargar descomprimida y selecciona la carpeta dist/.