@bandeira-tech/b3nd-web 0.2.5 → 0.2.6

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,354 @@
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
+ }
184
+
185
+ /**
186
+ * B3nd Wallet Client
187
+ *
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
196
+ *
197
+ * Manages authentication with a wallet server and provides methods
198
+ * for user management, key retrieval, and proxied writes.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const wallet = new WalletClient({
203
+ * walletServerUrl: "http://localhost:3001",
204
+ * apiBasePath: "/api/v1",
205
+ * });
206
+ *
207
+ * // Sign up a new user
208
+ * const session = await wallet.signup({
209
+ * username: "alice",
210
+ * password: "secure-password-123"
211
+ * });
212
+ *
213
+ * // Activate the session
214
+ * wallet.setSession(session);
215
+ *
216
+ * // Write data through proxy
217
+ * await wallet.proxyWrite({
218
+ * uri: "mutable://data/my-app/profile",
219
+ * data: { name: "Alice" },
220
+ * encrypt: true
221
+ * });
222
+ * ```
223
+ */
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;
232
+ /**
233
+ * Get the current authenticated session
234
+ */
235
+ getSession(): AuthSession | null;
236
+ /**
237
+ * Set the current session (useful for restoring from storage)
238
+ */
239
+ setSession(session: AuthSession | null): void;
240
+ /**
241
+ * Check if user is currently authenticated
242
+ */
243
+ isAuthenticated(): boolean;
244
+ /**
245
+ * Get current username (if authenticated)
246
+ */
247
+ getUsername(): string | null;
248
+ /**
249
+ * Get current JWT token (if authenticated)
250
+ */
251
+ getToken(): string | null;
252
+ /**
253
+ * Clear current session (logout)
254
+ */
255
+ logout(): void;
256
+ /**
257
+ * Check wallet server health
258
+ */
259
+ health(): Promise<HealthResponse>;
260
+ /**
261
+ * Sign up a new user
262
+ * Returns session data - call setSession() to activate it
263
+ */
264
+ signup(_credentials: UserCredentials): Promise<AuthSession>;
265
+ /**
266
+ * Login existing user
267
+ * Returns session data - call setSession() to activate it
268
+ */
269
+ login(_credentials: UserCredentials): Promise<AuthSession>;
270
+ /**
271
+ * Change password for current user
272
+ * Requires active authentication session
273
+ */
274
+ changePassword(appKey: string, oldPassword: string, newPassword: string): Promise<void>;
275
+ /**
276
+ * Request a password reset token
277
+ * Does not require authentication
278
+ */
279
+ requestPasswordReset(_username: string): Promise<PasswordResetToken>;
280
+ /**
281
+ * Reset password using a reset token
282
+ * Returns session data - call setSession() to activate it
283
+ */
284
+ 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
+ requestPasswordResetWithToken(appKey: string, tokenOrUsername: string, maybeUsername?: string): Promise<PasswordResetToken>;
297
+ /**
298
+ * Reset password scoped to an app
299
+ */
300
+ 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
+ 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
+ */
311
+ 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
+ proxyRead(request: ProxyReadRequest): Promise<ProxyReadResponse>;
318
+ /**
319
+ * Convenience method: Get current user's public keys
320
+ * Requires active authentication session
321
+ */
322
+ getMyPublicKeys(appKey: string): Promise<UserPublicKeys>;
323
+ /**
324
+ * Get server's public keys
325
+ *
326
+ * @returns Server's identity and encryption public keys
327
+ * @throws Error if request fails
328
+ */
329
+ getServerKeys(): Promise<{
330
+ identityPublicKeyHex: string;
331
+ 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>;
352
+ }
353
+
354
+ export { type AuthSession as A, type ChangePasswordResponse as C, type GoogleAuthSession as G, type HealthResponse as H, type LoginResponse as L, type PasswordResetToken as P, type RequestPasswordResetResponse as R, type SignupResponse as S, type UserCredentials as U, WalletClient as W, type UserPublicKeys as a, type ProxyWriteRequest as b, type ProxyWriteResponse as c, type ProxyReadRequest as d, type ProxyReadResponse as e, type WalletClientConfig as f, type ApiResponse as g, type PublicKeysResponse as h, type ResetPasswordResponse as i, type GoogleSignupResponse as j, type GoogleLoginResponse as k };
@@ -1,4 +1,4 @@
1
- import { S as Schema, N as NodeProtocolInterface, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, H as HealthStatus, D as DeleteResult } from '../../types-oQCx3U-_.js';
1
+ import { N as NodeProtocolInterface, S as Schema, g as WriteResult, R as ReadResult, b as ListOptions, c as ListResult, H as HealthStatus, D as DeleteResult } from '../../types-oQCx3U-_.js';
2
2
 
3
3
  type MemoryClientStorageNode<T> = {
4
4
  value?: T;
@@ -1,203 +1,7 @@
1
+ import {
2
+ MemoryClient
3
+ } from "../../chunk-GIMIWVPX.js";
1
4
  import "../../chunk-MLKGABMK.js";
2
-
3
- // clients/memory/mod.ts
4
- function target(uri, schema, storage) {
5
- const url = URL.parse(uri);
6
- const program = `${url.protocol}//${url.hostname}`;
7
- if (!schema[program]) {
8
- return { success: false, error: "Program not found" };
9
- }
10
- const node = storage.get(program);
11
- if (!node) {
12
- return { success: false, error: "Storage not initialized for program" };
13
- }
14
- const parts = url.pathname.substring(1).split("/");
15
- return {
16
- success: true,
17
- program,
18
- path: url.pathname,
19
- node,
20
- parts
21
- };
22
- }
23
- var MemoryClient = class {
24
- constructor(config) {
25
- this.schema = config.schema;
26
- this.storage = config.storage || /* @__PURE__ */ new Map();
27
- this.cleanup();
28
- }
29
- async write(uri, payload) {
30
- const result = target(uri, this.schema, this.storage);
31
- if (!result.success) {
32
- return result;
33
- }
34
- const { program, node, parts } = result;
35
- const validator = this.schema[program];
36
- const validation = await validator({ uri, value: payload, read: this.read.bind(this) });
37
- if (!validation.valid) {
38
- return {
39
- success: false,
40
- error: validation.error || "Validation failed"
41
- };
42
- }
43
- const record = {
44
- ts: Date.now(),
45
- data: payload
46
- };
47
- let prev = node;
48
- parts.filter(Boolean).forEach((ns) => {
49
- if (!prev.children) prev.children = /* @__PURE__ */ new Map();
50
- if (!prev.children.get(ns)) {
51
- const newnode = {};
52
- prev.children.set(ns, newnode);
53
- prev = newnode;
54
- } else {
55
- prev = prev.children.get(ns);
56
- }
57
- });
58
- prev.value = record;
59
- return {
60
- success: true,
61
- record
62
- };
63
- }
64
- read(uri) {
65
- const result = target(uri, this.schema, this.storage);
66
- if (!result.success) {
67
- return Promise.resolve(result);
68
- }
69
- const { node, parts } = result;
70
- let current = node;
71
- for (const part of parts.filter(Boolean)) {
72
- current = current?.children?.get(part);
73
- if (!current) {
74
- return Promise.resolve({
75
- success: false,
76
- error: `Path not found: ${part}`
77
- });
78
- }
79
- }
80
- if (!current.value) {
81
- return Promise.resolve({
82
- success: false,
83
- error: "Not found"
84
- });
85
- }
86
- return Promise.resolve({
87
- success: true,
88
- record: current.value
89
- });
90
- }
91
- list(uri, options) {
92
- const result = target(uri, this.schema, this.storage);
93
- if (!result.success) {
94
- return Promise.resolve(result);
95
- }
96
- const { node, parts, program, path } = result;
97
- let current = node;
98
- const filteredParts = parts.filter(Boolean);
99
- for (const part of filteredParts) {
100
- current = current?.children?.get(part);
101
- if (!current) {
102
- return Promise.resolve({
103
- success: false,
104
- error: `Path not found: ${part}`
105
- });
106
- }
107
- }
108
- if (!current.children?.size) {
109
- return Promise.resolve({
110
- success: true,
111
- data: [],
112
- pagination: {
113
- page: options?.page ?? 1,
114
- limit: options?.limit ?? 50,
115
- total: 0
116
- }
117
- });
118
- }
119
- let items = Array.from(current.children.entries()).map(([key, child]) => ({
120
- uri: path.endsWith("/") ? `${program}://${path}${key}` : `${program}://${path}/${key}`,
121
- type: child.value ? "file" : "directory"
122
- }));
123
- if (options?.pattern) {
124
- const regex = new RegExp(options.pattern);
125
- items = items.filter((item) => regex.test(item.uri));
126
- }
127
- if (options?.sortBy === "name") {
128
- items.sort((a, b) => a.uri.localeCompare(b.uri));
129
- } else if (options?.sortBy === "timestamp") {
130
- items.sort((a, b) => {
131
- const aTs = current.children?.get(a.uri.split("/").pop())?.value?.ts ?? 0;
132
- const bTs = current.children?.get(b.uri.split("/").pop())?.value?.ts ?? 0;
133
- return aTs - bTs;
134
- });
135
- }
136
- if (options?.sortOrder === "desc") {
137
- items.reverse();
138
- }
139
- const page = options?.page ?? 1;
140
- const limit = options?.limit ?? 50;
141
- const offset = (page - 1) * limit;
142
- const paginated = items.slice(offset, offset + limit);
143
- return Promise.resolve({
144
- success: true,
145
- data: paginated,
146
- pagination: { page, limit, total: items.length }
147
- });
148
- }
149
- health() {
150
- return Promise.resolve({
151
- status: "healthy"
152
- });
153
- }
154
- getSchema() {
155
- return Promise.resolve(Object.keys(this.schema));
156
- }
157
- cleanup() {
158
- Object.keys(this.schema).forEach((program) => {
159
- if (!this.storage.get(program)) {
160
- this.storage.set(program, { children: /* @__PURE__ */ new Map() });
161
- }
162
- });
163
- return Promise.resolve();
164
- }
165
- delete(uri) {
166
- const result = target(uri, this.schema, this.storage);
167
- if (!result.success) {
168
- return Promise.resolve(result);
169
- }
170
- const { node, parts } = result;
171
- const filteredParts = parts.filter(Boolean);
172
- if (filteredParts.length === 0) {
173
- return Promise.resolve({
174
- success: false,
175
- error: "Cannot delete root path"
176
- });
177
- }
178
- let current = node;
179
- const lastPart = filteredParts.pop();
180
- for (const part of filteredParts) {
181
- current = current?.children?.get(part);
182
- if (!current) {
183
- return Promise.resolve({
184
- success: false,
185
- error: `Path not found: ${part}`
186
- });
187
- }
188
- }
189
- if (!current.children?.has(lastPart)) {
190
- return Promise.resolve({
191
- success: false,
192
- error: `Item not found: ${lastPart}`
193
- });
194
- }
195
- current.children.delete(lastPart);
196
- return Promise.resolve({
197
- success: true
198
- });
199
- }
200
- };
201
5
  export {
202
6
  MemoryClient
203
7
  };
@@ -2,6 +2,6 @@ export { C as ClientError, D as DeleteResult, H as HealthStatus, a as HttpClient
2
2
  export { HttpClient } from '../clients/http/mod.js';
3
3
  export { WebSocketClient } from '../clients/websocket/mod.js';
4
4
  export { LocalStorageClient } from '../clients/local-storage/mod.js';
5
- export { WalletClient } from '../wallet/mod.js';
5
+ export { W as WalletClient } from '../client-B0Ekm99R.js';
6
6
  export { AppsClient } from '../apps/mod.js';
7
7
  export { m as encrypt } from '../mod-CII9wqu2.js';
@@ -4,18 +4,20 @@ import {
4
4
  import {
5
5
  AppsClient
6
6
  } from "../chunk-VAZUCGED.js";
7
+ import {
8
+ WalletClient
9
+ } from "../chunk-FVLXYKYS.js";
10
+ import "../chunk-F3W5GZU6.js";
7
11
  import {
8
12
  mod_exports
9
13
  } from "../chunk-JN75UL5C.js";
10
- import {
11
- WalletClient
12
- } from "../chunk-S7NJA6B6.js";
13
14
  import {
14
15
  HttpClient
15
16
  } from "../chunk-LFUC4ETD.js";
16
17
  import {
17
18
  LocalStorageClient
18
19
  } from "../chunk-7U5JDFQW.js";
20
+ import "../chunk-GIMIWVPX.js";
19
21
  import "../chunk-MLKGABMK.js";
20
22
  export {
21
23
  AppsClient,