** SKELETON PLACEHOLDER - check https://docs.bsvblockchain.org/guides/sdks/ts/low-level/tx_sig ** *This is a technical reference document for transaction signatures in the BSV TypeScript SDK.
This reference document provides detailed technical information about transaction signatures in Bitcoin SV and how they are implemented in the TypeScript SDK. It complements the Key Management and Cryptography tutorial and the Advanced Transaction Signing guide.
Bitcoin uses the Elliptic Curve Digital Signature Algorithm (ECDSA) with the secp256k1 curve. Each signature consists of two components:
r
: A value derived from a random nonce used during signings
: A value that combines the private key, message hash, and the nonce// Structure of a Signature class instance
class Signature {
r: BigNumber; // The r component
s: BigNumber; // The s component
// Methods for serialization
toDER(encoding?: 'hex'): number[] | string;
// Static methods for deserialization
static fromDER(bytes: number[]): Signature;
// Additional methods...
}
Signatures in Bitcoin are encoded using the Distinguished Encoding Rules (DER) format, which provides a standardized way to represent the ECDSA signature components.
Bitcoin transactions use SIGHASH flags to indicate which parts of a transaction are included in the signature hash:
Flag | Hex Value | Description |
---|---|---|
SIGHASH_ALL | 0x01 | Signs all inputs and outputs (default) |
SIGHASH_NONE | 0x02 | Signs inputs only, allows any outputs |
SIGHASH_SINGLE | 0x03 | Signs inputs and the output with the same index |
SIGHASH_ANYONECANPAY | 0x80 | Can be combined with above flags, allows additional inputs |
// Sign a message or transaction with a private key
sign(message: string | number[], sigHashType?: number): Promise<Signature>;
// Verify a signature with a public key
verify(message: string | number[], signature: Signature): boolean;
// Sign a transaction
sign(sigHashType?: number): Promise<void>;
// Verify all signatures in a transaction
verify(): Promise<boolean>;
// Example of how signature hashing is implemented
function calculateSignatureHash(tx: Transaction, inputIndex: number, sigHashType: number): number[] {
// Implementation details...
}