@blockchaincommons/components - v1.0.0-beta.4
    Preparing search index...

    Interface Encrypter

    A trait for types that can encapsulate shared secrets for public key encryption.

    The Encrypter interface defines an interface for encapsulating a shared secret using a public key. This is a key part of hybrid encryption schemes, where a shared symmetric key is encapsulated with a public key, and the recipient uses their private key to recover the symmetric key.

    Types implementing this interface provide the ability to:

    1. Access their encapsulation public key
    2. Generate and encapsulate new shared secrets

    This interface is typically implemented by:

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

    // Generate a recipient keypair
    const [recipientPrivateKey, recipientPublicKey] = createEncapsulationKeypair(EncapsulationScheme.X25519);

    // Encapsulate a new shared secret
    const [sharedSecret, ciphertext] = recipientPublicKey.encapsulateNewSharedSecret();
    interface Encrypter {
        encapsulationPublicKey(): EncapsulationPublicKey;
        encapsulateNewSharedSecret(
            options?: RngOptions,
        ): [SymmetricKey, EncapsulationCiphertext];
    }

    Implemented by

    Index
    • Encapsulates a new shared secret for the recipient.

      This method generates a new shared secret and encapsulates it using the encapsulation public key from this encrypter.

      Parameters

      • Optionaloptions: RngOptions

      Returns [SymmetricKey, EncapsulationCiphertext]

      A tuple containing:

      • The generated shared secret as a SymmetricKey
      • The encapsulation ciphertext that can be sent to the recipient