class Bitcoin::Payments::PaymentRequest
github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#PaymentDetailsPaymentRequest
Public Class Methods
parse_from_payload(payload)
click to toggle source
# File lib/bitcoin/payments/payment_request.pb.rb, line 17 def self.parse_from_payload(payload) self.decode(payload) end
Public Instance Methods
certs()
click to toggle source
get certificates @return [Array]
# File lib/bitcoin/payments/payment_request.pb.rb, line 36 def certs return [] unless has_pki? X509Certificates.decode(pki_data).certs end
details()
click to toggle source
get payment details @return [Bitcoin::Payments:PaymentDetails]
# File lib/bitcoin/payments/payment_request.pb.rb, line 30 def details PaymentDetails.decode(serialized_payment_details) end
has_pki?()
click to toggle source
whether exist pki_data
.
# File lib/bitcoin/payments/payment_request.pb.rb, line 42 def has_pki? pki_type != 'none' end
valid_sig?()
click to toggle source
verify signature.
# 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, sig_message) end
valid_time?()
click to toggle source
verify expire time for payment request.
# 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()
click to toggle source
verify pki_data
. @return [Struct] pki information.
# 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
Private Instance Methods
sig_message()
click to toggle source
Generate data to be signed
# File lib/bitcoin/payments/payment_request.pb.rb, line 70 def sig_message PaymentRequest.new(payment_details_version: payment_details_version, pki_type: pki_type, pki_data: pki_data, signature: '', serialized_payment_details: serialized_payment_details).encode end