@konemono/nostr-login 1.10.3 → 1.10.4
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
|
@@ -171,7 +171,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
171
171
|
return info;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
public async createNostrConnect(
|
|
174
|
+
public async createNostrConnect(relays?: string[]) {
|
|
175
175
|
this.nostrConnectKey = generatePrivateKey();
|
|
176
176
|
this.nostrConnectSecret = Math.random().toString(36).substring(7);
|
|
177
177
|
|
|
@@ -183,11 +183,12 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
183
183
|
perms: encodeURIComponent(this.params.optionsModal.perms || ''),
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
const relayParams = relays && relays.length > 0 ? relays.map(r => `&relay=${encodeURIComponent(r)}`).join('') : '';
|
|
187
|
+
return `nostrconnect://${pubkey}?image=${meta.icon}&url=${meta.url}&name=${meta.name}&perms=${meta.perms}&secret=${this.nostrConnectSecret}${relayParams}`;
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
public async getNostrConnectServices(): Promise<[string, ConnectionString[]]> {
|
|
190
|
-
const nostrconnect = await this.createNostrConnect();
|
|
190
|
+
public async getNostrConnectServices(customRelays?: string[]): Promise<[string, ConnectionString[]]> {
|
|
191
|
+
const nostrconnect = await this.createNostrConnect(customRelays);
|
|
191
192
|
|
|
192
193
|
// copy defaults
|
|
193
194
|
const apps = NOSTRCONNECT_APPS.map(a => ({ ...a }));
|
|
@@ -203,20 +204,23 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
203
204
|
// }
|
|
204
205
|
|
|
205
206
|
for (const a of apps) {
|
|
206
|
-
let
|
|
207
|
+
let relays = customRelays && customRelays.length > 0 ? customRelays : [DEFAULT_NOSTRCONNECT_RELAY];
|
|
207
208
|
if (a.link.startsWith('https://')) {
|
|
208
209
|
let domain = a.domain || new URL(a.link).hostname;
|
|
209
210
|
try {
|
|
210
211
|
const info = await (await fetch(`https://${domain}/.well-known/nostr.json`)).json();
|
|
211
212
|
const pubkey = info.names['_'];
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
213
|
+
const fetchedRelays = info.nip46[pubkey] as string[];
|
|
214
|
+
if (fetchedRelays && fetchedRelays.length && (!customRelays || customRelays.length === 0)) {
|
|
215
|
+
relays = fetchedRelays;
|
|
216
|
+
}
|
|
214
217
|
a.iframeUrl = info.nip46.iframe_url || '';
|
|
215
218
|
} catch (e) {
|
|
216
219
|
console.log('Bad app info', e, a);
|
|
217
220
|
}
|
|
218
221
|
}
|
|
219
|
-
const
|
|
222
|
+
const relayParams = relays.map(r => `&relay=${encodeURIComponent(r)}`).join('');
|
|
223
|
+
const nc = nostrconnect + relayParams;
|
|
220
224
|
if (a.iframeUrl) {
|
|
221
225
|
// pass plain nc url for iframe-based flow
|
|
222
226
|
a.link = nc;
|
|
@@ -92,7 +92,7 @@ class ModalManager extends EventEmitter {
|
|
|
92
92
|
this.modal.isLoadingExtension = false;
|
|
93
93
|
this.modal.isLoading = false;
|
|
94
94
|
|
|
95
|
-
[this.modal.connectionString, this.modal.connectionStringServices] = await this.authNostrService.getNostrConnectServices();
|
|
95
|
+
[this.modal.connectionString, this.modal.connectionStringServices] = await this.authNostrService.getNostrConnectServices(this.customNip46Relays);
|
|
96
96
|
|
|
97
97
|
dialog.appendChild(this.modal);
|
|
98
98
|
document.body.appendChild(dialog);
|