# All files BitcoinError.ts

13.33% Statements 2/15
0% Branches 0/9
0% Functions 0/2
14.29% Lines 2/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    321x

    1x

     import { BitcoinErrorCode } from './BitcoinErrorCode';

    function getMessage(code: BitcoinErrorCode) {
      switch (code) {
        case BitcoinErrorCode.Base58ChecksumFailed:
          return 'Base58Check checksum failed';
        case BitcoinErrorCode.PubKeyInvalid:
          return 'Invalid pubkey';
        case BitcoinErrorCode.PubKeyHashInvalid:
          return 'Invalid pubkeyhash';
        case BitcoinErrorCode.SigEncodingInvalid:
          return 'Signatures requires BIP66 DER encoding';
        case BitcoinErrorCode.SigHashTypeInvalid:
          return 'Invalid Signature SIGHASH type';
        case BitcoinErrorCode.MultiSigSetupInvalid:
          return 'MultiSig structure is invalid';
        case BitcoinErrorCode.Hash160Invalid:
          return 'Hash160 requires 20-byte Buffer';
        case BitcoinErrorCode.Hash256Invalid:
          return 'return Hash256 requires 32-byte Buffer';
        default:
          return 'Unknown';
      }
    }

    export class BitcoinError extends Error {
      // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
      constructor(readonly code: BitcoinErrorCode, readonly data?: any) {
        super(getMessage(code));
      }
    }