Repository navigation
P2P Sync & Mobile
H.A.N. features a zero-backend, local-first, peer-to-peer (P2P) synchronization engine protected by End-to-End Encryption (E2EE). It allows you to seamlessly synchronize your entire notes vault between your desktop computer and mobile devices (or between two computers) without trusting any cloud provider with your unencrypted data.
Unlike traditional SaaS note apps that store your notes on central servers in plain text or with provider-managed encryption keys, H.A.N.'s sync engine operates on three unshakeable rules:
- Zero-Knowledge Encryption (AES-GCM 256): All note contents, paths, tags, tasks, decisions, and sync metadata are encrypted on your device before transmission. No unencrypted payload ever touches the network.
-
True Peer-to-Peer Data Transfer (WebRTC): Data flows directly between your devices over an encrypted WebRTC
RTCDataChannel. No application server acts as a storage intermediary. - Ephemeral Signaling: A lightweight WebSocket signaling relay is used solely for the initial WebRTC connection handshake (SDP offer/answer and ICE candidate exchange). The moment the direct P2P data channel opens, the WebSocket connection is immediately terminated, dropping server resource utilization to zero.
┌────────────────────────────────────────────────────────────────────────┐
│ H.A.N. Desktop / Mobile App │
└───────────────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────┴────────────────────────┐
▼ ▼
┌──────────────────────┐ ┌───────────────────────┐
│ Desktop / Tauri / │ │ Mobile / Unsupported │
│ File System Access │ │ Fallback (IndexedDB) │
│ (Raw .md on disk) │ │ (han_notes_db) │
└──────────┬───────────┘ └───────────┬───────────┘
│ │
└────────────────────────┬────────────────────────┘
▼
┌──────────────────────────────┐
│ SyncStorageAdapter │
│ (Canonical Note & Tombstone) │
└──────────────┬───────────────┘
│
┌────────────────────┴────────────────────┐
▼ ▼
┌──────────────────────┐ ┌──────────────────────┐
│ Web Crypto API │ │ Signaling Relay │
│ (AES-GCM 256 E2EE) │ │ (Cloudflare Worker + │
│ Ephemeral QR Key │ │ Durable Objects) │
└───────────┬──────────┘ └──────────┬───────────┘
│ │
│ WebSocket Dropped on Open │
│ ◄──────────────────────────────────────┤
▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ WebRTC P2P DataChannel │
│ 16 KiB Framed Packets & Flow Control │
└─────────────────────────────────────────────────────────────────┘
When you initiate a sync session on your host device (Desktop), H.A.N. uses the native Web Crypto API to generate a cryptographically strong, ephemeral 256-bit symmetric key:
-
Algorithm:
AES-GCMwith a 256-bit key length. -
Random IV: Every individual message transmitted across the DataChannel is encrypted with a unique 12-byte initialization vector (
crypto.getRandomValues(new Uint8Array(12))). - Content Integrity: Each note payload includes a SHA-256 content hash to detect changes and verify integrity without transferring redundant data.
How does the mobile device obtain the decryption key without exposing it to the signaling server or internet?
- The key is exported as a URL-safe Base64 (
base64url) string. - It is embedded solely in the URL hash fragment of the pairing link:
https://bishoku.github.io/han-notes-app/#sync=<ROOM_ID>&key=<BASE64_KEY>&role=peer -
Why Hash Fragments? In accordance with the HTTP/1.1 specification (RFC 3986), characters following the
#symbol in a URL are strictly client-side. Browsers never send hash fragments in HTTP requests to web servers or proxies. - The QR code displayed on your desktop screen encodes this URL. When your mobile device scans the QR code with its camera, the key is ingested directly into browser memory.
- In H.A.N., click the P2P Sync icon in the bottom status bar (or navigate to Settings -> P2P Sync).
- The sync modal will open in Host Mode:
- A unique pairing QR code is generated on screen.
- The status badge changes to Waiting for peer....
- (Optional) If scanning a QR code is not convenient, click Copy Link to share the pairing link via a secure local clipboard or messenger.
┌─────────────────────────────────────────────────────────────────────────────┐
│ 🔄 P2P Encrypted Synchronization [Close ✕] │
├─────────────────────────────────────────────────────────────────────────────┤
│ 📱 Scan with Mobile Device │
│ │
│ ┌─────────────────────────┐ │
│ │ █████████ █████████ │ │
│ │ █ ▄▄▄ █ █ █ █ ▄▄▄ █ █ │ Status: Waiting for Peer... │
│ │ █ ███ █ █ █ █ ███ █ █ │ Room ID: 7f8a-92b1-4cd2 │
│ │ █▄▄▄█ █ █ █ █▄▄▄█ █ █ │ Encryption: AES-GCM 256 (E2EE) │
│ │ █████████ █████████ │ │
│ └─────────────────────────┘ │
│ │
│ [ 📋 Copy Pairing Link ] [ Switch to Scanner / Join Mode ] │
└─────────────────────────────────────────────────────────────────────────────┘
- Open the H.A.N. Web App on your mobile device (Safari on iOS, Chrome on Android).
- Tap the Sync icon or open Settings -> P2P Sync.
- Tap Scan QR Code / Join:
- Grant temporary camera permission if prompted.
- Point your mobile camera at the QR code displayed on the desktop screen.
- The scanner reticle will instantly detect the pairing QR code, read the session ID and decryption key from the hash, and begin the handshake.
-
Alternative: If you opened the pairing link directly in your mobile browser, H.A.N. automatically detects the
#sync=...hash on launch and begins pairing immediately with zero taps!
Once connected, the synchronization protocol executes automatically in seconds:
-
Manifest Exchange: Both devices exchange an encrypted summary (
id,updatedAt,hash,deletedAt) of their notes. - State Diffing: Each device determines exactly which notes are missing, updated, or deleted on the other side.
- Encrypted Transfer: Modified notes are streamed across the WebRTC DataChannel with a live progress indicator.
- Completion Summary: A detailed report appears showing the count of notes sent, received, deleted, and conflicts detected.
┌─────────────────────────────────────────────────────────────────────────────┐
│ 🔄 Synchronizing Notes... │
├─────────────────────────────────────────────────────────────────────────────┤
│ Transferring: Work/Architecture.md (Note 14 of 42) │
│ │
│ [████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░] 52% │
│ │
│ ⬆️ Sending: 18 notes | ⬇️ Receiving: 24 notes │
└─────────────────────────────────────────────────────────────────────────────┘
WebRTC DataChannels operate over SCTP, which enforces a strict maximum message size (typically 64 KiB or 262 KiB depending on the browser). Attempting to send a large note, embedded diagram, or vault manifest exceeding this limit causes browsers to throw:
Failed to execute 'send' on 'RTCDataChannel': Trying to send message larger than max-message-size.
H.A.N. completely eliminates this restriction with a specialized Packet Chunking & Backpressure Engine (src/services/sync/chunking.ts):
- 16 KiB Chunk Slicing: Every encrypted payload is automatically sliced into safe 16 KiB (16,384 bytes) chunks.
-
8-Byte Binary Framing Header:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Message ID (uint32) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Chunk Index (uint16) | Total Chunks (uint16) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Chunk Data (0..16 KiB) | | ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -
Backpressure Flow Control:
- To prevent memory exhaustion and buffer bloat during bulk transfers, H.A.N. tracks
channel.bufferedAmount. - If the sending buffer exceeds 128 KiB, transmission pauses until the browser flushes data to the network and fires
bufferedamountlow(threshold: 64 KiB).
- To prevent memory exhaustion and buffer bloat during bulk transfers, H.A.N. tracks
-
Reassembly & Deinterleaving:
- The receiving device reassembles packets in real time. Even if packets arrive out-of-order or are interleaved from concurrent tasks, the message reassembler reconstructs the full buffer before AES-GCM decryption.
H.A.N. guarantees note consistency across asynchronous, offline edits without data loss.
Every note carries an epoch millisecond modification timestamp (updatedAt). When comparing notes:
- If a note exists on Device A with timestamp
T2and on Device B with timestampT1(T2 > T1), Device A's version is accepted. - Notes with identical SHA-256 content hashes are skipped, saving bandwidth and battery.
A common flaw in naive P2P sync systems is note resurrection: User deletes Note X on Device A. Later, Device A syncs with Device B (which still has Note X). Device B treats Note X as a "new note" and sends it back to Device A!
H.A.N. prevents this using a persistent metadata store (.han_sync_metadata.json):
- When a note is deleted, a tombstone record is created with
deleted: trueanddeletedAt: <timestamp>. - During sync, Device A informs Device B that Note X was deleted.
- If Note X on Device B was last edited before the deletion timestamp, Device B deletes its local copy.
- If Note X on Device B was edited after the deletion timestamp, the newer edit takes precedence and is retained.
If both devices edited the same note offline at the exact same timestamp or with diverging contents:
- The remote note is saved with a conflict suffix:
Notes/Meeting-Notes (Conflict 2026-09-04-143022).md - Both versions are preserved so you never lose notes or ideas.
H.A.N. adapts transparently to whatever storage capabilities the host operating system allows:
| Platform | Primary Storage Engine | Characteristics |
|---|---|---|
| Desktop (Tauri) | TauriStorage |
Direct native disk I/O, .git repository, full file paths. |
| Desktop (Chrome/Edge) | BrowserStorage |
File System Access API (showDirectoryPicker), writes directly to local disk folder. |
| Mobile (iOS Safari, Android) | IndexedDBStorage |
High-capacity browser IndexedDB (han_notes_db), works 100% offline, zero permission dialogs. |
You can install H.A.N. as an offline app on your smartphone or tablet:
- iOS (Safari): Tap the Share button -> Add to Home Screen.
- Android (Chrome): Tap the three-dot menu -> Install app / Add to Home screen.
- Once added, H.A.N. launches in standalone fullscreen mode without browser URL bars and operates entirely offline using cached service workers and IndexedDB storage.
H.A.N. includes an open-source, production-ready signaling server designed for Cloudflare Workers with Durable Objects. It can be deployed in under two minutes on Cloudflare's free tier.
The signaling server contains zero persistent database storage, logs no IP addresses, and holds no note contents or keys.
-
Navigate to the
signaling-serverfolder:cd signaling-server npm install -
Authenticate with Cloudflare:
npx wrangler login
-
Deploy to Cloudflare:
npm run deploy
Wrangler will output your live worker URL:
https://han-notes-signaling.<your-subdomain>.workers.dev -
Connect H.A.N. to your custom server:
- Open H.A.N. Settings -> P2P Sync.
- Under Signaling Server URL, enter your Cloudflare Worker URL:
wss://han-notes-signaling.<your-subdomain>.workers.dev - Click Save.
Third-party databases require user accounts, monthly subscriptions, vendor lock-in, and trusting cloud administrators with your private notes. H.A.N.'s P2P WebRTC architecture requires zero accounts, costs $0, and gives you complete sovereignty over your data.
Yes! H.A.N. uses standard Google STUN servers (stun:stun.l.google.com:19302) to discover reflexive public IP addresses and establish direct P2P connections across standard home routers, mobile data connections (4G/5G), and public Wi-Fi networks.
If you are behind strict corporate firewalls, university networks, or symmetric NATs, WebRTC peer discovery may be blocked. To resolve:
- Ensure both devices are connected to the same Wi-Fi network or personal hotspot.
- In enterprise environments, configure a TURN relay server in WebRTC configuration settings.
Thanks to the 16 KiB packet chunking and backpressure engine, there is no technical size limit on individual notes or attachments. Vaults with thousands of notes and large embedded diagrams transfer smoothly with flow control.