@glyphteck/veyl 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -100
- package/dist/cli.js +1072 -951
- package/dist/index.js +957 -591
- package/docs/agents.md +235 -0
- package/docs/api.md +647 -0
- package/docs/cli.md +169 -0
- package/docs/mcp.md +54 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -38993,12 +38993,6 @@ function mnemonicFromWalletEntropy(entropy) {
|
|
|
38993
38993
|
}
|
|
38994
38994
|
return entropyToMnemonic(entropyBytesValue, wordlist);
|
|
38995
38995
|
}
|
|
38996
|
-
function deriveLegacyWalletEntropy(seed) {
|
|
38997
|
-
const entropy = deriveSeed(seed, "wallet-mnemonic");
|
|
38998
|
-
const out = new Uint8Array(entropy.subarray(0, WALLET_MNEMONIC_ENTROPY_BYTES));
|
|
38999
|
-
cleanBytes(entropy);
|
|
39000
|
-
return out;
|
|
39001
|
-
}
|
|
39002
38996
|
function getKeyPair(seed) {
|
|
39003
38997
|
const priv = new Uint8Array(seed);
|
|
39004
38998
|
priv[0] &= 248;
|
|
@@ -39085,15 +39079,6 @@ async function openAccountSessionFromSecrets(walletEntropy, chatSeed, { SparkWal
|
|
|
39085
39079
|
cleanBytes(chatSeed, chatPubKey);
|
|
39086
39080
|
}
|
|
39087
39081
|
}
|
|
39088
|
-
async function openLegacyAccountSession(masterSeed, options = {}) {
|
|
39089
|
-
const walletEntropy = deriveLegacyWalletEntropy(masterSeed);
|
|
39090
|
-
const chatSeed = deriveSeed(masterSeed, "chat");
|
|
39091
|
-
try {
|
|
39092
|
-
return await openAccountSessionFromSecrets(walletEntropy, chatSeed, options);
|
|
39093
|
-
} finally {
|
|
39094
|
-
cleanBytes(walletEntropy, chatSeed);
|
|
39095
|
-
}
|
|
39096
|
-
}
|
|
39097
39082
|
async function openRegistryAccountSession(masterSeed, registryEnvelope, options = {}) {
|
|
39098
39083
|
const registry = await openSecretRegistry(masterSeed, registryEnvelope);
|
|
39099
39084
|
const walletEntropy = getDefaultWalletEntropy(registry);
|
|
@@ -39108,7 +39093,7 @@ async function openRegistryAccountSession(masterSeed, registryEnvelope, options
|
|
|
39108
39093
|
import { Buffer as Buffer4 } from "buffer";
|
|
39109
39094
|
import process5 from "process";
|
|
39110
39095
|
|
|
39111
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
39096
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/chunk-BCcL9Bmk.js
|
|
39112
39097
|
var __toBinaryNode = (base642) => new Uint8Array(Buffer.from(base642, "base64"));
|
|
39113
39098
|
|
|
39114
39099
|
// ../../node_modules/.bun/@bufbuild+protobuf@2.12.0/node_modules/@bufbuild/protobuf/dist/esm/wire/varint.js
|
|
@@ -39724,7 +39709,7 @@ function assertFloat32(arg) {
|
|
|
39724
39709
|
throw new Error("invalid float32: " + arg);
|
|
39725
39710
|
}
|
|
39726
39711
|
|
|
39727
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
39712
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/empty-CbimPmjm.js
|
|
39728
39713
|
function createBaseTimestamp() {
|
|
39729
39714
|
return {
|
|
39730
39715
|
seconds: 0,
|
|
@@ -39967,7 +39952,7 @@ var Empty = {
|
|
|
39967
39952
|
}
|
|
39968
39953
|
};
|
|
39969
39954
|
|
|
39970
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
39955
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/proto/spark.js
|
|
39971
39956
|
var Network = /* @__PURE__ */ function(Network2) {
|
|
39972
39957
|
Network2[Network2["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
39973
39958
|
Network2[Network2["MAINNET"] = 1] = "MAINNET";
|
|
@@ -57118,7 +57103,7 @@ var DefaultRequester = class extends Requester {
|
|
|
57118
57103
|
}
|
|
57119
57104
|
};
|
|
57120
57105
|
|
|
57121
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
57106
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/sdk-types-DJDUa17y.js
|
|
57122
57107
|
var BitcoinNetwork = /* @__PURE__ */ function(BitcoinNetwork2) {
|
|
57123
57108
|
BitcoinNetwork2["FUTURE_VALUE"] = "FUTURE_VALUE";
|
|
57124
57109
|
BitcoinNetwork2["MAINNET"] = "MAINNET";
|
|
@@ -57979,7 +57964,7 @@ function mapTransferToWalletTransfer(proto, identityPublicKey, userRequest) {
|
|
|
57979
57964
|
};
|
|
57980
57965
|
}
|
|
57981
57966
|
|
|
57982
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
57967
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/multisig-BPUmc7A3.js
|
|
57983
57968
|
function createBaseMultisigConfig() {
|
|
57984
57969
|
return {
|
|
57985
57970
|
version: 0,
|
|
@@ -58204,7 +58189,7 @@ function isSet3(value) {
|
|
|
58204
58189
|
return value !== null && value !== undefined;
|
|
58205
58190
|
}
|
|
58206
58191
|
|
|
58207
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
58192
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/proto/spark_token.js
|
|
58208
58193
|
var TokenOutputStatus = /* @__PURE__ */ function(TokenOutputStatus2) {
|
|
58209
58194
|
TokenOutputStatus2[TokenOutputStatus2["TOKEN_OUTPUT_STATUS_UNSPECIFIED"] = 0] = "TOKEN_OUTPUT_STATUS_UNSPECIFIED";
|
|
58210
58195
|
TokenOutputStatus2[TokenOutputStatus2["TOKEN_OUTPUT_STATUS_AVAILABLE"] = 1] = "TOKEN_OUTPUT_STATUS_AVAILABLE";
|
|
@@ -67597,7 +67582,7 @@ class Transaction {
|
|
|
67597
67582
|
// ../../node_modules/.bun/@scure+btc-signer@1.8.1/node_modules/@scure/btc-signer/esm/index.js
|
|
67598
67583
|
/*! scure-btc-signer - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
67599
67584
|
|
|
67600
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
67585
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/spark-wallet-DEFcyFjN.js
|
|
67601
67586
|
var import_nice_grpc_common = __toESM(require_lib(), 1);
|
|
67602
67587
|
|
|
67603
67588
|
// ../../node_modules/.bun/@scure+bip32@1.7.0/node_modules/@scure/bip32/lib/esm/index.js
|
|
@@ -70215,7 +70200,7 @@ class Mutex {
|
|
|
70215
70200
|
// ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.mjs
|
|
70216
70201
|
var import__ = __toESM(require_eventemitter3(), 1);
|
|
70217
70202
|
|
|
70218
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
70203
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/spark-wallet-DEFcyFjN.js
|
|
70219
70204
|
var import_light_bolt11_decoder = __toESM(require_bolt11(), 1);
|
|
70220
70205
|
var SparkFrostBase = class {
|
|
70221
70206
|
generateAdaptorFromSignature(signature) {
|
|
@@ -89329,7 +89314,7 @@ function isTokenTransactionStreamEvent(event) {
|
|
|
89329
89314
|
return Boolean(event?.$case === "tokenTransaction" && event.tokenTransaction.tokenTransactionHash);
|
|
89330
89315
|
}
|
|
89331
89316
|
|
|
89332
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
89317
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/buffer-C7zVfCZb.js
|
|
89333
89318
|
import { Buffer as Buffer2 } from "buffer";
|
|
89334
89319
|
if (typeof globalThis.Buffer === "undefined")
|
|
89335
89320
|
globalThis.Buffer = Buffer2;
|
|
@@ -89340,7 +89325,7 @@ if (typeof window !== "undefined") {
|
|
|
89340
89325
|
window.globalThis = window;
|
|
89341
89326
|
}
|
|
89342
89327
|
|
|
89343
|
-
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+
|
|
89328
|
+
// ../../node_modules/.bun/@buildonspark+spark-sdk@0.8.8+bee703889d31789e/node_modules/@buildonspark/spark-sdk/dist/index.browser.js
|
|
89344
89329
|
var import_nice_grpc_common2 = __toESM(require_lib(), 1);
|
|
89345
89330
|
var import_nice_grpc_client_middleware_retry = __toESM(require_lib4(), 1);
|
|
89346
89331
|
var import_nice_grpc_web = __toESM(require_lib5(), 1);
|
|
@@ -92127,7 +92112,7 @@ var CHAT_READY_DOWNLOAD_MAX_BYTES = 8 * MIB_BYTES;
|
|
|
92127
92112
|
var CHAT_MESSAGE_FILE_CACHE_MAX_BYTES = 64 * MIB_BYTES;
|
|
92128
92113
|
var CHAT_UNSAVED_TTL_DAYS = 21;
|
|
92129
92114
|
var CHAT_UNSAVED_TTL_MS = CHAT_UNSAVED_TTL_DAYS * DAY_MS;
|
|
92130
|
-
var
|
|
92115
|
+
var CHAT_AFTER_SEEN_MS = DAY_MS;
|
|
92131
92116
|
var CHAT_MEDIA_TTL_DAYS = CHAT_UNSAVED_TTL_DAYS;
|
|
92132
92117
|
var CHAT_MEDIA_TTL_MS = CHAT_MEDIA_TTL_DAYS * DAY_MS;
|
|
92133
92118
|
var CHAT_UPLOAD_MAX_BYTES = 64 * MIB_BYTES;
|
|
@@ -92135,10 +92120,12 @@ var CHAT_AUDIO_TRANSCODE_BITRATE_BPS = 128000;
|
|
|
92135
92120
|
var CHAT_VIDEO_TRANSCODE_VIDEO_BITRATE_BPS = 768000;
|
|
92136
92121
|
var CHAT_VIDEO_TRANSCODE_AUDIO_BITRATE_BPS = CHAT_AUDIO_TRANSCODE_BITRATE_BPS;
|
|
92137
92122
|
var CHAT_MESSAGE_BATCH_SIZE = 40;
|
|
92123
|
+
var CHAT_TTL_WRITE_BATCH_SIZE = 400;
|
|
92138
92124
|
var CHAT_LIST_PAGE_SIZE = 20;
|
|
92139
92125
|
var CHAT_INBOX_PING_PAGE_SIZE = 25;
|
|
92140
92126
|
var CHAT_LIST_STATUS_CACHE_MS = 30 * MS_PER_SECOND;
|
|
92141
92127
|
var CHAT_MEDIA_WARM_TYPES = Object.freeze(["img", "gif", "mp4"]);
|
|
92128
|
+
var CHAT_READ_WRITE_INTERVAL_MS = 5 * MS_PER_SECOND;
|
|
92142
92129
|
var CHAT_SEND_QUEUE_RATE_LIMIT_WINDOW_MS = 10 * MS_PER_SECOND;
|
|
92143
92130
|
var CHAT_MESSAGE_BODY_MAX_BYTES = 64 * KIB_BYTES;
|
|
92144
92131
|
var CHAT_LAST_MESSAGE_BODY_MAX_BYTES = 64 * KIB_BYTES;
|
|
@@ -92168,6 +92155,7 @@ var WALLET_PENDING_TRANSFER_WARM_AGE_MS = 10 * MINUTE_MS;
|
|
|
92168
92155
|
var WALLET_PENDING_TRANSFER_WARM_RETRY_MS = 15 * MS_PER_SECOND;
|
|
92169
92156
|
var WALLET_PENDING_TRANSFER_STALE_RETRY_MS = 2 * MINUTE_MS;
|
|
92170
92157
|
var WALLET_PENDING_TRANSFER_STUCK_RETRY_MS = 10 * MINUTE_MS;
|
|
92158
|
+
var WALLET_TRANSFER_CACHE_WRITE_DELAY_MS = 3 * MS_PER_SECOND;
|
|
92171
92159
|
|
|
92172
92160
|
// ../../shared/chat/filepayload.js
|
|
92173
92161
|
"use client";
|
|
@@ -92295,8 +92283,8 @@ var CHAT_RETENTION_LABELS = Object.freeze({
|
|
|
92295
92283
|
[CHAT_RETENTION_SEEN]: "delete after seen",
|
|
92296
92284
|
[CHAT_RETENTION_24H]: "keep for 24h"
|
|
92297
92285
|
});
|
|
92298
|
-
var
|
|
92299
|
-
var
|
|
92286
|
+
var MESSAGE_STORAGE_TTL_MS = CHAT_UNSAVED_TTL_MS;
|
|
92287
|
+
var AFTER_SEEN_MS = CHAT_AFTER_SEEN_MS;
|
|
92300
92288
|
function hasChatRetention(value) {
|
|
92301
92289
|
const retention = cleanText(value);
|
|
92302
92290
|
return CHAT_RETENTION_VALUES.includes(retention);
|
|
@@ -92332,16 +92320,14 @@ function isTtlExpired(value, now = Date.now()) {
|
|
|
92332
92320
|
const ms = ttlMillis(value);
|
|
92333
92321
|
return ms != null && ms <= now;
|
|
92334
92322
|
}
|
|
92335
|
-
function
|
|
92336
|
-
|
|
92337
|
-
case CHAT_RETENTION_SEEN:
|
|
92338
|
-
case CHAT_RETENTION_24H:
|
|
92339
|
-
default:
|
|
92340
|
-
return now + DEFAULT_MESSAGE_TTL_MS;
|
|
92341
|
-
}
|
|
92323
|
+
function newMessageStorageTtlMs(now = Date.now()) {
|
|
92324
|
+
return now + MESSAGE_STORAGE_TTL_MS;
|
|
92342
92325
|
}
|
|
92343
|
-
function
|
|
92344
|
-
|
|
92326
|
+
function messageExpiryMs(retention, seenAt) {
|
|
92327
|
+
if (!Number.isFinite(seenAt)) {
|
|
92328
|
+
return null;
|
|
92329
|
+
}
|
|
92330
|
+
return cleanChatRetention(retention) === CHAT_RETENTION_24H ? seenAt + AFTER_SEEN_MS : seenAt;
|
|
92345
92331
|
}
|
|
92346
92332
|
|
|
92347
92333
|
// ../../shared/links.js
|
|
@@ -92567,7 +92553,6 @@ function targetMessageMs(target, byKey) {
|
|
|
92567
92553
|
}
|
|
92568
92554
|
|
|
92569
92555
|
// ../../shared/chat/messages/control.js
|
|
92570
|
-
var retainedMessageCache = new WeakMap;
|
|
92571
92556
|
function cleanReactionEmoji(value) {
|
|
92572
92557
|
const emoji = cleanText(value);
|
|
92573
92558
|
return emoji || DEFAULT_REACTION_EMOJI;
|
|
@@ -92590,13 +92575,6 @@ function isPeerMsg(msg, chatPK) {
|
|
|
92590
92575
|
function isServerConfirmedMsg(msg) {
|
|
92591
92576
|
return !!msg?.id && !String(msg.id).startsWith("local:") && !msg.pending && !msg.failed;
|
|
92592
92577
|
}
|
|
92593
|
-
function messageOrderMs(message) {
|
|
92594
|
-
const ms = getMessageOrderMs(message);
|
|
92595
|
-
return Number.isFinite(ms) ? ms : null;
|
|
92596
|
-
}
|
|
92597
|
-
function hasAnyMsgKey(msg, keys) {
|
|
92598
|
-
return messageHasKey(msg, keys);
|
|
92599
|
-
}
|
|
92600
92578
|
function makeReadReceipt(target) {
|
|
92601
92579
|
const upto = cleanTarget(target);
|
|
92602
92580
|
if (!upto) {
|
|
@@ -92698,236 +92676,6 @@ function canStoreMsg(msg) {
|
|
|
92698
92676
|
}
|
|
92699
92677
|
return canShowMsg(msg) || isControlMsg(msg) || isActionMutationMsg(msg);
|
|
92700
92678
|
}
|
|
92701
|
-
function needsRetentionProjection(messages) {
|
|
92702
|
-
for (const msg of messages || []) {
|
|
92703
|
-
if (isSystemMsg(msg) || isReadReceiptMsg(msg) || isHiddenCheckpointMsg(msg)) {
|
|
92704
|
-
return true;
|
|
92705
|
-
}
|
|
92706
|
-
}
|
|
92707
|
-
return false;
|
|
92708
|
-
}
|
|
92709
|
-
function receiptCoverageTarget(receipt, byKey) {
|
|
92710
|
-
const targetKey = cleanText(receipt?.upto);
|
|
92711
|
-
if (!targetKey) {
|
|
92712
|
-
return null;
|
|
92713
|
-
}
|
|
92714
|
-
const target = byKey.get(targetKey);
|
|
92715
|
-
const targetMs = messageOrderMs(target) ?? messageOrderMs({ cid: targetKey }) ?? messageOrderMs(receipt);
|
|
92716
|
-
const receiptMs = messageOrderMs(receipt);
|
|
92717
|
-
if (targetMs == null || receiptMs == null) {
|
|
92718
|
-
return null;
|
|
92719
|
-
}
|
|
92720
|
-
return {
|
|
92721
|
-
target,
|
|
92722
|
-
targetMs,
|
|
92723
|
-
receiptMs
|
|
92724
|
-
};
|
|
92725
|
-
}
|
|
92726
|
-
function makeReceiptCoverage(messages, byKey, chatPK, peerChatPK) {
|
|
92727
|
-
const peerMessageReceipts = [];
|
|
92728
|
-
const ownMessageReceipts = [];
|
|
92729
|
-
for (const msg of messages || []) {
|
|
92730
|
-
if (!isServerConfirmedMsg(msg) || !isReadReceiptMsg(msg)) {
|
|
92731
|
-
continue;
|
|
92732
|
-
}
|
|
92733
|
-
const coverage = receiptCoverageTarget(msg, byKey);
|
|
92734
|
-
if (!coverage) {
|
|
92735
|
-
continue;
|
|
92736
|
-
}
|
|
92737
|
-
const receiptFromPeer = isPeerMsg(msg, chatPK);
|
|
92738
|
-
if (receiptFromPeer) {
|
|
92739
|
-
if (peerChatPK && msg?.s !== peerChatPK) {
|
|
92740
|
-
continue;
|
|
92741
|
-
}
|
|
92742
|
-
if (coverage.target && isPeerMsg(coverage.target, chatPK)) {
|
|
92743
|
-
continue;
|
|
92744
|
-
}
|
|
92745
|
-
ownMessageReceipts.push(coverage);
|
|
92746
|
-
} else {
|
|
92747
|
-
if (coverage.target && !isPeerMsg(coverage.target, chatPK)) {
|
|
92748
|
-
continue;
|
|
92749
|
-
}
|
|
92750
|
-
peerMessageReceipts.push(coverage);
|
|
92751
|
-
}
|
|
92752
|
-
}
|
|
92753
|
-
peerMessageReceipts.sort((a, b) => b.targetMs - a.targetMs);
|
|
92754
|
-
ownMessageReceipts.sort((a, b) => b.targetMs - a.targetMs);
|
|
92755
|
-
return {
|
|
92756
|
-
peer: { receipts: peerMessageReceipts, index: 0, seenAt: null },
|
|
92757
|
-
own: { receipts: ownMessageReceipts, index: 0, seenAt: null }
|
|
92758
|
-
};
|
|
92759
|
-
}
|
|
92760
|
-
function receiptCoverageSeenAt(state, messageMs) {
|
|
92761
|
-
if (!state || messageMs == null) {
|
|
92762
|
-
return null;
|
|
92763
|
-
}
|
|
92764
|
-
while (state.index < state.receipts.length && state.receipts[state.index].targetMs >= messageMs) {
|
|
92765
|
-
const receiptMs = state.receipts[state.index].receiptMs;
|
|
92766
|
-
state.seenAt = state.seenAt == null ? receiptMs : Math.min(state.seenAt, receiptMs);
|
|
92767
|
-
state.index += 1;
|
|
92768
|
-
}
|
|
92769
|
-
return state.seenAt;
|
|
92770
|
-
}
|
|
92771
|
-
function hasRetentionControls(messages) {
|
|
92772
|
-
for (const msg of messages || []) {
|
|
92773
|
-
if (isServerConfirmedMsg(msg) && (isReadReceiptMsg(msg) || isHiddenCheckpointMsg(msg))) {
|
|
92774
|
-
return true;
|
|
92775
|
-
}
|
|
92776
|
-
}
|
|
92777
|
-
return false;
|
|
92778
|
-
}
|
|
92779
|
-
function hiddenCheckpointCoverageTarget(checkpoint, byKey) {
|
|
92780
|
-
const targetKey = cleanText(checkpoint?.upto);
|
|
92781
|
-
if (!targetKey) {
|
|
92782
|
-
return null;
|
|
92783
|
-
}
|
|
92784
|
-
const target = byKey.get(targetKey);
|
|
92785
|
-
const targetMs = targetMessageMs(targetKey, byKey);
|
|
92786
|
-
const targetFrom = cleanText(target?.s) || cleanText(target?.from) || cleanText(checkpoint?.targetFrom);
|
|
92787
|
-
if (targetMs == null || !targetFrom) {
|
|
92788
|
-
return null;
|
|
92789
|
-
}
|
|
92790
|
-
return { targetMs, targetFrom };
|
|
92791
|
-
}
|
|
92792
|
-
function makeHiddenCheckpointCoverage(messages, byKey, chatPK, peerChatPK) {
|
|
92793
|
-
const own = cleanText(chatPK);
|
|
92794
|
-
const peer = cleanText(peerChatPK);
|
|
92795
|
-
const coverage = { peerTargetMs: null, ownTargetMs: null };
|
|
92796
|
-
if (!own) {
|
|
92797
|
-
return coverage;
|
|
92798
|
-
}
|
|
92799
|
-
for (const msg of messages || []) {
|
|
92800
|
-
if (!isServerConfirmedMsg(msg) || !isHiddenCheckpointMsg(msg)) {
|
|
92801
|
-
continue;
|
|
92802
|
-
}
|
|
92803
|
-
const checkpointFrom = cleanText(msg?.s);
|
|
92804
|
-
if (checkpointFrom !== own && (!peer || checkpointFrom !== peer)) {
|
|
92805
|
-
continue;
|
|
92806
|
-
}
|
|
92807
|
-
const target = hiddenCheckpointCoverageTarget(msg, byKey);
|
|
92808
|
-
if (!target) {
|
|
92809
|
-
continue;
|
|
92810
|
-
}
|
|
92811
|
-
const targetFrom = target.targetFrom;
|
|
92812
|
-
if (targetFrom === own) {
|
|
92813
|
-
coverage.ownTargetMs = coverage.ownTargetMs == null ? target.targetMs : Math.max(coverage.ownTargetMs, target.targetMs);
|
|
92814
|
-
} else if (!peer || targetFrom === peer) {
|
|
92815
|
-
coverage.peerTargetMs = coverage.peerTargetMs == null ? target.targetMs : Math.max(coverage.peerTargetMs, target.targetMs);
|
|
92816
|
-
}
|
|
92817
|
-
}
|
|
92818
|
-
return coverage;
|
|
92819
|
-
}
|
|
92820
|
-
function canRetentionControlsHideMessages(messages, now) {
|
|
92821
|
-
let hasSeenRetention = false;
|
|
92822
|
-
let hasExpiredSeenWindow = false;
|
|
92823
|
-
let hasCheckpoint = false;
|
|
92824
|
-
for (const msg of messages || []) {
|
|
92825
|
-
if (isServerConfirmedMsg(msg) && isReadReceiptMsg(msg)) {
|
|
92826
|
-
const ms = messageOrderMs(msg);
|
|
92827
|
-
if (ms != null && seenMessageTtlMs(ms) <= now) {
|
|
92828
|
-
hasExpiredSeenWindow = true;
|
|
92829
|
-
}
|
|
92830
|
-
continue;
|
|
92831
|
-
}
|
|
92832
|
-
if (isServerConfirmedMsg(msg) && isHiddenCheckpointMsg(msg)) {
|
|
92833
|
-
hasCheckpoint = true;
|
|
92834
|
-
continue;
|
|
92835
|
-
}
|
|
92836
|
-
if (getMessageRetention(msg) === CHAT_RETENTION_SEEN) {
|
|
92837
|
-
hasSeenRetention = true;
|
|
92838
|
-
}
|
|
92839
|
-
if (hasSeenRetention && (hasExpiredSeenWindow || hasCheckpoint)) {
|
|
92840
|
-
return true;
|
|
92841
|
-
}
|
|
92842
|
-
}
|
|
92843
|
-
return hasSeenRetention || hasExpiredSeenWindow || hasCheckpoint;
|
|
92844
|
-
}
|
|
92845
|
-
function collectSeenHiddenMessages(messages, chatPK, peerChatPK, options = {}) {
|
|
92846
|
-
if (!Array.isArray(messages) || !messages.length || !chatPK) {
|
|
92847
|
-
return { hidden: [], nextMs: null };
|
|
92848
|
-
}
|
|
92849
|
-
if (!hasRetentionControls(messages)) {
|
|
92850
|
-
return { hidden: [], nextMs: null };
|
|
92851
|
-
}
|
|
92852
|
-
const keepKeys = options?.keepKeys instanceof Set ? options.keepKeys : new Set(Array.isArray(options?.keepKeys) ? options.keepKeys.filter(Boolean) : []);
|
|
92853
|
-
const now = Number.isFinite(options?.now) ? options.now : Date.now();
|
|
92854
|
-
if (options?.next !== true && !canRetentionControlsHideMessages(messages, now)) {
|
|
92855
|
-
return { hidden: [], nextMs: null };
|
|
92856
|
-
}
|
|
92857
|
-
const byKey = indexMessagesByKey(messages, { keep: "last" });
|
|
92858
|
-
const coverage = makeReceiptCoverage(messages, byKey, chatPK, peerChatPK);
|
|
92859
|
-
const checkpointCoverage = makeHiddenCheckpointCoverage(messages, byKey, chatPK, peerChatPK);
|
|
92860
|
-
if (!coverage.peer.receipts.length && !coverage.own.receipts.length && checkpointCoverage.peerTargetMs == null && checkpointCoverage.ownTargetMs == null) {
|
|
92861
|
-
return { hidden: [], nextMs: null };
|
|
92862
|
-
}
|
|
92863
|
-
const hidden = [];
|
|
92864
|
-
let nextMs = null;
|
|
92865
|
-
const candidates = [];
|
|
92866
|
-
for (const msg of messages) {
|
|
92867
|
-
if (!hasAnyMsgKey(msg, keepKeys) && isServerConfirmedMsg(msg) && !isControlMsg(msg) && !isSystemMsg(msg) && canShowMsg(msg) && msg.ttl != null) {
|
|
92868
|
-
const ms = messageOrderMs(msg);
|
|
92869
|
-
if (ms != null) {
|
|
92870
|
-
candidates.push({ msg, ms, fromPeer: isPeerMsg(msg, chatPK) });
|
|
92871
|
-
}
|
|
92872
|
-
}
|
|
92873
|
-
}
|
|
92874
|
-
candidates.sort((a, b) => b.ms - a.ms);
|
|
92875
|
-
for (const candidate of candidates) {
|
|
92876
|
-
const retention = getMessageRetention(candidate.msg);
|
|
92877
|
-
const checkpointTargetMs = candidate.fromPeer ? checkpointCoverage.peerTargetMs : checkpointCoverage.ownTargetMs;
|
|
92878
|
-
if (options?.hideSeen !== false && retention === CHAT_RETENTION_SEEN && checkpointTargetMs != null && candidate.ms <= checkpointTargetMs) {
|
|
92879
|
-
hidden.push(candidate.msg);
|
|
92880
|
-
continue;
|
|
92881
|
-
}
|
|
92882
|
-
const seenAt = receiptCoverageSeenAt(candidate.fromPeer ? coverage.peer : coverage.own, candidate.ms);
|
|
92883
|
-
if (seenAt == null) {
|
|
92884
|
-
continue;
|
|
92885
|
-
}
|
|
92886
|
-
if (retention === CHAT_RETENTION_SEEN) {
|
|
92887
|
-
if (options?.hideSeen !== false) {
|
|
92888
|
-
hidden.push(candidate.msg);
|
|
92889
|
-
}
|
|
92890
|
-
continue;
|
|
92891
|
-
}
|
|
92892
|
-
const hideAt = seenMessageTtlMs(seenAt);
|
|
92893
|
-
if (hideAt <= now) {
|
|
92894
|
-
hidden.push(candidate.msg);
|
|
92895
|
-
} else if (nextMs == null || hideAt < nextMs) {
|
|
92896
|
-
nextMs = hideAt;
|
|
92897
|
-
}
|
|
92898
|
-
}
|
|
92899
|
-
return { hidden, nextMs };
|
|
92900
|
-
}
|
|
92901
|
-
function filterSeenMessages(messages, chatPK, peerChatPK, options = {}) {
|
|
92902
|
-
const state = collectProjectedSeenHiddenState(messages, chatPK, peerChatPK, options);
|
|
92903
|
-
const projectedMessages = state.messages;
|
|
92904
|
-
const hidden = state.hidden;
|
|
92905
|
-
if (!hidden.length) {
|
|
92906
|
-
return projectedMessages;
|
|
92907
|
-
}
|
|
92908
|
-
const hiddenKeys = collectMessageKeys(hidden);
|
|
92909
|
-
return projectedMessages.filter((msg) => !hasAnyMsgKey(msg, hiddenKeys));
|
|
92910
|
-
}
|
|
92911
|
-
function getDisplayMessages(messages, chatPK, peerChatPK, options = {}) {
|
|
92912
|
-
return filterSeenMessages(messages, chatPK, peerChatPK, options);
|
|
92913
|
-
}
|
|
92914
|
-
function collectProjectedSeenHiddenState(messages, chatPK, peerChatPK, options = {}) {
|
|
92915
|
-
const actionMessages = applyMessageActions(messages);
|
|
92916
|
-
if (!needsRetentionProjection(actionMessages)) {
|
|
92917
|
-
return {
|
|
92918
|
-
messages: actionMessages || [],
|
|
92919
|
-
hidden: [],
|
|
92920
|
-
nextMs: null
|
|
92921
|
-
};
|
|
92922
|
-
}
|
|
92923
|
-
const projectedMessages = applyMessageRetentionTimeline(actionMessages, options.fallback);
|
|
92924
|
-
const state = collectSeenHiddenMessages(projectedMessages, chatPK, peerChatPK, options);
|
|
92925
|
-
return {
|
|
92926
|
-
messages: projectedMessages,
|
|
92927
|
-
hidden: state.hidden,
|
|
92928
|
-
nextMs: state.nextMs
|
|
92929
|
-
};
|
|
92930
|
-
}
|
|
92931
92679
|
function actionTarget(msg) {
|
|
92932
92680
|
return cleanText(msg?.actionTarget) || cleanText(msg?.target) || cleanText(msg?.id);
|
|
92933
92681
|
}
|
|
@@ -92943,7 +92691,7 @@ function actionPatch(msg) {
|
|
|
92943
92691
|
actionId,
|
|
92944
92692
|
actionOp,
|
|
92945
92693
|
actionTarget: actionTarget2,
|
|
92946
|
-
|
|
92694
|
+
signingPublicKey,
|
|
92947
92695
|
target,
|
|
92948
92696
|
...payload
|
|
92949
92697
|
} = msg || {};
|
|
@@ -93031,53 +92779,241 @@ function applyMessageActions(messages) {
|
|
|
93031
92779
|
}
|
|
93032
92780
|
return out.filter(Boolean);
|
|
93033
92781
|
}
|
|
92782
|
+
|
|
92783
|
+
// ../../shared/chat/messages/expiry.js
|
|
92784
|
+
var retainedMessageCache = new WeakMap;
|
|
92785
|
+
function messageOrderMs(message) {
|
|
92786
|
+
const ms = getMessageOrderMs(message);
|
|
92787
|
+
return Number.isFinite(ms) ? ms : null;
|
|
92788
|
+
}
|
|
92789
|
+
function hasExpiryControls(messages) {
|
|
92790
|
+
return (messages || []).some((message) => isServerConfirmedMsg(message) && (isReadReceiptMsg(message) || isHiddenCheckpointMsg(message)));
|
|
92791
|
+
}
|
|
92792
|
+
function needsRetentionTimeline(messages) {
|
|
92793
|
+
return (messages || []).some(isSystemMsg);
|
|
92794
|
+
}
|
|
92795
|
+
function withCachedRetention(message, retention) {
|
|
92796
|
+
const nextRetention = cleanChatRetention(retention);
|
|
92797
|
+
if (message.retention === nextRetention) {
|
|
92798
|
+
return message;
|
|
92799
|
+
}
|
|
92800
|
+
let byRetention = retainedMessageCache.get(message);
|
|
92801
|
+
if (!byRetention) {
|
|
92802
|
+
byRetention = new Map;
|
|
92803
|
+
retainedMessageCache.set(message, byRetention);
|
|
92804
|
+
}
|
|
92805
|
+
const cached = byRetention.get(nextRetention);
|
|
92806
|
+
if (cached) {
|
|
92807
|
+
return cached;
|
|
92808
|
+
}
|
|
92809
|
+
const next = { ...message, retention: nextRetention };
|
|
92810
|
+
byRetention.set(nextRetention, next);
|
|
92811
|
+
return next;
|
|
92812
|
+
}
|
|
93034
92813
|
function applyMessageRetentionTimeline(messages, fallback = DEFAULT_CHAT_RETENTION) {
|
|
93035
92814
|
if (!Array.isArray(messages) || !messages.length) {
|
|
93036
92815
|
return messages || [];
|
|
93037
92816
|
}
|
|
93038
92817
|
let retention = cleanChatRetention(fallback);
|
|
93039
|
-
let timelineActive = false;
|
|
93040
92818
|
let changed = false;
|
|
93041
|
-
const next = messages.map((
|
|
93042
|
-
if (!
|
|
93043
|
-
return
|
|
93044
|
-
}
|
|
93045
|
-
if (isSystemMsg(msg)) {
|
|
93046
|
-
retention = cleanChatRetention(msg.retention);
|
|
93047
|
-
timelineActive = true;
|
|
93048
|
-
return msg;
|
|
92819
|
+
const next = messages.map((message) => {
|
|
92820
|
+
if (!message || typeof message !== "object" || Array.isArray(message)) {
|
|
92821
|
+
return message;
|
|
93049
92822
|
}
|
|
93050
|
-
if (
|
|
93051
|
-
|
|
92823
|
+
if (isSystemMsg(message)) {
|
|
92824
|
+
retention = cleanChatRetention(message.retention);
|
|
92825
|
+
return message;
|
|
93052
92826
|
}
|
|
93053
|
-
if (hasChatRetention(
|
|
93054
|
-
return
|
|
92827
|
+
if (isControlMsg(message) || !canShowMsg(message) || hasChatRetention(message.retention)) {
|
|
92828
|
+
return message;
|
|
93055
92829
|
}
|
|
93056
|
-
const
|
|
93057
|
-
if (
|
|
92830
|
+
const retained = withCachedRetention(message, retention);
|
|
92831
|
+
if (retained !== message) {
|
|
93058
92832
|
changed = true;
|
|
93059
92833
|
}
|
|
93060
|
-
return
|
|
92834
|
+
return retained;
|
|
93061
92835
|
});
|
|
93062
92836
|
return changed ? next : messages;
|
|
93063
92837
|
}
|
|
93064
|
-
function
|
|
93065
|
-
const
|
|
93066
|
-
if (
|
|
93067
|
-
return
|
|
92838
|
+
function receiptTarget(receipt, byKey) {
|
|
92839
|
+
const targetKey = cleanText(receipt?.upto);
|
|
92840
|
+
if (!targetKey) {
|
|
92841
|
+
return null;
|
|
93068
92842
|
}
|
|
93069
|
-
|
|
93070
|
-
|
|
93071
|
-
|
|
93072
|
-
|
|
92843
|
+
const target = byKey.get(targetKey);
|
|
92844
|
+
const targetMs = messageOrderMs(target) ?? messageOrderMs({ cid: targetKey }) ?? messageOrderMs(receipt);
|
|
92845
|
+
const seenAt = messageOrderMs(receipt);
|
|
92846
|
+
const receiptKey = getMessageKey(receipt);
|
|
92847
|
+
return targetMs == null || seenAt == null || !receiptKey ? null : { receiptKey, target, targetMs, seenAt };
|
|
92848
|
+
}
|
|
92849
|
+
function makeReceiptCoverage(messages, byKey, selfChatPublicKey, peerChatPublicKey) {
|
|
92850
|
+
const peerMessages = [];
|
|
92851
|
+
const ownMessages = [];
|
|
92852
|
+
for (const message of messages || []) {
|
|
92853
|
+
if (!isServerConfirmedMsg(message) || !isReadReceiptMsg(message)) {
|
|
92854
|
+
continue;
|
|
92855
|
+
}
|
|
92856
|
+
const receipt = receiptTarget(message, byKey);
|
|
92857
|
+
if (!receipt) {
|
|
92858
|
+
continue;
|
|
92859
|
+
}
|
|
92860
|
+
if (isPeerMsg(message, selfChatPublicKey)) {
|
|
92861
|
+
if (peerChatPublicKey && message.s !== peerChatPublicKey || receipt.target && isPeerMsg(receipt.target, selfChatPublicKey)) {
|
|
92862
|
+
continue;
|
|
92863
|
+
}
|
|
92864
|
+
ownMessages.push(receipt);
|
|
92865
|
+
} else {
|
|
92866
|
+
if (receipt.target && !isPeerMsg(receipt.target, selfChatPublicKey)) {
|
|
92867
|
+
continue;
|
|
92868
|
+
}
|
|
92869
|
+
peerMessages.push(receipt);
|
|
92870
|
+
}
|
|
93073
92871
|
}
|
|
93074
|
-
|
|
93075
|
-
|
|
93076
|
-
|
|
92872
|
+
peerMessages.sort((left, right) => right.targetMs - left.targetMs || left.seenAt - right.seenAt);
|
|
92873
|
+
ownMessages.sort((left, right) => right.targetMs - left.targetMs || left.seenAt - right.seenAt);
|
|
92874
|
+
return {
|
|
92875
|
+
peer: { items: peerMessages, index: 0, current: null },
|
|
92876
|
+
own: { items: ownMessages, index: 0, current: null }
|
|
92877
|
+
};
|
|
92878
|
+
}
|
|
92879
|
+
function coveringReceipt(state, messageMs) {
|
|
92880
|
+
while (state && state.index < state.items.length && state.items[state.index].targetMs >= messageMs) {
|
|
92881
|
+
const next = state.items[state.index];
|
|
92882
|
+
if (!state.current || next.seenAt < state.current.seenAt) {
|
|
92883
|
+
state.current = next;
|
|
92884
|
+
}
|
|
92885
|
+
state.index += 1;
|
|
93077
92886
|
}
|
|
93078
|
-
|
|
93079
|
-
|
|
93080
|
-
|
|
92887
|
+
return state?.current ?? null;
|
|
92888
|
+
}
|
|
92889
|
+
function checkpointTarget(checkpoint, byKey) {
|
|
92890
|
+
const targetKey = cleanText(checkpoint?.upto);
|
|
92891
|
+
if (!targetKey) {
|
|
92892
|
+
return null;
|
|
92893
|
+
}
|
|
92894
|
+
const target = byKey.get(targetKey);
|
|
92895
|
+
const targetMs = targetMessageMs(targetKey, byKey);
|
|
92896
|
+
const targetFrom = cleanText(target?.s) || cleanText(target?.from) || cleanText(checkpoint?.targetFrom);
|
|
92897
|
+
const hiddenAt = messageOrderMs(checkpoint);
|
|
92898
|
+
return targetMs == null || !targetFrom || hiddenAt == null ? null : { targetMs, targetFrom, hiddenAt };
|
|
92899
|
+
}
|
|
92900
|
+
function makeCheckpointCoverage(messages, byKey, selfChatPublicKey, peerChatPublicKey) {
|
|
92901
|
+
const peerMessages = [];
|
|
92902
|
+
const ownMessages = [];
|
|
92903
|
+
const self2 = cleanText(selfChatPublicKey);
|
|
92904
|
+
const peer = cleanText(peerChatPublicKey);
|
|
92905
|
+
for (const message of messages || []) {
|
|
92906
|
+
if (!isServerConfirmedMsg(message) || !isHiddenCheckpointMsg(message)) {
|
|
92907
|
+
continue;
|
|
92908
|
+
}
|
|
92909
|
+
const checkpointFrom = cleanText(message.s);
|
|
92910
|
+
if (checkpointFrom !== self2 && (!peer || checkpointFrom !== peer)) {
|
|
92911
|
+
continue;
|
|
92912
|
+
}
|
|
92913
|
+
const checkpoint = checkpointTarget(message, byKey);
|
|
92914
|
+
if (!checkpoint) {
|
|
92915
|
+
continue;
|
|
92916
|
+
}
|
|
92917
|
+
if (checkpoint.targetFrom === self2) {
|
|
92918
|
+
ownMessages.push(checkpoint);
|
|
92919
|
+
} else if (!peer || checkpoint.targetFrom === peer) {
|
|
92920
|
+
peerMessages.push(checkpoint);
|
|
92921
|
+
}
|
|
92922
|
+
}
|
|
92923
|
+
peerMessages.sort((left, right) => right.targetMs - left.targetMs || left.hiddenAt - right.hiddenAt);
|
|
92924
|
+
ownMessages.sort((left, right) => right.targetMs - left.targetMs || left.hiddenAt - right.hiddenAt);
|
|
92925
|
+
return {
|
|
92926
|
+
peer: { items: peerMessages, index: 0, current: null },
|
|
92927
|
+
own: { items: ownMessages, index: 0, current: null }
|
|
92928
|
+
};
|
|
92929
|
+
}
|
|
92930
|
+
function coveringCheckpoint(state, messageMs) {
|
|
92931
|
+
while (state && state.index < state.items.length && state.items[state.index].targetMs >= messageMs) {
|
|
92932
|
+
const next = state.items[state.index];
|
|
92933
|
+
if (!state.current || next.targetMs > state.current.targetMs || next.targetMs === state.current.targetMs && next.hiddenAt < state.current.hiddenAt) {
|
|
92934
|
+
state.current = next;
|
|
92935
|
+
}
|
|
92936
|
+
state.index += 1;
|
|
92937
|
+
}
|
|
92938
|
+
return state?.current ?? null;
|
|
92939
|
+
}
|
|
92940
|
+
function heldKeys(value) {
|
|
92941
|
+
if (value instanceof Set) {
|
|
92942
|
+
return value;
|
|
92943
|
+
}
|
|
92944
|
+
return new Set(Array.isArray(value) ? value.filter(Boolean) : []);
|
|
92945
|
+
}
|
|
92946
|
+
function analyzeMessageExpiry(messages, selfChatPublicKey, peerChatPublicKey, options = {}) {
|
|
92947
|
+
const actionMessages = applyMessageActions(messages);
|
|
92948
|
+
const projectedMessages = needsRetentionTimeline(actionMessages) ? applyMessageRetentionTimeline(actionMessages, options.fallback) : actionMessages || [];
|
|
92949
|
+
if (!projectedMessages.length || !selfChatPublicKey || !hasExpiryControls(projectedMessages)) {
|
|
92950
|
+
return {
|
|
92951
|
+
messages: projectedMessages,
|
|
92952
|
+
visible: projectedMessages,
|
|
92953
|
+
expired: [],
|
|
92954
|
+
heldExpired: [],
|
|
92955
|
+
nextExpiryAt: null,
|
|
92956
|
+
requiredReceiptKeys: new Set
|
|
92957
|
+
};
|
|
92958
|
+
}
|
|
92959
|
+
const byKey = indexMessagesByKey(projectedMessages, { keep: "last" });
|
|
92960
|
+
const receipts = makeReceiptCoverage(projectedMessages, byKey, selfChatPublicKey, peerChatPublicKey);
|
|
92961
|
+
const checkpoints = makeCheckpointCoverage(projectedMessages, byKey, selfChatPublicKey, peerChatPublicKey);
|
|
92962
|
+
const keepKeys = heldKeys(options.keepKeys);
|
|
92963
|
+
const now = Number.isFinite(options.now) ? options.now : Date.now();
|
|
92964
|
+
const candidates = [];
|
|
92965
|
+
for (const message of projectedMessages) {
|
|
92966
|
+
if (!isServerConfirmedMsg(message) || isControlMsg(message) || isSystemMsg(message) || !canShowMsg(message) || message.ttl == null) {
|
|
92967
|
+
continue;
|
|
92968
|
+
}
|
|
92969
|
+
const orderMs = messageOrderMs(message);
|
|
92970
|
+
if (orderMs != null) {
|
|
92971
|
+
candidates.push({ message, orderMs, fromPeer: isPeerMsg(message, selfChatPublicKey) });
|
|
92972
|
+
}
|
|
92973
|
+
}
|
|
92974
|
+
candidates.sort((left, right) => right.orderMs - left.orderMs);
|
|
92975
|
+
const expired = [];
|
|
92976
|
+
const heldExpired = [];
|
|
92977
|
+
const requiredReceiptKeys = new Set;
|
|
92978
|
+
let nextExpiryAt = null;
|
|
92979
|
+
for (const candidate of candidates) {
|
|
92980
|
+
const direction = candidate.fromPeer ? "peer" : "own";
|
|
92981
|
+
const receipt = coveringReceipt(receipts[direction], candidate.orderMs);
|
|
92982
|
+
const checkpoint = coveringCheckpoint(checkpoints[direction], candidate.orderMs);
|
|
92983
|
+
const retention = getMessageRetention(candidate.message);
|
|
92984
|
+
const seenAt = retention === CHAT_RETENTION_SEEN ? receipt?.seenAt ?? checkpoint?.hiddenAt ?? null : receipt?.seenAt ?? null;
|
|
92985
|
+
if (retention !== CHAT_RETENTION_SEEN && receipt) {
|
|
92986
|
+
requiredReceiptKeys.add(receipt.receiptKey);
|
|
92987
|
+
}
|
|
92988
|
+
const expiresAt = messageExpiryMs(retention, seenAt);
|
|
92989
|
+
if (expiresAt == null) {
|
|
92990
|
+
continue;
|
|
92991
|
+
}
|
|
92992
|
+
if (expiresAt > now) {
|
|
92993
|
+
nextExpiryAt = nextExpiryAt == null ? expiresAt : Math.min(nextExpiryAt, expiresAt);
|
|
92994
|
+
continue;
|
|
92995
|
+
}
|
|
92996
|
+
if (messageHasKey(candidate.message, keepKeys)) {
|
|
92997
|
+
heldExpired.push(candidate.message);
|
|
92998
|
+
} else {
|
|
92999
|
+
expired.push(candidate.message);
|
|
93000
|
+
}
|
|
93001
|
+
}
|
|
93002
|
+
if (!expired.length) {
|
|
93003
|
+
return { messages: projectedMessages, visible: projectedMessages, expired, heldExpired, nextExpiryAt, requiredReceiptKeys };
|
|
93004
|
+
}
|
|
93005
|
+
const expiredKeys = collectMessageKeys(expired);
|
|
93006
|
+
return {
|
|
93007
|
+
messages: projectedMessages,
|
|
93008
|
+
visible: projectedMessages.filter((message) => !messageHasKey(message, expiredKeys)),
|
|
93009
|
+
expired,
|
|
93010
|
+
heldExpired,
|
|
93011
|
+
nextExpiryAt,
|
|
93012
|
+
requiredReceiptKeys
|
|
93013
|
+
};
|
|
93014
|
+
}
|
|
93015
|
+
function getDisplayMessages(messages, selfChatPublicKey, peerChatPublicKey, options = {}) {
|
|
93016
|
+
return analyzeMessageExpiry(messages, selfChatPublicKey, peerChatPublicKey, options).visible;
|
|
93081
93017
|
}
|
|
93082
93018
|
|
|
93083
93019
|
// ../../shared/chat/messages/compose.js
|
|
@@ -93428,21 +93364,21 @@ function markError(diag, label, startedAt, error, data = {}) {
|
|
|
93428
93364
|
|
|
93429
93365
|
// ../../shared/crypto/sign.js
|
|
93430
93366
|
"use client";
|
|
93431
|
-
var
|
|
93367
|
+
var CHAT_SIGNING_SCOPE = "chat-actor-sign-v2";
|
|
93432
93368
|
function orderKeys(a, b) {
|
|
93433
93369
|
if (!a || !b) {
|
|
93434
93370
|
throw new Error("chat keys required");
|
|
93435
93371
|
}
|
|
93436
93372
|
return a <= b ? [a, b] : [b, a];
|
|
93437
93373
|
}
|
|
93438
|
-
function
|
|
93374
|
+
function deriveChatSigningSecret(chatPrivKey, chatId, chatPK, peerChatPK) {
|
|
93439
93375
|
if (!chatPrivKey || !chatId || !chatPK || !peerChatPK) {
|
|
93440
|
-
throw new Error("chat
|
|
93376
|
+
throw new Error("chat signing key material required");
|
|
93441
93377
|
}
|
|
93442
|
-
return deriveKey2(toBytes(chatPrivKey, "chat private key"),
|
|
93378
|
+
return deriveKey2(toBytes(chatPrivKey, "chat private key"), CHAT_SIGNING_SCOPE, [chatId, ...orderKeys(chatPK, peerChatPK)]);
|
|
93443
93379
|
}
|
|
93444
|
-
function
|
|
93445
|
-
const secret =
|
|
93380
|
+
function getChatSigningKey(chatPrivKey, chatId, chatPK, peerChatPK) {
|
|
93381
|
+
const secret = deriveChatSigningSecret(chatPrivKey, chatId, chatPK, peerChatPK);
|
|
93446
93382
|
try {
|
|
93447
93383
|
return {
|
|
93448
93384
|
secret,
|
|
@@ -93453,15 +93389,15 @@ function getChatActorKey(chatPrivKey, chatId, chatPK, peerChatPK) {
|
|
|
93453
93389
|
throw error;
|
|
93454
93390
|
}
|
|
93455
93391
|
}
|
|
93456
|
-
function signChatBytes(
|
|
93457
|
-
if (!
|
|
93458
|
-
throw new Error("chat
|
|
93392
|
+
function signChatBytes(signingKey, bytes) {
|
|
93393
|
+
if (!signingKey?.secret || !signingKey?.publicKey) {
|
|
93394
|
+
throw new Error("chat signing key required");
|
|
93459
93395
|
}
|
|
93460
|
-
return toHex(ed25519.sign(toBytes(bytes, "signing bytes"),
|
|
93396
|
+
return toHex(ed25519.sign(toBytes(bytes, "signing bytes"), signingKey.secret));
|
|
93461
93397
|
}
|
|
93462
93398
|
function verifyChatBytes(publicKey, sig, bytes) {
|
|
93463
93399
|
try {
|
|
93464
|
-
return ed25519.verify(fromHexBytes(sig, "chat signature"), toBytes(bytes, "signed bytes"), fromHex(publicKey, "chat
|
|
93400
|
+
return ed25519.verify(fromHexBytes(sig, "chat signature"), toBytes(bytes, "signed bytes"), fromHex(publicKey, "chat signing public key"));
|
|
93465
93401
|
} catch {
|
|
93466
93402
|
return false;
|
|
93467
93403
|
}
|
|
@@ -93503,12 +93439,12 @@ async function openPair(chatPK, chatPrivKey, peerChatPK, options = {}) {
|
|
|
93503
93439
|
const linkRoot = deriveKey2(secret, "chat-link-root-v1", orderedKeys);
|
|
93504
93440
|
const root = chatId ? deriveKey2(secret, "chat-root-v2", [chatId, ...orderedKeys]) : null;
|
|
93505
93441
|
const bodyKey = root ? deriveKey2(root, "chat-msg-body-key-v2") : null;
|
|
93506
|
-
const
|
|
93442
|
+
const signingKey = chatId ? getChatSigningKey(privKeyBytes, chatId, chatPK, peerChatPK) : null;
|
|
93507
93443
|
cleanBytes(sharedSecret);
|
|
93508
|
-
return { linkId, chatId, chatPK, peerChatPK, linkRoot, root, bodyKey,
|
|
93444
|
+
return { linkId, chatId, chatPK, peerChatPK, linkRoot, root, bodyKey, signingKey };
|
|
93509
93445
|
}
|
|
93510
93446
|
function closePair(pair) {
|
|
93511
|
-
cleanBytes(pair?.linkRoot, pair?.root, pair?.bodyKey, pair?.
|
|
93447
|
+
cleanBytes(pair?.linkRoot, pair?.root, pair?.bodyKey, pair?.signingKey?.secret);
|
|
93512
93448
|
}
|
|
93513
93449
|
function getPairAad(pair, scope, ...parts) {
|
|
93514
93450
|
if (!pair?.chatId) {
|
|
@@ -93579,7 +93515,7 @@ function normalizePlainPayload(payload) {
|
|
|
93579
93515
|
return payload;
|
|
93580
93516
|
}
|
|
93581
93517
|
function makeMsgAction(pair, head, message, options = {}) {
|
|
93582
|
-
if (!pair?.chatId || !pair?.
|
|
93518
|
+
if (!pair?.chatId || !pair?.signingKey?.publicKey) {
|
|
93583
93519
|
throw new Error("chat action pair required");
|
|
93584
93520
|
}
|
|
93585
93521
|
const payload = getPayload(message);
|
|
@@ -93590,7 +93526,7 @@ function makeMsgAction(pair, head, message, options = {}) {
|
|
|
93590
93526
|
id: cleanText(options?.id) || head.cid,
|
|
93591
93527
|
...target ? { target } : {},
|
|
93592
93528
|
s: pair.chatPK,
|
|
93593
|
-
actor: pair.
|
|
93529
|
+
actor: pair.signingKey.publicKey,
|
|
93594
93530
|
ts: Number.isFinite(options?.ts) ? options.ts : Date.now(),
|
|
93595
93531
|
p: payload
|
|
93596
93532
|
};
|
|
@@ -93643,12 +93579,12 @@ function unpackMsgBody(body) {
|
|
|
93643
93579
|
ct: bytes.subarray(MSG_BODY_HEADER_BYTES)
|
|
93644
93580
|
};
|
|
93645
93581
|
}
|
|
93646
|
-
function
|
|
93582
|
+
function expectedSigningKeyForSender(pair, sender, signingKeysByChatKey) {
|
|
93647
93583
|
if (sender === pair?.chatPK) {
|
|
93648
|
-
return cleanText(pair?.
|
|
93584
|
+
return cleanText(pair?.signingKey?.publicKey);
|
|
93649
93585
|
}
|
|
93650
|
-
if (sender === pair?.peerChatPK &&
|
|
93651
|
-
return cleanText(
|
|
93586
|
+
if (sender === pair?.peerChatPK && signingKeysByChatKey && typeof signingKeysByChatKey === "object" && !Array.isArray(signingKeysByChatKey)) {
|
|
93587
|
+
return cleanText(signingKeysByChatKey[sender]);
|
|
93652
93588
|
}
|
|
93653
93589
|
return "";
|
|
93654
93590
|
}
|
|
@@ -93665,17 +93601,17 @@ function normalizeOpenedAction(pair, head, action, options = {}) {
|
|
|
93665
93601
|
if (sender !== pair.chatPK && sender !== pair.peerChatPK) {
|
|
93666
93602
|
throw new Error("chat action sender mismatch");
|
|
93667
93603
|
}
|
|
93668
|
-
const
|
|
93669
|
-
const
|
|
93670
|
-
if (!
|
|
93671
|
-
throw new Error("chat action
|
|
93604
|
+
const signingPublicKey = cleanText(action.actor);
|
|
93605
|
+
const expectedSigningPublicKey = expectedSigningKeyForSender(pair, sender, options?.signingKeysByChatKey);
|
|
93606
|
+
if (!expectedSigningPublicKey || signingPublicKey !== expectedSigningPublicKey) {
|
|
93607
|
+
throw new Error("chat action signer mismatch");
|
|
93672
93608
|
}
|
|
93673
93609
|
return {
|
|
93674
93610
|
op,
|
|
93675
93611
|
id,
|
|
93676
93612
|
target: cleanText(action.target),
|
|
93677
93613
|
sender,
|
|
93678
|
-
|
|
93614
|
+
signingPublicKey,
|
|
93679
93615
|
ts: cleanActionTimestamp(action.ts),
|
|
93680
93616
|
payload: normalizePlainPayload(action.p)
|
|
93681
93617
|
};
|
|
@@ -93688,7 +93624,7 @@ async function sealMsgBody(pair, head, action) {
|
|
|
93688
93624
|
const body = encoder.encode(JSON.stringify(action));
|
|
93689
93625
|
try {
|
|
93690
93626
|
const { nonce, ct } = await sealBox(pair.bodyKey, body, aad);
|
|
93691
|
-
const sig = signChatBytes(pair.
|
|
93627
|
+
const sig = signChatBytes(pair.signingKey, getSignatureInput(aad, nonce, ct));
|
|
93692
93628
|
return packMsgBody({ nonce, sig, ct });
|
|
93693
93629
|
} finally {
|
|
93694
93630
|
cleanBytes(body);
|
|
@@ -93704,31 +93640,31 @@ async function openMsgPlaintext(pair, nonce, ct, aad, options = {}) {
|
|
|
93704
93640
|
}
|
|
93705
93641
|
return openBox(pair.bodyKey, nonce, ct, aad);
|
|
93706
93642
|
}
|
|
93707
|
-
async function verifyMsgSignature(
|
|
93643
|
+
async function verifyMsgSignature(signingPublicKey, sig, bytes, options = {}) {
|
|
93708
93644
|
const crypto3 = options?.crypto;
|
|
93709
93645
|
if (typeof crypto3?.isAvailable === "function" && !crypto3.isAvailable()) {
|
|
93710
|
-
return verifyChatBytes(
|
|
93646
|
+
return verifyChatBytes(signingPublicKey, toHex(sig), bytes);
|
|
93711
93647
|
}
|
|
93712
93648
|
if (typeof crypto3?.verifyChatBytes === "function") {
|
|
93713
|
-
return crypto3.verifyChatBytes(
|
|
93649
|
+
return crypto3.verifyChatBytes(signingPublicKey, sig, bytes);
|
|
93714
93650
|
}
|
|
93715
|
-
return verifyChatBytes(
|
|
93651
|
+
return verifyChatBytes(signingPublicKey, toHex(sig), bytes);
|
|
93716
93652
|
}
|
|
93717
|
-
function
|
|
93653
|
+
function expectedSigningKeys(pair, signingKeysByChatKey) {
|
|
93718
93654
|
const values = [];
|
|
93719
93655
|
const seen = new Set;
|
|
93720
93656
|
const add3 = (value) => {
|
|
93721
|
-
const
|
|
93722
|
-
if (!
|
|
93657
|
+
const signingPublicKey = cleanText(value);
|
|
93658
|
+
if (!signingPublicKey || seen.has(signingPublicKey)) {
|
|
93723
93659
|
return;
|
|
93724
93660
|
}
|
|
93725
|
-
seen.add(
|
|
93726
|
-
values.push(
|
|
93661
|
+
seen.add(signingPublicKey);
|
|
93662
|
+
values.push(signingPublicKey);
|
|
93727
93663
|
};
|
|
93728
|
-
add3(pair?.
|
|
93729
|
-
if (
|
|
93730
|
-
add3(
|
|
93731
|
-
add3(
|
|
93664
|
+
add3(pair?.signingKey?.publicKey);
|
|
93665
|
+
if (signingKeysByChatKey && typeof signingKeysByChatKey === "object" && !Array.isArray(signingKeysByChatKey)) {
|
|
93666
|
+
add3(signingKeysByChatKey[pair?.chatPK]);
|
|
93667
|
+
add3(signingKeysByChatKey[pair?.peerChatPK]);
|
|
93732
93668
|
}
|
|
93733
93669
|
return values;
|
|
93734
93670
|
}
|
|
@@ -93736,12 +93672,12 @@ async function verifyExpectedSignatureBeforeOpen(pair, sig, bytes, options = {})
|
|
|
93736
93672
|
if (!options?.crypto?.preverifyBeforeOpen) {
|
|
93737
93673
|
return true;
|
|
93738
93674
|
}
|
|
93739
|
-
const
|
|
93740
|
-
if (
|
|
93675
|
+
const signingKeysByChatKey = expectedSigningKeys(pair, options?.signingKeysByChatKey);
|
|
93676
|
+
if (signingKeysByChatKey.length < 2) {
|
|
93741
93677
|
return true;
|
|
93742
93678
|
}
|
|
93743
|
-
for (const
|
|
93744
|
-
if (await verifyMsgSignature(
|
|
93679
|
+
for (const signingPublicKey of signingKeysByChatKey) {
|
|
93680
|
+
if (await verifyMsgSignature(signingPublicKey, sig, bytes, options)) {
|
|
93745
93681
|
return true;
|
|
93746
93682
|
}
|
|
93747
93683
|
}
|
|
@@ -93773,7 +93709,7 @@ async function openMsg(pair, data, options = {}) {
|
|
|
93773
93709
|
try {
|
|
93774
93710
|
const action = JSON.parse(decoder.decode(plaintext));
|
|
93775
93711
|
const normalized = normalizeOpenedAction(pair, head, action, options);
|
|
93776
|
-
if (!await verifyMsgSignature(normalized.
|
|
93712
|
+
if (!await verifyMsgSignature(normalized.signingPublicKey, sig, signatureInput, options)) {
|
|
93777
93713
|
throw new Error("invalid chat action signature");
|
|
93778
93714
|
}
|
|
93779
93715
|
return {
|
|
@@ -93783,7 +93719,7 @@ async function openMsg(pair, data, options = {}) {
|
|
|
93783
93719
|
actionId: normalized.id,
|
|
93784
93720
|
actionOp: normalized.op,
|
|
93785
93721
|
actionTarget: normalized.target,
|
|
93786
|
-
|
|
93722
|
+
signingPublicKey: normalized.signingPublicKey,
|
|
93787
93723
|
from: normalized.sender,
|
|
93788
93724
|
s: normalized.sender
|
|
93789
93725
|
};
|
|
@@ -93894,9 +93830,11 @@ function entryAad(entryId) {
|
|
|
93894
93830
|
async function sealOwnChatEntry(chatPrivKey, entryId, entry) {
|
|
93895
93831
|
const key = entryKey(chatPrivKey, entryId);
|
|
93896
93832
|
try {
|
|
93833
|
+
const { signingKeysByChatKey, ...entryFields } = entry || {};
|
|
93897
93834
|
const body = {
|
|
93898
93835
|
v: CHAT_ENTRY_VERSION,
|
|
93899
|
-
...
|
|
93836
|
+
...entryFields,
|
|
93837
|
+
actors: signingKeysByChatKey || {},
|
|
93900
93838
|
settings: normalizeChatSettings(entry?.settings)
|
|
93901
93839
|
};
|
|
93902
93840
|
const { nonce, ct } = await sealJson(key, body, entryAad(entryId));
|
|
@@ -93913,8 +93851,10 @@ async function openOwnChatEntry(chatPrivKey, entryId, body) {
|
|
|
93913
93851
|
if (entry?.v !== CHAT_ENTRY_VERSION || !entry?.linkId || !entry?.chatId || !entry?.peerChatPK) {
|
|
93914
93852
|
throw new Error("invalid chat entry");
|
|
93915
93853
|
}
|
|
93854
|
+
const { actors, ...entryFields } = entry;
|
|
93916
93855
|
return {
|
|
93917
|
-
...
|
|
93856
|
+
...entryFields,
|
|
93857
|
+
signingKeysByChatKey: actors || {},
|
|
93918
93858
|
settings: normalizeChatSettings(entry.settings)
|
|
93919
93859
|
};
|
|
93920
93860
|
} finally {
|
|
@@ -93928,10 +93868,10 @@ function makeOwnChatEntry(pair, fields = {}) {
|
|
|
93928
93868
|
chatId: pair.chatId,
|
|
93929
93869
|
peerChatPK: pair.peerChatPK,
|
|
93930
93870
|
peerUid: cleanText(fields.peerUid),
|
|
93931
|
-
|
|
93932
|
-
...fields.
|
|
93933
|
-
[pair.chatPK]: pair.
|
|
93934
|
-
...fields.
|
|
93871
|
+
signingKeysByChatKey: {
|
|
93872
|
+
...fields.signingKeysByChatKey || {},
|
|
93873
|
+
[pair.chatPK]: pair.signingKey.publicKey,
|
|
93874
|
+
...fields.peerSigningPublicKey ? { [pair.peerChatPK]: fields.peerSigningPublicKey } : {}
|
|
93935
93875
|
},
|
|
93936
93876
|
settings: normalizeChatSettings(fields.settings),
|
|
93937
93877
|
preview: fields.preview || null,
|
|
@@ -93967,7 +93907,7 @@ async function sealPing(senderChatPK, senderPrivKey, recipientChatPK, fields = {
|
|
|
93967
93907
|
let key = null;
|
|
93968
93908
|
try {
|
|
93969
93909
|
pair = await openChatPair(senderChatPK, senderPrivKey, recipientChatPK, { chatId: fields.chatId });
|
|
93970
|
-
if (!pair?.chatId || !pair?.
|
|
93910
|
+
if (!pair?.chatId || !pair?.signingKey?.publicKey || !pair?.linkRoot) {
|
|
93971
93911
|
throw new Error("chat ping pair required");
|
|
93972
93912
|
}
|
|
93973
93913
|
eph = getKeyPair(randomBytes3(32));
|
|
@@ -93983,7 +93923,7 @@ async function sealPing(senderChatPK, senderPrivKey, recipientChatPK, fields = {
|
|
|
93983
93923
|
chatId: pair.chatId,
|
|
93984
93924
|
senderChatPK,
|
|
93985
93925
|
senderUid: cleanText(fields.senderUid),
|
|
93986
|
-
actorPK: pair.
|
|
93926
|
+
actorPK: pair.signingKey.publicKey,
|
|
93987
93927
|
messageId: cleanText(fields.messageId),
|
|
93988
93928
|
ts: Number.isFinite(fields.ts) ? fields.ts : Date.now()
|
|
93989
93929
|
};
|
|
@@ -94013,26 +93953,27 @@ async function openPing(chatPK, chatPrivKey, ping) {
|
|
|
94013
93953
|
const key = deriveKey2(shared.subarray(0, 32), "chat-inbox-ping-v1", [epk, chatPK]);
|
|
94014
93954
|
try {
|
|
94015
93955
|
const { nonce, ct } = unpackBodyData(ping.body);
|
|
94016
|
-
const
|
|
94017
|
-
const senderChatPK = cleanText(
|
|
94018
|
-
if (!senderChatPK ||
|
|
93956
|
+
const wirePayload = await openJson(key, nonce, ct, canonicalBytes({ v: CHAT_PING_VERSION, epk }, "chat ping aad"));
|
|
93957
|
+
const senderChatPK = cleanText(wirePayload?.senderChatPK);
|
|
93958
|
+
if (!senderChatPK || wirePayload?.v !== CHAT_PING_VERSION || wirePayload?.protocol !== CHAT_PROTOCOL_VERSION) {
|
|
94019
93959
|
throw new Error("invalid chat ping payload");
|
|
94020
93960
|
}
|
|
94021
93961
|
linkPair = await openChatPair(chatPK, chatPrivKey, senderChatPK);
|
|
94022
|
-
if (
|
|
93962
|
+
if (wirePayload.linkId !== linkPair.linkId || wirePayload.proof !== pingProof(linkPair.linkRoot, wirePayload)) {
|
|
94023
93963
|
throw new Error("invalid chat ping proof");
|
|
94024
93964
|
}
|
|
94025
|
-
const pair = await openChatPair(chatPK, chatPrivKey, senderChatPK, { chatId:
|
|
94026
|
-
if (!pair?.chatId || !pair?.
|
|
93965
|
+
const pair = await openChatPair(chatPK, chatPrivKey, senderChatPK, { chatId: wirePayload.chatId });
|
|
93966
|
+
if (!pair?.chatId || !pair?.signingKey?.publicKey) {
|
|
94027
93967
|
closeChatPair(pair);
|
|
94028
93968
|
throw new Error("invalid chat ping chat");
|
|
94029
93969
|
}
|
|
93970
|
+
const { actorPK, ...payloadFields } = wirePayload;
|
|
94030
93971
|
return {
|
|
94031
93972
|
pair,
|
|
94032
93973
|
payload: {
|
|
94033
|
-
...
|
|
93974
|
+
...payloadFields,
|
|
94034
93975
|
senderChatPK,
|
|
94035
|
-
|
|
93976
|
+
signingPublicKey: cleanText(actorPK)
|
|
94036
93977
|
}
|
|
94037
93978
|
};
|
|
94038
93979
|
} finally {
|
|
@@ -94049,27 +93990,24 @@ function makeTtlMs(value) {
|
|
|
94049
93990
|
const ms = timestampMs(value, null, { positive: true });
|
|
94050
93991
|
return ms == null ? null : ms;
|
|
94051
93992
|
}
|
|
94052
|
-
function
|
|
94053
|
-
return makeTtlMs(
|
|
93993
|
+
function newStorageTtlMs() {
|
|
93994
|
+
return makeTtlMs(newMessageStorageTtlMs());
|
|
94054
93995
|
}
|
|
94055
93996
|
async function profileByChatPK(cloud, chatPK) {
|
|
94056
93997
|
if (!cloud || !chatPK) {
|
|
94057
93998
|
return null;
|
|
94058
93999
|
}
|
|
94059
|
-
const peer = await cloud.search.peer.byChatPK(chatPK)
|
|
94000
|
+
const peer = await cloud.search.peer.byChatPK(chatPK);
|
|
94060
94001
|
if (!peer) {
|
|
94061
94002
|
return null;
|
|
94062
94003
|
}
|
|
94063
|
-
return {
|
|
94064
|
-
uid: cleanText(peer.uid),
|
|
94065
|
-
actorPK: cleanText(peer.actorPK)
|
|
94066
|
-
};
|
|
94004
|
+
return { uid: cleanText(peer.uid) };
|
|
94067
94005
|
}
|
|
94068
94006
|
async function readOwnEntry(cloud, uid, chatPrivKey, entryId) {
|
|
94069
94007
|
if (!cloud || !uid || !chatPrivKey || !entryId) {
|
|
94070
94008
|
return null;
|
|
94071
94009
|
}
|
|
94072
|
-
const record = await cloud.user.chats.read(uid, entryId)
|
|
94010
|
+
const record = await cloud.user.chats.read(uid, entryId);
|
|
94073
94011
|
if (!record) {
|
|
94074
94012
|
return null;
|
|
94075
94013
|
}
|
|
@@ -94103,16 +94041,16 @@ async function ownEntryWrite(cloud, uid, chatPrivKey, pair, fields = {}) {
|
|
|
94103
94041
|
}
|
|
94104
94042
|
const entryId = ownChatEntryId(chatPrivKey, pair.chatId);
|
|
94105
94043
|
const existing = fields.entry || await readOwnEntry(cloud, uid, chatPrivKey, entryId);
|
|
94106
|
-
const
|
|
94107
|
-
const
|
|
94108
|
-
...existing?.
|
|
94109
|
-
[pair.chatPK]: pair.
|
|
94110
|
-
...
|
|
94044
|
+
const peerSigningPublicKey = cleanText(fields.peerSigningPublicKey) || cleanText(existing?.signingKeysByChatKey?.[pair.peerChatPK]);
|
|
94045
|
+
const signingKeysByChatKey = {
|
|
94046
|
+
...existing?.signingKeysByChatKey || {},
|
|
94047
|
+
[pair.chatPK]: pair.signingKey.publicKey,
|
|
94048
|
+
...peerSigningPublicKey ? { [pair.peerChatPK]: peerSigningPublicKey } : {}
|
|
94111
94049
|
};
|
|
94112
94050
|
const entry = makeOwnChatEntry(pair, {
|
|
94113
94051
|
peerUid: fields.peerUid || existing?.peerUid,
|
|
94114
|
-
|
|
94115
|
-
|
|
94052
|
+
peerSigningPublicKey,
|
|
94053
|
+
signingKeysByChatKey,
|
|
94116
94054
|
settings: fields.settings || existing?.settings,
|
|
94117
94055
|
preview: fields.preview || existing?.preview,
|
|
94118
94056
|
saved: existing?.saved || null,
|
|
@@ -94156,9 +94094,9 @@ async function recipientForSend(cloud, receiverChatPK, options, needed) {
|
|
|
94156
94094
|
return null;
|
|
94157
94095
|
}
|
|
94158
94096
|
const uid = cleanText(options?.receiverUid);
|
|
94159
|
-
const
|
|
94097
|
+
const signingPublicKey = cleanText(options?.peerSigningPublicKey);
|
|
94160
94098
|
if (uid) {
|
|
94161
|
-
return { uid,
|
|
94099
|
+
return { uid, signingPublicKey };
|
|
94162
94100
|
}
|
|
94163
94101
|
return profileByChatPK(cloud, receiverChatPK);
|
|
94164
94102
|
}
|
|
@@ -94180,7 +94118,7 @@ async function sendMsg(cloud, senderPubkey, senderPrivkey, receiverChatPK, messa
|
|
|
94180
94118
|
const messagePayload = withMessageRetention(message, retention);
|
|
94181
94119
|
const actionOp = actionOpForPayload(messagePayload);
|
|
94182
94120
|
const { head, body } = await sealMsg(pair, messagePayload, { op: actionOp, ts: tsMs });
|
|
94183
|
-
const ttlMs = actionOp === CHAT_ACTION_OPS.CREATE ?
|
|
94121
|
+
const ttlMs = actionOp === CHAT_ACTION_OPS.CREATE ? newStorageTtlMs() : null;
|
|
94184
94122
|
const messageId = cleanText(options?.messageId) || await cloud.chat.messages.id(chatId);
|
|
94185
94123
|
const msgData = {
|
|
94186
94124
|
head,
|
|
@@ -94192,7 +94130,7 @@ async function sendMsg(cloud, senderPubkey, senderPrivkey, receiverChatPK, messa
|
|
|
94192
94130
|
const preview = updatePreview ? sentMessage : null;
|
|
94193
94131
|
const ownerEntry = updatePreview ? await ownEntryWrite(cloud, cleanText(options?.senderUid), senderPrivkey, pair, {
|
|
94194
94132
|
peerUid: recipientProfile?.uid || cleanText(options?.receiverUid),
|
|
94195
|
-
|
|
94133
|
+
peerSigningPublicKey: recipientProfile?.signingPublicKey,
|
|
94196
94134
|
entry: options?.ownEntry,
|
|
94197
94135
|
settings: options?.chatSettings,
|
|
94198
94136
|
preview,
|
|
@@ -94213,7 +94151,7 @@ async function sendMsg(cloud, senderPubkey, senderPrivkey, receiverChatPK, messa
|
|
|
94213
94151
|
message: msgData,
|
|
94214
94152
|
ownerEntry,
|
|
94215
94153
|
inbox: ping ? { recipientUid: recipientProfile?.uid, ping } : null,
|
|
94216
|
-
onCommitted: options?.onCommitted
|
|
94154
|
+
onCommitted: typeof options?.onCommitted === "function" ? (committed) => options.onCommitted({ ...committed, message: sentMessage, preview }) : undefined
|
|
94217
94155
|
});
|
|
94218
94156
|
return { chatId, msgId: messageId, cid: head.cid, message: sentMessage, preview, ...write?.skipped ? { skipped: true } : {} };
|
|
94219
94157
|
}
|
|
@@ -94276,7 +94214,7 @@ function messagePermanentUpdateItems(messages) {
|
|
|
94276
94214
|
function messageTemporaryUpdateItems(messages) {
|
|
94277
94215
|
return messageMutationItems(messages, { include: (message) => message?.ttl == null });
|
|
94278
94216
|
}
|
|
94279
|
-
async function makeMsgTemporary(cloud, chatId, messages, ttlMs =
|
|
94217
|
+
async function makeMsgTemporary(cloud, chatId, messages, ttlMs = newMessageStorageTtlMs()) {
|
|
94280
94218
|
const nextTtlMs = makeTtlMs(ttlMs);
|
|
94281
94219
|
const items = messageTemporaryUpdateItems(messages);
|
|
94282
94220
|
if (!cloud || !chatId || !nextTtlMs || !items.length) {
|
|
@@ -94285,7 +94223,7 @@ async function makeMsgTemporary(cloud, chatId, messages, ttlMs = newMessageTtlMs
|
|
|
94285
94223
|
if (typeof cloud.chat?.messages?.ttl !== "function") {
|
|
94286
94224
|
throw new Error("message ttl unavailable");
|
|
94287
94225
|
}
|
|
94288
|
-
const result = await cloud.chat.messages.ttl(chatId, items, { permanent: false, ttlMs: nextTtlMs });
|
|
94226
|
+
const result = await cloud.chat.messages.ttl(chatId, items, { permanent: false, ttlMs: nextTtlMs, releaseMediaHold: true });
|
|
94289
94227
|
return Number.isFinite(result?.updated) ? result.updated : items.length;
|
|
94290
94228
|
}
|
|
94291
94229
|
async function makeMsgPermanent(cloud, chatId, messages) {
|
|
@@ -94310,7 +94248,7 @@ async function setChatRetention(cloud, chatId, senderPubkey, senderPrivkey, peer
|
|
|
94310
94248
|
}
|
|
94311
94249
|
const systemMessage = {
|
|
94312
94250
|
...makeRetentionSystemMsg(nextRetention),
|
|
94313
|
-
cid: makeCid(),
|
|
94251
|
+
cid: cleanText(options?.cid) || makeCid(),
|
|
94314
94252
|
s: senderPubkey
|
|
94315
94253
|
};
|
|
94316
94254
|
await sendMsg(cloud, senderPubkey, senderPrivkey, peerChatPK, systemMessage, {
|
|
@@ -94321,7 +94259,8 @@ async function setChatRetention(cloud, chatId, senderPubkey, senderPrivkey, peer
|
|
|
94321
94259
|
chatExists: true,
|
|
94322
94260
|
senderUid: options?.senderUid,
|
|
94323
94261
|
ownEntry: options?.ownEntry,
|
|
94324
|
-
chatSettings: { retention: nextRetention }
|
|
94262
|
+
chatSettings: { retention: nextRetention },
|
|
94263
|
+
onCommitted: options?.onCommitted
|
|
94325
94264
|
});
|
|
94326
94265
|
return nextRetention;
|
|
94327
94266
|
}
|
|
@@ -94349,7 +94288,7 @@ async function updateMsg(cloud, chatId, msgId, senderPubkey, senderPrivkey, rece
|
|
|
94349
94288
|
const preview = updatePreview ? ownerEditedPreview(senderPubkey, newMessage) : null;
|
|
94350
94289
|
const ownerEntry = updatePreview ? await ownEntryWrite(cloud, cleanText(options?.senderUid), senderPrivkey, pair, {
|
|
94351
94290
|
peerUid: cleanText(options?.receiverUid),
|
|
94352
|
-
|
|
94291
|
+
peerSigningPublicKey: cleanText(options?.peerSigningPublicKey),
|
|
94353
94292
|
entry: options?.ownEntry,
|
|
94354
94293
|
preview,
|
|
94355
94294
|
ts: preview?.ts ?? tsMs
|
|
@@ -94491,7 +94430,7 @@ async function decryptMsg(msgData, userChatPK, userPrivKey, peerChatPK, options
|
|
|
94491
94430
|
}
|
|
94492
94431
|
try {
|
|
94493
94432
|
const pair = await getCachedPair(userChatPK, userPrivKey, peerChatPK, { chatId: options?.chatId });
|
|
94494
|
-
const message = await openMsg(pair, msgData, {
|
|
94433
|
+
const message = await openMsg(pair, msgData, { signingKeysByChatKey: options?.signingKeysByChatKey, crypto: options?.crypto });
|
|
94495
94434
|
return normalizeDecryptedMsg(msgData, message);
|
|
94496
94435
|
} catch {
|
|
94497
94436
|
return null;
|
|
@@ -94513,7 +94452,7 @@ function normalizeChatPreview(msgData, message) {
|
|
|
94513
94452
|
return canRenderChatPreview(normalized) ? normalized : null;
|
|
94514
94453
|
}
|
|
94515
94454
|
async function readExistingEntry(cloud, uid, userPrivKey, entryId) {
|
|
94516
|
-
const entry = await cloud.user.chats.read(uid, entryId)
|
|
94455
|
+
const entry = await cloud.user.chats.read(uid, entryId);
|
|
94517
94456
|
if (!entry) {
|
|
94518
94457
|
return null;
|
|
94519
94458
|
}
|
|
@@ -94539,11 +94478,11 @@ function isReadPing(ping) {
|
|
|
94539
94478
|
function isDeletePing(ping) {
|
|
94540
94479
|
return pingKind(ping) === CHAT_PING_KIND_DELETE;
|
|
94541
94480
|
}
|
|
94542
|
-
function
|
|
94481
|
+
function pingSigningKeys(ping, existing) {
|
|
94543
94482
|
return {
|
|
94544
|
-
...existing?.
|
|
94545
|
-
[ping.pair.chatPK]: ping.pair.
|
|
94546
|
-
[ping.payload.senderChatPK]: ping.payload.
|
|
94483
|
+
...existing?.signingKeysByChatKey || {},
|
|
94484
|
+
[ping.pair.chatPK]: ping.pair.signingKey.publicKey,
|
|
94485
|
+
[ping.payload.senderChatPK]: ping.payload.signingPublicKey
|
|
94547
94486
|
};
|
|
94548
94487
|
}
|
|
94549
94488
|
function chatFromPing(ping, entryId, existing, preview, userChatPK, ms) {
|
|
@@ -94560,7 +94499,7 @@ function chatFromPing(ping, entryId, existing, preview, userChatPK, ms) {
|
|
|
94560
94499
|
entryId,
|
|
94561
94500
|
peerChatPK: ping.payload.senderChatPK,
|
|
94562
94501
|
peerUid: existing?.peerUid || cleanText(ping.payload.senderUid) || null,
|
|
94563
|
-
|
|
94502
|
+
signingKeysByChatKey: pingSigningKeys(ping, existing),
|
|
94564
94503
|
settings: existing?.settings,
|
|
94565
94504
|
saved: existing?.saved || null,
|
|
94566
94505
|
readMs,
|
|
@@ -94576,27 +94515,27 @@ async function resolvePingUid(cloud, payload) {
|
|
|
94576
94515
|
return null;
|
|
94577
94516
|
}
|
|
94578
94517
|
if (claimedUid) {
|
|
94579
|
-
const peer2 = await cloud.peer.read(claimedUid)
|
|
94518
|
+
const peer2 = await cloud.peer.read(claimedUid);
|
|
94580
94519
|
if (cleanText(peer2?.chatPK) !== senderChatPK) {
|
|
94581
94520
|
throw new Error("ping sender uid mismatch");
|
|
94582
94521
|
}
|
|
94583
94522
|
return claimedUid;
|
|
94584
94523
|
}
|
|
94585
|
-
const peer = await cloud.search.peer.byChatPK(senderChatPK)
|
|
94524
|
+
const peer = await cloud.search.peer.byChatPK(senderChatPK);
|
|
94586
94525
|
return peer?.uid || null;
|
|
94587
94526
|
}
|
|
94588
|
-
async function readPingMsg(cloud, userChatPK, userPrivKey, ping,
|
|
94527
|
+
async function readPingMsg(cloud, userChatPK, userPrivKey, ping, signingKeysByChatKey, options = {}) {
|
|
94589
94528
|
const chatId = ping?.pair?.chatId;
|
|
94590
94529
|
const messageId = cleanText(ping?.payload?.messageId);
|
|
94591
94530
|
const peerChatPK = cleanText(ping?.payload?.senderChatPK);
|
|
94592
94531
|
if (!cloud || !chatId || !messageId || !userChatPK || !userPrivKey || !peerChatPK) {
|
|
94593
94532
|
return null;
|
|
94594
94533
|
}
|
|
94595
|
-
const data = await cloud.chat.messages.read(chatId, messageId)
|
|
94534
|
+
const data = await cloud.chat.messages.read(chatId, messageId);
|
|
94596
94535
|
if (!data) {
|
|
94597
94536
|
return null;
|
|
94598
94537
|
}
|
|
94599
|
-
const message = await decryptMsg(data, userChatPK, userPrivKey, peerChatPK, {
|
|
94538
|
+
const message = await decryptMsg(data, userChatPK, userPrivKey, peerChatPK, { signingKeysByChatKey, chatId }).catch(() => null);
|
|
94600
94539
|
const normalized = message ? { ...message, id: data.id, ts: data.ts ?? message.ts, ttl: data.ttl ?? message.ttl } : null;
|
|
94601
94540
|
if (options.raw === true) {
|
|
94602
94541
|
return normalized;
|
|
@@ -94606,19 +94545,19 @@ async function readPingMsg(cloud, userChatPK, userPrivKey, ping, actors, options
|
|
|
94606
94545
|
}
|
|
94607
94546
|
async function savePing(cloud, uid, userChatPK, userPrivKey, ping, options = {}) {
|
|
94608
94547
|
const chatId = ping?.pair?.chatId;
|
|
94609
|
-
if (!chatId || !cleanText(ping?.payload?.
|
|
94548
|
+
if (!chatId || !cleanText(ping?.payload?.signingPublicKey) || !cleanText(ping?.payload?.senderChatPK)) {
|
|
94610
94549
|
return false;
|
|
94611
94550
|
}
|
|
94612
94551
|
const entryId = ownChatEntryId(userPrivKey, chatId);
|
|
94613
94552
|
const existing = options.existing || await readExistingEntry(cloud, uid, userPrivKey, entryId);
|
|
94614
94553
|
const peerUid = options.peerUid || await resolvePingUid(cloud, ping.payload);
|
|
94615
|
-
const
|
|
94554
|
+
const signingKeysByChatKey = options.signingKeysByChatKey || pingSigningKeys(ping, existing);
|
|
94616
94555
|
const hasPreview = Object.prototype.hasOwnProperty.call(options, "preview");
|
|
94617
|
-
const preview = hasPreview ? options.preview : await readPingMsg(cloud, userChatPK, userPrivKey, ping,
|
|
94556
|
+
const preview = hasPreview ? options.preview : await readPingMsg(cloud, userChatPK, userPrivKey, ping, signingKeysByChatKey);
|
|
94618
94557
|
const entry = makeOwnChatEntry(ping.pair, {
|
|
94619
94558
|
peerUid: peerUid || existing?.peerUid,
|
|
94620
|
-
|
|
94621
|
-
|
|
94559
|
+
peerSigningPublicKey: ping.payload.signingPublicKey || existing?.signingKeysByChatKey?.[ping.payload.senderChatPK],
|
|
94560
|
+
signingKeysByChatKey,
|
|
94622
94561
|
settings: existing?.settings,
|
|
94623
94562
|
preview: preview || existing?.preview,
|
|
94624
94563
|
readMs: existing?.readMs
|
|
@@ -94661,7 +94600,7 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94661
94600
|
if (!cloud || !uid || !userChatPK || !userPrivKey) {
|
|
94662
94601
|
return false;
|
|
94663
94602
|
}
|
|
94664
|
-
const inboxItems = await cloud.inbox.list(uid)
|
|
94603
|
+
const inboxItems = await cloud.inbox.list(uid);
|
|
94665
94604
|
if (!inboxItems?.length) {
|
|
94666
94605
|
return false;
|
|
94667
94606
|
}
|
|
@@ -94716,9 +94655,9 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94716
94655
|
if (group.message) {
|
|
94717
94656
|
const item = group.message;
|
|
94718
94657
|
const entryId = ownChatEntryId(userPrivKey, item.chatId);
|
|
94719
|
-
const
|
|
94658
|
+
const signingKeysByChatKey = pingSigningKeys(item.ping, current);
|
|
94720
94659
|
const existingMs = timestampMs(current?.preview?.ts, 0) ?? 0;
|
|
94721
|
-
const preview = existingMs >= item.ms ? current?.preview || null : await readPingMsg(cloud, userChatPK, userPrivKey, item.ping,
|
|
94660
|
+
const preview = existingMs >= item.ms ? current?.preview || null : await readPingMsg(cloud, userChatPK, userPrivKey, item.ping, signingKeysByChatKey);
|
|
94722
94661
|
const chat = chatFromPing(item.ping, entryId, current, preview, userChatPK, item.ms);
|
|
94723
94662
|
if (chat) {
|
|
94724
94663
|
current = chat;
|
|
@@ -94728,7 +94667,7 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94728
94667
|
}
|
|
94729
94668
|
wrote = await savePing(cloud, uid, userChatPK, userPrivKey, item.ping, {
|
|
94730
94669
|
existing: current,
|
|
94731
|
-
|
|
94670
|
+
signingKeysByChatKey,
|
|
94732
94671
|
preview
|
|
94733
94672
|
});
|
|
94734
94673
|
}
|
|
@@ -94736,8 +94675,8 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94736
94675
|
const item = group.read;
|
|
94737
94676
|
const entryId = ownChatEntryId(userPrivKey, item.chatId);
|
|
94738
94677
|
const existing = current || await readExistingEntry(cloud, uid, userPrivKey, entryId);
|
|
94739
|
-
const
|
|
94740
|
-
const receiptPreview = await readPingMsg(cloud, userChatPK, userPrivKey, item.ping,
|
|
94678
|
+
const signingKeysByChatKey = pingSigningKeys(item.ping, existing);
|
|
94679
|
+
const receiptPreview = await readPingMsg(cloud, userChatPK, userPrivKey, item.ping, signingKeysByChatKey);
|
|
94741
94680
|
const openedPreview = patchReadPingPreview(existing, receiptPreview, userChatPK);
|
|
94742
94681
|
const chat = chatWithReadPreview(current, openedPreview, userChatPK);
|
|
94743
94682
|
handled = true;
|
|
@@ -94750,7 +94689,7 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94750
94689
|
const writeExisting = chat || existing;
|
|
94751
94690
|
wrote = await savePing(cloud, uid, userChatPK, userPrivKey, item.ping, {
|
|
94752
94691
|
existing: writeExisting,
|
|
94753
|
-
|
|
94692
|
+
signingKeysByChatKey,
|
|
94754
94693
|
preview: openedPreview,
|
|
94755
94694
|
writeTs: false
|
|
94756
94695
|
}) || wrote;
|
|
@@ -94760,8 +94699,8 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94760
94699
|
const item = group.delete;
|
|
94761
94700
|
const entryId = ownChatEntryId(userPrivKey, item.chatId);
|
|
94762
94701
|
const existing = current || await readExistingEntry(cloud, uid, userPrivKey, entryId);
|
|
94763
|
-
const
|
|
94764
|
-
const deletePreview = await readPingMsg(cloud, userChatPK, userPrivKey, item.ping,
|
|
94702
|
+
const signingKeysByChatKey = pingSigningKeys(item.ping, existing);
|
|
94703
|
+
const deletePreview = await readPingMsg(cloud, userChatPK, userPrivKey, item.ping, signingKeysByChatKey, { raw: true });
|
|
94765
94704
|
const deletedPreview = patchDeletePingPreview(existing, deletePreview);
|
|
94766
94705
|
const chat = deletedPreview ? chatFromPing(item.ping, entryId, current || existing, deletedPreview, userChatPK, item.ms) : null;
|
|
94767
94706
|
handled = true;
|
|
@@ -94774,7 +94713,7 @@ async function processInbox(cloud, uid, userChatPK, userPrivKey, options = {}) {
|
|
|
94774
94713
|
const writeExisting = chat || existing;
|
|
94775
94714
|
wrote = await savePing(cloud, uid, userChatPK, userPrivKey, item.ping, {
|
|
94776
94715
|
existing: writeExisting,
|
|
94777
|
-
|
|
94716
|
+
signingKeysByChatKey,
|
|
94778
94717
|
preview: deletedPreview
|
|
94779
94718
|
}) || wrote;
|
|
94780
94719
|
}
|
|
@@ -94943,7 +94882,7 @@ async function getChat(cloud, uid, chatId, userChatPK, userPrivKey) {
|
|
|
94943
94882
|
return null;
|
|
94944
94883
|
}
|
|
94945
94884
|
const entryId = ownChatEntryId(userPrivKey, chatId);
|
|
94946
|
-
const entry = await cloud.user.chats.read(uid, entryId)
|
|
94885
|
+
const entry = await cloud.user.chats.read(uid, entryId);
|
|
94947
94886
|
if (!entry) {
|
|
94948
94887
|
return null;
|
|
94949
94888
|
}
|
|
@@ -94978,7 +94917,7 @@ async function decryptChatEntry(entryRecord, userChatPK, userPrivKey) {
|
|
|
94978
94917
|
entryId: entryRecord.id,
|
|
94979
94918
|
peerChatPK: entry.peerChatPK,
|
|
94980
94919
|
peerUid: entry.peerUid || null,
|
|
94981
|
-
|
|
94920
|
+
signingKeysByChatKey: entry.signingKeysByChatKey || {},
|
|
94982
94921
|
settings: entry.settings,
|
|
94983
94922
|
saved: entry.saved || null,
|
|
94984
94923
|
readMs,
|
|
@@ -95236,7 +95175,7 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95236
95175
|
chatId: chat.id,
|
|
95237
95176
|
senderUid: active.uid,
|
|
95238
95177
|
receiverUid: chat.peerUid,
|
|
95239
|
-
|
|
95178
|
+
peerSigningPublicKey: chat.signingKeysByChatKey?.[chat.peerChatPK],
|
|
95240
95179
|
ownEntry: chat.entryId ? chat : null,
|
|
95241
95180
|
chatSettings: normalizeChatSettings(chat.settings)
|
|
95242
95181
|
};
|
|
@@ -95257,10 +95196,7 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95257
95196
|
...chat,
|
|
95258
95197
|
peerChatPK,
|
|
95259
95198
|
peerUid: profile.uid || chat.peerUid || null,
|
|
95260
|
-
|
|
95261
|
-
...chat.actors || {},
|
|
95262
|
-
...peerChatPK && profile.actorPK ? { [peerChatPK]: profile.actorPK } : {}
|
|
95263
|
-
}
|
|
95199
|
+
signingKeysByChatKey: chat.signingKeysByChatKey || {}
|
|
95264
95200
|
};
|
|
95265
95201
|
}
|
|
95266
95202
|
async function list(options = {}) {
|
|
@@ -95284,11 +95220,11 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95284
95220
|
if (chat) {
|
|
95285
95221
|
return withPeerProfile(chat, profile2);
|
|
95286
95222
|
}
|
|
95287
|
-
const link = await resolvePeerChat(readCloud(), active.chatPK, active.chatPrivKey, profile2.chatPK, options)
|
|
95223
|
+
const link = await resolvePeerChat(readCloud(), active.chatPK, active.chatPrivKey, profile2.chatPK, options);
|
|
95288
95224
|
if (!link?.chatId) {
|
|
95289
95225
|
return null;
|
|
95290
95226
|
}
|
|
95291
|
-
const linkedChat = await getChat(readCloud(), active.uid, link.chatId, active.chatPK, active.chatPrivKey)
|
|
95227
|
+
const linkedChat = await getChat(readCloud(), active.uid, link.chatId, active.chatPK, active.chatPrivKey);
|
|
95292
95228
|
return withPeerProfile(linkedChat, profile2);
|
|
95293
95229
|
};
|
|
95294
95230
|
if (CHAT_PK_RE.test(value)) {
|
|
@@ -95296,12 +95232,12 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95296
95232
|
if (chat) {
|
|
95297
95233
|
return chat;
|
|
95298
95234
|
}
|
|
95299
|
-
const profile2 = await peers.resolve(value)
|
|
95235
|
+
const profile2 = await peers.resolve(value);
|
|
95300
95236
|
const resolvedChat = await chatByProfile(profile2);
|
|
95301
95237
|
if (resolvedChat) {
|
|
95302
95238
|
return resolvedChat;
|
|
95303
95239
|
}
|
|
95304
|
-
return getChat(readCloud(), active.uid, value, active.chatPK, active.chatPrivKey)
|
|
95240
|
+
return getChat(readCloud(), active.uid, value, active.chatPK, active.chatPrivKey);
|
|
95305
95241
|
}
|
|
95306
95242
|
const profile = await peers.resolve(peer);
|
|
95307
95243
|
return chatByProfile(profile);
|
|
@@ -95311,7 +95247,7 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95311
95247
|
const decrypted = [];
|
|
95312
95248
|
for (const record of page.records || []) {
|
|
95313
95249
|
const message = await decryptMsg(record, active.chatPK, active.chatPrivKey, chat.peerChatPK, {
|
|
95314
|
-
|
|
95250
|
+
signingKeysByChatKey: chat.signingKeysByChatKey,
|
|
95315
95251
|
chatId: chat.id
|
|
95316
95252
|
});
|
|
95317
95253
|
if (message) {
|
|
@@ -95340,7 +95276,7 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95340
95276
|
senderUid: active.uid,
|
|
95341
95277
|
receiverUid: chat.peerUid,
|
|
95342
95278
|
linkId: chat.linkId,
|
|
95343
|
-
|
|
95279
|
+
peerSigningPublicKey: chat.signingKeysByChatKey?.[chat.peerChatPK],
|
|
95344
95280
|
ping: true
|
|
95345
95281
|
}).catch(() => {});
|
|
95346
95282
|
}
|
|
@@ -95369,9 +95305,9 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95369
95305
|
if (message) {
|
|
95370
95306
|
return { active, chat, message, target: getMessageKey(message) || target };
|
|
95371
95307
|
}
|
|
95372
|
-
const record = await readCloud().chat.messages.read(chat.id, target)
|
|
95308
|
+
const record = await readCloud().chat.messages.read(chat.id, target);
|
|
95373
95309
|
const direct = record ? await decryptMsg(record, active.chatPK, active.chatPrivKey, chat.peerChatPK, {
|
|
95374
|
-
|
|
95310
|
+
signingKeysByChatKey: chat.signingKeysByChatKey,
|
|
95375
95311
|
chatId: chat.id
|
|
95376
95312
|
}) : null;
|
|
95377
95313
|
if (!direct) {
|
|
@@ -95420,8 +95356,7 @@ function createChatActions({ readCloud, readSession, inbox, peers }) {
|
|
|
95420
95356
|
linkVersion: link.version,
|
|
95421
95357
|
protocol: link.protocol,
|
|
95422
95358
|
senderUid: active.uid,
|
|
95423
|
-
receiverUid: profile.uid
|
|
95424
|
-
peerActorPK: profile.actorPK
|
|
95359
|
+
receiverUid: profile.uid
|
|
95425
95360
|
});
|
|
95426
95361
|
return {
|
|
95427
95362
|
chat: {
|
|
@@ -96792,7 +96727,7 @@ function createMoneyActions({ readCloud, readSession, resolvePeer, sendPayload }
|
|
|
96792
96727
|
}
|
|
96793
96728
|
const record = await readCloud().chat.messages.read(chat.id, messageId);
|
|
96794
96729
|
const message = await decryptMsg(record, active.chatPK, active.chatPrivKey, chat.peerChatPK, {
|
|
96795
|
-
|
|
96730
|
+
signingKeysByChatKey: chat.signingKeysByChatKey,
|
|
96796
96731
|
chatId: chat.id
|
|
96797
96732
|
});
|
|
96798
96733
|
if (!message || message.t !== "req") {
|
|
@@ -96815,7 +96750,7 @@ function createMoneyActions({ readCloud, readSession, resolvePeer, sendPayload }
|
|
|
96815
96750
|
senderUid: active.uid,
|
|
96816
96751
|
receiverUid: chat.peerUid,
|
|
96817
96752
|
linkId: chat.linkId,
|
|
96818
|
-
|
|
96753
|
+
peerSigningPublicKey: chat.signingKeysByChatKey?.[chat.peerChatPK]
|
|
96819
96754
|
});
|
|
96820
96755
|
return {
|
|
96821
96756
|
...paid,
|
|
@@ -98115,7 +98050,7 @@ replaceTraps((oldTraps) => ({
|
|
|
98115
98050
|
has: (target, prop) => !!getMethod2(target, prop) || oldTraps.has(target, prop)
|
|
98116
98051
|
}));
|
|
98117
98052
|
|
|
98118
|
-
// ../../node_modules/.bun/@firebase+app@0.15.
|
|
98053
|
+
// ../../node_modules/.bun/@firebase+app@0.15.1/node_modules/@firebase/app/dist/esm/index.esm.js
|
|
98119
98054
|
class PlatformLoggerServiceImpl {
|
|
98120
98055
|
constructor(container) {
|
|
98121
98056
|
this.container = container;
|
|
@@ -98137,7 +98072,7 @@ function isVersionServiceProvider(provider) {
|
|
|
98137
98072
|
return component?.type === "VERSION";
|
|
98138
98073
|
}
|
|
98139
98074
|
var name$q = "@firebase/app";
|
|
98140
|
-
var version$1 = "0.15.
|
|
98075
|
+
var version$1 = "0.15.1";
|
|
98141
98076
|
var logger2 = new Logger2("@firebase/app");
|
|
98142
98077
|
var name$p = "@firebase/app-compat";
|
|
98143
98078
|
var name$o = "@firebase/analytics-compat";
|
|
@@ -98165,7 +98100,7 @@ var name$3 = "@firebase/firestore";
|
|
|
98165
98100
|
var name$2 = "@firebase/ai";
|
|
98166
98101
|
var name$1 = "@firebase/firestore-compat";
|
|
98167
98102
|
var name2 = "firebase";
|
|
98168
|
-
var version2 = "12.
|
|
98103
|
+
var version2 = "12.16.0";
|
|
98169
98104
|
var DEFAULT_ENTRY_NAME2 = "[DEFAULT]";
|
|
98170
98105
|
var PLATFORM_LOG_STRING = {
|
|
98171
98106
|
[name$q]: "fire-core",
|
|
@@ -98615,12 +98550,12 @@ function registerCoreComponents(variant) {
|
|
|
98615
98550
|
}
|
|
98616
98551
|
registerCoreComponents("");
|
|
98617
98552
|
|
|
98618
|
-
// ../../node_modules/.bun/firebase@12.
|
|
98553
|
+
// ../../node_modules/.bun/firebase@12.16.0+419ecb626e0dfd90/node_modules/firebase/app/dist/index.mjs
|
|
98619
98554
|
var name3 = "firebase";
|
|
98620
|
-
var version3 = "12.
|
|
98555
|
+
var version3 = "12.16.0";
|
|
98621
98556
|
registerVersion(name3, version3, "app");
|
|
98622
98557
|
|
|
98623
|
-
// ../../node_modules/.bun/@firebase+auth@1.13.3+
|
|
98558
|
+
// ../../node_modules/.bun/@firebase+auth@1.13.3+8807f692d12224be/node_modules/@firebase/auth/dist/node-esm/totp-65577477.js
|
|
98624
98559
|
function _prodErrorMap() {
|
|
98625
98560
|
return {
|
|
98626
98561
|
["dependent-sdk-initialized-before-auth"]: "Another Firebase SDK was initialized and is trying to use Auth before Auth is " + "initialized. Please be sure to call `initializeAuth` or `getAuth` before " + "starting any other Firebase SDK."
|
|
@@ -101913,7 +101848,7 @@ var Md5;
|
|
|
101913
101848
|
Integer = bloom_blob_es2018.Integer = t;
|
|
101914
101849
|
}).apply(typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
|
|
101915
101850
|
|
|
101916
|
-
// ../../node_modules/.bun/@firebase+firestore@4.16.0+
|
|
101851
|
+
// ../../node_modules/.bun/@firebase+firestore@4.16.0+80db1b7a714a6e79/node_modules/@firebase/firestore/dist/common-cc96d03b.node.mjs
|
|
101917
101852
|
var grpc = __toESM(require_src3(), 1);
|
|
101918
101853
|
var protoLoader = __toESM(require_src2(), 1);
|
|
101919
101854
|
import { TextEncoder as TextEncoder2, inspect as inspect2, TextDecoder as TextDecoder2 } from "util";
|
|
@@ -106116,7 +106051,7 @@ class RE2JS {
|
|
|
106116
106051
|
}
|
|
106117
106052
|
}
|
|
106118
106053
|
|
|
106119
|
-
// ../../node_modules/.bun/@firebase+firestore@4.16.0+
|
|
106054
|
+
// ../../node_modules/.bun/@firebase+firestore@4.16.0+80db1b7a714a6e79/node_modules/@firebase/firestore/dist/common-cc96d03b.node.mjs
|
|
106120
106055
|
class User {
|
|
106121
106056
|
constructor(uid) {
|
|
106122
106057
|
this.uid = uid;
|
|
@@ -110822,6 +110757,31 @@ function toMutationDocument(serializer, key, fields) {
|
|
|
110822
110757
|
fields: fields.value.mapValue.fields
|
|
110823
110758
|
};
|
|
110824
110759
|
}
|
|
110760
|
+
function fromFound(serializer, doc) {
|
|
110761
|
+
hardAssert(!!doc.found, 43571);
|
|
110762
|
+
assertPresent(doc.found.name);
|
|
110763
|
+
assertPresent(doc.found.updateTime);
|
|
110764
|
+
const key = fromName(serializer, doc.found.name);
|
|
110765
|
+
const version6 = fromVersion(doc.found.updateTime);
|
|
110766
|
+
const createTime = doc.found.createTime ? fromVersion(doc.found.createTime) : SnapshotVersion.min();
|
|
110767
|
+
const data = new ObjectValue({ mapValue: { fields: doc.found.fields } });
|
|
110768
|
+
return MutableDocument.newFoundDocument(key, version6, createTime, data);
|
|
110769
|
+
}
|
|
110770
|
+
function fromMissing(serializer, result) {
|
|
110771
|
+
hardAssert(!!result.missing, 3894);
|
|
110772
|
+
hardAssert(!!result.readTime, 22933);
|
|
110773
|
+
const key = fromName(serializer, result.missing);
|
|
110774
|
+
const version6 = fromVersion(result.readTime);
|
|
110775
|
+
return MutableDocument.newNoDocument(key, version6);
|
|
110776
|
+
}
|
|
110777
|
+
function fromBatchGetDocumentsResponse(serializer, result) {
|
|
110778
|
+
if ("found" in result) {
|
|
110779
|
+
return fromFound(serializer, result);
|
|
110780
|
+
} else if ("missing" in result) {
|
|
110781
|
+
return fromMissing(serializer, result);
|
|
110782
|
+
}
|
|
110783
|
+
return fail(7234, { result });
|
|
110784
|
+
}
|
|
110825
110785
|
function fromWatchChange(serializer, change) {
|
|
110826
110786
|
let watchChange;
|
|
110827
110787
|
if ("targetChange" in change) {
|
|
@@ -116699,6 +116659,34 @@ class DatastoreImpl extends Datastore {
|
|
|
116699
116659
|
function newDatastore(authCredentials, appCheckCredentials, connection, serializer) {
|
|
116700
116660
|
return new DatastoreImpl(authCredentials, appCheckCredentials, connection, serializer);
|
|
116701
116661
|
}
|
|
116662
|
+
async function invokeCommitRpc(datastore, mutations) {
|
|
116663
|
+
const datastoreImpl = debugCast(datastore);
|
|
116664
|
+
const request = {
|
|
116665
|
+
writes: mutations.map((m) => toMutation(datastoreImpl.serializer, m))
|
|
116666
|
+
};
|
|
116667
|
+
await datastoreImpl.invokeRPC("Commit", datastoreImpl.serializer.databaseId, ResourcePath.emptyPath(), request);
|
|
116668
|
+
}
|
|
116669
|
+
async function invokeBatchGetDocumentsRpc(datastore, keys) {
|
|
116670
|
+
const datastoreImpl = debugCast(datastore);
|
|
116671
|
+
const request = {
|
|
116672
|
+
documents: keys.map((k) => toName(datastoreImpl.serializer, k))
|
|
116673
|
+
};
|
|
116674
|
+
const response = await datastoreImpl.invokeStreamingRPC("BatchGetDocuments", datastoreImpl.serializer.databaseId, ResourcePath.emptyPath(), request, keys.length);
|
|
116675
|
+
const docs = new Map;
|
|
116676
|
+
response.forEach((proto) => {
|
|
116677
|
+
const doc = fromBatchGetDocumentsResponse(datastoreImpl.serializer, proto);
|
|
116678
|
+
docs.set(doc.key.toString(), doc);
|
|
116679
|
+
});
|
|
116680
|
+
const result = [];
|
|
116681
|
+
keys.forEach((key) => {
|
|
116682
|
+
const doc = docs.get(key.toString());
|
|
116683
|
+
hardAssert(!!doc, 55234, {
|
|
116684
|
+
key
|
|
116685
|
+
});
|
|
116686
|
+
result.push(doc);
|
|
116687
|
+
});
|
|
116688
|
+
return result;
|
|
116689
|
+
}
|
|
116702
116690
|
function newPersistentWriteStream(datastore, queue, listener) {
|
|
116703
116691
|
const datastoreImpl = debugCast(datastore);
|
|
116704
116692
|
datastoreImpl.verifyInitialized();
|
|
@@ -125371,6 +125359,172 @@ class AsyncObserver {
|
|
|
125371
125359
|
}, 0);
|
|
125372
125360
|
}
|
|
125373
125361
|
}
|
|
125362
|
+
class Transaction2 {
|
|
125363
|
+
constructor(datastore) {
|
|
125364
|
+
this.datastore = datastore;
|
|
125365
|
+
this.readVersions = new Map;
|
|
125366
|
+
this.mutations = [];
|
|
125367
|
+
this.committed = false;
|
|
125368
|
+
this.lastTransactionError = null;
|
|
125369
|
+
this.writtenDocs = new Set;
|
|
125370
|
+
}
|
|
125371
|
+
async lookup(keys) {
|
|
125372
|
+
this.ensureCommitNotCalled();
|
|
125373
|
+
if (this.mutations.length > 0) {
|
|
125374
|
+
this.lastTransactionError = new FirestoreError(Code.INVALID_ARGUMENT, "Firestore transactions require all reads to be executed before all writes.");
|
|
125375
|
+
throw this.lastTransactionError;
|
|
125376
|
+
}
|
|
125377
|
+
const docs = await invokeBatchGetDocumentsRpc(this.datastore, keys);
|
|
125378
|
+
docs.forEach((doc2) => this.recordVersion(doc2));
|
|
125379
|
+
return docs;
|
|
125380
|
+
}
|
|
125381
|
+
set(key, data) {
|
|
125382
|
+
this.write(data.toMutation(key, this.precondition(key)));
|
|
125383
|
+
this.writtenDocs.add(key.toString());
|
|
125384
|
+
}
|
|
125385
|
+
update(key, data) {
|
|
125386
|
+
try {
|
|
125387
|
+
this.write(data.toMutation(key, this.preconditionForUpdate(key)));
|
|
125388
|
+
} catch (e) {
|
|
125389
|
+
this.lastTransactionError = e;
|
|
125390
|
+
}
|
|
125391
|
+
this.writtenDocs.add(key.toString());
|
|
125392
|
+
}
|
|
125393
|
+
delete(key) {
|
|
125394
|
+
this.write(new DeleteMutation(key, this.precondition(key)));
|
|
125395
|
+
this.writtenDocs.add(key.toString());
|
|
125396
|
+
}
|
|
125397
|
+
async commit() {
|
|
125398
|
+
this.ensureCommitNotCalled();
|
|
125399
|
+
if (this.lastTransactionError) {
|
|
125400
|
+
throw this.lastTransactionError;
|
|
125401
|
+
}
|
|
125402
|
+
const unwritten = this.readVersions;
|
|
125403
|
+
this.mutations.forEach((mutation) => {
|
|
125404
|
+
unwritten.delete(mutation.key.toString());
|
|
125405
|
+
});
|
|
125406
|
+
unwritten.forEach((_, path) => {
|
|
125407
|
+
const key = DocumentKey.fromPath(path);
|
|
125408
|
+
this.mutations.push(new VerifyMutation(key, this.precondition(key)));
|
|
125409
|
+
});
|
|
125410
|
+
await invokeCommitRpc(this.datastore, this.mutations);
|
|
125411
|
+
this.committed = true;
|
|
125412
|
+
}
|
|
125413
|
+
recordVersion(doc2) {
|
|
125414
|
+
let docVersion;
|
|
125415
|
+
if (doc2.isFoundDocument()) {
|
|
125416
|
+
docVersion = doc2.version;
|
|
125417
|
+
} else if (doc2.isNoDocument()) {
|
|
125418
|
+
docVersion = SnapshotVersion.min();
|
|
125419
|
+
} else {
|
|
125420
|
+
throw fail(50498, {
|
|
125421
|
+
documentName: doc2.constructor.name
|
|
125422
|
+
});
|
|
125423
|
+
}
|
|
125424
|
+
const existingVersion = this.readVersions.get(doc2.key.toString());
|
|
125425
|
+
if (existingVersion) {
|
|
125426
|
+
if (!docVersion.isEqual(existingVersion)) {
|
|
125427
|
+
throw new FirestoreError(Code.ABORTED, "Document version changed between two reads.");
|
|
125428
|
+
}
|
|
125429
|
+
} else {
|
|
125430
|
+
this.readVersions.set(doc2.key.toString(), docVersion);
|
|
125431
|
+
}
|
|
125432
|
+
}
|
|
125433
|
+
precondition(key) {
|
|
125434
|
+
const version6 = this.readVersions.get(key.toString());
|
|
125435
|
+
if (!this.writtenDocs.has(key.toString()) && version6) {
|
|
125436
|
+
if (version6.isEqual(SnapshotVersion.min())) {
|
|
125437
|
+
return Precondition.exists(false);
|
|
125438
|
+
} else {
|
|
125439
|
+
return Precondition.updateTime(version6);
|
|
125440
|
+
}
|
|
125441
|
+
} else {
|
|
125442
|
+
return Precondition.none();
|
|
125443
|
+
}
|
|
125444
|
+
}
|
|
125445
|
+
preconditionForUpdate(key) {
|
|
125446
|
+
const version6 = this.readVersions.get(key.toString());
|
|
125447
|
+
if (!this.writtenDocs.has(key.toString()) && version6) {
|
|
125448
|
+
if (version6.isEqual(SnapshotVersion.min())) {
|
|
125449
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, "Can't update a document that doesn't exist.");
|
|
125450
|
+
}
|
|
125451
|
+
return Precondition.updateTime(version6);
|
|
125452
|
+
} else {
|
|
125453
|
+
return Precondition.exists(true);
|
|
125454
|
+
}
|
|
125455
|
+
}
|
|
125456
|
+
write(mutation) {
|
|
125457
|
+
this.ensureCommitNotCalled();
|
|
125458
|
+
this.mutations.push(mutation);
|
|
125459
|
+
}
|
|
125460
|
+
ensureCommitNotCalled() {}
|
|
125461
|
+
}
|
|
125462
|
+
|
|
125463
|
+
class TransactionRunner {
|
|
125464
|
+
constructor(asyncQueue, datastore, options2, updateFunction, deferred) {
|
|
125465
|
+
this.asyncQueue = asyncQueue;
|
|
125466
|
+
this.datastore = datastore;
|
|
125467
|
+
this.options = options2;
|
|
125468
|
+
this.updateFunction = updateFunction;
|
|
125469
|
+
this.deferred = deferred;
|
|
125470
|
+
this.attemptsRemaining = options2.maxAttempts;
|
|
125471
|
+
this.backoff = new ExponentialBackoff(this.asyncQueue, "transaction_retry");
|
|
125472
|
+
}
|
|
125473
|
+
run() {
|
|
125474
|
+
this.attemptsRemaining -= 1;
|
|
125475
|
+
this.runWithBackOff();
|
|
125476
|
+
}
|
|
125477
|
+
runWithBackOff() {
|
|
125478
|
+
this.backoff.backoffAndRun(async () => {
|
|
125479
|
+
const transaction = new Transaction2(this.datastore);
|
|
125480
|
+
const userPromise = this.tryRunUpdateFunction(transaction);
|
|
125481
|
+
if (userPromise) {
|
|
125482
|
+
userPromise.then((result) => {
|
|
125483
|
+
this.asyncQueue.enqueueAndForget(() => {
|
|
125484
|
+
return transaction.commit().then(() => {
|
|
125485
|
+
this.deferred.resolve(result);
|
|
125486
|
+
}).catch((commitError) => {
|
|
125487
|
+
this.handleTransactionError(commitError);
|
|
125488
|
+
});
|
|
125489
|
+
});
|
|
125490
|
+
}).catch((userPromiseError) => {
|
|
125491
|
+
this.handleTransactionError(userPromiseError);
|
|
125492
|
+
});
|
|
125493
|
+
}
|
|
125494
|
+
});
|
|
125495
|
+
}
|
|
125496
|
+
tryRunUpdateFunction(transaction) {
|
|
125497
|
+
try {
|
|
125498
|
+
const userPromise = this.updateFunction(transaction);
|
|
125499
|
+
if (isNullOrUndefined(userPromise) || !userPromise.catch || !userPromise.then) {
|
|
125500
|
+
this.deferred.reject(Error("Transaction callback must return a Promise"));
|
|
125501
|
+
return null;
|
|
125502
|
+
}
|
|
125503
|
+
return userPromise;
|
|
125504
|
+
} catch (error) {
|
|
125505
|
+
this.deferred.reject(error);
|
|
125506
|
+
return null;
|
|
125507
|
+
}
|
|
125508
|
+
}
|
|
125509
|
+
handleTransactionError(error) {
|
|
125510
|
+
if (this.attemptsRemaining > 0 && this.isRetryableTransactionError(error)) {
|
|
125511
|
+
this.attemptsRemaining -= 1;
|
|
125512
|
+
this.asyncQueue.enqueueAndForget(() => {
|
|
125513
|
+
this.runWithBackOff();
|
|
125514
|
+
return Promise.resolve();
|
|
125515
|
+
});
|
|
125516
|
+
} else {
|
|
125517
|
+
this.deferred.reject(error);
|
|
125518
|
+
}
|
|
125519
|
+
}
|
|
125520
|
+
isRetryableTransactionError(error) {
|
|
125521
|
+
if (error?.name === "FirebaseError") {
|
|
125522
|
+
const code = error.code;
|
|
125523
|
+
return code === "aborted" || code === "failed-precondition" || code === "already-exists" || !isPermanentError(code);
|
|
125524
|
+
}
|
|
125525
|
+
return false;
|
|
125526
|
+
}
|
|
125527
|
+
}
|
|
125374
125528
|
var LOG_TAG$1 = "FirestoreClient";
|
|
125375
125529
|
var MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100;
|
|
125376
125530
|
var DOM_EXCEPTION_INVALID_STATE = 11;
|
|
@@ -125505,6 +125659,9 @@ async function ensureOnlineComponents(client2) {
|
|
|
125505
125659
|
function getSyncEngine(client2) {
|
|
125506
125660
|
return ensureOnlineComponents(client2).then((c) => c.syncEngine);
|
|
125507
125661
|
}
|
|
125662
|
+
function getDatastore(client2) {
|
|
125663
|
+
return ensureOnlineComponents(client2).then((c) => c.datastore);
|
|
125664
|
+
}
|
|
125508
125665
|
async function getEventManager(client2) {
|
|
125509
125666
|
const onlineComponentProvider = await ensureOnlineComponents(client2);
|
|
125510
125667
|
const eventManager = onlineComponentProvider.eventManager;
|
|
@@ -125553,6 +125710,14 @@ function firestoreClientWrite(client2, mutations) {
|
|
|
125553
125710
|
});
|
|
125554
125711
|
return deferred.promise;
|
|
125555
125712
|
}
|
|
125713
|
+
function firestoreClientTransaction(client2, updateFunction, options2) {
|
|
125714
|
+
const deferred = new Deferred2;
|
|
125715
|
+
client2.asyncQueue.enqueueAndForget(async () => {
|
|
125716
|
+
const datastore = await getDatastore(client2);
|
|
125717
|
+
new TransactionRunner(client2.asyncQueue, datastore, options2, updateFunction, deferred).run();
|
|
125718
|
+
});
|
|
125719
|
+
return deferred.promise;
|
|
125720
|
+
}
|
|
125556
125721
|
function readDocumentViaSnapshotListener(eventManager, asyncQueue, key, options2, result) {
|
|
125557
125722
|
const wrappedObserver = new AsyncObserver({
|
|
125558
125723
|
next: (snap) => {
|
|
@@ -125907,7 +126072,7 @@ class ExpUserDataWriter extends AbstractUserDataWriter {
|
|
|
125907
126072
|
return new DocumentReference(this.firestore, null, key);
|
|
125908
126073
|
}
|
|
125909
126074
|
}
|
|
125910
|
-
// ../../node_modules/.bun/@firebase+firestore@4.16.0+
|
|
126075
|
+
// ../../node_modules/.bun/@firebase+firestore@4.16.0+80db1b7a714a6e79/node_modules/@firebase/firestore/dist/index.node.mjs
|
|
125911
126076
|
var import_grpc_js = __toESM(require_src3(), 1);
|
|
125912
126077
|
var import_proto_loader = __toESM(require_src2(), 1);
|
|
125913
126078
|
var name$12 = "@firebase/firestore";
|
|
@@ -126305,6 +126470,20 @@ function applyFirestoreDataConverter(converter, value, options2) {
|
|
|
126305
126470
|
}
|
|
126306
126471
|
return convertedValue;
|
|
126307
126472
|
}
|
|
126473
|
+
|
|
126474
|
+
class LiteUserDataWriter extends AbstractUserDataWriter {
|
|
126475
|
+
constructor(firestore) {
|
|
126476
|
+
super();
|
|
126477
|
+
this.firestore = firestore;
|
|
126478
|
+
}
|
|
126479
|
+
convertBytes(bytes) {
|
|
126480
|
+
return new Bytes(bytes);
|
|
126481
|
+
}
|
|
126482
|
+
convertReference(name5) {
|
|
126483
|
+
const key = this.convertDocumentKey(name5, this.firestore._databaseId);
|
|
126484
|
+
return new DocumentReference(this.firestore, null, key);
|
|
126485
|
+
}
|
|
126486
|
+
}
|
|
126308
126487
|
var encoder2 = newTextEncoder();
|
|
126309
126488
|
function lengthPrefixedString(o) {
|
|
126310
126489
|
const str = JSON.stringify(o);
|
|
@@ -126719,6 +126898,15 @@ function resultChangeType(type) {
|
|
|
126719
126898
|
return fail(61501, { type });
|
|
126720
126899
|
}
|
|
126721
126900
|
}
|
|
126901
|
+
var DEFAULT_TRANSACTION_OPTIONS = {
|
|
126902
|
+
maxAttempts: 5
|
|
126903
|
+
};
|
|
126904
|
+
function validateTransactionOptions(options2) {
|
|
126905
|
+
if (options2.maxAttempts < 1) {
|
|
126906
|
+
throw new FirestoreError(Code.INVALID_ARGUMENT, "Max attempts must be at least 1");
|
|
126907
|
+
}
|
|
126908
|
+
}
|
|
126909
|
+
|
|
126722
126910
|
class WriteBatch {
|
|
126723
126911
|
constructor(_firestore, _commitHandler) {
|
|
126724
126912
|
this._firestore = _firestore;
|
|
@@ -126776,6 +126964,79 @@ function validateReference(documentRef, firestore) {
|
|
|
126776
126964
|
return documentRef;
|
|
126777
126965
|
}
|
|
126778
126966
|
}
|
|
126967
|
+
|
|
126968
|
+
class Transaction$1 {
|
|
126969
|
+
constructor(_firestore, _transaction) {
|
|
126970
|
+
this._firestore = _firestore;
|
|
126971
|
+
this._transaction = _transaction;
|
|
126972
|
+
this._dataReader = newUserDataReader(_firestore);
|
|
126973
|
+
}
|
|
126974
|
+
get(documentRef) {
|
|
126975
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
126976
|
+
const userDataWriter = new LiteUserDataWriter(this._firestore);
|
|
126977
|
+
return this._transaction.lookup([ref._key]).then((docs) => {
|
|
126978
|
+
if (!docs || docs.length !== 1) {
|
|
126979
|
+
return fail(24041);
|
|
126980
|
+
}
|
|
126981
|
+
const doc3 = docs[0];
|
|
126982
|
+
if (doc3.isFoundDocument()) {
|
|
126983
|
+
return new DocumentSnapshot$1(this._firestore, userDataWriter, doc3.key, doc3, ref.converter);
|
|
126984
|
+
} else if (doc3.isNoDocument()) {
|
|
126985
|
+
return new DocumentSnapshot$1(this._firestore, userDataWriter, ref._key, null, ref.converter);
|
|
126986
|
+
} else {
|
|
126987
|
+
throw fail(18433, {
|
|
126988
|
+
doc: doc3
|
|
126989
|
+
});
|
|
126990
|
+
}
|
|
126991
|
+
});
|
|
126992
|
+
}
|
|
126993
|
+
set(documentRef, value, options2) {
|
|
126994
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
126995
|
+
const convertedValue = applyFirestoreDataConverter(ref.converter, value, options2);
|
|
126996
|
+
const parsed = parseSetData(this._dataReader, "Transaction.set", ref._key, convertedValue, ref.converter !== null, options2);
|
|
126997
|
+
this._transaction.set(ref._key, parsed);
|
|
126998
|
+
return this;
|
|
126999
|
+
}
|
|
127000
|
+
update(documentRef, fieldOrUpdateData, value, ...moreFieldsAndValues) {
|
|
127001
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
127002
|
+
fieldOrUpdateData = getModularInstance(fieldOrUpdateData);
|
|
127003
|
+
let parsed;
|
|
127004
|
+
if (typeof fieldOrUpdateData === "string" || fieldOrUpdateData instanceof FieldPath) {
|
|
127005
|
+
parsed = parseUpdateVarargs(this._dataReader, "Transaction.update", ref._key, fieldOrUpdateData, value, moreFieldsAndValues);
|
|
127006
|
+
} else {
|
|
127007
|
+
parsed = parseUpdateData(this._dataReader, "Transaction.update", ref._key, fieldOrUpdateData);
|
|
127008
|
+
}
|
|
127009
|
+
this._transaction.update(ref._key, parsed);
|
|
127010
|
+
return this;
|
|
127011
|
+
}
|
|
127012
|
+
delete(documentRef) {
|
|
127013
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
127014
|
+
this._transaction.delete(ref._key);
|
|
127015
|
+
return this;
|
|
127016
|
+
}
|
|
127017
|
+
}
|
|
127018
|
+
|
|
127019
|
+
class Transaction3 extends Transaction$1 {
|
|
127020
|
+
constructor(_firestore, _transaction) {
|
|
127021
|
+
super(_firestore, _transaction);
|
|
127022
|
+
this._firestore = _firestore;
|
|
127023
|
+
}
|
|
127024
|
+
get(documentRef) {
|
|
127025
|
+
const ref = validateReference(documentRef, this._firestore);
|
|
127026
|
+
const userDataWriter = new ExpUserDataWriter(this._firestore);
|
|
127027
|
+
return super.get(documentRef).then((liteDocumentSnapshot) => new DocumentSnapshot(this._firestore, userDataWriter, ref._key, liteDocumentSnapshot._document, new SnapshotMetadata(false, false), ref.converter));
|
|
127028
|
+
}
|
|
127029
|
+
}
|
|
127030
|
+
function runTransaction(firestore, updateFunction, options2) {
|
|
127031
|
+
firestore = cast(firestore, Firestore);
|
|
127032
|
+
const optionsWithDefaults = {
|
|
127033
|
+
...DEFAULT_TRANSACTION_OPTIONS,
|
|
127034
|
+
...options2
|
|
127035
|
+
};
|
|
127036
|
+
validateTransactionOptions(optionsWithDefaults);
|
|
127037
|
+
const client2 = ensureFirestoreConfigured(firestore);
|
|
127038
|
+
return firestoreClientTransaction(client2, (internalTransaction) => updateFunction(new Transaction3(firestore, internalTransaction)), optionsWithDefaults);
|
|
127039
|
+
}
|
|
126779
127040
|
function isPartialObserver(obj) {
|
|
126780
127041
|
return implementsAnyMethods2(obj, ["next", "error", "complete"]);
|
|
126781
127042
|
}
|
|
@@ -126920,7 +127181,7 @@ function writeBatch(firestore) {
|
|
|
126920
127181
|
}
|
|
126921
127182
|
var persistentCacheIndexManagerByFirestore = new WeakMap;
|
|
126922
127183
|
registerFirestore("node");
|
|
126923
|
-
// ../../node_modules/.bun/@firebase+functions@0.13.5+
|
|
127184
|
+
// ../../node_modules/.bun/@firebase+functions@0.13.5+80db1b7a714a6e79/node_modules/@firebase/functions/dist/esm/index.esm.js
|
|
126924
127185
|
var LONG_TYPE = "type.googleapis.com/google.protobuf.Int64Value";
|
|
126925
127186
|
var UNSIGNED_LONG_TYPE = "type.googleapis.com/google.protobuf.UInt64Value";
|
|
126926
127187
|
function mapValues(o, f) {
|
|
@@ -127485,7 +127746,7 @@ function httpsCallable(functionsInstance, name6, options2) {
|
|
|
127485
127746
|
return httpsCallable$1(getModularInstance(functionsInstance), name6, options2);
|
|
127486
127747
|
}
|
|
127487
127748
|
registerFunctions();
|
|
127488
|
-
// ../../node_modules/.bun/@firebase+storage@0.14.3+
|
|
127749
|
+
// ../../node_modules/.bun/@firebase+storage@0.14.3+80db1b7a714a6e79/node_modules/@firebase/storage/dist/node-esm/index.node.esm.js
|
|
127489
127750
|
var DEFAULT_HOST2 = "firebasestorage.googleapis.com";
|
|
127490
127751
|
var CONFIG_STORAGE_BUCKET_KEY = "storageBucket";
|
|
127491
127752
|
var DEFAULT_MAX_OPERATION_RETRY_TIME = 2 * 60 * 1000;
|
|
@@ -128962,7 +129223,7 @@ function registerStorage() {
|
|
|
128962
129223
|
registerVersion(name6, version8);
|
|
128963
129224
|
}
|
|
128964
129225
|
registerStorage();
|
|
128965
|
-
// ../../node_modules/.bun/@firebase+auth@1.13.3+
|
|
129226
|
+
// ../../node_modules/.bun/@firebase+auth@1.13.3+5d31dd782a334479/node_modules/@firebase/auth/dist/node-esm/totp-65577477.js
|
|
128966
129227
|
function _prodErrorMap2() {
|
|
128967
129228
|
return {
|
|
128968
129229
|
["dependent-sdk-initialized-before-auth"]: "Another Firebase SDK was initialized and is trying to use Auth before Auth is " + "initialized. Please be sure to call `initializeAuth` or `getAuth` before " + "starting any other Firebase SDK."
|
|
@@ -132562,10 +132823,10 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
132562
132823
|
}
|
|
132563
132824
|
const unlinked = targets.filter((target) => !target.linkId);
|
|
132564
132825
|
const unlinkedStatuses = await Promise.all(unlinked.map(async (target) => {
|
|
132565
|
-
const chatSnap = await getDocFromServer(doc(db, "chats", target.chatId))
|
|
132826
|
+
const chatSnap = await getDocFromServer(doc(db, "chats", target.chatId));
|
|
132566
132827
|
return {
|
|
132567
132828
|
chatId: target.chatId,
|
|
132568
|
-
active: chatSnap
|
|
132829
|
+
active: !chatSnap.exists() || chatSnap.data()?.deleted !== true
|
|
132569
132830
|
};
|
|
132570
132831
|
}));
|
|
132571
132832
|
for (const status of unlinkedStatuses) {
|
|
@@ -132589,6 +132850,10 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
132589
132850
|
await callFunction("submitReport", payload);
|
|
132590
132851
|
return true;
|
|
132591
132852
|
}
|
|
132853
|
+
async function submitBug(payload) {
|
|
132854
|
+
const result = await callFunction("submitBug", payload);
|
|
132855
|
+
return result || true;
|
|
132856
|
+
}
|
|
132592
132857
|
async function submitFeedback(payload) {
|
|
132593
132858
|
const result = await callFunction("submitFeedback", payload);
|
|
132594
132859
|
return result || true;
|
|
@@ -132791,7 +133056,7 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
132791
133056
|
return chatMessagesPage(snap, count, { reverse: messagesQuery.reverse });
|
|
132792
133057
|
}
|
|
132793
133058
|
async function readChatMessage(chatId, messageId) {
|
|
132794
|
-
const snap = await getDocFromServer(chatMessageDoc(chatId, messageId))
|
|
133059
|
+
const snap = await getDocFromServer(chatMessageDoc(chatId, messageId));
|
|
132795
133060
|
return messageRecordFromDoc(snap);
|
|
132796
133061
|
}
|
|
132797
133062
|
function cleanMessageWrite(message) {
|
|
@@ -132887,11 +133152,31 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
132887
133152
|
throw new Error("message ttl required");
|
|
132888
133153
|
}
|
|
132889
133154
|
const ttl = options2?.permanent === true ? null : Timestamp2.fromMillis(ttlMs);
|
|
132890
|
-
const updateItems = async (nextTtl = ttl, targetItems = items) => {
|
|
133155
|
+
const updateItems = async (nextTtl = ttl, targetItems = items, { shortenOnly = false } = {}) => {
|
|
132891
133156
|
const updated2 = [];
|
|
132892
|
-
for (
|
|
132893
|
-
|
|
132894
|
-
|
|
133157
|
+
for (let index = 0;index < targetItems.length; index += CHAT_TTL_WRITE_BATCH_SIZE) {
|
|
133158
|
+
const chunk = targetItems.slice(index, index + CHAT_TTL_WRITE_BATCH_SIZE);
|
|
133159
|
+
if (shortenOnly) {
|
|
133160
|
+
const chunkUpdated = await runTransaction(db, async (transaction) => {
|
|
133161
|
+
const refs = chunk.map((item) => chatMessageDoc(chatId, item.id));
|
|
133162
|
+
const snapshots = await Promise.all(refs.map((messageRef) => transaction.get(messageRef)));
|
|
133163
|
+
const eligible = [];
|
|
133164
|
+
snapshots.forEach((snapshot, snapshotIndex) => {
|
|
133165
|
+
const currentTtlMs = timestampMs(snapshot?.data?.()?.ttl, null);
|
|
133166
|
+
if (snapshot?.exists?.() && currentTtlMs != null && currentTtlMs > ttlMs) {
|
|
133167
|
+
transaction.update(refs[snapshotIndex], { ttl: nextTtl });
|
|
133168
|
+
eligible.push(chunk[snapshotIndex]);
|
|
133169
|
+
}
|
|
133170
|
+
});
|
|
133171
|
+
return eligible;
|
|
133172
|
+
});
|
|
133173
|
+
updated2.push(...chunkUpdated);
|
|
133174
|
+
continue;
|
|
133175
|
+
}
|
|
133176
|
+
const batch = writeBatch(db);
|
|
133177
|
+
chunk.forEach((item) => batch.update(chatMessageDoc(chatId, item.id), { ttl: nextTtl }));
|
|
133178
|
+
await batch.commit();
|
|
133179
|
+
updated2.push(...chunk);
|
|
132895
133180
|
}
|
|
132896
133181
|
return updated2;
|
|
132897
133182
|
};
|
|
@@ -132909,6 +133194,10 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
132909
133194
|
throw error;
|
|
132910
133195
|
}
|
|
132911
133196
|
}
|
|
133197
|
+
if (options2?.releaseMediaHold !== true) {
|
|
133198
|
+
const updated2 = await updateItems(ttl, items, { shortenOnly: options2?.shortenOnly === true });
|
|
133199
|
+
return { updated: updated2.length };
|
|
133200
|
+
}
|
|
132912
133201
|
let updated = [];
|
|
132913
133202
|
try {
|
|
132914
133203
|
updated = await updateItems();
|
|
@@ -132948,7 +133237,7 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
132948
133237
|
requireUid(uid);
|
|
132949
133238
|
if (!entryId)
|
|
132950
133239
|
throw new Error("chat entry id required");
|
|
132951
|
-
const snap = await getDocFromServer(doc(db, "users", uid, "chats", entryId))
|
|
133240
|
+
const snap = await getDocFromServer(doc(db, "users", uid, "chats", entryId));
|
|
132952
133241
|
return userChatRecordFromDoc(snap);
|
|
132953
133242
|
}
|
|
132954
133243
|
async function writeUserChat(uid, entryId, { body, tsMs, touchTs = false } = {}) {
|
|
@@ -133045,6 +133334,12 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
133045
133334
|
onUpdate?.(recordsFromSnapshot(snap));
|
|
133046
133335
|
}, onError);
|
|
133047
133336
|
}
|
|
133337
|
+
function watchAdminBugs(onUpdate, onError, options2 = {}) {
|
|
133338
|
+
const count = Math.min(positiveInt(options2?.count, 100), 250);
|
|
133339
|
+
return onSnapshot(query(collection(db, "bugs"), orderBy("createdAt", "desc"), limit(count)), (snap) => {
|
|
133340
|
+
onUpdate?.(recordsFromSnapshot(snap));
|
|
133341
|
+
}, onError);
|
|
133342
|
+
}
|
|
133048
133343
|
function watchAdminBots(onUpdate, onError) {
|
|
133049
133344
|
return onSnapshot(collection(db, "bots"), (snap) => {
|
|
133050
133345
|
onUpdate?.(recordsFromSnapshot(snap));
|
|
@@ -133218,6 +133513,9 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
133218
133513
|
push: pushInbox
|
|
133219
133514
|
},
|
|
133220
133515
|
admin: {
|
|
133516
|
+
bugs: {
|
|
133517
|
+
watch: watchAdminBugs
|
|
133518
|
+
},
|
|
133221
133519
|
reports: {
|
|
133222
133520
|
watchOffenders: watchAdminReportOffenders,
|
|
133223
133521
|
watchUser: watchAdminUserReports,
|
|
@@ -133248,6 +133546,9 @@ function createFirebaseCloud({ db, auth: auth3, getAuth: getAuth3, functions: fu
|
|
|
133248
133546
|
upload: uploadReportEvidence
|
|
133249
133547
|
}
|
|
133250
133548
|
},
|
|
133549
|
+
bugs: {
|
|
133550
|
+
submit: submitBug
|
|
133551
|
+
},
|
|
133251
133552
|
feedback: {
|
|
133252
133553
|
submit: submitFeedback
|
|
133253
133554
|
},
|
|
@@ -134806,57 +135107,203 @@ class ProfileStore {
|
|
|
134806
135107
|
// src/mcp.js
|
|
134807
135108
|
import { createInterface } from "readline";
|
|
134808
135109
|
import process4 from "process";
|
|
134809
|
-
|
|
134810
|
-
|
|
135110
|
+
// package.json
|
|
135111
|
+
var package_default = {
|
|
135112
|
+
name: "@glyphteck/veyl",
|
|
135113
|
+
version: "0.3.1",
|
|
135114
|
+
license: "Apache-2.0",
|
|
135115
|
+
type: "module",
|
|
135116
|
+
description: "Programmable Bun client for Veyl accounts, vaults, chat, and wallet payments.",
|
|
135117
|
+
exports: {
|
|
135118
|
+
".": "./dist/index.js"
|
|
135119
|
+
},
|
|
135120
|
+
bin: {
|
|
135121
|
+
veyl: "dist/cli.js"
|
|
135122
|
+
},
|
|
135123
|
+
files: [
|
|
135124
|
+
"dist",
|
|
135125
|
+
"docs",
|
|
135126
|
+
"README.md",
|
|
135127
|
+
"package.json"
|
|
135128
|
+
],
|
|
135129
|
+
engines: {
|
|
135130
|
+
bun: ">=1.3.0"
|
|
135131
|
+
},
|
|
135132
|
+
publishConfig: {
|
|
135133
|
+
access: "public"
|
|
135134
|
+
},
|
|
135135
|
+
scripts: {
|
|
135136
|
+
build: "bun build src/index.js src/cli.js --target=bun --outdir dist",
|
|
135137
|
+
prepack: "bun run build",
|
|
135138
|
+
start: "bun src/cli.js",
|
|
135139
|
+
lint: "eslint src --quiet"
|
|
135140
|
+
}
|
|
135141
|
+
};
|
|
135142
|
+
|
|
135143
|
+
// src/commands.js
|
|
135144
|
+
var stringProp = Object.freeze({ type: "string" });
|
|
135145
|
+
var numberProp = Object.freeze({ type: "number" });
|
|
135146
|
+
var booleanProp = Object.freeze({ type: "boolean" });
|
|
135147
|
+
var objectProp = Object.freeze({ type: "object" });
|
|
135148
|
+
function command({ name: name8, group, apiNames, description, properties = {}, required = [], paths = [], shortUsage = "", structuredUsage = "", cliInput, invoke, invokeCli, mcp = true }) {
|
|
135149
|
+
return Object.freeze({
|
|
134811
135150
|
name: name8,
|
|
135151
|
+
group,
|
|
135152
|
+
apiNames: Object.freeze(apiNames || []),
|
|
134812
135153
|
description,
|
|
134813
|
-
|
|
134814
|
-
|
|
134815
|
-
|
|
134816
|
-
|
|
134817
|
-
|
|
134818
|
-
|
|
134819
|
-
|
|
134820
|
-
|
|
134821
|
-
|
|
134822
|
-
|
|
134823
|
-
|
|
134824
|
-
var
|
|
134825
|
-
|
|
134826
|
-
|
|
134827
|
-
|
|
134828
|
-
|
|
134829
|
-
|
|
134830
|
-
|
|
134831
|
-
|
|
134832
|
-
|
|
134833
|
-
|
|
134834
|
-
|
|
134835
|
-
|
|
134836
|
-
|
|
134837
|
-
|
|
134838
|
-
|
|
134839
|
-
|
|
134840
|
-
|
|
134841
|
-
|
|
134842
|
-
|
|
134843
|
-
|
|
134844
|
-
|
|
134845
|
-
|
|
134846
|
-
|
|
134847
|
-
|
|
134848
|
-
|
|
134849
|
-
|
|
134850
|
-
|
|
134851
|
-
|
|
134852
|
-
|
|
134853
|
-
|
|
134854
|
-
|
|
134855
|
-
|
|
134856
|
-
|
|
134857
|
-
|
|
134858
|
-
|
|
134859
|
-
|
|
135154
|
+
properties: Object.freeze(properties),
|
|
135155
|
+
required: Object.freeze(required),
|
|
135156
|
+
paths: Object.freeze(paths.map((path) => Object.freeze(path))),
|
|
135157
|
+
shortUsage,
|
|
135158
|
+
structuredUsage,
|
|
135159
|
+
cliInput,
|
|
135160
|
+
invoke,
|
|
135161
|
+
invokeCli,
|
|
135162
|
+
mcp
|
|
135163
|
+
});
|
|
135164
|
+
}
|
|
135165
|
+
var optionsOnly = (_args, context) => ({ ...context.commandOptions });
|
|
135166
|
+
var peerInput = (args, context) => ({ ...context.commandOptions, peer: args[0] });
|
|
135167
|
+
var peerMessageInput = (args, context) => ({ ...context.commandOptions, peer: args[0], message: args.slice(1).join(" ") });
|
|
135168
|
+
var peerMessageIdInput = (args, context) => ({ ...context.commandOptions, peer: args[0], messageId: args[1] });
|
|
135169
|
+
var peerMessageActionInput = (args, context) => ({ ...context.commandOptions, peer: args[0], messageId: args[1], message: args.slice(2).join(" ") });
|
|
135170
|
+
var peerEmojiInput = (args, context) => ({ ...context.commandOptions, peer: args[0], messageId: args[1], emoji: args.slice(2).join(" ") });
|
|
135171
|
+
var peerSatsInput = (args, context) => ({ ...context.commandOptions, peer: args[0], sats: args[1] });
|
|
135172
|
+
var invoiceInput = (args, context) => ({ ...context.commandOptions, invoice: args[0] });
|
|
135173
|
+
var requestInput = (args, context) => ({ ...context.commandOptions, requestId: args[0] });
|
|
135174
|
+
var idInput = (args, context) => ({ ...context.commandOptions, id: args[0] });
|
|
135175
|
+
var withdrawalInput = (args, context) => ({ ...context.commandOptions, address: args[0], sats: args[1] });
|
|
135176
|
+
function accountInput(args, context) {
|
|
135177
|
+
return {
|
|
135178
|
+
username: args[0],
|
|
135179
|
+
network: context.options.network,
|
|
135180
|
+
webUrl: context.options.webUrl,
|
|
135181
|
+
saveCredential: context.options.saveCredential,
|
|
135182
|
+
onPasskeyUrl: context.onPasskeyUrl
|
|
135183
|
+
};
|
|
135184
|
+
}
|
|
135185
|
+
function vaultInput(_args, context) {
|
|
135186
|
+
return {
|
|
135187
|
+
secret: context.options.secret,
|
|
135188
|
+
saveSecret: context.options.saveSecret
|
|
135189
|
+
};
|
|
135190
|
+
}
|
|
135191
|
+
function invoiceCreateInput(args, context) {
|
|
135192
|
+
return {
|
|
135193
|
+
...context.commandOptions,
|
|
135194
|
+
sats: args[0] || 0,
|
|
135195
|
+
memo: context.commandOptions.memo || args.slice(1).join(" ") || undefined
|
|
135196
|
+
};
|
|
135197
|
+
}
|
|
135198
|
+
var HEADLESS_COMMANDS = Object.freeze([
|
|
135199
|
+
command({
|
|
135200
|
+
name: "account_create",
|
|
135201
|
+
group: "account",
|
|
135202
|
+
apiNames: ["create"],
|
|
135203
|
+
description: "Create a Veyl account headlessly.",
|
|
135204
|
+
properties: { username: stringProp, network: stringProp },
|
|
135205
|
+
required: ["username"],
|
|
135206
|
+
paths: [["create"], ["account", "create"]],
|
|
135207
|
+
shortUsage: "create [--passkey] @name",
|
|
135208
|
+
structuredUsage: "account create [--passkey] @name",
|
|
135209
|
+
cliInput: accountInput,
|
|
135210
|
+
invoke: (client2, input) => client2.account.create(input),
|
|
135211
|
+
invokeCli: (client2, input, context) => context.options.passkey ? client2.account.createPasskey(input) : client2.account.create({ username: input.username, network: input.network, saveCredential: input.saveCredential })
|
|
135212
|
+
}),
|
|
135213
|
+
command({
|
|
135214
|
+
name: "account_login",
|
|
135215
|
+
group: "account",
|
|
135216
|
+
apiNames: ["login"],
|
|
135217
|
+
description: "Log in with the local machine credential.",
|
|
135218
|
+
properties: { username: stringProp },
|
|
135219
|
+
paths: [["login"], ["account", "login"]],
|
|
135220
|
+
shortUsage: "login [--passkey] [@name]",
|
|
135221
|
+
structuredUsage: "account login [--passkey] [@name]",
|
|
135222
|
+
cliInput: accountInput,
|
|
135223
|
+
invoke: (client2, input) => client2.account.login(input),
|
|
135224
|
+
invokeCli: (client2, input, context) => context.options.passkey ? client2.account.loginPasskey(input) : client2.account.login({ username: input.username })
|
|
135225
|
+
}),
|
|
135226
|
+
command({ name: "account_me", group: "account", apiNames: ["me"], description: "Show the current local account.", paths: [["me"], ["account", "me"]], shortUsage: "me", structuredUsage: "account me", cliInput: optionsOnly, invoke: (client2) => client2.account.me() }),
|
|
135227
|
+
command({ name: "vault_create", group: "vault", apiNames: ["create"], description: "Create and upload the local encrypted vault.", properties: { secret: stringProp, saveSecret: booleanProp }, paths: [["vault", "create"]], structuredUsage: "vault create", cliInput: vaultInput, invoke: (client2, input) => client2.vault.create(input) }),
|
|
135228
|
+
command({ name: "vault_unlock", group: "vault", apiNames: ["unlock"], description: "Unlock the local vault.", properties: { secret: stringProp }, paths: [["unlock"], ["vault", "unlock"]], shortUsage: "unlock", structuredUsage: "vault unlock [--secret value]", cliInput: vaultInput, invoke: (client2, input) => client2.vault.unlock(input) }),
|
|
135229
|
+
command({ name: "vault_lock", group: "vault", apiNames: ["lock"], description: "Lock the wallet and chat session.", paths: [["lock"], ["vault", "lock"]], shortUsage: "lock", structuredUsage: "vault lock", cliInput: optionsOnly, invoke: (client2) => client2.vault.lock() }),
|
|
135230
|
+
command({ name: "chat_list", group: "chat", apiNames: ["list"], description: "List chats.", properties: { count: numberProp }, paths: [["chats"], ["chat", "list"]], shortUsage: "chats", structuredUsage: "chat list", cliInput: optionsOnly, invoke: (client2, input) => client2.chat.list(input) }),
|
|
135231
|
+
command({ name: "chat_read", group: "chat", apiNames: ["read"], description: "Read display messages from a chat.", properties: { peer: stringProp, count: numberProp }, required: ["peer"], paths: [["read"], ["chat", "read"]], shortUsage: "read @name", structuredUsage: "chat read @name", cliInput: peerInput, invoke: (client2, input) => client2.chat.read(input.peer, input) }),
|
|
135232
|
+
command({ name: "chat_send", group: "chat", apiNames: ["send"], description: "Send a text message.", properties: { peer: stringProp, message: stringProp }, required: ["peer", "message"], paths: [["say"], ["msg"], ["chat", "send"]], shortUsage: 'say @name "message"', structuredUsage: 'chat send @name "message"', cliInput: peerMessageInput, invoke: (client2, input) => client2.chat.send(input.peer, input.message, input) }),
|
|
135233
|
+
command({ name: "chat_reply", group: "chat", apiNames: ["reply"], description: "Reply to one displayed message or listen event.", properties: { peer: stringProp, messageId: stringProp, event: objectProp, message: stringProp }, required: ["message"], paths: [["reply"], ["chat", "reply"]], shortUsage: 'reply @name <message-id> "message"', structuredUsage: 'chat reply @name <message-id> "message"', cliInput: peerMessageActionInput, invoke: (client2, input) => client2.chat.reply(input.event || { peer: input.peer, messageId: input.messageId }, input.message, input) }),
|
|
135234
|
+
command({ name: "chat_react", group: "chat", apiNames: ["react"], description: "React to one displayed message.", properties: { peer: stringProp, messageId: stringProp, emoji: stringProp }, required: ["peer", "messageId", "emoji"], paths: [["react"], ["chat", "react"]], shortUsage: "react @name <message-id> <emoji>", structuredUsage: "chat react @name <message-id> <emoji>", cliInput: peerEmojiInput, invoke: (client2, input) => client2.chat.react(input.peer, input.messageId, input.emoji, input) }),
|
|
135235
|
+
command({ name: "chat_react_to", group: "chat", apiNames: ["react-to"], description: "React to a displayed message or listen event.", properties: { peer: stringProp, messageId: stringProp, event: objectProp, emoji: stringProp }, required: ["emoji"], paths: [["chat", "react-to"]], structuredUsage: "chat react-to @name <message-id> <emoji>", cliInput: peerEmojiInput, invoke: (client2, input) => client2.chat.reactTo(input.event || { peer: input.peer, messageId: input.messageId }, input.emoji, input) }),
|
|
135236
|
+
command({ name: "chat_unreact", group: "chat", apiNames: ["unreact"], description: "Remove your reaction from one displayed message.", properties: { peer: stringProp, messageId: stringProp }, required: ["peer", "messageId"], paths: [["unreact"], ["chat", "unreact"]], shortUsage: "unreact @name <message-id>", structuredUsage: "chat unreact @name <message-id>", cliInput: peerMessageIdInput, invoke: (client2, input) => client2.chat.unreact(input.peer, input.messageId, input) }),
|
|
135237
|
+
command({ name: "chat_save", group: "chat", apiNames: ["save"], description: "Keep one displayed message permanently.", properties: { peer: stringProp, messageId: stringProp }, required: ["peer", "messageId"], paths: [["save"], ["chat", "save"]], shortUsage: "save @name <message-id>", structuredUsage: "chat save @name <message-id>", cliInput: peerMessageIdInput, invoke: (client2, input) => client2.chat.save(input.peer, input.messageId, input) }),
|
|
135238
|
+
command({ name: "chat_unsave", group: "chat", apiNames: ["unsave"], description: "Return one displayed message to temporary retention.", properties: { peer: stringProp, messageId: stringProp }, required: ["peer", "messageId"], paths: [["unsave"], ["chat", "unsave"]], shortUsage: "unsave @name <message-id>", structuredUsage: "chat unsave @name <message-id>", cliInput: peerMessageIdInput, invoke: (client2, input) => client2.chat.unsave(input.peer, input.messageId, input) }),
|
|
135239
|
+
command({ name: "chat_delete_message", group: "chat", apiNames: ["delete"], description: "Delete one displayed message.", properties: { peer: stringProp, messageId: stringProp }, required: ["peer", "messageId"], paths: [["delete-message"], ["chat", "delete"]], shortUsage: "delete-message @name <message-id>", structuredUsage: "chat delete @name <message-id>", cliInput: peerMessageIdInput, invoke: (client2, input) => client2.chat.delete(input.peer, input.messageId, input) }),
|
|
135240
|
+
command({ name: "chat_delete", group: "chat", apiNames: ["delete-chat"], description: "Delete one chat.", properties: { peer: stringProp, cleanup: booleanProp }, required: ["peer"], paths: [["delete-chat"], ["chat", "delete-chat"]], shortUsage: "delete-chat @name", structuredUsage: "chat delete-chat @name", cliInput: peerInput, invoke: (client2, input) => client2.chat.deleteChat(input.peer, input) }),
|
|
135241
|
+
command({ name: "chat_retention", group: "chat", apiNames: ["retention"], description: "Set chat retention to seen or 24h.", properties: { peer: stringProp, retention: stringProp }, required: ["peer", "retention"], paths: [["retention"], ["chat", "retention"]], shortUsage: "retention @name seen|24h", structuredUsage: "chat retention @name seen|24h", cliInput: (args, context) => ({ ...context.commandOptions, peer: args[0], retention: args[1] }), invoke: (client2, input) => client2.chat.retention(input.peer, input.retention, input) }),
|
|
135242
|
+
command({ name: "money_receive", group: "money", apiNames: ["address", "receive"], description: "Get the static funding address.", paths: [["receive"], ["address"], ["money", "receive"], ["money", "address"]], shortUsage: "receive", structuredUsage: "money receive", cliInput: optionsOnly, invoke: (client2, input) => client2.money.receive(input) }),
|
|
135243
|
+
command({ name: "money_claim", group: "money", apiNames: ["claim"], description: "Claim static deposits and pending incoming transfers.", properties: { count: numberProp }, paths: [["claim"], ["money", "claim"]], shortUsage: "claim", structuredUsage: "money claim", cliInput: optionsOnly, invoke: (client2, input) => client2.money.claim(input) }),
|
|
135244
|
+
command({ name: "money_balance", group: "money", apiNames: ["balance"], description: "Read wallet balance.", paths: [["balance"], ["money", "balance"]], shortUsage: "balance", structuredUsage: "money balance", cliInput: optionsOnly, invoke: (client2, input) => client2.money.balance(input) }),
|
|
135245
|
+
command({ name: "money_send", group: "money", apiNames: ["send"], description: "Send sats to a peer.", properties: { peer: stringProp, sats: numberProp }, required: ["peer", "sats"], paths: [["send"], ["money", "send"]], shortUsage: "send @name 1000", structuredUsage: "money send @name 1000", cliInput: peerSatsInput, invoke: (client2, input) => client2.money.send(input.peer, input.sats, input) }),
|
|
135246
|
+
command({ name: "money_request", group: "money", apiNames: ["request"], description: "Request sats from a peer.", properties: { peer: stringProp, sats: numberProp }, required: ["peer", "sats"], paths: [["request"], ["money", "request"]], shortUsage: "request @name 1000", structuredUsage: "money request @name 1000", cliInput: peerSatsInput, invoke: (client2, input) => client2.money.request(input.peer, input.sats, input) }),
|
|
135247
|
+
command({ name: "money_pay", group: "money", apiNames: ["pay"], description: "Pay a chat payment request.", properties: { requestId: stringProp }, required: ["requestId"], paths: [["pay"], ["money", "pay"]], shortUsage: "pay <request-id>", structuredUsage: "money pay <request-id>", cliInput: requestInput, invoke: (client2, input) => client2.money.pay(input.requestId, input) }),
|
|
135248
|
+
command({ name: "money_invoice", group: "money", apiNames: ["invoice"], description: "Create a Lightning invoice.", properties: { sats: numberProp, memo: stringProp, expirySeconds: numberProp, includeSparkAddress: booleanProp, includeSparkInvoice: booleanProp }, paths: [["invoice"], ["money", "invoice"]], shortUsage: 'invoice 100 ["memo"]', structuredUsage: 'money invoice 100 ["memo"]', cliInput: invoiceCreateInput, invoke: (client2, input) => client2.money.invoice(input.sats || 0, input) }),
|
|
135249
|
+
command({ name: "money_pay_invoice", group: "money", apiNames: ["pay-invoice"], description: "Pay a Lightning or Spark invoice.", properties: { invoice: stringProp, type: stringProp, amountSats: numberProp, maxFeeSats: numberProp, preferSpark: booleanProp }, required: ["invoice"], paths: [["pay-invoice"], ["payinvoice"], ["money", "pay-invoice"]], shortUsage: "pay-invoice <invoice>", structuredUsage: "money pay-invoice <invoice>", cliInput: invoiceInput, invoke: (client2, input) => client2.money.payInvoice(input.invoice, input) }),
|
|
135250
|
+
command({ name: "lightning_quote", group: "money", apiNames: ["lightning-quote"], description: "Quote Lightning send fees.", properties: { invoice: stringProp, amountSats: numberProp }, required: ["invoice"], paths: [["money", "lightning-quote"]], structuredUsage: "money lightning-quote <invoice>", cliInput: invoiceInput, invoke: (client2, input) => client2.money.lightningQuote(input.invoice, input) }),
|
|
135251
|
+
command({ name: "lightning_pay", group: "money", apiNames: ["lightning-pay"], description: "Pay a Lightning invoice.", properties: { invoice: stringProp, amountSats: numberProp, amountSatsToSend: numberProp, maxFeeSats: numberProp, preferSpark: booleanProp }, required: ["invoice"], paths: [["money", "lightning-pay"]], structuredUsage: "money lightning-pay <invoice>", cliInput: invoiceInput, invoke: (client2, input) => client2.money.lightningPay(input.invoice, input) }),
|
|
135252
|
+
command({ name: "lightning_receive", group: "money", apiNames: ["lightning-receive"], description: "Read a Lightning receive request.", properties: { id: stringProp }, required: ["id"], paths: [["money", "lightning-receive"]], structuredUsage: "money lightning-receive <id>", cliInput: idInput, invoke: (client2, input) => client2.money.lightningReceive(input.id, input) }),
|
|
135253
|
+
command({ name: "lightning_send", group: "money", apiNames: ["lightning-send"], description: "Read a Lightning send request.", properties: { id: stringProp }, required: ["id"], paths: [["money", "lightning-send"]], structuredUsage: "money lightning-send <id>", cliInput: idInput, invoke: (client2, input) => client2.money.lightningSend(input.id, input) }),
|
|
135254
|
+
command({ name: "withdraw_quote", group: "money", apiNames: ["withdraw-quote"], description: "Quote an on-chain withdrawal.", properties: { address: stringProp, sats: numberProp }, required: ["address", "sats"], paths: [["withdraw-quote"], ["money", "withdraw-quote"]], shortUsage: "withdraw-quote <address> 1000", structuredUsage: "money withdraw-quote <address> 1000", cliInput: withdrawalInput, invoke: (client2, input) => client2.money.withdrawQuote(input.address, input.sats, input) }),
|
|
135255
|
+
command({ name: "withdraw_prepare", group: "money", apiNames: ["withdraw-prepare"], description: "Prepare an on-chain withdrawal review.", properties: { address: stringProp, sats: numberProp, speed: stringProp, deductFeeFromWithdrawalAmount: booleanProp }, required: ["address", "sats"], paths: [["withdraw-prepare"], ["money", "withdraw-prepare"]], shortUsage: "withdraw-prepare <address> 1000", structuredUsage: "money withdraw-prepare <address> 1000", cliInput: withdrawalInput, invoke: (client2, input) => client2.money.withdrawPrepare(input.address, input.sats, input) }),
|
|
135256
|
+
command({ name: "withdraw_send", group: "money", apiNames: ["withdraw"], description: "Send an on-chain withdrawal.", properties: { address: stringProp, sats: numberProp, speed: stringProp, deductFeeFromWithdrawalAmount: booleanProp }, required: ["address", "sats"], paths: [["withdraw"], ["money", "withdraw"]], shortUsage: "withdraw <address> 1000", structuredUsage: "money withdraw <address> 1000", cliInput: withdrawalInput, invoke: (client2, input) => client2.money.withdraw(input.address, input.sats, input) }),
|
|
135257
|
+
command({ name: "transactions_list", group: "transactions", apiNames: ["list"], description: "List wallet transactions.", properties: { count: numberProp, offset: numberProp }, paths: [["transactions"], ["txs"], ["money", "transactions"]], shortUsage: "transactions", structuredUsage: "money transactions", cliInput: optionsOnly, invoke: (client2, input) => client2.money.transactions(input) }),
|
|
135258
|
+
command({ name: "listen_start", group: "listen", apiNames: ["start"], description: "Listen for account events.", paths: [["listen"]], shortUsage: "listen", cliInput: optionsOnly, mcp: false, invokeCli: (client2, _input, context) => context.listen(client2) }),
|
|
135259
|
+
command({ name: "mcp_serve", group: "mcp", apiNames: ["serve"], description: "Serve MCP over stdio.", paths: [["mcp", "serve"]], structuredUsage: "mcp serve", cliInput: optionsOnly, mcp: false, invoke: (client2) => client2.mcp.serve() })
|
|
135260
|
+
]);
|
|
135261
|
+
var commandByName = new Map(HEADLESS_COMMANDS.map((item) => [item.name, item]));
|
|
135262
|
+
var cliPaths = HEADLESS_COMMANDS.flatMap((item) => item.paths.map((path) => ({ command: item, path }))).sort((a, b) => b.path.length - a.path.length);
|
|
135263
|
+
var MCP_TOOLS = Object.freeze(HEADLESS_COMMANDS.filter((item) => item.mcp).map((item) => Object.freeze({
|
|
135264
|
+
name: item.name,
|
|
135265
|
+
description: item.description,
|
|
135266
|
+
inputSchema: Object.freeze({
|
|
135267
|
+
type: "object",
|
|
135268
|
+
properties: item.properties,
|
|
135269
|
+
...item.required.length ? { required: item.required } : {}
|
|
135270
|
+
})
|
|
135271
|
+
})));
|
|
135272
|
+
var groups = ["account", "vault", "chat", "money", "mcp", "transactions", "listen"];
|
|
135273
|
+
var COMMANDS = Object.freeze(Object.fromEntries(groups.map((group) => [group, Object.freeze(HEADLESS_COMMANDS.filter((item) => item.group === group).flatMap((item) => item.apiNames))])));
|
|
135274
|
+
function invokeCommand(client2, name8, input = {}) {
|
|
135275
|
+
const selected = commandByName.get(name8);
|
|
135276
|
+
if (!selected?.invoke || !selected.mcp) {
|
|
135277
|
+
throw new Error(`unknown tool ${name8}`);
|
|
135278
|
+
}
|
|
135279
|
+
return selected.invoke(client2, input);
|
|
135280
|
+
}
|
|
135281
|
+
function resolveCliCommand(tokens = []) {
|
|
135282
|
+
for (const entry of cliPaths) {
|
|
135283
|
+
if (entry.path.every((part, index) => tokens[index] === part)) {
|
|
135284
|
+
return { command: entry.command, args: tokens.slice(entry.path.length) };
|
|
135285
|
+
}
|
|
135286
|
+
}
|
|
135287
|
+
return null;
|
|
135288
|
+
}
|
|
135289
|
+
function invokeCliCommand(client2, resolved, context) {
|
|
135290
|
+
const selected = resolved?.command;
|
|
135291
|
+
if (!selected) {
|
|
135292
|
+
throw new Error("command required");
|
|
135293
|
+
}
|
|
135294
|
+
const input = selected.cliInput?.(resolved.args, context) || {};
|
|
135295
|
+
const invoke = selected.invokeCli || selected.invoke;
|
|
135296
|
+
if (!invoke) {
|
|
135297
|
+
throw new Error(`CLI command unavailable: ${selected.name}`);
|
|
135298
|
+
}
|
|
135299
|
+
return invoke(client2, input, context);
|
|
135300
|
+
}
|
|
135301
|
+
function cliHelpLines(kind) {
|
|
135302
|
+
const field2 = kind === "structured" ? "structuredUsage" : "shortUsage";
|
|
135303
|
+
return HEADLESS_COMMANDS.map((item) => item[field2]).filter(Boolean);
|
|
135304
|
+
}
|
|
135305
|
+
|
|
135306
|
+
// src/mcp.js
|
|
134860
135307
|
function result(value) {
|
|
134861
135308
|
return {
|
|
134862
135309
|
content: [
|
|
@@ -134867,77 +135314,6 @@ function result(value) {
|
|
|
134867
135314
|
]
|
|
134868
135315
|
};
|
|
134869
135316
|
}
|
|
134870
|
-
async function callTool(client2, name8, args = {}) {
|
|
134871
|
-
if (name8 === "account_create")
|
|
134872
|
-
return client2.account.create(args);
|
|
134873
|
-
if (name8 === "account_login")
|
|
134874
|
-
return client2.account.login(args);
|
|
134875
|
-
if (name8 === "account_me")
|
|
134876
|
-
return client2.account.me();
|
|
134877
|
-
if (name8 === "vault_create")
|
|
134878
|
-
return client2.vault.create(args);
|
|
134879
|
-
if (name8 === "vault_unlock")
|
|
134880
|
-
return client2.vault.unlock(args);
|
|
134881
|
-
if (name8 === "vault_lock")
|
|
134882
|
-
return client2.vault.lock();
|
|
134883
|
-
if (name8 === "chat_list")
|
|
134884
|
-
return client2.chat.list(args);
|
|
134885
|
-
if (name8 === "chat_read")
|
|
134886
|
-
return client2.chat.read(args.peer, args);
|
|
134887
|
-
if (name8 === "chat_send")
|
|
134888
|
-
return client2.chat.send(args.peer, args.message, args);
|
|
134889
|
-
if (name8 === "chat_reply")
|
|
134890
|
-
return client2.chat.reply(args.event || { peer: args.peer, messageId: args.messageId }, args.message, args);
|
|
134891
|
-
if (name8 === "chat_react")
|
|
134892
|
-
return client2.chat.react(args.peer, args.messageId, args.emoji, args);
|
|
134893
|
-
if (name8 === "chat_react_to")
|
|
134894
|
-
return client2.chat.reactTo(args.event || { peer: args.peer, messageId: args.messageId }, args.emoji, args);
|
|
134895
|
-
if (name8 === "chat_unreact")
|
|
134896
|
-
return client2.chat.unreact(args.peer, args.messageId, args);
|
|
134897
|
-
if (name8 === "chat_save")
|
|
134898
|
-
return client2.chat.save(args.peer, args.messageId, args);
|
|
134899
|
-
if (name8 === "chat_unsave")
|
|
134900
|
-
return client2.chat.unsave(args.peer, args.messageId, args);
|
|
134901
|
-
if (name8 === "chat_delete_message")
|
|
134902
|
-
return client2.chat.delete(args.peer, args.messageId, args);
|
|
134903
|
-
if (name8 === "chat_delete")
|
|
134904
|
-
return client2.chat.deleteChat(args.peer, args);
|
|
134905
|
-
if (name8 === "chat_retention")
|
|
134906
|
-
return client2.chat.retention(args.peer, args.retention, args);
|
|
134907
|
-
if (name8 === "money_receive")
|
|
134908
|
-
return client2.money.receive(args);
|
|
134909
|
-
if (name8 === "money_claim")
|
|
134910
|
-
return client2.money.claim(args);
|
|
134911
|
-
if (name8 === "money_balance")
|
|
134912
|
-
return client2.money.balance(args);
|
|
134913
|
-
if (name8 === "money_send")
|
|
134914
|
-
return client2.money.send(args.peer, args.sats, args);
|
|
134915
|
-
if (name8 === "money_request")
|
|
134916
|
-
return client2.money.request(args.peer, args.sats, args);
|
|
134917
|
-
if (name8 === "money_pay")
|
|
134918
|
-
return client2.money.pay(args.requestId, args);
|
|
134919
|
-
if (name8 === "money_invoice")
|
|
134920
|
-
return client2.money.invoice(args.sats || 0, args);
|
|
134921
|
-
if (name8 === "money_pay_invoice")
|
|
134922
|
-
return client2.money.payInvoice(args.invoice, args);
|
|
134923
|
-
if (name8 === "lightning_quote")
|
|
134924
|
-
return client2.money.lightningQuote(args.invoice, args);
|
|
134925
|
-
if (name8 === "lightning_pay")
|
|
134926
|
-
return client2.money.lightningPay(args.invoice, args);
|
|
134927
|
-
if (name8 === "lightning_receive")
|
|
134928
|
-
return client2.money.lightningReceive(args.id, args);
|
|
134929
|
-
if (name8 === "lightning_send")
|
|
134930
|
-
return client2.money.lightningSend(args.id, args);
|
|
134931
|
-
if (name8 === "withdraw_quote")
|
|
134932
|
-
return client2.money.withdrawQuote(args.address, args.sats, args);
|
|
134933
|
-
if (name8 === "withdraw_prepare")
|
|
134934
|
-
return client2.money.withdrawPrepare(args.address, args.sats, args);
|
|
134935
|
-
if (name8 === "withdraw_send")
|
|
134936
|
-
return client2.money.withdraw(args.address, args.sats, args);
|
|
134937
|
-
if (name8 === "transactions_list")
|
|
134938
|
-
return client2.money.transactions(args);
|
|
134939
|
-
throw new Error(`unknown tool ${name8}`);
|
|
134940
|
-
}
|
|
134941
135317
|
function write(message) {
|
|
134942
135318
|
process4.stdout.write(`${JSON.stringify(message)}
|
|
134943
135319
|
`);
|
|
@@ -134968,13 +135344,13 @@ async function serveMcp(client2) {
|
|
|
134968
135344
|
result: {
|
|
134969
135345
|
protocolVersion: "2024-11-05",
|
|
134970
135346
|
capabilities: { tools: {} },
|
|
134971
|
-
serverInfo: { name: "veyl", version:
|
|
135347
|
+
serverInfo: { name: "veyl", version: package_default.version }
|
|
134972
135348
|
}
|
|
134973
135349
|
});
|
|
134974
135350
|
} else if (message.method === "tools/list") {
|
|
134975
|
-
write({ jsonrpc: "2.0", id: message.id, result: { tools:
|
|
135351
|
+
write({ jsonrpc: "2.0", id: message.id, result: { tools: MCP_TOOLS } });
|
|
134976
135352
|
} else if (message.method === "tools/call") {
|
|
134977
|
-
const toolResult = await
|
|
135353
|
+
const toolResult = await invokeCommand(client2, message.params?.name, message.params?.arguments || {});
|
|
134978
135354
|
write({ jsonrpc: "2.0", id: message.id, result: result(toolResult) });
|
|
134979
135355
|
} else if (message.id != null) {
|
|
134980
135356
|
write({ jsonrpc: "2.0", id: message.id, result: {} });
|
|
@@ -134987,15 +135363,6 @@ async function serveMcp(client2) {
|
|
|
134987
135363
|
|
|
134988
135364
|
// src/client.js
|
|
134989
135365
|
var API_VERSION = 1;
|
|
134990
|
-
var COMMANDS = Object.freeze({
|
|
134991
|
-
account: Object.freeze(["create", "login", "me"]),
|
|
134992
|
-
vault: Object.freeze(["create", "unlock", "lock"]),
|
|
134993
|
-
chat: Object.freeze(["list", "read", "send", "reply", "react", "react-to", "unreact", "save", "unsave", "delete", "delete-chat", "retention"]),
|
|
134994
|
-
money: Object.freeze(["address", "balance", "claim", "invoice", "lightning-quote", "lightning-pay", "lightning-receive", "lightning-send", "pay-invoice", "receive", "request", "send", "pay", "withdraw", "withdraw-prepare", "withdraw-quote"]),
|
|
134995
|
-
mcp: Object.freeze(["serve"]),
|
|
134996
|
-
transactions: Object.freeze(["list"]),
|
|
134997
|
-
listen: Object.freeze(["start"])
|
|
134998
|
-
});
|
|
134999
135366
|
|
|
135000
135367
|
class ClientNotReadyError extends Error {
|
|
135001
135368
|
constructor(feature) {
|
|
@@ -135565,7 +135932,6 @@ export {
|
|
|
135565
135932
|
signInHeadless,
|
|
135566
135933
|
runPasskeyBrowserFlow,
|
|
135567
135934
|
openRegistryAccountSession,
|
|
135568
|
-
openLegacyAccountSession,
|
|
135569
135935
|
openAccountSessionFromSecrets,
|
|
135570
135936
|
open,
|
|
135571
135937
|
headlessFunctionBaseUrl,
|