@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.
- package/dist/chunk-F3W5GZU6.js +1775 -0
- package/dist/{chunk-K3ZSSVHR.js → chunk-JN75UL5C.js} +2 -0
- package/dist/core-CgxQpSVM.d.ts +275 -0
- package/dist/encrypt/mod.d.ts +1 -1
- package/dist/encrypt/mod.js +1 -1
- package/dist/{mod-D02790g_.d.ts → mod-CII9wqu2.d.ts} +1 -1
- package/dist/src/mod.web.d.ts +1 -1
- package/dist/src/mod.web.js +4 -4
- package/dist/wallet-server/adapters/browser.d.ts +76 -0
- package/dist/wallet-server/adapters/browser.js +105 -0
- package/dist/wallet-server/mod.d.ts +320 -0
- package/dist/wallet-server/mod.js +77 -0
- package/package.json +13 -3
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { N as NodeProtocolInterface } from './types-oQCx3U-_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wallet Server Dependency Injection Interfaces
|
|
6
|
+
*
|
|
7
|
+
* These interfaces abstract runtime-specific operations, enabling the wallet
|
|
8
|
+
* server to run in Deno, Node.js, or browsers through dependency injection.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* File storage abstraction - replaces Deno.readTextFile/writeTextFile
|
|
12
|
+
*/
|
|
13
|
+
interface FileStorage {
|
|
14
|
+
readTextFile(path: string): Promise<string>;
|
|
15
|
+
writeTextFile(path: string, content: string): Promise<void>;
|
|
16
|
+
exists(path: string): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Environment abstraction - replaces Deno.env.get()
|
|
20
|
+
*/
|
|
21
|
+
interface Environment {
|
|
22
|
+
get(key: string): string | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Logger abstraction - replaces console.log/warn/error
|
|
26
|
+
*/
|
|
27
|
+
interface Logger {
|
|
28
|
+
log(...args: unknown[]): void;
|
|
29
|
+
warn(...args: unknown[]): void;
|
|
30
|
+
error(...args: unknown[]): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* HTTP fetch abstraction - allows custom fetch implementations
|
|
34
|
+
*/
|
|
35
|
+
type HttpFetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
36
|
+
/**
|
|
37
|
+
* Default console logger implementation
|
|
38
|
+
*/
|
|
39
|
+
declare const defaultLogger: Logger;
|
|
40
|
+
/**
|
|
41
|
+
* In-memory file storage implementation (for testing/browser)
|
|
42
|
+
*/
|
|
43
|
+
declare class MemoryFileStorage implements FileStorage {
|
|
44
|
+
private storage;
|
|
45
|
+
readTextFile(path: string): Promise<string>;
|
|
46
|
+
writeTextFile(path: string, content: string): Promise<void>;
|
|
47
|
+
exists(path: string): Promise<boolean>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Environment from config object (for testing/browser)
|
|
51
|
+
*/
|
|
52
|
+
declare class ConfigEnvironment implements Environment {
|
|
53
|
+
private config;
|
|
54
|
+
constructor(config?: Record<string, string>);
|
|
55
|
+
get(key: string): string | undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Wallet Server Types
|
|
60
|
+
*
|
|
61
|
+
* Type definitions for the universal wallet server SDK.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Server key pair configuration
|
|
66
|
+
*/
|
|
67
|
+
interface ServerKeyPair {
|
|
68
|
+
privateKeyPem: string;
|
|
69
|
+
publicKeyHex: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Server keys configuration (identity + encryption)
|
|
73
|
+
*/
|
|
74
|
+
interface ServerKeys {
|
|
75
|
+
identityKey: ServerKeyPair;
|
|
76
|
+
encryptionKey: ServerKeyPair;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* App backend configuration for bootstrap
|
|
80
|
+
*/
|
|
81
|
+
interface AppBackendConfig {
|
|
82
|
+
url: string;
|
|
83
|
+
apiBasePath?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Dependency injection configuration
|
|
87
|
+
*/
|
|
88
|
+
interface WalletServerDeps {
|
|
89
|
+
/** File storage for bootstrap state persistence */
|
|
90
|
+
storage?: FileStorage;
|
|
91
|
+
/** Logger for output */
|
|
92
|
+
logger?: Logger;
|
|
93
|
+
/** Custom fetch implementation */
|
|
94
|
+
fetch?: HttpFetch;
|
|
95
|
+
/** Pre-configured credential client (alternative to credentialNodeUrl) */
|
|
96
|
+
credentialClient?: NodeProtocolInterface;
|
|
97
|
+
/** Pre-configured proxy client (alternative to proxyNodeUrl) */
|
|
98
|
+
proxyClient?: NodeProtocolInterface;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Wallet server configuration
|
|
102
|
+
*/
|
|
103
|
+
interface WalletServerConfig {
|
|
104
|
+
/** Server identity and encryption keys */
|
|
105
|
+
serverKeys: ServerKeys;
|
|
106
|
+
/** JWT secret for token signing (must be 32+ characters) */
|
|
107
|
+
jwtSecret: string;
|
|
108
|
+
/** JWT expiration in seconds (default: 86400 = 24 hours) */
|
|
109
|
+
jwtExpirationSeconds?: number;
|
|
110
|
+
/** URL of the credential backend node */
|
|
111
|
+
credentialNodeUrl?: string;
|
|
112
|
+
/** URL of the proxy backend node */
|
|
113
|
+
proxyNodeUrl?: string;
|
|
114
|
+
/** CORS allowed origins (default: ["*"]) */
|
|
115
|
+
allowedOrigins?: string[];
|
|
116
|
+
/** App backend for bootstrap (optional) */
|
|
117
|
+
appBackend?: AppBackendConfig;
|
|
118
|
+
/** Password reset token TTL in seconds (default: 3600 = 1 hour) */
|
|
119
|
+
passwordResetTokenTtlSeconds?: number;
|
|
120
|
+
/** Google OAuth client ID (optional, enables Google auth) */
|
|
121
|
+
googleClientId?: string;
|
|
122
|
+
/** Path for bootstrap state file (optional) */
|
|
123
|
+
bootstrapStatePath?: string;
|
|
124
|
+
/** Dependency injection */
|
|
125
|
+
deps?: WalletServerDeps;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resolved configuration with defaults applied
|
|
129
|
+
*/
|
|
130
|
+
interface ResolvedWalletServerConfig {
|
|
131
|
+
serverKeys: ServerKeys;
|
|
132
|
+
jwtSecret: string;
|
|
133
|
+
jwtExpirationSeconds: number;
|
|
134
|
+
allowedOrigins: string[];
|
|
135
|
+
passwordResetTokenTtlSeconds: number;
|
|
136
|
+
googleClientId: string | null;
|
|
137
|
+
bootstrapStatePath: string | null;
|
|
138
|
+
appBackend: AppBackendConfig | null;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* User keys structure
|
|
142
|
+
*/
|
|
143
|
+
interface UserKeys {
|
|
144
|
+
accountKey: ServerKeyPair;
|
|
145
|
+
encryptionKey: ServerKeyPair;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Proxy write request
|
|
149
|
+
*/
|
|
150
|
+
interface ProxyWriteRequest {
|
|
151
|
+
uri: string;
|
|
152
|
+
data: unknown;
|
|
153
|
+
encrypt?: boolean;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Proxy write response
|
|
157
|
+
*/
|
|
158
|
+
interface ProxyWriteResponse {
|
|
159
|
+
success: boolean;
|
|
160
|
+
resolvedUri?: string;
|
|
161
|
+
error?: string;
|
|
162
|
+
record?: {
|
|
163
|
+
data: unknown;
|
|
164
|
+
ts: number;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Proxy read response
|
|
169
|
+
*/
|
|
170
|
+
interface ProxyReadResponse {
|
|
171
|
+
success: boolean;
|
|
172
|
+
error?: string;
|
|
173
|
+
record?: {
|
|
174
|
+
data: unknown;
|
|
175
|
+
ts: number;
|
|
176
|
+
};
|
|
177
|
+
decrypted?: unknown;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Auth session response
|
|
181
|
+
*/
|
|
182
|
+
interface AuthSessionResponse {
|
|
183
|
+
success: boolean;
|
|
184
|
+
username: string;
|
|
185
|
+
token: string;
|
|
186
|
+
expiresIn: number;
|
|
187
|
+
error?: string;
|
|
188
|
+
email?: string;
|
|
189
|
+
name?: string;
|
|
190
|
+
picture?: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Public keys response
|
|
194
|
+
*/
|
|
195
|
+
interface PublicKeysResponse {
|
|
196
|
+
success: boolean;
|
|
197
|
+
accountPublicKeyHex?: string;
|
|
198
|
+
encryptionPublicKeyHex?: string;
|
|
199
|
+
error?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Health response
|
|
203
|
+
*/
|
|
204
|
+
interface HealthResponse {
|
|
205
|
+
success: boolean;
|
|
206
|
+
status: string;
|
|
207
|
+
server: string;
|
|
208
|
+
timestamp: string;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Server keys response
|
|
212
|
+
*/
|
|
213
|
+
interface ServerKeysResponse {
|
|
214
|
+
success: boolean;
|
|
215
|
+
identityPublicKeyHex: string;
|
|
216
|
+
encryptionPublicKeyHex: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Wallet Server Core
|
|
221
|
+
*
|
|
222
|
+
* Universal wallet server that works in Deno, Node.js, and browsers.
|
|
223
|
+
* Uses dependency injection for all runtime-specific operations.
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
interface BootstrapState {
|
|
227
|
+
appKey: string;
|
|
228
|
+
createdAt: string;
|
|
229
|
+
appServerUrl: string;
|
|
230
|
+
apiBasePath: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Wallet Server Core
|
|
234
|
+
*
|
|
235
|
+
* Creates a portable Hono application that can be served by any runtime.
|
|
236
|
+
*/
|
|
237
|
+
declare class WalletServerCore {
|
|
238
|
+
private config;
|
|
239
|
+
private serverKeys;
|
|
240
|
+
private credentialClient;
|
|
241
|
+
private proxyClient;
|
|
242
|
+
private app;
|
|
243
|
+
private logger;
|
|
244
|
+
private storage;
|
|
245
|
+
private fetchImpl;
|
|
246
|
+
constructor(userConfig: WalletServerConfig);
|
|
247
|
+
private validateConfig;
|
|
248
|
+
private applyDefaults;
|
|
249
|
+
/**
|
|
250
|
+
* Get the Hono app instance
|
|
251
|
+
*/
|
|
252
|
+
getApp(): Hono;
|
|
253
|
+
/**
|
|
254
|
+
* Get the fetch handler for use with various runtimes
|
|
255
|
+
*/
|
|
256
|
+
getFetchHandler(): (request: Request) => Response | Promise<Response>;
|
|
257
|
+
/**
|
|
258
|
+
* Get server public keys
|
|
259
|
+
*/
|
|
260
|
+
getServerKeys(): {
|
|
261
|
+
identityPublicKeyHex: string;
|
|
262
|
+
encryptionPublicKeyHex: string;
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Bootstrap wallet app registration (optional)
|
|
266
|
+
*/
|
|
267
|
+
bootstrap(): Promise<BootstrapState | null>;
|
|
268
|
+
private normalizeApiBasePath;
|
|
269
|
+
private readBootstrapState;
|
|
270
|
+
private writeBootstrapState;
|
|
271
|
+
private sessionExists;
|
|
272
|
+
private createApp;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export { type AppBackendConfig as A, ConfigEnvironment as C, type Environment as E, type FileStorage as F, type HttpFetch as H, type Logger as L, MemoryFileStorage as M, type ProxyWriteRequest as P, type ResolvedWalletServerConfig as R, type ServerKeys as S, type UserKeys as U, WalletServerCore as W, type ProxyWriteResponse as a, type ProxyReadResponse as b, type WalletServerConfig as c, type WalletServerDeps as d, type ServerKeyPair as e, type AuthSessionResponse as f, type PublicKeysResponse as g, type HealthResponse as h, type ServerKeysResponse as i, defaultLogger as j };
|
package/dist/encrypt/mod.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AuthenticatedMessage,
|
|
1
|
+
export { A as AuthenticatedMessage, E as EncryptedPayload, a as EncryptionKeyPair, I as IdentityKey, K as KeyPair, d as PrivateEncryptionKey, P as PublicEncryptionKey, c as SecretEncryptionKey, S as SignedEncryptedMessage, b as SignedSymmetricMessage, k as createAuthenticatedMessage, l as createAuthenticatedMessageWithHex, w as createSignedEncryptedMessage, B as createSignedSymmetricMessage, i as decrypt, z as decryptSymmetric, j as decryptWithHex, n as deriveKeyFromSeed, h as encrypt, y as encryptSymmetric, r as exportPrivateKeyPem, e as generateEncryptionKeyPair, o as generateNonce, q as generateRandomData, g as generateSigningKeyPair, p as pemToCryptoKey, s as sign, t as signPayload, f as signWithHex, v as verify, x as verifyAndDecryptMessage, u as verifyPayload } from '../mod-CII9wqu2.js';
|
package/dist/encrypt/mod.js
CHANGED
|
@@ -238,4 +238,4 @@ declare namespace mod {
|
|
|
238
238
|
export { type mod_AuthenticatedMessage as AuthenticatedMessage, type mod_EncryptedPayload as EncryptedPayload, type mod_EncryptionKeyPair as EncryptionKeyPair, mod_IdentityKey as IdentityKey, type mod_KeyPair as KeyPair, mod_PrivateEncryptionKey as PrivateEncryptionKey, mod_PublicEncryptionKey as PublicEncryptionKey, mod_SecretEncryptionKey as SecretEncryptionKey, type mod_SignedEncryptedMessage as SignedEncryptedMessage, type mod_SignedSymmetricMessage as SignedSymmetricMessage, mod_createAuthenticatedMessage as createAuthenticatedMessage, mod_createAuthenticatedMessageWithHex as createAuthenticatedMessageWithHex, mod_createSignedEncryptedMessage as createSignedEncryptedMessage, mod_createSignedSymmetricMessage as createSignedSymmetricMessage, mod_decrypt as decrypt, mod_decryptSymmetric as decryptSymmetric, mod_decryptWithHex as decryptWithHex, mod_deriveKeyFromSeed as deriveKeyFromSeed, mod_encrypt as encrypt, mod_encryptSymmetric as encryptSymmetric, mod_exportPrivateKeyPem as exportPrivateKeyPem, mod_generateEncryptionKeyPair as generateEncryptionKeyPair, mod_generateNonce as generateNonce, mod_generateRandomData as generateRandomData, mod_generateSigningKeyPair as generateSigningKeyPair, mod_pemToCryptoKey as pemToCryptoKey, mod_sign as sign, mod_signPayload as signPayload, mod_signWithHex as signWithHex, mod_verify as verify, mod_verifyAndDecryptMessage as verifyAndDecryptMessage, mod_verifyPayload as verifyPayload };
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
export { type AuthenticatedMessage as A, createSignedSymmetricMessage as B, type
|
|
241
|
+
export { type AuthenticatedMessage as A, createSignedSymmetricMessage as B, type EncryptedPayload as E, IdentityKey as I, type KeyPair as K, PublicEncryptionKey as P, type SignedEncryptedMessage as S, type EncryptionKeyPair as a, type SignedSymmetricMessage as b, SecretEncryptionKey as c, PrivateEncryptionKey as d, generateEncryptionKeyPair as e, signWithHex as f, generateSigningKeyPair as g, encrypt as h, decrypt as i, decryptWithHex as j, createAuthenticatedMessage as k, createAuthenticatedMessageWithHex as l, mod as m, deriveKeyFromSeed as n, generateNonce as o, pemToCryptoKey as p, generateRandomData as q, exportPrivateKeyPem as r, sign as s, signPayload as t, verifyPayload as u, verify as v, createSignedEncryptedMessage as w, verifyAndDecryptMessage as x, encryptSymmetric as y, decryptSymmetric as z };
|
package/dist/src/mod.web.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { WebSocketClient } from '../clients/websocket/mod.js';
|
|
|
4
4
|
export { LocalStorageClient } from '../clients/local-storage/mod.js';
|
|
5
5
|
export { WalletClient } from '../wallet/mod.js';
|
|
6
6
|
export { AppsClient } from '../apps/mod.js';
|
|
7
|
-
export { m as encrypt } from '../mod-
|
|
7
|
+
export { m as encrypt } from '../mod-CII9wqu2.js';
|
package/dist/src/mod.web.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppsClient
|
|
3
|
+
} from "../chunk-VAZUCGED.js";
|
|
1
4
|
import {
|
|
2
5
|
mod_exports
|
|
3
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-JN75UL5C.js";
|
|
4
7
|
import {
|
|
5
8
|
WalletClient
|
|
6
9
|
} from "../chunk-S7NJA6B6.js";
|
|
@@ -13,9 +16,6 @@ import {
|
|
|
13
16
|
import {
|
|
14
17
|
WebSocketClient
|
|
15
18
|
} from "../chunk-T43IWAQK.js";
|
|
16
|
-
import {
|
|
17
|
-
AppsClient
|
|
18
|
-
} from "../chunk-VAZUCGED.js";
|
|
19
19
|
import "../chunk-MLKGABMK.js";
|
|
20
20
|
export {
|
|
21
21
|
AppsClient,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { F as FileStorage, S as ServerKeys, W as WalletServerCore } from '../../core-CgxQpSVM.js';
|
|
2
|
+
export { C as BrowserEnvironment, M as BrowserMemoryStorage } from '../../core-CgxQpSVM.js';
|
|
3
|
+
import 'hono';
|
|
4
|
+
import '../../types-oQCx3U-_.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Browser Adapter for Wallet Server
|
|
8
|
+
*
|
|
9
|
+
* Provides browser-compatible implementations for running a wallet server
|
|
10
|
+
* in simulation/demo mode using in-memory or localStorage storage.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Browser localStorage-backed file storage
|
|
15
|
+
*/
|
|
16
|
+
declare class BrowserLocalStorageFileStorage implements FileStorage {
|
|
17
|
+
private keyPrefix;
|
|
18
|
+
constructor(keyPrefix?: string);
|
|
19
|
+
readTextFile(path: string): Promise<string>;
|
|
20
|
+
writeTextFile(path: string, content: string): Promise<void>;
|
|
21
|
+
exists(path: string): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Options for creating a browser wallet server
|
|
26
|
+
*/
|
|
27
|
+
interface BrowserWalletServerOptions {
|
|
28
|
+
/** Server keys (required) */
|
|
29
|
+
serverKeys: ServerKeys;
|
|
30
|
+
/** JWT secret (required, must be 32+ chars) */
|
|
31
|
+
jwtSecret: string;
|
|
32
|
+
/** Use localStorage for persistence (default: false = in-memory) */
|
|
33
|
+
useLocalStorage?: boolean;
|
|
34
|
+
/** Key prefix for localStorage (default: "b3nd-wallet-") */
|
|
35
|
+
localStoragePrefix?: string;
|
|
36
|
+
/** JWT expiration in seconds (default: 86400) */
|
|
37
|
+
jwtExpirationSeconds?: number;
|
|
38
|
+
/** Allowed origins (default: ["*"]) */
|
|
39
|
+
allowedOrigins?: string[];
|
|
40
|
+
/** Google OAuth client ID (optional) */
|
|
41
|
+
googleClientId?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a browser-compatible wallet server for simulation/testing
|
|
45
|
+
*
|
|
46
|
+
* This creates a fully functional wallet server that runs in the browser
|
|
47
|
+
* using LocalStorageClient as the backend. Useful for:
|
|
48
|
+
* - Demo applications
|
|
49
|
+
* - Testing without a real backend
|
|
50
|
+
* - Offline-first applications
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { createBrowserWalletServer, generateBrowserServerKeys } from "@b3nd/sdk/wallet-server/adapters/browser";
|
|
55
|
+
*
|
|
56
|
+
* const serverKeys = await generateBrowserServerKeys();
|
|
57
|
+
* const server = createBrowserWalletServer({
|
|
58
|
+
* serverKeys,
|
|
59
|
+
* jwtSecret: "your-32-character-minimum-secret!!",
|
|
60
|
+
* useLocalStorage: true,
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Use with fetch API
|
|
64
|
+
* const response = await server.getFetchHandler()(new Request("/api/v1/health"));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function createBrowserWalletServer(options: BrowserWalletServerOptions): WalletServerCore;
|
|
68
|
+
/**
|
|
69
|
+
* Generate server keys in the browser
|
|
70
|
+
*
|
|
71
|
+
* Creates Ed25519 (identity) and X25519 (encryption) key pairs
|
|
72
|
+
* using the Web Crypto API.
|
|
73
|
+
*/
|
|
74
|
+
declare function generateBrowserServerKeys(): Promise<ServerKeys>;
|
|
75
|
+
|
|
76
|
+
export { BrowserLocalStorageFileStorage, type BrowserWalletServerOptions, createBrowserWalletServer, generateBrowserServerKeys };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigEnvironment,
|
|
3
|
+
MemoryFileStorage,
|
|
4
|
+
WalletServerCore
|
|
5
|
+
} from "../../chunk-F3W5GZU6.js";
|
|
6
|
+
import "../../chunk-JN75UL5C.js";
|
|
7
|
+
import "../../chunk-LFUC4ETD.js";
|
|
8
|
+
import {
|
|
9
|
+
LocalStorageClient
|
|
10
|
+
} from "../../chunk-7U5JDFQW.js";
|
|
11
|
+
import "../../chunk-MLKGABMK.js";
|
|
12
|
+
|
|
13
|
+
// wallet-server/adapters/browser.ts
|
|
14
|
+
var BrowserLocalStorageFileStorage = class {
|
|
15
|
+
constructor(keyPrefix = "b3nd-wallet-files:") {
|
|
16
|
+
this.keyPrefix = keyPrefix;
|
|
17
|
+
}
|
|
18
|
+
async readTextFile(path) {
|
|
19
|
+
const content = localStorage.getItem(this.keyPrefix + path);
|
|
20
|
+
if (content === null) {
|
|
21
|
+
throw new Error(`File not found: ${path}`);
|
|
22
|
+
}
|
|
23
|
+
return content;
|
|
24
|
+
}
|
|
25
|
+
async writeTextFile(path, content) {
|
|
26
|
+
localStorage.setItem(this.keyPrefix + path, content);
|
|
27
|
+
}
|
|
28
|
+
async exists(path) {
|
|
29
|
+
return localStorage.getItem(this.keyPrefix + path) !== null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function createBrowserWalletServer(options) {
|
|
33
|
+
const prefix = options.localStoragePrefix ?? "b3nd-wallet-";
|
|
34
|
+
const storage = options.useLocalStorage ? new BrowserLocalStorageFileStorage(prefix + "files:") : new MemoryFileStorage();
|
|
35
|
+
const client = new LocalStorageClient({
|
|
36
|
+
keyPrefix: prefix + "data:"
|
|
37
|
+
});
|
|
38
|
+
const config = {
|
|
39
|
+
serverKeys: options.serverKeys,
|
|
40
|
+
jwtSecret: options.jwtSecret,
|
|
41
|
+
jwtExpirationSeconds: options.jwtExpirationSeconds ?? 86400,
|
|
42
|
+
allowedOrigins: options.allowedOrigins ?? ["*"],
|
|
43
|
+
googleClientId: options.googleClientId,
|
|
44
|
+
deps: {
|
|
45
|
+
storage,
|
|
46
|
+
logger: console,
|
|
47
|
+
credentialClient: client,
|
|
48
|
+
proxyClient: client
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return new WalletServerCore(config);
|
|
52
|
+
}
|
|
53
|
+
async function generateBrowserServerKeys() {
|
|
54
|
+
const identityKeyPair = await crypto.subtle.generateKey(
|
|
55
|
+
"Ed25519",
|
|
56
|
+
true,
|
|
57
|
+
["sign", "verify"]
|
|
58
|
+
);
|
|
59
|
+
const encryptionKeyPair = await crypto.subtle.generateKey(
|
|
60
|
+
{ name: "X25519", namedCurve: "X25519" },
|
|
61
|
+
true,
|
|
62
|
+
["deriveBits"]
|
|
63
|
+
);
|
|
64
|
+
const identityPrivateKeyBuffer = await crypto.subtle.exportKey(
|
|
65
|
+
"pkcs8",
|
|
66
|
+
identityKeyPair.privateKey
|
|
67
|
+
);
|
|
68
|
+
const identityPublicKeyBuffer = await crypto.subtle.exportKey(
|
|
69
|
+
"raw",
|
|
70
|
+
identityKeyPair.publicKey
|
|
71
|
+
);
|
|
72
|
+
const encryptionPrivateKeyBuffer = await crypto.subtle.exportKey(
|
|
73
|
+
"pkcs8",
|
|
74
|
+
encryptionKeyPair.privateKey
|
|
75
|
+
);
|
|
76
|
+
const encryptionPublicKeyBuffer = await crypto.subtle.exportKey(
|
|
77
|
+
"raw",
|
|
78
|
+
encryptionKeyPair.publicKey
|
|
79
|
+
);
|
|
80
|
+
const bytesToBase64 = (bytes) => btoa(String.fromCharCode(...bytes));
|
|
81
|
+
const bytesToHex = (bytes) => Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
82
|
+
const toPem = (buffer) => {
|
|
83
|
+
const base64 = bytesToBase64(new Uint8Array(buffer));
|
|
84
|
+
return `-----BEGIN PRIVATE KEY-----
|
|
85
|
+
${base64.match(/.{1,64}/g)?.join("\n")}
|
|
86
|
+
-----END PRIVATE KEY-----`;
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
identityKey: {
|
|
90
|
+
privateKeyPem: toPem(identityPrivateKeyBuffer),
|
|
91
|
+
publicKeyHex: bytesToHex(new Uint8Array(identityPublicKeyBuffer))
|
|
92
|
+
},
|
|
93
|
+
encryptionKey: {
|
|
94
|
+
privateKeyPem: toPem(encryptionPrivateKeyBuffer),
|
|
95
|
+
publicKeyHex: bytesToHex(new Uint8Array(encryptionPublicKeyBuffer))
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
ConfigEnvironment as BrowserEnvironment,
|
|
101
|
+
BrowserLocalStorageFileStorage,
|
|
102
|
+
MemoryFileStorage as BrowserMemoryStorage,
|
|
103
|
+
createBrowserWalletServer,
|
|
104
|
+
generateBrowserServerKeys
|
|
105
|
+
};
|