feat: nip55
This commit is contained in:
@ -105,6 +105,7 @@
|
||||
"@types/webtorrent": "^0.109.3",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"@typescript-eslint/parser": "^6.1.0",
|
||||
"@vitejs/plugin-basic-ssl": "^1.2.0",
|
||||
"@vitejs/plugin-react": "^4.2.0",
|
||||
"@webbtc/webln-types": "^3.0.0",
|
||||
"@webscopeio/react-textarea-autocomplete": "^4.9.2",
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { unwrap } from "@snort/shared";
|
||||
import { NotEncrypted } from "@snort/system";
|
||||
import { Nip7Signer, Nip55Signer, NotEncrypted } from "@snort/system";
|
||||
import { SnortContext } from "@snort/system-react";
|
||||
import classNames from "classnames";
|
||||
import { FormEvent, useContext, useState } from "react";
|
||||
@ -16,6 +15,8 @@ import { NewUserState } from ".";
|
||||
|
||||
const NSEC_NPUB_REGEX = /(nsec1|npub1)[a-zA-Z0-9]{20,65}/gi;
|
||||
|
||||
const signer = new Nip55Signer();
|
||||
|
||||
export function SignIn() {
|
||||
const navigate = useNavigate();
|
||||
const { formatMessage } = useIntl();
|
||||
@ -25,15 +26,23 @@ export function SignIn() {
|
||||
const loginHandler = useLoginHandler();
|
||||
|
||||
const hasNip7 = "nostr" in window;
|
||||
const hasNip55 = true;
|
||||
|
||||
async function doNip07Login() {
|
||||
/*const relays =
|
||||
"getRelays" in unwrap(window.nostr) ? await unwrap(window.nostr?.getRelays).call(window.nostr) : undefined;*/
|
||||
const pubKey = await unwrap(window.nostr).getPublicKey();
|
||||
const signer = new Nip7Signer();
|
||||
const pubKey = await signer.getPubKey();
|
||||
LoginStore.loginWithPubkey(pubKey, LoginSessionType.Nip7);
|
||||
trackEvent("Login", { type: "NIP7" });
|
||||
navigate("/");
|
||||
}
|
||||
|
||||
async function doNip55Login() {
|
||||
const pubKey = await signer.getPubKey();
|
||||
LoginStore.loginWithPubkey(pubKey, LoginSessionType.Nip55);
|
||||
trackEvent("Login", { type: "NIP55" });
|
||||
navigate("/");
|
||||
}
|
||||
|
||||
async function onSubmit(e) {
|
||||
e.preventDefault();
|
||||
doLogin(key);
|
||||
@ -69,7 +78,7 @@ export function SignIn() {
|
||||
}
|
||||
};
|
||||
|
||||
const nip7Login = hasNip7 && !useKey;
|
||||
const signerExtLogin = (hasNip7 || hasNip55) && !useKey;
|
||||
return (
|
||||
<div className="flex flex-col g24">
|
||||
<img src={CONFIG.icon} width={48} height={48} className="br mr-auto ml-auto" />
|
||||
@ -77,10 +86,10 @@ export function SignIn() {
|
||||
<h1>
|
||||
<FormattedMessage defaultMessage="Sign In" />
|
||||
</h1>
|
||||
{nip7Login && <FormattedMessage defaultMessage="Use a nostr signer extension to sign in" />}
|
||||
{signerExtLogin && <FormattedMessage defaultMessage="Use a nostr signer extension to sign in" />}
|
||||
</div>
|
||||
<div className={classNames("flex flex-col g16", { "items-center": nip7Login })}>
|
||||
{hasNip7 && !useKey && (
|
||||
<div className={classNames("flex flex-col g16", { "items-center": signerExtLogin })}>
|
||||
{signerExtLogin && (
|
||||
<>
|
||||
<AsyncButton onClick={doNip07Login}>
|
||||
<div className="circle bg-warning p12 text-white">
|
||||
@ -88,6 +97,12 @@ export function SignIn() {
|
||||
</div>
|
||||
<FormattedMessage defaultMessage="Sign in with Nostr Extension" />
|
||||
</AsyncButton>
|
||||
<AsyncButton onClick={doNip55Login}>
|
||||
<div className="circle bg-warning p12 text-white">
|
||||
<Icon name="key" />
|
||||
</div>
|
||||
<FormattedMessage defaultMessage="Sign in with Android signer" />
|
||||
</AsyncButton>
|
||||
<Link to="" className="highlight">
|
||||
<FormattedMessage defaultMessage="Supported Extensions" />
|
||||
</Link>
|
||||
@ -96,13 +111,12 @@ export function SignIn() {
|
||||
</AsyncButton>
|
||||
</>
|
||||
)}
|
||||
{(!hasNip7 || useKey) && (
|
||||
{(!signerExtLogin || useKey) && (
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder={formatMessage({
|
||||
defaultMessage: "nsec, npub, nip-05, hex, mnemonic",
|
||||
id: "X7xU8J",
|
||||
})}
|
||||
value={key}
|
||||
onChange={onChange}
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
KeyStorage,
|
||||
Nip7Signer,
|
||||
Nip46Signer,
|
||||
Nip55Signer,
|
||||
PrivateKeySigner,
|
||||
RelaySettings,
|
||||
SystemInterface,
|
||||
@ -157,5 +158,8 @@ export function createPublisher(l: LoginSession) {
|
||||
case LoginSessionType.Nip7: {
|
||||
return new EventPublisher(new Nip7Signer(), unwrap(l.publicKey));
|
||||
}
|
||||
case LoginSessionType.Nip55: {
|
||||
return new EventPublisher(new Nip55Signer(), unwrap(l.publicKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ export const enum LoginSessionType {
|
||||
Nip7 = "nip7",
|
||||
Nip46 = "nip46",
|
||||
Nip7os = "nip7_os",
|
||||
Nip55 = "nip55",
|
||||
}
|
||||
|
||||
export interface SnortAppData {
|
||||
|
@ -876,6 +876,9 @@
|
||||
"J2Q92B": {
|
||||
"defaultMessage": "Emoji sets"
|
||||
},
|
||||
"J6N9xl": {
|
||||
"defaultMessage": "Sign in with Android signer"
|
||||
},
|
||||
"JCIgkj": {
|
||||
"defaultMessage": "Username"
|
||||
},
|
||||
|
@ -290,6 +290,7 @@
|
||||
"J1iLmb": "Notifications Not Allowed",
|
||||
"J2HeQ+": "Use commas to separate words e.g. word1, word2, word3",
|
||||
"J2Q92B": "Emoji sets",
|
||||
"J6N9xl": "Sign in with Android signer",
|
||||
"JCIgkj": "Username",
|
||||
"JGrt9q": "Send sats to {name}",
|
||||
"JHEHCk": "Zaps ({n})",
|
||||
|
@ -1,3 +1,4 @@
|
||||
import basicSsl from "@vitejs/plugin-basic-ssl";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import appConfig from "config";
|
||||
import { visualizer } from "rollup-plugin-visualizer";
|
||||
@ -7,6 +8,7 @@ import { vitePluginVersionMark } from "vite-plugin-version-mark";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
basicSsl(),
|
||||
react({
|
||||
jsxImportSource: "@welldone-software/why-did-you-render",
|
||||
babel: {
|
||||
|
Reference in New Issue
Block a user