@alwatr/crypto 4.10.0 โ 4.10.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/CHANGELOG.md +6 -0
- package/dist/main.cjs +2 -2
- package/dist/main.mjs +2 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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.10.1](https://github.com/Alwatr/nanotron/compare/v4.10.0...v4.10.1) (2025-09-21)
|
|
7
|
+
|
|
8
|
+
### ๐งน Miscellaneous Chores
|
|
9
|
+
|
|
10
|
+
* add "sideEffects": false to package.json files for better tree-shaking ([2aae07b](https://github.com/Alwatr/nanotron/commit/2aae07b0e1757b6035ea0ca8c1b0eda64a13dfcc))
|
|
11
|
+
|
|
6
12
|
## [4.10.0](https://github.com/Alwatr/nanotron/compare/v4.9.4...v4.10.0) (2025-09-21)
|
|
7
13
|
|
|
8
14
|
### ๐ Bug Fixes
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ๐ฆ @alwatr/crypto v4.10.
|
|
2
|
-
__dev_mode__: console.debug("๐ฆ @alwatr/crypto v4.10.
|
|
1
|
+
/** ๐ฆ @alwatr/crypto v4.10.1 */
|
|
2
|
+
__dev_mode__: console.debug("๐ฆ @alwatr/crypto v4.10.1");
|
|
3
3
|
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{AlwatrCryptoFactory:()=>AlwatrCryptoFactory,AlwatrHashGenerator:()=>AlwatrHashGenerator,AlwatrTokenGenerator:()=>AlwatrTokenGenerator,deviceIdGeneratorRecommendedConfig:()=>deviceIdGeneratorRecommendedConfig,secretGeneratorRecommendedConfig:()=>secretGeneratorRecommendedConfig,userIdGeneratorRecommendedConfig:()=>userIdGeneratorRecommendedConfig,userTokenGeneratorRecommendedConfig:()=>userTokenGeneratorRecommendedConfig});module.exports=__toCommonJS(main_exports);var import_node_crypto=require("node:crypto");var AlwatrHashGenerator=class{constructor(config){this.config=config}generateRandom(){return this.generate((0,import_node_crypto.randomBytes)(16))}generateRandomSelfValidate(){return this.generateSelfValidate((0,import_node_crypto.randomBytes)(16))}generate(data){return this.config.prefix+(0,import_node_crypto.createHash)(this.config.algorithm).update(data).digest(this.config.encoding)}generateCrc(data){const crc=(0,import_node_crypto.createHash)("sha1").update(data).digest(this.config.encoding);return this.config.crcLength==null||this.config.crcLength<1?crc:crc.slice(0,this.config.crcLength)}generateSelfValidate(data){const mainHash=this.generate(data);const crcHash=this.generateCrc(mainHash);return mainHash+crcHash}verify(data,hash){return hash===this.generate(data)}verifySelfValidate(hash){const gapPos=hash.length-this.config.crcLength;const mainHash=hash.slice(0,gapPos);const crcHash=hash.slice(gapPos);return crcHash===this.generateCrc(mainHash)}};var import_node_crypto2=require("node:crypto");var import_parse_duration=require("@alwatr/parse-duration");var AlwatrTokenGenerator=class{constructor(config){this.config=config;this._duration=config.duration=="infinite"?0:(0,import_parse_duration.parseDuration)(config.duration)}get _epoch(){return this._duration==0?0:Math.floor(Date.now()/this._duration)}generate(data){return this._generate(data,this._epoch)}verify(data,token){const epoch=this._epoch;if(token===this._generate(data,epoch))return"valid";if(this._duration==0)return"invalid";if(token===this._generate(data,epoch-1))return"expired";return"invalid"}_generate(data,epoch){return this.config.prefix+(0,import_node_crypto2.createHmac)(this.config.algorithm,data).update(data+epoch).digest(this.config.encoding)}};var userIdGeneratorRecommendedConfig={prefix:"u",algorithm:"sha1",encoding:"base64url",crcLength:4};var deviceIdGeneratorRecommendedConfig={...userIdGeneratorRecommendedConfig,prefix:"d"};var secretGeneratorRecommendedConfig={prefix:"s",algorithm:"sha384",encoding:"base64url",crcLength:4};var userTokenGeneratorRecommendedConfig={prefix:"t",algorithm:"sha224",encoding:"base64url"};var AlwatrCryptoFactory=class{constructor(config){this._generators={secret:new AlwatrHashGenerator(secretGeneratorRecommendedConfig),deviceId:new AlwatrHashGenerator(deviceIdGeneratorRecommendedConfig),userId:new AlwatrHashGenerator(userIdGeneratorRecommendedConfig),token:new AlwatrTokenGenerator({...userTokenGeneratorRecommendedConfig,...config})}}generateUserId(){return this._generators.userId.generateRandomSelfValidate()}verifyUserId(userId){return this._generators.userId.verifySelfValidate(userId)}generateToken(uniquelyList){return this._generators.token.generate(uniquelyList.join())}verifyToken(uniquelyList,token){return this._generators.token.verify(uniquelyList.join(),token)}generateSecret(){return this._generators.secret.generateRandomSelfValidate()}verifySecret(secret){return this._generators.secret.verifySelfValidate(secret)}generateDeviceId(){return this._generators.deviceId.generateRandomSelfValidate()}verifyDeviceId(deviceId){return this._generators.deviceId.verifySelfValidate(deviceId)}};0&&(module.exports={AlwatrCryptoFactory,AlwatrHashGenerator,AlwatrTokenGenerator,deviceIdGeneratorRecommendedConfig,secretGeneratorRecommendedConfig,userIdGeneratorRecommendedConfig,userTokenGeneratorRecommendedConfig});
|
|
4
4
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ๐ฆ @alwatr/crypto v4.10.
|
|
2
|
-
__dev_mode__: console.debug("๐ฆ @alwatr/crypto v4.10.
|
|
1
|
+
/** ๐ฆ @alwatr/crypto v4.10.1 */
|
|
2
|
+
__dev_mode__: console.debug("๐ฆ @alwatr/crypto v4.10.1");
|
|
3
3
|
import{createHash,randomBytes}from"node:crypto";var AlwatrHashGenerator=class{constructor(config){this.config=config}generateRandom(){return this.generate(randomBytes(16))}generateRandomSelfValidate(){return this.generateSelfValidate(randomBytes(16))}generate(data){return this.config.prefix+createHash(this.config.algorithm).update(data).digest(this.config.encoding)}generateCrc(data){const crc=createHash("sha1").update(data).digest(this.config.encoding);return this.config.crcLength==null||this.config.crcLength<1?crc:crc.slice(0,this.config.crcLength)}generateSelfValidate(data){const mainHash=this.generate(data);const crcHash=this.generateCrc(mainHash);return mainHash+crcHash}verify(data,hash){return hash===this.generate(data)}verifySelfValidate(hash){const gapPos=hash.length-this.config.crcLength;const mainHash=hash.slice(0,gapPos);const crcHash=hash.slice(gapPos);return crcHash===this.generateCrc(mainHash)}};import{createHmac}from"node:crypto";import{parseDuration}from"@alwatr/parse-duration";var AlwatrTokenGenerator=class{constructor(config){this.config=config;this._duration=config.duration=="infinite"?0:parseDuration(config.duration)}get _epoch(){return this._duration==0?0:Math.floor(Date.now()/this._duration)}generate(data){return this._generate(data,this._epoch)}verify(data,token){const epoch=this._epoch;if(token===this._generate(data,epoch))return"valid";if(this._duration==0)return"invalid";if(token===this._generate(data,epoch-1))return"expired";return"invalid"}_generate(data,epoch){return this.config.prefix+createHmac(this.config.algorithm,data).update(data+epoch).digest(this.config.encoding)}};var userIdGeneratorRecommendedConfig={prefix:"u",algorithm:"sha1",encoding:"base64url",crcLength:4};var deviceIdGeneratorRecommendedConfig={...userIdGeneratorRecommendedConfig,prefix:"d"};var secretGeneratorRecommendedConfig={prefix:"s",algorithm:"sha384",encoding:"base64url",crcLength:4};var userTokenGeneratorRecommendedConfig={prefix:"t",algorithm:"sha224",encoding:"base64url"};var AlwatrCryptoFactory=class{constructor(config){this._generators={secret:new AlwatrHashGenerator(secretGeneratorRecommendedConfig),deviceId:new AlwatrHashGenerator(deviceIdGeneratorRecommendedConfig),userId:new AlwatrHashGenerator(userIdGeneratorRecommendedConfig),token:new AlwatrTokenGenerator({...userTokenGeneratorRecommendedConfig,...config})}}generateUserId(){return this._generators.userId.generateRandomSelfValidate()}verifyUserId(userId){return this._generators.userId.verifySelfValidate(userId)}generateToken(uniquelyList){return this._generators.token.generate(uniquelyList.join())}verifyToken(uniquelyList,token){return this._generators.token.verify(uniquelyList.join(),token)}generateSecret(){return this._generators.secret.generateRandomSelfValidate()}verifySecret(secret){return this._generators.secret.verifySelfValidate(secret)}generateDeviceId(){return this._generators.deviceId.generateRandomSelfValidate()}verifyDeviceId(deviceId){return this._generators.deviceId.verifySelfValidate(deviceId)}};export{AlwatrCryptoFactory,AlwatrHashGenerator,AlwatrTokenGenerator,deviceIdGeneratorRecommendedConfig,secretGeneratorRecommendedConfig,userIdGeneratorRecommendedConfig,userTokenGeneratorRecommendedConfig};
|
|
4
4
|
//# sourceMappingURL=main.mjs.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/crypto",
|
|
3
3
|
"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.",
|
|
4
|
-
"version": "4.10.
|
|
4
|
+
"version": "4.10.1",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Alwatr/nanotron/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -73,7 +73,8 @@
|
|
|
73
73
|
"watch:es": "yarn run build:es --watch",
|
|
74
74
|
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput"
|
|
75
75
|
},
|
|
76
|
+
"sideEffects": false,
|
|
76
77
|
"type": "module",
|
|
77
78
|
"types": "./dist/main.d.ts",
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "e077211736b90023d4842a23b252dc5284d0445a"
|
|
79
80
|
}
|