UNPKG

expo-aes-vetkeys

Version:

Hooks and components for using AES & vetkeys in Expo Web/Native applications

917 lines (914 loc) 30 kB
import Ye, { useState as mr, useRef as Er, useCallback as br, useEffect as Rr } from "react"; import { TransportSecretKey as _r, ibeDecrypt as wr, ibeEncrypt as Sr } from "vetkeys-client-utils"; import { StyleSheet as Tr, View as Pe, ActivityIndicator as Ar, Text as je } from "react-native"; const kr = async ({ backend: o, transportPublicKey: n }) => { const d = performance.now(), g = await o.asymmetricKeys(n); return console.log( `Getting asymmetric keys took: ${performance.now() - d}ms` ), g; }, Cr = async ({ backend: o, tskSeed: n }) => { const d = new _r(n), g = d.public_key(), { publicKey: E, encryptedAesKey: S, encryptedKey: w } = await kr({ backend: o, transportPublicKey: g }); return { tsk: d, publicKey: E, encryptedAesKey: S, encryptedKey: w }; }, xr = async ({ encryptedAesKey: o, principal: n, encryptedKey: d, publicKey: g, tsk: E }) => { console.log("Decrypting existing AES key"); const S = performance.now(), w = await wr({ ciphertext: o, principal: n, encryptedKey: d, publicKey: g, tsk: E }); return console.log( `Decrypting existing AES key took: ${performance.now() - S}ms` ), w; }, Or = async ({ aesRawKey: o, principal: n, publicKey: d, seed: g }) => { console.log("Encrypting AES key"); const E = performance.now(), S = await Sr({ data: o, principal: n, publicKey: d, seed: g }); return console.log(`Encrypting AES key took: ${performance.now() - E}ms`), S; }, Pr = async ({ encryptedAesKey: o, backend: n }) => { console.log("Saving encrypted AES key to backend"); const d = performance.now(); await n.asymmetricSaveEncryptedAesKey(o), console.log( `Saving encrypted AES key to backend took: ${performance.now() - d}ms` ); }, Mr = ({ cryptoModule: o, aesRawKeyStorage: n, identity: d, backend: g }) => { const [E, S] = mr(!1), w = Er(void 0), O = br(async () => { try { if (w.current = void 0, S(!0), !d) { console.log("Generating an AES key"); const s = o.getRandomBytes(32); console.log("Saving locally an AES key"), await n.save(s); return; } const p = d.getPrincipal().toUint8Array(), D = o.getRandomBytes(32), { tsk: R, publicKey: A, encryptedAesKey: P, encryptedKey: i } = await Cr({ backend: g, tskSeed: D }); if (P && i) { const s = await xr({ encryptedAesKey: P, principal: p, encryptedKey: i, publicKey: A, tsk: R }); console.log("Saving locally existing AES key"), await n.save(s); return; } else { console.log("Generating an AES key"); const s = o.getRandomBytes(32); console.log("Saving locally an AES key"), await n.save(s); const y = await Or({ aesRawKey: s, principal: p, publicKey: A, seed: D }); await Pr({ encryptedAesKey: y, backend: g }); } } catch (p) { console.error("Failed to initialize AES key:", p), w.current = p; } finally { S(!1); } }, [d]); return Rr(() => { O(); }, [d, O]), { isProcessingAes: E, aesError: w.current }; }; var H = { exports: {} }, V = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var De; function jr() { if (De) return V; De = 1; var o = Ye, n = Symbol.for("react.element"), d = Symbol.for("react.fragment"), g = Object.prototype.hasOwnProperty, E = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, S = { key: !0, ref: !0, __self: !0, __source: !0 }; function w(O, p, D) { var R, A = {}, P = null, i = null; D !== void 0 && (P = "" + D), p.key !== void 0 && (P = "" + p.key), p.ref !== void 0 && (i = p.ref); for (R in p) g.call(p, R) && !S.hasOwnProperty(R) && (A[R] = p[R]); if (O && O.defaultProps) for (R in p = O.defaultProps, p) A[R] === void 0 && (A[R] = p[R]); return { $$typeof: n, type: O, key: P, ref: i, props: A, _owner: E.current }; } return V.Fragment = d, V.jsx = w, V.jsxs = w, V; } var U = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Fe; function Dr() { return Fe || (Fe = 1, process.env.NODE_ENV !== "production" && function() { var o = Ye, n = Symbol.for("react.element"), d = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), S = Symbol.for("react.profiler"), w = Symbol.for("react.provider"), O = Symbol.for("react.context"), p = Symbol.for("react.forward_ref"), D = Symbol.for("react.suspense"), R = Symbol.for("react.suspense_list"), A = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), i = Symbol.for("react.offscreen"), s = Symbol.iterator, y = "@@iterator"; function _(e) { if (e === null || typeof e != "object") return null; var r = s && e[s] || e[y]; return typeof r == "function" ? r : null; } var b = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function l(e) { { for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), a = 1; a < r; a++) t[a - 1] = arguments[a]; k("error", e, t); } } function k(e, r, t) { { var a = b.ReactDebugCurrentFrame, f = a.getStackAddendum(); f !== "" && (r += "%s", t = t.concat([f])); var v = t.map(function(c) { return String(c); }); v.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, v); } } var I = !1, C = !1, Be = !1, Le = !1, Ve = !1, ie; ie = Symbol.for("react.module.reference"); function Ue(e) { return !!(typeof e == "string" || typeof e == "function" || e === g || e === S || Ve || e === E || e === D || e === R || Le || e === i || I || C || Be || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === A || e.$$typeof === w || e.$$typeof === O || e.$$typeof === p || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === ie || e.getModuleId !== void 0)); } function Me(e, r, t) { var a = e.displayName; if (a) return a; var f = r.displayName || r.name || ""; return f !== "" ? t + "(" + f + ")" : t; } function se(e) { return e.displayName || "Context"; } function F(e) { if (e == null) return null; if (typeof e.tag == "number" && l("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case g: return "Fragment"; case d: return "Portal"; case S: return "Profiler"; case E: return "StrictMode"; case D: return "Suspense"; case R: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case O: var r = e; return se(r) + ".Consumer"; case w: var t = e; return se(t._context) + ".Provider"; case p: return Me(e, e.render, "ForwardRef"); case A: var a = e.displayName || null; return a !== null ? a : F(e.type) || "Memo"; case P: { var f = e, v = f._payload, c = f._init; try { return F(c(v)); } catch { return null; } } } return null; } var K = Object.assign, B = 0, ue, ce, le, fe, de, ve, ye; function pe() { } pe.__reactDisabledLog = !0; function Ne() { { if (B === 0) { ue = console.log, ce = console.info, le = console.warn, fe = console.error, de = console.group, ve = console.groupCollapsed, ye = console.groupEnd; var e = { configurable: !0, enumerable: !0, value: pe, writable: !0 }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } B++; } } function Je() { { if (B--, B === 0) { var e = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: K({}, e, { value: ue }), info: K({}, e, { value: ce }), warn: K({}, e, { value: le }), error: K({}, e, { value: fe }), group: K({}, e, { value: de }), groupCollapsed: K({}, e, { value: ve }), groupEnd: K({}, e, { value: ye }) }); } B < 0 && l("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var Z = b.ReactCurrentDispatcher, Q; function q(e, r, t) { { if (Q === void 0) try { throw Error(); } catch (f) { var a = f.stack.trim().match(/\n( *(at )?)/); Q = a && a[1] || ""; } return ` ` + Q + e; } } var ee = !1, z; { var qe = typeof WeakMap == "function" ? WeakMap : Map; z = new qe(); } function ge(e, r) { if (!e || ee) return ""; { var t = z.get(e); if (t !== void 0) return t; } var a; ee = !0; var f = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var v; v = Z.current, Z.current = null, Ne(); try { if (r) { var c = function() { throw Error(); }; if (Object.defineProperty(c.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(c, []); } catch (x) { a = x; } Reflect.construct(e, [], c); } else { try { c.call(); } catch (x) { a = x; } e.call(c.prototype); } } else { try { throw Error(); } catch (x) { a = x; } e(); } } catch (x) { if (x && a && typeof x.stack == "string") { for (var u = x.stack.split(` `), T = a.stack.split(` `), h = u.length - 1, m = T.length - 1; h >= 1 && m >= 0 && u[h] !== T[m]; ) m--; for (; h >= 1 && m >= 0; h--, m--) if (u[h] !== T[m]) { if (h !== 1 || m !== 1) do if (h--, m--, m < 0 || u[h] !== T[m]) { var j = ` ` + u[h].replace(" at new ", " at "); return e.displayName && j.includes("<anonymous>") && (j = j.replace("<anonymous>", e.displayName)), typeof e == "function" && z.set(e, j), j; } while (h >= 1 && m >= 0); break; } } } finally { ee = !1, Z.current = v, Je(), Error.prepareStackTrace = f; } var Y = e ? e.displayName || e.name : "", $ = Y ? q(Y) : ""; return typeof e == "function" && z.set(e, $), $; } function ze(e, r, t) { return ge(e, !1); } function Ge(e) { var r = e.prototype; return !!(r && r.isReactComponent); } function G(e, r, t) { if (e == null) return ""; if (typeof e == "function") return ge(e, Ge(e)); if (typeof e == "string") return q(e); switch (e) { case D: return q("Suspense"); case R: return q("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case p: return ze(e.render); case A: return G(e.type, r, t); case P: { var a = e, f = a._payload, v = a._init; try { return G(v(f), r, t); } catch { } } } return ""; } var L = Object.prototype.hasOwnProperty, he = {}, me = b.ReactDebugCurrentFrame; function X(e) { if (e) { var r = e._owner, t = G(e.type, e._source, r ? r.type : null); me.setExtraStackFrame(t); } else me.setExtraStackFrame(null); } function Xe(e, r, t, a, f) { { var v = Function.call.bind(L); for (var c in e) if (v(e, c)) { var u = void 0; try { if (typeof e[c] != "function") { var T = Error((a || "React class") + ": " + t + " type `" + c + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[c] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw T.name = "Invariant Violation", T; } u = e[c](r, c, a, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (h) { u = h; } u && !(u instanceof Error) && (X(f), l("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", a || "React class", t, c, typeof u), X(null)), u instanceof Error && !(u.message in he) && (he[u.message] = !0, X(f), l("Failed %s type: %s", t, u.message), X(null)); } } } var He = Array.isArray; function re(e) { return He(e); } function Ze(e) { { var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object"; return t; } } function Qe(e) { try { return Ee(e), !1; } catch { return !0; } } function Ee(e) { return "" + e; } function be(e) { if (Qe(e)) return l("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ze(e)), Ee(e); } var Re = b.ReactCurrentOwner, er = { key: !0, ref: !0, __self: !0, __source: !0 }, _e, we; function rr(e) { if (L.call(e, "ref")) { var r = Object.getOwnPropertyDescriptor(e, "ref").get; if (r && r.isReactWarning) return !1; } return e.ref !== void 0; } function tr(e) { if (L.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function nr(e, r) { typeof e.ref == "string" && Re.current; } function ar(e, r) { { var t = function() { _e || (_e = !0, l("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "key", { get: t, configurable: !0 }); } } function or(e, r) { { var t = function() { we || (we = !0, l("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r)); }; t.isReactWarning = !0, Object.defineProperty(e, "ref", { get: t, configurable: !0 }); } } var ir = function(e, r, t, a, f, v, c) { var u = { // This tag allows us to uniquely identify this as a React Element $$typeof: n, // Built-in properties that belong on the element type: e, key: r, ref: t, props: c, // Record the component responsible for creating this element. _owner: v }; return u._store = {}, Object.defineProperty(u._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(u, "_self", { configurable: !1, enumerable: !1, writable: !1, value: a }), Object.defineProperty(u, "_source", { configurable: !1, enumerable: !1, writable: !1, value: f }), Object.freeze && (Object.freeze(u.props), Object.freeze(u)), u; }; function sr(e, r, t, a, f) { { var v, c = {}, u = null, T = null; t !== void 0 && (be(t), u = "" + t), tr(r) && (be(r.key), u = "" + r.key), rr(r) && (T = r.ref, nr(r, f)); for (v in r) L.call(r, v) && !er.hasOwnProperty(v) && (c[v] = r[v]); if (e && e.defaultProps) { var h = e.defaultProps; for (v in h) c[v] === void 0 && (c[v] = h[v]); } if (u || T) { var m = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; u && ar(c, m), T && or(c, m); } return ir(e, u, T, f, a, Re.current, c); } } var te = b.ReactCurrentOwner, Se = b.ReactDebugCurrentFrame; function W(e) { if (e) { var r = e._owner, t = G(e.type, e._source, r ? r.type : null); Se.setExtraStackFrame(t); } else Se.setExtraStackFrame(null); } var ne; ne = !1; function ae(e) { return typeof e == "object" && e !== null && e.$$typeof === n; } function Te() { { if (te.current) { var e = F(te.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function ur(e) { return ""; } var Ae = {}; function cr(e) { { var r = Te(); if (!r) { var t = typeof e == "string" ? e : e.displayName || e.name; t && (r = ` Check the top-level render call using <` + t + ">."); } return r; } } function ke(e, r) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = !0; var t = cr(r); if (Ae[t]) return; Ae[t] = !0; var a = ""; e && e._owner && e._owner !== te.current && (a = " It was passed a child from " + F(e._owner.type) + "."), W(e), l('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, a), W(null); } } function Ce(e, r) { { if (typeof e != "object") return; if (re(e)) for (var t = 0; t < e.length; t++) { var a = e[t]; ae(a) && ke(a, r); } else if (ae(e)) e._store && (e._store.validated = !0); else if (e) { var f = _(e); if (typeof f == "function" && f !== e.entries) for (var v = f.call(e), c; !(c = v.next()).done; ) ae(c.value) && ke(c.value, r); } } } function lr(e) { { var r = e.type; if (r == null || typeof r == "string") return; var t; if (typeof r == "function") t = r.propTypes; else if (typeof r == "object" && (r.$$typeof === p || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r.$$typeof === A)) t = r.propTypes; else return; if (t) { var a = F(r); Xe(t, e.props, "prop", a, e); } else if (r.PropTypes !== void 0 && !ne) { ne = !0; var f = F(r); l("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", f || "Unknown"); } typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && l("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function fr(e) { { for (var r = Object.keys(e.props), t = 0; t < r.length; t++) { var a = r[t]; if (a !== "children" && a !== "key") { W(e), l("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", a), W(null); break; } } e.ref !== null && (W(e), l("Invalid attribute `ref` supplied to `React.Fragment`."), W(null)); } } var xe = {}; function Oe(e, r, t, a, f, v) { { var c = Ue(e); if (!c) { var u = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (u += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var T = ur(); T ? u += T : u += Te(); var h; e === null ? h = "null" : re(e) ? h = "array" : e !== void 0 && e.$$typeof === n ? (h = "<" + (F(e.type) || "Unknown") + " />", u = " Did you accidentally export a JSX literal instead of a component?") : h = typeof e, l("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", h, u); } var m = sr(e, r, t, f, v); if (m == null) return m; if (c) { var j = r.children; if (j !== void 0) if (a) if (re(j)) { for (var Y = 0; Y < j.length; Y++) Ce(j[Y], e); Object.freeze && Object.freeze(j); } else l("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else Ce(j, e); } if (L.call(r, "key")) { var $ = F(e), x = Object.keys(r).filter(function(hr) { return hr !== "key"; }), oe = x.length > 0 ? "{key: someKey, " + x.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!xe[$ + oe]) { var gr = x.length > 0 ? "{" + x.join(": ..., ") + ": ...}" : "{}"; l(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, oe, $, gr, $), xe[$ + oe] = !0; } } return e === g ? fr(m) : lr(m), m; } } function dr(e, r, t) { return Oe(e, r, t, !0); } function vr(e, r, t) { return Oe(e, r, t, !1); } var yr = vr, pr = dr; U.Fragment = g, U.jsx = yr, U.jsxs = pr; }()), U; } var Ie; function Fr() { return Ie || (Ie = 1, process.env.NODE_ENV === "production" ? H.exports = jr() : H.exports = Dr()), H.exports; } var M = Fr(); const Nr = () => /* @__PURE__ */ M.jsx(Pe, { style: N.loadingContainer, children: /* @__PURE__ */ M.jsxs(Pe, { style: N.contentContainer, children: [ /* @__PURE__ */ M.jsx( Ar, { size: "large", color: "#007AFF", style: N.indicator } ), /* @__PURE__ */ M.jsx(je, { style: N.loadingText, children: "Preparing Encryption..." }), /* @__PURE__ */ M.jsx(je, { style: N.hintText, children: "This may take a moment..." }) ] }) }), N = Tr.create({ loadingContainer: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#fff", padding: 20 }, contentContainer: { width: "100%", maxWidth: 400, alignItems: "center", marginTop: -80, paddingBottom: 20 }, indicator: { marginBottom: 24 }, loadingText: { fontSize: 18, fontWeight: "bold", marginBottom: 16 }, hintText: { fontSize: 16, color: "#666", fontStyle: "italic", textAlign: "center" } }); var Ir = Object.defineProperty, Kr = (o, n, d) => n in o ? Ir(o, n, { enumerable: !0, configurable: !0, writable: !0, value: d }) : o[n] = d, Ke = (o, n, d) => Kr(o, typeof n != "symbol" ? n + "" : n, d); function $r(o) { return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o; } var J = {}, $e; function Wr() { if ($e) return J; $e = 1, J.byteLength = O, J.toByteArray = D, J.fromByteArray = P; for (var o = [], n = [], d = typeof Uint8Array < "u" ? Uint8Array : Array, g = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", E = 0, S = g.length; E < S; ++E) o[E] = g[E], n[g.charCodeAt(E)] = E; n[45] = 62, n[95] = 63; function w(i) { var s = i.length; if (s % 4 > 0) throw new Error("Invalid string. Length must be a multiple of 4"); var y = i.indexOf("="); y === -1 && (y = s); var _ = y === s ? 0 : 4 - y % 4; return [y, _]; } function O(i) { var s = w(i), y = s[0], _ = s[1]; return (y + _) * 3 / 4 - _; } function p(i, s, y) { return (s + y) * 3 / 4 - y; } function D(i) { var s, y = w(i), _ = y[0], b = y[1], l = new d(p(i, _, b)), k = 0, I = b > 0 ? _ - 4 : _, C; for (C = 0; C < I; C += 4) s = n[i.charCodeAt(C)] << 18 | n[i.charCodeAt(C + 1)] << 12 | n[i.charCodeAt(C + 2)] << 6 | n[i.charCodeAt(C + 3)], l[k++] = s >> 16 & 255, l[k++] = s >> 8 & 255, l[k++] = s & 255; return b === 2 && (s = n[i.charCodeAt(C)] << 2 | n[i.charCodeAt(C + 1)] >> 4, l[k++] = s & 255), b === 1 && (s = n[i.charCodeAt(C)] << 10 | n[i.charCodeAt(C + 1)] << 4 | n[i.charCodeAt(C + 2)] >> 2, l[k++] = s >> 8 & 255, l[k++] = s & 255), l; } function R(i) { return o[i >> 18 & 63] + o[i >> 12 & 63] + o[i >> 6 & 63] + o[i & 63]; } function A(i, s, y) { for (var _, b = [], l = s; l < y; l += 3) _ = (i[l] << 16 & 16711680) + (i[l + 1] << 8 & 65280) + (i[l + 2] & 255), b.push(R(_)); return b.join(""); } function P(i) { for (var s, y = i.length, _ = y % 3, b = [], l = 16383, k = 0, I = y - _; k < I; k += l) b.push(A(i, k, k + l > I ? I : k + l)); return _ === 1 ? (s = i[y - 1], b.push( o[s >> 2] + o[s << 4 & 63] + "==" )) : _ === 2 && (s = (i[y - 2] << 8) + i[y - 1], b.push( o[s >> 10] + o[s >> 4 & 63] + o[s << 2 & 63] + "=" )), b.join(""); } return J; } var Yr = Wr(); const We = /* @__PURE__ */ $r(Yr); class Br { /** * Creates a new instance of Uint8ArrayValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the binary data will be stored */ constructor(n, d) { Ke(this, "storage"), Ke(this, "key"), this.storage = n, this.key = d; } /** * Finds binary data from storage. * Automatically decodes the stored base64 string back to Uint8Array. * * @returns {Promise<Uint8Array | undefined>} A promise that resolves to the stored binary data or undefined if not found * @throws {Error} If there's an error accessing the storage or decoding the data */ async find() { const n = await this.storage.find(this.key); if (n) return We.toByteArray(n); } /** * Retrieves binary data from storage. * Unlike find(), this method throws an error if no value is found. * Automatically decodes the stored base64 string back to Uint8Array. * * @returns {Promise<Uint8Array>} A promise that resolves to the stored binary data * @throws {Error} If no value is found or if there's an error accessing/decoding the storage */ async retrieve() { const n = await this.find(); if (!n) throw new Error(`No value found for key ${this.key}`); return n; } /** * Saves binary data to storage. * Automatically encodes the Uint8Array to base64 for storage. * * @param {Uint8Array} value - The binary data to store * @returns {Promise<void>} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage or encoding the data */ async save(n) { return this.storage.save(this.key, We.fromByteArray(n)); } /** * Removes binary data from storage. * @returns {Promise<void>} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ async remove() { return this.storage.remove(this.key); } } class Jr extends Br { /** * Creates an instance of AesRawKeyStorage. * * @param {Storage} storage - The storage instance to be used for storing the AES raw key. */ constructor(n) { super(n, "aesRawKey"); } } export { Nr as AesProcessingView, Jr as AesRawKeyStorage, Mr as useAesKey };