mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-02-01 06:48:51 +00:00
Compare commits
5 Commits
b40f59af74
...
v2.22.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b624ad4059 | ||
|
|
b3d314643a | ||
|
|
30ac8a02c2 | ||
|
|
42c9c7554d | ||
|
|
3588d30044 |
43
README.md
43
README.md
@@ -1,4 +1,4 @@
|
|||||||
#  [](https://jsr.io/@nostr/tools) nostr-tools
|
# [](https://jsr.io/@nostr/tools) @nostr/tools
|
||||||
|
|
||||||
Tools for developing [Nostr](https://github.com/fiatjaf/nostr) clients.
|
Tools for developing [Nostr](https://github.com/fiatjaf/nostr) clients.
|
||||||
|
|
||||||
@@ -9,9 +9,6 @@ This package is only providing lower-level functionality. If you want higher-lev
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# npm
|
|
||||||
npm install --save nostr-tools
|
|
||||||
|
|
||||||
# jsr
|
# jsr
|
||||||
npx jsr add @nostr/tools
|
npx jsr add @nostr/tools
|
||||||
```
|
```
|
||||||
@@ -27,7 +24,7 @@ https://jsr.io/@nostr/tools/doc
|
|||||||
### Generating a private key and a public key
|
### Generating a private key and a public key
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure'
|
import { generateSecretKey, getPublicKey } from '@nostr/tools/pure'
|
||||||
|
|
||||||
let sk = generateSecretKey() // `sk` is a Uint8Array
|
let sk = generateSecretKey() // `sk` is a Uint8Array
|
||||||
let pk = getPublicKey(sk) // `pk` is a hex string
|
let pk = getPublicKey(sk) // `pk` is a hex string
|
||||||
@@ -36,7 +33,7 @@ let pk = getPublicKey(sk) // `pk` is a hex string
|
|||||||
To get the secret key in hex format, use
|
To get the secret key in hex format, use
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { bytesToHex, hexToBytes } from '@noble/hashes/utils' // already an installed dependency
|
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js' // already an installed dependency
|
||||||
|
|
||||||
let skHex = bytesToHex(sk)
|
let skHex = bytesToHex(sk)
|
||||||
let backToBytes = hexToBytes(skHex)
|
let backToBytes = hexToBytes(skHex)
|
||||||
@@ -45,7 +42,7 @@ let backToBytes = hexToBytes(skHex)
|
|||||||
### Creating, signing and verifying events
|
### Creating, signing and verifying events
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { finalizeEvent, verifyEvent } from 'nostr-tools/pure'
|
import { finalizeEvent, verifyEvent } from '@nostr/tools/pure'
|
||||||
|
|
||||||
let event = finalizeEvent({
|
let event = finalizeEvent({
|
||||||
kind: 1,
|
kind: 1,
|
||||||
@@ -62,8 +59,8 @@ let isGood = verifyEvent(event)
|
|||||||
Doesn't matter what you do, you always should be using a `SimplePool`:
|
Doesn't matter what you do, you always should be using a `SimplePool`:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools/pure'
|
import { finalizeEvent, generateSecretKey, getPublicKey } from '@nostr/tools/pure'
|
||||||
import { SimplePool } from 'nostr-tools/pool'
|
import { SimplePool } from '@nostr/tools/pool'
|
||||||
|
|
||||||
const pool = new SimplePool()
|
const pool = new SimplePool()
|
||||||
|
|
||||||
@@ -126,8 +123,8 @@ relay.close()
|
|||||||
To use this on Node.js you first must install `ws` and call something like this:
|
To use this on Node.js you first must install `ws` and call something like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useWebSocketImplementation } from 'nostr-tools/pool'
|
import { useWebSocketImplementation } from '@nostr/tools/pool'
|
||||||
// or import { useWebSocketImplementation } from 'nostr-tools/relay' if you're using the Relay directly
|
// or import { useWebSocketImplementation } from '@nostr/tools/relay' if you're using the Relay directly
|
||||||
|
|
||||||
import WebSocket from 'ws'
|
import WebSocket from 'ws'
|
||||||
useWebSocketImplementation(WebSocket)
|
useWebSocketImplementation(WebSocket)
|
||||||
@@ -138,7 +135,7 @@ useWebSocketImplementation(WebSocket)
|
|||||||
You can enable regular pings of connected relays with the `enablePing` option. This will set up a heartbeat that closes the websocket if it doesn't receive a response in time. Some platforms, like Node.js, don't report websocket disconnections due to network issues, and enabling this can increase the reliability of the `onclose` event.
|
You can enable regular pings of connected relays with the `enablePing` option. This will set up a heartbeat that closes the websocket if it doesn't receive a response in time. Some platforms, like Node.js, don't report websocket disconnections due to network issues, and enabling this can increase the reliability of the `onclose` event.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { SimplePool } from 'nostr-tools/pool'
|
import { SimplePool } from '@nostr/tools/pool'
|
||||||
|
|
||||||
const pool = new SimplePool({ enablePing: true })
|
const pool = new SimplePool({ enablePing: true })
|
||||||
```
|
```
|
||||||
@@ -148,7 +145,7 @@ const pool = new SimplePool({ enablePing: true })
|
|||||||
You can also enable automatic reconnection with the `enableReconnect` option. This will make the pool try to reconnect to relays with an exponential backoff delay if the connection is lost unexpectedly.
|
You can also enable automatic reconnection with the `enableReconnect` option. This will make the pool try to reconnect to relays with an exponential backoff delay if the connection is lost unexpectedly.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { SimplePool } from 'nostr-tools/pool'
|
import { SimplePool } from '@nostr/tools/pool'
|
||||||
|
|
||||||
const pool = new SimplePool({ enableReconnect: true })
|
const pool = new SimplePool({ enableReconnect: true })
|
||||||
```
|
```
|
||||||
@@ -331,7 +328,7 @@ for (let profile of refs.profiles) {
|
|||||||
### Querying profile data from a NIP-05 address
|
### Querying profile data from a NIP-05 address
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { queryProfile } from 'nostr-tools/nip05'
|
import { queryProfile } from '@nostr/tools/nip05'
|
||||||
|
|
||||||
let profile = await queryProfile('jb55.com')
|
let profile = await queryProfile('jb55.com')
|
||||||
console.log(profile.pubkey)
|
console.log(profile.pubkey)
|
||||||
@@ -343,13 +340,13 @@ console.log(profile.relays)
|
|||||||
To use this on Node.js < v18, you first must install `node-fetch@2` and call something like this:
|
To use this on Node.js < v18, you first must install `node-fetch@2` and call something like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useFetchImplementation } from 'nostr-tools/nip05'
|
import { useFetchImplementation } from '@nostr/tools/nip05'
|
||||||
useFetchImplementation(require('node-fetch'))
|
useFetchImplementation(require('node-fetch'))
|
||||||
```
|
```
|
||||||
|
|
||||||
### Including NIP-07 types
|
### Including NIP-07 types
|
||||||
```js
|
```js
|
||||||
import type { WindowNostr } from 'nostr-tools/nip07'
|
import type { WindowNostr } from '@nostr/tools/nip07'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -361,8 +358,8 @@ declare global {
|
|||||||
### Encoding and decoding NIP-19 codes
|
### Encoding and decoding NIP-19 codes
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure'
|
import { generateSecretKey, getPublicKey } from '@nostr/tools/pure'
|
||||||
import * as nip19 from 'nostr-tools/nip19'
|
import * as nip19 from '@nostr/tools/nip19'
|
||||||
|
|
||||||
let sk = generateSecretKey()
|
let sk = generateSecretKey()
|
||||||
let nsec = nip19.nsecEncode(sk)
|
let nsec = nip19.nsecEncode(sk)
|
||||||
@@ -390,7 +387,7 @@ assert(data.relays.length === 2)
|
|||||||
[`nostr-wasm`](https://github.com/fiatjaf/nostr-wasm) is a thin wrapper over [libsecp256k1](https://github.com/bitcoin-core/secp256k1) compiled to WASM just for hashing, signing and verifying Nostr events.
|
[`nostr-wasm`](https://github.com/fiatjaf/nostr-wasm) is a thin wrapper over [libsecp256k1](https://github.com/bitcoin-core/secp256k1) compiled to WASM just for hashing, signing and verifying Nostr events.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { setNostrWasm, generateSecretKey, finalizeEvent, verifyEvent } from 'nostr-tools/wasm'
|
import { setNostrWasm, generateSecretKey, finalizeEvent, verifyEvent } from '@nostr/tools/wasm'
|
||||||
import { initNostrWasm } from 'nostr-wasm'
|
import { initNostrWasm } from 'nostr-wasm'
|
||||||
|
|
||||||
// make sure this promise resolves before your app starts calling finalizeEvent or verifyEvent
|
// make sure this promise resolves before your app starts calling finalizeEvent or verifyEvent
|
||||||
@@ -403,9 +400,9 @@ initNostrWasm().then(setNostrWasm)
|
|||||||
If you're going to use `Relay` and `SimplePool` you must also import `nostr-tools/abstract-relay` and/or `nostr-tools/abstract-pool` instead of the defaults and then instantiate them by passing the `verifyEvent`:
|
If you're going to use `Relay` and `SimplePool` you must also import `nostr-tools/abstract-relay` and/or `nostr-tools/abstract-pool` instead of the defaults and then instantiate them by passing the `verifyEvent`:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { setNostrWasm, verifyEvent } from 'nostr-tools/wasm'
|
import { setNostrWasm, verifyEvent } from '@nostr/tools/wasm'
|
||||||
import { AbstractRelay } from 'nostr-tools/abstract-relay'
|
import { AbstractRelay } from '@nostr/tools/abstract-relay'
|
||||||
import { AbstractSimplePool } from 'nostr-tools/abstract-pool'
|
import { AbstractSimplePool } from '@nostr/tools/abstract-pool'
|
||||||
import { initNostrWasm } from 'nostr-wasm'
|
import { initNostrWasm } from 'nostr-wasm'
|
||||||
|
|
||||||
initNostrWasm().then(setNostrWasm)
|
initNostrWasm().then(setNostrWasm)
|
||||||
@@ -442,7 +439,7 @@ summary for relay read message and verify event
|
|||||||
|
|
||||||
## Plumbing
|
## Plumbing
|
||||||
|
|
||||||
To develop `nostr-tools`, install [`just`](https://just.systems/) and run `just -l` to see commands available.
|
To develop `@nostr/tools`, install [`just`](https://just.systems/) and run `just -l` to see commands available.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { normalizeURL } from './utils.ts'
|
|||||||
import type { Event, EventTemplate, Nostr, VerifiedEvent } from './core.ts'
|
import type { Event, EventTemplate, Nostr, VerifiedEvent } from './core.ts'
|
||||||
import { type Filter } from './filter.ts'
|
import { type Filter } from './filter.ts'
|
||||||
import { alwaysTrue } from './helpers.ts'
|
import { alwaysTrue } from './helpers.ts'
|
||||||
|
import { Relay } from './relay.ts'
|
||||||
|
|
||||||
export type SubCloser = { close: (reason?: string) => void }
|
export type SubCloser = { close: (reason?: string) => void }
|
||||||
|
|
||||||
@@ -19,6 +20,11 @@ export type AbstractPoolConstructorOptions = AbstractRelayConstructorOptions & {
|
|||||||
// in case that relay shouldn't be authenticated against
|
// in case that relay shouldn't be authenticated against
|
||||||
// or a function to sign the AUTH event template otherwise (that function may still throw in case of failure)
|
// or a function to sign the AUTH event template otherwise (that function may still throw in case of failure)
|
||||||
automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
|
automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
|
||||||
|
// onRelayConnectionFailure is called with the URL of a relay that failed the initial connection
|
||||||
|
onRelayConnectionFailure?: (url: string) => void
|
||||||
|
// allowConnectingToRelay takes a relay URL and the operation being performed
|
||||||
|
// return false to skip connecting to that relay
|
||||||
|
allowConnectingToRelay?: (url: string, operation: ['read', Filter[]] | ['write', Event]) => boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SubscribeManyParams = Omit<SubscriptionParams, 'onclose'> & {
|
export type SubscribeManyParams = Omit<SubscriptionParams, 'onclose'> & {
|
||||||
@@ -40,6 +46,8 @@ export class AbstractSimplePool {
|
|||||||
public enableReconnect: boolean
|
public enableReconnect: boolean
|
||||||
public automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
|
public automaticallyAuth?: (relayURL: string) => null | ((event: EventTemplate) => Promise<VerifiedEvent>)
|
||||||
public trustedRelayURLs: Set<string> = new Set()
|
public trustedRelayURLs: Set<string> = new Set()
|
||||||
|
public onRelayConnectionFailure?: (url: string) => void
|
||||||
|
public allowConnectingToRelay?: (url: string, operation: ['read', Filter[]] | ['write', Event]) => boolean
|
||||||
|
|
||||||
private _WebSocket?: typeof WebSocket
|
private _WebSocket?: typeof WebSocket
|
||||||
|
|
||||||
@@ -49,6 +57,8 @@ export class AbstractSimplePool {
|
|||||||
this.enablePing = opts.enablePing
|
this.enablePing = opts.enablePing
|
||||||
this.enableReconnect = opts.enableReconnect || false
|
this.enableReconnect = opts.enableReconnect || false
|
||||||
this.automaticallyAuth = opts.automaticallyAuth
|
this.automaticallyAuth = opts.automaticallyAuth
|
||||||
|
this.onRelayConnectionFailure = opts.onRelayConnectionFailure
|
||||||
|
this.allowConnectingToRelay = opts.allowConnectingToRelay
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureRelay(
|
async ensureRelay(
|
||||||
@@ -181,6 +191,11 @@ export class AbstractSimplePool {
|
|||||||
// open a subscription in all given relays
|
// open a subscription in all given relays
|
||||||
const allOpened = Promise.all(
|
const allOpened = Promise.all(
|
||||||
groupedRequests.map(async ({ url, filters }, i) => {
|
groupedRequests.map(async ({ url, filters }, i) => {
|
||||||
|
if (this.allowConnectingToRelay?.(url, ['read', filters]) === false) {
|
||||||
|
handleClose(i, 'connection skipped by allowConnectingToRelay')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let relay: AbstractRelay
|
let relay: AbstractRelay
|
||||||
try {
|
try {
|
||||||
relay = await this.ensureRelay(url, {
|
relay = await this.ensureRelay(url, {
|
||||||
@@ -188,6 +203,7 @@ export class AbstractSimplePool {
|
|||||||
abort: params.abort,
|
abort: params.abort,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
this.onRelayConnectionFailure?.(url)
|
||||||
handleClose(i, (err as any)?.message || String(err))
|
handleClose(i, (err as any)?.message || String(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -306,7 +322,18 @@ export class AbstractSimplePool {
|
|||||||
return Promise.reject('duplicate url')
|
return Promise.reject('duplicate url')
|
||||||
}
|
}
|
||||||
|
|
||||||
let r = await this.ensureRelay(url)
|
if (this.allowConnectingToRelay?.(url, ['write', event]) === false) {
|
||||||
|
return Promise.reject('connection skipped by allowConnectingToRelay')
|
||||||
|
}
|
||||||
|
|
||||||
|
let r: Relay
|
||||||
|
try {
|
||||||
|
r = await this.ensureRelay(url)
|
||||||
|
} catch (err) {
|
||||||
|
this.onRelayConnectionFailure?.(url)
|
||||||
|
return String('connection failure: ' + String(err))
|
||||||
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
.publish(event)
|
.publish(event)
|
||||||
.catch(async err => {
|
.catch(async err => {
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ export class AbstractRelay {
|
|||||||
reject('connection timed out')
|
reject('connection timed out')
|
||||||
this.connectionPromise = undefined
|
this.connectionPromise = undefined
|
||||||
this.onclose?.()
|
this.onclose?.()
|
||||||
this.closeAllSubscriptions('relay connection timed out')
|
this.handleHardClose('relay connection timed out')
|
||||||
}, opts.timeout)
|
}, opts.timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +153,17 @@ export class AbstractRelay {
|
|||||||
opts.abort.onabort = reject
|
opts.abort.onabort = reject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const connectionFailed = () => {
|
||||||
|
clearTimeout(connectionTimeoutHandle)
|
||||||
|
reject('connection failed')
|
||||||
|
this.connectionPromise = undefined
|
||||||
|
this.onclose?.()
|
||||||
|
this.handleHardClose('relay connection failed')
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.ws = new this._WebSocket(this.url)
|
this.ws = new this._WebSocket(this.url)
|
||||||
|
this.ws.addEventListener('error', connectionFailed)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
clearTimeout(connectionTimeoutHandle)
|
clearTimeout(connectionTimeoutHandle)
|
||||||
reject(err)
|
reject(err)
|
||||||
@@ -162,6 +171,8 @@ export class AbstractRelay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.ws.onopen = () => {
|
this.ws.onopen = () => {
|
||||||
|
this.ws?.removeEventListener('error', connectionFailed)
|
||||||
|
|
||||||
if (this.reconnectTimeoutHandle) {
|
if (this.reconnectTimeoutHandle) {
|
||||||
clearTimeout(this.reconnectTimeoutHandle)
|
clearTimeout(this.reconnectTimeoutHandle)
|
||||||
this.reconnectTimeoutHandle = undefined
|
this.reconnectTimeoutHandle = undefined
|
||||||
|
|||||||
2
jsr.json
2
jsr.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.20.0",
|
"version": "2.22.1",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|||||||
4
nip04.ts
4
nip04.ts
@@ -1,6 +1,6 @@
|
|||||||
import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils.js'
|
import { hexToBytes, randomBytes } from '@noble/hashes/utils.js'
|
||||||
import { secp256k1 } from '@noble/curves/secp256k1.js'
|
import { secp256k1 } from '@noble/curves/secp256k1.js'
|
||||||
import { cbc } from '@noble/ciphers/aes'
|
import { cbc } from '@noble/ciphers/aes.js'
|
||||||
import { base64 } from '@scure/base'
|
import { base64 } from '@scure/base'
|
||||||
|
|
||||||
import { utf8Decoder, utf8Encoder } from './utils.ts'
|
import { utf8Decoder, utf8Encoder } from './utils.ts'
|
||||||
|
|||||||
2
nip06.ts
2
nip06.ts
@@ -1,5 +1,5 @@
|
|||||||
import { bytesToHex } from '@noble/hashes/utils.js'
|
import { bytesToHex } from '@noble/hashes/utils.js'
|
||||||
import { wordlist } from '@scure/bip39/wordlists/english'
|
import { wordlist } from '@scure/bip39/wordlists/english.js'
|
||||||
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic } from '@scure/bip39'
|
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic } from '@scure/bip39'
|
||||||
import { HDKey } from '@scure/bip32'
|
import { HDKey } from '@scure/bip32'
|
||||||
|
|
||||||
|
|||||||
2
nip19.ts
2
nip19.ts
@@ -110,7 +110,7 @@ export function decode(nip19: NPub): DecodedNpub
|
|||||||
export function decode(nip19: Note): DecodedNote
|
export function decode(nip19: Note): DecodedNote
|
||||||
export function decode(code: string): DecodedResult
|
export function decode(code: string): DecodedResult
|
||||||
export function decode(code: string): DecodedResult {
|
export function decode(code: string): DecodedResult {
|
||||||
let { prefix, words } = bech32.decode(code, Bech32MaxSize)
|
let { prefix, words } = bech32.decode(code as `${string}1${string}`, Bech32MaxSize)
|
||||||
let data = new Uint8Array(bech32.fromWords(words))
|
let data = new Uint8Array(bech32.fromWords(words))
|
||||||
|
|
||||||
switch (prefix) {
|
switch (prefix) {
|
||||||
|
|||||||
4
nip44.ts
4
nip44.ts
@@ -1,5 +1,5 @@
|
|||||||
import { chacha20 } from '@noble/ciphers/chacha'
|
import { chacha20 } from '@noble/ciphers/chacha.js'
|
||||||
import { equalBytes } from '@noble/ciphers/utils'
|
import { equalBytes } from '@noble/ciphers/utils.js'
|
||||||
import { secp256k1 } from '@noble/curves/secp256k1.js'
|
import { secp256k1 } from '@noble/curves/secp256k1.js'
|
||||||
import { extract as hkdf_extract, expand as hkdf_expand } from '@noble/hashes/hkdf.js'
|
import { extract as hkdf_extract, expand as hkdf_expand } from '@noble/hashes/hkdf.js'
|
||||||
import { hmac } from '@noble/hashes/hmac.js'
|
import { hmac } from '@noble/hashes/hmac.js'
|
||||||
|
|||||||
6
nip49.ts
6
nip49.ts
@@ -1,8 +1,8 @@
|
|||||||
|
import { bech32 } from '@scure/base'
|
||||||
import { scrypt } from '@noble/hashes/scrypt.js'
|
import { scrypt } from '@noble/hashes/scrypt.js'
|
||||||
import { xchacha20poly1305 } from '@noble/ciphers/chacha'
|
import { xchacha20poly1305 } from '@noble/ciphers/chacha.js'
|
||||||
import { concatBytes, randomBytes } from '@noble/hashes/utils.js'
|
import { concatBytes, randomBytes } from '@noble/hashes/utils.js'
|
||||||
import { Bech32MaxSize, Ncryptsec, encodeBytes } from './nip19.ts'
|
import { Bech32MaxSize, Ncryptsec, encodeBytes } from './nip19.ts'
|
||||||
import { bech32 } from '@scure/base'
|
|
||||||
|
|
||||||
export function encrypt(
|
export function encrypt(
|
||||||
sec: Uint8Array,
|
sec: Uint8Array,
|
||||||
@@ -22,7 +22,7 @@ export function encrypt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function decrypt(ncryptsec: string, password: string): Uint8Array {
|
export function decrypt(ncryptsec: string, password: string): Uint8Array {
|
||||||
let { prefix, words } = bech32.decode(ncryptsec, Bech32MaxSize)
|
let { prefix, words } = bech32.decode(ncryptsec as `${string}1${string}`, Bech32MaxSize)
|
||||||
if (prefix !== 'ncryptsec') {
|
if (prefix !== 'ncryptsec') {
|
||||||
throw new Error(`invalid prefix ${prefix}, expected 'ncryptsec'`)
|
throw new Error(`invalid prefix ${prefix}, expected 'ncryptsec'`)
|
||||||
}
|
}
|
||||||
|
|||||||
2
nip77.ts
2
nip77.ts
@@ -1,4 +1,4 @@
|
|||||||
import { bytesToHex, hexToBytes } from '@noble/ciphers/utils'
|
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'
|
||||||
import { Filter } from './filter.ts'
|
import { Filter } from './filter.ts'
|
||||||
import { AbstractRelay, Subscription } from './relay.ts'
|
import { AbstractRelay, Subscription } from './relay.ts'
|
||||||
import { sha256 } from '@noble/hashes/sha2.js'
|
import { sha256 } from '@noble/hashes/sha2.js'
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.20.0",
|
"version": "2.22.1",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -236,12 +236,12 @@
|
|||||||
},
|
},
|
||||||
"license": "Unlicense",
|
"license": "Unlicense",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/ciphers": "^0.5.1",
|
"@noble/ciphers": "2.1.1",
|
||||||
"@noble/curves": "^2.0.1",
|
"@noble/curves": "2.0.1",
|
||||||
"@noble/hashes": "^2.0.1",
|
"@noble/hashes": "2.0.1",
|
||||||
"@scure/base": "1.1.1",
|
"@scure/base": "2.0.0",
|
||||||
"@scure/bip32": "1.3.1",
|
"@scure/bip32": "2.0.1",
|
||||||
"@scure/bip39": "1.2.1",
|
"@scure/bip39": "2.0.1",
|
||||||
"nostr-wasm": "0.1.0"
|
"nostr-wasm": "0.1.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user