pubky / pkarr

Public Key Addressable Resource Records (sovereign TLDs)
https://app.pkarr.org
MIT License
153 stars 17 forks source link

Rust - Wrong public key when calling `relay_get` #32

Closed zrus closed 10 months ago

zrus commented 10 months ago

Brief

When I use relay_get with my public_key that I just put. I see in the implementation will use format_relay_url to make my public_key to_z32 as zbase32 String. The issue is: When calling relay_get with that public_key the key now is totally different from the key that passed as path of api request in the web demo. And, I can get my record via the web demo using my public_key which didn't be to_z32ed.

E.g: my public_key is x748s37789udakuuchh793ybk5mnrpdue5uo648idomaw7qqkw5o which turned into pn5xw633pn5xw633pn5xw633pn5xw633pn5xw633pn5xw633pn5q by using to_z32.

Reality

Expectation

Work as the web demo.

Suggestion

Remove the to_z32 when calling format_relay_url in relay_get.

Nuhvi commented 10 months ago

@zrus I am a bit confused because all string representations of public keys are z-base32, I am not sure how did you get "pn5xw633pn5xw633pn5xw633pn5xw633pn5xw633pn5xw633pn5q"?

You can see the code working in this example:

        println!("\nResolving pk:{}...\n", keypair);
        let reader = PkarrClient::new();

        let instant = Instant::now();

        let signed_packet = reader
            .relay_get(
                &Url::parse(DEFAULT_PKARR_RELAY).unwrap(),
                "x748s37789udakuuchh793ybk5mnrpdue5uo648idomaw7qqkw5o"
                    .try_into()
                    .unwrap(),
            )
            .await?;

        println!("Resolved {:?} \n{}", instant.elapsed(), signed_packet);

In the code above, I use try_into() to convert the z32 string to a public key.

While I think the code is working as expected, there might be a documentation problem or insufficient examples, or need for a CLI, so please suggest how can I make this better.

That being said, I am mostly focused on making a Rust Mainline implementation at the moment, so these enhancement will have less priority, but I will always be responsive to issues like this.

zrus commented 10 months ago

@zrus I am a bit confused because all string representations of public keys are z-base32, I am not sure how did you get "pn5xw633pn5xw633pn5xw633pn5xw633pn5xw633pn5xw633pn5q"?

Is x748s37789udakuuchh793ybk5mnrpdue5uo648idomaw7qqkw5o already in z-base32 format? If so, I might have misunderstood. I once again turn x748s37789udakuuchh793ybk5mnrpdue5uo648idomaw7qqkw5o into z-base32 somewhere in my flow.

Thank you for you quick response.