UNPKG

@ton/crypto

Version:

[![Version npm](https://img.shields.io/npm/v/@ton/crypto.svg?logo=npm)](https://www.npmjs.com/package/@ton/crypto)

31 lines (30 loc) 1.24 kB
"use strict"; /** * Copyright (c) Whales Corp. * All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.hmac_sha512 = exports.hmac_sha512_fallback = void 0; const jssha_1 = __importDefault(require("jssha")); const crypto_primitives_1 = require("@ton/crypto-primitives"); async function hmac_sha512_fallback(key, data) { let keyBuffer = typeof key === 'string' ? Buffer.from(key, 'utf-8') : key; let dataBuffer = typeof data === 'string' ? Buffer.from(data, 'utf-8') : data; const shaObj = new jssha_1.default("SHA-512", "HEX", { hmacKey: { value: keyBuffer.toString('hex'), format: "HEX" }, }); shaObj.update(dataBuffer.toString('hex')); const hmac = shaObj.getHash("HEX"); return Buffer.from(hmac, 'hex'); } exports.hmac_sha512_fallback = hmac_sha512_fallback; function hmac_sha512(key, data) { return (0, crypto_primitives_1.hmac_sha512)(key, data); } exports.hmac_sha512 = hmac_sha512;