@ghostlytools/cli 1.11.2 → 1.11.4
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 +34 -28
- package/SKILL.md +4 -2
- package/dist/assets/{api-CtXgscmK.js → api-BwyFq4lA.js} +2 -2
- package/dist/assets/{api-BM3PsXbB.js → api-MYc6QNRs.js} +306 -114
- package/dist/assets/api-MYc6QNRs.js.map +1 -0
- package/dist/assets/{apiKit-lCTQ0EBG.js → apiKit-CfsNx9ZR.js} +62 -16
- package/dist/assets/apiKit-CfsNx9ZR.js.map +1 -0
- package/dist/assets/{appFetch-BKHy5H8J.js → appFetch-DVYZOZFw.js} +3 -3
- package/dist/assets/{appFetch-BKHy5H8J.js.map → appFetch-DVYZOZFw.js.map} +1 -1
- package/dist/assets/{apps-DO_gAZgm.js → apps-Dbw2Hcko.js} +1 -1
- package/dist/assets/{apps-Do26w3c7.js → apps-h12II1us.js} +150 -57
- package/dist/assets/apps-h12II1us.js.map +1 -0
- package/dist/assets/{arkade-CZrLbz-M.js → arkade-Bw_4PZRG.js} +2 -2
- package/dist/assets/{arkade-CZrLbz-M.js.map → arkade-Bw_4PZRG.js.map} +1 -1
- package/dist/assets/{backup-D21x1f5P.js → backup-CdEzTq5C.js} +1 -1
- package/dist/assets/{backup-j47AzDvG.js → backup-Chvy79SN.js} +60 -55
- package/dist/assets/backup-Chvy79SN.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{buttons-CiGlBVBT.js → buttons-BgoExb4E.js} +37 -7
- package/dist/assets/buttons-BgoExb4E.js.map +1 -0
- package/dist/assets/buttons-DK2aAGat.js +2 -0
- package/dist/assets/{client-raIncVtF.js → client-DY8tZZWi.js} +28 -8
- package/dist/assets/client-DY8tZZWi.js.map +1 -0
- package/dist/assets/{codec-DcG2AeyE.js → codec-BnMg-Grj.js} +2 -2
- package/dist/assets/{codec-DcG2AeyE.js.map → codec-BnMg-Grj.js.map} +1 -1
- package/dist/assets/{envelope-Dud6lntA.js → envelope-CdV7vHVZ.js} +2 -2
- package/dist/assets/{envelope-Dud6lntA.js.map → envelope-CdV7vHVZ.js.map} +1 -1
- package/dist/assets/{errors-Dt-ZnyOX.js → errors-CAh6GLJZ.js} +27 -2
- package/dist/assets/errors-CAh6GLJZ.js.map +1 -0
- package/dist/assets/{fedimintSdk-DRKRSw14.js → fedimintSdk-CPFfVK-G.js} +2 -2
- package/dist/assets/{fedimintSdk-DRKRSw14.js.map → fedimintSdk-CPFfVK-G.js.map} +1 -1
- package/dist/assets/{fixedHosts-CNX7QiUD.js → fixedHosts-CbgqrIKs.js} +3 -3
- package/dist/assets/{fixedHosts-CNX7QiUD.js.map → fixedHosts-CbgqrIKs.js.map} +1 -1
- package/dist/assets/{host-8RskzQgB.js → host-C0NMNQLl.js} +702 -143
- package/dist/assets/host-C0NMNQLl.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-uAThbFub.js → hyperdhtRelay-Dz7pvcBA.js} +2 -2
- package/dist/assets/{hyperdhtRelay-uAThbFub.js.map → hyperdhtRelay-Dz7pvcBA.js.map} +1 -1
- package/dist/assets/{irohWeb-DGelfgDJ.js → irohWeb-caAj4Dms.js} +19 -12
- package/dist/assets/irohWeb-caAj4Dms.js.map +1 -0
- package/dist/assets/{main-BC33ooYg.js → main-C6t5zrD5.js} +383 -110
- package/dist/assets/main-C6t5zrD5.js.map +1 -0
- package/dist/assets/{mainline-DYrjsS1t.js → mainline-DCuGUSZF.js} +35 -18
- package/dist/assets/mainline-DCuGUSZF.js.map +1 -0
- package/dist/assets/{networkReason-n2oBs4by.js → networkReason-BbQW1Xpc.js} +3 -3
- package/dist/assets/{networkReason-n2oBs4by.js.map → networkReason-BbQW1Xpc.js.map} +1 -1
- package/dist/assets/{nwc-Do3VSlIS.js → nwc-CSDRMZ0e.js} +3 -3
- package/dist/assets/{nwc-Do3VSlIS.js.map → nwc-CSDRMZ0e.js.map} +1 -1
- package/dist/assets/{nwcProvider-Du5aWNIn.js → nwcProvider-PE0wli8n.js} +2 -2
- package/dist/assets/{nwcProvider-Du5aWNIn.js.map → nwcProvider-PE0wli8n.js.map} +1 -1
- package/dist/assets/{ownDid-CwwYu8s2.js → ownDid-C1R5Kd8q.js} +2 -2
- package/dist/assets/{ownDid-CwwYu8s2.js.map → ownDid-C1R5Kd8q.js.map} +1 -1
- package/dist/assets/{ownStatus-D7dB4zJB.js → ownStatus-BoTf5WqQ.js} +27 -9
- package/dist/assets/ownStatus-BoTf5WqQ.js.map +1 -0
- package/dist/assets/{profiles-NyF5FnYF.js → profiles-DszHjEJi.js} +25 -10
- package/dist/assets/profiles-DszHjEJi.js.map +1 -0
- package/dist/assets/{registry-DKDInr0A.js → registry-Da-r6eC3.js} +30 -12
- package/dist/assets/registry-Da-r6eC3.js.map +1 -0
- package/dist/assets/{registry-C734VrO9.js → registry-zUZBSHYv.js} +1 -1
- package/dist/assets/{resolve-3Tqh9AWQ.js → resolve-tUzh4lHh.js} +2 -2
- package/dist/assets/{resolve-3Tqh9AWQ.js.map → resolve-tUzh4lHh.js.map} +1 -1
- package/dist/assets/{secretGuard-B7Hj0Kvz.js → secretGuard-CsVHDdYk.js} +68 -6
- package/dist/assets/{secretGuard-B7Hj0Kvz.js.map → secretGuard-CsVHDdYk.js.map} +1 -1
- package/dist/assets/secretGuard-DCb1I0_B.js +2 -0
- package/dist/assets/{server-B6PQ6iae.js → server-C1jZZ61O.js} +896 -277
- package/dist/assets/server-C1jZZ61O.js.map +1 -0
- package/dist/assets/{src-ChJijTlM.js → src-DJe-OYxd.js} +1010 -236
- package/dist/assets/src-DJe-OYxd.js.map +1 -0
- package/dist/assets/{sshForges-Brf0fslM.js → sshForges-C9zTO72R.js} +4 -3
- package/dist/assets/sshForges-C9zTO72R.js.map +1 -0
- package/dist/assets/{translate-xLme9Rdh.js → translate-CUuC5szR.js} +36 -15
- package/dist/assets/translate-CUuC5szR.js.map +1 -0
- package/dist/assets/{usdt-CSU5KzTV.js → usdt-DI51znt-.js} +3 -3
- package/dist/assets/{usdt-CSU5KzTV.js.map → usdt-DI51znt-.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/assets/api-BM3PsXbB.js.map +0 -1
- package/dist/assets/apiKit-lCTQ0EBG.js.map +0 -1
- package/dist/assets/apps-Do26w3c7.js.map +0 -1
- package/dist/assets/backup-j47AzDvG.js.map +0 -1
- package/dist/assets/buttons-CiGlBVBT.js.map +0 -1
- package/dist/assets/buttons-D2l2bVCG.js +0 -2
- package/dist/assets/client-raIncVtF.js.map +0 -1
- package/dist/assets/errors-Dt-ZnyOX.js.map +0 -1
- package/dist/assets/host-8RskzQgB.js.map +0 -1
- package/dist/assets/irohWeb-DGelfgDJ.js.map +0 -1
- package/dist/assets/main-BC33ooYg.js.map +0 -1
- package/dist/assets/mainline-DYrjsS1t.js.map +0 -1
- package/dist/assets/ownStatus-D7dB4zJB.js.map +0 -1
- package/dist/assets/profiles-NyF5FnYF.js.map +0 -1
- package/dist/assets/registry-DKDInr0A.js.map +0 -1
- package/dist/assets/secretGuard-DUr6bgKc.js +0 -2
- package/dist/assets/server-B6PQ6iae.js.map +0 -1
- package/dist/assets/src-ChJijTlM.js.map +0 -1
- package/dist/assets/sshForges-Brf0fslM.js.map +0 -1
- package/dist/assets/translate-xLme9Rdh.js.map +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $
|
|
2
|
+
import { $ as mentionsMember, $a as parseVideoMeta, $c as inboxRecord, $l as readCanonicalJson, $n as INVITE_TAKEN, $r as transferStalled, $s as HANDOFF_VERIFIED, $t as signDidDhtPacket, $u as budgetRetryMs, A as encodeGroupEntryLink, Ai as isServeId, Ar as pickMeshHubs, As as RTC_CONFIG, Au as TURN_MAX, B as parseGroupWakeFrame, Ba as dhtFileId, Bi as DHT_TEXT_CAPABILITY, Bl as isAppKey, Bn as parseFedimintRequestPayload, Br as mergeLobby, Bs as HTTP_SERVICE_PROTO, Bu as turnVerifierMark, C as GROUP_READ_NOTE_COMMUNITY, Cc as readHandoffDone, Cd as randomBytes, Ci as newWakeToken, Co as pairedReplyAuthor, Cs as webLocalFetch, Cu as webCryptoSigner, D as routedCommunityFrame, Dc as readHandoffTurnFrame, Dd as utf8Encode, Di as checkPushEndpoint, Dr as MESH_HUBS, Du as classifyTurnRead, E as encodeCommunityLink, Ec as readHandoffPake, Ed as utf8Decode, Ei as wakeRequest, Eo as BUTTON_ID, Er as readGroupSignal, Es as encodeControl, Eu as TURN_SETTLE_MS, F as readKnocks, Fc as signTombstone, Fi as BUTTONS_CAPABILITY, Fl as appFingerprint, Fn as cashuRequestPayload, Fr as freshHubs, Fs as contactRtcConfig, Fu as signTurnRelease, G as frameBytes, Gc as enrollGrantFrame, Gr as readBeaconHead, Gs as HANDOFF_DONE, Ha as sanitizeFileName, Hc as enrollCancelReason, Hi as dialDescriptors, Hl as isAppRef, Ho as sameButtonText, Hr as pickHubs, Hs as serviceIdFromName, Ic as verifySetUpdate, Ii as EDIT_CAPABILITY, Il as appRef, In as fedimintRequestPayload, Ir as hubRank, Iu as turnInstance, Jc as readEnrollGrant, Jo as heardTime, Jr as ChatFiles, Js as HANDOFF_OFFER, Jt as didDhtDocument, Ju as normalizeRelayUrl, K as CatchUpAnswers, Kc as enrollHelloFrame, Ko as arrivalKey, Kr as readLobby, Ks as HANDOFF_HAVE, L as GroupWakeLimiter, La as DHT_MESSAGE_TTL, Li as STATUS_CARD_CAPABILITY, Ll as appRefPublisher, Ln as findEndpoint, Lr as lobbyKeys, Ls as parseCallSignal, Lu as turnKeys, M as knockIdentity, Mc as readSetUpdate, Mi as chatAppId, Ml as sha256Paced, Mr as beaconKeys, Mu as nextTurnPosition, N as knockRecords, Nc as setAckFrame, Ni as isAppVersion, Nn as decodeBolt11, Nr as beaconRecords, Nu as readTurnPacket, Oc as readHandoffVerified, Oi as vapidKeysMatch, Or as mayBeHub, Ou as turnPutSummary, P as mergeKnocks, Pc as setUpdateFrame, Pi as APPS_CAPABILITY, Pl as APP_STATEMENT_LIMITS, Pn as ENDPOINT, Po as STATUS_CARD_LIMITS, Pr as doorHubs, Pu as signTurnPacket, Q as parseCommunityEdit, Qc as endedRequests, Ql as canonicalJsonBytes, Qn as GhostLink, Qo as GROUP_MEMBER_CAP, Qr as transferEnded, Qs as HANDOFF_TIMINGS, R as groupWakeFrame, Ra as peekDhtMailbox, Ri as UPGRADE_CAPABILITY, Rn as isFederationId, Rr as lobbyRecords, Ru as turnName, S as CommunitySession, Sc as readHandoffCancel, Si as deviceWakeRequest, Sl as APP_BUNDLE_MAGIC, Sn as isPubkyKey, So as wireReaction, Ss as parseLocalTarget, Su as seedSigner, T as decodeCommunityLink, Tc as readHandoffHello, Td as toZ32, Ti as relayRequest, Tl as appViewOf, To as replySnippet, Tr as groupSignalFrame, Ts as decodeControl, Tu as TURN_RAISE_READ_TIMEOUT_MS, U as GROUP_READ_NOTE, Ua as sanitizeMime, Uc as enrollDigits, Ul as readAppRevocation, Ur as rankHubs, Us as HANDOFF_ACK, V as GROUP_LIMITS, Va as formatFileSize, Vc as enrollCancelFrame, Vi as capsDescriptors, Vo as checkStatusCard, Vr as newerHead, Vs as LEGACY_SERVICES, Vu as DEFAULT_RELAYS, W as GroupSession, Wc as enrollDoneFrame, Wl as readAppRevocationShape, Wo as statusCardText, Wr as readBeacon, Ws as HANDOFF_CANCEL, Wu as RelayTransport, X as carryMentions, Xa as parseVoiceMeta, Xc as verifyEnrollProof, Xi as emptyIdentityLedger, Xo as shownTime, Xs as HANDOFF_PIECE_BYTES, Xt as encodeDidDhtDeactivated, Y as GROUP_EDIT_TEXT_BYTES, Ya as fileMessageText, Yc as readEnrollHello, Yl as parseImageMeta, Yo as receivedTimestamp, Yr as FILE_LIMITS, Ys as HANDOFF_PAKE, Yt as didDhtFromPublicKey, Z as meshMessageRef, Zc as clearMissed, Zl as canonicalJson, Zo as GROUP_ADMIN_OFF_ERROR, Zr as sentWhole, Zs as HANDOFF_REQUEST, Zt as encodeDidDhtPacket, Zu as traceLink, _ as GroupTypingBoard, _a as HoldRefusedError, _c as handoffRetryAfter, _d as hasVisible, _i as WAKE_CALL_INTERVAL_MS, _l as readKnockSlot, _n as SPARK_PROVIDER, _o as queueReaction, _s as RELAY_POLL_INTERVALS, _u as deviceEchoNonce, a as appRevocationFor, aa as PeerProofs, ac as handoffBusyFrame, al as ContactRequestError, ao as dhtEditId, ar as EngineError, as as verifyCommitSignature, au as readDeviceInvite, b as sealGroupTyping, ba as readManifest, bc as newHandoffId, bd as bytesEqual, bl as seenEntry, bn as isBitcoinAddress, bo as readReaction, br as CarriedTransport, bs as GhostlyHttpError, bt as isAtprotoDid, bu as devicePingFrame, c as checkAppBeforeRun, ca as TRANSPORTS, cc as handoffContextProof, cd as createIdentity, cl as contactAskerHolds, cn as WALLET_NETWORKS, cr as parseEngineError, cs as RatchetBox, cu as decodeInviteCode, dc as handoffEphemeral, dd as publicKeyFromZ32, di as PIN_LIMITS, dl as knockSlotOf, dn as assertWholeSats, do as readForwarded, ds as DirectPathWatch, du as inviteOwnership, ec as NO_ATTEMPTS, ed as isDiscoveryBudgetError, el as newInbox, en as ETHEREUM_USDT, eo as EDIT_BUFFER_MS, er as LIVENESS_PING_MS, es as MEMBER_KEY, et as groupName, eu as createContactLink, fc as handoffHelloFrame, fi as mayPin, fl as knockSlotRecords, fn as formatPaymentAmount, fo as COMMUNITY_REACTION_FRAME, ga as HoldKeys, gc as handoffReleaseFrame, gi as readPin, gl as openRequest, gn as SPARK_NETWORKS, go as nextReactionNumber, gr as readGroupFileMeta, gs as PRESENCE_WINDOW, gu as deviceEchoFrame, ha as HOLD_LIMITS, hc as handoffPakeFrame, hd as sanitizeAvatar, hi as pinNumberHolds, hl as mergeContactKnocks, hn as walletNetworkOf, ho as ReactionWindow, hu as HANDOFF_CAPABILITY, i as addedAppPermissions, ia as lastSharedWithMe, ic as handoffAttemptSucceeded, id as createRelayPayload, il as turnOff, in as SEPOLIA_TEST_USDT, io as RateWindow, ir as pairedMessageFrame, is as rosterHas, iu as deviceInviteJoinerParams, j as entryParams, jl as readAppBundleAsync, jr as COMMUNITY_TOPOLOGY, ju as firstDeviceSetSecret, k as decodeGroupEntryLink, kc as sealHandoffPiece, ki as APP_RANGE_LIMITS, kl as pacer, kr as meshHubs, ku as TURN_LAST_SEQUENCE, l as planAppUpdate, la as automaticTransport, lc as handoffDataFrame, ld as identityFromSeed, li as typingActivity, ll as contactDay, ln as arkAddressPrefix, lo as parseLinkPreview, lr as GROUP_FILE_LIMITS, ls as emptyRatchetState, lu as encodeInviteCode, ma as HOLD_DATED_BACK_MS, mc as handoffOfferFrame, mi as pinIsNewer, ml as makeStampPaced, mn as validatePaymentTarget, mo as REACTION_LIMITS, mr as groupFileFallback, ms as DHT_POLL_INTERVALS, mu as ENROLL_CAPABILITY, n as readX401SdJwtVc, na as receivedIdentityStatus, nc as handoffAttemptAllowed, nd as PacketTooLargeError, ni as liveStatus, nl as settleRequest, nn as ONCHAIN_PROVIDER, no as MAX_REMOVAL_NUMBER, nr as pairedEditFits, ns as parseGroupCommit, nu as readContactLink, o as appStoreDecision, oa as emptyProofLedger, oc as handoffCancelFrame, ol as REQUEST_LIFETIME_MS, on as TEST_USDT_FAUCET_AMOUNT, or as engineError, os as edgeParams, ou as OwnInviteError, p as readAppStoreSteps, pa as HOLD_CAPABILITY, pc as handoffManifestFrames, pd as verify, pi as nextPinNumber, pl as linkRecords, po as GROUP_REACTION_FRAME, pu as DEVICES_CAPABILITY, qc as enrollProofFrame, qo as claimedTime, qr as shouldBeHub, qs as HANDOFF_HELLO, qu as currentRelays, r as sameX401HolderJwk, rc as handoffAttemptFailed, ri as personStatus, rl as takeRequest, rn as PaymentPreflightError, ro as REMOVED_TEXT, rr as pairedMessageFits, rs as rosterAdmin, ru as createDeviceInvite, s as appUpdateDecision, sa as validExternalKey, sc as handoffContext, si as TypingSender, sl as contactAskerFrame, sn as USDT_PUBLIC_RPC, sr as engineText, ss as RATCHET_CAPABILITY, su as createChatInvite, t as newX401HolderKey, tc as filePartName, td as withRequestOptions, ti as STATUS_IDLE_AFTER_MS, tl as planKnocks, tn as EVM_TEST_CHAINS, to as EDIT_RATE_WINDOW_MS, tr as PAIRED_FRAME_TOO_LARGE, ts as commitHash, tu as encodeContactLink, u as APP_STORE_LIMITS, uc as handoffDigest, ud as identityFromSeedB64, ul as knockSlotIdentity, un as assertTokenUnits, uo as forwardedAgain, ur as GROUP_HAVE_FRAME, us as ratchetSessionOf, uu as inviteLink, v as groupTypingEpoch, va as isHoldUrl, vc as handoffStreamKey, vd as sanitizeDisplayText, vi as WAKE_ONLINE_BATCH_MS, vl as readLinkRecord, vn as sparkAddressKind, vo as reactionEmoji, vs as WATCH_PEER_MS, vu as deviceKeyZ32, w as communityHasFrame, wc as readHandoffHave, wd as toBase64Url, wi as parseWakeFrame, wl as appDigest, wo as readReply, ws as LIMITS, x as COMMUNITY_LIMITS, xc as readHandoffAck, xd as fromBase64Url, xi as WakeLimiter, xl as APP_BUNDLE_LIMITS, xo as validReactionNumber, xs as formatLocalTarget, xt as normalizeAtprotoHandle, xu as newDeviceSetSecret, y as openGroupTyping, ya as newMailbox, yc as handoffVersions, yd as stripHidden, yi as WAKE_ONLINE_DELAY_MS, yl as requestRecords, yn as sparkInvoiceDetails, yo as reactionIsNewer, ys as presenceSeenAt, yu as deviceLinkPairing, z as groupWakes, za as DHT_FILE_CAPABILITY, zi as CapsExchange, zl as isAppHash, zn as parseCashuRequestPayload, zr as mergeBeacon, zs as emptyLinkRecords, zu as turnStatedVerifier } from "./src-DJe-OYxd.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-Clyb52K2.js";
|
|
4
4
|
import { t as bitcoindRpc } from "./bitcoindProvider-BvoRh0D5.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
5
|
+
import { t as nwc } from "./nwcProvider-PE0wli8n.js";
|
|
6
6
|
import { _ as openDb, a as GROUP_LIGHT_RANGE, b as transact, c as clearProfileStores, d as deleteDatabase, f as errorLine, g as newestWalletTx, h as groupLiveKey, i as FILE_INDEX, l as committed, m as groupLightKey, n as APP_STORAGE_SCOPE_INDEX, o as GROUP_LIVE_RANGE, p as fileStore, r as CARD_INDEX, s as STORES$1, t as APP_STORAGE_CHAT_INDEX, u as databaseName, v as profileOpenFailure, x as wrap, y as store } from "./idb-CEuoNsTv.js";
|
|
7
|
-
import { a as sealSeed, c as openRow, d as sealRow, f as sealedStore, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, l as openRows, m as openSecret, o as unsealSeed, p as hasDataKey, r as intentRepository, s as RowSeals, u as proofKey } from "./networkReason-
|
|
7
|
+
import { a as sealSeed, c as openRow, d as sealRow, f as sealedStore, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, l as openRows, m as openSecret, o as unsealSeed, p as hasDataKey, r as intentRepository, s as RowSeals, u as proofKey } from "./networkReason-BbQW1Xpc.js";
|
|
8
8
|
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-BLPZq9YU.js";
|
|
9
|
-
import { $ as lightningPaying, A as paymentNetworksOf, B as removeStored, C as paymentWireId, Ct as setSingleWriterGate, D as createTiming, E as createFailure, F as copyForForward, G as IdentityProofs, H as streamStored, I as forwardError, J as cardsKey, K as CASHU_CARD, L as forwardKind, N as WALLET_TYPES, O as crossNetwork, P as FORWARD_MESSAGE_GONE, Q as journaledPayment, R as FileAppender, S as paymentAlias, St as setAwayWallets, T as assertConfirmedReal, V as storedSize, X as breez, Y as BREEZ_SOURCE, Z as normalizePhrase, _ as groupReply, _t as WrongNetworkError, at as cashuMint, b as replyRef, bt as refuseAway, ct as loadBreezSdk, d as parsePayLink, dt as breezDatabasesFor, et as INVOICE_PACE, f as GroupFileDesk, ft as iceServerProblem, g as storedGroupFiles, gt as ModeGate, h as groupOfFile, ht as ModeChanged, i as onPublicIrohRelay, it as CASHU_MINT_SOURCE, j as walletInstances, k as paymentNetwork, l as groupLinkId, lt as openBreez, m as groupFileText, mt as relayOnlyProblem, n as createIrohWebEndpoint, nt as ProviderSources, o as groupPayLineId, ot as AskBackoff, p as groupFileId, pt as iceServerSetting, q as LightningCards, r as irohRelayProblem, rt as sourceKey, st as forgetBreez, t as DEFAULT_IROH_RELAYS, tt as nextInvoiceAsk, u as pairLinkId, ut as breezDatabaseInUse, v as pairedWireReply, vt as networkLabel, w as WALLET_NAMES, x as replyTo, xt as requireTurn, y as receivedPairedReply, yt as awayFrom, z as readStored$2 } from "./irohWeb-
|
|
10
|
-
import { r as loadFedimintSdk, t as fedimintDatabase } from "./fedimintSdk-
|
|
9
|
+
import { $ as lightningPaying, A as paymentNetworksOf, B as removeStored, C as paymentWireId, Ct as setSingleWriterGate, D as createTiming, E as createFailure, F as copyForForward, G as IdentityProofs, H as streamStored, I as forwardError, J as cardsKey, K as CASHU_CARD, L as forwardKind, N as WALLET_TYPES, O as crossNetwork, P as FORWARD_MESSAGE_GONE, Q as journaledPayment, R as FileAppender, S as paymentAlias, St as setAwayWallets, T as assertConfirmedReal, V as storedSize, X as breez, Y as BREEZ_SOURCE, Z as normalizePhrase, _ as groupReply, _t as WrongNetworkError, at as cashuMint, b as replyRef, bt as refuseAway, ct as loadBreezSdk, d as parsePayLink, dt as breezDatabasesFor, et as INVOICE_PACE, f as GroupFileDesk, ft as iceServerProblem, g as storedGroupFiles, gt as ModeGate, h as groupOfFile, ht as ModeChanged, i as onPublicIrohRelay, it as CASHU_MINT_SOURCE, j as walletInstances, k as paymentNetwork, l as groupLinkId, lt as openBreez, m as groupFileText, mt as relayOnlyProblem, n as createIrohWebEndpoint, nt as ProviderSources, o as groupPayLineId, ot as AskBackoff, p as groupFileId, pt as iceServerSetting, q as LightningCards, r as irohRelayProblem, rt as sourceKey, st as forgetBreez, t as DEFAULT_IROH_RELAYS, tt as nextInvoiceAsk, u as pairLinkId, ut as breezDatabaseInUse, v as pairedWireReply, vt as networkLabel, w as WALLET_NAMES, x as replyTo, xt as requireTurn, y as receivedPairedReply, yt as awayFrom, z as readStored$2 } from "./irohWeb-caAj4Dms.js";
|
|
10
|
+
import { r as loadFedimintSdk, t as fedimintDatabase } from "./fedimintSdk-CPFfVK-G.js";
|
|
11
11
|
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";
|
|
12
|
-
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-
|
|
13
|
-
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-
|
|
14
|
-
import { a as
|
|
15
|
-
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-
|
|
12
|
+
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-C1R5Kd8q.js";
|
|
13
|
+
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-tUzh4lHh.js";
|
|
14
|
+
import { a as besideUrl, c as isGitHubPage, i as appPasteUrl, n as APP_FETCH_LIMITS, o as boundedAppFetch, r as AppFetchError, s as isAppFetchUrl } from "./appFetch-DVYZOZFw.js";
|
|
15
|
+
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-CdV7vHVZ.js";
|
|
16
16
|
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
|
|
17
17
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
18
18
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
@@ -746,7 +746,7 @@ function viewNews(before, after) {
|
|
|
746
746
|
//#endregion
|
|
747
747
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
748
748
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
749
|
-
var loadUsdt = () => import("./usdt-
|
|
749
|
+
var loadUsdt = () => import("./usdt-DI51znt-.js");
|
|
750
750
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
751
751
|
var DEFAULT_USDT = {
|
|
752
752
|
network: "ethereum",
|
|
@@ -1235,7 +1235,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
1235
1235
|
//#endregion
|
|
1236
1236
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
1237
1237
|
/** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
|
|
1238
|
-
var loadArkade = () => import("./arkade-
|
|
1238
|
+
var loadArkade = () => import("./arkade-Bw_4PZRG.js");
|
|
1239
1239
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
1240
1240
|
var RETIRE_READ_MS = 1e4;
|
|
1241
1241
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -3647,11 +3647,7 @@ var SparkWallet = class {
|
|
|
3647
3647
|
const replaced = this.saved && await this.retirable("This Spark wallet already has funds or payments; it will not be replaced");
|
|
3648
3648
|
let adapter;
|
|
3649
3649
|
try {
|
|
3650
|
-
adapter = await this.
|
|
3651
|
-
network: params.network,
|
|
3652
|
-
mnemonic,
|
|
3653
|
-
apiKey
|
|
3654
|
-
}, this.sdk), (a) => a.close());
|
|
3650
|
+
adapter = await this.connect(params.network, mnemonic, apiKey);
|
|
3655
3651
|
const deviceKey = newDeviceKey();
|
|
3656
3652
|
const saved = {
|
|
3657
3653
|
network: params.network,
|
|
@@ -3677,17 +3673,26 @@ var SparkWallet = class {
|
|
|
3677
3673
|
async open() {
|
|
3678
3674
|
if (!this.saved || this.adapter) return;
|
|
3679
3675
|
const { mnemonic, apiKey } = await this.secrets();
|
|
3680
|
-
this.adapter = await this.
|
|
3681
|
-
network: this.saved.network,
|
|
3682
|
-
mnemonic,
|
|
3683
|
-
apiKey
|
|
3684
|
-
}, this.sdk), (a) => a.close());
|
|
3676
|
+
this.adapter = await this.connect(this.saved.network, mnemonic, apiKey);
|
|
3685
3677
|
this.view = {
|
|
3686
3678
|
...this.view,
|
|
3687
3679
|
locked: false
|
|
3688
3680
|
};
|
|
3689
3681
|
await this.refresh();
|
|
3690
3682
|
}
|
|
3683
|
+
/** The SDK's error comes back with the phrase and the key blanked out, as a Breez Lightning card's does: it is shown and stored. */
|
|
3684
|
+
connect(network, mnemonic, apiKey) {
|
|
3685
|
+
return this.gate.within(SparkAdapter.connect({
|
|
3686
|
+
network,
|
|
3687
|
+
mnemonic,
|
|
3688
|
+
apiKey
|
|
3689
|
+
}, this.sdk), (a) => a.close()).catch((error) => {
|
|
3690
|
+
throw error instanceof ModeChanged ? error : new Error(redact(error, {
|
|
3691
|
+
mnemonic,
|
|
3692
|
+
apiKey: apiKey ?? ""
|
|
3693
|
+
}));
|
|
3694
|
+
});
|
|
3695
|
+
}
|
|
3691
3696
|
async secrets() {
|
|
3692
3697
|
const saved = this.saved;
|
|
3693
3698
|
return {
|
|
@@ -3973,7 +3978,28 @@ var PaymentCoordinator = class {
|
|
|
3973
3978
|
return saved.review;
|
|
3974
3979
|
});
|
|
3975
3980
|
}
|
|
3981
|
+
/**
|
|
3982
|
+
* A reconcile asked for while another call on the same payment is under way (the approval, or a status check) may
|
|
3983
|
+
* bring news it started too early to see: the contact saying they took the ecash just after the mint was asked. It
|
|
3984
|
+
* runs once more after that call, shared by every caller meanwhile, instead of taking that call's older answer: the
|
|
3985
|
+
* payer's card waited for the next poll, up to 10 s after the contact had it.
|
|
3986
|
+
*/
|
|
3976
3987
|
reconcile(id) {
|
|
3988
|
+
const running = this.active.get(id);
|
|
3989
|
+
if (!running) return this.reconcileNow(id);
|
|
3990
|
+
let next = this.again.get(id);
|
|
3991
|
+
if (!next) {
|
|
3992
|
+
next = running.catch(() => {}).then(() => {
|
|
3993
|
+
this.again.delete(id);
|
|
3994
|
+
return this.reconcile(id);
|
|
3995
|
+
});
|
|
3996
|
+
this.again.set(id, next);
|
|
3997
|
+
}
|
|
3998
|
+
return next;
|
|
3999
|
+
}
|
|
4000
|
+
/** The reconcile after the one under way, by payment (`reconcile`). */
|
|
4001
|
+
again = /* @__PURE__ */ new Map();
|
|
4002
|
+
reconcileNow(id) {
|
|
3977
4003
|
return this.once(id, async () => {
|
|
3978
4004
|
const saved = await this.require(id);
|
|
3979
4005
|
if (!["submitted", "unknown"].includes(saved.review.state)) return saved.review;
|
|
@@ -9462,7 +9488,7 @@ var HostNotContacted = class extends Error {};
|
|
|
9462
9488
|
*/
|
|
9463
9489
|
function fixedHostsFetch(fetch) {
|
|
9464
9490
|
return async (url, options) => {
|
|
9465
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
9491
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-CbgqrIKs.js");
|
|
9466
9492
|
const host = hostOf$1(url);
|
|
9467
9493
|
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`);
|
|
9468
9494
|
return fetch(url, options);
|
|
@@ -10911,8 +10937,8 @@ var STORE_READ_PARALLEL = 4;
|
|
|
10911
10937
|
/** Revocations are checked this long at a time before the page's thread is let go. */
|
|
10912
10938
|
var REVOCATIONS_SLICE_MS = 10;
|
|
10913
10939
|
/**
|
|
10914
|
-
* `ghostly-revoke.json` files whose result is kept, so an unchanged one is not
|
|
10915
|
-
* at most this many, and of the
|
|
10940
|
+
* `ghostly-revoke.json` files whose result for one app is kept, so an unchanged one is not read again (the oldest dropped
|
|
10941
|
+
* first): at most this many, and of the lists held at most one file's limit of bytes in all. A publisher's file is
|
|
10916
10942
|
* small; nine large ones beside one app's URLs, or one that changes at every check, would stay for the engine's life.
|
|
10917
10943
|
*/
|
|
10918
10944
|
var REVOCATION_FILES_KEPT = {
|
|
@@ -10920,6 +10946,12 @@ var REVOCATION_FILES_KEPT = {
|
|
|
10920
10946
|
bytes: APP_FETCH_LIMITS.revocationsBytes
|
|
10921
10947
|
};
|
|
10922
10948
|
/**
|
|
10949
|
+
* Verdicts of `ghostly-revoke.json` files (every entry verified, or the file refused), by the SHA-256 of their bytes:
|
|
10950
|
+
* a file whose list was dropped from `REVOCATION_FILES_KEPT` is read again with no signature checked. About 64 bytes
|
|
10951
|
+
* each; the oldest dropped first.
|
|
10952
|
+
*/
|
|
10953
|
+
var REVOCATION_VERDICTS_KEPT = 1024;
|
|
10954
|
+
/**
|
|
10923
10955
|
* Revocations of store indexes whose signature was checked, kept by `appRevocationId` so an index that changes around
|
|
10924
10956
|
* them does not have each checked again (the one read longest ago dropped first): four indexes' worth, about 1 MiB.
|
|
10925
10957
|
*/
|
|
@@ -10938,7 +10970,7 @@ var BUNDLES_KEPT = {
|
|
|
10938
10970
|
min: 2,
|
|
10939
10971
|
ms: 6e4
|
|
10940
10972
|
};
|
|
10941
|
-
/** URLs the
|
|
10973
|
+
/** URLs the engine remembers it read whole and refused (`Apps.refusedReads`). */
|
|
10942
10974
|
var REFUSED_READS_KEPT = 256;
|
|
10943
10975
|
/** The first bytes of a bundle: magic, the manifest's length and the largest manifest. */
|
|
10944
10976
|
var PEEK_BYTES = APP_BUNDLE_MAGIC.length + 4 + APP_BUNDLE_LIMITS.manifestBytes;
|
|
@@ -11093,8 +11125,8 @@ async function noteBundles(change) {
|
|
|
11093
11125
|
*/
|
|
11094
11126
|
var APP_REVOCATIONS_KEY = "appRevocations";
|
|
11095
11127
|
/**
|
|
11096
|
-
* Revocations kept there: at most `each` of one app and `all` in all,
|
|
11097
|
-
* revocation is at most about 3.5 KiB (64 digests and a reason).
|
|
11128
|
+
* Revocations kept there: at most `each` of one app and `all` in all, dropped from the publisher holding the most (see
|
|
11129
|
+
* `keepRevocations`). A revocation is at most about 3.5 KiB (64 digests and a reason).
|
|
11098
11130
|
*/
|
|
11099
11131
|
var REVOCATIONS_KEPT = {
|
|
11100
11132
|
each: 64,
|
|
@@ -11130,12 +11162,19 @@ function keepRevocations(settings, ref, add) {
|
|
|
11130
11162
|
if (merged.size === before.length) return;
|
|
11131
11163
|
kept.delete(ref);
|
|
11132
11164
|
kept.set(ref, [...merged.values()].slice(-REVOCATIONS_KEPT.each));
|
|
11165
|
+
const held = /* @__PURE__ */ new Map();
|
|
11133
11166
|
let all = 0;
|
|
11134
|
-
for (const list of kept
|
|
11135
|
-
|
|
11136
|
-
|
|
11167
|
+
for (const [r, list] of kept) {
|
|
11168
|
+
held.set(appRefPublisher(r), (held.get(appRefPublisher(r)) ?? 0) + list.length);
|
|
11169
|
+
all += list.length;
|
|
11170
|
+
}
|
|
11171
|
+
while (all > REVOCATIONS_KEPT.all) {
|
|
11172
|
+
let most = "";
|
|
11173
|
+
for (const [publisher, n] of held) if (n > (held.get(most) ?? 0)) most = publisher;
|
|
11174
|
+
const [other, list] = [...kept].find(([r]) => appRefPublisher(r) === most);
|
|
11137
11175
|
const drop = Math.min(list.length, all - REVOCATIONS_KEPT.all);
|
|
11138
11176
|
all -= drop;
|
|
11177
|
+
held.set(most, held.get(most) - drop);
|
|
11139
11178
|
if (drop === list.length) kept.delete(other);
|
|
11140
11179
|
else kept.set(other, list.slice(drop));
|
|
11141
11180
|
}
|
|
@@ -11358,23 +11397,38 @@ var Apps = class {
|
|
|
11358
11397
|
held = /* @__PURE__ */ new Map();
|
|
11359
11398
|
heldStores = null;
|
|
11360
11399
|
/**
|
|
11361
|
-
* Listing URLs whose peek showed nothing to take (`<store> <ref> <url>` → `<index digest> <listed digest
|
|
11362
|
-
* index listing the same is not peeked again at
|
|
11400
|
+
* Listing URLs whose peek showed nothing to take (`<store> <ref> <url>` → `<index digest> <listed digest> <pin>
|
|
11401
|
+
* <installed digest> <waiting digest>`): the same index listing the same, for the same app, is not peeked again at
|
|
11402
|
+
* every check.
|
|
11363
11403
|
*/
|
|
11364
11404
|
listingMisses = /* @__PURE__ */ new Map();
|
|
11365
11405
|
/**
|
|
11366
|
-
* URLs whose whole read the update check refused (a file hash that does not hold, a bad
|
|
11367
|
-
* the digest their peek showed then: the same peek
|
|
11368
|
-
*
|
|
11406
|
+
* URLs whose whole read the update check, or a fetch of missing files, refused (a file hash that does not hold, a bad
|
|
11407
|
+
* signature, too large, another version under a number held), with the digest their peek showed then: the same peek
|
|
11408
|
+
* there is not read whole again at every check or Open, for an hour (a fixed upload of the same version keeps its
|
|
11409
|
+
* manifest). At most `REFUSED_READS_KEPT`, the oldest going first.
|
|
11369
11410
|
*/
|
|
11370
11411
|
refusedReads = /* @__PURE__ */ new Map();
|
|
11412
|
+
refuseRead(url, digest) {
|
|
11413
|
+
this.refusedReads.delete(url);
|
|
11414
|
+
this.refusedReads.set(url, {
|
|
11415
|
+
digest,
|
|
11416
|
+
at: this.now()
|
|
11417
|
+
});
|
|
11418
|
+
for (const old of this.refusedReads.keys()) {
|
|
11419
|
+
if (this.refusedReads.size <= REFUSED_READS_KEPT) break;
|
|
11420
|
+
this.refusedReads.delete(old);
|
|
11421
|
+
}
|
|
11422
|
+
}
|
|
11371
11423
|
/**
|
|
11372
11424
|
* The index a store's own URL served at its last read when it was not taken (behind the copy the person took, at a
|
|
11373
11425
|
* commit): by store key, with that URL. The same bytes there again are not checked whole at every refresh.
|
|
11374
11426
|
*/
|
|
11375
11427
|
behindReads = /* @__PURE__ */ new Map();
|
|
11376
|
-
/** `ghostly-revoke.json` files checked, by the SHA-256 of their bytes:
|
|
11428
|
+
/** `ghostly-revoke.json` files checked, by the SHA-256 of their bytes and the app read (`<digest> <ref>`): that app's revocations in it, and the bytes the list counts for. */
|
|
11377
11429
|
revocationFiles = /* @__PURE__ */ new Map();
|
|
11430
|
+
/** Whether every entry of a `ghostly-revoke.json` verified, by the SHA-256 of its bytes: at most `REVOCATION_VERDICTS_KEPT`. */
|
|
11431
|
+
revocationVerdicts = /* @__PURE__ */ new Map();
|
|
11378
11432
|
/** Revocations read in a store's index and verified, by `appRevocationId`: at most `STORE_REVOCATIONS_KEPT`. */
|
|
11379
11433
|
storeRevocations = /* @__PURE__ */ new Set();
|
|
11380
11434
|
checkedRevocations = {
|
|
@@ -11411,6 +11465,15 @@ var Apps = class {
|
|
|
11411
11465
|
const age = at === void 0 ? -1 : this.now() - at;
|
|
11412
11466
|
return age >= 0 && age < ms;
|
|
11413
11467
|
}
|
|
11468
|
+
/** `url`'s whole read was refused within the hour while its peek showed `digest`: not downloaded again (`refusedReads`). */
|
|
11469
|
+
readRefused(url, digest) {
|
|
11470
|
+
const refused = this.refusedReads.get(url);
|
|
11471
|
+
return refused?.digest === digest && this.checkedWithin(refused.at, APP_CHECK_TIMINGS.freshMs);
|
|
11472
|
+
}
|
|
11473
|
+
/** Keeps a failed whole read of `url` refused for what its peek showed; a read that brought no bundle (the host down) is not kept. */
|
|
11474
|
+
refuseFailedRead(url, digest, error) {
|
|
11475
|
+
if (!(error instanceof AppFetchError) || error.code === "too-large") this.refuseRead(url, digest);
|
|
11476
|
+
}
|
|
11414
11477
|
/**
|
|
11415
11478
|
* Preloads the default stores (no request) and removes the bundles no record names (`sweepBundles`), then checks for
|
|
11416
11479
|
* updates soon after start and every 24 hours.
|
|
@@ -11495,6 +11558,13 @@ var Apps = class {
|
|
|
11495
11558
|
async keptRevocationsOf(ref) {
|
|
11496
11559
|
return keptRevocations(await wrap((await store(STORES$1.settings, "readonly")).get(APP_REVOCATIONS_KEY)), ref).mine;
|
|
11497
11560
|
}
|
|
11561
|
+
/** Keeps on an installed app's record those of these revocations that stop one of its versions (as `keepStoreRevocations` does). */
|
|
11562
|
+
async keepOnRecord(first, revoked) {
|
|
11563
|
+
for (let app = first; app; app = await this.app(first.ref)) {
|
|
11564
|
+
const next = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11565
|
+
if ((next.revocations?.length ?? 0) <= (app.revocations?.length ?? 0) || await this.putAppIfUnchanged(next, app)) break;
|
|
11566
|
+
}
|
|
11567
|
+
}
|
|
11498
11568
|
/**
|
|
11499
11569
|
* The built-in apps this profile is offered (WISP 1200 § Built-in apps): shown with the installed ones, with nothing
|
|
11500
11570
|
* stored and nothing granted. Opening one is an install like any other, from the bundle the build carries.
|
|
@@ -11628,12 +11698,14 @@ var Apps = class {
|
|
|
11628
11698
|
* only the records written before it. A revocation the record gained since `was` (`keepStoreRevocations`) is kept:
|
|
11629
11699
|
* one `app` leaves out on purpose (the check's, of a version gone) was on `was` already. So is what the person's stores
|
|
11630
11700
|
* revoke of the versions written, as held at the write: a version fetched while a store's index revoked it was not on
|
|
11631
|
-
* the record `keepStoreRevocations` read.
|
|
11701
|
+
* the record `keepStoreRevocations` read. A store removed since keeps no index: what it revoked of this app is among
|
|
11702
|
+
* the ones this profile kept (`APP_REVOCATIONS_KEY`), judged here too.
|
|
11632
11703
|
*/
|
|
11633
11704
|
async putAppIfUnchanged(app, was) {
|
|
11634
11705
|
const stores = await this.records();
|
|
11635
|
-
const tx = (await openDb()).transaction(STORES$1.apps, "readwrite");
|
|
11706
|
+
const tx = (await openDb()).transaction([STORES$1.apps, STORES$1.settings], "readwrite");
|
|
11636
11707
|
let put = false;
|
|
11708
|
+
const kept = tx.objectStore(STORES$1.settings).get(APP_REVOCATIONS_KEY);
|
|
11637
11709
|
const read = tx.objectStore(STORES$1.apps).get(app.ref);
|
|
11638
11710
|
read.onsuccess = () => {
|
|
11639
11711
|
const now = read.result;
|
|
@@ -11641,7 +11713,7 @@ var Apps = class {
|
|
|
11641
11713
|
const had = new Set((was?.revocations ?? []).map((r) => canonicalJson(r)));
|
|
11642
11714
|
app = withRevocations(app, (now?.revocations ?? []).filter((r) => !had.has(canonicalJson(r))));
|
|
11643
11715
|
const revoked = [...stores.values()].flatMap((s) => s.removed ? [] : s.index?.revoked ?? []);
|
|
11644
|
-
app = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11716
|
+
app = withRevocations(app, stopping(this.versionsOf(app), [...revoked, ...keptRevocations(kept.result, app.ref).mine]));
|
|
11645
11717
|
const { store: pin, ...unpinned } = app;
|
|
11646
11718
|
tx.objectStore(STORES$1.apps).put(pin !== void 0 && stores.get(pin)?.removed ? unpinned : app);
|
|
11647
11719
|
put = true;
|
|
@@ -11689,13 +11761,21 @@ var Apps = class {
|
|
|
11689
11761
|
/**
|
|
11690
11762
|
* Keeps on each installed app the revocations a store's index carries of its versions: a client keeps every
|
|
11691
11763
|
* revocation it verified (WISP 1200 § Publisher keys), so the store's next index without it, or the store removed,
|
|
11692
|
-
* does not let that version run again.
|
|
11764
|
+
* does not let that version run again. Those of an installed app's other versions are kept with the profile's
|
|
11765
|
+
* (`APP_REVOCATIONS_KEY`): a version the update check or Install is writing meanwhile is not on the record yet.
|
|
11693
11766
|
*/
|
|
11694
11767
|
async keepStoreRevocations(record) {
|
|
11695
11768
|
const revoked = record.index?.revoked ?? [];
|
|
11696
11769
|
if (!revoked.length) return;
|
|
11697
11770
|
const reread = async (ref) => wrap((await store(STORES$1.apps, "readonly")).get(ref));
|
|
11698
|
-
|
|
11771
|
+
const installed = await this.installed();
|
|
11772
|
+
const mine = installed.map((app) => [app.ref, revoked.filter((r) => r.statement.app === app.ref)]).filter(([, r]) => r.length);
|
|
11773
|
+
if (mine.length) {
|
|
11774
|
+
const tx = (await openDb()).transaction(STORES$1.settings, "readwrite");
|
|
11775
|
+
for (const [ref, r] of mine) keepRevocations(tx.objectStore(STORES$1.settings), ref, r);
|
|
11776
|
+
await done(tx);
|
|
11777
|
+
}
|
|
11778
|
+
for (const first of installed) for (let app = first; app; app = await reread(first.ref)) {
|
|
11699
11779
|
const next = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11700
11780
|
if ((next.revocations?.length ?? 0) <= (app.revocations?.length ?? 0) || await this.putAppIfUnchanged(next, app)) break;
|
|
11701
11781
|
}
|
|
@@ -11720,8 +11800,13 @@ var Apps = class {
|
|
|
11720
11800
|
revoked: s.index.revoked
|
|
11721
11801
|
}));
|
|
11722
11802
|
}
|
|
11723
|
-
|
|
11724
|
-
|
|
11803
|
+
/**
|
|
11804
|
+
* The stores that list this version of an app: a store vouches for what it lists (WISP 1200 § Publisher identity), the
|
|
11805
|
+
* digest of its listing, not every version of the app. `pin`: the store an installed app's updates come from, whose
|
|
11806
|
+
* listing may have moved on to a newer version the app has not taken yet; it took that store's listed digest.
|
|
11807
|
+
*/
|
|
11808
|
+
listedBy(version, stores, pin) {
|
|
11809
|
+
return stores.filter((s) => s.index?.apps.some((a) => a.ref === version.ref && (a.digest === version.digest || s.key === pin))).map((s) => ({
|
|
11725
11810
|
key: s.key,
|
|
11726
11811
|
name: s.index.name,
|
|
11727
11812
|
kind: s.index.kind
|
|
@@ -12038,23 +12123,32 @@ var Apps = class {
|
|
|
12038
12123
|
if (read.has(url)) continue;
|
|
12039
12124
|
read.add(url);
|
|
12040
12125
|
try {
|
|
12041
|
-
const file = await this.readRevocationsFile(await this.host.fetch(url, {
|
|
12126
|
+
const file = await this.readRevocationsFile(ref, await this.host.fetch(url, {
|
|
12042
12127
|
maxBytes: APP_FETCH_LIMITS.revocationsBytes,
|
|
12043
12128
|
revalidate: true
|
|
12044
12129
|
}));
|
|
12045
|
-
if (file) (out ??= []).push(...file
|
|
12130
|
+
if (file) (out ??= []).push(...file);
|
|
12046
12131
|
} catch {}
|
|
12047
12132
|
}
|
|
12048
12133
|
return out;
|
|
12049
12134
|
}
|
|
12050
12135
|
/**
|
|
12051
12136
|
* `readAppRevocations` (one entry that does not verify refuses the file, null here), with a pause every few ms: the
|
|
12052
|
-
* engine shares the page's thread, and each entry is a signature check.
|
|
12137
|
+
* engine shares the page's thread, and each entry is a signature check. Of the file, the revocations of `ref`. The
|
|
12138
|
+
* same bytes are not checked again: their list for `ref` is kept while it fits, and their verdict longer, so a file
|
|
12139
|
+
* read again is only parsed, with no signature checked.
|
|
12053
12140
|
*/
|
|
12054
|
-
async readRevocationsFile(bytes) {
|
|
12141
|
+
async readRevocationsFile(ref, bytes) {
|
|
12055
12142
|
const id = toBase64Url(await sha256Paced(bytes));
|
|
12056
|
-
const
|
|
12057
|
-
if (
|
|
12143
|
+
const verdict = this.revocationVerdicts.get(id);
|
|
12144
|
+
if (verdict === false) return null;
|
|
12145
|
+
const key = `${id} ${ref}`;
|
|
12146
|
+
const known = this.revocationFiles.get(key);
|
|
12147
|
+
if (known !== void 0) {
|
|
12148
|
+
this.revocationFiles.delete(key);
|
|
12149
|
+
this.revocationFiles.set(key, known);
|
|
12150
|
+
return known.revocations;
|
|
12151
|
+
}
|
|
12058
12152
|
const read = readCanonicalJson(bytes);
|
|
12059
12153
|
let out = null;
|
|
12060
12154
|
if (read.ok && Array.isArray(read.value) && read.value.length <= APP_STATEMENT_LIMITS.revocations) {
|
|
@@ -12062,18 +12156,21 @@ var Apps = class {
|
|
|
12062
12156
|
const pause = pacer(REVOCATIONS_SLICE_MS);
|
|
12063
12157
|
for (const entry of read.value) {
|
|
12064
12158
|
await pause();
|
|
12065
|
-
const one = readAppRevocation(entry);
|
|
12159
|
+
const one = verdict ? readAppRevocationShape(entry) : readAppRevocation(entry);
|
|
12066
12160
|
if (!one.ok) {
|
|
12067
12161
|
out = null;
|
|
12068
12162
|
break;
|
|
12069
12163
|
}
|
|
12070
|
-
out.push(one.revocation);
|
|
12164
|
+
if (one.revocation.statement.app === ref) out.push(one.revocation);
|
|
12071
12165
|
}
|
|
12072
12166
|
}
|
|
12073
|
-
this.
|
|
12074
|
-
this.
|
|
12167
|
+
this.revocationVerdicts.delete(id);
|
|
12168
|
+
this.revocationVerdicts.set(id, out !== null);
|
|
12169
|
+
if (this.revocationVerdicts.size > REVOCATION_VERDICTS_KEPT) this.revocationVerdicts.delete(this.revocationVerdicts.keys().next().value);
|
|
12170
|
+
if (!out) return null;
|
|
12171
|
+
this.revocationFiles.set(key, {
|
|
12075
12172
|
revocations: out,
|
|
12076
|
-
bytes: out ?
|
|
12173
|
+
bytes: out.length ? canonicalJsonBytes(out).length : 0
|
|
12077
12174
|
});
|
|
12078
12175
|
let held = 0;
|
|
12079
12176
|
for (const file of this.revocationFiles.values()) held += file.bytes;
|
|
@@ -12446,7 +12543,7 @@ var Apps = class {
|
|
|
12446
12543
|
let last = null;
|
|
12447
12544
|
for (const url of urls) try {
|
|
12448
12545
|
const kept = expect?.digest !== void 0 ? this.staged.get(stagedKey(expect.digest, url, fromStore)) : void 0;
|
|
12449
|
-
const { bundle, bytes } = kept && this.
|
|
12546
|
+
const { bundle, bytes } = kept && this.checkedWithin(kept.at, STAGED.ms) ? kept : await this.fetchBundle(url);
|
|
12450
12547
|
const version = versionOf(bundle.manifest, bundle.digest);
|
|
12451
12548
|
if (expect) {
|
|
12452
12549
|
if (version.ref !== expect.ref) fail("other-app", "The URL holds another app");
|
|
@@ -12460,29 +12557,43 @@ var Apps = class {
|
|
|
12460
12557
|
}
|
|
12461
12558
|
throw last instanceof Error ? last : new Error(String(last));
|
|
12462
12559
|
}
|
|
12463
|
-
/**
|
|
12560
|
+
/**
|
|
12561
|
+
* Drops the staged bundles past `STAGED.ms` (or staged while the clock ran ahead), and comes back when the oldest left
|
|
12562
|
+
* is due: within `STAGED.ms`, as every one left was staged less than that ago.
|
|
12563
|
+
*/
|
|
12464
12564
|
sweepStaged() {
|
|
12465
12565
|
this.sweep = null;
|
|
12466
|
-
for (const [key, s] of this.staged) if (this.
|
|
12566
|
+
for (const [key, s] of this.staged) if (!this.checkedWithin(s.at, STAGED.ms)) this.staged.delete(key);
|
|
12467
12567
|
const oldest = this.staged.values().next().value;
|
|
12468
12568
|
if (oldest) this.sweep = setTimeout(() => this.sweepStaged(), STAGED.ms - (this.now() - oldest.at));
|
|
12469
12569
|
}
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
|
|
12570
|
+
/**
|
|
12571
|
+
* The publisher's revocations of `version`'s app read beside `urls`. One that stops this version is kept (the person was
|
|
12572
|
+
* shown it revoked: a copy of it elsewhere is refused too), and the ones kept before are judged with them, whatever URL
|
|
12573
|
+
* this one came from.
|
|
12574
|
+
*/
|
|
12575
|
+
async readStopping(version, urls) {
|
|
12576
|
+
const read = await this.readRevocations(version.ref, urls) ?? [];
|
|
12474
12577
|
const stops = stopping([version], read);
|
|
12475
12578
|
if (stops.length) {
|
|
12476
12579
|
const tx = (await openDb()).transaction(STORES$1.settings, "readwrite");
|
|
12477
12580
|
keepRevocations(tx.objectStore(STORES$1.settings), version.ref, stops);
|
|
12478
12581
|
await done(tx);
|
|
12582
|
+
const installed = await this.app(version.ref);
|
|
12583
|
+
if (installed) await this.keepOnRecord(installed, stops);
|
|
12479
12584
|
}
|
|
12585
|
+
return read;
|
|
12586
|
+
}
|
|
12587
|
+
async stage(bundle, bytes, from, fromStore, carried = false) {
|
|
12588
|
+
const { manifest, digest } = bundle;
|
|
12589
|
+
const version = versionOf(manifest, digest);
|
|
12590
|
+
const read = carried ? [] : await this.readStopping(version, [from, ...manifest.sources ?? []]);
|
|
12480
12591
|
const revocations = [...await this.keptRevocationsOf(version.ref), ...read];
|
|
12481
12592
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
12482
12593
|
const decision = installDecision(installed, version);
|
|
12483
12594
|
const install = decision === "other-app" ? "new" : decision;
|
|
12484
12595
|
const asks = install === "new" ? [...manifest.permissions] : install === "update" ? manifest.permissions.filter((p) => !installed.permissions.includes(p)) : [];
|
|
12485
|
-
for (const [d, s] of this.staged) if (this.
|
|
12596
|
+
for (const [d, s] of this.staged) if (!this.checkedWithin(s.at, STAGED.ms)) this.staged.delete(d);
|
|
12486
12597
|
const stage = stagedKey(digest, from, fromStore);
|
|
12487
12598
|
this.staged.delete(stage);
|
|
12488
12599
|
while (this.staged.size >= STAGED.max) this.staged.delete(this.staged.keys().next().value);
|
|
@@ -12493,10 +12604,11 @@ var Apps = class {
|
|
|
12493
12604
|
...fromStore !== void 0 && { store: fromStore },
|
|
12494
12605
|
revocations,
|
|
12495
12606
|
asks,
|
|
12496
|
-
at: this.now()
|
|
12607
|
+
at: this.now(),
|
|
12608
|
+
...carried && { carried: true }
|
|
12497
12609
|
});
|
|
12498
12610
|
if (!this.sweep) this.sweepStaged();
|
|
12499
|
-
const listedBy = this.listedBy(version
|
|
12611
|
+
const listedBy = this.listedBy(version, stores);
|
|
12500
12612
|
return {
|
|
12501
12613
|
digest,
|
|
12502
12614
|
ref: version.ref,
|
|
@@ -12524,19 +12636,20 @@ var Apps = class {
|
|
|
12524
12636
|
* bundle waits.
|
|
12525
12637
|
*/
|
|
12526
12638
|
async install({ stage, digest, grant, asks }) {
|
|
12527
|
-
const live = [...this.staged].filter(([key, s]) => s.bundle.digest === digest && (stage === void 0 || key === stage) && this.
|
|
12639
|
+
const live = [...this.staged].filter(([key, s]) => s.bundle.digest === digest && (stage === void 0 || key === stage) && this.checkedWithin(s.at, STAGED.ms));
|
|
12528
12640
|
if (live.length > 1) fail("screens", "This app was fetched from more than one place; install it from its screen");
|
|
12529
12641
|
const [key, staged] = live[0] ?? [stage ?? ""];
|
|
12530
12642
|
if (!staged) {
|
|
12531
12643
|
this.staged.delete(key);
|
|
12532
12644
|
fail("expired", "Fetch the app again");
|
|
12533
12645
|
}
|
|
12534
|
-
const { bundle, bytes, from, store: fromStore
|
|
12646
|
+
const { bundle, bytes, from, store: fromStore } = staged;
|
|
12535
12647
|
const { manifest } = bundle;
|
|
12536
12648
|
if (!Array.isArray(grant) || !manifest.permissions.every((p) => grant.includes(p))) fail("permissions", "Every permission the app asks for must be granted");
|
|
12537
12649
|
const shown = asks ?? staged.asks;
|
|
12538
12650
|
if (!Array.isArray(shown)) fail("permissions", "The permissions shown must be a list");
|
|
12539
12651
|
const version = versionOf(manifest, digest);
|
|
12652
|
+
const revocations = staged.carried ? [...staged.revocations, ...await this.readStopping(version, [from, ...manifest.sources ?? []])] : staged.revocations;
|
|
12540
12653
|
let wrote;
|
|
12541
12654
|
try {
|
|
12542
12655
|
let read = false;
|
|
@@ -12583,7 +12696,11 @@ var Apps = class {
|
|
|
12583
12696
|
return this.view(await this.app(version.ref), stores);
|
|
12584
12697
|
}
|
|
12585
12698
|
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
12586
|
-
if (this.runStatus(version, await this.heldViews(), [
|
|
12699
|
+
if (this.runStatus(version, await this.heldViews(), [
|
|
12700
|
+
...installed?.revocations ?? [],
|
|
12701
|
+
...known,
|
|
12702
|
+
...await this.keptRevocationsOf(version.ref)
|
|
12703
|
+
]).status !== "ok") continue;
|
|
12587
12704
|
const next = withRevocations(this.versionRecord(installed, bundle, kind, from, fromStore), known);
|
|
12588
12705
|
if (!await this.putAppIfUnchanged(next, installed)) continue;
|
|
12589
12706
|
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
@@ -12637,18 +12754,25 @@ var Apps = class {
|
|
|
12637
12754
|
async acceptUpdate({ ref, sequence, added: shown }) {
|
|
12638
12755
|
if (shown !== void 0 && !Array.isArray(shown)) fail("permissions", "The permissions shown must be a list");
|
|
12639
12756
|
const installed = await this.installedOrFail(ref);
|
|
12757
|
+
if (!installed.pending && sequence !== void 0 && installed.sequence === sequence) return this.view(installed, await this.stores());
|
|
12640
12758
|
const pending = installed.pending ?? fail("no-update", "No update waits for this app");
|
|
12641
12759
|
if (sequence !== void 0 && pending.sequence !== sequence) fail("permissions-changed", `Another update waits now, which adds ${pending.added.length ? pending.added.join(", ") : "no permission"}; look at it again`);
|
|
12642
12760
|
const bytes = await this.readBundleBytes(pending.bytes, pending.digest);
|
|
12643
12761
|
const read = bytes ? await readAppBundleAsync(bytes) : null;
|
|
12644
12762
|
if (!read?.ok || read.bundle.digest !== pending.digest) {
|
|
12645
12763
|
const { pending: _p, ...rest } = installed;
|
|
12646
|
-
if (!await this.
|
|
12764
|
+
if (!await this.putAppIfUnchanged(rest, installed)) return this.acceptedOver(ref, pending.digest);
|
|
12647
12765
|
fail("needs-files", "The update's files are gone; it is fetched again at the next check");
|
|
12648
12766
|
}
|
|
12649
12767
|
const stores = await this.stores();
|
|
12650
|
-
if (installed.store !== void 0 && this.pinnedListing(installed, stores)?.digest !== pending.digest)
|
|
12651
|
-
|
|
12768
|
+
if (installed.store !== void 0 && this.pinnedListing(installed, stores)?.digest !== pending.digest) {
|
|
12769
|
+
if (stores.find((s) => s.key === installed.store)?.index) {
|
|
12770
|
+
const { pending: _p, ...rest } = installed;
|
|
12771
|
+
if (await this.putAppIfUnchanged(rest, installed)) await this.removeBundle(pending.bytes, pending.digest);
|
|
12772
|
+
}
|
|
12773
|
+
fail("unlisted", "The store no longer lists this update");
|
|
12774
|
+
}
|
|
12775
|
+
const run = this.runStatus(versionOf(read.bundle.manifest, pending.digest), this.storeViews(stores), [...installed.revocations ?? [], ...await this.keptRevocationsOf(ref)]);
|
|
12652
12776
|
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
12653
12777
|
if (run.status === "removed") fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
12654
12778
|
const plan = planAppUpdate(installed, {
|
|
@@ -12658,27 +12782,29 @@ var Apps = class {
|
|
|
12658
12782
|
if (plan.action === "refuse") fail(plan.decision, "This update can no longer be installed");
|
|
12659
12783
|
const added = plan.action === "ask" ? plan.added : [];
|
|
12660
12784
|
if (added.length !== pending.added.length || added.some((p) => !pending.added.includes(p))) {
|
|
12661
|
-
if (!await this.
|
|
12785
|
+
if (!await this.putAppIfUnchanged({
|
|
12662
12786
|
...installed,
|
|
12663
12787
|
pending: {
|
|
12664
12788
|
...pending,
|
|
12665
12789
|
added
|
|
12666
12790
|
}
|
|
12667
|
-
}))
|
|
12791
|
+
}, installed)) return this.acceptedOver(ref, pending.digest);
|
|
12668
12792
|
fail("permissions-changed", `This update now adds ${added.length ? added.join(", ") : "no permission"}; look at it again`);
|
|
12669
12793
|
}
|
|
12670
12794
|
if (shown && added.some((p) => !shown.includes(p))) fail("permissions-changed", `This update now adds ${added.join(", ")}; look at it again`);
|
|
12671
12795
|
const { pending: _p, ...without } = installed;
|
|
12672
12796
|
const next = this.versionRecord(without, read.bundle, pending.bytes, pending.from, installed.store);
|
|
12673
|
-
if (!await this.putAppIfUnchanged(next, installed))
|
|
12674
|
-
const now = await this.app(ref);
|
|
12675
|
-
if (!now) fail("not-installed", "This app is not installed");
|
|
12676
|
-
if (now.digest === pending.digest) return this.view(now, await this.stores());
|
|
12677
|
-
fail("no-update", "This update can no longer be installed");
|
|
12678
|
-
}
|
|
12797
|
+
if (!await this.putAppIfUnchanged(next, installed)) return this.acceptedOver(ref, pending.digest);
|
|
12679
12798
|
await this.removeBundle(installed.bytes, installed.digest);
|
|
12680
12799
|
return this.view(next, stores);
|
|
12681
12800
|
}
|
|
12801
|
+
/** Accept's answer when the app's record changed while it read: uninstalled, this update installed, or another version. */
|
|
12802
|
+
async acceptedOver(ref, digest) {
|
|
12803
|
+
const now = await this.app(ref);
|
|
12804
|
+
if (!now) fail("not-installed", "This app is not installed");
|
|
12805
|
+
if (now.digest === digest) return this.view(now, await this.stores());
|
|
12806
|
+
fail("no-update", "This update can no longer be installed");
|
|
12807
|
+
}
|
|
12682
12808
|
/** An app's listing in the store its updates come from (`InstalledApp.store`), while that store is the person's. */
|
|
12683
12809
|
pinnedListing(app, stores) {
|
|
12684
12810
|
return app.store === void 0 ? void 0 : stores.find((s) => s.key === app.store)?.index?.apps.find((a) => a.ref === app.ref);
|
|
@@ -12736,7 +12862,7 @@ var Apps = class {
|
|
|
12736
12862
|
if (pinned !== void 0 && s.key !== pinned) continue;
|
|
12737
12863
|
const listing = s.index?.apps.find((a) => a.ref === app.ref);
|
|
12738
12864
|
if (!listing || !newer(listing)) continue;
|
|
12739
|
-
const seen = `${s.digest} ${listing.digest}`;
|
|
12865
|
+
const seen = `${s.digest} ${listing.digest} ${pinned ?? ""} ${app.digest} ${app.pending?.digest ?? ""}`;
|
|
12740
12866
|
for (const url of listingUrls(listing.urls)) {
|
|
12741
12867
|
const missed = `${s.key} ${app.ref} ${url}`;
|
|
12742
12868
|
if (candidates.has(url) || s.digest !== void 0 && this.listingMisses.get(missed) === seen) continue;
|
|
@@ -12791,27 +12917,17 @@ var Apps = class {
|
|
|
12791
12917
|
}
|
|
12792
12918
|
const twin = holds && (holds.sequence === app.sequence || holds.sequence === app.pending?.sequence);
|
|
12793
12919
|
if (holds && !twin && judge(holds).status !== "ok") continue;
|
|
12920
|
+
if (holds && !twin && app.pending && holds.sequence < app.pending.sequence) continue;
|
|
12794
12921
|
if (holds && twin && app.equivocation?.sequence === holds.sequence && app.equivocation.digest === holds.digest) {
|
|
12795
12922
|
outcome = "equivocation";
|
|
12796
12923
|
continue;
|
|
12797
12924
|
}
|
|
12798
|
-
|
|
12799
|
-
if (holds && refused?.digest === holds.digest && this.now() - refused.at < APP_CHECK_TIMINGS.freshMs) continue;
|
|
12925
|
+
if (holds && this.readRefused(url, holds.digest)) continue;
|
|
12800
12926
|
let fetched;
|
|
12801
12927
|
try {
|
|
12802
12928
|
fetched = await this.fetchBundle(url);
|
|
12803
12929
|
} catch (error) {
|
|
12804
|
-
if (holds
|
|
12805
|
-
this.refusedReads.delete(url);
|
|
12806
|
-
this.refusedReads.set(url, {
|
|
12807
|
-
digest: holds.digest,
|
|
12808
|
-
at: this.now()
|
|
12809
|
-
});
|
|
12810
|
-
for (const old of this.refusedReads.keys()) {
|
|
12811
|
-
if (this.refusedReads.size <= REFUSED_READS_KEPT) break;
|
|
12812
|
-
this.refusedReads.delete(old);
|
|
12813
|
-
}
|
|
12814
|
-
}
|
|
12930
|
+
if (holds) this.refuseFailedRead(url, holds.digest, error);
|
|
12815
12931
|
continue;
|
|
12816
12932
|
}
|
|
12817
12933
|
const { bundle, bytes } = fetched;
|
|
@@ -12828,6 +12944,7 @@ var Apps = class {
|
|
|
12828
12944
|
}
|
|
12829
12945
|
};
|
|
12830
12946
|
outcome = "equivocation";
|
|
12947
|
+
this.refuseRead(url, version.digest);
|
|
12831
12948
|
continue;
|
|
12832
12949
|
}
|
|
12833
12950
|
const plan = planAppUpdate(app, {
|
|
@@ -12845,6 +12962,7 @@ var Apps = class {
|
|
|
12845
12962
|
}
|
|
12846
12963
|
};
|
|
12847
12964
|
outcome = "equivocation";
|
|
12965
|
+
this.refuseRead(url, version.digest);
|
|
12848
12966
|
}
|
|
12849
12967
|
continue;
|
|
12850
12968
|
}
|
|
@@ -12937,21 +13055,7 @@ var Apps = class {
|
|
|
12937
13055
|
const carried = this.builtIn(app.ref);
|
|
12938
13056
|
if (carried && carried.digest === app.digest) {
|
|
12939
13057
|
const held = await this.bundled(carried).catch(() => null);
|
|
12940
|
-
if (held)
|
|
12941
|
-
const kind = await this.writeBundle(app.digest, held.bytes);
|
|
12942
|
-
const now = await this.app(app.ref);
|
|
12943
|
-
if (!now || now.digest !== app.digest || now.bytes !== kind && !await this.putApp({
|
|
12944
|
-
...now,
|
|
12945
|
-
bytes: kind
|
|
12946
|
-
})) {
|
|
12947
|
-
await this.removeBundle(kind, app.digest);
|
|
12948
|
-
fail("not-installed", "This app is not installed");
|
|
12949
|
-
}
|
|
12950
|
-
return this.runCheckOf({
|
|
12951
|
-
...now,
|
|
12952
|
-
bytes: kind
|
|
12953
|
-
}, stores);
|
|
12954
|
-
}
|
|
13058
|
+
if (held) return this.filesBack(app, held.bytes, stores);
|
|
12955
13059
|
}
|
|
12956
13060
|
const urls = [app.from];
|
|
12957
13061
|
for (const s of stores) {
|
|
@@ -12965,32 +13069,41 @@ var Apps = class {
|
|
|
12965
13069
|
} catch {
|
|
12966
13070
|
continue;
|
|
12967
13071
|
}
|
|
13072
|
+
if (this.readRefused(url, app.digest)) continue;
|
|
12968
13073
|
let fetched;
|
|
12969
13074
|
try {
|
|
12970
13075
|
fetched = await this.fetchBundle(url);
|
|
12971
|
-
} catch {
|
|
13076
|
+
} catch (error) {
|
|
13077
|
+
this.refuseFailedRead(url, app.digest, error);
|
|
12972
13078
|
continue;
|
|
12973
13079
|
}
|
|
12974
13080
|
if (fetched.bundle.digest !== app.digest) continue;
|
|
12975
|
-
|
|
12976
|
-
const now = await this.app(app.ref);
|
|
12977
|
-
if (!now || now.digest !== app.digest || now.bytes !== kind && !await this.putApp({
|
|
12978
|
-
...now,
|
|
12979
|
-
bytes: kind
|
|
12980
|
-
})) {
|
|
12981
|
-
await this.removeBundle(kind, app.digest);
|
|
12982
|
-
fail("not-installed", "This app is not installed");
|
|
12983
|
-
}
|
|
12984
|
-
return this.runCheckOf({
|
|
12985
|
-
...now,
|
|
12986
|
-
bytes: kind
|
|
12987
|
-
}, stores);
|
|
13081
|
+
return this.filesBack(app, fetched.bytes, stores);
|
|
12988
13082
|
}
|
|
12989
13083
|
return { status: "needs-files" };
|
|
12990
13084
|
}
|
|
13085
|
+
/** The installed version's files, fetched again, written back. */
|
|
13086
|
+
async filesBack(app, bytes, stores) {
|
|
13087
|
+
const kind = await this.writeBundle(app.digest, bytes);
|
|
13088
|
+
const now = await this.app(app.ref);
|
|
13089
|
+
if (!now || now.digest !== app.digest || now.bytes !== kind && !await this.putApp({
|
|
13090
|
+
...now,
|
|
13091
|
+
bytes: kind
|
|
13092
|
+
})) {
|
|
13093
|
+
await this.removeBundle(kind, app.digest);
|
|
13094
|
+
fail("not-installed", "This app is not installed");
|
|
13095
|
+
}
|
|
13096
|
+
try {
|
|
13097
|
+
this.host.checked?.([]);
|
|
13098
|
+
} catch {}
|
|
13099
|
+
return this.runCheckOf({
|
|
13100
|
+
...now,
|
|
13101
|
+
bytes: kind
|
|
13102
|
+
}, stores);
|
|
13103
|
+
}
|
|
12991
13104
|
async runCheckOf(app, stores) {
|
|
12992
13105
|
if (!await this.hasBundle(app.bytes, app.digest, app.manifest)) return { status: "needs-files" };
|
|
12993
|
-
return this.runStatus(app, this.storeViews(stores), app.revocations);
|
|
13106
|
+
return this.runStatus(app, this.storeViews(stores), [...app.revocations ?? [], ...await this.keptRevocationsOf(app.ref)]);
|
|
12994
13107
|
}
|
|
12995
13108
|
/** Before an app runs (WISP 1200 § Takedowns): revoked stops it, removed by a store of the person's warns. No request. */
|
|
12996
13109
|
async runCheck({ ref }) {
|
|
@@ -13069,7 +13182,7 @@ var Apps = class {
|
|
|
13069
13182
|
}
|
|
13070
13183
|
async view(app, stores) {
|
|
13071
13184
|
const { manifest } = app;
|
|
13072
|
-
const listedBy = this.listedBy(app
|
|
13185
|
+
const listedBy = this.listedBy(app, stores, app.store);
|
|
13073
13186
|
const stopped = this.startedBefore(app).map((v) => ({
|
|
13074
13187
|
digest: v.digest,
|
|
13075
13188
|
run: this.runStatus(v, this.storeViews(stores), app.revocations)
|
|
@@ -13280,6 +13393,10 @@ var Apps = class {
|
|
|
13280
13393
|
if (!old) return;
|
|
13281
13394
|
const next = plus(used, countOf(old, -1));
|
|
13282
13395
|
const writing = await store(STORES$1.appStorage, "readwrite");
|
|
13396
|
+
if (where !== "alone" && !this.host.isChat(where)) {
|
|
13397
|
+
this.usage.delete(`${app.ref}\0${where}`);
|
|
13398
|
+
fail("bad-scope", "Not a chat of this profile");
|
|
13399
|
+
}
|
|
13283
13400
|
if (this.uninstalls.get(app.ref) !== uninstalls) {
|
|
13284
13401
|
this.usage.delete(`${app.ref}\0${where}`);
|
|
13285
13402
|
fail("not-installed", "This app is not installed");
|
|
@@ -20817,7 +20934,7 @@ var FileDesk = class {
|
|
|
20817
20934
|
deps;
|
|
20818
20935
|
chats = /* @__PURE__ */ new Map();
|
|
20819
20936
|
speeds = /* @__PURE__ */ new Map();
|
|
20820
|
-
/** By local id: when its bytes last moved (for the stall rule). */
|
|
20937
|
+
/** By local id: when its bytes last moved (for the stall rule), and whether it then waited on a person. */
|
|
20821
20938
|
moved = /* @__PURE__ */ new Map();
|
|
20822
20939
|
/** Unfinished when the app started, and not moved since. */
|
|
20823
20940
|
restored = /* @__PURE__ */ new Set();
|
|
@@ -21151,9 +21268,16 @@ var FileDesk = class {
|
|
|
21151
21268
|
refuse: "no-room",
|
|
21152
21269
|
room
|
|
21153
21270
|
};
|
|
21271
|
+
if (room !== null && file.size + this.stillComing() > room) return "ask";
|
|
21154
21272
|
const taken = this.deps.receivedBytes(linkId) + this.autoTaken(linkId);
|
|
21155
21273
|
return file.size <= FILE_LIMITS.askAboveBytes && taken + file.size <= FILE_LIMITS.autoAcceptBytesPerPeer ? "accept" : "ask";
|
|
21156
21274
|
}
|
|
21275
|
+
/** Bytes still to come of the files taken here (every chat's, not ended): the room they will take. */
|
|
21276
|
+
stillComing() {
|
|
21277
|
+
let due = 0;
|
|
21278
|
+
for (const chat of this.chats.values()) for (const r of chat.files.records()) if (r.direction === "in" && r.state !== "asking" && !transferEnded(r)) due += Math.max(0, r.file.size - r.confirmed);
|
|
21279
|
+
return due;
|
|
21280
|
+
}
|
|
21157
21281
|
/** files/3 files this contact sent that were taken without asking and are kept (or on their way). */
|
|
21158
21282
|
autoTaken(linkId) {
|
|
21159
21283
|
const chat = this.chats.get(linkId);
|
|
@@ -21440,6 +21564,10 @@ var FileDesk = class {
|
|
|
21440
21564
|
* Whether a transfer is stuck (`transferStalled`): not moved for `FILE_LIMITS.stallMs`, or not since the app started.
|
|
21441
21565
|
* Only bytes moving count (`progress`: confirmed by the receiver, stored here), not a session saying again where it
|
|
21442
21566
|
* stands. A stall is nothing happening, so a timer looks again when it would be one.
|
|
21567
|
+
*
|
|
21568
|
+
* Time it waits on a person (an offer not answered yet, a pause) is not time stuck: its quiet spell starts when it goes
|
|
21569
|
+
* on. Before, a file accepted after its offer waited a minute read as stuck at once, "Ask again" beside it, for as
|
|
21570
|
+
* long as it waited its turn behind other files.
|
|
21443
21571
|
*/
|
|
21444
21572
|
stalled(linkId, id, record, progress) {
|
|
21445
21573
|
if (transferEnded(record)) {
|
|
@@ -21447,8 +21575,12 @@ var FileDesk = class {
|
|
|
21447
21575
|
return false;
|
|
21448
21576
|
}
|
|
21449
21577
|
const now = elapsed();
|
|
21450
|
-
|
|
21451
|
-
if (progress) this.
|
|
21578
|
+
const waiting = record.state === "asking" || record.state === "paused";
|
|
21579
|
+
if (progress || waiting || !this.moved.has(id) || this.moved.get(id).waiting) this.moved.set(id, {
|
|
21580
|
+
at: now,
|
|
21581
|
+
...waiting && { waiting }
|
|
21582
|
+
});
|
|
21583
|
+
if (progress || waiting) this.restored.delete(id);
|
|
21452
21584
|
const movedAt = this.moved.get(id).at;
|
|
21453
21585
|
const stalled = transferStalled(record, movedAt, this.restored.has(id), now);
|
|
21454
21586
|
if (!stalled && !this.stallChecks.has(id) && transferStalled(record, 0, true, now)) {
|
|
@@ -23646,8 +23778,7 @@ function noteIfStanding(current, message) {
|
|
|
23646
23778
|
* the new one, and every member would show it twice.
|
|
23647
23779
|
*/
|
|
23648
23780
|
function groupReactionsToResend(messages, limit) {
|
|
23649
|
-
|
|
23650
|
-
for (const m of messages) if (m.event === "joined" && !m.member) joinedAt = Math.max(joinedAt, m.timestamp);
|
|
23781
|
+
const joinedAt = lastJoined(messages);
|
|
23651
23782
|
return messages.flatMap((m) => {
|
|
23652
23783
|
const r = m.reactions?.me, id = replyRef(m, true);
|
|
23653
23784
|
return r && id && r.at >= joinedAt ? [{
|
|
@@ -23657,6 +23788,12 @@ function groupReactionsToResend(messages, limit) {
|
|
|
23657
23788
|
}] : [];
|
|
23658
23789
|
}).sort((a, b) => b.n - a.n).slice(0, limit);
|
|
23659
23790
|
}
|
|
23791
|
+
/** When I last joined a group (its "You joined" line): my reactions from before went out under a member key I may hold no more. */
|
|
23792
|
+
function lastJoined(messages) {
|
|
23793
|
+
let at = 0;
|
|
23794
|
+
for (const m of messages) if (m.event === "joined" && !m.member) at = Math.max(at, m.timestamp);
|
|
23795
|
+
return at;
|
|
23796
|
+
}
|
|
23660
23797
|
/** This side's highest number in a chat's history: the next one goes past it. */
|
|
23661
23798
|
function lastMine(messages) {
|
|
23662
23799
|
let last = 0;
|
|
@@ -23680,6 +23817,8 @@ var Reactions = class {
|
|
|
23680
23817
|
* out. It only has to grow, so a row deleted since leaves it too high and nothing is wrong.
|
|
23681
23818
|
*/
|
|
23682
23819
|
last = /* @__PURE__ */ new Map();
|
|
23820
|
+
/** Per private group's chat: my member key and when I joined under it (`joinedAt`). */
|
|
23821
|
+
joined = /* @__PURE__ */ new Map();
|
|
23683
23822
|
/** Per 1:1 chat: when it was last read whole for a received reaction, and the read of those that waited meanwhile. */
|
|
23684
23823
|
lookups = /* @__PURE__ */ new Map();
|
|
23685
23824
|
constructor(host) {
|
|
@@ -23708,7 +23847,10 @@ var Reactions = class {
|
|
|
23708
23847
|
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or takes no reaction` };
|
|
23709
23848
|
const current = target.reactions?.me;
|
|
23710
23849
|
if (!e && !current?.e) return { error: "No reaction of yours to take back" };
|
|
23711
|
-
let
|
|
23850
|
+
let history;
|
|
23851
|
+
const read = async () => history ??= await this.host.messages(chat);
|
|
23852
|
+
if (group && current?.e && current.at < await this.joinedAt(chat, read)) return { error: "Your reaction to this message went out before you were invited back, and stays as it is" };
|
|
23853
|
+
let last = this.last.get(chat) ?? lastMine(await read());
|
|
23712
23854
|
for (const p of pending) last = Math.max(last, p.n);
|
|
23713
23855
|
const reaction = {
|
|
23714
23856
|
id,
|
|
@@ -23723,6 +23865,24 @@ var Reactions = class {
|
|
|
23723
23865
|
});
|
|
23724
23866
|
}
|
|
23725
23867
|
/**
|
|
23868
|
+
* When I joined a private group under the member key I hold now: removed and invited back, I hold a new one, and the
|
|
23869
|
+
* members keep a reaction of mine from before under the old one. Said again under the new key, a change or a take
|
|
23870
|
+
* back left it standing for them, beside the new one. Read from the history once per key.
|
|
23871
|
+
*/
|
|
23872
|
+
async joinedAt(chat, read) {
|
|
23873
|
+
const key = this.host.memberKey?.(chat);
|
|
23874
|
+
if (!key) return 0;
|
|
23875
|
+
const known = this.joined.get(chat);
|
|
23876
|
+
if (known?.key === key) return known.at;
|
|
23877
|
+
const messages = await read(), at = lastJoined(messages);
|
|
23878
|
+
this.joined.set(chat, {
|
|
23879
|
+
key,
|
|
23880
|
+
at
|
|
23881
|
+
});
|
|
23882
|
+
if (!this.last.has(chat)) this.last.set(chat, lastMine(messages));
|
|
23883
|
+
return at;
|
|
23884
|
+
}
|
|
23885
|
+
/**
|
|
23726
23886
|
* A reaction that came from `by` (`peer`, or a member's key), already authenticated as theirs. A message not here
|
|
23727
23887
|
* yet keeps it for five minutes; past the room for that sender, it is dropped (and, on a 1:1 session, not confirmed).
|
|
23728
23888
|
* Past `REACTION_LIMITS.receive` a window from one group member, the rest wait for the next window (`hold`): a
|
|
@@ -23930,6 +24090,7 @@ var Reactions = class {
|
|
|
23930
24090
|
this.dropHeld(chat);
|
|
23931
24091
|
this.waiting.delete(chat);
|
|
23932
24092
|
this.last.delete(chat);
|
|
24093
|
+
this.joined.delete(chat);
|
|
23933
24094
|
clearTimeout(this.lookups.get(chat)?.timer);
|
|
23934
24095
|
this.lookups.delete(chat);
|
|
23935
24096
|
}
|
|
@@ -24184,7 +24345,8 @@ var GroupRows = class {
|
|
|
24184
24345
|
this.written.delete(groupId);
|
|
24185
24346
|
await raw.deleteGroup(groupId);
|
|
24186
24347
|
},
|
|
24187
|
-
getMessages: (linkId) => raw.getMessages(linkId)
|
|
24348
|
+
getMessages: (linkId) => raw.getMessages(linkId),
|
|
24349
|
+
...raw.getMessagePage && { getMessagePage: (linkId, page) => raw.getMessagePage(linkId, page) }
|
|
24188
24350
|
};
|
|
24189
24351
|
}
|
|
24190
24352
|
/**
|
|
@@ -24758,6 +24920,11 @@ var AWAIT_EDGE_MS = 12e4;
|
|
|
24758
24920
|
* hub its members a minute, another hub three), and the app dials those that were live once at start (`resume`).
|
|
24759
24921
|
*/
|
|
24760
24922
|
var RESTORED_EDGE_MS = 6e4;
|
|
24923
|
+
/**
|
|
24924
|
+
* Of those, the edges to members (not to hubs, and not up yet) a hub keeps: what its relays' budget brings up in about
|
|
24925
|
+
* a minute. The others close at its first reading of the beacon, and those members ask another hub at once.
|
|
24926
|
+
*/
|
|
24927
|
+
var RESTORED_MEMBER_EDGES = 6;
|
|
24761
24928
|
/** After letting someone in, the door keeps its reads at the admitting pace this long. */
|
|
24762
24929
|
var ADMITTED_QUIET_MS = 3e4;
|
|
24763
24930
|
var MAX_PENDING_ENTRIES$1 = 8;
|
|
@@ -24801,6 +24968,14 @@ var TIP_CHECK_EVERY_MS = 3e5;
|
|
|
24801
24968
|
* group that needs one more hub gets it.
|
|
24802
24969
|
*/
|
|
24803
24970
|
var CUT_OFF_STEP_UP_MS = 15e3;
|
|
24971
|
+
/**
|
|
24972
|
+
* Members that lost their hub step in for it (`stepsIn`) this long after, one turn this long each, one of them for each
|
|
24973
|
+
* `STEP_IN_LOAD` members it carried: about what a new hub's relays' budget brings up in its first minute. One for every
|
|
24974
|
+
* 10 or 12 left the new hubs too slow (worst 175 s against 137, 36 members, 2026-11-13); one for every 6, no faster.
|
|
24975
|
+
*/
|
|
24976
|
+
var STEP_IN_MS = 6e4;
|
|
24977
|
+
var STEP_IN_TURN_MS = 3e3;
|
|
24978
|
+
var STEP_IN_LOAD = 8;
|
|
24804
24979
|
/** A lobby request this recent is from a member still looking fast for my side of the edge: mine opens expecting it. */
|
|
24805
24980
|
var LOBBY_EXPECT_MS = 3e4;
|
|
24806
24981
|
/**
|
|
@@ -24836,7 +25011,9 @@ var FULL_SAID_MS$1 = 66e4;
|
|
|
24836
25011
|
* the accept refused, every turn of the door for as long as the admin was away.
|
|
24837
25012
|
*/
|
|
24838
25013
|
function admissionsHeld(s) {
|
|
24839
|
-
|
|
25014
|
+
return !s.isAdmin && membersAtBound(s);
|
|
25015
|
+
}
|
|
25016
|
+
function membersAtBound(s) {
|
|
24840
25017
|
const admin = s.admin, chain = s.state.chain;
|
|
24841
25018
|
let n = 0;
|
|
24842
25019
|
for (let i = chain.length - 1; i >= 0; i--) {
|
|
@@ -24846,6 +25023,16 @@ function admissionsHeld(s) {
|
|
|
24846
25023
|
}
|
|
24847
25024
|
return n >= COMMUNITY_LIMITS.memberAdmissions;
|
|
24848
25025
|
}
|
|
25026
|
+
/**
|
|
25027
|
+
* Whether the admin's app is wanted at the door: the members signed all the admissions in a row they may, and only the
|
|
25028
|
+
* admin lets the next person in. Only hubs answer knocks, and an admin's app that is no hub (the role was handed to
|
|
25029
|
+
* it, or it stepped down when idle) let nobody in while it was open: whoever opened the link waited for good, nobody
|
|
25030
|
+
* told (bug hunt, 2026-11-12: the role handed to a member at 40 members, then 50 opening the link: 32 let in, 18
|
|
25031
|
+
* knocking 20 minutes later). It is one more hub until it lets someone in, which opens the members' door again.
|
|
25032
|
+
*/
|
|
25033
|
+
function adminAtDoor(s) {
|
|
25034
|
+
return s.isAdmin && s.adminWork && !!s.entryKey && !!s.state.entry.seedB64 && membersAtBound(s);
|
|
25035
|
+
}
|
|
24849
25036
|
var RELAYED_KEPT = 4096;
|
|
24850
25037
|
/**
|
|
24851
25038
|
* Someone the chain took out while its app was closed comes back believing it is a member: it asks in a hub's lobby,
|
|
@@ -25025,16 +25212,22 @@ var Communities = class {
|
|
|
25025
25212
|
const live = this.live.get(groupId);
|
|
25026
25213
|
return !!live?.hub && live.session.status === "active";
|
|
25027
25214
|
}
|
|
25028
|
-
|
|
25215
|
+
/** `newestOnly`: a run that starts no group reads each history's newest message alone (`Groups.load`). */
|
|
25216
|
+
async load(groups, newestOnly = false) {
|
|
25029
25217
|
for (const group of groups) {
|
|
25030
25218
|
this.stored.set(group.id, group);
|
|
25031
|
-
|
|
25032
|
-
|
|
25033
|
-
|
|
25034
|
-
|
|
25035
|
-
|
|
25036
|
-
|
|
25037
|
-
|
|
25219
|
+
if (newestOnly) {
|
|
25220
|
+
if (group.community) this.attach(group.community);
|
|
25221
|
+
await loadNewest(this.marks, this.store, group.id);
|
|
25222
|
+
} else {
|
|
25223
|
+
const history = await this.store.getMessages(MESSAGE_LINK$1(group.id));
|
|
25224
|
+
if (group.community) this.attach(group.community, history.flatMap((m) => m.frame ? [{
|
|
25225
|
+
id: m.id,
|
|
25226
|
+
frame: m.frame
|
|
25227
|
+
}] : []));
|
|
25228
|
+
loadMarks(this.marks, group, history);
|
|
25229
|
+
this.host.loaded?.(group.id, history);
|
|
25230
|
+
}
|
|
25038
25231
|
for (const [, linkId] of this.host.entries(group.id)) if (group.joining?.linkId !== linkId) await this.host.closeEdge(linkId);
|
|
25039
25232
|
const live = this.live.get(group.id);
|
|
25040
25233
|
if (live) for (const key of this.host.edges(group.id).keys()) live.restored.set(key, 0);
|
|
@@ -25051,7 +25244,7 @@ var Communities = class {
|
|
|
25051
25244
|
/** A message deleted for everyone left this device: the marks it set go back (`unmark` in groups.ts); `mentionOnly`, its "@" alone. */
|
|
25052
25245
|
async unmark(groupId, removed, mentionOnly = false) {
|
|
25053
25246
|
const group = this.stored.get(groupId);
|
|
25054
|
-
if (await unmark(this.marks, group, groupId,
|
|
25247
|
+
if (await unmark(this.marks, group, groupId, this.store, removed, mentionOnly) && group) await this.store.putGroup(group);
|
|
25055
25248
|
}
|
|
25056
25249
|
views() {
|
|
25057
25250
|
return [...this.stored.values()].flatMap((group) => this.viewOf(group));
|
|
@@ -25457,14 +25650,14 @@ var Communities = class {
|
|
|
25457
25650
|
if (!rosterHas(s.roster, s.myKey) && !this.handedToLeaver(left)) await this.dropLeftBehind(groupId);
|
|
25458
25651
|
else if (now - left.since > LEFT_FOLLOW_MS) await this.dropLeftBehind(groupId);
|
|
25459
25652
|
else if (!rosterHas(s.roster, s.myKey)) left.handOnAt = void 0;
|
|
25460
|
-
else if (s.admin !== s.myKey) left.handOnAt = void 0;
|
|
25461
25653
|
else {
|
|
25462
|
-
if (
|
|
25654
|
+
if (now - (left.askedAt ?? 0) >= (s.leftWaitsForSecret ? 5e3 : 3e4)) {
|
|
25463
25655
|
left.askedAt = now;
|
|
25464
25656
|
const ready = [...this.host.edges(groupId)].filter(([key, id]) => key !== s.myKey && this.host.linkReady(id, 2) && rosterHas(s.roster, key)).map(([key]) => key);
|
|
25465
25657
|
for (const key of ready.slice(0, 3)) s.catchUp(key);
|
|
25466
25658
|
}
|
|
25467
|
-
if (
|
|
25659
|
+
if (s.admin !== s.myKey) left.handOnAt = void 0;
|
|
25660
|
+
else if (left.handOnAt === void 0) left.handOnAt = now + LEFT_HAND_ON_MS$1;
|
|
25468
25661
|
else if (now >= left.handOnAt) await this.handOn(groupId, now);
|
|
25469
25662
|
}
|
|
25470
25663
|
}
|
|
@@ -25713,9 +25906,10 @@ var Communities = class {
|
|
|
25713
25906
|
live.cutOffSince ??= now;
|
|
25714
25907
|
return now - live.cutOffSince < CUT_OFF_STEP_UP_MS;
|
|
25715
25908
|
};
|
|
25716
|
-
const
|
|
25909
|
+
const stepIn = () => this.stepsIn(live, now);
|
|
25910
|
+
const want = () => settled() && (stepIn() !== void 0 || !cutOff() && (shouldBeHub(me, this.hubs(live), now) || (!!live.forceHub || adminAtDoor(s)) && freshHubs(this.hubs(live), now).length < COMMUNITY_TOPOLOGY.maxHubs)) && this.capacity(groupId, live, now) > 0;
|
|
25717
25911
|
if (want()) {
|
|
25718
|
-
if (!live.hubCandidateAt) live.hubCandidateAt = now + (freshHubs(this.hubs(live), now).length ? Math.floor(this.random() * this.timings.hubJitterMs) : 0);
|
|
25912
|
+
if (!live.hubCandidateAt) live.hubCandidateAt = stepIn() ?? now + (freshHubs(this.hubs(live), now).length ? Math.floor(this.random() * this.timings.hubJitterMs) : 0);
|
|
25719
25913
|
if (now >= live.hubCandidateAt) {
|
|
25720
25914
|
live.hubCandidateAt = 0;
|
|
25721
25915
|
if (live.lastBeaconRead !== now) await this.readBeacon(groupId, live, now);
|
|
@@ -25726,6 +25920,7 @@ var Communities = class {
|
|
|
25726
25920
|
live.emptySince = now;
|
|
25727
25921
|
live.leaving = 0;
|
|
25728
25922
|
live.knocksScanned = false;
|
|
25923
|
+
if (stepIn() !== void 0) live.lobbyBusyUntil = now + this.timings.lobbyBusyMs;
|
|
25729
25924
|
await this.publishBeacon(groupId, live, now, true).catch(() => {});
|
|
25730
25925
|
traceJoin(groupId, "hub.elected");
|
|
25731
25926
|
}
|
|
@@ -25735,7 +25930,7 @@ var Communities = class {
|
|
|
25735
25930
|
if (live.hub) {
|
|
25736
25931
|
const load = this.hubLoad(groupId, live, now);
|
|
25737
25932
|
if (load > 0) live.emptySince = now;
|
|
25738
|
-
const idle = now - live.emptySince > this.timings.idleHubMs && now - live.hubSince > this.timings.idleHubMs;
|
|
25933
|
+
const idle = now - live.emptySince > this.timings.idleHubMs && now - live.hubSince > this.timings.idleHubMs && !adminAtDoor(s);
|
|
25739
25934
|
if (live.leaving) {
|
|
25740
25935
|
const read = live.beaconAt > live.leaving, listed = live.beacon.some((h) => h.key === me);
|
|
25741
25936
|
if (read && idle && !listed && this.canStepDown(groupId, live, now)) {
|
|
@@ -25812,6 +26007,11 @@ var Communities = class {
|
|
|
25812
26007
|
const wait = (back || taking || live.replacing?.has(key) ? 3 : listed ? 2 : 1) * this.timings.hubWaitMs;
|
|
25813
26008
|
const dropped = !live.hubsUp.has(key) && live.beaconAt === now && live.seenHubs.has(key) && !live.beacon.some((h) => h.key === key);
|
|
25814
26009
|
if (now - since > wait || dropped) {
|
|
26010
|
+
if (live.hubsUp.has(key) && !back) live.lostHub = {
|
|
26011
|
+
key,
|
|
26012
|
+
at: now,
|
|
26013
|
+
load: live.beacon.find((h) => h.key === key)?.load ?? 0
|
|
26014
|
+
};
|
|
25815
26015
|
if (live.hubsUp.has(key) || dropped) lost = true;
|
|
25816
26016
|
live.hubsAvoided.set(key, now + 2 * wait);
|
|
25817
26017
|
live.hubWaits.delete(key);
|
|
@@ -25826,14 +26026,18 @@ var Communities = class {
|
|
|
25826
26026
|
}
|
|
25827
26027
|
const picked = pickHubs(me, others, now, new Set(live.hubsAvoided.keys()));
|
|
25828
26028
|
const bare = ![...edges.values()].some((id) => this.host.linkReady(id, 2));
|
|
25829
|
-
|
|
25830
|
-
|
|
25831
|
-
|
|
25832
|
-
|
|
26029
|
+
const waiting = !kept.length && (this.stepsIn(live, now) ?? 0) > now;
|
|
26030
|
+
const lostLately = !!live.lostHub && now - live.lostHub.at <= STEP_IN_MS;
|
|
26031
|
+
if (!waiting) {
|
|
26032
|
+
for (const key of picked) if (kept.length < Math.max(1, picked.length) && !kept.includes(key)) {
|
|
26033
|
+
kept.push(key);
|
|
26034
|
+
if ((gone.length || lost || lostLately || bare) && !edges.has(key)) live.expect.add(key);
|
|
26035
|
+
if (gone.length || lost || lostLately) (live.replacing ??= /* @__PURE__ */ new Set()).add(key);
|
|
26036
|
+
}
|
|
25833
26037
|
}
|
|
25834
26038
|
await this.lookPast(groupId, live, others, kept, now);
|
|
25835
26039
|
live.myHubs = kept;
|
|
25836
|
-
live.forceHub = !kept.length && others.length < COMMUNITY_TOPOLOGY.maxHubs;
|
|
26040
|
+
live.forceHub = !waiting && !kept.length && others.length < COMMUNITY_TOPOLOGY.maxHubs;
|
|
25837
26041
|
for (const hub of kept) {
|
|
25838
26042
|
const id = edges.get(hub);
|
|
25839
26043
|
if (id && this.host.linkReady(id, 2)) {
|
|
@@ -25865,7 +26069,12 @@ var Communities = class {
|
|
|
25865
26069
|
} else if (now - since > ENTRY_TIMEOUT_MS$1) {
|
|
25866
26070
|
live.pendingEntries.delete(key);
|
|
25867
26071
|
this.refused.set(key, now + REFUSED_FOR_MS$1);
|
|
25868
|
-
} else
|
|
26072
|
+
} else {
|
|
26073
|
+
const invited = live.invitedAt?.get(key);
|
|
26074
|
+
if (up && invited !== void 0 && now - invited >= ENTRY_LINGER_MS$1 && !live.accepting?.has(key)) this.entryReady(groupId, linkId, key);
|
|
26075
|
+
continue;
|
|
26076
|
+
}
|
|
26077
|
+
live.invitedAt?.delete(key);
|
|
25869
26078
|
if (linkId) await this.host.closeEdge(linkId);
|
|
25870
26079
|
}
|
|
25871
26080
|
if (live.unanswered) {
|
|
@@ -25972,6 +26181,33 @@ var Communities = class {
|
|
|
25972
26181
|
return !!id && this.host.linkReady(id, 2);
|
|
25973
26182
|
});
|
|
25974
26183
|
}
|
|
26184
|
+
/**
|
|
26185
|
+
* As a member that gave up on a hub whose edge was up (killed, or closed for good) that carried more members than one
|
|
26186
|
+
* hub brings up in a minute, when only one of the hubs from before is left (most often the admin's): when I step up in
|
|
26187
|
+
* its place, or undefined once enough members did (one for each `STEP_IN_LOAD` of the load its last entry said), or
|
|
26188
|
+
* after `STEP_IN_MS`. Its members lost it in the same seconds and know nothing of each other: they take turns by
|
|
26189
|
+
* rendezvous rank for its key (`hubRank`) among the members that are no hubs, `STEP_IN_TURN_MS` each, a turn taken
|
|
26190
|
+
* only on a reading that still lists too few. Until its turn, or until enough stepped in, a member asks no hub
|
|
26191
|
+
* (`waiting` in `topology`), then picks among them all.
|
|
26192
|
+
*
|
|
26193
|
+
* Before, they all asked the hub left, which opened their 7-19 edges at once: its relays' 60 requests a minute went in
|
|
26194
|
+
* the first seconds on looking for them all, and almost none came up for two minutes. Each waited a minute for it, then
|
|
26195
|
+
* 3-7 stepped up in the same second as hubs with no edge to anyone (36 members, 22 seeds with only the admin's hub
|
|
26196
|
+
* left: median 208 s until everyone had everyone's lines, worst 277; now 106 and 148, no hub with nobody on it).
|
|
26197
|
+
*/
|
|
26198
|
+
stepsIn(live, now) {
|
|
26199
|
+
const lost = live.lostHub;
|
|
26200
|
+
if (!lost || now - lost.at > STEP_IN_MS || lost.load <= RESTORED_MEMBER_EDGES) return void 0;
|
|
26201
|
+
const s = live.session, me = s.myKey, fresh = freshHubs(this.hubs(live), now);
|
|
26202
|
+
if (fresh.some((h) => h.key === lost.key && h.ts > lost.at)) return void 0;
|
|
26203
|
+
const others = fresh.filter((h) => h.key !== me && h.key !== lost.key);
|
|
26204
|
+
const stepped = others.filter((h) => (h.since ?? h.ts) >= lost.at - STEP_IN_MS);
|
|
26205
|
+
if (others.length - stepped.length !== 1) return void 0;
|
|
26206
|
+
if (stepped.length >= Math.max(1, Math.ceil(lost.load / STEP_IN_LOAD))) return void 0;
|
|
26207
|
+
const hubs = new Set(fresh.map((h) => h.key));
|
|
26208
|
+
const turn = rankHubs(lost.key, s.roster.map(([key]) => key).filter((key) => !hubs.has(key) && key !== s.admin)).indexOf(me);
|
|
26209
|
+
return turn < 0 ? void 0 : lost.at + turn * STEP_IN_TURN_MS;
|
|
26210
|
+
}
|
|
25975
26211
|
hubLoad(groupId, live, now) {
|
|
25976
26212
|
const edges = this.host.edges(groupId);
|
|
25977
26213
|
if (now - live.beaconAt <= 2 * this.timings.beaconReadMs) {
|
|
@@ -25984,7 +26220,7 @@ var Communities = class {
|
|
|
25984
26220
|
}
|
|
25985
26221
|
for (const [key, since] of live.members) {
|
|
25986
26222
|
const id = edges.get(key);
|
|
25987
|
-
if (this.gone(live, key)) live.members.delete(key);
|
|
26223
|
+
if (this.gone(live, key) || !rosterHas(live.session.roster, key)) live.members.delete(key);
|
|
25988
26224
|
else if (id && this.host.linkReady(id, 2)) live.members.set(key, now);
|
|
25989
26225
|
else if (live.session.wasRemoved(key)) live.members.delete(key);
|
|
25990
26226
|
else if (now - since > this.timings.memberGoneMs) {
|
|
@@ -26304,6 +26540,16 @@ var Communities = class {
|
|
|
26304
26540
|
} else for (const key of live.myHubs) wanted.add(key);
|
|
26305
26541
|
for (const [key, id] of existing) if (this.host.linkReady(id, 2) && (live.members.has(key) || this.recentHub(live, key)) && !this.gone(live, key)) wanted.add(key);
|
|
26306
26542
|
}
|
|
26543
|
+
if (!live.restoredTrimmed && live.beaconKnown) {
|
|
26544
|
+
live.restoredTrimmed = true;
|
|
26545
|
+
const hubs = new Set(freshHubs(this.hubs(live), now).map((h) => h.key));
|
|
26546
|
+
let kept = 0;
|
|
26547
|
+
for (const key of [...live.restored.keys()]) {
|
|
26548
|
+
const id = existing.get(key);
|
|
26549
|
+
if (hubs.has(key) || id && this.host.linkReady(id, 2)) continue;
|
|
26550
|
+
if (++kept > RESTORED_MEMBER_EDGES) live.restored.delete(key);
|
|
26551
|
+
}
|
|
26552
|
+
}
|
|
26307
26553
|
for (const [key, since] of live.restored) {
|
|
26308
26554
|
if (!since) live.restored.set(key, now);
|
|
26309
26555
|
if (!existing.has(key) || now - (since || now) >= RESTORED_EDGE_MS || s.wasRemoved(key)) live.restored.delete(key);
|
|
@@ -26482,9 +26728,10 @@ var Communities = class {
|
|
|
26482
26728
|
const turn = Math.floor(waited / KNOCK_SLOT_MS) % order.length, early = order.length === 1 || waited % KNOCK_SLOT_MS < KNOCK_SLOT_OPEN_MS;
|
|
26483
26729
|
if (order[turn] !== s.myKey || !early || waited >= KNOCK_SLOT_MS && !stillKnocking) continue;
|
|
26484
26730
|
if (live.pendingEntries.size >= MAX_PENDING_ENTRIES$1) break;
|
|
26485
|
-
if (
|
|
26731
|
+
if (this.room(groupId, live, now) <= live.members.size) break;
|
|
26486
26732
|
if (this.host.adminTurn && !await this.host.adminTurn(groupId, { wait: false })) break;
|
|
26487
26733
|
live.pendingEntries.set(key, now);
|
|
26734
|
+
live.invitedAt?.delete(key);
|
|
26488
26735
|
live.doorKey = link.host;
|
|
26489
26736
|
traceJoin(groupId, "knock.seen", {
|
|
26490
26737
|
age: now - ts,
|
|
@@ -26599,6 +26846,7 @@ var Communities = class {
|
|
|
26599
26846
|
async closeEntries(groupId) {
|
|
26600
26847
|
const live = this.live.get(groupId), mine = this.stored.get(groupId)?.joining?.linkId;
|
|
26601
26848
|
live?.pendingEntries.clear();
|
|
26849
|
+
live?.invitedAt?.clear();
|
|
26602
26850
|
for (const linkId of this.host.entries(groupId).values()) if (linkId !== mine) await this.host.closeEdge(linkId);
|
|
26603
26851
|
}
|
|
26604
26852
|
/** An entry session of a community came up with groups v2 on both sides: the hub invites. */
|
|
@@ -26631,6 +26879,7 @@ var Communities = class {
|
|
|
26631
26879
|
this.host.sendOnLink(linkId, live.session.inviteFrame());
|
|
26632
26880
|
traceJoin(groupId, "invite.sent");
|
|
26633
26881
|
} catch {}
|
|
26882
|
+
(live.invitedAt ??= /* @__PURE__ */ new Map()).set(peer, now);
|
|
26634
26883
|
return true;
|
|
26635
26884
|
}
|
|
26636
26885
|
/** Admission frames on an entry session (either side). */
|
|
@@ -26661,7 +26910,8 @@ var Communities = class {
|
|
|
26661
26910
|
}
|
|
26662
26911
|
case "group-full": {
|
|
26663
26912
|
const joining = group.joining, { n, max } = frame;
|
|
26664
|
-
if (!joining || joining.linkId !== linkId || joining.inviter || !Number.isSafeInteger(n) || !Number.isSafeInteger(max)
|
|
26913
|
+
if (!joining || joining.linkId !== linkId || joining.inviter || !Number.isSafeInteger(n) || !Number.isSafeInteger(max)) return;
|
|
26914
|
+
if (max < 1 || max > COMMUNITY_LIMITS.members || n < 0 || n > max) return;
|
|
26665
26915
|
this.toldFull.set(g, {
|
|
26666
26916
|
n,
|
|
26667
26917
|
max,
|
|
@@ -26676,6 +26926,9 @@ var Communities = class {
|
|
|
26676
26926
|
const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
|
|
26677
26927
|
if (!live || !peer || frame.key !== peer || !live.pendingEntries.has(peer)) return;
|
|
26678
26928
|
if (live.doorKey !== live.session.entryKey) return;
|
|
26929
|
+
if (live.accepting?.has(peer)) return;
|
|
26930
|
+
(live.accepting ??= /* @__PURE__ */ new Set()).add(peer);
|
|
26931
|
+
live.invitedAt?.delete(peer);
|
|
26679
26932
|
let welcome;
|
|
26680
26933
|
try {
|
|
26681
26934
|
welcome = rosterHas(live.session.roster, peer) ? await live.session.rewelcome(peer) : await live.session.admit(peer, this.now());
|
|
@@ -26683,6 +26936,8 @@ var Communities = class {
|
|
|
26683
26936
|
live.pendingEntries.delete(peer);
|
|
26684
26937
|
await this.host.closeEdge(linkId);
|
|
26685
26938
|
return;
|
|
26939
|
+
} finally {
|
|
26940
|
+
live.accepting.delete(peer);
|
|
26686
26941
|
}
|
|
26687
26942
|
for (const piece of welcome) try {
|
|
26688
26943
|
this.host.sendOnLink(linkId, piece);
|
|
@@ -26776,6 +27031,7 @@ var Communities = class {
|
|
|
26776
27031
|
const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
|
|
26777
27032
|
if (live && peer) {
|
|
26778
27033
|
live.pendingEntries.delete(peer);
|
|
27034
|
+
live.invitedAt?.delete(peer);
|
|
26779
27035
|
await this.host.closeEdge(linkId);
|
|
26780
27036
|
}
|
|
26781
27037
|
return;
|
|
@@ -26803,15 +27059,16 @@ var Communities = class {
|
|
|
26803
27059
|
if (!named && f.t !== "group-commit" && f.t !== "group-msg" && f.t !== "group-secrets" && !(f.t === "group-secret" && f.to === live.session.myKey)) return;
|
|
26804
27060
|
if ((f.t === "group-secret" || f.t === "group-entry") && typeof f.to === "string" && f.to !== live.session.myKey) {
|
|
26805
27061
|
if (!live.hub) return;
|
|
26806
|
-
const
|
|
27062
|
+
const routed = routedCommunityFrame(f);
|
|
27063
|
+
if (!routed || routed.g !== groupId || !live.session.isRecentMember(routed.to) || live.session.wasRemoved(routed.to)) return;
|
|
27064
|
+
const id = `${routed.t}:${routed.to}:${routed.t === "group-secret" ? routed.h : routed.x}`;
|
|
26807
27065
|
if (!this.remember(live, id)) return;
|
|
26808
|
-
|
|
26809
|
-
const edges = this.host.edges(groupId), direct = edges.get(f.to);
|
|
27066
|
+
const edges = this.host.edges(groupId), direct = edges.get(routed.to);
|
|
26810
27067
|
if (direct && this.host.linkReady(direct, 2)) {
|
|
26811
|
-
this.sendTo(direct,
|
|
27068
|
+
this.sendTo(direct, routed);
|
|
26812
27069
|
return;
|
|
26813
27070
|
}
|
|
26814
|
-
for (const [key, id] of edges) if (key !== peerKey && this.peerIsHub(live, key)) this.sendTo(id,
|
|
27071
|
+
for (const [key, id] of edges) if (key !== peerKey && this.peerIsHub(live, key)) this.sendTo(id, routed);
|
|
26815
27072
|
return;
|
|
26816
27073
|
}
|
|
26817
27074
|
if (!await live.session.handle(peerKey, frame) || !live.hub) return;
|
|
@@ -27769,13 +28026,18 @@ var MeshHubs = class {
|
|
|
27769
28026
|
}
|
|
27770
28027
|
/**
|
|
27771
28028
|
* As a hub, a member's signed reaction goes on to my other edges, the first time I see that number from that member
|
|
27772
|
-
* for that message; and it is kept (the latest `REACTIONS_KEPT`) for members whose edge opens later.
|
|
28029
|
+
* for that message; and it is kept (the latest `REACTIONS_KEPT`) for members whose edge opens later. Stepped down,
|
|
28030
|
+
* one I kept still follows what I take: a hub again, I would say a reaction taken back meanwhile to a member back.
|
|
27773
28031
|
*/
|
|
27774
28032
|
passReaction(groupId, session, from, frame) {
|
|
27775
28033
|
const live = this.live.get(groupId);
|
|
27776
|
-
if (!live
|
|
28034
|
+
if (!live) return;
|
|
27777
28035
|
const at = `${frame.k} ${frame.id}`, held = live.reactions.get(at);
|
|
27778
28036
|
if (held && held.n >= frame.n) return;
|
|
28037
|
+
if (!live.hub) {
|
|
28038
|
+
if (held) live.reactions.set(at, frame);
|
|
28039
|
+
return;
|
|
28040
|
+
}
|
|
27779
28041
|
let pace = live.reactionPace.get(frame.k);
|
|
27780
28042
|
if (!pace) live.reactionPace.set(frame.k, pace = new ReactionWindow(REACTION_LIMITS.receive, REACTION_LIMITS.windowMs));
|
|
27781
28043
|
if (!pace.take()) return;
|
|
@@ -28323,6 +28585,20 @@ function loadMarks(marks, group, history) {
|
|
|
28323
28585
|
mention: mention?.id
|
|
28324
28586
|
});
|
|
28325
28587
|
}
|
|
28588
|
+
/**
|
|
28589
|
+
* What `load` reads of a group's history in a run that starts no group (`NodeOptions.offline`): its newest message,
|
|
28590
|
+
* read from the newest back, for the list's order, as a 1:1 chat left unstarted reads its newest row. The other marks
|
|
28591
|
+
* and what the rest of the history gives a session are of no use to a run that takes and sends nothing.
|
|
28592
|
+
*/
|
|
28593
|
+
async function loadNewest(marks, store, groupId) {
|
|
28594
|
+
const { last } = await newestMarkedOf(store, MESSAGE_LINK(groupId), "", {
|
|
28595
|
+
last: true,
|
|
28596
|
+
peer: false,
|
|
28597
|
+
mention: false
|
|
28598
|
+
});
|
|
28599
|
+
if (last) marks.lastMessageAt.set(groupId, last.timestamp);
|
|
28600
|
+
marks.by.set(groupId, { last: last?.id });
|
|
28601
|
+
}
|
|
28326
28602
|
/** A group gone from this engine: its marks too. */
|
|
28327
28603
|
function dropMarks(marks, groupId) {
|
|
28328
28604
|
marks.lastMessageAt.delete(groupId);
|
|
@@ -28340,18 +28616,53 @@ function newestMarked(history) {
|
|
|
28340
28616
|
};
|
|
28341
28617
|
}
|
|
28342
28618
|
/**
|
|
28619
|
+
* `newestMarked` of a group's rows without `skip`, for the marks in `want` only: read a page at a time from the newest
|
|
28620
|
+
* back until each is found, where the whole history cost ~20 ms per 1,000 rows on each member's daemon for every delete.
|
|
28621
|
+
* Past `UNMARK_PAGES`, or with a store without pages, it reads the whole history.
|
|
28622
|
+
*/
|
|
28623
|
+
async function newestMarkedOf(store, linkId, skip, want) {
|
|
28624
|
+
const whole = async () => newestMarked((await store.getMessages(linkId)).filter((m) => m.id !== skip));
|
|
28625
|
+
if (!store.getMessagePage) return whole();
|
|
28626
|
+
const found = {};
|
|
28627
|
+
for (let before, pages = 0;; pages++) {
|
|
28628
|
+
if (pages === 4) return whole();
|
|
28629
|
+
const page = await store.getMessagePage(linkId, {
|
|
28630
|
+
limit: 64,
|
|
28631
|
+
before
|
|
28632
|
+
});
|
|
28633
|
+
for (const m of [...page.messages].reverse()) {
|
|
28634
|
+
if (m.id === skip) continue;
|
|
28635
|
+
if (!m.event && !m.groupPay) {
|
|
28636
|
+
found.last ??= m;
|
|
28637
|
+
if (m.sender !== "me") found.peer ??= m;
|
|
28638
|
+
}
|
|
28639
|
+
if (m.mentioned) found.mention ??= m;
|
|
28640
|
+
}
|
|
28641
|
+
const oldest = page.messages[0];
|
|
28642
|
+
if (!page.more || !oldest || (!want.last || found.last) && (!want.peer || found.peer) && (!want.mention || found.mention)) return found;
|
|
28643
|
+
before = {
|
|
28644
|
+
timestamp: oldest.timestamp,
|
|
28645
|
+
id: oldest.id
|
|
28646
|
+
};
|
|
28647
|
+
}
|
|
28648
|
+
}
|
|
28649
|
+
/**
|
|
28343
28650
|
* A message deleted for everyone (WISP 400 § Delete for everyone: a tombstone does not count as unread or move the
|
|
28344
28651
|
* chat): the marks it moved go back to the newest line still kept, as `load` reads them, and the record's `came` it
|
|
28345
28652
|
* raised goes too. A mark a newer line moved stays, and the history is read only when the message moved one
|
|
28346
|
-
* (`markedBy`): removals go at the pace of edits. `history`: the group's rows,
|
|
28347
|
-
*
|
|
28348
|
-
* the "@" goes back.
|
|
28653
|
+
* (`markedBy`): removals go at the pace of edits. `history`: where the group's rows are, read from the newest back
|
|
28654
|
+
* until each mark to move is found (`newestMarkedOf`). True when `came` changed (the record is to be saved).
|
|
28655
|
+
* `mentionOnly`: an edit took my mention out of it: the message is still there, so only the "@" goes back.
|
|
28349
28656
|
*/
|
|
28350
28657
|
async function unmark(marks, group, groupId, history, removed, mentionOnly = false) {
|
|
28351
28658
|
const by = marks.by.get(groupId);
|
|
28352
28659
|
const last = !mentionOnly && by?.last === removed.id, peer = !mentionOnly && by?.peer === removed.id, mention = by?.mention === removed.id;
|
|
28353
28660
|
if (!by || !(last || peer || mention)) return false;
|
|
28354
|
-
const newest =
|
|
28661
|
+
const newest = await newestMarkedOf(history, MESSAGE_LINK(groupId), removed.id, {
|
|
28662
|
+
last,
|
|
28663
|
+
peer,
|
|
28664
|
+
mention
|
|
28665
|
+
});
|
|
28355
28666
|
const back = (map, row) => {
|
|
28356
28667
|
if (row) map.set(groupId, row.timestamp);
|
|
28357
28668
|
else map.delete(groupId);
|
|
@@ -28777,7 +29088,7 @@ var Groups = class {
|
|
|
28777
29088
|
membership: (groupId) => this.fileMembership(groupId),
|
|
28778
29089
|
out: (groupId) => this.fileOut(groupId),
|
|
28779
29090
|
sendApp: (groupId, frame) => this.communities.sendApp(groupId, frame),
|
|
28780
|
-
changed: () => host.emit(),
|
|
29091
|
+
changed: (delayMs) => host.emit(delayMs),
|
|
28781
29092
|
now: () => this.now()
|
|
28782
29093
|
});
|
|
28783
29094
|
this.communities.files = this.files;
|
|
@@ -28814,13 +29125,23 @@ var Groups = class {
|
|
|
28814
29125
|
this.unsaved.clear();
|
|
28815
29126
|
for (const group of due) if (this.record(group.id) === group) await this.store.putGroup(group);
|
|
28816
29127
|
}
|
|
28817
|
-
/**
|
|
28818
|
-
|
|
29128
|
+
/**
|
|
29129
|
+
* `asItIs`: a copy that must stay as it was stored (limited mode, WISP 06), so nothing left over is cleared from it.
|
|
29130
|
+
* `newestOnly`: a run that starts no group (`NodeOptions.offline`) reads each history's newest message alone
|
|
29131
|
+
* (`loadNewest`): read whole, 50,000 rows in a group cost every `status` or `chat history` 0.4 s and 80 MB.
|
|
29132
|
+
*/
|
|
29133
|
+
async load(asItIs = false, newestOnly = false) {
|
|
28819
29134
|
const all = await this.store.getGroups();
|
|
28820
29135
|
await this.rows.load(all);
|
|
28821
|
-
await this.communities.load(all.filter((g) => g.community || g.joining));
|
|
29136
|
+
await this.communities.load(all.filter((g) => g.community || g.joining), newestOnly);
|
|
28822
29137
|
for (const group of all.filter((g) => !g.community && !g.joining)) {
|
|
28823
29138
|
this.stored.set(group.id, group);
|
|
29139
|
+
if (newestOnly) {
|
|
29140
|
+
if (group.state) this.attach(group.state);
|
|
29141
|
+
if (group.invited) this.invited.set(group.id, new Set(Object.keys(group.invited)));
|
|
29142
|
+
await loadNewest(this.marks, this.store, group.id);
|
|
29143
|
+
continue;
|
|
29144
|
+
}
|
|
28824
29145
|
const history = await this.store.getMessages(MESSAGE_LINK(group.id));
|
|
28825
29146
|
const framed = history.filter((m) => m.frame);
|
|
28826
29147
|
this.framesKept.set(group.id, framed.map((m) => ({
|
|
@@ -28858,6 +29179,17 @@ var Groups = class {
|
|
|
28858
29179
|
this.host.emit();
|
|
28859
29180
|
return true;
|
|
28860
29181
|
}
|
|
29182
|
+
/** A pin kept before its message came names the row now, while it is still the group's pin (none taken meanwhile). */
|
|
29183
|
+
async pinRowCame(groupId, pin, messageId) {
|
|
29184
|
+
const group = this.record(groupId);
|
|
29185
|
+
if (!group || group.pin !== pin || pin.messageId) return;
|
|
29186
|
+
group.pin = {
|
|
29187
|
+
...pin,
|
|
29188
|
+
messageId
|
|
29189
|
+
};
|
|
29190
|
+
await this.store.putGroup(group);
|
|
29191
|
+
this.host.emit();
|
|
29192
|
+
}
|
|
28861
29193
|
record(groupId) {
|
|
28862
29194
|
return this.isCommunity(groupId) ? this.communities.record(groupId) : this.stored.get(groupId);
|
|
28863
29195
|
}
|
|
@@ -29206,7 +29538,7 @@ var Groups = class {
|
|
|
29206
29538
|
const others = group.others;
|
|
29207
29539
|
group.others = others.filter((o) => o !== other);
|
|
29208
29540
|
try {
|
|
29209
|
-
await this.forget(groupId);
|
|
29541
|
+
await this.forget(groupId, true, true);
|
|
29210
29542
|
} catch (error) {
|
|
29211
29543
|
group.others = others;
|
|
29212
29544
|
throw error;
|
|
@@ -29723,7 +30055,7 @@ var Groups = class {
|
|
|
29723
30055
|
async unmark(groupId, removed, mentionOnly = false) {
|
|
29724
30056
|
if (this.isCommunity(groupId)) return this.communities.unmark(groupId, removed, mentionOnly);
|
|
29725
30057
|
const group = this.stored.get(groupId);
|
|
29726
|
-
if (await unmark(this.marks, group, groupId,
|
|
30058
|
+
if (await unmark(this.marks, group, groupId, this.store, removed, mentionOnly) && group) await this.store.putGroup(group);
|
|
29727
30059
|
}
|
|
29728
30060
|
/** The connection of an edge opened. One kept to tell a removed member closes a while after, whatever its app says or does not say. */
|
|
29729
30061
|
edgeOpen(groupId, peerKey) {
|
|
@@ -29841,14 +30173,20 @@ var Groups = class {
|
|
|
29841
30173
|
if (this.isCommunity(groupId)) return this.communities.rename(groupId, name);
|
|
29842
30174
|
await this.session(groupId).rename(name);
|
|
29843
30175
|
}
|
|
29844
|
-
/**
|
|
29845
|
-
|
|
30176
|
+
/**
|
|
30177
|
+
* `answer`: false when an invitation goes because its inviter took it back, so no decline is said for it. `wipe`: an
|
|
30178
|
+
* active group goes with its tombstone too (another group takes its id).
|
|
30179
|
+
*/
|
|
30180
|
+
async forget(groupId, answer = true, wipe = false) {
|
|
29846
30181
|
if (this.isCommunity(groupId)) return this.communities.deleteHere(groupId);
|
|
29847
30182
|
const session = this.sessions.get(groupId);
|
|
29848
|
-
if (session?.status === "active")
|
|
29849
|
-
|
|
29850
|
-
|
|
29851
|
-
|
|
30183
|
+
if (session?.status === "active") {
|
|
30184
|
+
try {
|
|
30185
|
+
await this.leave(groupId);
|
|
30186
|
+
} catch (e) {
|
|
30187
|
+
if (session.isAdmin && session.others.length) throw e;
|
|
30188
|
+
}
|
|
30189
|
+
if (this.stored.get(groupId)?.left && !wipe) return;
|
|
29852
30190
|
}
|
|
29853
30191
|
const gone = this.stored.get(groupId), invitation = answer && gone?.invitation && !gone.invitation.entry && !gone.invitation.takenBack ? gone.invitation : void 0;
|
|
29854
30192
|
const owed = invitation && this.sayDecline(groupId, invitation.linkId);
|
|
@@ -30604,7 +30942,8 @@ var Groups = class {
|
|
|
30604
30942
|
case "group-full": {
|
|
30605
30943
|
const invitation = this.stored.get(g)?.invitation, { n, max } = frame;
|
|
30606
30944
|
if (!invitation?.entry || this.stored.get(g).state || invitation.linkId !== linkId || invitation.admin) return;
|
|
30607
|
-
if (!Number.isSafeInteger(n) || !Number.isSafeInteger(max) || max < 1 ||
|
|
30945
|
+
if (!Number.isSafeInteger(n) || !Number.isSafeInteger(max) || max < 1 || max > GROUP_MEMBER_CAP.max) return;
|
|
30946
|
+
if (n < 0 || n > max) return;
|
|
30608
30947
|
this.toldFull.set(g, {
|
|
30609
30948
|
n,
|
|
30610
30949
|
max,
|
|
@@ -32353,6 +32692,11 @@ var said = (m) => m.removed ? {
|
|
|
32353
32692
|
...m.card && { sc: m.card }
|
|
32354
32693
|
};
|
|
32355
32694
|
var resendKey = (groupId, member) => `${groupId}\n${member}`;
|
|
32695
|
+
/**
|
|
32696
|
+
* A row of mine in a private group written under a member key I no longer hold: removed, then invited back, I came in
|
|
32697
|
+
* with a new key, and the group knows my lines from before by the old one. Its session refuses their edits.
|
|
32698
|
+
*/
|
|
32699
|
+
var underOldKey = (message, membership) => !membership.community && !message.id.startsWith(`${membership.me}:`);
|
|
32356
32700
|
var GroupEdits = class {
|
|
32357
32701
|
host;
|
|
32358
32702
|
now;
|
|
@@ -32408,7 +32752,7 @@ var GroupEdits = class {
|
|
|
32408
32752
|
if (typeof messageId !== "string" || typeof raw !== "string") return refuse("No message to edit");
|
|
32409
32753
|
const chat = chatOf(groupId);
|
|
32410
32754
|
const message = await this.find(chat, messageId);
|
|
32411
|
-
if (!message || !canEditInGroup(message)) return refuse("Only your own text messages can be edited");
|
|
32755
|
+
if (!message || !canEditInGroup(message) || underOldKey(message, membership)) return refuse("Only your own text messages can be edited");
|
|
32412
32756
|
const text = raw.trim();
|
|
32413
32757
|
if (!text) return refuse("An edit cannot be empty. Delete the message instead.");
|
|
32414
32758
|
if (isJoinNotice(text)) return refuse("An edit cannot read as a join notice.");
|
|
@@ -32454,10 +32798,11 @@ var GroupEdits = class {
|
|
|
32454
32798
|
error,
|
|
32455
32799
|
refused: true
|
|
32456
32800
|
});
|
|
32457
|
-
|
|
32801
|
+
const membership = this.host.membership(groupId);
|
|
32802
|
+
if (!membership) return refuse(this.notMember(groupId));
|
|
32458
32803
|
const chat = chatOf(groupId);
|
|
32459
32804
|
const message = typeof messageId === "string" ? await this.find(chat, messageId) : void 0;
|
|
32460
|
-
if (!message || message.removed || message.sender !== "me" || !GROUP_MESSAGE_ID.test(message.id)) return refuse("Only your own messages can be deleted for everyone");
|
|
32805
|
+
if (!message || message.removed || message.sender !== "me" || !GROUP_MESSAGE_ID.test(message.id) || underOldKey(message, membership)) return refuse("Only your own messages can be deleted for everyone");
|
|
32461
32806
|
if (!canRemove(message)) return refuse("A payment, a request or a notice cannot be deleted for everyone");
|
|
32462
32807
|
const e = removalNumber(message.edit?.seq);
|
|
32463
32808
|
await this.host.removeMine(chat, message, {
|
|
@@ -32722,7 +33067,7 @@ var GroupEdits = class {
|
|
|
32722
33067
|
const kept = this.keptMine.get(key);
|
|
32723
33068
|
this.keptMine.delete(key);
|
|
32724
33069
|
if (this.stopped || edge === void 0 || !membership || membership.community || !membership.members.has(to)) return;
|
|
32725
|
-
const mine = paced && kept?.edge === edge ? kept.mine : (await (this.host.history ? this.host.history(chat) : this.host.messages(chat))).filter((m) => m.sender === "me" && m.edit && !m.edit.pending && canEditInGroup(m)).sort((a, b) => a.edit.at - b.edit.at || (a.id < b.id ? -1 : 1));
|
|
33070
|
+
const mine = paced && kept?.edge === edge ? kept.mine : (await (this.host.history ? this.host.history(chat) : this.host.messages(chat))).filter((m) => m.sender === "me" && m.edit && !m.edit.pending && canEditInGroup(m) && !underOldKey(m, membership)).sort((a, b) => a.edit.at - b.edit.at || (a.id < b.id ? -1 : 1));
|
|
32726
33071
|
const last = this.heard.get(key);
|
|
32727
33072
|
const after = (m) => !last || m.edit.at > last.at || m.edit.at === last.at && m.id > last.id;
|
|
32728
33073
|
const unheard = last ? mine.filter(after).length : Math.min(mine.length, 256);
|
|
@@ -32970,6 +33315,12 @@ var CommunityPay = class {
|
|
|
32970
33315
|
id: frame.id,
|
|
32971
33316
|
ok: true
|
|
32972
33317
|
});
|
|
33318
|
+
else if (frame.t === "pay-res" && frame.c) await this.host.onPaymentResult(linkId, {
|
|
33319
|
+
id: frame.id,
|
|
33320
|
+
ok: false,
|
|
33321
|
+
error: frame.err,
|
|
33322
|
+
closed: true
|
|
33323
|
+
});
|
|
32973
33324
|
}
|
|
32974
33325
|
learn(groupId, member, raw) {
|
|
32975
33326
|
const methods = methodsOf(raw);
|
|
@@ -33201,6 +33552,13 @@ var GroupLink = class {
|
|
|
33201
33552
|
id: r.id,
|
|
33202
33553
|
ok: true
|
|
33203
33554
|
}).catch(() => {});
|
|
33555
|
+
else if (r.closed) this.host.sendApp(this.groupId, {
|
|
33556
|
+
t: "pay-res",
|
|
33557
|
+
id: r.id,
|
|
33558
|
+
ok: false,
|
|
33559
|
+
err: r.error,
|
|
33560
|
+
c: true
|
|
33561
|
+
}).catch(() => {});
|
|
33204
33562
|
}
|
|
33205
33563
|
};
|
|
33206
33564
|
//#endregion
|
|
@@ -35679,7 +36037,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35679
36037
|
throw Object.assign(engineError("mintUnreachable", { host: new URL(normalized).host }), { cause: error });
|
|
35680
36038
|
}
|
|
35681
36039
|
const info = wallet.getMintInfo();
|
|
35682
|
-
const name = info.name || new URL(normalized).hostname;
|
|
36040
|
+
const name = (typeof info.name === "string" ? stripHidden(info.name).replace(/\s+/g, " ").trim().slice(0, 80) : "") || new URL(normalized).hostname;
|
|
35683
36041
|
this.names.set(normalized, name);
|
|
35684
36042
|
const bounds = (nut) => {
|
|
35685
36043
|
const method = info.isSupported(nut).params.find((m) => m.method === "bolt11" && m.unit === UNIT$1);
|
|
@@ -35692,7 +36050,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35692
36050
|
const active = wallet.keyChain.getKeysets().filter((k) => k.isActive);
|
|
35693
36051
|
this.infos.set(normalized, {
|
|
35694
36052
|
version: info.version || void 0,
|
|
35695
|
-
motd: info.motd
|
|
36053
|
+
motd: typeof info.motd === "string" ? stripHidden(info.motd).trim().slice(0, 200) || void 0 : void 0,
|
|
35696
36054
|
inputFeePpk: active.length > 0 ? Math.min(...active.map((k) => k.fee)) : 0,
|
|
35697
36055
|
receive: bounds(4),
|
|
35698
36056
|
send: bounds(5)
|
|
@@ -37353,6 +37711,23 @@ var PAYMENTS_PER_MINUTE = 10;
|
|
|
37353
37711
|
var PAYMENTS_BUSY = "Too many payments at once: send it again in a minute";
|
|
37354
37712
|
/** Refusal lines one chat gets in an hour; past it the contact is still told, and the chat stays as it is. */
|
|
37355
37713
|
var REFUSAL_LINES_PER_HOUR = 5;
|
|
37714
|
+
/** The longest reason of a contact's kept: no wallet's reason is longer, and the app reads none past it (errorText `readable`). */
|
|
37715
|
+
var CONTACT_REASON_MAX = 120;
|
|
37716
|
+
/** An address in a reason: a link or URI ("https://…", "lightning:…"), a "www.", a host ("evil.example/…", any dot). */
|
|
37717
|
+
var ADDRESS = /[a-z][a-z0-9+.-]*:(?:\/\/|[a-z0-9])|\bwww[..。。]|[\p{L}\p{N}-][..。。]\p{L}{2,}/iu;
|
|
37718
|
+
/** The one reason of a wallet's that names a host: our own ecash's mint, which the contact does not take (wallet.ts). */
|
|
37719
|
+
var MINT_REFUSED = /^Ecash from [a-z0-9-]+(?:\.[a-z0-9-]+)+ is not accepted$/i;
|
|
37720
|
+
/**
|
|
37721
|
+
* A contact's reason for a payment result (`pay-res` `err`), as this app keeps it; undefined for the app's own words.
|
|
37722
|
+
* It is said after the app's words in the payment's state line and its chat line, so it gets a display text's check:
|
|
37723
|
+
* invisible and direction characters out, and nothing that names an address (but a mint's host in `MINT_REFUSED`) or
|
|
37724
|
+
* is longer than a wallet's reason.
|
|
37725
|
+
*/
|
|
37726
|
+
function contactReason(error) {
|
|
37727
|
+
if (!error) return void 0;
|
|
37728
|
+
const reason = stripHidden(error.replace(/\s+/g, " ")).replace(/ {2,}/g, " ").trim();
|
|
37729
|
+
return hasVisible(reason) && reason.length <= CONTACT_REASON_MAX && (MINT_REFUSED.test(reason) || !ADDRESS.test(reason)) ? reason : void 0;
|
|
37730
|
+
}
|
|
37356
37731
|
var INVOICE_CLAIMS_KEY = "invoicePaidClaims";
|
|
37357
37732
|
var sameClaim = (a, b) => a.linkId === b.linkId && a.invoice.toLowerCase() === b.invoice.toLowerCase();
|
|
37358
37733
|
var satsWord = (n) => `${n} sat${n === 1 ? "" : "s"}`;
|
|
@@ -37587,15 +37962,18 @@ var within = (now, at, ms) => at !== void 0 && at <= now && now - at < ms;
|
|
|
37587
37962
|
/** What a contact reads about a request of ours closed for good (`close`), when it closes and each time their chat opens again. */
|
|
37588
37963
|
var CLOSED_TOLD = "your contact removed the wallet it was paid to";
|
|
37589
37964
|
/**
|
|
37590
|
-
* How often a wallet's own refresh asks about an open Ark request (at its server's indexer
|
|
37591
|
-
*
|
|
37592
|
-
*
|
|
37593
|
-
*
|
|
37594
|
-
*
|
|
37965
|
+
* How often a wallet's own refresh asks about an open Ark, Bark or Spark request (at its server's indexer, after a sync
|
|
37966
|
+
* with its server or Spark's operators) or a contact's pending Ark or USDT receipt (at the server or the chain) that
|
|
37967
|
+
* has no answer yet (`AskBackoff`): at the wallet's pace while the request is new (`INVOICE_PACE.fastForMs`) or the
|
|
37968
|
+
* transaction is seen confirming, then twice as late after each ask with nothing, up to `RECEIPT_ASK_CAP_MS`. Asked at
|
|
37969
|
+
* every refresh, 5 open Ark requests cost 30 indexer reads a minute, one open Bark or Spark request a server sync every
|
|
37970
|
+
* 10 s, and a receipt whose transaction never lands 3 RPC calls every 8 s, for as long as the app ran.
|
|
37595
37971
|
* A refresh that read new money asks about every one at once, as do a contact's receipt or check and a wallet's removal,
|
|
37596
37972
|
* so money that lands late, an expired request's included, is still seen.
|
|
37597
37973
|
*/
|
|
37598
37974
|
var ARK_ASK_MS = 1e4;
|
|
37975
|
+
var BARK_ASK_MS = 1e4;
|
|
37976
|
+
var SPARK_ASK_MS = 1e4;
|
|
37599
37977
|
var USDT_ASK_MS = 8e3;
|
|
37600
37978
|
var RECEIPT_ASK_CAP_MS = INVOICE_PACE.missedCapMs;
|
|
37601
37979
|
var PaymentDesk = class {
|
|
@@ -37619,9 +37997,13 @@ var PaymentDesk = class {
|
|
|
37619
37997
|
/** Pending USDT receipts (by payment id) whose transaction the chain does not show settled yet. */
|
|
37620
37998
|
usdtAsk = new AskBackoff(USDT_ASK_MS, RECEIPT_ASK_CAP_MS);
|
|
37621
37999
|
checkingBark = false;
|
|
38000
|
+
/** Open Bark requests (by request id) asked with nothing found yet. */
|
|
38001
|
+
barkAsk = new AskBackoff(BARK_ASK_MS, RECEIPT_ASK_CAP_MS);
|
|
37622
38002
|
checkingBitcoin = false;
|
|
37623
38003
|
redeeming = /* @__PURE__ */ new Map();
|
|
37624
38004
|
checkingSpark = false;
|
|
38005
|
+
/** Open Spark requests (by request id) asked with nothing found yet. */
|
|
38006
|
+
sparkAsk = new AskBackoff(SPARK_ASK_MS, RECEIPT_ASK_CAP_MS);
|
|
37625
38007
|
/** Each network's wallets: a request, a payment and a receipt all go through the wallet of their own network. */
|
|
37626
38008
|
ark;
|
|
37627
38009
|
usdt;
|
|
@@ -38099,6 +38481,11 @@ var PaymentDesk = class {
|
|
|
38099
38481
|
owns(request, linkId) {
|
|
38100
38482
|
return request.linkId === linkId || !!request.group && this.host.groupOf?.(linkId) === request.group;
|
|
38101
38483
|
}
|
|
38484
|
+
/** The request a contact's payment names, kept only when this link may pay it: ecash naming one of our requests from elsewhere is a plain payment. */
|
|
38485
|
+
paysRequest(requestId, linkId) {
|
|
38486
|
+
const request = requestId ? this.payments.get(requestId) : void 0;
|
|
38487
|
+
return request?.kind === "request" && request.direction === "out" && !this.owns(request, linkId) ? void 0 : requestId;
|
|
38488
|
+
}
|
|
38102
38489
|
/**
|
|
38103
38490
|
* Why a token cannot pay a request to the group, checked before anything is redeemed: already paid, another member's
|
|
38104
38491
|
* ecash for it still being redeemed (the mint has not answered), or it would not settle it (too little, a mint the
|
|
@@ -38701,7 +39088,7 @@ var PaymentDesk = class {
|
|
|
38701
39088
|
state: "settled",
|
|
38702
39089
|
createdAt: payment.timestamp,
|
|
38703
39090
|
mint,
|
|
38704
|
-
requestId: payment.requestId
|
|
39091
|
+
requestId: this.paysRequest(payment.requestId, linkId)
|
|
38705
39092
|
});
|
|
38706
39093
|
const { amount, mint } = await this.wallet.receiveToken(token, "ecash-in", payment.memo, {
|
|
38707
39094
|
addTestMint: true,
|
|
@@ -38800,7 +39187,11 @@ var PaymentDesk = class {
|
|
|
38800
39187
|
reason
|
|
38801
39188
|
}), record.createdAt);
|
|
38802
39189
|
}
|
|
38803
|
-
async onPaymentResult(linkId,
|
|
39190
|
+
async onPaymentResult(linkId, said) {
|
|
39191
|
+
const result = {
|
|
39192
|
+
...said,
|
|
39193
|
+
error: contactReason(said.error)
|
|
39194
|
+
};
|
|
38804
39195
|
const payment = this.find(linkId, result.id);
|
|
38805
39196
|
if (payment?.target?.method === "fedimint" && payment.linkId === linkId && payment.direction === "out" && payment.kind === "payment") {
|
|
38806
39197
|
if (payment.state !== "pending") return;
|
|
@@ -39386,7 +39777,7 @@ var PaymentDesk = class {
|
|
|
39386
39777
|
return;
|
|
39387
39778
|
}
|
|
39388
39779
|
const link = this.host.getLink(linkId), request = payment.requestId ? this.payments.get(payment.requestId) : void 0;
|
|
39389
|
-
if (!link?.supportsArkPayments ||
|
|
39780
|
+
if (!link?.supportsArkPayments || request?.target?.method !== "arkade" || request.linkId !== linkId || request.direction !== "out" || request.kind !== "request") return;
|
|
39390
39781
|
const existing = this.payments.get(payment.id);
|
|
39391
39782
|
if (existing && (existing.linkId !== linkId || existing.direction !== "in" || existing.requestId !== request.id)) return;
|
|
39392
39783
|
if (existing) {
|
|
@@ -39589,26 +39980,38 @@ var PaymentDesk = class {
|
|
|
39589
39980
|
/**
|
|
39590
39981
|
* A Bark request is paid when this wallet received, on the address made for it, at least the amount asked,
|
|
39591
39982
|
* after asking. It settles with or without the contact's receipt, and one receive pays one request.
|
|
39983
|
+
* `paced` (a wallet refresh that read nothing new): only the requests whose turn came (`barkAsk`), and no sync at
|
|
39984
|
+
* all when none did; otherwise every one now.
|
|
39592
39985
|
*/
|
|
39593
|
-
async reconcileBarkReceipts() {
|
|
39986
|
+
async reconcileBarkReceipts(paced = false) {
|
|
39594
39987
|
if (this.checkingBark || !this.bark || !distinct(this.bark).some((w) => w.adapter)) return;
|
|
39595
39988
|
this.checkingBark = true;
|
|
39596
39989
|
try {
|
|
39597
|
-
const
|
|
39598
|
-
const
|
|
39990
|
+
const bark = this.bark, now = Date.now();
|
|
39991
|
+
const all = [...this.payments.values()].filter((r) => r.kind === "request" && r.direction === "out" && r.state === "pending" && r.target?.method === "bark");
|
|
39992
|
+
this.barkAsk.keepOnly(new Set(all.map((r) => r.id)));
|
|
39993
|
+
const open = all.filter((r) => {
|
|
39994
|
+
const adapter = bark[walletNetworkOf(r.target.network)].adapter;
|
|
39995
|
+
return !!adapter && r.target.provider === adapter.config.provider && r.target.network === adapter.config.network && (!paced || this.barkAsk.due(r.id, now));
|
|
39996
|
+
});
|
|
39599
39997
|
const receipts = /* @__PURE__ */ new Map();
|
|
39600
39998
|
for (const wallet of new Set(open.map((r) => bark[walletNetworkOf(r.target.network)]))) {
|
|
39601
39999
|
if (!wallet.adapter) continue;
|
|
39602
40000
|
await wallet.adapter.sync().catch(() => {});
|
|
39603
40001
|
receipts.set(wallet.adapter, await wallet.adapter.receipts().catch(() => void 0));
|
|
39604
40002
|
}
|
|
40003
|
+
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "bark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
39605
40004
|
for (const request of open) {
|
|
39606
40005
|
if (request.kind !== "request" || request.direction !== "out" || request.state !== "pending" || request.target?.method !== "bark") continue;
|
|
39607
40006
|
const adapter = this.bark[walletNetworkOf(request.target.network)].adapter;
|
|
39608
40007
|
if (!adapter || request.target.provider !== adapter.config.provider || request.target.network !== adapter.config.network) continue;
|
|
39609
|
-
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "bark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
39610
40008
|
const txid = receipts.get(adapter)?.(request.target.address, request.amount, request.createdAt, claimed);
|
|
39611
|
-
if (!txid)
|
|
40009
|
+
if (!txid) {
|
|
40010
|
+
this.barkAsk.missed(request.id, Date.now(), Date.now() < request.createdAt + INVOICE_PACE.fastForMs);
|
|
40011
|
+
continue;
|
|
40012
|
+
}
|
|
40013
|
+
this.barkAsk.forget(request.id);
|
|
40014
|
+
claimed.add(txid);
|
|
39612
40015
|
await this.settleRequest(request, { txid });
|
|
39613
40016
|
for (const payment of this.payments.values()) if (payment.kind === "payment" && payment.direction === "in" && payment.requestId === request.id && payment.state === "pending") await this.save({
|
|
39614
40017
|
...payment,
|
|
@@ -39936,7 +40339,7 @@ var PaymentDesk = class {
|
|
|
39936
40339
|
memo: payment.memo,
|
|
39937
40340
|
state: "pending",
|
|
39938
40341
|
createdAt: payment.timestamp,
|
|
39939
|
-
requestId: payment.requestId,
|
|
40342
|
+
requestId: this.paysRequest(payment.requestId, linkId),
|
|
39940
40343
|
federation: found.federation,
|
|
39941
40344
|
token: notes,
|
|
39942
40345
|
notesDigest: digest,
|
|
@@ -40140,23 +40543,33 @@ var PaymentDesk = class {
|
|
|
40140
40543
|
/**
|
|
40141
40544
|
* A Spark request is paid when this wallet completed a receive on the invoice made for it, of at least the amount
|
|
40142
40545
|
* asked. It settles with or without the contact's receipt, and one transfer pays one request.
|
|
40546
|
+
* `paced` (a wallet refresh that read nothing new): only the requests whose turn came (`sparkAsk`), and no sync at
|
|
40547
|
+
* all when none did; otherwise every one now.
|
|
40143
40548
|
*/
|
|
40144
|
-
async reconcileSparkReceipts() {
|
|
40549
|
+
async reconcileSparkReceipts(paced = false) {
|
|
40145
40550
|
const spark = this.spark;
|
|
40146
40551
|
if (this.checkingSpark || !spark || !distinct(spark).some((s) => s.ready())) return;
|
|
40147
40552
|
this.checkingSpark = true;
|
|
40148
40553
|
try {
|
|
40149
|
-
const
|
|
40554
|
+
const now = Date.now();
|
|
40555
|
+
const all = [...this.payments.values()].filter((r) => r.kind === "request" && r.direction === "out" && r.state === "pending" && r.target?.method === "spark");
|
|
40556
|
+
this.sparkAsk.keepOnly(new Set(all.map((r) => r.id)));
|
|
40557
|
+
const open = all.filter((r) => spark[walletNetworkOf(r.target.network)].ready() && (!paced || this.sparkAsk.due(r.id, now)));
|
|
40150
40558
|
const networks = new Set(open.map((r) => walletNetworkOf(r.target.network)));
|
|
40151
40559
|
for (const network of networks) if (spark[network].ready()) await spark[network].sync().catch(() => {});
|
|
40560
|
+
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "spark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
40152
40561
|
for (const request of open) {
|
|
40153
40562
|
const current = this.current(request);
|
|
40154
40563
|
if (current.state !== "pending" || !current.target) continue;
|
|
40155
40564
|
const wallet = spark[walletNetworkOf(current.target.network)];
|
|
40156
40565
|
if (!wallet.ready()) continue;
|
|
40157
|
-
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "spark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
40158
40566
|
const id = await wallet.received(current.target, current.amount, current.createdAt, claimed).catch(() => void 0);
|
|
40159
|
-
if (!id)
|
|
40567
|
+
if (!id) {
|
|
40568
|
+
this.sparkAsk.missed(current.id, Date.now(), Date.now() < current.createdAt + INVOICE_PACE.fastForMs);
|
|
40569
|
+
continue;
|
|
40570
|
+
}
|
|
40571
|
+
this.sparkAsk.forget(current.id);
|
|
40572
|
+
claimed.add(id);
|
|
40160
40573
|
await this.settleRequest(current, { txid: id });
|
|
40161
40574
|
for (const payment of this.payments.values()) if (payment.kind === "payment" && payment.direction === "in" && payment.requestId === current.id && payment.state === "pending") await this.save({
|
|
40162
40575
|
...payment,
|
|
@@ -41024,6 +41437,8 @@ var STARTUP_QUIET_MS = 15e3;
|
|
|
41024
41437
|
var START_SLICE_MS = 10;
|
|
41025
41438
|
/** How long the wallets' changes gather into one view of them (`walletChanged`). */
|
|
41026
41439
|
var WALLET_CHANGE_MS = 50;
|
|
41440
|
+
/** How often the shared services' request counts may send a state while contacts use them (`hostedService`). */
|
|
41441
|
+
var REQUEST_COUNTS_MS = 1e3;
|
|
41027
41442
|
var SPARE_INVITE_MAX_AGE_MS = 9e5;
|
|
41028
41443
|
/** How far before this clock a warm packet is dated (`warmKey`): further than a contact's clock is ever behind. */
|
|
41029
41444
|
var WARM_DATED_BACK_MS = 864e5;
|
|
@@ -41184,6 +41599,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41184
41599
|
}
|
|
41185
41600
|
/** The chats found saved at start that this run leaves unstarted (`NodeOptions.deferChats`). */
|
|
41186
41601
|
deferredChats = /* @__PURE__ */ new Set();
|
|
41602
|
+
/** The groups whose edges this run leaves unstarted (`NodeOptions.deferChats`): every saved one, until a command names it. */
|
|
41603
|
+
deferredGroups = /* @__PURE__ */ new Set();
|
|
41187
41604
|
transport;
|
|
41188
41605
|
/** The same, for groups' requests: a relay budget keeps a chat's share from them (`CHAT_RESERVE`). */
|
|
41189
41606
|
groupTransport;
|
|
@@ -41369,6 +41786,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41369
41786
|
/** `group-wake` frames read per edge, a handful a minute. */
|
|
41370
41787
|
groupWakeReceived = /* @__PURE__ */ new Map();
|
|
41371
41788
|
requestCounts = /* @__PURE__ */ new Map();
|
|
41789
|
+
/** One per service and contact that was served: aborted once that contact may no longer reach it (`servicesChanged`). */
|
|
41790
|
+
serviceGrants = /* @__PURE__ */ new Map();
|
|
41791
|
+
/** A request only moves a counter: the counts go out with the next state, at most once a `REQUEST_COUNTS_MS`. */
|
|
41792
|
+
requestCountsTimer;
|
|
41372
41793
|
transfers = /* @__PURE__ */ new Map();
|
|
41373
41794
|
/**
|
|
41374
41795
|
* Views that go in the next state sent, and then away (`GroupFilesHost.brief`): dropped once a state carried them,
|
|
@@ -41405,6 +41826,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41405
41826
|
}
|
|
41406
41827
|
});
|
|
41407
41828
|
stateTimer = null;
|
|
41829
|
+
/** When the snapshot `stateTimer` waits for is due (`emitState`). */
|
|
41830
|
+
stateDue = 0;
|
|
41408
41831
|
paymentTimer = null;
|
|
41409
41832
|
/**
|
|
41410
41833
|
* The reviews whose outcome is still open (submitted, unknown), by id: what the payment poll asks about, so that it
|
|
@@ -41476,7 +41899,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41476
41899
|
}));
|
|
41477
41900
|
barkWallets = perNetwork((network) => new BarkWallet(network, (viewChanged = true) => {
|
|
41478
41901
|
if (viewChanged) this.walletChanged();
|
|
41479
|
-
this.desk.reconcileBarkReceipts().catch(() => {});
|
|
41902
|
+
this.desk.reconcileBarkReceipts(!viewChanged).catch(() => {});
|
|
41480
41903
|
}));
|
|
41481
41904
|
fedimintWallets = perNetwork((network) => new FedimintWallet(network, {
|
|
41482
41905
|
changed: () => this.walletChanged(),
|
|
@@ -41484,7 +41907,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41484
41907
|
}, () => (this.options.fedimintSdk ?? loadFedimintSdk)()));
|
|
41485
41908
|
sparkWallets = perNetwork((network) => new SparkWallet(network, (viewChanged = true) => {
|
|
41486
41909
|
if (viewChanged) this.walletChanged();
|
|
41487
|
-
this.desk.reconcileSparkReceipts().catch(() => {});
|
|
41910
|
+
this.desk.reconcileSparkReceipts(!viewChanged).catch(() => {});
|
|
41488
41911
|
}));
|
|
41489
41912
|
/** What a call naming no network acts on (a caller from before wallets had their own): Mainnet. */
|
|
41490
41913
|
net(network) {
|
|
@@ -41814,6 +42237,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41814
42237
|
if (!live) return "unknown chat";
|
|
41815
42238
|
if (live.files.wireIds.has(wire.wireId)) return "duplicate file id";
|
|
41816
42239
|
if (live.files.receivedBytes + wire.size > LIMITS.maxStoredIncomingBytesPerPeer) return "no room for more files";
|
|
42240
|
+
if (live.files.receivedBytes + this.fileDesk.autoTaken(linkId) + wire.size > FILE_LIMITS.autoAcceptBytesPerPeer) return "no room for more files";
|
|
41817
42241
|
const file = {
|
|
41818
42242
|
id: `${linkId}-in-${toBase64Url(randomBytes(12))}`,
|
|
41819
42243
|
name: wire.name,
|
|
@@ -42283,6 +42707,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42283
42707
|
believed: (chat, by) => {
|
|
42284
42708
|
const membership = this.membership(chat.slice(6));
|
|
42285
42709
|
return !!membership?.members.has(by) && by !== membership.me;
|
|
42710
|
+
},
|
|
42711
|
+
memberKey: (chat) => {
|
|
42712
|
+
const groupId = chat.startsWith("group:") ? chat.slice(6) : void 0;
|
|
42713
|
+
return groupId && !this.groups.isCommunityGroup(groupId) ? this.membership(groupId)?.me : void 0;
|
|
42286
42714
|
}
|
|
42287
42715
|
});
|
|
42288
42716
|
/**
|
|
@@ -42397,7 +42825,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42397
42825
|
placeAbove: (linkId, id) => this.placeAbove(linkId, id),
|
|
42398
42826
|
membersChanged: (groupId) => this.groupMembersChanged(groupId),
|
|
42399
42827
|
historyGone: (groupId) => this.groupHistoryGone(groupId),
|
|
42400
|
-
emit: () => this.emitState(),
|
|
42828
|
+
emit: (delayMs) => this.emitState(delayMs),
|
|
42401
42829
|
communityApp: (groupId, sender, frame) => frame.t === "reaction" ? this.receiveGroupReaction(groupId, sender, frame) : frame.t === "edit" ? this.receiveCommunityEdit(groupId, sender, frame) : frame.t === "pin" ? this.receiveGroupPin(groupId, sender, readPin(frame)) : this.communityPay.receiveApp(groupId, sender, frame),
|
|
42402
42830
|
groupEdit: async (groupId, { sender, ...edit }) => {
|
|
42403
42831
|
await this.groupEdits.receive(groupId, sender, edit);
|
|
@@ -42956,38 +43384,23 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42956
43384
|
const links = await db.getLinks();
|
|
42957
43385
|
if (this.options.deferChats) {
|
|
42958
43386
|
for (const stored of links) if (!stored.group) this.deferredChats.add(stored.id);
|
|
43387
|
+
else if (!stored.groupEntry) this.deferredGroups.add(stored.group);
|
|
42959
43388
|
}
|
|
42960
43389
|
for (const stored of links) if (stored.group) this.links.set(stored.id, newLiveLink(stored, 0, linkFilesFrom(stored.id, [], [])));
|
|
42961
43390
|
for (const group of await db.getGroups()) await this.settleHistory(`group:${group.id}`);
|
|
42962
|
-
await this.groups.load(this.limitedMode);
|
|
43391
|
+
await this.groups.load(this.limitedMode, !!this.options.offline);
|
|
42963
43392
|
this.groupsLoaded = true;
|
|
42964
43393
|
this.groupsLoadedNow();
|
|
42965
43394
|
this.emitState();
|
|
42966
|
-
for (
|
|
43395
|
+
for (const stored of links) {
|
|
42967
43396
|
if (stored.group) continue;
|
|
42968
43397
|
await this.settleHistory(stored.id);
|
|
42969
|
-
|
|
42970
|
-
|
|
42971
|
-
|
|
42972
|
-
|
|
42973
|
-
|
|
42974
|
-
|
|
42975
|
-
state: "failed",
|
|
42976
|
-
error: "Transfer interrupted. Retry when connected."
|
|
42977
|
-
} : file.transfer);
|
|
42978
|
-
const unreceipted = new Set(messages.flatMap((m) => m.sender === "me" && m.file && m.delivery !== "delivered" ? [m.file.id] : []));
|
|
42979
|
-
this.fileDesk.restore(stored.id, storedFiles, unreceipted);
|
|
42980
|
-
const files = linkFilesFrom(stored.id, storedFiles, messages);
|
|
42981
|
-
this.links.set(stored.id, newLiveLink(stored, messages[messages.length - 1]?.timestamp ?? 0, files));
|
|
42982
|
-
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
42983
|
-
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
42984
|
-
this.editsFor(stored.id).learn([...messages, ...(stored.removals ?? []).map((r) => removalRow(stored.id, r))]);
|
|
42985
|
-
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
42986
|
-
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
42987
|
-
const note = this.noteFromHistory(stored.id, messages);
|
|
42988
|
-
if (note) this.reactionNotes.set(stored.id, note);
|
|
42989
|
-
if (stored.reactionsWaiting?.length) await this.reactions.restore(stored.id, stored.reactionsWaiting, messages);
|
|
42990
|
-
if (stored.profile) await this.outboxFor(stored.id).recover(messages);
|
|
43398
|
+
if (this.deferredChats.has(stored.id)) {
|
|
43399
|
+
this.links.set(stored.id, newLiveLink(stored, (await db.getMessagePage(stored.id, { limit: 1 })).messages[0]?.timestamp ?? 0));
|
|
43400
|
+
this.chatRestores.set(stored.id, null);
|
|
43401
|
+
continue;
|
|
43402
|
+
}
|
|
43403
|
+
await this.restoreChat(stored);
|
|
42991
43404
|
}
|
|
42992
43405
|
this.transfersRestored = true;
|
|
42993
43406
|
this.awaitingSoon();
|
|
@@ -43010,6 +43423,56 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43010
43423
|
else if (!this.options.singleDevice && this.limitedMode && knownDeviceGate()?.state === "active") this.readTurnWhileLimited();
|
|
43011
43424
|
if (this.restoreCheck === "checking" && this.limitedMode) this.checkRestoredTurn(0);
|
|
43012
43425
|
}
|
|
43426
|
+
/**
|
|
43427
|
+
* The chats left unstarted at start (`deferChats`) whose history is not read yet: `null` until the command names one
|
|
43428
|
+
* (`restoreDeferred`), then that read.
|
|
43429
|
+
*/
|
|
43430
|
+
chatRestores = /* @__PURE__ */ new Map();
|
|
43431
|
+
/** A deferred chat's restore (`restoreChat`), read once, before it starts or a command reads it. */
|
|
43432
|
+
restoreDeferred(linkId) {
|
|
43433
|
+
const restore = this.chatRestores.get(linkId);
|
|
43434
|
+
if (restore !== null) return restore ?? Promise.resolve();
|
|
43435
|
+
const live = this.links.get(linkId);
|
|
43436
|
+
const restoring = live ? this.restoreChat(live.stored) : Promise.resolve();
|
|
43437
|
+
this.chatRestores.set(linkId, restoring);
|
|
43438
|
+
return restoring;
|
|
43439
|
+
}
|
|
43440
|
+
/**
|
|
43441
|
+
* What a saved 1:1 chat knows from its history, read whole once: its newest message, its files and their transfers, what
|
|
43442
|
+
* waits for it to be live, my edits on their way, when the contact was last heard, its latest reaction, and the
|
|
43443
|
+
* outbox's rows.
|
|
43444
|
+
*/
|
|
43445
|
+
async restoreChat(stored) {
|
|
43446
|
+
const messages = await db.getMessages(stored.id);
|
|
43447
|
+
stored = await this.settleJoinLine(stored, messages);
|
|
43448
|
+
const storedFiles = await fileStore.listForLink(stored.id);
|
|
43449
|
+
const notInterrupted = new Set(messages.flatMap((m) => m.sender === "me" && m.file && (m.delivery === "waiting" || m.via === "hold" && (m.delivery === "held" || m.delivery === "delivered")) ? [m.file.id] : []));
|
|
43450
|
+
for (const file of storedFiles) if (file.transfer && file.transfer.state !== "done" && !file.wire3 && !notInterrupted.has(file.id)) this.transfers.set(file.id, file.transfer.state === "transferring" ? {
|
|
43451
|
+
...file.transfer,
|
|
43452
|
+
state: "failed",
|
|
43453
|
+
error: "Transfer interrupted. Retry when connected."
|
|
43454
|
+
} : file.transfer);
|
|
43455
|
+
const unreceipted = new Set(messages.flatMap((m) => m.sender === "me" && m.file && m.delivery !== "delivered" ? [m.file.id] : []));
|
|
43456
|
+
this.fileDesk.restore(stored.id, storedFiles, unreceipted);
|
|
43457
|
+
const files = linkFilesFrom(stored.id, storedFiles, messages);
|
|
43458
|
+
const newest = messages[messages.length - 1]?.timestamp ?? 0;
|
|
43459
|
+
const left = this.links.get(stored.id);
|
|
43460
|
+
if (left) Object.assign(left, {
|
|
43461
|
+
stored,
|
|
43462
|
+
lastMessageAt: Math.max(left.lastMessageAt, newest),
|
|
43463
|
+
files
|
|
43464
|
+
});
|
|
43465
|
+
else this.links.set(stored.id, newLiveLink(stored, newest, files));
|
|
43466
|
+
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
43467
|
+
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
43468
|
+
this.editsFor(stored.id).learn([...messages, ...(stored.removals ?? []).map((r) => removalRow(stored.id, r))]);
|
|
43469
|
+
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
43470
|
+
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
43471
|
+
const note = this.noteFromHistory(stored.id, messages);
|
|
43472
|
+
if (note) this.reactionNotes.set(stored.id, note);
|
|
43473
|
+
if (stored.reactionsWaiting?.length) await this.reactions.restore(stored.id, stored.reactionsWaiting, messages);
|
|
43474
|
+
if (stored.profile) await this.outboxFor(stored.id).recover(messages);
|
|
43475
|
+
}
|
|
43013
43476
|
/** Where the check of a restored copy stands: reading every 30 seconds, or a tombstone found (the person decides). */
|
|
43014
43477
|
restoreCheck = null;
|
|
43015
43478
|
restoreTimer = null;
|
|
@@ -43444,6 +43907,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43444
43907
|
if (this.paymentTimer) clearTimeout(this.paymentTimer);
|
|
43445
43908
|
clearTimeout(this.awaitingTimer);
|
|
43446
43909
|
clearTimeout(this.walletChangeTimer);
|
|
43910
|
+
clearTimeout(this.requestCountsTimer);
|
|
43447
43911
|
clearInterval(this.staleReviewTimer);
|
|
43448
43912
|
if (this.spareTimer) clearTimeout(this.spareTimer);
|
|
43449
43913
|
for (const timer of this.reactionTimers.values()) clearTimeout(timer);
|
|
@@ -43562,8 +44026,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43562
44026
|
appInstall(params) {
|
|
43563
44027
|
return this.appStore.install(params);
|
|
43564
44028
|
}
|
|
43565
|
-
|
|
43566
|
-
|
|
44029
|
+
/** Installs a waiting update; the pages are told, so another tab's screen drops its Update. */
|
|
44030
|
+
async appUpdateAccept(params) {
|
|
44031
|
+
const view = await this.appStore.acceptUpdate(params);
|
|
44032
|
+
this.events.onAppsChecked?.();
|
|
44033
|
+
return view;
|
|
43567
44034
|
}
|
|
43568
44035
|
appCheckUpdates() {
|
|
43569
44036
|
return this.appStore.checkUpdates();
|
|
@@ -43607,7 +44074,35 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43607
44074
|
appDataExportText(params) {
|
|
43608
44075
|
return this.appStore.exportDataText(params);
|
|
43609
44076
|
}
|
|
44077
|
+
/** The settings `getState` gives, without the view of every chat it builds (a host reading one setting). */
|
|
44078
|
+
getSettings() {
|
|
44079
|
+
return this.settings;
|
|
44080
|
+
}
|
|
44081
|
+
/** One chat's view as `getState().links` has it (none for a group's edge), without building every chat's. */
|
|
44082
|
+
chatView(linkId) {
|
|
44083
|
+
const live = this.links.get(linkId);
|
|
44084
|
+
return live && !live.stored.group ? this.viewOf(live) : void 0;
|
|
44085
|
+
}
|
|
44086
|
+
/** Every chat's view built again: what a caller reads may follow a change no state was asked for. */
|
|
43610
44087
|
getState() {
|
|
44088
|
+
this.changedChats = null;
|
|
44089
|
+
return this.pushedState();
|
|
44090
|
+
}
|
|
44091
|
+
/**
|
|
44092
|
+
* Each chat's view as the last state had it, by its live link (a chat made again is built again), and the chats
|
|
44093
|
+
* changed since (`chatChanged`; null: unknown which, all). A state then costs the chats that changed, not every chat.
|
|
44094
|
+
*/
|
|
44095
|
+
chatViews = /* @__PURE__ */ new WeakMap();
|
|
44096
|
+
changedChats = null;
|
|
44097
|
+
/** The state `emitState` sends: the views of the chats no change named since the last are the same objects. */
|
|
44098
|
+
pushedState() {
|
|
44099
|
+
const changed = this.changedChats;
|
|
44100
|
+
this.changedChats = /* @__PURE__ */ new Set();
|
|
44101
|
+
const viewOf = (live) => {
|
|
44102
|
+
let view = changed && !changed.has(live.stored.id) ? this.chatViews.get(live) : void 0;
|
|
44103
|
+
if (!view) this.chatViews.set(live, view = this.viewOf(live));
|
|
44104
|
+
return view;
|
|
44105
|
+
};
|
|
43611
44106
|
const groups = this.groups.views();
|
|
43612
44107
|
const edges = this.edgesByMember();
|
|
43613
44108
|
return {
|
|
@@ -43630,7 +44125,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43630
44125
|
...this.clock.offset !== null && { clockOffMs: this.clock.offset },
|
|
43631
44126
|
...!this.contactRtc() && !Object.keys(this.nativeFactories).length && { groupLinks: false }
|
|
43632
44127
|
},
|
|
43633
|
-
links: [...this.links.values()].filter((live) => !live.stored.group).map(
|
|
44128
|
+
links: [...this.links.values()].filter((live) => !live.stored.group).map(viewOf).sort((a, b) => b.createdAt - a.createdAt),
|
|
43634
44129
|
services: this.services.map((s) => ({
|
|
43635
44130
|
...s,
|
|
43636
44131
|
requests: this.requestCounts.get(s.id) ?? 0
|
|
@@ -43646,7 +44141,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43646
44141
|
contactRequests: this.contactLinks.requests(),
|
|
43647
44142
|
contactAsks: this.contactAsks.views(),
|
|
43648
44143
|
nostr: this.nostrSocial.state(),
|
|
43649
|
-
edges: [...[...this.links.values()].filter((live) => live.stored.group && !live.stored.groupEntry).map(
|
|
44144
|
+
edges: [...[...this.links.values()].filter((live) => live.stored.group && !live.stored.groupEntry).map(viewOf), ...this.communityPayViews(groups)],
|
|
43650
44145
|
groups: groups.map((group) => ({
|
|
43651
44146
|
...group,
|
|
43652
44147
|
...this.groupAdminOff.has(group.id) && { adminOff: true },
|
|
@@ -43896,7 +44391,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43896
44391
|
const existing = [...this.links.values()].find((l) => l.stored.seedB64 === params.seedB64);
|
|
43897
44392
|
if (existing) {
|
|
43898
44393
|
if (existing.stored.profile !== params.profile) throw new Error("Invitation profile does not match the stored link");
|
|
43899
|
-
|
|
44394
|
+
await this.startDeferredChat(existing.stored.id);
|
|
43900
44395
|
return { linkId: await this.existingLink(existing.stored.id) };
|
|
43901
44396
|
}
|
|
43902
44397
|
this.refuseOwnInvite(params);
|
|
@@ -44416,10 +44911,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44416
44911
|
* what says it. Apart from the message wake-ups' limit, so it never holds one back. A muted chat's contact shared no
|
|
44417
44912
|
* target; a group's edge is never told. `WAKE_ONLINE_BATCH` at a time, the rest a `WAKE_ONLINE_BATCH_MS` later (those
|
|
44418
44913
|
* still away then), so a push relay's minute keeps room for the message and call wake-ups. None while this profile does
|
|
44419
|
-
* not share when it is online (`sharePresence`).
|
|
44914
|
+
* not share when it is online (`sharePresence`), nor while the host says this run is not online to them (`onlineNotices`).
|
|
44420
44915
|
*/
|
|
44421
44916
|
sayOnline(now = Date.now()) {
|
|
44422
|
-
if (!this.networkOn || this.shuttingDown || this.settings.sharePresence === false) return;
|
|
44917
|
+
if (!this.networkOn || this.shuttingDown || this.settings.sharePresence === false || this.options.onlineNotices?.() === false) return;
|
|
44423
44918
|
let sent = 0;
|
|
44424
44919
|
for (const live of this.links.values()) {
|
|
44425
44920
|
const { id, peerWake: target, profile, group, onlineWokeAt } = live.stored;
|
|
@@ -44694,7 +45189,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44694
45189
|
label: clean
|
|
44695
45190
|
};
|
|
44696
45191
|
db.patchLink(linkId, { label: live.stored.label });
|
|
44697
|
-
this.
|
|
45192
|
+
this.chatChanged(linkId);
|
|
44698
45193
|
}
|
|
44699
45194
|
/** `linkId`: a chat's, or `group:<id>` for a group on screen, whose edges then take native listeners as a chat on screen does. */
|
|
44700
45195
|
setActiveLink({ linkId }) {
|
|
@@ -45896,6 +46391,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45896
46391
|
removalPending({ linkId, messageId }) {
|
|
45897
46392
|
return !!this.links.get(linkId)?.stored.removals?.some((r) => r.id === messageId);
|
|
45898
46393
|
}
|
|
46394
|
+
/** The messages of a 1:1 chat whose removal of mine is still on its way to the contact, by id (`removeMessage`). */
|
|
46395
|
+
removalsPending({ linkId }) {
|
|
46396
|
+
return (this.links.get(linkId)?.stored.removals ?? []).map((r) => r.id);
|
|
46397
|
+
}
|
|
45899
46398
|
/** A chat's row write of its removals and deleted ids waiting to go, by chat (`writeDeletions`). */
|
|
45900
46399
|
deletionWrites = /* @__PURE__ */ new Map();
|
|
45901
46400
|
/** The last such write of each chat, which the next one follows. */
|
|
@@ -45988,7 +46487,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45988
46487
|
};
|
|
45989
46488
|
await db.patchLink(linkId, { peerSpoke: true }).catch(() => {});
|
|
45990
46489
|
}
|
|
45991
|
-
if (message?.paymentId && message.delivery
|
|
46490
|
+
if (message?.paymentId && message.delivery && message.delivery !== "sent" && message.delivery !== "delivered") await this.desk.withdraw(message.paymentId).catch(() => {});
|
|
45992
46491
|
if (message?.paymentId && message.sender === "peer") await this.desk.dropReceipt(message.paymentId).catch(() => {});
|
|
45993
46492
|
if (message?.sender === "me" && message.file && message.delivery === "waiting" && (message.fileOnFloor === "sent" || message.fileOnFloor === "seen")) await this.withdrawFloorFile(live, message.file.id.slice(`${linkId}-out-`.length));
|
|
45994
46493
|
if (message?.file) {
|
|
@@ -46082,6 +46581,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46082
46581
|
if (this.transfers.get(file.id)?.state === "transferring") return;
|
|
46083
46582
|
const wireId = file.id.slice(`${linkId}-out-`.length);
|
|
46084
46583
|
if (file.id !== GhostlyNode.outgoingFileId(linkId, wireId)) return refuse("Invalid file id");
|
|
46584
|
+
this.setTyping({
|
|
46585
|
+
linkId,
|
|
46586
|
+
typing: false
|
|
46587
|
+
});
|
|
46085
46588
|
const holdable = file.size <= HOLD_LIMITS.maxBundleBytes - 4096;
|
|
46086
46589
|
if (!live.link.isDataLinkOpen) this.wakePeer(live);
|
|
46087
46590
|
if (!GhostlyNode.takesFiles(live.link) && this.holdingFor(live) && holdable) {
|
|
@@ -47731,10 +48234,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47731
48234
|
await db.patchLink(linkId, { pinOut: void 0 });
|
|
47732
48235
|
}
|
|
47733
48236
|
/**
|
|
47734
|
-
* A
|
|
47735
|
-
* what waited) names its row once the row is here. Only the rows that changed are read, and only
|
|
48237
|
+
* A pin that came before its message (pinned while I was away: a 1:1 chat's goes as the session opens, a group's as an
|
|
48238
|
+
* edge opens, ahead of what waited) names its row once the row is here. Only the rows that changed are read, and only
|
|
48239
|
+
* while such a pin stands.
|
|
47736
48240
|
*/
|
|
47737
48241
|
async pinnedRowCame(linkId, ids) {
|
|
48242
|
+
if (linkId.startsWith("group:")) {
|
|
48243
|
+
const groupId = linkId.slice(6), pin = this.groups.pinOf(groupId);
|
|
48244
|
+
if (!pin?.id || pin.messageId || pin.removed || !ids.includes(pin.id)) return;
|
|
48245
|
+
const row = await db.getMessage(linkId, pin.id);
|
|
48246
|
+
if (row && replyRef(row, true) === pin.id) await this.groups.pinRowCame(groupId, pin, row.id);
|
|
48247
|
+
return;
|
|
48248
|
+
}
|
|
47738
48249
|
const live = this.links.get(linkId), pin = live?.stored.pin;
|
|
47739
48250
|
if (!live || live.stored.group || !pin?.id || pin.messageId || pin.removed) return;
|
|
47740
48251
|
for (const id of new Set(ids)) {
|
|
@@ -47948,7 +48459,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47948
48459
|
this.peerStatusTimers.set(linkId, setTimeout(() => {
|
|
47949
48460
|
this.peerStatusTimers.delete(linkId);
|
|
47950
48461
|
if (until > Date.now()) this.redrawAtStatusEnd(linkId, until);
|
|
47951
|
-
else this.
|
|
48462
|
+
else this.chatChanged(linkId);
|
|
47952
48463
|
}, Math.min(until - Date.now() + 1, GhostlyNode.TIMER_MAX_MS)));
|
|
47953
48464
|
}
|
|
47954
48465
|
/**
|
|
@@ -48838,10 +49349,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48838
49349
|
async sendPayment(params) {
|
|
48839
49350
|
const live = await this.linkWhenAdded(params.linkId);
|
|
48840
49351
|
if (live && this.holdingFor(live)) throw new Error("Ecash is not held for an away contact. Send a request instead, or wait until they are back.");
|
|
48841
|
-
|
|
49352
|
+
const sent = await this.desk.send({
|
|
48842
49353
|
...params,
|
|
48843
49354
|
network: this.net(params.network)
|
|
48844
49355
|
});
|
|
49356
|
+
this.setTyping({
|
|
49357
|
+
linkId: params.linkId,
|
|
49358
|
+
typing: false
|
|
49359
|
+
});
|
|
49360
|
+
return sent;
|
|
48845
49361
|
}
|
|
48846
49362
|
/** `network`: the card's network; the request is paid only by a wallet of that network. */
|
|
48847
49363
|
/** `card`: the Lightning card the request's invoice comes from; absent, the network's default for receiving. */
|
|
@@ -50070,10 +50586,21 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50070
50586
|
try {
|
|
50071
50587
|
const target = parseLocalTarget(service.target);
|
|
50072
50588
|
this.requestCounts.set(id, (this.requestCounts.get(id) ?? 0) + 1);
|
|
50073
|
-
this.
|
|
50589
|
+
this.requestCountsTimer ??= setTimeout(() => {
|
|
50590
|
+
this.requestCountsTimer = void 0;
|
|
50591
|
+
this.emitState();
|
|
50592
|
+
}, REQUEST_COUNTS_MS);
|
|
50593
|
+
const key = `${id} ${peerPubKeyZ32}`;
|
|
50594
|
+
let grant = this.serviceGrants.get(key);
|
|
50595
|
+
if (!grant) this.serviceGrants.set(key, grant = {
|
|
50596
|
+
serviceId: id,
|
|
50597
|
+
peerPubKeyZ32,
|
|
50598
|
+
revoke: new AbortController()
|
|
50599
|
+
});
|
|
50074
50600
|
return {
|
|
50075
50601
|
id,
|
|
50076
|
-
target
|
|
50602
|
+
target,
|
|
50603
|
+
revoked: grant.revoke.signal
|
|
50077
50604
|
};
|
|
50078
50605
|
} catch {
|
|
50079
50606
|
return;
|
|
@@ -50214,7 +50741,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50214
50741
|
}
|
|
50215
50742
|
startEdge(linkId) {
|
|
50216
50743
|
const live = this.links.get(linkId);
|
|
50217
|
-
if (!live || live.link || this.options.deferGroups) return;
|
|
50744
|
+
if (!live || live.link || this.options.deferGroups || !live.stored.groupEntry && this.deferredGroups.has(live.stored.group)) return;
|
|
50218
50745
|
const { stored } = live;
|
|
50219
50746
|
const group = stored.group, peer = stored.groupPeer, entry = !!stored.groupEntry;
|
|
50220
50747
|
const role = stored.groupEntry ?? "edge";
|
|
@@ -50542,12 +51069,25 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50542
51069
|
}
|
|
50543
51070
|
/**
|
|
50544
51071
|
* Starts a chat this run left unstarted (`NodeOptions.deferChats`): the one a one-shot names, once the command has
|
|
50545
|
-
* found it.
|
|
51072
|
+
* found it. Its history is read first (`restoreDeferred`), offline too: the command reads what it knows. Any other
|
|
51073
|
+
* chat, or one already started, is left as it is.
|
|
50546
51074
|
*/
|
|
50547
|
-
startDeferredChat(linkId) {
|
|
51075
|
+
async startDeferredChat(linkId) {
|
|
51076
|
+
if (!this.deferredChats.has(linkId)) return;
|
|
51077
|
+
await this.restoreDeferred(linkId);
|
|
50548
51078
|
if (!this.deferredChats.delete(linkId)) return;
|
|
50549
51079
|
if (this.networkOn && !this.shuttingDown) this.startLink(linkId);
|
|
50550
51080
|
}
|
|
51081
|
+
/**
|
|
51082
|
+
* Starts the edges of a group this run left unstarted (`NodeOptions.deferChats`): the one a one-shot names. Each
|
|
51083
|
+
* group's edges put their records and read their members' on the relays: started, six groups shared with one member
|
|
51084
|
+
* asked the relays about three times what the named group alone does, and a `group react` behind them waited out its
|
|
51085
|
+
* 60 s with no edge up. Any other group, or one already started, is left as it is.
|
|
51086
|
+
*/
|
|
51087
|
+
startDeferredGroup(groupId) {
|
|
51088
|
+
if (!this.deferredGroups.delete(groupId) || !this.networkOn || this.shuttingDown) return;
|
|
51089
|
+
for (const [linkId, live] of this.links) if (live.stored.group === groupId) this.startEdge(linkId);
|
|
51090
|
+
}
|
|
50551
51091
|
startLink(linkId) {
|
|
50552
51092
|
const live = this.links.get(linkId);
|
|
50553
51093
|
if (!live || live.link || this.deferredChats.has(linkId)) return;
|
|
@@ -50787,7 +51327,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50787
51327
|
const was = live.status, synced = live.lastSyncAt;
|
|
50788
51328
|
live.status = status;
|
|
50789
51329
|
if (status === "online") live.lastSyncAt = Date.now();
|
|
50790
|
-
if (status !== was || !synced && status === "online" || stored.group || linkId === this.activeLinkId) this.
|
|
51330
|
+
if (status !== was || !synced && status === "online" || stored.group || linkId === this.activeLinkId) this.chatChanged(linkId);
|
|
50791
51331
|
},
|
|
50792
51332
|
onPoll: ({ polling, nextInMs }) => {
|
|
50793
51333
|
const was = live.poll.polling, first = !live.lastSyncAt && !live.firstReadDone;
|
|
@@ -50797,7 +51337,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50797
51337
|
interval: nextInMs || live.poll.interval
|
|
50798
51338
|
};
|
|
50799
51339
|
if (was && !polling) live.firstReadDone = true;
|
|
50800
|
-
if (linkId === this.activeLinkId || first && polling !== was) this.
|
|
51340
|
+
if (linkId === this.activeLinkId || first && polling !== was) this.chatChanged(linkId);
|
|
50801
51341
|
},
|
|
50802
51342
|
onMessageReceipt: async (id) => {
|
|
50803
51343
|
const oneToOne = !!stored.profile && !stored.group;
|
|
@@ -50822,13 +51362,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50822
51362
|
peerWake: target ?? void 0
|
|
50823
51363
|
};
|
|
50824
51364
|
db.patchLink(linkId, { peerWake: target ?? void 0 });
|
|
50825
|
-
this.
|
|
51365
|
+
this.chatChanged(linkId);
|
|
50826
51366
|
},
|
|
50827
51367
|
onPeerAck: (ack) => {
|
|
50828
51368
|
if (stored.profile) return;
|
|
50829
|
-
if (ack
|
|
51369
|
+
if (ack <= live.peerAck) return;
|
|
50830
51370
|
live.peerAck = ack;
|
|
50831
|
-
this.
|
|
51371
|
+
this.chatChanged(linkId);
|
|
50832
51372
|
},
|
|
50833
51373
|
onDirectEvidence: (evidence) => this.directPath.note(stored.peerPubKeyZ32, evidence),
|
|
50834
51374
|
onPeerClock: (packetAt, readBefore, readAt) => {
|
|
@@ -50867,7 +51407,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50867
51407
|
peerAvatar: avatar ?? void 0
|
|
50868
51408
|
};
|
|
50869
51409
|
db.patchLink(linkId, { peerAvatar: avatar ?? void 0 });
|
|
50870
|
-
this.
|
|
51410
|
+
this.chatChanged(linkId);
|
|
50871
51411
|
},
|
|
50872
51412
|
onPeerNick: (nick) => {
|
|
50873
51413
|
if ((nick ?? "") === live.stored.peerNick) return;
|
|
@@ -50876,7 +51416,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50876
51416
|
peerNick: nick ?? ""
|
|
50877
51417
|
};
|
|
50878
51418
|
db.patchLink(linkId, { peerNick: nick ?? "" });
|
|
50879
|
-
this.
|
|
51419
|
+
this.chatChanged(linkId);
|
|
50880
51420
|
},
|
|
50881
51421
|
onPresence: (presence) => {
|
|
50882
51422
|
let same = samePresence(live.presence, presence);
|
|
@@ -50893,7 +51433,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50893
51433
|
db.patchLink(linkId, { peerNick: presence.nick });
|
|
50894
51434
|
same = false;
|
|
50895
51435
|
}
|
|
50896
|
-
if (!same) this.
|
|
51436
|
+
if (!same) this.chatChanged(linkId);
|
|
50897
51437
|
},
|
|
50898
51438
|
onMessage: (message) => {
|
|
50899
51439
|
if (live.stored.inviteCode) {
|
|
@@ -50920,9 +51460,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50920
51460
|
});
|
|
50921
51461
|
},
|
|
50922
51462
|
onCallSignal: (signal) => this.events.onCallSignal(linkId, signal),
|
|
50923
|
-
onPeerTyping: () => this.
|
|
51463
|
+
onPeerTyping: () => this.chatChanged(linkId),
|
|
50924
51464
|
onPeerStatus: (state) => {
|
|
50925
|
-
this.
|
|
51465
|
+
this.chatChanged(linkId);
|
|
50926
51466
|
this.redrawAtStatusEnd(linkId, state.status?.until);
|
|
50927
51467
|
},
|
|
50928
51468
|
onReaction: async (reaction) => await this.reactions.receive(linkId, "peer", reaction) !== "dropped",
|
|
@@ -51125,7 +51665,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51125
51665
|
nativeFactoriesFor(relayOnly) {
|
|
51126
51666
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
51127
51667
|
return {
|
|
51128
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
51668
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-Dz7pvcBA.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
51129
51669
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
51130
51670
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
51131
51671
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, {
|
|
@@ -51247,6 +51787,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51247
51787
|
for (const [linkId, live] of this.links) {
|
|
51248
51788
|
const link = live.link;
|
|
51249
51789
|
if (!link?.availableTransports.includes("hyperdht/1")) {
|
|
51790
|
+
if (live.transportErrors) delete live.transportErrors["hyperdht/1"];
|
|
51250
51791
|
if (this.hyperdhtRelay && link && this.keepsNativeEndpoints(linkId, live.stored)) this.ensureNativeEndpoints(linkId);
|
|
51251
51792
|
continue;
|
|
51252
51793
|
}
|
|
@@ -51594,16 +52135,19 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51594
52135
|
};
|
|
51595
52136
|
}
|
|
51596
52137
|
if (this.shuttingDown || live.link !== link) return false;
|
|
51597
|
-
const
|
|
51598
|
-
const
|
|
51599
|
-
|
|
51600
|
-
|
|
51601
|
-
|
|
51602
|
-
|
|
51603
|
-
|
|
51604
|
-
|
|
51605
|
-
|
|
51606
|
-
|
|
52138
|
+
const stored = live.stored.transportSeeds?.[key];
|
|
52139
|
+
const seed = stored ?? createIdentity().seedB64;
|
|
52140
|
+
if (!stored) {
|
|
52141
|
+
const transportSeeds = {
|
|
52142
|
+
...live.stored.transportSeeds,
|
|
52143
|
+
[key]: seed
|
|
52144
|
+
};
|
|
52145
|
+
live.stored = {
|
|
52146
|
+
...live.stored,
|
|
52147
|
+
transportSeeds
|
|
52148
|
+
};
|
|
52149
|
+
await db.patchLink(linkId, { transportSeeds });
|
|
52150
|
+
}
|
|
51607
52151
|
const starting = factory(seed);
|
|
51608
52152
|
const endpoint = await Promise.race([starting, this.stopping]);
|
|
51609
52153
|
if (!endpoint) {
|
|
@@ -52007,10 +52551,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52007
52551
|
const live = this.links.get(message.linkId);
|
|
52008
52552
|
const deletes = this.removedChats.get(message.linkId);
|
|
52009
52553
|
if (!live && deletes !== void 0) return false;
|
|
52010
|
-
const chat = message.linkId;
|
|
52011
|
-
const
|
|
52012
|
-
|
|
52013
|
-
if (
|
|
52554
|
+
const chat = message.linkId, id = message.id;
|
|
52555
|
+
const group = chat.startsWith("group:") ? chat.slice(6) : void 0;
|
|
52556
|
+
const kept = () => this.removedChats.get(chat) === deletes && !live?.stored.deletedIds?.includes(id) && !(group && this.groups.isRemoved(group, id));
|
|
52557
|
+
if (!kept()) return false;
|
|
52014
52558
|
const first = live ? this.firstContactRow(live, message) : false;
|
|
52015
52559
|
const mine = live?.stored.profile && !live.stored.group && message.sender === "peer" && !message.file && message.id.startsWith("peer_") ? this.namesMine(chat, message.id.slice(5)).catch(() => false) : false;
|
|
52016
52560
|
message = await this.resolveReply(message);
|
|
@@ -52081,6 +52625,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52081
52625
|
return false;
|
|
52082
52626
|
}
|
|
52083
52627
|
servicesChanged() {
|
|
52628
|
+
for (const [key, grant] of this.serviceGrants) {
|
|
52629
|
+
const service = this.services.find((s) => s.id === grant.serviceId);
|
|
52630
|
+
if (service && mayReach(service, grant.peerPubKeyZ32)) continue;
|
|
52631
|
+
this.serviceGrants.delete(key);
|
|
52632
|
+
grant.revoke.abort();
|
|
52633
|
+
}
|
|
52084
52634
|
for (const live of this.links.values()) live.link?.refreshServices();
|
|
52085
52635
|
this.emitState();
|
|
52086
52636
|
}
|
|
@@ -52190,14 +52740,31 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52190
52740
|
services: false
|
|
52191
52741
|
};
|
|
52192
52742
|
}
|
|
52193
|
-
/**
|
|
52743
|
+
/**
|
|
52744
|
+
* State changes arrive in bursts; the UI gets one snapshot per tick. `delayMs`: how long this change may wait. One
|
|
52745
|
+
* that may not wait as long as the snapshot already due (a new file behind another's progress) brings it forward.
|
|
52746
|
+
*/
|
|
52194
52747
|
emitState(delayMs = 50) {
|
|
52748
|
+
this.changedChats = null;
|
|
52749
|
+
this.scheduleState(delayMs);
|
|
52750
|
+
}
|
|
52751
|
+
/** A change of one chat's own (its link's word, its name): the next state builds this chat's view again, and reuses the others'. */
|
|
52752
|
+
chatChanged(linkId) {
|
|
52753
|
+
this.changedChats?.add(linkId);
|
|
52754
|
+
this.scheduleState(50);
|
|
52755
|
+
}
|
|
52756
|
+
scheduleState(delayMs) {
|
|
52195
52757
|
if (this.gatedOut) return;
|
|
52196
|
-
|
|
52758
|
+
const due = Date.now() + delayMs;
|
|
52759
|
+
if (this.stateTimer) {
|
|
52760
|
+
if (due >= this.stateDue) return;
|
|
52761
|
+
clearTimeout(this.stateTimer);
|
|
52762
|
+
}
|
|
52763
|
+
this.stateDue = due;
|
|
52197
52764
|
this.stateTimer = setTimeout(() => {
|
|
52198
52765
|
this.stateTimer = null;
|
|
52199
52766
|
if (this.gatedOut) return;
|
|
52200
|
-
this.events.onState(this.
|
|
52767
|
+
this.events.onState(this.pushedState());
|
|
52201
52768
|
this.dropBriefViews();
|
|
52202
52769
|
if (this.deviceLinks) this.syncDeviceTokens();
|
|
52203
52770
|
}, delayMs);
|
|
@@ -52260,6 +52827,12 @@ var EngineServer = class {
|
|
|
52260
52827
|
/** How many history changes the engine told; per chat or group, the count at its last one (`historyMark`). */
|
|
52261
52828
|
changes = 0;
|
|
52262
52829
|
changedAt = /* @__PURE__ */ new Map();
|
|
52830
|
+
/** This engine among the ones a page's mark (`AttachMark`) may come from: another counts its changes from nothing. */
|
|
52831
|
+
epoch = crypto.randomUUID();
|
|
52832
|
+
/** The clients that attached for marks, once their attach was sent, and the last mark each was told. */
|
|
52833
|
+
marking = /* @__PURE__ */ new Map();
|
|
52834
|
+
/** A mark is on its way to them: it waits for what changed to be sent. */
|
|
52835
|
+
markDue = false;
|
|
52263
52836
|
/**
|
|
52264
52837
|
* An attention event while no client is attached to hear it: the host tells the person itself. The extension's peer
|
|
52265
52838
|
* runs with no tab open, and a message that came then showed nothing until Ghostly was opened.
|
|
@@ -52339,6 +52912,10 @@ var EngineServer = class {
|
|
|
52339
52912
|
* not changed since is not read and sent again: the client hears only what changes in it from now on.
|
|
52340
52913
|
* `newest`: each chat's newest rows that many (`messagePage`), not its whole history, which the client asks for when
|
|
52341
52914
|
* it needs it (`HistoryRequest`). What changes in the chat goes to it on top of that page.
|
|
52915
|
+
* `marks`: the client is told a `mark` once its attach was sent, and again as changes settle. With `since`, a mark of
|
|
52916
|
+
* this engine's it was told, a chat that has not changed since is not sent: it has it (the extension's pages mirror
|
|
52917
|
+
* every chat into the stored chats they share). Its newest page goes with its first change, as a chat's the client
|
|
52918
|
+
* does not have.
|
|
52342
52919
|
*/
|
|
52343
52920
|
attach(client, read, scope = {}) {
|
|
52344
52921
|
this.clients.add(client);
|
|
@@ -52349,6 +52926,7 @@ var EngineServer = class {
|
|
|
52349
52926
|
this.histories.set(client, sent);
|
|
52350
52927
|
if (scope.newest) this.newest.set(client, scope.newest);
|
|
52351
52928
|
else this.newest.delete(client);
|
|
52929
|
+
const since = scope.since?.epoch === this.epoch && typeof scope.since.mark === "number" ? scope.since.mark : void 0;
|
|
52352
52930
|
this.ready.then(async () => {
|
|
52353
52931
|
if (!this.clients.has(client)) return;
|
|
52354
52932
|
client.post({
|
|
@@ -52361,14 +52939,29 @@ var EngineServer = class {
|
|
|
52361
52939
|
signal
|
|
52362
52940
|
});
|
|
52363
52941
|
else this.offers.delete(linkId);
|
|
52942
|
+
const skipped = [];
|
|
52364
52943
|
for (const link of this.node.getState().links) {
|
|
52365
52944
|
if (sent.has(link.id)) continue;
|
|
52945
|
+
if (since !== void 0 && (this.changedAt.get(link.id) ?? 0) <= since) {
|
|
52946
|
+
skipped.push(link.id);
|
|
52947
|
+
continue;
|
|
52948
|
+
}
|
|
52366
52949
|
await this.inOrder(link.id, async () => {
|
|
52367
52950
|
if (!this.clients.has(client)) return;
|
|
52368
52951
|
client.post(scope.newest ? await this.newestOf(link.id, scope.newest) : this.historyEvent(link.id, await this.node.getMessages(link.id)));
|
|
52369
52952
|
this.histories.get(client)?.add(link.id);
|
|
52370
52953
|
});
|
|
52371
52954
|
}
|
|
52955
|
+
if (!scope.marks && !scope.since) return;
|
|
52956
|
+
const mark = await this.settledMark();
|
|
52957
|
+
if (!this.clients.has(client)) return;
|
|
52958
|
+
this.marking.set(client, mark);
|
|
52959
|
+
client.post({
|
|
52960
|
+
kind: "mark",
|
|
52961
|
+
epoch: this.epoch,
|
|
52962
|
+
mark,
|
|
52963
|
+
...since !== void 0 && { skipped }
|
|
52964
|
+
});
|
|
52372
52965
|
}, (error) => {
|
|
52373
52966
|
this.post(client, {
|
|
52374
52967
|
kind: "start-failed",
|
|
@@ -52384,6 +52977,7 @@ var EngineServer = class {
|
|
|
52384
52977
|
detach(client) {
|
|
52385
52978
|
this.clients.delete(client);
|
|
52386
52979
|
this.histories.delete(client);
|
|
52980
|
+
this.marking.delete(client);
|
|
52387
52981
|
if (this.clients.size === 0) {
|
|
52388
52982
|
this.node.setActiveLink({ linkId: null });
|
|
52389
52983
|
this.node.appsCloseAll();
|
|
@@ -52465,6 +53059,31 @@ var EngineServer = class {
|
|
|
52465
53059
|
}
|
|
52466
53060
|
changed(linkId) {
|
|
52467
53061
|
this.changedAt.set(linkId, ++this.changes);
|
|
53062
|
+
if (!this.marking.size || this.markDue) return;
|
|
53063
|
+
this.markDue = true;
|
|
53064
|
+
this.settledMark().then((mark) => {
|
|
53065
|
+
this.markDue = false;
|
|
53066
|
+
for (const [client, told] of [...this.marking]) {
|
|
53067
|
+
if (told >= mark) continue;
|
|
53068
|
+
this.marking.set(client, mark);
|
|
53069
|
+
this.post(client, {
|
|
53070
|
+
kind: "mark",
|
|
53071
|
+
epoch: this.epoch,
|
|
53072
|
+
mark
|
|
53073
|
+
});
|
|
53074
|
+
}
|
|
53075
|
+
});
|
|
53076
|
+
}
|
|
53077
|
+
/**
|
|
53078
|
+
* The mark once nothing is left being sent: every change up to it went to each client, as a change or in a chat's page
|
|
53079
|
+
* read for it (`inOrder`). A change that comes meanwhile is waited for too.
|
|
53080
|
+
*/
|
|
53081
|
+
async settledMark() {
|
|
53082
|
+
for (;;) {
|
|
53083
|
+
const mark = this.changes;
|
|
53084
|
+
await Promise.all(this.sending.values());
|
|
53085
|
+
if (mark === this.changes && !this.sending.size) return mark;
|
|
53086
|
+
}
|
|
52468
53087
|
}
|
|
52469
53088
|
track(linkId, running) {
|
|
52470
53089
|
const settled = running.catch(() => {});
|
|
@@ -52567,4 +53186,4 @@ function signalKind(signal) {
|
|
|
52567
53186
|
//#endregion
|
|
52568
53187
|
export { EngineServer };
|
|
52569
53188
|
|
|
52570
|
-
//# sourceMappingURL=server-
|
|
53189
|
+
//# sourceMappingURL=server-C1jZZ61O.js.map
|