Class: Bitcoin::Payments::PaymentRequest
- Defined in:
- lib/bitcoin/payments/payment_request.pb.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
-
#certs ⇒ Array[OpenSSL::X509::Certificate]
get certificates.
-
#details ⇒ Bitcoin::Payments:PaymentDetails
get payment details.
-
#has_pki? ⇒ Boolean
whether exist
pki_data
. -
#valid_sig? ⇒ Boolean
verify signature.
-
#valid_time? ⇒ Boolean
verify expire time for payment request.
-
#verify_pki_data ⇒ Struct
verify
pki_data
.
Class Method Details
.parse_from_payload(payload) ⇒ Object
17 18 19 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 17 def self.parse_from_payload(payload) self.decode(payload) end |
Instance Method Details
#certs ⇒ Array[OpenSSL::X509::Certificate]
get certificates
36 37 38 39 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 36 def certs return [] unless has_pki? X509Certificates.decode(pki_data).certs end |
#details ⇒ Bitcoin::Payments:PaymentDetails
get payment details
30 31 32 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 30 def details PaymentDetails.decode(serialized_payment_details) end |
#has_pki? ⇒ Boolean
whether exist pki_data
.
42 43 44 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 42 def has_pki? pki_type != 'none' end |
#valid_sig? ⇒ Boolean
verify signature.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 47 def valid_sig? return false unless has_pki? digest = case pki_type when 'x509+sha256' OpenSSL::Digest::SHA256.new when 'x509+sha1' OpenSSL::Digest::SHA1.new else raise "pki_type: #{pki_type} is invalid type." end certs.first.public_key.verify(digest, signature, ) end |
#valid_time? ⇒ Boolean
verify expire time for payment request.
61 62 63 64 65 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 61 def valid_time? expires = details.expires return true if expires == 0 Time.now.to_i <= expires end |
#verify_pki_data ⇒ Struct
verify pki_data
.
23 24 25 26 |
# File 'lib/bitcoin/payments/payment_request.pb.rb', line 23 def verify_pki_data d = Struct.new(:display_name, :merchant_sign_key, :root_auth, :root_auth_name) d end |