@alwatr/crypto 4.2.1 → 4.2.2

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 CHANGED
@@ -3,6 +3,17 @@
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.2](https://github.com/Alwatr/nanotron/compare/v4.2.1...v4.2.2) (2024-09-29)
7
+
8
+ ### Miscellaneous Chores
9
+
10
+ * **crypto:** change the license to AGPL-3.0 ([a37fb50](https://github.com/Alwatr/nanotron/commit/a37fb50898bb0bc909746f44bc34d14bcf255a61)) by @ArmanAsadian
11
+
12
+ ### Dependencies update
13
+
14
+ * bump @types/node in the development-dependencies group ([9c8d7d5](https://github.com/Alwatr/nanotron/commit/9c8d7d518d9a5da2ea57ac2b210a8697267e6d3d)) by @dependabot[bot]
15
+ * update ([1c4ef63](https://github.com/Alwatr/nanotron/commit/1c4ef635fc969d4abd416aea2b954de674748da8)) by @AliMD
16
+
6
17
  ## [4.2.1](https://github.com/Alwatr/nanotron/compare/v4.2.0...v4.2.1) (2024-09-24)
7
18
 
8
19
  ### Dependencies update
package/README.md CHANGED
@@ -18,3 +18,17 @@ A robust generator of secure authentication HOTP tokens, employing the HMAC-base
18
18
  - [HMAC Generator/Tester Tool](https://www.freeformatter.com/hmac-generator.html). FreeFormatter.
19
19
  - [How API Request Signing Works (And How to Implement HMAC in NodeJS)](https://blog.andrewhoang.me/how-api-request-signing-works-and-how-to-implement-it-in-nodejs-2/). (2016). Andrew Hoang.
20
20
  - [Implement HMAC Authentication](https://support.google.com/admanager/answer/7637490?hl=en). Google Ad Manager Help.
21
+
22
+ ## Sponsors
23
+
24
+ The following companies, organizations, and individuals support Nitrobase ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.
25
+
26
+ [![Exir Studio](https://avatars.githubusercontent.com/u/181194967?s=200&v=4)](https://exirstudio.com)
27
+
28
+ ### Contributing
29
+
30
+ Contributions are welcome! Please read our [contribution guidelines](https://github.com/Alwatr/.github/blob/next/CONTRIBUTING.md) before submitting a pull request.
31
+
32
+ ### License
33
+
34
+ This project is licensed under the [AGPL-3.0 License](LICENSE).
package/dist/main.cjs CHANGED
@@ -1,3 +1,3 @@
1
- /* @alwatr/crypto v4.2.1 */
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.1");0&&(module.exports={AlwatrCryptoFactory,AlwatrHashGenerator,AlwatrTokenGenerator,deviceIdGeneratorRecommendedConfig,secretGeneratorRecommendedConfig,userIdGeneratorRecommendedConfig,userTokenGeneratorRecommendedConfig});
1
+ /* @alwatr/crypto v4.2.2 */
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.2");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.2.1 */
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.1");export{p as AlwatrCryptoFactory,n as AlwatrHashGenerator,i as AlwatrTokenGenerator,c as deviceIdGeneratorRecommendedConfig,d as secretGeneratorRecommendedConfig,o as userIdGeneratorRecommendedConfig,f as userTokenGeneratorRecommendedConfig};
1
+ /* @alwatr/crypto v4.2.2 */
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.2");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.2.1",
3
+ "version": "4.2.2",
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": [
@@ -31,7 +31,7 @@
31
31
  "require": "./dist/main.cjs"
32
32
  }
33
33
  },
34
- "license": "MIT",
34
+ "license": "AGPL-3.0-only",
35
35
  "files": [
36
36
  "**/*.{js,mjs,cjs,map,d.ts,html,md}",
37
37
  "!demo/**/*"
@@ -74,9 +74,9 @@
74
74
  "@alwatr/prettier-config": "^1.0.4",
75
75
  "@alwatr/tsconfig-base": "^1.2.0",
76
76
  "@alwatr/type-helper": "^1.2.6",
77
- "@types/node": "^22.6.1",
77
+ "@types/node": "^22.7.4",
78
78
  "jest": "^29.7.0",
79
79
  "typescript": "^5.6.2"
80
80
  },
81
- "gitHead": "b4a2982e438591723fc4a19ce004cf2938b01971"
81
+ "gitHead": "887f58ef716850a245871fe0f3672354201cdb9a"
82
82
  }