ns-auth-sdk 1.2.5 → 1.3.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,6 +1,32 @@
1
- # NS Auth SSO
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_
4
+
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.
8
+
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.
11
+
12
+ ## Technology
13
+
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
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.
26
+
27
+ ### Restoration Steps
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.
2
29
 
3
- SSO library for NS Auth - Authentication, membership, and profile management compatible with applesauce.
4
30
 
5
31
  ## Installation
6
32
 
@@ -14,15 +40,6 @@ pnpm install ns-auth-sdk
14
40
  yarn add ns-auth-sdk
15
41
  ```
16
42
 
17
- ## Peer Dependencies
18
-
19
- This library requires the following peer dependencies:
20
-
21
- - `react` ^18.0.0
22
- - `react-dom` ^18.0.0
23
- - `applesauce-core` ^5.0.0
24
- - `nosskey-sdk` ^0.0.4
25
-
26
43
  ## Quick Start
27
44
 
28
45
  ### 1. Initialize Services
@@ -38,13 +55,13 @@ const authService = new AuthService({
38
55
  storageKey: 'nsauth_keyinfo',
39
56
  });
40
57
 
41
- // Initialize relay service with applesauce EventStore
58
+ // Initialize relay service with EventStore
42
59
  const relayService = new RelayService({
43
- relayUrls: ['wss://relay.damus.io'],
60
+ relayUrls: ['wss://relay.io'],
44
61
  });
45
62
 
46
- // Initialize with applesauce EventStore
47
- const eventStore = new EventStore(/* applesauce config */);
63
+ // Initialize with EventStore
64
+ const eventStore = new EventStore(/* config */);
48
65
  relayService.initialize(eventStore);
49
66
  ```
50
67
 
@@ -153,10 +170,6 @@ function MembershipPageComponent() {
153
170
 
154
171
  ## API Reference
155
172
 
156
- ### AuthService
157
-
158
- Wrapper around `nosskey-sdk` for WebAuthn/Passkey integration.
159
-
160
173
  #### Methods
161
174
 
162
175
  - `createPasskey(username?: string): Promise<Uint8Array>` - Create a new passkey
@@ -175,7 +188,8 @@ Service for communicating with Nostr relays using applesauce-core.
175
188
 
176
189
  #### Methods
177
190
 
178
- - `initialize(eventStore: EventStore): void` - Initialize with applesauce EventStore
191
+ - `initialize(eventStore: EventStore): void` - Initialize with EventStore
192
+ - `getRelays(): string[]` - Get current relay URLs
179
193
  - `setRelays(urls: string[]): void` - Set relay URLs
180
194
  - `publishEvent(event: NostrEvent, timeoutMs?: number): Promise<boolean>` - Publish event
181
195
  - `fetchProfile(pubkey: string): Promise<ProfileMetadata | null>` - Fetch profile
@@ -206,17 +220,16 @@ import { EventStore } from 'applesauce-core';
206
220
  import { RelayService } from 'ns-auth-sdk';
207
221
 
208
222
  const eventStore = new EventStore({
209
- // applesauce configuration
223
+ // configuration
210
224
  });
211
225
 
212
226
  const relayService = new RelayService();
213
227
  relayService.initialize(eventStore);
214
228
  ```
215
229
 
216
- ## TypeScript Support
217
-
218
- This library is written in TypeScript and includes full type definitions.
230
+ ## Security Guidance
219
231
 
220
- ## License
232
+ - Configure a strict Content Security Policy (CSP) in the host app to restrict script and image sources.
233
+ - Add rate limiting or debouncing around profile queries and event publishing in the host app or API layer.
234
+ - Avoid surfacing raw error details to end users; log detailed errors in secure logs.
221
235
 
222
- MIT