module Bitcoin

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Porting part of the code from bitcoin-ruby. see the license. github.com/lian/bitcoin-ruby/blob/master/COPYING

Constants

ANNEX_TAG

Tag for input annex. If there are at least two witness elements for a transaction input, and the first byte of the last element is 0x50, this last element is called annex, and has meanings independent of the script

BIP32_EXTKEY_WITH_VERSION_SIZE
COIN
COINBASE_MATURITY

Coinbase transaction outputs can only be spent after this number of new blocks (network rule)

COINBASE_WTXID
CURVE_ORDER

Integers modulo the order of the curve(secp256k1)

DEFAULT_MAX_NUM_SIZE

Maximum number length in bytes

DUST_RELAY_TX_FEE

Min feerate for defining dust.

ERRCODES_MAP
HARDENED_THRESHOLD
LOCKTIME_MEDIAN_TIME_PAST
LOCKTIME_THRESHOLD

Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.

LOCKTIME_VERIFY_SEQUENCE

Flags for nSequence and nLockTime locks

MANDATORY_SCRIPT_VERIFY_FLAGS
MAX_BLOCK_SERIALIZED_SIZE

The maximum allowed size for a serialized block, in bytes (only for buffer size limits)

MAX_BLOCK_SIGOPS_COST

The maximum allowed number of signature check operations in a block (network rule)

MAX_BLOCK_WEIGHT

The maximum allowed weight for a block, see BIP 141 (network rule)

MAX_FUTURE_BLOCK_TIME

Maximum amount of time that a block timestamp is allowed to exceed the current network-adjusted time before the block will be accepted.

MAX_MONEY
MAX_OPS_PER_SCRIPT

Maximum number of non-push operations per script

MAX_OP_RETURN_RELAY

80 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes.

MAX_PUBKEYS_PER_MULTISIG

Maximum number of public keys per multisig

MAX_SCRIPT_ELEMENT_SIZE

Maximum number of bytes pushable to the stack

MAX_SCRIPT_SIZE

Maximum script length in bytes

MAX_STACK_SIZE

Maximum number of size in the stack

MEDIAN_TIME_SPAN

Size of set to pick median time from.

MESSAGE_HEADER_SIZE

for message

MIN_SERIALIZABLE_TRANSACTION_WEIGHT

10 is the lower bound for the size of a serialized Tx

MIN_TRANSACTION_WEIGHT

60 is the lower bound for the size of a valid serialized Tx

NAME_MAP
PARALLEL_THREAD

for peer

SCRIPT_ERR_BAD_OPCODE

Logical/Format/Canonical errors

SCRIPT_ERR_CHECKMULTISIGVERIFY
SCRIPT_ERR_CHECKSIGVERIFY
SCRIPT_ERR_CLEANSTACK
SCRIPT_ERR_DISABLED_OPCODE
SCRIPT_ERR_DISCOURAGE_OP_SUCCESS
SCRIPT_ERR_DISCOURAGE_UNKNOWN_ANNEX
SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS

softfork safeness

SCRIPT_ERR_DISCOURAGE_UPGRADABLE_PUBKEYTYPE
SCRIPT_ERR_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION
SCRIPT_ERR_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
SCRIPT_ERR_EQUALVERIFY
SCRIPT_ERR_ERROR_COUNT
SCRIPT_ERR_EVAL_FALSE
SCRIPT_ERR_INVALID_ALTSTACK_OPERATION
SCRIPT_ERR_INVALID_STACK_OPERATION
SCRIPT_ERR_MINIMALDATA
SCRIPT_ERR_MINIMALIF
SCRIPT_ERR_NEGATIVE_LOCKTIME

CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY

SCRIPT_ERR_NUMEQUALVERIFY
SCRIPT_ERR_OK

for script error

SCRIPT_ERR_OP_CODESEPARATOR

Constant scriptCode

SCRIPT_ERR_OP_COUNT
SCRIPT_ERR_OP_RETURN
SCRIPT_ERR_PUBKEYTYPE
SCRIPT_ERR_PUBKEY_COUNT
SCRIPT_ERR_PUSH_SIZE
SCRIPT_ERR_SCHNORR_SIG
SCRIPT_ERR_SCHNORR_SIG_HASHTYPE
SCRIPT_ERR_SCHNORR_SIG_SIZE

Taproot

SCRIPT_ERR_SCRIPT_SIZE

Max sizes

SCRIPT_ERR_SIG_COUNT
SCRIPT_ERR_SIG_DER
SCRIPT_ERR_SIG_FINDANDDELETE
SCRIPT_ERR_SIG_HASHTYPE

Malleability

SCRIPT_ERR_SIG_HIGH_S
SCRIPT_ERR_SIG_NULLDUMMY
SCRIPT_ERR_SIG_NULLFAIL
SCRIPT_ERR_SIG_PUSHONLY
SCRIPT_ERR_STACK_SIZE
SCRIPT_ERR_TAPROOT_WRONG_CONTROL_SIZE
SCRIPT_ERR_TAPSCRIPT_CHECKMULTISIG
SCRIPT_ERR_TAPSCRIPT_MINIMALIF
SCRIPT_ERR_TAPSCRIPT_VALIDATION_WEIGHT
SCRIPT_ERR_UNBALANCED_CONDITIONAL
SCRIPT_ERR_UNKNOWN_ERROR
SCRIPT_ERR_UNSATISFIED_LOCKTIME
SCRIPT_ERR_VERIFY

Failed verify operations

SCRIPT_ERR_WITNESS_MALLEATED
SCRIPT_ERR_WITNESS_MALLEATED_P2SH
SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH
SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY
SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH

segregated witness

SCRIPT_ERR_WITNESS_PUBKEYTYPE
SCRIPT_ERR_WITNESS_UNEXPECTED
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
SCRIPT_VERIFY_CLEANSTACK
SCRIPT_VERIFY_CONST_SCRIPTCODE
SCRIPT_VERIFY_DERSIG
SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS
SCRIPT_VERIFY_DISCOURAGE_UNKNOWN_ANNEX
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
SCRIPT_VERIFY_LOW_S
SCRIPT_VERIFY_MINIMALDATA
SCRIPT_VERIFY_MINIMALIF
SCRIPT_VERIFY_NONE

script verify flags

SCRIPT_VERIFY_NULLDUMMY
SCRIPT_VERIFY_NULLFAIL
SCRIPT_VERIFY_P2SH
SCRIPT_VERIFY_SIGPUSHONLY
SCRIPT_VERIFY_STRICTENC
SCRIPT_VERIFY_TAPROOT
SCRIPT_VERIFY_WITNESS
SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
SIGHASH_TYPE

Signature hash types/flags

STANDARD_SCRIPT_VERIFY_FLAGS

Standard script verification flags that standard transactions will comply with.

TAPROOT_CONTROL_BASE_SIZE
TAPROOT_CONTROL_MAX_NODE_COUNT
TAPROOT_CONTROL_MAX_SIZE
TAPROOT_CONTROL_NODE_SIZE
TAPROOT_LEAF_MASK
TAPROOT_LEAF_TAPSCRIPT
VALIDATION_WEIGHT_OFFSET

How much weight budget is added to the witness size (Tapscript only, see BIP 342).

VALIDATION_WEIGHT_PER_SIGOP_PASSED

Validation weight per passing signature (Tapscript only, see BIP 342).

VERSION
WITNESS_COMMITMENT_HEADER

witness commitment

WITNESS_SCALE_FACTOR
WITNESS_V0_KEYHASH_SIZE
WITNESS_V0_SCRIPTHASH_SIZE

Signature hash sizes

WITNESS_V1_TAPROOT_SIZE
WITNESS_VERSION_V0

witness version

WITNESS_VERSION_V1

Public Class Methods

base_dir() click to toggle source

base dir path that store blockchain data and wallet data

# File lib/bitcoin.rb, line 97
def self.base_dir
  "#{Dir.home}/.bitcoinrb/#{@chain_param}"
end
chain_params() click to toggle source

current bitcoin network chain params.

# File lib/bitcoin.rb, line 81
def self.chain_params
  return @current_chain if @current_chain
  case @chain_param
  when :mainnet
    @current_chain = Bitcoin::ChainParams.mainnet
  when :testnet
    @current_chain = Bitcoin::ChainParams.testnet
  when :regtest
    @current_chain = Bitcoin::ChainParams.regtest
  when :signet
    @current_chain = Bitcoin::ChainParams.signet
  end
  @current_chain
end
chain_params=(name) click to toggle source

set bitcoin network chain params

# File lib/bitcoin.rb, line 74
def self.chain_params=(name)
  raise "chain params for #{name} is not defined." unless %i(mainnet testnet regtest signet).include?(name.to_sym)
  @current_chain = nil
  @chain_param = name.to_sym
end
hmac_sha256(key, data) click to toggle source
# File lib/bitcoin.rb, line 111
def self.hmac_sha256(key, data)
  OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), key, data)
end
hmac_sha512(key, data) click to toggle source
# File lib/bitcoin.rb, line 107
def self.hmac_sha512(key, data)
  OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA512'), key, data)
end
secp_impl() click to toggle source

get secp implementation module

# File lib/bitcoin.rb, line 102
def self.secp_impl
  path = ENV['SECP256K1_LIB_PATH']
  (path && File.exist?(path)) ? Bitcoin::Secp256k1::Native : Bitcoin::Secp256k1::Ruby
end