Module: X402::Verification::ProtocolChecks
- Defined in:
- lib/x402/verification/protocol_checks.rb
Class Method Summary collapse
- .check_challenge_hash!(challenge, proof) ⇒ Object
- .check_expiry!(challenge) ⇒ Object
- .check_request_binding!(challenge, rack_request) ⇒ Object
- .check_scheme!(challenge) ⇒ Object
- .check_version!(challenge) ⇒ Object
Class Method Details
.check_challenge_hash!(challenge, proof) ⇒ Object
20 21 22 |
# File 'lib/x402/verification/protocol_checks.rb', line 20 def check_challenge_hash!(challenge, proof) raise VerificationError, "challenge hash mismatch" unless challenge.sha256_hex == proof.challenge_sha256 end |
.check_expiry!(challenge) ⇒ Object
38 39 40 |
# File 'lib/x402/verification/protocol_checks.rb', line 38 def check_expiry!(challenge) raise VerificationError.new("challenge expired", status: 402) if challenge.expires_at <= Time.now.to_i end |
.check_request_binding!(challenge, rack_request) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/x402/verification/protocol_checks.rb', line 24 def check_request_binding!(challenge, rack_request) raise VerificationError, "request method mismatch" unless challenge.method == rack_request.request_method raise VerificationError, "request path mismatch" unless challenge.path == rack_request.path_info raise VerificationError, "request query mismatch" unless challenge.query == rack_request.query_string expected_body = RequestBinding.body_sha256(rack_request) raise VerificationError, "request body hash mismatch" unless challenge.req_body_sha256 == expected_body expected_headers = RequestBinding.headers_sha256(rack_request) return if challenge.req_headers_sha256 == expected_headers raise VerificationError, "request headers hash mismatch" end |
.check_scheme!(challenge) ⇒ Object
14 15 16 17 18 |
# File 'lib/x402/verification/protocol_checks.rb', line 14 def check_scheme!(challenge) return if Challenge::SUPPORTED_SCHEMES.include?(challenge.scheme) raise VerificationError, "unsupported scheme: #{challenge.scheme}" end |
.check_version!(challenge) ⇒ Object
8 9 10 11 12 |
# File 'lib/x402/verification/protocol_checks.rb', line 8 def check_version!(challenge) return if challenge.version == Challenge::CURRENT_VERSION raise VerificationError, "unsupported version: #{challenge.version}" end |