@opendatalabs/vana-sdk 0.1.0-alpha.376e2fd → 0.1.0-alpha.3bc04d8
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/README.md +85 -32
- package/dist/browser-DY8XDblx.d.ts +241 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +309 -0
- package/dist/browser.js.map +1 -0
- package/dist/chains.browser.cjs +2 -2
- package/dist/chains.browser.cjs.map +1 -1
- package/dist/chains.browser.js +2 -2
- package/dist/chains.browser.js.map +1 -1
- package/dist/chains.cjs +2 -2
- package/dist/chains.cjs.map +1 -1
- package/dist/chains.js +2 -2
- package/dist/chains.js.map +1 -1
- package/dist/chains.node.cjs +2 -2
- package/dist/chains.node.cjs.map +1 -1
- package/dist/chains.node.js +2 -2
- package/dist/chains.node.js.map +1 -1
- package/dist/index.browser.d.ts +10182 -5028
- package/dist/index.browser.js +39151 -32825
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +39593 -33223
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +10246 -5035
- package/dist/index.node.d.ts +10246 -5035
- package/dist/index.node.js +39595 -33230
- package/dist/index.node.js.map +1 -1
- package/dist/node-D9-F9uEP.d.cts +238 -0
- package/dist/node-D9-F9uEP.d.ts +238 -0
- package/dist/node.cjs +348 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +311 -0
- package/dist/node.js.map +1 -0
- package/dist/platform.browser.d.ts +3 -167
- package/dist/platform.browser.js +78 -8
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.cjs +147 -62
- package/dist/platform.cjs.map +1 -1
- package/dist/platform.d.cts +2 -1
- package/dist/platform.d.ts +2 -1
- package/dist/platform.js +147 -62
- package/dist/platform.js.map +1 -1
- package/dist/platform.node.cjs +147 -62
- package/dist/platform.node.cjs.map +1 -1
- package/dist/platform.node.d.cts +8 -167
- package/dist/platform.node.d.ts +8 -167
- package/dist/platform.node.js +147 -62
- package/dist/platform.node.js.map +1 -1
- package/package.json +17 -12
package/dist/platform.js
CHANGED
|
@@ -75,26 +75,46 @@ var init_error_utils = __esm({
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
// src/utils/lazy-import.ts
|
|
79
|
+
function lazyImport(importFn) {
|
|
80
|
+
let cached = null;
|
|
81
|
+
return () => {
|
|
82
|
+
if (!cached) {
|
|
83
|
+
cached = importFn().catch((err) => {
|
|
84
|
+
cached = null;
|
|
85
|
+
throw new Error("Failed to load module", { cause: err });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return cached;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var init_lazy_import = __esm({
|
|
92
|
+
"src/utils/lazy-import.ts"() {
|
|
93
|
+
"use strict";
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
78
97
|
// src/platform/browser.ts
|
|
79
98
|
var browser_exports = {};
|
|
80
99
|
__export(browser_exports, {
|
|
81
100
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
82
101
|
browserPlatformAdapter: () => browserPlatformAdapter
|
|
83
102
|
});
|
|
84
|
-
|
|
85
|
-
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
103
|
+
var getOpenPGP, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
86
104
|
var init_browser = __esm({
|
|
87
105
|
"src/platform/browser.ts"() {
|
|
88
106
|
"use strict";
|
|
89
107
|
init_crypto_utils();
|
|
90
108
|
init_pgp_utils();
|
|
91
109
|
init_error_utils();
|
|
110
|
+
init_lazy_import();
|
|
111
|
+
getOpenPGP = lazyImport(() => import("openpgp"));
|
|
92
112
|
BrowserCryptoAdapter = class {
|
|
93
113
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
94
114
|
try {
|
|
95
|
-
const
|
|
115
|
+
const eccrypto = await import("eccrypto-js");
|
|
96
116
|
const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
|
|
97
|
-
const encrypted = await
|
|
117
|
+
const encrypted = await eccrypto.encrypt(
|
|
98
118
|
publicKeyBuffer,
|
|
99
119
|
Buffer.from(data, "utf8")
|
|
100
120
|
);
|
|
@@ -111,12 +131,12 @@ var init_browser = __esm({
|
|
|
111
131
|
}
|
|
112
132
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
113
133
|
try {
|
|
114
|
-
const
|
|
134
|
+
const eccrypto = await import("eccrypto-js");
|
|
115
135
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
116
136
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
117
137
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
118
138
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
119
|
-
const decryptedBuffer = await
|
|
139
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
120
140
|
privateKeyBuffer,
|
|
121
141
|
encryptedObj
|
|
122
142
|
);
|
|
@@ -127,11 +147,11 @@ var init_browser = __esm({
|
|
|
127
147
|
}
|
|
128
148
|
async generateKeyPair() {
|
|
129
149
|
try {
|
|
130
|
-
const
|
|
150
|
+
const eccrypto = await import("eccrypto-js");
|
|
131
151
|
const privateKeyBytes = new Uint8Array(32);
|
|
132
152
|
crypto.getRandomValues(privateKeyBytes);
|
|
133
153
|
const privateKey = Buffer.from(privateKeyBytes);
|
|
134
|
-
const publicKey =
|
|
154
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
135
155
|
return {
|
|
136
156
|
privateKey: privateKey.toString("hex"),
|
|
137
157
|
publicKey: publicKey.toString("hex")
|
|
@@ -142,9 +162,9 @@ var init_browser = __esm({
|
|
|
142
162
|
}
|
|
143
163
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
144
164
|
try {
|
|
145
|
-
const
|
|
165
|
+
const eccrypto = await import("eccrypto-js");
|
|
146
166
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
147
|
-
const encryptedBuffer = await
|
|
167
|
+
const encryptedBuffer = await eccrypto.encrypt(
|
|
148
168
|
uncompressedKey,
|
|
149
169
|
Buffer.from(data)
|
|
150
170
|
);
|
|
@@ -161,12 +181,12 @@ var init_browser = __esm({
|
|
|
161
181
|
}
|
|
162
182
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
163
183
|
try {
|
|
164
|
-
const
|
|
184
|
+
const eccrypto = await import("eccrypto-js");
|
|
165
185
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
166
186
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
167
187
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
168
188
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
169
|
-
const decryptedBuffer = await
|
|
189
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
170
190
|
privateKeyBuffer,
|
|
171
191
|
encryptedObj
|
|
172
192
|
);
|
|
@@ -177,11 +197,11 @@ var init_browser = __esm({
|
|
|
177
197
|
}
|
|
178
198
|
async encryptWithPassword(data, password) {
|
|
179
199
|
try {
|
|
180
|
-
const
|
|
181
|
-
const message = await
|
|
200
|
+
const openpgp = await getOpenPGP();
|
|
201
|
+
const message = await openpgp.createMessage({
|
|
182
202
|
binary: data
|
|
183
203
|
});
|
|
184
|
-
const encrypted = await
|
|
204
|
+
const encrypted = await openpgp.encrypt({
|
|
185
205
|
message,
|
|
186
206
|
passwords: [password],
|
|
187
207
|
format: "binary"
|
|
@@ -195,11 +215,11 @@ var init_browser = __esm({
|
|
|
195
215
|
}
|
|
196
216
|
async decryptWithPassword(encryptedData, password) {
|
|
197
217
|
try {
|
|
198
|
-
const
|
|
199
|
-
const message = await
|
|
218
|
+
const openpgp = await getOpenPGP();
|
|
219
|
+
const message = await openpgp.readMessage({
|
|
200
220
|
binaryMessage: encryptedData
|
|
201
221
|
});
|
|
202
|
-
const { data: decrypted } = await
|
|
222
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
203
223
|
message,
|
|
204
224
|
passwords: [password],
|
|
205
225
|
format: "binary"
|
|
@@ -213,6 +233,7 @@ var init_browser = __esm({
|
|
|
213
233
|
BrowserPGPAdapter = class {
|
|
214
234
|
async encrypt(data, publicKeyArmored) {
|
|
215
235
|
try {
|
|
236
|
+
const openpgp = await getOpenPGP();
|
|
216
237
|
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
217
238
|
const encrypted = await openpgp.encrypt({
|
|
218
239
|
message: await openpgp.createMessage({ text: data }),
|
|
@@ -228,6 +249,7 @@ var init_browser = __esm({
|
|
|
228
249
|
}
|
|
229
250
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
230
251
|
try {
|
|
252
|
+
const openpgp = await getOpenPGP();
|
|
231
253
|
const privateKey = await openpgp.readPrivateKey({
|
|
232
254
|
armoredKey: privateKeyArmored
|
|
233
255
|
});
|
|
@@ -245,6 +267,7 @@ var init_browser = __esm({
|
|
|
245
267
|
}
|
|
246
268
|
async generateKeyPair(options) {
|
|
247
269
|
try {
|
|
270
|
+
const openpgp = await getOpenPGP();
|
|
248
271
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
249
272
|
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
250
273
|
return { publicKey, privateKey };
|
|
@@ -261,15 +284,60 @@ var init_browser = __esm({
|
|
|
261
284
|
return fetch(url, options);
|
|
262
285
|
}
|
|
263
286
|
};
|
|
287
|
+
BrowserCacheAdapter = class {
|
|
288
|
+
prefix = "vana_cache_";
|
|
289
|
+
get(key) {
|
|
290
|
+
try {
|
|
291
|
+
if (typeof sessionStorage === "undefined") {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
return sessionStorage.getItem(this.prefix + key);
|
|
295
|
+
} catch {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
set(key, value) {
|
|
300
|
+
try {
|
|
301
|
+
if (typeof sessionStorage !== "undefined") {
|
|
302
|
+
sessionStorage.setItem(this.prefix + key, value);
|
|
303
|
+
}
|
|
304
|
+
} catch {
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
delete(key) {
|
|
308
|
+
try {
|
|
309
|
+
if (typeof sessionStorage !== "undefined") {
|
|
310
|
+
sessionStorage.removeItem(this.prefix + key);
|
|
311
|
+
}
|
|
312
|
+
} catch {
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
clear() {
|
|
316
|
+
try {
|
|
317
|
+
if (typeof sessionStorage === "undefined") {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const keys = Object.keys(sessionStorage);
|
|
321
|
+
for (const key of keys) {
|
|
322
|
+
if (key.startsWith(this.prefix)) {
|
|
323
|
+
sessionStorage.removeItem(key);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} catch {
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
264
330
|
BrowserPlatformAdapter = class {
|
|
265
331
|
crypto;
|
|
266
332
|
pgp;
|
|
267
333
|
http;
|
|
334
|
+
cache;
|
|
268
335
|
platform = "browser";
|
|
269
336
|
constructor() {
|
|
270
337
|
this.crypto = new BrowserCryptoAdapter();
|
|
271
338
|
this.pgp = new BrowserPGPAdapter();
|
|
272
339
|
this.http = new BrowserHttpAdapter();
|
|
340
|
+
this.cache = new BrowserCacheAdapter();
|
|
273
341
|
}
|
|
274
342
|
};
|
|
275
343
|
browserPlatformAdapter = new BrowserPlatformAdapter();
|
|
@@ -283,8 +351,6 @@ init_browser();
|
|
|
283
351
|
init_crypto_utils();
|
|
284
352
|
init_pgp_utils();
|
|
285
353
|
init_error_utils();
|
|
286
|
-
import { randomBytes } from "crypto";
|
|
287
|
-
import * as openpgp2 from "openpgp";
|
|
288
354
|
|
|
289
355
|
// src/platform/shared/stream-utils.ts
|
|
290
356
|
async function streamToUint8Array(stream) {
|
|
@@ -310,29 +376,16 @@ async function streamToUint8Array(stream) {
|
|
|
310
376
|
}
|
|
311
377
|
|
|
312
378
|
// src/platform/node.ts
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
try {
|
|
317
|
-
const eccryptoLib = await import("eccrypto");
|
|
318
|
-
eccrypto = {
|
|
319
|
-
encrypt: eccryptoLib.encrypt,
|
|
320
|
-
decrypt: eccryptoLib.decrypt,
|
|
321
|
-
getPublicCompressed: eccryptoLib.getPublicCompressed
|
|
322
|
-
};
|
|
323
|
-
} catch (error) {
|
|
324
|
-
throw new Error(`Failed to load eccrypto library: ${error}`);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return eccrypto;
|
|
328
|
-
}
|
|
379
|
+
init_lazy_import();
|
|
380
|
+
var getOpenPGP2 = lazyImport(() => import("openpgp"));
|
|
381
|
+
var getEccrypto = lazyImport(() => import("eccrypto"));
|
|
329
382
|
var NodeCryptoAdapter = class {
|
|
330
383
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
331
384
|
try {
|
|
332
|
-
const
|
|
385
|
+
const eccrypto = await getEccrypto();
|
|
333
386
|
const publicKey = Buffer.from(publicKeyHex, "hex");
|
|
334
387
|
const message = Buffer.from(data, "utf8");
|
|
335
|
-
const encrypted = await
|
|
388
|
+
const encrypted = await eccrypto.encrypt(publicKey, message);
|
|
336
389
|
const result = Buffer.concat([
|
|
337
390
|
encrypted.iv,
|
|
338
391
|
encrypted.ephemPublicKey,
|
|
@@ -346,15 +399,12 @@ var NodeCryptoAdapter = class {
|
|
|
346
399
|
}
|
|
347
400
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
348
401
|
try {
|
|
349
|
-
const
|
|
402
|
+
const eccrypto = await getEccrypto();
|
|
350
403
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
351
404
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
352
405
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
353
406
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
354
|
-
const decrypted = await
|
|
355
|
-
privateKeyBuffer,
|
|
356
|
-
encryptedObj
|
|
357
|
-
);
|
|
407
|
+
const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
|
|
358
408
|
return decrypted.toString("utf8");
|
|
359
409
|
} catch (error) {
|
|
360
410
|
throw new Error(`Decryption failed: ${error}`);
|
|
@@ -362,9 +412,9 @@ var NodeCryptoAdapter = class {
|
|
|
362
412
|
}
|
|
363
413
|
async generateKeyPair() {
|
|
364
414
|
try {
|
|
365
|
-
const
|
|
366
|
-
const privateKey =
|
|
367
|
-
const publicKey =
|
|
415
|
+
const eccrypto = await getEccrypto();
|
|
416
|
+
const privateKey = eccrypto.generatePrivate();
|
|
417
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
368
418
|
return {
|
|
369
419
|
privateKey: privateKey.toString("hex"),
|
|
370
420
|
publicKey: publicKey.toString("hex")
|
|
@@ -375,9 +425,9 @@ var NodeCryptoAdapter = class {
|
|
|
375
425
|
}
|
|
376
426
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
377
427
|
try {
|
|
378
|
-
const
|
|
428
|
+
const eccrypto = await getEccrypto();
|
|
379
429
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
380
|
-
const encrypted = await
|
|
430
|
+
const encrypted = await eccrypto.encrypt(
|
|
381
431
|
uncompressedKey,
|
|
382
432
|
Buffer.from(data)
|
|
383
433
|
);
|
|
@@ -394,12 +444,12 @@ var NodeCryptoAdapter = class {
|
|
|
394
444
|
}
|
|
395
445
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
396
446
|
try {
|
|
397
|
-
const
|
|
447
|
+
const eccrypto = await getEccrypto();
|
|
398
448
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
399
449
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
400
450
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
401
451
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
402
|
-
const decryptedBuffer = await
|
|
452
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
403
453
|
privateKeyBuffer,
|
|
404
454
|
encryptedObj
|
|
405
455
|
);
|
|
@@ -410,10 +460,11 @@ var NodeCryptoAdapter = class {
|
|
|
410
460
|
}
|
|
411
461
|
async encryptWithPassword(data, password) {
|
|
412
462
|
try {
|
|
413
|
-
const
|
|
463
|
+
const openpgp = await getOpenPGP2();
|
|
464
|
+
const message = await openpgp.createMessage({
|
|
414
465
|
binary: data
|
|
415
466
|
});
|
|
416
|
-
const encrypted = await
|
|
467
|
+
const encrypted = await openpgp.encrypt({
|
|
417
468
|
message,
|
|
418
469
|
passwords: [password],
|
|
419
470
|
format: "binary"
|
|
@@ -433,10 +484,11 @@ var NodeCryptoAdapter = class {
|
|
|
433
484
|
}
|
|
434
485
|
async decryptWithPassword(encryptedData, password) {
|
|
435
486
|
try {
|
|
436
|
-
const
|
|
487
|
+
const openpgp = await getOpenPGP2();
|
|
488
|
+
const message = await openpgp.readMessage({
|
|
437
489
|
binaryMessage: encryptedData
|
|
438
490
|
});
|
|
439
|
-
const { data: decrypted } = await
|
|
491
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
440
492
|
message,
|
|
441
493
|
passwords: [password],
|
|
442
494
|
format: "binary"
|
|
@@ -450,12 +502,13 @@ var NodeCryptoAdapter = class {
|
|
|
450
502
|
var NodePGPAdapter = class {
|
|
451
503
|
async encrypt(data, publicKeyArmored) {
|
|
452
504
|
try {
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
|
|
505
|
+
const openpgp = await getOpenPGP2();
|
|
506
|
+
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
507
|
+
const encrypted = await openpgp.encrypt({
|
|
508
|
+
message: await openpgp.createMessage({ text: data }),
|
|
456
509
|
encryptionKeys: publicKey,
|
|
457
510
|
config: {
|
|
458
|
-
preferredCompressionAlgorithm:
|
|
511
|
+
preferredCompressionAlgorithm: openpgp.enums.compression.zlib
|
|
459
512
|
}
|
|
460
513
|
});
|
|
461
514
|
return encrypted;
|
|
@@ -465,13 +518,14 @@ var NodePGPAdapter = class {
|
|
|
465
518
|
}
|
|
466
519
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
467
520
|
try {
|
|
468
|
-
const
|
|
521
|
+
const openpgp = await getOpenPGP2();
|
|
522
|
+
const privateKey = await openpgp.readPrivateKey({
|
|
469
523
|
armoredKey: privateKeyArmored
|
|
470
524
|
});
|
|
471
|
-
const message = await
|
|
525
|
+
const message = await openpgp.readMessage({
|
|
472
526
|
armoredMessage: encryptedData
|
|
473
527
|
});
|
|
474
|
-
const { data: decrypted } = await
|
|
528
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
475
529
|
message,
|
|
476
530
|
decryptionKeys: privateKey
|
|
477
531
|
});
|
|
@@ -482,8 +536,9 @@ var NodePGPAdapter = class {
|
|
|
482
536
|
}
|
|
483
537
|
async generateKeyPair(options) {
|
|
484
538
|
try {
|
|
539
|
+
const openpgp = await getOpenPGP2();
|
|
485
540
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
486
|
-
const { privateKey, publicKey } = await
|
|
541
|
+
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
487
542
|
return { publicKey, privateKey };
|
|
488
543
|
} catch (error) {
|
|
489
544
|
throw wrapCryptoError("PGP key generation", error);
|
|
@@ -498,15 +553,45 @@ var NodeHttpAdapter = class {
|
|
|
498
553
|
throw new Error("No fetch implementation available in Node.js environment");
|
|
499
554
|
}
|
|
500
555
|
};
|
|
556
|
+
var NodeCacheAdapter = class {
|
|
557
|
+
cache = /* @__PURE__ */ new Map();
|
|
558
|
+
defaultTtl = 2 * 60 * 60 * 1e3;
|
|
559
|
+
// 2 hours in milliseconds
|
|
560
|
+
get(key) {
|
|
561
|
+
const entry = this.cache.get(key);
|
|
562
|
+
if (!entry) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
if (Date.now() > entry.expires) {
|
|
566
|
+
this.cache.delete(key);
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
return entry.value;
|
|
570
|
+
}
|
|
571
|
+
set(key, value) {
|
|
572
|
+
this.cache.set(key, {
|
|
573
|
+
value,
|
|
574
|
+
expires: Date.now() + this.defaultTtl
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
delete(key) {
|
|
578
|
+
this.cache.delete(key);
|
|
579
|
+
}
|
|
580
|
+
clear() {
|
|
581
|
+
this.cache.clear();
|
|
582
|
+
}
|
|
583
|
+
};
|
|
501
584
|
var NodePlatformAdapter = class {
|
|
502
585
|
crypto;
|
|
503
586
|
pgp;
|
|
504
587
|
http;
|
|
588
|
+
cache;
|
|
505
589
|
platform = "node";
|
|
506
590
|
constructor() {
|
|
507
591
|
this.crypto = new NodeCryptoAdapter();
|
|
508
592
|
this.pgp = new NodePGPAdapter();
|
|
509
593
|
this.http = new NodeHttpAdapter();
|
|
594
|
+
this.cache = new NodeCacheAdapter();
|
|
510
595
|
}
|
|
511
596
|
};
|
|
512
597
|
var nodePlatformAdapter = new NodePlatformAdapter();
|