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

    Class CryptoError

    Thrown for wrong-length keys, nonces, signatures and public keys (InvalidSize), a key, point or signature of the right length that is not valid (InvalidData), an argument outside its domain, including a value of the wrong type (InvalidParameter), and AEAD tag mismatch (AuthenticationFailed).

    Every failure of an argument or of a primitive is a CryptoError; when a backend error is what was caught, it is the cause. Two things propagate unwrapped, because they are not this package's: a generator's own error (RandError from @blockchaincommons/rand, including InvalidGenerator for a generator that lacks a method the draw calls), and an allocation failure outside the KDFs (RangeError from the engine). Instances come from the static factories only.

    try {
    chacha20Poly1305.decrypt(key, nonce, sealed);
    } catch (e) {
    if (CryptoError.isCryptoError(e) && e.is("AuthenticationFailed")) {
    // tampered
    }
    }

    Hierarchy

    • Error
      • CryptoError
    Index
    name: "CryptoError"

    Always "CryptoError"; the cross-copy identity CryptoError.isCryptoError checks.

    The discriminant; equals details.code.

    The structured payload, discriminated by code.

    • Type guard for a CryptoError, including one from another copy of this package.

      Parameters

      • value: unknown

      Returns value is CryptoError

    • what had actual bytes; expected were required.

      Parameters

      • what: string
      • expected: number
      • actual: number

      Returns CryptoError

    • what has the right length but is not a valid key, point or signature.

      Parameters

      • what: string
      • message: string
      • Optionalcause: unknown

      Returns CryptoError

    • what (a number, an options object or a byte argument) is outside its domain.

      Parameters

      • what: string
      • message: string
      • Optionalcause: unknown

      Returns CryptoError

    • AEAD authentication failed (wrong key, nonce, aad, or tampered data).

      Parameters

      • Optionalcause: unknown

      Returns CryptoError