@massalabs/gossip-sdk 0.0.2-dev.20260128094509 → 0.0.2-dev.20260128111120
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/api/messageProtocol/index.d.ts +19 -0
- package/dist/api/messageProtocol/index.js +26 -0
- package/dist/api/messageProtocol/mock.d.ts +12 -0
- package/{src/api/messageProtocol/mock.ts → dist/api/messageProtocol/mock.js} +2 -3
- package/dist/api/messageProtocol/rest.d.ts +22 -0
- package/dist/api/messageProtocol/rest.js +161 -0
- package/dist/api/messageProtocol/types.d.ts +61 -0
- package/dist/api/messageProtocol/types.js +6 -0
- package/dist/assets/generated/wasm/README.md +281 -0
- package/dist/assets/generated/wasm/gossip_wasm.d.ts +498 -0
- package/dist/assets/generated/wasm/gossip_wasm.js +1399 -0
- package/dist/assets/generated/wasm/gossip_wasm_bg.wasm +0 -0
- package/dist/assets/generated/wasm/gossip_wasm_bg.wasm.d.ts +68 -0
- package/dist/assets/generated/wasm/package.json +15 -0
- package/dist/config/protocol.d.ts +36 -0
- package/dist/config/protocol.js +77 -0
- package/dist/config/sdk.d.ts +82 -0
- package/dist/config/sdk.js +55 -0
- package/{src/contacts.ts → dist/contacts.d.ts} +10 -94
- package/dist/contacts.js +166 -0
- package/dist/core/SdkEventEmitter.d.ts +36 -0
- package/dist/core/SdkEventEmitter.js +59 -0
- package/dist/core/SdkPolling.d.ts +35 -0
- package/dist/core/SdkPolling.js +100 -0
- package/{src/core/index.ts → dist/core/index.d.ts} +0 -2
- package/dist/core/index.js +5 -0
- package/dist/crypto/bip39.d.ts +34 -0
- package/dist/crypto/bip39.js +62 -0
- package/dist/crypto/encryption.d.ts +37 -0
- package/dist/crypto/encryption.js +46 -0
- package/dist/db.d.ts +190 -0
- package/dist/db.js +311 -0
- package/dist/gossipSdk.d.ts +274 -0
- package/dist/gossipSdk.js +690 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +77 -0
- package/dist/services/announcement.d.ts +43 -0
- package/dist/services/announcement.js +491 -0
- package/dist/services/auth.d.ts +37 -0
- package/dist/services/auth.js +76 -0
- package/dist/services/discussion.d.ts +63 -0
- package/dist/services/discussion.js +297 -0
- package/dist/services/message.d.ts +74 -0
- package/dist/services/message.js +826 -0
- package/dist/services/refresh.d.ts +41 -0
- package/dist/services/refresh.js +205 -0
- package/{src/sw.ts → dist/sw.d.ts} +1 -8
- package/dist/sw.js +10 -0
- package/dist/types/events.d.ts +80 -0
- package/dist/types/events.js +7 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +7 -0
- package/dist/utils/base64.d.ts +10 -0
- package/dist/utils/base64.js +30 -0
- package/dist/utils/contacts.d.ts +42 -0
- package/dist/utils/contacts.js +113 -0
- package/dist/utils/discussions.d.ts +24 -0
- package/dist/utils/discussions.js +38 -0
- package/dist/utils/logs.d.ts +19 -0
- package/dist/utils/logs.js +89 -0
- package/dist/utils/messageSerialization.d.ts +64 -0
- package/dist/utils/messageSerialization.js +184 -0
- package/dist/utils/queue.d.ts +50 -0
- package/dist/utils/queue.js +110 -0
- package/dist/utils/type.d.ts +10 -0
- package/dist/utils/type.js +4 -0
- package/dist/utils/userId.d.ts +40 -0
- package/dist/utils/userId.js +90 -0
- package/dist/utils/validation.d.ts +50 -0
- package/dist/utils/validation.js +112 -0
- package/dist/utils.d.ts +30 -0
- package/{src/utils.ts → dist/utils.js} +9 -19
- package/dist/wasm/encryption.d.ts +56 -0
- package/{src/wasm/encryption.ts → dist/wasm/encryption.js} +22 -51
- package/dist/wasm/index.d.ts +10 -0
- package/{src/wasm/index.ts → dist/wasm/index.js} +1 -8
- package/dist/wasm/loader.d.ts +21 -0
- package/dist/wasm/loader.js +103 -0
- package/dist/wasm/session.d.ts +85 -0
- package/dist/wasm/session.js +226 -0
- package/dist/wasm/userKeys.d.ts +17 -0
- package/{src/wasm/userKeys.ts → dist/wasm/userKeys.js} +6 -13
- package/package.json +5 -1
- package/src/api/messageProtocol/index.ts +0 -53
- package/src/api/messageProtocol/rest.ts +0 -209
- package/src/api/messageProtocol/types.ts +0 -70
- package/src/config/protocol.ts +0 -97
- package/src/config/sdk.ts +0 -131
- package/src/core/SdkEventEmitter.ts +0 -91
- package/src/core/SdkPolling.ts +0 -134
- package/src/crypto/bip39.ts +0 -84
- package/src/crypto/encryption.ts +0 -77
- package/src/db.ts +0 -465
- package/src/gossipSdk.ts +0 -994
- package/src/index.ts +0 -211
- package/src/services/announcement.ts +0 -653
- package/src/services/auth.ts +0 -95
- package/src/services/discussion.ts +0 -380
- package/src/services/message.ts +0 -1055
- package/src/services/refresh.ts +0 -234
- package/src/types/events.ts +0 -108
- package/src/types.ts +0 -70
- package/src/utils/base64.ts +0 -39
- package/src/utils/contacts.ts +0 -161
- package/src/utils/discussions.ts +0 -55
- package/src/utils/logs.ts +0 -86
- package/src/utils/messageSerialization.ts +0 -257
- package/src/utils/queue.ts +0 -106
- package/src/utils/type.ts +0 -7
- package/src/utils/userId.ts +0 -114
- package/src/utils/validation.ts +0 -144
- package/src/wasm/loader.ts +0 -123
- package/src/wasm/session.ts +0 -276
- package/test/config/protocol.spec.ts +0 -31
- package/test/config/sdk.spec.ts +0 -163
- package/test/db/helpers.spec.ts +0 -142
- package/test/db/operations.spec.ts +0 -128
- package/test/db/states.spec.ts +0 -535
- package/test/integration/discussion-flow.spec.ts +0 -422
- package/test/integration/messaging-flow.spec.ts +0 -708
- package/test/integration/sdk-lifecycle.spec.ts +0 -325
- package/test/mocks/index.ts +0 -9
- package/test/mocks/mockMessageProtocol.ts +0 -100
- package/test/services/auth.spec.ts +0 -311
- package/test/services/discussion.spec.ts +0 -279
- package/test/services/message-deduplication.spec.ts +0 -299
- package/test/services/message-startup.spec.ts +0 -331
- package/test/services/message.spec.ts +0 -817
- package/test/services/refresh.spec.ts +0 -199
- package/test/services/session-status.spec.ts +0 -349
- package/test/session/wasm.spec.ts +0 -227
- package/test/setup.ts +0 -52
- package/test/utils/contacts.spec.ts +0 -156
- package/test/utils/discussions.spec.ts +0 -66
- package/test/utils/queue.spec.ts +0 -52
- package/test/utils/serialization.spec.ts +0 -120
- package/test/utils/userId.spec.ts +0 -120
- package/test/utils/validation.spec.ts +0 -223
- package/test/utils.ts +0 -212
- package/tsconfig.json +0 -26
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -28
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gossip SDK
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Gossip SDK.
|
|
5
|
+
* Provides a platform-agnostic interface for automation, chatbot,
|
|
6
|
+
* and integration use cases with the Gossip messenger.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { gossipSdk } from 'gossip-sdk';
|
|
11
|
+
*
|
|
12
|
+
* // Initialize once at app startup
|
|
13
|
+
* await gossipSdk.init({
|
|
14
|
+
* db,
|
|
15
|
+
* protocolBaseUrl: 'https://api.example.com',
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Open session (login)
|
|
19
|
+
* await gossipSdk.openSession({ mnemonic: '...' });
|
|
20
|
+
*
|
|
21
|
+
* // Use clean API
|
|
22
|
+
* await gossipSdk.messages.send(contactId, 'Hello!');
|
|
23
|
+
* await gossipSdk.discussions.start(contact);
|
|
24
|
+
*
|
|
25
|
+
* // Events
|
|
26
|
+
* gossipSdk.on('message', (msg) => { ... });
|
|
27
|
+
*
|
|
28
|
+
* // Logout
|
|
29
|
+
* await gossipSdk.closeSession();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @packageDocumentation
|
|
33
|
+
*/
|
|
34
|
+
export declare const SDK_VERSION = "0.0.1";
|
|
35
|
+
export { gossipSdk, GossipSdkImpl } from './gossipSdk';
|
|
36
|
+
export type { GossipSdkInitOptions, OpenSessionOptions, SdkEventType, SdkEventHandlers, } from './gossipSdk';
|
|
37
|
+
export type { GossipSdkEvents } from './types/events';
|
|
38
|
+
export { AuthService } from './services/auth';
|
|
39
|
+
export type { PublicKeyResult } from './services/auth';
|
|
40
|
+
export { getPublicKeyErrorMessage, PUBLIC_KEY_NOT_FOUND_ERROR, PUBLIC_KEY_NOT_FOUND_MESSAGE, FAILED_TO_FETCH_ERROR, FAILED_TO_FETCH_MESSAGE, FAILED_TO_RETRIEVE_CONTACT_PUBLIC_KEY_ERROR, } from './services/auth';
|
|
41
|
+
export { AnnouncementService, EstablishSessionError, } from './services/announcement';
|
|
42
|
+
export type { AnnouncementReceptionResult } from './services/announcement';
|
|
43
|
+
export { MessageService } from './services/message';
|
|
44
|
+
export type { MessageResult, SendMessageResult } from './services/message';
|
|
45
|
+
export { DiscussionService } from './services/discussion';
|
|
46
|
+
export { RefreshService } from './services/refresh';
|
|
47
|
+
export { getContacts, getContact, addContact, updateContactName, deleteContact, } from './contacts';
|
|
48
|
+
export type { UpdateContactNameResult, DeleteContactResult, } from './utils/contacts';
|
|
49
|
+
export { updateDiscussionName } from './utils/discussions';
|
|
50
|
+
export type { UpdateDiscussionNameResult } from './utils/discussions';
|
|
51
|
+
export * from './types';
|
|
52
|
+
export { createMessageProtocol, restMessageProtocol, RestMessageProtocol, MessageProtocol, } from './api/messageProtocol';
|
|
53
|
+
export type { IMessageProtocol, EncryptedMessage, MessageProtocolResponse, BulletinItem, } from './api/messageProtocol';
|
|
54
|
+
export { setProtocolBaseUrl, resetProtocolBaseUrl, MessageProtocolType, protocolConfig, } from './config/protocol';
|
|
55
|
+
export type { ProtocolConfig } from './config/protocol';
|
|
56
|
+
export { defaultSdkConfig, mergeConfig } from './config/sdk';
|
|
57
|
+
export type { SdkConfig, PollingConfig, MessagesConfig, AnnouncementsConfig, DeepPartial, } from './config/sdk';
|
|
58
|
+
export { setDb, getDb, db, GossipDatabase } from './db';
|
|
59
|
+
export { SessionModule, sessionStatusToString } from './wasm/session';
|
|
60
|
+
export { initializeWasm, ensureWasmInitialized, startWasmInitialization, } from './wasm/loader';
|
|
61
|
+
export { EncryptionKey, Nonce, generateEncryptionKey, generateEncryptionKeyFromSeed, encryptionKeyFromBytes, generateNonce, nonceFromBytes, encryptAead, decryptAead, } from './wasm/encryption';
|
|
62
|
+
export { generateUserKeys } from './wasm/userKeys';
|
|
63
|
+
export { encodeUserId, decodeUserId, isValidUserId, formatUserId, generate as generateUserId, } from './utils/userId';
|
|
64
|
+
export { validateUsernameFormat, validatePassword, validateUserIdFormat, validateUsernameAvailability, validateUsernameFormatAndAvailability, } from './utils/validation';
|
|
65
|
+
export type { ValidationResult } from './utils/validation';
|
|
66
|
+
export { encodeToBase64, decodeFromBase64, encodeToBase64Url, decodeFromBase64Url, } from './utils/base64';
|
|
67
|
+
export type { Result } from './utils/type';
|
|
68
|
+
export { MESSAGE_TYPE_KEEP_ALIVE, serializeKeepAliveMessage, serializeRegularMessage, serializeReplyMessage, serializeForwardMessage, deserializeMessage, } from './utils/messageSerialization';
|
|
69
|
+
export type { DeserializedMessage } from './utils/messageSerialization';
|
|
70
|
+
export { generateMnemonic, validateMnemonic, mnemonicToSeed, accountFromMnemonic, PRIVATE_KEY_VERSION, } from './crypto/bip39';
|
|
71
|
+
export { encrypt, decrypt, deriveKey } from './crypto/encryption';
|
|
72
|
+
export { UserPublicKeys, UserSecretKeys, SessionStatus, SessionConfig, SessionManagerWrapper, SendMessageOutput, ReceiveMessageOutput, AnnouncementResult, generate_user_keys, } from './assets/generated/wasm/gossip_wasm';
|
|
73
|
+
export { UserKeys } from './wasm/userKeys';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gossip SDK
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Gossip SDK.
|
|
5
|
+
* Provides a platform-agnostic interface for automation, chatbot,
|
|
6
|
+
* and integration use cases with the Gossip messenger.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { gossipSdk } from 'gossip-sdk';
|
|
11
|
+
*
|
|
12
|
+
* // Initialize once at app startup
|
|
13
|
+
* await gossipSdk.init({
|
|
14
|
+
* db,
|
|
15
|
+
* protocolBaseUrl: 'https://api.example.com',
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Open session (login)
|
|
19
|
+
* await gossipSdk.openSession({ mnemonic: '...' });
|
|
20
|
+
*
|
|
21
|
+
* // Use clean API
|
|
22
|
+
* await gossipSdk.messages.send(contactId, 'Hello!');
|
|
23
|
+
* await gossipSdk.discussions.start(contact);
|
|
24
|
+
*
|
|
25
|
+
* // Events
|
|
26
|
+
* gossipSdk.on('message', (msg) => { ... });
|
|
27
|
+
*
|
|
28
|
+
* // Logout
|
|
29
|
+
* await gossipSdk.closeSession();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @packageDocumentation
|
|
33
|
+
*/
|
|
34
|
+
// SDK version - matches package.json
|
|
35
|
+
export const SDK_VERSION = '0.0.1';
|
|
36
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
// SDK Singleton - Primary API
|
|
38
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
39
|
+
export { gossipSdk, GossipSdkImpl } from './gossipSdk';
|
|
40
|
+
// Services - class-based with dependency injection
|
|
41
|
+
export { AuthService } from './services/auth';
|
|
42
|
+
export { getPublicKeyErrorMessage, PUBLIC_KEY_NOT_FOUND_ERROR, PUBLIC_KEY_NOT_FOUND_MESSAGE, FAILED_TO_FETCH_ERROR, FAILED_TO_FETCH_MESSAGE, FAILED_TO_RETRIEVE_CONTACT_PUBLIC_KEY_ERROR, } from './services/auth';
|
|
43
|
+
export { AnnouncementService, EstablishSessionError, } from './services/announcement';
|
|
44
|
+
export { MessageService } from './services/message';
|
|
45
|
+
export { DiscussionService } from './services/discussion';
|
|
46
|
+
export { RefreshService } from './services/refresh';
|
|
47
|
+
// Contact Management (utility functions)
|
|
48
|
+
export { getContacts, getContact, addContact, updateContactName, deleteContact, } from './contacts';
|
|
49
|
+
// Discussion utilities
|
|
50
|
+
export { updateDiscussionName } from './utils/discussions';
|
|
51
|
+
// Types - re-export all types from the types module
|
|
52
|
+
export * from './types';
|
|
53
|
+
// Message Protocol - for direct use by host apps
|
|
54
|
+
export { createMessageProtocol, restMessageProtocol, RestMessageProtocol, MessageProtocol, } from './api/messageProtocol';
|
|
55
|
+
// Config - for runtime configuration
|
|
56
|
+
export { setProtocolBaseUrl, resetProtocolBaseUrl, MessageProtocolType, protocolConfig, } from './config/protocol';
|
|
57
|
+
// SDK Config - for SDK initialization options
|
|
58
|
+
export { defaultSdkConfig, mergeConfig } from './config/sdk';
|
|
59
|
+
// Database - for direct access by host apps
|
|
60
|
+
export { setDb, getDb, db, GossipDatabase } from './db';
|
|
61
|
+
// WASM utilities - for session management
|
|
62
|
+
export { SessionModule, sessionStatusToString } from './wasm/session';
|
|
63
|
+
export { initializeWasm, ensureWasmInitialized, startWasmInitialization, } from './wasm/loader';
|
|
64
|
+
export { EncryptionKey, Nonce, generateEncryptionKey, generateEncryptionKeyFromSeed, encryptionKeyFromBytes, generateNonce, nonceFromBytes, encryptAead, decryptAead, } from './wasm/encryption';
|
|
65
|
+
export { generateUserKeys } from './wasm/userKeys';
|
|
66
|
+
// Utility functions - for direct use
|
|
67
|
+
export { encodeUserId, decodeUserId, isValidUserId, formatUserId, generate as generateUserId, } from './utils/userId';
|
|
68
|
+
export { validateUsernameFormat, validatePassword, validateUserIdFormat, validateUsernameAvailability, validateUsernameFormatAndAvailability, } from './utils/validation';
|
|
69
|
+
export { encodeToBase64, decodeFromBase64, encodeToBase64Url, decodeFromBase64Url, } from './utils/base64';
|
|
70
|
+
// Message serialization utilities
|
|
71
|
+
export { MESSAGE_TYPE_KEEP_ALIVE, serializeKeepAliveMessage, serializeRegularMessage, serializeReplyMessage, serializeForwardMessage, deserializeMessage, } from './utils/messageSerialization';
|
|
72
|
+
// Crypto utilities
|
|
73
|
+
export { generateMnemonic, validateMnemonic, mnemonicToSeed, accountFromMnemonic, PRIVATE_KEY_VERSION, } from './crypto/bip39';
|
|
74
|
+
export { encrypt, decrypt, deriveKey } from './crypto/encryption';
|
|
75
|
+
// WASM types and functions re-exported for convenience
|
|
76
|
+
export { UserPublicKeys, UserSecretKeys, SessionStatus, SessionConfig, SessionManagerWrapper, SendMessageOutput, ReceiveMessageOutput, AnnouncementResult, generate_user_keys, } from './assets/generated/wasm/gossip_wasm';
|
|
77
|
+
export { UserKeys } from './wasm/userKeys';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Announcement Service
|
|
3
|
+
*
|
|
4
|
+
* Handles broadcasting and processing of session announcements.
|
|
5
|
+
*/
|
|
6
|
+
import { type Discussion, type GossipDatabase } from '../db';
|
|
7
|
+
import { IMessageProtocol } from '../api/messageProtocol';
|
|
8
|
+
import { UserPublicKeys } from '../assets/generated/wasm/gossip_wasm';
|
|
9
|
+
import { SessionModule } from '../wasm/session';
|
|
10
|
+
import { GossipSdkEvents } from '../types/events';
|
|
11
|
+
import { SdkConfig } from '../config/sdk';
|
|
12
|
+
export interface AnnouncementReceptionResult {
|
|
13
|
+
success: boolean;
|
|
14
|
+
newAnnouncementsCount: number;
|
|
15
|
+
error?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const EstablishSessionError = "Session manager failed to establish outgoing session";
|
|
18
|
+
export declare class AnnouncementService {
|
|
19
|
+
private db;
|
|
20
|
+
private messageProtocol;
|
|
21
|
+
private session;
|
|
22
|
+
private isProcessingAnnouncements;
|
|
23
|
+
private events;
|
|
24
|
+
private config;
|
|
25
|
+
constructor(db: GossipDatabase, messageProtocol: IMessageProtocol, session: SessionModule, events?: GossipSdkEvents, config?: SdkConfig);
|
|
26
|
+
setMessageProtocol(messageProtocol: IMessageProtocol): void;
|
|
27
|
+
sendAnnouncement(announcement: Uint8Array): Promise<{
|
|
28
|
+
success: boolean;
|
|
29
|
+
counter?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
}>;
|
|
32
|
+
establishSession(contactPublicKeys: UserPublicKeys, userData?: Uint8Array): Promise<{
|
|
33
|
+
success: boolean;
|
|
34
|
+
error?: string;
|
|
35
|
+
announcement: Uint8Array;
|
|
36
|
+
}>;
|
|
37
|
+
fetchAndProcessAnnouncements(): Promise<AnnouncementReceptionResult>;
|
|
38
|
+
resendAnnouncements(failedDiscussions: Discussion[]): Promise<void>;
|
|
39
|
+
private _fetchAnnouncements;
|
|
40
|
+
private _generateTemporaryContactName;
|
|
41
|
+
private _processIncomingAnnouncement;
|
|
42
|
+
private _handleReceivedDiscussion;
|
|
43
|
+
}
|