@continuumdao/ctm-mpc-defi 0.2.59 → 0.2.60

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.
@@ -29,8 +29,8 @@ Call `ctm_railgun_ensure_wallet` first. Use the returned `railgunAddress` as the
29
29
 
30
30
  ## Shield
31
31
 
32
- 1. Call `ctm_railgun_build_shield_multisign` without `shieldSignature`, with `railgunAddress` from `ctm_railgun_ensure_wallet`. Submit that personal_sign request.
33
- 2. Call the same tool again with `shieldSignature` set to the completed signature. Submit the resulting approve-and-shield transaction.
32
+ 1. Call `ctm_railgun_build_shield_multisign` without `shieldSignature`, with `railgunAddress` from `ctm_railgun_ensure_wallet`. Submit that personal_sign request (`sign_request_agree`, then `trigger_sign_result`).
33
+ 2. `broadcast_sign_result` on that request returns the shield-key signature in `txHashes[0]` and does not send a transaction. Call this tool again with `shieldSignature` set to that hex. Submit the resulting approve-and-shield transaction.
34
34
 
35
35
  The first call signs Railgun's shield message. The second call builds the EVM shield. If allowance is short, the second call includes an approve, and a zero-approve reset when a non-zero allowance is still too small. Shielding spends the KeyGen threshold key, not the 0zk spending key.
36
36
 
@@ -662,6 +662,16 @@ async function shieldSignatureMessage() {
662
662
  const wallet = await import('@railgun-community/wallet');
663
663
  return wallet.getShieldPrivateKeySignatureMessage();
664
664
  }
665
+ function shieldPrivateKeyFromSignature(signature) {
666
+ const hex = signature.startsWith("0x") ? signature : `0x${signature}`;
667
+ if (!/^0x[0-9a-fA-F]+$/.test(hex) || (hex.length - 2) % 2 !== 0) {
668
+ throw new Error("Shield-key signature must be hex.");
669
+ }
670
+ if ((hex.length - 2) / 2 !== 65) {
671
+ throw new Error("Shield-key signature must be the 65-byte personal_sign of RAILGUN_SHIELD.");
672
+ }
673
+ return viem.keccak256(hex);
674
+ }
665
675
  function personalSignBody(args, message) {
666
676
  const executor = viem.getAddress(args.executorAddress);
667
677
  const digest = viem.hashMessage(message);
@@ -742,6 +752,7 @@ async function buildEvmMultisignBodyRailgunShield(args) {
742
752
  if (!signature) {
743
753
  return personalSignBody(args, await shieldSignatureMessage());
744
754
  }
755
+ const shieldPrivateKey = shieldPrivateKeyFromSignature(signature);
745
756
  const network = await railgunNetworkByChainId(args.chainId);
746
757
  if (!network) throw new Error("Railgun is not deployed on this chain.");
747
758
  const tokenAddress = viem.getAddress(args.tokenAddress);
@@ -793,7 +804,7 @@ async function buildEvmMultisignBodyRailgunShield(args) {
793
804
  const populated = await populate(
794
805
  sharedModels.TXIDVersion.V2_PoseidonMerkle,
795
806
  networkName,
796
- signature,
807
+ shieldPrivateKey,
797
808
  [{ tokenAddress, amount, recipientAddress: args.railgunAddress.trim() }],
798
809
  [],
799
810
  railgunGasDetails(args.chainDetail, 1200000n)
@@ -1263,6 +1274,7 @@ exports.setRailgunPopulateShieldForTests = setRailgunPopulateShieldForTests;
1263
1274
  exports.setRailgunShieldLogReaderForTests = setRailgunShieldLogReaderForTests;
1264
1275
  exports.setRailgunWalletSession = setRailgunWalletSession;
1265
1276
  exports.shieldIndexEndpoint = shieldIndexEndpoint;
1277
+ exports.shieldPrivateKeyFromSignature = shieldPrivateKeyFromSignature;
1266
1278
  exports.unlockRailgunBrowserWallet = unlockRailgunBrowserWallet;
1267
1279
  exports.utxoScanTerminalStatus = utxoScanTerminalStatus;
1268
1280
  //# sourceMappingURL=index.cjs.map