nostr-double-ratchet 0.0.37 → 0.0.48
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/README.md +52 -15
- package/dist/AppKeys.d.ts +52 -0
- package/dist/AppKeys.d.ts.map +1 -0
- package/dist/AppKeysManager.d.ts +136 -0
- package/dist/AppKeysManager.d.ts.map +1 -0
- package/dist/Invite.d.ts +7 -7
- package/dist/Invite.d.ts.map +1 -1
- package/dist/Session.d.ts +29 -0
- package/dist/Session.d.ts.map +1 -1
- package/dist/SessionManager.d.ts +46 -22
- package/dist/SessionManager.d.ts.map +1 -1
- package/dist/StorageAdapter.d.ts.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/inviteUtils.d.ts +122 -0
- package/dist/inviteUtils.d.ts.map +1 -0
- package/dist/nostr-double-ratchet.es.js +2843 -1901
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +32 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +20 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +5 -19
- package/src/AppKeys.ts +210 -0
- package/src/AppKeysManager.ts +405 -0
- package/src/Invite.ts +69 -89
- package/src/Session.ts +47 -4
- package/src/SessionManager.ts +478 -300
- package/src/StorageAdapter.ts +5 -6
- package/src/index.ts +4 -1
- package/src/inviteUtils.ts +271 -0
- package/src/types.ts +37 -2
- package/src/utils.ts +45 -8
- package/LICENSE +0 -21
- package/dist/UserRecord.d.ts +0 -117
- package/dist/UserRecord.d.ts.map +0 -1
- package/src/UserRecord.ts +0 -338
package/src/Session.ts
CHANGED
|
@@ -9,8 +9,11 @@ import {
|
|
|
9
9
|
MESSAGE_EVENT_KIND,
|
|
10
10
|
Rumor,
|
|
11
11
|
CHAT_MESSAGE_KIND,
|
|
12
|
+
REACTION_KIND,
|
|
13
|
+
RECEIPT_KIND,
|
|
14
|
+
TYPING_KIND,
|
|
12
15
|
} from "./types";
|
|
13
|
-
import { kdf, deepCopyState } from "./utils";
|
|
16
|
+
import { kdf, deepCopyState, createReactionPayload } from "./utils";
|
|
14
17
|
|
|
15
18
|
const MAX_SKIP = 1000;
|
|
16
19
|
|
|
@@ -93,7 +96,7 @@ export class Session {
|
|
|
93
96
|
previousSendingChainMessageCount: 0,
|
|
94
97
|
skippedKeys: {},
|
|
95
98
|
};
|
|
96
|
-
|
|
99
|
+
|
|
97
100
|
const session = new Session(nostrSubscribe, state);
|
|
98
101
|
if (name) session.name = name;
|
|
99
102
|
return session;
|
|
@@ -113,6 +116,46 @@ export class Session {
|
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Sends a reaction to a message through the encrypted session.
|
|
121
|
+
* @param messageId The ID of the message being reacted to
|
|
122
|
+
* @param emoji The emoji or reaction content (e.g., "👍", "❤️", "+1")
|
|
123
|
+
* @returns A verified Nostr event containing the encrypted reaction. You need to publish this event to the Nostr network.
|
|
124
|
+
* @throws Error if we are not the initiator and trying to send the first message
|
|
125
|
+
*/
|
|
126
|
+
sendReaction(messageId: string, emoji: string): {event: VerifiedEvent, innerEvent: Rumor} {
|
|
127
|
+
return this.sendEvent({
|
|
128
|
+
content: createReactionPayload(messageId, emoji),
|
|
129
|
+
kind: REACTION_KIND,
|
|
130
|
+
tags: [["e", messageId]]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sends a typing indicator through the encrypted session.
|
|
136
|
+
* @returns A verified Nostr event containing the encrypted typing indicator. You need to publish this event to the Nostr network.
|
|
137
|
+
*/
|
|
138
|
+
sendTyping(): {event: VerifiedEvent, innerEvent: Rumor} {
|
|
139
|
+
return this.sendEvent({
|
|
140
|
+
content: 'typing',
|
|
141
|
+
kind: TYPING_KIND,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Sends a delivery/read receipt through the encrypted session.
|
|
147
|
+
* @param receiptType Either "delivered" or "seen"
|
|
148
|
+
* @param messageIds The IDs of the messages being acknowledged
|
|
149
|
+
* @returns A verified Nostr event containing the encrypted receipt. You need to publish this event to the Nostr network.
|
|
150
|
+
*/
|
|
151
|
+
sendReceipt(receiptType: 'delivered' | 'seen', messageIds: string[]): {event: VerifiedEvent, innerEvent: Rumor} {
|
|
152
|
+
return this.sendEvent({
|
|
153
|
+
content: receiptType,
|
|
154
|
+
kind: RECEIPT_KIND,
|
|
155
|
+
tags: messageIds.map(id => ["e", id]),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
116
159
|
/**
|
|
117
160
|
* Send a partial Nostr event through the encrypted session.
|
|
118
161
|
* In addition to chat messages, it could be files, webrtc negotiation or many other types of messages.
|
|
@@ -393,7 +436,7 @@ export class Session {
|
|
|
393
436
|
this.nostrUnsubscribe = this.nostrSubscribe(
|
|
394
437
|
{authors: [this.state.theirCurrentNostrPublicKey], kinds: [MESSAGE_EVENT_KIND]},
|
|
395
438
|
(e) => this.handleNostrEvent(e)
|
|
396
|
-
);
|
|
439
|
+
);
|
|
397
440
|
}
|
|
398
441
|
|
|
399
442
|
const skippedAuthors = Object.keys(this.state.skippedKeys);
|
|
@@ -401,7 +444,7 @@ export class Session {
|
|
|
401
444
|
this.skippedSubscription = this.nostrSubscribe(
|
|
402
445
|
{authors: skippedAuthors, kinds: [MESSAGE_EVENT_KIND]},
|
|
403
446
|
(e) => this.handleNostrEvent(e)
|
|
404
|
-
);
|
|
447
|
+
);
|
|
405
448
|
}
|
|
406
449
|
}
|
|
407
450
|
}
|