refactor: remove electron-related code

This commit is contained in:
codytseng
2024-12-21 23:20:30 +08:00
parent bed8df06e8
commit 2b1e6fe8f5
200 changed files with 2771 additions and 8432 deletions

View File

@@ -0,0 +1,35 @@
import { ISigner, TDraftEvent } from '@/types'
import { finalizeEvent, getPublicKey as nGetPublicKey, nip19 } from 'nostr-tools'
export class NsecSigner implements ISigner {
private privkey: Uint8Array | null = null
private pubkey: string | null = null
login(nsec: string) {
const { type, data } = nip19.decode(nsec)
if (type !== 'nsec') {
throw new Error('invalid nsec')
}
this.privkey = data
this.pubkey = nGetPublicKey(data)
return this.pubkey
}
async getPublicKey() {
return this.pubkey
}
async signEvent(draftEvent: TDraftEvent) {
if (!this.privkey) {
return null
}
try {
return finalizeEvent(draftEvent, this.privkey)
} catch (error) {
console.error(error)
return null
}
}
}