secure-webstore
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("SecureStore",[],e):"object"==typeof exports?exports.SecureStore=e():t.SecureStore=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0}),e._idb=e.Store=void 0;var u=r(1),s=r(2),a=function(){function t(t,e){if(this.storeName=t,this.passphrase=e,!t||!e)throw new Error("Store name and passphrase required");this.store=new u.Store(t,t)}return Object.defineProperty(t.prototype,"key",{get:function(){if(!this._key)throw new Error("Master key not initialized");return this._key},enumerable:!1,configurable:!0}),t.prototype.init=function(){return n(this,void 0,void 0,(function(){var t,e,r,n=this;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,6,,7]),[4,u.get("__key",this.store)];case 1:return(t=o.sent())?[3,4]:[4,s.genEncryptedMasterKey(this.passphrase)];case 2:return t=o.sent(),[4,u.set("__key",t,this.store)];case 3:o.sent(),o.label=4;case 4:return this.encMasterKey=t,e=this,[4,s.decryptMasterKey(this.passphrase,this.encMasterKey)];case 5:return e._key=o.sent(),window.addEventListener("freeze",(function(){n.close()})),[3,7];case 6:throw r=o.sent(),new Error(r.message);case 7:return[2]}}))}))},t.prototype.updatePassphrase=function(t,e){return n(this,void 0,void 0,(function(){var r,n;return o(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,3,,4]),!this.encMasterKey)throw new Error("No password to update set");return[4,s.updatePassphraseKey(t,e,this.encMasterKey)];case 1:return r=o.sent(),[4,u.set("__key",r,this.store)];case 2:return o.sent(),this.encMasterKey=r,[3,4];case 3:throw n=o.sent(),new Error(n.message);case 4:return[2]}}))}))},t.prototype.set=function(t,e){return n(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,s.encrypt(this.key,e)];case 1:return e=r.sent(),[2,u.set(t,e,this.store)]}}))}))},t.prototype.get=function(t){return n(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return[4,u.get(t,this.store)];case 1:return(e=r.sent())?[4,s.decrypt(this.key,e)]:[2,e];case 2:return[2,r.sent()]}}))}))},t.prototype.del=function(t){return u.del(t,this.store)},t.prototype.keys=function(){return u.keys(this.store)},t.prototype.clear=function(){return u.clear(this.store)},t.prototype.close=function(){return u.close(this.store)},t.prototype.destroy=function(){var t=this;return new Promise((function(e,r){t.close();var n=window.indexedDB.deleteDatabase(t.storeName);n.onsuccess=function(t){e(t)},n.onerror=function(t){r(t)}}))},t.prototype.export=function(){return n(this,void 0,void 0,(function(){var t,e,r,n,s,a,f,c,h;return o(this,(function(o){switch(o.label){case 0:return t={},[4,this.keys()];case 1:if(!(e=o.sent()))return[3,9];o.label=2;case 2:o.trys.push([2,7,8,9]),r=i(e),n=r.next(),o.label=3;case 3:return n.done?[3,6]:"string"!=typeof(s=n.value)&&"number"!=typeof s?[3,5]:[4,u.get(s,this.store)];case 4:a=o.sent(),t[s]=a,o.label=5;case 5:return n=r.next(),[3,3];case 6:return[3,9];case 7:return f=o.sent(),c={error:f},[3,9];case 8:try{n&&!n.done&&(h=r.return)&&h.call(r)}finally{if(c)throw c.error}return[7];case 9:return[2,t]}}))}))},t.prototype.import=function(t){return n(this,void 0,void 0,(function(){var e,r,n,s,a,f;return o(this,(function(o){switch(o.label){case 0:if(!t||0===Object.keys(t).length)throw new Error("No data provided");if("[object Object]"!==Object.prototype.toString.call(t))throw new Error("Data must be a valid JSON object");o.label=1;case 1:o.trys.push([1,6,7,8]),e=i(Object.keys(t)),r=e.next(),o.label=2;case 2:return r.done?[3,5]:(n=r.value,[4,u.set(n,t[n],this.store)]);case 3:o.sent(),o.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return s=o.sent(),a={error:s},[3,8];case 7:try{r&&!r.done&&(f=e.return)&&f.call(e)}finally{if(a)throw a.error}return[7];case 8:return[2]}}))}))},t}();e.Store=a;var f=u;e._idb=f},function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.close=e.keys=e.clear=e.del=e.set=e.get=e.Store=void 0;var i,u=function(){function t(t,e){void 0===t&&(t="keyval-store"),void 0===e&&(e="keyval"),this.storeName=e,this._dbName=t,this._storeName=e,this._init()}return t.prototype._withIDBStore=function(t,e){return n(this,void 0,void 0,(function(){var r,n,i=this;return o(this,(function(o){switch(o.label){case 0:return[4,this._init()];case 1:return r=o.sent(),[4,new Promise((function(o,u){var s=r.transaction(i.storeName,t);s.oncomplete=function(){return o()},s.onabort=s.onerror=function(){return u(s.error)},n=e(s.objectStore(i.storeName))}))];case 2:return o.sent(),[2,n]}}))}))},t.prototype._init=function(){return n(this,void 0,void 0,(function(){var t,e=this;return o(this,(function(r){switch(r.label){case 0:return this._dbp?[2,this._dbp]:(t=this,[4,new Promise((function(t,r){var n=window.indexedDB.open(e._dbName,1);n.onerror=function(){return r(n.error)},n.onsuccess=function(){return t(n.result)},n.onupgradeneeded=function(){n.result.createObjectStore(e._storeName)}}))]);case 1:return t._dbp=r.sent(),this._dbp.onclose=function(){e._dbp=void 0},this._dbp.onversionchange=function(t){var r;null===t.newVersion&&(console.log("Got delete request for db"),null===(r=e._dbp)||void 0===r||r.close())},[2,this._dbp]}}))}))},t.prototype._close=function(){var t;null===(t=this._dbp)||void 0===t||t.close()},t}();function s(){return i||(i=new u),i}e.Store=u,e.get=function(t,e){return void 0===e&&(e=s()),n(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,e._withIDBStore("readonly",(function(e){return e.get(t)}))];case 1:return[2,r.sent().result]}}))}))},e.set=function(t,e,r){return void 0===r&&(r=s()),r._withIDBStore("readwrite",(function(r){r.put(e,t)}))},e.del=function(t,e){return void 0===e&&(e=s()),e._withIDBStore("readwrite",(function(e){e.delete(t)}))},e.clear=function(t){return void 0===t&&(t=s()),t._withIDBStore("readwrite",(function(t){t.clear()}))},e.keys=function(t){return void 0===t&&(t=s()),t._withIDBStore("readonly",(function(t){var e=[];return(t.openKeyCursor||t.openCursor).call(t).onsuccess=function(){this.result&&(e.push(this.result.key),this.result.continue())},e}))},e.close=function(t){return void 0===t&&(t=s()),t._close()}},function(t,e,r){window,t.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";(function(t){var r=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))},n=this&&this.__generator||function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};Object.defineProperty(e,"__esModule",{value:!0}),e._genRandomBufferAsStr=e._genRandomBuffer=e.updatePassphraseKey=e.decryptMasterKey=e.genEncryptedMasterKey=e.decryptBuffer=e.encryptBuffer=e.decrypt=e.encrypt=e.exportKey=e.importKey=e.genAESKey=e.verify=e.sign=e.exportPrivateKey=e.exportPublicKey=e.importPrivateKey=e.importPublicKey=e.genKeyPair=e.hash=e.genId=void 0;var o=function(t){if(!t.type||"secret"!==t.type)throw new Error("Invalid key type")},i=function(e){void 0===e&&(e=16);var r=window.crypto.getRandomValues(new Uint8Array(e));return t.from(r)},u=function(t,e){return void 0===t&&(t=16),void 0===e&&(e="hex"),e&&s(e),i(t).toString(e)},s=function(t){if("hex"!==t&&"base64"!==t)throw new Error("Invalid encoding")};e.genId=function(t){return void 0===t&&(t=32),u(Math.floor(t/2))},e.hash=function(e,o,i){return void 0===o&&(o="hex"),void 0===i&&(i="SHA-256"),r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.digest({name:i},"string"==typeof e?t.from(e):e)];case 1:return r=n.sent(),[2,t.from(r).toString(o)]}}))}))},e.genKeyPair=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e="P-256"),window.crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},t,["sign","verify"])},e.importPublicKey=function(e,r,n){return void 0===r&&(r="P-256"),void 0===n&&(n="base64"),window.crypto.subtle.importKey("spki","string"==typeof e?t.from(e,n):e,{name:"ECDSA",namedCurve:r},!0,["verify"])},e.importPrivateKey=function(e,r,n){return void 0===r&&(r="P-256"),void 0===n&&(n="base64"),window.crypto.subtle.importKey("pkcs8","string"==typeof e?t.from(e,n):e,{name:"ECDSA",namedCurve:r},!0,["sign"])},e.exportPublicKey=function(e,o){return void 0===o&&(o="base64"),r(this,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.exportKey("spki",e)];case 1:return r=n.sent(),[2,"raw"===o?new Uint8Array(r):t.from(r).toString(o)]}}))}))},e.exportPrivateKey=function(e,o){return void 0===o&&(o="base64"),r(this,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.exportKey("pkcs8",e)];case 1:return r=n.sent(),[2,"raw"===o?new Uint8Array(r):t.from(r).toString(o)]}}))}))},e.sign=function(e,o,i,u){return void 0===i&&(i="base64"),void 0===u&&(u="SHA-256"),r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.sign({name:"ECDSA",hash:{name:u}},e,t.from(JSON.stringify(o)))];case 1:return r=n.sent(),[2,"raw"===i?new Uint8Array(r):t.from(r).toString(i)]}}))}))},e.verify=function(e,o,i,u,s){return void 0===u&&(u="base64"),void 0===s&&(s="SHA-256"),r(void 0,void 0,void 0,(function(){return n(this,(function(r){return[2,window.crypto.subtle.verify({name:"ECDSA",hash:{name:s}},e,t.from(i,u),t.from(JSON.stringify(o)))]}))}))},e.genAESKey=function(t,e,r){return void 0===t&&(t=!0),void 0===e&&(e="AES-GCM"),void 0===r&&(r=128),window.crypto.subtle.generateKey({name:e,length:r},t,["decrypt","encrypt"])};var a=function(e,r,n){void 0===r&&(r="raw"),void 0===n&&(n="AES-GCM");var o="raw"===r?t.from(e,"base64"):e;return window.crypto.subtle.importKey(r,o,{name:n},!0,["encrypt","decrypt"])};e.importKey=a;var f=function(t,e){return void 0===e&&(e="raw"),r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.exportKey(e,t)];case 1:return r=n.sent(),[2,"raw"===e?new Uint8Array(r):r]}}))}))};e.exportKey=f;var c=function(t,e,o){return r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.encrypt(o,t,e)];case 1:return r=n.sent(),[2,new Uint8Array(r)]}}))}))};e.encryptBuffer=c;var h=function(t,e,o){return r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,window.crypto.subtle.decrypt(o,t,e)];case 1:return r=n.sent(),[2,new Uint8Array(r)];case 2:if("Unsupported state or unable to authenticate data"===n.sent().message)throw new Error("Unable to decrypt data");return[3,3];case 3:return[2]}}))}))};e.decryptBuffer=h;var l=function(e,u,s){return void 0===s&&(s="hex"),r(void 0,void 0,void 0,(function(){var r,a,f;return n(this,(function(n){switch(n.label){case 0:return o(e),r={iv:i("AES-GCM"===e.algorithm.name?12:16),plaintext:t.from(JSON.stringify(u))},a={name:e.algorithm.name,iv:r.iv},[4,c(e,r.plaintext,a)];case 1:return f=n.sent(),[2,{ciphertext:t.from(f).toString(s),iv:t.from(r.iv).toString(s)}]}}))}))};e.encrypt=l;var p=function(e,i,u){return void 0===u&&(u="hex"),r(void 0,void 0,void 0,(function(){var r,s,a;return n(this,(function(n){switch(n.label){case 0:o(e),r={ciphertext:t.from(Object.prototype.hasOwnProperty.call(i,"ciphertext")?i.ciphertext:"",u),iv:Object.prototype.hasOwnProperty.call(i,"iv")?t.from(i.iv,u):""},s={name:e.algorithm.name,iv:r.iv},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,h(e,r.ciphertext,s)];case 2:if(void 0===(a=n.sent()))throw new Error;return[2,JSON.parse(t.from(a).toString())];case 3:throw n.sent(),new Error("Unable to decrypt data");case 4:return[2]}}))}))};e.decrypt=p;var y=function(e,o,i,u){return r(void 0,void 0,void 0,(function(){var r,s;return n(this,(function(n){switch(n.label){case 0:return i<1e4&&console.warn("Less than 10000 :("),[4,window.crypto.subtle.importKey("raw","string"==typeof e?t.from(e):e,"PBKDF2",!1,["deriveBits","deriveKey"])];case 1:return r=n.sent(),[4,window.crypto.subtle.deriveBits({name:"PBKDF2",salt:o||new Uint8Array([]),iterations:i||1e5,hash:u||"SHA-256"},r,128)];case 2:return s=n.sent(),[2,new Uint8Array(s)]}}))}))},d=function(e,o,u,s){return void 0===o&&(o=i(16)),void 0===u&&(u=1e5),void 0===s&&(s="SHA-256"),r(void 0,void 0,void 0,(function(){var r,i;return n(this,(function(n){switch(n.label){case 0:return function(t){if("string"!=typeof t||""===t)throw new Error("Not a valid value")}(e),[4,y(e,o,u,s)];case 1:return r=n.sent(),[4,a(r)];case 2:return i=n.sent(),[2,{derivationParams:{salt:t.from(o).toString("hex"),iterations:u,hashAlgo:s},key:i}]}}))}))};e.genEncryptedMasterKey=function(t,e,o,i){return r(void 0,void 0,void 0,(function(){var r,s,a;return n(this,(function(n){switch(n.label){case 0:return[4,d(t,e,o,i)];case 1:return r=n.sent(),s=u(32,"hex"),[4,l(r.key,s)];case 2:return a=n.sent(),[2,{derivationParams:r.derivationParams,encryptedMasterKey:a}]}}))}))},e.updatePassphraseKey=function(e,o,i,u,s,a){return r(void 0,void 0,void 0,(function(){var r,c,h,p,y,w;return n(this,(function(n){switch(n.label){case 0:return[4,v(e,i)];case 1:return r=n.sent(),[4,d(o,u,s,a)];case 2:return c=n.sent(),y=(p=t).from,[4,f(r)];case 3:return h=y.apply(p,[n.sent()]).toString("hex"),[4,l(c.key,h)];case 4:return w=n.sent(),[2,{derivationParams:c.derivationParams,encryptedMasterKey:w}]}}))}))};var v=function(e,o){return r(void 0,void 0,void 0,(function(){var r,i,u,s,f,c,h,l,d,v;return n(this,(function(n){switch(n.label){case 0:if(!o.encryptedMasterKey||!o.derivationParams)throw new Error("Missing properties from master key");return r=o.derivationParams,i=o.encryptedMasterKey,u=r.salt,s=r.iterations,f=r.hashAlgo,c="string"==typeof u?t.from(u,"hex"):u,[4,y(e,c,s,f)];case 1:return h=n.sent(),[4,a(h)];case 2:l=n.sent(),n.label=3;case 3:return n.trys.push([3,5,,6]),[4,p(l,i)];case 4:return d=n.sent(),v=t.from(d,"hex"),[2,window.crypto.subtle.importKey("raw",v,{name:"AES-GCM"},!0,["encrypt","decrypt"])];case 5:throw n.sent(),new Error("Wrong passphrase");case 6:return[2]}}))}))};e.decryptMasterKey=v;var w=i;e._genRandomBuffer=w;var g=u;e._genRandomBufferAsStr=g}).call(this,r(1).Buffer)},function(t,e,r){"use strict";(function(t){ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("SecureStore",[],e):"object"==typeof exports?exports.SecureStore=e():t.SecureStore=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0}),e._idb=e.Store=void 0;var u=r(1),s=r(2),a=function(){function t(t,e){if(this.storeName=t,this.passphrase=e,!t||!e)throw new Error("Store name and passphrase required");this.store=new u.Store(t,t)}return Object.defineProperty(t.prototype,"key",{get:function(){if(!this._key)throw new Error("Master key not initialized");return this._key},enumerable:!1,configurable:!0}),t.prototype.init=function(){return n(this,void 0,void 0,(function(){var t,e,r,n=this;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,6,,7]),[4,u.get("__key",this.store)];case 1:return(t=o.sent())?[3,4]:[4,s.genEncryptedMasterKey(this.passphrase)];case 2:return t=o.sent(),[4,u.set("__key",t,this.store)];case 3:o.sent(),o.label=4;case 4:return this.encMasterKey=t,e=this,[4,s.decryptMasterKey(this.passphrase,this.encMasterKey)];case 5:return e._key=o.sent(),window.addEventListener("freeze",(function(){n.close()})),[3,7];case 6:throw r=o.sent(),new Error(r.message);case 7:return[2]}}))}))},t.prototype.updatePassphrase=function(t,e){return n(this,void 0,void 0,(function(){var r,n;return o(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,3,,4]),!this.encMasterKey)throw new Error("No password to update set");return[4,s.updatePassphraseKey(t,e,this.encMasterKey)];case 1:return r=o.sent(),[4,u.set("__key",r,this.store)];case 2:return o.sent(),this.encMasterKey=r,[3,4];case 3:throw n=o.sent(),new Error(n.message);case 4:return[2]}}))}))},t.prototype.set=function(t,e){return n(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,s.encrypt(this.key,e)];case 1:return e=r.sent(),[2,u.set(t,e,this.store)]}}))}))},t.prototype.get=function(t){return n(this,void 0,void 0,(function(){var e;return o(this,(function(r){switch(r.label){case 0:return[4,u.get(t,this.store)];case 1:return(e=r.sent())?[4,s.decrypt(this.key,e)]:[2,e];case 2:return[2,r.sent()]}}))}))},t.prototype.del=function(t){return u.del(t,this.store)},t.prototype.keys=function(){return n(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,u.keys(this.store)];case 1:return[2,t.sent().filter((function(t){return"__key"!==t}))]}}))}))},t.prototype.clear=function(){return u.clear(this.store)},t.prototype.close=function(){return u.close(this.store)},t.prototype.destroy=function(){var t=this;return new Promise((function(e,r){t.close();var n=window.indexedDB.deleteDatabase(t.storeName);n.onsuccess=function(t){e(t)},n.onerror=function(t){r(t)}}))},t.prototype.export=function(){return n(this,void 0,void 0,(function(){var t,e,r,n,s,a,f,c,h;return o(this,(function(o){switch(o.label){case 0:return t={},[4,this.keys()];case 1:if(!(e=o.sent()))return[3,9];o.label=2;case 2:o.trys.push([2,7,8,9]),r=i(e),n=r.next(),o.label=3;case 3:return n.done?[3,6]:"string"!=typeof(s=n.value)&&"number"!=typeof s?[3,5]:[4,u.get(s,this.store)];case 4:a=o.sent(),t[s]=a,o.label=5;case 5:return n=r.next(),[3,3];case 6:return[3,9];case 7:return f=o.sent(),c={error:f},[3,9];case 8:try{n&&!n.done&&(h=r.return)&&h.call(r)}finally{if(c)throw c.error}return[7];case 9:return[2,t]}}))}))},t.prototype.import=function(t){return n(this,void 0,void 0,(function(){var e,r,n,s,a,f;return o(this,(function(o){switch(o.label){case 0:if(!t||0===Object.keys(t).length)throw new Error("No data provided");if("[object Object]"!==Object.prototype.toString.call(t))throw new Error("Data must be a valid JSON object");o.label=1;case 1:o.trys.push([1,6,7,8]),e=i(Object.keys(t)),r=e.next(),o.label=2;case 2:return r.done?[3,5]:(n=r.value,[4,u.set(n,t[n],this.store)]);case 3:o.sent(),o.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return s=o.sent(),a={error:s},[3,8];case 7:try{r&&!r.done&&(f=e.return)&&f.call(e)}finally{if(a)throw a.error}return[7];case 8:return[2]}}))}))},t}();e.Store=a;var f=u;e._idb=f},function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.close=e.keys=e.clear=e.del=e.set=e.get=e.Store=void 0;var i,u=function(){function t(t,e){void 0===t&&(t="keyval-store"),void 0===e&&(e="keyval"),this.storeName=e,this._dbName=t,this._storeName=e,this._init()}return t.prototype._withIDBStore=function(t,e){return n(this,void 0,void 0,(function(){var r,n,i=this;return o(this,(function(o){switch(o.label){case 0:return[4,this._init()];case 1:return r=o.sent(),[4,new Promise((function(o,u){var s=r.transaction(i.storeName,t);s.oncomplete=function(){return o()},s.onabort=s.onerror=function(){return u(s.error)},n=e(s.objectStore(i.storeName))}))];case 2:return o.sent(),[2,n]}}))}))},t.prototype._init=function(){return n(this,void 0,void 0,(function(){var t,e=this;return o(this,(function(r){switch(r.label){case 0:return this._dbp?[2,this._dbp]:(t=this,[4,new Promise((function(t,r){var n=window.indexedDB.open(e._dbName,1);n.onerror=function(){return r(n.error)},n.onsuccess=function(){return t(n.result)},n.onupgradeneeded=function(){n.result.createObjectStore(e._storeName)}}))]);case 1:return t._dbp=r.sent(),this._dbp.onclose=function(){e._dbp=void 0},this._dbp.onversionchange=function(t){var r;null===t.newVersion&&(console.log("Got delete request for db"),null===(r=e._dbp)||void 0===r||r.close())},[2,this._dbp]}}))}))},t.prototype._close=function(){var t;null===(t=this._dbp)||void 0===t||t.close()},t}();function s(){return i||(i=new u),i}e.Store=u,e.get=function(t,e){return void 0===e&&(e=s()),n(this,void 0,void 0,(function(){return o(this,(function(r){switch(r.label){case 0:return[4,e._withIDBStore("readonly",(function(e){return e.get(t)}))];case 1:return[2,r.sent().result]}}))}))},e.set=function(t,e,r){return void 0===r&&(r=s()),r._withIDBStore("readwrite",(function(r){r.put(e,t)}))},e.del=function(t,e){return void 0===e&&(e=s()),e._withIDBStore("readwrite",(function(e){e.delete(t)}))},e.clear=function(t){return void 0===t&&(t=s()),t._withIDBStore("readwrite",(function(t){t.clear()}))},e.keys=function(t){return void 0===t&&(t=s()),t._withIDBStore("readonly",(function(t){var e=[];return(t.openKeyCursor||t.openCursor).call(t).onsuccess=function(){this.result&&(e.push(this.result.key),this.result.continue())},e}))},e.close=function(t){return void 0===t&&(t=s()),t._close()}},function(t,e,r){window,t.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";(function(t){var r=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{a(n.next(t))}catch(t){i(t)}}function s(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}a((n=n.apply(t,e||[])).next())}))},n=this&&this.__generator||function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};Object.defineProperty(e,"__esModule",{value:!0}),e._genRandomBufferAsStr=e._genRandomBuffer=e.updatePassphraseKey=e.decryptMasterKey=e.genEncryptedMasterKey=e.decryptBuffer=e.encryptBuffer=e.decrypt=e.encrypt=e.exportKey=e.importKey=e.genAESKey=e.verify=e.sign=e.exportPrivateKey=e.exportPublicKey=e.importPrivateKey=e.importPublicKey=e.genKeyPair=e.hash=e.genId=void 0;var o=function(t){if(!t.type||"secret"!==t.type)throw new Error("Invalid key type")},i=function(e){void 0===e&&(e=16);var r=window.crypto.getRandomValues(new Uint8Array(e));return t.from(r)},u=function(t,e){return void 0===t&&(t=16),void 0===e&&(e="hex"),e&&s(e),i(t).toString(e)},s=function(t){if("hex"!==t&&"base64"!==t)throw new Error("Invalid encoding")};e.genId=function(t){return void 0===t&&(t=32),u(Math.floor(t/2))},e.hash=function(e,o,i){return void 0===o&&(o="hex"),void 0===i&&(i="SHA-256"),r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.digest({name:i},"string"==typeof e?t.from(e):e)];case 1:return r=n.sent(),[2,t.from(r).toString(o)]}}))}))},e.genKeyPair=function(t,e){return void 0===t&&(t=!0),void 0===e&&(e="P-256"),window.crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},t,["sign","verify"])},e.importPublicKey=function(e,r,n){return void 0===r&&(r="P-256"),void 0===n&&(n="base64"),window.crypto.subtle.importKey("spki","string"==typeof e?t.from(e,n):e,{name:"ECDSA",namedCurve:r},!0,["verify"])},e.importPrivateKey=function(e,r,n){return void 0===r&&(r="P-256"),void 0===n&&(n="base64"),window.crypto.subtle.importKey("pkcs8","string"==typeof e?t.from(e,n):e,{name:"ECDSA",namedCurve:r},!0,["sign"])},e.exportPublicKey=function(e,o){return void 0===o&&(o="base64"),r(this,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.exportKey("spki",e)];case 1:return r=n.sent(),[2,"raw"===o?new Uint8Array(r):t.from(r).toString(o)]}}))}))},e.exportPrivateKey=function(e,o){return void 0===o&&(o="base64"),r(this,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.exportKey("pkcs8",e)];case 1:return r=n.sent(),[2,"raw"===o?new Uint8Array(r):t.from(r).toString(o)]}}))}))},e.sign=function(e,o,i,u){return void 0===i&&(i="base64"),void 0===u&&(u="SHA-256"),r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.sign({name:"ECDSA",hash:{name:u}},e,t.from(JSON.stringify(o)))];case 1:return r=n.sent(),[2,"raw"===i?new Uint8Array(r):t.from(r).toString(i)]}}))}))},e.verify=function(e,o,i,u,s){return void 0===u&&(u="base64"),void 0===s&&(s="SHA-256"),r(void 0,void 0,void 0,(function(){return n(this,(function(r){return[2,window.crypto.subtle.verify({name:"ECDSA",hash:{name:s}},e,t.from(i,u),t.from(JSON.stringify(o)))]}))}))},e.genAESKey=function(t,e,r){return void 0===t&&(t=!0),void 0===e&&(e="AES-GCM"),void 0===r&&(r=128),window.crypto.subtle.generateKey({name:e,length:r},t,["decrypt","encrypt"])};var a=function(e,r,n){void 0===r&&(r="raw"),void 0===n&&(n="AES-GCM");var o="raw"===r?t.from(e,"base64"):e;return window.crypto.subtle.importKey(r,o,{name:n},!0,["encrypt","decrypt"])};e.importKey=a;var f=function(t,e){return void 0===e&&(e="raw"),r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.exportKey(e,t)];case 1:return r=n.sent(),[2,"raw"===e?new Uint8Array(r):r]}}))}))};e.exportKey=f;var c=function(t,e,o){return r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return[4,window.crypto.subtle.encrypt(o,t,e)];case 1:return r=n.sent(),[2,new Uint8Array(r)]}}))}))};e.encryptBuffer=c;var h=function(t,e,o){return r(void 0,void 0,void 0,(function(){var r;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,window.crypto.subtle.decrypt(o,t,e)];case 1:return r=n.sent(),[2,new Uint8Array(r)];case 2:if("Unsupported state or unable to authenticate data"===n.sent().message)throw new Error("Unable to decrypt data");return[3,3];case 3:return[2]}}))}))};e.decryptBuffer=h;var l=function(e,u,s){return void 0===s&&(s="hex"),r(void 0,void 0,void 0,(function(){var r,a,f;return n(this,(function(n){switch(n.label){case 0:return o(e),r={iv:i("AES-GCM"===e.algorithm.name?12:16),plaintext:t.from(JSON.stringify(u))},a={name:e.algorithm.name,iv:r.iv},[4,c(e,r.plaintext,a)];case 1:return f=n.sent(),[2,{ciphertext:t.from(f).toString(s),iv:t.from(r.iv).toString(s)}]}}))}))};e.encrypt=l;var p=function(e,i,u){return void 0===u&&(u="hex"),r(void 0,void 0,void 0,(function(){var r,s,a;return n(this,(function(n){switch(n.label){case 0:o(e),r={ciphertext:t.from(Object.prototype.hasOwnProperty.call(i,"ciphertext")?i.ciphertext:"",u),iv:Object.prototype.hasOwnProperty.call(i,"iv")?t.from(i.iv,u):""},s={name:e.algorithm.name,iv:r.iv},n.label=1;case 1:return n.trys.push([1,3,,4]),[4,h(e,r.ciphertext,s)];case 2:if(void 0===(a=n.sent()))throw new Error;return[2,JSON.parse(t.from(a).toString())];case 3:throw n.sent(),new Error("Unable to decrypt data");case 4:return[2]}}))}))};e.decrypt=p;var y=function(e,o,i,u){return r(void 0,void 0,void 0,(function(){var r,s;return n(this,(function(n){switch(n.label){case 0:return i<1e4&&console.warn("Less than 10000 :("),[4,window.crypto.subtle.importKey("raw","string"==typeof e?t.from(e):e,"PBKDF2",!1,["deriveBits","deriveKey"])];case 1:return r=n.sent(),[4,window.crypto.subtle.deriveBits({name:"PBKDF2",salt:o||new Uint8Array([]),iterations:i||1e5,hash:u||"SHA-256"},r,128)];case 2:return s=n.sent(),[2,new Uint8Array(s)]}}))}))},d=function(e,o,u,s){return void 0===o&&(o=i(16)),void 0===u&&(u=1e5),void 0===s&&(s="SHA-256"),r(void 0,void 0,void 0,(function(){var r,i;return n(this,(function(n){switch(n.label){case 0:return function(t){if("string"!=typeof t||""===t)throw new Error("Not a valid value")}(e),[4,y(e,o,u,s)];case 1:return r=n.sent(),[4,a(r)];case 2:return i=n.sent(),[2,{derivationParams:{salt:t.from(o).toString("hex"),iterations:u,hashAlgo:s},key:i}]}}))}))};e.genEncryptedMasterKey=function(t,e,o,i){return r(void 0,void 0,void 0,(function(){var r,s,a;return n(this,(function(n){switch(n.label){case 0:return[4,d(t,e,o,i)];case 1:return r=n.sent(),s=u(32,"hex"),[4,l(r.key,s)];case 2:return a=n.sent(),[2,{derivationParams:r.derivationParams,encryptedMasterKey:a}]}}))}))},e.updatePassphraseKey=function(e,o,i,u,s,a){return r(void 0,void 0,void 0,(function(){var r,c,h,p,y,w;return n(this,(function(n){switch(n.label){case 0:return[4,v(e,i)];case 1:return r=n.sent(),[4,d(o,u,s,a)];case 2:return c=n.sent(),y=(p=t).from,[4,f(r)];case 3:return h=y.apply(p,[n.sent()]).toString("hex"),[4,l(c.key,h)];case 4:return w=n.sent(),[2,{derivationParams:c.derivationParams,encryptedMasterKey:w}]}}))}))};var v=function(e,o){return r(void 0,void 0,void 0,(function(){var r,i,u,s,f,c,h,l,d,v;return n(this,(function(n){switch(n.label){case 0:if(!o.encryptedMasterKey||!o.derivationParams)throw new Error("Missing properties from master key");return r=o.derivationParams,i=o.encryptedMasterKey,u=r.salt,s=r.iterations,f=r.hashAlgo,c="string"==typeof u?t.from(u,"hex"):u,[4,y(e,c,s,f)];case 1:return h=n.sent(),[4,a(h)];case 2:l=n.sent(),n.label=3;case 3:return n.trys.push([3,5,,6]),[4,p(l,i)];case 4:return d=n.sent(),v=t.from(d,"hex"),[2,window.crypto.subtle.importKey("raw",v,{name:"AES-GCM"},!0,["encrypt","decrypt"])];case 5:throw n.sent(),new Error("Wrong passphrase");case 6:return[2]}}))}))};e.decryptMasterKey=v;var w=i;e._genRandomBuffer=w;var g=u;e._genRandomBufferAsStr=g}).call(this,r(1).Buffer)},function(t,e,r){"use strict";(function(t){ | ||
/*! | ||
@@ -3,0 +3,0 @@ * The buffer module from node.js, for the browser. |
{ | ||
"name": "secure-webstore", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Secure IndexedDB store using encryption", | ||
@@ -5,0 +5,0 @@ "author": "Andrei Sambra", |
@@ -6,2 +6,4 @@ import * as idb from './store'; | ||
const encryptedKeyKey = '__key'; | ||
class Store { | ||
@@ -34,3 +36,3 @@ private store: idb.Store; | ||
try { | ||
let encryptedKey: crypto.ProtectedMasterKey | undefined = await idb.get('__key', this.store) | ||
let encryptedKey: crypto.ProtectedMasterKey | undefined = await idb.get(encryptedKeyKey, this.store) | ||
// generate a new key for the user if no key exists (empty store) | ||
@@ -40,3 +42,3 @@ if (!encryptedKey) { | ||
// store the new key since it's the first time | ||
await idb.set('__key', encryptedKey, this.store) | ||
await idb.set(encryptedKeyKey, encryptedKey, this.store) | ||
} | ||
@@ -61,3 +63,3 @@ // decrypt key so we can use it during this session | ||
const encryptedKey = await crypto.updatePassphraseKey(oldPass, newPass, this.encMasterKey) | ||
await idb.set('__key', encryptedKey, this.store) | ||
await idb.set(encryptedKeyKey, encryptedKey, this.store) | ||
this.encMasterKey = encryptedKey | ||
@@ -88,4 +90,6 @@ } catch (e) { | ||
keys (): Promise<IDBValidKey[]> { | ||
return idb.keys(this.store) | ||
async keys (): Promise<IDBValidKey[]> { | ||
const keys = await idb.keys(this.store); | ||
// Users of secure-webstore should not have to be aware of existence of __key. | ||
return keys.filter(key => key !== encryptedKeyKey); | ||
} | ||
@@ -92,0 +96,0 @@ |
@@ -101,4 +101,4 @@ /* eslint-env mocha */ | ||
const items = await store.keys() // [ '__key', 'one' ] | ||
chai.assert.equal(items.length, 2) | ||
const items = await store.keys() // [ 'one' ] | ||
chai.assert.equal(items.length, 1) | ||
await store.close() | ||
@@ -113,4 +113,4 @@ }) | ||
const items = await store.keys() // [ '__key', 'one ] | ||
chai.assert.equal(items.length, 2) | ||
const items = await store.keys() // [ 'one ] | ||
chai.assert.equal(items.length, 1) | ||
await store.close() | ||
@@ -125,4 +125,4 @@ }) | ||
const items = await store.keys() // [ '__key' ] | ||
chai.assert.equal(items.length, 1) | ||
const items = await store.keys() // [] | ||
chai.assert.equal(items.length, 0) | ||
await store.close() | ||
@@ -129,0 +129,0 @@ }) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
161774
687
0