feat(core): Enhanced JWT handling and key management
This commit is contained in:
parent
26655ff92e
commit
b247630e0f
106
changelog.md
Normal file
106
changelog.md
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-08-26 - 2.1.0 - feat(core)
|
||||||
|
Enhanced JWT handling and key management
|
||||||
|
|
||||||
|
- Introduced the `IObjectWithJwt` type for improved type constraints.
|
||||||
|
- Added support for smartguard to create object guards with JWT validation.
|
||||||
|
- Upgraded dependencies to latest versions.
|
||||||
|
|
||||||
|
## 2024-05-29 - 2.0.4 - Maintenance
|
||||||
|
Minor updates and configuration changes.
|
||||||
|
|
||||||
|
- Updated project description.
|
||||||
|
- Modified tsconfig settings.
|
||||||
|
- Updated npmextra.json with githost.
|
||||||
|
|
||||||
|
## 2024-02-13 - 2.0.3 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2023-07-11 - 2.0.2 - Organizational Update
|
||||||
|
Switched to the new organizational scheme.
|
||||||
|
|
||||||
|
- Adjusted project structure to align with new organizational policies.
|
||||||
|
|
||||||
|
## 2022-12-22 - 2.0.1 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2022-10-24 - 2.0.0 - Major Update
|
||||||
|
Significant updates including breaking changes.
|
||||||
|
|
||||||
|
- **Breaking Change:** Switched project to ECMAScript modules.
|
||||||
|
|
||||||
|
## 2021-09-22 - 1.0.14 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2021-02-20 - 1.0.13 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2021-02-09 - 1.0.12 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2021-02-09 - 1.0.11 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2020-03-28 - 1.0.10 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-10-01 - 1.0.9 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-10-01 - 1.0.8 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-10-01 - 1.0.7 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-10-01 - 1.0.6 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-10-01 - 1.0.5 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-10-01 - 1.0.4 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-02-23 - 1.0.3 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-02-23 - 1.0.2 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
||||||
|
## 2019-02-23 - 1.0.1 - Bug Fixes
|
||||||
|
Critical fixes in core functionalities.
|
||||||
|
|
||||||
|
- Fixed core issues.
|
||||||
|
|
15
package.json
15
package.json
@ -12,16 +12,17 @@
|
|||||||
"build": "(tsbuild)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.72",
|
"@git.zone/tsbuild": "^2.1.84",
|
||||||
"@git.zone/tsrun": "^1.2.46",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"@git.zone/tstest": "^1.0.86",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@push.rocks/tapbundle": "^5.0.15",
|
"@push.rocks/tapbundle": "^5.0.24",
|
||||||
"@types/node": "^20.11.17"
|
"@types/node": "^22.5.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartcrypto": "^2.0.4",
|
"@push.rocks/smartcrypto": "^2.0.4",
|
||||||
"@tsclass/tsclass": "^4.0.51",
|
"@push.rocks/smartguard": "^3.1.0",
|
||||||
"@types/jsonwebtoken": "^9.0.5",
|
"@tsclass/tsclass": "^4.1.2",
|
||||||
|
"@types/jsonwebtoken": "^9.0.6",
|
||||||
"jsonwebtoken": "^9.0.2"
|
"jsonwebtoken": "^9.0.2"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
8891
pnpm-lock.yaml
generated
8891
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartjwt',
|
name: '@push.rocks/smartjwt',
|
||||||
version: '2.0.4',
|
version: '2.1.0',
|
||||||
description: 'a package for handling jwt'
|
description: 'A JavaScript package for creating and verifying JWTs with strong typing support.'
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import * as plugins from './smartjwt.plugins.js';
|
import * as plugins from './smartjwt.plugins.js';
|
||||||
|
|
||||||
|
// Define the IWithJwt interface with a constraint that T must be an object
|
||||||
|
export type IObjectWithJwt<T extends object> = T & { jwt: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to create and validate JWTs and their keys
|
* A class to create and validate JWTs and their keys
|
||||||
*/
|
*/
|
||||||
@ -81,4 +84,33 @@ export class SmartJwt<T extends object = any> {
|
|||||||
public async init() {
|
public async init() {
|
||||||
await this.createNewKeyPair();
|
await this.createNewKeyPair();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public isObjectWithJwt<T extends object>(
|
||||||
|
object: unknown,
|
||||||
|
): object is IObjectWithJwt<T> {
|
||||||
|
return (
|
||||||
|
typeof object === 'object' &&
|
||||||
|
object !== null &&
|
||||||
|
'jwt' in object &&
|
||||||
|
typeof (object as IObjectWithJwt<T>).jwt === 'string'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public jwtObjectGuard = new plugins.smartguard.Guard(async (dataArg: IObjectWithJwt<any>) => {
|
||||||
|
const jwtData = this.verifyJWTAndGetData(dataArg.jwt);
|
||||||
|
// check all other properties wether they match with jwtData
|
||||||
|
for (const key in dataArg) {
|
||||||
|
if (key !== 'jwt') {
|
||||||
|
if (jwtData[key] !== dataArg[key]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}, {
|
||||||
|
name: 'jwtObjectGuard',
|
||||||
|
failedHint: 'is not a valid jwt object',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartcrypto from '@push.rocks/smartcrypto';
|
import * as smartcrypto from '@push.rocks/smartcrypto';
|
||||||
|
import * as smartguard from '@push.rocks/smartguard';
|
||||||
|
|
||||||
export { smartcrypto };
|
export { smartcrypto, smartguard };
|
||||||
|
|
||||||
// thirdparty scope
|
// thirdparty scope
|
||||||
import jsonwebtoken from 'jsonwebtoken';
|
import jsonwebtoken from 'jsonwebtoken';
|
||||||
|
Loading…
Reference in New Issue
Block a user