
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Chapi provides a compatible API for different hashing algorithms.
Chapi provides two ways of accessing hashing functions, you can use it as a function, or an object.
The function signature looks like this:
function(algorithm, options);
The other way of using it, is accessing the property name of the algorithm you would like to use, that property is a function which you can pass an optional configuration object to. Like this:
chapi.bcrypt()
Each hashing API provides 2 functions, being hash
and compare
.
The hash function takes a string, and a callback. It performs the actually computation of the hash of str
and stores any needed information in the hash you get back.
The signature of the callback you pass should be function(err, hash)
The compare function takes a string, a hash, and a callback. It calculates the hash of str
(using the options from hash
, if necessary) and compares it to hash
.
The signature of the callback you pass should be function(err, match)
var chapi = require("chapi");
var async = require("async");
var algorithms = [ "bcrypt", "pbkdf2", "scrypt", "sha256" ];
var data = "hello world! so original.";
// Iterate over each algorithm in array
async.map(algorithms, function(algorithm, done) {
// Call the `hash` function and pass in data & callback
chapi[algorithm]().hash(data, done);
}, function(err, hashes) {
// Check for errors..
if(err) {
return console.error("Error hashing:", err);
}
console.log("Hashes:", hashes);
// Hashes contains the uniquely hashed string using each algorithm.
});
var chapi = require("chapi");
var plaintext = "omg not something random words";
var algorithm = "bcrypt";
chapi[algorithm].hash(plaintext, function(err, hash) {
if(err) return console.error("Error hashing:", err);
chapi[algorithm].compare(plaintext, hash, function(err, match) {
if(err) return console.error("Error verifying:", err);
console.log("Hash matched:", match);
});
});
See LICENSE.md
FAQs
Compatible hashing API for NodeJS
The npm package chapi receives a total of 2 weekly downloads. As such, chapi popularity was classified as not popular.
We found that chapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.