@konemono/nostr-login 1.7.27 → 1.7.30

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.7.27",
3
+ "version": "1.7.30",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -572,7 +572,8 @@ class AuthNostrService extends EventEmitter implements Signer {
572
572
  }
573
573
  }
574
574
 
575
- public async signEvent(event: any) {
575
+ public async signEvent(ev: any) {
576
+ const event = { ...ev };
576
577
  if (this.localSigner) {
577
578
  event.pubkey = getPublicKey(this.localSigner.privateKey!);
578
579
  event.id = getEventHash(event);
@@ -3,71 +3,92 @@ import { CALL_TIMEOUT } from '../const';
3
3
 
4
4
  class ProcessManager extends EventEmitter {
5
5
  private paused = false;
6
- private callCount = 0;
7
- private callTimer?: NodeJS.Timeout;
6
+ private callCount: number = 0;
7
+ private callTimer: NodeJS.Timeout | undefined;
8
8
 
9
9
  constructor() {
10
10
  super();
11
11
  }
12
12
 
13
13
  public onAuthUrl() {
14
+ console.log('ProcessManager.onAuthUrl called, resetting timer');
14
15
  this.resetTimer();
15
16
  }
16
17
 
17
18
  public onIframeUrl() {
19
+ console.log('ProcessManager.onIframeUrl called, resetting timer');
18
20
  this.resetTimer();
19
21
  }
20
22
 
21
- private startTimer() {
22
- if (this.paused) return;
23
- if (this.callTimer) clearTimeout(this.callTimer);
24
-
25
- this.callTimer = setTimeout(() => {
26
- this.emit('onCallTimeout');
27
- }, CALL_TIMEOUT);
28
- }
29
-
30
23
  private resetTimer() {
24
+ if (this.callTimer) {
25
+ clearTimeout(this.callTimer);
26
+ console.log('ProcessManager: timer reset');
27
+ }
31
28
  if (this.callCount > 0) {
32
- this.startTimer();
29
+ this.callTimer = setTimeout(() => {
30
+ console.log('ProcessManager: timeout reached, emitting onCallTimeout');
31
+ this.emit('onCallTimeout');
32
+ }, CALL_TIMEOUT);
33
+ console.log(`ProcessManager: new timer set for ${CALL_TIMEOUT} ms`);
33
34
  }
34
35
  }
35
36
 
36
37
  public async wait<T>(cb: () => Promise<T>): Promise<T> {
37
- if (this.callCount === 0) {
38
+ console.log('ProcessManager.wait called, callTimer exists:', !!this.callTimer, 'callCount:', this.callCount);
39
+
40
+ if (!this.callTimer) {
41
+ this.callTimer = setTimeout(() => {
42
+ console.log('ProcessManager: timeout reached, emitting onCallTimeout');
43
+ this.emit('onCallTimeout');
44
+ }, CALL_TIMEOUT);
45
+ console.log(`Setting up timeout timer for ${CALL_TIMEOUT} ms`);
46
+ }
47
+
48
+ if (!this.callCount) {
38
49
  this.emit('onCallStart');
39
50
  }
40
51
 
41
52
  this.callCount++;
42
- this.startTimer();
53
+
54
+ let error;
55
+ let result;
43
56
 
44
57
  try {
45
- return await cb();
46
- } finally {
47
- this.callCount--;
48
-
49
- if (this.callCount === 0) {
50
- if (this.callTimer) {
51
- clearTimeout(this.callTimer);
52
- this.callTimer = undefined;
53
- }
54
- this.emit('onCallEnd');
55
- }
58
+ result = await cb();
59
+ } catch (e) {
60
+ error = e;
56
61
  }
57
- }
58
62
 
59
- public pause() {
60
- this.paused = true;
63
+ this.callCount--;
64
+
65
+ this.emit('onCallEnd');
66
+
61
67
  if (this.callTimer) {
62
68
  clearTimeout(this.callTimer);
63
- this.callTimer = undefined;
64
69
  }
70
+
71
+ this.callTimer = undefined;
72
+
73
+ if (error) {
74
+ throw error;
75
+ }
76
+
77
+ // @ts-ignore
78
+ return result;
79
+ }
80
+ public pause() {
81
+ if (this.callTimer) clearTimeout(this.callTimer);
82
+ this.callTimer = undefined;
83
+ this.paused = true;
65
84
  }
66
85
 
67
86
  public resume() {
68
87
  this.paused = false;
69
- if (this.callCount > 0) {
70
- this.startTimer();
88
+ if (this.callCount > 0 && !this.callTimer) {
89
+ this.callTimer = setTimeout(() => {
90
+ this.emit('onCallTimeout');
91
+ }, CALL_TIMEOUT);
71
92
  }
72
93
  }
73
94
  }