expo-ii-integration
Version:
Expo library to enable smartphone native applications to invoke Internet Identity through a web application
1,088 lines (1,085 loc) • 37.3 kB
JavaScript
var Er = Object.defineProperty;
var wr = (c, t, o) => t in c ? Er(c, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : c[t] = o;
var V = (c, t, o) => wr(c, typeof t != "symbol" ? t + "" : t, o);
import Ve, { useState as le, useRef as $e, useCallback as Le, useEffect as Fe, createContext as br, useContext as Rr } from "react";
import { HttpAgent as _r, AnonymousIdentity as Pr, Actor as xr, toHex as Cr } from "@dfinity/agent";
import { DelegationIdentity as Ue, Ed25519KeyIdentity as Me, DelegationChain as Ke, isDelegationValid as kr } from "@dfinity/identity";
import * as We from "expo-web-browser";
import { useURL as Sr } from "expo-linking";
import { usePathname as Ir } from "expo-router";
class Or {
/**
* Creates a new instance of CanisterManager
*
* @param config - Configuration options for the CanisterManager
* @remarks
* - For local development with Chrome, only replicaPort is required
* - canisterPort and internetIdentityPort are only needed when accessing from a smartphone
*/
constructor({
dfxNetwork: t,
localIPAddress: o,
replicaPort: s = 4943,
canisterPort: p = 14943,
internetIdentityPort: u = 24943
}) {
this.getBackendCanisterURL = (d) => {
var y, v;
return this.dfxNetwork !== "local" ? `https://${d}.ic0.app/` : (v = (y = window == null ? void 0 : window.location) == null ? void 0 : y.origin) != null && v.includes("localhost") ? `http://localhost:${this.replicaPort}/?canisterId=${d}` : `https://${this.localIPAddress}:${this.canisterPort}/?canisterId=${d}`;
}, this.getFrontendCanisterURL = (d) => this.dfxNetwork !== "local" ? `https://${d}.icp0.io/` : this.isLocalhostSubdomainSupported() ? this.getLocalhostSubdomainCanisterURL(d) : `https://${this.localIPAddress}:${this.canisterPort}/?canisterId=${d}`, this.getInternetIdentityURL = (d) => this.dfxNetwork !== "local" ? "https://identity.ic0.app/" : this.isLocalhostSubdomainSupported() ? this.getLocalhostSubdomainCanisterURL(d) : `https://${this.localIPAddress}:${this.internetIdentityPort}/?canisterId=${d}`, this.isLocalhostSubdomainSupported = () => {
var d, y, v, _;
return (y = (d = window == null ? void 0 : window.location) == null ? void 0 : d.origin) != null && y.includes("localhost") ? !!(((_ = (v = window == null ? void 0 : window.navigator) == null ? void 0 : v.userAgent) == null ? void 0 : _.toLowerCase()) || "").includes("chrome") : !1;
}, this.getLocalhostSubdomainCanisterURL = (d) => `http://${d}.localhost:${this.replicaPort}/`, this.createActor = ({
canisterId: d,
interfaceFactory: y,
identity: v = new Pr()
}) => {
const _ = this.getBackendCanisterURL(d), b = {
host: _,
identity: v
// fetchOptions: {
// reactNative: {
// __nativeResponseType: 'base64',
// },
// },
// callOptions: {
// reactNative: {
// textStreaming: true,
// },
// },
}, w = new _r(b);
return this.dfxNetwork === "local" && w.fetchRootKey().catch((P) => {
throw console.warn(`Your local replica is not running: ${_}`), console.error(P), P;
}), xr.createActor(y, {
agent: w,
canisterId: d
});
}, this.dfxNetwork = t, this.localIPAddress = o, this.replicaPort = s, this.canisterPort = p, this.internetIdentityPort = u;
}
}
class Tr extends Error {
constructor(t, o) {
var s;
super(`Expected origin ${t}, got ${o}`), this.expectedOrigin = t, this.actualOrigin = o, this.name = "OriginMismatchError", (s = Error.captureStackTrace) == null || s.call(Error, this, this.constructor);
}
}
class jr {
/**
* Creates an instance of IframeMessenger
* @param errorFunc - Function to handle errors, defaults to console.error
*/
constructor(t = console.error) {
this.handlers = {}, this.errorFunc = t;
}
/**
* Registers a handler for a specific message kind
* @param kind - The type of message to handle
* @param handler - Function to handle messages of the specified kind
* @returns The IframeMessenger instance for chaining
*/
on(t, o) {
return this.handlers[t] = o, this;
}
/**
* Handles incoming message events
* @param event - The message event containing data from the iframe
*/
handleEvent(t) {
const o = t.data;
if (this.isValidMessageData(o)) {
const s = this.handlers[o.kind];
s ? s(o) : console.warn(`No handler registered for message kind: ${o.kind}`);
} else
console.warn("Invalid message format:", o);
}
/**
* Validates that the received message data matches the expected format
* @param data - The message data to validate
* @returns True if the data is valid, false otherwise
*/
isValidMessageData(t) {
if (!t || typeof t != "object")
return !1;
const o = t;
return "kind" in t && typeof o.kind == "string";
}
/**
* Opens an iframe with the specified URL in a modal-like overlay
* @param options - Options for opening the iframe
* @throws {WindowOpenError} If the iframe cannot be created
*/
async open({ url: t }) {
const o = new URL(t);
this.close(), this.setupEventHandler(o);
const s = document.createElement("div");
s.style.position = "fixed", s.style.top = "0", s.style.left = "0", s.style.width = "100%", s.style.height = "100%", s.style.backgroundColor = "rgba(0, 0, 0, 0.5)", s.style.zIndex = "2147483646", s.style.display = "flex", s.style.justifyContent = "center", s.style.alignItems = "center";
const p = document.createElement("div");
p.style.position = "relative", p.style.width = "400px", p.style.height = "600px", this.iframe = document.createElement("iframe"), this.iframe.style.width = "100%", this.iframe.style.height = "100%", this.iframe.style.border = "none", this.iframe.style.borderRadius = "8px", this.iframe.style.backgroundColor = "white", this.iframe.src = o.toString();
const u = document.createElement("button");
u.textContent = "×", u.style.position = "absolute", u.style.top = "-16px", u.style.right = "-16px", u.style.fontSize = "24px", u.style.width = "32px", u.style.height = "32px", u.style.border = "none", u.style.borderRadius = "50%", u.style.background = "white", u.style.color = "#333", u.style.cursor = "pointer", u.style.display = "flex", u.style.alignItems = "center", u.style.justifyContent = "center", u.style.boxShadow = "0 2px 4px rgba(0,0,0,0.2)", u.style.zIndex = "2147483647", u.onclick = () => this.close(), p.appendChild(this.iframe), p.appendChild(u), s.appendChild(p), document.body.appendChild(s);
}
/**
* Closes the iframe and removes it from the DOM
*/
async close() {
var t;
if (this.iframe) {
const o = (t = this.iframe.parentElement) == null ? void 0 : t.parentElement;
o && o.parentElement && o.parentElement.removeChild(o), delete this.iframe;
}
this.removeEventHandler();
}
/**
* Sets up the event handler for postMessage communication
* @param targetURL - The URL of the iframe for origin validation
*/
setupEventHandler(t) {
this.eventHandler = (o) => {
var s;
try {
if (((s = window == null ? void 0 : window.location) == null ? void 0 : s.origin) === o.origin)
return;
if (o.origin !== t.origin)
throw console.log("event", o), new Tr(t.origin, o.origin);
this.handleEvent(o);
} catch (p) {
const u = typeof p == "string" ? new Error(p) : p instanceof Error ? p : new Error(String(p));
this.handleError(u);
}
}, window.addEventListener("message", this.eventHandler);
}
/**
* Removes the event handler for postMessage communication
*/
removeEventHandler() {
this.eventHandler && (window.removeEventListener("message", this.eventHandler), this.eventHandler = void 0);
}
/**
* Handles errors by closing the iframe and calling the error handler
* @param error - The error to handle
*/
handleError(t) {
this.close(), this.errorFunc(t);
}
}
class Ar extends jr {
constructor(t = console.error) {
super(t);
}
}
const Dr = ({
easDeepLinkType: c,
deepLink: t,
frontendCanisterId: o
}) => {
if (t.startsWith("exp://"))
return "expo-go";
if (t.startsWith("http://localhost:8081"))
return "dev-server";
if (t.includes(o))
return "icp";
if (c)
return c;
throw new Error(
`Could not determine deep link type:
{
"easDeepLinkType": ${c === void 0 ? "undefined" : `"${c}"`},
"deepLink": "${t}",
"frontendCanisterId": "${o}"
}`
);
};
function $r(c, t) {
if (c.byteLength !== t.byteLength) return !1;
const o = new Uint8Array(c), s = new Uint8Array(t);
return o.every((p, u) => p === s[u]);
}
function zr({
localIPAddress: c,
dfxNetwork: t,
easDeepLinkType: o,
deepLink: s,
frontendCanisterId: p,
iiIntegrationCanisterId: u,
appKeyStorage: d,
delegationStorage: y,
platform: v
}) {
const [_, b] = le(!1), w = Sr(), [P, A] = le(
void 0
), [J, U] = le(void 0), B = $e(
void 0
), T = Ir(), m = $e(void 0), Z = Le(() => {
console.log("Saving path when login:", T), T && (m.current = T);
}, [T]), Q = Le(() => {
console.log("Clearing path when login:", m.current), m.current = void 0;
}, []);
Fe(() => {
if (_) {
console.log("skipping first useEffect");
return;
}
if (P) {
console.log("skipping first useEffect because identity is already set");
return;
}
(async () => {
try {
const R = await d.find(), x = await y.find();
if (R && x) {
const j = Ue.fromDelegation(
R,
x
);
A(j);
} else if (!R) {
const j = Me.generate();
await d.save(j), await y.remove();
}
} catch (R) {
U(R);
} finally {
b(!0);
}
})();
}, []);
const H = async (R) => {
console.log("Processing delegation");
const x = Ke.fromJSON(R);
await y.save(x);
const j = await d.retrieve(), D = x.delegations, $ = D[D.length - 1];
if (!$r(
$.delegation.pubkey,
j.getPublicKey().toDer()
))
throw new Error("Last delegation public key does not match app key");
const C = Ue.fromDelegation(j, x);
A(C), console.log("identity set from delegation");
};
return Fe(() => {
if (P || !w)
return;
const x = new URLSearchParams(w == null ? void 0 : w.split("#")[1]).get("delegation");
console.log("Delegation from URL:", x ? "present" : "not present"), x && (async () => {
try {
await H(x), We.dismissBrowser();
} catch (j) {
U(j);
}
})();
}, [w]), {
identity: P,
isReady: _,
isAuthenticated: !!P,
login: async () => {
try {
console.log("Logging in"), Z();
const R = await d.retrieve(), x = Cr(R.getPublicKey().toDer()), D = new Or({
dfxNetwork: t,
localIPAddress: c
}).getFrontendCanisterURL(
u
);
console.log("iiIntegrationURL", D);
const $ = Dr({
easDeepLinkType: o,
deepLink: s,
frontendCanisterId: p
});
console.log("deepLinkType", $);
const C = new URL(D);
if (C.searchParams.set("pubkey", x), C.searchParams.set("deep-link-type", $), v === "web") {
const I = new Ar();
B.current = I, I.on("success", async (L) => {
console.log("IIIntegration success"), await H(L.delegation), I.close(), B.current = void 0;
}), await I.open({
url: C.toString()
});
} else
await We.openBrowserAsync(C.toString());
} catch (R) {
U(R);
}
},
logout: async () => {
console.log("Logging out");
try {
await y.remove(), A(void 0), console.log("identity set to undefined after logout");
} catch (R) {
U(R);
}
},
pathWhenLogin: m.current,
clearPathWhenLogin: Q,
authError: J
};
}
var ce = { exports: {} }, M = {};
/**
* @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 Ne;
function Lr() {
if (Ne) return M;
Ne = 1;
var c = Ve, t = Symbol.for("react.element"), o = Symbol.for("react.fragment"), s = Object.prototype.hasOwnProperty, p = c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, u = { key: !0, ref: !0, __self: !0, __source: !0 };
function d(y, v, _) {
var b, w = {}, P = null, A = null;
_ !== void 0 && (P = "" + _), v.key !== void 0 && (P = "" + v.key), v.ref !== void 0 && (A = v.ref);
for (b in v) s.call(v, b) && !u.hasOwnProperty(b) && (w[b] = v[b]);
if (y && y.defaultProps) for (b in v = y.defaultProps, v) w[b] === void 0 && (w[b] = v[b]);
return { $$typeof: t, type: y, key: P, ref: A, props: w, _owner: p.current };
}
return M.Fragment = o, M.jsx = d, M.jsxs = d, M;
}
var K = {};
/**
* @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 Ye;
function Fr() {
return Ye || (Ye = 1, process.env.NODE_ENV !== "production" && function() {
var c = Ve, t = Symbol.for("react.element"), o = Symbol.for("react.portal"), s = Symbol.for("react.fragment"), p = Symbol.for("react.strict_mode"), u = Symbol.for("react.profiler"), d = Symbol.for("react.provider"), y = Symbol.for("react.context"), v = Symbol.for("react.forward_ref"), _ = Symbol.for("react.suspense"), b = Symbol.for("react.suspense_list"), w = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), A = Symbol.for("react.offscreen"), J = Symbol.iterator, U = "@@iterator";
function B(e) {
if (e === null || typeof e != "object")
return null;
var r = J && e[J] || e[U];
return typeof r == "function" ? r : null;
}
var T = c.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function m(e) {
{
for (var r = arguments.length, n = new Array(r > 1 ? r - 1 : 0), i = 1; i < r; i++)
n[i - 1] = arguments[i];
Z("error", e, n);
}
}
function Z(e, r, n) {
{
var i = T.ReactDebugCurrentFrame, f = i.getStackAddendum();
f !== "" && (r += "%s", n = n.concat([f]));
var h = n.map(function(l) {
return String(l);
});
h.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, h);
}
}
var Q = !1, H = !1, ue = !1, fe = !1, R = !1, x;
x = Symbol.for("react.module.reference");
function j(e) {
return !!(typeof e == "string" || typeof e == "function" || e === s || e === u || R || e === p || e === _ || e === b || fe || e === A || Q || H || ue || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === w || e.$$typeof === d || e.$$typeof === y || e.$$typeof === v || // 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 === x || e.getModuleId !== void 0));
}
function D(e, r, n) {
var i = e.displayName;
if (i)
return i;
var f = r.displayName || r.name || "";
return f !== "" ? n + "(" + f + ")" : n;
}
function $(e) {
return e.displayName || "Context";
}
function C(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && m("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 s:
return "Fragment";
case o:
return "Portal";
case u:
return "Profiler";
case p:
return "StrictMode";
case _:
return "Suspense";
case b:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case y:
var r = e;
return $(r) + ".Consumer";
case d:
var n = e;
return $(n._context) + ".Provider";
case v:
return D(e, e.render, "ForwardRef");
case w:
var i = e.displayName || null;
return i !== null ? i : C(e.type) || "Memo";
case P: {
var f = e, h = f._payload, l = f._init;
try {
return C(l(h));
} catch {
return null;
}
}
}
return null;
}
var I = Object.assign, L = 0, de, he, ve, pe, ge, ye, me;
function Ee() {
}
Ee.__reactDisabledLog = !0;
function Be() {
{
if (L === 0) {
de = console.log, he = console.info, ve = console.warn, pe = console.error, ge = console.group, ye = console.groupCollapsed, me = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: Ee,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
L++;
}
}
function He() {
{
if (L--, L === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: I({}, e, {
value: de
}),
info: I({}, e, {
value: he
}),
warn: I({}, e, {
value: ve
}),
error: I({}, e, {
value: pe
}),
group: I({}, e, {
value: ge
}),
groupCollapsed: I({}, e, {
value: ye
}),
groupEnd: I({}, e, {
value: me
})
});
}
L < 0 && m("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var ee = T.ReactCurrentDispatcher, re;
function q(e, r, n) {
{
if (re === void 0)
try {
throw Error();
} catch (f) {
var i = f.stack.trim().match(/\n( *(at )?)/);
re = i && i[1] || "";
}
return `
` + re + e;
}
}
var te = !1, z;
{
var qe = typeof WeakMap == "function" ? WeakMap : Map;
z = new qe();
}
function we(e, r) {
if (!e || te)
return "";
{
var n = z.get(e);
if (n !== void 0)
return n;
}
var i;
te = !0;
var f = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var h;
h = ee.current, ee.current = null, Be();
try {
if (r) {
var l = function() {
throw Error();
};
if (Object.defineProperty(l.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(l, []);
} catch (S) {
i = S;
}
Reflect.construct(e, [], l);
} else {
try {
l.call();
} catch (S) {
i = S;
}
e.call(l.prototype);
}
} else {
try {
throw Error();
} catch (S) {
i = S;
}
e();
}
} catch (S) {
if (S && i && typeof S.stack == "string") {
for (var a = S.stack.split(`
`), k = i.stack.split(`
`), g = a.length - 1, E = k.length - 1; g >= 1 && E >= 0 && a[g] !== k[E]; )
E--;
for (; g >= 1 && E >= 0; g--, E--)
if (a[g] !== k[E]) {
if (g !== 1 || E !== 1)
do
if (g--, E--, E < 0 || a[g] !== k[E]) {
var O = `
` + a[g].replace(" at new ", " at ");
return e.displayName && O.includes("<anonymous>") && (O = O.replace("<anonymous>", e.displayName)), typeof e == "function" && z.set(e, O), O;
}
while (g >= 1 && E >= 0);
break;
}
}
} finally {
te = !1, ee.current = h, He(), Error.prepareStackTrace = f;
}
var N = e ? e.displayName || e.name : "", F = N ? q(N) : "";
return typeof e == "function" && z.set(e, F), F;
}
function ze(e, r, n) {
return we(e, !1);
}
function Ge(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function G(e, r, n) {
if (e == null)
return "";
if (typeof e == "function")
return we(e, Ge(e));
if (typeof e == "string")
return q(e);
switch (e) {
case _:
return q("Suspense");
case b:
return q("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case v:
return ze(e.render);
case w:
return G(e.type, r, n);
case P: {
var i = e, f = i._payload, h = i._init;
try {
return G(h(f), r, n);
} catch {
}
}
}
return "";
}
var Y = Object.prototype.hasOwnProperty, be = {}, Re = T.ReactDebugCurrentFrame;
function X(e) {
if (e) {
var r = e._owner, n = G(e.type, e._source, r ? r.type : null);
Re.setExtraStackFrame(n);
} else
Re.setExtraStackFrame(null);
}
function Xe(e, r, n, i, f) {
{
var h = Function.call.bind(Y);
for (var l in e)
if (h(e, l)) {
var a = void 0;
try {
if (typeof e[l] != "function") {
var k = Error((i || "React class") + ": " + n + " type `" + l + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[l] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw k.name = "Invariant Violation", k;
}
a = e[l](r, l, i, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (g) {
a = g;
}
a && !(a instanceof Error) && (X(f), m("%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).", i || "React class", n, l, typeof a), X(null)), a instanceof Error && !(a.message in be) && (be[a.message] = !0, X(f), m("Failed %s type: %s", n, a.message), X(null));
}
}
}
var Ze = Array.isArray;
function ne(e) {
return Ze(e);
}
function Qe(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, n = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return n;
}
}
function er(e) {
try {
return _e(e), !1;
} catch {
return !0;
}
}
function _e(e) {
return "" + e;
}
function Pe(e) {
if (er(e))
return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Qe(e)), _e(e);
}
var xe = T.ReactCurrentOwner, rr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Ce, ke;
function tr(e) {
if (Y.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function nr(e) {
if (Y.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function or(e, r) {
typeof e.ref == "string" && xe.current;
}
function ir(e, r) {
{
var n = function() {
Ce || (Ce = !0, m("%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));
};
n.isReactWarning = !0, Object.defineProperty(e, "key", {
get: n,
configurable: !0
});
}
}
function ar(e, r) {
{
var n = function() {
ke || (ke = !0, m("%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));
};
n.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: n,
configurable: !0
});
}
}
var sr = function(e, r, n, i, f, h, l) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: t,
// Built-in properties that belong on the element
type: e,
key: r,
ref: n,
props: l,
// Record the component responsible for creating this element.
_owner: h
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(a, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: i
}), Object.defineProperty(a, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: f
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function lr(e, r, n, i, f) {
{
var h, l = {}, a = null, k = null;
n !== void 0 && (Pe(n), a = "" + n), nr(r) && (Pe(r.key), a = "" + r.key), tr(r) && (k = r.ref, or(r, f));
for (h in r)
Y.call(r, h) && !rr.hasOwnProperty(h) && (l[h] = r[h]);
if (e && e.defaultProps) {
var g = e.defaultProps;
for (h in g)
l[h] === void 0 && (l[h] = g[h]);
}
if (a || k) {
var E = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && ir(l, E), k && ar(l, E);
}
return sr(e, a, k, f, i, xe.current, l);
}
}
var oe = T.ReactCurrentOwner, Se = T.ReactDebugCurrentFrame;
function W(e) {
if (e) {
var r = e._owner, n = G(e.type, e._source, r ? r.type : null);
Se.setExtraStackFrame(n);
} else
Se.setExtraStackFrame(null);
}
var ie;
ie = !1;
function ae(e) {
return typeof e == "object" && e !== null && e.$$typeof === t;
}
function Ie() {
{
if (oe.current) {
var e = C(oe.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function cr(e) {
return "";
}
var Oe = {};
function ur(e) {
{
var r = Ie();
if (!r) {
var n = typeof e == "string" ? e : e.displayName || e.name;
n && (r = `
Check the top-level render call using <` + n + ">.");
}
return r;
}
}
function Te(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var n = ur(r);
if (Oe[n])
return;
Oe[n] = !0;
var i = "";
e && e._owner && e._owner !== oe.current && (i = " It was passed a child from " + C(e._owner.type) + "."), W(e), m('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, i), W(null);
}
}
function je(e, r) {
{
if (typeof e != "object")
return;
if (ne(e))
for (var n = 0; n < e.length; n++) {
var i = e[n];
ae(i) && Te(i, r);
}
else if (ae(e))
e._store && (e._store.validated = !0);
else if (e) {
var f = B(e);
if (typeof f == "function" && f !== e.entries)
for (var h = f.call(e), l; !(l = h.next()).done; )
ae(l.value) && Te(l.value, r);
}
}
}
function fr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var n;
if (typeof r == "function")
n = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === v || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === w))
n = r.propTypes;
else
return;
if (n) {
var i = C(r);
Xe(n, e.props, "prop", i, e);
} else if (r.PropTypes !== void 0 && !ie) {
ie = !0;
var f = C(r);
m("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", f || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function dr(e) {
{
for (var r = Object.keys(e.props), n = 0; n < r.length; n++) {
var i = r[n];
if (i !== "children" && i !== "key") {
W(e), m("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", i), W(null);
break;
}
}
e.ref !== null && (W(e), m("Invalid attribute `ref` supplied to `React.Fragment`."), W(null));
}
}
var Ae = {};
function De(e, r, n, i, f, h) {
{
var l = j(e);
if (!l) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " 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 k = cr();
k ? a += k : a += Ie();
var g;
e === null ? g = "null" : ne(e) ? g = "array" : e !== void 0 && e.$$typeof === t ? (g = "<" + (C(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : g = typeof e, m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", g, a);
}
var E = lr(e, r, n, f, h);
if (E == null)
return E;
if (l) {
var O = r.children;
if (O !== void 0)
if (i)
if (ne(O)) {
for (var N = 0; N < O.length; N++)
je(O[N], e);
Object.freeze && Object.freeze(O);
} else
m("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
je(O, e);
}
if (Y.call(r, "key")) {
var F = C(e), S = Object.keys(r).filter(function(mr) {
return mr !== "key";
}), se = S.length > 0 ? "{key: someKey, " + S.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!Ae[F + se]) {
var yr = S.length > 0 ? "{" + S.join(": ..., ") + ": ...}" : "{}";
m(`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} />`, se, F, yr, F), Ae[F + se] = !0;
}
}
return e === s ? dr(E) : fr(E), E;
}
}
function hr(e, r, n) {
return De(e, r, n, !0);
}
function vr(e, r, n) {
return De(e, r, n, !1);
}
var pr = vr, gr = hr;
K.Fragment = s, K.jsx = pr, K.jsxs = gr;
}()), K;
}
process.env.NODE_ENV === "production" ? ce.exports = Lr() : ce.exports = Fr();
var Ur = ce.exports;
const Je = br(void 0);
function Gr() {
const c = Rr(Je);
if (c === void 0)
throw new Error(
"useIIIntegrationContext must be used within an IIIntegrationProvider"
);
return c;
}
function Xr({
children: c,
value: t
}) {
return /* @__PURE__ */ Ur.jsx(Je.Provider, { value: t, children: c });
}
class Wr {
/**
* Creates a new instance of Ed25519KeyIdentityValueStorageWrapper.
* @param storage - The storage implementation to use for persistence
* @param key - The key under which the Ed25519KeyIdentity will be stored
*/
constructor(t, o) {
V(this, "storage");
V(this, "key");
this.storage = t, this.key = o;
}
/**
* Attempts to find and retrieve an Ed25519KeyIdentity from storage.
* @returns A Promise that resolves to the found Ed25519KeyIdentity or undefined if not found
*/
async find() {
const t = await this.storage.find(this.key);
if (t)
return Me.fromJSON(t);
}
/**
* Retrieves an Ed25519KeyIdentity from storage, throwing an error if not found.
* @returns A Promise that resolves to the found Ed25519KeyIdentity
* @throws {Error} If no Ed25519KeyIdentity is found for the configured key
*/
async retrieve() {
const t = await this.find();
if (!t)
throw new Error(`No value found for key ${this.key}`);
return t;
}
/**
* Saves an Ed25519KeyIdentity to storage.
* @param value - The Ed25519KeyIdentity to save
* @returns A Promise that resolves when the save operation is complete
*/
async save(t) {
return this.storage.save(this.key, JSON.stringify(t.toJSON()));
}
/**
* Removes the stored Ed25519KeyIdentity from storage.
* @returns A Promise that resolves when the removal operation is complete
*/
async remove() {
return this.storage.remove(this.key);
}
}
const Nr = "appKey";
class Zr extends Wr {
/**
* Creates a new instance of AppKeyStorage.
* @param storage - The storage implementation to use for persistence
*/
constructor(t) {
super(t, Nr);
}
}
class Yr {
/**
* Creates a new instance of DelegationChainValueStorageWrapper.
* @param storage - The storage implementation to use for persistence
* @param key - The key under which the DelegationChain will be stored
*/
constructor(t, o) {
V(this, "storage");
V(this, "key");
this.storage = t, this.key = o;
}
/**
* Attempts to find and retrieve a DelegationChain from storage.
* If the stored delegation chain is invalid, it will be automatically removed from storage.
* @returns A Promise that resolves to the found DelegationChain or undefined if not found or invalid
*/
async find() {
const t = await this.storage.find(this.key);
if (!t)
return;
const o = Ke.fromJSON(t);
if (!kr(o)) {
console.log("Invalid delegation chain, removing delegation"), await this.remove();
return;
}
return o;
}
/**
* Retrieves a DelegationChain from storage, throwing an error if not found or invalid.
* @returns A Promise that resolves to the found and valid DelegationChain
* @throws {Error} If no valid DelegationChain is found for the configured key
*/
async retrieve() {
const t = await this.find();
if (!t)
throw new Error(`No value found for key ${this.key}`);
return t;
}
/**
* Saves a DelegationChain to storage.
* @param value - The DelegationChain to save
* @returns A Promise that resolves when the save operation is complete
*/
async save(t) {
return this.storage.save(this.key, JSON.stringify(t.toJSON()));
}
/**
* Removes the stored DelegationChain from storage.
* @returns A Promise that resolves when the removal operation is complete
*/
async remove() {
return this.storage.remove(this.key);
}
}
const Vr = "delegation";
class Qr extends Yr {
/**
* Creates a new instance of DelegationStorage.
* @param storage - The storage implementation to use for persistence
*/
constructor(t) {
super(t, Vr);
}
}
export {
Zr as AppKeyStorage,
Yr as DelegationChainValueStorageWrapper,
Qr as DelegationStorage,
Wr as Ed25519KeyIdentityValueStorageWrapper,
Xr as IIIntegrationProvider,
zr as useIIIntegration,
Gr as useIIIntegrationContext
};