CertTree

Imperative wrapper of MerkleTree

This module contains an imperative wrapper of the functional API provided by MerkleTree. This makes common usage pattern around these trees more convenient.

This module defines two types:

So this is the suggested idiom:

  stable let cert_store : CertTree.Store = CertTree.newStore();
  let ct = CertTree.Ops(cert_store);
  

type Store = { var tree : MerkleTree.Tree }

type Path = MerkleTree.Path

type Value = MerkleTree.Value

type Key = MerkleTree.Key

type Hash = MerkleTree.Hash

type Witness = MerkleTree.Witness

public func newStore() : Store

class Ops(ct : Store)

public func put(ks : Path, v : Value)

Inserting a value at a given path into the tree.

An existing value (or subtree) under that path is overridden.

If there are values at any prefix of the given path, they will be removed.

public func delete(ks : Path)

Deleting a path from a tree.

This removes the given path from the tree, independently of whether there is a value at that path, or a whole subtree.

If there are values at any prefix of the given path, they will be removed.

public func lookup(ks : Path) : ?Value

Looking up a value at a path

This will return null if the path does not exist, or if there is a subtree (and not a value) at that key.

public func labelsAt(ks : Path) : Iter.Iter<Key>

Lookup up all labels at a path.

Returns an iterator, so you can use it with

for (k in ct.labelsAt(["some", "path"))) { … }

public func treeHash() : Hash

Root hash

public func setCertifiedData()

Sets the canister's certified data to the root hash Call this at the end of any update function that changed the certified data tree

public func reveal(path : Path) : Witness

Create a witness that reveals the value of the key k in the tree tree.

If k is not in the tree, the witness will prove that fact.

public func reveals(paths : Iter.Iter<Path>) : Witness

Reveals multiple paths

public func encodeWitness(w : Witness) : Blob

Encodes a witness as CBOR, e.g. for certified assets