Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nostr-tools

Package Overview
Dependencies
Maintainers
1
Versions
153
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nostr-tools - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0

keys.js

26

event.js
import {Buffer} from 'buffer'
import * as secp256k1 from '@noble/secp256k1'
import createHash from 'create-hash'
import {signSchnorr, verifySchnorr} from 'tiny-secp256k1'
import {sha256} from './utils'
export function getBlankEvent() {

@@ -28,17 +27,20 @@ return {

export async function getEventHash(event) {
let eventHash = await sha256(Buffer.from(serializeEvent(event)))
let eventHash = createHash('sha256')
.update(Buffer.from(serializeEvent(event)))
.digest()
return Buffer.from(eventHash).toString('hex')
}
export async function verifySignature(event) {
return await secp256k1.schnorr.verify(
event.sig,
await getEventHash(event),
event.pubkey
export function verifySignature(event) {
if (event.id !== getEventHash(event)) return false
return verifySchnorr(
Buffer.from(event.sig, 'hex'),
Buffer.from(event.id, 'hex'),
Buffer.from(event.pubkey, 'hex')
)
}
export async function signEvent(event, key) {
let eventHash = await getEventHash(event)
return await secp256k1.schnorr.sign(eventHash, key)
export function signEvent(event, key) {
let eventHash = getEventHash(event)
return signSchnorr(Buffer.from(eventHash, 'hex'), Buffer.from(key, 'hex'))
}

@@ -0,1 +1,2 @@

import {generatePrivateKey, getPublicKey} from './keys'
import {relayConnect} from './relay'

@@ -11,3 +12,2 @@ import {relayPool} from './pool'

import {matchFilter, matchFilters} from './filter'
import {makeRandom32, sha256, getPublicKey} from './utils'

@@ -21,4 +21,2 @@ export {

getEventHash,
makeRandom32,
sha256,
getPublicKey,

@@ -25,0 +23,0 @@ getBlankEvent,

import createHmac from 'create-hmac'
import randomBytes from 'randombytes'
import * as bip39 from 'bip39'
import {wordlist} from 'micro-bip39/wordlists/english'
import {
generateMnemonic,
mnemonicToSeedSync,
validateMnemonic
} from 'micro-bip39'
import BIP32Factory from 'bip32'
import * as ecc from 'tiny-secp256k1'
const bip32 = BIP32Factory(ecc)
export function privateKeyFromSeed(seed) {
let hmac = createHmac('sha512', Buffer.from('Nostr seed', 'utf8'))
hmac.update(seed)
return hmac.digest().slice(0, 32).toString('hex')
let root = bip32.fromSeed(seed)
return root.derivePath(`m/44'/1237'/0'/0'`).privateKey.toString('hex')
}
export function seedFromWords(mnemonic) {
return bip39.mnemonicToSeedSync(mnemonic)
return mnemonicToSeedSync(mnemonic, wordlist)
}
export function generateSeedWords() {
return bip39.entropyToMnemonic(randomBytes(16).toString('hex'))
return generateMnemonic(wordlist)
}
export function validateWords(words) {
return validateMnemonic(words, wordlist)
}
{
"name": "nostr-tools",
"version": "0.11.0",
"version": "0.12.0",
"description": "Tools for making a Nostr client.",

@@ -11,8 +11,11 @@ "repository": {

"@noble/secp256k1": "^1.3.0",
"bip39": "^3.0.4",
"bip32": "^3.0.1",
"browserify-cipher": ">=1",
"buffer": ">=5",
"create-hash": "^1.2.0",
"create-hmac": ">=1",
"dns-packet": "^5.2.4",
"micro-bip39": "^0.1.3",
"randombytes": ">=2",
"tiny-secp256k1": "^2.1.2",
"websocket-polyfill": "^0.0.3"

@@ -19,0 +22,0 @@ },

@@ -98,2 +98,4 @@ import {getEventHash, signEvent} from './event'

async publish(event, statusCallback = (status, relayURL) => {}) {
event.id = await getEventHash(event)
if (!event.sig) {

@@ -103,3 +105,2 @@ event.tags = event.tags || []

if (globalPrivateKey) {
event.id = await getEventHash(event)
event.sig = await signEvent(event, globalPrivateKey)

@@ -106,0 +107,0 @@ } else {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc