common.types

Common types used throughout the SecretVaults library.

This module provides centralized type definitions including Uuid, Did, and ByNodeName for consistent type checking across the codebase.

decode_base58(encoded: str) bytes[source]

Decode base58 string to bytes.

to_hex(data: bytes) str[source]

Convert bytes to hex string.

convert_did_key_to_did_nil(did_key: str) str[source]

Convert did:key to did:nil format.

validate_did_string(v: str) str[source]

Validate and convert DID string.

class Did(value: str)[source]

Bases: str

Decentralized Identifier (DID) for Nillion network.

A branded string type that loosely validates DIDs. Supports did:nil, did:key, and did:ethr formats. Automatically converts did:key to did:nil for backwards compatibility.

static __new__(cls, value: str) Did[source]

Create a new Did instance with validation and conversion.

classmethod __get_pydantic_core_schema__(_source_type: type, _handler: GetCoreSchemaHandler) InvalidSchema | AnySchema | NoneSchema | BoolSchema | IntSchema | FloatSchema | DecimalSchema | StringSchema | BytesSchema | DateSchema | TimeSchema | DatetimeSchema | TimedeltaSchema | LiteralSchema | MissingSentinelSchema | EnumSchema | IsInstanceSchema | IsSubclassSchema | CallableSchema | ListSchema | TupleSchema | SetSchema | FrozenSetSchema | GeneratorSchema | DictSchema | AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema | WithDefaultSchema | NullableSchema | UnionSchema | TaggedUnionSchema | ChainSchema | LaxOrStrictSchema | JsonOrPythonSchema | TypedDictSchema | ModelFieldsSchema | ModelSchema | DataclassArgsSchema | DataclassSchema | ArgumentsSchema | ArgumentsV3Schema | CallSchema | CustomErrorSchema | JsonSchema | UrlSchema | MultiHostUrlSchema | DefinitionsSchema | DefinitionReferenceSchema | UuidSchema | ComplexSchema[source]

Custom Pydantic core schema to handle DID validation and conversion.

class ByNodeName(root: RootModelRootType = PydanticUndefined)[source]

Bases: RootModel[Dict[Did, TypeVar]]

Map type indexed by node DIDs.

Used to store data associated with specific nodes in the network.

__getitem__(key: Did) T[source]
__setitem__(key: Did, value: T) None[source]
__len__() int[source]
keys()[source]

Return the keys of the underlying dictionary.

values()[source]

Return the values of the underlying dictionary.

items()[source]

Return the items of the underlying dictionary.

get(key: Did, default: T = None) T[source]

Get value by key with default fallback.

__contains__(key: Did) bool[source]

Check if key exists in the mapping.