fix: Make JWK `alg` and `key_ops` fields optional. Issue #37

This commit is contained in:
microshine 2021-11-10 03:00:20 +03:00
parent 9fab59c4dc
commit 6eb3459bc4
2 changed files with 11 additions and 2 deletions

View File

@ -17,6 +17,6 @@ export class CryptoKey extends core.CryptoKey {
@JsonProp({ type: JsonPropTypes.String })
protected kty = "oct";
@JsonProp({ type: JsonPropTypes.String })
@JsonProp({ type: JsonPropTypes.String, optional: true })
protected alg = "";
}

View File

@ -67,7 +67,7 @@ context("Crypto", () => {
it("Ed25519", async () => {
const keys = await crypto.subtle.generateKey({ name: "eddsa", namedCurve: "ed25519" } as globalThis.EcKeyGenParams, false, ["sign", "verify"]);
assert.strictEqual(keys.privateKey.algorithm.name, "EdDSA");
assert.strictEqual((keys.privateKey.algorithm as EcKeyAlgorithm).namedCurve, "Ed25519");
});
@ -195,4 +195,13 @@ context("Crypto", () => {
});
});
it("Import Secret JWK without 'alg' and 'key_ops' fields", async () => {
const aesKey = await crypto.subtle.generateKey({ name: "AES-CBC", length: 256 }, true, ["encrypt", "decrypt"]);
const jwk = await crypto.subtle.exportKey("jwk", aesKey);
delete jwk.key_ops;
delete jwk.alg;
const hmacKey = await crypto.subtle.importKey("jwk", jwk, { name: "HMAC", hash: "SHA-256" } as Algorithm, false, ["sign", "verify"]);
assert.strictEqual(hmacKey.algorithm.name, "HMAC");
});
});