npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cmdcode/nostr-storage

v1.0.9

Published

A shared, encrypted cloud storage using Nostr.

Downloads

8

Readme

nostr-storage

A shared, encrypted cloud data store using Nostr.

Installation

This package is designed to work in both the browser and nodejs.

<!-- Browser import -->
<script src='https://bundle.run/[email protected]'></script>
<script src="https://unpkg.com/@cmdcode/nostr-emitter"></script>
<script src="https://unpkg.com/@cmdcode/nostr-storage"></script>
// 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.

// 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!