Skip to content

Commit

Permalink
fix: Make JWK alg and key_ops fields optional. Issue #37
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Nov 10, 2021
1 parent 9fab59c commit 6eb3459
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/keys/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
11 changes: 10 additions & 1 deletion test/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down Expand Up @@ -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");
});

});

0 comments on commit 6eb3459

Please sign in to comment.