types.ts (2125B)
1 import type { ResolveError } from "@radroots/utils"; 2 import type { CryptoRegistryExport } from "../crypto/types.js"; 3 4 export type BackupBundleVersion = 1; 5 6 export type BackupBundleStoreType = "sql" | "keystore" | "datastore"; 7 8 export type BackupSqlPayload = { 9 bytes_b64: string; 10 }; 11 12 export type BackupKeystoreEntry = { 13 key: string; 14 value: string; 15 }; 16 17 export type BackupKeystorePayload = { 18 entries: BackupKeystoreEntry[]; 19 }; 20 21 export type BackupDatastoreEntry = { 22 key: string; 23 value: string; 24 }; 25 26 export type BackupDatastorePayload = { 27 entries: BackupDatastoreEntry[]; 28 }; 29 30 export type BackupBundlePayload = 31 | { 32 store_id: string; 33 store_type: "sql"; 34 data: BackupSqlPayload; 35 } 36 | { 37 store_id: string; 38 store_type: "keystore"; 39 data: BackupKeystorePayload; 40 } 41 | { 42 store_id: string; 43 store_type: "datastore"; 44 data: BackupDatastorePayload; 45 }; 46 47 export type BackupBundleManifest = { 48 version: BackupBundleVersion; 49 created_at: number; 50 app_version?: string; 51 stores: { store_id: string; store_type: BackupBundleStoreType; }[]; 52 crypto_registry: CryptoRegistryExport; 53 }; 54 55 export type BackupBundle = { 56 manifest: BackupBundleManifest; 57 payloads: BackupBundlePayload[]; 58 }; 59 60 export type BackupBundleEnvelope = { 61 version: number; 62 created_at: number; 63 kdf_salt_b64: string; 64 kdf_iterations: number; 65 iv_b64: string; 66 ciphertext_b64: string; 67 }; 68 69 export interface BackupSqlStore { 70 export_backup(): Promise<ResolveError<BackupSqlPayload>>; 71 import_backup(payload: BackupSqlPayload): Promise<ResolveError<void>>; 72 get_store_id(): string; 73 } 74 75 export interface BackupKeystoreStore { 76 export_backup(): Promise<ResolveError<BackupKeystorePayload>>; 77 import_backup(payload: BackupKeystorePayload): Promise<ResolveError<void>>; 78 get_store_id(): string; 79 } 80 81 export interface BackupDatastoreStore { 82 export_backup(): Promise<ResolveError<BackupDatastorePayload>>; 83 import_backup(payload: BackupDatastorePayload): Promise<ResolveError<void>>; 84 get_store_id(): string; 85 }