Class: BSV::Primitives::Schnorr::Proof
- Inherits:
-
Object
- Object
- BSV::Primitives::Schnorr::Proof
- Defined in:
- lib/bsv/primitives/schnorr.rb
Overview
A Schnorr zero-knowledge proof consisting of a commitment point, blinded shared secret, and response scalar.
Instance Attribute Summary collapse
-
#r ⇒ PublicKey
readonly
The commitment point R.
-
#s_prime ⇒ PublicKey
readonly
The blinded shared secret S’.
-
#z ⇒ OpenSSL::BN
readonly
The response scalar z.
Class Method Summary collapse
-
.from_binary(data) ⇒ Proof
Deserialise a proof from its binary representation.
Instance Method Summary collapse
-
#initialize(r, s_prime, z) ⇒ Proof
constructor
A new instance of Proof.
Constructor Details
#initialize(r, s_prime, z) ⇒ Proof
Returns a new instance of Proof.
32 33 34 35 36 |
# File 'lib/bsv/primitives/schnorr.rb', line 32 def initialize(r, s_prime, z) @r = r @s_prime = s_prime @z = z end |
Instance Attribute Details
#r ⇒ PublicKey (readonly)
Returns the commitment point R.
21 22 23 |
# File 'lib/bsv/primitives/schnorr.rb', line 21 def r @r end |
#s_prime ⇒ PublicKey (readonly)
Returns the blinded shared secret S’.
24 25 26 |
# File 'lib/bsv/primitives/schnorr.rb', line 24 def s_prime @s_prime end |
#z ⇒ OpenSSL::BN (readonly)
Returns the response scalar z.
27 28 29 |
# File 'lib/bsv/primitives/schnorr.rb', line 27 def z @z end |
Class Method Details
.from_binary(data) ⇒ Proof
Deserialise a proof from its binary representation.
The format is: R (33 bytes) + S’ (33 bytes) + z (remaining bytes). The z scalar is variable-length to accommodate both the Ruby SDK’s fixed 32-byte encoding and the TS SDK’s minimal encoding (which omits leading zero bytes). See issue #203.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bsv/primitives/schnorr.rb', line 48 def self.from_binary(data) data = data.b raise ArgumentError, "proof too short: #{data.bytesize} bytes (minimum 67)" if data.bytesize < 67 r = PublicKey.from_bytes(data.byteslice(0, 33)) s_prime = PublicKey.from_bytes(data.byteslice(33, 33)) z_bytes = data.byteslice(66, data.bytesize - 66) z = OpenSSL::BN.new(z_bytes, 2) new(r, s_prime, z) end |