Crypto KMS
    Preparing search index...

    Class LocalKmsProvider

    Local in-memory KMS provider.

    Uses Node.js crypto for AES-256-GCM symmetric operations and @sebastienrousseau/crypto-lib Ed25519 for signing operations. Keys are stored in memory and do not persist across restarts.

    Rotation adds a key version rather than replacing the material: ciphertext names the version that produced it, so data encrypted before a rotation still decrypts, and signatures made before a rotation still verify, until that version is destroyed with LocalKmsProvider.destroyKeyVersion. Failures reject with a KmsError.

    const provider = new LocalKmsProvider();
    const key = await provider.createKey("aes-256-gcm", "encrypt");
    const enc = await provider.encrypt(key.keyId, new TextEncoder().encode("hello"));
    const dec = await provider.decrypt(key.keyId, enc.ciphertext);
    console.log(new TextDecoder().decode(dec.plaintext)); // "hello"

    Implements

    Index
    name: "local"

    Provider identifier.

    • Create a new key with the given algorithm and usage.

      Parameters

      • algorithm: string
      • usage: "encrypt" | "sign" | "wrap"
      • Optional_metadata: Record<string, string>

      Returns Promise<KmsKeyMetadata>

    • Schedule a key for deletion after a pending window.

      Parameters

      • keyId: string
      • pendingWindowDays: number = 30

      Returns Promise<void>

    • Encrypt plaintext with AES-256-GCM under the current key version.

      Parameters

      • keyId: string
      • plaintext: Uint8Array
      • Optionalcontext: Record<string, string>

      Returns Promise<KmsEncryptResult>

    • Decrypt AES-256-GCM ciphertext with the key version it names.

      Parameters

      • keyId: string
      • ciphertext: string
      • Optionalcontext: Record<string, string>

      Returns Promise<KmsDecryptResult>

    • Sign data using the current Ed25519 key version.

      Parameters

      • keyId: string
      • data: Uint8Array
      • Optional_algorithm: string

      Returns Promise<KmsSignResult>

    • Verify an Ed25519 signature against every key version that has not been destroyed. Malformed signatures verify as false.

      Parameters

      • keyId: string
      • data: Uint8Array
      • signature: string
      • Optional_algorithm: string

      Returns Promise<boolean>

    • Destroy the material of a non-current key version. Ciphertext and signatures produced under it can no longer be used. Rejects with INVALID_ARGUMENT for the current version and NOT_FOUND for an unknown key or version.

      Parameters

      • keyId: string
      • version: number

      Returns Promise<void>

    • Generate a data encryption key (DEK) wrapped by the managed key.

      Parameters

      • keyId: string
      • Optional_keySpec: string

      Returns Promise<{ plaintext: Uint8Array; ciphertext: string }>

    • Wrap an existing key with the managed key.

      Parameters

      • keyId: string
      • unwrappedKey: Uint8Array
      • Optionalcontext: Record<string, string>

      Returns Promise<{ wrappedKey: string; keyId: string }>

    • Unwrap a wrapped key with the managed key.

      Parameters

      • keyId: string
      • wrappedKey: string
      • Optionalcontext: Record<string, string>

      Returns Promise<{ unwrappedKey: Uint8Array; keyId: string }>