Module: X402::RequestBinding
- Defined in:
- lib/x402/protocol/request_binding.rb
Overview
Computes canonical hashes of request headers and body for binding challenges and proofs to the actual HTTP request.
Class Method Summary collapse
-
.body_sha256(rack_request) ⇒ Object
Compute SHA-256 hex digest of the request body.
-
.headers_sha256(_rack_request) ⇒ Object
Compute SHA-256 hex digest of canonical request headers.
- .sha256_hex(data) ⇒ Object
Class Method Details
.body_sha256(rack_request) ⇒ Object
Compute SHA-256 hex digest of the request body. Returns the hash of an empty string if no body is present.
13 14 15 16 17 18 19 20 |
# File 'lib/x402/protocol/request_binding.rb', line 13 def body_sha256(rack_request) return sha256_hex("") unless rack_request.body rack_request.body.rewind if rack_request.body.respond_to?(:rewind) body = rack_request.body.read || "" rack_request.body.rewind if rack_request.body.respond_to?(:rewind) sha256_hex(body) end |
.headers_sha256(_rack_request) ⇒ Object
Compute SHA-256 hex digest of canonical request headers. For v1, this is the empty string hash (no headers bound).
24 25 26 |
# File 'lib/x402/protocol/request_binding.rb', line 24 def headers_sha256(_rack_request) sha256_hex("") end |
.sha256_hex(data) ⇒ Object
28 29 30 |
# File 'lib/x402/protocol/request_binding.rb', line 28 def sha256_hex(data) OpenSSL::Digest::SHA256.hexdigest(data) end |