Extension API
The WoT Extension injects window.nostr.wot into every page for client-side trust queries.
Prerequisite: Users must have the WoT Extension installed and configured.
Setup
Always check for extension availability before using the API:
// Feature detection
function hasWoT() {
return typeof window !== "undefined" &&
window.nostr?.wot !== undefined;
}
// Wait for extension to load
async function waitForWoT(timeout = 3000) {
const start = Date.now();
while (!hasWoT() && Date.now() - start < timeout) {
await new Promise(r => setTimeout(r, 100));
}
return hasWoT();
}Core Methods
getDistance(targetPubkey)
Returns the number of hops from your pubkey to the target.
Parameters
| Name | Type | Description |
|---|---|---|
targetPubkey | string | Hex or npub format pubkey |
Returns
Promise<number | null>
Example
const distance = await window.nostr.wot.getDistance(
"3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d"
);
switch (distance) {
case null: console.log("Not connected"); break;
case 0: console.log("This is you"); break;
case 1: console.log("Direct follow"); break;
default: console.log(`${distance} hops away`);
}isInMyWoT(targetPubkey, maxHops?)
Boolean check if a pubkey is within your web of trust threshold.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
targetPubkey | string | - | Hex or npub format pubkey |
maxHops | number | 3 | Maximum hops to consider "trusted" |
Returns
Promise<boolean>
Example
// Check with default threshold (3 hops)
const trusted = await window.nostr.wot.isInMyWoT(pubkey);
// Stricter check (2 hops)
const veryTrusted = await window.nostr.wot.isInMyWoT(pubkey, 2);getDistanceBetween(fromPubkey, toPubkey)
Get the distance between any two pubkeys (not just from you).
Parameters
| Name | Type | Description |
|---|---|---|
fromPubkey | string | Source pubkey |
toPubkey | string | Target pubkey |
Returns
Promise<number | null>
Example
const distance = await window.nostr.wot.getDistanceBetween(
alicePubkey,
bobPubkey
);
if (distance === 1) {
console.log("Alice follows Bob directly");
}getTrustScore(targetPubkey)
Get a normalized trust score (0-1) based on distance and path count.
Parameters
| Name | Type | Description |
|---|---|---|
targetPubkey | string | Hex or npub format pubkey |
Returns
Promise<number | null>
score = distanceWeight + pathBonus
Distance Weights
- 1 hop: 1.0
- 2 hops: 0.5
- 3 hops: 0.25
- 4+ hops: 0.1
Path Bonuses
- 2 hops: +0.05 per path
- 3 hops: +0.02 per path
- 4+ hops: +0.01 per path
- Max bonus: 0.25
Example
const score = await window.nostr.wot.getTrustScore(pubkey);
if (score === null) {
console.log("Not connected");
} else if (score >= 0.7) {
console.log("Highly trusted");
} else if (score >= 0.3) {
console.log("Somewhat trusted");
} else {
console.log("Low trust score");
}getDetails(targetPubkey)
Get comprehensive trust information including distance, score, paths, and bridging nodes.
Parameters
| Name | Type | Description |
|---|---|---|
targetPubkey | string | Hex or npub format pubkey |
Returns
Promise<TrustDetails | null>
Example
const details = await window.nostr.wot.getDetails(pubkey);
if (details) {
console.log(`Distance: ${details.distance} hops`);
console.log(`Trust score: ${details.score}`);
console.log(`Connection paths: ${details.paths}`);
console.log(`Mutual follow: ${details.mutual}`);
console.log(`Bridging nodes: ${details.bridgingNodes.join(", ")}`);
}getConfig()
Get the current extension configuration.
Returns
Promise<WoTConfig>
Example
const config = await window.nostr.wot.getConfig();
console.log(`Mode: ${config.mode}`); // "remote", "local", or "hybrid"
console.log(`Max hops: ${config.maxHops}`);
console.log(`Timeout: ${config.timeout}ms`);Batch Operations
getDistanceBatch(targets)
Get distances for multiple pubkeys in a single call.
Parameters
| Name | Type | Description |
|---|---|---|
targets | string[] | Array of hex pubkeys |
Returns
Promise<Record<string, number | null>>
Example
const distances = await window.nostr.wot.getDistanceBatch([
"pubkey1...",
"pubkey2...",
"pubkey3..."
]);
// { "pubkey1...": 1, "pubkey2...": 2, "pubkey3...": null }getTrustScoreBatch(targets)
Get trust scores for multiple pubkeys in a single call.
Parameters
| Name | Type | Description |
|---|---|---|
targets | string[] | Array of hex pubkeys |
Returns
Promise<Record<string, number | null>>
Example
const scores = await window.nostr.wot.getTrustScoreBatch([
"pubkey1...",
"pubkey2...",
"pubkey3..."
]);
// { "pubkey1...": 0.95, "pubkey2...": 0.45, "pubkey3...": null }filterByWoT(pubkeys, maxHops?)
Filter a list of pubkeys to only those within the Web of Trust.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pubkeys | string[] | - | Array of hex pubkeys |
maxHops | number | 3 | Override default max hops |
Returns
Promise<string[]>
Example
const allPubkeys = ["pk1...", "pk2...", "pk3...", "pk4..."];
// Filter to only trusted pubkeys (within 3 hops)
const trusted = await window.nostr.wot.filterByWoT(allPubkeys);
// Stricter filtering (2 hops)
const veryTrusted = await window.nostr.wot.filterByWoT(allPubkeys, 2);User Info
getMyPubkey()
Returns the configured user's pubkey.
Returns
Promise<string | null>
Example
const myPubkey = await window.nostr.wot.getMyPubkey();
if (myPubkey) {
console.log(`Configured as: ${myPubkey}`);
} else {
console.log("Extension not configured");
}isConfigured()
Check if the extension is configured and ready.
Returns
Promise<ConfigStatus>
Example
const status = await window.nostr.wot.isConfigured();
if (status.configured) {
console.log(`Mode: ${status.mode}`);
console.log(`Has local graph: ${status.hasLocalGraph}`);
} else {
console.log("Please configure the extension");
}Graph Queries
getFollows(pubkey?)
Get the follow list for a pubkey.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pubkey | string | user's pubkey | Hex pubkey (defaults to user's pubkey) |
Returns
Promise<string[]>
Example
// Get your own follows
const myFollows = await window.nostr.wot.getFollows();
// Get someone else's follows
const theirFollows = await window.nostr.wot.getFollows("pubkey...");
console.log(`Following ${myFollows.length} accounts`);getCommonFollows(pubkey)
Get accounts that both you and the target follow.
Parameters
| Name | Type | Description |
|---|---|---|
pubkey | string | Hex pubkey to compare with |
Returns
Promise<string[]>
Example
const common = await window.nostr.wot.getCommonFollows(pubkey);
console.log(`You both follow ${common.length} accounts`);getStats()
Get statistics about the local graph cache.
Returns
Promise<GraphStats>
Example
const stats = await window.nostr.wot.getStats();
console.log(`Total users: ${stats.totalUsers}`);
console.log(`Total follows: ${stats.totalFollows}`);
console.log(`Last updated: ${stats.lastUpdated}`);getPath(targetPubkey)
Get the shortest path from you to the target pubkey.
Parameters
| Name | Type | Description |
|---|---|---|
targetPubkey | string | Hex pubkey to find path to |
Returns
Promise<string[] | null>
Example
const path = await window.nostr.wot.getPath(targetPubkey);
if (path) {
console.log("Connection path:");
path.forEach((pk, i) => {
console.log(` ${i + 1}. ${pk}`);
});
} else {
console.log("No path found");
}