@konemono/nostr-login 1.7.63 → 1.7.65
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.esm.js +1 -1
- package/dist/modules/AmberDirectSigner.d.ts +7 -7
- package/dist/modules/AuthNostrService.d.ts +2 -2
- package/dist/unpkg.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/src/modules/AmberDirectSigner.ts +40 -34
- package/src/modules/AuthNostrService.ts +15 -3
- package/src/modules/ModalManager.ts +2 -2
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -148,7 +148,11 @@ export class NostrLoginInitializer {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
private openPopup(url: string) {
|
|
151
|
-
|
|
151
|
+
if (url.startsWith('nostrsigner:')) {
|
|
152
|
+
window.location.href = url;
|
|
153
|
+
} else {
|
|
154
|
+
this.popupManager.openPopup(url);
|
|
155
|
+
}
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
private async switchAccount(info: Info, signup = false) {
|
|
@@ -27,83 +27,89 @@ export class AmberDirectSigner implements Signer {
|
|
|
27
27
|
decrypt: (pubkey: string, ciphertext: string) => this.decrypt44(pubkey, ciphertext),
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
public async getPublicKey(): Promise<string> {
|
|
31
|
-
|
|
30
|
+
public async getPublicKey(id?: string): Promise<string> {
|
|
31
|
+
id = id || Math.random().toString(36).substring(7);
|
|
32
32
|
const url = this.generateUrl('', 'get_public_key', id);
|
|
33
|
-
|
|
33
|
+
console.log('Amber redirecting to:', url);
|
|
34
|
+
window.location.assign(url);
|
|
34
35
|
return new Promise((resolve) => {
|
|
35
|
-
AmberDirectSigner.pendingResolves.set(id
|
|
36
|
+
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
public async signEvent(event: any): Promise<any> {
|
|
40
|
-
|
|
40
|
+
public async signEvent(event: any, id?: string): Promise<any> {
|
|
41
|
+
id = id || Math.random().toString(36).substring(7);
|
|
41
42
|
const url = this.generateUrl(JSON.stringify(event), 'sign_event', id);
|
|
42
|
-
|
|
43
|
+
console.log('Amber redirecting to:', url);
|
|
44
|
+
window.location.assign(url);
|
|
43
45
|
return new Promise((resolve) => {
|
|
44
|
-
AmberDirectSigner.pendingResolves.set(id
|
|
46
|
+
AmberDirectSigner.pendingResolves.set(id!, (result: string) => {
|
|
45
47
|
resolve(JSON.parse(result));
|
|
46
48
|
});
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
public async encrypt04(pubkey: string, plaintext: string): Promise<string> {
|
|
51
|
-
|
|
52
|
+
public async encrypt04(pubkey: string, plaintext: string, id?: string): Promise<string> {
|
|
53
|
+
id = id || Math.random().toString(36).substring(7);
|
|
52
54
|
const url = this.generateUrl(plaintext, 'nip04_encrypt', id, pubkey);
|
|
53
|
-
|
|
55
|
+
console.log('Amber redirecting to:', url);
|
|
56
|
+
window.location.assign(url);
|
|
54
57
|
return new Promise((resolve) => {
|
|
55
|
-
AmberDirectSigner.pendingResolves.set(id
|
|
58
|
+
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
56
59
|
});
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
public async decrypt04(pubkey: string, ciphertext: string): Promise<string> {
|
|
60
|
-
|
|
62
|
+
public async decrypt04(pubkey: string, ciphertext: string, id?: string): Promise<string> {
|
|
63
|
+
id = id || Math.random().toString(36).substring(7);
|
|
61
64
|
const url = this.generateUrl(ciphertext, 'nip04_decrypt', id, pubkey);
|
|
62
|
-
|
|
65
|
+
console.log('Amber redirecting to:', url);
|
|
66
|
+
window.location.assign(url);
|
|
63
67
|
return new Promise((resolve) => {
|
|
64
|
-
AmberDirectSigner.pendingResolves.set(id
|
|
68
|
+
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
65
69
|
});
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
public async encrypt44(pubkey: string, plaintext: string): Promise<string> {
|
|
69
|
-
|
|
72
|
+
public async encrypt44(pubkey: string, plaintext: string, id?: string): Promise<string> {
|
|
73
|
+
id = id || Math.random().toString(36).substring(7);
|
|
70
74
|
const url = this.generateUrl(plaintext, 'nip44_encrypt', id, pubkey);
|
|
71
|
-
|
|
75
|
+
console.log('Amber redirecting to:', url);
|
|
76
|
+
window.location.assign(url);
|
|
72
77
|
return new Promise((resolve) => {
|
|
73
|
-
AmberDirectSigner.pendingResolves.set(id
|
|
78
|
+
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
74
79
|
});
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
public async decrypt44(pubkey: string, ciphertext: string): Promise<string> {
|
|
78
|
-
|
|
82
|
+
public async decrypt44(pubkey: string, ciphertext: string, id?: string): Promise<string> {
|
|
83
|
+
id = id || Math.random().toString(36).substring(7);
|
|
79
84
|
const url = this.generateUrl(ciphertext, 'nip44_decrypt', id, pubkey);
|
|
80
|
-
|
|
85
|
+
console.log('Amber redirecting to:', url);
|
|
86
|
+
window.location.assign(url);
|
|
81
87
|
return new Promise((resolve) => {
|
|
82
|
-
AmberDirectSigner.pendingResolves.set(id
|
|
88
|
+
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
83
89
|
});
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
|
|
87
|
-
|
|
93
|
+
public generateUrl(content: string, type: string, id: string, pubkey?: string): string {
|
|
88
94
|
const callbackUrl = window.location.href.split('#')[0].split('?')[0];
|
|
89
95
|
const encodedContent = encodeURIComponent(content || '');
|
|
90
96
|
const encodedCallback = encodeURIComponent(callbackUrl);
|
|
91
97
|
|
|
92
|
-
// ★ 追加: sessionStorageに保存(これが無い)
|
|
93
98
|
sessionStorage.setItem('amber_last_type', type);
|
|
94
99
|
sessionStorage.setItem('amber_last_id', id);
|
|
95
100
|
sessionStorage.setItem('amber_last_timestamp', Date.now().toString());
|
|
96
101
|
|
|
97
102
|
// NIP-55準拠: nostrsigner: スキーム
|
|
98
103
|
let url = `nostrsigner:${encodedContent}`;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const params = new URLSearchParams();
|
|
105
|
+
params.append('compressionType', 'none');
|
|
106
|
+
params.append('returnType', 'signature');
|
|
107
|
+
params.append('type', type);
|
|
108
|
+
params.append('callbackUrl', callbackUrl);
|
|
109
|
+
if (pubkey) params.append('pubkey', pubkey);
|
|
110
|
+
if (this._pubkey) params.append('current_user', this._pubkey);
|
|
111
|
+
|
|
112
|
+
return `${url}?${params.toString()}`;
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
// AmberDirectSigner.ts の parseResponse を拡張
|
|
@@ -193,9 +193,21 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
193
193
|
if (link && !iframeUrl) {
|
|
194
194
|
if (link === 'amber') {
|
|
195
195
|
const signer = new AmberDirectSigner();
|
|
196
|
-
|
|
196
|
+
this.amberSigner = signer;
|
|
197
|
+
|
|
198
|
+
const id = Math.random().toString(36).substring(7);
|
|
199
|
+
const url = signer.generateUrl('', 'get_public_key', id);
|
|
197
200
|
this.emit('onAuthUrl', { url });
|
|
198
|
-
|
|
201
|
+
|
|
202
|
+
const pubkey = await signer.getPublicKey(id);
|
|
203
|
+
|
|
204
|
+
const info: Info = {
|
|
205
|
+
pubkey,
|
|
206
|
+
authMethod: 'amber' as any,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
this.onAuth('login', info);
|
|
210
|
+
return info;
|
|
199
211
|
}
|
|
200
212
|
window.open(link, '_blank', 'width=400,height=700');
|
|
201
213
|
}
|
|
@@ -575,7 +587,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
575
587
|
return !!this.readyCallback;
|
|
576
588
|
}
|
|
577
589
|
|
|
578
|
-
public
|
|
590
|
+
public startAuth() {
|
|
579
591
|
console.log("startAuth");
|
|
580
592
|
if (this.readyCallback) throw new Error('Already started');
|
|
581
593
|
|
|
@@ -27,7 +27,7 @@ class ModalManager extends EventEmitter {
|
|
|
27
27
|
if (this.launcherPromise) {
|
|
28
28
|
try {
|
|
29
29
|
await this.launcherPromise;
|
|
30
|
-
} catch {}
|
|
30
|
+
} catch { }
|
|
31
31
|
this.launcherPromise = undefined;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -141,7 +141,7 @@ class ModalManager extends EventEmitter {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
try {
|
|
144
|
-
if (!options || options.start)
|
|
144
|
+
if (!options || options.start) this.authNostrService.startAuth();
|
|
145
145
|
await body();
|
|
146
146
|
if (!options || options.end) await done(ok);
|
|
147
147
|
} catch (e: any) {
|