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

bug: NDKUser getZapInfo its failling #272

Open
gzuuus opened this issue Sep 20, 2024 · 1 comment
Open

bug: NDKUser getZapInfo its failling #272

gzuuus opened this issue Sep 20, 2024 · 1 comment

Comments

@gzuuus
Copy link
Contributor

gzuuus commented Sep 20, 2024

I was testing the getZapInfo method with a profile that only has LUD06 and no LUD16, and it threw the following error:

Error getting NIP-57 zap spec Error: Unable to fetch zap endpoint https://undefined/.well-known/lnurlp/ : TypeError: Failed to fetch

Upon inspecting the code, I noticed that the method getNip57ZapSpecFromLud should not have fallen into the conditional case for LUD16 since the user I was trying to retrieve zap info from has an explicit LUD06 value (lud06 : "LNURL1DP68GURN8GHJ7ER9D4HJUMRWVF5HGUEWVDHK6TMVDE6HYMRS9A2K552DW9QS4J8WR2") and an empty string for lud16 (lud16 : " ").

    if (lud16 && !lud16.startsWith("LNURL")) {
        const [name, domain] = lud16.split("@");
        zapEndpoint = `https://${domain}/.well-known/lnurlp/${name}`;
    } else if (lud06) {
        const { words } = bech32.decode(lud06, 1000);
        const data = bech32.fromWords(words);
        const utf8Decoder = new TextDecoder("utf-8");
        zapEndpoint = utf8Decoder.decode(data);
    }

This issue occurs because the profileFromEvent function is not parsing the payload correctly.

  case "lud06":
      profile.lud06 = payload.lud06;
      break;
  case "lud16":
      profile.lud16 = payload.lud16;
      break;

It might be helpful to add .trim() to detect falsy inputs.

@gzuuus
Copy link
Contributor Author

gzuuus commented Sep 20, 2024

I was testing with more ill formed data and getZapInfo throws the same error. Would be nice to improve the robustness of the method
Ill formed data example:

    "lud06": "a9f7fd5eb16e17ae99fdf72dfbefbbe501de1aca49ba821391ace30014c1b9ed",
    "lud16": "fefdcc30b309de6eeda10ac1dfb40cc4afd67bac1ddc0c2fbbd6ada7eb6e6ada",

We can use a regex to test the LUD16 ln address

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

No branches or pull requests

1 participant