@alwatr/crypto 4.0.0-alpha.0 → 4.0.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 CHANGED
@@ -3,59 +3,25 @@
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.0.0-alpha.0 (2024-09-10)
6
+ ## [4.0.0](https://github.com/Alwatr/nanotron/compare/v4.0.0-alpha.3...v4.0.0) (2024-09-14)
7
7
 
8
- ### BREAKING CHANGES
9
-
10
- * **crypto:** new api
11
- * **crypto/api:** rename AlwatrUserGenerator to AlwatrCryptoFactory and change config
12
- * **crypto/user:** methods name updated
13
- * **crypto/token:** methods name updated
14
- * **crypto/hash:** methods name updated
15
-
16
- ### Features
8
+ **Note:** Version bump only for package @alwatr/crypto
17
9
 
18
- * **crypto/api:** AlwatrCryptoFactory with secret and device id ([2d754a1](https://github.com/Alwatr/nanotron/commit/2d754a19b2f04f64d0828e31ba004fc192f466d3)) by @
19
- * **crypto/api:** device id generator preconfig ([71e80d6](https://github.com/Alwatr/nanotron/commit/71e80d63743579505a6be17d014c364e9f6cf55c)) by @
20
- * **crypto/hash:** review and update all methods and documents ([14acd26](https://github.com/Alwatr/nanotron/commit/14acd265a19b1b67bd32f725468fe66985464fe6)) by @
21
- * **crypto/preConfig:** update prefix and secret algorithm ([0cfff12](https://github.com/Alwatr/nanotron/commit/0cfff124e692d02aad0b5c97908df63bc692f896)) by @
22
- * **crypto/token:** review and update all methods and documents ([dc943f8](https://github.com/Alwatr/nanotron/commit/dc943f8a007567b58e9e3b7f9cada556ac76ae9b)) by @
23
- * **crypto/user:** review and update all methods and documents ([bb79fa8](https://github.com/Alwatr/nanotron/commit/bb79fa81f8632d5fe75cac813238b04094d0bb6a)) by @
24
- * **crypto:** complete rewrite with new api ([3d56861](https://github.com/Alwatr/nanotron/commit/3d56861a2857e760c7cd5f03be98f003738fc7a9)) by @
25
- * **crypto:** prefix option ([6be5c90](https://github.com/Alwatr/nanotron/commit/6be5c90dad4674e8ae3e27611a13dcf1e08ce11a)) by @
26
- * **crypto:** rename user file to api ([52343ea](https://github.com/Alwatr/nanotron/commit/52343ead04c23f50bedac2caa01f46bf489ab318)) by @
27
- * **yarn:** pnp ([b6a562c](https://github.com/Alwatr/nanotron/commit/b6a562c909a35b3e626442e5c325da3fce448e1b)) by @
10
+ ## [4.0.0-alpha.0](https://github.com/Alwatr/nanotron/compare/v1.2.7...v4.0.0-alpha.0) (2024-09-10)
28
11
 
29
12
  ### Bug Fixes
30
13
 
31
14
  * build issue after update package.json ([9df6a58](https://github.com/Alwatr/nanotron/commit/9df6a5866d2b5542e89788f1cf2a1bea5cc369d3)) by @njfamirm
32
- * **crypto:** compatible with new logger api ([f867317](https://github.com/Alwatr/nanotron/commit/f8673178d18f14276e13dcb35a7d973f301a722b)) by @
33
- * **crypto:** use import type ([30e3bac](https://github.com/Alwatr/nanotron/commit/30e3bacb187d58417cb62e2a1511de4ade3f80c0)) by @
34
- * move repo urls ([719aa3e](https://github.com/Alwatr/nanotron/commit/719aa3e7462d3c9c6272958fc93f89fda6793fb1)) by @
35
- * package repo urls ([466cbe9](https://github.com/Alwatr/nanotron/commit/466cbe9188f24e1a1bc36d879a95b52538a58f16)) by @
36
15
 
37
16
  ### Code Refactoring
38
17
 
39
- * change build config and remove tslib ([81eabfa](https://github.com/Alwatr/nanotron/commit/81eabfa7ba4db432333f11f854e054304e80e922)) by @
40
- * rename core ro packages ([680604f](https://github.com/Alwatr/nanotron/commit/680604fb6af49273e5ad0745194b7186cb818faa)) by @
41
18
  * Update import paths for duration parsing ([97dd8aa](https://github.com/Alwatr/nanotron/commit/97dd8aa68e050127e444ef268e48246b6b7318c6)) by @AliMD
42
19
  * Update import paths for duration parsing and update typescript SDK version to 5.6.2 ([7d8ea97](https://github.com/Alwatr/nanotron/commit/7d8ea97ed8d7741e26d3a609b30e42992d9fb051)) by @AliMD
43
20
 
44
21
  ### Miscellaneous Chores
45
22
 
46
23
  * add required deps ([32b8ade](https://github.com/Alwatr/nanotron/commit/32b8adeba96dbd68879d004fe44f2f2c88b2b624)) by @njfamirm
47
- * **crypto:** define package version ([cd54226](https://github.com/Alwatr/nanotron/commit/cd5422634edf7f29f19fb7fccc880397c02c18c0)) by @
48
- * **deps-dev:** bump the development-dependencies group with 1 update ([97fcdb3](https://github.com/Alwatr/nanotron/commit/97fcdb3487be289c3c6a718335fea9ba441bfef9)) by @
49
- * **deps-dev:** bump the development-dependencies group with 1 update ([0e580fa](https://github.com/Alwatr/nanotron/commit/0e580fa23274e6ddc626512b00ba5b7612ad9ed4)) by @
50
- * **deps-dev:** bump the development-dependencies group with 12 updates ([c908185](https://github.com/Alwatr/nanotron/commit/c908185df0bdd4acf361382ec6c1cfbcf6667256)) by @
51
- * **deps-dev:** bump the development-dependencies group with 4 updates ([0334169](https://github.com/Alwatr/nanotron/commit/033416915a9b8a6d62ce5d1831c31ff953f6c54c)) by @
52
- * **deps-dev:** bump the development-dependencies group with 5 updates ([64f796d](https://github.com/Alwatr/nanotron/commit/64f796ddfb8b1073da586cfdf526172b20b70903)) by @
53
- * **deps-dev:** bump the development-dependencies group with 9 updates ([4d50729](https://github.com/Alwatr/nanotron/commit/4d50729cdc8d0fdb6d5a9c0c3b98e3d9ad057a1b)) by @
54
- * **deps-dev:** bump the development-dependencies group with 9 updates ([e0f9bde](https://github.com/Alwatr/nanotron/commit/e0f9bdeb13fae513334c56d8e6414caca0611fab)) by @
55
- * rename project ([3f54d28](https://github.com/Alwatr/nanotron/commit/3f54d289c004ee1454f4906ad46baca7e3060d16)) by @
56
24
  * update package.json of each package from nanolib ([b8a7c8a](https://github.com/Alwatr/nanotron/commit/b8a7c8af9f88d36ac3c1ab6324b78890dc2023b3)) by @njfamirm
57
- * update repository url ([3d96754](https://github.com/Alwatr/nanotron/commit/3d96754b11740b18c02e4f11f6a559f90b09d726)) by @
58
- * **yarn:** fix packages version ([aaf3818](https://github.com/Alwatr/nanotron/commit/aaf381844ac253e9b0e5ffaf2e039a33edee0668)) by @
59
25
 
60
26
  ### Dependencies update
61
27
 
package/dist/main.cjs CHANGED
@@ -1,3 +1,3 @@
1
- /* @alwatr/crypto v4.0.0-alpha.0 */
1
+ /* @alwatr/crypto v4.0.0 */
2
2
  "use strict";var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},_=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of C(e))!x.call(t,o)&&o!==r&&c(t,o,{get:()=>e[o],enumerable:!(n=y(e,o))||n.enumerable});return t};var k=t=>_(c({},"__esModule",{value:!0}),t);var G={};v(G,{AlwatrCryptoFactory:()=>h,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 m=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,m.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 h=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)("crypto","3.x");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.0-alpha.0 */
1
+ /* @alwatr/crypto v4.0.0 */
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 h}from"node:crypto";import{parseDuration as m}from"@alwatr/parse-duration";var i=class{constructor(e){this.config=e;this._duration=e.duration=="infinite"?0:m(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+h(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("crypto","3.x");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.0-alpha.0",
3
+ "version": "4.0.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": [
@@ -78,5 +78,5 @@
78
78
  "jest": "^29.7.0",
79
79
  "typescript": "^5.6.2"
80
80
  },
81
- "gitHead": "98c507c61c76e83f1559fd1df4f7ef6510cfc70a"
81
+ "gitHead": "4fac85b6d696585b70485f2cd171c3eca0b72ea3"
82
82
  }