@orangecheck/auth-client 2.7.0 → 2.9.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
@@ -125,12 +125,6 @@ interface OcLinkedIdentitiesProps {
125
125
  onChange?: () => void;
126
126
  }
127
127
  declare function OcLinkedIdentities({ authOrigin, className, onChange, }: OcLinkedIdentitiesProps): React.ReactElement;
128
- interface OcIdentityBondProps {
129
- didOc: string;
130
- btc: string;
131
- className?: string;
132
- }
133
- declare function OcIdentityBond({ didOc, btc, className, }: OcIdentityBondProps): React.ReactElement;
134
128
 
135
129
  interface WebAuthnCredentialPublic {
136
130
  id: string;
@@ -214,4 +208,4 @@ declare function handleSudoRequired(body: {
214
208
  returnTo?: string;
215
209
  }): boolean;
216
210
 
217
- export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcIdentityBond, type OcIdentityBondProps, 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -125,12 +125,6 @@ interface OcLinkedIdentitiesProps {
125
125
  onChange?: () => void;
126
126
  }
127
127
  declare function OcLinkedIdentities({ authOrigin, className, onChange, }: OcLinkedIdentitiesProps): React.ReactElement;
128
- interface OcIdentityBondProps {
129
- didOc: string;
130
- btc: string;
131
- className?: string;
132
- }
133
- declare function OcIdentityBond({ didOc, btc, className, }: OcIdentityBondProps): React.ReactElement;
134
128
 
135
129
  interface WebAuthnCredentialPublic {
136
130
  id: string;
@@ -214,4 +208,4 @@ declare function handleSudoRequired(body: {
214
208
  returnTo?: string;
215
209
  }): boolean;
216
210
 
217
- export { DEFAULT_CONFIG, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcIdentityBond, type OcIdentityBondProps, 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 };
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 };
package/dist/index.js CHANGED
@@ -890,7 +890,7 @@ function OcLinkedIdentities({
890
890
  onCancel: () => setShowBtcLink(false)
891
891
  }
892
892
  ),
893
- hasBtc && resp.did_oc && /* @__PURE__ */ jsxRuntime.jsx(OcIdentityBond, { didOc: resp.did_oc, btc: btcRows.find((i) => !!i.value).value })
893
+ hasBtc && /* @__PURE__ */ jsxRuntime.jsx(AttestationLink, {})
894
894
  ] });
895
895
  }
896
896
  function IdentityGroup({
@@ -1069,6 +1069,65 @@ function ConsolidationPanel({ entries }) {
1069
1069
  )) })
1070
1070
  ] });
1071
1071
  }
1072
+ function AttestationLink() {
1073
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: panelStyle(), "data-oc-li-attest": "", children: [
1074
+ /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "\xA7 portable attestation" }),
1075
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: bodyStyle, children: "Make your identity links portable: publish a standard OrangeCheck attestation \u2014 one Bitcoin-wallet signature (BIP-322) binding your address to your handles (Nostr, GitHub, \u2026). It is published to Nostr and verifies with zero trust in OrangeCheck, so it outlives any single service." }),
1076
+ /* @__PURE__ */ jsxRuntime.jsx(
1077
+ "a",
1078
+ {
1079
+ href: "https://attest.ochk.io/create",
1080
+ target: "_blank",
1081
+ rel: "noreferrer",
1082
+ style: { ...primaryChipStyle, textDecoration: "none", display: "inline-block" },
1083
+ "data-oc-li-attest-link": "",
1084
+ children: "open the attestation builder \u2197"
1085
+ }
1086
+ )
1087
+ ] });
1088
+ }
1089
+ function LinkPromptStep({
1090
+ method,
1091
+ didOc,
1092
+ authOrigin,
1093
+ onResolved
1094
+ }) {
1095
+ const [stage, setStage] = React3__namespace.useState("offer");
1096
+ if (stage === "linking") {
1097
+ return method === "btc" ? /* @__PURE__ */ jsxRuntime.jsx(
1098
+ BtcLinkForm,
1099
+ {
1100
+ authOrigin,
1101
+ didOc,
1102
+ onDone: onResolved,
1103
+ onCancel: () => setStage("offer")
1104
+ }
1105
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1106
+ EmailLinkForm,
1107
+ {
1108
+ authOrigin,
1109
+ onDone: onResolved,
1110
+ onCancel: () => setStage("offer")
1111
+ }
1112
+ );
1113
+ }
1114
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: panelStyle("accent"), "data-oc-linkprompt": method, children: [
1115
+ /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { tone: "success", children: "\xA7 signed in" }),
1116
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: bodyStyle, children: method === "btc" ? "You're in. Link a Bitcoin address now \u2014 a second way to sign in, and it unlocks your on-chain footprint. You prove it with one wallet signature, right here \u2014 no separate trip to your account page." : "You're in. Add your email now \u2014 a backup way to sign in if you ever lose your wallet. You prove it with a one-time code, right here \u2014 no separate trip to your account page." }),
1117
+ /* @__PURE__ */ jsxRuntime.jsxs(FormButtons, { children: [
1118
+ /* @__PURE__ */ jsxRuntime.jsx(
1119
+ "button",
1120
+ {
1121
+ type: "button",
1122
+ onClick: () => setStage("linking"),
1123
+ style: primaryBtnStyle(false),
1124
+ children: method === "btc" ? "link a Bitcoin address" : "link an email"
1125
+ }
1126
+ ),
1127
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onResolved, style: ghostBtnStyle(false), children: "skip" })
1128
+ ] })
1129
+ ] });
1130
+ }
1072
1131
  function EmailLinkForm({
1073
1132
  authOrigin,
1074
1133
  onDone,
@@ -1375,185 +1434,6 @@ function TransferConfirm({
1375
1434
  ] })
1376
1435
  ] });
1377
1436
  }
1378
- function OcIdentityBond({
1379
- didOc,
1380
- btc,
1381
- className
1382
- }) {
1383
- const [stage, setStage] = React3__namespace.useState("idle");
1384
- const [message, setMessage] = React3__namespace.useState("");
1385
- const [err, setErr] = React3__namespace.useState(null);
1386
- const [result, setResult] = React3__namespace.useState(null);
1387
- function nip07() {
1388
- if (typeof window === "undefined") return null;
1389
- const w = window;
1390
- return w.nostr ?? null;
1391
- }
1392
- async function begin() {
1393
- setErr(null);
1394
- const nostr = nip07();
1395
- if (!nostr) {
1396
- setErr(
1397
- "no Nostr signer found \xB7 install a NIP-07 extension (Alby, nos2x) to counter-sign the bond"
1398
- );
1399
- return;
1400
- }
1401
- try {
1402
- const sdk = await loadSdk();
1403
- const pubkeyHex = (await nostr.getPublicKey()).toLowerCase();
1404
- const npub = sdk.xOnlyHexToNpub(pubkeyHex);
1405
- const msg = sdk.buildBindingMessage({
1406
- principal: didOc,
1407
- btc,
1408
- nostr: npub,
1409
- nonce: randomNonceHex(),
1410
- issued_at: (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z")
1411
- });
1412
- setMessage(msg);
1413
- setStage("sign-btc");
1414
- } catch (e) {
1415
- setErr(e instanceof Error ? e.message : "could not start the bond ceremony");
1416
- }
1417
- }
1418
- async function afterBtcSign(btcSignature) {
1419
- setErr(null);
1420
- setStage("sign-nostr");
1421
- try {
1422
- const nostr = nip07();
1423
- if (!nostr) throw new Error("Nostr extension went away \xB7 retry");
1424
- const sdk = await loadSdk();
1425
- const pubkeyHex = (await nostr.getPublicKey()).toLowerCase();
1426
- const template = sdk.buildBindingEventTemplate({
1427
- message,
1428
- btcSignature,
1429
- nostrPubkeyHex: pubkeyHex,
1430
- btc
1431
- });
1432
- const signedEvent = await nostr.signEvent(template);
1433
- const envelope = sdk.assembleBindingEnvelope({
1434
- message,
1435
- btcSignature,
1436
- btcScheme: "bip322",
1437
- nostrEvent: signedEvent
1438
- });
1439
- const check = sdk.verifyBinding(envelope);
1440
- if (!check.valid) {
1441
- throw new Error(`assembled bond failed local verification (${check.status})`);
1442
- }
1443
- setStage("publishing");
1444
- const { publishEvent } = await loadNostrCore();
1445
- const results = await publishEvent(signedEvent);
1446
- const ok = results.filter((r) => r.ok).length;
1447
- if (ok === 0) {
1448
- throw new Error("no relay accepted the bond \xB7 check your connection and retry");
1449
- }
1450
- setResult({
1451
- bindingId: check.valid ? check.binding_id : sdk.bindingId(message),
1452
- relays: ok,
1453
- relaysTotal: results.length
1454
- });
1455
- setStage("done");
1456
- } catch (e) {
1457
- setErr(e instanceof Error ? e.message : "bond publish failed");
1458
- setStage("sign-btc");
1459
- }
1460
- }
1461
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: panelStyle("accent"), "data-oc-identity-bond": "", children: [
1462
- /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { children: "\xA7 identity bond \xB7 publish to nostr" }),
1463
- stage === "idle" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1464
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: bodyStyle, children: [
1465
- "Publish a ",
1466
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Binding Attestation" }),
1467
- " \u2014 a Bitcoin-signed, Nostr-signed proof that this address and your Nostr key are one identity. It lives on Nostr, verifies with zero trust in OrangeCheck, and means your identity survives even if OC's database does not. Two signatures: your Bitcoin wallet, then your Nostr extension."
1468
- ] }),
1469
- /* @__PURE__ */ jsxRuntime.jsx(FormButtons, { children: /* @__PURE__ */ jsxRuntime.jsx(
1470
- "button",
1471
- {
1472
- type: "button",
1473
- onClick: () => void begin(),
1474
- style: primaryBtnStyle(false),
1475
- children: "create & publish bond"
1476
- }
1477
- ) })
1478
- ] }),
1479
- stage === "sign-btc" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1480
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: bodyStyle, children: [
1481
- "Step 1 of 2 \u2014 sign the binding message with the Bitcoin wallet that controls ",
1482
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontFamily: MONO, wordBreak: "break-all" }, children: btc }),
1483
- "."
1484
- ] }),
1485
- /* @__PURE__ */ jsxRuntime.jsx(
1486
- LazyWalletButton,
1487
- {
1488
- address: btc,
1489
- message,
1490
- showManual: true,
1491
- layout: "list",
1492
- heading: null,
1493
- onSigned: (sig) => void afterBtcSign(sig),
1494
- onError: (e) => setErr(e?.message ?? "wallet rejected the signature")
1495
- }
1496
- )
1497
- ] }),
1498
- (stage === "sign-nostr" || stage === "publishing") && /* @__PURE__ */ jsxRuntime.jsx("p", { style: bodyStyle, children: stage === "sign-nostr" ? "Step 2 of 2 \u2014 approve the signature in your Nostr extension\u2026" : "Publishing the bond to Nostr\u2026" }),
1499
- stage === "done" && result && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1500
- /* @__PURE__ */ jsxRuntime.jsx(SectionLabel, { tone: "success", children: "\xA7 bond published" }),
1501
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: bodyStyle, children: [
1502
- "Your identity bond is live on ",
1503
- result.relays,
1504
- "/",
1505
- result.relaysTotal,
1506
- " ",
1507
- "relay",
1508
- result.relays === 1 ? "" : "s",
1509
- ". Anyone can now verify the BTC \u21C4 Nostr binding offline."
1510
- ] }),
1511
- /* @__PURE__ */ jsxRuntime.jsxs(
1512
- "div",
1513
- {
1514
- style: {
1515
- fontFamily: MONO,
1516
- fontSize: 11,
1517
- color: V.muted,
1518
- wordBreak: "break-all"
1519
- },
1520
- children: [
1521
- "binding_id: ",
1522
- result.bindingId
1523
- ]
1524
- }
1525
- )
1526
- ] }),
1527
- err && /* @__PURE__ */ jsxRuntime.jsx(ErrorLine, { children: err })
1528
- ] });
1529
- }
1530
- function randomNonceHex() {
1531
- const b = new Uint8Array(16);
1532
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1533
- crypto.getRandomValues(b);
1534
- } else {
1535
- for (let i = 0; i < 16; i++) b[i] = Math.floor(Math.random() * 256);
1536
- }
1537
- let out = "";
1538
- for (const x of b) out += x.toString(16).padStart(2, "0");
1539
- return out;
1540
- }
1541
- async function loadSdk() {
1542
- try {
1543
- return await import('@orangecheck/sdk');
1544
- } catch {
1545
- throw new Error("@orangecheck/sdk not installed \xB7 add it to your site to publish bonds");
1546
- }
1547
- }
1548
- async function loadNostrCore() {
1549
- try {
1550
- return await import('@orangecheck/nostr-core');
1551
- } catch {
1552
- throw new Error(
1553
- "@orangecheck/nostr-core not installed \xB7 add it to your site to publish bonds"
1554
- );
1555
- }
1556
- }
1557
1437
  function LazyWalletButton(props) {
1558
1438
  const [Comp, setComp] = React3__namespace.useState(null);
1559
1439
  const [failed, setFailed] = React3__namespace.useState(false);
@@ -1756,7 +1636,7 @@ function OcSignIn({
1756
1636
  returnTo,
1757
1637
  onSuccess,
1758
1638
  resolveReturnTo,
1759
- linkPrompt,
1639
+ linkPrompt = true,
1760
1640
  authOrigin = "https://ochk.io",
1761
1641
  initialPath = "wallet",
1762
1642
  paths,
@@ -1781,18 +1661,34 @@ function OcSignIn({
1781
1661
  [resolveReturnTo, safeReturn]
1782
1662
  );
1783
1663
  const handleSuccess = React3__namespace.useCallback(
1784
- async (account, token) => {
1785
- if (onSuccess) {
1786
- onSuccess(account, token);
1664
+ async (account, token, via) => {
1665
+ const proceed = () => {
1666
+ if (onSuccess) onSuccess(account, token);
1667
+ else void navigate(account);
1668
+ };
1669
+ if (!linkPrompt) {
1670
+ proceed();
1787
1671
  return;
1788
1672
  }
1789
- if (linkPrompt) {
1790
- setSignedIn(account);
1791
- return;
1673
+ try {
1674
+ const meRes = await fetch(`${authOrigin}/api/auth/me`, {
1675
+ credentials: "include",
1676
+ headers: { Accept: "application/json" }
1677
+ });
1678
+ const me = meRes.ok ? await meRes.json() : null;
1679
+ const acct = me?.account;
1680
+ const didOc = acct?.did_oc;
1681
+ const complementary = via === "email" ? "btc" : "email";
1682
+ const alreadyLinked = complementary === "btc" ? Boolean(acct?.primary_btc) : Boolean(acct?.has_email);
1683
+ if (didOc && !alreadyLinked) {
1684
+ setSignedIn({ method: complementary, didOc, proceed });
1685
+ return;
1686
+ }
1687
+ } catch {
1792
1688
  }
1793
- await navigate(account);
1689
+ proceed();
1794
1690
  },
1795
- [onSuccess, linkPrompt, navigate]
1691
+ [onSuccess, linkPrompt, navigate, authOrigin]
1796
1692
  );
1797
1693
  if (!walletEnabled && !emailEnabled) {
1798
1694
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1823,8 +1719,10 @@ function OcSignIn({
1823
1719
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsxRuntime.jsx(
1824
1720
  LinkPromptStep,
1825
1721
  {
1722
+ method: signedIn.method,
1723
+ didOc: signedIn.didOc,
1826
1724
  authOrigin,
1827
- onContinue: () => void navigate(signedIn)
1725
+ onResolved: signedIn.proceed
1828
1726
  }
1829
1727
  ) });
1830
1728
  }
@@ -1863,32 +1761,19 @@ function OcSignIn({
1863
1761
  {
1864
1762
  authOrigin,
1865
1763
  audience,
1866
- onSuccess: handleSuccess
1764
+ onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
1867
1765
  }
1868
1766
  ),
1869
- showEmail && /* @__PURE__ */ jsxRuntime.jsx(EmailFlow, { authOrigin, onSuccess: handleSuccess })
1767
+ showEmail && /* @__PURE__ */ jsxRuntime.jsx(
1768
+ EmailFlow,
1769
+ {
1770
+ authOrigin,
1771
+ onSuccess: (a, t) => void handleSuccess(a, t, "email")
1772
+ }
1773
+ )
1870
1774
  ] })
1871
1775
  ] });
1872
1776
  }
1873
- function LinkPromptStep({
1874
- authOrigin,
1875
- onContinue
1876
- }) {
1877
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-linkprompt": "", children: [
1878
- /* @__PURE__ */ jsxRuntime.jsx(FlowHeader, { label: "\xA7 signed in \xB7 add a backup", children: "You're in. Linking a second way to sign in \u2014 your email or your Bitcoin wallet \u2014 is also your recovery path: lose one, the other still gets you in. Optional; skip with continue." }),
1879
- /* @__PURE__ */ jsxRuntime.jsx(OcLinkedIdentities, { authOrigin }),
1880
- /* @__PURE__ */ jsxRuntime.jsx(
1881
- "button",
1882
- {
1883
- type: "button",
1884
- onClick: onContinue,
1885
- style: submitStyle(false),
1886
- "data-oc-signin-continue": "",
1887
- children: "continue \u2192"
1888
- }
1889
- )
1890
- ] });
1891
- }
1892
1777
  function SigninTab({
1893
1778
  active,
1894
1779
  onClick,
@@ -2552,7 +2437,6 @@ exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
2552
2437
  exports.OcAccountChip = OcAccountChip;
2553
2438
  exports.OcAccountPill = OcAccountPill;
2554
2439
  exports.OcAddressInput = OcAddressInput;
2555
- exports.OcIdentityBond = OcIdentityBond;
2556
2440
  exports.OcLinkedIdentities = OcLinkedIdentities;
2557
2441
  exports.OcSessionProvider = OcSessionProvider;
2558
2442
  exports.OcSignIn = OcSignIn;