nostr-wot-sdk 0.6.2 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -472
- package/dist/data/cache/index.cjs +14 -0
- package/dist/data/cache/index.cjs.map +1 -0
- package/dist/data/cache/index.d.cts +1 -0
- package/dist/data/cache/index.d.ts +1 -0
- package/dist/data/cache/index.js +3 -0
- package/dist/data/cache/index.js.map +1 -0
- package/dist/data/index.cjs +14 -0
- package/dist/data/index.cjs.map +1 -0
- package/dist/data/index.d.cts +1 -0
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.js +3 -0
- package/dist/data/index.js.map +1 -0
- package/dist/index.cjs +9 -616
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -623
- package/dist/index.d.ts +1 -623
- package/dist/index.js +3 -607
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +32 -911
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +36 -729
- package/dist/react/index.d.ts +36 -729
- package/dist/react/index.js +22 -903
- package/dist/react/index.js.map +1 -1
- package/dist/relay/index.cjs +14 -0
- package/dist/relay/index.cjs.map +1 -0
- package/dist/relay/index.js +3 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/relay/react/index.cjs +14 -0
- package/dist/relay/react/index.cjs.map +1 -0
- package/dist/relay/react/index.d.cts +1 -0
- package/dist/relay/react/index.d.ts +1 -0
- package/dist/relay/react/index.js +3 -0
- package/dist/relay/react/index.js.map +1 -0
- package/dist/solid/index.cjs +7 -906
- package/dist/solid/index.cjs.map +1 -1
- package/dist/solid/index.d.cts +1 -740
- package/dist/solid/index.d.ts +1 -740
- package/dist/solid/index.js +1 -901
- package/dist/solid/index.js.map +1 -1
- package/package.json +54 -24
- package/CHANGELOG.md +0 -287
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,480 +1,25 @@
|
|
|
1
1
|
# nostr-wot-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **This package is a back-compat meta re-export.** New code should depend on the scoped packages directly.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Install the [Nostr WoT Extension](https://github.com/nostr-wot/nostr-wot-extension) for the best experience. The extension downloads your follow graph locally and works across all websites.
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
import { WoT } from 'nostr-wot-sdk';
|
|
18
|
-
|
|
19
|
-
// The SDK automatically uses the extension when available
|
|
20
|
-
const wot = new WoT({
|
|
21
|
-
fallback: {
|
|
22
|
-
oracle: 'https://nostr-wot.com',
|
|
23
|
-
myPubkey: 'abc123...' // Used only if extension unavailable
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Check distance
|
|
28
|
-
const hops = await wot.getDistance('def456...');
|
|
29
|
-
console.log(hops); // 2
|
|
30
|
-
|
|
31
|
-
// Boolean check
|
|
32
|
-
const trusted = await wot.isInMyWoT('def456...', { maxHops: 3 });
|
|
33
|
-
console.log(trusted); // true
|
|
34
|
-
|
|
35
|
-
// Trust score (from extension)
|
|
36
|
-
const score = await wot.getTrustScore('def456...');
|
|
37
|
-
console.log(score); // 0.72
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
When the extension is installed, **it always takes priority** — the SDK uses the extension's pubkey and locally-cached follow graph automatically.
|
|
41
|
-
|
|
42
|
-
### Without Extension (Oracle Fallback)
|
|
43
|
-
|
|
44
|
-
```javascript
|
|
45
|
-
import { WoT } from 'nostr-wot-sdk';
|
|
46
|
-
|
|
47
|
-
const wot = new WoT({
|
|
48
|
-
oracle: 'https://nostr-wot.com',
|
|
49
|
-
myPubkey: 'abc123...' // Required for oracle fallback
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const hops = await wot.getDistance('def456...');
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Features
|
|
56
|
-
|
|
57
|
-
- **Extension-First** — Automatically uses browser extension when available
|
|
58
|
-
- **Simple API** — Three methods cover most use cases
|
|
59
|
-
- **Cross-Site Trust** — Extension provides same WoT data on all websites
|
|
60
|
-
- **Offline Support** — Extension caches data locally for offline queries
|
|
61
|
-
- **Batch Queries** — Check multiple pubkeys efficiently
|
|
62
|
-
- **TypeScript** — Full type definitions included
|
|
63
|
-
|
|
64
|
-
## API Reference
|
|
65
|
-
|
|
66
|
-
### Constructor
|
|
67
|
-
```javascript
|
|
68
|
-
const wot = new WoT(options);
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
| Option | Type | Default | Description |
|
|
72
|
-
|--------|------|---------|-------------|
|
|
73
|
-
| `oracle` | string | `'https://nostr-wot.com'` | Oracle API URL (fallback when extension unavailable) |
|
|
74
|
-
| `myPubkey` | string | — | Your pubkey (optional - fetched from extension when available) |
|
|
75
|
-
| `maxHops` | number | `3` | Default max search depth |
|
|
76
|
-
| `timeout` | number | `5000` | Request timeout (ms) |
|
|
77
|
-
| `fallback` | object | — | Fallback config when extension unavailable |
|
|
78
|
-
| `extensionId` | string | — | Chrome Web Store extension ID (for detecting "installed but not enabled" state) |
|
|
79
|
-
|
|
80
|
-
Trust scores are calculated by the extension and not configurable via the SDK.
|
|
81
|
-
|
|
82
|
-
**Note:** When the extension is installed, it always takes priority over `myPubkey` or `oracle` settings.
|
|
83
|
-
|
|
84
|
-
### Methods
|
|
85
|
-
|
|
86
|
-
#### `getDistance(target, options?)`
|
|
87
|
-
|
|
88
|
-
Get shortest path length to target pubkey.
|
|
89
|
-
```javascript
|
|
90
|
-
const hops = await wot.getDistance('def456...');
|
|
91
|
-
// Returns: number | null
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
#### `isInMyWoT(target, options?)`
|
|
95
|
-
|
|
96
|
-
Check if target is within your Web of Trust.
|
|
97
|
-
```javascript
|
|
98
|
-
const trusted = await wot.isInMyWoT('def456...', { maxHops: 2 });
|
|
99
|
-
// Returns: boolean
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
#### `getTrustScore(target)`
|
|
103
|
-
|
|
104
|
-
Get computed trust score from the extension.
|
|
105
|
-
```javascript
|
|
106
|
-
const score = await wot.getTrustScore('def456...');
|
|
107
|
-
// Returns: number (0-1), or 0 if extension unavailable
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
#### `getDistanceBetween(from, to, options?)`
|
|
111
|
-
|
|
112
|
-
Get distance between any two pubkeys.
|
|
113
|
-
```javascript
|
|
114
|
-
const hops = await wot.getDistanceBetween('abc...', 'def...');
|
|
115
|
-
// Returns: number | null
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### `batchCheck(targets, options?)`
|
|
119
|
-
|
|
120
|
-
Check multiple pubkeys efficiently.
|
|
121
|
-
```javascript
|
|
122
|
-
const results = await wot.batchCheck(['pk1...', 'pk2...', 'pk3...']);
|
|
123
|
-
// Returns: Map<string, BatchResult>
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
#### `getDetails(target, options?)`
|
|
127
|
-
|
|
128
|
-
Get distance, path count, and score details.
|
|
129
|
-
```javascript
|
|
130
|
-
const details = await wot.getDetails('def456...');
|
|
131
|
-
// Returns: { hops: 2, paths: 5, score: 0.65 }
|
|
132
|
-
// Oracle may also return: bridges, mutual (but score will be 0)
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
#### `getMyPubkey()`
|
|
136
|
-
|
|
137
|
-
Get the current pubkey (from extension or fallback).
|
|
138
|
-
```javascript
|
|
139
|
-
const pubkey = await wot.getMyPubkey();
|
|
140
|
-
// Returns: string
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
#### `isUsingExtension()`
|
|
144
|
-
|
|
145
|
-
Check if extension is available and being used.
|
|
146
|
-
```javascript
|
|
147
|
-
const usingExt = await wot.isUsingExtension();
|
|
148
|
-
// Returns: boolean
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### `getExtensionStatus()`
|
|
152
|
-
|
|
153
|
-
Get detailed extension connection status. Useful for showing appropriate UI based on why the extension isn't working.
|
|
154
|
-
```javascript
|
|
155
|
-
const status = await wot.getExtensionStatus();
|
|
156
|
-
// Returns: 'connected' | 'not-enabled' | 'unavailable' | 'not-browser'
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
| Status | Description |
|
|
160
|
-
|--------|-------------|
|
|
161
|
-
| `'connected'` | Extension is enabled and working on this domain |
|
|
162
|
-
| `'not-enabled'` | Extension is installed but not enabled for this domain |
|
|
163
|
-
| `'unavailable'` | Extension is not installed (or using local dev build) |
|
|
164
|
-
| `'not-browser'` | Running in SSR/Node.js environment |
|
|
165
|
-
|
|
166
|
-
**Note:** Detecting `'not-enabled'` requires providing the `extensionId` option.
|
|
167
|
-
|
|
168
|
-
#### `getExtensionConfig()`
|
|
169
|
-
|
|
170
|
-
Get extension's configuration.
|
|
171
|
-
```javascript
|
|
172
|
-
const config = await wot.getExtensionConfig();
|
|
173
|
-
// Returns: { maxHops: 3, timeout: 5000, scoring: {...} } or null
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Batch Operations
|
|
177
|
-
|
|
178
|
-
#### `getDistanceBatch(targets, options?)`
|
|
179
|
-
|
|
180
|
-
Get distances for multiple pubkeys in a single call.
|
|
181
|
-
```javascript
|
|
182
|
-
// Default (just hops)
|
|
183
|
-
const distances = await wot.getDistanceBatch(['pk1...', 'pk2...']);
|
|
184
|
-
// Returns: { 'pk1...': 2, 'pk2...': null }
|
|
185
|
-
|
|
186
|
-
// With paths
|
|
187
|
-
const withPaths = await wot.getDistanceBatch(['pk1...', 'pk2...'], { includePaths: true });
|
|
188
|
-
// Returns: { 'pk1...': { hops: 2, paths: 5 }, 'pk2...': null }
|
|
189
|
-
|
|
190
|
-
// With scores
|
|
191
|
-
const withScores = await wot.getDistanceBatch(['pk1...', 'pk2...'], { includeScores: true });
|
|
192
|
-
// Returns: { 'pk1...': { hops: 2, score: 0.65 }, 'pk2...': null }
|
|
193
|
-
|
|
194
|
-
// With both
|
|
195
|
-
const full = await wot.getDistanceBatch(['pk1...', 'pk2...'], { includePaths: true, includeScores: true });
|
|
196
|
-
// Returns: { 'pk1...': { hops: 2, paths: 5, score: 0.65 }, 'pk2...': null }
|
|
197
|
-
|
|
198
|
-
// Legacy boolean still works (backwards compatible)
|
|
199
|
-
const legacy = await wot.getDistanceBatch(['pk1...'], true); // same as { includePaths: true }
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
#### `getTrustScoreBatch(targets)`
|
|
203
|
-
|
|
204
|
-
Get trust scores for multiple pubkeys in a single call.
|
|
205
|
-
```javascript
|
|
206
|
-
const scores = await wot.getTrustScoreBatch(['pk1...', 'pk2...']);
|
|
207
|
-
// Returns: { 'pk1...': 0.72, 'pk2...': null }
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
#### `filterByWoT(pubkeys, options?)`
|
|
211
|
-
|
|
212
|
-
Filter a list of pubkeys to only those within the Web of Trust.
|
|
213
|
-
```javascript
|
|
214
|
-
const trusted = await wot.filterByWoT(['pk1...', 'pk2...', 'pk3...']);
|
|
215
|
-
// Returns: ['pk1...', 'pk3...'] (only those in WoT)
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### Graph Queries (Extension-only)
|
|
219
|
-
|
|
220
|
-
These methods require the browser extension and return `null`/empty when unavailable.
|
|
221
|
-
|
|
222
|
-
#### `getFollows(pubkey?)`
|
|
223
|
-
|
|
224
|
-
Get the follow list for a pubkey (defaults to your pubkey).
|
|
225
|
-
```javascript
|
|
226
|
-
const follows = await wot.getFollows();
|
|
227
|
-
// Returns: ['pk1...', 'pk2...', ...]
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
#### `getCommonFollows(pubkey)`
|
|
231
|
-
|
|
232
|
-
Get mutual follows between you and a target.
|
|
233
|
-
```javascript
|
|
234
|
-
const common = await wot.getCommonFollows('def456...');
|
|
235
|
-
// Returns: ['pk1...', 'pk2...'] (people you both follow)
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
#### `getPath(target)`
|
|
239
|
-
|
|
240
|
-
Get the actual path from you to a target.
|
|
241
|
-
```javascript
|
|
242
|
-
const path = await wot.getPath('def456...');
|
|
243
|
-
// Returns: ['myPubkey', 'friend', 'friendOfFriend', 'def456...']
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
#### `getStats()`
|
|
247
|
-
|
|
248
|
-
Get graph statistics.
|
|
249
|
-
```javascript
|
|
250
|
-
const stats = await wot.getStats();
|
|
251
|
-
// Returns: { nodes: 50000, edges: 150000, lastSync: 1699999999, size: '12 MB' }
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
#### `isConfigured()`
|
|
255
|
-
|
|
256
|
-
Check if the extension is configured and ready.
|
|
257
|
-
```javascript
|
|
258
|
-
const status = await wot.isConfigured();
|
|
259
|
-
// Returns: { configured: true, mode: 'local', hasLocalGraph: true }
|
|
260
|
-
```
|
|
5
|
+
| Old import | New import |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `nostr-wot-sdk` | `@nostr-wot/wot` |
|
|
8
|
+
| `nostr-wot-sdk/react` | `@nostr-wot/wot/react` + `@nostr-wot/data/react` |
|
|
9
|
+
| `nostr-wot-sdk/solid` | `@nostr-wot/wot/solid` |
|
|
10
|
+
| `nostr-wot-sdk/relay` | `@nostr-wot/relay` |
|
|
11
|
+
| `nostr-wot-sdk/relay/react` | `@nostr-wot/relay/react` |
|
|
12
|
+
| `nostr-wot-sdk/data` | `@nostr-wot/data` |
|
|
13
|
+
| `nostr-wot-sdk/data/cache` | `@nostr-wot/data/cache` |
|
|
261
14
|
|
|
262
|
-
|
|
15
|
+
Existing imports keep working — this package just re-exports the scoped packages so older consumers don't break. It will continue to be published in lock-step with `@nostr-wot/*` minor releases.
|
|
263
16
|
|
|
264
|
-
|
|
17
|
+
For new projects, install only the scoped package(s) you actually need:
|
|
265
18
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
- **Offline** — Works without internet once synced
|
|
271
|
-
|
|
272
|
-
The SDK automatically detects the extension via `window.nostr.wot`. When the extension is present (with auto-inject enabled), it **always takes priority** over oracle settings.
|
|
273
|
-
|
|
274
|
-
```javascript
|
|
275
|
-
const wot = new WoT({
|
|
276
|
-
fallback: {
|
|
277
|
-
oracle: 'https://nostr-wot.com',
|
|
278
|
-
myPubkey: 'abc123...'
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// Check if using extension
|
|
283
|
-
if (await wot.isUsingExtension()) {
|
|
284
|
-
console.log('Using local extension data');
|
|
285
|
-
} else {
|
|
286
|
-
console.log('Falling back to oracle');
|
|
287
|
-
}
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## Framework Integration
|
|
291
|
-
|
|
292
|
-
### React
|
|
293
|
-
|
|
294
|
-
The SDK provides first-class React support with automatic extension detection. Just wrap your app with `WoTProvider` and you're ready to go — no additional configuration needed.
|
|
295
|
-
|
|
296
|
-
```javascript
|
|
297
|
-
import { WoTProvider, useWoT, useExtension } from 'nostr-wot-sdk/react';
|
|
298
|
-
|
|
299
|
-
// Wrap your app - automatically detects extension
|
|
300
|
-
function App() {
|
|
301
|
-
return (
|
|
302
|
-
<WoTProvider>
|
|
303
|
-
<YourApp />
|
|
304
|
-
</WoTProvider>
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Check extension status anywhere
|
|
309
|
-
function ExtensionStatus() {
|
|
310
|
-
const { isConnected, isChecking } = useExtension();
|
|
311
|
-
|
|
312
|
-
if (isChecking) return <span>Checking for extension...</span>;
|
|
313
|
-
if (isConnected) return <span>Extension connected!</span>;
|
|
314
|
-
return <span>Extension not available</span>;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Use WoT data in components
|
|
318
|
-
function Profile({ pubkey }) {
|
|
319
|
-
const { distance, score, loading } = useWoT(pubkey);
|
|
320
|
-
|
|
321
|
-
if (loading) return <Spinner />;
|
|
322
|
-
|
|
323
|
-
return (
|
|
324
|
-
<div>
|
|
325
|
-
{distance !== null ? (
|
|
326
|
-
<span>{distance} hops away (score: {score.toFixed(2)})</span>
|
|
327
|
-
) : (
|
|
328
|
-
<span>Not in your network</span>
|
|
329
|
-
)}
|
|
330
|
-
</div>
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
#### Provider Options
|
|
336
|
-
|
|
337
|
-
```javascript
|
|
338
|
-
// With fallback for when extension is not available
|
|
339
|
-
<WoTProvider options={{
|
|
340
|
-
fallback: { myPubkey: 'abc123...' }
|
|
341
|
-
}}>
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
#### Available Hooks
|
|
345
|
-
|
|
346
|
-
| Hook | Description |
|
|
347
|
-
|------|-------------|
|
|
348
|
-
| `useWoT(pubkey)` | Get distance, score, and details for a pubkey |
|
|
349
|
-
| `useIsInWoT(pubkey)` | Check if pubkey is in your WoT (boolean) |
|
|
350
|
-
| `useTrustScore(pubkey)` | Get trust score only |
|
|
351
|
-
| `useBatchWoT(pubkeys[])` | Check multiple pubkeys efficiently |
|
|
352
|
-
| `useExtension()` | Get extension connection state |
|
|
353
|
-
| `useWoTInstance()` | Get raw WoT instance for advanced usage |
|
|
354
|
-
|
|
355
|
-
#### Extension State
|
|
356
|
-
|
|
357
|
-
The `useExtension()` hook provides extension status:
|
|
358
|
-
|
|
359
|
-
```javascript
|
|
360
|
-
const {
|
|
361
|
-
state, // 'checking' | 'connected' | 'not-available'
|
|
362
|
-
isConnected, // Extension is connected and ready
|
|
363
|
-
isChecking, // Currently checking
|
|
364
|
-
isChecked, // Check complete
|
|
365
|
-
refresh, // Function to re-check extension availability
|
|
366
|
-
} = useExtension();
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### SolidJS
|
|
370
|
-
|
|
371
|
-
The SDK also provides SolidJS support with reactive primitives and automatic extension detection. Wrap your app with `WoTProvider` and use `create*` primitives for fine-grained reactivity.
|
|
372
|
-
|
|
373
|
-
```javascript
|
|
374
|
-
import { WoTProvider, useExtension, createWoT } from 'nostr-wot-sdk/solid';
|
|
375
|
-
|
|
376
|
-
// Wrap your app - automatically detects extension
|
|
377
|
-
function App() {
|
|
378
|
-
return (
|
|
379
|
-
<WoTProvider>
|
|
380
|
-
<YourApp />
|
|
381
|
-
</WoTProvider>
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Check extension status anywhere
|
|
386
|
-
function ExtensionStatus() {
|
|
387
|
-
const ext = useExtension();
|
|
388
|
-
|
|
389
|
-
return (
|
|
390
|
-
<Show when={!ext.isChecking()} fallback={<span>Checking...</span>}>
|
|
391
|
-
<Show when={ext.isConnected()} fallback={<span>Extension not available</span>}>
|
|
392
|
-
<span>Extension connected!</span>
|
|
393
|
-
</Show>
|
|
394
|
-
</Show>
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// Use WoT data in components
|
|
399
|
-
function Profile(props: { pubkey: string }) {
|
|
400
|
-
const wot = createWoT(() => props.pubkey);
|
|
401
|
-
|
|
402
|
-
return (
|
|
403
|
-
<Show when={!wot.loading()} fallback={<Spinner />}>
|
|
404
|
-
<Show when={wot.distance() !== null} fallback={<span>Not in your network</span>}>
|
|
405
|
-
<span>{wot.distance()} hops away (score: {wot.score().toFixed(2)})</span>
|
|
406
|
-
</Show>
|
|
407
|
-
</Show>
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
#### Provider Options
|
|
413
|
-
|
|
414
|
-
```javascript
|
|
415
|
-
// With fallback for when extension is not available
|
|
416
|
-
<WoTProvider options={{
|
|
417
|
-
fallback: { myPubkey: 'abc123...' }
|
|
418
|
-
}}>
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
#### Available Primitives
|
|
422
|
-
|
|
423
|
-
| Primitive | Description |
|
|
424
|
-
|-----------|-------------|
|
|
425
|
-
| `createWoT(pubkey)` | Get distance, score, and details for a pubkey |
|
|
426
|
-
| `createIsInWoT(pubkey)` | Check if pubkey is in your WoT (boolean) |
|
|
427
|
-
| `createTrustScore(pubkey)` | Get trust score only |
|
|
428
|
-
| `createBatchWoT(pubkeys[])` | Check multiple pubkeys efficiently |
|
|
429
|
-
| `useExtension()` | Get extension connection state |
|
|
430
|
-
| `useWoTInstance()` | Get raw WoT instance for advanced usage |
|
|
431
|
-
|
|
432
|
-
#### Extension State
|
|
433
|
-
|
|
434
|
-
The `useExtension()` function provides extension status:
|
|
435
|
-
|
|
436
|
-
```javascript
|
|
437
|
-
const ext = useExtension();
|
|
438
|
-
|
|
439
|
-
ext.state() // 'checking' | 'connected' | 'not-available'
|
|
440
|
-
ext.isConnected() // Extension is connected and ready
|
|
441
|
-
ext.isChecking() // Currently checking
|
|
442
|
-
ext.isChecked() // Check complete
|
|
443
|
-
ext.refresh() // Function to re-check extension availability
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
## TypeScript
|
|
447
|
-
|
|
448
|
-
Full type definitions included:
|
|
449
|
-
```typescript
|
|
450
|
-
import { WoT, DistanceResult, WoTOptions } from 'nostr-wot-sdk';
|
|
451
|
-
|
|
452
|
-
const wot = new WoT();
|
|
453
|
-
const result: DistanceResult | null = await wot.getDetails(pubkey);
|
|
454
|
-
const score: number = await wot.getTrustScore(pubkey);
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
## Error Handling
|
|
458
|
-
```javascript
|
|
459
|
-
import { WoT, WoTError, NetworkError, NotFoundError } from 'nostr-wot-sdk';
|
|
460
|
-
|
|
461
|
-
try {
|
|
462
|
-
const hops = await wot.getDistance('def456...');
|
|
463
|
-
} catch (e) {
|
|
464
|
-
if (e instanceof NetworkError) {
|
|
465
|
-
console.log('Oracle unreachable');
|
|
466
|
-
} else if (e instanceof NotFoundError) {
|
|
467
|
-
console.log('Pubkey not in graph');
|
|
468
|
-
}
|
|
469
|
-
}
|
|
19
|
+
```bash
|
|
20
|
+
npm i @nostr-wot/data # event fetchers + cache + hooks
|
|
21
|
+
npm i @nostr-wot/wot # WoT scoring + browser-extension bridge
|
|
22
|
+
npm i @nostr-wot/relay # low-level relay utilities
|
|
470
23
|
```
|
|
471
24
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
- [Nostr WoT Extension](https://github.com/nostr-wot/nostr-wot-extension) — Browser extension (recommended)
|
|
475
|
-
- [WoT Oracle](https://github.com/nostr-wot/nostr-wot-oracle) — Backend service
|
|
476
|
-
- [nostr-wot.com](https://nostr-wot.com) — Public oracle & docs
|
|
477
|
-
|
|
478
|
-
## License
|
|
479
|
-
|
|
480
|
-
MIT
|
|
25
|
+
See [the monorepo README](https://github.com/nostr-wot/nostr-wot-sdk) for architecture and per-package docs.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cache = require('@nostr-wot/data/cache');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.keys(cache).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return cache[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=index.cjs.map
|
|
14
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@nostr-wot/data/cache';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@nostr-wot/data/cache';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var data = require('@nostr-wot/data');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.keys(data).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return data[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=index.cjs.map
|
|
14
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs","sourcesContent":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@nostr-wot/data';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@nostr-wot/data';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|