Skip to content

Commit 14f4643

Browse files
committed
Updating enclave.js
1 parent 487068f commit 14f4643

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

UIcode/src/Services/enclave.js

+39-29
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export async function getEncryptionKey(publicKey) {
6262
}
6363
);
6464
});
65-
66-
const { result } = getEncryptionKeyResult;
65+
const { result } = await getEncryptionKeyResult;
6766
const { taskPubKey } = result;
6867
// ToDo: verify signature
6968
return taskPubKey;
@@ -85,14 +84,8 @@ function decrypt(taskPubKey, privateKey, enc_variable) {
8584
return JSON.parse(outputStr);
8685
}
8786

88-
export async function addData(userId, data) {
89-
let { publicKey, privateKey } = getClientKeys();
90-
91-
let taskPubKey = await getEncryptionKey(publicKey);
92-
let encryptedUserId = encrypt(taskPubKey, privateKey, userId);
93-
let encryptedData = encrypt(taskPubKey, privateKey, data);
94-
95-
return await new Promise((resolve, reject) => {
87+
async function addPersonalData(encryptedUserId, encryptedData, publicKey) {
88+
const getEncryptionKeyResult = await new Promise((resolve, reject) => {
9689
client.request(
9790
"addPersonalData",
9891
{
@@ -109,32 +102,49 @@ export async function addData(userId, data) {
109102
}
110103
);
111104
});
105+
const { result } = await getEncryptionKeyResult;
106+
return result;
107+
}
108+
async function findMatchCall(encryptedUserId, publicKey) {
109+
const findMatchResult = await new Promise((resolve, reject) => {
110+
client.request(
111+
"findMatch",
112+
{
113+
encryptedUserId: encryptedUserId,
114+
userPubKey: publicKey,
115+
},
116+
(err, response) => {
117+
if (err) {
118+
reject(err);
119+
return;
120+
}
121+
resolve(response);
122+
}
123+
);
124+
});
125+
const { result } = await findMatchResult;
126+
return result;
112127
}
113128

114-
export async function findMatch(userId) {
129+
export async function addData(userId, data) {
115130
let { publicKey, privateKey } = getClientKeys();
131+
let taskPubKey = await getEncryptionKey(publicKey);
132+
let encryptedUserId = await encrypt(taskPubKey, privateKey, userId);
133+
let encryptedData = await encrypt(taskPubKey, privateKey, data);
134+
let addDataResult = await addPersonalData(
135+
encryptedUserId,
136+
encryptedData,
137+
taskPubKey
138+
);
139+
return addDataResult;
140+
}
116141

142+
export async function findMatch(userId) {
143+
let { publicKey, privateKey } = getClientKeys();
117144
try {
118145
let taskPubKey = await getEncryptionKey(publicKey);
119146
let encryptedUserId = encrypt(taskPubKey, privateKey, userId);
120-
121-
const findMatchResult = await new Promise((resolve, reject) => {
122-
client.request(
123-
"findMatch",
124-
{
125-
encryptedUserId: encryptedUserId,
126-
userPubKey: publicKey,
127-
},
128-
(err, response) => {
129-
if (err) {
130-
reject(err);
131-
return;
132-
}
133-
resolve(response);
134-
}
135-
);
136-
});
137-
147+
let findMatchResult = await findMatchCall(encryptedUserId, taskPubKey);
138148
if (findMatchResult.findMatch.status === 0) {
139149
return decrypt(
140150
taskPubKey,

0 commit comments

Comments
 (0)