@opendatalabs/vana-sdk 0.1.0-alpha.d44f792 → 0.1.0-alpha.db07fe1

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 (45) hide show
  1. package/README.md +68 -13
  2. package/package.json +45 -24
  3. package/dist/chains.browser.cjs +0 -96
  4. package/dist/chains.browser.cjs.map +0 -1
  5. package/dist/chains.browser.d.cts +0 -53
  6. package/dist/chains.browser.d.ts +0 -53
  7. package/dist/chains.browser.js +0 -65
  8. package/dist/chains.browser.js.map +0 -1
  9. package/dist/chains.cjs +0 -96
  10. package/dist/chains.cjs.map +0 -1
  11. package/dist/chains.d.cts +0 -2
  12. package/dist/chains.d.ts +0 -2
  13. package/dist/chains.js +0 -65
  14. package/dist/chains.js.map +0 -1
  15. package/dist/chains.node.cjs +0 -96
  16. package/dist/chains.node.cjs.map +0 -1
  17. package/dist/chains.node.d.cts +0 -2
  18. package/dist/chains.node.d.ts +0 -2
  19. package/dist/chains.node.js +0 -65
  20. package/dist/chains.node.js.map +0 -1
  21. package/dist/index.browser.d.ts +0 -34334
  22. package/dist/index.browser.js +0 -41687
  23. package/dist/index.browser.js.map +0 -1
  24. package/dist/index.d.cts +0 -2
  25. package/dist/index.node.cjs +0 -42197
  26. package/dist/index.node.cjs.map +0 -1
  27. package/dist/index.node.d.cts +0 -34468
  28. package/dist/index.node.d.ts +0 -34468
  29. package/dist/index.node.js +0 -42057
  30. package/dist/index.node.js.map +0 -1
  31. package/dist/platform.browser.d.ts +0 -293
  32. package/dist/platform.browser.js +0 -365
  33. package/dist/platform.browser.js.map +0 -1
  34. package/dist/platform.cjs +0 -734
  35. package/dist/platform.cjs.map +0 -1
  36. package/dist/platform.d.cts +0 -1
  37. package/dist/platform.d.ts +0 -1
  38. package/dist/platform.js +0 -697
  39. package/dist/platform.js.map +0 -1
  40. package/dist/platform.node.cjs +0 -734
  41. package/dist/platform.node.cjs.map +0 -1
  42. package/dist/platform.node.d.cts +0 -334
  43. package/dist/platform.node.d.ts +0 -334
  44. package/dist/platform.node.js +0 -697
  45. package/dist/platform.node.js.map +0 -1
package/dist/platform.cjs DELETED
@@ -1,734 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // src/platform/shared/crypto-utils.ts
34
- function processWalletPublicKey(publicKey) {
35
- const publicKeyHex = publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
36
- const publicKeyBytes = Buffer.from(publicKeyHex, "hex");
37
- return publicKeyBytes.length === 64 ? Buffer.concat([Buffer.from([4]), publicKeyBytes]) : publicKeyBytes;
38
- }
39
- function processWalletPrivateKey(privateKey) {
40
- const privateKeyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
41
- return Buffer.from(privateKeyHex, "hex");
42
- }
43
- function parseEncryptedDataBuffer(encryptedBuffer) {
44
- return {
45
- iv: encryptedBuffer.slice(0, 16),
46
- ephemPublicKey: encryptedBuffer.slice(16, 81),
47
- // 65 bytes for uncompressed public key
48
- ciphertext: encryptedBuffer.slice(81, -32),
49
- mac: encryptedBuffer.slice(-32)
50
- };
51
- }
52
- var init_crypto_utils = __esm({
53
- "src/platform/shared/crypto-utils.ts"() {
54
- "use strict";
55
- }
56
- });
57
-
58
- // src/platform/shared/pgp-utils.ts
59
- function processPGPKeyOptions(options) {
60
- return {
61
- name: options?.name || "Vana User",
62
- email: options?.email || "user@vana.org",
63
- passphrase: options?.passphrase
64
- };
65
- }
66
- function getPGPKeyGenParams(options) {
67
- const { name, email, passphrase } = processPGPKeyOptions(options);
68
- return {
69
- type: "rsa",
70
- rsaBits: 2048,
71
- userIDs: [{ name, email }],
72
- passphrase,
73
- config: STANDARD_PGP_CONFIG
74
- };
75
- }
76
- var STANDARD_PGP_CONFIG;
77
- var init_pgp_utils = __esm({
78
- "src/platform/shared/pgp-utils.ts"() {
79
- "use strict";
80
- STANDARD_PGP_CONFIG = {
81
- preferredCompressionAlgorithm: 2,
82
- // zlib (openpgp.enums.compression.zlib)
83
- preferredSymmetricAlgorithm: 7
84
- // aes256 (openpgp.enums.symmetric.aes256)
85
- };
86
- }
87
- });
88
-
89
- // src/platform/shared/error-utils.ts
90
- function wrapCryptoError(operation, error) {
91
- const message = error instanceof Error ? error.message : "Unknown error";
92
- return new Error(`${operation} failed: ${message}`);
93
- }
94
- var init_error_utils = __esm({
95
- "src/platform/shared/error-utils.ts"() {
96
- "use strict";
97
- }
98
- });
99
-
100
- // src/platform/browser.ts
101
- var browser_exports = {};
102
- __export(browser_exports, {
103
- BrowserPlatformAdapter: () => BrowserPlatformAdapter,
104
- browserPlatformAdapter: () => browserPlatformAdapter
105
- });
106
- var openpgp, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
107
- var init_browser = __esm({
108
- "src/platform/browser.ts"() {
109
- "use strict";
110
- openpgp = __toESM(require("openpgp"), 1);
111
- init_crypto_utils();
112
- init_pgp_utils();
113
- init_error_utils();
114
- BrowserCryptoAdapter = class {
115
- async encryptWithPublicKey(data, publicKeyHex) {
116
- try {
117
- const eccrypto2 = await import("eccrypto-js");
118
- const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
119
- const encrypted = await eccrypto2.encrypt(
120
- publicKeyBuffer,
121
- Buffer.from(data, "utf8")
122
- );
123
- const result = Buffer.concat([
124
- encrypted.iv,
125
- encrypted.ephemPublicKey,
126
- encrypted.ciphertext,
127
- encrypted.mac
128
- ]);
129
- return result.toString("hex");
130
- } catch (error) {
131
- throw new Error(`Encryption failed: ${error}`);
132
- }
133
- }
134
- async decryptWithPrivateKey(encryptedData, privateKeyHex) {
135
- try {
136
- const eccrypto2 = await import("eccrypto-js");
137
- const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
138
- const encryptedBuffer = Buffer.from(encryptedData, "hex");
139
- const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
140
- const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
141
- const decryptedBuffer = await eccrypto2.decrypt(
142
- privateKeyBuffer,
143
- encryptedObj
144
- );
145
- return decryptedBuffer.toString("utf8");
146
- } catch (error) {
147
- throw new Error(`Decryption failed: ${error}`);
148
- }
149
- }
150
- async generateKeyPair() {
151
- try {
152
- const eccrypto2 = await import("eccrypto-js");
153
- const privateKeyBytes = new Uint8Array(32);
154
- crypto.getRandomValues(privateKeyBytes);
155
- const privateKey = Buffer.from(privateKeyBytes);
156
- const publicKey = eccrypto2.getPublicCompressed(privateKey);
157
- return {
158
- privateKey: privateKey.toString("hex"),
159
- publicKey: publicKey.toString("hex")
160
- };
161
- } catch (error) {
162
- throw wrapCryptoError("key generation", error);
163
- }
164
- }
165
- async encryptWithWalletPublicKey(data, publicKey) {
166
- try {
167
- const eccrypto2 = await import("eccrypto-js");
168
- const uncompressedKey = processWalletPublicKey(publicKey);
169
- const encryptedBuffer = await eccrypto2.encrypt(
170
- uncompressedKey,
171
- Buffer.from(data)
172
- );
173
- const result = Buffer.concat([
174
- encryptedBuffer.iv,
175
- encryptedBuffer.ephemPublicKey,
176
- encryptedBuffer.ciphertext,
177
- encryptedBuffer.mac
178
- ]);
179
- return result.toString("hex");
180
- } catch (error) {
181
- throw wrapCryptoError("encrypt with wallet public key", error);
182
- }
183
- }
184
- async decryptWithWalletPrivateKey(encryptedData, privateKey) {
185
- try {
186
- const eccrypto2 = await import("eccrypto-js");
187
- const privateKeyBuffer = processWalletPrivateKey(privateKey);
188
- const encryptedBuffer = Buffer.from(encryptedData, "hex");
189
- const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
190
- const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
191
- const decryptedBuffer = await eccrypto2.decrypt(
192
- privateKeyBuffer,
193
- encryptedObj
194
- );
195
- return decryptedBuffer.toString("utf8");
196
- } catch (error) {
197
- throw wrapCryptoError("decrypt with wallet private key", error);
198
- }
199
- }
200
- async encryptWithPassword(data, password) {
201
- try {
202
- const openpgp3 = await import("openpgp");
203
- const message = await openpgp3.createMessage({
204
- binary: data
205
- });
206
- const encrypted = await openpgp3.encrypt({
207
- message,
208
- passwords: [password],
209
- format: "binary"
210
- });
211
- const response = new Response(encrypted);
212
- const arrayBuffer = await response.arrayBuffer();
213
- return new Uint8Array(arrayBuffer);
214
- } catch (error) {
215
- throw new Error(`Failed to encrypt with password: ${error}`);
216
- }
217
- }
218
- async decryptWithPassword(encryptedData, password) {
219
- try {
220
- const openpgp3 = await import("openpgp");
221
- const message = await openpgp3.readMessage({
222
- binaryMessage: encryptedData
223
- });
224
- const { data: decrypted } = await openpgp3.decrypt({
225
- message,
226
- passwords: [password],
227
- format: "binary"
228
- });
229
- return new Uint8Array(decrypted);
230
- } catch (error) {
231
- throw new Error(`Failed to decrypt with password: ${error}`);
232
- }
233
- }
234
- };
235
- BrowserPGPAdapter = class {
236
- async encrypt(data, publicKeyArmored) {
237
- try {
238
- const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
239
- const encrypted = await openpgp.encrypt({
240
- message: await openpgp.createMessage({ text: data }),
241
- encryptionKeys: publicKey,
242
- config: {
243
- preferredCompressionAlgorithm: openpgp.enums.compression.zlib
244
- }
245
- });
246
- return encrypted;
247
- } catch (error) {
248
- throw new Error(`PGP encryption failed: ${error}`);
249
- }
250
- }
251
- async decrypt(encryptedData, privateKeyArmored) {
252
- try {
253
- const privateKey = await openpgp.readPrivateKey({
254
- armoredKey: privateKeyArmored
255
- });
256
- const message = await openpgp.readMessage({
257
- armoredMessage: encryptedData
258
- });
259
- const { data: decrypted } = await openpgp.decrypt({
260
- message,
261
- decryptionKeys: privateKey
262
- });
263
- return decrypted;
264
- } catch (error) {
265
- throw new Error(`PGP decryption failed: ${error}`);
266
- }
267
- }
268
- async generateKeyPair(options) {
269
- try {
270
- const keyGenParams = getPGPKeyGenParams(options);
271
- const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
272
- return { publicKey, privateKey };
273
- } catch (error) {
274
- throw wrapCryptoError("PGP key generation", error);
275
- }
276
- }
277
- };
278
- BrowserHttpAdapter = class {
279
- async fetch(url, options) {
280
- if (typeof fetch === "undefined") {
281
- throw new Error("Fetch API not available in this browser environment");
282
- }
283
- return fetch(url, options);
284
- }
285
- };
286
- BrowserCacheAdapter = class {
287
- prefix = "vana_cache_";
288
- get(key) {
289
- try {
290
- if (typeof sessionStorage === "undefined") {
291
- return null;
292
- }
293
- return sessionStorage.getItem(this.prefix + key);
294
- } catch {
295
- return null;
296
- }
297
- }
298
- set(key, value) {
299
- try {
300
- if (typeof sessionStorage !== "undefined") {
301
- sessionStorage.setItem(this.prefix + key, value);
302
- }
303
- } catch {
304
- }
305
- }
306
- delete(key) {
307
- try {
308
- if (typeof sessionStorage !== "undefined") {
309
- sessionStorage.removeItem(this.prefix + key);
310
- }
311
- } catch {
312
- }
313
- }
314
- clear() {
315
- try {
316
- if (typeof sessionStorage === "undefined") {
317
- return;
318
- }
319
- const keys = Object.keys(sessionStorage);
320
- for (const key of keys) {
321
- if (key.startsWith(this.prefix)) {
322
- sessionStorage.removeItem(key);
323
- }
324
- }
325
- } catch {
326
- }
327
- }
328
- };
329
- BrowserPlatformAdapter = class {
330
- crypto;
331
- pgp;
332
- http;
333
- cache;
334
- platform = "browser";
335
- constructor() {
336
- this.crypto = new BrowserCryptoAdapter();
337
- this.pgp = new BrowserPGPAdapter();
338
- this.http = new BrowserHttpAdapter();
339
- this.cache = new BrowserCacheAdapter();
340
- }
341
- };
342
- browserPlatformAdapter = new BrowserPlatformAdapter();
343
- }
344
- });
345
-
346
- // src/platform.ts
347
- var platform_exports = {};
348
- __export(platform_exports, {
349
- BrowserPlatformAdapter: () => BrowserPlatformAdapter,
350
- NodePlatformAdapter: () => NodePlatformAdapter,
351
- createBrowserPlatformAdapter: () => createBrowserPlatformAdapter,
352
- createNodePlatformAdapter: () => createNodePlatformAdapter,
353
- createPlatformAdapter: () => createPlatformAdapter,
354
- createPlatformAdapterFor: () => createPlatformAdapterFor,
355
- createPlatformAdapterSafe: () => createPlatformAdapterSafe,
356
- detectPlatform: () => detectPlatform,
357
- getPlatformCapabilities: () => getPlatformCapabilities,
358
- isPlatformSupported: () => isPlatformSupported
359
- });
360
- module.exports = __toCommonJS(platform_exports);
361
- init_browser();
362
-
363
- // src/platform/node.ts
364
- var import_crypto = require("crypto");
365
- var openpgp2 = __toESM(require("openpgp"), 1);
366
- init_crypto_utils();
367
- init_pgp_utils();
368
- init_error_utils();
369
-
370
- // src/platform/shared/stream-utils.ts
371
- async function streamToUint8Array(stream) {
372
- const reader = stream.getReader();
373
- const chunks = [];
374
- try {
375
- while (true) {
376
- const { done, value } = await reader.read();
377
- if (done) break;
378
- chunks.push(value);
379
- }
380
- } finally {
381
- reader.releaseLock();
382
- }
383
- const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
384
- const result = new Uint8Array(totalLength);
385
- let offset = 0;
386
- for (const chunk of chunks) {
387
- result.set(chunk, offset);
388
- offset += chunk.length;
389
- }
390
- return result;
391
- }
392
-
393
- // src/platform/node.ts
394
- var eccrypto = null;
395
- async function getEccrypto() {
396
- if (!eccrypto) {
397
- try {
398
- const eccryptoLib = await import("eccrypto");
399
- eccrypto = {
400
- encrypt: eccryptoLib.encrypt,
401
- decrypt: eccryptoLib.decrypt,
402
- getPublicCompressed: eccryptoLib.getPublicCompressed
403
- };
404
- } catch (error) {
405
- throw new Error(`Failed to load eccrypto library: ${error}`);
406
- }
407
- }
408
- return eccrypto;
409
- }
410
- var NodeCryptoAdapter = class {
411
- async encryptWithPublicKey(data, publicKeyHex) {
412
- try {
413
- const eccryptoLib = await getEccrypto();
414
- const publicKey = Buffer.from(publicKeyHex, "hex");
415
- const message = Buffer.from(data, "utf8");
416
- const encrypted = await eccryptoLib.encrypt(publicKey, message);
417
- const result = Buffer.concat([
418
- encrypted.iv,
419
- encrypted.ephemPublicKey,
420
- encrypted.ciphertext,
421
- encrypted.mac
422
- ]);
423
- return result.toString("hex");
424
- } catch (error) {
425
- throw new Error(`Encryption failed: ${error}`);
426
- }
427
- }
428
- async decryptWithPrivateKey(encryptedData, privateKeyHex) {
429
- try {
430
- const eccryptoLib = await getEccrypto();
431
- const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
432
- const encryptedBuffer = Buffer.from(encryptedData, "hex");
433
- const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
434
- const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
435
- const decrypted = await eccryptoLib.decrypt(
436
- privateKeyBuffer,
437
- encryptedObj
438
- );
439
- return decrypted.toString("utf8");
440
- } catch (error) {
441
- throw new Error(`Decryption failed: ${error}`);
442
- }
443
- }
444
- async generateKeyPair() {
445
- try {
446
- const eccryptoLib = await getEccrypto();
447
- const privateKey = (0, import_crypto.randomBytes)(32);
448
- const publicKey = eccryptoLib.getPublicCompressed(privateKey);
449
- return {
450
- privateKey: privateKey.toString("hex"),
451
- publicKey: publicKey.toString("hex")
452
- };
453
- } catch (error) {
454
- throw wrapCryptoError("key generation", error);
455
- }
456
- }
457
- async encryptWithWalletPublicKey(data, publicKey) {
458
- try {
459
- const eccryptoLib = await getEccrypto();
460
- const uncompressedKey = processWalletPublicKey(publicKey);
461
- const encrypted = await eccryptoLib.encrypt(
462
- uncompressedKey,
463
- Buffer.from(data)
464
- );
465
- const result = Buffer.concat([
466
- encrypted.iv,
467
- encrypted.ephemPublicKey,
468
- encrypted.ciphertext,
469
- encrypted.mac
470
- ]);
471
- return result.toString("hex");
472
- } catch (error) {
473
- throw wrapCryptoError("encrypt with wallet public key", error);
474
- }
475
- }
476
- async decryptWithWalletPrivateKey(encryptedData, privateKey) {
477
- try {
478
- const eccryptoLib = await getEccrypto();
479
- const privateKeyBuffer = processWalletPrivateKey(privateKey);
480
- const encryptedBuffer = Buffer.from(encryptedData, "hex");
481
- const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
482
- const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
483
- const decryptedBuffer = await eccryptoLib.decrypt(
484
- privateKeyBuffer,
485
- encryptedObj
486
- );
487
- return decryptedBuffer.toString("utf8");
488
- } catch (error) {
489
- throw wrapCryptoError("decrypt with wallet private key", error);
490
- }
491
- }
492
- async encryptWithPassword(data, password) {
493
- try {
494
- const message = await openpgp2.createMessage({
495
- binary: data
496
- });
497
- const encrypted = await openpgp2.encrypt({
498
- message,
499
- passwords: [password],
500
- format: "binary"
501
- });
502
- if (encrypted instanceof Uint8Array) {
503
- return encrypted;
504
- }
505
- if (encrypted && typeof encrypted === "object" && "getReader" in encrypted) {
506
- return await streamToUint8Array(
507
- encrypted
508
- );
509
- }
510
- throw new Error("Unexpected encrypted data format");
511
- } catch (error) {
512
- throw wrapCryptoError("encrypt with password", error);
513
- }
514
- }
515
- async decryptWithPassword(encryptedData, password) {
516
- try {
517
- const message = await openpgp2.readMessage({
518
- binaryMessage: encryptedData
519
- });
520
- const { data: decrypted } = await openpgp2.decrypt({
521
- message,
522
- passwords: [password],
523
- format: "binary"
524
- });
525
- return new Uint8Array(decrypted);
526
- } catch (error) {
527
- throw wrapCryptoError("decrypt with password", error);
528
- }
529
- }
530
- };
531
- var NodePGPAdapter = class {
532
- async encrypt(data, publicKeyArmored) {
533
- try {
534
- const publicKey = await openpgp2.readKey({ armoredKey: publicKeyArmored });
535
- const encrypted = await openpgp2.encrypt({
536
- message: await openpgp2.createMessage({ text: data }),
537
- encryptionKeys: publicKey,
538
- config: {
539
- preferredCompressionAlgorithm: openpgp2.enums.compression.zlib
540
- }
541
- });
542
- return encrypted;
543
- } catch (error) {
544
- throw wrapCryptoError("PGP encryption", error);
545
- }
546
- }
547
- async decrypt(encryptedData, privateKeyArmored) {
548
- try {
549
- const privateKey = await openpgp2.readPrivateKey({
550
- armoredKey: privateKeyArmored
551
- });
552
- const message = await openpgp2.readMessage({
553
- armoredMessage: encryptedData
554
- });
555
- const { data: decrypted } = await openpgp2.decrypt({
556
- message,
557
- decryptionKeys: privateKey
558
- });
559
- return decrypted;
560
- } catch (error) {
561
- throw wrapCryptoError("PGP decryption", error);
562
- }
563
- }
564
- async generateKeyPair(options) {
565
- try {
566
- const keyGenParams = getPGPKeyGenParams(options);
567
- const { privateKey, publicKey } = await openpgp2.generateKey(keyGenParams);
568
- return { publicKey, privateKey };
569
- } catch (error) {
570
- throw wrapCryptoError("PGP key generation", error);
571
- }
572
- }
573
- };
574
- var NodeHttpAdapter = class {
575
- async fetch(url, options) {
576
- if (typeof globalThis.fetch !== "undefined") {
577
- return globalThis.fetch(url, options);
578
- }
579
- throw new Error("No fetch implementation available in Node.js environment");
580
- }
581
- };
582
- var NodeCacheAdapter = class {
583
- cache = /* @__PURE__ */ new Map();
584
- defaultTtl = 2 * 60 * 60 * 1e3;
585
- // 2 hours in milliseconds
586
- get(key) {
587
- const entry = this.cache.get(key);
588
- if (!entry) {
589
- return null;
590
- }
591
- if (Date.now() > entry.expires) {
592
- this.cache.delete(key);
593
- return null;
594
- }
595
- return entry.value;
596
- }
597
- set(key, value) {
598
- this.cache.set(key, {
599
- value,
600
- expires: Date.now() + this.defaultTtl
601
- });
602
- }
603
- delete(key) {
604
- this.cache.delete(key);
605
- }
606
- clear() {
607
- this.cache.clear();
608
- }
609
- };
610
- var NodePlatformAdapter = class {
611
- crypto;
612
- pgp;
613
- http;
614
- cache;
615
- platform = "node";
616
- constructor() {
617
- this.crypto = new NodeCryptoAdapter();
618
- this.pgp = new NodePGPAdapter();
619
- this.http = new NodeHttpAdapter();
620
- this.cache = new NodeCacheAdapter();
621
- }
622
- };
623
- var nodePlatformAdapter = new NodePlatformAdapter();
624
-
625
- // src/platform/utils.ts
626
- function detectPlatform() {
627
- if (typeof process !== "undefined" && process.versions && process.versions.node) {
628
- return "node";
629
- }
630
- if (typeof window !== "undefined" && typeof document !== "undefined") {
631
- return "browser";
632
- }
633
- return "node";
634
- }
635
- async function createPlatformAdapter() {
636
- const platform = detectPlatform();
637
- try {
638
- if (platform === "node") {
639
- if (typeof window !== "undefined") {
640
- throw new Error(
641
- "NodePlatformAdapter is not available in browser environments. Use BrowserPlatformAdapter instead."
642
- );
643
- }
644
- const moduleName = "./node";
645
- const { NodePlatformAdapter: NodePlatformAdapter2 } = await import(moduleName);
646
- return new NodePlatformAdapter2();
647
- } else {
648
- const { BrowserPlatformAdapter: BrowserPlatformAdapter2 } = await Promise.resolve().then(() => (init_browser(), browser_exports));
649
- return new BrowserPlatformAdapter2();
650
- }
651
- } catch (error) {
652
- throw new Error(
653
- `Failed to create platform adapter for ${platform}: ${error instanceof Error ? error.message : "Unknown error"}`
654
- );
655
- }
656
- }
657
- async function createPlatformAdapterFor(platformType) {
658
- try {
659
- if (platformType === "node") {
660
- if (typeof window !== "undefined") {
661
- throw new Error(
662
- "NodePlatformAdapter is not available in browser environments. Use BrowserPlatformAdapter instead."
663
- );
664
- }
665
- const moduleName = "./node";
666
- const { NodePlatformAdapter: NodePlatformAdapter2 } = await import(moduleName);
667
- return new NodePlatformAdapter2();
668
- } else {
669
- const { BrowserPlatformAdapter: BrowserPlatformAdapter2 } = await Promise.resolve().then(() => (init_browser(), browser_exports));
670
- return new BrowserPlatformAdapter2();
671
- }
672
- } catch (error) {
673
- throw new Error(
674
- `Failed to create platform adapter for ${platformType}: ${error instanceof Error ? error.message : "Unknown error"}`
675
- );
676
- }
677
- }
678
- function isPlatformSupported(platformType) {
679
- const currentPlatform = detectPlatform();
680
- return currentPlatform === platformType;
681
- }
682
- function getPlatformCapabilities() {
683
- const platform = detectPlatform();
684
- return {
685
- platform,
686
- crypto: {
687
- webCrypto: typeof crypto !== "undefined" && crypto.subtle,
688
- nodeCrypto: typeof process !== "undefined" && process.versions && process.versions.node
689
- },
690
- fetch: typeof fetch !== "undefined" || typeof globalThis.fetch !== "undefined",
691
- streams: typeof ReadableStream !== "undefined"
692
- };
693
- }
694
-
695
- // src/platform/browser-safe.ts
696
- init_browser();
697
- async function createNodePlatformAdapter() {
698
- if (typeof window !== "undefined") {
699
- throw new Error(
700
- "NodePlatformAdapter is not available in browser environments. Use BrowserPlatformAdapter instead."
701
- );
702
- }
703
- const moduleName = "./node";
704
- const { NodePlatformAdapter: NodePlatformAdapter2 } = await import(moduleName);
705
- return new NodePlatformAdapter2();
706
- }
707
- function createBrowserPlatformAdapter() {
708
- return new BrowserPlatformAdapter();
709
- }
710
- async function createPlatformAdapterSafe() {
711
- if (typeof window !== "undefined") {
712
- return createBrowserPlatformAdapter();
713
- }
714
- if (typeof process !== "undefined" && process.versions && process.versions.node) {
715
- if (typeof window === "undefined") {
716
- return await createNodePlatformAdapter();
717
- }
718
- }
719
- return createBrowserPlatformAdapter();
720
- }
721
- // Annotate the CommonJS export names for ESM import in node:
722
- 0 && (module.exports = {
723
- BrowserPlatformAdapter,
724
- NodePlatformAdapter,
725
- createBrowserPlatformAdapter,
726
- createNodePlatformAdapter,
727
- createPlatformAdapter,
728
- createPlatformAdapterFor,
729
- createPlatformAdapterSafe,
730
- detectPlatform,
731
- getPlatformCapabilities,
732
- isPlatformSupported
733
- });
734
- //# sourceMappingURL=platform.cjs.map