applesauce-signers 7.1.0 → 7.2.0
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Debugger } from "applesauce-core";
|
|
2
|
-
import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { EventTemplate, NostrEvent, verifyEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { Subscription } from "rxjs";
|
|
4
4
|
import { ConnectRequestParams, ConnectResponseResults, NostrConnectMethod, NostrConnectResponse, NostrConnectURI } from "../helpers/nostr-connect.js";
|
|
5
5
|
import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod } from "../interop.js";
|
|
@@ -23,6 +23,8 @@ export interface ProviderAuthorization {
|
|
|
23
23
|
onLogout?: (client: string) => void | Promise<void>;
|
|
24
24
|
}
|
|
25
25
|
export type NostrConnectProviderOptions = ProviderAuthorization & NostrConnectionMethodsOptions & {
|
|
26
|
+
/** A synchronous method that verifies event hashes and signatures */
|
|
27
|
+
verifyEvent?: typeof verifyEvent;
|
|
26
28
|
/** The relays to communicate over */
|
|
27
29
|
relays: string[];
|
|
28
30
|
/** The signer to use for signing events and encryption */
|
|
@@ -39,6 +41,10 @@ export type NostrConnectProviderOptions = ProviderAuthorization & NostrConnectio
|
|
|
39
41
|
onClientDisconnect?: (client: string) => void;
|
|
40
42
|
};
|
|
41
43
|
export declare class NostrConnectProvider implements ProviderAuthorization {
|
|
44
|
+
/** The default event verifier for new instances */
|
|
45
|
+
static verifyEvent: typeof verifyEvent;
|
|
46
|
+
/** A synchronous method that verifies incoming request events */
|
|
47
|
+
verifyEvent: typeof verifyEvent;
|
|
42
48
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the provider */
|
|
43
49
|
static subscriptionMethod: NostrSubscriptionMethod | undefined;
|
|
44
50
|
/** A fallback method to use for publishMethod if none is passed in when creating the provider */
|
|
@@ -9,6 +9,10 @@ import { createBunkerURI, createNbunksec, NostrConnectMethod, parseNostrConnectU
|
|
|
9
9
|
import { getConnectionMethods, } from "../interop.js";
|
|
10
10
|
import { PrivateKeySigner } from "./private-key-signer.js";
|
|
11
11
|
export class NostrConnectProvider {
|
|
12
|
+
/** The default event verifier for new instances */
|
|
13
|
+
static verifyEvent = verifyEvent;
|
|
14
|
+
/** A synchronous method that verifies incoming request events */
|
|
15
|
+
verifyEvent;
|
|
12
16
|
/** A fallback method to use for subscriptionMethod if none is passed in when creating the provider */
|
|
13
17
|
static subscriptionMethod = undefined;
|
|
14
18
|
/** A fallback method to use for publishMethod if none is passed in when creating the provider */
|
|
@@ -68,6 +72,7 @@ export class NostrConnectProvider {
|
|
|
68
72
|
/** A method called when a client requests to logout (end the session) */
|
|
69
73
|
onLogout;
|
|
70
74
|
constructor(options) {
|
|
75
|
+
this.verifyEvent = options.verifyEvent ?? NostrConnectProvider.verifyEvent;
|
|
71
76
|
this.relays = options.relays;
|
|
72
77
|
this.upstream = options.upstream;
|
|
73
78
|
this.signer = options.signer ?? new PrivateKeySigner();
|
|
@@ -189,7 +194,7 @@ export class NostrConnectProvider {
|
|
|
189
194
|
}
|
|
190
195
|
/** Call this method with incoming events */
|
|
191
196
|
async handleEvent(event) {
|
|
192
|
-
if (!verifyEvent(event))
|
|
197
|
+
if (!this.verifyEvent(event))
|
|
193
198
|
return;
|
|
194
199
|
// Do nothing if this request has already been seen
|
|
195
200
|
if (this.seen.has(event.id) || event.created_at <= this.seenUntil)
|
|
@@ -5,6 +5,8 @@ import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod,
|
|
|
5
5
|
import { Subscription } from "rxjs";
|
|
6
6
|
import { BunkerURI, NostrConnectAppMetadata, Nbunksec } from "../helpers/nostr-connect.js";
|
|
7
7
|
export type NostrConnectSignerOptions = NostrConnectionMethodsOptions & {
|
|
8
|
+
/** A synchronous method that verifies event hashes and signatures */
|
|
9
|
+
verifyEvent?: typeof verifyEvent;
|
|
8
10
|
/** The relays to communicate over */
|
|
9
11
|
relays: string[];
|
|
10
12
|
/** A {@link PrivateKeySigner} for this client */
|
|
@@ -34,6 +36,8 @@ export type NostrConnectLogoutOptions = {
|
|
|
34
36
|
timeout?: number;
|
|
35
37
|
};
|
|
36
38
|
export declare class NostrConnectSigner implements ISigner {
|
|
39
|
+
/** The default event verifier for new instances */
|
|
40
|
+
static verifyEvent: typeof verifyEvent;
|
|
37
41
|
/** A fallback method to use for subscriptionMethod if none is pass in when creating the signer */
|
|
38
42
|
static subscriptionMethod: NostrSubscriptionMethod | undefined;
|
|
39
43
|
/** A fallback method to use for publishMethod if none is pass in when creating the signer */
|
|
@@ -67,6 +71,7 @@ export declare class NostrConnectSigner implements ISigner {
|
|
|
67
71
|
autoSwitchRelays: boolean;
|
|
68
72
|
/** Client metadata sent with `connect` requests */
|
|
69
73
|
metadata?: NostrConnectAppMetadata;
|
|
74
|
+
/** A synchronous method that verifies response events and returned signed events */
|
|
70
75
|
verifyEvent: typeof verifyEvent;
|
|
71
76
|
/** A secret used when initiating a connection from the client side (the `secret` in a nostrconnect:// URI) */
|
|
72
77
|
connectSecret: string;
|
|
@@ -37,6 +37,8 @@ function redactAuthUrl(raw) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
export class NostrConnectSigner {
|
|
40
|
+
/** The default event verifier for new instances */
|
|
41
|
+
static verifyEvent = verifyEvent;
|
|
40
42
|
/** A fallback method to use for subscriptionMethod if none is pass in when creating the signer */
|
|
41
43
|
static subscriptionMethod = undefined;
|
|
42
44
|
/** A fallback method to use for publishMethod if none is pass in when creating the signer */
|
|
@@ -72,7 +74,8 @@ export class NostrConnectSigner {
|
|
|
72
74
|
autoSwitchRelays;
|
|
73
75
|
/** Client metadata sent with `connect` requests */
|
|
74
76
|
metadata;
|
|
75
|
-
|
|
77
|
+
/** A synchronous method that verifies response events and returned signed events */
|
|
78
|
+
verifyEvent;
|
|
76
79
|
/** A secret used when initiating a connection from the client side (the `secret` in a nostrconnect:// URI) */
|
|
77
80
|
connectSecret;
|
|
78
81
|
/** A secret used when connecting to a remote bunker (the `secret` in a bunker:// URI) */
|
|
@@ -87,6 +90,7 @@ export class NostrConnectSigner {
|
|
|
87
90
|
nip04;
|
|
88
91
|
nip44;
|
|
89
92
|
constructor(options) {
|
|
93
|
+
this.verifyEvent = options.verifyEvent ?? NostrConnectSigner.verifyEvent;
|
|
90
94
|
this.relays = options.relays;
|
|
91
95
|
this.pubkey = options.pubkey;
|
|
92
96
|
this.remote = options.remote;
|