///
import type { ContextTimed, ContextTimedInput } from '@matrixai/contexts';
import type { DBTransaction, LevelPath } from '@matrixai/db';
import type { VaultId, VaultName, VaultActions, VaultIdString, VaultIdEncoded } from './types.js';
import type { Vault } from './Vault.js';
import type { FileSystem } from '../types.js';
import type { NodeId } from '../ids/types.js';
import type KeyRing from '../keys/KeyRing.js';
import type NodeManager from '../nodes/NodeManager.js';
import type GestaltGraph from '../gestalts/GestaltGraph.js';
import type NotificationsManager from '../notifications/NotificationsManager.js';
import type ACL from '../acl/ACL.js';
import type { PolykeyWorkerManager } from '../workers/types.js';
import type { RemoteInfo } from './VaultInternal.js';
import type { VaultAction } from './types.js';
import type { AgentClientManifest } from '../nodes/agent/callers/index.js';
import { DB } from '@matrixai/db';
import { EncryptedFS } from 'encryptedfs';
import { createDestroyStartStop } from '@matrixai/async-init';
import { LockBox, RWLockWriter } from '@matrixai/async-locks';
import Logger from '@matrixai/logger';
import VaultInternal from './VaultInternal.js';
/**
* Object map pattern for each vault.
*/
type VaultMap = Map;
type VaultList = Map;
type VaultMetadata = {
dirty: boolean;
vaultName: VaultName;
remoteInfo?: RemoteInfo;
};
interface VaultManager extends createDestroyStartStop.CreateDestroyStartStop {
}
declare class VaultManager {
static createVaultManager({ vaultsPath, db, acl, keyRing, nodeManager, gestaltGraph, notificationsManager, fs, logger, fresh, }: {
vaultsPath: string;
db: DB;
acl: ACL;
keyRing: KeyRing;
nodeManager: NodeManager;
gestaltGraph: GestaltGraph;
notificationsManager: NotificationsManager;
fs?: FileSystem;
logger?: Logger;
fresh?: boolean;
}): Promise;
readonly vaultsPath: string;
readonly efsPath: string;
protected fs: FileSystem;
protected logger: Logger;
protected db: DB;
protected acl: ACL;
protected keyRing: KeyRing;
protected nodeManager: NodeManager;
protected gestaltGraph: GestaltGraph;
protected notificationsManager: NotificationsManager;
protected vaultsDbPath: LevelPath;
protected vaultsNamesDbPath: LevelPath;
protected vaultMap: VaultMap;
protected vaultLocks: LockBox;
protected vaultKey: Buffer;
protected efsDb: DB;
protected efs: EncryptedFS;
protected vaultIdGenerator: () => VaultId;
constructor({ vaultsPath, db, acl, keyRing, nodeManager, gestaltGraph, notificationsManager, fs, logger, }: {
vaultsPath: string;
db: DB;
acl: ACL;
keyRing: KeyRing;
nodeManager: NodeManager;
gestaltGraph: GestaltGraph;
notificationsManager: NotificationsManager;
fs: FileSystem;
logger: Logger;
});
start({ fresh, }?: {
fresh?: boolean;
}): Promise;
stop(): Promise;
destroy(): Promise;
setWorkerManager(workerManager: PolykeyWorkerManager): void;
unsetWorkerManager(): void;
/**
* Constructs a new Vault instance with a given name and stores it in memory.
*/
createVault(vaultName: VaultName, tran?: DBTransaction, ctx?: Partial): Promise;
/**
* Retrieves the vault metadata using the VaultId and parses it to return the
* associated vault name.
*/
getVaultMeta(vaultId: VaultId, tran?: DBTransaction): Promise;
/**
* Removes the metadata and EFS state of a vault using a given VaultId.
*/
destroyVault(vaultId: VaultId, tran?: DBTransaction, ctx?: Partial): Promise;
/**
* Removes a vault from the vault map.
*/
closeVault(vaultId: VaultId, tran?: DBTransaction, ctx?: Partial): Promise;
/**
* Lists the vault name and associated VaultId of all the stored vaults.
*/
listVaults(ctx?: Partial, tran?: DBTransaction): Promise;
/**
* Changes the vault name metadata of a VaultId.
*/
renameVault(vaultId: VaultId, newVaultName: VaultName, tran?: DBTransaction): Promise;
/**
* Retrieves the VaultId associated with a vault name.
*/
getVaultId(vaultName: VaultName, tran?: DBTransaction): Promise;
/**
* Retrieves the vault name associated with a VaultId.
*/
getVaultName(vaultId: VaultId, tran?: DBTransaction): Promise;
/**
* Returns a dictionary of VaultActions for each node
*/
getVaultPermission(vaultId: VaultId, tran?: DBTransaction): Promise>;
/**
* Sets clone, pull and scan permissions of a vault for a gestalt and send a
* notification to this gestalt.
*/
shareVault(vaultId: VaultId, nodeId: NodeId, tran?: DBTransaction): Promise;
/**
* Unsets clone, pull and scan permissions of a vault for a gestalt.
*/
unshareVault(vaultId: VaultId, nodeId: NodeId, tran?: DBTransaction): Promise;
/**
* Clones the contents of a remote vault into a new local
* vault instance
*/
cloneVault(nodeId: NodeId, vaultNameOrId: VaultId | VaultName, tran?: DBTransaction, ctx?: Partial): Promise;
/**
* Pulls the contents of a remote vault into an existing vault instance.
*/
pullVault({ vaultId, pullNodeId, pullVaultNameOrId, }: {
vaultId: VaultId;
pullNodeId?: NodeId;
pullVaultNameOrId?: VaultId | VaultName;
}, tran?: DBTransaction, ctx?: Partial): Promise;
/**
* Handler for receiving http GET requests when being cloned or pulled from.
*/
handleInfoRequest(vaultId: VaultId, tran?: DBTransaction, ctx?: Partial): AsyncGenerator;
/**
* Handler for receiving http POST requests when being cloned or pulled from.
*/
handlePackRequest(vaultId: VaultId, body: Array, tran?: DBTransaction, ctx?: Partial): AsyncGenerator;
/**
* Retrieves all the vaults for a peer's node.
*/
scanVaults(targetNodeId: NodeId, ctx?: Partial): AsyncGenerator<{
vaultName: VaultName;
vaultIdEncoded: VaultIdEncoded;
vaultPermissions: VaultAction[];
}>;
/**
* Returns all the shared vaults for a NodeId.
*/
handleScanVaults(nodeId: NodeId, tran?: DBTransaction, ctx?: Partial): AsyncGenerator<{
vaultId: VaultId;
vaultName: VaultName;
vaultPermissions: VaultAction[];
}>;
protected generateVaultId(): Promise;
protected getVault(vaultId: VaultId, tran: DBTransaction, ctx: ContextTimed): Promise;
/**
* Takes a function and runs it with the listed vaults. Locking is handled
* automatically.
* @param vaultIds List of vault ID for vaults you wish to use
* @param f Function you wish to run with the provided vaults
* @param tran
* @param ctx
*/
withVaults(vaultIds: VaultId[], f: (...args: Vault[]) => Promise, tran?: DBTransaction, ctx?: Partial): Promise;
/**
* Takes a generator and runs it with the listed vaults. Locking is handled
* automatically.
* @param vaultIds List of vault ID for vaults you wish to use
* @param g Generator you wish to run with the provided vaults
* @param tran
* @param ctx
*/
withVaultsG(vaultIds: Array, g: (...args: Array) => AsyncGenerator, tran?: DBTransaction, ctx?: Partial): AsyncGenerator;
protected setupKey(tran: DBTransaction): Promise;
protected existsEFS(): Promise;
}
export default VaultManager;