applesauce-signers 0.0.0-next-20250511152752 → 0.0.0-next-20250526151506
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/signers/nostr-connect-signer.d.ts +4 -2
- package/dist/signers/nostr-connect-signer.js +9 -3
- package/package.json +3 -3
- package/dist/logger.d.ts +0 -2
- package/dist/logger.js +0 -2
- package/dist/signers/nostr-connect-signer.test.d.ts +0 -1
- package/dist/signers/nostr-connect-signer.test.js +0 -23
|
@@ -82,8 +82,10 @@ interface Observer<T> {
|
|
|
82
82
|
type Subscribable<T extends unknown> = {
|
|
83
83
|
subscribe: (observer: Partial<Observer<T>>) => Unsubscribable;
|
|
84
84
|
};
|
|
85
|
-
|
|
86
|
-
export type
|
|
85
|
+
/** A method used to subscribe to events on a set of relays */
|
|
86
|
+
export type NostrSubscriptionMethod = (relays: string[], filters: Filter[]) => Subscribable<NostrEvent | string>;
|
|
87
|
+
/** A method used for publishing an event, can return a Promise that completes when published or an Observable that completes when published*/
|
|
88
|
+
export type NostrPublishMethod = (relays: string[], event: NostrEvent) => Promise<any> | Subscribable<any>;
|
|
87
89
|
export type NostrConnectAppMetadata = {
|
|
88
90
|
name?: string;
|
|
89
91
|
image?: string;
|
|
@@ -104,7 +104,7 @@ export class NostrConnectSigner {
|
|
|
104
104
|
"#p": [pubkey],
|
|
105
105
|
},
|
|
106
106
|
]).subscribe({
|
|
107
|
-
next: (event) => this.handleEvent(event),
|
|
107
|
+
next: (event) => typeof event !== "string" && this.handleEvent(event),
|
|
108
108
|
});
|
|
109
109
|
this.log("Opened", this.relays);
|
|
110
110
|
}
|
|
@@ -195,10 +195,16 @@ export class NostrConnectSigner {
|
|
|
195
195
|
const request = { id, method, params };
|
|
196
196
|
const encrypted = await this.signer.nip44.encrypt(this.remote, JSON.stringify(request));
|
|
197
197
|
const event = await this.createRequestEvent(encrypted, this.remote, kind);
|
|
198
|
-
this.log(`Sending
|
|
198
|
+
this.log(`Sending ${id} (${method}) ${JSON.stringify(params)}`);
|
|
199
199
|
const p = createDefer();
|
|
200
200
|
this.requests.set(id, p);
|
|
201
|
-
|
|
201
|
+
const result = this.publishMethod?.(this.relays, event);
|
|
202
|
+
// Handle returned Promise or Observable
|
|
203
|
+
if (result instanceof Promise)
|
|
204
|
+
await result;
|
|
205
|
+
else if ("subscribe" in result)
|
|
206
|
+
await new Promise((res) => result.subscribe({ complete: res }));
|
|
207
|
+
this.log(`Sent ${id} (${method})`);
|
|
202
208
|
return p;
|
|
203
209
|
}
|
|
204
210
|
/** Connect to remote signer */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-signers",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250526151506",
|
|
4
4
|
"description": "Signer classes for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"@noble/hashes": "^1.7.1",
|
|
37
37
|
"@noble/secp256k1": "^1.7.1",
|
|
38
38
|
"@scure/base": "^1.2.4",
|
|
39
|
-
"applesauce-core": "0.0.0-next-
|
|
39
|
+
"applesauce-core": "0.0.0-next-20250526151506",
|
|
40
40
|
"debug": "^4.4.0",
|
|
41
41
|
"nanoid": "^5.0.9",
|
|
42
|
-
"nostr-tools": "^2.
|
|
42
|
+
"nostr-tools": "^2.13"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/debug": "^4.1.12",
|
package/dist/logger.d.ts
DELETED
package/dist/logger.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { NostrConnectSigner } from "./nostr-connect-signer.js";
|
|
3
|
-
import { SimpleSigner } from "./simple-signer.js";
|
|
4
|
-
describe("NostrConnectSigner", () => {
|
|
5
|
-
describe("connection", () => {
|
|
6
|
-
it("should call subscription method with filters", async () => {
|
|
7
|
-
const relays = ["wss://relay.signer.com"];
|
|
8
|
-
const subscription = vi.fn().mockReturnValue({ subscribe: vi.fn() });
|
|
9
|
-
const publish = vi.fn(async () => { });
|
|
10
|
-
const client = new SimpleSigner();
|
|
11
|
-
const remote = new SimpleSigner();
|
|
12
|
-
const signer = new NostrConnectSigner({
|
|
13
|
-
relays,
|
|
14
|
-
remote: await remote.getPublicKey(),
|
|
15
|
-
signer: client,
|
|
16
|
-
subscriptionMethod: subscription,
|
|
17
|
-
publishMethod: publish,
|
|
18
|
-
});
|
|
19
|
-
signer.connect();
|
|
20
|
-
expect(subscription).toHaveBeenCalledWith(relays, [{ "#p": [await client.getPublicKey()], kinds: [24133] }]);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|