@hashtree/nostr 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +77 -0
  2. package/package.json +6 -3
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @hashtree/nostr
2
+
3
+ WebRTC P2P storage and Nostr ref resolver for hashtree.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @hashtree/nostr
9
+ ```
10
+
11
+ ## WebRTC Store
12
+
13
+ P2P data fetching via WebRTC with Nostr signaling:
14
+
15
+ ```typescript
16
+ import { WebRTCStore } from '@hashtree/nostr';
17
+
18
+ const store = new WebRTCStore({
19
+ signer, // NIP-07 compatible
20
+ pubkey,
21
+ encrypt, // NIP-44
22
+ decrypt,
23
+ localStore,
24
+ relays: ['wss://relay.example.com'],
25
+ });
26
+
27
+ await store.start();
28
+ const data = await store.get(hash);
29
+ ```
30
+
31
+ ## Nostr Ref Resolver
32
+
33
+ Resolve `npub/treename` references to merkle root hashes via Nostr events.
34
+
35
+ ### Event Format
36
+
37
+ Trees are published as **kind 30078** (parameterized replaceable with label):
38
+
39
+ ```
40
+ npub1abc.../treename/path/to/file.ext
41
+ │ │ │
42
+ │ │ └── Path within merkle tree (client-side traversal)
43
+ │ └── d-tag value (tree identifier)
44
+ └── Author pubkey (bech32 → hex for event)
45
+ ```
46
+
47
+ **Tags:**
48
+ | Tag | Purpose |
49
+ |-----|---------|
50
+ | `d` | Tree name (replaceable event key) |
51
+ | `l` | `"hashtree"` label for discovery |
52
+ | `hash` | Merkle root SHA256 (64 hex chars) |
53
+ | `key` | Decryption key (public trees) |
54
+ | `encryptedKey` | XOR'd key (link-visible trees) |
55
+ | `selfEncryptedKey` | NIP-44 encrypted (private/link-visible) |
56
+
57
+ **Visibility:**
58
+ - **Public**: plaintext `key` tag
59
+ - **Link-visible**: `encryptedKey` + link key in share URL
60
+ - **Private**: only `selfEncryptedKey` (owner access)
61
+
62
+ ### Usage
63
+
64
+ ```typescript
65
+ import { createNostrRefResolver } from '@hashtree/nostr';
66
+
67
+ const resolver = createNostrRefResolver({
68
+ subscribe: (filters, onEvent) => { /* NDK subscribe */ },
69
+ publish: (event) => { /* NDK publish */ },
70
+ });
71
+
72
+ const root = await resolver.resolve('npub1.../myfiles');
73
+ ```
74
+
75
+ ## License
76
+
77
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashtree/nostr",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Nostr integration for hashtree - WebRTC P2P store and ref resolver",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,11 +29,14 @@
29
29
  "dependencies": {
30
30
  "@msgpack/msgpack": "^3.1.2",
31
31
  "nostr-tools": "^2.18.2",
32
- "@hashtree/core": "0.1.1"
32
+ "@hashtree/core": "0.1.3"
33
33
  },
34
34
  "devDependencies": {
35
+ "@nostr-dev-kit/ndk": "^2.18.1",
36
+ "@types/ws": "^8.18.1",
35
37
  "typescript": "^5.3.0",
36
- "vitest": "^2.0.0"
38
+ "vitest": "^2.0.0",
39
+ "ws": "^8.18.3"
37
40
  },
38
41
  "scripts": {
39
42
  "build": "tsc",