increase bech32 max size to 5000.

This commit is contained in:
fiatjaf 2023-01-18 17:31:37 -03:00
parent fa9e169c46
commit cb05ee188f
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 7 additions and 5 deletions

View File

@ -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 {

View File

@ -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",