Class: Mpp::Methods::Tempo::ChargeIntent
- Inherits:
-
Object
- Object
- Mpp::Methods::Tempo::ChargeIntent
- Defined in:
- lib/mpp/methods/tempo/intents.rb
Overview
Tempo charge intent for server-side verification.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rpc_url ⇒ Object
Returns the value of attribute rpc_url.
Instance Method Summary collapse
- #fee_payer ⇒ Object
-
#initialize(chain_id: nil, rpc_url: nil, timeout: 30, store: nil) ⇒ ChargeIntent
constructor
A new instance of ChargeIntent.
- #verify(credential, request) ⇒ Object
Constructor Details
#initialize(chain_id: nil, rpc_url: nil, timeout: 30, store: nil) ⇒ ChargeIntent
Returns a new instance of ChargeIntent.
23 24 25 26 27 28 29 |
# File 'lib/mpp/methods/tempo/intents.rb', line 23 def initialize(chain_id: nil, rpc_url: nil, timeout: 30, store: nil) @name = "charge" @rpc_url = rpc_url || (chain_id ? Defaults.rpc_url_for_chain(chain_id) : nil) @_method = nil @timeout = timeout @store = store end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/mpp/methods/tempo/intents.rb', line 20 def name @name end |
#rpc_url ⇒ Object
Returns the value of attribute rpc_url.
21 22 23 |
# File 'lib/mpp/methods/tempo/intents.rb', line 21 def rpc_url @rpc_url end |
Instance Method Details
#fee_payer ⇒ Object
31 32 33 |
# File 'lib/mpp/methods/tempo/intents.rb', line 31 def fee_payer @_method&.fee_payer end |
#verify(credential, request) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mpp/methods/tempo/intents.rb', line 35 def verify(credential, request) req = Schemas::ChargeRequest.from_hash(request) # Check challenge expiry challenge_expires = credential.challenge.expires if challenge_expires expires = Time.iso8601(challenge_expires.gsub("Z", "+00:00")) raise Mpp::VerificationError, "Request has expired" if expires < Time.now.utc end payload_data = credential.payload unless payload_data.is_a?(Hash) && payload_data.key?("type") raise Mpp::VerificationError, "Invalid credential payload" end case payload_data["type"] when "hash" payload = Schemas::HashCredentialPayload.new(type: "hash", hash: payload_data["hash"]) verify_hash(payload, req) when "transaction" payload = Schemas::TransactionCredentialPayload.new( type: "transaction", signature: payload_data["signature"] ) verify_transaction(payload, req) when "proof" payload = Schemas::ProofCredentialPayload.new( type: "proof", signature: payload_data["signature"] ) verify_proof(payload, req, credential: credential) else raise Mpp::VerificationError, "Invalid credential type: #{payload_data["type"]}" end end |