Skip to content

Commit 3097efa

Browse files
Update DESIGN.md with git push documentation
- Add NIP-98 push authentication to features - Document custom HTTP client for Schnorr-signed requests - Add push example section - Update future improvements - Add NIP-98 and @noble/curves to references
1 parent f288c9a commit 3097efa

1 file changed

Lines changed: 70 additions & 10 deletions

File tree

DESIGN.md

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A browser-based git repository viewer and sync client using Nostr for real-time
44

55
## Status: ✅ Implemented
66

7-
Working prototype in `index.html` (~750 lines, single file, no build step).
7+
Working prototype in `index.html` (~1000 lines, single file, no build step).
88

99
**Features working:**
1010
- Clone repositories to IndexedDB
@@ -15,6 +15,9 @@ Working prototype in `index.html` (~750 lines, single file, no build step).
1515
- Multi-relay WebSocket connections with status indicators
1616
- Add/remove repositories via modal
1717
- Configuration persisted to localStorage
18+
- **Git push with NIP-98 authentication** (Schnorr signatures)
19+
- Settings modal for private key configuration
20+
- Create commits and push to remote servers
1821

1922
## Overview
2023

@@ -24,15 +27,17 @@ This project brings the functionality of [nostr-git-sync](https://github.com/Jav
2427
2. Clone/sync repositories to browser IndexedDB
2528
3. Browse repository files with a visual UI
2629
4. Auto-update when new commits are published
30+
5. **Push commits with NIP-98 Schnorr authentication**
2731

2832
```
2933
┌─────────────────┐ WebSocket ┌─────────────────┐
3034
│ │◄──────────────────►│ Nostr Relays │
31-
│ Browser │ └─────────────────┘
32-
│ │ HTTP/fetch ┌─────────────────┐
33-
│ IndexedDB │◄──────────────────►│ Git Server │
34-
│ /sync/repo1/ │ (clone/pull) │ (JSS, GitHub) │
35-
│ /sync/repo2/ │ └─────────────────┘
35+
│ Browser │ │ (30617 events) │
36+
│ │ └─────────────────┘
37+
│ IndexedDB │ HTTP/fetch ┌─────────────────┐
38+
│ /sync/repo1/ │◄──────────────────►│ Git Server │
39+
│ /sync/repo2/ │ clone/pull/push │ (JSS w/NIP-98) │
40+
│ │ (NIP-98 auth) └─────────────────┘
3641
└─────────────────┘
3742
```
3843

@@ -160,9 +165,52 @@ await git.pull({
160165
singleBranch: true,
161166
author: { name: 'browser', email: 'browser@local' }
162167
});
168+
169+
// Push with NIP-98 auth
170+
await git.push({
171+
fs,
172+
http: createAuthenticatedHttp(privkey), // Custom HTTP client
173+
dir,
174+
url: cloneUrl,
175+
ref: branch
176+
});
177+
```
178+
179+
### 2. NIP-98 Push Authentication
180+
181+
Git push uses NIP-98 (HTTP Auth) with Schnorr signatures. Each HTTP request gets a unique signed token:
182+
183+
```javascript
184+
function createAuthenticatedHttp(privkey) {
185+
return {
186+
async request({ url, method, headers, body }) {
187+
// Create NIP-98 event (kind 27235)
188+
const event = {
189+
kind: 27235,
190+
created_at: Math.floor(Date.now() / 1000),
191+
tags: [['u', url], ['method', method]],
192+
content: ''
193+
};
194+
const signed = await signEvent(event, privkey);
195+
const token = btoa(JSON.stringify(signed));
196+
197+
return fetch(url, {
198+
method,
199+
headers: { ...headers, 'Authorization': 'Nostr ' + token },
200+
body
201+
});
202+
}
203+
};
204+
}
163205
```
164206

165-
### 2. Nostr Relay Connections
207+
**Key points:**
208+
- Uses `@noble/curves` for Schnorr signatures (same as Bitcoin/Nostr)
209+
- Each request (GET /info/refs, POST /git-receive-pack) gets its own token
210+
- Server validates signature and checks ACL for `did:nostr:<pubkey>`
211+
- Private key stored in localStorage (settings modal)
212+
213+
### 3. Nostr Relay Connections
166214

167215
```javascript
168216
function connectRelays(relays, repoIds, trusted, onEvent) {
@@ -333,23 +381,35 @@ No build step, no npm install, no configuration files needed.
333381
4. Repository clones to IndexedDB
334382
5. Browse files, view index.html with live WebLedger data
335383

384+
## Example: Push Changes
385+
386+
1. Open Settings (⚙️ button)
387+
2. Enter your **private key** (64-char hex)
388+
3. Select a repository from dropdown
389+
4. Click **"Create Commit & Push"**
390+
5. Creates `browser-test.txt`, commits, and pushes to remote
391+
392+
The push button (↑) in repo list also works for pushing existing commits.
393+
336394
## Future Improvements
337395

338396
- [ ] Delete repository button
339-
- [ ] Settings panel for relay configuration
397+
- [ ] File editing UI
398+
- [ ] NIP-07 browser extension support (avoid raw privkey)
340399
- [ ] Syntax highlighting for code files
341400
- [ ] Commit history viewer
342401
- [ ] Diff viewer
343-
- [ ] Export/import configuration
344402
- [ ] Service worker for offline support
345-
- [ ] Storage usage indicator
403+
- [ ] Publish 30617 events after push
346404

347405
## References
348406

349407
- [isomorphic-git](https://isomorphic-git.org/) - Git implementation in JavaScript
350408
- [LightningFS](https://github.com/isomorphic-git/lightning-fs) - IndexedDB filesystem
351409
- [NIP-34](https://github.com/nostr-protocol/nips/blob/master/34.md) - Git over Nostr
410+
- [NIP-98](https://github.com/nostr-protocol/nips/blob/master/98.md) - HTTP Auth with Nostr
352411
- [nostr-git-sync](https://github.com/JavaScriptSolidServer/nostr-git-sync) - Server-side equivalent
412+
- [@noble/curves](https://github.com/paulmillr/noble-curves) - Schnorr signatures
353413
- [Preact](https://preactjs.com/) - Fast 3kB React alternative
354414
- [htm](https://github.com/developit/htm) - JSX-like syntax with template literals
355415

0 commit comments

Comments
 (0)