@massalabs/gossip-sdk 0.0.2-dev.20260128111120 → 0.0.2-dev.20260128162527

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.
@@ -0,0 +1,164 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_announcementresult_free: (a: number, b: number) => void;
5
+ export const __wbg_encryptionkey_free: (a: number, b: number) => void;
6
+ export const __wbg_nonce_free: (a: number, b: number) => void;
7
+ export const __wbg_receivemessageoutput_free: (a: number, b: number) => void;
8
+ export const __wbg_sendmessageoutput_free: (a: number, b: number) => void;
9
+ export const __wbg_sessionconfig_free: (a: number, b: number) => void;
10
+ export const __wbg_sessionmanagerwrapper_free: (a: number, b: number) => void;
11
+ export const __wbg_userkeys_free: (a: number, b: number) => void;
12
+ export const __wbg_userpublickeys_free: (a: number, b: number) => void;
13
+ export const __wbg_usersecretkeys_free: (a: number, b: number) => void;
14
+ export const aead_decrypt: (
15
+ a: number,
16
+ b: number,
17
+ c: number,
18
+ d: number,
19
+ e: number,
20
+ f: number
21
+ ) => [number, number];
22
+ export const aead_encrypt: (
23
+ a: number,
24
+ b: number,
25
+ c: number,
26
+ d: number,
27
+ e: number,
28
+ f: number
29
+ ) => [number, number];
30
+ export const announcementresult_announcer_public_keys: (a: number) => number;
31
+ export const announcementresult_timestamp: (a: number) => number;
32
+ export const announcementresult_user_data: (a: number) => [number, number];
33
+ export const encryptionkey_from_bytes: (
34
+ a: number,
35
+ b: number
36
+ ) => [number, number, number];
37
+ export const encryptionkey_from_seed: (
38
+ a: number,
39
+ b: number,
40
+ c: number,
41
+ d: number
42
+ ) => [number, number, number];
43
+ export const encryptionkey_generate: () => number;
44
+ export const encryptionkey_to_bytes: (a: number) => [number, number];
45
+ export const generate_user_keys: (
46
+ a: number,
47
+ b: number
48
+ ) => [number, number, number];
49
+ export const nonce_from_bytes: (
50
+ a: number,
51
+ b: number
52
+ ) => [number, number, number];
53
+ export const nonce_generate: () => number;
54
+ export const nonce_to_bytes: (a: number) => [number, number];
55
+ export const receivemessageoutput_acknowledged_seekers: (a: number) => any;
56
+ export const receivemessageoutput_message: (a: number) => [number, number];
57
+ export const receivemessageoutput_timestamp: (a: number) => number;
58
+ export const receivemessageoutput_user_id: (a: number) => [number, number];
59
+ export const sendmessageoutput_data: (a: number) => [number, number];
60
+ export const sendmessageoutput_seeker: (a: number) => [number, number];
61
+ export const sessionconfig_new: (
62
+ a: number,
63
+ b: number,
64
+ c: number,
65
+ d: number,
66
+ e: number,
67
+ f: number,
68
+ g: bigint
69
+ ) => number;
70
+ export const sessionconfig_new_default: () => number;
71
+ export const sessionmanagerwrapper_establish_outgoing_session: (
72
+ a: number,
73
+ b: number,
74
+ c: number,
75
+ d: number,
76
+ e: number,
77
+ f: number
78
+ ) => [number, number];
79
+ export const sessionmanagerwrapper_feed_incoming_announcement: (
80
+ a: number,
81
+ b: number,
82
+ c: number,
83
+ d: number,
84
+ e: number
85
+ ) => number;
86
+ export const sessionmanagerwrapper_feed_incoming_message_board_read: (
87
+ a: number,
88
+ b: number,
89
+ c: number,
90
+ d: number,
91
+ e: number,
92
+ f: number
93
+ ) => number;
94
+ export const sessionmanagerwrapper_from_encrypted_blob: (
95
+ a: number,
96
+ b: number,
97
+ c: number
98
+ ) => [number, number, number];
99
+ export const sessionmanagerwrapper_get_message_board_read_keys: (
100
+ a: number
101
+ ) => any;
102
+ export const sessionmanagerwrapper_new: (a: number) => number;
103
+ export const sessionmanagerwrapper_peer_discard: (
104
+ a: number,
105
+ b: number,
106
+ c: number
107
+ ) => [number, number];
108
+ export const sessionmanagerwrapper_peer_list: (a: number) => any;
109
+ export const sessionmanagerwrapper_peer_session_status: (
110
+ a: number,
111
+ b: number,
112
+ c: number
113
+ ) => [number, number, number];
114
+ export const sessionmanagerwrapper_refresh: (a: number) => any;
115
+ export const sessionmanagerwrapper_send_message: (
116
+ a: number,
117
+ b: number,
118
+ c: number,
119
+ d: number,
120
+ e: number
121
+ ) => [number, number, number];
122
+ export const sessionmanagerwrapper_to_encrypted_blob: (
123
+ a: number,
124
+ b: number
125
+ ) => [number, number, number, number];
126
+ export const userkeys_public_keys: (a: number) => [number, number, number];
127
+ export const userkeys_secret_keys: (a: number) => [number, number, number];
128
+ export const userpublickeys_derive_id: (a: number) => [number, number];
129
+ export const userpublickeys_dsa_verification_key: (
130
+ a: number
131
+ ) => [number, number];
132
+ export const userpublickeys_from_bytes: (
133
+ a: number,
134
+ b: number
135
+ ) => [number, number, number];
136
+ export const userpublickeys_kem_public_key: (a: number) => [number, number];
137
+ export const userpublickeys_massa_public_key: (a: number) => [number, number];
138
+ export const userpublickeys_to_bytes: (
139
+ a: number
140
+ ) => [number, number, number, number];
141
+ export const usersecretkeys_dsa_signing_key: (a: number) => [number, number];
142
+ export const usersecretkeys_from_bytes: (
143
+ a: number,
144
+ b: number
145
+ ) => [number, number, number];
146
+ export const usersecretkeys_kem_secret_key: (a: number) => [number, number];
147
+ export const usersecretkeys_massa_secret_key: (a: number) => [number, number];
148
+ export const usersecretkeys_to_bytes: (
149
+ a: number
150
+ ) => [number, number, number, number];
151
+ export const start: () => void;
152
+ export const __wbindgen_exn_store: (a: number) => void;
153
+ export const __externref_table_alloc: () => number;
154
+ export const __wbindgen_export_2: WebAssembly.Table;
155
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
156
+ export const __wbindgen_malloc: (a: number, b: number) => number;
157
+ export const __wbindgen_realloc: (
158
+ a: number,
159
+ b: number,
160
+ c: number,
161
+ d: number
162
+ ) => number;
163
+ export const __externref_table_dealloc: (a: number) => void;
164
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "gossip-wasm",
3
+ "version": "0.1.0",
4
+ "files": [
5
+ "gossip_wasm_bg.wasm",
6
+ "gossip_wasm.js",
7
+ "gossip_wasm.d.ts"
8
+ ],
9
+ "main": "gossip_wasm.js",
10
+ "types": "gossip_wasm.d.ts"
11
+ }
@@ -9,23 +9,29 @@
9
9
  const DEFAULT_API_URL = 'https://api.usegossip.com';
10
10
  // Mutable config that can be updated at runtime
11
11
  let currentBaseUrl = null;
12
+ /**
13
+ * Safely get Vite environment variable without causing parse-time errors.
14
+ * Uses dynamic Function evaluation to avoid import.meta syntax errors
15
+ * in environments that don't support ESM (like jiti).
16
+ */
17
+ function getViteEnvUrl() {
18
+ try {
19
+ // Use Function constructor to evaluate import.meta at runtime
20
+ // This avoids parse-time syntax errors in non-ESM environments
21
+ const fn = new Function('return typeof import.meta !== "undefined" && import.meta.env && import.meta.env.VITE_GOSSIP_API_URL');
22
+ return fn() || undefined;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
12
28
  function buildProtocolApiBaseUrl() {
13
29
  // If runtime override is set, use it
14
30
  if (currentBaseUrl !== null) {
15
31
  return currentBaseUrl;
16
32
  }
17
- // Try to get from environment variable (Vite)
18
- let apiUrl;
19
- try {
20
- // Check if import.meta.env is available (Vite environment)
21
- if (typeof import.meta !== 'undefined' &&
22
- import.meta.env?.VITE_GOSSIP_API_URL) {
23
- apiUrl = import.meta.env.VITE_GOSSIP_API_URL;
24
- }
25
- }
26
- catch {
27
- // import.meta.env not available (Node.js without Vite)
28
- }
33
+ // Try to get from Vite environment variable
34
+ let apiUrl = getViteEnvUrl();
29
35
  // Check process.env for Node.js environment
30
36
  if (!apiUrl &&
31
37
  typeof process !== 'undefined' &&
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { type Contact, type GossipDatabase } from './db';
21
21
  import type { UpdateContactNameResult, DeleteContactResult } from './utils/contacts';
22
- import type { UserPublicKeys } from './assets/generated/wasm/gossip_wasm';
22
+ import type { UserPublicKeys } from '#wasm';
23
23
  import type { SessionModule } from './wasm/session';
24
24
  export type { UpdateContactNameResult, DeleteContactResult };
25
25
  /**
@@ -46,7 +46,7 @@ import { type MessageResult, type SendMessageResult } from './services/message';
46
46
  import { AuthService } from './services/auth';
47
47
  import type { DeleteContactResult, UpdateContactNameResult } from './utils/contacts';
48
48
  import { type ValidationResult } from './utils/validation';
49
- import type { UserPublicKeys } from './assets/generated/wasm/gossip_wasm';
49
+ import type { UserPublicKeys } from '#wasm';
50
50
  import { type SdkEventType, type SdkEventHandlers } from './core/SdkEventEmitter';
51
51
  export type { SdkEventType, SdkEventHandlers };
52
52
  export interface GossipSdkInitOptions {
package/dist/index.d.ts CHANGED
@@ -2,36 +2,23 @@
2
2
  * Gossip SDK
3
3
  *
4
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.
5
+ * Works in both browser and Node.js environments.
6
+ *
7
+ * WASM is loaded via the #wasm subpath import which resolves conditionally:
8
+ * - Browser: web target (uses import.meta.url)
9
+ * - Node: nodejs target (uses fs, no import.meta.url)
7
10
  *
8
11
  * @example
9
12
  * ```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
- * });
13
+ * import { gossipSdk } from '@massalabs/gossip-sdk';
17
14
  *
18
- * // Open session (login)
15
+ * await gossipSdk.init({ db, protocolBaseUrl: 'https://api.example.com' });
19
16
  * await gossipSdk.openSession({ mnemonic: '...' });
20
- *
21
- * // Use clean API
22
17
  * 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
18
  * ```
31
19
  *
32
20
  * @packageDocumentation
33
21
  */
34
- export declare const SDK_VERSION = "0.0.1";
35
22
  export { gossipSdk, GossipSdkImpl } from './gossipSdk';
36
23
  export type { GossipSdkInitOptions, OpenSessionOptions, SdkEventType, SdkEventHandlers, } from './gossipSdk';
37
24
  export type { GossipSdkEvents } from './types/events';
@@ -59,7 +46,7 @@ export { setDb, getDb, db, GossipDatabase } from './db';
59
46
  export { SessionModule, sessionStatusToString } from './wasm/session';
60
47
  export { initializeWasm, ensureWasmInitialized, startWasmInitialization, } from './wasm/loader';
61
48
  export { EncryptionKey, Nonce, generateEncryptionKey, generateEncryptionKeyFromSeed, encryptionKeyFromBytes, generateNonce, nonceFromBytes, encryptAead, decryptAead, } from './wasm/encryption';
62
- export { generateUserKeys } from './wasm/userKeys';
49
+ export { generateUserKeys, UserKeys } from './wasm/userKeys';
63
50
  export { encodeUserId, decodeUserId, isValidUserId, formatUserId, generate as generateUserId, } from './utils/userId';
64
51
  export { validateUsernameFormat, validatePassword, validateUserIdFormat, validateUsernameAvailability, validateUsernameFormatAndAvailability, } from './utils/validation';
65
52
  export type { ValidationResult } from './utils/validation';
@@ -69,5 +56,4 @@ export { MESSAGE_TYPE_KEEP_ALIVE, serializeKeepAliveMessage, serializeRegularMes
69
56
  export type { DeserializedMessage } from './utils/messageSerialization';
70
57
  export { generateMnemonic, validateMnemonic, mnemonicToSeed, accountFromMnemonic, PRIVATE_KEY_VERSION, } from './crypto/bip39';
71
58
  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';
59
+ export { UserPublicKeys, UserSecretKeys, SessionStatus, SessionConfig, SessionManagerWrapper, SendMessageOutput, ReceiveMessageOutput, AnnouncementResult, generate_user_keys, } from '#wasm';
package/dist/index.js CHANGED
@@ -2,76 +2,60 @@
2
2
  * Gossip SDK
3
3
  *
4
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.
5
+ * Works in both browser and Node.js environments.
6
+ *
7
+ * WASM is loaded via the #wasm subpath import which resolves conditionally:
8
+ * - Browser: web target (uses import.meta.url)
9
+ * - Node: nodejs target (uses fs, no import.meta.url)
7
10
  *
8
11
  * @example
9
12
  * ```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
- * });
13
+ * import { gossipSdk } from '@massalabs/gossip-sdk';
17
14
  *
18
- * // Open session (login)
15
+ * await gossipSdk.init({ db, protocolBaseUrl: 'https://api.example.com' });
19
16
  * await gossipSdk.openSession({ mnemonic: '...' });
20
- *
21
- * // Use clean API
22
17
  * 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
18
  * ```
31
19
  *
32
20
  * @packageDocumentation
33
21
  */
34
- // SDK version - matches package.json
35
- export const SDK_VERSION = '0.0.1';
36
22
  // ─────────────────────────────────────────────────────────────────────────────
37
23
  // SDK Singleton - Primary API
38
24
  // ─────────────────────────────────────────────────────────────────────────────
39
25
  export { gossipSdk, GossipSdkImpl } from './gossipSdk';
40
- // Services - class-based with dependency injection
26
+ // Services
41
27
  export { AuthService } from './services/auth';
42
28
  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
29
  export { AnnouncementService, EstablishSessionError, } from './services/announcement';
44
30
  export { MessageService } from './services/message';
45
31
  export { DiscussionService } from './services/discussion';
46
32
  export { RefreshService } from './services/refresh';
47
- // Contact Management (utility functions)
33
+ // Contact Management
48
34
  export { getContacts, getContact, addContact, updateContactName, deleteContact, } from './contacts';
49
35
  // Discussion utilities
50
36
  export { updateDiscussionName } from './utils/discussions';
51
- // Types - re-export all types from the types module
37
+ // Types
52
38
  export * from './types';
53
- // Message Protocol - for direct use by host apps
39
+ // Message Protocol
54
40
  export { createMessageProtocol, restMessageProtocol, RestMessageProtocol, MessageProtocol, } from './api/messageProtocol';
55
- // Config - for runtime configuration
41
+ // Config
56
42
  export { setProtocolBaseUrl, resetProtocolBaseUrl, MessageProtocolType, protocolConfig, } from './config/protocol';
57
- // SDK Config - for SDK initialization options
58
43
  export { defaultSdkConfig, mergeConfig } from './config/sdk';
59
- // Database - for direct access by host apps
44
+ // Database
60
45
  export { setDb, getDb, db, GossipDatabase } from './db';
61
- // WASM utilities - for session management
46
+ // WASM utilities
62
47
  export { SessionModule, sessionStatusToString } from './wasm/session';
63
48
  export { initializeWasm, ensureWasmInitialized, startWasmInitialization, } from './wasm/loader';
64
49
  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
50
+ export { generateUserKeys, UserKeys } from './wasm/userKeys';
51
+ // Utility functions
67
52
  export { encodeUserId, decodeUserId, isValidUserId, formatUserId, generate as generateUserId, } from './utils/userId';
68
53
  export { validateUsernameFormat, validatePassword, validateUserIdFormat, validateUsernameAvailability, validateUsernameFormatAndAvailability, } from './utils/validation';
69
54
  export { encodeToBase64, decodeFromBase64, encodeToBase64Url, decodeFromBase64Url, } from './utils/base64';
70
- // Message serialization utilities
55
+ // Message serialization
71
56
  export { MESSAGE_TYPE_KEEP_ALIVE, serializeKeepAliveMessage, serializeRegularMessage, serializeReplyMessage, serializeForwardMessage, deserializeMessage, } from './utils/messageSerialization';
72
57
  // Crypto utilities
73
58
  export { generateMnemonic, validateMnemonic, mnemonicToSeed, accountFromMnemonic, PRIVATE_KEY_VERSION, } from './crypto/bip39';
74
59
  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';
60
+ // WASM types re-exported for convenience
61
+ export { UserPublicKeys, UserSecretKeys, SessionStatus, SessionConfig, SessionManagerWrapper, SendMessageOutput, ReceiveMessageOutput, AnnouncementResult, generate_user_keys, } from '#wasm';
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { type Discussion, type GossipDatabase } from '../db';
7
7
  import { IMessageProtocol } from '../api/messageProtocol';
8
- import { UserPublicKeys } from '../assets/generated/wasm/gossip_wasm';
8
+ import { UserPublicKeys } from '#wasm';
9
9
  import { SessionModule } from '../wasm/session';
10
10
  import { GossipSdkEvents } from '../types/events';
11
11
  import { SdkConfig } from '../config/sdk';
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { DiscussionStatus, DiscussionDirection, } from '../db';
7
7
  import { decodeUserId, encodeUserId } from '../utils/userId';
8
- import { SessionStatus, } from '../assets/generated/wasm/gossip_wasm';
8
+ import { SessionStatus } from '#wasm';
9
9
  import { sessionStatusToString } from '../wasm/session';
10
10
  import { Logger } from '../utils/logs';
11
11
  import { defaultSdkConfig } from '../config/sdk';
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Handles storing and retrieving public keys by userId hash via the auth API.
5
5
  */
6
- import { UserPublicKeys } from '../assets/generated/wasm/gossip_wasm';
6
+ import { UserPublicKeys } from '#wasm';
7
7
  import { IMessageProtocol } from '../api/messageProtocol/types';
8
8
  import { type GossipDatabase } from '../db';
9
9
  export type PublicKeyResult = {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Handles storing and retrieving public keys by userId hash via the auth API.
5
5
  */
6
- import { UserPublicKeys } from '../assets/generated/wasm/gossip_wasm';
6
+ import { UserPublicKeys } from '#wasm';
7
7
  import { decodeUserId } from '../utils/userId';
8
8
  import { encodeToBase64, decodeFromBase64 } from '../utils/base64';
9
9
  export class AuthService {
@@ -4,7 +4,7 @@
4
4
  * Class-based service for initializing, accepting, and managing discussions.
5
5
  */
6
6
  import { DiscussionStatus, MessageDirection, MessageStatus, DiscussionDirection, } from '../db';
7
- import { UserPublicKeys, SessionStatus, } from '../assets/generated/wasm/gossip_wasm';
7
+ import { UserPublicKeys, SessionStatus } from '#wasm';
8
8
  import { EstablishSessionError } from './announcement';
9
9
  import { sessionStatusToString } from '../wasm/session';
10
10
  import { decodeUserId } from '../utils/userId';
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { DiscussionStatus, MessageDirection, MessageStatus, MessageType, } from '../db';
8
8
  import { decodeUserId, encodeUserId } from '../utils/userId';
9
- import { SessionStatus, } from '../assets/generated/wasm/gossip_wasm';
9
+ import { SessionStatus } from '#wasm';
10
10
  import { serializeRegularMessage, serializeReplyMessage, serializeForwardMessage, serializeKeepAliveMessage, deserializeMessage, } from '../utils/messageSerialization';
11
11
  import { encodeToBase64 } from '../utils/base64';
12
12
  import { sessionStatusToString } from '../wasm/session';
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { MessageDirection, MessageStatus, MessageType, } from '../db';
8
8
  import { sessionStatusToString } from '../wasm/session';
9
- import { SessionStatus } from '../assets/generated/wasm/gossip_wasm';
9
+ import { SessionStatus } from '#wasm';
10
10
  import { decodeUserId, encodeUserId } from '../utils/userId';
11
11
  import { Logger } from '../utils/logs';
12
12
  const logger = new Logger('RefreshService');
@@ -5,7 +5,7 @@
5
5
  * and AEAD (Authenticated Encryption with Additional Data) operations,
6
6
  * ensuring proper initialization before calling any WASM functions.
7
7
  */
8
- import { EncryptionKey, Nonce } from '../assets/generated/wasm/gossip_wasm';
8
+ import { EncryptionKey, Nonce } from '#wasm';
9
9
  export { EncryptionKey, Nonce };
10
10
  /**
11
11
  * Generate a new random encryption key (64 bytes)
@@ -6,7 +6,7 @@
6
6
  * ensuring proper initialization before calling any WASM functions.
7
7
  */
8
8
  import { ensureWasmInitialized } from './loader';
9
- import { EncryptionKey, Nonce, aead_encrypt as _aead_encrypt, aead_decrypt as _aead_decrypt, } from '../assets/generated/wasm/gossip_wasm';
9
+ import { EncryptionKey, Nonce, aead_encrypt as _aead_encrypt, aead_decrypt as _aead_decrypt, } from '#wasm';
10
10
  // Re-export classes
11
11
  export { EncryptionKey, Nonce };
12
12
  /**
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * WASM Module Loader and Initialization Service
3
3
  *
4
- * This file handles both WASM core initialization and module loading.
5
- * It ensures WASM modules are initialized once and properly throughout
6
- * the application lifecycle.
4
+ * This file handles WASM initialization. The actual wasm module is resolved
5
+ * via the #wasm import which conditionally loads the correct target:
6
+ * - Browser: web target (has init function, uses import.meta.url + fetch)
7
+ * - Node: nodejs target (auto-initializes, no init function needed)
7
8
  */
8
9
  /**
9
10
  * Initialize WASM modules if not already initialized
@@ -1,38 +1,15 @@
1
1
  /**
2
2
  * WASM Module Loader and Initialization Service
3
3
  *
4
- * This file handles both WASM core initialization and module loading.
5
- * It ensures WASM modules are initialized once and properly throughout
6
- * the application lifecycle.
4
+ * This file handles WASM initialization. The actual wasm module is resolved
5
+ * via the #wasm import which conditionally loads the correct target:
6
+ * - Browser: web target (has init function, uses import.meta.url + fetch)
7
+ * - Node: nodejs target (auto-initializes, no init function needed)
7
8
  */
8
- import init from '../assets/generated/wasm/gossip_wasm';
9
- /**
10
- * Check if we're running in Node.js environment
11
- */
12
- function isNodeEnvironment() {
13
- return (typeof process !== 'undefined' &&
14
- process.versions != null &&
15
- process.versions.node != null);
16
- }
17
- /**
18
- * Load WASM module for Node.js environment using fs.readFileSync
19
- */
20
- async function loadWasmForNode() {
21
- // Dynamic import to avoid bundling Node.js modules in browser builds
22
- const fs = await import('node:fs');
23
- const path = await import('node:path');
24
- const { fileURLToPath } = await import('node:url');
25
- // Get the directory of the current module
26
- const __filename = fileURLToPath(import.meta.url);
27
- const __dirname = path.dirname(__filename);
28
- // Resolve path to WASM file - WASM is in the SDK's generated folder
29
- const wasmPath = path.resolve(__dirname, '../assets/generated/wasm/gossip_wasm_bg.wasm');
30
- // Read WASM file as binary
31
- const wasmBuffer = fs.readFileSync(wasmPath);
32
- // Instantiate WASM module
33
- const wasmModule = await WebAssembly.compile(wasmBuffer);
34
- return wasmModule;
35
- }
9
+ import * as wasmModule from '#wasm';
10
+ // The web target has a default export (init function), nodejs target doesn't
11
+ const init = wasmModule
12
+ .default;
36
13
  /**
37
14
  * WASM Initialization State
38
15
  */
@@ -58,15 +35,13 @@ export async function initializeWasm() {
58
35
  initError = null;
59
36
  initializationPromise = (async () => {
60
37
  try {
61
- // In Node.js environment, load WASM using fs.readFileSync
62
- if (isNodeEnvironment()) {
63
- const wasmModule = await loadWasmForNode();
64
- await init(wasmModule);
65
- }
66
- else {
67
- // In browser/jsdom, use default init (which uses fetch)
38
+ // The #wasm import resolves to the correct target based on environment:
39
+ // - Browser (web target): has init() function that needs to be called
40
+ // - Node (nodejs target): auto-initializes on import, no init needed
41
+ if (typeof init === 'function') {
68
42
  await init();
69
43
  }
44
+ // For nodejs target, wasm is already initialized on import
70
45
  isInitialized = true;
71
46
  isInitializing = false;
72
47
  }
@@ -4,7 +4,7 @@
4
4
  * This file contains the real WASM implementation of the SessionModule
5
5
  * using SessionManagerWrapper and related WASM classes.
6
6
  */
7
- import { UserPublicKeys, UserSecretKeys, ReceiveMessageOutput, SendMessageOutput, SessionStatus, EncryptionKey, SessionConfig, AnnouncementResult, UserKeys } from '../assets/generated/wasm/gossip_wasm';
7
+ import { UserPublicKeys, UserSecretKeys, ReceiveMessageOutput, SendMessageOutput, SessionStatus, EncryptionKey, SessionConfig, AnnouncementResult, UserKeys } from '#wasm';
8
8
  import { UserProfile } from '../db';
9
9
  export declare class SessionModule {
10
10
  private sessionManager;
@@ -4,7 +4,7 @@
4
4
  * This file contains the real WASM implementation of the SessionModule
5
5
  * using SessionManagerWrapper and related WASM classes.
6
6
  */
7
- import { SessionManagerWrapper, SessionStatus, SessionConfig, } from '../assets/generated/wasm/gossip_wasm';
7
+ import { SessionManagerWrapper, SessionStatus, SessionConfig, } from '#wasm';
8
8
  import { encodeUserId } from '../utils/userId';
9
9
  export class SessionModule {
10
10
  constructor(userKeys, onPersist, config) {
@@ -4,7 +4,7 @@
4
4
  * This file provides proxy functions for user key generation,
5
5
  * ensuring proper initialization before calling any WASM functions.
6
6
  */
7
- import { UserKeys } from '../assets/generated/wasm/gossip_wasm';
7
+ import { UserKeys } from '#wasm';
8
8
  export { UserKeys };
9
9
  /**
10
10
  * Generate user keys from a passphrase using password-based key derivation
@@ -5,7 +5,7 @@
5
5
  * ensuring proper initialization before calling any WASM functions.
6
6
  */
7
7
  import { ensureWasmInitialized } from './loader';
8
- import { generate_user_keys as _generate_user_keys, UserKeys, } from '../assets/generated/wasm/gossip_wasm';
8
+ import { generate_user_keys as _generate_user_keys, UserKeys } from '#wasm';
9
9
  // Re-export classes
10
10
  export { UserKeys };
11
11
  /**