Skip to content

Commit

Permalink
add basic hashing support
Browse files Browse the repository at this point in the history
  • Loading branch information
realtux committed Feb 6, 2025
1 parent 1a17dbd commit 760a711
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ declare module '@exajs/core/system/sequelize' {
}

declare module '@exajs/core/util' {
import hash from '#exa/util/hash.js';
import json from '#exa/util/json.js';
import string from '#exa/util/string.js';
export { json, string };
export { hash, json, string };
}
19 changes: 19 additions & 0 deletions lib/util/hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import crypto from 'node:crypto';

export default new class {

sha1(string) {
return crypto
.createHash('sha1')
.update(string?.toString() ?? crypto.randomBytes(1024))
.digest('hex');
}

sha2(string) {
return crypto
.createHash('sha256')
.update(string?.toString() ?? crypto.randomBytes(1024))
.digest('hex');
}

};
2 changes: 2 additions & 0 deletions lib/util/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import hash from '#exa/util/hash.js';
import json from '#exa/util/json.js';
import string from '#exa/util/string.js';

export {
hash,
json,
string,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@exajs/core",
"type": "module",
"author": "Brian Seymour <@realtux>",
"version": "0.0.20",
"version": "0.0.21",
"description": "modern opinionated node.js framework",
"license": "MIT",
"homepage": "https://github.com/realtux/exa",
Expand Down

0 comments on commit 760a711

Please sign in to comment.