@bandeira-tech/b3nd-web 0.2.7 → 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/dist/{chunk-F3W5GZU6.js → chunk-B4VAPGAO.js} +218 -22
- package/dist/{chunk-7O4D7SF6.js → chunk-GWPCZVXV.js} +233 -59
- package/dist/{chunk-GIMIWVPX.js → chunk-O53KW746.js} +53 -2
- package/dist/{chunk-LFUC4ETD.js → chunk-OY4CDOHY.js} +45 -0
- package/dist/{chunk-7U5JDFQW.js → chunk-PZFEKQ7F.js} +24 -0
- package/dist/{chunk-T43IWAQK.js → chunk-UUHVOWVI.js} +29 -0
- package/dist/{client-B0Ekm99R.d.ts → client-C4oQxiDu.d.ts} +147 -8
- package/dist/clients/http/mod.d.ts +3 -1
- package/dist/clients/http/mod.js +1 -1
- package/dist/clients/local-storage/mod.d.ts +2 -1
- package/dist/clients/local-storage/mod.js +1 -1
- package/dist/clients/memory/mod.d.ts +36 -2
- package/dist/clients/memory/mod.js +5 -3
- package/dist/clients/websocket/mod.d.ts +2 -1
- package/dist/clients/websocket/mod.js +1 -1
- package/dist/{core-CgxQpSVM.d.ts → core-ClnuubZw.d.ts} +17 -1
- package/dist/src/mod.web.d.ts +2 -2
- package/dist/src/mod.web.js +10 -10
- package/dist/{types-oQCx3U-_.d.ts → types-uuvn4oKw.d.ts} +36 -2
- package/dist/wallet/mod.d.ts +183 -8
- package/dist/wallet/mod.js +8 -4
- package/dist/wallet-server/adapters/browser.d.ts +3 -3
- package/dist/wallet-server/adapters/browser.js +5 -5
- package/dist/wallet-server/mod.d.ts +12 -6
- package/dist/wallet-server/mod.js +2 -2
- package/package.json +1 -1
package/dist/wallet/mod.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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-
|
|
2
|
-
export {
|
|
3
|
-
import { N as NodeProtocolInterface } from '../types-
|
|
4
|
-
import { S as ServerKeys, W as WalletServerCore } from '../core-
|
|
1
|
+
import { A as AuthSession, H as HealthResponse, U as UserCredentials, S as SessionKeypair, P as PasswordResetToken, a as UserPublicKeys, b as ProxyWriteRequest, c as ProxyWriteResponse, d as ProxyReadRequest, e as ProxyReadResponse, f as ProxyReadMultiRequest, g as ProxyReadMultiResponse, G as GoogleAuthSession } from '../client-C4oQxiDu.js';
|
|
2
|
+
export { l as ApiResponse, C as ChangePasswordResponse, q as GoogleLoginResponse, p as GoogleSignupResponse, L as LoginResponse, k as ProxyReadMultiResultItem, n as PublicKeysResponse, R as RequestPasswordResetResponse, o as ResetPasswordResponse, m as SignupResponse, W as WalletClient, j as WalletClientConfig, i as WalletClientInterface, h as generateSessionKeypair } from '../client-C4oQxiDu.js';
|
|
3
|
+
import { N as NodeProtocolInterface, S as Schema } from '../types-uuvn4oKw.js';
|
|
4
|
+
import { S as ServerKeys, W as WalletServerCore } from '../core-ClnuubZw.js';
|
|
5
|
+
import { MemoryClient } from '../clients/memory/mod.js';
|
|
5
6
|
import 'hono';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -106,8 +107,32 @@ declare class MemoryWalletClient {
|
|
|
106
107
|
}>;
|
|
107
108
|
signup(_credentials: UserCredentials): Promise<AuthSession>;
|
|
108
109
|
login(_credentials: UserCredentials): Promise<AuthSession>;
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Sign up with session keypair (scoped to an app)
|
|
112
|
+
*
|
|
113
|
+
* The session must be approved by the app beforehand:
|
|
114
|
+
* 1. Client writes request to: immutable://inbox/{appKey}/sessions/{sessionPubkey} = 1
|
|
115
|
+
* 2. App approves by writing: mutable://accounts/{appKey}/sessions/{sessionPubkey} = 1
|
|
116
|
+
* 3. Client calls this method with the session keypair
|
|
117
|
+
*
|
|
118
|
+
* @param appKey - The app's public key
|
|
119
|
+
* @param session - Session keypair (generated via generateSessionKeypair)
|
|
120
|
+
* @param credentials - User credentials (username/password)
|
|
121
|
+
*/
|
|
122
|
+
signupWithToken(appKey: string, session: SessionKeypair, credentials: UserCredentials): Promise<AuthSession>;
|
|
123
|
+
/**
|
|
124
|
+
* Login with session keypair (scoped to an app)
|
|
125
|
+
*
|
|
126
|
+
* The session must be approved by the app beforehand:
|
|
127
|
+
* 1. Client writes request to: immutable://inbox/{appKey}/sessions/{sessionPubkey} = 1
|
|
128
|
+
* 2. App approves by writing: mutable://accounts/{appKey}/sessions/{sessionPubkey} = 1
|
|
129
|
+
* 3. Client calls this method with the session keypair
|
|
130
|
+
*
|
|
131
|
+
* @param appKey - The app's public key
|
|
132
|
+
* @param session - Session keypair (generated via generateSessionKeypair)
|
|
133
|
+
* @param credentials - User credentials (username/password)
|
|
134
|
+
*/
|
|
135
|
+
loginWithTokenSession(appKey: string, session: SessionKeypair, credentials: UserCredentials): Promise<AuthSession>;
|
|
111
136
|
changePassword(appKey: string, oldPassword: string, newPassword: string): Promise<void>;
|
|
112
137
|
requestPasswordReset(_username: string): Promise<PasswordResetToken>;
|
|
113
138
|
resetPassword(_username: string, _resetToken: string, _newPassword: string): Promise<AuthSession>;
|
|
@@ -117,8 +142,21 @@ declare class MemoryWalletClient {
|
|
|
117
142
|
getMyPublicKeys(appKey: string): Promise<UserPublicKeys>;
|
|
118
143
|
proxyWrite(request: ProxyWriteRequest): Promise<ProxyWriteResponse>;
|
|
119
144
|
proxyRead(request: ProxyReadRequest): Promise<ProxyReadResponse>;
|
|
145
|
+
proxyReadMulti(request: ProxyReadMultiRequest): Promise<ProxyReadMultiResponse>;
|
|
120
146
|
signupWithGoogle(appKey: string, token: string, googleIdToken: string): Promise<GoogleAuthSession>;
|
|
121
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Login with Google OAuth (scoped to app token and session keypair)
|
|
149
|
+
* Returns session data with Google profile info - call setSession() to activate it
|
|
150
|
+
*
|
|
151
|
+
* The session must be approved by the app beforehand.
|
|
152
|
+
*
|
|
153
|
+
* @param appKey - The app's public key
|
|
154
|
+
* @param token - App token from app server
|
|
155
|
+
* @param session - Session keypair (generated via generateSessionKeypair)
|
|
156
|
+
* @param googleIdToken - Google ID token from Google Sign-In
|
|
157
|
+
* @returns GoogleAuthSession with username, JWT token, and Google profile info
|
|
158
|
+
*/
|
|
159
|
+
loginWithGoogle(appKey: string, token: string, session: SessionKeypair, googleIdToken: string): Promise<GoogleAuthSession>;
|
|
122
160
|
/**
|
|
123
161
|
* Get the underlying WalletServerCore (for testing/inspection)
|
|
124
162
|
*/
|
|
@@ -132,4 +170,141 @@ declare class MemoryWalletClient {
|
|
|
132
170
|
};
|
|
133
171
|
}
|
|
134
172
|
|
|
135
|
-
|
|
173
|
+
/**
|
|
174
|
+
* Test Utilities for B3nd Wallet
|
|
175
|
+
*
|
|
176
|
+
* Provides helpers for setting up test environments with shared in-memory storage.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* import { createTestEnvironment } from "@bandeira-tech/b3nd-web/wallet";
|
|
181
|
+
*
|
|
182
|
+
* const { backend, wallet, signupTestUser, cleanup } = await createTestEnvironment();
|
|
183
|
+
*
|
|
184
|
+
* // Sign up a test user
|
|
185
|
+
* const { session, keys } = await signupTestUser("app-key", "testuser", "pass123");
|
|
186
|
+
*
|
|
187
|
+
* // Now wallet.proxyRead/proxyWrite work with the shared backend
|
|
188
|
+
* const writeResult = await wallet.proxyWrite({ uri: "mutable://data/test", data: { foo: "bar" }, encrypt: true });
|
|
189
|
+
* const readResult = await wallet.proxyRead({ uri: "mutable://data/test" });
|
|
190
|
+
* console.log(readResult.decrypted); // { foo: "bar" }
|
|
191
|
+
*
|
|
192
|
+
* // Direct backend access also works
|
|
193
|
+
* const raw = await backend.read("mutable://data/test");
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Test environment configuration
|
|
199
|
+
*/
|
|
200
|
+
interface TestEnvironmentConfig {
|
|
201
|
+
/**
|
|
202
|
+
* Custom schema for the backend.
|
|
203
|
+
* If not provided, uses createTestSchema() which accepts all writes.
|
|
204
|
+
*/
|
|
205
|
+
schema?: Schema;
|
|
206
|
+
/**
|
|
207
|
+
* Custom server keys.
|
|
208
|
+
* If not provided, keys are auto-generated.
|
|
209
|
+
*/
|
|
210
|
+
serverKeys?: ServerKeys;
|
|
211
|
+
/**
|
|
212
|
+
* Custom JWT secret.
|
|
213
|
+
* Defaults to a test secret.
|
|
214
|
+
*/
|
|
215
|
+
jwtSecret?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Test environment with shared backend
|
|
219
|
+
*/
|
|
220
|
+
interface TestEnvironment {
|
|
221
|
+
/**
|
|
222
|
+
* The shared in-memory backend storage.
|
|
223
|
+
* Use this for direct reads/writes in tests.
|
|
224
|
+
*/
|
|
225
|
+
backend: MemoryClient;
|
|
226
|
+
/**
|
|
227
|
+
* The wallet client connected to the shared backend.
|
|
228
|
+
* Same API as WalletClient but runs in-memory.
|
|
229
|
+
*/
|
|
230
|
+
wallet: MemoryWalletClient;
|
|
231
|
+
/**
|
|
232
|
+
* Server keys (for advanced testing)
|
|
233
|
+
*/
|
|
234
|
+
serverKeys: ServerKeys;
|
|
235
|
+
/**
|
|
236
|
+
* Sign up a test user and set the session.
|
|
237
|
+
* Automatically generates and approves a session keypair for testing.
|
|
238
|
+
*
|
|
239
|
+
* @param appKey - App key for the signup
|
|
240
|
+
* @param username - Username
|
|
241
|
+
* @param password - Password
|
|
242
|
+
* @returns Session, user public keys, and the session keypair used
|
|
243
|
+
*/
|
|
244
|
+
signupTestUser(appKey: string, username: string, password: string): Promise<{
|
|
245
|
+
session: AuthSession;
|
|
246
|
+
keys: UserPublicKeys;
|
|
247
|
+
sessionKeypair: SessionKeypair;
|
|
248
|
+
}>;
|
|
249
|
+
/**
|
|
250
|
+
* Login a test user and set the session.
|
|
251
|
+
* Automatically generates and approves a session keypair for testing.
|
|
252
|
+
*
|
|
253
|
+
* @param appKey - App key for the login
|
|
254
|
+
* @param username - Username
|
|
255
|
+
* @param password - Password
|
|
256
|
+
* @returns Session, user public keys, and the session keypair used
|
|
257
|
+
*/
|
|
258
|
+
loginTestUser(appKey: string, username: string, password: string): Promise<{
|
|
259
|
+
session: AuthSession;
|
|
260
|
+
keys: UserPublicKeys;
|
|
261
|
+
sessionKeypair: SessionKeypair;
|
|
262
|
+
}>;
|
|
263
|
+
/**
|
|
264
|
+
* Clean up the test environment.
|
|
265
|
+
* Clears all data from the backend.
|
|
266
|
+
*/
|
|
267
|
+
cleanup(): Promise<void>;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Create a test environment with shared in-memory backend.
|
|
271
|
+
*
|
|
272
|
+
* This sets up a MemoryClient and MemoryWalletClient that share the same storage,
|
|
273
|
+
* enabling you to test wallet operations alongside direct backend access.
|
|
274
|
+
*
|
|
275
|
+
* @param config - Optional configuration
|
|
276
|
+
* @returns Test environment with backend, wallet, and helper functions
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* // Basic usage
|
|
281
|
+
* const { backend, wallet, signupTestUser } = await createTestEnvironment();
|
|
282
|
+
* const { keys } = await signupTestUser("my-app", "alice", "password123");
|
|
283
|
+
*
|
|
284
|
+
* // Write encrypted data
|
|
285
|
+
* await wallet.proxyWrite({
|
|
286
|
+
* uri: "mutable://data/:key/profile",
|
|
287
|
+
* data: { name: "Alice" },
|
|
288
|
+
* encrypt: true
|
|
289
|
+
* });
|
|
290
|
+
*
|
|
291
|
+
* // Read and decrypt
|
|
292
|
+
* const result = await wallet.proxyRead({ uri: "mutable://data/:key/profile" });
|
|
293
|
+
* console.log(result.decrypted); // { name: "Alice" }
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* // With custom schema
|
|
299
|
+
* const { backend, wallet } = await createTestEnvironment({
|
|
300
|
+
* schema: {
|
|
301
|
+
* "mutable://myapp": async () => ({ valid: true }),
|
|
302
|
+
* "mutable://accounts": async () => ({ valid: true }),
|
|
303
|
+
* "immutable://accounts": async () => ({ valid: true }),
|
|
304
|
+
* }
|
|
305
|
+
* });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
declare function createTestEnvironment(config?: TestEnvironmentConfig): Promise<TestEnvironment>;
|
|
309
|
+
|
|
310
|
+
export { AuthSession, GoogleAuthSession, HealthResponse, MemoryWalletClient, type MemoryWalletClientConfig, PasswordResetToken, ProxyReadMultiRequest, ProxyReadMultiResponse, ProxyReadRequest, ProxyReadResponse, ProxyWriteRequest, ProxyWriteResponse, SessionKeypair, type TestEnvironment, type TestEnvironmentConfig, UserCredentials, UserPublicKeys, createTestEnvironment, generateTestServerKeys };
|
package/dist/wallet/mod.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MemoryWalletClient,
|
|
3
3
|
WalletClient,
|
|
4
|
+
createTestEnvironment,
|
|
5
|
+
generateSessionKeypair,
|
|
4
6
|
generateTestServerKeys
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-F3W5GZU6.js";
|
|
7
|
+
} from "../chunk-GWPCZVXV.js";
|
|
8
|
+
import "../chunk-B4VAPGAO.js";
|
|
8
9
|
import "../chunk-JN75UL5C.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-OY4CDOHY.js";
|
|
11
|
+
import "../chunk-O53KW746.js";
|
|
10
12
|
import "../chunk-MLKGABMK.js";
|
|
11
13
|
export {
|
|
12
14
|
MemoryWalletClient,
|
|
13
15
|
WalletClient,
|
|
16
|
+
createTestEnvironment,
|
|
17
|
+
generateSessionKeypair,
|
|
14
18
|
generateTestServerKeys
|
|
15
19
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { F as FileStorage, S as ServerKeys, W as WalletServerCore } from '../../core-
|
|
2
|
-
export { C as BrowserEnvironment, M as BrowserMemoryStorage } from '../../core-
|
|
1
|
+
import { F as FileStorage, S as ServerKeys, W as WalletServerCore } from '../../core-ClnuubZw.js';
|
|
2
|
+
export { C as BrowserEnvironment, M as BrowserMemoryStorage } from '../../core-ClnuubZw.js';
|
|
3
3
|
import 'hono';
|
|
4
|
-
import '../../types-
|
|
4
|
+
import '../../types-uuvn4oKw.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Browser Adapter for Wallet Server
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LocalStorageClient
|
|
3
|
-
} from "../../chunk-7U5JDFQW.js";
|
|
4
1
|
import {
|
|
5
2
|
ConfigEnvironment,
|
|
6
3
|
MemoryFileStorage,
|
|
7
4
|
WalletServerCore
|
|
8
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-B4VAPGAO.js";
|
|
9
6
|
import "../../chunk-JN75UL5C.js";
|
|
10
|
-
import "../../chunk-
|
|
7
|
+
import "../../chunk-OY4CDOHY.js";
|
|
8
|
+
import {
|
|
9
|
+
LocalStorageClient
|
|
10
|
+
} from "../../chunk-PZFEKQ7F.js";
|
|
11
11
|
import "../../chunk-MLKGABMK.js";
|
|
12
12
|
|
|
13
13
|
// wallet-server/adapters/browser.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as ProxyWriteRequest, a as ProxyWriteResponse, b as ProxyReadResponse, U as UserKeys, L as Logger, H as HttpFetch } from '../core-
|
|
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-
|
|
3
|
-
import { N as NodeProtocolInterface } from '../types-
|
|
1
|
+
import { P as ProxyWriteRequest, a as ProxyWriteResponse, b as ProxyReadResponse, U as UserKeys, L as Logger, H as HttpFetch } from '../core-ClnuubZw.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-ClnuubZw.js';
|
|
3
|
+
import { N as NodeProtocolInterface } from '../types-uuvn4oKw.js';
|
|
4
4
|
import { S as SignedEncryptedMessage, E as EncryptedPayload } from '../mod-CII9wqu2.js';
|
|
5
5
|
import 'hono';
|
|
6
6
|
|
|
@@ -43,8 +43,11 @@ declare function extractUsernameFromJwt(token: string): string | null;
|
|
|
43
43
|
declare function proxyWrite(proxyClient: NodeProtocolInterface, credentialClient: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, request: ProxyWriteRequest): Promise<ProxyWriteResponse>;
|
|
44
44
|
/**
|
|
45
45
|
* Proxy a read request (with optional decryption)
|
|
46
|
+
*
|
|
47
|
+
* Data encrypted with proxyWrite is encrypted with the user's encryption key,
|
|
48
|
+
* so we need to load the user's encryption key to decrypt it.
|
|
46
49
|
*/
|
|
47
|
-
declare function proxyRead(proxyClient: NodeProtocolInterface,
|
|
50
|
+
declare function proxyRead(proxyClient: NodeProtocolInterface, credentialClient: NodeProtocolInterface, serverPublicKey: string, username: string, serverEncryptionPrivateKeyPem: string, uri: string): Promise<ProxyReadResponse>;
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
53
|
* User Key Management
|
|
@@ -140,7 +143,7 @@ declare function createUser(client: NodeProtocolInterface, serverPublicKey: stri
|
|
|
140
143
|
/**
|
|
141
144
|
* Authenticate user with password
|
|
142
145
|
*/
|
|
143
|
-
declare function authenticateUser(client: NodeProtocolInterface, serverPublicKey: string, username: string, password: string,
|
|
146
|
+
declare function authenticateUser(client: NodeProtocolInterface, serverPublicKey: string, username: string, password: string, serverEncryptionPrivateKeyPem: string, appScope?: string, logger?: Logger): Promise<boolean>;
|
|
144
147
|
/**
|
|
145
148
|
* Change user password
|
|
146
149
|
*/
|
|
@@ -190,7 +193,10 @@ interface CredentialResult {
|
|
|
190
193
|
*/
|
|
191
194
|
interface BaseCredentialPayload {
|
|
192
195
|
type: string;
|
|
193
|
-
session
|
|
196
|
+
/** Session public key (hex). Required for login - identifies the session. */
|
|
197
|
+
sessionPubkey?: string;
|
|
198
|
+
/** Signature of the login payload by session private key (hex). Required for login. */
|
|
199
|
+
sessionSignature?: string;
|
|
194
200
|
}
|
|
195
201
|
/**
|
|
196
202
|
* Password credential payload
|
|
@@ -34,9 +34,9 @@ import {
|
|
|
34
34
|
userExists,
|
|
35
35
|
verifyGoogleIdToken,
|
|
36
36
|
verifyJwt
|
|
37
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-B4VAPGAO.js";
|
|
38
38
|
import "../chunk-JN75UL5C.js";
|
|
39
|
-
import "../chunk-
|
|
39
|
+
import "../chunk-OY4CDOHY.js";
|
|
40
40
|
import "../chunk-MLKGABMK.js";
|
|
41
41
|
export {
|
|
42
42
|
ConfigEnvironment,
|