@decentnetwork/peer 0.1.147 → 0.1.149

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.
@@ -54,6 +54,7 @@ export class LegacyExpressClient {
54
54
  await this.#postEncrypted(friendUserId, friendEncrypted);
55
55
  }
56
56
  async pullOnce() {
57
+ this.#debugLog(`pullOnce: ${this.#nodes.length} node(s)`);
57
58
  if (!this.#nodes.length) {
58
59
  return;
59
60
  }
@@ -77,6 +78,9 @@ export class LegacyExpressClient {
77
78
  }
78
79
  const messages = parseExpressResponseFrames(body);
79
80
  if (messages.length === 0) {
81
+ // Silent until now: a body that arrives but parses to nothing looked
82
+ // exactly like an empty inbox.
83
+ this.#debugLog(`pullOnce: ${body.length} byte(s) from ${node.host} parsed to 0 frames`);
80
84
  continue;
81
85
  }
82
86
  this.#debugLog(`pullOnce got ${messages.length} offline frame(s) from ${node.host}:${node.port}`);
package/dist/peer.js CHANGED
@@ -571,7 +571,13 @@ export class Peer {
571
571
  if (this.#started) {
572
572
  return;
573
573
  }
574
- this.#keyPair = await loadOrCreateKeyPair(this.#opts.keyFile);
574
+ // An explicit keypair wins over the file. A browser holds its key in
575
+ // IndexedDB and passes it here; loading from keyFile regardless made the
576
+ // peer run as a DIFFERENT identity than the app thought it had — it
577
+ // announced under one userid, showed the user another, polled express for
578
+ // the wrong inbox, and every friend request sent to the visible userid
579
+ // reached an identity nobody was listening as.
580
+ this.#keyPair = this.#opts.keyPair ?? await loadOrCreateKeyPair(this.#opts.keyFile);
575
581
  this.#bootstrap = new LegacyBootstrapClient({
576
582
  nodes: this.#opts.bootstrapNodes,
577
583
  keyPair: this.#keyPair,
@@ -1,3 +1,4 @@
1
+ import type { KeyPair } from "../crypto/keypair.js";
1
2
  export type CompatibilityMode = "legacy";
2
3
  export type NetworkNode = {
3
4
  host: string;
@@ -99,6 +100,15 @@ export type PeerOptions = {
99
100
  * waits 30s for a datagram that cannot arrive, and everything downstream
100
101
  * of it never runs: self-announce (so nobody can find this peer) and the
101
102
  * express pull loop (so offline messages are never collected). */
103
+ /** Use THIS keypair instead of loading one from keyFile.
104
+ *
105
+ * For hosts where the key does not live on a filesystem — a browser holds
106
+ * it in IndexedDB. Without it, start() loaded from keyFile regardless and
107
+ * the peer ran as a DIFFERENT identity than the app believed it was: it
108
+ * announced under one userid while showing the user another, so friend
109
+ * requests sent to the visible one reached nobody and offline mail was
110
+ * polled for the wrong inbox. */
111
+ keyPair?: KeyPair;
102
112
  tcpOnlyBootstrap?: boolean;
103
113
  /** Turn on peer debug logging without env vars — the only route in from a
104
114
  * browser, where process.env does not exist. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.147",
3
+ "version": "0.1.149",
4
4
  "description": "Pure TypeScript port of Elastos Carrier (toxcore-derived) P2P messaging. DHT, onion routing, TCP relay, FlatBuffers app payloads, Express offline relay. Wire-compatible with iOS Beagle and the Carrier C SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",