jose 4.6.0 → 4.6.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.
@@ -39,8 +39,9 @@ export class LocalJWKSet {
39
39
  }
40
40
  async getKey(protectedHeader, token) {
41
41
  const { alg, kid } = { ...protectedHeader, ...token.header };
42
+ const kty = getKtyFromAlg(alg);
42
43
  const candidates = this._jwks.keys.filter((jwk) => {
43
- let candidate = jwk.kty === getKtyFromAlg(alg);
44
+ let candidate = kty === jwk.kty;
44
45
  if (candidate && typeof kid === 'string') {
45
46
  candidate = kid === jwk.kid;
46
47
  }
@@ -39,19 +39,13 @@ export function lengthAndInput(input) {
39
39
  }
40
40
  export async function concatKdf(secret, bits, value) {
41
41
  const iterations = Math.ceil((bits >> 3) / 32);
42
- let res;
43
- for (let iter = 1; iter <= iterations; iter++) {
42
+ const res = new Uint8Array(iterations * 32);
43
+ for (let iter = 0; iter < iterations; iter++) {
44
44
  const buf = new Uint8Array(4 + secret.length + value.length);
45
- buf.set(uint32be(iter));
45
+ buf.set(uint32be(iter + 1));
46
46
  buf.set(secret, 4);
47
47
  buf.set(value, 4 + secret.length);
48
- if (!res) {
49
- res = await digest('sha256', buf);
50
- }
51
- else {
52
- res = concat(res, await digest('sha256', buf));
53
- }
48
+ res.set(await digest('sha256', buf), iter * 32);
54
49
  }
55
- res = res.slice(0, bits >> 3);
56
- return res;
50
+ return res.slice(0, bits >> 3);
57
51
  }
@@ -15,9 +15,12 @@ export const encode = (input) => {
15
15
  return encodeBase64(input).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
16
16
  };
17
17
  export const decodeBase64 = (encoded) => {
18
- return new Uint8Array(atob(encoded)
19
- .split('')
20
- .map((c) => c.charCodeAt(0)));
18
+ const binary = atob(encoded);
19
+ const bytes = new Uint8Array(binary.length);
20
+ for (let i = 0; i < binary.length; i++) {
21
+ bytes[i] = binary.charCodeAt(i);
22
+ }
23
+ return bytes;
21
24
  };
22
25
  export const decode = (input) => {
23
26
  let encoded = input;
@@ -43,8 +43,9 @@ class LocalJWKSet {
43
43
  }
44
44
  async getKey(protectedHeader, token) {
45
45
  const { alg, kid } = { ...protectedHeader, ...token.header };
46
+ const kty = getKtyFromAlg(alg);
46
47
  const candidates = this._jwks.keys.filter((jwk) => {
47
- let candidate = jwk.kty === getKtyFromAlg(alg);
48
+ let candidate = kty === jwk.kty;
48
49
  if (candidate && typeof kid === 'string') {
49
50
  candidate = kid === jwk.kid;
50
51
  }
@@ -47,20 +47,14 @@ function lengthAndInput(input) {
47
47
  exports.lengthAndInput = lengthAndInput;
48
48
  async function concatKdf(secret, bits, value) {
49
49
  const iterations = Math.ceil((bits >> 3) / 32);
50
- let res;
51
- for (let iter = 1; iter <= iterations; iter++) {
50
+ const res = new Uint8Array(iterations * 32);
51
+ for (let iter = 0; iter < iterations; iter++) {
52
52
  const buf = new Uint8Array(4 + secret.length + value.length);
53
- buf.set(uint32be(iter));
53
+ buf.set(uint32be(iter + 1));
54
54
  buf.set(secret, 4);
55
55
  buf.set(value, 4 + secret.length);
56
- if (!res) {
57
- res = await (0, digest_js_1.default)('sha256', buf);
58
- }
59
- else {
60
- res = concat(res, await (0, digest_js_1.default)('sha256', buf));
61
- }
56
+ res.set(await (0, digest_js_1.default)('sha256', buf), iter * 32);
62
57
  }
63
- res = res.slice(0, bits >> 3);
64
- return res;
58
+ return res.slice(0, bits >> 3);
65
59
  }
66
60
  exports.concatKdf = concatKdf;
@@ -84,12 +84,13 @@ async function generateKeyPair(alg, options) {
84
84
  case 'ECDH-ES+A128KW':
85
85
  case 'ECDH-ES+A192KW':
86
86
  case 'ECDH-ES+A256KW':
87
- switch (options === null || options === void 0 ? void 0 : options.crv) {
87
+ const crv = (_b = options === null || options === void 0 ? void 0 : options.crv) !== null && _b !== void 0 ? _b : 'P-256';
88
+ switch (crv) {
88
89
  case undefined:
89
90
  case 'P-256':
90
91
  case 'P-384':
91
92
  case 'P-521':
92
- return generate('ec', { namedCurve: (_b = options === null || options === void 0 ? void 0 : options.crv) !== null && _b !== void 0 ? _b : 'P-256' });
93
+ return generate('ec', { namedCurve: crv });
93
94
  case 'X25519':
94
95
  return generate('x25519');
95
96
  case 'X448':
@@ -39,8 +39,9 @@ export class LocalJWKSet {
39
39
  }
40
40
  async getKey(protectedHeader, token) {
41
41
  const { alg, kid } = { ...protectedHeader, ...token.header };
42
+ const kty = getKtyFromAlg(alg);
42
43
  const candidates = this._jwks.keys.filter((jwk) => {
43
- let candidate = jwk.kty === getKtyFromAlg(alg);
44
+ let candidate = kty === jwk.kty;
44
45
  if (candidate && typeof kid === 'string') {
45
46
  candidate = kid === jwk.kid;
46
47
  }
@@ -39,19 +39,13 @@ export function lengthAndInput(input) {
39
39
  }
40
40
  export async function concatKdf(secret, bits, value) {
41
41
  const iterations = Math.ceil((bits >> 3) / 32);
42
- let res;
43
- for (let iter = 1; iter <= iterations; iter++) {
42
+ const res = new Uint8Array(iterations * 32);
43
+ for (let iter = 0; iter < iterations; iter++) {
44
44
  const buf = new Uint8Array(4 + secret.length + value.length);
45
- buf.set(uint32be(iter));
45
+ buf.set(uint32be(iter + 1));
46
46
  buf.set(secret, 4);
47
47
  buf.set(value, 4 + secret.length);
48
- if (!res) {
49
- res = await digest('sha256', buf);
50
- }
51
- else {
52
- res = concat(res, await digest('sha256', buf));
53
- }
48
+ res.set(await digest('sha256', buf), iter * 32);
54
49
  }
55
- res = res.slice(0, bits >> 3);
56
- return res;
50
+ return res.slice(0, bits >> 3);
57
51
  }
@@ -80,12 +80,13 @@ export async function generateKeyPair(alg, options) {
80
80
  case 'ECDH-ES+A128KW':
81
81
  case 'ECDH-ES+A192KW':
82
82
  case 'ECDH-ES+A256KW':
83
- switch (options === null || options === void 0 ? void 0 : options.crv) {
83
+ const crv = (_b = options === null || options === void 0 ? void 0 : options.crv) !== null && _b !== void 0 ? _b : 'P-256';
84
+ switch (crv) {
84
85
  case undefined:
85
86
  case 'P-256':
86
87
  case 'P-384':
87
88
  case 'P-521':
88
- return generate('ec', { namedCurve: (_b = options === null || options === void 0 ? void 0 : options.crv) !== null && _b !== void 0 ? _b : 'P-256' });
89
+ return generate('ec', { namedCurve: crv });
89
90
  case 'X25519':
90
91
  return generate('x25519');
91
92
  case 'X448':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.6.0",
3
+ "version": "4.6.1",
4
4
  "description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto",
5
5
  "keywords": [
6
6
  "browser",