@konemono/nostr-login 1.10.3 → 1.10.5
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
|
@@ -9,9 +9,9 @@ import { Signer } from './Nostr';
|
|
|
9
9
|
import { Nip44 } from '../utils/nip44';
|
|
10
10
|
import { IframeNostrRpc, Nip46Signer, ReadyListener } from './Nip46';
|
|
11
11
|
import { PrivateKeySigner } from './Signer';
|
|
12
|
+
import { DEFAULT_NIP46_RELAYS } from '../const';
|
|
12
13
|
|
|
13
14
|
const OUTBOX_RELAYS = ['wss://user.kindpag.es', 'wss://purplepag.es', 'wss://relay.nos.social'];
|
|
14
|
-
const DEFAULT_NOSTRCONNECT_RELAY = 'wss://relay.nsec.app/';
|
|
15
15
|
const NOSTRCONNECT_APPS: ConnectionString[] = [
|
|
16
16
|
{
|
|
17
17
|
name: 'Nsec.app',
|
|
@@ -19,19 +19,16 @@ const NOSTRCONNECT_APPS: ConnectionString[] = [
|
|
|
19
19
|
canImport: true,
|
|
20
20
|
img: 'https://nsec.app/assets/favicon.ico',
|
|
21
21
|
link: 'https://use.nsec.app/<nostrconnect>',
|
|
22
|
-
relay: 'wss://relay.nsec.app/',
|
|
23
22
|
},
|
|
24
23
|
{
|
|
25
24
|
name: 'Amber',
|
|
26
25
|
img: 'https://raw.githubusercontent.com/greenart7c3/Amber/refs/heads/master/assets/android-icon.svg',
|
|
27
26
|
link: '<nostrconnect>',
|
|
28
|
-
relay: 'wss://relay.nsec.app/',
|
|
29
27
|
},
|
|
30
28
|
{
|
|
31
29
|
name: 'Other key stores',
|
|
32
30
|
img: '',
|
|
33
31
|
link: '<nostrconnect>',
|
|
34
|
-
relay: 'wss://relay.nsec.app/',
|
|
35
32
|
},
|
|
36
33
|
];
|
|
37
34
|
|
|
@@ -138,7 +135,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
138
135
|
} = {},
|
|
139
136
|
) {
|
|
140
137
|
// カスタムリレーが指定されていれば使用、そうでなければ単一リレーまたはデフォルト
|
|
141
|
-
const relays = customRelays && customRelays.length > 0 ? customRelays : [relay
|
|
138
|
+
const relays = customRelays && customRelays.length > 0 ? customRelays : relay ? [relay] : DEFAULT_NIP46_RELAYS;
|
|
142
139
|
|
|
143
140
|
const info: Info = {
|
|
144
141
|
authMethod: 'connect',
|
|
@@ -171,7 +168,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
171
168
|
return info;
|
|
172
169
|
}
|
|
173
170
|
|
|
174
|
-
public async createNostrConnect(
|
|
171
|
+
public async createNostrConnect(relays?: string[]) {
|
|
175
172
|
this.nostrConnectKey = generatePrivateKey();
|
|
176
173
|
this.nostrConnectSecret = Math.random().toString(36).substring(7);
|
|
177
174
|
|
|
@@ -183,11 +180,12 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
183
180
|
perms: encodeURIComponent(this.params.optionsModal.perms || ''),
|
|
184
181
|
};
|
|
185
182
|
|
|
186
|
-
|
|
183
|
+
const relayParams = relays && relays.length > 0 ? relays.map(r => `&relay=${encodeURIComponent(r)}`).join('') : '';
|
|
184
|
+
return `nostrconnect://${pubkey}?image=${meta.icon}&url=${meta.url}&name=${meta.name}&perms=${meta.perms}&secret=${this.nostrConnectSecret}${relayParams}`;
|
|
187
185
|
}
|
|
188
186
|
|
|
189
|
-
public async getNostrConnectServices(): Promise<[string, ConnectionString[]]> {
|
|
190
|
-
const nostrconnect = await this.createNostrConnect();
|
|
187
|
+
public async getNostrConnectServices(customRelays?: string[]): Promise<[string, ConnectionString[]]> {
|
|
188
|
+
const nostrconnect = await this.createNostrConnect(customRelays);
|
|
191
189
|
|
|
192
190
|
// copy defaults
|
|
193
191
|
const apps = NOSTRCONNECT_APPS.map(a => ({ ...a }));
|
|
@@ -203,20 +201,23 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
203
201
|
// }
|
|
204
202
|
|
|
205
203
|
for (const a of apps) {
|
|
206
|
-
let
|
|
204
|
+
let relays = customRelays && customRelays.length > 0 ? customRelays : DEFAULT_NIP46_RELAYS;
|
|
207
205
|
if (a.link.startsWith('https://')) {
|
|
208
206
|
let domain = a.domain || new URL(a.link).hostname;
|
|
209
207
|
try {
|
|
210
208
|
const info = await (await fetch(`https://${domain}/.well-known/nostr.json`)).json();
|
|
211
209
|
const pubkey = info.names['_'];
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
210
|
+
const fetchedRelays = info.nip46[pubkey] as string[];
|
|
211
|
+
if (fetchedRelays && fetchedRelays.length && (!customRelays || customRelays.length === 0)) {
|
|
212
|
+
relays = fetchedRelays;
|
|
213
|
+
}
|
|
214
214
|
a.iframeUrl = info.nip46.iframe_url || '';
|
|
215
215
|
} catch (e) {
|
|
216
216
|
console.log('Bad app info', e, a);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
const
|
|
219
|
+
const relayParams = relays.map(r => `&relay=${encodeURIComponent(r)}`).join('');
|
|
220
|
+
const nc = nostrconnect + relayParams;
|
|
220
221
|
if (a.iframeUrl) {
|
|
221
222
|
// pass plain nc url for iframe-based flow
|
|
222
223
|
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);
|