From 56fe3dd5dde4285dde08be52586593062b93d822 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 17 Apr 2023 20:53:19 -0400 Subject: [PATCH] nip19: improve return type --- nip19.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nip19.ts b/nip19.ts index 8780312..ff370eb 100644 --- a/nip19.ts +++ b/nip19.ts @@ -23,10 +23,15 @@ export type AddressPointer = { relays?: string[] } -export function decode(nip19: string): { - type: string - data: ProfilePointer | EventPointer | AddressPointer | string -} { +export type DecodeResult = + | {type: 'nprofile'; data: ProfilePointer} + | {type: 'nevent'; data: EventPointer} + | {type: 'naddr'; data: AddressPointer} + | {type: 'nsec'; data: string} + | {type: 'npub'; data: string} + | {type: 'note'; data: string} + +export function decode(nip19: string): DecodeResult { let {prefix, words} = bech32.decode(nip19, Bech32MaxSize) let data = new Uint8Array(bech32.fromWords(words))