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

auth() method in the style of LNURL Auth #57

Open
wbobeirne opened this issue Jun 27, 2023 · 0 comments
Open

auth() method in the style of LNURL Auth #57

wbobeirne opened this issue Jun 27, 2023 · 0 comments

Comments

@wbobeirne
Copy link
Member

To simplify auth implementations for JS-centric clients, it would make sense for WebLN to have an auth() method that follows the same spec as LNURL's LUD-04, but have the back-and-forth happen entirely on the client via JS rather than requiring a server-side component be implemented using long polling or websockets. This would hopefully make for a much easier implementation.

The implementation would look something like this, matching LUD-04:

type AuthAction = 'register' | 'login' | 'link' | 'auth';

function auth(k1: string, action?: AuthAction): Promise<{ sig: string; key: string; }>;

And an implementation would look something like this:

import { requestProvider } from "webln"

async function register(username: string) {
  // Initiailize WebLN
  const webln = await requestProvider();
  await webln.enable();

  // Auth with WebLN
  const k1 = await generateChallengeHex(); // Your custom implementation here
  const { sig, key } = await webln.auth(k1, "register");

  // Send auth information to your backend
  fetch("/api/register", {
    method: "POST",
    body: JSON.stringify({
      k1,
      sig,
      key,
      username,
    }),
  })
}

I have not personally implemented an LNURL auth flow end to end, so I'd love to hear from folks who have on if there are any other considerations we could add to the WebLN implementation that would improve the developer experience.

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