Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015-2018 Protocol Labs Inc.
Copyright (c) 2018 Haja Networks Oy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,42 @@ const db = await orbitdb.open(dbAddress, { encryption })

```

## Detecting Encrypted Databases

The `isDatabaseEncrypted()` function helps detect if a database is encrypted when it has been opened **without** any encryption options. It currently detects encryption in two main ways:

- **Data-only encryption**: `db.all()` succeeds, entries exist, but their `value` fields are `undefined` (while `hash` is present).
- **Replication and/or data encryption**: `db.all()` throws a `TypeError` such as `Cannot read properties of undefined (reading 'value')` because OrbitDB cannot decrypt the underlying log entries.

```js
import SimpleEncryption, { isDatabaseEncrypted } from '@orbitdb/simple-encryption'

// Try opening database without encryption
const db = await orbitdb.open(address, {})

// Check if it's encrypted
const isEncrypted = await isDatabaseEncrypted(db)

if (isEncrypted) {
// Application-specific flow: ask user for password / config
const password = await promptForPassword()

// Depending on how the DB was created, you may need:
// - data encryption only
// - replication encryption only
// - or both
const replication = await SimpleEncryption({ password })
const data = await SimpleEncryption({ password })

await db.close()

// Example: open with both replication and data encryption
const encryptedDb = await orbitdb.open(address, {
encryption: { replication, data }
})
}
```

## Contributing

**Take a look at our organization-wide [Contributing Guide](https://github.com/orbitdb/welcome/blob/master/contributing.md).** You'll find most of your questions answered there. Some questions may be answered in the [FAQ](FAQ.md), as well.
Expand Down
Loading