@unicitylabs/sphere-sdk 0.3.8 → 0.3.9
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/connect/index.cjs +770 -0
- package/dist/connect/index.cjs.map +1 -0
- package/dist/connect/index.d.cts +312 -0
- package/dist/connect/index.d.ts +312 -0
- package/dist/connect/index.js +747 -0
- package/dist/connect/index.js.map +1 -0
- package/dist/core/index.cjs +87 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +57 -1
- package/dist/core/index.d.ts +57 -1
- package/dist/core/index.js +87 -7
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +271 -0
- package/dist/impl/browser/connect/index.cjs.map +1 -0
- package/dist/impl/browser/connect/index.d.cts +137 -0
- package/dist/impl/browser/connect/index.d.ts +137 -0
- package/dist/impl/browser/connect/index.js +248 -0
- package/dist/impl/browser/connect/index.js.map +1 -0
- package/dist/impl/browser/index.cjs +167 -32
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +170 -33
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/connect/index.cjs +372 -0
- package/dist/impl/nodejs/connect/index.cjs.map +1 -0
- package/dist/impl/nodejs/connect/index.d.cts +178 -0
- package/dist/impl/nodejs/connect/index.d.ts +178 -0
- package/dist/impl/nodejs/connect/index.js +333 -0
- package/dist/impl/nodejs/connect/index.js.map +1 -0
- package/dist/impl/nodejs/index.cjs +114 -4
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +49 -0
- package/dist/impl/nodejs/index.d.ts +49 -0
- package/dist/impl/nodejs/index.js +117 -5
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +87 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +87 -7
- package/dist/index.js.map +1 -1
- package/package.json +31 -1
|
@@ -1199,6 +1199,8 @@ var NostrTransportProvider = class {
|
|
|
1199
1199
|
transferHandlers = /* @__PURE__ */ new Set();
|
|
1200
1200
|
paymentRequestHandlers = /* @__PURE__ */ new Set();
|
|
1201
1201
|
paymentRequestResponseHandlers = /* @__PURE__ */ new Set();
|
|
1202
|
+
readReceiptHandlers = /* @__PURE__ */ new Set();
|
|
1203
|
+
typingIndicatorHandlers = /* @__PURE__ */ new Set();
|
|
1202
1204
|
broadcastHandlers = /* @__PURE__ */ new Map();
|
|
1203
1205
|
eventCallbacks = /* @__PURE__ */ new Set();
|
|
1204
1206
|
constructor(config) {
|
|
@@ -1450,6 +1452,18 @@ var NostrTransportProvider = class {
|
|
|
1450
1452
|
const wrappedContent = senderNametag ? JSON.stringify({ senderNametag, text: content }) : content;
|
|
1451
1453
|
const giftWrap = import_nostr_js_sdk.NIP17.createGiftWrap(this.keyManager, nostrRecipient, wrappedContent);
|
|
1452
1454
|
await this.publishEvent(giftWrap);
|
|
1455
|
+
const selfWrapContent = JSON.stringify({
|
|
1456
|
+
selfWrap: true,
|
|
1457
|
+
originalId: giftWrap.id,
|
|
1458
|
+
recipientPubkey,
|
|
1459
|
+
senderNametag,
|
|
1460
|
+
text: content
|
|
1461
|
+
});
|
|
1462
|
+
const selfPubkey = this.keyManager.getPublicKeyHex();
|
|
1463
|
+
const selfGiftWrap = import_nostr_js_sdk.NIP17.createGiftWrap(this.keyManager, selfPubkey, selfWrapContent);
|
|
1464
|
+
this.publishEvent(selfGiftWrap).catch((err) => {
|
|
1465
|
+
this.log("Self-wrap publish failed:", err);
|
|
1466
|
+
});
|
|
1453
1467
|
this.emitEvent({
|
|
1454
1468
|
type: "message:sent",
|
|
1455
1469
|
timestamp: Date.now(),
|
|
@@ -1548,6 +1562,37 @@ var NostrTransportProvider = class {
|
|
|
1548
1562
|
this.paymentRequestResponseHandlers.add(handler);
|
|
1549
1563
|
return () => this.paymentRequestResponseHandlers.delete(handler);
|
|
1550
1564
|
}
|
|
1565
|
+
// ===========================================================================
|
|
1566
|
+
// Read Receipts
|
|
1567
|
+
// ===========================================================================
|
|
1568
|
+
async sendReadReceipt(recipientTransportPubkey, messageEventId) {
|
|
1569
|
+
if (!this.keyManager) throw new Error("Not initialized");
|
|
1570
|
+
const nostrRecipient = recipientTransportPubkey.length === 66 ? recipientTransportPubkey.slice(2) : recipientTransportPubkey;
|
|
1571
|
+
const event = import_nostr_js_sdk.NIP17.createReadReceipt(this.keyManager, nostrRecipient, messageEventId);
|
|
1572
|
+
await this.publishEvent(event);
|
|
1573
|
+
this.log("Sent read receipt for:", messageEventId, "to:", nostrRecipient.slice(0, 16));
|
|
1574
|
+
}
|
|
1575
|
+
onReadReceipt(handler) {
|
|
1576
|
+
this.readReceiptHandlers.add(handler);
|
|
1577
|
+
return () => this.readReceiptHandlers.delete(handler);
|
|
1578
|
+
}
|
|
1579
|
+
// ===========================================================================
|
|
1580
|
+
// Typing Indicators
|
|
1581
|
+
// ===========================================================================
|
|
1582
|
+
async sendTypingIndicator(recipientTransportPubkey) {
|
|
1583
|
+
if (!this.keyManager) throw new Error("Not initialized");
|
|
1584
|
+
const nostrRecipient = recipientTransportPubkey.length === 66 ? recipientTransportPubkey.slice(2) : recipientTransportPubkey;
|
|
1585
|
+
const content = JSON.stringify({
|
|
1586
|
+
type: "typing",
|
|
1587
|
+
senderNametag: this.identity?.nametag
|
|
1588
|
+
});
|
|
1589
|
+
const event = import_nostr_js_sdk.NIP17.createGiftWrap(this.keyManager, nostrRecipient, content);
|
|
1590
|
+
await this.publishEvent(event);
|
|
1591
|
+
}
|
|
1592
|
+
onTypingIndicator(handler) {
|
|
1593
|
+
this.typingIndicatorHandlers.add(handler);
|
|
1594
|
+
return () => this.typingIndicatorHandlers.delete(handler);
|
|
1595
|
+
}
|
|
1551
1596
|
/**
|
|
1552
1597
|
* Resolve any identifier to full peer information.
|
|
1553
1598
|
* Routes to the appropriate specific resolve method based on identifier format.
|
|
@@ -2001,11 +2046,74 @@ var NostrTransportProvider = class {
|
|
|
2001
2046
|
const pm = import_nostr_js_sdk.NIP17.unwrap(event, this.keyManager);
|
|
2002
2047
|
this.log("Gift wrap unwrapped, sender:", pm.senderPubkey?.slice(0, 16), "kind:", pm.kind);
|
|
2003
2048
|
if (pm.senderPubkey === this.keyManager.getPublicKeyHex()) {
|
|
2004
|
-
|
|
2049
|
+
try {
|
|
2050
|
+
const parsed = JSON.parse(pm.content);
|
|
2051
|
+
if (parsed?.selfWrap && parsed.recipientPubkey) {
|
|
2052
|
+
this.log("Self-wrap replay for recipient:", parsed.recipientPubkey?.slice(0, 16));
|
|
2053
|
+
const message2 = {
|
|
2054
|
+
id: parsed.originalId || pm.eventId,
|
|
2055
|
+
senderTransportPubkey: pm.senderPubkey,
|
|
2056
|
+
senderNametag: parsed.senderNametag,
|
|
2057
|
+
recipientTransportPubkey: parsed.recipientPubkey,
|
|
2058
|
+
content: parsed.text ?? "",
|
|
2059
|
+
timestamp: pm.timestamp * 1e3,
|
|
2060
|
+
encrypted: true,
|
|
2061
|
+
isSelfWrap: true
|
|
2062
|
+
};
|
|
2063
|
+
for (const handler of this.messageHandlers) {
|
|
2064
|
+
try {
|
|
2065
|
+
handler(message2);
|
|
2066
|
+
} catch (e) {
|
|
2067
|
+
this.log("Self-wrap handler error:", e);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
} catch {
|
|
2073
|
+
}
|
|
2074
|
+
this.log("Skipping own non-self-wrap message");
|
|
2005
2075
|
return;
|
|
2006
2076
|
}
|
|
2007
|
-
if (
|
|
2008
|
-
this.log("
|
|
2077
|
+
if ((0, import_nostr_js_sdk.isReadReceipt)(pm)) {
|
|
2078
|
+
this.log("Read receipt from:", pm.senderPubkey?.slice(0, 16), "for:", pm.replyToEventId);
|
|
2079
|
+
if (pm.replyToEventId) {
|
|
2080
|
+
const receipt = {
|
|
2081
|
+
senderTransportPubkey: pm.senderPubkey,
|
|
2082
|
+
messageEventId: pm.replyToEventId,
|
|
2083
|
+
timestamp: pm.timestamp * 1e3
|
|
2084
|
+
};
|
|
2085
|
+
for (const handler of this.readReceiptHandlers) {
|
|
2086
|
+
try {
|
|
2087
|
+
handler(receipt);
|
|
2088
|
+
} catch (e) {
|
|
2089
|
+
this.log("Read receipt handler error:", e);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
try {
|
|
2096
|
+
const parsed = JSON.parse(pm.content);
|
|
2097
|
+
if (parsed?.type === "typing") {
|
|
2098
|
+
this.log("Typing indicator from:", pm.senderPubkey?.slice(0, 16));
|
|
2099
|
+
const indicator = {
|
|
2100
|
+
senderTransportPubkey: pm.senderPubkey,
|
|
2101
|
+
senderNametag: parsed.senderNametag,
|
|
2102
|
+
timestamp: pm.timestamp * 1e3
|
|
2103
|
+
};
|
|
2104
|
+
for (const handler of this.typingIndicatorHandlers) {
|
|
2105
|
+
try {
|
|
2106
|
+
handler(indicator);
|
|
2107
|
+
} catch (e) {
|
|
2108
|
+
this.log("Typing handler error:", e);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
} catch {
|
|
2114
|
+
}
|
|
2115
|
+
if (!(0, import_nostr_js_sdk.isChatMessage)(pm)) {
|
|
2116
|
+
this.log("Skipping unknown message kind:", pm.kind);
|
|
2009
2117
|
return;
|
|
2010
2118
|
}
|
|
2011
2119
|
let content = pm.content;
|
|
@@ -2020,7 +2128,9 @@ var NostrTransportProvider = class {
|
|
|
2020
2128
|
}
|
|
2021
2129
|
this.log("DM received from:", senderNametag || pm.senderPubkey?.slice(0, 16), "content:", content?.slice(0, 50));
|
|
2022
2130
|
const message = {
|
|
2023
|
-
id
|
|
2131
|
+
// Use outer gift wrap event.id so it matches the sender's stored giftWrap.id.
|
|
2132
|
+
// This ensures read receipts reference an ID the sender recognizes.
|
|
2133
|
+
id: event.id,
|
|
2024
2134
|
senderTransportPubkey: pm.senderPubkey,
|
|
2025
2135
|
senderNametag,
|
|
2026
2136
|
content,
|