@agentvault/agentvault 0.9.0 → 0.9.2
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/dist/channel.d.ts.map +1 -1
- package/dist/cli.js +200 -16
- package/dist/cli.js.map +3 -3
- package/dist/index.js +200 -16
- package/dist/index.js.map +3 -3
- package/dist/openclaw-entry.d.ts.map +1 -1
- package/dist/openclaw-entry.js +16 -8
- package/dist/openclaw-entry.js.map +2 -2
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAqB3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAMZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,QAAQ,EAER,UAAU,EAEX,MAAM,YAAY,CAAC;AAoDpB,qBAAa,aAAc,SAAQ,YAAY;IA0CjC,OAAO,CAAC,MAAM;IAzC1B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,sBAAsB,CAAc;IAC5C,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,SAAS,CAGH;IACd,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,eAAe,CAA8C;IACrE,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAA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B,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,gBAAgB;YAOV,qBAAqB;IAuCnC,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,kBAAkB;IAiH1B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;YACW,aAAa;CAmB5B"}
|
package/dist/cli.js
CHANGED
|
@@ -45522,9 +45522,18 @@ var init_channel = __esm({
|
|
|
45522
45522
|
scanStatus = scanResult.status;
|
|
45523
45523
|
}
|
|
45524
45524
|
this._appendHistory("agent", plaintext, topicId);
|
|
45525
|
+
const roomConvIds = /* @__PURE__ */ new Set();
|
|
45526
|
+
if (this._persisted?.rooms) {
|
|
45527
|
+
for (const room of Object.values(this._persisted.rooms)) {
|
|
45528
|
+
for (const cid of room.conversationIds) {
|
|
45529
|
+
roomConvIds.add(cid);
|
|
45530
|
+
}
|
|
45531
|
+
}
|
|
45532
|
+
}
|
|
45525
45533
|
const messageGroupId = randomUUID();
|
|
45526
45534
|
for (const [convId, session] of this._sessions) {
|
|
45527
45535
|
if (!session.activated) continue;
|
|
45536
|
+
if (roomConvIds.has(convId)) continue;
|
|
45528
45537
|
const encrypted = session.ratchet.encrypt(plaintext);
|
|
45529
45538
|
const transport = encryptedMessageToTransport(encrypted);
|
|
45530
45539
|
const msg = {
|
|
@@ -45670,6 +45679,10 @@ var init_channel = __esm({
|
|
|
45670
45679
|
if (conv.participantA !== myDeviceId && conv.participantB !== myDeviceId) {
|
|
45671
45680
|
continue;
|
|
45672
45681
|
}
|
|
45682
|
+
if (this._sessions.has(conv.id)) {
|
|
45683
|
+
conversationIds.push(conv.id);
|
|
45684
|
+
continue;
|
|
45685
|
+
}
|
|
45673
45686
|
const otherDeviceId = conv.participantA === myDeviceId ? conv.participantB : conv.participantA;
|
|
45674
45687
|
const otherMember = roomData.members.find((m2) => m2.deviceId === otherDeviceId);
|
|
45675
45688
|
if (!otherMember?.identityPublicKey) {
|
|
@@ -45679,13 +45692,12 @@ var init_channel = __esm({
|
|
|
45679
45692
|
continue;
|
|
45680
45693
|
}
|
|
45681
45694
|
const isInitiator = myDeviceId < otherDeviceId;
|
|
45695
|
+
const theirEphKey = otherMember.ephemeralPublicKey ?? otherMember.identityPublicKey;
|
|
45682
45696
|
const sharedSecret = performX3DH({
|
|
45683
45697
|
myIdentityPrivate: hexToBytes(identity.privateKey),
|
|
45684
45698
|
myEphemeralPrivate: hexToBytes(ephemeral.privateKey),
|
|
45685
45699
|
theirIdentityPublic: hexToBytes(otherMember.identityPublicKey),
|
|
45686
|
-
theirEphemeralPublic: hexToBytes(
|
|
45687
|
-
otherMember.ephemeralPublicKey ?? otherMember.identityPublicKey
|
|
45688
|
-
),
|
|
45700
|
+
theirEphemeralPublic: hexToBytes(theirEphKey),
|
|
45689
45701
|
isInitiator
|
|
45690
45702
|
});
|
|
45691
45703
|
const ratchet = isInitiator ? DoubleRatchet.initSender(sharedSecret, {
|
|
@@ -45757,9 +45769,11 @@ var init_channel = __esm({
|
|
|
45757
45769
|
this._ws.send(
|
|
45758
45770
|
JSON.stringify({
|
|
45759
45771
|
event: "room_message",
|
|
45760
|
-
|
|
45761
|
-
|
|
45762
|
-
|
|
45772
|
+
data: {
|
|
45773
|
+
room_id: roomId,
|
|
45774
|
+
recipients,
|
|
45775
|
+
message_type: messageType
|
|
45776
|
+
}
|
|
45763
45777
|
})
|
|
45764
45778
|
);
|
|
45765
45779
|
} else {
|
|
@@ -46185,6 +46199,23 @@ var init_channel = __esm({
|
|
|
46185
46199
|
if (this._persisted.hubAddress) {
|
|
46186
46200
|
payload2.hub_address = this._persisted.hubAddress;
|
|
46187
46201
|
}
|
|
46202
|
+
if (channelEntry.observerSession?.ratchetState) {
|
|
46203
|
+
try {
|
|
46204
|
+
const obsRatchet = DoubleRatchet.deserialize(channelEntry.observerSession.ratchetState);
|
|
46205
|
+
const obsEncrypted = obsRatchet.encrypt(text);
|
|
46206
|
+
const obsHeaderObj = {
|
|
46207
|
+
dhPublicKey: bytesToHex(obsEncrypted.header.dhPublicKey),
|
|
46208
|
+
previousChainLength: obsEncrypted.header.previousChainLength,
|
|
46209
|
+
messageNumber: obsEncrypted.header.messageNumber
|
|
46210
|
+
};
|
|
46211
|
+
payload2.observer_header_blob = Buffer.from(JSON.stringify(obsHeaderObj)).toString("hex");
|
|
46212
|
+
payload2.observer_ciphertext = bytesToHex(obsEncrypted.ciphertext);
|
|
46213
|
+
payload2.observer_nonce = bytesToHex(obsEncrypted.nonce);
|
|
46214
|
+
channelEntry.observerSession.ratchetState = obsRatchet.serialize();
|
|
46215
|
+
} catch (obsErr) {
|
|
46216
|
+
console.error("[SecureChannel] Observer encryption failed (sending without observer copy):", obsErr);
|
|
46217
|
+
}
|
|
46218
|
+
}
|
|
46188
46219
|
channelEntry.session.ratchetState = ratchet.serialize();
|
|
46189
46220
|
await this._persistState();
|
|
46190
46221
|
this._ws.send(
|
|
@@ -46481,13 +46512,20 @@ var init_channel = __esm({
|
|
|
46481
46512
|
return;
|
|
46482
46513
|
}
|
|
46483
46514
|
if (data.event === "message") {
|
|
46484
|
-
|
|
46515
|
+
try {
|
|
46516
|
+
await this._handleIncomingMessage(data.data);
|
|
46517
|
+
} catch (msgErr) {
|
|
46518
|
+
console.error(
|
|
46519
|
+
`[SecureChannel] Message handler failed for conv ${data.data?.conversation_id?.slice(0, 8) ?? "?"}...:`,
|
|
46520
|
+
msgErr
|
|
46521
|
+
);
|
|
46522
|
+
}
|
|
46485
46523
|
}
|
|
46486
46524
|
if (data.event === "room_joined") {
|
|
46487
46525
|
const d2 = data.data;
|
|
46488
46526
|
this.joinRoom({
|
|
46489
46527
|
roomId: d2.room_id,
|
|
46490
|
-
name: d2.name,
|
|
46528
|
+
name: d2.room_name ?? d2.name ?? "Room",
|
|
46491
46529
|
members: (d2.members || []).map((m2) => ({
|
|
46492
46530
|
deviceId: m2.device_id,
|
|
46493
46531
|
entityType: m2.entity_type,
|
|
@@ -46503,7 +46541,14 @@ var init_channel = __esm({
|
|
|
46503
46541
|
}).catch((err) => this.emit("error", err));
|
|
46504
46542
|
}
|
|
46505
46543
|
if (data.event === "room_message") {
|
|
46506
|
-
|
|
46544
|
+
try {
|
|
46545
|
+
await this._handleRoomMessage(data.data);
|
|
46546
|
+
} catch (rmErr) {
|
|
46547
|
+
console.error(
|
|
46548
|
+
`[SecureChannel] Room message handler failed:`,
|
|
46549
|
+
rmErr
|
|
46550
|
+
);
|
|
46551
|
+
}
|
|
46507
46552
|
}
|
|
46508
46553
|
if (data.event === "room_participant_added") {
|
|
46509
46554
|
const p2 = data.data;
|
|
@@ -46640,6 +46685,74 @@ var init_channel = __esm({
|
|
|
46640
46685
|
}
|
|
46641
46686
|
this.emit("a2a_channel_activated", actData);
|
|
46642
46687
|
}
|
|
46688
|
+
if (data.event === "a2a_observer_enabled") {
|
|
46689
|
+
const obsData = data.data || data;
|
|
46690
|
+
const obsChannelId = obsData.channel_id;
|
|
46691
|
+
const obsChannelEntry = this._persisted?.a2aChannels?.[obsChannelId];
|
|
46692
|
+
if (obsChannelEntry && this._persisted && this._ws) {
|
|
46693
|
+
try {
|
|
46694
|
+
const obsEphemeral = await generateEphemeralKeypair();
|
|
46695
|
+
const obsEphPubHex = bytesToHex(obsEphemeral.publicKey);
|
|
46696
|
+
const obsEphPrivHex = bytesToHex(obsEphemeral.privateKey);
|
|
46697
|
+
obsChannelEntry.pendingObserverEphemeralPrivateKey = obsEphPrivHex;
|
|
46698
|
+
await this._persistState();
|
|
46699
|
+
this._ws.send(
|
|
46700
|
+
JSON.stringify({
|
|
46701
|
+
event: "a2a_observer_key_submit",
|
|
46702
|
+
data: {
|
|
46703
|
+
channel_id: obsChannelId,
|
|
46704
|
+
ephemeral_key: obsEphPubHex,
|
|
46705
|
+
side: obsChannelEntry.role || "initiator"
|
|
46706
|
+
}
|
|
46707
|
+
})
|
|
46708
|
+
);
|
|
46709
|
+
console.log(
|
|
46710
|
+
`[SecureChannel] Observer key submitted for channel ${obsChannelId.slice(0, 8)}... (side=${obsChannelEntry.role})`
|
|
46711
|
+
);
|
|
46712
|
+
} catch (err) {
|
|
46713
|
+
console.error("[SecureChannel] Observer key submission failed:", err);
|
|
46714
|
+
}
|
|
46715
|
+
}
|
|
46716
|
+
}
|
|
46717
|
+
if (data.event === "a2a_observer_key_accepted") {
|
|
46718
|
+
const obsAccData = data.data || data;
|
|
46719
|
+
const obsAccChannelId = obsAccData.channel_id;
|
|
46720
|
+
const observerIdentityHex = obsAccData.observer_identity_key;
|
|
46721
|
+
const obsAccSide = obsAccData.side;
|
|
46722
|
+
const obsAccEntry = this._persisted?.a2aChannels?.[obsAccChannelId];
|
|
46723
|
+
if (obsAccEntry && obsAccEntry.pendingObserverEphemeralPrivateKey && this._persisted) {
|
|
46724
|
+
try {
|
|
46725
|
+
const myIdentityPrivate = hexToBytes(this._persisted.identityKeypair.privateKey);
|
|
46726
|
+
const myIdentityPublic = hexToBytes(this._persisted.identityKeypair.publicKey);
|
|
46727
|
+
const myObsEphemeralPrivate = hexToBytes(obsAccEntry.pendingObserverEphemeralPrivateKey);
|
|
46728
|
+
const ownerIdentityPublic = hexToBytes(observerIdentityHex);
|
|
46729
|
+
const obsSharedSecret = performX3DH({
|
|
46730
|
+
myIdentityPrivate,
|
|
46731
|
+
myEphemeralPrivate: myObsEphemeralPrivate,
|
|
46732
|
+
theirIdentityPublic: ownerIdentityPublic,
|
|
46733
|
+
theirEphemeralPublic: ownerIdentityPublic,
|
|
46734
|
+
// owner uses identity as ephemeral
|
|
46735
|
+
isInitiator: true
|
|
46736
|
+
});
|
|
46737
|
+
const identityKp = {
|
|
46738
|
+
publicKey: myIdentityPublic,
|
|
46739
|
+
privateKey: myIdentityPrivate,
|
|
46740
|
+
keyType: "ed25519"
|
|
46741
|
+
};
|
|
46742
|
+
const obsRatchet = DoubleRatchet.initSender(obsSharedSecret, identityKp);
|
|
46743
|
+
obsAccEntry.observerSession = {
|
|
46744
|
+
ratchetState: obsRatchet.serialize()
|
|
46745
|
+
};
|
|
46746
|
+
delete obsAccEntry.pendingObserverEphemeralPrivateKey;
|
|
46747
|
+
await this._persistState();
|
|
46748
|
+
console.log(
|
|
46749
|
+
`[SecureChannel] Observer ratchet initialized for channel ${obsAccChannelId.slice(0, 8)}... (side=${obsAccSide})`
|
|
46750
|
+
);
|
|
46751
|
+
} catch (err) {
|
|
46752
|
+
console.error("[SecureChannel] Observer ratchet init failed:", err);
|
|
46753
|
+
}
|
|
46754
|
+
}
|
|
46755
|
+
}
|
|
46643
46756
|
if (data.event === "a2a_channel_rejected") {
|
|
46644
46757
|
this.emit("a2a_channel_rejected", data.data || data);
|
|
46645
46758
|
}
|
|
@@ -47110,7 +47223,73 @@ ${messageText}`;
|
|
|
47110
47223
|
header_blob: msgData.header_blob,
|
|
47111
47224
|
ciphertext: msgData.ciphertext
|
|
47112
47225
|
});
|
|
47113
|
-
|
|
47226
|
+
let plaintext;
|
|
47227
|
+
try {
|
|
47228
|
+
plaintext = session.ratchet.decrypt(encrypted);
|
|
47229
|
+
} catch (decryptErr) {
|
|
47230
|
+
console.warn(
|
|
47231
|
+
`[SecureChannel] Room decrypt failed for conv ${convId.slice(0, 8)}...: ${String(decryptErr)}, re-initializing ratchet`
|
|
47232
|
+
);
|
|
47233
|
+
try {
|
|
47234
|
+
const roomEntry = this._persisted?.rooms ? Object.values(this._persisted.rooms).find(
|
|
47235
|
+
(r2) => r2.conversationIds.includes(convId)
|
|
47236
|
+
) : null;
|
|
47237
|
+
if (!roomEntry) throw new Error("Room not found for conversation");
|
|
47238
|
+
const otherMember = roomEntry.members.find(
|
|
47239
|
+
(m2) => m2.deviceId === msgData.sender_device_id
|
|
47240
|
+
);
|
|
47241
|
+
if (!otherMember?.identityPublicKey) throw new Error("No key for sender");
|
|
47242
|
+
const isInitiator = this._deviceId < msgData.sender_device_id;
|
|
47243
|
+
const identity = this._persisted.identityKeypair;
|
|
47244
|
+
const ephemeral = this._persisted.ephemeralKeypair;
|
|
47245
|
+
const sharedSecret = performX3DH({
|
|
47246
|
+
myIdentityPrivate: hexToBytes(identity.privateKey),
|
|
47247
|
+
myEphemeralPrivate: hexToBytes(ephemeral.privateKey),
|
|
47248
|
+
theirIdentityPublic: hexToBytes(otherMember.identityPublicKey),
|
|
47249
|
+
theirEphemeralPublic: hexToBytes(
|
|
47250
|
+
otherMember.ephemeralPublicKey ?? otherMember.identityPublicKey
|
|
47251
|
+
),
|
|
47252
|
+
isInitiator
|
|
47253
|
+
});
|
|
47254
|
+
const newRatchet = isInitiator ? DoubleRatchet.initSender(sharedSecret, {
|
|
47255
|
+
publicKey: hexToBytes(identity.publicKey),
|
|
47256
|
+
privateKey: hexToBytes(identity.privateKey),
|
|
47257
|
+
keyType: "ed25519"
|
|
47258
|
+
}) : DoubleRatchet.initReceiver(sharedSecret, {
|
|
47259
|
+
publicKey: hexToBytes(identity.publicKey),
|
|
47260
|
+
privateKey: hexToBytes(identity.privateKey),
|
|
47261
|
+
keyType: "ed25519"
|
|
47262
|
+
});
|
|
47263
|
+
session.ratchet = newRatchet;
|
|
47264
|
+
session.activated = false;
|
|
47265
|
+
this._persisted.sessions[convId] = {
|
|
47266
|
+
ownerDeviceId: session.ownerDeviceId,
|
|
47267
|
+
ratchetState: newRatchet.serialize(),
|
|
47268
|
+
activated: false
|
|
47269
|
+
};
|
|
47270
|
+
await this._persistState();
|
|
47271
|
+
console.log(
|
|
47272
|
+
`[SecureChannel] Room ratchet re-initialized for conv ${convId.slice(0, 8)}...`
|
|
47273
|
+
);
|
|
47274
|
+
plaintext = session.ratchet.decrypt(encrypted);
|
|
47275
|
+
} catch (reinitErr) {
|
|
47276
|
+
console.error(
|
|
47277
|
+
`[SecureChannel] Room ratchet re-init failed for conv ${convId.slice(0, 8)}...:`,
|
|
47278
|
+
reinitErr
|
|
47279
|
+
);
|
|
47280
|
+
return;
|
|
47281
|
+
}
|
|
47282
|
+
}
|
|
47283
|
+
let messageText;
|
|
47284
|
+
let messageType;
|
|
47285
|
+
try {
|
|
47286
|
+
const parsed = JSON.parse(plaintext);
|
|
47287
|
+
messageType = parsed.type || "message";
|
|
47288
|
+
messageText = parsed.text || plaintext;
|
|
47289
|
+
} catch {
|
|
47290
|
+
messageType = "message";
|
|
47291
|
+
messageText = plaintext;
|
|
47292
|
+
}
|
|
47114
47293
|
if (!session.activated) {
|
|
47115
47294
|
session.activated = true;
|
|
47116
47295
|
console.log(
|
|
@@ -47125,16 +47304,17 @@ ${messageText}`;
|
|
|
47125
47304
|
messageId: msgData.message_id ?? "",
|
|
47126
47305
|
conversationId: convId,
|
|
47127
47306
|
timestamp: msgData.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
47128
|
-
messageType
|
|
47307
|
+
messageType,
|
|
47308
|
+
roomId: msgData.room_id
|
|
47129
47309
|
};
|
|
47130
47310
|
this.emit("room_message", {
|
|
47131
47311
|
roomId: msgData.room_id,
|
|
47132
47312
|
senderDeviceId: msgData.sender_device_id,
|
|
47133
|
-
plaintext,
|
|
47134
|
-
messageType
|
|
47313
|
+
plaintext: messageText,
|
|
47314
|
+
messageType,
|
|
47135
47315
|
timestamp: msgData.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
47136
47316
|
});
|
|
47137
|
-
this.config.onMessage?.(
|
|
47317
|
+
this.config.onMessage?.(messageText, metadata);
|
|
47138
47318
|
}
|
|
47139
47319
|
/**
|
|
47140
47320
|
* Find the pairwise conversation ID for a given sender in a room.
|
|
@@ -47222,8 +47402,12 @@ ${messageText}`;
|
|
|
47222
47402
|
since = msg.created_at;
|
|
47223
47403
|
totalProcessed++;
|
|
47224
47404
|
} catch (err) {
|
|
47225
|
-
|
|
47226
|
-
|
|
47405
|
+
console.warn(
|
|
47406
|
+
`[SecureChannel] Sync decrypt failed for msg ${msg.id.slice(0, 8)}... in conv ${msg.conversation_id.slice(0, 8)}...: ${String(err)}`
|
|
47407
|
+
);
|
|
47408
|
+
this._persisted.lastMessageTimestamp = msg.created_at;
|
|
47409
|
+
since = msg.created_at;
|
|
47410
|
+
continue;
|
|
47227
47411
|
}
|
|
47228
47412
|
}
|
|
47229
47413
|
await this._persistState();
|