Type alias Input<Bytecode, ByteStringRepresentation>

Input<Bytecode, ByteStringRepresentation>: {
    outpointIndex: number;
    outpointTransactionHash: ByteStringRepresentation;
    sequenceNumber: number;
    unlockingBytecode: Bytecode;
}

Data type representing a Transaction Input.

Type Parameters

  • Bytecode = Uint8Array

    the type of unlockingBytecode - this can be configured to allow for defining compilation directives.

  • ByteStringRepresentation = Uint8Array

    the type used to represent strings of bytes (Input.outpointTransactionHash) - this allows for JSON-compatible types to be used rather than the default Uint8Array.

Type declaration

  • outpointIndex: number

    The index of the output in the transaction from which this input is spent.

    Remarks

    An "outpoint" is a reference (A.K.A. "pointer") to a specific output in a previous transaction.

  • outpointTransactionHash: ByteStringRepresentation

    The hash of the raw transaction from which this input is spent in user interface byte order (hashTransactionUiOrder). This is the byte order typically seen in wallets and block explorers (the reverse of that used by P2P network messages, the VM, and most SHA-256 libraries).

    A.K.A. Transaction ID

    Remarks

    An "outpoint" is a reference (A.K.A. "pointer") to a specific output in a previous transaction.

    Encoded raw bitcoin transactions encode this value in little-endian byte order (see hashTransactionP2pOrder). However, it is more common to use big-endian byte order when displaying transaction hashes (see hashTransactionUiOrder).

  • sequenceNumber: number

    The positive, 32-bit unsigned integer used as the "sequence number" for this input.

    A sequence number is a complex bitfield that can encode several properties about an input:

    • sequence age support – whether or not the input can use OP_CHECKSEQUENCEVERIFY, and the minimum number of blocks or length of time that has passed since this input's source transaction was mined (up to approximately 1 year).
    • locktime support – whether or not the input can use OP_CHECKLOCKTIMEVERIFY

    Sequence Age Support

    Sequence number age is enforced by mining consensus – a transaction is invalid until it has "aged" such that all outputs referenced by its age-enabled inputs are at least as old as claimed by their respective sequence numbers.

    This allows sequence numbers to function as a "relative locktime" for each input: a lockingBytecode can use the OP_CHECKSEQUENCEVERIFY operation to verify that the funds being spent have been "locked" for a minimum required amount of time (or block count). This can be used in protocols that require a reliable "proof-of-publication", like escrow, time-delayed withdrawals, and various payment channel protocols.

    Sequence age support is enabled unless the "disable bit" – the most significant bit – is set (i.e. the sequence number is less than (1 << 31) >>> 0/0b10000000000000000000000000000000/2147483648).

    If sequence age is enabled, the "type bit" – the most significant bit in the second-most significant byte (1 << 22/0b1000000000000000000000/2097152) – indicates the unit type of the specified age:

    • if set, the age is in units of 512 seconds (using Median Time-Past)
    • if not set, the age is a number of blocks

    The least significant 16 bits specify the age (i.e. age = sequenceNumber & 0x0000ffff). This makes the maximum age either 65535 blocks (about 1.25 years) or 33553920 seconds (about 1.06 years).

    Locktime Support

    Locktime support is disabled for an input if the sequence number is exactly 0xffffffff (4294967295). Because this value requires the "disable bit" to be set, disabling locktime support also disables sequence age support.

    With locktime support disabled, if either OP_CHECKLOCKTIMEVERIFY or OP_CHECKSEQUENCEVERIFY are encountered during the validation of unlockingBytecode, an error is produced, and the transaction is invalid.

    Remarks

    The term "sequence number" was the name given to this field in the Satoshi implementation of the bitcoin transaction format. The field was originally intended for use in a multi-party signing protocol where parties updated the "sequence number" to indicate to miners that this input should replace a previously-signed input in an existing, not-yet-mined transaction. The original use-case was not completed and relied on behavior that can not be enforced by mining consensus, so the field was mostly-unused until it was repurposed by BIP68 in block 419328. See BIP68, BIP112, and BIP113 for details.

  • unlockingBytecode: Bytecode

    The bytecode used to unlock a transaction output. To spend an output, unlocking bytecode must be included in a transaction input that – when evaluated in the authentication virtual machine with the locking bytecode – completes in valid state.

    A.K.A. scriptSig or "unlocking script"

Generated using TypeDoc