@konemono/nostr-login 1.7.37 → 1.7.38
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.d.ts +2 -2
- package/dist/index.esm.js +41 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/Nip46.d.ts +8 -8
- package/dist/modules/Signer.d.ts +0 -9
- package/dist/unpkg.js +41 -12
- package/dist/utils/nip44.d.ts +1 -1
- package/package.json +7 -7
- package/src/modules/AuthNostrService.ts +13 -16
- package/src/modules/Nip46.ts +42 -34
- package/src/modules/Signer.ts +2 -1
package/dist/utils/nip44.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare function encryptNip44(plaintext: string, conversationKey: Uint8Ar
|
|
|
2
2
|
export declare function decryptNip44(payload: string, conversationKey: Uint8Array): string;
|
|
3
3
|
export declare class Nip44 {
|
|
4
4
|
private cache;
|
|
5
|
-
createKey(privkey: string, pubkey: string): Uint8Array
|
|
5
|
+
createKey(privkey: string, pubkey: string): Uint8Array<ArrayBufferLike>;
|
|
6
6
|
private getKey;
|
|
7
7
|
encrypt(privkey: string, pubkey: string, text: string): string;
|
|
8
8
|
decrypt(privkey: string, pubkey: string, data: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konemono/nostr-login",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.38",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.esm.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
},
|
|
12
12
|
"author": "a-fralou",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@nostr-dev-kit/ndk": "^2.
|
|
14
|
+
"@nostr-dev-kit/ndk": "^2.18.1",
|
|
15
15
|
"nostr-tools": "^1.17.0",
|
|
16
|
-
"tseep": "^1.
|
|
16
|
+
"tseep": "^1.3.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
20
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
19
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
20
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
21
21
|
"@rollup/plugin-terser": "^0.4.4",
|
|
22
22
|
"nostr-login-components": "^1.0.3",
|
|
23
|
-
"prettier": "^3.
|
|
24
|
-
"rollup": "^4.
|
|
23
|
+
"prettier": "^3.7.4",
|
|
24
|
+
"rollup": "^4.53.5",
|
|
25
25
|
"rollup-plugin-typescript2": "^0.36.0"
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT"
|
|
@@ -2,13 +2,13 @@ import { localStorageAddAccount, bunkerUrlToInfo, isBunkerUrl, fetchProfile, get
|
|
|
2
2
|
import { ConnectionString, Info } from 'nostr-login-components/dist/types/types';
|
|
3
3
|
import { generatePrivateKey, getEventHash, getPublicKey, nip19 } from 'nostr-tools';
|
|
4
4
|
import { NostrLoginAuthOptions, Response } from '../types';
|
|
5
|
-
import NDK, { NDKEvent, NDKNip46Signer, NDKRpcResponse, NDKUser, NostrEvent } from '@nostr-dev-kit/ndk';
|
|
5
|
+
import NDK, { NDKEvent, NDKNip46Signer, NDKPrivateKeySigner, NDKRpcResponse, NDKUser, NostrEvent } from '@nostr-dev-kit/ndk';
|
|
6
6
|
import { NostrParams } from './';
|
|
7
7
|
import { EventEmitter } from 'tseep';
|
|
8
8
|
import { Signer } from './Nostr';
|
|
9
9
|
import { Nip44 } from '../utils/nip44';
|
|
10
10
|
import { IframeNostrRpc, Nip46Signer, ReadyListener } from './Nip46';
|
|
11
|
-
import { PrivateKeySigner } from './Signer';
|
|
11
|
+
//import { PrivateKeySigner } from './Signer';
|
|
12
12
|
|
|
13
13
|
const OUTBOX_RELAYS = ['wss://user.kindpag.es', 'wss://purplepag.es', 'wss://relay.nos.social'];
|
|
14
14
|
const DEFAULT_NOSTRCONNECT_RELAYS = ['wss://relay.nsec.app/', 'wss://ephemeral.snowflare.cc/'];
|
|
@@ -40,7 +40,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
40
40
|
private ndk: NDK;
|
|
41
41
|
private profileNdk: NDK;
|
|
42
42
|
private signer: Nip46Signer | null = null;
|
|
43
|
-
private localSigner:
|
|
43
|
+
private localSigner: NDKPrivateKeySigner | null = null;
|
|
44
44
|
private params: NostrParams;
|
|
45
45
|
private signerPromise?: Promise<void>;
|
|
46
46
|
private signerErrCallback?: (err: string) => void;
|
|
@@ -92,13 +92,13 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
92
92
|
if (this.signerPromise) {
|
|
93
93
|
try {
|
|
94
94
|
await this.signerPromise;
|
|
95
|
-
} catch {
|
|
95
|
+
} catch {}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
if (this.readyPromise) {
|
|
99
99
|
try {
|
|
100
100
|
await this.readyPromise;
|
|
101
|
-
} catch {
|
|
101
|
+
} catch {}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -123,7 +123,6 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
123
123
|
) {
|
|
124
124
|
relays = relays && relays.length > 0 ? relays : DEFAULT_NOSTRCONNECT_RELAYS;
|
|
125
125
|
|
|
126
|
-
|
|
127
126
|
const info: Info = {
|
|
128
127
|
authMethod: 'connect',
|
|
129
128
|
pubkey: '', // unknown yet!
|
|
@@ -172,7 +171,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
172
171
|
perms: encodeURIComponent(this.params.optionsModal.perms || ''),
|
|
173
172
|
};
|
|
174
173
|
|
|
175
|
-
return `nostrconnect://${pubkey}?image=${meta.icon}&url=${meta.url}&name=${meta.name}&perms=${meta.perms}&secret=${this.nostrConnectSecret}${(relays || []).length > 0 ? (relays || []).map((r, i) => `&relay=${r}`) :
|
|
174
|
+
return `nostrconnect://${pubkey}?image=${meta.icon}&url=${meta.url}&name=${meta.name}&perms=${meta.perms}&secret=${this.nostrConnectSecret}${(relays || []).length > 0 ? (relays || []).map((r, i) => `&relay=${r}`) : ''}`;
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
public async getNostrConnectServices(): Promise<[string, ConnectionString[]]> {
|
|
@@ -244,7 +243,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
244
243
|
|
|
245
244
|
public async setLocal(info: Info, signup?: boolean) {
|
|
246
245
|
this.releaseSigner();
|
|
247
|
-
this.localSigner = new
|
|
246
|
+
this.localSigner = new NDKPrivateKeySigner(info.sk!);
|
|
248
247
|
|
|
249
248
|
if (signup) await createProfile(info, this.profileNdk, this.localSigner, this.params.optionsModal.signupRelays, this.params.optionsModal.outboxRelays);
|
|
250
249
|
|
|
@@ -318,9 +317,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
318
317
|
const userPubkey = await this.signer!.createAccount2({ bunkerPubkey: info.signerPubkey!, name, domain, perms: this.params.optionsModal.perms });
|
|
319
318
|
|
|
320
319
|
return {
|
|
321
|
-
bunkerUrl:
|
|
322
|
-
`bunker://${userPubkey}?` +
|
|
323
|
-
(info.relays ?? []).map((r: string) => `relay=${encodeURIComponent(r)}`).join('&'),
|
|
320
|
+
bunkerUrl: `bunker://${userPubkey}?` + (info.relays ?? []).map((r: string) => `relay=${encodeURIComponent(r)}`).join('&'),
|
|
324
321
|
sk: info.sk,
|
|
325
322
|
};
|
|
326
323
|
}
|
|
@@ -371,7 +368,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
371
368
|
if (info && this.params.userInfo && (info.pubkey !== this.params.userInfo.pubkey || info.authMethod !== this.params.userInfo.authMethod)) {
|
|
372
369
|
const event = new CustomEvent('nlAuth', { detail: { type: 'logout' } });
|
|
373
370
|
console.log('nostr-login auth', event.detail);
|
|
374
|
-
document.dispatchEvent(event)
|
|
371
|
+
document.dispatchEvent(event);
|
|
375
372
|
}
|
|
376
373
|
|
|
377
374
|
this.setUserInfo(info);
|
|
@@ -508,7 +505,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
508
505
|
}
|
|
509
506
|
|
|
510
507
|
public async startAuth() {
|
|
511
|
-
console.log(
|
|
508
|
+
console.log('startAuth');
|
|
512
509
|
if (this.readyCallback) throw new Error('Already started');
|
|
513
510
|
|
|
514
511
|
// start the new promise
|
|
@@ -552,7 +549,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
552
549
|
if (this.signerPromise) {
|
|
553
550
|
try {
|
|
554
551
|
await this.signerPromise;
|
|
555
|
-
} catch {
|
|
552
|
+
} catch {}
|
|
556
553
|
}
|
|
557
554
|
|
|
558
555
|
// we remove support for iframe from nip05 and bunker-url methods,
|
|
@@ -584,7 +581,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
584
581
|
await this.ndk.connect(CONNECT_TIMEOUT);
|
|
585
582
|
|
|
586
583
|
// create and prepare the signer
|
|
587
|
-
const localSigner = new
|
|
584
|
+
const localSigner = new NDKPrivateKeySigner(info.sk!);
|
|
588
585
|
this.signer = new Nip46Signer(this.ndk, localSigner, info.signerPubkey!, iframeOrigin);
|
|
589
586
|
|
|
590
587
|
// we should notify the banner the same way as
|
|
@@ -619,7 +616,7 @@ class AuthNostrService extends EventEmitter implements Signer {
|
|
|
619
616
|
|
|
620
617
|
// ensure, we're using it in callbacks above
|
|
621
618
|
// and expect info to be valid after this call
|
|
622
|
-
info.pubkey = this.signer!.userPubkey
|
|
619
|
+
info.pubkey = this.signer!.userPubkey!;
|
|
623
620
|
// learned after nostrconnect flow
|
|
624
621
|
info.signerPubkey = this.signer!.remotePubkey;
|
|
625
622
|
|
package/src/modules/Nip46.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import NDK, {
|
|
1
|
+
import NDK, {
|
|
2
|
+
NDKEvent,
|
|
3
|
+
NDKFilter,
|
|
4
|
+
NDKNip46Signer,
|
|
5
|
+
NDKNostrRpc,
|
|
6
|
+
NDKPrivateKeySigner,
|
|
7
|
+
NDKRpcRequest,
|
|
8
|
+
NDKRpcResponse,
|
|
9
|
+
NDKSubscription,
|
|
10
|
+
NDKSubscriptionCacheUsage,
|
|
11
|
+
NostrEvent,
|
|
12
|
+
} from '@nostr-dev-kit/ndk';
|
|
2
13
|
import { validateEvent, verifySignature } from 'nostr-tools';
|
|
3
|
-
import { PrivateKeySigner } from './Signer';
|
|
14
|
+
//import { PrivateKeySigner } from './Signer';
|
|
4
15
|
|
|
5
16
|
class NostrRpc extends NDKNostrRpc {
|
|
6
17
|
protected _ndk: NDK;
|
|
7
|
-
protected _signer:
|
|
18
|
+
protected _signer: NDKPrivateKeySigner;
|
|
8
19
|
protected requests: Set<string> = new Set();
|
|
9
20
|
private sub?: NDKSubscription;
|
|
10
21
|
protected _useNip44: boolean = false;
|
|
11
22
|
|
|
12
|
-
public constructor(ndk: NDK, signer:
|
|
23
|
+
public constructor(ndk: NDK, signer: NDKPrivateKeySigner) {
|
|
13
24
|
super(ndk, signer, ndk.debug.extend('nip46:signer:rpc'));
|
|
14
25
|
this._ndk = ndk;
|
|
15
26
|
this._signer = signer;
|
|
@@ -43,8 +54,10 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
43
54
|
public async parseEvent(event: NDKEvent): Promise<NDKRpcRequest | NDKRpcResponse> {
|
|
44
55
|
const remoteUser = this._ndk.getUser({ pubkey: event.pubkey });
|
|
45
56
|
remoteUser.ndk = this._ndk;
|
|
46
|
-
const
|
|
47
|
-
|
|
57
|
+
const decryptedContent = this.isNip04(event.content)
|
|
58
|
+
? await this._signer.decrypt(remoteUser, event.content, 'nip04')
|
|
59
|
+
: await this._signer.decrypt(remoteUser, event.content, 'nip44');
|
|
60
|
+
//const decryptedContent = await decrypt.call(this._signer, remoteUser, event.content);
|
|
48
61
|
const parsedContent = JSON.parse(decryptedContent);
|
|
49
62
|
const { id, method, params, result, error } = parsedContent;
|
|
50
63
|
|
|
@@ -134,7 +147,7 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
134
147
|
|
|
135
148
|
// create and sign request
|
|
136
149
|
const event = await this.createRequestEvent(id, remotePubkey, method, params, kind);
|
|
137
|
-
console.log(
|
|
150
|
+
console.log('sendRequest', { event, method, remotePubkey, params });
|
|
138
151
|
|
|
139
152
|
// send to relays
|
|
140
153
|
await event.publish();
|
|
@@ -186,8 +199,8 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
186
199
|
} as NostrEvent);
|
|
187
200
|
|
|
188
201
|
const useNip44 = this._useNip44 && method !== 'create_account';
|
|
189
|
-
|
|
190
|
-
event.content = await encrypt.call(this._signer, remoteUser, event.content);
|
|
202
|
+
event.content = useNip44 ? await this._signer.encrypt(remoteUser, event.content, 'nip44') : await this._signer.encrypt(remoteUser, event.content, 'nip04');
|
|
203
|
+
//event.content = await encrypt.call(this._signer, remoteUser, event.content);
|
|
191
204
|
await event.sign(this._signer);
|
|
192
205
|
|
|
193
206
|
return event;
|
|
@@ -199,7 +212,7 @@ export class IframeNostrRpc extends NostrRpc {
|
|
|
199
212
|
private iframePort?: MessagePort;
|
|
200
213
|
private iframeRequests = new Map<string, { id: string; pubkey: string }>();
|
|
201
214
|
|
|
202
|
-
public constructor(ndk: NDK, localSigner:
|
|
215
|
+
public constructor(ndk: NDK, localSigner: NDKPrivateKeySigner, iframePeerOrigin?: string) {
|
|
203
216
|
super(ndk, localSigner);
|
|
204
217
|
this._ndk = ndk;
|
|
205
218
|
this.peerOrigin = iframePeerOrigin;
|
|
@@ -338,53 +351,54 @@ export class ReadyListener {
|
|
|
338
351
|
}
|
|
339
352
|
|
|
340
353
|
export class Nip46Signer extends NDKNip46Signer {
|
|
341
|
-
private _userPubkey: string = '';
|
|
342
354
|
private _rpc: IframeNostrRpc;
|
|
355
|
+
private _remotePubkey: string = '';
|
|
343
356
|
|
|
344
|
-
constructor(ndk: NDK, localSigner:
|
|
357
|
+
constructor(ndk: NDK, localSigner: NDKPrivateKeySigner, signerPubkey: string, iframeOrigin?: string) {
|
|
345
358
|
super(ndk, signerPubkey, localSigner);
|
|
359
|
+
this._remotePubkey = signerPubkey;
|
|
346
360
|
|
|
347
|
-
// override with our own rpc implementation
|
|
348
361
|
this._rpc = new IframeNostrRpc(ndk, localSigner, iframeOrigin);
|
|
349
|
-
this._rpc.setUseNip44(true);
|
|
362
|
+
this._rpc.setUseNip44(true);
|
|
350
363
|
this._rpc.on('authUrl', (url: string) => {
|
|
351
364
|
this.emit('authUrl', url);
|
|
352
365
|
});
|
|
353
|
-
|
|
354
366
|
this.rpc = this._rpc;
|
|
355
367
|
}
|
|
356
368
|
|
|
357
|
-
get
|
|
358
|
-
return this.
|
|
369
|
+
get remotePubkey(): string {
|
|
370
|
+
return this._remotePubkey;
|
|
359
371
|
}
|
|
360
372
|
|
|
361
|
-
|
|
362
|
-
|
|
373
|
+
set remotePubkey(value: string) {
|
|
374
|
+
this._remotePubkey = value;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// userPubkeyのgetterを削除し、親クラスのプロパティを直接使用
|
|
363
378
|
|
|
364
|
-
|
|
379
|
+
private async setSignerPubkey(signerPubkey: string, sameAsUser: boolean = false) {
|
|
380
|
+
console.log('setSignerPubkey', signerPubkey);
|
|
365
381
|
this.remotePubkey = signerPubkey;
|
|
366
382
|
|
|
367
|
-
// when we're sure it's known
|
|
368
383
|
this._rpc.on(`iframeRestart-${signerPubkey}`, () => {
|
|
369
384
|
this.emit('iframeRestart');
|
|
370
385
|
});
|
|
371
386
|
|
|
372
|
-
// now call getPublicKey and swap remotePubkey w/ that
|
|
373
387
|
await this.initUserPubkey(sameAsUser ? signerPubkey : '');
|
|
374
388
|
}
|
|
375
389
|
|
|
376
390
|
public async initUserPubkey(hintPubkey?: string) {
|
|
377
|
-
|
|
391
|
+
// 親クラスのuserPubkeyプロパティを直接設定
|
|
392
|
+
if (this.userPubkey) throw new Error('Already called initUserPubkey');
|
|
378
393
|
|
|
379
394
|
if (hintPubkey) {
|
|
380
|
-
this.
|
|
395
|
+
this.userPubkey = hintPubkey;
|
|
381
396
|
return;
|
|
382
397
|
}
|
|
383
398
|
|
|
384
|
-
this.
|
|
399
|
+
this.userPubkey = await new Promise((ok, err) => {
|
|
385
400
|
if (!this.remotePubkey) throw new Error('Signer pubkey not set');
|
|
386
|
-
|
|
387
|
-
console.log("get_public_key", this.remotePubkey);
|
|
401
|
+
console.log('get_public_key', this.remotePubkey);
|
|
388
402
|
this._rpc.sendRequest(this.remotePubkey, 'get_public_key', [], 24133, (response: NDKRpcResponse) => {
|
|
389
403
|
ok(response.result);
|
|
390
404
|
});
|
|
@@ -408,12 +422,7 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
408
422
|
}
|
|
409
423
|
|
|
410
424
|
public async createAccount2({ bunkerPubkey, name, domain, perms = '' }: { bunkerPubkey: string; name: string; domain: string; perms?: string }) {
|
|
411
|
-
const params = [
|
|
412
|
-
name,
|
|
413
|
-
domain,
|
|
414
|
-
'', // email
|
|
415
|
-
perms,
|
|
416
|
-
];
|
|
425
|
+
const params = [name, domain, '', perms];
|
|
417
426
|
|
|
418
427
|
const r = await new Promise<NDKRpcResponse>(ok => {
|
|
419
428
|
this.rpc.sendRequest(bunkerPubkey, 'create_account', params, undefined, ok);
|
|
@@ -423,7 +432,6 @@ export class Nip46Signer extends NDKNip46Signer {
|
|
|
423
432
|
if (r.result === 'error') {
|
|
424
433
|
throw new Error(r.error);
|
|
425
434
|
}
|
|
426
|
-
|
|
427
435
|
return r.result;
|
|
428
436
|
}
|
|
429
437
|
}
|
package/src/modules/Signer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
|
|
1
|
+
/* import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
|
|
2
2
|
import { Nip44 } from '../utils/nip44';
|
|
3
3
|
import { getPublicKey } from 'nostr-tools';
|
|
4
4
|
|
|
@@ -23,3 +23,4 @@ export class PrivateKeySigner extends NDKPrivateKeySigner {
|
|
|
23
23
|
return Promise.resolve(this.nip44.decrypt(this.privateKey!, sender.pubkey, value));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
*/
|