From 7dbd86eb5ced8c5db93d5b6d0c0f9fedcfe6a4db Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 12 May 2025 05:23:54 -0300 Subject: [PATCH] fix types from latest nip19 type change. --- nip17.test.ts | 2 +- nip21.ts | 28 ++++++++++++++++++++++++++-- nip59.test.ts | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/nip17.test.ts b/nip17.test.ts index ac7eaf0..87f848e 100644 --- a/nip17.test.ts +++ b/nip17.test.ts @@ -4,7 +4,7 @@ import { decode } from './nip19.ts' import { wrapEvent, wrapManyEvents, unwrapEvent } from './nip17.ts' import { hexToBytes } from '@noble/hashes/utils' -const senderPrivateKey = decode(`nsec1p0ht6p3wepe47sjrgesyn4m50m6avk2waqudu9rl324cg2c4ufesyp6rdg`).data +const senderPrivateKey = decode(`nsec1p0ht6p3wepe47sjrgesyn4m50m6avk2waqudu9rl324cg2c4ufesyp6rdg`).data as Uint8Array const sk1 = hexToBytes('f09ac9b695d0a4c6daa418fe95b977eea20f54d9545592bc36a4f9e14f3eb840') const sk2 = hexToBytes('5393a825e5892d8e18d4a5ea61ced105e8bb2a106f42876be3a40522e0b13747') diff --git a/nip21.ts b/nip21.ts index 63e0464..fd79123 100644 --- a/nip21.ts +++ b/nip21.ts @@ -1,4 +1,4 @@ -import { BECH32_REGEX, decode, type DecodeResult } from './nip19.ts' +import { AddressPointer, BECH32_REGEX, decode, EventPointer, ProfilePointer } from './nip19.ts' /** Nostr URI regex, eg `nostr:npub1...` */ export const NOSTR_URI_REGEX: RegExp = new RegExp(`nostr:(${BECH32_REGEX.source})`) @@ -15,7 +15,31 @@ export interface NostrURI { /** The bech32-encoded data (eg `npub1...`). */ value: string /** Decoded bech32 string, according to NIP-19. */ - decoded: DecodeResult + decoded: + | { + type: 'nevent' + data: EventPointer + } + | { + type: 'nprofile' + data: ProfilePointer + } + | { + type: 'naddr' + data: AddressPointer + } + | { + type: 'npub' + data: string + } + | { + type: 'nsec' + data: Uint8Array + } + | { + type: 'note' + data: string + } } /** Parse and decode a Nostr URI. */ diff --git a/nip59.test.ts b/nip59.test.ts index fba153f..1e1b4ad 100644 --- a/nip59.test.ts +++ b/nip59.test.ts @@ -6,8 +6,8 @@ import { SimplePool } from './pool.ts' import { GiftWrap } from './kinds.ts' import { hexToBytes } from '@noble/hashes/utils' -const senderPrivateKey = decode(`nsec1p0ht6p3wepe47sjrgesyn4m50m6avk2waqudu9rl324cg2c4ufesyp6rdg`).data -const recipientPrivateKey = decode(`nsec1uyyrnx7cgfp40fcskcr2urqnzekc20fj0er6de0q8qvhx34ahazsvs9p36`).data +const senderPrivateKey = decode(`nsec1p0ht6p3wepe47sjrgesyn4m50m6avk2waqudu9rl324cg2c4ufesyp6rdg`).data as Uint8Array +const recipientPrivateKey = decode(`nsec1uyyrnx7cgfp40fcskcr2urqnzekc20fj0er6de0q8qvhx34ahazsvs9p36`).data as Uint8Array const recipientPublicKey = getPublicKey(recipientPrivateKey) const event = { kind: 1,