Class: X402::Proof
- Inherits:
-
Object
- Object
- X402::Proof
- Defined in:
- lib/x402/protocol/proof.rb
Instance Attribute Summary collapse
-
#challenge_sha256 ⇒ Object
readonly
Returns the value of attribute challenge_sha256.
-
#payment ⇒ Object
readonly
Returns the value of attribute payment.
Class Method Summary collapse
-
.from_header(header_value) ⇒ Object
Parse a proof from the X402-Proof header (base64url-encoded JSON).
Instance Method Summary collapse
-
#initialize(challenge_sha256:, payment:) ⇒ Proof
constructor
A new instance of Proof.
-
#rawtx_b64 ⇒ Object
Convenience accessors for payment fields.
- #txid ⇒ Object
Constructor Details
#initialize(challenge_sha256:, payment:) ⇒ Proof
Returns a new instance of Proof.
9 10 11 12 |
# File 'lib/x402/protocol/proof.rb', line 9 def initialize(challenge_sha256:, payment:) @challenge_sha256 = challenge_sha256 @payment = payment end |
Instance Attribute Details
#challenge_sha256 ⇒ Object (readonly)
Returns the value of attribute challenge_sha256.
7 8 9 |
# File 'lib/x402/protocol/proof.rb', line 7 def challenge_sha256 @challenge_sha256 end |
#payment ⇒ Object (readonly)
Returns the value of attribute payment.
7 8 9 |
# File 'lib/x402/protocol/proof.rb', line 7 def payment @payment end |
Class Method Details
.from_header(header_value) ⇒ Object
Parse a proof from the X402-Proof header (base64url-encoded JSON).
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/x402/protocol/proof.rb', line 15 def self.from_header(header_value) json = Base64Url.decode(header_value) data = JSON.parse(json, symbolize_names: true) new( challenge_sha256: data[:challenge_sha256], payment: data[:payment] ) rescue JSON::ParserError raise X402::Error, "invalid proof JSON" end |
Instance Method Details
#rawtx_b64 ⇒ Object
Convenience accessors for payment fields.
28 29 30 |
# File 'lib/x402/protocol/proof.rb', line 28 def rawtx_b64 @payment&.fetch(:rawtx_b64, nil) end |
#txid ⇒ Object
32 33 34 |
# File 'lib/x402/protocol/proof.rb', line 32 def txid @payment&.fetch(:txid, nil) end |