@konemono/nostr-login 1.7.36 → 1.7.38
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/dist/index.d.ts +2 -2
- package/dist/index.esm.js +41 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/AuthNostrService.d.ts +3 -3
- package/dist/modules/BannerManager.d.ts +1 -1
- package/dist/modules/ModalManager.d.ts +1 -1
- package/dist/modules/Nip46.d.ts +8 -10
- package/dist/modules/Nostr.d.ts +1 -1
- package/dist/modules/NostrParams.d.ts +1 -1
- package/dist/modules/Signer.d.ts +0 -9
- package/dist/types.d.ts +1 -1
- package/dist/unpkg.js +41 -12
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/nip44.d.ts +1 -1
- package/package.json +7 -7
- package/src/const/index.ts +1 -2
- package/src/iife-module.ts +2 -7
- package/src/index.ts +2 -7
- package/src/modules/AuthNostrService.ts +168 -57
- package/src/modules/BannerManager.ts +1 -1
- package/src/modules/ModalManager.ts +58 -51
- package/src/modules/Nip46.ts +92 -263
- package/src/modules/Nostr.ts +1 -1
- package/src/modules/NostrParams.ts +1 -1
- package/src/modules/ProcessManager.ts +18 -57
- package/src/modules/Signer.ts +2 -1
- package/src/types.ts +31 -1
- package/src/utils/index.ts +1 -1
|
@@ -2,7 +2,6 @@ import { EventEmitter } from 'tseep';
|
|
|
2
2
|
import { CALL_TIMEOUT } from '../const';
|
|
3
3
|
|
|
4
4
|
class ProcessManager extends EventEmitter {
|
|
5
|
-
private paused = false;
|
|
6
5
|
private callCount: number = 0;
|
|
7
6
|
private callTimer: NodeJS.Timeout | undefined;
|
|
8
7
|
|
|
@@ -11,41 +10,22 @@ class ProcessManager extends EventEmitter {
|
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
public onAuthUrl() {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (Boolean(this.callTimer)) {
|
|
14
|
+
clearTimeout(this.callTimer);
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
public onIframeUrl() {
|
|
19
|
-
|
|
20
|
-
this.resetTimer();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public resetTimer() {
|
|
24
|
-
// 既存のタイマーがあればクリア
|
|
25
|
-
if (this.callTimer) {
|
|
19
|
+
if (Boolean(this.callTimer)) {
|
|
26
20
|
clearTimeout(this.callTimer);
|
|
27
|
-
this.callTimer = undefined; // IDをクリア
|
|
28
|
-
console.log('ProcessManager: timer reset');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 監視対象が残っていて、かつ一時停止中でなければ、新しいタイマーを設定
|
|
32
|
-
if (this.callCount > 0 && !this.paused) {
|
|
33
|
-
this.callTimer = setTimeout(() => {
|
|
34
|
-
console.log('ProcessManager: timeout reached, emitting onCallTimeout');
|
|
35
|
-
this.callTimer = undefined; // タイムアウト時にIDをクリア
|
|
36
|
-
this.emit('onCallTimeout');
|
|
37
|
-
}, CALL_TIMEOUT);
|
|
38
|
-
console.log(`ProcessManager: new timer set for ${CALL_TIMEOUT} ms`);
|
|
39
21
|
}
|
|
40
22
|
}
|
|
41
23
|
|
|
42
24
|
public async wait<T>(cb: () => Promise<T>): Promise<T> {
|
|
43
|
-
|
|
25
|
+
// FIXME only allow 1 parallel req
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// waitの最初の呼び出し時のみ、タイマーを初期設定
|
|
48
|
-
this.resetTimer();
|
|
27
|
+
if (!this.callTimer) {
|
|
28
|
+
this.callTimer = setTimeout(() => this.emit('onCallTimeout'), CALL_TIMEOUT);
|
|
49
29
|
}
|
|
50
30
|
|
|
51
31
|
if (!this.callCount) {
|
|
@@ -54,52 +34,33 @@ class ProcessManager extends EventEmitter {
|
|
|
54
34
|
|
|
55
35
|
this.callCount++;
|
|
56
36
|
|
|
57
|
-
let error
|
|
58
|
-
let result
|
|
37
|
+
let error;
|
|
38
|
+
let result;
|
|
59
39
|
|
|
60
|
-
// 非同期処理の実行
|
|
61
40
|
try {
|
|
62
41
|
result = await cb();
|
|
63
42
|
} catch (e) {
|
|
64
43
|
error = e;
|
|
65
44
|
}
|
|
66
45
|
|
|
67
|
-
// ★ 修正点: クリーンアップロジックを resetTimer に置き換え
|
|
68
|
-
// ProcessManagerの呼び出しカウントをデクリメント
|
|
69
46
|
this.callCount--;
|
|
70
|
-
this.emit('onCallEnd');
|
|
71
|
-
|
|
72
|
-
// リクエスト完了後、タイマーをリセットし、callCountに応じて再設定
|
|
73
|
-
this.resetTimer();
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
if (error) {
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
return result as T;
|
|
82
|
-
}
|
|
48
|
+
this.emit('onCallEnd');
|
|
83
49
|
|
|
84
|
-
public pause() {
|
|
85
|
-
console.log('ProcessManager: PAUSING timer...');
|
|
86
50
|
if (this.callTimer) {
|
|
87
51
|
clearTimeout(this.callTimer);
|
|
88
52
|
}
|
|
89
|
-
this.callTimer = undefined; // タイマーをクリア
|
|
90
|
-
this.paused = true;
|
|
91
|
-
this.emit('onCallPause');
|
|
92
|
-
}
|
|
93
53
|
|
|
94
|
-
|
|
95
|
-
console.log('ProcessManager: RESUMING timer...');
|
|
96
|
-
this.paused = false;
|
|
54
|
+
this.callTimer = undefined;
|
|
97
55
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.resetTimer();
|
|
56
|
+
if (error) {
|
|
57
|
+
throw error;
|
|
101
58
|
}
|
|
102
|
-
|
|
59
|
+
|
|
60
|
+
// we can't return undefined bcs an exception is
|
|
61
|
+
// thrown above on error
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
return result;
|
|
103
64
|
}
|
|
104
65
|
}
|
|
105
66
|
|
package/src/modules/Signer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
|
|
1
|
+
/* import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
|
|
2
2
|
import { Nip44 } from '../utils/nip44';
|
|
3
3
|
import { getPublicKey } from 'nostr-tools';
|
|
4
4
|
|
|
@@ -23,3 +23,4 @@ export class PrivateKeySigner extends NDKPrivateKeySigner {
|
|
|
23
23
|
return Promise.resolve(this.nip44.decrypt(this.privateKey!, sender.pubkey, value));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
*/
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface NostrLoginAuthOptions {
|
|
|
10
10
|
name?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// NOTE: must be a subset of CURRENT_MODULE enum
|
|
13
14
|
export type StartScreens =
|
|
14
15
|
| 'welcome'
|
|
15
16
|
| 'welcome-login'
|
|
@@ -26,27 +27,56 @@ export type StartScreens =
|
|
|
26
27
|
| 'import';
|
|
27
28
|
|
|
28
29
|
export interface NostrLoginOptions {
|
|
30
|
+
// optional
|
|
29
31
|
theme?: string;
|
|
30
32
|
startScreen?: StartScreens;
|
|
31
33
|
bunkers?: string;
|
|
32
34
|
onAuth?: (npub: string, options: NostrLoginAuthOptions) => void;
|
|
33
35
|
perms?: string;
|
|
34
36
|
darkMode?: boolean;
|
|
37
|
+
|
|
38
|
+
// do not show the banner, modals must be `launch`-ed
|
|
35
39
|
noBanner?: boolean;
|
|
40
|
+
|
|
41
|
+
// forward reqs to this bunker origin for testing
|
|
36
42
|
devOverrideBunkerOrigin?: string;
|
|
43
|
+
|
|
44
|
+
// deprecated, use methods=['local']
|
|
45
|
+
// use local signup instead of nostr connect
|
|
37
46
|
localSignup?: boolean;
|
|
47
|
+
|
|
48
|
+
// allowed auth methods
|
|
38
49
|
methods?: AuthMethod[];
|
|
50
|
+
|
|
51
|
+
// otp endpoints
|
|
39
52
|
otpRequestUrl?: string;
|
|
40
53
|
otpReplyUrl?: string;
|
|
54
|
+
|
|
55
|
+
// welcome screen's title/desc
|
|
41
56
|
title?: string;
|
|
42
57
|
description?: string;
|
|
58
|
+
|
|
59
|
+
// comma-separated list of relays added
|
|
60
|
+
// to relay list of new profiles created with local signup
|
|
43
61
|
signupRelays?: string;
|
|
62
|
+
|
|
63
|
+
// relay list to override hardcoded `OUTBOX_RELAYS` constant
|
|
44
64
|
outboxRelays?: string[];
|
|
65
|
+
|
|
66
|
+
// dev mode
|
|
45
67
|
dev?: boolean;
|
|
68
|
+
|
|
69
|
+
// use start.njump.me instead of local signup
|
|
46
70
|
signupNstart?: boolean;
|
|
71
|
+
|
|
72
|
+
// list of npubs to auto/suggest-follow on signup
|
|
47
73
|
followNpubs?: string;
|
|
74
|
+
|
|
75
|
+
// when method call auth needed, instead of showing
|
|
76
|
+
// the modal, we start waiting for incoming nip46
|
|
77
|
+
// connection and send the nostrconnect string using
|
|
78
|
+
// nlNeedAuth event
|
|
48
79
|
customNostrConnect?: boolean;
|
|
49
|
-
connectRelays?: string[];
|
|
50
80
|
}
|
|
51
81
|
|
|
52
82
|
export interface IBanner {
|
package/src/utils/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Info, RecentType } from 'nostr-login-components';
|
|
1
|
+
import { Info, RecentType } from 'nostr-login-components/dist/types/types';
|
|
2
2
|
import NDK, { NDKEvent, NDKRelaySet, NDKSigner, NDKUser } from '@nostr-dev-kit/ndk';
|
|
3
3
|
import { generatePrivateKey } from 'nostr-tools';
|
|
4
4
|
import { NostrLoginOptions } from '../types';
|