To create a Blake2s hash from a string in TypeScript, you can use the built-in crypto
module available in Node.js. First, you need to install blake2s-js
library which provides an implementation of Blake2s in JavaScript.
You can install this library using NPM:
25 chars2 lines
Once you have installed the blake2s-js
library, you can use the following code snippet to create a Blake2s hash from a string:
index.ts166 chars7 lines
Here, we first import the Blake2s
class from the blake2s-js
library. We then create a str
variable with the string we want to hash. We then pass str
as a parameter to the Blake2s
constructor, which returns the hash as a Uint8Array
. Finally, we convert the Uint8Array
to a hexadecimal string using the toString()
method.
The output of the above code snippet will be:
index.ts65 chars2 lines
which is the Blake2s hash of the input string.
gistlibby LogSnag