/// import { BossObject, CompletablePromise, ParsecSessionStorage, PConnection } from "uparsecjs"; import { PrivateKey } from "unicrypto"; import { AnnotatedKey } from "./AnnotatedKey"; import { MyoElement } from "./MyoElement"; import { CloudElement, LO } from "./CloudData"; import { CloudObject } from "./CloudObject"; import { AnnotatedKeyring } from "./AnnotatedKeyring"; import { Inbox } from "./Inbox"; import { EmitterEventListener, EmitterHandle } from "uparsecjs/dist/Emitter"; export declare type MyoEventType = "connected" | "disconnected" | "loggedIn" | "loggedOut"; export interface MyoEvent { type: MyoEventType; cloud: MyoCloud; } export declare type RegistrationResult = "OK" | "login_in_use" | "error"; export interface ElementSearchArgs { tag1?: string; tag2?: string; tag3?: string; } export declare class MyoCloud implements PConnection { #private; private store; static Exception: { new (text?: string): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; static NotFound: { new (text?: string): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; static IllegalState: { new (text?: string): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; static NotLoggedIn: { new (): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; static RegistryNotLoaded: { new (): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; static InvalidPassword: { new (text?: string): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; static LoginNotAvailable: { new (text?: string): { name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; private readonly rootConnection; private readonly session; private readonly emitter; private lastEvent?; private readonly lastLogin; private connectedPromise; private loginState?; /** * Create connection to the myonly.cloud service. * * __Important note about `testMode` sessions__. Anu login registered from test mode is subject to eventual * cleanup by the service, we guarantee only few minutes, and it could be deleted by any other process by login * only, not requiring even the password, see [clearTestLogin] for details. So __do not use `testMode` except * for regression tests!__ * * @param store where to store sensitive connection data. It is recommended to keep it in some safe or encrypted * storage. * @param params `testMode` */ constructor(store: ParsecSessionStorage, params: { serviceAddress?: string; testMode?: boolean; }); traceCalls: boolean; call(method: string, params?: BossObject): Promise; callTo(method: string, params: BossObject): Promise; /** * Smart add listener. The listener receives last connection event if any. E.g. if the service is in logged in * state by the time of call, it will immediately receive [[MyoEvent]] with type 'loggedIn', etc. This makes * it safe to call at any moment in future. * * __important__. If some listener will be added several times, it will be called several times. Be sure to remove * unneeded listeners using returned label. Invocation order is not guaranteed. * * @param lr listener to add. * @return listener label used to remove it */ addListener(lr: EmitterEventListener): EmitterHandle; /** * Remove listener by its label. Will do nothing if there is no listener with such label, * @param listenerLabel listener label to remove. */ removeListener(listenerLabel: string): void; get connected(): CompletablePromise; /** * Logged in state could be: true if it is logged in now, false if user is logged out, and undefined if the * state is not yet known. */ get isLoggedIn(): boolean | undefined; get hasSavedLogin(): boolean; get hasLoginKey(): boolean; /** * Create login-key based signed record promising the key is still available. If key is not available, * caller should restore it by providing the password to [[restoreLoginKey]]. After it returns, client * have at least 10 minutes to perform login-requiring operations. * * @param payload to include * @param nonce to use. If not set, uses parsec's standard, TSK as nonce. It is save and fast. * @return packed signed record or undefined if the key is not known at the moment. */ loginSignedRecord(payload: BossObject, nonce?: Uint8Array): Promise; /** * Try to login using specified credentials. Successful login also fires [[MyoEvent]] with `type:loggedIn`. * If the service is in the logged in state, it must be explicitly logged out first. * * @param login to use * @param password to use * @return resolve to success if logged in * @throws IllegalState * @throws InvalidPassword */ login(login: string, password: string): Promise; private get registry(); logout(): Promise; private static newPrivateKey; private lastPrivateKey; /** * Get currently (being) generated new private key of default strength and start generating new one, * so we always have a private key at hand */ nextPrivateKey(): Promise; /** * Create new cloud registration. Note that it does not automatically log in to it. * * @param login * @param password * @param loginKey specify new private key to use with a login, or null to let library to generate new one. * * @return result, namely 'OK', 'login_in_use' or 'error' if some other error has occurred (e.g. network error). * * @throws MyoCloud.IllegalState if it is already logged in (log out first) */ register(login: string, password: string, loginKey?: PrivateKey): Promise; /** * For testing only. Deletes _test login_. Test logins are all logins created from the * sessions opened in _test mode_, see [MyoCloud] constructor `test_mode` parameter. Note that * any login registered from _test_mode session_ could be deleted by anyone, so only use it for testing. * @param login */ clearTestLogin(login: string): Promise; get mainRing(): Promise; /** * Current main storage key that _must be used dor encrypting new data_. As main storage key is subject to * change with time, use [[mainRing]] for decryption, it will create all available keys, also old storage keys. */ get storageKey(): Promise; /** * Get and decrypt login key. Could be used by client software to get the key when it is expired, * in which case _login parameter should be omitted_. * * Please do not specify login other than used by system or it will cause exception. When implementing * login protocol, be sure to drop saved login first. * * @param password to use to decrypt the login key. * @param login for internal use in login procedure. Login to request the key from. * @throws IllegalState if it is not logged in or login is specified but is wrong. Log out or log in. * @throws InvalidPassword */ private restoreLoginKey; elementByUniqueTag(uniqueTag: string): Promise; setByUniqueTag(element: CloudElement): Promise; elementByUniqueTagOrTrow(uniqueTag: string): Promise; /** * Try to create element. If uniqueTag is provided and the element with such a tag already exists, * returns undefined. Otherwise creates new element or throw exception on network/server failure. */ tryCreateElement(element: CloudElement): Promise; updateElement(element: CloudElement): Promise; deleteElements(...elements: CloudElement[]): Promise; elementsByTags(args: ElementSearchArgs & LO): Promise; inboxes(): AsyncGenerator; static simpleScramble(source: string): Promise; scramble(name: string): Promise; objectByUniqueTag(utag: string, creator?: (element: CloudElement) => Promise>): Promise | undefined>; fireEvent(type: MyoEventType): void; private tryRestoreSession; private setLoggedOut; /** * Check connection state. It could be: * - `loggedIn`: parsec session connected, user is logged in in the session * - `loggedOut`: parsec session connected, user is not logged in in the session * - `notConnected`: parsec session is not established or network failure */ checkConnection(): Promise<"loggedIn" | "loggedOut" | "notConnected">; /** * Delete item by the unique tag * @param uniqueTag to delete * @return true if the item was found and deleted and false if the item did not exist */ deleteByUniqueTag(uniqueTag: string): Promise; }