Skip to content

Commit

Permalink
refactor: removed the deprecated jwk/parse module
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The deprecated `jose/jwk/parse` module was
removed, use `import { importJWK } from 'jose'` instead.
  • Loading branch information
panva committed Oct 14, 2021
1 parent ec1d0e7 commit 8d3cc3b
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 113 deletions.
17 changes: 0 additions & 17 deletions docs/functions/jwk_parse.parseJwk.md

This file was deleted.

31 changes: 0 additions & 31 deletions docs/modules/jwk_parse.md

This file was deleted.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@
"import": "./dist/node/esm/jwk/embedded.js",
"require": "./dist/node/cjs/jwk/embedded.js"
},
"./jwk/parse": {
"browser": "./dist/browser/jwk/parse.js",
"import": "./dist/node/esm/jwk/parse.js",
"require": "./dist/node/cjs/jwk/parse.js"
},
"./jwk/thumbprint": {
"browser": "./dist/browser/jwk/thumbprint.js",
"import": "./dist/node/esm/jwk/thumbprint.js",
Expand Down
18 changes: 0 additions & 18 deletions src/jwk/parse.ts

This file was deleted.

14 changes: 7 additions & 7 deletions test/jwe/cookbook.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Promise.all([
import(`${root}/jwe/flattened/decrypt`),
import(`${root}/jwe/compact/encrypt`),
import(`${root}/jwe/compact/decrypt`),
import(`${keyRoot}/jwk/parse`),
import(`${keyRoot}/key/import`),
import(`${root}/util/base64url`),
]).then(
([
{ default: FlattenedEncrypt },
{ default: flattenedDecrypt },
{ default: CompactEncrypt },
{ default: compactDecrypt },
{ default: parseJwk },
{ importJWK },
base64url,
]) => {
const flattened = {
Expand Down Expand Up @@ -102,14 +102,14 @@ Promise.all([
}

if (vector.encrypting_key && vector.encrypting_key.epk) {
keyManagementParameters.epk = parseJwk(vector.encrypting_key.epk, 'ECDH');
keyManagementParameters.epk = importJWK(vector.encrypting_key.epk, 'ECDH');
}

if (Object.keys(keyManagementParameters) !== 0) {
encrypt.setKeyManagementParameters(keyManagementParameters);
}

const publicKey = await parseJwk(
const publicKey = await importJWK(
pubjwk(toJWK(vector.input.pwd || vector.input.key)),
dir ? vector.input.enc : vector.input.alg,
);
Expand All @@ -135,15 +135,15 @@ Promise.all([
encrypt.setUnprotectedHeader(vector.encrypting_content.unprotected);
}

const privateKey = await parseJwk(
const privateKey = await importJWK(
toJWK(vector.input.pwd || vector.input.key),
dir ? vector.input.enc : vector.input.alg,
);
let publicKey;
if (privateKey.type === 'secret') {
publicKey = privateKey;
} else {
publicKey = await parseJwk(
publicKey = await importJWK(
pubjwk(toJWK(vector.input.pwd || vector.input.key)),
dir ? vector.input.enc : vector.input.alg,
);
Expand All @@ -153,7 +153,7 @@ Promise.all([
await t.notThrowsAsync(flattened.decrypt(result, privateKey));
}

const privateKey = await parseJwk(
const privateKey = await importJWK(
toJWK(vector.input.pwd || vector.input.key),
dir ? vector.input.enc : vector.input.alg,
);
Expand Down
10 changes: 5 additions & 5 deletions test/jwe/smoke.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Promise.all([
import(`${root}/jwe/flattened/decrypt`),
import(`${root}/util/random`),
import(`${root}/util/base64url`),
import(`${keyRoot}/jwk/parse`),
import(`${keyRoot}/key/import`),
import(`${keyRoot}/util/generate_key_pair`),
import(`${keyRoot}/util/generate_secret`),
]).then(
Expand All @@ -26,7 +26,7 @@ Promise.all([
{ default: decryptFlattened },
{ default: random },
{ encode: base64url },
{ default: parseJwk },
{ importJWK },
{ default: generateKeyPair },
{ default: generateSecret },
]) => {
Expand Down Expand Up @@ -212,7 +212,7 @@ Promise.all([
publicKeyUsages || privateKeyUsage
? [...new Set([...publicKeyUsages, ...privateKeyUsage])]
: undefined;
const secret = await parseJwk({ ...fixtures.secret, key_ops }, alg, octAsKeyObject);
const secret = await importJWK({ ...fixtures.secret, key_ops }, alg, octAsKeyObject);
if (octAsKeyObject) {
t.false(secret instanceof Uint8Array);
} else {
Expand All @@ -222,8 +222,8 @@ Promise.all([
priv = secret;
} else {
[pub, priv] = await Promise.all([
parseJwk({ ...fixtures.public, key_ops: publicKeyUsages }, alg),
parseJwk({ ...fixtures.private, key_ops: privateKeyUsage }, alg),
importJWK({ ...fixtures.public, key_ops: publicKeyUsages }, alg),
importJWK({ ...fixtures.private, key_ops: privateKeyUsage }, alg),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions test/jwk/embedded.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ if ('WEBCRYPTO' in process.env) {
Promise.all([
import(`${root}/jws/flattened/sign`),
import(`${root}/jws/flattened/verify`),
import(`${keyRoot}/jwk/parse`),
import(`${keyRoot}/key/import`),
import(`${keyRoot}/jwk/embedded`),
]).then(
([
{ default: FlattenedSign },
{ default: flattenedVerify },
{ default: parseJwk },
{ importJWK },
{ default: EmbeddedJWK },
]) => {
function pubjwk(jwk) {
Expand All @@ -41,7 +41,7 @@ Promise.all([
kty: 'EC',
};

const privateKey = await parseJwk(t.context.key);
const privateKey = await importJWK(t.context.key);
t.context.token = await new FlattenedSign(
encode('It’s a dangerous business, Frodo, going out your door.'),
)
Expand Down
14 changes: 7 additions & 7 deletions test/jwks/remote.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ if ('WEBCRYPTO' in process.env) {
Promise.all([
import(`${root}/jwt/verify`),
import(`${root}/jwt/sign`),
import(`${keyRoot}/jwk/parse`),
import(`${keyRoot}/key/import`),
import(`${keyRoot}/jwks/remote`),
]).then(
([
{ default: jwtVerify },
{ default: SignJWT },
{ default: parseJwk },
{ importJWK },
{ default: createRemoteJWKSet },
]) => {
const now = 1604416038;
Expand Down Expand Up @@ -135,7 +135,7 @@ Promise.all([
const JWKS = createRemoteJWKSet(url);
{
const [jwk] = keys;
const key = await parseJwk({ ...jwk, alg: 'PS256' });
const key = await importJWK({ ...jwk, alg: 'PS256' });
const jwt = await new SignJWT({})
.setProtectedHeader({ alg: 'PS256', kid: jwk.kid })
.sign(key);
Expand All @@ -147,7 +147,7 @@ Promise.all([
}
{
const [jwk] = keys;
const key = await parseJwk({ ...jwk, alg: 'RS256' });
const key = await importJWK({ ...jwk, alg: 'RS256' });
const jwt = await new SignJWT({}).setProtectedHeader({ alg: 'RS256' }).sign(key);
await t.throwsAsync(jwtVerify(jwt, JWKS), {
code: 'ERR_JWKS_MULTIPLE_MATCHING_KEYS',
Expand All @@ -156,7 +156,7 @@ Promise.all([
}
{
const [, jwk] = keys;
const key = await parseJwk({ ...jwk, alg: 'PS256' });
const key = await importJWK({ ...jwk, alg: 'PS256' });
const jwt = await new SignJWT({})
.setProtectedHeader({ alg: 'PS256', kid: jwk.kid })
.sign(key);
Expand All @@ -167,7 +167,7 @@ Promise.all([
}
{
const [, , jwk] = keys;
const key = await parseJwk({ ...jwk, alg: 'ES256' });
const key = await importJWK({ ...jwk, alg: 'ES256' });
const jwt = await new SignJWT({}).setProtectedHeader({ alg: 'ES256' }).sign(key);
await t.notThrowsAsync(jwtVerify(jwt, JWKS));
}
Expand Down Expand Up @@ -198,7 +198,7 @@ Promise.all([

const url = new URL('https://as.example.com/jwks');
const JWKS = createRemoteJWKSet(url);
const key = await parseJwk({ ...jwk, alg: 'ES256' });
const key = await importJWK({ ...jwk, alg: 'ES256' });
{
const jwt = await new SignJWT({})
.setProtectedHeader({ alg: 'ES256', kid: 'one' })
Expand Down
12 changes: 6 additions & 6 deletions test/jws/cookbook.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Promise.all([
import(`${root}/jws/flattened/verify`),
import(`${root}/jws/compact/sign`),
import(`${root}/jws/compact/verify`),
import(`${keyRoot}/jwk/parse`),
import(`${keyRoot}/key/import`),
]).then(
([
{ default: FlattenedSign },
{ default: flattenedVerify },
{ default: CompactSign },
{ default: compactVerify },
{ default: parseJwk },
{ importJWK },
]) => {
const flattened = {
Sign: FlattenedSign,
Expand Down Expand Up @@ -66,7 +66,7 @@ Promise.all([
sign.setUnprotectedHeader(vector.signing.unprotected);
}

const privateKey = await parseJwk(vector.input.key, vector.input.alg);
const privateKey = await importJWK(vector.input.key, vector.input.alg);

const result = await sign.sign(privateKey);

Expand Down Expand Up @@ -95,14 +95,14 @@ Promise.all([
sign.setUnprotectedHeader(vector.signing.unprotected);
}

const privateKey = await parseJwk(vector.input.key, vector.input.alg);
const publicKey = await parseJwk(pubjwk(vector.input.key), vector.input.alg);
const privateKey = await importJWK(vector.input.key, vector.input.alg);
const publicKey = await importJWK(pubjwk(vector.input.key), vector.input.alg);

const result = await sign.sign(privateKey);
await t.notThrowsAsync(flattened.verify(result, publicKey));
}

const publicKey = await parseJwk(pubjwk(vector.input.key), vector.input.alg);
const publicKey = await importJWK(pubjwk(vector.input.key), vector.input.alg);

if (vector.output.json_flat) {
await t.notThrowsAsync(flattened.verify(vector.output.json_flat, publicKey));
Expand Down
16 changes: 8 additions & 8 deletions test/jws/restrictions.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Promise.all([
import(`${root}/util/random`),
import(`${root}/util/base64url`),
import(`${keyRoot}/util/generate_key_pair`),
import(`${keyRoot}/jwk/parse`),
import(`${keyRoot}/key/import`),
]).then(
([
{ default: FlattenedSign },
Expand All @@ -31,7 +31,7 @@ Promise.all([
{ default: random },
base64url,
{ default: generateKeyPair },
{ default: parseJwk },
{ importJWK },
]) => {
function pubjwk(jwk) {
const { d, p, q, dp, dq, qi, ...publicJwk } = jwk;
Expand Down Expand Up @@ -94,15 +94,15 @@ Promise.all([
await t.throwsAsync(
new FlattenedSign(t.context.payload)
.setProtectedHeader({ alg })
.sign(await parseJwk(keyBad, alg)),
.sign(await importJWK(keyBad, alg)),
{ instanceOf: TypeError, message },
);

const jws = await new FlattenedSign(t.context.payload)
.setProtectedHeader({ alg })
.sign(await parseJwk(keyOk, alg));
.sign(await importJWK(keyOk, alg));

await t.throwsAsync(flattenedVerify(jws, await parseJwk(pubjwk(keyBad), alg)), {
await t.throwsAsync(flattenedVerify(jws, await importJWK(pubjwk(keyBad), alg)), {
instanceOf: TypeError,
message,
});
Expand All @@ -117,15 +117,15 @@ Promise.all([
await t.throwsAsync(
new FlattenedEncrypt(t.context.payload)
.setProtectedHeader({ alg, enc: 'A256GCM' })
.encrypt(await parseJwk(pubjwk(keyBad), alg)),
.encrypt(await importJWK(pubjwk(keyBad), alg)),
{ instanceOf: TypeError, message },
);

const jwe = await new FlattenedEncrypt(t.context.payload)
.setProtectedHeader({ alg, enc: 'A256GCM' })
.encrypt(await parseJwk(pubjwk(keyOk), alg));
.encrypt(await importJWK(pubjwk(keyOk), alg));

await t.throwsAsync(flattenedDecrypt(jwe, await parseJwk(keyBad, alg)), {
await t.throwsAsync(flattenedDecrypt(jwe, await importJWK(keyBad, alg)), {
instanceOf: TypeError,
message,
});
Expand Down
Loading

0 comments on commit 8d3cc3b

Please sign in to comment.