reconstruct function

Future<Uint8List> reconstruct(
  1. List t
)

Implementation

Future<Uint8List> reconstruct(List t) async {
  switch (t[0] as int) {
    case NodeId.Empty:
      return Future.value(hash(domainSep('ic-hashtree-empty')));
    case NodeId.Pruned:
      return (t[1] as Uint8Buffer).buffer.asUint8List();
    case NodeId.Leaf:
      return Future.value(hash(
        u8aConcat([
          domainSep('ic-hashtree-leaf'),
          (t[1] as Uint8Buffer).buffer.asUint8List(),
        ]),
      ));
    case NodeId.Labeled:
      return Future.value(hash(u8aConcat([
        domainSep('ic-hashtree-labeled'),
        (t[1] as Uint8Buffer).buffer.asUint8List(),
        (await reconstruct(t[2] as List)),
      ])));
    case NodeId.Fork:
      return Future.value(hash(u8aConcat([
        domainSep('ic-hashtree-fork'),
        (await reconstruct(t[1] as List)),
        (await reconstruct(t[2] as List)),
      ])));
    default:
      throw 'unreachable';
  }
}