@@ -62,8 +62,7 @@ export async function getEncryptionKey(publicKey) {
62
62
}
63
63
) ;
64
64
} ) ;
65
-
66
- const { result } = getEncryptionKeyResult ;
65
+ const { result } = await getEncryptionKeyResult ;
67
66
const { taskPubKey } = result ;
68
67
// ToDo: verify signature
69
68
return taskPubKey ;
@@ -85,14 +84,8 @@ function decrypt(taskPubKey, privateKey, enc_variable) {
85
84
return JSON . parse ( outputStr ) ;
86
85
}
87
86
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 ) => {
96
89
client . request (
97
90
"addPersonalData" ,
98
91
{
@@ -109,32 +102,49 @@ export async function addData(userId, data) {
109
102
}
110
103
) ;
111
104
} ) ;
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 ;
112
127
}
113
128
114
- export async function findMatch ( userId ) {
129
+ export async function addData ( userId , data ) {
115
130
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
+ }
116
141
142
+ export async function findMatch ( userId ) {
143
+ let { publicKey, privateKey } = getClientKeys ( ) ;
117
144
try {
118
145
let taskPubKey = await getEncryptionKey ( publicKey ) ;
119
146
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 ) ;
138
148
if ( findMatchResult . findMatch . status === 0 ) {
139
149
return decrypt (
140
150
taskPubKey ,
0 commit comments