fix: Make JWK `alg` and `key_ops` fields optional. Issue #37
This commit is contained in:
parent
9fab59c4dc
commit
6eb3459bc4
|
@ -17,6 +17,6 @@ export class CryptoKey extends core.CryptoKey {
|
||||||
@JsonProp({ type: JsonPropTypes.String })
|
@JsonProp({ type: JsonPropTypes.String })
|
||||||
protected kty = "oct";
|
protected kty = "oct";
|
||||||
|
|
||||||
@JsonProp({ type: JsonPropTypes.String })
|
@JsonProp({ type: JsonPropTypes.String, optional: true })
|
||||||
protected alg = "";
|
protected alg = "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ context("Crypto", () => {
|
||||||
|
|
||||||
it("Ed25519", async () => {
|
it("Ed25519", async () => {
|
||||||
const keys = await crypto.subtle.generateKey({ name: "eddsa", namedCurve: "ed25519" } as globalThis.EcKeyGenParams, false, ["sign", "verify"]);
|
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.name, "EdDSA");
|
||||||
assert.strictEqual((keys.privateKey.algorithm as EcKeyAlgorithm).namedCurve, "Ed25519");
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Reference in New Issue