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

nostr

v0.2.8

Published

nostr lib and cli

Downloads

2,473

Readme

nostr

nostr nodejs library

Example

const {RelayPool} = require('nostr')

const jb55 = "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
const damus = "wss://relay.damus.io"
const scsi = "wss://nostr-pub.wellorder.net"
const relays = [damus, scsi]

const pool = RelayPool(relays)

pool.on('open', relay => {
	relay.subscribe("subid", {limit: 2, kinds:[1], authors: [jb55]})
});

pool.on('eose', relay => {
	relay.close()
});

pool.on('event', (relay, sub_id, ev) => {
	console.log(ev)
});

API

RelayPool(urls, options)

Connect to a pool of relays. You should use this instead of Relay directly.

options: {reconnect: true|false}, defaults to {reconnect: true}

const relays = [`wss://relay1.com`, `wss://relay2.com`]
const pool = RelayPool(relays, {reconnect: false})

Relay(url, options)

Connect to a relay

options: {reconnect: true|false}, defaults to {reconnect: true}

const relay = Relay(`wss://relay.damus.io`, {reconnect: false})

async calculateId(event)

Calculate an id from an event

async signId(privkey, id)

Create a signature for an id

async verifyEvent(event)

Verify an event

Returns: true if valid signature, false otherwise

decryptDm(privkey, event)

Decrypt a direct message

Returns: decrypted content

encryptDM(privkey, pubkey, msg)

Encrypt a direct message

Returns: encrypted content

getPublicKey(privkey)

Get a public key from a privkey

async createDelegation(privkey, publisherPubkey, conditions)

Create a delegation. This gives publisherPubkey permission to create events on the privkeys behalf subject to conditions

privkey: authorizer private key

publisherKey: delegate/publisher pubkey

conditions: & separated set of event creation permissions that the delegate is required to adhere to when creating events

eg: created_at>1669303873&created_at<1674574279&kind=1,7

Returns:

{pubkey, publisherPubkey, conditions, token}

Where token is the delegation token, which is a signature from the authorizer of the delegation nostr:delegation:publisher_key:.

async createDelegationEvent(publisherPrivkey, event, delegation)

Create a delegated event from a delegation. This is an event posted on behalf of delegation.pubkey subject to delegation.conditions.

delegation: a delegation in the form returned by createDelegation

publisherPrivkey: the private key of the delegate, the entity posting on behalf of delegation.pubkey

event: The event to post as a delegate. The event pubkey will be overridden by the publisherPubkey. The delegation tag will be upserted into the tag list.

async signDelegationToken(privkey, unsignedToken)

Sign a delegation string in the form nostr:delegation:....

Returns: a signature string called the delegation token.