Remove tsc-multi, re-install gts, apply autoformatting and linting
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {StampedEvent} from '@welshman/util'
|
||||
import {nip04, nip44, own, hash, sign, getPubkey, ISigner, makeSecret} from "../util"
|
||||
import {StampedEvent} from "@welshman/util"
|
||||
import {nip04, nip44, own, hash, sign, getPubkey, ISigner, makeSecret} from "../util.js"
|
||||
|
||||
export class Nip01Signer implements ISigner {
|
||||
#pubkey: string
|
||||
@@ -17,16 +17,12 @@ export class Nip01Signer implements ISigner {
|
||||
sign = async (event: StampedEvent) => sign(hash(own(event, this.#pubkey)), this.secret)
|
||||
|
||||
nip04 = {
|
||||
encrypt: async (pubkey: string, message: string) =>
|
||||
nip04.encrypt(pubkey, this.secret, message),
|
||||
decrypt: async (pubkey: string, message: string) =>
|
||||
nip04.decrypt(pubkey, this.secret, message),
|
||||
encrypt: async (pubkey: string, message: string) => nip04.encrypt(pubkey, this.secret, message),
|
||||
decrypt: async (pubkey: string, message: string) => nip04.decrypt(pubkey, this.secret, message),
|
||||
}
|
||||
|
||||
nip44 = {
|
||||
encrypt: async (pubkey: string, message: string) =>
|
||||
nip44.encrypt(pubkey, this.secret, message),
|
||||
decrypt: async (pubkey: string, message: string) =>
|
||||
nip44.decrypt(pubkey, this.secret, message),
|
||||
encrypt: async (pubkey: string, message: string) => nip44.encrypt(pubkey, this.secret, message),
|
||||
decrypt: async (pubkey: string, message: string) => nip44.decrypt(pubkey, this.secret, message),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {StampedEvent} from '@welshman/util'
|
||||
import {hash, own, Sign, ISigner, EncryptionImplementation} from '../util'
|
||||
import {StampedEvent} from "@welshman/util"
|
||||
import {hash, own, Sign, ISigner, EncryptionImplementation} from "../util.js"
|
||||
|
||||
export type Nip07 = {
|
||||
signEvent: Sign
|
||||
@@ -23,7 +23,10 @@ export class Nip07Signer implements ISigner {
|
||||
})
|
||||
|
||||
// Recover from errors
|
||||
this.#lock = promise.then(() => undefined, () => undefined)
|
||||
this.#lock = promise.then(
|
||||
() => undefined,
|
||||
() => undefined,
|
||||
)
|
||||
|
||||
return promise
|
||||
}
|
||||
@@ -50,4 +53,3 @@ export class Nip07Signer implements ISigner {
|
||||
this.#then(ext => ext.nip44.decrypt(pubkey, message)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
import {Emitter, throttle, makePromise, defer, sleep, tryCatch, randomId, equals} from "@welshman/lib"
|
||||
import {createEvent, normalizeRelayUrl, TrustedEvent, StampedEvent, NOSTR_CONNECT} from "@welshman/util"
|
||||
import {
|
||||
Emitter,
|
||||
throttle,
|
||||
makePromise,
|
||||
defer,
|
||||
sleep,
|
||||
tryCatch,
|
||||
randomId,
|
||||
equals,
|
||||
} from "@welshman/lib"
|
||||
import {
|
||||
createEvent,
|
||||
normalizeRelayUrl,
|
||||
TrustedEvent,
|
||||
StampedEvent,
|
||||
NOSTR_CONNECT,
|
||||
} from "@welshman/util"
|
||||
import {subscribe, publish, Subscription, SubscriptionEvent} from "@welshman/net"
|
||||
import {ISigner, decrypt, hash, own} from '../util'
|
||||
import {Nip01Signer} from './nip01'
|
||||
import {ISigner, EncryptionImplementation, decrypt, hash, own} from "../util.js"
|
||||
import {Nip01Signer} from "./nip01.js"
|
||||
|
||||
export type Nip46Algorithm = "nip04" | "nip44"
|
||||
|
||||
export enum Nip46Event {
|
||||
Send = 'send',
|
||||
Receive = 'receive',
|
||||
Send = "send",
|
||||
Receive = "receive",
|
||||
}
|
||||
|
||||
export type Nip46BrokerParams = {
|
||||
@@ -82,7 +97,10 @@ const popupManager = (() => {
|
||||
export class Nip46Receiver extends Emitter {
|
||||
public sub?: Subscription
|
||||
|
||||
constructor(public signer: ISigner, public params: Nip46BrokerParams) {
|
||||
constructor(
|
||||
public signer: ISigner,
|
||||
public params: Nip46BrokerParams,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
@@ -125,7 +143,10 @@ export class Nip46Sender extends Emitter {
|
||||
public processing = false
|
||||
public queue: Nip46Request[] = []
|
||||
|
||||
constructor(public signer: ISigner, public params: Nip46BrokerParams) {
|
||||
constructor(
|
||||
public signer: ISigner,
|
||||
public params: Nip46BrokerParams,
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
@@ -160,7 +181,7 @@ export class Nip46Sender extends Emitter {
|
||||
try {
|
||||
await this.send(request)
|
||||
} catch (error: any) {
|
||||
console.error(`nip46 error:`, error, request)
|
||||
console.error("nip46 error:", error, request)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -182,7 +203,10 @@ export class Nip46Request {
|
||||
id = randomId()
|
||||
promise = defer<Nip46ResponseWithResult, Nip46ResponseWithError>()
|
||||
|
||||
constructor(readonly method: string, readonly params: string[]) {}
|
||||
constructor(
|
||||
readonly method: string,
|
||||
readonly params: string[],
|
||||
) {}
|
||||
|
||||
listen = async (receiver: Nip46Receiver) => {
|
||||
await receiver.start()
|
||||
@@ -251,7 +275,7 @@ export class Nip46Broker extends Emitter {
|
||||
const sender = new Nip46Sender(this.signer, this.params)
|
||||
|
||||
sender.on(Nip46Event.Send, (data: any) => {
|
||||
console.log('nip46 send:', data)
|
||||
console.log("nip46 send:", data)
|
||||
})
|
||||
|
||||
return sender
|
||||
@@ -261,7 +285,7 @@ export class Nip46Broker extends Emitter {
|
||||
const receiver = new Nip46Receiver(this.signer, this.params)
|
||||
|
||||
receiver.on(Nip46Event.Receive, (data: any) => {
|
||||
console.log('nip46 receive:', data)
|
||||
console.log("nip46 receive:", data)
|
||||
})
|
||||
|
||||
return receiver
|
||||
@@ -314,7 +338,7 @@ export class Nip46Broker extends Emitter {
|
||||
const _url = new URL(url)
|
||||
|
||||
relays = _url.searchParams.getAll("relay") || []
|
||||
signerPubkey = _url.hostname || _url.pathname.replace(/\//g, '')
|
||||
signerPubkey = _url.hostname || _url.pathname.replace(/\//g, "")
|
||||
connectSecret = _url.searchParams.get("secret") || ""
|
||||
} catch {
|
||||
// pass
|
||||
@@ -329,22 +353,24 @@ export class Nip46Broker extends Emitter {
|
||||
const params = new URLSearchParams({...meta, secret})
|
||||
|
||||
for (const relay of this.params.relays) {
|
||||
params.append('relay', relay)
|
||||
params.append("relay", relay)
|
||||
}
|
||||
|
||||
return `nostrconnect://${clientPubkey}?${params.toString()}`
|
||||
}
|
||||
|
||||
waitForNostrconnect = (url: string, abort?: AbortController) => {
|
||||
const secret = new URL(url).searchParams.get('secret')
|
||||
const secret = new URL(url).searchParams.get("secret")
|
||||
|
||||
return makePromise<Nip46ResponseWithResult, Nip46Response | undefined>((resolve, reject) => {
|
||||
const onReceive = (response: Nip46Response) => {
|
||||
if (["ack", secret].includes(response.result!)) {
|
||||
this.setParams({signerPubkey: response.event.pubkey})
|
||||
|
||||
if (response.result === 'ack') {
|
||||
console.warn("Bunker responded to nostrconnect with 'ack', which can lead to session hijacking")
|
||||
if (response.result === "ack") {
|
||||
console.warn(
|
||||
"Bunker responded to nostrconnect with 'ack', which can lead to session hijacking",
|
||||
)
|
||||
}
|
||||
|
||||
resolve(response as Nip46ResponseWithResult)
|
||||
@@ -362,7 +388,7 @@ export class Nip46Broker extends Emitter {
|
||||
this.receiver.on(Nip46Event.Receive, onReceive)
|
||||
this.receiver.start()
|
||||
|
||||
abort?.signal.addEventListener('abort', () => {
|
||||
abort?.signal.addEventListener("abort", () => {
|
||||
reject(undefined)
|
||||
cleanup()
|
||||
})
|
||||
@@ -394,9 +420,21 @@ export class Nip46Broker extends Emitter {
|
||||
}
|
||||
|
||||
export class Nip46Signer implements ISigner {
|
||||
public pubkey?: string
|
||||
pubkey?: string
|
||||
nip04: EncryptionImplementation
|
||||
nip44: EncryptionImplementation
|
||||
|
||||
constructor(public broker: Nip46Broker) {}
|
||||
constructor(public broker: Nip46Broker) {
|
||||
this.nip04 = {
|
||||
encrypt: this.broker.nip04Encrypt,
|
||||
decrypt: this.broker.nip04Decrypt,
|
||||
}
|
||||
|
||||
this.nip44 = {
|
||||
encrypt: this.broker.nip44Encrypt,
|
||||
decrypt: this.broker.nip44Decrypt,
|
||||
}
|
||||
}
|
||||
|
||||
getPubkey = async () => {
|
||||
if (!this.pubkey) {
|
||||
@@ -408,14 +446,4 @@ export class Nip46Signer implements ISigner {
|
||||
|
||||
sign = async (template: StampedEvent) =>
|
||||
this.broker.signEvent(hash(own(template, await this.getPubkey())))
|
||||
|
||||
nip04 = {
|
||||
encrypt: this.broker.nip04Encrypt,
|
||||
decrypt: this.broker.nip04Decrypt,
|
||||
}
|
||||
|
||||
nip44 = {
|
||||
encrypt: this.broker.nip44Encrypt,
|
||||
decrypt: this.broker.nip44Decrypt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {SignedEvent, StampedEvent} from "@welshman/util"
|
||||
import {hash, own, ISigner} from "../util"
|
||||
import {NostrSignerPlugin, AppInfo} from "nostr-signer-capacitor-plugin"
|
||||
import {nip19} from "nostr-tools"
|
||||
import {decode} from "nostr-tools/nip19"
|
||||
import {SignedEvent, StampedEvent} from "@welshman/util"
|
||||
import {hash, own, ISigner} from "../util.js"
|
||||
|
||||
export const getNip55 = async (): Promise<AppInfo[]> => {
|
||||
const {apps} = await NostrSignerPlugin.getInstalledSignerApps()
|
||||
@@ -21,10 +21,11 @@ export class Nip55Signer implements ISigner {
|
||||
this.#initialize()
|
||||
}
|
||||
|
||||
async #initialize() {
|
||||
#initialize() {
|
||||
if (!this.#packageNameSet) {
|
||||
await this.#plugin.setPackageName({packageName: this.#packageName})
|
||||
this.#packageNameSet = true
|
||||
void this.#plugin.setPackageName({packageName: this.#packageName}).then(() => {
|
||||
this.#packageNameSet = true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +54,10 @@ export class Nip55Signer implements ISigner {
|
||||
try {
|
||||
const {npub} = await signer.getPublicKey()
|
||||
this.#npub = npub
|
||||
const {data} = nip19.decode(npub)
|
||||
const {data} = decode(npub)
|
||||
this.#publicKey = data as string
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to get public key`)
|
||||
throw new Error("Failed to get public key")
|
||||
}
|
||||
}
|
||||
return this.#publicKey
|
||||
|
||||
Reference in New Issue
Block a user