Module: Mpp::Methods::Tempo::Schemas

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

Defined Under Namespace

Classes: ChargeRequest, HashCredentialPayload, MethodDetails, ProofCredentialPayload, TransactionCredentialPayload

Constant Summary collapse

HEX_PATTERN =
/\A0x[a-fA-F0-9]+\z/

Class Method Summary collapse

Class Method Details

.parse_credential_payload(data) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mpp/methods/tempo/schemas.rb', line 79

def parse_credential_payload(data)
  Kernel.raise ArgumentError, "Invalid credential payload" unless data.is_a?(Hash) && data.key?("type")

  case data["type"]
  when "hash"
    HashCredentialPayload.new(type: "hash", hash: data["hash"])
  when "transaction"
    TransactionCredentialPayload.new(type: "transaction", signature: data["signature"])
  when "proof"
    ProofCredentialPayload.new(type: "proof", signature: data["signature"])
  else
    Kernel.raise ArgumentError, "Invalid credential type: #{data["type"]}"
  end
end