PHP WebShell
Текущая директория: /opt/BitGoJS/node_modules/@hashgraph/cryptography/lib/primitive
Просмотр файла: hmac.browser.cjs
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.HashAlgorithm = void 0;
exports.hash = hash;
var utf8 = _interopRequireWildcard(require("../encoding/utf8.cjs"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* @enum {string}
*/
const HashAlgorithm = {
Sha256: "SHA-256",
Sha384: "SHA-384",
Sha512: "SHA-512"
};
/**
* @param {HashAlgorithm} algorithm
* @param {Uint8Array | string} secretKey
* @param {Uint8Array | string} data
* @returns {Promise<Uint8Array>}
*/
exports.HashAlgorithm = HashAlgorithm;
async function hash(algorithm, secretKey, data) {
const key = typeof secretKey === "string" ? utf8.encode(secretKey) : secretKey;
const value = typeof data === "string" ? utf8.encode(data) : data;
try {
const key_ = await window.crypto.subtle.importKey("raw", key, {
name: "HMAC",
hash: algorithm
}, false, ["sign"]);
return new Uint8Array(await window.crypto.subtle.sign("HMAC", key_, value));
} catch {
throw new Error("Fallback if SubtleCrypto fails is not implemented");
}
}Выполнить команду
Для локальной разработки. Не используйте в интернете!