@opensecret/react 0.2.0 → 0.3.1

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
@@ -64,7 +64,10 @@ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an ob
64
64
 
65
65
  #### Authentication Methods
66
66
  - `signIn(email: string, password: string): Promise<void>`: Signs in a user with the provided email and password.
67
- - `signUp(name: string, email: string, password: string, inviteCode: string): Promise<void>`: Signs up a new user with the provided name, email, password, and invite code.
67
+ - `signUp(email: string, password: string, inviteCode: string, name?: string): Promise<void>`: Signs up a new user with the provided email, password, invite code, and optional name.
68
+ - `signInGuest(id: string, password: string): Promise<void>`: Signs in a guest user with their ID and password.
69
+ - `signUpGuest(password: string, inviteCode: string): Promise<LoginResponse>`: Creates a new guest account with just a password and invite code. Returns a response containing the guest's ID, access token, and refresh token.
70
+ - `convertGuestToUserAccount(email: string, password: string, name?: string): Promise<void>`: Converts current guest account to a regular account with email authentication. Optionally sets the user's name.
68
71
  - `signOut(): Promise<void>`: Signs out the current user.
69
72
 
70
73
  #### Key-Value Storage Methods
@@ -76,6 +79,7 @@ The `useOpenSecret` hook provides access to the OpenSecret API. It returns an ob
76
79
  #### Account Management Methods
77
80
  - `refetchUser(): Promise<void>`: Refreshes the user's authentication state.
78
81
  - `changePassword(currentPassword: string, newPassword: string): Promise<void>`: Changes the user's password.
82
+ - `generateThirdPartyToken(audience: string): Promise<{ token: string }>`: Generates a JWT token for use with pre-authorized third-party services (e.g. "https://api.devservice.com"). Developers must register this URL in advance (coming soon).
79
83
 
80
84
  #### Cryptographic Methods
81
85
  - `getPrivateKey(): Promise<PrivateKeyResponse>`: Retrieves the user's private key mnemonic phrase. This is used for cryptographic operations and should be kept secure.
package/dist/index.d.ts CHANGED
@@ -6,7 +6,9 @@ declare namespace api {
6
6
  export {
7
7
  setApiUrl,
8
8
  fetchLogin,
9
+ fetchGuestLogin,
9
10
  fetchSignUp,
11
+ fetchGuestSignUp,
10
12
  refreshToken,
11
13
  fetchUser,
12
14
  fetchPut,
@@ -28,6 +30,8 @@ declare namespace api {
28
30
  fetchPrivateKey,
29
31
  signMessage,
30
32
  fetchPublicKey,
33
+ convertGuestToEmailAccount,
34
+ generateThirdPartyToken,
31
35
  LoginResponse,
32
36
  UserResponse,
33
37
  KVListItem,
@@ -35,7 +39,9 @@ declare namespace api {
35
39
  GoogleAuthResponse,
36
40
  PrivateKeyResponse,
37
41
  SignMessageResponse,
38
- PublicKeyResponse
42
+ PublicKeyResponse,
43
+ ThirdPartyTokenRequest,
44
+ ThirdPartyTokenResponse
39
45
  }
40
46
  }
41
47
 
@@ -86,6 +92,8 @@ declare function changePassword(currentPassword: string, newPassword: string): P
86
92
 
87
93
  declare function confirmPasswordReset(email: string, alphanumericCode: string, plaintextSecret: string, newPassword: string): Promise<void>;
88
94
 
95
+ declare function convertGuestToEmailAccount(email: string, password: string, name?: string): Promise<void>;
96
+
89
97
  declare const EXPECTED_ROOT_CERT_HASH = "641a0321a3e244efe456463195d606317ed7cdcc3c1756e09893f3c68f79bb5b";
90
98
 
91
99
  declare function fetchAttestationDocument(nonce: string): Promise<string>;
@@ -94,6 +102,10 @@ declare function fetchDelete(key: string): Promise<void>;
94
102
 
95
103
  declare function fetchGet(key: string): Promise<string | undefined>;
96
104
 
105
+ declare function fetchGuestLogin(id: string, password: string): Promise<LoginResponse>;
106
+
107
+ declare function fetchGuestSignUp(password: string, inviteCode: string): Promise<LoginResponse>;
108
+
97
109
  declare function fetchList(): Promise<KVListItem[]>;
98
110
 
99
111
  declare function fetchLogin(email: string, password: string): Promise<LoginResponse>;
@@ -106,12 +118,14 @@ declare function fetchPublicKey(algorithm: SigningAlgorithm): Promise<PublicKeyR
106
118
 
107
119
  declare function fetchPut(key: string, value: string): Promise<string>;
108
120
 
109
- declare function fetchSignUp(name: string, email: string, password: string, inviteCode: string): Promise<LoginResponse>;
121
+ declare function fetchSignUp(email: string, password: string, inviteCode: string, name?: string | null): Promise<LoginResponse>;
110
122
 
111
123
  declare function fetchUser(): Promise<UserResponse>;
112
124
 
113
125
  export declare function generateSecureSecret(): string;
114
126
 
127
+ declare function generateThirdPartyToken(audience: string): Promise<ThirdPartyTokenResponse>;
128
+
115
129
  declare function getAttestation(forceRefresh?: boolean): Promise<Attestation>;
116
130
 
117
131
  export declare type GithubAuthResponse = {
@@ -147,8 +161,8 @@ export declare type KVListItem = {
147
161
  };
148
162
 
149
163
  export declare type LoginResponse = {
150
- id: number;
151
- email: string;
164
+ id: string;
165
+ email?: string;
152
166
  access_token: string;
153
167
  refresh_token: string;
154
168
  };
@@ -178,10 +192,10 @@ export declare type OpenSecretContextType = {
178
192
  signIn: (email: string, password: string) => Promise<void>;
179
193
  /**
180
194
  * Creates a new user account
181
- * @param name - User's full name
182
195
  * @param email - User's email address
183
196
  * @param password - User's chosen password
184
197
  * @param inviteCode - Invitation code for registration
198
+ * @param name - Optional user's full name
185
199
  * @returns A promise that resolves when account creation is complete
186
200
  * @throws {Error} If signup fails
187
201
  *
@@ -191,7 +205,53 @@ export declare type OpenSecretContextType = {
191
205
  * - Updates the auth state with new user information
192
206
  * - Throws an error if account creation fails
193
207
  */
194
- signUp: (name: string, email: string, password: string, inviteCode: string) => Promise<void>;
208
+ signUp: (email: string, password: string, inviteCode: string, name?: string) => Promise<void>;
209
+ /**
210
+ * Authenticates a guest user with user id and password
211
+ * @param id - User's unique id
212
+ * @param password - User's password
213
+ * @returns A promise that resolves when authentication is complete
214
+ * @throws {Error} If login fails
215
+ *
216
+ * @description
217
+ * - Calls the login API endpoint
218
+ * - Stores access_token and refresh_token in localStorage
219
+ * - Updates the auth state with user information
220
+ * - Throws an error if authentication fails
221
+ */
222
+ signInGuest: (id: string, password: string) => Promise<void>;
223
+ /**
224
+ * Creates a new guest account, which can be upgraded to a normal account later with email.
225
+ * @param password - User's chosen password, cannot be changed or recovered without adding email address.
226
+ * @param inviteCode - Invitation code for registration
227
+ * @returns A promise that resolves to the login response containing the guest ID
228
+ * @throws {Error} If signup fails
229
+ *
230
+ * @description
231
+ * - Calls the registration API endpoint
232
+ * - Stores access_token and refresh_token in localStorage
233
+ * - Updates the auth state with new user information
234
+ * - Throws an error if account creation fails
235
+ */
236
+ signUpGuest: (password: string, inviteCode: string) => Promise<LoginResponse>;
237
+ /**
238
+ * Upgrades a guest account to a user account with email and password authentication.
239
+ * @param email - User's email address
240
+ * @param password - User's chosen password
241
+ * @param name - Optional user's full name
242
+ * @returns A promise that resolves when account creation is complete
243
+ * @throws {Error} If:
244
+ * - The current user is not a guest account
245
+ * - The email address is already in use
246
+ * - The user is not authenticated
247
+ *
248
+ * @description
249
+ * - Upgrades the currently signed-in guest account (identified by their UUID) to a full email account
250
+ * - Requires the user to be currently authenticated as a guest
251
+ * - Updates the auth state with new user information
252
+ * - Preserves all existing data associated with the guest account
253
+ */
254
+ convertGuestToUserAccount: (email: string, password: string, name?: string) => Promise<void>;
195
255
  /**
196
256
  * Logs out the current user
197
257
  * @returns A promise that resolves when logout is complete
@@ -351,6 +411,22 @@ export declare type OpenSecretContextType = {
351
411
  * 3. Parses it for viewing
352
412
  */
353
413
  getAttestationDocument: () => Promise<ParsedAttestationView>;
414
+ /**
415
+ * Generates a JWT token for use with authorized third-party services
416
+ * @param audience - The URL of the authorized service (e.g. "https://billing.opensecret.cloud")
417
+ * @returns A promise resolving to the token response
418
+ * @throws {Error} If:
419
+ * - The user is not authenticated
420
+ * - The audience URL is invalid
421
+ * - The audience URL is not authorized
422
+ *
423
+ * @description
424
+ * - Generates a signed JWT token for use with specific authorized third-party services
425
+ * - The audience must be an pre-authorized URL registered by the developer (e.g. api.devservice.com)
426
+ * - Requires an active authentication session
427
+ * - Token can be used to authenticate with the specified service
428
+ */
429
+ generateThirdPartyToken: (audience: string) => Promise<ThirdPartyTokenResponse>;
354
430
  };
355
431
 
356
432
  /**
@@ -442,13 +518,21 @@ declare type SignMessageResponse = {
442
518
  message_hash: string;
443
519
  };
444
520
 
521
+ declare type ThirdPartyTokenRequest = {
522
+ audience: string;
523
+ };
524
+
525
+ declare type ThirdPartyTokenResponse = {
526
+ token: string;
527
+ };
528
+
445
529
  export declare function useOpenSecret(): OpenSecretContextType;
446
530
 
447
531
  export declare type UserResponse = {
448
532
  user: {
449
533
  id: string;
450
534
  name: string | null;
451
- email: string;
535
+ email?: string;
452
536
  email_verified: boolean;
453
537
  login_method: string;
454
538
  created_at: string;