Sha256: 9617261c92f91d86e9137cca173f16e6d71a3e998c1e1d1911827dd15b0074a8
Contents?: true
Size: 1.56 KB
Versions: 4
Compression:
Stored size: 1.56 KB
Contents
module BTC class TestSignatureChecker include SignatureChecker def initialize(signature_hash: nil, timestamp: nil) @signature_hash = signature_hash @timestamp = timestamp end # for testing check_signature def signature_hash @signature_hash end # for testing check_lock_time def timestamp @timestamp end def check_signature(script_signature:nil, public_key:nil, script:nil) # Signature must be long enough to contain a sighash byte. return false if script_signature.size < 1 # Extract raw ECDSA signature by stripping off the last hashtype byte ecdsa_sig = script_signature[0..-2] key = BTC::Key.new(public_key: public_key) result = key.verify_ecdsa_signature(ecdsa_sig, signature_hash) return result end def check_lock_time(lock_time) # There are two times of nLockTime: lock-by-blockheight # and lock-by-blocktime, distinguished by whether # nLockTime < LOCKTIME_THRESHOLD. # # We want to compare apples to apples, so fail the script # if the type of nLockTime being tested is not the same as # the nLockTime in the transaction. if !( (timestamp < LOCKTIME_THRESHOLD && lock_time < LOCKTIME_THRESHOLD) || (timestamp >= LOCKTIME_THRESHOLD && lock_time >= LOCKTIME_THRESHOLD) ) return false end # Now that we know we're comparing apples-to-apples, the # comparison is a simple numeric one. return timestamp >= lock_time end end end
Version data entries
4 entries across 4 versions & 1 rubygems