Class: X402::Proof

Inherits:
Object
  • Object
show all
Defined in:
lib/x402/protocol/proof.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_sha256Object (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

#paymentObject (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_b64Object

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

#txidObject



32
33
34
# File 'lib/x402/protocol/proof.rb', line 32

def txid
  @payment&.fetch(:txid, nil)
end