@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.mjs
CHANGED
|
@@ -867,7 +867,8 @@ function OcLinkedIdentities({
|
|
|
867
867
|
onDone: afterChange,
|
|
868
868
|
onCancel: () => setShowBtcLink(false)
|
|
869
869
|
}
|
|
870
|
-
)
|
|
870
|
+
),
|
|
871
|
+
hasBtc && resp.did_oc && /* @__PURE__ */ jsx(OcIdentityBond, { didOc: resp.did_oc, btc: btcRows.find((i) => !!i.value).value })
|
|
871
872
|
] });
|
|
872
873
|
}
|
|
873
874
|
function IdentityGroup({
|
|
@@ -1352,6 +1353,185 @@ function TransferConfirm({
|
|
|
1352
1353
|
] })
|
|
1353
1354
|
] });
|
|
1354
1355
|
}
|
|
1356
|
+
function OcIdentityBond({
|
|
1357
|
+
didOc,
|
|
1358
|
+
btc,
|
|
1359
|
+
className
|
|
1360
|
+
}) {
|
|
1361
|
+
const [stage, setStage] = React3.useState("idle");
|
|
1362
|
+
const [message, setMessage] = React3.useState("");
|
|
1363
|
+
const [err, setErr] = React3.useState(null);
|
|
1364
|
+
const [result, setResult] = React3.useState(null);
|
|
1365
|
+
function nip07() {
|
|
1366
|
+
if (typeof window === "undefined") return null;
|
|
1367
|
+
const w = window;
|
|
1368
|
+
return w.nostr ?? null;
|
|
1369
|
+
}
|
|
1370
|
+
async function begin() {
|
|
1371
|
+
setErr(null);
|
|
1372
|
+
const nostr = nip07();
|
|
1373
|
+
if (!nostr) {
|
|
1374
|
+
setErr(
|
|
1375
|
+
"no Nostr signer found \xB7 install a NIP-07 extension (Alby, nos2x) to counter-sign the bond"
|
|
1376
|
+
);
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
try {
|
|
1380
|
+
const sdk = await loadSdk();
|
|
1381
|
+
const pubkeyHex = (await nostr.getPublicKey()).toLowerCase();
|
|
1382
|
+
const npub = sdk.xOnlyHexToNpub(pubkeyHex);
|
|
1383
|
+
const msg = sdk.buildBindingMessage({
|
|
1384
|
+
principal: didOc,
|
|
1385
|
+
btc,
|
|
1386
|
+
nostr: npub,
|
|
1387
|
+
nonce: randomNonceHex(),
|
|
1388
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
1389
|
+
});
|
|
1390
|
+
setMessage(msg);
|
|
1391
|
+
setStage("sign-btc");
|
|
1392
|
+
} catch (e) {
|
|
1393
|
+
setErr(e instanceof Error ? e.message : "could not start the bond ceremony");
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
async function afterBtcSign(btcSignature) {
|
|
1397
|
+
setErr(null);
|
|
1398
|
+
setStage("sign-nostr");
|
|
1399
|
+
try {
|
|
1400
|
+
const nostr = nip07();
|
|
1401
|
+
if (!nostr) throw new Error("Nostr extension went away \xB7 retry");
|
|
1402
|
+
const sdk = await loadSdk();
|
|
1403
|
+
const pubkeyHex = (await nostr.getPublicKey()).toLowerCase();
|
|
1404
|
+
const template = sdk.buildBindingEventTemplate({
|
|
1405
|
+
message,
|
|
1406
|
+
btcSignature,
|
|
1407
|
+
nostrPubkeyHex: pubkeyHex,
|
|
1408
|
+
btc
|
|
1409
|
+
});
|
|
1410
|
+
const signedEvent = await nostr.signEvent(template);
|
|
1411
|
+
const envelope = sdk.assembleBindingEnvelope({
|
|
1412
|
+
message,
|
|
1413
|
+
btcSignature,
|
|
1414
|
+
btcScheme: "bip322",
|
|
1415
|
+
nostrEvent: signedEvent
|
|
1416
|
+
});
|
|
1417
|
+
const check = sdk.verifyBinding(envelope);
|
|
1418
|
+
if (!check.valid) {
|
|
1419
|
+
throw new Error(`assembled bond failed local verification (${check.status})`);
|
|
1420
|
+
}
|
|
1421
|
+
setStage("publishing");
|
|
1422
|
+
const { publishEvent } = await loadNostrCore();
|
|
1423
|
+
const results = await publishEvent(signedEvent);
|
|
1424
|
+
const ok = results.filter((r) => r.ok).length;
|
|
1425
|
+
if (ok === 0) {
|
|
1426
|
+
throw new Error("no relay accepted the bond \xB7 check your connection and retry");
|
|
1427
|
+
}
|
|
1428
|
+
setResult({
|
|
1429
|
+
bindingId: check.valid ? check.binding_id : sdk.bindingId(message),
|
|
1430
|
+
relays: ok,
|
|
1431
|
+
relaysTotal: results.length
|
|
1432
|
+
});
|
|
1433
|
+
setStage("done");
|
|
1434
|
+
} catch (e) {
|
|
1435
|
+
setErr(e instanceof Error ? e.message : "bond publish failed");
|
|
1436
|
+
setStage("sign-btc");
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
return /* @__PURE__ */ jsxs("div", { className, style: panelStyle("accent"), "data-oc-identity-bond": "", children: [
|
|
1440
|
+
/* @__PURE__ */ jsx(SectionLabel, { children: "\xA7 identity bond \xB7 publish to nostr" }),
|
|
1441
|
+
stage === "idle" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1442
|
+
/* @__PURE__ */ jsxs("p", { style: bodyStyle, children: [
|
|
1443
|
+
"Publish a ",
|
|
1444
|
+
/* @__PURE__ */ jsx("strong", { children: "Binding Attestation" }),
|
|
1445
|
+
" \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."
|
|
1446
|
+
] }),
|
|
1447
|
+
/* @__PURE__ */ jsx(FormButtons, { children: /* @__PURE__ */ jsx(
|
|
1448
|
+
"button",
|
|
1449
|
+
{
|
|
1450
|
+
type: "button",
|
|
1451
|
+
onClick: () => void begin(),
|
|
1452
|
+
style: primaryBtnStyle(false),
|
|
1453
|
+
children: "create & publish bond"
|
|
1454
|
+
}
|
|
1455
|
+
) })
|
|
1456
|
+
] }),
|
|
1457
|
+
stage === "sign-btc" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1458
|
+
/* @__PURE__ */ jsxs("p", { style: bodyStyle, children: [
|
|
1459
|
+
"Step 1 of 2 \u2014 sign the binding message with the Bitcoin wallet that controls ",
|
|
1460
|
+
/* @__PURE__ */ jsx("span", { style: { fontFamily: MONO, wordBreak: "break-all" }, children: btc }),
|
|
1461
|
+
"."
|
|
1462
|
+
] }),
|
|
1463
|
+
/* @__PURE__ */ jsx(
|
|
1464
|
+
LazyWalletButton,
|
|
1465
|
+
{
|
|
1466
|
+
address: btc,
|
|
1467
|
+
message,
|
|
1468
|
+
showManual: true,
|
|
1469
|
+
layout: "list",
|
|
1470
|
+
heading: null,
|
|
1471
|
+
onSigned: (sig) => void afterBtcSign(sig),
|
|
1472
|
+
onError: (e) => setErr(e?.message ?? "wallet rejected the signature")
|
|
1473
|
+
}
|
|
1474
|
+
)
|
|
1475
|
+
] }),
|
|
1476
|
+
(stage === "sign-nostr" || stage === "publishing") && /* @__PURE__ */ 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" }),
|
|
1477
|
+
stage === "done" && result && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1478
|
+
/* @__PURE__ */ jsx(SectionLabel, { tone: "success", children: "\xA7 bond published" }),
|
|
1479
|
+
/* @__PURE__ */ jsxs("p", { style: bodyStyle, children: [
|
|
1480
|
+
"Your identity bond is live on ",
|
|
1481
|
+
result.relays,
|
|
1482
|
+
"/",
|
|
1483
|
+
result.relaysTotal,
|
|
1484
|
+
" ",
|
|
1485
|
+
"relay",
|
|
1486
|
+
result.relays === 1 ? "" : "s",
|
|
1487
|
+
". Anyone can now verify the BTC \u21C4 Nostr binding offline."
|
|
1488
|
+
] }),
|
|
1489
|
+
/* @__PURE__ */ jsxs(
|
|
1490
|
+
"div",
|
|
1491
|
+
{
|
|
1492
|
+
style: {
|
|
1493
|
+
fontFamily: MONO,
|
|
1494
|
+
fontSize: 11,
|
|
1495
|
+
color: V.muted,
|
|
1496
|
+
wordBreak: "break-all"
|
|
1497
|
+
},
|
|
1498
|
+
children: [
|
|
1499
|
+
"binding_id: ",
|
|
1500
|
+
result.bindingId
|
|
1501
|
+
]
|
|
1502
|
+
}
|
|
1503
|
+
)
|
|
1504
|
+
] }),
|
|
1505
|
+
err && /* @__PURE__ */ jsx(ErrorLine, { children: err })
|
|
1506
|
+
] });
|
|
1507
|
+
}
|
|
1508
|
+
function randomNonceHex() {
|
|
1509
|
+
const b = new Uint8Array(16);
|
|
1510
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
1511
|
+
crypto.getRandomValues(b);
|
|
1512
|
+
} else {
|
|
1513
|
+
for (let i = 0; i < 16; i++) b[i] = Math.floor(Math.random() * 256);
|
|
1514
|
+
}
|
|
1515
|
+
let out = "";
|
|
1516
|
+
for (const x of b) out += x.toString(16).padStart(2, "0");
|
|
1517
|
+
return out;
|
|
1518
|
+
}
|
|
1519
|
+
async function loadSdk() {
|
|
1520
|
+
try {
|
|
1521
|
+
return await import('@orangecheck/sdk');
|
|
1522
|
+
} catch {
|
|
1523
|
+
throw new Error("@orangecheck/sdk not installed \xB7 add it to your site to publish bonds");
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
async function loadNostrCore() {
|
|
1527
|
+
try {
|
|
1528
|
+
return await import('@orangecheck/nostr-core');
|
|
1529
|
+
} catch {
|
|
1530
|
+
throw new Error(
|
|
1531
|
+
"@orangecheck/nostr-core not installed \xB7 add it to your site to publish bonds"
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1355
1535
|
function LazyWalletButton(props) {
|
|
1356
1536
|
const [Comp, setComp] = React3.useState(null);
|
|
1357
1537
|
const [failed, setFailed] = React3.useState(false);
|
|
@@ -2346,6 +2526,6 @@ function handleSudoRequired(body, args = {}) {
|
|
|
2346
2526
|
return false;
|
|
2347
2527
|
}
|
|
2348
2528
|
|
|
2349
|
-
export { DEFAULT_CONFIG, OcAccountChip, OcAccountPill, OcAddressInput, OcLinkedIdentities, OcSessionProvider, OcSignIn, OcSignInButton, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
|
|
2529
|
+
export { DEFAULT_CONFIG, OcAccountChip, OcAccountPill, OcAddressInput, OcIdentityBond, OcLinkedIdentities, OcSessionProvider, OcSignIn, OcSignInButton, buildSignInUrl, handleSudoRequired, redirectToSudo, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister };
|
|
2350
2530
|
//# sourceMappingURL=index.mjs.map
|
|
2351
2531
|
//# sourceMappingURL=index.mjs.map
|