From 24d1ff4aecc9e194d93192f9422a60288d112ad8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Jan 2024 17:26:53 -0600 Subject: [PATCH] lnurl: increase default limit to 2000 --- src/utils/lnurl.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/lnurl.ts b/src/utils/lnurl.ts index f053bc4..2d60814 100644 --- a/src/utils/lnurl.ts +++ b/src/utils/lnurl.ts @@ -1,28 +1,28 @@ import { bech32 } from '@/deps.ts'; /** Encode a URL to LNURL format. */ -function lnurlEncode(url: string): `lnurl1${string}` { +function lnurlEncode(url: string, limit = 2000): `lnurl1${string}` { const data = new TextEncoder().encode(url); const words = bech32.toWords(data); - return bech32.encode('lnurl', words); + return bech32.encode('lnurl', words, limit); } /** Decode a LNURL into a URL. */ -function lnurlDecode(lnurl: string): string { - const { prefix, words } = bech32.decode(lnurl); +function lnurlDecode(lnurl: string, limit = 2000): string { + const { prefix, words } = bech32.decode(lnurl, limit); if (prefix !== 'lnurl') throw new Error('Invalid LNURL'); const data = new Uint8Array(bech32.fromWords(words)); return new TextDecoder().decode(data); } /** Get an LNURL from a lud06 or lud16. */ -function getLnurl({ lud06, lud16 }: { lud06?: string; lud16?: string }): string | undefined { +function getLnurl({ lud06, lud16 }: { lud06?: string; lud16?: string }, limit?: number): string | undefined { if (lud06) return lud06; if (lud16) { const [name, host] = lud16.split('@'); if (name && host) { const url = new URL(`/.well-known/lnurlp/${name}`, `https://${host}`).toString(); - return lnurlEncode(url); + return lnurlEncode(url, limit); } } }