reconstruct function

Future<Uint8List> reconstruct(
  1. List t
)

Implementation

Future<Uint8List> reconstruct(List t) async {
  final nodeId = NodeId.fromValue(t[0]);
  switch (nodeId) {
    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)),
          ]),
        ),
      );
  }
}