Class: BSV::Primitives::Schnorr::Proof

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, s_prime, z) ⇒ Proof

Returns a new instance of Proof.

Parameters:

  • r (PublicKey)

    commitment point

  • s_prime (PublicKey)

    blinded shared secret

  • z (OpenSSL::BN)

    response scalar



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

#rPublicKey (readonly)

Returns the commitment point R.

Returns:



21
22
23
# File 'lib/bsv/primitives/schnorr.rb', line 21

def r
  @r
end

#s_primePublicKey (readonly)

Returns the blinded shared secret S’.

Returns:

  • (PublicKey)

    the blinded shared secret S’



24
25
26
# File 'lib/bsv/primitives/schnorr.rb', line 24

def s_prime
  @s_prime
end

#zOpenSSL::BN (readonly)

Returns the response scalar z.

Returns:

  • (OpenSSL::BN)

    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.

Parameters:

  • data (String)

    binary proof data (>= 67 bytes)

Returns:

Raises:

  • (ArgumentError)

    if data is too short



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