@konemono/nostr-login 1.9.14 → 1.10.1
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/const/index.d.ts +3 -0
- package/dist/index.esm.js +12 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/AuthNostrService.d.ts +13 -12
- package/dist/modules/ModalManager.d.ts +1 -0
- package/dist/modules/Nip46.d.ts +44 -47
- package/dist/modules/NostrExtensionService.d.ts +0 -5
- package/dist/modules/Signer.d.ts +4 -11
- package/dist/types.d.ts +0 -5
- package/dist/unpkg.js +12 -10
- package/dist/utils/index.d.ts +3 -2
- package/package.json +4 -7
- package/src/const/index.ts +7 -0
- package/src/index.ts +2 -8
- package/src/modules/AuthNostrService.ts +169 -311
- package/src/modules/ModalManager.ts +14 -10
- package/src/modules/Nip46.ts +400 -208
- package/src/modules/NostrExtensionService.ts +0 -6
- package/src/modules/Signer.ts +8 -39
- package/src/types.ts +0 -7
- package/src/utils/index.ts +31 -79
- package/tsconfig.json +1 -1
- package/src/modules/AmberDirectSigner.ts +0 -228
- package/src/modules/Nip46.iframe.test.ts +0 -124
- package/src/modules/Nip46.test.ts +0 -31
- package/src/modules/nip46/Nip46Adapter.ts +0 -123
- package/src/modules/nip46/Nip46Client.ts +0 -248
- package/src/modules/nip46/types.ts +0 -26
- package/vitest.config.ts +0 -9
|
@@ -3,12 +3,14 @@ import { NostrParams } from './';
|
|
|
3
3
|
import { EventEmitter } from 'tseep';
|
|
4
4
|
import { Signer } from './Nostr';
|
|
5
5
|
declare class AuthNostrService extends EventEmitter implements Signer {
|
|
6
|
+
private ndk;
|
|
7
|
+
private profileNdk;
|
|
6
8
|
private signer;
|
|
7
|
-
private amberSigner;
|
|
8
9
|
private localSigner;
|
|
9
10
|
private params;
|
|
10
11
|
private signerPromise?;
|
|
11
12
|
private signerErrCallback?;
|
|
13
|
+
private signerAbortController?;
|
|
12
14
|
private readyPromise?;
|
|
13
15
|
private readyCallback?;
|
|
14
16
|
private nip44Codec;
|
|
@@ -25,19 +27,17 @@ declare class AuthNostrService extends EventEmitter implements Signer {
|
|
|
25
27
|
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
26
28
|
};
|
|
27
29
|
constructor(params: NostrParams);
|
|
28
|
-
private checkAmberResponse;
|
|
29
|
-
private handledAmberIds;
|
|
30
|
-
private handleAmberResponse;
|
|
31
30
|
isIframe(): boolean;
|
|
32
31
|
waitReady(): Promise<void>;
|
|
33
32
|
cancelNostrConnect(): void;
|
|
34
|
-
|
|
33
|
+
cancelSignerInit(): void;
|
|
34
|
+
nostrConnect(relay?: string, { domain, link, iframeUrl, importConnect, }?: {
|
|
35
35
|
domain?: string;
|
|
36
36
|
link?: string;
|
|
37
37
|
importConnect?: boolean;
|
|
38
38
|
iframeUrl?: string;
|
|
39
39
|
}): Promise<Info>;
|
|
40
|
-
createNostrConnect(
|
|
40
|
+
createNostrConnect(relay?: string): Promise<string>;
|
|
41
41
|
getNostrConnectServices(): Promise<[string, ConnectionString[]]>;
|
|
42
42
|
localSignup(name: string, sk?: string): Promise<void>;
|
|
43
43
|
setLocal(info: Info, signup?: boolean): Promise<void>;
|
|
@@ -47,7 +47,6 @@ declare class AuthNostrService extends EventEmitter implements Signer {
|
|
|
47
47
|
setExtension(pubkey: string): void;
|
|
48
48
|
setOTP(pubkey: string, data: string): void;
|
|
49
49
|
setConnect(info: Info): Promise<void>;
|
|
50
|
-
setAmber(info: Info): Promise<void>;
|
|
51
50
|
createAccount(nip05: string): Promise<{
|
|
52
51
|
bunkerUrl: string;
|
|
53
52
|
sk: string | undefined;
|
|
@@ -60,27 +59,29 @@ declare class AuthNostrService extends EventEmitter implements Signer {
|
|
|
60
59
|
private createIframe;
|
|
61
60
|
sendNeedAuth(): Promise<void>;
|
|
62
61
|
isAuthing(): boolean;
|
|
63
|
-
startAuth(): void
|
|
62
|
+
startAuth(): Promise<void>;
|
|
64
63
|
endAuth(): Promise<void>;
|
|
65
64
|
resetAuth(): void;
|
|
66
65
|
private listen;
|
|
67
|
-
connect(info: Info, perms?: string): Promise<
|
|
66
|
+
connect(info: Info, perms?: string): Promise<void>;
|
|
68
67
|
initSigner(info: Info, { listen, connect, eventToAddAccount }?: {
|
|
69
68
|
listen?: boolean | undefined;
|
|
70
69
|
connect?: boolean | undefined;
|
|
71
70
|
eventToAddAccount?: boolean | undefined;
|
|
72
71
|
}): Promise<void>;
|
|
73
|
-
|
|
72
|
+
private initSignerInternal;
|
|
73
|
+
authNip46(type: 'login' | 'signup', { name, bunkerUrl, sk, domain, iframeUrl, customRelays, }: {
|
|
74
74
|
name: string;
|
|
75
75
|
bunkerUrl: string;
|
|
76
76
|
sk?: string;
|
|
77
77
|
domain?: string;
|
|
78
78
|
iframeUrl?: string;
|
|
79
|
+
customRelays?: string[];
|
|
79
80
|
}): Promise<void>;
|
|
80
81
|
signEvent(event: any): Promise<any>;
|
|
81
82
|
private codec_call;
|
|
82
|
-
encrypt04(pubkey: string, plaintext: string): Promise<
|
|
83
|
-
decrypt04(pubkey: string, ciphertext: string): Promise<
|
|
83
|
+
encrypt04(pubkey: string, plaintext: string): Promise<string>;
|
|
84
|
+
decrypt04(pubkey: string, ciphertext: string): Promise<string>;
|
|
84
85
|
encrypt44(pubkey: string, plaintext: string): Promise<string>;
|
|
85
86
|
decrypt44(pubkey: string, ciphertext: string): Promise<string>;
|
|
86
87
|
}
|
|
@@ -11,6 +11,7 @@ declare class ModalManager extends EventEmitter {
|
|
|
11
11
|
private accounts;
|
|
12
12
|
private recents;
|
|
13
13
|
private opt?;
|
|
14
|
+
private customNip46Relays;
|
|
14
15
|
constructor(params: NostrParams, authNostrService: AuthNostrService, extensionManager: NostrExtensionService);
|
|
15
16
|
waitReady(): Promise<void>;
|
|
16
17
|
launch(opt: NostrLoginOptions): Promise<void>;
|
package/dist/modules/Nip46.d.ts
CHANGED
|
@@ -1,51 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SimplePool } from 'nostr-tools';
|
|
1
|
+
import NDK, { NDKEvent, NDKFilter, NDKNip46Signer, NDKNostrRpc, NDKRpcRequest, NDKRpcResponse, NDKSubscription } from '@nostr-dev-kit/ndk';
|
|
3
2
|
import { PrivateKeySigner } from './Signer';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
method: string;
|
|
8
|
-
params: any[];
|
|
9
|
-
event?: any;
|
|
10
|
-
};
|
|
11
|
-
export type RpcResponse = {
|
|
12
|
-
id: string;
|
|
13
|
-
result?: any;
|
|
14
|
-
error?: any;
|
|
15
|
-
event?: any;
|
|
16
|
-
};
|
|
17
|
-
export declare class NostrRpc extends EventEmitter {
|
|
18
|
-
protected localSigner: PrivateKeySigner;
|
|
19
|
-
protected localPubkey: string;
|
|
20
|
-
protected localPrivateKey: string;
|
|
21
|
-
protected remotePubkey: string;
|
|
22
|
-
protected pool: SimplePool;
|
|
23
|
-
protected relays: string[];
|
|
24
|
-
protected subscription: any;
|
|
25
|
-
protected isSubscribed: boolean;
|
|
26
|
-
protected useNip44: boolean;
|
|
3
|
+
declare class NostrRpc extends NDKNostrRpc {
|
|
4
|
+
protected _ndk: NDK;
|
|
5
|
+
protected _signer: PrivateKeySigner;
|
|
27
6
|
protected requests: Set<string>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
private sub?;
|
|
8
|
+
protected _useNip44: boolean;
|
|
9
|
+
private reconnectAttempts;
|
|
10
|
+
private maxReconnectAttempts;
|
|
11
|
+
private reconnectDelay;
|
|
12
|
+
constructor(ndk: NDK, signer: PrivateKeySigner);
|
|
13
|
+
subscribe(filter: NDKFilter): Promise<NDKSubscription>;
|
|
34
14
|
stop(): void;
|
|
15
|
+
setUseNip44(useNip44: boolean): void;
|
|
16
|
+
private isNip04;
|
|
17
|
+
parseEvent(event: NDKEvent): Promise<NDKRpcRequest | NDKRpcResponse>;
|
|
18
|
+
parseNostrConnectReply(reply: any, secret: string): Promise<string>;
|
|
19
|
+
listen(nostrConnectSecret: string): Promise<string>;
|
|
20
|
+
connect(pubkey: string, token?: string, perms?: string): Promise<void>;
|
|
21
|
+
connectWithTimeout(pubkey: string, token?: string, perms?: string, timeoutMs?: number): Promise<void>;
|
|
22
|
+
sendRequestWithTimeout(remotePubkey: string, method: string, params?: string[], kind?: number, timeoutMs?: number): Promise<NDKRpcResponse>;
|
|
23
|
+
private setupConnectionMonitoring;
|
|
24
|
+
private ensureConnected;
|
|
25
|
+
protected reconnect(): Promise<void>;
|
|
35
26
|
protected getId(): string;
|
|
36
|
-
|
|
37
|
-
protected
|
|
38
|
-
protected
|
|
39
|
-
sendRequest(remotePubkey: string, method: string, params?: any[], kind?: number, cb?: (res: RpcResponse) => void): Promise<RpcResponse | undefined>;
|
|
40
|
-
listen(nostrConnectSecret: string, relays?: string[]): Promise<string>;
|
|
27
|
+
sendRequest(remotePubkey: string, method: string, params?: string[], kind?: number, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse>;
|
|
28
|
+
protected setResponseHandler(id: string, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse>;
|
|
29
|
+
protected createRequestEvent(id: string, remotePubkey: string, method: string, params?: string[], kind?: number): Promise<NDKEvent>;
|
|
41
30
|
}
|
|
42
31
|
export declare class IframeNostrRpc extends NostrRpc {
|
|
43
32
|
private peerOrigin?;
|
|
44
33
|
private iframePort?;
|
|
45
34
|
private iframeRequests;
|
|
46
|
-
|
|
35
|
+
private heartbeatInterval?;
|
|
36
|
+
private lastResponseTime;
|
|
37
|
+
private heartbeatTimeoutMs;
|
|
38
|
+
constructor(ndk: NDK, localSigner: PrivateKeySigner, iframePeerOrigin?: string);
|
|
39
|
+
subscribe(filter: NDKFilter): Promise<NDKSubscription>;
|
|
40
|
+
private startHeartbeat;
|
|
41
|
+
private stopHeartbeat;
|
|
47
42
|
setWorkerIframePort(port: MessagePort): void;
|
|
48
|
-
sendRequest(remotePubkey: string, method: string, params?:
|
|
43
|
+
sendRequest(remotePubkey: string, method: string, params?: string[], kind?: number, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse>;
|
|
49
44
|
}
|
|
50
45
|
export declare class ReadyListener {
|
|
51
46
|
origin: string;
|
|
@@ -54,19 +49,21 @@ export declare class ReadyListener {
|
|
|
54
49
|
constructor(messages: string[], origin: string);
|
|
55
50
|
wait(): Promise<any>;
|
|
56
51
|
}
|
|
57
|
-
export declare class Nip46Signer extends
|
|
52
|
+
export declare class Nip46Signer extends NDKNip46Signer {
|
|
58
53
|
private _userPubkey;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
private localSigner;
|
|
62
|
-
constructor(localSigner: PrivateKeySigner, signerPubkey: string, iframeOrigin?: string, relays?: string[]);
|
|
54
|
+
private _rpc;
|
|
55
|
+
constructor(ndk: NDK, localSigner: PrivateKeySigner, signerPubkey: string, iframeOrigin?: string);
|
|
63
56
|
get userPubkey(): string;
|
|
64
57
|
private setSignerPubkey;
|
|
65
58
|
initUserPubkey(hintPubkey?: string): Promise<void>;
|
|
66
59
|
listen(nostrConnectSecret: string): Promise<void>;
|
|
67
60
|
connect(token?: string, perms?: string): Promise<void>;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
setListenReply(reply: any, nostrConnectSecret: string): Promise<void>;
|
|
62
|
+
createAccount2({ bunkerPubkey, name, domain, perms }: {
|
|
63
|
+
bunkerPubkey: string;
|
|
64
|
+
name: string;
|
|
65
|
+
domain: string;
|
|
66
|
+
perms?: string;
|
|
67
|
+
}): Promise<string>;
|
|
72
68
|
}
|
|
69
|
+
export {};
|
package/dist/modules/Signer.d.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
|
|
2
|
+
export declare class PrivateKeySigner extends NDKPrivateKeySigner {
|
|
2
3
|
private nip44;
|
|
3
4
|
private _pubkey;
|
|
4
|
-
privateKey: string;
|
|
5
5
|
constructor(privateKey: string);
|
|
6
6
|
get pubkey(): string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
pubkey: string;
|
|
10
|
-
}>;
|
|
11
|
-
sign(event: any): Promise<string>;
|
|
12
|
-
encrypt(recipient: any, plaintext: string): Promise<string>;
|
|
13
|
-
decrypt(sender: any, ciphertext: string): Promise<string>;
|
|
14
|
-
encryptNip44(recipient: any, value: string): Promise<string>;
|
|
15
|
-
decryptNip44(sender: any, value: string): Promise<string>;
|
|
7
|
+
encryptNip44(recipient: NDKUser, value: string): Promise<string>;
|
|
8
|
+
decryptNip44(sender: NDKUser, value: string): Promise<string>;
|
|
16
9
|
}
|