4866f3c46d430848b79f99480a75899ea5a0a1f6
moon-i2p
A clean, zero-dependency, pure-MoonBit 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>orI2P_SAM_HOST/I2P_SAM_PORT) - Protocol: SAM
3.1–3.3 - Keys:
TRANSIENTdestination,SIGNATURE_TYPE=7(EdDSA_SHA512_Ed25519) - I2CP Tunnel Defaults:
i2cp.leaseSetEncType=4,0(ECIES-X25519 preferred), 3-hop / 3-tunnel inbound & outbound pools
# 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
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
- Phase 1–2 (Completed): Core encoding, pure-MoonBit modern crypto, I2P Common Structures, I2NP messages,
Noise_XK_25519_ChaChaPoly_SHA256state machine, NTCP2 SipHash length masking, SAMv3 protocol codec, and working native SAMv3 TCP client + CLI (sam_client/,cmd/client/). - Phase 3 (Signatures & Ratchet):
- Pure-MoonBit Ed25519 signing & verification (
RouterInfo&LeaseSet2signatures). - ECIES-X25519-AEAD-Ratchet (Proposal 144) for Garlic encryption & end-to-end sessions.
- Pure-MoonBit Ed25519 signing & verification (
- Phase 4 (Direct Transports):
- NTCP2 full TCP transport (AES-256-CBC ephemeral key obfuscation, options/padding blocks, session manager).
- Phase 5 (Router Core):
- NetDB & Floodfill DHT (Kademlia XOR routing with daily routing key derivation).
- Tunnel builder (
ShortTunnelBuildProposal 157), layered tunnel encryption, and tunnel pool management. - Streaming & Repliable Datagrams libraries.
Description
MoonBit I2P protocol implementation
1.4 MiB
0 Stars
1 Watchers
0 Forks
Releases
1
Languages
MoonBit
76.7%
Python
7.1%
Java
5.5%
HTML
4.1%
JavaScript
3.8%
Other
2.8%