@orangecheck/auth-client 2.12.0 → 2.13.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,
@@ -2477,6 +2519,7 @@ function handleSudoRequired(body, args = {}) {
2477
2519
  }
2478
2520
 
2479
2521
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
2522
+ exports.DISPLAY_IDENTITY_KINDS = DISPLAY_IDENTITY_KINDS;
2480
2523
  exports.OcAccountChip = OcAccountChip;
2481
2524
  exports.OcAccountPill = OcAccountPill;
2482
2525
  exports.OcAddressInput = OcAddressInput;
@@ -2485,6 +2528,7 @@ exports.OcSessionProvider = OcSessionProvider;
2485
2528
  exports.OcSignIn = OcSignIn;
2486
2529
  exports.OcSignInButton = OcSignInButton;
2487
2530
  exports.buildSignInUrl = buildSignInUrl;
2531
+ exports.fetchOcLinkedIdentities = fetchOcLinkedIdentities;
2488
2532
  exports.handleSudoRequired = handleSudoRequired;
2489
2533
  exports.redirectToSudo = redirectToSudo;
2490
2534
  exports.useOcAddressSuggestion = useOcAddressSuggestion;