@ghostlytools/cli 1.10.5 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -22
- package/SKILL.md +8 -5
- package/dist/assets/api-B-52sVYp.js +3 -0
- package/dist/assets/{api-DppWqAP3.js → api-CTqIcdu7.js} +532 -197
- package/dist/assets/api-CTqIcdu7.js.map +1 -0
- package/dist/assets/{apiKit-DFIho4Ev.js → apiKit-CZq4Lq4f.js} +97 -13
- package/dist/assets/apiKit-CZq4Lq4f.js.map +1 -0
- package/dist/assets/{apps-yBnbEtfV.js → apps-C_X0zgSG.js} +16 -4
- package/dist/assets/apps-C_X0zgSG.js.map +1 -0
- package/dist/assets/{apps-1MkGMH8m.js → apps-kRsY9S2S.js} +1 -1
- package/dist/assets/{arkade-bFAS6imn.js → arkade-_aaB7VbW.js} +2 -2
- package/dist/assets/{arkade-bFAS6imn.js.map → arkade-_aaB7VbW.js.map} +1 -1
- package/dist/assets/{backup-ejIX59o7.js → backup-DBg388Ke.js} +1 -1
- package/dist/assets/{backup-vj4J7M3e.js → backup-OTvrmk-w.js} +35 -7
- package/dist/assets/backup-OTvrmk-w.js.map +1 -0
- package/dist/assets/{blobFiles-XZ9PEXYy.js → blobFiles-BmsrvZc3.js} +3 -3
- package/dist/assets/{blobFiles-XZ9PEXYy.js.map → blobFiles-BmsrvZc3.js.map} +1 -1
- package/dist/assets/buttons-4EKtQl-7.js +2 -0
- package/dist/assets/{buttons-BoDMx3Ky.js → buttons-DUu7hxxT.js} +61 -30
- package/dist/assets/buttons-DUu7hxxT.js.map +1 -0
- package/dist/assets/{client-BQArefYa.js → client-DDpZP1R1.js} +55 -10
- package/dist/assets/client-DDpZP1R1.js.map +1 -0
- package/dist/assets/{codec-_MwTUz5E.js → codec-DrryGcPT.js} +2 -2
- package/dist/assets/{codec-_MwTUz5E.js.map → codec-DrryGcPT.js.map} +1 -1
- package/dist/assets/{envelope-CeZBNGX-.js → envelope-Q_rMgoE9.js} +2 -2
- package/dist/assets/{envelope-CeZBNGX-.js.map → envelope-Q_rMgoE9.js.map} +1 -1
- package/dist/assets/{irohWeb-C_Wnw7Q9.js → fedimintSdk-CqTeMdF0.js} +2 -354
- package/dist/assets/fedimintSdk-CqTeMdF0.js.map +1 -0
- package/dist/assets/{fileBytes-DqnfKIkj.js → fileBytes-B0z9A6Le.js} +2 -2
- package/dist/assets/{fileBytes-DqnfKIkj.js.map → fileBytes-B0z9A6Le.js.map} +1 -1
- package/dist/assets/{fileBytes-BABGEF13.js → fileBytes-BLPZq9YU.js} +3 -3
- package/dist/assets/{fileBytes-BABGEF13.js.map → fileBytes-BLPZq9YU.js.map} +1 -1
- package/dist/assets/{fileBytes-CQQK2uOh.js → fileBytes-BtIyoDF2.js} +1 -1
- package/dist/assets/{fileBytesIdb-DrXmDUSy.js → fileBytesIdb-Bmlrl9EO.js} +3 -3
- package/dist/assets/{fileBytesIdb-DrXmDUSy.js.map → fileBytesIdb-Bmlrl9EO.js.map} +1 -1
- package/dist/assets/fileBytesIdb-D8mAK4pF.js +2 -0
- package/dist/assets/{fileBytesOpfs-udKCzcLe.js → fileBytesOpfs-DBS0kbPT.js} +3 -3
- package/dist/assets/{fileBytesOpfs-udKCzcLe.js.map → fileBytesOpfs-DBS0kbPT.js.map} +1 -1
- package/dist/assets/{fixedHosts-B_2Rvyja.js → fixedHosts-BV5GDiTU.js} +3 -3
- package/dist/assets/{fixedHosts-B_2Rvyja.js.map → fixedHosts-BV5GDiTU.js.map} +1 -1
- package/dist/assets/{host-DFLzzKNr.js → host-BlUzZgQL.js} +336 -84
- package/dist/assets/host-BlUzZgQL.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js → hyperdhtRelay-BvI_uNZO.js} +2 -2
- package/dist/assets/{hyperdhtRelay-CV6qMrom.js.map → hyperdhtRelay-BvI_uNZO.js.map} +1 -1
- package/dist/assets/{idb-BHsAqENE.js → idb-CEuoNsTv.js} +16 -5
- package/dist/assets/idb-CEuoNsTv.js.map +1 -0
- package/dist/assets/{groupFiles-D-ZUUHrx.js → irohWeb-CqPN8VPY.js} +469 -16
- package/dist/assets/irohWeb-CqPN8VPY.js.map +1 -0
- package/dist/assets/{main-xO8MnXxD.js → main-vQjlgEnt.js} +409 -126
- package/dist/assets/main-vQjlgEnt.js.map +1 -0
- package/dist/assets/{mainline-Bx184Ixg.js → mainline-p6HOW7sb.js} +2 -2
- package/dist/assets/{mainline-Bx184Ixg.js.map → mainline-p6HOW7sb.js.map} +1 -1
- package/dist/assets/{networkReason-BlQhTbXk.js → networkReason-DMffkiJ6.js} +4 -4
- package/dist/assets/{networkReason-BlQhTbXk.js.map → networkReason-DMffkiJ6.js.map} +1 -1
- package/dist/assets/{nwc-B3-PHX0L.js → nwc-2vH18oNy.js} +4 -4
- package/dist/assets/nwc-2vH18oNy.js.map +1 -0
- package/dist/assets/{nwcProvider-BeQBPB2q.js → nwcProvider-DpeDy0bV.js} +11 -3
- package/dist/assets/nwcProvider-DpeDy0bV.js.map +1 -0
- package/dist/assets/{ownDid-DAzW-Urb.js → ownDid-iKz8u_fM.js} +2 -2
- package/dist/assets/{ownDid-DAzW-Urb.js.map → ownDid-iKz8u_fM.js.map} +1 -1
- package/dist/assets/{words-BvdNuw_v.js → ownStatus-BlRKnM5F.js} +56 -4
- package/dist/assets/ownStatus-BlRKnM5F.js.map +1 -0
- package/dist/assets/{profiles-Bg43mRXu.js → profiles-B5e0TyvS.js} +22 -12
- package/dist/assets/profiles-B5e0TyvS.js.map +1 -0
- package/dist/assets/{registry-CAk2-5BQ.js → registry-Cc_PQb3k.js} +1 -1
- package/dist/assets/{registry-BDnsZJBi.js → registry-CnFO2Pp5.js} +123 -99
- package/dist/assets/registry-CnFO2Pp5.js.map +1 -0
- package/dist/assets/{resolve-UAfshn6j.js → resolve-DI8uAM_Y.js} +2 -2
- package/dist/assets/{resolve-UAfshn6j.js.map → resolve-DI8uAM_Y.js.map} +1 -1
- package/dist/assets/{restoredRows-YhlbokEE.js → restoredRows-C3LcxmOw.js} +4 -4
- package/dist/assets/{restoredRows-YhlbokEE.js.map → restoredRows-C3LcxmOw.js.map} +1 -1
- package/dist/assets/{server-DYdR0_Fj.js → server-DdtPxkqI.js} +2057 -655
- package/dist/assets/server-DdtPxkqI.js.map +1 -0
- package/dist/assets/{src-BTRPAi5X.js → src-BnpEQqzk.js} +813 -144
- package/dist/assets/src-BnpEQqzk.js.map +1 -0
- package/dist/assets/{sshForges-KtHK5x1x.js → sshForges-cdIAraDw.js} +2 -2
- package/dist/assets/{sshForges-KtHK5x1x.js.map → sshForges-cdIAraDw.js.map} +1 -1
- package/dist/assets/{translate-CYuygrvA.js → translate-kNopA04L.js} +2 -2
- package/dist/assets/{translate-CYuygrvA.js.map → translate-kNopA04L.js.map} +1 -1
- package/dist/assets/{usdt-Dw9IENe_.js → usdt-CDaLhEYh.js} +3 -3
- package/dist/assets/{usdt-Dw9IENe_.js.map → usdt-CDaLhEYh.js.map} +1 -1
- package/dist/assets/{waitNotice-Ce3YCinu.js → waitNotice-Cn0WJ-He.js} +3 -1
- package/dist/assets/waitNotice-Cn0WJ-He.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/claude-code-agent.sh +5 -0
- package/package.json +2 -2
- package/dist/assets/api-DppWqAP3.js.map +0 -1
- package/dist/assets/api-K-i5MrP-.js +0 -3
- package/dist/assets/apiKit-DFIho4Ev.js.map +0 -1
- package/dist/assets/apps-yBnbEtfV.js.map +0 -1
- package/dist/assets/backup-vj4J7M3e.js.map +0 -1
- package/dist/assets/buttons-BoDMx3Ky.js.map +0 -1
- package/dist/assets/buttons-DG1CKgAI.js +0 -2
- package/dist/assets/client-BQArefYa.js.map +0 -1
- package/dist/assets/fileBytesIdb-BtXATa7j.js +0 -2
- package/dist/assets/groupFiles-D-ZUUHrx.js.map +0 -1
- package/dist/assets/host-DFLzzKNr.js.map +0 -1
- package/dist/assets/idb-BHsAqENE.js.map +0 -1
- package/dist/assets/irohWeb-C_Wnw7Q9.js.map +0 -1
- package/dist/assets/main-xO8MnXxD.js.map +0 -1
- package/dist/assets/nwc-B3-PHX0L.js.map +0 -1
- package/dist/assets/nwcProvider-BeQBPB2q.js.map +0 -1
- package/dist/assets/profiles-Bg43mRXu.js.map +0 -1
- package/dist/assets/registry-BDnsZJBi.js.map +0 -1
- package/dist/assets/server-DYdR0_Fj.js.map +0 -1
- package/dist/assets/src-BTRPAi5X.js.map +0 -1
- package/dist/assets/waitNotice-Ce3YCinu.js.map +0 -1
- package/dist/assets/words-BvdNuw_v.js.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $
|
|
2
|
+
import { $c as contactAskerFrame, $i as emptyProofLedger, $l as OwnInviteError, $n as engineError, $o as RATCHET_CAPABILITY, $s as handoffContext, $t as ONCHAIN_PROVIDER, A as knockIdentity, Aa as DHT_MESSAGE_TTL, Ai as STATUS_CARD_CAPABILITY, Al as appRefPublisher, An as ENDPOINT, Ar as lobbyKeys, Au as turnKeys, Bc as readEnrollGrant, Bn as NO_PICTURE_METADATA, Bo as heardTime, Br as shouldBeHub, Bs as HANDOFF_OFFER, Bu as currentRelays, C as communityHasFrame, Ci as isServeId, Cr as pickMeshHubs, Cu as TURN_MAX, D as decodeGroupEntryLink, Dc as signTombstone, Di as APPS_CAPABILITY, Dl as APP_STATEMENT_LIMITS, Dr as doorHubs, Ds as contactRtcConfig, Du as signTurnPacket, Ec as setUpdateFrame, Ei as isAppVersion, Eo as STATUS_CARD_LIMITS, Er as beaconRecords, Eu as readTurnPacket, F as GroupWakeLimiter, Fa as sanitizeFileName, Fc as enrollDigits, Fi as dialDescriptors, Fl as isAppRef, Fn as parseCashuRequestPayload, Fr as pickHubs, Fs as HANDOFF_ACK, Gc as inboxRecord, Gl as canonicalJsonBytes, Gn as GhostLink, Gr as transferEnded, Gs as HANDOFF_VERIFIED, Gt as didDhtDocument, H as GroupSession, Ha as fileMessageText, Hc as verifyEnrollProof, Hl as parseImageMeta, Hn as isStrippedPicture, Ho as shownTime, Hr as FILE_LIMITS, Hs as HANDOFF_PIECE_BYTES, I as groupWakeFrame, Ia as sanitizeMime, Ic as enrollDoneFrame, Il as readAppRevocation, In as parseFedimintRequestPayload, Io as statusCardText, Ir as rankHubs, Is as HANDOFF_CANCEL, J as meshMessageRef, Ja as EDIT_RATE_WINDOW_MS, Jc as settleRequest, Jl as encodeContactLink, Jn as PAIRED_FRAME_TOO_LARGE, Jo as parseGroupCommit, Jr as STATUS_IDLE_AFTER_MS, Js as handoffAttemptAllowed, Jt as encodeDidDhtPacket, Ju as withRequestOptions, K as GROUP_EDIT_TEXT_BYTES, Ka as parseVideoMeta, Kc as newInbox, Kl as readCanonicalJson, Kn as INVITE_TAKEN, Ko as MEMBER_KEY, Kr as transferStalled, Ks as NO_ATTEMPTS, Kt as didDhtFromPublicKey, Ku as budgetRetryMs, L as groupWakes, Lc as enrollGrantFrame, Ll as readAppRevocationShape, Lr as readBeacon, Ls as HANDOFF_DONE, Lu as RelayTransport, M as mergeKnocks, Ma as DHT_FILE_CAPABILITY, Mi as CapsExchange, Ml as isAppHash, Mn as fedimintRequestPayload, Mr as mergeBeacon, Ms as HTTP_SERVICE_PROTO, Mu as turnStatedVerifier, N as readKnocks, Na as dhtFileId, Nc as enrollCancelFrame, Ni as DHT_TEXT_CAPABILITY, Nl as isAppKey, Nn as findEndpoint, No as checkStatusCard, Nr as mergeLobby, Ns as LEGACY_SERVICES, Nu as turnVerifierMark, O as encodeGroupEntryLink, Oc as verifySetUpdate, Oi as BUTTONS_CAPABILITY, Ol as appFingerprint, Or as freshHubs, Ou as signTurnRelease, Pa as formatFileSize, Pc as enrollCancelReason, Pi as capsDescriptors, Pn as isFederationId, Po as sameButtonText, Pr as newerHead, Ps as serviceIdFromName, Pu as DEFAULT_RELAYS, Qa as dhtEditId, Qc as REQUEST_LIFETIME_MS, Qi as PeerProofs, Ql as readDeviceInvite, Qn as EngineError, Qo as edgeParams, Qs as handoffCancelFrame, Qt as EVM_TEST_CHAINS, R as parseGroupWakeFrame, Rc as enrollHelloFrame, Rn as videoMetadataPatches, Ro as arrivalKey, Rr as readBeaconHead, Rs as HANDOFF_HAVE, S as GROUP_READ_NOTE_COMMUNITY, Si as APP_RANGE_LIMITS, Sl as pacer, Sr as meshHubs, Ss as RTC_CONFIG, Su as TURN_LAST_SEQUENCE, T as encodeCommunityLink, Tc as setAckFrame, Ti as chatAppId, Tl as sha256Paced, Tr as beaconKeys, Tu as nextTurnPosition, U as frameBytes, Ua as parseVoiceMeta, Uc as clearMissed, Ui as emptyIdentityLedger, Un as stripPictureMetadata, Uo as GROUP_ADMIN_OFF_ERROR, Us as HANDOFF_REQUEST, V as GROUP_READ_NOTE, Vc as readEnrollHello, Vn as PICTURE_METADATA_LIMITS, Vo as receivedTimestamp, Vr as ChatFiles, Vs as HANDOFF_PAKE, Vu as normalizeRelayUrl, Wc as endedRequests, Wl as canonicalJson, Wo as GROUP_MEMBER_CAP, Wr as sentWhole, Ws as HANDOFF_TIMINGS, Wu as traceLink, X as mentionsMember, Xa as REMOVED_TEXT, Xc as turnOff, Xl as createDeviceInvite, Xn as pairedMessageFits, Xo as rosterHas, Xr as personStatus, Xs as handoffAttemptSucceeded, Xt as signDidDhtPacket, Y as parseCommunityEdit, Ya as MAX_REMOVAL_NUMBER, Yc as takeRequest, Yi as receivedIdentityStatus, Yl as readContactLink, Yn as pairedEditFits, Yo as rosterAdmin, Yr as liveStatus, Ys as handoffAttemptFailed, Yu as PacketTooLargeError, Z as groupName, Za as RateWindow, Zc as ContactRequestError, Zi as lastSharedWithMe, Zl as deviceInviteJoinerParams, Zn as pairedMessageFrame, Zo as verifyCommitSignature, Zs as handoffBusyFrame, Zt as ETHEREUM_USDT, Zu as createRelayPayload, _ as groupTypingEpoch, _c as readHandoffHello, _d as utf8Decode, _i as parseWakeFrame, _l as appDigest, _o as replySnippet, _s as decodeControl, _t as isAtprotoDid, a as appRevocationFor, ac as handoffManifestFrames, ad as verify, ai as mayPin, al as linkRecords, an as WALLET_NETWORKS, ao as GROUP_REACTION_FRAME, b as COMMUNITY_LIMITS, bc as readHandoffVerified, bi as checkPushEndpoint, br as MESH_HUBS, bu as classifyTurnRead, c as checkAppBeforeRun, ca as HOLD_LIMITS, cc as handoffReleaseFrame, cd as hasVisible, ci as pinNumberHolds, cl as openRequest, cn as assertWholeSats, co as nextReactionNumber, cs as PRESENCE_WINDOW, cu as HANDOFF_CAPABILITY, da as isHoldUrl, dc as handoffVersions, dd as bytesEqual, di as WAKE_ONLINE_BATCH_MS, dl as requestRecords, dn as walletNetworkOf, do as reactionIsNewer, ds as presenceSeenAt, du as deviceKeyZ32, ea as validExternalKey, ec as handoffContextProof, ei as TypingSender, el as contactAskerHolds, en as PaymentPreflightError, er as engineText, es as RatchetBox, eu as createChatInvite, fa as newMailbox, fc as newHandoffId, fd as fromBase64Url, fi as WAKE_ONLINE_DELAY_MS, fl as seenEntry, fn as SPARK_NETWORKS, fo as readReaction, fs as GhostlyHttpError, fu as deviceLinkPairing, g as GroupTypingBoard, gc as readHandoffHave, gd as toZ32, gi as newWakeToken, gn as isBitcoinAddress, go as readReply, gs as LIMITS, gu as webCryptoSigner, hc as readHandoffDone, hd as toBase64Url, hi as deviceWakeRequest, hn as sparkInvoiceDetails, ho as pairedReplyAuthor, hs as webLocalFetch, hu as seedSigner, i as addedAppPermissions, ic as handoffHelloFrame, id as publicKeyFromZ32, ii as PIN_LIMITS, il as knockSlotRecords, in as USDT_PUBLIC_RPC, io as COMMUNITY_REACTION_FRAME, iu as inviteOwnership, j as knockRecords, ja as peekDhtMailbox, ji as UPGRADE_CAPABILITY, jn as cashuRequestPayload, jr as lobbyRecords, js as emptyLinkRecords, ju as turnName, k as entryParams, ki as EDIT_CAPABILITY, kl as appRef, kn as decodeBolt11, kr as hubRank, ks as parseCallSignal, ku as turnInstance, l as planAppUpdate, la as HoldKeys, lc as handoffRetryAfter, ld as sanitizeDisplayText, li as readPin, ll as readKnockSlot, ln as formatPaymentAmount, lo as queueReaction, lr as readGroupFileMeta, ls as RELAY_POLL_INTERVALS, lu as deviceEchoFrame, mc as readHandoffCancel, md as randomBytes, mi as WakeLimiter, ml as APP_BUNDLE_MAGIC, mn as sparkAddressKind, mo as wireReaction, ms as parseLocalTarget, mu as newDeviceSetSecret, n as readX401SdJwtVc, na as automaticTransport, nc as handoffDigest, nd as identityFromSeed, ni as typingActivity, nl as knockSlotIdentity, no as forwardedAgain, nr as GROUP_FILE_LIMITS, ns as ratchetSessionOf, nu as encodeInviteCode, o as appStoreDecision, oa as HOLD_CAPABILITY, oc as handoffOfferFrame, oi as nextPinNumber, ol as makeStampPaced, on as arkAddressPrefix, oo as REACTION_LIMITS, os as DHT_POLL_INTERVALS, ou as DEVICES_CAPABILITY, p as readAppStoreSteps, pa as readManifest, pc as readHandoffAck, pl as APP_BUNDLE_LIMITS, pn as SPARK_PROVIDER, po as validReactionNumber, pr as CarriedTransport, ps as formatLocalTarget, pu as devicePingFrame, q as carryMentions, qa as EDIT_BUFFER_MS, qc as planKnocks, ql as createContactLink, qn as LIVENESS_PING_MS, qo as commitHash, qs as filePartName, qt as encodeDidDhtDeactivated, qu as isDiscoveryBudgetError, r as sameX401HolderJwk, rc as handoffEphemeral, rd as identityFromSeedB64, rl as knockSlotOf, rn as TEST_USDT_FAUCET_AMOUNT, ro as readForwarded, rr as GROUP_HAVE_FRAME, rs as DirectPathWatch, ru as inviteLink, s as appUpdateDecision, sa as HOLD_DATED_BACK_MS, sc as handoffPakeFrame, sd as sanitizeAvatar, si as pinIsNewer, sl as mergeContactKnocks, sn as assertTokenUnits, so as ReactionWindow, sr as groupFileFallback, su as ENROLL_CAPABILITY, t as newX401HolderKey, ta as TRANSPORTS, tc as handoffDataFrame, td as createIdentity, tl as contactDay, tn as SEPOLIA_TEST_USDT, to as parseLinkPreview, tr as parseEngineError, ts as emptyRatchetState, tu as decodeInviteCode, u as APP_STORE_LIMITS, ua as HoldRefusedError, uc as handoffStreamKey, ud as stripHidden, ui as WAKE_CALL_INTERVAL_MS, ul as readLinkRecord, un as validatePaymentTarget, uo as reactionEmoji, us as WATCH_PEER_MS, uu as deviceEchoNonce, v as openGroupTyping, vc as readHandoffPake, vd as utf8Encode, vi as relayRequest, vl as appViewOf, vn as isPubkyKey, vo as BUTTON_ID, vr as groupSignalFrame, vs as encodeControl, vt as normalizeAtprotoHandle, vu as TURN_RAISE_READ_TIMEOUT_MS, w as decodeCommunityLink, wc as readSetUpdate, wl as readAppBundleAsync, wr as COMMUNITY_TOPOLOGY, wu as firstDeviceSetSecret, x as CommunitySession, xc as sealHandoffPiece, xi as vapidKeysMatch, xl as isAppUrl, xr as mayBeHub, xu as turnPutSummary, y as sealGroupTyping, yc as readHandoffTurnFrame, yi as wakeRequest, yr as readGroupSignal, yu as TURN_SETTLE_MS, z as GROUP_LIMITS, zc as enrollProofFrame, zn as withoutVideoMetadata, zo as claimedTime, zr as readLobby, zs as HANDOFF_HELLO } from "./src-BnpEQqzk.js";
|
|
3
3
|
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
|
|
4
4
|
import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
6
|
-
import { a as
|
|
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-
|
|
8
|
-
import {
|
|
9
|
-
import { a as
|
|
5
|
+
import { t as nwc } from "./nwcProvider-DpeDy0bV.js";
|
|
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-DMffkiJ6.js";
|
|
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 iceServerProblem, A as storedSize, B as journaledPayment, C as paymentNetworksOf, D as FileAppender, E as WALLET_TYPES, F as CASHU_CARD, G as sourceKey, H as INVOICE_PACE, I as LightningCards, J as AskBackoff, K as CASHU_MINT_SOURCE, L as cardsKey, O as readStored$2, P as IdentityProofs, Q as dropBreezDatabase, R as isRecoveryPhrase, S as paymentNetwork, U as nextInvoiceAsk, V as lightningPaying, W as ProviderSources, X as breezDatabaseInUse, Y as breezDatabase, Z as breezDatabasesFor, _ as WALLET_NAMES, a as GroupFileDesk, at as networkLabel, b as createTiming, c as groupOfFile, ct as requireTurn, d as pairedWireReply, et as iceServerSetting, f as receivedPairedReply, g as paymentWireId, h as paymentAlias, i as onPublicIrohRelay, it as WrongNetworkError, j as streamStored, k as removeStored, l as storedGroupFiles, lt as setAwayWallets, m as replyTo, n as createIrohWebEndpoint, nt as ModeChanged, o as groupFileId, ot as awayFrom, p as replyRef, q as cashuMint, r as irohRelayProblem, rt as ModeGate, s as groupFileText, st as refuseAway, t as DEFAULT_IROH_RELAYS, tt as relayOnlyProblem, u as groupReply, ut as setSingleWriterGate, v as assertConfirmedReal, w as walletInstances, x as crossNetwork, y as createFailure, z as normalizePhrase } from "./irohWeb-CqPN8VPY.js";
|
|
10
|
+
import { r as loadFedimintSdk, t as fedimintDatabase } from "./fedimintSdk-CqTeMdF0.js";
|
|
10
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";
|
|
11
|
-
import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-
|
|
12
|
-
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-
|
|
13
|
-
import {
|
|
14
|
-
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-CeZBNGX-.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-iKz8u_fM.js";
|
|
13
|
+
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-DI8uAM_Y.js";
|
|
14
|
+
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-Q_rMgoE9.js";
|
|
15
15
|
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
|
|
16
16
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
17
17
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
@@ -124,6 +124,552 @@ var ClockWatch = class {
|
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
//#endregion
|
|
127
|
+
//#region ../browser/src/shared/messageChanges.ts
|
|
128
|
+
/** A row as a page gets it: without the frame a private group's message came in (`StoredMessage.frame`), which only the engine reads. */
|
|
129
|
+
function withoutFrame(message) {
|
|
130
|
+
if (message.frame === void 0) return message;
|
|
131
|
+
const { frame: _frame, ...row } = message;
|
|
132
|
+
return row;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region ../browser/src/engine/db.ts
|
|
136
|
+
/**
|
|
137
|
+
* The newest `count` rows of an index range, newest first: one descending read where IndexedDB has it (the options
|
|
138
|
+
* that came with `getAllRecords`), else a cursor from the end.
|
|
139
|
+
*/
|
|
140
|
+
function newestMessages(index, query, count) {
|
|
141
|
+
if (typeof index.getAllRecords === "function") return wrap(index.getAll({
|
|
142
|
+
query,
|
|
143
|
+
count,
|
|
144
|
+
direction: "prev"
|
|
145
|
+
}));
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const rows = [];
|
|
148
|
+
const request = index.openCursor(query, "prev");
|
|
149
|
+
request.onerror = () => reject(request.error);
|
|
150
|
+
request.onsuccess = () => {
|
|
151
|
+
const cursor = request.result;
|
|
152
|
+
if (cursor) rows.push(cursor.value);
|
|
153
|
+
if (!cursor || rows.length >= count) resolve(rows);
|
|
154
|
+
else cursor.continue();
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/** A write that waits for no disk sync of its own (in a browser, the engine's default already; on Node, the CLI's store). */
|
|
159
|
+
var RELAXED = { durability: "relaxed" };
|
|
160
|
+
var CHANGED = Symbol("changed");
|
|
161
|
+
/**
|
|
162
|
+
* While on (`keepNewest`), each whole history read (`getMessages`) keeps its newest rows as the engine's `messagePage`
|
|
163
|
+
* hands them, so a reader of that page right after the engine's start (the CLI's event check) reads nothing again: at 200
|
|
164
|
+
* chats of 300 messages that second read was a fifth of a one-shot command. Kept only when no write of that history
|
|
165
|
+
* was on its way while it was read, and dropped by the next one (`written`).
|
|
166
|
+
*/
|
|
167
|
+
var keepLimit = 0;
|
|
168
|
+
var keptNewest = /* @__PURE__ */ new Map();
|
|
169
|
+
/** Per chat or group, its message writes started and ended; and the writes still on their way. */
|
|
170
|
+
var writeTurns = /* @__PURE__ */ new Map();
|
|
171
|
+
var writesOn = /* @__PURE__ */ new Map();
|
|
172
|
+
/** Runs a write of a history's rows: what was kept of it is dropped as the write starts and as it ends. */
|
|
173
|
+
async function written(linkId, write) {
|
|
174
|
+
const turn = (on) => {
|
|
175
|
+
writeTurns.set(linkId, (writeTurns.get(linkId) ?? 0) + 1);
|
|
176
|
+
writesOn.set(linkId, (writesOn.get(linkId) ?? 0) + on);
|
|
177
|
+
if (!writesOn.get(linkId)) writesOn.delete(linkId);
|
|
178
|
+
keptNewest.delete(linkId);
|
|
179
|
+
};
|
|
180
|
+
turn(1);
|
|
181
|
+
try {
|
|
182
|
+
return await write();
|
|
183
|
+
} finally {
|
|
184
|
+
turn(-1);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** The newest rows of a whole history read (in `getMessages`' order), kept as its page would read them. */
|
|
188
|
+
function keepPage(linkId, turn, messages) {
|
|
189
|
+
if (writeTurns.get(linkId) !== turn || writesOn.has(linkId) || !messages.every((m) => Number.isFinite(m.timestamp))) {
|
|
190
|
+
keptNewest.delete(linkId);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
keptNewest.set(linkId, {
|
|
194
|
+
messages: structuredClone(messages.slice(-keepLimit).map(withoutFrame)),
|
|
195
|
+
more: messages.length > keepLimit
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A chat's pinned key, for the transaction that checks and changes it, and the seals of the keys that change writes.
|
|
200
|
+
* Sealed (the data key is set), it is opened before the transaction, and holds inside it only while the row still has
|
|
201
|
+
* the sealed value that was opened: `CHANGED` otherwise.
|
|
202
|
+
*/
|
|
203
|
+
async function pinnedKey(linkId, key) {
|
|
204
|
+
const seals = new RowSeals();
|
|
205
|
+
if (!seals.on) return {
|
|
206
|
+
seals,
|
|
207
|
+
pinned: (link) => link?.pairedPeerKey
|
|
208
|
+
};
|
|
209
|
+
const seen = await wrap((await store(STORES$1.links, "readonly")).get(linkId));
|
|
210
|
+
const opened = await openRow(STORES$1.links, seen);
|
|
211
|
+
await seals.prepare(STORES$1.links, [{
|
|
212
|
+
id: linkId,
|
|
213
|
+
pairedPeerKey: key,
|
|
214
|
+
peerTrust: { verifiedKey: key }
|
|
215
|
+
}, {
|
|
216
|
+
id: linkId,
|
|
217
|
+
peerTrust: { verifiedKey: opened?.pairedPeerKey }
|
|
218
|
+
}]);
|
|
219
|
+
const then = JSON.stringify(seen?.pairedPeerKey);
|
|
220
|
+
return {
|
|
221
|
+
seals,
|
|
222
|
+
pinned: (link) => JSON.stringify(link?.pairedPeerKey) === then ? opened?.pairedPeerKey : CHANGED
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Durable local state of the browser peer. Identity seeds live here the same
|
|
227
|
+
* way Desktop keeps them in its WebView storage: local to this profile, never
|
|
228
|
+
* published. Network presence is not stored; it only exists while the engine runs.
|
|
229
|
+
*/
|
|
230
|
+
var db = {
|
|
231
|
+
async getLinks() {
|
|
232
|
+
return openRows(STORES$1.links, await wrap((await store(STORES$1.links, "readonly")).getAll()));
|
|
233
|
+
},
|
|
234
|
+
async putLink(link) {
|
|
235
|
+
const row = await sealRow(STORES$1.links, link);
|
|
236
|
+
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
237
|
+
tx.objectStore(STORES$1.links).put(row);
|
|
238
|
+
await new Promise((resolve, reject) => {
|
|
239
|
+
tx.oncomplete = () => resolve();
|
|
240
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Link storage failed"));
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
/** `relaxed`: for what a power cut may cost (a round trip, a note made again later), no disk sync of its own. */
|
|
244
|
+
async patchLink(linkId, patch, relaxed = false) {
|
|
245
|
+
const sealed = await sealRow(STORES$1.links, {
|
|
246
|
+
...patch,
|
|
247
|
+
id: linkId
|
|
248
|
+
});
|
|
249
|
+
const tx = (await openDb()).transaction(STORES$1.links, "readwrite", relaxed ? RELAXED : void 0);
|
|
250
|
+
const links = tx.objectStore(STORES$1.links);
|
|
251
|
+
const request = links.get(linkId);
|
|
252
|
+
request.onsuccess = () => {
|
|
253
|
+
if (!request.result) {
|
|
254
|
+
tx.abort();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
links.put({
|
|
258
|
+
...request.result,
|
|
259
|
+
...sealed
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
await new Promise((resolve, reject) => {
|
|
263
|
+
tx.oncomplete = () => resolve();
|
|
264
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Link unavailable"));
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
async updatePeerProofs(linkId, change) {
|
|
268
|
+
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
269
|
+
const links = tx.objectStore(STORES$1.links);
|
|
270
|
+
let result;
|
|
271
|
+
let failure;
|
|
272
|
+
const request = links.get(linkId);
|
|
273
|
+
request.onsuccess = () => {
|
|
274
|
+
try {
|
|
275
|
+
const link = request.result;
|
|
276
|
+
if (!link?.pairedPeerKey) throw new Error("Confirmed conversation unavailable");
|
|
277
|
+
result = change(link.peerProofs ?? emptyProofLedger());
|
|
278
|
+
links.put({
|
|
279
|
+
...link,
|
|
280
|
+
peerProofs: result
|
|
281
|
+
});
|
|
282
|
+
} catch (e) {
|
|
283
|
+
failure = e;
|
|
284
|
+
tx.abort();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
await new Promise((resolve, reject) => {
|
|
288
|
+
tx.oncomplete = () => resolve();
|
|
289
|
+
tx.onerror = tx.onabort = () => reject(failure ?? tx.error ?? /* @__PURE__ */ new Error("Proof storage failed"));
|
|
290
|
+
});
|
|
291
|
+
return result;
|
|
292
|
+
},
|
|
293
|
+
/** Read-transform-write of a chat's identity ledger in one transaction, keeping every other field. */
|
|
294
|
+
async updateIdentities(linkId, change) {
|
|
295
|
+
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
296
|
+
const links = tx.objectStore(STORES$1.links);
|
|
297
|
+
let result;
|
|
298
|
+
let failure;
|
|
299
|
+
const request = links.get(linkId);
|
|
300
|
+
request.onsuccess = () => {
|
|
301
|
+
try {
|
|
302
|
+
const link = request.result;
|
|
303
|
+
if (!link?.profile) throw new Error("Paired chat unavailable");
|
|
304
|
+
result = change(link.identities ?? emptyIdentityLedger());
|
|
305
|
+
links.put({
|
|
306
|
+
...link,
|
|
307
|
+
identities: result
|
|
308
|
+
});
|
|
309
|
+
} catch (e) {
|
|
310
|
+
failure = e;
|
|
311
|
+
tx.abort();
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
await new Promise((resolve, reject) => {
|
|
315
|
+
tx.oncomplete = () => resolve();
|
|
316
|
+
tx.onerror = tx.onabort = () => reject(failure ?? tx.error ?? /* @__PURE__ */ new Error("Identity storage failed"));
|
|
317
|
+
});
|
|
318
|
+
return result;
|
|
319
|
+
},
|
|
320
|
+
async pinPeer(linkId, key, signedSignals = false) {
|
|
321
|
+
const { seals, pinned } = await pinnedKey(linkId, key);
|
|
322
|
+
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
323
|
+
const links = tx.objectStore(STORES$1.links);
|
|
324
|
+
const request = links.get(linkId);
|
|
325
|
+
request.onsuccess = () => {
|
|
326
|
+
const link = request.result;
|
|
327
|
+
const before = pinned(link);
|
|
328
|
+
if (!link?.participationSeed || before === CHANGED || before && before !== key) {
|
|
329
|
+
tx.abort();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
links.put(seals.row(STORES$1.links, {
|
|
333
|
+
...link,
|
|
334
|
+
peerTrust: link.peerTrust ?? {
|
|
335
|
+
version: 1,
|
|
336
|
+
verifiedKey: before
|
|
337
|
+
},
|
|
338
|
+
pairedPeerKey: key,
|
|
339
|
+
requireSignedSignals: link.requireSignedSignals || signedSignals,
|
|
340
|
+
inviteCode: void 0
|
|
341
|
+
}));
|
|
342
|
+
};
|
|
343
|
+
await new Promise((resolve, reject) => {
|
|
344
|
+
tx.oncomplete = () => resolve();
|
|
345
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Invitation already consumed or unavailable"));
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
async verifyPeer(linkId, key) {
|
|
349
|
+
const { seals, pinned } = await pinnedKey(linkId, key);
|
|
350
|
+
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
351
|
+
const links = tx.objectStore(STORES$1.links);
|
|
352
|
+
const request = links.get(linkId);
|
|
353
|
+
request.onsuccess = () => {
|
|
354
|
+
const link = request.result;
|
|
355
|
+
if (!link?.pairedPeerKey || pinned(link) !== key) {
|
|
356
|
+
tx.abort();
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
links.put(seals.row(STORES$1.links, {
|
|
360
|
+
...link,
|
|
361
|
+
peerTrust: {
|
|
362
|
+
version: 1,
|
|
363
|
+
verifiedKey: key,
|
|
364
|
+
verifiedAt: Date.now()
|
|
365
|
+
}
|
|
366
|
+
}));
|
|
367
|
+
};
|
|
368
|
+
await new Promise((resolve, reject) => {
|
|
369
|
+
tx.oncomplete = () => resolve();
|
|
370
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Contact changed or verification could not be saved"));
|
|
371
|
+
});
|
|
372
|
+
},
|
|
373
|
+
async deleteLink(linkId) {
|
|
374
|
+
await committed((await store(STORES$1.links, "readwrite")).delete(linkId));
|
|
375
|
+
await written(linkId, async () => committed((await store(STORES$1.messages, "readwrite")).delete(IDBKeyRange.bound([linkId], [linkId, []]))));
|
|
376
|
+
await fileStore.deleteForLink(linkId);
|
|
377
|
+
await removeFileBytes(`${linkId}-in-`);
|
|
378
|
+
await removeFileBytes(`${linkId}-out-`);
|
|
379
|
+
const appStorage = await store(STORES$1.appStorage, "readwrite");
|
|
380
|
+
await new Promise((resolve, reject) => {
|
|
381
|
+
appStorage.transaction.oncomplete = () => resolve();
|
|
382
|
+
appStorage.transaction.onerror = appStorage.transaction.onabort = () => reject(appStorage.transaction.error ?? /* @__PURE__ */ new Error("App storage failed"));
|
|
383
|
+
const request = appStorage.index(APP_STORAGE_CHAT_INDEX).openKeyCursor(IDBKeyRange.only(linkId));
|
|
384
|
+
request.onsuccess = () => {
|
|
385
|
+
const cursor = request.result;
|
|
386
|
+
if (!cursor) return;
|
|
387
|
+
const [ref] = cursor.primaryKey;
|
|
388
|
+
appStorage.delete(IDBKeyRange.bound([ref, linkId], [
|
|
389
|
+
ref,
|
|
390
|
+
linkId,
|
|
391
|
+
[]
|
|
392
|
+
]));
|
|
393
|
+
cursor.continue();
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
},
|
|
397
|
+
/**
|
|
398
|
+
* A chat's whole history, by time. Read by its key range (every key is `[linkId, id]`, ids are strings: from `[linkId]`
|
|
399
|
+
* to `[linkId, []]`), the same rows in the same order as the `byLink` index has them, without looking each one up
|
|
400
|
+
* again: in the CLI's store (fake-indexeddb) that lookup cost 4-9 times the read itself.
|
|
401
|
+
*/
|
|
402
|
+
async getMessages(linkId) {
|
|
403
|
+
const turn = writeTurns.get(linkId);
|
|
404
|
+
const messages = await wrap((await store(STORES$1.messages, "readonly")).getAll(IDBKeyRange.bound([linkId], [linkId, []])));
|
|
405
|
+
messages.sort((a, b) => a.timestamp - b.timestamp);
|
|
406
|
+
if (keepLimit) keepPage(linkId, turn, messages);
|
|
407
|
+
return messages;
|
|
408
|
+
},
|
|
409
|
+
/**
|
|
410
|
+
* From now on, each whole history read keeps its newest `limit` rows for `takeNewest` (0: none, and what was kept
|
|
411
|
+
* goes). Only the CLI's engine keeps them, for its start.
|
|
412
|
+
*/
|
|
413
|
+
keepNewest(limit) {
|
|
414
|
+
keepLimit = limit;
|
|
415
|
+
keptNewest.clear();
|
|
416
|
+
},
|
|
417
|
+
/** What was kept of the histories read whole (`keepNewest`), by chat or group, still as stored; keeping stops. */
|
|
418
|
+
takeNewest() {
|
|
419
|
+
const kept = new Map(keptNewest);
|
|
420
|
+
keepLimit = 0;
|
|
421
|
+
keptNewest.clear();
|
|
422
|
+
return kept;
|
|
423
|
+
},
|
|
424
|
+
/** Whether the chat has a message with this id. */
|
|
425
|
+
async hasMessage(linkId, id) {
|
|
426
|
+
return await wrap((await store(STORES$1.messages, "readonly")).getKey([linkId, id])) !== void 0;
|
|
427
|
+
},
|
|
428
|
+
async getMessage(linkId, id) {
|
|
429
|
+
return wrap((await store(STORES$1.messages, "readonly")).get([linkId, id]));
|
|
430
|
+
},
|
|
431
|
+
/**
|
|
432
|
+
* These rows of a chat, in the order asked (undefined where none is), in one transaction: in the CLI's store
|
|
433
|
+
* (fake-indexeddb) each transaction waiting at once is checked against all the others, so one per row costs the square.
|
|
434
|
+
*/
|
|
435
|
+
async getMessagesById(linkId, ids) {
|
|
436
|
+
if (!ids.length) return [];
|
|
437
|
+
const messages = await store(STORES$1.messages, "readonly");
|
|
438
|
+
return Promise.all(ids.map((id) => wrap(messages.get([linkId, id]))));
|
|
439
|
+
},
|
|
440
|
+
/**
|
|
441
|
+
* The newest `limit` messages of a chat before `before`, oldest first, in `getMessages`' order (time, then id), and
|
|
442
|
+
* whether older ones remain. Reads those rows only: a long chat's first page costs what a short one's does.
|
|
443
|
+
* `before`: a message's place (the page ends just before it), or a time (`id` left out: the page ends before it).
|
|
444
|
+
*/
|
|
445
|
+
async getMessagePage(linkId, { limit, before }) {
|
|
446
|
+
const range = IDBKeyRange.bound([linkId, -Infinity], [linkId, before?.timestamp ?? Infinity], false, !!before && before.id === void 0);
|
|
447
|
+
const kept = (m) => !(before?.id !== void 0 && m.timestamp === before.timestamp && m.id >= before.id);
|
|
448
|
+
for (let want = limit + 1;;) {
|
|
449
|
+
const newest = await newestMessages((await store(STORES$1.messages, "readonly")).index("byLinkTime"), range, want);
|
|
450
|
+
const page = newest.filter(kept);
|
|
451
|
+
if (page.length > limit || newest.length < want) return {
|
|
452
|
+
messages: page.slice(0, limit).reverse(),
|
|
453
|
+
more: page.length > limit
|
|
454
|
+
};
|
|
455
|
+
want += newest.length - page.length;
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
/**
|
|
459
|
+
* The oldest `limit` messages of a chat after `after` (and before `before`, when given), oldest first, and whether
|
|
460
|
+
* newer ones remain in that window. Reads those rows only: a bot that reads what came since its last message costs
|
|
461
|
+
* a page, where reading the whole history and cutting it cost 94 ms of the daemon's time a call at 7,000 messages.
|
|
462
|
+
*/
|
|
463
|
+
async getMessagePageAfter(linkId, { limit, before, after }) {
|
|
464
|
+
const upper = before?.timestamp ?? Infinity;
|
|
465
|
+
if (after.timestamp > upper || after.timestamp === upper && (after.id === void 0 || before?.id === void 0)) return {
|
|
466
|
+
messages: [],
|
|
467
|
+
more: false
|
|
468
|
+
};
|
|
469
|
+
const range = IDBKeyRange.bound([linkId, after.timestamp], [linkId, upper], after.id === void 0, !!before && before.id === void 0);
|
|
470
|
+
const kept = (m) => !(after.id !== void 0 && m.timestamp === after.timestamp && m.id <= after.id) && !(before?.id !== void 0 && m.timestamp === before.timestamp && m.id >= before.id);
|
|
471
|
+
for (let want = limit + 1;;) {
|
|
472
|
+
const oldest = await wrap((await store(STORES$1.messages, "readonly")).index("byLinkTime").getAll(range, want));
|
|
473
|
+
const page = oldest.filter(kept);
|
|
474
|
+
if (page.length > limit || oldest.length < want) return {
|
|
475
|
+
messages: page.slice(0, limit),
|
|
476
|
+
more: page.length > limit
|
|
477
|
+
};
|
|
478
|
+
want += oldest.length - page.length;
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
/**
|
|
482
|
+
* Every message of this profile that carries a task, a routine or a usage card, from every chat and group, oldest first (time,
|
|
483
|
+
* then id). Reads the card index only (`CARD_INDEX`): no chat's history is read, however long. The index follows the
|
|
484
|
+
* rows, so an edit's card, a deleted message and a deleted chat or group are in step with no bookkeeping.
|
|
485
|
+
*/
|
|
486
|
+
async getCardMessages() {
|
|
487
|
+
const index = (await store(STORES$1.messages, "readonly")).index(CARD_INDEX);
|
|
488
|
+
return (await Promise.all([
|
|
489
|
+
"task",
|
|
490
|
+
"routine",
|
|
491
|
+
"usage"
|
|
492
|
+
].map((kind) => wrap(index.getAll(kind))))).flat().sort((a, b) => a.timestamp - b.timestamp || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
493
|
+
},
|
|
494
|
+
/**
|
|
495
|
+
* A chat's or a group's messages that carry a file, by time (then id), as `getMessages` has them. Reads the file index
|
|
496
|
+
* only (`FILE_INDEX`): a chat of thousands of texts and a few files costs the files.
|
|
497
|
+
*/
|
|
498
|
+
async getFileMessages(linkId) {
|
|
499
|
+
const index = (await store(STORES$1.messages, "readonly")).index(FILE_INDEX);
|
|
500
|
+
return (await wrap(index.getAll(IDBKeyRange.bound([linkId], [linkId, []])))).sort((a, b) => a.timestamp - b.timestamp || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
501
|
+
},
|
|
502
|
+
/** Returns false when the message was already stored. */
|
|
503
|
+
addMessage(message) {
|
|
504
|
+
return written(message.linkId, async () => {
|
|
505
|
+
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite");
|
|
506
|
+
const messages = tx.objectStore(STORES$1.messages);
|
|
507
|
+
let added = false;
|
|
508
|
+
const request = messages.getKey([message.linkId, message.id]);
|
|
509
|
+
request.onsuccess = () => {
|
|
510
|
+
if (request.result !== void 0) return;
|
|
511
|
+
messages.put(message);
|
|
512
|
+
added = true;
|
|
513
|
+
};
|
|
514
|
+
await new Promise((resolve, reject) => {
|
|
515
|
+
tx.oncomplete = () => resolve();
|
|
516
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Message storage failed"));
|
|
517
|
+
});
|
|
518
|
+
return added;
|
|
519
|
+
});
|
|
520
|
+
},
|
|
521
|
+
/** Writes a message whether or not it is there: lines of history that change as what they tell changes. */
|
|
522
|
+
async putMessage(message) {
|
|
523
|
+
await written(message.linkId, async () => committed((await store(STORES$1.messages, "readwrite")).put(message)));
|
|
524
|
+
},
|
|
525
|
+
updateDelivery(linkId, id, delivery, deliveryError, extra) {
|
|
526
|
+
return written(linkId, async () => {
|
|
527
|
+
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite", delivery === "sent" || delivery === "delivered" ? RELAXED : void 0);
|
|
528
|
+
const messages = tx.objectStore(STORES$1.messages);
|
|
529
|
+
const request = messages.get([linkId, id]);
|
|
530
|
+
request.onsuccess = () => {
|
|
531
|
+
const message = request.result;
|
|
532
|
+
if (!message?.delivery || message.delivery === "delivered") return;
|
|
533
|
+
if (message.delivery === delivery && message.deliveryError === deliveryError && Object.entries(extra ?? {}).every(([key, value]) => message[key] === value)) return;
|
|
534
|
+
messages.put({
|
|
535
|
+
...message,
|
|
536
|
+
...extra,
|
|
537
|
+
delivery,
|
|
538
|
+
deliveryError
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
await new Promise((resolve, reject) => {
|
|
542
|
+
tx.oncomplete = () => resolve();
|
|
543
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Receipt storage failed"));
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
},
|
|
547
|
+
/**
|
|
548
|
+
* Changes one message row in place, in one transaction: `change` sees the row as stored and gives the fields to
|
|
549
|
+
* set (`null`: leave it). A row that is not there is not made. Used for what the delivery states do not carry
|
|
550
|
+
* (the message's details record), on rows in any state. `relaxed`: for what can be made again or is only a note
|
|
551
|
+
* (a receipt's mark, the details record), written with no disk sync of its own.
|
|
552
|
+
*/
|
|
553
|
+
patchMessage(linkId, id, change, relaxed = false) {
|
|
554
|
+
return written(linkId, async () => {
|
|
555
|
+
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite", relaxed ? RELAXED : void 0);
|
|
556
|
+
const messages = tx.objectStore(STORES$1.messages);
|
|
557
|
+
const request = messages.get([linkId, id]);
|
|
558
|
+
let result;
|
|
559
|
+
request.onsuccess = () => {
|
|
560
|
+
const message = request.result;
|
|
561
|
+
if (!message) return;
|
|
562
|
+
const patch = change(message);
|
|
563
|
+
if (!patch) return;
|
|
564
|
+
result = {
|
|
565
|
+
...message,
|
|
566
|
+
...patch
|
|
567
|
+
};
|
|
568
|
+
messages.put(result);
|
|
569
|
+
};
|
|
570
|
+
await new Promise((resolve, reject) => {
|
|
571
|
+
tx.oncomplete = () => resolve();
|
|
572
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Message storage failed"));
|
|
573
|
+
});
|
|
574
|
+
return result;
|
|
575
|
+
});
|
|
576
|
+
},
|
|
577
|
+
/**
|
|
578
|
+
* `patchMessage` on these rows of one history, all in one transaction: one disk sync for all of them. Resolves to
|
|
579
|
+
* the rows changed, in the order of `ids`.
|
|
580
|
+
*/
|
|
581
|
+
patchMessages(linkId, ids, change) {
|
|
582
|
+
return written(linkId, async () => {
|
|
583
|
+
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite");
|
|
584
|
+
const messages = tx.objectStore(STORES$1.messages);
|
|
585
|
+
const results = [];
|
|
586
|
+
ids.forEach((id, i) => {
|
|
587
|
+
const request = messages.get([linkId, id]);
|
|
588
|
+
request.onsuccess = () => {
|
|
589
|
+
const message = request.result;
|
|
590
|
+
const patch = message && change(message);
|
|
591
|
+
if (!patch) return;
|
|
592
|
+
messages.put(results[i] = {
|
|
593
|
+
...message,
|
|
594
|
+
...patch
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
});
|
|
598
|
+
await new Promise((resolve, reject) => {
|
|
599
|
+
tx.oncomplete = () => resolve();
|
|
600
|
+
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Message storage failed"));
|
|
601
|
+
});
|
|
602
|
+
return results.filter((row) => !!row);
|
|
603
|
+
});
|
|
604
|
+
},
|
|
605
|
+
async deleteMessage(linkId, messageId) {
|
|
606
|
+
await written(linkId, async () => committed((await store(STORES$1.messages, "readwrite")).delete([linkId, messageId])));
|
|
607
|
+
},
|
|
608
|
+
async getGroups() {
|
|
609
|
+
return openRows(STORES$1.groups, await wrap((await store(STORES$1.groups, "readonly")).getAll()));
|
|
610
|
+
},
|
|
611
|
+
/**
|
|
612
|
+
* `live`: the group's small row (`GroupLive`) in the same transaction, or `null` to delete it. It holds none of the
|
|
613
|
+
* fields the encrypted profile seals; the record's are sealed before the transaction opens. The record holds the
|
|
614
|
+
* group's pin and deletions for everyone again: their row (`GroupLight`) goes.
|
|
615
|
+
*/
|
|
616
|
+
async putGroup(group, live) {
|
|
617
|
+
const row = await sealRow(STORES$1.groups, group);
|
|
618
|
+
if (live === void 0) {
|
|
619
|
+
await committed((await store(STORES$1.groups, "readwrite")).put(row));
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
const tx = (await openDb()).transaction([STORES$1.groups, STORES$1.settings], "readwrite");
|
|
623
|
+
tx.objectStore(STORES$1.groups).put(row);
|
|
624
|
+
const settings = tx.objectStore(STORES$1.settings);
|
|
625
|
+
settings.delete(groupLightKey(group.id));
|
|
626
|
+
if (live) await committed(settings.put(live, groupLiveKey(group.id)));
|
|
627
|
+
else await committed(settings.delete(groupLiveKey(group.id)));
|
|
628
|
+
},
|
|
629
|
+
/** Every private group's small row, by group id. */
|
|
630
|
+
async getGroupLive() {
|
|
631
|
+
const settings = await store(STORES$1.settings, "readonly");
|
|
632
|
+
const [keys, rows] = await Promise.all([wrap(settings.getAllKeys(GROUP_LIVE_RANGE())), wrap(settings.getAll(GROUP_LIVE_RANGE()))]);
|
|
633
|
+
return new Map(keys.map((key, i) => [String(key).slice(groupLiveKey("").length), rows[i]]));
|
|
634
|
+
},
|
|
635
|
+
async putGroupLive(groupId, live) {
|
|
636
|
+
await committed((await store(STORES$1.settings, "readwrite")).put(live, groupLiveKey(groupId)));
|
|
637
|
+
},
|
|
638
|
+
/** Every private group's pin and deletions for everyone that its record is behind on, by group id. */
|
|
639
|
+
async getGroupLight() {
|
|
640
|
+
const settings = await store(STORES$1.settings, "readonly");
|
|
641
|
+
const [keys, rows] = await Promise.all([wrap(settings.getAllKeys(GROUP_LIGHT_RANGE())), wrap(settings.getAll(GROUP_LIGHT_RANGE()))]);
|
|
642
|
+
return new Map(keys.map((key, i) => [String(key).slice(groupLightKey("").length), rows[i]]));
|
|
643
|
+
},
|
|
644
|
+
async putGroupLight(groupId, light) {
|
|
645
|
+
await committed((await store(STORES$1.settings, "readwrite")).put(light, groupLightKey(groupId)));
|
|
646
|
+
},
|
|
647
|
+
/** The group and its history. */
|
|
648
|
+
async deleteGroup(groupId) {
|
|
649
|
+
const tx = (await openDb()).transaction([STORES$1.groups, STORES$1.settings], "readwrite");
|
|
650
|
+
tx.objectStore(STORES$1.groups).delete(groupId);
|
|
651
|
+
tx.objectStore(STORES$1.settings).delete(groupLightKey(groupId));
|
|
652
|
+
await committed(tx.objectStore(STORES$1.settings).delete(groupLiveKey(groupId)));
|
|
653
|
+
const link = `group:${groupId}`;
|
|
654
|
+
await written(link, async () => committed((await store(STORES$1.messages, "readwrite")).delete(IDBKeyRange.bound([link], [link, []]))));
|
|
655
|
+
},
|
|
656
|
+
async getServices() {
|
|
657
|
+
return wrap((await store(STORES$1.services, "readonly")).getAll());
|
|
658
|
+
},
|
|
659
|
+
async putService(service) {
|
|
660
|
+
await committed((await store(STORES$1.services, "readwrite")).put(service));
|
|
661
|
+
},
|
|
662
|
+
async deleteService(serviceId) {
|
|
663
|
+
await committed((await store(STORES$1.services, "readwrite")).delete(serviceId));
|
|
664
|
+
},
|
|
665
|
+
async getSettings() {
|
|
666
|
+
return await wrap((await store(STORES$1.settings, "readonly")).get("settings")) ?? {};
|
|
667
|
+
},
|
|
668
|
+
async putSettings(settings) {
|
|
669
|
+
await committed((await store(STORES$1.settings, "readwrite")).put(settings, "settings"));
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
//#endregion
|
|
127
673
|
//#region ../browser/src/engine/paymentAdapters/walletNetworks.ts
|
|
128
674
|
/** Where the wallet of one network is stored. The same key an older app parks it under, so it finds it too. */
|
|
129
675
|
var walletKey = (rail, network) => `${rail}-mode-${network}`;
|
|
@@ -199,7 +745,7 @@ function viewNews(before, after) {
|
|
|
199
745
|
//#endregion
|
|
200
746
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
201
747
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
202
|
-
var loadUsdt = () => import("./usdt-
|
|
748
|
+
var loadUsdt = () => import("./usdt-CDaLhEYh.js");
|
|
203
749
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
204
750
|
var DEFAULT_USDT = {
|
|
205
751
|
network: "ethereum",
|
|
@@ -558,6 +1104,7 @@ var SWITCHES = [
|
|
|
558
1104
|
"shareProfile",
|
|
559
1105
|
"publicProfiles",
|
|
560
1106
|
"sendTyping",
|
|
1107
|
+
"sharePresence",
|
|
561
1108
|
"autoDownloads",
|
|
562
1109
|
"serveFiles"
|
|
563
1110
|
];
|
|
@@ -686,7 +1233,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
686
1233
|
//#endregion
|
|
687
1234
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
688
1235
|
/** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
|
|
689
|
-
var loadArkade = () => import("./arkade-
|
|
1236
|
+
var loadArkade = () => import("./arkade-_aaB7VbW.js");
|
|
690
1237
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
691
1238
|
var RETIRE_READ_MS = 1e4;
|
|
692
1239
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -3626,6 +4173,15 @@ function mintRefused(error) {
|
|
|
3626
4173
|
* those outputs is ever signed; new ones on the keyset it signs with now can be. cashu-ts says it in its own English,
|
|
3627
4174
|
* which is never shown to a person.
|
|
3628
4175
|
*/
|
|
4176
|
+
/**
|
|
4177
|
+
* The mint failed, and said nothing of the request: a server error (5xx, "internal error"), or no answer at all (a
|
|
4178
|
+
* closed connection, cashu-ts's `NetworkError`). Unlike a refusal, it may work later. By name, as `mintRefused`.
|
|
4179
|
+
*/
|
|
4180
|
+
function mintFailed(error) {
|
|
4181
|
+
if (!(error instanceof Error)) return false;
|
|
4182
|
+
const status = error.status;
|
|
4183
|
+
return error.name === "NetworkError" || error.name === "HttpResponseError" && typeof status === "number" && status >= 500;
|
|
4184
|
+
}
|
|
3629
4185
|
function keysetRefused(error) {
|
|
3630
4186
|
return error instanceof Error && error.name === "StaleKeysetError" && mintRefused(error);
|
|
3631
4187
|
}
|
|
@@ -9262,7 +9818,7 @@ var HostNotContacted = class extends Error {};
|
|
|
9262
9818
|
*/
|
|
9263
9819
|
function fixedHostsFetch(fetch) {
|
|
9264
9820
|
return async (url, options) => {
|
|
9265
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
9821
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-BV5GDiTU.js");
|
|
9266
9822
|
const host = hostOf$1(url);
|
|
9267
9823
|
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`);
|
|
9268
9824
|
return fetch(url, options);
|
|
@@ -10534,13 +11090,29 @@ async function withoutMetadata(source, size, file, read) {
|
|
|
10534
11090
|
}
|
|
10535
11091
|
return new Blob(stripPictureMetadata(whole, file.mime), { type: source.blob?.type ?? file.mime });
|
|
10536
11092
|
}
|
|
11093
|
+
/** What a forward of a message deleted meanwhile says, whether it went before the forward or while its file was copied. */
|
|
11094
|
+
var FORWARD_MESSAGE_GONE = "That message is not in this chat";
|
|
10537
11095
|
/**
|
|
10538
11096
|
* A copy of a file on this device, for sending in another chat under `file.id`: a small one whole, a larger one a
|
|
10539
11097
|
* step at a time, never whole in memory; a picture without its metadata, read whole, and a video without its. Refused
|
|
10540
11098
|
* while it is still arriving, or when its bytes are gone. Resolves to `file` as it goes: a stripped file's size is its
|
|
10541
11099
|
* copy's.
|
|
11100
|
+
*
|
|
11101
|
+
* A copy cut off because its source went meanwhile says why, as one started after would: its message deleted (here, or
|
|
11102
|
+
* for everyone by its sender, which takes its file: `messageGone`, asked only once the copy failed) is
|
|
11103
|
+
* `FORWARD_MESSAGE_GONE`, its record gone with the message still here is "not on this device any more". Only bytes
|
|
11104
|
+
* missing from a source still kept whole on record stay "shorter than it says".
|
|
10542
11105
|
*/
|
|
10543
|
-
async function copyForForward(sourceId, target) {
|
|
11106
|
+
async function copyForForward(sourceId, target, messageGone) {
|
|
11107
|
+
try {
|
|
11108
|
+
return await copyFile(sourceId, target);
|
|
11109
|
+
} catch (error) {
|
|
11110
|
+
if (await messageGone?.().catch(() => false)) throw Object.assign(/* @__PURE__ */ new Error(FORWARD_MESSAGE_GONE), { cause: error });
|
|
11111
|
+
if (!(await fileStore.get(sourceId).catch(() => ({ metadata: true })))?.metadata) throw Object.assign(/* @__PURE__ */ new Error("The file is not on this device any more"), { cause: error });
|
|
11112
|
+
throw error;
|
|
11113
|
+
}
|
|
11114
|
+
}
|
|
11115
|
+
async function copyFile(sourceId, target) {
|
|
10544
11116
|
const source = await fileStore.get(sourceId);
|
|
10545
11117
|
if (!source?.metadata) throw new Error("The file is not on this device any more");
|
|
10546
11118
|
const stored = storedSize(source);
|
|
@@ -11089,6 +11661,19 @@ var PEEK_BYTES = APP_BUNDLE_MAGIC.length + 4 + APP_BUNDLE_LIMITS.manifestBytes;
|
|
|
11089
11661
|
/** What a peek reads first: the magic, the length and any usual manifest (about 1 KiB). A longer one is read to its end after. */
|
|
11090
11662
|
var PEEK_FIRST_BYTES = 4096;
|
|
11091
11663
|
var bundleId = (digest) => `app-${digest}`;
|
|
11664
|
+
/** A bundle's signature statement: `{alg, key, sig}` with its 52-character key and 86-character signature, canonical. */
|
|
11665
|
+
var STATEMENT_BYTES = canonicalJsonBytes({
|
|
11666
|
+
alg: "ed25519",
|
|
11667
|
+
key: "y".repeat(52),
|
|
11668
|
+
sig: "A".repeat(86)
|
|
11669
|
+
}).length;
|
|
11670
|
+
/**
|
|
11671
|
+
* The length of the whole bundle of a manifest (core's `assembleAppBundle` layout: magic, u32, the canonical manifest,
|
|
11672
|
+
* u32, the statement, the files): what its stored file holds once written. A shorter or longer one is not that bundle.
|
|
11673
|
+
*/
|
|
11674
|
+
function bundleLength(manifest) {
|
|
11675
|
+
return utf8Encode(APP_BUNDLE_MAGIC).length + 8 + canonicalJsonBytes(manifest).length + STATEMENT_BYTES + manifest.files.reduce((sum, f) => sum + f.size, 0);
|
|
11676
|
+
}
|
|
11092
11677
|
/**
|
|
11093
11678
|
* The key of a scope's counter row (`AppScopeCount` as JSON in `value`, `size` 0): an app's key is never empty
|
|
11094
11679
|
* (`keyOf`), and the app's own rows of a scope are `keysOf`, which leaves it out.
|
|
@@ -11442,6 +12027,16 @@ var Apps = class {
|
|
|
11442
12027
|
/** Reads of a bundle's URL under way: an install screen opened again waits on the read the closed one began, not on a second. */
|
|
11443
12028
|
bundleReads = /* @__PURE__ */ new Map();
|
|
11444
12029
|
/**
|
|
12030
|
+
* The last write of a bundle under way, by digest: a second write of the same files (Open while the update check
|
|
12031
|
+
* fetches them, two Installs) waits for it and finds them stored, never removing the file the first one is filling.
|
|
12032
|
+
*/
|
|
12033
|
+
bundleWrites = /* @__PURE__ */ new Map();
|
|
12034
|
+
/**
|
|
12035
|
+
* Fetches of an installed app's files under way, by `ref digest`: Open or Get its files while the update check fetches
|
|
12036
|
+
* them waits for that fetch, with no download, hash or read-back of its own.
|
|
12037
|
+
*/
|
|
12038
|
+
filesFetches = /* @__PURE__ */ new Map();
|
|
12039
|
+
/**
|
|
11445
12040
|
* The `icon.png` of each checked bundle, by digest (at most 256 KiB and 1024 × 1024 pixels, or null for none): every icon shown on the Apps
|
|
11446
12041
|
* page, in a chat's cards and in the composer's Apps is read without the whole bundle again.
|
|
11447
12042
|
*/
|
|
@@ -11506,6 +12101,10 @@ var Apps = class {
|
|
|
11506
12101
|
stopped = false;
|
|
11507
12102
|
/** Bundles written by this engine (`writeBundle`), by digest: one whose record is not written yet is not swept (`sweepBundles`). */
|
|
11508
12103
|
written = /* @__PURE__ */ new Set();
|
|
12104
|
+
/** Bundle writes of this engine by digest: how many started, and how many still run (a read meanwhile may see part of one). */
|
|
12105
|
+
writes = /* @__PURE__ */ new Map();
|
|
12106
|
+
/** `bundleLength` of each installed version's manifest, by digest. */
|
|
12107
|
+
lengths = /* @__PURE__ */ new Map();
|
|
11509
12108
|
/** The sweep of `start` while it runs: a bundle written meanwhile waits for it. */
|
|
11510
12109
|
sweeping = null;
|
|
11511
12110
|
constructor(host) {
|
|
@@ -11836,10 +12435,30 @@ var Apps = class {
|
|
|
11836
12435
|
/**
|
|
11837
12436
|
* Stores a bundle's bytes. A browser that keeps no files fails here: Safari's Private Browsing (and WebKit's in-memory
|
|
11838
12437
|
* contexts) refuses a Blob in IndexedDB with "Error preparing Blob/File data to be stored in object store". Any such
|
|
11839
|
-
* failure is `storage`, with the browser's own words after it for the logs, and leaves no piece behind.
|
|
12438
|
+
* failure is `storage`, with the browser's own words after it for the logs, and leaves no piece behind. Writes of one
|
|
12439
|
+
* digest run one after the other (`bundleWrites`): a file store takes a file's pieces only in order.
|
|
11840
12440
|
*/
|
|
11841
|
-
|
|
12441
|
+
writeBundle(digest, bytes) {
|
|
11842
12442
|
this.written.add(digest);
|
|
12443
|
+
const writes = this.writes.get(digest) ?? {
|
|
12444
|
+
started: 0,
|
|
12445
|
+
running: 0
|
|
12446
|
+
};
|
|
12447
|
+
this.writes.set(digest, writes);
|
|
12448
|
+
writes.started++;
|
|
12449
|
+
writes.running++;
|
|
12450
|
+
const before = this.bundleWrites.get(digest);
|
|
12451
|
+
const write = (before ? before.catch(() => {}).then(() => this.writeBundleBytes(digest, bytes)) : this.writeBundleBytes(digest, bytes)).finally(() => {
|
|
12452
|
+
if (--writes.running === 0 && this.writes.get(digest) === writes) this.writes.delete(digest);
|
|
12453
|
+
});
|
|
12454
|
+
this.bundleWrites.set(digest, write);
|
|
12455
|
+
const done = () => {
|
|
12456
|
+
if (this.bundleWrites.get(digest) === write) this.bundleWrites.delete(digest);
|
|
12457
|
+
};
|
|
12458
|
+
write.then(done, done);
|
|
12459
|
+
return write;
|
|
12460
|
+
}
|
|
12461
|
+
async writeBundleBytes(digest, bytes) {
|
|
11843
12462
|
const id = bundleId(digest);
|
|
11844
12463
|
const expected = toBase64Url(await sha256Paced(bytes));
|
|
11845
12464
|
let files;
|
|
@@ -11882,14 +12501,23 @@ var Apps = class {
|
|
|
11882
12501
|
}
|
|
11883
12502
|
return out;
|
|
11884
12503
|
}
|
|
11885
|
-
|
|
12504
|
+
/**
|
|
12505
|
+
* Whether an installed version's files are here: a file of its whole length. One cut short (the page, the worker or
|
|
12506
|
+
* the app went away while `writeBundle` appended it) or longer is not, so Open, Get its files, the update check and
|
|
12507
|
+
* an install of the same version write it again. Its size only, no read: a list asks it of every app.
|
|
12508
|
+
*/
|
|
12509
|
+
async hasBundle(kind, digest, manifest) {
|
|
11886
12510
|
const files = await fileBytesOf(kind);
|
|
11887
|
-
|
|
12511
|
+
if (!files) return false;
|
|
12512
|
+
let length = this.lengths.get(digest);
|
|
12513
|
+
if (length === void 0) this.lengths.set(digest, length = bundleLength(manifest));
|
|
12514
|
+
return await files.size(bundleId(digest)) === length;
|
|
11888
12515
|
}
|
|
11889
12516
|
async removeBundle(kind, digest) {
|
|
11890
12517
|
this.verified.delete(digest);
|
|
11891
12518
|
this.runUsed.delete(digest);
|
|
11892
12519
|
this.icons.delete(digest);
|
|
12520
|
+
this.lengths.delete(digest);
|
|
11893
12521
|
await (await fileBytesOf(kind))?.remove(bundleId(digest)).catch(() => {});
|
|
11894
12522
|
}
|
|
11895
12523
|
/** A bundle's bytes removed unless the app's record (installed again meanwhile) holds that version, or waits for it. */
|
|
@@ -11934,10 +12562,20 @@ var Apps = class {
|
|
|
11934
12562
|
const under = this.verifying.get(app.digest);
|
|
11935
12563
|
if (under) return under;
|
|
11936
12564
|
const reading = (async () => {
|
|
12565
|
+
const writes = this.writes.get(app.digest)?.started ?? 0;
|
|
11937
12566
|
const bytes = await this.readBundleBytes(app.bytes, app.digest);
|
|
11938
12567
|
if (!bytes) fail("needs-files", "This app's files are not on this device yet");
|
|
11939
12568
|
const read = await readAppBundleAsync(bytes);
|
|
11940
|
-
if (!read.ok || read.bundle.digest !== app.digest)
|
|
12569
|
+
if (!read.ok || read.bundle.digest !== app.digest) {
|
|
12570
|
+
const now = this.writes.get(app.digest);
|
|
12571
|
+
if ((now?.started ?? 0) === writes && !now?.running) {
|
|
12572
|
+
await this.removeBundle(app.bytes, app.digest);
|
|
12573
|
+
try {
|
|
12574
|
+
this.host.checked?.([]);
|
|
12575
|
+
} catch {}
|
|
12576
|
+
}
|
|
12577
|
+
fail("damaged", "This app's stored files do not match what was installed");
|
|
12578
|
+
}
|
|
11941
12579
|
this.verified.set(app.digest, read.bundle);
|
|
11942
12580
|
this.dropUnusedBundles();
|
|
11943
12581
|
this.icons.set(app.digest, read.bundle.files.get("icon.png")?.slice() ?? null);
|
|
@@ -12627,7 +13265,7 @@ var Apps = class {
|
|
|
12627
13265
|
const added = installed ? addedAppPermissions(installed.permissions, manifest.permissions) : [...manifest.permissions];
|
|
12628
13266
|
if (added.some((p) => !shown.includes(p))) fail("permissions-changed", `This install now asks for ${added.join(", ")}; look at it again`);
|
|
12629
13267
|
if (decision === "same" && installed) {
|
|
12630
|
-
const files = await this.hasBundle(installed.bytes, digest) ? null : wrote = await this.writeBundle(digest, bytes);
|
|
13268
|
+
const files = await this.hasBundle(installed.bytes, digest, installed.manifest) ? null : wrote = await this.writeBundle(digest, bytes);
|
|
12631
13269
|
const pin = fromStore !== void 0 && installed.store !== fromStore;
|
|
12632
13270
|
if (files || pin) {
|
|
12633
13271
|
const { pending, ...rest } = installed;
|
|
@@ -12768,7 +13406,7 @@ var Apps = class {
|
|
|
12768
13406
|
}
|
|
12769
13407
|
/** One app's part of the update check (`checkNow`); null when it is not installed any more. */
|
|
12770
13408
|
async checkApp(listed, stores) {
|
|
12771
|
-
if (!await this.hasBundle(listed.bytes, listed.digest)) await this.fetchFiles({ ref: listed.ref }).catch(() => {});
|
|
13409
|
+
if (!await this.hasBundle(listed.bytes, listed.digest, listed.manifest)) await this.fetchFiles({ ref: listed.ref }).catch(() => {});
|
|
12772
13410
|
const first = await this.app(listed.ref);
|
|
12773
13411
|
if (!first) return null;
|
|
12774
13412
|
let stored = first;
|
|
@@ -12958,8 +13596,18 @@ var Apps = class {
|
|
|
12958
13596
|
*/
|
|
12959
13597
|
async fetchFiles({ ref }) {
|
|
12960
13598
|
const app = await this.installedOrFail(ref);
|
|
13599
|
+
const key = `${app.ref} ${app.digest}`;
|
|
13600
|
+
const under = this.filesFetches.get(key);
|
|
13601
|
+
if (under) return under;
|
|
13602
|
+
const fetching = this.fetchFilesOf(app).finally(() => {
|
|
13603
|
+
this.filesFetches.delete(key);
|
|
13604
|
+
});
|
|
13605
|
+
this.filesFetches.set(key, fetching);
|
|
13606
|
+
return fetching;
|
|
13607
|
+
}
|
|
13608
|
+
async fetchFilesOf(app) {
|
|
12961
13609
|
const stores = await this.stores();
|
|
12962
|
-
if (await this.hasBundle(app.bytes, app.digest)) return this.runCheckOf(app, stores);
|
|
13610
|
+
if (await this.hasBundle(app.bytes, app.digest, app.manifest)) return this.runCheckOf(app, stores);
|
|
12963
13611
|
const carried = this.builtIn(app.ref);
|
|
12964
13612
|
if (carried && carried.digest === app.digest) {
|
|
12965
13613
|
const held = await this.bundled(carried).catch(() => null);
|
|
@@ -13017,7 +13665,7 @@ var Apps = class {
|
|
|
13017
13665
|
return { status: "needs-files" };
|
|
13018
13666
|
}
|
|
13019
13667
|
async runCheckOf(app, stores) {
|
|
13020
|
-
if (!await this.hasBundle(app.bytes, app.digest)) return { status: "needs-files" };
|
|
13668
|
+
if (!await this.hasBundle(app.bytes, app.digest, app.manifest)) return { status: "needs-files" };
|
|
13021
13669
|
return this.runStatus(app, this.storeViews(stores), app.revocations);
|
|
13022
13670
|
}
|
|
13023
13671
|
/** Before an app runs (WISP 1200 § Takedowns): revoked stops it, removed by a store of the person's warns. No request. */
|
|
@@ -13597,6 +14245,7 @@ function isPush(value) {
|
|
|
13597
14245
|
function isEarlierSet(value) {
|
|
13598
14246
|
const set = value;
|
|
13599
14247
|
if (!set || typeof set !== "object" || !bytes(set.d) || !bytes(set.tombstone) || !text(set.setUpdate) || !Array.isArray(set.pending) || !set.pending.every(bytes)) return false;
|
|
14248
|
+
if (set.delivered !== void 0 && (!Array.isArray(set.delivered) || set.delivered.length > 36 || !set.delivered.every((entry) => !!entry && typeof entry === "object" && bytes(entry.key) && bytes(entry.d)))) return false;
|
|
13600
14249
|
return set.pending.length <= 4 && (set.foreign === void 0 || set.foreign === true) && optional(set.removed, bytes);
|
|
13601
14250
|
}
|
|
13602
14251
|
/** Why a stored record cannot be trusted. The gate then starts nothing (see `gate.ts`). */
|
|
@@ -14946,6 +15595,16 @@ function tombstoneBelieved(record, tombstone) {
|
|
|
14946
15595
|
const key = toBase64Url(author.key);
|
|
14947
15596
|
return key === (record.activeSlot === void 0 ? void 0 : record.deviceSet[record.activeSlot]?.key) || key === record.handoff?.release?.to || key === record.handoff?.peer;
|
|
14948
15597
|
}
|
|
15598
|
+
/**
|
|
15599
|
+
* Whether a tombstone leaves this device with no exit but enrolling anew: it does not list this device, it is not
|
|
15600
|
+
* believed, and this device holds no copy to start a set of its own from. It may be the real tombstone of a device the
|
|
15601
|
+
* profile moved to while this one was off: that device sends no frame to a device it removed, and the device this one
|
|
15602
|
+
* believes signs nothing any more. A forged one ends nothing either way: a `set-update` the believed device signs is
|
|
15603
|
+
* still accepted (WISP 06 § Removing a device).
|
|
15604
|
+
*/
|
|
15605
|
+
function stranded(record, read) {
|
|
15606
|
+
return read.result === "tombstone" && !!read.record && read.listed === false && !record.copy && !tombstoneBelieved(record, read.record);
|
|
15607
|
+
}
|
|
14949
15608
|
/** The record's slots as the device state keeps them. */
|
|
14950
15609
|
function deviceSetOf(record) {
|
|
14951
15610
|
return record.slots.map((slot) => slot && {
|
|
@@ -15450,7 +16109,7 @@ var TurnKeeper = class {
|
|
|
15450
16109
|
} : {};
|
|
15451
16110
|
const tombstoned = state === "moving" && read.result === "tombstone" && read.record && read.payload ? {
|
|
15452
16111
|
tombstone: toBase64Url(read.payload),
|
|
15453
|
-
...storedActiveListed(held.record, read.record) || foreign && ran ? {} : { reenroll: true }
|
|
16112
|
+
...(storedActiveListed(held.record, read.record) || foreign && ran) && (ran || !stranded(held.record, read)) ? {} : { reenroll: true }
|
|
15454
16113
|
} : {};
|
|
15455
16114
|
const stopped = won && held.record.handoff?.peer ? held.record.deviceSet.find((slot) => slot?.key === held.record.handoff.peer) : void 0;
|
|
15456
16115
|
held.record = await this.store.move(this.options.profile, state, {
|
|
@@ -15519,12 +16178,14 @@ var TurnKeeper = class {
|
|
|
15519
16178
|
kind: "wait",
|
|
15520
16179
|
read
|
|
15521
16180
|
};
|
|
15522
|
-
case "stay":
|
|
15523
|
-
|
|
15524
|
-
|
|
15525
|
-
|
|
15526
|
-
|
|
15527
|
-
|
|
16181
|
+
case "stay":
|
|
16182
|
+
if (held.record.state === "moving" && !held.record.reenroll && stranded(held.record, read)) held.record = await this.store.amend(this.options.profile, { reenroll: true });
|
|
16183
|
+
return {
|
|
16184
|
+
kind: "stay",
|
|
16185
|
+
offers: action.offers,
|
|
16186
|
+
...action.awaits ? { awaits: action.awaits } : {},
|
|
16187
|
+
read
|
|
16188
|
+
};
|
|
15528
16189
|
case "impossible": return {
|
|
15529
16190
|
kind: "impossible",
|
|
15530
16191
|
row,
|
|
@@ -16726,10 +17387,39 @@ function wakeOwnerOf(current, self) {
|
|
|
16726
17387
|
if (!current?.device || !self) return void 0;
|
|
16727
17388
|
return current.device === self ? "here" : "away";
|
|
16728
17389
|
}
|
|
17390
|
+
/** The most of a push relay's own error text kept to show the person (`PushRelayRefusal.text`). */
|
|
17391
|
+
var RELAY_TEXT_CHARS = 120;
|
|
17392
|
+
/**
|
|
17393
|
+
* The push relay answered, but not with a push service's status: its own refusal (403 `Origin not allowed`, 400 naming
|
|
17394
|
+
* a header, 429), a web page or JSON without `status` (a wrong address or path, a proxy with no route). `text` is the
|
|
17395
|
+
* relay's own `{ error }` text when it gave one, on one line and cut to `RELAY_TEXT_CHARS`; a web page gives none.
|
|
17396
|
+
*/
|
|
17397
|
+
var PushRelayRefusal = class extends Error {
|
|
17398
|
+
http;
|
|
17399
|
+
text;
|
|
17400
|
+
cause;
|
|
17401
|
+
constructor(http, text, cause) {
|
|
17402
|
+
super(`The push relay did not forward it (HTTP ${http})`);
|
|
17403
|
+
this.http = http;
|
|
17404
|
+
this.text = text;
|
|
17405
|
+
this.cause = cause;
|
|
17406
|
+
this.name = "PushRelayRefusal";
|
|
17407
|
+
}
|
|
17408
|
+
};
|
|
17409
|
+
/** The relay's own `{ error: "..." }` text in `body`, one line, cut; undefined when it gave none. */
|
|
17410
|
+
function relayErrorText(body) {
|
|
17411
|
+
const error = body && typeof body === "object" ? body.error : void 0;
|
|
17412
|
+
if (typeof error !== "string") return void 0;
|
|
17413
|
+
const line = error.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u200e\u200f\u202a-\u202e\u2066-\u2069]+/g, " ").replace(/\s+/g, " ").trim();
|
|
17414
|
+
if (!line) return void 0;
|
|
17415
|
+
const chars = [...line];
|
|
17416
|
+
return chars.length > RELAY_TEXT_CHARS ? `${chars.slice(0, 119).join("")}…` : line;
|
|
17417
|
+
}
|
|
16729
17418
|
/**
|
|
16730
17419
|
* Posts a push: the host's way (Desktop and the CLI post it themselves), or `fetch`, then the person's push relay when
|
|
16731
|
-
* a page may not post it (the push services answer without CORS). Answers the push service's HTTP status; throws
|
|
16732
|
-
* the relay
|
|
17420
|
+
* a page may not post it (the push services answer without CORS). Answers the push service's HTTP status; throws a
|
|
17421
|
+
* `PushRelayRefusal` when the relay answers without it (`relayed` is told when it answers with it), and the fetch's
|
|
17422
|
+
* own error when the relay cannot be reached at all.
|
|
16733
17423
|
*/
|
|
16734
17424
|
async function postPush(request, options) {
|
|
16735
17425
|
if (options.pushSend) return options.pushSend(request);
|
|
@@ -16755,8 +17445,9 @@ async function postPush(request, options) {
|
|
|
16755
17445
|
signal: AbortSignal.timeout(15e3),
|
|
16756
17446
|
...quiet
|
|
16757
17447
|
});
|
|
16758
|
-
const answer =
|
|
16759
|
-
if (typeof answer?.status !== "number") throw
|
|
17448
|
+
const answer = await response.json().catch(() => null);
|
|
17449
|
+
if (!response.ok || typeof answer?.status !== "number") throw new PushRelayRefusal(response.status, relayErrorText(answer), error);
|
|
17450
|
+
options.relayed?.();
|
|
16760
17451
|
return answer.status;
|
|
16761
17452
|
}
|
|
16762
17453
|
}
|
|
@@ -16863,10 +17554,10 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16863
17554
|
by = readSetUpdate(JSON.parse(set.setUpdate))?.by;
|
|
16864
17555
|
} catch {}
|
|
16865
17556
|
if (!by || !bytesEqual(by, signer.publicKey)) {
|
|
16866
|
-
earlier.push({
|
|
17557
|
+
earlier.push(withDelivered({
|
|
16867
17558
|
...set,
|
|
16868
17559
|
pending
|
|
16869
|
-
});
|
|
17560
|
+
}, []));
|
|
16870
17561
|
continue;
|
|
16871
17562
|
}
|
|
16872
17563
|
const setKeys = turnKeys(fromBase64Url(set.d)), tombBytes = fromBase64Url(set.tombstone);
|
|
@@ -16880,11 +17571,11 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16880
17571
|
set: kept,
|
|
16881
17572
|
tomb: tombBytes
|
|
16882
17573
|
}, signer)) : set.setUpdate;
|
|
16883
|
-
earlier.push({
|
|
17574
|
+
earlier.push(withDelivered({
|
|
16884
17575
|
...set,
|
|
16885
17576
|
pending,
|
|
16886
17577
|
setUpdate
|
|
16887
|
-
});
|
|
17578
|
+
}, []));
|
|
16888
17579
|
}
|
|
16889
17580
|
earlier.push({
|
|
16890
17581
|
d: record.d,
|
|
@@ -17044,10 +17735,37 @@ function pendingFrames(record) {
|
|
|
17044
17735
|
*/
|
|
17045
17736
|
function acknowledged(record, key, d) {
|
|
17046
17737
|
if (!record?.earlierSets.some((set) => (d === void 0 || set.d === d) && set.pending.includes(key))) return null;
|
|
17047
|
-
return { earlierSets: record.earlierSets.map((set) => d === void 0 || set.d === d ? {
|
|
17738
|
+
return { earlierSets: record.earlierSets.map((set) => d === void 0 || set.d === d ? withDelivered({
|
|
17048
17739
|
...set,
|
|
17049
17740
|
pending: set.pending.filter((k) => k !== key)
|
|
17050
|
-
} : set) };
|
|
17741
|
+
}, []) : set) };
|
|
17742
|
+
}
|
|
17743
|
+
/**
|
|
17744
|
+
* The record once the frame of the set under `d` went to `key` over a live link (`EarlierDeviceSet.delivered`): the
|
|
17745
|
+
* device may hold the secret that frame names, and keep it if its `set-ack` is lost. Null when that is noted already.
|
|
17746
|
+
*/
|
|
17747
|
+
function delivered(record, key, d) {
|
|
17748
|
+
const set = record?.earlierSets.find((s) => s.d === d && s.pending.includes(key));
|
|
17749
|
+
let named;
|
|
17750
|
+
try {
|
|
17751
|
+
const update = set && readSetUpdate(JSON.parse(set.setUpdate));
|
|
17752
|
+
if (update) named = toBase64Url(update.d);
|
|
17753
|
+
} catch {}
|
|
17754
|
+
if (!record || !set || named === void 0 || set.delivered?.some((e) => e.key === key && e.d === named)) return null;
|
|
17755
|
+
const kept = /* @__PURE__ */ new Set([record.d, ...record.earlierSets.map((s) => s.d)]);
|
|
17756
|
+
return { earlierSets: record.earlierSets.map((s) => s === set ? withDelivered(s, [{
|
|
17757
|
+
key,
|
|
17758
|
+
d: named
|
|
17759
|
+
}], kept) : s) };
|
|
17760
|
+
}
|
|
17761
|
+
/** `set` with `more` delivered, and only entries of devices still pending under a secret the record keeps (`kept`). */
|
|
17762
|
+
function withDelivered(set, more, kept) {
|
|
17763
|
+
const { delivered: was, ...rest } = set;
|
|
17764
|
+
const entries = [...was ?? [], ...more].filter((e) => set.pending.includes(e.key) && (!kept || kept.has(e.d)));
|
|
17765
|
+
return entries.length ? {
|
|
17766
|
+
...rest,
|
|
17767
|
+
delivered: entries
|
|
17768
|
+
} : rest;
|
|
17051
17769
|
}
|
|
17052
17770
|
//#endregion
|
|
17053
17771
|
//#region ../browser/src/devices/takeover.ts
|
|
@@ -17364,6 +18082,14 @@ async function supersedeOwnTombstone(ports, before, removerTomb) {
|
|
|
17364
18082
|
}
|
|
17365
18083
|
//#endregion
|
|
17366
18084
|
//#region ../browser/src/devices/restoreGuard.ts
|
|
18085
|
+
/**
|
|
18086
|
+
* The slot a bundle names active, or undefined when it names none: a bundle from before the field, or a value that is
|
|
18087
|
+
* not the index of a device in its set (a damaged copy names no device rather than a wrong one).
|
|
18088
|
+
*/
|
|
18089
|
+
function bundleActiveSlot(devices) {
|
|
18090
|
+
const at = devices?.active;
|
|
18091
|
+
return typeof at === "number" && Number.isSafeInteger(at) && at >= 0 && at < 4 && !!devices.set[at] ? at : void 0;
|
|
18092
|
+
}
|
|
17367
18093
|
/** Reads the turn at the address of `d`, as a device that holds no record of the set yet. */
|
|
17368
18094
|
async function peekTurn(d, network) {
|
|
17369
18095
|
const keys = turnKeys(d);
|
|
@@ -17402,7 +18128,7 @@ function restoredStandby(devices, didSeed, peek, ownKey, name) {
|
|
|
17402
18128
|
if (!d) throw new Error("This backup leads to no device set");
|
|
17403
18129
|
const listed = peek?.record?.slots ?? devices?.set ?? [];
|
|
17404
18130
|
const set = Array.from({ length: 4 }, (_, i) => listed[i] ?? null);
|
|
17405
|
-
const active = peek?.record && peek.record.active < 4 ? peek.record.active :
|
|
18131
|
+
const active = peek?.record && peek.record.active < 4 ? peek.record.active : bundleActiveSlot(devices) ?? -1;
|
|
17406
18132
|
let own = set.findIndex((slot) => !slot);
|
|
17407
18133
|
if (own < 0) own = active >= 0 ? active : 0;
|
|
17408
18134
|
set[own] = {
|
|
@@ -17880,7 +18606,8 @@ var DeviceLinks = class {
|
|
|
17880
18606
|
for (const staying of record.deviceSet) {
|
|
17881
18607
|
if (!staying || staying.key === own) continue;
|
|
17882
18608
|
const key = staying.key;
|
|
17883
|
-
|
|
18609
|
+
const took = record.earlierSets.flatMap((set) => set.pending.includes(key) ? (set.delivered ?? []).filter((e) => e.key === key).map((e) => pendingFor(key, e.d)) : []);
|
|
18610
|
+
for (const start of [pendingFor(key), ...took]) for (let set = start; set;) {
|
|
17884
18611
|
const id = `${set.d}|${key}`;
|
|
17885
18612
|
if (wanted.some((w) => w.id === id)) break;
|
|
17886
18613
|
wanted.push({
|
|
@@ -18288,7 +19015,10 @@ var DeviceLinks = class {
|
|
|
18288
19015
|
if (pending.d !== running.d || pending.key !== running.key) continue;
|
|
18289
19016
|
try {
|
|
18290
19017
|
running.link.sendDeviceFrame(pending.frame);
|
|
18291
|
-
} catch {
|
|
19018
|
+
} catch {
|
|
19019
|
+
continue;
|
|
19020
|
+
}
|
|
19021
|
+
if (record.state === "active" && delivered(record, pending.key, pending.d)) await amendDevice(this.options.profile, (current) => delivered(current, pending.key, pending.d));
|
|
18292
19022
|
}
|
|
18293
19023
|
return;
|
|
18294
19024
|
}
|
|
@@ -19693,6 +20423,10 @@ var HandoffGiver = class {
|
|
|
19693
20423
|
this.pake = null;
|
|
19694
20424
|
this.secret = null;
|
|
19695
20425
|
this.bundleMade = null;
|
|
20426
|
+
this.haveBuffer = {
|
|
20427
|
+
d: [],
|
|
20428
|
+
p: {}
|
|
20429
|
+
};
|
|
19696
20430
|
this.offerHellos.clear();
|
|
19697
20431
|
this.sender = new PartSender(this.now);
|
|
19698
20432
|
}
|
|
@@ -19707,6 +20441,10 @@ var HandoffGiver = class {
|
|
|
19707
20441
|
this.refused = refused;
|
|
19708
20442
|
this.pake = null;
|
|
19709
20443
|
this.have = null;
|
|
20444
|
+
this.haveBuffer = {
|
|
20445
|
+
d: [],
|
|
20446
|
+
p: {}
|
|
20447
|
+
};
|
|
19710
20448
|
this.planned = null;
|
|
19711
20449
|
this.secret = null;
|
|
19712
20450
|
this.bundleMade = null;
|
|
@@ -19822,7 +20560,7 @@ async function room() {
|
|
|
19822
20560
|
async function handoffSelf(profileHost) {
|
|
19823
20561
|
return {
|
|
19824
20562
|
app: profileHost.app.replace(/[^0-9A-Za-z.+_-]/g, "").slice(0, 40) || "0",
|
|
19825
|
-
db:
|
|
20563
|
+
db: 16,
|
|
19826
20564
|
pins: { ...WALLET_SDK_PINS },
|
|
19827
20565
|
kind: profileHost.kind,
|
|
19828
20566
|
room: await room(),
|
|
@@ -21098,7 +21836,10 @@ var FileDesk = class {
|
|
|
21098
21836
|
const offset = Math.min(have, record.confirmed);
|
|
21099
21837
|
if (have > offset) await bytes.truncate(id, offset);
|
|
21100
21838
|
if (size === null && record.file.size === 0) await bytes.append(id, 0, /* @__PURE__ */ new Uint8Array());
|
|
21101
|
-
if (stored && stored.bytes !== bytes.kind) await fileStore.patch(id, {
|
|
21839
|
+
if (stored && (stored.bytes !== bytes.kind || stored.leftOut)) await fileStore.patch(id, {
|
|
21840
|
+
bytes: bytes.kind,
|
|
21841
|
+
...stored.leftOut && { leftOut: false }
|
|
21842
|
+
});
|
|
21102
21843
|
const appender = new FileAppender(bytes, id, offset);
|
|
21103
21844
|
return {
|
|
21104
21845
|
offset,
|
|
@@ -21615,14 +22356,6 @@ function forgetWallet(records, id) {
|
|
|
21615
22356
|
return rest;
|
|
21616
22357
|
}
|
|
21617
22358
|
//#endregion
|
|
21618
|
-
//#region ../browser/src/shared/messageChanges.ts
|
|
21619
|
-
/** A row as a page gets it: without the frame a private group's message came in (`StoredMessage.frame`), which only the engine reads. */
|
|
21620
|
-
function withoutFrame(message) {
|
|
21621
|
-
if (message.frame === void 0) return message;
|
|
21622
|
-
const { frame: _frame, ...row } = message;
|
|
21623
|
-
return row;
|
|
21624
|
-
}
|
|
21625
|
-
//#endregion
|
|
21626
22359
|
//#region ../browser/src/shared/buttons.ts
|
|
21627
22360
|
/** The buttons of a message, when it has any. */
|
|
21628
22361
|
function messageButtons(message) {
|
|
@@ -21813,6 +22546,20 @@ var KEPT_CANCELLED = 1e3;
|
|
|
21813
22546
|
var DEADLINE_SKEW_MS = 6e4;
|
|
21814
22547
|
/** The longest delay a timer keeps: past it (about 24.8 days) `setTimeout` fires at once, in Node and in browsers. */
|
|
21815
22548
|
var MAX_TIMER_MS = 2 ** 31 - 1;
|
|
22549
|
+
/**
|
|
22550
|
+
* A clock in ms that keeps counting while the machine is suspended, where the platform has one apart from the wall
|
|
22551
|
+
* clock: Linux's boot time (`os.uptime()` reads `CLOCK_BOOTTIME`) for Node on Linux. Node's monotonic clock there
|
|
22552
|
+
* (`CLOCK_MONOTONIC`, what `performance.now()` reads) stands still in a suspend, so a session that slept and a wall
|
|
22553
|
+
* clock set forward looked the same to `Outbox.clock`. On macOS Node's monotonic clock counts sleep already, and a
|
|
22554
|
+
* browser or Android's WebView has no such clock: none there (`Outbox.clock` counts the time it ran).
|
|
22555
|
+
*/
|
|
22556
|
+
function bootClock() {
|
|
22557
|
+
const host = globalThis.process;
|
|
22558
|
+
if (host?.platform !== "linux" || typeof host.getBuiltinModule !== "function") return void 0;
|
|
22559
|
+
const uptime = host.getBuiltinModule("node:os")?.uptime;
|
|
22560
|
+
if (typeof uptime !== "function") return void 0;
|
|
22561
|
+
return () => uptime() * 1e3;
|
|
22562
|
+
}
|
|
21816
22563
|
/** The most rows a new message's look reads one by one (`Outbox.look`), where the store cannot read them in one go. */
|
|
21817
22564
|
var KNOWN_ROWS = 16;
|
|
21818
22565
|
/**
|
|
@@ -21850,7 +22597,7 @@ var Outbox = class {
|
|
|
21850
22597
|
* Queued: when it is looked at again, how far along the backoff, since when. `at` and `since` are on the monotonic
|
|
21851
22598
|
* clock (`monotonic`): they live only in this session, and a step of the device clock must not move them. Read by the
|
|
21852
22599
|
* wall clock, a clock set back an hour after a text was queued handed it to store-and-forward an hour late, not at
|
|
21853
|
-
* its first check past a minute (`holdAfterMs`).
|
|
22600
|
+
* its first check past a minute (`holdAfterMs`). `wallSince`: the same moment by the wall clock (`waitedOut`).
|
|
21854
22601
|
*/
|
|
21855
22602
|
waiting = /* @__PURE__ */ new Map();
|
|
21856
22603
|
/**
|
|
@@ -21915,7 +22662,9 @@ var Outbox = class {
|
|
|
21915
22662
|
policy;
|
|
21916
22663
|
now;
|
|
21917
22664
|
monotonic;
|
|
21918
|
-
/**
|
|
22665
|
+
/** A clock that counts a suspend (`bootClock`), where the platform has one. */
|
|
22666
|
+
boot;
|
|
22667
|
+
/** The wall, monotonic and boot clocks when this outbox began: `clock` counts on from there. */
|
|
21919
22668
|
origin;
|
|
21920
22669
|
constructor(store, send, timeoutMs = 2e4, pendingUntil, options = {}) {
|
|
21921
22670
|
this.store = store;
|
|
@@ -21929,18 +22678,34 @@ var Outbox = class {
|
|
|
21929
22678
|
};
|
|
21930
22679
|
this.now = options.now ?? Date.now;
|
|
21931
22680
|
this.monotonic = options.monotonic ?? (() => performance.now());
|
|
22681
|
+
this.boot = options.boot === void 0 ? bootClock() : options.boot ?? void 0;
|
|
21932
22682
|
this.origin = {
|
|
21933
22683
|
wall: this.now(),
|
|
21934
|
-
monotonic: this.monotonic()
|
|
22684
|
+
monotonic: this.monotonic(),
|
|
22685
|
+
boot: this.boot?.()
|
|
21935
22686
|
};
|
|
21936
22687
|
}
|
|
21937
22688
|
/**
|
|
21938
22689
|
* The time a stored deadline (`resendUntil`, set by the wall clock) is judged by: the wall clock, never ahead of the
|
|
21939
|
-
* time
|
|
21940
|
-
* as not confirmed within 7 days, a few seconds after it was written.
|
|
22690
|
+
* time that passed since this session began. A clock set forward 8 days failed every queued text at its next check,
|
|
22691
|
+
* as not confirmed within 7 days, a few seconds after it was written. The time that passed counts a suspend where a
|
|
22692
|
+
* clock says so (`bootClock`): a laptop asleep 9 days fails a text queued before at its first check after the wake,
|
|
22693
|
+
* where it went on a week of the machine awake. Elsewhere it is the time the session ran.
|
|
21941
22694
|
*/
|
|
21942
22695
|
clock() {
|
|
21943
|
-
|
|
22696
|
+
let passed = this.monotonic() - this.origin.monotonic;
|
|
22697
|
+
if (this.boot && this.origin.boot !== void 0) passed = Math.max(passed, this.boot() - this.origin.boot);
|
|
22698
|
+
return Math.min(this.now(), this.origin.wall + passed);
|
|
22699
|
+
}
|
|
22700
|
+
/**
|
|
22701
|
+
* Queued a minute (`holdAfterMs`), so it may be handed to store-and-forward: by the monotonic clock or by the wall
|
|
22702
|
+
* clock, whichever counts more. A clock set back must not delay it (the monotonic clock counts), and a suspend must
|
|
22703
|
+
* not either: on Linux and Android the monotonic clock stands still in one, and a text queued before a night asleep
|
|
22704
|
+
* waited out its minute again after the wake. A clock set forward hands it over at its next check: harmless, a text to
|
|
22705
|
+
* an away contact goes there anyway.
|
|
22706
|
+
*/
|
|
22707
|
+
waitedOut(wait) {
|
|
22708
|
+
return Math.max(this.monotonic() - wait.since, this.now() - wait.wallSince) >= this.policy.holdAfterMs;
|
|
21944
22709
|
}
|
|
21945
22710
|
/**
|
|
21946
22711
|
* Its window to go is over (`resendUntil`, by `clock`). A deadline further ahead than a whole window was set before
|
|
@@ -22153,11 +22918,11 @@ var Outbox = class {
|
|
|
22153
22918
|
* receipt and nothing waiting read the chat's whole history for nothing, twice (the link says it is open in two
|
|
22154
22919
|
* ways): 600 ms of a daemon's time per reconnect at 10,000 messages (agents#2468).
|
|
22155
22920
|
*/
|
|
22156
|
-
async held() {
|
|
22921
|
+
async held(id) {
|
|
22157
22922
|
this.looks++;
|
|
22158
22923
|
const at = this.writes ? void 0 : this.stamp;
|
|
22159
22924
|
try {
|
|
22160
|
-
const messages = await this.look();
|
|
22925
|
+
const messages = await this.look(id);
|
|
22161
22926
|
if (at !== void 0 && !messages.some((m) => this.unknown(m))) this.seen = at;
|
|
22162
22927
|
return messages;
|
|
22163
22928
|
} finally {
|
|
@@ -22400,7 +23165,7 @@ var Outbox = class {
|
|
|
22400
23165
|
async check(id) {
|
|
22401
23166
|
if (this.stopped) return;
|
|
22402
23167
|
if (!this.waiting.has(id) || this.waiting.get(id)?.timer || this.receipts.has(id)) return;
|
|
22403
|
-
const messages = await this.
|
|
23168
|
+
const messages = await this.held(id), message = messages.find((m) => m.id === id);
|
|
22404
23169
|
if (!message || !(toGo(message) || this.file(message))) {
|
|
22405
23170
|
await this.attempt(id);
|
|
22406
23171
|
return;
|
|
@@ -22430,7 +23195,7 @@ var Outbox = class {
|
|
|
22430
23195
|
*/
|
|
22431
23196
|
waitsOn(message) {
|
|
22432
23197
|
const wait = this.waiting.get(message.id);
|
|
22433
|
-
return !!wait && (message.delivery === "queued" || message.delivery === "waiting") && message.via !== "hold" && !this.pastDeadline(message) && !this.resender.ready(message) && !(this.resender.divert && this.
|
|
23198
|
+
return !!wait && (message.delivery === "queued" || message.delivery === "waiting") && message.via !== "hold" && !this.pastDeadline(message) && !this.resender.ready(message) && !(this.resender.divert && this.waitedOut(wait));
|
|
22434
23199
|
}
|
|
22435
23200
|
/**
|
|
22436
23201
|
* A queued or waiting message is looked at; one sent and awaiting its receipt goes again now, if the chat can carry
|
|
@@ -22526,7 +23291,7 @@ var Outbox = class {
|
|
|
22526
23291
|
await this.transmitNow(id);
|
|
22527
23292
|
return true;
|
|
22528
23293
|
}
|
|
22529
|
-
if (this.resender.divert && wait && this.
|
|
23294
|
+
if (this.resender.divert && wait && this.waitedOut(wait) && await this.resender.divert(message)) {
|
|
22530
23295
|
this.forget(id);
|
|
22531
23296
|
return true;
|
|
22532
23297
|
}
|
|
@@ -22605,6 +23370,7 @@ var Outbox = class {
|
|
|
22605
23370
|
const wait = this.waiting.get(id) ?? {
|
|
22606
23371
|
step: 0,
|
|
22607
23372
|
since: this.monotonic(),
|
|
23373
|
+
wallSince: this.now(),
|
|
22608
23374
|
at: 0
|
|
22609
23375
|
};
|
|
22610
23376
|
if (wait.timer) clearTimeout(wait.timer);
|
|
@@ -22628,6 +23394,7 @@ var Outbox = class {
|
|
|
22628
23394
|
if (!wait) this.waiting.set(id, {
|
|
22629
23395
|
step: 0,
|
|
22630
23396
|
since: this.monotonic(),
|
|
23397
|
+
wallSince: this.now(),
|
|
22631
23398
|
at: 0
|
|
22632
23399
|
});
|
|
22633
23400
|
}
|
|
@@ -23302,7 +24069,7 @@ var TARGETED = /* @__PURE__ */ new Set([
|
|
|
23302
24069
|
* close. A request of ours counts only for the wallet it can be paid through, and only when there is one: a request a
|
|
23303
24070
|
* Cashu mint and another Lightning source can both be paid through is not lost when one of them goes.
|
|
23304
24071
|
*/
|
|
23305
|
-
function walletAwaiting({ network, mints, quotes, lightningOps, lightningSource, lightningCard, lightningOwner = (op) => op.card, payments, now }) {
|
|
24072
|
+
function walletAwaiting({ network, mints, quotes, lightningOps, lightningSource, lightningCard, lightningOwner = (op) => op.card, payments, now, chatGone }) {
|
|
23306
24073
|
const at = new Set(mints);
|
|
23307
24074
|
const live = (expiresAt) => !expiresAt || expiresAt + GRACE_MS > now;
|
|
23308
24075
|
const invoiceKey = (invoice) => invoice.trim().toLowerCase();
|
|
@@ -23400,12 +24167,14 @@ function walletAwaiting({ network, mints, quotes, lightningOps, lightningSource,
|
|
|
23400
24167
|
}
|
|
23401
24168
|
for (const p of payments) {
|
|
23402
24169
|
if (p.kind !== "payment" || p.direction !== "out" || p.state !== "pending" || !p.token) continue;
|
|
24170
|
+
const gone = chatGone?.(p.id) ? { chatGone: true } : {};
|
|
23403
24171
|
if (p.target?.method === "fedimint" || p.federation) {
|
|
23404
24172
|
if (paymentNetwork(p) === network) out.push({
|
|
23405
24173
|
type: "fedimint",
|
|
23406
24174
|
kind: "sent",
|
|
23407
24175
|
amount: p.amount,
|
|
23408
|
-
paymentId: p.id
|
|
24176
|
+
paymentId: p.id,
|
|
24177
|
+
...gone
|
|
23409
24178
|
});
|
|
23410
24179
|
continue;
|
|
23411
24180
|
}
|
|
@@ -23414,7 +24183,8 @@ function walletAwaiting({ network, mints, quotes, lightningOps, lightningSource,
|
|
|
23414
24183
|
type: "cashu",
|
|
23415
24184
|
kind: "sent",
|
|
23416
24185
|
amount: p.amount,
|
|
23417
|
-
paymentId: p.id
|
|
24186
|
+
paymentId: p.id,
|
|
24187
|
+
...gone
|
|
23418
24188
|
});
|
|
23419
24189
|
}
|
|
23420
24190
|
return out;
|
|
@@ -23445,445 +24215,15 @@ function mintAwaiting(mint, sources) {
|
|
|
23445
24215
|
*/
|
|
23446
24216
|
/** What one press asks a test mint for: small, fixed, worth nothing. */
|
|
23447
24217
|
var TEST_COINS_SATS = 1e4;
|
|
23448
|
-
/** A faucet's failure in words a person can act on: rate limited says to wait, anything else says what failed. */
|
|
24218
|
+
/** A faucet's failure in words a person can act on: rate limited says to wait, a failed mint to try later, anything else says what failed. */
|
|
23449
24219
|
function faucetError(error) {
|
|
24220
|
+
if (error?.engineCode === "mintFailedFaucet") return error;
|
|
23450
24221
|
const message = error instanceof Error ? error.message : String(error);
|
|
23451
24222
|
if (error?.status === 429 || /\b429\b|rate.?limit|too many requests/i.test(message)) return /* @__PURE__ */ new Error("Rate limited: the faucet is busy. Try again in a minute.");
|
|
23452
24223
|
if (/failed to fetch|networkerror|did not answer|load failed/i.test(message)) return /* @__PURE__ */ new Error(`The faucet did not answer: ${message}`);
|
|
23453
24224
|
return /* @__PURE__ */ new Error(`The faucet did not pay: ${message}`);
|
|
23454
24225
|
}
|
|
23455
24226
|
//#endregion
|
|
23456
|
-
//#region ../browser/src/engine/db.ts
|
|
23457
|
-
/**
|
|
23458
|
-
* The newest `count` rows of an index range, newest first: one descending read where IndexedDB has it (the options
|
|
23459
|
-
* that came with `getAllRecords`), else a cursor from the end.
|
|
23460
|
-
*/
|
|
23461
|
-
function newestMessages(index, query, count) {
|
|
23462
|
-
if (typeof index.getAllRecords === "function") return wrap(index.getAll({
|
|
23463
|
-
query,
|
|
23464
|
-
count,
|
|
23465
|
-
direction: "prev"
|
|
23466
|
-
}));
|
|
23467
|
-
return new Promise((resolve, reject) => {
|
|
23468
|
-
const rows = [];
|
|
23469
|
-
const request = index.openCursor(query, "prev");
|
|
23470
|
-
request.onerror = () => reject(request.error);
|
|
23471
|
-
request.onsuccess = () => {
|
|
23472
|
-
const cursor = request.result;
|
|
23473
|
-
if (cursor) rows.push(cursor.value);
|
|
23474
|
-
if (!cursor || rows.length >= count) resolve(rows);
|
|
23475
|
-
else cursor.continue();
|
|
23476
|
-
};
|
|
23477
|
-
});
|
|
23478
|
-
}
|
|
23479
|
-
/** A write that waits for no disk sync of its own (in a browser, the engine's default already; on Node, the CLI's store). */
|
|
23480
|
-
var RELAXED = { durability: "relaxed" };
|
|
23481
|
-
var CHANGED = Symbol("changed");
|
|
23482
|
-
/**
|
|
23483
|
-
* A chat's pinned key, for the transaction that checks and changes it, and the seals of the keys that change writes.
|
|
23484
|
-
* Sealed (the data key is set), it is opened before the transaction, and holds inside it only while the row still has
|
|
23485
|
-
* the sealed value that was opened: `CHANGED` otherwise.
|
|
23486
|
-
*/
|
|
23487
|
-
async function pinnedKey(linkId, key) {
|
|
23488
|
-
const seals = new RowSeals();
|
|
23489
|
-
if (!seals.on) return {
|
|
23490
|
-
seals,
|
|
23491
|
-
pinned: (link) => link?.pairedPeerKey
|
|
23492
|
-
};
|
|
23493
|
-
const seen = await wrap((await store(STORES$1.links, "readonly")).get(linkId));
|
|
23494
|
-
const opened = await openRow(STORES$1.links, seen);
|
|
23495
|
-
await seals.prepare(STORES$1.links, [{
|
|
23496
|
-
id: linkId,
|
|
23497
|
-
pairedPeerKey: key,
|
|
23498
|
-
peerTrust: { verifiedKey: key }
|
|
23499
|
-
}, {
|
|
23500
|
-
id: linkId,
|
|
23501
|
-
peerTrust: { verifiedKey: opened?.pairedPeerKey }
|
|
23502
|
-
}]);
|
|
23503
|
-
const then = JSON.stringify(seen?.pairedPeerKey);
|
|
23504
|
-
return {
|
|
23505
|
-
seals,
|
|
23506
|
-
pinned: (link) => JSON.stringify(link?.pairedPeerKey) === then ? opened?.pairedPeerKey : CHANGED
|
|
23507
|
-
};
|
|
23508
|
-
}
|
|
23509
|
-
/**
|
|
23510
|
-
* Durable local state of the browser peer. Identity seeds live here the same
|
|
23511
|
-
* way Desktop keeps them in its WebView storage: local to this profile, never
|
|
23512
|
-
* published. Network presence is not stored; it only exists while the engine runs.
|
|
23513
|
-
*/
|
|
23514
|
-
var db = {
|
|
23515
|
-
async getLinks() {
|
|
23516
|
-
return openRows(STORES$1.links, await wrap((await store(STORES$1.links, "readonly")).getAll()));
|
|
23517
|
-
},
|
|
23518
|
-
async putLink(link) {
|
|
23519
|
-
const row = await sealRow(STORES$1.links, link);
|
|
23520
|
-
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
23521
|
-
tx.objectStore(STORES$1.links).put(row);
|
|
23522
|
-
await new Promise((resolve, reject) => {
|
|
23523
|
-
tx.oncomplete = () => resolve();
|
|
23524
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Link storage failed"));
|
|
23525
|
-
});
|
|
23526
|
-
},
|
|
23527
|
-
/** `relaxed`: for what a power cut may cost (a round trip, a note made again later), no disk sync of its own. */
|
|
23528
|
-
async patchLink(linkId, patch, relaxed = false) {
|
|
23529
|
-
const sealed = await sealRow(STORES$1.links, {
|
|
23530
|
-
...patch,
|
|
23531
|
-
id: linkId
|
|
23532
|
-
});
|
|
23533
|
-
const tx = (await openDb()).transaction(STORES$1.links, "readwrite", relaxed ? RELAXED : void 0);
|
|
23534
|
-
const links = tx.objectStore(STORES$1.links);
|
|
23535
|
-
const request = links.get(linkId);
|
|
23536
|
-
request.onsuccess = () => {
|
|
23537
|
-
if (!request.result) {
|
|
23538
|
-
tx.abort();
|
|
23539
|
-
return;
|
|
23540
|
-
}
|
|
23541
|
-
links.put({
|
|
23542
|
-
...request.result,
|
|
23543
|
-
...sealed
|
|
23544
|
-
});
|
|
23545
|
-
};
|
|
23546
|
-
await new Promise((resolve, reject) => {
|
|
23547
|
-
tx.oncomplete = () => resolve();
|
|
23548
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Link unavailable"));
|
|
23549
|
-
});
|
|
23550
|
-
},
|
|
23551
|
-
async updatePeerProofs(linkId, change) {
|
|
23552
|
-
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
23553
|
-
const links = tx.objectStore(STORES$1.links);
|
|
23554
|
-
let result;
|
|
23555
|
-
let failure;
|
|
23556
|
-
const request = links.get(linkId);
|
|
23557
|
-
request.onsuccess = () => {
|
|
23558
|
-
try {
|
|
23559
|
-
const link = request.result;
|
|
23560
|
-
if (!link?.pairedPeerKey) throw new Error("Confirmed conversation unavailable");
|
|
23561
|
-
result = change(link.peerProofs ?? emptyProofLedger());
|
|
23562
|
-
links.put({
|
|
23563
|
-
...link,
|
|
23564
|
-
peerProofs: result
|
|
23565
|
-
});
|
|
23566
|
-
} catch (e) {
|
|
23567
|
-
failure = e;
|
|
23568
|
-
tx.abort();
|
|
23569
|
-
}
|
|
23570
|
-
};
|
|
23571
|
-
await new Promise((resolve, reject) => {
|
|
23572
|
-
tx.oncomplete = () => resolve();
|
|
23573
|
-
tx.onerror = tx.onabort = () => reject(failure ?? tx.error ?? /* @__PURE__ */ new Error("Proof storage failed"));
|
|
23574
|
-
});
|
|
23575
|
-
return result;
|
|
23576
|
-
},
|
|
23577
|
-
/** Read-transform-write of a chat's identity ledger in one transaction, keeping every other field. */
|
|
23578
|
-
async updateIdentities(linkId, change) {
|
|
23579
|
-
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
23580
|
-
const links = tx.objectStore(STORES$1.links);
|
|
23581
|
-
let result;
|
|
23582
|
-
let failure;
|
|
23583
|
-
const request = links.get(linkId);
|
|
23584
|
-
request.onsuccess = () => {
|
|
23585
|
-
try {
|
|
23586
|
-
const link = request.result;
|
|
23587
|
-
if (!link?.profile) throw new Error("Paired chat unavailable");
|
|
23588
|
-
result = change(link.identities ?? emptyIdentityLedger());
|
|
23589
|
-
links.put({
|
|
23590
|
-
...link,
|
|
23591
|
-
identities: result
|
|
23592
|
-
});
|
|
23593
|
-
} catch (e) {
|
|
23594
|
-
failure = e;
|
|
23595
|
-
tx.abort();
|
|
23596
|
-
}
|
|
23597
|
-
};
|
|
23598
|
-
await new Promise((resolve, reject) => {
|
|
23599
|
-
tx.oncomplete = () => resolve();
|
|
23600
|
-
tx.onerror = tx.onabort = () => reject(failure ?? tx.error ?? /* @__PURE__ */ new Error("Identity storage failed"));
|
|
23601
|
-
});
|
|
23602
|
-
return result;
|
|
23603
|
-
},
|
|
23604
|
-
async pinPeer(linkId, key, signedSignals = false) {
|
|
23605
|
-
const { seals, pinned } = await pinnedKey(linkId, key);
|
|
23606
|
-
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
23607
|
-
const links = tx.objectStore(STORES$1.links);
|
|
23608
|
-
const request = links.get(linkId);
|
|
23609
|
-
request.onsuccess = () => {
|
|
23610
|
-
const link = request.result;
|
|
23611
|
-
const before = pinned(link);
|
|
23612
|
-
if (!link?.participationSeed || before === CHANGED || before && before !== key) {
|
|
23613
|
-
tx.abort();
|
|
23614
|
-
return;
|
|
23615
|
-
}
|
|
23616
|
-
links.put(seals.row(STORES$1.links, {
|
|
23617
|
-
...link,
|
|
23618
|
-
peerTrust: link.peerTrust ?? {
|
|
23619
|
-
version: 1,
|
|
23620
|
-
verifiedKey: before
|
|
23621
|
-
},
|
|
23622
|
-
pairedPeerKey: key,
|
|
23623
|
-
requireSignedSignals: link.requireSignedSignals || signedSignals,
|
|
23624
|
-
inviteCode: void 0
|
|
23625
|
-
}));
|
|
23626
|
-
};
|
|
23627
|
-
await new Promise((resolve, reject) => {
|
|
23628
|
-
tx.oncomplete = () => resolve();
|
|
23629
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Invitation already consumed or unavailable"));
|
|
23630
|
-
});
|
|
23631
|
-
},
|
|
23632
|
-
async verifyPeer(linkId, key) {
|
|
23633
|
-
const { seals, pinned } = await pinnedKey(linkId, key);
|
|
23634
|
-
const tx = (await openDb()).transaction(STORES$1.links, "readwrite");
|
|
23635
|
-
const links = tx.objectStore(STORES$1.links);
|
|
23636
|
-
const request = links.get(linkId);
|
|
23637
|
-
request.onsuccess = () => {
|
|
23638
|
-
const link = request.result;
|
|
23639
|
-
if (!link?.pairedPeerKey || pinned(link) !== key) {
|
|
23640
|
-
tx.abort();
|
|
23641
|
-
return;
|
|
23642
|
-
}
|
|
23643
|
-
links.put(seals.row(STORES$1.links, {
|
|
23644
|
-
...link,
|
|
23645
|
-
peerTrust: {
|
|
23646
|
-
version: 1,
|
|
23647
|
-
verifiedKey: key,
|
|
23648
|
-
verifiedAt: Date.now()
|
|
23649
|
-
}
|
|
23650
|
-
}));
|
|
23651
|
-
};
|
|
23652
|
-
await new Promise((resolve, reject) => {
|
|
23653
|
-
tx.oncomplete = () => resolve();
|
|
23654
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Contact changed or verification could not be saved"));
|
|
23655
|
-
});
|
|
23656
|
-
},
|
|
23657
|
-
async deleteLink(linkId) {
|
|
23658
|
-
await committed((await store(STORES$1.links, "readwrite")).delete(linkId));
|
|
23659
|
-
await committed((await store(STORES$1.messages, "readwrite")).delete(IDBKeyRange.bound([linkId], [linkId, []])));
|
|
23660
|
-
await fileStore.deleteForLink(linkId);
|
|
23661
|
-
await removeFileBytes(`${linkId}-in-`);
|
|
23662
|
-
await removeFileBytes(`${linkId}-out-`);
|
|
23663
|
-
const appStorage = await store(STORES$1.appStorage, "readwrite");
|
|
23664
|
-
await new Promise((resolve, reject) => {
|
|
23665
|
-
appStorage.transaction.oncomplete = () => resolve();
|
|
23666
|
-
appStorage.transaction.onerror = appStorage.transaction.onabort = () => reject(appStorage.transaction.error ?? /* @__PURE__ */ new Error("App storage failed"));
|
|
23667
|
-
const request = appStorage.index(APP_STORAGE_CHAT_INDEX).openKeyCursor(IDBKeyRange.only(linkId));
|
|
23668
|
-
request.onsuccess = () => {
|
|
23669
|
-
const cursor = request.result;
|
|
23670
|
-
if (!cursor) return;
|
|
23671
|
-
const [ref] = cursor.primaryKey;
|
|
23672
|
-
appStorage.delete(IDBKeyRange.bound([ref, linkId], [
|
|
23673
|
-
ref,
|
|
23674
|
-
linkId,
|
|
23675
|
-
[]
|
|
23676
|
-
]));
|
|
23677
|
-
cursor.continue();
|
|
23678
|
-
};
|
|
23679
|
-
});
|
|
23680
|
-
},
|
|
23681
|
-
/**
|
|
23682
|
-
* A chat's whole history, by time. Read by its key range (every key is `[linkId, id]`, ids are strings: from `[linkId]`
|
|
23683
|
-
* to `[linkId, []]`), the same rows in the same order as the `byLink` index has them, without looking each one up
|
|
23684
|
-
* again: in the CLI's store (fake-indexeddb) that lookup cost 4-9 times the read itself.
|
|
23685
|
-
*/
|
|
23686
|
-
async getMessages(linkId) {
|
|
23687
|
-
return (await wrap((await store(STORES$1.messages, "readonly")).getAll(IDBKeyRange.bound([linkId], [linkId, []])))).sort((a, b) => a.timestamp - b.timestamp);
|
|
23688
|
-
},
|
|
23689
|
-
/** Whether the chat has a message with this id. */
|
|
23690
|
-
async hasMessage(linkId, id) {
|
|
23691
|
-
return await wrap((await store(STORES$1.messages, "readonly")).getKey([linkId, id])) !== void 0;
|
|
23692
|
-
},
|
|
23693
|
-
async getMessage(linkId, id) {
|
|
23694
|
-
return wrap((await store(STORES$1.messages, "readonly")).get([linkId, id]));
|
|
23695
|
-
},
|
|
23696
|
-
/**
|
|
23697
|
-
* These rows of a chat, in the order asked (undefined where none is), in one transaction: in the CLI's store
|
|
23698
|
-
* (fake-indexeddb) each transaction waiting at once is checked against all the others, so one per row costs the square.
|
|
23699
|
-
*/
|
|
23700
|
-
async getMessagesById(linkId, ids) {
|
|
23701
|
-
if (!ids.length) return [];
|
|
23702
|
-
const messages = await store(STORES$1.messages, "readonly");
|
|
23703
|
-
return Promise.all(ids.map((id) => wrap(messages.get([linkId, id]))));
|
|
23704
|
-
},
|
|
23705
|
-
/**
|
|
23706
|
-
* The newest `limit` messages of a chat before `before`, oldest first, in `getMessages`' order (time, then id), and
|
|
23707
|
-
* whether older ones remain. Reads those rows only: a long chat's first page costs what a short one's does.
|
|
23708
|
-
* `before`: a message's place (the page ends just before it), or a time (`id` left out: the page ends before it).
|
|
23709
|
-
*/
|
|
23710
|
-
async getMessagePage(linkId, { limit, before }) {
|
|
23711
|
-
const range = IDBKeyRange.bound([linkId, -Infinity], [linkId, before?.timestamp ?? Infinity], false, !!before && before.id === void 0);
|
|
23712
|
-
const kept = (m) => !(before?.id !== void 0 && m.timestamp === before.timestamp && m.id >= before.id);
|
|
23713
|
-
for (let want = limit + 1;;) {
|
|
23714
|
-
const newest = await newestMessages((await store(STORES$1.messages, "readonly")).index("byLinkTime"), range, want);
|
|
23715
|
-
const page = newest.filter(kept);
|
|
23716
|
-
if (page.length > limit || newest.length < want) return {
|
|
23717
|
-
messages: page.slice(0, limit).reverse(),
|
|
23718
|
-
more: page.length > limit
|
|
23719
|
-
};
|
|
23720
|
-
want += newest.length - page.length;
|
|
23721
|
-
}
|
|
23722
|
-
},
|
|
23723
|
-
/**
|
|
23724
|
-
* The oldest `limit` messages of a chat after `after` (and before `before`, when given), oldest first, and whether
|
|
23725
|
-
* newer ones remain in that window. Reads those rows only: a bot that reads what came since its last message costs
|
|
23726
|
-
* a page, where reading the whole history and cutting it cost 94 ms of the daemon's time a call at 7,000 messages.
|
|
23727
|
-
*/
|
|
23728
|
-
async getMessagePageAfter(linkId, { limit, before, after }) {
|
|
23729
|
-
const upper = before?.timestamp ?? Infinity;
|
|
23730
|
-
if (after.timestamp > upper || after.timestamp === upper && (after.id === void 0 || before?.id === void 0)) return {
|
|
23731
|
-
messages: [],
|
|
23732
|
-
more: false
|
|
23733
|
-
};
|
|
23734
|
-
const range = IDBKeyRange.bound([linkId, after.timestamp], [linkId, upper], after.id === void 0, !!before && before.id === void 0);
|
|
23735
|
-
const kept = (m) => !(after.id !== void 0 && m.timestamp === after.timestamp && m.id <= after.id) && !(before?.id !== void 0 && m.timestamp === before.timestamp && m.id >= before.id);
|
|
23736
|
-
for (let want = limit + 1;;) {
|
|
23737
|
-
const oldest = await wrap((await store(STORES$1.messages, "readonly")).index("byLinkTime").getAll(range, want));
|
|
23738
|
-
const page = oldest.filter(kept);
|
|
23739
|
-
if (page.length > limit || oldest.length < want) return {
|
|
23740
|
-
messages: page.slice(0, limit),
|
|
23741
|
-
more: page.length > limit
|
|
23742
|
-
};
|
|
23743
|
-
want += oldest.length - page.length;
|
|
23744
|
-
}
|
|
23745
|
-
},
|
|
23746
|
-
/**
|
|
23747
|
-
* Every message of this profile that carries a task, a routine or a usage card, from every chat and group, oldest first (time,
|
|
23748
|
-
* then id). Reads the card index only (`CARD_INDEX`): no chat's history is read, however long. The index follows the
|
|
23749
|
-
* rows, so an edit's card, a deleted message and a deleted chat or group are in step with no bookkeeping.
|
|
23750
|
-
*/
|
|
23751
|
-
async getCardMessages() {
|
|
23752
|
-
const index = (await store(STORES$1.messages, "readonly")).index(CARD_INDEX);
|
|
23753
|
-
return (await Promise.all([
|
|
23754
|
-
"task",
|
|
23755
|
-
"routine",
|
|
23756
|
-
"usage"
|
|
23757
|
-
].map((kind) => wrap(index.getAll(kind))))).flat().sort((a, b) => a.timestamp - b.timestamp || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
23758
|
-
},
|
|
23759
|
-
/** Returns false when the message was already stored. */
|
|
23760
|
-
async addMessage(message) {
|
|
23761
|
-
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite");
|
|
23762
|
-
const messages = tx.objectStore(STORES$1.messages);
|
|
23763
|
-
let added = false;
|
|
23764
|
-
const request = messages.getKey([message.linkId, message.id]);
|
|
23765
|
-
request.onsuccess = () => {
|
|
23766
|
-
if (request.result !== void 0) return;
|
|
23767
|
-
messages.put(message);
|
|
23768
|
-
added = true;
|
|
23769
|
-
};
|
|
23770
|
-
await new Promise((resolve, reject) => {
|
|
23771
|
-
tx.oncomplete = () => resolve();
|
|
23772
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Message storage failed"));
|
|
23773
|
-
});
|
|
23774
|
-
return added;
|
|
23775
|
-
},
|
|
23776
|
-
/** Writes a message whether or not it is there: lines of history that change as what they tell changes. */
|
|
23777
|
-
async putMessage(message) {
|
|
23778
|
-
await committed((await store(STORES$1.messages, "readwrite")).put(message));
|
|
23779
|
-
},
|
|
23780
|
-
async updateDelivery(linkId, id, delivery, deliveryError, extra) {
|
|
23781
|
-
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite", delivery === "sent" || delivery === "delivered" ? RELAXED : void 0);
|
|
23782
|
-
const messages = tx.objectStore(STORES$1.messages);
|
|
23783
|
-
const request = messages.get([linkId, id]);
|
|
23784
|
-
request.onsuccess = () => {
|
|
23785
|
-
const message = request.result;
|
|
23786
|
-
if (!message?.delivery || message.delivery === "delivered") return;
|
|
23787
|
-
if (message.delivery === delivery && message.deliveryError === deliveryError && Object.entries(extra ?? {}).every(([key, value]) => message[key] === value)) return;
|
|
23788
|
-
messages.put({
|
|
23789
|
-
...message,
|
|
23790
|
-
...extra,
|
|
23791
|
-
delivery,
|
|
23792
|
-
deliveryError
|
|
23793
|
-
});
|
|
23794
|
-
};
|
|
23795
|
-
await new Promise((resolve, reject) => {
|
|
23796
|
-
tx.oncomplete = () => resolve();
|
|
23797
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Receipt storage failed"));
|
|
23798
|
-
});
|
|
23799
|
-
},
|
|
23800
|
-
/**
|
|
23801
|
-
* Changes one message row in place, in one transaction: `change` sees the row as stored and gives the fields to
|
|
23802
|
-
* set (`null`: leave it). A row that is not there is not made. Used for what the delivery states do not carry
|
|
23803
|
-
* (the message's details record), on rows in any state. `relaxed`: for what can be made again or is only a note
|
|
23804
|
-
* (a receipt's mark, the details record), written with no disk sync of its own.
|
|
23805
|
-
*/
|
|
23806
|
-
async patchMessage(linkId, id, change, relaxed = false) {
|
|
23807
|
-
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite", relaxed ? RELAXED : void 0);
|
|
23808
|
-
const messages = tx.objectStore(STORES$1.messages);
|
|
23809
|
-
const request = messages.get([linkId, id]);
|
|
23810
|
-
let result;
|
|
23811
|
-
request.onsuccess = () => {
|
|
23812
|
-
const message = request.result;
|
|
23813
|
-
if (!message) return;
|
|
23814
|
-
const patch = change(message);
|
|
23815
|
-
if (!patch) return;
|
|
23816
|
-
result = {
|
|
23817
|
-
...message,
|
|
23818
|
-
...patch
|
|
23819
|
-
};
|
|
23820
|
-
messages.put(result);
|
|
23821
|
-
};
|
|
23822
|
-
await new Promise((resolve, reject) => {
|
|
23823
|
-
tx.oncomplete = () => resolve();
|
|
23824
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Message storage failed"));
|
|
23825
|
-
});
|
|
23826
|
-
return result;
|
|
23827
|
-
},
|
|
23828
|
-
/**
|
|
23829
|
-
* `patchMessage` on these rows of one history, all in one transaction: one disk sync for all of them. Resolves to
|
|
23830
|
-
* the rows changed, in the order of `ids`.
|
|
23831
|
-
*/
|
|
23832
|
-
async patchMessages(linkId, ids, change) {
|
|
23833
|
-
const tx = (await openDb()).transaction(STORES$1.messages, "readwrite");
|
|
23834
|
-
const messages = tx.objectStore(STORES$1.messages);
|
|
23835
|
-
const results = [];
|
|
23836
|
-
ids.forEach((id, i) => {
|
|
23837
|
-
const request = messages.get([linkId, id]);
|
|
23838
|
-
request.onsuccess = () => {
|
|
23839
|
-
const message = request.result;
|
|
23840
|
-
const patch = message && change(message);
|
|
23841
|
-
if (!patch) return;
|
|
23842
|
-
messages.put(results[i] = {
|
|
23843
|
-
...message,
|
|
23844
|
-
...patch
|
|
23845
|
-
});
|
|
23846
|
-
};
|
|
23847
|
-
});
|
|
23848
|
-
await new Promise((resolve, reject) => {
|
|
23849
|
-
tx.oncomplete = () => resolve();
|
|
23850
|
-
tx.onerror = tx.onabort = () => reject(tx.error ?? /* @__PURE__ */ new Error("Message storage failed"));
|
|
23851
|
-
});
|
|
23852
|
-
return results.filter((row) => !!row);
|
|
23853
|
-
},
|
|
23854
|
-
async deleteMessage(linkId, messageId) {
|
|
23855
|
-
await committed((await store(STORES$1.messages, "readwrite")).delete([linkId, messageId]));
|
|
23856
|
-
},
|
|
23857
|
-
async getGroups() {
|
|
23858
|
-
return openRows(STORES$1.groups, await wrap((await store(STORES$1.groups, "readonly")).getAll()));
|
|
23859
|
-
},
|
|
23860
|
-
async putGroup(group) {
|
|
23861
|
-
const row = await sealRow(STORES$1.groups, group);
|
|
23862
|
-
await committed((await store(STORES$1.groups, "readwrite")).put(row));
|
|
23863
|
-
},
|
|
23864
|
-
/** The group and its history. */
|
|
23865
|
-
async deleteGroup(groupId) {
|
|
23866
|
-
await committed((await store(STORES$1.groups, "readwrite")).delete(groupId));
|
|
23867
|
-
const link = `group:${groupId}`;
|
|
23868
|
-
await committed((await store(STORES$1.messages, "readwrite")).delete(IDBKeyRange.bound([link], [link, []])));
|
|
23869
|
-
},
|
|
23870
|
-
async getServices() {
|
|
23871
|
-
return wrap((await store(STORES$1.services, "readonly")).getAll());
|
|
23872
|
-
},
|
|
23873
|
-
async putService(service) {
|
|
23874
|
-
await committed((await store(STORES$1.services, "readwrite")).put(service));
|
|
23875
|
-
},
|
|
23876
|
-
async deleteService(serviceId) {
|
|
23877
|
-
await committed((await store(STORES$1.services, "readwrite")).delete(serviceId));
|
|
23878
|
-
},
|
|
23879
|
-
async getSettings() {
|
|
23880
|
-
return await wrap((await store(STORES$1.settings, "readonly")).get("settings")) ?? {};
|
|
23881
|
-
},
|
|
23882
|
-
async putSettings(settings) {
|
|
23883
|
-
await committed((await store(STORES$1.settings, "readwrite")).put(settings, "settings"));
|
|
23884
|
-
}
|
|
23885
|
-
};
|
|
23886
|
-
//#endregion
|
|
23887
24227
|
//#region ../browser/src/engine/arrival.ts
|
|
23888
24228
|
/**
|
|
23889
24229
|
* A history stored before a received row was placed where it arrived (WISP 400, requirement 10; until 2026-10): a
|
|
@@ -24344,7 +24684,8 @@ async function pinnedRow(host, chat, id) {
|
|
|
24344
24684
|
}
|
|
24345
24685
|
/**
|
|
24346
24686
|
* This side's pin (`messageId` its row here or the id both sides know; `remove` unpins): numbered past the pin shown
|
|
24347
|
-
* now, or why it cannot be.
|
|
24687
|
+
* now, or why it cannot be. The message pinned already (its number holding) is `already`: nothing is numbered or sent,
|
|
24688
|
+
* so the pin stays its pinner's, and goes only when they leave a group.
|
|
24348
24689
|
*/
|
|
24349
24690
|
async function myPin(host, chat, messageId, remove, current, now = Date.now()) {
|
|
24350
24691
|
const n = nextPinNumber(current?.n, now);
|
|
@@ -24359,6 +24700,7 @@ async function myPin(host, chat, messageId, remove, current, now = Date.now()) {
|
|
|
24359
24700
|
const target = host.message ? await host.message(chat, messageId) ?? await pinnedRow(host, chat, messageId) : (await host.messages(chat)).find((m) => m.id === messageId) ?? await pinnedRow(host, chat, messageId);
|
|
24360
24701
|
const id = target && replyRef(target, group);
|
|
24361
24702
|
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or cannot be pinned` };
|
|
24703
|
+
if (current?.id === id && pinNumberHolds(current.n, now)) return { already: true };
|
|
24362
24704
|
return {
|
|
24363
24705
|
id,
|
|
24364
24706
|
n,
|
|
@@ -24368,6 +24710,289 @@ async function myPin(host, chat, messageId, remove, current, now = Date.now()) {
|
|
|
24368
24710
|
};
|
|
24369
24711
|
}
|
|
24370
24712
|
//#endregion
|
|
24713
|
+
//#region ../browser/src/engine/groupRows.ts
|
|
24714
|
+
/**
|
|
24715
|
+
* A private group's record in two rows. A message sent or received changes a few fields of the group's state (my
|
|
24716
|
+
* sequence number, what I saw, my last frames, my texts not yet stored or said); the rest, its membership chain above
|
|
24717
|
+
* all, changes with a commit or a secret only. Each commit carries the whole roster and the chain is never compacted,
|
|
24718
|
+
* so the record grew with every join and leave, and each message wrote all of it again: 50 KB in a group of 32 just
|
|
24719
|
+
* made, 800 KB after 150 joins and leaves. Now a message writes the group's small row (`GroupLive`, in the settings
|
|
24720
|
+
* store) alone, and the record is written when the rest changes.
|
|
24721
|
+
*
|
|
24722
|
+
* An app from before reads the record alone. Each time the record is written, its `state.seq` is `SEQ_BLOCK` above
|
|
24723
|
+
* mine (`StoredGroup.seqReserved`), and it is written again before I send at that number: such an app sends above
|
|
24724
|
+
* everything I said, and the members do not drop its messages as already seen. Back here, a record whose `state.seq`
|
|
24725
|
+
* is not the number reserved was written by such an app since, and the small row is stale: the record counts.
|
|
24726
|
+
*/
|
|
24727
|
+
var SEQ_BLOCK = 1024;
|
|
24728
|
+
/** The fields of the state the small row holds. */
|
|
24729
|
+
var LIVE = [
|
|
24730
|
+
"seq",
|
|
24731
|
+
"seqEpoch",
|
|
24732
|
+
"seen",
|
|
24733
|
+
"sent",
|
|
24734
|
+
"alone",
|
|
24735
|
+
"provisional",
|
|
24736
|
+
"nicks",
|
|
24737
|
+
"unsaid"
|
|
24738
|
+
];
|
|
24739
|
+
/**
|
|
24740
|
+
* The fields of the record a row of their own holds (`GroupLight`) while nothing else of it changed: what a pin (mine
|
|
24741
|
+
* or a member's) and a deletion for everyone change. Each wrote the whole record, as a message did before (150 KB in a
|
|
24742
|
+
* group of 31 after 20 joins and leaves, 350 KB after 60). Apart from the small row: up to 500 ids each, which a message
|
|
24743
|
+
* would write again every time. `came` is the small row's. The same row holds the state's `relayEdits` (up to 64 frames):
|
|
24744
|
+
* each edit and deletion for everyone a member's app takes in changes them, and wrote the whole record too.
|
|
24745
|
+
*
|
|
24746
|
+
* And the hubs I keep for my next start (`StoredGroup.hubs`, at most eight keys): they change each time a hub goes
|
|
24747
|
+
* offline or comes back, and wrote the whole record each time (two hubs away 90 s every 2 minutes: 30 whole records,
|
|
24748
|
+
* 1.7 MB, per other hub in 30 min in a group of 31). Only read at the next start, before the beacon is: an app from
|
|
24749
|
+
* before, or a row it left stale, starts on the hubs of an older list, and reads the beacon as before. With them,
|
|
24750
|
+
* the members whose apps said they take rosters past eight (`StoredGroup.large`), noted when an edge with one first
|
|
24751
|
+
* comes up: a member moving to a hub it never had an edge with noted it, and wrote the whole record for that. The row
|
|
24752
|
+
* holds the ones noted since the record was written whole, and the list only grows: at load, the record's and the
|
|
24753
|
+
* row's together, so none an app from before noted in the record since is lost.
|
|
24754
|
+
*/
|
|
24755
|
+
var LIGHT = [
|
|
24756
|
+
"pin",
|
|
24757
|
+
"removedIds",
|
|
24758
|
+
"removals",
|
|
24759
|
+
"hubs",
|
|
24760
|
+
"large"
|
|
24761
|
+
];
|
|
24762
|
+
var topOf = (state) => state.chain[state.chain.length - 1]?.sig ?? "";
|
|
24763
|
+
/** The members' edits the state keeps to hand on, by their signatures. */
|
|
24764
|
+
var editsOf = (state) => (state.relayEdits ?? []).map((f) => f.sig).join(" ");
|
|
24765
|
+
/** The state as its record holds it, but for `LIVE` and `relayEdits`, in one string: its frames and statements by their signatures. */
|
|
24766
|
+
function recordKey(state) {
|
|
24767
|
+
const { chain, relay, relayEdits: _edits, meta, metaPast, ...rest } = state;
|
|
24768
|
+
for (const field of LIVE) delete rest[field];
|
|
24769
|
+
return JSON.stringify([
|
|
24770
|
+
rest,
|
|
24771
|
+
chain.length,
|
|
24772
|
+
chain[0]?.sig,
|
|
24773
|
+
topOf(state),
|
|
24774
|
+
relay?.map((f) => f.sig),
|
|
24775
|
+
meta?.sig,
|
|
24776
|
+
metaPast?.map((m) => m.sig)
|
|
24777
|
+
]);
|
|
24778
|
+
}
|
|
24779
|
+
/** The record but for its state, `LIGHT` and `came` (the small row's), in one string. */
|
|
24780
|
+
function restKey(group) {
|
|
24781
|
+
const { state: _state, seqReserved: _reserved, came: _came, ...rest } = group;
|
|
24782
|
+
for (const field of LIGHT) delete rest[field];
|
|
24783
|
+
return JSON.stringify(rest);
|
|
24784
|
+
}
|
|
24785
|
+
/** The row for `group`, whose record holds the members' apps in `kept` (`StoredGroup.large`) already. */
|
|
24786
|
+
function lightOf(group, kept) {
|
|
24787
|
+
const large = group.large?.filter((key) => !kept.includes(key));
|
|
24788
|
+
return {
|
|
24789
|
+
...group.pin && { pin: group.pin },
|
|
24790
|
+
removedIds: group.removedIds ?? [],
|
|
24791
|
+
removals: group.removals ?? [],
|
|
24792
|
+
relayEdits: group.state?.relayEdits ?? [],
|
|
24793
|
+
...group.hubs && { hubs: group.hubs },
|
|
24794
|
+
...large?.length ? { large } : {}
|
|
24795
|
+
};
|
|
24796
|
+
}
|
|
24797
|
+
/**
|
|
24798
|
+
* What a record holds of `LIGHT` (`lightOf`, in one string), as their row's `of`: an app from before that took a pin, an
|
|
24799
|
+
* unpin or a deletion for everyone wrote the record and not their row, and changed nothing the small row's check sees.
|
|
24800
|
+
*/
|
|
24801
|
+
var markOf = (light) => bytesToHex(sha256(utf8ToBytes(light))).slice(0, 32);
|
|
24802
|
+
function liveOf(group) {
|
|
24803
|
+
const s = group.state;
|
|
24804
|
+
return {
|
|
24805
|
+
top: topOf(s),
|
|
24806
|
+
state: {
|
|
24807
|
+
seq: s.seq,
|
|
24808
|
+
seqEpoch: s.seqEpoch,
|
|
24809
|
+
seen: s.seen,
|
|
24810
|
+
sent: s.sent,
|
|
24811
|
+
nicks: s.nicks,
|
|
24812
|
+
...s.alone && { alone: s.alone },
|
|
24813
|
+
...s.provisional && { provisional: s.provisional },
|
|
24814
|
+
...s.unsaid?.length ? { unsaid: s.unsaid } : {}
|
|
24815
|
+
},
|
|
24816
|
+
...group.came && { came: group.came }
|
|
24817
|
+
};
|
|
24818
|
+
}
|
|
24819
|
+
var cameOf = (group) => JSON.stringify(group.came ?? {});
|
|
24820
|
+
var later = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.max(a, b);
|
|
24821
|
+
var GroupRows = class {
|
|
24822
|
+
raw;
|
|
24823
|
+
written = /* @__PURE__ */ new Map();
|
|
24824
|
+
/** What the engine writes a private group through: its record holds the state as it was last written whole. */
|
|
24825
|
+
store;
|
|
24826
|
+
constructor(raw) {
|
|
24827
|
+
this.raw = raw;
|
|
24828
|
+
this.store = {
|
|
24829
|
+
getGroups: () => raw.getGroups(),
|
|
24830
|
+
putGroup: (group) => this.put(group),
|
|
24831
|
+
deleteGroup: async (groupId) => {
|
|
24832
|
+
this.written.delete(groupId);
|
|
24833
|
+
await raw.deleteGroup(groupId);
|
|
24834
|
+
},
|
|
24835
|
+
getMessages: (linkId) => raw.getMessages(linkId)
|
|
24836
|
+
};
|
|
24837
|
+
}
|
|
24838
|
+
/**
|
|
24839
|
+
* At load: the state of each record that no app from before wrote since takes what its small row says, and its pin,
|
|
24840
|
+
* deletions for everyone, hubs, members' apps and members' edits what their row says while the record still holds of
|
|
24841
|
+
* them what it did when the row was written (`of`).
|
|
24842
|
+
*/
|
|
24843
|
+
async load(groups) {
|
|
24844
|
+
if (!this.raw.getGroupLive) return;
|
|
24845
|
+
const rows = await this.raw.getGroupLive().catch(() => /* @__PURE__ */ new Map());
|
|
24846
|
+
const lights = await this.raw.getGroupLight?.().catch(() => void 0) ?? /* @__PURE__ */ new Map();
|
|
24847
|
+
for (const group of groups) {
|
|
24848
|
+
const live = rows.get(group.id), state = group.state, held = group.seqReserved;
|
|
24849
|
+
if (!live || !state || group.community) continue;
|
|
24850
|
+
if (!held || held.e !== state.seqEpoch || held.n !== state.seq || live.top !== topOf(state) || live.state.seqEpoch !== state.seqEpoch || !(live.state.seq <= state.seq)) {
|
|
24851
|
+
if (live.came) group.came = {
|
|
24852
|
+
...group.came,
|
|
24853
|
+
...live.came,
|
|
24854
|
+
peer: later(group.came?.peer, live.came.peer),
|
|
24855
|
+
mention: later(group.came?.mention, live.came.mention)
|
|
24856
|
+
};
|
|
24857
|
+
continue;
|
|
24858
|
+
}
|
|
24859
|
+
if (live.came) group.came = live.came;
|
|
24860
|
+
else delete group.came;
|
|
24861
|
+
const recorded = group.large ?? [], of = markOf(JSON.stringify(lightOf(group, recorded)));
|
|
24862
|
+
const light = lights.get(group.id), fresh = light && (light.of === void 0 || light.of === of) ? light : void 0;
|
|
24863
|
+
if (fresh) {
|
|
24864
|
+
if (fresh.pin) group.pin = fresh.pin;
|
|
24865
|
+
else delete group.pin;
|
|
24866
|
+
if (fresh.removedIds.length) group.removedIds = fresh.removedIds;
|
|
24867
|
+
else delete group.removedIds;
|
|
24868
|
+
if (fresh.removals.length) group.removals = fresh.removals;
|
|
24869
|
+
else delete group.removals;
|
|
24870
|
+
if (fresh.hubs) group.hubs = fresh.hubs;
|
|
24871
|
+
if (fresh.large) group.large = [.../* @__PURE__ */ new Set([...recorded, ...fresh.large])];
|
|
24872
|
+
}
|
|
24873
|
+
const merged = { ...state };
|
|
24874
|
+
for (const field of LIVE) delete merged[field];
|
|
24875
|
+
group.state = Object.assign(merged, live.state, fresh?.relayEdits && { relayEdits: fresh.relayEdits });
|
|
24876
|
+
this.written.set(group.id, {
|
|
24877
|
+
key: recordKey(state),
|
|
24878
|
+
state: structuredClone(state),
|
|
24879
|
+
rest: restKey(group),
|
|
24880
|
+
of,
|
|
24881
|
+
large: recorded,
|
|
24882
|
+
edits: editsOf(group.state),
|
|
24883
|
+
came: cameOf(group)
|
|
24884
|
+
});
|
|
24885
|
+
}
|
|
24886
|
+
}
|
|
24887
|
+
/**
|
|
24888
|
+
* A session's save: its small row alone while the rest of its state is what the record holds, and the members' edits'
|
|
24889
|
+
* row when they changed; else the record too.
|
|
24890
|
+
*/
|
|
24891
|
+
async save(group) {
|
|
24892
|
+
const written = this.written.get(group.id), state = group.state, edits = editsOf(state);
|
|
24893
|
+
if (this.raw.putGroupLive && written && holds(written.state, written.key, state) && (edits === written.edits || this.raw.putGroupLight)) {
|
|
24894
|
+
await this.raw.putGroupLive(group.id, liveOf(group));
|
|
24895
|
+
written.came = cameOf(group);
|
|
24896
|
+
if (edits === written.edits) return;
|
|
24897
|
+
await this.raw.putGroupLight(group.id, {
|
|
24898
|
+
...lightOf(group, written.large),
|
|
24899
|
+
of: written.of
|
|
24900
|
+
});
|
|
24901
|
+
written.edits = edits;
|
|
24902
|
+
return;
|
|
24903
|
+
}
|
|
24904
|
+
await this.put(group);
|
|
24905
|
+
}
|
|
24906
|
+
async put(group) {
|
|
24907
|
+
const state = group.state;
|
|
24908
|
+
if (!this.raw.putGroupLive || group.community) return this.raw.putGroup(group);
|
|
24909
|
+
if (!state) {
|
|
24910
|
+
this.written.delete(group.id);
|
|
24911
|
+
return this.raw.putGroup(group, null);
|
|
24912
|
+
}
|
|
24913
|
+
const was = this.written.get(group.id);
|
|
24914
|
+
if (was && holds(was.state, was.key, state)) {
|
|
24915
|
+
const rest = restKey(group);
|
|
24916
|
+
if (rest === was.rest && this.raw.putGroupLight) {
|
|
24917
|
+
await this.raw.putGroupLight(group.id, {
|
|
24918
|
+
...lightOf(group, was.large),
|
|
24919
|
+
of: was.of
|
|
24920
|
+
});
|
|
24921
|
+
was.edits = editsOf(state);
|
|
24922
|
+
const came = cameOf(group);
|
|
24923
|
+
if (came !== was.came) {
|
|
24924
|
+
await this.raw.putGroupLive(group.id, liveOf(group));
|
|
24925
|
+
was.came = came;
|
|
24926
|
+
}
|
|
24927
|
+
return;
|
|
24928
|
+
}
|
|
24929
|
+
const record = {
|
|
24930
|
+
...group,
|
|
24931
|
+
state: {
|
|
24932
|
+
...was.state,
|
|
24933
|
+
relayEdits: state.relayEdits
|
|
24934
|
+
},
|
|
24935
|
+
seqReserved: {
|
|
24936
|
+
e: was.state.seqEpoch,
|
|
24937
|
+
n: was.state.seq
|
|
24938
|
+
}
|
|
24939
|
+
};
|
|
24940
|
+
await this.whole(group, record, was);
|
|
24941
|
+
Object.assign(was, {
|
|
24942
|
+
rest,
|
|
24943
|
+
large: record.large ?? [],
|
|
24944
|
+
edits: editsOf(state),
|
|
24945
|
+
came: cameOf(group)
|
|
24946
|
+
});
|
|
24947
|
+
return;
|
|
24948
|
+
}
|
|
24949
|
+
const written = {
|
|
24950
|
+
key: recordKey(state),
|
|
24951
|
+
state: {
|
|
24952
|
+
...structuredClone(state),
|
|
24953
|
+
seq: state.seq + SEQ_BLOCK
|
|
24954
|
+
},
|
|
24955
|
+
rest: restKey(group),
|
|
24956
|
+
of: "",
|
|
24957
|
+
large: group.large ?? [],
|
|
24958
|
+
edits: editsOf(state),
|
|
24959
|
+
came: cameOf(group)
|
|
24960
|
+
};
|
|
24961
|
+
this.written.set(group.id, written);
|
|
24962
|
+
try {
|
|
24963
|
+
await this.whole(group, {
|
|
24964
|
+
...group,
|
|
24965
|
+
state: written.state,
|
|
24966
|
+
seqReserved: {
|
|
24967
|
+
e: state.seqEpoch,
|
|
24968
|
+
n: written.state.seq
|
|
24969
|
+
}
|
|
24970
|
+
}, written);
|
|
24971
|
+
} catch (error) {
|
|
24972
|
+
if (this.written.get(group.id) === written) this.written.delete(group.id);
|
|
24973
|
+
throw error;
|
|
24974
|
+
}
|
|
24975
|
+
}
|
|
24976
|
+
/**
|
|
24977
|
+
* The record written whole as `record`, with the small row, and its `GroupLight` row deleted: the record holds the pin,
|
|
24978
|
+
* the deletions, the hubs, the members' apps and the members' edits again (`written.of`). One that changed while it was
|
|
24979
|
+
* being written goes to its row again after it.
|
|
24980
|
+
*/
|
|
24981
|
+
async whole(group, record, written) {
|
|
24982
|
+
const kept = record.large ?? [], light = JSON.stringify(lightOf(record, kept)), of = markOf(light);
|
|
24983
|
+
written.of = of;
|
|
24984
|
+
await this.raw.putGroup(record, liveOf(group));
|
|
24985
|
+
if (this.raw.putGroupLight && JSON.stringify(lightOf(group, kept)) !== light) await this.raw.putGroupLight(group.id, {
|
|
24986
|
+
...lightOf(group, kept),
|
|
24987
|
+
of
|
|
24988
|
+
});
|
|
24989
|
+
}
|
|
24990
|
+
};
|
|
24991
|
+
/** Whether a record holding `written` (its `recordKey` `key`) holds `state` too, but for what the small row says. */
|
|
24992
|
+
function holds(written, key, state) {
|
|
24993
|
+
return written.seqEpoch === state.seqEpoch && state.seq <= written.seq && key === recordKey(state);
|
|
24994
|
+
}
|
|
24995
|
+
//#endregion
|
|
24371
24996
|
//#region ../browser/src/engine/groupAuthorOrder.ts
|
|
24372
24997
|
/**
|
|
24373
24998
|
* How long a member's message may still be placed again below that member's older ones (WISP 400, requirement 10):
|
|
@@ -24849,9 +25474,9 @@ var ENTRY_LINGER_MS$1 = 2e4;
|
|
|
24849
25474
|
* often while it stays full, its side of the entry session closed `FULL_LINGER_MS` after. The joiner shows it is full
|
|
24850
25475
|
* for `FULL_SAID_MS` after the last one (one answer missed included), then waits as before.
|
|
24851
25476
|
*/
|
|
24852
|
-
var FULL_TELL_MS = 3e5;
|
|
24853
|
-
var FULL_LINGER_MS = 5e3;
|
|
24854
|
-
var FULL_SAID_MS = 66e4;
|
|
25477
|
+
var FULL_TELL_MS$1 = 3e5;
|
|
25478
|
+
var FULL_LINGER_MS$1 = 5e3;
|
|
25479
|
+
var FULL_SAID_MS$1 = 66e4;
|
|
24855
25480
|
/**
|
|
24856
25481
|
* Whether this device can let in no one new now (WISP 903 § Admissions while the admin is away): members signed
|
|
24857
25482
|
* `COMMUNITY_LIMITS.memberAdmissions` admissions in a row, counted as the session's `commit` counts them. Its hub
|
|
@@ -24903,7 +25528,18 @@ var FAREWELL_SKEW_MS = 3e5;
|
|
|
24903
25528
|
var HUB_CLOCK_READ_GAP_MS$1 = 45e3;
|
|
24904
25529
|
/** A member that opens the group's link again knocks to check it is still in, this long at most (`joinByLink`). */
|
|
24905
25530
|
var CHECK_MS = 18e4;
|
|
25531
|
+
/** How long a community I left follows its chain (`leftBehind`): a hand-over that crossed my leave reaches me within it. */
|
|
25532
|
+
var LEFT_FOLLOW_MS = 6e5;
|
|
25533
|
+
/**
|
|
25534
|
+
* A role that reached my leave goes on this long after: the leave its giver said right after its `role` commit (an
|
|
25535
|
+
* admin's leave does) is heard first, so the role does not go back to a leaver.
|
|
25536
|
+
*/
|
|
25537
|
+
var LEFT_HAND_ON_MS$1 = 1e3;
|
|
24906
25538
|
var MESSAGE_LINK$1 = (groupId) => `group:${groupId}`;
|
|
25539
|
+
/** The newest hand-over in a chain. */
|
|
25540
|
+
var lastRole = (chain) => {
|
|
25541
|
+
for (let i = chain.length - 1; i >= 0; i--) if (chain[i].k === "role") return chain[i];
|
|
25542
|
+
};
|
|
24907
25543
|
/**
|
|
24908
25544
|
* A member key for a joiner whose entry session the member's side dials. Of a paired session's two
|
|
24909
25545
|
* ends only the lower key dials, and only once it has seen the other; the member's side opens when it
|
|
@@ -24948,6 +25584,11 @@ var Communities = class {
|
|
|
24948
25584
|
/** Since when this run knocks with nobody answering (`JOIN_GIVE_UP_MS`), and the joins it gave up (`Groups.giveUpJoin`). */
|
|
24949
25585
|
knockingSince = /* @__PURE__ */ new Map();
|
|
24950
25586
|
gaveUp = /* @__PURE__ */ new Set();
|
|
25587
|
+
/**
|
|
25588
|
+
* Communities I left, gone from here but for their session and edges, which follow the chain a while
|
|
25589
|
+
* (`LEFT_FOLLOW_MS`): the leave I said, whose leaves I heard since, and when a role that reached me goes on.
|
|
25590
|
+
*/
|
|
25591
|
+
leftBehind = /* @__PURE__ */ new Map();
|
|
24951
25592
|
/** Joiners: the knock record a knock read whose write the relays refused, and when it was read (`knock`). */
|
|
24952
25593
|
knockRead = /* @__PURE__ */ new Map();
|
|
24953
25594
|
/** My frames an edge took, and which of them carry an edit (`frame id → editKey`). */
|
|
@@ -25006,8 +25647,9 @@ var Communities = class {
|
|
|
25006
25647
|
}
|
|
25007
25648
|
/** Files and voice messages (WISP 503), the desk `Groups` keeps for every group. */
|
|
25008
25649
|
files;
|
|
25650
|
+
/** A community I left is still this engine's while it follows its chain (`leftBehind`): its edges' frames come here. */
|
|
25009
25651
|
has(groupId) {
|
|
25010
|
-
return this.stored.has(groupId);
|
|
25652
|
+
return this.stored.has(groupId) || this.leftBehind.has(groupId);
|
|
25011
25653
|
}
|
|
25012
25654
|
ids() {
|
|
25013
25655
|
return [...this.stored.keys()];
|
|
@@ -25129,7 +25771,7 @@ var Communities = class {
|
|
|
25129
25771
|
community: {
|
|
25130
25772
|
hub: live.hub,
|
|
25131
25773
|
hubs: hubs.length,
|
|
25132
|
-
connected: [...edges.keys()].filter(ready).length,
|
|
25774
|
+
connected: [...edges.keys()].filter((key) => ready(key) && !this.gone(live, key)).length,
|
|
25133
25775
|
...s.isAdmin && live.unansweredTold && { unansweredKnocks: live.unanswered.size }
|
|
25134
25776
|
},
|
|
25135
25777
|
members: roster.map(([key, role]) => ({
|
|
@@ -25157,7 +25799,7 @@ var Communities = class {
|
|
|
25157
25799
|
/** A member's app said lately that the community is full (`group-full`): how full, as it said. */
|
|
25158
25800
|
fullSaid(groupId) {
|
|
25159
25801
|
const told = this.toldFull.get(groupId);
|
|
25160
|
-
return told && this.now() - told.at < FULL_SAID_MS ? {
|
|
25802
|
+
return told && this.now() - told.at < FULL_SAID_MS$1 ? {
|
|
25161
25803
|
n: told.n,
|
|
25162
25804
|
max: told.max
|
|
25163
25805
|
} : void 0;
|
|
@@ -25182,6 +25824,7 @@ var Communities = class {
|
|
|
25182
25824
|
if (!link) throw new Error("This is not a link to a group");
|
|
25183
25825
|
const existing = this.stored.get(link.g);
|
|
25184
25826
|
const live = this.live.get(link.g);
|
|
25827
|
+
await this.dropLeftBehind(link.g);
|
|
25185
25828
|
if (existing?.joining && existing.joining.host === link.host) {
|
|
25186
25829
|
await this.knockAgain(link.g);
|
|
25187
25830
|
return link.g;
|
|
@@ -25359,11 +26002,13 @@ var Communities = class {
|
|
|
25359
26002
|
};
|
|
25360
26003
|
}
|
|
25361
26004
|
/** An application frame to everyone in the group (WISP 903 · Group Community § Payments). */
|
|
25362
|
-
|
|
26005
|
+
/** `key`: what taking the frame takes, for `taken` (a reaction's `reactionKey`). */
|
|
26006
|
+
async sendApp(groupId, frame, key) {
|
|
25363
26007
|
const live = this.live.get(groupId);
|
|
25364
26008
|
if (!live) throw new Error("You are not in this group yet");
|
|
25365
26009
|
const result = await live.session.sendApp(frame, this.host.myNick?.(), this.now());
|
|
25366
26010
|
if ("error" in result) throw new Error(result.error);
|
|
26011
|
+
if (key) this.carry(groupId, result.id, key);
|
|
25367
26012
|
}
|
|
25368
26013
|
/** An edit of my message, through the group like any frame (WISP 903 · Group Community § Edits). An error when it cannot go now. */
|
|
25369
26014
|
async sendEdit(groupId, edit) {
|
|
@@ -25379,12 +26024,15 @@ var Communities = class {
|
|
|
25379
26024
|
...edit.rm && { remove: true }
|
|
25380
26025
|
}, this.host.myNick?.(), this.now());
|
|
25381
26026
|
if ("error" in result) return result.error;
|
|
25382
|
-
|
|
25383
|
-
this.carriers.set(result.id, key);
|
|
25384
|
-
if (this.carriers.size > 512) this.carriers.delete(this.carriers.keys().next().value);
|
|
25385
|
-
for (let i = 0; i < this.frames.count(groupId, result.id); i++) this.frames.add(groupId, key);
|
|
26027
|
+
this.carry(groupId, result.id, editKey(edit.id, edit.e));
|
|
25386
26028
|
return null;
|
|
25387
26029
|
}
|
|
26030
|
+
/** What rides in a frame of its own (an edit, a reaction): what takes that frame (now, or in a catch-up later) takes it. */
|
|
26031
|
+
carry(groupId, id, key) {
|
|
26032
|
+
this.carriers.set(id, key);
|
|
26033
|
+
if (this.carriers.size > 512) this.carriers.delete(this.carriers.keys().next().value);
|
|
26034
|
+
for (let i = 0; i < this.frames.count(groupId, id); i++) this.frames.add(groupId, key);
|
|
26035
|
+
}
|
|
25388
26036
|
/** A payload for one member only, sealed to them and carried by the group (hubs relay it, members keep it for them). */
|
|
25389
26037
|
async sendPair(groupId, to, payload) {
|
|
25390
26038
|
const live = this.live.get(groupId);
|
|
@@ -25417,11 +26065,104 @@ var Communities = class {
|
|
|
25417
26065
|
next = s.others.find((key) => connected.has(key)) ?? s.others[0];
|
|
25418
26066
|
await s.transferAdmin(next);
|
|
25419
26067
|
}
|
|
25420
|
-
await s.leave();
|
|
25421
|
-
|
|
26068
|
+
const frame = await s.leave(true);
|
|
26069
|
+
if (frame) this.leftBehind.set(groupId, {
|
|
26070
|
+
session: s,
|
|
26071
|
+
frame,
|
|
26072
|
+
since: this.now(),
|
|
26073
|
+
heard: /* @__PURE__ */ new Set()
|
|
26074
|
+
});
|
|
26075
|
+
await this.forget(groupId, !!frame);
|
|
26076
|
+
await s.followAfterLeave();
|
|
25422
26077
|
return next;
|
|
25423
26078
|
}
|
|
25424
26079
|
/**
|
|
26080
|
+
* A community I left, and a frame from its edges (WISP 903 § Leaving, "A role that reaches a leave"): a member's leave
|
|
26081
|
+
* (the role does not go on to it), or what moves the chain. Once it takes me out, my leave is done; when it makes me
|
|
26082
|
+
* the admin, the role goes on at the next tick past `LEFT_HAND_ON_MS` (`handOn`).
|
|
26083
|
+
*/
|
|
26084
|
+
async afterLeave(groupId, from, raw) {
|
|
26085
|
+
const left = this.leftBehind.get(groupId), s = left?.session;
|
|
26086
|
+
if (!left || !s || !raw || typeof raw !== "object") return;
|
|
26087
|
+
const f = raw;
|
|
26088
|
+
let fresh = false;
|
|
26089
|
+
if (f.t === "group-leave") {
|
|
26090
|
+
const by = f.s !== s.myKey && !left.heard.has(f.s) ? s.signedLeave(f) : void 0;
|
|
26091
|
+
if (by) {
|
|
26092
|
+
left.heard.add(by);
|
|
26093
|
+
fresh = true;
|
|
26094
|
+
}
|
|
26095
|
+
} else fresh = await s.handle(from, raw) && f.t === "group-commit";
|
|
26096
|
+
if (fresh && rosterHas(s.roster, s.myKey)) {
|
|
26097
|
+
for (const [key, linkId] of this.host.edges(groupId)) if (key !== from) this.sendTo(linkId, f);
|
|
26098
|
+
}
|
|
26099
|
+
await this.leftMoved(groupId, this.now());
|
|
26100
|
+
}
|
|
26101
|
+
/** Where the chain of a community I left stands now: out (done), or the admin (the role goes on), or neither. */
|
|
26102
|
+
async leftMoved(groupId, now) {
|
|
26103
|
+
const left = this.leftBehind.get(groupId), s = left?.session;
|
|
26104
|
+
if (!left || !s) return;
|
|
26105
|
+
if (!rosterHas(s.roster, s.myKey) && !this.handedToLeaver(left)) await this.dropLeftBehind(groupId);
|
|
26106
|
+
else if (now - left.since > LEFT_FOLLOW_MS) await this.dropLeftBehind(groupId);
|
|
26107
|
+
else if (!rosterHas(s.roster, s.myKey)) left.handOnAt = void 0;
|
|
26108
|
+
else if (s.admin !== s.myKey) left.handOnAt = void 0;
|
|
26109
|
+
else {
|
|
26110
|
+
if (s.leftWaitsForSecret && now - (left.askedAt ?? 0) >= 5e3) {
|
|
26111
|
+
left.askedAt = now;
|
|
26112
|
+
const ready = [...this.host.edges(groupId)].filter(([key, id]) => key !== s.myKey && this.host.linkReady(id, 2) && rosterHas(s.roster, key)).map(([key]) => key);
|
|
26113
|
+
for (const key of ready.slice(0, 3)) s.catchUp(key);
|
|
26114
|
+
}
|
|
26115
|
+
if (left.handOnAt === void 0) left.handOnAt = now + LEFT_HAND_ON_MS$1;
|
|
26116
|
+
else if (now >= left.handOnAt) await this.handOn(groupId, now);
|
|
26117
|
+
}
|
|
26118
|
+
}
|
|
26119
|
+
/**
|
|
26120
|
+
* The role I handed on before I left is still with the member I gave it to, and that member's leave reached me: its
|
|
26121
|
+
* hand-on (`handOn`) may reach the group only through my edges, even once a hub committed my own leave (WISP 903,
|
|
26122
|
+
* "A role that reaches a leave": an older hub does not keep my request while the admin's waits).
|
|
26123
|
+
*/
|
|
26124
|
+
handedToLeaver(left) {
|
|
26125
|
+
const s = left.session, admin = s.admin, role = lastRole(s.state.chain);
|
|
26126
|
+
return !!admin && admin !== s.myKey && role?.by === s.myKey && role.s === admin && (left.heard.has(admin) || s.state.pendingLeaves.some((r) => r.s === admin));
|
|
26127
|
+
}
|
|
26128
|
+
/**
|
|
26129
|
+
* Whom a role that reached my leave goes on to: the member whose `role` commit gave it to me (`by`, whatever was
|
|
26130
|
+
* committed on top since), while it stays; else the first other member whose edge is up,
|
|
26131
|
+
* else the first in the roster. Never one whose leave I heard, nor one I handed the role to myself (an admin who left):
|
|
26132
|
+
* with two leavers the role would go back and forth between them.
|
|
26133
|
+
*/
|
|
26134
|
+
nextAdmin(groupId, left, by) {
|
|
26135
|
+
const s = left.session, handed = new Set(s.state.chain.filter((c) => c.k === "role" && c.by === s.myKey).map((c) => c.s));
|
|
26136
|
+
const eligible = s.others.filter((key) => !left.heard.has(key) && !handed.has(key));
|
|
26137
|
+
if (eligible.includes(by)) return by;
|
|
26138
|
+
const edges = this.host.edges(groupId);
|
|
26139
|
+
return eligible.find((key) => {
|
|
26140
|
+
const id = edges.get(key);
|
|
26141
|
+
return !!id && this.host.linkReady(id, 2);
|
|
26142
|
+
}) ?? eligible[0];
|
|
26143
|
+
}
|
|
26144
|
+
/**
|
|
26145
|
+
* A role that reached my leave goes on (`nextAdmin`), and my leave is said again: a hub from before dropped it while
|
|
26146
|
+
* it named the admin, and one that came on since never had it.
|
|
26147
|
+
*/
|
|
26148
|
+
async handOn(groupId, now) {
|
|
26149
|
+
const left = this.leftBehind.get(groupId), s = left?.session;
|
|
26150
|
+
if (!left || !s) return;
|
|
26151
|
+
try {
|
|
26152
|
+
if (!await s.handOnAfterLeave((by) => this.nextAdmin(groupId, left, by), now)) return;
|
|
26153
|
+
} catch {
|
|
26154
|
+
return;
|
|
26155
|
+
}
|
|
26156
|
+
left.handOnAt = void 0;
|
|
26157
|
+
left.since = now;
|
|
26158
|
+
for (const [, linkId] of this.host.edges(groupId)) this.sendTo(linkId, left.frame);
|
|
26159
|
+
}
|
|
26160
|
+
/** A community I left stops following its chain: its edges close, unless I am in it again. */
|
|
26161
|
+
async dropLeftBehind(groupId) {
|
|
26162
|
+
if (!this.leftBehind.delete(groupId) || this.stored.has(groupId)) return;
|
|
26163
|
+
for (const linkId of this.host.edges(groupId).values()) await this.host.closeEdge(linkId);
|
|
26164
|
+
}
|
|
26165
|
+
/**
|
|
25425
26166
|
* Delete from this device: left first, as Leave does. With nothing connected to carry the request, a member's leave
|
|
25426
26167
|
* goes unsaid and the group goes anyway, as a private group's failed goodbye does: the others still list the device,
|
|
25427
26168
|
* but members who never open the app again kept it here for good. An admin with members is still refused: gone with
|
|
@@ -25501,7 +26242,8 @@ var Communities = class {
|
|
|
25501
26242
|
if (live) throw new Error("You were in this group: leave it to stop trying to get back in");
|
|
25502
26243
|
await this.forget(groupId);
|
|
25503
26244
|
}
|
|
25504
|
-
|
|
26245
|
+
/** `keepEdges`: a community I just left, whose edges follow its chain a while yet (`leftBehind`). */
|
|
26246
|
+
async forget(groupId, keepEdges = false) {
|
|
25505
26247
|
const live = this.live.get(groupId);
|
|
25506
26248
|
if (live?.hub) await this.publishBeacon(groupId, live, this.now(), false).catch(() => {});
|
|
25507
26249
|
this.live.delete(groupId);
|
|
@@ -25512,7 +26254,8 @@ var Communities = class {
|
|
|
25512
26254
|
this.knockingSince.delete(groupId);
|
|
25513
26255
|
this.gaveUp.delete(groupId);
|
|
25514
26256
|
this.lineOrder.forget(MESSAGE_LINK$1(groupId));
|
|
25515
|
-
|
|
26257
|
+
if (!keepEdges) this.leftBehind.delete(groupId);
|
|
26258
|
+
for (const linkId of [...keepEdges ? [] : this.host.edges(groupId).values(), ...this.host.entries(groupId).values()]) await this.host.closeEdge(linkId);
|
|
25516
26259
|
await this.store.deleteGroup(groupId);
|
|
25517
26260
|
await this.files?.drop(groupId);
|
|
25518
26261
|
this.host.historyGone?.(groupId);
|
|
@@ -25585,6 +26328,7 @@ var Communities = class {
|
|
|
25585
26328
|
await this.topology(group.id, live, now).catch(() => {});
|
|
25586
26329
|
}
|
|
25587
26330
|
for (const [key, until] of this.refused) if (until <= now) this.refused.delete(key);
|
|
26331
|
+
for (const groupId of [...this.leftBehind.keys()]) await this.leftMoved(groupId, now);
|
|
25588
26332
|
}
|
|
25589
26333
|
async topology(groupId, live, now) {
|
|
25590
26334
|
const s = live.session, me = s.myKey;
|
|
@@ -25786,6 +26530,7 @@ var Communities = class {
|
|
|
25786
26530
|
for (const key of ready.slice(0, 3)) s.catchUp(key);
|
|
25787
26531
|
}
|
|
25788
26532
|
await s.resume().catch(() => {});
|
|
26533
|
+
if (s.settleGaps()) this.host.emit();
|
|
25789
26534
|
await s.reseal().catch(() => {});
|
|
25790
26535
|
await this.reconcile(groupId, live, now);
|
|
25791
26536
|
}
|
|
@@ -26031,7 +26776,10 @@ var Communities = class {
|
|
|
26031
26776
|
* into the beacon (CLI daemons on local relays, 2026-10-03).
|
|
26032
26777
|
*/
|
|
26033
26778
|
gone(live, key) {
|
|
26034
|
-
|
|
26779
|
+
const s = live.session;
|
|
26780
|
+
if (s.wasRemoved(key)) return true;
|
|
26781
|
+
if (key === s.admin || !s.state.pendingLeaves.some((r) => r.s === key)) return false;
|
|
26782
|
+
return !(s.state.pendingLeaves.some((r) => r.s === s.admin) && [...s.state.chain].reverse().find((c) => c.k === "role")?.by === key);
|
|
26035
26783
|
}
|
|
26036
26784
|
/** Out of the group by its own leave (it signed the request), not removed: its app knows it went. */
|
|
26037
26785
|
leftItself(live, key) {
|
|
@@ -26047,6 +26795,7 @@ var Communities = class {
|
|
|
26047
26795
|
mayHear(live, key, frame, said = false) {
|
|
26048
26796
|
const f = frame;
|
|
26049
26797
|
if (live?.session.wasRemoved(key)) return f.t === "group-commit" && (f.commit?.k === "remove" || f.commit?.k === "leave") && f.commit.s === key;
|
|
26798
|
+
if (live && said && this.gone(live, key)) return f.t === "group-commit" || f.t === "group-leave";
|
|
26050
26799
|
if (!live || !said || rosterHas(live.session.roster, key)) return true;
|
|
26051
26800
|
return f.t === "group-commit" && live.session.isRecentMember(key);
|
|
26052
26801
|
}
|
|
@@ -26198,7 +26947,7 @@ var Communities = class {
|
|
|
26198
26947
|
for (const key of live.farewells.keys()) wanted.add(key);
|
|
26199
26948
|
for (const key of live.ahead.keys()) wanted.add(key);
|
|
26200
26949
|
} else for (const key of live.myHubs) wanted.add(key);
|
|
26201
|
-
for (const [key, id] of existing) if (this.host.linkReady(id, 2) && (live.members.has(key) || this.recentHub(live, key)) && !
|
|
26950
|
+
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);
|
|
26202
26951
|
}
|
|
26203
26952
|
for (const [key, since] of live.restored) {
|
|
26204
26953
|
if (!since) live.restored.set(key, now);
|
|
@@ -26319,7 +27068,7 @@ var Communities = class {
|
|
|
26319
27068
|
const s = live.session;
|
|
26320
27069
|
if (!s.adminWork || !s.entryKey || !s.state.entry.seedB64) return;
|
|
26321
27070
|
const full = s.roster.length >= COMMUNITY_LIMITS.members, held = admissionsHeld(s);
|
|
26322
|
-
for (const [key, at] of live.fullTold) if (now - at >= FULL_TELL_MS) live.fullTold.delete(key);
|
|
27071
|
+
for (const [key, at] of live.fullTold) if (now - at >= FULL_TELL_MS$1) live.fullTold.delete(key);
|
|
26323
27072
|
const link = {
|
|
26324
27073
|
g: groupId,
|
|
26325
27074
|
host: s.entryKey
|
|
@@ -26515,7 +27264,7 @@ var Communities = class {
|
|
|
26515
27264
|
} catch {}
|
|
26516
27265
|
live.pendingEntries.delete(peer);
|
|
26517
27266
|
live.fullTold.set(peer, now);
|
|
26518
|
-
live.lingering.set(linkId, now + FULL_LINGER_MS);
|
|
27267
|
+
live.lingering.set(linkId, now + FULL_LINGER_MS$1);
|
|
26519
27268
|
return true;
|
|
26520
27269
|
}
|
|
26521
27270
|
if (!rosterHas(s.roster, peer) && admissionsHeld(s)) {
|
|
@@ -26681,7 +27430,11 @@ var Communities = class {
|
|
|
26681
27430
|
/** A frame on an edge, from the member it is pinned to: handled, then relayed on by a hub. */
|
|
26682
27431
|
async handleEdgeFrame(groupId, peerKey, frame) {
|
|
26683
27432
|
const live = this.live.get(groupId);
|
|
26684
|
-
if (!live
|
|
27433
|
+
if (!live) {
|
|
27434
|
+
await this.afterLeave(groupId, peerKey, frame);
|
|
27435
|
+
return;
|
|
27436
|
+
}
|
|
27437
|
+
if (!frame || typeof frame !== "object") return;
|
|
26685
27438
|
const f = frame;
|
|
26686
27439
|
if (live.session.wasRemoved(peerKey)) {
|
|
26687
27440
|
if (f.t === "group-sync" && live.session.isMember) this.sayFarewell(groupId, live, peerKey, f);
|
|
@@ -28091,9 +28844,14 @@ function otherEndSeen(presence, dataLink, now = Date.now()) {
|
|
|
28091
28844
|
}
|
|
28092
28845
|
/** The key an edit of message `id` goes by in `FramesTaken`. */
|
|
28093
28846
|
var editKey = (id, e) => `${id}#e${e}`;
|
|
28847
|
+
/** The key my reaction numbered `n` goes by in `FramesTaken` (the number is mine in the group, whatever the message). */
|
|
28848
|
+
var reactionKey = (n) => `#r${n}`;
|
|
28849
|
+
/** The key my pin (or unpin) numbered `n` goes by in `FramesTaken`: one pin per group, its number newer each time. */
|
|
28850
|
+
var pinKey = (n) => `#p${n}`;
|
|
28094
28851
|
/**
|
|
28095
28852
|
* Which of my frames an edge took (handed to an open session), per group: what `ghostly group send --wait sent` waits
|
|
28096
|
-
* for. A message by its id, an edit by `editKey
|
|
28853
|
+
* for. A message by its id, an edit by `editKey`, a reaction by `reactionKey`, a pin by `pinKey`. A group has no
|
|
28854
|
+
* receipts: this is as far as the author can see.
|
|
28097
28855
|
*/
|
|
28098
28856
|
var FramesTaken = class {
|
|
28099
28857
|
counts = /* @__PURE__ */ new Map();
|
|
@@ -28317,6 +29075,14 @@ var JAMMED_WINDOW_MS = 9e5;
|
|
|
28317
29075
|
/** A joiner refused (its app cannot follow the group) is not answered again for this long. */
|
|
28318
29076
|
var REFUSED_FOR_MS = 6e5;
|
|
28319
29077
|
/**
|
|
29078
|
+
* A full group's admin answers a knock with `group-full` (WISP 902 § A full group): the same joiner at most this often
|
|
29079
|
+
* while there is no room, its side of the entry session closed `FULL_LINGER_MS` after. The joiner shows it is full for
|
|
29080
|
+
* `FULL_SAID_MS` after the last one (one answer missed included), then waits as before.
|
|
29081
|
+
*/
|
|
29082
|
+
var FULL_TELL_MS = 3e5;
|
|
29083
|
+
var FULL_LINGER_MS = 5e3;
|
|
29084
|
+
var FULL_SAID_MS = 66e4;
|
|
29085
|
+
/**
|
|
28320
29086
|
* The removed ids with this one noted. Full, the oldest of the author who has the most goes (the one just noted's own on
|
|
28321
29087
|
* a tie): a member's removals of messages that are not here, as many as they like, push out only their own.
|
|
28322
29088
|
*/
|
|
@@ -28371,6 +29137,8 @@ var ACCEPT_AGAINS = 5;
|
|
|
28371
29137
|
var REWELCOME_MS = ACCEPT_AGAIN_MS / 2;
|
|
28372
29138
|
/** Invitee side: the invitations one contact chat may have waiting here at a time. More are answered as declined. */
|
|
28373
29139
|
var MAX_INVITATIONS_PER_CHAT = 4;
|
|
29140
|
+
/** Invitee side: the invitations that may wait here at a time, all contact chats together. More are not kept. */
|
|
29141
|
+
var MAX_WAITING_INVITATIONS = 32;
|
|
28374
29142
|
/** Other groups kept beside one under its id (`StoredGroup.others`), at most; an invitation past them is declined. */
|
|
28375
29143
|
var MAX_OTHER_GROUPS = 4;
|
|
28376
29144
|
/** Invitee side, removed and invited again: the chat that let me into the group I kept, if it is its admin's. */
|
|
@@ -28456,7 +29224,6 @@ function meshEdgeIntervals(base, members) {
|
|
|
28456
29224
|
*/
|
|
28457
29225
|
var Groups = class {
|
|
28458
29226
|
host;
|
|
28459
|
-
store;
|
|
28460
29227
|
timings;
|
|
28461
29228
|
stored = /* @__PURE__ */ new Map();
|
|
28462
29229
|
sessions = /* @__PURE__ */ new Map();
|
|
@@ -28492,6 +29259,12 @@ var Groups = class {
|
|
|
28492
29259
|
refused = /* @__PURE__ */ new Map();
|
|
28493
29260
|
/** Admin side: entry sessions of a member key that timed out in a row, and when the last did. */
|
|
28494
29261
|
entryTimeouts = /* @__PURE__ */ new Map();
|
|
29262
|
+
/** Admin side: joiners told the group has no room (`group-full`), per group: member key → when. */
|
|
29263
|
+
fullTold = /* @__PURE__ */ new Map();
|
|
29264
|
+
/** Admin side: entry sessions a `group-full` went over, closed at `until`. */
|
|
29265
|
+
fullClosing = /* @__PURE__ */ new Map();
|
|
29266
|
+
/** Joiner side: the last `group-full` the admin's app answered with, and when. */
|
|
29267
|
+
toldFull = /* @__PURE__ */ new Map();
|
|
28495
29268
|
lastPoll = /* @__PURE__ */ new Map();
|
|
28496
29269
|
/** Admin side: when a link nobody is using was last read. Those links share one `pollMs` between them, read in turn. */
|
|
28497
29270
|
lastQuietPoll = 0;
|
|
@@ -28594,10 +29367,14 @@ var Groups = class {
|
|
|
28594
29367
|
signals;
|
|
28595
29368
|
/** Files and voice messages in every group, private or community (WISP 503 · Group Files). */
|
|
28596
29369
|
files;
|
|
29370
|
+
/** Where private groups are written: a message writes the group's small row, a commit its record too (`GroupRows`). */
|
|
29371
|
+
rows;
|
|
29372
|
+
store;
|
|
28597
29373
|
constructor(host, store = db, timings = ENTRY_TIMINGS, communityTimings = COMMUNITY_TIMINGS, random, hubTimings = MESH_HUB_TIMINGS) {
|
|
28598
29374
|
this.host = host;
|
|
28599
|
-
this.store = store;
|
|
28600
29375
|
this.timings = timings;
|
|
29376
|
+
this.rows = new GroupRows(store);
|
|
29377
|
+
this.store = this.rows.store;
|
|
28601
29378
|
this.communities = new Communities(host, store, communityTimings, random);
|
|
28602
29379
|
this.hubs = new MeshHubs(host, {
|
|
28603
29380
|
stored: (id) => this.stored.get(id),
|
|
@@ -28678,6 +29455,7 @@ var Groups = class {
|
|
|
28678
29455
|
/** `asItIs`: a copy that must stay as it was stored (limited mode, WISP 06), so nothing left over is cleared from it. */
|
|
28679
29456
|
async load(asItIs = false) {
|
|
28680
29457
|
const all = await this.store.getGroups();
|
|
29458
|
+
await this.rows.load(all);
|
|
28681
29459
|
await this.communities.load(all.filter((g) => g.community || g.joining));
|
|
28682
29460
|
for (const group of all.filter((g) => !g.community && !g.joining)) {
|
|
28683
29461
|
this.stored.set(group.id, group);
|
|
@@ -28764,7 +29542,7 @@ var Groups = class {
|
|
|
28764
29542
|
...group.others?.length ? { others: group.others.map((other) => this.otherView(other)) } : {}
|
|
28765
29543
|
};
|
|
28766
29544
|
if (!session) {
|
|
28767
|
-
const invitation = group.invitation;
|
|
29545
|
+
const invitation = group.invitation, full = invitation.entry && !invitation.admin ? this.fullSaid(group.id) : void 0;
|
|
28768
29546
|
return {
|
|
28769
29547
|
...base,
|
|
28770
29548
|
name: groupName(invitation.name) ?? "",
|
|
@@ -28784,6 +29562,10 @@ var Groups = class {
|
|
|
28784
29562
|
viaLink: true,
|
|
28785
29563
|
stage: this.joinStage(group),
|
|
28786
29564
|
...this.gaveUp.has(group.id) && { unanswered: true },
|
|
29565
|
+
...full && { full: {
|
|
29566
|
+
n: full.n,
|
|
29567
|
+
max: full.max
|
|
29568
|
+
} },
|
|
28787
29569
|
...this.othersKnocked.has(group.id) && { othersKnocked: true }
|
|
28788
29570
|
} : {}
|
|
28789
29571
|
}
|
|
@@ -28877,20 +29659,25 @@ var Groups = class {
|
|
|
28877
29659
|
return this.isCommunity(groupId);
|
|
28878
29660
|
}
|
|
28879
29661
|
/** Through a community group: an application frame to everyone, or a payload sealed to one member. */
|
|
28880
|
-
sendCommunityApp(groupId, frame) {
|
|
28881
|
-
return this.communities.sendApp(groupId, frame);
|
|
29662
|
+
sendCommunityApp(groupId, frame, key) {
|
|
29663
|
+
return this.communities.sendApp(groupId, frame, key);
|
|
28882
29664
|
}
|
|
28883
29665
|
sendCommunityPair(groupId, to, payload) {
|
|
28884
29666
|
return this.communities.sendPair(groupId, to, payload);
|
|
28885
29667
|
}
|
|
28886
29668
|
/**
|
|
28887
|
-
* How many edges took my message `messageId` (or its edit number `edit
|
|
28888
|
-
* in a community, the edges to my hubs, which pass it on.
|
|
29669
|
+
* How many edges took my message `messageId` (or its edit number `edit`, or my reaction numbered `reaction`, or my pin
|
|
29670
|
+
* numbered `pin`) so far: in a private group, members' edges; in a community, the edges to my hubs, which pass it on.
|
|
29671
|
+
* 0 while none did.
|
|
28889
29672
|
*/
|
|
28890
|
-
taken(groupId, messageId, edit) {
|
|
28891
|
-
const key = edit ? editKey(messageId, edit) : messageId;
|
|
29673
|
+
taken(groupId, messageId, edit, reaction, pin) {
|
|
29674
|
+
const key = pin ? pinKey(pin) : reaction ? reactionKey(reaction) : edit ? editKey(messageId, edit) : messageId;
|
|
28892
29675
|
return this.isCommunity(groupId) ? this.communities.taken(groupId, key) : this.frames.count(groupId, key);
|
|
28893
29676
|
}
|
|
29677
|
+
/** An edge of a private group took a frame of mine the engine said on it (a reaction, a pin): `key` as `taken` reads it. */
|
|
29678
|
+
noteTaken(groupId, key) {
|
|
29679
|
+
this.frames.add(groupId, key);
|
|
29680
|
+
}
|
|
28894
29681
|
/**
|
|
28895
29682
|
* Says an edit of my message to the group (WISP 902 § Edits): over the edges of a private group (to member `to`
|
|
28896
29683
|
* alone, when given), through a community like any frame. An error when it cannot go now.
|
|
@@ -29131,6 +29918,35 @@ var Groups = class {
|
|
|
29131
29918
|
};
|
|
29132
29919
|
}
|
|
29133
29920
|
}
|
|
29921
|
+
/**
|
|
29922
|
+
* Invitee side: 32 invitations wait, and a new one comes over a chat whose invitations this app accepts by itself
|
|
29923
|
+
* (`GroupsHost.autoJoins`). It takes the place of the oldest waiting from the chat that holds the most (of chats tied,
|
|
29924
|
+
* the one whose oldest is oldest), its inviter told no as one past the 32 is, so that contacts whose invitations
|
|
29925
|
+
* nobody here answers cannot keep it out. Never one over such a chat, one being accepted, or a link's join. Nothing
|
|
29926
|
+
* is made room for when the new one replaces one waiting under its id (it takes no new room) or its chat holds its
|
|
29927
|
+
* four already. True when room was made.
|
|
29928
|
+
*/
|
|
29929
|
+
async roomForAutoJoin(linkId, existing) {
|
|
29930
|
+
if (!this.host.autoJoins?.(linkId) || existing?.invitation && !existing.invitation.takenBack) return false;
|
|
29931
|
+
const waiting = [...this.stored.values()].filter((x) => x.invitation && !x.invitation.takenBack);
|
|
29932
|
+
if (waiting.filter((x) => x.invitation.linkId === linkId).length >= MAX_INVITATIONS_PER_CHAT) return false;
|
|
29933
|
+
const autoJoined = /* @__PURE__ */ new Map();
|
|
29934
|
+
const autoJoins = (chat) => autoJoined.get(chat) ?? autoJoined.set(chat, !!this.host.autoJoins?.(chat)).get(chat);
|
|
29935
|
+
const others = waiting.filter((x) => !x.state && !x.invitation.entry && !x.invitation.seedB64 && !autoJoins(x.invitation.linkId));
|
|
29936
|
+
const held = /* @__PURE__ */ new Map();
|
|
29937
|
+
for (const x of others) held.set(x.invitation.linkId, (held.get(x.invitation.linkId) ?? 0) + 1);
|
|
29938
|
+
const most = Math.max(0, ...held.values());
|
|
29939
|
+
const oldest = others.filter((x) => held.get(x.invitation.linkId) === most).sort((a, b) => a.createdAt - b.createdAt)[0];
|
|
29940
|
+
if (!oldest) return false;
|
|
29941
|
+
try {
|
|
29942
|
+
this.host.sendOnLink(oldest.invitation.linkId, {
|
|
29943
|
+
t: "group-decline",
|
|
29944
|
+
g: oldest.id
|
|
29945
|
+
});
|
|
29946
|
+
} catch {}
|
|
29947
|
+
await this.dropInvitation(oldest);
|
|
29948
|
+
return true;
|
|
29949
|
+
}
|
|
29134
29950
|
/** Invitee side: a decline its inviter's chat was down for is said once that chat is up, or dropped after `LEFT_KEPT_MS`. */
|
|
29135
29951
|
async declineOwed(group, now) {
|
|
29136
29952
|
const { at, linkId } = group.declined;
|
|
@@ -29623,6 +30439,8 @@ var Groups = class {
|
|
|
29623
30439
|
this.lastRoster.delete(groupId);
|
|
29624
30440
|
this.lastTold.delete(groupId);
|
|
29625
30441
|
this.pendingEntries.delete(groupId);
|
|
30442
|
+
this.fullTold.delete(groupId);
|
|
30443
|
+
this.toldFull.delete(groupId);
|
|
29626
30444
|
this.entriesSeen.delete(groupId);
|
|
29627
30445
|
this.unansweredEntries.delete(groupId);
|
|
29628
30446
|
this.framesKept.delete(groupId);
|
|
@@ -29838,7 +30656,7 @@ var Groups = class {
|
|
|
29838
30656
|
if (linkId) await this.host.closeEdge(linkId);
|
|
29839
30657
|
}
|
|
29840
30658
|
this.noteUnanswered(group.id, now, unanswered);
|
|
29841
|
-
const busy = (pending?.size ?? 0) >= MAX_PENDING_ENTRIES
|
|
30659
|
+
const busy = (pending?.size ?? 0) >= MAX_PENDING_ENTRIES;
|
|
29842
30660
|
const since = now - (this.lastPoll.get(group.id) ?? 0);
|
|
29843
30661
|
if (busy) continue;
|
|
29844
30662
|
const held = this.knocksHeldUntil.get(group.id);
|
|
@@ -29856,6 +30674,10 @@ var Groups = class {
|
|
|
29856
30674
|
}
|
|
29857
30675
|
}
|
|
29858
30676
|
for (const [key, until] of this.refused) if (until <= now) this.refused.delete(key);
|
|
30677
|
+
for (const [linkId, { groupId, until }] of this.fullClosing) if (now >= until || !this.host.linkReady(linkId)) {
|
|
30678
|
+
this.fullClosing.delete(linkId);
|
|
30679
|
+
if ([...this.host.entries(groupId).values()].includes(linkId)) await this.host.closeEdge(linkId);
|
|
30680
|
+
}
|
|
29859
30681
|
for (const [key, { at }] of this.entryTimeouts) if (now - at > 36e5) this.entryTimeouts.delete(key);
|
|
29860
30682
|
for (const [groupId, kept] of this.lingering) if (now >= kept.until) await this.endLinger(groupId);
|
|
29861
30683
|
this.meshTick(now);
|
|
@@ -29939,6 +30761,29 @@ var Groups = class {
|
|
|
29939
30761
|
}
|
|
29940
30762
|
const session = this.sessions.get(groupId), group = this.stored.get(groupId);
|
|
29941
30763
|
if (!session?.isAdmin || !group || !this.pendingEntries.get(groupId)?.has(peer)) return;
|
|
30764
|
+
const full = rosterHas(session.roster, peer) ? null : this.noRoom(group, session, peer);
|
|
30765
|
+
if (full) {
|
|
30766
|
+
try {
|
|
30767
|
+
this.host.sendOnLink(linkId, {
|
|
30768
|
+
t: "group-full",
|
|
30769
|
+
g: groupId,
|
|
30770
|
+
n: full.n,
|
|
30771
|
+
max: GROUP_MEMBER_CAP.max,
|
|
30772
|
+
...full.update && { why: "update" }
|
|
30773
|
+
});
|
|
30774
|
+
traceJoin(groupId, "full.sent");
|
|
30775
|
+
} catch {}
|
|
30776
|
+
const now = this.now();
|
|
30777
|
+
this.pendingEntries.get(groupId)?.delete(peer);
|
|
30778
|
+
let told = this.fullTold.get(groupId);
|
|
30779
|
+
if (!told) this.fullTold.set(groupId, told = /* @__PURE__ */ new Map());
|
|
30780
|
+
told.set(peer, now);
|
|
30781
|
+
this.fullClosing.set(linkId, {
|
|
30782
|
+
groupId,
|
|
30783
|
+
until: now + FULL_LINGER_MS
|
|
30784
|
+
});
|
|
30785
|
+
return;
|
|
30786
|
+
}
|
|
29942
30787
|
if (!rosterHas(session.roster, peer) && this.growthBlocked(group, session, session.roster.length + 1, linkId)) {
|
|
29943
30788
|
this.pendingEntries.get(groupId)?.delete(peer);
|
|
29944
30789
|
this.refused.set(peer, Date.now() + REFUSED_FOR_MS);
|
|
@@ -29995,9 +30840,20 @@ var Groups = class {
|
|
|
29995
30840
|
joinStage(group) {
|
|
29996
30841
|
const invitation = group.invitation;
|
|
29997
30842
|
if (invitation.admin) return "admitted";
|
|
30843
|
+
const full = this.fullSaid(group.id);
|
|
30844
|
+
if (full) return full.update ? "blocked" : "full";
|
|
29998
30845
|
if (this.host.linkReady(invitation.linkId) || this.host.linkSeen?.(invitation.linkId)) return "answered";
|
|
29999
30846
|
return this.knocked.has(group.id) ? "knocked" : "knocking";
|
|
30000
30847
|
}
|
|
30848
|
+
/** The admin's app said lately that the group has no room (`group-full`): how full, as it said, and whether it waits for updates. */
|
|
30849
|
+
fullSaid(groupId) {
|
|
30850
|
+
const told = this.toldFull.get(groupId);
|
|
30851
|
+
return told && this.now() - told.at < FULL_SAID_MS ? {
|
|
30852
|
+
n: told.n,
|
|
30853
|
+
max: told.max,
|
|
30854
|
+
update: told.update
|
|
30855
|
+
} : void 0;
|
|
30856
|
+
}
|
|
30001
30857
|
entryOf(group) {
|
|
30002
30858
|
if (!group.entry) return void 0;
|
|
30003
30859
|
const { seedB64 } = group.entry;
|
|
@@ -30148,15 +31004,18 @@ var Groups = class {
|
|
|
30148
31004
|
});
|
|
30149
31005
|
let pending = this.pendingEntries.get(group.id);
|
|
30150
31006
|
let ever;
|
|
31007
|
+
const told = this.fullTold.get(group.id);
|
|
31008
|
+
for (const [key, at] of told ?? []) if (now - at >= FULL_TELL_MS) told?.delete(key);
|
|
30151
31009
|
for (const { key, ts } of knocks) {
|
|
30152
31010
|
const again = this.unwelcomed(group, session, key);
|
|
30153
31011
|
if (now - ts > 18e4 || rosterHas(session.roster, key) && !again || this.refused.has(key) || pending?.has(key) || key === entry.link.host) continue;
|
|
30154
31012
|
if (!again && (ever ??= everMembers(session)).has(key)) continue;
|
|
30155
31013
|
if (again && this.rewelcomedLately(group.id, key)) continue;
|
|
30156
|
-
|
|
30157
|
-
|
|
30158
|
-
|
|
30159
|
-
|
|
31014
|
+
if ((pending?.size ?? 0) >= MAX_PENDING_ENTRIES) break;
|
|
31015
|
+
if (!again && this.noRoom(group, session)) {
|
|
31016
|
+
const linkId = this.host.entries(group.id).get(key);
|
|
31017
|
+
if (this.fullTold.get(group.id)?.has(key) || linkId && this.fullClosing.has(linkId)) continue;
|
|
31018
|
+
}
|
|
30160
31019
|
if (!pending) this.pendingEntries.set(group.id, pending = /* @__PURE__ */ new Map());
|
|
30161
31020
|
pending.set(key, now);
|
|
30162
31021
|
this.warmUntil.set(group.id, now + this.timings.warmMs);
|
|
@@ -30169,6 +31028,25 @@ var Groups = class {
|
|
|
30169
31028
|
}
|
|
30170
31029
|
return held;
|
|
30171
31030
|
}
|
|
31031
|
+
/**
|
|
31032
|
+
* Why the group has no room for one more joiner, or null: full (those invited and those being let in counted, `except`
|
|
31033
|
+
* the joiner asked about), or past eight while a member's app takes only eight (`update`; the newcomer's own app is
|
|
31034
|
+
* checked on its entry session). `n`: the members it has.
|
|
31035
|
+
*/
|
|
31036
|
+
noRoom(group, session, except) {
|
|
31037
|
+
const entryIds = new Set(this.host.entries(group.id).values());
|
|
31038
|
+
const contactsInvited = [...this.invited.get(group.id) ?? []].filter((id) => !entryIds.has(id)).length;
|
|
31039
|
+
const pending = [...this.pendingEntries.get(group.id)?.keys() ?? []].filter((key) => key !== except).length;
|
|
31040
|
+
const size = session.roster.length + contactsInvited + pending;
|
|
31041
|
+
if (size >= GROUP_MEMBER_CAP.max) return {
|
|
31042
|
+
n: session.roster.length,
|
|
31043
|
+
update: false
|
|
31044
|
+
};
|
|
31045
|
+
return this.growthBlocked(group, session, size + 1) ? {
|
|
31046
|
+
n: session.roster.length,
|
|
31047
|
+
update: true
|
|
31048
|
+
} : null;
|
|
31049
|
+
}
|
|
30172
31050
|
/** The admin's entry sessions of this group whose other side was seen, once and for as long as they are open. */
|
|
30173
31051
|
seenEntries(groupId) {
|
|
30174
31052
|
let seen = this.entriesSeen.get(groupId);
|
|
@@ -30218,8 +31096,7 @@ var Groups = class {
|
|
|
30218
31096
|
});
|
|
30219
31097
|
const ownWaiting = existing?.invitation && !existing.invitation.takenBack && existing.invitation.linkId === linkId || existing?.others?.some((o) => "linkId" in o && o.linkId === linkId);
|
|
30220
31098
|
const waiting = [...this.stored.values()].flatMap((x) => [...x.invitation && !x.invitation.takenBack ? [x.invitation.linkId] : [], ...(x.others ?? []).flatMap((o) => "linkId" in o ? [o.linkId] : [])]);
|
|
30221
|
-
if (!ownWaiting && waiting.length >=
|
|
30222
|
-
if (!ownWaiting && waiting.filter((chat) => chat === linkId).length >= MAX_INVITATIONS_PER_CHAT) {
|
|
31099
|
+
if (!ownWaiting && (waiting.filter((chat) => chat === linkId).length >= MAX_INVITATIONS_PER_CHAT || waiting.length >= MAX_WAITING_INVITATIONS && !await this.roomForAutoJoin(linkId, existing))) {
|
|
30223
31100
|
try {
|
|
30224
31101
|
this.host.sendOnLink(linkId, {
|
|
30225
31102
|
t: "group-decline",
|
|
@@ -30238,6 +31115,7 @@ var Groups = class {
|
|
|
30238
31115
|
...invitationClaims(frame)
|
|
30239
31116
|
};
|
|
30240
31117
|
await this.store.putGroup(existing);
|
|
31118
|
+
this.toldFull.delete(g);
|
|
30241
31119
|
traceJoin(g, "invite.received");
|
|
30242
31120
|
this.host.sendOnLink(linkId, {
|
|
30243
31121
|
t: "group-accept",
|
|
@@ -30292,6 +31170,20 @@ var Groups = class {
|
|
|
30292
31170
|
this.host.emit();
|
|
30293
31171
|
return;
|
|
30294
31172
|
}
|
|
31173
|
+
case "group-full": {
|
|
31174
|
+
const invitation = this.stored.get(g)?.invitation, { n, max } = frame;
|
|
31175
|
+
if (!invitation?.entry || this.stored.get(g).state || invitation.linkId !== linkId || invitation.admin) return;
|
|
31176
|
+
if (!Number.isSafeInteger(n) || !Number.isSafeInteger(max) || max < 1 || n < 0) return;
|
|
31177
|
+
this.toldFull.set(g, {
|
|
31178
|
+
n,
|
|
31179
|
+
max,
|
|
31180
|
+
update: frame.why === "update",
|
|
31181
|
+
at: this.now()
|
|
31182
|
+
});
|
|
31183
|
+
traceJoin(g, "full.received");
|
|
31184
|
+
this.host.emit();
|
|
31185
|
+
return;
|
|
31186
|
+
}
|
|
30295
31187
|
case "group-accept": {
|
|
30296
31188
|
const session = this.sessions.get(g);
|
|
30297
31189
|
if (typeof frame.key !== "string" || !MEMBER_KEY.test(frame.key)) return;
|
|
@@ -31285,7 +32177,7 @@ var Groups = class {
|
|
|
31285
32177
|
const group = this.stored.get(state.id);
|
|
31286
32178
|
if (!group || this.sessions.get(state.id) !== session) return;
|
|
31287
32179
|
group.state = next;
|
|
31288
|
-
await this.
|
|
32180
|
+
await this.rows.save(group);
|
|
31289
32181
|
},
|
|
31290
32182
|
send: (to, frame) => {
|
|
31291
32183
|
const edge = this.host.edges(state.id).get(to);
|
|
@@ -34420,12 +35312,13 @@ var PEEK_LIMITS = {
|
|
|
34420
35312
|
windowMs: 6e5
|
|
34421
35313
|
};
|
|
34422
35314
|
/**
|
|
34423
|
-
* How a profile reads Pkarr records: the DHT itself (Desktop, unless its relays are read too), or these relays
|
|
34424
|
-
*
|
|
35315
|
+
* How a profile reads Pkarr records: the DHT itself (Desktop, unless its relays are read too), or these relays (a
|
|
35316
|
+
* browser, or a Desktop profile with Hide my IP from contacts on, which keeps off the DHT). Two profiles with the same
|
|
35317
|
+
* path show the network nothing new when one reads the other's records.
|
|
34425
35318
|
*/
|
|
34426
35319
|
function readPathOf(settings, direct) {
|
|
34427
35320
|
const relays = [...new Set(currentRelays(settings?.relays?.length ? settings.relays : DEFAULT_RELAYS).map(normalizeRelayUrl).filter((r) => !!r))].sort();
|
|
34428
|
-
if (direct) return settings?.readRelays === true ? `dht+${relays.join(",")}` : "dht";
|
|
35321
|
+
if (direct && settings?.relayOnly !== true) return settings?.readRelays === true ? `dht+${relays.join(",")}` : "dht";
|
|
34429
35322
|
return relays.join(",");
|
|
34430
35323
|
}
|
|
34431
35324
|
/** A community group this profile is in (mesh groups publish nothing to look at). */
|
|
@@ -34969,10 +35862,8 @@ var SwapUnsettledError = class extends Error {
|
|
|
34969
35862
|
* contact is told when the mint never made a redeem (`PaymentDesk.onSwapSettled`). The token stays unspent.
|
|
34970
35863
|
*/
|
|
34971
35864
|
var MINT_DID_NOT_CONFIRM = "The mint did not confirm the ecash";
|
|
34972
|
-
/**
|
|
34973
|
-
var
|
|
34974
|
-
/** When a melt with no answer can no longer reach the mint: its one request is sent right after it is written down. */
|
|
34975
|
-
var meltOverdueAt = (melt) => melt.createdAt + CASHU_REQUEST_TIMEOUT_MS + SWAP_SETTLED_MS;
|
|
35865
|
+
/** How many of the times melts and swaps wrote down a wallet keeps on the monotonic clock (`CashuWallet.passed`). */
|
|
35866
|
+
var WRITTEN_KEPT = 1e3;
|
|
34976
35867
|
var swapOf = (swap) => swap.swap;
|
|
34977
35868
|
function normalizeMintUrl(input) {
|
|
34978
35869
|
let url;
|
|
@@ -35111,13 +36002,21 @@ function within$1(ms, work, mint) {
|
|
|
35111
36002
|
});
|
|
35112
36003
|
return Promise.race([work, late]).finally(() => clearTimeout(timer));
|
|
35113
36004
|
}
|
|
36005
|
+
/**
|
|
36006
|
+
* How long a mint that could not be loaded stays so for the payment poll's reads, then twice as long after each failed
|
|
36007
|
+
* load up to `MINT_FAILED_CAP_MS`: the payments of one round at a gone mint share its failure, instead of each loading
|
|
36008
|
+
* it again (three requests each), and so do payments made at different times, whose own backoffs are out of step.
|
|
36009
|
+
*/
|
|
36010
|
+
var MINT_FAILED_MS = 5e3;
|
|
36011
|
+
var MINT_FAILED_CAP_MS = 6e5;
|
|
35114
36012
|
var CashuWallet = class CashuWallet {
|
|
35115
36013
|
getMints;
|
|
35116
36014
|
events;
|
|
35117
36015
|
getKnownMints;
|
|
35118
36016
|
wallets = /* @__PURE__ */ new Map();
|
|
35119
|
-
/**
|
|
35120
|
-
failedLoads = /* @__PURE__ */ new
|
|
36017
|
+
/** The mints whose load in `wallets` failed: the payment poll's reads try them again at `mintAsk`'s pace. */
|
|
36018
|
+
failedLoads = /* @__PURE__ */ new Set();
|
|
36019
|
+
mintAsk = new AskBackoff(MINT_FAILED_MS, MINT_FAILED_CAP_MS);
|
|
35121
36020
|
names = /* @__PURE__ */ new Map();
|
|
35122
36021
|
infos = /* @__PURE__ */ new Map();
|
|
35123
36022
|
locks = /* @__PURE__ */ new Map();
|
|
@@ -35153,6 +36052,12 @@ var CashuWallet = class CashuWallet {
|
|
|
35153
36052
|
* (the mint's reserve and the coins' own fees). Only these are paid, for no more. */
|
|
35154
36053
|
shownQuotes = /* @__PURE__ */ new Map();
|
|
35155
36054
|
/**
|
|
36055
|
+
* Per time a melt or swap wrote down (`createdAt`, `attemptEndedAt`): where it stands on the monotonic clock. Whether a
|
|
36056
|
+
* request of it can still reach the mint is measured from there (`passed`): read by the wall clock, a clock stepped an
|
|
36057
|
+
* hour forward booked a melt whose answer was lost unpaid within seconds, its sats back, and then the mint paid it.
|
|
36058
|
+
*/
|
|
36059
|
+
writtenAt = /* @__PURE__ */ new Map();
|
|
36060
|
+
/**
|
|
35156
36061
|
* `getMints`: the mints of one network (the engine's default when none is named), primary first: balances,
|
|
35157
36062
|
* invoices, payments of that network's Cashu wallet. `getKnownMints`: every mint the user added, whatever its
|
|
35158
36063
|
* network: ecash from any of them is taken in, and counts in its own network's wallet.
|
|
@@ -35193,6 +36098,38 @@ var CashuWallet = class CashuWallet {
|
|
|
35193
36098
|
}
|
|
35194
36099
|
/** How long `stop` waits for a swap in a per-mint lock. */
|
|
35195
36100
|
static STOP_WAIT_MS = 3e4;
|
|
36101
|
+
/** The wall-clock time a melt or swap writes down, its place on the monotonic clock kept for `passed`. */
|
|
36102
|
+
stamp() {
|
|
36103
|
+
const now = Date.now();
|
|
36104
|
+
this.keepWritten(now, performance.now());
|
|
36105
|
+
return now;
|
|
36106
|
+
}
|
|
36107
|
+
keepWritten(at, monotonic) {
|
|
36108
|
+
this.writtenAt.set(at, monotonic);
|
|
36109
|
+
if (this.writtenAt.size > WRITTEN_KEPT) this.writtenAt.delete(this.writtenAt.keys().next().value);
|
|
36110
|
+
}
|
|
36111
|
+
/**
|
|
36112
|
+
* How long really passed since `at`, a time a melt or swap wrote down, while this wallet ran. One written by an earlier
|
|
36113
|
+
* run counts by the wall clock up to the first time this run asks, never below nothing: written by a clock ahead of
|
|
36114
|
+
* this one, its window starts again rather than waiting for the clock to get there.
|
|
36115
|
+
*/
|
|
36116
|
+
passed(at) {
|
|
36117
|
+
let since = this.writtenAt.get(at);
|
|
36118
|
+
if (since === void 0) this.keepWritten(at, since = performance.now() - Math.max(0, Date.now() - at));
|
|
36119
|
+
return performance.now() - since;
|
|
36120
|
+
}
|
|
36121
|
+
/** Whether no request of this melt can reach the mint any more: its one request is sent right after it is written down. */
|
|
36122
|
+
meltOverdue(melt) {
|
|
36123
|
+
return this.passed(melt.createdAt) >= CASHU_REQUEST_TIMEOUT_MS + SWAP_SETTLED_MS;
|
|
36124
|
+
}
|
|
36125
|
+
/** Whether no request of this swap can reach the mint any more: a request's longest life, and a margin after its last try. */
|
|
36126
|
+
swapOverdue(swap) {
|
|
36127
|
+
return swap.attemptEndedAt !== void 0 && this.passed(swap.createdAt) >= 42e4 && this.passed(swap.attemptEndedAt) >= 12e4;
|
|
36128
|
+
}
|
|
36129
|
+
/** Whether a swap is past the hour it is watched for (`SWAP_WATCH_MS`). */
|
|
36130
|
+
pastWatch(swap) {
|
|
36131
|
+
return this.passed(swap.createdAt) >= SWAP_WATCH_MS;
|
|
36132
|
+
}
|
|
35196
36133
|
/**
|
|
35197
36134
|
* The Cashu wallet of one network: its mints, their balance, and the network's newest movements (every network's when
|
|
35198
36135
|
* none is named) with the fees they paid. Only those movements are read, however long the history is. `read` is the
|
|
@@ -35397,7 +36334,15 @@ var CashuWallet = class CashuWallet {
|
|
|
35397
36334
|
assertAmount(amount);
|
|
35398
36335
|
const mint = this.getMints(network).find(paysItsOwnInvoices);
|
|
35399
36336
|
if (!mint) throw new Error("This wallet has no test mint to ask for test coins");
|
|
35400
|
-
|
|
36337
|
+
let response;
|
|
36338
|
+
try {
|
|
36339
|
+
response = await within$1(MINT_TIMEOUT_MS, mintInvoice(await this.wallet(mint), amount, "Ghostly test coins"), mint);
|
|
36340
|
+
} catch (error) {
|
|
36341
|
+
throw mintFailed(error) ? Object.assign(engineError("mintFailedFaucet", {
|
|
36342
|
+
host: new URL(mint).host,
|
|
36343
|
+
reason: mintReason(error)
|
|
36344
|
+
}), { cause: error }) : error;
|
|
36345
|
+
}
|
|
35401
36346
|
const quote = {
|
|
35402
36347
|
quote: response.quote,
|
|
35403
36348
|
mint,
|
|
@@ -35994,7 +36939,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35994
36939
|
mint,
|
|
35995
36940
|
kind: "receive",
|
|
35996
36941
|
swap: serializeSwapPreview(preview),
|
|
35997
|
-
createdAt:
|
|
36942
|
+
createdAt: this.stamp(),
|
|
35998
36943
|
token,
|
|
35999
36944
|
...records(preview.amount.toNumber())
|
|
36000
36945
|
};
|
|
@@ -36059,7 +37004,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36059
37004
|
mint,
|
|
36060
37005
|
kind: "send",
|
|
36061
37006
|
swap: serializeSwapPreview(preview),
|
|
36062
|
-
createdAt:
|
|
37007
|
+
createdAt: this.stamp()
|
|
36063
37008
|
};
|
|
36064
37009
|
const inputs = among(preview.inputs);
|
|
36065
37010
|
await this.sealedTransact([STORES$1.proofs, STORES$1.swaps], {
|
|
@@ -36098,7 +37043,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36098
37043
|
const refused = mintRefused(error) && swap.attemptEndedAt === void 0;
|
|
36099
37044
|
const ended = {
|
|
36100
37045
|
...swap,
|
|
36101
|
-
attemptEndedAt:
|
|
37046
|
+
attemptEndedAt: this.stamp()
|
|
36102
37047
|
};
|
|
36103
37048
|
await this.putSwap(ended).catch(() => {});
|
|
36104
37049
|
const outcome = await this.swapOutcome(ended, refused).catch(() => ({ state: "open" }));
|
|
@@ -36220,7 +37165,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36220
37165
|
gone,
|
|
36221
37166
|
final: true
|
|
36222
37167
|
};
|
|
36223
|
-
if (
|
|
37168
|
+
if (this.swapOverdue(swap)) return {
|
|
36224
37169
|
state: "never",
|
|
36225
37170
|
gone,
|
|
36226
37171
|
final: false
|
|
@@ -36352,7 +37297,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36352
37297
|
* pay the request, which another member may pay.
|
|
36353
37298
|
*/
|
|
36354
37299
|
async redeemingFor(requestId) {
|
|
36355
|
-
return (await this.readSwaps()).some((s) => s.kind === "receive" && !s.released && s.payment?.requestId === requestId && !(s.stuck &&
|
|
37300
|
+
return (await this.readSwaps()).some((s) => s.kind === "receive" && !s.released && s.payment?.requestId === requestId && !(s.stuck && this.pastWatch(s)));
|
|
36356
37301
|
}
|
|
36357
37302
|
async pollSwaps(mints) {
|
|
36358
37303
|
if (!mints) {
|
|
@@ -36387,7 +37332,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36387
37332
|
if (swap.attemptEndedAt === void 0) {
|
|
36388
37333
|
swap = {
|
|
36389
37334
|
...swap,
|
|
36390
|
-
attemptEndedAt:
|
|
37335
|
+
attemptEndedAt: this.stamp()
|
|
36391
37336
|
};
|
|
36392
37337
|
await this.putSwap(swap);
|
|
36393
37338
|
}
|
|
@@ -36398,7 +37343,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36398
37343
|
};
|
|
36399
37344
|
if (!(outcome.state === "open" && outcome.idle && swap.kind === "receive" && !swap.released)) this.swapAsk.forget(id);
|
|
36400
37345
|
if (outcome.state === "open") {
|
|
36401
|
-
if (swap.released &&
|
|
37346
|
+
if (swap.released && this.pastWatch(swap)) {
|
|
36402
37347
|
await this.dropSwap(swap, /* @__PURE__ */ new Set());
|
|
36403
37348
|
return;
|
|
36404
37349
|
}
|
|
@@ -36431,7 +37376,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36431
37376
|
}
|
|
36432
37377
|
swap = {
|
|
36433
37378
|
...swap,
|
|
36434
|
-
attemptEndedAt:
|
|
37379
|
+
attemptEndedAt: this.stamp()
|
|
36435
37380
|
};
|
|
36436
37381
|
await this.putSwap(swap);
|
|
36437
37382
|
const refusal = mintRefused(error) ? await this.swapOutcome(swap, true).catch(() => void 0) : void 0;
|
|
@@ -36447,8 +37392,8 @@ var CashuWallet = class CashuWallet {
|
|
|
36447
37392
|
this.events.onChange();
|
|
36448
37393
|
} else later(this.swapAsk.missed(id, Date.now()));
|
|
36449
37394
|
}
|
|
36450
|
-
} else if (outcome.pending && swap.kind === "receive" && !swap.released &&
|
|
36451
|
-
if (
|
|
37395
|
+
} else if (outcome.pending && swap.kind === "receive" && !swap.released && this.swapOverdue(swap)) {
|
|
37396
|
+
if (!this.pastWatch(swap)) {
|
|
36452
37397
|
await this.putSwap({
|
|
36453
37398
|
...swap,
|
|
36454
37399
|
askAt: Date.now() + SWAP_SLOW_POLL_MS
|
|
@@ -36469,7 +37414,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36469
37414
|
else if (swap.payment) later(SWAP_POLL_MS);
|
|
36470
37415
|
}
|
|
36471
37416
|
} else if (swap.released) {
|
|
36472
|
-
if (outcome.final ||
|
|
37417
|
+
if (outcome.final || this.pastWatch(swap)) await this.dropSwap(swap, outcome.gone);
|
|
36473
37418
|
else later(SWAP_SLOW_POLL_MS);
|
|
36474
37419
|
return;
|
|
36475
37420
|
} else {
|
|
@@ -36479,9 +37424,9 @@ var CashuWallet = class CashuWallet {
|
|
|
36479
37424
|
}
|
|
36480
37425
|
this.events.onChange();
|
|
36481
37426
|
} catch {
|
|
36482
|
-
if (swap.released &&
|
|
37427
|
+
if (swap.released && this.pastWatch(swap)) await this.dropSwap(swap, /* @__PURE__ */ new Set()).catch(() => {});
|
|
36483
37428
|
else if (swap.released) later(SWAP_SLOW_POLL_MS);
|
|
36484
|
-
else later(this.swapAsk.missed(id, Date.now(),
|
|
37429
|
+
else later(this.swapAsk.missed(id, Date.now(), !this.swapOverdue(swap)));
|
|
36485
37430
|
}
|
|
36486
37431
|
}).catch(() => {
|
|
36487
37432
|
later(SWAP_POLL_MS);
|
|
@@ -36536,7 +37481,10 @@ var CashuWallet = class CashuWallet {
|
|
|
36536
37481
|
feeReserve: fee
|
|
36537
37482
|
};
|
|
36538
37483
|
} catch (error) {
|
|
36539
|
-
lastError = error
|
|
37484
|
+
lastError = mintFailed(error) ? Object.assign(engineError("mintFailedQuote", {
|
|
37485
|
+
host: new URL(mint).host,
|
|
37486
|
+
reason: mintReason(error)
|
|
37487
|
+
}), { cause: error }) : error;
|
|
36540
37488
|
}
|
|
36541
37489
|
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
36542
37490
|
}
|
|
@@ -36591,7 +37539,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36591
37539
|
outputs: preview.outputData.map((o) => OutputData.serialize(o)),
|
|
36592
37540
|
note: note?.slice(0, 140),
|
|
36593
37541
|
paymentId,
|
|
36594
|
-
createdAt:
|
|
37542
|
+
createdAt: this.stamp()
|
|
36595
37543
|
};
|
|
36596
37544
|
await this.sealedTransact([
|
|
36597
37545
|
STORES$1.proofs,
|
|
@@ -36663,7 +37611,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36663
37611
|
this.events.onChange();
|
|
36664
37612
|
}
|
|
36665
37613
|
} catch {}
|
|
36666
|
-
this.meltAsk.missed(melt.quote, Date.now(),
|
|
37614
|
+
this.meltAsk.missed(melt.quote, Date.now(), !this.meltOverdue(melt));
|
|
36667
37615
|
}
|
|
36668
37616
|
const remaining = new Set((await this.readMelts()).map((m) => m.quote));
|
|
36669
37617
|
this.meltAsk.keepOnly(remaining);
|
|
@@ -36697,7 +37645,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36697
37645
|
return "paid";
|
|
36698
37646
|
}
|
|
36699
37647
|
if (quote.state === "PENDING") return "pending";
|
|
36700
|
-
if (!answered &&
|
|
37648
|
+
if (!answered && !this.meltOverdue(melt)) return "pending";
|
|
36701
37649
|
const inputs = await this.reservedProofs(melt);
|
|
36702
37650
|
const states = inputs.length > 0 ? await wallet.checkProofsStates(inputs) : [];
|
|
36703
37651
|
if (states.some((s) => s.state === "PENDING")) return "pending";
|
|
@@ -36805,14 +37753,17 @@ var CashuWallet = class CashuWallet {
|
|
|
36805
37753
|
}
|
|
36806
37754
|
return out;
|
|
36807
37755
|
}
|
|
37756
|
+
/** Whether the payment poll's reads at this mint may ask it now: its last load did not fail, or its next try came. */
|
|
37757
|
+
mintDue(mint, now) {
|
|
37758
|
+
return !this.failedLoads.has(mint) || this.mintAsk.due(mint, now);
|
|
37759
|
+
}
|
|
36808
37760
|
/**
|
|
36809
37761
|
* A mint's loaded wallet. A failed load is tried again by the next caller, unless that one takes `recentFailure`
|
|
36810
|
-
* (a payment's reads in the poll): a
|
|
37762
|
+
* (a payment's reads in the poll): a failed load is its answer too until the mint's next try (`mintAsk`).
|
|
36811
37763
|
*/
|
|
36812
37764
|
wallet(mint, recentFailure = false) {
|
|
36813
|
-
const failed = this.failedLoads.get(mint);
|
|
36814
37765
|
let wallet = this.wallets.get(mint);
|
|
36815
|
-
if (
|
|
37766
|
+
if (this.failedLoads.has(mint) && !(recentFailure && !this.mintAsk.due(mint, Date.now()))) wallet = void 0;
|
|
36816
37767
|
if (!wallet) {
|
|
36817
37768
|
const loading = (async () => {
|
|
36818
37769
|
const instance = new (await (loadCashu())).Wallet(mint, { unit: UNIT$1 });
|
|
@@ -36824,8 +37775,10 @@ var CashuWallet = class CashuWallet {
|
|
|
36824
37775
|
wallet = loading;
|
|
36825
37776
|
this.failedLoads.delete(mint);
|
|
36826
37777
|
this.wallets.set(mint, loading);
|
|
36827
|
-
loading.
|
|
36828
|
-
if (this.wallets.get(mint)
|
|
37778
|
+
loading.then(() => this.mintAsk.forget(mint), () => {
|
|
37779
|
+
if (this.wallets.get(mint) !== loading) return;
|
|
37780
|
+
this.failedLoads.add(mint);
|
|
37781
|
+
this.mintAsk.missed(mint, Date.now());
|
|
36829
37782
|
});
|
|
36830
37783
|
}
|
|
36831
37784
|
return wallet;
|
|
@@ -36961,11 +37914,13 @@ var NoEcashError = class extends Error {
|
|
|
36961
37914
|
var arkSats = (network) => network === "bitcoin" ? "sats" : "test sats";
|
|
36962
37915
|
/** The English line kept with a payment message (the CLI and older apps show it): test sats say so. */
|
|
36963
37916
|
var satsOn = (network) => network === "testnet" ? "test sats" : "sats";
|
|
37917
|
+
/** An amount in that line, "21,000" whatever digits the device's own language writes numbers with. */
|
|
37918
|
+
var englishAmount = (amount) => amount.toLocaleString("en-US");
|
|
36964
37919
|
/** The sender's chat line of ecash sent in a chat, from its record: one id, whether written as it goes or on a later start. */
|
|
36965
37920
|
var ecashLine = (payment) => ({
|
|
36966
37921
|
linkId: payment.linkId,
|
|
36967
37922
|
id: `me_${payment.createdAt}`,
|
|
36968
|
-
text: `⚡ ${payment.amount
|
|
37923
|
+
text: `⚡ ${englishAmount(payment.amount)} ${satsOn(paymentNetwork(payment))}`,
|
|
36969
37924
|
sender: "me",
|
|
36970
37925
|
timestamp: payment.createdAt,
|
|
36971
37926
|
via: "datalink",
|
|
@@ -37148,6 +38103,18 @@ var RAIL_LOOK_MS = 1e4;
|
|
|
37148
38103
|
* ago: otherwise a pace stays shut for as long as the clock went back.
|
|
37149
38104
|
*/
|
|
37150
38105
|
var within = (now, at, ms) => at !== void 0 && at <= now && now - at < ms;
|
|
38106
|
+
/**
|
|
38107
|
+
* How often a wallet's own refresh asks about an open Ark request (at its server's indexer) or a contact's pending Ark
|
|
38108
|
+
* or USDT receipt (at the server or the chain) that has no answer yet (`AskBackoff`): at the wallet's pace while the
|
|
38109
|
+
* request is new (`INVOICE_PACE.fastForMs`) or the transaction is seen confirming, then twice as late after each ask
|
|
38110
|
+
* with nothing, up to `RECEIPT_ASK_CAP_MS`. Asked at every refresh, 5 open Ark requests cost 30 indexer reads a
|
|
38111
|
+
* minute and a receipt whose transaction never lands 3 RPC calls every 8 s, for as long as the app ran.
|
|
38112
|
+
* 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,
|
|
38113
|
+
* so money that lands late, an expired request's included, is still seen.
|
|
38114
|
+
*/
|
|
38115
|
+
var ARK_ASK_MS = 1e4;
|
|
38116
|
+
var USDT_ASK_MS = 8e3;
|
|
38117
|
+
var RECEIPT_ASK_CAP_MS = INVOICE_PACE.missedCapMs;
|
|
37151
38118
|
var PaymentDesk = class {
|
|
37152
38119
|
wallet;
|
|
37153
38120
|
host;
|
|
@@ -37164,6 +38131,10 @@ var PaymentDesk = class {
|
|
|
37164
38131
|
cashuSent = /* @__PURE__ */ new Set();
|
|
37165
38132
|
checkingArk = false;
|
|
37166
38133
|
checkingUsdt = false;
|
|
38134
|
+
/** Open Ark requests (by request id) and pending Ark receipts (by payment id) asked with nothing found yet. */
|
|
38135
|
+
arkAsk = new AskBackoff(ARK_ASK_MS, RECEIPT_ASK_CAP_MS);
|
|
38136
|
+
/** Pending USDT receipts (by payment id) whose transaction the chain does not show settled yet. */
|
|
38137
|
+
usdtAsk = new AskBackoff(USDT_ASK_MS, RECEIPT_ASK_CAP_MS);
|
|
37167
38138
|
checkingBark = false;
|
|
37168
38139
|
checkingBitcoin = false;
|
|
37169
38140
|
redeeming = /* @__PURE__ */ new Map();
|
|
@@ -37424,7 +38395,7 @@ var PaymentDesk = class {
|
|
|
37424
38395
|
await this.host.storeMessage({
|
|
37425
38396
|
linkId: params.linkId,
|
|
37426
38397
|
id: `me_${params.timestamp}`,
|
|
37427
|
-
text: `Requested ${params.amount
|
|
38398
|
+
text: `Requested ${englishAmount(params.amount)} ${test ? "test sats" : "sats"} on Fedimint`,
|
|
37428
38399
|
sender: "me",
|
|
37429
38400
|
timestamp: params.timestamp,
|
|
37430
38401
|
via: "datalink",
|
|
@@ -37554,7 +38525,7 @@ var PaymentDesk = class {
|
|
|
37554
38525
|
await this.host.storeMessage({
|
|
37555
38526
|
linkId: params.linkId,
|
|
37556
38527
|
id: `me_${params.timestamp}`,
|
|
37557
|
-
text: `⚡ Requested ${params.amount
|
|
38528
|
+
text: `⚡ Requested ${englishAmount(params.amount)} ${network === "testnet" ? "test sats" : "sats"}`,
|
|
37558
38529
|
sender: "me",
|
|
37559
38530
|
timestamp: params.timestamp,
|
|
37560
38531
|
via: held ? "hold" : "datalink",
|
|
@@ -37614,7 +38585,7 @@ var PaymentDesk = class {
|
|
|
37614
38585
|
await this.host.storeMessage({
|
|
37615
38586
|
linkId,
|
|
37616
38587
|
id: `me_${params.timestamp}`,
|
|
37617
|
-
text: `⚡ Requested ${params.amount
|
|
38588
|
+
text: `⚡ Requested ${englishAmount(params.amount)} ${satsOn(network)} from the group`,
|
|
37618
38589
|
sender: "me",
|
|
37619
38590
|
timestamp: params.timestamp,
|
|
37620
38591
|
via: "datalink",
|
|
@@ -38113,7 +39084,7 @@ var PaymentDesk = class {
|
|
|
38113
39084
|
await this.host.storeMessage({
|
|
38114
39085
|
linkId,
|
|
38115
39086
|
id: `peer_${request.timestamp}`,
|
|
38116
|
-
text: `⚡ Requested ${amount
|
|
39087
|
+
text: `⚡ Requested ${englishAmount(amount)} ${satsOn(network)}`,
|
|
38117
39088
|
sender: "peer",
|
|
38118
39089
|
timestamp: request.timestamp,
|
|
38119
39090
|
via: held ? "hold" : "datalink",
|
|
@@ -38290,7 +39261,7 @@ var PaymentDesk = class {
|
|
|
38290
39261
|
await this.host.storeMessage({
|
|
38291
39262
|
linkId,
|
|
38292
39263
|
id: `peer_${record.createdAt}`,
|
|
38293
|
-
text: `⚡ ${amount
|
|
39264
|
+
text: `⚡ ${englishAmount(amount)} ${isWorthlessMint(mint) ? "test sats" : "sats"}`,
|
|
38294
39265
|
sender: "peer",
|
|
38295
39266
|
timestamp: record.createdAt,
|
|
38296
39267
|
via: "datalink",
|
|
@@ -38752,19 +39723,30 @@ var PaymentDesk = class {
|
|
|
38752
39723
|
assertTokenUnits(unique);
|
|
38753
39724
|
return unique;
|
|
38754
39725
|
}
|
|
38755
|
-
|
|
39726
|
+
/**
|
|
39727
|
+
* Each pending USDT receipt asked at the chain. `paced` (a wallet refresh that read nothing new): only the receipts
|
|
39728
|
+
* whose turn came (`usdtAsk`); otherwise every one now.
|
|
39729
|
+
*/
|
|
39730
|
+
async reconcileUsdtReceipts(paced = false) {
|
|
38756
39731
|
if (this.checkingUsdt || !this.usdt) return;
|
|
38757
39732
|
this.checkingUsdt = true;
|
|
38758
39733
|
try {
|
|
39734
|
+
const open = /* @__PURE__ */ new Set();
|
|
38759
39735
|
for (const payment of this.payments.values()) {
|
|
38760
39736
|
if (payment.kind !== "payment" || payment.direction !== "in" || payment.state !== "pending" || !payment.txid || payment.target?.method !== "usdt") continue;
|
|
39737
|
+
open.add(payment.id);
|
|
38761
39738
|
const adapter = this.usdt[walletNetworkOf(payment.target.network)].adapter;
|
|
38762
39739
|
if (!adapter) continue;
|
|
39740
|
+
if (paced && !this.usdtAsk.due(payment.id, Date.now())) continue;
|
|
38763
39741
|
const result = await adapter.receipt(payment.txid, {
|
|
38764
39742
|
...payment.target,
|
|
38765
39743
|
amount: payment.amount
|
|
38766
39744
|
}).catch(() => null);
|
|
38767
|
-
if (!result?.settled && !result?.failed)
|
|
39745
|
+
if (!result?.settled && !result?.failed) {
|
|
39746
|
+
this.usdtAsk.missed(payment.id, Date.now(), !!result?.pending);
|
|
39747
|
+
continue;
|
|
39748
|
+
}
|
|
39749
|
+
this.usdtAsk.forget(payment.id);
|
|
38768
39750
|
if (result.settled && this.usdtTxUsed(payment.txid, payment.requestId)) {
|
|
38769
39751
|
await this.save({
|
|
38770
39752
|
...payment,
|
|
@@ -38787,6 +39769,7 @@ var PaymentDesk = class {
|
|
|
38787
39769
|
});
|
|
38788
39770
|
}
|
|
38789
39771
|
}
|
|
39772
|
+
this.usdtAsk.keepOnly(open);
|
|
38790
39773
|
} finally {
|
|
38791
39774
|
this.checkingUsdt = false;
|
|
38792
39775
|
}
|
|
@@ -38961,18 +39944,32 @@ var PaymentDesk = class {
|
|
|
38961
39944
|
/**
|
|
38962
39945
|
* An Ark request is paid when a virtual output of at least the amount reached the address made for it,
|
|
38963
39946
|
* whoever sent it: with the contact's receipt (its txid, verified), or without one, through the indexer.
|
|
39947
|
+
* `paced` (a wallet refresh that read nothing new): only the requests and receipts whose turn came (`arkAsk`);
|
|
39948
|
+
* otherwise every one now.
|
|
38964
39949
|
*/
|
|
38965
|
-
async reconcileArkReceipts() {
|
|
39950
|
+
async reconcileArkReceipts(paced = false) {
|
|
38966
39951
|
if (this.checkingArk || !this.ark || !distinct(this.ark).some((w) => w.adapter)) return;
|
|
38967
39952
|
this.checkingArk = true;
|
|
38968
39953
|
try {
|
|
39954
|
+
const open = /* @__PURE__ */ new Set();
|
|
39955
|
+
const claimers = /* @__PURE__ */ new Map();
|
|
39956
|
+
for (const p of this.payments.values()) if (p.target?.method === "arkade" && p.kind === "request" && p.txid) claimers.set(p.txid, (claimers.get(p.txid) ?? 0) + 1);
|
|
39957
|
+
let claimed = new Set(claimers.keys());
|
|
38969
39958
|
for (const request of [...this.payments.values()]) {
|
|
38970
39959
|
if (request.kind !== "request" || request.direction !== "out" || request.state !== "pending" || request.target?.method !== "arkade") continue;
|
|
39960
|
+
open.add(request.id);
|
|
38971
39961
|
const adapter = this.ark[walletNetworkOf(request.target.network)].adapter;
|
|
38972
39962
|
if (!adapter || request.target.provider !== adapter.config.provider || request.target.network !== adapter.config.network) continue;
|
|
38973
|
-
|
|
38974
|
-
const
|
|
38975
|
-
|
|
39963
|
+
if (paced && !this.arkAsk.due(request.id, Date.now())) continue;
|
|
39964
|
+
const own = request.txid && claimers.get(request.txid) === 1 ? request.txid : void 0;
|
|
39965
|
+
const txid = await adapter.received(request.target.address, request.amount, request.createdAt, own ? new Set([...claimed].filter((t) => t !== own)) : claimed).catch(() => void 0);
|
|
39966
|
+
if (!txid) {
|
|
39967
|
+
this.arkAsk.missed(request.id, Date.now(), Date.now() < request.createdAt + INVOICE_PACE.fastForMs);
|
|
39968
|
+
continue;
|
|
39969
|
+
}
|
|
39970
|
+
this.arkAsk.forget(request.id);
|
|
39971
|
+
claimers.set(txid, (claimers.get(txid) ?? 0) + 1);
|
|
39972
|
+
claimed = /* @__PURE__ */ new Set([...claimed, txid]);
|
|
38976
39973
|
await this.settleRequest(request, { txid });
|
|
38977
39974
|
for (const payment of this.payments.values()) if (payment.kind === "payment" && payment.direction === "in" && payment.requestId === request.id && payment.state === "pending") await this.save({
|
|
38978
39975
|
...payment,
|
|
@@ -38982,9 +39979,15 @@ var PaymentDesk = class {
|
|
|
38982
39979
|
}
|
|
38983
39980
|
for (const payment of this.payments.values()) {
|
|
38984
39981
|
if (payment.kind !== "payment" || payment.direction !== "in" || payment.state !== "pending" || !payment.txid || payment.target?.method !== "arkade") continue;
|
|
39982
|
+
open.add(payment.id);
|
|
38985
39983
|
const adapter = this.ark[walletNetworkOf(payment.target.network)].adapter;
|
|
38986
39984
|
if (!adapter || payment.target.provider !== adapter.config.provider || payment.target.network !== adapter.config.network) continue;
|
|
38987
|
-
if (!
|
|
39985
|
+
if (paced && !this.arkAsk.due(payment.id, Date.now())) continue;
|
|
39986
|
+
if (!await adapter.verifyReceipt(payment.txid, payment.target.address, payment.amount).catch(() => false)) {
|
|
39987
|
+
this.arkAsk.missed(payment.id, Date.now());
|
|
39988
|
+
continue;
|
|
39989
|
+
}
|
|
39990
|
+
this.arkAsk.forget(payment.id);
|
|
38988
39991
|
await this.save({
|
|
38989
39992
|
...payment,
|
|
38990
39993
|
state: "settled"
|
|
@@ -38992,6 +39995,7 @@ var PaymentDesk = class {
|
|
|
38992
39995
|
const request = payment.requestId ? this.payments.get(payment.requestId) : void 0;
|
|
38993
39996
|
if (request?.linkId === payment.linkId && request.state === "pending") await this.settleRequest(request, { txid: payment.txid });
|
|
38994
39997
|
}
|
|
39998
|
+
this.arkAsk.keepOnly(open);
|
|
38995
39999
|
} finally {
|
|
38996
40000
|
this.checkingArk = false;
|
|
38997
40001
|
}
|
|
@@ -39299,7 +40303,7 @@ var PaymentDesk = class {
|
|
|
39299
40303
|
await this.host.storeMessage({
|
|
39300
40304
|
linkId: review.linkId,
|
|
39301
40305
|
id: `me_${review.createdAt}`,
|
|
39302
|
-
text: `${review.amount
|
|
40306
|
+
text: `${englishAmount(review.amount)} ${review.network === "bitcoin" ? "sats" : "test sats"} on Fedimint`,
|
|
39303
40307
|
sender: "me",
|
|
39304
40308
|
timestamp: review.createdAt,
|
|
39305
40309
|
via: "datalink",
|
|
@@ -39504,7 +40508,7 @@ var PaymentDesk = class {
|
|
|
39504
40508
|
await this.host.storeMessage({
|
|
39505
40509
|
linkId: payment.linkId,
|
|
39506
40510
|
id: `peer_${payment.createdAt}`,
|
|
39507
|
-
text: `⚡ ${payment.amount
|
|
40511
|
+
text: `⚡ ${englishAmount(payment.amount)} ${test ? "test sats" : "sats"} on Fedimint`,
|
|
39508
40512
|
sender: "peer",
|
|
39509
40513
|
timestamp: payment.createdAt,
|
|
39510
40514
|
via: "datalink",
|
|
@@ -40411,6 +41415,16 @@ var RTT_SAVE_MS = 3e5;
|
|
|
40411
41415
|
var REACTION_RESEND_MS = 3e4;
|
|
40412
41416
|
/** How long a deleted chat's session stays up once the ends of its moving files are said, so they get there (as a yield's goodbye). */
|
|
40413
41417
|
var FILES_END_MS = 300;
|
|
41418
|
+
/** A link event that only asks something and acts on nothing: a deleted chat's link may still ask it (`whileChat`). */
|
|
41419
|
+
var ASKS_ONLY = /* @__PURE__ */ new Set(["onFileRoom"]);
|
|
41420
|
+
/**
|
|
41421
|
+
* A chat's link events, acted on only while `current` says the link is still the chat's. A deleted chat's link stays
|
|
41422
|
+
* up a moment to say the ends of its files (`removeLink`): what it hears meanwhile (a text, a reaction, a pin, a
|
|
41423
|
+
* payment, a call signal) is not taken. Each handler the chat has stays there, so the link offers what it offered.
|
|
41424
|
+
*/
|
|
41425
|
+
function whileChat(events, current) {
|
|
41426
|
+
return Object.fromEntries(Object.entries(events).map(([name, handler]) => [name, typeof handler !== "function" || ASKS_ONLY.has(name) ? handler : (...args) => current() ? handler(...args) : void 0]));
|
|
41427
|
+
}
|
|
40414
41428
|
/** A chat's reactions shown on the chat list before the one shown now, kept to show again when that one is taken back. */
|
|
40415
41429
|
var REACTION_NOTES_KEPT = 8;
|
|
40416
41430
|
/** When the contact's newest message over the DHT in these was sent (`LiveLink.pkarrSeenAt`). */
|
|
@@ -40600,6 +41614,10 @@ var LIMITED_MODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
40600
41614
|
"setFastPoll",
|
|
40601
41615
|
"exportLinks",
|
|
40602
41616
|
"walletBackupReminder",
|
|
41617
|
+
"setPresence",
|
|
41618
|
+
"setOwnStatus",
|
|
41619
|
+
"clearOwnStatus",
|
|
41620
|
+
"getOwnStatus",
|
|
40603
41621
|
"savedMessages",
|
|
40604
41622
|
"saveMessage",
|
|
40605
41623
|
"deviceRestoreStartOwn"
|
|
@@ -40684,7 +41702,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40684
41702
|
edgeRtcOff = /* @__PURE__ */ new Map();
|
|
40685
41703
|
/** Edges put back on WebRTC by a return (`edgeRtcPresence`) since the network last changed: failing again holds them native. */
|
|
40686
41704
|
edgeRtcRetried = /* @__PURE__ */ new Set();
|
|
40687
|
-
pollIntervals
|
|
41705
|
+
/** The pace the app gave (`NodeOptions.pollIntervals`): the Desktop's is the DHT's. */
|
|
41706
|
+
ownPollIntervals;
|
|
40688
41707
|
localFetch;
|
|
40689
41708
|
links = /* @__PURE__ */ new Map();
|
|
40690
41709
|
services = [];
|
|
@@ -40724,6 +41743,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40724
41743
|
walletFeedbackIds = /* @__PURE__ */ new Set();
|
|
40725
41744
|
/** `cue`: a finer sound the page plays instead of the event's own when its category is on (apps/ui/src/lib/cues.ts). */
|
|
40726
41745
|
feedback(type, id, linkId, mention = false, cue) {
|
|
41746
|
+
if ((type === "message" || type === "reaction") && this.doNotDisturb) return;
|
|
40727
41747
|
const key = type + ":" + id;
|
|
40728
41748
|
if (this.feedbackIds.has(key)) return;
|
|
40729
41749
|
this.feedbackIds.add(key);
|
|
@@ -40743,6 +41763,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40743
41763
|
}
|
|
40744
41764
|
/** The newest time written in each chat while this engine runs: a message written well before it is a catch-up. */
|
|
40745
41765
|
newestAt = /* @__PURE__ */ new Map();
|
|
41766
|
+
/**
|
|
41767
|
+
* The chats deleted while this engine runs (`removeLink`), with how many times each was: a row that comes for one
|
|
41768
|
+
* later is not stored, nor one whose store was under way as it was deleted (`storeNewMessage`), the same invite
|
|
41769
|
+
* joined again meanwhile or not.
|
|
41770
|
+
*/
|
|
41771
|
+
removedChats = /* @__PURE__ */ new Map();
|
|
40746
41772
|
/** The chats whose contact's joined line came while this engine runs (`firstContactRow`), whatever `stored` says. */
|
|
40747
41773
|
contactSpoke = /* @__PURE__ */ new WeakSet();
|
|
40748
41774
|
/** Per group: when the last message written well before it came, came. What comes after it, as old, is its catch-up. */
|
|
@@ -40825,6 +41851,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40825
41851
|
cardPresses = /* @__PURE__ */ new Map();
|
|
40826
41852
|
/** At most one wake-up per contact per `WAKE_INTERVAL_MS` (WISP 401 § Wake-up push). */
|
|
40827
41853
|
wakeLimiter = new WakeLimiter();
|
|
41854
|
+
/** The push relay's last answer that was not a push service's status, until it forwards one (`EngineState.pushRelayRefused`). */
|
|
41855
|
+
pushRelayRefusal;
|
|
40828
41856
|
/** Call wake-ups have their own, shorter limit: a call is rarer than a message and cannot wait five minutes. */
|
|
40829
41857
|
callWakeLimiter = new WakeLimiter(WAKE_CALL_INTERVAL_MS);
|
|
40830
41858
|
/** Mentions in private groups: one per member per 5 minutes, four per group per minute (WISP 902 · Group Mesh § Wake-up push). */
|
|
@@ -40929,11 +41957,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40929
41957
|
*/
|
|
40930
41958
|
usdtWallets = perNetwork((network) => new UsdtWallet(network, (viewChanged = true) => {
|
|
40931
41959
|
if (viewChanged) this.walletChanged();
|
|
40932
|
-
this.desk.reconcileUsdtReceipts().catch(() => {});
|
|
41960
|
+
this.desk.reconcileUsdtReceipts(!viewChanged).catch(() => {});
|
|
40933
41961
|
}));
|
|
40934
41962
|
arkWallets = perNetwork((network) => new ArkWallet(network, (viewChanged = true) => {
|
|
40935
41963
|
if (viewChanged) this.walletChanged();
|
|
40936
|
-
this.desk.reconcileArkReceipts().catch(() => {});
|
|
41964
|
+
this.desk.reconcileArkReceipts(!viewChanged).catch(() => {});
|
|
40937
41965
|
}));
|
|
40938
41966
|
barkWallets = perNetwork((network) => new BarkWallet(network, (viewChanged = true) => {
|
|
40939
41967
|
if (viewChanged) this.walletChanged();
|
|
@@ -41785,6 +42813,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41785
42813
|
seqFloor: () => this.counterFloor,
|
|
41786
42814
|
adminWork: (groupId) => !this.limitedMode && !this.groupAdminOff.has(groupId),
|
|
41787
42815
|
adminTurn: (_groupId, options) => this.confirmTurn({ within: options?.wait === false ? 0 : GhostlyNode.TURN_CONFIRM_WAIT_MS }),
|
|
42816
|
+
autoJoins: (linkId) => !!this.options.autoJoins?.(linkId),
|
|
41788
42817
|
staysOnline: () => this.options.staysOnline ?? (this.options.platform === "desktop" && typeof RTCPeerConnection !== "undefined"),
|
|
41789
42818
|
peerRoom: (groupId) => {
|
|
41790
42819
|
const native = Object.keys(this.nativeFactories);
|
|
@@ -41946,6 +42975,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41946
42975
|
const moved = row ?? (this.groups.movedMarks(groupId, id) ? await db.getMessage(chat, id) : void 0);
|
|
41947
42976
|
await this.groups.removed(groupId, id);
|
|
41948
42977
|
await db.deleteMessage(chat, id);
|
|
42978
|
+
if (id.includes(":me_")) this.awaitingSoon();
|
|
41949
42979
|
if (moved) await this.groups.unmark(groupId, moved);
|
|
41950
42980
|
this.quoteSweeps.add(chat, id, id);
|
|
41951
42981
|
await this.messagesChanged(chat, [id]);
|
|
@@ -42070,26 +43100,40 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42070
43100
|
...options.singleDevice ? { runsHere: async () => true } : {},
|
|
42071
43101
|
readPath: () => readPathOf(this.relays ? { relays: this.relays.describe().relays } : this.settings, !!this.transport.configure)
|
|
42072
43102
|
});
|
|
42073
|
-
this.
|
|
43103
|
+
this.ownPollIntervals = options.pollIntervals ?? RELAY_POLL_INTERVALS;
|
|
42074
43104
|
this.localFetch = options.localFetch ?? webLocalFetch;
|
|
42075
43105
|
this.hold.host.transport = this.transport;
|
|
42076
43106
|
this.transport.subscribe?.(() => this.emitState());
|
|
42077
43107
|
this.clockOff = this.transport.onServerTime?.((time) => this.clock.server(time.source, time.date, time.sent, time.received));
|
|
42078
43108
|
}
|
|
42079
|
-
/**
|
|
43109
|
+
/**
|
|
43110
|
+
* The Desktop reaches the DHT itself: the relays in Settings are written to, and read from only when the person chose
|
|
43111
|
+
* so. With Hide my IP from contacts on, it does not reach the DHT at all: reads and writes go through the relays.
|
|
43112
|
+
*/
|
|
42080
43113
|
configureDirect() {
|
|
42081
43114
|
this.transport.configure?.({
|
|
42082
43115
|
relays: this.settings.relays,
|
|
42083
|
-
readRelays: this.settings.readRelays === true
|
|
43116
|
+
readRelays: this.settings.readRelays === true,
|
|
43117
|
+
dhtDirect: this.settings.relayOnly !== true
|
|
42084
43118
|
});
|
|
42085
43119
|
}
|
|
42086
43120
|
/**
|
|
43121
|
+
* How often links read Pkarr. The Desktop that keeps to the relays (Hide my IP from contacts) reads every packet from
|
|
43122
|
+
* them, background reads too, so it goes at the relays' pace, not the DHT's: at the DHT's, one waiting invite was 45
|
|
43123
|
+
* relay reads a minute, against a browser's 30. Links take it as they start; turning the switch restarts them.
|
|
43124
|
+
*/
|
|
43125
|
+
get pollIntervals() {
|
|
43126
|
+
return this.transport.configure && this.settings.relayOnly === true ? RELAY_POLL_INTERVALS : this.ownPollIntervals;
|
|
43127
|
+
}
|
|
43128
|
+
/**
|
|
42087
43129
|
* What each network's wallets still wait for (see `walletAwaiting`): open requests and invoices, paid invoices not
|
|
42088
43130
|
* claimed yet, ecash sent and not taken. Read from the Cashu quotes, the Lightning journals and the payments.
|
|
42089
43131
|
*/
|
|
42090
43132
|
/** What each network's wallets still wait for, and each mint on its own (`mints`, only the mints that wait for something). */
|
|
42091
43133
|
async readAwaiting() {
|
|
42092
43134
|
const quotes = await this.wallet.quotes(), payments = this.desk.records(), now = Date.now();
|
|
43135
|
+
const lost = this.transfersRestored ? await this.sentWithoutLine(payments) : void 0;
|
|
43136
|
+
const chatGone = lost && ((paymentId) => lost.has(paymentId));
|
|
42093
43137
|
const out = {};
|
|
42094
43138
|
const mints = /* @__PURE__ */ new Map();
|
|
42095
43139
|
for (const network of WALLET_NETWORKS) {
|
|
@@ -42103,7 +43147,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42103
43147
|
lightningCard: lightning.receivingId,
|
|
42104
43148
|
lightningOwner: (op) => lightning.owner(op),
|
|
42105
43149
|
payments,
|
|
42106
|
-
now
|
|
43150
|
+
now,
|
|
43151
|
+
chatGone
|
|
42107
43152
|
});
|
|
42108
43153
|
for (const url of this.networkMints(network)) {
|
|
42109
43154
|
const waits = mintAwaiting(url, {
|
|
@@ -42120,6 +43165,47 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42120
43165
|
mints
|
|
42121
43166
|
};
|
|
42122
43167
|
}
|
|
43168
|
+
/**
|
|
43169
|
+
* The ecash sent and not taken yet whose chat line, the bubble with its Take it back, is in no chat the person can
|
|
43170
|
+
* open (`WalletAwaitingView.chatGone`): its 1:1 chat deleted, or joined again by the same invite (the same id) without
|
|
43171
|
+
* its old history, or its group gone. Asked of the line itself, not of the link it went over: a member's edge closes
|
|
43172
|
+
* when they leave the group, and the line stays in the group's history.
|
|
43173
|
+
*
|
|
43174
|
+
* The line's id is the payment's own (`me_<createdAt>`, as `paymentMessage` reads it first); a member's is filed in
|
|
43175
|
+
* the group under the edge's id (`storeNewMessage`). An edge closed since says no more which group it was: every
|
|
43176
|
+
* group here is asked, one row each. A community's payment link with no member is no chat: never said gone.
|
|
43177
|
+
*/
|
|
43178
|
+
async sentWithoutLine(payments) {
|
|
43179
|
+
const lost = /* @__PURE__ */ new Set();
|
|
43180
|
+
const sent = payments.filter((p) => p.kind === "payment" && p.direction === "out" && p.state === "pending" && p.token);
|
|
43181
|
+
if (!sent.length) return lost;
|
|
43182
|
+
let groups;
|
|
43183
|
+
const everyGroup = () => groups ??= this.groups.views().map((g) => g.id);
|
|
43184
|
+
const groupHere = (groupId) => !!this.groups.view(groupId);
|
|
43185
|
+
const asked = /* @__PURE__ */ new Map();
|
|
43186
|
+
const ask = (chat, id, paymentId) => {
|
|
43187
|
+
const ids = asked.get(chat) ?? /* @__PURE__ */ new Map();
|
|
43188
|
+
asked.set(chat, ids.set(id, [...ids.get(id) ?? [], paymentId]));
|
|
43189
|
+
};
|
|
43190
|
+
for (const p of sent) {
|
|
43191
|
+
const line = `me_${p.createdAt}`, stored = this.links.get(p.linkId)?.stored, pay = parsePayLink(p.linkId);
|
|
43192
|
+
if (pay && !pay.member) continue;
|
|
43193
|
+
lost.add(p.id);
|
|
43194
|
+
if (stored && !stored.group) ask(p.linkId, line, p.id);
|
|
43195
|
+
else if (stored?.group && stored.groupPeer && !stored.groupEntry) {
|
|
43196
|
+
if (groupHere(stored.group)) ask(`group:${stored.group}`, `${p.linkId}:${line}`, p.id);
|
|
43197
|
+
} else if (pay) {
|
|
43198
|
+
if (groupHere(pay.groupId)) ask(`group:${pay.groupId}`, `${p.linkId}:${line}`, p.id);
|
|
43199
|
+
} else if (!stored) for (const groupId of everyGroup()) ask(`group:${groupId}`, `${p.linkId}:${line}`, p.id);
|
|
43200
|
+
}
|
|
43201
|
+
for (const [chat, ids] of asked) {
|
|
43202
|
+
const keys = [...ids.keys()];
|
|
43203
|
+
(await db.getMessagesById(chat, keys)).forEach((row, i) => {
|
|
43204
|
+
for (const paymentId of ids.get(keys[i])) if (row?.sender === "me" && row.paymentId === paymentId) lost.delete(paymentId);
|
|
43205
|
+
});
|
|
43206
|
+
}
|
|
43207
|
+
return lost;
|
|
43208
|
+
}
|
|
42123
43209
|
/** A mint as the wallet page shows it, with what it still waits for when it does (asked about before it is removed). */
|
|
42124
43210
|
withWaits(mints, waits) {
|
|
42125
43211
|
return mints.map(({ awaiting: _, ...mint }) => waits.has(mint.url) ? {
|
|
@@ -42301,12 +43387,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42301
43387
|
continue;
|
|
42302
43388
|
}
|
|
42303
43389
|
const network = walletNetworkOf(review.network);
|
|
43390
|
+
const prepared = saved.prepared;
|
|
43391
|
+
if (review.method === "cashu" && !prepared.abandoned && !prepared.spentElsewhere && !this.wallet.mintDue(prepared.mint, Date.now())) continue;
|
|
42304
43392
|
if (review.method === "arkade" && !this.arkWallets[network].adapter || review.method === "bark" && !this.barkWallets[network].adapter || review.method === "spark" && !this.sparkWallets[network].adapter || review.method === "usdt" && !this.usdtWallets[network].adapter || review.method === "bitcoin" && !this.bitcoins[network].sources.active || review.method === "fedimint" && !this.fedimintWallets[network].federation(review.provider)) continue;
|
|
42305
43393
|
const after = await this.reconcilePayment({ id: review.id }).catch(() => review);
|
|
42306
|
-
if (review.method === "cashu" && ["submitted", "unknown"].includes(after.state))
|
|
42307
|
-
const prepared = saved.prepared;
|
|
42308
|
-
this.cashuPayAsk.missed(id, Date.now(), Date.now() < (prepared.token ? (review.submittedAt ?? review.createdAt) + 6e4 : swapSettledAt(review, prepared)));
|
|
42309
|
-
}
|
|
43394
|
+
if (review.method === "cashu" && ["submitted", "unknown"].includes(after.state)) this.cashuPayAsk.missed(id, Date.now(), Date.now() < (prepared.token ? (review.submittedAt ?? review.createdAt) + 6e4 : swapSettledAt(review, prepared)));
|
|
42310
43395
|
}
|
|
42311
43396
|
} finally {
|
|
42312
43397
|
if (!this.shuttingDown) this.paymentTimer = setTimeout(() => void this.pollPaymentStatus(), 1e4);
|
|
@@ -42331,6 +43416,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42331
43416
|
...DEFAULT_SETTINGS,
|
|
42332
43417
|
...stored
|
|
42333
43418
|
};
|
|
43419
|
+
this.armOwnStatusEnd();
|
|
42334
43420
|
this.settings.relays = currentRelays(this.settings.relays);
|
|
42335
43421
|
this.relays?.setRelays(this.settings.relays);
|
|
42336
43422
|
this.configureDirect();
|
|
@@ -42386,6 +43472,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42386
43472
|
if (stored.profile) await this.outboxFor(stored.id).recover(messages);
|
|
42387
43473
|
}
|
|
42388
43474
|
this.transfersRestored = true;
|
|
43475
|
+
this.awaitingSoon();
|
|
42389
43476
|
this.publicProfiles.start();
|
|
42390
43477
|
await this.startLinks(links.map((stored) => stored.id), (linkId) => {
|
|
42391
43478
|
if (!this.links.get(linkId)?.stored.group) this.refreshPublicProfiles({ linkId }).catch(() => {});
|
|
@@ -42396,6 +43483,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42396
43483
|
this.hold.start();
|
|
42397
43484
|
this.startGroupEntries();
|
|
42398
43485
|
this.prepareSpare(STARTUP_QUIET_MS);
|
|
43486
|
+
this.announceOnline();
|
|
42399
43487
|
}
|
|
42400
43488
|
if (!this.limitedMode) this.openStartedWallets(fresh);
|
|
42401
43489
|
if (this.appsOn && !this.appsWireOnly) this.appStore.start().catch(() => {});
|
|
@@ -42644,6 +43732,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42644
43732
|
this.hold.start();
|
|
42645
43733
|
this.startGroupEntries();
|
|
42646
43734
|
this.prepareSpare(STARTUP_QUIET_MS);
|
|
43735
|
+
this.announceOnline();
|
|
42647
43736
|
this.did.publishNow().catch(() => {});
|
|
42648
43737
|
this.identities.networkBack();
|
|
42649
43738
|
}
|
|
@@ -42820,6 +43909,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42820
43909
|
clearTimeout(this.limitedTimer);
|
|
42821
43910
|
this.limitedTimer = null;
|
|
42822
43911
|
}
|
|
43912
|
+
clearTimeout(this.onlineTimer);
|
|
42823
43913
|
this.appShelf?.stop();
|
|
42824
43914
|
if (!quiet) this.depart({ quitting: options.quitting === true });
|
|
42825
43915
|
const linksStopped = Promise.allSettled([...this.links.values()].map(async (live) => {
|
|
@@ -42842,6 +43932,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42842
43932
|
this.reactionTimers.clear();
|
|
42843
43933
|
for (const timer of this.pinTimers.values()) clearTimeout(timer);
|
|
42844
43934
|
this.pinTimers.clear();
|
|
43935
|
+
for (const timer of [
|
|
43936
|
+
this.idleTimer,
|
|
43937
|
+
this.ownStatusTimer,
|
|
43938
|
+
...this.peerStatusTimers.values()
|
|
43939
|
+
]) clearTimeout(timer);
|
|
43940
|
+
this.peerStatusTimers.clear();
|
|
42845
43941
|
this.stopGroupEntries();
|
|
42846
43942
|
this.stopWatchingAdapters?.();
|
|
42847
43943
|
this.enrollment?.cancel().catch(() => {});
|
|
@@ -43002,6 +44098,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43002
44098
|
...this.limitedMode && this.restoreCheck && { restoreCheck: this.restoreCheck },
|
|
43003
44099
|
...this.limitedMode && this.startChecking && { startCheck: true },
|
|
43004
44100
|
...wakeOwnerOf(this.settings.wake, this.ownDeviceKey) && { wakeOwner: wakeOwnerOf(this.settings.wake, this.ownDeviceKey) },
|
|
44101
|
+
...this.pushRelayRefusal && this.pushRelayRefusal.url === this.settings.pushRelay && { pushRelayRefused: this.pushRelayRefusal },
|
|
43005
44102
|
transport: {
|
|
43006
44103
|
...this.transport.describe(),
|
|
43007
44104
|
...this.options.irohWeb || this.ownIrohRelays ? { iroh: {
|
|
@@ -43108,6 +44205,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43108
44205
|
async getMessages(linkId) {
|
|
43109
44206
|
return (await db.getMessages(linkId)).map(withoutFrame);
|
|
43110
44207
|
}
|
|
44208
|
+
/** A chat's or a group's (`group:<id>`) messages that carry a file, by time: read without the rest of its history. */
|
|
44209
|
+
async fileMessages(linkId) {
|
|
44210
|
+
return (await db.getFileMessages(linkId)).map(withoutFrame);
|
|
44211
|
+
}
|
|
43111
44212
|
/**
|
|
43112
44213
|
* The 1:1 chats among `linkIds` with a message whose text holds `query`, whatever the case and the accents: the chat
|
|
43113
44214
|
* list's search, read here so a page that holds each chat's newest page only is not sent every whole history for it.
|
|
@@ -43757,11 +44858,72 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43757
44858
|
await db.patchLink(linkId, { wakeToken: token });
|
|
43758
44859
|
this.emitState();
|
|
43759
44860
|
}
|
|
44861
|
+
const online = this.settings.wakeOnline !== false && wakeOwnerOf(own, this.ownDeviceKey) !== "away";
|
|
43760
44862
|
live.link.sendWake({
|
|
43761
44863
|
...own,
|
|
43762
|
-
token
|
|
44864
|
+
token,
|
|
44865
|
+
...online && { online: true }
|
|
43763
44866
|
});
|
|
43764
44867
|
}
|
|
44868
|
+
/**
|
|
44869
|
+
* Whether paired contacts are asked for an online notice (Settings → Notifications, on by default). Each live one is
|
|
44870
|
+
* told again now; one away hears it on its next session, and until then may still send one, which shows.
|
|
44871
|
+
*/
|
|
44872
|
+
async setWakeOnline({ on }) {
|
|
44873
|
+
if (this.settings.wakeOnline !== false === on) return;
|
|
44874
|
+
this.settings = {
|
|
44875
|
+
...this.settings,
|
|
44876
|
+
wakeOnline: false
|
|
44877
|
+
};
|
|
44878
|
+
if (on) delete this.settings.wakeOnline;
|
|
44879
|
+
await db.putSettings(this.settings);
|
|
44880
|
+
for (const live of this.links.values()) if (live.stored.profile && !live.stored.group) await this.shareWake(live.stored.id);
|
|
44881
|
+
this.emitState();
|
|
44882
|
+
}
|
|
44883
|
+
onlineTimer;
|
|
44884
|
+
/**
|
|
44885
|
+
* This app came online (it started, or its network came back): once the chats had `WAKE_ONLINE_DELAY_MS` to go live,
|
|
44886
|
+
* the contacts still away that asked are told (`sayOnline`). A contact whose app is open goes live and is not pushed.
|
|
44887
|
+
*/
|
|
44888
|
+
announceOnline() {
|
|
44889
|
+
clearTimeout(this.onlineTimer);
|
|
44890
|
+
this.onlineTimer = setTimeout(() => {
|
|
44891
|
+
this.onlineTimer = void 0;
|
|
44892
|
+
this.sayOnline();
|
|
44893
|
+
}, WAKE_ONLINE_DELAY_MS);
|
|
44894
|
+
}
|
|
44895
|
+
/**
|
|
44896
|
+
* An online wake-up (WISP 401 § Wake-up push, revision 2026-10-27) to each paired contact that asked for one, whose
|
|
44897
|
+
* chat is not live: at most one per contact per `WAKE_ONLINE_INTERVAL_MS`, counted across restarts, since a restart is
|
|
44898
|
+
* what says it. Apart from the message wake-ups' limit, so it never holds one back. A muted chat's contact shared no
|
|
44899
|
+
* target; a group's edge is never told. `WAKE_ONLINE_BATCH` at a time, the rest a `WAKE_ONLINE_BATCH_MS` later (those
|
|
44900
|
+
* still away then), so a push relay's minute keeps room for the message and call wake-ups. None while this profile does
|
|
44901
|
+
* not share when it is online (`sharePresence`).
|
|
44902
|
+
*/
|
|
44903
|
+
sayOnline(now = Date.now()) {
|
|
44904
|
+
if (!this.networkOn || this.shuttingDown || this.settings.sharePresence === false) return;
|
|
44905
|
+
let sent = 0;
|
|
44906
|
+
for (const live of this.links.values()) {
|
|
44907
|
+
const { id, peerWake: target, profile, group, onlineWokeAt } = live.stored;
|
|
44908
|
+
if (!target?.online || !profile || group || live.link?.isDataLinkOpen) continue;
|
|
44909
|
+
if (onlineWokeAt !== void 0 && onlineWokeAt <= now && now - onlineWokeAt < 18e5) continue;
|
|
44910
|
+
if (sent === 10) {
|
|
44911
|
+
clearTimeout(this.onlineTimer);
|
|
44912
|
+
this.onlineTimer = setTimeout(() => {
|
|
44913
|
+
this.onlineTimer = void 0;
|
|
44914
|
+
this.sayOnline();
|
|
44915
|
+
}, WAKE_ONLINE_BATCH_MS);
|
|
44916
|
+
return;
|
|
44917
|
+
}
|
|
44918
|
+
sent += 1;
|
|
44919
|
+
live.stored = {
|
|
44920
|
+
...live.stored,
|
|
44921
|
+
onlineWokeAt: now
|
|
44922
|
+
};
|
|
44923
|
+
db.patchLink(id, { onlineWokeAt: now });
|
|
44924
|
+
this.postWake(id, target, "online");
|
|
44925
|
+
}
|
|
44926
|
+
}
|
|
43765
44927
|
/** An edge of a private group: where a member shares how to wake it. A community has none between two members. */
|
|
43766
44928
|
meshEdge(stored) {
|
|
43767
44929
|
return !!stored.group && !!stored.groupPeer && !stored.groupEntry && !this.groups.isCommunityGroup(stored.group);
|
|
@@ -43796,6 +44958,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43796
44958
|
this.reactionNotesBefore.delete(linkId);
|
|
43797
44959
|
this.reactionNotesWhole.delete(linkId);
|
|
43798
44960
|
this.events.onMessages(linkId, []);
|
|
44961
|
+
this.awaitingSoon();
|
|
43799
44962
|
}
|
|
43800
44963
|
async setGroupWakeMuted(groupId, muted) {
|
|
43801
44964
|
const list = this.settings.wakeMutedGroups ?? [];
|
|
@@ -43895,11 +45058,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43895
45058
|
wakePeer(live, kind = "message") {
|
|
43896
45059
|
const target = live.stored.peerWake, linkId = live.stored.id;
|
|
43897
45060
|
if (!target || !live.stored.profile || live.stored.group || !this.networkOn) return;
|
|
43898
|
-
|
|
43899
|
-
|
|
45061
|
+
const limiter = kind === "call" ? this.callWakeLimiter : this.wakeLimiter, takenAt = Date.now();
|
|
45062
|
+
if (!limiter.take(linkId, takenAt)) return;
|
|
45063
|
+
this.postWake(linkId, target, kind, () => limiter.missed(linkId, takenAt));
|
|
43900
45064
|
}
|
|
43901
|
-
/**
|
|
43902
|
-
|
|
45065
|
+
/**
|
|
45066
|
+
* Posts one wake-up to the target a link holds; a subscription gone (404, 410) is forgotten. `missed`: it did not
|
|
45067
|
+
* reach the push service (no network, the relay did not forward it, or the service answered 429 or 5xx).
|
|
45068
|
+
*/
|
|
45069
|
+
postWake(linkId, target, kind, missed) {
|
|
43903
45070
|
let request;
|
|
43904
45071
|
try {
|
|
43905
45072
|
request = wakeRequest(target, Date.now(), kind);
|
|
@@ -43907,6 +45074,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43907
45074
|
return;
|
|
43908
45075
|
}
|
|
43909
45076
|
this.postPush(request).then((status) => {
|
|
45077
|
+
if (status === 429 || status >= 500) missed?.();
|
|
43910
45078
|
if ((status === 404 || status === 410) && this.links.get(linkId)?.stored.peerWake?.endpoint === target.endpoint) {
|
|
43911
45079
|
const current = this.links.get(linkId);
|
|
43912
45080
|
current.stored = {
|
|
@@ -43916,7 +45084,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43916
45084
|
db.patchLink(linkId, { peerWake: void 0 });
|
|
43917
45085
|
this.emitState();
|
|
43918
45086
|
}
|
|
43919
|
-
}).catch(() => {
|
|
45087
|
+
}).catch(() => {
|
|
45088
|
+
missed?.();
|
|
45089
|
+
});
|
|
43920
45090
|
}
|
|
43921
45091
|
/**
|
|
43922
45092
|
* A call to a contact whose app is closed (WISP 401 § Wake-up push, calls): one "call" wake-up, so its app shows
|
|
@@ -43930,12 +45100,36 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43930
45100
|
live.link?.session.pollNow();
|
|
43931
45101
|
return true;
|
|
43932
45102
|
}
|
|
43933
|
-
/**
|
|
43934
|
-
|
|
43935
|
-
|
|
43936
|
-
|
|
43937
|
-
|
|
43938
|
-
|
|
45103
|
+
/**
|
|
45104
|
+
* Posts a wake-up: the host's way, or `fetch`, then the push relay when a page may not post it itself. A relay that
|
|
45105
|
+
* answers but not as a push relay is kept for the pages (`EngineState.pushRelayRefused`) until it forwards one; a
|
|
45106
|
+
* relay that cannot be reached at all (offline, timed out) is not, as a page cannot tell that from being offline.
|
|
45107
|
+
*/
|
|
45108
|
+
async postPush(request) {
|
|
45109
|
+
const relay = this.settings.pushRelay;
|
|
45110
|
+
try {
|
|
45111
|
+
return await postPush(request, {
|
|
45112
|
+
pushSend: this.options.pushSend,
|
|
45113
|
+
relay,
|
|
45114
|
+
relayed: () => {
|
|
45115
|
+
if (this.pushRelayRefusal?.url === relay) {
|
|
45116
|
+
this.pushRelayRefusal = void 0;
|
|
45117
|
+
this.emitState();
|
|
45118
|
+
}
|
|
45119
|
+
}
|
|
45120
|
+
});
|
|
45121
|
+
} catch (error) {
|
|
45122
|
+
if (error instanceof PushRelayRefusal && relay) {
|
|
45123
|
+
this.pushRelayRefusal = {
|
|
45124
|
+
url: relay,
|
|
45125
|
+
at: Date.now(),
|
|
45126
|
+
http: error.http,
|
|
45127
|
+
...error.text !== void 0 && { text: error.text }
|
|
45128
|
+
};
|
|
45129
|
+
this.emitState();
|
|
45130
|
+
}
|
|
45131
|
+
throw error;
|
|
45132
|
+
}
|
|
43939
45133
|
}
|
|
43940
45134
|
removeLink({ linkId }) {
|
|
43941
45135
|
const live = this.links.get(linkId);
|
|
@@ -43951,6 +45145,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43951
45145
|
live.carried?.stop();
|
|
43952
45146
|
const filesEnded = this.fileDesk.drop(linkId);
|
|
43953
45147
|
this.links.delete(linkId);
|
|
45148
|
+
this.removedChats.set(linkId, (this.removedChats.get(linkId) ?? 0) + 1);
|
|
45149
|
+
this.newestAt.delete(linkId);
|
|
45150
|
+
this.clockLeads.delete(linkId);
|
|
45151
|
+
this.placedAt.delete(linkId);
|
|
45152
|
+
this.reactionNotes.delete(linkId);
|
|
45153
|
+
this.reactionNotesBefore.delete(linkId);
|
|
45154
|
+
this.reactionNotesWhole.delete(linkId);
|
|
43954
45155
|
if (filesEnded) setTimeout(() => void live.link?.stop(true), FILES_END_MS);
|
|
43955
45156
|
else live.link?.stop(true);
|
|
43956
45157
|
live.caps?.stop();
|
|
@@ -43963,6 +45164,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43963
45164
|
if (live.stored.wakeToken) this.rotateWake().then(() => this.emitState());
|
|
43964
45165
|
db.deleteLink(linkId);
|
|
43965
45166
|
this.desk.forgetLink(linkId);
|
|
45167
|
+
this.awaitingSoon();
|
|
43966
45168
|
this.emitState();
|
|
43967
45169
|
}
|
|
43968
45170
|
renameLink({ linkId, label }) {
|
|
@@ -44289,12 +45491,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44289
45491
|
const reply = message.replyTo;
|
|
44290
45492
|
if (!reply || reply.messageId) return message;
|
|
44291
45493
|
const group = message.linkId.startsWith("group:");
|
|
45494
|
+
const gone = () => !group && !this.links.has(message.linkId) && this.removedChats.has(message.linkId);
|
|
45495
|
+
if (gone()) return message;
|
|
44292
45496
|
let original, history;
|
|
44293
45497
|
for (const rowId of group ? [reply.id] : [
|
|
44294
45498
|
`peer_${reply.id}`,
|
|
44295
45499
|
`me_${reply.id}`,
|
|
44296
45500
|
...await this.rowsNamed(message.linkId, reply.id)
|
|
44297
45501
|
]) {
|
|
45502
|
+
if (gone()) return message;
|
|
44298
45503
|
const row = rowId === message.id ? void 0 : await db.getMessage(message.linkId, rowId);
|
|
44299
45504
|
if (row && replyRef(row, group) === reply.id) {
|
|
44300
45505
|
original = row;
|
|
@@ -44326,7 +45531,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44326
45531
|
const id = (await this.unkeyedRowsOf(this.links.get(message.linkId))).get(reply.id);
|
|
44327
45532
|
const row = id === void 0 || id === message.id ? void 0 : await db.getMessage(message.linkId, id);
|
|
44328
45533
|
if (row && replyRef(row) === reply.id) original = row;
|
|
44329
|
-
} else if (!original && !group) {
|
|
45534
|
+
} else if (!original && !group && !gone()) {
|
|
44330
45535
|
history = await db.getMessages(message.linkId);
|
|
44331
45536
|
original = history.find((m) => m.id !== message.id && replyRef(m) === reply.id);
|
|
44332
45537
|
}
|
|
@@ -45113,15 +46318,17 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45113
46318
|
this.emitState();
|
|
45114
46319
|
}
|
|
45115
46320
|
}
|
|
46321
|
+
/** `everyone`: whether it is deleted for everyone, a waiting text the outbox already handed to the link; else only here. */
|
|
45116
46322
|
deleteMessage({ linkId, messageId }) {
|
|
45117
46323
|
if (this.outboxes.get(linkId)?.cancel(messageId)) {
|
|
45118
46324
|
this.removeMessage({
|
|
45119
46325
|
linkId,
|
|
45120
46326
|
messageId
|
|
45121
46327
|
}).then(({ refused }) => refused ? this.forgetMessage(linkId, messageId) : void 0).catch(() => {});
|
|
45122
|
-
return;
|
|
46328
|
+
return { everyone: true };
|
|
45123
46329
|
}
|
|
45124
46330
|
this.forgetMessage(linkId, messageId);
|
|
46331
|
+
return { everyone: false };
|
|
45125
46332
|
}
|
|
45126
46333
|
/**
|
|
45127
46334
|
* Deletes a message of mine for everyone (WISP 400 § Delete for everyone): it goes from this device at once, as a delete
|
|
@@ -45274,6 +46481,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45274
46481
|
this.transfers.delete(message.file.id);
|
|
45275
46482
|
}
|
|
45276
46483
|
await db.deleteMessage(linkId, messageId);
|
|
46484
|
+
if (message?.sender === "me" && message.paymentId) this.awaitingSoon();
|
|
45277
46485
|
live.lastMessageAt = (await db.getMessagePage(linkId, { limit: 1 })).messages[0]?.timestamp ?? 0;
|
|
45278
46486
|
if (removed) this.quoteSweeps.add(linkId, messageId, replyRef(message ?? {
|
|
45279
46487
|
id: messageId,
|
|
@@ -45984,19 +47192,20 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45984
47192
|
* `chosen`: a choice from the chat's Connection menu, a row in its timeline even when it names the transport already
|
|
45985
47193
|
* set. Left out (the RPC), only a change of transport is: the Fallback switch sends the same preference again, and
|
|
45986
47194
|
* is neither a row nor a switch intent. On Automatic it sends back the transport Automatic names: only the fallback
|
|
45987
|
-
* changes, and the chat stays on Automatic.
|
|
47195
|
+
* changes (and with it what Automatic names), and the chat stays on Automatic.
|
|
45988
47196
|
*/
|
|
45989
47197
|
async setTransportPreference({ linkId, preferred, fallback }, chosen) {
|
|
45990
47198
|
const live = this.links.get(linkId);
|
|
45991
47199
|
if (!live?.stored.profile || !live.link?.availableTransports.includes(preferred) || typeof fallback !== "boolean") throw new Error("Transport unavailable");
|
|
45992
|
-
|
|
47200
|
+
const available = live.link.availableTransports;
|
|
47201
|
+
if (chosen === void 0 && live.stored.preferredTransport === void 0 && [true, false].some((f) => preferred === automaticTransport(available, f))) {
|
|
45993
47202
|
await db.patchLink(linkId, { transportFallback: fallback });
|
|
45994
47203
|
live.stored = {
|
|
45995
47204
|
...live.stored,
|
|
45996
47205
|
transportFallback: fallback
|
|
45997
47206
|
};
|
|
45998
47207
|
this.emitState();
|
|
45999
|
-
await live.link.setTransportPreference(
|
|
47208
|
+
await live.link.setTransportPreference(automaticTransport(available, fallback), fallback, true, false);
|
|
46000
47209
|
this.capsChanged(linkId);
|
|
46001
47210
|
return;
|
|
46002
47211
|
}
|
|
@@ -46408,7 +47617,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46408
47617
|
if (targets.length > 5) throw new Error(`Forward to at most 5 chats at once`);
|
|
46409
47618
|
if (linkId.startsWith("group:") ? !this.groups.view(linkId.slice(6)) : this.links.get(linkId)?.stored.group !== void 0 || !this.links.has(linkId)) throw new Error("Chat not found");
|
|
46410
47619
|
const chosen = await Promise.all(ids.map((id) => db.getMessage(linkId, id)));
|
|
46411
|
-
if (chosen.some((m) => !m)) throw new Error(
|
|
47620
|
+
if (chosen.some((m) => !m)) throw new Error(FORWARD_MESSAGE_GONE);
|
|
46412
47621
|
const messages = chosen.sort((a, b) => a.timestamp - b.timestamp);
|
|
46413
47622
|
for (const message of messages) {
|
|
46414
47623
|
const kind = forwardKind(message);
|
|
@@ -46436,6 +47645,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46436
47645
|
}
|
|
46437
47646
|
for (const message of messages) {
|
|
46438
47647
|
const hops = forwardedAgain(message.forwarded);
|
|
47648
|
+
const gone = () => this.forwardSourceGone(linkId, message.id);
|
|
46439
47649
|
try {
|
|
46440
47650
|
if (forwardKind(message) === "text") {
|
|
46441
47651
|
const sent = groupId ? await this.groups.send(groupId, message.text, [], void 0, hops) : !live.link && !(this.limitedMode && live.stored.profile) ? { error: this.limitedMode ? LIMITED_MODE_ERROR : "You are offline" } : live.stored.profile ? await this.sendChatText(live, message.text.trim(), now(), message.preview, void 0, hops) : await this.sendMessage({
|
|
@@ -46471,7 +47681,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46471
47681
|
wireId: picked.id.slice(`group-${groupId}-out-`.length),
|
|
46472
47682
|
timestamp: now(),
|
|
46473
47683
|
file: picked
|
|
46474
|
-
});
|
|
47684
|
+
}, gone);
|
|
46475
47685
|
const sent = await this.sendGroupFile({
|
|
46476
47686
|
groupId,
|
|
46477
47687
|
file,
|
|
@@ -46505,7 +47715,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46505
47715
|
wireId,
|
|
46506
47716
|
timestamp,
|
|
46507
47717
|
file: picked
|
|
46508
|
-
});
|
|
47718
|
+
}, gone);
|
|
46509
47719
|
try {
|
|
46510
47720
|
await this.sendFile({
|
|
46511
47721
|
linkId: to,
|
|
@@ -46527,9 +47737,19 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46527
47737
|
}
|
|
46528
47738
|
return { results };
|
|
46529
47739
|
}
|
|
46530
|
-
/**
|
|
46531
|
-
|
|
46532
|
-
|
|
47740
|
+
/**
|
|
47741
|
+
* A message being forwarded was deleted meanwhile: here, or for everyone by its author. Its deletion is written down
|
|
47742
|
+
* (a chat's `deletedIds`, a group's removals) before its file goes, and its row after: either says so.
|
|
47743
|
+
*/
|
|
47744
|
+
async forwardSourceGone(linkId, messageId) {
|
|
47745
|
+
return (linkId.startsWith("group:") ? this.groups.isRemoved(linkId.slice(6), messageId) : !!this.links.get(linkId)?.stored.deletedIds?.includes(messageId)) || !await db.getMessage(linkId, messageId);
|
|
47746
|
+
}
|
|
47747
|
+
/**
|
|
47748
|
+
* How many edges took my message (or its edit number `edit`, or my reaction numbered `reaction`, as `react` gave it,
|
|
47749
|
+
* or my pin numbered `pin`, as `pinMessage` gave it) so far: what `group send`, `group react` and `pin --wait sent` wait for.
|
|
47750
|
+
*/
|
|
47751
|
+
groupTaken({ groupId, messageId, edit, reaction, pin }) {
|
|
47752
|
+
return this.groups.taken(groupId, messageId, edit, reaction, pin);
|
|
46533
47753
|
}
|
|
46534
47754
|
/** The numbers of my reactions and of my pin in a 1:1 chat that the contact has not confirmed: what `react` and `pin` wait for. */
|
|
46535
47755
|
chatUnconfirmed({ linkId }) {
|
|
@@ -46541,7 +47761,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46541
47761
|
}
|
|
46542
47762
|
/**
|
|
46543
47763
|
* Reacts to a message of a chat or a group (WISP 400 § Reactions): shown here at once; a 1:1 chat keeps it until the
|
|
46544
|
-
* contact confirms it (the live session, or DHT envelopes meanwhile), a group sends it to its members.
|
|
47764
|
+
* contact confirms it (the live session, or DHT envelopes meanwhile), a group sends it to its members. In a group, `n`
|
|
47765
|
+
* is its number, for `groupTaken`.
|
|
46545
47766
|
*/
|
|
46546
47767
|
async react({ linkId, messageId, emoji }) {
|
|
46547
47768
|
if (typeof linkId !== "string" || !linkId) return { error: "No chat to react in" };
|
|
@@ -46552,7 +47773,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46552
47773
|
refused: true
|
|
46553
47774
|
};
|
|
46554
47775
|
const result = await this.reactions.mine(linkId, messageId, emoji);
|
|
46555
|
-
|
|
47776
|
+
if ("error" in result) return result;
|
|
47777
|
+
const sent = await this.sendGroupReaction(groupId, result.reaction);
|
|
47778
|
+
return sent.error ? sent : {
|
|
47779
|
+
error: null,
|
|
47780
|
+
n: result.reaction.n
|
|
47781
|
+
};
|
|
46556
47782
|
}
|
|
46557
47783
|
const live = this.links.get(linkId);
|
|
46558
47784
|
if (!live || live.stored.group) return { error: "No such chat" };
|
|
@@ -46620,13 +47846,16 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46620
47846
|
this.reactionTimers.delete(linkId);
|
|
46621
47847
|
} else if (upTo) this.flushReactions(linkId);
|
|
46622
47848
|
}
|
|
46623
|
-
/**
|
|
47849
|
+
/**
|
|
47850
|
+
* A group reaction goes to every member: over each edge in a private group, through the group in a community. Each
|
|
47851
|
+
* edge that takes it counts for `groupTaken` (`reactionKey`), as a message does.
|
|
47852
|
+
*/
|
|
46624
47853
|
async sendGroupReaction(groupId, reaction) {
|
|
46625
47854
|
if (this.groups.isCommunityGroup(groupId)) try {
|
|
46626
47855
|
await this.groups.sendCommunityApp(groupId, {
|
|
46627
47856
|
t: COMMUNITY_REACTION_FRAME,
|
|
46628
47857
|
...wireReaction(reaction)
|
|
46629
|
-
});
|
|
47858
|
+
}, reactionKey(reaction.n));
|
|
46630
47859
|
return { error: null };
|
|
46631
47860
|
} catch (error) {
|
|
46632
47861
|
return { error: error instanceof Error ? error.message : String(error) };
|
|
@@ -46637,11 +47866,20 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46637
47866
|
...wireReaction(reaction),
|
|
46638
47867
|
...this.groups.signReaction(groupId, wireReaction(reaction))
|
|
46639
47868
|
};
|
|
46640
|
-
for (const edge of this.memberEdges(groupId).values())
|
|
46641
|
-
this.links.get(edge)?.link?.sendGroupFrame(frame);
|
|
46642
|
-
} catch {}
|
|
47869
|
+
for (const edge of this.memberEdges(groupId).values()) this.sayGroupReaction(groupId, this.links.get(edge)?.link, frame);
|
|
46643
47870
|
return { error: null };
|
|
46644
47871
|
}
|
|
47872
|
+
/** My reaction frame on one edge of a private group: whether the edge took it (counted for `groupTaken`). */
|
|
47873
|
+
sayGroupReaction(groupId, link, frame) {
|
|
47874
|
+
if (!link) return false;
|
|
47875
|
+
try {
|
|
47876
|
+
link.sendGroupFrame(frame);
|
|
47877
|
+
} catch {
|
|
47878
|
+
return false;
|
|
47879
|
+
}
|
|
47880
|
+
this.groups.noteTaken(groupId, reactionKey(frame.n));
|
|
47881
|
+
return true;
|
|
47882
|
+
}
|
|
46645
47883
|
/** A group's history read in flight for edges that opened, by chat: its callers of the moment share it. */
|
|
46646
47884
|
edgeOpenReads = /* @__PURE__ */ new Map();
|
|
46647
47885
|
/**
|
|
@@ -46666,16 +47904,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46666
47904
|
const mine = groupReactionsToResend(await this.edgeOpenHistory(`group:${groupId}`), REACTION_LIMITS.pending);
|
|
46667
47905
|
const link = this.links.get(linkId)?.link;
|
|
46668
47906
|
const say = (batch) => {
|
|
46669
|
-
for (const reaction of batch)
|
|
46670
|
-
|
|
46671
|
-
|
|
46672
|
-
|
|
46673
|
-
|
|
46674
|
-
|
|
46675
|
-
});
|
|
46676
|
-
} catch {
|
|
46677
|
-
return;
|
|
46678
|
-
}
|
|
47907
|
+
for (const reaction of batch) if (!this.sayGroupReaction(groupId, link, {
|
|
47908
|
+
t: "group-react",
|
|
47909
|
+
g: groupId,
|
|
47910
|
+
...reaction,
|
|
47911
|
+
...this.groups.signReaction(groupId, reaction)
|
|
47912
|
+
})) return;
|
|
46679
47913
|
};
|
|
46680
47914
|
say(mine.slice(0, REACTION_LIMITS.send));
|
|
46681
47915
|
for (let start = REACTION_LIMITS.send, turn = 1; start < mine.length; start += REACTION_LIMITS.send, turn++) {
|
|
@@ -46698,7 +47932,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46698
47932
|
/**
|
|
46699
47933
|
* Pins a message of a chat or a group, or unpins (WISP 400 § Pinned message): one per chat, the last pin winning. A
|
|
46700
47934
|
* 1:1 chat keeps it until the contact confirms it on a live session; a group sends it to its members, where the rule
|
|
46701
|
-
* (`mayPin`) allows it.
|
|
47935
|
+
* (`mayPin`) allows it. In a group, `n` is the pin's number, for `groupTaken`. The message pinned already is not
|
|
47936
|
+
* pinned again: nothing goes, and the pin stays its pinner's (`n` only when that is me).
|
|
46702
47937
|
*/
|
|
46703
47938
|
async pinMessage({ linkId, messageId, remove }) {
|
|
46704
47939
|
if (typeof linkId !== "string" || !linkId) return { error: "No chat to pin in" };
|
|
@@ -46710,20 +47945,27 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46710
47945
|
refused: true
|
|
46711
47946
|
};
|
|
46712
47947
|
if (!mayPinIn(view)) return { error: "Only the admin pins in a community" };
|
|
46713
|
-
const pin = await myPin(host, linkId, messageId, !!remove,
|
|
47948
|
+
const current = this.groups.pinOf(groupId), pin = await myPin(host, linkId, messageId, !!remove, current);
|
|
46714
47949
|
if ("error" in pin) return pin;
|
|
47950
|
+
if ("already" in pin) return {
|
|
47951
|
+
error: null,
|
|
47952
|
+
...current?.by === "me" && { n: current.n }
|
|
47953
|
+
};
|
|
46715
47954
|
if (this.groups.isCommunityGroup(groupId)) {
|
|
46716
47955
|
try {
|
|
46717
47956
|
await this.groups.sendCommunityApp(groupId, {
|
|
46718
47957
|
t: "pin",
|
|
46719
47958
|
id: pin.id,
|
|
46720
47959
|
n: pin.n
|
|
46721
|
-
});
|
|
47960
|
+
}, pinKey(pin.n));
|
|
46722
47961
|
} catch (error) {
|
|
46723
47962
|
return { error: error instanceof Error ? error.message : String(error) };
|
|
46724
47963
|
}
|
|
46725
47964
|
await this.groups.setPin(groupId, pin);
|
|
46726
|
-
return {
|
|
47965
|
+
return {
|
|
47966
|
+
error: null,
|
|
47967
|
+
n: pin.n
|
|
47968
|
+
};
|
|
46727
47969
|
}
|
|
46728
47970
|
const frame = this.groups.pinFrame(groupId, pin);
|
|
46729
47971
|
if (!frame) return { error: "You are not in this group" };
|
|
@@ -46733,13 +47975,17 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46733
47975
|
sig: frame.sig
|
|
46734
47976
|
});
|
|
46735
47977
|
for (const member of this.memberEdges(groupId).keys()) this.sendGroupPinFrame(groupId, member);
|
|
46736
|
-
return {
|
|
47978
|
+
return {
|
|
47979
|
+
error: null,
|
|
47980
|
+
n: pin.n
|
|
47981
|
+
};
|
|
46737
47982
|
}
|
|
46738
47983
|
const live = this.links.get(linkId);
|
|
46739
47984
|
if (!live || live.stored.group) return { error: "No such chat" };
|
|
46740
47985
|
if (!live.stored.profile) return { error: "Pins need a current chat; this compatibility chat sends text only." };
|
|
46741
47986
|
const pin = await myPin(host, linkId, messageId, !!remove, live.stored.pin);
|
|
46742
47987
|
if ("error" in pin) return pin;
|
|
47988
|
+
if ("already" in pin) return { error: null };
|
|
46743
47989
|
await this.keepLinkPin(linkId, pin, {
|
|
46744
47990
|
id: pin.id,
|
|
46745
47991
|
n: pin.n
|
|
@@ -47019,7 +48265,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47019
48265
|
}) || !via) return;
|
|
47020
48266
|
for (const key of this.memberEdges(groupId).keys()) if (key !== via.from && key !== member) this.sendGroupPinFrame(groupId, key);
|
|
47021
48267
|
}
|
|
47022
|
-
/**
|
|
48268
|
+
/**
|
|
48269
|
+
* A private group's pin, as its pinner signed it, over the edge to `member`; nothing when it is down (said when it
|
|
48270
|
+
* opens). An edge that took my own pin counts for `groupTaken` (`pinKey`).
|
|
48271
|
+
*/
|
|
47023
48272
|
sendGroupPinFrame(groupId, member) {
|
|
47024
48273
|
const pin = this.groups.pinOf(groupId), edge = this.memberEdges(groupId).get(member);
|
|
47025
48274
|
if (!pin?.k || !pin.sig || !edge || this.groups.isCommunityGroup(groupId) || !pinNumberHolds(pin.n)) return;
|
|
@@ -47031,9 +48280,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47031
48280
|
k: pin.k,
|
|
47032
48281
|
sig: pin.sig
|
|
47033
48282
|
};
|
|
48283
|
+
const link = this.links.get(edge)?.link;
|
|
48284
|
+
if (!link) return;
|
|
47034
48285
|
try {
|
|
47035
|
-
|
|
47036
|
-
} catch {
|
|
48286
|
+
link.sendGroupFrame(frame);
|
|
48287
|
+
} catch {
|
|
48288
|
+
return;
|
|
48289
|
+
}
|
|
48290
|
+
if (pin.by === "me") this.groups.noteTaken(groupId, pinKey(pin.n));
|
|
47037
48291
|
}
|
|
47038
48292
|
/** `admin`: the member a leaving admin handed the role to. */
|
|
47039
48293
|
async leaveGroup({ groupId }) {
|
|
@@ -47083,6 +48337,91 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47083
48337
|
if (typing === true && this.settings.sendTyping !== false) this.groups.setTyping(groupId, true, typingActivity(kind, status));
|
|
47084
48338
|
else this.groups.setTyping(groupId, false);
|
|
47085
48339
|
}
|
|
48340
|
+
/** The longest a timer waits (a later end is waited for in steps). */
|
|
48341
|
+
static TIMER_MAX_MS = 2 ** 31 - 1;
|
|
48342
|
+
/** This profile's presence as the pages last said it (`setPresence`): none before their first word. */
|
|
48343
|
+
ownPresence;
|
|
48344
|
+
idleTimer;
|
|
48345
|
+
/** Ends this profile's status at its `until`. */
|
|
48346
|
+
ownStatusTimer;
|
|
48347
|
+
/** Per chat: when the contact's status ends, so its view is drawn again without it. */
|
|
48348
|
+
peerStatusTimers = /* @__PURE__ */ new Map();
|
|
48349
|
+
/** WISP 401 § Presence and status: `active` at a page's word, `idle` 10 minutes after the last one (or at a page's). */
|
|
48350
|
+
setPresence({ presence }) {
|
|
48351
|
+
if (presence !== "active" && presence !== "idle") return;
|
|
48352
|
+
clearTimeout(this.idleTimer);
|
|
48353
|
+
if (presence === "active") this.idleTimer = setTimeout(() => this.setPresence({ presence: "idle" }), STATUS_IDLE_AFTER_MS);
|
|
48354
|
+
if (presence === this.ownPresence) return;
|
|
48355
|
+
this.ownPresence = presence;
|
|
48356
|
+
this.sayStatus();
|
|
48357
|
+
}
|
|
48358
|
+
/** A status checked as a contact would read it: one already over is none. Said at once, then saved. */
|
|
48359
|
+
async setOwnStatus({ status }) {
|
|
48360
|
+
const clean = liveStatus(personStatus(status));
|
|
48361
|
+
if (!clean) return this.clearOwnStatus();
|
|
48362
|
+
this.settings = {
|
|
48363
|
+
...this.settings,
|
|
48364
|
+
ownStatus: clean
|
|
48365
|
+
};
|
|
48366
|
+
this.ownStatusChanged();
|
|
48367
|
+
await db.putSettings(this.settings);
|
|
48368
|
+
}
|
|
48369
|
+
async clearOwnStatus() {
|
|
48370
|
+
if (!this.settings.ownStatus) return;
|
|
48371
|
+
const { ownStatus: _cleared, ...settings } = this.settings;
|
|
48372
|
+
this.settings = settings;
|
|
48373
|
+
this.ownStatusChanged();
|
|
48374
|
+
await db.putSettings(this.settings);
|
|
48375
|
+
}
|
|
48376
|
+
getOwnStatus() {
|
|
48377
|
+
const status = liveStatus(this.settings.ownStatus);
|
|
48378
|
+
return {
|
|
48379
|
+
...this.ownPresence ? { presence: this.ownPresence } : {},
|
|
48380
|
+
...status ? { status } : {},
|
|
48381
|
+
sharePresence: this.settings.sharePresence !== false
|
|
48382
|
+
};
|
|
48383
|
+
}
|
|
48384
|
+
/** While this profile's status says Do not disturb: messages make no sound and no notice here. */
|
|
48385
|
+
get doNotDisturb() {
|
|
48386
|
+
return liveStatus(this.settings.ownStatus)?.availability === "dnd";
|
|
48387
|
+
}
|
|
48388
|
+
/** What this side says: presence only while shared, the status while it lasts. */
|
|
48389
|
+
statusToSay() {
|
|
48390
|
+
const status = liveStatus(this.settings.ownStatus);
|
|
48391
|
+
return {
|
|
48392
|
+
...this.ownPresence && this.settings.sharePresence !== false ? { presence: this.ownPresence } : {},
|
|
48393
|
+
...status ? { status } : {}
|
|
48394
|
+
};
|
|
48395
|
+
}
|
|
48396
|
+
/** Every 1:1 chat's link keeps it and says it where both sides offer `status/1` (a group edge never). */
|
|
48397
|
+
sayStatus() {
|
|
48398
|
+
const state = this.statusToSay();
|
|
48399
|
+
for (const live of this.links.values()) if (live.stored.profile && !live.stored.group) live.link?.setStatus(state);
|
|
48400
|
+
}
|
|
48401
|
+
ownStatusChanged() {
|
|
48402
|
+
this.armOwnStatusEnd();
|
|
48403
|
+
this.sayStatus();
|
|
48404
|
+
this.emitState();
|
|
48405
|
+
}
|
|
48406
|
+
armOwnStatusEnd() {
|
|
48407
|
+
clearTimeout(this.ownStatusTimer);
|
|
48408
|
+
const until = this.settings.ownStatus?.until;
|
|
48409
|
+
if (until === void 0) return;
|
|
48410
|
+
this.ownStatusTimer = setTimeout(() => {
|
|
48411
|
+
if (liveStatus(this.settings.ownStatus)) this.armOwnStatusEnd();
|
|
48412
|
+
else this.clearOwnStatus().catch(() => {});
|
|
48413
|
+
}, Math.min(Math.max(until - Date.now(), 0), GhostlyNode.TIMER_MAX_MS));
|
|
48414
|
+
}
|
|
48415
|
+
redrawAtStatusEnd(linkId, until) {
|
|
48416
|
+
clearTimeout(this.peerStatusTimers.get(linkId));
|
|
48417
|
+
this.peerStatusTimers.delete(linkId);
|
|
48418
|
+
if (until === void 0 || until <= Date.now()) return;
|
|
48419
|
+
this.peerStatusTimers.set(linkId, setTimeout(() => {
|
|
48420
|
+
this.peerStatusTimers.delete(linkId);
|
|
48421
|
+
if (until > Date.now()) this.redrawAtStatusEnd(linkId, until);
|
|
48422
|
+
else this.emitState();
|
|
48423
|
+
}, Math.min(until - Date.now() + 1, GhostlyNode.TIMER_MAX_MS)));
|
|
48424
|
+
}
|
|
47086
48425
|
/**
|
|
47087
48426
|
* A call's signaling: read the contact's record fast, for its `_call`. A compatibility chat's only: a paired chat's
|
|
47088
48427
|
* signals go only over its live session (WISP 601), so a read finds nothing for the call, and its data link keeps
|
|
@@ -48101,6 +49440,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48101
49440
|
const { nostr, ...rest } = patch;
|
|
48102
49441
|
const settings = rest;
|
|
48103
49442
|
delete settings.backupReminders;
|
|
49443
|
+
delete settings.ownStatus;
|
|
48104
49444
|
const wasOnline = this.networkOn;
|
|
48105
49445
|
if (Array.isArray(settings.iceServers)) settings.iceServers = settings.iceServers.map(iceServerSetting);
|
|
48106
49446
|
for (const server of settings.iceServers ?? []) {
|
|
@@ -48135,6 +49475,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48135
49475
|
}
|
|
48136
49476
|
delete settings.wake;
|
|
48137
49477
|
delete settings.wakeRotate;
|
|
49478
|
+
delete settings.wakeOnline;
|
|
48138
49479
|
delete settings.wakeMutedGroups;
|
|
48139
49480
|
delete settings.wakeHeldBy;
|
|
48140
49481
|
delete settings.wakeRenew;
|
|
@@ -48162,7 +49503,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48162
49503
|
if (this.relays) this.settings.relays = this.relays.describe().relays;
|
|
48163
49504
|
else if (this.transport.configure) this.settings.relays = [...new Set(settings.relays.map(normalizeRelayUrl).filter((relay) => relay !== null))];
|
|
48164
49505
|
}
|
|
48165
|
-
if (settings.relays || settings.readRelays !== void 0) {
|
|
49506
|
+
if (settings.relays || settings.readRelays !== void 0 || relayOnlyChanged) {
|
|
48166
49507
|
if (this.settings.readRelays !== true) delete this.settings.readRelays;
|
|
48167
49508
|
this.configureDirect();
|
|
48168
49509
|
}
|
|
@@ -48184,6 +49525,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48184
49525
|
this.groups.stopTyping();
|
|
48185
49526
|
}
|
|
48186
49527
|
}
|
|
49528
|
+
if (settings.sharePresence !== void 0) {
|
|
49529
|
+
if (settings.sharePresence !== false) delete this.settings.sharePresence;
|
|
49530
|
+
else this.settings.sharePresence = false;
|
|
49531
|
+
await db.putSettings(this.settings);
|
|
49532
|
+
this.sayStatus();
|
|
49533
|
+
}
|
|
48187
49534
|
for (const key of ["autoDownloads", "serveFiles"]) {
|
|
48188
49535
|
if (settings[key] === void 0) continue;
|
|
48189
49536
|
if (settings[key] !== false) delete this.settings[key];
|
|
@@ -48238,6 +49585,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48238
49585
|
this.hold.start();
|
|
48239
49586
|
this.startGroupEntries();
|
|
48240
49587
|
this.prepareSpare(STARTUP_QUIET_MS);
|
|
49588
|
+
this.announceOnline();
|
|
48241
49589
|
this.did.publishNow().catch(() => {});
|
|
48242
49590
|
this.identities.networkBack();
|
|
48243
49591
|
if (!this.options.singleDevice && knownDeviceGate()?.state === "active") this.startDeviceSet({ justRead: true }).catch(() => {});
|
|
@@ -48715,6 +50063,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48715
50063
|
*/
|
|
48716
50064
|
async deviceEnrollInvite({ name }) {
|
|
48717
50065
|
this.enrollAllowed();
|
|
50066
|
+
const handoff = this.handoffGiver?.view();
|
|
50067
|
+
if (handoff && handoff.step !== "failed") throw new Error("enroll-busy: The profile is moving. Try again after it.");
|
|
50068
|
+
if (this.settingMove) throw new Error("enroll-busy: The device set is already changing.");
|
|
48718
50069
|
await this.enrollment?.cancel().catch(() => {});
|
|
48719
50070
|
const inviter = new EnrollInviter({
|
|
48720
50071
|
profile: databaseName(),
|
|
@@ -49696,6 +51047,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
49696
51047
|
largeFilesSupport: true,
|
|
49697
51048
|
binaryFilesSupport: true,
|
|
49698
51049
|
typingSupport: true,
|
|
51050
|
+
statusSupport: !stored.group,
|
|
49699
51051
|
reactionsSupport: this.options.reactions !== false,
|
|
49700
51052
|
editSupport: !GhostlyNode.testNoEdit(),
|
|
49701
51053
|
pinSupport: true,
|
|
@@ -49805,7 +51157,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
49805
51157
|
getPairedServices: () => this.advertisedServices(stored.peerPubKeyZ32).filter((service) => service.type === "http"),
|
|
49806
51158
|
getHostedHttpService: (id) => this.hostedService(id, stored.peerPubKeyZ32),
|
|
49807
51159
|
groupsSupport: !!stored.profile,
|
|
49808
|
-
events: {
|
|
51160
|
+
events: whileChat({
|
|
49809
51161
|
onPairingProgress: (progress) => {
|
|
49810
51162
|
if (knockCue(live.pairingProgress, progress)) this.cueFeedback({
|
|
49811
51163
|
cue: "knock",
|
|
@@ -50036,6 +51388,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50036
51388
|
},
|
|
50037
51389
|
onCallSignal: (signal) => this.events.onCallSignal(linkId, signal),
|
|
50038
51390
|
onPeerTyping: () => this.emitState(),
|
|
51391
|
+
onPeerStatus: (state) => {
|
|
51392
|
+
this.emitState();
|
|
51393
|
+
this.redrawAtStatusEnd(linkId, state.status?.until);
|
|
51394
|
+
},
|
|
50039
51395
|
onReaction: async (reaction) => await this.reactions.receive(linkId, "peer", reaction) !== "dropped",
|
|
50040
51396
|
onReactionReceipt: (n) => this.reactionReceipt(linkId, n),
|
|
50041
51397
|
onReactionsTaken: (n) => this.reactionReceipt(linkId, n, true),
|
|
@@ -50079,9 +51435,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50079
51435
|
},
|
|
50080
51436
|
onFileAnnounced: stored.profile && !stored.group ? (file, packet) => this.fileAnnounced(linkId, file, packet) : void 0,
|
|
50081
51437
|
onFileFailed: (id, reason, direction) => this.fileSettled(this.localFileId(linkId, id, direction, { failed: true }), reason, linkId)
|
|
50082
|
-
}
|
|
51438
|
+
}, () => this.links.get(linkId) === live)
|
|
50083
51439
|
});
|
|
50084
51440
|
const link = live.link;
|
|
51441
|
+
const said = stored.profile && !stored.group ? this.statusToSay() : {};
|
|
51442
|
+
if (said.presence || said.status) link.setStatus(said);
|
|
50085
51443
|
if (linkId === this.activeLinkId) link.setChatActive(true);
|
|
50086
51444
|
link.start();
|
|
50087
51445
|
this.emitState();
|
|
@@ -50208,7 +51566,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50208
51566
|
* The native transports this engine runs for its contacts: the host's, Iroh's browser build where it runs in the
|
|
50209
51567
|
* page, and HyperDHT through a relay where one is set and the host has no HyperDHT of its own. While "Hide my IP from
|
|
50210
51568
|
* contacts" is on, not the host's own: its endpoints tell a contact this device's addresses (an Iroh descriptor lists
|
|
50211
|
-
* them, HyperDHT connects directly); HyperDHT then goes through the relay, as in a browser.
|
|
51569
|
+
* them, HyperDHT connects directly); HyperDHT then goes through the relay, as in a browser. Iroh's browser build stays,
|
|
51570
|
+
* dialling a contact only on one of the person's own Iroh relays: through the relay the contact names, a contact who
|
|
51571
|
+
* runs it would see this device's address.
|
|
50212
51572
|
*/
|
|
50213
51573
|
get nativeFactories() {
|
|
50214
51574
|
return this.nativeFactoriesFor(this.settings.relayOnly === true);
|
|
@@ -50220,11 +51580,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50220
51580
|
nativeFactoriesFor(relayOnly) {
|
|
50221
51581
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
50222
51582
|
return {
|
|
50223
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
51583
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-BvI_uNZO.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
50224
51584
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
50225
51585
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
50226
51586
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, {
|
|
50227
51587
|
relays: this.irohRelays,
|
|
51588
|
+
...relayOnly && { ownRelaysOnly: true },
|
|
50228
51589
|
...this.options.irohPublicRelay && { publicRelay: this.options.irohPublicRelay }
|
|
50229
51590
|
}) } : {}
|
|
50230
51591
|
};
|
|
@@ -51099,6 +52460,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51099
52460
|
};
|
|
51100
52461
|
message = this.placed(message, place);
|
|
51101
52462
|
const live = this.links.get(message.linkId);
|
|
52463
|
+
const deletes = this.removedChats.get(message.linkId);
|
|
52464
|
+
if (!live && deletes !== void 0) return false;
|
|
52465
|
+
const chat = message.linkId;
|
|
52466
|
+
const kept = () => this.removedChats.get(chat) === deletes;
|
|
51102
52467
|
if (live?.stored.deletedIds?.includes(message.id)) return false;
|
|
51103
52468
|
if (message.linkId.startsWith("group:") && this.groups.isRemoved(message.linkId.slice(6), message.id)) return false;
|
|
51104
52469
|
const first = live ? this.firstContactRow(live, message) : false;
|
|
@@ -51131,7 +52496,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51131
52496
|
}
|
|
51132
52497
|
};
|
|
51133
52498
|
}
|
|
51134
|
-
if (!await
|
|
52499
|
+
if (!await this.addRowWhile(message, kept)) return false;
|
|
52500
|
+
if (message.sender === "me" && message.paymentId) this.awaitingSoon();
|
|
51135
52501
|
if (live && waitsForLive(message)) live.waitingSends?.then((known) => known.add(message.id), () => {});
|
|
51136
52502
|
const unkeyed = live && !live.stored.group && unkeyedRef(message);
|
|
51137
52503
|
if (unkeyed) live.unkeyedRows?.then((rows) => rows.set(unkeyed, message.id), () => {});
|
|
@@ -51145,14 +52511,28 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51145
52511
|
const early = message.sender === "peer" && message.id.startsWith("peer_") ? this.editBuffer.take(message.linkId, message.id.slice(5)) : void 0;
|
|
51146
52512
|
if (early) {
|
|
51147
52513
|
await this.applyPeerEdit(message.linkId, message, early);
|
|
52514
|
+
if (!kept()) return false;
|
|
51148
52515
|
live?.link?.confirmEdit(early.id, early.e);
|
|
51149
52516
|
}
|
|
51150
52517
|
await this.messagesChanged(message.linkId, [message.id]);
|
|
52518
|
+
if (!kept()) return false;
|
|
51151
52519
|
this.emitState();
|
|
51152
52520
|
await this.reactions.stored(message);
|
|
51153
52521
|
await this.groupEdits.stored(message);
|
|
51154
52522
|
return true;
|
|
51155
52523
|
}
|
|
52524
|
+
/**
|
|
52525
|
+
* Writes a new message's row while `kept` says its chat is still the one its store began for, checked right before
|
|
52526
|
+
* the write and again once it is done: a chat deleted while the row was being written loses it again, as the
|
|
52527
|
+
* chat's other rows went (`db.deleteLink`). False when it was there already, or its chat went.
|
|
52528
|
+
*/
|
|
52529
|
+
async addRowWhile(message, kept) {
|
|
52530
|
+
if (!kept()) return false;
|
|
52531
|
+
if (!await db.addMessage(message)) return false;
|
|
52532
|
+
if (kept()) return true;
|
|
52533
|
+
await db.deleteMessage(message.linkId, message.id).catch(() => {});
|
|
52534
|
+
return false;
|
|
52535
|
+
}
|
|
51156
52536
|
servicesChanged() {
|
|
51157
52537
|
for (const live of this.links.values()) live.link?.refreshServices();
|
|
51158
52538
|
this.emitState();
|
|
@@ -51177,6 +52557,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51177
52557
|
sessionOffers: stored.profile ? live.link?.sessionOffers : void 0,
|
|
51178
52558
|
callsUnavailable: !stored.profile ? void 0 : live.link ? live.link.callsUnavailable : "Calls need a live connection",
|
|
51179
52559
|
...stored.profile && !stored.group && live.link?.peerTyping ? typingView(live.link.peerTypingActivity) : {},
|
|
52560
|
+
...stored.profile && !stored.group && live.link?.peerStatus?.presence ? { peerPresence: live.link.peerStatus.presence } : {},
|
|
52561
|
+
...stored.profile && !stored.group && live.link?.peerStatus?.status ? { peerStatus: live.link.peerStatus.status } : {},
|
|
51180
52562
|
...stored.profile && !stored.group && {
|
|
51181
52563
|
wakeToken: this.settings.wake ? stored.wakeToken : void 0,
|
|
51182
52564
|
peerWakes: !!stored.peerWake,
|
|
@@ -51204,7 +52586,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51204
52586
|
canSendText: (live.link?.canSendText ?? false) || this.holdingFor(live),
|
|
51205
52587
|
textDelivery: this.holdingFor(live) ? "hold" : live.link?.textDelivery ?? "unavailable",
|
|
51206
52588
|
transportErrors: live.transportErrors,
|
|
51207
|
-
preferredTransport: live.stored.preferredTransport ?? automaticTransport(live.link?.availableTransports ?? []),
|
|
52589
|
+
preferredTransport: live.stored.preferredTransport ?? automaticTransport(live.link?.availableTransports ?? [], live.stored.transportFallback ?? true),
|
|
51208
52590
|
transportFallback: live.stored.transportFallback ?? true,
|
|
51209
52591
|
transportAutomatic: live.stored.preferredTransport === void 0,
|
|
51210
52592
|
peerTransports: live.link?.peerAvailableTransports,
|
|
@@ -51325,12 +52707,22 @@ var EngineServer = class {
|
|
|
51325
52707
|
/** How many history changes the engine told; per chat or group, the count at its last one (`historyMark`). */
|
|
51326
52708
|
changes = 0;
|
|
51327
52709
|
changedAt = /* @__PURE__ */ new Map();
|
|
52710
|
+
/**
|
|
52711
|
+
* An attention event while no client is attached to hear it: the host tells the person itself. The extension's peer
|
|
52712
|
+
* runs with no tab open, and a message that came then showed nothing until Ghostly was opened.
|
|
52713
|
+
*/
|
|
52714
|
+
unheardAttention;
|
|
52715
|
+
/**
|
|
52716
|
+
* `keepNewest`: the start keeps each chat's and group's newest rows that many, from the whole histories it reads anyway,
|
|
52717
|
+
* for `takeStartNewest` (the CLI's event check at start, which read them again).
|
|
52718
|
+
*/
|
|
51328
52719
|
constructor(options = {}) {
|
|
52720
|
+
if (options.keepNewest) db.keepNewest(options.keepNewest);
|
|
51329
52721
|
this.node = new GhostlyNode({
|
|
51330
|
-
onAttention: (event) => this.broadcast({
|
|
52722
|
+
onAttention: (event) => this.clients.size ? this.broadcast({
|
|
51331
52723
|
kind: "attention",
|
|
51332
52724
|
event
|
|
51333
|
-
}),
|
|
52725
|
+
}) : this.unheardAttention?.(event),
|
|
51334
52726
|
onState: (state) => this.broadcast({
|
|
51335
52727
|
kind: "state",
|
|
51336
52728
|
state
|
|
@@ -51369,7 +52761,17 @@ var EngineServer = class {
|
|
|
51369
52761
|
})
|
|
51370
52762
|
}, options);
|
|
51371
52763
|
this.ready = this.node.start();
|
|
51372
|
-
this.ready.catch(() => {
|
|
52764
|
+
this.ready.catch(() => {
|
|
52765
|
+
if (options.keepNewest) db.keepNewest(0);
|
|
52766
|
+
});
|
|
52767
|
+
}
|
|
52768
|
+
/**
|
|
52769
|
+
* Once the engine has started: per chat or group, its newest rows (`keepNewest`) as `messagePage` reads them, from the
|
|
52770
|
+
* whole history the start read. A history written since that read is not in it; one changed since the engine was made
|
|
52771
|
+
* may be (`historyChanged` says). Keeping stops: a second call gets none.
|
|
52772
|
+
*/
|
|
52773
|
+
takeStartNewest() {
|
|
52774
|
+
return db.takeNewest();
|
|
51373
52775
|
}
|
|
51374
52776
|
/** A point in the engine's history changes: a history read after it can be handed to `attach` as read. */
|
|
51375
52777
|
get historyMark() {
|
|
@@ -51603,4 +53005,4 @@ function signalKind(signal) {
|
|
|
51603
53005
|
//#endregion
|
|
51604
53006
|
export { EngineServer };
|
|
51605
53007
|
|
|
51606
|
-
//# sourceMappingURL=server-
|
|
53008
|
+
//# sourceMappingURL=server-DdtPxkqI.js.map
|