Remove promenade and pomade stuff from signer package

This commit is contained in:
Jon Staab
2026-01-13 10:25:29 -08:00
parent ac7190acc5
commit 09e687ab05
16 changed files with 92 additions and 268 deletions
+76 -5
View File
@@ -1,6 +1,7 @@
import * as nt44 from "nostr-tools/nip44"
import {Client, ClientOptions} from "@pomade/core"
import {derived, writable} from "svelte/store"
import {cached, randomId, append, omit, equals, assoc} from "@welshman/lib"
import {cached, randomId, append, omit, equals, assoc, thrower, hexToBytes} from "@welshman/lib"
import {withGetter} from "@welshman/store"
import {
Wallet,
@@ -14,17 +15,81 @@ import {
import {
Nip59,
WrappedSigner,
PomadeSigner,
Nip46Broker,
Nip46Signer,
Nip07Signer,
Nip01Signer,
Nip55Signer,
ISigner,
SignOptions,
signWithOptions,
} from "@welshman/signer"
import {WrapManager} from "@welshman/net"
import {tracker, repository} from "./core.js"
class PomadeSigner implements ISigner {
#pubkey: string
#sharedSecretCache = new Map<string, Uint8Array<ArrayBuffer>>()
constructor(readonly client: Client) {
this.#pubkey = client.userPubkey
}
private getSharedSecret = async (pubkey: string) => {
let sharedSecret = this.#sharedSecretCache.get(pubkey)
if (!sharedSecret) {
const hexSharedSecret = await this.client.getConversationKey(pubkey)
if (hexSharedSecret) {
sharedSecret = hexToBytes(hexSharedSecret)
this.#sharedSecretCache.set(pubkey, sharedSecret)
}
}
return sharedSecret
}
getPubkey = async () => this.#pubkey
sign = (event: StampedEvent, options: SignOptions = {}) => {
const promise = this.client.sign(event).then(r => {
if (!r.event) {
throw new Error(r.messages[0]?.payload.message || "Failed to sign event")
}
return r.event
})
return signWithOptions(promise, options)
}
nip04 = {
encrypt: thrower("PomadeSigner does not support nip44"),
decrypt: thrower("PomadeSigner does not support nip44"),
}
nip44 = {
encrypt: async (pubkey: string, message: string) => {
const sharedSecret = await this.getSharedSecret(pubkey)
if (!sharedSecret) {
throw new Error("Failed to get shared secret")
}
return nt44.v2.encrypt(message, sharedSecret)
},
decrypt: async (pubkey: string, message: string) => {
const sharedSecret = await this.getSharedSecret(pubkey)
if (!sharedSecret) {
throw new Error("Failed to get shared secret")
}
return nt44.v2.decrypt(message, sharedSecret)
},
}
}
export enum SessionMethod {
Nip01 = "nip01",
Nip07 = "nip07",
@@ -66,6 +131,7 @@ export type SessionPomade = {
method: SessionMethod.Pomade
pubkey: string
clientOptions: ClientOptions
email: string
}
export type SessionPubkey = {
@@ -164,10 +230,15 @@ export const makeNip55Session = (pubkey: string, signer: string): SessionNip55 =
signer,
})
export const makePomadeSession = (pubkey: string, clientOptions: ClientOptions): SessionPomade => ({
export const makePomadeSession = (
pubkey: string,
email: string,
clientOptions: ClientOptions,
): SessionPomade => ({
method: SessionMethod.Pomade,
pubkey,
clientOptions,
email,
})
export const makePubkeySession = (pubkey: string): SessionPubkey => ({
@@ -211,8 +282,8 @@ export const loginWithNip46 = (
export const loginWithNip55 = (pubkey: string, signer: string) =>
addSession(makeNip55Session(pubkey, signer))
export const loginWithPomade = (pubkey: string, clientOptions: ClientOptions) =>
addSession(makePomadeSession(pubkey, clientOptions))
export const loginWithPomade = (pubkey: string, email: string, clientOptions: ClientOptions) =>
addSession(makePomadeSession(pubkey, email, clientOptions))
export const loginWithPubkey = (pubkey: string) => addSession(makePubkeySession(pubkey))