@ghostlytools/cli 1.7.4 → 1.8.1
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 +16 -10
- package/SKILL.md +1 -1
- package/dist/assets/{api-D3i2hwy0.js → api-BpQC8dAw.js} +121 -40
- package/dist/assets/api-BpQC8dAw.js.map +1 -0
- package/dist/assets/{api-Chhvpwok.js → api-CttDF-S5.js} +2 -2
- package/dist/assets/{apiKit-BtsHrnoo.js → apiKit-CSMeHKgo.js} +17 -5
- package/dist/assets/{apiKit-BtsHrnoo.js.map → apiKit-CSMeHKgo.js.map} +1 -1
- package/dist/assets/{apps-BHl97rHs.js → apps-DqTyZ40T.js} +8 -7
- package/dist/assets/apps-DqTyZ40T.js.map +1 -0
- package/dist/assets/{apps-BFJTqvAt.js → apps-DzFMdVt6.js} +1 -1
- package/dist/assets/{arkade-BFE8KkEE.js → arkade-Cu3TbPxC.js} +2 -2
- package/dist/assets/{arkade-BFE8KkEE.js.map → arkade-Cu3TbPxC.js.map} +1 -1
- package/dist/assets/{backup-Bbsr6nDi.js → backup-CLZOORFC.js} +1 -1
- package/dist/assets/{backup-CxACdtQX.js → backup-CyTZhu28.js} +6 -6
- package/dist/assets/{backup-CxACdtQX.js.map → backup-CyTZhu28.js.map} +1 -1
- package/dist/assets/{buttons-CieBtXEO.js → buttons-Bd9fR31r.js} +177 -23
- package/dist/assets/buttons-Bd9fR31r.js.map +1 -0
- package/dist/assets/buttons-c4CJnL6i.js +2 -0
- package/dist/assets/{daemonProof-QmtwDj-N.js → daemonProof-DtrL5lE5.js} +2 -2
- package/dist/assets/{daemonProof-QmtwDj-N.js.map → daemonProof-DtrL5lE5.js.map} +1 -1
- package/dist/assets/{envelope-DYiGwzq_.js → envelope-CGfUsR1m.js} +2 -2
- package/dist/assets/{envelope-DYiGwzq_.js.map → envelope-CGfUsR1m.js.map} +1 -1
- package/dist/assets/{errors-QUGP-jIF.js → errors-R4S2SAEM.js} +7 -2
- package/dist/assets/errors-R4S2SAEM.js.map +1 -0
- package/dist/assets/fixedHosts-BiukTsd9.js +24 -0
- package/dist/assets/fixedHosts-BiukTsd9.js.map +1 -0
- package/dist/assets/{ghostly_iroh_web-CO0onry8.js → ghostly_iroh_web-BzAXJUYH.js} +10 -10
- package/dist/assets/{ghostly_iroh_web-CO0onry8.js.map → ghostly_iroh_web-BzAXJUYH.js.map} +1 -1
- package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
- package/dist/assets/{groupFiles-CBJIEvCE.js → groupFiles-CeF9nPv9.js} +759 -29
- package/dist/assets/groupFiles-CeF9nPv9.js.map +1 -0
- package/dist/assets/{host-Va-r_KJz.js → host-CKAehWP6.js} +65 -29
- package/dist/assets/host-CKAehWP6.js.map +1 -0
- package/dist/assets/hyperdhtRelay-1wzya_0L.js +25 -0
- package/dist/assets/hyperdhtRelay-1wzya_0L.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-B2uK9tJv.js → hyperdhtRelay-B8Pdykhg.js} +15 -3
- package/dist/assets/hyperdhtRelay-B8Pdykhg.js.map +1 -0
- package/dist/assets/{irohWeb-DxeEgQ-W.js → irohWeb-D6tAPHZa.js} +11 -7
- package/dist/assets/{irohWeb-DxeEgQ-W.js.map → irohWeb-D6tAPHZa.js.map} +1 -1
- package/dist/assets/{main-BX4oPWCJ.js → main-BDY-pfpz.js} +121 -37
- package/dist/assets/main-BDY-pfpz.js.map +1 -0
- package/dist/assets/{mainline-IfWQOB-J.js → mainline-3ueXpFQL.js} +2 -2
- package/dist/assets/{mainline-IfWQOB-J.js.map → mainline-3ueXpFQL.js.map} +1 -1
- package/dist/assets/mints-BaOmx517.js +2 -0
- package/dist/assets/{mints-BrlY773j.js → mints-j5XAOk4f.js} +15 -3
- package/dist/assets/mints-j5XAOk4f.js.map +1 -0
- package/dist/assets/{networkReason-N2vAaoth.js → networkReason-DhJYOomu.js} +2 -2
- package/dist/assets/{networkReason-N2vAaoth.js.map → networkReason-DhJYOomu.js.map} +1 -1
- package/dist/assets/{nwc-CzyCtNK2.js → nwc-B1Quqda-.js} +3 -3
- package/dist/assets/{nwc-CzyCtNK2.js.map → nwc-B1Quqda-.js.map} +1 -1
- package/dist/assets/{nwcProvider-DjWmEn3j.js → nwcProvider-DUB6xO-b.js} +2 -2
- package/dist/assets/{nwcProvider-DjWmEn3j.js.map → nwcProvider-DUB6xO-b.js.map} +1 -1
- package/dist/assets/ownDid-BfqHJdA6.js +281 -0
- package/dist/assets/ownDid-BfqHJdA6.js.map +1 -0
- package/dist/assets/{profiles-DcCeOi7J.js → profiles-MFtCmJwK.js} +3 -3
- package/dist/assets/{profiles-DcCeOi7J.js.map → profiles-MFtCmJwK.js.map} +1 -1
- package/dist/assets/{registry-BmS02J5h.js → registry-CZTmtSws.js} +1 -1
- package/dist/assets/{registry-CeW8XEQc.js → registry-DwlTNQjr.js} +5 -246
- package/dist/assets/registry-DwlTNQjr.js.map +1 -0
- package/dist/assets/{resolve-BvHkAhDH.js → resolve-BVwhiYjj.js} +3 -268
- package/dist/assets/resolve-BVwhiYjj.js.map +1 -0
- package/dist/assets/{restoredRows-mTTp3XNs.js → restoredRows-BCRCjhdF.js} +26 -2
- package/dist/assets/{restoredRows-mTTp3XNs.js.map → restoredRows-BCRCjhdF.js.map} +1 -1
- package/dist/assets/{server-BUcJo4vz.js → server-Br3XPwFG.js} +1001 -243
- package/dist/assets/server-Br3XPwFG.js.map +1 -0
- package/dist/assets/{src-BB5-5P3s.js → src-C4sOH4zH.js} +1109 -181
- package/dist/assets/src-C4sOH4zH.js.map +1 -0
- package/dist/assets/sshForges-CQQomStK.js +253 -0
- package/dist/assets/sshForges-CQQomStK.js.map +1 -0
- package/dist/assets/{translate-2WyaRVCr.js → translate-C2aNyUkR.js} +20 -10
- package/dist/assets/translate-C2aNyUkR.js.map +1 -0
- package/dist/assets/{usdt-BLazHiaP.js → usdt-CMwatDnQ.js} +3 -3
- package/dist/assets/{usdt-BLazHiaP.js.map → usdt-CMwatDnQ.js.map} +1 -1
- package/dist/assets/waitNotice-Ck3el3_Z.js +45 -0
- package/dist/assets/waitNotice-Ck3el3_Z.js.map +1 -0
- package/dist/assets/{words-BaumxjXe.js → words-CqN2KG1r.js} +6 -3
- package/dist/assets/words-CqN2KG1r.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/examples/claude-code-agent.sh +1 -1
- package/package.json +1 -1
- package/dist/assets/api-D3i2hwy0.js.map +0 -1
- package/dist/assets/apps-BHl97rHs.js.map +0 -1
- package/dist/assets/buttons-CieBtXEO.js.map +0 -1
- package/dist/assets/buttons-YtAj3R_E.js +0 -2
- package/dist/assets/errors-QUGP-jIF.js.map +0 -1
- package/dist/assets/groupFiles-CBJIEvCE.js.map +0 -1
- package/dist/assets/host-Va-r_KJz.js.map +0 -1
- package/dist/assets/hyperdhtRelay-B2uK9tJv.js.map +0 -1
- package/dist/assets/hyperdhtRelay-BT_wRxab.js +0 -21
- package/dist/assets/hyperdhtRelay-BT_wRxab.js.map +0 -1
- package/dist/assets/main-BX4oPWCJ.js.map +0 -1
- package/dist/assets/mints-BrlY773j.js.map +0 -1
- package/dist/assets/mints-CqTdA4Gk.js +0 -2
- package/dist/assets/registry-CeW8XEQc.js.map +0 -1
- package/dist/assets/resolve-BvHkAhDH.js.map +0 -1
- package/dist/assets/server-BUcJo4vz.js.map +0 -1
- package/dist/assets/src-BB5-5P3s.js.map +0 -1
- package/dist/assets/translate-2WyaRVCr.js.map +0 -1
- package/dist/assets/words-BaumxjXe.js.map +0 -1
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $i as
|
|
2
|
+
import { $i as validExternalKey, $l as turnStatedVerifier, $r as wakeRequest, $s as verifySetUpdate, $t as SEPOLIA_TEST_USDT, A as knockIdentity, Aa as parseLinkPreview, Ac as mergeContactKnocks, Al as deviceEchoFrame, An as fedimintRequestPayload, Ao as ratchetSessionOf, Ar as FILE_LIMITS, As as handoffManifestFrames, Ba as reactionIsNewer, Bc as appDigest, Bl as TURN_SETTLE_MS, Bn as pairedMessageFrame, Bo as formatLocalTarget, Bs as readHandoffDone, C as communityHasFrame, Ca as EDIT_RATE_WINDOW_MS, Cc as REQUEST_LIFETIME_MS, Cl as encodeInviteCode, Co as rosterAdmin, Cr as pickHubs, Cs as handoffCancelFrame, Cu as publicKeyFromZ32, D as decodeGroupEntryLink, Da as dhtEditId, Dc as knockSlotRecords, Dl as DEVICES_CAPABILITY, Dn as decodeBolt11, Do as RATCHET_CAPABILITY, Dr as readLobby, Ds as handoffDigest, Du as sanitizeDisplayText, Ea as RateWindow, Ec as knockSlotOf, Eo as edgeParams, Er as readBeaconHead, Es as handoffDataFrame, Eu as sanitizeAvatar, F as GroupWakeLimiter, Fa as REACTION_LIMITS, Fc as seenEntry, Fi as DHT_TEXT_CAPABILITY, Fl as newDeviceSetSecret, Fn as GhostLink, Fo as PRESENCE_WINDOW, Fs as handoffStreamKey, Fu as utf8Encode, Ga as readReply, Gc as pacer, Gl as firstDeviceSetSecret, Gn as GROUP_FILE_LIMITS, Go as encodeControl, Gr as pinNumberHolds, Gs as readHandoffVerified, Gt as encodeDidDhtDeactivated, H as GroupSession, Ha as validReactionNumber, Hl as turnPutSummary, Hn as engineError, Ho as webLocalFetch, Hr as mayPin, Hs as readHandoffHello, I as groupWakeFrame, Ia as ReactionWindow, Ic as APP_BUNDLE_LIMITS, Ii as capsDescriptors, Il as seedSigner, In as INVITE_TAKEN, Io as RELAY_POLL_INTERVALS, Is as handoffVersions, J as parseCommunityEdit, Jc as sha256Paced, Ji as receivedIdentityStatus, Jl as signTurnPacket, Jr as WakeLimiter, Jt as signDidDhtPacket, K as GROUP_EDIT_TEXT_BYTES, Ka as replySnippet, Kl as nextTurnPosition, Kr as readPin, Ks as sealHandoffPiece, Kt as encodeDidDhtPacket, L as groupWakes, La as nextReactionNumber, Lc as APP_BUNDLE_MAGIC, Li as dialDescriptors, Ll as webCryptoSigner, Ln as LIVENESS_PING_MS, Lo as WATCH_PEER_MS, Lr as TypingSender, Ls as newHandoffId, M as mergeKnocks, Ma as readForwarded, Mc as readKnockSlot, Ml as deviceKeyZ32, Mn as isFederationId, Mr as sentWhole, Ms as handoffPakeFrame, Mu as toBase64Url, N as readKnocks, Na as COMMUNITY_REACTION_FRAME, Nc as readLinkRecord, Nl as deviceLinkPairing, Nn as parseCashuRequestPayload, No as DHT_POLL_INTERVALS, Nr as transferEnded, Ns as handoffReleaseFrame, Nu as toZ32, O as encodeGroupEntryLink, Oc as linkRecords, Ol as ENROLL_CAPABILITY, On as ENDPOINT, Oo as RatchetBox, Or as shouldBeHub, Os as handoffEphemeral, Ou as bytesEqual, Pa as GROUP_REACTION_FRAME, Pc as requestRecords, Pi as CapsExchange, Pl as devicePingFrame, Pn as parseFedimintRequestPayload, Pr as transferStalled, Ps as handoffRetryAfter, Pu as utf8Decode, Qc as appRef, Qi as emptyProofLedger, Ql as turnName, Qn as readGroupFileMeta, Qo as contactRtcConfig, Qr as relayRequest, Qs as signTombstone, Qt as PaymentPreflightError, R as parseGroupWakeFrame, Ra as queueReaction, Rc as APP_ICON_PATH, Rn as PAIRED_FRAME_TOO_LARGE, Ro as presenceSeenAt, Rs as readHandoffAck, S as GROUP_READ_NOTE_COMMUNITY, Sa as EDIT_BUFFER_MS, Sc as ContactRequestError, Sl as decodeInviteCode, So as parseGroupCommit, Sr as newerHead, Ss as handoffBusyFrame, Su as identityFromSeedB64, T as encodeCommunityLink, Ta as REMOVED_TEXT, Tc as knockSlotIdentity, Tl as inviteOwnership, To as verifyCommitSignature, Tr as readBeacon, Ts as handoffContextProof, U as frameBytes, Ua as wireReaction, Ul as TURN_LAST_SEQUENCE, Un as engineText, Uo as LIMITS, Ur as nextPinNumber, Us as readHandoffPake, Ut as didDhtDocument, V as GROUP_READ_NOTE, Va as readReaction, Vc as appViewOf, Vl as classifyTurnRead, Vn as EngineError, Vo as parseLocalTarget, Vr as PIN_LIMITS, Vs as readHandoffHave, Wa as pairedReplyAuthor, Wc as isAppUrl, Wi as emptyIdentityLedger, Wl as TURN_MAX, Wn as parseEngineError, Wo as decodeControl, Wr as pinIsNewer, Ws as readHandoffTurnFrame, Wt as didDhtFromPublicKey, X as groupName, Xc as APP_STATEMENT_LIMITS, Xi as lastSharedWithMe, Xl as turnInstance, Xn as groupFileFallback, Xr as newWakeToken, Xs as setAckFrame, Xt as EVM_TEST_CHAINS, Y as mentionsMember, Yl as signTurnRelease, Yr as deviceWakeRequest, Ys as readSetUpdate, Yt as ETHEREUM_USDT, Zc as appFingerprint, Zi as PeerProofs, Zl as turnKeys, Zr as parseWakeFrame, Zs as setUpdateFrame, Zt as ONCHAIN_PROVIDER, _ as groupTypingEpoch, _a as fileMessageText, _c as newInbox, _i as isHoldUrl, _l as createDeviceInvite, _o as GROUP_ADMIN_OFF_ERROR, _r as freshHubs, _s as NO_ATTEMPTS, _t as normalizeAtprotoHandle, a as appRevocationFor, aa as DHT_MESSAGE_TTL, ac as enrollCancelReason, ai as chatAppId, an as assertTokenUnits, as as serviceIdFromName, b as COMMUNITY_LIMITS, bc as takeRequest, bl as OwnInviteError, bo as MEMBER_KEY, br as mergeBeacon, bs as handoffAttemptFailed, bu as createIdentity, c as checkAppBeforeRun, ca as dhtFileId, cc as enrollGrantFrame, ci as BUTTONS_CAPABILITY, cn as validatePaymentTarget, co as checkStatusCard, cr as readGroupSignal, cs as HANDOFF_DONE, cu as normalizeRelayUrl, da as sanitizeMime, dc as readEnrollGrant, di as UPGRADE_CAPABILITY, dl as canonicalJson, dn as SPARK_PROVIDER, do as statusCardText, dr as meshHubs, ds as HANDOFF_OFFER, du as budgetRetryMs, ea as TRANSPORTS, ei as checkPushEndpoint, el as isAppHash, es as parseCallSignal, eu as turnVerifierMark, fc as readEnrollHello, fi as HOLD_CAPABILITY, fn as sparkAddressKind, fo as arrivalKey, fr as pickMeshHubs, fs as HANDOFF_PAKE, fu as isDiscoveryBudgetError, g as GroupTypingBoard, gc as inboxRecord, gi as HoldRefusedError, gl as readContactLink, gn as isPubkyKey, go as shownTime, gr as doorHubs, gs as HANDOFF_VERIFIED, gt as isAtprotoDid, gu as createRelayPayload, hc as endedRequests, hi as HoldKeys, hl as encodeContactLink, ho as receivedTimestamp, hr as beaconRecords, hs as HANDOFF_TIMINGS, i as addedAppPermissions, ic as enrollCancelFrame, in as arkAddressPrefix, is as LEGACY_SERVICES, iu as RelayTransport, j as knockRecords, ja as forwardedAgain, jc as openRequest, jl as deviceEchoNonce, jn as findEndpoint, jo as DirectPathWatch, js as handoffOfferFrame, ju as randomBytes, k as entryParams, kc as makeStampPaced, kl as HANDOFF_CAPABILITY, kn as cashuRequestPayload, ko as emptyRatchetState, kr as ChatFiles, ks as handoffHelloFrame, ku as fromBase64Url, l as planAppUpdate, la as formatFileSize, lc as enrollHelloFrame, li as EDIT_CAPABILITY, ll as parseImageMeta, ln as walletNetworkOf, lo as sameButtonText, lr as MESH_HUBS, ls as HANDOFF_HAVE, mc as clearMissed, mi as HOLD_LIMITS, ml as createContactLink, mn as isBitcoinAddress, mo as heardTime, mr as beaconKeys, ms as HANDOFF_REQUEST, mu as PacketTooLargeError, n as readX401SdJwtVc, ni as APP_RANGE_LIMITS, nl as isAppRef, nn as USDT_PUBLIC_RPC, nr as CarriedTransport, ns as emptyLinkRecords, o as appStoreDecision, oa as peekDhtMailbox, oc as enrollDigits, oi as isAppVersion, on as assertWholeSats, os as HANDOFF_ACK, p as readAppStoreSteps, pc as verifyEnrollProof, pi as HOLD_DATED_BACK_MS, pl as readCanonicalJson, pn as sparkInvoiceDetails, po as claimedTime, pr as COMMUNITY_TOPOLOGY, ps as HANDOFF_PIECE_BYTES, pu as withRequestOptions, q as carryMentions, qa as BUTTON_ID, qc as readAppBundleAsync, ql as readTurnPacket, qo as RTC_CONFIG, qr as WAKE_CALL_INTERVAL_MS, r as sameX401HolderJwk, ri as isServeId, rl as readAppRevocation, rn as WALLET_NETWORKS, rs as HTTP_SERVICE_PROTO, s as appUpdateDecision, sa as DHT_FILE_CAPABILITY, sc as enrollDoneFrame, si as APPS_CAPABILITY, sn as formatPaymentAmount, sr as groupSignalFrame, ss as HANDOFF_CANCEL, su as currentRelays, t as newX401HolderKey, ta as automaticTransport, ti as vapidKeysMatch, tl as isAppKey, tn as TEST_USDT_FAUCET_AMOUNT, to as STATUS_CARD_LIMITS, tu as DEFAULT_RELAYS, u as APP_STORE_LIMITS, ua as sanitizeFileName, uc as enrollProofFrame, ui as STATUS_CARD_CAPABILITY, un as SPARK_NETWORKS, ur as mayBeHub, us as HANDOFF_HELLO, uu as traceLink, v as openGroupTyping, va as parseVoiceMeta, vc as planKnocks, vi as newMailbox, vl as deviceInviteJoinerParams, vo as GROUP_MEMBER_CAP, vr as lobbyKeys, vs as filePartName, w as decodeCommunityLink, wa as MAX_REMOVAL_NUMBER, wc as contactDay, wl as inviteLink, wo as rosterHas, wr as rankHubs, ws as handoffContext, wu as verify, x as CommunitySession, xa as parseVideoMeta, xc as turnOff, xl as createChatInvite, xo as commitHash, xr as mergeLobby, xs as handoffAttemptSucceeded, xu as identityFromSeed, y as sealGroupTyping, yc as settleRequest, yi as readManifest, yl as readDeviceInvite, yr as lobbyRecords, ys as handoffAttemptAllowed, z as GROUP_LIMITS, za as reactionEmoji, zl as TURN_RAISE_READ_TIMEOUT_MS, zn as pairedMessageFits, zo as GhostlyHttpError, zr as typingActivity, zs as readHandoffCancel } from "./src-C4sOH4zH.js";
|
|
3
|
+
import { $ as ModeChanged, A as IdentityProofs, B as INVOICE_PACE, C as FileAppender, D as streamStored, E as storedSize, F as LightningCards, G as cashuMint, H as ProviderSources, I as cardsKey, J as breezDatabasesFor, K as breezDatabase, L as isRecoveryPhrase, M as sealSecret, N as whenDataKeyDropped, P as CASHU_CARD, Q as relayOnlyProblem, R as normalizePhrase, S as WALLET_TYPES, T as removeStored, U as sourceKey, V as nextInvoiceAsk, W as CASHU_MINT_SOURCE, X as iceServerProblem, Y as dropBreezDatabase, Z as iceServerSetting, _ as crossNetwork, a as storedGroupFiles, at as requireTurn, b as walletInstances, c as receivedPairedReply, ct as NO_PICTURE_METADATA, d as paymentAlias, dt as stripPictureMetadata, et as ModeGate, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, it as refuseAway, j as openSecret, l as replyRef, lt as PICTURE_METADATA_LIMITS, m as assertConfirmedReal, n as groupFileId, nt as networkLabel, o as groupReply, ot as setAwayWallets, p as WALLET_NAMES, q as breezDatabaseInUse, r as groupFileText, rt as awayFrom, s as pairedWireReply, st as setSingleWriterGate, t as GroupFileDesk, tt as WrongNetworkError, u as replyTo, ut as isStrippedPicture, v as paymentNetwork, w as readStored$1, y as paymentNetworksOf, z as lightningPaying } from "./groupFiles-CeF9nPv9.js";
|
|
3
4
|
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
|
|
4
5
|
import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
6
|
+
import { t as nwc } from "./nwcProvider-DUB6xO-b.js";
|
|
6
7
|
import { a as clearProfileStores, c as deleteDatabase, d as newestWalletTx, f as openDb, g as wrap, h as transact, i as STORES$1, l as errorLine, m as store, n as APP_STORAGE_SCOPE_INDEX, o as committed, p as profileOpenFailure, r as CARD_INDEX, s as databaseName, t as APP_STORAGE_CHAT_INDEX, u as fileStore } from "./idb-BkOJES5_.js";
|
|
7
|
-
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-DhJYOomu.js";
|
|
9
|
+
import { i as fedimintDatabase, n as createIrohWebEndpoint, o as loadFedimintSdk, r as irohRelayProblem, t as DEFAULT_IROH_RELAYS } from "./irohWeb-D6tAPHZa.js";
|
|
10
|
+
import { c as isTestMint, d as mintUrlSpelling, f as paysItsOwnInvoices, l as isWorthlessMint, n as DEFAULT_MINTS, o as fakesLightning, r as TEST_MINT, t as BITCOIN_INVOICE_ON_TESTNET, u as mintNetwork } from "./mints-j5XAOk4f.js";
|
|
11
|
+
import { a as registeredLightningProviders, c as boundedIdentityFetch, d as testSwitch, n as setOwnDidSource, o as registeredOnchainProviders, r as onAdaptersChanged, s as reserveAdapterIds, u as testBuild } from "./ownDid-BfqHJdA6.js";
|
|
12
|
+
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-CGfUsR1m.js";
|
|
13
|
+
import { d as chosenResolver, r as resolveAtprotoDid, t as assertPublicServer } from "./resolve-BVwhiYjj.js";
|
|
13
14
|
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-DNgrRL0R.js";
|
|
14
|
-
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-
|
|
15
|
+
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-1wzya_0L.js";
|
|
15
16
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
16
17
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
17
18
|
import { base64, base64url, base64urlnopad, bech32, hex } from "@scure/base";
|
|
@@ -198,7 +199,7 @@ function viewNews(before, after) {
|
|
|
198
199
|
//#endregion
|
|
199
200
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
200
201
|
/** The Ethereum libraries, a large part of the app: loaded once a USDT wallet is made, opened or restored, not with the engine. */
|
|
201
|
-
var loadUsdt = () => import("./usdt-
|
|
202
|
+
var loadUsdt = () => import("./usdt-CMwatDnQ.js");
|
|
202
203
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
203
204
|
var DEFAULT_USDT = {
|
|
204
205
|
network: "ethereum",
|
|
@@ -647,7 +648,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
647
648
|
//#endregion
|
|
648
649
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
649
650
|
/** The Ark SDK, a large part of the app: loaded once an Ark wallet is made, opened or restored, not with the engine. */
|
|
650
|
-
var loadArkade = () => import("./arkade-
|
|
651
|
+
var loadArkade = () => import("./arkade-Cu3TbPxC.js");
|
|
651
652
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
652
653
|
var RETIRE_READ_MS = 1e4;
|
|
653
654
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -8602,7 +8603,7 @@ var NostrSocial = class {
|
|
|
8602
8603
|
fetchedAt: c.follows.fetchedAt,
|
|
8603
8604
|
relays: c.follows.relays,
|
|
8604
8605
|
stale: this.stale(c.follows.fetchedAt),
|
|
8605
|
-
|
|
8606
|
+
count: c.follows.follows.length,
|
|
8606
8607
|
eventAt: c.follows.event?.created_at ?? 0
|
|
8607
8608
|
};
|
|
8608
8609
|
if (c?.mute) view.mute = {
|
|
@@ -8629,6 +8630,11 @@ var NostrSocial = class {
|
|
|
8629
8630
|
ownFollows() {
|
|
8630
8631
|
return [...new Set(this.host.ownSubjects().flatMap((s) => this.own[s]?.follows?.follows ?? []))];
|
|
8631
8632
|
}
|
|
8633
|
+
/** The keys one of the person's own follow lists names, as last loaded (`nostrOwnFollows`); none for a key not theirs. */
|
|
8634
|
+
ownFollowList({ subject }) {
|
|
8635
|
+
if (!this.host.ownSubjects().includes(subject)) return [];
|
|
8636
|
+
return [...this.own[subject]?.follows?.follows ?? []];
|
|
8637
|
+
}
|
|
8632
8638
|
/** The person's own mute lists hide this note by `author`. */
|
|
8633
8639
|
hides(note, author) {
|
|
8634
8640
|
return this.muted({
|
|
@@ -8672,7 +8678,7 @@ var NostrSocial = class {
|
|
|
8672
8678
|
})).find((x) => x.follows);
|
|
8673
8679
|
if (mine?.follows) view.follows.hints = this.hintsOf(c.follows, mine.follows, mine.key, myKeys, subject);
|
|
8674
8680
|
}
|
|
8675
|
-
if (c?.notes) view.notes = this.notesOf(c.notes, muteLists, subject);
|
|
8681
|
+
if (c?.notes) view.notes = this.notesOf(c.notes, muteLists, subject).view;
|
|
8676
8682
|
const loading = this.loading.get(`${linkId}:${subject}`);
|
|
8677
8683
|
if (loading) view.loading = loading;
|
|
8678
8684
|
const error = this.errors.get(`${linkId}:${subject}`);
|
|
@@ -8702,31 +8708,44 @@ var NostrSocial = class {
|
|
|
8702
8708
|
});
|
|
8703
8709
|
return hints;
|
|
8704
8710
|
}
|
|
8705
|
-
/**
|
|
8711
|
+
/**
|
|
8712
|
+
* A contact's posts as shown, past the person's mute lists: the counts for every state's view, the posts for
|
|
8713
|
+
* `contactNotes`. Every state asks; a list that changes is a new object.
|
|
8714
|
+
*/
|
|
8706
8715
|
notesOf(notes, lists, subject) {
|
|
8707
8716
|
const kept = this.shownNotes.get(notes);
|
|
8708
|
-
if (kept && kept.subject === subject && kept.lists.length === lists.length && kept.lists.every((list, i) => list === lists[i])) return kept
|
|
8717
|
+
if (kept && kept.subject === subject && kept.lists.length === lists.length && kept.lists.every((list, i) => list === lists[i])) return kept;
|
|
8709
8718
|
const authorMuted = lists.some((m) => m.pubkeys.includes(subject));
|
|
8710
8719
|
const shown = authorMuted ? [] : notes.notes.filter((n) => !lists.some((m) => !!mutedBecause(n, subject, m)));
|
|
8711
|
-
const
|
|
8712
|
-
|
|
8713
|
-
|
|
8720
|
+
const entry = {
|
|
8721
|
+
lists,
|
|
8722
|
+
subject,
|
|
8723
|
+
view: {
|
|
8724
|
+
fetchedAt: notes.fetchedAt,
|
|
8725
|
+
relays: notes.relays,
|
|
8726
|
+
count: shown.length,
|
|
8727
|
+
more: !notes.exhausted,
|
|
8728
|
+
hidden: notes.notes.length - shown.length,
|
|
8729
|
+
authorMuted
|
|
8730
|
+
},
|
|
8714
8731
|
notes: shown.map((n) => ({
|
|
8715
8732
|
id: n.id,
|
|
8716
8733
|
createdAt: n.createdAt,
|
|
8717
8734
|
content: n.content,
|
|
8718
8735
|
reply: n.reply
|
|
8719
|
-
}))
|
|
8720
|
-
more: !notes.exhausted,
|
|
8721
|
-
hidden: notes.notes.length - shown.length,
|
|
8722
|
-
authorMuted
|
|
8736
|
+
}))
|
|
8723
8737
|
};
|
|
8724
|
-
this.shownNotes.set(notes,
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
|
|
8729
|
-
|
|
8738
|
+
this.shownNotes.set(notes, entry);
|
|
8739
|
+
return entry;
|
|
8740
|
+
}
|
|
8741
|
+
/**
|
|
8742
|
+
* The posts a contact's card shows (`nostrContactNotes`), newest first, past the person's mute lists: the engine
|
|
8743
|
+
* state carries only their count. None for a key this contact has not proved here, or before any were loaded.
|
|
8744
|
+
*/
|
|
8745
|
+
contactNotes({ linkId, subject }) {
|
|
8746
|
+
if (!this.host.contactSubjects(linkId).includes(subject)) return [];
|
|
8747
|
+
const notes = this.host.readContacts(linkId)?.[subject]?.notes;
|
|
8748
|
+
return notes ? [...this.notesOf(notes, this.muteLists(), subject).notes] : [];
|
|
8730
8749
|
}
|
|
8731
8750
|
requireOnline() {
|
|
8732
8751
|
if (!this.host.online()) throw new Error("Offline: turn the network on first");
|
|
@@ -9120,6 +9139,23 @@ var PUBKY_NEXUS = "https://nexus.pubky.app";
|
|
|
9120
9139
|
var BLUESKY_APPVIEW = "https://public.api.bsky.app";
|
|
9121
9140
|
/** Bluesky's avatar CDN: the AppView names avatars there. It sends no CORS header, so the picture is read from the account's own server. */
|
|
9122
9141
|
var BLUESKY_CDN_AVATAR = /^https:\/\/cdn\.bsky\.app\/img\/avatar\/plain\/(did:[a-z]+:[A-Za-z0-9._:%-]+)\/(b[a-z2-7]{20,100})(@(jpeg|png))?$/;
|
|
9142
|
+
/** A request the readers did not make: Hide my IP from contacts is on and the host is one the contact chose. */
|
|
9143
|
+
var HostNotContacted = class extends Error {};
|
|
9144
|
+
/**
|
|
9145
|
+
* `fetch`, limited to the hosts this app names (Bluesky's AppView, the Pubky index, and the identity checks' fixed
|
|
9146
|
+
* hosts): for a contact's identity while "Hide my IP from contacts" is on, so a server the contact chose (their AT
|
|
9147
|
+
* Protocol server, a did:web's web server) never sees this device's IP address. Anything else is refused unasked.
|
|
9148
|
+
*/
|
|
9149
|
+
function fixedHostsFetch(fetch) {
|
|
9150
|
+
return async (url, options) => {
|
|
9151
|
+
const { fixedIdentityHosts } = await import("./fixedHosts-BiukTsd9.js");
|
|
9152
|
+
const host = hostOf$1(url);
|
|
9153
|
+
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`);
|
|
9154
|
+
return fetch(url, options);
|
|
9155
|
+
};
|
|
9156
|
+
}
|
|
9157
|
+
/** Why a picture was not read: the refusal above says so; anything else is `fallback`. */
|
|
9158
|
+
var pictureMiss = (e, fallback) => e instanceof HostNotContacted ? e.message : fallback;
|
|
9123
9159
|
var count$1 = (value) => Number.isSafeInteger(value) && value >= 0 && value <= MAX_COUNT ? value : void 0;
|
|
9124
9160
|
var hostOf$1 = (url) => new URL(url).host;
|
|
9125
9161
|
var pictureUnreachable = (host) => ({ miss: `${host} could not be reached, or the picture is larger than ${AVATAR_MAX_BYTES / 1024 / 1024} MiB` });
|
|
@@ -9295,8 +9331,8 @@ var PUBLIC_PROFILE_READERS = {
|
|
|
9295
9331
|
});
|
|
9296
9332
|
picture = blob.status === 200 ? await decodeAvatar(blob.bytes, 160) : { miss: `${server.host} answered ${blob.status}` };
|
|
9297
9333
|
hosts.push(server.host);
|
|
9298
|
-
} catch {
|
|
9299
|
-
picture = { miss: "the account's server could not be asked for it" };
|
|
9334
|
+
} catch (e) {
|
|
9335
|
+
picture = { miss: pictureMiss(e, "the account's server could not be asked for it") };
|
|
9300
9336
|
}
|
|
9301
9337
|
else if (typeof d.avatar === "string") picture = { miss: "Bluesky named it at an address this app does not read" };
|
|
9302
9338
|
return profile({
|
|
@@ -9319,6 +9355,14 @@ var KEY = "publicProfiles";
|
|
|
9319
9355
|
var PRUNE_MS = 6e5;
|
|
9320
9356
|
var keyOf$1 = (s) => `${s.provider}\n${s.subject}`;
|
|
9321
9357
|
/**
|
|
9358
|
+
* The fetch an identity's public data is read with: a contact's, while Hide my IP from contacts is on, reaches only
|
|
9359
|
+
* hosts this app names, so a server the contact chose (their AT Protocol server) never learns this device's IP address.
|
|
9360
|
+
*/
|
|
9361
|
+
function profileFetch(host, s, fetch) {
|
|
9362
|
+
if (!host.relayOnly?.() || host.own?.().some((o) => o.provider === s.provider && o.subject === s.subject)) return fetch;
|
|
9363
|
+
return fixedHostsFetch(fetch);
|
|
9364
|
+
}
|
|
9365
|
+
/**
|
|
9322
9366
|
* The public profiles of verified identities, engine side: asked for one identity at a time, when its card is on
|
|
9323
9367
|
* screen (the UI's `loadPublicProfile`), only for an identity with a current verified proof and only with the
|
|
9324
9368
|
* setting on and the network on. Kept in IndexedDB for offline use, asked again after a day (misses after five
|
|
@@ -9424,7 +9468,7 @@ var PublicProfiles = class {
|
|
|
9424
9468
|
const checkedAt = this.now;
|
|
9425
9469
|
try {
|
|
9426
9470
|
const data = await reader.read(s.subject, {
|
|
9427
|
-
fetch: this.fetch,
|
|
9471
|
+
fetch: profileFetch(this.host, s, this.fetch),
|
|
9428
9472
|
signal: AbortSignal.timeout(2e4),
|
|
9429
9473
|
relays: this.host.nostrRelays(),
|
|
9430
9474
|
makeSocket: this.host.makeSocket,
|
|
@@ -9960,19 +10004,26 @@ async function readPostImage(source, ctx) {
|
|
|
9960
10004
|
const doc = await resolveAtprotoDid(source.did, resolve);
|
|
9961
10005
|
server = new URL(doc.pds);
|
|
9962
10006
|
await assertPublicServer(server.hostname, resolve);
|
|
9963
|
-
} catch {
|
|
10007
|
+
} catch (e) {
|
|
9964
10008
|
return {
|
|
9965
|
-
miss: "the account's server could not be asked for it",
|
|
10009
|
+
miss: pictureMiss(e, "the account's server could not be asked for it"),
|
|
9966
10010
|
hosts: []
|
|
9967
10011
|
};
|
|
9968
10012
|
}
|
|
10013
|
+
let refused;
|
|
9969
10014
|
const r = await ctx.fetch(`${server.origin}/xrpc/com.atproto.sync.getBlob?${new URLSearchParams({
|
|
9970
10015
|
did: source.did,
|
|
9971
10016
|
cid: source.cid
|
|
9972
10017
|
})}`, {
|
|
9973
10018
|
maxBytes: AVATAR_MAX_BYTES,
|
|
9974
10019
|
signal: ctx.signal
|
|
9975
|
-
}).catch(() =>
|
|
10020
|
+
}).catch((e) => {
|
|
10021
|
+
refused = e;
|
|
10022
|
+
});
|
|
10023
|
+
if (refused instanceof HostNotContacted) return {
|
|
10024
|
+
miss: refused.message,
|
|
10025
|
+
hosts: []
|
|
10026
|
+
};
|
|
9976
10027
|
if (!r) return {
|
|
9977
10028
|
miss: `${server.host} could not be reached, or the picture is larger than ${AVATAR_MAX_BYTES / 1024 / 1024} MiB`,
|
|
9978
10029
|
hosts: [server.host]
|
|
@@ -10021,9 +10072,10 @@ var PublicActivity = class {
|
|
|
10021
10072
|
allowed(s) {
|
|
10022
10073
|
return this.host.enabled() && !!this.reader(s) && this.host.eligible().some((e) => e.provider === s.provider && e.subject === s.subject);
|
|
10023
10074
|
}
|
|
10024
|
-
|
|
10075
|
+
/** A contact's identity, while Hide my IP from contacts is on, is read only from hosts this app names (`profileFetch`). */
|
|
10076
|
+
ctx(s, signal = AbortSignal.timeout(ASK_TIMEOUT_MS)) {
|
|
10025
10077
|
return {
|
|
10026
|
-
fetch: this.fetch,
|
|
10078
|
+
fetch: profileFetch(this.host, s, this.fetch),
|
|
10027
10079
|
signal,
|
|
10028
10080
|
relays: this.host.nostrRelays(),
|
|
10029
10081
|
makeSocket: this.host.makeSocket,
|
|
@@ -10104,7 +10156,7 @@ var PublicActivity = class {
|
|
|
10104
10156
|
}
|
|
10105
10157
|
const reader = this.reader(s);
|
|
10106
10158
|
await this.once(`posts\n${key}${s.more ? "\nmore" : ""}`, async () => {
|
|
10107
|
-
const page = await reader.posts(s.subject, this.ctx(), s.more ? kept?.cursor : void 0);
|
|
10159
|
+
const page = await reader.posts(s.subject, this.ctx(s), s.more ? kept?.cursor : void 0);
|
|
10108
10160
|
if (!this.allowed(s)) return;
|
|
10109
10161
|
const before = s.more ? this.posts.get(key)?.posts ?? [] : [];
|
|
10110
10162
|
const seen = new Set(before.map((p) => p.id));
|
|
@@ -10197,7 +10249,7 @@ var PublicActivity = class {
|
|
|
10197
10249
|
}
|
|
10198
10250
|
const reader = this.reader(s);
|
|
10199
10251
|
await this.once(`graph\n${key}`, async () => {
|
|
10200
|
-
const g = await reader.graph(s.subject, this.ctx());
|
|
10252
|
+
const g = await reader.graph(s.subject, this.ctx(s));
|
|
10201
10253
|
if (!this.allowed(s)) return;
|
|
10202
10254
|
this.graphs.set(key, {
|
|
10203
10255
|
...g,
|
|
@@ -10222,7 +10274,7 @@ var PublicActivity = class {
|
|
|
10222
10274
|
}
|
|
10223
10275
|
if (!this.host.online()) throw new Error("Offline: turn the network on first");
|
|
10224
10276
|
return this.once(`image\n${key}`, async () => {
|
|
10225
|
-
const r = await readPostImage(image.source, this.ctx());
|
|
10277
|
+
const r = await readPostImage(image.source, this.ctx(s));
|
|
10226
10278
|
const view = {
|
|
10227
10279
|
hosts: r.hosts,
|
|
10228
10280
|
...r.avatar ? { src: r.avatar } : {},
|
|
@@ -10314,16 +10366,43 @@ async function bytesHere(file) {
|
|
|
10314
10366
|
return await (file.bytes ? await fileBytesOf(file.bytes) : null)?.size(file.id) ?? 0;
|
|
10315
10367
|
}
|
|
10316
10368
|
/**
|
|
10369
|
+
* A received picture as it goes on: without its metadata (one from an app that sent it with them keeps where its author
|
|
10370
|
+
* took it, the device, the time), read whole; undefined for any other file, copied as it is. Refused with
|
|
10371
|
+
* `NO_PICTURE_METADATA` when its metadata cannot be removed, as a picture sent from here is.
|
|
10372
|
+
*/
|
|
10373
|
+
async function withoutMetadata(source, size, file, read) {
|
|
10374
|
+
if (file.voice || file.video || !size) return void 0;
|
|
10375
|
+
if (!isStrippedPicture(await read(0, Math.min(PICTURE_METADATA_LIMITS.headBytes, size)), file.mime)) return void 0;
|
|
10376
|
+
if (size > PICTURE_METADATA_LIMITS.maxBytes) throw new Error(NO_PICTURE_METADATA);
|
|
10377
|
+
const whole = new Uint8Array(size);
|
|
10378
|
+
for (let offset = 0; offset < size;) {
|
|
10379
|
+
const part = await read(offset, Math.min(1048576, size - offset));
|
|
10380
|
+
if (!part.length) throw new Error("The file is shorter than it says");
|
|
10381
|
+
whole.set(part, offset);
|
|
10382
|
+
offset += part.length;
|
|
10383
|
+
}
|
|
10384
|
+
return new Blob(stripPictureMetadata(whole, file.mime), { type: source.blob?.type ?? file.mime });
|
|
10385
|
+
}
|
|
10386
|
+
/**
|
|
10317
10387
|
* A copy of a file on this device, for sending in another chat under `file.id`: a small one whole, a larger one a
|
|
10318
|
-
* step at a time, never whole in memory
|
|
10388
|
+
* step at a time, never whole in memory; a picture without its metadata, read whole. Refused while it is still
|
|
10389
|
+
* arriving, or when its bytes are gone. Resolves to `file` as it goes: a stripped picture's size is its copy's.
|
|
10319
10390
|
*/
|
|
10320
10391
|
async function copyForForward(sourceId, target) {
|
|
10321
10392
|
const source = await fileStore.get(sourceId);
|
|
10322
10393
|
if (!source?.metadata) throw new Error("The file is not on this device any more");
|
|
10323
|
-
const
|
|
10394
|
+
const stored = storedSize(source);
|
|
10324
10395
|
const checked = source.wire3 ? source.wire3.state === "done" : !source.group || source.transfer?.state === "done";
|
|
10325
|
-
if (source.direction === "in" && !checked || await bytesHere(source) !==
|
|
10326
|
-
const
|
|
10396
|
+
if (source.direction === "in" && !checked || await bytesHere(source) !== stored) throw new Error("The file has not arrived yet");
|
|
10397
|
+
const from = source.bytes ? await fileBytesOf(source.bytes) : null;
|
|
10398
|
+
const read = async (offset, length) => source.blob ? new Uint8Array(await source.blob.slice(offset, offset + length).arrayBuffer()) : from.read(source.id, offset, length);
|
|
10399
|
+
const stripped = await withoutMetadata(source, stored, target.file, read);
|
|
10400
|
+
const blob = stripped ?? source.blob, size = stripped?.size ?? stored;
|
|
10401
|
+
const known = stripped ? void 0 : source.digest;
|
|
10402
|
+
const { linkId, wireId, timestamp } = target, file = stripped ? {
|
|
10403
|
+
...target.file,
|
|
10404
|
+
size
|
|
10405
|
+
} : target.file;
|
|
10327
10406
|
const metadata = {
|
|
10328
10407
|
name: file.name,
|
|
10329
10408
|
size: file.size,
|
|
@@ -10346,32 +10425,33 @@ async function copyForForward(sourceId, target) {
|
|
|
10346
10425
|
size: file.size
|
|
10347
10426
|
}
|
|
10348
10427
|
};
|
|
10349
|
-
if (size <= 16777216 &&
|
|
10350
|
-
const copy = new Blob([await
|
|
10428
|
+
if (size <= 16777216 && blob) {
|
|
10429
|
+
const copy = new Blob([await blob.slice(0, size).arrayBuffer()], { type: blob.type });
|
|
10430
|
+
const digest = known ?? (stripped ? await blobDigest(copy) : void 0);
|
|
10351
10431
|
await fileStore.put({
|
|
10352
10432
|
...record,
|
|
10353
10433
|
blob: copy,
|
|
10354
|
-
...
|
|
10434
|
+
...digest && { digest }
|
|
10355
10435
|
});
|
|
10356
|
-
return;
|
|
10436
|
+
return file;
|
|
10357
10437
|
}
|
|
10358
10438
|
const bytes = await fileBytes();
|
|
10359
|
-
const from = source.bytes ? await fileBytesOf(source.bytes) : null;
|
|
10360
10439
|
try {
|
|
10361
10440
|
const appender = new FileAppender(bytes, file.id);
|
|
10362
10441
|
for (let offset = 0; offset < size;) {
|
|
10363
|
-
const part =
|
|
10442
|
+
const part = blob ? new Uint8Array(await blob.slice(offset, offset + 1048576).arrayBuffer()) : await read(offset, Math.min(1048576, size - offset));
|
|
10364
10443
|
if (!part.length) throw new Error("The file is shorter than it says");
|
|
10365
10444
|
await appender.append(part);
|
|
10366
10445
|
offset += part.length;
|
|
10367
10446
|
}
|
|
10368
10447
|
await appender.close();
|
|
10369
|
-
const digest =
|
|
10448
|
+
const digest = known ?? await bytes.digest(file.id);
|
|
10370
10449
|
await fileStore.put({
|
|
10371
10450
|
...record,
|
|
10372
10451
|
bytes: bytes.kind,
|
|
10373
10452
|
digest
|
|
10374
10453
|
});
|
|
10454
|
+
return file;
|
|
10375
10455
|
} catch (error) {
|
|
10376
10456
|
await bytes.remove(file.id).catch(() => {});
|
|
10377
10457
|
throw error;
|
|
@@ -10922,9 +11002,10 @@ async function noteBundles(change) {
|
|
|
10922
11002
|
const settings = tx.objectStore(STORES$1.settings);
|
|
10923
11003
|
const read = settings.get(APP_BUNDLES_KEY);
|
|
10924
11004
|
read.onsuccess = () => {
|
|
10925
|
-
const
|
|
11005
|
+
const before = bundleDigests(read.result);
|
|
11006
|
+
const noted = new Set(before);
|
|
10926
11007
|
change(noted);
|
|
10927
|
-
settings.put([...noted], APP_BUNDLES_KEY);
|
|
11008
|
+
if (noted.size !== before.length || before.some((d) => !noted.has(d))) settings.put([...noted], APP_BUNDLES_KEY);
|
|
10928
11009
|
};
|
|
10929
11010
|
await done(tx);
|
|
10930
11011
|
}
|
|
@@ -10953,6 +11034,21 @@ function notReadable(url, words) {
|
|
|
10953
11034
|
if (typeof url === "string" && isGitHubPage(url)) fail("github-link", "Paste the repository's link, or the link to its app file");
|
|
10954
11035
|
fail("host", words);
|
|
10955
11036
|
}
|
|
11037
|
+
/**
|
|
11038
|
+
* A pasted link Ghostly reads, with a query or a fragment, is refused (`private-link`): a private repository's file link
|
|
11039
|
+
* carries its read token in the query, and the link an app is installed from goes on the card a contact receives. A
|
|
11040
|
+
* github.com page's query never reaches the file read (`appPasteUrl` makes that link anew).
|
|
11041
|
+
*/
|
|
11042
|
+
function refusePrivateLink(url) {
|
|
11043
|
+
if (typeof url !== "string" || isGitHubPage(url)) return;
|
|
11044
|
+
let href;
|
|
11045
|
+
try {
|
|
11046
|
+
href = new URL(url.trim()).href;
|
|
11047
|
+
} catch {
|
|
11048
|
+
return;
|
|
11049
|
+
}
|
|
11050
|
+
if (/[?#]/.test(href)) fail("private-link", "This link carries a query or a fragment, as a private repository's file link does: publish the app in a public repository and paste its link");
|
|
11051
|
+
}
|
|
10956
11052
|
var versionOf = (manifest, digest) => ({
|
|
10957
11053
|
ref: appRef(manifest.publisher, manifest.name),
|
|
10958
11054
|
sequence: manifest.sequence,
|
|
@@ -11495,6 +11591,7 @@ var Apps = class {
|
|
|
11495
11591
|
for (const kind of kinds) await this.removeBundle(kind, digest);
|
|
11496
11592
|
gone.add(digest);
|
|
11497
11593
|
}
|
|
11594
|
+
if (this.stopped) return;
|
|
11498
11595
|
await noteBundles((noted) => {
|
|
11499
11596
|
for (const digest of named) noted.add(digest);
|
|
11500
11597
|
for (const digest of gone) noted.delete(digest);
|
|
@@ -11692,7 +11789,9 @@ var Apps = class {
|
|
|
11692
11789
|
return (await this.stores()).sort((a, b) => a.addedAt - b.addedAt).map((s) => this.summary(s));
|
|
11693
11790
|
}
|
|
11694
11791
|
storeUrl(url) {
|
|
11695
|
-
|
|
11792
|
+
const at = typeof url === "string" && appPasteUrl(url, "ghostly-store.json") || notReadable(url, "Stores are read only from raw.githubusercontent.com, or from cdn.jsdelivr.net at a commit, over HTTPS");
|
|
11793
|
+
refusePrivateLink(url);
|
|
11794
|
+
return at;
|
|
11696
11795
|
}
|
|
11697
11796
|
keepPreviewed(previewed) {
|
|
11698
11797
|
if (this.previewedSweep) clearTimeout(this.previewedSweep);
|
|
@@ -11879,8 +11978,10 @@ var Apps = class {
|
|
|
11879
11978
|
const { bundle, bytes } = await this.bundled(app);
|
|
11880
11979
|
return this.stage(bundle, bytes, app.url, void 0, true);
|
|
11881
11980
|
}
|
|
11882
|
-
if ("url" in source)
|
|
11883
|
-
|
|
11981
|
+
if ("url" in source) {
|
|
11982
|
+
urls = [typeof source.url === "string" && appPasteUrl(source.url, "app.ghostlyapp") || notReadable(source.url, "Apps are read only from raw.githubusercontent.com, or from cdn.jsdelivr.net at a commit, over HTTPS")];
|
|
11983
|
+
refusePrivateLink(source.url);
|
|
11984
|
+
} else if ("store" in source) {
|
|
11884
11985
|
const s = await this.storeRecord(source.store);
|
|
11885
11986
|
const listing = s && !s.removed ? s.index?.apps.find((a) => a.ref === source.ref) : void 0;
|
|
11886
11987
|
if (!listing) fail("not-listed", "This store does not list this app");
|
|
@@ -11933,19 +12034,21 @@ var Apps = class {
|
|
|
11933
12034
|
if (oldest) this.sweep = setTimeout(() => this.sweepStaged(), STAGED.ms - (this.now() - oldest.at));
|
|
11934
12035
|
}
|
|
11935
12036
|
async stage(bundle, bytes, from, fromStore, carried = false) {
|
|
11936
|
-
|
|
11937
|
-
|
|
12037
|
+
const { manifest, digest } = bundle;
|
|
12038
|
+
const version = versionOf(manifest, digest);
|
|
12039
|
+
const revocations = carried ? [] : await this.readRevocations(version.ref, [from, ...manifest.sources ?? []]) ?? [];
|
|
12040
|
+
for (const [d, s] of this.staged) if (this.now() - s.at > STAGED.ms) this.staged.delete(d);
|
|
12041
|
+
this.staged.delete(digest);
|
|
11938
12042
|
while (this.staged.size >= STAGED.max) this.staged.delete(this.staged.keys().next().value);
|
|
11939
|
-
this.staged.set(
|
|
12043
|
+
this.staged.set(digest, {
|
|
11940
12044
|
bundle,
|
|
11941
12045
|
bytes,
|
|
11942
12046
|
from,
|
|
11943
12047
|
...fromStore !== void 0 && { store: fromStore },
|
|
12048
|
+
revocations,
|
|
11944
12049
|
at: this.now()
|
|
11945
12050
|
});
|
|
11946
12051
|
if (!this.sweep) this.sweepStaged();
|
|
11947
|
-
const { manifest, digest } = bundle;
|
|
11948
|
-
const version = versionOf(manifest, digest);
|
|
11949
12052
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
11950
12053
|
const decision = installDecision(installed, version);
|
|
11951
12054
|
const install = decision === "other-app" ? "new" : decision;
|
|
@@ -11961,7 +12064,7 @@ var Apps = class {
|
|
|
11961
12064
|
icon: bundle.files.get("icon.png")?.slice() ?? null,
|
|
11962
12065
|
install,
|
|
11963
12066
|
asks,
|
|
11964
|
-
run: this.runStatus(version, this.storeViews(stores), installed?.revocations),
|
|
12067
|
+
run: this.runStatus(version, this.storeViews(stores), [...installed?.revocations ?? [], ...revocations]),
|
|
11965
12068
|
listedBy,
|
|
11966
12069
|
unknownPublisher: !listedBy.some((s) => s.kind === "curated"),
|
|
11967
12070
|
...carried && { carried: true }
|
|
@@ -11978,7 +12081,7 @@ var Apps = class {
|
|
|
11978
12081
|
this.staged.delete(digest);
|
|
11979
12082
|
fail("expired", "Fetch the app again");
|
|
11980
12083
|
}
|
|
11981
|
-
const { bundle, bytes, from, store: fromStore } = staged;
|
|
12084
|
+
const { bundle, bytes, from, store: fromStore, revocations } = staged;
|
|
11982
12085
|
const { manifest } = bundle;
|
|
11983
12086
|
if (!Array.isArray(grant) || !manifest.permissions.every((p) => grant.includes(p))) fail("permissions", "Every permission the app asks for must be granted");
|
|
11984
12087
|
const version = versionOf(manifest, digest);
|
|
@@ -11986,7 +12089,7 @@ var Apps = class {
|
|
|
11986
12089
|
try {
|
|
11987
12090
|
for (;;) {
|
|
11988
12091
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
11989
|
-
const run = this.runStatus(version, this.storeViews(stores), installed?.revocations);
|
|
12092
|
+
const run = this.runStatus(version, this.storeViews(stores), [...installed?.revocations ?? [], ...revocations]);
|
|
11990
12093
|
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
11991
12094
|
if (run.status === "removed") fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
11992
12095
|
const decision = installDecision(installed, version);
|
|
@@ -12018,7 +12121,7 @@ var Apps = class {
|
|
|
12018
12121
|
return this.view(await this.app(version.ref), stores);
|
|
12019
12122
|
}
|
|
12020
12123
|
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
12021
|
-
const next = this.versionRecord(installed, bundle, kind, from, fromStore);
|
|
12124
|
+
const next = withRevocations(this.versionRecord(installed, bundle, kind, from, fromStore), revocations);
|
|
12022
12125
|
if (!await this.putAppIfUnchanged(next, installed)) continue;
|
|
12023
12126
|
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
12024
12127
|
if (installed && installed.digest !== digest) await this.removeBundle(installed.bytes, installed.digest);
|
|
@@ -12187,7 +12290,7 @@ var Apps = class {
|
|
|
12187
12290
|
const before = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
|
|
12188
12291
|
app = withRevocations(app, before ?? []);
|
|
12189
12292
|
if (app.pending && this.runStatus(versionOf(app.pending.manifest, app.pending.digest), this.storeViews(stores), app.revocations).status !== "ok") {
|
|
12190
|
-
|
|
12293
|
+
dropped.push(app.pending);
|
|
12191
12294
|
const { pending: _p, ...rest } = app;
|
|
12192
12295
|
app = rest;
|
|
12193
12296
|
}
|
|
@@ -12862,6 +12965,7 @@ function transition(from, profile, to, patch = {}) {
|
|
|
12862
12965
|
state: to
|
|
12863
12966
|
};
|
|
12864
12967
|
if (failed) delete next.breezDatabases;
|
|
12968
|
+
if (to === "active" && !("heldFiles" in patch)) delete next.heldFiles;
|
|
12865
12969
|
return checked(rising(from, next));
|
|
12866
12970
|
}
|
|
12867
12971
|
/** The record with some fields changed and its state kept. */
|
|
@@ -13930,7 +14034,8 @@ var raisedCounter = (value, floor) => Math.max((Number.isSafeInteger(value) ? va
|
|
|
13930
14034
|
*/
|
|
13931
14035
|
function raisedLink(link, floor) {
|
|
13932
14036
|
const paired = !!link.profile && !link.group;
|
|
13933
|
-
const
|
|
14037
|
+
const { ratchetState: _ratchet, ...rest } = link;
|
|
14038
|
+
const next = { ...rest };
|
|
13934
14039
|
if (link.dhtDeliveryState) next.dhtDeliveryState = {
|
|
13935
14040
|
...link.dhtDeliveryState,
|
|
13936
14041
|
sequence: raisedCounter(link.dhtDeliveryState.sequence, floor)
|
|
@@ -16172,6 +16277,17 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16172
16277
|
const earlier = [];
|
|
16173
16278
|
for (const set of record.earlierSets) {
|
|
16174
16279
|
const pending = staying(set.pending);
|
|
16280
|
+
let by;
|
|
16281
|
+
try {
|
|
16282
|
+
by = readSetUpdate(JSON.parse(set.setUpdate))?.by;
|
|
16283
|
+
} catch {}
|
|
16284
|
+
if (!by || !bytesEqual(by, signer.publicKey)) {
|
|
16285
|
+
earlier.push({
|
|
16286
|
+
...set,
|
|
16287
|
+
pending
|
|
16288
|
+
});
|
|
16289
|
+
continue;
|
|
16290
|
+
}
|
|
16175
16291
|
let oldRec;
|
|
16176
16292
|
try {
|
|
16177
16293
|
const was = JSON.parse(set.setUpdate);
|
|
@@ -16981,6 +17097,8 @@ var DeviceLinks = class {
|
|
|
16981
17097
|
turnQueue = Promise.resolve();
|
|
16982
17098
|
turnTimer = null;
|
|
16983
17099
|
lastHintRead = 0;
|
|
17100
|
+
/** When a link closing by the other side's doing last made this standby read the turn (`linkLost`). */
|
|
17101
|
+
lastLossRead = 0;
|
|
16984
17102
|
timers = /* @__PURE__ */ new Set();
|
|
16985
17103
|
constructor(options) {
|
|
16986
17104
|
this.options = options;
|
|
@@ -17211,6 +17329,7 @@ var DeviceLinks = class {
|
|
|
17211
17329
|
running.rtcWait = void 0;
|
|
17212
17330
|
}
|
|
17213
17331
|
if (state !== "open") {
|
|
17332
|
+
if (running.agreed && !running.earlier && this.running.get(running.id) === running) this.linkLost().catch(() => {});
|
|
17214
17333
|
running.agreed = false;
|
|
17215
17334
|
this.failPings(running, "The device link closed");
|
|
17216
17335
|
if (running.handoff) {
|
|
@@ -17531,6 +17650,19 @@ var DeviceLinks = class {
|
|
|
17531
17650
|
this.lastHintRead = Date.now();
|
|
17532
17651
|
await this.checkAndShow().catch(() => null);
|
|
17533
17652
|
}
|
|
17653
|
+
/**
|
|
17654
|
+
* A standby's live link to another device of its set closed by that device's doing. A removal does this right after
|
|
17655
|
+
* it puts the tombstone, and nothing else tells a screen left in front (no focus, no visibility change) before its
|
|
17656
|
+
* next read, up to 10 minutes away: it would go on offering Use here, which must fail. Read once, as a hint is, at
|
|
17657
|
+
* most once in `TURN_HINT_EVERY_MS`: a network that drops every link at once costs one read.
|
|
17658
|
+
*/
|
|
17659
|
+
async linkLost() {
|
|
17660
|
+
if (!this.options.watchTurn || this.stopped || Date.now() - this.lastLossRead < 3e4) return;
|
|
17661
|
+
this.lastLossRead = Date.now();
|
|
17662
|
+
const record = await this.record();
|
|
17663
|
+
if (!record || record.state === "active" || record.state === "removed") return;
|
|
17664
|
+
await this.checkAndShow();
|
|
17665
|
+
}
|
|
17534
17666
|
/** `key` holds the set under `d` (or the current one): its pending frame is done, and the old link goes. */
|
|
17535
17667
|
async acked(key, d) {
|
|
17536
17668
|
if (!acknowledged(await this.record(), key, d)) return;
|
|
@@ -19572,6 +19704,34 @@ async function writeWalletHomes(wallets) {
|
|
|
19572
19704
|
});
|
|
19573
19705
|
}
|
|
19574
19706
|
//#endregion
|
|
19707
|
+
//#region ../browser/src/shared/refusals.ts
|
|
19708
|
+
/**
|
|
19709
|
+
* The ids the engine writes these lines under. A contact's frame names its own id, and one of these shapes fits what a
|
|
19710
|
+
* paired text (22 characters) or a held one may name: the engine stores no frame of a contact's under one
|
|
19711
|
+
* (`GhostlyNode.storeNewMessage`) and takes no edit of one (`receiveEdit`).
|
|
19712
|
+
*/
|
|
19713
|
+
var REFUSAL_ID = /^peer_(?:\d+_refused|spent_[0-9a-f]{32})$/;
|
|
19714
|
+
/** Whether a chat row's id is one a refusal line is written under. */
|
|
19715
|
+
var isRefusalId = (id) => REFUSAL_ID.test(id);
|
|
19716
|
+
/** The English line for `notice`, stored as the row's `text`. */
|
|
19717
|
+
function refusedText(notice) {
|
|
19718
|
+
return `Could not receive ${notice.method === "fedimint" ? "Fedimint ecash" : notice.amount === void 0 ? "a payment" : `${notice.amount.toLocaleString("en-US")} ${notice.network === "testnet" ? "test sats" : "sats"}`}: ${notice.reason}`;
|
|
19719
|
+
}
|
|
19720
|
+
/** The row the engine stores for a refusal: the values, and their English as the text. */
|
|
19721
|
+
function refusedRow(notice) {
|
|
19722
|
+
const values = {
|
|
19723
|
+
type: "paymentRefused",
|
|
19724
|
+
...notice.amount !== void 0 && { amount: notice.amount },
|
|
19725
|
+
...notice.network && { network: notice.network },
|
|
19726
|
+
...notice.method && { method: notice.method },
|
|
19727
|
+
reason: notice.reason
|
|
19728
|
+
};
|
|
19729
|
+
return {
|
|
19730
|
+
text: refusedText(values),
|
|
19731
|
+
notice: values
|
|
19732
|
+
};
|
|
19733
|
+
}
|
|
19734
|
+
//#endregion
|
|
19575
19735
|
//#region ../browser/src/engine/messageDetails.ts
|
|
19576
19736
|
/**
|
|
19577
19737
|
* What the engine remembers about a message's travels (WISP 400 § Message details), and how the details view is put
|
|
@@ -19806,7 +19966,8 @@ var FileDesk = class {
|
|
|
19806
19966
|
kept: () => made.saving,
|
|
19807
19967
|
room: async () => (await fileBytes()).room(),
|
|
19808
19968
|
...this.deps.sendData && { sendData: (id, offset, data) => this.deps.sendData(linkId, id, offset, data) },
|
|
19809
|
-
writable: () => this.deps.writable?.(linkId)
|
|
19969
|
+
writable: () => this.deps.writable?.(linkId),
|
|
19970
|
+
batchConfirms: true
|
|
19810
19971
|
});
|
|
19811
19972
|
this.chats.set(linkId, made);
|
|
19812
19973
|
chat = made;
|
|
@@ -19992,7 +20153,7 @@ var FileDesk = class {
|
|
|
19992
20153
|
chat.files.resume(direction, wireId);
|
|
19993
20154
|
break;
|
|
19994
20155
|
case "cancel":
|
|
19995
|
-
chat.files.cancel(direction, wireId);
|
|
20156
|
+
if (!sentWhole(record)) chat.files.cancel(direction, wireId);
|
|
19996
20157
|
break;
|
|
19997
20158
|
case "retry":
|
|
19998
20159
|
if (out) chat.files.retry(wireId);
|
|
@@ -20821,6 +20982,9 @@ var Outbox = class {
|
|
|
20821
20982
|
writes = 0;
|
|
20822
20983
|
stamp = 0;
|
|
20823
20984
|
seen = -1;
|
|
20985
|
+
/** How many looks at the chat (`held`) began, and how many are over: a row marked waiting meanwhile may not be in one. */
|
|
20986
|
+
looks = 0;
|
|
20987
|
+
looked = 0;
|
|
20824
20988
|
stopped = false;
|
|
20825
20989
|
resender;
|
|
20826
20990
|
policy;
|
|
@@ -20839,6 +21003,7 @@ var Outbox = class {
|
|
|
20839
21003
|
}
|
|
20840
21004
|
/** `messages`: the chat's history as the caller just read it (a start has), so it is not read a second time. */
|
|
20841
21005
|
async recover(messages) {
|
|
21006
|
+
const at = this.writes ? void 0 : this.stamp;
|
|
20842
21007
|
for (const message of messages ?? await this.store.read()) {
|
|
20843
21008
|
if (message.via === "hold" || message.sender !== "me") continue;
|
|
20844
21009
|
if (message.delivery === "queued") {
|
|
@@ -20857,6 +21022,7 @@ var Outbox = class {
|
|
|
20857
21022
|
} else if (until !== void 0) await this.expired(message);
|
|
20858
21023
|
else await this.queue(message, "Not confirmed before the app closed. It is sent again, under the same ID, once your contact is reachable.");
|
|
20859
21024
|
}
|
|
21025
|
+
if (at !== void 0 && !this.stopped) this.seen = at;
|
|
20860
21026
|
}
|
|
20861
21027
|
/**
|
|
20862
21028
|
* One at a time, in the order asked: `run` starts when the turns before it are over. A turn that takes longer than
|
|
@@ -20966,12 +21132,31 @@ var Outbox = class {
|
|
|
20966
21132
|
*/
|
|
20967
21133
|
async look(id) {
|
|
20968
21134
|
if (!this.store.get || !this.known || this.waiting.size + this.receipts.size + this.onTheirWay.size > KNOWN_ROWS) return this.store.read();
|
|
20969
|
-
|
|
20970
|
-
id,
|
|
21135
|
+
const ids = /* @__PURE__ */ new Set([
|
|
21136
|
+
...id === void 0 ? [] : [id],
|
|
20971
21137
|
...this.waiting.keys(),
|
|
20972
21138
|
...this.receipts.keys(),
|
|
20973
21139
|
...this.onTheirWay.keys()
|
|
20974
|
-
])
|
|
21140
|
+
]);
|
|
21141
|
+
return (await Promise.all([...ids].map((known) => this.store.get(known)))).filter((row) => !!row);
|
|
21142
|
+
}
|
|
21143
|
+
/**
|
|
21144
|
+
* What a look at the chat takes up comes from: the rows this outbox holds, by id, where it knows them all (`look`);
|
|
21145
|
+
* else the chat's whole history, which, when it shows nothing of mine to go that this outbox did not know of, says
|
|
21146
|
+
* so until the next row stored by someone else. A session that opened with nothing queued, nothing awaiting a
|
|
21147
|
+
* receipt and nothing waiting read the chat's whole history for nothing, twice (the link says it is open in two
|
|
21148
|
+
* ways): 600 ms of a daemon's time per reconnect at 10,000 messages (agents#2468).
|
|
21149
|
+
*/
|
|
21150
|
+
async held() {
|
|
21151
|
+
this.looks++;
|
|
21152
|
+
const at = this.writes ? void 0 : this.stamp;
|
|
21153
|
+
try {
|
|
21154
|
+
const messages = await this.look();
|
|
21155
|
+
if (at !== void 0 && !messages.some((m) => this.unknown(m))) this.seen = at;
|
|
21156
|
+
return messages;
|
|
21157
|
+
} finally {
|
|
21158
|
+
this.looked++;
|
|
21159
|
+
}
|
|
20975
21160
|
}
|
|
20976
21161
|
/** A row of mine still to go that this outbox holds nothing of: only a look at the chat finds it. */
|
|
20977
21162
|
unknown(m, id) {
|
|
@@ -21129,10 +21314,12 @@ var Outbox = class {
|
|
|
21129
21314
|
* nothing about it is unconfirmed; it counts no attempt until it goes.
|
|
21130
21315
|
*/
|
|
21131
21316
|
async wait(id, reason) {
|
|
21317
|
+
const looked = this.looked;
|
|
21132
21318
|
const message = await this.one(id);
|
|
21133
21319
|
if (!message || this.stopped) return;
|
|
21134
21320
|
await this.store.update(id, "waiting", reason, { resendUntil: message.resendUntil ?? this.now() + this.policy.windowMs });
|
|
21135
21321
|
this.schedule(id);
|
|
21322
|
+
if (this.looks !== looked) this.flush().catch(() => {});
|
|
21136
21323
|
}
|
|
21137
21324
|
async received(wireId) {
|
|
21138
21325
|
const id = `me_${wireId}`;
|
|
@@ -21155,7 +21342,7 @@ var Outbox = class {
|
|
|
21155
21342
|
if (!reopened && this.lookAhead === look) this.lookAhead = void 0;
|
|
21156
21343
|
if (this.stopped) return;
|
|
21157
21344
|
if (reopened) for (const id of this.busy) this.reopenedWhileBusy.add(id);
|
|
21158
|
-
await this.inOrder(this.due(await this.
|
|
21345
|
+
await this.inOrder(this.due(await this.held(), opened));
|
|
21159
21346
|
});
|
|
21160
21347
|
if (reopened) return look;
|
|
21161
21348
|
this.lookAhead = look;
|
|
@@ -21395,7 +21582,7 @@ var EditQueue = class {
|
|
|
21395
21582
|
wires = /* @__PURE__ */ new Map();
|
|
21396
21583
|
dhtIds = /* @__PURE__ */ new Map();
|
|
21397
21584
|
tick = 0;
|
|
21398
|
-
/** The chat's history was read for the rows with an edit on its way: `known` has them all
|
|
21585
|
+
/** The chat's history was read for the rows with an edit on its way: `known` has them all from then on (`edited`). */
|
|
21399
21586
|
learnt = false;
|
|
21400
21587
|
timer;
|
|
21401
21588
|
flushing = null;
|
|
@@ -21436,10 +21623,11 @@ var EditQueue = class {
|
|
|
21436
21623
|
* A new session: what the last one sent without a confirmation may go again at once, with a fresh count of attempts.
|
|
21437
21624
|
* Said once, as the session opens and before anything goes on it: said again later, it would send a second time what
|
|
21438
21625
|
* this session already sent (two flushes of one opening, each starting over, sent a restored question's edit twice).
|
|
21626
|
+
* What it learnt stays: every edit of this run is told (`edited`), so the rows it knows are still all of them, and a
|
|
21627
|
+
* session that opened read the chat's whole history to find none (agents#2468). A new run learns them once.
|
|
21439
21628
|
*/
|
|
21440
21629
|
reopened() {
|
|
21441
21630
|
this.sent.clear();
|
|
21442
|
-
this.learnt = false;
|
|
21443
21631
|
}
|
|
21444
21632
|
/** This row has an edit to send (it was just written so): the next look reads it. */
|
|
21445
21633
|
edited(id) {
|
|
@@ -22653,8 +22841,8 @@ var Reactions = class {
|
|
|
22653
22841
|
const e = emoji === "" ? "" : reactionEmoji(emoji);
|
|
22654
22842
|
if (e === null) return { error: "A reaction is one emoji" };
|
|
22655
22843
|
const target = await this.named(chat, messageId);
|
|
22656
|
-
const id = target && replyRef(target,
|
|
22657
|
-
if (!target || !id) return { error:
|
|
22844
|
+
const group = isGroup$1(chat), id = target && replyRef(target, group);
|
|
22845
|
+
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or takes no reaction` };
|
|
22658
22846
|
const current = target.reactions?.me;
|
|
22659
22847
|
if (!e && !current?.e) return { error: "No reaction of yours to take back" };
|
|
22660
22848
|
let last = this.last.get(chat) ?? lastMine(await this.host.messages(chat));
|
|
@@ -22971,17 +23159,17 @@ async function pinnedRow(host, chat, id) {
|
|
|
22971
23159
|
*/
|
|
22972
23160
|
async function myPin(host, chat, messageId, remove, current, now = Date.now()) {
|
|
22973
23161
|
const n = nextPinNumber(current?.n, now);
|
|
23162
|
+
const group = isGroup(chat);
|
|
22974
23163
|
if (remove) return current?.id ? {
|
|
22975
23164
|
id: "",
|
|
22976
23165
|
n,
|
|
22977
23166
|
by: "me",
|
|
22978
23167
|
at: now
|
|
22979
|
-
} : { error:
|
|
23168
|
+
} : { error: `Nothing is pinned in this ${group ? "group" : "chat"}` };
|
|
22980
23169
|
if (typeof messageId !== "string" || !messageId) return { error: "No message to pin" };
|
|
22981
|
-
const group = isGroup(chat);
|
|
22982
23170
|
const target = host.message ? await host.message(chat, messageId) ?? await pinnedRow(host, chat, messageId) : (await host.messages(chat)).find((m) => m.id === messageId) ?? await pinnedRow(host, chat, messageId);
|
|
22983
23171
|
const id = target && replyRef(target, group);
|
|
22984
|
-
if (!target || !id) return { error:
|
|
23172
|
+
if (!target || !id) return { error: `That message is not in this ${group ? "group" : "chat"}, or cannot be pinned` };
|
|
22985
23173
|
return {
|
|
22986
23174
|
id,
|
|
22987
23175
|
n,
|
|
@@ -23419,6 +23607,19 @@ var KNOCK_SLOT_OPEN_MS = 2e4;
|
|
|
23419
23607
|
/** How long a hub missing from the beacon still counts as one for the edges already up. */
|
|
23420
23608
|
var HUB_GRACE_MS = 18e4;
|
|
23421
23609
|
/**
|
|
23610
|
+
* A member's look past its hubs (`tipCheck`): the beacon's head names a newer epoch than mine for this long, or readings
|
|
23611
|
+
* of the beacon this far apart left my hub out while listing another (`HUB_MISSING_MS`, kept that long). A hub the
|
|
23612
|
+
* admin removed whose app does not take that in keeps my edge up and lists itself: heard only from it, I stayed on the
|
|
23613
|
+
* epoch before, and what I wrote went to it alone (bug hunt, 2026-11-02). Then another hub is asked too, for a while,
|
|
23614
|
+
* and not again before `TIP_CHECK_EVERY_MS`.
|
|
23615
|
+
*/
|
|
23616
|
+
var TIP_AHEAD_MS = 45e3;
|
|
23617
|
+
var HUB_MISSING_MS = 2e4;
|
|
23618
|
+
var HUB_MISSING_KEPT_MS = 18e4;
|
|
23619
|
+
var TIP_CHECK_MS = 12e4;
|
|
23620
|
+
var TIP_CHECK_UP_MS = 2e4;
|
|
23621
|
+
var TIP_CHECK_EVERY_MS = 3e5;
|
|
23622
|
+
/**
|
|
23422
23623
|
* A member cut off by a hub that left waits this long for the hub that takes it in its place before it may step up as
|
|
23423
23624
|
* a hub itself: long enough for that hub's lobby reading (every 6 s once a hub left) and an edge, short enough that a
|
|
23424
23625
|
* group that needs one more hub gets it.
|
|
@@ -24070,7 +24271,7 @@ var Communities = class {
|
|
|
24070
24271
|
await this.closeEntries(group.id);
|
|
24071
24272
|
await this.startJoining({
|
|
24072
24273
|
g: group.id,
|
|
24073
|
-
host: live.session.
|
|
24274
|
+
host: live.session.lostEntryKey
|
|
24074
24275
|
}, live.session.state.seedB64, now);
|
|
24075
24276
|
continue;
|
|
24076
24277
|
}
|
|
@@ -24238,6 +24439,7 @@ var Communities = class {
|
|
|
24238
24439
|
if ((gone.length || lost || bare) && !edges.has(key)) live.expect.add(key);
|
|
24239
24440
|
if (gone.length || lost) (live.replacing ??= /* @__PURE__ */ new Set()).add(key);
|
|
24240
24441
|
}
|
|
24442
|
+
await this.lookPast(groupId, live, others, kept, now);
|
|
24241
24443
|
live.myHubs = kept;
|
|
24242
24444
|
live.forceHub = !kept.length && others.length < COMMUNITY_TOPOLOGY.maxHubs;
|
|
24243
24445
|
for (const hub of kept) {
|
|
@@ -24272,7 +24474,7 @@ var Communities = class {
|
|
|
24272
24474
|
} else continue;
|
|
24273
24475
|
if (linkId) await this.host.closeEdge(linkId);
|
|
24274
24476
|
}
|
|
24275
|
-
if (s.needsCatchUp && now - (live.lastCatchUp ?? 0) >= 5e3 || now - (live.lastCatchUp ?? 0) >= 3e4) {
|
|
24477
|
+
if ((s.needsCatchUp || live.tipCheck?.upAt) && now - (live.lastCatchUp ?? 0) >= 5e3 || now - (live.lastCatchUp ?? 0) >= 3e4) {
|
|
24276
24478
|
live.lastCatchUp = now;
|
|
24277
24479
|
const ready = [...this.host.edges(groupId)].filter(([key, id]) => this.host.linkReady(id, 2) && !s.wasRemoved(key)).map(([key]) => key);
|
|
24278
24480
|
for (const key of ready.slice(0, 3)) s.catchUp(key);
|
|
@@ -24302,6 +24504,52 @@ var Communities = class {
|
|
|
24302
24504
|
}
|
|
24303
24505
|
}
|
|
24304
24506
|
/**
|
|
24507
|
+
* As a member: does my hub pass the chain on? A hub removed whose app does not take that in keeps my edge up and goes
|
|
24508
|
+
* on listing itself, and I heard of the removal only from it (`TIP_AHEAD_MS`). The other hubs drop it from the beacon
|
|
24509
|
+
* each time they write, and the head they carry names their newer epoch once someone speaks in it. On either, another
|
|
24510
|
+
* hub is asked too (`kept`, for its lobby and edge) and the catch-up asks it with mine, until its edge has been up a
|
|
24511
|
+
* while: the commit I lacked comes with it, and a hub the chain took out goes as after a leave (`gone`).
|
|
24512
|
+
*/
|
|
24513
|
+
async lookPast(groupId, live, others, kept, now) {
|
|
24514
|
+
const s = live.session, edges = this.host.edges(groupId);
|
|
24515
|
+
const up = (key) => {
|
|
24516
|
+
const id = edges.get(key);
|
|
24517
|
+
return !!id && this.host.linkReady(id, 2);
|
|
24518
|
+
};
|
|
24519
|
+
live.aheadSince = live.head && live.head.e > s.epoch ? live.aheadSince ?? now : void 0;
|
|
24520
|
+
if (live.beaconAt === now) {
|
|
24521
|
+
const listed = freshHubs(live.beacon, now);
|
|
24522
|
+
if (kept.some((key) => up(key) && !listed.some((h) => h.key === key)) && listed.some((h) => h.key !== s.myKey && !kept.includes(h.key))) (live.hubMissing ??= []).push(now);
|
|
24523
|
+
}
|
|
24524
|
+
if (live.hubMissing) live.hubMissing = live.hubMissing.filter((at) => now - at <= HUB_MISSING_KEPT_MS);
|
|
24525
|
+
const check = live.tipCheck;
|
|
24526
|
+
if (check) {
|
|
24527
|
+
if (up(check.key)) check.upAt ??= now;
|
|
24528
|
+
if (!(kept.includes(check.key) || live.hubsAvoided.has(check.key) || this.gone(live, check.key) || check.upAt !== void 0 && now - check.upAt >= TIP_CHECK_UP_MS || now - check.since >= TIP_CHECK_MS)) {
|
|
24529
|
+
kept.push(check.key);
|
|
24530
|
+
return;
|
|
24531
|
+
}
|
|
24532
|
+
live.tipCheck = void 0;
|
|
24533
|
+
live.tipCheckedAt = now;
|
|
24534
|
+
live.hubMissing = void 0;
|
|
24535
|
+
const id = edges.get(check.key);
|
|
24536
|
+
if (id && !kept.includes(check.key)) await this.host.closeEdge(id);
|
|
24537
|
+
return;
|
|
24538
|
+
}
|
|
24539
|
+
const missing = live.hubMissing ?? [];
|
|
24540
|
+
const ahead = live.aheadSince !== void 0 && now - live.aheadSince >= TIP_AHEAD_MS;
|
|
24541
|
+
if (!kept.length || !(ahead || missing.length >= 2 && missing[missing.length - 1] - missing[0] >= HUB_MISSING_MS)) return;
|
|
24542
|
+
if (now - (live.tipCheckedAt ?? -Infinity) < TIP_CHECK_EVERY_MS) return;
|
|
24543
|
+
if ([...edges].some(([key, id]) => !kept.includes(key) && this.host.linkReady(id, 2) && !this.gone(live, key))) return;
|
|
24544
|
+
const [key] = pickHubs(s.myKey, others, now, /* @__PURE__ */ new Set([...kept, ...live.hubsAvoided.keys()]));
|
|
24545
|
+
if (!key) return;
|
|
24546
|
+
live.tipCheck = {
|
|
24547
|
+
key,
|
|
24548
|
+
since: now
|
|
24549
|
+
};
|
|
24550
|
+
kept.push(key);
|
|
24551
|
+
}
|
|
24552
|
+
/**
|
|
24305
24553
|
* May this idle hub step down? When enough other hubs are listed and it has an edge up to one that is listed now
|
|
24306
24554
|
* (a hub cut off from the others would only come back as one). It then steps down in two steps: it takes itself
|
|
24307
24555
|
* out of the beacon, still a hub, and is a member only once a later reading still lists a hub it has an edge to.
|
|
@@ -24323,9 +24571,12 @@ var Communities = class {
|
|
|
24323
24571
|
hubLoad(groupId, live, now) {
|
|
24324
24572
|
const edges = this.host.edges(groupId);
|
|
24325
24573
|
if (now - live.beaconAt <= 2 * this.timings.beaconReadMs) {
|
|
24326
|
-
const
|
|
24327
|
-
for (const [key, id] of edges) if (!
|
|
24328
|
-
for (const key of [...live.members.keys()])
|
|
24574
|
+
const listed = new Map(freshHubs(this.hubs(live), now).map((h) => [h.key, h]));
|
|
24575
|
+
for (const [key, id] of edges) if (!listed.has(key) && !live.members.has(key) && this.host.linkReady(id, 2) && rosterHas(live.session.roster, key) && !this.gone(live, key)) live.members.set(key, now);
|
|
24576
|
+
for (const key of [...live.members.keys()]) {
|
|
24577
|
+
const hub = listed.get(key);
|
|
24578
|
+
if (hub && !this.hubDead(groupId, live, hub, now)) live.members.delete(key);
|
|
24579
|
+
}
|
|
24329
24580
|
}
|
|
24330
24581
|
for (const [key, since] of live.members) {
|
|
24331
24582
|
const id = edges.get(key);
|
|
@@ -25010,10 +25261,12 @@ var Communities = class {
|
|
|
25010
25261
|
case "group-welcome": {
|
|
25011
25262
|
const joining = group.joining;
|
|
25012
25263
|
if (!joining || joining.linkId !== linkId || !joining.inviter) return;
|
|
25013
|
-
const
|
|
25264
|
+
const inviter = joining.inviter;
|
|
25265
|
+
const joined = await CommunitySession.joinPaced({
|
|
25014
25266
|
g,
|
|
25015
25267
|
host: joining.host
|
|
25016
25268
|
}, joining.pieces, frame, joining.seedB64);
|
|
25269
|
+
if (this.stored.get(g) !== group || group.joining !== joining || joining.linkId !== linkId || joining.inviter !== inviter) return;
|
|
25017
25270
|
if ("error" in joined && joined.error === LINK_REPLACED && !joining.check) {
|
|
25018
25271
|
joining.replaced = true;
|
|
25019
25272
|
joining.inviter = "";
|
|
@@ -25101,7 +25354,12 @@ var Communities = class {
|
|
|
25101
25354
|
if (f.t === "group-sync" && live.session.isMember) this.sayFarewell(groupId, live, peerKey, f);
|
|
25102
25355
|
return;
|
|
25103
25356
|
}
|
|
25104
|
-
|
|
25357
|
+
const named = live.session.isRecentMember(peerKey);
|
|
25358
|
+
if (!named && f.t === "group-sync") {
|
|
25359
|
+
await live.session.handle(peerKey, frame);
|
|
25360
|
+
return;
|
|
25361
|
+
}
|
|
25362
|
+
if (!named && f.t !== "group-commit" && f.t !== "group-msg" && f.t !== "group-secrets" && !(f.t === "group-secret" && f.to === live.session.myKey)) return;
|
|
25105
25363
|
if ((f.t === "group-secret" || f.t === "group-entry") && typeof f.to === "string" && f.to !== live.session.myKey) {
|
|
25106
25364
|
if (!live.hub) return;
|
|
25107
25365
|
const id = `${String(f.t)}:${f.to}:${String(f.h ?? f.x)}`;
|
|
@@ -26160,13 +26418,13 @@ var MeshSignals = class {
|
|
|
26160
26418
|
* one of them is a link of the two of us, or reaches the admin (`CarriedHooks.carry`).
|
|
26161
26419
|
*/
|
|
26162
26420
|
carry(groupId, to, payload) {
|
|
26163
|
-
const
|
|
26164
|
-
if (!
|
|
26421
|
+
const carriers = this.carriers(groupId, to);
|
|
26422
|
+
if (!carriers) return {
|
|
26165
26423
|
taken: 0,
|
|
26166
26424
|
sure: false
|
|
26167
26425
|
};
|
|
26168
|
-
const frame = groupSignalFrame(groupId, session.myKey, to, payload);
|
|
26169
|
-
const { links, sure } =
|
|
26426
|
+
const frame = groupSignalFrame(groupId, carriers.session.myKey, to, payload);
|
|
26427
|
+
const { links, sure } = carriers;
|
|
26170
26428
|
let taken = 0;
|
|
26171
26429
|
for (const linkId of links) try {
|
|
26172
26430
|
this.host.sendOnLink(linkId, frame);
|
|
@@ -26177,6 +26435,18 @@ var MeshSignals = class {
|
|
|
26177
26435
|
sure: sure && taken > 0
|
|
26178
26436
|
};
|
|
26179
26437
|
}
|
|
26438
|
+
/** Whether `carry` would hand my packet for the edge to `to` to any link now (`CarriedHooks.canCarry`). */
|
|
26439
|
+
canCarry(groupId, to) {
|
|
26440
|
+
return !!this.carriers(groupId, to)?.links.length;
|
|
26441
|
+
}
|
|
26442
|
+
carriers(groupId, to) {
|
|
26443
|
+
const session = this.scope.session(groupId), group = this.scope.stored(groupId);
|
|
26444
|
+
if (!session || !group || group.left || session.status !== "active" || to === session.myKey || !rosterHas(session.roster, to)) return void 0;
|
|
26445
|
+
return {
|
|
26446
|
+
session,
|
|
26447
|
+
...this.links(groupId, session, group, to)
|
|
26448
|
+
};
|
|
26449
|
+
}
|
|
26180
26450
|
/**
|
|
26181
26451
|
* A `group-signal` that came on `linkId`, whose other end is the member `via` (none: an entry session's admin side
|
|
26182
26452
|
* as the joiner sees it). For me: the edge takes it, and my own packet goes back the same way when theirs was news.
|
|
@@ -27347,6 +27617,7 @@ var Groups = class {
|
|
|
27347
27617
|
return {
|
|
27348
27618
|
me: session.myKey,
|
|
27349
27619
|
community: false,
|
|
27620
|
+
onHubs: this.hubs.active(groupId, session, this.now()),
|
|
27350
27621
|
inRoster: (key) => rosterHas(session.roster, key),
|
|
27351
27622
|
couldRead: (key, messageId, ts) => session.couldRead(key, messageId, ts)
|
|
27352
27623
|
};
|
|
@@ -27758,7 +28029,10 @@ var Groups = class {
|
|
|
27758
28029
|
return;
|
|
27759
28030
|
}
|
|
27760
28031
|
const group = this.stored.get(groupId);
|
|
27761
|
-
if (!group?.entry)
|
|
28032
|
+
if (!group?.entry) {
|
|
28033
|
+
if (!this.sessions.get(groupId)?.isAdmin) throw new Error("Only the admin can replace or turn off the group's link");
|
|
28034
|
+
return;
|
|
28035
|
+
}
|
|
27762
28036
|
delete group.entry;
|
|
27763
28037
|
await this.store.putGroup(group);
|
|
27764
28038
|
await this.closeEntries(groupId);
|
|
@@ -28017,6 +28291,10 @@ var Groups = class {
|
|
|
28017
28291
|
sure: false
|
|
28018
28292
|
} : this.signals.carry(groupId, to, payload);
|
|
28019
28293
|
}
|
|
28294
|
+
/** Whether `carrySignal` would hand my packet for the edge to `to` to any link now. */
|
|
28295
|
+
canCarrySignal(groupId, to) {
|
|
28296
|
+
return !this.isCommunity(groupId) && this.signals.canCarry(groupId, to);
|
|
28297
|
+
}
|
|
28020
28298
|
/** My packet for the edge to `to`, over that edge itself while it is up (`MeshSignals.direct`). */
|
|
28021
28299
|
directSignal(groupId, to, linkId, payload) {
|
|
28022
28300
|
return !this.isCommunity(groupId) && this.signals.direct(groupId, to, linkId, payload);
|
|
@@ -29323,15 +29601,24 @@ function edgeView(live, now = Date.now(), noSlot = false) {
|
|
|
29323
29601
|
const pairingError = live.pairing?.status === "error" ? live.pairing.error : void 0;
|
|
29324
29602
|
const error = open ? void 0 : pairingError ?? live.discoveryError;
|
|
29325
29603
|
const state = open ? "open" : error ? "error" : live.dataLink !== "idle" ? "connecting" : "waiting";
|
|
29604
|
+
const cause = error ? pairingError ? edgeErrorCause(pairingError) : "relays" : void 0;
|
|
29605
|
+
const heardAt = Math.max(presenceSeenAt(live.presence), live.lastSyncAt);
|
|
29606
|
+
const seen = heardAt > 0 ? now - heardAt < PRESENCE_WINDOW : !!live.stored.edgeLive && now - (live.edgeStartedAt ?? now) < 6e5;
|
|
29607
|
+
const reconnecting = !open && seen && (live.lastSyncAt > 0 || !!live.stored.edgeLive) && cause !== "other";
|
|
29608
|
+
const retryAt = reconnecting ? live.link?.liveAttempt?.retryAt : void 0;
|
|
29609
|
+
const attempt = reconnecting ? live.link?.dialAttempts ?? 0 : 0;
|
|
29326
29610
|
return {
|
|
29327
29611
|
linkId: live.stored.id,
|
|
29328
29612
|
state,
|
|
29329
29613
|
...open && live.pairing?.transport ? { transport: live.pairing.transport } : {},
|
|
29330
|
-
lastSeenAt:
|
|
29614
|
+
lastSeenAt: heardAt,
|
|
29331
29615
|
...error ? {
|
|
29332
29616
|
error,
|
|
29333
|
-
cause
|
|
29334
|
-
} : {}
|
|
29617
|
+
cause
|
|
29618
|
+
} : {},
|
|
29619
|
+
...reconnecting ? { reconnecting: true } : {},
|
|
29620
|
+
...retryAt && retryAt > now ? { retryAt } : {},
|
|
29621
|
+
...attempt > 0 ? { attempt } : {}
|
|
29335
29622
|
};
|
|
29336
29623
|
}
|
|
29337
29624
|
/**
|
|
@@ -29504,7 +29791,8 @@ var testOf = (p, federationNetwork) => {
|
|
|
29504
29791
|
};
|
|
29505
29792
|
/**
|
|
29506
29793
|
* What this device says about one of its own payments in a group, or null when it says nothing (not a group's,
|
|
29507
|
-
* or nothing to say yet). `all` is
|
|
29794
|
+
* or nothing to say yet). `all` is the desk records to find a request's payments in (and whether this device paid it):
|
|
29795
|
+
* every record, or only that request's.
|
|
29508
29796
|
*/
|
|
29509
29797
|
function authoredNote(p, at, all, current, memberOf = () => void 0, federationNetwork = () => void 0) {
|
|
29510
29798
|
const base = {
|
|
@@ -29611,11 +29899,17 @@ var GroupPayments = class {
|
|
|
29611
29899
|
if (!known.has(groupId)) known.set(groupId, this.host.membership(groupId));
|
|
29612
29900
|
return known.get(groupId);
|
|
29613
29901
|
};
|
|
29902
|
+
const answers = /* @__PURE__ */ new Map();
|
|
29903
|
+
for (const x of all) if (x.requestId) {
|
|
29904
|
+
const list = answers.get(x.requestId);
|
|
29905
|
+
if (list) list.push(x);
|
|
29906
|
+
else answers.set(x.requestId, [x]);
|
|
29907
|
+
}
|
|
29614
29908
|
for (const p of all) {
|
|
29615
29909
|
const at = this.placement(p, membership);
|
|
29616
29910
|
if (!at) continue;
|
|
29617
29911
|
const current = (await this.load(at.groupId)).get(paymentWireId(p.id));
|
|
29618
|
-
const frame = authoredNote(p, at,
|
|
29912
|
+
const frame = authoredNote(p, at, answers.get(p.id) ?? [], current, (linkId) => this.host.edgeOf(linkId)?.member, (federation) => this.host.federationNetwork?.(federation));
|
|
29619
29913
|
if (!frame || JSON.stringify(frame) === JSON.stringify(current?.mine)) continue;
|
|
29620
29914
|
const merged = mergeGroupPay(current, frame, at.me, membership(at.groupId).members) ?? current;
|
|
29621
29915
|
if (!merged) continue;
|
|
@@ -29757,7 +30051,7 @@ var GroupEdits = class {
|
|
|
29757
30051
|
refused: true
|
|
29758
30052
|
});
|
|
29759
30053
|
const membership = this.host.membership(groupId);
|
|
29760
|
-
if (!membership) return refuse(
|
|
30054
|
+
if (!membership) return refuse(this.notMember(groupId));
|
|
29761
30055
|
if (typeof messageId !== "string" || typeof raw !== "string") return refuse("No message to edit");
|
|
29762
30056
|
const chat = chatOf(groupId);
|
|
29763
30057
|
const message = await this.find(chat, messageId);
|
|
@@ -29807,7 +30101,7 @@ var GroupEdits = class {
|
|
|
29807
30101
|
error,
|
|
29808
30102
|
refused: true
|
|
29809
30103
|
});
|
|
29810
|
-
if (!this.host.membership(groupId)) return refuse(
|
|
30104
|
+
if (!this.host.membership(groupId)) return refuse(this.notMember(groupId));
|
|
29811
30105
|
const chat = chatOf(groupId);
|
|
29812
30106
|
const message = typeof messageId === "string" ? await this.find(chat, messageId) : void 0;
|
|
29813
30107
|
if (!message || message.removed || message.sender !== "me" || !GROUP_MESSAGE_ID.test(message.id)) return refuse("Only your own messages can be deleted for everyone");
|
|
@@ -29825,6 +30119,10 @@ var GroupEdits = class {
|
|
|
29825
30119
|
messageId
|
|
29826
30120
|
};
|
|
29827
30121
|
}
|
|
30122
|
+
/** What an edit or a removal in a group I am not in is refused with: the group's reason, as a message or a reaction is. */
|
|
30123
|
+
notMember(groupId) {
|
|
30124
|
+
return this.host.notMember?.(groupId) ?? "You are not in this group";
|
|
30125
|
+
}
|
|
29828
30126
|
/** Says my pending edits in a group, oldest first, at the pace allowed; what waits goes when the window has room. */
|
|
29829
30127
|
flush(groupId) {
|
|
29830
30128
|
const running = this.flushing.get(groupId);
|
|
@@ -30615,6 +30913,14 @@ var REPUBLISH_MS = 36e5;
|
|
|
30615
30913
|
var HOLD_FETCH_MS = 2e4;
|
|
30616
30914
|
var HOLD_FETCH_BYTES_PER_S = 65536;
|
|
30617
30915
|
var holdFetchTimeoutMs = (max) => HOLD_FETCH_MS + Math.ceil(max / HOLD_FETCH_BYTES_PER_S) * 1e3;
|
|
30916
|
+
/** Why a pickup waits: its storage would see this device's address, which the person hides from contacts. */
|
|
30917
|
+
var HOLD_HIDDEN_IP = "Hide my IP from contacts is on: what your contact held for you waits on their storage until you turn it off.";
|
|
30918
|
+
/** Thrown where an address is about to be read, so a pickup stops there and starts again once it may. */
|
|
30919
|
+
var HiddenIpError = class extends Error {
|
|
30920
|
+
constructor() {
|
|
30921
|
+
super(HOLD_HIDDEN_IP);
|
|
30922
|
+
}
|
|
30923
|
+
};
|
|
30618
30924
|
var hex$2 = (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
30619
30925
|
/**
|
|
30620
30926
|
* Store-and-forward for away contacts (WISP 404, `hold/1`), on both ends of every chat that turned it
|
|
@@ -30640,6 +30946,11 @@ var HoldEngine = class {
|
|
|
30640
30946
|
/** A read the contact's word asked for, one waiting per chat, and when the last such read went out. */
|
|
30641
30947
|
peerPolls = /* @__PURE__ */ new Map();
|
|
30642
30948
|
lastPeerPoll = /* @__PURE__ */ new Map();
|
|
30949
|
+
/**
|
|
30950
|
+
* Per chat, the contact's item this device waits on (`seq`) because it came in a ratchet session this device never had,
|
|
30951
|
+
* and the manifest that listed it (its `seq`): it is fetched again only once the contact rewrites its manifest.
|
|
30952
|
+
*/
|
|
30953
|
+
waiting = /* @__PURE__ */ new Map();
|
|
30643
30954
|
constructor(host) {
|
|
30644
30955
|
this.host = host;
|
|
30645
30956
|
}
|
|
@@ -30697,6 +31008,8 @@ var HoldEngine = class {
|
|
|
30697
31008
|
/** Items can be held for this contact now: both switched it on, storage is set up and the contact is pinned. */
|
|
30698
31009
|
canHold(linkId) {
|
|
30699
31010
|
const hold = this.state(linkId);
|
|
31011
|
+
const ratchet = this.host.ratchet?.(linkId);
|
|
31012
|
+
if (ratchet && ratchet.box.heardAny && !ratchet.peerSupports()) return false;
|
|
30700
31013
|
return hold.enabled && !!hold.peerAllows && !!this.host.storage() && !!this.keysFor(linkId);
|
|
30701
31014
|
}
|
|
30702
31015
|
/** Ways of paying a request held for this contact may name: what its app allowed at the last session. */
|
|
@@ -30824,6 +31137,7 @@ var HoldEngine = class {
|
|
|
30824
31137
|
outSeq: seq,
|
|
30825
31138
|
outbox: [...hold.outbox, entry]
|
|
30826
31139
|
});
|
|
31140
|
+
await this.resealStale(linkId);
|
|
30827
31141
|
await this.upload(linkId, entry);
|
|
30828
31142
|
});
|
|
30829
31143
|
}
|
|
@@ -30838,11 +31152,38 @@ var HoldEngine = class {
|
|
|
30838
31152
|
await this.host.delivery(linkId, messageId, "held");
|
|
30839
31153
|
return;
|
|
30840
31154
|
}
|
|
31155
|
+
await this.resealStale(linkId);
|
|
30841
31156
|
await this.upload(linkId, entry);
|
|
30842
31157
|
}).then(() => found);
|
|
30843
31158
|
}
|
|
30844
31159
|
/** Seals and uploads one queued or failed entry, then the manifest and the pointer. */
|
|
30845
31160
|
async upload(linkId, entry) {
|
|
31161
|
+
await this.store(linkId, entry);
|
|
31162
|
+
try {
|
|
31163
|
+
await this.publishPointer(linkId, true);
|
|
31164
|
+
} catch (error) {
|
|
31165
|
+
return this.failEntry(linkId, entry, `Stored, but could not tell the contact where: ${error instanceof Error ? error.message : String(error)}`);
|
|
31166
|
+
}
|
|
31167
|
+
this.errors.delete(linkId);
|
|
31168
|
+
await this.host.delivery(linkId, entry.messageId, "held");
|
|
31169
|
+
this.host.changed();
|
|
31170
|
+
}
|
|
31171
|
+
async failEntry(linkId, entry, error) {
|
|
31172
|
+
await this.save(linkId, {
|
|
31173
|
+
...this.state(linkId),
|
|
31174
|
+
outbox: this.state(linkId).outbox.map((e) => e.seq === entry.seq ? {
|
|
31175
|
+
...e,
|
|
31176
|
+
state: "failed",
|
|
31177
|
+
error
|
|
31178
|
+
} : e)
|
|
31179
|
+
});
|
|
31180
|
+
this.errors.set(linkId, error);
|
|
31181
|
+
await this.host.delivery(linkId, entry.messageId, "failed", error);
|
|
31182
|
+
this.host.changed();
|
|
31183
|
+
throw new Error(error);
|
|
31184
|
+
}
|
|
31185
|
+
/** Seals one entry and puts it in storage under its name; the manifest and the pointer are the caller's. */
|
|
31186
|
+
async store(linkId, entry) {
|
|
30846
31187
|
const storage = this.host.storage(), keys = this.keysFor(linkId), hold = this.state(linkId);
|
|
30847
31188
|
const update = async (patch) => this.save(linkId, {
|
|
30848
31189
|
...this.state(linkId),
|
|
@@ -30851,16 +31192,7 @@ var HoldEngine = class {
|
|
|
30851
31192
|
...patch
|
|
30852
31193
|
} : e)
|
|
30853
31194
|
});
|
|
30854
|
-
const fail =
|
|
30855
|
-
await update({
|
|
30856
|
-
state: "failed",
|
|
30857
|
-
error
|
|
30858
|
-
});
|
|
30859
|
-
this.errors.set(linkId, error);
|
|
30860
|
-
await this.host.delivery(linkId, entry.messageId, "failed", error);
|
|
30861
|
-
this.host.changed();
|
|
30862
|
-
throw new Error(error);
|
|
30863
|
-
};
|
|
31195
|
+
const fail = (error) => this.failEntry(linkId, entry, error);
|
|
30864
31196
|
if (!storage || !keys || !hold.mailbox) return fail("Held messages need S3 storage (Profile → Backups) and a pinned contact.");
|
|
30865
31197
|
let body, meta;
|
|
30866
31198
|
try {
|
|
@@ -30907,17 +31239,23 @@ var HoldEngine = class {
|
|
|
30907
31239
|
} catch (error) {
|
|
30908
31240
|
return fail(error instanceof Error ? error.message : String(error));
|
|
30909
31241
|
}
|
|
30910
|
-
let bytes;
|
|
31242
|
+
let bytes, sid;
|
|
31243
|
+
const item = {
|
|
31244
|
+
mailbox: hold.mailbox,
|
|
31245
|
+
seq: entry.seq,
|
|
31246
|
+
id: entry.id,
|
|
31247
|
+
ts: entry.ts,
|
|
31248
|
+
kind: entry.kind,
|
|
31249
|
+
meta,
|
|
31250
|
+
expires: entry.expires
|
|
31251
|
+
};
|
|
31252
|
+
const ratchet = this.host.ratchet?.(linkId);
|
|
30911
31253
|
try {
|
|
30912
|
-
bytes = keys.
|
|
30913
|
-
|
|
30914
|
-
|
|
30915
|
-
|
|
30916
|
-
|
|
30917
|
-
kind: entry.kind,
|
|
30918
|
-
meta,
|
|
30919
|
-
expires: entry.expires
|
|
30920
|
-
}, body);
|
|
31254
|
+
bytes = ratchet && (ratchet.box.heardAny || ratchet.peerSupports()) ? await keys.sealRatcheted(item, body, (plaintext) => ratchet.box.lock(async (tx) => {
|
|
31255
|
+
const sealed = await tx.seal("hold", plaintext);
|
|
31256
|
+
sid = ratchetSessionOf(sealed, "hold");
|
|
31257
|
+
return sealed;
|
|
31258
|
+
})) : keys.seal(item, body);
|
|
30921
31259
|
} catch (error) {
|
|
30922
31260
|
return fail(error instanceof Error ? error.message : String(error));
|
|
30923
31261
|
}
|
|
@@ -30930,16 +31268,23 @@ var HoldEngine = class {
|
|
|
30930
31268
|
await update({
|
|
30931
31269
|
state: "held",
|
|
30932
31270
|
error: void 0,
|
|
30933
|
-
bytes: bytes.length
|
|
31271
|
+
bytes: bytes.length,
|
|
31272
|
+
sid
|
|
30934
31273
|
});
|
|
30935
|
-
|
|
30936
|
-
|
|
30937
|
-
|
|
30938
|
-
|
|
30939
|
-
|
|
30940
|
-
|
|
30941
|
-
|
|
30942
|
-
|
|
31274
|
+
}
|
|
31275
|
+
/**
|
|
31276
|
+
* WISP 4xx § Held items, "A contact that started anew": the items still held that were sealed in a session other than
|
|
31277
|
+
* the one the chat's ratchet seals with now are sealed again in it, under the same sequence, id and name. The contact
|
|
31278
|
+
* moved to another device or restored, its floor envelope made its new session current here, and its new device never
|
|
31279
|
+
* had the old one: it leaves those items unopened, unacknowledged, until they come in a session it has. True when
|
|
31280
|
+
* something was sealed again: the manifest and the pointer are the caller's.
|
|
31281
|
+
*/
|
|
31282
|
+
async resealStale(linkId) {
|
|
31283
|
+
const current = this.host.ratchet?.(linkId)?.box.session;
|
|
31284
|
+
if (!current || !this.host.storage()) return false;
|
|
31285
|
+
const stale = this.state(linkId).outbox.filter((e) => e.state === "held" && e.sid && e.sid !== current);
|
|
31286
|
+
for (const entry of stale) await this.store(linkId, entry).catch(() => {});
|
|
31287
|
+
return stale.length > 0;
|
|
30943
31288
|
}
|
|
30944
31289
|
/** A message deleted here: its held item goes too, so the contact never picks it up. */
|
|
30945
31290
|
forget(linkId, messageId) {
|
|
@@ -30977,6 +31322,7 @@ var HoldEngine = class {
|
|
|
30977
31322
|
this.errors.delete(linkId);
|
|
30978
31323
|
this.chains.delete(linkId);
|
|
30979
31324
|
this.pointerDue.delete(linkId);
|
|
31325
|
+
this.waiting.delete(linkId);
|
|
30980
31326
|
clearTimeout(this.peerPolls.get(linkId));
|
|
30981
31327
|
this.peerPolls.delete(linkId);
|
|
30982
31328
|
this.lastPeerPoll.delete(linkId);
|
|
@@ -31102,9 +31448,10 @@ var HoldEngine = class {
|
|
|
31102
31448
|
this.host.changed();
|
|
31103
31449
|
}
|
|
31104
31450
|
for (const entry of hold.outbox.filter((e) => e.state === "queued")) await this.upload(linkId, entry).catch(() => {});
|
|
31451
|
+
const resealed = await this.resealStale(linkId);
|
|
31105
31452
|
hold = this.state(linkId);
|
|
31106
31453
|
const held = hold.outbox.some((e) => e.state === "held");
|
|
31107
|
-
if (this.host.storage() && (expired.length || held && (hold.manifestSignedAt ?? 0) + RENEW_AFTER_MS <= now)) await this.publishPointer(linkId, true).catch((error) => this.errors.set(linkId, String(error instanceof Error ? error.message : error)));
|
|
31454
|
+
if (this.host.storage() && (expired.length || resealed || held && (hold.manifestSignedAt ?? 0) + RENEW_AFTER_MS <= now)) await this.publishPointer(linkId, true).catch((error) => this.errors.set(linkId, String(error instanceof Error ? error.message : error)));
|
|
31108
31455
|
else if (this.pointerDue.has(linkId) || held && (this.lastPublish.get(linkId) ?? 0) + REPUBLISH_MS <= now) await this.publishPointer(linkId, false).catch(() => {});
|
|
31109
31456
|
}
|
|
31110
31457
|
/**
|
|
@@ -31156,8 +31503,11 @@ var HoldEngine = class {
|
|
|
31156
31503
|
...hold,
|
|
31157
31504
|
peerAck: pointer.ack
|
|
31158
31505
|
});
|
|
31506
|
+
const wasHidden = this.errors.get(linkId) === HOLD_HIDDEN_IP;
|
|
31507
|
+
if (wasHidden) this.errors.delete(linkId);
|
|
31159
31508
|
if (pointer.top <= hold.inSeq) {
|
|
31160
31509
|
this.expecting.delete(linkId);
|
|
31510
|
+
if (wasHidden) this.host.changed();
|
|
31161
31511
|
return;
|
|
31162
31512
|
}
|
|
31163
31513
|
if (!pointer.manifestUrl || pointer.expires <= now) {
|
|
@@ -31165,7 +31515,7 @@ var HoldEngine = class {
|
|
|
31165
31515
|
this.host.changed();
|
|
31166
31516
|
return;
|
|
31167
31517
|
}
|
|
31168
|
-
let entries, mailbox;
|
|
31518
|
+
let entries, mailbox, manifestRev;
|
|
31169
31519
|
try {
|
|
31170
31520
|
const manifest = keys.open(await this.fetchBytes(pointer.manifestUrl, HOLD_LIMITS.maxManifestBytes), {
|
|
31171
31521
|
maxBytes: HOLD_LIMITS.maxManifestBytes,
|
|
@@ -31174,6 +31524,7 @@ var HoldEngine = class {
|
|
|
31174
31524
|
});
|
|
31175
31525
|
if (manifest.header.kind !== "manifest") throw new HoldRefusedError("format", "Not a manifest");
|
|
31176
31526
|
mailbox = manifest.header.mailbox;
|
|
31527
|
+
manifestRev = manifest.header.seq;
|
|
31177
31528
|
entries = readManifest(manifest.header.meta, this.host.loopbackStorage?.()).filter(([seq]) => seq > this.state(linkId).inSeq).sort((a, b) => a[0] - b[0]);
|
|
31178
31529
|
} catch (error) {
|
|
31179
31530
|
if (error instanceof HoldRefusedError) {
|
|
@@ -31182,11 +31533,13 @@ var HoldEngine = class {
|
|
|
31182
31533
|
refused: this.state(linkId).refused + 1
|
|
31183
31534
|
});
|
|
31184
31535
|
this.errors.set(linkId, `Refused what the contact's storage offered: ${error.message}`);
|
|
31185
|
-
} else this.errors.set(linkId,
|
|
31536
|
+
} else if (error instanceof HiddenIpError) this.errors.set(linkId, HOLD_HIDDEN_IP);
|
|
31537
|
+
else this.errors.set(linkId, `Could not pick up held items: ${error instanceof Error ? error.message : String(error)}`);
|
|
31186
31538
|
this.host.changed();
|
|
31187
31539
|
return;
|
|
31188
31540
|
}
|
|
31189
31541
|
let changed = false, stop = false;
|
|
31542
|
+
if ((this.waiting.get(linkId)?.seq ?? Infinity) <= this.state(linkId).inSeq) this.waiting.delete(linkId);
|
|
31190
31543
|
for (const [seq, id, kind, bytes, url, expires] of entries) {
|
|
31191
31544
|
if (stop) break;
|
|
31192
31545
|
if (expires <= now) {
|
|
@@ -31197,12 +31550,30 @@ var HoldEngine = class {
|
|
|
31197
31550
|
changed = true;
|
|
31198
31551
|
continue;
|
|
31199
31552
|
}
|
|
31553
|
+
const waiting = this.waiting.get(linkId);
|
|
31554
|
+
if (waiting?.seq === seq && waiting.manifest === manifestRev) {
|
|
31555
|
+
stop = true;
|
|
31556
|
+
break;
|
|
31557
|
+
}
|
|
31558
|
+
const ratchet = this.host.ratchet?.(linkId);
|
|
31559
|
+
let ratcheted, fetched, unknownSession = false;
|
|
31200
31560
|
try {
|
|
31201
|
-
|
|
31561
|
+
fetched = await this.fetchBytes(url, Math.min(bytes, HOLD_LIMITS.maxBundleBytes));
|
|
31562
|
+
const opened = keys.open(fetched, {
|
|
31202
31563
|
maxBytes: HOLD_LIMITS.maxBundleBytes,
|
|
31203
31564
|
now,
|
|
31204
|
-
mailbox
|
|
31565
|
+
mailbox,
|
|
31566
|
+
...ratchet && {
|
|
31567
|
+
ratchet: (sealed) => {
|
|
31568
|
+
const plain = ratchet.box.peek("hold", sealed);
|
|
31569
|
+
unknownSession = !plain && ratchet.box.unknownSession("hold", sealed);
|
|
31570
|
+
return plain;
|
|
31571
|
+
},
|
|
31572
|
+
refusePlain: ratchet.box.heard("hold")
|
|
31573
|
+
}
|
|
31205
31574
|
});
|
|
31575
|
+
const { header, body } = opened;
|
|
31576
|
+
ratcheted = opened.ratcheted;
|
|
31206
31577
|
if (header.seq !== seq || header.id !== id || header.kind !== kind) throw new HoldRefusedError("format", "The item does not match the manifest");
|
|
31207
31578
|
const held = {
|
|
31208
31579
|
seq,
|
|
@@ -31265,13 +31636,29 @@ var HoldEngine = class {
|
|
|
31265
31636
|
network: frame.n
|
|
31266
31637
|
});
|
|
31267
31638
|
}
|
|
31639
|
+
if (ratcheted && ratchet) await ratchet.box.commitOpen("hold", ratcheted);
|
|
31268
31640
|
hold = await this.save(linkId, {
|
|
31269
31641
|
...this.state(linkId),
|
|
31270
31642
|
inSeq: seq
|
|
31271
31643
|
});
|
|
31272
31644
|
changed = true;
|
|
31273
31645
|
} catch (error) {
|
|
31274
|
-
|
|
31646
|
+
const opened = ratcheted ?? (error instanceof HoldRefusedError ? error.ratcheted : void 0);
|
|
31647
|
+
if (error instanceof HoldRefusedError && opened && ratchet) await ratchet.box.commitOpen("hold", opened).catch(() => {});
|
|
31648
|
+
if (error instanceof HoldRefusedError && error.reason === "tampered" && fetched?.[4] === 2 && await this.host.taken?.(linkId, id)) {
|
|
31649
|
+
await this.save(linkId, {
|
|
31650
|
+
...this.state(linkId),
|
|
31651
|
+
inSeq: seq
|
|
31652
|
+
});
|
|
31653
|
+
changed = true;
|
|
31654
|
+
} else if (error instanceof HoldRefusedError && error.reason === "tampered" && unknownSession) {
|
|
31655
|
+
this.waiting.set(linkId, {
|
|
31656
|
+
seq,
|
|
31657
|
+
manifest: manifestRev
|
|
31658
|
+
});
|
|
31659
|
+
this.errors.set(linkId, "Could not pick up held items: the contact's app sealed them for the device this profile was on before. They come once it seals them again for this one.");
|
|
31660
|
+
stop = true;
|
|
31661
|
+
} else if (error instanceof HoldRefusedError) {
|
|
31275
31662
|
await this.save(linkId, {
|
|
31276
31663
|
...this.state(linkId),
|
|
31277
31664
|
inSeq: seq,
|
|
@@ -31281,7 +31668,7 @@ var HoldEngine = class {
|
|
|
31281
31668
|
this.errors.set(linkId, `Refused a held item from the contact: ${error.message}`);
|
|
31282
31669
|
changed = true;
|
|
31283
31670
|
} else {
|
|
31284
|
-
this.errors.set(linkId, `Could not pick up held items: ${error instanceof Error ? error.message : String(error)}`);
|
|
31671
|
+
this.errors.set(linkId, error instanceof HiddenIpError ? HOLD_HIDDEN_IP : `Could not pick up held items: ${error instanceof Error ? error.message : String(error)}`);
|
|
31285
31672
|
stop = true;
|
|
31286
31673
|
}
|
|
31287
31674
|
}
|
|
@@ -31317,6 +31704,8 @@ var HoldEngine = class {
|
|
|
31317
31704
|
}
|
|
31318
31705
|
async readBytes(url, max, signal) {
|
|
31319
31706
|
if (!isHoldUrl(url, this.host.loopbackStorage?.())) throw new Error("The storage address is not one this app reads");
|
|
31707
|
+
const hosts = this.host.hiddenIpHosts?.();
|
|
31708
|
+
if (hosts && !hosts.includes(new URL(url).host.toLowerCase())) throw new HiddenIpError();
|
|
31320
31709
|
const response = await (this.host.fetch ?? ((...args) => fetch(...args)))(url, {
|
|
31321
31710
|
cache: "no-store",
|
|
31322
31711
|
credentials: "omit",
|
|
@@ -32187,7 +32576,8 @@ var ProfilePeek = class {
|
|
|
32187
32576
|
},
|
|
32188
32577
|
state: link.dhtDeliveryState,
|
|
32189
32578
|
transport: readOnly,
|
|
32190
|
-
background: true
|
|
32579
|
+
background: true,
|
|
32580
|
+
ratchet: link.ratchetState
|
|
32191
32581
|
});
|
|
32192
32582
|
let held = 0;
|
|
32193
32583
|
if (holdable(link)) {
|
|
@@ -32460,26 +32850,6 @@ var S3Store = class {
|
|
|
32460
32850
|
}
|
|
32461
32851
|
};
|
|
32462
32852
|
//#endregion
|
|
32463
|
-
//#region ../browser/src/shared/refusals.ts
|
|
32464
|
-
/** The English line for `notice`, stored as the row's `text`. */
|
|
32465
|
-
function refusedText(notice) {
|
|
32466
|
-
return `Could not receive ${notice.method === "fedimint" ? "Fedimint ecash" : notice.amount === void 0 ? "a payment" : `${notice.amount.toLocaleString("en-US")} ${notice.network === "testnet" ? "test sats" : "sats"}`}: ${notice.reason}`;
|
|
32467
|
-
}
|
|
32468
|
-
/** The row the engine stores for a refusal: the values, and their English as the text. */
|
|
32469
|
-
function refusedRow(notice) {
|
|
32470
|
-
const values = {
|
|
32471
|
-
type: "paymentRefused",
|
|
32472
|
-
...notice.amount !== void 0 && { amount: notice.amount },
|
|
32473
|
-
...notice.network && { network: notice.network },
|
|
32474
|
-
...notice.method && { method: notice.method },
|
|
32475
|
-
reason: notice.reason
|
|
32476
|
-
};
|
|
32477
|
-
return {
|
|
32478
|
-
text: refusedText(values),
|
|
32479
|
-
notice: values
|
|
32480
|
-
};
|
|
32481
|
-
}
|
|
32482
|
-
//#endregion
|
|
32483
32853
|
//#region ../browser/src/engine/wallet.ts
|
|
32484
32854
|
/**
|
|
32485
32855
|
* The peer's Cashu wallet. Ecash is custodial: the mint holds the sats and the
|
|
@@ -32495,7 +32865,30 @@ function refusedRow(notice) {
|
|
|
32495
32865
|
* asked for again (NUT-09) at any time.
|
|
32496
32866
|
*/
|
|
32497
32867
|
var UNIT$1 = "sat";
|
|
32498
|
-
|
|
32868
|
+
/**
|
|
32869
|
+
* cdk-mintd 0.17 writes NUT-05's `amountless` beside the method, not under its `options` as 0.18 does, and cashu-ts reads
|
|
32870
|
+
* `options` only: such a mint would be taken for one that refuses an invoice with no amount, and never sent the amount.
|
|
32871
|
+
*/
|
|
32872
|
+
var saysAmountlessBeside = (method) => method.amountless === true;
|
|
32873
|
+
function amountlessUnderOptions(info) {
|
|
32874
|
+
const moved = info.nuts[5].methods.map((method) => saysAmountlessBeside(method) ? {
|
|
32875
|
+
...method,
|
|
32876
|
+
options: {
|
|
32877
|
+
...method.options,
|
|
32878
|
+
amountless: true
|
|
32879
|
+
}
|
|
32880
|
+
} : method);
|
|
32881
|
+
return {
|
|
32882
|
+
...info,
|
|
32883
|
+
nuts: {
|
|
32884
|
+
...info.nuts,
|
|
32885
|
+
5: {
|
|
32886
|
+
...info.nuts[5],
|
|
32887
|
+
methods: moved
|
|
32888
|
+
}
|
|
32889
|
+
}
|
|
32890
|
+
};
|
|
32891
|
+
}
|
|
32499
32892
|
/** A Lightning payment can stay in flight for minutes or hours; the mint is asked again this often. */
|
|
32500
32893
|
var MELT_POLL_MS = 3e4;
|
|
32501
32894
|
var MAX_AMOUNT = 1e6;
|
|
@@ -32512,6 +32905,8 @@ var SWAP_SLOW_POLL_MS = 6e5;
|
|
|
32512
32905
|
var SWAP_WATCH_MS = 36e5;
|
|
32513
32906
|
/** How many proofs of tokens refused as spent are remembered. */
|
|
32514
32907
|
var SPENT_KEPT = 1e3;
|
|
32908
|
+
/** The most coins `sendCoins` makes for one token. */
|
|
32909
|
+
var MAX_SEND_COINS = 64;
|
|
32515
32910
|
/** Cashu's library (174 KiB) loads with the wallet's first use of a mint or a token, not with the app's start. */
|
|
32516
32911
|
var loadCashu = () => import("@cashu/cashu-ts");
|
|
32517
32912
|
async function reviewedCashuFee(preview) {
|
|
@@ -32549,7 +32944,7 @@ function normalizeMintUrl(input) {
|
|
|
32549
32944
|
}
|
|
32550
32945
|
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
|
32551
32946
|
if (url.protocol !== "https:" && !(local && url.protocol === "http:")) throw engineError("mintNotHttps");
|
|
32552
|
-
return
|
|
32947
|
+
return mintUrlSpelling(url.href);
|
|
32553
32948
|
}
|
|
32554
32949
|
function assertAmount(amount) {
|
|
32555
32950
|
if (!Number.isSafeInteger(amount) || amount <= 0) throw new Error("Enter an amount in sats");
|
|
@@ -32559,6 +32954,84 @@ function assertAmount(amount) {
|
|
|
32559
32954
|
var asProofLike = (proofs) => proofs;
|
|
32560
32955
|
var total = (proofs) => proofs.reduce((sum, p) => sum + p.amount, 0);
|
|
32561
32956
|
var sats = (proofs) => total(proofs.map((p) => ({ amount: p.amount.toNumber() })));
|
|
32957
|
+
/**
|
|
32958
|
+
* Whether `split` can take `amount` out of `proofs`, as it does: coins that add up exactly with the fee their receiver
|
|
32959
|
+
* pays to redeem them, or a swap whose inputs also pay the mint's fee for taking them in. Asks nothing of the mint.
|
|
32960
|
+
*/
|
|
32961
|
+
/** Whether exact coins go as one token a payment frame carries: a wallet of many small coins can add up in hundreds. */
|
|
32962
|
+
var inOneFrame = (encode, mint) => (send) => encode({
|
|
32963
|
+
mint,
|
|
32964
|
+
proofs: send,
|
|
32965
|
+
unit: UNIT$1
|
|
32966
|
+
}).length <= LIMITS.maxPaymentEndpointChars;
|
|
32967
|
+
/**
|
|
32968
|
+
* The coins a swap makes to send `amount` with the fee their receiver pays to redeem them: the fewest sats whose coins,
|
|
32969
|
+
* less that fee, are exactly `amount`. cashu-ts' includeFees adds coins for the fee that can be worth more than it, and
|
|
32970
|
+
* the contact is credited more than was sent. Undefined at a mint that charges nothing for coins, or when no such
|
|
32971
|
+
* coins are found up to what cashu-ts would make: its own choice is used then.
|
|
32972
|
+
*/
|
|
32973
|
+
function sendCoins(wallet, amount) {
|
|
32974
|
+
const included = wallet.getFeesToInclude(amount).toNumber();
|
|
32975
|
+
if (included === 0) return void 0;
|
|
32976
|
+
const keyset = wallet.getKeyset();
|
|
32977
|
+
const fee = (coins) => wallet.getFeesForKeyset(coins, keyset.id).toNumber();
|
|
32978
|
+
const sizes = Object.keys(keyset.keys).map(Number).filter((size) => size > 0).sort((a, b) => b - a);
|
|
32979
|
+
const coinsOf = (value, among = sizes) => {
|
|
32980
|
+
const coins = [];
|
|
32981
|
+
for (const size of among) while (value >= size) {
|
|
32982
|
+
coins.push(size);
|
|
32983
|
+
value -= size;
|
|
32984
|
+
}
|
|
32985
|
+
return value === 0 ? coins : void 0;
|
|
32986
|
+
};
|
|
32987
|
+
for (let value = amount; value <= amount + included; value++) {
|
|
32988
|
+
let coins = coinsOf(value);
|
|
32989
|
+
while (coins && coins.length <= MAX_SEND_COINS && fee(coins.length) < value - amount) {
|
|
32990
|
+
const [largest, ...rest] = coins;
|
|
32991
|
+
const parts = coinsOf(largest, sizes.filter((size) => size < largest));
|
|
32992
|
+
coins = parts && [...parts, ...rest].sort((a, b) => b - a);
|
|
32993
|
+
}
|
|
32994
|
+
if (coins && coins.length <= MAX_SEND_COINS && fee(coins.length) === value - amount) return coins;
|
|
32995
|
+
}
|
|
32996
|
+
}
|
|
32997
|
+
function fitsAt(wallet, proofs, amount) {
|
|
32998
|
+
return outlayAt(wallet, proofs, amount) !== void 0;
|
|
32999
|
+
}
|
|
33000
|
+
/**
|
|
33001
|
+
* The sats `split` takes out of the wallet for `amount`, the mint's fees for the coins it takes in included, as `fitsAt`
|
|
33002
|
+
* works it out: undefined when it cannot. `inOneFrame`: whether exact coins fit in one token, as `split` asks of them.
|
|
33003
|
+
*/
|
|
33004
|
+
function outlayAt(wallet, proofs, amount, inOneFrame = (_send) => true) {
|
|
33005
|
+
try {
|
|
33006
|
+
const { send } = wallet.sendOffline(amount, asProofLike(proofs), {
|
|
33007
|
+
includeFees: true,
|
|
33008
|
+
exactMatch: true
|
|
33009
|
+
});
|
|
33010
|
+
if (send.length > 0 && sats(send) === amount + wallet.getFeesForProofs(send).toNumber() && inOneFrame(send)) return sats(send);
|
|
33011
|
+
} catch {}
|
|
33012
|
+
try {
|
|
33013
|
+
const coins = sendCoins(wallet, amount);
|
|
33014
|
+
const outputs = coins ? coins.reduce((sum, coin) => sum + coin, 0) : amount + wallet.getFeesToInclude(amount).toNumber();
|
|
33015
|
+
const { send } = wallet.selectProofsToSend(asProofLike(proofs), outputs, true);
|
|
33016
|
+
const taken = outputs + wallet.getFeesForProofs(send).toNumber();
|
|
33017
|
+
return send.length > 0 && sats(send) >= taken ? taken : void 0;
|
|
33018
|
+
} catch {
|
|
33019
|
+
return;
|
|
33020
|
+
}
|
|
33021
|
+
}
|
|
33022
|
+
/** The most `fitsAt` takes out of `proofs` with `extra` on top (a Lightning fee reserve): 0 when nothing fits. */
|
|
33023
|
+
function roomAt(wallet, proofs, extra = 0) {
|
|
33024
|
+
const most = total(proofs) - wallet.getFeesForProofs(asProofLike(proofs)).toNumber() - extra;
|
|
33025
|
+
if (most <= 0 || fitsAt(wallet, proofs, most + extra)) return Math.max(0, most);
|
|
33026
|
+
let low = 0;
|
|
33027
|
+
let high = most - 1;
|
|
33028
|
+
while (low < high) {
|
|
33029
|
+
const middle = Math.ceil((low + high) / 2);
|
|
33030
|
+
if (fitsAt(wallet, proofs, middle + extra)) low = middle;
|
|
33031
|
+
else high = middle - 1;
|
|
33032
|
+
}
|
|
33033
|
+
return low;
|
|
33034
|
+
}
|
|
32562
33035
|
var MINT_QUOTE_MISMATCH = "The mint quoted another amount than this invoice's. Nothing was paid.";
|
|
32563
33036
|
/** A melt quote that is not for this invoice (`invoice` lower case, as `decodeBolt11` gives it) and its amount. */
|
|
32564
33037
|
var quoteMismatch = (quote, invoice, amount) => quote.request.trim().toLowerCase().replace(/^lightning:/, "") !== invoice || quote.amount.toNumber() !== amount;
|
|
@@ -32585,6 +33058,8 @@ var walletTx = (mint, kind, amount, fee, note) => ({
|
|
|
32585
33058
|
});
|
|
32586
33059
|
/** What a failed payment left in the wallet, said to the person: all of it, or all but the fee the mint kept. */
|
|
32587
33060
|
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.";
|
|
33061
|
+
/** A mint's own words for a refusal, as one short line: the reason at the end of `lightningRefused`. */
|
|
33062
|
+
var mintReason = (error) => (error instanceof Error ? error.message : String(error)).replace(/\s+/g, " ").trim().slice(0, 160) || "no reason given";
|
|
32588
33063
|
/**
|
|
32589
33064
|
* How long a mint gets to answer when it is only being asked something (its keys, an invoice). A mint
|
|
32590
33065
|
* that is down can hold a request for minutes; the next mint should get its turn well before that.
|
|
@@ -32606,6 +33081,12 @@ var CashuWallet = class CashuWallet {
|
|
|
32606
33081
|
infos = /* @__PURE__ */ new Map();
|
|
32607
33082
|
locks = /* @__PURE__ */ new Map();
|
|
32608
33083
|
quoteTimer = null;
|
|
33084
|
+
/** When `quoteTimer` fires: a round that would fire later leaves it as it is. */
|
|
33085
|
+
quoteTimerAt = 0;
|
|
33086
|
+
/** Per open quote: when its mint was last asked about it, in this run (`nextInvoiceAsk`). */
|
|
33087
|
+
quoteAsked = /* @__PURE__ */ new Map();
|
|
33088
|
+
/** Per quote the screen shows: until when (`watch`). */
|
|
33089
|
+
quoteWatched = /* @__PURE__ */ new Map();
|
|
32609
33090
|
meltTimer = null;
|
|
32610
33091
|
restoredTimer = null;
|
|
32611
33092
|
swapTimer = null;
|
|
@@ -32619,7 +33100,8 @@ var CashuWallet = class CashuWallet {
|
|
|
32619
33100
|
* so the same token sent again, under any id or encoding, is refused without asking the mint again.
|
|
32620
33101
|
*/
|
|
32621
33102
|
spentTokens = /* @__PURE__ */ new Set();
|
|
32622
|
-
/** Per melt quote shown to the person: the invoice, its amount and the
|
|
33103
|
+
/** Per melt quote shown to the person: the invoice, its amount and the most it was said to cost in fees
|
|
33104
|
+
* (the mint's reserve and the coins' own fees). Only these are paid, for no more. */
|
|
32623
33105
|
shownQuotes = /* @__PURE__ */ new Map();
|
|
32624
33106
|
/**
|
|
32625
33107
|
* `getMints`: the mints of one network (the engine's default when none is named), primary first: balances,
|
|
@@ -32802,10 +33284,23 @@ var CashuWallet = class CashuWallet {
|
|
|
32802
33284
|
...paysItsOwnInvoices(mint) ? { held: true } : {}
|
|
32803
33285
|
};
|
|
32804
33286
|
await committed((await store(STORES$1.quotes, "readwrite")).put(quote));
|
|
33287
|
+
this.quoteAsked.set(quote.quote, Date.now());
|
|
32805
33288
|
this.pollQuotes();
|
|
32806
33289
|
return quote;
|
|
32807
33290
|
}
|
|
32808
33291
|
/**
|
|
33292
|
+
* The screen shows this invoice of ours (Receive): it is asked about at the fast pace for `INVOICE_PACE.watchMs`, and
|
|
33293
|
+
* now if it was not just asked. The screen says it again while it shows it. Returns whether it is one of ours here.
|
|
33294
|
+
*/
|
|
33295
|
+
async watch(invoice) {
|
|
33296
|
+
const wanted = invoice.trim().toLowerCase();
|
|
33297
|
+
const quote = (await this.quotes()).find((q) => q.invoice.toLowerCase() === wanted);
|
|
33298
|
+
if (!quote) return false;
|
|
33299
|
+
this.quoteWatched.set(quote.quote, Date.now() + INVOICE_PACE.watchMs);
|
|
33300
|
+
await this.pollQuotes();
|
|
33301
|
+
return true;
|
|
33302
|
+
}
|
|
33303
|
+
/**
|
|
32809
33304
|
* A payer says it paid this invoice of ours (a contact's app, once its payment went through). A held quote (a test
|
|
32810
33305
|
* mint's, which reads paid by itself) is minted from now on; on any other mint the mint's own answer decides, as
|
|
32811
33306
|
* always. Returns whether the invoice is one of ours.
|
|
@@ -32818,7 +33313,8 @@ var CashuWallet = class CashuWallet {
|
|
|
32818
33313
|
...quote,
|
|
32819
33314
|
held: void 0
|
|
32820
33315
|
}));
|
|
32821
|
-
|
|
33316
|
+
this.quoteWatched.set(quote.quote, Date.now() + INVOICE_PACE.watchMs);
|
|
33317
|
+
await this.pollQuotes(true);
|
|
32822
33318
|
return true;
|
|
32823
33319
|
}
|
|
32824
33320
|
/** True while an invoice of ours waits for a payer's word (see `vouch`): whatever its mint says, it is not paid. */
|
|
@@ -32866,7 +33362,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32866
33362
|
* these mints (one network's wallet, before it is removed), claiming what is paid; the regular round is left alone.
|
|
32867
33363
|
*/
|
|
32868
33364
|
async checkQuotes(mints) {
|
|
32869
|
-
if (!mints) return this.pollQuotes();
|
|
33365
|
+
if (!mints) return this.pollQuotes(true);
|
|
32870
33366
|
const at = new Set(mints);
|
|
32871
33367
|
await this.settleQuotes((await this.quotes()).filter((q) => at.has(q.mint)));
|
|
32872
33368
|
}
|
|
@@ -32877,25 +33373,63 @@ var CashuWallet = class CashuWallet {
|
|
|
32877
33373
|
/**
|
|
32878
33374
|
* Invoices are paid by someone else, somewhere else; all we can do is ask the mint. A quote is the only
|
|
32879
33375
|
* claim on the sats paid to it, so it is dropped only once the mint says it is unpaid and it has expired.
|
|
33376
|
+
* Each quote is asked about at its own pace (`nextInvoiceAsk`): often while it is new or on screen, then less.
|
|
33377
|
+
* `now`: every open quote is asked about, whatever its pace (someone says it was paid). The store is read once.
|
|
32880
33378
|
*/
|
|
32881
|
-
async pollQuotes() {
|
|
33379
|
+
async pollQuotes(now = false) {
|
|
32882
33380
|
if (this.quoteTimer) clearTimeout(this.quoteTimer);
|
|
32883
33381
|
this.quoteTimer = null;
|
|
32884
33382
|
if (this.stopped) return;
|
|
32885
|
-
const quotes = await
|
|
32886
|
-
|
|
32887
|
-
|
|
32888
|
-
|
|
32889
|
-
|
|
33383
|
+
const quotes = await this.quotes();
|
|
33384
|
+
const gone = /* @__PURE__ */ new Set();
|
|
33385
|
+
for (const held of quotes.filter((q) => q.held && q.expiresAt && q.expiresAt + INVOICE_PACE.expiryGraceMs < Date.now())) {
|
|
33386
|
+
await committed((await store(STORES$1.quotes, "readwrite")).delete(held.quote));
|
|
33387
|
+
gone.add(held.quote);
|
|
33388
|
+
}
|
|
33389
|
+
const stored = new Set(quotes.map((q) => q.quote));
|
|
33390
|
+
for (const pace of [this.quoteAsked, this.quoteWatched]) for (const id of pace.keys()) if (!stored.has(id)) pace.delete(id);
|
|
33391
|
+
const open = quotes.filter((q) => !q.issuedUnclaimed && !q.held);
|
|
33392
|
+
const at = Date.now();
|
|
33393
|
+
for (const settled of await this.settleQuotes(open.filter((q) => now || this.nextAsk(q, at) <= at + INVOICE_PACE.dueSlackMs))) gone.add(settled);
|
|
33394
|
+
const next = open.filter((q) => !gone.has(q.quote)).map((q) => this.nextAsk(q, Date.now()));
|
|
33395
|
+
if (next.length) this.scheduleQuotes(Math.min(...next));
|
|
33396
|
+
}
|
|
33397
|
+
/** When the mint is next asked about this quote. */
|
|
33398
|
+
nextAsk(quote, now) {
|
|
33399
|
+
return nextInvoiceAsk({
|
|
33400
|
+
createdAt: quote.createdAt,
|
|
33401
|
+
expiresAt: quote.expiresAt,
|
|
33402
|
+
watchedUntil: this.quoteWatched.get(quote.quote),
|
|
33403
|
+
closed: !!quote.paymentId && !!this.events.requestClosed?.(quote.paymentId),
|
|
33404
|
+
paid: !!quote.paid
|
|
33405
|
+
}, this.quoteAsked.get(quote.quote), now);
|
|
33406
|
+
}
|
|
33407
|
+
/** The next round at `at`, unless one is due sooner. */
|
|
33408
|
+
scheduleQuotes(at) {
|
|
33409
|
+
if (this.stopped) return;
|
|
33410
|
+
if (this.quoteTimer && this.quoteTimerAt <= at) return;
|
|
33411
|
+
if (this.quoteTimer) clearTimeout(this.quoteTimer);
|
|
33412
|
+
this.quoteTimerAt = at;
|
|
33413
|
+
this.quoteTimer = setTimeout(() => {
|
|
33414
|
+
this.quoteTimer = null;
|
|
33415
|
+
this.pollQuotes();
|
|
33416
|
+
}, Math.max(0, at - Date.now()));
|
|
32890
33417
|
}
|
|
33418
|
+
/** Asks the mints about these quotes. Returns the ones minted. */
|
|
32891
33419
|
async settleQuotes(quotes) {
|
|
32892
|
-
|
|
32893
|
-
|
|
32894
|
-
|
|
32895
|
-
|
|
32896
|
-
this.
|
|
32897
|
-
|
|
32898
|
-
|
|
33420
|
+
const minted = [];
|
|
33421
|
+
for (const { quote, mint } of quotes.filter((q) => !q.issuedUnclaimed && !q.held)) {
|
|
33422
|
+
this.quoteAsked.set(quote, Date.now());
|
|
33423
|
+
try {
|
|
33424
|
+
const paid = await this.locked(mint, () => this.settleQuote(quote));
|
|
33425
|
+
if (paid) {
|
|
33426
|
+
minted.push(quote);
|
|
33427
|
+
if (!paid.testCoins) this.events.onQuotePaid(paid);
|
|
33428
|
+
this.events.onChange();
|
|
33429
|
+
}
|
|
33430
|
+
} catch {}
|
|
33431
|
+
}
|
|
33432
|
+
return minted;
|
|
32899
33433
|
}
|
|
32900
33434
|
/** Runs under the mint's lock, so two rounds never mint one quote twice. Returns the quote once its ecash is in. */
|
|
32901
33435
|
async settleQuote(id) {
|
|
@@ -32980,11 +33514,23 @@ var CashuWallet = class CashuWallet {
|
|
|
32980
33514
|
async createToken(amount, preferred, note, outbox, network) {
|
|
32981
33515
|
assertAmount(amount);
|
|
32982
33516
|
const mine = preferred ? this.getKnownMints() : this.getMints(network);
|
|
32983
|
-
const candidates = (preferred ? preferred.map(
|
|
33517
|
+
const candidates = (preferred ? preferred.map(mintUrlSpelling).filter((m) => mine.includes(m)) : mine).filter((m) => !network || mintNetwork(m) === network);
|
|
33518
|
+
/** The most a mint that holds the amount could send with its fees on top. */
|
|
33519
|
+
let room = 0;
|
|
33520
|
+
/** The coins held at `mint` when they send the amount. */
|
|
33521
|
+
const fitting = async (mint) => {
|
|
33522
|
+
const proofs = await this.proofsAt(mint);
|
|
33523
|
+
if (total(proofs) < amount) return void 0;
|
|
33524
|
+
const wallet = await this.wallet(mint);
|
|
33525
|
+
if (fitsAt(wallet, proofs, amount)) return proofs;
|
|
33526
|
+
room = Math.max(room, roomAt(wallet, proofs));
|
|
33527
|
+
};
|
|
32984
33528
|
for (const mint of candidates) {
|
|
32985
|
-
if (await
|
|
32986
|
-
|
|
32987
|
-
const
|
|
33529
|
+
if (!await fitting(mint)) continue;
|
|
33530
|
+
const sent = await this.locked(mint, async () => {
|
|
33531
|
+
const proofs = await fitting(mint);
|
|
33532
|
+
if (!proofs) return void 0;
|
|
33533
|
+
const { inputs, keep, send, swap } = await this.split(mint, amount, proofs);
|
|
32988
33534
|
const token = (await loadCashu()).getEncodedToken({
|
|
32989
33535
|
mint,
|
|
32990
33536
|
proofs: send,
|
|
@@ -33010,7 +33556,9 @@ var CashuWallet = class CashuWallet {
|
|
|
33010
33556
|
mint
|
|
33011
33557
|
};
|
|
33012
33558
|
});
|
|
33559
|
+
if (sent) return sent;
|
|
33013
33560
|
}
|
|
33561
|
+
if (room > 0) throw engineError("notEnoughForFee", { amount: room });
|
|
33014
33562
|
throw engineError(candidates.length === 0 && preferred ? "noSharedMint" : "notEnoughSats");
|
|
33015
33563
|
}
|
|
33016
33564
|
async prepareReviewedCashu(mint, amount) {
|
|
@@ -33269,7 +33817,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33269
33817
|
try {
|
|
33270
33818
|
if (/^cashu[AB]/i.test(value)) {
|
|
33271
33819
|
const metadata = getTokenMetadata(value);
|
|
33272
|
-
const mint = metadata.mint
|
|
33820
|
+
const mint = mintUrlSpelling(metadata.mint);
|
|
33273
33821
|
return {
|
|
33274
33822
|
kind: "token",
|
|
33275
33823
|
amount: Number(metadata.amount),
|
|
@@ -33285,7 +33833,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33285
33833
|
kind: "request",
|
|
33286
33834
|
amount: request.amount === void 0 ? null : Number(request.amount),
|
|
33287
33835
|
unit: request.unit ?? UNIT$1,
|
|
33288
|
-
mints: request.mints ?? [],
|
|
33836
|
+
mints: (request.mints ?? []).map(mintUrlSpelling),
|
|
33289
33837
|
description: request.description || void 0
|
|
33290
33838
|
};
|
|
33291
33839
|
}
|
|
@@ -33304,7 +33852,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33304
33852
|
try {
|
|
33305
33853
|
const metadata = getTokenMetadata(token);
|
|
33306
33854
|
unit = metadata.unit;
|
|
33307
|
-
mint = metadata.mint
|
|
33855
|
+
mint = mintUrlSpelling(metadata.mint);
|
|
33308
33856
|
faceValue = Number(metadata.amount);
|
|
33309
33857
|
} catch {
|
|
33310
33858
|
throw new Error("That is not a valid ecash token");
|
|
@@ -33332,6 +33880,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33332
33880
|
if (preview.inputs.some((p) => this.spentTokens.has(`${mint} ${p.secret}`))) throw engineError("ecashAlreadySpent");
|
|
33333
33881
|
const redeeming = new Set(written.flatMap((s) => (swapOf(s).inputs ?? []).map((p) => p.secret)));
|
|
33334
33882
|
if (preview.inputs.some((p) => redeeming.has(p.secret))) throw engineError("ecashBeingReceived");
|
|
33883
|
+
if (preview.amount.toNumber() <= 0) throw engineError("ecashFeeTakesAll", { amount: String(faceValue) });
|
|
33335
33884
|
swap = {
|
|
33336
33885
|
id: swapId(),
|
|
33337
33886
|
mint,
|
|
@@ -33382,17 +33931,17 @@ var CashuWallet = class CashuWallet {
|
|
|
33382
33931
|
includeFees: true,
|
|
33383
33932
|
exactMatch: true
|
|
33384
33933
|
});
|
|
33385
|
-
if (send.length > 0 && sats(send) === amount + wallet.getFeesForProofs(send).toNumber() && getEncodedToken({
|
|
33386
|
-
mint,
|
|
33387
|
-
proofs: send,
|
|
33388
|
-
unit: UNIT$1
|
|
33389
|
-
}).length <= LIMITS.maxPaymentEndpointChars) return {
|
|
33934
|
+
if (send.length > 0 && sats(send) === amount + wallet.getFeesForProofs(send).toNumber() && inOneFrame(getEncodedToken, mint)(send)) return {
|
|
33390
33935
|
inputs: among(send),
|
|
33391
33936
|
keep: [],
|
|
33392
33937
|
send
|
|
33393
33938
|
};
|
|
33394
33939
|
} catch {}
|
|
33395
|
-
const
|
|
33940
|
+
const coins = sendCoins(wallet, amount);
|
|
33941
|
+
const preview = coins ? await wallet.prepareSwapToSend(coins.reduce((sum, coin) => sum + coin, 0), asProofLike(proofs), {}, { send: {
|
|
33942
|
+
type: "random",
|
|
33943
|
+
denominations: coins
|
|
33944
|
+
} }) : await wallet.prepareSwapToSend(amount, asProofLike(proofs), { includeFees: true });
|
|
33396
33945
|
const swap = {
|
|
33397
33946
|
id: swapId(),
|
|
33398
33947
|
mint,
|
|
@@ -33748,40 +34297,51 @@ var CashuWallet = class CashuWallet {
|
|
|
33748
34297
|
});
|
|
33749
34298
|
if (again && !mints) this.swapsAgainIn(again);
|
|
33750
34299
|
}
|
|
33751
|
-
/**
|
|
33752
|
-
|
|
34300
|
+
/**
|
|
34301
|
+
* What paying this invoice would cost, from the first mint that can afford it. `chosen`: the sats the person typed for
|
|
34302
|
+
* an invoice with no amount, the only way one is paid (WISP 203); only a mint that says it takes one is asked.
|
|
34303
|
+
*/
|
|
34304
|
+
async quoteInvoice(invoice, network, chosen) {
|
|
33753
34305
|
let lastError = /* @__PURE__ */ new Error("Add a mint in Settings first");
|
|
33754
34306
|
let mints = this.getMints(network);
|
|
33755
34307
|
/** The most any mint asked could pay with its fee on top: a Max comes down to it. */
|
|
33756
34308
|
let room = 0;
|
|
33757
34309
|
const decoded = decodeBolt11(invoice);
|
|
33758
34310
|
if (!decoded) throw new Error("That is not an invoice this wallet can pay");
|
|
33759
|
-
if (decoded.amountSat === null) throw new Error("Invoices without an amount are not supported");
|
|
34311
|
+
if (decoded.amountSat === null && chosen === void 0) throw new Error("Invoices without an amount are not supported");
|
|
34312
|
+
if (decoded.amountSat !== null && chosen !== void 0) throw new Error(MINT_QUOTE_MISMATCH);
|
|
34313
|
+
if (chosen !== void 0) assertAmount(chosen);
|
|
34314
|
+
const expected = decoded.amountSat ?? chosen;
|
|
33760
34315
|
if (decoded.network === "bitcoin" && mints.some((mint) => mintNetwork(mint) === "testnet")) {
|
|
33761
34316
|
mints = mints.filter((mint) => mintNetwork(mint) === "mainnet" || fakesLightning(mint));
|
|
33762
34317
|
if (!mints.length) throw new Error(BITCOIN_INVOICE_ON_TESTNET);
|
|
33763
34318
|
}
|
|
34319
|
+
if (chosen !== void 0 && mints.length) lastError = engineError("mintsNoAnyAmount");
|
|
33764
34320
|
for (const mint of mints) try {
|
|
33765
|
-
const
|
|
34321
|
+
const wallet = await this.wallet(mint);
|
|
34322
|
+
if (chosen !== void 0 && !wallet.getMintInfo().supportsAmountless("bolt11", UNIT$1)) continue;
|
|
34323
|
+
const quote = chosen === void 0 ? await wallet.createMeltQuoteBolt11(invoice.trim()) : await wallet.createMeltQuoteBolt11(invoice.trim(), chosen * 1e3);
|
|
33766
34324
|
const amount = quote.amount.toNumber();
|
|
33767
34325
|
const feeReserve = quote.fee_reserve.toNumber();
|
|
33768
|
-
if (quoteMismatch(quote, decoded.invoice,
|
|
33769
|
-
const
|
|
33770
|
-
|
|
33771
|
-
|
|
34326
|
+
if (quoteMismatch(quote, decoded.invoice, expected)) throw new Error(MINT_QUOTE_MISMATCH);
|
|
34327
|
+
const proofs = await this.proofsAt(mint);
|
|
34328
|
+
const outlay = outlayAt(wallet, proofs, amount + feeReserve, inOneFrame((await loadCashu()).getEncodedToken, mint));
|
|
34329
|
+
if (outlay === void 0) {
|
|
34330
|
+
room = Math.max(room, roomAt(wallet, proofs, feeReserve));
|
|
33772
34331
|
lastError = room > 0 ? engineError("notEnoughForFee", { amount: room }) : engineError("notEnoughSats");
|
|
33773
34332
|
continue;
|
|
33774
34333
|
}
|
|
34334
|
+
const fee = outlay - amount;
|
|
33775
34335
|
this.shownQuotes.set(quote.quote, {
|
|
33776
34336
|
request: decoded.invoice,
|
|
33777
34337
|
amount,
|
|
33778
|
-
feeReserve
|
|
34338
|
+
feeReserve: fee
|
|
33779
34339
|
});
|
|
33780
34340
|
return {
|
|
33781
34341
|
quote: quote.quote,
|
|
33782
34342
|
mint,
|
|
33783
34343
|
amount,
|
|
33784
|
-
feeReserve
|
|
34344
|
+
feeReserve: fee
|
|
33785
34345
|
};
|
|
33786
34346
|
} catch (error) {
|
|
33787
34347
|
lastError = error;
|
|
@@ -33806,13 +34366,19 @@ var CashuWallet = class CashuWallet {
|
|
|
33806
34366
|
}
|
|
33807
34367
|
async melt(quoteId, mint, note, paymentId) {
|
|
33808
34368
|
const wallet = await this.wallet(mint);
|
|
33809
|
-
const { MeltChangeError, OutputData } = await loadCashu();
|
|
34369
|
+
const { MeltChangeError, OutputData, getEncodedToken } = await loadCashu();
|
|
33810
34370
|
const quote = await wallet.checkMeltQuoteBolt11(quoteId);
|
|
33811
34371
|
if ((await wrap((await store(STORES$1.melts, "readonly")).getAll())).some((m) => m.quote === quote.quote || m.request === quote.request)) throw new Error("This invoice is already being paid");
|
|
33812
34372
|
const shown = this.shownQuotes.get(quoteId);
|
|
33813
|
-
if (!shown || quote.quote !== quoteId || quoteMismatch(quote, shown.request, shown.amount) || quote.fee_reserve.toNumber() > shown.feeReserve) throw new Error(MINT_QUOTE_MISMATCH);
|
|
33814
34373
|
const needed = quote.amount.toNumber() + quote.fee_reserve.toNumber();
|
|
33815
|
-
const
|
|
34374
|
+
const proofs = await this.proofsAt(mint);
|
|
34375
|
+
const outlay = outlayAt(wallet, proofs, needed, inOneFrame(getEncodedToken, mint));
|
|
34376
|
+
if (!shown || quote.quote !== quoteId || quoteMismatch(quote, shown.request, shown.amount) || (outlay ?? needed) > shown.amount + shown.feeReserve) throw new Error(MINT_QUOTE_MISMATCH);
|
|
34377
|
+
if (outlay === void 0) {
|
|
34378
|
+
const room = roomAt(wallet, proofs, quote.fee_reserve.toNumber());
|
|
34379
|
+
throw room > 0 ? engineError("notEnoughForFee", { amount: room }) : engineError("notEnoughSats");
|
|
34380
|
+
}
|
|
34381
|
+
const { inputs, keep, send, swap } = await this.split(mint, needed, proofs);
|
|
33816
34382
|
let preview;
|
|
33817
34383
|
try {
|
|
33818
34384
|
preview = await wallet.prepareMelt("bolt11", quote, send);
|
|
@@ -33856,7 +34422,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33856
34422
|
const lost = this.takeFailedFee(melt.quote);
|
|
33857
34423
|
if (this.spentAway.delete(melt.quote)) throw Object.assign(engineError("ecashAlreadySpent"), { cause: error });
|
|
33858
34424
|
if (lost > 0) throw Object.assign(/* @__PURE__ */ new Error(`${error instanceof Error ? error.message : String(error)} ${backInWallet(lost)}`), { cause: error });
|
|
33859
|
-
throw error;
|
|
34425
|
+
throw Object.assign(engineError("lightningRefused", { reason: mintReason(error) }), { cause: error });
|
|
33860
34426
|
}
|
|
33861
34427
|
return outcome;
|
|
33862
34428
|
}
|
|
@@ -34029,6 +34595,8 @@ var CashuWallet = class CashuWallet {
|
|
|
34029
34595
|
wallet = (async () => {
|
|
34030
34596
|
const instance = new (await (loadCashu())).Wallet(mint, { unit: UNIT$1 });
|
|
34031
34597
|
await within(MINT_TIMEOUT_MS, instance.loadMint(), mint);
|
|
34598
|
+
const info = instance.getMintInfo();
|
|
34599
|
+
if (info.isSupported(5).params.some(saysAmountlessBeside)) instance.loadMintFromCache(amountlessUnderOptions(info.cache), instance.keyChain.cache);
|
|
34032
34600
|
return instance;
|
|
34033
34601
|
})();
|
|
34034
34602
|
this.wallets.set(mint, wallet);
|
|
@@ -37339,6 +37907,13 @@ var REACTION_RESEND_MS = 3e4;
|
|
|
37339
37907
|
var pkarrSeenAt = (messages) => messages.reduce((max, m) => m.sender === "peer" && m.via === "pkarr" ? Math.max(max, m.sentAt ?? m.timestamp) : max, 0);
|
|
37340
37908
|
/** A file or a payment request of mine that waits for the chat to be live (a text that waits is its outbox's). */
|
|
37341
37909
|
var waitsForLive = (m) => m.sender === "me" && m.delivery === "waiting" && (!!m.file || !!m.paymentId);
|
|
37910
|
+
/** A message of mine whose card went as its text alone and is due to go again live (`restoreCards`). */
|
|
37911
|
+
var cardDue = (m) => m.sender === "me" && (m.cardRestore ?? m.buttonsRestore) === "due";
|
|
37912
|
+
/** The id a 1:1 chat's row goes by on both sides when its own row is not `peer_`/`me_` and that id (`resolveReply`). */
|
|
37913
|
+
var unkeyedRef = (m) => {
|
|
37914
|
+
const ref = replyRef(m, false);
|
|
37915
|
+
return ref && m.id !== `peer_${ref}` && m.id !== `me_${ref}` ? ref : void 0;
|
|
37916
|
+
};
|
|
37342
37917
|
/** This side's participation key in a chat: derived from its seed once, not at every state built. */
|
|
37343
37918
|
/** A read of the contact's packet that found it as the last one did: online the same, the same packet, name and services. */
|
|
37344
37919
|
var samePresence = (a, b) => a.online === b.online && a.lastPacketAt === b.lastPacketAt && a.seenAt === b.seenAt && a.nick === b.nick && JSON.stringify(a.services) === JSON.stringify(b.services);
|
|
@@ -37585,6 +38160,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37585
38160
|
* Not one queue for all: a transport slow to start held every other chat's listeners of every kind behind it.
|
|
37586
38161
|
*/
|
|
37587
38162
|
nativeQueues = /* @__PURE__ */ new Map();
|
|
38163
|
+
/** Per transport, whether a start is under way, and the starts waiting their turn (`nativeTurn`). */
|
|
38164
|
+
nativeTurns = /* @__PURE__ */ new Map();
|
|
37588
38165
|
/** Every listener start asked for so far has ended. */
|
|
37589
38166
|
get nativeQueue() {
|
|
37590
38167
|
return Promise.all(this.nativeQueues.values()).then(() => {});
|
|
@@ -37918,8 +38495,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37918
38495
|
mint: melt.mint
|
|
37919
38496
|
}),
|
|
37920
38497
|
onTestMintNeeded: async (mint) => void await this.walletAddMint({ url: mint }),
|
|
37921
|
-
onSwapSettled: (swap, done) => this.desk.onSwapSettled(swap, done).then(() => swap.payment?.direction === "out" ? this.reviewTakenBack(swap.payment.id) : void 0)
|
|
38498
|
+
onSwapSettled: (swap, done) => this.desk.onSwapSettled(swap, done).then(() => swap.payment?.direction === "out" ? this.reviewTakenBack(swap.payment.id) : void 0),
|
|
38499
|
+
requestClosed: (paymentId) => this.requestClosed(paymentId)
|
|
37922
38500
|
}, () => this.settings.mints);
|
|
38501
|
+
/** A chat request of ours that nobody is meant to pay any more: its invoice is asked about only once it expired. */
|
|
38502
|
+
requestClosed(paymentId) {
|
|
38503
|
+
const request = this.desk.payment(paymentId);
|
|
38504
|
+
return request?.kind === "request" && request.direction === "out" && request.state !== "pending";
|
|
38505
|
+
}
|
|
37923
38506
|
registry;
|
|
37924
38507
|
providers() {
|
|
37925
38508
|
return this.registry ??= this.options.providers ?? defaultRegistry();
|
|
@@ -37946,7 +38529,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37946
38529
|
events: {
|
|
37947
38530
|
changed: () => this.walletChanged(),
|
|
37948
38531
|
received: (op) => void this.desk.onLightningPaid(op),
|
|
37949
|
-
resolved: (op, paid) => void this.desk.onLightningResolved(op, paid)
|
|
38532
|
+
resolved: (op, paid) => void this.desk.onLightningResolved(op, paid),
|
|
38533
|
+
requestClosed: (paymentId) => this.requestClosed(paymentId)
|
|
37950
38534
|
}
|
|
37951
38535
|
}));
|
|
37952
38536
|
/** On-chain Bitcoin of each network, through its active source: none until the person sets one up. */
|
|
@@ -38217,17 +38801,33 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38217
38801
|
return null;
|
|
38218
38802
|
},
|
|
38219
38803
|
receivePaymentRequest: (linkId, request) => this.desk.onPaymentRequest(linkId, request, true),
|
|
38804
|
+
taken: (linkId, id) => db.hasMessage(linkId, `peer_${id}`),
|
|
38220
38805
|
changed: () => this.emitState(),
|
|
38221
38806
|
fetch: (...request) => (this.options.holdFetch ?? globalThis.fetch)(...request),
|
|
38222
38807
|
loopbackStorage: () => this.options.holdLoopback === true,
|
|
38223
|
-
|
|
38808
|
+
hiddenIpHosts: () => {
|
|
38809
|
+
if (this.settings.relayOnly !== true) return null;
|
|
38224
38810
|
try {
|
|
38225
|
-
|
|
38226
|
-
const ms = raw ? Number(raw) : NaN;
|
|
38227
|
-
return Number.isFinite(ms) && ms > 0 ? ms : void 0;
|
|
38811
|
+
return this.settings.holdStorage?.s3 ? [new URL(this.settings.holdStorage.s3.endpoint.trim()).host.toLowerCase()] : [];
|
|
38228
38812
|
} catch {
|
|
38229
|
-
return;
|
|
38813
|
+
return [];
|
|
38230
38814
|
}
|
|
38815
|
+
},
|
|
38816
|
+
ttlMs: () => {
|
|
38817
|
+
const raw = testSwitch("ghostly-test-hold-ttl");
|
|
38818
|
+
const ms = raw ? Number(raw) : NaN;
|
|
38819
|
+
return Number.isFinite(ms) && ms > 0 ? ms : void 0;
|
|
38820
|
+
},
|
|
38821
|
+
ratchet: (linkId) => {
|
|
38822
|
+
const live = this.links.get(linkId), stored = live?.stored;
|
|
38823
|
+
if (!live || !stored?.profile || !stored.participationSeed || !stored.pairedPeerKey || GhostlyNode.testNoRatchet()) return void 0;
|
|
38824
|
+
return {
|
|
38825
|
+
box: this.ratchetOf(linkId, live, {
|
|
38826
|
+
seedB64: stored.participationSeed,
|
|
38827
|
+
peerKey: stored.pairedPeerKey
|
|
38828
|
+
}),
|
|
38829
|
+
peerSupports: () => this.peerRatchets(live)
|
|
38830
|
+
};
|
|
38231
38831
|
}
|
|
38232
38832
|
});
|
|
38233
38833
|
/** x401 credentials (WISP 3xx): kept for websites the headless CLI calls, never shared with a contact. */
|
|
@@ -38266,6 +38866,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38266
38866
|
},
|
|
38267
38867
|
linkIds: () => [...this.links.keys()],
|
|
38268
38868
|
online: () => this.networkOn,
|
|
38869
|
+
relayOnly: () => this.settings.relayOnly === true,
|
|
38269
38870
|
emit: () => {
|
|
38270
38871
|
this.emitState();
|
|
38271
38872
|
this.did.changed();
|
|
@@ -38391,7 +38992,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38391
38992
|
online: () => this.networkOn,
|
|
38392
38993
|
emit: () => this.emitState(),
|
|
38393
38994
|
eligible: () => this.profileSubjects(),
|
|
38394
|
-
nostrRelays: () => effectiveNostrSettings(this.settings.nostr).relays
|
|
38995
|
+
nostrRelays: () => effectiveNostrSettings(this.settings.nostr).relays,
|
|
38996
|
+
relayOnly: () => this.settings.relayOnly === true,
|
|
38997
|
+
own: () => this.ownProfileSubjects()
|
|
38395
38998
|
});
|
|
38396
38999
|
/** A contact's verified identity's posts and follows, asked when its card is chosen (PUBLIC-PROFILES.md, "Posts and follows"). */
|
|
38397
39000
|
publicActivity = new PublicActivity({
|
|
@@ -38399,17 +39002,20 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38399
39002
|
online: () => this.networkOn,
|
|
38400
39003
|
eligible: () => this.profileSubjects(),
|
|
38401
39004
|
nostrRelays: () => effectiveNostrSettings(this.settings.nostr).relays,
|
|
38402
|
-
own: () =>
|
|
38403
|
-
|
|
38404
|
-
return this.identities.views().filter((p) => p.expiresAt > t).map((p) => ({
|
|
38405
|
-
provider: p.provider,
|
|
38406
|
-
subject: p.verified.subject
|
|
38407
|
-
}));
|
|
38408
|
-
},
|
|
39005
|
+
own: () => this.ownProfileSubjects(),
|
|
39006
|
+
relayOnly: () => this.settings.relayOnly === true,
|
|
38409
39007
|
contacts: () => this.contactSubjects(),
|
|
38410
39008
|
ownNostrFollows: () => this.nostrSocial.ownFollows(),
|
|
38411
39009
|
nostrMuted: (note, author) => this.nostrSocial.hides(note, author)
|
|
38412
39010
|
});
|
|
39011
|
+
/** The profile's own identities with a current proof. */
|
|
39012
|
+
ownProfileSubjects() {
|
|
39013
|
+
const t = Math.floor(Date.now() / 1e3);
|
|
39014
|
+
return this.identities.views().filter((p) => p.expiresAt > t).map((p) => ({
|
|
39015
|
+
provider: p.provider,
|
|
39016
|
+
subject: p.verified.subject
|
|
39017
|
+
}));
|
|
39018
|
+
}
|
|
38413
39019
|
/** What contacts shared that verifies now, with the chat it came in (paired chats only). */
|
|
38414
39020
|
contactSubjects() {
|
|
38415
39021
|
const t = Math.floor(Date.now() / 1e3);
|
|
@@ -38679,6 +39285,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
38679
39285
|
admin: !!view?.isAdmin
|
|
38680
39286
|
};
|
|
38681
39287
|
},
|
|
39288
|
+
notMember: (groupId) => this.groups.view(groupId)?.statusReason,
|
|
38682
39289
|
send: (groupId, edit, to) => this.groups.sendEdit(groupId, edit, to),
|
|
38683
39290
|
remove: (chat, id) => this.forgetGroupMessage(chat, id),
|
|
38684
39291
|
removeMine: async (chat, message, removal) => {
|
|
@@ -39122,6 +39729,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39122
39729
|
const files = linkFilesFrom(stored.id, storedFiles, messages);
|
|
39123
39730
|
this.links.set(stored.id, newLiveLink(stored, messages[messages.length - 1]?.timestamp ?? 0, files));
|
|
39124
39731
|
this.links.get(stored.id).waitingSends = Promise.resolve(new Set(messages.filter(waitsForLive).map((m) => m.id)));
|
|
39732
|
+
this.links.get(stored.id).cardsDue = Promise.resolve(new Set(messages.filter(cardDue).map((m) => m.id)));
|
|
39125
39733
|
this.links.get(stored.id).pkarrSeenAt = pkarrSeenAt(messages);
|
|
39126
39734
|
for (const message of messages.slice(-20)) this.clockSample(message);
|
|
39127
39735
|
const note = latestReaction(messages);
|
|
@@ -40222,6 +40830,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40222
40830
|
nostrLoadOwn(params) {
|
|
40223
40831
|
return this.nostrSocial.loadOwn(params);
|
|
40224
40832
|
}
|
|
40833
|
+
nostrOwnFollows(params) {
|
|
40834
|
+
return this.nostrSocial.ownFollowList({ subject: String(params?.subject) });
|
|
40835
|
+
}
|
|
40836
|
+
nostrContactNotes(params) {
|
|
40837
|
+
return this.nostrSocial.contactNotes({
|
|
40838
|
+
linkId: String(params?.linkId),
|
|
40839
|
+
subject: String(params?.subject)
|
|
40840
|
+
});
|
|
40841
|
+
}
|
|
40225
40842
|
nostrLookup(params) {
|
|
40226
40843
|
return this.nostrSocial.lookup(params);
|
|
40227
40844
|
}
|
|
@@ -41037,7 +41654,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41037
41654
|
}
|
|
41038
41655
|
};
|
|
41039
41656
|
}
|
|
41040
|
-
if (!original && !group) {
|
|
41657
|
+
if (!original && !group && live) {
|
|
41658
|
+
const id = (await this.unkeyedRowsOf(this.links.get(message.linkId))).get(reply.id);
|
|
41659
|
+
const row = id === void 0 || id === message.id ? void 0 : await db.getMessage(message.linkId, id);
|
|
41660
|
+
if (row && replyRef(row) === reply.id) original = row;
|
|
41661
|
+
} else if (!original && !group) {
|
|
41041
41662
|
history = await db.getMessages(message.linkId);
|
|
41042
41663
|
original = history.find((m) => m.id !== message.id && replyRef(m) === reply.id);
|
|
41043
41664
|
}
|
|
@@ -41088,10 +41709,21 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41088
41709
|
return press;
|
|
41089
41710
|
}
|
|
41090
41711
|
/** A paired row's reply as it goes on the wire again (a resend, a hold). */
|
|
41091
|
-
/** `localStorage["ghostly-test-no-edit"]`: this app offers no edit/1, as an older one (the e2e's old contact).
|
|
41712
|
+
/** `localStorage["ghostly-test-no-edit"]`: this app offers no edit/1, as an older one (the e2e's old contact). A test build only. */
|
|
41092
41713
|
static testNoEdit() {
|
|
41714
|
+
return testSwitch("ghostly-test-no-edit") === "1";
|
|
41715
|
+
}
|
|
41716
|
+
/**
|
|
41717
|
+
* Whether the contact's capability record lists `ratchet/1` (WISP 4xx): the record read this run, or else the last one
|
|
41718
|
+
* kept with the chat (the run's is cleared while offline and on a restart of the chat's transports).
|
|
41719
|
+
*/
|
|
41720
|
+
peerRatchets(live) {
|
|
41721
|
+
return !!(live.caps?.peer ?? live.stored.capsState?.peer)?.capabilities.includes(RATCHET_CAPABILITY);
|
|
41722
|
+
}
|
|
41723
|
+
/** An e2e run playing an app from before forward secrecy (WISP 4xx): no ratchet/1, no ratchet, as that app. A release build ignores the key. */
|
|
41724
|
+
static testNoRatchet() {
|
|
41093
41725
|
try {
|
|
41094
|
-
return typeof localStorage !== "undefined" && localStorage.getItem("ghostly-test-no-
|
|
41726
|
+
return testBuild() && typeof localStorage !== "undefined" && localStorage.getItem("ghostly-test-no-ratchet") === "1";
|
|
41095
41727
|
} catch {
|
|
41096
41728
|
return false;
|
|
41097
41729
|
}
|
|
@@ -41201,6 +41833,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41201
41833
|
const live = this.links.get(linkId);
|
|
41202
41834
|
if (!live?.stored.profile || live.stored.group) return false;
|
|
41203
41835
|
const id = `peer_${edit.id}`;
|
|
41836
|
+
if (isRefusalId(id)) return true;
|
|
41204
41837
|
const ref = edit.rm && !await this.namesMine(linkId, edit.id);
|
|
41205
41838
|
if (live.stored.deletedIds?.includes(id)) {
|
|
41206
41839
|
if (ref) {
|
|
@@ -41270,7 +41903,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41270
41903
|
*/
|
|
41271
41904
|
async cardWentBare(linkId, message) {
|
|
41272
41905
|
if (!message.card || message.cardRestore || message.buttonsRestore) return;
|
|
41273
|
-
await db.patchMessage(linkId, message.id, (current) => current.sender === "me" && current.card && !current.cardRestore && !current.buttonsRestore ? { cardRestore: "due" } : null);
|
|
41906
|
+
if (await db.patchMessage(linkId, message.id, (current) => current.sender === "me" && current.card && !current.cardRestore && !current.buttonsRestore ? { cardRestore: "due" } : null)) this.links.get(linkId)?.cardsDue?.then((known) => known.add(message.id), () => {});
|
|
41907
|
+
}
|
|
41908
|
+
/** `cardsDue`: a chat loaded at the start has them from that read; any other reads its history once in a run. */
|
|
41909
|
+
cardsDueOf(live) {
|
|
41910
|
+
return live.cardsDue ??= db.getMessages(live.stored.id).then((history) => new Set(history.filter(cardDue).map((m) => m.id)), (error) => {
|
|
41911
|
+
live.cardsDue = void 0;
|
|
41912
|
+
throw error;
|
|
41913
|
+
});
|
|
41274
41914
|
}
|
|
41275
41915
|
/** The session capability a contact's app lists when it shows a card of this kind, so a restore edit reads as a card there. */
|
|
41276
41916
|
static cardCapability(card) {
|
|
@@ -41294,7 +41934,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41294
41934
|
const live = this.links.get(linkId), link = live?.link;
|
|
41295
41935
|
const offers = link?.sessionOffers.peer;
|
|
41296
41936
|
if (!live?.stored.profile || live.stored.group || !link?.supportsEdits || !offers) return;
|
|
41937
|
+
const due = await this.cardsDueOf(live);
|
|
41938
|
+
if (!due.size) return;
|
|
41939
|
+
const asked = new Set(due);
|
|
41297
41940
|
const mine = (await db.getMessages(linkId)).filter((m) => m.sender === "me").sort((a, b) => b.timestamp - a.timestamp);
|
|
41941
|
+
for (const id of asked) due.delete(id);
|
|
41942
|
+
for (const message of mine) if (cardDue(message)) due.add(message.id);
|
|
41298
41943
|
const since = Date.now() - CARD_RESTORE_MS;
|
|
41299
41944
|
const changed = [];
|
|
41300
41945
|
const cards = /* @__PURE__ */ new Set();
|
|
@@ -41307,7 +41952,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41307
41952
|
const stale = superseded || kept++ >= CARD_RESTORE_MOST || message.timestamp < since;
|
|
41308
41953
|
if (!stale && message.card && !offers.includes(GhostlyNode.cardCapability(message.card))) continue;
|
|
41309
41954
|
const at = Date.now();
|
|
41310
|
-
|
|
41955
|
+
const patched = await db.patchMessage(linkId, message.id, (current) => {
|
|
41311
41956
|
if (current.sender !== "me" || (current.cardRestore ?? current.buttonsRestore) !== "due") return null;
|
|
41312
41957
|
const done = {
|
|
41313
41958
|
cardRestore: "sent",
|
|
@@ -41330,7 +41975,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41330
41975
|
},
|
|
41331
41976
|
...done
|
|
41332
41977
|
};
|
|
41333
|
-
})
|
|
41978
|
+
});
|
|
41979
|
+
due.delete(message.id);
|
|
41980
|
+
if (patched?.edit?.pending) {
|
|
41334
41981
|
changed.push(message.id);
|
|
41335
41982
|
this.editsFor(linkId).edited(message.id);
|
|
41336
41983
|
}
|
|
@@ -41340,7 +41987,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41340
41987
|
/**
|
|
41341
41988
|
* `restoreCards`, then what waits goes. One look at a time per chat, at most once per `CARD_RESTORE_EVERY_MS`: asked
|
|
41342
41989
|
* again while one runs or within the gap, one more look goes once it is over, and what waits still goes at once (the
|
|
41343
|
-
* edit queue reads the history once a
|
|
41990
|
+
* edit queue reads the history once a run).
|
|
41344
41991
|
*/
|
|
41345
41992
|
restoreCardsSoon(linkId) {
|
|
41346
41993
|
const flush = () => this.editsFor(linkId).flush().catch(() => {});
|
|
@@ -42392,6 +43039,16 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42392
43039
|
}
|
|
42393
43040
|
if (waiting.length) await this.messagesChanged(linkId, waiting.map((m) => m.id));
|
|
42394
43041
|
}
|
|
43042
|
+
/** The rows of a chat a reply names by another id than their own (`unkeyedRef`), read once in a run. */
|
|
43043
|
+
unkeyedRowsOf(live) {
|
|
43044
|
+
return live.unkeyedRows ??= db.getMessages(live.stored.id).then((history) => new Map(history.flatMap((m) => {
|
|
43045
|
+
const ref = unkeyedRef(m);
|
|
43046
|
+
return ref ? [[ref, m.id]] : [];
|
|
43047
|
+
})), (error) => {
|
|
43048
|
+
live.unkeyedRows = void 0;
|
|
43049
|
+
throw error;
|
|
43050
|
+
});
|
|
43051
|
+
}
|
|
42395
43052
|
/**
|
|
42396
43053
|
* The ids of my messages that wait for the live link (`waitsForLive`). A chat loaded at the start has them from that
|
|
42397
43054
|
* read; any other reads its history once in a run. A session that opens then reads those rows, however long the chat.
|
|
@@ -42672,6 +43329,26 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42672
43329
|
this.capsChanged(linkId);
|
|
42673
43330
|
}
|
|
42674
43331
|
/** The chat's connection story, for paired chats (not group edges). */
|
|
43332
|
+
/**
|
|
43333
|
+
* The chat's ratchet (WISP 4xx), made once per chat: its keys are read from the chat's row when used (each start of
|
|
43334
|
+
* the link has credentials of its own), so a contact pinned later is the one it seals to. Saved in the row as
|
|
43335
|
+
* `ratchetState`, which no backup or handoff takes along.
|
|
43336
|
+
*/
|
|
43337
|
+
ratchetOf(linkId, live, credentials) {
|
|
43338
|
+
return live.ratchet ??= new RatchetBox(() => ({
|
|
43339
|
+
seed: fromBase64Url(live.stored.participationSeed ?? credentials.seedB64),
|
|
43340
|
+
self: identityFromSeedB64(live.stored.participationSeed ?? credentials.seedB64).pubKeyZ32,
|
|
43341
|
+
peer: live.stored.pairedPeerKey ?? credentials.peerKey,
|
|
43342
|
+
rendezvous: [identityFromSeedB64(live.stored.seedB64).pubKeyZ32, live.stored.peerPubKeyZ32],
|
|
43343
|
+
secret: fromBase64Url(live.stored.encKeyB64)
|
|
43344
|
+
}), live.stored.ratchetState ?? emptyRatchetState(), async (state) => {
|
|
43345
|
+
await db.patchLink(linkId, { ratchetState: state });
|
|
43346
|
+
live.stored = {
|
|
43347
|
+
...live.stored,
|
|
43348
|
+
ratchetState: state
|
|
43349
|
+
};
|
|
43350
|
+
});
|
|
43351
|
+
}
|
|
42675
43352
|
transportLogOf(live) {
|
|
42676
43353
|
if (!live.stored.profile || live.stored.group) return void 0;
|
|
42677
43354
|
if (live.transportLog) return live.transportLog;
|
|
@@ -43010,7 +43687,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43010
43687
|
note(check.error);
|
|
43011
43688
|
continue;
|
|
43012
43689
|
}
|
|
43013
|
-
const original = message.file,
|
|
43690
|
+
const original = message.file, picked = {
|
|
43014
43691
|
id: groupFileId(groupId, "out"),
|
|
43015
43692
|
name: original.name,
|
|
43016
43693
|
size: original.size,
|
|
@@ -43019,11 +43696,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43019
43696
|
...original.video && { video: original.video },
|
|
43020
43697
|
...original.image && { image: original.image }
|
|
43021
43698
|
};
|
|
43022
|
-
await copyForForward(original.id, {
|
|
43699
|
+
const file = await copyForForward(original.id, {
|
|
43023
43700
|
linkId: to,
|
|
43024
|
-
wireId:
|
|
43701
|
+
wireId: picked.id.slice(`group-${groupId}-out-`.length),
|
|
43025
43702
|
timestamp: now(),
|
|
43026
|
-
file
|
|
43703
|
+
file: picked
|
|
43027
43704
|
});
|
|
43028
43705
|
const sent = await this.sendGroupFile({
|
|
43029
43706
|
groupId,
|
|
@@ -43044,7 +43721,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43044
43721
|
continue;
|
|
43045
43722
|
}
|
|
43046
43723
|
const original = message.file, wireId = toBase64Url(randomBytes(12)), timestamp = now();
|
|
43047
|
-
const
|
|
43724
|
+
const picked = {
|
|
43048
43725
|
id: GhostlyNode.outgoingFileId(to, wireId),
|
|
43049
43726
|
name: original.name,
|
|
43050
43727
|
size: original.size,
|
|
@@ -43053,11 +43730,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43053
43730
|
...original.video && { video: original.video },
|
|
43054
43731
|
...original.image && { image: original.image }
|
|
43055
43732
|
};
|
|
43056
|
-
await copyForForward(original.id, {
|
|
43733
|
+
const file = await copyForForward(original.id, {
|
|
43057
43734
|
linkId: to,
|
|
43058
43735
|
wireId,
|
|
43059
43736
|
timestamp,
|
|
43060
|
-
file
|
|
43737
|
+
file: picked
|
|
43061
43738
|
});
|
|
43062
43739
|
try {
|
|
43063
43740
|
await this.sendFile({
|
|
@@ -44045,10 +44722,22 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44045
44722
|
source: created.source
|
|
44046
44723
|
};
|
|
44047
44724
|
}
|
|
44048
|
-
/**
|
|
44049
|
-
|
|
44725
|
+
/**
|
|
44726
|
+
* The screen shows this invoice of ours (Receive): its mint or its Lightning card asks about it at the fast pace for a
|
|
44727
|
+
* while (`INVOICE_PACE.watchMs`), so a payment shows within seconds. The screen says it again while it shows it.
|
|
44728
|
+
*/
|
|
44729
|
+
async walletWatchInvoice({ invoice, network }) {
|
|
44730
|
+
if (typeof invoice !== "string" || !invoice.trim()) throw new Error("invoice is required");
|
|
44731
|
+
if (await this.wallet.watch(invoice)) return;
|
|
44732
|
+
await this.lightnings[this.net(network)].watch(invoice);
|
|
44733
|
+
}
|
|
44734
|
+
/**
|
|
44735
|
+
* `card`: the Lightning card that will pay; absent, the network's default one. `amount`: the sats chosen for an
|
|
44736
|
+
* invoice with no amount, which only the mints pay (`via: "cashu"`); a Lightning source refuses one.
|
|
44737
|
+
*/
|
|
44738
|
+
walletQuoteInvoice({ invoice, via, network, card, amount }) {
|
|
44050
44739
|
const n = this.net(network);
|
|
44051
|
-
return via === "cashu" ? this.wallet.quoteInvoice(invoice, n) : this.lightningCard(n, card).then((c) => c.quote(invoice));
|
|
44740
|
+
return via === "cashu" ? this.wallet.quoteInvoice(invoice, n, amount) : this.lightningCard(n, card).then((c) => c.quote(invoice));
|
|
44052
44741
|
}
|
|
44053
44742
|
/**
|
|
44054
44743
|
* `confirmedReal`: the person confirmed a Mainnet payment as real money; without it one is refused. `linkId` +
|
|
@@ -44194,8 +44883,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44194
44883
|
return { inspection: await this.wallet.inspect(text) };
|
|
44195
44884
|
}
|
|
44196
44885
|
async walletReceiveToken({ token }) {
|
|
44197
|
-
const { amount } = await this.wallet.receiveToken(token.trim());
|
|
44198
|
-
return {
|
|
44886
|
+
const { amount, fee } = await this.wallet.receiveToken(token.trim());
|
|
44887
|
+
return {
|
|
44888
|
+
amount,
|
|
44889
|
+
fee
|
|
44890
|
+
};
|
|
44199
44891
|
}
|
|
44200
44892
|
/** `network`: only that network's Cashu wallet (its mints). */
|
|
44201
44893
|
walletExport(params) {
|
|
@@ -44637,7 +45329,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44637
45329
|
if (settings.relays && (this.relays || this.transport.configure) && !settings.relays.some((relay) => normalizeRelayUrl(relay))) throw new Error("Enter at least one relay address (https://…)");
|
|
44638
45330
|
if (settings.readRelays !== void 0 && typeof settings.readRelays !== "boolean") throw new Error("readRelays is on or off");
|
|
44639
45331
|
if (settings.irohRelays) {
|
|
44640
|
-
if (settings.irohRelays.length >
|
|
45332
|
+
if (settings.irohRelays.length > 5) throw new Error("Use at most five Iroh relays");
|
|
44641
45333
|
for (const relay of settings.irohRelays) {
|
|
44642
45334
|
const problem = irohRelayProblem(relay);
|
|
44643
45335
|
if (problem) throw new Error(problem);
|
|
@@ -44763,6 +45455,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44763
45455
|
this.did.publishNow().catch(() => {});
|
|
44764
45456
|
if (!this.options.singleDevice && knownDeviceGate()?.state === "active") this.startDeviceSet({ justRead: true }).catch(() => {});
|
|
44765
45457
|
} else if (wasOnline && this.networkOn && relayOnlyChanged) await this.restartLinksForRelayOnly();
|
|
45458
|
+
if (relayOnlyChanged && this.settings.relayOnly !== true) this.hold.wake();
|
|
44766
45459
|
if (wasOnline && !this.networkOn) this.stopGroupEntries();
|
|
44767
45460
|
if (wasOnline && !this.networkOn) await this.hold.stop();
|
|
44768
45461
|
const gate = knownDeviceGate();
|
|
@@ -45801,9 +46494,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45801
46494
|
const native = this.keepsGroupNative(stored);
|
|
45802
46495
|
const resumeOn = native ? TRANSPORTS.find((t) => t !== "webrtc/1" && t in this.nativeFactories && !!stored.peerTransports?.includes(t)) : "webrtc/1";
|
|
45803
46496
|
live.pairing = { status: "connecting" };
|
|
46497
|
+
live.edgeStartedAt = Date.now();
|
|
45804
46498
|
live.carried?.stop();
|
|
45805
46499
|
live.carried = entry || this.groups.isCommunityGroup(group) ? void 0 : new CarriedTransport(this.groupTransport, live.myPubKeyZ32, stored.peerPubKeyZ32, {
|
|
45806
46500
|
carry: (payload) => this.groups.carrySignal(group, peer, payload),
|
|
46501
|
+
canCarry: () => this.groups.canCarrySignal(group, peer),
|
|
45807
46502
|
open: () => !!live.link?.isDataLinkOpen,
|
|
45808
46503
|
look: () => live.link?.look(),
|
|
45809
46504
|
direct: (payload) => this.groups.directSignal(group, peer, linkId, payload),
|
|
@@ -46156,7 +46851,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46156
46851
|
return !peer || peer.capabilities.includes("dht-text/1");
|
|
46157
46852
|
},
|
|
46158
46853
|
peerAcceptsFile: () => !!live.caps?.peer?.capabilities.includes(DHT_FILE_CAPABILITY),
|
|
46159
|
-
reactions: () => live.stored.reactionsOut ?? []
|
|
46854
|
+
reactions: () => live.stored.reactionsOut ?? [],
|
|
46855
|
+
ratchet: credentials && !GhostlyNode.testNoRatchet() ? {
|
|
46856
|
+
box: this.ratchetOf(linkId, live, credentials),
|
|
46857
|
+
peerSupports: () => this.peerRatchets(live)
|
|
46858
|
+
} : void 0
|
|
46160
46859
|
} : void 0,
|
|
46161
46860
|
native: {
|
|
46162
46861
|
peerDescriptors: stored.peerDescriptors,
|
|
@@ -46563,6 +47262,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46563
47262
|
"chat/1",
|
|
46564
47263
|
DHT_TEXT_CAPABILITY,
|
|
46565
47264
|
DHT_FILE_CAPABILITY,
|
|
47265
|
+
...GhostlyNode.testNoRatchet() ? [] : [RATCHET_CAPABILITY],
|
|
46566
47266
|
...live?.stored.hold?.enabled ? [HOLD_CAPABILITY] : [],
|
|
46567
47267
|
"files/2",
|
|
46568
47268
|
UPGRADE_CAPABILITY,
|
|
@@ -46634,7 +47334,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46634
47334
|
nativeFactoriesFor(relayOnly) {
|
|
46635
47335
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
46636
47336
|
return {
|
|
46637
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
47337
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-B8Pdykhg.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
46638
47338
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
46639
47339
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
46640
47340
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, { relays: this.irohRelays }) } : {}
|
|
@@ -46856,8 +47556,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46856
47556
|
const expected = this.links.get(linkId)?.link;
|
|
46857
47557
|
const starts = Object.entries(this.nativeFactories).map(([transport, factory]) => {
|
|
46858
47558
|
const key = transport;
|
|
46859
|
-
const operation =
|
|
46860
|
-
this.nativeQueues.set(key, operation.then(() => {}, () => {}));
|
|
47559
|
+
const operation = this.nativeTurn(key, linkId, inUse).then(() => factory ? this.startNativeEndpoint(linkId, expected, key, factory, inUse) : false).finally(() => this.nextNativeTurn(key, true));
|
|
47560
|
+
this.nativeQueues.set(key, Promise.all([this.nativeQueues.get(key), operation.then(() => {}, () => {})]).then(() => {}));
|
|
46861
47561
|
return operation;
|
|
46862
47562
|
});
|
|
46863
47563
|
return Promise.all(starts).then((full) => {
|
|
@@ -46878,6 +47578,41 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46878
47578
|
this.emitState();
|
|
46879
47579
|
});
|
|
46880
47580
|
}
|
|
47581
|
+
/**
|
|
47582
|
+
* A start's turn in its transport's queue: one at a time, in the order asked, but the chat in use (on screen, a text
|
|
47583
|
+
* going or coming in it, an edge of the group on screen) goes before the others waiting. With the relay out of reach
|
|
47584
|
+
* each start takes 10 s to fail, and the chat opened waited for every other chat's retry before its own started or
|
|
47585
|
+
* said why: 331 s with 40 chats.
|
|
47586
|
+
*/
|
|
47587
|
+
nativeTurn(key, linkId, inUse) {
|
|
47588
|
+
let lane = this.nativeTurns.get(key);
|
|
47589
|
+
if (!lane) this.nativeTurns.set(key, lane = {
|
|
47590
|
+
busy: false,
|
|
47591
|
+
waiting: []
|
|
47592
|
+
});
|
|
47593
|
+
const turn = new Promise((go) => lane.waiting.push({
|
|
47594
|
+
linkId,
|
|
47595
|
+
inUse,
|
|
47596
|
+
go
|
|
47597
|
+
}));
|
|
47598
|
+
this.nextNativeTurn(key);
|
|
47599
|
+
return turn;
|
|
47600
|
+
}
|
|
47601
|
+
/** `ended`: the start under way ended. The next one waiting starts: the first in use, or else the first asked. */
|
|
47602
|
+
nextNativeTurn(key, ended = false) {
|
|
47603
|
+
const lane = this.nativeTurns.get(key);
|
|
47604
|
+
if (!lane) return;
|
|
47605
|
+
if (ended) lane.busy = false;
|
|
47606
|
+
if (lane.busy || !lane.waiting.length) return;
|
|
47607
|
+
const onScreen = (linkId) => {
|
|
47608
|
+
const stored = this.links.get(linkId)?.stored;
|
|
47609
|
+
return !!stored && (stored.group ? `group:${stored.group}` : stored.id) === this.activeLinkId;
|
|
47610
|
+
};
|
|
47611
|
+
const next = lane.waiting.findIndex((start) => start.inUse || onScreen(start.linkId));
|
|
47612
|
+
const [start] = lane.waiting.splice(Math.max(next, 0), 1);
|
|
47613
|
+
lane.busy = true;
|
|
47614
|
+
start.go();
|
|
47615
|
+
}
|
|
46881
47616
|
/** The listeners this app may hold for a transport: sixteen for Iroh's browser build (`IROH_WEB_SLOTS`), eight for the others. */
|
|
46882
47617
|
nativeSlots(key) {
|
|
46883
47618
|
return key === "iroh/1" && this.options.irohWeb ? IROH_WEB_SLOTS : NATIVE_SLOTS;
|
|
@@ -47073,6 +47808,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47073
47808
|
groupNativeRetryAt = 0;
|
|
47074
47809
|
/** Chats and group links whose native listener failed to start, by link id: when each tries again, and how long it waited last. */
|
|
47075
47810
|
nativeFailed = /* @__PURE__ */ new Map();
|
|
47811
|
+
/** Of those, the ones whose start is queued or under way: a transport's starts go one after another. */
|
|
47812
|
+
nativeRetrying = /* @__PURE__ */ new Set();
|
|
47076
47813
|
/**
|
|
47077
47814
|
* Now and then, the group links that found no free native slot try again: a chat or another group may have let one go.
|
|
47078
47815
|
* Chats and group links whose listener failed to start try again once their wait is over.
|
|
@@ -47081,13 +47818,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47081
47818
|
this.groupAnchorsAnswered();
|
|
47082
47819
|
const now = Date.now();
|
|
47083
47820
|
for (const [linkId, failed] of this.nativeFailed) {
|
|
47084
|
-
if (now < failed.at) continue;
|
|
47821
|
+
if (now < failed.at || this.nativeRetrying.has(linkId)) continue;
|
|
47085
47822
|
if (!this.links.get(linkId)?.link) {
|
|
47086
47823
|
this.nativeFailed.delete(linkId);
|
|
47087
47824
|
continue;
|
|
47088
47825
|
}
|
|
47089
47826
|
failed.at = now + failed.wait;
|
|
47090
|
-
this.
|
|
47827
|
+
this.nativeRetrying.add(linkId);
|
|
47828
|
+
this.ensureNativeEndpoints(linkId).finally(() => this.nativeRetrying.delete(linkId));
|
|
47091
47829
|
}
|
|
47092
47830
|
if (!this.groupNativeWaiting.size || Date.now() < this.groupNativeRetryAt) return;
|
|
47093
47831
|
this.groupNativeRetryAt = Date.now() + NATIVE_RETRY_MS;
|
|
@@ -47251,6 +47989,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47251
47989
|
* straight from its author (`clockSample`). `place`: as `placed`.
|
|
47252
47990
|
*/
|
|
47253
47991
|
async storeNewMessage(message, straight = false, place) {
|
|
47992
|
+
if (message.sender === "peer" && !message.notice && isRefusalId(message.id)) return false;
|
|
47254
47993
|
const edge = this.links.get(message.linkId)?.stored;
|
|
47255
47994
|
if (edge?.group && edge.groupPeer && !edge.groupEntry) message = {
|
|
47256
47995
|
...message,
|
|
@@ -47296,6 +48035,9 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47296
48035
|
}
|
|
47297
48036
|
if (!await db.addMessage(message)) return false;
|
|
47298
48037
|
if (live && waitsForLive(message)) live.waitingSends?.then((known) => known.add(message.id), () => {});
|
|
48038
|
+
const unkeyed = live && !live.stored.group && unkeyedRef(message);
|
|
48039
|
+
if (unkeyed) live.unkeyedRows?.then((rows) => rows.set(unkeyed, message.id), () => {});
|
|
48040
|
+
if (live && cardDue(message)) live.cardsDue?.then((due) => due.add(message.id), () => {});
|
|
47299
48041
|
this.clockSample(message, straight);
|
|
47300
48042
|
const newest = this.newestAt.get(message.linkId);
|
|
47301
48043
|
if (!message.event) this.newestAt.set(message.linkId, Math.max(newest ?? 0, writtenAt(message, this.clockLeads.get(this.clockOf(message)))));
|
|
@@ -47601,7 +48343,7 @@ var EngineServer = class {
|
|
|
47601
48343
|
kind: "response",
|
|
47602
48344
|
id: request.id
|
|
47603
48345
|
};
|
|
47604
|
-
if (request.method === "setCallSignal") this.
|
|
48346
|
+
if (request.method === "setCallSignal") this.callHandled(client, request.params);
|
|
47605
48347
|
let params = request.params;
|
|
47606
48348
|
if (request.method === "setCallOn") {
|
|
47607
48349
|
if (request.params?.on === true) this.onCall.add(client);
|
|
@@ -47729,6 +48471,22 @@ var EngineServer = class {
|
|
|
47729
48471
|
broadcast(event) {
|
|
47730
48472
|
for (const client of [...this.clients]) this.post(client, event);
|
|
47731
48473
|
}
|
|
48474
|
+
/**
|
|
48475
|
+
* A page sent a call signal in a chat. While the contact's offer rang there, an answer or a hang-up is that page taking
|
|
48476
|
+
* the call or declining it: the other pages (the extension's tabs share one engine) stop ringing. Before, they rang
|
|
48477
|
+
* on to their timeout and then wrote "Missed call" into the history of a call that was on, and a Decline pressed in
|
|
48478
|
+
* one of them ended it.
|
|
48479
|
+
*/
|
|
48480
|
+
callHandled(from, params) {
|
|
48481
|
+
const { linkId, signal } = params ?? {};
|
|
48482
|
+
if (typeof linkId !== "string" || !this.offers.delete(linkId)) return;
|
|
48483
|
+
const kind = typeof signal === "string" ? signalKind(signal) : void 0;
|
|
48484
|
+
if (kind !== "a" && kind !== "h") return;
|
|
48485
|
+
for (const client of [...this.clients]) if (client !== from) this.post(client, {
|
|
48486
|
+
kind: "call-handled",
|
|
48487
|
+
linkId
|
|
48488
|
+
});
|
|
48489
|
+
}
|
|
47732
48490
|
};
|
|
47733
48491
|
/** Whether a call only reads a group's stored history (`GhostlyNode.groupsRead`). */
|
|
47734
48492
|
function readsGroupHistory(request) {
|
|
@@ -47747,4 +48505,4 @@ function signalKind(signal) {
|
|
|
47747
48505
|
//#endregion
|
|
47748
48506
|
export { EngineServer };
|
|
47749
48507
|
|
|
47750
|
-
//# sourceMappingURL=server-
|
|
48508
|
+
//# sourceMappingURL=server-Br3XPwFG.js.map
|