From cb05ee188f18e13f5c93b0c1ca40afb482e12b10 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 18 Jan 2023 17:31:37 -0300 Subject: [PATCH] increase bech32 max size to 5000. --- nip19.ts | 10 ++++++---- package.json | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nip19.ts b/nip19.ts index ef92eb6..8346d3a 100644 --- a/nip19.ts +++ b/nip19.ts @@ -3,6 +3,8 @@ import {bech32} from '@scure/base' import {utf8Decoder, utf8Encoder} from './utils' +const Bech32MaxSize = 5000 + export type ProfilePointer = { pubkey: string // hex relays?: string[] @@ -17,7 +19,7 @@ export function decode(nip19: string): { type: string data: ProfilePointer | EventPointer | string } { - let {prefix, words} = bech32.decode(nip19, 1500) + let {prefix, words} = bech32.decode(nip19, Bech32MaxSize) let data = new Uint8Array(bech32.fromWords(words)) if (prefix === 'nprofile') { @@ -87,7 +89,7 @@ export function noteEncode(hex: string): string { function encodeBytes(prefix: string, hex: string): string { let data = secp256k1.utils.hexToBytes(hex) let words = bech32.toWords(data) - return bech32.encode(prefix, words, 1500) + return bech32.encode(prefix, words, Bech32MaxSize) } export function nprofileEncode(profile: ProfilePointer): string { @@ -96,7 +98,7 @@ export function nprofileEncode(profile: ProfilePointer): string { 1: (profile.relays || []).map(url => utf8Encoder.encode(url)) }) let words = bech32.toWords(data) - return bech32.encode('nprofile', words, 1500) + return bech32.encode('nprofile', words, Bech32MaxSize) } export function neventEncode(event: EventPointer): string { @@ -105,7 +107,7 @@ export function neventEncode(event: EventPointer): string { 1: (event.relays || []).map(url => utf8Encoder.encode(url)) }) let words = bech32.toWords(data) - return bech32.encode('nevent', words, 1500) + return bech32.encode('nevent', words, Bech32MaxSize) } function encodeTLV(tlv: TLV): Uint8Array { diff --git a/package.json b/package.json index 51f4074..53150b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nostr-tools", - "version": "1.1.1", + "version": "1.1.2", "description": "Tools for making a Nostr client.", "repository": { "type": "git",