99/*eslint no-console: ["error", { allow: ["warn", "error"] }] */
1010define ( [ 'helper/mpc' , 'controllers/tableController' , 'filesaver' ] , function ( mpc , tableController , filesaver ) {
1111
12+ function parseWebShares ( data ) {
13+ let arr = [ ] ;
14+ for ( var d of data ) {
15+ arr . push ( d . fields ) ;
16+ }
17+ return arr ;
18+ }
19+
1220 // Takes callback(true|false, data).
1321 function aggregate_and_unmask ( mOut , analyticsMasks , privateKey , session , password , callback ) {
1422
1523 aMOut = JSON . parse ( analyticsMasks . data ) ;
16-
17- console . log ( 'analytics mask' , aMOut ) ;
18-
1924 mOut = JSON . parse ( mOut . data ) ;
20- // console.log(mOut);
2125 // Questions Public is the public answers to questions.
2226 var questions_public = [ ] ;
2327 for ( var i = 0 ; i < mOut . length ; i ++ ) {
@@ -45,36 +49,36 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
4549 // decrypted is a list of promises, each promise
4650 // corresponding to a submission with decrypted
4751 // value fields
52+ // var decryptedLytics = decryptValueShares(sk, aMOut, true);
4853 var decrypted = decryptValueShares ( sk , mOut , true ) ;
49- console . log ( decrypted )
5054 questions_public = decryptValueShares ( sk , questions_public , false ) ;
5155
5256 // Aggregate decrypted values by key
5357 var analystResultShare = decrypted . then ( function ( analystShares ) {
54- // var invalidShareCount = mpc.countInvalidShares(analystShares);
55- // TODO: we should set a threshold and abort if there are too
56- // many invalid shares
57- // console.log('Invalid share count:', invalidShareCount);
5858 return mpc . aggregateShares ( analystShares ) ;
5959 } ) ;
6060
61+ var webShares = parseWebShares ( aMOut ) ;
62+ var webCombinedShares = mpc . aggregateShares ( webShares ) ;
63+
6164 // Request service to aggregate its shares and send us the result
6265 var serviceResultShare = getServiceResultShare ( session , password ) ;
6366
64- var analyticsShares = getAnalyticsShares ( session , password ) ;
67+ var webAggShares = getAnalyticsShares ( session , password ) ;
6568
66- console . log ( analyticsShares ) ;
67-
68- Promise . all ( [ analystResultShare , serviceResultShare , questions_public ] )
69+ Promise . all ( [ analystResultShare , serviceResultShare , questions_public , webAggShares ] )
6970 . then ( function ( resultShares ) {
7071 var analystResult = resultShares [ 0 ] ,
7172 serviceResult = resultShares [ 1 ] ,
7273 finalResult = mpc . recombineValues ( serviceResult , analystResult ) ;
74+
75+ usabilityResults = mpc . recombineValues ( resultShares [ 3 ] , webCombinedShares ) ;
76+
7377 if ( ! ensure_equal ( finalResult . questions , mpc . aggregateShares ( resultShares [ 2 ] ) ) ) {
7478 console . error ( 'Secret-shared question answers do not aggregate to the same values as publicly collected answers.' ) ;
7579 }
7680 // generateQuestionsCSV(resultShares[2], session)
77- callback ( true , finalResult , resultShares [ 2 ] , session ) ;
81+ callback ( true , finalResult , resultShares [ 2 ] , usabilityResults , session ) ;
7882
7983 } )
8084 . catch ( function ( err ) {
@@ -83,7 +87,7 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
8387 } ) ;
8488
8589 // Do the Hypercube
86- // NOTE: do we need this?
90+ // // NOTE: do we need this?
8791 // var cubes = getCubes(session, password);
8892 // Promise.all([cubes, sk]).then(function (results) {
8993 // var cubes = results[0];
@@ -159,15 +163,13 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
159163 function _decryptWithKey ( obj , importedKey ) {
160164 // decrypt one level of obj, decrypt nested object recursively
161165 var resultTuples = [ ] ;
162-
163166 for ( var key in obj ) {
164167 if ( obj . hasOwnProperty ( key ) ) {
165168 var value = obj [ key ] ;
166169 if ( typeof ( value ) === 'number' || typeof ( value ) === 'string' ) {
167170 // decrypt atomic value
168171 var resultTuple = window . crypto . subtle . decrypt ( { name : 'RSA-OAEP' } , importedKey , str2ab ( value ) )
169172 . then ( construct_tuple ( key , true ) ) ;
170-
171173 resultTuples . push ( resultTuple ) ;
172174 } else {
173175 resultTuples . push ( _decryptWithKey ( value , importedKey )
@@ -187,7 +189,7 @@ define(['helper/mpc', 'controllers/tableController', 'filesaver'], function (mpc
187189 */
188190 function decryptValueShares ( sk , maskedData , fields ) {
189191 return sk . then ( function ( importedKey ) {
190- // decrypt all masks
192+
191193 var all = [ ] ;
192194 for ( var d = 0 ; d < maskedData . length ; d ++ ) {
193195 all . push ( _decryptWithKey ( fields ? maskedData [ d ] . fields : maskedData [ d ] , importedKey ) ) ;
0 commit comments