Compare commits

...

7 Commits

Author SHA1 Message Date
b
2cdcfd7ca7 Merge branch 'main' into improve-verification 2024-05-24 09:27:46 +00:00
b
9caba52f7d Merge pull request 'Login with NSEC and HEX private key formats. Proper errors.' (#66) from issue-45 into main
Some checks failed
Release / build_and_release (push) Failing after 37s
Reviewed-on: https://git.sigit.io/sig/it/pulls/66
Reviewed-by: Y <yury@4gl.io>
2024-05-24 08:35:33 +00:00
Davinci
555d8bedca chore(git): Merge branch 'main' into issue-45 2024-05-24 08:52:29 +02:00
Davinci
e501f99729 chore: removed commented code 2024-05-24 08:51:59 +02:00
Davinci
dada1eebc5 chore: label fix 2024-05-22 12:31:00 +02:00
Davinci
35bd6d3688 style: lint 2024-05-22 12:08:12 +02:00
Davinci
213ae79bf5 fix: login with hex key does not work, missing proper error when nsec or private key is wrong 2024-05-22 12:08:02 +02:00
2 changed files with 45 additions and 9 deletions

View File

@ -20,6 +20,7 @@ import { LoginMethods } from '../../store/auth/types'
import { Dispatch } from '../../store/store' import { Dispatch } from '../../store/store'
import { npubToHex, queryNip05 } from '../../utils' import { npubToHex, queryNip05 } from '../../utils'
import styles from './style.module.scss' import styles from './style.module.scss'
import { hexToBytes } from '@noble/hashes/utils'
export const Login = () => { export const Login = () => {
const [searchParams] = useSearchParams() const [searchParams] = useSearchParams()
@ -92,9 +93,24 @@ export const Login = () => {
}) })
} }
const loginWithNsec = async () => { /**
const nsec = inputValue * Login with NSEC or HEX private key
const privateKey = nip19.decode(nsec).data as Uint8Array * @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) { if (!privateKey) {
toast.error( toast.error(
@ -307,7 +323,19 @@ export const Login = () => {
return loginWithNsecBunker() 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 return
} }
@ -329,7 +357,7 @@ export const Login = () => {
<Typography variant="h4">Welcome to Sigit</Typography> <Typography variant="h4">Welcome to Sigit</Typography>
<TextField <TextField
onKeyDown={handleInputKeyDown} onKeyDown={handleInputKeyDown}
label="nip05 login / nip46 bunker string / nsec" label="nip05 login / nip46 bunker string"
value={inputValue} value={inputValue}
onChange={(e) => setInputValue(e.target.value)} onChange={(e) => setInputValue(e.target.value)}
sx={{ width: '100%', mt: 2 }} sx={{ width: '100%', mt: 2 }}

View File

@ -240,11 +240,19 @@ export const ProfilePage = () => {
</Box> </Box>
<Box> <Box>
{profileMetadata?.nip05 && {profileMetadata?.nip05 &&
textElementWithCopyIcon(profileMetadata.nip05, undefined, 15)} textElementWithCopyIcon(
profileMetadata.nip05,
undefined,
15
)}
</Box> </Box>
<Box> <Box>
{profileMetadata?.lud16 && {profileMetadata?.lud16 &&
textElementWithCopyIcon(profileMetadata.lud16, undefined, 15)} textElementWithCopyIcon(
profileMetadata.lud16,
undefined,
15
)}
</Box> </Box>
</Box> </Box>