MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / signPdfFun

Function signPdfFun

apps/OpenSign/src/constant/Utils.js:910–993  ·  view source on GitHub ↗
(
  base64Url,
  documentId,
  signerObjectId,
  objectId,
  widgets,
  activity
)

Source from the content-addressed store, hash-verified

908
909//function for call cloud function signPdf and generate digital signature
910export const signPdfFun = async (
911 base64Url,
912 documentId,
913 signerObjectId,
914 objectId,
915 widgets,
916 activity
917) => {
918 let isCustomCompletionMail = false;
919 try {
920 //get tenant details
921 const tenantDetails = await getTenantDetails(objectId);
922 if (tenantDetails && tenantDetails === "user does not exist!") {
923 return { status: "error", message: "User does not exist." };
924 } else {
925 if (tenantDetails?.CompletionBody && tenantDetails?.CompletionSubject) {
926 isCustomCompletionMail = true;
927 }
928 }
929 // below for loop is used to get first signature of user to send if to signpdf
930 // for adding it in completion certificate
931 let getSignature;
932 for (let item of widgets) {
933 if (!getSignature) {
934 const typeExist = item.pos.some((data) => data?.type);
935 if (typeExist) {
936 getSignature = item.pos.find((data) => data?.type === "signature");
937 } else {
938 getSignature = item.pos.find((data) => !data.isStamp);
939 }
940 }
941 }
942
943 let base64Sign = getSignature?.SignUrl;
944 let suffixbase64 = "";
945 if (base64Sign) {
946 //check https type signature (default signature exist) then convert in base64
947 const isUrl = base64Sign.includes("https");
948 if (isUrl) {
949 try {
950 base64Sign = await fetchImageBase64(base64Sign);
951 } catch (e) {
952 console.log("error", e);
953 return { status: "error", message: "something went wrong." };
954 }
955 }
956 //change image width and height to 300/120 in png base64
957 const imagebase64 = await changeImageWH(base64Sign);
958 //remove suffiix of base64 (without type)
959 suffixbase64 = imagebase64 && imagebase64.split(",").pop();
960 }
961
962 const params = {
963 pdfFile: base64Url,
964 docId: documentId,
965 userId: signerObjectId,
966 isCustomCompletionMail: isCustomCompletionMail,
967 signature: suffixbase64,

Callers 1

embedWidgetsDataFunction · 0.90

Calls 3

getTenantDetailsFunction · 0.85
fetchImageBase64Function · 0.85
changeImageWHFunction · 0.85

Tested by

no test coverage detected