@verii/jwt 1.1.0-pre.1759611851 → 1.1.0-pre.1759923180

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/core.js +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verii/jwt",
3
- "version": "1.1.0-pre.1759611851",
3
+ "version": "1.1.0-pre.1759923180",
4
4
  "description": "Set of JWT related functions used in Verii projects",
5
5
  "repository": "https://github.com/LFDT-Verii/core",
6
6
  "main": "index.js",
@@ -18,15 +18,15 @@
18
18
  "license": "Apache-2.0",
19
19
  "dependencies": {
20
20
  "@trust/keyto": "~2.0.0-alpha1",
21
- "@verii/crypto": "1.1.0-pre.1759611851",
21
+ "@verii/crypto": "1.1.0-pre.1759923180",
22
22
  "canonicalize": "^2.1.0",
23
23
  "date-fns": "~3.6.0",
24
24
  "jose": "~5.10.0",
25
25
  "lodash": "^4.17.21"
26
26
  },
27
27
  "devDependencies": {
28
- "@verii/sample-data": "1.1.0-pre.1759611851",
29
- "@verii/test-regexes": "1.1.0-pre.1759611851",
28
+ "@verii/sample-data": "1.1.0-pre.1759923180",
29
+ "@verii/test-regexes": "1.1.0-pre.1759923180",
30
30
  "eslint": "8.57.1",
31
31
  "eslint-config-airbnb-base": "14.2.1",
32
32
  "eslint-config-prettier": "8.10.2",
@@ -45,5 +45,5 @@
45
45
  "lib"
46
46
  ]
47
47
  },
48
- "gitHead": "8868ae46c8c9cdcf6a98a33cc1ceef6c521fe7af"
48
+ "gitHead": "ce6f18b96ee098edb4a511d3deef48c3ed987fad"
49
49
  }
package/src/core.js CHANGED
@@ -21,6 +21,7 @@ const {
21
21
  calculateJwkThumbprint,
22
22
  decodeJwt,
23
23
  decodeProtectedHeader,
24
+ compactVerify: joseJwsVerify,
24
25
  base64url,
25
26
  } = require('jose');
26
27
  const canonicalize = require('canonicalize');
@@ -123,6 +124,18 @@ const jwtVerify = async (jwt, keyOrSecret, options = {}) => {
123
124
  return { header, payload };
124
125
  };
125
126
 
127
+ const jwsVerify = async (jws, keyOrSecret, options = {}) => {
128
+ const header = decodeProtectedHeader(jws);
129
+ const keyObject = isString(keyOrSecret)
130
+ ? new TextEncoder().encode(keyOrSecret)
131
+ : await toKeyObject(keyOrSecret, header);
132
+ const { payload } = await joseJwsVerify(jws, keyObject, {
133
+ clockTolerance: '120s',
134
+ ...options,
135
+ });
136
+ return { header, payload: JSON.parse(new TextDecoder().decode(payload)) };
137
+ };
138
+
126
139
  const isPem = startsWith('-----BEGIN');
127
140
 
128
141
  const jwkFromSecp256k1Key = (key, priv = true) => {
@@ -222,6 +235,7 @@ module.exports = {
222
235
  jwtSign,
223
236
  jwtSignSymmetric,
224
237
  jwkThumbprint,
238
+ jwsVerify,
225
239
  jwtVerify,
226
240
  publicKeyFromPrivateKey,
227
241
  safeJwtDecode,