1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.pbkdf2Encode = void 0;
|
4 | const pbkdf2_1 = require("@noble/hashes/pbkdf2");
|
5 | const sha512_1 = require("@noble/hashes/sha512");
|
6 | const util_1 = require("@polkadot/util");
|
7 | const wasm_crypto_1 = require("@polkadot/wasm-crypto");
|
8 | const asU8a_js_1 = require("../random/asU8a.js");
|
9 | function pbkdf2Encode(passphrase, salt = (0, asU8a_js_1.randomAsU8a)(), rounds = 2048, onlyJs) {
|
10 | const u8aPass = (0, util_1.u8aToU8a)(passphrase);
|
11 | const u8aSalt = (0, util_1.u8aToU8a)(salt);
|
12 | return {
|
13 | password: !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
|
14 | ? (0, wasm_crypto_1.pbkdf2)(u8aPass, u8aSalt, rounds)
|
15 | : (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, u8aPass, u8aSalt, { c: rounds, dkLen: 64 }),
|
16 | rounds,
|
17 | salt
|
18 | };
|
19 | }
|
20 | exports.pbkdf2Encode = pbkdf2Encode;
|