UNPKG

moeralib

Version:

Library to interact with Moera decentralized social network

189 lines 8.05 kB
import { ErrorResult, OperationStatusInfo, RegisteredNameInfo, SigningKeyInfo } from "./types"; /** * Main Moera naming server. */ export declare const MAIN_NAMING_SERVER = "https://naming.moera.org/moera-naming"; /** * Moera developers' naming server. */ export declare const DEV_NAMING_SERVER = "https://naming-dev.moera.org/moera-naming"; /** * Node name used to represent anonymous content author. */ export declare const ANONYMOUS_NODE_NAME = "unk_0"; /** * Public key used to verify signatures of anonymous content. */ export declare const ANONYMOUS_NODE_PUBLIC_KEY: Buffer<ArrayBuffer>; /** * Private key used to sign anonymous content. */ export declare const ANONYMOUS_NODE_PRIVATE_KEY: Buffer<ArrayBuffer>; /** * Generic naming server error. */ export declare class MoeraNamingError extends Error { /** * @param {string} method - API method name * @param {string} message - error message */ constructor(method: string, message: string); } /** * Naming server returned an error response. */ export declare class MoeraNamingApiError extends MoeraNamingError { /** * Error code. */ errorCode: number; /** * @param {string} method - API method name * @param {ErrorResult} result - server response */ constructor(method: string, result: ErrorResult); } /** * Naming server connection error. */ export declare class MoeraNamingConnectionError extends Error { /** * @param {string} message - error message */ constructor(message: string); } /** * Naming API interface. */ export declare class MoeraNaming { private rpcClient; /** * @param {string} server - the naming server URL */ constructor(server?: string); /** * Register or update the name. See Architecture Overview for the `detailed description * {@link https://moera.org/overview/naming.html} of the algorithm. * * @param {string} name - the name to be registered/updated * @param {number} generation - the name generation to be registered/updated * @param {string | null} updatingKey - the public key for verifying signatures of further updates of the name. May * be ``null`` if the current generation of the name is updated – the current key is preserved in this case. * @param {string | null} nodeUri - 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. * @param {string | null} signingKey - the public key of the name owner. May be ``null`` – the current key is * preserved in this case. * @param {number | null} validFrom - the moment in time the owner's key is valid from. May be ``null`` if * ``signingKey`` is also ``null``. * @param {string | null} previousDigest - 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. * @param {string | null} signature - the signature, if required, ``null`` otherwise * @return {Promise<string>} identifier of the operation that was created */ put(name: string, generation: number, updatingKey?: string | null, nodeUri?: string | null, signingKey?: string | null, validFrom?: number | null, previousDigest?: string | null, signature?: string | null): Promise<string>; /** * Get the current status of the operation. * * @param {string} operationId * @return {Promise<OperationStatusInfo |null>} the operation status or ``null``, if the operation ID is unknown */ getStatus(operationId: string): Promise<OperationStatusInfo | null>; /** * Get current information about the given generation of the name. * * @param {string} name * @param {number} generation * @return {Promise<RegisteredNameInfo>} the information or ``null``, if the name/generation is not found */ getCurrent(name: string, generation: number): Promise<RegisteredNameInfo>; /** * Get past information about the given generation of the name. * * @param {string} name * @param {number} generation * @param {number} at - the moment in time the information is related to * @return {Promise<RegisteredNameInfo | null>} the information or ``null``, if the name/generation did not exist at * the given moment */ getPast(name: string, generation: number, at: number): Promise<RegisteredNameInfo | null>; /** * Check if the given name is available for registration. * * @param {string} name * @param {number} generation * @return {Promise<boolean>} ``true``, if the name is free, ``false`` otherwise */ isFree(name: string, generation: number): Promise<boolean>; /** * Find a name that is close to the given name. * * @param {string} name * @return {Promise<RegisteredNameInfo | null>} information about the name or ``null``, if no name found that is * close enough */ getSimilar(name: string): Promise<RegisteredNameInfo | null>; /** * Get the whole history of signing keys for the given name. * * @param {string} name * @param {number} generation * @return {Promise<SigningKeyInfo[]>} the keys */ getAllKeys(name: string, generation: number): Promise<SigningKeyInfo[]>; /** * Get the list of all registered names at the given moment. The list is returned in pages, one per call. * * @param {number} at - the moment in time the information is related to * @param {number} page - number of the page to be returned (starting from 0) * @param {number} size - size of the page * @return {Promise<RegisteredNameInfo[]>} */ getAll(at: number, page: number, size: number): Promise<RegisteredNameInfo[]>; /** * Get the list of all names registered after the given moment. The list is returned in pages, one per call. * * @param {number} at - the moment in time the information is related to * @param {number} page - number of the page to be returned (starting from 0) * @param {number} size - size of the page * @return {Promise<RegisteredNameInfo[]>} */ getAllNewer(at: number, page: number, size: number): Promise<RegisteredNameInfo[]>; } /** * 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. * * @param {string} nodeName - the node name to be parsed * @return {[string, number]} [name, generation] */ export declare function parseNodeName(nodeName: string): [string, number]; /** * Converts the node name to the compact form, omitting generation 0. * * @param {string | null} nodeName - the node name in compact or full form * @return {string | null} the node name in the compact form */ export declare function shorten(nodeName: null): null; export declare function shorten(nodeName: string): string; export declare function shorten(nodeName: string | null): string | null; /** * Converts the node name to the full form, containing generation. * * @param {string | null} nodeName - the node name in compact or full form * @return {string | null} the node name in the full form */ export declare function expand(nodeName: null): null; export declare function expand(nodeName: string): string; export declare function expand(nodeName: string | null): string | null; /** * Shortcut function to resolve a node name and get the node URI. * * @param name {string} - the node name * @param namingServer {string} - a naming server to be used * @return {Promise<string | null>} the node URI, or ``null`` if the name does not exist */ export declare function resolve(name: string, namingServer?: string): Promise<string | null>; //# sourceMappingURL=naming.d.ts.map