ismx-nexo-node-app 0.4.156 → 0.4.158

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.
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const buffer_1 = require("buffer");
4
+ class JwtUtils {
5
+ static decodeBase64Url(base64Url) {
6
+ // Reemplaza caracteres de base64url
7
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
8
+ // Decodifica en UTF-8
9
+ return decodeURIComponent(buffer_1.Buffer.from(base64, 'base64').toString("utf-8")
10
+ .split("")
11
+ .map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
12
+ .join(""));
13
+ }
14
+ static decode(jwt) {
15
+ const [headerB64, payloadB64, signature] = jwt.split(".");
16
+ const header = JSON.parse(JwtUtils.decodeBase64Url(headerB64));
17
+ const payload = JSON.parse(JwtUtils.decodeBase64Url(payloadB64));
18
+ // Si tiene campos de tiempo, conviértelos a fecha legible
19
+ if (payload.iat)
20
+ payload.iat_date = new Date(payload.iat * 1000).toISOString();
21
+ if (payload.exp)
22
+ payload.exp_date = new Date(payload.exp * 1000).toISOString();
23
+ return { header, payload, signature };
24
+ }
25
+ }
26
+ exports.default = JwtUtils;
@@ -0,0 +1,25 @@
1
+ export default class JwtUtils {
2
+ private static decodeBase64Url;
3
+ static decode(jwt: string): Jwt;
4
+ }
5
+ export interface JwtHeader {
6
+ alg: string;
7
+ typ: string;
8
+ kid?: string;
9
+ [key: string]: any;
10
+ }
11
+ export interface JwtPayload {
12
+ exp?: number;
13
+ iat?: number;
14
+ nbf?: number;
15
+ iss?: string;
16
+ aud?: string | string[];
17
+ sub?: string;
18
+ jti?: string;
19
+ [key: string]: any;
20
+ }
21
+ export interface Jwt {
22
+ header: JwtHeader;
23
+ payload: JwtPayload;
24
+ signature: string;
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.156",
3
+ "version": "0.4.158",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -0,0 +1,52 @@
1
+ import { Buffer } from 'buffer';
2
+
3
+ export default class JwtUtils
4
+ {
5
+ private static decodeBase64Url(base64Url: string) {
6
+ // Reemplaza caracteres de base64url
7
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
8
+ // Decodifica en UTF-8
9
+ return decodeURIComponent(
10
+ Buffer.from(base64, 'base64').toString("utf-8")
11
+ .split("")
12
+ .map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
13
+ .join("")
14
+ );
15
+ }
16
+
17
+ static decode(jwt: string): Jwt {
18
+ const [headerB64, payloadB64, signature] = jwt.split(".");
19
+ const header: JwtHeader = JSON.parse(JwtUtils.decodeBase64Url(headerB64));
20
+ const payload: JwtPayload = JSON.parse(JwtUtils.decodeBase64Url(payloadB64));
21
+
22
+ // Si tiene campos de tiempo, conviértelos a fecha legible
23
+ if (payload.iat) payload.iat_date = new Date(payload.iat * 1000).toISOString();
24
+ if (payload.exp) payload.exp_date = new Date(payload.exp * 1000).toISOString();
25
+
26
+ return { header, payload, signature };
27
+ }
28
+ }
29
+
30
+ export interface JwtHeader {
31
+ alg: string; // Algorithm (e.g., "RS256")
32
+ typ: string; // Token type (usually "JWT")
33
+ kid?: string; // Key ID (optional)
34
+ [key: string]: any; // Allow other custom header fields
35
+ }
36
+
37
+ export interface JwtPayload {
38
+ exp?: number; // Expiration time (Unix timestamp)
39
+ iat?: number; // Issued at
40
+ nbf?: number; // Not before
41
+ iss?: string; // Issuer
42
+ aud?: string | string[]; // Audience
43
+ sub?: string; // Subject (usually user ID)
44
+ jti?: string; // JWT ID
45
+ [key: string]: any; // Allow extra claims
46
+ }
47
+
48
+ export interface Jwt {
49
+ header: JwtHeader;
50
+ payload: JwtPayload;
51
+ signature: string;
52
+ }