Class: Sigma::SecretKey
- Inherits:
-
Object
- Object
- Sigma::SecretKey
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/secret_key.rb
Overview
Secret key for the prover
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create ⇒ SecretKey
Generate random key.
-
.from_bytes(bytes) ⇒ SecretKey
Parse dlog secret key from bytes (SEC-1-encoded scalar).
-
.with_raw_pointer(pointer) ⇒ SecretKey
Takes ownership of an existing SecretKey Pointer.
Instance Method Summary collapse
-
#get_address ⇒ Address
Get address (encoded public image).
-
#to_bytes ⇒ Array<uint8>
Encode to bytes.
Instance Attribute Details
#pointer ⇒ Object
Returns the value of attribute pointer.
17 18 19 |
# File 'lib/sigma/secret_key.rb', line 17 def pointer @pointer end |
Class Method Details
.create ⇒ SecretKey
Generate random key
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)
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.
43 44 45 |
# File 'lib/sigma/secret_key.rb', line 43 def self.with_raw_pointer(pointer) init(pointer) end |
Instance Method Details
#get_address ⇒ Address
Get address (encoded public image)
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_bytes ⇒ Array<uint8>
Encode to bytes
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 |