@konemono/nostr-login 1.9.13 → 1.10.0

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.
@@ -3,11 +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
9
  private localSigner;
8
10
  private params;
9
11
  private signerPromise?;
10
12
  private signerErrCallback?;
13
+ private signerAbortController?;
11
14
  private readyPromise?;
12
15
  private readyCallback?;
13
16
  private nip44Codec;
@@ -27,13 +30,14 @@ declare class AuthNostrService extends EventEmitter implements Signer {
27
30
  isIframe(): boolean;
28
31
  waitReady(): Promise<void>;
29
32
  cancelNostrConnect(): void;
30
- nostrConnect(relays?: string[], { domain, link, iframeUrl, importConnect, }?: {
33
+ cancelSignerInit(): void;
34
+ nostrConnect(relay?: string, { domain, link, iframeUrl, importConnect, }?: {
31
35
  domain?: string;
32
36
  link?: string;
33
37
  importConnect?: boolean;
34
38
  iframeUrl?: string;
35
39
  }): Promise<Info>;
36
- createNostrConnect(relays?: string[]): Promise<string>;
40
+ createNostrConnect(relay?: string): Promise<string>;
37
41
  getNostrConnectServices(): Promise<[string, ConnectionString[]]>;
38
42
  localSignup(name: string, sk?: string): Promise<void>;
39
43
  setLocal(info: Info, signup?: boolean): Promise<void>;
@@ -43,7 +47,6 @@ declare class AuthNostrService extends EventEmitter implements Signer {
43
47
  setExtension(pubkey: string): void;
44
48
  setOTP(pubkey: string, data: string): void;
45
49
  setConnect(info: Info): Promise<void>;
46
- setAmber(info: Info): Promise<void>;
47
50
  createAccount(nip05: string): Promise<{
48
51
  bunkerUrl: string;
49
52
  sk: string | undefined;
@@ -56,27 +59,29 @@ declare class AuthNostrService extends EventEmitter implements Signer {
56
59
  private createIframe;
57
60
  sendNeedAuth(): Promise<void>;
58
61
  isAuthing(): boolean;
59
- startAuth(): void;
62
+ startAuth(): Promise<void>;
60
63
  endAuth(): Promise<void>;
61
64
  resetAuth(): void;
62
65
  private listen;
63
- connect(info: Info, perms?: string): Promise<any>;
66
+ connect(info: Info, perms?: string): Promise<void>;
64
67
  initSigner(info: Info, { listen, connect, eventToAddAccount }?: {
65
68
  listen?: boolean | undefined;
66
69
  connect?: boolean | undefined;
67
70
  eventToAddAccount?: boolean | undefined;
68
71
  }): Promise<void>;
69
- authNip46(type: 'login' | 'signup', { name, bunkerUrl, sk, domain, iframeUrl }: {
72
+ private initSignerInternal;
73
+ authNip46(type: 'login' | 'signup', { name, bunkerUrl, sk, domain, iframeUrl, customRelays, }: {
70
74
  name: string;
71
75
  bunkerUrl: string;
72
76
  sk?: string;
73
77
  domain?: string;
74
78
  iframeUrl?: string;
79
+ customRelays?: string[];
75
80
  }): Promise<void>;
76
81
  signEvent(event: any): Promise<any>;
77
82
  private codec_call;
78
- encrypt04(pubkey: string, plaintext: string): Promise<any>;
79
- decrypt04(pubkey: string, ciphertext: string): Promise<any>;
83
+ encrypt04(pubkey: string, plaintext: string): Promise<string>;
84
+ decrypt04(pubkey: string, ciphertext: string): Promise<string>;
80
85
  encrypt44(pubkey: string, plaintext: string): Promise<string>;
81
86
  decrypt44(pubkey: string, ciphertext: string): Promise<string>;
82
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>;
@@ -1,51 +1,46 @@
1
- import { EventEmitter } from 'tseep';
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
- export type RpcRequest = {
5
- id: string;
6
- pubkey: string;
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
- constructor(localSigner: PrivateKeySigner, relays?: string[]);
29
- setUseNip44(use: boolean): void;
30
- protected isNip04(ciphertext: string): boolean;
31
- protected decryptEventContent(event: any): Promise<any>;
32
- protected parseEvent(event: any): Promise<RpcRequest | RpcResponse>;
33
- subscribe(relays: string[], filter: any): void;
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
- protected setResponseHandler(id: string, cb?: (res: RpcResponse) => void): void;
37
- protected createRequestEvent(id: string, remotePubkey: string, method: string, params?: any[], kind?: number): Promise<any>;
38
- protected publishRequest(event: any): Promise<void>;
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
- constructor(localSigner: PrivateKeySigner, iframePeerOrigin?: string, relays?: string[]);
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?: any[], kind?: number, cb?: (res: RpcResponse) => void): Promise<RpcResponse | undefined>;
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 EventEmitter {
52
+ export declare class Nip46Signer extends NDKNip46Signer {
58
53
  private _userPubkey;
59
- remotePubkey: string;
60
- rpc: IframeNostrRpc | NostrRpc;
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
- createAccount2(params: any): Promise<unknown>;
69
- encrypt(pubkey: string, plaintext: string): Promise<string>;
70
- decrypt(pubkey: string, ciphertext: string): Promise<string>;
71
- sign(event: any): Promise<any>;
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 {};
@@ -1,10 +1,5 @@
1
1
  import { Nostr, NostrParams } from './';
2
2
  import { EventEmitter } from 'tseep';
3
- declare global {
4
- interface Window {
5
- nostr?: any;
6
- }
7
- }
8
3
  declare class NostrExtensionService extends EventEmitter {
9
4
  private params;
10
5
  private nostrExtension;
@@ -1,16 +1,9 @@
1
- export declare class PrivateKeySigner {
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
- blockUntilReady(): Promise<void>;
8
- user(): Promise<{
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
  }
@@ -8,16 +8,8 @@ export declare class Nip46Adapter extends EventEmitter {
8
8
  remotePubkey: string;
9
9
  constructor(client: Nip46Client, localSigner: PrivateKeySigner);
10
10
  initUserPubkey(hintPubkey?: string): Promise<void>;
11
- /**
12
- * nostrconnect:// フロー - 受信待機
13
- * サイナーからの接続を待つ
14
- */
15
- listen(nostrConnectSecret: string, timeoutMs?: number): Promise<string>;
16
- /**
17
- * bunker:// フロー - 能動的接続
18
- * サイナーに接続リクエストを送る
19
- */
20
- connect(token?: string, perms?: string, timeoutMs?: number): Promise<void>;
11
+ listen(nostrConnectSecret: string): Promise<string>;
12
+ connect(token?: string, perms?: string): Promise<void>;
21
13
  setListenReply(reply: any, nostrConnectSecret: string): Promise<void>;
22
14
  createAccount2({ bunkerPubkey, name, domain, perms }: {
23
15
  bunkerPubkey: string;
@@ -11,19 +11,12 @@ export declare class Nip46Client extends EventEmitter {
11
11
  private subscription;
12
12
  private isSubscribed;
13
13
  private nip44Codec;
14
- private iframeConfig?;
15
- private retryConfig;
16
- private iframeKeepaliveInterval?;
17
14
  constructor(options: Nip46ClientOptions);
18
15
  get localPubkey(): string;
19
16
  /**
20
- * NIP-46リクエストを送信(リトライ機能付き)
17
+ * NIP-46リクエストを送信
21
18
  */
22
19
  sendRequest(method: string, params?: string[], timeoutMs?: number): Promise<string>;
23
- /**
24
- * NIP-46リクエストを送信(内部実装)
25
- */
26
- private sendRequestInternal;
27
20
  /**
28
21
  * リクエストイベントを作成して送信
29
22
  */
@@ -56,12 +49,4 @@ export declare class Nip46Client extends EventEmitter {
56
49
  * 接続状態を確認
57
50
  */
58
51
  isConnected(): boolean;
59
- /**
60
- * iframeポートを設定
61
- */
62
- setIframePort(port: MessagePort): void;
63
- /**
64
- * iframe用のメッセージハンドラを設定
65
- */
66
- private setupIframePort;
67
52
  }
@@ -21,12 +21,4 @@ export interface Nip46ClientOptions {
21
21
  relays: string[];
22
22
  timeoutMs?: number;
23
23
  useNip44?: boolean;
24
- iframeConfig?: {
25
- origin: string;
26
- port?: MessagePort;
27
- };
28
- retryConfig?: {
29
- maxRetries: number;
30
- retryDelayMs: number;
31
- };
32
24
  }
package/dist/types.d.ts CHANGED
@@ -70,8 +70,3 @@ export interface Response {
70
70
  result?: string;
71
71
  error?: string;
72
72
  }
73
- export interface AmberResponse {
74
- id: string;
75
- type: string;
76
- result: string;
77
- }