Skip to content

Commit

Permalink
fixing names of nostr types and types guards
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioconselheiro committed Jun 17, 2024
1 parent eadfcd0 commit 5c620ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,51 +78,51 @@ test('NostrTypeGuard isNEvent with invalid nevent', () => {
})

test('NostrTypeGuard isNAddress', () => {
const is = NostrTypeGuard.isNAddress(
const is = NostrTypeGuard.isNAddr(
'naddr1qqxnzdesxqmnxvpexqunzvpcqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzypve7elhmamff3sr5mgxxms4a0rppkmhmn7504h96pfcdkpplvl2jqcyqqq823cnmhuld',
)

expect(is).toBeTrue()
})

test('NostrTypeGuard isNAddress with invalid nadress', () => {
const is = NostrTypeGuard.isNAddress('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv')
const is = NostrTypeGuard.isNAddr('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv')

expect(is).toBeFalse()
})

test('NostrTypeGuard isNSecret', () => {
const is = NostrTypeGuard.isNSecret('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv')
const is = NostrTypeGuard.isNSec('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv')

expect(is).toBeTrue()
})

test('NostrTypeGuard isNSecret with invalid nsec', () => {
const is = NostrTypeGuard.isNSecret('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juã')
const is = NostrTypeGuard.isNSec('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juã')

expect(is).toBeFalse()
})

test('NostrTypeGuard isNSecret with invalid nsec', () => {
const is = NostrTypeGuard.isNSecret('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg')
const is = NostrTypeGuard.isNSec('nprofile1qqsvc6ulagpn7kwrcwdqgp797xl7usumqa6s3kgcelwq6m75x8fe8yc5usxdg')

expect(is).toBeFalse()
})

test('NostrTypeGuard isNPublic', () => {
const is = NostrTypeGuard.isNPublic('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats')
const is = NostrTypeGuard.isNPub('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzasv8xeh5q92fv33sjgqy4pats')

expect(is).toBeTrue()
})

test('NostrTypeGuard isNPublic with invalid npub', () => {
const is = NostrTypeGuard.isNPublic('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzãsv8xeh5q92fv33sjgqy4pats')
const is = NostrTypeGuard.isNPub('npub1jz5mdljkmffmqjshpyjgqgrhdkuxd9ztzãsv8xeh5q92fv33sjgqy4pats')

expect(is).toBeFalse()
})

test('NostrTypeGuard isNPublic with invalid npub', () => {
const is = NostrTypeGuard.isNPublic('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv')
const is = NostrTypeGuard.isNPub('nsec1lqw6zqyanj9mz8gwhdam6tqge42vptz4zg93qsfej440xm5h5esqya0juv')

expect(is).toBeFalse()
})
Expand Down
12 changes: 6 additions & 6 deletions core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export type UnsignedEvent = Pick<Event, 'kind' | 'tags' | 'content' | 'created_a
export type NProfile = `nprofile1${string}`
export type NRelay = `nrelay1${string}`
export type NEvent = `nevent1${string}`
export type NAddress = `naddr1${string}`
export type NSecret = `nsec1${string}`
export type NPublic = `npub1${string}`
export type NAddr = `naddr1${string}`
export type NSec = `nsec1${string}`
export type NPub = `npub1${string}`
export type Note = `note1${string}`
export type Ncryptsec = `ncryptsec1${string}`
export type Nip05 = `${string}@${string}`
Expand All @@ -37,9 +37,9 @@ export const NostrTypeGuard = {
isNProfile: (value?: string | null): value is NProfile => /^nprofile1[a-z\d]+$/.test(value || ''),
isNRelay: (value?: string | null): value is NRelay => /^nrelay1[a-z\d]+$/.test(value || ''),
isNEvent: (value?: string | null): value is NEvent => /^nevent1[a-z\d]+$/.test(value || ''),
isNAddress: (value?: string | null): value is NAddress => /^naddr1[a-z\d]+$/.test(value || ''),
isNSecret: (value?: string | null): value is NSecret => /^nsec1[a-z\d]{58}$/.test(value || ''),
isNPublic: (value?: string | null): value is NPublic => /^npub1[a-z\d]{58}$/.test(value || ''),
isNAddr: (value?: string | null): value is NAddr => /^naddr1[a-z\d]+$/.test(value || ''),
isNSec: (value?: string | null): value is NSec => /^nsec1[a-z\d]{58}$/.test(value || ''),
isNPub: (value?: string | null): value is NPub => /^npub1[a-z\d]{58}$/.test(value || ''),
isNote: (value?: string | null): value is Note => /^note1[a-z\d]+$/.test(value || ''),
isNcryptsec: (value?: string | null): value is Note => /^ncryptsec1[a-z\d]+$/.test(value || ''),
}
Expand Down
8 changes: 4 additions & 4 deletions nip19.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { bytesToHex, concatBytes, hexToBytes } from '@noble/hashes/utils'
import { bech32 } from '@scure/base'

import { utf8Decoder, utf8Encoder } from './utils.ts'
import { NAddress, NEvent, Note, NProfile, NPublic, NRelay, NSecret } from './core.ts'
import { NAddr, NEvent, Note, NProfile, NPub, NRelay, NSec } from './core.ts'

export const Bech32MaxSize = 5000

Expand Down Expand Up @@ -159,11 +159,11 @@ function parseTLV(data: Uint8Array): TLV {
return result
}

export function nsecEncode(key: Uint8Array): NSecret {
export function nsecEncode(key: Uint8Array): NSec {
return encodeBytes('nsec', key)
}

export function npubEncode(hex: string): NPublic {
export function npubEncode(hex: string): NPub {
return encodeBytes('npub', hexToBytes(hex))
}

Expand Down Expand Up @@ -204,7 +204,7 @@ export function neventEncode(event: EventPointer): NEvent {
return encodeBech32('nevent', data)
}

export function naddrEncode(addr: AddressPointer): NAddress {
export function naddrEncode(addr: AddressPointer): NAddr {
let kind = new ArrayBuffer(4)
new DataView(kind).setUint32(0, addr.kind, false)

Expand Down

0 comments on commit 5c620ba

Please sign in to comment.