@konemono/nostr-login 1.13.0 → 1.13.2
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 +25 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/Nip46.d.ts +0 -2
- package/dist/modules/Signer.d.ts +1 -1
- package/dist/packages/auth/src/iife-module.d.ts +1 -0
- package/dist/unpkg.js +25 -13
- package/package.json +2 -2
- package/src/modules/AuthNostrService.ts +4 -4
- package/src/modules/Nip46.ts +17 -19
- package/src/modules/Signer.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konemono/nostr-login",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.2",
|
|
4
4
|
"description": "Extended fork of nostr-login with multi-relay support, QR scanner, and improved stability",
|
|
5
5
|
"main": "./dist/index.esm.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
31
31
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
32
32
|
"@rollup/plugin-terser": "^0.4.4",
|
|
33
|
-
"@konemono/nostr-login-components": "^1.2.
|
|
33
|
+
"@konemono/nostr-login-components": "^1.2.2",
|
|
34
34
|
"prettier": "^3.2.2",
|
|
35
35
|
"rollup": "^4.9.6",
|
|
36
36
|
"rollup-plugin-typescript2": "^0.36.0"
|
|
@@ -676,8 +676,8 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
676
676
|
await this.signer!.initUserPubkey(info.pubkey);
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
info.pubkey = this.signer!.userPubkey;
|
|
680
|
-
info.signerPubkey = this.signer!.
|
|
679
|
+
info.pubkey = this.signer!.userPubkey as string;
|
|
680
|
+
info.signerPubkey = this.signer!.bunkerPubkey;
|
|
681
681
|
|
|
682
682
|
console.log('Signer initialized successfully. User pubkey:', info.pubkey, 'Signer pubkey:', info.signerPubkey);
|
|
683
683
|
|
|
@@ -756,7 +756,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
756
756
|
throw new Error('Signer is not initialized. Please reconnect.');
|
|
757
757
|
}
|
|
758
758
|
await this.ensureRelayConnection();
|
|
759
|
-
event.pubkey = this.signer.
|
|
759
|
+
event.pubkey = this.signer.bunkerPubkey;
|
|
760
760
|
event.id = getEventHash(event);
|
|
761
761
|
event.sig = await this.signer?.sign(event);
|
|
762
762
|
console.log('signed', { event, attempt });
|
|
@@ -903,7 +903,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
903
903
|
|
|
904
904
|
private async codec_call(method: string, pubkey: string, param: string) {
|
|
905
905
|
return new Promise<string>((resolve, reject) => {
|
|
906
|
-
this.signer!.rpc.sendRequest(this.signer!.
|
|
906
|
+
this.signer!.rpc.sendRequest(this.signer!.bunkerPubkey!, method, [pubkey, param], 24133, (response: NDKRpcResponse) => {
|
|
907
907
|
if (!response.error) {
|
|
908
908
|
resolve(response.result);
|
|
909
909
|
} else {
|
package/src/modules/Nip46.ts
CHANGED
|
@@ -445,11 +445,13 @@ export class ReadyListener {
|
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
export class Nip46Signer extends NDKNip46Signer {
|
|
448
|
-
private _userPubkey: string = '';
|
|
449
448
|
private _rpc: IframeNostrRpc;
|
|
450
449
|
|
|
451
450
|
constructor(ndk: NDK, localSigner: PrivateKeySigner, signerPubkey: string, iframeOrigin?: string) {
|
|
452
|
-
|
|
451
|
+
// Pass `false` to skip NDK's built-in init (nip05Init/bunkerFlowInit/nostrconnectFlowInit)
|
|
452
|
+
// because we manage bunkerPubkey and RPC ourselves.
|
|
453
|
+
super(ndk, false as any, localSigner);
|
|
454
|
+
this.bunkerPubkey = signerPubkey;
|
|
453
455
|
|
|
454
456
|
this._rpc = new IframeNostrRpc(ndk, localSigner, iframeOrigin);
|
|
455
457
|
this._rpc.setUseNip44(true);
|
|
@@ -460,14 +462,10 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
460
462
|
this.rpc = this._rpc;
|
|
461
463
|
}
|
|
462
464
|
|
|
463
|
-
get userPubkey() {
|
|
464
|
-
return this._userPubkey;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
465
|
private async setSignerPubkey(signerPubkey: string, sameAsUser: boolean = false) {
|
|
468
466
|
console.log('setSignerPubkey', signerPubkey);
|
|
469
467
|
|
|
470
|
-
this.
|
|
468
|
+
this.bunkerPubkey = signerPubkey;
|
|
471
469
|
|
|
472
470
|
this._rpc.on(`iframeRestart-${signerPubkey}`, () => {
|
|
473
471
|
this.emit('iframeRestart');
|
|
@@ -477,28 +475,28 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
477
475
|
}
|
|
478
476
|
|
|
479
477
|
public async initUserPubkey(hintPubkey?: string) {
|
|
480
|
-
if (this.
|
|
481
|
-
console.warn('initUserPubkey already called, pubkey:', this.
|
|
478
|
+
if (this.userPubkey) {
|
|
479
|
+
console.warn('initUserPubkey already called, pubkey:', this.userPubkey);
|
|
482
480
|
return;
|
|
483
481
|
}
|
|
484
482
|
|
|
485
483
|
if (hintPubkey) {
|
|
486
|
-
this.
|
|
487
|
-
console.log('User pubkey set from hint:', this.
|
|
484
|
+
this.userPubkey = hintPubkey;
|
|
485
|
+
console.log('User pubkey set from hint:', this.userPubkey);
|
|
488
486
|
return;
|
|
489
487
|
}
|
|
490
488
|
|
|
491
|
-
console.log('Requesting user pubkey from signer:', this.
|
|
489
|
+
console.log('Requesting user pubkey from signer:', this.bunkerPubkey);
|
|
492
490
|
|
|
493
|
-
this.
|
|
494
|
-
if (!this.
|
|
491
|
+
this.userPubkey = await new Promise<string>((ok, err) => {
|
|
492
|
+
if (!this.bunkerPubkey) throw new Error('Signer pubkey not set');
|
|
495
493
|
|
|
496
494
|
const timeout = setTimeout(() => {
|
|
497
495
|
err(new Error('Timeout getting user pubkey'));
|
|
498
496
|
}, 30000);
|
|
499
497
|
|
|
500
|
-
console.log('get_public_key', this.
|
|
501
|
-
this._rpc.sendRequest(this.
|
|
498
|
+
console.log('get_public_key', this.bunkerPubkey);
|
|
499
|
+
this._rpc.sendRequest(this.bunkerPubkey, 'get_public_key', [], 24133, (response: NDKRpcResponse) => {
|
|
502
500
|
clearTimeout(timeout);
|
|
503
501
|
|
|
504
502
|
if (response.error) {
|
|
@@ -517,9 +515,9 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
517
515
|
}
|
|
518
516
|
|
|
519
517
|
public async connect(token?: string, perms?: string) {
|
|
520
|
-
if (!this.
|
|
521
|
-
await this._rpc.connect(this.
|
|
522
|
-
await this.setSignerPubkey(this.
|
|
518
|
+
if (!this.bunkerPubkey) throw new Error('No signer pubkey');
|
|
519
|
+
await this._rpc.connect(this.bunkerPubkey, token, perms);
|
|
520
|
+
await this.setSignerPubkey(this.bunkerPubkey);
|
|
523
521
|
}
|
|
524
522
|
|
|
525
523
|
public async setListenReply(reply: any, nostrConnectSecret: string) {
|
package/src/modules/Signer.ts
CHANGED
|
@@ -4,15 +4,15 @@ import { getPublicKey } from 'nostr-tools';
|
|
|
4
4
|
|
|
5
5
|
export class PrivateKeySigner extends NDKPrivateKeySigner {
|
|
6
6
|
private nip44: Nip44 = new Nip44();
|
|
7
|
-
private
|
|
7
|
+
private _derivedPubkey: string;
|
|
8
8
|
|
|
9
9
|
constructor(privateKey: string) {
|
|
10
10
|
super(privateKey);
|
|
11
|
-
this.
|
|
11
|
+
this._derivedPubkey = getPublicKey(privateKey);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
get pubkey() {
|
|
15
|
-
return this.
|
|
14
|
+
override get pubkey() {
|
|
15
|
+
return this._derivedPubkey;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
encryptNip44(recipient: NDKUser, value: string): Promise<string> {
|