using more then one async()
in a chain in the function breaks my function.
Is there a way i can include Key2pkcs8()
inside generateKey()
?
async function generateKey() {
let getKeyPair = await crypto.subtle.generateKey(
{
name: "ECDH",
namedCurve: "P-384"
},
false,
["deriveKey"]
);
let PriKey = async() => {
let PriKey = await getKeyPair.privateKey;
console.log("pri = " + PriKey);
return PriKey;
};
let PubKey = async() => {
let PubKey = await getKeyPair.publicKey;
console.log("pub = " + PubKey);
};
let Key2pkcs8 = async(PriKey, PubKey) => {
let Key2pkcs8Pub = await crypto.subtle.exportKey("pkcs8", PubKey);
let Key2pkcs8Pri = await crypto.subtle.exportKey("pkcs8", PriKey);
return pkcs8keyarray = [Key2pkcs8Pub, Key2pkcs8Pri];
return Keyarray = [PriKey(), PubKey()]; // i want to put <return pkcs8keyarray()> here
};
generateKey().then(Key2pkcs8 => console.log(Key2pkcs8[0], Key2pkcs8[1]));
works as expected and returns pri = [object CryptoKey]
Promise { <state>: "fulfilled", <value>: undefined } Promise { <state>: "fulfilled", <value>: CryptoKey }
but when using return pkcs8keyarray()
instead of return Keyarray = [PriKey(), PubKey()];
it breaks and returns undefined
i had intended to have key2pkcs2
take a key as a variable (public or private key) and then return both in a array at the end similar to the example