simplify nip-42.

This commit is contained in:
fiatjaf
2023-12-16 11:21:49 -03:00
parent bf31f2eba3
commit 2ac69278ce
2 changed files with 12 additions and 40 deletions

View File

@@ -1,26 +1,14 @@
import 'websocket-polyfill'
import { finishEvent } from './event.ts'
import { generatePrivateKey } from './keys.ts'
import { authenticate } from './nip42.ts'
import { makeAuthEvent } from './nip42.ts'
import { relayInit } from './relay.ts'
test('auth flow', () => {
const relay = relayInit('wss://nostr.kollider.xyz')
relay.connect()
const sk = generatePrivateKey()
const relay = relayInit('wss://nostr.wine')
return new Promise<void>(resolve => {
relay.on('auth', async challenge => {
await expect(
authenticate({
challenge,
relay,
sign: e => finishEvent(e, sk),
}),
).rejects.toBeTruthy()
relay.close()
resolve()
})
})
const auth = makeAuthEvent(relay.url, 'chachacha')
expect(auth.tags).toHaveLength(2)
expect(auth.tags[0]).toEqual(['relay', 'wss://nostr.wine'])
expect(auth.tags[1]).toEqual(['challenge', 'chachacha'])
expect(auth.kind).toEqual(22242)
})