npub.signer.ts raw
1 import { ISigner } from '@/types'
2 import { nip19 } from 'nostr-tools'
3
4 export class NpubSigner implements ISigner {
5 private pubkey: string | null = null
6
7 login(npub: string) {
8 const { type, data } = nip19.decode(npub)
9 if (type !== 'npub') {
10 throw new Error('invalid nsec')
11 }
12 this.pubkey = data
13 return this.pubkey
14 }
15
16 async getPublicKey() {
17 if (!this.pubkey) {
18 throw new Error('Not logged in')
19 }
20 return this.pubkey
21 }
22
23 async signEvent(): Promise<any> {
24 throw new Error('Not logged in')
25 }
26
27 async nip04Encrypt(): Promise<any> {
28 throw new Error('Not logged in')
29 }
30
31 async nip04Decrypt(): Promise<any> {
32 throw new Error('Not logged in')
33 }
34 }
35