@alwatr/crypto 4.0.2 → 4.2.0
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/CHANGELOG.md +8 -0
- package/dist/main.cjs +2 -2
- package/dist/main.mjs +2 -2
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.2.0](https://github.com/Alwatr/nanotron/compare/v4.1.0...v4.2.0) (2024-09-23)
|
|
7
|
+
|
|
8
|
+
### Dependencies update
|
|
9
|
+
|
|
10
|
+
* bump the alwatr-dependencies group with 6 updates ([1c8a8ec](https://github.com/Alwatr/nanotron/commit/1c8a8ec468aa31c79de45f0e897cc45578242981)) by @dependabot[bot]
|
|
11
|
+
* bump the development-dependencies group with 2 updates ([e3bc7f7](https://github.com/Alwatr/nanotron/commit/e3bc7f7dcbf1779a3fdf8fbe18c4f8b4095cc222)) by @dependabot[bot]
|
|
12
|
+
* update ([d9f8d57](https://github.com/Alwatr/nanotron/commit/d9f8d577b058b4e945db7dfc1c5c68da78c4112f)) by @AliMD
|
|
13
|
+
|
|
6
14
|
## [4.0.2](https://github.com/Alwatr/nanotron/compare/v4.0.1...v4.0.2) (2024-09-14)
|
|
7
15
|
|
|
8
16
|
### Bug Fixes
|
package/dist/main.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @alwatr/crypto v4.0
|
|
2
|
-
"use strict";var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},v=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of C(e))!_.call(t,o)&&o!==r&&c(t,o,{get:()=>e[o],enumerable:!(n=y(e,o))||n.enumerable});return t};var k=t=>v(c({},"__esModule",{value:!0}),t);var G={};x(G,{AlwatrCryptoFactory:()=>m,AlwatrHashGenerator:()=>i,AlwatrTokenGenerator:()=>s,deviceIdGeneratorRecommendedConfig:()=>d,secretGeneratorRecommendedConfig:()=>f,userIdGeneratorRecommendedConfig:()=>g,userTokenGeneratorRecommendedConfig:()=>p});module.exports=k(G);var a=require("node:crypto"),i=class{constructor(e){this.config=e}generateRandom(){return this.generate((0,a.randomBytes)(16))}generateRandomSelfValidate(){return this.generateSelfValidate((0,a.randomBytes)(16))}generate(e){return this.config.prefix+(0,a.createHash)(this.config.algorithm).update(e).digest(this.config.encoding)}generateCrc(e){let r=(0,a.createHash)("sha1").update(e).digest(this.config.encoding);return this.config.crcLength==null||this.config.crcLength<1?r:r.slice(0,this.config.crcLength)}generateSelfValidate(e){let r=this.generate(e),n=this.generateCrc(r);return r+n}verify(e,r){return r===this.generate(e)}verifySelfValidate(e){let r=e.length-this.config.crcLength,n=e.slice(0,r);return e.slice(r)===this.generateCrc(n)}};var h=require("node:crypto"),u=require("@alwatr/parse-duration"),s=class{constructor(e){this.config=e;this._duration=e.duration=="infinite"?0:(0,u.parseDuration)(e.duration)}get _epoch(){return this._duration==0?0:Math.floor(Date.now()/this._duration)}generate(e){return this._generate(e,this._epoch)}verify(e,r){let n=this._epoch;return r===this._generate(e,n)?"valid":this._duration==0?"invalid":r===this._generate(e,n-1)?"expired":"invalid"}_generate(e,r){return this.config.prefix+(0,h.createHmac)(this.config.algorithm,e).update(e+r).digest(this.config.encoding)}};var g={prefix:"u",algorithm:"sha1",encoding:"base64url",crcLength:4},d={...g,prefix:"d"},f={prefix:"s",algorithm:"sha384",encoding:"base64url",crcLength:4},p={prefix:"t",algorithm:"sha224",encoding:"base64url"};var m=class{constructor(e){this._generators={secret:new i(f),deviceId:new i(d),userId:new i(g),token:new s({...p,...e})}}generateUserId(){return this._generators.userId.generateRandomSelfValidate()}verifyUserId(e){return this._generators.userId.verifySelfValidate(e)}generateToken(e){return this._generators.token.generate(e.join())}verifyToken(e,r){return this._generators.token.verify(e.join(),r)}generateSecret(){return this._generators.secret.generateRandomSelfValidate()}verifySecret(e){return this._generators.secret.verifySelfValidate(e)}generateDeviceId(){return this._generators.deviceId.generateRandomSelfValidate()}verifyDeviceId(e){return this._generators.deviceId.verifySelfValidate(e)}};var l=require("@alwatr/logger");(0,l.definePackage)("@alwatr/crypto","4.0
|
|
1
|
+
/* @alwatr/crypto v4.2.0 */
|
|
2
|
+
"use strict";var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},v=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of C(e))!_.call(t,o)&&o!==r&&c(t,o,{get:()=>e[o],enumerable:!(n=y(e,o))||n.enumerable});return t};var k=t=>v(c({},"__esModule",{value:!0}),t);var G={};x(G,{AlwatrCryptoFactory:()=>m,AlwatrHashGenerator:()=>i,AlwatrTokenGenerator:()=>s,deviceIdGeneratorRecommendedConfig:()=>d,secretGeneratorRecommendedConfig:()=>f,userIdGeneratorRecommendedConfig:()=>g,userTokenGeneratorRecommendedConfig:()=>p});module.exports=k(G);var a=require("node:crypto"),i=class{constructor(e){this.config=e}generateRandom(){return this.generate((0,a.randomBytes)(16))}generateRandomSelfValidate(){return this.generateSelfValidate((0,a.randomBytes)(16))}generate(e){return this.config.prefix+(0,a.createHash)(this.config.algorithm).update(e).digest(this.config.encoding)}generateCrc(e){let r=(0,a.createHash)("sha1").update(e).digest(this.config.encoding);return this.config.crcLength==null||this.config.crcLength<1?r:r.slice(0,this.config.crcLength)}generateSelfValidate(e){let r=this.generate(e),n=this.generateCrc(r);return r+n}verify(e,r){return r===this.generate(e)}verifySelfValidate(e){let r=e.length-this.config.crcLength,n=e.slice(0,r);return e.slice(r)===this.generateCrc(n)}};var h=require("node:crypto"),u=require("@alwatr/parse-duration"),s=class{constructor(e){this.config=e;this._duration=e.duration=="infinite"?0:(0,u.parseDuration)(e.duration)}get _epoch(){return this._duration==0?0:Math.floor(Date.now()/this._duration)}generate(e){return this._generate(e,this._epoch)}verify(e,r){let n=this._epoch;return r===this._generate(e,n)?"valid":this._duration==0?"invalid":r===this._generate(e,n-1)?"expired":"invalid"}_generate(e,r){return this.config.prefix+(0,h.createHmac)(this.config.algorithm,e).update(e+r).digest(this.config.encoding)}};var g={prefix:"u",algorithm:"sha1",encoding:"base64url",crcLength:4},d={...g,prefix:"d"},f={prefix:"s",algorithm:"sha384",encoding:"base64url",crcLength:4},p={prefix:"t",algorithm:"sha224",encoding:"base64url"};var m=class{constructor(e){this._generators={secret:new i(f),deviceId:new i(d),userId:new i(g),token:new s({...p,...e})}}generateUserId(){return this._generators.userId.generateRandomSelfValidate()}verifyUserId(e){return this._generators.userId.verifySelfValidate(e)}generateToken(e){return this._generators.token.generate(e.join())}verifyToken(e,r){return this._generators.token.verify(e.join(),r)}generateSecret(){return this._generators.secret.generateRandomSelfValidate()}verifySecret(e){return this._generators.secret.verifySelfValidate(e)}generateDeviceId(){return this._generators.deviceId.generateRandomSelfValidate()}verifyDeviceId(e){return this._generators.deviceId.verifySelfValidate(e)}};var l=require("@alwatr/logger");(0,l.definePackage)("@alwatr/crypto","4.2.0");0&&(module.exports={AlwatrCryptoFactory,AlwatrHashGenerator,AlwatrTokenGenerator,deviceIdGeneratorRecommendedConfig,secretGeneratorRecommendedConfig,userIdGeneratorRecommendedConfig,userTokenGeneratorRecommendedConfig});
|
|
3
3
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @alwatr/crypto v4.0
|
|
2
|
-
import{createHash as s,randomBytes as g}from"node:crypto";var n=class{constructor(e){this.config=e}generateRandom(){return this.generate(g(16))}generateRandomSelfValidate(){return this.generateSelfValidate(g(16))}generate(e){return this.config.prefix+s(this.config.algorithm).update(e).digest(this.config.encoding)}generateCrc(e){let r=s("sha1").update(e).digest(this.config.encoding);return this.config.crcLength==null||this.config.crcLength<1?r:r.slice(0,this.config.crcLength)}generateSelfValidate(e){let r=this.generate(e),t=this.generateCrc(r);return r+t}verify(e,r){return r===this.generate(e)}verifySelfValidate(e){let r=e.length-this.config.crcLength,t=e.slice(0,r);return e.slice(r)===this.generateCrc(t)}};import{createHmac as m}from"node:crypto";import{parseDuration as h}from"@alwatr/parse-duration";var i=class{constructor(e){this.config=e;this._duration=e.duration=="infinite"?0:h(e.duration)}get _epoch(){return this._duration==0?0:Math.floor(Date.now()/this._duration)}generate(e){return this._generate(e,this._epoch)}verify(e,r){let t=this._epoch;return r===this._generate(e,t)?"valid":this._duration==0?"invalid":r===this._generate(e,t-1)?"expired":"invalid"}_generate(e,r){return this.config.prefix+m(this.config.algorithm,e).update(e+r).digest(this.config.encoding)}};var o={prefix:"u",algorithm:"sha1",encoding:"base64url",crcLength:4},c={...o,prefix:"d"},d={prefix:"s",algorithm:"sha384",encoding:"base64url",crcLength:4},f={prefix:"t",algorithm:"sha224",encoding:"base64url"};var p=class{constructor(e){this._generators={secret:new n(d),deviceId:new n(c),userId:new n(o),token:new i({...f,...e})}}generateUserId(){return this._generators.userId.generateRandomSelfValidate()}verifyUserId(e){return this._generators.userId.verifySelfValidate(e)}generateToken(e){return this._generators.token.generate(e.join())}verifyToken(e,r){return this._generators.token.verify(e.join(),r)}generateSecret(){return this._generators.secret.generateRandomSelfValidate()}verifySecret(e){return this._generators.secret.verifySelfValidate(e)}generateDeviceId(){return this._generators.deviceId.generateRandomSelfValidate()}verifyDeviceId(e){return this._generators.deviceId.verifySelfValidate(e)}};import{definePackage as u}from"@alwatr/logger";u("@alwatr/crypto","4.0
|
|
1
|
+
/* @alwatr/crypto v4.2.0 */
|
|
2
|
+
import{createHash as s,randomBytes as g}from"node:crypto";var n=class{constructor(e){this.config=e}generateRandom(){return this.generate(g(16))}generateRandomSelfValidate(){return this.generateSelfValidate(g(16))}generate(e){return this.config.prefix+s(this.config.algorithm).update(e).digest(this.config.encoding)}generateCrc(e){let r=s("sha1").update(e).digest(this.config.encoding);return this.config.crcLength==null||this.config.crcLength<1?r:r.slice(0,this.config.crcLength)}generateSelfValidate(e){let r=this.generate(e),t=this.generateCrc(r);return r+t}verify(e,r){return r===this.generate(e)}verifySelfValidate(e){let r=e.length-this.config.crcLength,t=e.slice(0,r);return e.slice(r)===this.generateCrc(t)}};import{createHmac as m}from"node:crypto";import{parseDuration as h}from"@alwatr/parse-duration";var i=class{constructor(e){this.config=e;this._duration=e.duration=="infinite"?0:h(e.duration)}get _epoch(){return this._duration==0?0:Math.floor(Date.now()/this._duration)}generate(e){return this._generate(e,this._epoch)}verify(e,r){let t=this._epoch;return r===this._generate(e,t)?"valid":this._duration==0?"invalid":r===this._generate(e,t-1)?"expired":"invalid"}_generate(e,r){return this.config.prefix+m(this.config.algorithm,e).update(e+r).digest(this.config.encoding)}};var o={prefix:"u",algorithm:"sha1",encoding:"base64url",crcLength:4},c={...o,prefix:"d"},d={prefix:"s",algorithm:"sha384",encoding:"base64url",crcLength:4},f={prefix:"t",algorithm:"sha224",encoding:"base64url"};var p=class{constructor(e){this._generators={secret:new n(d),deviceId:new n(c),userId:new n(o),token:new i({...f,...e})}}generateUserId(){return this._generators.userId.generateRandomSelfValidate()}verifyUserId(e){return this._generators.userId.verifySelfValidate(e)}generateToken(e){return this._generators.token.generate(e.join())}verifyToken(e,r){return this._generators.token.verify(e.join(),r)}generateSecret(){return this._generators.secret.generateRandomSelfValidate()}verifySecret(e){return this._generators.secret.verifySelfValidate(e)}generateDeviceId(){return this._generators.deviceId.generateRandomSelfValidate()}verifyDeviceId(e){return this._generators.deviceId.verifySelfValidate(e)}};import{definePackage as u}from"@alwatr/logger";u("@alwatr/crypto","4.2.0");export{p as AlwatrCryptoFactory,n as AlwatrHashGenerator,i as AlwatrTokenGenerator,c as deviceIdGeneratorRecommendedConfig,d as secretGeneratorRecommendedConfig,o as userIdGeneratorRecommendedConfig,f as userTokenGeneratorRecommendedConfig};
|
|
3
3
|
//# sourceMappingURL=main.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/crypto",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "A robust generator of secure authentication HOTP tokens, employing the HMAC-based One-Time Password algorithm, accompanied by a suite of cryptographic utilities, all encapsulated within a compact TypeScript module.",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -66,17 +66,17 @@
|
|
|
66
66
|
"clean": "rm -rfv dist *.tsbuildinfo"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@alwatr/logger": "^3.2.
|
|
70
|
-
"@alwatr/parse-duration": "^1.0.
|
|
69
|
+
"@alwatr/logger": "^3.2.14",
|
|
70
|
+
"@alwatr/parse-duration": "^1.0.11"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@alwatr/nano-build": "^1.3.
|
|
73
|
+
"@alwatr/nano-build": "^1.3.10",
|
|
74
74
|
"@alwatr/prettier-config": "^1.0.4",
|
|
75
75
|
"@alwatr/tsconfig-base": "^1.2.0",
|
|
76
|
-
"@alwatr/type-helper": "^1.2.
|
|
77
|
-
"@types/node": "^22.5.
|
|
76
|
+
"@alwatr/type-helper": "^1.2.6",
|
|
77
|
+
"@types/node": "^22.5.5",
|
|
78
78
|
"jest": "^29.7.0",
|
|
79
79
|
"typescript": "^5.6.2"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "34e75bad9206fc2b5c6b787cd030707003bd3c2a"
|
|
82
82
|
}
|