@orangecheck/auth-client 2.12.0 → 2.14.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/index.d.mts CHANGED
@@ -1,5 +1,11 @@
1
1
  import * as React from 'react';
2
2
 
3
+ declare const DISPLAY_IDENTITY_KINDS: readonly ["did", "btc", "email", "nostr"];
4
+ type DisplayIdentityKind = (typeof DISPLAY_IDENTITY_KINDS)[number];
5
+ interface DisplayIdentity {
6
+ kind: DisplayIdentityKind;
7
+ value: string;
8
+ }
3
9
  interface OcAccount {
4
10
  accountId: string;
5
11
  didOc: string;
@@ -10,6 +16,7 @@ interface OcAccount {
10
16
  homeFederation?: string | null;
11
17
  signingMethod?: 'fedimint_threshold' | 'fedimint_client' | 'bip322' | null;
12
18
  isOwner?: boolean;
19
+ displayIdentity: DisplayIdentity;
13
20
  }
14
21
  type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';
15
22
  interface OcSessionState {
@@ -18,6 +25,7 @@ interface OcSessionState {
18
25
  error: Error | null;
19
26
  refresh: () => Promise<void>;
20
27
  signOut: () => Promise<void>;
28
+ setDisplayIdentity: (kind: DisplayIdentityKind) => Promise<void>;
21
29
  signInUrl: string;
22
30
  }
23
31
  interface OcAuthConfig {
@@ -119,6 +127,9 @@ interface OcLinkedIdentity {
119
127
  verification_method: 'email-otp' | 'bip322' | null;
120
128
  is_primary: boolean;
121
129
  }
130
+ declare function fetchOcLinkedIdentities(opts?: {
131
+ authOrigin?: string;
132
+ }): Promise<OcLinkedIdentity[]>;
122
133
  interface OcLinkedIdentitiesProps {
123
134
  authOrigin?: string;
124
135
  className?: string;
@@ -208,4 +219,4 @@ declare function handleSudoRequired(body: {
208
219
  returnTo?: string;
209
220
  }): boolean;
210
221
 
211
- export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type RedirectToSudoArgs, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
222
+ export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type RedirectToSudoArgs, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildSignInUrl, fetchOcLinkedIdentities, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  import * as React from 'react';
2
2
 
3
+ declare const DISPLAY_IDENTITY_KINDS: readonly ["did", "btc", "email", "nostr"];
4
+ type DisplayIdentityKind = (typeof DISPLAY_IDENTITY_KINDS)[number];
5
+ interface DisplayIdentity {
6
+ kind: DisplayIdentityKind;
7
+ value: string;
8
+ }
3
9
  interface OcAccount {
4
10
  accountId: string;
5
11
  didOc: string;
@@ -10,6 +16,7 @@ interface OcAccount {
10
16
  homeFederation?: string | null;
11
17
  signingMethod?: 'fedimint_threshold' | 'fedimint_client' | 'bip322' | null;
12
18
  isOwner?: boolean;
19
+ displayIdentity: DisplayIdentity;
13
20
  }
14
21
  type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';
15
22
  interface OcSessionState {
@@ -18,6 +25,7 @@ interface OcSessionState {
18
25
  error: Error | null;
19
26
  refresh: () => Promise<void>;
20
27
  signOut: () => Promise<void>;
28
+ setDisplayIdentity: (kind: DisplayIdentityKind) => Promise<void>;
21
29
  signInUrl: string;
22
30
  }
23
31
  interface OcAuthConfig {
@@ -119,6 +127,9 @@ interface OcLinkedIdentity {
119
127
  verification_method: 'email-otp' | 'bip322' | null;
120
128
  is_primary: boolean;
121
129
  }
130
+ declare function fetchOcLinkedIdentities(opts?: {
131
+ authOrigin?: string;
132
+ }): Promise<OcLinkedIdentity[]>;
122
133
  interface OcLinkedIdentitiesProps {
123
134
  authOrigin?: string;
124
135
  className?: string;
@@ -208,4 +219,4 @@ declare function handleSudoRequired(body: {
208
219
  returnTo?: string;
209
220
  }): boolean;
210
221
 
211
- export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type RedirectToSudoArgs, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
222
+ export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type RedirectToSudoArgs, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, buildSignInUrl, fetchOcLinkedIdentities, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ var React3__namespace = /*#__PURE__*/_interopNamespace(React3);
27
27
  // src/provider.tsx
28
28
 
29
29
  // src/types.ts
30
+ var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
30
31
  var DEFAULT_CONFIG = {
31
32
  authOrigin: "https://ochk.io",
32
33
  signInPath: "/signin",
@@ -44,6 +45,13 @@ function buildSignInUrl(cfg, returnTo) {
44
45
  return u.toString();
45
46
  }
46
47
  var SessionContext = React3__namespace.createContext(null);
48
+ function normalizeDisplayIdentity(raw, didOc) {
49
+ const di = raw.display_identity ?? raw.displayIdentity;
50
+ if (di && typeof di === "object" && typeof di.value === "string" && di.value.length > 0 && typeof di.kind === "string" && DISPLAY_IDENTITY_KINDS.includes(di.kind)) {
51
+ return { kind: di.kind, value: di.value };
52
+ }
53
+ return { kind: "did", value: didOc };
54
+ }
47
55
  function normalizeAccount(raw) {
48
56
  if (!raw) return null;
49
57
  const didOc = raw.did_oc ?? raw.didOc;
@@ -58,7 +66,8 @@ function normalizeAccount(raw) {
58
66
  nostrNpub: raw.nostr_npub ?? raw.nostrNpub ?? null,
59
67
  homeFederation: raw.home_federation_slug ?? raw.homeFederation ?? null,
60
68
  signingMethod: raw.signing_method ?? raw.signingMethod ?? null,
61
- isOwner: Boolean(raw.is_owner ?? raw.isOwner ?? false)
69
+ isOwner: Boolean(raw.is_owner ?? raw.isOwner ?? false),
70
+ displayIdentity: normalizeDisplayIdentity(raw, didOc)
62
71
  };
63
72
  }
64
73
  function OcSessionProvider({
@@ -119,6 +128,28 @@ function OcSessionProvider({
119
128
  setAccount(null);
120
129
  setStatus("anonymous");
121
130
  }, [cfg.authOrigin, cfg.logoutPath]);
131
+ const setDisplayIdentity = React3__namespace.useCallback(
132
+ async (kind) => {
133
+ if (typeof window === "undefined") return;
134
+ const res = await fetch(`${cfg.authOrigin}/api/auth/account`, {
135
+ method: "PATCH",
136
+ credentials: "include",
137
+ headers: { "Content-Type": "application/json" },
138
+ body: JSON.stringify({ display_identity: kind })
139
+ });
140
+ if (!res.ok) {
141
+ let reason = `http_${res.status}`;
142
+ try {
143
+ const body = await res.json();
144
+ if (body.reason) reason = body.reason;
145
+ } catch {
146
+ }
147
+ throw new Error(`[@orangecheck/auth-client] setDisplayIdentity failed: ${reason}`);
148
+ }
149
+ await refresh();
150
+ },
151
+ [cfg.authOrigin, refresh]
152
+ );
122
153
  const value = React3__namespace.useMemo(() => {
123
154
  const returnTo = defaultReturnTo ?? (typeof window !== "undefined" ? window.location.href : void 0);
124
155
  return {
@@ -127,9 +158,10 @@ function OcSessionProvider({
127
158
  error,
128
159
  refresh,
129
160
  signOut,
161
+ setDisplayIdentity,
130
162
  signInUrl: buildSignInUrl(cfg, returnTo)
131
163
  };
132
- }, [status, account, error, refresh, signOut, cfg, defaultReturnTo]);
164
+ }, [status, account, error, refresh, signOut, setDisplayIdentity, cfg, defaultReturnTo]);
133
165
  return /* @__PURE__ */ jsxRuntime.jsx(SessionContext.Provider, { value, children });
134
166
  }
135
167
  function useOcSession() {
@@ -777,6 +809,16 @@ var OcAddressInput = React3__namespace.forwardRef(
777
809
  }
778
810
  );
779
811
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
812
+ async function fetchOcLinkedIdentities(opts) {
813
+ const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
814
+ const r = await fetch(`${authOrigin}/api/auth/identities`, {
815
+ credentials: "include"
816
+ });
817
+ if (r.status === 401) return [];
818
+ if (!r.ok) throw new Error(`identities fetch failed: http_${r.status}`);
819
+ const body = await r.json();
820
+ return body.linked ?? [];
821
+ }
780
822
  function OcLinkedIdentities({
781
823
  authOrigin = DEFAULT_AUTH_ORIGIN,
782
824
  className,
@@ -1657,6 +1699,13 @@ function OcSignIn({
1657
1699
  const [path, setPath] = React3__namespace.useState(initialPath);
1658
1700
  const [signedIn, setSignedIn] = React3__namespace.useState(null);
1659
1701
  const [linkAlso, setLinkAlso] = React3__namespace.useState(false);
1702
+ const [oauthError, setOauthError] = React3__namespace.useState(false);
1703
+ React3__namespace.useEffect(() => {
1704
+ if (typeof window === "undefined") return;
1705
+ if (new URLSearchParams(window.location.search).has("oauth_error")) {
1706
+ setOauthError(true);
1707
+ }
1708
+ }, []);
1660
1709
  const navigate = React3__namespace.useCallback(
1661
1710
  async (account) => {
1662
1711
  if (resolveReturnTo) {
@@ -1742,6 +1791,22 @@ function OcSignIn({
1742
1791
  const bothEnabled = walletEnabled && emailEnabled;
1743
1792
  const activeMethod = !emailEnabled ? "wallet" : !walletEnabled ? "email" : path;
1744
1793
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, "data-oc-signin": "", children: [
1794
+ oauthError && /* @__PURE__ */ jsxRuntime.jsx(
1795
+ "div",
1796
+ {
1797
+ "data-oc-signin-oauth-error": "",
1798
+ style: {
1799
+ marginBottom: 14,
1800
+ padding: "0.6rem 0.75rem",
1801
+ border: "1px solid var(--destructive, #ef4444)",
1802
+ borderRadius: 6,
1803
+ color: "var(--destructive, #ef4444)",
1804
+ fontFamily: "ui-monospace, SFMono-Regular, monospace",
1805
+ fontSize: 11
1806
+ },
1807
+ children: "That sign-in didn't complete. Please try again."
1808
+ }
1809
+ ),
1745
1810
  bothEnabled && /* @__PURE__ */ jsxRuntime.jsxs(
1746
1811
  "div",
1747
1812
  {
@@ -1784,6 +1849,7 @@ function OcSignIn({
1784
1849
  }
1785
1850
  )
1786
1851
  ] }),
1852
+ /* @__PURE__ */ jsxRuntime.jsx(ProviderSignIn, { authOrigin, returnTo: safeReturn }),
1787
1853
  linkPrompt && /* @__PURE__ */ jsxRuntime.jsxs("label", { "data-oc-signin-linkalso": "", style: linkAlsoStyle, children: [
1788
1854
  /* @__PURE__ */ jsxRuntime.jsx(
1789
1855
  "input",
@@ -1834,6 +1900,63 @@ function SigninTab({
1834
1900
  }
1835
1901
  );
1836
1902
  }
1903
+ var OAUTH_PROVIDERS = [
1904
+ { id: "google", label: "Continue with Google" }
1905
+ ];
1906
+ function ProviderSignIn({
1907
+ authOrigin,
1908
+ returnTo
1909
+ }) {
1910
+ const line = { flex: 1, height: 1, background: "var(--border, #27272a)" };
1911
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-providers": "", style: { marginTop: 20 }, children: [
1912
+ /* @__PURE__ */ jsxRuntime.jsxs(
1913
+ "div",
1914
+ {
1915
+ style: {
1916
+ display: "flex",
1917
+ alignItems: "center",
1918
+ gap: 10,
1919
+ margin: "4px 0 12px",
1920
+ color: "var(--muted-foreground, #a1a1aa)",
1921
+ fontFamily: "ui-monospace, SFMono-Regular, monospace",
1922
+ fontSize: 10,
1923
+ letterSpacing: "0.16em",
1924
+ textTransform: "uppercase"
1925
+ },
1926
+ children: [
1927
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: line }),
1928
+ "or",
1929
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: line })
1930
+ ]
1931
+ }
1932
+ ),
1933
+ OAUTH_PROVIDERS.map((p) => /* @__PURE__ */ jsxRuntime.jsx(
1934
+ "a",
1935
+ {
1936
+ href: `${authOrigin}/api/auth/${p.id}/start?return_to=${encodeURIComponent(
1937
+ returnTo
1938
+ )}`,
1939
+ "data-oc-signin-provider": p.id,
1940
+ style: {
1941
+ display: "block",
1942
+ boxSizing: "border-box",
1943
+ width: "100%",
1944
+ padding: "0.6rem 0.875rem",
1945
+ textAlign: "center",
1946
+ border: "1px solid var(--border, #27272a)",
1947
+ borderRadius: 6,
1948
+ background: "transparent",
1949
+ color: "var(--muted-foreground, #a1a1aa)",
1950
+ fontFamily: "ui-monospace, SFMono-Regular, monospace",
1951
+ fontSize: 12,
1952
+ textDecoration: "none"
1953
+ },
1954
+ children: p.label
1955
+ },
1956
+ p.id
1957
+ ))
1958
+ ] });
1959
+ }
1837
1960
  function WalletFlow({ authOrigin, audience, onSuccess }) {
1838
1961
  const [address, setAddress] = React3__namespace.useState("");
1839
1962
  const [error, setError] = React3__namespace.useState(null);
@@ -2477,6 +2600,7 @@ function handleSudoRequired(body, args = {}) {
2477
2600
  }
2478
2601
 
2479
2602
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
2603
+ exports.DISPLAY_IDENTITY_KINDS = DISPLAY_IDENTITY_KINDS;
2480
2604
  exports.OcAccountChip = OcAccountChip;
2481
2605
  exports.OcAccountPill = OcAccountPill;
2482
2606
  exports.OcAddressInput = OcAddressInput;
@@ -2485,6 +2609,7 @@ exports.OcSessionProvider = OcSessionProvider;
2485
2609
  exports.OcSignIn = OcSignIn;
2486
2610
  exports.OcSignInButton = OcSignInButton;
2487
2611
  exports.buildSignInUrl = buildSignInUrl;
2612
+ exports.fetchOcLinkedIdentities = fetchOcLinkedIdentities;
2488
2613
  exports.handleSudoRequired = handleSudoRequired;
2489
2614
  exports.redirectToSudo = redirectToSudo;
2490
2615
  exports.useOcAddressSuggestion = useOcAddressSuggestion;