Stellar comes equipped with a hashing system, which makes use of the bcrypt library. This allows you to compute hashes and compare them with clear text data to validate them.

It’s important that you set the default salt on production environment in order to increase the security of your API. You can do that setting the general.salt config.

Compute Hashes

The api.hash.hash and api.hash.hashSync methods allow you to generate a hash from a string asynchronously and synchronously, respectively.

// generate a hash synchronously
let hash = api.hash.hashSync(plainData)

// generate a hash asynchronously
api.hash.hash(plainData).then(hash => {
// do something, with the hash...

You can also use other salt with different resources, all you need is pass an extra hash with your special params who meets your needs:

hash.hashSync(plainData, { salt: yourSuperSalt })

Compare Hashes

The and api.hash.compareSync methods allow you to compare a string with a hash to check whether they match.

// compare a hash synchronously
let result =, hashToCompare)

// compare a hash asynchronously
api.hash.compareSync(plainData, hashToCompare).then(isValid => {
// do something, with the result...