starknet 11.8.0 → 11.9.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [11.9.0](https://github.com/starknet-io/starknet.js/compare/v11.8.0...v11.9.0) (2026-11-23)
2
+
3
+ ### Features
4
+
5
+ - **falcon:** share a post-quantum secret between two Falcon accounts with ML-KEM-768 ([5e8aa3f](https://github.com/starknet-io/starknet.js/commit/5e8aa3f46a6e8d41c26aeb366fd453e73f6e4ea1))
6
+
1
7
  # [11.8.0](https://github.com/starknet-io/starknet.js/compare/v11.7.2...v11.8.0) (2026-11-23)
2
8
 
3
9
  ### Features
@@ -457,5 +457,147 @@ declare namespace falcon512 {
457
457
  };
458
458
  }
459
459
 
460
- export { Falcon512Signer, falcon512 };
461
- export type { Falcon512AccountType, Falcon512KeyPair, Falcon512Options };
460
+ /** What `createKey` gives to Alice. */
461
+ type MlKemKey = {
462
+ /** 64 random bytes. Alice keeps them secret: `decapsulate` needs them to open a capsule. */
463
+ seed: Uint8Array;
464
+ /** The ML-KEM-768 public key of Alice (1184 bytes). Alice publishes it. */
465
+ publicKey: Uint8Array;
466
+ /** The message that Alice signs with her account, to link the public key to her account. */
467
+ typedData: starknet.TypedData;
468
+ };
469
+ /**
470
+ * What Alice publishes: her ML-KEM public key, signed by her account. Bob gives it to
471
+ * `encapsulate`.
472
+ */
473
+ type MlKemSignedKey = {
474
+ /** The address of the account of Alice, which owns the ML-KEM key. */
475
+ keyOwnerAddress: starknet.BigNumberish;
476
+ /** The ML-KEM-768 public key of Alice (1184 bytes). */
477
+ publicKey: Uint8Array;
478
+ /** The end of validity of the key, in seconds since 1970-01-01 (UTC). */
479
+ validUntil: number;
480
+ /** The signature of the message of `createKey`, by the account of Alice. */
481
+ signature: starknet.Signature;
482
+ };
483
+ /** What `encapsulate` gives to Bob. */
484
+ type MlKemEncapsulation = {
485
+ /** The shared secret (32 bytes). Bob keeps it secret. */
486
+ sharedSecret: Uint8Array;
487
+ /** The capsule (1088 bytes). Bob sends it to Alice. Only Alice can open it. */
488
+ capsule: Uint8Array;
489
+ /** The time of the encapsulation, in seconds since 1970-01-01 (UTC). */
490
+ timestamp: number;
491
+ /** The message that Bob signs with his account, to show that the capsule comes from him. */
492
+ typedData: starknet.TypedData;
493
+ };
494
+ /**
495
+ * What Bob sends to Alice: the capsule, signed by his account. Alice gives it to `decapsulate`.
496
+ */
497
+ type MlKemSignedCapsule = {
498
+ /** The address of the account of Bob, who made the capsule and sent it. */
499
+ senderAddress: starknet.BigNumberish;
500
+ /** The capsule (1088 bytes). */
501
+ capsule: Uint8Array;
502
+ /** The time of the encapsulation, from `encapsulate`. */
503
+ timestamp: number;
504
+ /** The signature of the message of `encapsulate`, by the account of Bob. */
505
+ signature: starknet.Signature;
506
+ };
507
+
508
+ /**
509
+ * Step 1, for Alice: creates a new ML-KEM-768 key, and the message that links it to her account.
510
+ * Alice keeps the seed secret. She signs the message with her account (`signMessage`). Then she
511
+ * publishes her public key, its end of validity and the signature (see `MlKemSignedKey`).
512
+ * A wallet can sign the message: it needs nothing new. The seed stays in the dapp.
513
+ * @param {string} chainId the chain id, as `provider.getChainId()` returns it
514
+ * @param {number} validUntil the end of validity of the key, in seconds since 1970-01-01 (UTC).
515
+ * It must be in the future
516
+ * @returns {MlKemKey} the seed, the public key and the message to sign
517
+ * @throws {Error} when the chain id is empty, or when validUntil is not a time in seconds in the
518
+ * future
519
+ * @example
520
+ * ```typescript
521
+ * const chainId = await myProvider.getChainId();
522
+ * const validUntil = Math.floor(Date.now() / 1000) + 30 * 24 * 3600; // in 30 days
523
+ * const aliceKey = mlkem.createKey(chainId, validUntil);
524
+ * const signature = await aliceAccount.signMessage(aliceKey.typedData);
525
+ * const signedKey = {
526
+ * keyOwnerAddress: aliceAccount.address,
527
+ * publicKey: aliceKey.publicKey,
528
+ * validUntil,
529
+ * signature,
530
+ * };
531
+ * // Alice keeps aliceKey.seed (64 bytes) secret, and publishes signedKey.
532
+ * ```
533
+ */
534
+ declare function createKey(chainId: string, validUntil: number): MlKemKey;
535
+ /**
536
+ * Step 2, for Bob: checks the signed key of Alice, then creates the shared secret and a capsule.
537
+ * Bob keeps the shared secret. He signs the message with his account (`signMessage`). Then he
538
+ * sends the capsule, the timestamp and the signature to Alice (see `MlKemSignedCapsule`).
539
+ * The function refuses the key when it has expired, or when the account of Alice did not sign it
540
+ * with a post-quantum signature (see `checkSignature`).
541
+ * @param {ProviderInterface} provider the provider of the chain of the exchange
542
+ * @param {MlKemSignedKey} signedKey what Alice published
543
+ * @param {BigNumberish} senderAddress the address of the account of Bob, who makes the capsule
544
+ * and sends it
545
+ * @returns {Promise<MlKemEncapsulation>} the shared secret, the capsule, the timestamp and the
546
+ * message to sign
547
+ * @throws {Error} when the key has a wrong size or has expired, or when the signature of Alice is
548
+ * not valid
549
+ * @example
550
+ * ```typescript
551
+ * const bobSide = await mlkem.encapsulate(myProvider, signedKey, bobAccount.address);
552
+ * const signature = await bobAccount.signMessage(bobSide.typedData);
553
+ * const signedCapsule = {
554
+ * senderAddress: bobAccount.address,
555
+ * capsule: bobSide.capsule,
556
+ * timestamp: bobSide.timestamp,
557
+ * signature,
558
+ * };
559
+ * // Bob keeps bobSide.sharedSecret (32 bytes) secret, and sends signedCapsule to Alice.
560
+ * ```
561
+ */
562
+ declare function encapsulate(provider: starknet.ProviderInterface, signedKey: MlKemSignedKey, senderAddress: starknet.BigNumberish): Promise<MlKemEncapsulation>;
563
+ /**
564
+ * Step 3, for Alice: checks the signed capsule of Bob, then opens the capsule. Alice gets the same
565
+ * shared secret as Bob.
566
+ * The function refuses the capsule when the account of Bob did not sign it with a post-quantum
567
+ * signature (see `checkSignature`). A capsule made for another key or for another account is
568
+ * refused too: the signature of Bob does not match.
569
+ * Bob signed the timestamp, so it is the time that Bob gave. To refuse an old capsule, or a
570
+ * capsule received twice, is the job of the application.
571
+ * @param {ProviderInterface} provider the provider of the chain of the exchange
572
+ * @param {MlKemSignedCapsule} signedCapsule what Bob sent
573
+ * @param {BigNumberish} keyOwnerAddress the address of the account of Alice, who owns the key
574
+ * @param {Uint8Array} seed the seed that `createKey` gave to Alice (64 bytes)
575
+ * @returns {Promise<Uint8Array>} the shared secret (32 bytes), the same as the one of Bob
576
+ * @throws {Error} when the capsule or the seed has a wrong size, or when the signature of Bob is
577
+ * not valid
578
+ * @example
579
+ * ```typescript
580
+ * const sharedSecret = await mlkem.decapsulate(
581
+ * myProvider,
582
+ * signedCapsule,
583
+ * aliceAccount.address,
584
+ * aliceKey.seed
585
+ * );
586
+ * // sharedSecret = bobSide.sharedSecret (32 bytes)
587
+ * ```
588
+ */
589
+ declare function decapsulate(provider: starknet.ProviderInterface, signedCapsule: MlKemSignedCapsule, keyOwnerAddress: starknet.BigNumberish, seed: Uint8Array): Promise<Uint8Array>;
590
+
591
+ declare const index_createKey: typeof createKey;
592
+ declare const index_decapsulate: typeof decapsulate;
593
+ declare const index_encapsulate: typeof encapsulate;
594
+ declare namespace index {
595
+ export {
596
+ index_createKey as createKey,
597
+ index_decapsulate as decapsulate,
598
+ index_encapsulate as encapsulate,
599
+ };
600
+ }
601
+
602
+ export { Falcon512Signer, falcon512, index as mlkem };
603
+ export type { Falcon512AccountType, Falcon512KeyPair, Falcon512Options, MlKemEncapsulation, MlKemKey, MlKemSignedCapsule, MlKemSignedKey };