Use new nip55 plugin
This commit is contained in:
@@ -12,7 +12,8 @@ if (execSync('git status --porcelain', { encoding: 'utf8' }).trim()) {
|
|||||||
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
|
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
|
||||||
|
|
||||||
pkg.pnpm.overrides = pkg.pnpm.overrides || {}
|
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')
|
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n')
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -37,7 +37,8 @@
|
|||||||
"pnpm": {
|
"pnpm": {
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@tiptap/core": "^2.11.7",
|
"@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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {npubEncode} from "nostr-tools/nip19"
|
|||||||
|
|
||||||
vi.mock("nostr-signer-capacitor-plugin", () => ({
|
vi.mock("nostr-signer-capacitor-plugin", () => ({
|
||||||
NostrSignerPlugin: {
|
NostrSignerPlugin: {
|
||||||
|
setPackageName: vi.fn(() => Promise.resolve()),
|
||||||
getPublicKey: vi.fn(() => ({npub: npubEncode("ee".repeat(32))})),
|
getPublicKey: vi.fn(() => ({npub: npubEncode("ee".repeat(32))})),
|
||||||
signEvent: vi.fn(() => ({
|
signEvent: vi.fn(() => ({
|
||||||
event: JSON.stringify({sig: "ee".repeat(64)}),
|
event: JSON.stringify({sig: "ee".repeat(64)}),
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {NostrSignerPlugin, AppInfo} from "nostr-signer-capacitor-plugin"
|
import {NostrSignerPlugin, AppInfo} from "nostr-signer-capacitor-plugin"
|
||||||
import * as nip19 from "nostr-tools/nip19"
|
import {SignedEvent, StampedEvent, hash, own, Pubkey} from "@welshman/util"
|
||||||
import {SignedEvent, StampedEvent, hash, own} from "@welshman/util"
|
|
||||||
import {signWithOptions, SignOptions, ISigner} from "../util.js"
|
import {signWithOptions, SignOptions, ISigner} from "../util.js"
|
||||||
|
|
||||||
export const getNip55 = async (): Promise<AppInfo[]> => {
|
export const getNip55 = async (): Promise<AppInfo[]> => {
|
||||||
@@ -9,23 +8,19 @@ export const getNip55 = async (): Promise<AppInfo[]> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Nip55Signer implements ISigner {
|
export class Nip55Signer implements ISigner {
|
||||||
#lock = Promise.resolve()
|
#pubkey?: string
|
||||||
#plugin = NostrSignerPlugin
|
#lock: Promise<unknown>
|
||||||
#npub?: string
|
|
||||||
#publicKey?: string
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly packageName: string,
|
readonly packageName: string,
|
||||||
publicKey?: string,
|
pubkey?: string,
|
||||||
) {
|
) {
|
||||||
if (publicKey) {
|
this.#pubkey = pubkey
|
||||||
this.#publicKey = publicKey
|
this.#lock = NostrSignerPlugin.setPackageName(packageName)
|
||||||
this.#npub = nip19.npubEncode(publicKey)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#then = async <T>(f: (signer: typeof NostrSignerPlugin) => T | Promise<T>): Promise<T> => {
|
#then = async <T>(f: () => T | Promise<T>): Promise<T> => {
|
||||||
const promise = this.#lock.then(() => f(this.#plugin))
|
const promise = this.#lock.then(f)
|
||||||
|
|
||||||
this.#lock = promise.then(() => Promise.resolve())
|
this.#lock = promise.then(() => Promise.resolve())
|
||||||
|
|
||||||
@@ -33,15 +28,14 @@ export class Nip55Signer implements ISigner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPubkey = async (): Promise<string> => {
|
getPubkey = async (): Promise<string> => {
|
||||||
return this.#then(async signer => {
|
return this.#then(async () => {
|
||||||
if (!this.#publicKey || !this.#npub) {
|
if (!this.#pubkey) {
|
||||||
const {npub} = await signer.getPublicKey(this.packageName)
|
const {npub} = await NostrSignerPlugin.getPublicKey(this.packageName)
|
||||||
const {data} = nip19.decode(npub)
|
|
||||||
|
|
||||||
this.#npub = npub
|
this.#pubkey = Pubkey.from(npub).toString()
|
||||||
this.#publicKey = data as string
|
|
||||||
}
|
}
|
||||||
return this.#publicKey
|
|
||||||
|
return this.#pubkey
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +44,12 @@ export class Nip55Signer implements ISigner {
|
|||||||
this.getPubkey().then(pubkey => {
|
this.getPubkey().then(pubkey => {
|
||||||
const hashedEvent = hash(own(template, pubkey))
|
const hashedEvent = hash(own(template, pubkey))
|
||||||
|
|
||||||
return this.#then(async signer => {
|
return this.#then(async () => {
|
||||||
const {event: json} = await signer.signEvent(
|
const {event: json} = await NostrSignerPlugin.signEvent(
|
||||||
this.packageName,
|
this.packageName,
|
||||||
JSON.stringify({sig: "", ...hashedEvent}),
|
JSON.stringify({sig: "", ...hashedEvent}),
|
||||||
hashedEvent.id,
|
hashedEvent.id,
|
||||||
this.#npub!,
|
this.#pubkey!,
|
||||||
)
|
)
|
||||||
|
|
||||||
return JSON.parse(json) as SignedEvent
|
return JSON.parse(json) as SignedEvent
|
||||||
@@ -66,35 +60,35 @@ export class Nip55Signer implements ISigner {
|
|||||||
|
|
||||||
nip04 = {
|
nip04 = {
|
||||||
encrypt: async (recipientPubKey: string, message: string): Promise<string> => {
|
encrypt: async (recipientPubKey: string, message: string): Promise<string> => {
|
||||||
const myNpub = this.#npub
|
const myPubkey = this.#pubkey
|
||||||
if (!myNpub) {
|
if (!myPubkey) {
|
||||||
await this.getPubkey()
|
await this.getPubkey()
|
||||||
}
|
}
|
||||||
return this.#then(async signer => {
|
return this.#then(async () => {
|
||||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||||
const {result} = await signer.nip04Encrypt(
|
const {result} = await NostrSignerPlugin.nip04Encrypt(
|
||||||
this.packageName,
|
this.packageName,
|
||||||
message,
|
message,
|
||||||
id,
|
id,
|
||||||
recipientPubKey,
|
recipientPubKey,
|
||||||
this.#npub!,
|
this.#pubkey!,
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
decrypt: async (senderPubKey: string, message: string): Promise<string> => {
|
decrypt: async (senderPubKey: string, message: string): Promise<string> => {
|
||||||
const myNpub = this.#npub
|
const myPubkey = this.#pubkey
|
||||||
if (!myNpub) {
|
if (!myPubkey) {
|
||||||
await this.getPubkey()
|
await this.getPubkey()
|
||||||
}
|
}
|
||||||
return this.#then(async signer => {
|
return this.#then(async () => {
|
||||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||||
const {result} = await signer.nip04Decrypt(
|
const {result} = await NostrSignerPlugin.nip04Decrypt(
|
||||||
this.packageName,
|
this.packageName,
|
||||||
message,
|
message,
|
||||||
id,
|
id,
|
||||||
senderPubKey,
|
senderPubKey,
|
||||||
this.#npub!,
|
this.#pubkey!,
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
@@ -103,35 +97,35 @@ export class Nip55Signer implements ISigner {
|
|||||||
|
|
||||||
nip44 = {
|
nip44 = {
|
||||||
encrypt: async (recipientPubKey: string, message: string): Promise<string> => {
|
encrypt: async (recipientPubKey: string, message: string): Promise<string> => {
|
||||||
const myNpub = this.#npub
|
const myPubkey = this.#pubkey
|
||||||
if (!myNpub) {
|
if (!myPubkey) {
|
||||||
await this.getPubkey()
|
await this.getPubkey()
|
||||||
}
|
}
|
||||||
return this.#then(async signer => {
|
return this.#then(async () => {
|
||||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||||
const {result} = await signer.nip44Encrypt(
|
const {result} = await NostrSignerPlugin.nip44Encrypt(
|
||||||
this.packageName,
|
this.packageName,
|
||||||
message,
|
message,
|
||||||
id,
|
id,
|
||||||
recipientPubKey,
|
recipientPubKey,
|
||||||
this.#npub!,
|
this.#pubkey!,
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
decrypt: async (senderPubKey: string, message: string): Promise<string> => {
|
decrypt: async (senderPubKey: string, message: string): Promise<string> => {
|
||||||
const myNpub = this.#npub
|
const myPubkey = this.#pubkey
|
||||||
if (!myNpub) {
|
if (!myPubkey) {
|
||||||
await this.getPubkey()
|
await this.getPubkey()
|
||||||
}
|
}
|
||||||
return this.#then(async signer => {
|
return this.#then(async () => {
|
||||||
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||||
const {result} = await signer.nip44Decrypt(
|
const {result} = await NostrSignerPlugin.nip44Decrypt(
|
||||||
this.packageName,
|
this.packageName,
|
||||||
message,
|
message,
|
||||||
id,
|
id,
|
||||||
senderPubKey,
|
senderPubKey,
|
||||||
this.#npub!,
|
this.#pubkey!,
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|||||||
Generated
+10
-7
@@ -7,6 +7,7 @@ settings:
|
|||||||
overrides:
|
overrides:
|
||||||
'@tiptap/core': ^2.11.7
|
'@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
|
||||||
|
|
||||||
importers:
|
importers:
|
||||||
|
|
||||||
@@ -384,6 +385,10 @@ importers:
|
|||||||
version: 5.8.2
|
version: 5.8.2
|
||||||
|
|
||||||
packages/signer:
|
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:
|
devDependencies:
|
||||||
'@capacitor/core':
|
'@capacitor/core':
|
||||||
specifier: ^7.2.0
|
specifier: ^7.2.0
|
||||||
@@ -403,9 +408,6 @@ importers:
|
|||||||
'@welshman/util':
|
'@welshman/util':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../util
|
version: link:../util
|
||||||
nostr-signer-capacitor-plugin:
|
|
||||||
specifier: ~0.0.5
|
|
||||||
version: 0.0.5(@capacitor/core@7.2.0)
|
|
||||||
nostr-tools:
|
nostr-tools:
|
||||||
specifier: ^2.19.4
|
specifier: ^2.19.4
|
||||||
version: 2.19.4(typescript@5.8.2)
|
version: 2.19.4(typescript@5.8.2)
|
||||||
@@ -2473,10 +2475,11 @@ packages:
|
|||||||
prosemirror-view: ^1.39.3
|
prosemirror-view: ^1.39.3
|
||||||
tiptap-markdown: ^0.8.10
|
tiptap-markdown: ^0.8.10
|
||||||
|
|
||||||
nostr-signer-capacitor-plugin@0.0.5:
|
nostr-signer-capacitor-plugin@https://codeload.github.com/coracle-social/nostr-signer-capacitor-plugin/tar.gz/3f4d3747ebe573f3c5017fe67137632e06309580:
|
||||||
resolution: {integrity: sha512-/EvqWz71HZ5cWmzvfXWTm48AWZtbeZDbOg3vLwXyXPjnIp1DR7Wurww/Mo41ORNu1DNPlqH20l7kIXKO6vR5og==}
|
resolution: {tarball: https://codeload.github.com/coracle-social/nostr-signer-capacitor-plugin/tar.gz/3f4d3747ebe573f3c5017fe67137632e06309580}
|
||||||
|
version: 0.0.5
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
'@capacitor/core': ^7.0.0
|
'@capacitor/core': ^8.0.0
|
||||||
|
|
||||||
nostr-tools@2.14.2:
|
nostr-tools@2.14.2:
|
||||||
resolution: {integrity: sha512-YOIOn5EdJ2Kq5sQW5Zh4wOcqzR6kUyrCDHG4+mVD2szzthsyOTpiWX0yrwaRZGlHJG6q83vkhg95qc2W201XTQ==}
|
resolution: {integrity: sha512-YOIOn5EdJ2Kq5sQW5Zh4wOcqzR6kUyrCDHG4+mVD2szzthsyOTpiWX0yrwaRZGlHJG6q83vkhg95qc2W201XTQ==}
|
||||||
@@ -5326,7 +5329,7 @@ snapshots:
|
|||||||
prosemirror-view: 1.41.3
|
prosemirror-view: 1.41.3
|
||||||
tiptap-markdown: 0.8.10(@tiptap/core@2.11.7(@tiptap/pm@2.11.7))
|
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:
|
dependencies:
|
||||||
'@capacitor/core': 7.2.0
|
'@capacitor/core': 7.2.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user