82 lines
4.0 KiB
Markdown
82 lines
4.0 KiB
Markdown
# moon-i2p
|
||
|
||
A clean, zero-dependency, pure-[MoonBit](https://www.moonbitlang.com/) port of the modern **I2P (Invisible Internet Project)** protocol suite targeting `wasm`, `wasm-gc`, `js`, and `native`.
|
||
|
||
## Architecture & Implemented Modules
|
||
|
||
```
|
||
moon-i2p/
|
||
├── encoding/ # I2P Base64 (-/~), Base32 (.b32.i2p), big-endian Reader/Writer, UTF-8, Hex
|
||
├── crypto/ # Pure-MoonBit SHA-256, HMAC-SHA256, HKDF-SHA256, ChaCha20-Poly1305, X25519, SipHash-2-4
|
||
├── common/ # Hash, KeyTypes, Certificate/KeyCertificate, Mapping, Destination, RouterIdentity, RouterInfo, Lease2, LeaseSet2
|
||
├── i2np/ # 16-byte standard & 9-byte NTCP2 short headers, SHA-256 checksums, core I2NP messages
|
||
├── noise/ # Noise_XK_25519_ChaChaPoly_SHA256 handshake/transport + NTCP2 SipHash-2-4 length masking
|
||
├── sam/ # SAMv3 text protocol parser, serializer, and command builders
|
||
├── sam_client/ # Native POSIX TCP SAMv3 client with sane modern I2P defaults
|
||
├── cmd/main/ # Pure protocol demo CLI entrypoint
|
||
├── cmd/client/ # Native SAMv3 CLI (`keygen`, `lookup`, `http-get`, `dial`, `listen`)
|
||
└── scripts/ # Loopback SAMv3 bridge (`mock_sam.py`) and end-to-end test (`e2e_test.py`)
|
||
```
|
||
|
||
### Verified Test Vectors
|
||
Every cryptographic primitive in `crypto/` is verified against official standards:
|
||
- **SHA-256**: FIPS 180-4 / NIST test vectors
|
||
- **HMAC-SHA256**: RFC 4231 test cases 1 & 2
|
||
- **HKDF-SHA256**: RFC 5869 test case 1
|
||
- **ChaCha20-Poly1305 AEAD**: RFC 8439 Section 2.8.2
|
||
- **X25519**: RFC 7748 Sections 5.2 & 6.1
|
||
- **SipHash-2-4**: Official SipHash reference test vector
|
||
|
||
## Running the SAMv3 Client (Native)
|
||
|
||
The native client (`cmd/client`) connects to an I2P SAMv3 bridge with sane modern defaults:
|
||
- **Bridge:** `127.0.0.1:7656` (override with `--sam <host:port>` or `I2P_SAM_HOST` / `I2P_SAM_PORT`)
|
||
- **Protocol:** SAM `3.1`–`3.3`
|
||
- **Keys:** `TRANSIENT` destination, `SIGNATURE_TYPE=7` (`EdDSA_SHA512_Ed25519`)
|
||
- **I2CP Tunnel Defaults:** `i2cp.leaseSetEncType=4,0` (ECIES-X25519 preferred), 3-hop / 3-tunnel inbound & outbound pools
|
||
|
||
```bash
|
||
# Build the native client binary
|
||
moon build --target native cmd/client
|
||
|
||
# Start an I2P router with SAMv3 enabled (e.g. i2pd --sam.enabled=true)
|
||
# or use the bundled local loopback SAMv3 bridge for testing:
|
||
# python3 scripts/mock_sam.py
|
||
|
||
# Generate a new Ed25519 I2P destination
|
||
./_build/native/debug/build/cmd/client/client.exe keygen
|
||
|
||
# Resolve an I2P hostname
|
||
./_build/native/debug/build/cmd/client/client.exe lookup stats.i2p
|
||
|
||
# Fetch an eepsite over a transient STREAM session
|
||
./_build/native/debug/build/cmd/client/client.exe http-get stats.i2p /
|
||
|
||
# Peer-to-peer STREAM listener and dialer
|
||
./_build/native/debug/build/cmd/client/client.exe listen "hello back"
|
||
./_build/native/debug/build/cmd/client/client.exe dial <listener.b32.i2p> "hello over i2p"
|
||
```
|
||
|
||
## Running Checks & Tests
|
||
|
||
```bash
|
||
moon check --target wasm
|
||
moon test --target wasm
|
||
moon check --target native
|
||
moon test --target native
|
||
moon build --target native cmd/client && python3 scripts/e2e_test.py
|
||
```
|
||
|
||
## Roadmap
|
||
|
||
1. **Phase 1–2 (Completed):** Core encoding, pure-MoonBit modern crypto, I2P Common Structures, I2NP messages, `Noise_XK_25519_ChaChaPoly_SHA256` state machine, NTCP2 SipHash length masking, SAMv3 protocol codec, and working native SAMv3 TCP client + CLI (`sam_client/`, `cmd/client/`).
|
||
2. **Phase 3 (Signatures & Ratchet):**
|
||
- Pure-MoonBit **Ed25519** signing & verification (`RouterInfo` & `LeaseSet2` signatures).
|
||
- **ECIES-X25519-AEAD-Ratchet** (Proposal 144) for Garlic encryption & end-to-end sessions.
|
||
3. **Phase 4 (Direct Transports):**
|
||
- **NTCP2** full TCP transport (AES-256-CBC ephemeral key obfuscation, options/padding blocks, session manager).
|
||
4. **Phase 5 (Router Core):**
|
||
- **NetDB** & Floodfill DHT (Kademlia XOR routing with daily routing key derivation).
|
||
- **Tunnel** builder (`ShortTunnelBuild` Proposal 157), layered tunnel encryption, and tunnel pool management.
|
||
- **Streaming** & **Repliable Datagrams** libraries.
|