UNPKG

libnexa-ts

Version:

A pure and powerful Nexa SDK library.

46 lines (37 loc) 1.63 kB
import BufferUtils from "../utils/buffer.utils"; import ValidationUtils from "../utils/validation.utils"; import { sha256, sha512 } from '@noble/hashes/sha2.js'; import { ripemd160, sha1 } from '@noble/hashes/legacy.js'; import { hmac } from '@noble/hashes/hmac.js'; export default class Hash { public static sha1(buf: Uint8Array): Uint8Array { ValidationUtils.validateArgument(BufferUtils.isBuffer(buf), "buf", "Must be Buffer"); return sha1(buf); } public static sha256(buf: Uint8Array): Uint8Array { ValidationUtils.validateArgument(BufferUtils.isBuffer(buf), "buf", "Must be Buffer"); return sha256(buf); } public static sha512(buf: Uint8Array): Uint8Array { ValidationUtils.validateArgument(BufferUtils.isBuffer(buf), "buf", "Must be Buffer"); return sha512(buf); } public static ripemd160(buf: Uint8Array): Uint8Array { ValidationUtils.validateArgument(BufferUtils.isBuffer(buf), "buf", "Must be Buffer"); return ripemd160(buf); } public static sha256sha256(buf: Uint8Array): Uint8Array { ValidationUtils.validateArgument(BufferUtils.isBuffer(buf), "buf", "Must be Buffer"); return this.sha256(this.sha256(buf)); } public static sha256ripemd160(buf: Uint8Array): Uint8Array { ValidationUtils.validateArgument(BufferUtils.isBuffer(buf), "buf", "Must be Buffer"); return this.ripemd160(this.sha256(buf)); } public static sha256hmac(data: Uint8Array, key: Uint8Array): Uint8Array { return hmac(sha256, key, data); }; public static sha512hmac(data: Uint8Array, key: Uint8Array): Uint8Array { return hmac(sha512, key, data); }; }