summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/helpers/toHash.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/helpers/toHash.ts b/src/helpers/toHash.ts
new file mode 100644
index 0000000..6e8db1d
--- /dev/null
+++ b/src/helpers/toHash.ts
@@ -0,0 +1,10 @@
+import crypto from 'crypto';
+
+/**
+ * Returns hash digest of the given data using the given algorithm.
+ * @param data Data to hash
+ * @return The hash
+ */
+export default function toHash(data: Buffer, algo: string = 'SHA256'): Buffer {
+ return crypto.createHash(algo).update(data).digest();
+}