@ghostlytools/cli 1.8.1 → 1.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.
Files changed (78) hide show
  1. package/README.md +8 -5
  2. package/SKILL.md +4 -3
  3. package/dist/assets/{api-BpQC8dAw.js → api-DFCgr6RH.js} +40 -16
  4. package/dist/assets/api-DFCgr6RH.js.map +1 -0
  5. package/dist/assets/{api-CttDF-S5.js → api-raWw9j_m.js} +2 -2
  6. package/dist/assets/{apiKit-CSMeHKgo.js → apiKit-CCavJJcl.js} +2 -2
  7. package/dist/assets/{apiKit-CSMeHKgo.js.map → apiKit-CCavJJcl.js.map} +1 -1
  8. package/dist/assets/{apps-DzFMdVt6.js → apps-B7o2BPj6.js} +1 -1
  9. package/dist/assets/{apps-DqTyZ40T.js → apps-DmxEG147.js} +2 -2
  10. package/dist/assets/{apps-DqTyZ40T.js.map → apps-DmxEG147.js.map} +1 -1
  11. package/dist/assets/{arkade-Cu3TbPxC.js → arkade-DtYR9H0c.js} +2 -2
  12. package/dist/assets/{arkade-Cu3TbPxC.js.map → arkade-DtYR9H0c.js.map} +1 -1
  13. package/dist/assets/{backup-CLZOORFC.js → backup-BserdrNk.js} +1 -1
  14. package/dist/assets/{backup-CyTZhu28.js → backup-YIB2XIES.js} +4 -4
  15. package/dist/assets/{backup-CyTZhu28.js.map → backup-YIB2XIES.js.map} +1 -1
  16. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
  17. package/dist/assets/buttons-CuRfKnPI.js +1331 -0
  18. package/dist/assets/buttons-CuRfKnPI.js.map +1 -0
  19. package/dist/assets/buttons-De3LPdSG.js +2 -0
  20. package/dist/assets/{envelope-CGfUsR1m.js → envelope-Dt75vrmY.js} +2 -2
  21. package/dist/assets/{envelope-CGfUsR1m.js.map → envelope-Dt75vrmY.js.map} +1 -1
  22. package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -1
  23. package/dist/assets/{fixedHosts-BiukTsd9.js → fixedHosts-B598JzbC.js} +4 -4
  24. package/dist/assets/{fixedHosts-BiukTsd9.js.map → fixedHosts-B598JzbC.js.map} +1 -1
  25. package/dist/assets/{groupFiles-CeF9nPv9.js → groupFiles-FXel6zIc.js} +10 -599
  26. package/dist/assets/groupFiles-FXel6zIc.js.map +1 -0
  27. package/dist/assets/{host-CKAehWP6.js → host-DIBeK_c_.js} +73 -18
  28. package/dist/assets/host-DIBeK_c_.js.map +1 -0
  29. package/dist/assets/{hyperdhtRelay-B8Pdykhg.js → hyperdhtRelay-D185dETu.js} +2 -2
  30. package/dist/assets/{hyperdhtRelay-B8Pdykhg.js.map → hyperdhtRelay-D185dETu.js.map} +1 -1
  31. package/dist/assets/{irohWeb-D6tAPHZa.js → irohWeb-BSv_BWyG.js} +16 -3
  32. package/dist/assets/{irohWeb-D6tAPHZa.js.map → irohWeb-BSv_BWyG.js.map} +1 -1
  33. package/dist/assets/{main-BDY-pfpz.js → main-BbhfMTt8.js} +50 -22
  34. package/dist/assets/main-BbhfMTt8.js.map +1 -0
  35. package/dist/assets/{mainline-3ueXpFQL.js → mainline-9Vc3c3SA.js} +2 -2
  36. package/dist/assets/{mainline-3ueXpFQL.js.map → mainline-9Vc3c3SA.js.map} +1 -1
  37. package/dist/assets/{networkReason-DhJYOomu.js → networkReason-BncJ9KSM.js} +2 -2
  38. package/dist/assets/{networkReason-DhJYOomu.js.map → networkReason-BncJ9KSM.js.map} +1 -1
  39. package/dist/assets/{nwc-B1Quqda-.js → nwc-QX3Yt1Sb.js} +3 -3
  40. package/dist/assets/{nwc-B1Quqda-.js.map → nwc-QX3Yt1Sb.js.map} +1 -1
  41. package/dist/assets/{nwcProvider-DUB6xO-b.js → nwcProvider-CzX3xH47.js} +2 -2
  42. package/dist/assets/{nwcProvider-DUB6xO-b.js.map → nwcProvider-CzX3xH47.js.map} +1 -1
  43. package/dist/assets/{ownDid-BfqHJdA6.js → ownDid-D8z5gwGI.js} +2 -2
  44. package/dist/assets/{ownDid-BfqHJdA6.js.map → ownDid-D8z5gwGI.js.map} +1 -1
  45. package/dist/assets/{registry-DwlTNQjr.js → registry-B2Dtnibo.js} +5 -5
  46. package/dist/assets/{registry-DwlTNQjr.js.map → registry-B2Dtnibo.js.map} +1 -1
  47. package/dist/assets/{registry-CZTmtSws.js → registry-PTtBMaYZ.js} +1 -1
  48. package/dist/assets/{resolve-BVwhiYjj.js → resolve-ZxVzwFNA.js} +2 -2
  49. package/dist/assets/{resolve-BVwhiYjj.js.map → resolve-ZxVzwFNA.js.map} +1 -1
  50. package/dist/assets/{server-Br3XPwFG.js → server-Dw1o8z1o.js} +796 -269
  51. package/dist/assets/server-Dw1o8z1o.js.map +1 -0
  52. package/dist/assets/{src-C4sOH4zH.js → src-BD8RBVEp.js} +1038 -30
  53. package/dist/assets/src-BD8RBVEp.js.map +1 -0
  54. package/dist/assets/{sshForges-CQQomStK.js → sshForges-DWrESWkK.js} +2 -2
  55. package/dist/assets/{sshForges-CQQomStK.js.map → sshForges-DWrESWkK.js.map} +1 -1
  56. package/dist/assets/{translate-C2aNyUkR.js → translate-D1uP0q32.js} +9 -3
  57. package/dist/assets/translate-D1uP0q32.js.map +1 -0
  58. package/dist/assets/{usdt-CMwatDnQ.js → usdt-DhVN8geQ.js} +3 -3
  59. package/dist/assets/{usdt-CMwatDnQ.js.map → usdt-DhVN8geQ.js.map} +1 -1
  60. package/dist/assets/{waitNotice-Ck3el3_Z.js → waitNotice-B8D8WhbE.js} +2 -2
  61. package/dist/assets/waitNotice-B8D8WhbE.js.map +1 -0
  62. package/dist/assets/{words-CqN2KG1r.js → words-DdXPkB3n.js} +3 -2
  63. package/dist/assets/words-DdXPkB3n.js.map +1 -0
  64. package/dist/ghostly.mjs +1 -1
  65. package/examples/call-echo.mjs +7 -5
  66. package/package.json +1 -1
  67. package/dist/assets/api-BpQC8dAw.js.map +0 -1
  68. package/dist/assets/buttons-Bd9fR31r.js +0 -698
  69. package/dist/assets/buttons-Bd9fR31r.js.map +0 -1
  70. package/dist/assets/buttons-c4CJnL6i.js +0 -2
  71. package/dist/assets/groupFiles-CeF9nPv9.js.map +0 -1
  72. package/dist/assets/host-CKAehWP6.js.map +0 -1
  73. package/dist/assets/main-BDY-pfpz.js.map +0 -1
  74. package/dist/assets/server-Br3XPwFG.js.map +0 -1
  75. package/dist/assets/src-C4sOH4zH.js.map +0 -1
  76. package/dist/assets/translate-C2aNyUkR.js.map +0 -1
  77. package/dist/assets/waitNotice-Ck3el3_Z.js.map +0 -1
  78. package/dist/assets/words-CqN2KG1r.js.map +0 -1
@@ -1,16 +1,16 @@
1
1
  import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
2
- import { $i as validExternalKey, $l as turnStatedVerifier, $r as wakeRequest, $s as verifySetUpdate, $t as SEPOLIA_TEST_USDT, A as knockIdentity, Aa as parseLinkPreview, Ac as mergeContactKnocks, Al as deviceEchoFrame, An as fedimintRequestPayload, Ao as ratchetSessionOf, Ar as FILE_LIMITS, As as handoffManifestFrames, Ba as reactionIsNewer, Bc as appDigest, Bl as TURN_SETTLE_MS, Bn as pairedMessageFrame, Bo as formatLocalTarget, Bs as readHandoffDone, C as communityHasFrame, Ca as EDIT_RATE_WINDOW_MS, Cc as REQUEST_LIFETIME_MS, Cl as encodeInviteCode, Co as rosterAdmin, Cr as pickHubs, Cs as handoffCancelFrame, Cu as publicKeyFromZ32, D as decodeGroupEntryLink, Da as dhtEditId, Dc as knockSlotRecords, Dl as DEVICES_CAPABILITY, Dn as decodeBolt11, Do as RATCHET_CAPABILITY, Dr as readLobby, Ds as handoffDigest, Du as sanitizeDisplayText, Ea as RateWindow, Ec as knockSlotOf, Eo as edgeParams, Er as readBeaconHead, Es as handoffDataFrame, Eu as sanitizeAvatar, F as GroupWakeLimiter, Fa as REACTION_LIMITS, Fc as seenEntry, Fi as DHT_TEXT_CAPABILITY, Fl as newDeviceSetSecret, Fn as GhostLink, Fo as PRESENCE_WINDOW, Fs as handoffStreamKey, Fu as utf8Encode, Ga as readReply, Gc as pacer, Gl as firstDeviceSetSecret, Gn as GROUP_FILE_LIMITS, Go as encodeControl, Gr as pinNumberHolds, Gs as readHandoffVerified, Gt as encodeDidDhtDeactivated, H as GroupSession, Ha as validReactionNumber, Hl as turnPutSummary, Hn as engineError, Ho as webLocalFetch, Hr as mayPin, Hs as readHandoffHello, I as groupWakeFrame, Ia as ReactionWindow, Ic as APP_BUNDLE_LIMITS, Ii as capsDescriptors, Il as seedSigner, In as INVITE_TAKEN, Io as RELAY_POLL_INTERVALS, Is as handoffVersions, J as parseCommunityEdit, Jc as sha256Paced, Ji as receivedIdentityStatus, Jl as signTurnPacket, Jr as WakeLimiter, Jt as signDidDhtPacket, K as GROUP_EDIT_TEXT_BYTES, Ka as replySnippet, Kl as nextTurnPosition, Kr as readPin, Ks as sealHandoffPiece, Kt as encodeDidDhtPacket, L as groupWakes, La as nextReactionNumber, Lc as APP_BUNDLE_MAGIC, Li as dialDescriptors, Ll as webCryptoSigner, Ln as LIVENESS_PING_MS, Lo as WATCH_PEER_MS, Lr as TypingSender, Ls as newHandoffId, M as mergeKnocks, Ma as readForwarded, Mc as readKnockSlot, Ml as deviceKeyZ32, Mn as isFederationId, Mr as sentWhole, Ms as handoffPakeFrame, Mu as toBase64Url, N as readKnocks, Na as COMMUNITY_REACTION_FRAME, Nc as readLinkRecord, Nl as deviceLinkPairing, Nn as parseCashuRequestPayload, No as DHT_POLL_INTERVALS, Nr as transferEnded, Ns as handoffReleaseFrame, Nu as toZ32, O as encodeGroupEntryLink, Oc as linkRecords, Ol as ENROLL_CAPABILITY, On as ENDPOINT, Oo as RatchetBox, Or as shouldBeHub, Os as handoffEphemeral, Ou as bytesEqual, Pa as GROUP_REACTION_FRAME, Pc as requestRecords, Pi as CapsExchange, Pl as devicePingFrame, Pn as parseFedimintRequestPayload, Pr as transferStalled, Ps as handoffRetryAfter, Pu as utf8Decode, Qc as appRef, Qi as emptyProofLedger, Ql as turnName, Qn as readGroupFileMeta, Qo as contactRtcConfig, Qr as relayRequest, Qs as signTombstone, Qt as PaymentPreflightError, R as parseGroupWakeFrame, Ra as queueReaction, Rc as APP_ICON_PATH, Rn as PAIRED_FRAME_TOO_LARGE, Ro as presenceSeenAt, Rs as readHandoffAck, S as GROUP_READ_NOTE_COMMUNITY, Sa as EDIT_BUFFER_MS, Sc as ContactRequestError, Sl as decodeInviteCode, So as parseGroupCommit, Sr as newerHead, Ss as handoffBusyFrame, Su as identityFromSeedB64, T as encodeCommunityLink, Ta as REMOVED_TEXT, Tc as knockSlotIdentity, Tl as inviteOwnership, To as verifyCommitSignature, Tr as readBeacon, Ts as handoffContextProof, U as frameBytes, Ua as wireReaction, Ul as TURN_LAST_SEQUENCE, Un as engineText, Uo as LIMITS, Ur as nextPinNumber, Us as readHandoffPake, Ut as didDhtDocument, V as GROUP_READ_NOTE, Va as readReaction, Vc as appViewOf, Vl as classifyTurnRead, Vn as EngineError, Vo as parseLocalTarget, Vr as PIN_LIMITS, Vs as readHandoffHave, Wa as pairedReplyAuthor, Wc as isAppUrl, Wi as emptyIdentityLedger, Wl as TURN_MAX, Wn as parseEngineError, Wo as decodeControl, Wr as pinIsNewer, Ws as readHandoffTurnFrame, Wt as didDhtFromPublicKey, X as groupName, Xc as APP_STATEMENT_LIMITS, Xi as lastSharedWithMe, Xl as turnInstance, Xn as groupFileFallback, Xr as newWakeToken, Xs as setAckFrame, Xt as EVM_TEST_CHAINS, Y as mentionsMember, Yl as signTurnRelease, Yr as deviceWakeRequest, Ys as readSetUpdate, Yt as ETHEREUM_USDT, Zc as appFingerprint, Zi as PeerProofs, Zl as turnKeys, Zr as parseWakeFrame, Zs as setUpdateFrame, Zt as ONCHAIN_PROVIDER, _ as groupTypingEpoch, _a as fileMessageText, _c as newInbox, _i as isHoldUrl, _l as createDeviceInvite, _o as GROUP_ADMIN_OFF_ERROR, _r as freshHubs, _s as NO_ATTEMPTS, _t as normalizeAtprotoHandle, a as appRevocationFor, aa as DHT_MESSAGE_TTL, ac as enrollCancelReason, ai as chatAppId, an as assertTokenUnits, as as serviceIdFromName, b as COMMUNITY_LIMITS, bc as takeRequest, bl as OwnInviteError, bo as MEMBER_KEY, br as mergeBeacon, bs as handoffAttemptFailed, bu as createIdentity, c as checkAppBeforeRun, ca as dhtFileId, cc as enrollGrantFrame, ci as BUTTONS_CAPABILITY, cn as validatePaymentTarget, co as checkStatusCard, cr as readGroupSignal, cs as HANDOFF_DONE, cu as normalizeRelayUrl, da as sanitizeMime, dc as readEnrollGrant, di as UPGRADE_CAPABILITY, dl as canonicalJson, dn as SPARK_PROVIDER, do as statusCardText, dr as meshHubs, ds as HANDOFF_OFFER, du as budgetRetryMs, ea as TRANSPORTS, ei as checkPushEndpoint, el as isAppHash, es as parseCallSignal, eu as turnVerifierMark, fc as readEnrollHello, fi as HOLD_CAPABILITY, fn as sparkAddressKind, fo as arrivalKey, fr as pickMeshHubs, fs as HANDOFF_PAKE, fu as isDiscoveryBudgetError, g as GroupTypingBoard, gc as inboxRecord, gi as HoldRefusedError, gl as readContactLink, gn as isPubkyKey, go as shownTime, gr as doorHubs, gs as HANDOFF_VERIFIED, gt as isAtprotoDid, gu as createRelayPayload, hc as endedRequests, hi as HoldKeys, hl as encodeContactLink, ho as receivedTimestamp, hr as beaconRecords, hs as HANDOFF_TIMINGS, i as addedAppPermissions, ic as enrollCancelFrame, in as arkAddressPrefix, is as LEGACY_SERVICES, iu as RelayTransport, j as knockRecords, ja as forwardedAgain, jc as openRequest, jl as deviceEchoNonce, jn as findEndpoint, jo as DirectPathWatch, js as handoffOfferFrame, ju as randomBytes, k as entryParams, kc as makeStampPaced, kl as HANDOFF_CAPABILITY, kn as cashuRequestPayload, ko as emptyRatchetState, kr as ChatFiles, ks as handoffHelloFrame, ku as fromBase64Url, l as planAppUpdate, la as formatFileSize, lc as enrollHelloFrame, li as EDIT_CAPABILITY, ll as parseImageMeta, ln as walletNetworkOf, lo as sameButtonText, lr as MESH_HUBS, ls as HANDOFF_HAVE, mc as clearMissed, mi as HOLD_LIMITS, ml as createContactLink, mn as isBitcoinAddress, mo as heardTime, mr as beaconKeys, ms as HANDOFF_REQUEST, mu as PacketTooLargeError, n as readX401SdJwtVc, ni as APP_RANGE_LIMITS, nl as isAppRef, nn as USDT_PUBLIC_RPC, nr as CarriedTransport, ns as emptyLinkRecords, o as appStoreDecision, oa as peekDhtMailbox, oc as enrollDigits, oi as isAppVersion, on as assertWholeSats, os as HANDOFF_ACK, p as readAppStoreSteps, pc as verifyEnrollProof, pi as HOLD_DATED_BACK_MS, pl as readCanonicalJson, pn as sparkInvoiceDetails, po as claimedTime, pr as COMMUNITY_TOPOLOGY, ps as HANDOFF_PIECE_BYTES, pu as withRequestOptions, q as carryMentions, qa as BUTTON_ID, qc as readAppBundleAsync, ql as readTurnPacket, qo as RTC_CONFIG, qr as WAKE_CALL_INTERVAL_MS, r as sameX401HolderJwk, ri as isServeId, rl as readAppRevocation, rn as WALLET_NETWORKS, rs as HTTP_SERVICE_PROTO, s as appUpdateDecision, sa as DHT_FILE_CAPABILITY, sc as enrollDoneFrame, si as APPS_CAPABILITY, sn as formatPaymentAmount, sr as groupSignalFrame, ss as HANDOFF_CANCEL, su as currentRelays, t as newX401HolderKey, ta as automaticTransport, ti as vapidKeysMatch, tl as isAppKey, tn as TEST_USDT_FAUCET_AMOUNT, to as STATUS_CARD_LIMITS, tu as DEFAULT_RELAYS, u as APP_STORE_LIMITS, ua as sanitizeFileName, uc as enrollProofFrame, ui as STATUS_CARD_CAPABILITY, un as SPARK_NETWORKS, ur as mayBeHub, us as HANDOFF_HELLO, uu as traceLink, v as openGroupTyping, va as parseVoiceMeta, vc as planKnocks, vi as newMailbox, vl as deviceInviteJoinerParams, vo as GROUP_MEMBER_CAP, vr as lobbyKeys, vs as filePartName, w as decodeCommunityLink, wa as MAX_REMOVAL_NUMBER, wc as contactDay, wl as inviteLink, wo as rosterHas, wr as rankHubs, ws as handoffContext, wu as verify, x as CommunitySession, xa as parseVideoMeta, xc as turnOff, xl as createChatInvite, xo as commitHash, xr as mergeLobby, xs as handoffAttemptSucceeded, xu as identityFromSeed, y as sealGroupTyping, yc as settleRequest, yi as readManifest, yl as readDeviceInvite, yr as lobbyRecords, ys as handoffAttemptAllowed, z as GROUP_LIMITS, za as reactionEmoji, zl as TURN_RAISE_READ_TIMEOUT_MS, zn as pairedMessageFits, zo as GhostlyHttpError, zr as typingActivity, zs as readHandoffCancel } from "./src-C4sOH4zH.js";
3
- import { $ as ModeChanged, A as IdentityProofs, B as INVOICE_PACE, C as FileAppender, D as streamStored, E as storedSize, F as LightningCards, G as cashuMint, H as ProviderSources, I as cardsKey, J as breezDatabasesFor, K as breezDatabase, L as isRecoveryPhrase, M as sealSecret, N as whenDataKeyDropped, P as CASHU_CARD, Q as relayOnlyProblem, R as normalizePhrase, S as WALLET_TYPES, T as removeStored, U as sourceKey, V as nextInvoiceAsk, W as CASHU_MINT_SOURCE, X as iceServerProblem, Y as dropBreezDatabase, Z as iceServerSetting, _ as crossNetwork, a as storedGroupFiles, at as requireTurn, b as walletInstances, c as receivedPairedReply, ct as NO_PICTURE_METADATA, d as paymentAlias, dt as stripPictureMetadata, et as ModeGate, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, it as refuseAway, j as openSecret, l as replyRef, lt as PICTURE_METADATA_LIMITS, m as assertConfirmedReal, n as groupFileId, nt as networkLabel, o as groupReply, ot as setAwayWallets, p as WALLET_NAMES, q as breezDatabaseInUse, r as groupFileText, rt as awayFrom, s as pairedWireReply, st as setSingleWriterGate, t as GroupFileDesk, tt as WrongNetworkError, u as replyTo, ut as isStrippedPicture, v as paymentNetwork, w as readStored$1, y as paymentNetworksOf, z as lightningPaying } from "./groupFiles-CeF9nPv9.js";
2
+ import { $a as replySnippet, $l as readTurnPacket, $r as readPin, $s as sealHandoffPiece, $t as SEPOLIA_TEST_USDT, A as knockIdentity, Aa as EDIT_RATE_WINDOW_MS, Ac as REQUEST_LIFETIME_MS, Al as inviteLink, An as fedimintRequestPayload, Ao as rosterAdmin, Ar as pickHubs, As as handoffCancelFrame, Au as verify, Ba as COMMUNITY_REACTION_FRAME, Bc as readLinkRecord, Bl as devicePingFrame, Bn as stripPictureMetadata, Bo as DHT_POLL_INTERVALS, Br as transferEnded, Bs as handoffReleaseFrame, Bu as utf8Decode, C as communityHasFrame, Cc as inboxRecord, Ci as HoldRefusedError, Cl as createDeviceInvite, Co as shownTime, Cr as doorHubs, Cs as HANDOFF_VERIFIED, D as decodeGroupEntryLink, Dc as takeRequest, Dl as createChatInvite, Dn as decodeBolt11, Do as MEMBER_KEY, Dr as mergeBeacon, Ds as handoffAttemptFailed, Du as identityFromSeed, Ec as settleRequest, Ei as readManifest, El as OwnInviteError, Er as lobbyRecords, Es as handoffAttemptAllowed, Eu as createIdentity, F as GroupWakeLimiter, Fc as linkRecords, Fl as HANDOFF_CAPABILITY, Fo as RatchetBox, Fr as shouldBeHub, Fs as handoffEphemeral, Fu as fromBase64Url, Ga as queueReaction, Gc as APP_ICON_PATH, Gl as TURN_RAISE_READ_TIMEOUT_MS, Gn as PAIRED_FRAME_TOO_LARGE, Go as presenceSeenAt, Gs as readHandoffAck, Gt as encodeDidDhtDeactivated, H as GroupSession, Ha as REACTION_LIMITS, Hc as seenEntry, Hi as DHT_TEXT_CAPABILITY, Hl as seedSigner, Hn as GhostLink, Ho as PRESENCE_WINDOW, Hs as handoffStreamKey, I as groupWakeFrame, Ic as makeStampPaced, Il as deviceEchoFrame, Io as emptyRatchetState, Ir as ChatFiles, Is as handoffHelloFrame, J as parseCommunityEdit, Ja as readReaction, Jc as appViewOf, Jl as turnPutSummary, Jn as EngineError, Jo as parseLocalTarget, Jr as PIN_LIMITS, Js as readHandoffHave, Jt as signDidDhtPacket, K as GROUP_EDIT_TEXT_BYTES, Ka as reactionEmoji, Kl as TURN_SETTLE_MS, Kn as pairedMessageFits, Ko as GhostlyHttpError, Kr as typingActivity, Ks as readHandoffCancel, Kt as encodeDidDhtPacket, L as groupWakes, La as parseLinkPreview, Lc as mergeContactKnocks, Ll as deviceEchoNonce, Ln as NO_PICTURE_METADATA, Lo as ratchetSessionOf, Lr as FILE_LIMITS, Ls as handoffManifestFrames, Lu as randomBytes, M as mergeKnocks, Ma as REMOVED_TEXT, Mc as knockSlotIdentity, Mn as isFederationId, Mo as verifyCommitSignature, Mr as readBeacon, Ms as handoffContextProof, Mu as sanitizeAvatar, N as readKnocks, Na as RateWindow, Nc as knockSlotOf, Nl as DEVICES_CAPABILITY, Nn as parseCashuRequestPayload, No as edgeParams, Nr as readBeaconHead, Ns as handoffDataFrame, Nu as sanitizeDisplayText, O as encodeGroupEntryLink, Oa as parseVideoMeta, Oc as turnOff, Ol as decodeInviteCode, On as ENDPOINT, Oo as commitHash, Or as mergeLobby, Os as handoffAttemptSucceeded, Ou as identityFromSeedB64, Pa as dhtEditId, Pc as knockSlotRecords, Pl as ENROLL_CAPABILITY, Pn as parseFedimintRequestPayload, Po as RATCHET_CAPABILITY, Pr as readLobby, Ps as handoffDigest, Pu as bytesEqual, Qa as readReply, Qc as pacer, Ql as nextTurnPosition, Qn as GROUP_FILE_LIMITS, Qo as encodeControl, Qr as pinNumberHolds, Qs as readHandoffVerified, Qt as PaymentPreflightError, R as parseGroupWakeFrame, Ra as forwardedAgain, Rc as openRequest, Rl as deviceKeyZ32, Rn as PICTURE_METADATA_LIMITS, Ro as DirectPathWatch, Rs as handoffOfferFrame, Ru as toBase64Url, S as GROUP_READ_NOTE_COMMUNITY, Sc as endedRequests, Si as HoldKeys, Sl as readContactLink, So as receivedTimestamp, Sr as beaconRecords, Ss as HANDOFF_TIMINGS, Su as createRelayPayload, T as encodeCommunityLink, Ta as parseVoiceMeta, Tc as planKnocks, Ti as newMailbox, Tl as readDeviceInvite, To as GROUP_MEMBER_CAP, Tr as lobbyKeys, Ts as filePartName, U as frameBytes, Ua as ReactionWindow, Uc as APP_BUNDLE_LIMITS, Ui as capsDescriptors, Ul as webCryptoSigner, Un as INVITE_TAKEN, Uo as RELAY_POLL_INTERVALS, Us as handoffVersions, Ut as didDhtDocument, V as GROUP_READ_NOTE, Va as GROUP_REACTION_FRAME, Vc as requestRecords, Vi as CapsExchange, Vl as newDeviceSetSecret, Vr as transferStalled, Vs as handoffRetryAfter, Vu as utf8Encode, Wa as nextReactionNumber, Wc as APP_BUNDLE_MAGIC, Wi as dialDescriptors, Wn as LIVENESS_PING_MS, Wo as WATCH_PEER_MS, Wr as TypingSender, Ws as newHandoffId, Wt as didDhtFromPublicKey, X as groupName, Xa as wireReaction, Xl as TURN_MAX, Xn as engineText, Xo as LIMITS, Xr as nextPinNumber, Xs as readHandoffPake, Xt as EVM_TEST_CHAINS, Y as mentionsMember, Ya as validReactionNumber, Yl as TURN_LAST_SEQUENCE, Yn as engineError, Yo as webLocalFetch, Yr as mayPin, Ys as readHandoffHello, Yt as ETHEREUM_USDT, Za as pairedReplyAuthor, Zc as isAppUrl, Zi as emptyIdentityLedger, Zl as firstDeviceSetSecret, Zn as parseEngineError, Zo as decodeControl, Zr as pinIsNewer, Zs as readHandoffTurnFrame, Zt as ONCHAIN_PROVIDER, _ as groupTypingEpoch, _a as sanitizeFileName, _c as enrollProofFrame, _i as STATUS_CARD_CAPABILITY, _l as canonicalJson, _r as mayBeHub, _s as HANDOFF_HELLO, _t as normalizeAtprotoHandle, _u as budgetRetryMs, a as appRevocationFor, aa as emptyProofLedger, ac as signTombstone, ai as relayRequest, al as appRef, an as assertTokenUnits, ar as readGroupFileMeta, as as contactRtcConfig, au as turnStatedVerifier, b as COMMUNITY_LIMITS, bc as verifyEnrollProof, bi as HOLD_DATED_BACK_MS, bl as createContactLink, bo as claimedTime, br as COMMUNITY_TOPOLOGY, bs as HANDOFF_PIECE_BYTES, bu as PacketTooLargeError, c as checkAppBeforeRun, ca as automaticTransport, ci as vapidKeysMatch, cl as isAppKey, cn as validatePaymentTarget, co as STATUS_CARD_LIMITS, dc as enrollCancelFrame, dn as SPARK_PROVIDER, ds as LEGACY_SERVICES, ei as WAKE_CALL_INTERVAL_MS, el as readAppBundleAsync, eo as BUTTON_ID, es as RTC_CONFIG, eu as signTurnPacket, fa as DHT_MESSAGE_TTL, fc as enrollCancelReason, fi as chatAppId, fn as sparkAddressKind, fs as serviceIdFromName, g as GroupTypingBoard, ga as formatFileSize, gc as enrollHelloFrame, gi as EDIT_CAPABILITY, gn as isPubkyKey, go as sameButtonText, gr as MESH_HUBS, gs as HANDOFF_HAVE, gt as isAtprotoDid, gu as traceLink, ha as dhtFileId, hc as enrollGrantFrame, hi as BUTTONS_CAPABILITY, hl as parseImageMeta, ho as checkStatusCard, hr as readGroupSignal, hs as HANDOFF_DONE, i as addedAppPermissions, ia as PeerProofs, ic as setUpdateFrame, ii as parseWakeFrame, il as appFingerprint, in as arkAddressPrefix, iu as turnName, j as knockRecords, ja as MAX_REMOVAL_NUMBER, jc as contactDay, jl as inviteOwnership, jn as findEndpoint, jo as rosterHas, jr as rankHubs, js as handoffContext, k as entryParams, ka as EDIT_BUFFER_MS, kc as ContactRequestError, kl as encodeInviteCode, kn as cashuRequestPayload, ko as parseGroupCommit, kr as newerHead, ks as handoffBusyFrame, ku as publicKeyFromZ32, l as planAppUpdate, li as APP_RANGE_LIMITS, ll as isAppRef, ln as walletNetworkOf, lr as CarriedTransport, ls as emptyLinkRecords, ma as DHT_FILE_CAPABILITY, mc as enrollDoneFrame, mi as APPS_CAPABILITY, mn as isBitcoinAddress, mr as groupSignalFrame, ms as HANDOFF_CANCEL, mu as normalizeRelayUrl, n as readX401SdJwtVc, nc as readSetUpdate, ni as deviceWakeRequest, nn as USDT_PUBLIC_RPC, nu as turnInstance, o as appStoreDecision, oa as validExternalKey, oc as verifySetUpdate, oi as wakeRequest, on as assertWholeSats, ou as turnVerifierMark, p as readAppStoreSteps, pa as peekDhtMailbox, pc as enrollDigits, pi as isAppVersion, pn as sparkInvoiceDetails, ps as HANDOFF_ACK, pu as currentRelays, q as carryMentions, qa as reactionIsNewer, qc as appDigest, ql as classifyTurnRead, qn as pairedMessageFrame, qo as formatLocalTarget, qs as readHandoffDone, r as sameX401HolderJwk, ra as lastSharedWithMe, rc as setAckFrame, ri as newWakeToken, rl as APP_STATEMENT_LIMITS, rn as WALLET_NETWORKS, rr as groupFileFallback, ru as turnKeys, s as appUpdateDecision, sa as TRANSPORTS, si as checkPushEndpoint, sl as isAppHash, sn as formatPaymentAmount, ss as parseCallSignal, su as DEFAULT_RELAYS, t as newX401HolderKey, ta as receivedIdentityStatus, ti as WakeLimiter, tl as sha256Paced, tn as TEST_USDT_FAUCET_AMOUNT, tu as signTurnRelease, u as APP_STORE_LIMITS, ui as isServeId, ul as readAppRevocation, un as SPARK_NETWORKS, us as HTTP_SERVICE_PROTO, uu as RelayTransport, v as openGroupTyping, va as sanitizeMime, vc as readEnrollGrant, vi as UPGRADE_CAPABILITY, vo as statusCardText, vr as meshHubs, vs as HANDOFF_OFFER, vu as isDiscoveryBudgetError, w as decodeCommunityLink, wa as fileMessageText, wc as newInbox, wi as isHoldUrl, wl as deviceInviteJoinerParams, wo as GROUP_ADMIN_OFF_ERROR, wr as freshHubs, ws as NO_ATTEMPTS, x as CommunitySession, xc as clearMissed, xi as HOLD_LIMITS, xl as encodeContactLink, xo as heardTime, xr as beaconKeys, xs as HANDOFF_REQUEST, y as sealGroupTyping, yc as readEnrollHello, yi as HOLD_CAPABILITY, yl as readCanonicalJson, yo as arrivalKey, yr as pickMeshHubs, ys as HANDOFF_PAKE, yu as withRequestOptions, z as GROUP_LIMITS, za as readForwarded, zc as readKnockSlot, zl as deviceLinkPairing, zn as isStrippedPicture, zr as sentWhole, zs as handoffPakeFrame, zu as toZ32 } from "./src-BD8RBVEp.js";
4
3
  import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
5
4
  import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
6
- import { t as nwc } from "./nwcProvider-DUB6xO-b.js";
5
+ import { t as nwc } from "./nwcProvider-CzX3xH47.js";
7
6
  import { a as clearProfileStores, c as deleteDatabase, d as newestWalletTx, f as openDb, g as wrap, h as transact, i as STORES$1, l as errorLine, m as store, n as APP_STORAGE_SCOPE_INDEX, o as committed, p as profileOpenFailure, r as CARD_INDEX, s as databaseName, t as APP_STORAGE_CHAT_INDEX, u as fileStore } from "./idb-BkOJES5_.js";
8
- import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-DhJYOomu.js";
9
- import { i as fedimintDatabase, n as createIrohWebEndpoint, o as loadFedimintSdk, r as irohRelayProblem, t as DEFAULT_IROH_RELAYS } from "./irohWeb-D6tAPHZa.js";
7
+ import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-BncJ9KSM.js";
8
+ import { $ as ModeChanged, A as IdentityProofs, B as INVOICE_PACE, C as FileAppender, D as streamStored, E as storedSize, F as LightningCards, G as cashuMint, H as ProviderSources, I as cardsKey, J as breezDatabasesFor, K as breezDatabase, L as isRecoveryPhrase, M as sealSecret, N as whenDataKeyDropped, P as CASHU_CARD, Q as relayOnlyProblem, R as normalizePhrase, S as WALLET_TYPES, T as removeStored, U as sourceKey, V as nextInvoiceAsk, W as CASHU_MINT_SOURCE, X as iceServerProblem, Y as dropBreezDatabase, Z as iceServerSetting, _ as crossNetwork, a as storedGroupFiles, at as requireTurn, b as walletInstances, c as receivedPairedReply, d as paymentAlias, et as ModeGate, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, it as refuseAway, j as openSecret, l as replyRef, m as assertConfirmedReal, n as groupFileId, nt as networkLabel, o as groupReply, ot as setAwayWallets, p as WALLET_NAMES, q as breezDatabaseInUse, r as groupFileText, rt as awayFrom, s as pairedWireReply, st as setSingleWriterGate, t as GroupFileDesk, tt as WrongNetworkError, u as replyTo, v as paymentNetwork, w as readStored$1, y as paymentNetworksOf, z as lightningPaying } from "./groupFiles-FXel6zIc.js";
9
+ import { a as fedimintDatabase, i as onPublicIrohRelay, n as createIrohWebEndpoint, r as irohRelayProblem, s as loadFedimintSdk, t as DEFAULT_IROH_RELAYS } from "./irohWeb-BSv_BWyG.js";
10
10
  import { c as isTestMint, d as mintUrlSpelling, f as paysItsOwnInvoices, l as isWorthlessMint, n as DEFAULT_MINTS, o as fakesLightning, r as TEST_MINT, t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
11
- import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-BfqHJdA6.js";
12
- import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-CGfUsR1m.js";
13
- import { d as chosenResolver, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-BVwhiYjj.js";
11
+ import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-D8z5gwGI.js";
12
+ import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-Dt75vrmY.js";
13
+ import { d as chosenResolver, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-ZxVzwFNA.js";
14
14
  import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-DNgrRL0R.js";
15
15
  import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
16
16
  import { sha256 } from "@noble/hashes/sha2.js";
@@ -199,7 +199,7 @@ function viewNews(before, after) {
199
199
  //#endregion
200
200
  //#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
201
201
  /** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
202
- var loadUsdt = () => import("./usdt-CMwatDnQ.js");
202
+ var loadUsdt = () => import("./usdt-DhVN8geQ.js");
203
203
  /** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
204
204
  var DEFAULT_USDT = {
205
205
  network: "ethereum",
@@ -550,6 +550,44 @@ var UsdtWallet = class {
550
550
  }
551
551
  };
552
552
  //#endregion
553
+ //#region ../browser/src/shared/settingsPatch.ts
554
+ /** Settings that are on or off. */
555
+ var SWITCHES = [
556
+ "online",
557
+ "mintsInitialized",
558
+ "shareProfile",
559
+ "publicProfiles",
560
+ "sendTyping",
561
+ "autoDownloads",
562
+ "serveFiles"
563
+ ];
564
+ /** Settings that are lists of addresses. */
565
+ var LISTS = [
566
+ "relays",
567
+ "irohRelays",
568
+ "mints"
569
+ ];
570
+ var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
571
+ /**
572
+ * Why a settings patch holds a value of a kind its setting never has, or null. The apps' own patches always have the
573
+ * right kind; one from outside them (`ghostly engine updateSettings`, the socket's `engine.call`) was written as it
574
+ * came, and `mints` as a text left a profile that no longer opened. A key left out (or undefined) is not looked at; the
575
+ * values themselves (an address, a TURN server) are checked where they are used.
576
+ */
577
+ function settingsPatchProblem(patch) {
578
+ for (const key of SWITCHES) if (patch[key] !== void 0 && typeof patch[key] !== "boolean") return `${key} is on or off (true or false)`;
579
+ for (const key of LISTS) {
580
+ const value = patch[key];
581
+ if (value !== void 0 && !(Array.isArray(value) && value.every((item) => typeof item === "string"))) return `${key} is a list of addresses`;
582
+ }
583
+ if (patch.nick !== void 0 && typeof patch.nick !== "string") return "nick is a text";
584
+ if (patch.iceServers !== void 0 && !Array.isArray(patch.iceServers)) return "iceServers is a list of ICE servers";
585
+ const hold = patch.holdStorage;
586
+ if (hold !== void 0 && hold !== null && !isObject(hold)) return "holdStorage is the S3 storage and its space, or null";
587
+ if (patch.nostr !== void 0 && !isObject(patch.nostr)) return "nostr is an object of Nostr settings";
588
+ return null;
589
+ }
590
+ //#endregion
553
591
  //#region ../browser/src/engine/paymentAdapters/backup.ts
554
592
  /**
555
593
  * Wallet database versions a backup may carry. 3 is what SDK 0.4.74-0.4.76 made (Ghostly 1.1.3 and earlier);
@@ -648,7 +686,7 @@ async function restoreArkDatabase(walletId, snapshot) {
648
686
  //#endregion
649
687
  //#region ../browser/src/engine/paymentAdapters/arkWallet.ts
650
688
  /** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
651
- var loadArkade = () => import("./arkade-Cu3TbPxC.js");
689
+ var loadArkade = () => import("./arkade-DtYR9H0c.js");
652
690
  /** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
653
691
  var RETIRE_READ_MS = 1e4;
654
692
  /** Every new profile starts with this wallet: nothing to set up before receiving. */
@@ -9148,7 +9186,7 @@ var HostNotContacted = class extends Error {};
9148
9186
  */
9149
9187
  function fixedHostsFetch(fetch) {
9150
9188
  return async (url, options) => {
9151
- const { fixedIdentityHosts } = await import("./fixedHosts-BiukTsd9.js");
9189
+ const { fixedIdentityHosts } = await import("./fixedHosts-B598JzbC.js");
9152
9190
  const host = hostOf$1(url);
9153
9191
  if (!fixedIdentityHosts().has(host) && host !== hostOf$1("https://public.api.bsky.app") && host !== hostOf$1("https://nexus.pubky.app")) throw new HostNotContacted(`Hide my IP from contacts is on: ${host}, a server your contact chose, was not contacted`);
9154
9192
  return fetch(url, options);
@@ -10593,6 +10631,25 @@ function foldText(text) {
10593
10631
  */
10594
10632
  var SEARCH_KEPT_MS = 6e4;
10595
10633
  /**
10634
+ * Formatting's marks, which a bubble does not show, and a `[label](link)`'s brackets and link: "*hello* world" reads
10635
+ * "hello world". The pages parse a text to read it as it shows (apps/ui lib/chatSearch `searchText`); the engine has
10636
+ * no parser, so it leaves every such mark out of both the text and the query. That finds what the pages find (but by
10637
+ * a query of marks alone) and a little more ("*hello*" finds "hello"). A link is still found by its address.
10638
+ */
10639
+ var MARKS = /[*_~|`[\]]/g;
10640
+ var LINK = /\]\([^)\s]*\)/g;
10641
+ var loose = (folded) => folded.replace(MARKS, "");
10642
+ /** What a message offers the chat list's search, folded and loose: a file's name, a text's words; nothing for a payment. */
10643
+ function searchTexts(message) {
10644
+ if (message.paymentId) return [];
10645
+ if (message.file) return [loose(foldText(message.file.name))];
10646
+ if (!message.text) return [];
10647
+ const folded = foldText(message.text);
10648
+ const shown = loose(folded.replace(LINK, "]"));
10649
+ const withLinks = loose(folded);
10650
+ return shown === withLinks ? [shown] : [shown, withLinks];
10651
+ }
10652
+ /**
10596
10653
  * The chat list's search over the chats' whole histories, in the engine (`chatsFound`): a page that holds a chat's
10597
10654
  * newest page only (the extension's) finds it by an older message too, without being sent its whole history. Each chat's
10598
10655
  * texts are read and folded once, and read again only after the chat changed (`changed`, as the pages hear it).
@@ -10605,9 +10662,9 @@ var ChatTextSearch = class {
10605
10662
  constructor(read) {
10606
10663
  this.read = read;
10607
10664
  }
10608
- /** The chats among `linkIds` with a message whose text holds `query` (folded as `foldText` does), in that order. */
10665
+ /** The chats among `linkIds` with a message whose text holds `query` (folded as `foldText` does, marks out), in that order. */
10609
10666
  async found(linkIds, query) {
10610
- const q = foldText(query);
10667
+ const q = loose(foldText(query));
10611
10668
  if (!q) return [];
10612
10669
  if (this.timer) clearTimeout(this.timer);
10613
10670
  this.timer = setTimeout(() => {
@@ -10625,7 +10682,7 @@ var ChatTextSearch = class {
10625
10682
  textsOf(linkId) {
10626
10683
  let texts = this.texts.get(linkId);
10627
10684
  if (!texts) {
10628
- texts = this.read(linkId).then((messages) => messages.flatMap((m) => m.text ? [foldText(m.text)] : []));
10685
+ texts = this.read(linkId).then((messages) => messages.flatMap(searchTexts));
10629
10686
  this.texts.set(linkId, texts);
10630
10687
  texts.catch(() => {
10631
10688
  if (this.texts.get(linkId) === texts) this.texts.delete(linkId);
@@ -10875,6 +10932,8 @@ var APP_CHECK_TIMINGS = {
10875
10932
  /** A check at start is skipped when every app was checked this recently (a page reloaded several times). */
10876
10933
  freshMs: 36e5
10877
10934
  };
10935
+ /** Apps the update check reads at once (their publishers' files, their sources' peeks): all on the same two hosts. */
10936
+ var APP_CHECK_PARALLEL = 6;
10878
10937
  /** Revocations are checked this long at a time before the page's thread is let go. */
10879
10938
  var REVOCATIONS_SLICE_MS = 10;
10880
10939
  /**
@@ -11085,6 +11144,20 @@ function sameRecord(now, was) {
11085
11144
  if (!was) return !now;
11086
11145
  return !!now && now.installedAt === was.installedAt && now.digest === was.digest && now.pending?.digest === was.pending?.digest && now.bytes === was.bytes && now.equivocation?.digest === was.equivocation?.digest;
11087
11146
  }
11147
+ /** Whether two records of an app differ in nothing but `checkedAt`. */
11148
+ function sameExceptChecked(a, b) {
11149
+ try {
11150
+ return canonicalJson({
11151
+ ...a,
11152
+ checkedAt: 0
11153
+ }) === canonicalJson({
11154
+ ...b,
11155
+ checkedAt: 0
11156
+ });
11157
+ } catch {
11158
+ return false;
11159
+ }
11160
+ }
11088
11161
  /** Rows of one app (`[ref]`), or of one app in one scope (`[ref, scope]`), in `STORES.appStorage`, counter rows included. */
11089
11162
  var rowsOf = (...prefix) => IDBKeyRange.bound(prefix, [...prefix, []]);
11090
11163
  /** The app's own rows of one scope: its counter row left out. */
@@ -11811,6 +11884,7 @@ var Apps = class {
11811
11884
  digest,
11812
11885
  at: this.now()
11813
11886
  });
11887
+ const held = await this.storeRecord(index.key);
11814
11888
  return {
11815
11889
  url: at,
11816
11890
  key: index.key,
@@ -11821,15 +11895,17 @@ var Apps = class {
11821
11895
  expires: index.expires,
11822
11896
  expired: read.store.expired,
11823
11897
  apps: index.apps.length,
11824
- ...index.description !== void 0 && { description: index.description }
11898
+ ...index.description !== void 0 && { description: index.description },
11899
+ ...held && !held.removed && { held: held.index ? { sequence: held.index.sequence } : {} }
11825
11900
  };
11826
11901
  }
11827
11902
  /**
11828
11903
  * Adds a store the person chose: read at its URL and pinned to its key (`key`, when given, is the key the person saw,
11829
11904
  * and another one is refused). A store already added under that key keeps the URL it is read from and takes only a newer
11830
11905
  * index: a copy of its signed index at another URL, the same one or an older one, never moves it there (it would be
11831
- * read only there from then on, frozen). The index the preview just read at that URL, under that key, is taken as it
11832
- * is (only its expiry again), not downloaded again.
11906
+ * read only there from then on, frozen). The same index is nothing to do, and an older one is refused with the held
11907
+ * store left as it was: a copy the person chose is not a read of the store, so it marks no problem on it. The index the
11908
+ * preview just read at that URL, under that key, is taken as it is (only its expiry again), not downloaded again.
11833
11909
  */
11834
11910
  async addStore({ url, key }) {
11835
11911
  if (key !== void 0 && !isAppKey(key)) fail("store-key", "Not a store key");
@@ -11856,6 +11932,19 @@ var Apps = class {
11856
11932
  digest
11857
11933
  });
11858
11934
  if (seen === "rollback" || seen === "equivocation") fail(seen, `This store's index is older than the one you had (sequence ${held.seen.sequence})`);
11935
+ if (held && !held.removed && held.index) {
11936
+ const decision = appStoreDecision({
11937
+ key: held.key,
11938
+ sequence: held.index.sequence,
11939
+ digest: held.digest ?? ""
11940
+ }, {
11941
+ key: index.key,
11942
+ sequence: index.sequence,
11943
+ digest
11944
+ });
11945
+ if (decision === "same") return this.summary(held);
11946
+ if (decision === "rollback") fail("rollback", `This store's index is older than the one you have (sequence ${held.index.sequence})`);
11947
+ }
11859
11948
  const record = held && !held.removed ? held : {
11860
11949
  key: index.key,
11861
11950
  url: at,
@@ -12237,184 +12326,194 @@ var Apps = class {
12237
12326
  await this.refreshStores();
12238
12327
  const stores = await this.stores();
12239
12328
  const out = [];
12240
- for (const listed of apps) {
12241
- if (!await this.hasBundle(listed.bytes, listed.digest)) await this.fetchFiles({ ref: listed.ref }).catch(() => {});
12242
- const first = await this.app(listed.ref);
12243
- if (!first) continue;
12244
- let stored = first;
12245
- let app = first;
12246
- let outcome = "none";
12247
- let wrote;
12248
- const dropped = [];
12249
- if (app.store !== void 0 && !stores.some((s) => s.key === app.store)) {
12250
- const { store: _s, ...unpinned } = app;
12251
- app = unpinned;
12252
- }
12253
- if (app.store !== void 0 && app.pending && stores.find((s) => s.key === app.store)?.index && this.pinnedListing(app, stores)?.digest !== app.pending.digest) {
12254
- dropped.push(app.pending);
12255
- const { pending: _p, ...rest } = app;
12256
- app = rest;
12257
- }
12258
- const highest = Math.max(app.sequence, app.pending?.sequence ?? 0);
12259
- const known = /* @__PURE__ */ new Set([app.digest, ...app.pending ? [app.pending.digest] : []]);
12260
- const pinned = app.store;
12261
- const candidates = /* @__PURE__ */ new Map();
12262
- const newer = (v) => v.ref === app.ref && (v.sequence > highest || v.sequence >= app.sequence && !known.has(v.digest));
12263
- for (const s of stores) {
12264
- if (pinned !== void 0 && s.key !== pinned) continue;
12265
- const listing = s.index?.apps.find((a) => a.ref === app.ref);
12266
- if (!listing || !newer(listing)) continue;
12267
- const seen = `${s.digest} ${listing.digest}`;
12268
- for (const url of listingUrls(listing.urls)) {
12269
- const missed = `${s.key} ${app.ref} ${url}`;
12270
- if (candidates.has(url) || s.digest !== void 0 && this.listingMisses.get(missed) === seen) continue;
12271
- candidates.set(url, {
12272
- sequence: listing.sequence,
12273
- ...pinned !== void 0 && { digest: listing.digest },
12274
- peek: true,
12275
- ...s.digest !== void 0 && { miss: [missed, seen] }
12276
- });
12277
- }
12278
- }
12279
- if (pinned === void 0) for (const url of (app.manifest.sources ?? []).filter(isAppFetchUrl)) {
12280
- if (candidates.has(url)) continue;
12281
- try {
12282
- const peek = await this.peekAt(url);
12283
- if (peek && newer(peek)) candidates.set(url, {
12284
- sequence: peek.sequence,
12285
- holds: peek
12286
- });
12287
- } catch {}
12329
+ let next = 0;
12330
+ const worker = async () => {
12331
+ while (next < apps.length) {
12332
+ const i = next++;
12333
+ out[i] = await this.checkApp(apps[i], stores);
12334
+ }
12335
+ };
12336
+ await Promise.all(Array.from({ length: Math.min(APP_CHECK_PARALLEL, apps.length) }, worker));
12337
+ return out.filter((r) => r !== null);
12338
+ }
12339
+ /** One app's part of the update check (`checkNow`); null when it is not installed any more. */
12340
+ async checkApp(listed, stores) {
12341
+ if (!await this.hasBundle(listed.bytes, listed.digest)) await this.fetchFiles({ ref: listed.ref }).catch(() => {});
12342
+ const first = await this.app(listed.ref);
12343
+ if (!first) return null;
12344
+ let stored = first;
12345
+ let app = first;
12346
+ let outcome = "none";
12347
+ let wrote;
12348
+ const dropped = [];
12349
+ if (app.store !== void 0 && !stores.some((s) => s.key === app.store)) {
12350
+ const { store: _s, ...unpinned } = app;
12351
+ app = unpinned;
12352
+ }
12353
+ if (app.store !== void 0 && app.pending && stores.find((s) => s.key === app.store)?.index && this.pinnedListing(app, stores)?.digest !== app.pending.digest) {
12354
+ dropped.push(app.pending);
12355
+ const { pending: _p, ...rest } = app;
12356
+ app = rest;
12357
+ }
12358
+ const highest = Math.max(app.sequence, app.pending?.sequence ?? 0);
12359
+ const known = /* @__PURE__ */ new Set([app.digest, ...app.pending ? [app.pending.digest] : []]);
12360
+ const pinned = app.store;
12361
+ const candidates = /* @__PURE__ */ new Map();
12362
+ const newer = (v) => v.ref === app.ref && (v.sequence > highest || v.sequence >= app.sequence && !known.has(v.digest));
12363
+ for (const s of stores) {
12364
+ if (pinned !== void 0 && s.key !== pinned) continue;
12365
+ const listing = s.index?.apps.find((a) => a.ref === app.ref);
12366
+ if (!listing || !newer(listing)) continue;
12367
+ const seen = `${s.digest} ${listing.digest}`;
12368
+ for (const url of listingUrls(listing.urls)) {
12369
+ const missed = `${s.key} ${app.ref} ${url}`;
12370
+ if (candidates.has(url) || s.digest !== void 0 && this.listingMisses.get(missed) === seen) continue;
12371
+ candidates.set(url, {
12372
+ sequence: listing.sequence,
12373
+ ...pinned !== void 0 && { digest: listing.digest },
12374
+ peek: true,
12375
+ ...s.digest !== void 0 && { miss: [missed, seen] }
12376
+ });
12288
12377
  }
12289
- const revokeRead = /* @__PURE__ */ new Set();
12290
- const before = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
12291
- app = withRevocations(app, before ?? []);
12292
- if (app.pending && this.runStatus(versionOf(app.pending.manifest, app.pending.digest), this.storeViews(stores), app.revocations).status !== "ok") {
12293
- dropped.push(app.pending);
12294
- const { pending: _p, ...rest } = app;
12295
- app = rest;
12296
- }
12297
- for (const [url, want] of [...candidates].sort(([, a], [, b]) => b.sequence - a.sequence)) {
12298
- let holds = want.holds;
12299
- if (want.peek) {
12300
- let peek;
12301
- try {
12302
- peek = await this.peekAt(url);
12303
- } catch {
12304
- continue;
12305
- }
12306
- if (!peek || !newer(peek) || want.digest !== void 0 && peek.digest !== want.digest) {
12307
- if (want.miss) this.listingMisses.set(...want.miss);
12308
- continue;
12309
- }
12310
- holds = peek;
12311
- }
12312
- const twin = holds && (holds.sequence === app.sequence || holds.sequence === app.pending?.sequence);
12313
- if (holds && !twin && this.runStatus(holds, this.storeViews(stores), app.revocations).status !== "ok") continue;
12314
- let fetched;
12378
+ }
12379
+ if (pinned === void 0) for (const url of (app.manifest.sources ?? []).filter(isAppFetchUrl)) {
12380
+ if (candidates.has(url)) continue;
12381
+ try {
12382
+ const peek = await this.peekAt(url);
12383
+ if (peek && newer(peek)) candidates.set(url, {
12384
+ sequence: peek.sequence,
12385
+ holds: peek
12386
+ });
12387
+ } catch {}
12388
+ }
12389
+ const revokeRead = /* @__PURE__ */ new Set();
12390
+ const before = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
12391
+ app = withRevocations(app, before ?? []);
12392
+ if (app.pending && this.runStatus(versionOf(app.pending.manifest, app.pending.digest), this.storeViews(stores), app.revocations).status !== "ok") {
12393
+ dropped.push(app.pending);
12394
+ const { pending: _p, ...rest } = app;
12395
+ app = rest;
12396
+ }
12397
+ for (const [url, want] of [...candidates].sort(([, a], [, b]) => b.sequence - a.sequence)) {
12398
+ let holds = want.holds;
12399
+ if (want.peek) {
12400
+ let peek;
12315
12401
  try {
12316
- fetched = await this.fetchBundle(url);
12402
+ peek = await this.peekAt(url);
12317
12403
  } catch {
12318
12404
  continue;
12319
12405
  }
12320
- const { bundle, bytes } = fetched;
12321
- const version = versionOf(bundle.manifest, bundle.digest);
12322
- if (version.ref !== app.ref || known.has(version.digest)) continue;
12323
- if (want.digest !== void 0 && version.digest !== want.digest) continue;
12324
- if (app.pending && version.sequence === app.pending.sequence) {
12325
- app = {
12326
- ...app,
12327
- equivocation: {
12328
- sequence: version.sequence,
12329
- digest: version.digest,
12330
- at: this.now()
12331
- }
12332
- };
12333
- outcome = "equivocation";
12406
+ if (!peek || !newer(peek) || want.digest !== void 0 && peek.digest !== want.digest) {
12407
+ if (want.miss) this.listingMisses.set(...want.miss);
12334
12408
  continue;
12335
12409
  }
12336
- const plan = planAppUpdate(app, {
12337
- ...version,
12338
- permissions: bundle.manifest.permissions
12339
- });
12340
- if (plan.action === "refuse") {
12341
- if (plan.decision === "equivocation") {
12342
- app = {
12343
- ...app,
12344
- equivocation: {
12345
- sequence: version.sequence,
12346
- digest: version.digest,
12347
- at: this.now()
12348
- }
12349
- };
12350
- outcome = "equivocation";
12410
+ holds = peek;
12411
+ }
12412
+ const twin = holds && (holds.sequence === app.sequence || holds.sequence === app.pending?.sequence);
12413
+ if (holds && !twin && this.runStatus(holds, this.storeViews(stores), app.revocations).status !== "ok") continue;
12414
+ let fetched;
12415
+ try {
12416
+ fetched = await this.fetchBundle(url);
12417
+ } catch {
12418
+ continue;
12419
+ }
12420
+ const { bundle, bytes } = fetched;
12421
+ const version = versionOf(bundle.manifest, bundle.digest);
12422
+ if (version.ref !== app.ref || known.has(version.digest)) continue;
12423
+ if (want.digest !== void 0 && version.digest !== want.digest) continue;
12424
+ if (app.pending && version.sequence === app.pending.sequence) {
12425
+ app = {
12426
+ ...app,
12427
+ equivocation: {
12428
+ sequence: version.sequence,
12429
+ digest: version.digest,
12430
+ at: this.now()
12351
12431
  }
12352
- continue;
12353
- }
12354
- if (this.runStatus(version, this.storeViews(stores), app.revocations).status !== "ok") continue;
12355
- if (app.pending && version.sequence < app.pending.sequence) continue;
12356
- const kind = await this.writeBundle(version.digest, bytes);
12357
- wrote = {
12358
- bytes: kind,
12359
- digest: version.digest
12360
12432
  };
12361
- if (plan.action === "install") {
12362
- const old = app;
12363
- const next = this.versionRecord(app, bundle, kind, url, app.store);
12364
- const passed = old.pending && old.pending.sequence <= version.sequence ? old.pending : void 0;
12365
- if (passed) delete next.pending;
12366
- if (!await this.putAppIfUnchanged(next, stored)) break;
12367
- app = stored = next;
12368
- if (passed) await this.removeBundle(passed.bytes, passed.digest);
12369
- await this.removeBundle(old.bytes, old.digest);
12370
- outcome = "updated";
12371
- } else {
12372
- if (app.pending) dropped.push(app.pending);
12433
+ outcome = "equivocation";
12434
+ continue;
12435
+ }
12436
+ const plan = planAppUpdate(app, {
12437
+ ...version,
12438
+ permissions: bundle.manifest.permissions
12439
+ });
12440
+ if (plan.action === "refuse") {
12441
+ if (plan.decision === "equivocation") {
12373
12442
  app = {
12374
12443
  ...app,
12375
- pending: {
12444
+ equivocation: {
12376
12445
  sequence: version.sequence,
12377
12446
  digest: version.digest,
12378
- manifest: bundle.manifest,
12379
- added: plan.added,
12380
- bytes: kind,
12381
- from: url,
12382
12447
  at: this.now()
12383
12448
  }
12384
12449
  };
12385
- outcome = "ask";
12450
+ outcome = "equivocation";
12386
12451
  }
12387
- break;
12452
+ continue;
12388
12453
  }
12389
- const after = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
12390
- const revocations = before || after ? [...before ?? [], ...after ?? []] : null;
12391
- const versions = this.versionsOf(app);
12392
- const stays = revocations ? stopping(versions, app.revocations ?? []) : app.revocations ?? [];
12393
- const carried = stopping(versions, stores.flatMap((s) => s.index?.revoked ?? []));
12394
- const merged = new Map([
12395
- ...stays,
12396
- ...revocations ?? [],
12397
- ...carried
12398
- ].map((r) => [canonicalJson(r), r]));
12399
- if ((await this.app(app.ref))?.store === void 0 && app.store !== void 0) {
12400
- const { store: _s, ...unpinned } = app;
12401
- app = unpinned;
12402
- }
12403
- app = {
12404
- ...app,
12405
- ...merged.size && { revocations: [...merged.values()] },
12406
- checkedAt: this.now()
12454
+ if (this.runStatus(version, this.storeViews(stores), app.revocations).status !== "ok") continue;
12455
+ if (app.pending && version.sequence < app.pending.sequence) continue;
12456
+ const kind = await this.writeBundle(version.digest, bytes);
12457
+ wrote = {
12458
+ bytes: kind,
12459
+ digest: version.digest
12407
12460
  };
12408
- const put = await this.putAppIfUnchanged(app, stored);
12409
- for (const files of [...dropped, ...!put && wrote ? [wrote] : []]) await this.removeUnusedBundle(app.ref, files.bytes, files.digest);
12410
- if (!put) continue;
12411
- out.push({
12412
- ref: app.ref,
12413
- outcome,
12414
- run: await this.runCheckOf(app, stores)
12415
- });
12461
+ if (plan.action === "install") {
12462
+ const old = app;
12463
+ const next = this.versionRecord(app, bundle, kind, url, app.store);
12464
+ const passed = old.pending && old.pending.sequence <= version.sequence ? old.pending : void 0;
12465
+ if (passed) delete next.pending;
12466
+ if (!await this.putAppIfUnchanged(next, stored)) break;
12467
+ app = stored = next;
12468
+ if (passed) await this.removeBundle(passed.bytes, passed.digest);
12469
+ await this.removeBundle(old.bytes, old.digest);
12470
+ outcome = "updated";
12471
+ } else {
12472
+ if (app.pending) dropped.push(app.pending);
12473
+ app = {
12474
+ ...app,
12475
+ pending: {
12476
+ sequence: version.sequence,
12477
+ digest: version.digest,
12478
+ manifest: bundle.manifest,
12479
+ added: plan.added,
12480
+ bytes: kind,
12481
+ from: url,
12482
+ at: this.now()
12483
+ }
12484
+ };
12485
+ outcome = "ask";
12486
+ }
12487
+ break;
12416
12488
  }
12417
- return out;
12489
+ const after = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
12490
+ const revocations = before || after ? [...before ?? [], ...after ?? []] : null;
12491
+ const versions = this.versionsOf(app);
12492
+ const stays = revocations ? stopping(versions, app.revocations ?? []) : app.revocations ?? [];
12493
+ const carried = stopping(versions, stores.flatMap((s) => s.index?.revoked ?? []));
12494
+ const merged = new Map([
12495
+ ...stays,
12496
+ ...revocations ?? [],
12497
+ ...carried
12498
+ ].map((r) => [canonicalJson(r), r]));
12499
+ const current = await this.app(app.ref);
12500
+ if (current?.store === void 0 && app.store !== void 0) {
12501
+ const { store: _s, ...unpinned } = app;
12502
+ app = unpinned;
12503
+ }
12504
+ app = {
12505
+ ...app,
12506
+ ...merged.size && { revocations: [...merged.values()] },
12507
+ checkedAt: this.now()
12508
+ };
12509
+ const put = stored.checkedAt !== void 0 && this.now() - stored.checkedAt < APP_CHECK_TIMINGS.freshMs / 2 && sameExceptChecked(app, stored) ? sameRecord(current, stored) : await this.putAppIfUnchanged(app, stored);
12510
+ for (const files of [...dropped, ...!put && wrote ? [wrote] : []]) await this.removeUnusedBundle(app.ref, files.bytes, files.digest);
12511
+ if (!put) return null;
12512
+ return {
12513
+ ref: app.ref,
12514
+ outcome,
12515
+ run: await this.runCheckOf(app, stores)
12516
+ };
12418
12517
  }
12419
12518
  /**
12420
12519
  * Fetches an installed app's bundle again when it is not on this device (a profile restored from a backup, which
@@ -13190,6 +13289,20 @@ function cleanNames(record) {
13190
13289
  })) } : {}
13191
13290
  };
13192
13291
  }
13292
+ /**
13293
+ * When each fork the record lists was kept (`forkKeptAt`): only a listed fork's, only a time a date holds. A fork kept
13294
+ * before the time was written has none, and anything else in the field is taken as no time: it only tells rows apart.
13295
+ */
13296
+ function forkTimes(record) {
13297
+ const kept = record.forkKeptAt;
13298
+ if (!kept || typeof kept !== "object" || Array.isArray(kept)) return {};
13299
+ const times = {};
13300
+ for (const fork of record.forks ?? []) {
13301
+ const at = Object.prototype.hasOwnProperty.call(kept, fork) ? kept[fork] : void 0;
13302
+ if (count(at, 864e13)) times[fork] = at;
13303
+ }
13304
+ return times;
13305
+ }
13193
13306
  function checked(record) {
13194
13307
  return parseDeviceRecord(record);
13195
13308
  }
@@ -17040,7 +17153,10 @@ function deviceSetView(record, links) {
17040
17153
  ...record.state === "active" && record.earlierSets.some((set) => set.foreign) ? { foreignSet: true } : {},
17041
17154
  ...record.setNotice && !record.setNotice.seen ? { notice: record.setNotice.names } : {},
17042
17155
  ...record.reenroll ? { reenroll: true } : {},
17043
- ...record.state === "active" && record.forks?.length ? { forks: [...record.forks] } : {}
17156
+ ...record.state === "active" && record.forks?.length ? {
17157
+ forks: [...record.forks],
17158
+ forkKeptAt: forkTimes(record)
17159
+ } : {}
17044
17160
  };
17045
17161
  }
17046
17162
  /**
@@ -17054,6 +17170,10 @@ function handoffNotices(was, handoff, session) {
17054
17170
  if (handoff && session && was.session && session !== was.session) return [false, true];
17055
17171
  return [];
17056
17172
  }
17173
+ /** The record lists the device on this link, under the link's own secret (the current set's). */
17174
+ function listedOn(record, running) {
17175
+ return !!record && record.d === running.d && record.deviceSet.some((slot) => slot?.key === running.key);
17176
+ }
17057
17177
  /**
17058
17178
  * A native transport of a device link that did not start (a relay that did not answer) or went away (the relay closed
17059
17179
  * the connection) is started again after this long, then twice as long each time, up to `NATIVE_RETRY_MAX_MS`. A
@@ -17078,6 +17198,7 @@ var SET_ACK_FLUSH_MS = 1500;
17078
17198
  * removal's tombstone hides it.
17079
17199
  */
17080
17200
  var DEVICE_TURN_HINT = "device-turn";
17201
+ var TURN_HINT_EVERY_MS = 3e4;
17081
17202
  var defaultPeerConnection = () => typeof RTCPeerConnection === "undefined" ? void 0 : () => new RTCPeerConnection({ iceServers: RTC_CONFIG.iceServers });
17082
17203
  var DeviceLinks = class {
17083
17204
  options;
@@ -17099,6 +17220,8 @@ var DeviceLinks = class {
17099
17220
  lastHintRead = 0;
17100
17221
  /** When a link closing by the other side's doing last made this standby read the turn (`linkLost`). */
17101
17222
  lastLossRead = 0;
17223
+ /** A hint came inside `TURN_HINT_EVERY_MS` of the last read, and a read is due at its end. */
17224
+ hintDeferred = false;
17102
17225
  timers = /* @__PURE__ */ new Set();
17103
17226
  constructor(options) {
17104
17227
  this.options = options;
@@ -17129,12 +17252,16 @@ var DeviceLinks = class {
17129
17252
  this.checkAndShow().catch(() => null).finally(() => this.watchTurn(STANDBY_TURN_EVERY_MS + Math.floor(Math.random() * STANDBY_TURN_JITTER_MS)));
17130
17253
  }, after);
17131
17254
  }
17132
- /** Reads the turn and, when the device's state or the device it believes changed, tells the pages. */
17255
+ /** Reads the turn and, when the device's state, the device it believes or a name in the set changed, tells the pages. */
17133
17256
  async checkAndShow() {
17134
17257
  const before = await this.record().catch(() => null);
17135
17258
  const outcome = await this.checkTurn();
17136
17259
  const now = await this.record().catch(() => null);
17137
- if (now && before && (now.state !== before.state || now.activeSlot !== before.activeSlot || now.d !== before.d || now.reenroll !== before.reenroll)) this.host?.show(viewOf(now));
17260
+ const names = (record) => record.deviceSet.map((slot) => slot?.name ?? "").join("\n");
17261
+ if (now && before && (now.state !== before.state || now.activeSlot !== before.activeSlot || now.d !== before.d || now.reenroll !== before.reenroll || names(now) !== names(before))) {
17262
+ this.host?.show(viewOf(now));
17263
+ if (names(now) !== names(before)) this.changed();
17264
+ }
17138
17265
  return outcome;
17139
17266
  }
17140
17267
  /** The frames still pending go again on every old link that is live now (the hourly run: a refusal for a passing reason is retried). */
@@ -17504,29 +17631,45 @@ var DeviceLinks = class {
17504
17631
  }
17505
17632
  /** Asks the device with this signing key to make a new subscription. False when its link is not live (ask again later). */
17506
17633
  askRenew(key) {
17507
- const running = this.find(key);
17508
- if (!running || running.earlier || !this.isLive(running)) return false;
17509
- try {
17510
- running.link.sendDeviceFrame({ t: DEVICE_RENEW_FRAME });
17511
- return true;
17512
- } catch {
17513
- return false;
17514
- }
17634
+ return this.sendListed(key, { t: DEVICE_RENEW_FRAME });
17515
17635
  }
17516
17636
  /** Tells the device with this signing key which chats' tokens are handed out under the profile's subscription. */
17517
17637
  sendTokens(key, tokens) {
17638
+ return this.sendListed(key, {
17639
+ t: DEVICE_TOKENS_FRAME,
17640
+ k: tokens
17641
+ });
17642
+ }
17643
+ /**
17644
+ * A push frame for the device on its current link, only while the record lists it under that link's secret: a
17645
+ * removal stores the record before the links follow it, and a removed device is told nothing meanwhile.
17646
+ */
17647
+ async sendListed(key, frame) {
17518
17648
  const running = this.find(key);
17519
17649
  if (!running || running.earlier || !this.isLive(running)) return false;
17650
+ if (!listedOn(await this.record().catch(() => null), running)) return false;
17520
17651
  try {
17521
- running.link.sendDeviceFrame({
17522
- t: DEVICE_TOKENS_FRAME,
17523
- k: tokens
17524
- });
17652
+ running.link.sendDeviceFrame(frame);
17525
17653
  return true;
17526
17654
  } catch {
17527
17655
  return false;
17528
17656
  }
17529
17657
  }
17658
+ /**
17659
+ * The active device wrote a record the other devices should read now (a rename, `rename.ts`): the turn hint goes
17660
+ * over each live link under the current secret, as at the start of every session. The number of devices told.
17661
+ */
17662
+ hintTurn() {
17663
+ let told = 0;
17664
+ for (const running of this.running.values()) {
17665
+ if (running.earlier || !this.isLive(running)) continue;
17666
+ try {
17667
+ running.link.sendDeviceFrame({ t: DEVICE_TURN_HINT });
17668
+ told++;
17669
+ } catch {}
17670
+ }
17671
+ return told;
17672
+ }
17530
17673
  pushQueue = Promise.resolve();
17531
17674
  /** The record's push fields are changed one at a time: two frames at once must not write over each other. */
17532
17675
  pushExclusive(work) {
@@ -17534,16 +17677,20 @@ var DeviceLinks = class {
17534
17677
  this.pushQueue = run;
17535
17678
  return run;
17536
17679
  }
17537
- /** Another device shared its push target, or said it has none: kept here, and the engine told. A malformed frame says nothing. */
17680
+ /**
17681
+ * Another device shared its push target, or said it has none: kept here, and the engine told. A malformed frame says
17682
+ * nothing, and neither does a device the set does not list (one removed, whose link runs until the links follow).
17683
+ */
17538
17684
  async deviceWake(from, frame) {
17539
17685
  const target = readDeviceWake(frame);
17540
17686
  if (target === void 0) return;
17541
- await this.pushExclusive(async () => {
17687
+ if (!await this.pushExclusive(async () => {
17542
17688
  const record = await this.record();
17543
- if (!record || !record.deviceSet.some((slot) => slot?.key === from)) return;
17689
+ if (!record || !record.deviceSet.some((slot) => slot?.key === from)) return false;
17544
17690
  const patch = withOtherPush(record, from, target);
17545
17691
  if (patch) await amendDevice(this.options.profile, patch);
17546
- });
17692
+ return true;
17693
+ })) return;
17547
17694
  try {
17548
17695
  await this.options.onDeviceWake?.(from, target);
17549
17696
  } catch {}
@@ -17552,7 +17699,7 @@ var DeviceLinks = class {
17552
17699
  async shareOwnPush(running) {
17553
17700
  const target = await this.pushExclusive(async () => {
17554
17701
  const record = await this.record();
17555
- if (!record) return void 0;
17702
+ if (!record || !listedOn(record, running)) return void 0;
17556
17703
  const { target, patch } = ownTargetFor(record, running.key);
17557
17704
  if (patch) await amendDevice(this.options.profile, patch);
17558
17705
  return target;
@@ -17635,11 +17782,23 @@ var DeviceLinks = class {
17635
17782
  await this.acked(running.key);
17636
17783
  }
17637
17784
  /**
17638
- * A hint from another device that it holds the turn: read it, at most once in `TURN_HINT_EVERY_MS`. On the active
17639
- * device the engine reads it (`onActiveHint`): it stops itself when another device took over.
17785
+ * A hint from another device that it holds the turn: read it, at most once in `TURN_HINT_EVERY_MS`. A hint inside
17786
+ * that time is not dropped: one read follows at its end (the active device renamed a device just after this session
17787
+ * opened, and its record is news). On the active device the engine reads it (`onActiveHint`): it stops itself when
17788
+ * another device took over.
17640
17789
  */
17641
17790
  async hinted() {
17642
- if (Date.now() - this.lastHintRead < 3e4) return;
17791
+ const wait = this.lastHintRead + TURN_HINT_EVERY_MS - Date.now();
17792
+ if (wait > 0) {
17793
+ if (!this.hintDeferred) {
17794
+ this.hintDeferred = true;
17795
+ this.later(wait, () => {
17796
+ this.hintDeferred = false;
17797
+ this.hinted().catch(() => {});
17798
+ });
17799
+ }
17800
+ return;
17801
+ }
17643
17802
  const record = await this.record();
17644
17803
  if (record?.state === "active") {
17645
17804
  this.lastHintRead = Date.now();
@@ -18167,6 +18326,23 @@ function fileParts(files) {
18167
18326
  ]);
18168
18327
  return [...byDigest.values()];
18169
18328
  }
18329
+ /**
18330
+ * The most files a standby's record lists as held (`heldFiles`). The list goes into the device record, which Desktop
18331
+ * also keeps in a file of at most 4 MiB (`device_state.rs`) and which every read parses: one entry per file made a
18332
+ * profile of some 35,000 files unable to write `standby`, so its move failed at the very end. A file not listed is
18333
+ * only sent again by a later pull.
18334
+ */
18335
+ var MAX_HELD_FILES = 1e4;
18336
+ /** What the frozen copy holds, for the record: one file per digest (one copy is enough to copy from), the largest first. */
18337
+ function heldFilesOf(files) {
18338
+ const byDigest = /* @__PURE__ */ new Map();
18339
+ for (const file of files) if (!byDigest.has(file.sha256)) byDigest.set(file.sha256, {
18340
+ sha256: file.sha256,
18341
+ size: file.size,
18342
+ id: file.id
18343
+ });
18344
+ return [...byDigest.values()].sort((a, b) => b.size - a.size).slice(0, MAX_HELD_FILES);
18345
+ }
18170
18346
  /** Which file ids each digest is. */
18171
18347
  function idsOf(files) {
18172
18348
  const ids = {};
@@ -18885,11 +19061,7 @@ var HandoffGiver = class {
18885
19061
  h: toBase64Url(h),
18886
19062
  s: toBase64Url(signed.signature)
18887
19063
  };
18888
- const heldFiles = this.allFiles.map((file) => ({
18889
- sha256: file.sha256,
18890
- size: file.size,
18891
- id: file.id
18892
- }));
19064
+ const heldFiles = heldFilesOf(this.allFiles);
18893
19065
  const leftFiles = this.allFiles.filter((file) => later.has(file.sha256)).map((file) => ({
18894
19066
  sha256: file.sha256,
18895
19067
  size: file.size,
@@ -19105,6 +19277,73 @@ function handoffLinks(links) {
19105
19277
  };
19106
19278
  }
19107
19279
  //#endregion
19280
+ //#region ../browser/src/devices/rename.ts
19281
+ /** Why a rename was refused before anything was written. Its message starts with `rename-<reason>:`. */
19282
+ var RenameRefusal = class extends Error {
19283
+ reason;
19284
+ constructor(reason, message) {
19285
+ super(`rename-${reason}: ${message}`);
19286
+ this.reason = reason;
19287
+ this.name = "RenameRefusal";
19288
+ }
19289
+ };
19290
+ /**
19291
+ * The name a rename writes: trimmed, and otherwise exactly what the slot keeps (`turnName`). One the slot would change
19292
+ * is refused rather than cut or cleaned behind the person's back: empty or invisible, over 16 bytes of UTF-8, or with a
19293
+ * control, invisible or direction-changing character in it.
19294
+ */
19295
+ function renamedDeviceName(name) {
19296
+ if (typeof name !== "string") throw new RenameRefusal("name", "Give the device a name.");
19297
+ const typed = name.trim();
19298
+ const kept = turnName(typed);
19299
+ if (!kept) throw new RenameRefusal("name", "Give the device a name.");
19300
+ if (kept === typed) return kept;
19301
+ if (utf8Encode(typed).length > 16) throw new RenameRefusal("long", `A device name holds at most 16 bytes.`);
19302
+ throw new RenameRefusal("name", "A device name cannot hold this character.");
19303
+ }
19304
+ /**
19305
+ * Renames a device of the set on the active device. Reads the turn first, as an enrollment does before it writes the
19306
+ * new slot: on `mine`, `none` or `behind` it writes the next record with the new name; anything else (another device
19307
+ * took the turn) is refused, and the keeper does what this device's state asks for. False when the name is the one
19308
+ * the slot already holds (nothing is written).
19309
+ */
19310
+ async function renameDevice(options) {
19311
+ const read = options.read ?? (() => readDeviceRecord(options.profile));
19312
+ const name = renamedDeviceName(options.name);
19313
+ const before = await read();
19314
+ if (!before || before.state !== "active" || before.ownSlot === void 0) throw new RenameRefusal("state", "Only the active device renames a device.");
19315
+ const index = before.deviceSet.findIndex((slot) => slot?.key === options.key);
19316
+ if (index < 0) throw new RenameRefusal("device", "That device is not in this profile.");
19317
+ if (before.deviceSet[index].name === name) return false;
19318
+ const turn = await options.keeper.read();
19319
+ if (!turn?.good) throw new RenameRefusal("unreachable", "Can't check which device is active. Try again.");
19320
+ if (turn.result !== "mine" && turn.result !== "none" && turn.result !== "behind") {
19321
+ await options.keeper.check(false).catch(() => null);
19322
+ throw new RenameRefusal("replaced", "Another device holds the profile now.");
19323
+ }
19324
+ const record = await read();
19325
+ if (!record || record.state !== "active") throw new RenameRefusal("state", "Only the active device renames a device.");
19326
+ const at = record.deviceSet.findIndex((slot) => slot?.key === options.key);
19327
+ if (at < 0) throw new RenameRefusal("device", "That device is not in this profile.");
19328
+ const old = record.deviceSet[at].name;
19329
+ const slots = Array.from({ length: 4 }, (_, i) => {
19330
+ const slot = record.deviceSet[i] ?? null;
19331
+ return slot && i === at ? {
19332
+ ...slot,
19333
+ name
19334
+ } : slot;
19335
+ });
19336
+ const offer = record.secretOffer?.device === old ? { secretOffer: {
19337
+ ...record.secretOffer,
19338
+ device: name
19339
+ } } : {};
19340
+ await options.keeper.write(turn.conditions, {
19341
+ slots,
19342
+ patch: offer
19343
+ });
19344
+ return true;
19345
+ }
19346
+ //#endregion
19108
19347
  //#region ../browser/src/devices/handoffWallets.ts
19109
19348
  /** Wallet types the owner let move on Mainnet (WISP 06 § Decisions, "Mainnet money"). None yet: Testnet first. */
19110
19349
  var MAINNET_MOVES = /* @__PURE__ */ new Set();
@@ -23645,6 +23884,14 @@ var LOBBY_CHECK_MS = 2e3;
23645
23884
  var LOBBY_CHECK_JITTER_MS = 3e3;
23646
23885
  var REFUSED_FOR_MS$1 = 6e5;
23647
23886
  var ENTRY_LINGER_MS$1 = 2e4;
23887
+ /**
23888
+ * A full community's door answers a knock with `group-full` (WISP 903 § A full community): the same joiner at most this
23889
+ * often while it stays full, its side of the entry session closed `FULL_LINGER_MS` after. The joiner shows it is full
23890
+ * for `FULL_SAID_MS` after the last one (one answer missed included), then waits as before.
23891
+ */
23892
+ var FULL_TELL_MS = 3e5;
23893
+ var FULL_LINGER_MS = 5e3;
23894
+ var FULL_SAID_MS = 66e4;
23648
23895
  var RELAYED_KEPT = 4096;
23649
23896
  /**
23650
23897
  * Someone the chain took out while its app was closed comes back believing it is a member: it asks in a hub's lobby,
@@ -23719,6 +23966,8 @@ var Communities = class {
23719
23966
  knockAt = /* @__PURE__ */ new Map();
23720
23967
  /** Joiners: how many others had a knock still being refreshed in the record I last read (they wait with me). */
23721
23968
  knockingWith = /* @__PURE__ */ new Map();
23969
+ /** Joiners: the last `group-full` a member's app answered with, and when. */
23970
+ toldFull = /* @__PURE__ */ new Map();
23722
23971
  /** Since when this run knocks with nobody answering (`JOIN_GIVE_UP_MS`), and the joins it gave up (`Groups.giveUpJoin`). */
23723
23972
  knockingSince = /* @__PURE__ */ new Map();
23724
23973
  gaveUp = /* @__PURE__ */ new Set();
@@ -23862,8 +24111,10 @@ var Communities = class {
23862
24111
  viaLink: true,
23863
24112
  stage: this.joinStage(group),
23864
24113
  since: group.joining.since,
24114
+ ...!group.joining.inviter && this.fullSaid(group.id) && { full: this.fullSaid(group.id) },
23865
24115
  ...this.knockingWith.get(group.id) ? { waiting: this.knockingWith.get(group.id) } : {},
23866
- ...this.gaveUp.has(group.id) && { unanswered: true }
24116
+ ...this.gaveUp.has(group.id) && { unanswered: true },
24117
+ ...group.joining.inviter && group.joining.invitedAt && { admittedAt: group.joining.invitedAt }
23867
24118
  } : void 0;
23868
24119
  if (invitation && !this.keptWhileKnocking(live)) return [{
23869
24120
  ...base,
@@ -23921,9 +24172,18 @@ var Communities = class {
23921
24172
  const joining = group.joining;
23922
24173
  if (joining.replaced) return "replaced";
23923
24174
  if (joining.inviter) return "admitted";
24175
+ if (this.fullSaid(group.id)) return "full";
23924
24176
  if (this.host.linkReady(joining.linkId, 2) || this.host.linkSeen?.(joining.linkId)) return "answered";
23925
24177
  return this.knocked.has(group.id) ? "knocked" : "knocking";
23926
24178
  }
24179
+ /** A member's app said lately that the community is full (`group-full`): how full, as it said. */
24180
+ fullSaid(groupId) {
24181
+ const told = this.toldFull.get(groupId);
24182
+ return told && this.now() - told.at < FULL_SAID_MS ? {
24183
+ n: told.n,
24184
+ max: told.max
24185
+ } : void 0;
24186
+ }
23927
24187
  async create(name) {
23928
24188
  const state = CommunitySession.create(name);
23929
24189
  const group = {
@@ -23988,6 +24248,7 @@ var Communities = class {
23988
24248
  this.knockRead.delete(link.g);
23989
24249
  this.knockingSince.delete(link.g);
23990
24250
  this.gaveUp.delete(link.g);
24251
+ this.toldFull.delete(link.g);
23991
24252
  const before = this.stored.get(link.g)?.joining;
23992
24253
  const linkId = await this.host.openEntry(link, "guest", seedB64, link.host);
23993
24254
  if (before && before.linkId !== linkId) await this.host.closeEdge(before.linkId);
@@ -25008,7 +25269,9 @@ var Communities = class {
25008
25269
  }
25009
25270
  async answerKnocks(groupId, live, now, busy) {
25010
25271
  const s = live.session;
25011
- if (!s.adminWork || !s.entryKey || !s.state.entry.seedB64 || s.roster.length >= COMMUNITY_LIMITS.members) return;
25272
+ if (!s.adminWork || !s.entryKey || !s.state.entry.seedB64) return;
25273
+ const full = s.roster.length >= COMMUNITY_LIMITS.members;
25274
+ for (const [key, at] of live.fullTold) if (now - at >= FULL_TELL_MS) live.fullTold.delete(key);
25012
25275
  const link = {
25013
25276
  g: groupId,
25014
25277
  host: s.entryKey
@@ -25053,7 +25316,7 @@ var Communities = class {
25053
25316
  const stillKnocking = now - ts < 2 * this.timings.slowKnockMs;
25054
25317
  if (rosterHas(s.roster, key)) {
25055
25318
  if (!stillKnocking || ts < this.addedAt(s, key) + this.timings.knockFallbackMs) continue;
25056
- }
25319
+ } else if (full && (door !== s.myKey || live.fullTold.has(key))) continue;
25057
25320
  const seen = live.knocksSeen.get(key);
25058
25321
  const changed = !!seen && seen.doors !== doorSig;
25059
25322
  const first = seen && !changed ? seen.first : now;
@@ -25190,6 +25453,23 @@ var Communities = class {
25190
25453
  entryReady(groupId, linkId, peer) {
25191
25454
  const live = this.live.get(groupId);
25192
25455
  if (!live?.pendingEntries.has(peer) || !live.session.isMember) return false;
25456
+ const s = live.session, now = this.now();
25457
+ if (s.roster.length >= COMMUNITY_LIMITS.members && !rosterHas(s.roster, peer)) {
25458
+ try {
25459
+ this.host.sendOnLink(linkId, {
25460
+ t: "group-full",
25461
+ v: 2,
25462
+ g: groupId,
25463
+ n: s.roster.length,
25464
+ max: COMMUNITY_LIMITS.members
25465
+ });
25466
+ traceJoin(groupId, "full.sent");
25467
+ } catch {}
25468
+ live.pendingEntries.delete(peer);
25469
+ live.fullTold.set(peer, now);
25470
+ live.lingering.set(linkId, now + FULL_LINGER_MS);
25471
+ return true;
25472
+ }
25193
25473
  try {
25194
25474
  this.host.sendOnLink(linkId, live.session.inviteFrame());
25195
25475
  traceJoin(groupId, "invite.sent");
@@ -25208,6 +25488,7 @@ var Communities = class {
25208
25488
  if (joining.inviter && joining.inviter !== frame.admin && this.now() - (joining.invitedAt ?? 0) < ENTRY_LINGER_MS$1) return;
25209
25489
  joining.invitedAt = this.now();
25210
25490
  joining.inviter = frame.admin;
25491
+ this.toldFull.delete(g);
25211
25492
  joining.name = groupName(frame.name) ?? joining.name;
25212
25493
  joining.pieces = [];
25213
25494
  traceJoin(g, "invite.received");
@@ -25221,6 +25502,18 @@ var Communities = class {
25221
25502
  this.host.emit();
25222
25503
  return;
25223
25504
  }
25505
+ case "group-full": {
25506
+ const joining = group.joining, { n, max } = frame;
25507
+ if (!joining || joining.linkId !== linkId || joining.inviter || !Number.isSafeInteger(n) || !Number.isSafeInteger(max) || max < 1 || n < 0) return;
25508
+ this.toldFull.set(g, {
25509
+ n,
25510
+ max,
25511
+ at: this.now()
25512
+ });
25513
+ traceJoin(g, "full.received");
25514
+ this.host.emit();
25515
+ return;
25516
+ }
25224
25517
  case "group-accept": {
25225
25518
  const live = this.live.get(g);
25226
25519
  const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
@@ -25533,6 +25826,7 @@ var Communities = class {
25533
25826
  lobbyWrites: /* @__PURE__ */ new Map(),
25534
25827
  lastKnockPoll: 0,
25535
25828
  pendingEntries: /* @__PURE__ */ new Map(),
25829
+ fullTold: /* @__PURE__ */ new Map(),
25536
25830
  knocksSeen: /* @__PURE__ */ new Map(),
25537
25831
  hubWaits: /* @__PURE__ */ new Map(),
25538
25832
  hubsAvoided: /* @__PURE__ */ new Map(),
@@ -25558,6 +25852,7 @@ var Communities = class {
25558
25852
  admittedAt: 0,
25559
25853
  lastRearm: 0,
25560
25854
  lastRoster: session.roster,
25855
+ forkDropped: /* @__PURE__ */ new Set(),
25561
25856
  lastStatus: session.status,
25562
25857
  relayed: /* @__PURE__ */ new Set()
25563
25858
  });
@@ -25574,15 +25869,19 @@ var Communities = class {
25574
25869
  else if (statusChanged && s.status === "forked") await this.event(groupId, "forked", s.state.statusReason ?? "The membership history forked", when, s.epoch);
25575
25870
  else if (s.status === "active" && before !== after) {
25576
25871
  const at = receivedTimestamp(top.ts, when);
25577
- for (const [key] of after) if (!rosterHas(before, key) && key !== s.myKey) await this.event(groupId, "joined", `${name(key)} joined`, at, top.e, key);
25578
- const left = (key) => {
25872
+ for (const [key] of after) {
25873
+ if (rosterHas(before, key) || key === s.myKey || live.forkDropped.delete(key)) continue;
25874
+ await this.event(groupId, "joined", `${name(key)} joined`, at, top.e, key);
25875
+ }
25876
+ const out = (key) => {
25579
25877
  const chain = s.state.chain;
25580
- for (let i = chain.length - 1; i >= 0; i--) if ((chain[i].k === "remove" || chain[i].k === "leave") && chain[i].s === key) return chain[i].k === "leave";
25581
- return false;
25878
+ for (let i = chain.length - 1; i >= 0; i--) if ((chain[i].k === "remove" || chain[i].k === "leave") && chain[i].s === key) return chain[i].k;
25582
25879
  };
25583
25880
  for (const [key] of before) {
25584
25881
  if (rosterHas(after, key)) continue;
25585
- if (left(key)) await this.event(groupId, "left", `${name(key)} left`, at, top.e, key);
25882
+ const k = out(key);
25883
+ if (!k) live.forkDropped.add(key);
25884
+ else if (k === "leave") await this.event(groupId, "left", `${name(key)} left`, at, top.e, key);
25586
25885
  else await this.event(groupId, "gone", `${name(key)} is no longer a member`, at, top.e, key);
25587
25886
  }
25588
25887
  if (top.k === "role" && before.find(([k]) => k === top.s)?.[1] !== "admin") await this.event(groupId, "admin", `${name(top.s)} ${top.s === s.myKey ? "are" : "is"} now the admin`, at, top.e, top.s);
@@ -25629,6 +25928,8 @@ var MESH_HUB_TIMINGS = {
25629
25928
  };
25630
25929
  /** A hub says whom it reaches this often even when nothing changed: members that cannot read the beacon learn it is one. */
25631
25930
  var REACH_AGAIN_MS = 6e4;
25931
+ /** A member's `group-reach` is taken at most this often (a hub says it at most every `reachEveryMs`, and once to an edge that opens). */
25932
+ var REACH_HEARD_MS = 1e3;
25632
25933
  /** Signed reactions a hub keeps to say again to a member whose edge opens. */
25633
25934
  var REACTIONS_KEPT = 64;
25634
25935
  /** How long the edge to a member a commit took out stays, for that commit to reach it. */
@@ -25712,7 +26013,11 @@ var MeshHubs = class {
25712
26013
  avoided: /* @__PURE__ */ new Map(),
25713
26014
  hubsUp: /* @__PURE__ */ new Set(),
25714
26015
  seenHubs: /* @__PURE__ */ new Map(),
26016
+ claimed: /* @__PURE__ */ new Map(),
25715
26017
  reach: /* @__PURE__ */ new Map(),
26018
+ reachLegacy: /* @__PURE__ */ new Map(),
26019
+ reachHeard: /* @__PURE__ */ new Map(),
26020
+ takesHubs: /* @__PURE__ */ new Set(),
25716
26021
  sentReach: "",
25717
26022
  lastReach: 0,
25718
26023
  met: /* @__PURE__ */ new Map(),
@@ -25776,6 +26081,9 @@ var MeshHubs = class {
25776
26081
  const policy = session.hubPolicy, inRoster = (key) => rosterHas(session.roster, key);
25777
26082
  const out = new Set(this.listed(live, session, now).map((h) => h.key));
25778
26083
  for (const [key, at] of live.seenHubs) if (now - at <= this.timings.graceMs && key !== session.myKey && inRoster(key) && !policy.no.includes(key) && !live.departed.has(key)) out.add(key);
26084
+ if (!live.epochRead) {
26085
+ for (const [key, at] of live.claimed) if (now - at <= this.timings.graceMs && inRoster(key) && !policy.no.includes(key) && !live.departed.has(key)) out.add(key);
26086
+ }
25779
26087
  return [...out];
25780
26088
  }
25781
26089
  /** The beacon's hubs a member counts on (`meshHubs`), but those that said they leave. */
@@ -25792,6 +26100,8 @@ var MeshHubs = class {
25792
26100
  live.departed.add(key);
25793
26101
  const was = live.seenHubs.delete(key) || live.myHubs.includes(key) || live.beacon.some((h) => h.key === key);
25794
26102
  live.reach.delete(key);
26103
+ live.reachLegacy.delete(key);
26104
+ live.claimed.delete(key);
25795
26105
  live.hubsUp.delete(key);
25796
26106
  live.myHubs = live.myHubs.filter((k) => k !== key);
25797
26107
  return was;
@@ -25837,7 +26147,7 @@ var MeshHubs = class {
25837
26147
  const out = /* @__PURE__ */ new Set();
25838
26148
  for (const [key, until] of live.met) if (until > now) out.add(key);
25839
26149
  else live.met.delete(key);
25840
- const legacy = (group.legacy ?? []).filter((key) => rosterHas(session.roster, key));
26150
+ const legacy = this.legacy(groupId, session, group, live, now);
25841
26151
  if (!live.firstRead && now - live.started < this.timings.firstReadMs) for (const key of [...this.host.edges(groupId).keys(), ...group.hubs ?? []]) out.add(key);
25842
26152
  else {
25843
26153
  const hubs = this.hubs(groupId, session, now);
@@ -25866,6 +26176,20 @@ var MeshHubs = class {
25866
26176
  else if (edges.has(key)) out.add(key);
25867
26177
  return out;
25868
26178
  }
26179
+ /**
26180
+ * The members whose apps take no hubs: those whose own edge here said so (`edgeReady`, kept in `group`), and those a
26181
+ * hub of the beacon I still count on says so of its own edges, unless their own edge here said otherwise.
26182
+ */
26183
+ legacy(groupId, session, group, live, now) {
26184
+ const out = new Set(group.legacy ?? []);
26185
+ if (live.reachLegacy.size) {
26186
+ const hubs = new Set(this.hubs(groupId, session, now));
26187
+ for (const [hub, keys] of live.reachLegacy) if (hubs.has(hub)) {
26188
+ for (const key of keys) if (!live.takesHubs.has(key)) out.add(key);
26189
+ }
26190
+ }
26191
+ return [...out].filter((key) => rosterHas(session.roster, key));
26192
+ }
25869
26193
  /** Edges this member keeps in a group: what paces them (`meshEdgeIntervals`), not the roster. */
25870
26194
  edgeLoad(groupId, session) {
25871
26195
  const live = this.live.get(groupId);
@@ -25952,7 +26276,7 @@ var MeshHubs = class {
25952
26276
  */
25953
26277
  counted(live, session, now) {
25954
26278
  const keys = new Set(this.listed(live, session, now).map((h) => h.key));
25955
- for (const [key, at] of live.seenHubs) if (now - at <= this.timings.graceMs && key !== session.myKey && rosterHas(session.roster, key) && !live.departed.has(key)) keys.add(key);
26279
+ for (const map of [live.seenHubs, live.claimed]) for (const [key, at] of map) if (now - at <= this.timings.graceMs && key !== session.myKey && rosterHas(session.roster, key) && !live.departed.has(key)) keys.add(key);
25956
26280
  return keys.size;
25957
26281
  }
25958
26282
  shape(live) {
@@ -25981,6 +26305,11 @@ var MeshHubs = class {
25981
26305
  }
25982
26306
  noteHubs(live, session, now) {
25983
26307
  for (const h of this.listed(live, session, now)) live.seenHubs.set(h.key, now);
26308
+ for (const [key, at] of live.claimed) if (live.beacon.some((h) => h.key === key)) live.claimed.delete(key);
26309
+ else {
26310
+ live.reach.delete(key);
26311
+ if (now - at > this.timings.graceMs || !rosterHas(session.roster, key)) live.claimed.delete(key);
26312
+ }
25984
26313
  for (const [key, at] of live.seenHubs) if (now - at > this.timings.graceMs || !rosterHas(session.roster, key)) live.seenHubs.delete(key);
25985
26314
  for (const key of live.departed) if (!rosterHas(session.roster, key)) live.departed.delete(key);
25986
26315
  }
@@ -26143,7 +26472,7 @@ var MeshHubs = class {
26143
26472
  live.sentReach = said;
26144
26473
  live.lastReach = now;
26145
26474
  }
26146
- const legacy = this.legacyOf(groupId);
26475
+ const legacy = this.legacyOf(groupId).filter((key) => up.includes(key));
26147
26476
  const frame = {
26148
26477
  t: "group-reach",
26149
26478
  g: groupId,
@@ -26174,6 +26503,10 @@ var MeshHubs = class {
26174
26503
  if (hubs && legacy.delete(key)) changed = true;
26175
26504
  if (changed) group.legacy = [...legacy].sort();
26176
26505
  const live = this.live.get(groupId);
26506
+ if (live) {
26507
+ if (hubs) live.takesHubs.add(key);
26508
+ else live.takesHubs.delete(key);
26509
+ }
26177
26510
  if (live?.hub && this.large(session)) {
26178
26511
  if (!this.hubs(groupId, session, now).includes(key)) live.members.set(key, now);
26179
26512
  this.sayReach(groupId, session, live, now, key);
@@ -26207,21 +26540,36 @@ var MeshHubs = class {
26207
26540
  } catch {}
26208
26541
  }
26209
26542
  }
26210
- /** What a hub says it reaches, and which members' apps take no hubs (kept, so a new hub serves them too). True when `group` changed. */
26211
- reached(groupId, session, group, from, frame, now) {
26212
- if (!rosterHas(session.roster, from) || !Array.isArray(frame.k) || frame.k.length > session.roster.length) return false;
26543
+ /**
26544
+ * What a hub says it reaches, and which members on its edges have apps that take no hubs. Taken from a hub of the
26545
+ * beacon as I read it (or seen there within `graceMs`); from another member, only that it says it is a hub (`claimed`),
26546
+ * and nothing it says of other members' apps. At most one
26547
+ * every `REACH_HEARD_MS` from a member. Nothing of it is saved: what a member's app takes, its own edge says (`edgeReady`).
26548
+ */
26549
+ reached(groupId, session, from, frame, now) {
26550
+ if (!rosterHas(session.roster, from) || from === session.myKey || !Array.isArray(frame.k) || frame.k.length > session.roster.length) return;
26213
26551
  const live = this.get(groupId, now);
26214
- live.reach.set(from, new Set(frame.k.filter((key) => typeof key === "string" && rosterHas(session.roster, key))));
26215
- if (!session.hubPolicy.no.includes(from) && from !== session.myKey && !live.departed.has(from)) live.seenHubs.set(from, now);
26216
- if (!Array.isArray(frame.l) || frame.l.length > session.roster.length) return false;
26217
- const legacy = new Set(group.legacy ?? []);
26218
- let changed = false;
26219
- for (const key of frame.l) if (typeof key === "string" && key !== session.myKey && rosterHas(session.roster, key) && !legacy.has(key)) {
26220
- legacy.add(key);
26221
- changed = true;
26552
+ if (now - (live.reachHeard.get(from) ?? -Infinity) < REACH_HEARD_MS) return;
26553
+ if (session.hubPolicy.no.includes(from) || live.departed.has(from)) return;
26554
+ const seen = live.seenHubs.get(from);
26555
+ const inBeacon = live.beacon.some((h) => h.key === from) || seen !== void 0 && now - seen <= this.timings.graceMs;
26556
+ live.reachHeard.set(from, now);
26557
+ for (const [key] of live.reachHeard) if (!rosterHas(session.roster, key)) live.reachHeard.delete(key);
26558
+ const reach = new Set(frame.k.filter((key) => typeof key === "string" && rosterHas(session.roster, key)));
26559
+ if (!inBeacon) {
26560
+ live.claimed.set(from, now);
26561
+ if (!live.epochRead) live.reach.set(from, reach);
26562
+ return;
26222
26563
  }
26223
- if (changed) group.legacy = [...legacy].sort();
26224
- return changed;
26564
+ live.reach.set(from, reach);
26565
+ live.seenHubs.set(from, now);
26566
+ if (!Array.isArray(frame.l) || frame.l.length > session.roster.length) {
26567
+ live.reachLegacy.delete(from);
26568
+ return;
26569
+ }
26570
+ const legacy = frame.l.filter((key) => typeof key === "string" && key !== session.myKey && reach.has(key) && !live.takesHubs.has(key));
26571
+ if (legacy.length) live.reachLegacy.set(from, new Set(legacy));
26572
+ else live.reachLegacy.delete(from);
26225
26573
  }
26226
26574
  /** A member I have no edge with is reachable through a hub whose edge to me is up and that says it reaches them. */
26227
26575
  viaHub(groupId, session, key, now) {
@@ -26883,6 +27231,19 @@ function invitationClaims(frame) {
26883
27231
  var FAREWELL_ANSWERS = 3;
26884
27232
  /** Commits sent to a removed member that was behind when it left, at most. */
26885
27233
  var FAREWELL_COMMITS = 64;
27234
+ /**
27235
+ * The commit of epoch `e` for a removed member, with no secret: with the admin's `left` mark on a removal of someone who
27236
+ * left on their own, or its app says that the admin removed them (WISP 902 § Admission and departure).
27237
+ */
27238
+ function farewellCommit(groupId, session, e) {
27239
+ const left = session.state.leftMarks?.[e];
27240
+ return {
27241
+ t: "group-commit",
27242
+ g: groupId,
27243
+ commit: session.state.chain[e],
27244
+ ...left ? { left } : {}
27245
+ };
27246
+ }
26886
27247
  /** Where a member's gossip turns start among the members it is connected to: a number of its own, from its key. */
26887
27248
  var gossipStart = (key) => {
26888
27249
  let n = 0;
@@ -27869,17 +28230,13 @@ var Groups = class {
27869
28230
  * where it is in its sync, and gets the commits between (`farewellSync`). No secret goes with any of them.
27870
28231
  */
27871
28232
  sayFarewell(groupId, session, group, key, linkId) {
27872
- const farewell = group.farewells[key], commit = session.state.chain[farewell.e];
27873
- if (!commit) {
28233
+ const farewell = group.farewells[key];
28234
+ if (!session.state.chain[farewell.e]) {
27874
28235
  this.dropFarewell(group, key);
27875
28236
  return;
27876
28237
  }
27877
28238
  try {
27878
- this.host.sendOnLink(linkId, {
27879
- t: "group-commit",
27880
- g: groupId,
27881
- commit
27882
- });
28239
+ this.host.sendOnLink(linkId, farewellCommit(groupId, session, farewell.e));
27883
28240
  } catch {
27884
28241
  return;
27885
28242
  }
@@ -27894,14 +28251,7 @@ var Groups = class {
27894
28251
  if ((farewell.answered ?? 0) >= FAREWELL_ANSWERS) return;
27895
28252
  farewell.answered = (farewell.answered ?? 0) + 1;
27896
28253
  try {
27897
- for (let e = Math.max(from + 1, farewell.e - FAREWELL_COMMITS); e <= farewell.e; e++) {
27898
- const commit = session.state.chain[e];
27899
- if (commit) this.host.sendOnLink(linkId, {
27900
- t: "group-commit",
27901
- g: groupId,
27902
- commit
27903
- });
27904
- }
28254
+ for (let e = Math.max(from + 1, farewell.e - FAREWELL_COMMITS); e <= farewell.e; e++) if (session.state.chain[e]) this.host.sendOnLink(linkId, farewellCommit(groupId, session, e));
27905
28255
  } catch {}
27906
28256
  farewell.told ??= this.now();
27907
28257
  this.store.putGroup(group).catch(() => {});
@@ -28755,8 +29105,7 @@ var Groups = class {
28755
29105
  return;
28756
29106
  }
28757
29107
  if (session?.status === "active" && frame && typeof frame === "object" && frame.t === "group-reach") {
28758
- const group = this.stored.get(groupId);
28759
- if (group && this.hubs.enabled && this.hubs.reached(groupId, session, group, peerKey, frame, this.now())) await this.store.putGroup(group);
29108
+ if (this.hubs.enabled) this.hubs.reached(groupId, session, peerKey, frame, this.now());
28760
29109
  this.host.emit();
28761
29110
  return;
28762
29111
  }
@@ -30921,6 +31270,19 @@ var HiddenIpError = class extends Error {
30921
31270
  super(HOLD_HIDDEN_IP);
30922
31271
  }
30923
31272
  };
31273
+ /**
31274
+ * Where a person's own S3 storage is, as `S3Store` addresses it (path-style): its endpoint's origin and path, then its
31275
+ * bucket, ending in "/" so a bucket whose name starts with this one's ("bob", "bobby") is not under it.
31276
+ */
31277
+ function holdStoragePlace(s3) {
31278
+ const url = new URL(`${s3.endpoint.trim().replace(/\/+$/, "")}/${s3.bucket.trim()}/`);
31279
+ return `${url.origin}${url.pathname}`;
31280
+ }
31281
+ /** Whether an address is under a place: the same origin, and its (normalised) path inside the place's. */
31282
+ function underPlace(url, place) {
31283
+ const parsed = new URL(url);
31284
+ return `${parsed.origin}${parsed.pathname}`.startsWith(place);
31285
+ }
30924
31286
  var hex$2 = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
30925
31287
  /**
30926
31288
  * Store-and-forward for away contacts (WISP 404, `hold/1`), on both ends of every chat that turned it
@@ -31704,8 +32066,8 @@ var HoldEngine = class {
31704
32066
  }
31705
32067
  async readBytes(url, max, signal) {
31706
32068
  if (!isHoldUrl(url, this.host.loopbackStorage?.())) throw new Error("The storage address is not one this app reads");
31707
- const hosts = this.host.hiddenIpHosts?.();
31708
- if (hosts && !hosts.includes(new URL(url).host.toLowerCase())) throw new HiddenIpError();
32069
+ const places = this.host.hiddenIpPlaces?.();
32070
+ if (places && !places.some((place) => underPlace(url, place))) throw new HiddenIpError();
31709
32071
  const response = await (this.host.fetch ?? ((...args) => fetch(...args)))(url, {
31710
32072
  cache: "no-store",
31711
32073
  credentials: "omit",
@@ -37850,6 +38212,14 @@ var NATIVE_SLOTS = 8;
37850
38212
  * links listen there as well), and each of the CLI's is a whole DHT node.
37851
38213
  */
37852
38214
  var IROH_WEB_SLOTS = 16;
38215
+ /**
38216
+ * The same where none of its Iroh relays is n0's (a relay of the person's own, or Ghostly's): measured on a lab
38217
+ * `iroh-relay` 1.3, a Chromium page (phone-sized too) and the CLI each held 128 with none refused, started one after
38218
+ * another or all at once, at about 0.2 MiB and one WebSocket each, and the relay about 30 KiB each. Half of that:
38219
+ * Firefox opens 200 WebSockets at most, and a listener dialling a contact on another relay opens one more. 1:1 chats
38220
+ * hold half of them at most.
38221
+ */
38222
+ var IROH_WEB_OWN_RELAY_SLOTS = 64;
37853
38223
  /** Of a transport's listeners, the ones a group's links never hold: 1:1 chats keep that room. */
37854
38224
  var CHAT_NATIVE_SLOTS = 4;
37855
38225
  /** How often a group link that found no free native slot tries again, and the first wait of a listener that failed to start. */
@@ -38805,10 +39175,10 @@ var GhostlyNode = class GhostlyNode {
38805
39175
  changed: () => this.emitState(),
38806
39176
  fetch: (...request) => (this.options.holdFetch ?? globalThis.fetch)(...request),
38807
39177
  loopbackStorage: () => this.options.holdLoopback === true,
38808
- hiddenIpHosts: () => {
39178
+ hiddenIpPlaces: () => {
38809
39179
  if (this.settings.relayOnly !== true) return null;
38810
39180
  try {
38811
- return this.settings.holdStorage?.s3 ? [new URL(this.settings.holdStorage.s3.endpoint.trim()).host.toLowerCase()] : [];
39181
+ return this.settings.holdStorage?.s3 ? [holdStoragePlace(this.settings.holdStorage.s3)] : [];
38812
39182
  } catch {
38813
39183
  return [];
38814
39184
  }
@@ -40953,6 +41323,7 @@ var GhostlyNode = class GhostlyNode {
40953
41323
  */
40954
41324
  async deviceWakeReceived(from, target) {
40955
41325
  if (!this.ownDeviceKey || this.shuttingDown) return;
41326
+ if (!(await readDeviceRecord(databaseName()).catch(() => null))?.deviceSet.some((slot) => slot?.key === from)) return;
40956
41327
  const before = this.settings.wake;
40957
41328
  const asked = this.settings.wakeRenew?.[from];
40958
41329
  if (asked !== void 0 && (!target || target.endpoint !== asked)) {
@@ -41045,7 +41416,11 @@ var GhostlyNode = class GhostlyNode {
41045
41416
  this.renewAsked.delete(key);
41046
41417
  continue;
41047
41418
  }
41048
- if (!this.renewAsked.has(key) && links.askRenew(key)) this.renewAsked.add(key);
41419
+ if (this.renewAsked.has(key)) continue;
41420
+ this.renewAsked.add(key);
41421
+ links.askRenew(key).then((sent) => {
41422
+ if (!sent) this.renewAsked.delete(key);
41423
+ }, () => this.renewAsked.delete(key));
41049
41424
  }
41050
41425
  }
41051
41426
  /** What each device was last told of the chats' tokens, by its signing key. */
@@ -41067,7 +41442,15 @@ var GhostlyNode = class GhostlyNode {
41067
41442
  this.sentTokens.delete(view.key);
41068
41443
  continue;
41069
41444
  }
41070
- if (this.sentTokens.get(view.key) !== said && links.sendTokens(view.key, tokens)) this.sentTokens.set(view.key, said);
41445
+ if (this.sentTokens.get(view.key) === said) continue;
41446
+ const key = view.key;
41447
+ this.sentTokens.set(key, said);
41448
+ const unsent = () => {
41449
+ if (this.sentTokens.get(key) === said) this.sentTokens.delete(key);
41450
+ };
41451
+ links.sendTokens(key, tokens).then((sent) => {
41452
+ if (!sent) unsent();
41453
+ }, unsent);
41071
41454
  }
41072
41455
  }
41073
41456
  /**
@@ -43328,6 +43711,31 @@ var GhostlyNode = class GhostlyNode {
43328
43711
  await live.link.setTransportPreference(automaticTransport(live.link.availableTransports), true, true);
43329
43712
  this.capsChanged(linkId);
43330
43713
  }
43714
+ /**
43715
+ * A group's transport, chosen on this device (WISP 902 § Transports): Iroh or HyperDHT runs that one alone on the
43716
+ * group's edges, with no WebRTC, and each edge's `_tr` says so; WebRTC says `["webrtc/1"]`; `auto` is the rule every
43717
+ * edge had before. A member that chose otherwise, or whose app has no WebRTC, is met on a native transport, as
43718
+ * before. Each of the group's edges starts again on it (no goodbye); its entry sessions keep the rule.
43719
+ */
43720
+ async setGroupTransport({ groupId, transport }) {
43721
+ if (!this.groups.view(groupId)) throw new Error("Group not found");
43722
+ const runs = transport === "webrtc/1" ? typeof RTCPeerConnection !== "undefined" : transport !== "auto" && TRANSPORTS.includes(transport) && transport in this.nativeFactories;
43723
+ if (transport !== "auto" && !runs) throw new Error("Transport unavailable");
43724
+ if ((this.settings.groupTransports?.[groupId] ?? "auto") === transport) return;
43725
+ const { [groupId]: _, ...others } = this.settings.groupTransports ?? {};
43726
+ const next = transport === "auto" ? others : {
43727
+ ...others,
43728
+ [groupId]: transport
43729
+ };
43730
+ this.settings = {
43731
+ ...this.settings,
43732
+ groupTransports: next
43733
+ };
43734
+ if (!Object.keys(next).length) delete this.settings.groupTransports;
43735
+ await db.putSettings(this.settings);
43736
+ await Promise.all([...this.links.values()].filter((live) => live.stored.group === groupId && !live.stored.groupEntry && live.link).map((live) => this.restartEdge(live.stored.id)));
43737
+ this.emitState();
43738
+ }
43331
43739
  /** The chat's connection story, for paired chats (not group edges). */
43332
43740
  /**
43333
43741
  * The chat's ratchet (WISP 4xx), made once per chat: its keys are read from the chat's row when used (each start of
@@ -45313,6 +45721,8 @@ var GhostlyNode = class GhostlyNode {
45313
45721
  return this.settings.shareProfile === false ? void 0 : this.settings.avatar || void 0;
45314
45722
  }
45315
45723
  async updateSettings({ settings: patch }) {
45724
+ const wrongKind = settingsPatchProblem(patch);
45725
+ if (wrongKind) throw new Error(wrongKind);
45316
45726
  const { nostr, ...rest } = patch;
45317
45727
  const settings = rest;
45318
45728
  delete settings.backupReminders;
@@ -45353,6 +45763,7 @@ var GhostlyNode = class GhostlyNode {
45353
45763
  delete settings.wakeMutedGroups;
45354
45764
  delete settings.wakeHeldBy;
45355
45765
  delete settings.wakeRenew;
45766
+ delete settings.groupTransports;
45356
45767
  delete settings.walletSetup;
45357
45768
  const relayBefore = this.hyperdhtRelay;
45358
45769
  if (nostr) {
@@ -45731,15 +46142,18 @@ var GhostlyNode = class GhostlyNode {
45731
46142
  run();
45732
46143
  this.tombstoneTimer ??= setInterval(() => void run(), GhostlyNode.TOMBSTONE_EVERY_MS);
45733
46144
  }
45734
- /** Whether a move of the set may begin now: this device is active, online, and nothing else changes the set. */
45735
- setMoveAllowed() {
45736
- if (this.options.singleDevice) throw new Error("remove-state: A profile of the command line is on one device only");
46145
+ /**
46146
+ * Whether a move of the set (or a rename, `prefix` "rename") may begin now: this device is active, online, and nothing
46147
+ * else changes the set.
46148
+ */
46149
+ setMoveAllowed(prefix = "remove") {
46150
+ if (this.options.singleDevice) throw new Error(`${prefix}-state: A profile of the command line is on one device only`);
45737
46151
  if (this.limitedMode) throw new Error(LIMITED_MODE_ERROR);
45738
- if (!this.networkOn) throw new Error("remove-offline: You are offline");
46152
+ if (!this.networkOn) throw new Error(`${prefix}-offline: You are offline`);
45739
46153
  const view = this.enrollment?.current();
45740
- if (view && view.step !== "done" && view.step !== "failed") throw new Error("remove-busy: A device is being added. Try again after it.");
46154
+ if (view && view.step !== "done" && view.step !== "failed") throw new Error(`${prefix}-busy: A device is being added. Try again after it.`);
45741
46155
  const handoff = this.handoffGiver?.view();
45742
- if (handoff && handoff.step !== "failed") throw new Error("remove-busy: The profile is moving. Try again after it.");
46156
+ if (handoff && handoff.step !== "failed") throw new Error(`${prefix}-busy: The profile is moving. Try again after it.`);
45743
46157
  }
45744
46158
  async moveDeviceSet(remove) {
45745
46159
  this.setMoveAllowed();
@@ -45826,6 +46240,36 @@ var GhostlyNode = class GhostlyNode {
45826
46240
  if (typeof key !== "string" || !key) throw new Error("remove-device: Name the device to remove.");
45827
46241
  return this.moveDeviceSet(key);
45828
46242
  }
46243
+ /**
46244
+ * Rename (WISP 06 § User experience, the row menu): the active device writes its next record with the new name in
46245
+ * that device's slot (`devices/rename.ts`), and tells the devices on a live link to read it now. Only the active
46246
+ * device renames, any device of the set, itself included. Errors start with `rename-<reason>:`.
46247
+ */
46248
+ async deviceRename({ key, name }) {
46249
+ if (typeof key !== "string" || !key) throw new Error("rename-device: Name the device to rename.");
46250
+ const clean = renamedDeviceName(name);
46251
+ this.setMoveAllowed("rename");
46252
+ if (this.settingMove) throw new Error("rename-busy: The device set is already changing.");
46253
+ const work = (async () => {
46254
+ const keeper = await this.deviceLinks?.turnKeeper();
46255
+ if (!keeper) throw new Error("rename-state: This device cannot sign for its device set.");
46256
+ return renameDevice({
46257
+ profile: databaseName(),
46258
+ keeper,
46259
+ key,
46260
+ name: clean
46261
+ });
46262
+ })();
46263
+ this.settingMove = work;
46264
+ let renamed;
46265
+ try {
46266
+ renamed = await work;
46267
+ } finally {
46268
+ this.settingMove = null;
46269
+ }
46270
+ if (renamed) this.deviceLinks?.hintTurn();
46271
+ return this.deviceSet();
46272
+ }
45829
46273
  /** "New device secret": the set moves to a new secret with nobody removed. */
45830
46274
  async deviceNewSecret() {
45831
46275
  return this.moveDeviceSet();
@@ -46229,7 +46673,15 @@ var GhostlyNode = class GhostlyNode {
46229
46673
  const host = handoffProfileHost();
46230
46674
  if (!host) throw new Error("This app cannot discard it");
46231
46675
  await host.staging.drop(database);
46232
- await amendDevice(databaseName(), { forks: record.forks.filter((name) => name !== database) });
46676
+ const forks = record.forks.filter((name) => name !== database);
46677
+ const kept = forkTimes({
46678
+ forks,
46679
+ forkKeptAt: record.forkKeptAt
46680
+ });
46681
+ await amendDevice(databaseName(), {
46682
+ forks,
46683
+ forkKeptAt: Object.keys(kept).length ? kept : void 0
46684
+ });
46233
46685
  this.emitState();
46234
46686
  }
46235
46687
  async deviceTurnPeek({ d }) {
@@ -46492,7 +46944,8 @@ var GhostlyNode = class GhostlyNode {
46492
46944
  const member = () => entry || this.groups.isCommunityGroup(group) || this.groups.inRoster(group, peer);
46493
46945
  let seen = false;
46494
46946
  const native = this.keepsGroupNative(stored);
46495
- const resumeOn = native ? TRANSPORTS.find((t) => t !== "webrtc/1" && t in this.nativeFactories && !!stored.peerTransports?.includes(t)) : "webrtc/1";
46947
+ const natives = this.groupNatives(stored), chosen = this.groupChoice(stored);
46948
+ const resumeOn = native ? TRANSPORTS.find((t) => t !== "webrtc/1" && natives.includes(t) && !!stored.peerTransports?.includes(t)) : "webrtc/1";
46496
46949
  live.pairing = { status: "connecting" };
46497
46950
  live.edgeStartedAt = Date.now();
46498
46951
  live.carried?.stop();
@@ -46524,7 +46977,7 @@ var GhostlyNode = class GhostlyNode {
46524
46977
  largeFilesSupport: !entry,
46525
46978
  binaryFilesSupport: !entry,
46526
46979
  params: stored,
46527
- rtcAvailable: typeof RTCPeerConnection !== "undefined" && !this.edgeRtcOff.has(linkId),
46980
+ rtcAvailable: typeof RTCPeerConnection !== "undefined" && !this.edgeRtcOff.has(linkId) && !this.groupNativeChoice(stored),
46528
46981
  resume: !entry && stored.edgeLive ? resumeOn : void 0,
46529
46982
  native: {
46530
46983
  peerDescriptors: stored.peerDescriptors,
@@ -46533,7 +46986,7 @@ var GhostlyNode = class GhostlyNode {
46533
46986
  automatic: true
46534
46987
  },
46535
46988
  packetTransports: !this.options.webrtcGroupLinks,
46536
- packetTransportsSaid: !!stored.transportSeeds && Object.keys(stored.transportSeeds).length > 0,
46989
+ packetTransportsSaid: !!stored.transportSeeds && Object.keys(stored.transportSeeds).length > 0 || !!chosen,
46537
46990
  resumeFloor: !entry && stored.edgeLive ? stored.edgeLiveSince : void 0,
46538
46991
  pairing: {
46539
46992
  credentials: {
@@ -46692,7 +47145,27 @@ var GhostlyNode = class GhostlyNode {
46692
47145
  */
46693
47146
  keepsGroupNative(stored) {
46694
47147
  if (this.options.webrtcGroupLinks) return false;
46695
- return typeof RTCPeerConnection === "undefined" || this.edgeRtcOff.has(stored.id) || !!stored.peerTransports && !stored.peerTransports.includes("webrtc/1");
47148
+ return typeof RTCPeerConnection === "undefined" || this.edgeRtcOff.has(stored.id) || !!stored.peerTransports && !stored.peerTransports.includes("webrtc/1") || this.groupNativeChoice(stored) !== void 0;
47149
+ }
47150
+ /** What this device chose for the group of an edge (`setGroupTransport`); undefined on Automatic, and for an entry session. */
47151
+ groupChoice(stored) {
47152
+ return stored.group && !stored.groupEntry ? this.settings.groupTransports?.[stored.group] : void 0;
47153
+ }
47154
+ /** The native transport chosen for the group of an edge, where this app runs it. */
47155
+ groupNativeChoice(stored) {
47156
+ const chosen = this.groupChoice(stored);
47157
+ return chosen && chosen !== "webrtc/1" && chosen in this.nativeFactories ? chosen : void 0;
47158
+ }
47159
+ /**
47160
+ * The native transports a group's link may listen on (WISP 902 § Transports): every one this app runs, or the one
47161
+ * chosen for its group. A member whose `_tr` lists neither WebRTC nor that one (it chose another, or its app runs only
47162
+ * that other) is met on its own too: the two would have nothing in common.
47163
+ */
47164
+ groupNatives(stored) {
47165
+ const all = Object.keys(this.nativeFactories), chosen = this.groupNativeChoice(stored);
47166
+ if (!chosen) return all;
47167
+ const theirs = stored.peerTransports;
47168
+ return theirs && !theirs.includes("webrtc/1") && !theirs.includes(chosen) ? all.filter((t) => t === chosen || theirs.includes(t)) : [chosen];
46696
47169
  }
46697
47170
  /**
46698
47171
  * An edge's WebRTC attempt exchanged both descriptions and connected nothing, or found no candidate at all
@@ -47334,7 +47807,7 @@ var GhostlyNode = class GhostlyNode {
47334
47807
  nativeFactoriesFor(relayOnly) {
47335
47808
  const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
47336
47809
  return {
47337
- ...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-B8Pdykhg.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
47810
+ ...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-D185dETu.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
47338
47811
  ...relayOnly ? {} : this.options.nativeTransports,
47339
47812
  ...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
47340
47813
  ...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, { relays: this.irohRelays }) } : {}
@@ -47348,17 +47821,58 @@ var GhostlyNode = class GhostlyNode {
47348
47821
  if (this.options.irohRelays?.length) return [...this.options.irohRelays];
47349
47822
  return this.settings.irohRelays?.length ? this.settings.irohRelays : [...DEFAULT_IROH_RELAYS];
47350
47823
  }
47351
- /** New Iroh relays: idle endpoints move now; one carrying a chat keeps its relay until that session ends. */
47824
+ /** New Iroh relays: idle endpoints move now; one carrying a chat keeps its relay until that session ends (`moveNative`). */
47352
47825
  async rehomeIroh() {
47353
47826
  if (!this.options.irohWeb && !this.ownIrohRelays) return;
47354
47827
  this.deviceLinks?.nativeChanged(["iroh/1"]);
47355
47828
  for (const [linkId, live] of this.links) {
47356
47829
  const link = live.link;
47357
- if (!link?.availableTransports.includes("iroh/1") || !link.canReleaseEndpoint("iroh/1")) continue;
47830
+ if (!link?.availableTransports.includes("iroh/1")) continue;
47831
+ if (!link.canReleaseEndpoint("iroh/1")) {
47832
+ this.nativeMoved(linkId).add("iroh/1");
47833
+ continue;
47834
+ }
47358
47835
  await link.releaseEndpoint("iroh/1");
47359
47836
  this.ensureNativeEndpoints(linkId);
47360
47837
  }
47361
47838
  }
47839
+ /**
47840
+ * Chats and group links whose listener of a transport is on a relay the person changed or removed, kept while a
47841
+ * session ran on it (or a dial or a switch was under way), by link id. Before, it stayed there until the app restarted:
47842
+ * its record went on naming the old relay, and a contact dialled it there.
47843
+ */
47844
+ movedNative = /* @__PURE__ */ new Map();
47845
+ nativeMoved(linkId) {
47846
+ let moved = this.movedNative.get(linkId);
47847
+ if (!moved) this.movedNative.set(linkId, moved = /* @__PURE__ */ new Set());
47848
+ return moved;
47849
+ }
47850
+ /** Each second: those whose session ended let the old relay go, and start again on the new one (none where it was removed). */
47851
+ moveNative() {
47852
+ for (const [linkId, moved] of this.movedNative) {
47853
+ const link = this.links.get(linkId)?.link;
47854
+ for (const key of [...moved]) {
47855
+ if (!link?.availableTransports.includes(key)) {
47856
+ moved.delete(key);
47857
+ continue;
47858
+ }
47859
+ if (!link.canReleaseEndpoint(key)) continue;
47860
+ moved.delete(key);
47861
+ link.releaseEndpoint(key).then(() => {
47862
+ const live = this.links.get(linkId);
47863
+ if (this.shuttingDown || live?.link !== link) return;
47864
+ if (key === "iroh/1") {
47865
+ this.ensureNativeEndpoints(linkId);
47866
+ return;
47867
+ }
47868
+ if (live.transportErrors) delete live.transportErrors[key];
47869
+ if (this.hyperdhtRelay) this.ensureNativeEndpoints(linkId);
47870
+ this.emitState();
47871
+ }, () => {});
47872
+ }
47873
+ if (!moved.size) this.movedNative.delete(linkId);
47874
+ }
47875
+ }
47362
47876
  /** The HyperDHT relay a browser reaches the HyperDHT through; empty when none is set. */
47363
47877
  get hyperdhtRelay() {
47364
47878
  return (this.settings.hyperdhtRelay ?? "").trim();
@@ -47402,7 +47916,10 @@ var GhostlyNode = class GhostlyNode {
47402
47916
  if (this.hyperdhtRelay && link && this.keepsNativeEndpoints(linkId, live.stored)) this.ensureNativeEndpoints(linkId);
47403
47917
  continue;
47404
47918
  }
47405
- if (!link.canReleaseEndpoint("hyperdht/1")) continue;
47919
+ if (!link.canReleaseEndpoint("hyperdht/1")) {
47920
+ this.nativeMoved(linkId).add("hyperdht/1");
47921
+ continue;
47922
+ }
47406
47923
  await link.releaseEndpoint("hyperdht/1");
47407
47924
  if (live.transportErrors) delete live.transportErrors["hyperdht/1"];
47408
47925
  if (this.hyperdhtRelay) this.ensureNativeEndpoints(linkId);
@@ -47613,9 +48130,17 @@ var GhostlyNode = class GhostlyNode {
47613
48130
  lane.busy = true;
47614
48131
  start.go();
47615
48132
  }
47616
- /** The listeners this app may hold for a transport: sixteen for Iroh's browser build (`IROH_WEB_SLOTS`), eight for the others. */
48133
+ /**
48134
+ * The listeners this app may hold for a transport: for Iroh's browser build sixteen (`IROH_WEB_SLOTS`), or 64 where
48135
+ * none of its relays is n0's (`IROH_WEB_OWN_RELAY_SLOTS`); eight for the others. They start one at a time either way.
48136
+ */
47617
48137
  nativeSlots(key) {
47618
- return key === "iroh/1" && this.options.irohWeb ? IROH_WEB_SLOTS : NATIVE_SLOTS;
48138
+ if (key !== "iroh/1" || !this.options.irohWeb) return NATIVE_SLOTS;
48139
+ return onPublicIrohRelay(this.irohRelays) ? IROH_WEB_SLOTS : IROH_WEB_OWN_RELAY_SLOTS;
48140
+ }
48141
+ /** Of those, the most 1:1 chats hold: eight, or half of them where there are more. */
48142
+ chatNativeSlots(key) {
48143
+ return Math.max(NATIVE_SLOTS, this.nativeSlots(key) / 2);
47619
48144
  }
47620
48145
  /** Of those, what its groups' links may hold, all groups together. */
47621
48146
  groupNativeSlots(key) {
@@ -47641,6 +48166,7 @@ var GhostlyNode = class GhostlyNode {
47641
48166
  if (this.shuttingDown || !live?.stored.profile || live.stored.deliveryMode === "dht" || !link || link !== expected || link.takenFromUs) return false;
47642
48167
  const group = !!live.stored.group;
47643
48168
  if (group && !this.keepsGroupNative(live.stored)) return false;
48169
+ if (group && !this.groupNatives(live.stored).includes(key)) return false;
47644
48170
  if (link.availableTransports.includes(key)) return false;
47645
48171
  live.transportErrors ??= {};
47646
48172
  try {
@@ -47662,7 +48188,7 @@ var GhostlyNode = class GhostlyNode {
47662
48188
  const extra = (other) => !!other.stored.group && !other.stored.groupEntry && !onScreen(other) && anchorOf(other.stored.group) !== other && !this.chosenByPeer(other, key);
47663
48189
  const full = owners.length >= slots, entry = !!live.stored.groupEntry;
47664
48190
  if (group && (entry || extra(live)) && (full || groups >= this.groupNativeSlots(key) || !entry && !anchorOf(live.stored.group)?.link?.availableTransports.includes(key))) return "no-slot";
47665
- if (full || !group && owners.length - groups >= NATIVE_SLOTS) {
48191
+ if (full || !group && owners.length - groups >= this.chatNativeSlots(key)) {
47666
48192
  const paired = !group && live.pairedAt !== void 0 && now - live.pairedAt < 6e5 ? live.pairedAt : void 0;
47667
48193
  const taking = group || this.activeLinkId === linkId || inUse || paired !== void 0;
47668
48194
  const mine = taking && (inUse || onScreen(live)) ? now : Math.max(paired ?? 0, used(live));
@@ -47816,6 +48342,7 @@ var GhostlyNode = class GhostlyNode {
47816
48342
  */
47817
48343
  retryNative() {
47818
48344
  this.groupAnchorsAnswered();
48345
+ this.moveNative();
47819
48346
  const now = Date.now();
47820
48347
  for (const [linkId, failed] of this.nativeFailed) {
47821
48348
  if (now < failed.at || this.nativeRetrying.has(linkId)) continue;
@@ -48505,4 +49032,4 @@ function signalKind(signal) {
48505
49032
  //#endregion
48506
49033
  export { EngineServer };
48507
49034
 
48508
- //# sourceMappingURL=server-Br3XPwFG.js.map
49035
+ //# sourceMappingURL=server-Dw1o8z1o.js.map