@ghostlytools/cli 1.11.1 → 1.11.3
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 +32 -23
- package/dist/assets/{api-DL0Uazf6.js → api-DBlaoz8i.js} +478 -141
- package/dist/assets/api-DBlaoz8i.js.map +1 -0
- package/dist/assets/{api-D89ubgas.js → api-DgU4MZPD.js} +2 -2
- package/dist/assets/{apiKit-D78MXTrk.js → apiKit-DesObIDf.js} +19 -9
- package/dist/assets/apiKit-DesObIDf.js.map +1 -0
- package/dist/assets/appFetch-C8yZIq1e.js +194 -0
- package/dist/assets/appFetch-C8yZIq1e.js.map +1 -0
- package/dist/assets/{apps--pAqmfgQ.js → apps-DkMjDHML.js} +142 -67
- package/dist/assets/apps-DkMjDHML.js.map +1 -0
- package/dist/assets/{apps-BlSl1nGn.js → apps-rzxsjfBV.js} +1 -1
- package/dist/assets/{arkade-DxB-MR43.js → arkade-CarKONmH.js} +2 -2
- package/dist/assets/{arkade-DxB-MR43.js.map → arkade-CarKONmH.js.map} +1 -1
- package/dist/assets/{backup-B3JJd75o.js → backup-C0OJCJlM.js} +90 -47
- package/dist/assets/backup-C0OJCJlM.js.map +1 -0
- package/dist/assets/{backup-T7gFpU80.js → backup-CgWU7x0T.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/{bitcoind-CZchoh43.js → bitcoind-CdSmvy2y.js} +3 -3
- package/dist/assets/{bitcoind-CZchoh43.js.map → bitcoind-CdSmvy2y.js.map} +1 -1
- package/dist/assets/{bitcoindProvider-DGw3xBSa.js → bitcoindProvider-BvoRh0D5.js} +2 -2
- package/dist/assets/{bitcoindProvider-DGw3xBSa.js.map → bitcoindProvider-BvoRh0D5.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/buttons-Cco0Agfa.js +2 -0
- package/dist/assets/{buttons-C1VbDihe.js → buttons-fZTEa_2i.js} +47 -7
- package/dist/assets/buttons-fZTEa_2i.js.map +1 -0
- package/dist/assets/{childEnv-BVOQK9EA.js → childEnv-K_IzUqQx.js} +4 -3
- package/dist/assets/childEnv-K_IzUqQx.js.map +1 -0
- package/dist/assets/{client-CGLuWFRV.js → client-Ibk3-e60.js} +31 -3
- package/dist/assets/client-Ibk3-e60.js.map +1 -0
- package/dist/assets/{codec-YGJDr7uH.js → codec-DMpQqVSt.js} +2 -2
- package/dist/assets/{codec-YGJDr7uH.js.map → codec-DMpQqVSt.js.map} +1 -1
- package/dist/assets/endpoint-DarqblYE.js +5052 -0
- package/dist/assets/endpoint-DarqblYE.js.map +1 -0
- package/dist/assets/{envelope-Dwq8EN8x.js → envelope-CvQVCGdf.js} +2 -2
- package/dist/assets/{envelope-Dwq8EN8x.js.map → envelope-CvQVCGdf.js.map} +1 -1
- package/dist/assets/{fedimintSdk-CqTeMdF0.js → fedimintSdk-zV_5Qdqz.js} +6 -3
- package/dist/assets/fedimintSdk-zV_5Qdqz.js.map +1 -0
- package/dist/assets/{fixedHosts-CINXidpd.js → fixedHosts-6gKn8dp2.js} +3 -3
- package/dist/assets/{fixedHosts-CINXidpd.js.map → fixedHosts-6gKn8dp2.js.map} +1 -1
- package/dist/assets/{host-CGlHkiQv.js → host-CYlIiY3r.js} +455 -104
- package/dist/assets/host-CYlIiY3r.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-Bj5jJT5w.js → hyperdhtRelay-CdsLcAhY.js} +2 -2
- package/dist/assets/{hyperdhtRelay-Bj5jJT5w.js.map → hyperdhtRelay-CdsLcAhY.js.map} +1 -1
- package/dist/assets/{irohWeb-CYn0uB_A.js → irohWeb-D2IuloLL.js} +705 -43
- package/dist/assets/irohWeb-D2IuloLL.js.map +1 -0
- package/dist/assets/jsonOut-POtMBS_V.js +16 -0
- package/dist/assets/jsonOut-POtMBS_V.js.map +1 -0
- package/dist/assets/{main-CgLW_Gyx.js → main-C0PfjKTe.js} +263 -128
- package/dist/assets/main-C0PfjKTe.js.map +1 -0
- package/dist/assets/{mainline-B0h8RchD.js → mainline-Cu61qcPS.js} +60 -24
- package/dist/assets/mainline-Cu61qcPS.js.map +1 -0
- package/dist/assets/{networkReason-BBosp2KG.js → networkReason-Dt7Yx_n4.js} +3 -3
- package/dist/assets/{networkReason-BBosp2KG.js.map → networkReason-Dt7Yx_n4.js.map} +1 -1
- package/dist/assets/{nwc-SSNS1aJ-.js → nwc-CtZypDcv.js} +6 -5
- package/dist/assets/nwc-CtZypDcv.js.map +1 -0
- package/dist/assets/{nwcProvider-BXqJmM98.js → nwcProvider-DYHkd0iu.js} +6 -3
- package/dist/assets/{nwcProvider-BXqJmM98.js.map → nwcProvider-DYHkd0iu.js.map} +1 -1
- package/dist/assets/{ownDid--DtH_Jdi.js → ownDid-CJ0ta8CL.js} +3 -3
- package/dist/assets/{ownDid--DtH_Jdi.js.map → ownDid-CJ0ta8CL.js.map} +1 -1
- package/dist/assets/{ownStatus-CQPGjCUR.js → ownStatus-D4HC6tNR.js} +12 -6
- package/dist/assets/{ownStatus-CQPGjCUR.js.map → ownStatus-D4HC6tNR.js.map} +1 -1
- package/dist/assets/{profiles-4UQ1Hsds.js → profiles-Ccdq6Xf6.js} +82 -6
- package/dist/assets/profiles-Ccdq6Xf6.js.map +1 -0
- package/dist/assets/{registry-B6BXKv6Q.js → registry-CE0PpQAE.js} +1 -1
- package/dist/assets/{registry-BKCFTEYp.js → registry-LvxsLJ5S.js} +88 -25
- package/dist/assets/registry-LvxsLJ5S.js.map +1 -0
- package/dist/assets/{resolve-MFeFljsN.js → resolve-6kVu2DE5.js} +4 -3
- package/dist/assets/resolve-6kVu2DE5.js.map +1 -0
- package/dist/assets/{server-rHKhnog1.js → server-Q3VcNqGt.js} +630 -933
- package/dist/assets/server-Q3VcNqGt.js.map +1 -0
- package/dist/assets/{src-BzsyAvPf.js → src-DjVj2ynY.js} +580 -168
- package/dist/assets/src-DjVj2ynY.js.map +1 -0
- package/dist/assets/{sshForges-qITn-RoV.js → sshForges-DeZ9cN9Q.js} +4 -3
- package/dist/assets/sshForges-DeZ9cN9Q.js.map +1 -0
- package/dist/assets/{translate-Bkr_iDgp.js → translate-iQZq4TnY.js} +36 -15
- package/dist/assets/translate-iQZq4TnY.js.map +1 -0
- package/dist/assets/{types-C4_KafL_.js → types-Clyb52K2.js} +2 -1
- package/dist/assets/types-Clyb52K2.js.map +1 -0
- package/dist/assets/{usdt-Bp7T2iqt.js → usdt-DnyTGdTX.js} +3 -3
- package/dist/assets/{usdt-Bp7T2iqt.js.map → usdt-DnyTGdTX.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +3592 -0
- package/package.json +5 -3
- package/dist/assets/api-DL0Uazf6.js.map +0 -1
- package/dist/assets/apiKit-D78MXTrk.js.map +0 -1
- package/dist/assets/apps--pAqmfgQ.js.map +0 -1
- package/dist/assets/backup-B3JJd75o.js.map +0 -1
- package/dist/assets/buttons-C1VbDihe.js.map +0 -1
- package/dist/assets/buttons-DwWuK_uN.js +0 -2
- package/dist/assets/childEnv-BVOQK9EA.js.map +0 -1
- package/dist/assets/client-CGLuWFRV.js.map +0 -1
- package/dist/assets/endpoint-DWHkXWVM.js +0 -419
- package/dist/assets/endpoint-DWHkXWVM.js.map +0 -1
- package/dist/assets/fedimintSdk-CqTeMdF0.js.map +0 -1
- package/dist/assets/host-CGlHkiQv.js.map +0 -1
- package/dist/assets/irohWeb-CYn0uB_A.js.map +0 -1
- package/dist/assets/main-CgLW_Gyx.js.map +0 -1
- package/dist/assets/mainline-B0h8RchD.js.map +0 -1
- package/dist/assets/nwc-SSNS1aJ-.js.map +0 -1
- package/dist/assets/profiles-4UQ1Hsds.js.map +0 -1
- package/dist/assets/registry-BKCFTEYp.js.map +0 -1
- package/dist/assets/resolve-MFeFljsN.js.map +0 -1
- package/dist/assets/server-rHKhnog1.js.map +0 -1
- package/dist/assets/src-BzsyAvPf.js.map +0 -1
- package/dist/assets/sshForges-qITn-RoV.js.map +0 -1
- package/dist/assets/translate-Bkr_iDgp.js.map +0 -1
- package/dist/assets/types-C4_KafL_.js.map +0 -1
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $a as
|
|
3
|
-
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-
|
|
4
|
-
import { t as bitcoindRpc } from "./bitcoindProvider-
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
2
|
+
import { $ as groupName, $a as EDIT_RATE_WINDOW_MS, $c as planKnocks, $l as createContactLink, $n as PAIRED_FRAME_TOO_LARGE, $o as commitHash, $r as STATUS_IDLE_AFTER_MS, $s as filePartName, $t as ETHEREUM_USDT, $u as isDiscoveryBudgetError, A as entryParams, Ac as readSetUpdate, Ai as chatAppId, Al as readAppBundleAsync, Ar as beaconKeys, Au as firstDeviceSetSecret, B as GROUP_LIMITS, Ba as sanitizeFileName, Bc as enrollCancelReason, Bi as dialDescriptors, Bo as sameButtonText, Br as pickHubs, Bs as serviceIdFromName, Bu as DEFAULT_RELAYS, C as GROUP_READ_NOTE_COMMUNITY, Cc as readHandoffHello, Cd as toBase64Url, Ci as relayRequest, Cl as appDigest, Co as replySnippet, Cr as groupSignalFrame, Cs as decodeControl, Dc as sealHandoffPiece, Di as APP_RANGE_LIMITS, Dr as meshHubs, Du as turnPutSummary, E as encodeCommunityLink, Ec as readHandoffVerified, Ed as utf8Encode, Ei as vapidKeysMatch, Er as mayBeHub, Eu as classifyTurnRead, Fa as DHT_MESSAGE_TTL, Fi as STATUS_CARD_CAPABILITY, Fl as appRef, Fn as findEndpoint, Fr as lobbyKeys, Fs as parseCallSignal, Fu as turnInstance, G as CatchUpAnswers, Gc as enrollProofFrame, Go as claimedTime, Gr as shouldBeHub, Gs as HANDOFF_HELLO, H as GROUP_READ_NOTE, Hc as enrollDoneFrame, Hl as readAppRevocation, Ho as statusCardText, Hr as readBeacon, Hs as HANDOFF_CANCEL, I as GroupWakeLimiter, Ia as peekDhtMailbox, Ii as UPGRADE_CAPABILITY, Il as appRefPublisher, In as isFederationId, Ir as lobbyRecords, Iu as turnKeys, J as GROUP_EDIT_TEXT_BYTES, Ja as parseVoiceMeta, Jc as verifyEnrollProof, Ji as emptyIdentityLedger, Jl as parseImageMeta, Jo as shownTime, Js as HANDOFF_PIECE_BYTES, Jt as didDhtFromPublicKey, Kc as readEnrollGrant, Ko as heardTime, Kr as ChatFiles, Ks as HANDOFF_OFFER, Ku as currentRelays, L as groupWakeFrame, La as DHT_FILE_CAPABILITY, Li as CapsExchange, Ln as parseCashuRequestPayload, Lr as mergeBeacon, Ls as emptyLinkRecords, Lu as turnName, M as knockRecords, Mc as setUpdateFrame, Mi as APPS_CAPABILITY, Mn as ENDPOINT, Mo as STATUS_CARD_LIMITS, Mr as doorHubs, Mu as readTurnPacket, N as mergeKnocks, Nc as signTombstone, Ni as BUTTONS_CAPABILITY, Nl as APP_STATEMENT_LIMITS, Nn as cashuRequestPayload, Nr as freshHubs, Ns as contactRtcConfig, Nu as signTurnPacket, O as decodeGroupEntryLink, Oi as isServeId, Ol as pacer, Or as pickMeshHubs, Os as RTC_CONFIG, Ou as TURN_LAST_SEQUENCE, P as readKnocks, Pc as verifySetUpdate, Pi as EDIT_CAPABILITY, Pl as appFingerprint, Pn as fedimintRequestPayload, Pr as hubRank, Pu as signTurnRelease, Q as mentionsMember, Qa as EDIT_BUFFER_MS, Qc as newInbox, Ql as readCanonicalJson, Qn as LIVENESS_PING_MS, Qo as MEMBER_KEY, Qs as NO_ATTEMPTS, Qt as signDidDhtPacket, Qu as budgetRetryMs, R as groupWakes, Ra as dhtFileId, Ri as DHT_TEXT_CAPABILITY, Rl as isAppHash, Rn as parseFedimintRequestPayload, Rr as mergeLobby, Rs as HTTP_SERVICE_PROTO, Ru as turnStatedVerifier, S as CommunitySession, Sc as readHandoffHave, Sd as randomBytes, Si as parseWakeFrame, So as readReply, Ss as LIMITS, Su as webCryptoSigner, T as decodeCommunityLink, Tc as readHandoffTurnFrame, Td as utf8Decode, Ti as checkPushEndpoint, Tr as MESH_HUBS, Tu as TURN_SETTLE_MS, U as GroupSession, Uc as enrollGrantFrame, Ul as readAppRevocationShape, Ur as readBeaconHead, Us as HANDOFF_DONE, Uu as RelayTransport, Va as sanitizeMime, Vc as enrollDigits, Vl as isAppRef, Vr as rankHubs, Vs as HANDOFF_ACK, W as frameBytes, Wc as enrollHelloFrame, Wo as arrivalKey, Wr as readLobby, Ws as HANDOFF_HAVE, X as meshMessageRef, Xc as endedRequests, Xl as canonicalJson, Xn as GhostLink, Xo as GROUP_MEMBER_CAP, Xr as transferEnded, Xs as HANDOFF_TIMINGS, Xt as encodeDidDhtPacket, Xu as traceLink, Y as carryMentions, Yc as clearMissed, Yo as GROUP_ADMIN_OFF_ERROR, Yr as sentWhole, Ys as HANDOFF_REQUEST, Yt as encodeDidDhtDeactivated, Z as parseCommunityEdit, Za as parseVideoMeta, Zc as inboxRecord, Zl as canonicalJsonBytes, Zn as INVITE_TAKEN, Zr as transferStalled, Zs as HANDOFF_VERIFIED, _ as GroupTypingBoard, _a as newMailbox, _c as handoffVersions, _d as sanitizeDisplayText, _i as WAKE_ONLINE_DELAY_MS, _l as requestRecords, _n as sparkInvoiceDetails, _o as reactionIsNewer, _s as presenceSeenAt, _u as deviceKeyZ32, a as appRevocationFor, aa as validExternalKey, ac as handoffContext, ai as TypingSender, al as contactAskerFrame, an as TEST_USDT_FAUCET_AMOUNT, ar as engineText, as as RATCHET_CAPABILITY, au as OwnInviteError, b as sealGroupTyping, bc as readHandoffCancel, bd as fromBase64Url, bi as deviceWakeRequest, bl as APP_BUNDLE_MAGIC, bn as isPubkyKey, bo as wireReaction, bs as parseLocalTarget, bt as normalizeAtprotoHandle, bu as newDeviceSetSecret, c as checkAppBeforeRun, cc as handoffDigest, cd as identityFromSeed, cl as knockSlotIdentity, cn as arkAddressPrefix, co as forwardedAgain, cr as GROUP_HAVE_FRAME, cs as ratchetSessionOf, cu as encodeInviteCode, da as HOLD_CAPABILITY, dc as handoffManifestFrames, di as nextPinNumber, dl as linkRecords, dn as formatPaymentAmount, do as GROUP_REACTION_FRAME, ea as receivedIdentityStatus, ec as handoffAttemptAllowed, ed as withRequestOptions, ei as liveStatus, el as settleRequest, en as EVM_TEST_CHAINS, eo as MAX_REMOVAL_NUMBER, er as pairedEditFits, es as parseGroupCommit, eu as encodeContactLink, fa as HOLD_DATED_BACK_MS, fc as handoffOfferFrame, fd as verify, fi as pinIsNewer, fl as makeStampPaced, fn as validatePaymentTarget, fo as REACTION_LIMITS, fr as groupFileFallback, fs as DHT_POLL_INTERVALS, fu as DEVICES_CAPABILITY, ga as isHoldUrl, gc as handoffStreamKey, gd as hasVisible, gi as WAKE_ONLINE_BATCH_MS, gl as readLinkRecord, gn as sparkAddressKind, go as reactionEmoji, gs as WATCH_PEER_MS, gu as deviceEchoNonce, ha as HoldRefusedError, hc as handoffRetryAfter, hi as WAKE_CALL_INTERVAL_MS, hl as readKnockSlot, hn as SPARK_PROVIDER, ho as queueReaction, hs as RELAY_POLL_INTERVALS, hu as deviceEchoFrame, i as addedAppPermissions, ia as emptyProofLedger, ic as handoffCancelFrame, il as REQUEST_LIFETIME_MS, ir as engineError, is as edgeParams, iu as readDeviceInvite, j as knockIdentity, jc as setAckFrame, ji as isAppVersion, jl as sha256Paced, jn as decodeBolt11, jr as beaconRecords, ju as nextTurnPosition, k as encodeGroupEntryLink, kr as COMMUNITY_TOPOLOGY, ku as TURN_MAX, l as planAppUpdate, lc as handoffEphemeral, ld as identityFromSeedB64, li as PIN_LIMITS, ll as knockSlotOf, ln as assertTokenUnits, lo as readForwarded, ls as DirectPathWatch, lu as inviteLink, ma as HoldKeys, mc as handoffReleaseFrame, md as sanitizeAvatar, mi as readPin, ml as openRequest, mn as SPARK_NETWORKS, mo as nextReactionNumber, mr as readGroupFileMeta, ms as PRESENCE_WINDOW, mu as HANDOFF_CAPABILITY, n as readX401SdJwtVc, na as lastSharedWithMe, nc as handoffAttemptSucceeded, nl as turnOff, nn as PaymentPreflightError, no as RateWindow, nr as pairedMessageFrame, ns as rosterHas, nu as createDeviceInvite, o as appStoreDecision, oa as TRANSPORTS, oc as handoffContextProof, ol as contactAskerHolds, on as USDT_PUBLIC_RPC, or as parseEngineError, os as RatchetBox, ou as createChatInvite, p as readAppStoreSteps, pa as HOLD_LIMITS, pc as handoffPakeFrame, pi as pinNumberHolds, pl as mergeContactKnocks, pn as walletNetworkOf, po as ReactionWindow, pu as ENROLL_CAPABILITY, qa as fileMessageText, qc as readEnrollHello, qo as receivedTimestamp, qr as FILE_LIMITS, qs as HANDOFF_PAKE, qt as didDhtDocument, qu as normalizeRelayUrl, r as sameX401HolderJwk, ra as PeerProofs, rc as handoffBusyFrame, rd as createRelayPayload, rl as ContactRequestError, rn as SEPOLIA_TEST_USDT, ro as dhtEditId, rr as EngineError, rs as verifyCommitSignature, ru as deviceInviteJoinerParams, s as appUpdateDecision, sa as automaticTransport, sc as handoffDataFrame, sd as createIdentity, si as typingActivity, sl as contactDay, sn as WALLET_NETWORKS, so as parseLinkPreview, sr as GROUP_FILE_LIMITS, ss as emptyRatchetState, su as decodeInviteCode, t as newX401HolderKey, tc as handoffAttemptFailed, td as PacketTooLargeError, ti as personStatus, tl as takeRequest, tn as ONCHAIN_PROVIDER, to as REMOVED_TEXT, tr as pairedMessageFits, ts as rosterAdmin, tu as readContactLink, u as APP_STORE_LIMITS, uc as handoffHelloFrame, ud as publicKeyFromZ32, ui as mayPin, ul as knockSlotRecords, un as assertWholeSats, uo as COMMUNITY_REACTION_FRAME, uu as inviteOwnership, v as groupTypingEpoch, va as readManifest, vc as newHandoffId, vd as stripHidden, vl as seenEntry, vn as isBitcoinAddress, vo as readReaction, vr as CarriedTransport, vs as GhostlyHttpError, vu as deviceLinkPairing, w as communityHasFrame, wc as readHandoffPake, wd as toZ32, wi as wakeRequest, wl as appViewOf, wo as BUTTON_ID, wr as readGroupSignal, ws as encodeControl, wu as TURN_RAISE_READ_TIMEOUT_MS, x as COMMUNITY_LIMITS, xc as readHandoffDone, xi as newWakeToken, xo as pairedReplyAuthor, xs as webLocalFetch, xu as seedSigner, y as openGroupTyping, yc as readHandoffAck, yd as bytesEqual, yi as WakeLimiter, yl as APP_BUNDLE_LIMITS, yo as validReactionNumber, ys as formatLocalTarget, yt as isAtprotoDid, yu as devicePingFrame, z as parseGroupWakeFrame, za as formatFileSize, zc as enrollCancelFrame, zi as capsDescriptors, zl as isAppKey, zo as checkStatusCard, zr as newerHead, zs as LEGACY_SERVICES, zu as turnVerifierMark } from "./src-DjVj2ynY.js";
|
|
3
|
+
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-Clyb52K2.js";
|
|
4
|
+
import { t as bitcoindRpc } from "./bitcoindProvider-BvoRh0D5.js";
|
|
5
|
+
import { t as nwc } from "./nwcProvider-DYHkd0iu.js";
|
|
6
6
|
import { _ as openDb, a as GROUP_LIGHT_RANGE, b as transact, c as clearProfileStores, d as deleteDatabase, f as errorLine, g as newestWalletTx, h as groupLiveKey, i as FILE_INDEX, l as committed, m as groupLightKey, n as APP_STORAGE_SCOPE_INDEX, o as GROUP_LIVE_RANGE, p as fileStore, r as CARD_INDEX, s as STORES$1, t as APP_STORAGE_CHAT_INDEX, u as databaseName, v as profileOpenFailure, x as wrap, y as store } from "./idb-CEuoNsTv.js";
|
|
7
|
-
import { a as sealSeed, c as openRow, d as sealRow, f as sealedStore, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, l as openRows, m as openSecret, o as unsealSeed, p as hasDataKey, r as intentRepository, s as RowSeals, u as proofKey } from "./networkReason-
|
|
7
|
+
import { a as sealSeed, c as openRow, d as sealRow, f as sealedStore, g as whenDataKeyDropped, h as sealSecret, i as newDeviceKey, l as openRows, m as openSecret, o as unsealSeed, p as hasDataKey, r as intentRepository, s as RowSeals, u as proofKey } from "./networkReason-Dt7Yx_n4.js";
|
|
8
8
|
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-BLPZq9YU.js";
|
|
9
|
-
import { $ as
|
|
10
|
-
import { r as loadFedimintSdk, t as fedimintDatabase } from "./fedimintSdk-
|
|
9
|
+
import { $ as lightningPaying, A as paymentNetworksOf, B as removeStored, C as paymentWireId, Ct as setSingleWriterGate, D as createTiming, E as createFailure, F as copyForForward, G as IdentityProofs, H as streamStored, I as forwardError, J as cardsKey, K as CASHU_CARD, L as forwardKind, N as WALLET_TYPES, O as crossNetwork, P as FORWARD_MESSAGE_GONE, Q as journaledPayment, R as FileAppender, S as paymentAlias, St as setAwayWallets, T as assertConfirmedReal, V as storedSize, X as breez, Y as BREEZ_SOURCE, Z as normalizePhrase, _ as groupReply, _t as WrongNetworkError, at as cashuMint, b as replyRef, bt as refuseAway, ct as loadBreezSdk, d as parsePayLink, dt as breezDatabasesFor, et as INVOICE_PACE, f as GroupFileDesk, ft as iceServerProblem, g as storedGroupFiles, gt as ModeGate, h as groupOfFile, ht as ModeChanged, i as onPublicIrohRelay, it as CASHU_MINT_SOURCE, j as walletInstances, k as paymentNetwork, l as groupLinkId, lt as openBreez, m as groupFileText, mt as relayOnlyProblem, n as createIrohWebEndpoint, nt as ProviderSources, o as groupPayLineId, ot as AskBackoff, p as groupFileId, pt as iceServerSetting, q as LightningCards, r as irohRelayProblem, rt as sourceKey, st as forgetBreez, t as DEFAULT_IROH_RELAYS, tt as nextInvoiceAsk, u as pairLinkId, ut as breezDatabaseInUse, v as pairedWireReply, vt as networkLabel, w as WALLET_NAMES, x as replyTo, xt as requireTurn, y as receivedPairedReply, yt as awayFrom, z as readStored$2 } from "./irohWeb-D2IuloLL.js";
|
|
10
|
+
import { r as loadFedimintSdk, t as fedimintDatabase } from "./fedimintSdk-zV_5Qdqz.js";
|
|
11
11
|
import { c as isTestMint, d as mintUrlSpelling, f as paysItsOwnInvoices, l as isWorthlessMint, n as DEFAULT_MINTS, o as fakesLightning, r as TEST_MINT, t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
|
|
12
|
-
import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid
|
|
13
|
-
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-
|
|
14
|
-
import { n as
|
|
12
|
+
import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-CJ0ta8CL.js";
|
|
13
|
+
import { d as chosenResolver, m as setPkarrRelaySource, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-6kVu2DE5.js";
|
|
14
|
+
import { a as besideUrl, c as isGitHubPage, i as appPasteUrl, n as APP_FETCH_LIMITS, o as boundedAppFetch, r as AppFetchError, s as isAppFetchUrl } from "./appFetch-C8yZIq1e.js";
|
|
15
|
+
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-CvQVCGdf.js";
|
|
15
16
|
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
|
|
16
17
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
17
18
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
@@ -745,7 +746,7 @@ function viewNews(before, after) {
|
|
|
745
746
|
//#endregion
|
|
746
747
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
747
748
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
748
|
-
var loadUsdt = () => import("./usdt-
|
|
749
|
+
var loadUsdt = () => import("./usdt-DnyTGdTX.js");
|
|
749
750
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
750
751
|
var DEFAULT_USDT = {
|
|
751
752
|
network: "ethereum",
|
|
@@ -1105,6 +1106,7 @@ var SWITCHES = [
|
|
|
1105
1106
|
"publicProfiles",
|
|
1106
1107
|
"sendTyping",
|
|
1107
1108
|
"sharePresence",
|
|
1109
|
+
"daemonPresence",
|
|
1108
1110
|
"autoDownloads",
|
|
1109
1111
|
"serveFiles"
|
|
1110
1112
|
];
|
|
@@ -1233,7 +1235,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
1233
1235
|
//#endregion
|
|
1234
1236
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
1235
1237
|
/** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
|
|
1236
|
-
var loadArkade = () => import("./arkade-
|
|
1238
|
+
var loadArkade = () => import("./arkade-CarKONmH.js");
|
|
1237
1239
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
1238
1240
|
var RETIRE_READ_MS = 1e4;
|
|
1239
1241
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -1681,10 +1683,10 @@ var NETWORK = {
|
|
|
1681
1683
|
signet: "Signet",
|
|
1682
1684
|
regtest: "Regtest"
|
|
1683
1685
|
};
|
|
1684
|
-
var loading$
|
|
1686
|
+
var loading$2;
|
|
1685
1687
|
/** Loads the WebAssembly once, on first use: profiles that never open a Bark wallet never fetch its 7.7 MB. */
|
|
1686
1688
|
function loadBarkSdk() {
|
|
1687
|
-
return loading$
|
|
1689
|
+
return loading$2 ??= (async () => {
|
|
1688
1690
|
const [bark, wasm] = await Promise.all([import("@secondts/bark/web"), import("./bark_ffi_wasm_bg-EY2uc0Bx.js")]);
|
|
1689
1691
|
await bark.default({ module_or_path: wasm.default });
|
|
1690
1692
|
return {
|
|
@@ -1723,7 +1725,7 @@ function loadBarkSdk() {
|
|
|
1723
1725
|
}
|
|
1724
1726
|
};
|
|
1725
1727
|
})().catch((error) => {
|
|
1726
|
-
loading$
|
|
1728
|
+
loading$2 = void 0;
|
|
1727
1729
|
throw error;
|
|
1728
1730
|
});
|
|
1729
1731
|
}
|
|
@@ -2543,7 +2545,7 @@ var NOTES_REFUND_SECS = 604800;
|
|
|
2543
2545
|
var MAX_SATS = 1e7;
|
|
2544
2546
|
var fedimintMode = (network) => network === "bitcoin" ? "mainnet" : "testnet";
|
|
2545
2547
|
var key = (mode) => `fedimintWallet-${mode}`;
|
|
2546
|
-
var sats$
|
|
2548
|
+
var sats$5 = (msats) => Math.floor(msats / 1e3);
|
|
2547
2549
|
function assertFedimintAmount(amount) {
|
|
2548
2550
|
if (!Number.isSafeInteger(amount) || amount <= 0) throw new Error("Enter an amount in sats");
|
|
2549
2551
|
if (amount > MAX_SATS) throw new Error(`Amounts above ${MAX_SATS.toLocaleString("en-US")} sats are not supported`);
|
|
@@ -2566,21 +2568,21 @@ function historyEntry(federation, op) {
|
|
|
2566
2568
|
};
|
|
2567
2569
|
const invoiceSats = () => {
|
|
2568
2570
|
const decoded = op.invoice ? decodeBolt11(op.invoice) : null;
|
|
2569
|
-
return decoded?.amountMsat ? sats$
|
|
2571
|
+
return decoded?.amountMsat ? sats$5(Number(decoded.amountMsat)) : void 0;
|
|
2570
2572
|
};
|
|
2571
2573
|
if (op.kind === "mint" && op.variant === "spend_o_o_b") {
|
|
2572
2574
|
const state = text === "UserCanceledSuccess" || text === "Refunded" ? "taken-back" : text === "UserCanceledFailure" || text === "Success" ? "done" : "pending";
|
|
2573
2575
|
return {
|
|
2574
2576
|
...base,
|
|
2575
2577
|
kind: "notes-out",
|
|
2576
|
-
amount: op.amountMsats !== void 0 ? sats$
|
|
2578
|
+
amount: op.amountMsats !== void 0 ? sats$5(op.amountMsats) : void 0,
|
|
2577
2579
|
state
|
|
2578
2580
|
};
|
|
2579
2581
|
}
|
|
2580
2582
|
if (op.kind === "mint" && op.variant === "reissuance") return {
|
|
2581
2583
|
...base,
|
|
2582
2584
|
kind: "notes-in",
|
|
2583
|
-
amount: op.amountMsats !== void 0 ? sats$
|
|
2585
|
+
amount: op.amountMsats !== void 0 ? sats$5(op.amountMsats) : void 0,
|
|
2584
2586
|
state: text === "Done" ? "done" : text === "Failed" ? "failed" : "pending"
|
|
2585
2587
|
};
|
|
2586
2588
|
if (op.kind === "ln" && op.variant === "receive") return {
|
|
@@ -2602,7 +2604,7 @@ function historyEntry(federation, op) {
|
|
|
2602
2604
|
if (op.kind === "wallet") return {
|
|
2603
2605
|
...base,
|
|
2604
2606
|
kind: "onchain",
|
|
2605
|
-
amount: op.amountMsats !== void 0 ? sats$
|
|
2607
|
+
amount: op.amountMsats !== void 0 ? sats$5(op.amountMsats) : void 0,
|
|
2606
2608
|
state: "pending"
|
|
2607
2609
|
};
|
|
2608
2610
|
}
|
|
@@ -2736,7 +2738,7 @@ var FedimintWallet = class {
|
|
|
2736
2738
|
render() {
|
|
2737
2739
|
const federations = (this.saved?.federations ?? []).map(({ database: _database, ...f }) => ({
|
|
2738
2740
|
...f,
|
|
2739
|
-
balance: sats$
|
|
2741
|
+
balance: sats$5(this.balances.get(f.id) ?? 0),
|
|
2740
2742
|
...this.balances.has(f.id) ? { read: true } : {},
|
|
2741
2743
|
status: this.clients.has(f.id) ? "ready" : this.problems.has(f.id) ? "error" : "connecting",
|
|
2742
2744
|
error: this.problems.get(f.id),
|
|
@@ -2860,7 +2862,7 @@ var FedimintWallet = class {
|
|
|
2860
2862
|
if (!saved || !federation) throw new Error("Unknown federation");
|
|
2861
2863
|
const client = this.clients.get(federationId);
|
|
2862
2864
|
if (!client) throw new Error("Wait for this federation to connect: its balance must be read before leaving it");
|
|
2863
|
-
if (sats$
|
|
2865
|
+
if (sats$5(await client.balance()) > 0) throw new Error("This federation still holds your sats: spend or move them first");
|
|
2864
2866
|
if ((await intentRepository.list()).some((i) => i.review.method === "fedimint" && i.review.provider === federationId && [
|
|
2865
2867
|
"pending",
|
|
2866
2868
|
"submitted",
|
|
@@ -2868,7 +2870,7 @@ var FedimintWallet = class {
|
|
|
2868
2870
|
].includes(i.review.state))) throw new Error("A payment through this federation is not finished yet");
|
|
2869
2871
|
const out = (await client.operations(100)).filter((op) => historyEntry(federationId, op)?.kind === "notes-out" && historyEntry(federationId, op)?.state === "pending");
|
|
2870
2872
|
for (const op of out) if (await this.takeBack(federationId, op.id, 15e3) === "pending") throw new Error("Notes you sent from this federation are still being settled: try again in a moment");
|
|
2871
|
-
if (sats$
|
|
2873
|
+
if (sats$5(await client.balance()) > 0) throw new Error("Notes nobody redeemed came back to this federation: spend or move them first");
|
|
2872
2874
|
this.unsubscribe.get(federationId)?.();
|
|
2873
2875
|
this.unsubscribe.delete(federationId);
|
|
2874
2876
|
this.clients.delete(federationId);
|
|
@@ -2939,7 +2941,7 @@ var FedimintWallet = class {
|
|
|
2939
2941
|
async spendNotes(federationId, amount, ghostly = `wallet-${crypto.randomUUID()}`) {
|
|
2940
2942
|
assertFedimintAmount(amount);
|
|
2941
2943
|
const client = this.client(federationId);
|
|
2942
|
-
if (sats$
|
|
2944
|
+
if (sats$5(await client.balance()) < amount) throw engineError("fedimintNotEnough");
|
|
2943
2945
|
const spent = await client.spend(amount * 1e3, {
|
|
2944
2946
|
cancelAfterSecs: NOTES_REFUND_SECS,
|
|
2945
2947
|
ghostly
|
|
@@ -2995,7 +2997,7 @@ var FedimintWallet = class {
|
|
|
2995
2997
|
if (state !== "done") throw new Error("The federation is still redeeming these notes: they will show in the balance");
|
|
2996
2998
|
return {
|
|
2997
2999
|
federation: found.federation,
|
|
2998
|
-
amount: sats$
|
|
3000
|
+
amount: sats$5(found.amountMsats)
|
|
2999
3001
|
};
|
|
3000
3002
|
}
|
|
3001
3003
|
/** Takes notes back. `canceled`: they are ours again; `taken`: the recipient redeemed them first; `pending`: not settled yet. */
|
|
@@ -3274,102 +3276,16 @@ var FedimintAdapter = class {
|
|
|
3274
3276
|
}
|
|
3275
3277
|
};
|
|
3276
3278
|
//#endregion
|
|
3277
|
-
//#region ../browser/src/engine/paymentAdapters/providers/breezSdk.ts
|
|
3278
|
-
var loading$2;
|
|
3279
|
-
/** Loads the WebAssembly once, on first use: profiles that never pick Breez never fetch its 12.8 MB. */
|
|
3280
|
-
function loadBreezSdk() {
|
|
3281
|
-
return loading$2 ??= (async () => {
|
|
3282
|
-
const breez = await import("./web-DwgdhfcY.js");
|
|
3283
|
-
await breez.default();
|
|
3284
|
-
return { async connect({ network, mnemonic, apiKey, storage }) {
|
|
3285
|
-
const config = breez.defaultConfig(network);
|
|
3286
|
-
if (apiKey) config.apiKey = apiKey;
|
|
3287
|
-
return breez.connect({
|
|
3288
|
-
config,
|
|
3289
|
-
seed: {
|
|
3290
|
-
type: "mnemonic",
|
|
3291
|
-
mnemonic
|
|
3292
|
-
},
|
|
3293
|
-
storageDir: storage
|
|
3294
|
-
});
|
|
3295
|
-
} };
|
|
3296
|
-
})().catch((error) => {
|
|
3297
|
-
loading$2 = void 0;
|
|
3298
|
-
throw error;
|
|
3299
|
-
});
|
|
3300
|
-
}
|
|
3301
|
-
var hex$8 = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
3302
|
-
var breezNetwork = (network) => network === "bitcoin" ? "mainnet" : "regtest";
|
|
3303
|
-
var DISCONNECT_MS = 1e4;
|
|
3304
|
-
/** One SDK instance per wallet storage: two over one database would each think the leaves are theirs. */
|
|
3305
|
-
var open = /* @__PURE__ */ new Map();
|
|
3306
|
-
/**
|
|
3307
|
-
* Opens the Breez wallet of this seed on this network, or shares the one already open (the Spark rail and the
|
|
3308
|
-
* Breez Lightning source of the same seed are one wallet). `release` gives this user's share back; the last one
|
|
3309
|
-
* disconnects the SDK. `storage`: the database it opened, which `forgetBreez` deletes when the wallet is removed.
|
|
3310
|
-
*/
|
|
3311
|
-
async function openBreez(params, sdk = loadBreezSdk, storage = breezDatabase) {
|
|
3312
|
-
const name = await storage(params.network, params.mnemonic);
|
|
3313
|
-
const key = `${name}|${params.apiKey ? hex$8(sha256(new TextEncoder().encode(params.apiKey))).slice(0, 8) : ""}`;
|
|
3314
|
-
let entry = open.get(key);
|
|
3315
|
-
if (!entry) {
|
|
3316
|
-
const wallet = sdk().then((module) => module.connect({
|
|
3317
|
-
network: breezNetwork(params.network),
|
|
3318
|
-
mnemonic: params.mnemonic,
|
|
3319
|
-
apiKey: params.apiKey,
|
|
3320
|
-
storage: name
|
|
3321
|
-
}));
|
|
3322
|
-
entry = {
|
|
3323
|
-
wallet,
|
|
3324
|
-
refs: 0
|
|
3325
|
-
};
|
|
3326
|
-
open.set(key, entry);
|
|
3327
|
-
wallet.catch(() => {
|
|
3328
|
-
if (open.get(key) === entry) open.delete(key);
|
|
3329
|
-
});
|
|
3330
|
-
}
|
|
3331
|
-
entry.refs++;
|
|
3332
|
-
const held = entry;
|
|
3333
|
-
let wallet;
|
|
3334
|
-
try {
|
|
3335
|
-
wallet = await held.wallet;
|
|
3336
|
-
} catch (error) {
|
|
3337
|
-
held.refs--;
|
|
3338
|
-
throw error;
|
|
3339
|
-
}
|
|
3340
|
-
let released = false;
|
|
3341
|
-
return {
|
|
3342
|
-
wallet,
|
|
3343
|
-
storage: name,
|
|
3344
|
-
release: async () => {
|
|
3345
|
-
if (released) return;
|
|
3346
|
-
released = true;
|
|
3347
|
-
if (--held.refs > 0) return;
|
|
3348
|
-
if (open.get(key) === held) open.delete(key);
|
|
3349
|
-
await Promise.race([wallet.disconnect(), new Promise((resolve) => setTimeout(resolve, DISCONNECT_MS))]);
|
|
3350
|
-
}
|
|
3351
|
-
};
|
|
3352
|
-
}
|
|
3353
|
-
/** Whether a wallet of this storage is open here (the Spark rail and a Breez card of one seed share it). */
|
|
3354
|
-
var breezOpen = (storage) => [...open.keys()].some((key) => key.startsWith(`${storage}|`));
|
|
3355
|
-
/**
|
|
3356
|
-
* A wallet was removed: its Breez databases go, unless another user in this profile still has them open (a Breez
|
|
3357
|
-
* Lightning card on the Spark wallet's own phrase). That one deletes them when it is removed in turn.
|
|
3358
|
-
*/
|
|
3359
|
-
async function forgetBreez(storage) {
|
|
3360
|
-
if (!breezOpen(storage)) await dropBreezDatabase(storage);
|
|
3361
|
-
}
|
|
3362
|
-
//#endregion
|
|
3363
3279
|
//#region ../browser/src/engine/paymentAdapters/spark.ts
|
|
3364
3280
|
/** Payments read to find one: newest first, bounded. */
|
|
3365
|
-
var PAGE
|
|
3366
|
-
var PAGES
|
|
3367
|
-
var sats$
|
|
3281
|
+
var PAGE = 100;
|
|
3282
|
+
var PAGES = 5;
|
|
3283
|
+
var sats$4 = (value) => {
|
|
3368
3284
|
const n = Number(value);
|
|
3369
3285
|
if (!Number.isSafeInteger(n) || n < 0) throw new Error("Spark returned an invalid amount");
|
|
3370
3286
|
return n;
|
|
3371
3287
|
};
|
|
3372
|
-
var message$
|
|
3288
|
+
var message$4 = (error) => error instanceof Error ? error.message : typeof error === "string" ? error : "Spark refused the payment";
|
|
3373
3289
|
var invoiceOf = (p) => p.details?.type === "spark" ? p.details.invoiceDetails?.invoice : void 0;
|
|
3374
3290
|
/** A fresh RFC 4122 v4 UUID: the SDK wants its idempotency keys in that form. */
|
|
3375
3291
|
var newSparkKey = () => crypto.randomUUID();
|
|
@@ -3429,7 +3345,7 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3429
3345
|
return paymentRequest;
|
|
3430
3346
|
}
|
|
3431
3347
|
async balance() {
|
|
3432
|
-
return sats$
|
|
3348
|
+
return sats$4((await this.wallet.getInfo({ ensureSynced: false })).balanceSats);
|
|
3433
3349
|
}
|
|
3434
3350
|
/** Asks Spark's operators for what changed (transfers to claim, payments that completed). */
|
|
3435
3351
|
async sync() {
|
|
@@ -3443,8 +3359,8 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3443
3359
|
return payments.map((p) => ({
|
|
3444
3360
|
id: p.id,
|
|
3445
3361
|
direction: p.paymentType === "send" ? "out" : "in",
|
|
3446
|
-
amount: sats$
|
|
3447
|
-
fee: sats$
|
|
3362
|
+
amount: sats$4(p.amount),
|
|
3363
|
+
fee: sats$4(p.fees),
|
|
3448
3364
|
at: p.timestamp * 1e3,
|
|
3449
3365
|
status: p.status,
|
|
3450
3366
|
via: p.method === "spark" ? "spark" : p.method === "lightning" ? "lightning" : p.method === "deposit" || p.method === "withdraw" ? "onchain" : "other",
|
|
@@ -3486,7 +3402,7 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3486
3402
|
if (await this.balance() < review.amount + review.fee) throw new Error("Spark balance changed. Create a new review");
|
|
3487
3403
|
if (!persist) throw new Error("Durable payment journal required");
|
|
3488
3404
|
} catch (error) {
|
|
3489
|
-
throw new PaymentPreflightError(message$
|
|
3405
|
+
throw new PaymentPreflightError(message$4(error));
|
|
3490
3406
|
}
|
|
3491
3407
|
await persist();
|
|
3492
3408
|
try {
|
|
@@ -3498,7 +3414,7 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3498
3414
|
} catch (error) {
|
|
3499
3415
|
const found = await this.sent(review, prepared).catch(() => void 0);
|
|
3500
3416
|
if (found) return this.outcome(found);
|
|
3501
|
-
throw new Error(/insufficient/i.test(message$
|
|
3417
|
+
throw new Error(/insufficient/i.test(message$4(error)) ? "Insufficient Spark balance" : "Spark payment outcome unknown");
|
|
3502
3418
|
}
|
|
3503
3419
|
});
|
|
3504
3420
|
}
|
|
@@ -3519,17 +3435,17 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3519
3435
|
* amount asked. Nothing the payer says is trusted. `claimed`: transfers that already paid another request.
|
|
3520
3436
|
*/
|
|
3521
3437
|
async received(invoice, amount, since, claimed = /* @__PURE__ */ new Set()) {
|
|
3522
|
-
for (let page = 0; page < PAGES
|
|
3438
|
+
for (let page = 0; page < PAGES; page++) {
|
|
3523
3439
|
const { payments } = await this.wallet.listPayments({
|
|
3524
3440
|
typeFilter: ["receive"],
|
|
3525
3441
|
fromTimestamp: Math.floor(since / 1e3) - 600,
|
|
3526
|
-
offset: page * PAGE
|
|
3527
|
-
limit: PAGE
|
|
3442
|
+
offset: page * PAGE,
|
|
3443
|
+
limit: PAGE,
|
|
3528
3444
|
sortAscending: false
|
|
3529
3445
|
});
|
|
3530
|
-
const found = payments.find((p) => p.status === "completed" && invoiceOf(p) === invoice && sats$
|
|
3446
|
+
const found = payments.find((p) => p.status === "completed" && invoiceOf(p) === invoice && sats$4(p.amount) >= amount && !claimed.has(p.id));
|
|
3531
3447
|
if (found) return found.id;
|
|
3532
|
-
if (payments.length < PAGE
|
|
3448
|
+
if (payments.length < PAGE) break;
|
|
3533
3449
|
}
|
|
3534
3450
|
}
|
|
3535
3451
|
async close() {
|
|
@@ -3557,12 +3473,12 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3557
3473
|
} else if (method.type === "sparkInvoice") {
|
|
3558
3474
|
const details = method.sparkInvoiceDetails;
|
|
3559
3475
|
if (details.invoice !== address || details.tokenIdentifier) throw new Error("Spark prepared a payment to another invoice");
|
|
3560
|
-
if (details.amount !== void 0 && sats$
|
|
3476
|
+
if (details.amount !== void 0 && sats$4(details.amount) !== amount) throw new Error("The Spark invoice is for another amount");
|
|
3561
3477
|
if (details.expiryTime !== void 0 && details.expiryTime * 1e3 < Date.now()) throw new Error("The Spark invoice has expired");
|
|
3562
3478
|
} else throw new Error("Spark would not pay this as a Spark transfer");
|
|
3563
|
-
if (sats$
|
|
3479
|
+
if (sats$4(quote.amount) !== amount) throw new Error("Spark prepared another amount");
|
|
3564
3480
|
return {
|
|
3565
|
-
fee: sats$
|
|
3481
|
+
fee: sats$4(method.fee),
|
|
3566
3482
|
kind: method.type === "sparkAddress" ? "address" : "invoice"
|
|
3567
3483
|
};
|
|
3568
3484
|
}
|
|
@@ -3581,7 +3497,7 @@ var SparkAdapter = class SparkAdapter {
|
|
|
3581
3497
|
const { payments } = await this.wallet.listPayments({
|
|
3582
3498
|
typeFilter: ["send"],
|
|
3583
3499
|
fromTimestamp: Math.floor(review.createdAt / 1e3) - 600,
|
|
3584
|
-
limit: PAGE
|
|
3500
|
+
limit: PAGE,
|
|
3585
3501
|
sortAscending: false
|
|
3586
3502
|
});
|
|
3587
3503
|
const mine = payments.filter((p) => invoiceOf(p) === prepared.address);
|
|
@@ -4057,7 +3973,28 @@ var PaymentCoordinator = class {
|
|
|
4057
3973
|
return saved.review;
|
|
4058
3974
|
});
|
|
4059
3975
|
}
|
|
3976
|
+
/**
|
|
3977
|
+
* A reconcile asked for while another call on the same payment is under way (the approval, or a status check) may
|
|
3978
|
+
* bring news it started too early to see: the contact saying they took the ecash just after the mint was asked. It
|
|
3979
|
+
* runs once more after that call, shared by every caller meanwhile, instead of taking that call's older answer: the
|
|
3980
|
+
* payer's card waited for the next poll, up to 10 s after the contact had it.
|
|
3981
|
+
*/
|
|
4060
3982
|
reconcile(id) {
|
|
3983
|
+
const running = this.active.get(id);
|
|
3984
|
+
if (!running) return this.reconcileNow(id);
|
|
3985
|
+
let next = this.again.get(id);
|
|
3986
|
+
if (!next) {
|
|
3987
|
+
next = running.catch(() => {}).then(() => {
|
|
3988
|
+
this.again.delete(id);
|
|
3989
|
+
return this.reconcile(id);
|
|
3990
|
+
});
|
|
3991
|
+
this.again.set(id, next);
|
|
3992
|
+
}
|
|
3993
|
+
return next;
|
|
3994
|
+
}
|
|
3995
|
+
/** The reconcile after the one under way, by payment (`reconcile`). */
|
|
3996
|
+
again = /* @__PURE__ */ new Map();
|
|
3997
|
+
reconcileNow(id) {
|
|
4061
3998
|
return this.once(id, async () => {
|
|
4062
3999
|
const saved = await this.require(id);
|
|
4063
4000
|
if (!["submitted", "unknown"].includes(saved.review.state)) return saved.review;
|
|
@@ -4474,278 +4411,6 @@ var BitcoinService = class {
|
|
|
4474
4411
|
}
|
|
4475
4412
|
};
|
|
4476
4413
|
//#endregion
|
|
4477
|
-
//#region ../browser/src/engine/paymentAdapters/providers/breez.ts
|
|
4478
|
-
var BREEZ_SOURCE = "breez";
|
|
4479
|
-
/**
|
|
4480
|
-
* Where the Breez source is offered: Mainnet ("bitcoin", with the person's Breez API key, which the form requires
|
|
4481
|
-
* there) and Breez and Lightspark's hosted regtest (no API key).
|
|
4482
|
-
*/
|
|
4483
|
-
var BREEZ_NETWORKS = ["bitcoin", "regtest"];
|
|
4484
|
-
/** WebAssembly and HTTPS only: the page, the extension's offscreen document and Tauri's WebView all run it. */
|
|
4485
|
-
var BREEZ_PLATFORMS = [
|
|
4486
|
-
"web",
|
|
4487
|
-
"extension",
|
|
4488
|
-
"desktop"
|
|
4489
|
-
];
|
|
4490
|
-
var INVOICE_EXPIRY_SECS = 3600;
|
|
4491
|
-
/** How long `payInvoice` waits for the payment to settle before answering `pending`. */
|
|
4492
|
-
var COMPLETION_SECS = 30;
|
|
4493
|
-
/** A fee shown to the person is paid with the same prepared payment for this long, then prepared again. */
|
|
4494
|
-
var QUOTE_MS = 6e4;
|
|
4495
|
-
/** Payments read to find one by its hash: newest first, bounded. */
|
|
4496
|
-
var PAGE = 100;
|
|
4497
|
-
var PAGES = 10;
|
|
4498
|
-
/** Without any record of a payment, it is called failed only this long after its invoice expired. */
|
|
4499
|
-
var LOST_AFTER_MS = 36e5;
|
|
4500
|
-
var hex$7 = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
4501
|
-
var sats$4 = (value) => {
|
|
4502
|
-
const n = Number(value);
|
|
4503
|
-
if (!Number.isSafeInteger(n) || n < 0) throw new Error("Breez returned an invalid amount");
|
|
4504
|
-
return n;
|
|
4505
|
-
};
|
|
4506
|
-
var message$4 = (error) => error instanceof Error ? error.message : typeof error === "string" ? error : "Breez refused the payment";
|
|
4507
|
-
/**
|
|
4508
|
-
* The idempotency key of one attempt at paying one invoice: asking the SDK twice with it pays once.
|
|
4509
|
-
* A new attempt (after one that failed) gets a new key, or the SDK would only hand back the failure.
|
|
4510
|
-
*/
|
|
4511
|
-
function idempotencyKey(paymentHash, attempt) {
|
|
4512
|
-
const b = sha256(new TextEncoder().encode(`ghostly-breez-pay:${paymentHash}:${attempt}`)).slice(0, 16);
|
|
4513
|
-
b[6] = b[6] & 15 | 64;
|
|
4514
|
-
b[8] = b[8] & 63 | 128;
|
|
4515
|
-
const h = hex$7(b);
|
|
4516
|
-
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
4517
|
-
}
|
|
4518
|
-
/** The payment hash a Breez payment is about, when it is one (Lightning, or a Spark HTLC). */
|
|
4519
|
-
function hashOf(payment) {
|
|
4520
|
-
const details = payment.details;
|
|
4521
|
-
if (details?.type === "lightning") return details.htlcDetails.paymentHash;
|
|
4522
|
-
if (details?.type === "spark") return details.htlcDetails?.paymentHash;
|
|
4523
|
-
}
|
|
4524
|
-
function preimageOf(payment) {
|
|
4525
|
-
const details = payment.details;
|
|
4526
|
-
return details?.type === "lightning" ? details.htlcDetails.preimage : details?.type === "spark" ? details.htlcDetails?.preimage : void 0;
|
|
4527
|
-
}
|
|
4528
|
-
/**
|
|
4529
|
-
* Lightning through the Breez SDK, nodeless: a self-custodial wallet on Spark whose seed Ghostly
|
|
4530
|
-
* generated (or the person restored) and keeps sealed. Invoices are received and paid through Breez's
|
|
4531
|
-
* and Lightspark's Spark service providers; the sats are the seed's.
|
|
4532
|
-
*
|
|
4533
|
-
* Nothing is reported by itself: the engine polls `invoiceStatus` and `paymentStatus`, which find a
|
|
4534
|
-
* payment by its hash in the wallet's history.
|
|
4535
|
-
*/
|
|
4536
|
-
var BreezLightning = class BreezLightning {
|
|
4537
|
-
wallet;
|
|
4538
|
-
network;
|
|
4539
|
-
release;
|
|
4540
|
-
storage;
|
|
4541
|
-
capabilities = {
|
|
4542
|
-
receive: true,
|
|
4543
|
-
send: true,
|
|
4544
|
-
balance: true,
|
|
4545
|
-
lookup: true
|
|
4546
|
-
};
|
|
4547
|
-
/** The prepared payment behind a fee just shown: `payInvoice` pays exactly that one while it is fresh. */
|
|
4548
|
-
quotes = /* @__PURE__ */ new Map();
|
|
4549
|
-
closed = false;
|
|
4550
|
-
/** `storage`: the Breez database this card opened (`breezDatabase`). */
|
|
4551
|
-
constructor(wallet, network, release, storage) {
|
|
4552
|
-
this.wallet = wallet;
|
|
4553
|
-
this.network = network;
|
|
4554
|
-
this.release = release;
|
|
4555
|
-
this.storage = storage;
|
|
4556
|
-
}
|
|
4557
|
-
static async connect(params, sdk = loadBreezSdk, storage = breezDatabase) {
|
|
4558
|
-
const opened = await openBreez(params, sdk, storage);
|
|
4559
|
-
return new BreezLightning(opened.wallet, params.network, opened.release, opened.storage);
|
|
4560
|
-
}
|
|
4561
|
-
async info() {
|
|
4562
|
-
const { balanceSats } = await this.wallet.getInfo({ ensureSynced: false });
|
|
4563
|
-
return {
|
|
4564
|
-
network: this.network,
|
|
4565
|
-
balance: sats$4(balanceSats)
|
|
4566
|
-
};
|
|
4567
|
-
}
|
|
4568
|
-
async createInvoice(amount, memo) {
|
|
4569
|
-
const { paymentRequest } = await this.wallet.receivePayment({ paymentMethod: {
|
|
4570
|
-
type: "bolt11Invoice",
|
|
4571
|
-
description: (memo ?? "").slice(0, 100),
|
|
4572
|
-
amountSats: amount,
|
|
4573
|
-
expirySecs: INVOICE_EXPIRY_SECS
|
|
4574
|
-
} });
|
|
4575
|
-
const decoded = decodeBolt11(paymentRequest);
|
|
4576
|
-
if (!decoded?.paymentHash || decoded.amountSat !== amount) throw new Error("Breez returned an invoice that does not match the request");
|
|
4577
|
-
return {
|
|
4578
|
-
invoice: decoded.invoice,
|
|
4579
|
-
paymentHash: decoded.paymentHash,
|
|
4580
|
-
amount,
|
|
4581
|
-
expiresAt: decoded.expiresAt * 1e3
|
|
4582
|
-
};
|
|
4583
|
-
}
|
|
4584
|
-
async invoiceStatus(invoice) {
|
|
4585
|
-
const payment = await this.find("receive", invoice.paymentHash, invoice.invoice);
|
|
4586
|
-
if (payment?.status === "completed") return {
|
|
4587
|
-
state: "paid",
|
|
4588
|
-
amount: sats$4(payment.amount)
|
|
4589
|
-
};
|
|
4590
|
-
if (payment?.status === "pending") return { state: "open" };
|
|
4591
|
-
return { state: invoice.expiresAt < Date.now() ? "expired" : "open" };
|
|
4592
|
-
}
|
|
4593
|
-
/** Prepares the payment (nothing is sent) and keeps it for `payInvoice`: its fee is the one shown. */
|
|
4594
|
-
async estimateFee(invoice, amount) {
|
|
4595
|
-
const prepared = await this.prepare(invoice, amount);
|
|
4596
|
-
this.quotes.set(decodeBolt11(invoice)?.invoice ?? invoice, {
|
|
4597
|
-
prepared,
|
|
4598
|
-
at: Date.now()
|
|
4599
|
-
});
|
|
4600
|
-
return this.feeOf(prepared);
|
|
4601
|
-
}
|
|
4602
|
-
async payInvoice(invoice, maxFee) {
|
|
4603
|
-
const decoded = decodeBolt11(invoice);
|
|
4604
|
-
if (!decoded?.paymentHash || decoded.amountSat === null) throw new NothingSpentError("That is not an invoice Breez can pay");
|
|
4605
|
-
const hash = decoded.paymentHash, amount = decoded.amountSat, key = decoded.invoice;
|
|
4606
|
-
let prepared, attempt;
|
|
4607
|
-
try {
|
|
4608
|
-
if (this.closed) throw new Error("The Breez wallet is closed");
|
|
4609
|
-
const previous = await this.history("send", hash, decoded.invoice, decoded.createdAt);
|
|
4610
|
-
const live = previous.find((p) => p.status !== "failed");
|
|
4611
|
-
if (live) return this.result(live);
|
|
4612
|
-
attempt = previous.length;
|
|
4613
|
-
const quote = this.quotes.get(key);
|
|
4614
|
-
this.quotes.delete(key);
|
|
4615
|
-
prepared = quote && Date.now() - quote.at < QUOTE_MS ? quote.prepared : await this.prepare(decoded.invoice, amount);
|
|
4616
|
-
const fee = this.feeOf(prepared);
|
|
4617
|
-
if (fee > maxFee) throw new Error(`The Lightning fee (${fee} sats) is above your limit (${maxFee})`);
|
|
4618
|
-
const { balanceSats } = await this.wallet.getInfo({ ensureSynced: false });
|
|
4619
|
-
if (sats$4(balanceSats) < amount + fee) throw new Error(`Not enough sats in the Breez wallet (${sats$4(balanceSats)}; ${amount + fee} needed)`);
|
|
4620
|
-
} catch (error) {
|
|
4621
|
-
throw isNothingSpentError(error) ? error : new NothingSpentError(message$4(error));
|
|
4622
|
-
}
|
|
4623
|
-
const { payment } = await this.wallet.sendPayment({
|
|
4624
|
-
prepareResponse: prepared,
|
|
4625
|
-
options: {
|
|
4626
|
-
type: "bolt11Invoice",
|
|
4627
|
-
preferSpark: false,
|
|
4628
|
-
completionTimeoutSecs: COMPLETION_SECS
|
|
4629
|
-
},
|
|
4630
|
-
idempotencyKey: idempotencyKey(hash, attempt)
|
|
4631
|
-
});
|
|
4632
|
-
return this.result(payment);
|
|
4633
|
-
}
|
|
4634
|
-
async paymentStatus(ref) {
|
|
4635
|
-
const decoded = decodeBolt11(ref.invoice);
|
|
4636
|
-
let payment = await this.find("send", ref.paymentHash, ref.invoice, decoded?.createdAt);
|
|
4637
|
-
if (!payment && ref.ref) {
|
|
4638
|
-
const byId = (await this.wallet.getPayment({ paymentId: ref.ref }).catch(() => void 0))?.payment;
|
|
4639
|
-
if (byId && hashOf(byId) === ref.paymentHash) payment = byId;
|
|
4640
|
-
}
|
|
4641
|
-
if (!payment) {
|
|
4642
|
-
await this.wallet.syncWallet({});
|
|
4643
|
-
payment = await this.find("send", ref.paymentHash, ref.invoice, decoded?.createdAt);
|
|
4644
|
-
}
|
|
4645
|
-
if (!payment) return { state: (decoded ? decoded.expiresAt * 1e3 + LOST_AFTER_MS < Date.now() : false) ? "failed" : "pending" };
|
|
4646
|
-
const state = payment.status === "completed" ? "paid" : payment.status === "failed" ? "failed" : "pending";
|
|
4647
|
-
return {
|
|
4648
|
-
state,
|
|
4649
|
-
fee: state === "paid" ? sats$4(payment.fees) : void 0,
|
|
4650
|
-
preimage: preimageOf(payment)
|
|
4651
|
-
};
|
|
4652
|
-
}
|
|
4653
|
-
async close() {
|
|
4654
|
-
if (this.closed) return;
|
|
4655
|
-
this.closed = true;
|
|
4656
|
-
this.quotes.clear();
|
|
4657
|
-
await this.release();
|
|
4658
|
-
}
|
|
4659
|
-
/** The card is removed: closed, and its Breez databases deleted unless the Spark wallet of this phrase has them open. */
|
|
4660
|
-
async forget() {
|
|
4661
|
-
await this.close();
|
|
4662
|
-
await forgetBreez(this.storage);
|
|
4663
|
-
}
|
|
4664
|
-
async prepare(invoice, amount) {
|
|
4665
|
-
const prepared = await this.wallet.prepareSendPayment({ paymentRequest: {
|
|
4666
|
-
type: "input",
|
|
4667
|
-
input: invoice
|
|
4668
|
-
} });
|
|
4669
|
-
const method = prepared.paymentMethod;
|
|
4670
|
-
if (method.type !== "bolt11Invoice") throw new Error("Breez would not pay this as a Lightning invoice");
|
|
4671
|
-
if (method.invoiceDetails.paymentHash !== decodeBolt11(invoice)?.paymentHash || sats$4(prepared.amount) !== amount) throw new Error("Breez prepared a payment that does not match the invoice");
|
|
4672
|
-
return prepared;
|
|
4673
|
-
}
|
|
4674
|
-
feeOf(prepared) {
|
|
4675
|
-
if (prepared.paymentMethod.type !== "bolt11Invoice") throw new Error("Breez would not pay this as a Lightning invoice");
|
|
4676
|
-
return sats$4(prepared.paymentMethod.lightningFeeSats);
|
|
4677
|
-
}
|
|
4678
|
-
/** `failed` is never an answer here: a payment the SDK gave up on is pending until `paymentStatus` says so. */
|
|
4679
|
-
result(payment) {
|
|
4680
|
-
if (payment.status === "completed") return {
|
|
4681
|
-
state: "paid",
|
|
4682
|
-
fee: sats$4(payment.fees),
|
|
4683
|
-
preimage: preimageOf(payment),
|
|
4684
|
-
ref: payment.id
|
|
4685
|
-
};
|
|
4686
|
-
return {
|
|
4687
|
-
state: "pending",
|
|
4688
|
-
ref: payment.id
|
|
4689
|
-
};
|
|
4690
|
-
}
|
|
4691
|
-
async find(type, hash, invoice, createdAt) {
|
|
4692
|
-
const found = await this.history(type, hash, invoice, createdAt);
|
|
4693
|
-
return found.find((p) => p.status === "completed") ?? found.find((p) => p.status === "pending") ?? found[0];
|
|
4694
|
-
}
|
|
4695
|
-
/** This wallet's payments of this hash, newest first. Only payments since the invoice was made are read. */
|
|
4696
|
-
async history(type, hash, invoice, createdAt = decodeBolt11(invoice)?.createdAt) {
|
|
4697
|
-
const found = [];
|
|
4698
|
-
for (let page = 0; page < PAGES; page++) {
|
|
4699
|
-
const { payments } = await this.wallet.listPayments({
|
|
4700
|
-
typeFilter: [type],
|
|
4701
|
-
fromTimestamp: createdAt ? createdAt - 600 : void 0,
|
|
4702
|
-
offset: page * PAGE,
|
|
4703
|
-
limit: PAGE,
|
|
4704
|
-
sortAscending: false
|
|
4705
|
-
});
|
|
4706
|
-
found.push(...payments.filter((p) => hashOf(p) === hash));
|
|
4707
|
-
if (payments.length < PAGE) break;
|
|
4708
|
-
}
|
|
4709
|
-
return found;
|
|
4710
|
-
}
|
|
4711
|
-
};
|
|
4712
|
-
/** The descriptor, with the SDK it loads (tests hand it a fake). */
|
|
4713
|
-
var breezDescriptor = (sdk = loadBreezSdk) => ({
|
|
4714
|
-
id: BREEZ_SOURCE,
|
|
4715
|
-
label: "Breez (Spark)",
|
|
4716
|
-
kind: "lightning",
|
|
4717
|
-
description: "A self-custodial Lightning wallet on Spark, through the Breez SDK. Its recovery phrase is sealed on this device; you hold the sats.",
|
|
4718
|
-
networks: BREEZ_NETWORKS,
|
|
4719
|
-
platforms: BREEZ_PLATFORMS,
|
|
4720
|
-
fields: [{
|
|
4721
|
-
name: "mnemonic",
|
|
4722
|
-
label: "Recovery phrase",
|
|
4723
|
-
kind: "secret",
|
|
4724
|
-
placeholder: "twelve words…",
|
|
4725
|
-
help: "Made by Ghostly for a new wallet, or yours to restore one."
|
|
4726
|
-
}, {
|
|
4727
|
-
name: "apiKey",
|
|
4728
|
-
label: "Breez API key",
|
|
4729
|
-
kind: "secret",
|
|
4730
|
-
optional: true,
|
|
4731
|
-
help: "Required on Mainnet (free, from Breez). Not needed in Testnet (regtest)."
|
|
4732
|
-
}],
|
|
4733
|
-
experimental: true,
|
|
4734
|
-
validate({ secrets }, mode) {
|
|
4735
|
-
if (!isRecoveryPhrase(secrets.mnemonic ?? "")) throw new Error("That is not a valid recovery phrase");
|
|
4736
|
-
if (mode === "mainnet" && !secrets.apiKey?.trim()) throw new Error("Breez needs an API key on Mainnet");
|
|
4737
|
-
},
|
|
4738
|
-
async create({ secrets }, host) {
|
|
4739
|
-
const network = host.mode === "mainnet" ? "bitcoin" : "regtest";
|
|
4740
|
-
return BreezLightning.connect({
|
|
4741
|
-
network,
|
|
4742
|
-
mnemonic: normalizePhrase(secrets.mnemonic),
|
|
4743
|
-
apiKey: secrets.apiKey?.trim() || void 0
|
|
4744
|
-
}, sdk);
|
|
4745
|
-
}
|
|
4746
|
-
});
|
|
4747
|
-
var breez = breezDescriptor();
|
|
4748
|
-
//#endregion
|
|
4749
4414
|
//#region ../browser/src/engine/paymentAdapters/providers/bdkSdk.ts
|
|
4750
4415
|
var WASM_IMPORTS = "./bitcoindevkit_bg.js";
|
|
4751
4416
|
var appLoader = async () => {
|
|
@@ -9818,7 +9483,7 @@ var HostNotContacted = class extends Error {};
|
|
|
9818
9483
|
*/
|
|
9819
9484
|
function fixedHostsFetch(fetch) {
|
|
9820
9485
|
return async (url, options) => {
|
|
9821
|
-
const { fixedIdentityHosts } = await import("./fixedHosts-
|
|
9486
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-6gKn8dp2.js");
|
|
9822
9487
|
const host = hostOf$1(url);
|
|
9823
9488
|
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`);
|
|
9824
9489
|
return fetch(url, options);
|
|
@@ -11011,182 +10676,6 @@ async function readPubkyProof(key, path) {
|
|
|
11011
10676
|
}
|
|
11012
10677
|
}
|
|
11013
10678
|
//#endregion
|
|
11014
|
-
//#region ../browser/src/engine/forwards.ts
|
|
11015
|
-
/**
|
|
11016
|
-
* Whether a message can be forwarded, and as what. Payments and payment requests (a bearer token or a request is for
|
|
11017
|
-
* the chat it was made in), a group's history lines and its payment notes cannot; neither can a message with nothing
|
|
11018
|
-
* in it. Identity shares and call lines are not messages here at all.
|
|
11019
|
-
*/
|
|
11020
|
-
function forwardKind(message) {
|
|
11021
|
-
if (message.sender !== "me" && message.sender !== "peer") return { refused: "This message cannot be forwarded" };
|
|
11022
|
-
if (message.paymentId) return { refused: "Payments and payment requests cannot be forwarded" };
|
|
11023
|
-
if (message.event || message.groupPay) return { refused: "This line cannot be forwarded" };
|
|
11024
|
-
if (message.file) return "file";
|
|
11025
|
-
return message.text.trim() ? "text" : { refused: "This message cannot be forwarded" };
|
|
11026
|
-
}
|
|
11027
|
-
/**
|
|
11028
|
-
* Why a chat did not get a forward, as its result says it: never "" (a result with an error is a failure, whatever it
|
|
11029
|
-
* says). A copy that found no room says so in the words the app knows however the storage put it: IndexedDB's
|
|
11030
|
-
* QuotaExceededError (an empty message in Chromium), the OPFS worker's (named so), Desktop's io error (the system's English).
|
|
11031
|
-
*/
|
|
11032
|
-
function forwardError(error) {
|
|
11033
|
-
const message = (error instanceof Error ? error.message : String(error)).trim();
|
|
11034
|
-
if (/^No space left on device\b/.test(message)) return `Not enough space on this device (${message})`;
|
|
11035
|
-
const name = error?.name;
|
|
11036
|
-
return errorLine(error).trim() || (typeof name === "string" && name ? name : "Error");
|
|
11037
|
-
}
|
|
11038
|
-
/** How many bytes of a stored file are actually here: all of them once it arrived. */
|
|
11039
|
-
async function bytesHere(file) {
|
|
11040
|
-
if (file.blob) return file.blob.size;
|
|
11041
|
-
return await (file.bytes ? await fileBytesOf(file.bytes) : null)?.size(file.id) ?? 0;
|
|
11042
|
-
}
|
|
11043
|
-
/** `read` with the parts `patches` replace (zeros where a patch has no bytes). */
|
|
11044
|
-
function patchedRead(read, patches) {
|
|
11045
|
-
return async (offset, length) => {
|
|
11046
|
-
const part = (await read(offset, length)).slice();
|
|
11047
|
-
const end = offset + part.length;
|
|
11048
|
-
for (const { start, end: until, bytes } of patches) {
|
|
11049
|
-
if (until <= offset || start >= end) continue;
|
|
11050
|
-
const from = Math.max(start, offset), to = Math.min(until, end);
|
|
11051
|
-
if (bytes) part.set(bytes.subarray(from - start, to - start), from - offset);
|
|
11052
|
-
else part.fill(0, from - offset, to - offset);
|
|
11053
|
-
}
|
|
11054
|
-
return part;
|
|
11055
|
-
};
|
|
11056
|
-
}
|
|
11057
|
-
/**
|
|
11058
|
-
* A received picture, video, audio file or voice note as it goes on: without its metadata (one from an app that sent
|
|
11059
|
-
* it with them keeps where its author took it, the device, the time, an audio file's tags), as one sent from here;
|
|
11060
|
-
* undefined for any other file, copied as it is. A picture is read whole; a video's or an audio file's stripped bytes
|
|
11061
|
-
* are a Blob when it is kept in one, else read through the parts changed. Refused with `NO_PICTURE_METADATA`,
|
|
11062
|
-
* `NO_VIDEO_METADATA` or `NO_AUDIO_METADATA` when its metadata cannot be removed.
|
|
11063
|
-
*/
|
|
11064
|
-
async function withoutMetadata(source, size, file, read) {
|
|
11065
|
-
if (!size) return void 0;
|
|
11066
|
-
if (file.video || file.voice || !isStrippedPicture(await read(0, Math.min(PICTURE_METADATA_LIMITS.headBytes, size)), file.mime)) {
|
|
11067
|
-
if (source.blob) return await withoutVideoMetadata(source.blob, file.mime) ?? await withoutAudioMetadata(source.blob, file.mime);
|
|
11068
|
-
const readFully = async (offset, length) => {
|
|
11069
|
-
const whole = new Uint8Array(Math.max(0, Math.min(length, size - offset)));
|
|
11070
|
-
for (let at = 0; at < whole.length;) {
|
|
11071
|
-
const part = await read(offset + at, whole.length - at);
|
|
11072
|
-
if (!part.length) break;
|
|
11073
|
-
whole.set(part, at);
|
|
11074
|
-
at += part.length;
|
|
11075
|
-
}
|
|
11076
|
-
return whole;
|
|
11077
|
-
};
|
|
11078
|
-
const patches = await videoMetadataPatches({
|
|
11079
|
-
size,
|
|
11080
|
-
read: readFully
|
|
11081
|
-
}, file.mime) ?? await audioMetadataPatches({
|
|
11082
|
-
size,
|
|
11083
|
-
read: readFully
|
|
11084
|
-
}, file.mime);
|
|
11085
|
-
return patches && patchedRead(read, patches);
|
|
11086
|
-
}
|
|
11087
|
-
if (size > PICTURE_METADATA_LIMITS.maxBytes) throw new Error(NO_PICTURE_METADATA);
|
|
11088
|
-
const whole = new Uint8Array(size);
|
|
11089
|
-
for (let offset = 0; offset < size;) {
|
|
11090
|
-
const part = await read(offset, Math.min(1048576, size - offset));
|
|
11091
|
-
if (!part.length) throw new Error("The file is shorter than it says");
|
|
11092
|
-
whole.set(part, offset);
|
|
11093
|
-
offset += part.length;
|
|
11094
|
-
}
|
|
11095
|
-
return new Blob(stripPictureMetadata(whole, file.mime), { type: source.blob?.type ?? file.mime });
|
|
11096
|
-
}
|
|
11097
|
-
/** What a forward of a message deleted meanwhile says, whether it went before the forward or while its file was copied. */
|
|
11098
|
-
var FORWARD_MESSAGE_GONE = "That message is not in this chat";
|
|
11099
|
-
/**
|
|
11100
|
-
* A copy of a file on this device, for sending in another chat under `file.id`: a small one whole, a larger one a
|
|
11101
|
-
* step at a time, never whole in memory; a picture without its metadata, read whole, and a video or an audio file
|
|
11102
|
-
* without its. Refused while it is still arriving, or when its bytes are gone. Resolves to `file` as it goes: a
|
|
11103
|
-
* stripped file's size is its copy's.
|
|
11104
|
-
*
|
|
11105
|
-
* A copy cut off because its source went meanwhile says why, as one started after would: its message deleted (here, or
|
|
11106
|
-
* for everyone by its sender, which takes its file: `messageGone`, asked only once the copy failed) is
|
|
11107
|
-
* `FORWARD_MESSAGE_GONE`, its record gone with the message still here is "not on this device any more". Only bytes
|
|
11108
|
-
* missing from a source still kept whole on record stay "shorter than it says".
|
|
11109
|
-
*/
|
|
11110
|
-
async function copyForForward(sourceId, target, messageGone) {
|
|
11111
|
-
try {
|
|
11112
|
-
return await copyFile(sourceId, target);
|
|
11113
|
-
} catch (error) {
|
|
11114
|
-
if (await messageGone?.().catch(() => false)) throw Object.assign(/* @__PURE__ */ new Error(FORWARD_MESSAGE_GONE), { cause: error });
|
|
11115
|
-
if (!(await fileStore.get(sourceId).catch(() => ({ metadata: true })))?.metadata) throw Object.assign(/* @__PURE__ */ new Error("The file is not on this device any more"), { cause: error });
|
|
11116
|
-
throw error;
|
|
11117
|
-
}
|
|
11118
|
-
}
|
|
11119
|
-
async function copyFile(sourceId, target) {
|
|
11120
|
-
const source = await fileStore.get(sourceId);
|
|
11121
|
-
if (!source?.metadata) throw new Error("The file is not on this device any more");
|
|
11122
|
-
const stored = storedSize(source);
|
|
11123
|
-
const checked = source.wire3 ? source.wire3.state === "done" : !source.group || source.transfer?.state === "done";
|
|
11124
|
-
if (source.direction === "in" && !checked || await bytesHere(source) !== stored) throw new Error("The file has not arrived yet");
|
|
11125
|
-
const from = source.bytes ? await fileBytesOf(source.bytes) : null;
|
|
11126
|
-
const read = async (offset, length) => source.blob ? new Uint8Array(await source.blob.slice(offset, offset + length).arrayBuffer()) : from.read(source.id, offset, length);
|
|
11127
|
-
const stripped = await withoutMetadata(source, stored, target.file, read);
|
|
11128
|
-
const blob = typeof stripped === "function" ? void 0 : stripped ?? source.blob, size = blob && stripped ? blob.size : stored;
|
|
11129
|
-
const readCopy = typeof stripped === "function" ? stripped : read;
|
|
11130
|
-
const known = stripped ? void 0 : source.digest;
|
|
11131
|
-
const { linkId, wireId, timestamp } = target, file = stripped ? {
|
|
11132
|
-
...target.file,
|
|
11133
|
-
size
|
|
11134
|
-
} : target.file;
|
|
11135
|
-
const metadata = {
|
|
11136
|
-
name: file.name,
|
|
11137
|
-
size: file.size,
|
|
11138
|
-
mime: file.mime,
|
|
11139
|
-
timestamp,
|
|
11140
|
-
voice: file.voice,
|
|
11141
|
-
video: file.video,
|
|
11142
|
-
image: file.image
|
|
11143
|
-
};
|
|
11144
|
-
const record = {
|
|
11145
|
-
id: file.id,
|
|
11146
|
-
linkId,
|
|
11147
|
-
createdAt: timestamp,
|
|
11148
|
-
direction: "out",
|
|
11149
|
-
wireId,
|
|
11150
|
-
metadata,
|
|
11151
|
-
transfer: {
|
|
11152
|
-
state: "transferring",
|
|
11153
|
-
transferred: 0,
|
|
11154
|
-
size: file.size
|
|
11155
|
-
}
|
|
11156
|
-
};
|
|
11157
|
-
if (size <= 16777216 && blob) {
|
|
11158
|
-
const copy = new Blob([await blob.slice(0, size).arrayBuffer()], { type: blob.type });
|
|
11159
|
-
const digest = known ?? (stripped ? await blobDigest(copy) : void 0);
|
|
11160
|
-
await fileStore.put({
|
|
11161
|
-
...record,
|
|
11162
|
-
blob: copy,
|
|
11163
|
-
...digest && { digest }
|
|
11164
|
-
});
|
|
11165
|
-
return file;
|
|
11166
|
-
}
|
|
11167
|
-
const bytes = await fileBytes();
|
|
11168
|
-
try {
|
|
11169
|
-
const appender = new FileAppender(bytes, file.id);
|
|
11170
|
-
for (let offset = 0; offset < size;) {
|
|
11171
|
-
const part = blob ? new Uint8Array(await blob.slice(offset, offset + 1048576).arrayBuffer()) : await readCopy(offset, Math.min(1048576, size - offset));
|
|
11172
|
-
if (!part.length) throw new Error("The file is shorter than it says");
|
|
11173
|
-
await appender.append(part);
|
|
11174
|
-
offset += part.length;
|
|
11175
|
-
}
|
|
11176
|
-
await appender.close();
|
|
11177
|
-
const digest = known ?? await bytes.digest(file.id);
|
|
11178
|
-
await fileStore.put({
|
|
11179
|
-
...record,
|
|
11180
|
-
bytes: bytes.kind,
|
|
11181
|
-
digest
|
|
11182
|
-
});
|
|
11183
|
-
return file;
|
|
11184
|
-
} catch (error) {
|
|
11185
|
-
await bytes.remove(file.id).catch(() => {});
|
|
11186
|
-
throw error;
|
|
11187
|
-
}
|
|
11188
|
-
}
|
|
11189
|
-
//#endregion
|
|
11190
10679
|
//#region ../browser/src/engine/paymentAdapters/perNetwork.ts
|
|
11191
10680
|
var perNetwork = (make) => Object.fromEntries(WALLET_NETWORKS.map((network) => [network, make(network)]));
|
|
11192
10681
|
/** A single one for both networks (a test, a caller that predates networks), or one per network already. */
|
|
@@ -11382,196 +10871,6 @@ var ChatTextSearch = class {
|
|
|
11382
10871
|
return texts;
|
|
11383
10872
|
}
|
|
11384
10873
|
};
|
|
11385
|
-
//#endregion
|
|
11386
|
-
//#region ../browser/src/engine/appFetch.ts
|
|
11387
|
-
/** The hosts phase 1 reads from. A jsDelivr URL must also name a 40-character commit (`isAppUrl`). */
|
|
11388
|
-
var APP_FETCH_HOSTS = ["raw.githubusercontent.com", "cdn.jsdelivr.net"];
|
|
11389
|
-
var APP_FETCH_LIMITS = {
|
|
11390
|
-
/**
|
|
11391
|
-
* A store index as read (WISP 1200 § Stores, Privacy): 4 MiB in phase 1, under the format's 16 MiB. Counted on the body
|
|
11392
|
-
* as it arrives, after the browser undid any compression, since a page never sees the compressed size.
|
|
11393
|
-
*/
|
|
11394
|
-
storeIndexBytes: 4194304,
|
|
11395
|
-
/** A store's signature statement, `ghostly-store.sig` (canonical, at most 1 KiB). */
|
|
11396
|
-
sigBytes: 1024,
|
|
11397
|
-
/** `ghostly-revoke.json`: at most 4096 signed revocations. */
|
|
11398
|
-
revocationsBytes: 16777216,
|
|
11399
|
-
/** How long the host has to answer (the response's headers). */
|
|
11400
|
-
timeoutMs: 3e4,
|
|
11401
|
-
/** How long the body may go without a byte: a read still arriving is never cut by the clock alone. */
|
|
11402
|
-
idleMs: 3e4,
|
|
11403
|
-
/** A whole read at most: the 16 MiB cap at about 224 kbit/s. */
|
|
11404
|
-
totalMs: 6e5
|
|
11405
|
-
};
|
|
11406
|
-
/** A URL this client may read an app, a store or a revocation list from. */
|
|
11407
|
-
function isAppFetchUrl(value) {
|
|
11408
|
-
if (!isAppUrl(value)) return false;
|
|
11409
|
-
const url = new URL(value);
|
|
11410
|
-
return url.port === "" && APP_FETCH_HOSTS.includes(url.hostname.toLowerCase());
|
|
11411
|
-
}
|
|
11412
|
-
var AppFetchError = class extends Error {
|
|
11413
|
-
code;
|
|
11414
|
-
status;
|
|
11415
|
-
constructor(code, message, status) {
|
|
11416
|
-
super(`${code}: ${message}`);
|
|
11417
|
-
this.code = code;
|
|
11418
|
-
this.status = status;
|
|
11419
|
-
this.name = "AppFetchError";
|
|
11420
|
-
}
|
|
11421
|
-
};
|
|
11422
|
-
function boundedAppFetch(options = {}) {
|
|
11423
|
-
return async (url, { maxBytes, peek = false, revalidate = false, signal: stopped }) => {
|
|
11424
|
-
if (!isAppFetchUrl(url)) throw new AppFetchError("host", "Apps are read only from raw.githubusercontent.com, or from cdn.jsdelivr.net at a commit, over HTTPS");
|
|
11425
|
-
if (options.online && !options.online()) throw new AppFetchError("offline", "Offline");
|
|
11426
|
-
if (stopped?.aborted) throw new AppFetchError("network", "The read was stopped");
|
|
11427
|
-
const fetcher = options.fetcher ?? globalThis.fetch.bind(globalThis);
|
|
11428
|
-
const controller = new AbortController();
|
|
11429
|
-
const cut = () => {
|
|
11430
|
-
controller.abort(new DOMException("The read took too long", "TimeoutError"));
|
|
11431
|
-
};
|
|
11432
|
-
const stop = () => {
|
|
11433
|
-
controller.abort(new DOMException("The read was stopped", "AbortError"));
|
|
11434
|
-
};
|
|
11435
|
-
stopped?.addEventListener("abort", stop);
|
|
11436
|
-
const total = setTimeout(cut, options.totalMs ?? APP_FETCH_LIMITS.totalMs);
|
|
11437
|
-
let idle = setTimeout(cut, options.timeoutMs ?? APP_FETCH_LIMITS.timeoutMs);
|
|
11438
|
-
const heard = () => {
|
|
11439
|
-
clearTimeout(idle);
|
|
11440
|
-
idle = setTimeout(cut, options.idleMs ?? APP_FETCH_LIMITS.idleMs);
|
|
11441
|
-
};
|
|
11442
|
-
const failure = (error) => stopped?.aborted ? new AppFetchError("network", "The read was stopped") : controller.signal.aborted ? new AppFetchError("slow", "That took too long on this connection") : new AppFetchError("network", error instanceof Error ? error.message : String(error));
|
|
11443
|
-
const { signal } = controller;
|
|
11444
|
-
let response;
|
|
11445
|
-
try {
|
|
11446
|
-
response = await fetcher(url, {
|
|
11447
|
-
signal,
|
|
11448
|
-
credentials: "omit",
|
|
11449
|
-
referrerPolicy: "no-referrer",
|
|
11450
|
-
cache: revalidate && !peek ? "no-cache" : "no-store",
|
|
11451
|
-
redirect: "error",
|
|
11452
|
-
...peek && { headers: { range: `bytes=0-${maxBytes - 1}` } }
|
|
11453
|
-
});
|
|
11454
|
-
} catch (error) {
|
|
11455
|
-
clearTimeout(total);
|
|
11456
|
-
clearTimeout(idle);
|
|
11457
|
-
stopped?.removeEventListener("abort", stop);
|
|
11458
|
-
throw failure(error);
|
|
11459
|
-
}
|
|
11460
|
-
heard();
|
|
11461
|
-
const parts = [];
|
|
11462
|
-
let length = 0;
|
|
11463
|
-
try {
|
|
11464
|
-
if (response.url && response.url !== url && !isAppFetchUrl(response.url)) throw new AppFetchError("host", "The host sent the request elsewhere");
|
|
11465
|
-
if (!response.ok) {
|
|
11466
|
-
await response.body?.cancel().catch(() => {});
|
|
11467
|
-
throw new AppFetchError("status", `The host answered ${response.status}`, response.status);
|
|
11468
|
-
}
|
|
11469
|
-
if (!peek && Number(response.headers.get("content-length")) > maxBytes) {
|
|
11470
|
-
await response.body?.cancel().catch(() => {});
|
|
11471
|
-
throw new AppFetchError("too-large", "Too large");
|
|
11472
|
-
}
|
|
11473
|
-
const reader = response.body?.getReader();
|
|
11474
|
-
if (reader) {
|
|
11475
|
-
const letGo = () => {
|
|
11476
|
-
reader.cancel().catch(() => {});
|
|
11477
|
-
};
|
|
11478
|
-
signal.addEventListener("abort", letGo);
|
|
11479
|
-
try {
|
|
11480
|
-
for (;;) {
|
|
11481
|
-
const { done, value } = await reader.read();
|
|
11482
|
-
if (signal.aborted) throw failure(signal.reason);
|
|
11483
|
-
if (done) break;
|
|
11484
|
-
heard();
|
|
11485
|
-
if (length + value.length > maxBytes) {
|
|
11486
|
-
if (!peek) throw new AppFetchError("too-large", "Too large");
|
|
11487
|
-
parts.push(value.subarray(0, maxBytes - length));
|
|
11488
|
-
length = maxBytes;
|
|
11489
|
-
break;
|
|
11490
|
-
}
|
|
11491
|
-
parts.push(value);
|
|
11492
|
-
length += value.length;
|
|
11493
|
-
}
|
|
11494
|
-
} catch (error) {
|
|
11495
|
-
if (error instanceof AppFetchError) throw error;
|
|
11496
|
-
throw failure(error);
|
|
11497
|
-
} finally {
|
|
11498
|
-
signal.removeEventListener("abort", letGo);
|
|
11499
|
-
await reader.cancel().catch(() => {});
|
|
11500
|
-
}
|
|
11501
|
-
}
|
|
11502
|
-
} finally {
|
|
11503
|
-
clearTimeout(total);
|
|
11504
|
-
clearTimeout(idle);
|
|
11505
|
-
stopped?.removeEventListener("abort", stop);
|
|
11506
|
-
}
|
|
11507
|
-
const bytes = new Uint8Array(length);
|
|
11508
|
-
let at = 0;
|
|
11509
|
-
for (const part of parts) {
|
|
11510
|
-
bytes.set(part, at);
|
|
11511
|
-
at += part.length;
|
|
11512
|
-
}
|
|
11513
|
-
return bytes;
|
|
11514
|
-
};
|
|
11515
|
-
}
|
|
11516
|
-
var NAME = /^[A-Za-z0-9_.-]+$/;
|
|
11517
|
-
/**
|
|
11518
|
-
* The URL a pasted address reads `file` from (WISP 1200 § Paste a URL), or null when it is not one this client reads:
|
|
11519
|
-
* - `https://github.com/<owner>/<repo>`, or `/tree/<ref>`: `raw.githubusercontent.com/<owner>/<repo>/<ref or HEAD>/<file>`,
|
|
11520
|
-
* with no request to `github.com` or `api.github.com`;
|
|
11521
|
-
* - a file as GitHub shows it, `https://github.com/<owner>/<repo>/blob/<ref>/<path>` (or `/raw/`), naming a `.ghostlyapp`
|
|
11522
|
-
* or `.json` file: `raw.githubusercontent.com/<owner>/<repo>/<ref>/<path>`, again with no request to `github.com`;
|
|
11523
|
-
* - a URL of the list that names a file (`….ghostlyapp`, `….json`): itself;
|
|
11524
|
-
* - a URL of the list that names a folder: `<file>` in it.
|
|
11525
|
-
*/
|
|
11526
|
-
function appPasteUrl(input, file) {
|
|
11527
|
-
let url;
|
|
11528
|
-
try {
|
|
11529
|
-
url = new URL(input.trim());
|
|
11530
|
-
} catch {
|
|
11531
|
-
return null;
|
|
11532
|
-
}
|
|
11533
|
-
if (url.protocol !== "https:" || url.username || url.password || url.port) return null;
|
|
11534
|
-
const host = url.hostname.toLowerCase();
|
|
11535
|
-
if (host === "github.com" || host === "www.github.com") {
|
|
11536
|
-
const parts = url.pathname.split("/").filter(Boolean);
|
|
11537
|
-
if (parts.length < 2) return null;
|
|
11538
|
-
const owner = parts[0], repo = parts[1].replace(/\.git$/, "");
|
|
11539
|
-
if (!NAME.test(owner) || !NAME.test(repo)) return null;
|
|
11540
|
-
let ref = "HEAD";
|
|
11541
|
-
if (parts.length > 2) {
|
|
11542
|
-
const rest = parts.slice(3);
|
|
11543
|
-
if (!rest.length || !rest.every((p) => NAME.test(p) && p !== "." && p !== "..")) return null;
|
|
11544
|
-
if (parts[2] === "blob" || parts[2] === "raw") {
|
|
11545
|
-
if (rest.length < 2 || !/\.(ghostlyapp|json)$/.test(rest[rest.length - 1])) return null;
|
|
11546
|
-
const raw = `https://raw.githubusercontent.com/${owner}/${repo}/${rest.join("/")}`;
|
|
11547
|
-
return isAppFetchUrl(raw) ? raw : null;
|
|
11548
|
-
}
|
|
11549
|
-
if (parts[2] !== "tree") return null;
|
|
11550
|
-
ref = rest.join("/");
|
|
11551
|
-
}
|
|
11552
|
-
const raw = `https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${file}`;
|
|
11553
|
-
return isAppFetchUrl(raw) ? raw : null;
|
|
11554
|
-
}
|
|
11555
|
-
const last = url.pathname.split("/").pop() ?? "";
|
|
11556
|
-
const named = /\.(ghostlyapp|json)$/.test(last) ? url.href : new URL(`${url.pathname.replace(/\/?$/, "/")}${file}`, url).href;
|
|
11557
|
-
return isAppFetchUrl(named) ? named : null;
|
|
11558
|
-
}
|
|
11559
|
-
/** A page of github.com (any scheme): a link `appPasteUrl` could not read is still GitHub, and is answered as such. */
|
|
11560
|
-
function isGitHubPage(input) {
|
|
11561
|
-
try {
|
|
11562
|
-
const host = new URL(input.trim()).hostname.toLowerCase();
|
|
11563
|
-
return host === "github.com" || host === "www.github.com";
|
|
11564
|
-
} catch {
|
|
11565
|
-
return false;
|
|
11566
|
-
}
|
|
11567
|
-
}
|
|
11568
|
-
/** A file beside another (`ghostly-store.sig` beside the index, `ghostly-revoke.json` beside a bundle). */
|
|
11569
|
-
function besideUrl(url, name) {
|
|
11570
|
-
const target = new URL(url);
|
|
11571
|
-
target.search = "";
|
|
11572
|
-
target.hash = "";
|
|
11573
|
-
return new URL(name, target).href;
|
|
11574
|
-
}
|
|
11575
10874
|
/**
|
|
11576
10875
|
* The stores a new profile starts with (WISP 1200 § Stores: the default store, preloaded and removable), each a URL and
|
|
11577
10876
|
* the store key it is pinned to. Preloading one makes no request; the first read comes when the person opens the Apps
|
|
@@ -11633,8 +10932,8 @@ var STORE_READ_PARALLEL = 4;
|
|
|
11633
10932
|
/** Revocations are checked this long at a time before the page's thread is let go. */
|
|
11634
10933
|
var REVOCATIONS_SLICE_MS = 10;
|
|
11635
10934
|
/**
|
|
11636
|
-
* `ghostly-revoke.json` files whose result is kept, so an unchanged one is not
|
|
11637
|
-
* at most this many, and of the
|
|
10935
|
+
* `ghostly-revoke.json` files whose result for one app is kept, so an unchanged one is not read again (the oldest dropped
|
|
10936
|
+
* first): at most this many, and of the lists held at most one file's limit of bytes in all. A publisher's file is
|
|
11638
10937
|
* small; nine large ones beside one app's URLs, or one that changes at every check, would stay for the engine's life.
|
|
11639
10938
|
*/
|
|
11640
10939
|
var REVOCATION_FILES_KEPT = {
|
|
@@ -11642,6 +10941,12 @@ var REVOCATION_FILES_KEPT = {
|
|
|
11642
10941
|
bytes: APP_FETCH_LIMITS.revocationsBytes
|
|
11643
10942
|
};
|
|
11644
10943
|
/**
|
|
10944
|
+
* Verdicts of `ghostly-revoke.json` files (every entry verified, or the file refused), by the SHA-256 of their bytes:
|
|
10945
|
+
* a file whose list was dropped from `REVOCATION_FILES_KEPT` is read again with no signature checked. About 64 bytes
|
|
10946
|
+
* each; the oldest dropped first.
|
|
10947
|
+
*/
|
|
10948
|
+
var REVOCATION_VERDICTS_KEPT = 1024;
|
|
10949
|
+
/**
|
|
11645
10950
|
* Revocations of store indexes whose signature was checked, kept by `appRevocationId` so an index that changes around
|
|
11646
10951
|
* them does not have each checked again (the one read longest ago dropped first): four indexes' worth, about 1 MiB.
|
|
11647
10952
|
*/
|
|
@@ -11660,6 +10965,8 @@ var BUNDLES_KEPT = {
|
|
|
11660
10965
|
min: 2,
|
|
11661
10966
|
ms: 6e4
|
|
11662
10967
|
};
|
|
10968
|
+
/** URLs the update check remembers it read whole and refused (`Apps.refusedReads`). */
|
|
10969
|
+
var REFUSED_READS_KEPT = 256;
|
|
11663
10970
|
/** The first bytes of a bundle: magic, the manifest's length and the largest manifest. */
|
|
11664
10971
|
var PEEK_BYTES = APP_BUNDLE_MAGIC.length + 4 + APP_BUNDLE_LIMITS.manifestBytes;
|
|
11665
10972
|
/** What a peek reads first: the magic, the length and any usual manifest (about 1 KiB). A longer one is read to its end after. */
|
|
@@ -11813,8 +11120,8 @@ async function noteBundles(change) {
|
|
|
11813
11120
|
*/
|
|
11814
11121
|
var APP_REVOCATIONS_KEY = "appRevocations";
|
|
11815
11122
|
/**
|
|
11816
|
-
* Revocations kept there: at most `each` of one app and `all` in all,
|
|
11817
|
-
* revocation is at most about 3.5 KiB (64 digests and a reason).
|
|
11123
|
+
* Revocations kept there: at most `each` of one app and `all` in all, dropped from the publisher holding the most (see
|
|
11124
|
+
* `keepRevocations`). A revocation is at most about 3.5 KiB (64 digests and a reason).
|
|
11818
11125
|
*/
|
|
11819
11126
|
var REVOCATIONS_KEPT = {
|
|
11820
11127
|
each: 64,
|
|
@@ -11850,12 +11157,19 @@ function keepRevocations(settings, ref, add) {
|
|
|
11850
11157
|
if (merged.size === before.length) return;
|
|
11851
11158
|
kept.delete(ref);
|
|
11852
11159
|
kept.set(ref, [...merged.values()].slice(-REVOCATIONS_KEPT.each));
|
|
11160
|
+
const held = /* @__PURE__ */ new Map();
|
|
11853
11161
|
let all = 0;
|
|
11854
|
-
for (const list of kept
|
|
11855
|
-
|
|
11856
|
-
|
|
11162
|
+
for (const [r, list] of kept) {
|
|
11163
|
+
held.set(appRefPublisher(r), (held.get(appRefPublisher(r)) ?? 0) + list.length);
|
|
11164
|
+
all += list.length;
|
|
11165
|
+
}
|
|
11166
|
+
while (all > REVOCATIONS_KEPT.all) {
|
|
11167
|
+
let most = "";
|
|
11168
|
+
for (const [publisher, n] of held) if (n > (held.get(most) ?? 0)) most = publisher;
|
|
11169
|
+
const [other, list] = [...kept].find(([r]) => appRefPublisher(r) === most);
|
|
11857
11170
|
const drop = Math.min(list.length, all - REVOCATIONS_KEPT.all);
|
|
11858
11171
|
all -= drop;
|
|
11172
|
+
held.set(most, held.get(most) - drop);
|
|
11859
11173
|
if (drop === list.length) kept.delete(other);
|
|
11860
11174
|
else kept.set(other, list.slice(drop));
|
|
11861
11175
|
}
|
|
@@ -12078,17 +11392,26 @@ var Apps = class {
|
|
|
12078
11392
|
held = /* @__PURE__ */ new Map();
|
|
12079
11393
|
heldStores = null;
|
|
12080
11394
|
/**
|
|
12081
|
-
* Listing URLs whose peek showed nothing to take (`<store> <ref> <url>` → `<index digest> <listed digest
|
|
12082
|
-
* index listing the same is not peeked again at
|
|
11395
|
+
* Listing URLs whose peek showed nothing to take (`<store> <ref> <url>` → `<index digest> <listed digest> <pin>
|
|
11396
|
+
* <installed digest> <waiting digest>`): the same index listing the same, for the same app, is not peeked again at
|
|
11397
|
+
* every check.
|
|
12083
11398
|
*/
|
|
12084
11399
|
listingMisses = /* @__PURE__ */ new Map();
|
|
12085
11400
|
/**
|
|
11401
|
+
* URLs whose whole read the update check refused (a file hash that does not hold, a bad signature, too large), with
|
|
11402
|
+
* the digest their peek showed then: the same peek there is not read whole again at every check, for an hour (a fixed
|
|
11403
|
+
* upload of the same version keeps its manifest). At most `REFUSED_READS_KEPT`, the oldest going first.
|
|
11404
|
+
*/
|
|
11405
|
+
refusedReads = /* @__PURE__ */ new Map();
|
|
11406
|
+
/**
|
|
12086
11407
|
* The index a store's own URL served at its last read when it was not taken (behind the copy the person took, at a
|
|
12087
11408
|
* commit): by store key, with that URL. The same bytes there again are not checked whole at every refresh.
|
|
12088
11409
|
*/
|
|
12089
11410
|
behindReads = /* @__PURE__ */ new Map();
|
|
12090
|
-
/** `ghostly-revoke.json` files checked, by the SHA-256 of their bytes:
|
|
11411
|
+
/** `ghostly-revoke.json` files checked, by the SHA-256 of their bytes and the app read (`<digest> <ref>`): that app's revocations in it, and the bytes the list counts for. */
|
|
12091
11412
|
revocationFiles = /* @__PURE__ */ new Map();
|
|
11413
|
+
/** Whether every entry of a `ghostly-revoke.json` verified, by the SHA-256 of its bytes: at most `REVOCATION_VERDICTS_KEPT`. */
|
|
11414
|
+
revocationVerdicts = /* @__PURE__ */ new Map();
|
|
12092
11415
|
/** Revocations read in a store's index and verified, by `appRevocationId`: at most `STORE_REVOCATIONS_KEPT`. */
|
|
12093
11416
|
storeRevocations = /* @__PURE__ */ new Set();
|
|
12094
11417
|
checkedRevocations = {
|
|
@@ -12340,7 +11663,9 @@ var Apps = class {
|
|
|
12340
11663
|
* version it read over an update the person accepted meanwhile. `was` undefined: only while the app has no record.
|
|
12341
11664
|
* A store removed since the caller read the stores pins nothing: it is judged at the write, as `removeStore` unpins
|
|
12342
11665
|
* only the records written before it. A revocation the record gained since `was` (`keepStoreRevocations`) is kept:
|
|
12343
|
-
* one `app` leaves out on purpose (the check's, of a version gone) was on `was` already.
|
|
11666
|
+
* one `app` leaves out on purpose (the check's, of a version gone) was on `was` already. So is what the person's stores
|
|
11667
|
+
* revoke of the versions written, as held at the write: a version fetched while a store's index revoked it was not on
|
|
11668
|
+
* the record `keepStoreRevocations` read.
|
|
12344
11669
|
*/
|
|
12345
11670
|
async putAppIfUnchanged(app, was) {
|
|
12346
11671
|
const stores = await this.records();
|
|
@@ -12352,6 +11677,8 @@ var Apps = class {
|
|
|
12352
11677
|
if (!sameRecord(now, was)) return;
|
|
12353
11678
|
const had = new Set((was?.revocations ?? []).map((r) => canonicalJson(r)));
|
|
12354
11679
|
app = withRevocations(app, (now?.revocations ?? []).filter((r) => !had.has(canonicalJson(r))));
|
|
11680
|
+
const revoked = [...stores.values()].flatMap((s) => s.removed ? [] : s.index?.revoked ?? []);
|
|
11681
|
+
app = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
12355
11682
|
const { store: pin, ...unpinned } = app;
|
|
12356
11683
|
tx.objectStore(STORES$1.apps).put(pin !== void 0 && stores.get(pin)?.removed ? unpinned : app);
|
|
12357
11684
|
put = true;
|
|
@@ -12748,23 +12075,32 @@ var Apps = class {
|
|
|
12748
12075
|
if (read.has(url)) continue;
|
|
12749
12076
|
read.add(url);
|
|
12750
12077
|
try {
|
|
12751
|
-
const file = await this.readRevocationsFile(await this.host.fetch(url, {
|
|
12078
|
+
const file = await this.readRevocationsFile(ref, await this.host.fetch(url, {
|
|
12752
12079
|
maxBytes: APP_FETCH_LIMITS.revocationsBytes,
|
|
12753
12080
|
revalidate: true
|
|
12754
12081
|
}));
|
|
12755
|
-
if (file) (out ??= []).push(...file
|
|
12082
|
+
if (file) (out ??= []).push(...file);
|
|
12756
12083
|
} catch {}
|
|
12757
12084
|
}
|
|
12758
12085
|
return out;
|
|
12759
12086
|
}
|
|
12760
12087
|
/**
|
|
12761
12088
|
* `readAppRevocations` (one entry that does not verify refuses the file, null here), with a pause every few ms: the
|
|
12762
|
-
* engine shares the page's thread, and each entry is a signature check.
|
|
12089
|
+
* engine shares the page's thread, and each entry is a signature check. Of the file, the revocations of `ref`. The
|
|
12090
|
+
* same bytes are not checked again: their list for `ref` is kept while it fits, and their verdict longer, so a file
|
|
12091
|
+
* read again is only parsed, with no signature checked.
|
|
12763
12092
|
*/
|
|
12764
|
-
async readRevocationsFile(bytes) {
|
|
12093
|
+
async readRevocationsFile(ref, bytes) {
|
|
12765
12094
|
const id = toBase64Url(await sha256Paced(bytes));
|
|
12766
|
-
const
|
|
12767
|
-
if (
|
|
12095
|
+
const verdict = this.revocationVerdicts.get(id);
|
|
12096
|
+
if (verdict === false) return null;
|
|
12097
|
+
const key = `${id} ${ref}`;
|
|
12098
|
+
const known = this.revocationFiles.get(key);
|
|
12099
|
+
if (known !== void 0) {
|
|
12100
|
+
this.revocationFiles.delete(key);
|
|
12101
|
+
this.revocationFiles.set(key, known);
|
|
12102
|
+
return known.revocations;
|
|
12103
|
+
}
|
|
12768
12104
|
const read = readCanonicalJson(bytes);
|
|
12769
12105
|
let out = null;
|
|
12770
12106
|
if (read.ok && Array.isArray(read.value) && read.value.length <= APP_STATEMENT_LIMITS.revocations) {
|
|
@@ -12772,18 +12108,21 @@ var Apps = class {
|
|
|
12772
12108
|
const pause = pacer(REVOCATIONS_SLICE_MS);
|
|
12773
12109
|
for (const entry of read.value) {
|
|
12774
12110
|
await pause();
|
|
12775
|
-
const one = readAppRevocation(entry);
|
|
12111
|
+
const one = verdict ? readAppRevocationShape(entry) : readAppRevocation(entry);
|
|
12776
12112
|
if (!one.ok) {
|
|
12777
12113
|
out = null;
|
|
12778
12114
|
break;
|
|
12779
12115
|
}
|
|
12780
|
-
out.push(one.revocation);
|
|
12116
|
+
if (one.revocation.statement.app === ref) out.push(one.revocation);
|
|
12781
12117
|
}
|
|
12782
12118
|
}
|
|
12783
|
-
this.
|
|
12784
|
-
this.
|
|
12119
|
+
this.revocationVerdicts.delete(id);
|
|
12120
|
+
this.revocationVerdicts.set(id, out !== null);
|
|
12121
|
+
if (this.revocationVerdicts.size > REVOCATION_VERDICTS_KEPT) this.revocationVerdicts.delete(this.revocationVerdicts.keys().next().value);
|
|
12122
|
+
if (!out) return null;
|
|
12123
|
+
this.revocationFiles.set(key, {
|
|
12785
12124
|
revocations: out,
|
|
12786
|
-
bytes: out ?
|
|
12125
|
+
bytes: out.length ? canonicalJsonBytes(out).length : 0
|
|
12787
12126
|
});
|
|
12788
12127
|
let held = 0;
|
|
12789
12128
|
for (const file of this.revocationFiles.values()) held += file.bytes;
|
|
@@ -13293,6 +12632,7 @@ var Apps = class {
|
|
|
13293
12632
|
return this.view(await this.app(version.ref), stores);
|
|
13294
12633
|
}
|
|
13295
12634
|
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
12635
|
+
if (this.runStatus(version, await this.heldViews(), [...installed?.revocations ?? [], ...known]).status !== "ok") continue;
|
|
13296
12636
|
const next = withRevocations(this.versionRecord(installed, bundle, kind, from, fromStore), known);
|
|
13297
12637
|
if (!await this.putAppIfUnchanged(next, installed)) continue;
|
|
13298
12638
|
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
@@ -13346,17 +12686,24 @@ var Apps = class {
|
|
|
13346
12686
|
async acceptUpdate({ ref, sequence, added: shown }) {
|
|
13347
12687
|
if (shown !== void 0 && !Array.isArray(shown)) fail("permissions", "The permissions shown must be a list");
|
|
13348
12688
|
const installed = await this.installedOrFail(ref);
|
|
12689
|
+
if (!installed.pending && sequence !== void 0 && installed.sequence === sequence) return this.view(installed, await this.stores());
|
|
13349
12690
|
const pending = installed.pending ?? fail("no-update", "No update waits for this app");
|
|
13350
12691
|
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`);
|
|
13351
12692
|
const bytes = await this.readBundleBytes(pending.bytes, pending.digest);
|
|
13352
12693
|
const read = bytes ? await readAppBundleAsync(bytes) : null;
|
|
13353
12694
|
if (!read?.ok || read.bundle.digest !== pending.digest) {
|
|
13354
12695
|
const { pending: _p, ...rest } = installed;
|
|
13355
|
-
if (!await this.
|
|
12696
|
+
if (!await this.putAppIfUnchanged(rest, installed)) return this.acceptedOver(ref, pending.digest);
|
|
13356
12697
|
fail("needs-files", "The update's files are gone; it is fetched again at the next check");
|
|
13357
12698
|
}
|
|
13358
12699
|
const stores = await this.stores();
|
|
13359
|
-
if (installed.store !== void 0 && this.pinnedListing(installed, stores)?.digest !== pending.digest)
|
|
12700
|
+
if (installed.store !== void 0 && this.pinnedListing(installed, stores)?.digest !== pending.digest) {
|
|
12701
|
+
if (stores.find((s) => s.key === installed.store)?.index) {
|
|
12702
|
+
const { pending: _p, ...rest } = installed;
|
|
12703
|
+
if (await this.putAppIfUnchanged(rest, installed)) await this.removeBundle(pending.bytes, pending.digest);
|
|
12704
|
+
}
|
|
12705
|
+
fail("unlisted", "The store no longer lists this update");
|
|
12706
|
+
}
|
|
13360
12707
|
const run = this.runStatus(versionOf(read.bundle.manifest, pending.digest), this.storeViews(stores), installed.revocations);
|
|
13361
12708
|
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
13362
12709
|
if (run.status === "removed") fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
@@ -13367,27 +12714,29 @@ var Apps = class {
|
|
|
13367
12714
|
if (plan.action === "refuse") fail(plan.decision, "This update can no longer be installed");
|
|
13368
12715
|
const added = plan.action === "ask" ? plan.added : [];
|
|
13369
12716
|
if (added.length !== pending.added.length || added.some((p) => !pending.added.includes(p))) {
|
|
13370
|
-
if (!await this.
|
|
12717
|
+
if (!await this.putAppIfUnchanged({
|
|
13371
12718
|
...installed,
|
|
13372
12719
|
pending: {
|
|
13373
12720
|
...pending,
|
|
13374
12721
|
added
|
|
13375
12722
|
}
|
|
13376
|
-
}))
|
|
12723
|
+
}, installed)) return this.acceptedOver(ref, pending.digest);
|
|
13377
12724
|
fail("permissions-changed", `This update now adds ${added.length ? added.join(", ") : "no permission"}; look at it again`);
|
|
13378
12725
|
}
|
|
13379
12726
|
if (shown && added.some((p) => !shown.includes(p))) fail("permissions-changed", `This update now adds ${added.join(", ")}; look at it again`);
|
|
13380
12727
|
const { pending: _p, ...without } = installed;
|
|
13381
12728
|
const next = this.versionRecord(without, read.bundle, pending.bytes, pending.from, installed.store);
|
|
13382
|
-
if (!await this.putAppIfUnchanged(next, installed))
|
|
13383
|
-
const now = await this.app(ref);
|
|
13384
|
-
if (!now) fail("not-installed", "This app is not installed");
|
|
13385
|
-
if (now.digest === pending.digest) return this.view(now, await this.stores());
|
|
13386
|
-
fail("no-update", "This update can no longer be installed");
|
|
13387
|
-
}
|
|
12729
|
+
if (!await this.putAppIfUnchanged(next, installed)) return this.acceptedOver(ref, pending.digest);
|
|
13388
12730
|
await this.removeBundle(installed.bytes, installed.digest);
|
|
13389
12731
|
return this.view(next, stores);
|
|
13390
12732
|
}
|
|
12733
|
+
/** Accept's answer when the app's record changed while it read: uninstalled, this update installed, or another version. */
|
|
12734
|
+
async acceptedOver(ref, digest) {
|
|
12735
|
+
const now = await this.app(ref);
|
|
12736
|
+
if (!now) fail("not-installed", "This app is not installed");
|
|
12737
|
+
if (now.digest === digest) return this.view(now, await this.stores());
|
|
12738
|
+
fail("no-update", "This update can no longer be installed");
|
|
12739
|
+
}
|
|
13391
12740
|
/** An app's listing in the store its updates come from (`InstalledApp.store`), while that store is the person's. */
|
|
13392
12741
|
pinnedListing(app, stores) {
|
|
13393
12742
|
return app.store === void 0 ? void 0 : stores.find((s) => s.key === app.store)?.index?.apps.find((a) => a.ref === app.ref);
|
|
@@ -13445,7 +12794,7 @@ var Apps = class {
|
|
|
13445
12794
|
if (pinned !== void 0 && s.key !== pinned) continue;
|
|
13446
12795
|
const listing = s.index?.apps.find((a) => a.ref === app.ref);
|
|
13447
12796
|
if (!listing || !newer(listing)) continue;
|
|
13448
|
-
const seen = `${s.digest} ${listing.digest}`;
|
|
12797
|
+
const seen = `${s.digest} ${listing.digest} ${pinned ?? ""} ${app.digest} ${app.pending?.digest ?? ""}`;
|
|
13449
12798
|
for (const url of listingUrls(listing.urls)) {
|
|
13450
12799
|
const missed = `${s.key} ${app.ref} ${url}`;
|
|
13451
12800
|
if (candidates.has(url) || s.digest !== void 0 && this.listingMisses.get(missed) === seen) continue;
|
|
@@ -13470,7 +12819,15 @@ var Apps = class {
|
|
|
13470
12819
|
const revokeRead = /* @__PURE__ */ new Set();
|
|
13471
12820
|
const before = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
|
|
13472
12821
|
app = withRevocations(app, before ?? []);
|
|
13473
|
-
|
|
12822
|
+
const kept = await this.keptRevocationsOf(app.ref);
|
|
12823
|
+
const judge = (version) => this.runStatus(version, this.storeViews(stores), [...app.revocations ?? [], ...kept]);
|
|
12824
|
+
if (app.pending && judge(versionOf(app.pending.manifest, app.pending.digest)).status !== "ok") {
|
|
12825
|
+
const stops = stopping([versionOf(app.pending.manifest, app.pending.digest)], [...app.revocations ?? [], ...stores.flatMap((s) => s.index?.revoked ?? [])]);
|
|
12826
|
+
if (stops.length) {
|
|
12827
|
+
const tx = (await openDb()).transaction(STORES$1.settings, "readwrite");
|
|
12828
|
+
keepRevocations(tx.objectStore(STORES$1.settings), app.ref, stops);
|
|
12829
|
+
await done(tx);
|
|
12830
|
+
}
|
|
13474
12831
|
dropped.push(app.pending);
|
|
13475
12832
|
const { pending: _p, ...rest } = app;
|
|
13476
12833
|
app = rest;
|
|
@@ -13491,15 +12848,29 @@ var Apps = class {
|
|
|
13491
12848
|
holds = peek;
|
|
13492
12849
|
}
|
|
13493
12850
|
const twin = holds && (holds.sequence === app.sequence || holds.sequence === app.pending?.sequence);
|
|
13494
|
-
if (holds && !twin &&
|
|
12851
|
+
if (holds && !twin && judge(holds).status !== "ok") continue;
|
|
12852
|
+
if (holds && !twin && app.pending && holds.sequence < app.pending.sequence) continue;
|
|
13495
12853
|
if (holds && twin && app.equivocation?.sequence === holds.sequence && app.equivocation.digest === holds.digest) {
|
|
13496
12854
|
outcome = "equivocation";
|
|
13497
12855
|
continue;
|
|
13498
12856
|
}
|
|
12857
|
+
const refused = this.refusedReads.get(url);
|
|
12858
|
+
if (holds && refused?.digest === holds.digest && this.checkedWithin(refused.at, APP_CHECK_TIMINGS.freshMs)) continue;
|
|
13499
12859
|
let fetched;
|
|
13500
12860
|
try {
|
|
13501
12861
|
fetched = await this.fetchBundle(url);
|
|
13502
|
-
} catch {
|
|
12862
|
+
} catch (error) {
|
|
12863
|
+
if (holds && (!(error instanceof AppFetchError) || error.code === "too-large")) {
|
|
12864
|
+
this.refusedReads.delete(url);
|
|
12865
|
+
this.refusedReads.set(url, {
|
|
12866
|
+
digest: holds.digest,
|
|
12867
|
+
at: this.now()
|
|
12868
|
+
});
|
|
12869
|
+
for (const old of this.refusedReads.keys()) {
|
|
12870
|
+
if (this.refusedReads.size <= REFUSED_READS_KEPT) break;
|
|
12871
|
+
this.refusedReads.delete(old);
|
|
12872
|
+
}
|
|
12873
|
+
}
|
|
13503
12874
|
continue;
|
|
13504
12875
|
}
|
|
13505
12876
|
const { bundle, bytes } = fetched;
|
|
@@ -13536,7 +12907,8 @@ var Apps = class {
|
|
|
13536
12907
|
}
|
|
13537
12908
|
continue;
|
|
13538
12909
|
}
|
|
13539
|
-
if (
|
|
12910
|
+
if (judge(version).status !== "ok") continue;
|
|
12911
|
+
if (this.runStatus(version, await this.heldViews(), app.revocations).status !== "ok") continue;
|
|
13540
12912
|
if (app.pending && version.sequence < app.pending.sequence) continue;
|
|
13541
12913
|
const kind = await this.writeBundle(version.digest, bytes);
|
|
13542
12914
|
wrote = {
|
|
@@ -13882,6 +13254,16 @@ var Apps = class {
|
|
|
13882
13254
|
this.usage.set(id, used);
|
|
13883
13255
|
return used;
|
|
13884
13256
|
}
|
|
13257
|
+
/**
|
|
13258
|
+
* A chat removed, its rows gone (`db.deleteLink`): what this engine kept of every app's storage there goes too. A chat's
|
|
13259
|
+
* id comes from its invite, so the same invite joined again is the same scope: with the deleted chat's count still
|
|
13260
|
+
* held, its app found no keys yet every write refused as full until a restart.
|
|
13261
|
+
*/
|
|
13262
|
+
forgetScope(scope) {
|
|
13263
|
+
const of = (id) => id.slice(id.indexOf("\0") + 1) === scope;
|
|
13264
|
+
for (const id of [...this.usage.keys()]) if (of(id)) this.usage.delete(id);
|
|
13265
|
+
for (const id of [...this.keyReads.keys()]) if (of(id)) this.keyReads.delete(id);
|
|
13266
|
+
}
|
|
13885
13267
|
async storageGet({ ref, scope, key, digest }) {
|
|
13886
13268
|
const app = await this.runningOrFail(ref, digest);
|
|
13887
13269
|
const row = await wrap((await store(STORES$1.appStorage, "readonly")).get([
|
|
@@ -13944,6 +13326,7 @@ var Apps = class {
|
|
|
13944
13326
|
});
|
|
13945
13327
|
}
|
|
13946
13328
|
async storageDelete({ ref, scope, key, digest }) {
|
|
13329
|
+
const uninstalls = this.uninstalls.get(ref);
|
|
13947
13330
|
const app = await this.runningOrFail(ref, digest);
|
|
13948
13331
|
const where = this.scopeOf(scope), name = this.keyOf(key);
|
|
13949
13332
|
await this.serial(`${app.ref}\0${where}`, async () => {
|
|
@@ -13956,6 +13339,10 @@ var Apps = class {
|
|
|
13956
13339
|
if (!old) return;
|
|
13957
13340
|
const next = plus(used, countOf(old, -1));
|
|
13958
13341
|
const writing = await store(STORES$1.appStorage, "readwrite");
|
|
13342
|
+
if (this.uninstalls.get(app.ref) !== uninstalls) {
|
|
13343
|
+
this.usage.delete(`${app.ref}\0${where}`);
|
|
13344
|
+
fail("not-installed", "This app is not installed");
|
|
13345
|
+
}
|
|
13959
13346
|
writing.delete([
|
|
13960
13347
|
app.ref,
|
|
13961
13348
|
where,
|
|
@@ -21489,7 +20876,7 @@ var FileDesk = class {
|
|
|
21489
20876
|
deps;
|
|
21490
20877
|
chats = /* @__PURE__ */ new Map();
|
|
21491
20878
|
speeds = /* @__PURE__ */ new Map();
|
|
21492
|
-
/** By local id: when its bytes last moved (for the stall rule). */
|
|
20879
|
+
/** By local id: when its bytes last moved (for the stall rule), and whether it then waited on a person. */
|
|
21493
20880
|
moved = /* @__PURE__ */ new Map();
|
|
21494
20881
|
/** Unfinished when the app started, and not moved since. */
|
|
21495
20882
|
restored = /* @__PURE__ */ new Set();
|
|
@@ -22112,6 +21499,10 @@ var FileDesk = class {
|
|
|
22112
21499
|
* Whether a transfer is stuck (`transferStalled`): not moved for `FILE_LIMITS.stallMs`, or not since the app started.
|
|
22113
21500
|
* Only bytes moving count (`progress`: confirmed by the receiver, stored here), not a session saying again where it
|
|
22114
21501
|
* stands. A stall is nothing happening, so a timer looks again when it would be one.
|
|
21502
|
+
*
|
|
21503
|
+
* Time it waits on a person (an offer not answered yet, a pause) is not time stuck: its quiet spell starts when it goes
|
|
21504
|
+
* on. Before, a file accepted after its offer waited a minute read as stuck at once, "Ask again" beside it, for as
|
|
21505
|
+
* long as it waited its turn behind other files.
|
|
22115
21506
|
*/
|
|
22116
21507
|
stalled(linkId, id, record, progress) {
|
|
22117
21508
|
if (transferEnded(record)) {
|
|
@@ -22119,8 +21510,12 @@ var FileDesk = class {
|
|
|
22119
21510
|
return false;
|
|
22120
21511
|
}
|
|
22121
21512
|
const now = elapsed();
|
|
22122
|
-
|
|
22123
|
-
if (progress) this.
|
|
21513
|
+
const waiting = record.state === "asking" || record.state === "paused";
|
|
21514
|
+
if (progress || waiting || !this.moved.has(id) || this.moved.get(id).waiting) this.moved.set(id, {
|
|
21515
|
+
at: now,
|
|
21516
|
+
...waiting && { waiting }
|
|
21517
|
+
});
|
|
21518
|
+
if (progress || waiting) this.restored.delete(id);
|
|
22124
21519
|
const movedAt = this.moved.get(id).at;
|
|
22125
21520
|
const stalled = transferStalled(record, movedAt, this.restored.has(id), now);
|
|
22126
21521
|
if (!stalled && !this.stallChecks.has(id) && transferStalled(record, 0, true, now)) {
|
|
@@ -22479,12 +21874,16 @@ function canRemove(message) {
|
|
|
22479
21874
|
* version. A status card's update adds none either (WISP 405 · Status Cards): it replaces the card in place, and its
|
|
22480
21875
|
* text is only the card's fallback, so a bot's thousands of updates keep one card and no trail of versions. Buttons
|
|
22481
21876
|
* (WISP 406 · Message Buttons) are the exception: their text is the question people answer, so a new one keeps the
|
|
22482
|
-
* version it replaces, and only a change of the buttons alone (the answer marked, closed) adds none.
|
|
21877
|
+
* version it replaces, and only a change of the buttons alone (the answer marked, closed) adds none. A card on a text
|
|
21878
|
+
* that had none (or had buttons) is not an update: the text it replaces is kept. Only the text as it came keeps the
|
|
21879
|
+
* message's own time: an edited one is dated after it, whatever time the edit's author gave.
|
|
22483
21880
|
*/
|
|
22484
21881
|
function withEdit(message, edit) {
|
|
22485
21882
|
const before = message.edit?.history ?? [];
|
|
22486
|
-
const
|
|
22487
|
-
|
|
21883
|
+
const sent = shownTime(message);
|
|
21884
|
+
const cardUpdate = !!edit.card && edit.card.kind !== "buttons" && !!message.card && message.card.kind !== "buttons";
|
|
21885
|
+
const history = edit.text === message.text || cardUpdate ? before : trimHistory([...before, {
|
|
21886
|
+
at: message.edit ? Math.max(message.edit.at, sent + 1) : sent,
|
|
22488
21887
|
text: message.text
|
|
22489
21888
|
}]);
|
|
22490
21889
|
const next = {
|
|
@@ -22503,10 +21902,14 @@ function withEdit(message, edit) {
|
|
|
22503
21902
|
...edit.card && { card: edit.card }
|
|
22504
21903
|
};
|
|
22505
21904
|
}
|
|
21905
|
+
/** The first version (the text as it came) always stays; of the rest, the newest that fit. */
|
|
22506
21906
|
function trimHistory(history) {
|
|
22507
|
-
|
|
22508
|
-
|
|
22509
|
-
|
|
21907
|
+
if (history.length < 2) return history;
|
|
21908
|
+
const [first, ...rest] = history;
|
|
21909
|
+
let kept = rest.slice(-19);
|
|
21910
|
+
const bytes = (versions) => versions.reduce((sum, version) => sum + utf8Encode(version.text).length, 0);
|
|
21911
|
+
while (kept.length > 1 && bytes([first, ...kept]) > 65536) kept = kept.slice(1);
|
|
21912
|
+
return [first, ...kept];
|
|
22510
21913
|
}
|
|
22511
21914
|
//#endregion
|
|
22512
21915
|
//#region ../browser/src/engine/outbox.ts
|
|
@@ -24076,6 +23479,11 @@ var TARGETED = /* @__PURE__ */ new Set([
|
|
|
24076
23479
|
"usdt"
|
|
24077
23480
|
]);
|
|
24078
23481
|
/**
|
|
23482
|
+
* Ecash sent that can still be taken back: not taken yet, or refused by the contact while the mint did not answer the
|
|
23483
|
+
* automatic take back (`failed`, its token kept). Its bubble offers both, and `PaymentDesk.forgetLink` keeps both.
|
|
23484
|
+
*/
|
|
23485
|
+
var sentUntaken = (p) => p.kind === "payment" && p.direction === "out" && (p.state === "pending" || p.state === "failed") && !!p.token;
|
|
23486
|
+
/**
|
|
24079
23487
|
* What the wallets of one network still wait for (see `WalletAwaitingView`): what removing one of them would lose, or
|
|
24080
23488
|
* close. A request of ours counts only for the wallet it can be paid through, and only when there is one: a request a
|
|
24081
23489
|
* Cashu mint and another Lightning source can both be paid through is not lost when one of them goes.
|
|
@@ -24177,7 +23585,7 @@ function walletAwaiting({ network, mints, quotes, lightningOps, lightningSource,
|
|
|
24177
23585
|
});
|
|
24178
23586
|
}
|
|
24179
23587
|
for (const p of payments) {
|
|
24180
|
-
if (
|
|
23588
|
+
if (!sentUntaken(p)) continue;
|
|
24181
23589
|
const gone = chatGone?.(p.id) ? { chatGone: true } : {};
|
|
24182
23590
|
if (p.target?.method === "fedimint" || p.federation) {
|
|
24183
23591
|
if (paymentNetwork(p) === network) out.push({
|
|
@@ -25495,7 +24903,9 @@ var FULL_SAID_MS$1 = 66e4;
|
|
|
25495
24903
|
* the accept refused, every turn of the door for as long as the admin was away.
|
|
25496
24904
|
*/
|
|
25497
24905
|
function admissionsHeld(s) {
|
|
25498
|
-
|
|
24906
|
+
return !s.isAdmin && membersAtBound(s);
|
|
24907
|
+
}
|
|
24908
|
+
function membersAtBound(s) {
|
|
25499
24909
|
const admin = s.admin, chain = s.state.chain;
|
|
25500
24910
|
let n = 0;
|
|
25501
24911
|
for (let i = chain.length - 1; i >= 0; i--) {
|
|
@@ -25505,6 +24915,16 @@ function admissionsHeld(s) {
|
|
|
25505
24915
|
}
|
|
25506
24916
|
return n >= COMMUNITY_LIMITS.memberAdmissions;
|
|
25507
24917
|
}
|
|
24918
|
+
/**
|
|
24919
|
+
* Whether the admin's app is wanted at the door: the members signed all the admissions in a row they may, and only the
|
|
24920
|
+
* admin lets the next person in. Only hubs answer knocks, and an admin's app that is no hub (the role was handed to
|
|
24921
|
+
* it, or it stepped down when idle) let nobody in while it was open: whoever opened the link waited for good, nobody
|
|
24922
|
+
* told (bug hunt, 2026-11-12: the role handed to a member at 40 members, then 50 opening the link: 32 let in, 18
|
|
24923
|
+
* knocking 20 minutes later). It is one more hub until it lets someone in, which opens the members' door again.
|
|
24924
|
+
*/
|
|
24925
|
+
function adminAtDoor(s) {
|
|
24926
|
+
return s.isAdmin && s.adminWork && !!s.entryKey && !!s.state.entry.seedB64 && membersAtBound(s);
|
|
24927
|
+
}
|
|
25508
24928
|
var RELAYED_KEPT = 4096;
|
|
25509
24929
|
/**
|
|
25510
24930
|
* Someone the chain took out while its app was closed comes back believing it is a member: it asks in a hub's lobby,
|
|
@@ -26372,7 +25792,7 @@ var Communities = class {
|
|
|
26372
25792
|
live.cutOffSince ??= now;
|
|
26373
25793
|
return now - live.cutOffSince < CUT_OFF_STEP_UP_MS;
|
|
26374
25794
|
};
|
|
26375
|
-
const want = () => settled() && !cutOff() && (shouldBeHub(me, this.hubs(live), now) || !!live.forceHub && freshHubs(this.hubs(live), now).length < COMMUNITY_TOPOLOGY.maxHubs) && this.capacity(groupId, live, now) > 0;
|
|
25795
|
+
const want = () => settled() && !cutOff() && (shouldBeHub(me, this.hubs(live), now) || (!!live.forceHub || adminAtDoor(s)) && freshHubs(this.hubs(live), now).length < COMMUNITY_TOPOLOGY.maxHubs) && this.capacity(groupId, live, now) > 0;
|
|
26376
25796
|
if (want()) {
|
|
26377
25797
|
if (!live.hubCandidateAt) live.hubCandidateAt = now + (freshHubs(this.hubs(live), now).length ? Math.floor(this.random() * this.timings.hubJitterMs) : 0);
|
|
26378
25798
|
if (now >= live.hubCandidateAt) {
|
|
@@ -26394,7 +25814,7 @@ var Communities = class {
|
|
|
26394
25814
|
if (live.hub) {
|
|
26395
25815
|
const load = this.hubLoad(groupId, live, now);
|
|
26396
25816
|
if (load > 0) live.emptySince = now;
|
|
26397
|
-
const idle = now - live.emptySince > this.timings.idleHubMs && now - live.hubSince > this.timings.idleHubMs;
|
|
25817
|
+
const idle = now - live.emptySince > this.timings.idleHubMs && now - live.hubSince > this.timings.idleHubMs && !adminAtDoor(s);
|
|
26398
25818
|
if (live.leaving) {
|
|
26399
25819
|
const read = live.beaconAt > live.leaving, listed = live.beacon.some((h) => h.key === me);
|
|
26400
25820
|
if (read && idle && !listed && this.canStepDown(groupId, live, now)) {
|
|
@@ -26643,7 +26063,7 @@ var Communities = class {
|
|
|
26643
26063
|
}
|
|
26644
26064
|
for (const [key, since] of live.members) {
|
|
26645
26065
|
const id = edges.get(key);
|
|
26646
|
-
if (this.gone(live, key)) live.members.delete(key);
|
|
26066
|
+
if (this.gone(live, key) || !rosterHas(live.session.roster, key)) live.members.delete(key);
|
|
26647
26067
|
else if (id && this.host.linkReady(id, 2)) live.members.set(key, now);
|
|
26648
26068
|
else if (live.session.wasRemoved(key)) live.members.delete(key);
|
|
26649
26069
|
else if (now - since > this.timings.memberGoneMs) {
|
|
@@ -26674,13 +26094,16 @@ var Communities = class {
|
|
|
26674
26094
|
* other hubs and, for taking someone new (`entries`), its entry sessions.
|
|
26675
26095
|
*/
|
|
26676
26096
|
capacity(groupId, live, now, entries = true) {
|
|
26097
|
+
return Math.max(0, Math.min(COMMUNITY_TOPOLOGY.hubCapacity, this.room(groupId, live, now, entries)));
|
|
26098
|
+
}
|
|
26099
|
+
/** What the budget of connections leaves for members (`capacity` without its `hubCapacity`); no budget, no bound. */
|
|
26100
|
+
room(groupId, live, now, entries = true) {
|
|
26677
26101
|
const room = this.host.peerRoom?.(groupId);
|
|
26678
|
-
if (room === void 0) return
|
|
26102
|
+
if (room === void 0) return Infinity;
|
|
26679
26103
|
const hubs = new Set(freshHubs(this.hubs(live), now).map((h) => h.key));
|
|
26680
26104
|
for (const key of this.host.edges(groupId).keys()) if (!live.members.has(key)) hubs.add(key);
|
|
26681
26105
|
hubs.delete(live.session.myKey);
|
|
26682
|
-
|
|
26683
|
-
return Math.max(0, Math.min(COMMUNITY_TOPOLOGY.hubCapacity, room - held));
|
|
26106
|
+
return room - hubs.size - (entries ? this.host.entries(groupId).size : 0);
|
|
26684
26107
|
}
|
|
26685
26108
|
/** The load the beacon says: a hub with no room left says it is full, as one at `hubCapacity` does. */
|
|
26686
26109
|
beaconLoad(groupId, live, now) {
|
|
@@ -27138,7 +26561,7 @@ var Communities = class {
|
|
|
27138
26561
|
const turn = Math.floor(waited / KNOCK_SLOT_MS) % order.length, early = order.length === 1 || waited % KNOCK_SLOT_MS < KNOCK_SLOT_OPEN_MS;
|
|
27139
26562
|
if (order[turn] !== s.myKey || !early || waited >= KNOCK_SLOT_MS && !stillKnocking) continue;
|
|
27140
26563
|
if (live.pendingEntries.size >= MAX_PENDING_ENTRIES$1) break;
|
|
27141
|
-
if (
|
|
26564
|
+
if (this.room(groupId, live, now) <= live.members.size) break;
|
|
27142
26565
|
if (this.host.adminTurn && !await this.host.adminTurn(groupId, { wait: false })) break;
|
|
27143
26566
|
live.pendingEntries.set(key, now);
|
|
27144
26567
|
live.doorKey = link.host;
|
|
@@ -27859,6 +27282,7 @@ var MeshHubs = class {
|
|
|
27859
27282
|
primed: false,
|
|
27860
27283
|
gone: /* @__PURE__ */ new Map(),
|
|
27861
27284
|
reactions: /* @__PURE__ */ new Map(),
|
|
27285
|
+
reactionPace: /* @__PURE__ */ new Map(),
|
|
27862
27286
|
need: 0,
|
|
27863
27287
|
departed: /* @__PURE__ */ new Set(),
|
|
27864
27288
|
unreached: /* @__PURE__ */ new Map(),
|
|
@@ -28431,6 +27855,9 @@ var MeshHubs = class {
|
|
|
28431
27855
|
if (!live?.hub) return;
|
|
28432
27856
|
const at = `${frame.k} ${frame.id}`, held = live.reactions.get(at);
|
|
28433
27857
|
if (held && held.n >= frame.n) return;
|
|
27858
|
+
let pace = live.reactionPace.get(frame.k);
|
|
27859
|
+
if (!pace) live.reactionPace.set(frame.k, pace = new ReactionWindow(REACTION_LIMITS.receive, REACTION_LIMITS.windowMs));
|
|
27860
|
+
if (!pace.take()) return;
|
|
28434
27861
|
live.reactions.delete(at);
|
|
28435
27862
|
live.reactions.set(at, frame);
|
|
28436
27863
|
while (live.reactions.size > REACTIONS_KEPT) live.reactions.delete(live.reactions.keys().next().value);
|
|
@@ -29165,10 +28592,13 @@ function invitationClaims(frame) {
|
|
|
29165
28592
|
n: Math.min(Math.max(n, 1), GROUP_MEMBER_CAP.max)
|
|
29166
28593
|
};
|
|
29167
28594
|
}
|
|
29168
|
-
/**
|
|
28595
|
+
/**
|
|
28596
|
+
* Syncs of a removed member answered with the commits it lacks, per farewell: it needs one. Counted per answer, however
|
|
28597
|
+
* many slices it goes in; a sync while one still goes out is not counted (`farewellSync`).
|
|
28598
|
+
*/
|
|
29169
28599
|
var FAREWELL_ANSWERS = 3;
|
|
29170
|
-
/**
|
|
29171
|
-
var
|
|
28600
|
+
/** Who an answer to a removed member's sync goes to (`Groups.farewellAnswers`): its group and its key. */
|
|
28601
|
+
var farewellTo = (groupId, key) => `${groupId} ${key}`;
|
|
29172
28602
|
/**
|
|
29173
28603
|
* The commit of epoch `e` for a removed member, with no secret: with the admin's `left` mark on a removal of someone who
|
|
29174
28604
|
* left on their own, or its app says that the admin removed them (WISP 902 § Admission and departure).
|
|
@@ -29426,7 +28856,7 @@ var Groups = class {
|
|
|
29426
28856
|
membership: (groupId) => this.fileMembership(groupId),
|
|
29427
28857
|
out: (groupId) => this.fileOut(groupId),
|
|
29428
28858
|
sendApp: (groupId, frame) => this.communities.sendApp(groupId, frame),
|
|
29429
|
-
changed: () => host.emit(),
|
|
28859
|
+
changed: (delayMs) => host.emit(delayMs),
|
|
29430
28860
|
now: () => this.now()
|
|
29431
28861
|
});
|
|
29432
28862
|
this.communities.files = this.files;
|
|
@@ -30229,11 +29659,23 @@ var Groups = class {
|
|
|
30229
29659
|
* it where the role went.
|
|
30230
29660
|
*/
|
|
30231
29661
|
async leaveConfirmed(groupId) {
|
|
30232
|
-
|
|
29662
|
+
const group = this.stored.get(groupId), left = group?.left;
|
|
29663
|
+
if (!group || !left) return;
|
|
30233
29664
|
if (this.holdsRole(groupId, this.sessions.get(groupId))) {
|
|
30234
29665
|
if (!this.passedOnUntil.has(groupId)) this.passedOnUntil.set(groupId, this.now() + LEFT_PASSED_ON_MS);
|
|
30235
29666
|
return;
|
|
30236
29667
|
}
|
|
29668
|
+
if (this.farewellKeys(group, this.sessions.get(groupId), this.now()).length) {
|
|
29669
|
+
if (left.heard === void 0) {
|
|
29670
|
+
group.left = {
|
|
29671
|
+
...left,
|
|
29672
|
+
heard: this.now()
|
|
29673
|
+
};
|
|
29674
|
+
await this.store.putGroup(group);
|
|
29675
|
+
this.reconcileEdges(groupId);
|
|
29676
|
+
}
|
|
29677
|
+
return;
|
|
29678
|
+
}
|
|
30237
29679
|
await this.forget(groupId);
|
|
30238
29680
|
}
|
|
30239
29681
|
/** Tombstones the role went on from, removed already, and when they go (`leaveConfirmed`). */
|
|
@@ -30281,10 +29723,15 @@ var Groups = class {
|
|
|
30281
29723
|
const { [key]: _gone, ...rest } = group.farewells;
|
|
30282
29724
|
group.farewells = Object.keys(rest).length ? rest : void 0;
|
|
30283
29725
|
}
|
|
30284
|
-
/**
|
|
29726
|
+
/**
|
|
29727
|
+
* The removed members this admin still waits for: not told yet, told a moment ago (the commit is on its way), or with
|
|
29728
|
+
* my answer to their sync still going out a slice at a time. Also after it left the group: nobody else keeps an edge
|
|
29729
|
+
* to them, and the members it removed would never learn it. Never past `FAREWELL_OPEN_MS` after the edge opened.
|
|
29730
|
+
*/
|
|
30285
29731
|
farewellKeys(group, session, now) {
|
|
30286
|
-
if (!group?.farewells || session.status !== "active") return [];
|
|
30287
|
-
|
|
29732
|
+
if (!group?.farewells || !session || session.status !== "active" && !group.left) return [];
|
|
29733
|
+
const answering = (key) => !!this.farewellAnswers?.busy(farewellTo(group.id, key));
|
|
29734
|
+
return Object.entries(group.farewells).filter(([key, f]) => !rosterHas(session.roster, key) && now - f.at <= 6048e5 && (f.told === void 0 || now - f.told < REMOVED_LINGER_MS || answering(key)) && (f.opened === void 0 || now - f.opened < 6e4)).map(([key]) => key);
|
|
30288
29735
|
}
|
|
30289
29736
|
/** The edges an active member keeps: what the roster (or the hubs) ask for, and those to members it removed while they were away. */
|
|
30290
29737
|
edgesWanted(groupId, session, group, now) {
|
|
@@ -30383,19 +29830,65 @@ var Groups = class {
|
|
|
30383
29830
|
farewell.told ??= this.now();
|
|
30384
29831
|
this.store.putGroup(group).catch(() => {});
|
|
30385
29832
|
}
|
|
30386
|
-
/**
|
|
29833
|
+
/**
|
|
29834
|
+
* The sync of a removed member I wait for: the commits it lacks up to the one that removed it, a few times at most.
|
|
29835
|
+
* Every one from where it is (it takes them only one after the other), a slice at a time as a member's sync answer
|
|
29836
|
+
* goes (`farewellAnswers`): hundreds at once ended its session as more than its app holds waiting
|
|
29837
|
+
* (`SESSION_RECEIVE_PENDING`), and the next tries the same, until it was never told. A sync while my answer still
|
|
29838
|
+
* goes out (its app asks again every 10 s while it takes commits that bring no secret) is no new try: it adds only
|
|
29839
|
+
* what that answer does not hold or has not sent yet.
|
|
29840
|
+
*/
|
|
30387
29841
|
farewellSync(groupId, session, group, key, frame) {
|
|
30388
29842
|
const farewell = group.farewells[key], linkId = this.host.edges(groupId).get(key);
|
|
30389
29843
|
const from = frame.e;
|
|
30390
29844
|
if (!linkId || frame.t !== "group-sync" || !Number.isSafeInteger(from) || from < 0 || from >= farewell.e - 1) return;
|
|
30391
|
-
|
|
30392
|
-
|
|
30393
|
-
|
|
30394
|
-
|
|
30395
|
-
}
|
|
29845
|
+
const answers = this.farewellOut(), to = farewellTo(groupId, key), again = answers.busy(to);
|
|
29846
|
+
if (!again) {
|
|
29847
|
+
if ((farewell.answered ?? 0) >= FAREWELL_ANSWERS) return;
|
|
29848
|
+
farewell.answered = (farewell.answered ?? 0) + 1;
|
|
29849
|
+
}
|
|
29850
|
+
const commits = [];
|
|
29851
|
+
for (let e = from + 1; e <= farewell.e; e++) if (session.state.chain[e]) commits.push(farewellCommit(groupId, session, e));
|
|
29852
|
+
answers.handOut(to, commits);
|
|
29853
|
+
if (again) return;
|
|
30396
29854
|
farewell.told ??= this.now();
|
|
30397
29855
|
this.store.putGroup(group).catch(() => {});
|
|
30398
29856
|
}
|
|
29857
|
+
/**
|
|
29858
|
+
* Answers to removed members' syncs (`farewellSync`), per `farewellTo`, a slice at a time with two at most not handled
|
|
29859
|
+
* yet by the member's app, as a member's catch-up goes (`CatchUpAnswers`). One ends once its edge no longer takes a
|
|
29860
|
+
* frame, or the member is no longer waited for. Made at the first answer.
|
|
29861
|
+
*/
|
|
29862
|
+
farewellAnswers;
|
|
29863
|
+
farewellOut() {
|
|
29864
|
+
if (this.farewellAnswers) return this.farewellAnswers;
|
|
29865
|
+
const edge = (to) => {
|
|
29866
|
+
const [groupId, key] = to.split(" ");
|
|
29867
|
+
return {
|
|
29868
|
+
groupId,
|
|
29869
|
+
key,
|
|
29870
|
+
linkId: this.host.edges(groupId).get(key)
|
|
29871
|
+
};
|
|
29872
|
+
};
|
|
29873
|
+
return this.farewellAnswers = new CatchUpAnswers({
|
|
29874
|
+
send: (to, frame) => {
|
|
29875
|
+
const { groupId, key, linkId } = edge(to), session = this.sessions.get(groupId);
|
|
29876
|
+
if (!linkId || !session || !this.stored.get(groupId)?.farewells?.[key] || rosterHas(session.roster, key)) return false;
|
|
29877
|
+
try {
|
|
29878
|
+
this.host.sendOnLink(linkId, frame);
|
|
29879
|
+
return true;
|
|
29880
|
+
} catch {
|
|
29881
|
+
return false;
|
|
29882
|
+
}
|
|
29883
|
+
},
|
|
29884
|
+
...this.host.linkHandled && { handled: (to) => {
|
|
29885
|
+
const { linkId } = edge(to);
|
|
29886
|
+
return linkId && this.host.linkHandled ? this.host.linkHandled(linkId) : Promise.resolve(false);
|
|
29887
|
+
} },
|
|
29888
|
+
active: () => true,
|
|
29889
|
+
key: (frame) => frame.t === "group-commit" ? `commit:${frame.commit.e}` : void 0
|
|
29890
|
+
});
|
|
29891
|
+
}
|
|
30399
29892
|
async makeAdmin(groupId, key) {
|
|
30400
29893
|
if (this.isCommunity(groupId)) return this.communities.makeAdmin(groupId, key);
|
|
30401
29894
|
await this.session(groupId).transferAdmin(key);
|
|
@@ -30481,6 +29974,7 @@ var Groups = class {
|
|
|
30481
29974
|
this.hereHeard.delete(groupId);
|
|
30482
29975
|
this.hereActed.delete(groupId);
|
|
30483
29976
|
this.signals.forget(groupId);
|
|
29977
|
+
dropMarks(this.marks, groupId);
|
|
30484
29978
|
this.authorOrder.forget(groupId);
|
|
30485
29979
|
this.lineOrder.forget(MESSAGE_LINK(groupId));
|
|
30486
29980
|
for (const linkId of [...this.host.edges(groupId).values(), ...this.host.entries(groupId).values()]) await this.host.closeEdge(linkId);
|
|
@@ -30614,6 +30108,11 @@ var Groups = class {
|
|
|
30614
30108
|
continue;
|
|
30615
30109
|
}
|
|
30616
30110
|
const session = this.sessions.get(group.id);
|
|
30111
|
+
if (group.farewells && session) this.farewellsTick(group.id, session, now);
|
|
30112
|
+
if (group.left.heard !== void 0 && !group.farewells) {
|
|
30113
|
+
await this.forget(group.id);
|
|
30114
|
+
continue;
|
|
30115
|
+
}
|
|
30617
30116
|
if (session?.status === "left" && session.admin === session.myKey && now >= (this.handOnAt.get(group.id) ?? 0)) await this.handOn(group.id);
|
|
30618
30117
|
continue;
|
|
30619
30118
|
}
|
|
@@ -31415,6 +30914,11 @@ var Groups = class {
|
|
|
31415
30914
|
}
|
|
31416
30915
|
if (this.isCommunity(groupId)) return this.communities.handleEdgeFrame(groupId, peerKey, frame);
|
|
31417
30916
|
if (this.stored.get(groupId)?.left) {
|
|
30917
|
+
const tomb = this.stored.get(groupId), session = this.sessions.get(groupId);
|
|
30918
|
+
if (session && tomb.farewells?.[peerKey] && !rosterHas(session.roster, peerKey)) {
|
|
30919
|
+
if (frame && typeof frame === "object") this.farewellSync(groupId, session, tomb, peerKey, frame);
|
|
30920
|
+
return;
|
|
30921
|
+
}
|
|
31418
30922
|
if (this.removesMe(groupId, peerKey, frame)) await this.leaveConfirmed(groupId);
|
|
31419
30923
|
else await this.afterLeave(groupId, peerKey, frame);
|
|
31420
30924
|
return;
|
|
@@ -31620,6 +31124,10 @@ var Groups = class {
|
|
|
31620
31124
|
const left = this.stored.get(groupId)?.left;
|
|
31621
31125
|
if (left) {
|
|
31622
31126
|
const session = this.sessions.get(groupId), group = this.stored.get(groupId);
|
|
31127
|
+
if (session && group.farewells?.[peerKey] && !rosterHas(session.roster, peerKey)) {
|
|
31128
|
+
this.sayFarewell(groupId, session, group, peerKey, linkId);
|
|
31129
|
+
return;
|
|
31130
|
+
}
|
|
31623
31131
|
if (peerKey === left.admin) try {
|
|
31624
31132
|
if (session) this.sayLeave(groupId, session, group, linkId);
|
|
31625
31133
|
else this.host.sendOnLink(linkId, {
|
|
@@ -32351,9 +31859,9 @@ var Groups = class {
|
|
|
32351
31859
|
const left = group?.left;
|
|
32352
31860
|
const removed = this.removedAt.get(groupId);
|
|
32353
31861
|
const wanted = session?.status === "active" && group ? this.edgesWanted(groupId, session, group, this.now()) : left ? /* @__PURE__ */ new Set([
|
|
32354
|
-
left.admin,
|
|
32355
|
-
...
|
|
32356
|
-
...this.
|
|
31862
|
+
...left.heard === void 0 ? [left.admin, ...left.hubs ?? []] : [],
|
|
31863
|
+
...this.holdsRole(groupId, session) && !this.hubs.large(session) ? session.others : [],
|
|
31864
|
+
...this.farewellKeys(group, session, this.now())
|
|
32357
31865
|
]) : removed !== void 0 && this.now() - removed < REMOVED_LINGER_MS ? new Set(existing.keys()) : /* @__PURE__ */ new Set();
|
|
32358
31866
|
for (const [key, linkId] of existing) if (!wanted.has(key)) await this.host.closeEdge(linkId);
|
|
32359
31867
|
const met = this.justMet.get(groupId);
|
|
@@ -32399,6 +31907,34 @@ var Groups = class {
|
|
|
32399
31907
|
eventTimes = /* @__PURE__ */ new Map();
|
|
32400
31908
|
};
|
|
32401
31909
|
//#endregion
|
|
31910
|
+
//#region ../browser/src/engine/communityEdgePace.ts
|
|
31911
|
+
/**
|
|
31912
|
+
* How much slower this app looks at the Pkarr records of its connected edges in a community than a chat would, while it
|
|
31913
|
+
* holds `edges` edges there: up to eight, as a chat; past that, in proportion. A member holds one or two (its hubs);
|
|
31914
|
+
* a hub one per member it carries, and each connected read is a request of the minute the relays allow this app.
|
|
31915
|
+
* At the chat's pace, an admin carrying 22 members spent 22 of its 60 requests a minute on those reads alone, so it
|
|
31916
|
+
* had little left to bring up the edges of the members another hub's closing had cut off, who waited two to five
|
|
31917
|
+
* minutes (bug hunt, 2026-11-11). Now a hub's connected edges cost about 8 reads a minute however many it
|
|
31918
|
+
* carries, as a private group's do (`meshEdgeScale`), and the edges it is bringing up count too, so the reads slow
|
|
31919
|
+
* further while it takes members in. A data link that drops is noticed on its own (the edge reads fast again): a
|
|
31920
|
+
* connected read only notices a member's new offer while this side still thinks the link is up.
|
|
31921
|
+
*/
|
|
31922
|
+
function communityEdgeScale(edges) {
|
|
31923
|
+
return Math.max(1, edges / 8);
|
|
31924
|
+
}
|
|
31925
|
+
/** A community edge's poll pace, read live: its connected reads follow how many edges this app holds there. */
|
|
31926
|
+
function communityEdgeIntervals(base, edges) {
|
|
31927
|
+
return {
|
|
31928
|
+
active: base.active,
|
|
31929
|
+
idle: base.idle,
|
|
31930
|
+
fast: base.fast,
|
|
31931
|
+
background: base.background,
|
|
31932
|
+
get connected() {
|
|
31933
|
+
return Math.round(base.connected * communityEdgeScale(edges()));
|
|
31934
|
+
}
|
|
31935
|
+
};
|
|
31936
|
+
}
|
|
31937
|
+
//#endregion
|
|
32402
31938
|
//#region ../browser/src/engine/groupEdges.ts
|
|
32403
31939
|
/**
|
|
32404
31940
|
* An edge of a group as the group page shows it (WISP 902 § Mesh): open means group frames flow, which
|
|
@@ -32507,7 +32043,7 @@ var RANK = {
|
|
|
32507
32043
|
var ID = /^[A-Za-z0-9_-]{8,64}$/;
|
|
32508
32044
|
/** Notes of mine sent again to a member whose edge opens. */
|
|
32509
32045
|
var RESEND = 32;
|
|
32510
|
-
var NOTE_ID =
|
|
32046
|
+
var NOTE_ID = groupPayLineId;
|
|
32511
32047
|
/** A `group-pay` frame, strictly: anything else is dropped. */
|
|
32512
32048
|
function parseGroupPay(raw, groupId) {
|
|
32513
32049
|
if (!raw || typeof raw !== "object") return null;
|
|
@@ -32619,7 +32155,8 @@ function mergeGroupPay(current, frame, author, members) {
|
|
|
32619
32155
|
return JSON.stringify(next) === JSON.stringify(current) ? void 0 : next;
|
|
32620
32156
|
}
|
|
32621
32157
|
var federationOf = (p) => p.federation ?? p.federations?.[0];
|
|
32622
|
-
|
|
32158
|
+
/** A request's `mint` is where its invoice was paid in (a Cashu mint's Lightning, `onLightningPaid`), not how it was asked. */
|
|
32159
|
+
var railOf = (p) => p.target ? p.target.method === "cashu" ? "cashu" : p.target.method : federationOf(p) ? "fedimint" : p.invoice && !p.mints?.length && (p.kind === "request" || !p.mint) ? "lightning" : "cashu";
|
|
32623
32160
|
/** Test money as the chat's bubble reads it (paymentIsTest): a target's chain, else the record's network, else a Fedimint federation's network, else its mints. */
|
|
32624
32161
|
var testOf = (p, federationNetwork) => {
|
|
32625
32162
|
if (p.target) return p.target.method === "cashu" ? p.target.network === "cashu-test" : p.target.method === "usdt" ? p.unit === "testusdt" : p.target.network !== "bitcoin";
|
|
@@ -32895,6 +32432,11 @@ var said = (m) => m.removed ? {
|
|
|
32895
32432
|
...m.card && { sc: m.card }
|
|
32896
32433
|
};
|
|
32897
32434
|
var resendKey = (groupId, member) => `${groupId}\n${member}`;
|
|
32435
|
+
/**
|
|
32436
|
+
* A row of mine in a private group written under a member key I no longer hold: removed, then invited back, I came in
|
|
32437
|
+
* with a new key, and the group knows my lines from before by the old one. Its session refuses their edits.
|
|
32438
|
+
*/
|
|
32439
|
+
var underOldKey = (message, membership) => !membership.community && !message.id.startsWith(`${membership.me}:`);
|
|
32898
32440
|
var GroupEdits = class {
|
|
32899
32441
|
host;
|
|
32900
32442
|
now;
|
|
@@ -32950,7 +32492,7 @@ var GroupEdits = class {
|
|
|
32950
32492
|
if (typeof messageId !== "string" || typeof raw !== "string") return refuse("No message to edit");
|
|
32951
32493
|
const chat = chatOf(groupId);
|
|
32952
32494
|
const message = await this.find(chat, messageId);
|
|
32953
|
-
if (!message || !canEditInGroup(message)) return refuse("Only your own text messages can be edited");
|
|
32495
|
+
if (!message || !canEditInGroup(message) || underOldKey(message, membership)) return refuse("Only your own text messages can be edited");
|
|
32954
32496
|
const text = raw.trim();
|
|
32955
32497
|
if (!text) return refuse("An edit cannot be empty. Delete the message instead.");
|
|
32956
32498
|
if (isJoinNotice(text)) return refuse("An edit cannot read as a join notice.");
|
|
@@ -32996,10 +32538,11 @@ var GroupEdits = class {
|
|
|
32996
32538
|
error,
|
|
32997
32539
|
refused: true
|
|
32998
32540
|
});
|
|
32999
|
-
|
|
32541
|
+
const membership = this.host.membership(groupId);
|
|
32542
|
+
if (!membership) return refuse(this.notMember(groupId));
|
|
33000
32543
|
const chat = chatOf(groupId);
|
|
33001
32544
|
const message = typeof messageId === "string" ? await this.find(chat, messageId) : void 0;
|
|
33002
|
-
if (!message || message.removed || message.sender !== "me" || !GROUP_MESSAGE_ID.test(message.id)) return refuse("Only your own messages can be deleted for everyone");
|
|
32545
|
+
if (!message || message.removed || message.sender !== "me" || !GROUP_MESSAGE_ID.test(message.id) || underOldKey(message, membership)) return refuse("Only your own messages can be deleted for everyone");
|
|
33003
32546
|
if (!canRemove(message)) return refuse("A payment, a request or a notice cannot be deleted for everyone");
|
|
33004
32547
|
const e = removalNumber(message.edit?.seq);
|
|
33005
32548
|
await this.host.removeMine(chat, message, {
|
|
@@ -33348,22 +32891,6 @@ function outlives(membership, edit) {
|
|
|
33348
32891
|
return edit.rm === true && !membership.community;
|
|
33349
32892
|
}
|
|
33350
32893
|
//#endregion
|
|
33351
|
-
//#region ../browser/src/shared/payLinks.ts
|
|
33352
|
-
/**
|
|
33353
|
-
* The desk's links to members of a community group (WISP 903 · Group Community § Payments): payments with a member
|
|
33354
|
-
* go through the group, sealed to them, over `cpay:<group>:<member>`; a request to everyone over `cpay:<group>`.
|
|
33355
|
-
*/
|
|
33356
|
-
var pairLinkId = (groupId, member) => `cpay:${groupId}:${member}`;
|
|
33357
|
-
var groupLinkId = (groupId) => `cpay:${groupId}`;
|
|
33358
|
-
/** The group and member of a community payment link, or undefined for any other link. */
|
|
33359
|
-
function parsePayLink(linkId) {
|
|
33360
|
-
const m = /^cpay:([A-Za-z0-9_-]{22})(?::([a-z0-9]{52}))?$/.exec(linkId);
|
|
33361
|
-
return m ? {
|
|
33362
|
-
groupId: m[1],
|
|
33363
|
-
...m[2] ? { member: m[2] } : {}
|
|
33364
|
-
} : void 0;
|
|
33365
|
-
}
|
|
33366
|
-
//#endregion
|
|
33367
32894
|
//#region ../browser/src/engine/communityPay.ts
|
|
33368
32895
|
/**
|
|
33369
32896
|
* Payments in community groups (WISP 903 · Group Community § Payments). Members have no edge to each other: what
|
|
@@ -36000,7 +35527,7 @@ var walletTx = (mint, kind, amount, fee, note) => ({
|
|
|
36000
35527
|
/** What a failed payment left in the wallet, said to the person: all of it, or all but the fee the mint kept. */
|
|
36001
35528
|
var backInWallet = (lost) => lost > 0 ? `The sats are back in your wallet, less ${lost} sat${lost === 1 ? "" : "s"} the mint kept as its fee.` : "The sats are back in your wallet.";
|
|
36002
35529
|
/** A mint's own words for a refusal, as one short line: the reason at the end of `lightningRefused`. */
|
|
36003
|
-
var mintReason = (error) => (error instanceof Error ? error.message : String(error)).replace(/\s+/g, " ").trim().slice(0, 160) || "no reason given";
|
|
35530
|
+
var mintReason = (error) => stripHidden((error instanceof Error ? error.message : String(error)).replace(/\s+/g, " ")).replace(/\s+/g, " ").trim().slice(0, 160) || "no reason given";
|
|
36004
35531
|
/**
|
|
36005
35532
|
* How long a mint gets to answer when it is only being asked something (its keys, an invoice). A mint
|
|
36006
35533
|
* that is down can hold a request for minutes; the next mint should get its turn well before that.
|
|
@@ -36613,13 +36140,38 @@ var CashuWallet = class CashuWallet {
|
|
|
36613
36140
|
if (sent) return sent;
|
|
36614
36141
|
}
|
|
36615
36142
|
if (room > 0) throw engineError("notEnoughForFee", { amount: room });
|
|
36143
|
+
const held = await this.heldBySilentSplit(candidates, amount);
|
|
36144
|
+
if (held) throw new SwapUnsettledError(held);
|
|
36616
36145
|
throw engineError(candidates.length === 0 && preferred ? "noSharedMint" : "notEnoughSats");
|
|
36617
36146
|
}
|
|
36147
|
+
/** An open send swap at one of `mints` whose reserved inputs, with the coins free there, would cover `amount`. */
|
|
36148
|
+
async heldBySilentSplit(mints, amount) {
|
|
36149
|
+
for (const mint of mints) {
|
|
36150
|
+
const open = (await this.swapsAt(mint)).filter((s) => s.kind === "send" && !s.released && !s.finished);
|
|
36151
|
+
if (open.length === 0) continue;
|
|
36152
|
+
const held = await Promise.all(open.map((s) => this.storedInputs(s)));
|
|
36153
|
+
const swap = open.find((_, i) => held[i].length > 0);
|
|
36154
|
+
if (swap && total(await this.proofsAt(mint)) + total(held.flat()) >= amount) return swap;
|
|
36155
|
+
}
|
|
36156
|
+
}
|
|
36618
36157
|
async prepareReviewedCashu(mint, amount) {
|
|
36619
36158
|
assertAmount(amount);
|
|
36620
36159
|
if (!this.getKnownMints().includes(mint)) throw new Error("Select a configured mint");
|
|
36621
36160
|
return this.locked(mint, async () => {
|
|
36622
|
-
const
|
|
36161
|
+
const wallet = await this.wallet(mint);
|
|
36162
|
+
const proofs = await this.proofsAt(mint);
|
|
36163
|
+
const prepare = (sats) => wallet.ops.send(sats, asProofLike(proofs)).includeFees(true).prepare();
|
|
36164
|
+
const preview = await prepare(amount).catch(async (error) => {
|
|
36165
|
+
if (!/^Not enough funds available/.test(error instanceof Error ? error.message : "")) throw error;
|
|
36166
|
+
const fits = (sats) => prepare(sats).then(() => true, () => false);
|
|
36167
|
+
let low = 0, high = Math.min(amount, total(proofs) - wallet.getFeesForProofs(asProofLike(proofs)).toNumber()) - 1;
|
|
36168
|
+
while (low < high) {
|
|
36169
|
+
const middle = Math.ceil((low + high) / 2);
|
|
36170
|
+
if (await fits(middle)) low = middle;
|
|
36171
|
+
else high = middle - 1;
|
|
36172
|
+
}
|
|
36173
|
+
throw low > 0 ? engineError("notEnoughForFee", { amount: low }) : engineError("notEnoughSats");
|
|
36174
|
+
});
|
|
36623
36175
|
return {
|
|
36624
36176
|
fee: await reviewedCashuFee(preview),
|
|
36625
36177
|
prepared: {
|
|
@@ -37915,8 +37467,11 @@ function parseSats(value, asset) {
|
|
|
37915
37467
|
* wallet's `engineCode` and `values` stay on it: a host reads why by them (the CLI's `refused`, the app's words).
|
|
37916
37468
|
*/
|
|
37917
37469
|
var NoEcashError = class extends Error {
|
|
37470
|
+
/** The mint took the split and has not answered: the sats it set aside come back once it does (`SwapUnsettledError`). */
|
|
37471
|
+
unsettled;
|
|
37918
37472
|
constructor(cause) {
|
|
37919
37473
|
super(cause instanceof Error ? cause.message : String(cause));
|
|
37474
|
+
this.unsettled = cause instanceof SwapUnsettledError;
|
|
37920
37475
|
const { engineCode, values } = cause ?? {};
|
|
37921
37476
|
if (engineCode !== void 0) Object.assign(this, { engineCode });
|
|
37922
37477
|
if (values !== void 0) Object.assign(this, { values });
|
|
@@ -38114,6 +37669,8 @@ var RAIL_LOOK_MS = 1e4;
|
|
|
38114
37669
|
* ago: otherwise a pace stays shut for as long as the clock went back.
|
|
38115
37670
|
*/
|
|
38116
37671
|
var within = (now, at, ms) => at !== void 0 && at <= now && now - at < ms;
|
|
37672
|
+
/** What a contact reads about a request of ours closed for good (`close`), when it closes and each time their chat opens again. */
|
|
37673
|
+
var CLOSED_TOLD = "your contact removed the wallet it was paid to";
|
|
38117
37674
|
/**
|
|
38118
37675
|
* How often a wallet's own refresh asks about an open Ark request (at its server's indexer) or a contact's pending Ark
|
|
38119
37676
|
* or USDT receipt (at the server or the chain) that has no answer yet (`AskBackoff`): at the wallet's pace while the
|
|
@@ -38664,6 +38221,7 @@ var PaymentDesk = class {
|
|
|
38664
38221
|
await link.requirePaymentSupport();
|
|
38665
38222
|
const lightning = !!request.invoice && link.allowsPayment("lightning");
|
|
38666
38223
|
if (params.via === "lightning" && !lightning) throw new Error("This request cannot be paid over Lightning in this chat");
|
|
38224
|
+
let unsettled;
|
|
38667
38225
|
if (params.via !== "lightning" && link.allowsPayment("cashu") && !request.federations) try {
|
|
38668
38226
|
await this.sendEcash(link, {
|
|
38669
38227
|
linkId: params.linkId,
|
|
@@ -38676,9 +38234,13 @@ var PaymentDesk = class {
|
|
|
38676
38234
|
return;
|
|
38677
38235
|
} catch (error) {
|
|
38678
38236
|
if (!lightning || !(error instanceof NoEcashError)) throw error;
|
|
38237
|
+
if (error.unsettled) unsettled = error;
|
|
38679
38238
|
}
|
|
38680
38239
|
else if (!lightning) throw new Error("No way of paying this request is allowed in this chat");
|
|
38681
|
-
const quote = await this.lightning[network].quote(request.invoice, params.card)
|
|
38240
|
+
const quote = await this.lightning[network].quote(request.invoice, params.card).catch((error) => {
|
|
38241
|
+
const code = error?.engineCode;
|
|
38242
|
+
throw unsettled && (code === "notEnoughSats" || code === "notEnoughForFee") ? unsettled : error;
|
|
38243
|
+
});
|
|
38682
38244
|
if (quote.amount !== request.amount) throw new Error("The invoice does not match the requested amount");
|
|
38683
38245
|
const feeLimit = Math.min(Math.max(10, Math.ceil(request.amount * .03)), params.maxFee ?? Infinity);
|
|
38684
38246
|
if (quote.feeReserve > feeLimit) throw engineError("lightningFeeTooHigh", { fee: quote.feeReserve });
|
|
@@ -38850,6 +38412,12 @@ var PaymentDesk = class {
|
|
|
38850
38412
|
state: "settled",
|
|
38851
38413
|
token: void 0
|
|
38852
38414
|
});
|
|
38415
|
+
else if (current.state === "failed" && current.token) await this.save({
|
|
38416
|
+
...current,
|
|
38417
|
+
state: "settled",
|
|
38418
|
+
token: void 0,
|
|
38419
|
+
error: void 0
|
|
38420
|
+
});
|
|
38853
38421
|
return;
|
|
38854
38422
|
}
|
|
38855
38423
|
}
|
|
@@ -40758,10 +40326,10 @@ var PaymentDesk = class {
|
|
|
40758
40326
|
/**
|
|
40759
40327
|
* A request of ours closed for good: the wallet it was paid through was removed. Nothing sends it again (replay,
|
|
40760
40328
|
* a group edge opening), and the contact is told now when the chat is open (a request to a group: every member
|
|
40761
|
-
* reachable), so their app stops offering to pay it. `reason`: shown
|
|
40762
|
-
* whether it was open.
|
|
40329
|
+
* reachable; one away is told when their chat opens, `replay`), so their app stops offering to pay it. `reason`: shown
|
|
40330
|
+
* here. Returns whether it was open.
|
|
40763
40331
|
*/
|
|
40764
|
-
async close(id, reason
|
|
40332
|
+
async close(id, reason) {
|
|
40765
40333
|
const request = this.payments.get(id);
|
|
40766
40334
|
if (request?.kind !== "request" || request.direction !== "out" || request.state !== "pending") return false;
|
|
40767
40335
|
await this.save({
|
|
@@ -40777,7 +40345,7 @@ var PaymentDesk = class {
|
|
|
40777
40345
|
link.sendPaymentResult({
|
|
40778
40346
|
id,
|
|
40779
40347
|
ok: false,
|
|
40780
|
-
error:
|
|
40348
|
+
error: CLOSED_TOLD,
|
|
40781
40349
|
closed: true
|
|
40782
40350
|
});
|
|
40783
40351
|
} catch {}
|
|
@@ -40796,6 +40364,12 @@ var PaymentDesk = class {
|
|
|
40796
40364
|
id: request.id,
|
|
40797
40365
|
ok: true
|
|
40798
40366
|
});
|
|
40367
|
+
else if (request.closed) link.sendPaymentResult({
|
|
40368
|
+
id: request.id,
|
|
40369
|
+
ok: false,
|
|
40370
|
+
error: CLOSED_TOLD,
|
|
40371
|
+
closed: true
|
|
40372
|
+
});
|
|
40799
40373
|
}
|
|
40800
40374
|
for (const payment of this.payments.values()) {
|
|
40801
40375
|
if (payment.linkId !== linkId || payment.direction !== "out" || this.reclaims.has(payment.id)) continue;
|
|
@@ -40806,6 +40380,15 @@ var PaymentDesk = class {
|
|
|
40806
40380
|
});
|
|
40807
40381
|
continue;
|
|
40808
40382
|
}
|
|
40383
|
+
if (payment.kind === "request" && payment.closed) {
|
|
40384
|
+
link.sendPaymentResult({
|
|
40385
|
+
id: payment.id,
|
|
40386
|
+
ok: false,
|
|
40387
|
+
error: CLOSED_TOLD,
|
|
40388
|
+
closed: true
|
|
40389
|
+
});
|
|
40390
|
+
continue;
|
|
40391
|
+
}
|
|
40809
40392
|
if (payment.target?.method === "usdt") {
|
|
40810
40393
|
if (!link.supportsUsdtPayments) continue;
|
|
40811
40394
|
if (payment.kind === "request" && payment.state === "pending" && payment.target.expiresAt > Date.now()) await link.sendPaymentRequest({
|
|
@@ -41526,6 +41109,8 @@ var STARTUP_QUIET_MS = 15e3;
|
|
|
41526
41109
|
var START_SLICE_MS = 10;
|
|
41527
41110
|
/** How long the wallets' changes gather into one view of them (`walletChanged`). */
|
|
41528
41111
|
var WALLET_CHANGE_MS = 50;
|
|
41112
|
+
/** How often the shared services' request counts may send a state while contacts use them (`hostedService`). */
|
|
41113
|
+
var REQUEST_COUNTS_MS = 1e3;
|
|
41529
41114
|
var SPARE_INVITE_MAX_AGE_MS = 9e5;
|
|
41530
41115
|
/** How far before this clock a warm packet is dated (`warmKey`): further than a contact's clock is ever behind. */
|
|
41531
41116
|
var WARM_DATED_BACK_MS = 864e5;
|
|
@@ -41871,6 +41456,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41871
41456
|
/** `group-wake` frames read per edge, a handful a minute. */
|
|
41872
41457
|
groupWakeReceived = /* @__PURE__ */ new Map();
|
|
41873
41458
|
requestCounts = /* @__PURE__ */ new Map();
|
|
41459
|
+
/** A request only moves a counter: the counts go out with the next state, at most once a `REQUEST_COUNTS_MS`. */
|
|
41460
|
+
requestCountsTimer;
|
|
41874
41461
|
transfers = /* @__PURE__ */ new Map();
|
|
41875
41462
|
/**
|
|
41876
41463
|
* Views that go in the next state sent, and then away (`GroupFilesHost.brief`): dropped once a state carried them,
|
|
@@ -41907,6 +41494,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41907
41494
|
}
|
|
41908
41495
|
});
|
|
41909
41496
|
stateTimer = null;
|
|
41497
|
+
/** When the snapshot `stateTimer` waits for is due (`emitState`). */
|
|
41498
|
+
stateDue = 0;
|
|
41910
41499
|
paymentTimer = null;
|
|
41911
41500
|
/**
|
|
41912
41501
|
* The reviews whose outcome is still open (submitted, unknown), by id: what the payment poll asks about, so that it
|
|
@@ -41915,11 +41504,13 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41915
41504
|
*/
|
|
41916
41505
|
openReviews = null;
|
|
41917
41506
|
/**
|
|
41918
|
-
* The pace of each submitted
|
|
41919
|
-
*
|
|
41920
|
-
*
|
|
41507
|
+
* The pace of each submitted payment whose outcome is still open: asked at 10 s while new, then twice as late up to
|
|
41508
|
+
* 10 min (as a payee retries a redeem). At the poll's own 10 s, a contact online whose redeems fail cost the mint 12
|
|
41509
|
+
* checkstates a minute for each such Cashu payment, and an on-chain payment waiting in the mempool its source 360
|
|
41510
|
+
* reads an hour (each with the Ark, Bark, Spark and USDT wallets read again), for as long as it stayed so. The
|
|
41511
|
+
* contact taking one says so at once.
|
|
41921
41512
|
*/
|
|
41922
|
-
|
|
41513
|
+
payAsk = new AskBackoff(1e4, 6e5);
|
|
41923
41514
|
noteOpenReviews(reviews) {
|
|
41924
41515
|
const open = this.openReviews ??= /* @__PURE__ */ new Set();
|
|
41925
41516
|
for (const review of reviews) if (review.state === "submitted" || review.state === "unknown") open.add(review.id);
|
|
@@ -42110,6 +41701,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42110
41701
|
host: () => this.providerHost(network),
|
|
42111
41702
|
hasMints: () => this.networkMints(network).length > 0,
|
|
42112
41703
|
fetch: (...request) => (this.options.lnurlFetch ?? globalThis.fetch)(...request),
|
|
41704
|
+
sparkStorage: () => this.sparkWallets[network].adapter?.storage,
|
|
42113
41705
|
events: {
|
|
42114
41706
|
changed: () => this.walletChanged(),
|
|
42115
41707
|
received: (op) => void this.desk.onLightningPaid(op),
|
|
@@ -42308,6 +41900,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42308
41900
|
}
|
|
42309
41901
|
}),
|
|
42310
41902
|
receiveFile: async (linkId, wire, bytes, digest, held) => {
|
|
41903
|
+
if (await this.namesMine(linkId, wire.wireId)) return "duplicate file id";
|
|
42311
41904
|
const live = this.links.get(linkId);
|
|
42312
41905
|
if (!live) return "unknown chat";
|
|
42313
41906
|
if (live.files.wireIds.has(wire.wireId)) return "duplicate file id";
|
|
@@ -42830,7 +42423,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42830
42423
|
staysOnline: () => this.options.staysOnline ?? (this.options.platform === "desktop" && typeof RTCPeerConnection !== "undefined"),
|
|
42831
42424
|
peerRoom: (groupId) => {
|
|
42832
42425
|
const native = Object.keys(this.nativeFactories);
|
|
42833
|
-
if (
|
|
42426
|
+
if (!this.contactRtc() && native.length) {
|
|
42834
42427
|
let held = 0;
|
|
42835
42428
|
for (const live of this.links.values()) if (live.stored.group && live.stored.group !== groupId && live.link) held++;
|
|
42836
42429
|
return Math.max(0, Math.max(...native.map((key) => this.groupNativeRoom(key))) - held);
|
|
@@ -42895,7 +42488,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42895
42488
|
placeAbove: (linkId, id) => this.placeAbove(linkId, id),
|
|
42896
42489
|
membersChanged: (groupId) => this.groupMembersChanged(groupId),
|
|
42897
42490
|
historyGone: (groupId) => this.groupHistoryGone(groupId),
|
|
42898
|
-
emit: () => this.emitState(),
|
|
42491
|
+
emit: (delayMs) => this.emitState(delayMs),
|
|
42899
42492
|
communityApp: (groupId, sender, frame) => frame.t === "reaction" ? this.receiveGroupReaction(groupId, sender, frame) : frame.t === "edit" ? this.receiveCommunityEdit(groupId, sender, frame) : frame.t === "pin" ? this.receiveGroupPin(groupId, sender, readPin(frame)) : this.communityPay.receiveApp(groupId, sender, frame),
|
|
42900
42493
|
groupEdit: async (groupId, { sender, ...edit }) => {
|
|
42901
42494
|
await this.groupEdits.receive(groupId, sender, edit);
|
|
@@ -43190,7 +42783,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43190
42783
|
*/
|
|
43191
42784
|
async sentWithoutLine(payments) {
|
|
43192
42785
|
const lost = /* @__PURE__ */ new Set();
|
|
43193
|
-
const sent = payments.filter(
|
|
42786
|
+
const sent = payments.filter(sentUntaken);
|
|
43194
42787
|
if (!sent.length) return lost;
|
|
43195
42788
|
let groups;
|
|
43196
42789
|
const everyGroup = () => groups ??= this.groups.views().map((g) => g.id);
|
|
@@ -43391,9 +42984,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43391
42984
|
try {
|
|
43392
42985
|
if (!this.openReviews) this.noteOpenReviews((await intentRepository.list()).map((saved) => saved.review));
|
|
43393
42986
|
const open = this.openReviews;
|
|
43394
|
-
this.
|
|
42987
|
+
this.payAsk.keepOnly(open);
|
|
43395
42988
|
for (const id of [...open]) {
|
|
43396
|
-
if (!this.
|
|
42989
|
+
if (!this.payAsk.due(id, Date.now())) continue;
|
|
43397
42990
|
const saved = await intentRepository.get(id), review = saved?.review;
|
|
43398
42991
|
if (!review || !["submitted", "unknown"].includes(review.state)) {
|
|
43399
42992
|
open.delete(id);
|
|
@@ -43404,7 +42997,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43404
42997
|
if (review.method === "cashu" && !prepared.abandoned && !prepared.spentElsewhere && !this.wallet.mintDue(prepared.mint, Date.now())) continue;
|
|
43405
42998
|
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;
|
|
43406
42999
|
const after = await this.reconcilePayment({ id: review.id }).catch(() => review);
|
|
43407
|
-
if (
|
|
43000
|
+
if (["submitted", "unknown"].includes(after.state)) {
|
|
43001
|
+
const sent = review.submittedAt ?? review.createdAt;
|
|
43002
|
+
this.payAsk.missed(id, Date.now(), Date.now() < (review.method === "cashu" && !prepared.token ? swapSettledAt(review, prepared) : sent + 6e4));
|
|
43003
|
+
}
|
|
43408
43004
|
}
|
|
43409
43005
|
} finally {
|
|
43410
43006
|
if (!this.shuttingDown) this.paymentTimer = setTimeout(() => void this.pollPaymentStatus(), 1e4);
|
|
@@ -43458,31 +43054,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43458
43054
|
this.groupsLoaded = true;
|
|
43459
43055
|
this.groupsLoadedNow();
|
|
43460
43056
|
this.emitState();
|
|
43461
|
-
for (
|
|
43057
|
+
for (const stored of links) {
|
|
43462
43058
|
if (stored.group) continue;
|
|
43463
43059
|
await this.settleHistory(stored.id);
|
|
43464
|
-
|
|
43465
|
-
|
|
43466
|
-
|
|
43467
|
-
|
|
43468
|
-
|
|
43469
|
-
|
|
43470
|
-
state: "failed",
|
|
43471
|
-
error: "Transfer interrupted. Retry when connected."
|
|
43472
|
-
} : file.transfer);
|
|
43473
|
-
const unreceipted = new Set(messages.flatMap((m) => m.sender === "me" && m.file && m.delivery !== "delivered" ? [m.file.id] : []));
|
|
43474
|
-
this.fileDesk.restore(stored.id, storedFiles, unreceipted);
|
|
43475
|
-
const files = linkFilesFrom(stored.id, storedFiles, messages);
|
|
43476
|
-
this.links.set(stored.id, newLiveLink(stored, messages[messages.length - 1]?.timestamp ?? 0, files));
|
|
43477
|
-
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
43478
|
-
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
43479
|
-
this.editsFor(stored.id).learn([...messages, ...(stored.removals ?? []).map((r) => removalRow(stored.id, r))]);
|
|
43480
|
-
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
43481
|
-
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
43482
|
-
const note = this.noteFromHistory(stored.id, messages);
|
|
43483
|
-
if (note) this.reactionNotes.set(stored.id, note);
|
|
43484
|
-
if (stored.reactionsWaiting?.length) await this.reactions.restore(stored.id, stored.reactionsWaiting, messages);
|
|
43485
|
-
if (stored.profile) await this.outboxFor(stored.id).recover(messages);
|
|
43060
|
+
if (this.deferredChats.has(stored.id)) {
|
|
43061
|
+
this.links.set(stored.id, newLiveLink(stored, (await db.getMessagePage(stored.id, { limit: 1 })).messages[0]?.timestamp ?? 0));
|
|
43062
|
+
this.chatRestores.set(stored.id, null);
|
|
43063
|
+
continue;
|
|
43064
|
+
}
|
|
43065
|
+
await this.restoreChat(stored);
|
|
43486
43066
|
}
|
|
43487
43067
|
this.transfersRestored = true;
|
|
43488
43068
|
this.awaitingSoon();
|
|
@@ -43505,6 +43085,56 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43505
43085
|
else if (!this.options.singleDevice && this.limitedMode && knownDeviceGate()?.state === "active") this.readTurnWhileLimited();
|
|
43506
43086
|
if (this.restoreCheck === "checking" && this.limitedMode) this.checkRestoredTurn(0);
|
|
43507
43087
|
}
|
|
43088
|
+
/**
|
|
43089
|
+
* The chats left unstarted at start (`deferChats`) whose history is not read yet: `null` until the command names one
|
|
43090
|
+
* (`restoreDeferred`), then that read.
|
|
43091
|
+
*/
|
|
43092
|
+
chatRestores = /* @__PURE__ */ new Map();
|
|
43093
|
+
/** A deferred chat's restore (`restoreChat`), read once, before it starts or a command reads it. */
|
|
43094
|
+
restoreDeferred(linkId) {
|
|
43095
|
+
const restore = this.chatRestores.get(linkId);
|
|
43096
|
+
if (restore !== null) return restore ?? Promise.resolve();
|
|
43097
|
+
const live = this.links.get(linkId);
|
|
43098
|
+
const restoring = live ? this.restoreChat(live.stored) : Promise.resolve();
|
|
43099
|
+
this.chatRestores.set(linkId, restoring);
|
|
43100
|
+
return restoring;
|
|
43101
|
+
}
|
|
43102
|
+
/**
|
|
43103
|
+
* What a saved 1:1 chat knows from its history, read whole once: its newest message, its files and their transfers, what
|
|
43104
|
+
* waits for it to be live, my edits on their way, when the contact was last heard, its latest reaction, and the
|
|
43105
|
+
* outbox's rows.
|
|
43106
|
+
*/
|
|
43107
|
+
async restoreChat(stored) {
|
|
43108
|
+
const messages = await db.getMessages(stored.id);
|
|
43109
|
+
stored = await this.settleJoinLine(stored, messages);
|
|
43110
|
+
const storedFiles = await fileStore.listForLink(stored.id);
|
|
43111
|
+
const notInterrupted = new Set(messages.flatMap((m) => m.sender === "me" && m.file && (m.delivery === "waiting" || m.via === "hold" && (m.delivery === "held" || m.delivery === "delivered")) ? [m.file.id] : []));
|
|
43112
|
+
for (const file of storedFiles) if (file.transfer && file.transfer.state !== "done" && !file.wire3 && !notInterrupted.has(file.id)) this.transfers.set(file.id, file.transfer.state === "transferring" ? {
|
|
43113
|
+
...file.transfer,
|
|
43114
|
+
state: "failed",
|
|
43115
|
+
error: "Transfer interrupted. Retry when connected."
|
|
43116
|
+
} : file.transfer);
|
|
43117
|
+
const unreceipted = new Set(messages.flatMap((m) => m.sender === "me" && m.file && m.delivery !== "delivered" ? [m.file.id] : []));
|
|
43118
|
+
this.fileDesk.restore(stored.id, storedFiles, unreceipted);
|
|
43119
|
+
const files = linkFilesFrom(stored.id, storedFiles, messages);
|
|
43120
|
+
const newest = messages[messages.length - 1]?.timestamp ?? 0;
|
|
43121
|
+
const left = this.links.get(stored.id);
|
|
43122
|
+
if (left) Object.assign(left, {
|
|
43123
|
+
stored,
|
|
43124
|
+
lastMessageAt: Math.max(left.lastMessageAt, newest),
|
|
43125
|
+
files
|
|
43126
|
+
});
|
|
43127
|
+
else this.links.set(stored.id, newLiveLink(stored, newest, files));
|
|
43128
|
+
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
43129
|
+
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
43130
|
+
this.editsFor(stored.id).learn([...messages, ...(stored.removals ?? []).map((r) => removalRow(stored.id, r))]);
|
|
43131
|
+
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
43132
|
+
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
43133
|
+
const note = this.noteFromHistory(stored.id, messages);
|
|
43134
|
+
if (note) this.reactionNotes.set(stored.id, note);
|
|
43135
|
+
if (stored.reactionsWaiting?.length) await this.reactions.restore(stored.id, stored.reactionsWaiting, messages);
|
|
43136
|
+
if (stored.profile) await this.outboxFor(stored.id).recover(messages);
|
|
43137
|
+
}
|
|
43508
43138
|
/** Where the check of a restored copy stands: reading every 30 seconds, or a tombstone found (the person decides). */
|
|
43509
43139
|
restoreCheck = null;
|
|
43510
43140
|
restoreTimer = null;
|
|
@@ -43939,6 +43569,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43939
43569
|
if (this.paymentTimer) clearTimeout(this.paymentTimer);
|
|
43940
43570
|
clearTimeout(this.awaitingTimer);
|
|
43941
43571
|
clearTimeout(this.walletChangeTimer);
|
|
43572
|
+
clearTimeout(this.requestCountsTimer);
|
|
43942
43573
|
clearInterval(this.staleReviewTimer);
|
|
43943
43574
|
if (this.spareTimer) clearTimeout(this.spareTimer);
|
|
43944
43575
|
for (const timer of this.reactionTimers.values()) clearTimeout(timer);
|
|
@@ -44057,8 +43688,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44057
43688
|
appInstall(params) {
|
|
44058
43689
|
return this.appStore.install(params);
|
|
44059
43690
|
}
|
|
44060
|
-
|
|
44061
|
-
|
|
43691
|
+
/** Installs a waiting update; the pages are told, so another tab's screen drops its Update. */
|
|
43692
|
+
async appUpdateAccept(params) {
|
|
43693
|
+
const view = await this.appStore.acceptUpdate(params);
|
|
43694
|
+
this.events.onAppsChecked?.();
|
|
43695
|
+
return view;
|
|
44062
43696
|
}
|
|
44063
43697
|
appCheckUpdates() {
|
|
44064
43698
|
return this.appStore.checkUpdates();
|
|
@@ -44120,10 +43754,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44120
43754
|
} } : {},
|
|
44121
43755
|
...this.transport.configure && { direct: true },
|
|
44122
43756
|
...this.transport.discovery && { discovery: this.transport.discovery() },
|
|
44123
|
-
|
|
43757
|
+
...!this.contactRtc() && { webrtc: false },
|
|
44124
43758
|
...this.directPath.blocked && { directBlocked: true },
|
|
44125
43759
|
...this.clock.offset !== null && { clockOffMs: this.clock.offset },
|
|
44126
|
-
|
|
43760
|
+
...!this.contactRtc() && !Object.keys(this.nativeFactories).length && { groupLinks: false }
|
|
44127
43761
|
},
|
|
44128
43762
|
links: [...this.links.values()].filter((live) => !live.stored.group).map((live) => this.viewOf(live)).sort((a, b) => b.createdAt - a.createdAt),
|
|
44129
43763
|
services: this.services.map((s) => ({
|
|
@@ -44391,7 +44025,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44391
44025
|
const existing = [...this.links.values()].find((l) => l.stored.seedB64 === params.seedB64);
|
|
44392
44026
|
if (existing) {
|
|
44393
44027
|
if (existing.stored.profile !== params.profile) throw new Error("Invitation profile does not match the stored link");
|
|
44394
|
-
|
|
44028
|
+
await this.startDeferredChat(existing.stored.id);
|
|
44395
44029
|
return { linkId: await this.existingLink(existing.stored.id) };
|
|
44396
44030
|
}
|
|
44397
44031
|
this.refuseOwnInvite(params);
|
|
@@ -44911,10 +44545,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44911
44545
|
* what says it. Apart from the message wake-ups' limit, so it never holds one back. A muted chat's contact shared no
|
|
44912
44546
|
* target; a group's edge is never told. `WAKE_ONLINE_BATCH` at a time, the rest a `WAKE_ONLINE_BATCH_MS` later (those
|
|
44913
44547
|
* still away then), so a push relay's minute keeps room for the message and call wake-ups. None while this profile does
|
|
44914
|
-
* not share when it is online (`sharePresence`).
|
|
44548
|
+
* not share when it is online (`sharePresence`), nor while the host says this run is not online to them (`onlineNotices`).
|
|
44915
44549
|
*/
|
|
44916
44550
|
sayOnline(now = Date.now()) {
|
|
44917
|
-
if (!this.networkOn || this.shuttingDown || this.settings.sharePresence === false) return;
|
|
44551
|
+
if (!this.networkOn || this.shuttingDown || this.settings.sharePresence === false || this.options.onlineNotices?.() === false) return;
|
|
44918
44552
|
let sent = 0;
|
|
44919
44553
|
for (const live of this.links.values()) {
|
|
44920
44554
|
const { id, peerWake: target, profile, group, onlineWokeAt } = live.stored;
|
|
@@ -45175,7 +44809,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45175
44809
|
this.wakeLimiter.reset(linkId);
|
|
45176
44810
|
this.callWakeLimiter.reset(linkId);
|
|
45177
44811
|
if (live.stored.wakeToken) this.rotateWake().then(() => this.emitState());
|
|
45178
|
-
db.deleteLink(linkId);
|
|
44812
|
+
db.deleteLink(linkId).finally(() => this.appShelf?.forgetScope(linkId));
|
|
45179
44813
|
this.desk.forgetLink(linkId);
|
|
45180
44814
|
this.awaitingSoon();
|
|
45181
44815
|
this.emitState();
|
|
@@ -46391,6 +46025,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46391
46025
|
removalPending({ linkId, messageId }) {
|
|
46392
46026
|
return !!this.links.get(linkId)?.stored.removals?.some((r) => r.id === messageId);
|
|
46393
46027
|
}
|
|
46028
|
+
/** The messages of a 1:1 chat whose removal of mine is still on its way to the contact, by id (`removeMessage`). */
|
|
46029
|
+
removalsPending({ linkId }) {
|
|
46030
|
+
return (this.links.get(linkId)?.stored.removals ?? []).map((r) => r.id);
|
|
46031
|
+
}
|
|
46394
46032
|
/** A chat's row write of its removals and deleted ids waiting to go, by chat (`writeDeletions`). */
|
|
46395
46033
|
deletionWrites = /* @__PURE__ */ new Map();
|
|
46396
46034
|
/** The last such write of each chat, which the next one follows. */
|
|
@@ -46857,6 +46495,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46857
46495
|
* (its offer came first), or its message was deleted here.
|
|
46858
46496
|
*/
|
|
46859
46497
|
async fileAnnounced(linkId, said, packet) {
|
|
46498
|
+
if (await this.namesMine(linkId, said.wireId)) return;
|
|
46860
46499
|
const live = this.links.get(linkId);
|
|
46861
46500
|
if (!live) return;
|
|
46862
46501
|
const id = `peer_${said.wireId}`;
|
|
@@ -47296,7 +46935,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47296
46935
|
*/
|
|
47297
46936
|
async setGroupTransport({ groupId, transport }) {
|
|
47298
46937
|
if (!this.groups.view(groupId)) throw new Error("Group not found");
|
|
47299
|
-
const runs = transport === "webrtc/1" ?
|
|
46938
|
+
const runs = transport === "webrtc/1" ? this.contactRtc() : transport !== "auto" && TRANSPORTS.includes(transport) && transport in this.nativeFactories;
|
|
47300
46939
|
if (transport !== "auto" && !runs) throw new Error("Transport unavailable");
|
|
47301
46940
|
if ((this.settings.groupTransports?.[groupId] ?? "auto") === transport) return;
|
|
47302
46941
|
const { [groupId]: _, ...others } = this.settings.groupTransports ?? {};
|
|
@@ -48359,8 +47998,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48359
47998
|
ownStatusTimer;
|
|
48360
47999
|
/** Per chat: when the contact's status ends, so its view is drawn again without it. */
|
|
48361
48000
|
peerStatusTimers = /* @__PURE__ */ new Map();
|
|
48362
|
-
/**
|
|
48001
|
+
/**
|
|
48002
|
+
* WISP 401 § Presence and status: `active` at a page's word, `idle` 10 minutes after the last one (or at a page's).
|
|
48003
|
+
* `null`: none again, as before the first word (a headless daemon whose `daemonPresence` was turned off).
|
|
48004
|
+
*/
|
|
48363
48005
|
setPresence({ presence }) {
|
|
48006
|
+
if (presence === null) {
|
|
48007
|
+
clearTimeout(this.idleTimer);
|
|
48008
|
+
if (this.ownPresence === void 0) return;
|
|
48009
|
+
this.ownPresence = void 0;
|
|
48010
|
+
this.sayStatus();
|
|
48011
|
+
return;
|
|
48012
|
+
}
|
|
48364
48013
|
if (presence !== "active" && presence !== "idle") return;
|
|
48365
48014
|
clearTimeout(this.idleTimer);
|
|
48366
48015
|
if (presence === "active") this.idleTimer = setTimeout(() => this.setPresence({ presence: "idle" }), STATUS_IDLE_AFTER_MS);
|
|
@@ -48656,7 +48305,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
48656
48305
|
/** A request of ours closes for good (its wallet was removed): never sent again, taken back from the contact's storage too. */
|
|
48657
48306
|
async closeRequest(paymentId, reason) {
|
|
48658
48307
|
const request = this.desk.payment(paymentId);
|
|
48659
|
-
if (!request || !await this.desk.close(paymentId, reason
|
|
48308
|
+
if (!request || !await this.desk.close(paymentId, reason)) return;
|
|
48660
48309
|
const message = await this.paymentMessage(request.linkId, paymentId);
|
|
48661
48310
|
if (message) await this.hold.forget(request.linkId, message.id).catch(() => {});
|
|
48662
48311
|
}
|
|
@@ -49544,6 +49193,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
49544
49193
|
await db.putSettings(this.settings);
|
|
49545
49194
|
this.sayStatus();
|
|
49546
49195
|
}
|
|
49196
|
+
if (settings.daemonPresence !== void 0) {
|
|
49197
|
+
if (settings.daemonPresence !== true) delete this.settings.daemonPresence;
|
|
49198
|
+
await db.putSettings(this.settings);
|
|
49199
|
+
}
|
|
49547
49200
|
for (const key of ["autoDownloads", "serveFiles"]) {
|
|
49548
49201
|
if (settings[key] === void 0) continue;
|
|
49549
49202
|
if (settings[key] !== false) delete this.settings[key];
|
|
@@ -50550,7 +50203,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50550
50203
|
try {
|
|
50551
50204
|
const target = parseLocalTarget(service.target);
|
|
50552
50205
|
this.requestCounts.set(id, (this.requestCounts.get(id) ?? 0) + 1);
|
|
50553
|
-
this.
|
|
50206
|
+
this.requestCountsTimer ??= setTimeout(() => {
|
|
50207
|
+
this.requestCountsTimer = void 0;
|
|
50208
|
+
this.emitState();
|
|
50209
|
+
}, REQUEST_COUNTS_MS);
|
|
50554
50210
|
return {
|
|
50555
50211
|
id,
|
|
50556
50212
|
target
|
|
@@ -50734,7 +50390,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50734
50390
|
largeFilesSupport: !entry,
|
|
50735
50391
|
binaryFilesSupport: !entry,
|
|
50736
50392
|
params: stored,
|
|
50737
|
-
rtcAvailable:
|
|
50393
|
+
rtcAvailable: this.contactRtc() && !this.edgeRtcOff.has(linkId) && !this.groupNativeChoice(stored),
|
|
50738
50394
|
resume: !entry && stored.edgeLive ? resumeOn : void 0,
|
|
50739
50395
|
native: {
|
|
50740
50396
|
peerDescriptors: stored.peerDescriptors,
|
|
@@ -50759,14 +50415,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50759
50415
|
},
|
|
50760
50416
|
transport: live.carried ?? this.groupTransport,
|
|
50761
50417
|
nick: !entry && this.quietEdge(stored) ? void 0 : this.sharedNick,
|
|
50762
|
-
pollIntervals: entry
|
|
50418
|
+
pollIntervals: entry ? this.pollIntervals : this.groups.isCommunityGroup(group) ? communityEdgeIntervals(this.pollIntervals, () => this.groupEdges(group).size) : meshEdgeIntervals(this.pollIntervals, () => this.groups.meshSize(group)),
|
|
50763
50419
|
madeAt: stored.createdAt,
|
|
50764
50420
|
autoConnect: true,
|
|
50765
50421
|
...entry ? {
|
|
50766
50422
|
oneShot: true,
|
|
50767
50423
|
firstPublish: stored.groupEntry === "host" ? "after-first-poll" : "at-start"
|
|
50768
50424
|
} : {},
|
|
50769
|
-
createPeerConnection: () =>
|
|
50425
|
+
createPeerConnection: () => this.contactPeerConnection(),
|
|
50770
50426
|
localFetch: this.localFetch,
|
|
50771
50427
|
getServices: () => [{
|
|
50772
50428
|
id: "chat",
|
|
@@ -50902,7 +50558,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
50902
50558
|
*/
|
|
50903
50559
|
keepsGroupNative(stored) {
|
|
50904
50560
|
if (this.options.webrtcGroupLinks) return false;
|
|
50905
|
-
return
|
|
50561
|
+
return !this.contactRtc() || this.edgeRtcOff.has(stored.id) || !!stored.peerTransports && !stored.peerTransports.includes("webrtc/1") || this.groupNativeChoice(stored) !== void 0;
|
|
50906
50562
|
}
|
|
50907
50563
|
/** What this device chose for the group of an edge (`setGroupTransport`); undefined on Automatic, and for an entry session. */
|
|
50908
50564
|
groupChoice(stored) {
|
|
@@ -51022,9 +50678,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51022
50678
|
}
|
|
51023
50679
|
/**
|
|
51024
50680
|
* Starts a chat this run left unstarted (`NodeOptions.deferChats`): the one a one-shot names, once the command has
|
|
51025
|
-
* found it.
|
|
50681
|
+
* found it. Its history is read first (`restoreDeferred`), offline too: the command reads what it knows. Any other
|
|
50682
|
+
* chat, or one already started, is left as it is.
|
|
51026
50683
|
*/
|
|
51027
|
-
startDeferredChat(linkId) {
|
|
50684
|
+
async startDeferredChat(linkId) {
|
|
50685
|
+
if (!this.deferredChats.has(linkId)) return;
|
|
50686
|
+
await this.restoreDeferred(linkId);
|
|
51028
50687
|
if (!this.deferredChats.delete(linkId)) return;
|
|
51029
50688
|
if (this.networkOn && !this.shuttingDown) this.startLink(linkId);
|
|
51030
50689
|
}
|
|
@@ -51054,7 +50713,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51054
50713
|
usdtPaymentsSupport: true,
|
|
51055
50714
|
barkPaymentsSupport: true,
|
|
51056
50715
|
params: stored,
|
|
51057
|
-
rtcAvailable:
|
|
50716
|
+
rtcAvailable: this.contactRtc(),
|
|
51058
50717
|
callsSupport: this.options.callsSupport ?? typeof RTCPeerConnection !== "undefined",
|
|
51059
50718
|
callsMissing: this.options.callsUnavailable,
|
|
51060
50719
|
largeFilesSupport: true,
|
|
@@ -51161,7 +50820,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51161
50820
|
pollIntervals: this.pollIntervals,
|
|
51162
50821
|
...this.options.watchPeerIdleMs ? { watchPeerIdleMs: this.options.watchPeerIdleMs } : {},
|
|
51163
50822
|
autoConnect: true,
|
|
51164
|
-
createPeerConnection: () => this.chatPeer(
|
|
50823
|
+
createPeerConnection: () => this.chatPeer(this.contactPeerConnection()),
|
|
51165
50824
|
localFetch: this.localFetch,
|
|
51166
50825
|
getServices: () => stored.profile ? [{
|
|
51167
50826
|
id: "chat",
|
|
@@ -51546,7 +51205,19 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51546
51205
|
}
|
|
51547
51206
|
/** The layer-1 transports this app can run at all: WebRTC where the page has it, then its native adapters. */
|
|
51548
51207
|
transportsHere() {
|
|
51549
|
-
return [...
|
|
51208
|
+
return [...this.contactRtc() ? ["webrtc/1"] : [], ...Object.keys(this.nativeFactories)];
|
|
51209
|
+
}
|
|
51210
|
+
/**
|
|
51211
|
+
* Whether chats and group edges run WebRTC: where the page has it, but not while Hide my IP from contacts is on where
|
|
51212
|
+
* that WebRTC does not keep to the relay (`webrtcIgnoresRelayOnly`, the CLI). Calls are refused there on their own.
|
|
51213
|
+
*/
|
|
51214
|
+
contactRtc() {
|
|
51215
|
+
return typeof RTCPeerConnection !== "undefined" && !(this.options.webrtcIgnoresRelayOnly && this.settings.relayOnly === true);
|
|
51216
|
+
}
|
|
51217
|
+
/** A chat's or group edge's WebRTC connection; none (an offer is neither made nor answered) where `contactRtc` says so. */
|
|
51218
|
+
contactPeerConnection() {
|
|
51219
|
+
if (!this.contactRtc()) throw new Error("No WebRTC for contacts here");
|
|
51220
|
+
return new RTCPeerConnection(this.contactRtcConfig());
|
|
51550
51221
|
}
|
|
51551
51222
|
/** Something the capability record carries changed here: every chat publishes its record anew if it differs. */
|
|
51552
51223
|
capsChanged(linkId) {
|
|
@@ -51593,7 +51264,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51593
51264
|
nativeFactoriesFor(relayOnly) {
|
|
51594
51265
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
51595
51266
|
return {
|
|
51596
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
51267
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-CdsLcAhY.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
51597
51268
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
51598
51269
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
51599
51270
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, {
|
|
@@ -51715,6 +51386,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51715
51386
|
for (const [linkId, live] of this.links) {
|
|
51716
51387
|
const link = live.link;
|
|
51717
51388
|
if (!link?.availableTransports.includes("hyperdht/1")) {
|
|
51389
|
+
if (live.transportErrors) delete live.transportErrors["hyperdht/1"];
|
|
51718
51390
|
if (this.hyperdhtRelay && link && this.keepsNativeEndpoints(linkId, live.stored)) this.ensureNativeEndpoints(linkId);
|
|
51719
51391
|
continue;
|
|
51720
51392
|
}
|
|
@@ -51747,7 +51419,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
51747
51419
|
*/
|
|
51748
51420
|
reachedOnlyNatively(live) {
|
|
51749
51421
|
const theirs = live.stored.capsState?.peer?.transports ?? live.stored.peerTransports;
|
|
51750
|
-
return
|
|
51422
|
+
return !this.contactRtc() || !theirs || !theirs.includes("webrtc/1") || this.directPath.blocked;
|
|
51751
51423
|
}
|
|
51752
51424
|
/**
|
|
51753
51425
|
* When a chat or a group (for one of its edges) was last in use, for handing native listeners out least recently used
|
|
@@ -52129,7 +51801,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52129
51801
|
const stored = this.links.get(id)?.stored;
|
|
52130
51802
|
return !!stored && !stored.group;
|
|
52131
51803
|
};
|
|
52132
|
-
const rtc =
|
|
51804
|
+
const rtc = this.contactRtc();
|
|
52133
51805
|
const rank = new Map(linkIds.filter(isChat).map((id) => {
|
|
52134
51806
|
const live = this.links.get(id);
|
|
52135
51807
|
const theirs = live.stored.capsState?.peer?.transports ?? live.stored.peerTransports;
|
|
@@ -52475,12 +52147,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52475
52147
|
const live = this.links.get(message.linkId);
|
|
52476
52148
|
const deletes = this.removedChats.get(message.linkId);
|
|
52477
52149
|
if (!live && deletes !== void 0) return false;
|
|
52478
|
-
const chat = message.linkId;
|
|
52479
|
-
const
|
|
52480
|
-
|
|
52481
|
-
if (
|
|
52150
|
+
const chat = message.linkId, id = message.id;
|
|
52151
|
+
const group = chat.startsWith("group:") ? chat.slice(6) : void 0;
|
|
52152
|
+
const kept = () => this.removedChats.get(chat) === deletes && !live?.stored.deletedIds?.includes(id) && !(group && this.groups.isRemoved(group, id));
|
|
52153
|
+
if (!kept()) return false;
|
|
52482
52154
|
const first = live ? this.firstContactRow(live, message) : false;
|
|
52155
|
+
const mine = live?.stored.profile && !live.stored.group && message.sender === "peer" && !message.file && message.id.startsWith("peer_") ? this.namesMine(chat, message.id.slice(5)).catch(() => false) : false;
|
|
52483
52156
|
message = await this.resolveReply(message);
|
|
52157
|
+
if (await mine) return false;
|
|
52484
52158
|
if (first && isJoinNotice(message.text) && await first) message = {
|
|
52485
52159
|
...message,
|
|
52486
52160
|
joinLine: true
|
|
@@ -52656,10 +52330,18 @@ var GhostlyNode = class GhostlyNode {
|
|
|
52656
52330
|
services: false
|
|
52657
52331
|
};
|
|
52658
52332
|
}
|
|
52659
|
-
/**
|
|
52333
|
+
/**
|
|
52334
|
+
* State changes arrive in bursts; the UI gets one snapshot per tick. `delayMs`: how long this change may wait. One
|
|
52335
|
+
* that may not wait as long as the snapshot already due (a new file behind another's progress) brings it forward.
|
|
52336
|
+
*/
|
|
52660
52337
|
emitState(delayMs = 50) {
|
|
52661
52338
|
if (this.gatedOut) return;
|
|
52662
|
-
|
|
52339
|
+
const due = Date.now() + delayMs;
|
|
52340
|
+
if (this.stateTimer) {
|
|
52341
|
+
if (due >= this.stateDue) return;
|
|
52342
|
+
clearTimeout(this.stateTimer);
|
|
52343
|
+
}
|
|
52344
|
+
this.stateDue = due;
|
|
52663
52345
|
this.stateTimer = setTimeout(() => {
|
|
52664
52346
|
this.stateTimer = null;
|
|
52665
52347
|
if (this.gatedOut) return;
|
|
@@ -52717,6 +52399,12 @@ var EngineServer = class {
|
|
|
52717
52399
|
* call (WISP 06 § States and events). A client that goes away (a tab closed mid-call) is taken out with it.
|
|
52718
52400
|
*/
|
|
52719
52401
|
onCall = /* @__PURE__ */ new Set();
|
|
52402
|
+
/**
|
|
52403
|
+
* The clients whose last presence word (`setPresence`) was `active`: the engine hears `idle` only once none is, so a
|
|
52404
|
+
* tab hidden, locked or closed does not tell the contacts the profile is idle while another tab is in use. A client
|
|
52405
|
+
* that goes away is taken out with it.
|
|
52406
|
+
*/
|
|
52407
|
+
present = /* @__PURE__ */ new Set();
|
|
52720
52408
|
/** How many history changes the engine told; per chat or group, the count at its last one (`historyMark`). */
|
|
52721
52409
|
changes = 0;
|
|
52722
52410
|
changedAt = /* @__PURE__ */ new Map();
|
|
@@ -52849,6 +52537,7 @@ var EngineServer = class {
|
|
|
52849
52537
|
this.node.appsCloseAll();
|
|
52850
52538
|
}
|
|
52851
52539
|
if (this.onCall.delete(client)) this.node.setCallOn({ on: this.onCall.size > 0 });
|
|
52540
|
+
if (this.present.delete(client) && this.present.size === 0) this.node.setPresence({ presence: "idle" });
|
|
52852
52541
|
}
|
|
52853
52542
|
async handle(client, request) {
|
|
52854
52543
|
if (request?.kind !== "request") return;
|
|
@@ -52863,12 +52552,20 @@ var EngineServer = class {
|
|
|
52863
52552
|
else this.onCall.delete(client);
|
|
52864
52553
|
params = { on: this.onCall.size > 0 };
|
|
52865
52554
|
}
|
|
52555
|
+
let tell = true;
|
|
52556
|
+
if (request.method === "setPresence") {
|
|
52557
|
+
if (request.params?.presence === "active") this.present.add(client);
|
|
52558
|
+
else {
|
|
52559
|
+
this.present.delete(client);
|
|
52560
|
+
tell = this.present.size === 0;
|
|
52561
|
+
}
|
|
52562
|
+
}
|
|
52866
52563
|
try {
|
|
52867
52564
|
await (readsGroupHistory(request) ? Promise.race([this.ready, this.node.groupsRead]) : this.ready);
|
|
52868
52565
|
const method = this.node[request.method];
|
|
52869
52566
|
if (typeof method !== "function") throw new Error(`Unknown method: ${request.method}`);
|
|
52870
52567
|
if (this.node.limited && !LIMITED_MODE_METHODS.has(String(request.method))) throw new Error(LIMITED_MODE_ERROR);
|
|
52871
|
-
response.result = await method.call(this.node, params);
|
|
52568
|
+
if (tell) response.result = await method.call(this.node, params);
|
|
52872
52569
|
} catch (error) {
|
|
52873
52570
|
response.error = errorLine(error);
|
|
52874
52571
|
}
|
|
@@ -53018,4 +52715,4 @@ function signalKind(signal) {
|
|
|
53018
52715
|
//#endregion
|
|
53019
52716
|
export { EngineServer };
|
|
53020
52717
|
|
|
53021
|
-
//# sourceMappingURL=server-
|
|
52718
|
+
//# sourceMappingURL=server-Q3VcNqGt.js.map
|