Summary
databases/documents.js destructures encrypt (no -ion suffix) instead of encryption from its options parameter, and forwards encrypt to the underlying Database constructor. Every other store type (Events, KeyValue, KeyValueIndexed) destructures and forwards encryption correctly.
As a result, the encryption option passed to orbitdb.open() for a Documents-store database is silently dropped, writes and reads happen in cleartext with no error or warning, even when both data and replication encryption are configured.
Affected versions
Observed in @orbitdb/core@3.0.2. The lines in question appear unchanged in main.
Location
src/databases/documents.js, the function signature and Database(...) call:
const Documents = ({ indexBy } = DefaultOptions) => async ({ ..., onUpdate, encrypt }) => {
const database = await Database({ ..., syncAutomatically, encrypt })
The encrypt references should be encryption.
Reproducer
Minimal reproducer using @orbitdb/simple-encryption@0.0.2:
import { createHelia } from 'helia'
import { createOrbitDB, Documents } from '@orbitdb/core'
import SimpleEncryption from '@orbitdb/simple-encryption'
const ipfs = await createHelia()
const orbitdb = await createOrbitDB({ ipfs })
const data = await SimpleEncryption({ password: 'correct' })
const db = await orbitdb.open('docs-test', {
Database: Documents({ indexBy: '_id' }),
encryption: { data }
})
await db.put({ _id: 'doc1', secret: 'plaintext-value' })
await db.close()
// Re-open with a different password — should fail to decrypt
const wrongData = await SimpleEncryption({ password: 'wrong' })
const db2 = await orbitdb.open(db.address.toString(), {
Database: Documents({ indexBy: '_id' }),
encryption: { data: wrongData }
})
const all = await db2.all()
console.log(all) // Expected: throws "Could not decrypt payload"
// Actual: returns [{ value: { _id: 'doc1', secret: 'plaintext-value' } }]
Running the equivalent test against the Events store (using db.add / db.get) produces the expected Could not decrypt payload error, confirming the Documents-specific gap.
Suggested fix
Two-character change in databases/documents.js:
-const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, encrypt }) => {
- const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, encrypt })
+const Documents = ({ indexBy } = DefaultOptions) => async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, encryption }) => {
+ const database = await Database({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically, onUpdate, encryption })
I have verified the fix works end-to-end against the reproducer above, patched the local copy, re-ran, the wrong-password case now throws Could not decrypt payload as expected.
I can open a PR if you would like with the fix and a test case for simple-encryption mirroring its existing Events-store tests.
Summary
databases/documents.jsdestructuresencrypt(no-ionsuffix) instead ofencryptionfrom its options parameter, and forwardsencryptto the underlyingDatabaseconstructor. Every other store type (Events, KeyValue, KeyValueIndexed) destructures and forwardsencryptioncorrectly.As a result, the
encryptionoption passed toorbitdb.open()for a Documents-store database is silently dropped, writes and reads happen in cleartext with no error or warning, even when bothdataandreplicationencryption are configured.Affected versions
Observed in
@orbitdb/core@3.0.2. The lines in question appear unchanged in main.Location
src/databases/documents.js, the function signature andDatabase(...)call:The
encryptreferences should beencryption.Reproducer
Minimal reproducer using
@orbitdb/simple-encryption@0.0.2:Running the equivalent test against the Events store (using
db.add/db.get) produces the expectedCould not decrypt payloaderror, confirming the Documents-specific gap.Suggested fix
Two-character change in
databases/documents.js:I have verified the fix works end-to-end against the reproducer above, patched the local copy, re-ran, the wrong-password case now throws
Could not decrypt payloadas expected.I can open a PR if you would like with the fix and a test case for
simple-encryptionmirroring its existing Events-store tests.