Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nip19: Custom checksum with usize::MAX limit for bech32 decoding #785

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TheAwiteb
Copy link
Contributor

@TheAwiteb TheAwiteb commented Feb 28, 2025

Related: #723

Description

This patch introduces a custom checksum with a usize::MAX limit instead of the
previous limit of 1023.

Before this patch, the following code would not work. Now it works as expected:

use nostr::prelude::*;

const NPROFILE: &str = "...";

fn main() {
    let nprofile = Nip19Profile::from_bech32(NPROFILE).unwrap();
    println!("{}", nprofile.public_key);
    for (idx, relay) in nprofile.relays.iter().enumerate() {
        println!("{idx}: {relay}");
    }
}

Output:

Public Key: 813fce4c4e76f1e7b4f4697bf1030a90f1a0b783f187d329800a4dd8697f9759
0: wss://brb.io/
1: wss://brb.io/
2: wss://eden.nostr.land/
3: wss://eden.nostr.land/
4: wss://nos.lol/
5: wss://nos.lol/
6: wss://nostr-pub.wellorder.net/
7: wss://nostr-pub.wellorder.net/
8: wss://nostr.bitcoiner.social/
9: wss://nostr.fmt.wiz.biz/
10: wss://nostr.fmt.wiz.biz/
11: wss://nostr.relayer.se/
12: wss://nostr.relayer.se/
13: wss://nostr.wine/
14: wss://nostr.x0f.org/
15: wss://offchain.pub/
16: wss://offchain.pub/
17: wss://relay.current.fyi/
18: wss://relay.current.fyi/
19: wss://relay.damus.io/
20: wss://relay.damus.io/
21: wss://relay.mostr.pub/
22: wss://relay.nostr.band/
23: wss://relay.nostr.info/
24: wss://relay.nostr.info/
25: wss://relay.noswhere.com/
26: wss://relay.primal.net/
27: wss://relay.snort.social/
28: wss://relay.snort.social/

Notes to the reviewers

Why not encoding? I tried, but it produce a different nprofile, so I implemented decoding only.

Checklist

@TheAwiteb TheAwiteb changed the title Implement Custom Checksum with usize::MAX Limit for Nip19Profile Decoding nip19: Implement Custom Checksum with usize::MAX Limit for bech32 Decoding Feb 28, 2025
@TheAwiteb TheAwiteb changed the title nip19: Implement Custom Checksum with usize::MAX Limit for bech32 Decoding nip19: Custom checksum with usize::MAX limit for bech32 decoding Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant