-
Notifications
You must be signed in to change notification settings - Fork 197
/
nip05.test.ts
46 lines (38 loc) · 1.69 KB
/
nip05.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { test, expect } from 'bun:test'
import { useFetchImplementation, queryProfile, NIP05_REGEX, isNip05 } from './nip05.ts'
test('validate NIP05_REGEX', () => {
expect(NIP05_REGEX.test('[email protected]')).toBeTrue()
expect(NIP05_REGEX.test('[email protected]')).toBeTrue()
expect(NIP05_REGEX.test('b&[email protected]')).toBeFalse()
expect('b&[email protected]'.match(NIP05_REGEX)).toBeNull()
expect(Array.from('[email protected]'.match(NIP05_REGEX) || [])).toEqual(['[email protected]', 'bob', 'bob.com.br', '.br'])
expect(isNip05('[email protected]')).toBeTrue()
expect(isNip05('b&[email protected]')).toBeFalse()
})
test('fetch nip05 profiles', async () => {
const fetchStub = async (url: string) => ({
status: 200,
async json() {
return {
'https://compile-error.net/.well-known/nostr.json?name=_': {
names: { _: '2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc' },
},
'https://fiatjaf.com/.well-known/nostr.json?name=_': {
names: { _: '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d' },
relays: {
'3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d': [
'wss://pyramid.fiatjaf.com',
'wss://nos.lol',
],
},
},
}[url]
},
})
useFetchImplementation(fetchStub)
let p2 = await queryProfile('compile-error.net')
expect(p2!.pubkey).toEqual('2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc')
let p3 = await queryProfile('[email protected]')
expect(p3!.pubkey).toEqual('3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d')
expect(p3!.relays).toEqual(['wss://pyramid.fiatjaf.com', 'wss://nos.lol'])
})