lookup_path_value_in_an_ic_certificate_tree function

Uint8List? lookup_path_value_in_an_ic_certificate_tree(
  1. List tree,
  2. List<Uint8List> path
)

Looks up a path value in a certificate tree returned by the network. if path doesn't exist, returns null. Useful when verifying a canister's certified_data.

tree is a HashTree.
path is a path in the HashTree specified as a list of path-segments. Each path-segment is some bytes.

path: [utf8.encode('canister'), common.SYSTEM_CANISTERS.cycles_mint.principal.bytes, utf8.encode('certified_data')]) 
path: [utf8.encode('time')] 

Implementation

Uint8List? lookup_path_value_in_an_ic_certificate_tree(
    List tree,
    List<Uint8List> path
) {
    if (path.length > 0) {
        List flattrees = flattentreeforks(tree);
        for (List flattree in flattrees) {
            if (flattree[0]==2) {
                if (aresamebytes(flattree[1], path[0]) == true) {
                    return lookup_path_value_in_an_ic_certificate_tree(flattree[2], path.sublist(1));
                }
            }
        }
    }
    else {
        if (tree[0]==3) {
            return Uint8List.fromList(tree[1]);
        }
    }
    return null;
}