ns-auth-sdk 1.0.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.
@@ -0,0 +1,214 @@
1
+ import { NostrKeyInfo, NostrEvent as NostrEvent$1 } from 'nosskey-sdk';
2
+ import { EventStore } from 'applesauce-core';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as zustand from 'zustand';
5
+
6
+ /**
7
+ * Authentication state interface
8
+ */
9
+ interface AuthState {
10
+ isAuthenticated: boolean;
11
+ publicKey: string | null;
12
+ keyInfo: NostrKeyInfo | null;
13
+ loginError: string | null;
14
+ setAuthenticated: (keyInfo: NostrKeyInfo | null) => void;
15
+ setLoginError: (error: string | null) => void;
16
+ logout: () => void;
17
+ }
18
+ /**
19
+ * Auth service configuration
20
+ */
21
+ interface AuthServiceConfig {
22
+ rpId?: string;
23
+ rpName?: string;
24
+ storageKey?: string;
25
+ cacheTimeoutMs?: number;
26
+ }
27
+ /**
28
+ * Relay service configuration
29
+ */
30
+ interface RelayServiceConfig {
31
+ relayUrls?: string[];
32
+ }
33
+
34
+ /**
35
+ * Service wrapper around NosskeyManager
36
+ * Handles WebAuthn/Passkey integration with Nostr
37
+ */
38
+ declare class AuthService {
39
+ private manager;
40
+ private config;
41
+ constructor(config?: AuthServiceConfig);
42
+ private getDefaultRpName;
43
+ /**
44
+ * Initialize the NosskeyManager instance
45
+ */
46
+ private getManager;
47
+ /**
48
+ * Create a new passkey
49
+ * Uses platform authenticator only (Touch ID, Face ID, Windows Hello)
50
+ */
51
+ createPasskey(username?: string): Promise<Uint8Array>;
52
+ /**
53
+ * Create a new Nostr key from a credential ID
54
+ */
55
+ createNostrKey(credentialId?: Uint8Array): Promise<NostrKeyInfo>;
56
+ /**
57
+ * Get the current public key
58
+ */
59
+ getPublicKey(): Promise<string>;
60
+ /**
61
+ * Sign a Nostr event
62
+ */
63
+ signEvent(event: NostrEvent$1): Promise<NostrEvent$1>;
64
+ /**
65
+ * Get current key info
66
+ */
67
+ getCurrentKeyInfo(): NostrKeyInfo | null;
68
+ /**
69
+ * Set current key info
70
+ */
71
+ setCurrentKeyInfo(keyInfo: NostrKeyInfo): void;
72
+ /**
73
+ * Check if key info exists
74
+ */
75
+ hasKeyInfo(): boolean;
76
+ /**
77
+ * Clear stored key info
78
+ */
79
+ clearStoredKeyInfo(): void;
80
+ /**
81
+ * Check if PRF is supported
82
+ */
83
+ isPrfSupported(): Promise<boolean>;
84
+ }
85
+
86
+ /**
87
+ * Nostr event types
88
+ */
89
+ interface NostrEvent {
90
+ id?: string;
91
+ pubkey?: string;
92
+ created_at?: number;
93
+ kind: number;
94
+ tags?: string[][];
95
+ content: string;
96
+ sig?: string;
97
+ }
98
+ /**
99
+ * Profile metadata (Kind 0)
100
+ */
101
+ interface ProfileMetadata {
102
+ name?: string;
103
+ display_name?: string;
104
+ about?: string;
105
+ picture?: string;
106
+ website?: string;
107
+ [key: string]: unknown;
108
+ }
109
+ /**
110
+ * Follow list entry (from Kind 3 tags)
111
+ */
112
+ interface FollowEntry {
113
+ pubkey: string;
114
+ relay?: string;
115
+ petname?: string;
116
+ }
117
+
118
+ /**
119
+ * Service for communicating with Nostr relays using applesauce-core
120
+ */
121
+ declare class RelayService {
122
+ private eventStore;
123
+ private relayUrls;
124
+ private defaultRelays;
125
+ constructor(config?: RelayServiceConfig);
126
+ /**
127
+ * Initialize with applesauce EventStore
128
+ */
129
+ initialize(eventStore: EventStore): void;
130
+ /**
131
+ * Set relay URLs
132
+ */
133
+ setRelays(urls: string[]): void;
134
+ /**
135
+ * Publish an event to relays
136
+ */
137
+ publishEvent(event: NostrEvent, timeoutMs?: number): Promise<boolean>;
138
+ /**
139
+ * Fetch a profile (Kind 0 event)
140
+ */
141
+ fetchProfile(pubkey: string): Promise<ProfileMetadata | null>;
142
+ /**
143
+ * Fetch role tag from profile event (Kind 0)
144
+ */
145
+ fetchProfileRoleTag(pubkey: string): Promise<string | null>;
146
+ /**
147
+ * Fetch a follow list (Kind 3 event)
148
+ */
149
+ fetchFollowList(pubkey: string): Promise<FollowEntry[]>;
150
+ /**
151
+ * Fetch multiple profiles in batch
152
+ */
153
+ fetchMultipleProfiles(pubkeys: string[]): Promise<Map<string, ProfileMetadata>>;
154
+ /**
155
+ * Query kind 0 events (profiles) by pubkey
156
+ * If pubkeys array is empty, fetches recent kind 0 events
157
+ */
158
+ queryProfiles(pubkeys?: string[], limit?: number): Promise<Map<string, ProfileMetadata>>;
159
+ /**
160
+ * Publish or update a kind 3 event (follow list/contacts)
161
+ */
162
+ publishFollowList(pubkey: string, followList: FollowEntry[], signEvent: (event: NostrEvent) => Promise<NostrEvent>): Promise<boolean>;
163
+ }
164
+
165
+ interface LoginButtonProps {
166
+ authService: AuthService;
167
+ setAuthenticated: AuthState['setAuthenticated'];
168
+ setLoginError: AuthState['setLoginError'];
169
+ onSuccess?: () => void;
170
+ }
171
+ declare function LoginButton({ authService, setAuthenticated, setLoginError, onSuccess, }: LoginButtonProps): react_jsx_runtime.JSX.Element;
172
+
173
+ interface RegistrationFlowProps {
174
+ authService: AuthService;
175
+ setAuthenticated: AuthState['setAuthenticated'];
176
+ onSuccess?: () => void;
177
+ }
178
+ declare function RegistrationFlow({ authService, setAuthenticated, onSuccess, }: RegistrationFlowProps): react_jsx_runtime.JSX.Element;
179
+
180
+ interface MembershipPageProps {
181
+ authService: AuthService;
182
+ relayService: RelayService;
183
+ publicKey: string | null;
184
+ onUnauthenticated?: () => void;
185
+ }
186
+ declare function MembershipPage({ authService, relayService, publicKey, onUnauthenticated, }: MembershipPageProps): react_jsx_runtime.JSX.Element;
187
+
188
+ interface BarcodeScannerProps {
189
+ /** Called when a code is successfully read */
190
+ onDecode: (value: string) => void;
191
+ /** Optional flag to hide the scanner */
192
+ active?: boolean;
193
+ }
194
+ declare const BarcodeScanner: ({ onDecode, active }: BarcodeScannerProps) => react_jsx_runtime.JSX.Element | null;
195
+
196
+ interface ProfilePageProps {
197
+ authService: AuthService;
198
+ relayService: RelayService;
199
+ publicKey: string | null;
200
+ onUnauthenticated?: () => void;
201
+ onSuccess?: () => void;
202
+ onRoleSuggestion?: (about: string) => Promise<string | null>;
203
+ }
204
+ declare function ProfilePage({ authService, relayService, publicKey, onUnauthenticated, onSuccess, onRoleSuggestion, }: ProfilePageProps): react_jsx_runtime.JSX.Element;
205
+
206
+ /**
207
+ * Hook to initialize auth state on app load
208
+ */
209
+ declare function useAuthInit(authService: AuthService, setAuthenticated: AuthState['setAuthenticated']): void;
210
+
211
+ declare const createAuthStore: () => zustand.UseBoundStore<zustand.StoreApi<AuthState>>;
212
+ declare const useAuthStore: zustand.UseBoundStore<zustand.StoreApi<AuthState>>;
213
+
214
+ export { AuthService, type AuthServiceConfig, type AuthState, BarcodeScanner, type FollowEntry, LoginButton, MembershipPage, type NostrEvent, type ProfileMetadata, ProfilePage, RegistrationFlow, RelayService, type RelayServiceConfig, createAuthStore, useAuthInit, useAuthStore };
@@ -0,0 +1,214 @@
1
+ import { NostrKeyInfo, NostrEvent as NostrEvent$1 } from 'nosskey-sdk';
2
+ import { EventStore } from 'applesauce-core';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as zustand from 'zustand';
5
+
6
+ /**
7
+ * Authentication state interface
8
+ */
9
+ interface AuthState {
10
+ isAuthenticated: boolean;
11
+ publicKey: string | null;
12
+ keyInfo: NostrKeyInfo | null;
13
+ loginError: string | null;
14
+ setAuthenticated: (keyInfo: NostrKeyInfo | null) => void;
15
+ setLoginError: (error: string | null) => void;
16
+ logout: () => void;
17
+ }
18
+ /**
19
+ * Auth service configuration
20
+ */
21
+ interface AuthServiceConfig {
22
+ rpId?: string;
23
+ rpName?: string;
24
+ storageKey?: string;
25
+ cacheTimeoutMs?: number;
26
+ }
27
+ /**
28
+ * Relay service configuration
29
+ */
30
+ interface RelayServiceConfig {
31
+ relayUrls?: string[];
32
+ }
33
+
34
+ /**
35
+ * Service wrapper around NosskeyManager
36
+ * Handles WebAuthn/Passkey integration with Nostr
37
+ */
38
+ declare class AuthService {
39
+ private manager;
40
+ private config;
41
+ constructor(config?: AuthServiceConfig);
42
+ private getDefaultRpName;
43
+ /**
44
+ * Initialize the NosskeyManager instance
45
+ */
46
+ private getManager;
47
+ /**
48
+ * Create a new passkey
49
+ * Uses platform authenticator only (Touch ID, Face ID, Windows Hello)
50
+ */
51
+ createPasskey(username?: string): Promise<Uint8Array>;
52
+ /**
53
+ * Create a new Nostr key from a credential ID
54
+ */
55
+ createNostrKey(credentialId?: Uint8Array): Promise<NostrKeyInfo>;
56
+ /**
57
+ * Get the current public key
58
+ */
59
+ getPublicKey(): Promise<string>;
60
+ /**
61
+ * Sign a Nostr event
62
+ */
63
+ signEvent(event: NostrEvent$1): Promise<NostrEvent$1>;
64
+ /**
65
+ * Get current key info
66
+ */
67
+ getCurrentKeyInfo(): NostrKeyInfo | null;
68
+ /**
69
+ * Set current key info
70
+ */
71
+ setCurrentKeyInfo(keyInfo: NostrKeyInfo): void;
72
+ /**
73
+ * Check if key info exists
74
+ */
75
+ hasKeyInfo(): boolean;
76
+ /**
77
+ * Clear stored key info
78
+ */
79
+ clearStoredKeyInfo(): void;
80
+ /**
81
+ * Check if PRF is supported
82
+ */
83
+ isPrfSupported(): Promise<boolean>;
84
+ }
85
+
86
+ /**
87
+ * Nostr event types
88
+ */
89
+ interface NostrEvent {
90
+ id?: string;
91
+ pubkey?: string;
92
+ created_at?: number;
93
+ kind: number;
94
+ tags?: string[][];
95
+ content: string;
96
+ sig?: string;
97
+ }
98
+ /**
99
+ * Profile metadata (Kind 0)
100
+ */
101
+ interface ProfileMetadata {
102
+ name?: string;
103
+ display_name?: string;
104
+ about?: string;
105
+ picture?: string;
106
+ website?: string;
107
+ [key: string]: unknown;
108
+ }
109
+ /**
110
+ * Follow list entry (from Kind 3 tags)
111
+ */
112
+ interface FollowEntry {
113
+ pubkey: string;
114
+ relay?: string;
115
+ petname?: string;
116
+ }
117
+
118
+ /**
119
+ * Service for communicating with Nostr relays using applesauce-core
120
+ */
121
+ declare class RelayService {
122
+ private eventStore;
123
+ private relayUrls;
124
+ private defaultRelays;
125
+ constructor(config?: RelayServiceConfig);
126
+ /**
127
+ * Initialize with applesauce EventStore
128
+ */
129
+ initialize(eventStore: EventStore): void;
130
+ /**
131
+ * Set relay URLs
132
+ */
133
+ setRelays(urls: string[]): void;
134
+ /**
135
+ * Publish an event to relays
136
+ */
137
+ publishEvent(event: NostrEvent, timeoutMs?: number): Promise<boolean>;
138
+ /**
139
+ * Fetch a profile (Kind 0 event)
140
+ */
141
+ fetchProfile(pubkey: string): Promise<ProfileMetadata | null>;
142
+ /**
143
+ * Fetch role tag from profile event (Kind 0)
144
+ */
145
+ fetchProfileRoleTag(pubkey: string): Promise<string | null>;
146
+ /**
147
+ * Fetch a follow list (Kind 3 event)
148
+ */
149
+ fetchFollowList(pubkey: string): Promise<FollowEntry[]>;
150
+ /**
151
+ * Fetch multiple profiles in batch
152
+ */
153
+ fetchMultipleProfiles(pubkeys: string[]): Promise<Map<string, ProfileMetadata>>;
154
+ /**
155
+ * Query kind 0 events (profiles) by pubkey
156
+ * If pubkeys array is empty, fetches recent kind 0 events
157
+ */
158
+ queryProfiles(pubkeys?: string[], limit?: number): Promise<Map<string, ProfileMetadata>>;
159
+ /**
160
+ * Publish or update a kind 3 event (follow list/contacts)
161
+ */
162
+ publishFollowList(pubkey: string, followList: FollowEntry[], signEvent: (event: NostrEvent) => Promise<NostrEvent>): Promise<boolean>;
163
+ }
164
+
165
+ interface LoginButtonProps {
166
+ authService: AuthService;
167
+ setAuthenticated: AuthState['setAuthenticated'];
168
+ setLoginError: AuthState['setLoginError'];
169
+ onSuccess?: () => void;
170
+ }
171
+ declare function LoginButton({ authService, setAuthenticated, setLoginError, onSuccess, }: LoginButtonProps): react_jsx_runtime.JSX.Element;
172
+
173
+ interface RegistrationFlowProps {
174
+ authService: AuthService;
175
+ setAuthenticated: AuthState['setAuthenticated'];
176
+ onSuccess?: () => void;
177
+ }
178
+ declare function RegistrationFlow({ authService, setAuthenticated, onSuccess, }: RegistrationFlowProps): react_jsx_runtime.JSX.Element;
179
+
180
+ interface MembershipPageProps {
181
+ authService: AuthService;
182
+ relayService: RelayService;
183
+ publicKey: string | null;
184
+ onUnauthenticated?: () => void;
185
+ }
186
+ declare function MembershipPage({ authService, relayService, publicKey, onUnauthenticated, }: MembershipPageProps): react_jsx_runtime.JSX.Element;
187
+
188
+ interface BarcodeScannerProps {
189
+ /** Called when a code is successfully read */
190
+ onDecode: (value: string) => void;
191
+ /** Optional flag to hide the scanner */
192
+ active?: boolean;
193
+ }
194
+ declare const BarcodeScanner: ({ onDecode, active }: BarcodeScannerProps) => react_jsx_runtime.JSX.Element | null;
195
+
196
+ interface ProfilePageProps {
197
+ authService: AuthService;
198
+ relayService: RelayService;
199
+ publicKey: string | null;
200
+ onUnauthenticated?: () => void;
201
+ onSuccess?: () => void;
202
+ onRoleSuggestion?: (about: string) => Promise<string | null>;
203
+ }
204
+ declare function ProfilePage({ authService, relayService, publicKey, onUnauthenticated, onSuccess, onRoleSuggestion, }: ProfilePageProps): react_jsx_runtime.JSX.Element;
205
+
206
+ /**
207
+ * Hook to initialize auth state on app load
208
+ */
209
+ declare function useAuthInit(authService: AuthService, setAuthenticated: AuthState['setAuthenticated']): void;
210
+
211
+ declare const createAuthStore: () => zustand.UseBoundStore<zustand.StoreApi<AuthState>>;
212
+ declare const useAuthStore: zustand.UseBoundStore<zustand.StoreApi<AuthState>>;
213
+
214
+ export { AuthService, type AuthServiceConfig, type AuthState, BarcodeScanner, type FollowEntry, LoginButton, MembershipPage, type NostrEvent, type ProfileMetadata, ProfilePage, RegistrationFlow, RelayService, type RelayServiceConfig, createAuthStore, useAuthInit, useAuthStore };