57 lines
2.2 KiB
MoonBit
57 lines
2.2 KiB
MoonBit
///|
|
|
/// `moon-i2p`: Pure MoonBit implementation of the I2P (Invisible Internet Project) protocol suite.
|
|
///
|
|
/// Packages:
|
|
/// - `experiments/moon_i2p/encoding` — I2P custom Base64 (`-`/`~`), Base32 (`.b32.i2p`), big-endian `Reader`/`Writer`, hex.
|
|
/// - `experiments/moon_i2p/crypto` — SHA-256, HMAC-SHA256, HKDF-SHA256, ChaCha20-Poly1305 AEAD, X25519, SipHash-2-4.
|
|
/// - `experiments/moon_i2p/common` — `Hash`, `Certificate`/`KeyCertificate`, `Mapping`, `Destination`, `RouterIdentity`, `RouterAddress`, `RouterInfo`, `Lease`/`Lease2`, `LeaseSet2`.
|
|
/// - `experiments/moon_i2p/i2np` — I2NP 16-byte standard & 9-byte NTCP2 short headers, checksums, and core messages.
|
|
/// - `experiments/moon_i2p/noise` — `Noise_XK_25519_ChaChaPoly_SHA256` handshake/transport + NTCP2 SipHash length masking.
|
|
/// - `experiments/moon_i2p/sam` — SAMv3 text protocol parser, serializer, and command builders.
|
|
|
|
///|
|
|
pub fn version() -> String {
|
|
"0.1.0"
|
|
}
|
|
|
|
///|
|
|
/// Convenience helper: derives the `.b32.i2p` address from raw X25519 & Ed25519 public keys.
|
|
pub fn derive_b32_address(
|
|
crypto_pub : Bytes,
|
|
signing_pub : Bytes,
|
|
) -> String raise @common.CommonError {
|
|
let dest = @common.Destination::new_x25519_ed25519(crypto_pub, signing_pub)
|
|
dest.b32_address()
|
|
}
|
|
|
|
///|
|
|
/// Runs a self-contained protocol smoke check across encoding, crypto, common, I2NP, Noise_XK, and SAMv3.
|
|
pub fn demo_summary() -> String {
|
|
try {
|
|
let alice_s = @noise.KeyPair::from_private(
|
|
@encoding.hex_decode(
|
|
"77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a",
|
|
),
|
|
)
|
|
let bob_s = @noise.KeyPair::from_private(
|
|
@encoding.hex_decode(
|
|
"5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb",
|
|
),
|
|
)
|
|
let dest = @common.Destination::new_x25519_ed25519(
|
|
alice_s.public_key,
|
|
bob_s.public_key,
|
|
)
|
|
let msg = @i2np.encode_short_message(
|
|
1U,
|
|
1700000000U,
|
|
@i2np.I2npPayload::Data(data=b"moon-i2p"),
|
|
)
|
|
let sam_hello = @sam.hello_version().serialize()
|
|
let digest = @encoding.hex_encode(@crypto.sha256(msg))
|
|
"moon-i2p v\{version()} | b32=\{dest.b32_address()} | i2np_sha256=\{digest} | sam=\{sam_hello}"
|
|
} catch {
|
|
_ => "moon-i2p demo failed"
|
|
}
|
|
}
|