@konemono/nostr-login 1.7.64 → 1.7.66
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
|
@@ -30,7 +30,8 @@ export class AmberDirectSigner implements Signer {
|
|
|
30
30
|
public async getPublicKey(id?: string): Promise<string> {
|
|
31
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
36
|
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
36
37
|
});
|
|
@@ -39,7 +40,8 @@ export class AmberDirectSigner implements Signer {
|
|
|
39
40
|
public async signEvent(event: any, id?: string): Promise<any> {
|
|
40
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
46
|
AmberDirectSigner.pendingResolves.set(id!, (result: string) => {
|
|
45
47
|
resolve(JSON.parse(result));
|
|
@@ -50,7 +52,8 @@ export class AmberDirectSigner implements Signer {
|
|
|
50
52
|
public async encrypt04(pubkey: string, plaintext: string, id?: string): Promise<string> {
|
|
51
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
58
|
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
56
59
|
});
|
|
@@ -59,7 +62,8 @@ export class AmberDirectSigner implements Signer {
|
|
|
59
62
|
public async decrypt04(pubkey: string, ciphertext: string, id?: string): Promise<string> {
|
|
60
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
68
|
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
65
69
|
});
|
|
@@ -68,7 +72,8 @@ export class AmberDirectSigner implements Signer {
|
|
|
68
72
|
public async encrypt44(pubkey: string, plaintext: string, id?: string): Promise<string> {
|
|
69
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
78
|
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
74
79
|
});
|
|
@@ -77,7 +82,8 @@ export class AmberDirectSigner implements Signer {
|
|
|
77
82
|
public async decrypt44(pubkey: string, ciphertext: string, id?: string): Promise<string> {
|
|
78
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
88
|
AmberDirectSigner.pendingResolves.set(id!, resolve);
|
|
83
89
|
});
|
|
@@ -89,21 +95,21 @@ export class AmberDirectSigner implements Signer {
|
|
|
89
95
|
const encodedContent = encodeURIComponent(content || '');
|
|
90
96
|
const encodedCallback = encodeURIComponent(callbackUrl);
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
sessionStorage.setItem('amber_last_timestamp', Date.now().toString());
|
|
98
|
+
localStorage.setItem('amber_last_type', type);
|
|
99
|
+
localStorage.setItem('amber_last_id', id);
|
|
100
|
+
localStorage.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 を拡張
|
|
@@ -130,18 +136,18 @@ export class AmberDirectSigner implements Signer {
|
|
|
130
136
|
href: window.location.href,
|
|
131
137
|
eventParam: url.searchParams.get('event'),
|
|
132
138
|
pathResult: result,
|
|
133
|
-
sessionId:
|
|
134
|
-
sessionType:
|
|
139
|
+
sessionId: localStorage.getItem('amber_last_id'),
|
|
140
|
+
sessionType: localStorage.getItem('amber_last_type')
|
|
135
141
|
});
|
|
136
142
|
|
|
137
143
|
if (!result) return null;
|
|
138
144
|
|
|
139
|
-
const id =
|
|
140
|
-
const type =
|
|
145
|
+
const id = localStorage.getItem('amber_last_id');
|
|
146
|
+
const type = localStorage.getItem('amber_last_type');
|
|
141
147
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
localStorage.removeItem('amber_last_id');
|
|
149
|
+
localStorage.removeItem('amber_last_type');
|
|
150
|
+
localStorage.removeItem('amber_last_timestamp');
|
|
145
151
|
|
|
146
152
|
if (id && type) {
|
|
147
153
|
return { id, type, result };
|
|
@@ -130,10 +130,26 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
130
130
|
// NIP-55では直接resultを使用するため、追加のキャッシュは不要
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
// ★ 追加: URL
|
|
133
|
+
// ★ 追加: URLクリーンアップをより徹底的に
|
|
134
134
|
const url = new URL(window.location.href);
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
let changed = false;
|
|
136
|
+
if (url.searchParams.has('event')) {
|
|
137
|
+
url.searchParams.delete('event');
|
|
138
|
+
changed = true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// パス末尾が結果と一致する場合はパスもクリア
|
|
142
|
+
const pathParts = url.pathname.split('/');
|
|
143
|
+
if (pathParts.length > 0 && pathParts[pathParts.length - 1] === response.result) {
|
|
144
|
+
pathParts.pop();
|
|
145
|
+
url.pathname = pathParts.join('/') || '/';
|
|
146
|
+
changed = true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (changed) {
|
|
150
|
+
console.log('Cleaning up Amber response URL', url.toString());
|
|
151
|
+
window.history.replaceState({}, '', url.toString());
|
|
152
|
+
}
|
|
137
153
|
}
|
|
138
154
|
}
|
|
139
155
|
|
|
@@ -587,7 +603,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
587
603
|
return !!this.readyCallback;
|
|
588
604
|
}
|
|
589
605
|
|
|
590
|
-
public
|
|
606
|
+
public startAuth() {
|
|
591
607
|
console.log("startAuth");
|
|
592
608
|
if (this.readyCallback) throw new Error('Already started');
|
|
593
609
|
|
|
@@ -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) {
|