@unicitylabs/openclaw-unicity 0.5.4 → 0.5.5

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/channel.ts +16 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unicitylabs/openclaw-unicity",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Unicity wallet identity and encrypted DMs for OpenClaw agents — powered by Sphere SDK",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -44,7 +44,7 @@
44
44
  "dependencies": {
45
45
  "@clack/prompts": "^0.10.0",
46
46
  "@sinclair/typebox": "^0.34.48",
47
- "@unicitylabs/sphere-sdk": "^0.5.4"
47
+ "@unicitylabs/sphere-sdk": "^0.6.7"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "openclaw": "*"
package/src/channel.ts CHANGED
@@ -244,16 +244,27 @@ export const unicityChannelPlugin = {
244
244
 
245
245
  // Track DM start time and seen IDs to skip historical replays from the relay.
246
246
  // The SDK fires onDirectMessage for every cached/replayed DM on connect.
247
- const dmStartTime = Math.floor(Date.now() / 1000);
247
+ // msg.timestamp is milliseconds, so dmStartTime must be ms too.
248
+ const dmStartTime = Date.now();
248
249
  const seenDmIds = new Set<string>();
249
250
  const DM_SEEN_MAX = 1000;
250
251
 
251
252
  // Collect all known representations of "self" so we can detect echoed-back
252
- // messages. The SDK's built-in self-check compares transport pubkey against
253
- // chainPubkey, but those may differ in format (33-byte compressed vs 32-byte
254
- // x-only Nostr key), letting self-messages slip through.
253
+ // messages. We must track BOTH the 33-byte compressed chainPubkey (02/03…)
254
+ // and the 32-byte x-only Nostr transport key (chainPubkey without prefix).
255
+ // The SDK's own self-check in CommunicationsModule has a bug where it
256
+ // compares transport pubkey (32-byte) against chainPubkey (33-byte), which
257
+ // never matches — so self-messages can leak through to dmHandlers.
255
258
  const selfPubkeys = new Set<string>();
256
- if (sphere.identity?.chainPubkey) selfPubkeys.add(sphere.identity.chainPubkey);
259
+ if (sphere.identity?.chainPubkey) {
260
+ const cpk = sphere.identity.chainPubkey;
261
+ selfPubkeys.add(cpk);
262
+ // x-only transport key = compressed pubkey without the 02/03 prefix
263
+ if (cpk.length === 66 && (cpk.startsWith("02") || cpk.startsWith("03"))) {
264
+ selfPubkeys.add(cpk.slice(2));
265
+ }
266
+ }
267
+ // Also add the groupChat key (same value but grabbed independently for safety)
257
268
  const myNostrPubkey = sphere.groupChat?.getMyPublicKey?.() ?? null;
258
269
  if (myNostrPubkey) selfPubkeys.add(myNostrPubkey);
259
270