applesauce-signers 0.0.0-next-20250323173930 → 0.0.0-next-20250327153627

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.
@@ -66,6 +66,10 @@ export type NostrConnectSignerOptions = {
66
66
  pubkey?: string;
67
67
  /** A method for handling "auth" requests */
68
68
  onAuth?: (url: string) => Promise<void>;
69
+ /** A method for subscribing to relays */
70
+ subscriptionMethod?: NostrSubscriptionMethod;
71
+ /** A method for publishing events */
72
+ publishMethod?: NostrPublishMethod;
69
73
  };
70
74
  interface Unsubscribable {
71
75
  unsubscribe(): void;
@@ -88,9 +92,9 @@ export type NostrConnectAppMetadata = {
88
92
  };
89
93
  export declare class NostrConnectSigner implements Nip07Interface {
90
94
  /** A method that is called when an event needs to be published */
91
- protected publish: NostrPublishMethod;
95
+ protected publishMethod: NostrPublishMethod;
92
96
  /** The active nostr subscription */
93
- protected subscription: NostrSubscriptionMethod;
97
+ protected subscriptionMethod: NostrSubscriptionMethod;
94
98
  protected log: import("debug").Debugger;
95
99
  /** The local client signer */
96
100
  signer: SimpleSigner;
@@ -118,7 +122,9 @@ export declare class NostrConnectSigner implements Nip07Interface {
118
122
  encrypt: (pubkey: string, plaintext: string) => Promise<string> | string;
119
123
  decrypt: (pubkey: string, ciphertext: string) => Promise<string> | string;
120
124
  } | undefined;
121
- constructor(subscription: NostrSubscriptionMethod, publish: NostrPublishMethod, opts: NostrConnectSignerOptions);
125
+ static subscriptionMethod: NostrSubscriptionMethod | undefined;
126
+ static publishMethod: NostrPublishMethod | undefined;
127
+ constructor(opts: NostrConnectSignerOptions);
122
128
  /** The currently active REQ subscription */
123
129
  protected req?: Unsubscribable;
124
130
  /** Open the connection */
@@ -161,7 +167,7 @@ export declare class NostrConnectSigner implements Nip07Interface {
161
167
  /** Builds an array of signing permissions for event kinds */
162
168
  static buildSigningPermissions(kinds: number[]): string[];
163
169
  /** Create a {@link NostrConnectSigner} from a bunker:// URI */
164
- static fromBunkerURI(uri: string, subscription: NostrSubscriptionMethod, publish: NostrPublishMethod, options: Omit<NostrConnectSignerOptions, "relays"> & {
170
+ static fromBunkerURI(uri: string, options: Omit<NostrConnectSignerOptions, "relays"> & {
165
171
  permissions?: string[];
166
172
  signer?: SimpleSigner;
167
173
  }): Promise<NostrConnectSigner>;
@@ -34,9 +34,9 @@ async function defaultHandleAuth(url) {
34
34
  }
35
35
  export class NostrConnectSigner {
36
36
  /** A method that is called when an event needs to be published */
37
- publish;
37
+ publishMethod;
38
38
  /** The active nostr subscription */
39
- subscription;
39
+ subscriptionMethod;
40
40
  log = logger.extend("NostrConnectSigner");
41
41
  /** The local client signer */
42
42
  signer;
@@ -60,12 +60,20 @@ export class NostrConnectSigner {
60
60
  clientSecret = nanoid(12);
61
61
  nip04;
62
62
  nip44;
63
- constructor(subscription, publish, opts) {
63
+ static subscriptionMethod = undefined;
64
+ static publishMethod = undefined;
65
+ constructor(opts) {
64
66
  this.relays = opts.relays;
65
67
  this.pubkey = opts.pubkey;
66
68
  this.remote = opts.remote;
67
- this.subscription = subscription;
68
- this.publish = publish;
69
+ const subscriptionMethod = opts.subscriptionMethod || NostrConnectSigner.subscriptionMethod;
70
+ if (!subscriptionMethod)
71
+ throw new Error("Missing subscriptionMethod, either pass a method or set NostrConnectSigner.subscriptionMethod");
72
+ const publishMethod = opts.publishMethod || NostrConnectSigner.publishMethod;
73
+ if (!publishMethod)
74
+ throw new Error("Missing publishMethod, either pass a method or set NostrConnectSigner.publishMethod");
75
+ this.subscriptionMethod = subscriptionMethod;
76
+ this.publishMethod = publishMethod;
69
77
  if (opts.onAuth)
70
78
  this.onAuth = opts.onAuth;
71
79
  this.signer = opts?.signer || new SimpleSigner();
@@ -87,7 +95,7 @@ export class NostrConnectSigner {
87
95
  this.subscriptionOpen = true;
88
96
  const pubkey = await this.signer.getPublicKey();
89
97
  // Setup subscription
90
- this.req = this.subscription([
98
+ this.req = this.subscriptionMethod([
91
99
  {
92
100
  kinds: [kinds.NostrConnect],
93
101
  "#p": [pubkey],
@@ -178,7 +186,7 @@ export class NostrConnectSigner {
178
186
  this.log(`Sending request ${id} (${method}) ${JSON.stringify(params)}`);
179
187
  const p = createDefer();
180
188
  this.requests.set(id, p);
181
- await this.publish?.(event, this.relays);
189
+ await this.publishMethod?.(event, this.relays);
182
190
  return p;
183
191
  }
184
192
  /** Connect to remote signer */
@@ -318,9 +326,9 @@ export class NostrConnectSigner {
318
326
  return [Permission.GetPublicKey, ...kinds.map((k) => `${Permission.SignEvent}:${k}`)];
319
327
  }
320
328
  /** Create a {@link NostrConnectSigner} from a bunker:// URI */
321
- static async fromBunkerURI(uri, subscription, publish, options) {
329
+ static async fromBunkerURI(uri, options) {
322
330
  const { remote, relays, secret } = NostrConnectSigner.parseBunkerURI(uri);
323
- const client = new NostrConnectSigner(subscription, publish, { relays, remote, ...options });
331
+ const client = new NostrConnectSigner({ relays, remote, ...options });
324
332
  await client.connect(secret, options.permissions);
325
333
  return client;
326
334
  }
@@ -9,10 +9,12 @@ describe("NostrConnectSigner", () => {
9
9
  const publish = vi.fn(async () => { });
10
10
  const client = new SimpleSigner();
11
11
  const remote = new SimpleSigner();
12
- const signer = new NostrConnectSigner(subscription, publish, {
12
+ const signer = new NostrConnectSigner({
13
13
  relays,
14
14
  remote: await remote.getPublicKey(),
15
15
  signer: client,
16
+ subscriptionMethod: subscription,
17
+ publishMethod: publish,
16
18
  });
17
19
  signer.connect();
18
20
  expect(subscription).toHaveBeenCalledWith([{ "#p": [await client.getPublicKey()], kinds: [24133] }], relays);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-signers",
3
- "version": "0.0.0-next-20250323173930",
3
+ "version": "0.0.0-next-20250327153627",
4
4
  "description": "Signer classes for applesauce",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -36,7 +36,7 @@
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.12.0",
39
+ "applesauce-core": "0.0.0-next-20250327153627",
40
40
  "debug": "^4.4.0",
41
41
  "nanoid": "^5.0.9",
42
42
  "nostr-tools": "^2.10.4"