Skip to content
Snippets Groups Projects
Commit dbc2f61a authored by Damyan Mitev's avatar Damyan Mitev :beach:
Browse files

add signVCard function

parent 911bb0e4
No related branches found
No related tags found
1 merge request!71[VCL] Sign generated v-card upon using a profile
......@@ -1403,6 +1403,119 @@ const connection = Penpal.connectToParent({
return encodeResponse("200", "", "Document signed");
},
// passportUUID - passport to sign the vCard
// text, html - the text and html part of the email
// related, attachments - array of objects, containing hashes of images/objects, related to the html in format:
// {
// headers: {
// "Content-Type": "application/hash; algorithm=SHA-256",
// "Original-Content-Type": "image/jpeg", //original content type
// "Content-Disposition": "inline" or "attachment",
// ... //other headers
// },
// body: "base64 encoded hash"
// }
signVCard: async (passportUUID, text, html, parts = null) => {
const authenticationPublicKey = localStorage.getItem(
"authenticatedIdentity"
);
if (
!authenticationPublicKey ||
!window.loadedIdentities[authenticationPublicKey] ||
!extendPinCodeTtl(authenticationPublicKey)
) {
return encodeResponse("400", "", "Identity not authenticated");
}
const vCardImageResponse = await executeRestfulFunction(
"private",
window.viamApi,
window.viamApi.passportGetVCardImage,
null,
passportUUID
);
if (vCardImageResponse.code !== "200") {
return encodeResponse("400", "", vCardImageResponse.status);
}
const vCardImageData = vCardImageResponse.data;
if (vCardImageData.contentType !== "image/png") {
return encodeResponse("400", "", "Content type of vCard mmust be 'image/png'");
}
if (!parts) {
parts = [];
}
if (html) {
const htmlPart = {
headers: {
"Content-Type": "text/html"
},
body: stringToUtf8Base64(html)
};
parts.unshift(htmlPart);
}
if (text) {
const textPart = {
headers: {
"Content-Type": "text/plain"
},
body: stringToUtf8Base64(text)
};
parts.unshift(textPart);
}
const certResponse = await getCertificateForPassport(passportUUID, true);
if (certResponse.code !== "200") {
return encodeResponse("400", "", certResponse.status);
}
const {
x509Certificate: passportCertificate,
privateKey: passportPrivateKey,
chain: passportChain
} = certResponse.data;
const keys = await createOneTimePassportCertificate(
makeid() + "-" + passportUUID,
null,
passportPrivateKey,
passportCertificate
);
const {
privateKeyPEM: privateKeyOneTime,
certificatePEM: certificateOneTime
} = keys;
passportChain.reverse();
passportChain.push(passportCertificate);
passportChain.push(certificateOneTime);
passportChain.reverse();
const signVCardResponse = await executeRestfulFunction(
"private",
window.viamApi,
window.viamApi.signSignVCardForChain,
null,
vCardImageData,
privateKeyOneTime,
passportChain,
parts
);
if (signVCardResponse.code !== "200") {
return encodeResponse("400", "", signVCardResponse.status);
}
return encodeResponse("200", signVCardResponse.data, "vCard signed");
},
documentCreateDocument: async (passportUUID, path, contentType, title) => {
const authenticationPublicKey = localStorage.getItem(
"authenticatedIdentity"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment