ed25519

    A pure MoonBit Ed25519 signing and verification package.

    ed25519
    signature
    crypto
    license
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    6 months ago
    Downloads
    18K

    #hustcer/ed25519

    A pure MoonBit Ed25519 package for deterministic signing and verification.

    This implementation targets the license flow:

    • sign compact viewer license payloads with a local 32-byte private seed
    • verify 64-byte Ed25519 signatures from a 32-byte public key
    • interoperate with RFC 8032 test vectors and standard Ed25519 tooling

    #API

    pub fn derive_public_key(seed : Array[UInt]) -> Result[Array[UInt], String]
    pub fn sign(seed : Array[UInt], message : Array[UInt]) -> Result[Array[UInt], String]
    pub fn verify(public_key : Array[UInt], message : Array[UInt], signature : Array[UInt]) -> Bool
    pub fn verify_result(
    public_key : Array[UInt],
    message : Array[UInt],
    signature : Array[UInt]
    ) -> Result[Bool, String]

    pub struct SigningKey
    pub fn SigningKey::from_seed(seed : Array[UInt]) -> Result[SigningKey, String]
    pub fn SigningKey::public_key(self : SigningKey) -> Array[UInt]
    pub fn SigningKey::sign(self : SigningKey, message : Array[UInt]) -> Result[Array[UInt], String]

    pub struct VerifyingKey
    pub fn VerifyingKey::from_public_key(public_key : Array[UInt]) -> Result[VerifyingKey, String]
    pub fn VerifyingKey::public_key(self : VerifyingKey) -> Array[UInt]
    pub fn VerifyingKey::verify(self : VerifyingKey, message : Array[UInt], signature : Array[UInt]) -> Bool
    pub fn VerifyingKey::verify_result(
    self : VerifyingKey,
    message : Array[UInt],
    signature : Array[UInt]
    ) -> Result[Bool, String]

    Inputs use Array[UInt] byte arrays. Every byte must be in 0..255.

    For repeated license signing, prefer SigningKey::from_seed once and then call signing_key.sign(message) for each payload. That avoids re-expanding the seed and re-deriving the public key for every signature.

    For repeated license verification with the same public key, prefer VerifyingKey::from_public_key once and then call verifying_key.verify(message, signature) for each payload. That avoids decoding the public key and rebuilding its verification table for every signature.

    #Notes

    The package is correctness-first and uses MoonBit BigInt arithmetic. That is enough for license signing and verification payloads, but it is not intended to be a constant-time general-purpose cryptography primitive yet.

    Use a mature audited implementation for high-volume or side-channel-sensitive server cryptography. For S8FY, the recommended use is to sign license payloads offline and verify signatures inside the license policy layer.

    #Benchmarks

    Run:

    moon bench --release

    See BENCHMARK.md for the benchmark cases and workflow.

    #OpenSSL Interop Check

    Run:

    nu scripts/openssl-interop.nu

    The script generates an OpenSSL Ed25519 key, extracts the 32-byte seed, signs the same payload with OpenSSL and this package, then checks that public keys and signatures are identical. It also performs cross verification in both directions.

    SigningKey

    pub struct SigningKey {
    // private fields
    }

    Expanded Ed25519 signing key for repeated signing with the same seed.

    SigningKey::from_seed

    fn SigningKey::from_seed(seed : Array[UInt]) -> Result[SigningKey, String]

    Create an expanded signing key from a 32-byte Ed25519 private seed.

    SigningKey::public_key

    fn SigningKey::public_key(self : SigningKey) -> Array[UInt]

    Return a copy of the 32-byte public key for this signing key.

    SigningKey::sign

    fn SigningKey::sign(self : SigningKey, message : Array[UInt]) -> Result[Array[UInt], String]

    Sign a message with a pre-expanded Ed25519 signing key.

    VerifyingKey

    pub struct VerifyingKey {
    // private fields
    }

    Expanded Ed25519 verifying key for repeated verification.

    VerifyingKey::from_public_key

    fn VerifyingKey::from_public_key(public_key : Array[UInt]) -> Result[VerifyingKey, String]

    Create an expanded verifying key from a 32-byte Ed25519 public key.

    VerifyingKey::public_key

    fn VerifyingKey::public_key(self : VerifyingKey) -> Array[UInt]

    Return a copy of the 32-byte public key for this verifying key.

    VerifyingKey::verify

    fn VerifyingKey::verify(self : VerifyingKey, message : Array[UInt], signature : Array[UInt]) -> Bool

    Verify a signature with a pre-expanded verifying key.

    VerifyingKey::verify_result

    fn VerifyingKey::verify_result(self : VerifyingKey, message : Array[UInt], signature : Array[UInt]) -> Result[Bool, String]

    Verify a signature with a pre-expanded verifying key and report malformed inputs.

    derive_public_key

    fn derive_public_key(seed : Array[UInt]) -> Result[Array[UInt], String]

    Derive a 32-byte Ed25519 public key from a 32-byte private seed.

    sign

    fn sign(seed : Array[UInt], message : Array[UInt]) -> Result[Array[UInt], String]

    Sign a message with a 32-byte Ed25519 private seed.

    verify

    fn verify(public_key : Array[UInt], message : Array[UInt], signature : Array[UInt]) -> Bool

    Verify a 64-byte Ed25519 signature for a message and 32-byte public key.

    verify_result

    fn verify_result(public_key : Array[UInt], message : Array[UInt], signature : Array[UInt]) -> Result[Bool, String]

    Verify a signature and return an error for malformed public inputs.

    Source Files