Use new nip55 plugin

This commit is contained in:
Jon Staab
2026-02-23 15:10:36 -08:00
parent 2bf0808fc0
commit 6d5197b47c
5 changed files with 52 additions and 52 deletions
+2 -1
View File
@@ -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')
+2 -1
View File
@@ -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"
}
}
}
+1
View File
@@ -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)}),
+37 -43
View File
@@ -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<AppInfo[]> => {
@@ -9,23 +8,19 @@ export const getNip55 = async (): Promise<AppInfo[]> => {
}
export class Nip55Signer implements ISigner {
#lock = Promise.resolve()
#plugin = NostrSignerPlugin
#npub?: string
#publicKey?: string
#pubkey?: string
#lock: Promise<unknown>
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 <T>(f: (signer: typeof NostrSignerPlugin) => T | Promise<T>): Promise<T> => {
const promise = this.#lock.then(() => f(this.#plugin))
#then = async <T>(f: () => T | Promise<T>): Promise<T> => {
const promise = this.#lock.then(f)
this.#lock = promise.then(() => Promise.resolve())
@@ -33,15 +28,14 @@ export class Nip55Signer implements ISigner {
}
getPubkey = async (): Promise<string> => {
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<string> => {
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<string> => {
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<string> => {
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<string> => {
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
})
+10 -7
View File
@@ -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