Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

nodejs nostr library

License

NotificationsYou must be signed in to change notification settings

jb55/nostr-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nostr nodejs library

Example

const{RelayPool}=require('nostr')constjb55="32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"constdamus="wss://relay.damus.io"constscsi="wss://nostr-pub.wellorder.net"constrelays=[damus,scsi]constpool=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 ofRelay 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 givespublisherPubkey permission to create eventson theprivkeys behalf subject toconditions

privkey: authorizer private key

publisherKey: delegate/publisher pubkey

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

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

Returns:

{pubkey,publisherPubkey,conditions,token}

Wheretoken is the delegation token, which is a signature from the authorizerof the delegationnostr:delegation:publisher_key:.

async createDelegationEvent(publisherPrivkey, event, delegation)

Create a delegated event from adelegation. This is an event posted on behalfofdelegation.pubkey subject todelegation.conditions.

delegation: a delegation in the form returned bycreateDelegation

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

event: The event to post as a delegate. The eventpubkey will be overriddenby thepublisherPubkey. The delegation tag will be upserted into the taglist.

async signDelegationToken(privkey, unsignedToken)

Sign a delegation string in the formnostr:delegation:....

Returns: a signature string called the delegation token.

About

nodejs nostr library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript100.0%

[8]ページ先頭

©2009-2025 Movatter.jp