@opendatalabs/vana-sdk 0.1.0-alpha.82bbb39 → 0.1.0-alpha.899ca9d

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.
Files changed (50) hide show
  1. package/README.md +42 -0
  2. package/dist/browser-DY8XDblx.d.ts +241 -0
  3. package/dist/browser.d.ts +1 -0
  4. package/dist/browser.js +309 -0
  5. package/dist/browser.js.map +1 -0
  6. package/dist/chains.browser.cjs +2 -2
  7. package/dist/chains.browser.cjs.map +1 -1
  8. package/dist/chains.browser.js +2 -2
  9. package/dist/chains.browser.js.map +1 -1
  10. package/dist/chains.cjs +2 -2
  11. package/dist/chains.cjs.map +1 -1
  12. package/dist/chains.js +2 -2
  13. package/dist/chains.js.map +1 -1
  14. package/dist/chains.node.cjs +2 -2
  15. package/dist/chains.node.cjs.map +1 -1
  16. package/dist/chains.node.js +2 -2
  17. package/dist/chains.node.js.map +1 -1
  18. package/dist/index.browser.d.ts +1756 -1479
  19. package/dist/index.browser.js +37686 -35103
  20. package/dist/index.browser.js.map +1 -1
  21. package/dist/index.node.cjs +38174 -35582
  22. package/dist/index.node.cjs.map +1 -1
  23. package/dist/index.node.d.cts +1790 -1486
  24. package/dist/index.node.d.ts +1790 -1486
  25. package/dist/index.node.js +38402 -35813
  26. package/dist/index.node.js.map +1 -1
  27. package/dist/node-D9-F9uEP.d.cts +238 -0
  28. package/dist/node-D9-F9uEP.d.ts +238 -0
  29. package/dist/node.cjs +348 -0
  30. package/dist/node.cjs.map +1 -0
  31. package/dist/node.d.cts +1 -0
  32. package/dist/node.d.ts +1 -0
  33. package/dist/node.js +311 -0
  34. package/dist/node.js.map +1 -0
  35. package/dist/platform.browser.d.ts +3 -236
  36. package/dist/platform.browser.js +31 -8
  37. package/dist/platform.browser.js.map +1 -1
  38. package/dist/platform.cjs +72 -62
  39. package/dist/platform.cjs.map +1 -1
  40. package/dist/platform.d.cts +2 -1
  41. package/dist/platform.d.ts +2 -1
  42. package/dist/platform.js +72 -62
  43. package/dist/platform.js.map +1 -1
  44. package/dist/platform.node.cjs +72 -62
  45. package/dist/platform.node.cjs.map +1 -1
  46. package/dist/platform.node.d.cts +7 -236
  47. package/dist/platform.node.d.ts +7 -236
  48. package/dist/platform.node.js +72 -62
  49. package/dist/platform.node.js.map +1 -1
  50. package/package.json +17 -12
package/dist/node.js ADDED
@@ -0,0 +1,311 @@
1
+ // src/platform/shared/crypto-utils.ts
2
+ function processWalletPublicKey(publicKey) {
3
+ const publicKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
4
+ const publicKeyBytes = Buffer.from(publicKeyHex, "hex");
5
+ return publicKeyBytes.length === 64 ? Buffer.concat([Buffer.from([4]), publicKeyBytes]) : publicKeyBytes;
6
+ }
7
+ function processWalletPrivateKey(privateKey) {
8
+ const privateKeyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
9
+ return Buffer.from(privateKeyHex, "hex");
10
+ }
11
+ function parseEncryptedDataBuffer(encryptedBuffer) {
12
+ return {
13
+ iv: encryptedBuffer.slice(0, 16),
14
+ ephemPublicKey: encryptedBuffer.slice(16, 81),
15
+ // 65 bytes for uncompressed public key
16
+ ciphertext: encryptedBuffer.slice(81, -32),
17
+ mac: encryptedBuffer.slice(-32)
18
+ };
19
+ }
20
+
21
+ // src/platform/shared/pgp-utils.ts
22
+ var STANDARD_PGP_CONFIG = {
23
+ preferredCompressionAlgorithm: 2,
24
+ // zlib (openpgp.enums.compression.zlib)
25
+ preferredSymmetricAlgorithm: 7
26
+ // aes256 (openpgp.enums.symmetric.aes256)
27
+ };
28
+ function processPGPKeyOptions(options) {
29
+ return {
30
+ name: options?.name || "Vana User",
31
+ email: options?.email || "user@vana.org",
32
+ passphrase: options?.passphrase
33
+ };
34
+ }
35
+ function getPGPKeyGenParams(options) {
36
+ const { name, email, passphrase } = processPGPKeyOptions(options);
37
+ return {
38
+ type: "rsa",
39
+ rsaBits: 2048,
40
+ userIDs: [{ name, email }],
41
+ passphrase,
42
+ config: STANDARD_PGP_CONFIG
43
+ };
44
+ }
45
+
46
+ // src/platform/shared/error-utils.ts
47
+ function wrapCryptoError(operation, error) {
48
+ const message = error instanceof Error ? error.message : "Unknown error";
49
+ return new Error(`${operation} failed: ${message}`);
50
+ }
51
+
52
+ // src/platform/shared/stream-utils.ts
53
+ async function streamToUint8Array(stream) {
54
+ const reader = stream.getReader();
55
+ const chunks = [];
56
+ try {
57
+ while (true) {
58
+ const { done, value } = await reader.read();
59
+ if (done) break;
60
+ chunks.push(value);
61
+ }
62
+ } finally {
63
+ reader.releaseLock();
64
+ }
65
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
66
+ const result = new Uint8Array(totalLength);
67
+ let offset = 0;
68
+ for (const chunk of chunks) {
69
+ result.set(chunk, offset);
70
+ offset += chunk.length;
71
+ }
72
+ return result;
73
+ }
74
+
75
+ // src/utils/lazy-import.ts
76
+ function lazyImport(importFn) {
77
+ let cached = null;
78
+ return () => {
79
+ if (!cached) {
80
+ cached = importFn().catch((err) => {
81
+ cached = null;
82
+ throw new Error("Failed to load module", { cause: err });
83
+ });
84
+ }
85
+ return cached;
86
+ };
87
+ }
88
+
89
+ // src/platform/node.ts
90
+ var getOpenPGP = lazyImport(() => import("openpgp"));
91
+ var getEccrypto = lazyImport(() => import("eccrypto"));
92
+ var NodeCryptoAdapter = class {
93
+ async encryptWithPublicKey(data, publicKeyHex) {
94
+ try {
95
+ const eccrypto = await getEccrypto();
96
+ const publicKey = Buffer.from(publicKeyHex, "hex");
97
+ const message = Buffer.from(data, "utf8");
98
+ const encrypted = await eccrypto.encrypt(publicKey, message);
99
+ const result = Buffer.concat([
100
+ encrypted.iv,
101
+ encrypted.ephemPublicKey,
102
+ encrypted.ciphertext,
103
+ encrypted.mac
104
+ ]);
105
+ return result.toString("hex");
106
+ } catch (error) {
107
+ throw new Error(`Encryption failed: ${error}`);
108
+ }
109
+ }
110
+ async decryptWithPrivateKey(encryptedData, privateKeyHex) {
111
+ try {
112
+ const eccrypto = await getEccrypto();
113
+ const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
114
+ const encryptedBuffer = Buffer.from(encryptedData, "hex");
115
+ const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
116
+ const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
117
+ const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
118
+ return decrypted.toString("utf8");
119
+ } catch (error) {
120
+ throw new Error(`Decryption failed: ${error}`);
121
+ }
122
+ }
123
+ async generateKeyPair() {
124
+ try {
125
+ const eccrypto = await getEccrypto();
126
+ const privateKey = eccrypto.generatePrivate();
127
+ const publicKey = eccrypto.getPublicCompressed(privateKey);
128
+ return {
129
+ privateKey: privateKey.toString("hex"),
130
+ publicKey: publicKey.toString("hex")
131
+ };
132
+ } catch (error) {
133
+ throw wrapCryptoError("key generation", error);
134
+ }
135
+ }
136
+ async encryptWithWalletPublicKey(data, publicKey) {
137
+ try {
138
+ const eccrypto = await getEccrypto();
139
+ const uncompressedKey = processWalletPublicKey(publicKey);
140
+ const encrypted = await eccrypto.encrypt(
141
+ uncompressedKey,
142
+ Buffer.from(data)
143
+ );
144
+ const result = Buffer.concat([
145
+ encrypted.iv,
146
+ encrypted.ephemPublicKey,
147
+ encrypted.ciphertext,
148
+ encrypted.mac
149
+ ]);
150
+ return result.toString("hex");
151
+ } catch (error) {
152
+ throw wrapCryptoError("encrypt with wallet public key", error);
153
+ }
154
+ }
155
+ async decryptWithWalletPrivateKey(encryptedData, privateKey) {
156
+ try {
157
+ const eccrypto = await getEccrypto();
158
+ const privateKeyBuffer = processWalletPrivateKey(privateKey);
159
+ const encryptedBuffer = Buffer.from(encryptedData, "hex");
160
+ const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
161
+ const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
162
+ const decryptedBuffer = await eccrypto.decrypt(
163
+ privateKeyBuffer,
164
+ encryptedObj
165
+ );
166
+ return decryptedBuffer.toString("utf8");
167
+ } catch (error) {
168
+ throw wrapCryptoError("decrypt with wallet private key", error);
169
+ }
170
+ }
171
+ async encryptWithPassword(data, password) {
172
+ try {
173
+ const openpgp = await getOpenPGP();
174
+ const message = await openpgp.createMessage({
175
+ binary: data
176
+ });
177
+ const encrypted = await openpgp.encrypt({
178
+ message,
179
+ passwords: [password],
180
+ format: "binary"
181
+ });
182
+ if (encrypted instanceof Uint8Array) {
183
+ return encrypted;
184
+ }
185
+ if (encrypted && typeof encrypted === "object" && "getReader" in encrypted) {
186
+ return await streamToUint8Array(
187
+ encrypted
188
+ );
189
+ }
190
+ throw new Error("Unexpected encrypted data format");
191
+ } catch (error) {
192
+ throw wrapCryptoError("encrypt with password", error);
193
+ }
194
+ }
195
+ async decryptWithPassword(encryptedData, password) {
196
+ try {
197
+ const openpgp = await getOpenPGP();
198
+ const message = await openpgp.readMessage({
199
+ binaryMessage: encryptedData
200
+ });
201
+ const { data: decrypted } = await openpgp.decrypt({
202
+ message,
203
+ passwords: [password],
204
+ format: "binary"
205
+ });
206
+ return new Uint8Array(decrypted);
207
+ } catch (error) {
208
+ throw wrapCryptoError("decrypt with password", error);
209
+ }
210
+ }
211
+ };
212
+ var NodePGPAdapter = class {
213
+ async encrypt(data, publicKeyArmored) {
214
+ try {
215
+ const openpgp = await getOpenPGP();
216
+ const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
217
+ const encrypted = await openpgp.encrypt({
218
+ message: await openpgp.createMessage({ text: data }),
219
+ encryptionKeys: publicKey,
220
+ config: {
221
+ preferredCompressionAlgorithm: openpgp.enums.compression.zlib
222
+ }
223
+ });
224
+ return encrypted;
225
+ } catch (error) {
226
+ throw wrapCryptoError("PGP encryption", error);
227
+ }
228
+ }
229
+ async decrypt(encryptedData, privateKeyArmored) {
230
+ try {
231
+ const openpgp = await getOpenPGP();
232
+ const privateKey = await openpgp.readPrivateKey({
233
+ armoredKey: privateKeyArmored
234
+ });
235
+ const message = await openpgp.readMessage({
236
+ armoredMessage: encryptedData
237
+ });
238
+ const { data: decrypted } = await openpgp.decrypt({
239
+ message,
240
+ decryptionKeys: privateKey
241
+ });
242
+ return decrypted;
243
+ } catch (error) {
244
+ throw wrapCryptoError("PGP decryption", error);
245
+ }
246
+ }
247
+ async generateKeyPair(options) {
248
+ try {
249
+ const openpgp = await getOpenPGP();
250
+ const keyGenParams = getPGPKeyGenParams(options);
251
+ const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
252
+ return { publicKey, privateKey };
253
+ } catch (error) {
254
+ throw wrapCryptoError("PGP key generation", error);
255
+ }
256
+ }
257
+ };
258
+ var NodeHttpAdapter = class {
259
+ async fetch(url, options) {
260
+ if (typeof globalThis.fetch !== "undefined") {
261
+ return globalThis.fetch(url, options);
262
+ }
263
+ throw new Error("No fetch implementation available in Node.js environment");
264
+ }
265
+ };
266
+ var NodeCacheAdapter = class {
267
+ cache = /* @__PURE__ */ new Map();
268
+ defaultTtl = 2 * 60 * 60 * 1e3;
269
+ // 2 hours in milliseconds
270
+ get(key) {
271
+ const entry = this.cache.get(key);
272
+ if (!entry) {
273
+ return null;
274
+ }
275
+ if (Date.now() > entry.expires) {
276
+ this.cache.delete(key);
277
+ return null;
278
+ }
279
+ return entry.value;
280
+ }
281
+ set(key, value) {
282
+ this.cache.set(key, {
283
+ value,
284
+ expires: Date.now() + this.defaultTtl
285
+ });
286
+ }
287
+ delete(key) {
288
+ this.cache.delete(key);
289
+ }
290
+ clear() {
291
+ this.cache.clear();
292
+ }
293
+ };
294
+ var NodePlatformAdapter = class {
295
+ crypto;
296
+ pgp;
297
+ http;
298
+ cache;
299
+ platform = "node";
300
+ constructor() {
301
+ this.crypto = new NodeCryptoAdapter();
302
+ this.pgp = new NodePGPAdapter();
303
+ this.http = new NodeHttpAdapter();
304
+ this.cache = new NodeCacheAdapter();
305
+ }
306
+ };
307
+ var nodePlatformAdapter = new NodePlatformAdapter();
308
+ export {
309
+ NodePlatformAdapter
310
+ };
311
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/platform/shared/crypto-utils.ts","../src/platform/shared/pgp-utils.ts","../src/platform/shared/error-utils.ts","../src/platform/shared/stream-utils.ts","../src/utils/lazy-import.ts","../src/platform/node.ts"],"sourcesContent":["/**\n * Shared crypto utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Process wallet public key for encryption operations\n * Removes 0x prefix and ensures uncompressed format (65 bytes with 0x04 prefix)\n *\n * @param publicKey The public key (with or without 0x prefix)\n * @returns Buffer containing uncompressed public key\n */\nexport function processWalletPublicKey(publicKey: string): Buffer {\n const publicKeyHex = publicKey.startsWith(\"0x\")\n ? publicKey.slice(2)\n : publicKey;\n const publicKeyBytes = Buffer.from(publicKeyHex, \"hex\");\n\n // Ensure public key is in uncompressed format (65 bytes with 0x04 prefix)\n // If it's 64 bytes, add the 0x04 prefix; if already 65 bytes, use as-is\n return publicKeyBytes.length === 64\n ? Buffer.concat([Buffer.from([4]), publicKeyBytes])\n : publicKeyBytes;\n}\n\n/**\n * Process wallet private key for decryption operations\n * Removes 0x prefix and converts to Buffer\n *\n * @param privateKey The private key (with or without 0x prefix)\n * @returns Buffer containing private key\n */\nexport function processWalletPrivateKey(privateKey: string): Buffer {\n const privateKeyHex = privateKey.startsWith(\"0x\")\n ? privateKey.slice(2)\n : privateKey;\n return Buffer.from(privateKeyHex, \"hex\");\n}\n\n/**\n * Parse encrypted data buffer into components\n * Extracts IV, ephemeral public key, ciphertext, and MAC from a concatenated buffer\n *\n * @param encryptedBuffer The buffer containing encrypted data\n * @returns Object with parsed components\n */\nexport function parseEncryptedDataBuffer(encryptedBuffer: Buffer) {\n return {\n iv: encryptedBuffer.slice(0, 16),\n ephemPublicKey: encryptedBuffer.slice(16, 81), // 65 bytes for uncompressed public key\n ciphertext: encryptedBuffer.slice(81, -32),\n mac: encryptedBuffer.slice(-32),\n };\n}\n\n/**\n * Convert hex string to Uint8Array\n *\n * @param hex The hex string to convert\n * @returns Uint8Array representation\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n const result = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n result[i / 2] = parseInt(hex.substr(i, 2), 16);\n }\n return result;\n}\n\n/**\n * Convert Uint8Array to hex string\n *\n * @param array The Uint8Array to convert\n * @returns Hex string representation\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return Array.from(array, (byte) => byte.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n}\n\n/**\n * Cross-platform base64 encoding\n * Works in both Node.js and browser environments\n *\n * @param str The string to encode\n * @returns Base64 encoded string\n */\nexport function toBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"utf8\").toString(\"base64\");\n } else if (typeof btoa !== \"undefined\") {\n // Browser environment\n return btoa(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n while (i < str.length) {\n const a = str.charCodeAt(i++);\n const b = i < str.length ? str.charCodeAt(i++) : 0;\n const c = i < str.length ? str.charCodeAt(i++) : 0;\n\n const bitmap = (a << 16) | (b << 8) | c;\n\n result += chars.charAt((bitmap >> 18) & 63);\n result += chars.charAt((bitmap >> 12) & 63);\n result += i - 2 < str.length ? chars.charAt((bitmap >> 6) & 63) : \"=\";\n result += i - 1 < str.length ? chars.charAt(bitmap & 63) : \"=\";\n }\n return result;\n }\n}\n\n/**\n * Cross-platform base64 decoding\n * Works in both Node.js and browser environments\n *\n * @param str The base64 string to decode\n * @returns Decoded string\n */\nexport function fromBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"base64\").toString(\"utf8\");\n } else if (typeof atob !== \"undefined\") {\n // Browser environment\n return atob(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n\n // Remove any characters not in the base64 character set\n str = str.replace(/[^A-Za-z0-9+/]/g, \"\");\n\n while (i < str.length) {\n const encoded1 = chars.indexOf(str.charAt(i++));\n const encoded2 = chars.indexOf(str.charAt(i++));\n const encoded3 = chars.indexOf(str.charAt(i++));\n const encoded4 = chars.indexOf(str.charAt(i++));\n\n const bitmap =\n (encoded1 << 18) | (encoded2 << 12) | (encoded3 << 6) | encoded4;\n\n result += String.fromCharCode((bitmap >> 16) & 255);\n if (encoded3 !== 64) result += String.fromCharCode((bitmap >> 8) & 255);\n if (encoded4 !== 64) result += String.fromCharCode(bitmap & 255);\n }\n return result;\n }\n}\n","/**\n * Shared PGP utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Standard OpenPGP configuration for consistent behavior across platforms\n * Uses enum values instead of importing openpgp to avoid loading issues\n */\nexport const STANDARD_PGP_CONFIG = {\n preferredCompressionAlgorithm: 2, // zlib (openpgp.enums.compression.zlib)\n preferredSymmetricAlgorithm: 7, // aes256 (openpgp.enums.symmetric.aes256)\n} as const;\n\n/**\n * Process PGP key generation options with sensible defaults\n *\n * @param options - Optional key generation parameters\n * @param options.name - The name for the PGP key (defaults to \"Vana User\")\n * @param options.email - The email for the PGP key (defaults to \"user@vana.org\")\n * @param options.passphrase - Optional passphrase to protect the private key\n * @returns Processed options with defaults applied\n */\nexport function processPGPKeyOptions(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n}) {\n return {\n name: options?.name || \"Vana User\",\n email: options?.email || \"user@vana.org\",\n passphrase: options?.passphrase,\n };\n}\n\n/**\n * Get standard PGP key generation parameters\n * Combines default values with standard configuration\n *\n * @param options - Optional key generation parameters\n * @param options.name - The name for the PGP key (defaults to \"Vana User\")\n * @param options.email - The email for the PGP key (defaults to \"user@vana.org\")\n * @param options.passphrase - Optional passphrase to protect the private key\n * @returns Complete key generation parameters object\n */\nexport function getPGPKeyGenParams(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n}) {\n const { name, email, passphrase } = processPGPKeyOptions(options);\n\n return {\n type: \"rsa\" as const,\n rsaBits: 2048,\n userIDs: [{ name, email }],\n passphrase,\n config: STANDARD_PGP_CONFIG,\n };\n}\n","/**\n * Shared error utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Wrap platform-specific errors with consistent messaging\n * Provides consistent error formatting across all crypto operations\n *\n * @param operation The operation that failed (e.g., \"encryption\", \"decryption\")\n * @param error The original error that occurred\n * @returns Wrapped error with consistent format\n */\nexport function wrapCryptoError(operation: string, error: unknown): Error {\n const message = error instanceof Error ? error.message : \"Unknown error\";\n return new Error(`${operation} failed: ${message}`);\n}\n\n/**\n * Validate encrypted data structure has required fields\n * Ensures encrypted data objects contain the expected properties\n *\n * @param data The data structure to validate\n * @throws Error if data structure is invalid\n */\nexport function validateEncryptedDataStructure(data: unknown): void {\n if (!data || typeof data !== \"object\") {\n throw new Error(\"Invalid encrypted data format\");\n }\n\n const obj = data as Record<string, unknown>;\n if (!obj.encrypted || !obj.iv || !obj.ephemeralPublicKey) {\n throw new Error(\"Invalid encrypted data format\");\n }\n}\n","/**\n * Shared stream utilities for platform adapters\n *\n * IMPORTANT: This module contains NO IMPORTS to avoid affecting bundle loading.\n * All functions are pure utilities that can be safely shared across platforms.\n */\n\n/**\n * Convert ReadableStream to Uint8Array\n * Used primarily in Node.js environment where OpenPGP may return streams\n *\n * @param stream The ReadableStream to convert\n * @returns Promise resolving to Uint8Array containing all stream data\n */\nexport async function streamToUint8Array(\n stream: ReadableStream<Uint8Array>,\n): Promise<Uint8Array> {\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n // Concatenate all chunks\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n\n return result;\n}\n","/**\n * Utility for lazy-loading modules to avoid Turbopack TDZ issues\n *\n * WARNING: This is a workaround for Turbopack's strict module initialization.\n * Dependencies that access globals during init must be dynamically imported.\n */\n\n/**\n * Creates a lazy import function that caches the promise (not the module)\n * to avoid race conditions on concurrent first calls\n *\n * @param importFn - Function that returns a dynamic import promise\n * @returns Function that returns the cached import promise\n *\n * @example\n * const getOpenPGP = lazyImport(() => import('openpgp'));\n * const openpgp = await getOpenPGP();\n */\nexport function lazyImport<T>(importFn: () => Promise<T>): () => Promise<T> {\n let cached: Promise<T> | null = null;\n\n return () => {\n if (!cached) {\n cached = importFn().catch((err) => {\n // Clear cache on error so next attempt can retry\n cached = null;\n throw new Error(\"Failed to load module\", { cause: err });\n });\n }\n return cached;\n };\n}\n","/**\n * Node.js implementation of the Vana Platform Adapter\n *\n * WARNING: Dependencies that access globals during init\n * MUST be dynamically imported to support Turbopack.\n * See: https://github.com/vercel/next.js/issues/82632\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\n} from \"./interface\";\nimport {\n processWalletPublicKey,\n processWalletPrivateKey,\n parseEncryptedDataBuffer,\n} from \"./shared/crypto-utils\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\nconst getEccrypto = lazyImport(() => import(\"eccrypto\"));\n\n/**\n * Node.js implementation of crypto operations using secp256k1\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n const eccrypto = await getEccrypto();\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccrypto.encrypt(publicKey, message);\n\n // Concatenate all components and return as hex string for API consistency\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } catch (error) {\n throw new Error(`Encryption failed: ${error}`);\n }\n }\n\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n const eccrypto = await getEccrypto();\n\n // Use shared utilities to process keys and parse data\n const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure for eccrypto\n const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };\n\n const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);\n return decrypted.toString(\"utf8\");\n } catch (error) {\n throw new Error(`Decryption failed: ${error}`);\n }\n }\n\n async generateKeyPair(): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const eccrypto = await getEccrypto();\n const privateKey = eccrypto.generatePrivate();\n const publicKey = eccrypto.getPublicCompressed(privateKey);\n\n return {\n privateKey: privateKey.toString(\"hex\"),\n publicKey: publicKey.toString(\"hex\"),\n };\n } catch (error) {\n throw wrapCryptoError(\"key generation\", error);\n }\n }\n\n async encryptWithWalletPublicKey(\n data: string,\n publicKey: string,\n ): Promise<string> {\n try {\n const eccrypto = await getEccrypto();\n\n // Use shared utility to process public key\n const uncompressedKey = processWalletPublicKey(publicKey);\n\n const encrypted = await eccrypto.encrypt(\n uncompressedKey,\n Buffer.from(data),\n );\n\n // Concatenate all components and return as hex (same format as browser)\n const result = Buffer.concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return result.toString(\"hex\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with wallet public key\", error);\n }\n }\n\n async decryptWithWalletPrivateKey(\n encryptedData: string,\n privateKey: string,\n ): Promise<string> {\n try {\n const eccrypto = await getEccrypto();\n\n // Use shared utilities to process keys and parse data\n const privateKeyBuffer = processWalletPrivateKey(privateKey);\n const encryptedBuffer = Buffer.from(encryptedData, \"hex\");\n const { iv, ephemPublicKey, ciphertext, mac } =\n parseEncryptedDataBuffer(encryptedBuffer);\n\n // Reconstruct the encrypted data structure for eccrypto\n const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };\n\n // Decrypt using ECDH\n const decryptedBuffer = await eccrypto.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n\n return decryptedBuffer.toString(\"utf8\");\n } catch (error) {\n throw wrapCryptoError(\"decrypt with wallet private key\", error);\n }\n }\n\n async encryptWithPassword(\n data: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n const message = await openpgp.createMessage({\n binary: data,\n });\n\n // Use password-based encryption with wallet signature as password\n // Note: For deterministic encryption, we would need to control the salt\n // This implementation is secure but not deterministic due to OpenPGP's design\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // In Node.js, the encrypted result is already a Uint8Array\n if (encrypted instanceof Uint8Array) {\n return encrypted;\n }\n\n // If it's a stream (should not happen with format: \"binary\"), read it\n if (\n encrypted &&\n typeof encrypted === \"object\" &&\n \"getReader\" in encrypted\n ) {\n return await streamToUint8Array(\n encrypted as ReadableStream<Uint8Array>,\n );\n }\n\n throw new Error(\"Unexpected encrypted data format\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with password\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Use password-based decryption with wallet signature as password\n const { data: decrypted } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n // Convert decrypted data back to Uint8Array\n return new Uint8Array(decrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decrypt with password\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of PGP operations using openpgp with Node-specific configuration\n */\nclass NodePGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });\n\n const encrypted = await openpgp.encrypt({\n message: await openpgp.createMessage({ text: data }),\n encryptionKeys: publicKey,\n config: {\n preferredCompressionAlgorithm: openpgp.enums.compression.zlib,\n },\n });\n\n return encrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP encryption\", error);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\n const privateKey = await openpgp.readPrivateKey({\n armoredKey: privateKeyArmored,\n });\n const message = await openpgp.readMessage({\n armoredMessage: encryptedData,\n });\n\n const { data: decrypted } = await openpgp.decrypt({\n message,\n decryptionKeys: privateKey,\n });\n\n return decrypted as string;\n } catch (error) {\n throw wrapCryptoError(\"PGP decryption\", error);\n }\n }\n\n async generateKeyPair(options?: {\n name?: string;\n email?: string;\n passphrase?: string;\n }): Promise<{ publicKey: string; privateKey: string }> {\n try {\n const openpgp = await getOpenPGP();\n // Use shared utility to get standardized parameters\n const keyGenParams = getPGPKeyGenParams(options);\n\n const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);\n\n return { publicKey, privateKey };\n } catch (error) {\n throw wrapCryptoError(\"PGP key generation\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of HTTP operations using node-fetch or native fetch\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch(url, options);\n }\n\n throw new Error(\"No fetch implementation available in Node.js environment\");\n }\n}\n\n/**\n * Node.js implementation of cache operations using in-memory Map with TTL\n */\nclass NodeCacheAdapter implements VanaCacheAdapter {\n private cache = new Map<string, { value: string; expires: number }>();\n private readonly defaultTtl = 2 * 60 * 60 * 1000; // 2 hours in milliseconds\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string): void {\n this.cache.set(key, {\n value,\n expires: Date.now() + this.defaultTtl,\n });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Complete Node.js platform adapter implementation\n */\nexport class NodePlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n cache: VanaCacheAdapter;\n platform: \"node\" = \"node\" as const;\n\n constructor() {\n this.crypto = new NodeCryptoAdapter();\n this.pgp = new NodePGPAdapter();\n this.http = new NodeHttpAdapter();\n this.cache = new NodeCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const nodePlatformAdapter: VanaPlatformAdapter =\n new NodePlatformAdapter();\n"],"mappings":";AAcO,SAAS,uBAAuB,WAA2B;AAChE,QAAM,eAAe,UAAU,WAAW,IAAI,IAC1C,UAAU,MAAM,CAAC,IACjB;AACJ,QAAM,iBAAiB,OAAO,KAAK,cAAc,KAAK;AAItD,SAAO,eAAe,WAAW,KAC7B,OAAO,OAAO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,EAC/C,MAAM,MAAM,KAAa,SAA0C;AACjE,QAAI,OAAO,WAAW,UAAU,aAAa;AAC3C,aAAO,WAAW,MAAM,KAAK,OAAO;AAAA,IACtC;AAEA,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AACF;AAKA,IAAM,mBAAN,MAAmD;AAAA,EACzC,QAAQ,oBAAI,IAAgD;AAAA,EACnD,aAAa,IAAI,KAAK,KAAK;AAAA;AAAA,EAE5C,IAAI,KAA4B;AAC9B,UAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;AAChC,QAAI,CAAC,OAAO;AACV,aAAO;AAAA,IACT;AAGA,QAAI,KAAK,IAAI,IAAI,MAAM,SAAS;AAC9B,WAAK,MAAM,OAAO,GAAG;AACrB,aAAO;AAAA,IACT;AAEA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,IAAI,KAAa,OAAqB;AACpC,SAAK,MAAM,IAAI,KAAK;AAAA,MAClB;AAAA,MACA,SAAS,KAAK,IAAI,IAAI,KAAK;AAAA,IAC7B,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,KAAmB;AACxB,SAAK,MAAM,OAAO,GAAG;AAAA,EACvB;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AACF;AAKO,IAAM,sBAAN,MAAyD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAmB;AAAA,EAEnB,cAAc;AACZ,SAAK,SAAS,IAAI,kBAAkB;AACpC,SAAK,MAAM,IAAI,eAAe;AAC9B,SAAK,OAAO,IAAI,gBAAgB;AAChC,SAAK,QAAQ,IAAI,iBAAiB;AAAA,EACpC;AACF;AAKO,IAAM,sBACX,IAAI,oBAAoB;","names":[]}
@@ -1,238 +1,5 @@
1
- /**
2
- * Platform Adapter interface for environment-specific implementations
3
- *
4
- * This interface abstracts all environment-specific dependencies to ensure
5
- * the SDK works seamlessly across Node.js and browser/SSR environments.
6
- *
7
- * **Implementation Context:**
8
- * - Node.js: Uses native crypto modules and full OpenPGP support
9
- * - Browser: Uses Web Crypto API and browser-compatible libraries
10
- * - SSR: Automatically selects appropriate implementation based on runtime
11
- *
12
- * **Usage Notes:**
13
- * Platform adapters are automatically selected by the SDK. Direct usage is only
14
- * needed for custom implementations or testing.
15
- */
16
- /**
17
- * Platform type identifier
18
- */
19
- type PlatformType = "node" | "browser";
20
- /**
21
- * Encryption operations that require different implementations per platform
22
- */
23
- interface VanaCryptoAdapter {
24
- /**
25
- * Encrypt data with a public key using asymmetric cryptography
26
- *
27
- * **Usage Context:**
28
- * - Used internally for file encryption before storage
29
- * - Public key format: Armored PGP public key string
30
- * - Returns base64-encoded encrypted data
31
- *
32
- * @param data The data to encrypt
33
- * @param publicKey The public key for encryption
34
- * @returns Promise resolving to encrypted data
35
- */
36
- encryptWithPublicKey(data: string, publicKey: string): Promise<string>;
37
- /**
38
- * Decrypt data with a private key using asymmetric cryptography
39
- *
40
- * @param encryptedData The encrypted data
41
- * @param privateKey The private key for decryption
42
- * @returns Promise resolving to decrypted data
43
- */
44
- decryptWithPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
45
- /**
46
- * Generate a new key pair for asymmetric cryptography
47
- *
48
- * @returns Promise resolving to public and private key pair
49
- */
50
- generateKeyPair(): Promise<{
51
- publicKey: string;
52
- privateKey: string;
53
- }>;
54
- /**
55
- * Encrypt data with a wallet's public key using ECDH cryptography
56
- * Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
57
- *
58
- * **Usage Context:**
59
- * - Used for sharing encryption keys with permission recipients
60
- * - Public key format: Compressed or uncompressed secp256k1 hex string
61
- * - Compatible with Ethereum wallet public keys
62
- *
63
- * @param data The data to encrypt (string)
64
- * @param publicKey The wallet's public key (secp256k1)
65
- * @returns Promise resolving to encrypted data as hex string
66
- */
67
- encryptWithWalletPublicKey(data: string, publicKey: string): Promise<string>;
68
- /**
69
- * Decrypt data with a wallet's private key using ECDH cryptography
70
- * Uses platform-appropriate ECDH implementation (eccrypto vs eccrypto-js)
71
- *
72
- * @param encryptedData The encrypted data as hex string
73
- * @param privateKey The wallet's private key (secp256k1)
74
- * @returns Promise resolving to decrypted data as string
75
- */
76
- decryptWithWalletPrivateKey(encryptedData: string, privateKey: string): Promise<string>;
77
- /**
78
- * Encrypt data with a password using PGP password-based encryption
79
- * Uses platform-appropriate OpenPGP implementation with consistent format
80
- *
81
- * @param data The data to encrypt as Uint8Array
82
- * @param password The password for encryption (typically wallet signature)
83
- * @returns Promise resolving to encrypted data as Uint8Array
84
- */
85
- encryptWithPassword(data: Uint8Array, password: string): Promise<Uint8Array>;
86
- /**
87
- * Decrypt data with a password using PGP password-based decryption
88
- * Uses platform-appropriate OpenPGP implementation with consistent format
89
- *
90
- * @param encryptedData The encrypted data as Uint8Array
91
- * @param password The password for decryption (typically wallet signature)
92
- * @returns Promise resolving to decrypted data as Uint8Array
93
- */
94
- decryptWithPassword(encryptedData: Uint8Array, password: string): Promise<Uint8Array>;
95
- }
96
- /**
97
- * PGP operations that require different configurations per platform
98
- */
99
- interface VanaPGPAdapter {
100
- /**
101
- * Encrypt data using PGP with proper platform configuration
102
- *
103
- * @param data The data to encrypt
104
- * @param publicKey The PGP public key
105
- * @returns Promise resolving to encrypted data
106
- */
107
- encrypt(data: string, publicKey: string): Promise<string>;
108
- /**
109
- * Decrypt data using PGP with proper platform configuration
110
- *
111
- * @param encryptedData The encrypted data
112
- * @param privateKey The PGP private key
113
- * @returns Promise resolving to decrypted data
114
- */
115
- decrypt(encryptedData: string, privateKey: string): Promise<string>;
116
- /**
117
- * Generate a new PGP key pair with platform-appropriate configuration
118
- *
119
- * @param options - Key generation options
120
- * @param options.name - The name for the PGP key
121
- * @param options.email - The email for the PGP key
122
- * @param options.passphrase - Optional passphrase to protect the private key
123
- * @returns Promise resolving to public and private key pair
124
- */
125
- generateKeyPair(options?: {
126
- name?: string;
127
- email?: string;
128
- passphrase?: string;
129
- }): Promise<{
130
- publicKey: string;
131
- privateKey: string;
132
- }>;
133
- }
134
- /**
135
- * HTTP operations that need consistent API across platforms
136
- */
137
- interface VanaHttpAdapter {
138
- /**
139
- * Perform HTTP request with platform-appropriate fetch implementation
140
- *
141
- * @param url The URL to request
142
- * @param options Request options
143
- * @returns Promise resolving to response
144
- */
145
- fetch(url: string, options?: RequestInit): Promise<Response>;
146
- }
147
- /**
148
- * Simple cache operations that work across platforms
149
- */
150
- interface VanaCacheAdapter {
151
- /**
152
- * Get a value from the cache
153
- *
154
- * @param key The cache key
155
- * @returns The cached value or null if not found/expired
156
- */
157
- get(key: string): string | null;
158
- /**
159
- * Set a value in the cache
160
- *
161
- * @param key The cache key
162
- * @param value The value to cache
163
- */
164
- set(key: string, value: string): void;
165
- /**
166
- * Delete a value from the cache
167
- *
168
- * @param key The cache key
169
- */
170
- delete(key: string): void;
171
- /**
172
- * Clear all values from the cache
173
- */
174
- clear(): void;
175
- }
176
- /**
177
- * Main platform adapter interface that combines all platform-specific functionality
178
- *
179
- * **Implementation Guidelines:**
180
- * 1. All methods must maintain consistent behavior across platforms
181
- * 2. Error types and messages should be unified
182
- * 3. Data formats (encoding, serialization) must be identical
183
- * 4. Performance characteristics can vary but API must be consistent
184
- *
185
- * **Custom Implementation Example:**
186
- * ```typescript
187
- * class CustomPlatformAdapter implements VanaPlatformAdapter {
188
- * crypto = new CustomCryptoAdapter();
189
- * pgp = new CustomPGPAdapter();
190
- * http = new CustomHttpAdapter();
191
- * platform = 'browser' as const;
192
- * }
193
- * ```
194
- */
195
- interface VanaPlatformAdapter {
196
- /**
197
- * Crypto operations adapter
198
- */
199
- crypto: VanaCryptoAdapter;
200
- /**
201
- * PGP operations adapter
202
- */
203
- pgp: VanaPGPAdapter;
204
- /**
205
- * HTTP operations adapter
206
- */
207
- http: VanaHttpAdapter;
208
- /**
209
- * Cache operations adapter
210
- */
211
- cache: VanaCacheAdapter;
212
- /**
213
- * Platform identifier for debugging/telemetry
214
- */
215
- readonly platform: PlatformType;
216
- }
217
-
218
- /**
219
- * Browser implementation of the Vana Platform Adapter
220
- *
221
- * This implementation uses browser-compatible libraries and configurations
222
- * to provide crypto, PGP, and HTTP functionality without Node.js dependencies.
223
- */
224
-
225
- /**
226
- * Complete browser platform adapter implementation
227
- */
228
- declare class BrowserPlatformAdapter implements VanaPlatformAdapter {
229
- crypto: VanaCryptoAdapter;
230
- pgp: VanaPGPAdapter;
231
- http: VanaHttpAdapter;
232
- cache: VanaCacheAdapter;
233
- platform: "browser";
234
- constructor();
235
- }
1
+ import { V as VanaPlatformAdapter, P as PlatformType } from './browser-DY8XDblx.js';
2
+ export { B as BrowserPlatformAdapter } from './browser-DY8XDblx.js';
236
3
 
237
4
  /**
238
5
  * Browser-only exports for platform adapters
@@ -290,4 +57,4 @@ declare function getPlatformCapabilities(): {
290
57
  streams: boolean;
291
58
  };
292
59
 
293
- export { BrowserPlatformAdapter, type VanaPlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported };
60
+ export { VanaPlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported };