The `hash-test-vectors` package provides a comprehensive, static collection of cryptographic test vectors for various hash functions, HMACs, and PBKDF2. It consolidates and expands test data primarily sourced from NIST (for SHA, MD5) and RFCs (for HMAC, PBKDF2), tailoring them to cover all hash algorithms supported by Node.js. This data is made available in a JSON format, making it highly suitable for validating JavaScript cryptographic implementations in both Node.js and browser environments. The package is currently at version 1.3.2, with its last update in late 2015, indicating a stable, maintenance-mode status as a dataset rather than an actively developed library. Its primary differentiator is simplifying the rigorous testing of crypto functions against standardized, pre-computed references.
npm install hash-test-vectorsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to iterate through the provided SHA-1 test vectors to validate a custom SHA-1 implementation, showing both base64 and Buffer input methods for comprehensive testing. Note: `tape` and `MySha1` are placeholders for demonstration.
Replace `new Buffer(data, encoding)` with `Buffer.from(data, encoding)`.
In Node.js ESM, use dynamic `import('hash-test-vectors').then(mod => mod.default)` or `import vectors = require('hash-test-vectors');` if supported by your TypeScript configuration. For bundlers, ensure CJS interop is enabled.For newer algorithms or very recent updates, consult more current test vector sources or dedicated libraries, or consider generating vectors directly from official specifications.
If the file is intended to be an ESM module, use `import vectors from 'hash-test-vectors';` or configure your build system for CJS interop. Alternatively, change the file or project to use CommonJS.
Replace `new Buffer(data, encoding)` with `Buffer.from(data, encoding)`.
Ensure you are using `const vectors = require('hash-test-vectors');` in CommonJS or `import vectors from 'hash-test-vectors';` in ESM contexts that support CJS default imports.No dependency data recorded yet.