@continuumdao/ctm-mpc-defi 0.2.58 → 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.
@@ -1,8 +1,6 @@
1
- import { getAddress, parseAbi, zeroAddress, encodeFunctionData, defineChain, createPublicClient, parseGwei, serializeTransaction, keccak256, hashMessage, stringToHex, http } from 'viem';
1
+ import { getAddress, parseAbi, zeroAddress, keccak256, encodeFunctionData, defineChain, createPublicClient, parseGwei, serializeTransaction, hashMessage, stringToHex, http } from 'viem';
2
2
  import { fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
3
3
  import { TXIDVersion, calculateGasPrice, ChainType, EVMGasType, RailgunWalletBalanceBucket } from '@railgun-community/shared-models';
4
- import { createRequire } from 'module';
5
- import { join, dirname } from 'path';
6
4
 
7
5
  // src/core/registry.ts
8
6
  var modules = [];
@@ -541,7 +539,8 @@ async function buildEvmMultisignBatch(args) {
541
539
  }
542
540
  return result;
543
541
  }
544
- var require2 = createRequire(import.meta.url);
542
+
543
+ // src/protocols/evm/railgun/engine.ts
545
544
  var artifacts = /* @__PURE__ */ new Map();
546
545
  var started = false;
547
546
  var loadedProviders = /* @__PURE__ */ new Set();
@@ -578,17 +577,26 @@ var artifactStore = {
578
577
  return artifacts.has(path);
579
578
  }
580
579
  };
581
- async function ensureRailgunEngine() {
582
- if (started) return;
583
- const wallet = await walletModule();
580
+ async function attachEngineErrorLogger() {
581
+ if (typeof window !== "undefined") return;
582
+ if (typeof process === "undefined" || !process.versions?.node) return;
583
+ const load = new Function("id", "return import(id)");
584
+ const nodeModule = await load("node:module");
585
+ const nodePath = await load("node:path");
586
+ const require2 = nodeModule.createRequire(import.meta.url);
584
587
  const walletEntry = require2.resolve("@railgun-community/wallet");
585
- const { setLoggers } = require2(join(dirname(walletEntry), "utils/logger.js"));
588
+ const { setLoggers } = require2(nodePath.join(nodePath.dirname(walletEntry), "utils/logger.js"));
586
589
  setLoggers(
587
590
  () => void 0,
588
591
  (err) => {
589
592
  lastEngineError = errorChain(err);
590
593
  }
591
594
  );
595
+ }
596
+ async function ensureRailgunEngine() {
597
+ if (started) return;
598
+ const wallet = await walletModule();
599
+ await attachEngineErrorLogger();
592
600
  const memdown = (await import('memdown')).default;
593
601
  const store = new wallet.ArtifactStore(
594
602
  (path) => artifactStore.get(path),
@@ -651,6 +659,16 @@ async function shieldSignatureMessage() {
651
659
  const wallet = await import('@railgun-community/wallet');
652
660
  return wallet.getShieldPrivateKeySignatureMessage();
653
661
  }
662
+ function shieldPrivateKeyFromSignature(signature) {
663
+ const hex = signature.startsWith("0x") ? signature : `0x${signature}`;
664
+ if (!/^0x[0-9a-fA-F]+$/.test(hex) || (hex.length - 2) % 2 !== 0) {
665
+ throw new Error("Shield-key signature must be hex.");
666
+ }
667
+ if ((hex.length - 2) / 2 !== 65) {
668
+ throw new Error("Shield-key signature must be the 65-byte personal_sign of RAILGUN_SHIELD.");
669
+ }
670
+ return keccak256(hex);
671
+ }
654
672
  function personalSignBody(args, message) {
655
673
  const executor = getAddress(args.executorAddress);
656
674
  const digest = hashMessage(message);
@@ -731,6 +749,7 @@ async function buildEvmMultisignBodyRailgunShield(args) {
731
749
  if (!signature) {
732
750
  return personalSignBody(args, await shieldSignatureMessage());
733
751
  }
752
+ const shieldPrivateKey = shieldPrivateKeyFromSignature(signature);
734
753
  const network = await railgunNetworkByChainId(args.chainId);
735
754
  if (!network) throw new Error("Railgun is not deployed on this chain.");
736
755
  const tokenAddress = getAddress(args.tokenAddress);
@@ -782,7 +801,7 @@ async function buildEvmMultisignBodyRailgunShield(args) {
782
801
  const populated = await populate(
783
802
  TXIDVersion.V2_PoseidonMerkle,
784
803
  networkName,
785
- signature,
804
+ shieldPrivateKey,
786
805
  [{ tokenAddress, amount, recipientAddress: args.railgunAddress.trim() }],
787
806
  [],
788
807
  railgunGasDetails(args.chainDetail, 1200000n)
@@ -1213,6 +1232,6 @@ var railgunProtocolModule = {
1213
1232
  };
1214
1233
  registerProtocolModule(railgunProtocolModule);
1215
1234
 
1216
- export { RAILGUN_CTM_DISABLED_MESSAGE, RAILGUN_CTM_ENABLED, RAILGUN_POPULAR_ASSET_LIMIT, RAILGUN_PROTOCOL_ID, RAILGUN_WALLET_LOCKED_MESSAGE, assertRailgunCtmAllowed, buildEvmMultisignBodyRailgunShield, buildEvmMultisignBodyWethUnwrap, clearRailgunNetworkCache, clearRailgunPopularAssetCache, clearRailgunPrivateBalanceSnapshots, commitmentsFromShieldIndex, createRailgunBrowserWallet, discardRailgunWallet, getRailgunWalletSession, loadRailgunNetworks, loadRailgunPopularAssets, loadRailgunSupportedChainIds, openRailgunViewOnlyWallet, publishRailgunPrivateBalanceSnapshot, railgunAddressIsValid, railgunFetchPopularAssets, railgunFetchPrivateBalances, railgunFetchPrivateBalancesSummary, railgunNetworkByChainId, railgunPrivateTransfer, railgunProtocolModule, railgunShareableViewingKey, railgunUnshield, rankPopularShieldTokens, readRailgunPrivateBalanceSnapshot, requireRailgunWalletSession, scanRailgunPrivateBalances, selectRailgunNetworks, setRailgunAllowanceReaderForTests, setRailgunPopulateShieldForTests, setRailgunShieldLogReaderForTests, setRailgunWalletSession, shieldIndexEndpoint, unlockRailgunBrowserWallet, utxoScanTerminalStatus };
1235
+ export { RAILGUN_CTM_DISABLED_MESSAGE, RAILGUN_CTM_ENABLED, RAILGUN_POPULAR_ASSET_LIMIT, RAILGUN_PROTOCOL_ID, RAILGUN_WALLET_LOCKED_MESSAGE, assertRailgunCtmAllowed, buildEvmMultisignBodyRailgunShield, buildEvmMultisignBodyWethUnwrap, clearRailgunNetworkCache, clearRailgunPopularAssetCache, clearRailgunPrivateBalanceSnapshots, commitmentsFromShieldIndex, createRailgunBrowserWallet, discardRailgunWallet, getRailgunWalletSession, loadRailgunNetworks, loadRailgunPopularAssets, loadRailgunSupportedChainIds, openRailgunViewOnlyWallet, publishRailgunPrivateBalanceSnapshot, railgunAddressIsValid, railgunFetchPopularAssets, railgunFetchPrivateBalances, railgunFetchPrivateBalancesSummary, railgunNetworkByChainId, railgunPrivateTransfer, railgunProtocolModule, railgunShareableViewingKey, railgunUnshield, rankPopularShieldTokens, readRailgunPrivateBalanceSnapshot, requireRailgunWalletSession, scanRailgunPrivateBalances, selectRailgunNetworks, setRailgunAllowanceReaderForTests, setRailgunPopulateShieldForTests, setRailgunShieldLogReaderForTests, setRailgunWalletSession, shieldIndexEndpoint, shieldPrivateKeyFromSignature, unlockRailgunBrowserWallet, utxoScanTerminalStatus };
1217
1236
  //# sourceMappingURL=index.js.map
1218
1237
  //# sourceMappingURL=index.js.map