Class: BTC::TestSignatureChecker
- Inherits:
-
Object
- Object
- BTC::TestSignatureChecker
- Includes:
- SignatureChecker
- Defined in:
- lib/btcruby/script/test_signature_checker.rb
Instance Method Summary collapse
- #check_lock_time(lock_time) ⇒ Object
- #check_signature(script_signature: nil, public_key: nil, script: nil) ⇒ Object
-
#initialize(signature_hash: nil, timestamp: nil) ⇒ TestSignatureChecker
constructor
A new instance of TestSignatureChecker.
-
#signature_hash ⇒ Object
for testing check_signature.
-
#timestamp ⇒ Object
for testing check_lock_time.
Constructor Details
#initialize(signature_hash: nil, timestamp: nil) ⇒ TestSignatureChecker
Returns a new instance of TestSignatureChecker.
5 6 7 8 |
# File 'lib/btcruby/script/test_signature_checker.rb', line 5 def initialize(signature_hash: nil, timestamp: nil) @signature_hash = signature_hash @timestamp = end |
Instance Method Details
#check_lock_time(lock_time) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/btcruby/script/test_signature_checker.rb', line 32 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 !( ( < LOCKTIME_THRESHOLD && lock_time < LOCKTIME_THRESHOLD) || ( >= 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 >= lock_time end |
#check_signature(script_signature: nil, public_key: nil, script: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/btcruby/script/test_signature_checker.rb', line 20 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, hash) return result end |
#signature_hash ⇒ Object
for testing check_signature
11 12 13 |
# File 'lib/btcruby/script/test_signature_checker.rb', line 11 def signature_hash @signature_hash end |
#timestamp ⇒ Object
for testing check_lock_time
16 17 18 |
# File 'lib/btcruby/script/test_signature_checker.rb', line 16 def @timestamp end |