Skip to content

🔥 The free & Open Source DocuSign alternative

fix: change randomId generator

prafull-opensignlabsf57fcd25c9a7
diff --git a/apps/OpenSign/src/components/pdf/PlaceholderCopy.js b/apps/OpenSign/src/components/pdf/PlaceholderCopy.js
index be1646d08..4ae92e18f 100644
--- a/apps/OpenSign/src/components/pdf/PlaceholderCopy.js
+++ b/apps/OpenSign/src/components/pdf/PlaceholderCopy.js
@@ -1,17 +1,12 @@
import React, { useState } from "react";
import { themeColor } from "../../constant/const";
import ModalUi from "../../primitives/ModalUi";
+import { randomId } from "../../constant/Utils";
function PlaceholderCopy(props) {
const copyType = ["All pages", "All pages but last", "All pages but first"];
const [selectCopyType, setSelectCopyType] = useState("");
- //get RandomKey Id
- const randomKey = () => {
- const randomId = Math.floor(1000 + Math.random() * 9000);
- return randomId;
- };
-
//function for get copy placeholder position
const getCopyPlaceholderPosition = (
type,
@@ -88,7 +83,7 @@ function PlaceholderCopy(props) {
);
for (let i = 0; i < props.allPages; i++) {
- const newId = randomKey();
+ const newId = randomId();
currentPlaceholder.key = newId;
//get exist placeholder position for particular page
const existPlaceholder = filterSignerPosition[0].placeHolder.filter(
@@ -156,7 +151,7 @@ function PlaceholderCopy(props) {
const existPlaceholderPosition =
existPlaceholder[0] && existPlaceholder[0].pos;
- const newId = randomKey();
+ const newId = randomId();
currentPlaceholder.key = newId;
//function for get copy to requested location of placeholder position
const getPlaceholderObj = getCopyPlaceholderPosition(
diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.js
index 0d040d46a..615ce9cf5 100644
--- a/apps/OpenSign/src/constant/Utils.js
+++ b/apps/OpenSign/src/constant/Utils.js
@@ -479,7 +479,12 @@ export const signPdfFun = async (
return response;
};
-export const randomId = () => Math.floor(1000 + Math.random() * 9000);
+export const randomId = () => {
+ const randomBytes = crypto.getRandomValues(new Uint16Array(1));
+ const randomValue = randomBytes[0];
+ const randomDigit = 1000 + (randomValue % 9000);
+ return randomDigit;
+};
export const createDocument = async (template, placeholders, signerData) => {
if (template && template.length > 0) {
diff --git a/apps/OpenSign/src/pages/SignyourselfPdf.js b/apps/OpenSign/src/pages/SignyourselfPdf.js
index 29c1bc8ca..2bfba0070 100644
--- a/apps/OpenSign/src/pages/SignyourselfPdf.js
+++ b/apps/OpenSign/src/pages/SignyourselfPdf.js
@@ -24,7 +24,8 @@ import {
onSaveImage,
onSaveSign,
contractUsers,
- contactBook
+ contactBook,
+ randomId
} from "../constant/Utils";
import { useParams } from "react-router-dom";
import Tour from "reactour";
@@ -406,7 +407,7 @@ function SignYourSelf() {
};
//function for setting position after drop signature button over pdf
const addPositionOfSignature = (item, monitor) => {
- const key = Math.floor(1000 + Math.random() * 9000);
+ const key = randomId();
let dropData = [];
let dropObj = {};
let filterDropPos = xyPostion.filter(