mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 05:54:19 +01:00
fix: throw error if NIP-19 has invalid id
This commit is contained in:
@@ -179,6 +179,10 @@ describe('parseTextNote', () => {
|
||||
'npub1a',
|
||||
'npub133vj8ycevdle0cq8mtgddq0xtn34kxkwxvak983dx0u5vhqnycyqj6tcz1',
|
||||
'npub133vj8ycevdle0cq8mtgddq0xtn34kxkwxvak983dx0u5vhqnycyqj6tczb',
|
||||
// bech32 problem: checksum cannot detect arbitrary number of 'q' before 'p'
|
||||
'npub1harpehyplx66gzpsskwzejtwgm45zenlzr4md58lxrvsvllupe8qunwsqqqqqqqqp',
|
||||
// bech32 problem: checksum cannot detect deletion of 'q' in 'qp'
|
||||
'npub1harpehyplx66gzpsskwzejtwgm45zenlzr4md58lxrvsvllupe8qunwsp',
|
||||
])('should parse text note which includes invalid npub string (%s)', (invalidPubkey) => {
|
||||
const content = `this is pubkey\n${invalidPubkey}\nhello`;
|
||||
const parsed = parseTextNote(content);
|
||||
|
||||
@@ -151,6 +151,15 @@ const parseTextNote = (textNoteContent: string) => {
|
||||
data: decoded,
|
||||
isNIP19: match.groups.nip19 === 'nostr:',
|
||||
};
|
||||
if (
|
||||
((decoded.type === 'npub' || decoded.type === 'note') && !isValidId(decoded.data)) ||
|
||||
(decoded.type === 'nprofile' && !isValidId(decoded.data.pubkey)) ||
|
||||
(decoded.type === 'nevent' && !isValidId(decoded.data.id)) ||
|
||||
(decoded.type === 'naddr' && !isValidId(decoded.data.pubkey)) ||
|
||||
(decoded.type === 'nsec' && decoded.data.length !== 32)
|
||||
) {
|
||||
throw new Error('Invalid ID');
|
||||
}
|
||||
result.push(bech32Entity);
|
||||
} catch (e) {
|
||||
console.warn(`ignored invalid bech32 entity: ${match[0]}`);
|
||||
|
||||
Reference in New Issue
Block a user