diff --git a/core.test.ts b/core.test.ts index 3260af3..5ae8224 100644 --- a/core.test.ts +++ b/core.test.ts @@ -78,7 +78,7 @@ test('NostrTypeGuard isNEvent with invalid nevent', () => { }) test('NostrTypeGuard isNAddress', () => { - const is = NostrTypeGuard.isNAddress( + const is = NostrTypeGuard.isNAddr( 'naddr1qqxnzdesxqmnxvpexqunzvpcqyt8wumn8ghj7un9d3shjtnwdaehgu3wvfskueqzypve7elhmamff3sr5mgxxms4a0rppkmhmn7504h96pfcdkpplvl2jqcyqqq823cnmhuld', ) @@ -86,43 +86,43 @@ test('NostrTypeGuard isNAddress', () => { }) 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() }) diff --git a/core.ts b/core.ts index a7b0bf0..82b26d7 100644 --- a/core.ts +++ b/core.ts @@ -26,9 +26,9 @@ export type UnsignedEvent = Pick /^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 || ''), } diff --git a/nip19.ts b/nip19.ts index 045bdd0..ddcfef7 100644 --- a/nip19.ts +++ b/nip19.ts @@ -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 @@ -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)) } @@ -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)