@massalabs/gossip-sdk 0.0.1 → 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.
Files changed (142) hide show
  1. package/dist/api/messageProtocol/index.d.ts +19 -0
  2. package/dist/api/messageProtocol/index.js +26 -0
  3. package/dist/api/messageProtocol/mock.d.ts +12 -0
  4. package/{src/api/messageProtocol/mock.ts → dist/api/messageProtocol/mock.js} +2 -3
  5. package/dist/api/messageProtocol/rest.d.ts +22 -0
  6. package/dist/api/messageProtocol/rest.js +161 -0
  7. package/dist/api/messageProtocol/types.d.ts +61 -0
  8. package/dist/api/messageProtocol/types.js +6 -0
  9. package/dist/assets/generated/wasm/README.md +281 -0
  10. package/dist/assets/generated/wasm/gossip_wasm.d.ts +498 -0
  11. package/dist/assets/generated/wasm/gossip_wasm.js +1399 -0
  12. package/dist/assets/generated/wasm/gossip_wasm_bg.wasm +0 -0
  13. package/dist/assets/generated/wasm/gossip_wasm_bg.wasm.d.ts +68 -0
  14. package/dist/assets/generated/wasm/package.json +15 -0
  15. package/dist/config/protocol.d.ts +36 -0
  16. package/dist/config/protocol.js +77 -0
  17. package/dist/config/sdk.d.ts +82 -0
  18. package/dist/config/sdk.js +55 -0
  19. package/{src/contacts.ts → dist/contacts.d.ts} +10 -94
  20. package/dist/contacts.js +166 -0
  21. package/dist/core/SdkEventEmitter.d.ts +36 -0
  22. package/dist/core/SdkEventEmitter.js +59 -0
  23. package/dist/core/SdkPolling.d.ts +35 -0
  24. package/dist/core/SdkPolling.js +100 -0
  25. package/{src/core/index.ts → dist/core/index.d.ts} +0 -2
  26. package/dist/core/index.js +5 -0
  27. package/dist/crypto/bip39.d.ts +34 -0
  28. package/dist/crypto/bip39.js +62 -0
  29. package/dist/crypto/encryption.d.ts +37 -0
  30. package/dist/crypto/encryption.js +46 -0
  31. package/dist/db.d.ts +190 -0
  32. package/dist/db.js +311 -0
  33. package/dist/gossipSdk.d.ts +274 -0
  34. package/dist/gossipSdk.js +690 -0
  35. package/dist/index.d.ts +73 -0
  36. package/dist/index.js +77 -0
  37. package/dist/services/announcement.d.ts +43 -0
  38. package/dist/services/announcement.js +491 -0
  39. package/dist/services/auth.d.ts +37 -0
  40. package/dist/services/auth.js +76 -0
  41. package/dist/services/discussion.d.ts +63 -0
  42. package/dist/services/discussion.js +297 -0
  43. package/dist/services/message.d.ts +74 -0
  44. package/dist/services/message.js +826 -0
  45. package/dist/services/refresh.d.ts +41 -0
  46. package/dist/services/refresh.js +205 -0
  47. package/{src/sw.ts → dist/sw.d.ts} +1 -8
  48. package/dist/sw.js +10 -0
  49. package/dist/types/events.d.ts +80 -0
  50. package/dist/types/events.js +7 -0
  51. package/dist/types.d.ts +32 -0
  52. package/dist/types.js +7 -0
  53. package/dist/utils/base64.d.ts +10 -0
  54. package/dist/utils/base64.js +30 -0
  55. package/dist/utils/contacts.d.ts +42 -0
  56. package/dist/utils/contacts.js +113 -0
  57. package/dist/utils/discussions.d.ts +24 -0
  58. package/dist/utils/discussions.js +38 -0
  59. package/dist/utils/logs.d.ts +19 -0
  60. package/dist/utils/logs.js +89 -0
  61. package/dist/utils/messageSerialization.d.ts +64 -0
  62. package/dist/utils/messageSerialization.js +184 -0
  63. package/dist/utils/queue.d.ts +50 -0
  64. package/dist/utils/queue.js +110 -0
  65. package/dist/utils/type.d.ts +10 -0
  66. package/dist/utils/type.js +4 -0
  67. package/dist/utils/userId.d.ts +40 -0
  68. package/dist/utils/userId.js +90 -0
  69. package/dist/utils/validation.d.ts +50 -0
  70. package/dist/utils/validation.js +112 -0
  71. package/dist/utils.d.ts +30 -0
  72. package/{src/utils.ts → dist/utils.js} +9 -19
  73. package/dist/wasm/encryption.d.ts +56 -0
  74. package/{src/wasm/encryption.ts → dist/wasm/encryption.js} +22 -51
  75. package/dist/wasm/index.d.ts +10 -0
  76. package/{src/wasm/index.ts → dist/wasm/index.js} +1 -8
  77. package/dist/wasm/loader.d.ts +21 -0
  78. package/dist/wasm/loader.js +103 -0
  79. package/dist/wasm/session.d.ts +85 -0
  80. package/dist/wasm/session.js +226 -0
  81. package/dist/wasm/userKeys.d.ts +17 -0
  82. package/{src/wasm/userKeys.ts → dist/wasm/userKeys.js} +6 -13
  83. package/package.json +5 -1
  84. package/src/api/messageProtocol/index.ts +0 -53
  85. package/src/api/messageProtocol/rest.ts +0 -209
  86. package/src/api/messageProtocol/types.ts +0 -70
  87. package/src/config/protocol.ts +0 -97
  88. package/src/config/sdk.ts +0 -131
  89. package/src/core/SdkEventEmitter.ts +0 -91
  90. package/src/core/SdkPolling.ts +0 -134
  91. package/src/crypto/bip39.ts +0 -84
  92. package/src/crypto/encryption.ts +0 -77
  93. package/src/db.ts +0 -465
  94. package/src/gossipSdk.ts +0 -994
  95. package/src/index.ts +0 -211
  96. package/src/services/announcement.ts +0 -653
  97. package/src/services/auth.ts +0 -95
  98. package/src/services/discussion.ts +0 -380
  99. package/src/services/message.ts +0 -1055
  100. package/src/services/refresh.ts +0 -234
  101. package/src/types/events.ts +0 -108
  102. package/src/types.ts +0 -70
  103. package/src/utils/base64.ts +0 -39
  104. package/src/utils/contacts.ts +0 -161
  105. package/src/utils/discussions.ts +0 -55
  106. package/src/utils/logs.ts +0 -86
  107. package/src/utils/messageSerialization.ts +0 -257
  108. package/src/utils/queue.ts +0 -106
  109. package/src/utils/type.ts +0 -7
  110. package/src/utils/userId.ts +0 -114
  111. package/src/utils/validation.ts +0 -144
  112. package/src/wasm/loader.ts +0 -123
  113. package/src/wasm/session.ts +0 -276
  114. package/test/config/protocol.spec.ts +0 -31
  115. package/test/config/sdk.spec.ts +0 -163
  116. package/test/db/helpers.spec.ts +0 -142
  117. package/test/db/operations.spec.ts +0 -128
  118. package/test/db/states.spec.ts +0 -535
  119. package/test/integration/discussion-flow.spec.ts +0 -422
  120. package/test/integration/messaging-flow.spec.ts +0 -708
  121. package/test/integration/sdk-lifecycle.spec.ts +0 -325
  122. package/test/mocks/index.ts +0 -9
  123. package/test/mocks/mockMessageProtocol.ts +0 -100
  124. package/test/services/auth.spec.ts +0 -311
  125. package/test/services/discussion.spec.ts +0 -279
  126. package/test/services/message-deduplication.spec.ts +0 -299
  127. package/test/services/message-startup.spec.ts +0 -331
  128. package/test/services/message.spec.ts +0 -817
  129. package/test/services/refresh.spec.ts +0 -199
  130. package/test/services/session-status.spec.ts +0 -349
  131. package/test/session/wasm.spec.ts +0 -227
  132. package/test/setup.ts +0 -52
  133. package/test/utils/contacts.spec.ts +0 -156
  134. package/test/utils/discussions.spec.ts +0 -66
  135. package/test/utils/queue.spec.ts +0 -52
  136. package/test/utils/serialization.spec.ts +0 -120
  137. package/test/utils/userId.spec.ts +0 -120
  138. package/test/utils/validation.spec.ts +0 -223
  139. package/test/utils.ts +0 -212
  140. package/tsconfig.json +0 -26
  141. package/tsconfig.tsbuildinfo +0 -1
  142. package/vitest.config.ts +0 -28
@@ -0,0 +1,1399 @@
1
+ let wasm;
2
+
3
+ function addToExternrefTable0(obj) {
4
+ const idx = wasm.__externref_table_alloc();
5
+ wasm.__wbindgen_export_2.set(idx, obj);
6
+ return idx;
7
+ }
8
+
9
+ function handleError(f, args) {
10
+ try {
11
+ return f.apply(this, args);
12
+ } catch (e) {
13
+ const idx = addToExternrefTable0(e);
14
+ wasm.__wbindgen_exn_store(idx);
15
+ }
16
+ }
17
+
18
+ let cachedUint8ArrayMemory0 = null;
19
+
20
+ function getUint8ArrayMemory0() {
21
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
22
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
23
+ }
24
+ return cachedUint8ArrayMemory0;
25
+ }
26
+
27
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
28
+
29
+ cachedTextDecoder.decode();
30
+
31
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
32
+ let numBytesDecoded = 0;
33
+ function decodeText(ptr, len) {
34
+ numBytesDecoded += len;
35
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
36
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
37
+ cachedTextDecoder.decode();
38
+ numBytesDecoded = len;
39
+ }
40
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
41
+ }
42
+
43
+ function getStringFromWasm0(ptr, len) {
44
+ ptr = ptr >>> 0;
45
+ return decodeText(ptr, len);
46
+ }
47
+
48
+ function getArrayU8FromWasm0(ptr, len) {
49
+ ptr = ptr >>> 0;
50
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
51
+ }
52
+
53
+ let WASM_VECTOR_LEN = 0;
54
+
55
+ const cachedTextEncoder = new TextEncoder();
56
+
57
+ if (!('encodeInto' in cachedTextEncoder)) {
58
+ cachedTextEncoder.encodeInto = function (arg, view) {
59
+ const buf = cachedTextEncoder.encode(arg);
60
+ view.set(buf);
61
+ return {
62
+ read: arg.length,
63
+ written: buf.length
64
+ };
65
+ }
66
+ }
67
+
68
+ function passStringToWasm0(arg, malloc, realloc) {
69
+
70
+ if (realloc === undefined) {
71
+ const buf = cachedTextEncoder.encode(arg);
72
+ const ptr = malloc(buf.length, 1) >>> 0;
73
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
74
+ WASM_VECTOR_LEN = buf.length;
75
+ return ptr;
76
+ }
77
+
78
+ let len = arg.length;
79
+ let ptr = malloc(len, 1) >>> 0;
80
+
81
+ const mem = getUint8ArrayMemory0();
82
+
83
+ let offset = 0;
84
+
85
+ for (; offset < len; offset++) {
86
+ const code = arg.charCodeAt(offset);
87
+ if (code > 0x7F) break;
88
+ mem[ptr + offset] = code;
89
+ }
90
+
91
+ if (offset !== len) {
92
+ if (offset !== 0) {
93
+ arg = arg.slice(offset);
94
+ }
95
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
96
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
97
+ const ret = cachedTextEncoder.encodeInto(arg, view);
98
+
99
+ offset += ret.written;
100
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
101
+ }
102
+
103
+ WASM_VECTOR_LEN = offset;
104
+ return ptr;
105
+ }
106
+
107
+ let cachedDataViewMemory0 = null;
108
+
109
+ function getDataViewMemory0() {
110
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
111
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
112
+ }
113
+ return cachedDataViewMemory0;
114
+ }
115
+
116
+ function isLikeNone(x) {
117
+ return x === undefined || x === null;
118
+ }
119
+
120
+ export function start() {
121
+ wasm.start();
122
+ }
123
+
124
+ function takeFromExternrefTable0(idx) {
125
+ const value = wasm.__wbindgen_export_2.get(idx);
126
+ wasm.__externref_table_dealloc(idx);
127
+ return value;
128
+ }
129
+
130
+ function passArray8ToWasm0(arg, malloc) {
131
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
132
+ getUint8ArrayMemory0().set(arg, ptr / 1);
133
+ WASM_VECTOR_LEN = arg.length;
134
+ return ptr;
135
+ }
136
+ /**
137
+ * Generates user keys from a passphrase using password-based key derivation.
138
+ * @param {string} passphrase
139
+ * @returns {UserKeys}
140
+ */
141
+ export function generate_user_keys(passphrase) {
142
+ const ptr0 = passStringToWasm0(passphrase, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
143
+ const len0 = WASM_VECTOR_LEN;
144
+ const ret = wasm.generate_user_keys(ptr0, len0);
145
+ if (ret[2]) {
146
+ throw takeFromExternrefTable0(ret[1]);
147
+ }
148
+ return UserKeys.__wrap(ret[0]);
149
+ }
150
+
151
+ function _assertClass(instance, klass) {
152
+ if (!(instance instanceof klass)) {
153
+ throw new Error(`expected instance of ${klass.name}`);
154
+ }
155
+ }
156
+ /**
157
+ * Encrypts data using AES-256-SIV authenticated encryption.
158
+ *
159
+ * # Parameters
160
+ *
161
+ * - `key`: The encryption key (64 bytes)
162
+ * - `nonce`: The nonce (16 bytes, should be unique per encryption)
163
+ * - `plaintext`: The data to encrypt
164
+ * - `aad`: Additional authenticated data (not encrypted, but authenticated)
165
+ *
166
+ * # Returns
167
+ *
168
+ * The ciphertext with authentication tag appended.
169
+ *
170
+ * # Security Notes
171
+ *
172
+ * - The nonce should be unique for each encryption operation
173
+ * - AES-SIV is nonce-misuse resistant: reusing nonces only leaks if plaintexts are identical
174
+ * - AAD is authenticated but not encrypted; it must be transmitted separately
175
+ * - The same AAD must be provided during decryption
176
+ *
177
+ * # Example
178
+ *
179
+ * ```javascript
180
+ * const key = EncryptionKey.generate();
181
+ * const nonce = Nonce.generate();
182
+ * const plaintext = new TextEncoder().encode("Secret message");
183
+ * const aad = new TextEncoder().encode("context info");
184
+ *
185
+ * const ciphertext = aead_encrypt(key, nonce, plaintext, aad);
186
+ * ```
187
+ * @param {EncryptionKey} key
188
+ * @param {Nonce} nonce
189
+ * @param {Uint8Array} plaintext
190
+ * @param {Uint8Array} aad
191
+ * @returns {Uint8Array}
192
+ */
193
+ export function aead_encrypt(key, nonce, plaintext, aad) {
194
+ _assertClass(key, EncryptionKey);
195
+ _assertClass(nonce, Nonce);
196
+ const ptr0 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
197
+ const len0 = WASM_VECTOR_LEN;
198
+ const ptr1 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
199
+ const len1 = WASM_VECTOR_LEN;
200
+ const ret = wasm.aead_encrypt(key.__wbg_ptr, nonce.__wbg_ptr, ptr0, len0, ptr1, len1);
201
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
202
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
203
+ return v3;
204
+ }
205
+
206
+ /**
207
+ * Decrypts data using AES-256-SIV authenticated encryption.
208
+ *
209
+ * # Parameters
210
+ *
211
+ * - `key`: The encryption key (64 bytes, must match encryption key)
212
+ * - `nonce`: The nonce (16 bytes, must match encryption nonce)
213
+ * - `ciphertext`: The encrypted data with authentication tag
214
+ * - `aad`: Additional authenticated data (must match encryption AAD)
215
+ *
216
+ * # Returns
217
+ *
218
+ * The decrypted plaintext, or `null` if authentication fails.
219
+ *
220
+ * # Security Notes
221
+ *
222
+ * - Returns `null` if:
223
+ * - The ciphertext has been tampered with
224
+ * - The wrong key or nonce is used
225
+ * - The AAD doesn't match
226
+ * - Never ignore a decryption failure; it indicates tampering or corruption
227
+ *
228
+ * # Example
229
+ *
230
+ * ```javascript
231
+ * const plaintext = aead_decrypt(key, nonce, ciphertext, aad);
232
+ * if (plaintext) {
233
+ * console.log("Decrypted:", new TextDecoder().decode(plaintext));
234
+ * } else {
235
+ * console.error("Decryption failed - data may be corrupted or tampered");
236
+ * }
237
+ * ```
238
+ * @param {EncryptionKey} key
239
+ * @param {Nonce} nonce
240
+ * @param {Uint8Array} ciphertext
241
+ * @param {Uint8Array} aad
242
+ * @returns {Uint8Array | undefined}
243
+ */
244
+ export function aead_decrypt(key, nonce, ciphertext, aad) {
245
+ _assertClass(key, EncryptionKey);
246
+ _assertClass(nonce, Nonce);
247
+ const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
248
+ const len0 = WASM_VECTOR_LEN;
249
+ const ptr1 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
250
+ const len1 = WASM_VECTOR_LEN;
251
+ const ret = wasm.aead_decrypt(key.__wbg_ptr, nonce.__wbg_ptr, ptr0, len0, ptr1, len1);
252
+ let v3;
253
+ if (ret[0] !== 0) {
254
+ v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
255
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
256
+ }
257
+ return v3;
258
+ }
259
+
260
+ /**
261
+ * Session status indicating the state of a peer session.
262
+ * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6}
263
+ */
264
+ export const SessionStatus = Object.freeze({
265
+ Active: 0, "0": "Active",
266
+ UnknownPeer: 1, "1": "UnknownPeer",
267
+ NoSession: 2, "2": "NoSession",
268
+ PeerRequested: 3, "3": "PeerRequested",
269
+ SelfRequested: 4, "4": "SelfRequested",
270
+ Killed: 5, "5": "Killed",
271
+ Saturated: 6, "6": "Saturated",
272
+ });
273
+
274
+ const AnnouncementResultFinalization = (typeof FinalizationRegistry === 'undefined')
275
+ ? { register: () => {}, unregister: () => {} }
276
+ : new FinalizationRegistry(ptr => wasm.__wbg_announcementresult_free(ptr >>> 0, 1));
277
+ /**
278
+ * Result from feeding an incoming announcement.
279
+ */
280
+ export class AnnouncementResult {
281
+
282
+ static __wrap(ptr) {
283
+ ptr = ptr >>> 0;
284
+ const obj = Object.create(AnnouncementResult.prototype);
285
+ obj.__wbg_ptr = ptr;
286
+ AnnouncementResultFinalization.register(obj, obj.__wbg_ptr, obj);
287
+ return obj;
288
+ }
289
+
290
+ __destroy_into_raw() {
291
+ const ptr = this.__wbg_ptr;
292
+ this.__wbg_ptr = 0;
293
+ AnnouncementResultFinalization.unregister(this);
294
+ return ptr;
295
+ }
296
+
297
+ free() {
298
+ const ptr = this.__destroy_into_raw();
299
+ wasm.__wbg_announcementresult_free(ptr, 0);
300
+ }
301
+ /**
302
+ * Gets the announcer's public keys.
303
+ * @returns {UserPublicKeys}
304
+ */
305
+ get announcer_public_keys() {
306
+ const ret = wasm.announcementresult_announcer_public_keys(this.__wbg_ptr);
307
+ return UserPublicKeys.__wrap(ret);
308
+ }
309
+ /**
310
+ * Gets the announcement timestamp in milliseconds since Unix epoch.
311
+ * @returns {number}
312
+ */
313
+ get timestamp() {
314
+ const ret = wasm.announcementresult_timestamp(this.__wbg_ptr);
315
+ return ret;
316
+ }
317
+ /**
318
+ * Gets the user data embedded in the announcement.
319
+ * @returns {Uint8Array}
320
+ */
321
+ get user_data() {
322
+ const ret = wasm.announcementresult_user_data(this.__wbg_ptr);
323
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
324
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
325
+ return v1;
326
+ }
327
+ }
328
+ if (Symbol.dispose) AnnouncementResult.prototype[Symbol.dispose] = AnnouncementResult.prototype.free;
329
+
330
+ const EncryptionKeyFinalization = (typeof FinalizationRegistry === 'undefined')
331
+ ? { register: () => {}, unregister: () => {} }
332
+ : new FinalizationRegistry(ptr => wasm.__wbg_encryptionkey_free(ptr >>> 0, 1));
333
+ /**
334
+ * Encryption key for AEAD operations (AES-256-SIV).
335
+ *
336
+ * AES-256-SIV uses a 64-byte (512-bit) key: two 256-bit keys for encryption and MAC.
337
+ */
338
+ export class EncryptionKey {
339
+
340
+ static __wrap(ptr) {
341
+ ptr = ptr >>> 0;
342
+ const obj = Object.create(EncryptionKey.prototype);
343
+ obj.__wbg_ptr = ptr;
344
+ EncryptionKeyFinalization.register(obj, obj.__wbg_ptr, obj);
345
+ return obj;
346
+ }
347
+
348
+ __destroy_into_raw() {
349
+ const ptr = this.__wbg_ptr;
350
+ this.__wbg_ptr = 0;
351
+ EncryptionKeyFinalization.unregister(this);
352
+ return ptr;
353
+ }
354
+
355
+ free() {
356
+ const ptr = this.__destroy_into_raw();
357
+ wasm.__wbg_encryptionkey_free(ptr, 0);
358
+ }
359
+ /**
360
+ * Generates a new random encryption key (64 bytes).
361
+ * @returns {EncryptionKey}
362
+ */
363
+ static generate() {
364
+ const ret = wasm.encryptionkey_generate();
365
+ return EncryptionKey.__wrap(ret);
366
+ }
367
+ /**
368
+ * Generates a deterministic encryption key (64 bytes) from a seed and salt.
369
+ *
370
+ * Uses Argon2id via `crypto_password_kdf` to derive a 64-byte key suitable for
371
+ * AES-256-SIV (which requires 64 bytes: 2×256-bit keys).
372
+ *
373
+ * - `seed`: application-provided seed string (treat like a password)
374
+ * - `salt`: unique, random salt (minimum 8 bytes, recommended 16+ bytes)
375
+ * @param {string} seed
376
+ * @param {Uint8Array} salt
377
+ * @returns {EncryptionKey}
378
+ */
379
+ static from_seed(seed, salt) {
380
+ const ptr0 = passStringToWasm0(seed, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
381
+ const len0 = WASM_VECTOR_LEN;
382
+ const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
383
+ const len1 = WASM_VECTOR_LEN;
384
+ const ret = wasm.encryptionkey_from_seed(ptr0, len0, ptr1, len1);
385
+ if (ret[2]) {
386
+ throw takeFromExternrefTable0(ret[1]);
387
+ }
388
+ return EncryptionKey.__wrap(ret[0]);
389
+ }
390
+ /**
391
+ * Creates an encryption key from raw bytes (must be 64 bytes).
392
+ * @param {Uint8Array} bytes
393
+ * @returns {EncryptionKey}
394
+ */
395
+ static from_bytes(bytes) {
396
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
397
+ const len0 = WASM_VECTOR_LEN;
398
+ const ret = wasm.encryptionkey_from_bytes(ptr0, len0);
399
+ if (ret[2]) {
400
+ throw takeFromExternrefTable0(ret[1]);
401
+ }
402
+ return EncryptionKey.__wrap(ret[0]);
403
+ }
404
+ /**
405
+ * Gets the raw bytes of the encryption key.
406
+ * @returns {Uint8Array}
407
+ */
408
+ to_bytes() {
409
+ const ret = wasm.encryptionkey_to_bytes(this.__wbg_ptr);
410
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
411
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
412
+ return v1;
413
+ }
414
+ }
415
+ if (Symbol.dispose) EncryptionKey.prototype[Symbol.dispose] = EncryptionKey.prototype.free;
416
+
417
+ const NonceFinalization = (typeof FinalizationRegistry === 'undefined')
418
+ ? { register: () => {}, unregister: () => {} }
419
+ : new FinalizationRegistry(ptr => wasm.__wbg_nonce_free(ptr >>> 0, 1));
420
+ /**
421
+ * Nonce for AEAD operations (AES-256-SIV).
422
+ *
423
+ * AES-256-SIV uses a 16-byte (128-bit) nonce. The nonce should be unique
424
+ * per encryption for maximum security, though SIV mode is nonce-misuse resistant.
425
+ */
426
+ export class Nonce {
427
+
428
+ static __wrap(ptr) {
429
+ ptr = ptr >>> 0;
430
+ const obj = Object.create(Nonce.prototype);
431
+ obj.__wbg_ptr = ptr;
432
+ NonceFinalization.register(obj, obj.__wbg_ptr, obj);
433
+ return obj;
434
+ }
435
+
436
+ __destroy_into_raw() {
437
+ const ptr = this.__wbg_ptr;
438
+ this.__wbg_ptr = 0;
439
+ NonceFinalization.unregister(this);
440
+ return ptr;
441
+ }
442
+
443
+ free() {
444
+ const ptr = this.__destroy_into_raw();
445
+ wasm.__wbg_nonce_free(ptr, 0);
446
+ }
447
+ /**
448
+ * Generates a new random nonce (16 bytes).
449
+ * @returns {Nonce}
450
+ */
451
+ static generate() {
452
+ const ret = wasm.nonce_generate();
453
+ return Nonce.__wrap(ret);
454
+ }
455
+ /**
456
+ * Creates a nonce from raw bytes (must be 16 bytes).
457
+ * @param {Uint8Array} bytes
458
+ * @returns {Nonce}
459
+ */
460
+ static from_bytes(bytes) {
461
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
462
+ const len0 = WASM_VECTOR_LEN;
463
+ const ret = wasm.nonce_from_bytes(ptr0, len0);
464
+ if (ret[2]) {
465
+ throw takeFromExternrefTable0(ret[1]);
466
+ }
467
+ return Nonce.__wrap(ret[0]);
468
+ }
469
+ /**
470
+ * Gets the raw bytes of the nonce.
471
+ * @returns {Uint8Array}
472
+ */
473
+ to_bytes() {
474
+ const ret = wasm.nonce_to_bytes(this.__wbg_ptr);
475
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
476
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
477
+ return v1;
478
+ }
479
+ }
480
+ if (Symbol.dispose) Nonce.prototype[Symbol.dispose] = Nonce.prototype.free;
481
+
482
+ const ReceiveMessageOutputFinalization = (typeof FinalizationRegistry === 'undefined')
483
+ ? { register: () => {}, unregister: () => {} }
484
+ : new FinalizationRegistry(ptr => wasm.__wbg_receivemessageoutput_free(ptr >>> 0, 1));
485
+ /**
486
+ * Output from receiving a message.
487
+ */
488
+ export class ReceiveMessageOutput {
489
+
490
+ static __wrap(ptr) {
491
+ ptr = ptr >>> 0;
492
+ const obj = Object.create(ReceiveMessageOutput.prototype);
493
+ obj.__wbg_ptr = ptr;
494
+ ReceiveMessageOutputFinalization.register(obj, obj.__wbg_ptr, obj);
495
+ return obj;
496
+ }
497
+
498
+ __destroy_into_raw() {
499
+ const ptr = this.__wbg_ptr;
500
+ this.__wbg_ptr = 0;
501
+ ReceiveMessageOutputFinalization.unregister(this);
502
+ return ptr;
503
+ }
504
+
505
+ free() {
506
+ const ptr = this.__destroy_into_raw();
507
+ wasm.__wbg_receivemessageoutput_free(ptr, 0);
508
+ }
509
+ /**
510
+ * Gets the received message contents.
511
+ * @returns {Uint8Array}
512
+ */
513
+ get message() {
514
+ const ret = wasm.receivemessageoutput_message(this.__wbg_ptr);
515
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
516
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
517
+ return v1;
518
+ }
519
+ /**
520
+ * Gets the message timestamp (milliseconds since Unix epoch).
521
+ * @returns {number}
522
+ */
523
+ get timestamp() {
524
+ const ret = wasm.receivemessageoutput_timestamp(this.__wbg_ptr);
525
+ return ret;
526
+ }
527
+ /**
528
+ * Gets the list of newly acknowledged seekers.
529
+ * @returns {Array<any>}
530
+ */
531
+ get acknowledged_seekers() {
532
+ const ret = wasm.receivemessageoutput_acknowledged_seekers(this.__wbg_ptr);
533
+ return ret;
534
+ }
535
+ /**
536
+ * Gets the sender's user id (32 bytes).
537
+ * @returns {Uint8Array}
538
+ */
539
+ get user_id() {
540
+ const ret = wasm.receivemessageoutput_user_id(this.__wbg_ptr);
541
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
542
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
543
+ return v1;
544
+ }
545
+ }
546
+ if (Symbol.dispose) ReceiveMessageOutput.prototype[Symbol.dispose] = ReceiveMessageOutput.prototype.free;
547
+
548
+ const SendMessageOutputFinalization = (typeof FinalizationRegistry === 'undefined')
549
+ ? { register: () => {}, unregister: () => {} }
550
+ : new FinalizationRegistry(ptr => wasm.__wbg_sendmessageoutput_free(ptr >>> 0, 1));
551
+ /**
552
+ * Output from sending a message.
553
+ */
554
+ export class SendMessageOutput {
555
+
556
+ static __wrap(ptr) {
557
+ ptr = ptr >>> 0;
558
+ const obj = Object.create(SendMessageOutput.prototype);
559
+ obj.__wbg_ptr = ptr;
560
+ SendMessageOutputFinalization.register(obj, obj.__wbg_ptr, obj);
561
+ return obj;
562
+ }
563
+
564
+ __destroy_into_raw() {
565
+ const ptr = this.__wbg_ptr;
566
+ this.__wbg_ptr = 0;
567
+ SendMessageOutputFinalization.unregister(this);
568
+ return ptr;
569
+ }
570
+
571
+ free() {
572
+ const ptr = this.__destroy_into_raw();
573
+ wasm.__wbg_sendmessageoutput_free(ptr, 0);
574
+ }
575
+ /**
576
+ * Gets the seeker (identifier for message board lookup).
577
+ * @returns {Uint8Array}
578
+ */
579
+ get seeker() {
580
+ const ret = wasm.sendmessageoutput_seeker(this.__wbg_ptr);
581
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
582
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
583
+ return v1;
584
+ }
585
+ /**
586
+ * Gets the encrypted message data.
587
+ * @returns {Uint8Array}
588
+ */
589
+ get data() {
590
+ const ret = wasm.sendmessageoutput_data(this.__wbg_ptr);
591
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
592
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
593
+ return v1;
594
+ }
595
+ }
596
+ if (Symbol.dispose) SendMessageOutput.prototype[Symbol.dispose] = SendMessageOutput.prototype.free;
597
+
598
+ const SessionConfigFinalization = (typeof FinalizationRegistry === 'undefined')
599
+ ? { register: () => {}, unregister: () => {} }
600
+ : new FinalizationRegistry(ptr => wasm.__wbg_sessionconfig_free(ptr >>> 0, 1));
601
+ /**
602
+ * Session manager configuration for controlling session behavior.
603
+ */
604
+ export class SessionConfig {
605
+
606
+ static __wrap(ptr) {
607
+ ptr = ptr >>> 0;
608
+ const obj = Object.create(SessionConfig.prototype);
609
+ obj.__wbg_ptr = ptr;
610
+ SessionConfigFinalization.register(obj, obj.__wbg_ptr, obj);
611
+ return obj;
612
+ }
613
+
614
+ __destroy_into_raw() {
615
+ const ptr = this.__wbg_ptr;
616
+ this.__wbg_ptr = 0;
617
+ SessionConfigFinalization.unregister(this);
618
+ return ptr;
619
+ }
620
+
621
+ free() {
622
+ const ptr = this.__destroy_into_raw();
623
+ wasm.__wbg_sessionconfig_free(ptr, 0);
624
+ }
625
+ /**
626
+ * Creates a new session configuration with the given parameters.
627
+ * @param {number} max_incoming_announcement_age_millis
628
+ * @param {number} max_incoming_announcement_future_millis
629
+ * @param {number} max_incoming_message_age_millis
630
+ * @param {number} max_incoming_message_future_millis
631
+ * @param {number} max_session_inactivity_millis
632
+ * @param {number} keep_alive_interval_millis
633
+ * @param {bigint} max_session_lag_length
634
+ */
635
+ constructor(max_incoming_announcement_age_millis, max_incoming_announcement_future_millis, max_incoming_message_age_millis, max_incoming_message_future_millis, max_session_inactivity_millis, keep_alive_interval_millis, max_session_lag_length) {
636
+ const ret = wasm.sessionconfig_new(max_incoming_announcement_age_millis, max_incoming_announcement_future_millis, max_incoming_message_age_millis, max_incoming_message_future_millis, max_session_inactivity_millis, keep_alive_interval_millis, max_session_lag_length);
637
+ this.__wbg_ptr = ret >>> 0;
638
+ SessionConfigFinalization.register(this, this.__wbg_ptr, this);
639
+ return this;
640
+ }
641
+ /**
642
+ * Creates a default configuration with sensible defaults:
643
+ * - Announcement age: 1 week
644
+ * - Announcement future: 1 minute
645
+ * - Message age: 1 week
646
+ * - Message future: 1 minute
647
+ * - Session inactivity: 1 week
648
+ * - Keep-alive interval: 1 day
649
+ * - Max lag: 10000 messages
650
+ * @returns {SessionConfig}
651
+ */
652
+ static new_default() {
653
+ const ret = wasm.sessionconfig_new_default();
654
+ return SessionConfig.__wrap(ret);
655
+ }
656
+ }
657
+ if (Symbol.dispose) SessionConfig.prototype[Symbol.dispose] = SessionConfig.prototype.free;
658
+
659
+ const SessionManagerWrapperFinalization = (typeof FinalizationRegistry === 'undefined')
660
+ ? { register: () => {}, unregister: () => {} }
661
+ : new FinalizationRegistry(ptr => wasm.__wbg_sessionmanagerwrapper_free(ptr >>> 0, 1));
662
+ /**
663
+ * Session manager wrapper for WebAssembly.
664
+ */
665
+ export class SessionManagerWrapper {
666
+
667
+ static __wrap(ptr) {
668
+ ptr = ptr >>> 0;
669
+ const obj = Object.create(SessionManagerWrapper.prototype);
670
+ obj.__wbg_ptr = ptr;
671
+ SessionManagerWrapperFinalization.register(obj, obj.__wbg_ptr, obj);
672
+ return obj;
673
+ }
674
+
675
+ __destroy_into_raw() {
676
+ const ptr = this.__wbg_ptr;
677
+ this.__wbg_ptr = 0;
678
+ SessionManagerWrapperFinalization.unregister(this);
679
+ return ptr;
680
+ }
681
+
682
+ free() {
683
+ const ptr = this.__destroy_into_raw();
684
+ wasm.__wbg_sessionmanagerwrapper_free(ptr, 0);
685
+ }
686
+ /**
687
+ * Creates a new session manager with the given configuration.
688
+ * @param {SessionConfig} config
689
+ */
690
+ constructor(config) {
691
+ _assertClass(config, SessionConfig);
692
+ var ptr0 = config.__destroy_into_raw();
693
+ const ret = wasm.sessionmanagerwrapper_new(ptr0);
694
+ this.__wbg_ptr = ret >>> 0;
695
+ SessionManagerWrapperFinalization.register(this, this.__wbg_ptr, this);
696
+ return this;
697
+ }
698
+ /**
699
+ * Deserializes a session manager from an encrypted blob.
700
+ * @param {Uint8Array} encrypted_blob
701
+ * @param {EncryptionKey} key
702
+ * @returns {SessionManagerWrapper}
703
+ */
704
+ static from_encrypted_blob(encrypted_blob, key) {
705
+ const ptr0 = passArray8ToWasm0(encrypted_blob, wasm.__wbindgen_malloc);
706
+ const len0 = WASM_VECTOR_LEN;
707
+ _assertClass(key, EncryptionKey);
708
+ const ret = wasm.sessionmanagerwrapper_from_encrypted_blob(ptr0, len0, key.__wbg_ptr);
709
+ if (ret[2]) {
710
+ throw takeFromExternrefTable0(ret[1]);
711
+ }
712
+ return SessionManagerWrapper.__wrap(ret[0]);
713
+ }
714
+ /**
715
+ * Serializes and encrypts the session manager into a blob.
716
+ * @param {EncryptionKey} key
717
+ * @returns {Uint8Array}
718
+ */
719
+ to_encrypted_blob(key) {
720
+ _assertClass(key, EncryptionKey);
721
+ const ret = wasm.sessionmanagerwrapper_to_encrypted_blob(this.__wbg_ptr, key.__wbg_ptr);
722
+ if (ret[3]) {
723
+ throw takeFromExternrefTable0(ret[2]);
724
+ }
725
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
726
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
727
+ return v1;
728
+ }
729
+ /**
730
+ * Establishes an outgoing session with a peer.
731
+ *
732
+ * # Parameters
733
+ *
734
+ * - `peer_pk`: The peer's public keys
735
+ * - `our_pk`: Our public keys
736
+ * - `our_sk`: Our secret keys
737
+ * - `user_data`: Arbitrary user data to include in the announcement (can be empty)
738
+ *
739
+ * # Security Warning
740
+ *
741
+ * **The user_data in announcements has reduced security compared to regular messages:**
742
+ * - ✅ **Plausible deniability preserved**: The user_data is not cryptographically signed,
743
+ * so you can deny having sent specific user_data content (though you cannot deny the
744
+ * announcement itself).
745
+ * - ❌ **No post-compromise secrecy**: If your long-term keys are compromised in the
746
+ * future, past announcements (including their user_data) can be decrypted.
747
+ *
748
+ * **Recommendation**: Avoid including highly sensitive information in user_data. Use it for
749
+ * metadata like protocol version, public display names, or capability flags. Send truly
750
+ * sensitive data through regular messages after the session is established.
751
+ *
752
+ * # Returns
753
+ *
754
+ * The announcement bytes to publish to the blockchain.
755
+ * @param {UserPublicKeys} peer_pk
756
+ * @param {UserPublicKeys} our_pk
757
+ * @param {UserSecretKeys} our_sk
758
+ * @param {Uint8Array} user_data
759
+ * @returns {Uint8Array}
760
+ */
761
+ establish_outgoing_session(peer_pk, our_pk, our_sk, user_data) {
762
+ _assertClass(peer_pk, UserPublicKeys);
763
+ _assertClass(our_pk, UserPublicKeys);
764
+ _assertClass(our_sk, UserSecretKeys);
765
+ const ptr0 = passArray8ToWasm0(user_data, wasm.__wbindgen_malloc);
766
+ const len0 = WASM_VECTOR_LEN;
767
+ const ret = wasm.sessionmanagerwrapper_establish_outgoing_session(this.__wbg_ptr, peer_pk.__wbg_ptr, our_pk.__wbg_ptr, our_sk.__wbg_ptr, ptr0, len0);
768
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
769
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
770
+ return v2;
771
+ }
772
+ /**
773
+ * Feeds an incoming announcement from the blockchain.
774
+ *
775
+ * # Parameters
776
+ *
777
+ * - `announcement_bytes`: The raw announcement bytes received from the blockchain
778
+ * - `our_pk`: Our public keys
779
+ * - `our_sk`: Our secret keys
780
+ *
781
+ * # Returns
782
+ *
783
+ * If the announcement is valid, returns an `AnnouncementResult` containing:
784
+ * - The announcer's public keys
785
+ * - The timestamp when the announcement was created (milliseconds since Unix epoch)
786
+ * - The user data embedded in the announcement
787
+ *
788
+ * Returns `None` if the announcement is invalid or too old.
789
+ *
790
+ * # Security Warning
791
+ *
792
+ * **The user_data in announcements has reduced security compared to regular messages:**
793
+ * - ✅ **Plausible deniability preserved**: The user_data is not cryptographically signed,
794
+ * so the sender can deny having sent specific user_data content (though they cannot deny
795
+ * the announcement itself).
796
+ * - ❌ **No post-compromise secrecy**: If the sender's long-term keys are compromised
797
+ * in the future, all past announcements (including their user_data) can be decrypted.
798
+ *
799
+ * **Recommendation**: Treat user_data as having limited confidentiality. Use it for
800
+ * metadata that is not highly sensitive. Send truly sensitive information through regular
801
+ * messages after the session is established.
802
+ * @param {Uint8Array} announcement_bytes
803
+ * @param {UserPublicKeys} our_pk
804
+ * @param {UserSecretKeys} our_sk
805
+ * @returns {AnnouncementResult | undefined}
806
+ */
807
+ feed_incoming_announcement(announcement_bytes, our_pk, our_sk) {
808
+ const ptr0 = passArray8ToWasm0(announcement_bytes, wasm.__wbindgen_malloc);
809
+ const len0 = WASM_VECTOR_LEN;
810
+ _assertClass(our_pk, UserPublicKeys);
811
+ _assertClass(our_sk, UserSecretKeys);
812
+ const ret = wasm.sessionmanagerwrapper_feed_incoming_announcement(this.__wbg_ptr, ptr0, len0, our_pk.__wbg_ptr, our_sk.__wbg_ptr);
813
+ return ret === 0 ? undefined : AnnouncementResult.__wrap(ret);
814
+ }
815
+ /**
816
+ * Gets the list of message board seekers to monitor.
817
+ * @returns {Array<any>}
818
+ */
819
+ get_message_board_read_keys() {
820
+ const ret = wasm.sessionmanagerwrapper_get_message_board_read_keys(this.__wbg_ptr);
821
+ return ret;
822
+ }
823
+ /**
824
+ * Sends a message to a peer.
825
+ * @param {Uint8Array} peer_id
826
+ * @param {Uint8Array} message_contents
827
+ * @returns {SendMessageOutput | undefined}
828
+ */
829
+ send_message(peer_id, message_contents) {
830
+ const ptr0 = passArray8ToWasm0(peer_id, wasm.__wbindgen_malloc);
831
+ const len0 = WASM_VECTOR_LEN;
832
+ const ptr1 = passArray8ToWasm0(message_contents, wasm.__wbindgen_malloc);
833
+ const len1 = WASM_VECTOR_LEN;
834
+ const ret = wasm.sessionmanagerwrapper_send_message(this.__wbg_ptr, ptr0, len0, ptr1, len1);
835
+ if (ret[2]) {
836
+ throw takeFromExternrefTable0(ret[1]);
837
+ }
838
+ return ret[0] === 0 ? undefined : SendMessageOutput.__wrap(ret[0]);
839
+ }
840
+ /**
841
+ * Processes an incoming message from the message board.
842
+ * @param {Uint8Array} seeker
843
+ * @param {Uint8Array} ciphertext
844
+ * @param {UserSecretKeys} our_sk
845
+ * @returns {ReceiveMessageOutput | undefined}
846
+ */
847
+ feed_incoming_message_board_read(seeker, ciphertext, our_sk) {
848
+ const ptr0 = passArray8ToWasm0(seeker, wasm.__wbindgen_malloc);
849
+ const len0 = WASM_VECTOR_LEN;
850
+ const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
851
+ const len1 = WASM_VECTOR_LEN;
852
+ _assertClass(our_sk, UserSecretKeys);
853
+ const ret = wasm.sessionmanagerwrapper_feed_incoming_message_board_read(this.__wbg_ptr, ptr0, len0, ptr1, len1, our_sk.__wbg_ptr);
854
+ return ret === 0 ? undefined : ReceiveMessageOutput.__wrap(ret);
855
+ }
856
+ /**
857
+ * Gets the list of all peer IDs.
858
+ * @returns {Array<any>}
859
+ */
860
+ peer_list() {
861
+ const ret = wasm.sessionmanagerwrapper_peer_list(this.__wbg_ptr);
862
+ return ret;
863
+ }
864
+ /**
865
+ * Gets the session status for a peer.
866
+ * @param {Uint8Array} peer_id
867
+ * @returns {SessionStatus}
868
+ */
869
+ peer_session_status(peer_id) {
870
+ const ptr0 = passArray8ToWasm0(peer_id, wasm.__wbindgen_malloc);
871
+ const len0 = WASM_VECTOR_LEN;
872
+ const ret = wasm.sessionmanagerwrapper_peer_session_status(this.__wbg_ptr, ptr0, len0);
873
+ if (ret[2]) {
874
+ throw takeFromExternrefTable0(ret[1]);
875
+ }
876
+ return ret[0];
877
+ }
878
+ /**
879
+ * Discards a peer and all associated session state.
880
+ * @param {Uint8Array} peer_id
881
+ */
882
+ peer_discard(peer_id) {
883
+ const ptr0 = passArray8ToWasm0(peer_id, wasm.__wbindgen_malloc);
884
+ const len0 = WASM_VECTOR_LEN;
885
+ const ret = wasm.sessionmanagerwrapper_peer_discard(this.__wbg_ptr, ptr0, len0);
886
+ if (ret[1]) {
887
+ throw takeFromExternrefTable0(ret[0]);
888
+ }
889
+ }
890
+ /**
891
+ * Refreshes sessions and returns peer IDs that need keep-alive messages.
892
+ * @returns {Array<any>}
893
+ */
894
+ refresh() {
895
+ const ret = wasm.sessionmanagerwrapper_refresh(this.__wbg_ptr);
896
+ return ret;
897
+ }
898
+ }
899
+ if (Symbol.dispose) SessionManagerWrapper.prototype[Symbol.dispose] = SessionManagerWrapper.prototype.free;
900
+
901
+ const UserKeysFinalization = (typeof FinalizationRegistry === 'undefined')
902
+ ? { register: () => {}, unregister: () => {} }
903
+ : new FinalizationRegistry(ptr => wasm.__wbg_userkeys_free(ptr >>> 0, 1));
904
+ /**
905
+ * User keypair containing both public and secret keys.
906
+ */
907
+ export class UserKeys {
908
+
909
+ static __wrap(ptr) {
910
+ ptr = ptr >>> 0;
911
+ const obj = Object.create(UserKeys.prototype);
912
+ obj.__wbg_ptr = ptr;
913
+ UserKeysFinalization.register(obj, obj.__wbg_ptr, obj);
914
+ return obj;
915
+ }
916
+
917
+ __destroy_into_raw() {
918
+ const ptr = this.__wbg_ptr;
919
+ this.__wbg_ptr = 0;
920
+ UserKeysFinalization.unregister(this);
921
+ return ptr;
922
+ }
923
+
924
+ free() {
925
+ const ptr = this.__destroy_into_raw();
926
+ wasm.__wbg_userkeys_free(ptr, 0);
927
+ }
928
+ /**
929
+ * Gets the public keys.
930
+ * @returns {UserPublicKeys}
931
+ */
932
+ public_keys() {
933
+ const ret = wasm.userkeys_public_keys(this.__wbg_ptr);
934
+ if (ret[2]) {
935
+ throw takeFromExternrefTable0(ret[1]);
936
+ }
937
+ return UserPublicKeys.__wrap(ret[0]);
938
+ }
939
+ /**
940
+ * Gets the secret keys.
941
+ * @returns {UserSecretKeys}
942
+ */
943
+ secret_keys() {
944
+ const ret = wasm.userkeys_secret_keys(this.__wbg_ptr);
945
+ if (ret[2]) {
946
+ throw takeFromExternrefTable0(ret[1]);
947
+ }
948
+ return UserSecretKeys.__wrap(ret[0]);
949
+ }
950
+ }
951
+ if (Symbol.dispose) UserKeys.prototype[Symbol.dispose] = UserKeys.prototype.free;
952
+
953
+ const UserPublicKeysFinalization = (typeof FinalizationRegistry === 'undefined')
954
+ ? { register: () => {}, unregister: () => {} }
955
+ : new FinalizationRegistry(ptr => wasm.__wbg_userpublickeys_free(ptr >>> 0, 1));
956
+ /**
957
+ * User public keys for authentication and encryption.
958
+ */
959
+ export class UserPublicKeys {
960
+
961
+ static __wrap(ptr) {
962
+ ptr = ptr >>> 0;
963
+ const obj = Object.create(UserPublicKeys.prototype);
964
+ obj.__wbg_ptr = ptr;
965
+ UserPublicKeysFinalization.register(obj, obj.__wbg_ptr, obj);
966
+ return obj;
967
+ }
968
+
969
+ __destroy_into_raw() {
970
+ const ptr = this.__wbg_ptr;
971
+ this.__wbg_ptr = 0;
972
+ UserPublicKeysFinalization.unregister(this);
973
+ return ptr;
974
+ }
975
+
976
+ free() {
977
+ const ptr = this.__destroy_into_raw();
978
+ wasm.__wbg_userpublickeys_free(ptr, 0);
979
+ }
980
+ /**
981
+ * Derives a unique user ID from the public keys.
982
+ * @returns {Uint8Array}
983
+ */
984
+ derive_id() {
985
+ const ret = wasm.userpublickeys_derive_id(this.__wbg_ptr);
986
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
987
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
988
+ return v1;
989
+ }
990
+ /**
991
+ * Gets the DSA verification key bytes.
992
+ * @returns {Uint8Array}
993
+ */
994
+ get dsa_verification_key() {
995
+ const ret = wasm.userpublickeys_dsa_verification_key(this.__wbg_ptr);
996
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
997
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
998
+ return v1;
999
+ }
1000
+ /**
1001
+ * Gets the KEM public key bytes.
1002
+ * @returns {Uint8Array}
1003
+ */
1004
+ get kem_public_key() {
1005
+ const ret = wasm.userpublickeys_kem_public_key(this.__wbg_ptr);
1006
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1007
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1008
+ return v1;
1009
+ }
1010
+ /**
1011
+ * Gets the Massa public key bytes.
1012
+ * @returns {Uint8Array}
1013
+ */
1014
+ get massa_public_key() {
1015
+ const ret = wasm.userpublickeys_massa_public_key(this.__wbg_ptr);
1016
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1017
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1018
+ return v1;
1019
+ }
1020
+ /**
1021
+ * Serializes the public keys to bytes.
1022
+ * @returns {Uint8Array}
1023
+ */
1024
+ to_bytes() {
1025
+ const ret = wasm.userpublickeys_to_bytes(this.__wbg_ptr);
1026
+ if (ret[3]) {
1027
+ throw takeFromExternrefTable0(ret[2]);
1028
+ }
1029
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1030
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1031
+ return v1;
1032
+ }
1033
+ /**
1034
+ * Deserializes public keys from bytes.
1035
+ * @param {Uint8Array} bytes
1036
+ * @returns {UserPublicKeys}
1037
+ */
1038
+ static from_bytes(bytes) {
1039
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
1040
+ const len0 = WASM_VECTOR_LEN;
1041
+ const ret = wasm.userpublickeys_from_bytes(ptr0, len0);
1042
+ if (ret[2]) {
1043
+ throw takeFromExternrefTable0(ret[1]);
1044
+ }
1045
+ return UserPublicKeys.__wrap(ret[0]);
1046
+ }
1047
+ }
1048
+ if (Symbol.dispose) UserPublicKeys.prototype[Symbol.dispose] = UserPublicKeys.prototype.free;
1049
+
1050
+ const UserSecretKeysFinalization = (typeof FinalizationRegistry === 'undefined')
1051
+ ? { register: () => {}, unregister: () => {} }
1052
+ : new FinalizationRegistry(ptr => wasm.__wbg_usersecretkeys_free(ptr >>> 0, 1));
1053
+ /**
1054
+ * User secret keys for signing and decryption.
1055
+ */
1056
+ export class UserSecretKeys {
1057
+
1058
+ static __wrap(ptr) {
1059
+ ptr = ptr >>> 0;
1060
+ const obj = Object.create(UserSecretKeys.prototype);
1061
+ obj.__wbg_ptr = ptr;
1062
+ UserSecretKeysFinalization.register(obj, obj.__wbg_ptr, obj);
1063
+ return obj;
1064
+ }
1065
+
1066
+ __destroy_into_raw() {
1067
+ const ptr = this.__wbg_ptr;
1068
+ this.__wbg_ptr = 0;
1069
+ UserSecretKeysFinalization.unregister(this);
1070
+ return ptr;
1071
+ }
1072
+
1073
+ free() {
1074
+ const ptr = this.__destroy_into_raw();
1075
+ wasm.__wbg_usersecretkeys_free(ptr, 0);
1076
+ }
1077
+ /**
1078
+ * Serializes the secret keys to bytes for secure storage.
1079
+ * @returns {Uint8Array}
1080
+ */
1081
+ to_bytes() {
1082
+ const ret = wasm.usersecretkeys_to_bytes(this.__wbg_ptr);
1083
+ if (ret[3]) {
1084
+ throw takeFromExternrefTable0(ret[2]);
1085
+ }
1086
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1087
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1088
+ return v1;
1089
+ }
1090
+ /**
1091
+ * Deserializes secret keys from bytes.
1092
+ * @param {Uint8Array} bytes
1093
+ * @returns {UserSecretKeys}
1094
+ */
1095
+ static from_bytes(bytes) {
1096
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
1097
+ const len0 = WASM_VECTOR_LEN;
1098
+ const ret = wasm.usersecretkeys_from_bytes(ptr0, len0);
1099
+ if (ret[2]) {
1100
+ throw takeFromExternrefTable0(ret[1]);
1101
+ }
1102
+ return UserSecretKeys.__wrap(ret[0]);
1103
+ }
1104
+ /**
1105
+ * Gets the DSA signing key bytes.
1106
+ * @returns {Uint8Array}
1107
+ */
1108
+ get dsa_signing_key() {
1109
+ const ret = wasm.usersecretkeys_dsa_signing_key(this.__wbg_ptr);
1110
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1111
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1112
+ return v1;
1113
+ }
1114
+ /**
1115
+ * Gets the KEM secret key bytes.
1116
+ * @returns {Uint8Array}
1117
+ */
1118
+ get kem_secret_key() {
1119
+ const ret = wasm.usersecretkeys_kem_secret_key(this.__wbg_ptr);
1120
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1121
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1122
+ return v1;
1123
+ }
1124
+ /**
1125
+ * Gets only the Massa secret key bytes
1126
+ * @returns {Uint8Array}
1127
+ */
1128
+ get massa_secret_key() {
1129
+ const ret = wasm.usersecretkeys_massa_secret_key(this.__wbg_ptr);
1130
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
1131
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1132
+ return v1;
1133
+ }
1134
+ }
1135
+ if (Symbol.dispose) UserSecretKeys.prototype[Symbol.dispose] = UserSecretKeys.prototype.free;
1136
+
1137
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
1138
+
1139
+ async function __wbg_load(module, imports) {
1140
+ if (typeof Response === 'function' && module instanceof Response) {
1141
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1142
+ try {
1143
+ return await WebAssembly.instantiateStreaming(module, imports);
1144
+
1145
+ } catch (e) {
1146
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
1147
+
1148
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1149
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1150
+
1151
+ } else {
1152
+ throw e;
1153
+ }
1154
+ }
1155
+ }
1156
+
1157
+ const bytes = await module.arrayBuffer();
1158
+ return await WebAssembly.instantiate(bytes, imports);
1159
+
1160
+ } else {
1161
+ const instance = await WebAssembly.instantiate(module, imports);
1162
+
1163
+ if (instance instanceof WebAssembly.Instance) {
1164
+ return { instance, module };
1165
+
1166
+ } else {
1167
+ return instance;
1168
+ }
1169
+ }
1170
+ }
1171
+
1172
+ function __wbg_get_imports() {
1173
+ const imports = {};
1174
+ imports.wbg = {};
1175
+ imports.wbg.__wbg_call_13410aac570ffff7 = function() { return handleError(function (arg0, arg1) {
1176
+ const ret = arg0.call(arg1);
1177
+ return ret;
1178
+ }, arguments) };
1179
+ imports.wbg.__wbg_call_a5400b25a865cfd8 = function() { return handleError(function (arg0, arg1, arg2) {
1180
+ const ret = arg0.call(arg1, arg2);
1181
+ return ret;
1182
+ }, arguments) };
1183
+ imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
1184
+ const ret = arg0.crypto;
1185
+ return ret;
1186
+ };
1187
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
1188
+ let deferred0_0;
1189
+ let deferred0_1;
1190
+ try {
1191
+ deferred0_0 = arg0;
1192
+ deferred0_1 = arg1;
1193
+ console.error(getStringFromWasm0(arg0, arg1));
1194
+ } finally {
1195
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1196
+ }
1197
+ };
1198
+ imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
1199
+ arg0.getRandomValues(arg1);
1200
+ }, arguments) };
1201
+ imports.wbg.__wbg_length_6bb7e81f9d7713e4 = function(arg0) {
1202
+ const ret = arg0.length;
1203
+ return ret;
1204
+ };
1205
+ imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
1206
+ const ret = arg0.msCrypto;
1207
+ return ret;
1208
+ };
1209
+ imports.wbg.__wbg_new_1f3a344cf3123716 = function() {
1210
+ const ret = new Array();
1211
+ return ret;
1212
+ };
1213
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
1214
+ const ret = new Error();
1215
+ return ret;
1216
+ };
1217
+ imports.wbg.__wbg_newfromslice_074c56947bd43469 = function(arg0, arg1) {
1218
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
1219
+ return ret;
1220
+ };
1221
+ imports.wbg.__wbg_newnoargs_254190557c45b4ec = function(arg0, arg1) {
1222
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
1223
+ return ret;
1224
+ };
1225
+ imports.wbg.__wbg_newwithlength_a167dcc7aaa3ba77 = function(arg0) {
1226
+ const ret = new Uint8Array(arg0 >>> 0);
1227
+ return ret;
1228
+ };
1229
+ imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
1230
+ const ret = arg0.node;
1231
+ return ret;
1232
+ };
1233
+ imports.wbg.__wbg_now_1e80617bcee43265 = function() {
1234
+ const ret = Date.now();
1235
+ return ret;
1236
+ };
1237
+ imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
1238
+ const ret = arg0.process;
1239
+ return ret;
1240
+ };
1241
+ imports.wbg.__wbg_prototypesetcall_3d4a26c1ed734349 = function(arg0, arg1, arg2) {
1242
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
1243
+ };
1244
+ imports.wbg.__wbg_push_330b2eb93e4e1212 = function(arg0, arg1) {
1245
+ const ret = arg0.push(arg1);
1246
+ return ret;
1247
+ };
1248
+ imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
1249
+ arg0.randomFillSync(arg1);
1250
+ }, arguments) };
1251
+ imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
1252
+ const ret = module.require;
1253
+ return ret;
1254
+ }, arguments) };
1255
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
1256
+ const ret = arg1.stack;
1257
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1258
+ const len1 = WASM_VECTOR_LEN;
1259
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1260
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1261
+ };
1262
+ imports.wbg.__wbg_static_accessor_GLOBAL_8921f820c2ce3f12 = function() {
1263
+ const ret = typeof global === 'undefined' ? null : global;
1264
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1265
+ };
1266
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_f0a4409105898184 = function() {
1267
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
1268
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1269
+ };
1270
+ imports.wbg.__wbg_static_accessor_SELF_995b214ae681ff99 = function() {
1271
+ const ret = typeof self === 'undefined' ? null : self;
1272
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1273
+ };
1274
+ imports.wbg.__wbg_static_accessor_WINDOW_cde3890479c675ea = function() {
1275
+ const ret = typeof window === 'undefined' ? null : window;
1276
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1277
+ };
1278
+ imports.wbg.__wbg_subarray_70fd07feefe14294 = function(arg0, arg1, arg2) {
1279
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
1280
+ return ret;
1281
+ };
1282
+ imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
1283
+ const ret = arg0.versions;
1284
+ return ret;
1285
+ };
1286
+ imports.wbg.__wbg_wbindgenisfunction_8cee7dce3725ae74 = function(arg0) {
1287
+ const ret = typeof(arg0) === 'function';
1288
+ return ret;
1289
+ };
1290
+ imports.wbg.__wbg_wbindgenisobject_307a53c6bd97fbf8 = function(arg0) {
1291
+ const val = arg0;
1292
+ const ret = typeof(val) === 'object' && val !== null;
1293
+ return ret;
1294
+ };
1295
+ imports.wbg.__wbg_wbindgenisstring_d4fa939789f003b0 = function(arg0) {
1296
+ const ret = typeof(arg0) === 'string';
1297
+ return ret;
1298
+ };
1299
+ imports.wbg.__wbg_wbindgenisundefined_c4b71d073b92f3c5 = function(arg0) {
1300
+ const ret = arg0 === undefined;
1301
+ return ret;
1302
+ };
1303
+ imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
1304
+ throw new Error(getStringFromWasm0(arg0, arg1));
1305
+ };
1306
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
1307
+ // Cast intrinsic for `Ref(String) -> Externref`.
1308
+ const ret = getStringFromWasm0(arg0, arg1);
1309
+ return ret;
1310
+ };
1311
+ imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
1312
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1313
+ const ret = getArrayU8FromWasm0(arg0, arg1);
1314
+ return ret;
1315
+ };
1316
+ imports.wbg.__wbindgen_init_externref_table = function() {
1317
+ const table = wasm.__wbindgen_export_2;
1318
+ const offset = table.grow(4);
1319
+ table.set(0, undefined);
1320
+ table.set(offset + 0, undefined);
1321
+ table.set(offset + 1, null);
1322
+ table.set(offset + 2, true);
1323
+ table.set(offset + 3, false);
1324
+ ;
1325
+ };
1326
+
1327
+ return imports;
1328
+ }
1329
+
1330
+ function __wbg_init_memory(imports, memory) {
1331
+
1332
+ }
1333
+
1334
+ function __wbg_finalize_init(instance, module) {
1335
+ wasm = instance.exports;
1336
+ __wbg_init.__wbindgen_wasm_module = module;
1337
+ cachedDataViewMemory0 = null;
1338
+ cachedUint8ArrayMemory0 = null;
1339
+
1340
+
1341
+ wasm.__wbindgen_start();
1342
+ return wasm;
1343
+ }
1344
+
1345
+ function initSync(module) {
1346
+ if (wasm !== undefined) return wasm;
1347
+
1348
+
1349
+ if (typeof module !== 'undefined') {
1350
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1351
+ ({module} = module)
1352
+ } else {
1353
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1354
+ }
1355
+ }
1356
+
1357
+ const imports = __wbg_get_imports();
1358
+
1359
+ __wbg_init_memory(imports);
1360
+
1361
+ if (!(module instanceof WebAssembly.Module)) {
1362
+ module = new WebAssembly.Module(module);
1363
+ }
1364
+
1365
+ const instance = new WebAssembly.Instance(module, imports);
1366
+
1367
+ return __wbg_finalize_init(instance, module);
1368
+ }
1369
+
1370
+ async function __wbg_init(module_or_path) {
1371
+ if (wasm !== undefined) return wasm;
1372
+
1373
+
1374
+ if (typeof module_or_path !== 'undefined') {
1375
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1376
+ ({module_or_path} = module_or_path)
1377
+ } else {
1378
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1379
+ }
1380
+ }
1381
+
1382
+ if (typeof module_or_path === 'undefined') {
1383
+ module_or_path = new URL('gossip_wasm_bg.wasm', import.meta.url);
1384
+ }
1385
+ const imports = __wbg_get_imports();
1386
+
1387
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1388
+ module_or_path = fetch(module_or_path);
1389
+ }
1390
+
1391
+ __wbg_init_memory(imports);
1392
+
1393
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1394
+
1395
+ return __wbg_finalize_init(instance, module);
1396
+ }
1397
+
1398
+ export { initSync };
1399
+ export default __wbg_init;