@blockchaincommons/crypto - v1.0.0-beta.3
    Preparing search index...

    Interface X25519

    The shape of the x25519 family.

    interface X25519 {
        PRIVATE_KEY_SIZE: 32;
        PUBLIC_KEY_SIZE: 32;
        generatePrivateKey(options?: RngOptions): Uint8Array<ArrayBuffer>;
        publicKey(privateKey: Uint8Array): Uint8Array<ArrayBuffer>;
        sharedKey(
            privateKey: Uint8Array,
            publicKey: Uint8Array,
        ): Uint8Array<ArrayBuffer>;
    }
    Index
    PRIVATE_KEY_SIZE: 32

    Private key length in bytes.

    PUBLIC_KEY_SIZE: 32

    Public key length in bytes.

    • 32 random bytes from options.rng (default secure), unvalidated; the reference's x25519_new_private_key_using (random_data). A generator's own error, including rand's InvalidGenerator, propagates unwrapped.

      Parameters

      • Optionaloptions: RngOptions

      Returns Uint8Array<ArrayBuffer>

      InvalidParameter unless options is an object or absent.

    • The X25519 public key of privateKey (clamped per RFC 7748).

      Parameters

      • privateKey: Uint8Array

      Returns Uint8Array<ArrayBuffer>

      InvalidParameter on a non-Uint8Array; InvalidSize on a wrong-length key.

    • X25519 Diffie-Hellman, then HKDF-SHA-256 with salt "agreement" → 32 bytes (the reference's x25519_shared_key). A low-order publicKey (RFC 7748 §6.1) gives the all-zero shared secret and so one fixed key, whatever the private key: the reference calls x25519-dalek's diffie_hellman without checking was_contributory, and neither does this. Reject such peers yourself before deriving from an untrusted key.

      Parameters

      • privateKey: Uint8Array
      • publicKey: Uint8Array

      Returns Uint8Array<ArrayBuffer>

      InvalidParameter on a non-Uint8Array; InvalidSize on a wrong length.