@orangecheck/auth-client 2.6.0 → 2.7.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 +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +182 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -1
package/dist/index.d.mts
CHANGED
|
@@ -125,6 +125,12 @@ 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;
|
|
128
134
|
|
|
129
135
|
interface WebAuthnCredentialPublic {
|
|
130
136
|
id: string;
|
|
@@ -208,4 +214,4 @@ declare function handleSudoRequired(body: {
|
|
|
208
214
|
returnTo?: string;
|
|
209
215
|
}): boolean;
|
|
210
216
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,12 @@ 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;
|
|
128
134
|
|
|
129
135
|
interface WebAuthnCredentialPublic {
|
|
130
136
|
id: string;
|
|
@@ -208,4 +214,4 @@ declare function handleSudoRequired(body: {
|
|
|
208
214
|
returnTo?: string;
|
|
209
215
|
}): boolean;
|
|
210
216
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -889,7 +889,8 @@ function OcLinkedIdentities({
|
|
|
889
889
|
onDone: afterChange,
|
|
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
894
|
] });
|
|
894
895
|
}
|
|
895
896
|
function IdentityGroup({
|
|
@@ -1374,6 +1375,185 @@ function TransferConfirm({
|
|
|
1374
1375
|
] })
|
|
1375
1376
|
] });
|
|
1376
1377
|
}
|
|
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
|
+
}
|
|
1377
1557
|
function LazyWalletButton(props) {
|
|
1378
1558
|
const [Comp, setComp] = React3__namespace.useState(null);
|
|
1379
1559
|
const [failed, setFailed] = React3__namespace.useState(false);
|
|
@@ -2372,6 +2552,7 @@ exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
|
2372
2552
|
exports.OcAccountChip = OcAccountChip;
|
|
2373
2553
|
exports.OcAccountPill = OcAccountPill;
|
|
2374
2554
|
exports.OcAddressInput = OcAddressInput;
|
|
2555
|
+
exports.OcIdentityBond = OcIdentityBond;
|
|
2375
2556
|
exports.OcLinkedIdentities = OcLinkedIdentities;
|
|
2376
2557
|
exports.OcSessionProvider = OcSessionProvider;
|
|
2377
2558
|
exports.OcSignIn = OcSignIn;
|