@ghostlytools/cli 1.8.0 → 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.
- package/README.md +11 -8
- package/SKILL.md +4 -3
- package/dist/assets/{api-I_KbuXHa.js → api-DFCgr6RH.js} +94 -35
- package/dist/assets/api-DFCgr6RH.js.map +1 -0
- package/dist/assets/{api-Dj1yn0px.js → api-raWw9j_m.js} +2 -2
- package/dist/assets/{apiKit-C-_PWZvy.js → apiKit-CCavJJcl.js} +2 -2
- package/dist/assets/{apiKit-C-_PWZvy.js.map → apiKit-CCavJJcl.js.map} +1 -1
- package/dist/assets/{apps-DbEfL_3b.js → apps-B7o2BPj6.js} +1 -1
- package/dist/assets/{apps-DKIe8VjF.js → apps-DmxEG147.js} +2 -2
- package/dist/assets/{apps-DKIe8VjF.js.map → apps-DmxEG147.js.map} +1 -1
- package/dist/assets/{arkade-k1bdSm70.js → arkade-DtYR9H0c.js} +2 -2
- package/dist/assets/{arkade-k1bdSm70.js.map → arkade-DtYR9H0c.js.map} +1 -1
- package/dist/assets/{backup-Cdd6-HNu.js → backup-BserdrNk.js} +1 -1
- package/dist/assets/{backup-beKfbfNk.js → backup-YIB2XIES.js} +4 -4
- package/dist/assets/{backup-beKfbfNk.js.map → backup-YIB2XIES.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/buttons-CuRfKnPI.js +1331 -0
- package/dist/assets/buttons-CuRfKnPI.js.map +1 -0
- package/dist/assets/buttons-De3LPdSG.js +2 -0
- package/dist/assets/{envelope-B88yiCQj.js → envelope-Dt75vrmY.js} +2 -2
- package/dist/assets/{envelope-B88yiCQj.js.map → envelope-Dt75vrmY.js.map} +1 -1
- package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -1
- package/dist/assets/fixedHosts-B598JzbC.js +24 -0
- package/dist/assets/fixedHosts-B598JzbC.js.map +1 -0
- package/dist/assets/{ghostly_iroh_web-CO0onry8.js → ghostly_iroh_web-BzAXJUYH.js} +10 -10
- package/dist/assets/{ghostly_iroh_web-CO0onry8.js.map → ghostly_iroh_web-BzAXJUYH.js.map} +1 -1
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupFiles-DjQc5XXv.js → groupFiles-FXel6zIc.js} +41 -11
- package/dist/assets/groupFiles-FXel6zIc.js.map +1 -0
- package/dist/assets/{host-CNWGB3-j.js → host-DIBeK_c_.js} +95 -28
- package/dist/assets/host-DIBeK_c_.js.map +1 -0
- package/dist/assets/hyperdhtRelay-1wzya_0L.js +25 -0
- package/dist/assets/hyperdhtRelay-1wzya_0L.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-g7eXzf5h.js → hyperdhtRelay-D185dETu.js} +15 -3
- package/dist/assets/hyperdhtRelay-D185dETu.js.map +1 -0
- package/dist/assets/{irohWeb-Bx8dI4be.js → irohWeb-BSv_BWyG.js} +25 -8
- package/dist/assets/{irohWeb-Bx8dI4be.js.map → irohWeb-BSv_BWyG.js.map} +1 -1
- package/dist/assets/{main-BRxhBctJ.js → main-BbhfMTt8.js} +50 -22
- package/dist/assets/main-BbhfMTt8.js.map +1 -0
- package/dist/assets/{mainline-CwuS6ngj.js → mainline-9Vc3c3SA.js} +2 -2
- package/dist/assets/{mainline-CwuS6ngj.js.map → mainline-9Vc3c3SA.js.map} +1 -1
- package/dist/assets/{networkReason-CIAMieQm.js → networkReason-BncJ9KSM.js} +2 -2
- package/dist/assets/{networkReason-CIAMieQm.js.map → networkReason-BncJ9KSM.js.map} +1 -1
- package/dist/assets/{nwc-C9JLJJkL.js → nwc-QX3Yt1Sb.js} +3 -3
- package/dist/assets/{nwc-C9JLJJkL.js.map → nwc-QX3Yt1Sb.js.map} +1 -1
- package/dist/assets/{nwcProvider-pFMrsUJh.js → nwcProvider-CzX3xH47.js} +2 -2
- package/dist/assets/{nwcProvider-pFMrsUJh.js.map → nwcProvider-CzX3xH47.js.map} +1 -1
- package/dist/assets/ownDid-D8z5gwGI.js +281 -0
- package/dist/assets/ownDid-D8z5gwGI.js.map +1 -0
- package/dist/assets/{registry-Cks7FA_o.js → registry-B2Dtnibo.js} +5 -246
- package/dist/assets/registry-B2Dtnibo.js.map +1 -0
- package/dist/assets/{registry-DY2ixQfU.js → registry-PTtBMaYZ.js} +1 -1
- package/dist/assets/{resolve-C4Y2HPqQ.js → resolve-ZxVzwFNA.js} +3 -280
- package/dist/assets/resolve-ZxVzwFNA.js.map +1 -0
- package/dist/assets/{server-D9RAmGdm.js → server-Dw1o8z1o.js} +1144 -359
- package/dist/assets/server-Dw1o8z1o.js.map +1 -0
- package/dist/assets/{src-1RU4TilT.js → src-BD8RBVEp.js} +1269 -134
- package/dist/assets/src-BD8RBVEp.js.map +1 -0
- package/dist/assets/sshForges-DWrESWkK.js +253 -0
- package/dist/assets/sshForges-DWrESWkK.js.map +1 -0
- package/dist/assets/{translate-od5GbpvR.js → translate-D1uP0q32.js} +17 -5
- package/dist/assets/translate-D1uP0q32.js.map +1 -0
- package/dist/assets/{usdt-DldXV0MR.js → usdt-DhVN8geQ.js} +3 -3
- package/dist/assets/{usdt-DldXV0MR.js.map → usdt-DhVN8geQ.js.map} +1 -1
- package/dist/assets/{waitNotice-Ck3el3_Z.js → waitNotice-B8D8WhbE.js} +2 -2
- package/dist/assets/waitNotice-B8D8WhbE.js.map +1 -0
- package/dist/assets/{words-BS2qq_vV.js → words-DdXPkB3n.js} +3 -2
- package/dist/assets/words-DdXPkB3n.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/call-echo.mjs +7 -5
- package/package.json +1 -1
- package/dist/assets/api-I_KbuXHa.js.map +0 -1
- package/dist/assets/buttons-BO1_7V4L.js +0 -2
- package/dist/assets/buttons-ClI13rdv.js +0 -545
- package/dist/assets/buttons-ClI13rdv.js.map +0 -1
- package/dist/assets/groupFiles-DjQc5XXv.js.map +0 -1
- package/dist/assets/host-CNWGB3-j.js.map +0 -1
- package/dist/assets/hyperdhtRelay-BT_wRxab.js +0 -21
- package/dist/assets/hyperdhtRelay-BT_wRxab.js.map +0 -1
- package/dist/assets/hyperdhtRelay-g7eXzf5h.js.map +0 -1
- package/dist/assets/main-BRxhBctJ.js.map +0 -1
- package/dist/assets/registry-Cks7FA_o.js.map +0 -1
- package/dist/assets/resolve-C4Y2HPqQ.js.map +0 -1
- package/dist/assets/server-D9RAmGdm.js.map +0 -1
- package/dist/assets/src-1RU4TilT.js.map +0 -1
- package/dist/assets/translate-od5GbpvR.js.map +0 -1
- package/dist/assets/waitNotice-Ck3el3_Z.js.map +0 -1
- package/dist/assets/words-BS2qq_vV.js.map +0 -1
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $
|
|
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";
|
|
3
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";
|
|
4
4
|
import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
5
|
+
import { t as nwc } from "./nwcProvider-CzX3xH47.js";
|
|
6
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";
|
|
7
|
-
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-
|
|
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-
|
|
9
|
-
import {
|
|
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 {
|
|
12
|
-
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-
|
|
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";
|
|
13
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";
|
|
14
|
-
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-
|
|
15
|
+
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
|
|
15
16
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
16
17
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
17
18
|
import { base64, base64url, base64urlnopad, bech32, hex } from "@scure/base";
|
|
@@ -198,7 +199,7 @@ function viewNews(before, after) {
|
|
|
198
199
|
//#endregion
|
|
199
200
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
200
201
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
201
|
-
var loadUsdt = () => import("./usdt-
|
|
202
|
+
var loadUsdt = () => import("./usdt-DhVN8geQ.js");
|
|
202
203
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
203
204
|
var DEFAULT_USDT = {
|
|
204
205
|
network: "ethereum",
|
|
@@ -549,6 +550,44 @@ var UsdtWallet = class {
|
|
|
549
550
|
}
|
|
550
551
|
};
|
|
551
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
|
|
552
591
|
//#region ../browser/src/engine/paymentAdapters/backup.ts
|
|
553
592
|
/**
|
|
554
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);
|
|
@@ -647,7 +686,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
647
686
|
//#endregion
|
|
648
687
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
649
688
|
/** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
|
|
650
|
-
var loadArkade = () => import("./arkade-
|
|
689
|
+
var loadArkade = () => import("./arkade-DtYR9H0c.js");
|
|
651
690
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
652
691
|
var RETIRE_READ_MS = 1e4;
|
|
653
692
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -9138,6 +9177,23 @@ var PUBKY_NEXUS = "https://nexus.pubky.app";
|
|
|
9138
9177
|
var BLUESKY_APPVIEW = "https://public.api.bsky.app";
|
|
9139
9178
|
/** Bluesky's avatar CDN: the AppView names avatars there. It sends no CORS header, so the picture is read from the account's own server. */
|
|
9140
9179
|
var BLUESKY_CDN_AVATAR = /^https:\/\/cdn\.bsky\.app\/img\/avatar\/plain\/(did:[a-z]+:[A-Za-z0-9._:%-]+)\/(b[a-z2-7]{20,100})(@(jpeg|png))?$/;
|
|
9180
|
+
/** A request the readers did not make: Hide my IP from contacts is on and the host is one the contact chose. */
|
|
9181
|
+
var HostNotContacted = class extends Error {};
|
|
9182
|
+
/**
|
|
9183
|
+
* `fetch`, limited to the hosts this app names (Bluesky's AppView, the Pubky index, and the identity checks' fixed
|
|
9184
|
+
* hosts): for a contact's identity while "Hide my IP from contacts" is on, so a server the contact chose (their AT
|
|
9185
|
+
* Protocol server, a did:web's web server) never sees this device's IP address. Anything else is refused unasked.
|
|
9186
|
+
*/
|
|
9187
|
+
function fixedHostsFetch(fetch) {
|
|
9188
|
+
return async (url, options) => {
|
|
9189
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-B598JzbC.js");
|
|
9190
|
+
const host = hostOf$1(url);
|
|
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`);
|
|
9192
|
+
return fetch(url, options);
|
|
9193
|
+
};
|
|
9194
|
+
}
|
|
9195
|
+
/** Why a picture was not read: the refusal above says so; anything else is `fallback`. */
|
|
9196
|
+
var pictureMiss = (e, fallback) => e instanceof HostNotContacted ? e.message : fallback;
|
|
9141
9197
|
var count$1 = (value) => Number.isSafeInteger(value) && value >= 0 && value <= MAX_COUNT ? value : void 0;
|
|
9142
9198
|
var hostOf$1 = (url) => new URL(url).host;
|
|
9143
9199
|
var pictureUnreachable = (host) => ({ miss: `${host} could not be reached, or the picture is larger than ${AVATAR_MAX_BYTES / 1024 / 1024} MiB` });
|
|
@@ -9313,8 +9369,8 @@ var PUBLIC_PROFILE_READERS = {
|
|
|
9313
9369
|
});
|
|
9314
9370
|
picture = blob.status === 200 ? await decodeAvatar(blob.bytes, 160) : { miss: `${server.host} answered ${blob.status}` };
|
|
9315
9371
|
hosts.push(server.host);
|
|
9316
|
-
} catch {
|
|
9317
|
-
picture = { miss: "the account's server could not be asked for it" };
|
|
9372
|
+
} catch (e) {
|
|
9373
|
+
picture = { miss: pictureMiss(e, "the account's server could not be asked for it") };
|
|
9318
9374
|
}
|
|
9319
9375
|
else if (typeof d.avatar === "string") picture = { miss: "Bluesky named it at an address this app does not read" };
|
|
9320
9376
|
return profile({
|
|
@@ -9337,6 +9393,14 @@ var KEY = "publicProfiles";
|
|
|
9337
9393
|
var PRUNE_MS = 6e5;
|
|
9338
9394
|
var keyOf$1 = (s) => `${s.provider}\n${s.subject}`;
|
|
9339
9395
|
/**
|
|
9396
|
+
* The fetch an identity's public data is read with: a contact's, while Hide my IP from contacts is on, reaches only
|
|
9397
|
+
* hosts this app names, so a server the contact chose (their AT Protocol server) never learns this device's IP address.
|
|
9398
|
+
*/
|
|
9399
|
+
function profileFetch(host, s, fetch) {
|
|
9400
|
+
if (!host.relayOnly?.() || host.own?.().some((o) => o.provider === s.provider && o.subject === s.subject)) return fetch;
|
|
9401
|
+
return fixedHostsFetch(fetch);
|
|
9402
|
+
}
|
|
9403
|
+
/**
|
|
9340
9404
|
* The public profiles of verified identities, engine side: asked for one identity at a time, when its card is on
|
|
9341
9405
|
* screen (the UI's `loadPublicProfile`), only for an identity with a current verified proof and only with the
|
|
9342
9406
|
* setting on and the network on. Kept in IndexedDB for offline use, asked again after a day (misses after five
|
|
@@ -9442,7 +9506,7 @@ var PublicProfiles = class {
|
|
|
9442
9506
|
const checkedAt = this.now;
|
|
9443
9507
|
try {
|
|
9444
9508
|
const data = await reader.read(s.subject, {
|
|
9445
|
-
fetch: this.fetch,
|
|
9509
|
+
fetch: profileFetch(this.host, s, this.fetch),
|
|
9446
9510
|
signal: AbortSignal.timeout(2e4),
|
|
9447
9511
|
relays: this.host.nostrRelays(),
|
|
9448
9512
|
makeSocket: this.host.makeSocket,
|
|
@@ -9978,19 +10042,26 @@ async function readPostImage(source, ctx) {
|
|
|
9978
10042
|
const doc = await resolveAtprotoDid(source.did, resolve);
|
|
9979
10043
|
server = new URL(doc.pds);
|
|
9980
10044
|
await assertPublicServer(server.hostname, resolve);
|
|
9981
|
-
} catch {
|
|
10045
|
+
} catch (e) {
|
|
9982
10046
|
return {
|
|
9983
|
-
miss: "the account's server could not be asked for it",
|
|
10047
|
+
miss: pictureMiss(e, "the account's server could not be asked for it"),
|
|
9984
10048
|
hosts: []
|
|
9985
10049
|
};
|
|
9986
10050
|
}
|
|
10051
|
+
let refused;
|
|
9987
10052
|
const r = await ctx.fetch(`${server.origin}/xrpc/com.atproto.sync.getBlob?${new URLSearchParams({
|
|
9988
10053
|
did: source.did,
|
|
9989
10054
|
cid: source.cid
|
|
9990
10055
|
})}`, {
|
|
9991
10056
|
maxBytes: AVATAR_MAX_BYTES,
|
|
9992
10057
|
signal: ctx.signal
|
|
9993
|
-
}).catch(() =>
|
|
10058
|
+
}).catch((e) => {
|
|
10059
|
+
refused = e;
|
|
10060
|
+
});
|
|
10061
|
+
if (refused instanceof HostNotContacted) return {
|
|
10062
|
+
miss: refused.message,
|
|
10063
|
+
hosts: []
|
|
10064
|
+
};
|
|
9994
10065
|
if (!r) return {
|
|
9995
10066
|
miss: `${server.host} could not be reached, or the picture is larger than ${AVATAR_MAX_BYTES / 1024 / 1024} MiB`,
|
|
9996
10067
|
hosts: [server.host]
|
|
@@ -10039,9 +10110,10 @@ var PublicActivity = class {
|
|
|
10039
10110
|
allowed(s) {
|
|
10040
10111
|
return this.host.enabled() && !!this.reader(s) && this.host.eligible().some((e) => e.provider === s.provider && e.subject === s.subject);
|
|
10041
10112
|
}
|
|
10042
|
-
|
|
10113
|
+
/** A contact's identity, while Hide my IP from contacts is on, is read only from hosts this app names (`profileFetch`). */
|
|
10114
|
+
ctx(s, signal = AbortSignal.timeout(ASK_TIMEOUT_MS)) {
|
|
10043
10115
|
return {
|
|
10044
|
-
fetch: this.fetch,
|
|
10116
|
+
fetch: profileFetch(this.host, s, this.fetch),
|
|
10045
10117
|
signal,
|
|
10046
10118
|
relays: this.host.nostrRelays(),
|
|
10047
10119
|
makeSocket: this.host.makeSocket,
|
|
@@ -10122,7 +10194,7 @@ var PublicActivity = class {
|
|
|
10122
10194
|
}
|
|
10123
10195
|
const reader = this.reader(s);
|
|
10124
10196
|
await this.once(`posts\n${key}${s.more ? "\nmore" : ""}`, async () => {
|
|
10125
|
-
const page = await reader.posts(s.subject, this.ctx(), s.more ? kept?.cursor : void 0);
|
|
10197
|
+
const page = await reader.posts(s.subject, this.ctx(s), s.more ? kept?.cursor : void 0);
|
|
10126
10198
|
if (!this.allowed(s)) return;
|
|
10127
10199
|
const before = s.more ? this.posts.get(key)?.posts ?? [] : [];
|
|
10128
10200
|
const seen = new Set(before.map((p) => p.id));
|
|
@@ -10215,7 +10287,7 @@ var PublicActivity = class {
|
|
|
10215
10287
|
}
|
|
10216
10288
|
const reader = this.reader(s);
|
|
10217
10289
|
await this.once(`graph\n${key}`, async () => {
|
|
10218
|
-
const g = await reader.graph(s.subject, this.ctx());
|
|
10290
|
+
const g = await reader.graph(s.subject, this.ctx(s));
|
|
10219
10291
|
if (!this.allowed(s)) return;
|
|
10220
10292
|
this.graphs.set(key, {
|
|
10221
10293
|
...g,
|
|
@@ -10240,7 +10312,7 @@ var PublicActivity = class {
|
|
|
10240
10312
|
}
|
|
10241
10313
|
if (!this.host.online()) throw new Error("Offline: turn the network on first");
|
|
10242
10314
|
return this.once(`image\n${key}`, async () => {
|
|
10243
|
-
const r = await readPostImage(image.source, this.ctx());
|
|
10315
|
+
const r = await readPostImage(image.source, this.ctx(s));
|
|
10244
10316
|
const view = {
|
|
10245
10317
|
hosts: r.hosts,
|
|
10246
10318
|
...r.avatar ? { src: r.avatar } : {},
|
|
@@ -10332,16 +10404,43 @@ async function bytesHere(file) {
|
|
|
10332
10404
|
return await (file.bytes ? await fileBytesOf(file.bytes) : null)?.size(file.id) ?? 0;
|
|
10333
10405
|
}
|
|
10334
10406
|
/**
|
|
10407
|
+
* A received picture as it goes on: without its metadata (one from an app that sent it with them keeps where its author
|
|
10408
|
+
* took it, the device, the time), read whole; undefined for any other file, copied as it is. Refused with
|
|
10409
|
+
* `NO_PICTURE_METADATA` when its metadata cannot be removed, as a picture sent from here is.
|
|
10410
|
+
*/
|
|
10411
|
+
async function withoutMetadata(source, size, file, read) {
|
|
10412
|
+
if (file.voice || file.video || !size) return void 0;
|
|
10413
|
+
if (!isStrippedPicture(await read(0, Math.min(PICTURE_METADATA_LIMITS.headBytes, size)), file.mime)) return void 0;
|
|
10414
|
+
if (size > PICTURE_METADATA_LIMITS.maxBytes) throw new Error(NO_PICTURE_METADATA);
|
|
10415
|
+
const whole = new Uint8Array(size);
|
|
10416
|
+
for (let offset = 0; offset < size;) {
|
|
10417
|
+
const part = await read(offset, Math.min(1048576, size - offset));
|
|
10418
|
+
if (!part.length) throw new Error("The file is shorter than it says");
|
|
10419
|
+
whole.set(part, offset);
|
|
10420
|
+
offset += part.length;
|
|
10421
|
+
}
|
|
10422
|
+
return new Blob(stripPictureMetadata(whole, file.mime), { type: source.blob?.type ?? file.mime });
|
|
10423
|
+
}
|
|
10424
|
+
/**
|
|
10335
10425
|
* A copy of a file on this device, for sending in another chat under `file.id`: a small one whole, a larger one a
|
|
10336
|
-
* step at a time, never whole in memory
|
|
10426
|
+
* step at a time, never whole in memory; a picture without its metadata, read whole. Refused while it is still
|
|
10427
|
+
* arriving, or when its bytes are gone. Resolves to `file` as it goes: a stripped picture's size is its copy's.
|
|
10337
10428
|
*/
|
|
10338
10429
|
async function copyForForward(sourceId, target) {
|
|
10339
10430
|
const source = await fileStore.get(sourceId);
|
|
10340
10431
|
if (!source?.metadata) throw new Error("The file is not on this device any more");
|
|
10341
|
-
const
|
|
10432
|
+
const stored = storedSize(source);
|
|
10342
10433
|
const checked = source.wire3 ? source.wire3.state === "done" : !source.group || source.transfer?.state === "done";
|
|
10343
|
-
if (source.direction === "in" && !checked || await bytesHere(source) !==
|
|
10344
|
-
const
|
|
10434
|
+
if (source.direction === "in" && !checked || await bytesHere(source) !== stored) throw new Error("The file has not arrived yet");
|
|
10435
|
+
const from = source.bytes ? await fileBytesOf(source.bytes) : null;
|
|
10436
|
+
const read = async (offset, length) => source.blob ? new Uint8Array(await source.blob.slice(offset, offset + length).arrayBuffer()) : from.read(source.id, offset, length);
|
|
10437
|
+
const stripped = await withoutMetadata(source, stored, target.file, read);
|
|
10438
|
+
const blob = stripped ?? source.blob, size = stripped?.size ?? stored;
|
|
10439
|
+
const known = stripped ? void 0 : source.digest;
|
|
10440
|
+
const { linkId, wireId, timestamp } = target, file = stripped ? {
|
|
10441
|
+
...target.file,
|
|
10442
|
+
size
|
|
10443
|
+
} : target.file;
|
|
10345
10444
|
const metadata = {
|
|
10346
10445
|
name: file.name,
|
|
10347
10446
|
size: file.size,
|
|
@@ -10364,32 +10463,33 @@ async function copyForForward(sourceId, target) {
|
|
|
10364
10463
|
size: file.size
|
|
10365
10464
|
}
|
|
10366
10465
|
};
|
|
10367
|
-
if (size <= 16777216 &&
|
|
10368
|
-
const copy = new Blob([await
|
|
10466
|
+
if (size <= 16777216 && blob) {
|
|
10467
|
+
const copy = new Blob([await blob.slice(0, size).arrayBuffer()], { type: blob.type });
|
|
10468
|
+
const digest = known ?? (stripped ? await blobDigest(copy) : void 0);
|
|
10369
10469
|
await fileStore.put({
|
|
10370
10470
|
...record,
|
|
10371
10471
|
blob: copy,
|
|
10372
|
-
...
|
|
10472
|
+
...digest && { digest }
|
|
10373
10473
|
});
|
|
10374
|
-
return;
|
|
10474
|
+
return file;
|
|
10375
10475
|
}
|
|
10376
10476
|
const bytes = await fileBytes();
|
|
10377
|
-
const from = source.bytes ? await fileBytesOf(source.bytes) : null;
|
|
10378
10477
|
try {
|
|
10379
10478
|
const appender = new FileAppender(bytes, file.id);
|
|
10380
10479
|
for (let offset = 0; offset < size;) {
|
|
10381
|
-
const part =
|
|
10480
|
+
const part = blob ? new Uint8Array(await blob.slice(offset, offset + 1048576).arrayBuffer()) : await read(offset, Math.min(1048576, size - offset));
|
|
10382
10481
|
if (!part.length) throw new Error("The file is shorter than it says");
|
|
10383
10482
|
await appender.append(part);
|
|
10384
10483
|
offset += part.length;
|
|
10385
10484
|
}
|
|
10386
10485
|
await appender.close();
|
|
10387
|
-
const digest =
|
|
10486
|
+
const digest = known ?? await bytes.digest(file.id);
|
|
10388
10487
|
await fileStore.put({
|
|
10389
10488
|
...record,
|
|
10390
10489
|
bytes: bytes.kind,
|
|
10391
10490
|
digest
|
|
10392
10491
|
});
|
|
10492
|
+
return file;
|
|
10393
10493
|
} catch (error) {
|
|
10394
10494
|
await bytes.remove(file.id).catch(() => {});
|
|
10395
10495
|
throw error;
|
|
@@ -10531,6 +10631,25 @@ function foldText(text) {
|
|
|
10531
10631
|
*/
|
|
10532
10632
|
var SEARCH_KEPT_MS = 6e4;
|
|
10533
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
|
+
/**
|
|
10534
10653
|
* The chat list's search over the chats' whole histories, in the engine (`chatsFound`): a page that holds a chat's
|
|
10535
10654
|
* newest page only (the extension's) finds it by an older message too, without being sent its whole history. Each chat's
|
|
10536
10655
|
* texts are read and folded once, and read again only after the chat changed (`changed`, as the pages hear it).
|
|
@@ -10543,9 +10662,9 @@ var ChatTextSearch = class {
|
|
|
10543
10662
|
constructor(read) {
|
|
10544
10663
|
this.read = read;
|
|
10545
10664
|
}
|
|
10546
|
-
/** 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. */
|
|
10547
10666
|
async found(linkIds, query) {
|
|
10548
|
-
const q = foldText(query);
|
|
10667
|
+
const q = loose(foldText(query));
|
|
10549
10668
|
if (!q) return [];
|
|
10550
10669
|
if (this.timer) clearTimeout(this.timer);
|
|
10551
10670
|
this.timer = setTimeout(() => {
|
|
@@ -10563,7 +10682,7 @@ var ChatTextSearch = class {
|
|
|
10563
10682
|
textsOf(linkId) {
|
|
10564
10683
|
let texts = this.texts.get(linkId);
|
|
10565
10684
|
if (!texts) {
|
|
10566
|
-
texts = this.read(linkId).then((messages) => messages.flatMap(
|
|
10685
|
+
texts = this.read(linkId).then((messages) => messages.flatMap(searchTexts));
|
|
10567
10686
|
this.texts.set(linkId, texts);
|
|
10568
10687
|
texts.catch(() => {
|
|
10569
10688
|
if (this.texts.get(linkId) === texts) this.texts.delete(linkId);
|
|
@@ -10813,6 +10932,8 @@ var APP_CHECK_TIMINGS = {
|
|
|
10813
10932
|
/** A check at start is skipped when every app was checked this recently (a page reloaded several times). */
|
|
10814
10933
|
freshMs: 36e5
|
|
10815
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;
|
|
10816
10937
|
/** Revocations are checked this long at a time before the page's thread is let go. */
|
|
10817
10938
|
var REVOCATIONS_SLICE_MS = 10;
|
|
10818
10939
|
/**
|
|
@@ -10972,6 +11093,21 @@ function notReadable(url, words) {
|
|
|
10972
11093
|
if (typeof url === "string" && isGitHubPage(url)) fail("github-link", "Paste the repository's link, or the link to its app file");
|
|
10973
11094
|
fail("host", words);
|
|
10974
11095
|
}
|
|
11096
|
+
/**
|
|
11097
|
+
* A pasted link Ghostly reads, with a query or a fragment, is refused (`private-link`): a private repository's file link
|
|
11098
|
+
* carries its read token in the query, and the link an app is installed from goes on the card a contact receives. A
|
|
11099
|
+
* github.com page's query never reaches the file read (`appPasteUrl` makes that link anew).
|
|
11100
|
+
*/
|
|
11101
|
+
function refusePrivateLink(url) {
|
|
11102
|
+
if (typeof url !== "string" || isGitHubPage(url)) return;
|
|
11103
|
+
let href;
|
|
11104
|
+
try {
|
|
11105
|
+
href = new URL(url.trim()).href;
|
|
11106
|
+
} catch {
|
|
11107
|
+
return;
|
|
11108
|
+
}
|
|
11109
|
+
if (/[?#]/.test(href)) fail("private-link", "This link carries a query or a fragment, as a private repository's file link does: publish the app in a public repository and paste its link");
|
|
11110
|
+
}
|
|
10975
11111
|
var versionOf = (manifest, digest) => ({
|
|
10976
11112
|
ref: appRef(manifest.publisher, manifest.name),
|
|
10977
11113
|
sequence: manifest.sequence,
|
|
@@ -11008,6 +11144,20 @@ function sameRecord(now, was) {
|
|
|
11008
11144
|
if (!was) return !now;
|
|
11009
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;
|
|
11010
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
|
+
}
|
|
11011
11161
|
/** Rows of one app (`[ref]`), or of one app in one scope (`[ref, scope]`), in `STORES.appStorage`, counter rows included. */
|
|
11012
11162
|
var rowsOf = (...prefix) => IDBKeyRange.bound(prefix, [...prefix, []]);
|
|
11013
11163
|
/** The app's own rows of one scope: its counter row left out. */
|
|
@@ -11712,7 +11862,9 @@ var Apps = class {
|
|
|
11712
11862
|
return (await this.stores()).sort((a, b) => a.addedAt - b.addedAt).map((s) => this.summary(s));
|
|
11713
11863
|
}
|
|
11714
11864
|
storeUrl(url) {
|
|
11715
|
-
|
|
11865
|
+
const at = typeof url === "string" && appPasteUrl(url, "ghostly-store.json") || notReadable(url, "Stores are read only from raw.githubusercontent.com, or from cdn.jsdelivr.net at a commit, over HTTPS");
|
|
11866
|
+
refusePrivateLink(url);
|
|
11867
|
+
return at;
|
|
11716
11868
|
}
|
|
11717
11869
|
keepPreviewed(previewed) {
|
|
11718
11870
|
if (this.previewedSweep) clearTimeout(this.previewedSweep);
|
|
@@ -11732,6 +11884,7 @@ var Apps = class {
|
|
|
11732
11884
|
digest,
|
|
11733
11885
|
at: this.now()
|
|
11734
11886
|
});
|
|
11887
|
+
const held = await this.storeRecord(index.key);
|
|
11735
11888
|
return {
|
|
11736
11889
|
url: at,
|
|
11737
11890
|
key: index.key,
|
|
@@ -11742,15 +11895,17 @@ var Apps = class {
|
|
|
11742
11895
|
expires: index.expires,
|
|
11743
11896
|
expired: read.store.expired,
|
|
11744
11897
|
apps: index.apps.length,
|
|
11745
|
-
...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 } : {} }
|
|
11746
11900
|
};
|
|
11747
11901
|
}
|
|
11748
11902
|
/**
|
|
11749
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,
|
|
11750
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
|
|
11751
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
|
|
11752
|
-
* read only there from then on, frozen). The index
|
|
11753
|
-
* is
|
|
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.
|
|
11754
11909
|
*/
|
|
11755
11910
|
async addStore({ url, key }) {
|
|
11756
11911
|
if (key !== void 0 && !isAppKey(key)) fail("store-key", "Not a store key");
|
|
@@ -11777,6 +11932,19 @@ var Apps = class {
|
|
|
11777
11932
|
digest
|
|
11778
11933
|
});
|
|
11779
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
|
+
}
|
|
11780
11948
|
const record = held && !held.removed ? held : {
|
|
11781
11949
|
key: index.key,
|
|
11782
11950
|
url: at,
|
|
@@ -11899,8 +12067,10 @@ var Apps = class {
|
|
|
11899
12067
|
const { bundle, bytes } = await this.bundled(app);
|
|
11900
12068
|
return this.stage(bundle, bytes, app.url, void 0, true);
|
|
11901
12069
|
}
|
|
11902
|
-
if ("url" in source)
|
|
11903
|
-
|
|
12070
|
+
if ("url" in source) {
|
|
12071
|
+
urls = [typeof source.url === "string" && appPasteUrl(source.url, "app.ghostlyapp") || notReadable(source.url, "Apps are read only from raw.githubusercontent.com, or from cdn.jsdelivr.net at a commit, over HTTPS")];
|
|
12072
|
+
refusePrivateLink(source.url);
|
|
12073
|
+
} else if ("store" in source) {
|
|
11904
12074
|
const s = await this.storeRecord(source.store);
|
|
11905
12075
|
const listing = s && !s.removed ? s.index?.apps.find((a) => a.ref === source.ref) : void 0;
|
|
11906
12076
|
if (!listing) fail("not-listed", "This store does not list this app");
|
|
@@ -11953,19 +12123,21 @@ var Apps = class {
|
|
|
11953
12123
|
if (oldest) this.sweep = setTimeout(() => this.sweepStaged(), STAGED.ms - (this.now() - oldest.at));
|
|
11954
12124
|
}
|
|
11955
12125
|
async stage(bundle, bytes, from, fromStore, carried = false) {
|
|
11956
|
-
|
|
11957
|
-
|
|
12126
|
+
const { manifest, digest } = bundle;
|
|
12127
|
+
const version = versionOf(manifest, digest);
|
|
12128
|
+
const revocations = carried ? [] : await this.readRevocations(version.ref, [from, ...manifest.sources ?? []]) ?? [];
|
|
12129
|
+
for (const [d, s] of this.staged) if (this.now() - s.at > STAGED.ms) this.staged.delete(d);
|
|
12130
|
+
this.staged.delete(digest);
|
|
11958
12131
|
while (this.staged.size >= STAGED.max) this.staged.delete(this.staged.keys().next().value);
|
|
11959
|
-
this.staged.set(
|
|
12132
|
+
this.staged.set(digest, {
|
|
11960
12133
|
bundle,
|
|
11961
12134
|
bytes,
|
|
11962
12135
|
from,
|
|
11963
12136
|
...fromStore !== void 0 && { store: fromStore },
|
|
12137
|
+
revocations,
|
|
11964
12138
|
at: this.now()
|
|
11965
12139
|
});
|
|
11966
12140
|
if (!this.sweep) this.sweepStaged();
|
|
11967
|
-
const { manifest, digest } = bundle;
|
|
11968
|
-
const version = versionOf(manifest, digest);
|
|
11969
12141
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
11970
12142
|
const decision = installDecision(installed, version);
|
|
11971
12143
|
const install = decision === "other-app" ? "new" : decision;
|
|
@@ -11981,7 +12153,7 @@ var Apps = class {
|
|
|
11981
12153
|
icon: bundle.files.get("icon.png")?.slice() ?? null,
|
|
11982
12154
|
install,
|
|
11983
12155
|
asks,
|
|
11984
|
-
run: this.runStatus(version, this.storeViews(stores), installed?.revocations),
|
|
12156
|
+
run: this.runStatus(version, this.storeViews(stores), [...installed?.revocations ?? [], ...revocations]),
|
|
11985
12157
|
listedBy,
|
|
11986
12158
|
unknownPublisher: !listedBy.some((s) => s.kind === "curated"),
|
|
11987
12159
|
...carried && { carried: true }
|
|
@@ -11998,7 +12170,7 @@ var Apps = class {
|
|
|
11998
12170
|
this.staged.delete(digest);
|
|
11999
12171
|
fail("expired", "Fetch the app again");
|
|
12000
12172
|
}
|
|
12001
|
-
const { bundle, bytes, from, store: fromStore } = staged;
|
|
12173
|
+
const { bundle, bytes, from, store: fromStore, revocations } = staged;
|
|
12002
12174
|
const { manifest } = bundle;
|
|
12003
12175
|
if (!Array.isArray(grant) || !manifest.permissions.every((p) => grant.includes(p))) fail("permissions", "Every permission the app asks for must be granted");
|
|
12004
12176
|
const version = versionOf(manifest, digest);
|
|
@@ -12006,7 +12178,7 @@ var Apps = class {
|
|
|
12006
12178
|
try {
|
|
12007
12179
|
for (;;) {
|
|
12008
12180
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
12009
|
-
const run = this.runStatus(version, this.storeViews(stores), installed?.revocations);
|
|
12181
|
+
const run = this.runStatus(version, this.storeViews(stores), [...installed?.revocations ?? [], ...revocations]);
|
|
12010
12182
|
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
12011
12183
|
if (run.status === "removed") fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
12012
12184
|
const decision = installDecision(installed, version);
|
|
@@ -12038,7 +12210,7 @@ var Apps = class {
|
|
|
12038
12210
|
return this.view(await this.app(version.ref), stores);
|
|
12039
12211
|
}
|
|
12040
12212
|
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
12041
|
-
const next = this.versionRecord(installed, bundle, kind, from, fromStore);
|
|
12213
|
+
const next = withRevocations(this.versionRecord(installed, bundle, kind, from, fromStore), revocations);
|
|
12042
12214
|
if (!await this.putAppIfUnchanged(next, installed)) continue;
|
|
12043
12215
|
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
12044
12216
|
if (installed && installed.digest !== digest) await this.removeBundle(installed.bytes, installed.digest);
|
|
@@ -12154,184 +12326,194 @@ var Apps = class {
|
|
|
12154
12326
|
await this.refreshStores();
|
|
12155
12327
|
const stores = await this.stores();
|
|
12156
12328
|
const out = [];
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12161
|
-
|
|
12162
|
-
|
|
12163
|
-
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
const
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
12193
|
-
|
|
12194
|
-
|
|
12195
|
-
}
|
|
12196
|
-
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
}
|
|
12204
|
-
}
|
|
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
|
+
});
|
|
12205
12377
|
}
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12224
|
-
|
|
12225
|
-
|
|
12226
|
-
|
|
12227
|
-
|
|
12228
|
-
|
|
12229
|
-
const twin = holds && (holds.sequence === app.sequence || holds.sequence === app.pending?.sequence);
|
|
12230
|
-
if (holds && !twin && this.runStatus(holds, this.storeViews(stores), app.revocations).status !== "ok") continue;
|
|
12231
|
-
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;
|
|
12232
12401
|
try {
|
|
12233
|
-
|
|
12402
|
+
peek = await this.peekAt(url);
|
|
12234
12403
|
} catch {
|
|
12235
12404
|
continue;
|
|
12236
12405
|
}
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
if (version.ref !== app.ref || known.has(version.digest)) continue;
|
|
12240
|
-
if (want.digest !== void 0 && version.digest !== want.digest) continue;
|
|
12241
|
-
if (app.pending && version.sequence === app.pending.sequence) {
|
|
12242
|
-
app = {
|
|
12243
|
-
...app,
|
|
12244
|
-
equivocation: {
|
|
12245
|
-
sequence: version.sequence,
|
|
12246
|
-
digest: version.digest,
|
|
12247
|
-
at: this.now()
|
|
12248
|
-
}
|
|
12249
|
-
};
|
|
12250
|
-
outcome = "equivocation";
|
|
12406
|
+
if (!peek || !newer(peek) || want.digest !== void 0 && peek.digest !== want.digest) {
|
|
12407
|
+
if (want.miss) this.listingMisses.set(...want.miss);
|
|
12251
12408
|
continue;
|
|
12252
12409
|
}
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
|
|
12256
|
-
|
|
12257
|
-
|
|
12258
|
-
|
|
12259
|
-
|
|
12260
|
-
|
|
12261
|
-
|
|
12262
|
-
|
|
12263
|
-
|
|
12264
|
-
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
|
|
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()
|
|
12268
12431
|
}
|
|
12269
|
-
continue;
|
|
12270
|
-
}
|
|
12271
|
-
if (this.runStatus(version, this.storeViews(stores), app.revocations).status !== "ok") continue;
|
|
12272
|
-
if (app.pending && version.sequence < app.pending.sequence) continue;
|
|
12273
|
-
const kind = await this.writeBundle(version.digest, bytes);
|
|
12274
|
-
wrote = {
|
|
12275
|
-
bytes: kind,
|
|
12276
|
-
digest: version.digest
|
|
12277
12432
|
};
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
outcome = "updated";
|
|
12288
|
-
} else {
|
|
12289
|
-
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") {
|
|
12290
12442
|
app = {
|
|
12291
12443
|
...app,
|
|
12292
|
-
|
|
12444
|
+
equivocation: {
|
|
12293
12445
|
sequence: version.sequence,
|
|
12294
12446
|
digest: version.digest,
|
|
12295
|
-
manifest: bundle.manifest,
|
|
12296
|
-
added: plan.added,
|
|
12297
|
-
bytes: kind,
|
|
12298
|
-
from: url,
|
|
12299
12447
|
at: this.now()
|
|
12300
12448
|
}
|
|
12301
12449
|
};
|
|
12302
|
-
outcome = "
|
|
12450
|
+
outcome = "equivocation";
|
|
12303
12451
|
}
|
|
12304
|
-
|
|
12452
|
+
continue;
|
|
12305
12453
|
}
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
const
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
...stays,
|
|
12313
|
-
...revocations ?? [],
|
|
12314
|
-
...carried
|
|
12315
|
-
].map((r) => [canonicalJson(r), r]));
|
|
12316
|
-
if ((await this.app(app.ref))?.store === void 0 && app.store !== void 0) {
|
|
12317
|
-
const { store: _s, ...unpinned } = app;
|
|
12318
|
-
app = unpinned;
|
|
12319
|
-
}
|
|
12320
|
-
app = {
|
|
12321
|
-
...app,
|
|
12322
|
-
...merged.size && { revocations: [...merged.values()] },
|
|
12323
|
-
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
|
|
12324
12460
|
};
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
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;
|
|
12333
12488
|
}
|
|
12334
|
-
|
|
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
|
+
};
|
|
12335
12517
|
}
|
|
12336
12518
|
/**
|
|
12337
12519
|
* Fetches an installed app's bundle again when it is not on this device (a profile restored from a backup, which
|
|
@@ -12882,6 +13064,7 @@ function transition(from, profile, to, patch = {}) {
|
|
|
12882
13064
|
state: to
|
|
12883
13065
|
};
|
|
12884
13066
|
if (failed) delete next.breezDatabases;
|
|
13067
|
+
if (to === "active" && !("heldFiles" in patch)) delete next.heldFiles;
|
|
12885
13068
|
return checked(rising(from, next));
|
|
12886
13069
|
}
|
|
12887
13070
|
/** The record with some fields changed and its state kept. */
|
|
@@ -13106,6 +13289,20 @@ function cleanNames(record) {
|
|
|
13106
13289
|
})) } : {}
|
|
13107
13290
|
};
|
|
13108
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
|
+
}
|
|
13109
13306
|
function checked(record) {
|
|
13110
13307
|
return parseDeviceRecord(record);
|
|
13111
13308
|
}
|
|
@@ -16193,6 +16390,17 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16193
16390
|
const earlier = [];
|
|
16194
16391
|
for (const set of record.earlierSets) {
|
|
16195
16392
|
const pending = staying(set.pending);
|
|
16393
|
+
let by;
|
|
16394
|
+
try {
|
|
16395
|
+
by = readSetUpdate(JSON.parse(set.setUpdate))?.by;
|
|
16396
|
+
} catch {}
|
|
16397
|
+
if (!by || !bytesEqual(by, signer.publicKey)) {
|
|
16398
|
+
earlier.push({
|
|
16399
|
+
...set,
|
|
16400
|
+
pending
|
|
16401
|
+
});
|
|
16402
|
+
continue;
|
|
16403
|
+
}
|
|
16196
16404
|
let oldRec;
|
|
16197
16405
|
try {
|
|
16198
16406
|
const was = JSON.parse(set.setUpdate);
|
|
@@ -16945,7 +17153,10 @@ function deviceSetView(record, links) {
|
|
|
16945
17153
|
...record.state === "active" && record.earlierSets.some((set) => set.foreign) ? { foreignSet: true } : {},
|
|
16946
17154
|
...record.setNotice && !record.setNotice.seen ? { notice: record.setNotice.names } : {},
|
|
16947
17155
|
...record.reenroll ? { reenroll: true } : {},
|
|
16948
|
-
...record.state === "active" && record.forks?.length ? {
|
|
17156
|
+
...record.state === "active" && record.forks?.length ? {
|
|
17157
|
+
forks: [...record.forks],
|
|
17158
|
+
forkKeptAt: forkTimes(record)
|
|
17159
|
+
} : {}
|
|
16949
17160
|
};
|
|
16950
17161
|
}
|
|
16951
17162
|
/**
|
|
@@ -16959,6 +17170,10 @@ function handoffNotices(was, handoff, session) {
|
|
|
16959
17170
|
if (handoff && session && was.session && session !== was.session) return [false, true];
|
|
16960
17171
|
return [];
|
|
16961
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
|
+
}
|
|
16962
17177
|
/**
|
|
16963
17178
|
* A native transport of a device link that did not start (a relay that did not answer) or went away (the relay closed
|
|
16964
17179
|
* the connection) is started again after this long, then twice as long each time, up to `NATIVE_RETRY_MAX_MS`. A
|
|
@@ -16983,6 +17198,7 @@ var SET_ACK_FLUSH_MS = 1500;
|
|
|
16983
17198
|
* removal's tombstone hides it.
|
|
16984
17199
|
*/
|
|
16985
17200
|
var DEVICE_TURN_HINT = "device-turn";
|
|
17201
|
+
var TURN_HINT_EVERY_MS = 3e4;
|
|
16986
17202
|
var defaultPeerConnection = () => typeof RTCPeerConnection === "undefined" ? void 0 : () => new RTCPeerConnection({ iceServers: RTC_CONFIG.iceServers });
|
|
16987
17203
|
var DeviceLinks = class {
|
|
16988
17204
|
options;
|
|
@@ -17002,6 +17218,10 @@ var DeviceLinks = class {
|
|
|
17002
17218
|
turnQueue = Promise.resolve();
|
|
17003
17219
|
turnTimer = null;
|
|
17004
17220
|
lastHintRead = 0;
|
|
17221
|
+
/** When a link closing by the other side's doing last made this standby read the turn (`linkLost`). */
|
|
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;
|
|
17005
17225
|
timers = /* @__PURE__ */ new Set();
|
|
17006
17226
|
constructor(options) {
|
|
17007
17227
|
this.options = options;
|
|
@@ -17032,12 +17252,16 @@ var DeviceLinks = class {
|
|
|
17032
17252
|
this.checkAndShow().catch(() => null).finally(() => this.watchTurn(STANDBY_TURN_EVERY_MS + Math.floor(Math.random() * STANDBY_TURN_JITTER_MS)));
|
|
17033
17253
|
}, after);
|
|
17034
17254
|
}
|
|
17035
|
-
/** Reads the turn and, when the device's state
|
|
17255
|
+
/** Reads the turn and, when the device's state, the device it believes or a name in the set changed, tells the pages. */
|
|
17036
17256
|
async checkAndShow() {
|
|
17037
17257
|
const before = await this.record().catch(() => null);
|
|
17038
17258
|
const outcome = await this.checkTurn();
|
|
17039
17259
|
const now = await this.record().catch(() => null);
|
|
17040
|
-
|
|
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
|
+
}
|
|
17041
17265
|
return outcome;
|
|
17042
17266
|
}
|
|
17043
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). */
|
|
@@ -17232,6 +17456,7 @@ var DeviceLinks = class {
|
|
|
17232
17456
|
running.rtcWait = void 0;
|
|
17233
17457
|
}
|
|
17234
17458
|
if (state !== "open") {
|
|
17459
|
+
if (running.agreed && !running.earlier && this.running.get(running.id) === running) this.linkLost().catch(() => {});
|
|
17235
17460
|
running.agreed = false;
|
|
17236
17461
|
this.failPings(running, "The device link closed");
|
|
17237
17462
|
if (running.handoff) {
|
|
@@ -17406,29 +17631,45 @@ var DeviceLinks = class {
|
|
|
17406
17631
|
}
|
|
17407
17632
|
/** Asks the device with this signing key to make a new subscription. False when its link is not live (ask again later). */
|
|
17408
17633
|
askRenew(key) {
|
|
17409
|
-
|
|
17410
|
-
if (!running || running.earlier || !this.isLive(running)) return false;
|
|
17411
|
-
try {
|
|
17412
|
-
running.link.sendDeviceFrame({ t: DEVICE_RENEW_FRAME });
|
|
17413
|
-
return true;
|
|
17414
|
-
} catch {
|
|
17415
|
-
return false;
|
|
17416
|
-
}
|
|
17634
|
+
return this.sendListed(key, { t: DEVICE_RENEW_FRAME });
|
|
17417
17635
|
}
|
|
17418
17636
|
/** Tells the device with this signing key which chats' tokens are handed out under the profile's subscription. */
|
|
17419
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) {
|
|
17420
17648
|
const running = this.find(key);
|
|
17421
17649
|
if (!running || running.earlier || !this.isLive(running)) return false;
|
|
17650
|
+
if (!listedOn(await this.record().catch(() => null), running)) return false;
|
|
17422
17651
|
try {
|
|
17423
|
-
running.link.sendDeviceFrame(
|
|
17424
|
-
t: DEVICE_TOKENS_FRAME,
|
|
17425
|
-
k: tokens
|
|
17426
|
-
});
|
|
17652
|
+
running.link.sendDeviceFrame(frame);
|
|
17427
17653
|
return true;
|
|
17428
17654
|
} catch {
|
|
17429
17655
|
return false;
|
|
17430
17656
|
}
|
|
17431
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
|
+
}
|
|
17432
17673
|
pushQueue = Promise.resolve();
|
|
17433
17674
|
/** The record's push fields are changed one at a time: two frames at once must not write over each other. */
|
|
17434
17675
|
pushExclusive(work) {
|
|
@@ -17436,16 +17677,20 @@ var DeviceLinks = class {
|
|
|
17436
17677
|
this.pushQueue = run;
|
|
17437
17678
|
return run;
|
|
17438
17679
|
}
|
|
17439
|
-
/**
|
|
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
|
+
*/
|
|
17440
17684
|
async deviceWake(from, frame) {
|
|
17441
17685
|
const target = readDeviceWake(frame);
|
|
17442
17686
|
if (target === void 0) return;
|
|
17443
|
-
await this.pushExclusive(async () => {
|
|
17687
|
+
if (!await this.pushExclusive(async () => {
|
|
17444
17688
|
const record = await this.record();
|
|
17445
|
-
if (!record || !record.deviceSet.some((slot) => slot?.key === from)) return;
|
|
17689
|
+
if (!record || !record.deviceSet.some((slot) => slot?.key === from)) return false;
|
|
17446
17690
|
const patch = withOtherPush(record, from, target);
|
|
17447
17691
|
if (patch) await amendDevice(this.options.profile, patch);
|
|
17448
|
-
|
|
17692
|
+
return true;
|
|
17693
|
+
})) return;
|
|
17449
17694
|
try {
|
|
17450
17695
|
await this.options.onDeviceWake?.(from, target);
|
|
17451
17696
|
} catch {}
|
|
@@ -17454,7 +17699,7 @@ var DeviceLinks = class {
|
|
|
17454
17699
|
async shareOwnPush(running) {
|
|
17455
17700
|
const target = await this.pushExclusive(async () => {
|
|
17456
17701
|
const record = await this.record();
|
|
17457
|
-
if (!record) return void 0;
|
|
17702
|
+
if (!record || !listedOn(record, running)) return void 0;
|
|
17458
17703
|
const { target, patch } = ownTargetFor(record, running.key);
|
|
17459
17704
|
if (patch) await amendDevice(this.options.profile, patch);
|
|
17460
17705
|
return target;
|
|
@@ -17537,11 +17782,23 @@ var DeviceLinks = class {
|
|
|
17537
17782
|
await this.acked(running.key);
|
|
17538
17783
|
}
|
|
17539
17784
|
/**
|
|
17540
|
-
* A hint from another device that it holds the turn: read it, at most once in `TURN_HINT_EVERY_MS`.
|
|
17541
|
-
*
|
|
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.
|
|
17542
17789
|
*/
|
|
17543
17790
|
async hinted() {
|
|
17544
|
-
|
|
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
|
+
}
|
|
17545
17802
|
const record = await this.record();
|
|
17546
17803
|
if (record?.state === "active") {
|
|
17547
17804
|
this.lastHintRead = Date.now();
|
|
@@ -17552,6 +17809,19 @@ var DeviceLinks = class {
|
|
|
17552
17809
|
this.lastHintRead = Date.now();
|
|
17553
17810
|
await this.checkAndShow().catch(() => null);
|
|
17554
17811
|
}
|
|
17812
|
+
/**
|
|
17813
|
+
* A standby's live link to another device of its set closed by that device's doing. A removal does this right after
|
|
17814
|
+
* it puts the tombstone, and nothing else tells a screen left in front (no focus, no visibility change) before its
|
|
17815
|
+
* next read, up to 10 minutes away: it would go on offering Use here, which must fail. Read once, as a hint is, at
|
|
17816
|
+
* most once in `TURN_HINT_EVERY_MS`: a network that drops every link at once costs one read.
|
|
17817
|
+
*/
|
|
17818
|
+
async linkLost() {
|
|
17819
|
+
if (!this.options.watchTurn || this.stopped || Date.now() - this.lastLossRead < 3e4) return;
|
|
17820
|
+
this.lastLossRead = Date.now();
|
|
17821
|
+
const record = await this.record();
|
|
17822
|
+
if (!record || record.state === "active" || record.state === "removed") return;
|
|
17823
|
+
await this.checkAndShow();
|
|
17824
|
+
}
|
|
17555
17825
|
/** `key` holds the set under `d` (or the current one): its pending frame is done, and the old link goes. */
|
|
17556
17826
|
async acked(key, d) {
|
|
17557
17827
|
if (!acknowledged(await this.record(), key, d)) return;
|
|
@@ -18056,6 +18326,23 @@ function fileParts(files) {
|
|
|
18056
18326
|
]);
|
|
18057
18327
|
return [...byDigest.values()];
|
|
18058
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
|
+
}
|
|
18059
18346
|
/** Which file ids each digest is. */
|
|
18060
18347
|
function idsOf(files) {
|
|
18061
18348
|
const ids = {};
|
|
@@ -18774,11 +19061,7 @@ var HandoffGiver = class {
|
|
|
18774
19061
|
h: toBase64Url(h),
|
|
18775
19062
|
s: toBase64Url(signed.signature)
|
|
18776
19063
|
};
|
|
18777
|
-
const heldFiles = this.allFiles
|
|
18778
|
-
sha256: file.sha256,
|
|
18779
|
-
size: file.size,
|
|
18780
|
-
id: file.id
|
|
18781
|
-
}));
|
|
19064
|
+
const heldFiles = heldFilesOf(this.allFiles);
|
|
18782
19065
|
const leftFiles = this.allFiles.filter((file) => later.has(file.sha256)).map((file) => ({
|
|
18783
19066
|
sha256: file.sha256,
|
|
18784
19067
|
size: file.size,
|
|
@@ -18994,6 +19277,73 @@ function handoffLinks(links) {
|
|
|
18994
19277
|
};
|
|
18995
19278
|
}
|
|
18996
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
|
|
18997
19347
|
//#region ../browser/src/devices/handoffWallets.ts
|
|
18998
19348
|
/** Wallet types the owner let move on Mainnet (WISP 06 § Decisions, "Mainnet money"). None yet: Testnet first. */
|
|
18999
19349
|
var MAINNET_MOVES = /* @__PURE__ */ new Set();
|
|
@@ -19593,6 +19943,34 @@ async function writeWalletHomes(wallets) {
|
|
|
19593
19943
|
});
|
|
19594
19944
|
}
|
|
19595
19945
|
//#endregion
|
|
19946
|
+
//#region ../browser/src/shared/refusals.ts
|
|
19947
|
+
/**
|
|
19948
|
+
* The ids the engine writes these lines under. A contact's frame names its own id, and one of these shapes fits what a
|
|
19949
|
+
* paired text (22 characters) or a held one may name: the engine stores no frame of a contact's under one
|
|
19950
|
+
* (`GhostlyNode.storeNewMessage`) and takes no edit of one (`receiveEdit`).
|
|
19951
|
+
*/
|
|
19952
|
+
var REFUSAL_ID = /^peer_(?:\d+_refused|spent_[0-9a-f]{32})$/;
|
|
19953
|
+
/** Whether a chat row's id is one a refusal line is written under. */
|
|
19954
|
+
var isRefusalId = (id) => REFUSAL_ID.test(id);
|
|
19955
|
+
/** The English line for `notice`, stored as the row's `text`. */
|
|
19956
|
+
function refusedText(notice) {
|
|
19957
|
+
return `Could not receive ${notice.method === "fedimint" ? "Fedimint ecash" : notice.amount === void 0 ? "a payment" : `${notice.amount.toLocaleString("en-US")} ${notice.network === "testnet" ? "test sats" : "sats"}`}: ${notice.reason}`;
|
|
19958
|
+
}
|
|
19959
|
+
/** The row the engine stores for a refusal: the values, and their English as the text. */
|
|
19960
|
+
function refusedRow(notice) {
|
|
19961
|
+
const values = {
|
|
19962
|
+
type: "paymentRefused",
|
|
19963
|
+
...notice.amount !== void 0 && { amount: notice.amount },
|
|
19964
|
+
...notice.network && { network: notice.network },
|
|
19965
|
+
...notice.method && { method: notice.method },
|
|
19966
|
+
reason: notice.reason
|
|
19967
|
+
};
|
|
19968
|
+
return {
|
|
19969
|
+
text: refusedText(values),
|
|
19970
|
+
notice: values
|
|
19971
|
+
};
|
|
19972
|
+
}
|
|
19973
|
+
//#endregion
|
|
19596
19974
|
//#region ../browser/src/engine/messageDetails.ts
|
|
19597
19975
|
/**
|
|
19598
19976
|
* What the engine remembers about a message's travels (WISP 400 § Message details), and how the details view is put
|
|
@@ -19827,7 +20205,8 @@ var FileDesk = class {
|
|
|
19827
20205
|
kept: () => made.saving,
|
|
19828
20206
|
room: async () => (await fileBytes()).room(),
|
|
19829
20207
|
...this.deps.sendData && { sendData: (id, offset, data) => this.deps.sendData(linkId, id, offset, data) },
|
|
19830
|
-
writable: () => this.deps.writable?.(linkId)
|
|
20208
|
+
writable: () => this.deps.writable?.(linkId),
|
|
20209
|
+
batchConfirms: true
|
|
19831
20210
|
});
|
|
19832
20211
|
this.chats.set(linkId, made);
|
|
19833
20212
|
chat = made;
|
|
@@ -22701,8 +23080,8 @@ var Reactions = class {
|
|
|
22701
23080
|
const e = emoji === "" ? "" : reactionEmoji(emoji);
|
|
22702
23081
|
if (e === null) return { error: "A reaction is one emoji" };
|
|
22703
23082
|
const target = await this.named(chat, messageId);
|
|
22704
|
-
const id = target && replyRef(target,
|
|
22705
|
-
if (!target || !id) return { error:
|
|
23083
|
+
const group = isGroup$1(chat), id = target && replyRef(target, group);
|
|
23084
|
+
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or takes no reaction` };
|
|
22706
23085
|
const current = target.reactions?.me;
|
|
22707
23086
|
if (!e && !current?.e) return { error: "No reaction of yours to take back" };
|
|
22708
23087
|
let last = this.last.get(chat) ?? lastMine(await this.host.messages(chat));
|
|
@@ -23019,17 +23398,17 @@ async function pinnedRow(host, chat, id) {
|
|
|
23019
23398
|
*/
|
|
23020
23399
|
async function myPin(host, chat, messageId, remove, current, now = Date.now()) {
|
|
23021
23400
|
const n = nextPinNumber(current?.n, now);
|
|
23401
|
+
const group = isGroup(chat);
|
|
23022
23402
|
if (remove) return current?.id ? {
|
|
23023
23403
|
id: "",
|
|
23024
23404
|
n,
|
|
23025
23405
|
by: "me",
|
|
23026
23406
|
at: now
|
|
23027
|
-
} : { error:
|
|
23407
|
+
} : { error: `Nothing is pinned in this ${group ? "group" : "chat"}` };
|
|
23028
23408
|
if (typeof messageId !== "string" || !messageId) return { error: "No message to pin" };
|
|
23029
|
-
const group = isGroup(chat);
|
|
23030
23409
|
const target = host.message ? await host.message(chat, messageId) ?? await pinnedRow(host, chat, messageId) : (await host.messages(chat)).find((m) => m.id === messageId) ?? await pinnedRow(host, chat, messageId);
|
|
23031
23410
|
const id = target && replyRef(target, group);
|
|
23032
|
-
if (!target || !id) return { error:
|
|
23411
|
+
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or cannot be pinned` };
|
|
23033
23412
|
return {
|
|
23034
23413
|
id,
|
|
23035
23414
|
n,
|
|
@@ -23505,6 +23884,14 @@ var LOBBY_CHECK_MS = 2e3;
|
|
|
23505
23884
|
var LOBBY_CHECK_JITTER_MS = 3e3;
|
|
23506
23885
|
var REFUSED_FOR_MS$1 = 6e5;
|
|
23507
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;
|
|
23508
23895
|
var RELAYED_KEPT = 4096;
|
|
23509
23896
|
/**
|
|
23510
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,
|
|
@@ -23579,6 +23966,8 @@ var Communities = class {
|
|
|
23579
23966
|
knockAt = /* @__PURE__ */ new Map();
|
|
23580
23967
|
/** Joiners: how many others had a knock still being refreshed in the record I last read (they wait with me). */
|
|
23581
23968
|
knockingWith = /* @__PURE__ */ new Map();
|
|
23969
|
+
/** Joiners: the last `group-full` a member's app answered with, and when. */
|
|
23970
|
+
toldFull = /* @__PURE__ */ new Map();
|
|
23582
23971
|
/** Since when this run knocks with nobody answering (`JOIN_GIVE_UP_MS`), and the joins it gave up (`Groups.giveUpJoin`). */
|
|
23583
23972
|
knockingSince = /* @__PURE__ */ new Map();
|
|
23584
23973
|
gaveUp = /* @__PURE__ */ new Set();
|
|
@@ -23722,8 +24111,10 @@ var Communities = class {
|
|
|
23722
24111
|
viaLink: true,
|
|
23723
24112
|
stage: this.joinStage(group),
|
|
23724
24113
|
since: group.joining.since,
|
|
24114
|
+
...!group.joining.inviter && this.fullSaid(group.id) && { full: this.fullSaid(group.id) },
|
|
23725
24115
|
...this.knockingWith.get(group.id) ? { waiting: this.knockingWith.get(group.id) } : {},
|
|
23726
|
-
...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 }
|
|
23727
24118
|
} : void 0;
|
|
23728
24119
|
if (invitation && !this.keptWhileKnocking(live)) return [{
|
|
23729
24120
|
...base,
|
|
@@ -23781,9 +24172,18 @@ var Communities = class {
|
|
|
23781
24172
|
const joining = group.joining;
|
|
23782
24173
|
if (joining.replaced) return "replaced";
|
|
23783
24174
|
if (joining.inviter) return "admitted";
|
|
24175
|
+
if (this.fullSaid(group.id)) return "full";
|
|
23784
24176
|
if (this.host.linkReady(joining.linkId, 2) || this.host.linkSeen?.(joining.linkId)) return "answered";
|
|
23785
24177
|
return this.knocked.has(group.id) ? "knocked" : "knocking";
|
|
23786
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
|
+
}
|
|
23787
24187
|
async create(name) {
|
|
23788
24188
|
const state = CommunitySession.create(name);
|
|
23789
24189
|
const group = {
|
|
@@ -23848,6 +24248,7 @@ var Communities = class {
|
|
|
23848
24248
|
this.knockRead.delete(link.g);
|
|
23849
24249
|
this.knockingSince.delete(link.g);
|
|
23850
24250
|
this.gaveUp.delete(link.g);
|
|
24251
|
+
this.toldFull.delete(link.g);
|
|
23851
24252
|
const before = this.stored.get(link.g)?.joining;
|
|
23852
24253
|
const linkId = await this.host.openEntry(link, "guest", seedB64, link.host);
|
|
23853
24254
|
if (before && before.linkId !== linkId) await this.host.closeEdge(before.linkId);
|
|
@@ -24868,7 +25269,9 @@ var Communities = class {
|
|
|
24868
25269
|
}
|
|
24869
25270
|
async answerKnocks(groupId, live, now, busy) {
|
|
24870
25271
|
const s = live.session;
|
|
24871
|
-
if (!s.adminWork || !s.entryKey || !s.state.entry.seedB64
|
|
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);
|
|
24872
25275
|
const link = {
|
|
24873
25276
|
g: groupId,
|
|
24874
25277
|
host: s.entryKey
|
|
@@ -24913,7 +25316,7 @@ var Communities = class {
|
|
|
24913
25316
|
const stillKnocking = now - ts < 2 * this.timings.slowKnockMs;
|
|
24914
25317
|
if (rosterHas(s.roster, key)) {
|
|
24915
25318
|
if (!stillKnocking || ts < this.addedAt(s, key) + this.timings.knockFallbackMs) continue;
|
|
24916
|
-
}
|
|
25319
|
+
} else if (full && (door !== s.myKey || live.fullTold.has(key))) continue;
|
|
24917
25320
|
const seen = live.knocksSeen.get(key);
|
|
24918
25321
|
const changed = !!seen && seen.doors !== doorSig;
|
|
24919
25322
|
const first = seen && !changed ? seen.first : now;
|
|
@@ -25050,6 +25453,23 @@ var Communities = class {
|
|
|
25050
25453
|
entryReady(groupId, linkId, peer) {
|
|
25051
25454
|
const live = this.live.get(groupId);
|
|
25052
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
|
+
}
|
|
25053
25473
|
try {
|
|
25054
25474
|
this.host.sendOnLink(linkId, live.session.inviteFrame());
|
|
25055
25475
|
traceJoin(groupId, "invite.sent");
|
|
@@ -25068,6 +25488,7 @@ var Communities = class {
|
|
|
25068
25488
|
if (joining.inviter && joining.inviter !== frame.admin && this.now() - (joining.invitedAt ?? 0) < ENTRY_LINGER_MS$1) return;
|
|
25069
25489
|
joining.invitedAt = this.now();
|
|
25070
25490
|
joining.inviter = frame.admin;
|
|
25491
|
+
this.toldFull.delete(g);
|
|
25071
25492
|
joining.name = groupName(frame.name) ?? joining.name;
|
|
25072
25493
|
joining.pieces = [];
|
|
25073
25494
|
traceJoin(g, "invite.received");
|
|
@@ -25081,6 +25502,18 @@ var Communities = class {
|
|
|
25081
25502
|
this.host.emit();
|
|
25082
25503
|
return;
|
|
25083
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
|
+
}
|
|
25084
25517
|
case "group-accept": {
|
|
25085
25518
|
const live = this.live.get(g);
|
|
25086
25519
|
const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
|
|
@@ -25121,10 +25554,12 @@ var Communities = class {
|
|
|
25121
25554
|
case "group-welcome": {
|
|
25122
25555
|
const joining = group.joining;
|
|
25123
25556
|
if (!joining || joining.linkId !== linkId || !joining.inviter) return;
|
|
25124
|
-
const
|
|
25557
|
+
const inviter = joining.inviter;
|
|
25558
|
+
const joined = await CommunitySession.joinPaced({
|
|
25125
25559
|
g,
|
|
25126
25560
|
host: joining.host
|
|
25127
25561
|
}, joining.pieces, frame, joining.seedB64);
|
|
25562
|
+
if (this.stored.get(g) !== group || group.joining !== joining || joining.linkId !== linkId || joining.inviter !== inviter) return;
|
|
25128
25563
|
if ("error" in joined && joined.error === LINK_REPLACED && !joining.check) {
|
|
25129
25564
|
joining.replaced = true;
|
|
25130
25565
|
joining.inviter = "";
|
|
@@ -25391,6 +25826,7 @@ var Communities = class {
|
|
|
25391
25826
|
lobbyWrites: /* @__PURE__ */ new Map(),
|
|
25392
25827
|
lastKnockPoll: 0,
|
|
25393
25828
|
pendingEntries: /* @__PURE__ */ new Map(),
|
|
25829
|
+
fullTold: /* @__PURE__ */ new Map(),
|
|
25394
25830
|
knocksSeen: /* @__PURE__ */ new Map(),
|
|
25395
25831
|
hubWaits: /* @__PURE__ */ new Map(),
|
|
25396
25832
|
hubsAvoided: /* @__PURE__ */ new Map(),
|
|
@@ -25416,6 +25852,7 @@ var Communities = class {
|
|
|
25416
25852
|
admittedAt: 0,
|
|
25417
25853
|
lastRearm: 0,
|
|
25418
25854
|
lastRoster: session.roster,
|
|
25855
|
+
forkDropped: /* @__PURE__ */ new Set(),
|
|
25419
25856
|
lastStatus: session.status,
|
|
25420
25857
|
relayed: /* @__PURE__ */ new Set()
|
|
25421
25858
|
});
|
|
@@ -25432,15 +25869,19 @@ var Communities = class {
|
|
|
25432
25869
|
else if (statusChanged && s.status === "forked") await this.event(groupId, "forked", s.state.statusReason ?? "The membership history forked", when, s.epoch);
|
|
25433
25870
|
else if (s.status === "active" && before !== after) {
|
|
25434
25871
|
const at = receivedTimestamp(top.ts, when);
|
|
25435
|
-
for (const [key] of after)
|
|
25436
|
-
|
|
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) => {
|
|
25437
25877
|
const chain = s.state.chain;
|
|
25438
|
-
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
|
|
25439
|
-
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;
|
|
25440
25879
|
};
|
|
25441
25880
|
for (const [key] of before) {
|
|
25442
25881
|
if (rosterHas(after, key)) continue;
|
|
25443
|
-
|
|
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);
|
|
25444
25885
|
else await this.event(groupId, "gone", `${name(key)} is no longer a member`, at, top.e, key);
|
|
25445
25886
|
}
|
|
25446
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);
|
|
@@ -25487,6 +25928,8 @@ var MESH_HUB_TIMINGS = {
|
|
|
25487
25928
|
};
|
|
25488
25929
|
/** A hub says whom it reaches this often even when nothing changed: members that cannot read the beacon learn it is one. */
|
|
25489
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;
|
|
25490
25933
|
/** Signed reactions a hub keeps to say again to a member whose edge opens. */
|
|
25491
25934
|
var REACTIONS_KEPT = 64;
|
|
25492
25935
|
/** How long the edge to a member a commit took out stays, for that commit to reach it. */
|
|
@@ -25570,7 +26013,11 @@ var MeshHubs = class {
|
|
|
25570
26013
|
avoided: /* @__PURE__ */ new Map(),
|
|
25571
26014
|
hubsUp: /* @__PURE__ */ new Set(),
|
|
25572
26015
|
seenHubs: /* @__PURE__ */ new Map(),
|
|
26016
|
+
claimed: /* @__PURE__ */ new Map(),
|
|
25573
26017
|
reach: /* @__PURE__ */ new Map(),
|
|
26018
|
+
reachLegacy: /* @__PURE__ */ new Map(),
|
|
26019
|
+
reachHeard: /* @__PURE__ */ new Map(),
|
|
26020
|
+
takesHubs: /* @__PURE__ */ new Set(),
|
|
25574
26021
|
sentReach: "",
|
|
25575
26022
|
lastReach: 0,
|
|
25576
26023
|
met: /* @__PURE__ */ new Map(),
|
|
@@ -25634,6 +26081,9 @@ var MeshHubs = class {
|
|
|
25634
26081
|
const policy = session.hubPolicy, inRoster = (key) => rosterHas(session.roster, key);
|
|
25635
26082
|
const out = new Set(this.listed(live, session, now).map((h) => h.key));
|
|
25636
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
|
+
}
|
|
25637
26087
|
return [...out];
|
|
25638
26088
|
}
|
|
25639
26089
|
/** The beacon's hubs a member counts on (`meshHubs`), but those that said they leave. */
|
|
@@ -25650,6 +26100,8 @@ var MeshHubs = class {
|
|
|
25650
26100
|
live.departed.add(key);
|
|
25651
26101
|
const was = live.seenHubs.delete(key) || live.myHubs.includes(key) || live.beacon.some((h) => h.key === key);
|
|
25652
26102
|
live.reach.delete(key);
|
|
26103
|
+
live.reachLegacy.delete(key);
|
|
26104
|
+
live.claimed.delete(key);
|
|
25653
26105
|
live.hubsUp.delete(key);
|
|
25654
26106
|
live.myHubs = live.myHubs.filter((k) => k !== key);
|
|
25655
26107
|
return was;
|
|
@@ -25695,7 +26147,7 @@ var MeshHubs = class {
|
|
|
25695
26147
|
const out = /* @__PURE__ */ new Set();
|
|
25696
26148
|
for (const [key, until] of live.met) if (until > now) out.add(key);
|
|
25697
26149
|
else live.met.delete(key);
|
|
25698
|
-
const legacy =
|
|
26150
|
+
const legacy = this.legacy(groupId, session, group, live, now);
|
|
25699
26151
|
if (!live.firstRead && now - live.started < this.timings.firstReadMs) for (const key of [...this.host.edges(groupId).keys(), ...group.hubs ?? []]) out.add(key);
|
|
25700
26152
|
else {
|
|
25701
26153
|
const hubs = this.hubs(groupId, session, now);
|
|
@@ -25724,6 +26176,20 @@ var MeshHubs = class {
|
|
|
25724
26176
|
else if (edges.has(key)) out.add(key);
|
|
25725
26177
|
return out;
|
|
25726
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
|
+
}
|
|
25727
26193
|
/** Edges this member keeps in a group: what paces them (`meshEdgeIntervals`), not the roster. */
|
|
25728
26194
|
edgeLoad(groupId, session) {
|
|
25729
26195
|
const live = this.live.get(groupId);
|
|
@@ -25810,7 +26276,7 @@ var MeshHubs = class {
|
|
|
25810
26276
|
*/
|
|
25811
26277
|
counted(live, session, now) {
|
|
25812
26278
|
const keys = new Set(this.listed(live, session, now).map((h) => h.key));
|
|
25813
|
-
for (const [key, at] of
|
|
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);
|
|
25814
26280
|
return keys.size;
|
|
25815
26281
|
}
|
|
25816
26282
|
shape(live) {
|
|
@@ -25839,6 +26305,11 @@ var MeshHubs = class {
|
|
|
25839
26305
|
}
|
|
25840
26306
|
noteHubs(live, session, now) {
|
|
25841
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
|
+
}
|
|
25842
26313
|
for (const [key, at] of live.seenHubs) if (now - at > this.timings.graceMs || !rosterHas(session.roster, key)) live.seenHubs.delete(key);
|
|
25843
26314
|
for (const key of live.departed) if (!rosterHas(session.roster, key)) live.departed.delete(key);
|
|
25844
26315
|
}
|
|
@@ -26001,7 +26472,7 @@ var MeshHubs = class {
|
|
|
26001
26472
|
live.sentReach = said;
|
|
26002
26473
|
live.lastReach = now;
|
|
26003
26474
|
}
|
|
26004
|
-
const legacy = this.legacyOf(groupId);
|
|
26475
|
+
const legacy = this.legacyOf(groupId).filter((key) => up.includes(key));
|
|
26005
26476
|
const frame = {
|
|
26006
26477
|
t: "group-reach",
|
|
26007
26478
|
g: groupId,
|
|
@@ -26032,6 +26503,10 @@ var MeshHubs = class {
|
|
|
26032
26503
|
if (hubs && legacy.delete(key)) changed = true;
|
|
26033
26504
|
if (changed) group.legacy = [...legacy].sort();
|
|
26034
26505
|
const live = this.live.get(groupId);
|
|
26506
|
+
if (live) {
|
|
26507
|
+
if (hubs) live.takesHubs.add(key);
|
|
26508
|
+
else live.takesHubs.delete(key);
|
|
26509
|
+
}
|
|
26035
26510
|
if (live?.hub && this.large(session)) {
|
|
26036
26511
|
if (!this.hubs(groupId, session, now).includes(key)) live.members.set(key, now);
|
|
26037
26512
|
this.sayReach(groupId, session, live, now, key);
|
|
@@ -26065,21 +26540,36 @@ var MeshHubs = class {
|
|
|
26065
26540
|
} catch {}
|
|
26066
26541
|
}
|
|
26067
26542
|
}
|
|
26068
|
-
/**
|
|
26069
|
-
|
|
26070
|
-
|
|
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;
|
|
26071
26551
|
const live = this.get(groupId, now);
|
|
26072
|
-
|
|
26073
|
-
if (
|
|
26074
|
-
|
|
26075
|
-
const
|
|
26076
|
-
|
|
26077
|
-
for (const key of
|
|
26078
|
-
|
|
26079
|
-
|
|
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;
|
|
26080
26563
|
}
|
|
26081
|
-
|
|
26082
|
-
|
|
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);
|
|
26083
26573
|
}
|
|
26084
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. */
|
|
26085
26575
|
viaHub(groupId, session, key, now) {
|
|
@@ -26276,13 +26766,13 @@ var MeshSignals = class {
|
|
|
26276
26766
|
* one of them is a link of the two of us, or reaches the admin (`CarriedHooks.carry`).
|
|
26277
26767
|
*/
|
|
26278
26768
|
carry(groupId, to, payload) {
|
|
26279
|
-
const
|
|
26280
|
-
if (!
|
|
26769
|
+
const carriers = this.carriers(groupId, to);
|
|
26770
|
+
if (!carriers) return {
|
|
26281
26771
|
taken: 0,
|
|
26282
26772
|
sure: false
|
|
26283
26773
|
};
|
|
26284
|
-
const frame = groupSignalFrame(groupId, session.myKey, to, payload);
|
|
26285
|
-
const { links, sure } =
|
|
26774
|
+
const frame = groupSignalFrame(groupId, carriers.session.myKey, to, payload);
|
|
26775
|
+
const { links, sure } = carriers;
|
|
26286
26776
|
let taken = 0;
|
|
26287
26777
|
for (const linkId of links) try {
|
|
26288
26778
|
this.host.sendOnLink(linkId, frame);
|
|
@@ -26293,6 +26783,18 @@ var MeshSignals = class {
|
|
|
26293
26783
|
sure: sure && taken > 0
|
|
26294
26784
|
};
|
|
26295
26785
|
}
|
|
26786
|
+
/** Whether `carry` would hand my packet for the edge to `to` to any link now (`CarriedHooks.canCarry`). */
|
|
26787
|
+
canCarry(groupId, to) {
|
|
26788
|
+
return !!this.carriers(groupId, to)?.links.length;
|
|
26789
|
+
}
|
|
26790
|
+
carriers(groupId, to) {
|
|
26791
|
+
const session = this.scope.session(groupId), group = this.scope.stored(groupId);
|
|
26792
|
+
if (!session || !group || group.left || session.status !== "active" || to === session.myKey || !rosterHas(session.roster, to)) return void 0;
|
|
26793
|
+
return {
|
|
26794
|
+
session,
|
|
26795
|
+
...this.links(groupId, session, group, to)
|
|
26796
|
+
};
|
|
26797
|
+
}
|
|
26296
26798
|
/**
|
|
26297
26799
|
* A `group-signal` that came on `linkId`, whose other end is the member `via` (none: an entry session's admin side
|
|
26298
26800
|
* as the joiner sees it). For me: the edge takes it, and my own packet goes back the same way when theirs was news.
|
|
@@ -26729,6 +27231,19 @@ function invitationClaims(frame) {
|
|
|
26729
27231
|
var FAREWELL_ANSWERS = 3;
|
|
26730
27232
|
/** Commits sent to a removed member that was behind when it left, at most. */
|
|
26731
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
|
+
}
|
|
26732
27247
|
/** Where a member's gossip turns start among the members it is connected to: a number of its own, from its key. */
|
|
26733
27248
|
var gossipStart = (key) => {
|
|
26734
27249
|
let n = 0;
|
|
@@ -27463,6 +27978,7 @@ var Groups = class {
|
|
|
27463
27978
|
return {
|
|
27464
27979
|
me: session.myKey,
|
|
27465
27980
|
community: false,
|
|
27981
|
+
onHubs: this.hubs.active(groupId, session, this.now()),
|
|
27466
27982
|
inRoster: (key) => rosterHas(session.roster, key),
|
|
27467
27983
|
couldRead: (key, messageId, ts) => session.couldRead(key, messageId, ts)
|
|
27468
27984
|
};
|
|
@@ -27714,17 +28230,13 @@ var Groups = class {
|
|
|
27714
28230
|
* where it is in its sync, and gets the commits between (`farewellSync`). No secret goes with any of them.
|
|
27715
28231
|
*/
|
|
27716
28232
|
sayFarewell(groupId, session, group, key, linkId) {
|
|
27717
|
-
const farewell = group.farewells[key]
|
|
27718
|
-
if (!
|
|
28233
|
+
const farewell = group.farewells[key];
|
|
28234
|
+
if (!session.state.chain[farewell.e]) {
|
|
27719
28235
|
this.dropFarewell(group, key);
|
|
27720
28236
|
return;
|
|
27721
28237
|
}
|
|
27722
28238
|
try {
|
|
27723
|
-
this.host.sendOnLink(linkId,
|
|
27724
|
-
t: "group-commit",
|
|
27725
|
-
g: groupId,
|
|
27726
|
-
commit
|
|
27727
|
-
});
|
|
28239
|
+
this.host.sendOnLink(linkId, farewellCommit(groupId, session, farewell.e));
|
|
27728
28240
|
} catch {
|
|
27729
28241
|
return;
|
|
27730
28242
|
}
|
|
@@ -27739,14 +28251,7 @@ var Groups = class {
|
|
|
27739
28251
|
if ((farewell.answered ?? 0) >= FAREWELL_ANSWERS) return;
|
|
27740
28252
|
farewell.answered = (farewell.answered ?? 0) + 1;
|
|
27741
28253
|
try {
|
|
27742
|
-
for (let e = Math.max(from + 1, farewell.e - FAREWELL_COMMITS); e <= farewell.e; e++)
|
|
27743
|
-
const commit = session.state.chain[e];
|
|
27744
|
-
if (commit) this.host.sendOnLink(linkId, {
|
|
27745
|
-
t: "group-commit",
|
|
27746
|
-
g: groupId,
|
|
27747
|
-
commit
|
|
27748
|
-
});
|
|
27749
|
-
}
|
|
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));
|
|
27750
28255
|
} catch {}
|
|
27751
28256
|
farewell.told ??= this.now();
|
|
27752
28257
|
this.store.putGroup(group).catch(() => {});
|
|
@@ -27874,7 +28379,10 @@ var Groups = class {
|
|
|
27874
28379
|
return;
|
|
27875
28380
|
}
|
|
27876
28381
|
const group = this.stored.get(groupId);
|
|
27877
|
-
if (!group?.entry)
|
|
28382
|
+
if (!group?.entry) {
|
|
28383
|
+
if (!this.sessions.get(groupId)?.isAdmin) throw new Error("Only the admin can replace or turn off the group's link");
|
|
28384
|
+
return;
|
|
28385
|
+
}
|
|
27878
28386
|
delete group.entry;
|
|
27879
28387
|
await this.store.putGroup(group);
|
|
27880
28388
|
await this.closeEntries(groupId);
|
|
@@ -28133,6 +28641,10 @@ var Groups = class {
|
|
|
28133
28641
|
sure: false
|
|
28134
28642
|
} : this.signals.carry(groupId, to, payload);
|
|
28135
28643
|
}
|
|
28644
|
+
/** Whether `carrySignal` would hand my packet for the edge to `to` to any link now. */
|
|
28645
|
+
canCarrySignal(groupId, to) {
|
|
28646
|
+
return !this.isCommunity(groupId) && this.signals.canCarry(groupId, to);
|
|
28647
|
+
}
|
|
28136
28648
|
/** My packet for the edge to `to`, over that edge itself while it is up (`MeshSignals.direct`). */
|
|
28137
28649
|
directSignal(groupId, to, linkId, payload) {
|
|
28138
28650
|
return !this.isCommunity(groupId) && this.signals.direct(groupId, to, linkId, payload);
|
|
@@ -28593,8 +29105,7 @@ var Groups = class {
|
|
|
28593
29105
|
return;
|
|
28594
29106
|
}
|
|
28595
29107
|
if (session?.status === "active" && frame && typeof frame === "object" && frame.t === "group-reach") {
|
|
28596
|
-
|
|
28597
|
-
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());
|
|
28598
29109
|
this.host.emit();
|
|
28599
29110
|
return;
|
|
28600
29111
|
}
|
|
@@ -29449,7 +29960,7 @@ function edgeView(live, now = Date.now(), noSlot = false) {
|
|
|
29449
29960
|
linkId: live.stored.id,
|
|
29450
29961
|
state,
|
|
29451
29962
|
...open && live.pairing?.transport ? { transport: live.pairing.transport } : {},
|
|
29452
|
-
lastSeenAt:
|
|
29963
|
+
lastSeenAt: heardAt,
|
|
29453
29964
|
...error ? {
|
|
29454
29965
|
error,
|
|
29455
29966
|
cause
|
|
@@ -29889,7 +30400,7 @@ var GroupEdits = class {
|
|
|
29889
30400
|
refused: true
|
|
29890
30401
|
});
|
|
29891
30402
|
const membership = this.host.membership(groupId);
|
|
29892
|
-
if (!membership) return refuse(
|
|
30403
|
+
if (!membership) return refuse(this.notMember(groupId));
|
|
29893
30404
|
if (typeof messageId !== "string" || typeof raw !== "string") return refuse("No message to edit");
|
|
29894
30405
|
const chat = chatOf(groupId);
|
|
29895
30406
|
const message = await this.find(chat, messageId);
|
|
@@ -29939,7 +30450,7 @@ var GroupEdits = class {
|
|
|
29939
30450
|
error,
|
|
29940
30451
|
refused: true
|
|
29941
30452
|
});
|
|
29942
|
-
if (!this.host.membership(groupId)) return refuse(
|
|
30453
|
+
if (!this.host.membership(groupId)) return refuse(this.notMember(groupId));
|
|
29943
30454
|
const chat = chatOf(groupId);
|
|
29944
30455
|
const message = typeof messageId === "string" ? await this.find(chat, messageId) : void 0;
|
|
29945
30456
|
if (!message || message.removed || message.sender !== "me" || !GROUP_MESSAGE_ID.test(message.id)) return refuse("Only your own messages can be deleted for everyone");
|
|
@@ -29957,6 +30468,10 @@ var GroupEdits = class {
|
|
|
29957
30468
|
messageId
|
|
29958
30469
|
};
|
|
29959
30470
|
}
|
|
30471
|
+
/** What an edit or a removal in a group I am not in is refused with: the group's reason, as a message or a reaction is. */
|
|
30472
|
+
notMember(groupId) {
|
|
30473
|
+
return this.host.notMember?.(groupId) ?? "You are not in this group";
|
|
30474
|
+
}
|
|
29960
30475
|
/** Says my pending edits in a group, oldest first, at the pace allowed; what waits goes when the window has room. */
|
|
29961
30476
|
flush(groupId) {
|
|
29962
30477
|
const running = this.flushing.get(groupId);
|
|
@@ -30747,6 +31262,27 @@ var REPUBLISH_MS = 36e5;
|
|
|
30747
31262
|
var HOLD_FETCH_MS = 2e4;
|
|
30748
31263
|
var HOLD_FETCH_BYTES_PER_S = 65536;
|
|
30749
31264
|
var holdFetchTimeoutMs = (max) => HOLD_FETCH_MS + Math.ceil(max / HOLD_FETCH_BYTES_PER_S) * 1e3;
|
|
31265
|
+
/** Why a pickup waits: its storage would see this device's address, which the person hides from contacts. */
|
|
31266
|
+
var HOLD_HIDDEN_IP = "Hide my IP from contacts is on: what your contact held for you waits on their storage until you turn it off.";
|
|
31267
|
+
/** Thrown where an address is about to be read, so a pickup stops there and starts again once it may. */
|
|
31268
|
+
var HiddenIpError = class extends Error {
|
|
31269
|
+
constructor() {
|
|
31270
|
+
super(HOLD_HIDDEN_IP);
|
|
31271
|
+
}
|
|
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
|
+
}
|
|
30750
31286
|
var hex$2 = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
30751
31287
|
/**
|
|
30752
31288
|
* Store-and-forward for away contacts (WISP 404, `hold/1`), on both ends of every chat that turned it
|
|
@@ -31329,8 +31865,11 @@ var HoldEngine = class {
|
|
|
31329
31865
|
...hold,
|
|
31330
31866
|
peerAck: pointer.ack
|
|
31331
31867
|
});
|
|
31868
|
+
const wasHidden = this.errors.get(linkId) === HOLD_HIDDEN_IP;
|
|
31869
|
+
if (wasHidden) this.errors.delete(linkId);
|
|
31332
31870
|
if (pointer.top <= hold.inSeq) {
|
|
31333
31871
|
this.expecting.delete(linkId);
|
|
31872
|
+
if (wasHidden) this.host.changed();
|
|
31334
31873
|
return;
|
|
31335
31874
|
}
|
|
31336
31875
|
if (!pointer.manifestUrl || pointer.expires <= now) {
|
|
@@ -31356,7 +31895,8 @@ var HoldEngine = class {
|
|
|
31356
31895
|
refused: this.state(linkId).refused + 1
|
|
31357
31896
|
});
|
|
31358
31897
|
this.errors.set(linkId, `Refused what the contact's storage offered: ${error.message}`);
|
|
31359
|
-
} else this.errors.set(linkId,
|
|
31898
|
+
} else if (error instanceof HiddenIpError) this.errors.set(linkId, HOLD_HIDDEN_IP);
|
|
31899
|
+
else this.errors.set(linkId, `Could not pick up held items: ${error instanceof Error ? error.message : String(error)}`);
|
|
31360
31900
|
this.host.changed();
|
|
31361
31901
|
return;
|
|
31362
31902
|
}
|
|
@@ -31490,7 +32030,7 @@ var HoldEngine = class {
|
|
|
31490
32030
|
this.errors.set(linkId, `Refused a held item from the contact: ${error.message}`);
|
|
31491
32031
|
changed = true;
|
|
31492
32032
|
} else {
|
|
31493
|
-
this.errors.set(linkId, `Could not pick up held items: ${error instanceof Error ? error.message : String(error)}`);
|
|
32033
|
+
this.errors.set(linkId, error instanceof HiddenIpError ? HOLD_HIDDEN_IP : `Could not pick up held items: ${error instanceof Error ? error.message : String(error)}`);
|
|
31494
32034
|
stop = true;
|
|
31495
32035
|
}
|
|
31496
32036
|
}
|
|
@@ -31526,6 +32066,8 @@ var HoldEngine = class {
|
|
|
31526
32066
|
}
|
|
31527
32067
|
async readBytes(url, max, signal) {
|
|
31528
32068
|
if (!isHoldUrl(url, this.host.loopbackStorage?.())) throw new Error("The storage address is not one this app reads");
|
|
32069
|
+
const places = this.host.hiddenIpPlaces?.();
|
|
32070
|
+
if (places && !places.some((place) => underPlace(url, place))) throw new HiddenIpError();
|
|
31529
32071
|
const response = await (this.host.fetch ?? ((...args) => fetch(...args)))(url, {
|
|
31530
32072
|
cache: "no-store",
|
|
31531
32073
|
credentials: "omit",
|
|
@@ -32670,26 +33212,6 @@ var S3Store = class {
|
|
|
32670
33212
|
}
|
|
32671
33213
|
};
|
|
32672
33214
|
//#endregion
|
|
32673
|
-
//#region ../browser/src/shared/refusals.ts
|
|
32674
|
-
/** The English line for `notice`, stored as the row's `text`. */
|
|
32675
|
-
function refusedText(notice) {
|
|
32676
|
-
return `Could not receive ${notice.method === "fedimint" ? "Fedimint ecash" : notice.amount === void 0 ? "a payment" : `${notice.amount.toLocaleString("en-US")} ${notice.network === "testnet" ? "test sats" : "sats"}`}: ${notice.reason}`;
|
|
32677
|
-
}
|
|
32678
|
-
/** The row the engine stores for a refusal: the values, and their English as the text. */
|
|
32679
|
-
function refusedRow(notice) {
|
|
32680
|
-
const values = {
|
|
32681
|
-
type: "paymentRefused",
|
|
32682
|
-
...notice.amount !== void 0 && { amount: notice.amount },
|
|
32683
|
-
...notice.network && { network: notice.network },
|
|
32684
|
-
...notice.method && { method: notice.method },
|
|
32685
|
-
reason: notice.reason
|
|
32686
|
-
};
|
|
32687
|
-
return {
|
|
32688
|
-
text: refusedText(values),
|
|
32689
|
-
notice: values
|
|
32690
|
-
};
|
|
32691
|
-
}
|
|
32692
|
-
//#endregion
|
|
32693
33215
|
//#region ../browser/src/engine/wallet.ts
|
|
32694
33216
|
/**
|
|
32695
33217
|
* The peer's Cashu wallet. Ecash is custodial: the mint holds the sats and the
|
|
@@ -37690,6 +38212,14 @@ var NATIVE_SLOTS = 8;
|
|
|
37690
38212
|
* links listen there as well), and each of the CLI's is a whole DHT node.
|
|
37691
38213
|
*/
|
|
37692
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;
|
|
37693
38223
|
/** Of a transport's listeners, the ones a group's links never hold: 1:1 chats keep that room. */
|
|
37694
38224
|
var CHAT_NATIVE_SLOTS = 4;
|
|
37695
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. */
|
|
@@ -37747,6 +38277,13 @@ var REACTION_RESEND_MS = 3e4;
|
|
|
37747
38277
|
var pkarrSeenAt = (messages) => messages.reduce((max, m) => m.sender === "peer" && m.via === "pkarr" ? Math.max(max, m.sentAt ?? m.timestamp) : max, 0);
|
|
37748
38278
|
/** A file or a payment request of mine that waits for the chat to be live (a text that waits is its outbox's). */
|
|
37749
38279
|
var waitsForLive = (m) => m.sender === "me" && m.delivery === "waiting" && (!!m.file || !!m.paymentId);
|
|
38280
|
+
/** A message of mine whose card went as its text alone and is due to go again live (`restoreCards`). */
|
|
38281
|
+
var cardDue = (m) => m.sender === "me" && (m.cardRestore ?? m.buttonsRestore) === "due";
|
|
38282
|
+
/** The id a 1:1 chat's row goes by on both sides when its own row is not `peer_`/`me_` and that id (`resolveReply`). */
|
|
38283
|
+
var unkeyedRef = (m) => {
|
|
38284
|
+
const ref = replyRef(m, false);
|
|
38285
|
+
return ref && m.id !== `peer_${ref}` && m.id !== `me_${ref}` ? ref : void 0;
|
|
38286
|
+
};
|
|
37750
38287
|
/** This side's participation key in a chat: derived from its seed once, not at every state built. */
|
|
37751
38288
|
/** A read of the contact's packet that found it as the last one did: online the same, the same packet, name and services. */
|
|
37752
38289
|
var samePresence = (a, b) => a.online === b.online && a.lastPacketAt === b.lastPacketAt && a.seenAt === b.seenAt && a.nick === b.nick && JSON.stringify(a.services) === JSON.stringify(b.services);
|
|
@@ -37993,6 +38530,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37993
38530
|
* Not one queue for all: a transport slow to start held every other chat's listeners of every kind behind it.
|
|
37994
38531
|
*/
|
|
37995
38532
|
nativeQueues = /* @__PURE__ */ new Map();
|
|
38533
|
+
/** Per transport, whether a start is under way, and the starts waiting their turn (`nativeTurn`). */
|
|
38534
|
+
nativeTurns = /* @__PURE__ */ new Map();
|
|
37996
38535
|
/** Every listener start asked for so far has ended. */
|
|
37997
38536
|
get nativeQueue() {
|
|
37998
38537
|
return Promise.all(this.nativeQueues.values()).then(() => {});
|
|
@@ -38636,6 +39175,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38636
39175
|
changed: () => this.emitState(),
|
|
38637
39176
|
fetch: (...request) => (this.options.holdFetch ?? globalThis.fetch)(...request),
|
|
38638
39177
|
loopbackStorage: () => this.options.holdLoopback === true,
|
|
39178
|
+
hiddenIpPlaces: () => {
|
|
39179
|
+
if (this.settings.relayOnly !== true) return null;
|
|
39180
|
+
try {
|
|
39181
|
+
return this.settings.holdStorage?.s3 ? [holdStoragePlace(this.settings.holdStorage.s3)] : [];
|
|
39182
|
+
} catch {
|
|
39183
|
+
return [];
|
|
39184
|
+
}
|
|
39185
|
+
},
|
|
38639
39186
|
ttlMs: () => {
|
|
38640
39187
|
const raw = testSwitch("ghostly-test-hold-ttl");
|
|
38641
39188
|
const ms = raw ? Number(raw) : NaN;
|
|
@@ -38689,6 +39236,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38689
39236
|
},
|
|
38690
39237
|
linkIds: () => [...this.links.keys()],
|
|
38691
39238
|
online: () => this.networkOn,
|
|
39239
|
+
relayOnly: () => this.settings.relayOnly === true,
|
|
38692
39240
|
emit: () => {
|
|
38693
39241
|
this.emitState();
|
|
38694
39242
|
this.did.changed();
|
|
@@ -38814,7 +39362,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38814
39362
|
online: () => this.networkOn,
|
|
38815
39363
|
emit: () => this.emitState(),
|
|
38816
39364
|
eligible: () => this.profileSubjects(),
|
|
38817
|
-
nostrRelays: () => effectiveNostrSettings(this.settings.nostr).relays
|
|
39365
|
+
nostrRelays: () => effectiveNostrSettings(this.settings.nostr).relays,
|
|
39366
|
+
relayOnly: () => this.settings.relayOnly === true,
|
|
39367
|
+
own: () => this.ownProfileSubjects()
|
|
38818
39368
|
});
|
|
38819
39369
|
/** A contact's verified identity's posts and follows, asked when its card is chosen (PUBLIC-PROFILES.md, "Posts and follows"). */
|
|
38820
39370
|
publicActivity = new PublicActivity({
|
|
@@ -38822,17 +39372,20 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38822
39372
|
online: () => this.networkOn,
|
|
38823
39373
|
eligible: () => this.profileSubjects(),
|
|
38824
39374
|
nostrRelays: () => effectiveNostrSettings(this.settings.nostr).relays,
|
|
38825
|
-
own: () =>
|
|
38826
|
-
|
|
38827
|
-
return this.identities.views().filter((p) => p.expiresAt > t).map((p) => ({
|
|
38828
|
-
provider: p.provider,
|
|
38829
|
-
subject: p.verified.subject
|
|
38830
|
-
}));
|
|
38831
|
-
},
|
|
39375
|
+
own: () => this.ownProfileSubjects(),
|
|
39376
|
+
relayOnly: () => this.settings.relayOnly === true,
|
|
38832
39377
|
contacts: () => this.contactSubjects(),
|
|
38833
39378
|
ownNostrFollows: () => this.nostrSocial.ownFollows(),
|
|
38834
39379
|
nostrMuted: (note, author) => this.nostrSocial.hides(note, author)
|
|
38835
39380
|
});
|
|
39381
|
+
/** The profile's own identities with a current proof. */
|
|
39382
|
+
ownProfileSubjects() {
|
|
39383
|
+
const t = Math.floor(Date.now() / 1e3);
|
|
39384
|
+
return this.identities.views().filter((p) => p.expiresAt > t).map((p) => ({
|
|
39385
|
+
provider: p.provider,
|
|
39386
|
+
subject: p.verified.subject
|
|
39387
|
+
}));
|
|
39388
|
+
}
|
|
38836
39389
|
/** What contacts shared that verifies now, with the chat it came in (paired chats only). */
|
|
38837
39390
|
contactSubjects() {
|
|
38838
39391
|
const t = Math.floor(Date.now() / 1e3);
|
|
@@ -39102,6 +39655,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39102
39655
|
admin: !!view?.isAdmin
|
|
39103
39656
|
};
|
|
39104
39657
|
},
|
|
39658
|
+
notMember: (groupId) => this.groups.view(groupId)?.statusReason,
|
|
39105
39659
|
send: (groupId, edit, to) => this.groups.sendEdit(groupId, edit, to),
|
|
39106
39660
|
remove: (chat, id) => this.forgetGroupMessage(chat, id),
|
|
39107
39661
|
removeMine: async (chat, message, removal) => {
|
|
@@ -39545,6 +40099,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39545
40099
|
const files = linkFilesFrom(stored.id, storedFiles, messages);
|
|
39546
40100
|
this.links.set(stored.id, newLiveLink(stored, messages[messages.length - 1]?.timestamp ?? 0, files));
|
|
39547
40101
|
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
40102
|
+
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
39548
40103
|
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
39549
40104
|
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
39550
40105
|
const note = latestReaction(messages);
|
|
@@ -40768,6 +41323,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40768
41323
|
*/
|
|
40769
41324
|
async deviceWakeReceived(from, target) {
|
|
40770
41325
|
if (!this.ownDeviceKey || this.shuttingDown) return;
|
|
41326
|
+
if (!(await readDeviceRecord(databaseName()).catch(() => null))?.deviceSet.some((slot) => slot?.key === from)) return;
|
|
40771
41327
|
const before = this.settings.wake;
|
|
40772
41328
|
const asked = this.settings.wakeRenew?.[from];
|
|
40773
41329
|
if (asked !== void 0 && (!target || target.endpoint !== asked)) {
|
|
@@ -40860,7 +41416,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40860
41416
|
this.renewAsked.delete(key);
|
|
40861
41417
|
continue;
|
|
40862
41418
|
}
|
|
40863
|
-
if (
|
|
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));
|
|
40864
41424
|
}
|
|
40865
41425
|
}
|
|
40866
41426
|
/** What each device was last told of the chats' tokens, by its signing key. */
|
|
@@ -40882,7 +41442,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40882
41442
|
this.sentTokens.delete(view.key);
|
|
40883
41443
|
continue;
|
|
40884
41444
|
}
|
|
40885
|
-
if (this.sentTokens.get(view.key)
|
|
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);
|
|
40886
41454
|
}
|
|
40887
41455
|
}
|
|
40888
41456
|
/**
|
|
@@ -41469,7 +42037,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41469
42037
|
}
|
|
41470
42038
|
};
|
|
41471
42039
|
}
|
|
41472
|
-
if (!original && !group) {
|
|
42040
|
+
if (!original && !group && live) {
|
|
42041
|
+
const id = (await this.unkeyedRowsOf(this.links.get(message.linkId))).get(reply.id);
|
|
42042
|
+
const row = id === void 0 || id === message.id ? void 0 : await db.getMessage(message.linkId, id);
|
|
42043
|
+
if (row && replyRef(row) === reply.id) original = row;
|
|
42044
|
+
} else if (!original && !group) {
|
|
41473
42045
|
history = await db.getMessages(message.linkId);
|
|
41474
42046
|
original = history.find((m) => m.id !== message.id && replyRef(m) === reply.id);
|
|
41475
42047
|
}
|
|
@@ -41644,6 +42216,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41644
42216
|
const live = this.links.get(linkId);
|
|
41645
42217
|
if (!live?.stored.profile || live.stored.group) return false;
|
|
41646
42218
|
const id = `peer_${edit.id}`;
|
|
42219
|
+
if (isRefusalId(id)) return true;
|
|
41647
42220
|
const ref = edit.rm && !await this.namesMine(linkId, edit.id);
|
|
41648
42221
|
if (live.stored.deletedIds?.includes(id)) {
|
|
41649
42222
|
if (ref) {
|
|
@@ -41713,7 +42286,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41713
42286
|
*/
|
|
41714
42287
|
async cardWentBare(linkId, message) {
|
|
41715
42288
|
if (!message.card || message.cardRestore || message.buttonsRestore) return;
|
|
41716
|
-
await db.patchMessage(linkId, message.id, (current) => current.sender === "me" && current.card && !current.cardRestore && !current.buttonsRestore ? { cardRestore: "due" } : null);
|
|
42289
|
+
if (await db.patchMessage(linkId, message.id, (current) => current.sender === "me" && current.card && !current.cardRestore && !current.buttonsRestore ? { cardRestore: "due" } : null)) this.links.get(linkId)?.cardsDue?.then((known) => known.add(message.id), () => {});
|
|
42290
|
+
}
|
|
42291
|
+
/** `cardsDue`: a chat loaded at the start has them from that read; any other reads its history once in a run. */
|
|
42292
|
+
cardsDueOf(live) {
|
|
42293
|
+
return live.cardsDue ??= db.getMessages(live.stored.id).then((history) => new Set(history.filter(cardDue).map((m) => m.id)), (error) => {
|
|
42294
|
+
live.cardsDue = void 0;
|
|
42295
|
+
throw error;
|
|
42296
|
+
});
|
|
41717
42297
|
}
|
|
41718
42298
|
/** The session capability a contact's app lists when it shows a card of this kind, so a restore edit reads as a card there. */
|
|
41719
42299
|
static cardCapability(card) {
|
|
@@ -41737,7 +42317,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41737
42317
|
const live = this.links.get(linkId), link = live?.link;
|
|
41738
42318
|
const offers = link?.sessionOffers.peer;
|
|
41739
42319
|
if (!live?.stored.profile || live.stored.group || !link?.supportsEdits || !offers) return;
|
|
42320
|
+
const due = await this.cardsDueOf(live);
|
|
42321
|
+
if (!due.size) return;
|
|
42322
|
+
const asked = new Set(due);
|
|
41740
42323
|
const mine = (await db.getMessages(linkId)).filter((m) => m.sender === "me").sort((a, b) => b.timestamp - a.timestamp);
|
|
42324
|
+
for (const id of asked) due.delete(id);
|
|
42325
|
+
for (const message of mine) if (cardDue(message)) due.add(message.id);
|
|
41741
42326
|
const since = Date.now() - CARD_RESTORE_MS;
|
|
41742
42327
|
const changed = [];
|
|
41743
42328
|
const cards = /* @__PURE__ */ new Set();
|
|
@@ -41750,7 +42335,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41750
42335
|
const stale = superseded || kept++ >= CARD_RESTORE_MOST || message.timestamp < since;
|
|
41751
42336
|
if (!stale && message.card && !offers.includes(GhostlyNode.cardCapability(message.card))) continue;
|
|
41752
42337
|
const at = Date.now();
|
|
41753
|
-
|
|
42338
|
+
const patched = await db.patchMessage(linkId, message.id, (current) => {
|
|
41754
42339
|
if (current.sender !== "me" || (current.cardRestore ?? current.buttonsRestore) !== "due") return null;
|
|
41755
42340
|
const done = {
|
|
41756
42341
|
cardRestore: "sent",
|
|
@@ -41773,7 +42358,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41773
42358
|
},
|
|
41774
42359
|
...done
|
|
41775
42360
|
};
|
|
41776
|
-
})
|
|
42361
|
+
});
|
|
42362
|
+
due.delete(message.id);
|
|
42363
|
+
if (patched?.edit?.pending) {
|
|
41777
42364
|
changed.push(message.id);
|
|
41778
42365
|
this.editsFor(linkId).edited(message.id);
|
|
41779
42366
|
}
|
|
@@ -42835,6 +43422,16 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42835
43422
|
}
|
|
42836
43423
|
if (waiting.length) await this.messagesChanged(linkId, waiting.map((m) => m.id));
|
|
42837
43424
|
}
|
|
43425
|
+
/** The rows of a chat a reply names by another id than their own (`unkeyedRef`), read once in a run. */
|
|
43426
|
+
unkeyedRowsOf(live) {
|
|
43427
|
+
return live.unkeyedRows ??= db.getMessages(live.stored.id).then((history) => new Map(history.flatMap((m) => {
|
|
43428
|
+
const ref = unkeyedRef(m);
|
|
43429
|
+
return ref ? [[ref, m.id]] : [];
|
|
43430
|
+
})), (error) => {
|
|
43431
|
+
live.unkeyedRows = void 0;
|
|
43432
|
+
throw error;
|
|
43433
|
+
});
|
|
43434
|
+
}
|
|
42838
43435
|
/**
|
|
42839
43436
|
* The ids of my messages that wait for the live link (`waitsForLive`). A chat loaded at the start has them from that
|
|
42840
43437
|
* read; any other reads its history once in a run. A session that opens then reads those rows, however long the chat.
|
|
@@ -43114,6 +43711,31 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43114
43711
|
await live.link.setTransportPreference(automaticTransport(live.link.availableTransports), true, true);
|
|
43115
43712
|
this.capsChanged(linkId);
|
|
43116
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
|
+
}
|
|
43117
43739
|
/** The chat's connection story, for paired chats (not group edges). */
|
|
43118
43740
|
/**
|
|
43119
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
|
|
@@ -43473,7 +44095,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43473
44095
|
note(check.error);
|
|
43474
44096
|
continue;
|
|
43475
44097
|
}
|
|
43476
|
-
const original = message.file,
|
|
44098
|
+
const original = message.file, picked = {
|
|
43477
44099
|
id: groupFileId(groupId, "out"),
|
|
43478
44100
|
name: original.name,
|
|
43479
44101
|
size: original.size,
|
|
@@ -43482,11 +44104,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43482
44104
|
...original.video && { video: original.video },
|
|
43483
44105
|
...original.image && { image: original.image }
|
|
43484
44106
|
};
|
|
43485
|
-
await copyForForward(original.id, {
|
|
44107
|
+
const file = await copyForForward(original.id, {
|
|
43486
44108
|
linkId: to,
|
|
43487
|
-
wireId:
|
|
44109
|
+
wireId: picked.id.slice(`group-${groupId}-out-`.length),
|
|
43488
44110
|
timestamp: now(),
|
|
43489
|
-
file
|
|
44111
|
+
file: picked
|
|
43490
44112
|
});
|
|
43491
44113
|
const sent = await this.sendGroupFile({
|
|
43492
44114
|
groupId,
|
|
@@ -43507,7 +44129,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43507
44129
|
continue;
|
|
43508
44130
|
}
|
|
43509
44131
|
const original = message.file, wireId = toBase64Url(randomBytes(12)), timestamp = now();
|
|
43510
|
-
const
|
|
44132
|
+
const picked = {
|
|
43511
44133
|
id: GhostlyNode.outgoingFileId(to, wireId),
|
|
43512
44134
|
name: original.name,
|
|
43513
44135
|
size: original.size,
|
|
@@ -43516,11 +44138,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43516
44138
|
...original.video && { video: original.video },
|
|
43517
44139
|
...original.image && { image: original.image }
|
|
43518
44140
|
};
|
|
43519
|
-
await copyForForward(original.id, {
|
|
44141
|
+
const file = await copyForForward(original.id, {
|
|
43520
44142
|
linkId: to,
|
|
43521
44143
|
wireId,
|
|
43522
44144
|
timestamp,
|
|
43523
|
-
file
|
|
44145
|
+
file: picked
|
|
43524
44146
|
});
|
|
43525
44147
|
try {
|
|
43526
44148
|
await this.sendFile({
|
|
@@ -45099,6 +45721,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45099
45721
|
return this.settings.shareProfile === false ? void 0 : this.settings.avatar || void 0;
|
|
45100
45722
|
}
|
|
45101
45723
|
async updateSettings({ settings: patch }) {
|
|
45724
|
+
const wrongKind = settingsPatchProblem(patch);
|
|
45725
|
+
if (wrongKind) throw new Error(wrongKind);
|
|
45102
45726
|
const { nostr, ...rest } = patch;
|
|
45103
45727
|
const settings = rest;
|
|
45104
45728
|
delete settings.backupReminders;
|
|
@@ -45115,7 +45739,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45115
45739
|
if (settings.relays && (this.relays || this.transport.configure) && !settings.relays.some((relay) => normalizeRelayUrl(relay))) throw new Error("Enter at least one relay address (https://…)");
|
|
45116
45740
|
if (settings.readRelays !== void 0 && typeof settings.readRelays !== "boolean") throw new Error("readRelays is on or off");
|
|
45117
45741
|
if (settings.irohRelays) {
|
|
45118
|
-
if (settings.irohRelays.length >
|
|
45742
|
+
if (settings.irohRelays.length > 5) throw new Error("Use at most five Iroh relays");
|
|
45119
45743
|
for (const relay of settings.irohRelays) {
|
|
45120
45744
|
const problem = irohRelayProblem(relay);
|
|
45121
45745
|
if (problem) throw new Error(problem);
|
|
@@ -45139,6 +45763,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45139
45763
|
delete settings.wakeMutedGroups;
|
|
45140
45764
|
delete settings.wakeHeldBy;
|
|
45141
45765
|
delete settings.wakeRenew;
|
|
45766
|
+
delete settings.groupTransports;
|
|
45142
45767
|
delete settings.walletSetup;
|
|
45143
45768
|
const relayBefore = this.hyperdhtRelay;
|
|
45144
45769
|
if (nostr) {
|
|
@@ -45241,6 +45866,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45241
45866
|
this.did.publishNow().catch(() => {});
|
|
45242
45867
|
if (!this.options.singleDevice && knownDeviceGate()?.state === "active") this.startDeviceSet({ justRead: true }).catch(() => {});
|
|
45243
45868
|
} else if (wasOnline && this.networkOn && relayOnlyChanged) await this.restartLinksForRelayOnly();
|
|
45869
|
+
if (relayOnlyChanged && this.settings.relayOnly !== true) this.hold.wake();
|
|
45244
45870
|
if (wasOnline && !this.networkOn) this.stopGroupEntries();
|
|
45245
45871
|
if (wasOnline && !this.networkOn) await this.hold.stop();
|
|
45246
45872
|
const gate = knownDeviceGate();
|
|
@@ -45516,15 +46142,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45516
46142
|
run();
|
|
45517
46143
|
this.tombstoneTimer ??= setInterval(() => void run(), GhostlyNode.TOMBSTONE_EVERY_MS);
|
|
45518
46144
|
}
|
|
45519
|
-
/**
|
|
45520
|
-
|
|
45521
|
-
|
|
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`);
|
|
45522
46151
|
if (this.limitedMode) throw new Error(LIMITED_MODE_ERROR);
|
|
45523
|
-
if (!this.networkOn) throw new Error(
|
|
46152
|
+
if (!this.networkOn) throw new Error(`${prefix}-offline: You are offline`);
|
|
45524
46153
|
const view = this.enrollment?.current();
|
|
45525
|
-
if (view && view.step !== "done" && view.step !== "failed") throw new Error(
|
|
46154
|
+
if (view && view.step !== "done" && view.step !== "failed") throw new Error(`${prefix}-busy: A device is being added. Try again after it.`);
|
|
45526
46155
|
const handoff = this.handoffGiver?.view();
|
|
45527
|
-
if (handoff && handoff.step !== "failed") throw new Error(
|
|
46156
|
+
if (handoff && handoff.step !== "failed") throw new Error(`${prefix}-busy: The profile is moving. Try again after it.`);
|
|
45528
46157
|
}
|
|
45529
46158
|
async moveDeviceSet(remove) {
|
|
45530
46159
|
this.setMoveAllowed();
|
|
@@ -45611,6 +46240,36 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45611
46240
|
if (typeof key !== "string" || !key) throw new Error("remove-device: Name the device to remove.");
|
|
45612
46241
|
return this.moveDeviceSet(key);
|
|
45613
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
|
+
}
|
|
45614
46273
|
/** "New device secret": the set moves to a new secret with nobody removed. */
|
|
45615
46274
|
async deviceNewSecret() {
|
|
45616
46275
|
return this.moveDeviceSet();
|
|
@@ -46014,7 +46673,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46014
46673
|
const host = handoffProfileHost();
|
|
46015
46674
|
if (!host) throw new Error("This app cannot discard it");
|
|
46016
46675
|
await host.staging.drop(database);
|
|
46017
|
-
|
|
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
|
+
});
|
|
46018
46685
|
this.emitState();
|
|
46019
46686
|
}
|
|
46020
46687
|
async deviceTurnPeek({ d }) {
|
|
@@ -46277,12 +46944,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46277
46944
|
const member = () => entry || this.groups.isCommunityGroup(group) || this.groups.inRoster(group, peer);
|
|
46278
46945
|
let seen = false;
|
|
46279
46946
|
const native = this.keepsGroupNative(stored);
|
|
46280
|
-
const
|
|
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";
|
|
46281
46949
|
live.pairing = { status: "connecting" };
|
|
46282
46950
|
live.edgeStartedAt = Date.now();
|
|
46283
46951
|
live.carried?.stop();
|
|
46284
46952
|
live.carried = entry || this.groups.isCommunityGroup(group) ? void 0 : new CarriedTransport(this.groupTransport, live.myPubKeyZ32, stored.peerPubKeyZ32, {
|
|
46285
46953
|
carry: (payload) => this.groups.carrySignal(group, peer, payload),
|
|
46954
|
+
canCarry: () => this.groups.canCarrySignal(group, peer),
|
|
46286
46955
|
open: () => !!live.link?.isDataLinkOpen,
|
|
46287
46956
|
look: () => live.link?.look(),
|
|
46288
46957
|
direct: (payload) => this.groups.directSignal(group, peer, linkId, payload),
|
|
@@ -46308,7 +46977,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46308
46977
|
largeFilesSupport: !entry,
|
|
46309
46978
|
binaryFilesSupport: !entry,
|
|
46310
46979
|
params: stored,
|
|
46311
|
-
rtcAvailable: typeof RTCPeerConnection !== "undefined" && !this.edgeRtcOff.has(linkId),
|
|
46980
|
+
rtcAvailable: typeof RTCPeerConnection !== "undefined" && !this.edgeRtcOff.has(linkId) && !this.groupNativeChoice(stored),
|
|
46312
46981
|
resume: !entry && stored.edgeLive ? resumeOn : void 0,
|
|
46313
46982
|
native: {
|
|
46314
46983
|
peerDescriptors: stored.peerDescriptors,
|
|
@@ -46317,7 +46986,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46317
46986
|
automatic: true
|
|
46318
46987
|
},
|
|
46319
46988
|
packetTransports: !this.options.webrtcGroupLinks,
|
|
46320
|
-
packetTransportsSaid: !!stored.transportSeeds && Object.keys(stored.transportSeeds).length > 0,
|
|
46989
|
+
packetTransportsSaid: !!stored.transportSeeds && Object.keys(stored.transportSeeds).length > 0 || !!chosen,
|
|
46321
46990
|
resumeFloor: !entry && stored.edgeLive ? stored.edgeLiveSince : void 0,
|
|
46322
46991
|
pairing: {
|
|
46323
46992
|
credentials: {
|
|
@@ -46476,7 +47145,27 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46476
47145
|
*/
|
|
46477
47146
|
keepsGroupNative(stored) {
|
|
46478
47147
|
if (this.options.webrtcGroupLinks) return false;
|
|
46479
|
-
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];
|
|
46480
47169
|
}
|
|
46481
47170
|
/**
|
|
46482
47171
|
* An edge's WebRTC attempt exchanged both descriptions and connected nothing, or found no candidate at all
|
|
@@ -47118,7 +47807,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47118
47807
|
nativeFactoriesFor(relayOnly) {
|
|
47119
47808
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
47120
47809
|
return {
|
|
47121
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
47810
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-D185dETu.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
47122
47811
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
47123
47812
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
47124
47813
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, { relays: this.irohRelays }) } : {}
|
|
@@ -47132,17 +47821,58 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47132
47821
|
if (this.options.irohRelays?.length) return [...this.options.irohRelays];
|
|
47133
47822
|
return this.settings.irohRelays?.length ? this.settings.irohRelays : [...DEFAULT_IROH_RELAYS];
|
|
47134
47823
|
}
|
|
47135
|
-
/** 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`). */
|
|
47136
47825
|
async rehomeIroh() {
|
|
47137
47826
|
if (!this.options.irohWeb && !this.ownIrohRelays) return;
|
|
47138
47827
|
this.deviceLinks?.nativeChanged(["iroh/1"]);
|
|
47139
47828
|
for (const [linkId, live] of this.links) {
|
|
47140
47829
|
const link = live.link;
|
|
47141
|
-
if (!link?.availableTransports.includes("iroh/1")
|
|
47830
|
+
if (!link?.availableTransports.includes("iroh/1")) continue;
|
|
47831
|
+
if (!link.canReleaseEndpoint("iroh/1")) {
|
|
47832
|
+
this.nativeMoved(linkId).add("iroh/1");
|
|
47833
|
+
continue;
|
|
47834
|
+
}
|
|
47142
47835
|
await link.releaseEndpoint("iroh/1");
|
|
47143
47836
|
this.ensureNativeEndpoints(linkId);
|
|
47144
47837
|
}
|
|
47145
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
|
+
}
|
|
47146
47876
|
/** The HyperDHT relay a browser reaches the HyperDHT through; empty when none is set. */
|
|
47147
47877
|
get hyperdhtRelay() {
|
|
47148
47878
|
return (this.settings.hyperdhtRelay ?? "").trim();
|
|
@@ -47186,7 +47916,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47186
47916
|
if (this.hyperdhtRelay && link && this.keepsNativeEndpoints(linkId, live.stored)) this.ensureNativeEndpoints(linkId);
|
|
47187
47917
|
continue;
|
|
47188
47918
|
}
|
|
47189
|
-
if (!link.canReleaseEndpoint("hyperdht/1"))
|
|
47919
|
+
if (!link.canReleaseEndpoint("hyperdht/1")) {
|
|
47920
|
+
this.nativeMoved(linkId).add("hyperdht/1");
|
|
47921
|
+
continue;
|
|
47922
|
+
}
|
|
47190
47923
|
await link.releaseEndpoint("hyperdht/1");
|
|
47191
47924
|
if (live.transportErrors) delete live.transportErrors["hyperdht/1"];
|
|
47192
47925
|
if (this.hyperdhtRelay) this.ensureNativeEndpoints(linkId);
|
|
@@ -47340,8 +48073,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47340
48073
|
const expected = this.links.get(linkId)?.link;
|
|
47341
48074
|
const starts = Object.entries(this.nativeFactories).map(([transport, factory]) => {
|
|
47342
48075
|
const key = transport;
|
|
47343
|
-
const operation =
|
|
47344
|
-
this.nativeQueues.set(key, operation.then(() => {}, () => {}));
|
|
48076
|
+
const operation = this.nativeTurn(key, linkId, inUse).then(() => factory ? this.startNativeEndpoint(linkId, expected, key, factory, inUse) : false).finally(() => this.nextNativeTurn(key, true));
|
|
48077
|
+
this.nativeQueues.set(key, Promise.all([this.nativeQueues.get(key), operation.then(() => {}, () => {})]).then(() => {}));
|
|
47345
48078
|
return operation;
|
|
47346
48079
|
});
|
|
47347
48080
|
return Promise.all(starts).then((full) => {
|
|
@@ -47362,9 +48095,52 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47362
48095
|
this.emitState();
|
|
47363
48096
|
});
|
|
47364
48097
|
}
|
|
47365
|
-
/**
|
|
48098
|
+
/**
|
|
48099
|
+
* A start's turn in its transport's queue: one at a time, in the order asked, but the chat in use (on screen, a text
|
|
48100
|
+
* going or coming in it, an edge of the group on screen) goes before the others waiting. With the relay out of reach
|
|
48101
|
+
* each start takes 10 s to fail, and the chat opened waited for every other chat's retry before its own started or
|
|
48102
|
+
* said why: 331 s with 40 chats.
|
|
48103
|
+
*/
|
|
48104
|
+
nativeTurn(key, linkId, inUse) {
|
|
48105
|
+
let lane = this.nativeTurns.get(key);
|
|
48106
|
+
if (!lane) this.nativeTurns.set(key, lane = {
|
|
48107
|
+
busy: false,
|
|
48108
|
+
waiting: []
|
|
48109
|
+
});
|
|
48110
|
+
const turn = new Promise((go) => lane.waiting.push({
|
|
48111
|
+
linkId,
|
|
48112
|
+
inUse,
|
|
48113
|
+
go
|
|
48114
|
+
}));
|
|
48115
|
+
this.nextNativeTurn(key);
|
|
48116
|
+
return turn;
|
|
48117
|
+
}
|
|
48118
|
+
/** `ended`: the start under way ended. The next one waiting starts: the first in use, or else the first asked. */
|
|
48119
|
+
nextNativeTurn(key, ended = false) {
|
|
48120
|
+
const lane = this.nativeTurns.get(key);
|
|
48121
|
+
if (!lane) return;
|
|
48122
|
+
if (ended) lane.busy = false;
|
|
48123
|
+
if (lane.busy || !lane.waiting.length) return;
|
|
48124
|
+
const onScreen = (linkId) => {
|
|
48125
|
+
const stored = this.links.get(linkId)?.stored;
|
|
48126
|
+
return !!stored && (stored.group ? `group:${stored.group}` : stored.id) === this.activeLinkId;
|
|
48127
|
+
};
|
|
48128
|
+
const next = lane.waiting.findIndex((start) => start.inUse || onScreen(start.linkId));
|
|
48129
|
+
const [start] = lane.waiting.splice(Math.max(next, 0), 1);
|
|
48130
|
+
lane.busy = true;
|
|
48131
|
+
start.go();
|
|
48132
|
+
}
|
|
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
|
+
*/
|
|
47366
48137
|
nativeSlots(key) {
|
|
47367
|
-
|
|
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);
|
|
47368
48144
|
}
|
|
47369
48145
|
/** Of those, what its groups' links may hold, all groups together. */
|
|
47370
48146
|
groupNativeSlots(key) {
|
|
@@ -47390,6 +48166,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47390
48166
|
if (this.shuttingDown || !live?.stored.profile || live.stored.deliveryMode === "dht" || !link || link !== expected || link.takenFromUs) return false;
|
|
47391
48167
|
const group = !!live.stored.group;
|
|
47392
48168
|
if (group && !this.keepsGroupNative(live.stored)) return false;
|
|
48169
|
+
if (group && !this.groupNatives(live.stored).includes(key)) return false;
|
|
47393
48170
|
if (link.availableTransports.includes(key)) return false;
|
|
47394
48171
|
live.transportErrors ??= {};
|
|
47395
48172
|
try {
|
|
@@ -47411,7 +48188,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47411
48188
|
const extra = (other) => !!other.stored.group && !other.stored.groupEntry && !onScreen(other) && anchorOf(other.stored.group) !== other && !this.chosenByPeer(other, key);
|
|
47412
48189
|
const full = owners.length >= slots, entry = !!live.stored.groupEntry;
|
|
47413
48190
|
if (group && (entry || extra(live)) && (full || groups >= this.groupNativeSlots(key) || !entry && !anchorOf(live.stored.group)?.link?.availableTransports.includes(key))) return "no-slot";
|
|
47414
|
-
if (full || !group && owners.length - groups >=
|
|
48191
|
+
if (full || !group && owners.length - groups >= this.chatNativeSlots(key)) {
|
|
47415
48192
|
const paired = !group && live.pairedAt !== void 0 && now - live.pairedAt < 6e5 ? live.pairedAt : void 0;
|
|
47416
48193
|
const taking = group || this.activeLinkId === linkId || inUse || paired !== void 0;
|
|
47417
48194
|
const mine = taking && (inUse || onScreen(live)) ? now : Math.max(paired ?? 0, used(live));
|
|
@@ -47557,21 +48334,25 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47557
48334
|
groupNativeRetryAt = 0;
|
|
47558
48335
|
/** Chats and group links whose native listener failed to start, by link id: when each tries again, and how long it waited last. */
|
|
47559
48336
|
nativeFailed = /* @__PURE__ */ new Map();
|
|
48337
|
+
/** Of those, the ones whose start is queued or under way: a transport's starts go one after another. */
|
|
48338
|
+
nativeRetrying = /* @__PURE__ */ new Set();
|
|
47560
48339
|
/**
|
|
47561
48340
|
* Now and then, the group links that found no free native slot try again: a chat or another group may have let one go.
|
|
47562
48341
|
* Chats and group links whose listener failed to start try again once their wait is over.
|
|
47563
48342
|
*/
|
|
47564
48343
|
retryNative() {
|
|
47565
48344
|
this.groupAnchorsAnswered();
|
|
48345
|
+
this.moveNative();
|
|
47566
48346
|
const now = Date.now();
|
|
47567
48347
|
for (const [linkId, failed] of this.nativeFailed) {
|
|
47568
|
-
if (now < failed.at) continue;
|
|
48348
|
+
if (now < failed.at || this.nativeRetrying.has(linkId)) continue;
|
|
47569
48349
|
if (!this.links.get(linkId)?.link) {
|
|
47570
48350
|
this.nativeFailed.delete(linkId);
|
|
47571
48351
|
continue;
|
|
47572
48352
|
}
|
|
47573
48353
|
failed.at = now + failed.wait;
|
|
47574
|
-
this.
|
|
48354
|
+
this.nativeRetrying.add(linkId);
|
|
48355
|
+
this.ensureNativeEndpoints(linkId).finally(() => this.nativeRetrying.delete(linkId));
|
|
47575
48356
|
}
|
|
47576
48357
|
if (!this.groupNativeWaiting.size || Date.now() < this.groupNativeRetryAt) return;
|
|
47577
48358
|
this.groupNativeRetryAt = Date.now() + NATIVE_RETRY_MS;
|
|
@@ -47735,6 +48516,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47735
48516
|
* straight from its author (`clockSample`). `place`: as `placed`.
|
|
47736
48517
|
*/
|
|
47737
48518
|
async storeNewMessage(message, straight = false, place) {
|
|
48519
|
+
if (message.sender === "peer" && !message.notice && isRefusalId(message.id)) return false;
|
|
47738
48520
|
const edge = this.links.get(message.linkId)?.stored;
|
|
47739
48521
|
if (edge?.group && edge.groupPeer && !edge.groupEntry) message = {
|
|
47740
48522
|
...message,
|
|
@@ -47780,6 +48562,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47780
48562
|
}
|
|
47781
48563
|
if (!await db.addMessage(message)) return false;
|
|
47782
48564
|
if (live && waitsForLive(message)) live.waitingSends?.then((known) => known.add(message.id), () => {});
|
|
48565
|
+
const unkeyed = live && !live.stored.group && unkeyedRef(message);
|
|
48566
|
+
if (unkeyed) live.unkeyedRows?.then((rows) => rows.set(unkeyed, message.id), () => {});
|
|
48567
|
+
if (live && cardDue(message)) live.cardsDue?.then((due) => due.add(message.id), () => {});
|
|
47783
48568
|
this.clockSample(message, straight);
|
|
47784
48569
|
const newest = this.newestAt.get(message.linkId);
|
|
47785
48570
|
if (!message.event) this.newestAt.set(message.linkId, Math.max(newest ?? 0, writtenAt(message, this.clockLeads.get(this.clockOf(message)))));
|
|
@@ -48247,4 +49032,4 @@ function signalKind(signal) {
|
|
|
48247
49032
|
//#endregion
|
|
48248
49033
|
export { EngineServer };
|
|
48249
49034
|
|
|
48250
|
-
//# sourceMappingURL=server-
|
|
49035
|
+
//# sourceMappingURL=server-Dw1o8z1o.js.map
|