@bandeira-tech/b3nd-web 0.2.3 → 0.2.4

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,320 @@
1
+ import { P as ProxyWriteRequest, a as ProxyWriteResponse, b as ProxyReadResponse, U as UserKeys, L as Logger, H as HttpFetch } from '../core-CgxQpSVM.js';
2
+ export { A as AppBackendConfig, f as AuthSessionResponse, C as ConfigEnvironment, E as Environment, F as FileStorage, h as HealthResponse, M as MemoryFileStorage, g as PublicKeysResponse, R as ResolvedWalletServerConfig, e as ServerKeyPair, S as ServerKeys, i as ServerKeysResponse, c as WalletServerConfig, W as WalletServerCore, d as WalletServerDeps, j as defaultLogger } from '../core-CgxQpSVM.js';
3
+ import { N as NodeProtocolInterface } from '../types-oQCx3U-_.js';
4
+ import { S as SignedEncryptedMessage, E as EncryptedPayload } from '../mod-CII9wqu2.js';
5
+ import 'hono';
6
+
7
+ /**
8
+ * JWT Token Management
9
+ *
10
+ * Creates and validates JWT tokens for authenticated sessions.
11
+ */
12
+ interface JwtPayload {
13
+ username: string;
14
+ iat: number;
15
+ exp: number;
16
+ type: "access";
17
+ }
18
+ /**
19
+ * Create JWT token using HMAC-SHA256
20
+ */
21
+ declare function createJwt(username: string, secret: string, expirationSeconds: number): Promise<string>;
22
+ /**
23
+ * Verify and decode JWT token
24
+ */
25
+ declare function verifyJwt(token: string, secret: string): Promise<JwtPayload>;
26
+ /**
27
+ * Extract username from JWT token (without verification)
28
+ * Use only for logging/debugging
29
+ */
30
+ declare function extractUsernameFromJwt(token: string): string | null;
31
+
32
+ /**
33
+ * Write Proxy
34
+ *
35
+ * Handles proxying user write requests to the target b3nd backend.
36
+ * Automatically signs writes with the user's identity key and encrypts with user's encryption key.
37
+ */
38
+
39
+ /**
40
+ * Proxy a write request with user signing
41
+ * The server acts as the key custodian for the write operation.
42
+ */
43
+ declare function proxyWrite(proxyClient: NodeProtocolInterface, credentialClient: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, request: ProxyWriteRequest): Promise<ProxyWriteResponse>;
44
+ /**
45
+ * Proxy a read request (with optional decryption)
46
+ */
47
+ declare function proxyRead(proxyClient: NodeProtocolInterface, uri: string, serverEncryptionPrivateKeyPem?: string): Promise<ProxyReadResponse>;
48
+
49
+ /**
50
+ * User Key Management
51
+ *
52
+ * Generates and manages user Ed25519 (account/signing) and X25519 (encryption) keys.
53
+ */
54
+
55
+ /**
56
+ * Generate and store user keys
57
+ * Stores signed+encrypted at obfuscated paths under: mutable://accounts/{serverPublicKey}/...
58
+ */
59
+ declare function generateUserKeys(client: NodeProtocolInterface, serverPublicKey: string, username: string, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string): Promise<UserKeys>;
60
+ /**
61
+ * Load user's account key (Ed25519)
62
+ */
63
+ declare function loadUserAccountKey(client: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, logger?: Logger): Promise<{
64
+ privateKeyPem: string;
65
+ publicKeyHex: string;
66
+ }>;
67
+ /**
68
+ * Load user's encryption key (X25519)
69
+ */
70
+ declare function loadUserEncryptionKey(client: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, logger?: Logger): Promise<{
71
+ privateKeyPem: string;
72
+ publicKeyHex: string;
73
+ }>;
74
+ /**
75
+ * Load both user keys
76
+ */
77
+ declare function loadUserKeys(client: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, logger?: Logger): Promise<UserKeys>;
78
+ /**
79
+ * Get user's public keys (safe to share)
80
+ */
81
+ declare function getUserPublicKeys(client: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, logger?: Logger): Promise<{
82
+ accountPublicKeyHex: string;
83
+ encryptionPublicKeyHex: string;
84
+ }>;
85
+
86
+ /**
87
+ * Google OAuth Module
88
+ *
89
+ * Handles verification of Google ID tokens using Google's public keys.
90
+ * Supports both signup and login flows with Google OAuth2.
91
+ */
92
+
93
+ interface GoogleTokenPayload {
94
+ iss: string;
95
+ azp: string;
96
+ aud: string;
97
+ sub: string;
98
+ email: string;
99
+ email_verified: boolean;
100
+ name?: string;
101
+ picture?: string;
102
+ given_name?: string;
103
+ family_name?: string;
104
+ iat: number;
105
+ exp: number;
106
+ }
107
+ /**
108
+ * Clear the cached Google public keys
109
+ */
110
+ declare function clearGooglePublicKeyCache(): void;
111
+ /**
112
+ * Verify a Google ID token and extract the payload
113
+ */
114
+ declare function verifyGoogleIdToken(idToken: string, clientId: string, fetchImpl?: HttpFetch): Promise<GoogleTokenPayload>;
115
+ /**
116
+ * Generate a deterministic username from Google user info
117
+ * Uses the Google sub (unique user ID) to create a consistent username
118
+ */
119
+ declare function generateGoogleUsername(googleSub: string): Promise<string>;
120
+
121
+ /**
122
+ * Authentication Module
123
+ *
124
+ * Handles password hashing, user signup, login, password change, and reset flows.
125
+ * All data is encrypted before writing to backend using obfuscated paths.
126
+ */
127
+
128
+ /**
129
+ * Check if user exists
130
+ */
131
+ declare function userExists(client: NodeProtocolInterface, serverPublicKey: string, username: string, appScope?: string): Promise<boolean>;
132
+ /**
133
+ * Create a new user with password
134
+ * Stores signed+encrypted at obfuscated paths under: mutable://accounts/{serverPublicKey}/...
135
+ */
136
+ declare function createUser(client: NodeProtocolInterface, serverPublicKey: string, username: string, password: string, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string, appScope?: string): Promise<{
137
+ salt: string;
138
+ hash: string;
139
+ }>;
140
+ /**
141
+ * Authenticate user with password
142
+ */
143
+ declare function authenticateUser(client: NodeProtocolInterface, serverPublicKey: string, username: string, password: string, serverIdentityPublicKeyHex: string, serverEncryptionPrivateKeyPem: string, appScope?: string, logger?: Logger): Promise<boolean>;
144
+ /**
145
+ * Change user password
146
+ */
147
+ declare function changePassword(client: NodeProtocolInterface, serverPublicKey: string, username: string, oldPassword: string, newPassword: string, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string, serverEncryptionPrivateKeyPem: string, appScope?: string): Promise<void>;
148
+ /**
149
+ * Create password reset token
150
+ */
151
+ declare function createPasswordResetToken(client: NodeProtocolInterface, serverPublicKey: string, username: string, ttlSeconds: number, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string, appScope?: string): Promise<string>;
152
+ /**
153
+ * Reset password with token
154
+ */
155
+ declare function resetPasswordWithToken(client: NodeProtocolInterface, serverPublicKey: string, token: string, newPassword: string, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string, serverEncryptionPrivateKeyPem: string, username: string, appScope?: string, logger?: Logger): Promise<string>;
156
+ /**
157
+ * Check if a Google user exists by their Google sub ID
158
+ */
159
+ declare function googleUserExists(client: NodeProtocolInterface, serverPublicKey: string, googleSub: string, appScope?: string): Promise<boolean>;
160
+ /**
161
+ * Create a new user from Google OAuth
162
+ * Stores Google profile info instead of password credentials
163
+ */
164
+ declare function createGoogleUser(client: NodeProtocolInterface, serverPublicKey: string, username: string, googlePayload: GoogleTokenPayload, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string, appScope?: string): Promise<{
165
+ username: string;
166
+ googleSub: string;
167
+ }>;
168
+ /**
169
+ * Authenticate user via Google OAuth
170
+ * Returns the username if Google sub ID is found
171
+ */
172
+ declare function authenticateGoogleUser(client: NodeProtocolInterface, serverPublicKey: string, googleSub: string, serverEncryptionPrivateKeyPem: string, appScope?: string, logger?: Logger): Promise<string | null>;
173
+
174
+ /**
175
+ * Credential System
176
+ *
177
+ * Unified abstraction for different authentication methods (password, OAuth providers, etc.)
178
+ * Each credential type has a handler that implements signup and login logic.
179
+ */
180
+
181
+ /**
182
+ * Standard credential signup/login result
183
+ */
184
+ interface CredentialResult {
185
+ username: string;
186
+ metadata?: Record<string, unknown>;
187
+ }
188
+ /**
189
+ * Base credential payload
190
+ */
191
+ interface BaseCredentialPayload {
192
+ type: string;
193
+ session?: string;
194
+ }
195
+ /**
196
+ * Password credential payload
197
+ */
198
+ interface PasswordCredentialPayload extends BaseCredentialPayload {
199
+ type: "password";
200
+ username: string;
201
+ password: string;
202
+ }
203
+ /**
204
+ * Google OAuth credential payload
205
+ */
206
+ interface GoogleCredentialPayload extends BaseCredentialPayload {
207
+ type: "google";
208
+ googleIdToken: string;
209
+ }
210
+ /**
211
+ * Union of all credential payload types
212
+ */
213
+ type CredentialPayload = PasswordCredentialPayload | GoogleCredentialPayload;
214
+ /**
215
+ * Credential handler interface
216
+ */
217
+ interface CredentialHandler<T extends BaseCredentialPayload = BaseCredentialPayload> {
218
+ /**
219
+ * Handle signup with this credential type
220
+ */
221
+ signup(payload: T, context: CredentialContext): Promise<CredentialResult>;
222
+ /**
223
+ * Handle login with this credential type
224
+ */
225
+ login(payload: T, context: CredentialContext): Promise<CredentialResult>;
226
+ }
227
+ /**
228
+ * Context passed to credential handlers
229
+ */
230
+ interface CredentialContext {
231
+ client: NodeProtocolInterface;
232
+ serverPublicKey: string;
233
+ serverIdentityPrivateKeyPem: string;
234
+ serverIdentityPublicKeyHex: string;
235
+ serverEncryptionPublicKeyHex: string;
236
+ serverEncryptionPrivateKeyPem: string;
237
+ appKey: string;
238
+ googleClientId?: string | null;
239
+ logger?: Logger;
240
+ fetch?: HttpFetch;
241
+ }
242
+ /**
243
+ * Get a credential handler by type
244
+ */
245
+ declare function getCredentialHandler(type: string): CredentialHandler;
246
+ /**
247
+ * Register a new credential handler
248
+ */
249
+ declare function registerCredentialHandler(type: string, handler: CredentialHandler): void;
250
+ /**
251
+ * Get list of supported credential types
252
+ */
253
+ declare function getSupportedCredentialTypes(): string[];
254
+
255
+ /**
256
+ * Path Obfuscation & Encryption Utilities
257
+ *
258
+ * Provides deterministic path derivation and transparent encryption/decryption
259
+ * for all data stored in the public b3nd backend.
260
+ *
261
+ * All data written to the backend is:
262
+ * 1. Encrypted with server's X25519 key
263
+ * 2. Written to a deterministically obfuscated path
264
+ *
265
+ * The obfuscated path is derived from username/operationType/params,
266
+ * ensuring same inputs always produce same path (deterministic),
267
+ * but the path itself reveals nothing about the data.
268
+ */
269
+
270
+ /**
271
+ * Operation types for path obfuscation
272
+ */
273
+ type OperationType = "password" | "account-key" | "encryption-key" | "profile" | "reset-tokens" | "google-profile";
274
+ /**
275
+ * Derive obfuscated path deterministically using HMAC-SHA256
276
+ *
277
+ * Inputs:
278
+ * - serverPublicKey: Server's Ed25519 public key (for context)
279
+ * - username: Username to obfuscate
280
+ * - operationType: Type of operation (password, keys, tokens, etc.)
281
+ * - params: Additional parameters (e.g., token id)
282
+ *
283
+ * Output: Hex string that looks like random data
284
+ *
285
+ * Properties:
286
+ * - Deterministic: Same inputs → same output
287
+ * - Non-reversible: Can't guess username from hash
288
+ * - Uniform: All paths look similar length/format
289
+ * - Repeatable: Can reconstruct on write and read
290
+ */
291
+ declare function deriveObfuscatedPath(serverPublicKey: string, username: string, operationType: OperationType, ...params: string[]): Promise<string>;
292
+ /**
293
+ * Convert PEM string to CryptoKey
294
+ */
295
+ declare function pemToCryptoKey(pem: string, algorithm?: "Ed25519" | "X25519"): Promise<CryptoKey>;
296
+ /**
297
+ * Create a signed+encrypted payload for storage
298
+ * Signs with server identity key, encrypts with server encryption key
299
+ */
300
+ declare function createSignedEncryptedPayload(data: unknown, serverIdentityPrivateKeyPem: string, serverIdentityPublicKeyHex: string, serverEncryptionPublicKeyHex: string): Promise<SignedEncryptedMessage>;
301
+ /**
302
+ * Decrypt and verify a signed+encrypted payload from storage
303
+ */
304
+ declare function decryptSignedEncryptedPayload(signedMessage: SignedEncryptedMessage, serverEncryptionPrivateKeyPem: string): Promise<{
305
+ data: unknown;
306
+ verified: boolean;
307
+ signers: string[];
308
+ }>;
309
+ /**
310
+ * Encrypt data using server's X25519 public key
311
+ * Returns the encrypted payload structure
312
+ */
313
+ declare function encryptForBackend(data: unknown, serverEncryptionPublicKeyHex: string): Promise<EncryptedPayload>;
314
+ /**
315
+ * Decrypt data using server's X25519 private key
316
+ * Expects the encrypted payload structure
317
+ */
318
+ declare function decryptFromBackend(encryptedPayload: EncryptedPayload, serverEncryptionPrivateKeyPem: string): Promise<unknown>;
319
+
320
+ export { type BaseCredentialPayload, type CredentialContext, type CredentialHandler, type CredentialPayload, type CredentialResult, type GoogleCredentialPayload, type GoogleTokenPayload, HttpFetch, type JwtPayload, Logger, type OperationType, type PasswordCredentialPayload, ProxyReadResponse, ProxyWriteRequest, ProxyWriteResponse, UserKeys, authenticateGoogleUser, authenticateUser, changePassword, clearGooglePublicKeyCache, createGoogleUser, createJwt, createPasswordResetToken, createSignedEncryptedPayload, createUser, decryptFromBackend, decryptSignedEncryptedPayload, deriveObfuscatedPath, encryptForBackend, extractUsernameFromJwt, generateGoogleUsername, generateUserKeys, getCredentialHandler, getSupportedCredentialTypes, getUserPublicKeys, googleUserExists, loadUserAccountKey, loadUserEncryptionKey, loadUserKeys, pemToCryptoKey, proxyRead, proxyWrite, registerCredentialHandler, resetPasswordWithToken, userExists, verifyGoogleIdToken, verifyJwt };
@@ -0,0 +1,77 @@
1
+ import {
2
+ ConfigEnvironment,
3
+ MemoryFileStorage,
4
+ WalletServerCore,
5
+ authenticateGoogleUser,
6
+ authenticateUser,
7
+ changePassword,
8
+ clearGooglePublicKeyCache,
9
+ createGoogleUser,
10
+ createJwt,
11
+ createPasswordResetToken,
12
+ createSignedEncryptedPayload,
13
+ createUser,
14
+ decryptFromBackend,
15
+ decryptSignedEncryptedPayload,
16
+ defaultLogger,
17
+ deriveObfuscatedPath,
18
+ encryptForBackend,
19
+ extractUsernameFromJwt,
20
+ generateGoogleUsername,
21
+ generateUserKeys,
22
+ getCredentialHandler,
23
+ getSupportedCredentialTypes,
24
+ getUserPublicKeys,
25
+ googleUserExists,
26
+ loadUserAccountKey,
27
+ loadUserEncryptionKey,
28
+ loadUserKeys,
29
+ pemToCryptoKey,
30
+ proxyRead,
31
+ proxyWrite,
32
+ registerCredentialHandler,
33
+ resetPasswordWithToken,
34
+ userExists,
35
+ verifyGoogleIdToken,
36
+ verifyJwt
37
+ } from "../chunk-F3W5GZU6.js";
38
+ import "../chunk-JN75UL5C.js";
39
+ import "../chunk-LFUC4ETD.js";
40
+ import "../chunk-MLKGABMK.js";
41
+ export {
42
+ ConfigEnvironment,
43
+ MemoryFileStorage,
44
+ WalletServerCore,
45
+ authenticateGoogleUser,
46
+ authenticateUser,
47
+ changePassword,
48
+ clearGooglePublicKeyCache,
49
+ createGoogleUser,
50
+ createJwt,
51
+ createPasswordResetToken,
52
+ createSignedEncryptedPayload,
53
+ createUser,
54
+ decryptFromBackend,
55
+ decryptSignedEncryptedPayload,
56
+ defaultLogger,
57
+ deriveObfuscatedPath,
58
+ encryptForBackend,
59
+ extractUsernameFromJwt,
60
+ generateGoogleUsername,
61
+ generateUserKeys,
62
+ getCredentialHandler,
63
+ getSupportedCredentialTypes,
64
+ getUserPublicKeys,
65
+ googleUserExists,
66
+ loadUserAccountKey,
67
+ loadUserEncryptionKey,
68
+ loadUserKeys,
69
+ pemToCryptoKey,
70
+ proxyRead,
71
+ proxyWrite,
72
+ registerCredentialHandler,
73
+ resetPasswordWithToken,
74
+ userExists,
75
+ verifyGoogleIdToken,
76
+ verifyJwt
77
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bandeira-tech/b3nd-web",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Browser-focused B3nd SDK bundle",
5
5
  "type": "module",
6
6
  "main": "./dist/src/mod.web.js",
@@ -34,13 +34,21 @@
34
34
  "./apps": {
35
35
  "import": "./dist/apps/mod.js",
36
36
  "types": "./dist/apps/mod.d.ts"
37
+ },
38
+ "./wallet-server": {
39
+ "import": "./dist/wallet-server/mod.js",
40
+ "types": "./dist/wallet-server/mod.d.ts"
41
+ },
42
+ "./wallet-server/adapters/browser": {
43
+ "import": "./dist/wallet-server/adapters/browser.js",
44
+ "types": "./dist/wallet-server/adapters/browser.d.ts"
37
45
  }
38
46
  },
39
47
  "files": [
40
48
  "dist"
41
49
  ],
42
50
  "scripts": {
43
- "build": "tsup src/mod.web.ts wallet/mod.ts apps/mod.ts encrypt/mod.ts clients/http/mod.ts clients/local-storage/mod.ts clients/websocket/mod.ts --dts --format esm --out-dir dist --clean --tsconfig tsconfig.web.json",
51
+ "build": "tsup src/mod.web.ts wallet/mod.ts apps/mod.ts encrypt/mod.ts clients/http/mod.ts clients/local-storage/mod.ts clients/websocket/mod.ts wallet-server/mod.ts wallet-server/adapters/browser.ts --dts --format esm --out-dir dist --clean --tsconfig tsconfig.web.json",
44
52
  "clean": "rm -rf dist",
45
53
  "lint": "deno lint src/",
46
54
  "format": "deno fmt src/"
@@ -69,7 +77,9 @@
69
77
  "url": "https://github.com/bandeira-tech/b3nd-sdk/issues"
70
78
  },
71
79
  "homepage": "https://github.com/bandeira-tech/b3nd-sdk#readme",
72
- "dependencies": {},
80
+ "dependencies": {
81
+ "hono": "^4.6.0"
82
+ },
73
83
  "devDependencies": {
74
84
  "tsup": "^8.3.5",
75
85
  "typescript": "^5.6.3",