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
- #fee_payer_allowed_fee_tokens ⇒ Object
-
#initialize(chain_id: nil, rpc_url: nil, timeout: 30, store: nil, validate_sender: 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, validate_sender: nil) ⇒ ChargeIntent
Returns a new instance of ChargeIntent.
25 26 27 28 29 30 31 32 |
# File 'lib/mpp/methods/tempo/intents.rb', line 25 def initialize(chain_id: nil, rpc_url: nil, timeout: 30, store: nil, validate_sender: nil) @name = "charge" @rpc_url = rpc_url || (chain_id ? Defaults.rpc_url_for_chain(chain_id) : nil) @_method = nil @timeout = timeout @store = store @validate_sender = validate_sender end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/mpp/methods/tempo/intents.rb', line 22 def name @name end |
#rpc_url ⇒ Object
Returns the value of attribute rpc_url.
23 24 25 |
# File 'lib/mpp/methods/tempo/intents.rb', line 23 def rpc_url @rpc_url end |
Instance Method Details
#fee_payer ⇒ Object
34 35 36 |
# File 'lib/mpp/methods/tempo/intents.rb', line 34 def fee_payer @_method&.fee_payer end |
#fee_payer_allowed_fee_tokens ⇒ Object
38 39 40 |
# File 'lib/mpp/methods/tempo/intents.rb', line 38 def fee_payer_allowed_fee_tokens @_method&.fee_payer_allowed_fee_tokens end |
#verify(credential, request) ⇒ Object
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 69 70 71 72 73 74 75 |
# File 'lib/mpp/methods/tempo/intents.rb', line 42 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, credential: credential) when "transaction" payload = Schemas::TransactionCredentialPayload.new( type: "transaction", signature: payload_data["signature"] ) verify_transaction(payload, req, credential: credential) 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 |