blob: 054efbe2c5820513e4dc012ddc0575b3970487de [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test exporting a P-256 ECDH key pair with JWK format.");
jsTestIsAsync = true;
var algorithmKeyGen = {
name: "ECDH",
namedCurve: "P-256"
};
var extractable = true;
var keyPair;
debug("Generating a key pair...");
crypto.subtle.generateKey(algorithmKeyGen, extractable, ["deriveKey", "deriveBits"]).then(function(result) {
keyPair = result;
debug("Exporting the public key...");
return crypto.subtle.exportKey("jwk", keyPair.publicKey);
}).then(function(result) {
publicKey = result;
shouldBe("publicKey.kty", "'EC'");
shouldBe("publicKey.crv", "'P-256'");
shouldBe("Base64URL.parse(publicKey.x).byteLength", "32");
shouldBe("Base64URL.parse(publicKey.y).byteLength", "32");
shouldBeUndefined("publicKey.d");
shouldBe("publicKey.key_ops", "[ ]");
shouldBe("publicKey.ext", "true");
debug("Exporting the private key...");
return crypto.subtle.exportKey("jwk", keyPair.privateKey);
}).then(function(result) {
privateKey = result;
shouldBe("privateKey.kty", "'EC'");
shouldBe("privateKey.crv", "'P-256'");
shouldBe("Base64URL.parse(privateKey.x).byteLength", "32");
shouldBe("Base64URL.parse(privateKey.y).byteLength", "32");
shouldBe("Base64URL.parse(privateKey.d).byteLength", "32");
shouldBe("privateKey.key_ops", "['deriveBits', 'deriveKey']");
shouldBe("privateKey.ext", "true");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>