ADAByronAddr.deserialize constructor

ADAByronAddr.deserialize(
  1. List<int> serAddrBytes
)

Implementation

factory ADAByronAddr.deserialize(List<int> serAddrBytes) {
  final addrBytes = CborObject.fromCbor(serAddrBytes);
  if (addrBytes is! CborListValue || addrBytes.value.length != 2) {
    throw const AddressConverterException("Invalid address encoding");
  }
  if (addrBytes.value[0] is! CborTagValue ||
      addrBytes.value[1] is! CborIntValue) {
    throw const AddressConverterException("Invalid address encoding");
  }
  final decodeCbor = addrBytes.value[0] as CborTagValue;
  if (decodeCbor.tags.isEmpty ||
      decodeCbor.tags.first != ADAByronAddrConst.payloadTag ||
      decodeCbor.value is! CborBytesValue) {
    throw const AddressConverterException("Invalid CBOR tag");
  }

  final crcTag = (addrBytes.value[1] as CborIntValue).value;
  final List<int> payloadBytes = decodeCbor.value.value;
  final crc32Got = Crc32.quickIntDigest(payloadBytes);
  if (crc32Got != crcTag) {
    throw AddressConverterException(
        "Invalid CRC (expected: $crcTag, got: $crc32Got)");
  }

  return ADAByronAddr(payload: ADAByronAddrPayload.deserialize(payloadBytes));
}