@sourceregistry/node-jwt 1.2.1 → 1.3.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.
@@ -1,115 +1,2 @@
1
- import { KeyLike } from 'crypto';
2
- import { JWT as JSONWebToken, JWTPayload, SupportedAlgorithm, JWTHeader } from './index.js';
3
- export { type SupportedAlgorithm, SupportedAlgorithms, SignatureAlgorithm, type JWTHeader, type JWTPayload } from './index.js';
4
- /**
5
- * Decode a JWT string into its parts (without verification)
6
- */
7
- export declare const decode: (token: string) => Promise<JSONWebToken>;
8
- /**
9
- * Sign a JWT
10
- */
11
- export declare const sign: (payload: JWTPayload, secret: KeyLike, options?: {
12
- alg?: SupportedAlgorithm;
13
- kid?: string;
14
- typ?: string;
15
- }) => Promise<string>;
16
- /**
17
- * Verify and validate a JWT
18
- *
19
- * @throws { { reason: string; code: string } } if invalid
20
- */
21
- export declare const verify: (token: string, secret: KeyLike, options?: {
22
- algorithms?: SupportedAlgorithm[];
23
- issuer?: string;
24
- subject?: string;
25
- audience?: string | string[];
26
- jwtId?: string;
27
- ignoreExpiration?: boolean;
28
- clockSkew?: number;
29
- maxTokenAge?: number;
30
- }) => Promise<{
31
- header: JWTHeader;
32
- payload: JWTPayload;
33
- signature: string;
34
- }>;
35
- export type JWT = JSONWebToken;
36
- export declare const JWT: {
37
- sign: (payload: JWTPayload, secret: KeyLike, options?: {
38
- alg?: SupportedAlgorithm;
39
- kid?: string;
40
- typ?: string;
41
- }) => Promise<string>;
42
- verify: (token: string, secret: KeyLike, options?: {
43
- algorithms?: SupportedAlgorithm[];
44
- issuer?: string;
45
- subject?: string;
46
- audience?: string | string[];
47
- jwtId?: string;
48
- ignoreExpiration?: boolean;
49
- clockSkew?: number;
50
- maxTokenAge?: number;
51
- }) => Promise<{
52
- header: JWTHeader;
53
- payload: JWTPayload;
54
- signature: string;
55
- }>;
56
- decode: (token: string) => Promise<JSONWebToken>;
57
- algorithms: {
58
- readonly HS256: {
59
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
60
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
61
- };
62
- readonly HS384: {
63
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
64
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
65
- };
66
- readonly HS512: {
67
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
68
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
69
- };
70
- readonly RS256: {
71
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
72
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
73
- };
74
- readonly RS384: {
75
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
76
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
77
- };
78
- readonly RS512: {
79
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
80
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
81
- };
82
- readonly ES256: {
83
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
84
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
85
- };
86
- readonly ES384: {
87
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
88
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
89
- };
90
- readonly ES512: {
91
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
92
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
93
- };
94
- readonly ES256K: {
95
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
96
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
97
- };
98
- readonly PS256: {
99
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
100
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
101
- };
102
- readonly PS384: {
103
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
104
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
105
- };
106
- readonly PS512: {
107
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
108
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
109
- };
110
- readonly EdDSA: {
111
- readonly sign: (data: import('crypto').BinaryLike, secret: KeyLike) => string;
112
- readonly verify: (data: import('crypto').BinaryLike, secret: KeyLike, signature: string) => boolean;
113
- };
114
- };
115
- };
1
+ export * from './jwt/promises';
2
+ export * from './jwks/promises';
@@ -1,23 +1,42 @@
1
- import { SignatureAlgorithm as a, decode as d, sign as c, verify as l } from "./index.es.js";
2
- import { SupportedAlgorithms as y } from "./index.es.js";
3
- const m = (e) => Promise.resolve().then(() => d(e)), g = (e, r, o = {}) => Promise.resolve().then(() => c(e, r, o)), h = (e, r, o = {}) => Promise.resolve().then(() => {
4
- const s = l(e, r, o);
1
+ import { S as m, d as c, s as a, v as l, e as h, i as p, t as K, g as J, h as W, n as v, c as u } from "./index-DyXdSqEc.js";
2
+ import { a as q } from "./index-DyXdSqEc.js";
3
+ import "crypto";
4
+ const P = (e) => Promise.resolve().then(() => c(e)), g = (e, o, t = {}) => Promise.resolve().then(() => a(e, o, t)), $ = (e, o, t = {}) => Promise.resolve().then(() => {
5
+ const s = l(e, o, t);
5
6
  if (!s.valid)
6
7
  throw s.error;
7
- const { header: t, payload: i, signature: n } = s;
8
- return { header: t, payload: i, signature: n };
9
- }), f = {
8
+ const { header: r, payload: n, signature: i } = s;
9
+ return { header: r, payload: n, signature: i };
10
+ }), O = {
10
11
  sign: g,
11
- verify: h,
12
- decode: m,
13
- algorithms: a
12
+ verify: $,
13
+ decode: P,
14
+ algorithms: m
15
+ }, b = (e) => Promise.resolve().then(() => h(e)), d = (e) => Promise.resolve().then(() => p(e)), S = (e) => Promise.resolve().then(() => K(e)), T = (e, o = "sha256") => Promise.resolve().then(() => J(e, o)), y = (e, o) => Promise.resolve().then(() => W(e, o)), f = (e) => Promise.resolve().then(() => v(e)), x = (e) => Promise.resolve().then(() => u(e)), A = {
16
+ export: b,
17
+ import: d,
18
+ toPublic: S,
19
+ thumbprint: T,
20
+ computeX5T: x
21
+ }, X = {
22
+ toKeyObject: y,
23
+ normalize: f
14
24
  };
15
25
  export {
16
- f as JWT,
17
- a as SignatureAlgorithm,
18
- y as SupportedAlgorithms,
19
- m as decode,
26
+ A as JWK,
27
+ X as JWKS,
28
+ y as JWKSToKeyObject,
29
+ O as JWT,
30
+ m as SignatureAlgorithm,
31
+ q as SupportedAlgorithms,
32
+ x as computeX5T,
33
+ P as decode,
34
+ b as exportJWK,
35
+ T as getJWKThumbprint,
36
+ d as importJWK,
37
+ f as normalizeJWKS,
20
38
  g as sign,
21
- h as verify
39
+ S as toPublicJWK,
40
+ $ as verify
22
41
  };
23
42
  //# sourceMappingURL=promises.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promises.es.js","sources":["../src/promises.ts"],"sourcesContent":["import type { KeyLike } from 'crypto';\nimport {\n type JWT as JSONWebToken,\n decode as decodeSync,\n sign as signSync,\n verify as verifySync,\n JWTPayload,\n type SupportedAlgorithm,\n JWTHeader,\n SignatureAlgorithm\n} from './index.js';\n\nexport { type SupportedAlgorithm, SupportedAlgorithms, SignatureAlgorithm, type JWTHeader, type JWTPayload } from './index.js';\n\n/**\n * Decode a JWT string into its parts (without verification)\n */\nexport const decode = (token: string): Promise<JSONWebToken> =>\n Promise.resolve().then(() => decodeSync(token));\n\n/**\n * Sign a JWT\n */\nexport const sign = (\n payload: JWTPayload,\n secret: KeyLike,\n options: {\n alg?: SupportedAlgorithm;\n kid?: string;\n typ?: string;\n } = {}\n): Promise<string> =>\n Promise.resolve().then(() => signSync(payload, secret, options));\n\n/**\n * Verify and validate a JWT\n *\n * @throws { { reason: string; code: string } } if invalid\n */\nexport const verify = (\n token: string,\n secret: KeyLike,\n options: {\n algorithms?: SupportedAlgorithm[]; // Whitelist of allowed algorithms\n issuer?: string;\n subject?: string;\n audience?: string | string[];\n jwtId?: string;\n ignoreExpiration?: boolean;\n clockSkew?: number; // in seconds, default 0\n maxTokenAge?: number; // Maximum age in seconds\n } = {}\n): Promise<{ header: JWTHeader; payload: JWTPayload; signature: string }> =>\n Promise.resolve().then(() => {\n const result = verifySync(token, secret, options);\n if (!result.valid) {\n throw result.error;\n }\n const { header, payload, signature } = result;\n return { header, payload, signature };\n });\n\nexport type JWT = JSONWebToken;\n\nexport const JWT = {\n sign,\n verify,\n decode,\n algorithms: SignatureAlgorithm\n};\n"],"names":["decode","token","decodeSync","sign","payload","secret","options","signSync","verify","result","verifySync","header","signature","JWT","SignatureAlgorithm"],"mappings":";;AAiBO,MAAMA,IAAS,CAACC,MACnB,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAAWD,CAAK,CAAC,GAKrCE,IAAO,CAChBC,GACAC,GACAC,IAII,CAAA,MAEJ,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAASH,GAASC,GAAQC,CAAO,CAAC,GAOtDE,IAAS,CAClBP,GACAI,GACAC,IASI,CAAA,MAEJ,QAAQ,UAAU,KAAK,MAAM;AACzB,QAAMG,IAASC,EAAWT,GAAOI,GAAQC,CAAO;AAChD,MAAI,CAACG,EAAO;AACR,UAAMA,EAAO;AAEjB,QAAM,EAAE,QAAAE,GAAQ,SAAAP,GAAS,WAAAQ,EAAA,IAAcH;AACvC,SAAO,EAAE,QAAAE,GAAQ,SAAAP,GAAS,WAAAQ,EAAA;AAC9B,CAAC,GAIQC,IAAM;AAAA,EACf,MAAAV;AAAA,EACA,QAAAK;AAAA,EACA,QAAAR;AAAA,EACA,YAAYc;AAChB;"}
1
+ {"version":3,"file":"promises.es.js","sources":["../src/jwt/promises.ts","../src/jwks/promises.ts"],"sourcesContent":["import type { KeyLike } from 'crypto';\nimport {\n type JWT as JSONWebToken,\n decode as decodeSync,\n sign as signSync,\n verify as verifySync,\n JWTPayload,\n type SupportedAlgorithm,\n JWTHeader,\n SignatureAlgorithm\n} from '../';\n\nexport { type SupportedAlgorithm, SupportedAlgorithms, SignatureAlgorithm, type JWTHeader, type JWTPayload } from '../index';\n\n/**\n * Decode a JWT string into its parts (without verification)\n * @param token\n */\nexport const decode = (token: string): Promise<JSONWebToken> =>\n Promise.resolve().then(() => decodeSync(token));\n\n/**\n * Sign a JWT\n * @param payload\n * @param secret\n * @param options\n */\nexport const sign = (\n payload: JWTPayload,\n secret: KeyLike,\n options: {\n alg?: SupportedAlgorithm;\n kid?: string;\n typ?: string;\n } = {}\n): Promise<string> =>\n Promise.resolve().then(() => signSync(payload, secret, options));\n\n/**\n * Verify and validate a JWT\n * @throws { { reason: string; code: string } } if invalid\n */\nexport const verify = (\n token: string,\n secret: KeyLike,\n options: {\n algorithms?: SupportedAlgorithm[]; // Whitelist of allowed algorithms\n issuer?: string;\n subject?: string;\n audience?: string | string[];\n jwtId?: string;\n ignoreExpiration?: boolean;\n clockSkew?: number; // in seconds, default 0\n maxTokenAge?: number; // Maximum age in seconds\n } = {}\n): Promise<{ header: JWTHeader; payload: JWTPayload; signature: string }> =>\n Promise.resolve().then(() => {\n const result = verifySync(token, secret, options);\n if (!result.valid) {\n throw result.error;\n }\n const { header, payload, signature } = result;\n return { header, payload, signature };\n });\n\nexport type JWT = JSONWebToken;\n\n//namespace export\nexport const JWT = {\n sign,\n verify,\n decode,\n algorithms: SignatureAlgorithm\n};\n","import type {KeyObject} from 'crypto';\n\nimport {\n type JWK as JWKType,\n type JWKS as JSONWebKeySet,\n exportJWK as exportJWKSYNC,\n importJWK as importJWKSYNC,\n toPublicJWK as toPublicJWKSYNC,\n getJWKThumbprint as getJWKThumbprintSYNC,\n JWKSToKeyObject as JWKSToKeyObjectSYNC,\n normalizeJWKS as normalizeJWKSSYNC,\n computeX5T as computeX5TSYNC\n} from './';\n\n/**\n * Export a KeyObject to JWK\n * @param key\n */\nexport const exportJWK = (key: KeyObject): Promise<JWKType> =>\n Promise.resolve().then(() => exportJWKSYNC(key));\n\n/**\n * Import a JWK to KeyObject\n * @param jwk\n */\nexport const importJWK = (jwk: JWKType): Promise<KeyObject> =>\n Promise.resolve().then(() => importJWKSYNC(jwk));\n\n/**\n * Export public-only JWK\n * @param key\n */\nexport const toPublicJWK = (key: KeyObject): Promise<JWKType> =>\n Promise.resolve().then(() => toPublicJWKSYNC(key));\n\n/**\n * RFC 7638 JWK thumbprint\n * @param jwk\n * @param hashAlg\n */\nexport const getJWKThumbprint = (\n jwk: JWKType,\n hashAlg: 'sha256' = 'sha256'\n): Promise<string> =>\n Promise.resolve().then(() => getJWKThumbprintSYNC(jwk, hashAlg));\n\n/**\n * Resolve a KeyObject from a JWKS (kid-based)\n * @param jwks\n * @param kid\n * @constructor\n */\nexport const JWKSToKeyObject = (\n jwks: JSONWebKeySet,\n kid?: string\n): Promise<KeyObject> =>\n Promise.resolve().then(() => JWKSToKeyObjectSYNC(jwks, kid));\n\n/**\n * Normalize JWKS (auto-generate missing kid values)\n * @param jwks\n */\nexport const normalizeJWKS = (\n jwks: JSONWebKeySet\n): Promise<JSONWebKeySet> =>\n Promise.resolve().then(() => normalizeJWKSSYNC(jwks));\n\n/**\n * Compute x5t (SHA-1) from first cert in x5c if not set\n * @param jwk\n */\nexport const computeX5T = (jwk: JWKType) => Promise.resolve().then(() => computeX5TSYNC(jwk))\n\n//namespaced exports\nexport const JWK = {\n export: exportJWK,\n import: importJWK,\n toPublic: toPublicJWK,\n thumbprint: getJWKThumbprint,\n computeX5T: computeX5T,\n};\n\n//namespaced exports\nexport const JWKS = {\n toKeyObject: JWKSToKeyObject,\n normalize: normalizeJWKS,\n};\n"],"names":["decode","token","decodeSync","sign","payload","secret","options","signSync","verify","result","verifySync","header","signature","JWT","SignatureAlgorithm","exportJWK","key","exportJWKSYNC","importJWK","jwk","importJWKSYNC","toPublicJWK","toPublicJWKSYNC","getJWKThumbprint","hashAlg","getJWKThumbprintSYNC","JWKSToKeyObject","jwks","kid","JWKSToKeyObjectSYNC","normalizeJWKS","normalizeJWKSSYNC","computeX5T","computeX5TSYNC","JWK","JWKS"],"mappings":";;;AAkBO,MAAMA,IAAS,CAACC,MACnB,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAAWD,CAAK,CAAC,GAQrCE,IAAO,CAChBC,GACAC,GACAC,IAII,CAAA,MAEJ,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAASH,GAASC,GAAQC,CAAO,CAAC,GAMtDE,IAAS,CAClBP,GACAI,GACAC,IASI,CAAA,MAEJ,QAAQ,UAAU,KAAK,MAAM;AACzB,QAAMG,IAASC,EAAWT,GAAOI,GAAQC,CAAO;AAChD,MAAI,CAACG,EAAO;AACR,UAAMA,EAAO;AAEjB,QAAM,EAAE,QAAAE,GAAQ,SAAAP,GAAS,WAAAQ,EAAA,IAAcH;AACvC,SAAO,EAAE,QAAAE,GAAQ,SAAAP,GAAS,WAAAQ,EAAA;AAC9B,CAAC,GAKQC,IAAM;AAAA,EACf,MAAAV;AAAA,EACA,QAAAK;AAAA,EACA,QAAAR;AAAA,EACA,YAAYc;AAChB,GCvDaC,IAAY,CAACC,MACtB,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAAcD,CAAG,CAAC,GAMtCE,IAAY,CAACC,MACtB,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAAcD,CAAG,CAAC,GAMtCE,IAAc,CAACL,MACxB,QAAQ,QAAA,EAAU,KAAK,MAAMM,EAAgBN,CAAG,CAAC,GAOxCO,IAAmB,CAC5BJ,GACAK,IAAoB,aAEpB,QAAQ,QAAA,EAAU,KAAK,MAAMC,EAAqBN,GAAKK,CAAO,CAAC,GAQtDE,IAAkB,CAC3BC,GACAC,MAEA,QAAQ,UAAU,KAAK,MAAMC,EAAoBF,GAAMC,CAAG,CAAC,GAMlDE,IAAgB,CACzBH,MAEA,QAAQ,QAAA,EAAU,KAAK,MAAMI,EAAkBJ,CAAI,CAAC,GAM3CK,IAAa,CAACb,MAAiB,QAAQ,QAAA,EAAU,KAAK,MAAMc,EAAed,CAAG,CAAC,GAG/Ee,IAAM;AAAA,EACf,QAAQnB;AAAA,EACR,QAAQG;AAAA,EACR,UAAUG;AAAA,EACV,YAAYE;AAAA,EACZ,YAAAS;AACJ,GAGaG,IAAO;AAAA,EAChB,aAAaT;AAAA,EACb,WAAWI;AACf;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourceregistry/node-jwt",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "A lightweight, zero-dependency TypeScript library for creating, verifying and decoding JSON Web Tokens (JWT).",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.es.js",