@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.node.cjs
CHANGED
|
@@ -97,26 +97,46 @@ var init_error_utils = __esm({
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
+
// src/utils/lazy-import.ts
|
|
101
|
+
function lazyImport(importFn) {
|
|
102
|
+
let cached = null;
|
|
103
|
+
return () => {
|
|
104
|
+
if (!cached) {
|
|
105
|
+
cached = importFn().catch((err) => {
|
|
106
|
+
cached = null;
|
|
107
|
+
throw new Error("Failed to load module", { cause: err });
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return cached;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var init_lazy_import = __esm({
|
|
114
|
+
"src/utils/lazy-import.ts"() {
|
|
115
|
+
"use strict";
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
100
119
|
// src/platform/browser.ts
|
|
101
120
|
var browser_exports = {};
|
|
102
121
|
__export(browser_exports, {
|
|
103
122
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
104
123
|
browserPlatformAdapter: () => browserPlatformAdapter
|
|
105
124
|
});
|
|
106
|
-
var
|
|
125
|
+
var getOpenPGP, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
107
126
|
var init_browser = __esm({
|
|
108
127
|
"src/platform/browser.ts"() {
|
|
109
128
|
"use strict";
|
|
110
|
-
openpgp = __toESM(require("openpgp"), 1);
|
|
111
129
|
init_crypto_utils();
|
|
112
130
|
init_pgp_utils();
|
|
113
131
|
init_error_utils();
|
|
132
|
+
init_lazy_import();
|
|
133
|
+
getOpenPGP = lazyImport(() => import("openpgp"));
|
|
114
134
|
BrowserCryptoAdapter = class {
|
|
115
135
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
116
136
|
try {
|
|
117
|
-
const
|
|
137
|
+
const eccrypto = await import("eccrypto-js");
|
|
118
138
|
const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
|
|
119
|
-
const encrypted = await
|
|
139
|
+
const encrypted = await eccrypto.encrypt(
|
|
120
140
|
publicKeyBuffer,
|
|
121
141
|
Buffer.from(data, "utf8")
|
|
122
142
|
);
|
|
@@ -133,12 +153,12 @@ var init_browser = __esm({
|
|
|
133
153
|
}
|
|
134
154
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
135
155
|
try {
|
|
136
|
-
const
|
|
156
|
+
const eccrypto = await import("eccrypto-js");
|
|
137
157
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
138
158
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
139
159
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
140
160
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
141
|
-
const decryptedBuffer = await
|
|
161
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
142
162
|
privateKeyBuffer,
|
|
143
163
|
encryptedObj
|
|
144
164
|
);
|
|
@@ -149,11 +169,11 @@ var init_browser = __esm({
|
|
|
149
169
|
}
|
|
150
170
|
async generateKeyPair() {
|
|
151
171
|
try {
|
|
152
|
-
const
|
|
172
|
+
const eccrypto = await import("eccrypto-js");
|
|
153
173
|
const privateKeyBytes = new Uint8Array(32);
|
|
154
174
|
crypto.getRandomValues(privateKeyBytes);
|
|
155
175
|
const privateKey = Buffer.from(privateKeyBytes);
|
|
156
|
-
const publicKey =
|
|
176
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
157
177
|
return {
|
|
158
178
|
privateKey: privateKey.toString("hex"),
|
|
159
179
|
publicKey: publicKey.toString("hex")
|
|
@@ -164,9 +184,9 @@ var init_browser = __esm({
|
|
|
164
184
|
}
|
|
165
185
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
166
186
|
try {
|
|
167
|
-
const
|
|
187
|
+
const eccrypto = await import("eccrypto-js");
|
|
168
188
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
169
|
-
const encryptedBuffer = await
|
|
189
|
+
const encryptedBuffer = await eccrypto.encrypt(
|
|
170
190
|
uncompressedKey,
|
|
171
191
|
Buffer.from(data)
|
|
172
192
|
);
|
|
@@ -183,12 +203,12 @@ var init_browser = __esm({
|
|
|
183
203
|
}
|
|
184
204
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
185
205
|
try {
|
|
186
|
-
const
|
|
206
|
+
const eccrypto = await import("eccrypto-js");
|
|
187
207
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
188
208
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
189
209
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
190
210
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
191
|
-
const decryptedBuffer = await
|
|
211
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
192
212
|
privateKeyBuffer,
|
|
193
213
|
encryptedObj
|
|
194
214
|
);
|
|
@@ -199,11 +219,11 @@ var init_browser = __esm({
|
|
|
199
219
|
}
|
|
200
220
|
async encryptWithPassword(data, password) {
|
|
201
221
|
try {
|
|
202
|
-
const
|
|
203
|
-
const message = await
|
|
222
|
+
const openpgp = await getOpenPGP();
|
|
223
|
+
const message = await openpgp.createMessage({
|
|
204
224
|
binary: data
|
|
205
225
|
});
|
|
206
|
-
const encrypted = await
|
|
226
|
+
const encrypted = await openpgp.encrypt({
|
|
207
227
|
message,
|
|
208
228
|
passwords: [password],
|
|
209
229
|
format: "binary"
|
|
@@ -217,11 +237,11 @@ var init_browser = __esm({
|
|
|
217
237
|
}
|
|
218
238
|
async decryptWithPassword(encryptedData, password) {
|
|
219
239
|
try {
|
|
220
|
-
const
|
|
221
|
-
const message = await
|
|
240
|
+
const openpgp = await getOpenPGP();
|
|
241
|
+
const message = await openpgp.readMessage({
|
|
222
242
|
binaryMessage: encryptedData
|
|
223
243
|
});
|
|
224
|
-
const { data: decrypted } = await
|
|
244
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
225
245
|
message,
|
|
226
246
|
passwords: [password],
|
|
227
247
|
format: "binary"
|
|
@@ -235,6 +255,7 @@ var init_browser = __esm({
|
|
|
235
255
|
BrowserPGPAdapter = class {
|
|
236
256
|
async encrypt(data, publicKeyArmored) {
|
|
237
257
|
try {
|
|
258
|
+
const openpgp = await getOpenPGP();
|
|
238
259
|
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
239
260
|
const encrypted = await openpgp.encrypt({
|
|
240
261
|
message: await openpgp.createMessage({ text: data }),
|
|
@@ -250,6 +271,7 @@ var init_browser = __esm({
|
|
|
250
271
|
}
|
|
251
272
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
252
273
|
try {
|
|
274
|
+
const openpgp = await getOpenPGP();
|
|
253
275
|
const privateKey = await openpgp.readPrivateKey({
|
|
254
276
|
armoredKey: privateKeyArmored
|
|
255
277
|
});
|
|
@@ -267,6 +289,7 @@ var init_browser = __esm({
|
|
|
267
289
|
}
|
|
268
290
|
async generateKeyPair(options) {
|
|
269
291
|
try {
|
|
292
|
+
const openpgp = await getOpenPGP();
|
|
270
293
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
271
294
|
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
272
295
|
return { publicKey, privateKey };
|
|
@@ -283,15 +306,60 @@ var init_browser = __esm({
|
|
|
283
306
|
return fetch(url, options);
|
|
284
307
|
}
|
|
285
308
|
};
|
|
309
|
+
BrowserCacheAdapter = class {
|
|
310
|
+
prefix = "vana_cache_";
|
|
311
|
+
get(key) {
|
|
312
|
+
try {
|
|
313
|
+
if (typeof sessionStorage === "undefined") {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
return sessionStorage.getItem(this.prefix + key);
|
|
317
|
+
} catch {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
set(key, value) {
|
|
322
|
+
try {
|
|
323
|
+
if (typeof sessionStorage !== "undefined") {
|
|
324
|
+
sessionStorage.setItem(this.prefix + key, value);
|
|
325
|
+
}
|
|
326
|
+
} catch {
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
delete(key) {
|
|
330
|
+
try {
|
|
331
|
+
if (typeof sessionStorage !== "undefined") {
|
|
332
|
+
sessionStorage.removeItem(this.prefix + key);
|
|
333
|
+
}
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
clear() {
|
|
338
|
+
try {
|
|
339
|
+
if (typeof sessionStorage === "undefined") {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const keys = Object.keys(sessionStorage);
|
|
343
|
+
for (const key of keys) {
|
|
344
|
+
if (key.startsWith(this.prefix)) {
|
|
345
|
+
sessionStorage.removeItem(key);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} catch {
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
286
352
|
BrowserPlatformAdapter = class {
|
|
287
353
|
crypto;
|
|
288
354
|
pgp;
|
|
289
355
|
http;
|
|
356
|
+
cache;
|
|
290
357
|
platform = "browser";
|
|
291
358
|
constructor() {
|
|
292
359
|
this.crypto = new BrowserCryptoAdapter();
|
|
293
360
|
this.pgp = new BrowserPGPAdapter();
|
|
294
361
|
this.http = new BrowserHttpAdapter();
|
|
362
|
+
this.cache = new BrowserCacheAdapter();
|
|
295
363
|
}
|
|
296
364
|
};
|
|
297
365
|
browserPlatformAdapter = new BrowserPlatformAdapter();
|
|
@@ -316,8 +384,6 @@ module.exports = __toCommonJS(platform_node_exports);
|
|
|
316
384
|
init_browser();
|
|
317
385
|
|
|
318
386
|
// src/platform/node.ts
|
|
319
|
-
var import_crypto = require("crypto");
|
|
320
|
-
var openpgp2 = __toESM(require("openpgp"), 1);
|
|
321
387
|
init_crypto_utils();
|
|
322
388
|
init_pgp_utils();
|
|
323
389
|
init_error_utils();
|
|
@@ -346,29 +412,16 @@ async function streamToUint8Array(stream) {
|
|
|
346
412
|
}
|
|
347
413
|
|
|
348
414
|
// src/platform/node.ts
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
try {
|
|
353
|
-
const eccryptoLib = await import("eccrypto");
|
|
354
|
-
eccrypto = {
|
|
355
|
-
encrypt: eccryptoLib.encrypt,
|
|
356
|
-
decrypt: eccryptoLib.decrypt,
|
|
357
|
-
getPublicCompressed: eccryptoLib.getPublicCompressed
|
|
358
|
-
};
|
|
359
|
-
} catch (error) {
|
|
360
|
-
throw new Error(`Failed to load eccrypto library: ${error}`);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return eccrypto;
|
|
364
|
-
}
|
|
415
|
+
init_lazy_import();
|
|
416
|
+
var getOpenPGP2 = lazyImport(() => import("openpgp"));
|
|
417
|
+
var getEccrypto = lazyImport(() => import("eccrypto"));
|
|
365
418
|
var NodeCryptoAdapter = class {
|
|
366
419
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
367
420
|
try {
|
|
368
|
-
const
|
|
421
|
+
const eccrypto = await getEccrypto();
|
|
369
422
|
const publicKey = Buffer.from(publicKeyHex, "hex");
|
|
370
423
|
const message = Buffer.from(data, "utf8");
|
|
371
|
-
const encrypted = await
|
|
424
|
+
const encrypted = await eccrypto.encrypt(publicKey, message);
|
|
372
425
|
const result = Buffer.concat([
|
|
373
426
|
encrypted.iv,
|
|
374
427
|
encrypted.ephemPublicKey,
|
|
@@ -382,15 +435,12 @@ var NodeCryptoAdapter = class {
|
|
|
382
435
|
}
|
|
383
436
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
384
437
|
try {
|
|
385
|
-
const
|
|
438
|
+
const eccrypto = await getEccrypto();
|
|
386
439
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
387
440
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
388
441
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
389
442
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
390
|
-
const decrypted = await
|
|
391
|
-
privateKeyBuffer,
|
|
392
|
-
encryptedObj
|
|
393
|
-
);
|
|
443
|
+
const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
|
|
394
444
|
return decrypted.toString("utf8");
|
|
395
445
|
} catch (error) {
|
|
396
446
|
throw new Error(`Decryption failed: ${error}`);
|
|
@@ -398,9 +448,9 @@ var NodeCryptoAdapter = class {
|
|
|
398
448
|
}
|
|
399
449
|
async generateKeyPair() {
|
|
400
450
|
try {
|
|
401
|
-
const
|
|
402
|
-
const privateKey =
|
|
403
|
-
const publicKey =
|
|
451
|
+
const eccrypto = await getEccrypto();
|
|
452
|
+
const privateKey = eccrypto.generatePrivate();
|
|
453
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
404
454
|
return {
|
|
405
455
|
privateKey: privateKey.toString("hex"),
|
|
406
456
|
publicKey: publicKey.toString("hex")
|
|
@@ -411,9 +461,9 @@ var NodeCryptoAdapter = class {
|
|
|
411
461
|
}
|
|
412
462
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
413
463
|
try {
|
|
414
|
-
const
|
|
464
|
+
const eccrypto = await getEccrypto();
|
|
415
465
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
416
|
-
const encrypted = await
|
|
466
|
+
const encrypted = await eccrypto.encrypt(
|
|
417
467
|
uncompressedKey,
|
|
418
468
|
Buffer.from(data)
|
|
419
469
|
);
|
|
@@ -430,12 +480,12 @@ var NodeCryptoAdapter = class {
|
|
|
430
480
|
}
|
|
431
481
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
432
482
|
try {
|
|
433
|
-
const
|
|
483
|
+
const eccrypto = await getEccrypto();
|
|
434
484
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
435
485
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
436
486
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
437
487
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
438
|
-
const decryptedBuffer = await
|
|
488
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
439
489
|
privateKeyBuffer,
|
|
440
490
|
encryptedObj
|
|
441
491
|
);
|
|
@@ -446,10 +496,11 @@ var NodeCryptoAdapter = class {
|
|
|
446
496
|
}
|
|
447
497
|
async encryptWithPassword(data, password) {
|
|
448
498
|
try {
|
|
449
|
-
const
|
|
499
|
+
const openpgp = await getOpenPGP2();
|
|
500
|
+
const message = await openpgp.createMessage({
|
|
450
501
|
binary: data
|
|
451
502
|
});
|
|
452
|
-
const encrypted = await
|
|
503
|
+
const encrypted = await openpgp.encrypt({
|
|
453
504
|
message,
|
|
454
505
|
passwords: [password],
|
|
455
506
|
format: "binary"
|
|
@@ -469,10 +520,11 @@ var NodeCryptoAdapter = class {
|
|
|
469
520
|
}
|
|
470
521
|
async decryptWithPassword(encryptedData, password) {
|
|
471
522
|
try {
|
|
472
|
-
const
|
|
523
|
+
const openpgp = await getOpenPGP2();
|
|
524
|
+
const message = await openpgp.readMessage({
|
|
473
525
|
binaryMessage: encryptedData
|
|
474
526
|
});
|
|
475
|
-
const { data: decrypted } = await
|
|
527
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
476
528
|
message,
|
|
477
529
|
passwords: [password],
|
|
478
530
|
format: "binary"
|
|
@@ -486,12 +538,13 @@ var NodeCryptoAdapter = class {
|
|
|
486
538
|
var NodePGPAdapter = class {
|
|
487
539
|
async encrypt(data, publicKeyArmored) {
|
|
488
540
|
try {
|
|
489
|
-
const
|
|
490
|
-
const
|
|
491
|
-
|
|
541
|
+
const openpgp = await getOpenPGP2();
|
|
542
|
+
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
543
|
+
const encrypted = await openpgp.encrypt({
|
|
544
|
+
message: await openpgp.createMessage({ text: data }),
|
|
492
545
|
encryptionKeys: publicKey,
|
|
493
546
|
config: {
|
|
494
|
-
preferredCompressionAlgorithm:
|
|
547
|
+
preferredCompressionAlgorithm: openpgp.enums.compression.zlib
|
|
495
548
|
}
|
|
496
549
|
});
|
|
497
550
|
return encrypted;
|
|
@@ -501,13 +554,14 @@ var NodePGPAdapter = class {
|
|
|
501
554
|
}
|
|
502
555
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
503
556
|
try {
|
|
504
|
-
const
|
|
557
|
+
const openpgp = await getOpenPGP2();
|
|
558
|
+
const privateKey = await openpgp.readPrivateKey({
|
|
505
559
|
armoredKey: privateKeyArmored
|
|
506
560
|
});
|
|
507
|
-
const message = await
|
|
561
|
+
const message = await openpgp.readMessage({
|
|
508
562
|
armoredMessage: encryptedData
|
|
509
563
|
});
|
|
510
|
-
const { data: decrypted } = await
|
|
564
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
511
565
|
message,
|
|
512
566
|
decryptionKeys: privateKey
|
|
513
567
|
});
|
|
@@ -518,8 +572,9 @@ var NodePGPAdapter = class {
|
|
|
518
572
|
}
|
|
519
573
|
async generateKeyPair(options) {
|
|
520
574
|
try {
|
|
575
|
+
const openpgp = await getOpenPGP2();
|
|
521
576
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
522
|
-
const { privateKey, publicKey } = await
|
|
577
|
+
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
523
578
|
return { publicKey, privateKey };
|
|
524
579
|
} catch (error) {
|
|
525
580
|
throw wrapCryptoError("PGP key generation", error);
|
|
@@ -534,15 +589,45 @@ var NodeHttpAdapter = class {
|
|
|
534
589
|
throw new Error("No fetch implementation available in Node.js environment");
|
|
535
590
|
}
|
|
536
591
|
};
|
|
592
|
+
var NodeCacheAdapter = class {
|
|
593
|
+
cache = /* @__PURE__ */ new Map();
|
|
594
|
+
defaultTtl = 2 * 60 * 60 * 1e3;
|
|
595
|
+
// 2 hours in milliseconds
|
|
596
|
+
get(key) {
|
|
597
|
+
const entry = this.cache.get(key);
|
|
598
|
+
if (!entry) {
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
601
|
+
if (Date.now() > entry.expires) {
|
|
602
|
+
this.cache.delete(key);
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
return entry.value;
|
|
606
|
+
}
|
|
607
|
+
set(key, value) {
|
|
608
|
+
this.cache.set(key, {
|
|
609
|
+
value,
|
|
610
|
+
expires: Date.now() + this.defaultTtl
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
delete(key) {
|
|
614
|
+
this.cache.delete(key);
|
|
615
|
+
}
|
|
616
|
+
clear() {
|
|
617
|
+
this.cache.clear();
|
|
618
|
+
}
|
|
619
|
+
};
|
|
537
620
|
var NodePlatformAdapter = class {
|
|
538
621
|
crypto;
|
|
539
622
|
pgp;
|
|
540
623
|
http;
|
|
624
|
+
cache;
|
|
541
625
|
platform = "node";
|
|
542
626
|
constructor() {
|
|
543
627
|
this.crypto = new NodeCryptoAdapter();
|
|
544
628
|
this.pgp = new NodePGPAdapter();
|
|
545
629
|
this.http = new NodeHttpAdapter();
|
|
630
|
+
this.cache = new NodeCacheAdapter();
|
|
546
631
|
}
|
|
547
632
|
};
|
|
548
633
|
var nodePlatformAdapter = new NodePlatformAdapter();
|