@konemono/nostr-login 1.7.11
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/.prettierrc.json +13 -0
- package/README.md +167 -0
- package/dist/const/index.d.ts +1 -0
- package/dist/iife-module.d.ts +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.esm.js +18 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/modules/AuthNostrService.d.ts +84 -0
- package/dist/modules/BannerManager.d.ts +20 -0
- package/dist/modules/ModalManager.d.ts +25 -0
- package/dist/modules/Nip46.d.ts +56 -0
- package/dist/modules/Nostr.d.ts +34 -0
- package/dist/modules/NostrExtensionService.d.ts +17 -0
- package/dist/modules/NostrParams.d.ts +8 -0
- package/dist/modules/Popup.d.ts +7 -0
- package/dist/modules/ProcessManager.d.ts +10 -0
- package/dist/modules/Signer.d.ts +9 -0
- package/dist/modules/index.d.ts +8 -0
- package/dist/types.d.ts +72 -0
- package/dist/unpkg.js +17 -0
- package/dist/utils/index.d.ts +27 -0
- package/dist/utils/nip44.d.ts +9 -0
- package/index.html +30 -0
- package/package.json +28 -0
- package/rollup.config.js +55 -0
- package/src/const/index.ts +1 -0
- package/src/iife-module.ts +81 -0
- package/src/index.ts +347 -0
- package/src/modules/AuthNostrService.ts +756 -0
- package/src/modules/BannerManager.ts +146 -0
- package/src/modules/ModalManager.ts +635 -0
- package/src/modules/Nip46.ts +441 -0
- package/src/modules/Nostr.ts +107 -0
- package/src/modules/NostrExtensionService.ts +99 -0
- package/src/modules/NostrParams.ts +18 -0
- package/src/modules/Popup.ts +27 -0
- package/src/modules/ProcessManager.ts +67 -0
- package/src/modules/Signer.ts +25 -0
- package/src/modules/index.ts +8 -0
- package/src/types.ts +124 -0
- package/src/utils/index.ts +326 -0
- package/src/utils/nip44.ts +185 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { NostrLoginOptions, TypeBanner } from '../types';
|
|
2
|
+
import { NostrParams } from '.';
|
|
3
|
+
import { Info } from 'nostr-login-components';
|
|
4
|
+
import { EventEmitter } from 'tseep';
|
|
5
|
+
import { getDarkMode } from '../utils';
|
|
6
|
+
import { ReadyListener } from './Nip46';
|
|
7
|
+
|
|
8
|
+
class BannerManager extends EventEmitter {
|
|
9
|
+
private banner: TypeBanner | null = null;
|
|
10
|
+
private iframeReady?: ReadyListener;
|
|
11
|
+
|
|
12
|
+
private params: NostrParams;
|
|
13
|
+
|
|
14
|
+
constructor(params: NostrParams) {
|
|
15
|
+
super();
|
|
16
|
+
this.params = params;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public onAuthUrl(url: string, iframeUrl: string) {
|
|
20
|
+
if (this.banner) {
|
|
21
|
+
if (url)
|
|
22
|
+
this.banner.notify = {
|
|
23
|
+
mode: iframeUrl ? 'iframeAuthUrl' : 'authUrl',
|
|
24
|
+
url,
|
|
25
|
+
};
|
|
26
|
+
else
|
|
27
|
+
this.banner.notify = {
|
|
28
|
+
mode: '',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public onIframeRestart(iframeUrl: string) {
|
|
34
|
+
if (this.banner) {
|
|
35
|
+
this.iframeReady = new ReadyListener(['rebinderDone', 'rebinderError'], new URL(iframeUrl).origin);
|
|
36
|
+
this.banner.notify = {
|
|
37
|
+
mode: 'rebind',
|
|
38
|
+
url: iframeUrl,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public onUserInfo(info: Info | null) {
|
|
44
|
+
if (this.banner) {
|
|
45
|
+
this.banner.userInfo = info;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public onCallTimeout() {
|
|
50
|
+
if (this.banner) {
|
|
51
|
+
this.banner.notify = {
|
|
52
|
+
mode: 'timeout',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public onCallStart() {
|
|
58
|
+
if (this.banner) {
|
|
59
|
+
this.banner.isLoading = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async onCallEnd() {
|
|
64
|
+
if (this.banner) {
|
|
65
|
+
if (this.iframeReady) {
|
|
66
|
+
await this.iframeReady.wait();
|
|
67
|
+
this.iframeReady = undefined;
|
|
68
|
+
}
|
|
69
|
+
this.banner.isLoading = false;
|
|
70
|
+
this.banner.notify = { mode: '' };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public onUpdateAccounts(accounts: Info[]) {
|
|
75
|
+
if (this.banner) {
|
|
76
|
+
this.banner.accounts = accounts;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public onDarkMode(dark: boolean) {
|
|
81
|
+
if (this.banner) this.banner.darkMode = dark;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public launchAuthBanner(opt: NostrLoginOptions) {
|
|
85
|
+
this.banner = document.createElement('nl-banner');
|
|
86
|
+
|
|
87
|
+
this.banner.setAttribute('dark-mode', String(getDarkMode(opt)));
|
|
88
|
+
|
|
89
|
+
if (opt.theme) this.banner.setAttribute('theme', opt.theme);
|
|
90
|
+
if (opt.noBanner) this.banner.setAttribute('hidden-mode', 'true');
|
|
91
|
+
|
|
92
|
+
this.banner.addEventListener('handleLoginBanner', (event: any) => {
|
|
93
|
+
this.emit('launch', event.detail);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.banner.addEventListener('handleConfirmLogout', () => {
|
|
97
|
+
this.emit('onConfirmLogout');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
this.banner.addEventListener('handleLogoutBanner', async () => {
|
|
101
|
+
this.emit('logout');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
this.banner.addEventListener('handleImportModal', (event: any) => {
|
|
105
|
+
this.emit('import');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
this.banner.addEventListener('handleNotifyConfirmBanner', (event: any) => {
|
|
109
|
+
this.emit('onAuthUrlClick', event.detail);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.banner.addEventListener('handleNotifyConfirmBannerIframe', (event: any) => {
|
|
113
|
+
this.emit('onIframeAuthUrlClick', event.detail);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
this.banner.addEventListener('handleSwitchAccount', (event: any) => {
|
|
117
|
+
this.emit('onSwitchAccount', event.detail);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
this.banner.addEventListener('handleOpenWelcomeModal', () => {
|
|
121
|
+
this.emit('launch');
|
|
122
|
+
|
|
123
|
+
if (this.banner) {
|
|
124
|
+
this.banner.isOpen = false;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// this.banner.addEventListener('handleRetryConfirmBanner', () => {
|
|
129
|
+
// const url = this.listNotifies.pop();
|
|
130
|
+
// // FIXME go to nip05 domain?
|
|
131
|
+
// if (!url) {
|
|
132
|
+
// return;
|
|
133
|
+
// }
|
|
134
|
+
|
|
135
|
+
// if (this.banner) {
|
|
136
|
+
// this.banner.listNotifies = this.listNotifies;
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
// this.emit('onAuthUrlClick', url);
|
|
140
|
+
// });
|
|
141
|
+
|
|
142
|
+
document.body.appendChild(this.banner);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default BannerManager;
|