Pass pubkey to nip 55 signer to avoid mixing up sessions
This commit is contained in:
@@ -239,7 +239,7 @@ export const getSigner = cached({
|
||||
getValue: ([session]: [Session | undefined]) => {
|
||||
if (isNip07Session(session)) return wrapSigner(new Nip07Signer())
|
||||
if (isNip01Session(session)) return wrapSigner(new Nip01Signer(session.secret))
|
||||
if (isNip55Session(session)) return wrapSigner(new Nip55Signer(session.signer))
|
||||
if (isNip55Session(session)) return wrapSigner(new Nip55Signer(session.signer, session.pubkey))
|
||||
if (isNip46Session(session)) {
|
||||
const {
|
||||
secret: clientSecret,
|
||||
|
||||
@@ -622,7 +622,7 @@ export const sortBy = <T>(f: (x: T) => any, xs: T[]) =>
|
||||
* @param xs - Array to group
|
||||
* @returns Map of groups
|
||||
*/
|
||||
export const groupBy = <T, K>(f: (x: T) => K, xs: T[]) => {
|
||||
export const groupBy = <T, K>(f: (x: T) => K, xs: Iterable<T>) => {
|
||||
const r = new Map<K, T[]>()
|
||||
|
||||
for (const x of xs) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {NostrSignerPlugin, AppInfo} from "nostr-signer-capacitor-plugin"
|
||||
import {decode} from "nostr-tools/nip19"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {SignedEvent, StampedEvent} from "@welshman/util"
|
||||
import {hash, own, signWithOptions, SignOptions, ISigner} from "../util.js"
|
||||
|
||||
@@ -16,8 +16,14 @@ export class Nip55Signer implements ISigner {
|
||||
#npub?: string
|
||||
#publicKey?: string
|
||||
|
||||
constructor(packageName: string) {
|
||||
constructor(packageName: string, publicKey?: string) {
|
||||
this.#packageName = packageName
|
||||
|
||||
if (publicKey) {
|
||||
this.#publicKey = publicKey
|
||||
this.#npub = nip19.npubEncode(publicKey)
|
||||
}
|
||||
|
||||
this.#initialize()
|
||||
}
|
||||
|
||||
@@ -53,8 +59,9 @@ export class Nip55Signer implements ISigner {
|
||||
if (!this.#publicKey || !this.#npub) {
|
||||
try {
|
||||
const {npub} = await signer.getPublicKey()
|
||||
const {data} = nip19.decode(npub)
|
||||
|
||||
this.#npub = npub
|
||||
const {data} = decode(npub)
|
||||
this.#publicKey = data as string
|
||||
} catch (error) {
|
||||
throw new Error("Failed to get public key")
|
||||
|
||||
Reference in New Issue
Block a user