@bandeira-tech/b3nd-web 0.2.5 → 0.2.7

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.
@@ -1,354 +1,135 @@
1
- /**
2
- * Wallet Client Types
3
- *
4
- * Type definitions for the B3nd Wallet Client that interacts with wallet servers.
5
- */
6
- /**
7
- * Configuration for wallet client
8
- */
9
- interface WalletClientConfig {
10
- /**
11
- * Wallet server URL (e.g., "http://localhost:3001")
12
- */
13
- walletServerUrl: string;
14
- /**
15
- * API base path prefix (e.g., "/api/v1"). Must be provided explicitly.
16
- */
17
- apiBasePath: string;
18
- /**
19
- * Optional fetch implementation (for custom HTTP handling)
20
- */
21
- fetch?: typeof fetch;
22
- }
23
- /**
24
- * User credentials for authentication
25
- */
26
- interface UserCredentials {
27
- username: string;
28
- password: string;
29
- }
30
- /**
31
- * Authenticated session with JWT token
32
- */
33
- interface AuthSession {
34
- username: string;
35
- token: string;
36
- expiresIn: number;
37
- }
38
- /**
39
- * User's public keys
40
- */
41
- interface UserPublicKeys {
42
- accountPublicKeyHex: string;
43
- encryptionPublicKeyHex: string;
44
- }
45
- /**
46
- * Password reset token
47
- */
48
- interface PasswordResetToken {
49
- resetToken: string;
50
- expiresIn: number;
51
- }
52
- /**
53
- * Write proxy request
54
- */
55
- interface ProxyWriteRequest {
56
- uri: string;
57
- data: unknown;
58
- encrypt?: boolean;
59
- }
60
- /**
61
- * Write proxy response
62
- */
63
- interface ProxyWriteResponse {
64
- success: boolean;
65
- uri: string;
66
- resolvedUri?: string;
67
- data: unknown;
68
- record?: {
69
- data: unknown;
70
- ts: number;
71
- };
72
- }
73
- /**
74
- * Read proxy request
75
- */
76
- interface ProxyReadRequest {
77
- uri: string;
78
- }
79
- /**
80
- * Read proxy response
81
- */
82
- interface ProxyReadResponse {
83
- success: boolean;
84
- uri: string;
85
- record?: {
86
- data: unknown;
87
- ts: number;
88
- };
89
- decrypted?: unknown;
90
- error?: string;
91
- }
92
- /**
93
- * API response wrapper
94
- */
95
- interface ApiResponse {
96
- success: boolean;
97
- error?: string;
98
- [key: string]: unknown;
99
- }
100
- /**
101
- * Signup response
102
- */
103
- interface SignupResponse extends ApiResponse {
104
- username: string;
105
- token: string;
106
- expiresIn: number;
107
- }
108
- /**
109
- * Login response
110
- */
111
- interface LoginResponse extends ApiResponse {
112
- username: string;
113
- token: string;
114
- expiresIn: number;
115
- }
116
- /**
117
- * Public keys response
118
- */
119
- interface PublicKeysResponse extends ApiResponse {
120
- accountPublicKeyHex: string;
121
- encryptionPublicKeyHex: string;
122
- }
123
- /**
124
- * Change password response
125
- */
126
- interface ChangePasswordResponse extends ApiResponse {
127
- message: string;
128
- }
129
- /**
130
- * Request password reset response
131
- */
132
- interface RequestPasswordResetResponse extends ApiResponse {
133
- message: string;
134
- resetToken: string;
135
- expiresIn: number;
136
- }
137
- /**
138
- * Reset password response
139
- */
140
- interface ResetPasswordResponse extends ApiResponse {
141
- message: string;
142
- username: string;
143
- token: string;
144
- expiresIn: number;
145
- }
146
- /**
147
- * Health check response
148
- */
149
- interface HealthResponse extends ApiResponse {
150
- status: string;
151
- server: string;
152
- timestamp: string;
153
- }
154
- /**
155
- * Google OAuth session (extended AuthSession with Google profile info)
156
- */
157
- interface GoogleAuthSession extends AuthSession {
158
- email: string;
159
- name?: string;
160
- picture?: string;
161
- }
162
- /**
163
- * Google signup response
164
- */
165
- interface GoogleSignupResponse extends ApiResponse {
166
- username: string;
167
- email: string;
168
- name?: string;
169
- picture?: string;
170
- token: string;
171
- expiresIn: number;
172
- }
173
- /**
174
- * Google login response
175
- */
176
- interface GoogleLoginResponse extends ApiResponse {
177
- username: string;
178
- email: string;
179
- name?: string;
180
- picture?: string;
181
- token: string;
182
- expiresIn: number;
183
- }
1
+ import { A as AuthSession, H as HealthResponse, U as UserCredentials, P as PasswordResetToken, a as UserPublicKeys, b as ProxyWriteRequest, c as ProxyWriteResponse, d as ProxyReadRequest, e as ProxyReadResponse, G as GoogleAuthSession } from '../client-B0Ekm99R.js';
2
+ export { g as ApiResponse, C as ChangePasswordResponse, k as GoogleLoginResponse, j as GoogleSignupResponse, L as LoginResponse, h as PublicKeysResponse, R as RequestPasswordResetResponse, i as ResetPasswordResponse, S as SignupResponse, W as WalletClient, f as WalletClientConfig } from '../client-B0Ekm99R.js';
3
+ import { N as NodeProtocolInterface } from '../types-oQCx3U-_.js';
4
+ import { S as ServerKeys, W as WalletServerCore } from '../core-CgxQpSVM.js';
5
+ import 'hono';
184
6
 
185
7
  /**
186
- * B3nd Wallet Client
8
+ * Memory Wallet Client
187
9
  *
188
- * Client library for interacting with B3nd wallet servers.
189
- * Provides authentication, key management, and write proxying functionality.
190
- *
191
- * Works in both Deno and browser environments.
192
- */
193
-
194
- /**
195
- * B3nd Wallet Client
10
+ * In-memory implementation of the wallet client for testing.
11
+ * Embeds WalletServerCore with MemoryClient storage - no HTTP required.
196
12
  *
197
- * Manages authentication with a wallet server and provides methods
198
- * for user management, key retrieval, and proxied writes.
13
+ * Same interface as WalletClient, so you can swap between them:
199
14
  *
200
15
  * @example
201
16
  * ```typescript
17
+ * // Production
18
+ * const backend = new HttpClient({ baseUrl: "http://localhost:8842" });
202
19
  * const wallet = new WalletClient({
203
- * walletServerUrl: "http://localhost:3001",
204
- * apiBasePath: "/api/v1",
20
+ * walletServerUrl: "http://localhost:8843",
21
+ * apiBasePath: "/api/v1"
205
22
  * });
206
23
  *
207
- * // Sign up a new user
208
- * const session = await wallet.signup({
209
- * username: "alice",
210
- * password: "secure-password-123"
211
- * });
24
+ * // Tests - share same backend between wallet and direct operations
25
+ * const backend = new MemoryClient({ schema: { "mutable://accounts": ... } });
26
+ * const wallet = await MemoryWalletClient.create({ backend });
212
27
  *
213
- * // Activate the session
214
- * wallet.setSession(session);
28
+ * // Same API works for both
29
+ * await wallet.signupWithToken(appKey, { username: "alice", password: "secret" });
30
+ * await wallet.proxyWrite({ uri: "mutable://data/test", data: { foo: "bar" } });
215
31
  *
216
- * // Write data through proxy
217
- * await wallet.proxyWrite({
218
- * uri: "mutable://data/my-app/profile",
219
- * data: { name: "Alice" },
220
- * encrypt: true
221
- * });
32
+ * // Direct backend access in tests
33
+ * const result = await backend.read("mutable://accounts/...");
222
34
  * ```
223
35
  */
224
- declare class WalletClient {
225
- private walletServerUrl;
226
- private apiBasePath;
227
- private fetchImpl;
228
- private currentSession;
229
- constructor(config: WalletClientConfig);
230
- private buildUrl;
231
- private buildAppKeyUrl;
36
+
37
+ interface MemoryWalletClientConfig {
232
38
  /**
233
- * Get the current authenticated session
39
+ * Optional server keys. If not provided, keys are auto-generated.
234
40
  */
235
- getSession(): AuthSession | null;
41
+ serverKeys?: ServerKeys;
236
42
  /**
237
- * Set the current session (useful for restoring from storage)
43
+ * Optional JWT secret. Defaults to a test secret.
238
44
  */
239
- setSession(session: AuthSession | null): void;
45
+ jwtSecret?: string;
240
46
  /**
241
- * Check if user is currently authenticated
47
+ * Optional JWT expiration in seconds. Defaults to 3600 (1 hour).
242
48
  */
243
- isAuthenticated(): boolean;
49
+ jwtExpirationSeconds?: number;
244
50
  /**
245
- * Get current username (if authenticated)
51
+ * Shared backend storage (e.g., MemoryClient).
52
+ * Use this to share the same storage between wallet and direct operations.
53
+ * If not provided, a new MemoryClient is created.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const backend = new MemoryClient({ schema: { ... } });
58
+ * const wallet = await MemoryWalletClient.create({ backend });
59
+ *
60
+ * // Both use the same storage
61
+ * await backend.write("mutable://accounts/...", data);
62
+ * await wallet.proxyWrite({ uri: "mutable://...", data });
63
+ * ```
246
64
  */
247
- getUsername(): string | null;
65
+ backend?: NodeProtocolInterface;
66
+ }
67
+ /**
68
+ * Generate server keys for testing
69
+ */
70
+ declare function generateTestServerKeys(): Promise<ServerKeys>;
71
+ /**
72
+ * Memory Wallet Client
73
+ *
74
+ * In-memory implementation that embeds WalletServerCore.
75
+ * Use for testing without running a real server.
76
+ */
77
+ declare class MemoryWalletClient {
78
+ private server;
79
+ private handler;
80
+ private currentSession;
81
+ private apiBasePath;
82
+ private constructor();
248
83
  /**
249
- * Get current JWT token (if authenticated)
84
+ * Create a new MemoryWalletClient
85
+ * Use this factory method instead of constructor (async key generation)
250
86
  */
251
- getToken(): string | null;
87
+ static create(config?: MemoryWalletClientConfig): Promise<MemoryWalletClient>;
252
88
  /**
253
- * Clear current session (logout)
89
+ * Make a request to the embedded server
254
90
  */
255
- logout(): void;
91
+ private request;
256
92
  /**
257
- * Check wallet server health
93
+ * Make an authenticated request
258
94
  */
95
+ private authRequest;
96
+ getSession(): AuthSession | null;
97
+ setSession(session: AuthSession | null): void;
98
+ isAuthenticated(): boolean;
99
+ getUsername(): string | null;
100
+ getToken(): string | null;
101
+ logout(): void;
259
102
  health(): Promise<HealthResponse>;
260
- /**
261
- * Sign up a new user
262
- * Returns session data - call setSession() to activate it
263
- */
103
+ getServerKeys(): Promise<{
104
+ identityPublicKeyHex: string;
105
+ encryptionPublicKeyHex: string;
106
+ }>;
264
107
  signup(_credentials: UserCredentials): Promise<AuthSession>;
265
- /**
266
- * Login existing user
267
- * Returns session data - call setSession() to activate it
268
- */
269
108
  login(_credentials: UserCredentials): Promise<AuthSession>;
270
- /**
271
- * Change password for current user
272
- * Requires active authentication session
273
- */
109
+ signupWithToken(appKey: string, tokenOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
110
+ loginWithTokenSession(appKey: string, tokenOrSession: string, sessionOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
274
111
  changePassword(appKey: string, oldPassword: string, newPassword: string): Promise<void>;
275
- /**
276
- * Request a password reset token
277
- * Does not require authentication
278
- */
279
112
  requestPasswordReset(_username: string): Promise<PasswordResetToken>;
280
- /**
281
- * Reset password using a reset token
282
- * Returns session data - call setSession() to activate it
283
- */
284
113
  resetPassword(_username: string, _resetToken: string, _newPassword: string): Promise<AuthSession>;
285
- /**
286
- * Sign up with app token (scoped to an app)
287
- */
288
- signupWithToken(appKey: string, tokenOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
289
- /**
290
- * Login with app token and session (scoped to an app)
291
- */
292
- loginWithTokenSession(appKey: string, tokenOrSession: string, sessionOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
293
- /**
294
- * Request password reset scoped to app token
295
- */
296
114
  requestPasswordResetWithToken(appKey: string, tokenOrUsername: string, maybeUsername?: string): Promise<PasswordResetToken>;
297
- /**
298
- * Reset password scoped to an app
299
- */
300
115
  resetPasswordWithToken(appKey: string, _tokenOrUsername: string, usernameOrReset: string, resetToken?: string, newPassword?: string): Promise<AuthSession>;
301
- /**
302
- * Get public keys for the current authenticated user.
303
- * Requires an active authentication session.
304
- */
305
116
  getPublicKeys(appKey: string): Promise<UserPublicKeys>;
306
- /**
307
- * Proxy a write request through the wallet server
308
- * The server signs the write with its identity key
309
- * Requires active authentication session
310
- */
117
+ getMyPublicKeys(appKey: string): Promise<UserPublicKeys>;
311
118
  proxyWrite(request: ProxyWriteRequest): Promise<ProxyWriteResponse>;
312
- /**
313
- * Proxy a read request through the wallet server
314
- * The server decrypts encrypted data using user's encryption key
315
- * Requires active authentication session
316
- */
317
119
  proxyRead(request: ProxyReadRequest): Promise<ProxyReadResponse>;
120
+ signupWithGoogle(appKey: string, token: string, googleIdToken: string): Promise<GoogleAuthSession>;
121
+ loginWithGoogle(appKey: string, token: string, session: string, googleIdToken: string): Promise<GoogleAuthSession>;
318
122
  /**
319
- * Convenience method: Get current user's public keys
320
- * Requires active authentication session
123
+ * Get the underlying WalletServerCore (for testing/inspection)
321
124
  */
322
- getMyPublicKeys(appKey: string): Promise<UserPublicKeys>;
125
+ getServer(): WalletServerCore;
323
126
  /**
324
- * Get server's public keys
325
- *
326
- * @returns Server's identity and encryption public keys
327
- * @throws Error if request fails
127
+ * Get server's public keys directly (convenience method)
328
128
  */
329
- getServerKeys(): Promise<{
129
+ getServerPublicKeys(): {
330
130
  identityPublicKeyHex: string;
331
131
  encryptionPublicKeyHex: string;
332
- }>;
333
- /**
334
- * Sign up with Google OAuth (scoped to app token)
335
- * Returns session data with Google profile info - call setSession() to activate it
336
- *
337
- * @param token - App token from app server
338
- * @param googleIdToken - Google ID token from Google Sign-In
339
- * @returns GoogleAuthSession with username, JWT token, and Google profile info
340
- */
341
- signupWithGoogle(appKey: string, token: string, googleIdToken: string): Promise<GoogleAuthSession>;
342
- /**
343
- * Login with Google OAuth (scoped to app token and session)
344
- * Returns session data with Google profile info - call setSession() to activate it
345
- *
346
- * @param token - App token from app server
347
- * @param session - Session key from app server
348
- * @param googleIdToken - Google ID token from Google Sign-In
349
- * @returns GoogleAuthSession with username, JWT token, and Google profile info
350
- */
351
- loginWithGoogle(appKey: string, token: string, session: string, googleIdToken: string): Promise<GoogleAuthSession>;
132
+ };
352
133
  }
353
134
 
354
- export { type ApiResponse, type AuthSession, type ChangePasswordResponse, type GoogleAuthSession, type GoogleLoginResponse, type GoogleSignupResponse, type HealthResponse, type LoginResponse, type PasswordResetToken, type ProxyReadRequest, type ProxyReadResponse, type ProxyWriteRequest, type ProxyWriteResponse, type PublicKeysResponse, type RequestPasswordResetResponse, type ResetPasswordResponse, type SignupResponse, type UserCredentials, type UserPublicKeys, WalletClient, type WalletClientConfig };
135
+ export { AuthSession, GoogleAuthSession, HealthResponse, MemoryWalletClient, type MemoryWalletClientConfig, PasswordResetToken, ProxyReadRequest, ProxyReadResponse, ProxyWriteRequest, ProxyWriteResponse, UserCredentials, UserPublicKeys, generateTestServerKeys };
@@ -1,7 +1,15 @@
1
1
  import {
2
- WalletClient
3
- } from "../chunk-S7NJA6B6.js";
2
+ MemoryWalletClient,
3
+ WalletClient,
4
+ generateTestServerKeys
5
+ } from "../chunk-7O4D7SF6.js";
6
+ import "../chunk-GIMIWVPX.js";
7
+ import "../chunk-F3W5GZU6.js";
8
+ import "../chunk-JN75UL5C.js";
9
+ import "../chunk-LFUC4ETD.js";
4
10
  import "../chunk-MLKGABMK.js";
5
11
  export {
6
- WalletClient
12
+ MemoryWalletClient,
13
+ WalletClient,
14
+ generateTestServerKeys
7
15
  };
@@ -1,3 +1,6 @@
1
+ import {
2
+ LocalStorageClient
3
+ } from "../../chunk-7U5JDFQW.js";
1
4
  import {
2
5
  ConfigEnvironment,
3
6
  MemoryFileStorage,
@@ -5,9 +8,6 @@ import {
5
8
  } from "../../chunk-F3W5GZU6.js";
6
9
  import "../../chunk-JN75UL5C.js";
7
10
  import "../../chunk-LFUC4ETD.js";
8
- import {
9
- LocalStorageClient
10
- } from "../../chunk-7U5JDFQW.js";
11
11
  import "../../chunk-MLKGABMK.js";
12
12
 
13
13
  // wallet-server/adapters/browser.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bandeira-tech/b3nd-web",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Browser-focused B3nd SDK bundle",
5
5
  "type": "module",
6
6
  "main": "./dist/src/mod.web.js",