From 6d5197b47cca3d1e5b907c152562334074b5e35c Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 23 Feb 2026 15:10:36 -0800 Subject: [PATCH] Use new nip55 plugin --- link_deps | 3 +- package.json | 3 +- packages/signer/__tests__/nip55.test.ts | 1 + packages/signer/src/signers/nip55.ts | 80 ++++++++++++------------- pnpm-lock.yaml | 17 +++--- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/link_deps b/link_deps index 0358c43..03c50ae 100755 --- a/link_deps +++ b/link_deps @@ -12,7 +12,8 @@ if (execSync('git status --porcelain', { encoding: 'utf8' }).trim()) { const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')) pkg.pnpm.overrides = pkg.pnpm.overrides || {} -pkg.pnpm.overrides["@pomade/core"] = "link:../pomade/packages/core" +// pkg.pnpm.overrides["@pomade/core"] = "link:../pomade/packages/core" +// pkg.pnpm.overrides["nostr-signer-capacitor-plugin"] = "link:../nostr-signer-capacitor-plugin" fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n') diff --git a/package.json b/package.json index b78c85c..4b048f9 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "pnpm": { "overrides": { "@tiptap/core": "^2.11.7", - "@tiptap/pm": "^2.11.7" + "@tiptap/pm": "^2.11.7", + "nostr-signer-capacitor-plugin": "github:coracle-social/nostr-signer-capacitor-plugin#main" } } } diff --git a/packages/signer/__tests__/nip55.test.ts b/packages/signer/__tests__/nip55.test.ts index 1b56787..6159dc0 100644 --- a/packages/signer/__tests__/nip55.test.ts +++ b/packages/signer/__tests__/nip55.test.ts @@ -6,6 +6,7 @@ import {npubEncode} from "nostr-tools/nip19" vi.mock("nostr-signer-capacitor-plugin", () => ({ NostrSignerPlugin: { + setPackageName: vi.fn(() => Promise.resolve()), getPublicKey: vi.fn(() => ({npub: npubEncode("ee".repeat(32))})), signEvent: vi.fn(() => ({ event: JSON.stringify({sig: "ee".repeat(64)}), diff --git a/packages/signer/src/signers/nip55.ts b/packages/signer/src/signers/nip55.ts index d97b467..42fe107 100644 --- a/packages/signer/src/signers/nip55.ts +++ b/packages/signer/src/signers/nip55.ts @@ -1,6 +1,5 @@ import {NostrSignerPlugin, AppInfo} from "nostr-signer-capacitor-plugin" -import * as nip19 from "nostr-tools/nip19" -import {SignedEvent, StampedEvent, hash, own} from "@welshman/util" +import {SignedEvent, StampedEvent, hash, own, Pubkey} from "@welshman/util" import {signWithOptions, SignOptions, ISigner} from "../util.js" export const getNip55 = async (): Promise => { @@ -9,23 +8,19 @@ export const getNip55 = async (): Promise => { } export class Nip55Signer implements ISigner { - #lock = Promise.resolve() - #plugin = NostrSignerPlugin - #npub?: string - #publicKey?: string + #pubkey?: string + #lock: Promise constructor( readonly packageName: string, - publicKey?: string, + pubkey?: string, ) { - if (publicKey) { - this.#publicKey = publicKey - this.#npub = nip19.npubEncode(publicKey) - } + this.#pubkey = pubkey + this.#lock = NostrSignerPlugin.setPackageName(packageName) } - #then = async (f: (signer: typeof NostrSignerPlugin) => T | Promise): Promise => { - const promise = this.#lock.then(() => f(this.#plugin)) + #then = async (f: () => T | Promise): Promise => { + const promise = this.#lock.then(f) this.#lock = promise.then(() => Promise.resolve()) @@ -33,15 +28,14 @@ export class Nip55Signer implements ISigner { } getPubkey = async (): Promise => { - return this.#then(async signer => { - if (!this.#publicKey || !this.#npub) { - const {npub} = await signer.getPublicKey(this.packageName) - const {data} = nip19.decode(npub) + return this.#then(async () => { + if (!this.#pubkey) { + const {npub} = await NostrSignerPlugin.getPublicKey(this.packageName) - this.#npub = npub - this.#publicKey = data as string + this.#pubkey = Pubkey.from(npub).toString() } - return this.#publicKey + + return this.#pubkey }) } @@ -50,12 +44,12 @@ export class Nip55Signer implements ISigner { this.getPubkey().then(pubkey => { const hashedEvent = hash(own(template, pubkey)) - return this.#then(async signer => { - const {event: json} = await signer.signEvent( + return this.#then(async () => { + const {event: json} = await NostrSignerPlugin.signEvent( this.packageName, JSON.stringify({sig: "", ...hashedEvent}), hashedEvent.id, - this.#npub!, + this.#pubkey!, ) return JSON.parse(json) as SignedEvent @@ -66,35 +60,35 @@ export class Nip55Signer implements ISigner { nip04 = { encrypt: async (recipientPubKey: string, message: string): Promise => { - const myNpub = this.#npub - if (!myNpub) { + const myPubkey = this.#pubkey + if (!myPubkey) { await this.getPubkey() } - return this.#then(async signer => { + return this.#then(async () => { const id = `${Date.now()}-${Math.random().toString(36).slice(2)}` - const {result} = await signer.nip04Encrypt( + const {result} = await NostrSignerPlugin.nip04Encrypt( this.packageName, message, id, recipientPubKey, - this.#npub!, + this.#pubkey!, ) return result }) }, decrypt: async (senderPubKey: string, message: string): Promise => { - const myNpub = this.#npub - if (!myNpub) { + const myPubkey = this.#pubkey + if (!myPubkey) { await this.getPubkey() } - return this.#then(async signer => { + return this.#then(async () => { const id = `${Date.now()}-${Math.random().toString(36).slice(2)}` - const {result} = await signer.nip04Decrypt( + const {result} = await NostrSignerPlugin.nip04Decrypt( this.packageName, message, id, senderPubKey, - this.#npub!, + this.#pubkey!, ) return result }) @@ -103,35 +97,35 @@ export class Nip55Signer implements ISigner { nip44 = { encrypt: async (recipientPubKey: string, message: string): Promise => { - const myNpub = this.#npub - if (!myNpub) { + const myPubkey = this.#pubkey + if (!myPubkey) { await this.getPubkey() } - return this.#then(async signer => { + return this.#then(async () => { const id = `${Date.now()}-${Math.random().toString(36).slice(2)}` - const {result} = await signer.nip44Encrypt( + const {result} = await NostrSignerPlugin.nip44Encrypt( this.packageName, message, id, recipientPubKey, - this.#npub!, + this.#pubkey!, ) return result }) }, decrypt: async (senderPubKey: string, message: string): Promise => { - const myNpub = this.#npub - if (!myNpub) { + const myPubkey = this.#pubkey + if (!myPubkey) { await this.getPubkey() } - return this.#then(async signer => { + return this.#then(async () => { const id = `${Date.now()}-${Math.random().toString(36).slice(2)}` - const {result} = await signer.nip44Decrypt( + const {result} = await NostrSignerPlugin.nip44Decrypt( this.packageName, message, id, senderPubKey, - this.#npub!, + this.#pubkey!, ) return result }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 751dca0..dfbe4f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,7 @@ settings: overrides: '@tiptap/core': ^2.11.7 '@tiptap/pm': ^2.11.7 + nostr-signer-capacitor-plugin: github:coracle-social/nostr-signer-capacitor-plugin#main importers: @@ -384,6 +385,10 @@ importers: version: 5.8.2 packages/signer: + dependencies: + nostr-signer-capacitor-plugin: + specifier: github:coracle-social/nostr-signer-capacitor-plugin#main + version: https://codeload.github.com/coracle-social/nostr-signer-capacitor-plugin/tar.gz/3f4d3747ebe573f3c5017fe67137632e06309580(@capacitor/core@7.2.0) devDependencies: '@capacitor/core': specifier: ^7.2.0 @@ -403,9 +408,6 @@ importers: '@welshman/util': specifier: workspace:* version: link:../util - nostr-signer-capacitor-plugin: - specifier: ~0.0.5 - version: 0.0.5(@capacitor/core@7.2.0) nostr-tools: specifier: ^2.19.4 version: 2.19.4(typescript@5.8.2) @@ -2473,10 +2475,11 @@ packages: prosemirror-view: ^1.39.3 tiptap-markdown: ^0.8.10 - nostr-signer-capacitor-plugin@0.0.5: - resolution: {integrity: sha512-/EvqWz71HZ5cWmzvfXWTm48AWZtbeZDbOg3vLwXyXPjnIp1DR7Wurww/Mo41ORNu1DNPlqH20l7kIXKO6vR5og==} + nostr-signer-capacitor-plugin@https://codeload.github.com/coracle-social/nostr-signer-capacitor-plugin/tar.gz/3f4d3747ebe573f3c5017fe67137632e06309580: + resolution: {tarball: https://codeload.github.com/coracle-social/nostr-signer-capacitor-plugin/tar.gz/3f4d3747ebe573f3c5017fe67137632e06309580} + version: 0.0.5 peerDependencies: - '@capacitor/core': ^7.0.0 + '@capacitor/core': ^8.0.0 nostr-tools@2.14.2: resolution: {integrity: sha512-YOIOn5EdJ2Kq5sQW5Zh4wOcqzR6kUyrCDHG4+mVD2szzthsyOTpiWX0yrwaRZGlHJG6q83vkhg95qc2W201XTQ==} @@ -5326,7 +5329,7 @@ snapshots: prosemirror-view: 1.41.3 tiptap-markdown: 0.8.10(@tiptap/core@2.11.7(@tiptap/pm@2.11.7)) - nostr-signer-capacitor-plugin@0.0.5(@capacitor/core@7.2.0): + nostr-signer-capacitor-plugin@https://codeload.github.com/coracle-social/nostr-signer-capacitor-plugin/tar.gz/3f4d3747ebe573f3c5017fe67137632e06309580(@capacitor/core@7.2.0): dependencies: '@capacitor/core': 7.2.0