@ghostlytools/cli 1.10.2 → 1.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/assets/{api-DcE4KylM.js → api-DgS7f5TT.js} +2 -2
- package/dist/assets/{api-EUGHGnRz.js → api-DkcMOWLX.js} +44 -19
- package/dist/assets/api-DkcMOWLX.js.map +1 -0
- package/dist/assets/{apiKit-CJVp_crp.js → apiKit-D6Oj-vFx.js} +27 -11
- package/dist/assets/apiKit-D6Oj-vFx.js.map +1 -0
- package/dist/assets/{apps-C54T_MOT.js → apps-B22SeD6T.js} +3 -3
- package/dist/assets/{apps-C54T_MOT.js.map → apps-B22SeD6T.js.map} +1 -1
- package/dist/assets/{apps-C-KbyLCa.js → apps-DgALLHzS.js} +1 -1
- package/dist/assets/{arkade-BmxJTa65.js → arkade-D5cPr_dV.js} +2 -2
- package/dist/assets/{arkade-BmxJTa65.js.map → arkade-D5cPr_dV.js.map} +1 -1
- package/dist/assets/{backup-C0Plp-DF.js → backup-DndsW2uX.js} +1 -1
- package/dist/assets/{backup-BxSH5BZG.js → backup-dzJLzg-k.js} +6 -6
- package/dist/assets/{backup-BxSH5BZG.js.map → backup-dzJLzg-k.js.map} +1 -1
- package/dist/assets/{blobFiles-BnjN_Vrz.js → blobFiles-XZ9PEXYy.js} +2 -2
- package/dist/assets/{blobFiles-BnjN_Vrz.js.map → blobFiles-XZ9PEXYy.js.map} +1 -1
- package/dist/assets/{buttons-B-ZJYdo0.js → buttons-ByKT_vP8.js} +4 -4
- package/dist/assets/{buttons-B-ZJYdo0.js.map → buttons-ByKT_vP8.js.map} +1 -1
- package/dist/assets/buttons-TVCNj280.js +2 -0
- package/dist/assets/{client-CDa87uYD.js → client-q7dVOtYb.js} +10 -4
- package/dist/assets/client-q7dVOtYb.js.map +1 -0
- package/dist/assets/{codec-D45W1L8n.js → codec-HD6iOn_D.js} +2 -2
- package/dist/assets/{codec-D45W1L8n.js.map → codec-HD6iOn_D.js.map} +1 -1
- package/dist/assets/{envelope-C3yFCQa-.js → envelope-C-0tfbOG.js} +2 -2
- package/dist/assets/{envelope-C3yFCQa-.js.map → envelope-C-0tfbOG.js.map} +1 -1
- package/dist/assets/{fileBytes-DjBYYyXT.js → fileBytes-BABGEF13.js} +2 -2
- package/dist/assets/{fileBytes-DjBYYyXT.js.map → fileBytes-BABGEF13.js.map} +1 -1
- package/dist/assets/{fileBytes-DMzrIdCu.js → fileBytes-CQQK2uOh.js} +1 -1
- package/dist/assets/{fileBytes-Douk1yOp.js → fileBytes-DqnfKIkj.js} +2 -2
- package/dist/assets/{fileBytes-Douk1yOp.js.map → fileBytes-DqnfKIkj.js.map} +1 -1
- package/dist/assets/fileBytesIdb-BtXATa7j.js +2 -0
- package/dist/assets/{fileBytesIdb-CkClu9YI.js → fileBytesIdb-DrXmDUSy.js} +2 -2
- package/dist/assets/{fileBytesIdb-CkClu9YI.js.map → fileBytesIdb-DrXmDUSy.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-WryQuOgK.js → fileBytesOpfs-udKCzcLe.js} +6 -9
- package/dist/assets/{fileBytesOpfs-WryQuOgK.js.map → fileBytesOpfs-udKCzcLe.js.map} +1 -1
- package/dist/assets/{fixedHosts-C6nCHjOa.js → fixedHosts-CN3CsslV.js} +7 -8
- package/dist/assets/fixedHosts-CN3CsslV.js.map +1 -0
- package/dist/assets/{groupFiles-DYopNE57.js → groupFiles-BFv9K_za.js} +256 -110
- package/dist/assets/groupFiles-BFv9K_za.js.map +1 -0
- package/dist/assets/{host-G5seUwaI.js → host-C-wwtVt2.js} +378 -60
- package/dist/assets/host-C-wwtVt2.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-B_uHjg_r.js → hyperdhtRelay-B9EQTm_M.js} +2 -2
- package/dist/assets/{hyperdhtRelay-B_uHjg_r.js.map → hyperdhtRelay-B9EQTm_M.js.map} +1 -1
- package/dist/assets/{irohWeb-C-2oslSU.js → irohWeb-o0H_NlCF.js} +2 -2
- package/dist/assets/{irohWeb-C-2oslSU.js.map → irohWeb-o0H_NlCF.js.map} +1 -1
- package/dist/assets/{main-Dk--nD7X.js → main-CLUIPy4d.js} +49 -30
- package/dist/assets/main-CLUIPy4d.js.map +1 -0
- package/dist/assets/{mainline-HPlVrl8R.js → mainline-B2qmNsib.js} +155 -3
- package/dist/assets/mainline-B2qmNsib.js.map +1 -0
- package/dist/assets/{networkReason-CfpO9ayz.js → networkReason-BEl-DDWd.js} +4 -4
- package/dist/assets/{networkReason-CfpO9ayz.js.map → networkReason-BEl-DDWd.js.map} +1 -1
- package/dist/assets/{nwc-BY7BPttn.js → nwc-BNkhjJHN.js} +3 -3
- package/dist/assets/{nwc-BY7BPttn.js.map → nwc-BNkhjJHN.js.map} +1 -1
- package/dist/assets/{nwcProvider-CfpbNUf7.js → nwcProvider-CvaRJdHT.js} +2 -2
- package/dist/assets/{nwcProvider-CfpbNUf7.js.map → nwcProvider-CvaRJdHT.js.map} +1 -1
- package/dist/assets/{ownDid-DJFZM2cV.js → ownDid-D67KNdJq.js} +3 -2
- package/dist/assets/ownDid-D67KNdJq.js.map +1 -0
- package/dist/assets/{profiles-DKmZGXp6.js → profiles-QDB7V_Qt.js} +7 -5
- package/dist/assets/profiles-QDB7V_Qt.js.map +1 -0
- package/dist/assets/{registry-BUm4cAzV.js → registry-BKkSnpjL.js} +126 -19
- package/dist/assets/registry-BKkSnpjL.js.map +1 -0
- package/dist/assets/{registry-CAzrtV0_.js → registry-DN5a8Ul6.js} +1 -1
- package/dist/assets/{resolve-CDD4X68j.js → resolve-DhpAggDP.js} +24 -5
- package/dist/assets/resolve-DhpAggDP.js.map +1 -0
- package/dist/assets/{server-DcOsgYDU.js → server-7w2O5wsv.js} +956 -277
- package/dist/assets/server-7w2O5wsv.js.map +1 -0
- package/dist/assets/{src-D31D1_oY.js → src-BZkY6N3J.js} +909 -198
- package/dist/assets/src-BZkY6N3J.js.map +1 -0
- package/dist/assets/{sshForges-DerRwMf3.js → sshForges-Cxjt3c51.js} +2 -2
- package/dist/assets/{sshForges-DerRwMf3.js.map → sshForges-Cxjt3c51.js.map} +1 -1
- package/dist/assets/{translate-C-sj0VJe.js → translate-v8wF1GcF.js} +2 -2
- package/dist/assets/{translate-C-sj0VJe.js.map → translate-v8wF1GcF.js.map} +1 -1
- package/dist/assets/{usdt-DwHqp625.js → usdt-63gYjM5E.js} +7 -4
- package/dist/assets/usdt-63gYjM5E.js.map +1 -0
- package/dist/assets/{waitNotice-D52RWbV4.js → waitNotice-Ce3YCinu.js} +27 -5
- package/dist/assets/waitNotice-Ce3YCinu.js.map +1 -0
- package/dist/assets/{words-Db9WgatT.js → words-PUnyO4ph.js} +4 -4
- package/dist/assets/words-PUnyO4ph.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-EUGHGnRz.js.map +0 -1
- package/dist/assets/apiKit-CJVp_crp.js.map +0 -1
- package/dist/assets/buttons-DA3wZfG0.js +0 -2
- package/dist/assets/client-CDa87uYD.js.map +0 -1
- package/dist/assets/fileBytesIdb-CD5Uv490.js +0 -2
- package/dist/assets/fixedHosts-C6nCHjOa.js.map +0 -1
- package/dist/assets/groupFiles-DYopNE57.js.map +0 -1
- package/dist/assets/host-G5seUwaI.js.map +0 -1
- package/dist/assets/main-Dk--nD7X.js.map +0 -1
- package/dist/assets/mainline-HPlVrl8R.js.map +0 -1
- package/dist/assets/ownDid-DJFZM2cV.js.map +0 -1
- package/dist/assets/profiles-DKmZGXp6.js.map +0 -1
- package/dist/assets/registry-BUm4cAzV.js.map +0 -1
- package/dist/assets/resolve-CDD4X68j.js.map +0 -1
- package/dist/assets/server-DcOsgYDU.js.map +0 -1
- package/dist/assets/src-D31D1_oY.js.map +0 -1
- package/dist/assets/usdt-DwHqp625.js.map +0 -1
- package/dist/assets/waitNotice-D52RWbV4.js.map +0 -1
- package/dist/assets/words-Db9WgatT.js.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $a as
|
|
2
|
+
import { $a as ReactionWindow, $c as openRequest, $i as HOLD_DATED_BACK_MS, $l as deviceEchoFrame, $n as engineError, $o as PRESENCE_WINDOW, $r as PIN_LIMITS, $s as handoffReleaseFrame, $t as ONCHAIN_PROVIDER, $u as sanitizeDisplayText, A as knockIdentity, Ac as enrollProofFrame, An as ENDPOINT, Ao as claimedTime, Ar as lobbyKeys, As as HANDOFF_HELLO, Au as currentRelays, Ba as EDIT_RATE_WINDOW_MS, Bc as takeRequest, Bl as createDeviceInvite, Bn as NO_PICTURE_METADATA, Bo as rosterAdmin, Br as shouldBeHub, Bs as handoffAttemptFailed, C as communityHasFrame, Ca as peekDhtMailbox, Ci as UPGRADE_CAPABILITY, Cl as isAppHash, Cr as pickMeshHubs, Cs as HTTP_SERVICE_PROTO, Cu as turnVerifierMark, D as decodeGroupEntryLink, Da as sanitizeFileName, Dc as enrollDoneFrame, Di as dialDescriptors, Dl as readAppRevocationShape, Dr as doorHubs, Ds as HANDOFF_CANCEL, Du as RelayTransport, Ea as formatFileSize, Ec as enrollDigits, Ei as capsDescriptors, El as readAppRevocation, Eo as sameButtonText, Er as beaconRecords, Es as HANDOFF_ACK, F as GroupWakeLimiter, Fa as parseVoiceMeta, Fc as endedRequests, Fi as emptyIdentityLedger, Fn as parseCashuRequestPayload, Fo as GROUP_MEMBER_CAP, Fr as pickHubs, Fs as HANDOFF_TIMINGS, Gc as contactAskerHolds, Gi as emptyProofLedger, Gl as decodeInviteCode, Gn as GhostLink, Go as RatchetBox, Gr as transferEnded, Gs as handoffContextProof, Gt as didDhtDocument, Gu as createIdentity, H as GroupSession, Ha as REMOVED_TEXT, Hc as ContactRequestError, Hl as readDeviceInvite, Hn as isStrippedPicture, Ho as verifyCommitSignature, Hr as FILE_LIMITS, Hs as handoffBusyFrame, I as groupWakeFrame, Ic as inboxRecord, Il as readCanonicalJson, In as parseFedimintRequestPayload, Ir as rankHubs, Is as HANDOFF_VERIFIED, Iu as budgetRetryMs, J as meshMessageRef, Ja as forwardedAgain, Jc as knockSlotOf, Ji as automaticTransport, Jl as inviteOwnership, Jn as PAIRED_FRAME_TOO_LARGE, Jo as DirectPathWatch, Js as handoffEphemeral, Jt as encodeDidDhtPacket, Ju as publicKeyFromZ32, K as GROUP_EDIT_TEXT_BYTES, Kc as contactDay, Ki as validExternalKey, Kl as encodeInviteCode, Kn as INVITE_TAKEN, Ko as emptyRatchetState, Kr as transferStalled, Ks as handoffDataFrame, Kt as didDhtFromPublicKey, Ku as identityFromSeed, L as groupWakes, Lc as newInbox, Ll as createContactLink, Lo as MEMBER_KEY, Lr as readBeacon, Ls as NO_ATTEMPTS, Lu as isDiscoveryBudgetError, M as mergeKnocks, Mc as readEnrollHello, Ml as parseImageMeta, Mn as fedimintRequestPayload, Mo as receivedTimestamp, Mr as mergeBeacon, Ms as HANDOFF_PAKE, N as readKnocks, Nc as verifyEnrollProof, Nn as findEndpoint, No as shownTime, Nr as mergeLobby, Ns as HANDOFF_PIECE_BYTES, O as encodeGroupEntryLink, Oa as sanitizeMime, Oc as enrollGrantFrame, Oo as statusCardText, Or as freshHubs, Os as HANDOFF_DONE, Pa as fileMessageText, Pc as clearMissed, Pl as canonicalJson, Pn as isFederationId, Po as GROUP_ADMIN_OFF_ERROR, Pr as newerHead, Ps as HANDOFF_REQUEST, Pu as traceLink, Qa as REACTION_LIMITS, Qc as mergeContactKnocks, Qi as HOLD_CAPABILITY, Ql as HANDOFF_CAPABILITY, Qn as EngineError, Qs as handoffPakeFrame, Qt as EVM_TEST_CHAINS, Qu as hasVisible, R as parseGroupWakeFrame, Ra as parseVideoMeta, Rc as planKnocks, Rl as encodeContactLink, Rn as videoMetadataPatches, Ro as commitHash, Rr as readBeaconHead, Rs as filePartName, Ru as withRequestOptions, S as GROUP_READ_NOTE_COMMUNITY, Sa as DHT_MESSAGE_TTL, Si as STATUS_CARD_CAPABILITY, Sr as meshHubs, Ss as emptyLinkRecords, Su as turnStatedVerifier, T as encodeCommunityLink, Ta as dhtFileId, Tc as enrollCancelReason, Ti as DHT_TEXT_CAPABILITY, Tl as isAppRef, To as checkStatusCard, Tr as beaconKeys, Ts as serviceIdFromName, U as frameBytes, Ua as RateWindow, Uc as REQUEST_LIFETIME_MS, Ui as lastSharedWithMe, Ul as OwnInviteError, Un as stripPictureMetadata, Uo as edgeParams, Us as handoffCancelFrame, V as GROUP_READ_NOTE, Va as MAX_REMOVAL_NUMBER, Vc as turnOff, Vi as receivedIdentityStatus, Vl as deviceInviteJoinerParams, Vn as PICTURE_METADATA_LIMITS, Vo as rosterHas, Vr as ChatFiles, Vs as handoffAttemptSucceeded, Vu as createRelayPayload, Wa as dhtEditId, Wc as contactAskerFrame, Wi as PeerProofs, Wl as createChatInvite, Wo as RATCHET_CAPABILITY, Wr as sentWhole, Ws as handoffContext, X as mentionsMember, Xa as COMMUNITY_REACTION_FRAME, Xc as linkRecords, Xl as DEVICES_CAPABILITY, Xn as pairedMessageFits, Xs as handoffManifestFrames, Xt as signDidDhtPacket, Y as parseCommunityEdit, Ya as readForwarded, Yc as knockSlotRecords, Yn as pairedEditFits, Yr as TypingSender, Ys as handoffHelloFrame, Yu as verify, Z as groupName, Za as GROUP_REACTION_FRAME, Zc as makeStampPaced, Zl as ENROLL_CAPABILITY, Zn as pairedMessageFrame, Zo as DHT_POLL_INTERVALS, Zr as typingActivity, Zs as handoffOfferFrame, Zt as ETHEREUM_USDT, Zu as sanitizeAvatar, _ as groupTypingEpoch, _c as setUpdateFrame, _i as chatAppId, _t as isAtprotoDid, _u as signTurnPacket, a as appRevocationFor, aa as readManifest, ac as readHandoffCancel, ad as toBase64Url, ai as WAKE_CALL_INTERVAL_MS, al as APP_BUNDLE_MAGIC, an as WALLET_NETWORKS, ao as validReactionNumber, as as parseLocalTarget, au as seedSigner, b as COMMUNITY_LIMITS, bi as BUTTONS_CAPABILITY, bl as appRef, br as MESH_HUBS, bs as parseCallSignal, bu as turnKeys, c as checkAppBeforeRun, cc as readHandoffHello, cd as utf8Encode, ci as newWakeToken, cl as appDigest, cn as assertWholeSats, co as readReply, cs as decodeControl, cu as TURN_RAISE_READ_TIMEOUT_MS, dc as readHandoffVerified, di as wakeRequest, dn as walletNetworkOf, du as turnPutSummary, ea as HOLD_LIMITS, ec as handoffRetryAfter, ed as stripHidden, ei as mayPin, el as readKnockSlot, en as PaymentPreflightError, eo as nextReactionNumber, er as engineText, es as RELAY_POLL_INTERVALS, eu as deviceEchoNonce, fc as sealHandoffPiece, fi as checkPushEndpoint, fl as isAppUrl, fn as SPARK_NETWORKS, fu as TURN_LAST_SEQUENCE, g as GroupTypingBoard, gc as setAckFrame, gl as sha256Paced, gn as isBitcoinAddress, gu as readTurnPacket, hc as readSetUpdate, hi as isServeId, hl as readAppBundleAsync, hn as sparkInvoiceDetails, hu as nextTurnPosition, i as addedAppPermissions, ia as newMailbox, ic as readHandoffAck, id as randomBytes, ii as readPin, il as APP_BUNDLE_LIMITS, in as USDT_PUBLIC_RPC, io as readReaction, is as formatLocalTarget, iu as newDeviceSetSecret, j as knockRecords, jc as readEnrollGrant, jn as cashuRequestPayload, jo as heardTime, jr as lobbyRecords, js as HANDOFF_OFFER, ju as normalizeRelayUrl, k as entryParams, kc as enrollHelloFrame, kn as decodeBolt11, ko as arrivalKey, kr as hubRank, ks as HANDOFF_HAVE, l as planAppUpdate, lc as readHandoffPake, li as parseWakeFrame, ll as appViewOf, ln as formatPaymentAmount, lo as replySnippet, lr as readGroupFileMeta, ls as encodeControl, lu as TURN_SETTLE_MS, mi as APP_RANGE_LIMITS, mn as sparkAddressKind, mu as firstDeviceSetSecret, n as readX401SdJwtVc, na as HoldRefusedError, nc as handoffVersions, nd as fromBase64Url, ni as pinIsNewer, nl as requestRecords, no as reactionEmoji, nr as GROUP_FILE_LIMITS, ns as presenceSeenAt, nu as deviceLinkPairing, o as appStoreDecision, oc as readHandoffDone, od as toZ32, oi as WakeLimiter, on as arkAddressPrefix, oo as wireReaction, os as webLocalFetch, ou as webCryptoSigner, p as readAppStoreSteps, pi as vapidKeysMatch, pl as pacer, pn as SPARK_PROVIDER, pr as CarriedTransport, ps as RTC_CONFIG, pu as TURN_MAX, q as carryMentions, qa as parseLinkPreview, qc as knockSlotIdentity, qi as TRANSPORTS, ql as inviteLink, qn as LIVENESS_PING_MS, qo as ratchetSessionOf, qs as handoffDigest, qt as encodeDidDhtDeactivated, qu as identityFromSeedB64, r as sameX401HolderJwk, ra as isHoldUrl, rc as newHandoffId, ri as pinNumberHolds, rl as seenEntry, rn as TEST_USDT_FAUCET_AMOUNT, ro as reactionIsNewer, rr as GROUP_HAVE_FRAME, rs as GhostlyHttpError, ru as devicePingFrame, s as appUpdateDecision, sc as readHandoffHave, sd as utf8Decode, si as deviceWakeRequest, sn as assertTokenUnits, so as pairedReplyAuthor, sr as groupFileFallback, ss as LIMITS, t as newX401HolderKey, ta as HoldKeys, tc as handoffStreamKey, td as bytesEqual, ti as nextPinNumber, tl as readLinkRecord, tn as SEPOLIA_TEST_USDT, to as queueReaction, tr as parseEngineError, ts as WATCH_PEER_MS, tu as deviceKeyZ32, u as APP_STORE_LIMITS, uc as readHandoffTurnFrame, ui as relayRequest, un as validatePaymentTarget, uo as BUTTON_ID, uu as classifyTurnRead, v as openGroupTyping, vc as signTombstone, vi as isAppVersion, vl as APP_STATEMENT_LIMITS, vn as isPubkyKey, vo as STATUS_CARD_LIMITS, vr as groupSignalFrame, vs as contactRtcConfig, vt as normalizeAtprotoHandle, vu as signTurnRelease, w as decodeCommunityLink, wa as DHT_FILE_CAPABILITY, wc as enrollCancelFrame, wi as CapsExchange, wl as isAppKey, wr as COMMUNITY_TOPOLOGY, ws as LEGACY_SERVICES, wu as DEFAULT_RELAYS, x as CommunitySession, xi as EDIT_CAPABILITY, xl as appRefPublisher, xr as mayBeHub, xu as turnName, y as sealGroupTyping, yc as verifySetUpdate, yi as APPS_CAPABILITY, yl as appFingerprint, yr as readGroupSignal, yu as turnInstance, z as GROUP_LIMITS, za as EDIT_BUFFER_MS, zc as settleRequest, zl as readContactLink, zn as withoutVideoMetadata, zo as parseGroupCommit, zr as readLobby, zs as handoffAttemptAllowed, zu as PacketTooLargeError } from "./src-BZkY6N3J.js";
|
|
3
3
|
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
|
|
4
4
|
import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
5
|
+
import { t as nwc } from "./nwcProvider-CvaRJdHT.js";
|
|
6
6
|
import { a as clearProfileStores, c as deleteDatabase, d as newestWalletTx, f as openDb, g as wrap, h as transact, i as STORES$1, l as errorLine, m as store, n as APP_STORAGE_SCOPE_INDEX, o as committed, p as profileOpenFailure, r as CARD_INDEX, s as databaseName, t as APP_STORAGE_CHAT_INDEX, u as fileStore } from "./idb-BHsAqENE.js";
|
|
7
|
-
import { a as sealSeed, c as openRow, d as
|
|
8
|
-
import { $ as ModeGate, A as IdentityProofs, B as
|
|
9
|
-
import { a as fedimintDatabase, i as onPublicIrohRelay, n as createIrohWebEndpoint, r as irohRelayProblem, s as loadFedimintSdk, t as DEFAULT_IROH_RELAYS } from "./irohWeb-
|
|
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-BEl-DDWd.js";
|
|
8
|
+
import { $ as ModeGate, A as IdentityProofs, B as ProviderSources, C as FileAppender, D as streamStored, E as storedSize, F as normalizePhrase, G as breezDatabase, H as CASHU_MINT_SOURCE, I as journaledPayment, J as dropBreezDatabase, K as breezDatabaseInUse, L as lightningPaying, M as LightningCards, N as cardsKey, P as isRecoveryPhrase, Q as ModeChanged, R as INVOICE_PACE, S as WALLET_TYPES, T as removeStored, U as cashuMint, V as sourceKey, W as AskBackoff, X as iceServerSetting, Y as iceServerProblem, Z as relayOnlyProblem, _ as crossNetwork, a as storedGroupFiles, at as setAwayWallets, b as walletInstances, c as receivedPairedReply, d as paymentAlias, et as WrongNetworkError, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, it as requireTurn, j as CASHU_CARD, l as replyRef, m as assertConfirmedReal, n as groupFileId, nt as awayFrom, o as groupReply, ot as setSingleWriterGate, p as WALLET_NAMES, q as breezDatabasesFor, r as groupFileText, rt as refuseAway, s as pairedWireReply, t as GroupFileDesk, tt as networkLabel, u as replyTo, v as paymentNetwork, w as readStored$2, y as paymentNetworksOf, z as nextInvoiceAsk } from "./groupFiles-BFv9K_za.js";
|
|
9
|
+
import { a as fedimintDatabase, i as onPublicIrohRelay, n as createIrohWebEndpoint, r as irohRelayProblem, s as loadFedimintSdk, t as DEFAULT_IROH_RELAYS } from "./irohWeb-o0H_NlCF.js";
|
|
10
10
|
import { c as isTestMint, d as mintUrlSpelling, f as paysItsOwnInvoices, l as isWorthlessMint, n as DEFAULT_MINTS, o as fakesLightning, r as TEST_MINT, t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
|
|
11
|
-
import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-
|
|
12
|
-
import { d as chosenResolver, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-
|
|
13
|
-
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-
|
|
14
|
-
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-
|
|
11
|
+
import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-D67KNdJq.js";
|
|
12
|
+
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-DhpAggDP.js";
|
|
13
|
+
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-BABGEF13.js";
|
|
14
|
+
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-C-0tfbOG.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";
|
|
@@ -199,7 +199,7 @@ function viewNews(before, after) {
|
|
|
199
199
|
//#endregion
|
|
200
200
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
201
201
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
202
|
-
var loadUsdt = () => import("./usdt-
|
|
202
|
+
var loadUsdt = () => import("./usdt-63gYjM5E.js");
|
|
203
203
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
204
204
|
var DEFAULT_USDT = {
|
|
205
205
|
network: "ethereum",
|
|
@@ -686,7 +686,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
686
686
|
//#endregion
|
|
687
687
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
688
688
|
/** 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-
|
|
689
|
+
var loadArkade = () => import("./arkade-D5cPr_dV.js");
|
|
690
690
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
691
691
|
var RETIRE_READ_MS = 1e4;
|
|
692
692
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -1999,7 +1999,7 @@ var key = (mode) => `fedimintWallet-${mode}`;
|
|
|
1999
1999
|
var sats$6 = (msats) => Math.floor(msats / 1e3);
|
|
2000
2000
|
function assertFedimintAmount(amount) {
|
|
2001
2001
|
if (!Number.isSafeInteger(amount) || amount <= 0) throw new Error("Enter an amount in sats");
|
|
2002
|
-
if (amount > MAX_SATS) throw new Error(`Amounts above ${MAX_SATS.toLocaleString()} sats are not supported`);
|
|
2002
|
+
if (amount > MAX_SATS) throw new Error(`Amounts above ${MAX_SATS.toLocaleString("en-US")} sats are not supported`);
|
|
2003
2003
|
}
|
|
2004
2004
|
/** An invite code as the client takes it: bech32m with the prefix `fed1` (so `fed11…`), one line, bounded. */
|
|
2005
2005
|
function normalizeInvite(text) {
|
|
@@ -2666,7 +2666,7 @@ var FedimintAdapter = class {
|
|
|
2666
2666
|
if (!federation || federation.network !== target.network) throw new Error("You have not joined this federation in the Fedimint wallet of its network");
|
|
2667
2667
|
if (!Number.isSafeInteger(feeCap) || feeCap < 0) throw new Error("Invalid maximum fee");
|
|
2668
2668
|
const balance = Math.floor(await this.wallet.client(target.provider).balance() / 1e3);
|
|
2669
|
-
if (balance < amount) throw new Error(`Not enough in this federation: ${balance.toLocaleString()} sats`);
|
|
2669
|
+
if (balance < amount) throw new Error(`Not enough in this federation: ${balance.toLocaleString("en-US")} sats`);
|
|
2670
2670
|
return {
|
|
2671
2671
|
fee: 0,
|
|
2672
2672
|
prepared: {
|
|
@@ -3429,6 +3429,10 @@ var SparkWallet = class {
|
|
|
3429
3429
|
};
|
|
3430
3430
|
//#endregion
|
|
3431
3431
|
//#region ../browser/src/engine/paymentAdapters/coordinator.ts
|
|
3432
|
+
/** A saved intent as text, to tell whether a reconcile changed it: amounts in bigints and bytes count too. */
|
|
3433
|
+
function snapshot(saved) {
|
|
3434
|
+
return JSON.stringify(saved, (_key, value) => typeof value === "bigint" ? `${value}n` : ArrayBuffer.isView(value) ? Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) : value instanceof ArrayBuffer ? Array.from(new Uint8Array(value)) : value);
|
|
3435
|
+
}
|
|
3432
3436
|
/** Persist-before-spend; a submitted/unknown operation can only be reconciled, never re-executed. */
|
|
3433
3437
|
var PaymentCoordinator = class {
|
|
3434
3438
|
repository;
|
|
@@ -3511,6 +3515,7 @@ var PaymentCoordinator = class {
|
|
|
3511
3515
|
const saved = await this.require(id);
|
|
3512
3516
|
if (!["submitted", "unknown"].includes(saved.review.state)) return saved.review;
|
|
3513
3517
|
if (saved.review.parked) return saved.review;
|
|
3518
|
+
const before = snapshot(saved);
|
|
3514
3519
|
try {
|
|
3515
3520
|
const result = await this.adapter(saved.review.method).reconcile(saved.review, saved.prepared, () => this.repository.put(saved));
|
|
3516
3521
|
saved.review = {
|
|
@@ -3526,6 +3531,9 @@ var PaymentCoordinator = class {
|
|
|
3526
3531
|
error: engineText("couldNotVerify")
|
|
3527
3532
|
};
|
|
3528
3533
|
}
|
|
3534
|
+
const latest = await this.repository.get(id);
|
|
3535
|
+
if (latest && !["submitted", "unknown"].includes(latest.review.state)) return latest.review;
|
|
3536
|
+
if (snapshot(saved) === before) return saved.review;
|
|
3529
3537
|
await this.repository.put(saved);
|
|
3530
3538
|
this.changed(saved.review);
|
|
3531
3539
|
return saved.review;
|
|
@@ -3625,10 +3633,12 @@ var NEVER_REACHED_MINT = "The payment never reached the mint: nothing was sent,
|
|
|
3625
3633
|
var CashuAdapter = class {
|
|
3626
3634
|
wallet;
|
|
3627
3635
|
publish;
|
|
3636
|
+
takingBack;
|
|
3628
3637
|
method = "cashu";
|
|
3629
|
-
constructor(wallet, publish) {
|
|
3638
|
+
constructor(wallet, publish, takingBack = () => void 0) {
|
|
3630
3639
|
this.wallet = wallet;
|
|
3631
3640
|
this.publish = publish;
|
|
3641
|
+
this.takingBack = takingBack;
|
|
3632
3642
|
}
|
|
3633
3643
|
async prepare(target, amount, feeCap) {
|
|
3634
3644
|
if (target.method !== "cashu" || target.network !== (mintNetwork(target.provider) === "testnet" ? "cashu-test" : "bitcoin")) throw new Error("Cashu mint/network mismatch");
|
|
@@ -3657,15 +3667,31 @@ var CashuAdapter = class {
|
|
|
3657
3667
|
* What the mint and this wallet know of a payment whose token went out: paid once the mint reads its ecash spent,
|
|
3658
3668
|
* unless this wallet is the one that spent it, taking the payment back. Asked in that order: ecash taken back while
|
|
3659
3669
|
* the mint was being asked reads spent too. Undefined while the contact has not taken it.
|
|
3670
|
+
* A Take it back of it under way when the mint is asked, or started while it answers, is waited for: its swap makes
|
|
3671
|
+
* the ecash read spent before the ecash is back here. Ended with the ecash back, the payment was taken back; ended
|
|
3672
|
+
* with the mint saying the contact had it first, it is paid; ended any other way, this round's spent read proves
|
|
3673
|
+
* nothing, and the next round asks again (nothing is sent meanwhile). One whose answer from the mint was lost is still
|
|
3674
|
+
* under way while its redeem is written down: asked before whether the ecash is back, which is stored as it ends.
|
|
3660
3675
|
*/
|
|
3661
3676
|
async outcome(review, prepared) {
|
|
3677
|
+
const before = this.takingBack(review.id);
|
|
3662
3678
|
const spent = await this.wallet.reviewedCashuSpent(prepared);
|
|
3663
|
-
|
|
3679
|
+
const reclaim = this.takingBack(review.id) ?? before;
|
|
3680
|
+
const ended = await reclaim;
|
|
3681
|
+
const unsettled = await this.wallet.cashuTakingBack(review.id);
|
|
3682
|
+
const back = await this.takenBack(review.id);
|
|
3683
|
+
if (back) return back;
|
|
3684
|
+
if (unsettled || reclaim && ended !== "settled") return { settled: false };
|
|
3685
|
+
return spent ? { settled: true } : void 0;
|
|
3686
|
+
}
|
|
3687
|
+
/** Taken back, waiting for a Take it back under way first: the payment then ends failed, its sats back here. */
|
|
3688
|
+
async takenBack(id) {
|
|
3689
|
+
await this.takingBack(id);
|
|
3690
|
+
return await this.wallet.reviewedCashuTakenBack(id) ? {
|
|
3664
3691
|
settled: false,
|
|
3665
3692
|
failed: true,
|
|
3666
3693
|
error: engineText("paymentTakenBack")
|
|
3667
|
-
};
|
|
3668
|
-
return spent ? { settled: true } : void 0;
|
|
3694
|
+
} : void 0;
|
|
3669
3695
|
}
|
|
3670
3696
|
/** `persist` saves the intent as it is: required, since the abandon path must be durable before it releases anything. */
|
|
3671
3697
|
async reconcile(review, prepared, persist) {
|
|
@@ -3674,9 +3700,11 @@ var CashuAdapter = class {
|
|
|
3674
3700
|
const known = await this.outcome(review, prepared);
|
|
3675
3701
|
if (known) return known;
|
|
3676
3702
|
const token = prepared.token ?? await this.wallet.recoverReviewedCashu(review, prepared);
|
|
3677
|
-
if (token)
|
|
3678
|
-
|
|
3679
|
-
|
|
3703
|
+
if (token) {
|
|
3704
|
+
await this.publish(review, token);
|
|
3705
|
+
const back = await this.takenBack(review.id);
|
|
3706
|
+
if (back) return back;
|
|
3707
|
+
}
|
|
3680
3708
|
if (!token && Date.now() >= swapSettledAt(review, prepared) && await this.wallet.reviewedCashuNeverSwapped(prepared)) return this.abandon(prepared, persist);
|
|
3681
3709
|
if (!token && await this.wallet.reviewedCashuSpentElsewhere(prepared)) return this.spentElsewhere(prepared, persist);
|
|
3682
3710
|
return { settled: false };
|
|
@@ -4954,7 +4982,7 @@ var FedimintLightning = class {
|
|
|
4954
4982
|
const fee = await this.estimateFee(invoice, amount);
|
|
4955
4983
|
if (fee > maxFee) throw new Error(`The gateway's fee (${fee} sats) is above your maximum`);
|
|
4956
4984
|
const balance = Math.floor(await this.client().balance() / 1e3);
|
|
4957
|
-
if (balance < amount + fee) throw new Error(`Not enough in this federation (${balance.toLocaleString()} sats; ${(amount + fee).toLocaleString()} needed)`);
|
|
4985
|
+
if (balance < amount + fee) throw new Error(`Not enough in this federation (${balance.toLocaleString("en-US")} sats; ${(amount + fee).toLocaleString("en-US")} needed)`);
|
|
4958
4986
|
} catch (error) {
|
|
4959
4987
|
throw isNothingSpentError(error) ? error : new NothingSpentError(message$2(error));
|
|
4960
4988
|
}
|
|
@@ -9234,7 +9262,7 @@ var HostNotContacted = class extends Error {};
|
|
|
9234
9262
|
*/
|
|
9235
9263
|
function fixedHostsFetch(fetch) {
|
|
9236
9264
|
return async (url, options) => {
|
|
9237
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
9265
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-CN3CsslV.js");
|
|
9238
9266
|
const host = hostOf$1(url);
|
|
9239
9267
|
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`);
|
|
9240
9268
|
return fetch(url, options);
|
|
@@ -11099,6 +11127,8 @@ function readCount(value) {
|
|
|
11099
11127
|
return null;
|
|
11100
11128
|
}
|
|
11101
11129
|
}
|
|
11130
|
+
/** What a staged bundle is kept under (`AppPreview.stage`): one install screen's version and source, so another screen of it does not change it. */
|
|
11131
|
+
var stagedKey = (digest, from, store) => `${digest}\n${from}\n${store ?? ""}`;
|
|
11102
11132
|
/**
|
|
11103
11133
|
* `run` on every item, at most `limit` at a time (the next one starts when one ends): one promise per item, in the
|
|
11104
11134
|
* items' order, whatever order they end in.
|
|
@@ -11433,7 +11463,10 @@ var Apps = class {
|
|
|
11433
11463
|
/** Drops `previewed` past `STAGED.ms`: an index is up to 4 MiB, and a closed Add screen sends no call. */
|
|
11434
11464
|
previewedSweep = null;
|
|
11435
11465
|
checking = null;
|
|
11436
|
-
/**
|
|
11466
|
+
/**
|
|
11467
|
+
* Runs the person started with Run anyway (`<ref> <digest>`): a removal does not cut them off. Only that run's: dropped
|
|
11468
|
+
* when the version starts without it, when a call finds it no longer removed, and at Uninstall.
|
|
11469
|
+
*/
|
|
11437
11470
|
anyway = /* @__PURE__ */ new Set();
|
|
11438
11471
|
/** The apps started here (`entry`), for this engine's life: one of them uninstalled since may still have a frame open. */
|
|
11439
11472
|
ran = /* @__PURE__ */ new Set();
|
|
@@ -11628,6 +11661,7 @@ var Apps = class {
|
|
|
11628
11661
|
const version = this.versionRunning(app, digest);
|
|
11629
11662
|
const run = this.runStatus(version, await this.heldViews(), app.revocations);
|
|
11630
11663
|
if (run.status === "revoked") fail("stopped", "Its publisher revoked this version");
|
|
11664
|
+
if (run.status === "ok") this.anyway.delete(`${version.ref} ${version.digest}`);
|
|
11631
11665
|
if (run.status === "removed" && !this.anyway.has(`${version.ref} ${version.digest}`)) fail("stopped", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
11632
11666
|
return app;
|
|
11633
11667
|
}
|
|
@@ -11675,9 +11709,15 @@ var Apps = class {
|
|
|
11675
11709
|
if (!app && this.ran.has(ref)) fail("not-installed", "This app is not installed");
|
|
11676
11710
|
if (app) await this.stillRunnable(app, digest);
|
|
11677
11711
|
}
|
|
11712
|
+
/** Writes an app's record, keeping the revocations the record holds now (one kept since the caller read it among them). */
|
|
11678
11713
|
async putApp(app) {
|
|
11714
|
+
const tx = (await openDb()).transaction(STORES$1.apps, "readwrite");
|
|
11715
|
+
const read = tx.objectStore(STORES$1.apps).get(app.ref);
|
|
11716
|
+
read.onsuccess = () => {
|
|
11717
|
+
tx.objectStore(STORES$1.apps).put(withRevocations(app, read.result?.revocations ?? []));
|
|
11718
|
+
};
|
|
11679
11719
|
try {
|
|
11680
|
-
await
|
|
11720
|
+
await done(tx);
|
|
11681
11721
|
} finally {
|
|
11682
11722
|
this.held.delete(app.ref);
|
|
11683
11723
|
}
|
|
@@ -11687,7 +11727,8 @@ var Apps = class {
|
|
|
11687
11727
|
* transaction: an app uninstalled (or installed again) while the update check was reading is not put back, nor is the
|
|
11688
11728
|
* version it read over an update the person accepted meanwhile. `was` undefined: only while the app has no record.
|
|
11689
11729
|
* A store removed since the caller read the stores pins nothing: it is judged at the write, as `removeStore` unpins
|
|
11690
|
-
* only the records written before it.
|
|
11730
|
+
* only the records written before it. A revocation the record gained since `was` (`keepStoreRevocations`) is kept:
|
|
11731
|
+
* one `app` leaves out on purpose (the check's, of a version gone) was on `was` already.
|
|
11691
11732
|
*/
|
|
11692
11733
|
async putAppIfUnchanged(app, was) {
|
|
11693
11734
|
const stores = await this.records();
|
|
@@ -11695,7 +11736,10 @@ var Apps = class {
|
|
|
11695
11736
|
let put = false;
|
|
11696
11737
|
const read = tx.objectStore(STORES$1.apps).get(app.ref);
|
|
11697
11738
|
read.onsuccess = () => {
|
|
11698
|
-
|
|
11739
|
+
const now = read.result;
|
|
11740
|
+
if (!sameRecord(now, was)) return;
|
|
11741
|
+
const had = new Set((was?.revocations ?? []).map((r) => canonicalJson(r)));
|
|
11742
|
+
app = withRevocations(app, (now?.revocations ?? []).filter((r) => !had.has(canonicalJson(r))));
|
|
11699
11743
|
const { store: pin, ...unpinned } = app;
|
|
11700
11744
|
tx.objectStore(STORES$1.apps).put(pin !== void 0 && stores.get(pin)?.removed ? unpinned : app);
|
|
11701
11745
|
put = true;
|
|
@@ -11748,9 +11792,10 @@ var Apps = class {
|
|
|
11748
11792
|
async keepStoreRevocations(record) {
|
|
11749
11793
|
const revoked = record.index?.revoked ?? [];
|
|
11750
11794
|
if (!revoked.length) return;
|
|
11751
|
-
|
|
11795
|
+
const reread = async (ref) => wrap((await store(STORES$1.apps, "readonly")).get(ref));
|
|
11796
|
+
for (const first of await this.installed()) for (let app = first; app; app = await reread(first.ref)) {
|
|
11752
11797
|
const next = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11753
|
-
if ((next.revocations?.length ?? 0)
|
|
11798
|
+
if ((next.revocations?.length ?? 0) <= (app.revocations?.length ?? 0) || await this.putAppIfUnchanged(next, app)) break;
|
|
11754
11799
|
}
|
|
11755
11800
|
}
|
|
11756
11801
|
/** The stores' views, made once and again after a store is written here: an app's every storage call and chat frame checks them. */
|
|
@@ -12164,6 +12209,14 @@ var Apps = class {
|
|
|
12164
12209
|
digest
|
|
12165
12210
|
}) === "equivocation";
|
|
12166
12211
|
if (other && held.equivocation?.digest !== digest) await this.putStore(this.withIndex(held, index, digest));
|
|
12212
|
+
const seen = held?.removed && held.seen && appStoreDecision({
|
|
12213
|
+
key: held.key,
|
|
12214
|
+
...held.seen
|
|
12215
|
+
}, {
|
|
12216
|
+
key: index.key,
|
|
12217
|
+
sequence: index.sequence,
|
|
12218
|
+
digest
|
|
12219
|
+
});
|
|
12167
12220
|
return {
|
|
12168
12221
|
url: at,
|
|
12169
12222
|
key: index.key,
|
|
@@ -12178,7 +12231,8 @@ var Apps = class {
|
|
|
12178
12231
|
...held && !held.removed && { held: held.index ? {
|
|
12179
12232
|
sequence: held.index.sequence,
|
|
12180
12233
|
...other && { equivocation: true }
|
|
12181
|
-
} : {} }
|
|
12234
|
+
} : {} },
|
|
12235
|
+
...(seen === "rollback" || seen === "equivocation") && { refused: seen }
|
|
12182
12236
|
};
|
|
12183
12237
|
}
|
|
12184
12238
|
/**
|
|
@@ -12448,10 +12502,10 @@ var Apps = class {
|
|
|
12448
12502
|
};
|
|
12449
12503
|
} else fail("bad-source", "No app to fetch");
|
|
12450
12504
|
if (!urls.length) fail("host", "This listing has no URL Ghostly reads from");
|
|
12451
|
-
const kept = expect?.digest !== void 0 ? this.staged.get(expect.digest) : void 0;
|
|
12452
12505
|
let last = null;
|
|
12453
12506
|
for (const url of urls) try {
|
|
12454
|
-
const
|
|
12507
|
+
const kept = expect?.digest !== void 0 ? this.staged.get(stagedKey(expect.digest, url, fromStore)) : void 0;
|
|
12508
|
+
const { bundle, bytes } = kept && this.now() - kept.at <= STAGED.ms ? kept : await this.fetchBundle(url);
|
|
12455
12509
|
const version = versionOf(bundle.manifest, bundle.digest);
|
|
12456
12510
|
if (expect) {
|
|
12457
12511
|
if (version.ref !== expect.ref) fail("other-app", "The URL holds another app");
|
|
@@ -12468,7 +12522,7 @@ var Apps = class {
|
|
|
12468
12522
|
/** Drops the staged bundles past `STAGED.ms`, and comes back when the oldest left is due. */
|
|
12469
12523
|
sweepStaged() {
|
|
12470
12524
|
this.sweep = null;
|
|
12471
|
-
for (const [
|
|
12525
|
+
for (const [key, s] of this.staged) if (this.now() - s.at >= STAGED.ms) this.staged.delete(key);
|
|
12472
12526
|
const oldest = this.staged.values().next().value;
|
|
12473
12527
|
if (oldest) this.sweep = setTimeout(() => this.sweepStaged(), STAGED.ms - (this.now() - oldest.at));
|
|
12474
12528
|
}
|
|
@@ -12488,9 +12542,10 @@ var Apps = class {
|
|
|
12488
12542
|
const install = decision === "other-app" ? "new" : decision;
|
|
12489
12543
|
const asks = install === "new" ? [...manifest.permissions] : install === "update" ? manifest.permissions.filter((p) => !installed.permissions.includes(p)) : [];
|
|
12490
12544
|
for (const [d, s] of this.staged) if (this.now() - s.at > STAGED.ms) this.staged.delete(d);
|
|
12491
|
-
|
|
12545
|
+
const stage = stagedKey(digest, from, fromStore);
|
|
12546
|
+
this.staged.delete(stage);
|
|
12492
12547
|
while (this.staged.size >= STAGED.max) this.staged.delete(this.staged.keys().next().value);
|
|
12493
|
-
this.staged.set(
|
|
12548
|
+
this.staged.set(stage, {
|
|
12494
12549
|
bundle,
|
|
12495
12550
|
bytes,
|
|
12496
12551
|
from,
|
|
@@ -12514,7 +12569,8 @@ var Apps = class {
|
|
|
12514
12569
|
run: this.runStatus(version, this.storeViews(stores), [...installed?.revocations ?? [], ...revocations]),
|
|
12515
12570
|
listedBy,
|
|
12516
12571
|
unknownPublisher: !listedBy.some((s) => s.kind === "curated"),
|
|
12517
|
-
...carried && { carried: true }
|
|
12572
|
+
...carried && { carried: true },
|
|
12573
|
+
stage
|
|
12518
12574
|
};
|
|
12519
12575
|
}
|
|
12520
12576
|
/**
|
|
@@ -12522,12 +12578,16 @@ var Apps = class {
|
|
|
12522
12578
|
* for (WISP 1200 § Permissions: none is granted by a store or a contact). A revoked or removed version is not
|
|
12523
12579
|
* installed; neither is a rollback, nor another bundle under an installed `sequence` (marked on the app). `asks` is
|
|
12524
12580
|
* what the person's screen listed (`AppPreview.asks`; the last screen of this bundle when not given): what this install
|
|
12525
|
-
* adds to the record it writes over must be among it, else the screen is shown again first.
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12581
|
+
* adds to the record it writes over must be among it, else the screen is shown again first. `stage` is the screen's
|
|
12582
|
+
* (`AppPreview.stage`): it installs from that screen's source and store; without it, only while one source of the
|
|
12583
|
+
* bundle waits.
|
|
12584
|
+
*/
|
|
12585
|
+
async install({ stage, digest, grant, asks }) {
|
|
12586
|
+
const live = [...this.staged].filter(([key, s]) => s.bundle.digest === digest && (stage === void 0 || key === stage) && this.now() - s.at <= STAGED.ms);
|
|
12587
|
+
if (live.length > 1) fail("screens", "This app was fetched from more than one place; install it from its screen");
|
|
12588
|
+
const [key, staged] = live[0] ?? [stage ?? ""];
|
|
12589
|
+
if (!staged) {
|
|
12590
|
+
this.staged.delete(key);
|
|
12531
12591
|
fail("expired", "Fetch the app again");
|
|
12532
12592
|
}
|
|
12533
12593
|
const { bundle, bytes, from, store: fromStore, revocations } = staged;
|
|
@@ -12578,7 +12638,7 @@ var Apps = class {
|
|
|
12578
12638
|
}, installed)) continue;
|
|
12579
12639
|
if (pin && pending) await this.removeBundle(pending.bytes, pending.digest);
|
|
12580
12640
|
}
|
|
12581
|
-
this.staged.delete(
|
|
12641
|
+
this.staged.delete(key);
|
|
12582
12642
|
return this.view(await this.app(version.ref), stores);
|
|
12583
12643
|
}
|
|
12584
12644
|
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
@@ -12587,7 +12647,7 @@ var Apps = class {
|
|
|
12587
12647
|
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
12588
12648
|
if (installed && installed.digest !== digest) await this.removeBundle(installed.bytes, installed.digest);
|
|
12589
12649
|
if (installed?.pending && next.pending?.digest !== installed.pending.digest && installed.pending.digest !== digest) await this.removeBundle(installed.pending.bytes, installed.pending.digest);
|
|
12590
|
-
this.staged.delete(
|
|
12650
|
+
this.staged.delete(key);
|
|
12591
12651
|
return this.view(next, stores);
|
|
12592
12652
|
}
|
|
12593
12653
|
} catch (error) {
|
|
@@ -12627,10 +12687,16 @@ var Apps = class {
|
|
|
12627
12687
|
...installed?.checkedAt !== void 0 && { checkedAt: installed.checkedAt }
|
|
12628
12688
|
};
|
|
12629
12689
|
}
|
|
12630
|
-
/**
|
|
12631
|
-
|
|
12690
|
+
/**
|
|
12691
|
+
* The person accepted the permissions a waiting update adds: it is installed now. `sequence` and `added` are the
|
|
12692
|
+
* waiting update its screen listed (`InstalledAppView.pending`): another one waiting now (the check found a newer one
|
|
12693
|
+
* after the screen was drawn), or one that adds more than `added`, is refused with `permissions-changed`.
|
|
12694
|
+
*/
|
|
12695
|
+
async acceptUpdate({ ref, sequence, added: shown }) {
|
|
12696
|
+
if (shown !== void 0 && !Array.isArray(shown)) fail("permissions", "The permissions shown must be a list");
|
|
12632
12697
|
const installed = await this.installedOrFail(ref);
|
|
12633
12698
|
const pending = installed.pending ?? fail("no-update", "No update waits for this app");
|
|
12699
|
+
if (sequence !== void 0 && pending.sequence !== sequence) fail("permissions-changed", `Another update waits now, which adds ${pending.added.length ? pending.added.join(", ") : "no permission"}; look at it again`);
|
|
12634
12700
|
const bytes = await this.readBundleBytes(pending.bytes, pending.digest);
|
|
12635
12701
|
const read = bytes ? await readAppBundleAsync(bytes) : null;
|
|
12636
12702
|
if (!read?.ok || read.bundle.digest !== pending.digest) {
|
|
@@ -12659,6 +12725,7 @@ var Apps = class {
|
|
|
12659
12725
|
});
|
|
12660
12726
|
fail("permissions-changed", `This update now adds ${added.length ? added.join(", ") : "no permission"}; look at it again`);
|
|
12661
12727
|
}
|
|
12728
|
+
if (shown && added.some((p) => !shown.includes(p))) fail("permissions-changed", `This update now adds ${added.join(", ")}; look at it again`);
|
|
12662
12729
|
const { pending: _p, ...without } = installed;
|
|
12663
12730
|
const next = this.versionRecord(without, read.bundle, pending.bytes, pending.from, installed.store);
|
|
12664
12731
|
if (!await this.putAppIfUnchanged(next, installed)) {
|
|
@@ -12965,13 +13032,15 @@ var Apps = class {
|
|
|
12965
13032
|
let app = await this.installedOrFail(ref);
|
|
12966
13033
|
let run = await this.runCheckOf(app, await this.stores());
|
|
12967
13034
|
if (run.status === "needs-files") {
|
|
12968
|
-
|
|
13035
|
+
await this.fetchFiles({ ref });
|
|
12969
13036
|
app = await this.installedOrFail(ref);
|
|
13037
|
+
run = await this.runCheckOf(app, await this.stores());
|
|
12970
13038
|
}
|
|
12971
13039
|
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
12972
13040
|
if (run.status === "removed" && runAnyway !== true) fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
12973
13041
|
if (run.status === "needs-files") fail("needs-files", "This app's files are not on this device yet");
|
|
12974
13042
|
if (run.status === "removed") this.anyway.add(`${app.ref} ${app.digest}`);
|
|
13043
|
+
else this.anyway.delete(`${app.ref} ${app.digest}`);
|
|
12975
13044
|
const bundle = await this.verifiedBundle(app, true);
|
|
12976
13045
|
const entry = bundle.files.get(bundle.manifest.entry) ?? fail("damaged", "The entry is missing");
|
|
12977
13046
|
this.ran.add(app.ref);
|
|
@@ -13102,6 +13171,7 @@ var Apps = class {
|
|
|
13102
13171
|
}
|
|
13103
13172
|
for (const key of [...this.usage.keys()]) if (key.startsWith(`${ref}\0`)) this.usage.delete(key);
|
|
13104
13173
|
this.started.delete(ref);
|
|
13174
|
+
for (const key of [...this.anyway]) if (key.startsWith(`${ref} `)) this.anyway.delete(key);
|
|
13105
13175
|
if (!app) return;
|
|
13106
13176
|
await this.removeBundle(app.bytes, app.digest);
|
|
13107
13177
|
if (app.pending) await this.removeBundle(app.pending.bytes, app.pending.digest);
|
|
@@ -14733,25 +14803,9 @@ function storedActiveListed(record, tombstone) {
|
|
|
14733
14803
|
return listedIn(tombstone, active);
|
|
14734
14804
|
}
|
|
14735
14805
|
var listedIn = (record, key) => record.slots.some((slot) => !!slot && toBase64Url(slot.key) === key);
|
|
14736
|
-
/**
|
|
14737
|
-
|
|
14738
|
-
|
|
14739
|
-
* a release that the stored active device signed (WISP 06 § Record: a release names its taker). Null when it has none.
|
|
14740
|
-
*/
|
|
14741
|
-
function believed(record, oldKeys, by, rec) {
|
|
14742
|
-
const stored = record.activeSlot === void 0 || record.activeSlot === record.ownSlot ? void 0 : record.deviceSet[record.activeSlot]?.key;
|
|
14743
|
-
if (!stored) return null;
|
|
14744
|
-
if (by === stored || !rec) return stored;
|
|
14745
|
-
const carried = readTurnPacket(oldKeys, rec);
|
|
14746
|
-
if (carried.kind !== "valid" || carried.record.tombstone) return stored;
|
|
14747
|
-
const r = carried.record;
|
|
14748
|
-
const author = r.slots[r.author], release = r.release;
|
|
14749
|
-
if (!author || toBase64Url(author.key) !== by || !release || release.from === release.to) return stored;
|
|
14750
|
-
if (toBase64Url(r.slots[release.from].key) !== stored) return stored;
|
|
14751
|
-
const held = record.turnPacket ? readTurnPacket(oldKeys, fromBase64Url(record.turnPacket)) : null;
|
|
14752
|
-
if (held?.kind === "valid" && carried.sequence <= held.sequence) return stored;
|
|
14753
|
-
if (held?.kind !== "valid" && r.turn <= record.turn) return stored;
|
|
14754
|
-
return by;
|
|
14806
|
+
/** The device this device believes for a `set-update`: its stored active device. Null when it has none, or is it. */
|
|
14807
|
+
function believed$1(record) {
|
|
14808
|
+
return record.activeSlot === void 0 || record.activeSlot === record.ownSlot ? null : record.deviceSet[record.activeSlot]?.key ?? null;
|
|
14755
14809
|
}
|
|
14756
14810
|
/** The rule above, for `frame` reaching a device whose record is `record`. `now`: when, for the notice. */
|
|
14757
14811
|
function checkSetUpdate(record, frame, now) {
|
|
@@ -14772,7 +14826,7 @@ function checkSetUpdate(record, frame, now) {
|
|
|
14772
14826
|
const tomb = read.record;
|
|
14773
14827
|
if (!verifySetUpdate(update, oldKeys.address)) return refuse("signature");
|
|
14774
14828
|
const by = toBase64Url(update.by);
|
|
14775
|
-
const active = believed(record
|
|
14829
|
+
const active = believed$1(record);
|
|
14776
14830
|
if (!listedIn(tomb, own)) return active && by === active ? refuse("removed") : refuse("signer");
|
|
14777
14831
|
if (!active || by !== active) return refuse("signer", record.activeSlot !== record.ownSlot);
|
|
14778
14832
|
if (!listedIn(tomb, active)) return refuse("unlisted", true);
|
|
@@ -16012,7 +16066,7 @@ var EnrollInviter = class extends Enrollment {
|
|
|
16012
16066
|
}
|
|
16013
16067
|
this.crash("inviter:after-put");
|
|
16014
16068
|
const published = await confirmPublished(keeper, this.sleep);
|
|
16015
|
-
await this.options.afterWrite?.().catch(() => {});
|
|
16069
|
+
await this.options.afterWrite?.(toBase64Url(joiner.key)).catch(() => {});
|
|
16016
16070
|
await this.end({
|
|
16017
16071
|
role: "inviter",
|
|
16018
16072
|
step: "done",
|
|
@@ -16119,7 +16173,8 @@ var EnrollJoiner = class extends Enrollment {
|
|
|
16119
16173
|
return;
|
|
16120
16174
|
}
|
|
16121
16175
|
this.proven = true;
|
|
16122
|
-
const
|
|
16176
|
+
const left = Math.min(Math.max(0, this.invite.invite.expires * 1e3 - this.now()), 6e5);
|
|
16177
|
+
const grantMs = this.options.timing?.grantMs ?? left + 6e4;
|
|
16123
16178
|
this.timer(grantMs, () => {
|
|
16124
16179
|
if (!this.committed && this.view.step === "confirm") this.fail("unanswered", "failed");
|
|
16125
16180
|
});
|
|
@@ -16795,11 +16850,9 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16795
16850
|
turn,
|
|
16796
16851
|
rev: FIRST_REV
|
|
16797
16852
|
};
|
|
16798
|
-
const rec = record.turnPacket ? fromBase64Url(record.turnPacket) : void 0;
|
|
16799
16853
|
const frame = await setUpdateFrame(oldKeys.address, {
|
|
16800
16854
|
...update,
|
|
16801
|
-
tomb
|
|
16802
|
-
...rec ? { rec } : {}
|
|
16855
|
+
tomb
|
|
16803
16856
|
}, signer);
|
|
16804
16857
|
const staying = (keys) => keys.filter((key) => key !== own.key && slots.some((slot) => slot?.key === key));
|
|
16805
16858
|
const earlier = [];
|
|
@@ -16816,11 +16869,6 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16816
16869
|
});
|
|
16817
16870
|
continue;
|
|
16818
16871
|
}
|
|
16819
|
-
let oldRec;
|
|
16820
|
-
try {
|
|
16821
|
-
const was = JSON.parse(set.setUpdate);
|
|
16822
|
-
if (typeof was.rec === "string") oldRec = fromBase64Url(was.rec);
|
|
16823
|
-
} catch {}
|
|
16824
16872
|
const setKeys = turnKeys(fromBase64Url(set.d)), tombBytes = fromBase64Url(set.tombstone);
|
|
16825
16873
|
const oldTomb = readTurnPacket(setKeys, tombBytes);
|
|
16826
16874
|
const kept = oldTomb.kind === "valid" ? turnSlots.map((slot, i) => {
|
|
@@ -16830,8 +16878,7 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16830
16878
|
const setUpdate = pending.length ? JSON.stringify(await setUpdateFrame(setKeys.address, {
|
|
16831
16879
|
...update,
|
|
16832
16880
|
set: kept,
|
|
16833
|
-
tomb: tombBytes
|
|
16834
|
-
...oldRec ? { rec: oldRec } : {}
|
|
16881
|
+
tomb: tombBytes
|
|
16835
16882
|
}, signer)) : set.setUpdate;
|
|
16836
16883
|
earlier.push({
|
|
16837
16884
|
...set,
|
|
@@ -17663,10 +17710,21 @@ var DeviceLinks = class {
|
|
|
17663
17710
|
/** A hint came inside `TURN_HINT_EVERY_MS` of the last read, and a read is due at its end. */
|
|
17664
17711
|
hintDeferred = false;
|
|
17665
17712
|
timers = /* @__PURE__ */ new Set();
|
|
17713
|
+
/** When this device added each device it enrolled in this run, by signing key (`expectDevice`). */
|
|
17714
|
+
added = /* @__PURE__ */ new Map();
|
|
17666
17715
|
constructor(options) {
|
|
17667
17716
|
this.options = options;
|
|
17668
17717
|
this.createPeerConnection = "createPeerConnection" in options ? options.createPeerConnection : defaultPeerConnection();
|
|
17669
17718
|
}
|
|
17719
|
+
/**
|
|
17720
|
+
* This device just added the device of signing key `key` (an enrollment's record was written): its link, opened by the
|
|
17721
|
+
* next `refresh`, awaits it as a chat awaits the contact of an invite just sent (`AWAITING_PEER_MS`). The new device
|
|
17722
|
+
* starts into its standby screen only once the person taps Continue there, after the link's first read: read at the
|
|
17723
|
+
* background pace from then, it went live about 30 s after it started (bug hunt, 2026-11-06).
|
|
17724
|
+
*/
|
|
17725
|
+
expectDevice(key) {
|
|
17726
|
+
this.added.set(key, Date.now());
|
|
17727
|
+
}
|
|
17670
17728
|
/** `host` is the device-link-only server's: it is told when what the standby screen shows changes. */
|
|
17671
17729
|
async start(host) {
|
|
17672
17730
|
this.host = host ?? null;
|
|
@@ -17818,17 +17876,27 @@ var DeviceLinks = class {
|
|
|
17818
17876
|
earlier: false
|
|
17819
17877
|
});
|
|
17820
17878
|
});
|
|
17821
|
-
|
|
17822
|
-
|
|
17823
|
-
|
|
17824
|
-
|
|
17825
|
-
|
|
17826
|
-
id
|
|
17827
|
-
|
|
17828
|
-
|
|
17829
|
-
|
|
17830
|
-
|
|
17831
|
-
|
|
17879
|
+
const pendingFor = (key, d) => record.earlierSets.find((set) => set.d !== record.d && (d === void 0 || set.d === d) && set.pending.includes(key));
|
|
17880
|
+
for (const staying of record.deviceSet) {
|
|
17881
|
+
if (!staying || staying.key === own) continue;
|
|
17882
|
+
const key = staying.key;
|
|
17883
|
+
for (let set = pendingFor(key); set;) {
|
|
17884
|
+
const id = `${set.d}|${key}`;
|
|
17885
|
+
if (wanted.some((w) => w.id === id)) break;
|
|
17886
|
+
wanted.push({
|
|
17887
|
+
id,
|
|
17888
|
+
d: fromBase64Url(set.d),
|
|
17889
|
+
key,
|
|
17890
|
+
name: staying.name,
|
|
17891
|
+
earlier: true
|
|
17892
|
+
});
|
|
17893
|
+
let next;
|
|
17894
|
+
try {
|
|
17895
|
+
const update = readSetUpdate(JSON.parse(set.setUpdate));
|
|
17896
|
+
if (update) next = toBase64Url(update.d);
|
|
17897
|
+
} catch {}
|
|
17898
|
+
set = next === void 0 ? void 0 : pendingFor(key, next);
|
|
17899
|
+
}
|
|
17832
17900
|
}
|
|
17833
17901
|
return wanted;
|
|
17834
17902
|
}
|
|
@@ -17859,7 +17927,7 @@ var DeviceLinks = class {
|
|
|
17859
17927
|
packetTransports: true,
|
|
17860
17928
|
transport: this.options.transport,
|
|
17861
17929
|
pollIntervals: this.options.pollIntervals,
|
|
17862
|
-
madeAt: 0,
|
|
17930
|
+
madeAt: want.earlier ? 0 : this.added.get(want.key) ?? 0,
|
|
17863
17931
|
autoConnect: true,
|
|
17864
17932
|
createPeerConnection: () => {
|
|
17865
17933
|
if (!this.createPeerConnection) throw new ReferenceError("RTCPeerConnection is not defined");
|
|
@@ -18917,6 +18985,8 @@ var HandoffGiver = class {
|
|
|
18917
18985
|
failure;
|
|
18918
18986
|
/** What a failure about one wallet names. */
|
|
18919
18987
|
failed = {};
|
|
18988
|
+
/** The wrong password (`failure: "password"`) left that device refused. */
|
|
18989
|
+
refused = false;
|
|
18920
18990
|
stays = [];
|
|
18921
18991
|
retry;
|
|
18922
18992
|
newer = false;
|
|
@@ -18983,6 +19053,7 @@ var HandoffGiver = class {
|
|
|
18983
19053
|
total: 0,
|
|
18984
19054
|
failure: this.failure,
|
|
18985
19055
|
...this.retry ? { retry: this.retry } : {},
|
|
19056
|
+
...this.refused && this.failure === "password" ? { refused: true } : {},
|
|
18986
19057
|
...this.failedDetail()
|
|
18987
19058
|
} : null;
|
|
18988
19059
|
const confirmed = [...this.sender.confirmed.values()].reduce((a, b) => a + b, 0);
|
|
@@ -19051,6 +19122,7 @@ var HandoffGiver = class {
|
|
|
19051
19122
|
const record = await this.ports.records.read();
|
|
19052
19123
|
if (!record || record.state !== "active") throw new Error("handoff-refused: Only the active device moves the profile.");
|
|
19053
19124
|
if (slotOf(record, key) < 0) throw new Error("handoff-refused: That device is not one of this profile's.");
|
|
19125
|
+
if (this.ports.setChanging?.()) throw new Error("handoff-busy: Another move is in progress.");
|
|
19054
19126
|
const busy = reportOf(await this.ports.busy(this.takerFacts(key)));
|
|
19055
19127
|
if (busy) throw new Error(`handoff-${busy.why}:${busy.wallet ? `${busy.wallet}:` : ""} This device cannot move the profile now.`);
|
|
19056
19128
|
if (!this.ports.links.live(key)) {
|
|
@@ -19093,12 +19165,21 @@ var HandoffGiver = class {
|
|
|
19093
19165
|
this.reset("cancelled");
|
|
19094
19166
|
});
|
|
19095
19167
|
}
|
|
19096
|
-
/**
|
|
19097
|
-
|
|
19098
|
-
|
|
19099
|
-
|
|
19100
|
-
|
|
19101
|
-
|
|
19168
|
+
/**
|
|
19169
|
+
* "Let <device> try again": the count of wrong passwords of that device starts again. The wrong password it was
|
|
19170
|
+
* offered for is answered: the screen shows it no more (it stayed, and the press looked like it did nothing).
|
|
19171
|
+
*/
|
|
19172
|
+
allowAgain(key) {
|
|
19173
|
+
return this.exclusive(async () => {
|
|
19174
|
+
const record = await this.ports.records.read();
|
|
19175
|
+
if (record?.handoffAttempts?.[key]) {
|
|
19176
|
+
const { [key]: _, ...rest } = record.handoffAttempts;
|
|
19177
|
+
await this.ports.records.amend({ handoffAttempts: rest });
|
|
19178
|
+
}
|
|
19179
|
+
if (this.phase !== "idle" || this.peer !== key || this.failure !== "password") return;
|
|
19180
|
+
this.failure = void 0;
|
|
19181
|
+
this.changed();
|
|
19182
|
+
});
|
|
19102
19183
|
}
|
|
19103
19184
|
/** The link to `key` opened (a new session) or closed. */
|
|
19104
19185
|
linkChanged(key, live) {
|
|
@@ -19106,7 +19187,7 @@ var HandoffGiver = class {
|
|
|
19106
19187
|
if (key !== this.peer) return;
|
|
19107
19188
|
if (!live) {
|
|
19108
19189
|
this.sender.stop();
|
|
19109
|
-
if (this.phase === "authorizing") this.
|
|
19190
|
+
if (this.phase === "authorizing") await this.unproved(key);
|
|
19110
19191
|
if (this.phase === "pass2") this.arm(HANDOFF_TIMINGS.idleMs, () => this.backToActive());
|
|
19111
19192
|
this.changed();
|
|
19112
19193
|
return;
|
|
@@ -19248,6 +19329,7 @@ var HandoffGiver = class {
|
|
|
19248
19329
|
if (slotOf(record, from) < 0) return busy("refused", 0);
|
|
19249
19330
|
const pushed = this.phase === "offered" && from === this.peer && request.id === this.id;
|
|
19250
19331
|
if (this.phase !== "idle" && this.phase !== "failed" && !pushed) return busy("handoff");
|
|
19332
|
+
if (this.ports.setChanging?.()) return busy("handoff");
|
|
19251
19333
|
const session = this.sessionFor(from);
|
|
19252
19334
|
if (!session?.peer) return busy("handoff", 5);
|
|
19253
19335
|
const local = reportOf(await this.ports.busy(this.takerFacts(from)));
|
|
@@ -19265,6 +19347,14 @@ var HandoffGiver = class {
|
|
|
19265
19347
|
if (versions.older) return busy("older", 0);
|
|
19266
19348
|
if (!pushed) {
|
|
19267
19349
|
const allowed = handoffAttemptAllowed(record.handoffAttempts?.[from], this.now());
|
|
19350
|
+
if (allowed === "refused") {
|
|
19351
|
+
this.peer = from;
|
|
19352
|
+
this.deviceName = name(record, from);
|
|
19353
|
+
this.failure = "password";
|
|
19354
|
+
this.failed = {};
|
|
19355
|
+
this.refused = true;
|
|
19356
|
+
this.changed();
|
|
19357
|
+
}
|
|
19268
19358
|
if (allowed !== "ok") return busy(allowed, allowed === "refused" ? 0 : handoffRetryAfter(record.handoffAttempts?.[from], this.now()));
|
|
19269
19359
|
await this.ports.records.amend({ handoffAttempts: {
|
|
19270
19360
|
...setAttempts(record, record.handoffAttempts),
|
|
@@ -19297,21 +19387,21 @@ var HandoffGiver = class {
|
|
|
19297
19387
|
try {
|
|
19298
19388
|
this.pake = await startPakeGiver(verifier, pake.m);
|
|
19299
19389
|
} catch {
|
|
19300
|
-
this.wrongPassword(from);
|
|
19390
|
+
await this.wrongPassword(from);
|
|
19301
19391
|
return;
|
|
19302
19392
|
}
|
|
19303
19393
|
this.out(handoffPakeFrame({
|
|
19304
19394
|
n: 2,
|
|
19305
19395
|
m: this.pake.second
|
|
19306
19396
|
}), from);
|
|
19307
|
-
this.arm(HANDOFF_TIMINGS.idleMs, () => this.
|
|
19397
|
+
this.arm(HANDOFF_TIMINGS.idleMs, () => this.unproved(from));
|
|
19308
19398
|
return;
|
|
19309
19399
|
}
|
|
19310
19400
|
if (pake.n !== 3 || !this.pake) return;
|
|
19311
19401
|
const giver = this.pake;
|
|
19312
19402
|
this.pake = null;
|
|
19313
19403
|
if (pake.wrong) {
|
|
19314
|
-
this.wrongPassword(from);
|
|
19404
|
+
await this.wrongPassword(from);
|
|
19315
19405
|
return;
|
|
19316
19406
|
}
|
|
19317
19407
|
let key;
|
|
@@ -19319,7 +19409,7 @@ var HandoffGiver = class {
|
|
|
19319
19409
|
key = await giver.finish(pake.m, pake.c, handoffContext(this.ports.turnAddress, this.ports.ownKey, fromBase64Url(from), session.transcript));
|
|
19320
19410
|
} catch (error) {
|
|
19321
19411
|
if (error instanceof HandoffPasswordError) {
|
|
19322
|
-
this.wrongPassword(from);
|
|
19412
|
+
await this.wrongPassword(from);
|
|
19323
19413
|
return;
|
|
19324
19414
|
}
|
|
19325
19415
|
throw error;
|
|
@@ -19330,10 +19420,21 @@ var HandoffGiver = class {
|
|
|
19330
19420
|
await this.ports.records.amend({ handoffAttempts: attempts });
|
|
19331
19421
|
this.authorized(session, key);
|
|
19332
19422
|
}
|
|
19333
|
-
wrongPassword(from) {
|
|
19423
|
+
async wrongPassword(from) {
|
|
19334
19424
|
this.out(handoffCancelFrame("password"), from);
|
|
19335
19425
|
this.ports.notice?.("wrong-password", this.deviceName);
|
|
19336
|
-
this.
|
|
19426
|
+
const record = await this.ports.records.read();
|
|
19427
|
+
this.reset("password", handoffAttemptAllowed(record?.handoffAttempts?.[from], this.now()) === "refused");
|
|
19428
|
+
}
|
|
19429
|
+
/**
|
|
19430
|
+
* A pull that ends in `authorizing` with no proof (its link closed, or the minute out). Past the second message the
|
|
19431
|
+
* taker could check its password on it alone, so stopping there is a guess like a wrong password, and said as one;
|
|
19432
|
+
* before it, the move just stopped. The try stays counted either way.
|
|
19433
|
+
*/
|
|
19434
|
+
async unproved(from) {
|
|
19435
|
+
if (this.phase !== "authorizing") return;
|
|
19436
|
+
if (this.pake) await this.wrongPassword(from);
|
|
19437
|
+
else this.reset("dropped");
|
|
19337
19438
|
}
|
|
19338
19439
|
/** The proof held (a pull) or the person agreed (a push): the first session's key, and pass 1. */
|
|
19339
19440
|
authorized(session, k) {
|
|
@@ -19595,7 +19696,7 @@ var HandoffGiver = class {
|
|
|
19595
19696
|
this.offerHellos.clear();
|
|
19596
19697
|
this.sender = new PartSender(this.now);
|
|
19597
19698
|
}
|
|
19598
|
-
reset(failure) {
|
|
19699
|
+
reset(failure, refused = false) {
|
|
19599
19700
|
this.sender.stop();
|
|
19600
19701
|
clearInterval(this.stallTimer);
|
|
19601
19702
|
clearInterval(this.stuckTimer);
|
|
@@ -19603,6 +19704,7 @@ var HandoffGiver = class {
|
|
|
19603
19704
|
if (this.timer) clearTimeout(this.timer);
|
|
19604
19705
|
this.phase = "idle";
|
|
19605
19706
|
this.failure = failure;
|
|
19707
|
+
this.refused = refused;
|
|
19606
19708
|
this.pake = null;
|
|
19607
19709
|
this.have = null;
|
|
19608
19710
|
this.planned = null;
|
|
@@ -20620,6 +20722,11 @@ var ANNOUNCED_FOR_MS = 6048e5;
|
|
|
20620
20722
|
var floorRefusal = (why) => why === "no-room" ? "No room on this device for this file" : why === "too-many" ? "Too many files are waiting here" : "It was refused here";
|
|
20621
20723
|
/** Progress is written to the database at most this often; every change of state is written at once. */
|
|
20622
20724
|
var SAVE_EVERY_MS = 2e3;
|
|
20725
|
+
/**
|
|
20726
|
+
* The clock of a transfer's durations kept in memory (when it last moved, its speed, its last progress write): monotonic,
|
|
20727
|
+
* so the device's clock set back mid-transfer neither hides it stuck nor freezes its speed for as long as the step.
|
|
20728
|
+
*/
|
|
20729
|
+
var elapsed = () => performance.now();
|
|
20623
20730
|
/** A transfer's state the database refused is written again this often, until it goes (`FileDesk.save`). */
|
|
20624
20731
|
var REWRITE_AFTER_MS = 5e3;
|
|
20625
20732
|
/** The views of finished transfers the states carry, the newest (`FileDesk.finished`). */
|
|
@@ -20699,7 +20806,7 @@ var FileDesk = class {
|
|
|
20699
20806
|
if (!transferEnded(file.wire3)) this.restored.add(file.id);
|
|
20700
20807
|
else if (file.wire3.state !== "done" || !unsettled.has(file.id)) this.ended.add(file.id);
|
|
20701
20808
|
if (file.wire3.state === "done") continue;
|
|
20702
|
-
this.deps.transfers.set(file.id, this.view(chat, file.wire3, file.wire3.confirmed, transferStalled(file.wire3,
|
|
20809
|
+
this.deps.transfers.set(file.id, this.view(chat, file.wire3, file.wire3.confirmed, transferStalled(file.wire3, elapsed(), this.restored.has(file.id), elapsed())));
|
|
20703
20810
|
}
|
|
20704
20811
|
chat.files.restore(records);
|
|
20705
20812
|
}
|
|
@@ -20866,7 +20973,7 @@ var FileDesk = class {
|
|
|
20866
20973
|
if (action === "resend" !== out) throw new Error(out ? "A file you sent is sent again, not asked for" : "A file you receive is asked for again, not sent");
|
|
20867
20974
|
const now = out ? chat.files.resend(wireId) : chat.files.request(wireId);
|
|
20868
20975
|
this.restored.delete(fileId);
|
|
20869
|
-
this.moved.set(fileId, { at:
|
|
20976
|
+
this.moved.set(fileId, { at: elapsed() });
|
|
20870
20977
|
const current = chat.files.get(direction, wireId);
|
|
20871
20978
|
if (current) this.show(linkId, chat, current, chat.files.transferred(direction, wireId));
|
|
20872
20979
|
this.deps.changed();
|
|
@@ -21065,7 +21172,7 @@ var FileDesk = class {
|
|
|
21065
21172
|
wire: fileWire("files/3", file.size)
|
|
21066
21173
|
}
|
|
21067
21174
|
});
|
|
21068
|
-
}).catch(() =>
|
|
21175
|
+
}).catch((error) => this.unkept(linkId, chat, record.id, id, error, said));
|
|
21069
21176
|
}
|
|
21070
21177
|
if (record.direction === "in" && !chat.local.has(record.id)) {
|
|
21071
21178
|
const id = `${linkId}-in-${toBase64Url(randomBytes(12))}`;
|
|
@@ -21117,13 +21224,13 @@ var FileDesk = class {
|
|
|
21117
21224
|
...file.forwarded && { forwarded: file.forwarded },
|
|
21118
21225
|
details: { wire: fileWire("files/3", file.size) }
|
|
21119
21226
|
});
|
|
21120
|
-
}).catch(() =>
|
|
21227
|
+
}).catch((error) => this.unkept(linkId, chat, record.id, id, error));
|
|
21121
21228
|
}
|
|
21122
21229
|
const offered = record.direction === "in" && !this.deps.transfers.has(chat.local.get(record.id));
|
|
21123
21230
|
this.show(linkId, chat, record, transferred, progress);
|
|
21124
21231
|
if (offered) this.deps.flush?.();
|
|
21125
21232
|
const id = record.direction === "out" ? outgoingFileId(linkId, record.id) : chat.local.get(record.id);
|
|
21126
|
-
const now =
|
|
21233
|
+
const now = elapsed(), last = chat.lastSaved.get(id) ?? -Infinity;
|
|
21127
21234
|
if (!progress || now - last >= SAVE_EVERY_MS) this.save(chat, id, record);
|
|
21128
21235
|
else {
|
|
21129
21236
|
const held = chat.unsaved.get(id);
|
|
@@ -21144,6 +21251,29 @@ var FileDesk = class {
|
|
|
21144
21251
|
this.deps.changed(progress ? 250 : 50);
|
|
21145
21252
|
}
|
|
21146
21253
|
/**
|
|
21254
|
+
* A new offer whose record or message could not be stored: refused (no room, or `invalid` for any other cause), not
|
|
21255
|
+
* taken and said done with no message for it here. What was written of it goes, so the sender's Retry is a new offer.
|
|
21256
|
+
* One said on the floor gets its bubble back, saying it was refused, and waits for the offer again.
|
|
21257
|
+
*/
|
|
21258
|
+
unkept(linkId, chat, wireId, id, error, said) {
|
|
21259
|
+
if (said) chat.announced.set(wireId, said);
|
|
21260
|
+
else {
|
|
21261
|
+
chat.local.delete(wireId);
|
|
21262
|
+
this.deps.wireIds(linkId)?.delete(wireId);
|
|
21263
|
+
this.deps.transfers.delete(id);
|
|
21264
|
+
clearTimeout(chat.unsaved.get(id)?.timer);
|
|
21265
|
+
chat.unsaved.delete(id);
|
|
21266
|
+
chat.refused.delete(id);
|
|
21267
|
+
chat.lastSaved.delete(id);
|
|
21268
|
+
this.speeds.delete(id);
|
|
21269
|
+
this.underway.delete(id);
|
|
21270
|
+
this.unwatch(id);
|
|
21271
|
+
chat.saving = chat.saving.then(() => fileStore.delete(id)).catch(() => {});
|
|
21272
|
+
}
|
|
21273
|
+
chat.files.refuse(wireId, error?.name === "QuotaExceededError" ? "no-room" : "invalid");
|
|
21274
|
+
this.deps.changed();
|
|
21275
|
+
}
|
|
21276
|
+
/**
|
|
21147
21277
|
* Writes a transfer's record and the view of it, after the chat's writes before it; what was held back goes with it.
|
|
21148
21278
|
* One the database refuses (a full disk) is kept and written again, with the chat's next write and every few seconds,
|
|
21149
21279
|
* until it goes: dropped, a received file that failed for want of room read "under way" after a restart, then
|
|
@@ -21156,7 +21286,7 @@ var FileDesk = class {
|
|
|
21156
21286
|
chat.unsaved.delete(id);
|
|
21157
21287
|
}
|
|
21158
21288
|
if (transferEnded(record)) chat.lastSaved.delete(id);
|
|
21159
|
-
else chat.lastSaved.set(id,
|
|
21289
|
+
else chat.lastSaved.set(id, elapsed());
|
|
21160
21290
|
const transfer = this.deps.transfers.get(id);
|
|
21161
21291
|
const change = {
|
|
21162
21292
|
wire3: record,
|
|
@@ -21193,7 +21323,7 @@ var FileDesk = class {
|
|
|
21193
21323
|
if (!id) return;
|
|
21194
21324
|
const view = this.view(chat, record, transferred, this.stalled(linkId, id, record, progress));
|
|
21195
21325
|
if (view.state === "transferring" && !view.stage) {
|
|
21196
|
-
const now =
|
|
21326
|
+
const now = elapsed(), last = this.speeds.get(id);
|
|
21197
21327
|
if (!last) this.speeds.set(id, {
|
|
21198
21328
|
bytes: transferred,
|
|
21199
21329
|
at: now,
|
|
@@ -21236,7 +21366,7 @@ var FileDesk = class {
|
|
|
21236
21366
|
this.unwatch(id);
|
|
21237
21367
|
return false;
|
|
21238
21368
|
}
|
|
21239
|
-
const now =
|
|
21369
|
+
const now = elapsed();
|
|
21240
21370
|
if (progress || !this.moved.has(id)) this.moved.set(id, { at: now });
|
|
21241
21371
|
if (progress) this.restored.delete(id);
|
|
21242
21372
|
const movedAt = this.moved.get(id).at;
|
|
@@ -21616,6 +21746,7 @@ function withEdit(message, edit) {
|
|
|
21616
21746
|
const next = {
|
|
21617
21747
|
seq: edit.seq,
|
|
21618
21748
|
at: edit.at,
|
|
21749
|
+
...edit.heardAt !== void 0 && { heardAt: edit.heardAt },
|
|
21619
21750
|
history,
|
|
21620
21751
|
...edit.pending && { pending: true }
|
|
21621
21752
|
};
|
|
@@ -21657,8 +21788,31 @@ var RESEND_POLICY = {
|
|
|
21657
21788
|
/** Queued this long with the contact away, it is handed to store-and-forward when the chat allows it. */
|
|
21658
21789
|
holdAfterMs: 6e4
|
|
21659
21790
|
};
|
|
21791
|
+
/**
|
|
21792
|
+
* What a send hands back when the message did not leave this device: every relay refused it or was not asked, and it
|
|
21793
|
+
* was not out before (`PublishFailedError`). Nothing about it is unconfirmed: a message that had not gone before waits
|
|
21794
|
+
* again (`waiting`, so it can be cancelled), and the ones written after it wait behind it (`NotSent.REASON`).
|
|
21795
|
+
*/
|
|
21796
|
+
var NotSent = class {
|
|
21797
|
+
error;
|
|
21798
|
+
/** What a message that waits again says, in its details. */
|
|
21799
|
+
static REASON = "No relay took it, so it has not left this device. It is sent by itself once one does.";
|
|
21800
|
+
/** `error`: what the send said, kept as it was for a message queued already. */
|
|
21801
|
+
constructor(error) {
|
|
21802
|
+
this.error = error;
|
|
21803
|
+
}
|
|
21804
|
+
};
|
|
21660
21805
|
/** How long one turn of an outbox may hold the next one back: a send that never returns must not stop the chat. */
|
|
21661
21806
|
var TURN_MS = 3e4;
|
|
21807
|
+
/** The newest messages deleted here an outbox keeps from going (`Outbox.cancel`); their rows are long gone by the oldest. */
|
|
21808
|
+
var KEPT_CANCELLED = 1e3;
|
|
21809
|
+
/**
|
|
21810
|
+
* How far past a whole window ahead a stored deadline may be before it counts as set by a clock that went back since
|
|
21811
|
+
* (`Outbox.pastDeadline`): the wall clock and the monotonic one drift apart a little in a session.
|
|
21812
|
+
*/
|
|
21813
|
+
var DEADLINE_SKEW_MS = 6e4;
|
|
21814
|
+
/** The longest delay a timer keeps: past it (about 24.8 days) `setTimeout` fires at once, in Node and in browsers. */
|
|
21815
|
+
var MAX_TIMER_MS = 2 ** 31 - 1;
|
|
21662
21816
|
/** The most rows a new message's look reads one by one (`Outbox.look`), where the store cannot read them in one go. */
|
|
21663
21817
|
var KNOWN_ROWS = 16;
|
|
21664
21818
|
/**
|
|
@@ -21692,10 +21846,35 @@ var Outbox = class {
|
|
|
21692
21846
|
pendingUntil;
|
|
21693
21847
|
/** Sent, awaiting a receipt. */
|
|
21694
21848
|
receipts = /* @__PURE__ */ new Map();
|
|
21695
|
-
/**
|
|
21849
|
+
/**
|
|
21850
|
+
* Queued: when it is looked at again, how far along the backoff, since when. `at` and `since` are on the monotonic
|
|
21851
|
+
* clock (`monotonic`): they live only in this session, and a step of the device clock must not move them. Read by the
|
|
21852
|
+
* 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`).
|
|
21854
|
+
*/
|
|
21696
21855
|
waiting = /* @__PURE__ */ new Map();
|
|
21856
|
+
/**
|
|
21857
|
+
* Stored deadlines (`resendUntil`) found further ahead than a whole window after the device clock went back, each
|
|
21858
|
+
* with the deadline it is held to in this session: a window from when it was found so (`pastDeadline`).
|
|
21859
|
+
*/
|
|
21860
|
+
deadlines = /* @__PURE__ */ new Map();
|
|
21697
21861
|
attempts = /* @__PURE__ */ new Map();
|
|
21698
21862
|
busy = /* @__PURE__ */ new Set();
|
|
21863
|
+
/**
|
|
21864
|
+
* Texts whose last send did not leave this device (`NotSent`) and had not gone before, by id, with their time: what
|
|
21865
|
+
* was written after one goes only once it has (`behindUnsent`), so the contact reads them in order.
|
|
21866
|
+
*/
|
|
21867
|
+
unsent = /* @__PURE__ */ new Map();
|
|
21868
|
+
/**
|
|
21869
|
+
* Texts found waiting behind an unsent one, with their time. While that one cannot go in a turn (`parkedBehind`), a
|
|
21870
|
+
* look does not read them: none of them can go before it, and each new text read every one of them again, 200 rows
|
|
21871
|
+
* per send with 200 waiting.
|
|
21872
|
+
*/
|
|
21873
|
+
behind = /* @__PURE__ */ new Map();
|
|
21874
|
+
/** The unsent texts this turn read and found still to go: read once per turn, not once per text behind them. */
|
|
21875
|
+
stillUnsent = /* @__PURE__ */ new Map();
|
|
21876
|
+
/** Unsent texts whose followers this turn's look did not read: they go at their own check, not in this turn. */
|
|
21877
|
+
parked = /* @__PURE__ */ new Set();
|
|
21699
21878
|
/** Still in flight when the look a reopened chat asked for began (`flush({ reopened })`): sent again once that send returns. */
|
|
21700
21879
|
reopenedWhileBusy = /* @__PURE__ */ new Set();
|
|
21701
21880
|
/** The turns taken so far, one after the other (`turn`). */
|
|
@@ -21725,9 +21904,19 @@ var Outbox = class {
|
|
|
21725
21904
|
looks = 0;
|
|
21726
21905
|
looked = 0;
|
|
21727
21906
|
stopped = false;
|
|
21907
|
+
/**
|
|
21908
|
+
* Messages deleted here (`cancel`): never handed to `send`, whatever a look in progress read of them. A look reads a
|
|
21909
|
+
* row, then marks it and sends what it read: a Cancel sending in between deleted the row and the text went anyway.
|
|
21910
|
+
*/
|
|
21911
|
+
cancelled = /* @__PURE__ */ new Set();
|
|
21912
|
+
/** Handed to `send` and not back yet, each with whether it was waiting (it had not left this device) when its send began. */
|
|
21913
|
+
handed = /* @__PURE__ */ new Map();
|
|
21728
21914
|
resender;
|
|
21729
21915
|
policy;
|
|
21730
21916
|
now;
|
|
21917
|
+
monotonic;
|
|
21918
|
+
/** The wall clock and the monotonic clock when this outbox began: `clock` counts on from there. */
|
|
21919
|
+
origin;
|
|
21731
21920
|
constructor(store, send, timeoutMs = 2e4, pendingUntil, options = {}) {
|
|
21732
21921
|
this.store = store;
|
|
21733
21922
|
this.send = send;
|
|
@@ -21739,6 +21928,37 @@ var Outbox = class {
|
|
|
21739
21928
|
...options.policy
|
|
21740
21929
|
};
|
|
21741
21930
|
this.now = options.now ?? Date.now;
|
|
21931
|
+
this.monotonic = options.monotonic ?? (() => performance.now());
|
|
21932
|
+
this.origin = {
|
|
21933
|
+
wall: this.now(),
|
|
21934
|
+
monotonic: this.monotonic()
|
|
21935
|
+
};
|
|
21936
|
+
}
|
|
21937
|
+
/**
|
|
21938
|
+
* The time a stored deadline (`resendUntil`, set by the wall clock) is judged by: the wall clock, never ahead of the
|
|
21939
|
+
* time this session has run since it began. A clock set forward 8 days failed every queued text at its next check,
|
|
21940
|
+
* as not confirmed within 7 days, a few seconds after it was written.
|
|
21941
|
+
*/
|
|
21942
|
+
clock() {
|
|
21943
|
+
return Math.min(this.now(), this.origin.wall + this.monotonic() - this.origin.monotonic);
|
|
21944
|
+
}
|
|
21945
|
+
/**
|
|
21946
|
+
* Its window to go is over (`resendUntil`, by `clock`). A deadline further ahead than a whole window was set before
|
|
21947
|
+
* the device clock went back: it counts a window from the moment it is found so, as `DhtDelivery` bounds its times,
|
|
21948
|
+
* not for as long as the clock went back. The row keeps what was stored.
|
|
21949
|
+
*/
|
|
21950
|
+
pastDeadline(message) {
|
|
21951
|
+
const stored = message.resendUntil;
|
|
21952
|
+
if (stored === void 0) return false;
|
|
21953
|
+
const now = this.clock(), held = this.deadlines.get(message.id);
|
|
21954
|
+
let until = held?.stored === stored ? held.until : stored;
|
|
21955
|
+
if (until > now + this.policy.windowMs + DEADLINE_SKEW_MS) until = now + this.policy.windowMs;
|
|
21956
|
+
if (until !== stored) this.deadlines.set(message.id, {
|
|
21957
|
+
stored,
|
|
21958
|
+
until
|
|
21959
|
+
});
|
|
21960
|
+
else this.deadlines.delete(message.id);
|
|
21961
|
+
return until <= now;
|
|
21742
21962
|
}
|
|
21743
21963
|
/** `messages`: the chat's history as the caller just read it (a start has), so it is not read a second time. */
|
|
21744
21964
|
async recover(messages) {
|
|
@@ -21757,7 +21977,7 @@ var Outbox = class {
|
|
|
21757
21977
|
const until = this.pendingUntil?.(message);
|
|
21758
21978
|
if (until && until > this.now()) {
|
|
21759
21979
|
await this.store.update(message.id, "sent");
|
|
21760
|
-
this.track(message.id, until - this.now());
|
|
21980
|
+
this.track(message.id, Math.min(until - this.now(), this.receiptWindow(message)));
|
|
21761
21981
|
} else if (until !== void 0) await this.expired(message);
|
|
21762
21982
|
else await this.queue(message, "Not confirmed before the app closed. It is sent again, under the same ID, once your contact is reachable.");
|
|
21763
21983
|
}
|
|
@@ -21777,6 +21997,8 @@ var Outbox = class {
|
|
|
21777
21997
|
await this.requeueUnconfirmed();
|
|
21778
21998
|
}
|
|
21779
21999
|
this.began = this.closed;
|
|
22000
|
+
this.stillUnsent.clear();
|
|
22001
|
+
this.parked.clear();
|
|
21780
22002
|
return run();
|
|
21781
22003
|
});
|
|
21782
22004
|
this.line = before.then(() => new Promise((next) => {
|
|
@@ -21797,6 +22019,20 @@ var Outbox = class {
|
|
|
21797
22019
|
for (const wait of this.waiting.values()) if (wait.timer) return true;
|
|
21798
22020
|
return false;
|
|
21799
22021
|
}
|
|
22022
|
+
/**
|
|
22023
|
+
* The message is deleted here (Cancel sending, a delete, a delete for everyone): from now on it never goes, and
|
|
22024
|
+
* nothing of it is retried. A send already handed to the link cannot be called back: true when that send is of a text
|
|
22025
|
+
* that was waiting (it had not left this device), so the caller, who meant it never to leave, removes it from the
|
|
22026
|
+
* contact too. No row is read: the answer is what this outbox is doing with it right now.
|
|
22027
|
+
*/
|
|
22028
|
+
cancel(id) {
|
|
22029
|
+
this.cancelled.delete(id);
|
|
22030
|
+
this.cancelled.add(id);
|
|
22031
|
+
if (this.cancelled.size > KEPT_CANCELLED) this.cancelled.delete(this.cancelled.values().next().value);
|
|
22032
|
+
this.clear(id);
|
|
22033
|
+
this.forget(id);
|
|
22034
|
+
return this.handed.get(id) === true;
|
|
22035
|
+
}
|
|
21800
22036
|
/** One message as stored now: by its id when the store can, else picked out of the chat's history. */
|
|
21801
22037
|
async one(id) {
|
|
21802
22038
|
return this.store.get ? this.store.get(id) : (await this.store.read()).find((m) => m.id === id);
|
|
@@ -21871,16 +22107,46 @@ var Outbox = class {
|
|
|
21871
22107
|
* are never more than the history.
|
|
21872
22108
|
*/
|
|
21873
22109
|
async look(id) {
|
|
21874
|
-
if (!this.store.get || !this.known
|
|
22110
|
+
if (!this.store.get || !this.known) return this.store.read();
|
|
22111
|
+
const { skip, parked } = await this.parkedBehind();
|
|
22112
|
+
const waiting = [...this.waiting.keys()].filter((known) => known === id || !skip.has(known) || this.receipts.has(known) || this.onTheirWay.has(known));
|
|
22113
|
+
if (!this.store.getMany && waiting.length + this.receipts.size + this.onTheirWay.size > KNOWN_ROWS) return this.store.read();
|
|
22114
|
+
if (waiting.length < this.waiting.size) for (const unsent of parked) this.parked.add(unsent);
|
|
21875
22115
|
const ids = /* @__PURE__ */ new Set([
|
|
21876
22116
|
...id === void 0 ? [] : [id],
|
|
21877
|
-
...
|
|
22117
|
+
...waiting,
|
|
21878
22118
|
...this.receipts.keys(),
|
|
21879
22119
|
...this.onTheirWay.keys()
|
|
21880
22120
|
]);
|
|
21881
22121
|
return (this.store.getMany ? await this.store.getMany([...ids]) : await Promise.all([...ids].map((known) => this.store.get(known)))).filter((row) => !!row);
|
|
21882
22122
|
}
|
|
21883
22123
|
/**
|
|
22124
|
+
* The texts no relay took that cannot go in this turn: each waits for its own check to be published again (`attempt`),
|
|
22125
|
+
* and is still to go, within its window. What waits behind one of them (`behind`) cannot go in this turn either.
|
|
22126
|
+
*/
|
|
22127
|
+
async parkedBehind() {
|
|
22128
|
+
const skip = /* @__PURE__ */ new Set(), parked = [];
|
|
22129
|
+
if (!this.behind.size || !this.resender.via) return {
|
|
22130
|
+
skip,
|
|
22131
|
+
parked
|
|
22132
|
+
};
|
|
22133
|
+
let from = Infinity;
|
|
22134
|
+
for (const [id, timestamp] of this.unsent) {
|
|
22135
|
+
if (!this.waiting.get(id)?.timer || this.busy.has(id)) continue;
|
|
22136
|
+
const row = this.stillUnsent.get(id) ?? await this.one(id);
|
|
22137
|
+
if (!row || !toGo(row)) continue;
|
|
22138
|
+
this.stillUnsent.set(id, row);
|
|
22139
|
+
if (this.pastDeadline(row) || this.resender.via(row) !== "pkarr") continue;
|
|
22140
|
+
parked.push(id);
|
|
22141
|
+
from = Math.min(from, timestamp);
|
|
22142
|
+
}
|
|
22143
|
+
for (const [id, timestamp] of this.behind) if (timestamp >= from && !parked.includes(id)) skip.add(id);
|
|
22144
|
+
return {
|
|
22145
|
+
skip,
|
|
22146
|
+
parked
|
|
22147
|
+
};
|
|
22148
|
+
}
|
|
22149
|
+
/**
|
|
21884
22150
|
* What a look at the chat takes up comes from: the rows this outbox holds, by id, where it knows them all (`look`);
|
|
21885
22151
|
* else the chat's whole history, which, when it shows nothing of mine to go that this outbox did not know of, says
|
|
21886
22152
|
* so until the next row stored by someone else. A session that opened with nothing queued, nothing awaiting a
|
|
@@ -21947,6 +22213,10 @@ var Outbox = class {
|
|
|
21947
22213
|
/** A waiting file is said on the link, after the older messages passed by that can go now. False: the link cannot carry it. */
|
|
21948
22214
|
async fileGoes(message, passed) {
|
|
21949
22215
|
if (!this.resender.ready(message)) {
|
|
22216
|
+
if (message.fileOnFloor) {
|
|
22217
|
+
this.holdUnchecked(message.id);
|
|
22218
|
+
return false;
|
|
22219
|
+
}
|
|
21950
22220
|
if (!this.waiting.get(message.id)?.timer) this.schedule(message.id);
|
|
21951
22221
|
return false;
|
|
21952
22222
|
}
|
|
@@ -21955,7 +22225,15 @@ var Outbox = class {
|
|
|
21955
22225
|
if (!this.stopped && !this.waiting.get(message.id)?.timer) this.schedule(message.id);
|
|
21956
22226
|
return true;
|
|
21957
22227
|
}
|
|
21958
|
-
await this.
|
|
22228
|
+
if (await this.behindUnsent(message)) {
|
|
22229
|
+
if (!this.waiting.get(message.id)?.timer) this.schedule(message.id);
|
|
22230
|
+
return true;
|
|
22231
|
+
}
|
|
22232
|
+
if (this.cancelled.has(message.id)) {
|
|
22233
|
+
this.forget(message.id);
|
|
22234
|
+
return true;
|
|
22235
|
+
}
|
|
22236
|
+
await this.resender.sendFile(message, () => this.cancelled.has(message.id)).catch(() => {});
|
|
21959
22237
|
this.forget(message.id);
|
|
21960
22238
|
this.stamp++;
|
|
21961
22239
|
return true;
|
|
@@ -21995,12 +22273,15 @@ var Outbox = class {
|
|
|
21995
22273
|
}
|
|
21996
22274
|
/** `read`: the message's row, when it was read just now with nothing awaited since. */
|
|
21997
22275
|
async transmitNow(id, { manual = false } = {}, read) {
|
|
21998
|
-
if (this.stopped || this.busy.has(id) || this.receipts.has(id)) return;
|
|
22276
|
+
if (this.stopped || this.busy.has(id) || this.receipts.has(id) || this.cancelled.has(id)) return;
|
|
21999
22277
|
this.busy.add(id);
|
|
22000
22278
|
let again;
|
|
22001
22279
|
try {
|
|
22002
22280
|
let message = read ?? await this.one(id);
|
|
22003
22281
|
if (!message?.wireId || !message.delivery || message.delivery === "delivered") return;
|
|
22282
|
+
if (!manual && await this.behindUnsent(message)) return await this.waitBehind(message);
|
|
22283
|
+
this.behind.delete(id);
|
|
22284
|
+
const unsentBefore = message.delivery === "waiting" || message.delivery === "sending" && !this.attempts.get(id);
|
|
22004
22285
|
const wait = this.waiting.get(id);
|
|
22005
22286
|
if (wait?.timer) {
|
|
22006
22287
|
clearTimeout(wait.timer);
|
|
@@ -22011,7 +22292,8 @@ var Outbox = class {
|
|
|
22011
22292
|
this.waiting.delete(id);
|
|
22012
22293
|
}
|
|
22013
22294
|
this.attempts.set(id, (this.attempts.get(id) ?? 0) + 1);
|
|
22014
|
-
const via = this.resender.via?.(message) ?? message.via;
|
|
22295
|
+
const via = this.resender.via?.(message) ?? message.via, wasWaiting = message.delivery === "waiting";
|
|
22296
|
+
if (this.cancelled.has(id)) return this.forget(id);
|
|
22015
22297
|
await this.store.update(id, "sending", void 0, {
|
|
22016
22298
|
via,
|
|
22017
22299
|
...manual ? { resendUntil: void 0 } : {}
|
|
@@ -22029,14 +22311,30 @@ var Outbox = class {
|
|
|
22029
22311
|
}, "Connection closed. Delivery is unconfirmed.");
|
|
22030
22312
|
return;
|
|
22031
22313
|
}
|
|
22314
|
+
if (this.cancelled.has(id)) return this.forget(id);
|
|
22032
22315
|
this.track(id, typeof this.timeoutMs === "number" ? this.timeoutMs : this.timeoutMs(message));
|
|
22033
22316
|
this.sentUnder.set(id, this.opened);
|
|
22034
|
-
|
|
22035
|
-
|
|
22317
|
+
this.handed.set(id, wasWaiting);
|
|
22318
|
+
let error;
|
|
22319
|
+
try {
|
|
22320
|
+
error = await this.send(message);
|
|
22321
|
+
} finally {
|
|
22322
|
+
this.handed.delete(id);
|
|
22323
|
+
}
|
|
22324
|
+
if (this.cancelled.has(id)) {
|
|
22036
22325
|
this.clear(id);
|
|
22037
|
-
|
|
22326
|
+
return this.forget(id);
|
|
22327
|
+
}
|
|
22328
|
+
if (!(error instanceof NotSent)) this.unsent.delete(id);
|
|
22329
|
+
if (error instanceof NotSent && unsentBefore) {
|
|
22330
|
+
this.clear(id);
|
|
22331
|
+
await this.notSent(id);
|
|
22332
|
+
} else if (error) {
|
|
22333
|
+
this.clear(id);
|
|
22334
|
+
await this.requeue(id, error instanceof NotSent ? error.error : error);
|
|
22038
22335
|
} else if (this.receipts.has(id)) await this.store.update(id, "sent");
|
|
22039
22336
|
} catch (error) {
|
|
22337
|
+
this.unsent.delete(id);
|
|
22040
22338
|
this.clear(id);
|
|
22041
22339
|
await this.requeue(id, error instanceof Error ? error.message : "Sending failed");
|
|
22042
22340
|
} finally {
|
|
@@ -22107,7 +22405,7 @@ var Outbox = class {
|
|
|
22107
22405
|
await this.attempt(id);
|
|
22108
22406
|
return;
|
|
22109
22407
|
}
|
|
22110
|
-
const soon = this.
|
|
22408
|
+
const soon = this.monotonic() + this.policy.backoffMs[0], taken = [];
|
|
22111
22409
|
let until = message.timestamp;
|
|
22112
22410
|
for (const m of messages) {
|
|
22113
22411
|
const wait = this.waiting.get(m.id);
|
|
@@ -22132,7 +22430,7 @@ var Outbox = class {
|
|
|
22132
22430
|
*/
|
|
22133
22431
|
waitsOn(message) {
|
|
22134
22432
|
const wait = this.waiting.get(message.id);
|
|
22135
|
-
return !!wait && (message.delivery === "queued" || message.delivery === "waiting") && message.via !== "hold" &&
|
|
22433
|
+
return !!wait && (message.delivery === "queued" || message.delivery === "waiting") && message.via !== "hold" && !this.pastDeadline(message) && !this.resender.ready(message) && !(this.resender.divert && this.monotonic() - wait.since >= this.policy.holdAfterMs);
|
|
22136
22434
|
}
|
|
22137
22435
|
/**
|
|
22138
22436
|
* A queued or waiting message is looked at; one sent and awaiting its receipt goes again now, if the chat can carry
|
|
@@ -22178,6 +22476,7 @@ var Outbox = class {
|
|
|
22178
22476
|
this.reopenedWhileBusy.clear();
|
|
22179
22477
|
for (const wait of this.waiting.values()) if (wait.timer) clearTimeout(wait.timer);
|
|
22180
22478
|
this.waiting.clear();
|
|
22479
|
+
this.behind.clear();
|
|
22181
22480
|
this.dropped = false;
|
|
22182
22481
|
await this.requeueUnconfirmed();
|
|
22183
22482
|
}
|
|
@@ -22189,44 +22488,104 @@ var Outbox = class {
|
|
|
22189
22488
|
*/
|
|
22190
22489
|
async attempt(id, passed, read) {
|
|
22191
22490
|
if (this.stopped || this.busy.has(id)) return true;
|
|
22491
|
+
if (this.cancelled.has(id)) {
|
|
22492
|
+
this.forget(id);
|
|
22493
|
+
return true;
|
|
22494
|
+
}
|
|
22192
22495
|
if (read && this.waitsOn(read)) {
|
|
22193
22496
|
if (!this.waiting.get(id)?.timer) this.schedule(id);
|
|
22194
22497
|
return false;
|
|
22195
22498
|
}
|
|
22499
|
+
if (read?.wireId && this.unsent.size && !this.unsent.has(id) && !this.receipts.has(id) && (read.delivery === "queued" || read.delivery === "waiting") && read.via !== "hold" && !this.pastDeadline(read) && this.resender.ready(read)) {
|
|
22500
|
+
if (passed) await this.catchUp(passed);
|
|
22501
|
+
if (!this.busy.has(id) && await this.behindUnsent(read)) {
|
|
22502
|
+
await this.waitBehind(read);
|
|
22503
|
+
return true;
|
|
22504
|
+
}
|
|
22505
|
+
}
|
|
22196
22506
|
const message = await this.one(id);
|
|
22197
22507
|
if (!message || message.delivery !== "queued" && message.delivery !== "waiting" || message.via === "hold") {
|
|
22198
22508
|
this.forget(id);
|
|
22199
22509
|
return true;
|
|
22200
22510
|
}
|
|
22201
|
-
if (
|
|
22511
|
+
if (this.pastDeadline(message)) {
|
|
22202
22512
|
if (message.delivery === "waiting") {
|
|
22203
22513
|
this.forget(id);
|
|
22204
22514
|
await this.store.update(id, "failed", `Your contact was not reachable within ${days(this.policy.windowMs)}. It was not sent; Retry sends it.`);
|
|
22205
22515
|
} else await this.fail(id, `Not confirmed within ${days(this.policy.windowMs)}.`);
|
|
22206
22516
|
return true;
|
|
22207
22517
|
}
|
|
22518
|
+
const wait = this.waiting.get(id);
|
|
22519
|
+
if (wait?.timer && this.unsent.has(id) && this.resender.via?.(message) === "pkarr") return false;
|
|
22520
|
+
if (this.parked.has(id)) {
|
|
22521
|
+
if (!wait?.timer) this.schedule(id);
|
|
22522
|
+
return false;
|
|
22523
|
+
}
|
|
22208
22524
|
if (this.resender.ready(message)) {
|
|
22209
22525
|
if (passed) await this.catchUp(passed);
|
|
22210
22526
|
await this.transmitNow(id);
|
|
22211
22527
|
return true;
|
|
22212
22528
|
}
|
|
22213
|
-
|
|
22214
|
-
if (this.resender.divert && wait && this.now() - wait.since >= this.policy.holdAfterMs && await this.resender.divert(message)) {
|
|
22529
|
+
if (this.resender.divert && wait && this.monotonic() - wait.since >= this.policy.holdAfterMs && await this.resender.divert(message)) {
|
|
22215
22530
|
this.forget(id);
|
|
22216
22531
|
return true;
|
|
22217
22532
|
}
|
|
22218
22533
|
if (!wait?.timer) this.schedule(id);
|
|
22219
22534
|
return false;
|
|
22220
22535
|
}
|
|
22536
|
+
/**
|
|
22537
|
+
* A send that did not leave this device, of a message that had not gone before: it waits again, as it did, and counts
|
|
22538
|
+
* no attempt. It keeps the path a new message's turn gives it (`waitsItsTurn`): it goes the way the chat can carry it.
|
|
22539
|
+
*/
|
|
22540
|
+
async notSent(id) {
|
|
22541
|
+
const left = (this.attempts.get(id) ?? 1) - 1;
|
|
22542
|
+
if (left > 0) this.attempts.set(id, left);
|
|
22543
|
+
else this.attempts.delete(id);
|
|
22544
|
+
const message = await this.one(id);
|
|
22545
|
+
if (!message || message.delivery === "delivered") return;
|
|
22546
|
+
this.unsent.set(id, message.timestamp);
|
|
22547
|
+
await this.store.update(id, "waiting", NotSent.REASON, {
|
|
22548
|
+
via: "datalink",
|
|
22549
|
+
resendUntil: message.resendUntil ?? this.now() + this.policy.windowMs
|
|
22550
|
+
});
|
|
22551
|
+
if (!this.stopped) this.schedule(id);
|
|
22552
|
+
}
|
|
22553
|
+
/**
|
|
22554
|
+
* An older text of mine has not left this device (`unsent`) and still waits to go: this one must not go before it.
|
|
22555
|
+
* One cancelled meanwhile (its row gone) or gone another way (held, failed) holds nothing back any more.
|
|
22556
|
+
*/
|
|
22557
|
+
async behindUnsent(message) {
|
|
22558
|
+
for (const [id, timestamp] of this.unsent) {
|
|
22559
|
+
if (id === message.id || timestamp > message.timestamp) continue;
|
|
22560
|
+
const older = this.stillUnsent.get(id) ?? await this.one(id);
|
|
22561
|
+
if (older && toGo(older)) {
|
|
22562
|
+
this.stillUnsent.set(id, older);
|
|
22563
|
+
this.behind.set(message.id, message.timestamp);
|
|
22564
|
+
return true;
|
|
22565
|
+
}
|
|
22566
|
+
this.unsent.delete(id);
|
|
22567
|
+
}
|
|
22568
|
+
this.behind.delete(message.id);
|
|
22569
|
+
return false;
|
|
22570
|
+
}
|
|
22571
|
+
/** A message behind an unsent text: it waits as it did, and one that was about to go waits its turn. */
|
|
22572
|
+
async waitBehind(message) {
|
|
22573
|
+
if (message.delivery === "sending") await this.waitsItsTurn(message);
|
|
22574
|
+
else if (message.delivery !== "waiting") await this.queue(message, message.deliveryError ?? "Not confirmed yet.");
|
|
22575
|
+
else if (!this.waiting.get(message.id)?.timer) this.schedule(message.id);
|
|
22576
|
+
}
|
|
22221
22577
|
/** After a failed attempt: queued again, unless its window or its attempts are spent. */
|
|
22222
22578
|
async requeue(id, reason) {
|
|
22223
22579
|
const message = await this.one(id);
|
|
22224
22580
|
if (message && message.delivery !== "delivered") await this.queue(message, reason);
|
|
22225
22581
|
}
|
|
22226
22582
|
async queue(message, reason) {
|
|
22227
|
-
const
|
|
22583
|
+
const until = message.resendUntil ?? this.now() + this.policy.windowMs;
|
|
22228
22584
|
const sent = this.attempts.get(message.id) ?? 0;
|
|
22229
|
-
if (
|
|
22585
|
+
if (this.pastDeadline({
|
|
22586
|
+
...message,
|
|
22587
|
+
resendUntil: until
|
|
22588
|
+
})) return this.fail(message.id, `${reason} Not confirmed within ${days(this.policy.windowMs)}.`);
|
|
22230
22589
|
if (sent >= this.policy.maxAttempts) return this.fail(message.id, `${reason} Sent ${sent} times without a receipt.`);
|
|
22231
22590
|
if (message.delivery !== "queued" || message.deliveryError !== reason || message.resendUntil !== until) await this.store.update(message.id, "queued", reason, { resendUntil: until });
|
|
22232
22591
|
if (!this.stopped) this.schedule(message.id);
|
|
@@ -22242,14 +22601,15 @@ var Outbox = class {
|
|
|
22242
22601
|
await this.store.update(id, "failed", `${reason} Your contact may have received it; Retry uses the same message ID, so it is never shown twice.`);
|
|
22243
22602
|
}
|
|
22244
22603
|
schedule(id) {
|
|
22604
|
+
if (this.cancelled.has(id)) return;
|
|
22245
22605
|
const wait = this.waiting.get(id) ?? {
|
|
22246
22606
|
step: 0,
|
|
22247
|
-
since: this.
|
|
22607
|
+
since: this.monotonic(),
|
|
22248
22608
|
at: 0
|
|
22249
22609
|
};
|
|
22250
22610
|
if (wait.timer) clearTimeout(wait.timer);
|
|
22251
22611
|
const delay = this.policy.backoffMs[Math.min(wait.step, this.policy.backoffMs.length - 1)];
|
|
22252
|
-
wait.at = this.
|
|
22612
|
+
wait.at = this.monotonic() + delay;
|
|
22253
22613
|
wait.timer = setTimeout(() => {
|
|
22254
22614
|
wait.timer = void 0;
|
|
22255
22615
|
wait.step++;
|
|
@@ -22257,13 +22617,34 @@ var Outbox = class {
|
|
|
22257
22617
|
}, delay);
|
|
22258
22618
|
this.waiting.set(id, wait);
|
|
22259
22619
|
}
|
|
22620
|
+
/** Held, so a look reads its row by id (`look`), with no timer: nothing but a look at the chat sends it. */
|
|
22621
|
+
holdUnchecked(id) {
|
|
22622
|
+
if (this.cancelled.has(id)) return;
|
|
22623
|
+
const wait = this.waiting.get(id);
|
|
22624
|
+
if (wait?.timer) {
|
|
22625
|
+
clearTimeout(wait.timer);
|
|
22626
|
+
wait.timer = void 0;
|
|
22627
|
+
}
|
|
22628
|
+
if (!wait) this.waiting.set(id, {
|
|
22629
|
+
step: 0,
|
|
22630
|
+
since: this.monotonic(),
|
|
22631
|
+
at: 0
|
|
22632
|
+
});
|
|
22633
|
+
}
|
|
22260
22634
|
forget(id) {
|
|
22635
|
+
this.unsent.delete(id);
|
|
22636
|
+
this.behind.delete(id);
|
|
22261
22637
|
const wait = this.waiting.get(id);
|
|
22262
22638
|
if (wait?.timer) clearTimeout(wait.timer);
|
|
22263
22639
|
this.waiting.delete(id);
|
|
22640
|
+
this.deadlines.delete(id);
|
|
22264
22641
|
this.attempts.delete(id);
|
|
22265
22642
|
this.sentUnder.delete(id);
|
|
22266
22643
|
}
|
|
22644
|
+
/** How long a receipt is awaited for this message when it goes now. */
|
|
22645
|
+
receiptWindow(message) {
|
|
22646
|
+
return typeof this.timeoutMs === "number" ? this.timeoutMs : this.timeoutMs(message);
|
|
22647
|
+
}
|
|
22267
22648
|
track(id, duration) {
|
|
22268
22649
|
this.clear(id);
|
|
22269
22650
|
const timer = setTimeout(() => {
|
|
@@ -22274,7 +22655,7 @@ var Outbox = class {
|
|
|
22274
22655
|
if (message?.via === "pkarr") await this.expired(message);
|
|
22275
22656
|
else await this.requeue(id, "No receipt received yet.");
|
|
22276
22657
|
}).catch(() => {});
|
|
22277
|
-
}, duration);
|
|
22658
|
+
}, Math.min(Math.max(duration, 0), MAX_TIMER_MS));
|
|
22278
22659
|
this.receipts.set(id, timer);
|
|
22279
22660
|
}
|
|
22280
22661
|
clear(id) {
|
|
@@ -22307,6 +22688,8 @@ var days = (ms) => {
|
|
|
22307
22688
|
var CARD_RESTORE_GAP_MS = 2 * EDIT_RATE_WINDOW_MS / 10;
|
|
22308
22689
|
/** What makes a card the same card across messages: a new message may reuse a card's id, and the newest stands for it. */
|
|
22309
22690
|
var cardKey = (message) => message.card && `${message.card.kind}\n${message.card.id}`;
|
|
22691
|
+
/** A row of mine with an edit (or a removal) on its way to the contact. */
|
|
22692
|
+
var waits = (m) => m.sender === "me" && !!m.edit?.pending;
|
|
22310
22693
|
var EditQueue = class {
|
|
22311
22694
|
deps;
|
|
22312
22695
|
pace;
|
|
@@ -22369,6 +22752,19 @@ var EditQueue = class {
|
|
|
22369
22752
|
reopened() {
|
|
22370
22753
|
this.sent.clear();
|
|
22371
22754
|
}
|
|
22755
|
+
/**
|
|
22756
|
+
* The chat's whole history as read elsewhere in this run (the start reads each chat once): the rows with an edit on
|
|
22757
|
+
* their way are known from it, so the first look reads those rows alone instead of the history again. Only with rows
|
|
22758
|
+
* read by their id; without, every look reads the history anyway. An edit made since that read is told (`edited`).
|
|
22759
|
+
*/
|
|
22760
|
+
learn(history) {
|
|
22761
|
+
if (!this.deps.rows) return;
|
|
22762
|
+
for (const m of history) if (waits(m)) {
|
|
22763
|
+
if (!this.known.has(m.id)) this.known.set(m.id, this.tick);
|
|
22764
|
+
if (m.wireId) this.wires.set(m.id, m.wireId);
|
|
22765
|
+
}
|
|
22766
|
+
this.learnt = true;
|
|
22767
|
+
}
|
|
22372
22768
|
/** This row has an edit to send (it was just written so): the next look reads it. */
|
|
22373
22769
|
edited(id) {
|
|
22374
22770
|
this.known.set(id, ++this.tick);
|
|
@@ -22379,7 +22775,6 @@ var EditQueue = class {
|
|
|
22379
22775
|
* alone, in one read, and one that waits no more is forgotten, unless it was told again while it was read.
|
|
22380
22776
|
*/
|
|
22381
22777
|
async pending(only) {
|
|
22382
|
-
const waits = (m) => m.sender === "me" && !!m.edit?.pending;
|
|
22383
22778
|
const read = this.deps.rows;
|
|
22384
22779
|
if (!read || !this.learnt) {
|
|
22385
22780
|
const all = await this.deps.read(), rows = all.filter(waits);
|
|
@@ -24457,6 +24852,23 @@ var ENTRY_LINGER_MS$1 = 2e4;
|
|
|
24457
24852
|
var FULL_TELL_MS = 3e5;
|
|
24458
24853
|
var FULL_LINGER_MS = 5e3;
|
|
24459
24854
|
var FULL_SAID_MS = 66e4;
|
|
24855
|
+
/**
|
|
24856
|
+
* Whether this device can let in no one new now (WISP 903 § Admissions while the admin is away): members signed
|
|
24857
|
+
* `COMMUNITY_LIMITS.memberAdmissions` admissions in a row, counted as the session's `commit` counts them. Its hub
|
|
24858
|
+
* answered every knock all the same: an entry session, an invite, the joiner told it was in "in a moment", and then
|
|
24859
|
+
* the accept refused, every turn of the door for as long as the admin was away.
|
|
24860
|
+
*/
|
|
24861
|
+
function admissionsHeld(s) {
|
|
24862
|
+
if (s.isAdmin) return false;
|
|
24863
|
+
const admin = s.admin, chain = s.state.chain;
|
|
24864
|
+
let n = 0;
|
|
24865
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
24866
|
+
const c = chain[i];
|
|
24867
|
+
if (c.k === "create" || c.k === "role" || c.by === admin && c.k !== "remove" && c.k !== "leave") break;
|
|
24868
|
+
if (c.k === "add") n++;
|
|
24869
|
+
}
|
|
24870
|
+
return n >= COMMUNITY_LIMITS.memberAdmissions;
|
|
24871
|
+
}
|
|
24460
24872
|
var RELAYED_KEPT = 4096;
|
|
24461
24873
|
/**
|
|
24462
24874
|
* Someone the chain took out while its app was closed comes back believing it is a member: it asks in a hub's lobby,
|
|
@@ -25906,7 +26318,7 @@ var Communities = class {
|
|
|
25906
26318
|
async answerKnocks(groupId, live, now, busy) {
|
|
25907
26319
|
const s = live.session;
|
|
25908
26320
|
if (!s.adminWork || !s.entryKey || !s.state.entry.seedB64) return;
|
|
25909
|
-
const full = s.roster.length >= COMMUNITY_LIMITS.members;
|
|
26321
|
+
const full = s.roster.length >= COMMUNITY_LIMITS.members, held = admissionsHeld(s);
|
|
25910
26322
|
for (const [key, at] of live.fullTold) if (now - at >= FULL_TELL_MS) live.fullTold.delete(key);
|
|
25911
26323
|
const link = {
|
|
25912
26324
|
g: groupId,
|
|
@@ -25952,7 +26364,7 @@ var Communities = class {
|
|
|
25952
26364
|
const stillKnocking = now - ts < 2 * this.timings.slowKnockMs;
|
|
25953
26365
|
if (rosterHas(s.roster, key)) {
|
|
25954
26366
|
if (!stillKnocking || ts < this.addedAt(s, key) + this.timings.knockFallbackMs) continue;
|
|
25955
|
-
} else if (full
|
|
26367
|
+
} else if (full ? door !== s.myKey || live.fullTold.has(key) : held) continue;
|
|
25956
26368
|
const seen = live.knocksSeen.get(key);
|
|
25957
26369
|
const changed = !!seen && seen.doors !== doorSig;
|
|
25958
26370
|
const first = seen && !changed ? seen.first : now;
|
|
@@ -26106,6 +26518,11 @@ var Communities = class {
|
|
|
26106
26518
|
live.lingering.set(linkId, now + FULL_LINGER_MS);
|
|
26107
26519
|
return true;
|
|
26108
26520
|
}
|
|
26521
|
+
if (!rosterHas(s.roster, peer) && admissionsHeld(s)) {
|
|
26522
|
+
live.pendingEntries.delete(peer);
|
|
26523
|
+
this.host.closeEdge(linkId).catch(() => {});
|
|
26524
|
+
return true;
|
|
26525
|
+
}
|
|
26109
26526
|
try {
|
|
26110
26527
|
this.host.sendOnLink(linkId, live.session.inviteFrame());
|
|
26111
26528
|
traceJoin(groupId, "invite.sent");
|
|
@@ -28828,10 +29245,13 @@ var Groups = class {
|
|
|
28828
29245
|
couldRead: (key, messageId, ts) => session.couldRead(key, messageId, ts)
|
|
28829
29246
|
};
|
|
28830
29247
|
}
|
|
28831
|
-
/**
|
|
29248
|
+
/**
|
|
29249
|
+
* Why this device is out of the group for good, as `fileCheck` says it; undefined while it is in it, or not loaded. A
|
|
29250
|
+
* community join that lost a race (`lost`) is asked again and back in by itself: its files wait, not stop for good.
|
|
29251
|
+
*/
|
|
28832
29252
|
fileOut(groupId) {
|
|
28833
29253
|
const session = this.isCommunity(groupId) ? this.communities.session(groupId) : this.sessions.get(groupId);
|
|
28834
|
-
if (!session || session.status === "active") return void 0;
|
|
29254
|
+
if (!session || session.status === "active" || session.status === "lost") return void 0;
|
|
28835
29255
|
return session.state.statusReason ?? "You are no longer in this group";
|
|
28836
29256
|
}
|
|
28837
29257
|
/**
|
|
@@ -30944,6 +31364,7 @@ var Groups = class {
|
|
|
30944
31364
|
this.files?.arrivedAgain(state.id, id, frame.e);
|
|
30945
31365
|
},
|
|
30946
31366
|
edit: (e) => this.host.groupEdit?.(state.id, e),
|
|
31367
|
+
carriers: () => this.hubs.active(state.id, session, this.now()) ? this.hubs.hubs(state.id, session, this.now()) : [],
|
|
30947
31368
|
changed: () => {
|
|
30948
31369
|
if (session.status === "removed" && this.hubs.isHub(state.id) && !this.removedAt.has(state.id)) this.removedAt.set(state.id, this.now());
|
|
30949
31370
|
this.membershipChanged(state.id).catch(() => {});
|
|
@@ -31221,10 +31642,14 @@ function parseGroupPay(raw, groupId) {
|
|
|
31221
31642
|
* Whether `author` may say this. A request's state (open, paid, closed) is the payee's to say; a member who paid
|
|
31222
31643
|
* it says so about itself (`sent`, `by` = itself), and takes that back (`closed`) when its payment came back. A
|
|
31223
31644
|
* payment without a request: the payer says it sent it (or took it back), the payee that it was paid. Whoever a
|
|
31224
|
-
* note names must be in the group
|
|
31225
|
-
|
|
31226
|
-
|
|
31227
|
-
|
|
31645
|
+
* note names must be in the group, but for the payee's `paid` naming a payer who left since: `known` (the note so
|
|
31646
|
+
* far) shows that payer was in the group when a note naming it was believed (its own `sent`, or the request or
|
|
31647
|
+
* payment made with it as the payer).
|
|
31648
|
+
*/
|
|
31649
|
+
function mayAuthor(frame, author, members, known) {
|
|
31650
|
+
const left = (key) => frame.st === "paid" && author === frame.to && !!known && (known.from === key || key === frame.by && !!known.claims?.includes(key));
|
|
31651
|
+
const named = (key) => members.has(key) || left(key);
|
|
31652
|
+
if (!members.has(author) || !members.has(frame.to) || frame.f !== "*" && !named(frame.f) || frame.by && !named(frame.by)) return false;
|
|
31228
31653
|
if (frame.by && (frame.by === frame.to || frame.f !== "*" && frame.by !== frame.f)) return false;
|
|
31229
31654
|
if (frame.k === "req") {
|
|
31230
31655
|
if (author === frame.to) return frame.st !== "sent";
|
|
@@ -31247,16 +31672,17 @@ var fieldsOf = (frame) => ({
|
|
|
31247
31672
|
...frame.a ? { ask: true } : {},
|
|
31248
31673
|
createdAt: frame.ts
|
|
31249
31674
|
});
|
|
31675
|
+
/** Whether `author`'s `frame` may count for the note kept so far: one about another payment under the same id never does. */
|
|
31676
|
+
var believed = (current, frame, author, members) => mayAuthor(frame, author, members, current) && (!current || current.kind === (frame.k === "req" ? "request" : "payment") && current.to === frame.to);
|
|
31250
31677
|
/**
|
|
31251
31678
|
* The note after `author` said `frame`, or undefined when that changes nothing (or may not be believed). What a
|
|
31252
31679
|
* payment is (who, how much, over what) is its initiator's to say: the payee's for a request, the payer's for a
|
|
31253
31680
|
* payment; anyone else's description only stands in until the initiator's arrives. States only move forward.
|
|
31254
31681
|
*/
|
|
31255
31682
|
function mergeGroupPay(current, frame, author, members) {
|
|
31256
|
-
if (!
|
|
31683
|
+
if (!believed(current, frame, author, members)) return void 0;
|
|
31257
31684
|
const initiator = frame.k === "req" ? frame.to : frame.f;
|
|
31258
31685
|
const fields = fieldsOf(frame);
|
|
31259
|
-
if (current && (current.kind !== fields.kind || current.to !== fields.to)) return void 0;
|
|
31260
31686
|
let next = current ? { ...current } : {
|
|
31261
31687
|
...fields,
|
|
31262
31688
|
state: "open",
|
|
@@ -31365,11 +31791,33 @@ function authoredNote(p, at, all, current, memberOf = () => void 0, federationNe
|
|
|
31365
31791
|
};
|
|
31366
31792
|
return null;
|
|
31367
31793
|
}
|
|
31794
|
+
/**
|
|
31795
|
+
* What GroupPayments needs of a group's view: my key and who is in it while I am an active member, and when this
|
|
31796
|
+
* membership began here (the group's row is made anew when I create it, am invited or join by its link, and goes
|
|
31797
|
+
* when I leave or forget it).
|
|
31798
|
+
*/
|
|
31799
|
+
function paymentsMembership(view) {
|
|
31800
|
+
return view?.status === "active" && view.myKey ? {
|
|
31801
|
+
me: view.myKey,
|
|
31802
|
+
members: new Set(view.members.map((m) => m.key)),
|
|
31803
|
+
since: view.createdAt
|
|
31804
|
+
} : void 0;
|
|
31805
|
+
}
|
|
31806
|
+
/** The keys a note of mine names: one of them is mine as the member I was when I said it. */
|
|
31807
|
+
var named = (frame) => [
|
|
31808
|
+
frame.f,
|
|
31809
|
+
frame.to,
|
|
31810
|
+
...frame.by ? [frame.by] : []
|
|
31811
|
+
];
|
|
31368
31812
|
var GroupPayments = class {
|
|
31369
31813
|
host;
|
|
31370
31814
|
notes = /* @__PURE__ */ new Map();
|
|
31371
31815
|
/** Per group, the ids of others' notes still `undescribed`, oldest first. */
|
|
31372
31816
|
waiting = /* @__PURE__ */ new Map();
|
|
31817
|
+
/** Counts the groups forgotten (`forget`): a pass under way asks again whether it is still in a group. */
|
|
31818
|
+
forgotten = 0;
|
|
31819
|
+
/** Per group, how many times it was forgotten in this run: notes read from its history before that are not kept. */
|
|
31820
|
+
ends = /* @__PURE__ */ new Map();
|
|
31373
31821
|
queue = Promise.resolve();
|
|
31374
31822
|
constructor(host) {
|
|
31375
31823
|
this.host = host;
|
|
@@ -31379,8 +31827,9 @@ var GroupPayments = class {
|
|
|
31379
31827
|
return this.run(async () => {
|
|
31380
31828
|
const frame = parseGroupPay(raw, groupId), membership = this.host.membership(groupId);
|
|
31381
31829
|
if (!frame || !membership) return;
|
|
31382
|
-
const
|
|
31383
|
-
|
|
31830
|
+
const notes = await this.load(groupId);
|
|
31831
|
+
const next = mergeGroupPay(notes.get(frame.id), frame, author, membership.members);
|
|
31832
|
+
if (next) await this.write(groupId, membership.me, next, notes);
|
|
31384
31833
|
});
|
|
31385
31834
|
}
|
|
31386
31835
|
/** Says what changed about this device's own payments in groups. The engine calls it whenever payments change. */
|
|
@@ -31390,7 +31839,9 @@ var GroupPayments = class {
|
|
|
31390
31839
|
/** An edge came up: the member hears again what I said lately, in case it missed it. */
|
|
31391
31840
|
edgeReady(groupId, linkId) {
|
|
31392
31841
|
return this.run(async () => {
|
|
31393
|
-
const
|
|
31842
|
+
const me = this.host.membership(groupId)?.me;
|
|
31843
|
+
if (!me) return;
|
|
31844
|
+
const mine = [...(await this.load(groupId)).values()].filter((n) => n.mine && named(n.mine).includes(me)).sort((a, b) => b.createdAt - a.createdAt).slice(0, RESEND);
|
|
31394
31845
|
for (const note of mine.reverse()) try {
|
|
31395
31846
|
this.host.send(linkId, note.mine);
|
|
31396
31847
|
} catch {
|
|
@@ -31398,6 +31849,17 @@ var GroupPayments = class {
|
|
|
31398
31849
|
}
|
|
31399
31850
|
});
|
|
31400
31851
|
}
|
|
31852
|
+
/**
|
|
31853
|
+
* A group left or forgotten here (its history went with it; switching to another group under its id forgets it
|
|
31854
|
+
* first): what this run kept of its notes goes too. A later membership under the same id, mine again by its link or
|
|
31855
|
+
* another group's, starts with none of them.
|
|
31856
|
+
*/
|
|
31857
|
+
forget(groupId) {
|
|
31858
|
+
this.notes.delete(groupId);
|
|
31859
|
+
this.waiting.delete(groupId);
|
|
31860
|
+
this.ends.set(groupId, (this.ends.get(groupId) ?? 0) + 1);
|
|
31861
|
+
this.forgotten++;
|
|
31862
|
+
}
|
|
31401
31863
|
run(task) {
|
|
31402
31864
|
const next = this.queue.then(task, task);
|
|
31403
31865
|
this.queue = next.catch(() => {});
|
|
@@ -31406,7 +31868,12 @@ var GroupPayments = class {
|
|
|
31406
31868
|
async author() {
|
|
31407
31869
|
const all = this.host.payments();
|
|
31408
31870
|
const known = /* @__PURE__ */ new Map();
|
|
31871
|
+
let forgotten = this.forgotten;
|
|
31409
31872
|
const membership = (groupId) => {
|
|
31873
|
+
if (forgotten !== this.forgotten) {
|
|
31874
|
+
known.clear();
|
|
31875
|
+
forgotten = this.forgotten;
|
|
31876
|
+
}
|
|
31410
31877
|
if (!known.has(groupId)) known.set(groupId, this.host.membership(groupId));
|
|
31411
31878
|
return known.get(groupId);
|
|
31412
31879
|
};
|
|
@@ -31419,24 +31886,30 @@ var GroupPayments = class {
|
|
|
31419
31886
|
for (const p of all) {
|
|
31420
31887
|
const at = this.placement(p, membership);
|
|
31421
31888
|
if (!at) continue;
|
|
31422
|
-
const
|
|
31889
|
+
const notes = await this.load(at.groupId);
|
|
31890
|
+
const current = notes.get(paymentWireId(p.id));
|
|
31423
31891
|
const frame = authoredNote(p, at, answers.get(p.id) ?? [], current, (linkId) => this.host.edgeOf(linkId)?.member, (federation) => this.host.federationNetwork?.(federation));
|
|
31424
|
-
if (!frame
|
|
31425
|
-
const
|
|
31892
|
+
if (!frame) continue;
|
|
31893
|
+
const members = membership(at.groupId).members;
|
|
31894
|
+
if (!believed(current, frame, at.me, members)) continue;
|
|
31895
|
+
const next = mergeGroupPay(current, frame, at.me, members);
|
|
31896
|
+
if (!next && JSON.stringify(frame) === JSON.stringify(current?.mine)) continue;
|
|
31897
|
+
const merged = next ?? current;
|
|
31426
31898
|
if (!merged) continue;
|
|
31427
|
-
await this.write(at.groupId, at.me, {
|
|
31899
|
+
if (!await this.write(at.groupId, at.me, {
|
|
31428
31900
|
...merged,
|
|
31429
31901
|
mine: frame
|
|
31430
|
-
});
|
|
31902
|
+
}, notes)) continue;
|
|
31431
31903
|
for (const linkId of this.host.edges(at.groupId).values()) try {
|
|
31432
31904
|
this.host.send(linkId, frame);
|
|
31433
31905
|
} catch {}
|
|
31434
31906
|
}
|
|
31435
31907
|
}
|
|
31436
31908
|
placement(p, membership) {
|
|
31909
|
+
const current = (m) => !!m && !(p.direction === "out" && m.since !== void 0 && p.createdAt < m.since);
|
|
31437
31910
|
if (p.group) {
|
|
31438
31911
|
const m = membership(p.group);
|
|
31439
|
-
return m ? {
|
|
31912
|
+
return current(m) ? {
|
|
31440
31913
|
groupId: p.group,
|
|
31441
31914
|
me: m.me
|
|
31442
31915
|
} : void 0;
|
|
@@ -31444,7 +31917,7 @@ var GroupPayments = class {
|
|
|
31444
31917
|
const edge = this.host.edgeOf(p.linkId);
|
|
31445
31918
|
if (!edge) return void 0;
|
|
31446
31919
|
const m = membership(edge.groupId);
|
|
31447
|
-
return m ? {
|
|
31920
|
+
return current(m) ? {
|
|
31448
31921
|
groupId: edge.groupId,
|
|
31449
31922
|
me: m.me,
|
|
31450
31923
|
peer: edge.member
|
|
@@ -31453,14 +31926,19 @@ var GroupPayments = class {
|
|
|
31453
31926
|
async load(groupId) {
|
|
31454
31927
|
let notes = this.notes.get(groupId);
|
|
31455
31928
|
if (!notes) {
|
|
31929
|
+
const ends = this.ends.get(groupId);
|
|
31456
31930
|
notes = new Map((await this.host.messages(groupId)).filter((m) => m.groupPay).map((m) => [m.groupPay.id, m.groupPay]));
|
|
31457
|
-
this.notes.set(groupId, notes);
|
|
31931
|
+
if (this.ends.get(groupId) === ends) this.notes.set(groupId, notes);
|
|
31458
31932
|
}
|
|
31459
31933
|
return notes;
|
|
31460
31934
|
}
|
|
31461
|
-
|
|
31462
|
-
|
|
31463
|
-
|
|
31935
|
+
/**
|
|
31936
|
+
* Keeps `note` in `notes` (the group's, as `load` gave them) and in the group's history; false when the group was
|
|
31937
|
+
* forgotten since they were loaded: nothing goes back into a history that is gone.
|
|
31938
|
+
*/
|
|
31939
|
+
async write(groupId, me, note, notes) {
|
|
31940
|
+
if (this.notes.get(groupId) !== notes) return false;
|
|
31941
|
+
notes.set(note.id, note);
|
|
31464
31942
|
let waiting = this.waiting.get(groupId);
|
|
31465
31943
|
if (note.undescribed && !note.mine) {
|
|
31466
31944
|
if (!waiting) this.waiting.set(groupId, waiting = /* @__PURE__ */ new Set());
|
|
@@ -31468,10 +31946,10 @@ var GroupPayments = class {
|
|
|
31468
31946
|
for (const id of waiting) {
|
|
31469
31947
|
if (waiting.size <= 256) break;
|
|
31470
31948
|
waiting.delete(id);
|
|
31471
|
-
notes
|
|
31949
|
+
notes.delete(id);
|
|
31472
31950
|
}
|
|
31473
31951
|
} else waiting?.delete(note.id);
|
|
31474
|
-
if (note.undescribed) return;
|
|
31952
|
+
if (note.undescribed) return true;
|
|
31475
31953
|
const initiator = note.kind === "request" ? note.to : note.from;
|
|
31476
31954
|
await this.host.putMessage({
|
|
31477
31955
|
linkId: `group:${groupId}`,
|
|
@@ -31483,6 +31961,7 @@ var GroupPayments = class {
|
|
|
31483
31961
|
via: "datalink",
|
|
31484
31962
|
groupPay: note
|
|
31485
31963
|
});
|
|
31964
|
+
return true;
|
|
31486
31965
|
}
|
|
31487
31966
|
};
|
|
31488
31967
|
/** A plain line for previews and old views; the group page draws the note itself. */
|
|
@@ -31728,7 +32207,8 @@ var GroupEdits = class {
|
|
|
31728
32207
|
}
|
|
31729
32208
|
/**
|
|
31730
32209
|
* An edit past what a member's window takes: kept, the highest number per message, `GROUP_EDITS_HELD` messages a
|
|
31731
|
-
* group at most (the oldest go first), and taken when the window has room. The work
|
|
32210
|
+
* group at most (the oldest of the member holding the most go first), and taken when the window has room. The work
|
|
32211
|
+
* stays what the window allows.
|
|
31732
32212
|
*/
|
|
31733
32213
|
hold(groupId, sender, edit, pace) {
|
|
31734
32214
|
const key = `${groupId}\n${sender}`;
|
|
@@ -31742,13 +32222,18 @@ var GroupEdits = class {
|
|
|
31742
32222
|
waiting.set(edit.id, edit);
|
|
31743
32223
|
let count = 0;
|
|
31744
32224
|
for (const member of group.values()) count += member.size;
|
|
31745
|
-
|
|
31746
|
-
|
|
31747
|
-
|
|
31748
|
-
|
|
31749
|
-
|
|
32225
|
+
while (count > 256) {
|
|
32226
|
+
let most = key;
|
|
32227
|
+
for (const [member, edits] of group) if (edits.size > group.get(most).size) most = member;
|
|
32228
|
+
const edits = group.get(most);
|
|
32229
|
+
let oldest = edits.keys().next().value;
|
|
32230
|
+
for (const [id, held] of edits) if (!held.rm) {
|
|
32231
|
+
oldest = id;
|
|
32232
|
+
break;
|
|
31750
32233
|
}
|
|
31751
|
-
|
|
32234
|
+
edits.delete(oldest);
|
|
32235
|
+
count--;
|
|
32236
|
+
if (!edits.size && most !== key) group.delete(most);
|
|
31752
32237
|
}
|
|
31753
32238
|
if (!this.heldTimers.has(key) && !this.stopped) this.heldTimers.set(key, setTimeout(() => {
|
|
31754
32239
|
this.takeHeld(groupId, sender).catch(() => {});
|
|
@@ -31826,6 +32311,7 @@ var GroupEdits = class {
|
|
|
31826
32311
|
const next = withEdit(current, {
|
|
31827
32312
|
seq: edit.e,
|
|
31828
32313
|
at: heardTime(edit.ts),
|
|
32314
|
+
heardAt: this.now(),
|
|
31829
32315
|
text: edit.m,
|
|
31830
32316
|
card: edit.sc
|
|
31831
32317
|
});
|
|
@@ -34419,6 +34905,11 @@ function amountlessUnderOptions(info) {
|
|
|
34419
34905
|
}
|
|
34420
34906
|
};
|
|
34421
34907
|
}
|
|
34908
|
+
/**
|
|
34909
|
+
* An invoice from the mint, with `label` as its description when the mint says it takes one. NUT-04's `description` is
|
|
34910
|
+
* optional: cashu-ts refuses to ask a mint that leaves it out for an invoice with one, and the label is only a label.
|
|
34911
|
+
*/
|
|
34912
|
+
var mintInvoice = (wallet, amount, label) => wallet.createMintQuoteBolt11(amount, wallet.getMintInfo().supportsNut04Description?.("bolt11", UNIT$1) === false ? void 0 : label);
|
|
34422
34913
|
/** A Lightning payment can stay in flight for minutes or hours; the mint is asked again this often. */
|
|
34423
34914
|
var MELT_POLL_MS = 3e4;
|
|
34424
34915
|
/** Once its request can no longer land, a payment still pending is asked twice as late each time, up to this. */
|
|
@@ -34494,7 +34985,7 @@ function normalizeMintUrl(input) {
|
|
|
34494
34985
|
}
|
|
34495
34986
|
function assertAmount(amount) {
|
|
34496
34987
|
if (!Number.isSafeInteger(amount) || amount <= 0) throw new Error("Enter an amount in sats");
|
|
34497
|
-
if (amount > MAX_AMOUNT) throw new Error(`Amounts above ${MAX_AMOUNT.toLocaleString()} sats are not supported`);
|
|
34988
|
+
if (amount > MAX_AMOUNT) throw new Error(`Amounts above ${MAX_AMOUNT.toLocaleString("en-US")} sats are not supported`);
|
|
34498
34989
|
}
|
|
34499
34990
|
/** Stored proofs are plain objects (amounts as numbers), which is what the library calls ProofLike. */
|
|
34500
34991
|
var asProofLike = (proofs) => proofs;
|
|
@@ -34623,6 +35114,8 @@ var CashuWallet = class CashuWallet {
|
|
|
34623
35114
|
events;
|
|
34624
35115
|
getKnownMints;
|
|
34625
35116
|
wallets = /* @__PURE__ */ new Map();
|
|
35117
|
+
/** When the load in `wallets` of a mint failed: it is tried again once `MINT_FAILED_MS` passed. */
|
|
35118
|
+
failedLoads = /* @__PURE__ */ new Map();
|
|
34626
35119
|
names = /* @__PURE__ */ new Map();
|
|
34627
35120
|
infos = /* @__PURE__ */ new Map();
|
|
34628
35121
|
locks = /* @__PURE__ */ new Map();
|
|
@@ -34633,6 +35126,8 @@ var CashuWallet = class CashuWallet {
|
|
|
34633
35126
|
quoteAsked = /* @__PURE__ */ new Map();
|
|
34634
35127
|
/** Per quote the screen shows: until when (`watch`). */
|
|
34635
35128
|
quoteWatched = /* @__PURE__ */ new Map();
|
|
35129
|
+
/** Per open quote whose mint did not answer, or answered with an error: as `meltAsk`, on top of its own pace. */
|
|
35130
|
+
quoteAsk = new AskBackoff(INVOICE_PACE.missedMs, INVOICE_PACE.missedCapMs);
|
|
34636
35131
|
meltTimer = null;
|
|
34637
35132
|
/** Per pending melt: when it is asked about next and the wait before that, in this run (a restart asks at once). */
|
|
34638
35133
|
meltAsk = new AskBackoff(MELT_POLL_MS, MELT_SLOW_POLL_MS);
|
|
@@ -34830,7 +35325,7 @@ var CashuWallet = class CashuWallet {
|
|
|
34830
35325
|
for (const candidate of this.getMints(network)) try {
|
|
34831
35326
|
created = {
|
|
34832
35327
|
mint: candidate,
|
|
34833
|
-
response: await within$1(MINT_TIMEOUT_MS, (await this.wallet(candidate)
|
|
35328
|
+
response: await within$1(MINT_TIMEOUT_MS, mintInvoice(await this.wallet(candidate), amount, "Ghostly"), candidate)
|
|
34834
35329
|
};
|
|
34835
35330
|
break;
|
|
34836
35331
|
} catch (error) {
|
|
@@ -34862,6 +35357,7 @@ var CashuWallet = class CashuWallet {
|
|
|
34862
35357
|
const quote = (await this.quotes()).find((q) => q.invoice.toLowerCase() === wanted);
|
|
34863
35358
|
if (!quote) return false;
|
|
34864
35359
|
this.quoteWatched.set(quote.quote, Date.now() + INVOICE_PACE.watchMs);
|
|
35360
|
+
this.quoteAsk.forget(quote.quote);
|
|
34865
35361
|
await this.pollQuotes();
|
|
34866
35362
|
return true;
|
|
34867
35363
|
}
|
|
@@ -34899,7 +35395,7 @@ var CashuWallet = class CashuWallet {
|
|
|
34899
35395
|
assertAmount(amount);
|
|
34900
35396
|
const mint = this.getMints(network).find(paysItsOwnInvoices);
|
|
34901
35397
|
if (!mint) throw new Error("This wallet has no test mint to ask for test coins");
|
|
34902
|
-
const response = await within$1(MINT_TIMEOUT_MS, (await this.wallet(mint)
|
|
35398
|
+
const response = await within$1(MINT_TIMEOUT_MS, mintInvoice(await this.wallet(mint), amount, "Ghostly test coins"), mint);
|
|
34903
35399
|
const quote = {
|
|
34904
35400
|
quote: response.quote,
|
|
34905
35401
|
mint,
|
|
@@ -34962,21 +35458,22 @@ var CashuWallet = class CashuWallet {
|
|
|
34962
35458
|
}
|
|
34963
35459
|
const stored = new Set(quotes.map((q) => q.quote));
|
|
34964
35460
|
for (const pace of [this.quoteAsked, this.quoteWatched]) for (const id of pace.keys()) if (!stored.has(id)) pace.delete(id);
|
|
35461
|
+
this.quoteAsk.keepOnly(stored);
|
|
34965
35462
|
const open = quotes.filter((q) => !q.issuedUnclaimed && !q.held);
|
|
34966
35463
|
const at = Date.now();
|
|
34967
35464
|
for (const settled of await this.settleQuotes(open.filter((q) => now || this.nextAsk(q, at) <= at + INVOICE_PACE.dueSlackMs))) gone.add(settled);
|
|
34968
35465
|
const next = open.filter((q) => !gone.has(q.quote)).map((q) => this.nextAsk(q, Date.now()));
|
|
34969
35466
|
if (next.length) this.scheduleQuotes(Math.min(...next));
|
|
34970
35467
|
}
|
|
34971
|
-
/** When the mint is next asked about this quote. */
|
|
35468
|
+
/** When the mint is next asked about this quote: at its pace, and not before the wait its mint's silence earned. */
|
|
34972
35469
|
nextAsk(quote, now) {
|
|
34973
|
-
return nextInvoiceAsk({
|
|
35470
|
+
return Math.max(this.quoteAsk.at(quote.quote, 0), nextInvoiceAsk({
|
|
34974
35471
|
createdAt: quote.createdAt,
|
|
34975
35472
|
expiresAt: quote.expiresAt,
|
|
34976
35473
|
watchedUntil: this.quoteWatched.get(quote.quote),
|
|
34977
35474
|
closed: !!quote.paymentId && !!this.events.requestClosed?.(quote.paymentId),
|
|
34978
35475
|
paid: !!quote.paid
|
|
34979
|
-
}, this.quoteAsked.get(quote.quote), now);
|
|
35476
|
+
}, this.quoteAsked.get(quote.quote), now));
|
|
34980
35477
|
}
|
|
34981
35478
|
/** The next round at `at`, unless one is due sooner. */
|
|
34982
35479
|
scheduleQuotes(at) {
|
|
@@ -34989,19 +35486,37 @@ var CashuWallet = class CashuWallet {
|
|
|
34989
35486
|
this.pollQuotes();
|
|
34990
35487
|
}, Math.max(0, at - Date.now()));
|
|
34991
35488
|
}
|
|
34992
|
-
/**
|
|
35489
|
+
/**
|
|
35490
|
+
* Asks the mints about these quotes. Returns the ones minted. A quote whose mint does not answer, or answers with an
|
|
35491
|
+
* error, waits longer each time (`quoteAsk`); a mint that could not be loaded is not loaded again in this call for its
|
|
35492
|
+
* other quotes, which wait as that one does. The load runs outside the mint's lock, so a failed one does not hold it.
|
|
35493
|
+
*/
|
|
34993
35494
|
async settleQuotes(quotes) {
|
|
34994
35495
|
const minted = [];
|
|
35496
|
+
const down = /* @__PURE__ */ new Set();
|
|
34995
35497
|
for (const { quote, mint } of quotes.filter((q) => !q.issuedUnclaimed && !q.held)) {
|
|
34996
35498
|
this.quoteAsked.set(quote, Date.now());
|
|
35499
|
+
if (down.has(mint)) {
|
|
35500
|
+
this.quoteAsk.missed(quote, Date.now());
|
|
35501
|
+
continue;
|
|
35502
|
+
}
|
|
34997
35503
|
try {
|
|
35504
|
+
try {
|
|
35505
|
+
await this.wallet(mint);
|
|
35506
|
+
} catch (error) {
|
|
35507
|
+
down.add(mint);
|
|
35508
|
+
throw error;
|
|
35509
|
+
}
|
|
34998
35510
|
const paid = await this.locked(mint, () => this.settleQuote(quote));
|
|
35511
|
+
this.quoteAsk.forget(quote);
|
|
34999
35512
|
if (paid) {
|
|
35000
35513
|
minted.push(quote);
|
|
35001
35514
|
if (!paid.testCoins) this.events.onQuotePaid(paid);
|
|
35002
35515
|
this.events.onChange();
|
|
35003
35516
|
}
|
|
35004
|
-
} catch {
|
|
35517
|
+
} catch {
|
|
35518
|
+
this.quoteAsk.missed(quote, Date.now());
|
|
35519
|
+
}
|
|
35005
35520
|
}
|
|
35006
35521
|
return minted;
|
|
35007
35522
|
}
|
|
@@ -35190,7 +35705,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35190
35705
|
async recoverReviewedCashu(review, prepared) {
|
|
35191
35706
|
const stored = await openRow(STORES$1.payments, await wrap((await store(STORES$1.payments, "readonly")).get(review.id)));
|
|
35192
35707
|
if (stored?.token) return stored.token;
|
|
35193
|
-
const wallet = await this.wallet(prepared.mint);
|
|
35708
|
+
const wallet = await this.wallet(prepared.mint, true);
|
|
35194
35709
|
const { OutputData } = await loadCashu();
|
|
35195
35710
|
const keep = (prepared.swap.keepOutputs ?? []).map(OutputData.deserialize);
|
|
35196
35711
|
const send = (prepared.swap.sendOutputs ?? []).map(OutputData.deserialize);
|
|
@@ -35282,7 +35797,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35282
35797
|
const { OutputData, deserializeSwapPreview } = await loadCashu();
|
|
35283
35798
|
const preview = deserializeSwapPreview(prepared.swap);
|
|
35284
35799
|
if (!preview.inputs.length) return false;
|
|
35285
|
-
const wallet = await this.wallet(prepared.mint);
|
|
35800
|
+
const wallet = await this.wallet(prepared.mint, true);
|
|
35286
35801
|
const states = await wallet.checkProofsStates(preview.inputs.map((p) => ({
|
|
35287
35802
|
secret: p.secret,
|
|
35288
35803
|
id: p.id
|
|
@@ -35301,7 +35816,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35301
35816
|
const { OutputData, deserializeSwapPreview } = await loadCashu();
|
|
35302
35817
|
const preview = deserializeSwapPreview(prepared.swap);
|
|
35303
35818
|
if (!preview.inputs.length) return false;
|
|
35304
|
-
const wallet = await this.wallet(prepared.mint);
|
|
35819
|
+
const wallet = await this.wallet(prepared.mint, true);
|
|
35305
35820
|
const outputs = [...prepared.swap.keepOutputs ?? [], ...prepared.swap.sendOutputs ?? []].map(OutputData.deserialize);
|
|
35306
35821
|
if (await this.signedOutputs(wallet, outputs) !== "none") return false;
|
|
35307
35822
|
const states = await wallet.checkProofsStates(preview.inputs.map((p) => ({
|
|
@@ -35385,9 +35900,16 @@ var CashuWallet = class CashuWallet {
|
|
|
35385
35900
|
async reviewedCashuTakenBack(id) {
|
|
35386
35901
|
return (await wrap((await store(STORES$1.payments, "readonly")).get(id)))?.state === "reclaimed";
|
|
35387
35902
|
}
|
|
35903
|
+
/**
|
|
35904
|
+
* Whether a Take it back of this payment of ours is still written down: its redeem reached the mint, whose answer was
|
|
35905
|
+
* lost (`SwapUnsettledError`), and `pollSwaps` settles it. Its ecash reads SPENT meanwhile, by this wallet.
|
|
35906
|
+
*/
|
|
35907
|
+
async cashuTakingBack(id) {
|
|
35908
|
+
return (await this.readSwaps()).some((s) => s.kind === "receive" && !s.released && s.payment?.id === id && s.payment.direction === "out");
|
|
35909
|
+
}
|
|
35388
35910
|
async reviewedCashuSpent(prepared) {
|
|
35389
35911
|
const outputs = (prepared.swap.sendOutputs ?? []).map((await loadCashu()).OutputData.deserialize);
|
|
35390
|
-
const states = await (await this.wallet(prepared.mint)).checkProofsStates(outputs.map((o) => ({
|
|
35912
|
+
const states = await (await this.wallet(prepared.mint, true)).checkProofsStates(outputs.map((o) => ({
|
|
35391
35913
|
secret: new TextDecoder().decode(o.secret),
|
|
35392
35914
|
id: o.blindedMessage.id
|
|
35393
35915
|
})));
|
|
@@ -35475,8 +35997,12 @@ var CashuWallet = class CashuWallet {
|
|
|
35475
35997
|
...records(preview.amount.toNumber())
|
|
35476
35998
|
};
|
|
35477
35999
|
await this.putSwap(swap);
|
|
35478
|
-
}
|
|
35479
|
-
const
|
|
36000
|
+
} else if (payment && !this.swapAsk.due(swap.id, Date.now())) throw new SwapUnsettledError(swap);
|
|
36001
|
+
const sent = swap;
|
|
36002
|
+
const { keep } = await this.completeSwap(sent).catch((error) => {
|
|
36003
|
+
if (error instanceof SwapUnsettledError) this.swapAsk.missed(sent.id, Date.now());
|
|
36004
|
+
throw error;
|
|
36005
|
+
});
|
|
35480
36006
|
const credited = sats(keep);
|
|
35481
36007
|
if (swap.tx && credited !== swap.tx.amount) swap = {
|
|
35482
36008
|
...swap,
|
|
@@ -35710,8 +36236,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35710
36236
|
* payment then stays, marked `finished`, until the chat has been told (`tellSwap`). Returns whether it stored.
|
|
35711
36237
|
*/
|
|
35712
36238
|
async finishSwap(swap, keep, send, late) {
|
|
35713
|
-
const
|
|
35714
|
-
const inputs = (await this.allProofs()).filter((p) => p.mint === swap.mint && secrets.has(p.secret));
|
|
36239
|
+
const inputs = (await this.proofsOf(swap.kind === "send" ? swapOf(swap).inputs.map((p) => p.secret) : [])).filter((p) => p.mint === swap.mint);
|
|
35715
36240
|
const lost = swap.kind === "send" ? swapOf(swap).inputs.reduce((sum, p) => sum + Number(p.amount), 0) - sats(keep) - sats(send) : 0;
|
|
35716
36241
|
let stored = false;
|
|
35717
36242
|
await this.sealedTransact([
|
|
@@ -35787,8 +36312,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35787
36312
|
}
|
|
35788
36313
|
/** The proofs a split reserved, as they are stored now. */
|
|
35789
36314
|
async storedInputs(swap) {
|
|
35790
|
-
|
|
35791
|
-
return (await this.allProofs()).filter((p) => p.mint === swap.mint && p.reserved && secrets.has(p.secret));
|
|
36315
|
+
return (await this.proofsOf(swapOf(swap).inputs.map((p) => p.secret))).filter((p) => p.mint === swap.mint && p.reserved);
|
|
35792
36316
|
}
|
|
35793
36317
|
async swapsAt(mint) {
|
|
35794
36318
|
return (await this.readSwaps()).filter((s) => s.mint === mint);
|
|
@@ -35866,11 +36390,11 @@ var CashuWallet = class CashuWallet {
|
|
|
35866
36390
|
await this.putSwap(swap);
|
|
35867
36391
|
}
|
|
35868
36392
|
let outcome = await this.swapOutcome(swap);
|
|
35869
|
-
this.swapAsk.forget(id);
|
|
35870
36393
|
if (outcome.state === "never" && !outcome.final && swap.kind === "receive" && !swap.released) outcome = {
|
|
35871
36394
|
state: "open",
|
|
35872
36395
|
idle: true
|
|
35873
36396
|
};
|
|
36397
|
+
if (!(outcome.state === "open" && outcome.idle && swap.kind === "receive" && !swap.released)) this.swapAsk.forget(id);
|
|
35874
36398
|
if (outcome.state === "open") {
|
|
35875
36399
|
if (swap.released && Date.now() >= swap.createdAt + SWAP_WATCH_MS) {
|
|
35876
36400
|
await this.dropSwap(swap, /* @__PURE__ */ new Set());
|
|
@@ -35890,6 +36414,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35890
36414
|
const { deserializeSwapPreview } = await loadCashu();
|
|
35891
36415
|
try {
|
|
35892
36416
|
const { keep } = await (await this.wallet(mint)).completeSwap(deserializeSwapPreview(swapOf(swap)));
|
|
36417
|
+
this.swapAsk.forget(id);
|
|
35893
36418
|
if (await this.finishSwap(swap, keep, [], true)) {
|
|
35894
36419
|
const told = await this.tellSwap(swap, true);
|
|
35895
36420
|
if (swap.payment && told) await committed((await store(STORES$1.swaps, "readwrite")).delete(swap.id));
|
|
@@ -35918,7 +36443,7 @@ var CashuWallet = class CashuWallet {
|
|
|
35918
36443
|
await this.dropSwap(swap, refusal.gone);
|
|
35919
36444
|
await this.tellSwap(swap, false);
|
|
35920
36445
|
this.events.onChange();
|
|
35921
|
-
} else later(
|
|
36446
|
+
} else later(this.swapAsk.missed(id, Date.now()));
|
|
35922
36447
|
}
|
|
35923
36448
|
} else if (outcome.pending && swap.kind === "receive" && !swap.released && Date.now() >= swapOverdueAt(swap)) {
|
|
35924
36449
|
if (Date.now() < swap.createdAt + SWAP_WATCH_MS) {
|
|
@@ -36080,6 +36605,9 @@ var CashuWallet = class CashuWallet {
|
|
|
36080
36605
|
if (swap) stores[STORES$1.swaps].delete(swap.id);
|
|
36081
36606
|
});
|
|
36082
36607
|
this.shownQuotes.delete(quoteId);
|
|
36608
|
+
const unpaid = () => {
|
|
36609
|
+
this.shownQuotes.set(quoteId, shown);
|
|
36610
|
+
};
|
|
36083
36611
|
let result;
|
|
36084
36612
|
try {
|
|
36085
36613
|
result = await wallet.completeMelt(preview);
|
|
@@ -36087,6 +36615,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36087
36615
|
if (!mintRefused(error) && !(error instanceof MeltChangeError)) return "pending";
|
|
36088
36616
|
const outcome = await this.settleMelt(melt, true).catch(() => "pending");
|
|
36089
36617
|
if (outcome === "unpaid") {
|
|
36618
|
+
unpaid();
|
|
36090
36619
|
const lost = this.takeFailedFee(melt.quote);
|
|
36091
36620
|
if (this.spentAway.delete(melt.quote)) throw Object.assign(engineError("ecashAlreadySpent"), { cause: error });
|
|
36092
36621
|
if (lost > 0) throw Object.assign(/* @__PURE__ */ new Error(`${error instanceof Error ? error.message : String(error)} ${backInWallet(lost)}`), { cause: error });
|
|
@@ -36098,7 +36627,9 @@ var CashuWallet = class CashuWallet {
|
|
|
36098
36627
|
await this.finishMelt(melt, result.change);
|
|
36099
36628
|
return "paid";
|
|
36100
36629
|
}
|
|
36101
|
-
|
|
36630
|
+
const outcome = await this.settleMelt(melt, true).catch(() => "pending");
|
|
36631
|
+
if (outcome === "unpaid") unpaid();
|
|
36632
|
+
return outcome;
|
|
36102
36633
|
}
|
|
36103
36634
|
/**
|
|
36104
36635
|
* Whether a Lightning payment of this invoice is written down as in flight. A melt is written before the mint sees
|
|
@@ -36251,8 +36782,7 @@ var CashuWallet = class CashuWallet {
|
|
|
36251
36782
|
}
|
|
36252
36783
|
}
|
|
36253
36784
|
async reservedProofs(melt) {
|
|
36254
|
-
|
|
36255
|
-
return (await this.allProofs()).filter((p) => secrets.has(p.secret));
|
|
36785
|
+
return this.proofsOf(melt.secrets);
|
|
36256
36786
|
}
|
|
36257
36787
|
/** Everything held, as one token per mint; `mints`: only these mints' (one network's wallet). */
|
|
36258
36788
|
async exportTokens(mints) {
|
|
@@ -36273,18 +36803,28 @@ var CashuWallet = class CashuWallet {
|
|
|
36273
36803
|
}
|
|
36274
36804
|
return out;
|
|
36275
36805
|
}
|
|
36276
|
-
|
|
36806
|
+
/**
|
|
36807
|
+
* A mint's loaded wallet. A failed load is tried again by the next caller, unless that one takes `recentFailure`
|
|
36808
|
+
* (a payment's reads in the poll): a load failed within `MINT_FAILED_MS` is its answer too.
|
|
36809
|
+
*/
|
|
36810
|
+
wallet(mint, recentFailure = false) {
|
|
36811
|
+
const failed = this.failedLoads.get(mint);
|
|
36277
36812
|
let wallet = this.wallets.get(mint);
|
|
36813
|
+
if (failed !== void 0 && !(recentFailure && Date.now() - failed < 5e3)) wallet = void 0;
|
|
36278
36814
|
if (!wallet) {
|
|
36279
|
-
|
|
36815
|
+
const loading = (async () => {
|
|
36280
36816
|
const instance = new (await (loadCashu())).Wallet(mint, { unit: UNIT$1 });
|
|
36281
36817
|
await within$1(MINT_TIMEOUT_MS, instance.loadMint(), mint);
|
|
36282
36818
|
const info = instance.getMintInfo();
|
|
36283
36819
|
if (info.isSupported(5).params.some(saysAmountlessBeside)) instance.loadMintFromCache(amountlessUnderOptions(info.cache), instance.keyChain.cache);
|
|
36284
36820
|
return instance;
|
|
36285
36821
|
})();
|
|
36286
|
-
|
|
36287
|
-
|
|
36822
|
+
wallet = loading;
|
|
36823
|
+
this.failedLoads.delete(mint);
|
|
36824
|
+
this.wallets.set(mint, loading);
|
|
36825
|
+
loading.catch(() => {
|
|
36826
|
+
if (this.wallets.get(mint) === loading) this.failedLoads.set(mint, Date.now());
|
|
36827
|
+
});
|
|
36288
36828
|
}
|
|
36289
36829
|
return wallet;
|
|
36290
36830
|
}
|
|
@@ -36313,6 +36853,21 @@ var CashuWallet = class CashuWallet {
|
|
|
36313
36853
|
async allProofs() {
|
|
36314
36854
|
return openRows(STORES$1.proofs, await wrap((await store(STORES$1.proofs, "readonly")).getAll()));
|
|
36315
36855
|
}
|
|
36856
|
+
/**
|
|
36857
|
+
* The stored proofs of these secrets, each read by its key: a swap's inputs cost what the swap holds, not the wallet.
|
|
36858
|
+
* With the data key, a proof is under the hash of its secret, or under the secret itself until the migration reseals it.
|
|
36859
|
+
*/
|
|
36860
|
+
async proofsOf(secrets) {
|
|
36861
|
+
const wanted = [...new Set(secrets)];
|
|
36862
|
+
if (wanted.length === 0) return [];
|
|
36863
|
+
const proofs = await store(STORES$1.proofs, "readonly");
|
|
36864
|
+
const sealed = hasDataKey();
|
|
36865
|
+
const found = await Promise.all(wanted.map(async (secret) => {
|
|
36866
|
+
const [hashed, plain] = await Promise.all([sealed ? wrap(proofs.get(proofKey(secret))) : void 0, wrap(proofs.get(secret))]);
|
|
36867
|
+
return hashed ?? plain;
|
|
36868
|
+
}));
|
|
36869
|
+
return openRows(STORES$1.proofs, found.filter((p) => p !== void 0));
|
|
36870
|
+
}
|
|
36316
36871
|
async readSwaps() {
|
|
36317
36872
|
return openRows(STORES$1.swaps, await wrap((await store(STORES$1.swaps, "readonly")).getAll()));
|
|
36318
36873
|
}
|
|
@@ -36356,6 +36911,15 @@ var UNIT = "sat";
|
|
|
36356
36911
|
/** A contact's requests in one chat: the new ones taken per minute, and how many may wait to be paid. */
|
|
36357
36912
|
var REQUESTS_PER_MINUTE = 20;
|
|
36358
36913
|
var OPEN_REQUESTS = 50;
|
|
36914
|
+
/**
|
|
36915
|
+
* A contact's ecash in one chat (Cashu and Fedimint `pay` frames): the new ones taken per minute. Each asks the mint
|
|
36916
|
+
* (under its lock, which this side's own payments there wait on) or the federation. One past it is refused unredeemed,
|
|
36917
|
+
* so the contact takes it back and can send it again a minute later.
|
|
36918
|
+
*/
|
|
36919
|
+
var PAYMENTS_PER_MINUTE = 10;
|
|
36920
|
+
var PAYMENTS_BUSY = "Too many payments at once: send it again in a minute";
|
|
36921
|
+
/** Refusal lines one chat gets in an hour; past it the contact is still told, and the chat stays as it is. */
|
|
36922
|
+
var REFUSAL_LINES_PER_HOUR = 5;
|
|
36359
36923
|
var INVOICE_CLAIMS_KEY = "invoicePaidClaims";
|
|
36360
36924
|
var sameClaim = (a, b) => a.linkId === b.linkId && a.invoice.toLowerCase() === b.invoice.toLowerCase();
|
|
36361
36925
|
var satsWord = (n) => `${n} sat${n === 1 ? "" : "s"}`;
|
|
@@ -36591,6 +37155,11 @@ var PaymentDesk = class {
|
|
|
36591
37155
|
reclaims = /* @__PURE__ */ new Map();
|
|
36592
37156
|
/** Receipts older than `RECEIPT_FRESH_MS` said again in this run of the app, by payment id (`receiptOwed`). */
|
|
36593
37157
|
receiptsSaid = /* @__PURE__ */ new Set();
|
|
37158
|
+
/**
|
|
37159
|
+
* Reviewed Cashu payments whose token went out in this run, by id: `replay` sends it again whenever the link opens
|
|
37160
|
+
* again, so reconciling one does not (`resendCashu`).
|
|
37161
|
+
*/
|
|
37162
|
+
cashuSent = /* @__PURE__ */ new Set();
|
|
36594
37163
|
checkingArk = false;
|
|
36595
37164
|
checkingUsdt = false;
|
|
36596
37165
|
checkingBark = false;
|
|
@@ -37242,6 +37811,16 @@ var PaymentDesk = class {
|
|
|
37242
37811
|
}
|
|
37243
37812
|
return running;
|
|
37244
37813
|
}
|
|
37814
|
+
/**
|
|
37815
|
+
* The Take it back of this payment under way, if one is: settles, never rejects, once it is over, with the
|
|
37816
|
+
* payment's state then (`reclaimed` when the ecash came back, `settled` when the contact had taken it first).
|
|
37817
|
+
* A status check waits for it: the mint reads ecash this wallet is taking back as spent too.
|
|
37818
|
+
*/
|
|
37819
|
+
takingBack(paymentId) {
|
|
37820
|
+
const running = this.reclaims.get(paymentId);
|
|
37821
|
+
const after = () => this.payments.get(paymentId)?.state;
|
|
37822
|
+
return running?.then(after, after);
|
|
37823
|
+
}
|
|
37245
37824
|
async reclaimOnce(paymentId) {
|
|
37246
37825
|
const payment = this.payments.get(paymentId);
|
|
37247
37826
|
if (payment?.target?.method === "fedimint" && payment.direction === "out" && payment.kind === "payment") {
|
|
@@ -37395,6 +37974,40 @@ var PaymentDesk = class {
|
|
|
37395
37974
|
for (const p of this.payments.values()) if (p.linkId === linkId && p.kind === "request" && p.direction === "in" && p.state === "pending" && ++open >= OPEN_REQUESTS) return false;
|
|
37396
37975
|
return true;
|
|
37397
37976
|
}
|
|
37977
|
+
/** New ecash taken from each chat's contact lately, and the refusal lines each chat got (with their latest ids). */
|
|
37978
|
+
paymentsFrom = /* @__PURE__ */ new Map();
|
|
37979
|
+
refusalLines = /* @__PURE__ */ new Map();
|
|
37980
|
+
/** Whether this chat has room for one more new payment of its contact's ecash (`PAYMENTS_PER_MINUTE`). */
|
|
37981
|
+
roomForPayment(linkId) {
|
|
37982
|
+
let recent = this.paymentsFrom.get(linkId);
|
|
37983
|
+
if (!recent) this.paymentsFrom.set(linkId, recent = new RateWindow(PAYMENTS_PER_MINUTE, 6e4));
|
|
37984
|
+
return recent.take();
|
|
37985
|
+
}
|
|
37986
|
+
/**
|
|
37987
|
+
* Stores a refusal line in its chat, unless the chat had `REFUSAL_LINES_PER_HOUR` already. One stored again under an
|
|
37988
|
+
* id the chat got lately (spent ecash sent again) adds no line, and is not counted. Never throws: the contact was told.
|
|
37989
|
+
*/
|
|
37990
|
+
async refusalLine(linkId, id, line, timestamp) {
|
|
37991
|
+
let lines = this.refusalLines.get(linkId);
|
|
37992
|
+
if (!lines) this.refusalLines.set(linkId, lines = {
|
|
37993
|
+
recent: new RateWindow(REFUSAL_LINES_PER_HOUR, 36e5),
|
|
37994
|
+
ids: []
|
|
37995
|
+
});
|
|
37996
|
+
if (!lines.ids.includes(id)) {
|
|
37997
|
+
if (!lines.recent.take()) return;
|
|
37998
|
+
lines.ids = [...lines.ids, id].slice(-5);
|
|
37999
|
+
}
|
|
38000
|
+
try {
|
|
38001
|
+
await this.host.storeMessage({
|
|
38002
|
+
linkId,
|
|
38003
|
+
id,
|
|
38004
|
+
...line,
|
|
38005
|
+
sender: "peer",
|
|
38006
|
+
timestamp,
|
|
38007
|
+
via: "datalink"
|
|
38008
|
+
});
|
|
38009
|
+
} catch {}
|
|
38010
|
+
}
|
|
37398
38011
|
/** `held`: picked up from the contact's storage while it was away (WISP 404): only what this device allows counts, and only Cashu or Lightning. */
|
|
37399
38012
|
async onPaymentRequest(linkId, request, held = false) {
|
|
37400
38013
|
if (this.find(linkId, request.id)?.linkId === linkId) return;
|
|
@@ -37561,6 +38174,14 @@ var PaymentDesk = class {
|
|
|
37561
38174
|
});
|
|
37562
38175
|
return;
|
|
37563
38176
|
}
|
|
38177
|
+
if (!this.roomForPayment(linkId)) {
|
|
38178
|
+
link?.sendPaymentResult({
|
|
38179
|
+
id: payment.id,
|
|
38180
|
+
ok: false,
|
|
38181
|
+
error: PAYMENTS_BUSY
|
|
38182
|
+
});
|
|
38183
|
+
return;
|
|
38184
|
+
}
|
|
37564
38185
|
if (!link?.allowsPayment("cashu")) {
|
|
37565
38186
|
link?.sendPaymentResult({
|
|
37566
38187
|
id: payment.id,
|
|
@@ -37640,21 +38261,11 @@ var PaymentDesk = class {
|
|
|
37640
38261
|
const sats = parseSats(payment.amount.value, payment.amount.asset);
|
|
37641
38262
|
const spent = error instanceof EngineError && error.engineCode === "ecashAlreadySpent";
|
|
37642
38263
|
const network = inspected?.kind === "token" ? mintNetwork(inspected.mint) : void 0;
|
|
37643
|
-
|
|
38264
|
+
await this.refusalLine(linkId, spent ? `peer_spent_${digestHex(token).slice(0, 32)}` : `peer_${payment.timestamp}_refused`, refusedRow({
|
|
37644
38265
|
amount: sats ?? void 0,
|
|
37645
38266
|
network,
|
|
37646
38267
|
reason
|
|
37647
|
-
});
|
|
37648
|
-
try {
|
|
37649
|
-
await this.host.storeMessage({
|
|
37650
|
-
linkId,
|
|
37651
|
-
id: spent ? `peer_spent_${digestHex(token).slice(0, 32)}` : `peer_${payment.timestamp}_refused`,
|
|
37652
|
-
...line,
|
|
37653
|
-
sender: "peer",
|
|
37654
|
-
timestamp: payment.timestamp,
|
|
37655
|
-
via: "datalink"
|
|
37656
|
-
});
|
|
37657
|
-
} catch {}
|
|
38268
|
+
}), payment.timestamp);
|
|
37658
38269
|
}
|
|
37659
38270
|
}
|
|
37660
38271
|
/**
|
|
@@ -37716,21 +38327,11 @@ var PaymentDesk = class {
|
|
|
37716
38327
|
ok: false,
|
|
37717
38328
|
error: reason
|
|
37718
38329
|
});
|
|
37719
|
-
|
|
38330
|
+
await this.refusalLine(record.linkId, `peer_${record.createdAt}_refused`, refusedRow({
|
|
37720
38331
|
amount: record.amount,
|
|
37721
38332
|
network: record.mint ? mintNetwork(record.mint) : void 0,
|
|
37722
38333
|
reason
|
|
37723
|
-
});
|
|
37724
|
-
try {
|
|
37725
|
-
await this.host.storeMessage({
|
|
37726
|
-
linkId: record.linkId,
|
|
37727
|
-
id: `peer_${record.createdAt}_refused`,
|
|
37728
|
-
...line,
|
|
37729
|
-
sender: "peer",
|
|
37730
|
-
timestamp: record.createdAt,
|
|
37731
|
-
via: "datalink"
|
|
37732
|
-
});
|
|
37733
|
-
} catch {}
|
|
38334
|
+
}), record.createdAt);
|
|
37734
38335
|
}
|
|
37735
38336
|
async onPaymentResult(linkId, result) {
|
|
37736
38337
|
const payment = this.find(linkId, result.id);
|
|
@@ -38239,11 +38840,13 @@ var PaymentDesk = class {
|
|
|
38239
38840
|
async recordCashu(review, token) {
|
|
38240
38841
|
if (!review.linkId || review.method !== "cashu") throw new Error("Cashu chat recipient missing");
|
|
38241
38842
|
const link = this.requireLink(review.linkId);
|
|
38242
|
-
await link.requirePaymentSupport();
|
|
38243
38843
|
const existing = await openRow(STORES$1.payments, await wrap((await store(STORES$1.payments, "readonly")).get(review.id)));
|
|
38244
38844
|
if (!existing || existing.linkId !== review.linkId || existing.requestId !== review.requestId) throw new Error("Cashu outbox does not match the reviewed payment");
|
|
38845
|
+
if (!await this.cashuSendable(this.payments.get(existing.id) ?? existing)) return;
|
|
38245
38846
|
this.payments.set(existing.id, existing);
|
|
38246
38847
|
this.host.onChange();
|
|
38848
|
+
await link.requirePaymentSupport();
|
|
38849
|
+
if (!await this.cashuSendable(this.payments.get(existing.id) ?? existing)) return;
|
|
38247
38850
|
await this.host.storeMessage({
|
|
38248
38851
|
linkId: review.linkId,
|
|
38249
38852
|
id: `me_${review.createdAt}`,
|
|
@@ -38264,6 +38867,24 @@ var PaymentDesk = class {
|
|
|
38264
38867
|
memo: review.memo,
|
|
38265
38868
|
endpoint: [ENDPOINT.cashu, token]
|
|
38266
38869
|
});
|
|
38870
|
+
this.cashuSent.add(review.id);
|
|
38871
|
+
}
|
|
38872
|
+
async cashuSendable(payment) {
|
|
38873
|
+
return payment.state === "pending" && !await this.cashuTakingBack(payment.id);
|
|
38874
|
+
}
|
|
38875
|
+
/**
|
|
38876
|
+
* A Take it back of this payment under way: running here, or its redeem written down after the mint's answer was lost
|
|
38877
|
+
* (`CashuWallet.cashuTakingBack`), whose ecash the mint already reads spent. Unreadable: not sent now, asked again.
|
|
38878
|
+
*/
|
|
38879
|
+
async cashuTakingBack(id) {
|
|
38880
|
+
return this.reclaims.has(id) || await Promise.resolve(this.wallet.cashuTakingBack?.(id)).then(Boolean, () => true);
|
|
38881
|
+
}
|
|
38882
|
+
/**
|
|
38883
|
+
* A reviewed Cashu payment's token again, as reconciling it asks: only if it never went in this run. One that went is
|
|
38884
|
+
* the same token on the same link, and `replay` sends it again when the link opens again (a contact who missed it).
|
|
38885
|
+
*/
|
|
38886
|
+
async resendCashu(review, token) {
|
|
38887
|
+
if (!this.cashuSent.has(review.id)) await this.recordCashu(review, token);
|
|
38267
38888
|
}
|
|
38268
38889
|
async confirmReviewedCashu(review) {
|
|
38269
38890
|
if (review.method !== "cashu" || review.state !== "settled") return;
|
|
@@ -38746,22 +39367,12 @@ var PaymentDesk = class {
|
|
|
38746
39367
|
ok: false,
|
|
38747
39368
|
error: reason
|
|
38748
39369
|
});
|
|
38749
|
-
|
|
39370
|
+
await this.refusalLine(linkId, `peer_${payment.timestamp}_refused`, refusedRow({
|
|
38750
39371
|
amount: parseSats(payment.amount.value, payment.amount.asset) ?? void 0,
|
|
38751
39372
|
network,
|
|
38752
39373
|
method: "fedimint",
|
|
38753
39374
|
reason
|
|
38754
|
-
});
|
|
38755
|
-
try {
|
|
38756
|
-
await this.host.storeMessage({
|
|
38757
|
-
linkId,
|
|
38758
|
-
id: `peer_${payment.timestamp}_refused`,
|
|
38759
|
-
...line,
|
|
38760
|
-
sender: "peer",
|
|
38761
|
-
timestamp: payment.timestamp,
|
|
38762
|
-
via: "datalink"
|
|
38763
|
-
});
|
|
38764
|
-
} catch {}
|
|
39375
|
+
}), payment.timestamp);
|
|
38765
39376
|
};
|
|
38766
39377
|
if (!link?.allowsPayment("fedimint")) {
|
|
38767
39378
|
await refuse("Fedimint is off in this chat");
|
|
@@ -38807,6 +39418,14 @@ var PaymentDesk = class {
|
|
|
38807
39418
|
});
|
|
38808
39419
|
return;
|
|
38809
39420
|
}
|
|
39421
|
+
if (!this.roomForPayment(linkId)) {
|
|
39422
|
+
link.sendPaymentResult({
|
|
39423
|
+
id: payment.id,
|
|
39424
|
+
ok: false,
|
|
39425
|
+
error: PAYMENTS_BUSY
|
|
39426
|
+
});
|
|
39427
|
+
return;
|
|
39428
|
+
}
|
|
38810
39429
|
await this.save({
|
|
38811
39430
|
id: payment.id,
|
|
38812
39431
|
linkId,
|
|
@@ -38870,22 +39489,12 @@ var PaymentDesk = class {
|
|
|
38870
39489
|
ok: false,
|
|
38871
39490
|
error: "These notes were already redeemed"
|
|
38872
39491
|
});
|
|
38873
|
-
|
|
39492
|
+
await this.refusalLine(payment.linkId, `peer_${payment.createdAt}_refused`, refusedRow({
|
|
38874
39493
|
amount: payment.amount,
|
|
38875
39494
|
network: payment.network,
|
|
38876
39495
|
method: "fedimint",
|
|
38877
39496
|
reason: "These notes were already redeemed"
|
|
38878
|
-
});
|
|
38879
|
-
try {
|
|
38880
|
-
await this.host.storeMessage({
|
|
38881
|
-
linkId: payment.linkId,
|
|
38882
|
-
id: `peer_${payment.createdAt}_refused`,
|
|
38883
|
-
...line,
|
|
38884
|
-
sender: "peer",
|
|
38885
|
-
timestamp: payment.createdAt,
|
|
38886
|
-
via: "datalink"
|
|
38887
|
-
});
|
|
38888
|
-
} catch {}
|
|
39497
|
+
}), payment.createdAt);
|
|
38889
39498
|
return;
|
|
38890
39499
|
}
|
|
38891
39500
|
if (state) {
|
|
@@ -39323,6 +39932,7 @@ var PaymentDesk = class {
|
|
|
39323
39932
|
}
|
|
39324
39933
|
if (payment.state !== "pending") continue;
|
|
39325
39934
|
if (payment.kind === "payment" && payment.token) {
|
|
39935
|
+
if (await this.cashuTakingBack(payment.id)) continue;
|
|
39326
39936
|
await this.host.storeMessage(ecashLine(payment));
|
|
39327
39937
|
await this.sendTo(link, {
|
|
39328
39938
|
id: payment.id,
|
|
@@ -39335,6 +39945,7 @@ var PaymentDesk = class {
|
|
|
39335
39945
|
memo: payment.memo,
|
|
39336
39946
|
endpoint: [ENDPOINT.cashu, payment.token]
|
|
39337
39947
|
});
|
|
39948
|
+
this.cashuSent.add(payment.id);
|
|
39338
39949
|
} else if (payment.kind === "request" && (payment.invoice || payment.mints?.length)) await link.sendPaymentRequest({
|
|
39339
39950
|
id: payment.id,
|
|
39340
39951
|
timestamp: payment.createdAt,
|
|
@@ -40262,6 +40873,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40262
40873
|
* from a read of the store or a change of a review, and leaves when the poll finds its review ended or gone.
|
|
40263
40874
|
*/
|
|
40264
40875
|
openReviews = null;
|
|
40876
|
+
/**
|
|
40877
|
+
* The pace of each submitted Cashu payment the contact has not taken: asked at 10 s while new, then twice as late up
|
|
40878
|
+
* to 10 min (as a payee retries a redeem). At the poll's own 10 s, a contact online whose redeems fail cost the mint
|
|
40879
|
+
* 12 checkstates a minute for each such payment, for as long as the app ran. The contact taking one says so at once.
|
|
40880
|
+
*/
|
|
40881
|
+
cashuPayAsk = new AskBackoff(1e4, 6e5);
|
|
40265
40882
|
noteOpenReviews(reviews) {
|
|
40266
40883
|
const open = this.openReviews ??= /* @__PURE__ */ new Set();
|
|
40267
40884
|
for (const review of reviews) if (review.state === "submitted" || review.state === "unknown") open.add(review.id);
|
|
@@ -40381,10 +40998,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40381
40998
|
{
|
|
40382
40999
|
method: "cashu",
|
|
40383
41000
|
prepare: (target, amount, feeCap) => new CashuAdapter(this.wallet, (r, t) => this.desk.recordCashu(r, t)).prepare(target, amount, feeCap),
|
|
40384
|
-
execute: (review, prepared, persist) => new CashuAdapter(this.wallet, (r, t) => this.desk.recordCashu(r, t)).execute(review, prepared, persist),
|
|
41001
|
+
execute: (review, prepared, persist) => new CashuAdapter(this.wallet, (r, t) => this.desk.recordCashu(r, t), (id) => this.desk.takingBack(id)).execute(review, prepared, persist),
|
|
40385
41002
|
reconcile: (review, prepared, persist) => {
|
|
40386
41003
|
if (!persist) throw new Error("A Cashu payment is reconciled with its intent saved");
|
|
40387
|
-
return new CashuAdapter(this.wallet, (r, t) => this.desk.
|
|
41004
|
+
return new CashuAdapter(this.wallet, (r, t) => this.desk.resendCashu(r, t), (id) => this.desk.takingBack(id)).reconcile(review, prepared, persist);
|
|
40388
41005
|
}
|
|
40389
41006
|
}
|
|
40390
41007
|
], (review) => {
|
|
@@ -41371,7 +41988,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41371
41988
|
} : void 0;
|
|
41372
41989
|
},
|
|
41373
41990
|
edges: (groupId) => this.groups.isCommunityGroup(groupId) ? /* @__PURE__ */ new Map([["*", groupLinkId(groupId)]]) : this.memberEdges(groupId),
|
|
41374
|
-
membership: (groupId) => this.
|
|
41991
|
+
membership: (groupId) => paymentsMembership(this.groups.view(groupId)),
|
|
41375
41992
|
send: (linkId, frame) => {
|
|
41376
41993
|
const pay = parsePayLink(linkId);
|
|
41377
41994
|
if (pay) {
|
|
@@ -41673,15 +42290,21 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41673
42290
|
try {
|
|
41674
42291
|
if (!this.openReviews) this.noteOpenReviews((await intentRepository.list()).map((saved) => saved.review));
|
|
41675
42292
|
const open = this.openReviews;
|
|
42293
|
+
this.cashuPayAsk.keepOnly(open);
|
|
41676
42294
|
for (const id of [...open]) {
|
|
41677
|
-
|
|
42295
|
+
if (!this.cashuPayAsk.due(id, Date.now())) continue;
|
|
42296
|
+
const saved = await intentRepository.get(id), review = saved?.review;
|
|
41678
42297
|
if (!review || !["submitted", "unknown"].includes(review.state)) {
|
|
41679
42298
|
open.delete(id);
|
|
41680
42299
|
continue;
|
|
41681
42300
|
}
|
|
41682
42301
|
const network = walletNetworkOf(review.network);
|
|
41683
42302
|
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;
|
|
41684
|
-
await this.reconcilePayment({ id: review.id }).catch(() =>
|
|
42303
|
+
const after = await this.reconcilePayment({ id: review.id }).catch(() => review);
|
|
42304
|
+
if (review.method === "cashu" && ["submitted", "unknown"].includes(after.state)) {
|
|
42305
|
+
const prepared = saved.prepared;
|
|
42306
|
+
this.cashuPayAsk.missed(id, Date.now(), Date.now() < (prepared.token ? (review.submittedAt ?? review.createdAt) + 6e4 : swapSettledAt(review, prepared)));
|
|
42307
|
+
}
|
|
41685
42308
|
}
|
|
41686
42309
|
} finally {
|
|
41687
42310
|
if (!this.shuttingDown) this.paymentTimer = setTimeout(() => void this.pollPaymentStatus(), 1e4);
|
|
@@ -41715,6 +42338,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41715
42338
|
this.identities.start();
|
|
41716
42339
|
await this.did.load();
|
|
41717
42340
|
setOwnDidSource(() => this.did.id);
|
|
42341
|
+
setPkarrRelaySource(() => this.settings.relays);
|
|
41718
42342
|
this.did.start();
|
|
41719
42343
|
await this.contactLinks.load();
|
|
41720
42344
|
this.contactLinks.start();
|
|
@@ -41751,6 +42375,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41751
42375
|
this.links.set(stored.id, newLiveLink(stored, messages[messages.length - 1]?.timestamp ?? 0, files));
|
|
41752
42376
|
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
41753
42377
|
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
42378
|
+
this.editsFor(stored.id).learn([...messages, ...(stored.removals ?? []).map((r) => removalRow(stored.id, r))]);
|
|
41754
42379
|
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
41755
42380
|
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
41756
42381
|
const note = this.noteFromHistory(stored.id, messages);
|
|
@@ -42616,7 +43241,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42616
43241
|
prepareSpare(after = 0, aged = false) {
|
|
42617
43242
|
if (this.shuttingDown || !this.networkOn) return;
|
|
42618
43243
|
if (this.spare && after === 0 && (aged || Date.now() - this.spare.madeAt >= SPARE_INVITE_MAX_AGE_MS)) {
|
|
42619
|
-
|
|
43244
|
+
const keys = [identityFromSeedB64(this.spare.mine.seedB64), this.spare.inviteKey].map((identity) => identity.pubKeyZ32);
|
|
43245
|
+
for (const key of keys) this.warmedKeys.delete(key);
|
|
43246
|
+
this.transport.forget?.(keys);
|
|
42620
43247
|
this.spare = null;
|
|
42621
43248
|
}
|
|
42622
43249
|
if (!this.spare) this.spare = this.makeSpare();
|
|
@@ -43158,6 +43785,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43158
43785
|
groupHistoryGone(groupId) {
|
|
43159
43786
|
const linkId = `group:${groupId}`;
|
|
43160
43787
|
this.groupEdits.forget(groupId);
|
|
43788
|
+
this.groupPayments.forget(groupId);
|
|
43161
43789
|
this.newestAt.delete(linkId);
|
|
43162
43790
|
this.lateAt.delete(linkId);
|
|
43163
43791
|
for (const clock of this.clockLeads.keys()) if (clock.startsWith(`${linkId} `)) this.clockLeads.delete(clock);
|
|
@@ -43433,6 +44061,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43433
44061
|
if (!live || !live.link && !waitsForCheck) return { error: "You are offline" };
|
|
43434
44062
|
if (!trimmed) return { error: null };
|
|
43435
44063
|
const timestamp = params.timestamp ?? arrivalKey(Date.now(), this.placedAt.get(linkId));
|
|
44064
|
+
if (params.timestamp === void 0) this.placedAt.set(linkId, timestamp);
|
|
43436
44065
|
if (live.stored.profile) live.link?.setTyping(false);
|
|
43437
44066
|
if (live.stored.profile) {
|
|
43438
44067
|
const found = params.replyTo === void 0 ? void 0 : await this.replyFor(linkId, params.replyTo);
|
|
@@ -43923,9 +44552,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43923
44552
|
async applyPeerEditNow(linkId, message, edit) {
|
|
43924
44553
|
if (await db.patchMessage(linkId, message.id, (current) => {
|
|
43925
44554
|
if (!takesPeerEdit(current, edit.m) || (current.edit?.seq ?? 0) >= edit.e) return null;
|
|
44555
|
+
const now = Date.now();
|
|
43926
44556
|
const next = withEdit(current, {
|
|
43927
44557
|
seq: edit.e,
|
|
43928
|
-
at: heardTime(edit.ts),
|
|
44558
|
+
at: heardTime(edit.ts, now),
|
|
44559
|
+
heardAt: now,
|
|
43929
44560
|
text: edit.m,
|
|
43930
44561
|
preview: edit.pv,
|
|
43931
44562
|
card: edit.sc
|
|
@@ -44192,6 +44823,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44192
44823
|
const error = message.card ? await link.sendMessage(message.text, message.timestamp, message.wireId, message.preview, reply, message.forwarded, message.card) : message.forwarded ? await link.sendMessage(message.text, message.timestamp, message.wireId, message.preview, reply, message.forwarded) : reply ? await link.sendMessage(message.text, message.timestamp, message.wireId, message.preview, reply) : await link.sendMessage(message.text, message.timestamp, message.wireId, ...message.preview ? [message.preview] : []);
|
|
44193
44824
|
await this.noteTextSend(linkId, message, snapshot, at, error, link);
|
|
44194
44825
|
if (!error && message.via === "pkarr") await this.cardWentBare(linkId, message);
|
|
44826
|
+
if (error && message.via === "pkarr" && message.wireId && link.dhtWentNowhere(message.wireId)) return new NotSent(error);
|
|
44195
44827
|
return error;
|
|
44196
44828
|
}, (message) => message.via === "pkarr" ? DHT_MESSAGE_TTL : 2e4, (message) => {
|
|
44197
44829
|
const pending = this.links.get(linkId)?.stored.dhtDeliveryState?.pending;
|
|
@@ -44204,7 +44836,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44204
44836
|
return !!link?.canSendText && !!message.wireId && !link.validateText(message.text, message.timestamp, message.wireId, GhostlyNode.wireReply(message));
|
|
44205
44837
|
},
|
|
44206
44838
|
requeueExpired: () => !GhostlyNode.dhtByChoice(this.links.get(linkId)),
|
|
44207
|
-
...!!chat?.profile && !chat.group && { sendFile: (message) => this.sendWaitingFile(linkId, message) },
|
|
44839
|
+
...!!chat?.profile && !chat.group && { sendFile: (message, cancelled) => this.sendWaitingFile(linkId, message, cancelled) },
|
|
44208
44840
|
via: (message) => {
|
|
44209
44841
|
const delivery = this.links.get(linkId)?.link?.textDelivery;
|
|
44210
44842
|
return delivery === "dht" ? "pkarr" : delivery === "stream" ? "datalink" : message.via;
|
|
@@ -44480,6 +45112,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44480
45112
|
}
|
|
44481
45113
|
}
|
|
44482
45114
|
deleteMessage({ linkId, messageId }) {
|
|
45115
|
+
if (this.outboxes.get(linkId)?.cancel(messageId)) {
|
|
45116
|
+
this.removeMessage({
|
|
45117
|
+
linkId,
|
|
45118
|
+
messageId
|
|
45119
|
+
}).then(({ refused }) => refused ? this.forgetMessage(linkId, messageId) : void 0).catch(() => {});
|
|
45120
|
+
return;
|
|
45121
|
+
}
|
|
44483
45122
|
this.forgetMessage(linkId, messageId);
|
|
44484
45123
|
}
|
|
44485
45124
|
/**
|
|
@@ -44501,7 +45140,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44501
45140
|
if (!canRemove(message)) return refuse("A payment, a request or a notice cannot be deleted for everyone");
|
|
44502
45141
|
const out = `${linkId}-out-`;
|
|
44503
45142
|
const wireId = message.wireId ?? (message.file?.id.startsWith(out) ? message.file.id.slice(out.length) : void 0);
|
|
44504
|
-
|
|
45143
|
+
const going = this.outboxes.get(linkId)?.cancel(messageId) ?? false;
|
|
45144
|
+
if (!wireId || message.delivery === "waiting" && !going) {
|
|
44505
45145
|
await this.forgetMessage(linkId, messageId, message);
|
|
44506
45146
|
return { error: null };
|
|
44507
45147
|
}
|
|
@@ -44623,15 +45263,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44623
45263
|
}
|
|
44624
45264
|
if (message?.paymentId && message.delivery === "waiting") await this.desk.withdraw(message.paymentId).catch(() => {});
|
|
44625
45265
|
if (message?.paymentId && message.sender === "peer") await this.desk.dropReceipt(message.paymentId).catch(() => {});
|
|
44626
|
-
if (message?.sender === "me" && message.file && message.delivery === "waiting" && (message.fileOnFloor === "sent" || message.fileOnFloor === "seen")) {
|
|
44627
|
-
const wireId = message.file.id.slice(`${linkId}-out-`.length);
|
|
44628
|
-
live.link?.settleDht(dhtFileId(wireId)).catch(() => {});
|
|
44629
|
-
live.stored = {
|
|
44630
|
-
...live.stored,
|
|
44631
|
-
withdrawnFiles: [...(live.stored.withdrawnFiles ?? []).filter((id) => id !== wireId), wireId].slice(-64)
|
|
44632
|
-
};
|
|
44633
|
-
await db.patchLink(linkId, { withdrawnFiles: live.stored.withdrawnFiles });
|
|
44634
|
-
}
|
|
45266
|
+
if (message?.sender === "me" && message.file && message.delivery === "waiting" && (message.fileOnFloor === "sent" || message.fileOnFloor === "seen")) await this.withdrawFloorFile(live, message.file.id.slice(`${linkId}-out-`.length));
|
|
44635
45267
|
if (message?.file) {
|
|
44636
45268
|
const stored = await fileStore.get(message.file.id);
|
|
44637
45269
|
if (stored && !stored.wire3 && !stored.announced && (stored.direction === "in" || !stored.direction && message.sender === "peer")) live.files.receivedBytes = Math.max(0, live.files.receivedBytes - storedSize(stored));
|
|
@@ -44884,17 +45516,22 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44884
45516
|
* A file that waited for the chat to be live goes: said on the open session (see `transferFile`), and this returns
|
|
44885
45517
|
* then, so the chat's outbox sends it in its place among the texts that waited (WISP 400, requirement 10). A file
|
|
44886
45518
|
* for an app that turns out not to take files fails with that reason instead of waiting forever (WISP 03).
|
|
45519
|
+
* `cancelled`: whether it was deleted here since the outbox read it (`Outbox.cancel`); then nothing of it goes.
|
|
44887
45520
|
*/
|
|
44888
|
-
async sendWaitingFile(linkId, message) {
|
|
45521
|
+
async sendWaitingFile(linkId, message, cancelled) {
|
|
44889
45522
|
const live = this.links.get(linkId), file = message.file;
|
|
44890
|
-
if (live?.link && file && !live.link.isDataLinkOpen) return this.sayFileOnFloor(live, message);
|
|
45523
|
+
if (live?.link && file && !live.link.isDataLinkOpen) return this.sayFileOnFloor(live, message, cancelled);
|
|
44891
45524
|
if (!live?.link?.isDataLinkOpen || !file) return;
|
|
44892
45525
|
if (message.fileOnFloor === "sent" || message.fileOnFloor === "seen") live.link.settleDht(dhtFileId(file.id.slice(`${linkId}-out-`.length))).catch(() => {});
|
|
44893
45526
|
if (!GhostlyNode.takesFiles(live.link)) await GhostlyNode.largeFilesAgreed(live.link);
|
|
44894
|
-
if (!live.link.isDataLinkOpen) return;
|
|
45527
|
+
if (cancelled() || !live.link.isDataLinkOpen) return;
|
|
44895
45528
|
if (!GhostlyNode.takesFiles(live.link)) await db.updateDelivery(linkId, message.id, "failed", "Your contact's app cannot receive files.");
|
|
44896
45529
|
else {
|
|
44897
|
-
await db.
|
|
45530
|
+
if (!await db.patchMessage(linkId, message.id, (current) => current.delivery !== "waiting" ? null : {
|
|
45531
|
+
delivery: void 0,
|
|
45532
|
+
deliveryError: void 0,
|
|
45533
|
+
resendUntil: void 0
|
|
45534
|
+
}) || cancelled()) return;
|
|
44898
45535
|
await this.transferFile(live, file, file.id.slice(`${linkId}-out-`.length), message.timestamp, (error) => {
|
|
44899
45536
|
this.transfers.set(file.id, {
|
|
44900
45537
|
state: "failed",
|
|
@@ -44934,8 +45571,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44934
45571
|
/**
|
|
44935
45572
|
* Says a waiting file's offer on the DHT floor: the contact's chat shows its bubble in its place, and the bytes go once
|
|
44936
45573
|
* live (the file stays `waiting`). Once only: an offer that cannot go there (a name too long) waits as before.
|
|
45574
|
+
* `cancelled`: whether it was deleted here since the outbox read it (`Outbox.cancel`).
|
|
44937
45575
|
*/
|
|
44938
|
-
async sayFileOnFloor(live, message) {
|
|
45576
|
+
async sayFileOnFloor(live, message, cancelled = () => false) {
|
|
44939
45577
|
const link = live.link, file = message.file, linkId = live.stored.id;
|
|
44940
45578
|
if (!link || !file || message.fileOnFloor || !this.fileFloorReady(live, message)) return;
|
|
44941
45579
|
const offer = GhostlyNode.floorOffer(linkId, file), at = Date.now();
|
|
@@ -44950,9 +45588,22 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44950
45588
|
result: "sent"
|
|
44951
45589
|
}) }
|
|
44952
45590
|
});
|
|
44953
|
-
if (said &&
|
|
45591
|
+
if (said && cancelled()) await this.withdrawFloorFile(live, offer.wireId);
|
|
45592
|
+
else if (said && noted) await live.floorFiles?.then((known) => known.set(dhtFileId(offer.wireId), message.id), () => {});
|
|
44954
45593
|
await this.messagesChanged(linkId, [message.id]);
|
|
44955
45594
|
}
|
|
45595
|
+
/**
|
|
45596
|
+
* A file of mine said on the floor and deleted here before it went live: the floor stops saying it, and the next
|
|
45597
|
+
* session that carries files/3 tells the contact's bubble it was cancelled (`sayWithdrawnFiles`).
|
|
45598
|
+
*/
|
|
45599
|
+
async withdrawFloorFile(live, wireId) {
|
|
45600
|
+
live.link?.settleDht(dhtFileId(wireId)).catch(() => {});
|
|
45601
|
+
live.stored = {
|
|
45602
|
+
...live.stored,
|
|
45603
|
+
withdrawnFiles: [...(live.stored.withdrawnFiles ?? []).filter((id) => id !== wireId), wireId].slice(-64)
|
|
45604
|
+
};
|
|
45605
|
+
await db.patchLink(live.stored.id, { withdrawnFiles: live.stored.withdrawnFiles });
|
|
45606
|
+
}
|
|
44956
45607
|
/** A receipt on the DHT floor that names a waiting file's offer (`dhtFileId`): its bubble is in place on the contact's side. */
|
|
44957
45608
|
async fileSeenOnFloor(linkId, id) {
|
|
44958
45609
|
const live = this.links.get(linkId);
|
|
@@ -45088,7 +45739,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45088
45739
|
continue;
|
|
45089
45740
|
}
|
|
45090
45741
|
const file = message.file, wireId = file.id.slice(`${linkId}-out-`.length);
|
|
45091
|
-
await db.
|
|
45742
|
+
if (!await db.patchMessage(linkId, message.id, (current) => current.delivery !== "waiting" ? null : {
|
|
45743
|
+
delivery: void 0,
|
|
45744
|
+
deliveryError: void 0,
|
|
45745
|
+
resendUntil: void 0
|
|
45746
|
+
})) {
|
|
45747
|
+
known.delete(message.id);
|
|
45748
|
+
continue;
|
|
45749
|
+
}
|
|
45092
45750
|
this.transferFile(live, file, wireId, message.timestamp, (error) => {
|
|
45093
45751
|
this.transfers.set(file.id, {
|
|
45094
45752
|
state: "failed",
|
|
@@ -45374,12 +46032,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45374
46032
|
}
|
|
45375
46033
|
if (live?.stored.deliveryMode === "dht") {
|
|
45376
46034
|
const preferredTransport = transport === "auto" ? void 0 : transport;
|
|
46035
|
+
const native = transport === "auto" ? !live.link?.availableTransports.includes("webrtc/1") : transport !== "webrtc/1";
|
|
45377
46036
|
live.stored = {
|
|
45378
46037
|
...live.stored,
|
|
45379
46038
|
preferredTransport
|
|
45380
46039
|
};
|
|
45381
46040
|
await db.patchLink(linkId, { preferredTransport });
|
|
45382
|
-
await this.switchDeliveryMode(linkId, "stream",
|
|
46041
|
+
await this.switchDeliveryMode(linkId, "stream", native);
|
|
45383
46042
|
}
|
|
45384
46043
|
if (transport !== "auto") {
|
|
45385
46044
|
await this.setTransportPreference({
|
|
@@ -47716,14 +48375,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47716
48375
|
if (this.options.singleDevice) throw new Error("enroll-single: A profile of the command line is on one device only");
|
|
47717
48376
|
if (this.limitedMode) throw new Error(LIMITED_MODE_ERROR);
|
|
47718
48377
|
if (!this.networkOn) throw new Error("enroll-offline: You are offline");
|
|
48378
|
+
if (this.settingMove) throw new Error("enroll-busy: The device set is already changing. Try again after it.");
|
|
48379
|
+
const handoff = this.handoffGiver?.view();
|
|
48380
|
+
if (handoff && handoff.step !== "failed") throw new Error("enroll-busy: The profile is moving. Try again after it.");
|
|
47719
48381
|
}
|
|
47720
48382
|
/**
|
|
47721
48383
|
* The active device's links to the other devices, and its stored turn record put again (WISP 06 § Publishing and
|
|
47722
48384
|
* reading: "The active device puts its stored bytes at start"). This is also what completes an enrollment that a
|
|
47723
48385
|
* crash stopped after the record with the new device was stored and before it was put. `justRead`: it starts on a good
|
|
47724
|
-
* turn read made a moment before (the read at start, or limited mode's), which counts while it is fresh.
|
|
48386
|
+
* turn read made a moment before (the read at start, or limited mode's), which counts while it is fresh. `added`: the
|
|
48387
|
+
* signing key of a device an enrollment just added, whose link awaits it (`DeviceLinks.expectDevice`).
|
|
47725
48388
|
*/
|
|
47726
|
-
async startDeviceSet({ justRead = false } = {}) {
|
|
48389
|
+
async startDeviceSet({ justRead = false, added } = {}) {
|
|
47727
48390
|
if (this.shuttingDown || !this.networkOn) return;
|
|
47728
48391
|
const own = await readDeviceRecord(databaseName()).catch(() => null);
|
|
47729
48392
|
this.ownDeviceKey = own?.ownSlot !== void 0 ? own.deviceSet[own.ownSlot]?.key ?? null : null;
|
|
@@ -47745,9 +48408,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47745
48408
|
pushSend: (request) => this.postPush(request),
|
|
47746
48409
|
onActiveHint: () => void this.readActiveTurn().catch(() => {})
|
|
47747
48410
|
});
|
|
48411
|
+
if (added) this.deviceLinks.expectDevice(added);
|
|
47748
48412
|
await this.deviceLinks.start();
|
|
47749
48413
|
await this.startHandoff().catch(() => {});
|
|
47750
|
-
} else
|
|
48414
|
+
} else {
|
|
48415
|
+
if (added) this.deviceLinks.expectDevice(added);
|
|
48416
|
+
await this.deviceLinks.refresh();
|
|
48417
|
+
}
|
|
47751
48418
|
if (this.settings.wake?.device && this.settings.wake.device === this.ownDeviceKey) await this.deviceLinks.setOwnPush(this.settings.wake).catch(() => {});
|
|
47752
48419
|
else await this.ownWakeWins().catch(() => {});
|
|
47753
48420
|
this.emitState();
|
|
@@ -47870,6 +48537,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47870
48537
|
const handoff = this.handoffGiver?.view();
|
|
47871
48538
|
if (handoff && handoff.step !== "failed") throw new Error(`${prefix}-busy: The profile is moving. Try again after it.`);
|
|
47872
48539
|
}
|
|
48540
|
+
/**
|
|
48541
|
+
* A device being added or a move of the set in progress: the handoff waits for it (`GiverPorts.setChanging`). A move
|
|
48542
|
+
* that cancelled an Add after its grant went out would leave the note of that grant on a device no longer active.
|
|
48543
|
+
*/
|
|
48544
|
+
deviceSetChanging() {
|
|
48545
|
+
const view = this.enrollment?.current();
|
|
48546
|
+
return this.settingMove !== null || !!view && view.step !== "done" && view.step !== "failed";
|
|
48547
|
+
}
|
|
47873
48548
|
async moveDeviceSet(remove) {
|
|
47874
48549
|
this.setMoveAllowed();
|
|
47875
48550
|
if (this.settingMove) throw new Error("remove-busy: The device set is already changing.");
|
|
@@ -48046,9 +48721,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48046
48721
|
name,
|
|
48047
48722
|
didSeed: () => this.did.deviceSetSeed(),
|
|
48048
48723
|
networkSettings: () => deviceNetworkOf(this.settings),
|
|
48049
|
-
afterWrite: async () => {
|
|
48724
|
+
afterWrite: async (added) => {
|
|
48050
48725
|
await this.syncDeviceNetwork();
|
|
48051
|
-
await this.startDeviceSet();
|
|
48726
|
+
await this.startDeviceSet({ added });
|
|
48052
48727
|
},
|
|
48053
48728
|
onChange: (view) => {
|
|
48054
48729
|
if (view.step === "failed" || view.step === "done") setTimeout(() => void this.rotateIfDue().catch(() => {}), 0);
|
|
@@ -48166,6 +48841,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48166
48841
|
source: host.source(profile),
|
|
48167
48842
|
verifier: () => this.handoffVerifier(),
|
|
48168
48843
|
busy: (taker) => this.handoffBusy(taker),
|
|
48844
|
+
setChanging: () => this.deviceSetChanging(),
|
|
48169
48845
|
staying: (taker) => this.handoffStaying(taker),
|
|
48170
48846
|
quiesce: (patch, taker) => this.quiesceForHandoff(patch, taker)
|
|
48171
48847
|
});
|
|
@@ -49040,6 +49716,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
49040
49716
|
};
|
|
49041
49717
|
},
|
|
49042
49718
|
firstControlAfterMs: STARTUP_QUIET_MS,
|
|
49719
|
+
...this.options.peerDhtPollMs ? { peerDhtPollMs: this.options.peerDhtPollMs } : {},
|
|
49043
49720
|
capsRev: () => live.caps?.rev,
|
|
49044
49721
|
peerCapsRev: (rev) => live.caps?.peerRev(rev),
|
|
49045
49722
|
peerAcceptsText: () => {
|
|
@@ -49541,7 +50218,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
49541
50218
|
nativeFactoriesFor(relayOnly) {
|
|
49542
50219
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
49543
50220
|
return {
|
|
49544
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
50221
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-B9EQTm_M.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
49545
50222
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
49546
50223
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
49547
50224
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, { relays: this.irohRelays }) } : {}
|
|
@@ -50285,7 +50962,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50285
50962
|
* of a group's history (a membership change, a rename) is not a message: it stays at its commit's time, but never
|
|
50286
50963
|
* ahead of this clock nor above a row placed here since the app started. The admin's clock picks that time: two
|
|
50287
50964
|
* minutes ahead, "X joined" sat under everything said in the next two minutes; behind, it went above what the
|
|
50288
|
-
* members had just read. Read late with nothing newer here (a member back after a while), it keeps its moment
|
|
50965
|
+
* members had just read. Read late with nothing newer here (a member back after a while), it keeps its moment, and
|
|
50966
|
+
* `heardAt` says when it came here.
|
|
50289
50967
|
* `place`: a received row's place given already (`placeAbove`): it takes it, and the next row still goes past the last.
|
|
50290
50968
|
*/
|
|
50291
50969
|
placed(message, place) {
|
|
@@ -50296,7 +50974,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50296
50974
|
this.placedAt.set(message.linkId, timestamp);
|
|
50297
50975
|
return {
|
|
50298
50976
|
...message,
|
|
50299
|
-
timestamp
|
|
50977
|
+
timestamp,
|
|
50978
|
+
heardAt: now
|
|
50300
50979
|
};
|
|
50301
50980
|
}
|
|
50302
50981
|
if (message.sender === "peer" && message.sentAt === void 0) {
|
|
@@ -50919,4 +51598,4 @@ function signalKind(signal) {
|
|
|
50919
51598
|
//#endregion
|
|
50920
51599
|
export { EngineServer };
|
|
50921
51600
|
|
|
50922
|
-
//# sourceMappingURL=server-
|
|
51601
|
+
//# sourceMappingURL=server-7w2O5wsv.js.map
|