applesauce-signers 3.1.0 → 4.1.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.
package/README.md CHANGED
@@ -37,12 +37,12 @@ A basic signer that holds the secret key in memory with NIP-04 and NIP-44 encryp
37
37
 
38
38
  ```ts
39
39
  // Create new signer with random key
40
- const signer = new SimpleSigner();
40
+ const signer = new PrivateKeySigner();
41
41
 
42
42
  // Or import existing key
43
43
  const key = new Uint8Array(32);
44
44
  window.crypto.getRandomValues(key);
45
- const signer = new SimpleSigner(key);
45
+ const signer = new PrivateKeySigner(key);
46
46
  ```
47
47
 
48
48
  ### Nostr Connect Signer (NIP-46)
@@ -5,4 +5,5 @@ export * from "./nostr-connect-signer.js";
5
5
  export * from "./password-signer.js";
6
6
  export * from "./readonly-signer.js";
7
7
  export * from "./serial-port-signer.js";
8
+ export * from "./private-key-signer.js";
8
9
  export * from "./simple-signer.js";
@@ -5,4 +5,5 @@ export * from "./nostr-connect-signer.js";
5
5
  export * from "./password-signer.js";
6
6
  export * from "./readonly-signer.js";
7
7
  export * from "./serial-port-signer.js";
8
+ export * from "./private-key-signer.js";
8
9
  export * from "./simple-signer.js";
@@ -7,7 +7,7 @@ import { filter, from, repeat, retry } from "rxjs";
7
7
  import { isNIP04 } from "../helpers/encryption.js";
8
8
  import { createBunkerURI, NostrConnectMethod, parseNostrConnectURI, } from "../helpers/nostr-connect.js";
9
9
  import { getConnectionMethods, } from "../interop.js";
10
- import { SimpleSigner } from "./simple-signer.js";
10
+ import { PrivateKeySigner } from "./private-key-signer.js";
11
11
  export class NostrConnectProvider {
12
12
  /** A fallback method to use for subscriptionMethod if none is passed in when creating the provider */
13
13
  static subscriptionMethod = undefined;
@@ -55,7 +55,7 @@ export class NostrConnectProvider {
55
55
  constructor(options) {
56
56
  this.relays = options.relays;
57
57
  this.upstream = options.upstream;
58
- this.signer = options.signer ?? new SimpleSigner();
58
+ this.signer = options.signer ?? new PrivateKeySigner();
59
59
  this.secret = options.secret;
60
60
  // Get the subscription and publish methods
61
61
  const { subscriptionMethod, publishMethod } = getConnectionMethods(options, NostrConnectProvider);
@@ -1,13 +1,13 @@
1
1
  import { Deferred } from "applesauce-core/promise";
2
- import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod, SimpleSigner } from "applesauce-signers";
2
+ import { ISigner, NostrConnectionMethodsOptions, NostrPool, NostrPublishMethod, NostrSubscriptionMethod, PrivateKeySigner } from "applesauce-signers";
3
3
  import { EventTemplate, NostrEvent, verifyEvent } from "nostr-tools";
4
4
  import { Subscription } from "rxjs";
5
5
  import { BunkerURI, NostrConnectAppMetadata } from "../helpers/nostr-connect.js";
6
6
  export type NostrConnectSignerOptions = NostrConnectionMethodsOptions & {
7
7
  /** The relays to communicate over */
8
8
  relays: string[];
9
- /** A {@link SimpleSigner} for this client */
10
- signer?: SimpleSigner;
9
+ /** A {@link PrivateKeySigner} for this client */
10
+ signer?: PrivateKeySigner;
11
11
  /** pubkey of the remote signer application */
12
12
  remote?: string;
13
13
  /** Users pubkey */
@@ -30,7 +30,7 @@ export declare class NostrConnectSigner implements ISigner {
30
30
  protected subscriptionMethod: NostrSubscriptionMethod;
31
31
  protected log: import("debug").Debugger;
32
32
  /** The local client signer */
33
- signer: SimpleSigner;
33
+ signer: PrivateKeySigner;
34
34
  /** Whether the signer is listening for events */
35
35
  listening: boolean;
36
36
  /** Whether the signer is connected to the remote signer */
@@ -97,6 +97,6 @@ export declare class NostrConnectSigner implements ISigner {
97
97
  /** Create a {@link NostrConnectSigner} from a bunker:// URI */
98
98
  static fromBunkerURI(uri: string, options?: Omit<NostrConnectSignerOptions, "relays"> & {
99
99
  permissions?: string[];
100
- signer?: SimpleSigner;
100
+ signer?: PrivateKeySigner;
101
101
  }): Promise<NostrConnectSigner>;
102
102
  }
@@ -1,7 +1,7 @@
1
1
  import { logger } from "applesauce-core";
2
2
  import { getHiddenContent, unixNow } from "applesauce-core/helpers";
3
3
  import { createDefer } from "applesauce-core/promise";
4
- import { SimpleSigner, getConnectionMethods, } from "applesauce-signers";
4
+ import { PrivateKeySigner, getConnectionMethods, } from "applesauce-signers";
5
5
  import { nanoid } from "nanoid";
6
6
  import { getPublicKey, kinds, verifyEvent } from "nostr-tools";
7
7
  import { filter, from, repeat, retry } from "rxjs";
@@ -58,7 +58,7 @@ export class NostrConnectSigner {
58
58
  if (options.onAuth)
59
59
  this.onAuth = options.onAuth;
60
60
  // Get or create the local signer
61
- this.signer = options?.signer || new SimpleSigner();
61
+ this.signer = options?.signer || new PrivateKeySigner();
62
62
  this.nip04 = {
63
63
  encrypt: this.nip04Encrypt.bind(this),
64
64
  decrypt: this.nip04Decrypt.bind(this),
@@ -0,0 +1,19 @@
1
+ import { EventTemplate } from "nostr-tools";
2
+ import { ISigner } from "../interop.js";
3
+ /** A Simple signer that holds the private key in memory */
4
+ export declare class PrivateKeySigner implements ISigner {
5
+ key: Uint8Array;
6
+ constructor(key?: Uint8Array);
7
+ getPublicKey(): Promise<string>;
8
+ signEvent(event: EventTemplate): Promise<import("nostr-tools").VerifiedEvent>;
9
+ nip04: {
10
+ encrypt: (pubkey: string, plaintext: string) => Promise<string>;
11
+ decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
12
+ };
13
+ nip44: {
14
+ encrypt: (pubkey: string, plaintext: string) => Promise<string>;
15
+ decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
16
+ };
17
+ /** Creates a PrivateKeySigner from a hex private key or NIP-19 nsec */
18
+ static fromKey(privateKey: Uint8Array | string): PrivateKeySigner;
19
+ }
@@ -0,0 +1,27 @@
1
+ import { normalizeToSecretKey } from "applesauce-core/helpers";
2
+ import { finalizeEvent, generateSecretKey, getPublicKey, nip04, nip44 } from "nostr-tools";
3
+ /** A Simple signer that holds the private key in memory */
4
+ export class PrivateKeySigner {
5
+ key;
6
+ constructor(key) {
7
+ this.key = key || generateSecretKey();
8
+ }
9
+ async getPublicKey() {
10
+ return getPublicKey(this.key);
11
+ }
12
+ async signEvent(event) {
13
+ return finalizeEvent(event, this.key);
14
+ }
15
+ nip04 = {
16
+ encrypt: async (pubkey, plaintext) => nip04.encrypt(this.key, pubkey, plaintext),
17
+ decrypt: async (pubkey, ciphertext) => nip04.decrypt(this.key, pubkey, ciphertext),
18
+ };
19
+ nip44 = {
20
+ encrypt: async (pubkey, plaintext) => nip44.v2.encrypt(plaintext, nip44.v2.utils.getConversationKey(this.key, pubkey)),
21
+ decrypt: async (pubkey, ciphertext) => nip44.v2.decrypt(ciphertext, nip44.v2.utils.getConversationKey(this.key, pubkey)),
22
+ };
23
+ /** Creates a PrivateKeySigner from a hex private key or NIP-19 nsec */
24
+ static fromKey(privateKey) {
25
+ return new PrivateKeySigner(normalizeToSecretKey(privateKey));
26
+ }
27
+ }
@@ -169,6 +169,7 @@ export class SerialPortSigner {
169
169
  const sharedSecret = hexToBytes(sharedSecretStr);
170
170
  let iv = Uint8Array.from(randomBytes(16));
171
171
  let plaintext = utf8Encoder.encode(text);
172
+ // @ts-ignore
172
173
  let cryptoKey = await crypto.subtle.importKey("raw", sharedSecret, { name: "AES-CBC" }, false, ["encrypt"]);
173
174
  let ciphertext = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, plaintext);
174
175
  let ctb64 = base64.encode(new Uint8Array(ciphertext));
@@ -179,9 +180,11 @@ export class SerialPortSigner {
179
180
  let [ctb64, ivb64] = data.split("?iv=");
180
181
  const sharedSecretStr = await this.callMethodOnDevice(SerialPortSigner.METHOD_SHARED_SECRET, [xOnlyToXY(pubkey)]);
181
182
  const sharedSecret = hexToBytes(sharedSecretStr);
183
+ // @ts-ignore
182
184
  let cryptoKey = await crypto.subtle.importKey("raw", sharedSecret, { name: "AES-CBC" }, false, ["decrypt"]);
183
185
  let ciphertext = base64.decode(ctb64);
184
186
  let iv = base64.decode(ivb64);
187
+ // @ts-ignore
185
188
  let plaintext = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, ciphertext);
186
189
  let text = utf8Decoder.decode(plaintext);
187
190
  return text;
@@ -1,19 +1,4 @@
1
- import { EventTemplate } from "nostr-tools";
2
- import { ISigner } from "../interop.js";
3
- /** A Simple NIP-07 signer class */
4
- export declare class SimpleSigner implements ISigner {
5
- key: Uint8Array;
6
- constructor(key?: Uint8Array);
7
- getPublicKey(): Promise<string>;
8
- signEvent(event: EventTemplate): Promise<import("nostr-tools").VerifiedEvent>;
9
- nip04: {
10
- encrypt: (pubkey: string, plaintext: string) => Promise<string>;
11
- decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
12
- };
13
- nip44: {
14
- encrypt: (pubkey: string, plaintext: string) => Promise<string>;
15
- decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
16
- };
17
- /** Creates a SimpleSigner from a hex private key or NIP-19 nsec */
18
- static fromKey(privateKey: Uint8Array | string): SimpleSigner;
19
- }
1
+ import { PrivateKeySigner } from "./private-key-signer.js";
2
+ /** @deprecated Use PrivateKeySigner instead */
3
+ declare const SimpleSigner: typeof PrivateKeySigner;
4
+ export { SimpleSigner };
@@ -1,27 +1,4 @@
1
- import { normalizeToSecretKey } from "applesauce-core/helpers";
2
- import { finalizeEvent, generateSecretKey, getPublicKey, nip04, nip44 } from "nostr-tools";
3
- /** A Simple NIP-07 signer class */
4
- export class SimpleSigner {
5
- key;
6
- constructor(key) {
7
- this.key = key || generateSecretKey();
8
- }
9
- async getPublicKey() {
10
- return getPublicKey(this.key);
11
- }
12
- async signEvent(event) {
13
- return finalizeEvent(event, this.key);
14
- }
15
- nip04 = {
16
- encrypt: async (pubkey, plaintext) => nip04.encrypt(this.key, pubkey, plaintext),
17
- decrypt: async (pubkey, ciphertext) => nip04.decrypt(this.key, pubkey, ciphertext),
18
- };
19
- nip44 = {
20
- encrypt: async (pubkey, plaintext) => nip44.v2.encrypt(plaintext, nip44.v2.utils.getConversationKey(this.key, pubkey)),
21
- decrypt: async (pubkey, ciphertext) => nip44.v2.decrypt(ciphertext, nip44.v2.utils.getConversationKey(this.key, pubkey)),
22
- };
23
- /** Creates a SimpleSigner from a hex private key or NIP-19 nsec */
24
- static fromKey(privateKey) {
25
- return new SimpleSigner(normalizeToSecretKey(privateKey));
26
- }
27
- }
1
+ import { PrivateKeySigner } from "./private-key-signer.js";
2
+ /** @deprecated Use PrivateKeySigner instead */
3
+ const SimpleSigner = PrivateKeySigner;
4
+ export { SimpleSigner };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-signers",
3
- "version": "3.1.0",
3
+ "version": "4.1.0",
4
4
  "description": "Signer classes for applesauce",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,8 +14,7 @@
14
14
  "author": "hzrd149",
15
15
  "license": "MIT",
16
16
  "files": [
17
- "dist",
18
- "applesauce"
17
+ "dist"
19
18
  ],
20
19
  "exports": {
21
20
  ".": {
@@ -32,21 +31,32 @@
32
31
  "import": "./dist/signers/*.js",
33
32
  "require": "./dist/signers/*.js",
34
33
  "types": "./dist/signers/*.d.ts"
34
+ },
35
+ "./helpers": {
36
+ "import": "./dist/helpers/index.js",
37
+ "require": "./dist/helpers/index.js",
38
+ "types": "./dist/helpers/index.d.ts"
39
+ },
40
+ "./helpers/*": {
41
+ "import": "./dist/helpers/*.js",
42
+ "require": "./dist/helpers/*.js",
43
+ "types": "./dist/helpers/*.d.ts"
35
44
  }
36
45
  },
37
46
  "dependencies": {
38
47
  "@noble/hashes": "^1.7.1",
39
48
  "@noble/secp256k1": "^1.7.1",
40
49
  "@scure/base": "^1.2.4",
41
- "applesauce-core": "^3.1.0",
50
+ "applesauce-core": "^4.1.0",
42
51
  "debug": "^4.4.0",
43
52
  "nanoid": "^5.0.9",
44
- "nostr-tools": "~2.15",
53
+ "nostr-tools": "~2.17",
45
54
  "rxjs": "^7.8.2"
46
55
  },
47
56
  "devDependencies": {
48
57
  "@types/debug": "^4.1.12",
49
58
  "@types/dom-serial": "^1.0.6",
59
+ "rimraf": "^6.0.1",
50
60
  "typescript": "^5.8.3",
51
61
  "vitest": "^3.1.3",
52
62
  "vitest-websocket-mock": "^0.5.0"
@@ -56,6 +66,7 @@
56
66
  "url": "lightning:nostrudel@geyser.fund"
57
67
  },
58
68
  "scripts": {
69
+ "prebuild": "rimraf dist",
59
70
  "build": "tsc",
60
71
  "watch:build": "tsc --watch > /dev/null",
61
72
  "test": "vitest run --passWithNoTests",