Class: Immudb::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/immudb/store.rb

Class Method Summary collapse

Class Method Details

.entry_spec_digest_for(version) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/immudb/store.rb', line 75

def entry_spec_digest_for(version)
  if version == 0
    method(:entry_spec_digest_v0)
  elsif version == 1
    method(:entry_spec_digest_v1)
  else
    # TODO raise ErrUnsupportedTxVersion
    raise VerificationError
  end
end

.new_tx_with_entries(header, entries) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/immudb/store.rb', line 16

def new_tx_with_entries(header, entries)
  htree = HTree.new(entries.length)

  tx = Tx.new
  tx.header = header
  tx.entries = entries
  tx.htree = htree
  tx
end

.verify_dual_proof(proof, sourceTxID, targetTxID, sourceAlh, targetAlh) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/immudb/store.rb', line 46

def verify_dual_proof(proof, sourceTxID, targetTxID, sourceAlh, targetAlh)
  if proof.nil? || proof.sourceTxHeader.nil? || proof.targetTxHeader.nil? || proof.sourceTxHeader.iD != sourceTxID || proof.targetTxHeader.iD != targetTxID
    return false
  end
  if proof.sourceTxHeader.iD == 0 || proof.sourceTxHeader.iD > proof.targetTxHeader.iD
    return false
  end
  if sourceAlh != proof.sourceTxHeader.alh
    return false
  end
  if targetAlh != proof.targetTxHeader.alh
    return false
  end
  if sourceTxID < proof.targetTxHeader.blTxID && !verify_inclusion_aht(proof.inclusionProof, sourceTxID, proof.targetTxHeader.blTxID, leaf_for(sourceAlh), proof.targetTxHeader.blRoot)
    return false
  end
  if proof.sourceTxHeader.blTxID > 0 && !verify_consistency(proof.consistencyProof, proof.sourceTxHeader.blTxID, proof.targetTxHeader.blTxID, proof.sourceTxHeader.blRoot, proof.targetTxHeader.blRoot)
    return false
  end
  if proof.targetTxHeader.blTxID > 0 && !verify_last_inclusion(proof.lastInclusionProof, proof.targetTxHeader.blTxID, leaf_for(proof.targetBlTxAlh), proof.targetTxHeader.blRoot)
    return false
  end
  if sourceTxID < proof.targetTxHeader.blTxID
    verify_linear_proof(proof.linearProof, proof.targetTxHeader.blTxID, targetTxID, proof.targetBlTxAlh, targetAlh)
  else
    verify_linear_proof(proof.linearProof, sourceTxID, targetTxID, sourceAlh, targetAlh)
  end
end

.verify_inclusion(proof, digest, root) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/immudb/store.rb', line 26

def verify_inclusion(proof, digest, root)
  return false if proof.nil?
  leaf = LEAF_PREFIX + digest
  calc_root = Digest::SHA256.digest(leaf)
  i = proof.leaf
  r = proof.width - 1
  proof.terms.to_a.each do |t|
    b = NODE_PREFIX
    if i % 2 == 0 && i != r
      b = b + calc_root + t
    else
      b = b + t + calc_root
    end
    calc_root = Digest::SHA256.digest(b)
    i = i.div(2)
    r = r.div(2)
  end
  i == r && root == calc_root
end