-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support login via nip07 extension - allows user login from nostr nip07 extension without providing private keys * users can paste and reuse private keys * ignore window.nostr typecheck
- Loading branch information
Showing
18 changed files
with
1,998 additions
and
983 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
frontend/src/components/ui/auth/login-container/login-container.stories.tsx
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
frontend/src/components/ui/auth/login-container/login-container.tsx
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
frontend/src/components/ui/auth/login-container/login-form.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import dayjs from "dayjs"; | ||
import { nip19, nip04, relayInit } from "nostr-tools"; | ||
|
||
import { api } from "~/config"; | ||
|
||
export const relay = relayInit(process.env.NEXT_PUBLIC_FUSION_RELAY_URL!); | ||
relay.on("connect", () => { | ||
console.log(`connected to ${relay.url}`); | ||
}); | ||
relay.on("error", () => { | ||
console.log(`failed to connect to ${relay.url}`); | ||
}); | ||
|
||
interface AuthResponse { | ||
userNpub: string; | ||
authToken: string; | ||
} | ||
|
||
class AuthService { | ||
async completeNostrLogin(publicKey: string, privateKey?: string): Promise<AuthResponse | null> { | ||
const serverPublicKey = process.env.NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY; | ||
|
||
try { | ||
const loginTimestamp = dayjs().unix(); | ||
let sub = relay.sub([ | ||
{ | ||
authors: [serverPublicKey!], | ||
kinds: [4], | ||
"#p": [publicKey], | ||
since: loginTimestamp, | ||
}, | ||
]); | ||
|
||
const res = await api.post(`/nostrlogin`, { pubkey: publicKey }); | ||
const authToken: string = await (async () => { | ||
return new Promise((resolve) => { | ||
sub.on("event", async (event) => { | ||
// @ts-ignore | ||
const decoded = privateKey ? await nip04.decrypt(privateKey, serverPublicKey!, event.content) : await window.nostr?.nip04.decrypt(serverPublicKey!, event.content); | ||
resolve(decoded); | ||
}); | ||
}); | ||
})(); | ||
|
||
if (res.status == 200 && authToken) { | ||
return { | ||
userNpub: nip19.npubEncode(publicKey), | ||
authToken: authToken, | ||
}; | ||
} else { | ||
return null; | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
export const authService = Object.freeze(new AuthService()); |
Oops, something went wrong.
a73a6b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
fusion – ./
fusion-git-master-neurofusion-research-inc.vercel.app
fusion-neurofusion-research-inc.vercel.app
usefusion.app
www.usefusion.app