Transaction Signatures Reference
** 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.
Introduction
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.
Signature Components
ECDSA Signatures
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...
}
DER Encoding
Signatures in Bitcoin are encoded using the Distinguished Encoding Rules (DER) format, which provides a standardized way to represent the ECDSA signature components.
Signature Hash (SIGHASH) Types
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 |
Transaction Signature Verification Process
- Extract signature and public key from the unlockingScript
- Determine the SIGHASH flag from the signature
- Recreate the signature hash based on the SIGHASH flag
- Verify the signature against the hash using the public key
API Reference
PrivateKey Methods
// Sign a message or transaction with a private key
sign(message: string | number[], sigHashType?: number): Promise<Signature>;
PublicKey Methods
// Verify a signature with a public key
verify(message: string | number[], signature: Signature): boolean;
Transaction Methods
// Sign a transaction
sign(sigHashType?: number): Promise<void>;
// Verify all signatures in a transaction
verify(): Promise<boolean>;
Example Implementation Details
// Example of how signature hashing is implemented
function calculateSignatureHash(tx: Transaction, inputIndex: number, sigHashType: number): number[] {
// Implementation details...
}