@prsm/hash 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -0
- package/package.json +32 -0
- package/tsconfig.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# hash
|
|
2
|
+
|
|
3
|
+
A very simple string hashing library.
|
|
4
|
+
|
|
5
|
+
# create
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { hash } from "@prsm/hash";
|
|
9
|
+
|
|
10
|
+
hash.create("secret");
|
|
11
|
+
hash.create("secret");
|
|
12
|
+
hash.create("secret");
|
|
13
|
+
|
|
14
|
+
// sha256:UfH7lmEc5dr65iFPmvsKthzAgMHtdV6Qb4FXYSqlnOaQoZmqQWLBrPnJGLZmQontirQZKO9nTIz+zs544n0x7Q==:6qG75Cp5hysNWs+8TO65fzc1FaSZxykaWa3iatPrw4s=
|
|
15
|
+
// sha256:Wq6vrcGG4mKlM7r8DAuDHcYxJlG8fOEoO2sNWofl/snmsZPTaBuy8Dg6i2J28TdcncSgK8EhrCqgv69h5Kk2xA==:QvAc6op8ScJex38AYrZUtFDd69c4OJv5SsVIRgR+FPw=
|
|
16
|
+
// sha256:e16qmZpJiy1qvGycPkJz0qQnCdyAguGAFV8rqCokiFml10nl9lVU1v0hZ6QBy+laI0AYkHsYtt6wMkEOuNhpMw==:L3bHZeriSAjy8wEIz/fURxhOqxa8KltuvpHPE/nE/eQ=
|
|
17
|
+
// sha256:0SA+O819D52jZOqWuzIWa+KLyT+Ck+b5ze4HI7fAJOhRW3FYk527GnuVOS/pricLy1KqwUfk5wWyQx4z5x3fsA==:wPs8DRMOrZEJYeaPxZzccGPJSozGvNqRhhS6f8ITOyM=
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
# verify
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { hash } from "@prsm/hash";
|
|
24
|
+
|
|
25
|
+
const valid = hash.verify(
|
|
26
|
+
"secret",
|
|
27
|
+
"sha256:0SA+O819D52jZOqWuzIWa+KLyT+Ck+b5ze4HI7fAJOhRW3FYk527GnuVOS/pricLy1KqwUfk5wWyQx4z5x3fsA==:wPs8DRMOrZEJYeaPxZzccGPJSozGvNqRhhS6f8ITOyM=",
|
|
28
|
+
);
|
|
29
|
+
// valid = true
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
# custom hasher
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Hasher } from "@prsm/hash";
|
|
36
|
+
|
|
37
|
+
const hash = new Hasher("sha512", 128);
|
|
38
|
+
// hash.create("..");
|
|
39
|
+
// hash.verify("..", "sha512:...")
|
|
40
|
+
```
|
|
41
|
+
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var c=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var d=(r,s)=>{for(var t in s)a(r,t,{get:s[t],enumerable:!0})},g=(r,s,t,h)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of p(s))!u.call(r,i)&&i!==t&&a(r,i,{get:()=>s[i],enumerable:!(h=m(s,i))||h.enumerable});return r};var A=(r,s,t)=>(t=r!=null?l(c(r)):{},g(s||!r||!r.__esModule?a(t,"default",{value:r,enumerable:!0}):t,r)),b=r=>g(a({},"__esModule",{value:!0}),r);var f={};d(f,{Hasher:()=>n,hash:()=>v});module.exports=b(f);var e=A(require("crypto"),1),n=class{constructor(s="sha256",t=64){this.algorithm=s,this.saltLength=t}verify(s,t){let{algorithm:h,salt:i}=this.parse(s);return this.hash(t,h,i)===s}encode(s){let t=e.default.randomBytes(this.saltLength).toString("base64");return this.hash(s,this.algorithm,t)}hash(s,t,h){let i=e.default.createHash(t);return i.update(s),i.update(h,"utf8"),`${t}:${h}:${i.digest("base64")}`}parse(s){let t=s.split(":");if(t.length!==3)throw new Error(`Invalid hash string. Expected 3 parts, got ${t.length}`);let h=t[0],i=t[1],o=t[2];return{algorithm:h,salt:i,digest:o}}},v=new n;0&&(module.exports={Hasher,hash});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Algorithm = "sha256" | "sha512";
|
|
2
|
+
declare class Hasher {
|
|
3
|
+
private algorithm;
|
|
4
|
+
private saltLength;
|
|
5
|
+
constructor(algorithm?: Algorithm, saltLength?: number);
|
|
6
|
+
verify(encoded: string, unencoded: string): boolean;
|
|
7
|
+
encode(string: string): string;
|
|
8
|
+
hash(string: string, algorithm: Algorithm, salt: string): string;
|
|
9
|
+
private parse;
|
|
10
|
+
}
|
|
11
|
+
declare const hash: Hasher;
|
|
12
|
+
|
|
13
|
+
export { Hasher, hash };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type Algorithm = "sha256" | "sha512";
|
|
2
|
+
declare class Hasher {
|
|
3
|
+
private algorithm;
|
|
4
|
+
private saltLength;
|
|
5
|
+
constructor(algorithm?: Algorithm, saltLength?: number);
|
|
6
|
+
verify(encoded: string, unencoded: string): boolean;
|
|
7
|
+
encode(string: string): string;
|
|
8
|
+
hash(string: string, algorithm: Algorithm, salt: string): string;
|
|
9
|
+
private parse;
|
|
10
|
+
}
|
|
11
|
+
declare const hash: Hasher;
|
|
12
|
+
|
|
13
|
+
export { Hasher, hash };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import a from"crypto";var h=class{constructor(s="sha256",t=64){this.algorithm=s,this.saltLength=t}verify(s,t){let{algorithm:i,salt:r}=this.parse(s);return this.hash(t,i,r)===s}encode(s){let t=a.randomBytes(this.saltLength).toString("base64");return this.hash(s,this.algorithm,t)}hash(s,t,i){let r=a.createHash(t);return r.update(s),r.update(i,"utf8"),`${t}:${i}:${r.digest("base64")}`}parse(s){let t=s.split(":");if(t.length!==3)throw new Error(`Invalid hash string. Expected 3 parts, got ${t.length}`);let i=t[0],r=t[1],n=t[2];return{algorithm:i,salt:r,digest:n}}},o=new h;export{h as Hasher,o as hash};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prsm/hash",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"keywords": [],
|
|
20
|
+
"author": "nvms",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^20.4.1",
|
|
24
|
+
"bumpp": "^9.1.1",
|
|
25
|
+
"tsup": "^7.1.0",
|
|
26
|
+
"typescript": "^5.1.6"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && tsup src/index.ts --format cjs,esm --dts --clean --minify",
|
|
30
|
+
"release": "bumpp package.json --commit 'Release %s' --push --tag && pnpm publish --access public"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"target": "es2021",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"emitDecoratorMetadata": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"noImplicitAny": false,
|
|
12
|
+
"noImplicitReturns": false,
|
|
13
|
+
"strictNullChecks": false,
|
|
14
|
+
"baseUrl": "."
|
|
15
|
+
},
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules",
|
|
18
|
+
"lib"
|
|
19
|
+
]
|
|
20
|
+
}
|