Module: Mpp::Methods::Tempo::Keychain

Defined in:
lib/mpp/methods/tempo/keychain.rb

Constant Summary collapse

SIGNATURE_TYPE =
0x03
SIGNATURE_LENGTH =
86

Class Method Summary collapse

Class Method Details

.build_signature(msg_hash:, access_key:, root_account:) ⇒ Object

Build a Keychain signature for a message hash.

Format: 0x03 || root_account (20 bytes) || inner_sig (65 bytes) Total: 86 bytes



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mpp/methods/tempo/keychain.rb', line 17

def build_signature(msg_hash:, access_key:, root_account:)
  inner_sig = access_key.sign_hash(msg_hash)
  root_bytes = [.delete_prefix("0x")].pack("H*")

  keychain_sig = [SIGNATURE_TYPE].pack("C") + root_bytes + inner_sig
  unless keychain_sig.bytesize == SIGNATURE_LENGTH
    Kernel.raise "Invalid keychain signature length: #{keychain_sig.bytesize}"
  end

  keychain_sig
end