@konemono/nostr-login 1.7.70 → 1.9.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.
@@ -23,4 +23,5 @@ export declare class AmberDirectSigner implements Signer {
23
23
  generateUrl(content: string, type: string, id: string, pubkey?: string): string;
24
24
  static parseResponse(): AmberResponse | null;
25
25
  static resolvePending(id: string, type: string, result: string): boolean;
26
+ static cleanupPending(): void;
26
27
  }
@@ -3,8 +3,6 @@ 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;
8
6
  private signer;
9
7
  private amberSigner;
10
8
  private localSigner;
@@ -28,6 +26,8 @@ declare class AuthNostrService extends EventEmitter implements Signer {
28
26
  };
29
27
  constructor(params: NostrParams);
30
28
  private checkAmberResponse;
29
+ private handledAmberIds;
30
+ private handleAmberResponse;
31
31
  isIframe(): boolean;
32
32
  waitReady(): Promise<void>;
33
33
  cancelNostrConnect(): void;
@@ -64,7 +64,7 @@ declare class AuthNostrService extends EventEmitter implements Signer {
64
64
  endAuth(): Promise<void>;
65
65
  resetAuth(): void;
66
66
  private listen;
67
- connect(info: Info, perms?: string): Promise<void>;
67
+ connect(info: Info, perms?: string): Promise<any>;
68
68
  initSigner(info: Info, { listen, connect, eventToAddAccount }?: {
69
69
  listen?: boolean | undefined;
70
70
  connect?: boolean | undefined;
@@ -79,8 +79,8 @@ declare class AuthNostrService extends EventEmitter implements Signer {
79
79
  }): Promise<void>;
80
80
  signEvent(event: any): Promise<any>;
81
81
  private codec_call;
82
- encrypt04(pubkey: string, plaintext: string): Promise<string>;
83
- decrypt04(pubkey: string, ciphertext: string): Promise<string>;
82
+ encrypt04(pubkey: string, plaintext: string): Promise<any>;
83
+ decrypt04(pubkey: string, ciphertext: string): Promise<any>;
84
84
  encrypt44(pubkey: string, plaintext: string): Promise<string>;
85
85
  decrypt44(pubkey: string, ciphertext: string): Promise<string>;
86
86
  }
@@ -1,33 +1,51 @@
1
- import NDK, { NDKEvent, NDKFilter, NDKNip46Signer, NDKNostrRpc, NDKRpcRequest, NDKRpcResponse, NDKSubscription } from '@nostr-dev-kit/ndk';
1
+ import { EventEmitter } from 'tseep';
2
+ import { SimplePool } from 'nostr-tools';
2
3
  import { PrivateKeySigner } from './Signer';
3
- declare class NostrRpc extends NDKNostrRpc {
4
- protected _ndk: NDK;
5
- protected _signer: PrivateKeySigner;
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;
6
27
  protected requests: Set<string>;
7
- private sub?;
8
- protected _useNip44: boolean;
9
- constructor(ndk: NDK, signer: PrivateKeySigner);
10
- subscribe(filter: NDKFilter): Promise<NDKSubscription>;
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;
11
34
  stop(): void;
12
- setUseNip44(useNip44: boolean): void;
13
- private isNip04;
14
- parseEvent(event: NDKEvent): Promise<NDKRpcRequest | NDKRpcResponse>;
15
- parseNostrConnectReply(reply: any, secret: string): Promise<string>;
16
- listen(nostrConnectSecret: string): Promise<string>;
17
- connect(pubkey: string, token?: string, perms?: string): Promise<void>;
18
35
  protected getId(): string;
19
- sendRequest(remotePubkey: string, method: string, params?: string[], kind?: number, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse>;
20
- protected setResponseHandler(id: string, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse>;
21
- protected createRequestEvent(id: string, remotePubkey: string, method: string, params?: string[], kind?: number): Promise<NDKEvent>;
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>;
22
41
  }
23
42
  export declare class IframeNostrRpc extends NostrRpc {
24
43
  private peerOrigin?;
25
44
  private iframePort?;
26
45
  private iframeRequests;
27
- constructor(ndk: NDK, localSigner: PrivateKeySigner, iframePeerOrigin?: string);
28
- subscribe(filter: NDKFilter): Promise<NDKSubscription>;
46
+ constructor(localSigner: PrivateKeySigner, iframePeerOrigin?: string, relays?: string[]);
29
47
  setWorkerIframePort(port: MessagePort): void;
30
- sendRequest(remotePubkey: string, method: string, params?: string[], kind?: number, cb?: (res: NDKRpcResponse) => void): Promise<NDKRpcResponse>;
48
+ sendRequest(remotePubkey: string, method: string, params?: any[], kind?: number, cb?: (res: RpcResponse) => void): Promise<RpcResponse | undefined>;
31
49
  }
32
50
  export declare class ReadyListener {
33
51
  origin: string;
@@ -36,21 +54,19 @@ export declare class ReadyListener {
36
54
  constructor(messages: string[], origin: string);
37
55
  wait(): Promise<any>;
38
56
  }
39
- export declare class Nip46Signer extends NDKNip46Signer {
57
+ export declare class Nip46Signer extends EventEmitter {
40
58
  private _userPubkey;
41
- private _rpc;
42
- constructor(ndk: NDK, localSigner: PrivateKeySigner, signerPubkey: string, iframeOrigin?: string);
59
+ remotePubkey: string;
60
+ rpc: IframeNostrRpc | NostrRpc;
61
+ private localSigner;
62
+ constructor(localSigner: PrivateKeySigner, signerPubkey: string, iframeOrigin?: string, relays?: string[]);
43
63
  get userPubkey(): string;
44
64
  private setSignerPubkey;
45
65
  initUserPubkey(hintPubkey?: string): Promise<void>;
46
66
  listen(nostrConnectSecret: string): Promise<void>;
47
67
  connect(token?: string, perms?: string): Promise<void>;
48
- setListenReply(reply: any, nostrConnectSecret: string): Promise<void>;
49
- createAccount2({ bunkerPubkey, name, domain, perms }: {
50
- bunkerPubkey: string;
51
- name: string;
52
- domain: string;
53
- perms?: string;
54
- }): Promise<string>;
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>;
55
72
  }
56
- export {};
@@ -1,5 +1,10 @@
1
1
  import { Nostr, NostrParams } from './';
2
2
  import { EventEmitter } from 'tseep';
3
+ declare global {
4
+ interface Window {
5
+ nostr?: any;
6
+ }
7
+ }
3
8
  declare class NostrExtensionService extends EventEmitter {
4
9
  private params;
5
10
  private nostrExtension;
@@ -1,9 +1,16 @@
1
- import { NDKPrivateKeySigner, NDKUser } from '@nostr-dev-kit/ndk';
2
- export declare class PrivateKeySigner extends NDKPrivateKeySigner {
1
+ export declare class PrivateKeySigner {
3
2
  private nip44;
4
3
  private _pubkey;
4
+ privateKey: string;
5
5
  constructor(privateKey: string);
6
6
  get pubkey(): string;
7
- encryptNip44(recipient: NDKUser, value: string): Promise<string>;
8
- decryptNip44(sender: NDKUser, value: string): Promise<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>;
9
16
  }
@@ -0,0 +1,34 @@
1
+ import { EventEmitter } from 'tseep';
2
+ import { Nip46Client } from './Nip46Client';
3
+ import { PrivateKeySigner } from '../Signer';
4
+ export declare class Nip46Adapter extends EventEmitter {
5
+ private client;
6
+ private localSigner;
7
+ userPubkey: string;
8
+ remotePubkey: string;
9
+ constructor(client: Nip46Client, localSigner: PrivateKeySigner);
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>;
21
+ setListenReply(reply: any, nostrConnectSecret: string): Promise<void>;
22
+ createAccount2({ bunkerPubkey, name, domain, perms }: {
23
+ bunkerPubkey: string;
24
+ name: string;
25
+ domain: string;
26
+ perms?: string;
27
+ }): Promise<string>;
28
+ encrypt(recipientPubkey: string, plaintext: string): Promise<string>;
29
+ decrypt(recipientPubkey: string, ciphertext: string): Promise<string>;
30
+ sign(event: any): Promise<any>;
31
+ get rpc(): {
32
+ sendRequest: (remotePubkey: string, method: string, params: string[], kind: number, cb: (res: any) => void) => Promise<void>;
33
+ };
34
+ }
@@ -0,0 +1,67 @@
1
+ import { EventEmitter } from 'tseep';
2
+ import { Nip46ClientOptions } from './types';
3
+ export declare class Nip46Client extends EventEmitter {
4
+ private pool;
5
+ private localPrivateKey;
6
+ private remotePubkey;
7
+ private relays;
8
+ private pendingRequests;
9
+ private defaultTimeoutMs;
10
+ private useNip44;
11
+ private subscription;
12
+ private isSubscribed;
13
+ private nip44Codec;
14
+ private iframeConfig?;
15
+ private retryConfig;
16
+ private iframeKeepaliveInterval?;
17
+ constructor(options: Nip46ClientOptions);
18
+ get localPubkey(): string;
19
+ /**
20
+ * NIP-46リクエストを送信(リトライ機能付き)
21
+ */
22
+ sendRequest(method: string, params?: string[], timeoutMs?: number): Promise<string>;
23
+ /**
24
+ * NIP-46リクエストを送信(内部実装)
25
+ */
26
+ private sendRequestInternal;
27
+ /**
28
+ * リクエストイベントを作成して送信
29
+ */
30
+ private publishRequest;
31
+ /**
32
+ * レスポンスイベントを購読
33
+ */
34
+ private subscribeToResponses;
35
+ /**
36
+ * レスポンスイベントを処理
37
+ */
38
+ private handleResponseEvent;
39
+ /**
40
+ * NIP-04かNIP-44かを判定
41
+ */
42
+ private isNip04;
43
+ /**
44
+ * ランダムIDを生成
45
+ */
46
+ private generateId;
47
+ /**
48
+ * NIP-44を使用するかどうかを設定
49
+ */
50
+ setUseNip44(useNip44: boolean): void;
51
+ /**
52
+ * クリーンアップ
53
+ */
54
+ cleanup(): void;
55
+ /**
56
+ * 接続状態を確認
57
+ */
58
+ isConnected(): boolean;
59
+ /**
60
+ * iframeポートを設定
61
+ */
62
+ setIframePort(port: MessagePort): void;
63
+ /**
64
+ * iframe用のメッセージハンドラを設定
65
+ */
66
+ private setupIframePort;
67
+ }
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ export interface Nip46Request {
3
+ id: string;
4
+ method: string;
5
+ params: string[];
6
+ }
7
+ export interface Nip46Response {
8
+ id: string;
9
+ result?: string;
10
+ error?: string;
11
+ }
12
+ export interface PendingRequest {
13
+ resolve: (result: string) => void;
14
+ reject: (error: Error) => void;
15
+ timer: NodeJS.Timeout;
16
+ method: string;
17
+ }
18
+ export interface Nip46ClientOptions {
19
+ localPrivateKey: string;
20
+ remotePubkey: string;
21
+ relays: string[];
22
+ timeoutMs?: number;
23
+ useNip44?: boolean;
24
+ iframeConfig?: {
25
+ origin: string;
26
+ port?: MessagePort;
27
+ };
28
+ retryConfig?: {
29
+ maxRetries: number;
30
+ retryDelayMs: number;
31
+ };
32
+ }