validateCborTypeObject static method

void validateCborTypeObject(
  1. CborObject cbor,
  2. NativeScriptType type
)

Validates the CBOR object for the specified native script type.

Implementation

static void validateCborTypeObject(CborObject cbor, NativeScriptType type) {
  // Check if the CBOR object is an integer value
  if (cbor is! CborIntValue) {
    throw MessageException("Invalid CBOR type for native script type.",
        details: {"Type": cbor.runtimeType});
  }

  // Deserialize the CBOR object to a native script type
  final cborType = NativeScriptType.deserialize(cbor);

  // Check if the deserialized type matches the expected type
  if (cborType != type) {
    throw MessageException("Invalid Native Script type.",
        details: {"Expected": type, "Actual": cborType});
  }
}