Class: Sigma::SecretKey

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sigma/secret_key.rb

Overview

Secret key for the prover

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



17
18
19
# File 'lib/sigma/secret_key.rb', line 17

def pointer
  @pointer
end

Class Method Details

.createSecretKey

Generate random key

Returns:



21
22
23
24
25
# File 'lib/sigma/secret_key.rb', line 21

def self.create
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_secret_key_generate_random(pointer)
  init(pointer)
end

.from_bytes(bytes) ⇒ SecretKey

Parse dlog secret key from bytes (SEC-1-encoded scalar)

Parameters:

  • bytes (Array<uint8>)

    Array of 8-bit integers (0-255)

Returns:



30
31
32
33
34
35
36
37
# File 'lib/sigma/secret_key.rb', line 30

def self.from_bytes(bytes)
  pointer = FFI::MemoryPointer.new(:pointer)
  b_ptr = FFI::MemoryPointer.new(:uint8, bytes.size)
  b_ptr.write_array_of_uint8(bytes)
  error = ergo_lib_secret_key_from_bytes(b_ptr, pointer)
  Util.check_error!(error)
  init(pointer)
end

.with_raw_pointer(pointer) ⇒ SecretKey

Note:

A user of sigma_rb generally does not need to call this function

Takes ownership of an existing SecretKey Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



43
44
45
# File 'lib/sigma/secret_key.rb', line 43

def self.with_raw_pointer(pointer)
  init(pointer)
end

Instance Method Details

#get_addressAddress

Get address (encoded public image)

Returns:



49
50
51
52
53
# File 'lib/sigma/secret_key.rb', line 49

def get_address
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_secret_key_get_address(self.pointer, pointer)
  Sigma::Address.with_raw_pointer(pointer)
end

#to_bytesArray<uint8>

Encode to bytes

Returns:

  • (Array<uint8>)

    Array of 8-bit integers (0-255)



57
58
59
60
61
62
# File 'lib/sigma/secret_key.rb', line 57

def to_bytes
  bytes_len = 32
  b_ptr = FFI::MemoryPointer.new(:uint8, bytes_len) 
  ergo_lib_secret_key_to_bytes(self.pointer, b_ptr)
  b_ptr.get_array_of_uint8(0, bytes_len)
end