Repository navigation
Conversation
Documents destructured its option as `encrypt` and forwarded `encrypt` to Database, while orbitdb.open() passes it as `encryption`. A documents database opened with encryption therefore stored plaintext without error. Adds storage tests for a documents database with data and with replication encryption; both fail without the fix because the plaintext marker is found in the raw entry bytes. Fixes orbitdb#1253 Co-Authored-By: Claude Opus 5.5 <[email protected]>
aphelionz
left a comment
There was a problem hiding this comment.
LGTM, thanks for the fix and the tests. The rename matches what Events, KeyValue and KeyValueIndexed already do.
Non-blocking notes, fine as follow-ups:
- Replication coverage: the new tests check local storage only. #1253 also reports plaintext replication, so a two-peer Documents test (like the Events suite at lines 65-301) and a wrong-key test that expects
Could not decrypt payloadwould cover that path. - Test cleanup:
afterEachdoes not resetdb1. Ifopen()throws,afterEachdrops the previous suite's closed db, and that error replaces the real one. Settingdb1 = undefinedafter close fixes it. The existing storage suite has the same pattern. - Pre-existing doc drift: the
DatabaseJSDoc insrc/database.js(lines 42-43) still documentsoptions.encryptFn/options.decryptFn. The real option isparams.encryptionwith the{ replication, data }shape fromsrc/orbitdb.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, encryption }) |
There was a problem hiding this comment.
Optional, since you're on this line: onUpdate is destructured on line 28 but not passed to Database. Events and KeyValue forward it. Adding onUpdate here would let a wrapper (like KeyValueIndexed does for KeyValue) build an index on top of Documents. This bug is pre-existing and does not block this PR.
|
Thanks for this. One more thing on the same line: Documents receives Also worth a test: a Documents db written in plaintext before this fix, then reopened with |
Fixes #1253
Thanks to @georgemac510 for the report and the diagnosis in #1253.
Bug
Documentsdestructures its option asencryptand forwardsencrypttoDatabase, butorbitdb.open()passes it asencryption(src/orbitdb.js,open()and theDatabase(...)call).Events,KeyValueandKeyValueIndexedalready useencryption. Soorbitdb.open(name, { type: 'documents', encryption })silently ignores the encryption config. Entries and payloads are stored and replicated in plaintext, and no error is raised.Affected:
@orbitdb/core3.0.2 (per #1253), 4.0.0, andmainat 2ee8387.Fix
src/databases/documents.js:encrypt→encryptionin the parameter list and in theDatabase(...)call. That is the only change tosrc/.Test
In
test/orbitdb-encryption.test.jsthere is a new block,Documents database is encrypted in storage. It mirrors the existing storage tests for the default (events) database:payload bytes are encrypted in storage(encryption: { data })entry bytes are encrypted in storage(encryption: { replication })Each test puts a document that contains a unique plaintext marker. It then reads the raw entry bytes with
db.log.storage.get(hash)and asserts that:Uint8Arraythat does not CBOR-decodedb.getWithout the fix (on
mainat 2ee8387), both new tests fail at the first assertion because the marker is found in the stored bytes:test/orbitdb-encryption.test.js: 7 passing, 2 failing.With the fix:
test/orbitdb-encryption.test.js: 9 passing, 0 failingnpm test(Node 22): 546 passing, 0 failingnpm run lint: clean🤖 Generated with Claude Code