@konemono/nostr-login 1.7.55 → 1.7.57
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
|
@@ -119,42 +119,40 @@ export class AmberDirectSigner implements Signer {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
private generateUrl(content: string, type: string, id: string, recipient?: string): string {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
const url = new URL(window.location.origin + window.location.pathname);
|
|
123
|
+
url.searchParams.set('amberType', type);
|
|
124
|
+
url.searchParams.set('amberId', id);
|
|
125
125
|
|
|
126
126
|
const params = new URLSearchParams();
|
|
127
127
|
params.set('type', type);
|
|
128
128
|
params.set('id', id);
|
|
129
|
-
params.set('callbackUrl',
|
|
130
|
-
|
|
131
|
-
if (recipient)
|
|
129
|
+
params.set('callbackUrl', url.toString());
|
|
130
|
+
params.set('name', document.title || window.location.hostname || 'Nostr Login');
|
|
131
|
+
if (recipient) {
|
|
132
|
+
params.set('pubkey', recipient);
|
|
133
|
+
} else if (this._pubkey) {
|
|
134
|
+
params.set('pubkey', this._pubkey);
|
|
135
|
+
}
|
|
132
136
|
|
|
133
|
-
|
|
137
|
+
const dataPart = content ? encodeURIComponent(content) : '/';
|
|
138
|
+
return `nostrsigner:${dataPart}?${params.toString()}`;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
public static parseResponse(): { type: string; id: string; result: string } | null {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
type = type || hashParams.get('amberType');
|
|
146
|
-
id = id || hashParams.get('amberId');
|
|
147
|
-
result = result || hashParams.get('signature') || hashParams.get('result');
|
|
148
|
-
}
|
|
142
|
+
const url = new URL(window.location.href);
|
|
143
|
+
const params = new URLSearchParams(url.search);
|
|
144
|
+
const hashParams = new URLSearchParams(url.hash.substring(1));
|
|
145
|
+
|
|
146
|
+
let type = params.get('amberType') || hashParams.get('amberType');
|
|
147
|
+
let id = params.get('amberId') || hashParams.get('amberId');
|
|
148
|
+
let result = params.get('signature') || params.get('result') || params.get('pubKey') ||
|
|
149
|
+
hashParams.get('signature') || hashParams.get('result') || hashParams.get('pubKey');
|
|
149
150
|
|
|
150
151
|
if (type && id && result) {
|
|
151
152
|
// Clean up URL
|
|
152
153
|
const newUrl = new URL(window.location.href);
|
|
153
|
-
newUrl.searchParams.delete(
|
|
154
|
-
newUrl.
|
|
155
|
-
newUrl.searchParams.delete('signature');
|
|
156
|
-
newUrl.searchParams.delete('result');
|
|
157
|
-
newUrl.hash = ''; // Clear hash too
|
|
154
|
+
['amberType', 'amberId', 'signature', 'result', 'pubKey'].forEach(p => newUrl.searchParams.delete(p));
|
|
155
|
+
newUrl.hash = '';
|
|
158
156
|
window.history.replaceState({}, '', newUrl.toString());
|
|
159
157
|
|
|
160
158
|
return { type, id, result };
|
|
@@ -86,17 +86,24 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
86
86
|
decrypt: this.decrypt44.bind(this),
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
setTimeout(() => this.checkAmberResponse(),
|
|
89
|
+
setTimeout(() => this.checkAmberResponse(), 100);
|
|
90
|
+
|
|
91
|
+
window.addEventListener('focus', () => {
|
|
92
|
+
console.log('Window focused, checking Amber response');
|
|
93
|
+
this.checkAmberResponse();
|
|
94
|
+
});
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
private checkAmberResponse() {
|
|
93
98
|
const response = AmberDirectSigner.parseResponse();
|
|
94
99
|
if (response) {
|
|
100
|
+
console.log('Amber response detected', response);
|
|
95
101
|
if (response.type === 'get_public_key') {
|
|
96
102
|
const info: Info = {
|
|
97
103
|
pubkey: response.result,
|
|
98
104
|
authMethod: 'amber' as any,
|
|
99
105
|
};
|
|
106
|
+
console.log('Amber login success', info);
|
|
100
107
|
this.onAuth('login', info);
|
|
101
108
|
} else {
|
|
102
109
|
const pendingKey = `amber_pending_${response.id}`;
|