2018-07-21 21:51:20 +00:00
|
|
|
/* global window, postMessage, textsecure, close */
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then, no-global-assign, no-restricted-globals, no-unused-vars */
|
2015-04-08 19:53:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Load this script in a Web Worker to generate new prekeys without
|
|
|
|
* tying up the main thread.
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API
|
|
|
|
*
|
|
|
|
* Because workers don't have access to the window or localStorage, we
|
|
|
|
* create our own version that proxies back to the caller for actual
|
|
|
|
* storage.
|
|
|
|
*
|
|
|
|
* Example usage:
|
|
|
|
*
|
|
|
|
var myWorker = new Worker('/js/key_worker.js');
|
|
|
|
myWorker.onmessage = function(e) {
|
|
|
|
switch(e.data.method) {
|
|
|
|
case 'set':
|
|
|
|
localStorage.setItem(e.data.key, e.data.value);
|
|
|
|
break;
|
|
|
|
case 'remove':
|
|
|
|
localStorage.removeItem(e.data.key);
|
|
|
|
break;
|
|
|
|
case 'done':
|
2018-07-21 19:00:08 +00:00
|
|
|
console.error(e.data.keys);
|
2015-04-08 19:53:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
*/
|
2018-07-21 21:51:20 +00:00
|
|
|
let store = {};
|
2015-04-08 19:53:04 +00:00
|
|
|
window.textsecure.storage.impl = {
|
2018-07-21 21:51:20 +00:00
|
|
|
/** ***************************
|
2018-05-02 01:54:43 +00:00
|
|
|
*** Override Storage Routines ***
|
2018-07-21 21:51:20 +00:00
|
|
|
**************************** */
|
|
|
|
put(key, value) {
|
2018-05-02 01:54:43 +00:00
|
|
|
if (value === undefined) throw new Error('Tried to store undefined');
|
|
|
|
store[key] = value;
|
2018-07-21 21:51:20 +00:00
|
|
|
postMessage({ method: 'set', key, value });
|
2018-05-02 01:54:43 +00:00
|
|
|
},
|
2015-04-08 19:53:04 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
get(key, defaultValue) {
|
2018-05-02 01:54:43 +00:00
|
|
|
if (key in store) {
|
|
|
|
return store[key];
|
|
|
|
}
|
2018-07-21 21:51:20 +00:00
|
|
|
return defaultValue;
|
2018-05-02 01:54:43 +00:00
|
|
|
},
|
2015-04-08 19:53:04 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
remove(key) {
|
2018-05-02 01:54:43 +00:00
|
|
|
delete store[key];
|
2018-07-21 21:51:20 +00:00
|
|
|
postMessage({ method: 'remove', key });
|
2018-05-02 01:54:43 +00:00
|
|
|
},
|
2015-04-08 19:53:04 +00:00
|
|
|
};
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
onmessage = e => {
|
2018-05-02 01:54:43 +00:00
|
|
|
store = e.data;
|
2018-07-21 21:51:20 +00:00
|
|
|
textsecure.protocol_wrapper.generateKeys().then(keys => {
|
|
|
|
postMessage({ method: 'done', keys });
|
2018-05-02 01:54:43 +00:00
|
|
|
close();
|
|
|
|
});
|
|
|
|
};
|