diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx
index 9c224b7..8c2f702 100644
--- a/src/pages/login/index.tsx
+++ b/src/pages/login/index.tsx
@@ -20,6 +20,7 @@ import { LoginMethods } from '../../store/auth/types'
import { Dispatch } from '../../store/store'
import { npubToHex, queryNip05 } from '../../utils'
import styles from './style.module.scss'
+import { hexToBytes } from '@noble/hashes/utils'
export const Login = () => {
const [searchParams] = useSearchParams()
@@ -92,9 +93,24 @@ export const Login = () => {
})
}
- const loginWithNsec = async () => {
- const nsec = inputValue
- const privateKey = nip19.decode(nsec).data as Uint8Array
+ /**
+ * Login with NSEC or HEX private key
+ * @param privateKey in HEX format
+ */
+ const loginWithNsec = async (privateKey?: Uint8Array) => {
+ let nsec = ''
+
+ if (privateKey) {
+ nsec = nip19.nsecEncode(privateKey)
+ } else {
+ nsec = inputValue
+
+ try {
+ privateKey = nip19.decode(nsec).data as Uint8Array
+ } catch (err) {
+ toast.error(`Error decoding the nsec. ${err}`)
+ }
+ }
if (!privateKey) {
toast.error(
@@ -307,7 +323,19 @@ export const Login = () => {
return loginWithNsecBunker()
}
- toast.error('Invalid Input!')
+ // Check if maybe hex nsec
+ try {
+ const privateKey = hexToBytes(inputValue)
+ const publickey = getPublicKey(privateKey)
+
+ if (publickey) return loginWithNsec(privateKey)
+ } catch (err) {
+ console.warn('err', err)
+ }
+
+ toast.error(
+ 'Invalid format, please use: private key (hex), nsec..., bunker:// or nip05 format.'
+ )
return
}
@@ -329,7 +357,7 @@ export const Login = () => {
Welcome to Sigit
setInputValue(e.target.value)}
sx={{ width: '100%', mt: 2 }}
diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx
index caa5387..146dda8 100644
--- a/src/pages/profile/index.tsx
+++ b/src/pages/profile/index.tsx
@@ -208,7 +208,7 @@ export const ProfilePage = () => {
-
+
{
>
{profileMetadata && (
@@ -240,11 +240,19 @@ export const ProfilePage = () => {
{profileMetadata?.nip05 &&
- textElementWithCopyIcon(profileMetadata.nip05, undefined, 15)}
+ textElementWithCopyIcon(
+ profileMetadata.nip05,
+ undefined,
+ 15
+ )}
{profileMetadata?.lud16 &&
- textElementWithCopyIcon(profileMetadata.lud16, undefined, 15)}
+ textElementWithCopyIcon(
+ profileMetadata.lud16,
+ undefined,
+ 15
+ )}