From 6874f58c0a88863e64c198f43a82db00a66b61f4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 26 Sep 2023 12:19:01 -0300 Subject: [PATCH] apply prettier. --- justfile | 8 ++++---- nip13.test.ts | 17 ++++++++++------- nip47.test.ts | 42 +++++++++++++++--------------------------- nip47.ts | 24 ++++++++++-------------- pool.ts | 11 +++++++---- 5 files changed, 46 insertions(+), 56 deletions(-) diff --git a/justfile b/justfile index 386bdee..bdd0f00 100644 --- a/justfile +++ b/justfile @@ -20,9 +20,9 @@ publish: build emit-types npm publish format: - eslint --ext .ts --fix . - prettier --write . + eslint --ext .ts --fix *.ts + prettier --write *.ts lint: - eslint --ext .ts . - prettier --check . \ No newline at end of file + eslint --ext .ts *.ts + prettier --check *.ts diff --git a/nip13.test.ts b/nip13.test.ts index 3a65278..9463f4f 100644 --- a/nip13.test.ts +++ b/nip13.test.ts @@ -9,13 +9,16 @@ test('identifies proof-of-work difficulty', async () => { test('mines POW for an event', async () => { const difficulty = 10 - const event = minePow({ - kind: 1, - tags: [], - content: 'Hello, world!', - created_at: 0, - pubkey: '79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6', - }, difficulty) + const event = minePow( + { + kind: 1, + tags: [], + content: 'Hello, world!', + created_at: 0, + pubkey: '79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6', + }, + difficulty, + ) expect(getPow(event.id)).toBeGreaterThanOrEqual(difficulty) }) diff --git a/nip47.test.ts b/nip47.test.ts index 67b5183..15e4679 100644 --- a/nip47.test.ts +++ b/nip47.test.ts @@ -1,6 +1,6 @@ -import {makeNwcRequestEvent, parseConnectionString} from './nip47' -import {Kind} from './event' -import {decrypt} from './nip04.ts' +import { makeNwcRequestEvent, parseConnectionString } from './nip47' +import { Kind } from './event' +import { decrypt } from './nip04.ts' import crypto from 'node:crypto' // @ts-ignore @@ -11,58 +11,46 @@ describe('parseConnectionString', () => { test('returns pubkey, relay, and secret if connection string is valid', () => { const connectionString = 'nostr+walletconnect:b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?relay=wss%3A%2F%2Frelay.damus.io&secret=71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' - const {pubkey, relay, secret} = parseConnectionString(connectionString) + const { pubkey, relay, secret } = parseConnectionString(connectionString) - expect(pubkey).toBe( - 'b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4' - ) + expect(pubkey).toBe('b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4') expect(relay).toBe('wss://relay.damus.io') - expect(secret).toBe( - '71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' - ) + expect(secret).toBe('71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c') }) test('throws an error if no pubkey in connection string', async () => { const connectionString = 'nostr+walletconnect:relay=wss%3A%2F%2Frelay.damus.io&secret=71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' - expect(() => parseConnectionString(connectionString)).toThrow( - 'invalid connection string' - ) + expect(() => parseConnectionString(connectionString)).toThrow('invalid connection string') }) test('throws an error if no relay in connection string', async () => { const connectionString = 'nostr+walletconnect:b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?secret=71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' - expect(() => parseConnectionString(connectionString)).toThrow( - 'invalid connection string' - ) + expect(() => parseConnectionString(connectionString)).toThrow('invalid connection string') }) test('throws an error if no secret in connection string', async () => { const connectionString = 'nostr+walletconnect:b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4?relay=wss%3A%2F%2Frelay.damus.io' - expect(() => parseConnectionString(connectionString)).toThrow( - 'invalid connection string' - ) + expect(() => parseConnectionString(connectionString)).toThrow('invalid connection string') }) }) describe('makeNwcRequestEvent', () => { test('returns a valid NWC request event', async () => { - const pubkey = - 'b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4' - const secret = - '71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' + const pubkey = 'b889ff5b1513b641e2a139f661a661364979c5beee91842f8f0ef42ab558e9d4' + const secret = '71a8c14c1407c113601079c4302dab36460f0ccd0ad506f1f2dc73b5100e4f3c' const invoice = 'lnbc210n1pjdgyvupp5x43awdarnfd4mdlsklelux0nyckwfu5c708ykuet8vcjnjp3rnpqdqu2askcmr9wssx7e3q2dshgmmndp5scqzzsxqyz5vqsp52l7y9peq9pka3vd3j7aps7gjnalsmy46ndj2mlkz00dltjgqfumq9qyyssq5fasr5dxed8l4qjfnqq48a02jzss3asf8sly7sfaqtr9w3yu2q9spsxhghs3y9aqdf44zkrrg9jjjdg6amade4h0hulllkwk33eqpucp6d5jye' const timeBefore = Date.now() / 1000 const result = await makeNwcRequestEvent({ pubkey, secret, - invoice + invoice, }) const timeAfter = Date.now() / 1000 expect(result.kind).toBe(Kind.NwcRequest) @@ -72,9 +60,9 @@ describe('makeNwcRequestEvent', () => { JSON.stringify({ method: 'pay_invoice', params: { - invoice - } - }) + invoice, + }, + }), ) expect(result.tags).toEqual([['p', pubkey]]) expect(result.id).toEqual(expect.any(String)) diff --git a/nip47.ts b/nip47.ts index c6f608c..16b11b0 100644 --- a/nip47.ts +++ b/nip47.ts @@ -1,9 +1,9 @@ -import {finishEvent} from './event.ts' -import {encrypt} from './nip04.ts' -import {Kind} from './event' +import { finishEvent } from './event.ts' +import { encrypt } from './nip04.ts' +import { Kind } from './event' export function parseConnectionString(connectionString: string) { - const {pathname, searchParams} = new URL(connectionString) + const { pathname, searchParams } = new URL(connectionString) const pubkey = pathname const relay = searchParams.get('relay') const secret = searchParams.get('secret') @@ -12,13 +12,13 @@ export function parseConnectionString(connectionString: string) { throw new Error('invalid connection string') } - return {pubkey, relay, secret} + return { pubkey, relay, secret } } export async function makeNwcRequestEvent({ pubkey, secret, - invoice + invoice, }: { pubkey: string secret: string @@ -27,19 +27,15 @@ export async function makeNwcRequestEvent({ const content = { method: 'pay_invoice', params: { - invoice - } + invoice, + }, } - const encryptedContent = await encrypt( - secret, - pubkey, - JSON.stringify(content) - ) + const encryptedContent = await encrypt(secret, pubkey, JSON.stringify(content)) const eventTemplate = { kind: Kind.NwcRequest, created_at: Math.round(Date.now() / 1000), content: encryptedContent, - tags: [['p', pubkey]] + tags: [['p', pubkey]], } return finishEvent(eventTemplate, secret) diff --git a/pool.ts b/pool.ts index f64bcd7..1de6a70 100644 --- a/pool.ts +++ b/pool.ts @@ -79,10 +79,13 @@ export class SimplePool { let eosesMissing = relays.length let eoseSent = false - let eoseTimeout = setTimeout(() => { - eoseSent = true - for (let cb of eoseListeners.values()) cb() - }, opts?.eoseSubTimeout || this.eoseSubTimeout) + let eoseTimeout = setTimeout( + () => { + eoseSent = true + for (let cb of eoseListeners.values()) cb() + }, + opts?.eoseSubTimeout || this.eoseSubTimeout, + ) relays .filter((r, i, a) => a.indexOf(r) === i)