@evervault/react
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var r="object"==typeof exports?t(require("react")):t(e.react);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(t,r){t.exports=e},function(e,t,r){function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t,r,n,o,a,u){try{var i=e[a](u),c=i.value}catch(e){return void r(e)}i.done?t(c):Promise.resolve(c).then(n,o)}function a(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var u=e.apply(t,r);function i(e){o(u,n,a,i,c,"next",e)}function c(e){o(u,n,a,i,c,"throw",e)}i(void 0)}))}}var u=r(3);e.exports={keyStore:new function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var t=void 0;this.encryptString=function(e){var r=u.dataToBuffer(e),n=window.crypto.getRandomValues(new Uint8Array(12));return window.crypto.subtle.encrypt({name:"AES-GCM",iv:n},t,r).then((function(e){return u.buildEvervaultString(n,e)})).catch((function(e){throw new Error("Encryption operation failed.")}))},this.decryptString=function(e){if(u.isEvervaultString(e)){var r=u.parseEvervaultString(e),n=u.b64ToBuffer(r.browserData),o=u.b64ToBuffer(r.iv);return window.crypto.subtle.decrypt({name:"AES-GCM",iv:o},t,n).then((function(e){return u.bufferToString(e)})).catch((function(e){throw new Error(e)}))}return e},this.updateKey=function(){var e=a(regeneratorRuntime.mark((function e(r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=5;break}return e.next=3,u.getEncryptionKey(r||localStorage.getItem("evervault-privateKey"));case 3:n=e.sent,t=n;case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},urls:{auth:"https://auth.evervault.com",api:"https://api.evervault.com"},init:function(e,t){if(!e)throw new Error("No appId provided to the evervault sdk");if(this.appId=e,t){var r=/^(http){1}(s)?(:\/{2}){1}/,n={};Object.keys(t).forEach((function(e){var o=t[e];if(r.test(o))n[e]=o;else if(o)throw new Error("Invalid URL received in evervault sdk for ".concat(e," url (value: ").concat(o,")"))})),Object.assign(this.urls,n)}},encrypt:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=function(e,r){if(e)return function(){var e=a(regeneratorRuntime.mark((function e(r,n){var o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=Object.assign({},r),a=0;case 2:if(!(a<n.length)){e.next=11;break}if(i=n[a],!o[i]){e.next=8;break}return e.next=7,t.keyStore.encryptString(u.ensureString(o[i]));case 7:o[i]=e.sent;case 8:a++,e.next=2;break;case 11:return e.abrupt("return",o);case 12:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()(e,r)};if("object"===n(e)&&e&&"Array"!==e.constructor.name&&r.preserveObjectShape){var i=r.fieldsToEncrypt||Object.keys(e);return this.keyStore.updateKey(r.privateKey).then((function(){return o(e,i)}))}if(void 0!==e&&"symbol"!==n(e))return this.keyStore.updateKey(r.privateKey).then((function(){return t.keyStore.encryptString(u.ensureString(e))}))},decrypt:function(e,t){var r=this;return"object"===n(e)?"Array"===e.constructor.name?this.keyStore.updateKey(t).then((function(){return function(e){return function(){var t=a(regeneratorRuntime.mark((function t(n){var o,a;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o=new Array(n.length),a=0;case 2:if(!(a<e.length)){t.next=9;break}return t.next=5,r.keyStore.decryptString(u.ensureString(n[a]));case 5:o[a]=t.sent;case 6:a++,t.next=2;break;case 9:return t.abrupt("return",o);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()(e)}(e)})):this.keyStore.updateKey(t).then((function(){return function(e,t){if(e)return function(){var e=a(regeneratorRuntime.mark((function e(t,n){var o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=Object.assign({},t),a=0;case 2:if(!(a<n.length)){e.next=11;break}if(i=n[a],!o[i]){e.next=8;break}return e.next=7,r.keyStore.decryptString(u.ensureString(o[i]));case 7:o[i]=e.sent;case 8:a++,e.next=2;break;case 11:return e.abrupt("return",o);case 12:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()(e,t)}(e,Object.keys(e))})):void 0!==e&&"symbol"!==n(e)?this.keyStore.updateKey(t).then((function(){return r.keyStore.decryptString(u.ensureString(e))})):e},logout:function(e){localStorage.removeItem("evervault-privateKey"),localStorage.removeItem("evervault-accessToken"),localStorage.removeItem("evervault-refreshToken"),localStorage.removeItem("evervault-haiku"),e?window.location.replace(e):u.handleRedirect("".concat(this.urls.auth,"/").concat(this.appId))},refreshAccessToken:function(e,t){var r={accessToken:e||localStorage.getItem("evervault-accessToken"),refreshToken:t||localStorage.getItem("evervault-refreshToken")};return fetch("".concat(this.urls.api,"/v1/token/refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}).then((function(e){return e.json()})).then((function(e){var t=e.accessToken;if(!t)throw new Error("Unable to retrive access token");return t})).catch((function(e){throw new Error("Unable to retrieve refresh token",e)}))},checkAuth:function(){var e=window.location.hash.substring(2);window.location.hash="/";var t=localStorage.getItem("evervault-privateKey"),r=localStorage.getItem("evervault-accessToken"),n=localStorage.getItem("evervault-refreshToken"),o=Boolean(r&&n&&t);if(o||e){if(e)return u.setUserKeysInStorage(e),!0}else u.handleRedirect("".concat(this.urls.auth,"/").concat(this.appId));return o}}},function(e,t,r){"use strict";r.r(t),r.d(t,"EvervaultContext",(function(){return p})),r.d(t,"EvervaultProvider",(function(){return v})),r.d(t,"EvervaultConsumer",(function(){return y})),r.d(t,"withEvervault",(function(){return h}));var n=r(0),o=r.n(n),a=r(1),u=r.n(a);function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e,t){return!t||"object"!==i(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var p=o.a.createContext(void 0),v=p.Provider,y=p.Consumer;function h(e,t){var r=t.appId,n=t.authUrl,a=t.apiUrl,i=t.useEvervaultContext;return(function(t){function p(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,p),t=f(this,s(p).call(this,e)),u.a.init(r,{auth:n,api:a}),u.a.checkAuth(),t.state={evervault:u.a},t}var y,h,d;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(p,t),y=p,(h=[{key:"render",value:function(){return i?o.a.createElement(v,{value:this.state.evervault},o.a.createElement(e,null)):o.a.createElement(e,{evervault:this.state.evervault})}}])&&c(y.prototype,h),d&&c(y,d),p}(o.a.Component))}},function(e,t){function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,a,u;return t=e,u=[{key:"getEncryptionKey",value:function(e){var t=this.b64ToBuffer(e);return window.crypto.subtle.importKey("raw",t,{name:"AES-GCM"},!1,["encrypt","decrypt"])}},{key:"b64ToBuffer",value:function(e){for(var t=window.atob(e),r=new ArrayBuffer(t.length),n=new Uint8Array(r),o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}},{key:"ensureString",value:function(e){return function(e){return"string"==typeof e?e:["bigint","function"].includes(n(e))?e.toString():JSON.stringify(e)}(e).trim()}},{key:"bufToStr",value:function(e){for(var t,r=new Uint8Array(e),n=0,o="",a=8*n;a+8<r.length;)t=r.subarray(a,a+8),o+=String.fromCharCode.apply(null,t),a=8*++n;return o+=String.fromCharCode.apply(null,r.subarray(a))}},{key:"bufferToB64",value:function(e){return window.btoa(this.bufToStr(e))}},{key:"dataToBuffer",value:function(e){return(new TextEncoder).encode(e)}},{key:"parseEvervaultString",value:function(e){var t=e.split(":");if(t.length<4)throw new Error("String does not match expected structure");return{prefix:t[0],version:t[1],iv:t[2],browserData:t[3]}}},{key:"isEvervaultString",value:function(e){return/^enc:v[0-9]:(?:[\+\/-9A-Za-z]{4})*(?:[\+\/-9A-Za-z]{2}==|[\+\/-9A-Za-z]{3}=)?:(?:[\+\/-9A-Za-z]{4})*(?:[\+\/-9A-Za-z]{2}==|[\+\/-9A-Za-z]{3}=)?$/.test(e)}},{key:"bufferToString",value:function(e){for(var t,r=new Uint8Array(e),n=0,o="",a=8*n,u=new TextDecoder("utf-8");a+8<r.length;)t=r.subarray(a,a+8),o+=u.decode(t),a=8*++n;return o+=u.decode(r.subarray(a))}},{key:"buildEvervaultString",value:function(e,t){return"enc:v1:".concat(this.bufferToB64(e),":").concat(this.bufferToB64(t))}},{key:"setUserKeysInStorage",value:function(e){var t=e.split(":");localStorage.setItem("evervault-privateKey",t[0]),localStorage.setItem("evervault-accessToken",t[1]),localStorage.setItem("evervault-refreshToken",t[2]),localStorage.setItem("evervault-haiku",JSON.parse(window.atob(t[1].split(".")[1])).haiku)}},{key:"handleRedirect",value:function(t){var r=e.getParams(),n=["redirectUrl","state","nonce"],o=Object.keys(r).filter((function(e){return n.includes(e)})).map((function(e){return"".concat(e,"=").concat(encodeURI(r[e]))})).join("&");window.location.replace("".concat(t).concat(o&&o.length>0?"?"+o:o))}},{key:"getParams",value:function(){var e={};return window.location.search.substr(1).split("&").forEach((function(t){var n=r(t.split("="),2),o=n[0],a=n[1];e[o]=decodeURIComponent(a)})),e}}],(a=null)&&o(t.prototype,a),u&&o(t,u),e}()}])})); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var r="object"==typeof exports?t(require("react")):t(e.react);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(t,r){t.exports=e},function(e,t,r){const n=r(3);e.exports={keyStore:new class{constructor(){let e=void 0;this.encryptString=t=>{const r=n.dataToBuffer(t),o=window.crypto.getRandomValues(new Uint8Array(12));return window.crypto.subtle.encrypt({name:"AES-GCM",iv:o},e,r).then(e=>n.buildEvervaultString(o,e)).catch(e=>{throw new Error("Encryption operation failed.")})},this.decryptString=t=>{if(n.isEvervaultString(t)){const r=n.parseEvervaultString(t),o=n.b64ToBuffer(r.browserData),a=n.b64ToBuffer(r.iv);return window.crypto.subtle.decrypt({name:"AES-GCM",iv:a},e,o).then(e=>n.bufferToString(e)).catch(e=>{throw new Error(e)})}return t},this.updateKey=async t=>{if(!e){const r=await n.getEncryptionKey(t||localStorage.getItem("evervault-privateKey"));e=r}}}},urls:{auth:"https://auth.evervault.com",api:"https://api.evervault.com"},init:function(e,t){if(!e)throw new Error("No appId provided to the evervault sdk");if(this.appId=e,t){const e=/^(http){1}(s)?(:\/{2}){1}/;let r={};Object.keys(t).forEach(n=>{const o=t[n];if(e.test(o))r[n]=o;else if(o)throw new Error(`Invalid URL received in evervault sdk for ${n} url (value: ${o})`)}),Object.assign(this.urls,r)}},set:async function(e){e=await this.encrypt(e,{preserveObjectShape:!0});const t=await this.getValidAccessToken();return fetch(`${this.urls.api}/data/${this.appId}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({data:e})}).then(e=>e.json()).then(e=>{if(!e)throw new Error("Unable to save data");return e}).catch(e=>{throw new Error("Unable to save data",e)})},get:async function(e=""){const t=await this.getValidAccessToken();return await fetch(`${this.urls.api}/data/${this.appId}/${e}`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}}).then(e=>e.json()).then(e=>{if(!e)throw new Error("Unable to get data");return this.decrypt(e)}).catch(e=>{throw new Error("Unable to get data",e)})},getValidAccessToken:async function(){if(n.checkAccessToken(localStorage.getItem("evervault-accessToken")))return localStorage.getItem("evervault-accessToken");return(await this.refreshAccessToken(localStorage.getItem("evervault-accessToken"),localStorage.getItem("evervault-refreshToken"))).accessToken},encrypt:function(e,t={}){const r=(e,t)=>{if(e){return(async(e,t)=>{let r=Object.assign({},e);for(let e=0;e<t.length;e++){let o=t[e];r[o]&&(r[o]=await this.keyStore.encryptString(n.ensureString(r[o])))}return r})(e,t)}};if("object"==typeof e&&e&&"Array"!==e.constructor.name&&t.preserveObjectShape){const n=t.fieldsToEncrypt||Object.keys(e);return this.keyStore.updateKey(t.privateKey).then(()=>r(e,n))}if(void 0!==e&&"symbol"!=typeof e)return this.keyStore.updateKey(t.privateKey).then(()=>this.keyStore.encryptString(n.ensureString(e)))},decrypt:function(e,t){const r=e=>(async t=>{let r=new Array(t.length);for(let o=0;o<e.length;o++)r[o]=await this.keyStore.decryptString(n.ensureString(t[o]));return r})(e),o=(e,t)=>{if(e){return(async(e,t)=>{let r=Object.assign({},e);for(let e=0;e<t.length;e++){let o=t[e];r[o]&&(r[o]=await this.keyStore.decryptString(n.ensureString(r[o])))}return r})(e,t)}};return"object"==typeof e?"Array"===e.constructor.name?this.keyStore.updateKey(t).then(()=>r(e)):this.keyStore.updateKey(t).then(()=>o(e,Object.keys(e))):void 0!==e&&"symbol"!=typeof e?this.keyStore.updateKey(t).then(()=>this.keyStore.decryptString(n.ensureString(e))):e},logout:function(e){localStorage.removeItem("evervault-privateKey"),localStorage.removeItem("evervault-accessToken"),localStorage.removeItem("evervault-refreshToken"),localStorage.removeItem("evervault-haiku"),e?window.location.replace(e):n.handleRedirect(`${this.urls.auth}/${this.appId}`)},refreshAccessToken:function(e,t){const r={accessToken:e||localStorage.getItem("evervault-accessToken"),refreshToken:t||localStorage.getItem("evervault-refreshToken")};return fetch(`${this.urls.api}/token/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}).then(e=>e.json()).then(({accessToken:e,refreshToken:t})=>{if(!e)throw new Error("Unable to retrive access token");return localStorage.setItem("evervault-accessToken",e),localStorage.setItem("evervault-refreshToken",t),{accessToken:e,refreshToken:t}}).catch(e=>{throw new Error("Unable to retrieve refresh token",e)})},checkAuth:function(){const e=window.location.hash.substring(2);window.location.hash="/";const t=localStorage.getItem("evervault-privateKey"),r=localStorage.getItem("evervault-accessToken"),o=localStorage.getItem("evervault-refreshToken"),a=Boolean(r&&o&&t);if(a||e){if(e)return n.setUserKeysInStorage(e),!0}else n.handleRedirect(`${this.urls.auth}/${this.appId}`);return a}}},function(e,t,r){"use strict";r.r(t),r.d(t,"EvervaultContext",(function(){return p})),r.d(t,"EvervaultProvider",(function(){return h})),r.d(t,"EvervaultConsumer",(function(){return v})),r.d(t,"useEvervault",(function(){return y})),r.d(t,"withEvervault",(function(){return d}));var n=r(0),o=r.n(n),a=r(1),i=r.n(a);function c(e){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function u(e,t){return!t||"object"!==c(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var p=o.a.createContext(void 0),h=p.Provider,v=p.Consumer;function y(){var e=o.a.useContext(p);if(!e)throw new Error("No context found for evervault");if("function"!=typeof n.useContext)throw new Error("You must use React >= 16.8 in order to use useEvervault()");return e}function d(e,t){var r=t.appId,n=t.authUrl,a=t.apiUrl,c=t.useEvervaultContext;return(function(t){function p(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,p),t=u(this,l(p).call(this,e)),i.a.init(r,{auth:n,api:a}),i.a.checkAuth(),t.state={evervault:i.a},t}var v,y,d;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}(p,t),v=p,(y=[{key:"render",value:function(){return c?o.a.createElement(h,{value:this.state.evervault},o.a.createElement(e,null)):o.a.createElement(e,{evervault:this.state.evervault})}}])&&s(v.prototype,y),d&&s(v,d),p}(o.a.Component))}},function(e,t){e.exports=class e{static getEncryptionKey(e){const t=this.b64ToBuffer(e);return window.crypto.subtle.importKey("raw",t,{name:"AES-GCM"},!1,["encrypt","decrypt"])}static b64ToBuffer(e){const t=window.atob(e);for(var r=new ArrayBuffer(t.length),n=new Uint8Array(r),o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}static ensureString(e){return(e=>"string"==typeof e?e:["bigint","function"].includes(typeof e)?e.toString():JSON.stringify(e))(e).trim()}static bufToStr(e){const t=new Uint8Array(e);let r,n=0,o="",a=8*n;for(;a+8<t.length;)r=t.subarray(a,a+8),o+=String.fromCharCode.apply(null,r),n++,a=8*n;return o+=String.fromCharCode.apply(null,t.subarray(a)),o}static bufferToB64(e){return window.btoa(this.bufToStr(e))}static dataToBuffer(e){return(new TextEncoder).encode(e)}static checkAccessToken(e){return JSON.parse(this.bufToStr(this.b64ToBuffer(e.split(".")[1]))).exp>Math.floor(Date.now()/1e3)}static parseEvervaultString(e){const t=e.split(":");if(t.length<4)throw new Error("String does not match expected structure");return{prefix:t[0],version:t[1],iv:t[2],browserData:t[3]}}static isEvervaultString(e){return/^enc:v\d:(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?:(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/s.test(e)}static bufferToString(e){const t=new Uint8Array(e);let r,n=0,o="",a=8*n,i=new TextDecoder("utf-8");for(;a+8<t.length;)r=t.subarray(a,a+8),o+=i.decode(r),n++,a=8*n;return o+=i.decode(t.subarray(a)),o}static buildEvervaultString(e,t){return`enc:v1:${this.bufferToB64(e)}:${this.bufferToB64(t)}`}static setUserKeysInStorage(e){const t=e.split(":");localStorage.setItem("evervault-privateKey",t[0]),localStorage.setItem("evervault-accessToken",t[1]),localStorage.setItem("evervault-refreshToken",t[2]),localStorage.setItem("evervault-haiku",JSON.parse(window.atob(t[1].split(".")[1])).haiku)}static handleRedirect(t){const r=e.getParams(),n=["redirectUrl","state","nonce"],o=Object.keys(r).filter(e=>n.includes(e)).map(e=>`${e}=${encodeURI(r[e])}`).join("&");window.location.replace(`${t}${o&&o.length>0?"?"+o:o}`)}static getParams(){let e={};return window.location.search.substr(1).split("&").forEach(t=>{const[r,n]=t.split("=");e[r]=decodeURIComponent(n)}),e}}}])})); |
18
index.js
@@ -1,6 +0,4 @@ | ||
/** @format */ | ||
import React, { useContext } from 'react'; | ||
import evervault from '@evervault/sdk' | ||
import React from 'react'; | ||
import evervault from '@evervault/sdk'; | ||
export const EvervaultContext = React.createContext(undefined); | ||
@@ -10,2 +8,14 @@ export const EvervaultProvider = EvervaultContext.Provider; | ||
export function useEvervault() { | ||
const evervault = React.useContext(EvervaultContext); | ||
if (!evervault) { | ||
throw new Error('No context found for evervault'); | ||
} | ||
if (typeof useContext !== "function") { | ||
throw new Error('You must use React >= 16.8 in order to use useEvervault()'); | ||
} | ||
return evervault; | ||
} | ||
export function withEvervault(WrappedComponent, params) { | ||
@@ -12,0 +22,0 @@ const { appId, authUrl, apiUrl, useEvervaultContext } = params; |
{ | ||
"name": "@evervault/react", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "React package for the Evervault SDK", | ||
@@ -10,8 +10,10 @@ "main": "./build/lib/index.js", | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.12.0" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@evervault/sdk": "^0.2.3", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.12.0" | ||
"@evervault/sdk": "^0.3.2", | ||
"prop-types": "^15.7.2" | ||
}, | ||
@@ -18,0 +20,0 @@ "devDependencies": { |
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
7
71
14238
3
+ Added@evervault/sdk@0.3.9(transitive)
- Removedreact@^16.12.0
- Removed@evervault/sdk@0.2.3(transitive)
Updated@evervault/sdk@^0.3.2