allow for nip19 for account

This commit is contained in:
Tiago Vasconcelos 2023-03-13 15:48:32 +00:00
parent b7d091cf84
commit 0fe9712b45
2 changed files with 14 additions and 6 deletions

View file

@ -91,9 +91,12 @@ const market = async () => {
return window.nostr return window.nostr
}, },
isValidKey() { isValidKey() {
return this.accountDialog.data.key let key = this.accountDialog.data.key
?.toLowerCase() if (key && key.startsWith('n')) {
?.match(/^[0-9a-f]{64}$/) let {type, data} = NostrTools.nip19.decode(key)
key = data
}
return key?.toLowerCase()?.match(/^[0-9a-f]{64}$/)
} }
}, },
async created() { async created() {
@ -176,6 +179,10 @@ const market = async () => {
} }
if (this.isValidKey) { if (this.isValidKey) {
let {key, watchOnly} = this.accountDialog.data let {key, watchOnly} = this.accountDialog.data
if (key.startsWith('n')) {
let {type, data} = NostrTools.nip19.decode(key)
key = data
}
this.$q.localStorage.set('diagonAlley.account', { this.$q.localStorage.set('diagonAlley.account', {
privkey: watchOnly ? null : key, privkey: watchOnly ? null : key,
pubkey: watchOnly ? key : NostrTools.getPublicKey(key), pubkey: watchOnly ? key : NostrTools.getPublicKey(key),
@ -247,7 +254,7 @@ const market = async () => {
this.events.map(eventToObj).map(e => { this.events.map(eventToObj).map(e => {
if (e.kind == 0) { if (e.kind == 0) {
this.profiles.set(e.pubkey, e.content) this.profiles.set(e.pubkey, e.content)
if (e.pubkey == this.account.pubkey) { if (e.pubkey == this.account?.pubkey) {
this.accountMetadata = this.profiles.get(this.account.pubkey) this.accountMetadata = this.profiles.get(this.account.pubkey)
} }
return return

View file

@ -216,11 +216,12 @@
<q-card-section class="q-pt-none"> <q-card-section class="q-pt-none">
<q-input <q-input
dense dense
label="Private key (hex)" label="nsec/npub/hex"
v-model="accountDialog.data.key" v-model="accountDialog.data.key"
autofocus autofocus
@keyup.enter="createAccount" @keyup.enter="createAccount"
:error="!isValidKey" :error="accountDialog.data.key && !isValidKey"
hint="Enter you private key (recommended) or public key"
></q-input> ></q-input>
<q-item tag="label"> <q-item tag="label">