Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cmdruid/nostr-storage
A shared, encrypted cloud storage using Nostr.
https://github.com/cmdruid/nostr-storage
cloud-storage collaboration end-to-end-encryption nostr
Last synced: about 1 month ago
JSON representation
A shared, encrypted cloud storage using Nostr.
- Host: GitHub
- URL: https://github.com/cmdruid/nostr-storage
- Owner: cmdruid
- License: cc0-1.0
- Created: 2022-10-17T22:51:28.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-11-06T07:08:09.000Z (about 2 years ago)
- Last Synced: 2024-09-22T08:47:37.197Z (3 months ago)
- Topics: cloud-storage, collaboration, end-to-end-encryption, nostr
- Language: JavaScript
- Homepage: https://cmdruid.github.io/nostr-storage/example/
- Size: 42 KB
- Stars: 19
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nostr-storage
A shared, encrypted cloud data store using Nostr.## Installation
This package is designed to work in both the browser and nodejs.```html
```
```js
// Commonjs import.
const NostrStorage = require('@cmdcode/nostr-storage')
// ES6 import.
import NostrStorage from '@cmdcode/nostr-storage'
```## How to Use
To get started, define a `new NostrStore()` object, then provide a relay server and shared secret to `store.connect()`. Once connected, the store behaves like a typical localStorage object.```js
// Declare a new store object.
const store = new NostrStore()// Connect your store to the relay.
await store.connect(
'wss://nostr-relay.wlvs.space',
'secret-string'
)// NostrStore exposes a basic Map / localStorage API.
store
.has('key') => Promise(true || false)
.get('key') => Promise('value')
.keys() => [ 'key1', 'key2' ... ]
.values() => [ 'val1', 'val2' ... ]
.entries() => [ ['key1', 'val1'], ['key2', 'val2'] ... ]// You can use NostrStore in an iterator.
for (let [ key, val ] of store) {
console.log(key, val)
}// These methods will return whether the data operation suceeded.
store
.set('key', 'value') => Promise(true || false)
.delete('key') => Promise(true || false)
.clear() => Promise(true || false)// These methods assist with data fetching under the hood.
store
.refresh() // Fetch the latest copy of data from the relay.
.commit() // Commit the current data store to the relay.
.destroy() // Marks the data store for deletion (using NIP 9).// NostrStore is configurable with some basic options.
const store = new NostrStore({
refreshTimeout: 5000, // Timeout to refresh data before a has/get op.
commitTimeout: 5000, // Timeout on confirming a commit op suceeded.
emitter: { /* You can also configure the emitter here. */ }
})
```## How it Works
Nostr Storage uses replace-able events in order to store a serialized (and encrypted) copy of the data store. The shared secret is hashed multiple times, with each round used to generate the signature keys, encryption keys, and finally a label for filtering the events.It is safe to reveal the encryption key, without revealing the signature key.
This project uses nostr-emitter. To fully understand how it all works, see this link: https://github.com/cmdruid/nostr-emitter
## Resources
**Nostr Emitter**
Used under-the-hood for talking to relays.
https://github.com/cmdruid/nostr-emitter**Nostr Implementation Possibilities**
https://github.com/nostr-protocol/nips**Nostr-tools**
https://github.com/fiatjaf/nostr-tools## Contributions
All contributions are welcome!