cojson-core-wasm 0.19.21 → 0.20.0

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.
@@ -167,16 +167,6 @@ function debugString(val) {
167
167
  return className;
168
168
  }
169
169
 
170
- function passArrayJsValueToWasm0(array, malloc) {
171
- const ptr = malloc(array.length * 4, 4) >>> 0;
172
- for (let i = 0; i < array.length; i++) {
173
- const add = addToExternrefTable0(array[i]);
174
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
175
- }
176
- WASM_VECTOR_LEN = array.length;
177
- return ptr;
178
- }
179
-
180
170
  function takeFromExternrefTable0(idx) {
181
171
  const value = wasm.__wbindgen_export_4.get(idx);
182
172
  wasm.__externref_table_dealloc(idx);
@@ -195,85 +185,89 @@ function getArrayU8FromWasm0(ptr, len) {
195
185
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
196
186
  }
197
187
  /**
198
- * WASM-exposed function for XSalsa20 encryption without authentication.
199
- * - `key`: 32-byte key for encryption
200
- * - `nonce_material`: Raw bytes used to generate a 24-byte nonce via BLAKE3
201
- * - `plaintext`: Raw bytes to encrypt
202
- * Returns the encrypted bytes or throws a JsError if encryption fails.
203
- * Note: This function does not provide authentication. Use encrypt_xsalsa20_poly1305 for authenticated encryption.
204
- * @param {Uint8Array} key
205
- * @param {Uint8Array} nonce_material
206
- * @param {Uint8Array} plaintext
188
+ * WASM-exposed function to derive the public key from an Ed25519 signing key.
189
+ * - `signing_key`: 32 bytes of signing key material
190
+ * Returns 32 bytes of public key material or throws JsError if key is invalid.
191
+ * @param {Uint8Array} signing_key
207
192
  * @returns {Uint8Array}
208
193
  */
209
- export function encryptXsalsa20(key, nonce_material, plaintext) {
210
- const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
194
+ export function ed25519SigningKeyToPublic(signing_key) {
195
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
211
196
  const len0 = WASM_VECTOR_LEN;
212
- const ptr1 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
213
- const len1 = WASM_VECTOR_LEN;
214
- const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
215
- const len2 = WASM_VECTOR_LEN;
216
- const ret = wasm.encryptXsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
197
+ const ret = wasm.ed25519SigningKeyToPublic(ptr0, len0);
217
198
  if (ret[3]) {
218
199
  throw takeFromExternrefTable0(ret[2]);
219
200
  }
220
- var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
201
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
221
202
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
222
- return v4;
203
+ return v2;
223
204
  }
224
205
 
225
206
  /**
226
- * WASM-exposed function for XSalsa20 decryption without authentication.
227
- * - `key`: 32-byte key for decryption (must match encryption key)
228
- * - `nonce_material`: Raw bytes used to generate a 24-byte nonce (must match encryption)
229
- * - `ciphertext`: Encrypted bytes to decrypt
230
- * Returns the decrypted bytes or throws a JsError if decryption fails.
231
- * Note: This function does not provide authentication. Use decrypt_xsalsa20_poly1305 for authenticated decryption.
232
- * @param {Uint8Array} key
233
- * @param {Uint8Array} nonce_material
234
- * @param {Uint8Array} ciphertext
207
+ * WASM-exposed function to validate and copy Ed25519 signing key bytes.
208
+ * - `bytes`: 32 bytes of signing key material to validate
209
+ * Returns the same 32 bytes if valid or throws JsError if invalid.
210
+ * @param {Uint8Array} bytes
235
211
  * @returns {Uint8Array}
236
212
  */
237
- export function decryptXsalsa20(key, nonce_material, ciphertext) {
238
- const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
213
+ export function ed25519SigningKeyFromBytes(bytes) {
214
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
239
215
  const len0 = WASM_VECTOR_LEN;
240
- const ptr1 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
216
+ const ret = wasm.ed25519SigningKeyFromBytes(ptr0, len0);
217
+ if (ret[3]) {
218
+ throw takeFromExternrefTable0(ret[2]);
219
+ }
220
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
221
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
222
+ return v2;
223
+ }
224
+
225
+ /**
226
+ * WASM-exposed function to sign a message using Ed25519.
227
+ * - `signing_key`: 32 bytes of signing key material
228
+ * - `message`: Raw bytes to sign
229
+ * Returns 64 bytes of signature material or throws JsError if signing fails.
230
+ * @param {Uint8Array} signing_key
231
+ * @param {Uint8Array} message
232
+ * @returns {Uint8Array}
233
+ */
234
+ export function ed25519Sign(signing_key, message) {
235
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
236
+ const len0 = WASM_VECTOR_LEN;
237
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
241
238
  const len1 = WASM_VECTOR_LEN;
242
- const ptr2 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
243
- const len2 = WASM_VECTOR_LEN;
244
- const ret = wasm.decryptXsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
239
+ const ret = wasm.ed25519Sign(ptr0, len0, ptr1, len1);
245
240
  if (ret[3]) {
246
241
  throw takeFromExternrefTable0(ret[2]);
247
242
  }
248
- var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
243
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
249
244
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
250
- return v4;
245
+ return v3;
251
246
  }
252
247
 
253
248
  /**
254
- * Generate a new X25519 private key using secure random number generation.
255
- * Returns 32 bytes of raw key material suitable for use with other X25519 functions.
256
- * This key can be reused for multiple Diffie-Hellman exchanges.
249
+ * Generate a new Ed25519 signing key using secure random number generation.
250
+ * Returns 32 bytes of raw key material suitable for use with other Ed25519 functions.
257
251
  * @returns {Uint8Array}
258
252
  */
259
- export function newX25519PrivateKey() {
260
- const ret = wasm.newX25519PrivateKey();
253
+ export function newEd25519SigningKey() {
254
+ const ret = wasm.newEd25519SigningKey();
261
255
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
262
256
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
263
257
  return v1;
264
258
  }
265
259
 
266
260
  /**
267
- * WASM-exposed function to derive an X25519 public key from a private key.
268
- * - `private_key`: 32 bytes of private key material
269
- * Returns 32 bytes of public key material or throws JsError if key is invalid.
270
- * @param {Uint8Array} private_key
261
+ * WASM-exposed function to validate and copy Ed25519 signature bytes.
262
+ * - `bytes`: 64 bytes of signature material to validate
263
+ * Returns the same 64 bytes if valid or throws JsError if invalid.
264
+ * @param {Uint8Array} bytes
271
265
  * @returns {Uint8Array}
272
266
  */
273
- export function x25519PublicKey(private_key) {
274
- const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
267
+ export function ed25519SignatureFromBytes(bytes) {
268
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
275
269
  const len0 = WASM_VECTOR_LEN;
276
- const ret = wasm.x25519PublicKey(ptr0, len0);
270
+ const ret = wasm.ed25519SignatureFromBytes(ptr0, len0);
277
271
  if (ret[3]) {
278
272
  throw takeFromExternrefTable0(ret[2]);
279
273
  }
@@ -283,20 +277,39 @@ export function x25519PublicKey(private_key) {
283
277
  }
284
278
 
285
279
  /**
286
- * WASM-exposed function to perform X25519 Diffie-Hellman key exchange.
287
- * - `private_key`: 32 bytes of private key material
288
- * - `public_key`: 32 bytes of public key material
289
- * Returns 32 bytes of shared secret material or throws JsError if key exchange fails.
290
- * @param {Uint8Array} private_key
291
- * @param {Uint8Array} public_key
280
+ * WASM-exposed function to derive an Ed25519 verifying key from a signing key.
281
+ * - `signing_key`: 32 bytes of signing key material
282
+ * Returns 32 bytes of verifying key material or throws JsError if key is invalid.
283
+ * @param {Uint8Array} signing_key
292
284
  * @returns {Uint8Array}
293
285
  */
294
- export function x25519DiffieHellman(private_key, public_key) {
295
- const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
286
+ export function ed25519VerifyingKey(signing_key) {
287
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
296
288
  const len0 = WASM_VECTOR_LEN;
297
- const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
289
+ const ret = wasm.ed25519VerifyingKey(ptr0, len0);
290
+ if (ret[3]) {
291
+ throw takeFromExternrefTable0(ret[2]);
292
+ }
293
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
294
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
295
+ return v2;
296
+ }
297
+
298
+ /**
299
+ * WASM-exposed function to sign a message with an Ed25519 signing key.
300
+ * - `signing_key`: 32 bytes of signing key material
301
+ * - `message`: Raw bytes to sign
302
+ * Returns 64 bytes of signature material or throws JsError if signing fails.
303
+ * @param {Uint8Array} signing_key
304
+ * @param {Uint8Array} message
305
+ * @returns {Uint8Array}
306
+ */
307
+ export function ed25519SigningKeySign(signing_key, message) {
308
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
309
+ const len0 = WASM_VECTOR_LEN;
310
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
298
311
  const len1 = WASM_VECTOR_LEN;
299
- const ret = wasm.x25519DiffieHellman(ptr0, len0, ptr1, len1);
312
+ const ret = wasm.ed25519SigningKeySign(ptr0, len0, ptr1, len1);
300
313
  if (ret[3]) {
301
314
  throw takeFromExternrefTable0(ret[2]);
302
315
  }
@@ -306,19 +319,63 @@ export function x25519DiffieHellman(private_key, public_key) {
306
319
  }
307
320
 
308
321
  /**
309
- * WASM-exposed function to derive a sealer ID from a sealer secret.
310
- * - `secret`: Raw bytes of the sealer secret
311
- * Returns a base58-encoded sealer ID with "sealer_z" prefix or throws JsError if derivation fails.
322
+ * WASM-exposed function to validate and copy Ed25519 verifying key bytes.
323
+ * - `bytes`: 32 bytes of verifying key material to validate
324
+ * Returns the same 32 bytes if valid or throws JsError if invalid.
325
+ * @param {Uint8Array} bytes
326
+ * @returns {Uint8Array}
327
+ */
328
+ export function ed25519VerifyingKeyFromBytes(bytes) {
329
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
330
+ const len0 = WASM_VECTOR_LEN;
331
+ const ret = wasm.ed25519VerifyingKeyFromBytes(ptr0, len0);
332
+ if (ret[3]) {
333
+ throw takeFromExternrefTable0(ret[2]);
334
+ }
335
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
336
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
337
+ return v2;
338
+ }
339
+
340
+ /**
341
+ * WASM-exposed function to verify an Ed25519 signature.
342
+ * - `verifying_key`: 32 bytes of verifying key material
343
+ * - `message`: Raw bytes that were signed
344
+ * - `signature`: 64 bytes of signature material
345
+ * Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
346
+ * @param {Uint8Array} verifying_key
347
+ * @param {Uint8Array} message
348
+ * @param {Uint8Array} signature
349
+ * @returns {boolean}
350
+ */
351
+ export function ed25519Verify(verifying_key, message, signature) {
352
+ const ptr0 = passArray8ToWasm0(verifying_key, wasm.__wbindgen_malloc);
353
+ const len0 = WASM_VECTOR_LEN;
354
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
355
+ const len1 = WASM_VECTOR_LEN;
356
+ const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
357
+ const len2 = WASM_VECTOR_LEN;
358
+ const ret = wasm.ed25519Verify(ptr0, len0, ptr1, len1, ptr2, len2);
359
+ if (ret[2]) {
360
+ throw takeFromExternrefTable0(ret[1]);
361
+ }
362
+ return ret[0] !== 0;
363
+ }
364
+
365
+ /**
366
+ * WASM-exposed function to derive a signer ID from a signing key.
367
+ * - `secret`: Raw Ed25519 signing key bytes
368
+ * Returns base58-encoded verifying key with "signer_z" prefix or throws JsError if derivation fails.
312
369
  * @param {Uint8Array} secret
313
370
  * @returns {string}
314
371
  */
315
- export function getSealerId(secret) {
372
+ export function getSignerId(secret) {
316
373
  let deferred3_0;
317
374
  let deferred3_1;
318
375
  try {
319
376
  const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
320
377
  const len0 = WASM_VECTOR_LEN;
321
- const ret = wasm.getSealerId(ptr0, len0);
378
+ const ret = wasm.getSignerId(ptr0, len0);
322
379
  var ptr2 = ret[0];
323
380
  var len2 = ret[1];
324
381
  if (ret[3]) {
@@ -334,121 +391,60 @@ export function getSealerId(secret) {
334
391
  }
335
392
 
336
393
  /**
337
- * WASM-exposed function to encrypt bytes with a key secret and nonce material.
338
- * - `value`: The raw bytes to encrypt
339
- * - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
340
- * - `nonce_material`: Raw bytes used to generate the nonce
341
- * Returns the encrypted bytes or throws a JsError if encryption fails.
342
- * @param {Uint8Array} value
343
- * @param {string} key_secret
344
- * @param {Uint8Array} nonce_material
345
- * @returns {Uint8Array}
346
- */
347
- export function encrypt(value, key_secret, nonce_material) {
348
- const ptr0 = passArray8ToWasm0(value, wasm.__wbindgen_malloc);
349
- const len0 = WASM_VECTOR_LEN;
350
- const ptr1 = passStringToWasm0(key_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
351
- const len1 = WASM_VECTOR_LEN;
352
- const ptr2 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
353
- const len2 = WASM_VECTOR_LEN;
354
- const ret = wasm.encrypt(ptr0, len0, ptr1, len1, ptr2, len2);
355
- if (ret[3]) {
356
- throw takeFromExternrefTable0(ret[2]);
357
- }
358
- var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
359
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
360
- return v4;
361
- }
362
-
363
- /**
364
- * WASM-exposed function to decrypt bytes with a key secret and nonce material.
365
- * - `ciphertext`: The encrypted bytes to decrypt
366
- * - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
367
- * - `nonce_material`: Raw bytes used to generate the nonce (must match encryption)
368
- * Returns the decrypted bytes or throws a JsError if decryption fails.
369
- * @param {Uint8Array} ciphertext
370
- * @param {string} key_secret
371
- * @param {Uint8Array} nonce_material
372
- * @returns {Uint8Array}
373
- */
374
- export function decrypt(ciphertext, key_secret, nonce_material) {
375
- const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
376
- const len0 = WASM_VECTOR_LEN;
377
- const ptr1 = passStringToWasm0(key_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
378
- const len1 = WASM_VECTOR_LEN;
379
- const ptr2 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
380
- const len2 = WASM_VECTOR_LEN;
381
- const ret = wasm.decrypt(ptr0, len0, ptr1, len1, ptr2, len2);
382
- if (ret[3]) {
383
- throw takeFromExternrefTable0(ret[2]);
384
- }
385
- var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
386
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
387
- return v4;
388
- }
389
-
390
- /**
391
- * WASM-exposed function for sealing a message using X25519 + XSalsa20-Poly1305.
392
- * Provides authenticated encryption with perfect forward secrecy.
393
- * - `message`: Raw bytes to seal
394
- * - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
395
- * - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
396
- * - `nonce_material`: Raw bytes used to generate the nonce
397
- * Returns sealed bytes or throws JsError if sealing fails.
394
+ * WASM-exposed function to sign a message using Ed25519.
395
+ * - `message`: Raw bytes to sign
396
+ * - `secret`: Raw Ed25519 signing key bytes
397
+ * Returns base58-encoded signature with "signature_z" prefix or throws JsError if signing fails.
398
398
  * @param {Uint8Array} message
399
- * @param {string} sender_secret
400
- * @param {string} recipient_id
401
- * @param {Uint8Array} nonce_material
402
- * @returns {Uint8Array}
399
+ * @param {Uint8Array} secret
400
+ * @returns {string}
403
401
  */
404
- export function seal(message, sender_secret, recipient_id, nonce_material) {
405
- const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
406
- const len0 = WASM_VECTOR_LEN;
407
- const ptr1 = passStringToWasm0(sender_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
408
- const len1 = WASM_VECTOR_LEN;
409
- const ptr2 = passStringToWasm0(recipient_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
410
- const len2 = WASM_VECTOR_LEN;
411
- const ptr3 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
412
- const len3 = WASM_VECTOR_LEN;
413
- const ret = wasm.seal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
414
- if (ret[3]) {
415
- throw takeFromExternrefTable0(ret[2]);
402
+ export function sign(message, secret) {
403
+ let deferred4_0;
404
+ let deferred4_1;
405
+ try {
406
+ const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
407
+ const len0 = WASM_VECTOR_LEN;
408
+ const ptr1 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
409
+ const len1 = WASM_VECTOR_LEN;
410
+ const ret = wasm.sign(ptr0, len0, ptr1, len1);
411
+ var ptr3 = ret[0];
412
+ var len3 = ret[1];
413
+ if (ret[3]) {
414
+ ptr3 = 0; len3 = 0;
415
+ throw takeFromExternrefTable0(ret[2]);
416
+ }
417
+ deferred4_0 = ptr3;
418
+ deferred4_1 = len3;
419
+ return getStringFromWasm0(ptr3, len3);
420
+ } finally {
421
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
416
422
  }
417
- var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
418
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
419
- return v5;
420
423
  }
421
424
 
422
425
  /**
423
- * WASM-exposed function for unsealing a message using X25519 + XSalsa20-Poly1305.
424
- * Provides authenticated decryption with perfect forward secrecy.
425
- * - `sealed_message`: The sealed bytes to decrypt
426
- * - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
427
- * - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
428
- * - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
429
- * Returns unsealed bytes or throws JsError if unsealing fails.
430
- * @param {Uint8Array} sealed_message
431
- * @param {string} recipient_secret
432
- * @param {string} sender_id
433
- * @param {Uint8Array} nonce_material
434
- * @returns {Uint8Array}
426
+ * WASM-exposed function to verify an Ed25519 signature.
427
+ * - `signature`: Raw signature bytes
428
+ * - `message`: Raw bytes that were signed
429
+ * - `id`: Raw Ed25519 verifying key bytes
430
+ * Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
431
+ * @param {Uint8Array} signature
432
+ * @param {Uint8Array} message
433
+ * @param {Uint8Array} id
434
+ * @returns {boolean}
435
435
  */
436
- export function unseal(sealed_message, recipient_secret, sender_id, nonce_material) {
437
- const ptr0 = passArray8ToWasm0(sealed_message, wasm.__wbindgen_malloc);
436
+ export function verify(signature, message, id) {
437
+ const ptr0 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
438
438
  const len0 = WASM_VECTOR_LEN;
439
- const ptr1 = passStringToWasm0(recipient_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
439
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
440
440
  const len1 = WASM_VECTOR_LEN;
441
- const ptr2 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
441
+ const ptr2 = passArray8ToWasm0(id, wasm.__wbindgen_malloc);
442
442
  const len2 = WASM_VECTOR_LEN;
443
- const ptr3 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
444
- const len3 = WASM_VECTOR_LEN;
445
- const ret = wasm.unseal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
446
- if (ret[3]) {
447
- throw takeFromExternrefTable0(ret[2]);
443
+ const ret = wasm.verify(ptr0, len0, ptr1, len1, ptr2, len2);
444
+ if (ret[2]) {
445
+ throw takeFromExternrefTable0(ret[1]);
448
446
  }
449
- var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
450
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
451
- return v5;
447
+ return ret[0] !== 0;
452
448
  }
453
449
 
454
450
  /**
@@ -507,199 +503,190 @@ export function blake3HashOnceWithContext(data, context) {
507
503
  }
508
504
 
509
505
  /**
510
- * WASM-exposed function to sign a message using Ed25519.
511
- * - `message`: Raw bytes to sign
512
- * - `secret`: Raw Ed25519 signing key bytes
513
- * Returns base58-encoded signature with "signature_z" prefix or throws JsError if signing fails.
514
- * @param {Uint8Array} message
515
- * @param {Uint8Array} secret
516
- * @returns {string}
517
- */
518
- export function sign(message, secret) {
519
- let deferred4_0;
520
- let deferred4_1;
521
- try {
522
- const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
523
- const len0 = WASM_VECTOR_LEN;
524
- const ptr1 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
525
- const len1 = WASM_VECTOR_LEN;
526
- const ret = wasm.sign(ptr0, len0, ptr1, len1);
527
- var ptr3 = ret[0];
528
- var len3 = ret[1];
529
- if (ret[3]) {
530
- ptr3 = 0; len3 = 0;
531
- throw takeFromExternrefTable0(ret[2]);
532
- }
533
- deferred4_0 = ptr3;
534
- deferred4_1 = len3;
535
- return getStringFromWasm0(ptr3, len3);
536
- } finally {
537
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
538
- }
539
- }
540
-
541
- /**
542
- * WASM-exposed function to verify an Ed25519 signature.
543
- * - `signature`: Raw signature bytes
544
- * - `message`: Raw bytes that were signed
545
- * - `id`: Raw Ed25519 verifying key bytes
546
- * Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
547
- * @param {Uint8Array} signature
548
- * @param {Uint8Array} message
549
- * @param {Uint8Array} id
550
- * @returns {boolean}
506
+ * WASM-exposed function for XSalsa20 decryption without authentication.
507
+ * - `key`: 32-byte key for decryption (must match encryption key)
508
+ * - `nonce_material`: Raw bytes used to generate a 24-byte nonce (must match encryption)
509
+ * - `ciphertext`: Encrypted bytes to decrypt
510
+ * Returns the decrypted bytes or throws a JsError if decryption fails.
511
+ * Note: This function does not provide authentication. Use decrypt_xsalsa20_poly1305 for authenticated decryption.
512
+ * @param {Uint8Array} key
513
+ * @param {Uint8Array} nonce_material
514
+ * @param {Uint8Array} ciphertext
515
+ * @returns {Uint8Array}
551
516
  */
552
- export function verify(signature, message, id) {
553
- const ptr0 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
517
+ export function decryptXsalsa20(key, nonce_material, ciphertext) {
518
+ const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
554
519
  const len0 = WASM_VECTOR_LEN;
555
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
520
+ const ptr1 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
556
521
  const len1 = WASM_VECTOR_LEN;
557
- const ptr2 = passArray8ToWasm0(id, wasm.__wbindgen_malloc);
522
+ const ptr2 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
558
523
  const len2 = WASM_VECTOR_LEN;
559
- const ret = wasm.verify(ptr0, len0, ptr1, len1, ptr2, len2);
560
- if (ret[2]) {
561
- throw takeFromExternrefTable0(ret[1]);
562
- }
563
- return ret[0] !== 0;
564
- }
565
-
566
- /**
567
- * WASM-exposed function to derive a signer ID from a signing key.
568
- * - `secret`: Raw Ed25519 signing key bytes
569
- * Returns base58-encoded verifying key with "signer_z" prefix or throws JsError if derivation fails.
570
- * @param {Uint8Array} secret
571
- * @returns {string}
572
- */
573
- export function getSignerId(secret) {
574
- let deferred3_0;
575
- let deferred3_1;
576
- try {
577
- const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
578
- const len0 = WASM_VECTOR_LEN;
579
- const ret = wasm.getSignerId(ptr0, len0);
580
- var ptr2 = ret[0];
581
- var len2 = ret[1];
582
- if (ret[3]) {
583
- ptr2 = 0; len2 = 0;
584
- throw takeFromExternrefTable0(ret[2]);
585
- }
586
- deferred3_0 = ptr2;
587
- deferred3_1 = len2;
588
- return getStringFromWasm0(ptr2, len2);
589
- } finally {
590
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
524
+ const ret = wasm.decryptXsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
525
+ if (ret[3]) {
526
+ throw takeFromExternrefTable0(ret[2]);
591
527
  }
528
+ var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
529
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
530
+ return v4;
592
531
  }
593
532
 
594
533
  /**
595
- * Generate a new Ed25519 signing key using secure random number generation.
596
- * Returns 32 bytes of raw key material suitable for use with other Ed25519 functions.
534
+ * WASM-exposed function for XSalsa20 encryption without authentication.
535
+ * - `key`: 32-byte key for encryption
536
+ * - `nonce_material`: Raw bytes used to generate a 24-byte nonce via BLAKE3
537
+ * - `plaintext`: Raw bytes to encrypt
538
+ * Returns the encrypted bytes or throws a JsError if encryption fails.
539
+ * Note: This function does not provide authentication. Use encrypt_xsalsa20_poly1305 for authenticated encryption.
540
+ * @param {Uint8Array} key
541
+ * @param {Uint8Array} nonce_material
542
+ * @param {Uint8Array} plaintext
597
543
  * @returns {Uint8Array}
598
544
  */
599
- export function newEd25519SigningKey() {
600
- const ret = wasm.newEd25519SigningKey();
601
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
545
+ export function encryptXsalsa20(key, nonce_material, plaintext) {
546
+ const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
547
+ const len0 = WASM_VECTOR_LEN;
548
+ const ptr1 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
549
+ const len1 = WASM_VECTOR_LEN;
550
+ const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
551
+ const len2 = WASM_VECTOR_LEN;
552
+ const ret = wasm.encryptXsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
553
+ if (ret[3]) {
554
+ throw takeFromExternrefTable0(ret[2]);
555
+ }
556
+ var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
602
557
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
603
- return v1;
558
+ return v4;
604
559
  }
605
560
 
606
561
  /**
607
- * WASM-exposed function to derive an Ed25519 verifying key from a signing key.
608
- * - `signing_key`: 32 bytes of signing key material
609
- * Returns 32 bytes of verifying key material or throws JsError if key is invalid.
610
- * @param {Uint8Array} signing_key
562
+ * WASM-exposed function for unsealing a message using X25519 + XSalsa20-Poly1305.
563
+ * Provides authenticated decryption with perfect forward secrecy.
564
+ * - `sealed_message`: The sealed bytes to decrypt
565
+ * - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
566
+ * - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
567
+ * - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
568
+ * Returns unsealed bytes or throws JsError if unsealing fails.
569
+ * @param {Uint8Array} sealed_message
570
+ * @param {string} recipient_secret
571
+ * @param {string} sender_id
572
+ * @param {Uint8Array} nonce_material
611
573
  * @returns {Uint8Array}
612
574
  */
613
- export function ed25519VerifyingKey(signing_key) {
614
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
575
+ export function unseal(sealed_message, recipient_secret, sender_id, nonce_material) {
576
+ const ptr0 = passArray8ToWasm0(sealed_message, wasm.__wbindgen_malloc);
615
577
  const len0 = WASM_VECTOR_LEN;
616
- const ret = wasm.ed25519VerifyingKey(ptr0, len0);
578
+ const ptr1 = passStringToWasm0(recipient_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
579
+ const len1 = WASM_VECTOR_LEN;
580
+ const ptr2 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
581
+ const len2 = WASM_VECTOR_LEN;
582
+ const ptr3 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
583
+ const len3 = WASM_VECTOR_LEN;
584
+ const ret = wasm.unseal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
617
585
  if (ret[3]) {
618
586
  throw takeFromExternrefTable0(ret[2]);
619
587
  }
620
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
588
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
621
589
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
622
- return v2;
590
+ return v5;
623
591
  }
624
592
 
625
593
  /**
626
- * WASM-exposed function to sign a message using Ed25519.
627
- * - `signing_key`: 32 bytes of signing key material
628
- * - `message`: Raw bytes to sign
629
- * Returns 64 bytes of signature material or throws JsError if signing fails.
630
- * @param {Uint8Array} signing_key
594
+ * WASM-exposed function for sealing a message using X25519 + XSalsa20-Poly1305.
595
+ * Provides authenticated encryption with perfect forward secrecy.
596
+ * - `message`: Raw bytes to seal
597
+ * - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
598
+ * - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
599
+ * - `nonce_material`: Raw bytes used to generate the nonce
600
+ * Returns sealed bytes or throws JsError if sealing fails.
631
601
  * @param {Uint8Array} message
602
+ * @param {string} sender_secret
603
+ * @param {string} recipient_id
604
+ * @param {Uint8Array} nonce_material
632
605
  * @returns {Uint8Array}
633
606
  */
634
- export function ed25519Sign(signing_key, message) {
635
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
607
+ export function seal(message, sender_secret, recipient_id, nonce_material) {
608
+ const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
636
609
  const len0 = WASM_VECTOR_LEN;
637
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
610
+ const ptr1 = passStringToWasm0(sender_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
638
611
  const len1 = WASM_VECTOR_LEN;
639
- const ret = wasm.ed25519Sign(ptr0, len0, ptr1, len1);
612
+ const ptr2 = passStringToWasm0(recipient_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
613
+ const len2 = WASM_VECTOR_LEN;
614
+ const ptr3 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
615
+ const len3 = WASM_VECTOR_LEN;
616
+ const ret = wasm.seal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
640
617
  if (ret[3]) {
641
618
  throw takeFromExternrefTable0(ret[2]);
642
619
  }
643
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
620
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
644
621
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
645
- return v3;
622
+ return v5;
646
623
  }
647
624
 
648
625
  /**
649
- * WASM-exposed function to verify an Ed25519 signature.
650
- * - `verifying_key`: 32 bytes of verifying key material
651
- * - `message`: Raw bytes that were signed
652
- * - `signature`: 64 bytes of signature material
653
- * Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
654
- * @param {Uint8Array} verifying_key
655
- * @param {Uint8Array} message
656
- * @param {Uint8Array} signature
657
- * @returns {boolean}
626
+ * WASM-exposed function to encrypt bytes with a key secret and nonce material.
627
+ * - `value`: The raw bytes to encrypt
628
+ * - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
629
+ * - `nonce_material`: Raw bytes used to generate the nonce
630
+ * Returns the encrypted bytes or throws a JsError if encryption fails.
631
+ * @param {Uint8Array} value
632
+ * @param {string} key_secret
633
+ * @param {Uint8Array} nonce_material
634
+ * @returns {Uint8Array}
658
635
  */
659
- export function ed25519Verify(verifying_key, message, signature) {
660
- const ptr0 = passArray8ToWasm0(verifying_key, wasm.__wbindgen_malloc);
636
+ export function encrypt(value, key_secret, nonce_material) {
637
+ const ptr0 = passArray8ToWasm0(value, wasm.__wbindgen_malloc);
661
638
  const len0 = WASM_VECTOR_LEN;
662
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
639
+ const ptr1 = passStringToWasm0(key_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
663
640
  const len1 = WASM_VECTOR_LEN;
664
- const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
641
+ const ptr2 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
665
642
  const len2 = WASM_VECTOR_LEN;
666
- const ret = wasm.ed25519Verify(ptr0, len0, ptr1, len1, ptr2, len2);
667
- if (ret[2]) {
668
- throw takeFromExternrefTable0(ret[1]);
643
+ const ret = wasm.encrypt(ptr0, len0, ptr1, len1, ptr2, len2);
644
+ if (ret[3]) {
645
+ throw takeFromExternrefTable0(ret[2]);
669
646
  }
670
- return ret[0] !== 0;
647
+ var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
648
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
649
+ return v4;
671
650
  }
672
651
 
673
652
  /**
674
- * WASM-exposed function to validate and copy Ed25519 signing key bytes.
675
- * - `bytes`: 32 bytes of signing key material to validate
676
- * Returns the same 32 bytes if valid or throws JsError if invalid.
677
- * @param {Uint8Array} bytes
653
+ * WASM-exposed function to decrypt bytes with a key secret and nonce material.
654
+ * - `ciphertext`: The encrypted bytes to decrypt
655
+ * - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
656
+ * - `nonce_material`: Raw bytes used to generate the nonce (must match encryption)
657
+ * Returns the decrypted bytes or throws a JsError if decryption fails.
658
+ * @param {Uint8Array} ciphertext
659
+ * @param {string} key_secret
660
+ * @param {Uint8Array} nonce_material
678
661
  * @returns {Uint8Array}
679
662
  */
680
- export function ed25519SigningKeyFromBytes(bytes) {
681
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
663
+ export function decrypt(ciphertext, key_secret, nonce_material) {
664
+ const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
682
665
  const len0 = WASM_VECTOR_LEN;
683
- const ret = wasm.ed25519SigningKeyFromBytes(ptr0, len0);
666
+ const ptr1 = passStringToWasm0(key_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
667
+ const len1 = WASM_VECTOR_LEN;
668
+ const ptr2 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
669
+ const len2 = WASM_VECTOR_LEN;
670
+ const ret = wasm.decrypt(ptr0, len0, ptr1, len1, ptr2, len2);
684
671
  if (ret[3]) {
685
672
  throw takeFromExternrefTable0(ret[2]);
686
673
  }
687
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
674
+ var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
688
675
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
689
- return v2;
676
+ return v4;
690
677
  }
691
678
 
692
679
  /**
693
- * WASM-exposed function to derive the public key from an Ed25519 signing key.
694
- * - `signing_key`: 32 bytes of signing key material
680
+ * WASM-exposed function to derive an X25519 public key from a private key.
681
+ * - `private_key`: 32 bytes of private key material
695
682
  * Returns 32 bytes of public key material or throws JsError if key is invalid.
696
- * @param {Uint8Array} signing_key
683
+ * @param {Uint8Array} private_key
697
684
  * @returns {Uint8Array}
698
685
  */
699
- export function ed25519SigningKeyToPublic(signing_key) {
700
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
686
+ export function x25519PublicKey(private_key) {
687
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
701
688
  const len0 = WASM_VECTOR_LEN;
702
- const ret = wasm.ed25519SigningKeyToPublic(ptr0, len0);
689
+ const ret = wasm.x25519PublicKey(ptr0, len0);
703
690
  if (ret[3]) {
704
691
  throw takeFromExternrefTable0(ret[2]);
705
692
  }
@@ -709,20 +696,20 @@ export function ed25519SigningKeyToPublic(signing_key) {
709
696
  }
710
697
 
711
698
  /**
712
- * WASM-exposed function to sign a message with an Ed25519 signing key.
713
- * - `signing_key`: 32 bytes of signing key material
714
- * - `message`: Raw bytes to sign
715
- * Returns 64 bytes of signature material or throws JsError if signing fails.
716
- * @param {Uint8Array} signing_key
717
- * @param {Uint8Array} message
699
+ * WASM-exposed function to perform X25519 Diffie-Hellman key exchange.
700
+ * - `private_key`: 32 bytes of private key material
701
+ * - `public_key`: 32 bytes of public key material
702
+ * Returns 32 bytes of shared secret material or throws JsError if key exchange fails.
703
+ * @param {Uint8Array} private_key
704
+ * @param {Uint8Array} public_key
718
705
  * @returns {Uint8Array}
719
706
  */
720
- export function ed25519SigningKeySign(signing_key, message) {
721
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
707
+ export function x25519DiffieHellman(private_key, public_key) {
708
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
722
709
  const len0 = WASM_VECTOR_LEN;
723
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
710
+ const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
724
711
  const len1 = WASM_VECTOR_LEN;
725
- const ret = wasm.ed25519SigningKeySign(ptr0, len0, ptr1, len1);
712
+ const ret = wasm.x25519DiffieHellman(ptr0, len0, ptr1, len1);
726
713
  if (ret[3]) {
727
714
  throw takeFromExternrefTable0(ret[2]);
728
715
  }
@@ -732,41 +719,44 @@ export function ed25519SigningKeySign(signing_key, message) {
732
719
  }
733
720
 
734
721
  /**
735
- * WASM-exposed function to validate and copy Ed25519 verifying key bytes.
736
- * - `bytes`: 32 bytes of verifying key material to validate
737
- * Returns the same 32 bytes if valid or throws JsError if invalid.
738
- * @param {Uint8Array} bytes
739
- * @returns {Uint8Array}
722
+ * WASM-exposed function to derive a sealer ID from a sealer secret.
723
+ * - `secret`: Raw bytes of the sealer secret
724
+ * Returns a base58-encoded sealer ID with "sealer_z" prefix or throws JsError if derivation fails.
725
+ * @param {Uint8Array} secret
726
+ * @returns {string}
740
727
  */
741
- export function ed25519VerifyingKeyFromBytes(bytes) {
742
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
743
- const len0 = WASM_VECTOR_LEN;
744
- const ret = wasm.ed25519VerifyingKeyFromBytes(ptr0, len0);
745
- if (ret[3]) {
746
- throw takeFromExternrefTable0(ret[2]);
728
+ export function getSealerId(secret) {
729
+ let deferred3_0;
730
+ let deferred3_1;
731
+ try {
732
+ const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
733
+ const len0 = WASM_VECTOR_LEN;
734
+ const ret = wasm.getSealerId(ptr0, len0);
735
+ var ptr2 = ret[0];
736
+ var len2 = ret[1];
737
+ if (ret[3]) {
738
+ ptr2 = 0; len2 = 0;
739
+ throw takeFromExternrefTable0(ret[2]);
740
+ }
741
+ deferred3_0 = ptr2;
742
+ deferred3_1 = len2;
743
+ return getStringFromWasm0(ptr2, len2);
744
+ } finally {
745
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
747
746
  }
748
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
749
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
750
- return v2;
751
747
  }
752
748
 
753
749
  /**
754
- * WASM-exposed function to validate and copy Ed25519 signature bytes.
755
- * - `bytes`: 64 bytes of signature material to validate
756
- * Returns the same 64 bytes if valid or throws JsError if invalid.
757
- * @param {Uint8Array} bytes
750
+ * Generate a new X25519 private key using secure random number generation.
751
+ * Returns 32 bytes of raw key material suitable for use with other X25519 functions.
752
+ * This key can be reused for multiple Diffie-Hellman exchanges.
758
753
  * @returns {Uint8Array}
759
754
  */
760
- export function ed25519SignatureFromBytes(bytes) {
761
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
762
- const len0 = WASM_VECTOR_LEN;
763
- const ret = wasm.ed25519SignatureFromBytes(ptr0, len0);
764
- if (ret[3]) {
765
- throw takeFromExternrefTable0(ret[2]);
766
- }
767
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
755
+ export function newX25519PrivateKey() {
756
+ const ret = wasm.newX25519PrivateKey();
757
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
768
758
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
769
- return v2;
759
+ return v1;
770
760
  }
771
761
 
772
762
  const Blake3HasherFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -800,6 +790,13 @@ export class Blake3Hasher {
800
790
  Blake3HasherFinalization.register(this, this.__wbg_ptr, this);
801
791
  return this;
802
792
  }
793
+ /**
794
+ * @returns {Blake3Hasher}
795
+ */
796
+ clone() {
797
+ const ret = wasm.blake3hasher_clone(this.__wbg_ptr);
798
+ return Blake3Hasher.__wrap(ret);
799
+ }
803
800
  /**
804
801
  * @param {Uint8Array} data
805
802
  */
@@ -817,13 +814,6 @@ export class Blake3Hasher {
817
814
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
818
815
  return v1;
819
816
  }
820
- /**
821
- * @returns {Blake3Hasher}
822
- */
823
- clone() {
824
- const ret = wasm.blake3hasher_clone(this.__wbg_ptr);
825
- return Blake3Hasher.__wrap(ret);
826
- }
827
817
  }
828
818
 
829
819
  const SessionLogFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -852,40 +842,16 @@ export class SessionLog {
852
842
  wasm.__wbg_sessionlog_free(ptr, 0);
853
843
  }
854
844
  /**
855
- * @param {string} co_id
856
- * @param {string} session_id
857
- * @param {string | null} [signer_id]
858
- */
859
- constructor(co_id, session_id, signer_id) {
860
- const ptr0 = passStringToWasm0(co_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
861
- const len0 = WASM_VECTOR_LEN;
862
- const ptr1 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
863
- const len1 = WASM_VECTOR_LEN;
864
- var ptr2 = isLikeNone(signer_id) ? 0 : passStringToWasm0(signer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
865
- var len2 = WASM_VECTOR_LEN;
866
- const ret = wasm.sessionlog_new(ptr0, len0, ptr1, len1, ptr2, len2);
867
- this.__wbg_ptr = ret >>> 0;
868
- SessionLogFinalization.register(this, this.__wbg_ptr, this);
869
- return this;
870
- }
871
- /**
872
- * @returns {SessionLog}
873
- */
874
- clone() {
875
- const ret = wasm.sessionlog_clone(this.__wbg_ptr);
876
- return SessionLog.__wrap(ret);
877
- }
878
- /**
879
- * @param {string[]} transactions_json
845
+ * Commit pending transactions to the main state.
846
+ * If skip_validate is false, validates the signature first.
847
+ * If skip_validate is true, commits without validation.
880
848
  * @param {string} new_signature_str
881
- * @param {boolean} skip_verify
849
+ * @param {boolean} skip_validate
882
850
  */
883
- tryAdd(transactions_json, new_signature_str, skip_verify) {
884
- const ptr0 = passArrayJsValueToWasm0(transactions_json, wasm.__wbindgen_malloc);
851
+ commitTransactions(new_signature_str, skip_validate) {
852
+ const ptr0 = passStringToWasm0(new_signature_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
885
853
  const len0 = WASM_VECTOR_LEN;
886
- const ptr1 = passStringToWasm0(new_signature_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
887
- const len1 = WASM_VECTOR_LEN;
888
- const ret = wasm.sessionlog_tryAdd(this.__wbg_ptr, ptr0, len0, ptr1, len1, skip_verify);
854
+ const ret = wasm.sessionlog_commitTransactions(this.__wbg_ptr, ptr0, len0, skip_validate);
889
855
  if (ret[1]) {
890
856
  throw takeFromExternrefTable0(ret[0]);
891
857
  }
@@ -958,6 +924,64 @@ export class SessionLog {
958
924
  wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
959
925
  }
960
926
  }
927
+ /**
928
+ * Add an existing private transaction to the staging area.
929
+ * The transaction is NOT committed until commitTransactions() succeeds.
930
+ * Note: made_at uses f64 because JavaScript's number type is f64.
931
+ * @param {string} encrypted_changes
932
+ * @param {string} key_used
933
+ * @param {number} made_at
934
+ * @param {string | null} [meta]
935
+ */
936
+ addExistingPrivateTransaction(encrypted_changes, key_used, made_at, meta) {
937
+ const ptr0 = passStringToWasm0(encrypted_changes, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
938
+ const len0 = WASM_VECTOR_LEN;
939
+ const ptr1 = passStringToWasm0(key_used, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
940
+ const len1 = WASM_VECTOR_LEN;
941
+ var ptr2 = isLikeNone(meta) ? 0 : passStringToWasm0(meta, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
942
+ var len2 = WASM_VECTOR_LEN;
943
+ const ret = wasm.sessionlog_addExistingPrivateTransaction(this.__wbg_ptr, ptr0, len0, ptr1, len1, made_at, ptr2, len2);
944
+ if (ret[1]) {
945
+ throw takeFromExternrefTable0(ret[0]);
946
+ }
947
+ }
948
+ /**
949
+ * Add an existing trusting transaction to the staging area.
950
+ * The transaction is NOT committed until commitTransactions() succeeds.
951
+ * Note: made_at uses f64 because JavaScript's number type is f64.
952
+ * @param {string} changes
953
+ * @param {number} made_at
954
+ * @param {string | null} [meta]
955
+ */
956
+ addExistingTrustingTransaction(changes, made_at, meta) {
957
+ const ptr0 = passStringToWasm0(changes, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
958
+ const len0 = WASM_VECTOR_LEN;
959
+ var ptr1 = isLikeNone(meta) ? 0 : passStringToWasm0(meta, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
960
+ var len1 = WASM_VECTOR_LEN;
961
+ const ret = wasm.sessionlog_addExistingTrustingTransaction(this.__wbg_ptr, ptr0, len0, made_at, ptr1, len1);
962
+ if (ret[1]) {
963
+ throw takeFromExternrefTable0(ret[0]);
964
+ }
965
+ }
966
+ /**
967
+ * @param {number} tx_index
968
+ * @param {string} encryption_key
969
+ * @returns {string | undefined}
970
+ */
971
+ decryptNextTransactionMetaJson(tx_index, encryption_key) {
972
+ const ptr0 = passStringToWasm0(encryption_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
973
+ const len0 = WASM_VECTOR_LEN;
974
+ const ret = wasm.sessionlog_decryptNextTransactionMetaJson(this.__wbg_ptr, tx_index, ptr0, len0);
975
+ if (ret[3]) {
976
+ throw takeFromExternrefTable0(ret[2]);
977
+ }
978
+ let v2;
979
+ if (ret[0] !== 0) {
980
+ v2 = getStringFromWasm0(ret[0], ret[1]).slice();
981
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
982
+ }
983
+ return v2;
984
+ }
961
985
  /**
962
986
  * @param {number} tx_index
963
987
  * @param {string} encryption_key
@@ -984,23 +1008,28 @@ export class SessionLog {
984
1008
  }
985
1009
  }
986
1010
  /**
987
- * @param {number} tx_index
988
- * @param {string} encryption_key
989
- * @returns {string | undefined}
1011
+ * @param {string} co_id
1012
+ * @param {string} session_id
1013
+ * @param {string | null} [signer_id]
990
1014
  */
991
- decryptNextTransactionMetaJson(tx_index, encryption_key) {
992
- const ptr0 = passStringToWasm0(encryption_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1015
+ constructor(co_id, session_id, signer_id) {
1016
+ const ptr0 = passStringToWasm0(co_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
993
1017
  const len0 = WASM_VECTOR_LEN;
994
- const ret = wasm.sessionlog_decryptNextTransactionMetaJson(this.__wbg_ptr, tx_index, ptr0, len0);
995
- if (ret[3]) {
996
- throw takeFromExternrefTable0(ret[2]);
997
- }
998
- let v2;
999
- if (ret[0] !== 0) {
1000
- v2 = getStringFromWasm0(ret[0], ret[1]).slice();
1001
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
1002
- }
1003
- return v2;
1018
+ const ptr1 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1019
+ const len1 = WASM_VECTOR_LEN;
1020
+ var ptr2 = isLikeNone(signer_id) ? 0 : passStringToWasm0(signer_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1021
+ var len2 = WASM_VECTOR_LEN;
1022
+ const ret = wasm.sessionlog_new(ptr0, len0, ptr1, len1, ptr2, len2);
1023
+ this.__wbg_ptr = ret >>> 0;
1024
+ SessionLogFinalization.register(this, this.__wbg_ptr, this);
1025
+ return this;
1026
+ }
1027
+ /**
1028
+ * @returns {SessionLog}
1029
+ */
1030
+ clone() {
1031
+ const ret = wasm.sessionlog_clone(this.__wbg_ptr);
1032
+ return SessionLog.__wrap(ret);
1004
1033
  }
1005
1034
  }
1006
1035
 
@@ -1168,14 +1197,6 @@ function __wbg_get_imports() {
1168
1197
  const ret = wasm.memory;
1169
1198
  return ret;
1170
1199
  };
1171
- imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
1172
- const obj = arg1;
1173
- const ret = typeof(obj) === 'string' ? obj : undefined;
1174
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1175
- var len1 = WASM_VECTOR_LEN;
1176
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1177
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1178
- };
1179
1200
  imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
1180
1201
  const ret = getStringFromWasm0(arg0, arg1);
1181
1202
  return ret;