@konemono/nostr-login 1.11.6 → 1.11.7
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/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/Nip46.d.ts +0 -3
- package/dist/unpkg.js +1 -1
- package/package.json +1 -1
- package/src/modules/AuthNostrService.ts +1 -0
- package/src/modules/Nip46.ts +13 -19
package/package.json
CHANGED
|
@@ -610,6 +610,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
610
610
|
const localSigner = new PrivateKeySigner(info.sk!);
|
|
611
611
|
this.signer = new Nip46Signer(this.ndk, localSigner, info.signerPubkey!, info.iframeUrl ? new URL(info.iframeUrl!).origin : undefined);
|
|
612
612
|
|
|
613
|
+
|
|
613
614
|
// ★ once を使う - 1回だけ実行される ★
|
|
614
615
|
this.signer.once('connectionLost', async () => {
|
|
615
616
|
console.log('Connection lost, attempting to reconnect...');
|
package/src/modules/Nip46.ts
CHANGED
|
@@ -388,7 +388,7 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
388
388
|
private _rpc: IframeNostrRpc;
|
|
389
389
|
private lastPingTime: number = 0;
|
|
390
390
|
private pingCacheDuration: number = 30000; // 30秒
|
|
391
|
-
|
|
391
|
+
|
|
392
392
|
|
|
393
393
|
constructor(ndk: NDK, localSigner: PrivateKeySigner, signerPubkey: string, iframeOrigin?: string) {
|
|
394
394
|
super(ndk, signerPubkey, localSigner);
|
|
@@ -401,25 +401,18 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
401
401
|
});
|
|
402
402
|
|
|
403
403
|
this.rpc = this._rpc;
|
|
404
|
-
|
|
404
|
+
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
get userPubkey() {
|
|
408
408
|
return this._userPubkey;
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
// Use a different name to avoid conflict with base class property
|
|
412
|
-
get remotePubkeyAccessor() {
|
|
413
|
-
return this._remotePubkey;
|
|
414
|
-
}
|
|
415
411
|
|
|
416
|
-
set remotePubkeyAccessor(value: string | undefined) {
|
|
417
|
-
this._remotePubkey = value;
|
|
418
|
-
}
|
|
419
412
|
|
|
420
413
|
// 接続確認(必要時のみping)
|
|
421
414
|
private async ensureConnection(retries: number = 2): Promise<void> {
|
|
422
|
-
if (!this.
|
|
415
|
+
if (!this.remotePubkey) return;
|
|
423
416
|
|
|
424
417
|
const now = Date.now();
|
|
425
418
|
|
|
@@ -430,7 +423,7 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
430
423
|
|
|
431
424
|
for (let i = 0; i <= retries; i++) {
|
|
432
425
|
try {
|
|
433
|
-
await this._rpc.pingWithTimeout(this.
|
|
426
|
+
await this._rpc.pingWithTimeout(this.remotePubkey, 10000);
|
|
434
427
|
this.lastPingTime = now;
|
|
435
428
|
console.log('Connection check OK');
|
|
436
429
|
return;
|
|
@@ -448,7 +441,7 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
448
441
|
|
|
449
442
|
const checkReconnection = async () => {
|
|
450
443
|
try {
|
|
451
|
-
await this._rpc.pingWithTimeout(this.
|
|
444
|
+
await this._rpc.pingWithTimeout(this.remotePubkey!, 10000);
|
|
452
445
|
clearTimeout(timeout);
|
|
453
446
|
this.lastPingTime = Date.now();
|
|
454
447
|
console.log('Reconnection successful');
|
|
@@ -480,8 +473,9 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
480
473
|
private async setSignerPubkey(signerPubkey: string, sameAsUser: boolean = false) {
|
|
481
474
|
console.log('setSignerPubkey', signerPubkey);
|
|
482
475
|
|
|
476
|
+
|
|
483
477
|
// ensure it's set
|
|
484
|
-
this.
|
|
478
|
+
this.remotePubkey = signerPubkey;
|
|
485
479
|
|
|
486
480
|
// when we're sure it's known
|
|
487
481
|
this._rpc.on(`iframeRestart-${signerPubkey}`, () => {
|
|
@@ -502,10 +496,10 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
502
496
|
|
|
503
497
|
this._userPubkey = await withTimeout(
|
|
504
498
|
new Promise<string>((ok, err) => {
|
|
505
|
-
if (!this.
|
|
499
|
+
if (!this.remotePubkey) throw new Error('Signer pubkey not set');
|
|
506
500
|
|
|
507
|
-
console.log('get_public_key', this.
|
|
508
|
-
this._rpc.sendRequest(this.
|
|
501
|
+
console.log('get_public_key', this.remotePubkey);
|
|
502
|
+
this._rpc.sendRequest(this.remotePubkey, 'get_public_key', [], 24133, (response: NDKRpcResponse) => {
|
|
509
503
|
if (response.error) {
|
|
510
504
|
err(new Error(response.error));
|
|
511
505
|
} else {
|
|
@@ -527,9 +521,9 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
527
521
|
}
|
|
528
522
|
|
|
529
523
|
public async connect(token?: string, perms?: string) {
|
|
530
|
-
if (!this.
|
|
531
|
-
await this._rpc.connectWithTimeout(this.
|
|
532
|
-
await this.setSignerPubkey(this.
|
|
524
|
+
if (!this.remotePubkey) throw new Error('No signer pubkey');
|
|
525
|
+
await this._rpc.connectWithTimeout(this.remotePubkey, token, perms, NIP46_CONNECT_TIMEOUT);
|
|
526
|
+
await this.setSignerPubkey(this.remotePubkey);
|
|
533
527
|
|
|
534
528
|
// ログイン完了後に接続確認
|
|
535
529
|
await this.ensureConnection();
|