@decentnetwork/peer 0.1.157 → 0.1.158

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/peer.d.ts CHANGED
@@ -97,7 +97,28 @@ export declare class Peer {
97
97
  routes: number;
98
98
  targets: number;
99
99
  } | undefined;
100
- acceptFriendRequest(pubkey: string): Promise<void>;
100
+ /**
101
+ * Accept a friend request.
102
+ *
103
+ * `#pendingFriendRequests` is an in-memory cache, not the authority on what
104
+ * was asked. A host that remembers requests across a restart — beagle-web
105
+ * keeps them in IndexedDB, because a request usually arrives while the tab is
106
+ * closed — is doing the right thing, and refusing it here made every restored
107
+ * card permanently un-acceptable: click Accept, the SDK throws "no pending
108
+ * friend request", the card comes back, and the button reads as dead. That is
109
+ * the whole of the reported "Accept does not respond" on app.beagle.chat.
110
+ *
111
+ * Accepting is the host's decision. Take it, and let the host pass back what
112
+ * it remembered so the friend does not arrive nameless — anything missing is
113
+ * filled in by the userinfo exchange once the session comes up.
114
+ */
115
+ acceptFriendRequest(pubkey: string, opts?: {
116
+ name?: string;
117
+ description?: string;
118
+ hello?: string;
119
+ address?: string;
120
+ nospam?: number;
121
+ }): Promise<void>;
101
122
  /** Decline an inbound request.
102
123
  *
103
124
  * Also drops any friend record and session the request already created.
package/dist/peer.js CHANGED
@@ -1245,20 +1245,49 @@ export class Peer {
1245
1245
  lastFriendRequestDispatch() {
1246
1246
  return this.#lastFriendRequestDispatch;
1247
1247
  }
1248
- async acceptFriendRequest(pubkey) {
1248
+ /**
1249
+ * Accept a friend request.
1250
+ *
1251
+ * `#pendingFriendRequests` is an in-memory cache, not the authority on what
1252
+ * was asked. A host that remembers requests across a restart — beagle-web
1253
+ * keeps them in IndexedDB, because a request usually arrives while the tab is
1254
+ * closed — is doing the right thing, and refusing it here made every restored
1255
+ * card permanently un-acceptable: click Accept, the SDK throws "no pending
1256
+ * friend request", the card comes back, and the button reads as dead. That is
1257
+ * the whole of the reported "Accept does not respond" on app.beagle.chat.
1258
+ *
1259
+ * Accepting is the host's decision. Take it, and let the host pass back what
1260
+ * it remembered so the friend does not arrive nameless — anything missing is
1261
+ * filled in by the userinfo exchange once the session comes up.
1262
+ */
1263
+ async acceptFriendRequest(pubkey, opts) {
1249
1264
  const request = this.#pendingFriendRequests.get(pubkey);
1250
- if (!request) {
1251
- throw new Error("No pending friend request from this peer");
1265
+ if (!request && !opts) {
1266
+ // No cached request AND the caller told us nothing: it can still be
1267
+ // accepted, but say so, because it means the host is not passing on what
1268
+ // it knows and the friend will start out anonymous.
1269
+ this.#debugLog(`accepting ${pubkey} with no cached request and no details from the host`);
1270
+ }
1271
+ let key;
1272
+ try {
1273
+ key = base58ToBytes(pubkey);
1274
+ }
1275
+ catch {
1276
+ throw new Error(`Not a valid peer key: ${pubkey}`);
1252
1277
  }
1278
+ if (key.length !== 32) {
1279
+ throw new Error(`Not a valid peer key: ${pubkey}`);
1280
+ }
1281
+ const nospam = request?.nospam ?? opts?.nospam ?? 0;
1253
1282
  this.#pendingFriendRequests.delete(pubkey);
1254
1283
  this.#friends.set(pubkey, {
1255
1284
  pubkey,
1256
- userid: request.userid,
1257
- address: request.address,
1258
- nospam: request.nospam,
1259
- name: request.name,
1260
- description: request.description,
1261
- hello: request.hello,
1285
+ userid: request?.userid ?? pubkey,
1286
+ address: request?.address ?? opts?.address ?? carrierAddressFromPublicKey(key, nospam),
1287
+ nospam,
1288
+ name: request?.name ?? opts?.name ?? "",
1289
+ description: request?.description ?? opts?.description ?? "",
1290
+ hello: request?.hello ?? opts?.hello ?? "",
1262
1291
  status: "offline",
1263
1292
  acceptedAt: Date.now()
1264
1293
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decentnetwork/peer",
3
- "version": "0.1.157",
3
+ "version": "0.1.158",
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",