mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf55ad6b5a | ||
|
|
04a46b815c | ||
|
|
165ff44dff | ||
|
|
7bfd23af3c | ||
|
|
3d93ec8446 | ||
|
|
0f841138cd | ||
|
|
336948b1d1 | ||
|
|
d46794c681 | ||
|
|
93cef5d886 | ||
|
|
2324f9548e | ||
|
|
f9748d9cc3 | ||
|
|
3a22dd3da6 | ||
|
|
d13039dc11 | ||
|
|
95b03902cc |
13
README.md
13
README.md
@@ -4,6 +4,13 @@ Tools for developing [Nostr](https://github.com/fiatjaf/nostr) clients.
|
|||||||
|
|
||||||
Only depends on _@scure_ and _@noble_ packages.
|
Only depends on _@scure_ and _@noble_ packages.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install nostr-tools # or yarn add nostr-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Generating a private key and a public key
|
### Generating a private key and a public key
|
||||||
@@ -53,8 +60,6 @@ import {
|
|||||||
} from 'nostr-tools'
|
} from 'nostr-tools'
|
||||||
|
|
||||||
const relay = relayInit('wss://relay.example.com')
|
const relay = relayInit('wss://relay.example.com')
|
||||||
await relay.connect()
|
|
||||||
|
|
||||||
relay.on('connect', () => {
|
relay.on('connect', () => {
|
||||||
console.log(`connected to ${relay.url}`)
|
console.log(`connected to ${relay.url}`)
|
||||||
})
|
})
|
||||||
@@ -62,6 +67,8 @@ relay.on('error', () => {
|
|||||||
console.log(`failed to connect to ${relay.url}`)
|
console.log(`failed to connect to ${relay.url}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await relay.connect()
|
||||||
|
|
||||||
// let's query for an event that exists
|
// let's query for an event that exists
|
||||||
let sub = relay.sub([
|
let sub = relay.sub([
|
||||||
{
|
{
|
||||||
@@ -113,7 +120,7 @@ let event = await relay.get({
|
|||||||
ids: ['44e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245']
|
ids: ['44e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245']
|
||||||
})
|
})
|
||||||
|
|
||||||
await relay.close()
|
relay.close()
|
||||||
```
|
```
|
||||||
|
|
||||||
To use this on Node.js you first must install `websocket-polyfill` and import it:
|
To use this on Node.js you first must install `websocket-polyfill` and import it:
|
||||||
|
|||||||
10
build.js
10
build.js
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
const esbuild = require('esbuild')
|
const esbuild = require('esbuild')
|
||||||
|
|
||||||
let common = {
|
let common = {
|
||||||
@@ -11,11 +12,16 @@ let common = {
|
|||||||
esbuild
|
esbuild
|
||||||
.build({
|
.build({
|
||||||
...common,
|
...common,
|
||||||
outfile: 'lib/nostr.esm.js',
|
outfile: 'lib/esm/nostr.mjs',
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
packages: 'external'
|
packages: 'external'
|
||||||
})
|
})
|
||||||
.then(() => console.log('esm build success.'))
|
.then(() => {
|
||||||
|
const packageJson = JSON.stringify({ type: 'module' })
|
||||||
|
fs.writeFileSync(`${__dirname}/lib/esm/package.json`, packageJson, 'utf8')
|
||||||
|
|
||||||
|
console.log('esm build success.')
|
||||||
|
})
|
||||||
|
|
||||||
esbuild
|
esbuild
|
||||||
.build({
|
.build({
|
||||||
|
|||||||
22
event.ts
22
event.ts
@@ -2,6 +2,7 @@ import * as secp256k1 from '@noble/secp256k1'
|
|||||||
import {sha256} from '@noble/hashes/sha256'
|
import {sha256} from '@noble/hashes/sha256'
|
||||||
|
|
||||||
import {utf8Encoder} from './utils'
|
import {utf8Encoder} from './utils'
|
||||||
|
import {getPublicKey} from './keys'
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
export enum Kind {
|
export enum Kind {
|
||||||
@@ -32,8 +33,11 @@ export type EventTemplate = {
|
|||||||
created_at: number
|
created_at: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Event = EventTemplate & {
|
export type UnsignedEvent = EventTemplate & {
|
||||||
pubkey: string
|
pubkey: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Event = UnsignedEvent & {
|
||||||
id: string
|
id: string
|
||||||
sig: string
|
sig: string
|
||||||
}
|
}
|
||||||
@@ -47,7 +51,15 @@ export function getBlankEvent(): EventTemplate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function serializeEvent(evt: Event): string {
|
export function finishEvent(t: EventTemplate, privateKey: string): Event {
|
||||||
|
let event = t as Event
|
||||||
|
event.pubkey = getPublicKey(privateKey)
|
||||||
|
event.id = getEventHash(event)
|
||||||
|
event.sig = signEvent(event, privateKey)
|
||||||
|
return event
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializeEvent(evt: UnsignedEvent): string {
|
||||||
if (!validateEvent(evt))
|
if (!validateEvent(evt))
|
||||||
throw new Error("can't serialize event with wrong or missing properties")
|
throw new Error("can't serialize event with wrong or missing properties")
|
||||||
|
|
||||||
@@ -61,12 +73,12 @@ export function serializeEvent(evt: Event): string {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getEventHash(event: Event): string {
|
export function getEventHash(event: UnsignedEvent): string {
|
||||||
let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)))
|
let eventHash = sha256(utf8Encoder.encode(serializeEvent(event)))
|
||||||
return secp256k1.utils.bytesToHex(eventHash)
|
return secp256k1.utils.bytesToHex(eventHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateEvent(event: Event): boolean {
|
export function validateEvent(event: UnsignedEvent): boolean {
|
||||||
if (typeof event !== 'object') return false
|
if (typeof event !== 'object') return false
|
||||||
if (typeof event.content !== 'string') return false
|
if (typeof event.content !== 'string') return false
|
||||||
if (typeof event.created_at !== 'number') return false
|
if (typeof event.created_at !== 'number') return false
|
||||||
@@ -93,7 +105,7 @@ export function verifySignature(event: Event & {sig: string}): boolean {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function signEvent(event: Event, key: string): string {
|
export function signEvent(event: UnsignedEvent, key: string): string {
|
||||||
return secp256k1.utils.bytesToHex(
|
return secp256k1.utils.bytesToHex(
|
||||||
secp256k1.schnorr.signSync(getEventHash(event), key)
|
secp256k1.schnorr.signSync(getEventHash(event), key)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,3 +34,25 @@ test('encode and decode nprofile', () => {
|
|||||||
expect(data.relays).toContain(relays[0])
|
expect(data.relays).toContain(relays[0])
|
||||||
expect(data.relays).toContain(relays[1])
|
expect(data.relays).toContain(relays[1])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('encode and decode naddr', () => {
|
||||||
|
let pk = getPublicKey(generatePrivateKey())
|
||||||
|
let relays = [
|
||||||
|
'wss://relay.nostr.example.mydomain.example.com',
|
||||||
|
'wss://nostr.banana.com'
|
||||||
|
]
|
||||||
|
let naddr = nip19.naddrEncode({
|
||||||
|
pubkey: pk,
|
||||||
|
relays,
|
||||||
|
kind: 30023,
|
||||||
|
identifier: 'banana'
|
||||||
|
})
|
||||||
|
expect(naddr).toMatch(/naddr1\w+/)
|
||||||
|
let {type, data} = nip19.decode(naddr)
|
||||||
|
expect(type).toEqual('naddr')
|
||||||
|
expect(data.pubkey).toEqual(pk)
|
||||||
|
expect(data.relays).toContain(relays[0])
|
||||||
|
expect(data.relays).toContain(relays[1])
|
||||||
|
expect(data.kind).toEqual(30023)
|
||||||
|
expect(data.identifier).toEqual('banana')
|
||||||
|
})
|
||||||
|
|||||||
55
nip19.ts
55
nip19.ts
@@ -15,14 +15,22 @@ export type EventPointer = {
|
|||||||
relays?: string[]
|
relays?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type AddressPointer = {
|
||||||
|
identifier: string
|
||||||
|
pubkey: string
|
||||||
|
kind: number
|
||||||
|
relays?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export function decode(nip19: string): {
|
export function decode(nip19: string): {
|
||||||
type: string
|
type: string
|
||||||
data: ProfilePointer | EventPointer | string
|
data: ProfilePointer | EventPointer | AddressPointer | string
|
||||||
} {
|
} {
|
||||||
let {prefix, words} = bech32.decode(nip19, Bech32MaxSize)
|
let {prefix, words} = bech32.decode(nip19, Bech32MaxSize)
|
||||||
let data = new Uint8Array(bech32.fromWords(words))
|
let data = new Uint8Array(bech32.fromWords(words))
|
||||||
|
|
||||||
if (prefix === 'nprofile') {
|
switch (prefix) {
|
||||||
|
case 'nprofile': {
|
||||||
let tlv = parseTLV(data)
|
let tlv = parseTLV(data)
|
||||||
if (!tlv[0]?.[0]) throw new Error('missing TLV 0 for nprofile')
|
if (!tlv[0]?.[0]) throw new Error('missing TLV 0 for nprofile')
|
||||||
if (tlv[0][0].length !== 32) throw new Error('TLV 0 should be 32 bytes')
|
if (tlv[0][0].length !== 32) throw new Error('TLV 0 should be 32 bytes')
|
||||||
@@ -35,8 +43,7 @@ export function decode(nip19: string): {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'nevent': {
|
||||||
if (prefix === 'nevent') {
|
|
||||||
let tlv = parseTLV(data)
|
let tlv = parseTLV(data)
|
||||||
if (!tlv[0]?.[0]) throw new Error('missing TLV 0 for nevent')
|
if (!tlv[0]?.[0]) throw new Error('missing TLV 0 for nevent')
|
||||||
if (tlv[0][0].length !== 32) throw new Error('TLV 0 should be 32 bytes')
|
if (tlv[0][0].length !== 32) throw new Error('TLV 0 should be 32 bytes')
|
||||||
@@ -50,12 +57,34 @@ export function decode(nip19: string): {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix === 'nsec' || prefix === 'npub' || prefix === 'note') {
|
case 'naddr': {
|
||||||
return {type: prefix, data: secp256k1.utils.bytesToHex(data)}
|
let tlv = parseTLV(data)
|
||||||
|
if (!tlv[0]?.[0]) throw new Error('missing TLV 0 for naddr')
|
||||||
|
if (!tlv[2]?.[0]) throw new Error('missing TLV 2 for naddr')
|
||||||
|
if (tlv[2][0].length !== 32) throw new Error('TLV 2 should be 32 bytes')
|
||||||
|
if (!tlv[3]?.[0]) throw new Error('missing TLV 3 for naddr')
|
||||||
|
if (tlv[3][0].length !== 4) throw new Error('TLV 3 should be 4 bytes')
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'naddr',
|
||||||
|
data: {
|
||||||
|
identifier: utf8Decoder.decode(tlv[0][0]),
|
||||||
|
pubkey: secp256k1.utils.bytesToHex(tlv[2][0]),
|
||||||
|
kind: parseInt(secp256k1.utils.bytesToHex(tlv[3][0]), 16),
|
||||||
|
relays: tlv[1].map(d => utf8Decoder.decode(d))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'nsec':
|
||||||
|
case 'npub':
|
||||||
|
case 'note':
|
||||||
|
return {type: prefix, data: secp256k1.utils.bytesToHex(data)}
|
||||||
|
|
||||||
|
default:
|
||||||
throw new Error(`unknown prefix ${prefix}`)
|
throw new Error(`unknown prefix ${prefix}`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type TLV = {[t: number]: Uint8Array[]}
|
type TLV = {[t: number]: Uint8Array[]}
|
||||||
|
|
||||||
@@ -110,6 +139,20 @@ export function neventEncode(event: EventPointer): string {
|
|||||||
return bech32.encode('nevent', words, Bech32MaxSize)
|
return bech32.encode('nevent', words, Bech32MaxSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function naddrEncode(addr: AddressPointer): string {
|
||||||
|
let kind = new ArrayBuffer(4)
|
||||||
|
new DataView(kind).setUint32(0, addr.kind, false)
|
||||||
|
|
||||||
|
let data = encodeTLV({
|
||||||
|
0: [utf8Encoder.encode(addr.identifier)],
|
||||||
|
1: (addr.relays || []).map(url => utf8Encoder.encode(url)),
|
||||||
|
2: [secp256k1.utils.hexToBytes(addr.pubkey)],
|
||||||
|
3: [new Uint8Array(kind)]
|
||||||
|
})
|
||||||
|
let words = bech32.toWords(data)
|
||||||
|
return bech32.encode('naddr', words, Bech32MaxSize)
|
||||||
|
}
|
||||||
|
|
||||||
function encodeTLV(tlv: TLV): Uint8Array {
|
function encodeTLV(tlv: TLV): Uint8Array {
|
||||||
let entries: Uint8Array[] = []
|
let entries: Uint8Array[] = []
|
||||||
|
|
||||||
|
|||||||
37
nip57.ts
37
nip57.ts
@@ -1,6 +1,6 @@
|
|||||||
import {bech32} from '@scure/base'
|
import {bech32} from '@scure/base'
|
||||||
|
|
||||||
import {Event, EventTemplate} from './event'
|
import {Event, EventTemplate, validateEvent, verifySignature} from './event'
|
||||||
import {utf8Decoder} from './utils'
|
import {utf8Decoder} from './utils'
|
||||||
|
|
||||||
var _fetch: any
|
var _fetch: any
|
||||||
@@ -50,17 +50,20 @@ export function makeZapRequest({
|
|||||||
}: {
|
}: {
|
||||||
profile: string
|
profile: string
|
||||||
event: string | null
|
event: string | null
|
||||||
amount: string
|
amount: number
|
||||||
comment: string
|
comment: string
|
||||||
relays: string[]
|
relays: string[]
|
||||||
}): EventTemplate {
|
}): EventTemplate {
|
||||||
|
if (!amount) throw new Error('amount not given')
|
||||||
|
if (!profile) throw new Error('profile not given')
|
||||||
|
|
||||||
let zr = {
|
let zr = {
|
||||||
kind: 9734,
|
kind: 9734,
|
||||||
created_at: Math.round(Date.now() / 1000),
|
created_at: Math.round(Date.now() / 1000),
|
||||||
content: comment,
|
content: comment,
|
||||||
tags: [
|
tags: [
|
||||||
['p', profile],
|
['p', profile],
|
||||||
['amount', amount],
|
['amount', amount.toString()],
|
||||||
['relays', ...relays]
|
['relays', ...relays]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -72,6 +75,34 @@ export function makeZapRequest({
|
|||||||
return zr
|
return zr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function validateZapRequest(zapRequestString: string): string | null {
|
||||||
|
let zapRequest: Event
|
||||||
|
|
||||||
|
try {
|
||||||
|
zapRequest = JSON.parse(zapRequestString)
|
||||||
|
} catch (err) {
|
||||||
|
return 'Invalid zap request JSON.'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validateEvent(zapRequest))
|
||||||
|
return 'Zap request is not a valid Nostr event.'
|
||||||
|
if (!verifySignature(zapRequest)) return 'Invalid signature on zap request.'
|
||||||
|
|
||||||
|
let p = zapRequest.tags.find(([t, v]) => t === 'p' && v)
|
||||||
|
if (!p) return "Zap request doesn't have a 'p' tag."
|
||||||
|
if (!p[1].match(/^[a-f0-9]{64}$/))
|
||||||
|
return "Zap request 'p' tag is not valid hex."
|
||||||
|
|
||||||
|
let e = zapRequest.tags.find(([t, v]) => t === 'e' && v)
|
||||||
|
if (e && !e[1].match(/^[a-f0-9]{64}$/))
|
||||||
|
return "Zap request 'e' tag is not valid hex."
|
||||||
|
|
||||||
|
let relays = zapRequest.tags.find(([t, v]) => t === 'relays' && v)
|
||||||
|
if (!relays) return "Zap request doesn't have a 'relays' tag."
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export function makeZapReceipt({
|
export function makeZapReceipt({
|
||||||
zapRequest,
|
zapRequest,
|
||||||
preimage,
|
preimage,
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "1.4.2",
|
"version": "1.6.0",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/fiatjaf/nostr-tools.git"
|
"url": "https://github.com/fiatjaf/nostr-tools.git"
|
||||||
},
|
},
|
||||||
"main": "lib/nostr.cjs.js",
|
"main": "lib/nostr.cjs.js",
|
||||||
"module": "lib/nostr.esm.js",
|
"module": "lib/esm/nostr.mjs",
|
||||||
|
"exports": {
|
||||||
|
"import": "./lib/esm/nostr.mjs",
|
||||||
|
"require": "./lib/nostr.cjs.js"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/hashes": "1.0.0",
|
"@noble/hashes": "1.0.0",
|
||||||
"@noble/secp256k1": "^1.7.1",
|
"@noble/secp256k1": "^1.7.1",
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ let relays = [
|
|||||||
'wss://nostr.zebedee.cloud/'
|
'wss://nostr.zebedee.cloud/'
|
||||||
]
|
]
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(() => {
|
||||||
await pool.close([
|
pool.close([
|
||||||
...relays,
|
...relays,
|
||||||
'wss://nostr-relay.untethr.me',
|
'wss://nostr-relay.untethr.me',
|
||||||
'wss://offchain.pub',
|
'wss://offchain.pub',
|
||||||
|
|||||||
8
pool.ts
8
pool.ts
@@ -12,13 +12,11 @@ export class SimplePool {
|
|||||||
this._conn = {}
|
this._conn = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async close(relays: string[]): Promise<void> {
|
close(relays: string[]): void {
|
||||||
await Promise.all(
|
relays.map(url => {
|
||||||
relays.map(async url => {
|
|
||||||
let relay = this._conn[normalizeURL(url)]
|
let relay = this._conn[normalizeURL(url)]
|
||||||
if (relay) await relay.close()
|
if (relay) relay.close()
|
||||||
})
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureRelay(url: string): Promise<Relay> {
|
async ensureRelay(url: string): Promise<Relay> {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ beforeAll(() => {
|
|||||||
relay.connect()
|
relay.connect()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(() => {
|
||||||
await relay.close()
|
relay.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('connectivity', () => {
|
test('connectivity', () => {
|
||||||
|
|||||||
11
relay.ts
11
relay.ts
@@ -10,7 +10,7 @@ export type Relay = {
|
|||||||
url: string
|
url: string
|
||||||
status: number
|
status: number
|
||||||
connect: () => Promise<void>
|
connect: () => Promise<void>
|
||||||
close: () => Promise<void>
|
close: () => void
|
||||||
sub: (filters: Filter[], opts?: SubscriptionOptions) => Sub
|
sub: (filters: Filter[], opts?: SubscriptionOptions) => Sub
|
||||||
list: (filters: Filter[], opts?: SubscriptionOptions) => Promise<Event[]>
|
list: (filters: Filter[], opts?: SubscriptionOptions) => Promise<Event[]>
|
||||||
get: (filter: Filter, opts?: SubscriptionOptions) => Promise<Event | null>
|
get: (filter: Filter, opts?: SubscriptionOptions) => Promise<Event | null>
|
||||||
@@ -37,7 +37,6 @@ export type SubscriptionOptions = {
|
|||||||
|
|
||||||
export function relayInit(url: string): Relay {
|
export function relayInit(url: string): Relay {
|
||||||
var ws: WebSocket
|
var ws: WebSocket
|
||||||
var resolveClose: () => void
|
|
||||||
var openSubs: {[id: string]: {filters: Filter[]} & SubscriptionOptions} = {}
|
var openSubs: {[id: string]: {filters: Filter[]} & SubscriptionOptions} = {}
|
||||||
var listeners: {
|
var listeners: {
|
||||||
connect: Array<() => void>
|
connect: Array<() => void>
|
||||||
@@ -78,7 +77,6 @@ export function relayInit(url: string): Relay {
|
|||||||
}
|
}
|
||||||
ws.onclose = async () => {
|
ws.onclose = async () => {
|
||||||
listeners.disconnect.forEach(cb => cb())
|
listeners.disconnect.forEach(cb => cb())
|
||||||
resolveClose && resolveClose()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let incomingMessageQueue: string[] = []
|
let incomingMessageQueue: string[] = []
|
||||||
@@ -291,16 +289,13 @@ export function relayInit(url: string): Relay {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
connect,
|
connect,
|
||||||
close(): Promise<void> {
|
close(): void {
|
||||||
listeners = {connect: [], disconnect: [], error: [], notice: []}
|
listeners = {connect: [], disconnect: [], error: [], notice: []}
|
||||||
subListeners = {}
|
subListeners = {}
|
||||||
pubListeners = {}
|
pubListeners = {}
|
||||||
|
|
||||||
if (ws.readyState > 1) return Promise.resolve()
|
if (ws.readyState > 1) return
|
||||||
ws.close()
|
ws.close()
|
||||||
return new Promise<void>(resolve => {
|
|
||||||
resolveClose = resolve
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
get status() {
|
get status() {
|
||||||
return ws?.readyState ?? 3
|
return ws?.readyState ?? 3
|
||||||
|
|||||||
Reference in New Issue
Block a user