@massalabs/gossip-sdk 0.0.2-dev.20260429061149 → 0.0.2-dev.20260506131227

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.
@@ -1,5 +1,40 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ /**
4
+ * Decrypts data using AES-256-SIV authenticated encryption.
5
+ *
6
+ * # Parameters
7
+ *
8
+ * - `key`: The encryption key (64 bytes, must match encryption key)
9
+ * - `nonce`: The nonce (16 bytes, must match encryption nonce)
10
+ * - `ciphertext`: The encrypted data with authentication tag
11
+ * - `aad`: Additional authenticated data (must match encryption AAD)
12
+ *
13
+ * # Returns
14
+ *
15
+ * The decrypted plaintext, or `null` if authentication fails.
16
+ *
17
+ * # Security Notes
18
+ *
19
+ * - Returns `null` if:
20
+ * - The ciphertext has been tampered with
21
+ * - The wrong key or nonce is used
22
+ * - The AAD doesn't match
23
+ * - Never ignore a decryption failure; it indicates tampering or corruption
24
+ *
25
+ * # Example
26
+ *
27
+ * ```javascript
28
+ * const plaintext = aead_decrypt(key, nonce, ciphertext, aad);
29
+ * if (plaintext) {
30
+ * console.log("Decrypted:", new TextDecoder().decode(plaintext));
31
+ * } else {
32
+ * console.error("Decryption failed - data may be corrupted or tampered");
33
+ * }
34
+ * ```
35
+ */
36
+ export function aead_decrypt(key: EncryptionKey, nonce: Nonce, ciphertext: Uint8Array, aad: Uint8Array): Uint8Array | undefined;
37
+ export function start(): void;
3
38
  /**
4
39
  * Encrypts data using AES-256-SIV authenticated encryption.
5
40
  *
@@ -40,41 +75,6 @@ export function aead_encrypt(key: EncryptionKey, nonce: Nonce, plaintext: Uint8A
40
75
  * the passphrase crosses the JS boundary only once.
41
76
  */
42
77
  export function generate_user_keys(passphrase: string): UserKeys;
43
- export function start(): void;
44
- /**
45
- * Decrypts data using AES-256-SIV authenticated encryption.
46
- *
47
- * # Parameters
48
- *
49
- * - `key`: The encryption key (64 bytes, must match encryption key)
50
- * - `nonce`: The nonce (16 bytes, must match encryption nonce)
51
- * - `ciphertext`: The encrypted data with authentication tag
52
- * - `aad`: Additional authenticated data (must match encryption AAD)
53
- *
54
- * # Returns
55
- *
56
- * The decrypted plaintext, or `null` if authentication fails.
57
- *
58
- * # Security Notes
59
- *
60
- * - Returns `null` if:
61
- * - The ciphertext has been tampered with
62
- * - The wrong key or nonce is used
63
- * - The AAD doesn't match
64
- * - Never ignore a decryption failure; it indicates tampering or corruption
65
- *
66
- * # Example
67
- *
68
- * ```javascript
69
- * const plaintext = aead_decrypt(key, nonce, ciphertext, aad);
70
- * if (plaintext) {
71
- * console.log("Decrypted:", new TextDecoder().decode(plaintext));
72
- * } else {
73
- * console.error("Decryption failed - data may be corrupted or tampered");
74
- * }
75
- * ```
76
- */
77
- export function aead_decrypt(key: EncryptionKey, nonce: Nonce, ciphertext: Uint8Array, aad: Uint8Array): Uint8Array | undefined;
78
78
  /**
79
79
  * Session status indicating the state of a peer session.
80
80
  */
@@ -313,10 +313,24 @@ export class SessionManagerWrapper {
313
313
  feed_incoming_announcement(announcement_bytes: Uint8Array, our_pk: UserPublicKeys, our_sk: UserSecretKeys): AnnouncementResult | undefined;
314
314
  /**
315
315
  * Gets the list of message board seekers to monitor.
316
+ *
317
+ * Each seeker is materialised as a JS-owned Uint8Array via
318
+ * `new_with_length` + `copy_from`. `Uint8Array::from(&[u8])` in older
319
+ * js-sys returns an array whose buffer view sits over wasm linear
320
+ * memory; subsequent wasm calls that grow the heap detach those
321
+ * views, and the JS-side `SEEKERS_UPDATED` listener crashes with
322
+ * "Cannot perform values on a detached ArrayBuffer". The
323
+ * new-with-length path allocates a JS-side ArrayBuffer up front,
324
+ * then copies — the result is decoupled from wasm memory.
316
325
  */
317
326
  get_message_board_read_keys(): Array<any>;
318
327
  /**
319
328
  * Processes an incoming message from the message board.
329
+ *
330
+ * Each acknowledged seeker is materialised as a JS-owned Uint8Array
331
+ * (see `get_message_board_read_keys` for the rationale — same risk
332
+ * of detached views over wasm linear memory if the heap grows
333
+ * before the JS side reads the buffer).
320
334
  */
321
335
  feed_incoming_message_board_read(seeker: Uint8Array, ciphertext: Uint8Array, our_sk: UserSecretKeys): ReceiveMessageOutput | undefined;
322
336
  /**
@@ -325,10 +339,16 @@ export class SessionManagerWrapper {
325
339
  constructor(config: SessionConfig);
326
340
  /**
327
341
  * Refreshes sessions and returns peer IDs that need keep-alive messages.
342
+ *
343
+ * JS-owned Uint8Arrays — same detached-view rationale as
344
+ * `get_message_board_read_keys`.
328
345
  */
329
346
  refresh(): Array<any>;
330
347
  /**
331
348
  * Gets the list of all peer IDs.
349
+ *
350
+ * JS-owned Uint8Arrays — same detached-view rationale as
351
+ * `get_message_board_read_keys`.
332
352
  */
333
353
  peer_list(): Array<any>;
334
354
  }
@@ -135,6 +135,64 @@ function _assertClass(instance, klass) {
135
135
  throw new Error(`expected instance of ${klass.name}`);
136
136
  }
137
137
  }
138
+ /**
139
+ * Decrypts data using AES-256-SIV authenticated encryption.
140
+ *
141
+ * # Parameters
142
+ *
143
+ * - `key`: The encryption key (64 bytes, must match encryption key)
144
+ * - `nonce`: The nonce (16 bytes, must match encryption nonce)
145
+ * - `ciphertext`: The encrypted data with authentication tag
146
+ * - `aad`: Additional authenticated data (must match encryption AAD)
147
+ *
148
+ * # Returns
149
+ *
150
+ * The decrypted plaintext, or `null` if authentication fails.
151
+ *
152
+ * # Security Notes
153
+ *
154
+ * - Returns `null` if:
155
+ * - The ciphertext has been tampered with
156
+ * - The wrong key or nonce is used
157
+ * - The AAD doesn't match
158
+ * - Never ignore a decryption failure; it indicates tampering or corruption
159
+ *
160
+ * # Example
161
+ *
162
+ * ```javascript
163
+ * const plaintext = aead_decrypt(key, nonce, ciphertext, aad);
164
+ * if (plaintext) {
165
+ * console.log("Decrypted:", new TextDecoder().decode(plaintext));
166
+ * } else {
167
+ * console.error("Decryption failed - data may be corrupted or tampered");
168
+ * }
169
+ * ```
170
+ * @param {EncryptionKey} key
171
+ * @param {Nonce} nonce
172
+ * @param {Uint8Array} ciphertext
173
+ * @param {Uint8Array} aad
174
+ * @returns {Uint8Array | undefined}
175
+ */
176
+ export function aead_decrypt(key, nonce, ciphertext, aad) {
177
+ _assertClass(key, EncryptionKey);
178
+ _assertClass(nonce, Nonce);
179
+ const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
180
+ const len0 = WASM_VECTOR_LEN;
181
+ const ptr1 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
182
+ const len1 = WASM_VECTOR_LEN;
183
+ const ret = wasm.aead_decrypt(key.__wbg_ptr, nonce.__wbg_ptr, ptr0, len0, ptr1, len1);
184
+ let v3;
185
+ if (ret[0] !== 0) {
186
+ v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
187
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
188
+ }
189
+ return v3;
190
+ }
191
+
192
+ export function start() {
193
+ wasm.start();
194
+ }
195
+
138
196
  /**
139
197
  * Encrypts data using AES-256-SIV authenticated encryption.
140
198
  *
@@ -203,64 +261,6 @@ export function generate_user_keys(passphrase) {
203
261
  return UserKeys.__wrap(ret[0]);
204
262
  }
205
263
 
206
- export function start() {
207
- wasm.start();
208
- }
209
-
210
- /**
211
- * Decrypts data using AES-256-SIV authenticated encryption.
212
- *
213
- * # Parameters
214
- *
215
- * - `key`: The encryption key (64 bytes, must match encryption key)
216
- * - `nonce`: The nonce (16 bytes, must match encryption nonce)
217
- * - `ciphertext`: The encrypted data with authentication tag
218
- * - `aad`: Additional authenticated data (must match encryption AAD)
219
- *
220
- * # Returns
221
- *
222
- * The decrypted plaintext, or `null` if authentication fails.
223
- *
224
- * # Security Notes
225
- *
226
- * - Returns `null` if:
227
- * - The ciphertext has been tampered with
228
- * - The wrong key or nonce is used
229
- * - The AAD doesn't match
230
- * - Never ignore a decryption failure; it indicates tampering or corruption
231
- *
232
- * # Example
233
- *
234
- * ```javascript
235
- * const plaintext = aead_decrypt(key, nonce, ciphertext, aad);
236
- * if (plaintext) {
237
- * console.log("Decrypted:", new TextDecoder().decode(plaintext));
238
- * } else {
239
- * console.error("Decryption failed - data may be corrupted or tampered");
240
- * }
241
- * ```
242
- * @param {EncryptionKey} key
243
- * @param {Nonce} nonce
244
- * @param {Uint8Array} ciphertext
245
- * @param {Uint8Array} aad
246
- * @returns {Uint8Array | undefined}
247
- */
248
- export function aead_decrypt(key, nonce, ciphertext, aad) {
249
- _assertClass(key, EncryptionKey);
250
- _assertClass(nonce, Nonce);
251
- const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
252
- const len0 = WASM_VECTOR_LEN;
253
- const ptr1 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
254
- const len1 = WASM_VECTOR_LEN;
255
- const ret = wasm.aead_decrypt(key.__wbg_ptr, nonce.__wbg_ptr, ptr0, len0, ptr1, len1);
256
- let v3;
257
- if (ret[0] !== 0) {
258
- v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
259
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
260
- }
261
- return v3;
262
- }
263
-
264
264
  /**
265
265
  * Session status indicating the state of a peer session.
266
266
  * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6}
@@ -851,6 +851,15 @@ export class SessionManagerWrapper {
851
851
  }
852
852
  /**
853
853
  * Gets the list of message board seekers to monitor.
854
+ *
855
+ * Each seeker is materialised as a JS-owned Uint8Array via
856
+ * `new_with_length` + `copy_from`. `Uint8Array::from(&[u8])` in older
857
+ * js-sys returns an array whose buffer view sits over wasm linear
858
+ * memory; subsequent wasm calls that grow the heap detach those
859
+ * views, and the JS-side `SEEKERS_UPDATED` listener crashes with
860
+ * "Cannot perform values on a detached ArrayBuffer". The
861
+ * new-with-length path allocates a JS-side ArrayBuffer up front,
862
+ * then copies — the result is decoupled from wasm memory.
854
863
  * @returns {Array<any>}
855
864
  */
856
865
  get_message_board_read_keys() {
@@ -859,6 +868,11 @@ export class SessionManagerWrapper {
859
868
  }
860
869
  /**
861
870
  * Processes an incoming message from the message board.
871
+ *
872
+ * Each acknowledged seeker is materialised as a JS-owned Uint8Array
873
+ * (see `get_message_board_read_keys` for the rationale — same risk
874
+ * of detached views over wasm linear memory if the heap grows
875
+ * before the JS side reads the buffer).
862
876
  * @param {Uint8Array} seeker
863
877
  * @param {Uint8Array} ciphertext
864
878
  * @param {UserSecretKeys} our_sk
@@ -887,6 +901,9 @@ export class SessionManagerWrapper {
887
901
  }
888
902
  /**
889
903
  * Refreshes sessions and returns peer IDs that need keep-alive messages.
904
+ *
905
+ * JS-owned Uint8Arrays — same detached-view rationale as
906
+ * `get_message_board_read_keys`.
890
907
  * @returns {Array<any>}
891
908
  */
892
909
  refresh() {
@@ -895,6 +912,9 @@ export class SessionManagerWrapper {
895
912
  }
896
913
  /**
897
914
  * Gets the list of all peer IDs.
915
+ *
916
+ * JS-owned Uint8Arrays — same detached-view rationale as
917
+ * `get_message_board_read_keys`.
898
918
  * @returns {Array<any>}
899
919
  */
900
920
  peer_list() {
@@ -1272,10 +1292,6 @@ function __wbg_get_imports() {
1272
1292
  const ret = new Error();
1273
1293
  return ret;
1274
1294
  };
1275
- imports.wbg.__wbg_newfromslice_074c56947bd43469 = function(arg0, arg1) {
1276
- const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
1277
- return ret;
1278
- };
1279
1295
  imports.wbg.__wbg_newnoargs_254190557c45b4ec = function(arg0, arg1) {
1280
1296
  const ret = new Function(getStringFromWasm0(arg0, arg1));
1281
1297
  return ret;
@@ -1310,6 +1326,9 @@ function __wbg_get_imports() {
1310
1326
  const ret = module.require;
1311
1327
  return ret;
1312
1328
  }, arguments) };
1329
+ imports.wbg.__wbg_set_1353b2a5e96bc48c = function(arg0, arg1, arg2) {
1330
+ arg0.set(getArrayU8FromWasm0(arg1, arg2));
1331
+ };
1313
1332
  imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
1314
1333
  const ret = arg1.stack;
1315
1334
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -0,0 +1,2 @@
1
+ export * from "./secureStorage.js";
2
+ export { default } from "./secureStorage.js";
@@ -0,0 +1,143 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export function initSecureStorage(domain: string, backend: string): Promise<void>;
4
+ export function idbHasData(): Promise<boolean>;
5
+ export function provisionStorage(): void;
6
+ export function allocateSession(slot: number, password: Uint8Array): void;
7
+ export function flushEncrypted(): Promise<void>;
8
+ export function openDatabase(): void;
9
+ export function closeDatabase(): void;
10
+ /**
11
+ * Run a SQL statement with bound parameters.
12
+ *
13
+ * `params` is a JS array of values; supported types are number, string,
14
+ * Uint8Array, null, and bigint. Returns rows as a JS array of arrays
15
+ * (positional column values), matching the Drizzle sqlite-proxy contract.
16
+ */
17
+ export function execSql(sql: string, params: Array<any>): ExecResult;
18
+ export function unlockSession(password: Uint8Array): boolean;
19
+ export function lockSession(): void;
20
+ /**
21
+ * Permanently destroy the data of the currently unlocked slot.
22
+ *
23
+ * The actual writes (new dummy keypair + cover blocks) land in
24
+ * IdbBlockStorage's in-memory pending state. Durability comes from
25
+ * the caller's subsequent `flushEncrypted()` await — same pattern
26
+ * the worker uses for `lockSession`. A process crash before that
27
+ * flush rolls everything back: the IDB on-disk state is unchanged,
28
+ * the slot is left exactly as it was.
29
+ *
30
+ * **The caller must `closeDatabase()` first** so SQLite's xWrite
31
+ * flush on close lands in the buffer before destroy_session truncates
32
+ * the namespace. Mirrors `lockSession`'s contract.
33
+ */
34
+ export function destroySession(namespaces: Uint8Array): void;
35
+ export function coverTrafficTick(namespace: number): void;
36
+ export function writeNamespaceData(namespace: number, offset: number, data: Uint8Array): void;
37
+ export function readNamespaceData(namespace: number, offset: number, len: number): Uint8Array;
38
+ export function namespaceDataLength(namespace: number): number;
39
+ export function clearNamespace(namespace: number): void;
40
+ export function initThreadPool(num_threads: number): Promise<any>;
41
+ export function wbg_rayon_start_worker(receiver: number): void;
42
+ /**
43
+ * Result of an `execSql` call.
44
+ *
45
+ * `last_insert_rowid` is `f64` (not `i64`) because it crosses the JS bridge
46
+ * and JS has no native i64 — its `Number` type is f64. SQLite rowids are
47
+ * sequential and stay within JS's safe integer range (2^53) in practice,
48
+ * so the conversion is lossless.
49
+ */
50
+ export class ExecResult {
51
+ private constructor();
52
+ free(): void;
53
+ [Symbol.dispose](): void;
54
+ readonly lastInsertRowId: number;
55
+ readonly rows: Array<any>;
56
+ }
57
+ export class wbg_rayon_PoolBuilder {
58
+ private constructor();
59
+ free(): void;
60
+ [Symbol.dispose](): void;
61
+ numThreads(): number;
62
+ build(): void;
63
+ receiver(): number;
64
+ }
65
+
66
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
67
+
68
+ export interface InitOutput {
69
+ readonly __wbg_execresult_free: (a: number, b: number) => void;
70
+ readonly allocateSession: (a: number, b: number, c: number) => [number, number];
71
+ readonly clearNamespace: (a: number) => [number, number];
72
+ readonly closeDatabase: () => [number, number];
73
+ readonly coverTrafficTick: (a: number) => [number, number];
74
+ readonly destroySession: (a: number, b: number) => [number, number];
75
+ readonly execSql: (a: number, b: number, c: any) => [number, number, number];
76
+ readonly execresult_lastInsertRowId: (a: number) => number;
77
+ readonly execresult_rows: (a: number) => any;
78
+ readonly flushEncrypted: () => any;
79
+ readonly idbHasData: () => any;
80
+ readonly initSecureStorage: (a: number, b: number, c: number, d: number) => any;
81
+ readonly lockSession: () => [number, number];
82
+ readonly namespaceDataLength: (a: number) => [number, number, number];
83
+ readonly openDatabase: () => [number, number];
84
+ readonly provisionStorage: () => [number, number];
85
+ readonly readNamespaceData: (a: number, b: number, c: number) => [number, number, number, number];
86
+ readonly unlockSession: (a: number, b: number) => [number, number, number];
87
+ readonly writeNamespaceData: (a: number, b: number, c: number, d: number) => [number, number];
88
+ readonly __wbg_wbg_rayon_poolbuilder_free: (a: number, b: number) => void;
89
+ readonly initThreadPool: (a: number) => any;
90
+ readonly wbg_rayon_poolbuilder_build: (a: number) => void;
91
+ readonly wbg_rayon_poolbuilder_numThreads: (a: number) => number;
92
+ readonly wbg_rayon_poolbuilder_receiver: (a: number) => number;
93
+ readonly wbg_rayon_start_worker: (a: number) => void;
94
+ readonly rust_sqlite_wasm_abort: () => void;
95
+ readonly rust_sqlite_wasm_assert_fail: (a: number, b: number, c: number, d: number) => void;
96
+ readonly rust_sqlite_wasm_calloc: (a: number, b: number) => number;
97
+ readonly rust_sqlite_wasm_free: (a: number) => void;
98
+ readonly rust_sqlite_wasm_getentropy: (a: number, b: number) => number;
99
+ readonly rust_sqlite_wasm_localtime: (a: number) => number;
100
+ readonly rust_sqlite_wasm_malloc: (a: number) => number;
101
+ readonly rust_sqlite_wasm_realloc: (a: number, b: number) => number;
102
+ readonly sqlite3_os_end: () => number;
103
+ readonly sqlite3_os_init: () => number;
104
+ readonly __wbindgen_exn_store: (a: number) => void;
105
+ readonly __externref_table_alloc: () => number;
106
+ readonly __wbindgen_export_2: WebAssembly.Table;
107
+ readonly memory: WebAssembly.Memory;
108
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
109
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
110
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
111
+ readonly __wbindgen_export_7: WebAssembly.Table;
112
+ readonly __externref_table_dealloc: (a: number) => void;
113
+ readonly closure97_externref_shim: (a: number, b: number, c: any) => void;
114
+ readonly wasm_bindgen_b3ea05ef1784c7d3___convert__closures_____invoke______: (a: number, b: number) => void;
115
+ readonly closure662_externref_shim: (a: number, b: number, c: any) => void;
116
+ readonly closure89_externref_shim_multivalue_shim: (a: number, b: number, c: any) => [number, number];
117
+ readonly closure718_externref_shim: (a: number, b: number, c: any, d: any) => void;
118
+ readonly __wbindgen_thread_destroy: (a?: number, b?: number, c?: number) => void;
119
+ readonly __wbindgen_start: (a: number) => void;
120
+ }
121
+
122
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
123
+ /**
124
+ * Instantiates the given `module`, which can either be bytes or
125
+ * a precompiled `WebAssembly.Module`.
126
+ *
127
+ * @param {{ module: SyncInitInput, memory?: WebAssembly.Memory, thread_stack_size?: number }} module - Passing `SyncInitInput` directly is deprecated.
128
+ * @param {WebAssembly.Memory} memory - Deprecated.
129
+ *
130
+ * @returns {InitOutput}
131
+ */
132
+ export function initSync(module: { module: SyncInitInput, memory?: WebAssembly.Memory, thread_stack_size?: number } | SyncInitInput, memory?: WebAssembly.Memory): InitOutput;
133
+
134
+ /**
135
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
136
+ * for everything else, calls `WebAssembly.instantiate` directly.
137
+ *
138
+ * @param {{ module_or_path: InitInput | Promise<InitInput>, memory?: WebAssembly.Memory, thread_stack_size?: number }} module_or_path - Passing `InitInput` directly is deprecated.
139
+ * @param {WebAssembly.Memory} memory - Deprecated.
140
+ *
141
+ * @returns {Promise<InitOutput>}
142
+ */
143
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput>, memory?: WebAssembly.Memory, thread_stack_size?: number } | InitInput | Promise<InitInput>, memory?: WebAssembly.Memory): Promise<InitOutput>;