@konemono/nostr-login 1.7.58 → 1.7.59
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
|
@@ -52,10 +52,28 @@ export class AmberDirectSigner implements Signer {
|
|
|
52
52
|
sessionStorage.setItem(`amber_pending_${id}`, JSON.stringify({ hash, type }));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
public static resolvePending(id: string, result: string) {
|
|
56
|
-
|
|
55
|
+
public static resolvePending(id: string, type: string, result: string) {
|
|
56
|
+
// Try resolving by ID first
|
|
57
|
+
let resolve = this.pendingResolves.get(id);
|
|
58
|
+
|
|
59
|
+
// Fallback: If no ID match, try resolving by type if only one is pending of that type
|
|
60
|
+
if (!resolve) {
|
|
61
|
+
console.log('No direct ID match for Amber resolve, searching by type', { id, type });
|
|
62
|
+
for (const [pendingId, pendingResolve] of this.pendingResolves.entries()) {
|
|
63
|
+
const pending = sessionStorage.getItem(`amber_pending_${pendingId}`);
|
|
64
|
+
if (pending) {
|
|
65
|
+
const { type: pendingType } = JSON.parse(pending);
|
|
66
|
+
if (pendingType === type) {
|
|
67
|
+
resolve = pendingResolve;
|
|
68
|
+
id = pendingId;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
57
75
|
if (resolve) {
|
|
58
|
-
console.log('Resolving pending Amber promise', id);
|
|
76
|
+
console.log('Resolving pending Amber promise', { id, type });
|
|
59
77
|
resolve(result);
|
|
60
78
|
this.pendingResolves.delete(id);
|
|
61
79
|
return true;
|
|
@@ -142,32 +160,37 @@ export class AmberDirectSigner implements Signer {
|
|
|
142
160
|
|
|
143
161
|
private generateUrl(content: string, type: string, id: string, recipient?: string): string {
|
|
144
162
|
const callbackUrl = new URL(window.location.origin + window.location.pathname);
|
|
163
|
+
|
|
164
|
+
// Preserve other relevant current URL params if necessary, but avoid amber internal ones
|
|
165
|
+
const currentParams = new URLSearchParams(window.location.search);
|
|
166
|
+
currentParams.forEach((value, key) => {
|
|
167
|
+
if (!['amberType', 'amberId', 'signature', 'result', 'pubKey', 'pubkey'].includes(key)) {
|
|
168
|
+
callbackUrl.searchParams.set(key, value);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
145
172
|
callbackUrl.searchParams.set('amberType', type);
|
|
146
173
|
callbackUrl.searchParams.set('amberId', id);
|
|
147
174
|
|
|
148
|
-
const action = `com.greenart7c3.nostrsigner.${type.toUpperCase()}`;
|
|
149
175
|
const name = document.title || window.location.hostname || 'Nostr Login';
|
|
150
176
|
|
|
151
|
-
const params =
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
177
|
+
const params = new URLSearchParams();
|
|
178
|
+
params.set('type', type);
|
|
179
|
+
params.set('id', id);
|
|
180
|
+
params.set('callbackUrl', callbackUrl.toString());
|
|
181
|
+
params.set('name', name);
|
|
182
|
+
params.set('app_name', name); // Alias just in case
|
|
157
183
|
|
|
158
184
|
if (recipient) {
|
|
159
|
-
params.
|
|
185
|
+
params.set('pubkey', recipient);
|
|
186
|
+
params.set('pubKey', recipient); // Alias
|
|
160
187
|
} else if (this._pubkey) {
|
|
161
|
-
params.
|
|
188
|
+
params.set('pubkey', this._pubkey);
|
|
189
|
+
params.set('pubKey', this._pubkey); // Alias
|
|
162
190
|
}
|
|
163
191
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
} else {
|
|
167
|
-
params.push(`S.content=${encodeURIComponent(content)}`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return `intent:#Intent;action=${action};package=com.greenart7c3.nostrsigner;${params.join(';')};end`;
|
|
192
|
+
const dataPart = content ? encodeURIComponent(content) : '/';
|
|
193
|
+
return `nostrsigner:${dataPart}?${params.toString()}`;
|
|
171
194
|
}
|
|
172
195
|
|
|
173
196
|
public static parseResponse(): { type: string; id: string; result: string } | null {
|
|
@@ -175,19 +198,25 @@ export class AmberDirectSigner implements Signer {
|
|
|
175
198
|
const params = new URLSearchParams(url.search);
|
|
176
199
|
const hashParams = new URLSearchParams(url.hash.substring(1));
|
|
177
200
|
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
201
|
+
const getParam = (name: string) => params.get(name) || hashParams.get(name);
|
|
202
|
+
|
|
203
|
+
const type = getParam('amberType') || getParam('type');
|
|
204
|
+
const id = getParam('amberId') || getParam('id');
|
|
205
|
+
const result = getParam('signature') || getParam('result') || getParam('pubKey') || getParam('pubkey');
|
|
206
|
+
|
|
207
|
+
if (type && result) {
|
|
208
|
+
// ID might be missing in some older redirect cases, but we need it for precise resolution
|
|
209
|
+
const finalId = id || '';
|
|
182
210
|
|
|
183
|
-
if (type && id && result) {
|
|
184
211
|
// Clean up URL
|
|
185
212
|
const newUrl = new URL(window.location.href);
|
|
186
|
-
['amberType', 'amberId', 'signature', 'result', 'pubKey', 'pubkey'].forEach(p =>
|
|
213
|
+
['amberType', 'amberId', 'signature', 'result', 'pubKey', 'pubkey', 'type', 'id'].forEach(p => {
|
|
214
|
+
newUrl.searchParams.delete(p);
|
|
215
|
+
});
|
|
187
216
|
newUrl.hash = '';
|
|
188
217
|
window.history.replaceState({}, '', newUrl.toString());
|
|
189
218
|
|
|
190
|
-
return { type, id, result };
|
|
219
|
+
return { type, id: finalId, result };
|
|
191
220
|
}
|
|
192
221
|
return null;
|
|
193
222
|
}
|
|
@@ -100,7 +100,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
100
100
|
console.log('Amber response detected', response);
|
|
101
101
|
|
|
102
102
|
// Resolve pending promises if any (for non-reload cases)
|
|
103
|
-
AmberDirectSigner.resolvePending(response.id, response.result);
|
|
103
|
+
AmberDirectSigner.resolvePending(response.id, response.type, response.result);
|
|
104
104
|
|
|
105
105
|
if (response.type === 'get_public_key') {
|
|
106
106
|
const info: Info = {
|