shogun-core 6.2.2 → 6.2.4

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.
@@ -141716,6 +141716,11 @@ const performDHRatchetStep = async (state, newRemotePublicKey) => {
141716
141716
  // Generate our sending key pair for future messages
141717
141717
  console.log("🔑 Generating DH key pair for responder's future sending");
141718
141718
  state.sendingDHKeyPair = await (0, signal_protocol_1.generateSignalKeyPair)();
141719
+ // For responder's first receive, we don't derive a sending chain yet
141720
+ // because we haven't sent anything. The sending chain will be derived
141721
+ // when we send our first message.
141722
+ console.log("✓ DH ratchet step completed (responder first receive)");
141723
+ return;
141719
141724
  }
141720
141725
  else if (state.sendingDHKeyPair) {
141721
141726
  console.log("🔄 Deriving receiving chain from: DH(our_current_private, their_public)");
@@ -141727,6 +141732,7 @@ const performDHRatchetStep = async (state, newRemotePublicKey) => {
141727
141732
  console.log("🔄 DH ratchet step - receiving chain established");
141728
141733
  }
141729
141734
  // Step 2: Generate NEW DH key pair and derive sending chain
141735
+ // This only executes for subsequent ratchet steps (not responder's first receive)
141730
141736
  console.log("🔑 Generating NEW DH key pair for ratchet step");
141731
141737
  state.sendingDHKeyPair = await (0, signal_protocol_1.generateSignalKeyPair)();
141732
141738
  state.sendingMessageNumber = 0;
@@ -141763,8 +141769,24 @@ const skipMessageKeys = async (state, until) => {
141763
141769
  // Encrypt message using Double Ratchet
141764
141770
  const doubleRatchetEncrypt = async (state, plaintext) => {
141765
141771
  console.log(`🔒 Encrypting message #${state.sendingMessageNumber} with Double Ratchet`);
141772
+ // If responder is sending first message, derive sending chain
141766
141773
  if (!state.sendingChainKey) {
141767
- throw new Error("No sending chain key available - cannot encrypt");
141774
+ if (!state.isInitiator &&
141775
+ state.receivingDHPublicKey &&
141776
+ state.sendingDHKeyPair) {
141777
+ console.log("🔄 Responder's first send: Deriving sending chain");
141778
+ // Derive sending chain from our sending DH key pair and their receiving DH public key
141779
+ const sendingDHOutput = await (0, signal_protocol_1.performSignalDH)(state.sendingDHKeyPair.privateKey, state.receivingDHPublicKey);
141780
+ const hkdfSending = await doubleRatchetHKDF(new Uint8Array(state.rootKey), sendingDHOutput, DOUBLE_RATCHET_INFO_CHAIN_KEY, 64);
141781
+ state.rootKey = hkdfSending.slice(0, 32);
141782
+ state.sendingChainKey = hkdfSending.slice(32, 64);
141783
+ state.sendingMessageNumber = 0;
141784
+ state.previousChainLength = state.receivingMessageNumber;
141785
+ console.log("✅ Sending chain derived for responder's first message");
141786
+ }
141787
+ else {
141788
+ throw new Error("No sending chain key available - cannot encrypt");
141789
+ }
141768
141790
  }
141769
141791
  // Derive message key
141770
141792
  const messageKey = await deriveMessageKey(state.sendingChainKey);
@@ -144397,7 +144419,8 @@ exports.importSignalPublicKey = importSignalPublicKey;
144397
144419
  const importSignalSigningPublicKey = async (keyBytes) => {
144398
144420
  return await crypto.subtle.importKey("raw", keyBytes, {
144399
144421
  name: "Ed25519",
144400
- }, false, ["verify"]);
144422
+ }, true, // Make public keys extractable for re-export in bundles
144423
+ ["verify"]);
144401
144424
  };
144402
144425
  exports.importSignalSigningPublicKey = importSignalSigningPublicKey;
144403
144426
  const performSignalDH = async (privateKey, publicKey) => {