applesauce-signers 7.1.0 → 7.3.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.
@@ -9,6 +9,9 @@ export declare class AmberClipboardSigner implements ISigner {
9
9
  static SUPPORTED: false | (() => Promise<string>);
10
10
  private pendingRequest;
11
11
  pubkey?: string;
12
+ /** The default event verifier for new instances */
13
+ static verifyEvent: typeof verifyEvent;
14
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
12
15
  verifyEvent: typeof verifyEvent;
13
16
  nip04: {
14
17
  encrypt: (pubkey: string, plaintext: string) => Promise<string>;
@@ -18,7 +21,10 @@ export declare class AmberClipboardSigner implements ISigner {
18
21
  encrypt: (pubkey: string, plaintext: string) => Promise<string>;
19
22
  decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
20
23
  };
21
- constructor();
24
+ constructor(options?: {
25
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
26
+ verifyEvent?: typeof verifyEvent;
27
+ });
22
28
  private onVisibilityChange;
23
29
  private intentRequest;
24
30
  /** Reject the currently pending request */
@@ -13,10 +13,14 @@ export class AmberClipboardSigner {
13
13
  navigator.clipboard.readText;
14
14
  pendingRequest = null;
15
15
  pubkey;
16
- verifyEvent = verifyEvent;
16
+ /** The default event verifier for new instances */
17
+ static verifyEvent = verifyEvent;
18
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
19
+ verifyEvent;
17
20
  nip04;
18
21
  nip44;
19
- constructor() {
22
+ constructor(options) {
23
+ this.verifyEvent = options?.verifyEvent ?? AmberClipboardSigner.verifyEvent;
20
24
  document.addEventListener("visibilitychange", this.onVisibilityChange);
21
25
  this.nip04 = {
22
26
  encrypt: this.nip04Encrypt.bind(this),
@@ -6,6 +6,9 @@ export declare class AndroidNativeSigner implements ISigner {
6
6
  connected: boolean;
7
7
  permissions: Permission[];
8
8
  private pubkey;
9
+ /** The default event verifier for new instances */
10
+ static verifyEvent: typeof verifyEvent;
11
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
9
12
  verifyEvent: typeof verifyEvent;
10
13
  nip04: {
11
14
  encrypt: (pubkey: string, plaintext: string) => Promise<string>;
@@ -15,7 +18,10 @@ export declare class AndroidNativeSigner implements ISigner {
15
18
  encrypt: (pubkey: string, plaintext: string) => Promise<string>;
16
19
  decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
17
20
  };
18
- constructor(packageName: string, pubkey?: string);
21
+ constructor(packageName: string, pubkey?: string, options?: {
22
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
23
+ verifyEvent?: typeof verifyEvent;
24
+ });
19
25
  static getSignerApps(): Promise<AppInfo[]>;
20
26
  setup(): Promise<void>;
21
27
  getPublicKey(): Promise<string>;
@@ -6,11 +6,15 @@ export class AndroidNativeSigner {
6
6
  connected = false;
7
7
  permissions = [];
8
8
  pubkey = null;
9
- verifyEvent = verifyEvent;
9
+ /** The default event verifier for new instances */
10
+ static verifyEvent = verifyEvent;
11
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
12
+ verifyEvent;
10
13
  nip04;
11
14
  nip44;
12
- constructor(packageName, pubkey) {
15
+ constructor(packageName, pubkey, options) {
13
16
  this.packageName = packageName;
17
+ this.verifyEvent = options?.verifyEvent ?? AndroidNativeSigner.verifyEvent;
14
18
  this.pubkey = pubkey ?? null;
15
19
  this.nip04 = {
16
20
  encrypt: this.nip04Encrypt.bind(this),
@@ -1,10 +1,18 @@
1
- import { EventTemplate, VerifiedEvent } from "applesauce-core/helpers/event";
1
+ import { EventTemplate, VerifiedEvent, verifyEvent } from "applesauce-core/helpers/event";
2
2
  import { ISigner } from "../interop.js";
3
3
  /** AN error that is throw when the window.nostr extension is missing */
4
4
  export declare class ExtensionMissingError extends Error {
5
5
  }
6
6
  /** A signer that is a proxy for window.nostr */
7
7
  export declare class ExtensionSigner implements ISigner {
8
+ /** The default event verifier for new instances */
9
+ static verifyEvent: typeof verifyEvent;
10
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
11
+ verifyEvent: typeof verifyEvent;
12
+ constructor(options?: {
13
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
14
+ verifyEvent?: typeof verifyEvent;
15
+ });
8
16
  get nip04(): {
9
17
  encrypt: (pubkey: string, plaintext: string) => Promise<string>;
10
18
  decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
@@ -5,6 +5,13 @@ export class ExtensionMissingError extends Error {
5
5
  }
6
6
  /** A signer that is a proxy for window.nostr */
7
7
  export class ExtensionSigner {
8
+ /** The default event verifier for new instances */
9
+ static verifyEvent = verifyEvent;
10
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
11
+ verifyEvent;
12
+ constructor(options) {
13
+ this.verifyEvent = options?.verifyEvent ?? ExtensionSigner.verifyEvent;
14
+ }
8
15
  get nip04() {
9
16
  return window.nostr?.nip04;
10
17
  }
@@ -27,7 +34,7 @@ export class ExtensionSigner {
27
34
  if (!window.nostr)
28
35
  throw new ExtensionMissingError("Signer extension missing");
29
36
  const event = await window.nostr.signEvent(template);
30
- if (!verifyEvent(event))
37
+ if (!this.verifyEvent(event))
31
38
  throw new Error("Extension returned an invalid event");
32
39
  return event;
33
40
  }
@@ -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
- verifyEvent = verifyEvent;
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;
@@ -15,12 +15,18 @@ export declare class SerialPortSigner implements ISigner {
15
15
  protected writer: WritableStreamDefaultWriter<string> | null;
16
16
  pubkey?: string;
17
17
  get isConnected(): boolean;
18
+ /** The default event verifier for new instances */
19
+ static verifyEvent: typeof verifyEvent;
20
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
18
21
  verifyEvent: typeof verifyEvent;
19
22
  nip04: {
20
23
  encrypt: (pubkey: string, plaintext: string) => Promise<string>;
21
24
  decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
22
25
  };
23
- constructor();
26
+ constructor(options?: {
27
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
28
+ verifyEvent?: typeof verifyEvent;
29
+ });
24
30
  protected lastCommand: Deferred<string> | null;
25
31
  callMethodOnDevice(method: string, params: string[], opts?: DeviceOpts): Promise<string>;
26
32
  connectToDevice({ onConnect, onDisconnect, onError, onDone }: DeviceOpts): Promise<void>;
@@ -26,9 +26,13 @@ export class SerialPortSigner {
26
26
  get isConnected() {
27
27
  return !!this.writer;
28
28
  }
29
- verifyEvent = verifyEvent;
29
+ /** The default event verifier for new instances */
30
+ static verifyEvent = verifyEvent;
31
+ /** A synchronous method that verifies event hashes and signatures returned by the signer */
32
+ verifyEvent;
30
33
  nip04;
31
- constructor() {
34
+ constructor(options) {
35
+ this.verifyEvent = options?.verifyEvent ?? SerialPortSigner.verifyEvent;
32
36
  this.nip04 = {
33
37
  encrypt: this.nip04Encrypt.bind(this),
34
38
  decrypt: this.nip04Decrypt.bind(this),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-signers",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "Signer classes for applesauce",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",