Logo Decentralized Social Network

moeralib.naming

Constants

MAIN_SERVER = "https://naming.moera.org/moera-naming"

Main Moera naming server.

DEV_SERVER = "https://naming-dev.moera.org/moera-naming"

Moera developers' naming server.

Functions

node_name_parse(node_name)

Parse a node name and return its name and generation parts. If the node name does not include a generation, generation 0 is returned. If name syntax is invalid, ValueError is raised.

Parameters:
node_namestr – the node name to be parsed
Return value:
Tuple[str, int] – tuple (name, generation)

shorten(node_name)

Converts the node name to the compact form, omitting generation 0.

Parameters:
node_namestr | None – the node name in compact or full form
Return value:
str | None – the node name in the compact form

expand(node_name)

Converts the node name to the full form, containing generation.

Parameters:
node_namestr | None – the node name in compact or full form
Return value:
str | None – the node name in the full form

resolve(name, naming_server=MAIN_SERVER)

Shortcut function to resolve a node name and get the node URI.

Parameters:
namestr – the node name
naming_serverstr(optional) a naming server to be used
Return value:
str | None – the node URI, or None if the name does not exist

MoeraNamingError

Generic naming server error.

MoeraNamingError(name, message)

Parameters:
namestr – API method name
messagestr – error message

MoeraNamingConnectionError

Naming server connection error.

MoeraNamingConnectionError(name, result)

Parameters:
messagestr – error message

MoeraNaming

Naming API interface.

MoeraNaming(server=MAIN_SERVER)

Parameters:
serverstr(optional) the naming server URL

call(method, params, schema=None)

Generic naming API call.

Parameters:
methodstr – name of the method to be called
paramsSequence[Any] – parameters of the call
schemaAny(optional) JSON schema to validate the return value
Return value:
Any – the return value, if any

put(name, generation, updating_key, node_uri, signing_key, valid_from, previous_digest, signature)

Register or update the name. See Architecture Overview for the detailed description of the algorithm.

Parameters:
name: str – the name to be registered/updated. Required.
generation: int – the name generation to be registered/updated. Required.
updating_key: bytes – the public key for verifying signatures of further updates of the name. May be None – the current key is preserved in this case.
node_uri: str – URI of the REST API endpoint of the node to which the name is assigned. May be None – the current URI is preserved in this case.
signing_key: bytes – the public key of the name owner. May be None – the current key is preserved in this case.
valid_from: Timestamp – the moment in time the owner's key is valid from. May be None, if signing_key is also None.
previous_digest: bytes – the unique identifier as reported by a naming server of the current state of the name. Used to detect the situations when the name was changed by someone else between sending the request and processing it. May be None, if the name was never registered before.
signature: bytes – the signature, if required, None otherwise.
Return value:
str – identifier of the operation that was created

get_status(operation_id)

Get current status of the operation.

Parameters:
operation_id: str
Return value:
types.OperationStatusInfo – the operation status or None, if the operation ID is unknown

get_current(name, generation)

Get current information about the given generation of the name.

Parameters:
name: str
generation: int
Return value:
types.RegisteredNameInfo – the information or None, if the name/generation is not found

get_past(name, generation, at)

Get past information about the given generation of the name.

Parameters:
name: str
generation: int
at: Timestamp – the moment in time the information is related to
Return value:
types.RegisteredNameInfo – the information or None, if the name/generation did not exist at the given moment

is_free(name, generation)

Check if the given name is available for registration.

Parameters:
name: str
generation: int
Return value:
boolTrue, if the name is free, False otherwise

get_similar(name)

Find a name that is close to the given name.

Parameters:
name: str
Return value:
types.RegisteredNameInfo – information about the name or None, if no name found that is close enough

get_all_keys(name, generation)

Get the whole history of signing keys for the given name.

Parameters:
name: str
generation: int
Return value:
List[types.SigningKeyInfo]

get_all(at, page, size)

Get the list of all registered names at the given moment. The list is returned in pages, one per call.

Parameters:
at: Timestamp – the moment in time the information is related to
page: int – number of the page to be returned (starting from 0)
size: int – size of the page
Return value:
List[types.RegisteredNameInfo]

get_all_newer(at, page, size)

Get the list of all names registered after the given moment. The list is returned in pages, one per call.

Parameters:
at: Timestamp – the moment in time the information is related to
page: int – number of the page to be returned (starting from 0)
size: int – size of the page
Return value:
List[types.RegisteredNameInfo]


Structures

types.OperationStatusInfo

Field Name Type Description
operation_id str
name str the name that was created or updated by the operation
generation int the generation of the name that was created or updated by the operation
status types.OperationStatus the current status of the operation
added Timestamp when the operation was added
completed Timestamp when the operation was completed
error_code str the error code, if the operation have been failed
error_message str the human-readable error description, if the operation have been failed

types.RegisteredNameInfo

Field Name Type Description
name str
generation int
updating_key bytes the public key for verifying signatures of further updates of the name
node_uri str URI of the REST API endpoint of the node to which the name is assigned. May be absent.
created Timestamp when the name was created
signing_key bytes the public key of the name owner. May be None.
valid_from Timestamp the moment in time the owner's key is valid from. May be absent, if signing_key is also absent.
digest bytes a unique identifier of the current state of the name. May be transaction ID of the latest transaction with this name in the blockchain, or a cryptographic digest of the current state.

types.SigningKeyInfo

Field Name Type Description
key bytes the public key
valid_from Timestamp the moment in time the key is valid from


Enums

Enums are string literals. Every particular enum type is a set of allowed values you can choose from.

OperationStatus

This enum is used to designate the operation status both by the naming server and by the node.

Value Description
"WAITING" operation is waiting to be sent to the naming server
"ADDED" operation was accepted by the naming server
"STARTED" the naming server started to proceed the operation
"SUCCEEDED" operation completed successfully
"FAILED" operation failed
"UNKNOWN" operation status is unknown