allow using nip05 to sign from the client too

This commit is contained in:
Pablo Fernandez 2024-01-02 14:46:24 +00:00
parent d9c07c0115
commit bfcb0992d4
3 changed files with 14 additions and 3 deletions

View File

@ -41,7 +41,7 @@ In the background, the bunker will have configured the requested NIP-05 mapping
``` ```
## NIP-89 ## NIP-89
Bunkers supporting user registration can announce themselves using NIP-89's `kind:31990`. Clients SHOULD validate that the 31990 is from a pubkey that owns the root NIP-05 of the domain. Bunkers supporting user registration can announce themselves using NIP-89's `kind:31990`. Clients MUST validate that the 31990 is from a pubkey that owns the root NIP-05 of the domain.
```json ```json
{ {

View File

@ -85,7 +85,18 @@ function loadPrivateKey(): string | undefined {
remoteUser = u; remoteUser = u;
remotePubkey = remoteUser.pubkey; remotePubkey = remoteUser.pubkey;
} else { } else {
remoteUser = new NDKUser({npub: remotePubkey}); // check if we have a @ so we try to get the npub from nip05
if (remotePubkey.includes('@')) {
const u = await NDKUser.fromNip05(remotePubkey);
if (!u) {
console.log(`Invalid nip05 ${remotePubkey}`);
process.exit(1);
}
remoteUser = u;
remotePubkey = remoteUser.pubkey;
} else {
remoteUser = new NDKUser({npub: remotePubkey});
}
} }
ndk = await createNDK(); ndk = await createNDK();

View File

@ -19,7 +19,7 @@ export async function validateRegistration(request, record) {
if (!email.includes("@")) throw new Error("Invalid email address"); if (!email.includes("@")) throw new Error("Invalid email address");
// validate email uniqueness (if one was provided) // validate email uniqueness (if one was provided)
const emailRecord = await prisma.user.findUnique({ where: { email } }); const emailRecord = await prisma.user.findFirst({ where: { email } });
if (emailRecord) throw new Error("Email already exists"); if (emailRecord) throw new Error("Email already exists");
} }
} }