Skip to content

Commit

Permalink
feat(database): integrate encryption for storage and secure API key i…
Browse files Browse the repository at this point in the history
…n settings schema
  • Loading branch information
Red-Asuka authored and ysfscream committed Nov 25, 2024
1 parent 8aa9fa1 commit f515491
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/web/src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import settingsSchema from './schemas/Settings.schema'

// import modules
import { disableWarnings, RxDBDevModePlugin } from 'rxdb/plugins/dev-mode'
import { wrappedKeyEncryptionCryptoJsStorage } from 'rxdb/plugins/encryption-crypto-js'
import { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election'
import { RxDBUpdatePlugin } from 'rxdb/plugins/update'
import { wrappedValidateAjvStorage } from 'rxdb/plugins/validate-ajv'
Expand All @@ -29,11 +30,17 @@ export function useDatabase(): RxMqttxDatabase {
}

export async function createDatabase(): Promise<Plugin> {
// wrap the normal storage with the encryption plugin
const encryptedDexieStorage = wrappedKeyEncryptionCryptoJsStorage({
storage: getRxStorageDexie(),
})

const db = await createRxDatabase<RxMqttxCollections>({
name: 'mqttx',
storage: wrappedValidateAjvStorage({
storage: getRxStorageDexie(),
storage: encryptedDexieStorage,
}),
password: 'EBJ3cru8fun5gtw*tky',
eventReduce: true,
})

Expand Down
1 change: 1 addition & 0 deletions apps/web/src/database/schemas/Settings.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const settingsSchema: RxJsonSchema<RxSettingsDocumentType> = {
},
},
required: ['id'],
encrypted: ['openAIAPIKey'],
}

export default settingsSchema

0 comments on commit f515491

Please sign in to comment.