@ghostlytools/cli 1.11.3 → 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 +27 -22
- package/SKILL.md +4 -2
- package/dist/assets/{api-DgU4MZPD.js → api-BwyFq4lA.js} +2 -2
- package/dist/assets/{api-DBlaoz8i.js → api-MYc6QNRs.js} +187 -87
- package/dist/assets/api-MYc6QNRs.js.map +1 -0
- package/dist/assets/{apiKit-DesObIDf.js → apiKit-CfsNx9ZR.js} +60 -14
- package/dist/assets/apiKit-CfsNx9ZR.js.map +1 -0
- package/dist/assets/{appFetch-C8yZIq1e.js → appFetch-DVYZOZFw.js} +2 -2
- package/dist/assets/{appFetch-C8yZIq1e.js.map → appFetch-DVYZOZFw.js.map} +1 -1
- package/dist/assets/{apps-rzxsjfBV.js → apps-Dbw2Hcko.js} +1 -1
- package/dist/assets/{apps-DkMjDHML.js → apps-h12II1us.js} +52 -30
- package/dist/assets/apps-h12II1us.js.map +1 -0
- package/dist/assets/{arkade-CarKONmH.js → arkade-Bw_4PZRG.js} +2 -2
- package/dist/assets/{arkade-CarKONmH.js.map → arkade-Bw_4PZRG.js.map} +1 -1
- package/dist/assets/{backup-CgWU7x0T.js → backup-CdEzTq5C.js} +1 -1
- package/dist/assets/{backup-C0OJCJlM.js → backup-Chvy79SN.js} +49 -36
- 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-fZTEa_2i.js → buttons-BgoExb4E.js} +6 -5
- package/dist/assets/{buttons-fZTEa_2i.js.map → buttons-BgoExb4E.js.map} +1 -1
- package/dist/assets/buttons-DK2aAGat.js +2 -0
- package/dist/assets/{client-Ibk3-e60.js → client-DY8tZZWi.js} +28 -8
- package/dist/assets/client-DY8tZZWi.js.map +1 -0
- package/dist/assets/{codec-DMpQqVSt.js → codec-BnMg-Grj.js} +2 -2
- package/dist/assets/{codec-DMpQqVSt.js.map → codec-BnMg-Grj.js.map} +1 -1
- package/dist/assets/{envelope-CvQVCGdf.js → envelope-CdV7vHVZ.js} +2 -2
- package/dist/assets/{envelope-CvQVCGdf.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-zV_5Qdqz.js → fedimintSdk-CPFfVK-G.js} +2 -2
- package/dist/assets/{fedimintSdk-zV_5Qdqz.js.map → fedimintSdk-CPFfVK-G.js.map} +1 -1
- package/dist/assets/{fixedHosts-6gKn8dp2.js → fixedHosts-CbgqrIKs.js} +3 -3
- package/dist/assets/{fixedHosts-6gKn8dp2.js.map → fixedHosts-CbgqrIKs.js.map} +1 -1
- package/dist/assets/{host-CYlIiY3r.js → host-C0NMNQLl.js} +556 -126
- package/dist/assets/host-C0NMNQLl.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CdsLcAhY.js → hyperdhtRelay-Dz7pvcBA.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CdsLcAhY.js.map → hyperdhtRelay-Dz7pvcBA.js.map} +1 -1
- package/dist/assets/{irohWeb-D2IuloLL.js → irohWeb-caAj4Dms.js} +7 -7
- package/dist/assets/{irohWeb-D2IuloLL.js.map → irohWeb-caAj4Dms.js.map} +1 -1
- package/dist/assets/{main-C0PfjKTe.js → main-C6t5zrD5.js} +298 -92
- package/dist/assets/main-C6t5zrD5.js.map +1 -0
- package/dist/assets/{mainline-Cu61qcPS.js → mainline-DCuGUSZF.js} +2 -2
- package/dist/assets/{mainline-Cu61qcPS.js.map → mainline-DCuGUSZF.js.map} +1 -1
- package/dist/assets/{networkReason-Dt7Yx_n4.js → networkReason-BbQW1Xpc.js} +3 -3
- package/dist/assets/{networkReason-Dt7Yx_n4.js.map → networkReason-BbQW1Xpc.js.map} +1 -1
- package/dist/assets/{nwc-CtZypDcv.js → nwc-CSDRMZ0e.js} +3 -3
- package/dist/assets/{nwc-CtZypDcv.js.map → nwc-CSDRMZ0e.js.map} +1 -1
- package/dist/assets/{nwcProvider-DYHkd0iu.js → nwcProvider-PE0wli8n.js} +2 -2
- package/dist/assets/{nwcProvider-DYHkd0iu.js.map → nwcProvider-PE0wli8n.js.map} +1 -1
- package/dist/assets/{ownDid-CJ0ta8CL.js → ownDid-C1R5Kd8q.js} +2 -2
- package/dist/assets/{ownDid-CJ0ta8CL.js.map → ownDid-C1R5Kd8q.js.map} +1 -1
- package/dist/assets/{ownStatus-D4HC6tNR.js → ownStatus-BoTf5WqQ.js} +19 -6
- package/dist/assets/ownStatus-BoTf5WqQ.js.map +1 -0
- package/dist/assets/{profiles-Ccdq6Xf6.js → profiles-DszHjEJi.js} +25 -10
- package/dist/assets/profiles-DszHjEJi.js.map +1 -0
- package/dist/assets/{registry-LvxsLJ5S.js → registry-Da-r6eC3.js} +17 -10
- package/dist/assets/registry-Da-r6eC3.js.map +1 -0
- package/dist/assets/{registry-CE0PpQAE.js → registry-zUZBSHYv.js} +1 -1
- package/dist/assets/{resolve-6kVu2DE5.js → resolve-tUzh4lHh.js} +2 -2
- package/dist/assets/{resolve-6kVu2DE5.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-Q3VcNqGt.js → server-C1jZZ61O.js} +667 -196
- package/dist/assets/server-C1jZZ61O.js.map +1 -0
- package/dist/assets/{src-DjVj2ynY.js → src-DJe-OYxd.js} +826 -198
- package/dist/assets/src-DJe-OYxd.js.map +1 -0
- package/dist/assets/{sshForges-DeZ9cN9Q.js → sshForges-C9zTO72R.js} +2 -2
- package/dist/assets/{sshForges-DeZ9cN9Q.js.map → sshForges-C9zTO72R.js.map} +1 -1
- package/dist/assets/{translate-iQZq4TnY.js → translate-CUuC5szR.js} +3 -3
- package/dist/assets/{translate-iQZq4TnY.js.map → translate-CUuC5szR.js.map} +1 -1
- package/dist/assets/{usdt-DnyTGdTX.js → usdt-DI51znt-.js} +3 -3
- package/dist/assets/{usdt-DnyTGdTX.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-DBlaoz8i.js.map +0 -1
- package/dist/assets/apiKit-DesObIDf.js.map +0 -1
- package/dist/assets/apps-DkMjDHML.js.map +0 -1
- package/dist/assets/backup-C0OJCJlM.js.map +0 -1
- package/dist/assets/buttons-Cco0Agfa.js +0 -2
- package/dist/assets/client-Ibk3-e60.js.map +0 -1
- package/dist/assets/errors-Dt-ZnyOX.js.map +0 -1
- package/dist/assets/host-CYlIiY3r.js.map +0 -1
- package/dist/assets/main-C0PfjKTe.js.map +0 -1
- package/dist/assets/ownStatus-D4HC6tNR.js.map +0 -1
- package/dist/assets/profiles-Ccdq6Xf6.js.map +0 -1
- package/dist/assets/registry-LvxsLJ5S.js.map +0 -1
- package/dist/assets/secretGuard-DUr6bgKc.js +0 -2
- package/dist/assets/server-Q3VcNqGt.js.map +0 -1
- package/dist/assets/src-DjVj2ynY.js.map +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $ as
|
|
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 besideUrl, c as isGitHubPage, i as appPasteUrl, n as APP_FETCH_LIMITS, o as boundedAppFetch, r as AppFetchError, s as isAppFetchUrl } from "./appFetch-
|
|
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 {
|
|
@@ -9483,7 +9488,7 @@ var HostNotContacted = class extends Error {};
|
|
|
9483
9488
|
*/
|
|
9484
9489
|
function fixedHostsFetch(fetch) {
|
|
9485
9490
|
return async (url, options) => {
|
|
9486
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
9491
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-CbgqrIKs.js");
|
|
9487
9492
|
const host = hostOf$1(url);
|
|
9488
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`);
|
|
9489
9494
|
return fetch(url, options);
|
|
@@ -10965,7 +10970,7 @@ var BUNDLES_KEPT = {
|
|
|
10965
10970
|
min: 2,
|
|
10966
10971
|
ms: 6e4
|
|
10967
10972
|
};
|
|
10968
|
-
/** URLs the
|
|
10973
|
+
/** URLs the engine remembers it read whole and refused (`Apps.refusedReads`). */
|
|
10969
10974
|
var REFUSED_READS_KEPT = 256;
|
|
10970
10975
|
/** The first bytes of a bundle: magic, the manifest's length and the largest manifest. */
|
|
10971
10976
|
var PEEK_BYTES = APP_BUNDLE_MAGIC.length + 4 + APP_BUNDLE_LIMITS.manifestBytes;
|
|
@@ -11398,11 +11403,23 @@ var Apps = class {
|
|
|
11398
11403
|
*/
|
|
11399
11404
|
listingMisses = /* @__PURE__ */ new Map();
|
|
11400
11405
|
/**
|
|
11401
|
-
* URLs whose whole read the update check refused (a file hash that does not hold, a bad
|
|
11402
|
-
* the digest their peek showed then: the same peek
|
|
11403
|
-
*
|
|
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.
|
|
11404
11410
|
*/
|
|
11405
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
|
+
}
|
|
11406
11423
|
/**
|
|
11407
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
|
|
11408
11425
|
* commit): by store key, with that URL. The same bytes there again are not checked whole at every refresh.
|
|
@@ -11448,6 +11465,15 @@ var Apps = class {
|
|
|
11448
11465
|
const age = at === void 0 ? -1 : this.now() - at;
|
|
11449
11466
|
return age >= 0 && age < ms;
|
|
11450
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
|
+
}
|
|
11451
11477
|
/**
|
|
11452
11478
|
* Preloads the default stores (no request) and removes the bundles no record names (`sweepBundles`), then checks for
|
|
11453
11479
|
* updates soon after start and every 24 hours.
|
|
@@ -11532,6 +11558,13 @@ var Apps = class {
|
|
|
11532
11558
|
async keptRevocationsOf(ref) {
|
|
11533
11559
|
return keptRevocations(await wrap((await store(STORES$1.settings, "readonly")).get(APP_REVOCATIONS_KEY)), ref).mine;
|
|
11534
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
|
+
}
|
|
11535
11568
|
/**
|
|
11536
11569
|
* The built-in apps this profile is offered (WISP 1200 § Built-in apps): shown with the installed ones, with nothing
|
|
11537
11570
|
* stored and nothing granted. Opening one is an install like any other, from the bundle the build carries.
|
|
@@ -11665,12 +11698,14 @@ var Apps = class {
|
|
|
11665
11698
|
* only the records written before it. A revocation the record gained since `was` (`keepStoreRevocations`) is kept:
|
|
11666
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
|
|
11667
11700
|
* revoke of the versions written, as held at the write: a version fetched while a store's index revoked it was not on
|
|
11668
|
-
* 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.
|
|
11669
11703
|
*/
|
|
11670
11704
|
async putAppIfUnchanged(app, was) {
|
|
11671
11705
|
const stores = await this.records();
|
|
11672
|
-
const tx = (await openDb()).transaction(STORES$1.apps, "readwrite");
|
|
11706
|
+
const tx = (await openDb()).transaction([STORES$1.apps, STORES$1.settings], "readwrite");
|
|
11673
11707
|
let put = false;
|
|
11708
|
+
const kept = tx.objectStore(STORES$1.settings).get(APP_REVOCATIONS_KEY);
|
|
11674
11709
|
const read = tx.objectStore(STORES$1.apps).get(app.ref);
|
|
11675
11710
|
read.onsuccess = () => {
|
|
11676
11711
|
const now = read.result;
|
|
@@ -11678,7 +11713,7 @@ var Apps = class {
|
|
|
11678
11713
|
const had = new Set((was?.revocations ?? []).map((r) => canonicalJson(r)));
|
|
11679
11714
|
app = withRevocations(app, (now?.revocations ?? []).filter((r) => !had.has(canonicalJson(r))));
|
|
11680
11715
|
const revoked = [...stores.values()].flatMap((s) => s.removed ? [] : s.index?.revoked ?? []);
|
|
11681
|
-
app = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11716
|
+
app = withRevocations(app, stopping(this.versionsOf(app), [...revoked, ...keptRevocations(kept.result, app.ref).mine]));
|
|
11682
11717
|
const { store: pin, ...unpinned } = app;
|
|
11683
11718
|
tx.objectStore(STORES$1.apps).put(pin !== void 0 && stores.get(pin)?.removed ? unpinned : app);
|
|
11684
11719
|
put = true;
|
|
@@ -11726,13 +11761,21 @@ var Apps = class {
|
|
|
11726
11761
|
/**
|
|
11727
11762
|
* Keeps on each installed app the revocations a store's index carries of its versions: a client keeps every
|
|
11728
11763
|
* revocation it verified (WISP 1200 § Publisher keys), so the store's next index without it, or the store removed,
|
|
11729
|
-
* 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.
|
|
11730
11766
|
*/
|
|
11731
11767
|
async keepStoreRevocations(record) {
|
|
11732
11768
|
const revoked = record.index?.revoked ?? [];
|
|
11733
11769
|
if (!revoked.length) return;
|
|
11734
11770
|
const reread = async (ref) => wrap((await store(STORES$1.apps, "readonly")).get(ref));
|
|
11735
|
-
|
|
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)) {
|
|
11736
11779
|
const next = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11737
11780
|
if ((next.revocations?.length ?? 0) <= (app.revocations?.length ?? 0) || await this.putAppIfUnchanged(next, app)) break;
|
|
11738
11781
|
}
|
|
@@ -11757,8 +11800,13 @@ var Apps = class {
|
|
|
11757
11800
|
revoked: s.index.revoked
|
|
11758
11801
|
}));
|
|
11759
11802
|
}
|
|
11760
|
-
|
|
11761
|
-
|
|
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) => ({
|
|
11762
11810
|
key: s.key,
|
|
11763
11811
|
name: s.index.name,
|
|
11764
11812
|
kind: s.index.kind
|
|
@@ -12495,7 +12543,7 @@ var Apps = class {
|
|
|
12495
12543
|
let last = null;
|
|
12496
12544
|
for (const url of urls) try {
|
|
12497
12545
|
const kept = expect?.digest !== void 0 ? this.staged.get(stagedKey(expect.digest, url, fromStore)) : void 0;
|
|
12498
|
-
const { bundle, bytes } = kept && this.
|
|
12546
|
+
const { bundle, bytes } = kept && this.checkedWithin(kept.at, STAGED.ms) ? kept : await this.fetchBundle(url);
|
|
12499
12547
|
const version = versionOf(bundle.manifest, bundle.digest);
|
|
12500
12548
|
if (expect) {
|
|
12501
12549
|
if (version.ref !== expect.ref) fail("other-app", "The URL holds another app");
|
|
@@ -12509,29 +12557,43 @@ var Apps = class {
|
|
|
12509
12557
|
}
|
|
12510
12558
|
throw last instanceof Error ? last : new Error(String(last));
|
|
12511
12559
|
}
|
|
12512
|
-
/**
|
|
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
|
+
*/
|
|
12513
12564
|
sweepStaged() {
|
|
12514
12565
|
this.sweep = null;
|
|
12515
|
-
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);
|
|
12516
12567
|
const oldest = this.staged.values().next().value;
|
|
12517
12568
|
if (oldest) this.sweep = setTimeout(() => this.sweepStaged(), STAGED.ms - (this.now() - oldest.at));
|
|
12518
12569
|
}
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
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) ?? [];
|
|
12523
12577
|
const stops = stopping([version], read);
|
|
12524
12578
|
if (stops.length) {
|
|
12525
12579
|
const tx = (await openDb()).transaction(STORES$1.settings, "readwrite");
|
|
12526
12580
|
keepRevocations(tx.objectStore(STORES$1.settings), version.ref, stops);
|
|
12527
12581
|
await done(tx);
|
|
12582
|
+
const installed = await this.app(version.ref);
|
|
12583
|
+
if (installed) await this.keepOnRecord(installed, stops);
|
|
12528
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 ?? []]);
|
|
12529
12591
|
const revocations = [...await this.keptRevocationsOf(version.ref), ...read];
|
|
12530
12592
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
12531
12593
|
const decision = installDecision(installed, version);
|
|
12532
12594
|
const install = decision === "other-app" ? "new" : decision;
|
|
12533
12595
|
const asks = install === "new" ? [...manifest.permissions] : install === "update" ? manifest.permissions.filter((p) => !installed.permissions.includes(p)) : [];
|
|
12534
|
-
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);
|
|
12535
12597
|
const stage = stagedKey(digest, from, fromStore);
|
|
12536
12598
|
this.staged.delete(stage);
|
|
12537
12599
|
while (this.staged.size >= STAGED.max) this.staged.delete(this.staged.keys().next().value);
|
|
@@ -12542,10 +12604,11 @@ var Apps = class {
|
|
|
12542
12604
|
...fromStore !== void 0 && { store: fromStore },
|
|
12543
12605
|
revocations,
|
|
12544
12606
|
asks,
|
|
12545
|
-
at: this.now()
|
|
12607
|
+
at: this.now(),
|
|
12608
|
+
...carried && { carried: true }
|
|
12546
12609
|
});
|
|
12547
12610
|
if (!this.sweep) this.sweepStaged();
|
|
12548
|
-
const listedBy = this.listedBy(version
|
|
12611
|
+
const listedBy = this.listedBy(version, stores);
|
|
12549
12612
|
return {
|
|
12550
12613
|
digest,
|
|
12551
12614
|
ref: version.ref,
|
|
@@ -12573,19 +12636,20 @@ var Apps = class {
|
|
|
12573
12636
|
* bundle waits.
|
|
12574
12637
|
*/
|
|
12575
12638
|
async install({ stage, digest, grant, asks }) {
|
|
12576
|
-
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));
|
|
12577
12640
|
if (live.length > 1) fail("screens", "This app was fetched from more than one place; install it from its screen");
|
|
12578
12641
|
const [key, staged] = live[0] ?? [stage ?? ""];
|
|
12579
12642
|
if (!staged) {
|
|
12580
12643
|
this.staged.delete(key);
|
|
12581
12644
|
fail("expired", "Fetch the app again");
|
|
12582
12645
|
}
|
|
12583
|
-
const { bundle, bytes, from, store: fromStore
|
|
12646
|
+
const { bundle, bytes, from, store: fromStore } = staged;
|
|
12584
12647
|
const { manifest } = bundle;
|
|
12585
12648
|
if (!Array.isArray(grant) || !manifest.permissions.every((p) => grant.includes(p))) fail("permissions", "Every permission the app asks for must be granted");
|
|
12586
12649
|
const shown = asks ?? staged.asks;
|
|
12587
12650
|
if (!Array.isArray(shown)) fail("permissions", "The permissions shown must be a list");
|
|
12588
12651
|
const version = versionOf(manifest, digest);
|
|
12652
|
+
const revocations = staged.carried ? [...staged.revocations, ...await this.readStopping(version, [from, ...manifest.sources ?? []])] : staged.revocations;
|
|
12589
12653
|
let wrote;
|
|
12590
12654
|
try {
|
|
12591
12655
|
let read = false;
|
|
@@ -12632,7 +12696,11 @@ var Apps = class {
|
|
|
12632
12696
|
return this.view(await this.app(version.ref), stores);
|
|
12633
12697
|
}
|
|
12634
12698
|
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
12635
|
-
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;
|
|
12636
12704
|
const next = withRevocations(this.versionRecord(installed, bundle, kind, from, fromStore), known);
|
|
12637
12705
|
if (!await this.putAppIfUnchanged(next, installed)) continue;
|
|
12638
12706
|
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
@@ -12704,7 +12772,7 @@ var Apps = class {
|
|
|
12704
12772
|
}
|
|
12705
12773
|
fail("unlisted", "The store no longer lists this update");
|
|
12706
12774
|
}
|
|
12707
|
-
const run = this.runStatus(versionOf(read.bundle.manifest, pending.digest), this.storeViews(stores), installed.revocations);
|
|
12775
|
+
const run = this.runStatus(versionOf(read.bundle.manifest, pending.digest), this.storeViews(stores), [...installed.revocations ?? [], ...await this.keptRevocationsOf(ref)]);
|
|
12708
12776
|
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
12709
12777
|
if (run.status === "removed") fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
12710
12778
|
const plan = planAppUpdate(installed, {
|
|
@@ -12854,23 +12922,12 @@ var Apps = class {
|
|
|
12854
12922
|
outcome = "equivocation";
|
|
12855
12923
|
continue;
|
|
12856
12924
|
}
|
|
12857
|
-
|
|
12858
|
-
if (holds && refused?.digest === holds.digest && this.checkedWithin(refused.at, APP_CHECK_TIMINGS.freshMs)) continue;
|
|
12925
|
+
if (holds && this.readRefused(url, holds.digest)) continue;
|
|
12859
12926
|
let fetched;
|
|
12860
12927
|
try {
|
|
12861
12928
|
fetched = await this.fetchBundle(url);
|
|
12862
12929
|
} catch (error) {
|
|
12863
|
-
if (holds
|
|
12864
|
-
this.refusedReads.delete(url);
|
|
12865
|
-
this.refusedReads.set(url, {
|
|
12866
|
-
digest: holds.digest,
|
|
12867
|
-
at: this.now()
|
|
12868
|
-
});
|
|
12869
|
-
for (const old of this.refusedReads.keys()) {
|
|
12870
|
-
if (this.refusedReads.size <= REFUSED_READS_KEPT) break;
|
|
12871
|
-
this.refusedReads.delete(old);
|
|
12872
|
-
}
|
|
12873
|
-
}
|
|
12930
|
+
if (holds) this.refuseFailedRead(url, holds.digest, error);
|
|
12874
12931
|
continue;
|
|
12875
12932
|
}
|
|
12876
12933
|
const { bundle, bytes } = fetched;
|
|
@@ -12887,6 +12944,7 @@ var Apps = class {
|
|
|
12887
12944
|
}
|
|
12888
12945
|
};
|
|
12889
12946
|
outcome = "equivocation";
|
|
12947
|
+
this.refuseRead(url, version.digest);
|
|
12890
12948
|
continue;
|
|
12891
12949
|
}
|
|
12892
12950
|
const plan = planAppUpdate(app, {
|
|
@@ -12904,6 +12962,7 @@ var Apps = class {
|
|
|
12904
12962
|
}
|
|
12905
12963
|
};
|
|
12906
12964
|
outcome = "equivocation";
|
|
12965
|
+
this.refuseRead(url, version.digest);
|
|
12907
12966
|
}
|
|
12908
12967
|
continue;
|
|
12909
12968
|
}
|
|
@@ -12996,21 +13055,7 @@ var Apps = class {
|
|
|
12996
13055
|
const carried = this.builtIn(app.ref);
|
|
12997
13056
|
if (carried && carried.digest === app.digest) {
|
|
12998
13057
|
const held = await this.bundled(carried).catch(() => null);
|
|
12999
|
-
if (held)
|
|
13000
|
-
const kind = await this.writeBundle(app.digest, held.bytes);
|
|
13001
|
-
const now = await this.app(app.ref);
|
|
13002
|
-
if (!now || now.digest !== app.digest || now.bytes !== kind && !await this.putApp({
|
|
13003
|
-
...now,
|
|
13004
|
-
bytes: kind
|
|
13005
|
-
})) {
|
|
13006
|
-
await this.removeBundle(kind, app.digest);
|
|
13007
|
-
fail("not-installed", "This app is not installed");
|
|
13008
|
-
}
|
|
13009
|
-
return this.runCheckOf({
|
|
13010
|
-
...now,
|
|
13011
|
-
bytes: kind
|
|
13012
|
-
}, stores);
|
|
13013
|
-
}
|
|
13058
|
+
if (held) return this.filesBack(app, held.bytes, stores);
|
|
13014
13059
|
}
|
|
13015
13060
|
const urls = [app.from];
|
|
13016
13061
|
for (const s of stores) {
|
|
@@ -13024,32 +13069,41 @@ var Apps = class {
|
|
|
13024
13069
|
} catch {
|
|
13025
13070
|
continue;
|
|
13026
13071
|
}
|
|
13072
|
+
if (this.readRefused(url, app.digest)) continue;
|
|
13027
13073
|
let fetched;
|
|
13028
13074
|
try {
|
|
13029
13075
|
fetched = await this.fetchBundle(url);
|
|
13030
|
-
} catch {
|
|
13076
|
+
} catch (error) {
|
|
13077
|
+
this.refuseFailedRead(url, app.digest, error);
|
|
13031
13078
|
continue;
|
|
13032
13079
|
}
|
|
13033
13080
|
if (fetched.bundle.digest !== app.digest) continue;
|
|
13034
|
-
|
|
13035
|
-
const now = await this.app(app.ref);
|
|
13036
|
-
if (!now || now.digest !== app.digest || now.bytes !== kind && !await this.putApp({
|
|
13037
|
-
...now,
|
|
13038
|
-
bytes: kind
|
|
13039
|
-
})) {
|
|
13040
|
-
await this.removeBundle(kind, app.digest);
|
|
13041
|
-
fail("not-installed", "This app is not installed");
|
|
13042
|
-
}
|
|
13043
|
-
return this.runCheckOf({
|
|
13044
|
-
...now,
|
|
13045
|
-
bytes: kind
|
|
13046
|
-
}, stores);
|
|
13081
|
+
return this.filesBack(app, fetched.bytes, stores);
|
|
13047
13082
|
}
|
|
13048
13083
|
return { status: "needs-files" };
|
|
13049
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
|
+
}
|
|
13050
13104
|
async runCheckOf(app, stores) {
|
|
13051
13105
|
if (!await this.hasBundle(app.bytes, app.digest, app.manifest)) return { status: "needs-files" };
|
|
13052
|
-
return this.runStatus(app, this.storeViews(stores), app.revocations);
|
|
13106
|
+
return this.runStatus(app, this.storeViews(stores), [...app.revocations ?? [], ...await this.keptRevocationsOf(app.ref)]);
|
|
13053
13107
|
}
|
|
13054
13108
|
/** Before an app runs (WISP 1200 § Takedowns): revoked stops it, removed by a store of the person's warns. No request. */
|
|
13055
13109
|
async runCheck({ ref }) {
|
|
@@ -13128,7 +13182,7 @@ var Apps = class {
|
|
|
13128
13182
|
}
|
|
13129
13183
|
async view(app, stores) {
|
|
13130
13184
|
const { manifest } = app;
|
|
13131
|
-
const listedBy = this.listedBy(app
|
|
13185
|
+
const listedBy = this.listedBy(app, stores, app.store);
|
|
13132
13186
|
const stopped = this.startedBefore(app).map((v) => ({
|
|
13133
13187
|
digest: v.digest,
|
|
13134
13188
|
run: this.runStatus(v, this.storeViews(stores), app.revocations)
|
|
@@ -13339,6 +13393,10 @@ var Apps = class {
|
|
|
13339
13393
|
if (!old) return;
|
|
13340
13394
|
const next = plus(used, countOf(old, -1));
|
|
13341
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
|
+
}
|
|
13342
13400
|
if (this.uninstalls.get(app.ref) !== uninstalls) {
|
|
13343
13401
|
this.usage.delete(`${app.ref}\0${where}`);
|
|
13344
13402
|
fail("not-installed", "This app is not installed");
|
|
@@ -21210,9 +21268,16 @@ var FileDesk = class {
|
|
|
21210
21268
|
refuse: "no-room",
|
|
21211
21269
|
room
|
|
21212
21270
|
};
|
|
21271
|
+
if (room !== null && file.size + this.stillComing() > room) return "ask";
|
|
21213
21272
|
const taken = this.deps.receivedBytes(linkId) + this.autoTaken(linkId);
|
|
21214
21273
|
return file.size <= FILE_LIMITS.askAboveBytes && taken + file.size <= FILE_LIMITS.autoAcceptBytesPerPeer ? "accept" : "ask";
|
|
21215
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
|
+
}
|
|
21216
21281
|
/** files/3 files this contact sent that were taken without asking and are kept (or on their way). */
|
|
21217
21282
|
autoTaken(linkId) {
|
|
21218
21283
|
const chat = this.chats.get(linkId);
|
|
@@ -23713,8 +23778,7 @@ function noteIfStanding(current, message) {
|
|
|
23713
23778
|
* the new one, and every member would show it twice.
|
|
23714
23779
|
*/
|
|
23715
23780
|
function groupReactionsToResend(messages, limit) {
|
|
23716
|
-
|
|
23717
|
-
for (const m of messages) if (m.event === "joined" && !m.member) joinedAt = Math.max(joinedAt, m.timestamp);
|
|
23781
|
+
const joinedAt = lastJoined(messages);
|
|
23718
23782
|
return messages.flatMap((m) => {
|
|
23719
23783
|
const r = m.reactions?.me, id = replyRef(m, true);
|
|
23720
23784
|
return r && id && r.at >= joinedAt ? [{
|
|
@@ -23724,6 +23788,12 @@ function groupReactionsToResend(messages, limit) {
|
|
|
23724
23788
|
}] : [];
|
|
23725
23789
|
}).sort((a, b) => b.n - a.n).slice(0, limit);
|
|
23726
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
|
+
}
|
|
23727
23797
|
/** This side's highest number in a chat's history: the next one goes past it. */
|
|
23728
23798
|
function lastMine(messages) {
|
|
23729
23799
|
let last = 0;
|
|
@@ -23747,6 +23817,8 @@ var Reactions = class {
|
|
|
23747
23817
|
* out. It only has to grow, so a row deleted since leaves it too high and nothing is wrong.
|
|
23748
23818
|
*/
|
|
23749
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();
|
|
23750
23822
|
/** Per 1:1 chat: when it was last read whole for a received reaction, and the read of those that waited meanwhile. */
|
|
23751
23823
|
lookups = /* @__PURE__ */ new Map();
|
|
23752
23824
|
constructor(host) {
|
|
@@ -23775,7 +23847,10 @@ var Reactions = class {
|
|
|
23775
23847
|
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or takes no reaction` };
|
|
23776
23848
|
const current = target.reactions?.me;
|
|
23777
23849
|
if (!e && !current?.e) return { error: "No reaction of yours to take back" };
|
|
23778
|
-
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());
|
|
23779
23854
|
for (const p of pending) last = Math.max(last, p.n);
|
|
23780
23855
|
const reaction = {
|
|
23781
23856
|
id,
|
|
@@ -23790,6 +23865,24 @@ var Reactions = class {
|
|
|
23790
23865
|
});
|
|
23791
23866
|
}
|
|
23792
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
|
+
/**
|
|
23793
23886
|
* A reaction that came from `by` (`peer`, or a member's key), already authenticated as theirs. A message not here
|
|
23794
23887
|
* yet keeps it for five minutes; past the room for that sender, it is dropped (and, on a 1:1 session, not confirmed).
|
|
23795
23888
|
* Past `REACTION_LIMITS.receive` a window from one group member, the rest wait for the next window (`hold`): a
|
|
@@ -23997,6 +24090,7 @@ var Reactions = class {
|
|
|
23997
24090
|
this.dropHeld(chat);
|
|
23998
24091
|
this.waiting.delete(chat);
|
|
23999
24092
|
this.last.delete(chat);
|
|
24093
|
+
this.joined.delete(chat);
|
|
24000
24094
|
clearTimeout(this.lookups.get(chat)?.timer);
|
|
24001
24095
|
this.lookups.delete(chat);
|
|
24002
24096
|
}
|
|
@@ -24251,7 +24345,8 @@ var GroupRows = class {
|
|
|
24251
24345
|
this.written.delete(groupId);
|
|
24252
24346
|
await raw.deleteGroup(groupId);
|
|
24253
24347
|
},
|
|
24254
|
-
getMessages: (linkId) => raw.getMessages(linkId)
|
|
24348
|
+
getMessages: (linkId) => raw.getMessages(linkId),
|
|
24349
|
+
...raw.getMessagePage && { getMessagePage: (linkId, page) => raw.getMessagePage(linkId, page) }
|
|
24255
24350
|
};
|
|
24256
24351
|
}
|
|
24257
24352
|
/**
|
|
@@ -24825,6 +24920,11 @@ var AWAIT_EDGE_MS = 12e4;
|
|
|
24825
24920
|
* hub its members a minute, another hub three), and the app dials those that were live once at start (`resume`).
|
|
24826
24921
|
*/
|
|
24827
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;
|
|
24828
24928
|
/** After letting someone in, the door keeps its reads at the admitting pace this long. */
|
|
24829
24929
|
var ADMITTED_QUIET_MS = 3e4;
|
|
24830
24930
|
var MAX_PENDING_ENTRIES$1 = 8;
|
|
@@ -24868,6 +24968,14 @@ var TIP_CHECK_EVERY_MS = 3e5;
|
|
|
24868
24968
|
* group that needs one more hub gets it.
|
|
24869
24969
|
*/
|
|
24870
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;
|
|
24871
24979
|
/** A lobby request this recent is from a member still looking fast for my side of the edge: mine opens expecting it. */
|
|
24872
24980
|
var LOBBY_EXPECT_MS = 3e4;
|
|
24873
24981
|
/**
|
|
@@ -25104,16 +25212,22 @@ var Communities = class {
|
|
|
25104
25212
|
const live = this.live.get(groupId);
|
|
25105
25213
|
return !!live?.hub && live.session.status === "active";
|
|
25106
25214
|
}
|
|
25107
|
-
|
|
25215
|
+
/** `newestOnly`: a run that starts no group reads each history's newest message alone (`Groups.load`). */
|
|
25216
|
+
async load(groups, newestOnly = false) {
|
|
25108
25217
|
for (const group of groups) {
|
|
25109
25218
|
this.stored.set(group.id, group);
|
|
25110
|
-
|
|
25111
|
-
|
|
25112
|
-
|
|
25113
|
-
|
|
25114
|
-
|
|
25115
|
-
|
|
25116
|
-
|
|
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
|
+
}
|
|
25117
25231
|
for (const [, linkId] of this.host.entries(group.id)) if (group.joining?.linkId !== linkId) await this.host.closeEdge(linkId);
|
|
25118
25232
|
const live = this.live.get(group.id);
|
|
25119
25233
|
if (live) for (const key of this.host.edges(group.id).keys()) live.restored.set(key, 0);
|
|
@@ -25130,7 +25244,7 @@ var Communities = class {
|
|
|
25130
25244
|
/** A message deleted for everyone left this device: the marks it set go back (`unmark` in groups.ts); `mentionOnly`, its "@" alone. */
|
|
25131
25245
|
async unmark(groupId, removed, mentionOnly = false) {
|
|
25132
25246
|
const group = this.stored.get(groupId);
|
|
25133
|
-
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);
|
|
25134
25248
|
}
|
|
25135
25249
|
views() {
|
|
25136
25250
|
return [...this.stored.values()].flatMap((group) => this.viewOf(group));
|
|
@@ -25536,14 +25650,14 @@ var Communities = class {
|
|
|
25536
25650
|
if (!rosterHas(s.roster, s.myKey) && !this.handedToLeaver(left)) await this.dropLeftBehind(groupId);
|
|
25537
25651
|
else if (now - left.since > LEFT_FOLLOW_MS) await this.dropLeftBehind(groupId);
|
|
25538
25652
|
else if (!rosterHas(s.roster, s.myKey)) left.handOnAt = void 0;
|
|
25539
|
-
else if (s.admin !== s.myKey) left.handOnAt = void 0;
|
|
25540
25653
|
else {
|
|
25541
|
-
if (
|
|
25654
|
+
if (now - (left.askedAt ?? 0) >= (s.leftWaitsForSecret ? 5e3 : 3e4)) {
|
|
25542
25655
|
left.askedAt = now;
|
|
25543
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);
|
|
25544
25657
|
for (const key of ready.slice(0, 3)) s.catchUp(key);
|
|
25545
25658
|
}
|
|
25546
|
-
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;
|
|
25547
25661
|
else if (now >= left.handOnAt) await this.handOn(groupId, now);
|
|
25548
25662
|
}
|
|
25549
25663
|
}
|
|
@@ -25792,9 +25906,10 @@ var Communities = class {
|
|
|
25792
25906
|
live.cutOffSince ??= now;
|
|
25793
25907
|
return now - live.cutOffSince < CUT_OFF_STEP_UP_MS;
|
|
25794
25908
|
};
|
|
25795
|
-
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;
|
|
25796
25911
|
if (want()) {
|
|
25797
|
-
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);
|
|
25798
25913
|
if (now >= live.hubCandidateAt) {
|
|
25799
25914
|
live.hubCandidateAt = 0;
|
|
25800
25915
|
if (live.lastBeaconRead !== now) await this.readBeacon(groupId, live, now);
|
|
@@ -25805,6 +25920,7 @@ var Communities = class {
|
|
|
25805
25920
|
live.emptySince = now;
|
|
25806
25921
|
live.leaving = 0;
|
|
25807
25922
|
live.knocksScanned = false;
|
|
25923
|
+
if (stepIn() !== void 0) live.lobbyBusyUntil = now + this.timings.lobbyBusyMs;
|
|
25808
25924
|
await this.publishBeacon(groupId, live, now, true).catch(() => {});
|
|
25809
25925
|
traceJoin(groupId, "hub.elected");
|
|
25810
25926
|
}
|
|
@@ -25891,6 +26007,11 @@ var Communities = class {
|
|
|
25891
26007
|
const wait = (back || taking || live.replacing?.has(key) ? 3 : listed ? 2 : 1) * this.timings.hubWaitMs;
|
|
25892
26008
|
const dropped = !live.hubsUp.has(key) && live.beaconAt === now && live.seenHubs.has(key) && !live.beacon.some((h) => h.key === key);
|
|
25893
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
|
+
};
|
|
25894
26015
|
if (live.hubsUp.has(key) || dropped) lost = true;
|
|
25895
26016
|
live.hubsAvoided.set(key, now + 2 * wait);
|
|
25896
26017
|
live.hubWaits.delete(key);
|
|
@@ -25905,14 +26026,18 @@ var Communities = class {
|
|
|
25905
26026
|
}
|
|
25906
26027
|
const picked = pickHubs(me, others, now, new Set(live.hubsAvoided.keys()));
|
|
25907
26028
|
const bare = ![...edges.values()].some((id) => this.host.linkReady(id, 2));
|
|
25908
|
-
|
|
25909
|
-
|
|
25910
|
-
|
|
25911
|
-
|
|
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
|
+
}
|
|
25912
26037
|
}
|
|
25913
26038
|
await this.lookPast(groupId, live, others, kept, now);
|
|
25914
26039
|
live.myHubs = kept;
|
|
25915
|
-
live.forceHub = !kept.length && others.length < COMMUNITY_TOPOLOGY.maxHubs;
|
|
26040
|
+
live.forceHub = !waiting && !kept.length && others.length < COMMUNITY_TOPOLOGY.maxHubs;
|
|
25916
26041
|
for (const hub of kept) {
|
|
25917
26042
|
const id = edges.get(hub);
|
|
25918
26043
|
if (id && this.host.linkReady(id, 2)) {
|
|
@@ -25944,7 +26069,12 @@ var Communities = class {
|
|
|
25944
26069
|
} else if (now - since > ENTRY_TIMEOUT_MS$1) {
|
|
25945
26070
|
live.pendingEntries.delete(key);
|
|
25946
26071
|
this.refused.set(key, now + REFUSED_FOR_MS$1);
|
|
25947
|
-
} 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);
|
|
25948
26078
|
if (linkId) await this.host.closeEdge(linkId);
|
|
25949
26079
|
}
|
|
25950
26080
|
if (live.unanswered) {
|
|
@@ -26051,6 +26181,33 @@ var Communities = class {
|
|
|
26051
26181
|
return !!id && this.host.linkReady(id, 2);
|
|
26052
26182
|
});
|
|
26053
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
|
+
}
|
|
26054
26211
|
hubLoad(groupId, live, now) {
|
|
26055
26212
|
const edges = this.host.edges(groupId);
|
|
26056
26213
|
if (now - live.beaconAt <= 2 * this.timings.beaconReadMs) {
|
|
@@ -26383,6 +26540,16 @@ var Communities = class {
|
|
|
26383
26540
|
} else for (const key of live.myHubs) wanted.add(key);
|
|
26384
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);
|
|
26385
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
|
+
}
|
|
26386
26553
|
for (const [key, since] of live.restored) {
|
|
26387
26554
|
if (!since) live.restored.set(key, now);
|
|
26388
26555
|
if (!existing.has(key) || now - (since || now) >= RESTORED_EDGE_MS || s.wasRemoved(key)) live.restored.delete(key);
|
|
@@ -26564,6 +26731,7 @@ var Communities = class {
|
|
|
26564
26731
|
if (this.room(groupId, live, now) <= live.members.size) break;
|
|
26565
26732
|
if (this.host.adminTurn && !await this.host.adminTurn(groupId, { wait: false })) break;
|
|
26566
26733
|
live.pendingEntries.set(key, now);
|
|
26734
|
+
live.invitedAt?.delete(key);
|
|
26567
26735
|
live.doorKey = link.host;
|
|
26568
26736
|
traceJoin(groupId, "knock.seen", {
|
|
26569
26737
|
age: now - ts,
|
|
@@ -26678,6 +26846,7 @@ var Communities = class {
|
|
|
26678
26846
|
async closeEntries(groupId) {
|
|
26679
26847
|
const live = this.live.get(groupId), mine = this.stored.get(groupId)?.joining?.linkId;
|
|
26680
26848
|
live?.pendingEntries.clear();
|
|
26849
|
+
live?.invitedAt?.clear();
|
|
26681
26850
|
for (const linkId of this.host.entries(groupId).values()) if (linkId !== mine) await this.host.closeEdge(linkId);
|
|
26682
26851
|
}
|
|
26683
26852
|
/** An entry session of a community came up with groups v2 on both sides: the hub invites. */
|
|
@@ -26710,6 +26879,7 @@ var Communities = class {
|
|
|
26710
26879
|
this.host.sendOnLink(linkId, live.session.inviteFrame());
|
|
26711
26880
|
traceJoin(groupId, "invite.sent");
|
|
26712
26881
|
} catch {}
|
|
26882
|
+
(live.invitedAt ??= /* @__PURE__ */ new Map()).set(peer, now);
|
|
26713
26883
|
return true;
|
|
26714
26884
|
}
|
|
26715
26885
|
/** Admission frames on an entry session (either side). */
|
|
@@ -26740,7 +26910,8 @@ var Communities = class {
|
|
|
26740
26910
|
}
|
|
26741
26911
|
case "group-full": {
|
|
26742
26912
|
const joining = group.joining, { n, max } = frame;
|
|
26743
|
-
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;
|
|
26744
26915
|
this.toldFull.set(g, {
|
|
26745
26916
|
n,
|
|
26746
26917
|
max,
|
|
@@ -26755,6 +26926,9 @@ var Communities = class {
|
|
|
26755
26926
|
const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
|
|
26756
26927
|
if (!live || !peer || frame.key !== peer || !live.pendingEntries.has(peer)) return;
|
|
26757
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);
|
|
26758
26932
|
let welcome;
|
|
26759
26933
|
try {
|
|
26760
26934
|
welcome = rosterHas(live.session.roster, peer) ? await live.session.rewelcome(peer) : await live.session.admit(peer, this.now());
|
|
@@ -26762,6 +26936,8 @@ var Communities = class {
|
|
|
26762
26936
|
live.pendingEntries.delete(peer);
|
|
26763
26937
|
await this.host.closeEdge(linkId);
|
|
26764
26938
|
return;
|
|
26939
|
+
} finally {
|
|
26940
|
+
live.accepting.delete(peer);
|
|
26765
26941
|
}
|
|
26766
26942
|
for (const piece of welcome) try {
|
|
26767
26943
|
this.host.sendOnLink(linkId, piece);
|
|
@@ -26855,6 +27031,7 @@ var Communities = class {
|
|
|
26855
27031
|
const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
|
|
26856
27032
|
if (live && peer) {
|
|
26857
27033
|
live.pendingEntries.delete(peer);
|
|
27034
|
+
live.invitedAt?.delete(peer);
|
|
26858
27035
|
await this.host.closeEdge(linkId);
|
|
26859
27036
|
}
|
|
26860
27037
|
return;
|
|
@@ -26882,15 +27059,16 @@ var Communities = class {
|
|
|
26882
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;
|
|
26883
27060
|
if ((f.t === "group-secret" || f.t === "group-entry") && typeof f.to === "string" && f.to !== live.session.myKey) {
|
|
26884
27061
|
if (!live.hub) return;
|
|
26885
|
-
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}`;
|
|
26886
27065
|
if (!this.remember(live, id)) return;
|
|
26887
|
-
|
|
26888
|
-
const edges = this.host.edges(groupId), direct = edges.get(f.to);
|
|
27066
|
+
const edges = this.host.edges(groupId), direct = edges.get(routed.to);
|
|
26889
27067
|
if (direct && this.host.linkReady(direct, 2)) {
|
|
26890
|
-
this.sendTo(direct,
|
|
27068
|
+
this.sendTo(direct, routed);
|
|
26891
27069
|
return;
|
|
26892
27070
|
}
|
|
26893
|
-
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);
|
|
26894
27072
|
return;
|
|
26895
27073
|
}
|
|
26896
27074
|
if (!await live.session.handle(peerKey, frame) || !live.hub) return;
|
|
@@ -27848,13 +28026,18 @@ var MeshHubs = class {
|
|
|
27848
28026
|
}
|
|
27849
28027
|
/**
|
|
27850
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
|
|
27851
|
-
* 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.
|
|
27852
28031
|
*/
|
|
27853
28032
|
passReaction(groupId, session, from, frame) {
|
|
27854
28033
|
const live = this.live.get(groupId);
|
|
27855
|
-
if (!live
|
|
28034
|
+
if (!live) return;
|
|
27856
28035
|
const at = `${frame.k} ${frame.id}`, held = live.reactions.get(at);
|
|
27857
28036
|
if (held && held.n >= frame.n) return;
|
|
28037
|
+
if (!live.hub) {
|
|
28038
|
+
if (held) live.reactions.set(at, frame);
|
|
28039
|
+
return;
|
|
28040
|
+
}
|
|
27858
28041
|
let pace = live.reactionPace.get(frame.k);
|
|
27859
28042
|
if (!pace) live.reactionPace.set(frame.k, pace = new ReactionWindow(REACTION_LIMITS.receive, REACTION_LIMITS.windowMs));
|
|
27860
28043
|
if (!pace.take()) return;
|
|
@@ -28402,6 +28585,20 @@ function loadMarks(marks, group, history) {
|
|
|
28402
28585
|
mention: mention?.id
|
|
28403
28586
|
});
|
|
28404
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
|
+
}
|
|
28405
28602
|
/** A group gone from this engine: its marks too. */
|
|
28406
28603
|
function dropMarks(marks, groupId) {
|
|
28407
28604
|
marks.lastMessageAt.delete(groupId);
|
|
@@ -28419,18 +28616,53 @@ function newestMarked(history) {
|
|
|
28419
28616
|
};
|
|
28420
28617
|
}
|
|
28421
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
|
+
/**
|
|
28422
28650
|
* A message deleted for everyone (WISP 400 § Delete for everyone: a tombstone does not count as unread or move the
|
|
28423
28651
|
* chat): the marks it moved go back to the newest line still kept, as `load` reads them, and the record's `came` it
|
|
28424
28652
|
* raised goes too. A mark a newer line moved stays, and the history is read only when the message moved one
|
|
28425
|
-
* (`markedBy`): removals go at the pace of edits. `history`: the group's rows,
|
|
28426
|
-
*
|
|
28427
|
-
* 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.
|
|
28428
28656
|
*/
|
|
28429
28657
|
async function unmark(marks, group, groupId, history, removed, mentionOnly = false) {
|
|
28430
28658
|
const by = marks.by.get(groupId);
|
|
28431
28659
|
const last = !mentionOnly && by?.last === removed.id, peer = !mentionOnly && by?.peer === removed.id, mention = by?.mention === removed.id;
|
|
28432
28660
|
if (!by || !(last || peer || mention)) return false;
|
|
28433
|
-
const newest =
|
|
28661
|
+
const newest = await newestMarkedOf(history, MESSAGE_LINK(groupId), removed.id, {
|
|
28662
|
+
last,
|
|
28663
|
+
peer,
|
|
28664
|
+
mention
|
|
28665
|
+
});
|
|
28434
28666
|
const back = (map, row) => {
|
|
28435
28667
|
if (row) map.set(groupId, row.timestamp);
|
|
28436
28668
|
else map.delete(groupId);
|
|
@@ -28893,13 +29125,23 @@ var Groups = class {
|
|
|
28893
29125
|
this.unsaved.clear();
|
|
28894
29126
|
for (const group of due) if (this.record(group.id) === group) await this.store.putGroup(group);
|
|
28895
29127
|
}
|
|
28896
|
-
/**
|
|
28897
|
-
|
|
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) {
|
|
28898
29134
|
const all = await this.store.getGroups();
|
|
28899
29135
|
await this.rows.load(all);
|
|
28900
|
-
await this.communities.load(all.filter((g) => g.community || g.joining));
|
|
29136
|
+
await this.communities.load(all.filter((g) => g.community || g.joining), newestOnly);
|
|
28901
29137
|
for (const group of all.filter((g) => !g.community && !g.joining)) {
|
|
28902
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
|
+
}
|
|
28903
29145
|
const history = await this.store.getMessages(MESSAGE_LINK(group.id));
|
|
28904
29146
|
const framed = history.filter((m) => m.frame);
|
|
28905
29147
|
this.framesKept.set(group.id, framed.map((m) => ({
|
|
@@ -28937,6 +29179,17 @@ var Groups = class {
|
|
|
28937
29179
|
this.host.emit();
|
|
28938
29180
|
return true;
|
|
28939
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
|
+
}
|
|
28940
29193
|
record(groupId) {
|
|
28941
29194
|
return this.isCommunity(groupId) ? this.communities.record(groupId) : this.stored.get(groupId);
|
|
28942
29195
|
}
|
|
@@ -29285,7 +29538,7 @@ var Groups = class {
|
|
|
29285
29538
|
const others = group.others;
|
|
29286
29539
|
group.others = others.filter((o) => o !== other);
|
|
29287
29540
|
try {
|
|
29288
|
-
await this.forget(groupId);
|
|
29541
|
+
await this.forget(groupId, true, true);
|
|
29289
29542
|
} catch (error) {
|
|
29290
29543
|
group.others = others;
|
|
29291
29544
|
throw error;
|
|
@@ -29802,7 +30055,7 @@ var Groups = class {
|
|
|
29802
30055
|
async unmark(groupId, removed, mentionOnly = false) {
|
|
29803
30056
|
if (this.isCommunity(groupId)) return this.communities.unmark(groupId, removed, mentionOnly);
|
|
29804
30057
|
const group = this.stored.get(groupId);
|
|
29805
|
-
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);
|
|
29806
30059
|
}
|
|
29807
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. */
|
|
29808
30061
|
edgeOpen(groupId, peerKey) {
|
|
@@ -29920,14 +30173,20 @@ var Groups = class {
|
|
|
29920
30173
|
if (this.isCommunity(groupId)) return this.communities.rename(groupId, name);
|
|
29921
30174
|
await this.session(groupId).rename(name);
|
|
29922
30175
|
}
|
|
29923
|
-
/**
|
|
29924
|
-
|
|
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) {
|
|
29925
30181
|
if (this.isCommunity(groupId)) return this.communities.deleteHere(groupId);
|
|
29926
30182
|
const session = this.sessions.get(groupId);
|
|
29927
|
-
if (session?.status === "active")
|
|
29928
|
-
|
|
29929
|
-
|
|
29930
|
-
|
|
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;
|
|
29931
30190
|
}
|
|
29932
30191
|
const gone = this.stored.get(groupId), invitation = answer && gone?.invitation && !gone.invitation.entry && !gone.invitation.takenBack ? gone.invitation : void 0;
|
|
29933
30192
|
const owed = invitation && this.sayDecline(groupId, invitation.linkId);
|
|
@@ -30683,7 +30942,8 @@ var Groups = class {
|
|
|
30683
30942
|
case "group-full": {
|
|
30684
30943
|
const invitation = this.stored.get(g)?.invitation, { n, max } = frame;
|
|
30685
30944
|
if (!invitation?.entry || this.stored.get(g).state || invitation.linkId !== linkId || invitation.admin) return;
|
|
30686
|
-
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;
|
|
30687
30947
|
this.toldFull.set(g, {
|
|
30688
30948
|
n,
|
|
30689
30949
|
max,
|
|
@@ -32807,7 +33067,7 @@ var GroupEdits = class {
|
|
|
32807
33067
|
const kept = this.keptMine.get(key);
|
|
32808
33068
|
this.keptMine.delete(key);
|
|
32809
33069
|
if (this.stopped || edge === void 0 || !membership || membership.community || !membership.members.has(to)) return;
|
|
32810
|
-
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));
|
|
32811
33071
|
const last = this.heard.get(key);
|
|
32812
33072
|
const after = (m) => !last || m.edit.at > last.at || m.edit.at === last.at && m.id > last.id;
|
|
32813
33073
|
const unheard = last ? mine.filter(after).length : Math.min(mine.length, 256);
|
|
@@ -33055,6 +33315,12 @@ var CommunityPay = class {
|
|
|
33055
33315
|
id: frame.id,
|
|
33056
33316
|
ok: true
|
|
33057
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
|
+
});
|
|
33058
33324
|
}
|
|
33059
33325
|
learn(groupId, member, raw) {
|
|
33060
33326
|
const methods = methodsOf(raw);
|
|
@@ -33286,6 +33552,13 @@ var GroupLink = class {
|
|
|
33286
33552
|
id: r.id,
|
|
33287
33553
|
ok: true
|
|
33288
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(() => {});
|
|
33289
33562
|
}
|
|
33290
33563
|
};
|
|
33291
33564
|
//#endregion
|
|
@@ -35764,7 +36037,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35764
36037
|
throw Object.assign(engineError("mintUnreachable", { host: new URL(normalized).host }), { cause: error });
|
|
35765
36038
|
}
|
|
35766
36039
|
const info = wallet.getMintInfo();
|
|
35767
|
-
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;
|
|
35768
36041
|
this.names.set(normalized, name);
|
|
35769
36042
|
const bounds = (nut) => {
|
|
35770
36043
|
const method = info.isSupported(nut).params.find((m) => m.method === "bolt11" && m.unit === UNIT$1);
|
|
@@ -35777,7 +36050,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35777
36050
|
const active = wallet.keyChain.getKeysets().filter((k) => k.isActive);
|
|
35778
36051
|
this.infos.set(normalized, {
|
|
35779
36052
|
version: info.version || void 0,
|
|
35780
|
-
motd: info.motd
|
|
36053
|
+
motd: typeof info.motd === "string" ? stripHidden(info.motd).trim().slice(0, 200) || void 0 : void 0,
|
|
35781
36054
|
inputFeePpk: active.length > 0 ? Math.min(...active.map((k) => k.fee)) : 0,
|
|
35782
36055
|
receive: bounds(4),
|
|
35783
36056
|
send: bounds(5)
|
|
@@ -37438,6 +37711,23 @@ var PAYMENTS_PER_MINUTE = 10;
|
|
|
37438
37711
|
var PAYMENTS_BUSY = "Too many payments at once: send it again in a minute";
|
|
37439
37712
|
/** Refusal lines one chat gets in an hour; past it the contact is still told, and the chat stays as it is. */
|
|
37440
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
|
+
}
|
|
37441
37731
|
var INVOICE_CLAIMS_KEY = "invoicePaidClaims";
|
|
37442
37732
|
var sameClaim = (a, b) => a.linkId === b.linkId && a.invoice.toLowerCase() === b.invoice.toLowerCase();
|
|
37443
37733
|
var satsWord = (n) => `${n} sat${n === 1 ? "" : "s"}`;
|
|
@@ -37672,15 +37962,18 @@ var within = (now, at, ms) => at !== void 0 && at <= now && now - at < ms;
|
|
|
37672
37962
|
/** What a contact reads about a request of ours closed for good (`close`), when it closes and each time their chat opens again. */
|
|
37673
37963
|
var CLOSED_TOLD = "your contact removed the wallet it was paid to";
|
|
37674
37964
|
/**
|
|
37675
|
-
* How often a wallet's own refresh asks about an open Ark request (at its server's indexer
|
|
37676
|
-
*
|
|
37677
|
-
*
|
|
37678
|
-
*
|
|
37679
|
-
*
|
|
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.
|
|
37680
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,
|
|
37681
37972
|
* so money that lands late, an expired request's included, is still seen.
|
|
37682
37973
|
*/
|
|
37683
37974
|
var ARK_ASK_MS = 1e4;
|
|
37975
|
+
var BARK_ASK_MS = 1e4;
|
|
37976
|
+
var SPARK_ASK_MS = 1e4;
|
|
37684
37977
|
var USDT_ASK_MS = 8e3;
|
|
37685
37978
|
var RECEIPT_ASK_CAP_MS = INVOICE_PACE.missedCapMs;
|
|
37686
37979
|
var PaymentDesk = class {
|
|
@@ -37704,9 +37997,13 @@ var PaymentDesk = class {
|
|
|
37704
37997
|
/** Pending USDT receipts (by payment id) whose transaction the chain does not show settled yet. */
|
|
37705
37998
|
usdtAsk = new AskBackoff(USDT_ASK_MS, RECEIPT_ASK_CAP_MS);
|
|
37706
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);
|
|
37707
38002
|
checkingBitcoin = false;
|
|
37708
38003
|
redeeming = /* @__PURE__ */ new Map();
|
|
37709
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);
|
|
37710
38007
|
/** Each network's wallets: a request, a payment and a receipt all go through the wallet of their own network. */
|
|
37711
38008
|
ark;
|
|
37712
38009
|
usdt;
|
|
@@ -38184,6 +38481,11 @@ var PaymentDesk = class {
|
|
|
38184
38481
|
owns(request, linkId) {
|
|
38185
38482
|
return request.linkId === linkId || !!request.group && this.host.groupOf?.(linkId) === request.group;
|
|
38186
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
|
+
}
|
|
38187
38489
|
/**
|
|
38188
38490
|
* Why a token cannot pay a request to the group, checked before anything is redeemed: already paid, another member's
|
|
38189
38491
|
* ecash for it still being redeemed (the mint has not answered), or it would not settle it (too little, a mint the
|
|
@@ -38786,7 +39088,7 @@ var PaymentDesk = class {
|
|
|
38786
39088
|
state: "settled",
|
|
38787
39089
|
createdAt: payment.timestamp,
|
|
38788
39090
|
mint,
|
|
38789
|
-
requestId: payment.requestId
|
|
39091
|
+
requestId: this.paysRequest(payment.requestId, linkId)
|
|
38790
39092
|
});
|
|
38791
39093
|
const { amount, mint } = await this.wallet.receiveToken(token, "ecash-in", payment.memo, {
|
|
38792
39094
|
addTestMint: true,
|
|
@@ -38885,7 +39187,11 @@ var PaymentDesk = class {
|
|
|
38885
39187
|
reason
|
|
38886
39188
|
}), record.createdAt);
|
|
38887
39189
|
}
|
|
38888
|
-
async onPaymentResult(linkId,
|
|
39190
|
+
async onPaymentResult(linkId, said) {
|
|
39191
|
+
const result = {
|
|
39192
|
+
...said,
|
|
39193
|
+
error: contactReason(said.error)
|
|
39194
|
+
};
|
|
38889
39195
|
const payment = this.find(linkId, result.id);
|
|
38890
39196
|
if (payment?.target?.method === "fedimint" && payment.linkId === linkId && payment.direction === "out" && payment.kind === "payment") {
|
|
38891
39197
|
if (payment.state !== "pending") return;
|
|
@@ -39471,7 +39777,7 @@ var PaymentDesk = class {
|
|
|
39471
39777
|
return;
|
|
39472
39778
|
}
|
|
39473
39779
|
const link = this.host.getLink(linkId), request = payment.requestId ? this.payments.get(payment.requestId) : void 0;
|
|
39474
|
-
if (!link?.supportsArkPayments ||
|
|
39780
|
+
if (!link?.supportsArkPayments || request?.target?.method !== "arkade" || request.linkId !== linkId || request.direction !== "out" || request.kind !== "request") return;
|
|
39475
39781
|
const existing = this.payments.get(payment.id);
|
|
39476
39782
|
if (existing && (existing.linkId !== linkId || existing.direction !== "in" || existing.requestId !== request.id)) return;
|
|
39477
39783
|
if (existing) {
|
|
@@ -39674,26 +39980,38 @@ var PaymentDesk = class {
|
|
|
39674
39980
|
/**
|
|
39675
39981
|
* A Bark request is paid when this wallet received, on the address made for it, at least the amount asked,
|
|
39676
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.
|
|
39677
39985
|
*/
|
|
39678
|
-
async reconcileBarkReceipts() {
|
|
39986
|
+
async reconcileBarkReceipts(paced = false) {
|
|
39679
39987
|
if (this.checkingBark || !this.bark || !distinct(this.bark).some((w) => w.adapter)) return;
|
|
39680
39988
|
this.checkingBark = true;
|
|
39681
39989
|
try {
|
|
39682
|
-
const
|
|
39683
|
-
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
|
+
});
|
|
39684
39997
|
const receipts = /* @__PURE__ */ new Map();
|
|
39685
39998
|
for (const wallet of new Set(open.map((r) => bark[walletNetworkOf(r.target.network)]))) {
|
|
39686
39999
|
if (!wallet.adapter) continue;
|
|
39687
40000
|
await wallet.adapter.sync().catch(() => {});
|
|
39688
40001
|
receipts.set(wallet.adapter, await wallet.adapter.receipts().catch(() => void 0));
|
|
39689
40002
|
}
|
|
40003
|
+
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "bark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
39690
40004
|
for (const request of open) {
|
|
39691
40005
|
if (request.kind !== "request" || request.direction !== "out" || request.state !== "pending" || request.target?.method !== "bark") continue;
|
|
39692
40006
|
const adapter = this.bark[walletNetworkOf(request.target.network)].adapter;
|
|
39693
40007
|
if (!adapter || request.target.provider !== adapter.config.provider || request.target.network !== adapter.config.network) continue;
|
|
39694
|
-
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "bark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
39695
40008
|
const txid = receipts.get(adapter)?.(request.target.address, request.amount, request.createdAt, claimed);
|
|
39696
|
-
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);
|
|
39697
40015
|
await this.settleRequest(request, { txid });
|
|
39698
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({
|
|
39699
40017
|
...payment,
|
|
@@ -40021,7 +40339,7 @@ var PaymentDesk = class {
|
|
|
40021
40339
|
memo: payment.memo,
|
|
40022
40340
|
state: "pending",
|
|
40023
40341
|
createdAt: payment.timestamp,
|
|
40024
|
-
requestId: payment.requestId,
|
|
40342
|
+
requestId: this.paysRequest(payment.requestId, linkId),
|
|
40025
40343
|
federation: found.federation,
|
|
40026
40344
|
token: notes,
|
|
40027
40345
|
notesDigest: digest,
|
|
@@ -40225,23 +40543,33 @@ var PaymentDesk = class {
|
|
|
40225
40543
|
/**
|
|
40226
40544
|
* A Spark request is paid when this wallet completed a receive on the invoice made for it, of at least the amount
|
|
40227
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.
|
|
40228
40548
|
*/
|
|
40229
|
-
async reconcileSparkReceipts() {
|
|
40549
|
+
async reconcileSparkReceipts(paced = false) {
|
|
40230
40550
|
const spark = this.spark;
|
|
40231
40551
|
if (this.checkingSpark || !spark || !distinct(spark).some((s) => s.ready())) return;
|
|
40232
40552
|
this.checkingSpark = true;
|
|
40233
40553
|
try {
|
|
40234
|
-
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)));
|
|
40235
40558
|
const networks = new Set(open.map((r) => walletNetworkOf(r.target.network)));
|
|
40236
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));
|
|
40237
40561
|
for (const request of open) {
|
|
40238
40562
|
const current = this.current(request);
|
|
40239
40563
|
if (current.state !== "pending" || !current.target) continue;
|
|
40240
40564
|
const wallet = spark[walletNetworkOf(current.target.network)];
|
|
40241
40565
|
if (!wallet.ready()) continue;
|
|
40242
|
-
const claimed = new Set([...this.payments.values()].filter((p) => p.target?.method === "spark" && p.kind === "request" && p.txid).map((p) => p.txid));
|
|
40243
40566
|
const id = await wallet.received(current.target, current.amount, current.createdAt, claimed).catch(() => void 0);
|
|
40244
|
-
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);
|
|
40245
40573
|
await this.settleRequest(current, { txid: id });
|
|
40246
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({
|
|
40247
40575
|
...payment,
|
|
@@ -41271,6 +41599,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41271
41599
|
}
|
|
41272
41600
|
/** The chats found saved at start that this run leaves unstarted (`NodeOptions.deferChats`). */
|
|
41273
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();
|
|
41274
41604
|
transport;
|
|
41275
41605
|
/** The same, for groups' requests: a relay budget keeps a chat's share from them (`CHAT_RESERVE`). */
|
|
41276
41606
|
groupTransport;
|
|
@@ -41456,6 +41786,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41456
41786
|
/** `group-wake` frames read per edge, a handful a minute. */
|
|
41457
41787
|
groupWakeReceived = /* @__PURE__ */ new Map();
|
|
41458
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();
|
|
41459
41791
|
/** A request only moves a counter: the counts go out with the next state, at most once a `REQUEST_COUNTS_MS`. */
|
|
41460
41792
|
requestCountsTimer;
|
|
41461
41793
|
transfers = /* @__PURE__ */ new Map();
|
|
@@ -41567,7 +41899,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41567
41899
|
}));
|
|
41568
41900
|
barkWallets = perNetwork((network) => new BarkWallet(network, (viewChanged = true) => {
|
|
41569
41901
|
if (viewChanged) this.walletChanged();
|
|
41570
|
-
this.desk.reconcileBarkReceipts().catch(() => {});
|
|
41902
|
+
this.desk.reconcileBarkReceipts(!viewChanged).catch(() => {});
|
|
41571
41903
|
}));
|
|
41572
41904
|
fedimintWallets = perNetwork((network) => new FedimintWallet(network, {
|
|
41573
41905
|
changed: () => this.walletChanged(),
|
|
@@ -41575,7 +41907,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41575
41907
|
}, () => (this.options.fedimintSdk ?? loadFedimintSdk)()));
|
|
41576
41908
|
sparkWallets = perNetwork((network) => new SparkWallet(network, (viewChanged = true) => {
|
|
41577
41909
|
if (viewChanged) this.walletChanged();
|
|
41578
|
-
this.desk.reconcileSparkReceipts().catch(() => {});
|
|
41910
|
+
this.desk.reconcileSparkReceipts(!viewChanged).catch(() => {});
|
|
41579
41911
|
}));
|
|
41580
41912
|
/** What a call naming no network acts on (a caller from before wallets had their own): Mainnet. */
|
|
41581
41913
|
net(network) {
|
|
@@ -41905,6 +42237,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41905
42237
|
if (!live) return "unknown chat";
|
|
41906
42238
|
if (live.files.wireIds.has(wire.wireId)) return "duplicate file id";
|
|
41907
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";
|
|
41908
42241
|
const file = {
|
|
41909
42242
|
id: `${linkId}-in-${toBase64Url(randomBytes(12))}`,
|
|
41910
42243
|
name: wire.name,
|
|
@@ -42374,6 +42707,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42374
42707
|
believed: (chat, by) => {
|
|
42375
42708
|
const membership = this.membership(chat.slice(6));
|
|
42376
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;
|
|
42377
42714
|
}
|
|
42378
42715
|
});
|
|
42379
42716
|
/**
|
|
@@ -43047,10 +43384,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43047
43384
|
const links = await db.getLinks();
|
|
43048
43385
|
if (this.options.deferChats) {
|
|
43049
43386
|
for (const stored of links) if (!stored.group) this.deferredChats.add(stored.id);
|
|
43387
|
+
else if (!stored.groupEntry) this.deferredGroups.add(stored.group);
|
|
43050
43388
|
}
|
|
43051
43389
|
for (const stored of links) if (stored.group) this.links.set(stored.id, newLiveLink(stored, 0, linkFilesFrom(stored.id, [], [])));
|
|
43052
43390
|
for (const group of await db.getGroups()) await this.settleHistory(`group:${group.id}`);
|
|
43053
|
-
await this.groups.load(this.limitedMode);
|
|
43391
|
+
await this.groups.load(this.limitedMode, !!this.options.offline);
|
|
43054
43392
|
this.groupsLoaded = true;
|
|
43055
43393
|
this.groupsLoadedNow();
|
|
43056
43394
|
this.emitState();
|
|
@@ -43736,7 +44074,35 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43736
44074
|
appDataExportText(params) {
|
|
43737
44075
|
return this.appStore.exportDataText(params);
|
|
43738
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. */
|
|
43739
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
|
+
};
|
|
43740
44106
|
const groups = this.groups.views();
|
|
43741
44107
|
const edges = this.edgesByMember();
|
|
43742
44108
|
return {
|
|
@@ -43759,7 +44125,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43759
44125
|
...this.clock.offset !== null && { clockOffMs: this.clock.offset },
|
|
43760
44126
|
...!this.contactRtc() && !Object.keys(this.nativeFactories).length && { groupLinks: false }
|
|
43761
44127
|
},
|
|
43762
|
-
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),
|
|
43763
44129
|
services: this.services.map((s) => ({
|
|
43764
44130
|
...s,
|
|
43765
44131
|
requests: this.requestCounts.get(s.id) ?? 0
|
|
@@ -43775,7 +44141,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43775
44141
|
contactRequests: this.contactLinks.requests(),
|
|
43776
44142
|
contactAsks: this.contactAsks.views(),
|
|
43777
44143
|
nostr: this.nostrSocial.state(),
|
|
43778
|
-
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)],
|
|
43779
44145
|
groups: groups.map((group) => ({
|
|
43780
44146
|
...group,
|
|
43781
44147
|
...this.groupAdminOff.has(group.id) && { adminOff: true },
|
|
@@ -44823,7 +45189,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44823
45189
|
label: clean
|
|
44824
45190
|
};
|
|
44825
45191
|
db.patchLink(linkId, { label: live.stored.label });
|
|
44826
|
-
this.
|
|
45192
|
+
this.chatChanged(linkId);
|
|
44827
45193
|
}
|
|
44828
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. */
|
|
44829
45195
|
setActiveLink({ linkId }) {
|
|
@@ -46121,7 +46487,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46121
46487
|
};
|
|
46122
46488
|
await db.patchLink(linkId, { peerSpoke: true }).catch(() => {});
|
|
46123
46489
|
}
|
|
46124
|
-
if (message?.paymentId && message.delivery
|
|
46490
|
+
if (message?.paymentId && message.delivery && message.delivery !== "sent" && message.delivery !== "delivered") await this.desk.withdraw(message.paymentId).catch(() => {});
|
|
46125
46491
|
if (message?.paymentId && message.sender === "peer") await this.desk.dropReceipt(message.paymentId).catch(() => {});
|
|
46126
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));
|
|
46127
46493
|
if (message?.file) {
|
|
@@ -46215,6 +46581,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46215
46581
|
if (this.transfers.get(file.id)?.state === "transferring") return;
|
|
46216
46582
|
const wireId = file.id.slice(`${linkId}-out-`.length);
|
|
46217
46583
|
if (file.id !== GhostlyNode.outgoingFileId(linkId, wireId)) return refuse("Invalid file id");
|
|
46584
|
+
this.setTyping({
|
|
46585
|
+
linkId,
|
|
46586
|
+
typing: false
|
|
46587
|
+
});
|
|
46218
46588
|
const holdable = file.size <= HOLD_LIMITS.maxBundleBytes - 4096;
|
|
46219
46589
|
if (!live.link.isDataLinkOpen) this.wakePeer(live);
|
|
46220
46590
|
if (!GhostlyNode.takesFiles(live.link) && this.holdingFor(live) && holdable) {
|
|
@@ -47864,10 +48234,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47864
48234
|
await db.patchLink(linkId, { pinOut: void 0 });
|
|
47865
48235
|
}
|
|
47866
48236
|
/**
|
|
47867
|
-
* A
|
|
47868
|
-
* 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.
|
|
47869
48240
|
*/
|
|
47870
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
|
+
}
|
|
47871
48249
|
const live = this.links.get(linkId), pin = live?.stored.pin;
|
|
47872
48250
|
if (!live || live.stored.group || !pin?.id || pin.messageId || pin.removed) return;
|
|
47873
48251
|
for (const id of new Set(ids)) {
|
|
@@ -48081,7 +48459,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48081
48459
|
this.peerStatusTimers.set(linkId, setTimeout(() => {
|
|
48082
48460
|
this.peerStatusTimers.delete(linkId);
|
|
48083
48461
|
if (until > Date.now()) this.redrawAtStatusEnd(linkId, until);
|
|
48084
|
-
else this.
|
|
48462
|
+
else this.chatChanged(linkId);
|
|
48085
48463
|
}, Math.min(until - Date.now() + 1, GhostlyNode.TIMER_MAX_MS)));
|
|
48086
48464
|
}
|
|
48087
48465
|
/**
|
|
@@ -48971,10 +49349,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48971
49349
|
async sendPayment(params) {
|
|
48972
49350
|
const live = await this.linkWhenAdded(params.linkId);
|
|
48973
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.");
|
|
48974
|
-
|
|
49352
|
+
const sent = await this.desk.send({
|
|
48975
49353
|
...params,
|
|
48976
49354
|
network: this.net(params.network)
|
|
48977
49355
|
});
|
|
49356
|
+
this.setTyping({
|
|
49357
|
+
linkId: params.linkId,
|
|
49358
|
+
typing: false
|
|
49359
|
+
});
|
|
49360
|
+
return sent;
|
|
48978
49361
|
}
|
|
48979
49362
|
/** `network`: the card's network; the request is paid only by a wallet of that network. */
|
|
48980
49363
|
/** `card`: the Lightning card the request's invoice comes from; absent, the network's default for receiving. */
|
|
@@ -50207,9 +50590,17 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50207
50590
|
this.requestCountsTimer = void 0;
|
|
50208
50591
|
this.emitState();
|
|
50209
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
|
+
});
|
|
50210
50600
|
return {
|
|
50211
50601
|
id,
|
|
50212
|
-
target
|
|
50602
|
+
target,
|
|
50603
|
+
revoked: grant.revoke.signal
|
|
50213
50604
|
};
|
|
50214
50605
|
} catch {
|
|
50215
50606
|
return;
|
|
@@ -50350,7 +50741,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50350
50741
|
}
|
|
50351
50742
|
startEdge(linkId) {
|
|
50352
50743
|
const live = this.links.get(linkId);
|
|
50353
|
-
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;
|
|
50354
50745
|
const { stored } = live;
|
|
50355
50746
|
const group = stored.group, peer = stored.groupPeer, entry = !!stored.groupEntry;
|
|
50356
50747
|
const role = stored.groupEntry ?? "edge";
|
|
@@ -50687,6 +51078,16 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50687
51078
|
if (!this.deferredChats.delete(linkId)) return;
|
|
50688
51079
|
if (this.networkOn && !this.shuttingDown) this.startLink(linkId);
|
|
50689
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
|
+
}
|
|
50690
51091
|
startLink(linkId) {
|
|
50691
51092
|
const live = this.links.get(linkId);
|
|
50692
51093
|
if (!live || live.link || this.deferredChats.has(linkId)) return;
|
|
@@ -50926,7 +51327,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50926
51327
|
const was = live.status, synced = live.lastSyncAt;
|
|
50927
51328
|
live.status = status;
|
|
50928
51329
|
if (status === "online") live.lastSyncAt = Date.now();
|
|
50929
|
-
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);
|
|
50930
51331
|
},
|
|
50931
51332
|
onPoll: ({ polling, nextInMs }) => {
|
|
50932
51333
|
const was = live.poll.polling, first = !live.lastSyncAt && !live.firstReadDone;
|
|
@@ -50936,7 +51337,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50936
51337
|
interval: nextInMs || live.poll.interval
|
|
50937
51338
|
};
|
|
50938
51339
|
if (was && !polling) live.firstReadDone = true;
|
|
50939
|
-
if (linkId === this.activeLinkId || first && polling !== was) this.
|
|
51340
|
+
if (linkId === this.activeLinkId || first && polling !== was) this.chatChanged(linkId);
|
|
50940
51341
|
},
|
|
50941
51342
|
onMessageReceipt: async (id) => {
|
|
50942
51343
|
const oneToOne = !!stored.profile && !stored.group;
|
|
@@ -50961,13 +51362,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50961
51362
|
peerWake: target ?? void 0
|
|
50962
51363
|
};
|
|
50963
51364
|
db.patchLink(linkId, { peerWake: target ?? void 0 });
|
|
50964
|
-
this.
|
|
51365
|
+
this.chatChanged(linkId);
|
|
50965
51366
|
},
|
|
50966
51367
|
onPeerAck: (ack) => {
|
|
50967
51368
|
if (stored.profile) return;
|
|
50968
|
-
if (ack
|
|
51369
|
+
if (ack <= live.peerAck) return;
|
|
50969
51370
|
live.peerAck = ack;
|
|
50970
|
-
this.
|
|
51371
|
+
this.chatChanged(linkId);
|
|
50971
51372
|
},
|
|
50972
51373
|
onDirectEvidence: (evidence) => this.directPath.note(stored.peerPubKeyZ32, evidence),
|
|
50973
51374
|
onPeerClock: (packetAt, readBefore, readAt) => {
|
|
@@ -51006,7 +51407,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51006
51407
|
peerAvatar: avatar ?? void 0
|
|
51007
51408
|
};
|
|
51008
51409
|
db.patchLink(linkId, { peerAvatar: avatar ?? void 0 });
|
|
51009
|
-
this.
|
|
51410
|
+
this.chatChanged(linkId);
|
|
51010
51411
|
},
|
|
51011
51412
|
onPeerNick: (nick) => {
|
|
51012
51413
|
if ((nick ?? "") === live.stored.peerNick) return;
|
|
@@ -51015,7 +51416,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51015
51416
|
peerNick: nick ?? ""
|
|
51016
51417
|
};
|
|
51017
51418
|
db.patchLink(linkId, { peerNick: nick ?? "" });
|
|
51018
|
-
this.
|
|
51419
|
+
this.chatChanged(linkId);
|
|
51019
51420
|
},
|
|
51020
51421
|
onPresence: (presence) => {
|
|
51021
51422
|
let same = samePresence(live.presence, presence);
|
|
@@ -51032,7 +51433,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51032
51433
|
db.patchLink(linkId, { peerNick: presence.nick });
|
|
51033
51434
|
same = false;
|
|
51034
51435
|
}
|
|
51035
|
-
if (!same) this.
|
|
51436
|
+
if (!same) this.chatChanged(linkId);
|
|
51036
51437
|
},
|
|
51037
51438
|
onMessage: (message) => {
|
|
51038
51439
|
if (live.stored.inviteCode) {
|
|
@@ -51059,9 +51460,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51059
51460
|
});
|
|
51060
51461
|
},
|
|
51061
51462
|
onCallSignal: (signal) => this.events.onCallSignal(linkId, signal),
|
|
51062
|
-
onPeerTyping: () => this.
|
|
51463
|
+
onPeerTyping: () => this.chatChanged(linkId),
|
|
51063
51464
|
onPeerStatus: (state) => {
|
|
51064
|
-
this.
|
|
51465
|
+
this.chatChanged(linkId);
|
|
51065
51466
|
this.redrawAtStatusEnd(linkId, state.status?.until);
|
|
51066
51467
|
},
|
|
51067
51468
|
onReaction: async (reaction) => await this.reactions.receive(linkId, "peer", reaction) !== "dropped",
|
|
@@ -51264,7 +51665,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51264
51665
|
nativeFactoriesFor(relayOnly) {
|
|
51265
51666
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
51266
51667
|
return {
|
|
51267
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
51668
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-Dz7pvcBA.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
51268
51669
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
51269
51670
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
51270
51671
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, {
|
|
@@ -51734,16 +52135,19 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51734
52135
|
};
|
|
51735
52136
|
}
|
|
51736
52137
|
if (this.shuttingDown || live.link !== link) return false;
|
|
51737
|
-
const
|
|
51738
|
-
const
|
|
51739
|
-
|
|
51740
|
-
|
|
51741
|
-
|
|
51742
|
-
|
|
51743
|
-
|
|
51744
|
-
|
|
51745
|
-
|
|
51746
|
-
|
|
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
|
+
}
|
|
51747
52151
|
const starting = factory(seed);
|
|
51748
52152
|
const endpoint = await Promise.race([starting, this.stopping]);
|
|
51749
52153
|
if (!endpoint) {
|
|
@@ -52221,6 +52625,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52221
52625
|
return false;
|
|
52222
52626
|
}
|
|
52223
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
|
+
}
|
|
52224
52634
|
for (const live of this.links.values()) live.link?.refreshServices();
|
|
52225
52635
|
this.emitState();
|
|
52226
52636
|
}
|
|
@@ -52335,6 +52745,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52335
52745
|
* that may not wait as long as the snapshot already due (a new file behind another's progress) brings it forward.
|
|
52336
52746
|
*/
|
|
52337
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) {
|
|
52338
52757
|
if (this.gatedOut) return;
|
|
52339
52758
|
const due = Date.now() + delayMs;
|
|
52340
52759
|
if (this.stateTimer) {
|
|
@@ -52345,7 +52764,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52345
52764
|
this.stateTimer = setTimeout(() => {
|
|
52346
52765
|
this.stateTimer = null;
|
|
52347
52766
|
if (this.gatedOut) return;
|
|
52348
|
-
this.events.onState(this.
|
|
52767
|
+
this.events.onState(this.pushedState());
|
|
52349
52768
|
this.dropBriefViews();
|
|
52350
52769
|
if (this.deviceLinks) this.syncDeviceTokens();
|
|
52351
52770
|
}, delayMs);
|
|
@@ -52408,6 +52827,12 @@ var EngineServer = class {
|
|
|
52408
52827
|
/** How many history changes the engine told; per chat or group, the count at its last one (`historyMark`). */
|
|
52409
52828
|
changes = 0;
|
|
52410
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;
|
|
52411
52836
|
/**
|
|
52412
52837
|
* An attention event while no client is attached to hear it: the host tells the person itself. The extension's peer
|
|
52413
52838
|
* runs with no tab open, and a message that came then showed nothing until Ghostly was opened.
|
|
@@ -52487,6 +52912,10 @@ var EngineServer = class {
|
|
|
52487
52912
|
* not changed since is not read and sent again: the client hears only what changes in it from now on.
|
|
52488
52913
|
* `newest`: each chat's newest rows that many (`messagePage`), not its whole history, which the client asks for when
|
|
52489
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.
|
|
52490
52919
|
*/
|
|
52491
52920
|
attach(client, read, scope = {}) {
|
|
52492
52921
|
this.clients.add(client);
|
|
@@ -52497,6 +52926,7 @@ var EngineServer = class {
|
|
|
52497
52926
|
this.histories.set(client, sent);
|
|
52498
52927
|
if (scope.newest) this.newest.set(client, scope.newest);
|
|
52499
52928
|
else this.newest.delete(client);
|
|
52929
|
+
const since = scope.since?.epoch === this.epoch && typeof scope.since.mark === "number" ? scope.since.mark : void 0;
|
|
52500
52930
|
this.ready.then(async () => {
|
|
52501
52931
|
if (!this.clients.has(client)) return;
|
|
52502
52932
|
client.post({
|
|
@@ -52509,14 +52939,29 @@ var EngineServer = class {
|
|
|
52509
52939
|
signal
|
|
52510
52940
|
});
|
|
52511
52941
|
else this.offers.delete(linkId);
|
|
52942
|
+
const skipped = [];
|
|
52512
52943
|
for (const link of this.node.getState().links) {
|
|
52513
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
|
+
}
|
|
52514
52949
|
await this.inOrder(link.id, async () => {
|
|
52515
52950
|
if (!this.clients.has(client)) return;
|
|
52516
52951
|
client.post(scope.newest ? await this.newestOf(link.id, scope.newest) : this.historyEvent(link.id, await this.node.getMessages(link.id)));
|
|
52517
52952
|
this.histories.get(client)?.add(link.id);
|
|
52518
52953
|
});
|
|
52519
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
|
+
});
|
|
52520
52965
|
}, (error) => {
|
|
52521
52966
|
this.post(client, {
|
|
52522
52967
|
kind: "start-failed",
|
|
@@ -52532,6 +52977,7 @@ var EngineServer = class {
|
|
|
52532
52977
|
detach(client) {
|
|
52533
52978
|
this.clients.delete(client);
|
|
52534
52979
|
this.histories.delete(client);
|
|
52980
|
+
this.marking.delete(client);
|
|
52535
52981
|
if (this.clients.size === 0) {
|
|
52536
52982
|
this.node.setActiveLink({ linkId: null });
|
|
52537
52983
|
this.node.appsCloseAll();
|
|
@@ -52613,6 +53059,31 @@ var EngineServer = class {
|
|
|
52613
53059
|
}
|
|
52614
53060
|
changed(linkId) {
|
|
52615
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
|
+
}
|
|
52616
53087
|
}
|
|
52617
53088
|
track(linkId, running) {
|
|
52618
53089
|
const settled = running.catch(() => {});
|
|
@@ -52715,4 +53186,4 @@ function signalKind(signal) {
|
|
|
52715
53186
|
//#endregion
|
|
52716
53187
|
export { EngineServer };
|
|
52717
53188
|
|
|
52718
|
-
//# sourceMappingURL=server-
|
|
53189
|
+
//# sourceMappingURL=server-C1jZZ61O.js.map
|