Class: Sigma::MerkleProof

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



16
17
18
# File 'lib/sigma/merkle_proof.rb', line 16

def pointer
  @pointer
end

Class Method Details

.create(leaf_data) ⇒ Object

leaf_data is an Array(Uint8)



19
20
21
22
23
24
25
26
# File 'lib/sigma/merkle_proof.rb', line 19

def self.create(leaf_data)
  pointer = FFI::MemoryPointer.new(:pointer)
  b_ptr = FFI::MemoryPointer.new(:uint8, leaf_data.size)
  b_ptr.write_array_of_uint8(leaf_data)
  error = ergo_merkle_proof_new(b_ptr, leaf_data.size, pointer)
  Util.check_error!(error)
  init(pointer)
end

.with_json(json) ⇒ Object



28
29
30
31
32
# File 'lib/sigma/merkle_proof.rb', line 28

def self.with_json(json)
  pointer = FFI::MemoryPointer.new(:pointer)
  error = ergo_merkle_proof_from_json(json, pointer)
  init(pointer)
end

Instance Method Details

#add_node(hash:, side:) ⇒ Object

Adds a new node and it’s hash to the MerkleProof. Hash must be 32 bytes in size

Parameters:

  • hash: (Array<uint8, 32>)
  • side: (Integer)

See Also:



38
39
40
41
42
43
# File 'lib/sigma/merkle_proof.rb', line 38

def add_node(hash:, side:)
  b_ptr = FFI::MemoryPointer.new(:uint8, hash.size)
  b_ptr.write_array_of_uint8(hash)
  error = ergo_merkle_proof_add_node(self.pointer, b_ptr, hash.size, side)
  Util.check_error!(error)
end

#valid(hash) ⇒ bool

Validates the MerkleProof against the provided root hash

Parameters:

  • hash (Array<uint8>, String)

Returns:

  • (bool)


48
49
50
51
52
53
54
55
56
# File 'lib/sigma/merkle_proof.rb', line 48

def valid(hash)
  if hash.is_a?(Array)
    valid_with_array(hash)
  elsif hash.is_a?(String)
    valid_with_string(hash)
  else
    raise 'Invalid type for hash: #{hash.class}. It must be an Array(Uint8) or String'
  end
end