Skip to content

Commit

Permalink
fix tests for nostr type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioconselheiro committed May 30, 2024
1 parent 177f4b2 commit f3a1995
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,21 @@ test('NostrTypeGuard isNPublic with invalid npub', () => {

expect(is).toBeFalse()
})

test('NostrTypeGuard isNote', () => {
const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sclreky')

expect(is).toBeTrue()
})

test('NostrTypeGuard isNote with invalid note', () => {
const is = NostrTypeGuard.isNote('note1gmtnz6q2m55epmlpe3semjdcq987av3jvx4emmjsa8g3s9x7tg4sçlreky')

expect(is).toBeFalse()
})

test('NostrTypeGuard isNote with invalid note', () => {
const is = NostrTypeGuard.isNote('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats')

expect(is).toBeFalse()
})
6 changes: 3 additions & 3 deletions core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export type Note = `note${string}`
export type Nip05 = `${string}@${string}`

export const NostrTypeGuard = {
isNProfile: (value?: string): value is NProfile => /^nprofile1[a-z\d]{58}$/.test(value || ''),
isNRelay: (value?: string): value is NRelay => /^nrelay1[a-z\d]{45}$/.test(value || ''),
isNProfile: (value?: string): value is NProfile => /^nprofile1[a-z\d]+$/.test(value || ''),
isNRelay: (value?: string): value is NRelay => /^nrelay1[a-z\d]+$/.test(value || ''),
isNEvent: (value?: string): value is NEvent => /^nevent1[a-z\d]+$/.test(value || ''),
isNAddress: (value?: string): value is NAddress => /^naddr1[a-z\d]+$/.test(value || ''),
isNSecret: (value?: string): value is NSecret => /^nsec1[a-z\d]{58}$/.test(value || ''),
isNPublic: (value?: string): value is NPublic => /^npub1[a-z\d]{58}$/.test(value || ''),
isNote: (value?: string): value is Note => /^note1[a-z\d]{58}$/.test(value || '')
isNote: (value?: string): value is Note => /^note1[a-z\d]+$/.test(value || '')
}

/** An event whose signature has been verified. */
Expand Down

0 comments on commit f3a1995

Please sign in to comment.