Class: Bitcoin::Payments::PaymentRequest

Inherits:
Protobuf::Message
  • Object
show all
Defined in:
lib/bitcoin/payments/payment_request.pb.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

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

#certsArray[OpenSSL::X509::Certificate]

get certificates

Returns:

  • (Array[OpenSSL::X509::Certificate])


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

#detailsBitcoin::Payments:PaymentDetails

get payment details

Returns:

  • (Bitcoin::Payments:PaymentDetails)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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, sig_message)
end

#valid_time?Boolean

verify expire time for payment request.

Returns:

  • (Boolean)


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_dataStruct

verify pki_data.

Returns:

  • (Struct)

    pki information.



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