UNPKG

chaingate

Version:

A complete TypeScript library for connecting to and making transactions on different blockchains

37 lines (36 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pbkdf2 = pbkdf2; const pbkdf2_1 = require("@noble/hashes/pbkdf2"); const sha256_1 = require("@noble/hashes/sha256"); async function pbkdf2(params) { const subtleAvailable = !!global.crypto?.subtle?.importKey && !!global.crypto?.subtle?.deriveBits; if (subtleAvailable) return await pbkdf2Subtle(params); else { console.warn(` Your browser is using HTTP (not HTTPS), which: • Disables native encryption acceleration • Forces ~10× slower JavaScript fallback Critical impacts: → Encryption/decryption operations will be 10 times slower → Sensitive data could be intercepted`); return await (0, pbkdf2_1.pbkdf2Async)(sha256_1.sha256, params.password, params.salt, { c: params.iterations, dkLen: params.dkLen, }); } } async function pbkdf2Subtle(params) { // Setup key material for key derivation const deriveKeyMaterial = await crypto.subtle.importKey('raw', new TextEncoder().encode(params.password), { name: 'PBKDF2' }, false, ['deriveBits', 'deriveKey']); // Derive the key const derivedKeyBits = await crypto.subtle.deriveBits({ name: 'PBKDF2', salt: params.salt, iterations: params.iterations, hash: 'SHA-256', }, deriveKeyMaterial, params.dkLen * 8); return new Uint8Array(derivedKeyBits); } //# sourceMappingURL=Crypto.js.map