Class: PedicelPay::TokenHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/pedicel-pay/token_header.rb

Constant Summary collapse

Error =
Class.new(PedicelPay::Error)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_hash: nil, ephemeral_pubkey: nil, pubkey_hash: nil, transaction_id: nil) ⇒ TokenHeader

Returns a new instance of TokenHeader.



11
12
13
14
# File 'lib/pedicel-pay/token_header.rb', line 11

def initialize(data_hash: nil, ephemeral_pubkey: nil, pubkey_hash: nil, transaction_id: nil)
  @data_hash, @ephemeral_pubkey, @pubkey_hash, @transaction_id = \
    data_hash, ephemeral_pubkey,  pubkey_hash,  transaction_id
end

Instance Attribute Details

#data_hashObject

Returns the value of attribute data_hash.



5
6
7
# File 'lib/pedicel-pay/token_header.rb', line 5

def data_hash
  @data_hash
end

#ephemeral_pubkeyObject

Returns the value of attribute ephemeral_pubkey.



5
6
7
# File 'lib/pedicel-pay/token_header.rb', line 5

def ephemeral_pubkey
  @ephemeral_pubkey
end

#pubkey_hashObject

Returns the value of attribute pubkey_hash.



5
6
7
# File 'lib/pedicel-pay/token_header.rb', line 5

def pubkey_hash
  @pubkey_hash
end

#transaction_idObject

Returns the value of attribute transaction_id.



5
6
7
# File 'lib/pedicel-pay/token_header.rb', line 5

def transaction_id
  @transaction_id
end

Instance Method Details

#sampleObject



29
30
31
32
33
# File 'lib/pedicel-pay/token_header.rb', line 29

def sample
  self.transaction_id ||= PedicelPay.config[:random].bytes(32)

  self
end

#to_hashObject

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pedicel-pay/token_header.rb', line 16

def to_hash
  raise Error, 'missing ephemeral_pubkey' unless ephemeral_pubkey

  result = {
    'ephemeralPublicKey' => Base64.strict_encode64(Helper.ec_key_to_pkey_public_key(ephemeral_pubkey).to_der),
    'publicKeyHash'      => pubkey_hash,
    'transactionId'      => Helper.bytestring_to_hex(transaction_id),
  }
  result.merge!('applicationData' => data_hash) if data_hash

  result
end