@scrypt-inc/bitcoinjs-lib
Version:
Client-side Bitcoin JavaScript library
39 lines (38 loc) • 1.52 kB
TypeScript
export interface ScriptSignature {
signature: Uint8Array;
hashType: number;
}
export declare enum SignatureVersion {
BASE = 0,
WITNESS_V0 = 1,
TAPROOT = 2,
TAPSCRIPT = 3
}
/**
* Decodes a buffer into a ScriptSignature object.
* @param buffer - The buffer to decode.
* @returns The decoded ScriptSignature object.
* @throws Error if the hashType is invalid.
*/
export declare function decode(buffer: Uint8Array, strict?: boolean): ScriptSignature;
/**
* Encodes a signature and hash type into a buffer.
* @param signature - The signature to encode.
* @param hashType - The hash type to encode.
* @returns The encoded buffer.
* @throws Error if the hashType is invalid.
*/
export declare function encode(signature: Uint8Array, hashType: number): Uint8Array;
/**
* This function is translated from bitcoind's IsDERSignature and is used in
* the script interpreter. This "DER" format actually includes an extra byte,
* the nhashtype, at the end. It is really the tx format, not DER format.
*
* A canonical signature exists of: [30] [total len] [02] [len R] [R] [02] [len S] [S] [hashtype]
* Where R and S are not negative (their first byte has its highest bit not set), and not
* excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
* in which case a single 0 byte is necessary and even required).
*
* See https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623
*/
export declare function isTxDER(buf: Uint8Array): boolean;