@session.js/types 1.0.14 → 1.0.15

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 (38) hide show
  1. package/README.md +1 -1
  2. package/dist/envelope.d.ts +1 -1
  3. package/dist/index.d.ts +3 -3
  4. package/dist/index.js +1 -1
  5. package/dist/messages/expirable-message.d.ts +17 -0
  6. package/dist/messages/expirable-message.js +52 -0
  7. package/dist/messages/schema/configuration-message.d.ts +67 -0
  8. package/dist/messages/schema/configuration-message.js +172 -0
  9. package/dist/messages/schema/conversation-request-message.d.ts +13 -0
  10. package/dist/messages/schema/conversation-request-message.js +30 -0
  11. package/dist/messages/schema/data-extraction-message.d.ts +16 -0
  12. package/dist/messages/schema/data-extraction-message.js +22 -0
  13. package/dist/messages/schema/delete-message.d.ts +13 -0
  14. package/dist/messages/schema/delete-message.js +20 -0
  15. package/dist/messages/schema/index.d.ts +8 -0
  16. package/dist/messages/schema/index.js +8 -0
  17. package/dist/messages/schema/read-receipt-message.d.ts +16 -0
  18. package/dist/messages/schema/read-receipt-message.js +25 -0
  19. package/dist/messages/schema/shared-config-message.d.ts +18 -0
  20. package/dist/messages/schema/shared-config-message.js +30 -0
  21. package/dist/messages/schema/typing-indicator-message.d.ts +15 -0
  22. package/dist/messages/schema/typing-indicator-message.js +29 -0
  23. package/dist/messages/schema/visible-message.d.ts +75 -0
  24. package/dist/messages/schema/visible-message.js +104 -0
  25. package/dist/messages/signal-message.d.ts +25 -0
  26. package/dist/messages/signal-message.js +47 -0
  27. package/dist/namespaces.d.ts +1 -1
  28. package/dist/network/index.d.ts +1 -1
  29. package/dist/network/request.d.ts +3 -3
  30. package/dist/network/response.d.ts +4 -4
  31. package/dist/profile.d.ts +18 -0
  32. package/dist/profile.js +29 -0
  33. package/dist/reactions.d.ts +10 -0
  34. package/dist/reactions.js +5 -0
  35. package/dist/signal-bindings/index.d.ts +1 -1
  36. package/dist/signal-bindings/index.js +1 -1
  37. package/dist/snode-retrieve.d.ts +1 -1
  38. package/package.json +6 -66
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @session.js/types
2
2
 
3
- A special package that holds TypeScript definitions and enums shared internally for developing your own @session.js/client modular parts.
3
+ Session Messenger messages schemas, TypeScript definitions and enums used by @session.js/client
4
4
 
5
5
  To build your own Storage adapter, use:
6
6
 
@@ -1,4 +1,4 @@
1
- import type { SignalService } from "./signal-bindings/index.js";
1
+ import type { SignalService } from "./signal-bindings";
2
2
  export interface EnvelopePlus extends Omit<SignalService.Envelope, "toJSON"> {
3
3
  senderIdentity: string;
4
4
  receivedAt: number;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { SnodeNamespaces } from "./namespaces.js";
2
- export type { Network } from "./network/index.js";
3
- export type { Storage } from "./storage/index.js";
1
+ export { SnodeNamespaces } from "./namespaces";
2
+ export type { Network } from "./network";
3
+ export type { Storage } from "./storage";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { SnodeNamespaces } from "./namespaces.js";
1
+ export { SnodeNamespaces } from "./namespaces";
@@ -0,0 +1,17 @@
1
+ import { ContentMessage, type MessageParams } from "./signal-message";
2
+ import { SignalService } from "../signal-bindings";
3
+ import type { DisappearingMessageType } from "../disappearing-message";
4
+ export interface ExpirableMessageParams extends MessageParams {
5
+ expirationType: DisappearingMessageType | null;
6
+ expireTimer: number | null;
7
+ }
8
+ export declare class ExpirableMessage extends ContentMessage {
9
+ readonly expirationType: DisappearingMessageType | null;
10
+ /** in seconds, 0 means no expiration */
11
+ readonly expireTimer: number | null;
12
+ constructor(params: ExpirableMessageParams);
13
+ contentProto(): SignalService.Content;
14
+ dataProto(): SignalService.DataMessage;
15
+ getDisappearingMessageType(): DisappearingMessageType | undefined;
16
+ ttl(): number;
17
+ }
@@ -0,0 +1,52 @@
1
+ import { DURATION, TTL_DEFAULT } from "@session.js/consts";
2
+ import { ContentMessage } from "./signal-message";
3
+ import { SignalService } from "../signal-bindings";
4
+ export class ExpirableMessage extends ContentMessage {
5
+ expirationType;
6
+ /** in seconds, 0 means no expiration */
7
+ expireTimer;
8
+ constructor(params) {
9
+ super({
10
+ timestamp: params.timestamp,
11
+ identifier: params.identifier,
12
+ });
13
+ this.expirationType = params.expirationType;
14
+ this.expireTimer = params.expireTimer;
15
+ }
16
+ contentProto() {
17
+ return new SignalService.Content({
18
+ // TODO legacy messages support will be removed in a future release
19
+ expirationType: this.expirationType === "deleteAfterSend"
20
+ ? SignalService.Content.ExpirationType.DELETE_AFTER_SEND
21
+ : this.expirationType === "deleteAfterRead"
22
+ ? SignalService.Content.ExpirationType.DELETE_AFTER_READ
23
+ : this.expirationType === "unknown"
24
+ ? SignalService.Content.ExpirationType.UNKNOWN
25
+ : undefined,
26
+ expirationTimer: this.expireTimer && this.expireTimer > -1 ? this.expireTimer : undefined,
27
+ });
28
+ }
29
+ dataProto() {
30
+ return new SignalService.DataMessage({
31
+ // TODO legacy messages support will be removed in a future release
32
+ expireTimer: (this.expirationType === "unknown" || !this.expirationType) &&
33
+ this.expireTimer &&
34
+ this.expireTimer > -1
35
+ ? this.expireTimer
36
+ : undefined,
37
+ });
38
+ }
39
+ getDisappearingMessageType() {
40
+ return this.expirationType || undefined;
41
+ }
42
+ ttl() {
43
+ switch (this.expirationType) {
44
+ case "deleteAfterSend":
45
+ return this.expireTimer ? this.expireTimer * DURATION.SECONDS : TTL_DEFAULT.CONTENT_MESSAGE;
46
+ case "deleteAfterRead":
47
+ return TTL_DEFAULT.CONTENT_MESSAGE;
48
+ default:
49
+ return TTL_DEFAULT.CONTENT_MESSAGE;
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @deprecated — use SharedConfigMessage
3
+ */
4
+ import { ContentMessage, type MessageParams } from "../signal-message";
5
+ import { SignalService } from "../../signal-bindings";
6
+ interface ConfigurationMessageParams extends MessageParams {
7
+ activeClosedGroups: Array<ConfigurationMessageClosedGroup>;
8
+ activeOpenGroups: Array<string>;
9
+ displayName: string;
10
+ profilePicture?: string;
11
+ profileKey?: Uint8Array;
12
+ contacts: Array<ConfigurationMessageContact>;
13
+ }
14
+ export declare class ConfigurationMessage extends ContentMessage {
15
+ readonly activeClosedGroups: Array<ConfigurationMessageClosedGroup>;
16
+ readonly activeOpenGroups: Array<string>;
17
+ readonly displayName: string;
18
+ readonly profilePicture?: string;
19
+ readonly profileKey?: Uint8Array;
20
+ readonly contacts: Array<ConfigurationMessageContact>;
21
+ constructor(params: ConfigurationMessageParams);
22
+ contentProto(): SignalService.Content;
23
+ protected configurationProto(): SignalService.ConfigurationMessage;
24
+ private mapClosedGroupsObjectToProto;
25
+ private mapContactsObjectToProto;
26
+ }
27
+ export declare class ConfigurationMessageContact {
28
+ publicKey: Uint8Array;
29
+ displayName: string;
30
+ profilePictureURL?: string;
31
+ profileKey?: Uint8Array;
32
+ isApproved?: boolean;
33
+ isBlocked?: boolean;
34
+ didApproveMe?: boolean;
35
+ constructor({ publicKey, displayName, profilePictureURL, profileKey, isApproved, isBlocked, didApproveMe, }: {
36
+ publicKey: Uint8Array;
37
+ displayName: string;
38
+ profilePictureURL?: string;
39
+ profileKey?: Uint8Array;
40
+ isApproved?: boolean;
41
+ isBlocked?: boolean;
42
+ didApproveMe?: boolean;
43
+ });
44
+ toProto(): SignalService.ConfigurationMessage.Contact;
45
+ }
46
+ export declare class ConfigurationMessageClosedGroup {
47
+ publicKey: Uint8Array;
48
+ name: string;
49
+ encryptionKeyPair: {
50
+ privateKeyData: Uint8Array;
51
+ publicKeyData: Uint8Array;
52
+ };
53
+ members: Array<string>;
54
+ admins: Array<string>;
55
+ constructor({ publicKey, name, encryptionKeyPair, members, admins, }: {
56
+ publicKey: Uint8Array;
57
+ name: string;
58
+ encryptionKeyPair: {
59
+ privateKeyData: Uint8Array;
60
+ publicKeyData: Uint8Array;
61
+ };
62
+ members: Array<string>;
63
+ admins: Array<string>;
64
+ });
65
+ toProto(): SignalService.ConfigurationMessage.ClosedGroup;
66
+ }
67
+ export {};
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @deprecated — use SharedConfigMessage
3
+ */
4
+ import { SessionValidationError, SessionValidationErrorCode } from "@session.js/errors";
5
+ import { ContentMessage } from "../signal-message";
6
+ import { SignalService } from "../../signal-bindings";
7
+ const hexToBytes = (hex) => {
8
+ return Uint8Array.from(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
9
+ };
10
+ export class ConfigurationMessage extends ContentMessage {
11
+ activeClosedGroups;
12
+ activeOpenGroups;
13
+ displayName;
14
+ profilePicture;
15
+ profileKey;
16
+ contacts;
17
+ constructor(params) {
18
+ super({ timestamp: params.timestamp, identifier: params.identifier });
19
+ this.activeClosedGroups = params.activeClosedGroups;
20
+ this.activeOpenGroups = params.activeOpenGroups;
21
+ this.displayName = params.displayName;
22
+ this.profilePicture = params.profilePicture;
23
+ this.profileKey = params.profileKey;
24
+ this.contacts = params.contacts;
25
+ if (!this.activeClosedGroups) {
26
+ throw new SessionValidationError({
27
+ code: SessionValidationErrorCode.InvalidOptions,
28
+ message: "closed group must be set",
29
+ });
30
+ }
31
+ if (!this.activeOpenGroups) {
32
+ throw new SessionValidationError({
33
+ code: SessionValidationErrorCode.InvalidOptions,
34
+ message: "open group must be set",
35
+ });
36
+ }
37
+ if (!this.displayName || !this.displayName?.length) {
38
+ throw new SessionValidationError({
39
+ code: SessionValidationErrorCode.InvalidOptions,
40
+ message: "displayName must be set",
41
+ });
42
+ }
43
+ if (this.profilePicture && typeof this.profilePicture !== "string") {
44
+ throw new SessionValidationError({
45
+ code: SessionValidationErrorCode.InvalidOptions,
46
+ message: "profilePicture set but not an Uin8Array",
47
+ });
48
+ }
49
+ if (this.profileKey && !(this.profileKey instanceof Uint8Array)) {
50
+ throw new SessionValidationError({
51
+ code: SessionValidationErrorCode.InvalidOptions,
52
+ message: "profileKey set but not an Uin8Array",
53
+ });
54
+ }
55
+ if (!this.contacts) {
56
+ throw new SessionValidationError({
57
+ code: SessionValidationErrorCode.InvalidOptions,
58
+ message: "contacts must be set",
59
+ });
60
+ }
61
+ }
62
+ contentProto() {
63
+ return new SignalService.Content({
64
+ configurationMessage: this.configurationProto(),
65
+ });
66
+ }
67
+ configurationProto() {
68
+ return new SignalService.ConfigurationMessage({
69
+ closedGroups: this.mapClosedGroupsObjectToProto(this.activeClosedGroups),
70
+ openGroups: this.activeOpenGroups,
71
+ displayName: this.displayName,
72
+ profilePicture: this.profilePicture,
73
+ profileKey: this.profileKey,
74
+ contacts: this.mapContactsObjectToProto(this.contacts),
75
+ });
76
+ }
77
+ mapClosedGroupsObjectToProto(closedGroups) {
78
+ return (closedGroups || []).map((m) => m.toProto());
79
+ }
80
+ mapContactsObjectToProto(contacts) {
81
+ return (contacts || []).map((m) => m.toProto());
82
+ }
83
+ }
84
+ export class ConfigurationMessageContact {
85
+ publicKey;
86
+ displayName;
87
+ profilePictureURL;
88
+ profileKey;
89
+ isApproved;
90
+ isBlocked;
91
+ didApproveMe;
92
+ constructor({ publicKey, displayName, profilePictureURL, profileKey, isApproved, isBlocked, didApproveMe, }) {
93
+ this.publicKey = publicKey;
94
+ this.displayName = displayName;
95
+ this.profilePictureURL = profilePictureURL;
96
+ this.profileKey = profileKey;
97
+ this.isApproved = isApproved;
98
+ this.isBlocked = isBlocked;
99
+ this.didApproveMe = didApproveMe;
100
+ if (this.displayName?.length === 0) {
101
+ throw new SessionValidationError({
102
+ code: SessionValidationErrorCode.InvalidOptions,
103
+ message: "displayName must be set or undefined",
104
+ });
105
+ }
106
+ if (this.profilePictureURL !== undefined && this.profilePictureURL?.length === 0) {
107
+ throw new SessionValidationError({
108
+ code: SessionValidationErrorCode.InvalidOptions,
109
+ message: "profilePictureURL must either undefined or not empty",
110
+ });
111
+ }
112
+ if (this.profileKey !== undefined && this.profileKey?.length === 0) {
113
+ throw new SessionValidationError({
114
+ code: SessionValidationErrorCode.InvalidOptions,
115
+ message: "profileKey must either undefined or not empty",
116
+ });
117
+ }
118
+ }
119
+ toProto() {
120
+ return new SignalService.ConfigurationMessage.Contact({
121
+ publicKey: this.publicKey,
122
+ name: this.displayName,
123
+ profilePicture: this.profilePictureURL,
124
+ profileKey: this.profileKey,
125
+ isApproved: this.isApproved,
126
+ isBlocked: this.isBlocked,
127
+ didApproveMe: this.didApproveMe,
128
+ });
129
+ }
130
+ }
131
+ export class ConfigurationMessageClosedGroup {
132
+ publicKey;
133
+ name;
134
+ encryptionKeyPair;
135
+ members;
136
+ admins;
137
+ constructor({ publicKey, name, encryptionKeyPair, members, admins, }) {
138
+ this.publicKey = publicKey;
139
+ this.name = name;
140
+ this.encryptionKeyPair = encryptionKeyPair;
141
+ this.members = members;
142
+ this.admins = admins;
143
+ if (!encryptionKeyPair?.privateKeyData?.byteLength ||
144
+ !encryptionKeyPair?.publicKeyData?.byteLength) {
145
+ throw new Error("Encryption key pair looks invalid");
146
+ }
147
+ if (!this.name?.length) {
148
+ throw new Error("name must be set");
149
+ }
150
+ if (!this.members?.length) {
151
+ throw new Error("members must be set");
152
+ }
153
+ if (!this.admins?.length) {
154
+ throw new Error("admins must be set");
155
+ }
156
+ if (this.admins.some((a) => !this.members.includes(a))) {
157
+ throw new Error("some admins are not members");
158
+ }
159
+ }
160
+ toProto() {
161
+ return new SignalService.ConfigurationMessage.ClosedGroup({
162
+ publicKey: this.publicKey,
163
+ name: this.name,
164
+ encryptionKeyPair: {
165
+ publicKey: this.encryptionKeyPair.publicKeyData,
166
+ privateKey: this.encryptionKeyPair.privateKeyData,
167
+ },
168
+ members: this.members.map(hexToBytes),
169
+ admins: this.admins.map(hexToBytes),
170
+ });
171
+ }
172
+ }
@@ -0,0 +1,13 @@
1
+ import { ContentMessage, type MessageParams } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ import { type Profile } from "../../profile";
4
+ export interface MessageRequestResponseParams extends MessageParams {
5
+ profile?: Profile;
6
+ }
7
+ export declare class MessageRequestResponse extends ContentMessage {
8
+ private readonly profileKey?;
9
+ private readonly profile?;
10
+ constructor(params: MessageRequestResponseParams);
11
+ contentProto(): SignalService.Content;
12
+ messageRequestResponseProto(): SignalService.MessageRequestResponse;
13
+ }
@@ -0,0 +1,30 @@
1
+ import { ContentMessage } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ import { serializeProfile } from "../../profile";
4
+ // Request is always Approved
5
+ export class MessageRequestResponse extends ContentMessage {
6
+ profileKey;
7
+ profile;
8
+ constructor(params) {
9
+ super({
10
+ timestamp: params.timestamp,
11
+ });
12
+ if (params.profile) {
13
+ const profile = serializeProfile(params.profile);
14
+ this.profile = profile.lokiProfile;
15
+ this.profileKey = profile.profileKey;
16
+ }
17
+ }
18
+ contentProto() {
19
+ return new SignalService.Content({
20
+ messageRequestResponse: this.messageRequestResponseProto(),
21
+ });
22
+ }
23
+ messageRequestResponseProto() {
24
+ return new SignalService.MessageRequestResponse({
25
+ isApproved: true,
26
+ profileKey: this.profileKey?.length ? this.profileKey : undefined,
27
+ profile: this.profile,
28
+ });
29
+ }
30
+ }
@@ -0,0 +1,16 @@
1
+ import { ExpirableMessage, type ExpirableMessageParams } from "../expirable-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ interface DataExtractionNotificationMessageParams extends ExpirableMessageParams {
4
+ action: SignalService.DataExtractionNotification.Type;
5
+ /** For SCREENSHOT, timestamp when screenshot was taken
6
+ * For MEDIA_SAVED, message with attachment's timestamp */
7
+ timestamp: number;
8
+ }
9
+ export declare class DataExtractionNotificationMessage extends ExpirableMessage {
10
+ readonly timestamp: number;
11
+ readonly action: SignalService.DataExtractionNotification.Type;
12
+ constructor(params: DataExtractionNotificationMessageParams);
13
+ contentProto(): SignalService.Content;
14
+ protected dataExtractionProto(): SignalService.DataExtractionNotification;
15
+ }
16
+ export {};
@@ -0,0 +1,22 @@
1
+ import { ExpirableMessage } from "../expirable-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ export class DataExtractionNotificationMessage extends ExpirableMessage {
4
+ timestamp;
5
+ action;
6
+ constructor(params) {
7
+ super(params);
8
+ this.timestamp = params.timestamp;
9
+ this.action = params.action;
10
+ }
11
+ contentProto() {
12
+ const content = super.contentProto();
13
+ content.dataExtractionNotification = this.dataExtractionProto();
14
+ return content;
15
+ }
16
+ dataExtractionProto() {
17
+ return new SignalService.DataExtractionNotification({
18
+ type: this.action,
19
+ timestamp: this.timestamp,
20
+ });
21
+ }
22
+ }
@@ -0,0 +1,13 @@
1
+ import { ContentMessage, type MessageParams } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ interface UnsendMessageParams extends MessageParams {
4
+ timestamp: number;
5
+ author: string;
6
+ }
7
+ export declare class UnsendMessage extends ContentMessage {
8
+ private readonly author;
9
+ constructor(params: UnsendMessageParams);
10
+ contentProto(): SignalService.Content;
11
+ unsendProto(): SignalService.Unsend;
12
+ }
13
+ export {};
@@ -0,0 +1,20 @@
1
+ import { ContentMessage } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ export class UnsendMessage extends ContentMessage {
4
+ author;
5
+ constructor(params) {
6
+ super({ timestamp: params.timestamp, author: params.author });
7
+ this.author = params.author;
8
+ }
9
+ contentProto() {
10
+ return new SignalService.Content({
11
+ unsendMessage: this.unsendProto(),
12
+ });
13
+ }
14
+ unsendProto() {
15
+ return new SignalService.Unsend({
16
+ timestamp: this.timestamp,
17
+ author: this.author,
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,8 @@
1
+ export { VisibleMessage } from "./visible-message";
2
+ export { ConfigurationMessage } from "./configuration-message";
3
+ export { MessageRequestResponse } from "./conversation-request-message";
4
+ export { DataExtractionNotificationMessage } from "./data-extraction-message";
5
+ export { UnsendMessage } from "./delete-message";
6
+ export { ReadReceiptMessage } from "./read-receipt-message";
7
+ export { SharedConfigMessage } from "./shared-config-message";
8
+ export { TypingMessage } from "./typing-indicator-message";
@@ -0,0 +1,8 @@
1
+ export { VisibleMessage } from "./visible-message";
2
+ export { ConfigurationMessage } from "./configuration-message";
3
+ export { MessageRequestResponse } from "./conversation-request-message";
4
+ export { DataExtractionNotificationMessage } from "./data-extraction-message";
5
+ export { UnsendMessage } from "./delete-message";
6
+ export { ReadReceiptMessage } from "./read-receipt-message";
7
+ export { SharedConfigMessage } from "./shared-config-message";
8
+ export { TypingMessage } from "./typing-indicator-message";
@@ -0,0 +1,16 @@
1
+ import { ContentMessage, type MessageParams } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ interface ReceiptMessageParams extends MessageParams {
4
+ timestamps: Array<number>;
5
+ }
6
+ export declare abstract class ReceiptMessage extends ContentMessage {
7
+ readonly timestamps: Array<number>;
8
+ constructor({ timestamp, identifier, timestamps }: ReceiptMessageParams);
9
+ abstract getReceiptType(): SignalService.ReceiptMessage.Type;
10
+ contentProto(): SignalService.Content;
11
+ protected receiptProto(): SignalService.ReceiptMessage;
12
+ }
13
+ export declare class ReadReceiptMessage extends ReceiptMessage {
14
+ getReceiptType(): SignalService.ReceiptMessage.Type;
15
+ }
16
+ export {};
@@ -0,0 +1,25 @@
1
+ import { ContentMessage } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ export class ReceiptMessage extends ContentMessage {
4
+ timestamps;
5
+ constructor({ timestamp, identifier, timestamps }) {
6
+ super({ timestamp, identifier });
7
+ this.timestamps = timestamps;
8
+ }
9
+ contentProto() {
10
+ return new SignalService.Content({
11
+ receiptMessage: this.receiptProto(),
12
+ });
13
+ }
14
+ receiptProto() {
15
+ return new SignalService.ReceiptMessage({
16
+ type: this.getReceiptType(),
17
+ timestamp: this.timestamps,
18
+ });
19
+ }
20
+ }
21
+ export class ReadReceiptMessage extends ReceiptMessage {
22
+ getReceiptType() {
23
+ return SignalService.ReceiptMessage.Type.READ;
24
+ }
25
+ }
@@ -0,0 +1,18 @@
1
+ import Long from "long";
2
+ import { ContentMessage, type MessageParams } from "../signal-message";
3
+ import { SignalService } from "../../signal-bindings";
4
+ interface SharedConfigParams extends MessageParams {
5
+ seqno: Long;
6
+ kind: SignalService.SharedConfigMessage.Kind;
7
+ data: Uint8Array;
8
+ }
9
+ export declare class SharedConfigMessage extends ContentMessage {
10
+ readonly seqno: Long;
11
+ readonly kind: SignalService.SharedConfigMessage.Kind;
12
+ readonly data: Uint8Array;
13
+ constructor(params: SharedConfigParams);
14
+ contentProto(): SignalService.Content;
15
+ ttl(): number;
16
+ protected sharedConfigProto(): SignalService.SharedConfigMessage;
17
+ }
18
+ export {};
@@ -0,0 +1,30 @@
1
+ import Long from "long";
2
+ import { TTL_DEFAULT } from "@session.js/consts";
3
+ import { ContentMessage } from "../signal-message";
4
+ import { SignalService } from "../../signal-bindings";
5
+ export class SharedConfigMessage extends ContentMessage {
6
+ seqno;
7
+ kind;
8
+ data;
9
+ constructor(params) {
10
+ super({ timestamp: params.timestamp, identifier: params.identifier });
11
+ this.data = params.data;
12
+ this.kind = params.kind;
13
+ this.seqno = params.seqno;
14
+ }
15
+ contentProto() {
16
+ return new SignalService.Content({
17
+ sharedConfigMessage: this.sharedConfigProto(),
18
+ });
19
+ }
20
+ ttl() {
21
+ return TTL_DEFAULT.CONFIG_MESSAGE;
22
+ }
23
+ sharedConfigProto() {
24
+ return new SignalService.SharedConfigMessage({
25
+ data: this.data,
26
+ kind: this.kind,
27
+ seqno: this.seqno,
28
+ });
29
+ }
30
+ }
@@ -0,0 +1,15 @@
1
+ import { ContentMessage, type MessageParams } from "../signal-message";
2
+ import { SignalService } from "../../signal-bindings";
3
+ interface TypingMessageParams extends MessageParams {
4
+ isTyping: boolean;
5
+ typingTimestamp?: number;
6
+ }
7
+ export declare class TypingMessage extends ContentMessage {
8
+ readonly isTyping: boolean;
9
+ readonly typingTimestamp?: number;
10
+ constructor(params: TypingMessageParams);
11
+ ttl(): number;
12
+ contentProto(): SignalService.Content;
13
+ protected typingProto(): SignalService.TypingMessage;
14
+ }
15
+ export {};
@@ -0,0 +1,29 @@
1
+ import * as Constants from "@session.js/consts";
2
+ import { ContentMessage } from "../signal-message";
3
+ import { SignalService } from "../../signal-bindings";
4
+ export class TypingMessage extends ContentMessage {
5
+ isTyping;
6
+ typingTimestamp;
7
+ constructor(params) {
8
+ super({ timestamp: params.timestamp, identifier: params.identifier });
9
+ this.isTyping = params.isTyping;
10
+ this.typingTimestamp = params.typingTimestamp;
11
+ }
12
+ ttl() {
13
+ return Constants.TTL_DEFAULT.TYPING_MESSAGE;
14
+ }
15
+ contentProto() {
16
+ return new SignalService.Content({
17
+ typingMessage: this.typingProto(),
18
+ });
19
+ }
20
+ typingProto() {
21
+ const ACTION_ENUM = SignalService.TypingMessage.Action;
22
+ const action = this.isTyping ? ACTION_ENUM.STARTED : ACTION_ENUM.STOPPED;
23
+ const finalTimestamp = this.typingTimestamp || Date.now();
24
+ const typingMessage = new SignalService.TypingMessage();
25
+ typingMessage.action = action;
26
+ typingMessage.timestamp = finalTimestamp;
27
+ return typingMessage;
28
+ }
29
+ }
@@ -0,0 +1,75 @@
1
+ import { ExpirableMessage, type ExpirableMessageParams } from "../expirable-message";
2
+ import { type Reaction } from "../../reactions";
3
+ import { type Profile } from "../../profile";
4
+ import { SignalService } from "../../signal-bindings";
5
+ interface AttachmentPointerCommon {
6
+ contentType?: string;
7
+ key?: Uint8Array;
8
+ size?: number;
9
+ thumbnail?: Uint8Array;
10
+ digest?: Uint8Array;
11
+ fileName?: string;
12
+ flags?: number;
13
+ width?: number;
14
+ height?: number;
15
+ caption?: string;
16
+ }
17
+ export interface AttachmentPointer extends AttachmentPointerCommon {
18
+ url?: string;
19
+ id?: number;
20
+ }
21
+ export interface AttachmentPointerWithUrl extends AttachmentPointerCommon {
22
+ url: string;
23
+ id: number;
24
+ }
25
+ export interface Preview {
26
+ url: string;
27
+ title?: string;
28
+ image?: AttachmentPointer;
29
+ }
30
+ export interface PreviewWithAttachmentUrl {
31
+ url: string;
32
+ id: number;
33
+ title?: string;
34
+ image?: AttachmentPointerWithUrl;
35
+ }
36
+ interface QuotedAttachmentCommon {
37
+ contentType?: string;
38
+ fileName?: string;
39
+ }
40
+ export interface QuotedAttachment extends QuotedAttachmentCommon {
41
+ thumbnail?: AttachmentPointer;
42
+ }
43
+ export interface QuotedAttachmentWithUrl extends QuotedAttachmentCommon {
44
+ thumbnail?: AttachmentPointerWithUrl | QuotedAttachment;
45
+ }
46
+ export interface Quote {
47
+ id: number;
48
+ author: string;
49
+ text?: string;
50
+ attachments?: Array<QuotedAttachmentWithUrl>;
51
+ }
52
+ export interface VisibleMessageParams extends ExpirableMessageParams {
53
+ attachments?: Array<AttachmentPointerWithUrl>;
54
+ body?: string;
55
+ quote?: Quote;
56
+ profile?: Profile;
57
+ preview?: Array<PreviewWithAttachmentUrl>;
58
+ reaction?: Reaction;
59
+ syncTarget?: string;
60
+ }
61
+ export declare class VisibleMessage extends ExpirableMessage {
62
+ readonly reaction?: Reaction;
63
+ private readonly attachments?;
64
+ private readonly body?;
65
+ private readonly quote?;
66
+ private readonly profileKey?;
67
+ private readonly profile?;
68
+ private readonly preview?;
69
+ private readonly syncTarget?;
70
+ constructor(params: VisibleMessageParams);
71
+ contentProto(): SignalService.Content;
72
+ dataProto(): SignalService.DataMessage;
73
+ isEqual(comparator: VisibleMessage): boolean;
74
+ }
75
+ export {};
@@ -0,0 +1,104 @@
1
+ import { ExpirableMessage } from "../expirable-message";
2
+ import { ReactionAction } from "../../reactions";
3
+ import { serializeProfile } from "../../profile";
4
+ import { SignalService } from "../../signal-bindings";
5
+ export class VisibleMessage extends ExpirableMessage {
6
+ reaction;
7
+ attachments;
8
+ body;
9
+ quote;
10
+ profileKey;
11
+ profile;
12
+ preview;
13
+ syncTarget;
14
+ constructor(params) {
15
+ super({
16
+ timestamp: params.timestamp,
17
+ identifier: params.identifier,
18
+ expirationType: params.expirationType,
19
+ expireTimer: params.expireTimer,
20
+ });
21
+ this.attachments = params.attachments;
22
+ this.body = params.body;
23
+ this.quote = params.quote;
24
+ if (params.profile) {
25
+ const profile = serializeProfile(params.profile);
26
+ this.profile = profile.lokiProfile;
27
+ this.profileKey = profile.profileKey;
28
+ }
29
+ this.preview = params.preview;
30
+ this.reaction = params.reaction;
31
+ this.syncTarget = params.syncTarget;
32
+ }
33
+ contentProto() {
34
+ const content = super.contentProto();
35
+ content.dataMessage = this.dataProto();
36
+ return content;
37
+ }
38
+ dataProto() {
39
+ const dataMessage = super.dataProto();
40
+ if (this.body) {
41
+ dataMessage.body = this.body;
42
+ }
43
+ dataMessage.attachments = this.attachments || [];
44
+ if (this.preview) {
45
+ dataMessage.preview = this.preview;
46
+ }
47
+ if (this.reaction) {
48
+ dataMessage.reaction = {
49
+ ...this.reaction,
50
+ action: this.reaction.action === ReactionAction.REACT
51
+ ? SignalService.DataMessage.Reaction.Action.REACT
52
+ : SignalService.DataMessage.Reaction.Action.REMOVE,
53
+ };
54
+ }
55
+ if (this.syncTarget) {
56
+ dataMessage.syncTarget = this.syncTarget;
57
+ }
58
+ if (this.profile) {
59
+ dataMessage.profile = this.profile;
60
+ }
61
+ if (this.profileKey && this.profileKey.length) {
62
+ dataMessage.profileKey = this.profileKey;
63
+ }
64
+ if (this.quote) {
65
+ dataMessage.quote = new SignalService.DataMessage.Quote();
66
+ dataMessage.quote.id = this.quote.id;
67
+ dataMessage.quote.author = this.quote.author;
68
+ dataMessage.quote.text = this.quote.text;
69
+ if (this.quote.attachments) {
70
+ dataMessage.quote.attachments = this.quote.attachments.map((attachment) => {
71
+ const quotedAttachment = new SignalService.DataMessage.Quote.QuotedAttachment();
72
+ if (attachment.contentType) {
73
+ quotedAttachment.contentType = attachment.contentType;
74
+ }
75
+ if (attachment.fileName) {
76
+ quotedAttachment.fileName = attachment.fileName;
77
+ }
78
+ if (attachment.thumbnail && "id" in attachment.thumbnail) {
79
+ quotedAttachment.thumbnail = attachment.thumbnail;
80
+ }
81
+ return quotedAttachment;
82
+ });
83
+ }
84
+ }
85
+ if (Array.isArray(this.preview)) {
86
+ dataMessage.preview = this.preview.map((preview) => {
87
+ const item = new SignalService.DataMessage.Preview();
88
+ if (preview.title) {
89
+ item.title = preview.title;
90
+ }
91
+ if (preview.url) {
92
+ item.url = preview.url;
93
+ }
94
+ item.image = preview.image || null;
95
+ return item;
96
+ });
97
+ }
98
+ dataMessage.timestamp = this.timestamp;
99
+ return dataMessage;
100
+ }
101
+ isEqual(comparator) {
102
+ return this.identifier === comparator.identifier && this.timestamp === comparator.timestamp;
103
+ }
104
+ }
@@ -0,0 +1,25 @@
1
+ import { SignalService } from "../signal-bindings";
2
+ import { SnodeNamespaces } from "../namespaces";
3
+ export interface MessageParams {
4
+ timestamp: number;
5
+ identifier?: string;
6
+ }
7
+ export declare abstract class SignalMessage {
8
+ readonly timestamp: number;
9
+ readonly identifier: string;
10
+ constructor({ timestamp, identifier }: MessageParams);
11
+ }
12
+ export declare abstract class ContentMessage extends SignalMessage {
13
+ plainTextBuffer(): Uint8Array;
14
+ ttl(): number;
15
+ abstract contentProto(): SignalService.Content;
16
+ }
17
+ export type RawMessage = {
18
+ identifier: string;
19
+ plainTextBuffer: Uint8Array;
20
+ recipient: string;
21
+ ttl: number;
22
+ encryption: SignalService.Envelope.Type;
23
+ namespace: SnodeNamespaces;
24
+ };
25
+ export declare function toRawMessage(destinationPubKey: string, message: ContentMessage, namespace: SnodeNamespaces, isGroup?: boolean): RawMessage;
@@ -0,0 +1,47 @@
1
+ import { SessionValidationError, SessionValidationErrorCode } from "@session.js/errors";
2
+ import { SignalService } from "../signal-bindings";
3
+ import { SnodeNamespaces } from "../namespaces";
4
+ export class SignalMessage {
5
+ timestamp;
6
+ identifier;
7
+ constructor({ timestamp, identifier }) {
8
+ this.timestamp = timestamp;
9
+ if (identifier && identifier.length === 0) {
10
+ throw new SessionValidationError({
11
+ code: SessionValidationErrorCode.InvalidOptions,
12
+ message: "Cannot set empty identifier",
13
+ });
14
+ }
15
+ if (!timestamp) {
16
+ throw new SessionValidationError({
17
+ code: SessionValidationErrorCode.InvalidOptions,
18
+ message: "Cannot set undefined timestamp",
19
+ });
20
+ }
21
+ this.identifier = identifier || crypto.randomUUID();
22
+ }
23
+ }
24
+ export class ContentMessage extends SignalMessage {
25
+ plainTextBuffer() {
26
+ return SignalService.Content.encode(this.contentProto()).finish();
27
+ }
28
+ ttl() {
29
+ return 14 * 24 * 60 * 60 * 1000;
30
+ }
31
+ }
32
+ export function toRawMessage(destinationPubKey, message, namespace, isGroup = false) {
33
+ const ttl = message.ttl();
34
+ const plainTextBuffer = message.plainTextBuffer();
35
+ const encryption = isGroup
36
+ ? SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE
37
+ : SignalService.Envelope.Type.SESSION_MESSAGE;
38
+ const rawMessage = {
39
+ identifier: message.identifier,
40
+ plainTextBuffer,
41
+ recipient: destinationPubKey,
42
+ ttl,
43
+ encryption,
44
+ namespace,
45
+ };
46
+ return rawMessage;
47
+ }
@@ -1,4 +1,4 @@
1
- import type { PickEnum } from "./enums.js";
1
+ import type { PickEnum } from "./enums";
2
2
  export declare enum SnodeNamespaces {
3
3
  /**
4
4
  * This is the namespace anyone can deposit a message for us
@@ -1,4 +1,4 @@
1
- import type { RequestType } from "./request.js";
1
+ import type { RequestType } from "./request";
2
2
  export interface Network {
3
3
  onRequest(type: RequestType, body: unknown): Promise<unknown>;
4
4
  }
@@ -1,6 +1,6 @@
1
- import type { Snode } from "../snode.js";
2
- import type { RequestNamespace } from "../snode-retrieve.js";
3
- import type { Swarm } from "../swarm.js";
1
+ import type { Snode } from "../snode";
2
+ import type { RequestNamespace } from "../snode-retrieve";
3
+ import type { Swarm } from "../swarm";
4
4
  export declare enum RequestType {
5
5
  Store = "/store",
6
6
  GetSnodes = "/get_snodes",
@@ -1,7 +1,7 @@
1
- import type { SnodeNamespaces } from "../namespaces.js";
2
- import type { Snode } from "../snode.js";
3
- import type { RetrieveMessageItem } from "../snode-retrieve.js";
4
- import type { Swarm } from "../swarm.js";
1
+ import type { SnodeNamespaces } from "../namespaces";
2
+ import type { Snode } from "../snode";
3
+ import type { RetrieveMessageItem } from "../snode-retrieve";
4
+ import type { Swarm } from "../swarm";
5
5
  export type ResponseStore = {
6
6
  hash: string;
7
7
  };
@@ -0,0 +1,18 @@
1
+ import { SignalService } from "./signal-bindings";
2
+ export type Profile = {
3
+ /** Name, displayed instead of your Session ID. Acts like nickname. All unicode characters are accepted except for `ᅭ` (0xffd2) which is reserved by Session for mentions. Max length: 64 characters */
4
+ displayName: string;
5
+ /** Image, displayed near display name in Session clients. Acts like profile picture. */
6
+ avatar?: {
7
+ /** URL to avatar, uploaded to Session file server */
8
+ url: string;
9
+ /** 32 bytes key used for avatar encryption */
10
+ key: Uint8Array;
11
+ };
12
+ };
13
+ export type SignalILokiProfile = {
14
+ lokiProfile: SignalService.DataMessage.ILokiProfile | undefined;
15
+ profileKey: Uint8Array | undefined;
16
+ };
17
+ export declare function serializeProfile(profile: Profile): SignalILokiProfile;
18
+ export declare function deserializeProfile(signalILokiProfile: SignalILokiProfile): Profile;
@@ -0,0 +1,29 @@
1
+ import { SignalService } from "./signal-bindings";
2
+ export function serializeProfile(profile) {
3
+ let signalILokiProfile;
4
+ if (profile.avatar || profile.displayName) {
5
+ signalILokiProfile = new SignalService.DataMessage.LokiProfile();
6
+ if (profile.avatar && profile.avatar.url && profile.avatar.key.length) {
7
+ signalILokiProfile.profilePicture = profile.avatar.url;
8
+ }
9
+ if (profile.displayName) {
10
+ signalILokiProfile.displayName = profile.displayName;
11
+ }
12
+ }
13
+ return {
14
+ lokiProfile: signalILokiProfile,
15
+ profileKey: profile.avatar?.key,
16
+ };
17
+ }
18
+ export function deserializeProfile(signalILokiProfile) {
19
+ const profile = {
20
+ displayName: signalILokiProfile.lokiProfile?.displayName || "",
21
+ avatar: signalILokiProfile.lokiProfile?.profilePicture && signalILokiProfile.profileKey
22
+ ? {
23
+ url: signalILokiProfile.lokiProfile.profilePicture,
24
+ key: signalILokiProfile.profileKey,
25
+ }
26
+ : undefined,
27
+ };
28
+ return profile;
29
+ }
@@ -0,0 +1,10 @@
1
+ export declare enum ReactionAction {
2
+ REACT = 0,
3
+ REMOVE = 1
4
+ }
5
+ export interface Reaction {
6
+ id: number;
7
+ author: string;
8
+ emoji: string;
9
+ action: ReactionAction;
10
+ }
@@ -0,0 +1,5 @@
1
+ export var ReactionAction;
2
+ (function (ReactionAction) {
3
+ ReactionAction[ReactionAction["REACT"] = 0] = "REACT";
4
+ ReactionAction[ReactionAction["REMOVE"] = 1] = "REMOVE";
5
+ })(ReactionAction || (ReactionAction = {}));
@@ -1,3 +1,3 @@
1
1
  import { signalservice as SignalService } from './compiled';
2
- import { ProtobufUtils } from './utils.js';
2
+ import { ProtobufUtils } from './utils';
3
3
  export { SignalService, ProtobufUtils };
@@ -1,3 +1,3 @@
1
1
  import { signalservice as SignalService } from './compiled';
2
- import { ProtobufUtils } from './utils.js';
2
+ import { ProtobufUtils } from './utils';
3
3
  export { SignalService, ProtobufUtils };
@@ -1,4 +1,4 @@
1
- import type { SnodeNamespaces } from "./namespaces.js";
1
+ import type { SnodeNamespaces } from "./namespaces";
2
2
  export type RetrieveMessageItem = {
3
3
  hash: string;
4
4
  expiration: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@session.js/types",
3
- "version": "1.0.14",
4
- "description": "A special package that holds TypeScript definitions and enums shared internally and for developing your own @session.js/client modular parts.",
3
+ "version": "1.0.15",
4
+ "description": "Session Messenger messages schemas, TypeScript definitions and enums used by @session.js/client",
5
5
  "homepage": "https://git.hloth.dev/session.js/types#readme",
6
6
  "bugs": {
7
7
  "url": "https://git.hloth.dev/session.js/types/issues"
@@ -14,68 +14,6 @@
14
14
  "license": "MIT",
15
15
  "author": "Viktor Shchelochkov <hi@hloth.dev> (https://hloth.dev)",
16
16
  "type": "module",
17
- "exports": {
18
- ".": {
19
- "import": "./dist/index.js",
20
- "types": "./dist/index.d.ts"
21
- },
22
- "./network": {
23
- "import": "./dist/network/index.js",
24
- "types": "./dist/network/index.d.ts"
25
- },
26
- "./network/request": {
27
- "import": "./dist/network/request.js",
28
- "types": "./dist/network/request.d.ts"
29
- },
30
- "./network/response": {
31
- "import": "./dist/network/response.js",
32
- "types": "./dist/network/response.d.ts"
33
- },
34
- "./storage": {
35
- "import": "./dist/storage/index.js",
36
- "types": "./dist/storage/index.d.ts"
37
- },
38
- "./signal-bindings": {
39
- "import": "./dist/signal-bindings/index.js",
40
- "types": "./dist/signal-bindings/index.d.ts"
41
- },
42
- "./disappearing-message": {
43
- "import": "./dist/disappearing-message.js",
44
- "types": "./dist/disappearing-message.d.ts"
45
- },
46
- "./enums": {
47
- "import": "./dist/enums.js",
48
- "types": "./dist/enums.d.ts"
49
- },
50
- "./envelope": {
51
- "import": "./dist/envelope.js",
52
- "types": "./dist/envelope.d.ts"
53
- },
54
- "./namespaces": {
55
- "import": "./dist/namespaces.js",
56
- "types": "./dist/namespaces.d.ts"
57
- },
58
- "./pubkey": {
59
- "import": "./dist/pubkey.js",
60
- "types": "./dist/pubkey.d.ts"
61
- },
62
- "./snode-retrieve": {
63
- "import": "./dist/snode-retrieve.js",
64
- "types": "./dist/snode-retrieve.d.ts"
65
- },
66
- "./snode-signature-result": {
67
- "import": "./dist/snode-signature-result.js",
68
- "types": "./dist/snode-signature-result.d.ts"
69
- },
70
- "./snode": {
71
- "import": "./dist/snode.js",
72
- "types": "./dist/snode.d.ts"
73
- },
74
- "./swarm": {
75
- "import": "./dist/swarm.js",
76
- "types": "./dist/swarm.d.ts"
77
- }
78
- },
79
17
  "main": "dist/index.js",
80
18
  "types": "dist/index.d.ts",
81
19
  "files": [
@@ -85,11 +23,14 @@
85
23
  "LICENSE"
86
24
  ],
87
25
  "scripts": {
88
- "build": "rm -rf dist && tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json --resolve-full-paths && cp src/signal-bindings/compiled.js dist/signal-bindings/compiled.js && cp src/signal-bindings/compiled.d.ts dist/signal-bindings/compiled.d.ts",
26
+ "build": "rm -rf dist && tsc --project tsconfig.build.json && tsc -p tsconfig.build.json && cp src/signal-bindings/compiled.js dist/signal-bindings/compiled.js && cp src/signal-bindings/compiled.d.ts dist/signal-bindings/compiled.d.ts",
89
27
  "protobuf": "pbjs --target static-module --wrap es6 --out src/signal-bindings/compiled.js src/signal-bindings/signalservice.proto && pbts --out src/signal-bindings/compiled.d.ts src/signal-bindings/compiled.js --force-long"
90
28
  },
91
29
  "dependencies": {
30
+ "@session.js/consts": "^1.0.4",
31
+ "@session.js/errors": "^1.0.11",
92
32
  "lodash": "^4.17.21",
33
+ "long": "^5.3.2",
93
34
  "protobufjs": "^7.3.2"
94
35
  },
95
36
  "devDependencies": {
@@ -99,7 +40,6 @@
99
40
  "eslint-config-prettier": "^10.1.8",
100
41
  "prettier": "^3.8.0",
101
42
  "protobufjs-cli": "^1.1.2",
102
- "tsc-alias": "^1.8.10",
103
43
  "typescript-eslint": "^8.53.1"
104
44
  },
105
45
  "peerDependencies": {