Logo Decentralized Social Network

moeralib/naming

Constants

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

Main Moera naming server.

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

Moera developers' naming server.

Functions

parseNodeName(nodeName)

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, Error is thrown.

Parameters:
nodeNamestring – the node name to be parsed
Return value:
[string, number] – array [name, generation]

shorten(nodeName)

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

Parameters:
nodeNamestring | null – the node name in compact or full form
Return value:
string | null – the node name in the compact form

expand(nodeName)

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

Parameters:
nodeNamestring | null – the node name in compact or full form
Return value:
string | null – the node name in the full form

resolve(name, namingServer=MAIN_NAMING_SERVER)

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

Parameters:
namestring – the node name
namingServerstring(optional) a naming server to be used
Return value:
Promise<string | null> – the node URI, or null if the name does not exist

validateNamingSchema(schemaName, data)

Validates a data structure against the given JSON schema. In the process of validation, additional fields in the input that are absent in the schema are deleted.

Parameters:
schemaNamestring – the schema name (same as the validated structure name)
dataany – the data structure being validated
Return value:
{ valid: boolean; errors?: { message?: string }[] | null } – result of the validation and error messages

MoeraNamingError

Generic naming server error.

MoeraNamingError(name, message)

Parameters:
namestring – API method name
messagestring – error message

MoeraNamingApiError

Naming server connection error.

errorCode

string – Error code.

MoeraNamingApiError(name, result)

Parameters:
messagestring – error message
resultErrorResult – server response

MoeraNamingConnectionError

Naming server connection error.

MoeraNamingConnectionError(name)

Parameters:
messagestring – error message

MoeraNaming

Naming API interface.

MoeraNaming(server=MAIN_NAMING_SERVER)

Parameters:
serverstring(optional) the naming server URL

put(name, generation, updatingKey, nodeUri, signingKey, validFrom, previousDigest, signature)

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

Parameters:
name: string – the name to be registered/updated. Required.
generation: number – the name generation to be registered/updated. Required.
updatingKey: string – the public key for verifying signatures of further updates of the name. May be null – the current key is preserved in this case.
nodeUri: string – URI of the REST API endpoint of the node to which the name is assigned. May be null – the current URI is preserved in this case.
signingKey: string – the public key of the name owner. May be null – the current key is preserved in this case.
validFrom: number – the moment in time the owner's key is valid from. May be null, if signingKey is also null.
previousDigest: string – 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 null, if the name was never registered before.
signature: string – the signature, if required, null otherwise.
Return value:
Promise<string> – identifier of the operation that was created

getStatus(operationId)

Get current status of the operation.

Parameters:
operationId: string
Return value:
Promise<OperationStatusInfo> – the operation status or null, if the operation ID is unknown

getCurrent(name, generation)

Get current information about the given generation of the name.

Parameters:
name: string
generation: number
Return value:
Promise<RegisteredNameInfo> – the information or null, if the name/generation is not found

getPast(name, generation, at)

Get past information about the given generation of the name.

Parameters:
name: string
generation: number
at: number – the moment in time the information is related to
Return value:
Promise<RegisteredNameInfo> – the information or null, if the name/generation did not exist at the given moment

isFree(name, generation)

Check if the given name is available for registration.

Parameters:
name: string
generation: number
Return value:
Promise<boolean>true, if the name is free, false otherwise

getSimilar(name)

Find a name that is close to the given name.

Parameters:
name: string
Return value:
Promise<RegisteredNameInfo> – information about the name or null, if no name found that is close enough

getAllKeys(name, generation)

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

Parameters:
name: string
generation: number
Return value:
Promise<SigningKeyInfo[]>

getAll(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: number – the moment in time the information is related to
page: number – number of the page to be returned (starting from 0)
size: number – size of the page
Return value:
Promise<RegisteredNameInfo[]>

getAllNewer(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: number – the moment in time the information is related to
page: number – number of the page to be returned (starting from 0)
size: number – size of the page
Return value:
Promise<RegisteredNameInfo[]>


Structures

OperationStatusInfo

Field Name Type Description
operationId string
name string the name that was created or updated by the operation
generation number the generation of the name that was created or updated by the operation
status OperationStatus the current status of the operation
added number when the operation was added
completed number when the operation was completed
errorCode string the error code, if the operation have been failed
errorMessage string the human-readable error description, if the operation have been failed

RegisteredNameInfo

Field Name Type Description
name string
generation number
updatingKey string the public key for verifying signatures of further updates of the name
nodeUri string URI of the REST API endpoint of the node to which the name is assigned. May be absent.
created number when the name was created
signingKey string the public key of the name owner. May be null.
validFrom number the moment in time the owner's key is valid from. May be absent, if signingKey is also absent.
digest string 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.

SigningKeyInfo

Field Name Type Description
key string the public key
validFrom number 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