nappup 1.9.0 → 1.9.1

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/package.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "git+https://github.com/44billion/nappup.git"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "1.9.0",
9
+ "version": "1.9.1",
10
10
  "description": "Nostr App Uploader",
11
11
  "type": "module",
12
12
  "scripts": {
13
- "test": "node --test 'tests/**/*.test.js'",
14
- "test:only": "node --test --test-only 'tests/**/*.test.js'"
13
+ "test": "node --test --experimental-test-module-mocks 'tests/**/*.test.js'",
14
+ "test:only": "node --test --test-only --experimental-test-module-mocks 'tests/**/*.test.js'"
15
15
  },
16
16
  "bin": {
17
17
  "nappup": "bin/nappup/index.js"
@@ -23,7 +23,7 @@
23
23
  "file-type": "^21.0.0",
24
24
  "mime-types": "^3.0.1",
25
25
  "nmmr": "^1.0.9",
26
- "nostr-tools": "^2.15.0"
26
+ "nostr-tools": "^2.23.3"
27
27
  },
28
28
  "devDependencies": {
29
29
  "eslint": "^9.22.0",
@@ -2,7 +2,6 @@ import { generateSecretKey } from 'nostr-tools/pure'
2
2
  import { BunkerSigner, parseBunkerInput } from 'nostr-tools/nip46'
3
3
  import { getRelays } from '#helpers/signer.js'
4
4
 
5
- const CONNECT_TIMEOUT = 30_000
6
5
  const createToken = Symbol('createToken')
7
6
 
8
7
  export default class NostrBunkerSigner {
@@ -15,18 +14,25 @@ export default class NostrBunkerSigner {
15
14
  this.#publicKey = publicKey
16
15
  }
17
16
 
18
- static async create (bunkerUrl) {
17
+ static async create (bunkerUrl, { connectTimeout = 30_000 } = {}) {
19
18
  const bp = await parseBunkerInput(bunkerUrl)
20
19
  if (!bp) throw new Error('Invalid bunker URL')
21
20
  if (bp.relays.length === 0) throw new Error('Bunker URL must include at least one relay (?relay=wss://...)')
22
21
 
23
22
  const clientSk = generateSecretKey()
24
- const bunker = new BunkerSigner(clientSk, bp)
25
-
26
- await Promise.race([
27
- bunker.connect(),
28
- new Promise((_, reject) => setTimeout(() => reject(new Error('Bunker connection timed out')), CONNECT_TIMEOUT))
29
- ])
23
+ const bunker = BunkerSigner.fromBunker(clientSk, bp)
24
+
25
+ let timeoutHandle
26
+ try {
27
+ await Promise.race([
28
+ bunker.connect(),
29
+ new Promise((resolve, reject) => {
30
+ timeoutHandle = setTimeout(() => reject(new Error('Bunker connection timed out')), connectTimeout)
31
+ })
32
+ ])
33
+ } finally {
34
+ clearTimeout(timeoutHandle)
35
+ }
30
36
 
31
37
  const publicKey = await bunker.getPublicKey()
32
38
  return new this(createToken, bunker, publicKey)