Class: ApplePay::PaymentToken::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_pay/payment_token/signature.rb

Defined Under Namespace

Classes: VerificationFailed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, data:, ephemeral_public_key: nil, wrapped_key: nil, transaction_id:, application_data: nil) ⇒ Signature

Returns a new instance of Signature.



8
9
10
11
12
13
14
15
# File 'lib/apple_pay/payment_token/signature.rb', line 8

def initialize(signature, data:, ephemeral_public_key: nil, wrapped_key: nil, transaction_id:, application_data: nil)
  self.signature = signature
  self.data = data
  self.ephemeral_public_key = ephemeral_public_key
  self.wrapped_key = wrapped_key
  self.transaction_id = transaction_id
  self.application_data = application_data
end

Instance Attribute Details

#application_dataObject

Returns the value of attribute application_data.



6
7
8
# File 'lib/apple_pay/payment_token/signature.rb', line 6

def application_data
  @application_data
end

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/apple_pay/payment_token/signature.rb', line 6

def data
  @data
end

#ephemeral_public_keyObject

Returns the value of attribute ephemeral_public_key.



6
7
8
# File 'lib/apple_pay/payment_token/signature.rb', line 6

def ephemeral_public_key
  @ephemeral_public_key
end

#signatureObject

Returns the value of attribute signature.



6
7
8
# File 'lib/apple_pay/payment_token/signature.rb', line 6

def signature
  @signature
end

#transaction_idObject

Returns the value of attribute transaction_id.



6
7
8
# File 'lib/apple_pay/payment_token/signature.rb', line 6

def transaction_id
  @transaction_id
end

#wrapped_keyObject

Returns the value of attribute wrapped_key.



6
7
8
# File 'lib/apple_pay/payment_token/signature.rb', line 6

def wrapped_key
  @wrapped_key
end

Instance Method Details

#verify!Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/apple_pay/payment_token/signature.rb', line 17

def verify!
  chain = CertificateChain.new signature
  signature_base_string = [
    Base64.decode64(ephemeral_public_key || wrapped_key),
    Base64.decode64(data),
    [transaction_id].pack('H*'),
    [application_data].pack('H*')
  ].join
  chain.verify(
    signature_base_string
  ) or raise VerificationFailed
end