refactor: remove electron-related code
This commit is contained in:
parent
bed8df06e8
commit
2b1e6fe8f5
200 changed files with 2771 additions and 8432 deletions
53
src/providers/NostrProvider/bunker.signer.ts
Normal file
53
src/providers/NostrProvider/bunker.signer.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { ISigner, TDraftEvent } from '@/types'
|
||||
import { bytesToHex, hexToBytes } from '@noble/hashes/utils'
|
||||
import { generateSecretKey } from 'nostr-tools'
|
||||
import { BunkerSigner as NBunkerSigner, parseBunkerInput } from 'nostr-tools/nip46'
|
||||
|
||||
export class BunkerSigner implements ISigner {
|
||||
signer: NBunkerSigner | null = null
|
||||
private clientSecretKey: Uint8Array
|
||||
private pubkey: string | null = null
|
||||
|
||||
constructor(clientSecretKey?: string) {
|
||||
this.clientSecretKey = clientSecretKey ? hexToBytes(clientSecretKey) : generateSecretKey()
|
||||
}
|
||||
|
||||
async login(bunker: string): Promise<string> {
|
||||
const bunkerPointer = await parseBunkerInput(bunker)
|
||||
if (!bunkerPointer) {
|
||||
throw new Error('Invalid bunker')
|
||||
}
|
||||
|
||||
this.signer = new NBunkerSigner(this.clientSecretKey, bunkerPointer, {
|
||||
onauth: (url) => {
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
})
|
||||
await this.signer.connect()
|
||||
return await this.signer.getPublicKey()
|
||||
}
|
||||
|
||||
async getPublicKey() {
|
||||
if (!this.signer) {
|
||||
throw new Error('Not logged in')
|
||||
}
|
||||
if (!this.pubkey) {
|
||||
this.pubkey = await this.signer.getPublicKey()
|
||||
}
|
||||
return this.pubkey
|
||||
}
|
||||
|
||||
async signEvent(draftEvent: TDraftEvent) {
|
||||
if (!this.signer) {
|
||||
throw new Error('Not logged in')
|
||||
}
|
||||
return this.signer.signEvent({
|
||||
...draftEvent,
|
||||
pubkey: await this.signer.getPublicKey()
|
||||
})
|
||||
}
|
||||
|
||||
getClientSecretKey() {
|
||||
return bytesToHex(this.clientSecretKey)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue