Gordian Envelope TypeScript Library - v1.0.0-alpha.20
    Preparing search index...

    Interface Decrypter

    A trait for types that can decapsulate shared secrets for public key decryption.

    The Decrypter interface defines an interface for decapsulating (recovering) a shared secret using a private key. This is the counterpart to the Encrypter interface and is used by the recipient of encapsulated messages.

    Types implementing this interface provide the ability to:

    1. Access their encapsulation private key
    2. Decapsulate shared secrets from ciphertexts

    This interface is typically implemented by:

    • Encapsulation private keys
    • Higher-level types that contain or can access encapsulation private keys
    import { EncapsulationScheme, createEncapsulationKeypair } from '@bcts/components';

    // Generate a keypair
    const [privateKey, publicKey] = createEncapsulationKeypair(EncapsulationScheme.X25519);

    // Encapsulate a new shared secret
    const [originalSecret, ciphertext] = publicKey.encapsulateNewSharedSecret();

    // Decapsulate the shared secret
    const recoveredSecret = privateKey.decapsulateSharedSecret(ciphertext);

    // The original and recovered secrets should match
    interface Decrypter {
        encapsulationPrivateKey(): EncapsulationPrivateKey;
        decapsulateSharedSecret(ciphertext: EncapsulationCiphertext): SymmetricKey;
    }

    Implemented by

    Index

    Methods

    • Returns the encapsulation private key for this decrypter.

      Returns EncapsulationPrivateKey

      The encapsulation private key that should be used for decapsulation.

    • Decapsulates a shared secret from a ciphertext.

      This method recovers the shared secret that was encapsulated in the given ciphertext, using the private key from this decrypter.

      Parameters

      • ciphertext: EncapsulationCiphertext

        The encapsulation ciphertext containing the encapsulated shared secret

      Returns SymmetricKey

      The decapsulated SymmetricKey

      Error if the ciphertext type doesn't match the private key type or if decapsulation fails