@validate-sdk/v2
v1.22.16
Published
---
Maintainers
Readme
This package can:
- Compute a digest from strings or Buffers.
- Verify a digest against an expected hash securely.
Installation
npm install @validate-sdk/v2or
yarn add @validate-sdk/v2Usage
1. Import functions
import { hashString, verifyHashString } from "@validate-sdk/v2";2. Compute a hash
const hash = await hashString("test");
console.log(hash);
// => "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"The function accepts both string and Buffer inputs.
3. Verify a hash
const input = "test";
const expected = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08";
const ok = await verifyHashString(input, expected);
console.log(ok); // trueIf the hashes don't match or expected is not valid hex, it returns false.
Verification uses crypto.timingSafeEqual to prevent timing attacks.
API
hashString(input: string | Buffer, encoding?: BufferEncoding): Promise<string>
- input: the string or Buffer to hash.
- encoding: defaults to
"utf8". - returns: 64-character lowercase hex string.
verifyHashString(input: string | Buffer, expectedHex: string, encoding?: BufferEncoding): Promise<boolean>
- input: the string or Buffer to check.
- expectedHex: 64-character hex digest.
- returns:
trueif the hashes match,falseotherwise.
License
MIT
Do you want me to also obfuscate the README a bit (like making it look more mysterious/less straightforward), or keep it developer-friendly like this?
