ns-auth-sdk 1.2.6 → 1.4.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.
package/README.md CHANGED
@@ -1,16 +1,30 @@
1
1
  # NS Auth SDK
2
+
3
+ _The simplest way of doing Auth with seamless and decentralized Key-Management for SSO, Authentication, Membership, and Profile-Management_
2
4
 
3
- Decentralized SSO - Authentication, membership, and profile management.
5
+ ### Who is it for?
6
+ Being trusted by Financial Institutions for Client Onboarding and Digital Communities for Membership Management. Examples include [NSAuth](https://nsauth.vercel.app/) and [OneBoard](https://www.oneboard.li/).
7
+ The SDK enables client-side managing of private-keys with WebAuthn passkeys (FIDO2 credentials). By leveraging passkeys, users avoid traditional private‑key backups and password hassles, relying instead on biometric or device‑based authentication. The keys are compatible with common blockchains like Bitcoin and Ethereum and data is stored as events on public relays and can be encrypted.
4
8
 
5
- NSAuth enables client-side managing of private-keys with WebAuthn passkeys (FIDO2 credentials). By leveraging passkeys, users avoid traditional private‑key backups and password hassles, relying instead on biometric or device‑based authentication. The keys are compatible with common blockchains like Bitcoin and Ethereum and data is stored as events on public relays and can be encrypted.
9
+ ## The Open Alternative for Auth
10
+ Open‑source, client‑side, decentralized single‑sign‑on (SSO) like NSAuth is superior because it puts the user’s identity and cryptographic keys directly in the hands of the individual, eliminating reliance on any central authority that could become a single point of failure, a privacy sinkhole, or a bottleneck for policy updates. By storing a self‑sovereign credential on the device’s secure enclave and validating access against a signed, versioned member list, every interaction—from unlocking a gym door to logging into an online course is verified instantly without ever transmitting personal identifiers. This architecture enables real‑time privilege changes (a badge upgrade or a revocation propagates the moment the list is updated), removes passwords and phishing risk through biometric or hardware‑key authentication, and works uniformly for anyone, including stateless persons or diaspora communities, because trust is derived from cryptographic proofs rather than government‑issued IDs. Moreover, being open source lets developers audit the code, contribute improvements, and ensure transparency, while the decentralized design guarantees that no single entity can unilaterally alter membership rules, providing stronger governance, auditability, and privacy than traditional, server‑centric SSO solutions.
6
11
 
7
- Two Approaches
8
- PRF Direct Method – Derive the private key directly from the PRF value produced by a passkey. Encryption Method – Encrypt an existing private key with a key derived from the passkey’s PRF output. WebAuthn PRF Extension The PRF (Pseudo‑Random Function) extension, part of WebAuthn Level 3, yields deterministic 32‑byte high‑entropy values from an authenticator’s internal private key and a supplied salt. The same credential ID and salt always generate the same PRF output, which never leaves the device except during authentication.
12
+ ## Technology
9
13
 
10
- Using PRF Values as Private Keys
14
+ ### Choose your Backend
15
+ NSAuth is designed as a frontend SSO where data can be synced in a trust minimized way. The basics are there for extensions to interoperate with Farcaster, Nostr, Ethereum, Solana or even regular webservers.
16
+
17
+ ### Two Approaches
18
+ #### PRF Direct Method
19
+ Derive the private key directly from the PRF value produced by a passkey.
20
+
21
+ #### Encryption Method
22
+ Encrypt an existing private key with a key derived from the passkey’s PRF output. WebAuthn PRF Extension The PRF (Pseudo‑Random Function) extension, part of WebAuthn Level 3, yields deterministic 32‑byte high‑entropy values from an authenticator’s internal private key and a supplied salt. The same credential ID and salt always generate the same PRF output, which never leaves the device except during authentication.
23
+
24
+ ### Using PRF Values as Private Keys
11
25
  A 32‑byte PRF output can serve as a private key if it falls within the secp256k1 range (1 ≤ value < n). The chance of falling outside this range is astronomically low (~2⁻²²⁴), so explicit range checks are generally unnecessary.
12
26
 
13
- Restoration Steps
27
+ ### Restoration Steps
14
28
  Install the client on a new device. Fetch the latest kind 30100 event for the target public key. Extract the PWKBlob and decrypt it with the passkey’s PRF value. Use the recovered private key for signing. Multiple passkeys can each have their own PWKBlob, allowing redundancy across devices.
15
29
 
16
30
 
@@ -39,15 +53,16 @@ const authService = new AuthService({
39
53
  rpId: 'your-domain.com',
40
54
  rpName: 'Your App Name',
41
55
  storageKey: 'nsauth_keyinfo',
56
+ cacheOnCreation: true, // Enable early caching (default: true)
42
57
  });
43
58
 
44
- // Initialize relay service with applesauce EventStore
59
+ // Initialize relay service with EventStore
45
60
  const relayService = new RelayService({
46
- relayUrls: ['wss://relay.damus.io'],
61
+ relayUrls: ['wss://relay.io'],
47
62
  });
48
63
 
49
- // Initialize with applesauce EventStore
50
- const eventStore = new EventStore(/* applesauce config */);
64
+ // Initialize with EventStore
65
+ const eventStore = new EventStore(/* config */);
51
66
  relayService.initialize(eventStore);
52
67
  ```
53
68
 
@@ -156,10 +171,6 @@ function MembershipPageComponent() {
156
171
 
157
172
  ## API Reference
158
173
 
159
- ### AuthService
160
-
161
- Wrapper around `nosskey-sdk` for WebAuthn/Passkey integration.
162
-
163
174
  #### Methods
164
175
 
165
176
  - `createPasskey(username?: string): Promise<Uint8Array>` - Create a new passkey
@@ -172,13 +183,41 @@ Wrapper around `nosskey-sdk` for WebAuthn/Passkey integration.
172
183
  - `clearStoredKeyInfo(): void` - Clear stored key info
173
184
  - `isPrfSupported(): Promise<boolean>` - Check if PRF is supported
174
185
 
186
+ #### Configuration Options
187
+
188
+ ```typescript
189
+ interface NosskeyManagerOptions {
190
+ cacheOptions?: {
191
+ enabled: boolean;
192
+ timeoutMs?: number;
193
+ cacheOnCreation?: boolean; // Cache key immediately after derivation (default: true)
194
+ };
195
+ storageOptions?: {
196
+ enabled: boolean;
197
+ storage?: Storage;
198
+ storageKey?: string;
199
+ };
200
+ prfOptions?: {
201
+ rpId?: string;
202
+ timeout?: number;
203
+ userVerification?: UserVerificationRequirement;
204
+ };
205
+ }
206
+ ```
207
+
208
+ **Cache Options:**
209
+ - `enabled`: Enable/disable key caching
210
+ - `timeoutMs`: Cache timeout in milliseconds (default: 30 minutes)
211
+ - `cacheOnCreation`: When `true`, caches the key immediately after `createNostrKey()` to reduce biometric prompts from 2-3 to 1-2. This is enabled by default for better user experience.
212
+
175
213
  ### RelayService
176
214
 
177
215
  Service for communicating with Nostr relays using applesauce-core.
178
216
 
179
217
  #### Methods
180
218
 
181
- - `initialize(eventStore: EventStore): void` - Initialize with applesauce EventStore
219
+ - `initialize(eventStore: EventStore): void` - Initialize with EventStore
220
+ - `getRelays(): string[]` - Get current relay URLs
182
221
  - `setRelays(urls: string[]): void` - Set relay URLs
183
222
  - `publishEvent(event: NostrEvent, timeoutMs?: number): Promise<boolean>` - Publish event
184
223
  - `fetchProfile(pubkey: string): Promise<ProfileMetadata | null>` - Fetch profile
@@ -209,10 +248,16 @@ import { EventStore } from 'applesauce-core';
209
248
  import { RelayService } from 'ns-auth-sdk';
210
249
 
211
250
  const eventStore = new EventStore({
212
- // applesauce configuration
251
+ // configuration
213
252
  });
214
253
 
215
254
  const relayService = new RelayService();
216
255
  relayService.initialize(eventStore);
217
256
  ```
218
257
 
258
+ ## Security Guidance
259
+
260
+ - Configure a strict Content Security Policy (CSP) in the host app to restrict script and image sources.
261
+ - Add rate limiting or debouncing around profile queries and event publishing in the host app or API layer.
262
+ - Avoid surfacing raw error details to end users; log detailed errors in secure logs.
263
+