Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!(algName === "ECDH" || algName === "ECDSA")) {
throw new Error("Error: Unsupported asymmetric key algorithm.");
}
if (publicKey.type !== "public") {
throw new Error("Error: Expected key type to be public but it was not.");
}
res.key = publicKey;
// Serialize public key to JWK
const jwk = await getEngine().crypto.subtle.exportKey("jwk", publicKey);
if (!(jwk.x && jwk.y)) {
throw new Error("Wrong JWK data for EC public key. Parameters x and y are required.");
}
const x = Convert.FromBase64Url(jwk.x);
const y = Convert.FromBase64Url(jwk.y);
const xy = Convert.ToBinary(x) + Convert.ToBinary(y);
res.serialized = Convert.FromBinary(xy);
res.id = await res.thumbprint();
return res;
}