Update libsignal-protocol v0.13.0
* libsignal.Curve is now a synchronous interface. * libsignal.Curve.async is now the asynchronous interface. * Fixes bugs in session management. // FREEBIE
This commit is contained in:
		
					parent
					
						
							
								f216262298
							
						
					
				
			
			
				commit
				
					
						15e964de81
					
				
			
		
					 4 changed files with 406 additions and 275 deletions
				
			
		|  | @ -1,4 +1,6 @@ | |||
| ;(function(){ | ||||
| var Internal = {}; | ||||
| var libsignal = {}; | ||||
| // The Module object: Our interface to the outside world. We import
 | ||||
| // and export values on it, and do the work to get that through
 | ||||
| // closure compiler if necessary. There are various ways Module can be used:
 | ||||
|  | @ -25148,7 +25150,7 @@ run(); | |||
|  */ | ||||
| var Internal = Internal || {}; | ||||
| 
 | ||||
| Internal.curve25519 = function() { | ||||
| (function() { | ||||
|     'use strict'; | ||||
| 
 | ||||
|     // Insert some bytes into the emscripten memory and return a pointer
 | ||||
|  | @ -25166,38 +25168,35 @@ Internal.curve25519 = function() { | |||
|     var basepoint = new Uint8Array(32); | ||||
|     basepoint[0] = 9; | ||||
| 
 | ||||
|     return { | ||||
|     Internal.curve25519 = { | ||||
|         keyPair: function(privKey) { | ||||
|             return new Promise(function(resolve) { | ||||
|                 var priv = new Uint8Array(privKey); | ||||
|                 priv[0]  &= 248; | ||||
|                 priv[31] &= 127; | ||||
|                 priv[31] |= 64 | ||||
|             var priv = new Uint8Array(privKey); | ||||
|             priv[0]  &= 248; | ||||
|             priv[31] &= 127; | ||||
|             priv[31] |= 64 | ||||
| 
 | ||||
|                 // Where to store the result
 | ||||
|                 var publicKey_ptr = Module._malloc(32); | ||||
|             // Where to store the result
 | ||||
|             var publicKey_ptr = Module._malloc(32); | ||||
| 
 | ||||
|                 // Get a pointer to the private key
 | ||||
|                 var privateKey_ptr = _allocate(priv); | ||||
|             // Get a pointer to the private key
 | ||||
|             var privateKey_ptr = _allocate(priv); | ||||
| 
 | ||||
|                 // The basepoint for generating public keys
 | ||||
|                 var basepoint_ptr = _allocate(basepoint); | ||||
|             // The basepoint for generating public keys
 | ||||
|             var basepoint_ptr = _allocate(basepoint); | ||||
| 
 | ||||
|                 // The return value is just 0, the operation is done in place
 | ||||
|                 var err = Module._curve25519_donna(publicKey_ptr, | ||||
|                                                 privateKey_ptr, | ||||
|                                                 basepoint_ptr); | ||||
|             // The return value is just 0, the operation is done in place
 | ||||
|             var err = Module._curve25519_donna(publicKey_ptr, | ||||
|                                             privateKey_ptr, | ||||
|                                             basepoint_ptr); | ||||
| 
 | ||||
|                 var res = new Uint8Array(32); | ||||
|                 _readBytes(publicKey_ptr, 32, res); | ||||
|             var res = new Uint8Array(32); | ||||
|             _readBytes(publicKey_ptr, 32, res); | ||||
| 
 | ||||
|                 Module._free(publicKey_ptr); | ||||
|                 Module._free(privateKey_ptr); | ||||
|                 Module._free(basepoint_ptr); | ||||
| 
 | ||||
|                 resolve({ pubKey: res.buffer, privKey: privKey }); | ||||
|             }); | ||||
|             Module._free(publicKey_ptr); | ||||
|             Module._free(privateKey_ptr); | ||||
|             Module._free(basepoint_ptr); | ||||
| 
 | ||||
|             return { pubKey: res.buffer, privKey: priv.buffer }; | ||||
|         }, | ||||
|         sharedSecret: function(pubKey, privKey) { | ||||
|             // Where to store the result
 | ||||
|  | @ -25222,7 +25221,7 @@ Internal.curve25519 = function() { | |||
|             Module._free(privateKey_ptr); | ||||
|             Module._free(basepoint_ptr); | ||||
| 
 | ||||
|             return Promise.resolve(res.buffer); | ||||
|             return res.buffer; | ||||
|         }, | ||||
|         sign: function(privKey, message) { | ||||
|             // Where to store the result
 | ||||
|  | @ -25246,7 +25245,7 @@ Internal.curve25519 = function() { | |||
|             Module._free(privateKey_ptr); | ||||
|             Module._free(message_ptr); | ||||
| 
 | ||||
|             return Promise.resolve(res.buffer); | ||||
|             return res.buffer; | ||||
|         }, | ||||
|         verify: function(pubKey, message, sig) { | ||||
|             // Get a pointer to their public key
 | ||||
|  | @ -25267,21 +25266,43 @@ Internal.curve25519 = function() { | |||
|             Module._free(signature_ptr); | ||||
|             Module._free(message_ptr); | ||||
| 
 | ||||
|             return res !== 0; | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     Internal.curve25519_async = { | ||||
|         keyPair: function(privKey) { | ||||
|             return new Promise(function(resolve) { | ||||
|                 resolve(Internal.curve25519.keyPair(privKey)); | ||||
|             }); | ||||
|         }, | ||||
|         sharedSecret: function(pubKey, privKey) { | ||||
|             return new Promise(function(resolve) { | ||||
|                 resolve(Internal.curve25519.sharedSecret(pubKey, privKey)); | ||||
|             }); | ||||
|         }, | ||||
|         sign: function(privKey, message) { | ||||
|             return new Promise(function(resolve) { | ||||
|                 resolve(Internal.curve25519.sign(privKey, message)); | ||||
|             }); | ||||
|         }, | ||||
|         verify: function(pubKey, message, sig) { | ||||
|             return new Promise(function(resolve, reject) { | ||||
|                 if (res !== 0) { | ||||
|                 if (Internal.curve25519.verify(pubKey, message, sig)) { | ||||
|                     reject(new Error("Invalid signature")); | ||||
|                 } else { | ||||
|                     resolve(); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|         }, | ||||
|     }; | ||||
| }(); | ||||
| 
 | ||||
| })(); | ||||
| 
 | ||||
| var Internal = Internal || {}; | ||||
| // I am the worker
 | ||||
| this.onmessage = function(e) { | ||||
|     Internal.curve25519[e.data.methodName].apply(null, e.data.args).then(function(result) { | ||||
|     Internal.curve25519_async[e.data.methodName].apply(null, e.data.args).then(function(result) { | ||||
|         postMessage({ id: e.data.id, result: result }); | ||||
|     }).catch(function(error) { | ||||
|         postMessage({ id: e.data.id, error: error.message }); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 lilia
				lilia