import { AbortActionArgs, AbortActionResult, Beef, InternalizeActionArgs, ListActionsResult, ListCertificatesResult, ListOutputsResult, RelinquishCertificateArgs, RelinquishOutputArgs, Validation } from '@bsv/sdk'; import * as sdk from '../sdk'; import { TableCertificate, TableCertificateX, TableOutput, TableOutputBasket, TableProvenTx, TableProvenTxReq, TableSettings, TableUser } from '../storage/schema/tables'; import { StorageProvider } from './StorageProvider'; declare class ManagedStorage { storage: sdk.WalletStorageProvider; isAvailable: boolean; isStorageProvider: boolean; settings?: TableSettings; user?: TableUser; constructor(storage: sdk.WalletStorageProvider); } /** * The `WalletStorageManager` class delivers authentication checking storage access to the wallet. * * If manages multiple `StorageBase` derived storage services: one actice, the rest as backups. * * Of the storage services, one is 'active' at any one time. * On startup, and whenever triggered by the wallet, `WalletStorageManager` runs a syncrhonization sequence: * * 1. While synchronizing, all other access to storage is blocked waiting. * 2. The active service is confirmed, potentially triggering a resolution process if there is disagreement. * 3. Changes are pushed from the active storage service to each inactive, backup service. * * Some storage services do not support multiple writers. `WalletStorageManager` manages wait-blocking write requests * for these services. */ export declare class WalletStorageManager implements sdk.WalletStorage { /** * All configured stores including current active, backups, and conflicting actives. */ _stores: ManagedStorage[]; /** * True if makeAvailable has been run and access to managed stores (active) is allowed */ _isAvailable: boolean; /** * The current active store which is only enabled if the store's user record activeStorage property matches its settings record storageIdentityKey property */ _active?: ManagedStorage; /** * Stores to which state is pushed by updateBackups. */ _backups?: ManagedStorage[]; /** * Stores whose user record activeStorage property disagrees with the active store's user record activeStorage property. */ _conflictingActives?: ManagedStorage[]; /** * identityKey is always valid, userId and isActive are valid only if _isAvailable */ _authId: sdk.AuthId; /** * Configured services if any. If valid, shared with stores (which may ignore it). */ _services?: sdk.WalletServices; /** * Creates a new WalletStorageManager with the given identityKey and optional active and backup storage providers. * * @param identityKey The identity key of the user for whom this wallet is being managed. * @param active An optional active storage provider. If not provided, no active storage will be set. * @param backups An optional array of backup storage providers. If not provided, no backups will be set. */ constructor(identityKey: string, active?: sdk.WalletStorageProvider, backups?: sdk.WalletStorageProvider[]); isStorageProvider(): boolean; isAvailable(): boolean; /** * The active storage is "enabled" only if its `storageIdentityKey` matches the user's currently selected `activeStorage`, * and only if there are no stores with conflicting `activeStorage` selections. * * A wallet may be created without including the user's currently selected active storage. This allows readonly access to their wallet data. * * In addition, if there are conflicting `activeStorage` selections among backup storage providers then the active remains disabled. */ get isActiveEnabled(): boolean; /** * @returns true if at least one WalletStorageProvider has been added. */ canMakeAvailable(): boolean; /** * This async function must be called after construction and before * any other async function can proceed. * * Runs through `_stores` validating all properties and partitioning across `_active`, `_backups`, `_conflictingActives`. * * @throws WERR_INVALID_PARAMETER if canMakeAvailable returns false. * * @returns {TableSettings} from the active storage. */ private ensureStoreAvailable; private selectActiveFromStore; makeAvailable(): Promise; private verifyActive; getAuth(mustBeActive?: boolean): Promise; getUserId(): Promise; getActive(): sdk.WalletStorageProvider; getActiveSettings(): TableSettings; getActiveUser(): TableUser; getActiveStore(): string; getActiveStoreName(): string; getBackupStores(): string[]; getConflictingStores(): string[]; getAllStores(): string[]; private readonly readerLocks; private readonly writerLocks; private readonly syncLocks; private readonly spLocks; private getActiveLock; private releaseActiveLock; private getActiveForReader; private releaseActiveForReader; private getActiveForWriter; private releaseActiveForWriter; private getActiveForSync; private releaseActiveForSync; private getActiveForStorageProvider; private releaseActiveForStorageProvider; runAsWriter(writer: (active: sdk.WalletStorageWriter) => Promise): Promise; runAsReader(reader: (active: sdk.WalletStorageReader) => Promise): Promise; /** * * @param sync the function to run with sync access lock * @param activeSync from chained sync functions, active storage already held under sync access lock. * @returns */ runAsSync(sync: (active: sdk.WalletStorageSync) => Promise, activeSync?: sdk.WalletStorageSync): Promise; runAsStorageProvider(sync: (active: StorageProvider) => Promise): Promise; /** * * @returns true if the active `WalletStorageProvider` also implements `StorageProvider` */ isActiveStorageProvider(): boolean; addWalletStorageProvider(provider: sdk.WalletStorageProvider): Promise; setServices(v: sdk.WalletServices): void; getServices(): sdk.WalletServices; getSettings(): TableSettings; migrate(storageName: string, storageIdentityKey: string): Promise; destroy(): Promise; findOrInsertUser(identityKey: string): Promise<{ user: TableUser; isNew: boolean; }>; abortAction(args: AbortActionArgs): Promise; createAction(vargs: Validation.ValidCreateActionArgs): Promise; internalizeAction(args: InternalizeActionArgs): Promise; relinquishCertificate(args: RelinquishCertificateArgs): Promise; relinquishOutput(args: RelinquishOutputArgs): Promise; processAction(args: sdk.StorageProcessActionArgs): Promise; insertCertificate(certificate: TableCertificate): Promise; listActions(vargs: Validation.ValidListActionsArgs): Promise; listCertificates(args: Validation.ValidListCertificatesArgs): Promise; listOutputs(vargs: Validation.ValidListOutputsArgs): Promise; findCertificates(args: sdk.FindCertificatesArgs): Promise; findOutputBaskets(args: sdk.FindOutputBasketsArgs): Promise; findOutputs(args: sdk.FindOutputsArgs): Promise; findProvenTxReqs(args: sdk.FindProvenTxReqsArgs): Promise; /** * For each proven_txs record currently sourcing its transaction merkle proof from the given deactivated header, * attempt to reprove the transaction against the current chain, * updating the proven_txs record if a new valid proof is found. * * @param deactivatedHash An orphaned header than may have served as a proof source for proven_txs records. * @returns */ reproveHeader(deactivatedHash: string): Promise; /** * For all proven_txs records at the given height currently tied to the given stale merkleRoot, * attempt to reprove them against the current chain and update proof data if new valid proofs are found. * * This is intended for backup auditing of recent heights after the primary reorg event path has run. */ reproveHeightMerkleRoot(height: number, staleMerkleRoot: string): Promise; /** * Attempt to reprove the transaction against the current chain, * If a new valid proof is found and noUpdate is not true, * update the proven_txs record with new block and merkle proof data. * If noUpdate is true, the update to be applied is available in the returned result. * * @param ptx proven_txs record to reprove * @param noUpdate * @returns */ private evaluateNewMerkleLeaf; reproveProven(ptx: TableProvenTx, noUpdate?: boolean): Promise; syncFromReader(identityKey: string, reader: sdk.WalletStorageSyncReader, activeSync?: sdk.WalletStorageSync, log?: string): Promise<{ inserts: number; updates: number; log: string; }>; syncToWriter(auth: sdk.AuthId, writer: sdk.WalletStorageProvider, activeSync?: sdk.WalletStorageSync, log?: string, progLog?: (s: string) => string): Promise<{ inserts: number; updates: number; log: string; }>; updateBackups(activeSync?: sdk.WalletStorageSync, progLog?: (s: string) => string): Promise; /** * Updates backups and switches to new active storage provider from among current backup providers. * * Also resolves conflicting actives. * * @param storageIdentityKey of current backup storage provider that is to become the new active provider. */ setActive(storageIdentityKey: string, progLog?: (s: string) => string): Promise; getStoreEndpointURL(store: ManagedStorage): string | undefined; getStores(): sdk.WalletStorageInfo[]; } export interface VerifyAndRepairBeefResult { isStructurallyValid: boolean; originalRoots: Record; invalidRoots: Record; verifiedBeef?: Beef; } export {}; //# sourceMappingURL=WalletStorageManager.d.ts.map