dexbot 1.1.10
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/LICENSE +21 -0
- package/README.md +287 -0
- package/claw/README.md +513 -0
- package/claw/scripts/memu_runner.py +385 -0
- package/claw/skills/bitshares-guide/SKILL.md +14 -0
- package/claw/skills/bitshares-guide/references/example-skill-shells.md +18 -0
- package/claw/skills/bitshares-guide/references/presentation-patterns.md +19 -0
- package/claw/skills/bitshares-guide/references/scope-guardrails.md +9 -0
- package/claw/skills/launcher-ops/SKILL.md +18 -0
- package/claw/skills/launcher-ops/references/launcher-workflow.md +23 -0
- package/claw/skills/margin-trading/SKILL.md +23 -0
- package/claw/skills/margin-trading/references/honest-asset-list.md +74 -0
- package/claw/skills/margin-trading/references/honest-assets.md +44 -0
- package/claw/skills/margin-trading/references/position-management.md +203 -0
- package/claw/skills/margin-trading/references/trading-concepts.md +80 -0
- package/claw/skills/memu-memory/SKILL.md +218 -0
- package/claw/skills/shared/references/js-automation-overview.md +24 -0
- package/claw/skills/shared/references/safety-and-staleness.md +11 -0
- package/claw/skills/shared/references/skill-boundaries.md +17 -0
- package/claw/skills/trend-detection/SKILL.md +33 -0
- package/claw/skills/trend-detection/agents/openai.yaml +3 -0
- package/claw/skills/trend-detection/references/service.md +45 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +149 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +387 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +3 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +200 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +3 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +212 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +31 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +249 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +2 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +782 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -0
- package/dist/analysis/analyze_derivatives.d.ts +95 -0
- package/dist/analysis/analyze_derivatives.d.ts.map +1 -0
- package/dist/analysis/analyze_derivatives.js +295 -0
- package/dist/analysis/analyze_derivatives.js.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts +14 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.js +208 -0
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -0
- package/dist/analysis/analyze_kalman.d.ts +13 -0
- package/dist/analysis/analyze_kalman.d.ts.map +1 -0
- package/dist/analysis/analyze_kalman.js +123 -0
- package/dist/analysis/analyze_kalman.js.map +1 -0
- package/dist/analysis/analyze_regime.d.ts +20 -0
- package/dist/analysis/analyze_regime.d.ts.map +1 -0
- package/dist/analysis/analyze_regime.js +139 -0
- package/dist/analysis/analyze_regime.js.map +1 -0
- package/dist/analysis/analyze_regime_windows.d.ts +19 -0
- package/dist/analysis/analyze_regime_windows.d.ts.map +1 -0
- package/dist/analysis/analyze_regime_windows.js +413 -0
- package/dist/analysis/analyze_regime_windows.js.map +1 -0
- package/dist/analysis/analyze_risk_profile.d.ts +3 -0
- package/dist/analysis/analyze_risk_profile.d.ts.map +1 -0
- package/dist/analysis/analyze_risk_profile.js +159 -0
- package/dist/analysis/analyze_risk_profile.js.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts +3 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.js +367 -0
- package/dist/analysis/analyze_trade_heatmap.js.map +1 -0
- package/dist/analysis/analyze_volatility.d.ts +22 -0
- package/dist/analysis/analyze_volatility.d.ts.map +1 -0
- package/dist/analysis/analyze_volatility.js +172 -0
- package/dist/analysis/analyze_volatility.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +99 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +804 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +2 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +347 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +15 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.js +48 -0
- package/dist/analysis/bot_fitting/shared_utils.js.map +1 -0
- package/dist/analysis/bot_key_utils.d.ts +16 -0
- package/dist/analysis/bot_key_utils.d.ts.map +1 -0
- package/dist/analysis/bot_key_utils.js +61 -0
- package/dist/analysis/bot_key_utils.js.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +3 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js +498 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +546 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js +427 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -0
- package/dist/analysis/chart_utils.d.ts +13 -0
- package/dist/analysis/chart_utils.d.ts.map +1 -0
- package/dist/analysis/chart_utils.js +142 -0
- package/dist/analysis/chart_utils.js.map +1 -0
- package/dist/analysis/derivative_chart_generator.d.ts +18 -0
- package/dist/analysis/derivative_chart_generator.d.ts.map +1 -0
- package/dist/analysis/derivative_chart_generator.js +896 -0
- package/dist/analysis/derivative_chart_generator.js.map +1 -0
- package/dist/analysis/math_utils.d.ts +35 -0
- package/dist/analysis/math_utils.d.ts.map +1 -0
- package/dist/analysis/math_utils.js +121 -0
- package/dist/analysis/math_utils.js.map +1 -0
- package/dist/analysis/price_sources.d.ts +34 -0
- package/dist/analysis/price_sources.d.ts.map +1 -0
- package/dist/analysis/price_sources.js +103 -0
- package/dist/analysis/price_sources.js.map +1 -0
- package/dist/analysis/trade_profitability.d.ts +115 -0
- package/dist/analysis/trade_profitability.d.ts.map +1 -0
- package/dist/analysis/trade_profitability.js +1247 -0
- package/dist/analysis/trade_profitability.js.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +38 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +212 -0
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +9 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1717 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +250 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js +903 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +1449 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts +42 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js +159 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js +408 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +103 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +229 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +34 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +89 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +39 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +132 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js +345 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +130 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +38 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js +732 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -0
- package/dist/bot.d.ts +49 -0
- package/dist/bot.d.ts.map +1 -0
- package/dist/bot.js +221 -0
- package/dist/bot.js.map +1 -0
- package/dist/credential-daemon.d.ts +64 -0
- package/dist/credential-daemon.d.ts.map +1 -0
- package/dist/credential-daemon.js +987 -0
- package/dist/credential-daemon.js.map +1 -0
- package/dist/dexbot.d.ts +87 -0
- package/dist/dexbot.d.ts.map +1 -0
- package/dist/dexbot.js +1222 -0
- package/dist/dexbot.js.map +1 -0
- package/dist/market_adapter/ama_signal_runner.d.ts +3 -0
- package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -0
- package/dist/market_adapter/ama_signal_runner.js +175 -0
- package/dist/market_adapter/ama_signal_runner.js.map +1 -0
- package/dist/market_adapter/candle_utils.d.ts +57 -0
- package/dist/market_adapter/candle_utils.d.ts.map +1 -0
- package/dist/market_adapter/candle_utils.js +252 -0
- package/dist/market_adapter/candle_utils.js.map +1 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +20 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -0
- package/dist/market_adapter/core/asymmetric_bounds.js +88 -0
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -0
- package/dist/market_adapter/core/config_normalizers.d.ts +10 -0
- package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -0
- package/dist/market_adapter/core/config_normalizers.js +24 -0
- package/dist/market_adapter/core/config_normalizers.js.map +1 -0
- package/dist/market_adapter/core/kibana_candles.d.ts +74 -0
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_candles.js +249 -0
- package/dist/market_adapter/core/kibana_candles.js.map +1 -0
- package/dist/market_adapter/core/kibana_client.d.ts +27 -0
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_client.js +120 -0
- package/dist/market_adapter/core/kibana_client.js.map +1 -0
- package/dist/market_adapter/core/kibana_market_candles.d.ts +143 -0
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_market_candles.js +170 -0
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts +210 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -0
- package/dist/market_adapter/core/market_adapter_service.js +2328 -0
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -0
- package/dist/market_adapter/core/strategies/ama.d.ts +2 -0
- package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/ama.js +138 -0
- package/dist/market_adapter/core/strategies/ama.js.map +1 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +50 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.js +143 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -0
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +12 -0
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/atr/calculator.js +47 -0
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -0
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +32 -0
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/collateral_manager.js +68 -0
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -0
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +66 -0
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/regime_gate.js +189 -0
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -0
- package/dist/market_adapter/index.d.ts +10 -0
- package/dist/market_adapter/index.d.ts.map +1 -0
- package/dist/market_adapter/index.js +71 -0
- package/dist/market_adapter/index.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts +3 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1165 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +54 -0
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js +743 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts +68 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.js +143 -0
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -0
- package/dist/market_adapter/interval_utils.d.ts +6 -0
- package/dist/market_adapter/interval_utils.d.ts.map +1 -0
- package/dist/market_adapter/interval_utils.js +14 -0
- package/dist/market_adapter/interval_utils.js.map +1 -0
- package/dist/market_adapter/log_format.d.ts +16 -0
- package/dist/market_adapter/log_format.d.ts.map +1 -0
- package/dist/market_adapter/log_format.js +72 -0
- package/dist/market_adapter/log_format.js.map +1 -0
- package/dist/market_adapter/lp_chart_core.d.ts +6 -0
- package/dist/market_adapter/lp_chart_core.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_core.js +874 -0
- package/dist/market_adapter/lp_chart_core.js.map +1 -0
- package/dist/market_adapter/lp_chart_runner.d.ts +135 -0
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_runner.js +337 -0
- package/dist/market_adapter/lp_chart_runner.js.map +1 -0
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +23 -0
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_strategy_loader.js +169 -0
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -0
- package/dist/market_adapter/market_adapter.d.ts +133 -0
- package/dist/market_adapter/market_adapter.d.ts.map +1 -0
- package/dist/market_adapter/market_adapter.js +1331 -0
- package/dist/market_adapter/market_adapter.js.map +1 -0
- package/dist/market_adapter/merge_lp_data.d.ts +3 -0
- package/dist/market_adapter/merge_lp_data.d.ts.map +1 -0
- package/dist/market_adapter/merge_lp_data.js +125 -0
- package/dist/market_adapter/merge_lp_data.js.map +1 -0
- package/dist/market_adapter/test_helpers.d.ts +14 -0
- package/dist/market_adapter/test_helpers.d.ts.map +1 -0
- package/dist/market_adapter/test_helpers.js +22 -0
- package/dist/market_adapter/test_helpers.js.map +1 -0
- package/dist/market_adapter/utils/adapter_client.d.ts +20 -0
- package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -0
- package/dist/market_adapter/utils/adapter_client.js +88 -0
- package/dist/market_adapter/utils/adapter_client.js.map +1 -0
- package/dist/market_adapter/utils/atomic_write.d.ts +9 -0
- package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -0
- package/dist/market_adapter/utils/atomic_write.js +13 -0
- package/dist/market_adapter/utils/atomic_write.js.map +1 -0
- package/dist/market_adapter/utils/chain.d.ts +50 -0
- package/dist/market_adapter/utils/chain.d.ts.map +1 -0
- package/dist/market_adapter/utils/chain.js +196 -0
- package/dist/market_adapter/utils/chain.js.map +1 -0
- package/dist/market_adapter/utils/data_discovery.d.ts +6 -0
- package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -0
- package/dist/market_adapter/utils/data_discovery.js +35 -0
- package/dist/market_adapter/utils/data_discovery.js.map +1 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +15 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +60 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -0
- package/dist/market_adapter/utils/file_lock.d.ts +19 -0
- package/dist/market_adapter/utils/file_lock.d.ts.map +1 -0
- package/dist/market_adapter/utils/file_lock.js +191 -0
- package/dist/market_adapter/utils/file_lock.js.map +1 -0
- package/dist/market_adapter/utils/native_history.d.ts +19 -0
- package/dist/market_adapter/utils/native_history.d.ts.map +1 -0
- package/dist/market_adapter/utils/native_history.js +172 -0
- package/dist/market_adapter/utils/native_history.js.map +1 -0
- package/dist/market_adapter/utils/paths.d.ts +5 -0
- package/dist/market_adapter/utils/paths.d.ts.map +1 -0
- package/dist/market_adapter/utils/paths.js +7 -0
- package/dist/market_adapter/utils/paths.js.map +1 -0
- package/dist/modules/account_bots.d.ts +112 -0
- package/dist/modules/account_bots.d.ts.map +1 -0
- package/dist/modules/account_bots.js +1259 -0
- package/dist/modules/account_bots.js.map +1 -0
- package/dist/modules/account_orders.d.ts +273 -0
- package/dist/modules/account_orders.d.ts.map +1 -0
- package/dist/modules/account_orders.js +662 -0
- package/dist/modules/account_orders.js.map +1 -0
- package/dist/modules/authority_resolver.d.ts +2 -0
- package/dist/modules/authority_resolver.d.ts.map +1 -0
- package/dist/modules/authority_resolver.js +231 -0
- package/dist/modules/authority_resolver.js.map +1 -0
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -0
- package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -0
- package/dist/modules/bitshares-native/chain_client.js +322 -0
- package/dist/modules/bitshares-native/chain_client.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +59 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +456 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.d.ts +66 -0
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.js +557 -0
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +20 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -0
- package/dist/modules/bitshares-native/index.d.ts +3 -0
- package/dist/modules/bitshares-native/index.d.ts.map +1 -0
- package/dist/modules/bitshares-native/index.js +32 -0
- package/dist/modules/bitshares-native/index.js.map +1 -0
- package/dist/modules/bitshares-native/resolvers.d.ts +40 -0
- package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -0
- package/dist/modules/bitshares-native/resolvers.js +161 -0
- package/dist/modules/bitshares-native/resolvers.js.map +1 -0
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +56 -0
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/chain_constants.js +92 -0
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -0
- package/dist/modules/bitshares-native/serial/index.d.ts +10 -0
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/index.js +14 -0
- package/dist/modules/bitshares-native/serial/index.js.map +1 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +102 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/operations.js +615 -0
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -0
- package/dist/modules/bitshares-native/serial/serializer.d.ts +64 -0
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/serializer.js +252 -0
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -0
- package/dist/modules/bitshares-native/serial/types.d.ts +120 -0
- package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/types.js +837 -0
- package/dist/modules/bitshares-native/serial/types.js.map +1 -0
- package/dist/modules/bitshares-native/signing_client.d.ts +6 -0
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -0
- package/dist/modules/bitshares-native/signing_client.js +141 -0
- package/dist/modules/bitshares-native/signing_client.js.map +1 -0
- package/dist/modules/bitshares-native/subscriptions.d.ts +6 -0
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -0
- package/dist/modules/bitshares-native/subscriptions.js +865 -0
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -0
- package/dist/modules/bitshares-native/transport.d.ts +51 -0
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -0
- package/dist/modules/bitshares-native/transport.js +447 -0
- package/dist/modules/bitshares-native/transport.js.map +1 -0
- package/dist/modules/bitshares-native/tx/builder.d.ts +30 -0
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -0
- package/dist/modules/bitshares-native/tx/builder.js +262 -0
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -0
- package/dist/modules/bitshares_client.d.ts +129 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -0
- package/dist/modules/bitshares_client.js +627 -0
- package/dist/modules/bitshares_client.js.map +1 -0
- package/dist/modules/bot_settings.d.ts +33 -0
- package/dist/modules/bot_settings.d.ts.map +1 -0
- package/dist/modules/bot_settings.js +328 -0
- package/dist/modules/bot_settings.js.map +1 -0
- package/dist/modules/bots_file_lock.d.ts +88 -0
- package/dist/modules/bots_file_lock.d.ts.map +1 -0
- package/dist/modules/bots_file_lock.js +161 -0
- package/dist/modules/bots_file_lock.js.map +1 -0
- package/dist/modules/chain_keys.d.ts +302 -0
- package/dist/modules/chain_keys.d.ts.map +1 -0
- package/dist/modules/chain_keys.js +1095 -0
- package/dist/modules/chain_keys.js.map +1 -0
- package/dist/modules/chain_orders.d.ts +423 -0
- package/dist/modules/chain_orders.d.ts.map +1 -0
- package/dist/modules/chain_orders.js +1201 -0
- package/dist/modules/chain_orders.js.map +1 -0
- package/dist/modules/cli_whitelist_args.d.ts +6 -0
- package/dist/modules/cli_whitelist_args.d.ts.map +1 -0
- package/dist/modules/cli_whitelist_args.js +13 -0
- package/dist/modules/cli_whitelist_args.js.map +1 -0
- package/dist/modules/config.d.ts +57 -0
- package/dist/modules/config.d.ts.map +1 -0
- package/dist/modules/config.js +107 -0
- package/dist/modules/config.js.map +1 -0
- package/dist/modules/constants.d.ts +635 -0
- package/dist/modules/constants.d.ts.map +1 -0
- package/dist/modules/constants.js +1464 -0
- package/dist/modules/constants.js.map +1 -0
- package/dist/modules/cr_planner.d.ts +51 -0
- package/dist/modules/cr_planner.d.ts.map +1 -0
- package/dist/modules/cr_planner.js +299 -0
- package/dist/modules/cr_planner.js.map +1 -0
- package/dist/modules/credential_policy.d.ts +188 -0
- package/dist/modules/credential_policy.d.ts.map +1 -0
- package/dist/modules/credential_policy.js +1452 -0
- package/dist/modules/credential_policy.js.map +1 -0
- package/dist/modules/credential_runtime.d.ts +42 -0
- package/dist/modules/credential_runtime.d.ts.map +1 -0
- package/dist/modules/credential_runtime.js +148 -0
- package/dist/modules/credential_runtime.js.map +1 -0
- package/dist/modules/credential_session_cache.d.ts +36 -0
- package/dist/modules/credential_session_cache.d.ts.map +1 -0
- package/dist/modules/credential_session_cache.js +106 -0
- package/dist/modules/credential_session_cache.js.map +1 -0
- package/dist/modules/credit_runtime.d.ts +412 -0
- package/dist/modules/credit_runtime.d.ts.map +1 -0
- package/dist/modules/credit_runtime.js +2866 -0
- package/dist/modules/credit_runtime.js.map +1 -0
- package/dist/modules/crypto/browser_provider.d.ts +15 -0
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -0
- package/dist/modules/crypto/browser_provider.js +113 -0
- package/dist/modules/crypto/browser_provider.js.map +1 -0
- package/dist/modules/crypto/index.d.ts +9 -0
- package/dist/modules/crypto/index.d.ts.map +1 -0
- package/dist/modules/crypto/index.js +44 -0
- package/dist/modules/crypto/index.js.map +1 -0
- package/dist/modules/crypto/node_provider.d.ts +15 -0
- package/dist/modules/crypto/node_provider.d.ts.map +1 -0
- package/dist/modules/crypto/node_provider.js +74 -0
- package/dist/modules/crypto/node_provider.js.map +1 -0
- package/dist/modules/crypto/provider.d.ts +34 -0
- package/dist/modules/crypto/provider.d.ts.map +1 -0
- package/dist/modules/crypto/provider.js +3 -0
- package/dist/modules/crypto/provider.js.map +1 -0
- package/dist/modules/crypto/pure_ripemd160.d.ts +8 -0
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +1 -0
- package/dist/modules/crypto/pure_ripemd160.js +142 -0
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -0
- package/dist/modules/crypto/pure_scrypt.d.ts +23 -0
- package/dist/modules/crypto/pure_scrypt.d.ts.map +1 -0
- package/dist/modules/crypto/pure_scrypt.js +161 -0
- package/dist/modules/crypto/pure_scrypt.js.map +1 -0
- package/dist/modules/crypto/pure_secp256k1.d.ts +29 -0
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -0
- package/dist/modules/crypto/pure_secp256k1.js +195 -0
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -0
- package/dist/modules/crypto/sync.d.ts +13 -0
- package/dist/modules/crypto/sync.d.ts.map +1 -0
- package/dist/modules/crypto/sync.js +37 -0
- package/dist/modules/crypto/sync.js.map +1 -0
- package/dist/modules/dexbot_class.d.ts +1074 -0
- package/dist/modules/dexbot_class.d.ts.map +1 -0
- package/dist/modules/dexbot_class.js +4613 -0
- package/dist/modules/dexbot_class.js.map +1 -0
- package/dist/modules/dexbot_credential_client.d.ts +71 -0
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -0
- package/dist/modules/dexbot_credential_client.js +224 -0
- package/dist/modules/dexbot_credential_client.js.map +1 -0
- package/dist/modules/dexbot_fill_runtime.d.ts +173 -0
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_fill_runtime.js +217 -0
- package/dist/modules/dexbot_fill_runtime.js.map +1 -0
- package/dist/modules/dexbot_maintenance_runtime.d.ts +279 -0
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_maintenance_runtime.js +1613 -0
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -0
- package/dist/modules/env.d.ts +12 -0
- package/dist/modules/env.d.ts.map +1 -0
- package/dist/modules/env.js +57 -0
- package/dist/modules/env.js.map +1 -0
- package/dist/modules/fund_registry.d.ts +96 -0
- package/dist/modules/fund_registry.d.ts.map +1 -0
- package/dist/modules/fund_registry.js +261 -0
- package/dist/modules/fund_registry.js.map +1 -0
- package/dist/modules/general_settings.d.ts +36 -0
- package/dist/modules/general_settings.d.ts.map +1 -0
- package/dist/modules/general_settings.js +63 -0
- package/dist/modules/general_settings.js.map +1 -0
- package/dist/modules/graceful_shutdown.d.ts +86 -0
- package/dist/modules/graceful_shutdown.d.ts.map +1 -0
- package/dist/modules/graceful_shutdown.js +164 -0
- package/dist/modules/graceful_shutdown.js.map +1 -0
- package/dist/modules/key_store.d.ts +60 -0
- package/dist/modules/key_store.d.ts.map +1 -0
- package/dist/modules/key_store.js +215 -0
- package/dist/modules/key_store.js.map +1 -0
- package/dist/modules/launcher/bot_supervisor.d.ts +84 -0
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -0
- package/dist/modules/launcher/bot_supervisor.js +1067 -0
- package/dist/modules/launcher/bot_supervisor.js.map +1 -0
- package/dist/modules/launcher/child_env.d.ts +9 -0
- package/dist/modules/launcher/child_env.d.ts.map +1 -0
- package/dist/modules/launcher/child_env.js +78 -0
- package/dist/modules/launcher/child_env.js.map +1 -0
- package/dist/modules/launcher/credential_bootstrap.d.ts +22 -0
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -0
- package/dist/modules/launcher/credential_bootstrap.js +303 -0
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -0
- package/dist/modules/launcher/credential_daemon.d.ts +32 -0
- package/dist/modules/launcher/credential_daemon.d.ts.map +1 -0
- package/dist/modules/launcher/credential_daemon.js +173 -0
- package/dist/modules/launcher/credential_daemon.js.map +1 -0
- package/dist/modules/launcher/credential_secret.d.ts +6 -0
- package/dist/modules/launcher/credential_secret.d.ts.map +1 -0
- package/dist/modules/launcher/credential_secret.js +15 -0
- package/dist/modules/launcher/credential_secret.js.map +1 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -0
- package/dist/modules/launcher/foreign_cred_daemon.js +166 -0
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -0
- package/dist/modules/launcher/headless_password.d.ts +8 -0
- package/dist/modules/launcher/headless_password.d.ts.map +1 -0
- package/dist/modules/launcher/headless_password.js +33 -0
- package/dist/modules/launcher/headless_password.js.map +1 -0
- package/dist/modules/launcher/launch_modes.d.ts +36 -0
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -0
- package/dist/modules/launcher/launch_modes.js +129 -0
- package/dist/modules/launcher/launch_modes.js.map +1 -0
- package/dist/modules/launcher/market_adapter_runtime.d.ts +43 -0
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -0
- package/dist/modules/launcher/market_adapter_runtime.js +217 -0
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -0
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +26 -0
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -0
- package/dist/modules/launcher/market_adapter_watchdog.js +214 -0
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +89 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -0
- package/dist/modules/launcher/monolithic_runtime.js +425 -0
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -0
- package/dist/modules/launcher/runtime_entry.d.ts +26 -0
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -0
- package/dist/modules/launcher/runtime_entry.js +49 -0
- package/dist/modules/launcher/runtime_entry.js.map +1 -0
- package/dist/modules/launcher/status_reporting.d.ts +48 -0
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -0
- package/dist/modules/launcher/status_reporting.js +113 -0
- package/dist/modules/launcher/status_reporting.js.map +1 -0
- package/dist/modules/launcher/supervisor_control.d.ts +6 -0
- package/dist/modules/launcher/supervisor_control.d.ts.map +1 -0
- package/dist/modules/launcher/supervisor_control.js +59 -0
- package/dist/modules/launcher/supervisor_control.js.map +1 -0
- package/dist/modules/logger.d.ts +2 -0
- package/dist/modules/logger.d.ts.map +1 -0
- package/dist/modules/logger.js +71 -0
- package/dist/modules/logger.js.map +1 -0
- package/dist/modules/market_adapter_whitelist.d.ts +22 -0
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -0
- package/dist/modules/market_adapter_whitelist.js +82 -0
- package/dist/modules/market_adapter_whitelist.js.map +1 -0
- package/dist/modules/node_health_cache.d.ts +55 -0
- package/dist/modules/node_health_cache.d.ts.map +1 -0
- package/dist/modules/node_health_cache.js +134 -0
- package/dist/modules/node_health_cache.js.map +1 -0
- package/dist/modules/node_manager.d.ts +215 -0
- package/dist/modules/node_manager.d.ts.map +1 -0
- package/dist/modules/node_manager.js +628 -0
- package/dist/modules/node_manager.js.map +1 -0
- package/dist/modules/order/accounting.d.ts +349 -0
- package/dist/modules/order/accounting.d.ts.map +1 -0
- package/dist/modules/order/accounting.js +1191 -0
- package/dist/modules/order/accounting.js.map +1 -0
- package/dist/modules/order/async_lock.d.ts +126 -0
- package/dist/modules/order/async_lock.d.ts.map +1 -0
- package/dist/modules/order/async_lock.js +195 -0
- package/dist/modules/order/async_lock.js.map +1 -0
- package/dist/modules/order/export.d.ts +129 -0
- package/dist/modules/order/export.d.ts.map +1 -0
- package/dist/modules/order/export.js +316 -0
- package/dist/modules/order/export.js.map +1 -0
- package/dist/modules/order/format.d.ts +158 -0
- package/dist/modules/order/format.d.ts.map +1 -0
- package/dist/modules/order/format.js +232 -0
- package/dist/modules/order/format.js.map +1 -0
- package/dist/modules/order/grid.d.ts +549 -0
- package/dist/modules/order/grid.d.ts.map +1 -0
- package/dist/modules/order/grid.js +1746 -0
- package/dist/modules/order/grid.js.map +1 -0
- package/dist/modules/order/grid_reconcile.d.ts +154 -0
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -0
- package/dist/modules/order/grid_reconcile.js +1192 -0
- package/dist/modules/order/grid_reconcile.js.map +1 -0
- package/dist/modules/order/index.d.ts +55 -0
- package/dist/modules/order/index.d.ts.map +1 -0
- package/dist/modules/order/index.js +79 -0
- package/dist/modules/order/index.js.map +1 -0
- package/dist/modules/order/logger.d.ts +136 -0
- package/dist/modules/order/logger.d.ts.map +1 -0
- package/dist/modules/order/logger.js +614 -0
- package/dist/modules/order/logger.js.map +1 -0
- package/dist/modules/order/logger_state.d.ts +133 -0
- package/dist/modules/order/logger_state.d.ts.map +1 -0
- package/dist/modules/order/logger_state.js +170 -0
- package/dist/modules/order/logger_state.js.map +1 -0
- package/dist/modules/order/manager.d.ts +413 -0
- package/dist/modules/order/manager.d.ts.map +1 -0
- package/dist/modules/order/manager.js +1605 -0
- package/dist/modules/order/manager.js.map +1 -0
- package/dist/modules/order/processed_fill_store.d.ts +135 -0
- package/dist/modules/order/processed_fill_store.d.ts.map +1 -0
- package/dist/modules/order/processed_fill_store.js +288 -0
- package/dist/modules/order/processed_fill_store.js.map +1 -0
- package/dist/modules/order/runner.d.ts +70 -0
- package/dist/modules/order/runner.d.ts.map +1 -0
- package/dist/modules/order/runner.js +140 -0
- package/dist/modules/order/runner.js.map +1 -0
- package/dist/modules/order/strategy.d.ts +196 -0
- package/dist/modules/order/strategy.d.ts.map +1 -0
- package/dist/modules/order/strategy.js +398 -0
- package/dist/modules/order/strategy.js.map +1 -0
- package/dist/modules/order/sync_engine.d.ts +386 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -0
- package/dist/modules/order/sync_engine.js +1459 -0
- package/dist/modules/order/sync_engine.js.map +1 -0
- package/dist/modules/order/utils/math.d.ts +677 -0
- package/dist/modules/order/utils/math.d.ts.map +1 -0
- package/dist/modules/order/utils/math.js +1172 -0
- package/dist/modules/order/utils/math.js.map +1 -0
- package/dist/modules/order/utils/order.d.ts +572 -0
- package/dist/modules/order/utils/order.d.ts.map +1 -0
- package/dist/modules/order/utils/order.js +1145 -0
- package/dist/modules/order/utils/order.js.map +1 -0
- package/dist/modules/order/utils/system.d.ts +268 -0
- package/dist/modules/order/utils/system.d.ts.map +1 -0
- package/dist/modules/order/utils/system.js +1261 -0
- package/dist/modules/order/utils/system.js.map +1 -0
- package/dist/modules/order/utils/validate.d.ts +280 -0
- package/dist/modules/order/utils/validate.d.ts.map +1 -0
- package/dist/modules/order/utils/validate.js +918 -0
- package/dist/modules/order/utils/validate.js.map +1 -0
- package/dist/modules/order/working_grid.d.ts +212 -0
- package/dist/modules/order/working_grid.d.ts.map +1 -0
- package/dist/modules/order/working_grid.js +279 -0
- package/dist/modules/order/working_grid.js.map +1 -0
- package/dist/modules/path_api.d.ts +32 -0
- package/dist/modules/path_api.d.ts.map +1 -0
- package/dist/modules/path_api.js +148 -0
- package/dist/modules/path_api.js.map +1 -0
- package/dist/modules/paths.d.ts +58 -0
- package/dist/modules/paths.d.ts.map +1 -0
- package/dist/modules/paths.js +82 -0
- package/dist/modules/paths.js.map +1 -0
- package/dist/modules/process_discovery.d.ts +58 -0
- package/dist/modules/process_discovery.d.ts.map +1 -0
- package/dist/modules/process_discovery.js +265 -0
- package/dist/modules/process_discovery.js.map +1 -0
- package/dist/modules/runtime.d.ts +34 -0
- package/dist/modules/runtime.d.ts.map +1 -0
- package/dist/modules/runtime.js +98 -0
- package/dist/modules/runtime.js.map +1 -0
- package/dist/modules/runtime_settings.d.ts +12 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -0
- package/dist/modules/runtime_settings.js +122 -0
- package/dist/modules/runtime_settings.js.map +1 -0
- package/dist/modules/settings_merge.d.ts +38 -0
- package/dist/modules/settings_merge.d.ts.map +1 -0
- package/dist/modules/settings_merge.js +246 -0
- package/dist/modules/settings_merge.js.map +1 -0
- package/dist/modules/storage/browser_adapter.d.ts +56 -0
- package/dist/modules/storage/browser_adapter.d.ts.map +1 -0
- package/dist/modules/storage/browser_adapter.js +231 -0
- package/dist/modules/storage/browser_adapter.js.map +1 -0
- package/dist/modules/storage/index.d.ts +28 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +52 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/node_adapter.d.ts +49 -0
- package/dist/modules/storage/node_adapter.d.ts.map +1 -0
- package/dist/modules/storage/node_adapter.js +167 -0
- package/dist/modules/storage/node_adapter.js.map +1 -0
- package/dist/modules/storage/types.d.ts +92 -0
- package/dist/modules/storage/types.d.ts.map +1 -0
- package/dist/modules/storage/types.js +3 -0
- package/dist/modules/storage/types.js.map +1 -0
- package/dist/modules/types.d.ts +1382 -0
- package/dist/modules/types.d.ts.map +1 -0
- package/dist/modules/types.js +11 -0
- package/dist/modules/types.js.map +1 -0
- package/dist/modules/utils/base58check.d.ts +12 -0
- package/dist/modules/utils/base58check.d.ts.map +1 -0
- package/dist/modules/utils/base58check.js +112 -0
- package/dist/modules/utils/base58check.js.map +1 -0
- package/dist/modules/utils/build_dir.d.ts +7 -0
- package/dist/modules/utils/build_dir.d.ts.map +1 -0
- package/dist/modules/utils/build_dir.js +8 -0
- package/dist/modules/utils/build_dir.js.map +1 -0
- package/dist/modules/utils/fs_utils.d.ts +25 -0
- package/dist/modules/utils/fs_utils.d.ts.map +1 -0
- package/dist/modules/utils/fs_utils.js +27 -0
- package/dist/modules/utils/fs_utils.js.map +1 -0
- package/dist/modules/utils/math_utils.d.ts +10 -0
- package/dist/modules/utils/math_utils.d.ts.map +1 -0
- package/dist/modules/utils/math_utils.js +17 -0
- package/dist/modules/utils/math_utils.js.map +1 -0
- package/dist/modules/validate_profiles.d.ts +37 -0
- package/dist/modules/validate_profiles.d.ts.map +1 -0
- package/dist/modules/validate_profiles.js +369 -0
- package/dist/modules/validate_profiles.js.map +1 -0
- package/dist/pm2.d.ts +167 -0
- package/dist/pm2.d.ts.map +1 -0
- package/dist/pm2.js +998 -0
- package/dist/pm2.js.map +1 -0
- package/dist/scripts/analyze-git.d.ts +11 -0
- package/dist/scripts/analyze-git.d.ts.map +1 -0
- package/dist/scripts/analyze-git.js +851 -0
- package/dist/scripts/analyze-git.js.map +1 -0
- package/dist/scripts/analyze-orders.d.ts +17 -0
- package/dist/scripts/analyze-orders.d.ts.map +1 -0
- package/dist/scripts/analyze-orders.js +1568 -0
- package/dist/scripts/analyze-orders.js.map +1 -0
- package/dist/scripts/diagnose-kibana-candles.d.ts +3 -0
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -0
- package/dist/scripts/diagnose-kibana-candles.js +82 -0
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -0
- package/dist/scripts/diagnose-pool-history.d.ts +3 -0
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -0
- package/dist/scripts/diagnose-pool-history.js +296 -0
- package/dist/scripts/diagnose-pool-history.js.map +1 -0
- package/dist/scripts/divergence-calc.d.ts +26 -0
- package/dist/scripts/divergence-calc.d.ts.map +1 -0
- package/dist/scripts/divergence-calc.js +119 -0
- package/dist/scripts/divergence-calc.js.map +1 -0
- package/dist/scripts/generate_lp_chart.d.ts +31 -0
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -0
- package/dist/scripts/generate_lp_chart.js +92 -0
- package/dist/scripts/generate_lp_chart.js.map +1 -0
- package/dist/scripts/generate_mainnet_corpus_report.d.ts +24 -0
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -0
- package/dist/scripts/generate_mainnet_corpus_report.js +237 -0
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -0
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +2 -0
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -0
- package/dist/scripts/generate_market_adapter_whitelist.js +111 -0
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -0
- package/dist/scripts/migrate_bot_keys.d.ts +6 -0
- package/dist/scripts/migrate_bot_keys.d.ts.map +1 -0
- package/dist/scripts/migrate_bot_keys.js +301 -0
- package/dist/scripts/migrate_bot_keys.js.map +1 -0
- package/dist/scripts/native_release_gates.d.ts +3 -0
- package/dist/scripts/native_release_gates.d.ts.map +1 -0
- package/dist/scripts/native_release_gates.js +52 -0
- package/dist/scripts/native_release_gates.js.map +1 -0
- package/dist/scripts/print_grid.d.ts +16 -0
- package/dist/scripts/print_grid.d.ts.map +1 -0
- package/dist/scripts/print_grid.js +80 -0
- package/dist/scripts/print_grid.js.map +1 -0
- package/dist/scripts/run-tests.d.ts +2 -0
- package/dist/scripts/run-tests.d.ts.map +1 -0
- package/dist/scripts/run-tests.js +49 -0
- package/dist/scripts/run-tests.js.map +1 -0
- package/dist/scripts/sync-version.d.ts +14 -0
- package/dist/scripts/sync-version.d.ts.map +1 -0
- package/dist/scripts/sync-version.js +158 -0
- package/dist/scripts/sync-version.js.map +1 -0
- package/dist/scripts/test-credit-renewal.d.ts +2 -0
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -0
- package/dist/scripts/test-credit-renewal.js +329 -0
- package/dist/scripts/test-credit-renewal.js.map +1 -0
- package/dist/scripts/update.d.ts +24 -0
- package/dist/scripts/update.d.ts.map +1 -0
- package/dist/scripts/update.js +650 -0
- package/dist/scripts/update.js.map +1 -0
- package/dist/scripts/validate_bots.d.ts +16 -0
- package/dist/scripts/validate_bots.d.ts.map +1 -0
- package/dist/scripts/validate_bots.js +106 -0
- package/dist/scripts/validate_bots.js.map +1 -0
- package/dist/scripts/verify-browser-bundle.d.ts +22 -0
- package/dist/scripts/verify-browser-bundle.d.ts.map +1 -0
- package/dist/scripts/verify-browser-bundle.js +339 -0
- package/dist/scripts/verify-browser-bundle.js.map +1 -0
- package/dist/unlock.d.ts +48 -0
- package/dist/unlock.d.ts.map +1 -0
- package/dist/unlock.js +925 -0
- package/dist/unlock.js.map +1 -0
- package/package.json +112 -0
- package/scripts/README.md +356 -0
- package/scripts/clear-all.sh +195 -0
- package/scripts/clear-logs.sh +95 -0
- package/scripts/clear-market-adapter.sh +196 -0
- package/scripts/clear-orders.sh +113 -0
- package/scripts/create-bot-symlinks.sh +51 -0
- package/scripts/postinstall.js +9 -0
- package/scripts/reset-settings.sh +118 -0
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// node-only entry point — credential daemon (Unix socket, net, os, fs)
|
|
4
|
+
/**
|
|
5
|
+
* credential-daemon.ts - Secure Private Key Server
|
|
6
|
+
*
|
|
7
|
+
* DEXBot credential daemon for multi-bot private key management.
|
|
8
|
+
* Enables bot processes to request pre-decrypted keys via Unix socket.
|
|
9
|
+
* Keeps the derived vault secret in RAM so key updates remain visible while the daemon runs.
|
|
10
|
+
*
|
|
11
|
+
* ===============================================================================
|
|
12
|
+
* DAEMON OPERATION
|
|
13
|
+
* ===============================================================================
|
|
14
|
+
*
|
|
15
|
+
* STARTUP:
|
|
16
|
+
* 1. Prompts for master password ONCE at startup
|
|
17
|
+
* 2. Authenticates with profiles/keys.json
|
|
18
|
+
* 3. Re-wraps the decrypted account cache with a random session secret
|
|
19
|
+
* 4. Keeps the derived vault secret and session cache in RAM during operation
|
|
20
|
+
* 5. Listens on Unix socket for credential requests
|
|
21
|
+
* 6. Services private key requests from bot processes
|
|
22
|
+
*
|
|
23
|
+
* COMMUNICATION:
|
|
24
|
+
* - Socket: profiles/run/dexbot-cred-daemon.sock (or $DEXBOT_CRED_RUNTIME_DIR, or $XDG_RUNTIME_DIR/dexbot2/)
|
|
25
|
+
* - Ready file: profiles/run/dexbot-cred-daemon.ready (or $DEXBOT_CRED_RUNTIME_DIR, or $XDG_RUNTIME_DIR/dexbot2/)
|
|
26
|
+
* - Startup timeout: 60 seconds (DAEMON_STARTUP_TIMEOUT_MS)
|
|
27
|
+
* - Linux only (Unix socket)
|
|
28
|
+
*
|
|
29
|
+
* REQUEST FORMAT:
|
|
30
|
+
* {"type": "ping", "accountName": "account-name"}
|
|
31
|
+
* {"type": "probe-account", "accountName": "account-name"}
|
|
32
|
+
* {"type": "broadcast-operation", "sessionId": "...", "accountName": "account-name", "operation": {...}}
|
|
33
|
+
* {"type": "execute-operations", "sessionId": "...", "accountName": "account-name", "operations": [...]}
|
|
34
|
+
*
|
|
35
|
+
* RESPONSE FORMAT:
|
|
36
|
+
* Success: {"success": true, ...}
|
|
37
|
+
* Failure: {"success": false, "error": "Error message"}
|
|
38
|
+
*
|
|
39
|
+
* ===============================================================================
|
|
40
|
+
* SECURITY BENEFITS
|
|
41
|
+
* ===============================================================================
|
|
42
|
+
*
|
|
43
|
+
* - Master password prompt only once (at daemon startup)
|
|
44
|
+
* - Individual bot processes have no access to the derived vault secret
|
|
45
|
+
* - No persisted raw password in environment variables or config files
|
|
46
|
+
* - Private keys never written to disk unencrypted
|
|
47
|
+
* - Centralized key management
|
|
48
|
+
* - Unix socket provides process-level isolation
|
|
49
|
+
*
|
|
50
|
+
* ===============================================================================
|
|
51
|
+
* USAGE
|
|
52
|
+
* ===============================================================================
|
|
53
|
+
*
|
|
54
|
+
* Direct:
|
|
55
|
+
* tsx credential-daemon.ts
|
|
56
|
+
*
|
|
57
|
+
* Via PM2 (recommended):
|
|
58
|
+
* npm run unlock
|
|
59
|
+
* or: node unlock
|
|
60
|
+
*
|
|
61
|
+
* Bot processes then access keys automatically via socket connection.
|
|
62
|
+
*
|
|
63
|
+
* ===============================================================================
|
|
64
|
+
*/
|
|
65
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
+
const { setUmask } = require('./modules/config');
|
|
67
|
+
setUmask(0o077);
|
|
68
|
+
const net = require('net');
|
|
69
|
+
const fs = require('fs');
|
|
70
|
+
const { path } = require('./modules/path_api');
|
|
71
|
+
const os = require('os');
|
|
72
|
+
const { randomBytes } = require('./modules/crypto/sync');
|
|
73
|
+
const chainKeys = require('./modules/chain_keys');
|
|
74
|
+
const { TIMING, NODE_MANAGEMENT, DAEMON_ERRORS, DAEMON_CODES } = require('./modules/constants');
|
|
75
|
+
const { readGeneralSettings } = require('./modules/general_settings');
|
|
76
|
+
const { orderNodesForSettings } = require('./modules/node_health_cache');
|
|
77
|
+
const credentialPolicy = require('./modules/credential_policy');
|
|
78
|
+
const { getStorage } = require('./modules/storage');
|
|
79
|
+
const storage = getStorage();
|
|
80
|
+
let _nativeChainClient = null;
|
|
81
|
+
let _nativeNodeList = [];
|
|
82
|
+
const native = require('./modules/bitshares-native');
|
|
83
|
+
_nativeChainClient = native.createChainClient({ rpcTimeoutMs: TIMING.CONNECTION_TIMEOUT_MS, connectTimeoutMs: TIMING.CONNECTION_TIMEOUT_MS });
|
|
84
|
+
// Register asset-ref resolver so the credential policy can resolve symbol
|
|
85
|
+
// names (e.g. "BTS" -> "1.3.0") using the native chain client instead of
|
|
86
|
+
// the legacy global BitShares object (which is not initialised in daemon
|
|
87
|
+
// context).
|
|
88
|
+
const assetResolver = async (assetRef) => {
|
|
89
|
+
try {
|
|
90
|
+
if (_nativeChainClient.getStatus() !== 'connected') {
|
|
91
|
+
_nativeChainClient.setNodes(_nativeNodeList.length > 0 ? _nativeNodeList : NODE_MANAGEMENT.DEFAULT_NODES);
|
|
92
|
+
await _nativeChainClient.connect();
|
|
93
|
+
}
|
|
94
|
+
const result = await _nativeChainClient.db.lookup_asset_symbols([assetRef]);
|
|
95
|
+
const asset = Array.isArray(result) ? result[0] : null;
|
|
96
|
+
return asset?.id ? String(asset.id) : null;
|
|
97
|
+
}
|
|
98
|
+
catch (_) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
credentialPolicy.setExternalAssetResolver(assetResolver);
|
|
103
|
+
_nativeNodeList = [];
|
|
104
|
+
const { assertPrivatePathSecurity, ensureCredentialRuntimeDirSync, getCredentialReadyFilePath, getCredentialRuntimeDir, getCredentialSocketPath, } = require('./modules/credential_runtime');
|
|
105
|
+
const { buildSessionAccountCache, loadDaemonPrivateKey, } = require('./modules/credential_session_cache');
|
|
106
|
+
const { fetchBootstrapPassword } = require('./modules/launcher/credential_bootstrap');
|
|
107
|
+
const { normalizeBootstrapCredential } = require('./modules/launcher/credential_secret');
|
|
108
|
+
const Logger = require('./modules/logger');
|
|
109
|
+
const { ensureDir, safeUnlink } = require('./modules/utils/fs_utils');
|
|
110
|
+
const { Config } = require('./modules/config');
|
|
111
|
+
const daemonLogger = new Logger('credential-daemon');
|
|
112
|
+
// Resolve project root — handles running from dist/ (compiled) vs source
|
|
113
|
+
const { PATHS } = require('./modules/paths');
|
|
114
|
+
const PROJECT_ROOT = PATHS.PROJECT_ROOT;
|
|
115
|
+
// Unix sockets are required; only Unix-like systems are supported
|
|
116
|
+
const RUNTIME_DIR = getCredentialRuntimeDir({ root: PATHS.PROJECT_ROOT });
|
|
117
|
+
const SOCKET_PATH = getCredentialSocketPath({ root: PATHS.PROJECT_ROOT, runtimeDir: RUNTIME_DIR });
|
|
118
|
+
const READY_FILE = getCredentialReadyFilePath({ root: PATHS.PROJECT_ROOT, runtimeDir: RUNTIME_DIR });
|
|
119
|
+
let vaultSecret = null;
|
|
120
|
+
let sessionSecret = null;
|
|
121
|
+
let sessionAccountKeys = new Map();
|
|
122
|
+
let server = null;
|
|
123
|
+
let daemonShuttingDown = false;
|
|
124
|
+
// Policy layer and session management
|
|
125
|
+
let policyConfig = null;
|
|
126
|
+
let activeSessions = new Map();
|
|
127
|
+
let auditLogPath = null;
|
|
128
|
+
let auditLogQueue = Promise.resolve();
|
|
129
|
+
// Policy-file watcher (cleared on shutdown so we don't leak the inotify FD
|
|
130
|
+
// or fire a debounced reload after secrets have been zeroed).
|
|
131
|
+
let policyWatcher = null;
|
|
132
|
+
let policyWatchDebounce = null;
|
|
133
|
+
function debugLog(message, err = null) {
|
|
134
|
+
const suffix = err && err.message ? `: ${err.message}` : '';
|
|
135
|
+
daemonLogger.error(`[credential-daemon][debug] ${message}${suffix}`);
|
|
136
|
+
}
|
|
137
|
+
function formatFatalReason(reason) {
|
|
138
|
+
if (!reason)
|
|
139
|
+
return 'unknown';
|
|
140
|
+
if (reason instanceof Error)
|
|
141
|
+
return reason.stack || reason.message;
|
|
142
|
+
if (typeof reason === 'object') {
|
|
143
|
+
try {
|
|
144
|
+
return JSON.stringify(reason);
|
|
145
|
+
}
|
|
146
|
+
catch (_) {
|
|
147
|
+
return String(reason);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return String(reason);
|
|
151
|
+
}
|
|
152
|
+
function registerProcessDiagnostics() {
|
|
153
|
+
process.on('uncaughtException', (err) => {
|
|
154
|
+
daemonLogger.error(`[credential-daemon] Uncaught exception: ${formatFatalReason(err)}`);
|
|
155
|
+
shutdown(1, 'uncaughtException');
|
|
156
|
+
});
|
|
157
|
+
process.on('unhandledRejection', (reason) => {
|
|
158
|
+
daemonLogger.error(`[credential-daemon] Unhandled rejection: ${formatFatalReason(reason)}`);
|
|
159
|
+
shutdown(1, 'unhandledRejection');
|
|
160
|
+
});
|
|
161
|
+
process.on('exit', (code) => {
|
|
162
|
+
daemonLogger.log?.(`[credential-daemon] Process exiting with code ${code}`);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Policy and session management helpers
|
|
167
|
+
*/
|
|
168
|
+
function generateSessionId() {
|
|
169
|
+
return randomBytes(16).toString('hex');
|
|
170
|
+
}
|
|
171
|
+
function purgeExpiredSessions() {
|
|
172
|
+
const ttl = (policyConfig && policyConfig.sessionTtlMs) || 86400000;
|
|
173
|
+
const now = Date.now();
|
|
174
|
+
for (const [id, session] of activeSessions) {
|
|
175
|
+
if (now - session.createdAt > ttl) {
|
|
176
|
+
activeSessions.delete(id);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function checkSessionValid(accountName, sessionId) {
|
|
181
|
+
purgeExpiredSessions();
|
|
182
|
+
if (!sessionId) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const session = activeSessions.get(sessionId);
|
|
186
|
+
return session && session.accountName === accountName;
|
|
187
|
+
}
|
|
188
|
+
function queueAuditLogWork(work) {
|
|
189
|
+
auditLogQueue = auditLogQueue
|
|
190
|
+
.then(() => Promise.resolve().then(work))
|
|
191
|
+
.catch((err) => {
|
|
192
|
+
debugLog('Audit log operation failed', err);
|
|
193
|
+
});
|
|
194
|
+
return auditLogQueue;
|
|
195
|
+
}
|
|
196
|
+
function performAuditLogPrune() {
|
|
197
|
+
return new Promise((resolve) => {
|
|
198
|
+
if (!auditLogPath) {
|
|
199
|
+
resolve();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const stat = storage.stat(auditLogPath);
|
|
204
|
+
const perFileLimit = Math.floor(TIMING.AUDIT_LOG_MAX_SIZE / (TIMING.AUDIT_LOG_MAX_FILES + 1));
|
|
205
|
+
if (stat.size >= perFileLimit) {
|
|
206
|
+
for (let i = TIMING.AUDIT_LOG_MAX_FILES - 1; i >= 1; i--) {
|
|
207
|
+
const oldPath = auditLogPath + '.' + i;
|
|
208
|
+
const newPath = auditLogPath + '.' + (i + 1);
|
|
209
|
+
try {
|
|
210
|
+
if (storage.exists(oldPath))
|
|
211
|
+
storage.rename(oldPath, newPath);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
debugLog('Audit log rotation rename failed', err);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
if (storage.exists(auditLogPath))
|
|
219
|
+
storage.rename(auditLogPath, auditLogPath + '.1');
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
debugLog('Audit log rotation rename failed', err);
|
|
223
|
+
}
|
|
224
|
+
resolve();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
debugLog('Audit log size check failed', err);
|
|
230
|
+
}
|
|
231
|
+
resolve();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function pruneAuditLog() {
|
|
235
|
+
return queueAuditLogWork(() => performAuditLogPrune());
|
|
236
|
+
}
|
|
237
|
+
function appendAuditLog(entry) {
|
|
238
|
+
if (!auditLogPath)
|
|
239
|
+
return;
|
|
240
|
+
const line = JSON.stringify(entry) + '\n';
|
|
241
|
+
return queueAuditLogWork(() => new Promise((resolve) => {
|
|
242
|
+
fs.appendFile(auditLogPath, line, (err) => {
|
|
243
|
+
if (err) {
|
|
244
|
+
debugLog('Audit log write failed', err);
|
|
245
|
+
}
|
|
246
|
+
resolve();
|
|
247
|
+
});
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
async function resolveVaultSecret() {
|
|
251
|
+
// NOTE: The DAEMON_PASSWORD env-var path was removed. No launcher in this
|
|
252
|
+
// codebase ever sets it, and /proc/<pid>/environ retains deleted env values
|
|
253
|
+
// in cleartext for the lifetime of the process — making it a high-value
|
|
254
|
+
// extraction target for any local same-uid process. All callers should use
|
|
255
|
+
// the one-shot bootstrap socket (DEXBOT_CRED_BOOTSTRAP_PATH_FILE) instead.
|
|
256
|
+
// Try the bootstrap path file first (stable path, no PM2 env leak).
|
|
257
|
+
// The launcher writes the one-shot bootstrap socket path to this file
|
|
258
|
+
// before starting the daemon. We read it, connect, get the secret,
|
|
259
|
+
// and delete the file. Future restarts will not find the file and
|
|
260
|
+
// will fall through to interactive auth.
|
|
261
|
+
const bootstrapPathFile = Config.DEXBOT_CRED_BOOTSTRAP_PATH_FILE;
|
|
262
|
+
if (bootstrapPathFile) {
|
|
263
|
+
try {
|
|
264
|
+
const bootstrapSocket = storage.readFile(bootstrapPathFile, 'utf-8').trim();
|
|
265
|
+
if (bootstrapSocket) {
|
|
266
|
+
// Uses delete on process.env directly (not Config) intentionally:
|
|
267
|
+
// security cleanup — scrubs the one-shot path from the env block
|
|
268
|
+
// so /proc/self/environ doesn't leak it to child processes.
|
|
269
|
+
delete process.env.DEXBOT_CRED_BOOTSTRAP_PATH_FILE;
|
|
270
|
+
safeUnlink(bootstrapPathFile);
|
|
271
|
+
daemonLogger.log?.(`[credential-daemon] Resolving vault secret from bootstrap path file: ${bootstrapSocket}`);
|
|
272
|
+
const secret = await fetchBootstrapPassword({ socketPath: bootstrapSocket, retries: 2 });
|
|
273
|
+
daemonLogger.log?.('[credential-daemon] Bootstrap secret transfer completed');
|
|
274
|
+
return normalizeBootstrapCredential(secret);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
// Bootstrap path file was consumed on a previous run (or never
|
|
279
|
+
// written). This is normal for a PM2 restart/resurrect — the
|
|
280
|
+
// daemon is locked and needs re-authentication.
|
|
281
|
+
safeUnlink(bootstrapPathFile);
|
|
282
|
+
if (!process.stdin || !process.stdin.isTTY) {
|
|
283
|
+
daemonLogger.log?.('[credential-daemon] Credential daemon is locked — no bootstrap path file and no TTY. ' +
|
|
284
|
+
'Run \'node pm2\' to unlock.');
|
|
285
|
+
// delete on process.env directly (not Config) — see note above
|
|
286
|
+
delete process.env.DEXBOT_CRED_BOOTSTRAP_PATH_FILE;
|
|
287
|
+
process.exit(0);
|
|
288
|
+
}
|
|
289
|
+
daemonLogger.log?.(`[credential-daemon] Bootstrap path file not available (${err.message}), falling back to interactive auth.`);
|
|
290
|
+
}
|
|
291
|
+
// delete on process.env directly (not Config) — see note above
|
|
292
|
+
delete process.env.DEXBOT_CRED_BOOTSTRAP_PATH_FILE;
|
|
293
|
+
}
|
|
294
|
+
daemonLogger.log?.('[credential-daemon] Resolving vault secret from interactive authentication');
|
|
295
|
+
return chainKeys.authenticate();
|
|
296
|
+
}
|
|
297
|
+
function removeSecureStaleFile(filePath, expectedType) {
|
|
298
|
+
if (!storage.exists(filePath)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
// Intentionally throws rather than silently cleaning up: if the path fails
|
|
302
|
+
// the security check (wrong owner, wrong permissions, or a symlink) we must
|
|
303
|
+
// not remove it — doing so could mask an attack. The caller is expected to
|
|
304
|
+
// surface the error and abort daemon startup.
|
|
305
|
+
assertPrivatePathSecurity(filePath, {
|
|
306
|
+
expectedType,
|
|
307
|
+
requiredMode: 0o600,
|
|
308
|
+
});
|
|
309
|
+
storage.unlink(filePath);
|
|
310
|
+
}
|
|
311
|
+
async function loadCurrentPrivateKey(accountName) {
|
|
312
|
+
return loadDaemonPrivateKey(accountName, {
|
|
313
|
+
vaultSecret,
|
|
314
|
+
sessionAccountKeys,
|
|
315
|
+
sessionSecret,
|
|
316
|
+
chainClient: _nativeChainClient,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
async function executeOperationsWithClient(client, operations) {
|
|
320
|
+
const ops = Array.isArray(operations) ? operations.filter(Boolean) : [];
|
|
321
|
+
if (ops.length === 0) {
|
|
322
|
+
return { success: true, operation_results: [], raw: null };
|
|
323
|
+
}
|
|
324
|
+
if (client.initPromise) {
|
|
325
|
+
await client.initPromise;
|
|
326
|
+
}
|
|
327
|
+
if (typeof client.newTx !== 'function') {
|
|
328
|
+
throw new Error('Signing client does not support newTx()');
|
|
329
|
+
}
|
|
330
|
+
const tx = client.newTx();
|
|
331
|
+
for (const op of ops) {
|
|
332
|
+
if (!op || !op.op_name || !op.op_data) {
|
|
333
|
+
throw new Error('Each operation requires op_name and op_data');
|
|
334
|
+
}
|
|
335
|
+
if (typeof tx[op.op_name] !== 'function') {
|
|
336
|
+
throw new Error(`Transaction builder does not support ${op.op_name}`);
|
|
337
|
+
}
|
|
338
|
+
tx[op.op_name](op.op_data);
|
|
339
|
+
}
|
|
340
|
+
const result = await tx.broadcast();
|
|
341
|
+
const operationResults = (result && Array.isArray(result.operation_results) && result.operation_results.length > 0 && result.operation_results) ||
|
|
342
|
+
(result && result.trx && Array.isArray(result.trx.operation_results) && result.trx.operation_results.length > 0 && result.trx.operation_results) ||
|
|
343
|
+
(Array.isArray(result) && result[0] && result[0].trx && Array.isArray(result[0].trx.operation_results) && result[0].trx.operation_results.length > 0 && result[0].trx.operation_results) ||
|
|
344
|
+
[];
|
|
345
|
+
return {
|
|
346
|
+
success: true,
|
|
347
|
+
raw: result,
|
|
348
|
+
operation_results: operationResults,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
async function broadcastWithRetry(accountName, privateKey, broadcastFn) {
|
|
352
|
+
// The inner deadline caps the TOTAL time spent across BOTH retry attempts
|
|
353
|
+
// so we always reply to the bot well before its outer socket timer
|
|
354
|
+
// (CREDENTIAL_BROADCAST_TIMEOUT_MS) fires. If we don't reply in time, the
|
|
355
|
+
// bot raises BroadcastUncertainError and enters the recovery path.
|
|
356
|
+
// See: modules/dexbot_credential_client.ts BroadcastUncertainError.
|
|
357
|
+
const innerDeadlineMs = Number.isFinite(Number(TIMING?.CREDENTIAL_DAEMON_INNER_DEADLINE_MS))
|
|
358
|
+
? Number(TIMING.CREDENTIAL_DAEMON_INNER_DEADLINE_MS)
|
|
359
|
+
: 20000;
|
|
360
|
+
const startedAt = Date.now();
|
|
361
|
+
let deadlineTimer = null;
|
|
362
|
+
const deadlinePromise = new Promise((_, reject) => {
|
|
363
|
+
deadlineTimer = setTimeout(() => {
|
|
364
|
+
const err = new Error(`${DAEMON_CODES.BROADCAST_DEADLINE}:inner broadcast deadline ${innerDeadlineMs}ms exceeded`);
|
|
365
|
+
err.code = DAEMON_CODES.BROADCAST_DEADLINE;
|
|
366
|
+
err.uncertain = true;
|
|
367
|
+
err.accountName = accountName;
|
|
368
|
+
err.startedAt = startedAt;
|
|
369
|
+
err.ageMs = Date.now() - startedAt;
|
|
370
|
+
reject(err);
|
|
371
|
+
}, innerDeadlineMs);
|
|
372
|
+
});
|
|
373
|
+
const maxRetries = TIMING?.CREDENTIAL_DAEMON_BROADCAST_RETRIES ?? 2;
|
|
374
|
+
const work = (async () => {
|
|
375
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
376
|
+
try {
|
|
377
|
+
if (_nativeChainClient.getStatus() !== 'connected') {
|
|
378
|
+
_nativeChainClient.setNodes(_nativeNodeList.length > 0 ? _nativeNodeList : NODE_MANAGEMENT.DEFAULT_NODES);
|
|
379
|
+
await _nativeChainClient.connect();
|
|
380
|
+
}
|
|
381
|
+
const { createSigningClient } = require('./modules/bitshares-native');
|
|
382
|
+
const signingClient = createSigningClient(_nativeChainClient, accountName, privateKey);
|
|
383
|
+
const client = signingClient.client;
|
|
384
|
+
await client.initPromise;
|
|
385
|
+
return await broadcastFn(client);
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
if (attempt === maxRetries)
|
|
389
|
+
throw err;
|
|
390
|
+
debugLog(`Broadcast failed (attempt ${attempt}), reconnecting: ${err.message}`);
|
|
391
|
+
try {
|
|
392
|
+
_nativeChainClient.disconnect();
|
|
393
|
+
}
|
|
394
|
+
catch (_) { }
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
})();
|
|
398
|
+
try {
|
|
399
|
+
return await Promise.race([work, deadlinePromise]);
|
|
400
|
+
}
|
|
401
|
+
finally {
|
|
402
|
+
if (deadlineTimer)
|
|
403
|
+
clearTimeout(deadlineTimer);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Refresh the BitShares node list from the health cache.
|
|
408
|
+
* Ensures the daemon isn't stuck on stale nodes if they fail during long uptime.
|
|
409
|
+
*/
|
|
410
|
+
function refreshNodeList() {
|
|
411
|
+
const settings = readGeneralSettings({ fallback: null });
|
|
412
|
+
const nodeSettings = settings?.NODES;
|
|
413
|
+
const nodeManagerEnabled = nodeSettings?.enabled ?? NODE_MANAGEMENT.DEFAULT_ENABLED;
|
|
414
|
+
if (nodeManagerEnabled) {
|
|
415
|
+
try {
|
|
416
|
+
const bestNodes = orderNodesForSettings(settings);
|
|
417
|
+
if (bestNodes && bestNodes.length > 0) {
|
|
418
|
+
_nativeNodeList = bestNodes;
|
|
419
|
+
_nativeChainClient.setNodes(bestNodes);
|
|
420
|
+
daemonLogger.log?.(`[credential-daemon] Node list refreshed: using best ${bestNodes.length} nodes from cache.`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
catch (err) {
|
|
424
|
+
daemonLogger.warn?.(`[credential-daemon] Failed to refresh node list: ${err.message}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function getCredentialDaemonNodeRefreshIntervalMs(settings) {
|
|
429
|
+
const configured = settings?.NODES?.credentialDaemonRefreshIntervalMs
|
|
430
|
+
?? settings?.NODES?.CREDENTIAL_DAEMON_NODE_REFRESH_INTERVAL_MS
|
|
431
|
+
?? NODE_MANAGEMENT.CREDENTIAL_DAEMON_NODE_REFRESH_INTERVAL_MS;
|
|
432
|
+
return Number.isFinite(configured) && configured > 0
|
|
433
|
+
? configured
|
|
434
|
+
: NODE_MANAGEMENT.CREDENTIAL_DAEMON_NODE_REFRESH_INTERVAL_MS;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Initialize daemon: authenticate and start listening
|
|
438
|
+
*/
|
|
439
|
+
async function initialize() {
|
|
440
|
+
try {
|
|
441
|
+
// Check if profiles/keys.json exists
|
|
442
|
+
const keysPath = path.join(PATHS.PROJECT_ROOT, 'profiles', 'keys.json');
|
|
443
|
+
if (!storage.exists(keysPath)) {
|
|
444
|
+
throw new Error('profiles/keys.json not found. Please run: tsx dexbot.ts keys');
|
|
445
|
+
}
|
|
446
|
+
// Accept a one-shot bootstrap secret when launched by a wrapper,
|
|
447
|
+
// otherwise prompt once interactively.
|
|
448
|
+
vaultSecret = await resolveVaultSecret();
|
|
449
|
+
const accountsData = chainKeys.loadAccounts();
|
|
450
|
+
const sessionState = buildSessionAccountCache(accountsData, vaultSecret, {
|
|
451
|
+
onDecryptError: (accountName, err) => {
|
|
452
|
+
debugLog(`Skipping account '${accountName}' — decryption failed: ${err.message}`);
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
sessionAccountKeys = sessionState.cache;
|
|
456
|
+
sessionSecret = sessionState.sessionSecret;
|
|
457
|
+
if (accountsData && typeof accountsData === 'object') {
|
|
458
|
+
accountsData.accounts = null;
|
|
459
|
+
}
|
|
460
|
+
// Load policy config — auto-remediate legacy 0o644 permissions first
|
|
461
|
+
const policyConfigPath = PATHS.PROFILES.DAEMON_POLICIES_JSON;
|
|
462
|
+
credentialPolicy.checkPolicyFileSecurity(policyConfigPath);
|
|
463
|
+
policyConfig = credentialPolicy.loadRequiredPolicyConfig(policyConfigPath);
|
|
464
|
+
// Set audit log path
|
|
465
|
+
const auditLogDir = PATHS.LOGS_DIR;
|
|
466
|
+
if (!storage.exists(auditLogDir)) {
|
|
467
|
+
try {
|
|
468
|
+
ensureDir(auditLogDir, { mode: 0o700 });
|
|
469
|
+
}
|
|
470
|
+
catch (err) {
|
|
471
|
+
debugLog(`Failed to create audit log directory ${auditLogDir}: ${err.message}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
auditLogPath = path.join(auditLogDir, 'daemon-audit.jsonl');
|
|
475
|
+
// Apply configured node list so the daemon uses the same
|
|
476
|
+
// nodes as bot processes (when node management is enabled),
|
|
477
|
+
// without instantiating NodeManager (which was crashing the
|
|
478
|
+
// daemon ~80s after startup). Mirror the enabled check from
|
|
479
|
+
// bitshares_client.ts so both stay aligned.
|
|
480
|
+
const settings = readGeneralSettings({ fallback: null });
|
|
481
|
+
refreshNodeList();
|
|
482
|
+
// Fire-and-forget connect so the asset resolver works on first request
|
|
483
|
+
_nativeChainClient.setNodes(_nativeNodeList.length > 0 ? _nativeNodeList : NODE_MANAGEMENT.DEFAULT_NODES);
|
|
484
|
+
_nativeChainClient.connect().catch(() => { });
|
|
485
|
+
// Lightweight node list refresh from the health cache. This is separate
|
|
486
|
+
// from updater schedules and does not run active node probes.
|
|
487
|
+
const nodeRefreshInterval = setInterval(refreshNodeList, getCredentialDaemonNodeRefreshIntervalMs(settings));
|
|
488
|
+
if (typeof nodeRefreshInterval.unref === 'function') {
|
|
489
|
+
nodeRefreshInterval.unref();
|
|
490
|
+
}
|
|
491
|
+
// Audit log prune on a timer (M5): replaces inline pruning on every
|
|
492
|
+
// append, which caused read+rewrite of the entire file on each signed
|
|
493
|
+
// operation. Hourly prune is sufficient for the 7-day retention window.
|
|
494
|
+
const AUDIT_LOG_PRUNE_INTERVAL_MS = 60 * 60 * 1000;
|
|
495
|
+
const auditPruneInterval = setInterval(() => { pruneAuditLog(); }, AUDIT_LOG_PRUNE_INTERVAL_MS);
|
|
496
|
+
if (typeof auditPruneInterval.unref === 'function') {
|
|
497
|
+
auditPruneInterval.unref();
|
|
498
|
+
}
|
|
499
|
+
// Register SIGHUP handler for policy and node list reload.
|
|
500
|
+
// PM2 may forward SIGHUP on terminal disconnect, but we treat it
|
|
501
|
+
// as a trigger to refresh configuration.
|
|
502
|
+
process.on('SIGHUP', () => {
|
|
503
|
+
daemonLogger.log?.('[credential-daemon] SIGHUP received: refreshing configuration and node list...');
|
|
504
|
+
// Strict reload: fail closed if the operator just wrote an
|
|
505
|
+
// invalid policy. The try/catch wraps shutdown() so a
|
|
506
|
+
// successful reload falls through to refreshNodeList().
|
|
507
|
+
try {
|
|
508
|
+
policyConfig = credentialPolicy.reloadPolicyFromDisk(policyConfigPath, { strict: true });
|
|
509
|
+
debugLog('Policy config reloaded');
|
|
510
|
+
}
|
|
511
|
+
catch (err) {
|
|
512
|
+
daemonLogger.error?.(`[credential-daemon] SIGHUP policy reload failed: ${err.message}`);
|
|
513
|
+
shutdown(1, 'invalid policy reload');
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
// Reload node list
|
|
517
|
+
refreshNodeList();
|
|
518
|
+
});
|
|
519
|
+
// Watch policy config file for external changes (e.g. auto-provision
|
|
520
|
+
// of botHmacSecret by a bot process). fs.watch fires multiple events
|
|
521
|
+
// per atomic rename, so debounce with a 500ms settle window.
|
|
522
|
+
// This is the safety net that makes C2 fixes work end-to-end: the bot
|
|
523
|
+
// writes a new secret, sends SIGHUP, and even if SIGHUP is lost or
|
|
524
|
+
// delayed, the daemon picks up the change within 500ms.
|
|
525
|
+
try {
|
|
526
|
+
policyWatcher = fs.watch(policyConfigPath, { persistent: false }, (eventType) => {
|
|
527
|
+
if (policyWatchDebounce)
|
|
528
|
+
clearTimeout(policyWatchDebounce);
|
|
529
|
+
policyWatchDebounce = setTimeout(() => {
|
|
530
|
+
policyWatchDebounce = null;
|
|
531
|
+
const newConfig = credentialPolicy.reloadPolicyFromDisk(policyConfigPath);
|
|
532
|
+
if (newConfig) {
|
|
533
|
+
policyConfig = newConfig;
|
|
534
|
+
debugLog(`Policy config reloaded via fs.watch (${eventType})`);
|
|
535
|
+
}
|
|
536
|
+
// On non-strict failure, reloadPolicyFromDisk already logs
|
|
537
|
+
// a warn; the existing in-memory config is kept. This is
|
|
538
|
+
// intentionally distinct from SIGHUP's fail-closed policy.
|
|
539
|
+
}, 500);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
catch (watchErr) {
|
|
543
|
+
// fs.watch can fail on exotic filesystems (network FS, FUSE).
|
|
544
|
+
// Log at WARN (not debug): without the watch AND without a
|
|
545
|
+
// successful SIGHUP from the bot, the daemon keeps the stale
|
|
546
|
+
// botHmacSecret until restart. Operators need to see this.
|
|
547
|
+
daemonLogger.warn?.(`[credential-daemon] Could not watch policy config file ${policyConfigPath}: ${watchErr.message}. SIGHUP from bot process is now the only reload path.`);
|
|
548
|
+
}
|
|
549
|
+
ensureCredentialRuntimeDirSync({ root: PATHS.PROJECT_ROOT, runtimeDir: RUNTIME_DIR, socketPath: SOCKET_PATH, readyFilePath: READY_FILE });
|
|
550
|
+
daemonLogger.log?.(`[credential-daemon] Runtime socket path: ${SOCKET_PATH}`);
|
|
551
|
+
daemonLogger.log?.(`[credential-daemon] Ready file path: ${READY_FILE}`);
|
|
552
|
+
// Clean up old socket if it exists
|
|
553
|
+
try {
|
|
554
|
+
removeSecureStaleFile(SOCKET_PATH, 'socket');
|
|
555
|
+
removeSecureStaleFile(READY_FILE, 'file');
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
throw new Error(`Insecure credential runtime path detected: ${err.message}`);
|
|
559
|
+
}
|
|
560
|
+
// Create server
|
|
561
|
+
server = net.createServer(handleConnection);
|
|
562
|
+
server.listen(SOCKET_PATH, () => {
|
|
563
|
+
try {
|
|
564
|
+
storage.chmod(SOCKET_PATH, 0o600);
|
|
565
|
+
assertPrivatePathSecurity(SOCKET_PATH, { expectedType: 'socket', requiredMode: 0o600 });
|
|
566
|
+
}
|
|
567
|
+
catch (err) {
|
|
568
|
+
daemonLogger.error?.(`[credential-daemon] FATAL: Insecure socket permissions on ${SOCKET_PATH}: ${err.message}`);
|
|
569
|
+
shutdown(1, 'insecure socket permissions');
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
// Create ready file to signal startup completion.
|
|
573
|
+
// Open with explicit 0o600 mode to avoid the TOCTOU window between
|
|
574
|
+
// writeFileSync and chmodSync (the file is never world-readable).
|
|
575
|
+
// Write JSON with pid so callers can send SIGHUP to trigger policy reload.
|
|
576
|
+
try {
|
|
577
|
+
const readyPayload = JSON.stringify({ pid: process.pid, startedAt: new Date().toISOString() });
|
|
578
|
+
storage.writeFile(READY_FILE, readyPayload, { mode: 0o600 });
|
|
579
|
+
assertPrivatePathSecurity(READY_FILE, { expectedType: 'file', requiredMode: 0o600 });
|
|
580
|
+
daemonLogger.log?.(`[credential-daemon] Ready: listening on ${SOCKET_PATH}`);
|
|
581
|
+
}
|
|
582
|
+
catch (err) {
|
|
583
|
+
daemonLogger.error?.(`[credential-daemon] FATAL: Insecure ready-file permissions on ${READY_FILE}: ${err.message}`);
|
|
584
|
+
shutdown(1, 'insecure ready-file permissions');
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
server.on('error', (error) => {
|
|
589
|
+
daemonLogger.error(`Server error: ${error.message}`);
|
|
590
|
+
process.exit(1);
|
|
591
|
+
});
|
|
592
|
+
// Handle graceful shutdown.
|
|
593
|
+
// SIGTERM is sent by PM2 when stopping the daemon — honour it.
|
|
594
|
+
// SIGINT is from stray Ctrl-C in the parent terminal; under PM2
|
|
595
|
+
// management we ignore it so the daemon stays alive. When running
|
|
596
|
+
// interactively (not via PM2), SIGINT still works because the
|
|
597
|
+
// process group leader is the shell.
|
|
598
|
+
process.on('SIGTERM', () => shutdown(0, 'SIGTERM'));
|
|
599
|
+
process.on('SIGINT', () => {
|
|
600
|
+
daemonLogger.log?.('[credential-daemon] SIGINT ignored (daemon is managed by PM2; use `pm2 stop dexbot-cred` to shut down).');
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
catch (error) {
|
|
604
|
+
daemonLogger.error(`[credential-daemon] Startup failed: ${error.stack || error.message}`);
|
|
605
|
+
shutdown(1, 'startup failure');
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Handle incoming client connection to daemon.
|
|
610
|
+
* Reads newline-delimited JSON requests and processes credential requests.
|
|
611
|
+
*
|
|
612
|
+
* @param {net.Socket} socket - Connected client socket
|
|
613
|
+
*/
|
|
614
|
+
function handleConnection(socket) {
|
|
615
|
+
let buffer = '';
|
|
616
|
+
socket.on('data', (data) => {
|
|
617
|
+
try {
|
|
618
|
+
buffer += data.toString();
|
|
619
|
+
// Look for newline-delimited JSON
|
|
620
|
+
const lines = buffer.split('\n');
|
|
621
|
+
buffer = lines.pop() || ''; // Keep incomplete line in buffer
|
|
622
|
+
for (const line of lines) {
|
|
623
|
+
if (line.trim()) {
|
|
624
|
+
processRequest(line.trim(), socket);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
sendError(socket, 'Invalid request');
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
socket.on('end', () => {
|
|
633
|
+
// Connection closed
|
|
634
|
+
});
|
|
635
|
+
socket.on('error', (_error) => {
|
|
636
|
+
// Client disconnected or error
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Process incoming credential request from client.
|
|
641
|
+
* Validates request format and retrieves private key if valid.
|
|
642
|
+
* Sends success or error response back to client.
|
|
643
|
+
*
|
|
644
|
+
* @param {string} requestStr - JSON string with {type, accountName}
|
|
645
|
+
* @param {net.Socket} socket - Client socket to send response
|
|
646
|
+
*/
|
|
647
|
+
function processRequest(requestStr, socket) {
|
|
648
|
+
// The outer try/catch handles JSON parse errors and any synchronous throws.
|
|
649
|
+
// Each async branch manages its own errors via .catch() → sendError(), so
|
|
650
|
+
// the outer catch is not expected to fire for async operation failures.
|
|
651
|
+
try {
|
|
652
|
+
const request = JSON.parse(requestStr);
|
|
653
|
+
const { type, accountName } = request;
|
|
654
|
+
if (!type) {
|
|
655
|
+
return sendError(socket, 'Missing "type" field');
|
|
656
|
+
}
|
|
657
|
+
if (!accountName) {
|
|
658
|
+
return sendError(socket, 'Missing "accountName" field');
|
|
659
|
+
}
|
|
660
|
+
if (type === 'ping') {
|
|
661
|
+
// Lightweight health check — no session created, no audit log entry.
|
|
662
|
+
// Used by the credential daemon watchdog and pre-write probes where
|
|
663
|
+
// we only need to verify the daemon is alive, not establish a session.
|
|
664
|
+
sendSuccess(socket, { pong: true });
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (type === 'probe-account') {
|
|
668
|
+
loadCurrentPrivateKey(accountName)
|
|
669
|
+
.then(() => {
|
|
670
|
+
// Session registration
|
|
671
|
+
const sessionId = generateSessionId();
|
|
672
|
+
activeSessions.set(sessionId, {
|
|
673
|
+
accountName,
|
|
674
|
+
createdAt: Date.now(),
|
|
675
|
+
});
|
|
676
|
+
appendAuditLog({
|
|
677
|
+
event: 'session_created',
|
|
678
|
+
accountName,
|
|
679
|
+
sessionId,
|
|
680
|
+
timestamp: new Date().toISOString(),
|
|
681
|
+
});
|
|
682
|
+
sendSuccess(socket, { sessionId });
|
|
683
|
+
})
|
|
684
|
+
.catch((error) => sendError(socket, error.message));
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
if (type === 'broadcast-operation') {
|
|
688
|
+
const operation = request.operation;
|
|
689
|
+
if (!operation || typeof operation !== 'object') {
|
|
690
|
+
return sendError(socket, 'Missing "operation" field');
|
|
691
|
+
}
|
|
692
|
+
const sessionId = request.sessionId || null;
|
|
693
|
+
// Session validation
|
|
694
|
+
if (!checkSessionValid(accountName, sessionId)) {
|
|
695
|
+
const reason = DAEMON_ERRORS.SESSION_EXPIRED;
|
|
696
|
+
appendAuditLog({
|
|
697
|
+
event: 'sign_denied',
|
|
698
|
+
accountName,
|
|
699
|
+
sessionId,
|
|
700
|
+
reason: 'session: ' + reason,
|
|
701
|
+
timestamp: new Date().toISOString(),
|
|
702
|
+
});
|
|
703
|
+
return sendError(socket, credentialPolicy.POLICY_DENIED_PREFIX + reason);
|
|
704
|
+
}
|
|
705
|
+
// Source authentication (HMAC verification)
|
|
706
|
+
// For broadcast-operation, we verify HMAC over [operation] (single-element array)
|
|
707
|
+
const hmacResult = credentialPolicy.verifySourceHmac({ ...request, operations: [operation] }, policyConfig);
|
|
708
|
+
if (!hmacResult.valid) {
|
|
709
|
+
appendAuditLog({
|
|
710
|
+
event: 'sign_denied',
|
|
711
|
+
accountName,
|
|
712
|
+
sessionId,
|
|
713
|
+
reason: 'source: ' + hmacResult.reason,
|
|
714
|
+
timestamp: new Date().toISOString(),
|
|
715
|
+
});
|
|
716
|
+
return sendError(socket, credentialPolicy.POLICY_DENIED_PREFIX + DAEMON_ERRORS.SOURCE_AUTH_DENIED);
|
|
717
|
+
}
|
|
718
|
+
if (hmacResult.skipped) {
|
|
719
|
+
debugLog(`[warn] no botHmacSecret configured for ${accountName} — source authentication skipped`);
|
|
720
|
+
}
|
|
721
|
+
// Policy evaluation — treat as single-operation batch
|
|
722
|
+
const policy = credentialPolicy.resolveAccountPolicy(policyConfig, accountName);
|
|
723
|
+
const context = credentialPolicy.buildPolicyContext({
|
|
724
|
+
...request,
|
|
725
|
+
operations: [operation],
|
|
726
|
+
});
|
|
727
|
+
credentialPolicy.evaluatePolicy(policy, context)
|
|
728
|
+
.then(async (result) => {
|
|
729
|
+
if (!result.allow) {
|
|
730
|
+
appendAuditLog({
|
|
731
|
+
event: 'sign_denied',
|
|
732
|
+
accountName,
|
|
733
|
+
sessionId,
|
|
734
|
+
policyId: result.policyId,
|
|
735
|
+
reason: result.reason,
|
|
736
|
+
opCount: 1,
|
|
737
|
+
opTypes: [operation && operation.op_name].filter(Boolean),
|
|
738
|
+
timestamp: new Date().toISOString(),
|
|
739
|
+
});
|
|
740
|
+
sendError(socket, credentialPolicy.POLICY_DENIED_PREFIX + result.reason);
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
const privateKey = await loadCurrentPrivateKey(accountName);
|
|
744
|
+
let signResult;
|
|
745
|
+
try {
|
|
746
|
+
signResult = await broadcastWithRetry(accountName, privateKey, (client) => client.broadcast(operation));
|
|
747
|
+
}
|
|
748
|
+
catch (broadcastErr) {
|
|
749
|
+
if (broadcastErr && broadcastErr.code === DAEMON_CODES.BROADCAST_DEADLINE) {
|
|
750
|
+
appendAuditLog({
|
|
751
|
+
event: 'sign_timeout',
|
|
752
|
+
accountName,
|
|
753
|
+
sessionId,
|
|
754
|
+
opCount: 1,
|
|
755
|
+
opTypes: [operation && operation.op_name].filter(Boolean),
|
|
756
|
+
ageMs: broadcastErr.ageMs,
|
|
757
|
+
startedAt: broadcastErr.startedAt
|
|
758
|
+
? new Date(broadcastErr.startedAt).toISOString()
|
|
759
|
+
: null,
|
|
760
|
+
timestamp: new Date().toISOString(),
|
|
761
|
+
});
|
|
762
|
+
// Tell the bot the chain state is uncertain so it
|
|
763
|
+
// can run the recovery path (read chain, match by
|
|
764
|
+
// fingerprint, adopt or discard).
|
|
765
|
+
return sendError(socket, 'chain status uncertain after inner deadline', DAEMON_CODES.BROADCAST_DEADLINE);
|
|
766
|
+
}
|
|
767
|
+
throw broadcastErr;
|
|
768
|
+
}
|
|
769
|
+
appendAuditLog({
|
|
770
|
+
event: 'sign_allowed',
|
|
771
|
+
accountName,
|
|
772
|
+
sessionId,
|
|
773
|
+
opCount: 1,
|
|
774
|
+
opTypes: [operation && operation.op_name].filter(Boolean),
|
|
775
|
+
timestamp: new Date().toISOString(),
|
|
776
|
+
});
|
|
777
|
+
sendSuccess(socket, signResult);
|
|
778
|
+
})
|
|
779
|
+
.catch((error) => sendError(socket, error.message));
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
if (type === 'execute-operations') {
|
|
783
|
+
const operations = request.operations;
|
|
784
|
+
if (!Array.isArray(operations)) {
|
|
785
|
+
return sendError(socket, 'Missing "operations" field');
|
|
786
|
+
}
|
|
787
|
+
const sessionId = request.sessionId || null;
|
|
788
|
+
// Session validation
|
|
789
|
+
if (!checkSessionValid(accountName, sessionId)) {
|
|
790
|
+
const reason = DAEMON_ERRORS.SESSION_EXPIRED;
|
|
791
|
+
appendAuditLog({
|
|
792
|
+
event: 'sign_denied',
|
|
793
|
+
accountName,
|
|
794
|
+
sessionId,
|
|
795
|
+
reason: 'session: ' + reason,
|
|
796
|
+
timestamp: new Date().toISOString(),
|
|
797
|
+
});
|
|
798
|
+
return sendError(socket, credentialPolicy.POLICY_DENIED_PREFIX + reason);
|
|
799
|
+
}
|
|
800
|
+
// Source authentication (HMAC verification)
|
|
801
|
+
const hmacResult = credentialPolicy.verifySourceHmac(request, policyConfig);
|
|
802
|
+
if (!hmacResult.valid) {
|
|
803
|
+
appendAuditLog({
|
|
804
|
+
event: 'sign_denied',
|
|
805
|
+
accountName,
|
|
806
|
+
sessionId,
|
|
807
|
+
reason: 'source: ' + hmacResult.reason,
|
|
808
|
+
timestamp: new Date().toISOString(),
|
|
809
|
+
});
|
|
810
|
+
return sendError(socket, credentialPolicy.POLICY_DENIED_PREFIX + DAEMON_ERRORS.SOURCE_AUTH_DENIED);
|
|
811
|
+
}
|
|
812
|
+
if (hmacResult.skipped) {
|
|
813
|
+
debugLog(`[warn] no botHmacSecret configured for ${accountName} — source authentication skipped`);
|
|
814
|
+
}
|
|
815
|
+
// Policy evaluation — before any key material is touched
|
|
816
|
+
const policy = credentialPolicy.resolveAccountPolicy(policyConfig, accountName);
|
|
817
|
+
const context = credentialPolicy.buildPolicyContext(request);
|
|
818
|
+
credentialPolicy.evaluatePolicy(policy, context)
|
|
819
|
+
.then(async (result) => {
|
|
820
|
+
if (!result.allow) {
|
|
821
|
+
appendAuditLog({
|
|
822
|
+
event: 'sign_denied',
|
|
823
|
+
accountName,
|
|
824
|
+
sessionId,
|
|
825
|
+
policyId: result.policyId,
|
|
826
|
+
reason: result.reason,
|
|
827
|
+
opCount: operations.length,
|
|
828
|
+
opTypes: operations.map((o) => o && o.op_name).filter(Boolean),
|
|
829
|
+
timestamp: new Date().toISOString(),
|
|
830
|
+
});
|
|
831
|
+
sendError(socket, credentialPolicy.POLICY_DENIED_PREFIX + result.reason);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const privateKey = await loadCurrentPrivateKey(accountName);
|
|
835
|
+
let signResult;
|
|
836
|
+
try {
|
|
837
|
+
signResult = await broadcastWithRetry(accountName, privateKey, (client) => executeOperationsWithClient(client, operations));
|
|
838
|
+
}
|
|
839
|
+
catch (broadcastErr) {
|
|
840
|
+
if (broadcastErr && broadcastErr.code === DAEMON_CODES.BROADCAST_DEADLINE) {
|
|
841
|
+
appendAuditLog({
|
|
842
|
+
event: 'sign_timeout',
|
|
843
|
+
accountName,
|
|
844
|
+
sessionId,
|
|
845
|
+
opCount: operations.length,
|
|
846
|
+
opTypes: operations.map((o) => o && o.op_name).filter(Boolean),
|
|
847
|
+
ageMs: broadcastErr.ageMs,
|
|
848
|
+
startedAt: broadcastErr.startedAt
|
|
849
|
+
? new Date(broadcastErr.startedAt).toISOString()
|
|
850
|
+
: null,
|
|
851
|
+
timestamp: new Date().toISOString(),
|
|
852
|
+
});
|
|
853
|
+
return sendError(socket, 'chain status uncertain after inner deadline', DAEMON_CODES.BROADCAST_DEADLINE);
|
|
854
|
+
}
|
|
855
|
+
throw broadcastErr;
|
|
856
|
+
}
|
|
857
|
+
appendAuditLog({
|
|
858
|
+
event: 'sign_allowed',
|
|
859
|
+
accountName,
|
|
860
|
+
sessionId,
|
|
861
|
+
opCount: operations.length,
|
|
862
|
+
opTypes: operations.map((o) => o && o.op_name).filter(Boolean),
|
|
863
|
+
timestamp: new Date().toISOString(),
|
|
864
|
+
});
|
|
865
|
+
sendSuccess(socket, signResult);
|
|
866
|
+
})
|
|
867
|
+
.catch((error) => sendError(socket, error.message));
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
return sendError(socket, `Unknown credential type: ${type}`);
|
|
871
|
+
}
|
|
872
|
+
catch (error) {
|
|
873
|
+
sendError(socket, error.message);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Send successful credential response to client.
|
|
878
|
+
*
|
|
879
|
+
* @param {net.Socket} socket - Client socket
|
|
880
|
+
* @param {Object} data - Response data
|
|
881
|
+
*/
|
|
882
|
+
function sendSuccess(socket, data) {
|
|
883
|
+
const response = JSON.stringify({
|
|
884
|
+
success: true,
|
|
885
|
+
...data
|
|
886
|
+
});
|
|
887
|
+
socket.write(response + '\n');
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Send error response to client.
|
|
891
|
+
*
|
|
892
|
+
* @param {net.Socket} socket - Client socket
|
|
893
|
+
* @param {string} message - Error message
|
|
894
|
+
* @param {number} code - Error code
|
|
895
|
+
*/
|
|
896
|
+
function sendError(socket, message, code = null) {
|
|
897
|
+
const response = JSON.stringify({
|
|
898
|
+
success: false,
|
|
899
|
+
error: message,
|
|
900
|
+
...(code ? { code } : {})
|
|
901
|
+
});
|
|
902
|
+
socket.write(response + '\n');
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Gracefully shutdown daemon.
|
|
906
|
+
* Clears the derived vault secret from memory and closes server.
|
|
907
|
+
* @param {number} [exitCode=0] - Process exit code
|
|
908
|
+
* @param {string} [reason='shutdown'] - Reason for shutdown (for logging)
|
|
909
|
+
*/
|
|
910
|
+
function shutdown(exitCode = 0, reason = 'shutdown') {
|
|
911
|
+
if (daemonShuttingDown)
|
|
912
|
+
return;
|
|
913
|
+
daemonShuttingDown = true;
|
|
914
|
+
daemonLogger.log?.(`[credential-daemon] Shutdown requested (${reason}, exitCode=${exitCode})`);
|
|
915
|
+
// Clear derived vault secret from memory. Vault and session secrets are
|
|
916
|
+
// plain objects ({ kind, version, vaultKeyHex }) — not Buffers — so we
|
|
917
|
+
// iterate their properties, zero any Buffer values, and null everything.
|
|
918
|
+
// Hex-string properties (vaultKeyHex, sessionSaltHex) are immutable in V8
|
|
919
|
+
// and cannot be zeroed in place; they will be reclaimed by GC after the
|
|
920
|
+
// object reference is dropped.
|
|
921
|
+
if (vaultSecret) {
|
|
922
|
+
if (Buffer.isBuffer(vaultSecret)) {
|
|
923
|
+
vaultSecret.fill(0);
|
|
924
|
+
}
|
|
925
|
+
else if (typeof vaultSecret === 'object') {
|
|
926
|
+
for (const key of Object.keys(vaultSecret)) {
|
|
927
|
+
if (Buffer.isBuffer(vaultSecret[key]))
|
|
928
|
+
vaultSecret[key].fill(0);
|
|
929
|
+
vaultSecret[key] = null;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
vaultSecret = null;
|
|
933
|
+
}
|
|
934
|
+
if (sessionSecret) {
|
|
935
|
+
if (Buffer.isBuffer(sessionSecret)) {
|
|
936
|
+
sessionSecret.fill(0);
|
|
937
|
+
}
|
|
938
|
+
else if (typeof sessionSecret === 'object') {
|
|
939
|
+
for (const key of Object.keys(sessionSecret)) {
|
|
940
|
+
if (Buffer.isBuffer(sessionSecret[key]))
|
|
941
|
+
sessionSecret[key].fill(0);
|
|
942
|
+
sessionSecret[key] = null;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
sessionSecret = null;
|
|
946
|
+
}
|
|
947
|
+
if (sessionAccountKeys) {
|
|
948
|
+
for (const [key, val] of sessionAccountKeys) {
|
|
949
|
+
if (Buffer.isBuffer(val)) {
|
|
950
|
+
val.fill(0);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
sessionAccountKeys.clear();
|
|
954
|
+
}
|
|
955
|
+
// Close server — don't wait for active connections, process.exit will
|
|
956
|
+
// tear everything down. A hanging server.close() would prevent PM2 from
|
|
957
|
+
// stopping the daemon, causing a SIGKILL after 1.6s.
|
|
958
|
+
if (server) {
|
|
959
|
+
try {
|
|
960
|
+
server.close();
|
|
961
|
+
}
|
|
962
|
+
catch (_) { }
|
|
963
|
+
}
|
|
964
|
+
// Cancel any pending policy-watch debounce and close the inotify handle.
|
|
965
|
+
// If we don't, a reload could fire AFTER secrets have been zeroed, or
|
|
966
|
+
// the watcher could keep the event loop alive briefly during shutdown.
|
|
967
|
+
if (policyWatchDebounce) {
|
|
968
|
+
clearTimeout(policyWatchDebounce);
|
|
969
|
+
policyWatchDebounce = null;
|
|
970
|
+
}
|
|
971
|
+
if (policyWatcher) {
|
|
972
|
+
try {
|
|
973
|
+
policyWatcher.close();
|
|
974
|
+
}
|
|
975
|
+
catch (_) { }
|
|
976
|
+
policyWatcher = null;
|
|
977
|
+
}
|
|
978
|
+
daemonLogger.log?.('[credential-daemon] Server closed');
|
|
979
|
+
daemonLogger.flush().finally(() => process.exit(exitCode));
|
|
980
|
+
}
|
|
981
|
+
// Start daemon
|
|
982
|
+
registerProcessDiagnostics();
|
|
983
|
+
initialize().catch(error => {
|
|
984
|
+
daemonLogger.error(`[credential-daemon] Startup failed: ${error.stack || error.message}`);
|
|
985
|
+
shutdown(1, 'startup failure');
|
|
986
|
+
});
|
|
987
|
+
//# sourceMappingURL=credential-daemon.js.map
|