cojson-core-wasm 0.18.21 → 0.18.23

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.
@@ -206,14 +206,14 @@ function getArrayU8FromWasm0(ptr, len) {
206
206
  * @param {Uint8Array} plaintext
207
207
  * @returns {Uint8Array}
208
208
  */
209
- export function encrypt_xsalsa20(key, nonce_material, plaintext) {
209
+ export function encryptXsalsa20(key, nonce_material, plaintext) {
210
210
  const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
211
211
  const len0 = WASM_VECTOR_LEN;
212
212
  const ptr1 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
213
213
  const len1 = WASM_VECTOR_LEN;
214
214
  const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
215
215
  const len2 = WASM_VECTOR_LEN;
216
- const ret = wasm.encrypt_xsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
216
+ const ret = wasm.encryptXsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
217
217
  if (ret[3]) {
218
218
  throw takeFromExternrefTable0(ret[2]);
219
219
  }
@@ -234,14 +234,14 @@ export function encrypt_xsalsa20(key, nonce_material, plaintext) {
234
234
  * @param {Uint8Array} ciphertext
235
235
  * @returns {Uint8Array}
236
236
  */
237
- export function decrypt_xsalsa20(key, nonce_material, ciphertext) {
237
+ export function decryptXsalsa20(key, nonce_material, ciphertext) {
238
238
  const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
239
239
  const len0 = WASM_VECTOR_LEN;
240
240
  const ptr1 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
241
241
  const len1 = WASM_VECTOR_LEN;
242
242
  const ptr2 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
243
243
  const len2 = WASM_VECTOR_LEN;
244
- const ret = wasm.decrypt_xsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
244
+ const ret = wasm.decryptXsalsa20(ptr0, len0, ptr1, len1, ptr2, len2);
245
245
  if (ret[3]) {
246
246
  throw takeFromExternrefTable0(ret[2]);
247
247
  }
@@ -251,28 +251,29 @@ export function decrypt_xsalsa20(key, nonce_material, ciphertext) {
251
251
  }
252
252
 
253
253
  /**
254
- * Generate a new Ed25519 signing key using secure random number generation.
255
- * Returns 32 bytes of raw key material suitable for use with other Ed25519 functions.
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.
256
257
  * @returns {Uint8Array}
257
258
  */
258
- export function new_ed25519_signing_key() {
259
- const ret = wasm.new_ed25519_signing_key();
259
+ export function newX25519PrivateKey() {
260
+ const ret = wasm.newX25519PrivateKey();
260
261
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
261
262
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
262
263
  return v1;
263
264
  }
264
265
 
265
266
  /**
266
- * WASM-exposed function to derive an Ed25519 verifying key from a signing key.
267
- * - `signing_key`: 32 bytes of signing key material
268
- * Returns 32 bytes of verifying key material or throws JsError if key is invalid.
269
- * @param {Uint8Array} signing_key
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
270
271
  * @returns {Uint8Array}
271
272
  */
272
- export function ed25519_verifying_key(signing_key) {
273
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
273
+ export function x25519PublicKey(private_key) {
274
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
274
275
  const len0 = WASM_VECTOR_LEN;
275
- const ret = wasm.ed25519_verifying_key(ptr0, len0);
276
+ const ret = wasm.x25519PublicKey(ptr0, len0);
276
277
  if (ret[3]) {
277
278
  throw takeFromExternrefTable0(ret[2]);
278
279
  }
@@ -282,20 +283,20 @@ export function ed25519_verifying_key(signing_key) {
282
283
  }
283
284
 
284
285
  /**
285
- * WASM-exposed function to sign a message using Ed25519.
286
- * - `signing_key`: 32 bytes of signing key material
287
- * - `message`: Raw bytes to sign
288
- * Returns 64 bytes of signature material or throws JsError if signing fails.
289
- * @param {Uint8Array} signing_key
290
- * @param {Uint8Array} message
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
291
292
  * @returns {Uint8Array}
292
293
  */
293
- export function ed25519_sign(signing_key, message) {
294
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
294
+ export function x25519DiffieHellman(private_key, public_key) {
295
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
295
296
  const len0 = WASM_VECTOR_LEN;
296
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
297
+ const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
297
298
  const len1 = WASM_VECTOR_LEN;
298
- const ret = wasm.ed25519_sign(ptr0, len0, ptr1, len1);
299
+ const ret = wasm.x25519DiffieHellman(ptr0, len0, ptr1, len1);
299
300
  if (ret[3]) {
300
301
  throw takeFromExternrefTable0(ret[2]);
301
302
  }
@@ -305,129 +306,206 @@ export function ed25519_sign(signing_key, message) {
305
306
  }
306
307
 
307
308
  /**
308
- * WASM-exposed function to verify an Ed25519 signature.
309
- * - `verifying_key`: 32 bytes of verifying key material
310
- * - `message`: Raw bytes that were signed
311
- * - `signature`: 64 bytes of signature material
312
- * Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
313
- * @param {Uint8Array} verifying_key
314
- * @param {Uint8Array} message
315
- * @param {Uint8Array} signature
316
- * @returns {boolean}
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.
312
+ * @param {Uint8Array} secret
313
+ * @returns {string}
317
314
  */
318
- export function ed25519_verify(verifying_key, message, signature) {
319
- const ptr0 = passArray8ToWasm0(verifying_key, wasm.__wbindgen_malloc);
320
- const len0 = WASM_VECTOR_LEN;
321
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
322
- const len1 = WASM_VECTOR_LEN;
323
- const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
324
- const len2 = WASM_VECTOR_LEN;
325
- const ret = wasm.ed25519_verify(ptr0, len0, ptr1, len1, ptr2, len2);
326
- if (ret[2]) {
327
- throw takeFromExternrefTable0(ret[1]);
315
+ export function getSealerId(secret) {
316
+ let deferred3_0;
317
+ let deferred3_1;
318
+ try {
319
+ const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
320
+ const len0 = WASM_VECTOR_LEN;
321
+ const ret = wasm.getSealerId(ptr0, len0);
322
+ var ptr2 = ret[0];
323
+ var len2 = ret[1];
324
+ if (ret[3]) {
325
+ ptr2 = 0; len2 = 0;
326
+ throw takeFromExternrefTable0(ret[2]);
327
+ }
328
+ deferred3_0 = ptr2;
329
+ deferred3_1 = len2;
330
+ return getStringFromWasm0(ptr2, len2);
331
+ } finally {
332
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
328
333
  }
329
- return ret[0] !== 0;
330
334
  }
331
335
 
332
336
  /**
333
- * WASM-exposed function to validate and copy Ed25519 signing key bytes.
334
- * - `bytes`: 32 bytes of signing key material to validate
335
- * Returns the same 32 bytes if valid or throws JsError if invalid.
336
- * @param {Uint8Array} bytes
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
337
345
  * @returns {Uint8Array}
338
346
  */
339
- export function ed25519_signing_key_from_bytes(bytes) {
340
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
347
+ export function encrypt(value, key_secret, nonce_material) {
348
+ const ptr0 = passArray8ToWasm0(value, wasm.__wbindgen_malloc);
341
349
  const len0 = WASM_VECTOR_LEN;
342
- const ret = wasm.ed25519_signing_key_from_bytes(ptr0, len0);
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);
343
355
  if (ret[3]) {
344
356
  throw takeFromExternrefTable0(ret[2]);
345
357
  }
346
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
358
+ var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
347
359
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
348
- return v2;
360
+ return v4;
349
361
  }
350
362
 
351
363
  /**
352
- * WASM-exposed function to derive the public key from an Ed25519 signing key.
353
- * - `signing_key`: 32 bytes of signing key material
354
- * Returns 32 bytes of public key material or throws JsError if key is invalid.
355
- * @param {Uint8Array} signing_key
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
356
372
  * @returns {Uint8Array}
357
373
  */
358
- export function ed25519_signing_key_to_public(signing_key) {
359
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
374
+ export function decrypt(ciphertext, key_secret, nonce_material) {
375
+ const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
360
376
  const len0 = WASM_VECTOR_LEN;
361
- const ret = wasm.ed25519_signing_key_to_public(ptr0, len0);
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);
362
382
  if (ret[3]) {
363
383
  throw takeFromExternrefTable0(ret[2]);
364
384
  }
365
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
385
+ var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
366
386
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
367
- return v2;
387
+ return v4;
368
388
  }
369
389
 
370
390
  /**
371
- * WASM-exposed function to sign a message with an Ed25519 signing key.
372
- * - `signing_key`: 32 bytes of signing key material
373
- * - `message`: Raw bytes to sign
374
- * Returns 64 bytes of signature material or throws JsError if signing fails.
375
- * @param {Uint8Array} signing_key
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.
376
398
  * @param {Uint8Array} message
399
+ * @param {string} sender_secret
400
+ * @param {string} recipient_id
401
+ * @param {Uint8Array} nonce_material
377
402
  * @returns {Uint8Array}
378
403
  */
379
- export function ed25519_signing_key_sign(signing_key, message) {
380
- const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
404
+ export function seal(message, sender_secret, recipient_id, nonce_material) {
405
+ const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
381
406
  const len0 = WASM_VECTOR_LEN;
382
- const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
407
+ const ptr1 = passStringToWasm0(sender_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
383
408
  const len1 = WASM_VECTOR_LEN;
384
- const ret = wasm.ed25519_signing_key_sign(ptr0, len0, ptr1, len1);
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);
385
414
  if (ret[3]) {
386
415
  throw takeFromExternrefTable0(ret[2]);
387
416
  }
388
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
417
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
389
418
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
390
- return v3;
419
+ return v5;
391
420
  }
392
421
 
393
422
  /**
394
- * WASM-exposed function to validate and copy Ed25519 verifying key bytes.
395
- * - `bytes`: 32 bytes of verifying key material to validate
396
- * Returns the same 32 bytes if valid or throws JsError if invalid.
397
- * @param {Uint8Array} bytes
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
398
434
  * @returns {Uint8Array}
399
435
  */
400
- export function ed25519_verifying_key_from_bytes(bytes) {
401
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
436
+ export function unseal(sealed_message, recipient_secret, sender_id, nonce_material) {
437
+ const ptr0 = passArray8ToWasm0(sealed_message, wasm.__wbindgen_malloc);
402
438
  const len0 = WASM_VECTOR_LEN;
403
- const ret = wasm.ed25519_verifying_key_from_bytes(ptr0, len0);
439
+ const ptr1 = passStringToWasm0(recipient_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
440
+ const len1 = WASM_VECTOR_LEN;
441
+ const ptr2 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
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);
404
446
  if (ret[3]) {
405
447
  throw takeFromExternrefTable0(ret[2]);
406
448
  }
449
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
450
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
451
+ return v5;
452
+ }
453
+
454
+ /**
455
+ * Generate a 24-byte nonce from input material using BLAKE3.
456
+ * - `nonce_material`: Raw bytes to derive the nonce from
457
+ * Returns 24 bytes suitable for use as a nonce in cryptographic operations.
458
+ * This function is deterministic - the same input will produce the same nonce.
459
+ * @param {Uint8Array} nonce_material
460
+ * @returns {Uint8Array}
461
+ */
462
+ export function generateNonce(nonce_material) {
463
+ const ptr0 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
464
+ const len0 = WASM_VECTOR_LEN;
465
+ const ret = wasm.generateNonce(ptr0, len0);
407
466
  var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
408
467
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
409
468
  return v2;
410
469
  }
411
470
 
412
471
  /**
413
- * WASM-exposed function to validate and copy Ed25519 signature bytes.
414
- * - `bytes`: 64 bytes of signature material to validate
415
- * Returns the same 64 bytes if valid or throws JsError if invalid.
416
- * @param {Uint8Array} bytes
472
+ * Hash data once using BLAKE3.
473
+ * - `data`: Raw bytes to hash
474
+ * Returns 32 bytes of hash output.
475
+ * This is the simplest way to compute a BLAKE3 hash of a single piece of data.
476
+ * @param {Uint8Array} data
417
477
  * @returns {Uint8Array}
418
478
  */
419
- export function ed25519_signature_from_bytes(bytes) {
420
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
479
+ export function blake3HashOnce(data) {
480
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
421
481
  const len0 = WASM_VECTOR_LEN;
422
- const ret = wasm.ed25519_signature_from_bytes(ptr0, len0);
423
- if (ret[3]) {
424
- throw takeFromExternrefTable0(ret[2]);
425
- }
482
+ const ret = wasm.blake3HashOnce(ptr0, len0);
426
483
  var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
427
484
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
428
485
  return v2;
429
486
  }
430
487
 
488
+ /**
489
+ * Hash data once using BLAKE3 with a context prefix.
490
+ * - `data`: Raw bytes to hash
491
+ * - `context`: Context bytes to prefix to the data
492
+ * Returns 32 bytes of hash output.
493
+ * This is useful for domain separation - the same data hashed with different contexts will produce different outputs.
494
+ * @param {Uint8Array} data
495
+ * @param {Uint8Array} context
496
+ * @returns {Uint8Array}
497
+ */
498
+ export function blake3HashOnceWithContext(data, context) {
499
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
500
+ const len0 = WASM_VECTOR_LEN;
501
+ const ptr1 = passArray8ToWasm0(context, wasm.__wbindgen_malloc);
502
+ const len1 = WASM_VECTOR_LEN;
503
+ const ret = wasm.blake3HashOnceWithContext(ptr0, len0, ptr1, len1);
504
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
505
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
506
+ return v3;
507
+ }
508
+
431
509
  /**
432
510
  * WASM-exposed function to sign a message using Ed25519.
433
511
  * - `message`: Raw bytes to sign
@@ -492,13 +570,13 @@ export function verify(signature, message, id) {
492
570
  * @param {Uint8Array} secret
493
571
  * @returns {string}
494
572
  */
495
- export function get_signer_id(secret) {
573
+ export function getSignerId(secret) {
496
574
  let deferred3_0;
497
575
  let deferred3_1;
498
576
  try {
499
577
  const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
500
578
  const len0 = WASM_VECTOR_LEN;
501
- const ret = wasm.get_signer_id(ptr0, len0);
579
+ const ret = wasm.getSignerId(ptr0, len0);
502
580
  var ptr2 = ret[0];
503
581
  var len2 = ret[1];
504
582
  if (ret[3]) {
@@ -514,29 +592,28 @@ export function get_signer_id(secret) {
514
592
  }
515
593
 
516
594
  /**
517
- * Generate a new X25519 private key using secure random number generation.
518
- * Returns 32 bytes of raw key material suitable for use with other X25519 functions.
519
- * This key can be reused for multiple Diffie-Hellman exchanges.
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.
520
597
  * @returns {Uint8Array}
521
598
  */
522
- export function new_x25519_private_key() {
523
- const ret = wasm.new_x25519_private_key();
599
+ export function newEd25519SigningKey() {
600
+ const ret = wasm.newEd25519SigningKey();
524
601
  var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
525
602
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
526
603
  return v1;
527
604
  }
528
605
 
529
606
  /**
530
- * WASM-exposed function to derive an X25519 public key from a private key.
531
- * - `private_key`: 32 bytes of private key material
532
- * Returns 32 bytes of public key material or throws JsError if key is invalid.
533
- * @param {Uint8Array} private_key
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
534
611
  * @returns {Uint8Array}
535
612
  */
536
- export function x25519_public_key(private_key) {
537
- const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
613
+ export function ed25519VerifyingKey(signing_key) {
614
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
538
615
  const len0 = WASM_VECTOR_LEN;
539
- const ret = wasm.x25519_public_key(ptr0, len0);
616
+ const ret = wasm.ed25519VerifyingKey(ptr0, len0);
540
617
  if (ret[3]) {
541
618
  throw takeFromExternrefTable0(ret[2]);
542
619
  }
@@ -546,20 +623,20 @@ export function x25519_public_key(private_key) {
546
623
  }
547
624
 
548
625
  /**
549
- * WASM-exposed function to perform X25519 Diffie-Hellman key exchange.
550
- * - `private_key`: 32 bytes of private key material
551
- * - `public_key`: 32 bytes of public key material
552
- * Returns 32 bytes of shared secret material or throws JsError if key exchange fails.
553
- * @param {Uint8Array} private_key
554
- * @param {Uint8Array} public_key
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
631
+ * @param {Uint8Array} message
555
632
  * @returns {Uint8Array}
556
633
  */
557
- export function x25519_diffie_hellman(private_key, public_key) {
558
- const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
634
+ export function ed25519Sign(signing_key, message) {
635
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
559
636
  const len0 = WASM_VECTOR_LEN;
560
- const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
637
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
561
638
  const len1 = WASM_VECTOR_LEN;
562
- const ret = wasm.x25519_diffie_hellman(ptr0, len0, ptr1, len1);
639
+ const ret = wasm.ed25519Sign(ptr0, len0, ptr1, len1);
563
640
  if (ret[3]) {
564
641
  throw takeFromExternrefTable0(ret[2]);
565
642
  }
@@ -569,251 +646,127 @@ export function x25519_diffie_hellman(private_key, public_key) {
569
646
  }
570
647
 
571
648
  /**
572
- * WASM-exposed function to derive a sealer ID from a sealer secret.
573
- * - `secret`: Raw bytes of the sealer secret
574
- * Returns a base58-encoded sealer ID with "sealer_z" prefix or throws JsError if derivation fails.
575
- * @param {Uint8Array} secret
576
- * @returns {string}
577
- */
578
- export function get_sealer_id(secret) {
579
- let deferred3_0;
580
- let deferred3_1;
581
- try {
582
- const ptr0 = passArray8ToWasm0(secret, wasm.__wbindgen_malloc);
583
- const len0 = WASM_VECTOR_LEN;
584
- const ret = wasm.get_sealer_id(ptr0, len0);
585
- var ptr2 = ret[0];
586
- var len2 = ret[1];
587
- if (ret[3]) {
588
- ptr2 = 0; len2 = 0;
589
- throw takeFromExternrefTable0(ret[2]);
590
- }
591
- deferred3_0 = ptr2;
592
- deferred3_1 = len2;
593
- return getStringFromWasm0(ptr2, len2);
594
- } finally {
595
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
596
- }
597
- }
598
-
599
- /**
600
- * WASM-exposed function for sealing a message using X25519 + XSalsa20-Poly1305.
601
- * Provides authenticated encryption with perfect forward secrecy.
602
- * - `message`: Raw bytes to seal
603
- * - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
604
- * - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
605
- * - `nonce_material`: Raw bytes used to generate the nonce
606
- * Returns sealed bytes or throws JsError if sealing fails.
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
607
655
  * @param {Uint8Array} message
608
- * @param {string} sender_secret
609
- * @param {string} recipient_id
610
- * @param {Uint8Array} nonce_material
611
- * @returns {Uint8Array}
656
+ * @param {Uint8Array} signature
657
+ * @returns {boolean}
612
658
  */
613
- export function seal(message, sender_secret, recipient_id, nonce_material) {
614
- const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
659
+ export function ed25519Verify(verifying_key, message, signature) {
660
+ const ptr0 = passArray8ToWasm0(verifying_key, wasm.__wbindgen_malloc);
615
661
  const len0 = WASM_VECTOR_LEN;
616
- const ptr1 = passStringToWasm0(sender_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
662
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
617
663
  const len1 = WASM_VECTOR_LEN;
618
- const ptr2 = passStringToWasm0(recipient_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
664
+ const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
619
665
  const len2 = WASM_VECTOR_LEN;
620
- const ptr3 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
621
- const len3 = WASM_VECTOR_LEN;
622
- const ret = wasm.seal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
623
- if (ret[3]) {
624
- throw takeFromExternrefTable0(ret[2]);
666
+ const ret = wasm.ed25519Verify(ptr0, len0, ptr1, len1, ptr2, len2);
667
+ if (ret[2]) {
668
+ throw takeFromExternrefTable0(ret[1]);
625
669
  }
626
- var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
627
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
628
- return v5;
670
+ return ret[0] !== 0;
629
671
  }
630
672
 
631
673
  /**
632
- * WASM-exposed function for unsealing a message using X25519 + XSalsa20-Poly1305.
633
- * Provides authenticated decryption with perfect forward secrecy.
634
- * - `sealed_message`: The sealed bytes to decrypt
635
- * - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
636
- * - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
637
- * - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
638
- * Returns unsealed bytes or throws JsError if unsealing fails.
639
- * @param {Uint8Array} sealed_message
640
- * @param {string} recipient_secret
641
- * @param {string} sender_id
642
- * @param {Uint8Array} nonce_material
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
643
678
  * @returns {Uint8Array}
644
679
  */
645
- export function unseal(sealed_message, recipient_secret, sender_id, nonce_material) {
646
- const ptr0 = passArray8ToWasm0(sealed_message, wasm.__wbindgen_malloc);
680
+ export function ed25519SigningKeyFromBytes(bytes) {
681
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
647
682
  const len0 = WASM_VECTOR_LEN;
648
- const ptr1 = passStringToWasm0(recipient_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
649
- const len1 = WASM_VECTOR_LEN;
650
- const ptr2 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
651
- const len2 = WASM_VECTOR_LEN;
652
- const ptr3 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
653
- const len3 = WASM_VECTOR_LEN;
654
- const ret = wasm.unseal(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
683
+ const ret = wasm.ed25519SigningKeyFromBytes(ptr0, len0);
655
684
  if (ret[3]) {
656
685
  throw takeFromExternrefTable0(ret[2]);
657
686
  }
658
- var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
659
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
660
- return v5;
661
- }
662
-
663
- /**
664
- * Generate a 24-byte nonce from input material using BLAKE3.
665
- * - `nonce_material`: Raw bytes to derive the nonce from
666
- * Returns 24 bytes suitable for use as a nonce in cryptographic operations.
667
- * This function is deterministic - the same input will produce the same nonce.
668
- * @param {Uint8Array} nonce_material
669
- * @returns {Uint8Array}
670
- */
671
- export function generate_nonce(nonce_material) {
672
- const ptr0 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
673
- const len0 = WASM_VECTOR_LEN;
674
- const ret = wasm.generate_nonce(ptr0, len0);
675
687
  var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
676
688
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
677
689
  return v2;
678
690
  }
679
691
 
680
692
  /**
681
- * Hash data once using BLAKE3.
682
- * - `data`: Raw bytes to hash
683
- * Returns 32 bytes of hash output.
684
- * This is the simplest way to compute a BLAKE3 hash of a single piece of data.
685
- * @param {Uint8Array} data
693
+ * WASM-exposed function to derive the public key from an Ed25519 signing key.
694
+ * - `signing_key`: 32 bytes of signing key material
695
+ * Returns 32 bytes of public key material or throws JsError if key is invalid.
696
+ * @param {Uint8Array} signing_key
686
697
  * @returns {Uint8Array}
687
698
  */
688
- export function blake3_hash_once(data) {
689
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
699
+ export function ed25519SigningKeyToPublic(signing_key) {
700
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
690
701
  const len0 = WASM_VECTOR_LEN;
691
- const ret = wasm.blake3_hash_once(ptr0, len0);
702
+ const ret = wasm.ed25519SigningKeyToPublic(ptr0, len0);
703
+ if (ret[3]) {
704
+ throw takeFromExternrefTable0(ret[2]);
705
+ }
692
706
  var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
693
707
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
694
708
  return v2;
695
709
  }
696
710
 
697
711
  /**
698
- * Hash data once using BLAKE3 with a context prefix.
699
- * - `data`: Raw bytes to hash
700
- * - `context`: Context bytes to prefix to the data
701
- * Returns 32 bytes of hash output.
702
- * This is useful for domain separation - the same data hashed with different contexts will produce different outputs.
703
- * @param {Uint8Array} data
704
- * @param {Uint8Array} context
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
705
718
  * @returns {Uint8Array}
706
719
  */
707
- export function blake3_hash_once_with_context(data, context) {
708
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
720
+ export function ed25519SigningKeySign(signing_key, message) {
721
+ const ptr0 = passArray8ToWasm0(signing_key, wasm.__wbindgen_malloc);
709
722
  const len0 = WASM_VECTOR_LEN;
710
- const ptr1 = passArray8ToWasm0(context, wasm.__wbindgen_malloc);
723
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
711
724
  const len1 = WASM_VECTOR_LEN;
712
- const ret = wasm.blake3_hash_once_with_context(ptr0, len0, ptr1, len1);
725
+ const ret = wasm.ed25519SigningKeySign(ptr0, len0, ptr1, len1);
726
+ if (ret[3]) {
727
+ throw takeFromExternrefTable0(ret[2]);
728
+ }
713
729
  var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
714
730
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
715
731
  return v3;
716
732
  }
717
733
 
718
734
  /**
719
- * Get an empty BLAKE3 state for incremental hashing.
720
- * Returns a new Blake3Hasher instance for incremental hashing.
721
- * @returns {Blake3Hasher}
722
- */
723
- export function blake3_empty_state() {
724
- const ret = wasm.blake3_empty_state();
725
- return Blake3Hasher.__wrap(ret);
726
- }
727
-
728
- function _assertClass(instance, klass) {
729
- if (!(instance instanceof klass)) {
730
- throw new Error(`expected instance of ${klass.name}`);
731
- }
732
- }
733
- /**
734
- * Update a BLAKE3 state with new data for incremental hashing.
735
- * - `state`: Current Blake3Hasher instance
736
- * - `data`: New data to incorporate into the hash
737
- * Returns the updated Blake3Hasher.
738
- * @param {Blake3Hasher} state
739
- * @param {Uint8Array} data
740
- */
741
- export function blake3_update_state(state, data) {
742
- _assertClass(state, Blake3Hasher);
743
- const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
744
- const len0 = WASM_VECTOR_LEN;
745
- wasm.blake3_update_state(state.__wbg_ptr, ptr0, len0);
746
- }
747
-
748
- /**
749
- * Get the final hash from a BLAKE3 state.
750
- * - `state`: The Blake3Hasher to finalize
751
- * Returns 32 bytes of hash output.
752
- * This finalizes an incremental hashing operation.
753
- * @param {Blake3Hasher} state
754
- * @returns {Uint8Array}
755
- */
756
- export function blake3_digest_for_state(state) {
757
- _assertClass(state, Blake3Hasher);
758
- var ptr0 = state.__destroy_into_raw();
759
- const ret = wasm.blake3_digest_for_state(ptr0);
760
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
761
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
762
- return v2;
763
- }
764
-
765
- /**
766
- * WASM-exposed function to encrypt bytes with a key secret and nonce material.
767
- * - `value`: The raw bytes to encrypt
768
- * - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
769
- * - `nonce_material`: Raw bytes used to generate the nonce
770
- * Returns the encrypted bytes or throws a JsError if encryption fails.
771
- * @param {Uint8Array} value
772
- * @param {string} key_secret
773
- * @param {Uint8Array} nonce_material
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
774
739
  * @returns {Uint8Array}
775
740
  */
776
- export function encrypt(value, key_secret, nonce_material) {
777
- const ptr0 = passArray8ToWasm0(value, wasm.__wbindgen_malloc);
741
+ export function ed25519VerifyingKeyFromBytes(bytes) {
742
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
778
743
  const len0 = WASM_VECTOR_LEN;
779
- const ptr1 = passStringToWasm0(key_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
780
- const len1 = WASM_VECTOR_LEN;
781
- const ptr2 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
782
- const len2 = WASM_VECTOR_LEN;
783
- const ret = wasm.encrypt(ptr0, len0, ptr1, len1, ptr2, len2);
744
+ const ret = wasm.ed25519VerifyingKeyFromBytes(ptr0, len0);
784
745
  if (ret[3]) {
785
746
  throw takeFromExternrefTable0(ret[2]);
786
747
  }
787
- var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
748
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
788
749
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
789
- return v4;
750
+ return v2;
790
751
  }
791
752
 
792
753
  /**
793
- * WASM-exposed function to decrypt bytes with a key secret and nonce material.
794
- * - `ciphertext`: The encrypted bytes to decrypt
795
- * - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
796
- * - `nonce_material`: Raw bytes used to generate the nonce (must match encryption)
797
- * Returns the decrypted bytes or throws a JsError if decryption fails.
798
- * @param {Uint8Array} ciphertext
799
- * @param {string} key_secret
800
- * @param {Uint8Array} nonce_material
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
801
758
  * @returns {Uint8Array}
802
759
  */
803
- export function decrypt(ciphertext, key_secret, nonce_material) {
804
- const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
760
+ export function ed25519SignatureFromBytes(bytes) {
761
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
805
762
  const len0 = WASM_VECTOR_LEN;
806
- const ptr1 = passStringToWasm0(key_secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
807
- const len1 = WASM_VECTOR_LEN;
808
- const ptr2 = passArray8ToWasm0(nonce_material, wasm.__wbindgen_malloc);
809
- const len2 = WASM_VECTOR_LEN;
810
- const ret = wasm.decrypt(ptr0, len0, ptr1, len1, ptr2, len2);
763
+ const ret = wasm.ed25519SignatureFromBytes(ptr0, len0);
811
764
  if (ret[3]) {
812
765
  throw takeFromExternrefTable0(ret[2]);
813
766
  }
814
- var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
767
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
815
768
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
816
- return v4;
769
+ return v2;
817
770
  }
818
771
 
819
772
  const Blake3HasherFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -842,7 +795,7 @@ export class Blake3Hasher {
842
795
  wasm.__wbg_blake3hasher_free(ptr, 0);
843
796
  }
844
797
  constructor() {
845
- const ret = wasm.blake3_empty_state();
798
+ const ret = wasm.blake3hasher_new();
846
799
  this.__wbg_ptr = ret >>> 0;
847
800
  Blake3HasherFinalization.register(this, this.__wbg_ptr, this);
848
801
  return this;
@@ -853,7 +806,7 @@ export class Blake3Hasher {
853
806
  update(data) {
854
807
  const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
855
808
  const len0 = WASM_VECTOR_LEN;
856
- wasm.blake3_update_state(this.__wbg_ptr, ptr0, len0);
809
+ wasm.blake3hasher_update(this.__wbg_ptr, ptr0, len0);
857
810
  }
858
811
  /**
859
812
  * @returns {Uint8Array}