diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 58b6e00e6147e860f181b4b3e54bb38b45c8ba66..2c94611f4afa524d29bfc7be785ec2cc72960843 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1575,6 +1575,77 @@ const connection = Penpal.connectToParent({ messageUUID: messageUUID, }, "vCard signed"); }, + // vCardImageData = { + // contentType: "image/png", + // contentBase64: base 64 encoded image + // }; + // 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" + // } + validateVCard: async (vCardImageData, text, html, parts = null) => { + const authenticationPublicKey = localStorage.getItem( + "authenticatedIdentity" + ); + + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + //vCardImageData = new ImageData(vCardImageData); + + 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 validateVCardResponse = await executeRestfulFunction( + "private", + window.viamApi, + window.viamApi.signValidateVCard, + null, + parts + ); + if (validateVCardResponse.code !== "200") { + return encodeResponse("400", "", validateVCardResponse.status); + } + + //TODO - what will be the response? + + const signedVCardImageData = new ImageData(validateVCardResponse.data); + return encodeResponse("200", signedVCardImageData, "vCard signed"); + }, generateQrCode, documentCreateDocument: async (passportUUID, path, contentType, title) => { const authenticationPublicKey = localStorage.getItem(