From 4e87195739f2a5d9a05451b48773c8afdc680765 Mon Sep 17 00:00:00 2001 From: akiyamn Date: Sun, 24 Sep 2023 23:22:21 +1000 Subject: Initial commit (by create-cloudflare CLI) --- node_modules/blake3-wasm/dist/browser/hash-fn.js | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 node_modules/blake3-wasm/dist/browser/hash-fn.js (limited to 'node_modules/blake3-wasm/dist/browser/hash-fn.js') diff --git a/node_modules/blake3-wasm/dist/browser/hash-fn.js b/node_modules/blake3-wasm/dist/browser/hash-fn.js new file mode 100644 index 0000000..5259980 --- /dev/null +++ b/node_modules/blake3-wasm/dist/browser/hash-fn.js @@ -0,0 +1,47 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const hash_fn_1 = require("../base/hash-fn"); +const hash_1 = require("./hash"); +const wasm_1 = require("./wasm"); +const textEncoder = new TextEncoder(); +/** + * @hidden + */ +exports.normalizeInput = (input) => hash_fn_1.inputToArray(typeof input === 'string' ? textEncoder.encode(input) : input); +/** + * Returns a blake3 hash of the input. + */ +function hash(input, { length = hash_fn_1.defaultHashLength } = {}) { + const result = new hash_1.Hash(length); + wasm_1.getWasm().hash(exports.normalizeInput(input), result); + return result; +} +exports.hash = hash; +/** + * Given cryptographic key material and a context string, services a subkey of + * any length. See {@link https://docs.rs/blake3/0.1.3/blake3/fn.derive_key.html} + * for more information. + */ +function deriveKey(context, material, { length = hash_fn_1.defaultHashLength } = {}) { + const derive = wasm_1.getWasm().create_derive(context); + derive.update(exports.normalizeInput(material)); + const result = new hash_1.Hash(length); + derive.digest(result); + return result; +} +exports.deriveKey = deriveKey; +/** + * The keyed hash function. See {@link https://docs.rs/blake3/0.1.3/blake3/fn.keyed_hash.html}. + */ +function keyedHash(key, input, { length = hash_fn_1.defaultHashLength } = {}) { + if (key.length !== 32) { + throw new Error(`key provided to keyedHash must be 32 bytes, got ${key.length}`); + } + const derive = wasm_1.getWasm().create_keyed(key); + derive.update(exports.normalizeInput(input)); + const result = new hash_1.Hash(length); + derive.digest(result); + return result; +} +exports.keyedHash = keyedHash; +//# sourceMappingURL=hash-fn.js.map \ No newline at end of file -- cgit v1.2.3