@ghostlytools/cli 1.7.2 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -24
- package/SKILL.md +10 -4
- package/dist/assets/{api-CcuCtc1H.js → api-Chhvpwok.js} +2 -2
- package/dist/assets/{api-tSZELCPQ.js → api-D3i2hwy0.js} +340 -155
- package/dist/assets/api-D3i2hwy0.js.map +1 -0
- package/dist/assets/{apiKit-BFk7GAk9.js → apiKit-BtsHrnoo.js} +60 -8
- package/dist/assets/apiKit-BtsHrnoo.js.map +1 -0
- package/dist/assets/{apps-D6THreq_.js → apps-BFJTqvAt.js} +1 -1
- package/dist/assets/{apps-C5Mi6x9Q.js → apps-BHl97rHs.js} +11 -9
- package/dist/assets/apps-BHl97rHs.js.map +1 -0
- package/dist/assets/{arkade-Cz0B9bJ0.js → arkade-BFE8KkEE.js} +2 -2
- package/dist/assets/{arkade-Cz0B9bJ0.js.map → arkade-BFE8KkEE.js.map} +1 -1
- package/dist/assets/{backup-A0hIa9GE.js → backup-Bbsr6nDi.js} +1 -1
- package/dist/assets/{backup-Wb2sm2dd.js → backup-CxACdtQX.js} +7 -7
- package/dist/assets/{backup-Wb2sm2dd.js.map → backup-CxACdtQX.js.map} +1 -1
- package/dist/assets/{blobFiles-Bckz9fjp.js → blobFiles-DOQDRdDI.js} +3 -3
- package/dist/assets/{blobFiles-Bckz9fjp.js.map → blobFiles-DOQDRdDI.js.map} +1 -1
- package/dist/assets/{buttons-Cf70NVYq.js → buttons-CieBtXEO.js} +35 -9
- package/dist/assets/buttons-CieBtXEO.js.map +1 -0
- package/dist/assets/buttons-YtAj3R_E.js +2 -0
- package/dist/assets/{daemonProof-Bp9lJDxf.js → daemonProof-QmtwDj-N.js} +2 -2
- package/dist/assets/{daemonProof-Bp9lJDxf.js.map → daemonProof-QmtwDj-N.js.map} +1 -1
- package/dist/assets/{envelope-kQ5kYjVE.js → envelope-DYiGwzq_.js} +2 -2
- package/dist/assets/{envelope-kQ5kYjVE.js.map → envelope-DYiGwzq_.js.map} +1 -1
- package/dist/assets/{errors-mnjSQlbX.js → errors-QUGP-jIF.js} +2 -2
- package/dist/assets/errors-QUGP-jIF.js.map +1 -0
- package/dist/assets/{fileBytes-OolN5cSY.js → fileBytes-BPDKufla.js} +1 -1
- package/dist/assets/{fileBytes-BD0v3rRG.js → fileBytes-DNgrRL0R.js} +3 -3
- package/dist/assets/{fileBytes-BD0v3rRG.js.map → fileBytes-DNgrRL0R.js.map} +1 -1
- package/dist/assets/{fileBytes-_fd-2JRY.js → fileBytes-Q3ehcEr8.js} +2 -2
- package/dist/assets/{fileBytes-_fd-2JRY.js.map → fileBytes-Q3ehcEr8.js.map} +1 -1
- package/dist/assets/fileBytesIdb-DZcESfTt.js +2 -0
- package/dist/assets/{fileBytesIdb-NtA8r9EM.js → fileBytesIdb-Dm1EyEbT.js} +3 -3
- package/dist/assets/{fileBytesIdb-NtA8r9EM.js.map → fileBytesIdb-Dm1EyEbT.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-B8fJwkwM.js → fileBytesOpfs-ZGD21c4Q.js} +3 -3
- package/dist/assets/{fileBytesOpfs-B8fJwkwM.js.map → fileBytesOpfs-ZGD21c4Q.js.map} +1 -1
- package/dist/assets/{groupFiles-D9Ttlm3M.js → groupFiles-CBJIEvCE.js} +572 -6
- package/dist/assets/groupFiles-CBJIEvCE.js.map +1 -0
- package/dist/assets/{host-DpypH-fR.js → host-Va-r_KJz.js} +84 -23
- package/dist/assets/host-Va-r_KJz.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-D1rj84v2.js → hyperdhtRelay-B2uK9tJv.js} +2 -2
- package/dist/assets/{hyperdhtRelay-D1rj84v2.js.map → hyperdhtRelay-B2uK9tJv.js.map} +1 -1
- package/dist/assets/{idb-BlH8-O3R.js → idb-BkOJES5_.js} +5 -3
- package/dist/assets/idb-BkOJES5_.js.map +1 -0
- package/dist/assets/{irohWeb-BTSlWgEX.js → irohWeb-DxeEgQ-W.js} +2 -2
- package/dist/assets/{irohWeb-BTSlWgEX.js.map → irohWeb-DxeEgQ-W.js.map} +1 -1
- package/dist/assets/{main-BwgoQZVu.js → main-BX4oPWCJ.js} +589 -192
- package/dist/assets/main-BX4oPWCJ.js.map +1 -0
- package/dist/assets/{mainline-B1urhbEZ.js → mainline-IfWQOB-J.js} +39 -12
- package/dist/assets/mainline-IfWQOB-J.js.map +1 -0
- package/dist/assets/{networkReason-D2Z0BdIj.js → networkReason-N2vAaoth.js} +3 -3
- package/dist/assets/{networkReason-D2Z0BdIj.js.map → networkReason-N2vAaoth.js.map} +1 -1
- package/dist/assets/{nwc-T2aUK6bi.js → nwc-CzyCtNK2.js} +3 -3
- package/dist/assets/{nwc-T2aUK6bi.js.map → nwc-CzyCtNK2.js.map} +1 -1
- package/dist/assets/{nwcProvider-Dz-ty_DE.js → nwcProvider-DjWmEn3j.js} +2 -2
- package/dist/assets/{nwcProvider-Dz-ty_DE.js.map → nwcProvider-DjWmEn3j.js.map} +1 -1
- package/dist/assets/{profiles-C6XWqre5.js → profiles-DcCeOi7J.js} +104 -10
- package/dist/assets/profiles-DcCeOi7J.js.map +1 -0
- package/dist/assets/{registry-BlSTJlbv.js → registry-BmS02J5h.js} +1 -1
- package/dist/assets/{registry-Bazitl0a.js → registry-CeW8XEQc.js} +45 -14
- package/dist/assets/registry-CeW8XEQc.js.map +1 -0
- package/dist/assets/{resolve-Bx1Eeg-w.js → resolve-BvHkAhDH.js} +66 -29
- package/dist/assets/resolve-BvHkAhDH.js.map +1 -0
- package/dist/assets/{restoredRows-Fv-MuY45.js → restoredRows-mTTp3XNs.js} +2 -2
- package/dist/assets/{restoredRows-Fv-MuY45.js.map → restoredRows-mTTp3XNs.js.map} +1 -1
- package/dist/assets/{server-CnPj9wWh.js → server-BUcJo4vz.js} +1033 -821
- package/dist/assets/server-BUcJo4vz.js.map +1 -0
- package/dist/assets/{src-BsznF3XG.js → src-BB5-5P3s.js} +645 -196
- package/dist/assets/src-BB5-5P3s.js.map +1 -0
- package/dist/assets/{translate-cDBotA-b.js → translate-2WyaRVCr.js} +11 -9
- package/dist/assets/translate-2WyaRVCr.js.map +1 -0
- package/dist/assets/{usdt-DxxLdG60.js → usdt-BLazHiaP.js} +3 -3
- package/dist/assets/{usdt-DxxLdG60.js.map → usdt-BLazHiaP.js.map} +1 -1
- package/dist/assets/{words-qH8gGtmc.js → words-BaumxjXe.js} +5 -3
- package/dist/assets/words-BaumxjXe.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-tSZELCPQ.js.map +0 -1
- package/dist/assets/apiKit-BFk7GAk9.js.map +0 -1
- package/dist/assets/apps-C5Mi6x9Q.js.map +0 -1
- package/dist/assets/buttons-Bxxu3lSk.js +0 -2
- package/dist/assets/buttons-Cf70NVYq.js.map +0 -1
- package/dist/assets/errors-mnjSQlbX.js.map +0 -1
- package/dist/assets/fileBytesIdb-CsSQcSxD.js +0 -2
- package/dist/assets/groupFiles-D9Ttlm3M.js.map +0 -1
- package/dist/assets/host-DpypH-fR.js.map +0 -1
- package/dist/assets/idb-BlH8-O3R.js.map +0 -1
- package/dist/assets/main-BwgoQZVu.js.map +0 -1
- package/dist/assets/mainline-B1urhbEZ.js.map +0 -1
- package/dist/assets/profiles-C6XWqre5.js.map +0 -1
- package/dist/assets/registry-Bazitl0a.js.map +0 -1
- package/dist/assets/resolve-Bx1Eeg-w.js.map +0 -1
- package/dist/assets/server-CnPj9wWh.js.map +0 -1
- package/dist/assets/src-BsznF3XG.js.map +0 -1
- package/dist/assets/translate-cDBotA-b.js.map +0 -1
- package/dist/assets/words-qH8gGtmc.js.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { n as traceJoin } from "./joinTrace-CjRDFy85.js";
|
|
2
|
-
import { $i as
|
|
2
|
+
import { $i as TRANSPORTS, $l as currentRelays, $o as HANDOFF_ACK, $r as checkPushEndpoint, $s as enrollDigits, $t as SEPOLIA_TEST_USDT, A as knockIdentity, Aa as forwardedAgain, Ac as APP_BUNDLE_MAGIC, An as fedimintRequestPayload, Ao as WATCH_PEER_MS, Ar as FILE_LIMITS, As as newHandoffId, Ba as readReaction, Bc as readAppBundleAsync, Bl as signTurnPacket, Bn as pairedMessageFrame, Bo as RTC_CONFIG, Br as PIN_LIMITS, C as communityHasFrame, Ca as MAX_REMOVAL_NUMBER, Cc as mergeContactKnocks, Cl as deviceEchoNonce, Co as verifyCommitSignature, Cr as pickHubs, Cs as handoffManifestFrames, Cu as randomBytes, D as decodeGroupEntryLink, Dc as requestRecords, Dl as newDeviceSetSecret, Dn as decodeBolt11, Do as DHT_POLL_INTERVALS, Dr as readLobby, Ds as handoffRetryAfter, Du as utf8Encode, Ea as dhtEditId, Ec as readLinkRecord, El as devicePingFrame, Er as readBeaconHead, Es as handoffReleaseFrame, Eu as utf8Decode, F as GroupWakeLimiter, Fa as ReactionWindow, Fi as capsDescriptors, Fl as TURN_LAST_SEQUENCE, Fn as GhostLink, Fo as webLocalFetch, Fs as readHandoffHello, Ga as replySnippet, Gc as appRef, Gl as turnStatedVerifier, Gn as GROUP_FILE_LIMITS, Go as contactRtcConfig, Gr as readPin, Gs as signTombstone, Gt as encodeDidDhtDeactivated, H as GroupSession, Ha as wireReaction, Hl as turnInstance, Hn as engineError, Hr as nextPinNumber, Hs as readSetUpdate, I as groupWakeFrame, Ia as nextReactionNumber, Ii as dialDescriptors, Il as TURN_MAX, In as INVITE_TAKEN, Io as LIMITS, Ir as TypingSender, Is as readHandoffPake, J as parseCommunityEdit, Jc as isAppKey, Jr as deviceWakeRequest, Jt as signDidDhtPacket, K as GROUP_EDIT_TEXT_BYTES, Ka as BUTTON_ID, Kl as turnVerifierMark, Kr as WAKE_CALL_INTERVAL_MS, Ks as verifySetUpdate, Kt as encodeDidDhtPacket, L as groupWakes, La as queueReaction, Lc as isAppUrl, Ll as firstDeviceSetSecret, Ln as LIVENESS_PING_MS, Lo as decodeControl, Ls as readHandoffTurnFrame, M as mergeKnocks, Ma as COMMUNITY_REACTION_FRAME, Ml as TURN_SETTLE_MS, Mn as isFederationId, Mo as GhostlyHttpError, Mr as transferEnded, Ms as readHandoffCancel, N as readKnocks, Na as GROUP_REACTION_FRAME, Nc as appDigest, Ni as CapsExchange, Nl as classifyTurnRead, Nn as parseCashuRequestPayload, No as formatLocalTarget, Nr as transferStalled, Ns as readHandoffDone, O as encodeGroupEntryLink, Oc as seenEntry, Ol as seedSigner, On as ENDPOINT, Or as shouldBeHub, Os as handoffStreamKey, Pa as REACTION_LIMITS, Pc as appViewOf, Pi as DHT_TEXT_CAPABILITY, Pl as turnPutSummary, Pn as parseFedimintRequestPayload, Po as parseLocalTarget, Ps as readHandoffHave, Qi as validExternalKey, Qn as readGroupFileMeta, Qo as serviceIdFromName, Qr as wakeRequest, Qs as enrollCancelReason, Qt as PaymentPreflightError, R as parseGroupWakeFrame, Ra as reactionEmoji, Rc as pacer, Rl as nextTurnPosition, Rn as PAIRED_FRAME_TOO_LARGE, Ro as encodeControl, Rr as typingActivity, Rs as readHandoffVerified, S as GROUP_READ_NOTE_COMMUNITY, Sa as EDIT_RATE_WINDOW_MS, Sc as makeStampPaced, Sl as deviceEchoFrame, So as rosterHas, Sr as newerHead, Ss as handoffHelloFrame, T as encodeCommunityLink, Ta as RateWindow, Tc as readKnockSlot, Tl as deviceLinkPairing, To as DirectPathWatch, Tr as readBeacon, Ts as handoffPakeFrame, Tu as toZ32, U as frameBytes, Ua as pairedReplyAuthor, Uc as APP_STATEMENT_LIMITS, Ui as emptyIdentityLedger, Ul as turnKeys, Un as engineText, Ur as pinIsNewer, Us as setAckFrame, Ut as didDhtDocument, V as GROUP_READ_NOTE, Va as validReactionNumber, Vc as sha256Paced, Vl as signTurnRelease, Vn as EngineError, Vr as mayPin, Wa as readReply, Wc as appFingerprint, Wl as turnName, Wn as parseEngineError, Wr as pinNumberHolds, Ws as setUpdateFrame, Wt as didDhtFromPublicKey, X as groupName, Xc as readAppRevocation, Xi as PeerProofs, Xl as RelayTransport, Xn as groupFileFallback, Xo as HTTP_SERVICE_PROTO, Xr as parseWakeFrame, Xt as EVM_TEST_CHAINS, Y as mentionsMember, Yc as isAppRef, Yi as lastSharedWithMe, Yo as emptyLinkRecords, Yr as newWakeToken, Yt as ETHEREUM_USDT, Zi as emptyProofLedger, Zo as LEGACY_SERVICES, Zr as relayRequest, Zs as enrollCancelFrame, Zt as ONCHAIN_PROVIDER, _ as groupTypingEpoch, _a as parseVoiceMeta, _c as contactDay, _i as newMailbox, _l as inviteOwnership, _r as freshHubs, _s as handoffContext, _t as normalizeAtprotoHandle, a as appRevocationFor, aa as peekDhtMailbox, ac as readEnrollHello, ai as isAppVersion, al as readCanonicalJson, an as assertTokenUnits, as as HANDOFF_PAKE, au as withRequestOptions, b as COMMUNITY_LIMITS, ba as parseVideoMeta, bc as knockSlotRecords, bl as ENROLL_CAPABILITY, bo as parseGroupCommit, br as mergeBeacon, bs as handoffDigest, bu as bytesEqual, c as checkAppBeforeRun, ca as formatFileSize, cc as endedRequests, ci as EDIT_CAPABILITY, cl as readContactLink, cn as validatePaymentTarget, cr as readGroupSignal, cs as HANDOFF_TIMINGS, cu as createRelayPayload, dc as planKnocks, di as HOLD_CAPABILITY, dl as readDeviceInvite, dn as SPARK_PROVIDER, do as claimedTime, dr as meshHubs, ds as filePartName, ea as automaticTransport, ec as enrollDoneFrame, ei as vapidKeysMatch, eo as STATUS_CARD_LIMITS, es as HANDOFF_CANCEL, eu as normalizeRelayUrl, fc as settleRequest, fi as HOLD_DATED_BACK_MS, fl as OwnInviteError, fn as sparkAddressKind, fo as heardTime, fr as pickMeshHubs, fs as handoffAttemptAllowed, fu as createIdentity, g as GroupTypingBoard, ga as fileMessageText, gc as REQUEST_LIFETIME_MS, gi as isHoldUrl, gl as inviteLink, gn as isPubkyKey, go as GROUP_MEMBER_CAP, gr as doorHubs, gs as handoffCancelFrame, gt as isAtprotoDid, gu as verify, hc as ContactRequestError, hi as HoldRefusedError, hl as encodeInviteCode, ho as GROUP_ADMIN_OFF_ERROR, hr as beaconRecords, hs as handoffBusyFrame, hu as publicKeyFromZ32, i as addedAppPermissions, ia as DHT_MESSAGE_TTL, ic as readEnrollGrant, ii as chatAppId, in as arkAddressPrefix, is as HANDOFF_OFFER, iu as isDiscoveryBudgetError, j as knockRecords, ja as readForwarded, jc as APP_ICON_PATH, jl as TURN_RAISE_READ_TIMEOUT_MS, jn as findEndpoint, jo as presenceSeenAt, js as readHandoffAck, k as entryParams, ka as parseLinkPreview, kc as APP_BUNDLE_LIMITS, kl as webCryptoSigner, kn as cashuRequestPayload, ko as RELAY_POLL_INTERVALS, kr as ChatFiles, ks as handoffVersions, l as planAppUpdate, la as sanitizeFileName, lc as inboxRecord, li as STATUS_CARD_CAPABILITY, ll as createDeviceInvite, ln as walletNetworkOf, lo as statusCardText, lr as MESH_HUBS, ls as HANDOFF_VERIFIED, mc as turnOff, mi as HoldKeys, ml as decodeInviteCode, mn as isBitcoinAddress, mo as shownTime, mr as beaconKeys, ms as handoffAttemptSucceeded, mu as identityFromSeedB64, n as readX401SdJwtVc, nc as enrollHelloFrame, ni as isServeId, nn as USDT_PUBLIC_RPC, nr as CarriedTransport, ns as HANDOFF_HAVE, nu as traceLink, o as appStoreDecision, oa as DHT_FILE_CAPABILITY, oc as verifyEnrollProof, oi as APPS_CAPABILITY, ol as createContactLink, on as assertWholeSats, oo as checkStatusCard, os as HANDOFF_PIECE_BYTES, ou as PacketTooLargeError, p as readAppStoreSteps, pc as takeRequest, pi as HOLD_LIMITS, pl as createChatInvite, pn as sparkInvoiceDetails, po as receivedTimestamp, pr as COMMUNITY_TOPOLOGY, ps as handoffAttemptFailed, pu as identityFromSeed, q as carryMentions, qc as isAppHash, qi as receivedIdentityStatus, ql as DEFAULT_RELAYS, qo as parseCallSignal, qr as WakeLimiter, r as sameX401HolderJwk, rc as enrollProofFrame, rl as canonicalJson, rn as WALLET_NETWORKS, rs as HANDOFF_HELLO, ru as budgetRetryMs, s as appUpdateDecision, sa as dhtFileId, sc as clearMissed, si as BUTTONS_CAPABILITY, sl as encodeContactLink, sn as formatPaymentAmount, so as sameButtonText, sr as groupSignalFrame, ss as HANDOFF_REQUEST, t as newX401HolderKey, tc as enrollGrantFrame, ti as APP_RANGE_LIMITS, tl as parseImageMeta, tn as TEST_USDT_FAUCET_AMOUNT, ts as HANDOFF_DONE, u as APP_STORE_LIMITS, ua as sanitizeMime, uc as newInbox, ui as UPGRADE_CAPABILITY, ul as deviceInviteJoinerParams, un as SPARK_NETWORKS, uo as arrivalKey, ur as mayBeHub, us as NO_ATTEMPTS, v as openGroupTyping, vc as knockSlotIdentity, vi as readManifest, vo as MEMBER_KEY, vr as lobbyKeys, vs as handoffContextProof, vu as sanitizeAvatar, w as decodeCommunityLink, wa as REMOVED_TEXT, wc as openRequest, wl as deviceKeyZ32, wo as edgeParams, wr as rankHubs, ws as handoffOfferFrame, wu as toBase64Url, x as CommunitySession, xa as EDIT_BUFFER_MS, xc as linkRecords, xl as HANDOFF_CAPABILITY, xo as rosterAdmin, xr as mergeLobby, xs as handoffEphemeral, xu as fromBase64Url, y as sealGroupTyping, yc as knockSlotOf, yl as DEVICES_CAPABILITY, yo as commitHash, yr as lobbyRecords, ys as handoffDataFrame, yu as sanitizeDisplayText, z as GROUP_LIMITS, za as reactionIsNewer, zl as readTurnPacket, zn as pairedMessageFits, zs as sealHandoffPiece } from "./src-BB5-5P3s.js";
|
|
3
3
|
import { i as SourceUnreachableError, n as PROVIDER_PLATFORMS, o as isNothingSpentError, r as SourceConfigError, t as NothingSpentError, u as redact } from "./types-C4_KafL_.js";
|
|
4
4
|
import { t as bitcoindRpc } from "./bitcoindProvider-DGw3xBSa.js";
|
|
5
|
-
import { t as nwc } from "./nwcProvider-
|
|
6
|
-
import { a as 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-
|
|
7
|
-
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-
|
|
8
|
-
import { $ as
|
|
9
|
-
import { i as fedimintDatabase, n as createIrohWebEndpoint, o as loadFedimintSdk, r as irohRelayProblem, t as DEFAULT_IROH_RELAYS } from "./irohWeb-
|
|
5
|
+
import { t as nwc } from "./nwcProvider-DjWmEn3j.js";
|
|
6
|
+
import { a as clearProfileStores, c as deleteDatabase, d as newestWalletTx, f as openDb, g as wrap, h as transact, i as STORES$1, l as errorLine, m as store, n as APP_STORAGE_SCOPE_INDEX, o as committed, p as profileOpenFailure, r as CARD_INDEX, s as databaseName, t as APP_STORAGE_CHAT_INDEX, u as fileStore } from "./idb-BkOJES5_.js";
|
|
7
|
+
import { a as sealSeed, i as newDeviceKey, o as unsealSeed, r as intentRepository } from "./networkReason-N2vAaoth.js";
|
|
8
|
+
import { $ as WrongNetworkError, A as IdentityProofs, B as ProviderSources, C as FileAppender, D as streamStored, E as storedSize, F as LightningCards, G as breezDatabaseInUse, H as CASHU_MINT_SOURCE, I as cardsKey, J as iceServerProblem, K as breezDatabasesFor, L as isRecoveryPhrase, M as sealSecret, N as whenDataKeyDropped, P as CASHU_CARD, Q as ModeGate, R as normalizePhrase, S as WALLET_TYPES, T as removeStored, U as cashuMint, V as sourceKey, W as breezDatabase, X as relayOnlyProblem, Y as iceServerSetting, Z as ModeChanged, _ as crossNetwork, a as storedGroupFiles, at as setSingleWriterGate, b as walletInstances, c as receivedPairedReply, d as paymentAlias, et as networkLabel, f as paymentWireId, g as createTiming, h as createFailure, i as groupOfFile, it as setAwayWallets, j as openSecret, l as replyRef, m as assertConfirmedReal, n as groupFileId, nt as refuseAway, o as groupReply, p as WALLET_NAMES, q as dropBreezDatabase, r as groupFileText, rt as requireTurn, s as pairedWireReply, t as GroupFileDesk, tt as awayFrom, u as replyTo, v as paymentNetwork, w as readStored$1, y as paymentNetworksOf, z as lightningPaying } from "./groupFiles-CBJIEvCE.js";
|
|
9
|
+
import { i as fedimintDatabase, n as createIrohWebEndpoint, o as loadFedimintSdk, r as irohRelayProblem, t as DEFAULT_IROH_RELAYS } from "./irohWeb-DxeEgQ-W.js";
|
|
10
10
|
import { c as isTestMint, d 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-BrlY773j.js";
|
|
11
|
-
import { _ as reserveAdapterIds, b as testBuild, f as setOwnDidSource, g as registeredOnchainProviders, h as registeredLightningProviders, l as chosenResolver, n as resolveAtprotoDid, p as onAdaptersChanged, t as assertPublicServer, v as boundedIdentityFetch
|
|
12
|
-
import {
|
|
13
|
-
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-
|
|
11
|
+
import { _ as reserveAdapterIds, b as testBuild, f as setOwnDidSource, g as registeredOnchainProviders, h as registeredLightningProviders, l as chosenResolver, n as resolveAtprotoDid, p as onAdaptersChanged, t as assertPublicServer, v as boundedIdentityFetch } from "./resolve-BvHkAhDH.js";
|
|
12
|
+
import { n as MAX_BACKUP_BYTES, t as BACKUP_MEDIA_TYPE } from "./envelope-DYiGwzq_.js";
|
|
13
|
+
import { c as fileSpace, f as FILE_BYTES_STEP, o as fileBytes, r as blobDigest, s as fileBytesOf, u as removeFileBytes } from "./fileBytes-DNgrRL0R.js";
|
|
14
14
|
import { t as hyperdhtRelayProblem } from "./hyperdhtRelay-BT_wRxab.js";
|
|
15
15
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
16
16
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
@@ -198,7 +198,7 @@ function viewNews(before, after) {
|
|
|
198
198
|
//#endregion
|
|
199
199
|
//#region ../browser/src/engine/paymentAdapters/usdtWallet.ts
|
|
200
200
|
/** 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-
|
|
201
|
+
var loadUsdt = () => import("./usdt-BLazHiaP.js");
|
|
202
202
|
/** Every new profile starts with this wallet: an address to receive on, nothing to set up. */
|
|
203
203
|
var DEFAULT_USDT = {
|
|
204
204
|
network: "ethereum",
|
|
@@ -647,7 +647,7 @@ async function restoreArkDatabase(walletId, snapshot) {
|
|
|
647
647
|
//#endregion
|
|
648
648
|
//#region ../browser/src/engine/paymentAdapters/arkWallet.ts
|
|
649
649
|
/** 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-
|
|
650
|
+
var loadArkade = () => import("./arkade-BFE8KkEE.js");
|
|
651
651
|
/** How long a Testnet wallet about to make way for another waits for its server to say what it holds. */
|
|
652
652
|
var RETIRE_READ_MS = 1e4;
|
|
653
653
|
/** Every new profile starts with this wallet: nothing to set up before receiving. */
|
|
@@ -1095,10 +1095,10 @@ var NETWORK = {
|
|
|
1095
1095
|
signet: "Signet",
|
|
1096
1096
|
regtest: "Regtest"
|
|
1097
1097
|
};
|
|
1098
|
-
var loading$
|
|
1098
|
+
var loading$3;
|
|
1099
1099
|
/** Loads the WebAssembly once, on first use: profiles that never open a Bark wallet never fetch its 7.7 MB. */
|
|
1100
1100
|
function loadBarkSdk() {
|
|
1101
|
-
return loading$
|
|
1101
|
+
return loading$3 ??= (async () => {
|
|
1102
1102
|
const [bark, wasm] = await Promise.all([import("@secondts/bark/web"), import("./bark_ffi_wasm_bg-EY2uc0Bx.js")]);
|
|
1103
1103
|
await bark.default({ module_or_path: wasm.default });
|
|
1104
1104
|
return {
|
|
@@ -1137,7 +1137,7 @@ function loadBarkSdk() {
|
|
|
1137
1137
|
}
|
|
1138
1138
|
};
|
|
1139
1139
|
})().catch((error) => {
|
|
1140
|
-
loading$
|
|
1140
|
+
loading$3 = void 0;
|
|
1141
1141
|
throw error;
|
|
1142
1142
|
});
|
|
1143
1143
|
}
|
|
@@ -2678,10 +2678,10 @@ var FedimintAdapter = class {
|
|
|
2678
2678
|
};
|
|
2679
2679
|
//#endregion
|
|
2680
2680
|
//#region ../browser/src/engine/paymentAdapters/providers/breezSdk.ts
|
|
2681
|
-
var loading$
|
|
2681
|
+
var loading$2;
|
|
2682
2682
|
/** Loads the WebAssembly once, on first use: profiles that never pick Breez never fetch its 12.8 MB. */
|
|
2683
2683
|
function loadBreezSdk() {
|
|
2684
|
-
return loading$
|
|
2684
|
+
return loading$2 ??= (async () => {
|
|
2685
2685
|
const breez = await import("./web-DwgdhfcY.js");
|
|
2686
2686
|
await breez.default();
|
|
2687
2687
|
return { async connect({ network, mnemonic, apiKey, storage }) {
|
|
@@ -2697,7 +2697,7 @@ function loadBreezSdk() {
|
|
|
2697
2697
|
});
|
|
2698
2698
|
} };
|
|
2699
2699
|
})().catch((error) => {
|
|
2700
|
-
loading$
|
|
2700
|
+
loading$2 = void 0;
|
|
2701
2701
|
throw error;
|
|
2702
2702
|
});
|
|
2703
2703
|
}
|
|
@@ -3553,6 +3553,16 @@ var SWAP_SETTLED_MS = 12e4;
|
|
|
3553
3553
|
function swapSettledAt(review, prepared) {
|
|
3554
3554
|
return Math.max((review.submittedAt ?? review.createdAt) + CASHU_REQUEST_TIMEOUT_MS + SWAP_SETTLED_MS, (prepared.attemptEndedAt ?? 0) + SWAP_SETTLED_MS);
|
|
3555
3555
|
}
|
|
3556
|
+
/**
|
|
3557
|
+
* The mint answered, and refused. cashu-ts turns a refusal of a keyset the mint retired or does not know (codes
|
|
3558
|
+
* 12xxx) into a `StaleKeysetError` once it has reloaded the mint's keysets: the mint's refusal all the same, with it
|
|
3559
|
+
* as its cause. By name, as cashu-ts's own `isMintOperationError`, so it needs no import of the library.
|
|
3560
|
+
*/
|
|
3561
|
+
function mintRefused(error) {
|
|
3562
|
+
if (!(error instanceof Error)) return false;
|
|
3563
|
+
if (error.name === "StaleKeysetError") return mintRefused(error.cause);
|
|
3564
|
+
return error.name === "MintOperationError" && "code" in error;
|
|
3565
|
+
}
|
|
3556
3566
|
var NEVER_REACHED_MINT = "The payment never reached the mint: nothing was sent, and the sats are back in your wallet. You can pay again.";
|
|
3557
3567
|
var CashuAdapter = class {
|
|
3558
3568
|
wallet;
|
|
@@ -3575,7 +3585,10 @@ var CashuAdapter = class {
|
|
|
3575
3585
|
token = await this.wallet.executeReviewedCashu(review, prepared);
|
|
3576
3586
|
} catch (error) {
|
|
3577
3587
|
prepared.attemptEndedAt = Date.now();
|
|
3578
|
-
if (persist && (
|
|
3588
|
+
if (persist && mintRefused(error)) {
|
|
3589
|
+
if (await this.wallet.reviewedCashuSpentElsewhere(prepared).catch(() => false)) return this.spentElsewhere(prepared, persist);
|
|
3590
|
+
if (await this.wallet.reviewedCashuNeverSwapped(prepared).catch(() => false)) return this.abandon(prepared, persist);
|
|
3591
|
+
}
|
|
3579
3592
|
throw error;
|
|
3580
3593
|
}
|
|
3581
3594
|
await persist?.();
|
|
@@ -4100,7 +4113,7 @@ var appLoader = async () => {
|
|
|
4100
4113
|
wasm: await fetch(url.default)
|
|
4101
4114
|
};
|
|
4102
4115
|
};
|
|
4103
|
-
var loading$
|
|
4116
|
+
var loading$1;
|
|
4104
4117
|
/**
|
|
4105
4118
|
* Loads the WebAssembly once, on first use: profiles that never set up a BDK wallet never fetch its 2 MB.
|
|
4106
4119
|
* The package is wasm-pack's `bundler` build, whose entry imports the `.wasm` as an ES module (which
|
|
@@ -4108,7 +4121,7 @@ var loading$2;
|
|
|
4108
4121
|
* that entry would.
|
|
4109
4122
|
*/
|
|
4110
4123
|
function loadBdk(loader = appLoader) {
|
|
4111
|
-
return loading$
|
|
4124
|
+
return loading$1 ??= (async () => {
|
|
4112
4125
|
const { glue, wasm } = await loader();
|
|
4113
4126
|
const imports = { [WASM_IMPORTS]: glue };
|
|
4114
4127
|
let instance;
|
|
@@ -4122,7 +4135,7 @@ function loadBdk(loader = appLoader) {
|
|
|
4122
4135
|
instance.exports.__wbindgen_start?.();
|
|
4123
4136
|
return glue;
|
|
4124
4137
|
})().catch((error) => {
|
|
4125
|
-
loading$
|
|
4138
|
+
loading$1 = void 0;
|
|
4126
4139
|
throw error;
|
|
4127
4140
|
});
|
|
4128
4141
|
}
|
|
@@ -5853,7 +5866,8 @@ function fetchTransport(url, macaroon, signal) {
|
|
|
5853
5866
|
} catch (error) {
|
|
5854
5867
|
if (deadline.signal.aborted || closed.signal.aborted || signal?.aborted) throw error;
|
|
5855
5868
|
const origin = globalThis.location?.origin;
|
|
5856
|
-
|
|
5869
|
+
const hint = origin ? `From a browser it must allow this origin (restcors=${origin}) and have a certificate the browser trusts.` : "Check its address, and that its certificate is one this device trusts.";
|
|
5870
|
+
throw Object.assign(/* @__PURE__ */ new Error(`Could not reach the node. ${hint}`), { cause: error });
|
|
5857
5871
|
}
|
|
5858
5872
|
if (!response.body) return {
|
|
5859
5873
|
status: response.status,
|
|
@@ -6163,7 +6177,7 @@ var lnd = {
|
|
|
6163
6177
|
kind: "secret",
|
|
6164
6178
|
optional: true,
|
|
6165
6179
|
placeholder: "-----BEGIN CERTIFICATE-----…",
|
|
6166
|
-
help: "Desktop: the node's tls.cert, pinned (the node must present exactly this one). Leave empty for a certificate from a public authority."
|
|
6180
|
+
help: "Desktop only: the node's tls.cert, pinned (the node must present exactly this one). Leave empty for a certificate from a public authority; anywhere else it must stay empty."
|
|
6167
6181
|
}
|
|
6168
6182
|
],
|
|
6169
6183
|
experimental: true,
|
|
@@ -6172,7 +6186,9 @@ var lnd = {
|
|
|
6172
6186
|
},
|
|
6173
6187
|
async create(settings, host) {
|
|
6174
6188
|
const { url, macaroon, scope, certificate } = lndSettings(settings);
|
|
6175
|
-
|
|
6189
|
+
const desktop = host.platform === "desktop" && host.invoke;
|
|
6190
|
+
if (certificate && !desktop) throw new SourceConfigError("Only the desktop app can pin the node's TLS certificate. Leave the certificate empty here: the node then needs a certificate this device trusts.");
|
|
6191
|
+
return new LndLightning(desktop ? tauriTransport(desktop, url, macaroon.hex, certificate) : fetchTransport(url, macaroon.hex, host.signal), scope);
|
|
6176
6192
|
}
|
|
6177
6193
|
};
|
|
6178
6194
|
//#endregion
|
|
@@ -6754,544 +6770,6 @@ function defaultRegistry() {
|
|
|
6754
6770
|
};
|
|
6755
6771
|
}
|
|
6756
6772
|
//#endregion
|
|
6757
|
-
//#region ../browser/src/shared/profileKey.ts
|
|
6758
|
-
/**
|
|
6759
|
-
* Only the record key can hold a newline: the other parts come from the code, so the joined binding still reads one
|
|
6760
|
-
* way (the first two lines, the last line, and the key between them).
|
|
6761
|
-
*/
|
|
6762
|
-
function binding(b) {
|
|
6763
|
-
for (const part of [
|
|
6764
|
-
b.db,
|
|
6765
|
-
b.store,
|
|
6766
|
-
b.field
|
|
6767
|
-
]) if (!part || part.includes("\n")) throw new Error("Invalid sealed field binding");
|
|
6768
|
-
return new TextEncoder().encode([
|
|
6769
|
-
"ghostly-field/2",
|
|
6770
|
-
b.db,
|
|
6771
|
-
b.store,
|
|
6772
|
-
b.key,
|
|
6773
|
-
b.field
|
|
6774
|
-
].join("\n"));
|
|
6775
|
-
}
|
|
6776
|
-
function isSealedField(value) {
|
|
6777
|
-
const v = value;
|
|
6778
|
-
return !!v && typeof v === "object" && v.v === 2 && typeof v.iv === "string" && typeof v.ct === "string";
|
|
6779
|
-
}
|
|
6780
|
-
/** Seals one field under DK with a fresh random 96-bit nonce and no KDF per field. */
|
|
6781
|
-
async function sealField(key, where, value) {
|
|
6782
|
-
const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
|
|
6783
|
-
const ct = new Uint8Array(await crypto.subtle.encrypt({
|
|
6784
|
-
name: "AES-GCM",
|
|
6785
|
-
iv,
|
|
6786
|
-
additionalData: binding(where)
|
|
6787
|
-
}, key, new TextEncoder().encode(value)));
|
|
6788
|
-
return {
|
|
6789
|
-
v: 2,
|
|
6790
|
-
iv: toBase64Url(iv),
|
|
6791
|
-
ct: toBase64Url(ct)
|
|
6792
|
-
};
|
|
6793
|
-
}
|
|
6794
|
-
/** Opens a field sealed for exactly this place under this DK; anything else fails instead of opening wrong. */
|
|
6795
|
-
async function openField(key, where, sealed) {
|
|
6796
|
-
if (!isSealedField(sealed)) throw new Error("Unsupported sealed field version");
|
|
6797
|
-
const aad = binding(where);
|
|
6798
|
-
try {
|
|
6799
|
-
const iv = fromBase64Url$1(sealed.iv);
|
|
6800
|
-
if (iv.length !== 12) throw new Error("nonce");
|
|
6801
|
-
return new TextDecoder().decode(await crypto.subtle.decrypt({
|
|
6802
|
-
name: "AES-GCM",
|
|
6803
|
-
iv,
|
|
6804
|
-
additionalData: aad
|
|
6805
|
-
}, key, fromBase64Url$1(sealed.ct)));
|
|
6806
|
-
} catch {
|
|
6807
|
-
throw new Error("A sealed field could not be opened: it was changed, or it belongs to another record");
|
|
6808
|
-
}
|
|
6809
|
-
}
|
|
6810
|
-
//#endregion
|
|
6811
|
-
//#region ../browser/src/engine/dataKey.ts
|
|
6812
|
-
var PEER_DB = "ghostly";
|
|
6813
|
-
/**
|
|
6814
|
-
* The profile's data key (DK), when the profile is encrypted and unlocked: the one slot the engine owns. A
|
|
6815
|
-
* non-extractable key; nothing writes it anywhere. Empty, every secret is sealed as today (version 1).
|
|
6816
|
-
*/
|
|
6817
|
-
var slot = null;
|
|
6818
|
-
var onDrop = /* @__PURE__ */ new Set();
|
|
6819
|
-
/** A cache of opened secrets empties itself when the key goes. Returns the way to stop listening. */
|
|
6820
|
-
function whenDataKeyDropped(drop) {
|
|
6821
|
-
onDrop.add(drop);
|
|
6822
|
-
return () => {
|
|
6823
|
-
onDrop.delete(drop);
|
|
6824
|
-
};
|
|
6825
|
-
}
|
|
6826
|
-
async function sealSecret(value, at) {
|
|
6827
|
-
if (slot) return sealField(slot, {
|
|
6828
|
-
db: PEER_DB,
|
|
6829
|
-
...at
|
|
6830
|
-
}, value);
|
|
6831
|
-
const deviceKey = newDeviceKey();
|
|
6832
|
-
return {
|
|
6833
|
-
sealed: await sealSeed(value, deviceKey),
|
|
6834
|
-
deviceKey
|
|
6835
|
-
};
|
|
6836
|
-
}
|
|
6837
|
-
/** Reads both versions: a profile being encrypted holds some of each until its migration ends. */
|
|
6838
|
-
async function openSecret(secret, at) {
|
|
6839
|
-
if (!isSealedField(secret)) return unsealSeed(secret.sealed, secret.deviceKey);
|
|
6840
|
-
if (!slot) throw new Error("This profile is locked. Enter its passphrase first.");
|
|
6841
|
-
return openField(slot, {
|
|
6842
|
-
db: PEER_DB,
|
|
6843
|
-
...at
|
|
6844
|
-
}, secret);
|
|
6845
|
-
}
|
|
6846
|
-
//#endregion
|
|
6847
|
-
//#region ../browser/src/proofs/load.ts
|
|
6848
|
-
/**
|
|
6849
|
-
* The identity proof providers, loaded on first need and not with the app: they and their libraries (OpenPGP, the
|
|
6850
|
-
* Bitcoin signer, the DID, AT Protocol and OpenID Connect checks) are a large part of the code, and the first screen
|
|
6851
|
-
* draws none of it. The engine loads them with the profile's proofs; the UI once it draws something about identities.
|
|
6852
|
-
*/
|
|
6853
|
-
var registry;
|
|
6854
|
-
var loading$1;
|
|
6855
|
-
var listeners = /* @__PURE__ */ new Set();
|
|
6856
|
-
function loadIdentityProviders() {
|
|
6857
|
-
return loading$1 ??= import("./registry-BlSTJlbv.js").then((m) => {
|
|
6858
|
-
registry = m;
|
|
6859
|
-
for (const listener of listeners) listener();
|
|
6860
|
-
return m;
|
|
6861
|
-
}, (error) => {
|
|
6862
|
-
loading$1 = void 0;
|
|
6863
|
-
throw error;
|
|
6864
|
-
});
|
|
6865
|
-
}
|
|
6866
|
-
/** The providers (built in, from plugins, the test ones when asked for), once loaded; none before. */
|
|
6867
|
-
var loadedIdentityProviders = () => registry?.identityProviders() ?? [];
|
|
6868
|
-
//#endregion
|
|
6869
|
-
//#region ../browser/src/engine/identities.ts
|
|
6870
|
-
/** Where a proof key's seed belongs: by proof id, so it still opens once the proof moved to the revocations. */
|
|
6871
|
-
var proofKeyAt = (id) => ({
|
|
6872
|
-
store: STORES$1.settings,
|
|
6873
|
-
key: id,
|
|
6874
|
-
field: "identityProof.seed"
|
|
6875
|
-
});
|
|
6876
|
-
var KEY$2 = "identityProofs";
|
|
6877
|
-
var REVOCATIONS = "identityRevocations";
|
|
6878
|
-
/** Relays and the DHT forget a record within hours: republish revocations this often while the app runs. */
|
|
6879
|
-
var REPUBLISH_MS$1 = 36e5;
|
|
6880
|
-
/** How often the contacts' proofs are looked up for a revocation (and once shortly after start). */
|
|
6881
|
-
var REVOCATION_CHECK_MS = 432e5;
|
|
6882
|
-
/**
|
|
6883
|
-
* After a contact withdraws a proof, how long to wait before each lookup for its revocation (WISP 300: removing a proof withdraws it from
|
|
6884
|
-
* every chat and revokes it). The notice goes out before the revocation is published, so not at once; each try backs
|
|
6885
|
-
* off, and the first that finds it stops the rest. The 12 h check covers it after that.
|
|
6886
|
-
*/
|
|
6887
|
-
var WITHDRAWN_REVOCATION_TRIES_MS = [
|
|
6888
|
-
2e4,
|
|
6889
|
-
6e4,
|
|
6890
|
-
18e4
|
|
6891
|
-
];
|
|
6892
|
-
var DRAFT_TTL = 18e5;
|
|
6893
|
-
var MAX_DRAFTS$1 = 4;
|
|
6894
|
-
var MAX_PROOFS = 32;
|
|
6895
|
-
var now = () => Math.floor(Date.now() / 1e3);
|
|
6896
|
-
/**
|
|
6897
|
-
* Identity proofs, engine side: the profile's own proofs (made once, on the Identities page) and, per
|
|
6898
|
-
* chat, the `IdentityExchange` that shares them with that contact and checks what the contact shares.
|
|
6899
|
-
* Providers come from the registry; their `verify` runs here, through the shared checks.
|
|
6900
|
-
*/
|
|
6901
|
-
var IdentityProofs = class {
|
|
6902
|
-
host;
|
|
6903
|
-
providers;
|
|
6904
|
-
proofs = [];
|
|
6905
|
-
revocations = [];
|
|
6906
|
-
/** Unsealed proof-key seeds, by proof id, for this run only. */
|
|
6907
|
-
seeds = /* @__PURE__ */ new Map();
|
|
6908
|
-
timers = [];
|
|
6909
|
-
unlisten;
|
|
6910
|
-
drafts = /* @__PURE__ */ new Map();
|
|
6911
|
-
exchanges = /* @__PURE__ */ new Map();
|
|
6912
|
-
errors = /* @__PURE__ */ new Map();
|
|
6913
|
-
/** Chats whose current connection already got the hello: "ready" is reported more than once per connection. */
|
|
6914
|
-
greeted = /* @__PURE__ */ new Set();
|
|
6915
|
-
fetch;
|
|
6916
|
-
constructor(host, providers = loadedIdentityProviders) {
|
|
6917
|
-
this.host = host;
|
|
6918
|
-
this.providers = providers;
|
|
6919
|
-
this.fetch = boundedIdentityFetch({ online: host.online });
|
|
6920
|
-
}
|
|
6921
|
-
/** The profile's proofs, and the providers that check and show them: loaded here, not with the app. */
|
|
6922
|
-
async load() {
|
|
6923
|
-
const providers = loadIdentityProviders();
|
|
6924
|
-
const settings = await store(STORES$1.settings, "readonly");
|
|
6925
|
-
[this.proofs, this.revocations] = await Promise.all([wrap(settings.get(KEY$2)).then((v) => v ?? []), wrap(settings.get(REVOCATIONS)).then((v) => v ?? [])]);
|
|
6926
|
-
await providers;
|
|
6927
|
-
}
|
|
6928
|
-
/** Background work: republish revocations, look up the contacts' proofs for revocations. */
|
|
6929
|
-
start() {
|
|
6930
|
-
const every = (ms, first, work) => {
|
|
6931
|
-
const tick = () => {
|
|
6932
|
-
work().catch(() => {}).finally(() => {
|
|
6933
|
-
this.timers.push(setTimeout(tick, ms));
|
|
6934
|
-
});
|
|
6935
|
-
};
|
|
6936
|
-
this.timers.push(setTimeout(tick, first));
|
|
6937
|
-
};
|
|
6938
|
-
every(REPUBLISH_MS$1, 5e3, () => this.republish());
|
|
6939
|
-
every(REVOCATION_CHECK_MS, 6e4, () => this.checkRevocations());
|
|
6940
|
-
this.unlisten ??= whenDataKeyDropped(() => this.forgetSeeds());
|
|
6941
|
-
}
|
|
6942
|
-
stop() {
|
|
6943
|
-
for (const t of this.timers) clearTimeout(t);
|
|
6944
|
-
this.timers = [];
|
|
6945
|
-
this.unlisten?.();
|
|
6946
|
-
this.unlisten = void 0;
|
|
6947
|
-
this.forgetSeeds();
|
|
6948
|
-
}
|
|
6949
|
-
forgetSeeds() {
|
|
6950
|
-
for (const seed of this.seeds.values()) seed.fill(0);
|
|
6951
|
-
this.seeds.clear();
|
|
6952
|
-
}
|
|
6953
|
-
async save(proofs, revocations = this.revocations) {
|
|
6954
|
-
await transact([STORES$1.settings], (stores) => {
|
|
6955
|
-
stores[STORES$1.settings].put(proofs, KEY$2);
|
|
6956
|
-
stores[STORES$1.settings].put(revocations, REVOCATIONS);
|
|
6957
|
-
});
|
|
6958
|
-
this.proofs = proofs;
|
|
6959
|
-
this.revocations = revocations;
|
|
6960
|
-
this.host.emit();
|
|
6961
|
-
}
|
|
6962
|
-
async seedOf(id, sealed) {
|
|
6963
|
-
let seed = this.seeds.get(id);
|
|
6964
|
-
if (!seed) {
|
|
6965
|
-
seed = fromBase64Url(await openSecret(sealed, proofKeyAt(id)));
|
|
6966
|
-
this.seeds.set(id, seed);
|
|
6967
|
-
}
|
|
6968
|
-
return seed;
|
|
6969
|
-
}
|
|
6970
|
-
ctx() {
|
|
6971
|
-
return {
|
|
6972
|
-
now: now(),
|
|
6973
|
-
signal: AbortSignal.timeout(3e4),
|
|
6974
|
-
fetch: this.fetch
|
|
6975
|
-
};
|
|
6976
|
-
}
|
|
6977
|
-
verify = (statement, evidence) => verifyIdentity(this.providers(), statement, evidence, this.ctx());
|
|
6978
|
-
revoked = async (statement) => {
|
|
6979
|
-
if (!this.host.online()) return false;
|
|
6980
|
-
const records = await this.host.resolve(statement.binding.key);
|
|
6981
|
-
return !!records && revokesIdentity(records, statement.id);
|
|
6982
|
-
};
|
|
6983
|
-
async local(id) {
|
|
6984
|
-
const p = this.proofs.find((x) => identityStatement(x.binding).id === id);
|
|
6985
|
-
return p && {
|
|
6986
|
-
statement: identityStatement(p.binding),
|
|
6987
|
-
evidence: p.evidence,
|
|
6988
|
-
seed: await this.seedOf(id, p.seed)
|
|
6989
|
-
};
|
|
6990
|
-
}
|
|
6991
|
-
/** Step 1 of adding a proof: a fresh proof key and the statement the external identity must sign. */
|
|
6992
|
-
begin({ provider, subject, validityDays }) {
|
|
6993
|
-
const p = this.providers().find((x) => x.id === provider);
|
|
6994
|
-
if (!p) throw new Error("Unknown kind of identity");
|
|
6995
|
-
const days = validityDays ?? p.validity.defaultDays;
|
|
6996
|
-
if (!Number.isInteger(days) || days < 1 || days > p.validity.maxDays) throw new Error(`Choose between 1 and ${p.validity.maxDays} days`);
|
|
6997
|
-
const canonical = p.subject.normalize(subject);
|
|
6998
|
-
for (const [id, d] of this.drafts) if (Date.now() - d.at > DRAFT_TTL) {
|
|
6999
|
-
d.seed.fill(0);
|
|
7000
|
-
this.drafts.delete(id);
|
|
7001
|
-
}
|
|
7002
|
-
while (this.drafts.size >= MAX_DRAFTS$1) {
|
|
7003
|
-
const [id, d] = this.drafts.entries().next().value;
|
|
7004
|
-
d.seed.fill(0);
|
|
7005
|
-
this.drafts.delete(id);
|
|
7006
|
-
}
|
|
7007
|
-
const { binding, seed } = newIdentityBinding({
|
|
7008
|
-
provider,
|
|
7009
|
-
subject: canonical,
|
|
7010
|
-
validitySeconds: days * 86400
|
|
7011
|
-
});
|
|
7012
|
-
const draftId = toBase64Url(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)));
|
|
7013
|
-
this.drafts.set(draftId, {
|
|
7014
|
-
binding,
|
|
7015
|
-
seed,
|
|
7016
|
-
at: Date.now()
|
|
7017
|
-
});
|
|
7018
|
-
return {
|
|
7019
|
-
draftId,
|
|
7020
|
-
binding
|
|
7021
|
-
};
|
|
7022
|
-
}
|
|
7023
|
-
/** Step 2: the evidence. Verified here, exactly as a contact will, before anything is saved. */
|
|
7024
|
-
async complete({ draftId, evidence }) {
|
|
7025
|
-
const draft = this.drafts.get(draftId);
|
|
7026
|
-
if (!draft) throw new Error("This proof was started too long ago. Start again.");
|
|
7027
|
-
const statement = identityStatement(draft.binding);
|
|
7028
|
-
const verified = await this.verify(statement, JSON.parse(JSON.stringify(evidence ?? null)));
|
|
7029
|
-
if (this.proofs.length >= MAX_PROOFS) throw new Error("Remove an identity first");
|
|
7030
|
-
this.drafts.delete(draftId);
|
|
7031
|
-
const stored = {
|
|
7032
|
-
binding: draft.binding,
|
|
7033
|
-
evidence,
|
|
7034
|
-
seed: await sealSecret(toBase64Url(draft.seed), proofKeyAt(statement.id)),
|
|
7035
|
-
verified,
|
|
7036
|
-
createdAt: Date.now()
|
|
7037
|
-
};
|
|
7038
|
-
this.seeds.set(statement.id, draft.seed);
|
|
7039
|
-
await this.save([...this.proofs, stored]);
|
|
7040
|
-
return this.viewOf(stored);
|
|
7041
|
-
}
|
|
7042
|
-
cancel({ draftId }) {
|
|
7043
|
-
this.drafts.get(draftId)?.seed.fill(0);
|
|
7044
|
-
this.drafts.delete(draftId);
|
|
7045
|
-
}
|
|
7046
|
-
/**
|
|
7047
|
-
* Removes a proof from the profile: withdrawn from every chat it was shared in (each contact is told now
|
|
7048
|
-
* or when it next connects), and revoked for good, by a record its proof key publishes on Pkarr and this
|
|
7049
|
-
* app republishes until the proof would have expired, for contacts it never reconnects to.
|
|
7050
|
-
*/
|
|
7051
|
-
async remove({ id }) {
|
|
7052
|
-
const proof = this.proofs.find((p) => identityStatement(p.binding).id === id);
|
|
7053
|
-
if (!proof) return;
|
|
7054
|
-
for (const linkId of this.host.linkIds()) {
|
|
7055
|
-
const shared = this.host.ledger(linkId)?.shared.find((s) => s.id === id);
|
|
7056
|
-
if (shared && shared.status !== "withdrawn") await this.exchange(linkId)?.withdraw(id, !!this.host.channel(linkId));
|
|
7057
|
-
}
|
|
7058
|
-
const revocation = {
|
|
7059
|
-
id,
|
|
7060
|
-
key: proof.binding.key,
|
|
7061
|
-
seed: proof.seed,
|
|
7062
|
-
revokedAt: now(),
|
|
7063
|
-
expiresAt: Math.min(proof.binding.expiresAt, proof.verified.expiresAt ?? Infinity)
|
|
7064
|
-
};
|
|
7065
|
-
const wasShared = this.host.linkIds().some((l) => this.host.ledger(l)?.shared.some((s) => s.id === id));
|
|
7066
|
-
await this.save(this.proofs.filter((p) => p !== proof), wasShared && revocation.expiresAt > now() ? [...this.revocations, revocation] : this.revocations);
|
|
7067
|
-
if (wasShared) this.publishRevocation(revocation).catch(() => {});
|
|
7068
|
-
else {
|
|
7069
|
-
this.seeds.get(id)?.fill(0);
|
|
7070
|
-
this.seeds.delete(id);
|
|
7071
|
-
}
|
|
7072
|
-
}
|
|
7073
|
-
/**
|
|
7074
|
-
* "Clear all data": every proof that was ever shared, and every removed one still being revoked, gets its revocation
|
|
7075
|
-
* record published once more, all at once. Nothing will republish them after the clear, so this is a last word for
|
|
7076
|
-
* contacts who check; proofs posted elsewhere (a Bluesky record, a Pubky file, a DNS record) are the person's to delete.
|
|
7077
|
-
*/
|
|
7078
|
-
async revokeAll() {
|
|
7079
|
-
this.stop();
|
|
7080
|
-
const shared = new Set(this.host.linkIds().flatMap((l) => this.host.ledger(l)?.shared.map((s) => s.id) ?? []));
|
|
7081
|
-
const at = now();
|
|
7082
|
-
const last = [...this.revocations.filter((r) => r.expiresAt > at), ...this.proofs.filter((p) => shared.has(identityStatement(p.binding).id)).map((p) => ({
|
|
7083
|
-
id: identityStatement(p.binding).id,
|
|
7084
|
-
key: p.binding.key,
|
|
7085
|
-
seed: p.seed,
|
|
7086
|
-
revokedAt: at,
|
|
7087
|
-
expiresAt: Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity)
|
|
7088
|
-
}))];
|
|
7089
|
-
await Promise.allSettled(last.map((r) => this.publishRevocation(r)));
|
|
7090
|
-
this.stop();
|
|
7091
|
-
}
|
|
7092
|
-
async publishRevocation(r) {
|
|
7093
|
-
if (!this.host.online()) return;
|
|
7094
|
-
await this.host.publish(await this.seedOf(r.id, r.seed), [{
|
|
7095
|
-
label: IDENTITY_REVOCATION_LABEL,
|
|
7096
|
-
value: identityRevocationValue(r.id, r.revokedAt)
|
|
7097
|
-
}]);
|
|
7098
|
-
}
|
|
7099
|
-
async republish() {
|
|
7100
|
-
const live = this.revocations.filter((r) => r.expiresAt > now());
|
|
7101
|
-
if (live.length !== this.revocations.length) {
|
|
7102
|
-
for (const r of this.revocations) if (!live.includes(r)) {
|
|
7103
|
-
this.seeds.get(r.id)?.fill(0);
|
|
7104
|
-
this.seeds.delete(r.id);
|
|
7105
|
-
}
|
|
7106
|
-
await this.save(this.proofs, live);
|
|
7107
|
-
}
|
|
7108
|
-
for (const r of live) await this.publishRevocation(r).catch(() => {});
|
|
7109
|
-
}
|
|
7110
|
-
/**
|
|
7111
|
-
* Looks up the contacts' proofs for a revocation (the Pkarr record only, not the provider): the ones standing, and the
|
|
7112
|
-
* ones withdrawn, which a removal also revokes. Not a proof already revoked, nor one past its expiry: its owner
|
|
7113
|
-
* publishes the revocation only until then.
|
|
7114
|
-
*/
|
|
7115
|
-
async checkRevocations() {
|
|
7116
|
-
if (!this.host.online()) return;
|
|
7117
|
-
for (const linkId of this.host.linkIds()) for (const r of this.host.ledger(linkId)?.received ?? []) if (this.revocable(r)) await this.exchange(linkId)?.recheck(r.id, { revocationOnly: true }).catch(() => {});
|
|
7118
|
-
}
|
|
7119
|
-
revocable(r) {
|
|
7120
|
-
return r.status !== "revoked" && Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity) > now();
|
|
7121
|
-
}
|
|
7122
|
-
/** A proof the contact just withdrew: looked up for its revocation a few times (`WITHDRAWN_REVOCATION_TRIES_MS`). */
|
|
7123
|
-
afterWithdrawal(linkId, id, tries = WITHDRAWN_REVOCATION_TRIES_MS) {
|
|
7124
|
-
const [wait, ...rest] = tries;
|
|
7125
|
-
if (wait === void 0) return;
|
|
7126
|
-
const timer = setTimeout(() => {
|
|
7127
|
-
this.timers = this.timers.filter((t) => t !== timer);
|
|
7128
|
-
const r = this.host.ledger(linkId)?.received.find((x) => x.id === id);
|
|
7129
|
-
if (!r || r.status !== "withdrawn" || !this.revocable(r)) return;
|
|
7130
|
-
(async () => {
|
|
7131
|
-
if ((this.host.online() ? await this.exchange(linkId)?.recheck(id, { revocationOnly: true }).catch(() => void 0) : void 0)?.status !== "revoked") this.afterWithdrawal(linkId, id, rest);
|
|
7132
|
-
})();
|
|
7133
|
-
}, wait);
|
|
7134
|
-
this.timers.push(timer);
|
|
7135
|
-
}
|
|
7136
|
-
views() {
|
|
7137
|
-
return this.proofs.map((p) => this.viewOf(p));
|
|
7138
|
-
}
|
|
7139
|
-
viewOf(p) {
|
|
7140
|
-
const id = identityStatement(p.binding).id;
|
|
7141
|
-
const sharedWith = this.host.linkIds().filter((l) => this.host.ledger(l)?.shared.some((s) => s.id === id && s.status !== "withdrawn" && s.status !== "withdrawal-pending" && s.status !== "rejected")).length;
|
|
7142
|
-
const publicUri = this.publicUri(p);
|
|
7143
|
-
const expiresAt = Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity);
|
|
7144
|
-
const publicProfile = expiresAt > now() ? this.host.publicProfile?.(p.binding.provider, p.verified.subject) : void 0;
|
|
7145
|
-
return {
|
|
7146
|
-
id,
|
|
7147
|
-
provider: p.binding.provider,
|
|
7148
|
-
subject: p.binding.subject,
|
|
7149
|
-
key: p.binding.key,
|
|
7150
|
-
verified: p.verified,
|
|
7151
|
-
issuedAt: p.binding.issuedAt,
|
|
7152
|
-
expiresAt,
|
|
7153
|
-
createdAt: p.createdAt,
|
|
7154
|
-
sharedWith,
|
|
7155
|
-
evidence: p.evidence,
|
|
7156
|
-
...publicUri ? { publicUri } : {},
|
|
7157
|
-
...publicProfile ? { publicProfile } : {}
|
|
7158
|
-
};
|
|
7159
|
-
}
|
|
7160
|
-
/** What the profile's public DID would list for this identity: the provider's URI for the verified subject, if well formed. */
|
|
7161
|
-
publicUri(p) {
|
|
7162
|
-
try {
|
|
7163
|
-
const uri = this.providers().find((x) => x.id === p.binding.provider)?.publicUri?.(p.verified.subject);
|
|
7164
|
-
return uri && /^[A-Za-z][A-Za-z0-9+.-]*:[^\s,;]+$/.test(uri) ? uri : void 0;
|
|
7165
|
-
} catch {
|
|
7166
|
-
return;
|
|
7167
|
-
}
|
|
7168
|
-
}
|
|
7169
|
-
exchange(linkId) {
|
|
7170
|
-
if (!this.host.ledger(linkId)) return void 0;
|
|
7171
|
-
let x = this.exchanges.get(linkId);
|
|
7172
|
-
if (!x) {
|
|
7173
|
-
x = new IdentityExchange({
|
|
7174
|
-
scope: () => {
|
|
7175
|
-
const c = this.host.channel(linkId);
|
|
7176
|
-
if (!c) throw new Error("Connect to this contact first");
|
|
7177
|
-
return c.scope();
|
|
7178
|
-
},
|
|
7179
|
-
send: (frame) => {
|
|
7180
|
-
const c = this.host.channel(linkId);
|
|
7181
|
-
if (!c) throw new Error("Connect to this contact first");
|
|
7182
|
-
c.send(frame);
|
|
7183
|
-
},
|
|
7184
|
-
storage: {
|
|
7185
|
-
read: () => this.host.ledger(linkId) ?? emptyIdentityLedger(),
|
|
7186
|
-
update: async (change) => {
|
|
7187
|
-
await this.host.updateLedger(linkId, change);
|
|
7188
|
-
this.host.emit();
|
|
7189
|
-
}
|
|
7190
|
-
},
|
|
7191
|
-
providers: () => this.providers().map((p) => p.id),
|
|
7192
|
-
localProof: (id) => this.local(id),
|
|
7193
|
-
verify: this.verify,
|
|
7194
|
-
revoked: this.revoked,
|
|
7195
|
-
onError: (error) => {
|
|
7196
|
-
this.errors.set(linkId, error);
|
|
7197
|
-
this.host.emit();
|
|
7198
|
-
}
|
|
7199
|
-
});
|
|
7200
|
-
this.exchanges.set(linkId, x);
|
|
7201
|
-
}
|
|
7202
|
-
return x;
|
|
7203
|
-
}
|
|
7204
|
-
async share({ linkId, id }) {
|
|
7205
|
-
const x = this.exchange(linkId);
|
|
7206
|
-
if (!x) throw new Error("Identities can be shared in paired chats only");
|
|
7207
|
-
const p = this.proofs.find((q) => identityStatement(q.binding).id === id);
|
|
7208
|
-
if (!p) throw new Error("That identity is no longer in your profile");
|
|
7209
|
-
if (Math.min(p.binding.expiresAt, p.verified.expiresAt ?? Infinity) <= now()) throw new Error("This identity has expired. Make a new proof in your profile.");
|
|
7210
|
-
this.errors.delete(linkId);
|
|
7211
|
-
await x.share(id, !!this.host.channel(linkId));
|
|
7212
|
-
}
|
|
7213
|
-
async withdraw({ linkId, id }) {
|
|
7214
|
-
await this.exchange(linkId)?.withdraw(id, !!this.host.channel(linkId));
|
|
7215
|
-
}
|
|
7216
|
-
/** The contact's proof, checked again: its revocation record, then the provider's own check. */
|
|
7217
|
-
async recheck({ linkId, id }) {
|
|
7218
|
-
if (!this.host.online()) throw new Error("Offline: turn the network on to check again");
|
|
7219
|
-
await this.exchange(linkId)?.recheck(id);
|
|
7220
|
-
}
|
|
7221
|
-
/** Only on the person's request: the provider's public name/picture for a verified identity. */
|
|
7222
|
-
async lookupDisplay({ linkId, id }) {
|
|
7223
|
-
if (!this.host.online()) throw new Error("Offline: turn the network on first");
|
|
7224
|
-
const r = this.host.ledger(linkId)?.received.find((x) => x.id === id);
|
|
7225
|
-
const provider = r && this.providers().find((p) => p.id === r.binding.provider);
|
|
7226
|
-
if (!r || !provider?.lookupDisplay) throw new Error("No public profile for this identity");
|
|
7227
|
-
const display = await provider.lookupDisplay(r.verified.subject, { signal: AbortSignal.timeout(15e3) });
|
|
7228
|
-
if (!display) throw new Error("No public profile found");
|
|
7229
|
-
await this.host.updateLedger(linkId, (l) => ({
|
|
7230
|
-
...l,
|
|
7231
|
-
received: l.received.map((x) => x.id === id && x.verified.subject === r.verified.subject ? {
|
|
7232
|
-
...x,
|
|
7233
|
-
display
|
|
7234
|
-
} : x)
|
|
7235
|
-
}));
|
|
7236
|
-
this.host.emit();
|
|
7237
|
-
}
|
|
7238
|
-
async frame(linkId, frame) {
|
|
7239
|
-
const x = this.exchange(linkId);
|
|
7240
|
-
if (!x) return;
|
|
7241
|
-
const withdrawn = frame.t === "idp-withdraw" && typeof frame.id === "string" && this.host.ledger(linkId)?.received.some((r) => r.id === frame.id && r.status !== "withdrawn" && r.status !== "revoked");
|
|
7242
|
-
await x.receive(frame);
|
|
7243
|
-
if (withdrawn && this.host.ledger(linkId)?.received.some((r) => r.id === frame.id && r.status === "withdrawn")) this.afterWithdrawal(linkId, frame.id);
|
|
7244
|
-
}
|
|
7245
|
-
ready(linkId) {
|
|
7246
|
-
if (this.greeted.has(linkId) || !this.host.channel(linkId)) return;
|
|
7247
|
-
try {
|
|
7248
|
-
this.exchange(linkId)?.ready();
|
|
7249
|
-
this.greeted.add(linkId);
|
|
7250
|
-
} catch {}
|
|
7251
|
-
}
|
|
7252
|
-
closed(linkId) {
|
|
7253
|
-
this.greeted.delete(linkId);
|
|
7254
|
-
this.exchanges.get(linkId)?.stop();
|
|
7255
|
-
}
|
|
7256
|
-
forget(linkId) {
|
|
7257
|
-
this.greeted.delete(linkId);
|
|
7258
|
-
this.exchanges.get(linkId)?.stop();
|
|
7259
|
-
this.exchanges.delete(linkId);
|
|
7260
|
-
this.errors.delete(linkId);
|
|
7261
|
-
}
|
|
7262
|
-
linkView(linkId, supported) {
|
|
7263
|
-
const ledger = this.host.ledger(linkId);
|
|
7264
|
-
if (!ledger) return void 0;
|
|
7265
|
-
const { mine, theirs } = this.host.keys(linkId);
|
|
7266
|
-
const t = now();
|
|
7267
|
-
return {
|
|
7268
|
-
support: supported,
|
|
7269
|
-
contactProviders: supported ? this.exchanges.get(linkId)?.contactProviders?.slice() : void 0,
|
|
7270
|
-
shared: ledger.shared,
|
|
7271
|
-
received: ledger.received.map((r) => {
|
|
7272
|
-
const provider = this.providers().find((p) => p.id === r.binding.provider);
|
|
7273
|
-
const status = receivedIdentityStatus(r, theirs, mine, t);
|
|
7274
|
-
const publicProfile = status === "verified" ? this.host.publicProfile?.(r.binding.provider, r.verified.subject) : void 0;
|
|
7275
|
-
return {
|
|
7276
|
-
id: r.id,
|
|
7277
|
-
provider: r.binding.provider,
|
|
7278
|
-
subject: r.verified.subject,
|
|
7279
|
-
verified: r.verified,
|
|
7280
|
-
display: r.display,
|
|
7281
|
-
status,
|
|
7282
|
-
verifiedAt: r.verifiedAt,
|
|
7283
|
-
checkedAt: r.checkedAt,
|
|
7284
|
-
expiresAt: Math.min(r.binding.expiresAt, r.verified.expiresAt ?? Infinity),
|
|
7285
|
-
error: r.error,
|
|
7286
|
-
recheckDue: !!provider?.recheck && t - r.checkedAt >= provider.recheck.afterSeconds,
|
|
7287
|
-
...publicProfile ? { publicProfile } : {}
|
|
7288
|
-
};
|
|
7289
|
-
}),
|
|
7290
|
-
error: this.errors.get(linkId)
|
|
7291
|
-
};
|
|
7292
|
-
}
|
|
7293
|
-
};
|
|
7294
|
-
//#endregion
|
|
7295
6773
|
//#region ../browser/src/engine/x401.ts
|
|
7296
6774
|
var X401_KEY = "x401Credentials";
|
|
7297
6775
|
var MAX_CREDENTIALS = 32;
|
|
@@ -7480,6 +6958,12 @@ var ProfileDid = class {
|
|
|
7480
6958
|
inFlight = null;
|
|
7481
6959
|
again = false;
|
|
7482
6960
|
unlisten;
|
|
6961
|
+
/** The last `samePacket` answer. */
|
|
6962
|
+
compared;
|
|
6963
|
+
/** "Clear all data" ended the DID: a publish still on its way saves nothing, or the cleared record comes back. */
|
|
6964
|
+
ended = false;
|
|
6965
|
+
/** The newest sequence number signed here, so the `deactivated` packet goes past one still on its way. */
|
|
6966
|
+
signedSeq = 0;
|
|
7483
6967
|
constructor(host) {
|
|
7484
6968
|
this.host = host;
|
|
7485
6969
|
}
|
|
@@ -7529,15 +7013,16 @@ var ProfileDid = class {
|
|
|
7529
7013
|
view() {
|
|
7530
7014
|
if (!this.stored) return void 0;
|
|
7531
7015
|
const published = this.stored.published;
|
|
7016
|
+
const alsoKnownAs = this.alsoKnownAs(this.listed());
|
|
7532
7017
|
return {
|
|
7533
7018
|
id: this.id,
|
|
7534
7019
|
listed: this.listed(),
|
|
7535
|
-
alsoKnownAs
|
|
7020
|
+
alsoKnownAs,
|
|
7536
7021
|
...published ? { published: {
|
|
7537
7022
|
at: published.at,
|
|
7538
7023
|
versionId: String(published.seq)
|
|
7539
7024
|
} } : {},
|
|
7540
|
-
upToDate: !!published && this.samePacket(published.payload),
|
|
7025
|
+
upToDate: !!published && this.samePacket(published.payload, alsoKnownAs),
|
|
7541
7026
|
...this.error ? { error: this.error } : {}
|
|
7542
7027
|
};
|
|
7543
7028
|
}
|
|
@@ -7599,7 +7084,7 @@ var ProfileDid = class {
|
|
|
7599
7084
|
}, ms);
|
|
7600
7085
|
}
|
|
7601
7086
|
async publish() {
|
|
7602
|
-
if (!this.stored || !this.host.online()) return;
|
|
7087
|
+
if (!this.stored || this.ended || !this.host.online()) return;
|
|
7603
7088
|
const previous = this.stored.published;
|
|
7604
7089
|
try {
|
|
7605
7090
|
const packet = encodeDidDhtPacket(this.document());
|
|
@@ -7612,7 +7097,9 @@ var ProfileDid = class {
|
|
|
7612
7097
|
seq = Math.max(Math.floor(Date.now() / 1e3), (previous?.seq ?? 0) + 1);
|
|
7613
7098
|
payload = signDidDhtPacket(identityFromSeed(await this.unsealed()), packet, seq);
|
|
7614
7099
|
}
|
|
7100
|
+
this.signedSeq = Math.max(this.signedSeq, seq);
|
|
7615
7101
|
await this.host.publish(toZ32(this.publicKey()), payload);
|
|
7102
|
+
if (this.ended) return;
|
|
7616
7103
|
this.error = void 0;
|
|
7617
7104
|
await this.save({
|
|
7618
7105
|
...this.stored,
|
|
@@ -7628,14 +7115,15 @@ var ProfileDid = class {
|
|
|
7628
7115
|
this.host.emit();
|
|
7629
7116
|
}
|
|
7630
7117
|
/**
|
|
7631
|
-
* "Clear all data": the DID ends. When a document was ever published, a newer packet reading `deactivated` replaces
|
|
7118
|
+
* "Clear all data": the DID ends. When a document was ever published (or is on its way), a newer packet reading `deactivated` replaces
|
|
7632
7119
|
* it, so resolvers say the DID is gone instead of showing the old document until it expires. Stops publishing first.
|
|
7633
7120
|
*/
|
|
7634
7121
|
async deactivate() {
|
|
7122
|
+
this.ended = true;
|
|
7635
7123
|
this.stop();
|
|
7636
7124
|
const previous = this.stored?.published;
|
|
7637
|
-
if (!this.stored || !previous) return;
|
|
7638
|
-
const seq = Math.max(Math.floor(Date.now() / 1e3), previous
|
|
7125
|
+
if (!this.stored || !previous && this.signedSeq === 0) return;
|
|
7126
|
+
const seq = Math.max(Math.floor(Date.now() / 1e3), (previous?.seq ?? 0) + 1, this.signedSeq + 1);
|
|
7639
7127
|
const identity = identityFromSeed(fromBase64Url(await openSecret(this.stored.seed, SEED_AT)));
|
|
7640
7128
|
await this.host.publish(toZ32(this.publicKey()), signDidDhtPacket(identity, encodeDidDhtDeactivated(this.publicKey()), seq));
|
|
7641
7129
|
}
|
|
@@ -7643,6 +7131,7 @@ var ProfileDid = class {
|
|
|
7643
7131
|
return this.stored?.listed ?? [];
|
|
7644
7132
|
}
|
|
7645
7133
|
alsoKnownAs(ids) {
|
|
7134
|
+
if (ids.length === 0) return [];
|
|
7646
7135
|
const listable = this.host.listable();
|
|
7647
7136
|
return [...new Set(ids.map((id) => listable.get(id)).filter((uri) => !!uri))];
|
|
7648
7137
|
}
|
|
@@ -7650,13 +7139,23 @@ var ProfileDid = class {
|
|
|
7650
7139
|
if (!this.stored) throw new Error("The profile's DID is not loaded yet");
|
|
7651
7140
|
return fromBase64Url(this.stored.publicKey);
|
|
7652
7141
|
}
|
|
7653
|
-
/**
|
|
7654
|
-
|
|
7142
|
+
/**
|
|
7143
|
+
* Whether `payload` carries the document as it is now. Never throws: the engine's state is built from it. Every state
|
|
7144
|
+
* asks, and the document follows from the key and its URIs alone, so it is encoded again only when those URIs or `payload` change.
|
|
7145
|
+
*/
|
|
7146
|
+
samePacket(payload, alsoKnownAs = this.alsoKnownAs(this.listed())) {
|
|
7147
|
+
const uris = alsoKnownAs.join(" ");
|
|
7148
|
+
if (this.compared?.payload === payload && this.compared.uris === uris) return this.compared.same;
|
|
7149
|
+
let same = false;
|
|
7655
7150
|
try {
|
|
7656
|
-
|
|
7657
|
-
} catch {
|
|
7658
|
-
|
|
7659
|
-
|
|
7151
|
+
same = bytesEqual(fromBase64Url(payload).subarray(HEADER), encodeDidDhtPacket(didDhtDocument(this.publicKey(), { alsoKnownAs })));
|
|
7152
|
+
} catch {}
|
|
7153
|
+
this.compared = {
|
|
7154
|
+
payload,
|
|
7155
|
+
uris,
|
|
7156
|
+
same
|
|
7157
|
+
};
|
|
7158
|
+
return same;
|
|
7660
7159
|
}
|
|
7661
7160
|
/**
|
|
7662
7161
|
* A copy of the DID key's seed, for the first device-set secret of the profile (WISP 06 § Terms: `D0` comes from
|
|
@@ -7671,6 +7170,7 @@ var ProfileDid = class {
|
|
|
7671
7170
|
return this.seed;
|
|
7672
7171
|
}
|
|
7673
7172
|
async save(next) {
|
|
7173
|
+
if (this.ended) return;
|
|
7674
7174
|
await committed((await store(STORES$1.settings, "readwrite")).put(next, KEY$1));
|
|
7675
7175
|
this.stored = next;
|
|
7676
7176
|
}
|
|
@@ -9036,6 +8536,8 @@ var NostrSocial = class {
|
|
|
9036
8536
|
loadingOwn = /* @__PURE__ */ new Set();
|
|
9037
8537
|
errors = /* @__PURE__ */ new Map();
|
|
9038
8538
|
drafts = /* @__PURE__ */ new Map();
|
|
8539
|
+
hints = /* @__PURE__ */ new WeakMap();
|
|
8540
|
+
shownNotes = /* @__PURE__ */ new WeakMap();
|
|
9039
8541
|
constructor(host) {
|
|
9040
8542
|
this.host = host;
|
|
9041
8543
|
}
|
|
@@ -9142,6 +8644,7 @@ var NostrSocial = class {
|
|
|
9142
8644
|
if (subjects.length === 0) return void 0;
|
|
9143
8645
|
const cache = this.host.readContacts(linkId) ?? {};
|
|
9144
8646
|
const myKeys = this.host.ownSubjects();
|
|
8647
|
+
const muteLists = myKeys.map((s) => this.own[s]?.mute?.list).filter((m) => !!m);
|
|
9145
8648
|
return subjects.map((subject) => {
|
|
9146
8649
|
const c = cache[subject];
|
|
9147
8650
|
const view = {
|
|
@@ -9167,34 +8670,9 @@ var NostrSocial = class {
|
|
|
9167
8670
|
key: k,
|
|
9168
8671
|
follows: this.own[k]?.follows
|
|
9169
8672
|
})).find((x) => x.follows);
|
|
9170
|
-
if (mine?.follows)
|
|
9171
|
-
const h = followHints(c.follows.follows, mine.follows.follows, myKeys, subject);
|
|
9172
|
-
view.follows.hints = {
|
|
9173
|
-
followsYou: h.followsYou,
|
|
9174
|
-
youFollow: h.youFollow,
|
|
9175
|
-
mutual: h.mutual.length,
|
|
9176
|
-
myKey: mine.key,
|
|
9177
|
-
myFollowsAt: mine.follows.fetchedAt
|
|
9178
|
-
};
|
|
9179
|
-
}
|
|
9180
|
-
}
|
|
9181
|
-
if (c?.notes) {
|
|
9182
|
-
const authorMuted = this.muteLists().some((m) => m.pubkeys.includes(subject));
|
|
9183
|
-
const shown = authorMuted ? [] : c.notes.notes.filter((n) => !this.muted(n, subject));
|
|
9184
|
-
view.notes = {
|
|
9185
|
-
fetchedAt: c.notes.fetchedAt,
|
|
9186
|
-
relays: c.notes.relays,
|
|
9187
|
-
notes: shown.map((n) => ({
|
|
9188
|
-
id: n.id,
|
|
9189
|
-
createdAt: n.createdAt,
|
|
9190
|
-
content: n.content,
|
|
9191
|
-
reply: n.reply
|
|
9192
|
-
})),
|
|
9193
|
-
more: !c.notes.exhausted,
|
|
9194
|
-
hidden: c.notes.notes.length - shown.length,
|
|
9195
|
-
authorMuted
|
|
9196
|
-
};
|
|
8673
|
+
if (mine?.follows) view.follows.hints = this.hintsOf(c.follows, mine.follows, mine.key, myKeys, subject);
|
|
9197
8674
|
}
|
|
8675
|
+
if (c?.notes) view.notes = this.notesOf(c.notes, muteLists, subject);
|
|
9198
8676
|
const loading = this.loading.get(`${linkId}:${subject}`);
|
|
9199
8677
|
if (loading) view.loading = loading;
|
|
9200
8678
|
const error = this.errors.get(`${linkId}:${subject}`);
|
|
@@ -9202,6 +8680,54 @@ var NostrSocial = class {
|
|
|
9202
8680
|
return view;
|
|
9203
8681
|
});
|
|
9204
8682
|
}
|
|
8683
|
+
/** How a contact's follows meet the person's. Every state asks; a list that changes is a new object. */
|
|
8684
|
+
hintsOf(theirs, mine, myKey, myKeys, subject) {
|
|
8685
|
+
const keys = myKeys.join(" ");
|
|
8686
|
+
const kept = this.hints.get(theirs);
|
|
8687
|
+
if (kept?.mine === mine && kept.myKey === myKey && kept.keys === keys && kept.subject === subject) return kept.hints;
|
|
8688
|
+
const h = followHints(theirs.follows, mine.follows, myKeys, subject);
|
|
8689
|
+
const hints = {
|
|
8690
|
+
followsYou: h.followsYou,
|
|
8691
|
+
youFollow: h.youFollow,
|
|
8692
|
+
mutual: h.mutual.length,
|
|
8693
|
+
myKey,
|
|
8694
|
+
myFollowsAt: mine.fetchedAt
|
|
8695
|
+
};
|
|
8696
|
+
this.hints.set(theirs, {
|
|
8697
|
+
mine,
|
|
8698
|
+
myKey,
|
|
8699
|
+
keys,
|
|
8700
|
+
subject,
|
|
8701
|
+
hints
|
|
8702
|
+
});
|
|
8703
|
+
return hints;
|
|
8704
|
+
}
|
|
8705
|
+
/** A contact's posts as shown, past the person's mute lists. Every state asks; a list that changes is a new object. */
|
|
8706
|
+
notesOf(notes, lists, subject) {
|
|
8707
|
+
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.view;
|
|
8709
|
+
const authorMuted = lists.some((m) => m.pubkeys.includes(subject));
|
|
8710
|
+
const shown = authorMuted ? [] : notes.notes.filter((n) => !lists.some((m) => !!mutedBecause(n, subject, m)));
|
|
8711
|
+
const view = {
|
|
8712
|
+
fetchedAt: notes.fetchedAt,
|
|
8713
|
+
relays: notes.relays,
|
|
8714
|
+
notes: shown.map((n) => ({
|
|
8715
|
+
id: n.id,
|
|
8716
|
+
createdAt: n.createdAt,
|
|
8717
|
+
content: n.content,
|
|
8718
|
+
reply: n.reply
|
|
8719
|
+
})),
|
|
8720
|
+
more: !notes.exhausted,
|
|
8721
|
+
hidden: notes.notes.length - shown.length,
|
|
8722
|
+
authorMuted
|
|
8723
|
+
};
|
|
8724
|
+
this.shownNotes.set(notes, {
|
|
8725
|
+
lists,
|
|
8726
|
+
subject,
|
|
8727
|
+
view
|
|
8728
|
+
});
|
|
8729
|
+
return view;
|
|
8730
|
+
}
|
|
9205
8731
|
requireOnline() {
|
|
9206
8732
|
if (!this.host.online()) throw new Error("Offline: turn the network on first");
|
|
9207
8733
|
}
|
|
@@ -10973,6 +10499,62 @@ var SavedMessages = class {
|
|
|
10973
10499
|
}
|
|
10974
10500
|
};
|
|
10975
10501
|
//#endregion
|
|
10502
|
+
//#region ../browser/src/shared/fold.ts
|
|
10503
|
+
/** Lower case, accents off: "Ação" reads "acao". How every search of the app matches, in the pages and in the engine. */
|
|
10504
|
+
function foldText(text) {
|
|
10505
|
+
return text.normalize("NFD").toLowerCase().replace(/\p{M}/gu, "");
|
|
10506
|
+
}
|
|
10507
|
+
//#endregion
|
|
10508
|
+
//#region ../browser/src/engine/chatSearch.ts
|
|
10509
|
+
/**
|
|
10510
|
+
* How long the chats' folded texts stay after the last search: a search asks again at each letter typed, and each chat
|
|
10511
|
+
* is read from the store once for all of them. Then they go: the extension's engine runs with no page open, and would
|
|
10512
|
+
* keep every chat's text for good after one search.
|
|
10513
|
+
*/
|
|
10514
|
+
var SEARCH_KEPT_MS = 6e4;
|
|
10515
|
+
/**
|
|
10516
|
+
* The chat list's search over the chats' whole histories, in the engine (`chatsFound`): a page that holds a chat's
|
|
10517
|
+
* newest page only (the extension's) finds it by an older message too, without being sent its whole history. Each chat's
|
|
10518
|
+
* texts are read and folded once, and read again only after the chat changed (`changed`, as the pages hear it).
|
|
10519
|
+
*/
|
|
10520
|
+
var ChatTextSearch = class {
|
|
10521
|
+
read;
|
|
10522
|
+
/** Per chat, its messages' texts folded, as read after its last change. */
|
|
10523
|
+
texts = /* @__PURE__ */ new Map();
|
|
10524
|
+
timer = null;
|
|
10525
|
+
constructor(read) {
|
|
10526
|
+
this.read = read;
|
|
10527
|
+
}
|
|
10528
|
+
/** The chats among `linkIds` with a message whose text holds `query` (folded as `foldText` does), in that order. */
|
|
10529
|
+
async found(linkIds, query) {
|
|
10530
|
+
const q = foldText(query);
|
|
10531
|
+
if (!q) return [];
|
|
10532
|
+
if (this.timer) clearTimeout(this.timer);
|
|
10533
|
+
this.timer = setTimeout(() => {
|
|
10534
|
+
this.timer = null;
|
|
10535
|
+
this.texts.clear();
|
|
10536
|
+
}, SEARCH_KEPT_MS);
|
|
10537
|
+
this.timer.unref?.();
|
|
10538
|
+
const hits = await Promise.all(linkIds.map(async (linkId) => (await this.textsOf(linkId)).some((text) => text.includes(q))));
|
|
10539
|
+
return linkIds.filter((_, i) => hits[i]);
|
|
10540
|
+
}
|
|
10541
|
+
/** A chat's history changed: its texts are read again at the next search. A read still out stays the one it began as. */
|
|
10542
|
+
changed(linkId) {
|
|
10543
|
+
this.texts.delete(linkId);
|
|
10544
|
+
}
|
|
10545
|
+
textsOf(linkId) {
|
|
10546
|
+
let texts = this.texts.get(linkId);
|
|
10547
|
+
if (!texts) {
|
|
10548
|
+
texts = this.read(linkId).then((messages) => messages.flatMap((m) => m.text ? [foldText(m.text)] : []));
|
|
10549
|
+
this.texts.set(linkId, texts);
|
|
10550
|
+
texts.catch(() => {
|
|
10551
|
+
if (this.texts.get(linkId) === texts) this.texts.delete(linkId);
|
|
10552
|
+
});
|
|
10553
|
+
}
|
|
10554
|
+
return texts;
|
|
10555
|
+
}
|
|
10556
|
+
};
|
|
10557
|
+
//#endregion
|
|
10976
10558
|
//#region ../browser/src/engine/appFetch.ts
|
|
10977
10559
|
/** The hosts phase 1 reads from. A jsDelivr URL must also name a 40-character commit (`isAppUrl`). */
|
|
10978
10560
|
var APP_FETCH_HOSTS = ["raw.githubusercontent.com", "cdn.jsdelivr.net"];
|
|
@@ -11323,6 +10905,29 @@ function markBuiltIns(settings, change) {
|
|
|
11323
10905
|
settings.put(marks, BUILT_IN_APPS_KEY);
|
|
11324
10906
|
};
|
|
11325
10907
|
}
|
|
10908
|
+
/**
|
|
10909
|
+
* The key, in `STORES.settings`, of the digests of the bundles this profile may hold in file storage (one of
|
|
10910
|
+
* `PROFILE_SETTINGS_KEYS`): each one is noted before its bytes are written. File storage lists no files, and a bundle is
|
|
10911
|
+
* written or removed in a step of its own beside its app's record: a page gone between the two leaves one no record
|
|
10912
|
+
* names, which the next start finds here and removes.
|
|
10913
|
+
*/
|
|
10914
|
+
var APP_BUNDLES_KEY = "appBundles";
|
|
10915
|
+
/** The digests as kept, read with nothing taken on trust. */
|
|
10916
|
+
function bundleDigests(kept) {
|
|
10917
|
+
return Array.isArray(kept) ? kept.filter((d) => typeof d === "string" && isAppHash(d)) : [];
|
|
10918
|
+
}
|
|
10919
|
+
/** Changes the digests noted (`APP_BUNDLES_KEY`), read and written in one transaction. */
|
|
10920
|
+
async function noteBundles(change) {
|
|
10921
|
+
const tx = (await openDb()).transaction(STORES$1.settings, "readwrite");
|
|
10922
|
+
const settings = tx.objectStore(STORES$1.settings);
|
|
10923
|
+
const read = settings.get(APP_BUNDLES_KEY);
|
|
10924
|
+
read.onsuccess = () => {
|
|
10925
|
+
const noted = new Set(bundleDigests(read.result));
|
|
10926
|
+
change(noted);
|
|
10927
|
+
settings.put([...noted], APP_BUNDLES_KEY);
|
|
10928
|
+
};
|
|
10929
|
+
await done(tx);
|
|
10930
|
+
}
|
|
11326
10931
|
var builtInRef = (app) => appRef(app.publisher, app.name);
|
|
11327
10932
|
/**
|
|
11328
10933
|
* The entries of the built-in list this profile is offered (WISP 1200 § Built-in apps): each reference once, not
|
|
@@ -11363,6 +10968,27 @@ function withRevocations(app, read) {
|
|
|
11363
10968
|
revocations: [...merged.values()]
|
|
11364
10969
|
} : app;
|
|
11365
10970
|
}
|
|
10971
|
+
/** Of these revocations, the ones that stop one of these versions. */
|
|
10972
|
+
function stopping(versions, revocations) {
|
|
10973
|
+
return revocations.filter((r) => versions.some((v) => appRevocationFor(v, [r])));
|
|
10974
|
+
}
|
|
10975
|
+
/**
|
|
10976
|
+
* What installing `version` over `installed` does, for the install screen and for Install alike: the update rule, and an
|
|
10977
|
+
* equivocation for another bundle at the number of the update waiting (two different versions of that number exist).
|
|
10978
|
+
*/
|
|
10979
|
+
function installDecision(installed, version) {
|
|
10980
|
+
if (!installed) return "new";
|
|
10981
|
+
if (installed.pending && installed.pending.sequence === version.sequence && installed.pending.digest !== version.digest) return "equivocation";
|
|
10982
|
+
return appUpdateDecision(installed, version);
|
|
10983
|
+
}
|
|
10984
|
+
/**
|
|
10985
|
+
* Whether `now` is still the record `was`: the same install, version, waiting update, files and mark. A store pinned or
|
|
10986
|
+
* unpinned meanwhile is not a change here: the update check unpins on its own (`removeStore`).
|
|
10987
|
+
*/
|
|
10988
|
+
function sameRecord(now, was) {
|
|
10989
|
+
if (!was) return !now;
|
|
10990
|
+
return !!now && now.installedAt === was.installedAt && now.digest === was.digest && now.pending?.digest === was.pending?.digest && now.bytes === was.bytes && now.equivocation?.digest === was.equivocation?.digest;
|
|
10991
|
+
}
|
|
11366
10992
|
/** Rows of one app (`[ref]`), or of one app in one scope (`[ref, scope]`), in `STORES.appStorage`, counter rows included. */
|
|
11367
10993
|
var rowsOf = (...prefix) => IDBKeyRange.bound(prefix, [...prefix, []]);
|
|
11368
10994
|
/** The app's own rows of one scope: its counter row left out. */
|
|
@@ -11483,6 +11109,10 @@ var Apps = class {
|
|
|
11483
11109
|
}
|
|
11484
11110
|
};
|
|
11485
11111
|
stopped = false;
|
|
11112
|
+
/** Bundles written by this engine (`writeBundle`), by digest: one whose record is not written yet is not swept (`sweepBundles`). */
|
|
11113
|
+
written = /* @__PURE__ */ new Set();
|
|
11114
|
+
/** The sweep of `start` while it runs: a bundle written meanwhile waits for it. */
|
|
11115
|
+
sweeping = null;
|
|
11486
11116
|
constructor(host) {
|
|
11487
11117
|
this.host = host;
|
|
11488
11118
|
}
|
|
@@ -11492,10 +11122,14 @@ var Apps = class {
|
|
|
11492
11122
|
nowS() {
|
|
11493
11123
|
return Math.floor(this.now() / 1e3);
|
|
11494
11124
|
}
|
|
11495
|
-
/**
|
|
11125
|
+
/**
|
|
11126
|
+
* Preloads the default stores (no request) and removes the bundles no record names (`sweepBundles`), then checks for
|
|
11127
|
+
* updates soon after start and every 24 hours.
|
|
11128
|
+
*/
|
|
11496
11129
|
async start() {
|
|
11497
11130
|
this.stopped = false;
|
|
11498
11131
|
await this.seedDefaults();
|
|
11132
|
+
await (this.sweeping = this.sweepBundles().catch(() => {}));
|
|
11499
11133
|
this.schedule(APP_CHECK_TIMINGS.afterStartMs, true);
|
|
11500
11134
|
}
|
|
11501
11135
|
stop() {
|
|
@@ -11640,6 +11274,14 @@ var Apps = class {
|
|
|
11640
11274
|
digest
|
|
11641
11275
|
};
|
|
11642
11276
|
}
|
|
11277
|
+
/** The versions of an app a revocation it keeps may stop: the installed one, the one waiting, one started here before an update (it may still run). */
|
|
11278
|
+
versionsOf(app) {
|
|
11279
|
+
return [
|
|
11280
|
+
app,
|
|
11281
|
+
...app.pending ? [versionOf(app.pending.manifest, app.pending.digest)] : [],
|
|
11282
|
+
...this.startedBefore(app)
|
|
11283
|
+
];
|
|
11284
|
+
}
|
|
11643
11285
|
/** The versions started here that are not the installed one any more. */
|
|
11644
11286
|
startedBefore(app) {
|
|
11645
11287
|
return [...this.started.get(app.ref) ?? []].filter(([digest]) => digest !== app.digest).map(([digest, sequence]) => ({
|
|
@@ -11670,15 +11312,16 @@ var Apps = class {
|
|
|
11670
11312
|
}
|
|
11671
11313
|
}
|
|
11672
11314
|
/**
|
|
11673
|
-
* Writes an app's record back only while
|
|
11674
|
-
*
|
|
11315
|
+
* Writes an app's record back only while it is still the record `was` (`sameRecord`), read and written in one
|
|
11316
|
+
* transaction: an app uninstalled (or installed again) while the update check was reading is not put back, nor is the
|
|
11317
|
+
* version it read over an update the person accepted meanwhile. `was` undefined: only while the app has no record.
|
|
11675
11318
|
*/
|
|
11676
|
-
async
|
|
11319
|
+
async putAppIfUnchanged(app, was) {
|
|
11677
11320
|
const tx = (await openDb()).transaction(STORES$1.apps, "readwrite");
|
|
11678
11321
|
let put = false;
|
|
11679
11322
|
const read = tx.objectStore(STORES$1.apps).get(app.ref);
|
|
11680
11323
|
read.onsuccess = () => {
|
|
11681
|
-
if (read.result
|
|
11324
|
+
if (!sameRecord(read.result, was)) return;
|
|
11682
11325
|
tx.objectStore(STORES$1.apps).put(app);
|
|
11683
11326
|
put = true;
|
|
11684
11327
|
};
|
|
@@ -11718,8 +11361,22 @@ var Apps = class {
|
|
|
11718
11361
|
});
|
|
11719
11362
|
await written;
|
|
11720
11363
|
}
|
|
11721
|
-
putStore(record) {
|
|
11722
|
-
|
|
11364
|
+
async putStore(record) {
|
|
11365
|
+
await this.writeStores((records) => records.put(record), (held) => held.set(record.key, record));
|
|
11366
|
+
await this.keepStoreRevocations(record);
|
|
11367
|
+
}
|
|
11368
|
+
/**
|
|
11369
|
+
* Keeps on each installed app the revocations a store's index carries of its versions: a client keeps every
|
|
11370
|
+
* revocation it verified (WISP 1200 § Publisher keys), so the store's next index without it, or the store removed,
|
|
11371
|
+
* does not let that version run again.
|
|
11372
|
+
*/
|
|
11373
|
+
async keepStoreRevocations(record) {
|
|
11374
|
+
const revoked = record.index?.revoked ?? [];
|
|
11375
|
+
if (!revoked.length) return;
|
|
11376
|
+
for (const app of await this.installed()) {
|
|
11377
|
+
const next = withRevocations(app, stopping(this.versionsOf(app), revoked));
|
|
11378
|
+
if ((next.revocations?.length ?? 0) > (app.revocations?.length ?? 0)) await this.putAppIfUnchanged(next, app);
|
|
11379
|
+
}
|
|
11723
11380
|
}
|
|
11724
11381
|
/** The stores' views, made once and again after a store is written here: an app's every storage call and chat frame checks them. */
|
|
11725
11382
|
heldViews() {
|
|
@@ -11762,11 +11419,14 @@ var Apps = class {
|
|
|
11762
11419
|
* failure is `storage`, with the browser's own words after it for the logs, and leaves no piece behind.
|
|
11763
11420
|
*/
|
|
11764
11421
|
async writeBundle(digest, bytes) {
|
|
11422
|
+
this.written.add(digest);
|
|
11765
11423
|
const id = bundleId(digest);
|
|
11766
11424
|
const expected = toBase64Url(await sha256Paced(bytes));
|
|
11767
11425
|
let files;
|
|
11768
11426
|
let stored;
|
|
11769
11427
|
try {
|
|
11428
|
+
await this.sweeping;
|
|
11429
|
+
await noteBundles((noted) => noted.add(digest));
|
|
11770
11430
|
files = await fileBytes();
|
|
11771
11431
|
const size = await files.size(id);
|
|
11772
11432
|
if (size === bytes.length && await files.digest(id) === expected) return files.kind;
|
|
@@ -11817,6 +11477,29 @@ var Apps = class {
|
|
|
11817
11477
|
const app = await this.app(ref);
|
|
11818
11478
|
if (app?.digest !== digest && app?.pending?.digest !== digest) await this.removeBundle(kind, digest);
|
|
11819
11479
|
}
|
|
11480
|
+
/**
|
|
11481
|
+
* Removes the bundles noted (`APP_BUNDLES_KEY`) that no record names, as its version or the one waiting: what an
|
|
11482
|
+
* install, update, accept or uninstall cut short left. One written by this engine is left (its record may be on its
|
|
11483
|
+
* way); the next start sees it. The digests the records name are noted too, for the day they stop naming them.
|
|
11484
|
+
*/
|
|
11485
|
+
async sweepBundles() {
|
|
11486
|
+
const tx = (await openDb()).transaction([STORES$1.apps, STORES$1.settings], "readonly");
|
|
11487
|
+
const [apps, kept] = await Promise.all([wrap(tx.objectStore(STORES$1.apps).getAll()), wrap(tx.objectStore(STORES$1.settings).get(APP_BUNDLES_KEY))]);
|
|
11488
|
+
const named = new Set(apps.flatMap((a) => a.pending ? [a.digest, a.pending.digest] : [a.digest]));
|
|
11489
|
+
const kinds = new Set(apps.flatMap((a) => a.pending ? [a.bytes, a.pending.bytes] : [a.bytes]));
|
|
11490
|
+
const current = await fileBytes().catch(() => null);
|
|
11491
|
+
if (current) kinds.add(current.kind);
|
|
11492
|
+
const gone = /* @__PURE__ */ new Set();
|
|
11493
|
+
for (const digest of bundleDigests(kept)) {
|
|
11494
|
+
if (named.has(digest) || this.written.has(digest)) continue;
|
|
11495
|
+
for (const kind of kinds) await this.removeBundle(kind, digest);
|
|
11496
|
+
gone.add(digest);
|
|
11497
|
+
}
|
|
11498
|
+
await noteBundles((noted) => {
|
|
11499
|
+
for (const digest of named) noted.add(digest);
|
|
11500
|
+
for (const digest of gone) noted.delete(digest);
|
|
11501
|
+
});
|
|
11502
|
+
}
|
|
11820
11503
|
/** The installed bundle read back and checked again before it runs (WISP 1200 § Signatures: "again before it runs one"). */
|
|
11821
11504
|
verifiedBundle(app, running) {
|
|
11822
11505
|
if (running) this.runUsed.set(app.digest, this.now());
|
|
@@ -12133,6 +11816,7 @@ var Apps = class {
|
|
|
12133
11816
|
async removeStore({ key }) {
|
|
12134
11817
|
const held = await this.storeRecord(key);
|
|
12135
11818
|
if (!held) return;
|
|
11819
|
+
await this.keepStoreRevocations(held);
|
|
12136
11820
|
const seen = held.index ? {
|
|
12137
11821
|
sequence: held.index.sequence,
|
|
12138
11822
|
digest: held.digest ?? ""
|
|
@@ -12157,21 +11841,21 @@ var Apps = class {
|
|
|
12157
11841
|
if (key !== void 0 && !stores.length) fail("no-store", "No such store");
|
|
12158
11842
|
const out = [];
|
|
12159
11843
|
for (const s of stores) {
|
|
12160
|
-
let
|
|
11844
|
+
let read;
|
|
12161
11845
|
try {
|
|
12162
|
-
|
|
12163
|
-
next = read.ok ? this.withIndex(s, read.store.index, read.store.digest) : {
|
|
12164
|
-
...s,
|
|
12165
|
-
problem: read.reason
|
|
12166
|
-
};
|
|
11846
|
+
read = await this.readStoreAt(s.url, s.key, s);
|
|
12167
11847
|
} catch (error) {
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
11848
|
+
read = {
|
|
11849
|
+
ok: false,
|
|
11850
|
+
reason: error instanceof AppFetchError ? error.code : "network"
|
|
12171
11851
|
};
|
|
12172
11852
|
}
|
|
12173
11853
|
const now = await this.storeRecord(s.key);
|
|
12174
11854
|
if (!now || now.removed) continue;
|
|
11855
|
+
const next = read.ok ? this.withIndex(now, read.store.index, read.store.digest) : {
|
|
11856
|
+
...now,
|
|
11857
|
+
problem: read.reason
|
|
11858
|
+
};
|
|
12175
11859
|
if (now === s && next.index === s.index && next.digest === s.digest && next.problem === s.problem && next.equivocation === s.equivocation) (await this.records()).set(s.key, next);
|
|
12176
11860
|
else await this.putStore(next);
|
|
12177
11861
|
out.push(this.summary(next));
|
|
@@ -12263,7 +11947,7 @@ var Apps = class {
|
|
|
12263
11947
|
const { manifest, digest } = bundle;
|
|
12264
11948
|
const version = versionOf(manifest, digest);
|
|
12265
11949
|
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
12266
|
-
const decision =
|
|
11950
|
+
const decision = installDecision(installed, version);
|
|
12267
11951
|
const install = decision === "other-app" ? "new" : decision;
|
|
12268
11952
|
const asks = install === "new" ? [...manifest.permissions] : install === "update" ? manifest.permissions.filter((p) => !installed.permissions.includes(p)) : [];
|
|
12269
11953
|
const listedBy = this.listedBy(version.ref, stores);
|
|
@@ -12298,47 +11982,54 @@ var Apps = class {
|
|
|
12298
11982
|
const { manifest } = bundle;
|
|
12299
11983
|
if (!Array.isArray(grant) || !manifest.permissions.every((p) => grant.includes(p))) fail("permissions", "Every permission the app asks for must be granted");
|
|
12300
11984
|
const version = versionOf(manifest, digest);
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
11985
|
+
let wrote;
|
|
11986
|
+
try {
|
|
11987
|
+
for (;;) {
|
|
11988
|
+
const [installed, stores] = await Promise.all([this.app(version.ref), this.stores()]);
|
|
11989
|
+
const run = this.runStatus(version, this.storeViews(stores), installed?.revocations);
|
|
11990
|
+
if (run.status === "revoked") fail("revoked", "Its publisher revoked this version");
|
|
11991
|
+
if (run.status === "removed") fail("removed", `Removed by ${run.by[0].name}: ${run.by[0].reason}`);
|
|
11992
|
+
const decision = installDecision(installed, version);
|
|
11993
|
+
if (decision === "rollback") fail("rollback", "A newer version of this app is installed");
|
|
11994
|
+
if (decision === "equivocation") {
|
|
11995
|
+
if (!await this.putAppIfUnchanged({
|
|
11996
|
+
...installed,
|
|
11997
|
+
equivocation: {
|
|
11998
|
+
sequence: version.sequence,
|
|
11999
|
+
digest,
|
|
12000
|
+
at: this.now()
|
|
12001
|
+
}
|
|
12002
|
+
}, installed)) continue;
|
|
12003
|
+
fail("equivocation", `Two different versions ${version.sequence} exist. Ghostly kept the one you have.`);
|
|
12315
12004
|
}
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
|
-
|
|
12321
|
-
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12005
|
+
if (decision === "same" && installed) {
|
|
12006
|
+
const files = await this.hasBundle(installed.bytes, digest) ? null : wrote = await this.writeBundle(digest, bytes);
|
|
12007
|
+
const pin = fromStore !== void 0 && installed.store !== fromStore;
|
|
12008
|
+
if (files || pin) {
|
|
12009
|
+
const { pending, ...rest } = installed;
|
|
12010
|
+
if (!await this.putAppIfUnchanged({
|
|
12011
|
+
...pin ? rest : installed,
|
|
12012
|
+
...files && { bytes: files },
|
|
12013
|
+
...pin && { store: fromStore }
|
|
12014
|
+
}, installed)) continue;
|
|
12015
|
+
if (pin && pending) await this.removeBundle(pending.bytes, pending.digest);
|
|
12016
|
+
}
|
|
12017
|
+
this.staged.delete(digest);
|
|
12018
|
+
return this.view(await this.app(version.ref), stores);
|
|
12019
|
+
}
|
|
12020
|
+
const kind = wrote = await this.writeBundle(digest, bytes);
|
|
12021
|
+
const next = this.versionRecord(installed, bundle, kind, from, fromStore);
|
|
12022
|
+
if (!await this.putAppIfUnchanged(next, installed)) continue;
|
|
12023
|
+
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
12024
|
+
if (installed && installed.digest !== digest) await this.removeBundle(installed.bytes, installed.digest);
|
|
12025
|
+
if (installed?.pending && next.pending?.digest !== installed.pending.digest && installed.pending.digest !== digest) await this.removeBundle(installed.pending.bytes, installed.pending.digest);
|
|
12026
|
+
this.staged.delete(digest);
|
|
12027
|
+
return this.view(next, stores);
|
|
12330
12028
|
}
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
|
|
12335
|
-
const next = this.versionRecord(installed, bundle, kind, from, fromStore);
|
|
12336
|
-
await this.putApp(next);
|
|
12337
|
-
if (!installed && this.builtIn(version.ref)) await this.keepBuiltIn(version.ref);
|
|
12338
|
-
if (installed && installed.digest !== digest) await this.removeBundle(installed.bytes, installed.digest);
|
|
12339
|
-
if (installed?.pending && next.pending?.digest !== installed.pending.digest && installed.pending.digest !== digest) await this.removeBundle(installed.pending.bytes, installed.pending.digest);
|
|
12340
|
-
this.staged.delete(digest);
|
|
12341
|
-
return this.view(next, stores);
|
|
12029
|
+
} catch (error) {
|
|
12030
|
+
if (wrote) await this.removeUnusedBundle(version.ref, wrote, digest);
|
|
12031
|
+
throw error;
|
|
12032
|
+
}
|
|
12342
12033
|
}
|
|
12343
12034
|
/**
|
|
12344
12035
|
* The record of a version installed now, keeping what the app had (its revocations, a newer version waiting). `store`
|
|
@@ -12348,7 +12039,11 @@ var Apps = class {
|
|
|
12348
12039
|
versionRecord(installed, bundle, kind, from, store) {
|
|
12349
12040
|
const { manifest, digest } = bundle;
|
|
12350
12041
|
const now = this.now();
|
|
12351
|
-
const
|
|
12042
|
+
const kept = installed?.pending && installed.pending.sequence > manifest.sequence && installed.store === store ? installed.pending : void 0;
|
|
12043
|
+
const keepPending = kept && {
|
|
12044
|
+
...kept,
|
|
12045
|
+
added: addedAppPermissions(manifest.permissions, kept.manifest.permissions)
|
|
12046
|
+
};
|
|
12352
12047
|
return {
|
|
12353
12048
|
ref: appRef(manifest.publisher, manifest.name),
|
|
12354
12049
|
publisher: manifest.publisher,
|
|
@@ -12389,9 +12084,25 @@ var Apps = class {
|
|
|
12389
12084
|
permissions: read.bundle.manifest.permissions
|
|
12390
12085
|
});
|
|
12391
12086
|
if (plan.action === "refuse") fail(plan.decision, "This update can no longer be installed");
|
|
12087
|
+
const added = plan.action === "ask" ? plan.added : [];
|
|
12088
|
+
if (added.length !== pending.added.length || added.some((p) => !pending.added.includes(p))) {
|
|
12089
|
+
await this.putApp({
|
|
12090
|
+
...installed,
|
|
12091
|
+
pending: {
|
|
12092
|
+
...pending,
|
|
12093
|
+
added
|
|
12094
|
+
}
|
|
12095
|
+
});
|
|
12096
|
+
fail("permissions-changed", `This update now adds ${added.length ? added.join(", ") : "no permission"}; look at it again`);
|
|
12097
|
+
}
|
|
12392
12098
|
const { pending: _p, ...without } = installed;
|
|
12393
12099
|
const next = this.versionRecord(without, read.bundle, pending.bytes, pending.from, installed.store);
|
|
12394
|
-
await this.
|
|
12100
|
+
if (!await this.putAppIfUnchanged(next, installed)) {
|
|
12101
|
+
const now = await this.app(ref);
|
|
12102
|
+
if (!now) fail("not-installed", "This app is not installed");
|
|
12103
|
+
if (now.digest === pending.digest) return this.view(now, await this.stores());
|
|
12104
|
+
fail("no-update", "This update can no longer be installed");
|
|
12105
|
+
}
|
|
12395
12106
|
await this.removeBundle(installed.bytes, installed.digest);
|
|
12396
12107
|
return this.view(next, stores);
|
|
12397
12108
|
}
|
|
@@ -12427,15 +12138,17 @@ var Apps = class {
|
|
|
12427
12138
|
if (!await this.hasBundle(listed.bytes, listed.digest)) await this.fetchFiles({ ref: listed.ref }).catch(() => {});
|
|
12428
12139
|
const first = await this.app(listed.ref);
|
|
12429
12140
|
if (!first) continue;
|
|
12141
|
+
let stored = first;
|
|
12430
12142
|
let app = first;
|
|
12431
12143
|
let outcome = "none";
|
|
12432
12144
|
let wrote;
|
|
12145
|
+
const dropped = [];
|
|
12433
12146
|
if (app.store !== void 0 && !stores.some((s) => s.key === app.store)) {
|
|
12434
12147
|
const { store: _s, ...unpinned } = app;
|
|
12435
12148
|
app = unpinned;
|
|
12436
12149
|
}
|
|
12437
12150
|
if (app.store !== void 0 && app.pending && stores.find((s) => s.key === app.store)?.index && this.pinnedListing(app, stores)?.digest !== app.pending.digest) {
|
|
12438
|
-
|
|
12151
|
+
dropped.push(app.pending);
|
|
12439
12152
|
const { pending: _p, ...rest } = app;
|
|
12440
12153
|
app = rest;
|
|
12441
12154
|
}
|
|
@@ -12453,6 +12166,7 @@ var Apps = class {
|
|
|
12453
12166
|
const missed = `${s.key} ${app.ref} ${url}`;
|
|
12454
12167
|
if (candidates.has(url) || s.digest !== void 0 && this.listingMisses.get(missed) === seen) continue;
|
|
12455
12168
|
candidates.set(url, {
|
|
12169
|
+
sequence: listing.sequence,
|
|
12456
12170
|
...pinned !== void 0 && { digest: listing.digest },
|
|
12457
12171
|
peek: true,
|
|
12458
12172
|
...s.digest !== void 0 && { miss: [missed, seen] }
|
|
@@ -12463,13 +12177,21 @@ var Apps = class {
|
|
|
12463
12177
|
if (candidates.has(url)) continue;
|
|
12464
12178
|
try {
|
|
12465
12179
|
const peek = await this.peekAt(url);
|
|
12466
|
-
if (peek && newer(peek)) candidates.set(url, {
|
|
12180
|
+
if (peek && newer(peek)) candidates.set(url, {
|
|
12181
|
+
sequence: peek.sequence,
|
|
12182
|
+
holds: peek
|
|
12183
|
+
});
|
|
12467
12184
|
} catch {}
|
|
12468
12185
|
}
|
|
12469
12186
|
const revokeRead = /* @__PURE__ */ new Set();
|
|
12470
12187
|
const before = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
|
|
12471
12188
|
app = withRevocations(app, before ?? []);
|
|
12472
|
-
|
|
12189
|
+
if (app.pending && this.runStatus(versionOf(app.pending.manifest, app.pending.digest), this.storeViews(stores), app.revocations).status !== "ok") {
|
|
12190
|
+
await this.removeBundle(app.pending.bytes, app.pending.digest);
|
|
12191
|
+
const { pending: _p, ...rest } = app;
|
|
12192
|
+
app = rest;
|
|
12193
|
+
}
|
|
12194
|
+
for (const [url, want] of [...candidates].sort(([, a], [, b]) => b.sequence - a.sequence)) {
|
|
12473
12195
|
let holds = want.holds;
|
|
12474
12196
|
if (want.peek) {
|
|
12475
12197
|
let peek;
|
|
@@ -12538,13 +12260,13 @@ var Apps = class {
|
|
|
12538
12260
|
const next = this.versionRecord(app, bundle, kind, url, app.store);
|
|
12539
12261
|
const passed = old.pending && old.pending.sequence <= version.sequence ? old.pending : void 0;
|
|
12540
12262
|
if (passed) delete next.pending;
|
|
12541
|
-
if (!await this.
|
|
12542
|
-
app = next;
|
|
12263
|
+
if (!await this.putAppIfUnchanged(next, stored)) break;
|
|
12264
|
+
app = stored = next;
|
|
12543
12265
|
if (passed) await this.removeBundle(passed.bytes, passed.digest);
|
|
12544
12266
|
await this.removeBundle(old.bytes, old.digest);
|
|
12545
12267
|
outcome = "updated";
|
|
12546
12268
|
} else {
|
|
12547
|
-
if (app.pending)
|
|
12269
|
+
if (app.pending) dropped.push(app.pending);
|
|
12548
12270
|
app = {
|
|
12549
12271
|
...app,
|
|
12550
12272
|
pending: {
|
|
@@ -12563,13 +12285,14 @@ var Apps = class {
|
|
|
12563
12285
|
}
|
|
12564
12286
|
const after = await this.readRevocations(app.ref, [app.from, ...app.manifest.sources ?? []], revokeRead);
|
|
12565
12287
|
const revocations = before || after ? [...before ?? [], ...after ?? []] : null;
|
|
12566
|
-
const versions =
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12288
|
+
const versions = this.versionsOf(app);
|
|
12289
|
+
const stays = revocations ? stopping(versions, app.revocations ?? []) : app.revocations ?? [];
|
|
12290
|
+
const carried = stopping(versions, stores.flatMap((s) => s.index?.revoked ?? []));
|
|
12291
|
+
const merged = new Map([
|
|
12292
|
+
...stays,
|
|
12293
|
+
...revocations ?? [],
|
|
12294
|
+
...carried
|
|
12295
|
+
].map((r) => [canonicalJson(r), r]));
|
|
12573
12296
|
if ((await this.app(app.ref))?.store === void 0 && app.store !== void 0) {
|
|
12574
12297
|
const { store: _s, ...unpinned } = app;
|
|
12575
12298
|
app = unpinned;
|
|
@@ -12579,10 +12302,9 @@ var Apps = class {
|
|
|
12579
12302
|
...merged.size && { revocations: [...merged.values()] },
|
|
12580
12303
|
checkedAt: this.now()
|
|
12581
12304
|
};
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
}
|
|
12305
|
+
const put = await this.putAppIfUnchanged(app, stored);
|
|
12306
|
+
for (const files of [...dropped, ...!put && wrote ? [wrote] : []]) await this.removeUnusedBundle(app.ref, files.bytes, files.digest);
|
|
12307
|
+
if (!put) continue;
|
|
12586
12308
|
out.push({
|
|
12587
12309
|
ref: app.ref,
|
|
12588
12310
|
outcome,
|
|
@@ -13227,6 +12949,12 @@ function isPush(value) {
|
|
|
13227
12949
|
}
|
|
13228
12950
|
return true;
|
|
13229
12951
|
}
|
|
12952
|
+
/** One earlier device set as a record keeps it, and as a handoff's part `devices` carries it. */
|
|
12953
|
+
function isEarlierSet(value) {
|
|
12954
|
+
const set = value;
|
|
12955
|
+
if (!set || typeof set !== "object" || !bytes(set.d) || !bytes(set.tombstone) || !text(set.setUpdate) || !Array.isArray(set.pending) || !set.pending.every(bytes)) return false;
|
|
12956
|
+
return set.pending.length <= 4 && (set.foreign === void 0 || set.foreign === true) && optional(set.removed, bytes);
|
|
12957
|
+
}
|
|
13230
12958
|
/** Why a stored record cannot be trusted. The gate then starts nothing (see `gate.ts`). */
|
|
13231
12959
|
var DeviceRecordError = class extends Error {
|
|
13232
12960
|
constructor(what) {
|
|
@@ -13265,7 +12993,7 @@ function parseDeviceRecord(value) {
|
|
|
13265
12993
|
]) if (!optional(r[field], bytes)) return bad(field);
|
|
13266
12994
|
if (!optional(r.signingKey, (v) => DEVICE_SIGNING_KEY_KINDS.includes(v))) return bad("signingKey");
|
|
13267
12995
|
if (r.network !== void 0 && !isNetwork(r.network)) return bad("network");
|
|
13268
|
-
if (!optional(r.forks, (v) => Array.isArray(v) && v.
|
|
12996
|
+
if (!optional(r.forks, (v) => Array.isArray(v) && v.every((name) => text(name) && /^ghostly(_[A-Za-z0-9_-]{1,64})?$/.test(name)))) return bad("forks");
|
|
13269
12997
|
if (!optional(r.breezDatabases, (v) => Array.isArray(v) && v.length <= 8 && v.every((name) => text(name) && /^ghostly-breez-/.test(name)))) return bad("breezDatabases");
|
|
13270
12998
|
if (!optional(r.releasedTurn, (v) => count(v, 2 ** 32 - 1))) return bad("releasedTurn");
|
|
13271
12999
|
if (!optional(r.seenSequence, (v) => count(v, Number.MAX_SAFE_INTEGER))) return bad("seenSequence");
|
|
@@ -13320,10 +13048,7 @@ function parseDeviceRecord(value) {
|
|
|
13320
13048
|
if (!raise || typeof raise !== "object" || !bytes(raise.id) || raise.why !== "takeover" && raise.why !== "restore" || !count(raise.takeovers, 2 ** 32 - 1) || !count(raise.at, Number.MAX_SAFE_INTEGER)) return bad("raise");
|
|
13321
13049
|
}
|
|
13322
13050
|
if (!Array.isArray(r.earlierSets) || r.earlierSets.length > 8) return bad("the earlier device sets");
|
|
13323
|
-
|
|
13324
|
-
if (!set || !bytes(set.d) || !bytes(set.tombstone) || !text(set.setUpdate) || !Array.isArray(set.pending) || !set.pending.every(bytes)) return bad("an earlier device set");
|
|
13325
|
-
if (set.pending.length > 4 || set.foreign !== void 0 && set.foreign !== true) return bad("an earlier device set");
|
|
13326
|
-
}
|
|
13051
|
+
if (!r.earlierSets.every(isEarlierSet)) return bad("an earlier device set");
|
|
13327
13052
|
if (r.setNotice !== void 0) {
|
|
13328
13053
|
const n = r.setNotice;
|
|
13329
13054
|
if (!n || typeof n !== "object" || !texts(n.names, 4) || !count(n.at, Number.MAX_SAFE_INTEGER) || n.seen !== void 0 && n.seen !== true) return bad("setNotice");
|
|
@@ -13808,11 +13533,14 @@ async function enrollDevice(profile, state, patch = {}) {
|
|
|
13808
13533
|
async function moveDevice(profile, to, patch = {}) {
|
|
13809
13534
|
return change(profile, (current) => transition(current, profile, to, patch));
|
|
13810
13535
|
}
|
|
13811
|
-
/**
|
|
13536
|
+
/**
|
|
13537
|
+
* Fields of the record changed, its state kept. There must be a record. A function makes the patch from the record
|
|
13538
|
+
* read inside this write, so a write that landed since the caller's own read is not written over (null: no change).
|
|
13539
|
+
*/
|
|
13812
13540
|
async function amendDevice(profile, patch) {
|
|
13813
13541
|
return change(profile, (current) => {
|
|
13814
13542
|
if (!current) throw new Error("This profile has no device set");
|
|
13815
|
-
return amend(current, patch);
|
|
13543
|
+
return amend(current, (typeof patch === "function" ? patch(current) : patch) ?? {});
|
|
13816
13544
|
});
|
|
13817
13545
|
}
|
|
13818
13546
|
/** One writer at a time in this page; across pages and documents, the Web Lock below and the check inside `swap`. */
|
|
@@ -15361,6 +15089,8 @@ var EnrollInviter = class extends Enrollment {
|
|
|
15361
15089
|
seen = false;
|
|
15362
15090
|
/** The person answered the digits: one answer is taken, before the record is read or written for it. */
|
|
15363
15091
|
answered = false;
|
|
15092
|
+
/** When the code's ten minutes end, in ms. */
|
|
15093
|
+
expiresAt = 0;
|
|
15364
15094
|
constructor(options) {
|
|
15365
15095
|
super(options, {
|
|
15366
15096
|
role: "inviter",
|
|
@@ -15430,6 +15160,7 @@ var EnrollInviter = class extends Enrollment {
|
|
|
15430
15160
|
});
|
|
15431
15161
|
}
|
|
15432
15162
|
});
|
|
15163
|
+
this.expiresAt = side.invite.expires * 1e3;
|
|
15433
15164
|
this.timer(Math.max(0, side.invite.expires * 1e3 - this.now()), () => {
|
|
15434
15165
|
if (this.view.step === "waiting" || this.view.step === "confirm") this.fail("expired", "expired");
|
|
15435
15166
|
});
|
|
@@ -15443,6 +15174,10 @@ var EnrollInviter = class extends Enrollment {
|
|
|
15443
15174
|
return;
|
|
15444
15175
|
}
|
|
15445
15176
|
if (frame.t === "enroll-hello" && this.view.step === "waiting" && this.session && !this.joiner) {
|
|
15177
|
+
if (this.now() >= this.expiresAt) {
|
|
15178
|
+
await this.fail("expired", "expired");
|
|
15179
|
+
return;
|
|
15180
|
+
}
|
|
15446
15181
|
const hello = readEnrollHello(frame, this.session.hash, this.key.publicKey, this.session.peerKey);
|
|
15447
15182
|
if (!hello) {
|
|
15448
15183
|
await this.fail("proof", "failed");
|
|
@@ -15477,6 +15212,10 @@ var EnrollInviter = class extends Enrollment {
|
|
|
15477
15212
|
async confirm(match) {
|
|
15478
15213
|
if (this.over || this.answered || this.view.step !== "confirm" || !this.joiner) throw new Error("There are no digits to confirm");
|
|
15479
15214
|
this.answered = true;
|
|
15215
|
+
if (this.now() >= this.expiresAt) {
|
|
15216
|
+
await this.fail("expired", "expired", this.joiner.name);
|
|
15217
|
+
return this.view;
|
|
15218
|
+
}
|
|
15480
15219
|
if (!match) {
|
|
15481
15220
|
await this.fail("digits", "digits", this.joiner.name);
|
|
15482
15221
|
return this.view;
|
|
@@ -16438,9 +16177,16 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16438
16177
|
const was = JSON.parse(set.setUpdate);
|
|
16439
16178
|
if (typeof was.rec === "string") oldRec = fromBase64Url(was.rec);
|
|
16440
16179
|
} catch {}
|
|
16441
|
-
const
|
|
16180
|
+
const setKeys = turnKeys(fromBase64Url(set.d)), tombBytes = fromBase64Url(set.tombstone);
|
|
16181
|
+
const oldTomb = readTurnPacket(setKeys, tombBytes);
|
|
16182
|
+
const kept = oldTomb.kind === "valid" ? turnSlots.map((slot, i) => {
|
|
16183
|
+
const was = oldTomb.record.slots[i];
|
|
16184
|
+
return slot && was && bytesEqual(was.key, slot.key) ? slot : null;
|
|
16185
|
+
}) : turnSlots;
|
|
16186
|
+
const setUpdate = pending.length ? JSON.stringify(await setUpdateFrame(setKeys.address, {
|
|
16442
16187
|
...update,
|
|
16443
|
-
|
|
16188
|
+
set: kept,
|
|
16189
|
+
tomb: tombBytes,
|
|
16444
16190
|
...oldRec ? { rec: oldRec } : {}
|
|
16445
16191
|
}, signer)) : set.setUpdate;
|
|
16446
16192
|
earlier.push({
|
|
@@ -16453,7 +16199,8 @@ async function planSetMove(record, signer, options = {}) {
|
|
|
16453
16199
|
d: record.d,
|
|
16454
16200
|
tombstone: toBase64Url(tomb),
|
|
16455
16201
|
setUpdate: JSON.stringify(frame),
|
|
16456
|
-
pending: staying(slots.flatMap((slot) => slot ? [slot.key] : []))
|
|
16202
|
+
pending: staying(slots.flatMap((slot) => slot ? [slot.key] : [])),
|
|
16203
|
+
...removed ? { removed: removed.key } : {}
|
|
16457
16204
|
});
|
|
16458
16205
|
return {
|
|
16459
16206
|
removed,
|
|
@@ -17201,6 +16948,8 @@ var NATIVE_RETRY_MS$1 = 1e4;
|
|
|
17201
16948
|
var NATIVE_RETRY_MAX_MS = 12e4;
|
|
17202
16949
|
/** The other device is there and no session opened over WebRTC in this long: the link goes on without it (`withoutRtc`). */
|
|
17203
16950
|
var DEVICE_RTC_MS = 2e4;
|
|
16951
|
+
/** The longest that wait grows to, for a link that went back to WebRTC again and again (`withRtc`). */
|
|
16952
|
+
var DEVICE_RTC_MAX_MS = 3e5;
|
|
17204
16953
|
/** How often a standby reads the turn while its screen shows (WISP 06 § When a device checks), and the jitter on it. */
|
|
17205
16954
|
var STANDBY_TURN_EVERY_MS = 6e5;
|
|
17206
16955
|
var STANDBY_TURN_JITTER_MS = 6e4;
|
|
@@ -17217,6 +16966,8 @@ var defaultPeerConnection = () => typeof RTCPeerConnection === "undefined" ? voi
|
|
|
17217
16966
|
var DeviceLinks = class {
|
|
17218
16967
|
options;
|
|
17219
16968
|
running = /* @__PURE__ */ new Map();
|
|
16969
|
+
/** By link: the times it went back to WebRTC (`withRtc`) since a session last opened. Each doubles the wait before it goes without again. */
|
|
16970
|
+
rtcBacks = /* @__PURE__ */ new Map();
|
|
17220
16971
|
createPeerConnection;
|
|
17221
16972
|
key = null;
|
|
17222
16973
|
keeper = null;
|
|
@@ -17454,6 +17205,7 @@ var DeviceLinks = class {
|
|
|
17454
17205
|
this.changed();
|
|
17455
17206
|
},
|
|
17456
17207
|
onDataLinkState: (state) => {
|
|
17208
|
+
if (state === "open") this.rtcBacks.delete(running.id);
|
|
17457
17209
|
if (state === "open" && running.rtcWait) {
|
|
17458
17210
|
clearTimeout(running.rtcWait);
|
|
17459
17211
|
running.rtcWait = void 0;
|
|
@@ -17476,11 +17228,7 @@ var DeviceLinks = class {
|
|
|
17476
17228
|
},
|
|
17477
17229
|
onAnswersRefused: () => this.withoutRtc(running),
|
|
17478
17230
|
onPresence: (presence) => {
|
|
17479
|
-
if (
|
|
17480
|
-
running.rtcWait = setTimeout(() => {
|
|
17481
|
-
running.rtcWait = void 0;
|
|
17482
|
-
if (!running.link.isDataLinkOpen) this.withoutRtc(running);
|
|
17483
|
-
}, DEVICE_RTC_MS);
|
|
17231
|
+
if (presence.online) this.waitForRtc(running);
|
|
17484
17232
|
},
|
|
17485
17233
|
onPacketTransports: (transports) => {
|
|
17486
17234
|
if (!running.native && !transports.includes("webrtc/1")) this.startNative(running);
|
|
@@ -17522,6 +17270,10 @@ var DeviceLinks = class {
|
|
|
17522
17270
|
if (!this.missingNative(running).length && !running.starting.size) running.nativeMisses = 0;
|
|
17523
17271
|
}, () => {
|
|
17524
17272
|
running.starting.delete(transport);
|
|
17273
|
+
if (running.rtcOff && !running.starting.size && !running.link.availableTransports.length) {
|
|
17274
|
+
this.withRtc(running);
|
|
17275
|
+
return;
|
|
17276
|
+
}
|
|
17525
17277
|
this.retryNative(running);
|
|
17526
17278
|
});
|
|
17527
17279
|
}
|
|
@@ -17781,9 +17533,8 @@ var DeviceLinks = class {
|
|
|
17781
17533
|
}
|
|
17782
17534
|
/** `key` holds the set under `d` (or the current one): its pending frame is done, and the old link goes. */
|
|
17783
17535
|
async acked(key, d) {
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
await amendDevice(this.options.profile, patch);
|
|
17536
|
+
if (!acknowledged(await this.record(), key, d)) return;
|
|
17537
|
+
await amendDevice(this.options.profile, (current) => acknowledged(current, key, d));
|
|
17787
17538
|
await this.refresh();
|
|
17788
17539
|
this.changed();
|
|
17789
17540
|
}
|
|
@@ -17866,14 +17617,18 @@ var DeviceLinks = class {
|
|
|
17866
17617
|
/**
|
|
17867
17618
|
* WebRTC on both devices that connects nothing (two browsers whose host candidates the other does not resolve, a
|
|
17868
17619
|
* router that does not hairpin, no TURN): neither packet says it has no WebRTC, so neither device starts a native
|
|
17869
|
-
* endpoint, and the link never went live. It starts again as on an app with no WebRTC, for this run, as a group's edge
|
|
17620
|
+
* endpoint, and the link never went live. It starts again as on an app with no WebRTC, for this run (`withRtc` aside), as a group's edge
|
|
17870
17621
|
* does (node.ts `edgeWithoutRtc`): its native endpoints run and its packet lists no `webrtc/1`, the other device starts
|
|
17871
17622
|
* its own for it as for a Linux Desktop, and the two meet over Iroh's relay. Only with no session open, and only
|
|
17872
17623
|
* where this app has a native transport to go on with.
|
|
17873
17624
|
*/
|
|
17874
|
-
withoutRtc(running) {
|
|
17625
|
+
withoutRtc(running, waited = false) {
|
|
17875
17626
|
if (this.stopped || running.rtcOff || running.native || !this.createPeerConnection || running.link.isDataLinkOpen) return;
|
|
17876
17627
|
if (!Object.values(this.nativeFactories()).some(Boolean)) return;
|
|
17628
|
+
if (!waited && this.rtcBacks.get(running.id)) {
|
|
17629
|
+
this.waitForRtc(running);
|
|
17630
|
+
return;
|
|
17631
|
+
}
|
|
17877
17632
|
const run = this.queue.catch(() => {}).then(async () => {
|
|
17878
17633
|
if (this.stopped || this.running.get(running.id) !== running || running.link.isDataLinkOpen) return;
|
|
17879
17634
|
this.running.delete(running.id);
|
|
@@ -17891,6 +17646,40 @@ var DeviceLinks = class {
|
|
|
17891
17646
|
});
|
|
17892
17647
|
this.queue = run;
|
|
17893
17648
|
}
|
|
17649
|
+
/** `withoutRtc` once `DEVICE_RTC_MS` passed with no session open, twice as long for each time it went back (`rtcBacks`). */
|
|
17650
|
+
waitForRtc(running) {
|
|
17651
|
+
if (running.rtcOff || running.rtcWait || running.link.isDataLinkOpen) return;
|
|
17652
|
+
running.rtcWait = setTimeout(() => {
|
|
17653
|
+
running.rtcWait = void 0;
|
|
17654
|
+
if (!running.link.isDataLinkOpen) this.withoutRtc(running, true);
|
|
17655
|
+
}, Math.min(DEVICE_RTC_MS * 2 ** (this.rtcBacks.get(running.id) ?? 0), DEVICE_RTC_MAX_MS));
|
|
17656
|
+
}
|
|
17657
|
+
/**
|
|
17658
|
+
* The link that went on without WebRTC (`withoutRtc`) started none of its native transports: an Iroh relay neither
|
|
17659
|
+
* device reaches, and no HyperDHT relay. With nothing to go through it starts again with WebRTC, which may connect
|
|
17660
|
+
* now, or only after `DEVICE_RTC_MS` (a device that just reloaded dials at its own pace). The wait before it goes
|
|
17661
|
+
* without WebRTC again doubles each time (`rtcBacks`), so a native transport that comes back is still tried.
|
|
17662
|
+
*/
|
|
17663
|
+
withRtc(running) {
|
|
17664
|
+
if (this.stopped || !running.rtcOff || running.link.isDataLinkOpen || this.running.get(running.id) !== running) return;
|
|
17665
|
+
this.rtcBacks.set(running.id, (this.rtcBacks.get(running.id) ?? 0) + 1);
|
|
17666
|
+
const run = this.queue.catch(() => {}).then(async () => {
|
|
17667
|
+
if (this.stopped || this.running.get(running.id) !== running || running.link.isDataLinkOpen) return;
|
|
17668
|
+
this.running.delete(running.id);
|
|
17669
|
+
await this.close(running, false);
|
|
17670
|
+
if (this.stopped) return;
|
|
17671
|
+
this.open({
|
|
17672
|
+
id: running.id,
|
|
17673
|
+
d: fromBase64Url(running.d),
|
|
17674
|
+
key: running.key,
|
|
17675
|
+
name: running.name,
|
|
17676
|
+
slot: running.slot,
|
|
17677
|
+
earlier: running.earlier
|
|
17678
|
+
});
|
|
17679
|
+
this.changed();
|
|
17680
|
+
});
|
|
17681
|
+
this.queue = run;
|
|
17682
|
+
}
|
|
17894
17683
|
find(key) {
|
|
17895
17684
|
const all = [...this.running.values()].filter((r) => r.key === key);
|
|
17896
17685
|
return all.find((r) => !r.earlier && this.isLive(r)) ?? all.find((r) => this.isLive(r)) ?? all.find((r) => !r.earlier) ?? all[0];
|
|
@@ -18219,6 +18008,12 @@ var reportOf = (busy) => busy === null ? null : typeof busy === "string" ? { why
|
|
|
18219
18008
|
var wireWhy = (report) => report.why === "call" ? "call" : "handoff";
|
|
18220
18009
|
var name = (record, key) => record.deviceSet.find((slot) => slot?.key === key)?.name ?? "";
|
|
18221
18010
|
var slotOf = (record, key) => record.deviceSet.findIndex((slot) => slot?.key === key);
|
|
18011
|
+
/**
|
|
18012
|
+
* The counts of the devices still in the set: a removed device cannot pull (`onRequest` refuses it), and one added again
|
|
18013
|
+
* has a new key, so the list stays within the set's size instead of growing to the record's cap of 16 and refusing every
|
|
18014
|
+
* write after it.
|
|
18015
|
+
*/
|
|
18016
|
+
var setAttempts = (record, attempts) => Object.fromEntries(Object.entries(attempts ?? {}).filter(([key]) => slotOf(record, key) >= 0));
|
|
18222
18017
|
/** One session of a handoff with the other device: its own X25519 key, the other's hello, and the stream key. */
|
|
18223
18018
|
var Session = class {
|
|
18224
18019
|
transcript;
|
|
@@ -18247,6 +18042,15 @@ function idsOf(files) {
|
|
|
18247
18042
|
for (const list of Object.values(ids)) list.sort();
|
|
18248
18043
|
return ids;
|
|
18249
18044
|
}
|
|
18045
|
+
/**
|
|
18046
|
+
* The part `devices` (WISP 06 § What moves): the earlier device sets of the giver's record, so the device that takes
|
|
18047
|
+
* the turn puts their tombstones and delivers their frames. None when the record holds none: a profile that never
|
|
18048
|
+
* removed a device moves as it did before the part.
|
|
18049
|
+
*/
|
|
18050
|
+
var DEVICES_PART = "devices";
|
|
18051
|
+
function devicesBytes(record) {
|
|
18052
|
+
return record?.earlierSets.length ? new TextEncoder().encode(JSON.stringify({ earlierSets: record.earlierSets })) : null;
|
|
18053
|
+
}
|
|
18250
18054
|
/** Files over the taker's limit stay behind for later (WISP 06 § User experience, "Bring large files later"). */
|
|
18251
18055
|
var isLater = (file, later) => !!later && later > 0 && file.size > later;
|
|
18252
18056
|
/**
|
|
@@ -18686,7 +18490,7 @@ var HandoffGiver = class {
|
|
|
18686
18490
|
const allowed = handoffAttemptAllowed(record.handoffAttempts?.[from], this.now());
|
|
18687
18491
|
if (allowed !== "ok") return busy(allowed, allowed === "refused" ? 0 : handoffRetryAfter(record.handoffAttempts?.[from], this.now()));
|
|
18688
18492
|
await this.ports.records.amend({ handoffAttempts: {
|
|
18689
|
-
...record.handoffAttempts,
|
|
18493
|
+
...setAttempts(record, record.handoffAttempts),
|
|
18690
18494
|
[from]: handoffAttemptFailed(record.handoffAttempts?.[from], this.now())
|
|
18691
18495
|
} });
|
|
18692
18496
|
this.begin(from, request.id, record);
|
|
@@ -18744,10 +18548,9 @@ var HandoffGiver = class {
|
|
|
18744
18548
|
throw error;
|
|
18745
18549
|
}
|
|
18746
18550
|
const record = await this.ports.records.read();
|
|
18747
|
-
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
} });
|
|
18551
|
+
const attempts = record ? setAttempts(record, record.handoffAttempts) : {};
|
|
18552
|
+
delete attempts[from];
|
|
18553
|
+
await this.ports.records.amend({ handoffAttempts: attempts });
|
|
18751
18554
|
this.authorized(session, key);
|
|
18752
18555
|
}
|
|
18753
18556
|
wrongPassword(from) {
|
|
@@ -18815,12 +18618,13 @@ var HandoffGiver = class {
|
|
|
18815
18618
|
});
|
|
18816
18619
|
const parts = [...send];
|
|
18817
18620
|
if (pass === 2) {
|
|
18818
|
-
this.bundleMade ??= this.ports.source.bundle().then((bytes) => ({
|
|
18621
|
+
this.bundleMade ??= Promise.all([this.ports.source.bundle(), this.ports.records.read()]).then(([bytes, record]) => ({
|
|
18819
18622
|
bytes,
|
|
18820
|
-
digest: toBase64Url(sha256(bytes))
|
|
18623
|
+
digest: toBase64Url(sha256(bytes)),
|
|
18624
|
+
devices: devicesBytes(record)
|
|
18821
18625
|
}));
|
|
18822
18626
|
const made = this.bundleMade;
|
|
18823
|
-
const { bytes: bundle, digest } = await made.catch((error) => {
|
|
18627
|
+
const { bytes: bundle, digest, devices } = await made.catch((error) => {
|
|
18824
18628
|
if (this.bundleMade === made) this.bundleMade = null;
|
|
18825
18629
|
throw error;
|
|
18826
18630
|
});
|
|
@@ -18839,6 +18643,19 @@ var HandoffGiver = class {
|
|
|
18839
18643
|
bundle.length,
|
|
18840
18644
|
digest
|
|
18841
18645
|
];
|
|
18646
|
+
this.devicesPart = devices && [
|
|
18647
|
+
DEVICES_PART,
|
|
18648
|
+
devices.length,
|
|
18649
|
+
toBase64Url(sha256(devices))
|
|
18650
|
+
];
|
|
18651
|
+
if (this.devicesPart) {
|
|
18652
|
+
parts.push(this.devicesPart);
|
|
18653
|
+
out.push({
|
|
18654
|
+
name: DEVICES_PART,
|
|
18655
|
+
size: devices.length,
|
|
18656
|
+
read: async (offset, length) => devices.subarray(offset, offset + length)
|
|
18657
|
+
});
|
|
18658
|
+
}
|
|
18842
18659
|
}
|
|
18843
18660
|
this.planned = {
|
|
18844
18661
|
total: parts.reduce((sum, part) => sum + part[1], 0),
|
|
@@ -18871,6 +18688,7 @@ var HandoffGiver = class {
|
|
|
18871
18688
|
else this.arm(HANDOFF_TIMINGS.verifiedMs, () => this.backToActive());
|
|
18872
18689
|
}
|
|
18873
18690
|
bundlePart = null;
|
|
18691
|
+
devicesPart = null;
|
|
18874
18692
|
bundleMade = null;
|
|
18875
18693
|
paused = false;
|
|
18876
18694
|
stallTimer;
|
|
@@ -18913,7 +18731,11 @@ var HandoffGiver = class {
|
|
|
18913
18731
|
const h = readHandoffVerified(frame, this.ports.turnAddress, this.turn + 1, fromBase64Url(from));
|
|
18914
18732
|
if (!h) return;
|
|
18915
18733
|
const later = new Set(this.laterParts.map((part) => part[2]));
|
|
18916
|
-
const parts = [
|
|
18734
|
+
const parts = [
|
|
18735
|
+
...fileParts(this.allFiles.filter((file) => !later.has(file.sha256))),
|
|
18736
|
+
this.bundlePart,
|
|
18737
|
+
...this.devicesPart ? [this.devicesPart] : []
|
|
18738
|
+
];
|
|
18917
18739
|
const expected = handoffDigest(this.turn + 1, this.ports.ownKey, fromBase64Url(from), parts);
|
|
18918
18740
|
if (toBase64Url(expected) !== toBase64Url(h)) {
|
|
18919
18741
|
this.out(handoffCancelFrame("damaged"));
|
|
@@ -19981,6 +19803,7 @@ var FileDesk = class {
|
|
|
19981
19803
|
openTarget: (record) => this.openTarget(linkId, record),
|
|
19982
19804
|
openSource: (record) => this.openSource(linkId, record),
|
|
19983
19805
|
changed: (record, transferred, progress) => this.changed(linkId, record, transferred, progress),
|
|
19806
|
+
kept: () => made.saving,
|
|
19984
19807
|
room: async () => (await fileBytes()).room(),
|
|
19985
19808
|
...this.deps.sendData && { sendData: (id, offset, data) => this.deps.sendData(linkId, id, offset, data) },
|
|
19986
19809
|
writable: () => this.deps.writable?.(linkId)
|
|
@@ -20936,6 +20759,8 @@ var RESEND_POLICY = {
|
|
|
20936
20759
|
};
|
|
20937
20760
|
/** How long one turn of an outbox may hold the next one back: a send that never returns must not stop the chat. */
|
|
20938
20761
|
var TURN_MS = 3e4;
|
|
20762
|
+
/** The most rows a new message's look reads one by one (`Outbox.look`). */
|
|
20763
|
+
var KNOWN_ROWS = 16;
|
|
20939
20764
|
/**
|
|
20940
20765
|
* A text of mine, not handed to store-and-forward, and still to go: queued, or waiting for the chat to carry it. (A
|
|
20941
20766
|
* file or a payment request that waits for the live session has no wire id, and its own sender.)
|
|
@@ -20987,6 +20812,8 @@ var Outbox = class {
|
|
|
20987
20812
|
dropped = false;
|
|
20988
20813
|
/** Sends asked for (`transmit`) whose turn is not over, each counted from the moment its row began to be stored. */
|
|
20989
20814
|
transmits = 0;
|
|
20815
|
+
/** Those sends' message ids, each with how many of them name it (a Retry may be asked for while it goes). */
|
|
20816
|
+
onTheirWay = /* @__PURE__ */ new Map();
|
|
20990
20817
|
/**
|
|
20991
20818
|
* Rows of mine being stored by someone else (`storing`), and a count moved at each one's start and end: the last
|
|
20992
20819
|
* look at the chat that found nothing of mine to go that this outbox did not know of was at `seen`.
|
|
@@ -21085,15 +20912,22 @@ var Outbox = class {
|
|
|
21085
20912
|
*/
|
|
21086
20913
|
transmit(id, { manual = false, storing } = {}) {
|
|
21087
20914
|
this.transmits++;
|
|
20915
|
+
this.onTheirWay.set(id, (this.onTheirWay.get(id) ?? 0) + 1);
|
|
20916
|
+
const over = () => {
|
|
20917
|
+
this.transmits--;
|
|
20918
|
+
const left = this.onTheirWay.get(id) - 1;
|
|
20919
|
+
if (left) this.onTheirWay.set(id, left);
|
|
20920
|
+
else this.onTheirWay.delete(id);
|
|
20921
|
+
};
|
|
21088
20922
|
const go = () => this.turn(async () => {
|
|
21089
20923
|
try {
|
|
21090
20924
|
await this.transmitTurn(id, manual);
|
|
21091
20925
|
} finally {
|
|
21092
|
-
|
|
20926
|
+
over();
|
|
21093
20927
|
}
|
|
21094
20928
|
});
|
|
21095
20929
|
return storing ? storing.then(go, (error) => {
|
|
21096
|
-
|
|
20930
|
+
over();
|
|
21097
20931
|
throw error;
|
|
21098
20932
|
}) : go();
|
|
21099
20933
|
}
|
|
@@ -21110,13 +20944,34 @@ var Outbox = class {
|
|
|
21110
20944
|
});
|
|
21111
20945
|
}
|
|
21112
20946
|
/**
|
|
21113
|
-
*
|
|
21114
|
-
*
|
|
21115
|
-
* this outbox did not know of.
|
|
21116
|
-
|
|
20947
|
+
* What was written before a new message and has not gone is what this outbox holds, queued, waiting, awaiting a
|
|
20948
|
+
* receipt or asked to go by another send on its way (`onTheirWay`): no row stored by someone else since the last look
|
|
20949
|
+
* at the chat that found nothing this outbox did not know of.
|
|
20950
|
+
*/
|
|
20951
|
+
get known() {
|
|
20952
|
+
return !this.writes && this.seen === this.stamp;
|
|
20953
|
+
}
|
|
20954
|
+
/**
|
|
20955
|
+
* Nothing written before a new message can still wait. Each text sent read and sorted the chat's whole history (220 ms
|
|
20956
|
+
* at 10,000 messages on the CLI's store) to find what this says.
|
|
21117
20957
|
*/
|
|
21118
20958
|
get alone() {
|
|
21119
|
-
return
|
|
20959
|
+
return this.known && this.transmits === 1 && !this.waiting.size && !this.receipts.size;
|
|
20960
|
+
}
|
|
20961
|
+
/**
|
|
20962
|
+
* The rows a new message's look needs, itself among them: those this outbox holds, by id, where it knows them all.
|
|
20963
|
+
* A text sent before the last one's receipt came, or while one waits for an away contact, read the chat's whole
|
|
20964
|
+
* history on the page's thread (20,000 rows per send at 20,000 messages), and so did each of the texts a bot asked
|
|
20965
|
+
* for at the same time. Past `KNOWN_ROWS`, the history costs less.
|
|
20966
|
+
*/
|
|
20967
|
+
async look(id) {
|
|
20968
|
+
if (!this.store.get || !this.known || this.waiting.size + this.receipts.size + this.onTheirWay.size > KNOWN_ROWS) return this.store.read();
|
|
20969
|
+
return (await Promise.all([.../* @__PURE__ */ new Set([
|
|
20970
|
+
id,
|
|
20971
|
+
...this.waiting.keys(),
|
|
20972
|
+
...this.receipts.keys(),
|
|
20973
|
+
...this.onTheirWay.keys()
|
|
20974
|
+
])].map((known) => this.store.get(known)))).filter((row) => !!row);
|
|
21120
20975
|
}
|
|
21121
20976
|
/** A row of mine still to go that this outbox holds nothing of: only a look at the chat finds it. */
|
|
21122
20977
|
unknown(m, id) {
|
|
@@ -21127,7 +20982,7 @@ var Outbox = class {
|
|
|
21127
20982
|
if (manual || this.stopped || this.busy.has(id) || this.receipts.has(id)) return this.transmitNow(id, { manual });
|
|
21128
20983
|
if (this.alone) return this.transmitNow(id);
|
|
21129
20984
|
const at = this.writes ? void 0 : this.stamp;
|
|
21130
|
-
const messages = await this.
|
|
20985
|
+
const messages = await this.look(id), message = messages.find((m) => m.id === id);
|
|
21131
20986
|
if (at !== void 0 && !messages.some((m) => this.unknown(m, id))) this.seen = at;
|
|
21132
20987
|
const before = message?.delivery === "sending" ? this.before(messages, message) : [];
|
|
21133
20988
|
if (!before.length) return this.transmitNow(id, {}, message);
|
|
@@ -22508,6 +22363,29 @@ var db = {
|
|
|
22508
22363
|
}
|
|
22509
22364
|
},
|
|
22510
22365
|
/**
|
|
22366
|
+
* The oldest `limit` messages of a chat after `after` (and before `before`, when given), oldest first, and whether
|
|
22367
|
+
* newer ones remain in that window. Reads those rows only: a bot that reads what came since its last message costs
|
|
22368
|
+
* a page, where reading the whole history and cutting it cost 94 ms of the daemon's time a call at 7,000 messages.
|
|
22369
|
+
*/
|
|
22370
|
+
async getMessagePageAfter(linkId, { limit, before, after }) {
|
|
22371
|
+
const upper = before?.timestamp ?? Infinity;
|
|
22372
|
+
if (after.timestamp > upper || after.timestamp === upper && (after.id === void 0 || before?.id === void 0)) return {
|
|
22373
|
+
messages: [],
|
|
22374
|
+
more: false
|
|
22375
|
+
};
|
|
22376
|
+
const range = IDBKeyRange.bound([linkId, after.timestamp], [linkId, upper], after.id === void 0, !!before && before.id === void 0);
|
|
22377
|
+
const kept = (m) => !(after.id !== void 0 && m.timestamp === after.timestamp && m.id <= after.id) && !(before?.id !== void 0 && m.timestamp === before.timestamp && m.id >= before.id);
|
|
22378
|
+
for (let want = limit + 1;;) {
|
|
22379
|
+
const oldest = await wrap((await store(STORES$1.messages, "readonly")).index("byLinkTime").getAll(range, want));
|
|
22380
|
+
const page = oldest.filter(kept);
|
|
22381
|
+
if (page.length > limit || oldest.length < want) return {
|
|
22382
|
+
messages: page.slice(0, limit),
|
|
22383
|
+
more: page.length > limit
|
|
22384
|
+
};
|
|
22385
|
+
want += oldest.length - page.length;
|
|
22386
|
+
}
|
|
22387
|
+
},
|
|
22388
|
+
/**
|
|
22511
22389
|
* Every message of this profile that carries a task, a routine or a usage card, from every chat and group, oldest first (time,
|
|
22512
22390
|
* then id). Reads the card index only (`CARD_INDEX`): no chat's history is read, however long. The index follows the
|
|
22513
22391
|
* rows, so an edit's card, a deleted message and a deleted chat or group are in step with no bookkeeping.
|
|
@@ -23505,6 +23383,8 @@ var COMMUNITY_TIMINGS = {
|
|
|
23505
23383
|
newcomerMs: 3e4
|
|
23506
23384
|
};
|
|
23507
23385
|
var KNOCK_BELL = 0;
|
|
23386
|
+
/** What `CommunitySession.join` says of a welcome whose entry is not the link's: the link was replaced since. */
|
|
23387
|
+
var LINK_REPLACED = "This link was replaced or turned off";
|
|
23508
23388
|
var knockRecord = (link, n) => ({
|
|
23509
23389
|
g: `${link.g}.${n}`,
|
|
23510
23390
|
host: link.host
|
|
@@ -23668,6 +23548,10 @@ var Communities = class {
|
|
|
23668
23548
|
async idle() {
|
|
23669
23549
|
await Promise.all([...this.deliveries.values()]);
|
|
23670
23550
|
}
|
|
23551
|
+
/** Writes what the sessions still have to save (each saves within a second what it receives): the app is stopping. */
|
|
23552
|
+
async flush() {
|
|
23553
|
+
await Promise.allSettled([...this.live.values()].map((live) => live.session.flush()));
|
|
23554
|
+
}
|
|
23671
23555
|
/** The clock: the last tick's time (the engine ticks every second), so every decision reads one clock. */
|
|
23672
23556
|
time = 0;
|
|
23673
23557
|
/**
|
|
@@ -23683,6 +23567,16 @@ var Communities = class {
|
|
|
23683
23567
|
now() {
|
|
23684
23568
|
return this.time || Date.now();
|
|
23685
23569
|
}
|
|
23570
|
+
/** `Date.now()` at the last tick. */
|
|
23571
|
+
tickedAt = 0;
|
|
23572
|
+
/**
|
|
23573
|
+
* When a message of mine is dated: the clock, moved on by the time passed since the last tick. Dated by the tick
|
|
23574
|
+
* alone, an answer sent within a second of a member's message (a tick runs late too) was older than its place: it
|
|
23575
|
+
* went above the message it answered in my own history, and above my own "You joined" (bug hunt, 2026-11-01).
|
|
23576
|
+
*/
|
|
23577
|
+
sendTime() {
|
|
23578
|
+
return this.time ? this.time + Math.max(0, Date.now() - this.tickedAt) : Date.now();
|
|
23579
|
+
}
|
|
23686
23580
|
/** Files and voice messages (WISP 503), the desk `Groups` keeps for every group. */
|
|
23687
23581
|
files;
|
|
23688
23582
|
has(groupId) {
|
|
@@ -23713,8 +23607,11 @@ var Communities = class {
|
|
|
23713
23607
|
async load(groups) {
|
|
23714
23608
|
for (const group of groups) {
|
|
23715
23609
|
this.stored.set(group.id, group);
|
|
23716
|
-
if (group.community) this.attach(group.community);
|
|
23717
23610
|
const history = await this.store.getMessages(MESSAGE_LINK$1(group.id));
|
|
23611
|
+
if (group.community) this.attach(group.community, history.flatMap((m) => m.frame ? [{
|
|
23612
|
+
id: m.id,
|
|
23613
|
+
frame: m.frame
|
|
23614
|
+
}] : []));
|
|
23718
23615
|
loadMarks(this.marks, group, history);
|
|
23719
23616
|
this.host.loaded?.(group.id, history);
|
|
23720
23617
|
for (const [, linkId] of this.host.entries(group.id)) if (group.joining?.linkId !== linkId) await this.host.closeEdge(linkId);
|
|
@@ -23821,6 +23718,7 @@ var Communities = class {
|
|
|
23821
23718
|
/** How far a join through the link got, as the joiner's app knows it. */
|
|
23822
23719
|
joinStage(group) {
|
|
23823
23720
|
const joining = group.joining;
|
|
23721
|
+
if (joining.replaced) return "replaced";
|
|
23824
23722
|
if (joining.inviter) return "admitted";
|
|
23825
23723
|
if (this.host.linkReady(joining.linkId, 2) || this.host.linkSeen?.(joining.linkId)) return "answered";
|
|
23826
23724
|
return this.knocked.has(group.id) ? "knocked" : "knocking";
|
|
@@ -23964,7 +23862,7 @@ var Communities = class {
|
|
|
23964
23862
|
const check = this.sendCheck(groupId);
|
|
23965
23863
|
if (check.error) return check;
|
|
23966
23864
|
const live = this.live.get(groupId);
|
|
23967
|
-
const now = this.
|
|
23865
|
+
const now = this.sendTime();
|
|
23968
23866
|
const result = card || file ? await live.session.sendText(text, this.host.myNick?.(), now, mentions, reply, forwarded, card, file) : await live.session.sendText(text, this.host.myNick?.(), now, mentions, reply, forwarded);
|
|
23969
23867
|
return "error" in result ? { error: result.error } : {
|
|
23970
23868
|
error: null,
|
|
@@ -24134,6 +24032,7 @@ var Communities = class {
|
|
|
24134
24032
|
/** Everything timed: beacon, hub election, lobbies, knocks, leaves, edges. The engine calls it every second or so. */
|
|
24135
24033
|
async tick(now = Date.now()) {
|
|
24136
24034
|
this.time = now;
|
|
24035
|
+
this.tickedAt = Date.now();
|
|
24137
24036
|
this.lineOrder.tick(now);
|
|
24138
24037
|
const active = [...this.live.values()].filter((l) => l.session.status === "active");
|
|
24139
24038
|
this.sharing = {
|
|
@@ -24142,7 +24041,7 @@ var Communities = class {
|
|
|
24142
24041
|
};
|
|
24143
24042
|
for (const group of [...this.stored.values()]) {
|
|
24144
24043
|
const live = this.live.get(group.id);
|
|
24145
|
-
if (group.joining && (this.knocking(group, live) || group.joining.check) && !this.gaveUp.has(group.id)) {
|
|
24044
|
+
if (group.joining && (this.knocking(group, live) || group.joining.check) && !this.gaveUp.has(group.id) && !group.joining.replaced) {
|
|
24146
24045
|
const knocking = this.knocking(group, live), waited = now - group.joining.since;
|
|
24147
24046
|
const answered = this.host.linkReady(group.joining.linkId, 2) || !!this.host.linkSeen?.(group.joining.linkId);
|
|
24148
24047
|
const since = this.knockingSince.get(group.id);
|
|
@@ -24198,6 +24097,10 @@ var Communities = class {
|
|
|
24198
24097
|
live.lingering.delete(linkId);
|
|
24199
24098
|
if ([...this.host.entries(groupId).values()].includes(linkId)) await this.host.closeEdge(linkId);
|
|
24200
24099
|
}
|
|
24100
|
+
if (live.doorKey && live.doorKey !== s.entryKey) {
|
|
24101
|
+
live.doorKey = void 0;
|
|
24102
|
+
await this.closeEntries(groupId);
|
|
24103
|
+
}
|
|
24201
24104
|
const alone = live.hub && !freshHubs(this.hubs(live), now).some((h) => h.key !== me);
|
|
24202
24105
|
if ((live.beaconFailedAt ? now - live.beaconFailedAt >= BEACON_RETRY_MS : now - live.lastBeaconRead >= this.beaconEvery(groupId, live, alone)) || live.lastBeaconRead === 0) await this.readBeacon(groupId, live, now);
|
|
24203
24106
|
if (!live.beaconKnown) {
|
|
@@ -24916,6 +24819,7 @@ var Communities = class {
|
|
|
24916
24819
|
if (live.members.size >= this.capacity(groupId, live, now)) break;
|
|
24917
24820
|
if (this.host.adminTurn && !await this.host.adminTurn(groupId, { wait: false })) break;
|
|
24918
24821
|
live.pendingEntries.set(key, now);
|
|
24822
|
+
live.doorKey = link.host;
|
|
24919
24823
|
traceJoin(groupId, "knock.seen", {
|
|
24920
24824
|
age: now - ts,
|
|
24921
24825
|
turn
|
|
@@ -25070,6 +24974,7 @@ var Communities = class {
|
|
|
25070
24974
|
const live = this.live.get(g);
|
|
25071
24975
|
const peer = [...this.host.entries(g)].find(([, id]) => id === linkId)?.[0];
|
|
25072
24976
|
if (!live || !peer || frame.key !== peer || !live.pendingEntries.has(peer)) return;
|
|
24977
|
+
if (live.doorKey !== live.session.entryKey) return;
|
|
25073
24978
|
let welcome;
|
|
25074
24979
|
try {
|
|
25075
24980
|
welcome = rosterHas(live.session.roster, peer) ? await live.session.rewelcome(peer) : await live.session.admit(peer, this.now());
|
|
@@ -25109,6 +25014,23 @@ var Communities = class {
|
|
|
25109
25014
|
g,
|
|
25110
25015
|
host: joining.host
|
|
25111
25016
|
}, joining.pieces, frame, joining.seedB64);
|
|
25017
|
+
if ("error" in joined && joined.error === LINK_REPLACED && !joining.check) {
|
|
25018
|
+
joining.replaced = true;
|
|
25019
|
+
joining.inviter = "";
|
|
25020
|
+
joining.pieces = [];
|
|
25021
|
+
if (this.knocked.has(g)) this.unknock({
|
|
25022
|
+
g,
|
|
25023
|
+
host: joining.host
|
|
25024
|
+
}, this.knockAt.get(g) ?? KNOCK_BELL, joining.seedB64).catch(() => {});
|
|
25025
|
+
this.knocked.delete(g);
|
|
25026
|
+
this.knockAt.delete(g);
|
|
25027
|
+
countWaitingJoin(this.host, g, this.now(), false);
|
|
25028
|
+
traceJoin(g, "join.replaced");
|
|
25029
|
+
await this.store.putGroup(group);
|
|
25030
|
+
await this.host.closeEdge(linkId);
|
|
25031
|
+
this.host.emit();
|
|
25032
|
+
return;
|
|
25033
|
+
}
|
|
25112
25034
|
if ("error" in joined) {
|
|
25113
25035
|
joining.pieces = [];
|
|
25114
25036
|
return;
|
|
@@ -25241,7 +25163,8 @@ var Communities = class {
|
|
|
25241
25163
|
edgeNick(groupId, peerKey, nick) {
|
|
25242
25164
|
this.live.get(groupId)?.session.setNick(peerKey, nick);
|
|
25243
25165
|
}
|
|
25244
|
-
|
|
25166
|
+
/** `rows`: what the group's rows hold to hand on (none yet for a group just made or joined). */
|
|
25167
|
+
attach(state, rows = []) {
|
|
25245
25168
|
const id = state.id;
|
|
25246
25169
|
const session = new CommunitySession(state, {
|
|
25247
25170
|
save: async (next) => {
|
|
@@ -25289,13 +25212,18 @@ var Communities = class {
|
|
|
25289
25212
|
...m.reply && { replyTo: groupReply(m.reply, session.myKey) },
|
|
25290
25213
|
...m.forwarded && { forwarded: m.forwarded },
|
|
25291
25214
|
...m.card && { card: m.card },
|
|
25292
|
-
...file && { file }
|
|
25215
|
+
...file && { file },
|
|
25216
|
+
...m.frame && { frame: m.frame }
|
|
25293
25217
|
});
|
|
25294
25218
|
placing(stored !== false);
|
|
25295
|
-
if (stored === false && this.stored.get(id)?.removedIds?.includes(m.id)) return;
|
|
25219
|
+
if (stored === false && this.stored.get(id)?.removedIds?.includes(m.id)) return false;
|
|
25296
25220
|
const came = m.sender === session.myKey ? timestamp : cameAt(timestamp, stored, arrivalNow(this.now()));
|
|
25297
25221
|
markCame(this.marks, id, m.id, came, m.sender !== session.myKey, mentioned);
|
|
25298
25222
|
noteCame(this.stored.get(id), came, m.sender !== session.myKey, mentioned);
|
|
25223
|
+
return stored !== false;
|
|
25224
|
+
},
|
|
25225
|
+
forgetFrame: (rowId) => {
|
|
25226
|
+
this.host.forgetFrame?.(MESSAGE_LINK$1(id), rowId).catch(() => {});
|
|
25299
25227
|
},
|
|
25300
25228
|
app: (m) => this.deliver(id, () => m.frame.t === "group-have" ? this.files?.communityApp(id, m.sender, m.frame) : this.host.communityApp?.(id, m.sender, m.frame)),
|
|
25301
25229
|
lasting: (m) => m.frame.t === "pin" && m.sender === session.admin ? "pin" : void 0,
|
|
@@ -25323,7 +25251,7 @@ var Communities = class {
|
|
|
25323
25251
|
const edge = this.host.edges(id).get(to);
|
|
25324
25252
|
return edge && this.host.linkHandled ? this.host.linkHandled(edge) : Promise.resolve(false);
|
|
25325
25253
|
} }
|
|
25326
|
-
});
|
|
25254
|
+
}, rows);
|
|
25327
25255
|
this.live.set(id, {
|
|
25328
25256
|
session,
|
|
25329
25257
|
hub: false,
|
|
@@ -26918,11 +26846,15 @@ var Groups = class {
|
|
|
26918
26846
|
}
|
|
26919
26847
|
}
|
|
26920
26848
|
/**
|
|
26921
|
-
* Writes what the private groups' sessions still have to save (`GROUP_LIMITS.saveWithinMs
|
|
26922
|
-
* since the last save (`saveSoon`): the app is stopping.
|
|
26849
|
+
* Writes what the private groups' sessions and the communities' still have to save (`GROUP_LIMITS.saveWithinMs`, a
|
|
26850
|
+
* second), and the removals taken since the last save (`saveSoon`): the app is stopping.
|
|
26923
26851
|
*/
|
|
26924
26852
|
async flush() {
|
|
26925
|
-
await Promise.allSettled([
|
|
26853
|
+
await Promise.allSettled([
|
|
26854
|
+
...[...this.sessions.values()].map((session) => session.flush()),
|
|
26855
|
+
this.communities.flush(),
|
|
26856
|
+
this.saveUnsaved()
|
|
26857
|
+
]);
|
|
26926
26858
|
}
|
|
26927
26859
|
/**
|
|
26928
26860
|
* A group's record written within `GROUP_LIMITS.saveWithinMs`, for what may change many times a second (a catch-up
|
|
@@ -28466,7 +28398,7 @@ var Groups = class {
|
|
|
28466
28398
|
if (!viaLink) await this.sessions.get(g).setNick(group.invitation.admin, this.host.contactName(linkId));
|
|
28467
28399
|
const session = this.sessions.get(g);
|
|
28468
28400
|
for (const [key, nick] of Object.entries(group.formerNames ?? {})) if (!session.state.nicks[key]) await session.setNick(key, nick);
|
|
28469
|
-
await this.event(g, "joined", `You joined. ${GROUP_READ_NOTE}`, Date.now(), joined.state.chain.length - 1);
|
|
28401
|
+
await this.event(g, "joined", group.invitation.genesis ? "You joined again" : `You joined. ${GROUP_READ_NOTE}`, Date.now(), joined.state.chain.length - 1);
|
|
28470
28402
|
if (viaLink) traceJoin(g, "welcome.received");
|
|
28471
28403
|
if (viaLink) {
|
|
28472
28404
|
this.lastKnock.delete(g);
|
|
@@ -29290,13 +29222,17 @@ var Groups = class {
|
|
|
29290
29222
|
for (const [key] of after) if (!rosterHas(before, key) && key !== session.myKey) await this.event(groupId, "joined", `${name(key)} joined`, when, top.e, key);
|
|
29291
29223
|
const gone = before.filter(([key]) => !rosterHas(after, key)).map(([key]) => key);
|
|
29292
29224
|
this.hubs.removed(groupId, gone, this.now());
|
|
29293
|
-
const
|
|
29294
|
-
|
|
29295
|
-
for (let e = chain.length - 1; e > 0; e--) if (chain[e].k === "remove" && chain[e].s === key) return
|
|
29296
|
-
return
|
|
29225
|
+
const chain = session.state.chain;
|
|
29226
|
+
const removal = (key) => {
|
|
29227
|
+
for (let e = chain.length - 1; e > 0; e--) if (chain[e].k === "remove" && chain[e].s === key) return e;
|
|
29228
|
+
return -1;
|
|
29297
29229
|
};
|
|
29298
|
-
for (const key of gone)
|
|
29299
|
-
|
|
29230
|
+
for (const key of gone) {
|
|
29231
|
+
const e = removal(key), by = e > 0 && chain[e].by !== key ? chain[e].by : void 0;
|
|
29232
|
+
if (e > 0 && session.state.leftMarks?.[e]) await this.event(groupId, "left", `${name(key)} left`, when, top.e, key);
|
|
29233
|
+
else if (by) await this.event(groupId, "gone", `${name(by)} removed ${name(key)}`, when, top.e, key, by);
|
|
29234
|
+
else await this.event(groupId, "gone", `${name(key)} is no longer a member`, when, top.e, key);
|
|
29235
|
+
}
|
|
29300
29236
|
if (top.k === "role") await this.event(groupId, "admin", `${name(top.s)} ${top.s === session.myKey ? "are" : "is"} now the admin`, when, top.e, top.s);
|
|
29301
29237
|
if (top.k === "rotate") await this.event(groupId, "rotated", "Keys rotated: a fresh epoch", when, top.e);
|
|
29302
29238
|
}
|
|
@@ -29349,7 +29285,7 @@ var Groups = class {
|
|
|
29349
29285
|
}
|
|
29350
29286
|
/** `member`: whom it is about, so the apps can name them as they are known now, not as they were then. */
|
|
29351
29287
|
/** A line in the group's history; lines at the same time (two members gone in one change) get distinct ones, see `eventTime`. */
|
|
29352
|
-
async event(groupId, event, text, timestamp, epoch, member) {
|
|
29288
|
+
async event(groupId, event, text, timestamp, epoch, member, by) {
|
|
29353
29289
|
timestamp = eventTime(this.eventTimes, groupId, timestamp);
|
|
29354
29290
|
const id = `event:${epoch}:${event}:${timestamp}`;
|
|
29355
29291
|
this.lineOrder.placing(MESSAGE_LINK(groupId), {
|
|
@@ -29363,6 +29299,7 @@ var Groups = class {
|
|
|
29363
29299
|
sender: "peer",
|
|
29364
29300
|
event,
|
|
29365
29301
|
member,
|
|
29302
|
+
...by && { by },
|
|
29366
29303
|
timestamp,
|
|
29367
29304
|
via: "datalink"
|
|
29368
29305
|
}) !== false);
|
|
@@ -29964,13 +29901,14 @@ var GroupEdits = class {
|
|
|
29964
29901
|
}
|
|
29965
29902
|
/**
|
|
29966
29903
|
* An edit from a member, authenticated as `sender` by the group. Believed only while the sender is in the group (a
|
|
29967
|
-
* removed member's edits are dropped) and only of the sender's own message; the highest number wins.
|
|
29904
|
+
* removed member's edits are dropped) and only of the sender's own message; the highest number wins. In a private
|
|
29905
|
+
* group a removal stands once its author is out too (`outlives`): the group took it under the epoch rules. One of a message
|
|
29968
29906
|
* not here yet waits a minute for it. Past `EDIT_RECEIVE_LIMIT` a window from one member, the rest wait for the next
|
|
29969
29907
|
* window (`hold`): a catch-up hands back every edit of an author at once, and one dropped is never handed again.
|
|
29970
29908
|
*/
|
|
29971
29909
|
async receive(groupId, sender, edit) {
|
|
29972
29910
|
const membership = this.host.membership(groupId);
|
|
29973
|
-
if (!membership
|
|
29911
|
+
if (!membership || !(membership.members.has(sender) || outlives(membership, edit)) || sender === membership.me || !edit.id.startsWith(`${sender}:`)) return "dropped";
|
|
29974
29912
|
const key = `${groupId}\n${sender}`;
|
|
29975
29913
|
let pace = this.receivePace.get(key);
|
|
29976
29914
|
if (!pace) this.receivePace.set(key, pace = new RateWindow(30, EDIT_RATE_WINDOW_MS, this.now));
|
|
@@ -30014,10 +29952,14 @@ var GroupEdits = class {
|
|
|
30014
29952
|
if (this.stopped || !group || !waiting || !pace) return;
|
|
30015
29953
|
for (const [id, edit] of [...waiting]) {
|
|
30016
29954
|
const membership = this.host.membership(groupId);
|
|
30017
|
-
if (!membership
|
|
29955
|
+
if (!membership) {
|
|
30018
29956
|
waiting.clear();
|
|
30019
29957
|
break;
|
|
30020
29958
|
}
|
|
29959
|
+
if (!membership.members.has(sender) && !outlives(membership, edit)) {
|
|
29960
|
+
waiting.delete(id);
|
|
29961
|
+
continue;
|
|
29962
|
+
}
|
|
30021
29963
|
if (!pace.take()) break;
|
|
30022
29964
|
if (waiting.get(id) !== edit) continue;
|
|
30023
29965
|
waiting.delete(id);
|
|
@@ -30191,6 +30133,14 @@ var GroupEdits = class {
|
|
|
30191
30133
|
else this.held.delete(groupId);
|
|
30192
30134
|
}
|
|
30193
30135
|
};
|
|
30136
|
+
/**
|
|
30137
|
+
* A private group's removal (WISP 902 § Edits): it stands once its author left or was removed, since it only takes
|
|
30138
|
+
* away what the author wrote while in. The group's session checked it (signed by the author, for an epoch the author
|
|
30139
|
+
* and I were both in, handed on by a member). A community's member out of it edits nothing at all.
|
|
30140
|
+
*/
|
|
30141
|
+
function outlives(membership, edit) {
|
|
30142
|
+
return edit.rm === true && !membership.community;
|
|
30143
|
+
}
|
|
30194
30144
|
//#endregion
|
|
30195
30145
|
//#region ../browser/src/shared/payLinks.ts
|
|
30196
30146
|
/**
|
|
@@ -32510,6 +32460,26 @@ var S3Store = class {
|
|
|
32510
32460
|
}
|
|
32511
32461
|
};
|
|
32512
32462
|
//#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
|
|
32513
32483
|
//#region ../browser/src/engine/wallet.ts
|
|
32514
32484
|
/**
|
|
32515
32485
|
* The peer's Cashu wallet. Ecash is custodial: the mint holds the sats and the
|
|
@@ -32567,6 +32537,8 @@ var SwapUnsettledError = class extends Error {
|
|
|
32567
32537
|
};
|
|
32568
32538
|
/** When a swap with no answer can no longer reach the mint: a request's longest life, and a margin after its last try. */
|
|
32569
32539
|
var swapOverdueAt = (swap) => Math.max(swap.createdAt + CASHU_REQUEST_TIMEOUT_MS + SWAP_SETTLED_MS, (swap.attemptEndedAt ?? Number.POSITIVE_INFINITY) + SWAP_SETTLED_MS);
|
|
32540
|
+
/** When a melt with no answer can no longer reach the mint: its one request is sent right after it is written down. */
|
|
32541
|
+
var meltOverdueAt = (melt) => melt.createdAt + CASHU_REQUEST_TIMEOUT_MS + SWAP_SETTLED_MS;
|
|
32570
32542
|
var swapOf = (swap) => swap.swap;
|
|
32571
32543
|
function normalizeMintUrl(input) {
|
|
32572
32544
|
let url;
|
|
@@ -32930,7 +32902,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32930
32902
|
const quote = await wrap((await store(STORES$1.quotes, "readonly")).get(id));
|
|
32931
32903
|
if (!quote || quote.issuedUnclaimed || quote.held) return null;
|
|
32932
32904
|
const wallet = await this.wallet(quote.mint);
|
|
32933
|
-
const { OutputData
|
|
32905
|
+
const { OutputData } = await loadCashu();
|
|
32934
32906
|
const answer = await wallet.checkMintQuoteBolt11(quote.quote);
|
|
32935
32907
|
const { state } = answer;
|
|
32936
32908
|
if (state === "UNPAID") {
|
|
@@ -32963,7 +32935,7 @@ var CashuWallet = class CashuWallet {
|
|
|
32963
32935
|
try {
|
|
32964
32936
|
proofs = await wallet.completeMint(preview);
|
|
32965
32937
|
} catch (error) {
|
|
32966
|
-
if (
|
|
32938
|
+
if (mintRefused(error) && (await wallet.checkMintQuoteBolt11(quote.quote).catch(() => null))?.state === "PAID") {
|
|
32967
32939
|
const { outputs: _refused, ...fresh } = written;
|
|
32968
32940
|
await committed((await store(STORES$1.quotes, "readwrite")).put(fresh));
|
|
32969
32941
|
}
|
|
@@ -33452,11 +33424,11 @@ var CashuWallet = class CashuWallet {
|
|
|
33452
33424
|
* `pollSwaps` settles it. Runs under the mint's lock.
|
|
33453
33425
|
*/
|
|
33454
33426
|
async completeSwap(swap) {
|
|
33455
|
-
const { deserializeSwapPreview
|
|
33427
|
+
const { deserializeSwapPreview } = await loadCashu();
|
|
33456
33428
|
try {
|
|
33457
33429
|
return await (await this.wallet(swap.mint)).completeSwap(deserializeSwapPreview(swapOf(swap)));
|
|
33458
33430
|
} catch (error) {
|
|
33459
|
-
const refused =
|
|
33431
|
+
const refused = mintRefused(error) && swap.attemptEndedAt === void 0;
|
|
33460
33432
|
const ended = {
|
|
33461
33433
|
...swap,
|
|
33462
33434
|
attemptEndedAt: Date.now()
|
|
@@ -33708,7 +33680,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33708
33680
|
if (stuck === 1) this.events.onChange();
|
|
33709
33681
|
later(wait);
|
|
33710
33682
|
} else if (outcome.idle && swap.kind === "receive" && !swap.released) {
|
|
33711
|
-
const { deserializeSwapPreview
|
|
33683
|
+
const { deserializeSwapPreview } = await loadCashu();
|
|
33712
33684
|
try {
|
|
33713
33685
|
const { keep } = await (await this.wallet(mint)).completeSwap(deserializeSwapPreview(swapOf(swap)));
|
|
33714
33686
|
if (await this.finishSwap(swap, keep, [], true)) {
|
|
@@ -33723,7 +33695,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33723
33695
|
attemptEndedAt: Date.now()
|
|
33724
33696
|
};
|
|
33725
33697
|
await committed((await store(STORES$1.swaps, "readwrite")).put(swap));
|
|
33726
|
-
const refusal =
|
|
33698
|
+
const refusal = mintRefused(error) ? await this.swapOutcome(swap, true).catch(() => void 0) : void 0;
|
|
33727
33699
|
if (refusal?.state === "done") {
|
|
33728
33700
|
if (await this.finishSwap(swap, refusal.keep, refusal.send, true)) {
|
|
33729
33701
|
const told = await this.tellSwap(swap, true);
|
|
@@ -33834,7 +33806,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33834
33806
|
}
|
|
33835
33807
|
async melt(quoteId, mint, note, paymentId) {
|
|
33836
33808
|
const wallet = await this.wallet(mint);
|
|
33837
|
-
const { MeltChangeError, OutputData
|
|
33809
|
+
const { MeltChangeError, OutputData } = await loadCashu();
|
|
33838
33810
|
const quote = await wallet.checkMeltQuoteBolt11(quoteId);
|
|
33839
33811
|
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");
|
|
33840
33812
|
const shown = this.shownQuotes.get(quoteId);
|
|
@@ -33878,8 +33850,8 @@ var CashuWallet = class CashuWallet {
|
|
|
33878
33850
|
try {
|
|
33879
33851
|
result = await wallet.completeMelt(preview);
|
|
33880
33852
|
} catch (error) {
|
|
33881
|
-
if (!
|
|
33882
|
-
const outcome = await this.settleMelt(melt).catch(() => "pending");
|
|
33853
|
+
if (!mintRefused(error) && !(error instanceof MeltChangeError)) return "pending";
|
|
33854
|
+
const outcome = await this.settleMelt(melt, true).catch(() => "pending");
|
|
33883
33855
|
if (outcome === "unpaid") {
|
|
33884
33856
|
const lost = this.takeFailedFee(melt.quote);
|
|
33885
33857
|
if (this.spentAway.delete(melt.quote)) throw Object.assign(engineError("ecashAlreadySpent"), { cause: error });
|
|
@@ -33892,7 +33864,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33892
33864
|
await this.finishMelt(melt, result.change);
|
|
33893
33865
|
return "paid";
|
|
33894
33866
|
}
|
|
33895
|
-
return this.settleMelt(melt).catch(() => "pending");
|
|
33867
|
+
return this.settleMelt(melt, true).catch(() => "pending");
|
|
33896
33868
|
}
|
|
33897
33869
|
/**
|
|
33898
33870
|
* Whether a Lightning payment of this invoice is written down as in flight. A melt is written before the mint sees
|
|
@@ -33924,9 +33896,10 @@ var CashuWallet = class CashuWallet {
|
|
|
33924
33896
|
/**
|
|
33925
33897
|
* Asks the mint where a recorded melt stands and books the answer. Paid: the reserved proofs are gone and
|
|
33926
33898
|
* the change is ours. Unpaid: what the mint says is unspent is spendable again. Pending: nothing moves.
|
|
33927
|
-
* Throws when the mint cannot be asked, and the melt stays as it is.
|
|
33899
|
+
* Throws when the mint cannot be asked, and the melt stays as it is. `answered`: the mint answered the melt request
|
|
33900
|
+
* itself, so it has acted on it; without that, an unpaid quote may only mean the request has not landed yet.
|
|
33928
33901
|
*/
|
|
33929
|
-
async settleMelt(melt) {
|
|
33902
|
+
async settleMelt(melt, answered = false) {
|
|
33930
33903
|
const wallet = await this.wallet(melt.mint);
|
|
33931
33904
|
const { Amount, OutputData } = await loadCashu();
|
|
33932
33905
|
const quote = await wallet.checkMeltQuoteBolt11(melt.quote);
|
|
@@ -33945,6 +33918,7 @@ var CashuWallet = class CashuWallet {
|
|
|
33945
33918
|
return "paid";
|
|
33946
33919
|
}
|
|
33947
33920
|
if (quote.state === "PENDING") return "pending";
|
|
33921
|
+
if (!answered && Date.now() < meltOverdueAt(melt)) return "pending";
|
|
33948
33922
|
const inputs = await this.reservedProofs(melt);
|
|
33949
33923
|
const states = inputs.length > 0 ? await wallet.checkProofsStates(inputs) : [];
|
|
33950
33924
|
if (states.some((s) => s.state === "PENDING")) return "pending";
|
|
@@ -33999,20 +33973,26 @@ var CashuWallet = class CashuWallet {
|
|
|
33999
33973
|
*/
|
|
34000
33974
|
async forget(mints, acceptLoss = false) {
|
|
34001
33975
|
const at = new Set(mints);
|
|
34002
|
-
|
|
33976
|
+
const inFlight = async () => {
|
|
33977
|
+
if ((await wrap((await store(STORES$1.melts, "readonly")).getAll())).some((m) => at.has(m.mint))) throw new Error("A Lightning payment from this wallet is still in flight: wait for it to settle, then remove the wallet.");
|
|
33978
|
+
};
|
|
33979
|
+
await inFlight();
|
|
34003
33980
|
await this.pollSwaps(mints).catch(() => {});
|
|
34004
|
-
|
|
34005
|
-
|
|
34006
|
-
|
|
34007
|
-
|
|
34008
|
-
|
|
34009
|
-
STORES$1.
|
|
34010
|
-
|
|
34011
|
-
|
|
34012
|
-
|
|
34013
|
-
|
|
34014
|
-
|
|
34015
|
-
|
|
33981
|
+
await this.lockedAll(mints, async () => {
|
|
33982
|
+
await inFlight();
|
|
33983
|
+
if ((await wrap((await store(STORES$1.swaps, "readonly")).getAll())).filter((s) => at.has(s.mint) && !s.released).length > 0 && !acceptLoss) throw new Error("An exchange of ecash with this wallet's mint is not finished yet: wait for the mint to answer, or confirm that what it would bring is lost to remove the wallet.");
|
|
33984
|
+
const proofs = (await this.allProofs()).filter((p) => at.has(p.mint));
|
|
33985
|
+
const quotes = (await wrap((await store(STORES$1.quotes, "readonly")).getAll())).filter((q) => at.has(q.mint));
|
|
33986
|
+
const swaps = (await wrap((await store(STORES$1.swaps, "readonly")).getAll())).filter((s) => at.has(s.mint));
|
|
33987
|
+
await transact([
|
|
33988
|
+
STORES$1.proofs,
|
|
33989
|
+
STORES$1.quotes,
|
|
33990
|
+
STORES$1.swaps
|
|
33991
|
+
], (stores) => {
|
|
33992
|
+
for (const p of proofs) stores[STORES$1.proofs].delete(p.secret);
|
|
33993
|
+
for (const q of quotes) stores[STORES$1.quotes].delete(q.quote);
|
|
33994
|
+
for (const s of swaps) stores[STORES$1.swaps].delete(s.id);
|
|
33995
|
+
});
|
|
34016
33996
|
});
|
|
34017
33997
|
for (const mint of mints) {
|
|
34018
33998
|
this.wallets.delete(mint);
|
|
@@ -34074,6 +34054,10 @@ var CashuWallet = class CashuWallet {
|
|
|
34074
34054
|
this.locks.set(mint, next.catch(() => {}));
|
|
34075
34055
|
return next;
|
|
34076
34056
|
}
|
|
34057
|
+
/** `task` under the locks of every one of `mints`, taken in one order (no other task holds two, so none waits on this one). */
|
|
34058
|
+
lockedAll(mints, task) {
|
|
34059
|
+
return [...new Set(mints)].sort().reduceRight((inner, mint) => () => this.locked(mint, inner), task)();
|
|
34060
|
+
}
|
|
34077
34061
|
async allProofs() {
|
|
34078
34062
|
return wrap((await store(STORES$1.proofs, "readonly")).getAll());
|
|
34079
34063
|
}
|
|
@@ -34123,8 +34107,18 @@ function parseSats(value, asset) {
|
|
|
34123
34107
|
if (asset !== UNIT || !/^[1-9]\d{0,8}$/.test(value)) return null;
|
|
34124
34108
|
return Number(value);
|
|
34125
34109
|
}
|
|
34126
|
-
/**
|
|
34127
|
-
|
|
34110
|
+
/**
|
|
34111
|
+
* Paying in ecash failed before any token existed, so nothing reached the contact and Lightning is safe to try. The
|
|
34112
|
+
* wallet's `engineCode` and `values` stay on it: a host reads why by them (the CLI's `refused`, the app's words).
|
|
34113
|
+
*/
|
|
34114
|
+
var NoEcashError = class extends Error {
|
|
34115
|
+
constructor(cause) {
|
|
34116
|
+
super(cause instanceof Error ? cause.message : String(cause));
|
|
34117
|
+
const { engineCode, values } = cause ?? {};
|
|
34118
|
+
if (engineCode !== void 0) Object.assign(this, { engineCode });
|
|
34119
|
+
if (values !== void 0) Object.assign(this, { values });
|
|
34120
|
+
}
|
|
34121
|
+
};
|
|
34128
34122
|
var arkSats = (network) => network === "bitcoin" ? "sats" : "test sats";
|
|
34129
34123
|
/** The English line kept with a payment message (the CLI and older apps show it): test sats say so. */
|
|
34130
34124
|
var satsOn = (network) => network === "testnet" ? "test sats" : "sats";
|
|
@@ -35345,11 +35339,17 @@ var PaymentDesk = class {
|
|
|
35345
35339
|
});
|
|
35346
35340
|
const sats = parseSats(payment.amount.value, payment.amount.asset);
|
|
35347
35341
|
const spent = error instanceof EngineError && error.engineCode === "ecashAlreadySpent";
|
|
35342
|
+
const network = inspected?.kind === "token" ? mintNetwork(inspected.mint) : void 0;
|
|
35343
|
+
const line = refusedRow({
|
|
35344
|
+
amount: sats ?? void 0,
|
|
35345
|
+
network,
|
|
35346
|
+
reason
|
|
35347
|
+
});
|
|
35348
35348
|
try {
|
|
35349
35349
|
await this.host.storeMessage({
|
|
35350
35350
|
linkId,
|
|
35351
35351
|
id: spent ? `peer_spent_${digestHex(token).slice(0, 32)}` : `peer_${payment.timestamp}_refused`,
|
|
35352
|
-
|
|
35352
|
+
...line,
|
|
35353
35353
|
sender: "peer",
|
|
35354
35354
|
timestamp: payment.timestamp,
|
|
35355
35355
|
via: "datalink"
|
|
@@ -35416,11 +35416,16 @@ var PaymentDesk = class {
|
|
|
35416
35416
|
ok: false,
|
|
35417
35417
|
error: reason
|
|
35418
35418
|
});
|
|
35419
|
+
const line = refusedRow({
|
|
35420
|
+
amount: record.amount,
|
|
35421
|
+
network: record.mint ? mintNetwork(record.mint) : void 0,
|
|
35422
|
+
reason
|
|
35423
|
+
});
|
|
35419
35424
|
try {
|
|
35420
35425
|
await this.host.storeMessage({
|
|
35421
35426
|
linkId: record.linkId,
|
|
35422
35427
|
id: `peer_${record.createdAt}_refused`,
|
|
35423
|
-
|
|
35428
|
+
...line,
|
|
35424
35429
|
sender: "peer",
|
|
35425
35430
|
timestamp: record.createdAt,
|
|
35426
35431
|
via: "datalink"
|
|
@@ -36356,17 +36361,23 @@ var PaymentDesk = class {
|
|
|
36356
36361
|
});
|
|
36357
36362
|
return;
|
|
36358
36363
|
}
|
|
36359
|
-
const refuse = async (reason) => {
|
|
36364
|
+
const refuse = async (reason, network) => {
|
|
36360
36365
|
link?.sendPaymentResult({
|
|
36361
36366
|
id: payment.id,
|
|
36362
36367
|
ok: false,
|
|
36363
36368
|
error: reason
|
|
36364
36369
|
});
|
|
36370
|
+
const line = refusedRow({
|
|
36371
|
+
amount: parseSats(payment.amount.value, payment.amount.asset) ?? void 0,
|
|
36372
|
+
network,
|
|
36373
|
+
method: "fedimint",
|
|
36374
|
+
reason
|
|
36375
|
+
});
|
|
36365
36376
|
try {
|
|
36366
36377
|
await this.host.storeMessage({
|
|
36367
36378
|
linkId,
|
|
36368
36379
|
id: `peer_${payment.timestamp}_refused`,
|
|
36369
|
-
|
|
36380
|
+
...line,
|
|
36370
36381
|
sender: "peer",
|
|
36371
36382
|
timestamp: payment.timestamp,
|
|
36372
36383
|
via: "datalink"
|
|
@@ -36402,7 +36413,7 @@ var PaymentDesk = class {
|
|
|
36402
36413
|
}
|
|
36403
36414
|
const network = this.fedimintOf(found.federation)?.federation(found.federation)?.network;
|
|
36404
36415
|
if (network && !this.accepts(linkId, "fedimint", walletNetworkOf(network))) {
|
|
36405
|
-
await refuse(`${networkLabel(walletNetworkOf(network))} Fedimint is off in this chat
|
|
36416
|
+
await refuse(`${networkLabel(walletNetworkOf(network))} Fedimint is off in this chat`, walletNetworkOf(network));
|
|
36406
36417
|
return;
|
|
36407
36418
|
}
|
|
36408
36419
|
const digest = fedimintNotesDigest(notes);
|
|
@@ -36479,11 +36490,17 @@ var PaymentDesk = class {
|
|
|
36479
36490
|
ok: false,
|
|
36480
36491
|
error: "These notes were already redeemed"
|
|
36481
36492
|
});
|
|
36493
|
+
const line = refusedRow({
|
|
36494
|
+
amount: payment.amount,
|
|
36495
|
+
network: payment.network,
|
|
36496
|
+
method: "fedimint",
|
|
36497
|
+
reason: "These notes were already redeemed"
|
|
36498
|
+
});
|
|
36482
36499
|
try {
|
|
36483
36500
|
await this.host.storeMessage({
|
|
36484
36501
|
linkId: payment.linkId,
|
|
36485
36502
|
id: `peer_${payment.createdAt}_refused`,
|
|
36486
|
-
|
|
36503
|
+
...line,
|
|
36487
36504
|
sender: "peer",
|
|
36488
36505
|
timestamp: payment.createdAt,
|
|
36489
36506
|
via: "datalink"
|
|
@@ -36677,7 +36694,7 @@ var PaymentDesk = class {
|
|
|
36677
36694
|
paidFrom = created.mint;
|
|
36678
36695
|
this.payments.set(id, record(created.token, created.mint));
|
|
36679
36696
|
} catch (error) {
|
|
36680
|
-
throw new NoEcashError(error
|
|
36697
|
+
throw new NoEcashError(error);
|
|
36681
36698
|
}
|
|
36682
36699
|
this.host.onChange();
|
|
36683
36700
|
await this.host.storeMessage({
|
|
@@ -37248,7 +37265,11 @@ var WalletSetup = class {
|
|
|
37248
37265
|
};
|
|
37249
37266
|
//#endregion
|
|
37250
37267
|
//#region ../browser/src/engine/node.ts
|
|
37251
|
-
/**
|
|
37268
|
+
/**
|
|
37269
|
+
* How long a chat waits, on average, before listening again after its HyperDHT relay went away. Each app draws its own
|
|
37270
|
+
* wait within half of it either side: a relay that restarts closes every app's socket at once, and with one fixed wait
|
|
37271
|
+
* they all came back in the same instant, more listens than its one HyperDHT node sends out in time.
|
|
37272
|
+
*/
|
|
37252
37273
|
var RELAY_RETRY_MS = 3e4;
|
|
37253
37274
|
/** Native listeners an app may hold per transport (the Desktop's Rust Iroh allows eight, `paired_transport.rs`). */
|
|
37254
37275
|
var NATIVE_SLOTS = 8;
|
|
@@ -37293,6 +37314,8 @@ var DEFAULT_SETTINGS = {
|
|
|
37293
37314
|
mints: [],
|
|
37294
37315
|
mintsInitialized: false
|
|
37295
37316
|
};
|
|
37317
|
+
/** A link's `removedRefs` with `ref`, the newest `MAX_DELETED_IDS`. */
|
|
37318
|
+
var withRemovedRef = (refs, ref) => [...(refs ?? []).filter((r) => r !== ref), ref].slice(-500);
|
|
37296
37319
|
/**
|
|
37297
37320
|
* A card that went on the DHT floor or into a hold goes again live (`restoreCards`) only for the newest this many
|
|
37298
37321
|
* messages of a chat, sent within this long: an old chat's cards are not worth a burst of edits.
|
|
@@ -37456,6 +37479,7 @@ var LIMITED_MODE_METHODS = /* @__PURE__ */ new Set([
|
|
|
37456
37479
|
"forwardMessages",
|
|
37457
37480
|
"messageDetails",
|
|
37458
37481
|
"messagePage",
|
|
37482
|
+
"chatsFound",
|
|
37459
37483
|
"sendGroupMessage",
|
|
37460
37484
|
"groupMessages",
|
|
37461
37485
|
"statusCardIndex",
|
|
@@ -37589,6 +37613,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
37589
37613
|
const key = type + ":" + id;
|
|
37590
37614
|
if (this.feedbackIds.has(key)) return;
|
|
37591
37615
|
this.feedbackIds.add(key);
|
|
37616
|
+
if (this.feedbackIds.size > 4096) this.feedbackIds.delete(this.feedbackIds.values().next().value);
|
|
37592
37617
|
this.events.onAttention?.({
|
|
37593
37618
|
type,
|
|
37594
37619
|
id: key,
|
|
@@ -39255,7 +39280,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39255
39280
|
if (start.gated) {
|
|
39256
39281
|
await this.stopReplaced({
|
|
39257
39282
|
...start.gated,
|
|
39258
|
-
reload: true
|
|
39283
|
+
reload: true,
|
|
39284
|
+
keepUnlocked: true
|
|
39259
39285
|
});
|
|
39260
39286
|
return;
|
|
39261
39287
|
}
|
|
@@ -39825,6 +39851,19 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39825
39851
|
async getMessages(linkId) {
|
|
39826
39852
|
return (await db.getMessages(linkId)).map(withoutFrame);
|
|
39827
39853
|
}
|
|
39854
|
+
/**
|
|
39855
|
+
* The 1:1 chats among `linkIds` with a message whose text holds `query`, whatever the case and the accents: the chat
|
|
39856
|
+
* list's search, read here so a page that holds each chat's newest page only is not sent every whole history for it.
|
|
39857
|
+
*/
|
|
39858
|
+
async chatsFound(params) {
|
|
39859
|
+
if (typeof params?.query !== "string") throw new Error("query: the text to search for");
|
|
39860
|
+
if (!Array.isArray(params.linkIds)) throw new Error("linkIds: the ids of the chats to search");
|
|
39861
|
+
const chats = params.linkIds.filter((linkId) => {
|
|
39862
|
+
const link = this.links.get(linkId);
|
|
39863
|
+
return !!link && !link.stored.group;
|
|
39864
|
+
});
|
|
39865
|
+
return this.chatSearch.found(chats, params.query);
|
|
39866
|
+
}
|
|
39828
39867
|
/** The ids of the messages deleted in a chat (`deletedIds`, the newest `MAX_DELETED_IDS`): a whole history goes with them. */
|
|
39829
39868
|
deletedIdsOf(linkId) {
|
|
39830
39869
|
return this.links.get(linkId)?.stored.deletedIds ?? [];
|
|
@@ -39834,6 +39873,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39834
39873
|
const message = await db.getMessage(linkId, id);
|
|
39835
39874
|
return message && withoutFrame(message);
|
|
39836
39875
|
}
|
|
39876
|
+
/**
|
|
39877
|
+
* A page of a chat's or a group's history: the newest `limit` (before `before`), or with `after` the oldest `limit`
|
|
39878
|
+
* after it (and before `before`). Each bound is a time or a message's place; only the page's rows are read.
|
|
39879
|
+
*/
|
|
39837
39880
|
async messagePage(asked) {
|
|
39838
39881
|
const page = await this.storedPage(asked);
|
|
39839
39882
|
return {
|
|
@@ -39841,23 +39884,29 @@ var GhostlyNode = class GhostlyNode {
|
|
|
39841
39884
|
messages: page.messages.map(withoutFrame)
|
|
39842
39885
|
};
|
|
39843
39886
|
}
|
|
39844
|
-
async storedPage({ linkId, limit = 50, before }) {
|
|
39887
|
+
async storedPage({ linkId, limit = 50, before, after }) {
|
|
39845
39888
|
if (!Number.isSafeInteger(limit) || limit < 1) throw new Error("limit: a whole number of messages, at least 1");
|
|
39846
|
-
|
|
39847
|
-
if (
|
|
39848
|
-
|
|
39849
|
-
|
|
39850
|
-
|
|
39851
|
-
|
|
39852
|
-
});
|
|
39853
|
-
}
|
|
39854
|
-
const from = await db.getMessage(linkId, before);
|
|
39855
|
-
if (!from) throw new Error(`No message ${before}`);
|
|
39856
|
-
return db.getMessagePage(linkId, {
|
|
39889
|
+
const end = before === void 0 ? void 0 : await this.pagePlace(linkId, before, "before");
|
|
39890
|
+
if (after === void 0) return db.getMessagePage(linkId, {
|
|
39891
|
+
limit,
|
|
39892
|
+
before: end
|
|
39893
|
+
});
|
|
39894
|
+
return db.getMessagePageAfter(linkId, {
|
|
39857
39895
|
limit,
|
|
39858
|
-
before:
|
|
39896
|
+
before: end,
|
|
39897
|
+
after: await this.pagePlace(linkId, after, "after")
|
|
39859
39898
|
});
|
|
39860
39899
|
}
|
|
39900
|
+
/** A page's bound: a time, or the place of a message of the chat. */
|
|
39901
|
+
async pagePlace(linkId, bound, side) {
|
|
39902
|
+
if (typeof bound === "number") {
|
|
39903
|
+
if (Number.isNaN(bound)) throw new Error(`${side}: a time or a message id`);
|
|
39904
|
+
return { timestamp: bound };
|
|
39905
|
+
}
|
|
39906
|
+
const from = await db.getMessage(linkId, bound);
|
|
39907
|
+
if (!from) throw new Error(`No message ${bound}`);
|
|
39908
|
+
return from;
|
|
39909
|
+
}
|
|
39861
39910
|
/** Saves a message on this device, or unsaves it (`engine/saved.ts`): nothing is sent. */
|
|
39862
39911
|
saveMessage(params) {
|
|
39863
39912
|
return this.saved.save(params);
|
|
@@ -40967,6 +41016,27 @@ var GhostlyNode = class GhostlyNode {
|
|
|
40967
41016
|
break;
|
|
40968
41017
|
}
|
|
40969
41018
|
}
|
|
41019
|
+
if (!original && group && this.groups.isRemoved(message.linkId.slice(6), reply.id)) return {
|
|
41020
|
+
...message,
|
|
41021
|
+
replyTo: {
|
|
41022
|
+
...reply,
|
|
41023
|
+
snippet: "",
|
|
41024
|
+
messageId: reply.id
|
|
41025
|
+
}
|
|
41026
|
+
};
|
|
41027
|
+
const live = group ? void 0 : this.links.get(message.linkId)?.stored;
|
|
41028
|
+
if (!original && live?.removedRefs?.includes(reply.id)) {
|
|
41029
|
+
const row = [`peer_${reply.id}`, `me_${reply.id}`].find((id) => live.deletedIds?.includes(id));
|
|
41030
|
+
return {
|
|
41031
|
+
...message,
|
|
41032
|
+
replyTo: {
|
|
41033
|
+
...reply,
|
|
41034
|
+
snippet: "",
|
|
41035
|
+
messageId: row ?? reply.id,
|
|
41036
|
+
from: reply.from ?? (row?.startsWith("peer_") ? "peer" : "me")
|
|
41037
|
+
}
|
|
41038
|
+
};
|
|
41039
|
+
}
|
|
40970
41040
|
if (!original && !group) {
|
|
40971
41041
|
history = await db.getMessages(message.linkId);
|
|
40972
41042
|
original = history.find((m) => m.id !== message.id && replyRef(m) === reply.id);
|
|
@@ -41131,17 +41201,28 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41131
41201
|
const live = this.links.get(linkId);
|
|
41132
41202
|
if (!live?.stored.profile || live.stored.group) return false;
|
|
41133
41203
|
const id = `peer_${edit.id}`;
|
|
41204
|
+
const ref = edit.rm && !await this.namesMine(linkId, edit.id);
|
|
41134
41205
|
if (live.stored.deletedIds?.includes(id)) {
|
|
41135
|
-
if (
|
|
41136
|
-
id,
|
|
41137
|
-
|
|
41138
|
-
|
|
41206
|
+
if (ref) {
|
|
41207
|
+
this.quoteSweeps.add(linkId, id, replyRef({
|
|
41208
|
+
id,
|
|
41209
|
+
linkId
|
|
41210
|
+
}));
|
|
41211
|
+
if (!live.stored.removedRefs?.includes(edit.id)) {
|
|
41212
|
+
live.stored = {
|
|
41213
|
+
...live.stored,
|
|
41214
|
+
removedRefs: withRemovedRef(live.stored.removedRefs, edit.id)
|
|
41215
|
+
};
|
|
41216
|
+
await this.writeDeletions(linkId, { removedRefs: live.stored.removedRefs });
|
|
41217
|
+
this.emitState();
|
|
41218
|
+
}
|
|
41219
|
+
}
|
|
41139
41220
|
return true;
|
|
41140
41221
|
}
|
|
41141
41222
|
if (edit.rm) {
|
|
41142
41223
|
const message = await db.getMessage(linkId, id);
|
|
41143
|
-
if (
|
|
41144
|
-
if (!message || canRemove(message)) await this.forgetMessage(linkId, id, true);
|
|
41224
|
+
if (PAYMENT_LINE_ID.test(edit.id)) return true;
|
|
41225
|
+
if (!message || canRemove(message)) await this.forgetMessage(linkId, id, ref && (message ?? true));
|
|
41145
41226
|
return true;
|
|
41146
41227
|
}
|
|
41147
41228
|
const message = await db.getMessage(linkId, id);
|
|
@@ -41723,7 +41804,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41723
41804
|
const out = `${linkId}-out-`;
|
|
41724
41805
|
const wireId = message.wireId ?? (message.file?.id.startsWith(out) ? message.file.id.slice(out.length) : void 0);
|
|
41725
41806
|
if (!wireId || message.delivery === "waiting") {
|
|
41726
|
-
await this.forgetMessage(linkId, messageId,
|
|
41807
|
+
await this.forgetMessage(linkId, messageId, message);
|
|
41727
41808
|
return { error: null };
|
|
41728
41809
|
}
|
|
41729
41810
|
const removal = {
|
|
@@ -41738,7 +41819,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41738
41819
|
removals: withRemoval(live.stored.removals, removal)
|
|
41739
41820
|
};
|
|
41740
41821
|
const written = this.writeDeletions(linkId, { removals: live.stored.removals });
|
|
41741
|
-
const forgot = this.forgetMessage(linkId, messageId,
|
|
41822
|
+
const forgot = this.forgetMessage(linkId, messageId, message);
|
|
41742
41823
|
await written;
|
|
41743
41824
|
await forgot;
|
|
41744
41825
|
const edits = this.editsFor(linkId);
|
|
@@ -41746,6 +41827,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41746
41827
|
edits.flush().catch(() => {});
|
|
41747
41828
|
return { error: null };
|
|
41748
41829
|
}
|
|
41830
|
+
/** Whether my removal of this message of a 1:1 chat is still on its way to the contact (`removeMessage`). */
|
|
41831
|
+
removalPending({ linkId, messageId }) {
|
|
41832
|
+
return !!this.links.get(linkId)?.stored.removals?.some((r) => r.id === messageId);
|
|
41833
|
+
}
|
|
41749
41834
|
/** A chat's row write of its removals and deleted ids waiting to go, by chat (`writeDeletions`). */
|
|
41750
41835
|
deletionWrites = /* @__PURE__ */ new Map();
|
|
41751
41836
|
/** The last such write of each chat, which the next one follows. */
|
|
@@ -41781,19 +41866,35 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41781
41866
|
});
|
|
41782
41867
|
return entry.done;
|
|
41783
41868
|
}
|
|
41869
|
+
/** Whether a 1:1 chat's wire id names a message of mine: here, deleted here, removed, or a file or payment of mine. */
|
|
41870
|
+
async namesMine(linkId, wireId) {
|
|
41871
|
+
const stored = this.links.get(linkId)?.stored, row = `me_${wireId}`;
|
|
41872
|
+
if (stored?.deletedIds?.includes(row) || stored?.removals?.some((r) => r.id === row || r.wireId === wireId)) return true;
|
|
41873
|
+
for (const id of [row, ...await this.rowsNamed(linkId, wireId)]) if ((await db.getMessage(linkId, id))?.sender === "me") return true;
|
|
41874
|
+
return false;
|
|
41875
|
+
}
|
|
41784
41876
|
/**
|
|
41785
41877
|
* Forgets one message of a chat on this device, the bytes of its file and any transfer of it, and keeps its id so a
|
|
41786
41878
|
* copy that comes again is not stored: a delete here, or the contact's own removal (WISP 400 § Delete for everyone),
|
|
41787
|
-
* also of a message not here yet. `removed`: deleted for everyone,
|
|
41879
|
+
* also of a message not here yet. `removed`: deleted for everyone (its row, when the caller read it), so the replies
|
|
41880
|
+
* here that quote it lose its line too, and a pin of it goes (`removedRefs`).
|
|
41788
41881
|
*/
|
|
41789
41882
|
async forgetMessage(linkId, messageId, removed = false) {
|
|
41790
41883
|
const live = this.links.get(linkId);
|
|
41791
41884
|
if (!live) return;
|
|
41885
|
+
const ref = removed ? replyRef(removed === true ? {
|
|
41886
|
+
id: messageId,
|
|
41887
|
+
linkId
|
|
41888
|
+
} : removed) : void 0;
|
|
41792
41889
|
live.stored = {
|
|
41793
41890
|
...live.stored,
|
|
41794
|
-
deletedIds: [...live.stored.deletedIds ?? [], messageId].slice(-500)
|
|
41891
|
+
deletedIds: [...live.stored.deletedIds ?? [], messageId].slice(-500),
|
|
41892
|
+
...ref && { removedRefs: withRemovedRef(live.stored.removedRefs, ref) }
|
|
41795
41893
|
};
|
|
41796
|
-
this.writeDeletions(linkId, {
|
|
41894
|
+
this.writeDeletions(linkId, {
|
|
41895
|
+
deletedIds: live.stored.deletedIds,
|
|
41896
|
+
...ref && { removedRefs: live.stored.removedRefs }
|
|
41897
|
+
}).catch(() => {});
|
|
41797
41898
|
this.hold.forget(linkId, messageId).catch(() => {});
|
|
41798
41899
|
const message = await db.getMessage(linkId, messageId);
|
|
41799
41900
|
if (message?.paymentId && message.delivery === "waiting") await this.desk.withdraw(message.paymentId).catch(() => {});
|
|
@@ -41831,7 +41932,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
41831
41932
|
async forgetQuotes(linkId, removed) {
|
|
41832
41933
|
const byRef = /* @__PURE__ */ new Map();
|
|
41833
41934
|
for (const [id, ref] of removed) if (ref !== void 0) byRef.set(ref, id);
|
|
41834
|
-
const
|
|
41935
|
+
const side = (id) => id.startsWith("peer_") ? "peer" : id.startsWith("me_") ? "me" : void 0;
|
|
41936
|
+
const byReference = (reply) => {
|
|
41937
|
+
const id = byRef.get(reply.id);
|
|
41938
|
+
return id === void 0 || !reply.from || !side(id) || side(id) === reply.from ? id : void 0;
|
|
41939
|
+
};
|
|
41940
|
+
const quoted = (reply) => !reply ? void 0 : reply.messageId !== void 0 && removed.has(reply.messageId) ? reply.messageId : byReference(reply);
|
|
41835
41941
|
const ids = (await db.getMessages(linkId)).filter((m) => {
|
|
41836
41942
|
const id = quoted(m.replyTo);
|
|
41837
41943
|
return id !== void 0 && (m.replyTo.snippet || m.replyTo.messageId !== id);
|
|
@@ -42455,7 +42561,16 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42455
42561
|
if (!error) this.brief(fileId);
|
|
42456
42562
|
this.emitState();
|
|
42457
42563
|
}
|
|
42564
|
+
/**
|
|
42565
|
+
* DHT only, or back to a live link. Back, it answers once the link has left DHT only: the native listeners start
|
|
42566
|
+
* behind it and join the chat as each comes up (`registerEndpoint`). It waited for them before, 10 to 25 s with
|
|
42567
|
+
* Iroh's relay or the HyperDHT out of reach, so `chat disconnect --hold 0` blocked that long.
|
|
42568
|
+
*/
|
|
42458
42569
|
async setDeliveryMode({ linkId, mode }) {
|
|
42570
|
+
await this.switchDeliveryMode(linkId, mode, false);
|
|
42571
|
+
}
|
|
42572
|
+
/** `setDeliveryMode`; `native`: back on a live link, wait for its native listeners too (a choice that names one). */
|
|
42573
|
+
async switchDeliveryMode(linkId, mode, native) {
|
|
42459
42574
|
const live = this.links.get(linkId);
|
|
42460
42575
|
if (!live?.stored.profile || !live.link || mode !== "stream" && mode !== "dht") throw new Error("Delivery method unavailable.");
|
|
42461
42576
|
await db.patchLink(linkId, { deliveryMode: mode });
|
|
@@ -42464,7 +42579,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42464
42579
|
deliveryMode: mode
|
|
42465
42580
|
};
|
|
42466
42581
|
await live.link.setDeliveryMode(mode);
|
|
42467
|
-
if (mode === "stream")
|
|
42582
|
+
if (mode === "stream") {
|
|
42583
|
+
const listening = this.ensureNativeEndpoints(linkId);
|
|
42584
|
+
if (native) await listening;
|
|
42585
|
+
}
|
|
42468
42586
|
this.observeTransport(linkId);
|
|
42469
42587
|
this.emitState();
|
|
42470
42588
|
}
|
|
@@ -42527,10 +42645,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42527
42645
|
preferredTransport
|
|
42528
42646
|
};
|
|
42529
42647
|
await db.patchLink(linkId, { preferredTransport });
|
|
42530
|
-
await this.
|
|
42531
|
-
linkId,
|
|
42532
|
-
mode: "stream"
|
|
42533
|
-
});
|
|
42648
|
+
await this.switchDeliveryMode(linkId, "stream", true);
|
|
42534
42649
|
}
|
|
42535
42650
|
if (transport !== "auto") {
|
|
42536
42651
|
await this.setTransportPreference({
|
|
@@ -42969,6 +43084,14 @@ var GhostlyNode = class GhostlyNode {
|
|
|
42969
43084
|
groupTaken({ groupId, messageId, edit }) {
|
|
42970
43085
|
return this.groups.taken(groupId, messageId, edit);
|
|
42971
43086
|
}
|
|
43087
|
+
/** The numbers of my reactions and of my pin in a 1:1 chat that the contact has not confirmed: what `react` and `pin` wait for. */
|
|
43088
|
+
chatUnconfirmed({ linkId }) {
|
|
43089
|
+
const stored = this.links.get(linkId)?.stored;
|
|
43090
|
+
return {
|
|
43091
|
+
reactions: (stored?.reactionsOut ?? []).map((r) => r.n),
|
|
43092
|
+
pin: stored?.pinOut?.n ?? null
|
|
43093
|
+
};
|
|
43094
|
+
}
|
|
42972
43095
|
/**
|
|
42973
43096
|
* Reacts to a message of a chat or a group (WISP 400 § Reactions): shown here at once; a 1:1 chat keeps it until the
|
|
42974
43097
|
* contact confirms it (the live session, or DHT envelopes meanwhile), a group sends it to its members.
|
|
@@ -43135,7 +43258,10 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43135
43258
|
const host = this.pinsHost;
|
|
43136
43259
|
if (linkId.startsWith("group:")) {
|
|
43137
43260
|
const groupId = linkId.slice(6), view = this.groups.view(groupId);
|
|
43138
|
-
if (!view || view.status !== "active") return {
|
|
43261
|
+
if (!view || view.status !== "active") return {
|
|
43262
|
+
error: view?.statusReason ?? "You are not in this group",
|
|
43263
|
+
refused: true
|
|
43264
|
+
};
|
|
43139
43265
|
if (!mayPinIn(view)) return { error: "Only the admin pins in a community" };
|
|
43140
43266
|
const pin = await myPin(host, linkId, messageId, !!remove, this.groups.pinOf(groupId));
|
|
43141
43267
|
if ("error" in pin) return pin;
|
|
@@ -43217,17 +43343,32 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43217
43343
|
async appOpen({ linkId, ref, version, digest }) {
|
|
43218
43344
|
const { live, app } = this.appChat(linkId, ref);
|
|
43219
43345
|
if (!isAppVersion(version)) throw new Error("Not an app version");
|
|
43346
|
+
const turn = this.appTurn(linkId, app);
|
|
43220
43347
|
await this.appChatRunnable(ref, digest);
|
|
43348
|
+
if (this.appTurns.get(`${linkId} ${app}`) !== turn) return { app };
|
|
43221
43349
|
const open = live.appsOpen ??= /* @__PURE__ */ new Map();
|
|
43222
43350
|
if (live.link) live.link.openApp(app, version);
|
|
43223
43351
|
else open.set(app, version);
|
|
43224
43352
|
return { app };
|
|
43225
43353
|
}
|
|
43354
|
+
/** The last open or close of each app in each chat, by chat and chat app id: an open still reading the store is not the last. */
|
|
43355
|
+
appTurns = /* @__PURE__ */ new Map();
|
|
43356
|
+
nextAppTurn = 0;
|
|
43357
|
+
appTurn(linkId, app) {
|
|
43358
|
+
const turn = ++this.nextAppTurn;
|
|
43359
|
+
this.appTurns.set(`${linkId} ${app}`, turn);
|
|
43360
|
+
return turn;
|
|
43361
|
+
}
|
|
43362
|
+
/** Closes `app` in a chat, and any open of it still on its way. */
|
|
43363
|
+
appCloseIn(linkId, live, app) {
|
|
43364
|
+
this.appTurn(linkId, app);
|
|
43365
|
+
if (live.link) live.link.closeApp(app);
|
|
43366
|
+
else live.appsOpen?.delete(app);
|
|
43367
|
+
}
|
|
43226
43368
|
/** This side closed an app in a paired chat: `close` goes now when the session is live. */
|
|
43227
43369
|
appClose({ linkId, ref }) {
|
|
43228
43370
|
const { live, app } = this.appChat(linkId, ref);
|
|
43229
|
-
|
|
43230
|
-
else live.appsOpen?.delete(app);
|
|
43371
|
+
this.appCloseIn(linkId, live, app);
|
|
43231
43372
|
}
|
|
43232
43373
|
/** One data frame of an app open on both sides, on the live session only; nothing is kept to send later. */
|
|
43233
43374
|
async appSend({ linkId, ref, data, digest }) {
|
|
@@ -43314,17 +43455,15 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43314
43455
|
}
|
|
43315
43456
|
/** Every page went away: no app runs here any more, so each open one is closed (`close` goes where it can). */
|
|
43316
43457
|
appsCloseAll() {
|
|
43317
|
-
for (const live of this.links
|
|
43318
|
-
|
|
43458
|
+
for (const [linkId, live] of this.links) for (const app of [...live.appsOpen?.keys() ?? []]) this.appCloseIn(linkId, live, app);
|
|
43459
|
+
for (const key of this.appTurns.keys()) this.appTurns.set(key, ++this.nextAppTurn);
|
|
43319
43460
|
}
|
|
43320
43461
|
/** An app that went (uninstalled) is closed in every chat it was open in, as `appClose` does. */
|
|
43321
43462
|
appsCloseOf(ref) {
|
|
43322
43463
|
for (const [linkId, live] of this.links) {
|
|
43323
43464
|
if (!live.appsOpen?.size) continue;
|
|
43324
43465
|
const { app } = this.appChat(linkId, ref);
|
|
43325
|
-
if (
|
|
43326
|
-
if (live.link) live.link.closeApp(app);
|
|
43327
|
-
else live.appsOpen.delete(app);
|
|
43466
|
+
if (live.appsOpen.has(app)) this.appCloseIn(linkId, live, app);
|
|
43328
43467
|
}
|
|
43329
43468
|
}
|
|
43330
43469
|
/** Keeps a pin of a 1:1 chat when it is newer than the chat's; `out`: mine, to say until the contact confirms it. */
|
|
@@ -43366,6 +43505,29 @@ var GhostlyNode = class GhostlyNode {
|
|
|
43366
43505
|
};
|
|
43367
43506
|
await db.patchLink(linkId, { pinOut: void 0 });
|
|
43368
43507
|
}
|
|
43508
|
+
/**
|
|
43509
|
+
* A 1:1 chat's pin that came before its message (pinned while I was away: the pin goes as the session opens, ahead of
|
|
43510
|
+
* what waited) names its row once the row is here. Only the rows that changed are read, and only while such a pin stands.
|
|
43511
|
+
*/
|
|
43512
|
+
async pinnedRowCame(linkId, ids) {
|
|
43513
|
+
const live = this.links.get(linkId), pin = live?.stored.pin;
|
|
43514
|
+
if (!live || live.stored.group || !pin?.id || pin.messageId) return;
|
|
43515
|
+
for (const id of new Set(ids)) {
|
|
43516
|
+
const row = await db.getMessage(linkId, id);
|
|
43517
|
+
if (!row || replyRef(row) !== pin.id) continue;
|
|
43518
|
+
if (live.stored.pin !== pin) return;
|
|
43519
|
+
live.stored = {
|
|
43520
|
+
...live.stored,
|
|
43521
|
+
pin: {
|
|
43522
|
+
...pin,
|
|
43523
|
+
messageId: row.id
|
|
43524
|
+
}
|
|
43525
|
+
};
|
|
43526
|
+
await db.patchLink(linkId, { pin: live.stored.pin });
|
|
43527
|
+
this.emitState();
|
|
43528
|
+
return;
|
|
43529
|
+
}
|
|
43530
|
+
}
|
|
43369
43531
|
/** A pin that came, as it is kept: who pinned, and its row when it is here. */
|
|
43370
43532
|
async pinCame(chat, by, pin) {
|
|
43371
43533
|
const row = await pinnedRow(this.pinsHost, chat, pin.id);
|
|
@@ -44620,6 +44782,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44620
44782
|
/** Groups whose admin work is off on this device since a forced takeover or a restore. */
|
|
44621
44783
|
groupAdminOff = /* @__PURE__ */ new Set();
|
|
44622
44784
|
saved = new SavedMessages(() => this.emitState());
|
|
44785
|
+
/** The chat list's search over the chats' histories (`chatsFound`): each chat read once, and again after it changes. */
|
|
44786
|
+
chatSearch = new ChatTextSearch((linkId) => db.getMessages(linkId));
|
|
44623
44787
|
/**
|
|
44624
44788
|
* Raises the counters a copy from older state must raise, once (`devices/raise.ts`): the raise a forced takeover wrote
|
|
44625
44789
|
* into the device record with `active`, or the one a restore wrote into the profile's settings. Then reads the floor
|
|
@@ -44786,6 +44950,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44786
44950
|
}
|
|
44787
44951
|
this.watchActiveTurn();
|
|
44788
44952
|
this.watchTombstones();
|
|
44953
|
+
await this.finishRemovals().catch(() => {});
|
|
44789
44954
|
await this.rotateIfDue().catch(() => {});
|
|
44790
44955
|
}
|
|
44791
44956
|
/**
|
|
@@ -44886,6 +45051,12 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44886
45051
|
async moveDeviceSet(remove) {
|
|
44887
45052
|
this.setMoveAllowed();
|
|
44888
45053
|
if (this.settingMove) throw new Error("remove-busy: The device set is already changing.");
|
|
45054
|
+
const record = remove === void 0 ? null : await readDeviceRecord(databaseName()).catch(() => null);
|
|
45055
|
+
if (record?.state === "active" && record.earlierSets.some((set) => set.removed === remove) && !record.deviceSet.some((slot) => slot?.key === remove)) {
|
|
45056
|
+
await this.finishRemovals().catch(() => {});
|
|
45057
|
+
this.watchTombstones();
|
|
45058
|
+
return this.deviceSet();
|
|
45059
|
+
}
|
|
44889
45060
|
const work = (async () => {
|
|
44890
45061
|
const ports = await this.setMovePorts();
|
|
44891
45062
|
if (!ports) throw new Error("remove-state: This device cannot sign for its device set.");
|
|
@@ -44897,7 +45068,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44897
45068
|
} finally {
|
|
44898
45069
|
this.settingMove = null;
|
|
44899
45070
|
}
|
|
44900
|
-
if (remove !== void 0) await this.
|
|
45071
|
+
if (remove !== void 0) await this.finishRemovals().catch(() => {});
|
|
44901
45072
|
if (this.handoffGiver) {
|
|
44902
45073
|
this.deviceLinks?.setHandoff(null);
|
|
44903
45074
|
this.handoffGiver = null;
|
|
@@ -44932,6 +45103,28 @@ var GhostlyNode = class GhostlyNode {
|
|
|
44932
45103
|
}
|
|
44933
45104
|
}
|
|
44934
45105
|
/**
|
|
45106
|
+
* What each removal left in the profile (`afterDeviceRemoved`), for every earlier set that still names the device it
|
|
45107
|
+
* removed: after the move, and at start for one a reload, a crash or a stop cut short after its write. The name is
|
|
45108
|
+
* dropped once its device's leftovers are cleared.
|
|
45109
|
+
*/
|
|
45110
|
+
async finishRemovals() {
|
|
45111
|
+
const profile = databaseName();
|
|
45112
|
+
const record = await readDeviceRecord(profile);
|
|
45113
|
+
if (record?.state !== "active") return;
|
|
45114
|
+
const done = /* @__PURE__ */ new Set();
|
|
45115
|
+
for (const set of record.earlierSets) {
|
|
45116
|
+
if (set.removed === void 0 || done.has(set.removed)) continue;
|
|
45117
|
+
if (await this.afterDeviceRemoved(set.removed).then(() => true, () => false)) done.add(set.removed);
|
|
45118
|
+
}
|
|
45119
|
+
if (!done.size) return;
|
|
45120
|
+
const now = await readDeviceRecord(profile);
|
|
45121
|
+
if (now?.state !== "active") return;
|
|
45122
|
+
await amendDevice(profile, { earlierSets: now.earlierSets.map(({ removed, ...set }) => removed === void 0 || done.has(removed) ? set : {
|
|
45123
|
+
...set,
|
|
45124
|
+
removed
|
|
45125
|
+
}) });
|
|
45126
|
+
}
|
|
45127
|
+
/**
|
|
44935
45128
|
* Remove: the device with this signing key can no longer take the profile (WISP 06 § Removing a device). The set
|
|
44936
45129
|
* moves to a new secret, which the other devices get over their old links; the removed one gets nothing, and reads
|
|
44937
45130
|
* its removal from the tombstone. Only the active device removes.
|
|
@@ -45006,7 +45199,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
45006
45199
|
await this.startDeviceSet();
|
|
45007
45200
|
},
|
|
45008
45201
|
onChange: (view) => {
|
|
45009
|
-
if (view.step === "failed") setTimeout(() => void this.rotateIfDue().catch(() => {}), 0);
|
|
45202
|
+
if (view.step === "failed" || view.step === "done") setTimeout(() => void this.rotateIfDue().catch(() => {}), 0);
|
|
45010
45203
|
}
|
|
45011
45204
|
});
|
|
45012
45205
|
this.enrollment = inviter;
|
|
@@ -46441,7 +46634,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46441
46634
|
nativeFactoriesFor(relayOnly) {
|
|
46442
46635
|
const relay = relayOnly || this.relaysHyperdhtNatively ? this.hyperdhtRelay : "";
|
|
46443
46636
|
return {
|
|
46444
|
-
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-
|
|
46637
|
+
...relay ? { "hyperdht/1": async (seedB64) => (await import("./hyperdhtRelay-B2uK9tJv.js")).createRelayedHyperEndpoint(seedB64, relay) } : {},
|
|
46445
46638
|
...relayOnly ? {} : this.options.nativeTransports,
|
|
46446
46639
|
...this.ownIrohRelays && !relayOnly ? { "iroh/1": (seedB64) => this.options.nativeTransports["iroh/1"](seedB64, this.settings.irohRelays?.length ? { relays: [...this.settings.irohRelays] } : {}) } : {},
|
|
46447
46640
|
...this.options.irohWeb ? { "iroh/1": (seedB64) => createIrohWebEndpoint(seedB64, { relays: this.irohRelays }) } : {}
|
|
@@ -46497,7 +46690,7 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46497
46690
|
this.relayRetry = setTimeout(() => {
|
|
46498
46691
|
this.relayRetry = null;
|
|
46499
46692
|
for (const [linkId, live] of this.links) if (live.link && live.stored.profile && (!live.stored.group || this.keepsGroupNative(live.stored)) && live.stored.deliveryMode !== "dht" && !live.link.availableTransports.includes("hyperdht/1") && this.keepsNativeEndpoints(linkId, live.stored)) this.ensureNativeEndpoints(linkId);
|
|
46500
|
-
}, RELAY_RETRY_MS);
|
|
46693
|
+
}, RELAY_RETRY_MS / 2 + Math.random() * RELAY_RETRY_MS);
|
|
46501
46694
|
}
|
|
46502
46695
|
/** A new relay (or none): chats give up their endpoints on the old one, as soon as none of them carries a session. */
|
|
46503
46696
|
async relayChanged() {
|
|
@@ -46940,6 +47133,8 @@ var GhostlyNode = class GhostlyNode {
|
|
|
46940
47133
|
* the whole history. A host that takes whole histories only (no `onMessageChanges`) gets the whole history, as before.
|
|
46941
47134
|
*/
|
|
46942
47135
|
async messagesChanged(linkId, ids) {
|
|
47136
|
+
this.chatSearch.changed(linkId);
|
|
47137
|
+
await this.pinnedRowCame(linkId, ids);
|
|
46943
47138
|
const reacted = this.reactionNotes.get(linkId);
|
|
46944
47139
|
if (reacted?.message && ids.includes(reacted.message)) {
|
|
46945
47140
|
const row = await db.getMessage(linkId, reacted.message);
|
|
@@ -47148,7 +47343,11 @@ var GhostlyNode = class GhostlyNode {
|
|
|
47148
47343
|
...stored.wakeMuted && { wakeMuted: true }
|
|
47149
47344
|
},
|
|
47150
47345
|
...this.reactionNotes.has(stored.id) && { lastReaction: this.reactionNotes.get(stored.id) },
|
|
47151
|
-
...stored.pin && { pin: pinView(stored.pin)
|
|
47346
|
+
...stored.pin && { pin: pinView(stored.pin.id && stored.removedRefs?.includes(stored.pin.id) ? {
|
|
47347
|
+
...stored.pin,
|
|
47348
|
+
id: "",
|
|
47349
|
+
messageId: void 0
|
|
47350
|
+
} : stored.pin) },
|
|
47152
47351
|
participationKey: participationKeyOf(live),
|
|
47153
47352
|
peerParticipationKey: stored.pairedPeerKey,
|
|
47154
47353
|
publicProfiles: void 0,
|
|
@@ -47265,9 +47464,12 @@ var EngineServer = class {
|
|
|
47265
47464
|
clients = /* @__PURE__ */ new Set();
|
|
47266
47465
|
/**
|
|
47267
47466
|
* Per client, the chats and groups whose whole history it was sent. It hears only what changes in those; one it
|
|
47268
|
-
* does not have yet is sent
|
|
47467
|
+
* does not have yet is sent first (read once, when its first change comes), then what changes: whole, or as its newest
|
|
47468
|
+
* page to a client that attached for those (`newest`).
|
|
47269
47469
|
*/
|
|
47270
47470
|
histories = /* @__PURE__ */ new WeakMap();
|
|
47471
|
+
/** The clients that attached with `newest`, and how many rows of a chat they get before they ask for the rest. */
|
|
47472
|
+
newest = /* @__PURE__ */ new WeakMap();
|
|
47271
47473
|
/** Per chat or group, what is still being sent (a whole history being read): what comes next waits for it. */
|
|
47272
47474
|
sending = /* @__PURE__ */ new Map();
|
|
47273
47475
|
/**
|
|
@@ -47350,6 +47552,8 @@ var EngineServer = class {
|
|
|
47350
47552
|
for (const id of read.ids) if ((this.changedAt.get(id) ?? 0) <= read.mark) sent.add(id);
|
|
47351
47553
|
}
|
|
47352
47554
|
this.histories.set(client, sent);
|
|
47555
|
+
if (scope.newest) this.newest.set(client, scope.newest);
|
|
47556
|
+
else this.newest.delete(client);
|
|
47353
47557
|
this.ready.then(async () => {
|
|
47354
47558
|
if (!this.clients.has(client)) return;
|
|
47355
47559
|
client.post({
|
|
@@ -47498,12 +47702,20 @@ var EngineServer = class {
|
|
|
47498
47702
|
});
|
|
47499
47703
|
}
|
|
47500
47704
|
if (!behind.length) return;
|
|
47501
|
-
return this.
|
|
47502
|
-
|
|
47503
|
-
|
|
47504
|
-
|
|
47505
|
-
|
|
47506
|
-
|
|
47705
|
+
return this.catchUp(linkId, behind);
|
|
47706
|
+
}
|
|
47707
|
+
/**
|
|
47708
|
+
* A chat or group these clients do not have, read now: it holds the changes that brought it here, and what changes next
|
|
47709
|
+
* follows it. A client that attached with `newest` gets that page, and asks for the rest when it shows the chat: a group
|
|
47710
|
+
* is in no attach, and the first message of each one went whole, as JSON, to every tab, whether or not one showed it.
|
|
47711
|
+
*/
|
|
47712
|
+
async catchUp(linkId, behind) {
|
|
47713
|
+
let whole;
|
|
47714
|
+
for (const client of behind) {
|
|
47715
|
+
const newest = this.newest.get(client);
|
|
47716
|
+
const event = newest ? await this.newestOf(linkId, newest) : this.historyEvent(linkId, whole ??= await this.node.getMessages(linkId));
|
|
47717
|
+
if (this.clients.has(client) && this.post(client, event)) this.histories.get(client)?.add(linkId);
|
|
47718
|
+
}
|
|
47507
47719
|
}
|
|
47508
47720
|
post(client, event) {
|
|
47509
47721
|
try {
|
|
@@ -47535,4 +47747,4 @@ function signalKind(signal) {
|
|
|
47535
47747
|
//#endregion
|
|
47536
47748
|
export { EngineServer };
|
|
47537
47749
|
|
|
47538
|
-
//# sourceMappingURL=server-
|
|
47750
|
+
//# sourceMappingURL=server-BUcJo4vz.js.map
|