DataType Enum

Overview

The DataType enum provides metadata for serialized data, defining comprehensive data type system supporting primitive types, complex objects, and arrays.

Package: keychain.constants

from keychain.constants import DataType

Class Definition

class DataType(IntEnum):
    """Data type meta data for serialized data."""

Primitive Types

BYTES

Value: 0

Binary byte array (binary string).

UTF8_STRING

Value: 1

UTF8 string.

INT32

Value: 2

32-bit signed integer.

INT64

Value: 3

64-bit signed integer.

UINT32

Value: 4

32-bit unsigned integer.

UINT64

Value: 5

64-bit unsigned integer.

BOOLEAN

Value: 6

Boolean value.

SINGLE_FLOAT

Value: 12

Single-precision floating point number.

DOUBLE_FLOAT

Value: 13

Double-precision floating point number.

Complex Types

DID

Value: 7

Decentralized Identifier.

VERIFIABLE_DATA

Value: 8

Verifiable data object.

CREDENTIAL

Value: 9

Credential object.

TRANSACTION

Value: 10

Ledger transaction.

ENCRYPTED_DATA

Value: 11

Encrypted data.

URI

Value: 14

URI (deprecated).

KEY_LOCK

Value: 30

Key lock object.

ATTESTATION

Value: 31

Attestation.

PUBLIC_KEY

Value: 34

Public key.

SERIALIZABLE

Value: 36

Serializable object.

Array Types

ARRAY_BYTES

Value: 15

Array of byte arrays (array of binary strings).

ARRAY_UTF8_STRING

Value: 16

Array of UTF8 strings.

ARRAY_INT32

Value: 17

Array of 32-bit integers.

ARRAY_INT64

Value: 18

Array of 64-bit integers.

ARRAY_UINT32

Value: 19

Array of 32-bit unsigned integers.

ARRAY_UINT64

Value: 20

Array of 64-bit unsigned integers.

ARRAY_BOOLEAN

Value: 21

Array of Booleans.

ARRAY_DID

Value: 22

Array of DIDs.

ARRAY_VERIFIABLE_DATA

Value: 23

Array of verifiable data objects.

ARRAY_CREDENTIAL

Value: 24

Array of credential objects.

ARRAY_TRANSACTION

Value: 25

Array of transaction objects.

ARRAY_ENCRYPTED_DATA

Value: 26

Array of encrypted data objects.

ARRAY_SINGLE_FLOAT

Value: 27

Array of single-precision floating-point numbers.

ARRAY_DOUBLE_FLOAT

Value: 28

Array of double-precision floating-point numbers.

ARRAY_URI

Value: 29

Array of URI objects (deprecated).

ARRAY_KEY_LOCK

Value: 32

Array of key lock objects.

ARRAY_ATTESTATION

Value: 33

Array of attestation objects.

ARRAY_SERIALIZABLE

Value: 35

Array of serializable objects.

ARRAY_PUBLIC_KEY

Value: 37

Array of public key objects.

Usage Example

from keychain.constants import DataType

# Check data types
if data.data_type() == DataType.CREDENTIAL:
    print("This is a credential")
elif data.data_type() == DataType.ARRAY_DID:
    print("This is an array of DIDs")

# Type checking for arrays
def is_array_type(data_type: DataType) -> bool:
    return data_type.name.startswith("ARRAY_")

def get_base_type(data_type: DataType) -> DataType:
    if is_array_type(data_type):
        base_name = data_type.name[6:]  # Remove "ARRAY_" prefix
        return DataType[base_name]
    return data_type

See Also