@multiplatform.one/gpg 9.17.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/GpgButton.cjs +27 -41
- package/dist/cjs/GpgButton.native.cjs +56 -0
- package/dist/cjs/GpgButton.native.js +32 -52
- package/dist/cjs/GpgButton.native.js.map +1 -1
- package/dist/cjs/GpgContext.cjs +19 -21
- package/dist/cjs/GpgContext.native.cjs +36 -0
- package/dist/cjs/GpgContext.native.js +20 -21
- package/dist/cjs/GpgContext.native.js.map +1 -1
- package/dist/cjs/GpgIcon.cjs +40 -44
- package/dist/cjs/GpgIcon.native.cjs +62 -0
- package/dist/cjs/GpgIcon.native.js +44 -52
- package/dist/cjs/GpgIcon.native.js.map +1 -1
- package/dist/cjs/GpgProvider.cjs +88 -104
- package/dist/cjs/GpgProvider.native.cjs +120 -0
- package/dist/cjs/GpgProvider.native.js +96 -111
- package/dist/cjs/GpgProvider.native.js.map +1 -1
- package/dist/cjs/SignInWithGpg.cjs +108 -112
- package/dist/cjs/SignInWithGpg.native.cjs +140 -0
- package/dist/cjs/SignInWithGpg.native.js +115 -132
- package/dist/cjs/SignInWithGpg.native.js.map +1 -1
- package/dist/cjs/index.cjs +32 -39
- package/dist/cjs/index.native.cjs +55 -0
- package/dist/cjs/index.native.js +32 -38
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/screens.cjs +39 -52
- package/dist/cjs/screens.native.cjs +78 -0
- package/dist/cjs/screens.native.js +49 -61
- package/dist/cjs/screens.native.js.map +1 -1
- package/dist/cjs/signature.cjs +92 -90
- package/dist/cjs/signature.native.cjs +125 -0
- package/dist/cjs/signature.native.js +100 -97
- package/dist/cjs/signature.native.js.map +1 -1
- package/dist/cjs/signer.cjs +86 -92
- package/dist/cjs/signer.native.cjs +141 -0
- package/dist/cjs/signer.native.js +112 -119
- package/dist/cjs/signer.native.js.map +1 -1
- package/dist/cjs/useGpg.cjs +46 -57
- package/dist/cjs/useGpg.native.cjs +65 -0
- package/dist/cjs/useGpg.native.js +50 -60
- package/dist/cjs/useGpg.native.js.map +1 -1
- package/dist/esm/GpgButton.mjs +14 -24
- package/dist/esm/GpgButton.mjs.map +1 -1
- package/dist/esm/GpgButton.native.js +18 -30
- package/dist/esm/GpgButton.native.js.map +1 -1
- package/dist/esm/GpgContext.mjs +6 -4
- package/dist/esm/GpgContext.mjs.map +1 -1
- package/dist/esm/GpgContext.native.js +7 -5
- package/dist/esm/GpgContext.native.js.map +1 -1
- package/dist/esm/GpgIcon.mjs +28 -26
- package/dist/esm/GpgIcon.mjs.map +1 -1
- package/dist/esm/GpgIcon.native.js +31 -29
- package/dist/esm/GpgIcon.native.js.map +1 -1
- package/dist/esm/GpgProvider.mjs +76 -88
- package/dist/esm/GpgProvider.mjs.map +1 -1
- package/dist/esm/GpgProvider.native.js +85 -97
- package/dist/esm/GpgProvider.native.js.map +1 -1
- package/dist/esm/SignInWithGpg.mjs +97 -95
- package/dist/esm/SignInWithGpg.mjs.map +1 -1
- package/dist/esm/SignInWithGpg.native.js +102 -109
- package/dist/esm/SignInWithGpg.native.js.map +1 -1
- package/dist/esm/index.mjs +7 -7
- package/dist/esm/index.native.js +7 -7
- package/dist/esm/screens.mjs +23 -27
- package/dist/esm/screens.mjs.map +1 -1
- package/dist/esm/screens.native.js +34 -39
- package/dist/esm/screens.native.js.map +1 -1
- package/dist/esm/signature.mjs +80 -72
- package/dist/esm/signature.mjs.map +1 -1
- package/dist/esm/signature.native.js +88 -80
- package/dist/esm/signature.native.js.map +1 -1
- package/dist/esm/signer.mjs +69 -72
- package/dist/esm/signer.mjs.map +1 -1
- package/dist/esm/signer.native.js +95 -100
- package/dist/esm/signer.native.js.map +1 -1
- package/dist/esm/useGpg.mjs +34 -39
- package/dist/esm/useGpg.mjs.map +1 -1
- package/dist/esm/useGpg.native.js +38 -43
- package/dist/esm/useGpg.native.js.map +1 -1
- package/package.json +6 -6
- package/types/GpgProvider.d.ts +1 -1
- package/types/GpgProvider.d.ts.map +1 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
|
|
3
4
|
var GpgIcon = function GpgIcon2() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
6
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
7
|
+
width: "100%",
|
|
8
|
+
height: "100%",
|
|
9
|
+
viewBox: "0 0 32 32",
|
|
10
|
+
"aria-hidden": "true",
|
|
11
|
+
children: [/* @__PURE__ */ jsx("rect", {
|
|
12
|
+
width: "32",
|
|
13
|
+
height: "32",
|
|
14
|
+
fill: "#0093DD"
|
|
15
|
+
}), /* @__PURE__ */ jsxs("g", {
|
|
16
|
+
fill: "none",
|
|
17
|
+
stroke: "#FFFFFF",
|
|
18
|
+
strokeWidth: "2.2",
|
|
19
|
+
strokeLinecap: "round",
|
|
20
|
+
strokeLinejoin: "round",
|
|
21
|
+
children: [
|
|
22
|
+
/* @__PURE__ */ jsx("circle", {
|
|
23
|
+
cx: "11.5",
|
|
24
|
+
cy: "19.5",
|
|
25
|
+
r: "4.5"
|
|
26
|
+
}),
|
|
27
|
+
/* @__PURE__ */ jsx("path", { d: "m14.7 16.3 9.3-9.3" }),
|
|
28
|
+
/* @__PURE__ */ jsx("path", { d: "m20 11 3 3 2.5-2.5-3-3" })
|
|
29
|
+
]
|
|
30
|
+
})]
|
|
31
|
+
});
|
|
31
32
|
};
|
|
33
|
+
|
|
32
34
|
export { GpgIcon };
|
|
33
35
|
//# sourceMappingURL=GpgIcon.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"GpgIcon.native.js","names":[],"sources":["esm/GpgIcon.native.js"],"sourcesContent":["import { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nimport React from \"react\";\nvar GpgIcon = function GpgIcon2() {\n return /* @__PURE__ */ _jsxs(\"svg\", {\n xmlns: \"http://www.w3.org/2000/svg\",\n width: \"100%\",\n height: \"100%\",\n viewBox: \"0 0 32 32\",\n \"aria-hidden\": \"true\",\n children: [\n /* @__PURE__ */ _jsx(\"rect\", {\n width: \"32\",\n height: \"32\",\n fill: \"#0093DD\"\n }),\n /* @__PURE__ */ _jsxs(\"g\", {\n fill: \"none\",\n stroke: \"#FFFFFF\",\n strokeWidth: \"2.2\",\n strokeLinecap: \"round\",\n strokeLinejoin: \"round\",\n children: [\n /* @__PURE__ */ _jsx(\"circle\", {\n cx: \"11.5\",\n cy: \"19.5\",\n r: \"4.5\"\n }),\n /* @__PURE__ */ _jsx(\"path\", {\n d: \"m14.7 16.3 9.3-9.3\"\n }),\n /* @__PURE__ */ _jsx(\"path\", {\n d: \"m20 11 3 3 2.5-2.5-3-3\"\n })\n ]\n })\n ]\n });\n};\nexport {\n GpgIcon\n};\n//# sourceMappingURL=GpgIcon.js.map\n"],"mappings":";;;;AAEA,IAAI,UAAU,SAAS,WAAW;CAChC,OAAuB,qBAAM,OAAO;EAClC,OAAO;EACP,OAAO;EACP,QAAQ;EACR,SAAS;EACT,eAAe;EACf,UAAU,CACQ,oBAAK,QAAQ;GAC3B,OAAO;GACP,QAAQ;GACR,MAAM;EACR,CAAC,GACe,qBAAM,KAAK;GACzB,MAAM;GACN,QAAQ;GACR,aAAa;GACb,eAAe;GACf,gBAAgB;GAChB,UAAU;IACQ,oBAAK,UAAU;KAC7B,IAAI;KACJ,IAAI;KACJ,GAAG;IACL,CAAC;IACe,oBAAK,QAAQ,EAC3B,GAAG,qBACL,CAAC;IACe,oBAAK,QAAQ,EAC3B,GAAG,yBACL,CAAC;GACH;EACF,CAAC,CACH;CACF,CAAC;AACH"}
|
package/dist/esm/GpgProvider.mjs
CHANGED
|
@@ -1,97 +1,85 @@
|
|
|
1
1
|
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import { Context
|
|
3
|
+
import { Context } from "@multiplatform.one/connectkit";
|
|
4
4
|
import { GpgContext, GpgStatusState } from "./GpgContext.mjs";
|
|
5
5
|
import { assertGpgSignature, gpgSignCommand } from "./signer.mjs";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
|
|
7
8
|
const GPG_NONCE_QUERY_KEY = "ckGpgNonce";
|
|
8
|
-
const b64 = s => window.btoa(unescape(encodeURIComponent(s)));
|
|
9
|
-
const GpgProvider = ({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
value: {
|
|
82
|
-
enabled,
|
|
83
|
-
nonceRefetchInterval,
|
|
84
|
-
buildMessage,
|
|
85
|
-
...gpgConfig,
|
|
86
|
-
nonce,
|
|
87
|
-
message,
|
|
88
|
-
command,
|
|
89
|
-
status,
|
|
90
|
-
signIn,
|
|
91
|
-
resetStatus
|
|
92
|
-
},
|
|
93
|
-
children
|
|
94
|
-
});
|
|
9
|
+
const b64 = (s) => window.btoa(unescape(encodeURIComponent(s)));
|
|
10
|
+
const GpgProvider = ({ children, enabled = true, nonceRefetchInterval = false, buildMessage, onSignIn, ...gpgConfig }) => {
|
|
11
|
+
const [status, setStatus] = useState(GpgStatusState.READY);
|
|
12
|
+
const resetStatus = () => setStatus(GpgStatusState.READY);
|
|
13
|
+
if (useContext(GpgContext)) {
|
|
14
|
+
throw new Error("Multiple, nested usages of GpgProvider detected. Please use only one.");
|
|
15
|
+
}
|
|
16
|
+
if (useContext(Context)) {
|
|
17
|
+
throw new Error("ConnectKitProvider must be mounted inside GpgProvider.");
|
|
18
|
+
}
|
|
19
|
+
const nonce = useQuery({
|
|
20
|
+
queryKey: [GPG_NONCE_QUERY_KEY],
|
|
21
|
+
queryFn: () => gpgConfig.getNonce(),
|
|
22
|
+
refetchInterval: nonceRefetchInterval,
|
|
23
|
+
refetchOnWindowFocus: false,
|
|
24
|
+
refetchOnReconnect: false,
|
|
25
|
+
staleTime: Infinity
|
|
26
|
+
});
|
|
27
|
+
const { subscribeNonceReset } = gpgConfig;
|
|
28
|
+
const refetchNonce = nonce.refetch;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!subscribeNonceReset) return;
|
|
31
|
+
return subscribeNonceReset(() => {
|
|
32
|
+
void refetchNonce();
|
|
33
|
+
});
|
|
34
|
+
}, [subscribeNonceReset, refetchNonce]);
|
|
35
|
+
const buildMessageRef = useRef(buildMessage);
|
|
36
|
+
buildMessageRef.current = buildMessage;
|
|
37
|
+
const message = useMemo(() => nonce.data ? buildMessageRef.current({ nonce: nonce.data }) : null, [nonce.data]);
|
|
38
|
+
const command = useMemo(() => message ? gpgSignCommand(message) : null, [message]);
|
|
39
|
+
const signIn = async (pastedBlob) => {
|
|
40
|
+
let blob;
|
|
41
|
+
try {
|
|
42
|
+
blob = assertGpgSignature(pastedBlob);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
setStatus(GpgStatusState.ERROR);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
if (!message) {
|
|
48
|
+
setStatus(GpgStatusState.ERROR);
|
|
49
|
+
throw new Error("Could not fetch nonce");
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
setStatus(GpgStatusState.LOADING);
|
|
53
|
+
const result = await gpgConfig.onSign({
|
|
54
|
+
username: b64(blob),
|
|
55
|
+
password: b64(message),
|
|
56
|
+
message
|
|
57
|
+
});
|
|
58
|
+
if (result === false) throw new Error("GPG sign-in was rejected");
|
|
59
|
+
setStatus(GpgStatusState.SUCCESS);
|
|
60
|
+
onSignIn?.();
|
|
61
|
+
return true;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
setStatus(GpgStatusState.ERROR);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return /* @__PURE__ */ jsx(GpgContext.Provider, {
|
|
68
|
+
value: {
|
|
69
|
+
enabled,
|
|
70
|
+
nonceRefetchInterval,
|
|
71
|
+
buildMessage,
|
|
72
|
+
...gpgConfig,
|
|
73
|
+
nonce,
|
|
74
|
+
message,
|
|
75
|
+
command,
|
|
76
|
+
status,
|
|
77
|
+
signIn,
|
|
78
|
+
resetStatus
|
|
79
|
+
},
|
|
80
|
+
children
|
|
81
|
+
});
|
|
95
82
|
};
|
|
83
|
+
|
|
96
84
|
export { GPG_NONCE_QUERY_KEY, GpgProvider };
|
|
97
85
|
//# sourceMappingURL=GpgProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"GpgProvider.js","names":["ConnectKitContext"],"sources":["esm/GpgProvider.js"],"sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { Context as ConnectKitContext } from \"@multiplatform.one/connectkit\";\nimport { GpgContext, GpgStatusState } from \"./GpgContext\";\nimport { assertGpgSignature, gpgSignCommand } from \"./signer\";\nimport { jsx } from \"react/jsx-runtime\";\nconst GPG_NONCE_QUERY_KEY = \"ckGpgNonce\";\nconst b64 = (s) => window.btoa(unescape(encodeURIComponent(s)));\nconst GpgProvider = ({\n children,\n enabled = true,\n nonceRefetchInterval = false,\n buildMessage,\n onSignIn,\n ...gpgConfig\n}) => {\n const [status, setStatus] = useState(GpgStatusState.READY);\n const resetStatus = () => setStatus(GpgStatusState.READY);\n if (useContext(GpgContext)) {\n throw new Error(\"Multiple, nested usages of GpgProvider detected. Please use only one.\");\n }\n if (useContext(ConnectKitContext)) {\n throw new Error(\"ConnectKitProvider must be mounted inside GpgProvider.\");\n }\n const nonce = useQuery({\n queryKey: [GPG_NONCE_QUERY_KEY],\n queryFn: () => gpgConfig.getNonce(),\n refetchInterval: nonceRefetchInterval,\n // The challenge the user signs MUST equal the one we submit. Never refetch the nonce\n // out from under an in-flight signature — especially on window-focus, which fires every\n // time the user tabs to their terminal to run gpg and back.\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity\n });\n const { subscribeNonceReset } = gpgConfig;\n const refetchNonce = nonce.refetch;\n useEffect(() => {\n if (!subscribeNonceReset) return;\n return subscribeNonceReset(() => {\n void refetchNonce();\n });\n }, [subscribeNonceReset, refetchNonce]);\n const buildMessageRef = useRef(buildMessage);\n buildMessageRef.current = buildMessage;\n const message = useMemo(\n () => nonce.data ? buildMessageRef.current({ nonce: nonce.data }) : null,\n [nonce.data]\n );\n const command = useMemo(() => message ? gpgSignCommand(message) : null, [message]);\n const signIn = async (pastedBlob) => {\n let blob;\n try {\n blob = assertGpgSignature(pastedBlob);\n } catch (error) {\n setStatus(GpgStatusState.ERROR);\n throw error;\n }\n if (!message) {\n setStatus(GpgStatusState.ERROR);\n throw new Error(\"Could not fetch nonce\");\n }\n try {\n setStatus(GpgStatusState.LOADING);\n const result = await gpgConfig.onSign({\n username: b64(blob),\n password: b64(message),\n message\n });\n if (result === false) throw new Error(\"GPG sign-in was rejected\");\n setStatus(GpgStatusState.SUCCESS);\n onSignIn?.();\n return true;\n } catch (error) {\n setStatus(GpgStatusState.ERROR);\n throw error;\n }\n };\n return /* @__PURE__ */ jsx(\n GpgContext.Provider,\n {\n value: {\n enabled,\n nonceRefetchInterval,\n buildMessage,\n ...gpgConfig,\n nonce,\n message,\n command,\n status,\n signIn,\n resetStatus\n },\n children\n }\n );\n};\nexport {\n GPG_NONCE_QUERY_KEY,\n GpgProvider\n};\n//# sourceMappingURL=GpgProvider.js.map\n"],"mappings":";;;;;;;;AAMA,MAAM,sBAAsB;AAC5B,MAAM,OAAO,MAAM,OAAO,KAAK,SAAS,mBAAmB,CAAC,CAAC,CAAC;AAC9D,MAAM,eAAe,EACnB,UACA,UAAU,MACV,uBAAuB,OACvB,cACA,UACA,GAAG,gBACC;CACJ,MAAM,CAAC,QAAQ,aAAa,SAAS,eAAe,KAAK;CACzD,MAAM,oBAAoB,UAAU,eAAe,KAAK;CACxD,IAAI,WAAW,UAAU,GAAG;EAC1B,MAAM,IAAI,MAAM,uEAAuE;CACzF;CACA,IA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;GACA;GACA;EACF;EACA;CACF,CACF;AACF"}
|
|
@@ -1,108 +1,96 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import { Context
|
|
4
|
+
import { Context } from "@multiplatform.one/connectkit";
|
|
5
5
|
import { GpgContext, GpgStatusState } from "./GpgContext.native.js";
|
|
6
6
|
import { assertGpgSignature, gpgSignCommand } from "./signer.native.js";
|
|
7
|
+
|
|
7
8
|
var GPG_NONCE_QUERY_KEY = "ckGpgNonce";
|
|
8
9
|
var b64 = function b642(s) {
|
|
9
|
-
|
|
10
|
+
return window.btoa(unescape(encodeURIComponent(s)));
|
|
10
11
|
};
|
|
11
12
|
var GpgProvider = function GpgProvider2(param) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
value: {
|
|
93
|
-
enabled,
|
|
94
|
-
nonceRefetchInterval,
|
|
95
|
-
buildMessage,
|
|
96
|
-
...gpgConfig,
|
|
97
|
-
nonce,
|
|
98
|
-
message,
|
|
99
|
-
command,
|
|
100
|
-
status,
|
|
101
|
-
signIn,
|
|
102
|
-
resetStatus
|
|
103
|
-
},
|
|
104
|
-
children
|
|
105
|
-
});
|
|
13
|
+
var { children, enabled = true, nonceRefetchInterval = false, buildMessage, onSignIn, ...gpgConfig } = param;
|
|
14
|
+
var [status, setStatus] = useState(GpgStatusState.READY);
|
|
15
|
+
var resetStatus = function resetStatus2() {
|
|
16
|
+
return setStatus(GpgStatusState.READY);
|
|
17
|
+
};
|
|
18
|
+
if (useContext(GpgContext)) {
|
|
19
|
+
throw new Error("Multiple, nested usages of GpgProvider detected. Please use only one.");
|
|
20
|
+
}
|
|
21
|
+
if (useContext(Context)) {
|
|
22
|
+
throw new Error("ConnectKitProvider must be mounted inside GpgProvider.");
|
|
23
|
+
}
|
|
24
|
+
var nonce = useQuery({
|
|
25
|
+
queryKey: [GPG_NONCE_QUERY_KEY],
|
|
26
|
+
queryFn: function queryFn() {
|
|
27
|
+
return gpgConfig.getNonce();
|
|
28
|
+
},
|
|
29
|
+
refetchInterval: nonceRefetchInterval,
|
|
30
|
+
refetchOnWindowFocus: false,
|
|
31
|
+
refetchOnReconnect: false,
|
|
32
|
+
staleTime: Infinity
|
|
33
|
+
});
|
|
34
|
+
var { subscribeNonceReset } = gpgConfig;
|
|
35
|
+
var refetchNonce = nonce.refetch;
|
|
36
|
+
useEffect(function() {
|
|
37
|
+
if (!subscribeNonceReset) return;
|
|
38
|
+
return subscribeNonceReset(function() {
|
|
39
|
+
void refetchNonce();
|
|
40
|
+
});
|
|
41
|
+
}, [subscribeNonceReset, refetchNonce]);
|
|
42
|
+
var buildMessageRef = useRef(buildMessage);
|
|
43
|
+
buildMessageRef.current = buildMessage;
|
|
44
|
+
var message = useMemo(function() {
|
|
45
|
+
return nonce.data ? buildMessageRef.current({ nonce: nonce.data }) : null;
|
|
46
|
+
}, [nonce.data]);
|
|
47
|
+
var command = useMemo(function() {
|
|
48
|
+
return message ? gpgSignCommand(message) : null;
|
|
49
|
+
}, [message]);
|
|
50
|
+
var signIn = async function signIn2(pastedBlob) {
|
|
51
|
+
var blob;
|
|
52
|
+
try {
|
|
53
|
+
blob = assertGpgSignature(pastedBlob);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
setStatus(GpgStatusState.ERROR);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
if (!message) {
|
|
59
|
+
setStatus(GpgStatusState.ERROR);
|
|
60
|
+
throw new Error("Could not fetch nonce");
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
setStatus(GpgStatusState.LOADING);
|
|
64
|
+
var result = await gpgConfig.onSign({
|
|
65
|
+
username: b64(blob),
|
|
66
|
+
password: b64(message),
|
|
67
|
+
message
|
|
68
|
+
});
|
|
69
|
+
if (result === false) throw new Error("GPG sign-in was rejected");
|
|
70
|
+
setStatus(GpgStatusState.SUCCESS);
|
|
71
|
+
onSignIn === null || onSignIn === void 0 ? void 0 : onSignIn();
|
|
72
|
+
return true;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
setStatus(GpgStatusState.ERROR);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return /* @__PURE__ */ jsx(GpgContext.Provider, {
|
|
79
|
+
value: {
|
|
80
|
+
enabled,
|
|
81
|
+
nonceRefetchInterval,
|
|
82
|
+
buildMessage,
|
|
83
|
+
...gpgConfig,
|
|
84
|
+
nonce,
|
|
85
|
+
message,
|
|
86
|
+
command,
|
|
87
|
+
status,
|
|
88
|
+
signIn,
|
|
89
|
+
resetStatus
|
|
90
|
+
},
|
|
91
|
+
children
|
|
92
|
+
});
|
|
106
93
|
};
|
|
94
|
+
|
|
107
95
|
export { GPG_NONCE_QUERY_KEY, GpgProvider };
|
|
108
96
|
//# sourceMappingURL=GpgProvider.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"GpgProvider.native.js","names":["ConnectKitContext"],"sources":["esm/GpgProvider.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { Context as ConnectKitContext } from \"@multiplatform.one/connectkit\";\nimport { GpgContext, GpgStatusState } from \"./GpgContext\";\nimport { assertGpgSignature, gpgSignCommand } from \"./signer\";\nvar GPG_NONCE_QUERY_KEY = \"ckGpgNonce\";\nvar b64 = function b642(s) {\n return window.btoa(unescape(encodeURIComponent(s)));\n};\nvar GpgProvider = function GpgProvider2(param) {\n var { children, enabled = true, nonceRefetchInterval = false, buildMessage, onSignIn, ...gpgConfig } = param;\n var [status, setStatus] = useState(GpgStatusState.READY);\n var resetStatus = function resetStatus2() {\n return setStatus(GpgStatusState.READY);\n };\n if (useContext(GpgContext)) {\n throw new Error(\"Multiple, nested usages of GpgProvider detected. Please use only one.\");\n }\n if (useContext(ConnectKitContext)) {\n throw new Error(\"ConnectKitProvider must be mounted inside GpgProvider.\");\n }\n var nonce = useQuery({\n queryKey: [\n GPG_NONCE_QUERY_KEY\n ],\n queryFn: function queryFn() {\n return gpgConfig.getNonce();\n },\n refetchInterval: nonceRefetchInterval,\n // The challenge the user signs MUST equal the one we submit. Never refetch the nonce\n // out from under an in-flight signature — especially on window-focus, which fires every\n // time the user tabs to their terminal to run gpg and back.\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity\n });\n var { subscribeNonceReset } = gpgConfig;\n var refetchNonce = nonce.refetch;\n useEffect(function() {\n if (!subscribeNonceReset) return;\n return subscribeNonceReset(function() {\n void refetchNonce();\n });\n }, [\n subscribeNonceReset,\n refetchNonce\n ]);\n var buildMessageRef = useRef(buildMessage);\n buildMessageRef.current = buildMessage;\n var message = useMemo(function() {\n return nonce.data ? buildMessageRef.current({\n nonce: nonce.data\n }) : null;\n }, [\n nonce.data\n ]);\n var command = useMemo(function() {\n return message ? gpgSignCommand(message) : null;\n }, [\n message\n ]);\n var signIn = async function signIn2(pastedBlob) {\n var blob;\n try {\n blob = assertGpgSignature(pastedBlob);\n } catch (error) {\n setStatus(GpgStatusState.ERROR);\n throw error;\n }\n if (!message) {\n setStatus(GpgStatusState.ERROR);\n throw new Error(\"Could not fetch nonce\");\n }\n try {\n setStatus(GpgStatusState.LOADING);\n var result = await gpgConfig.onSign({\n username: b64(blob),\n password: b64(message),\n message\n });\n if (result === false) throw new Error(\"GPG sign-in was rejected\");\n setStatus(GpgStatusState.SUCCESS);\n onSignIn === null || onSignIn === void 0 ? void 0 : onSignIn();\n return true;\n } catch (error) {\n setStatus(GpgStatusState.ERROR);\n throw error;\n }\n };\n return /* @__PURE__ */ _jsx(GpgContext.Provider, {\n value: {\n enabled,\n nonceRefetchInterval,\n buildMessage,\n ...gpgConfig,\n nonce,\n message,\n command,\n status,\n signIn,\n resetStatus\n },\n children\n });\n};\nexport {\n GPG_NONCE_QUERY_KEY,\n GpgProvider\n};\n//# sourceMappingURL=GpgProvider.js.map\n"],"mappings":";;;;;;;;AAMA,IAAI,sBAAsB;AAC1B,IAAI,MAAM,SAAS,KAAK,GAAG;CACzB,OAAO,OAAO,KAAK,SAAS,mBAAmB,CAAC,CAAC,CAAC;AACpD;AACA,IAAI,cAAc,SAAS,aAAa,OAAO;CAC7C,IAAI,EAAE,U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