chainlesschain 0.51.0 → 0.81.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/package.json +1 -1
  2. package/src/assets/web-panel/.build-hash +1 -1
  3. package/src/assets/web-panel/assets/{AppLayout-Rvi759IS.js → AppLayout-6SPt_8Y_.js} +1 -1
  4. package/src/assets/web-panel/assets/{Dashboard-DBhFxXYQ.js → Dashboard-Br7kCwKJ.js} +2 -2
  5. package/src/assets/web-panel/assets/Dashboard-CKeMmCoT.css +1 -0
  6. package/src/assets/web-panel/assets/{index-uL0cZ8N_.js → index-tN-8TosE.js} +2 -2
  7. package/src/assets/web-panel/index.html +2 -2
  8. package/src/commands/a2a.js +380 -0
  9. package/src/commands/agent-network.js +785 -0
  10. package/src/commands/automation.js +654 -0
  11. package/src/commands/bi.js +348 -0
  12. package/src/commands/crosschain.js +218 -0
  13. package/src/commands/dao.js +565 -0
  14. package/src/commands/did-v2.js +620 -0
  15. package/src/commands/dlp.js +341 -0
  16. package/src/commands/economy.js +578 -0
  17. package/src/commands/evolution.js +391 -0
  18. package/src/commands/evomap.js +394 -0
  19. package/src/commands/federation.js +283 -0
  20. package/src/commands/hmemory.js +442 -0
  21. package/src/commands/inference.js +318 -0
  22. package/src/commands/lowcode.js +356 -0
  23. package/src/commands/marketplace.js +256 -0
  24. package/src/commands/perf.js +433 -0
  25. package/src/commands/pipeline.js +449 -0
  26. package/src/commands/plugin-ecosystem.js +517 -0
  27. package/src/commands/privacy.js +321 -0
  28. package/src/commands/reputation.js +261 -0
  29. package/src/commands/sandbox.js +401 -0
  30. package/src/commands/siem.js +246 -0
  31. package/src/commands/sla.js +259 -0
  32. package/src/commands/social.js +311 -0
  33. package/src/commands/sso.js +798 -0
  34. package/src/commands/stress.js +230 -0
  35. package/src/commands/terraform.js +245 -0
  36. package/src/commands/workflow.js +320 -0
  37. package/src/commands/zkp.js +562 -1
  38. package/src/index.js +21 -0
  39. package/src/lib/a2a-protocol.js +451 -0
  40. package/src/lib/agent-economy.js +479 -0
  41. package/src/lib/agent-network.js +1121 -0
  42. package/src/lib/app-builder.js +239 -0
  43. package/src/lib/automation-engine.js +948 -0
  44. package/src/lib/bi-engine.js +338 -0
  45. package/src/lib/cross-chain.js +345 -0
  46. package/src/lib/dao-governance.js +569 -0
  47. package/src/lib/did-v2-manager.js +1127 -0
  48. package/src/lib/dlp-engine.js +389 -0
  49. package/src/lib/evolution-system.js +453 -0
  50. package/src/lib/evomap-federation.js +177 -0
  51. package/src/lib/evomap-governance.js +276 -0
  52. package/src/lib/federation-hardening.js +259 -0
  53. package/src/lib/hierarchical-memory.js +481 -0
  54. package/src/lib/inference-network.js +330 -0
  55. package/src/lib/perf-tuning.js +734 -0
  56. package/src/lib/pipeline-orchestrator.js +928 -0
  57. package/src/lib/plugin-ecosystem.js +1109 -0
  58. package/src/lib/privacy-computing.js +427 -0
  59. package/src/lib/reputation-optimizer.js +299 -0
  60. package/src/lib/sandbox-v2.js +306 -0
  61. package/src/lib/siem-exporter.js +333 -0
  62. package/src/lib/skill-marketplace.js +325 -0
  63. package/src/lib/sla-manager.js +275 -0
  64. package/src/lib/social-graph-analytics.js +707 -0
  65. package/src/lib/sso-manager.js +841 -0
  66. package/src/lib/stress-tester.js +330 -0
  67. package/src/lib/terraform-manager.js +363 -0
  68. package/src/lib/workflow-engine.js +454 -1
  69. package/src/lib/zkp-engine.js +523 -20
  70. package/src/assets/web-panel/assets/Dashboard-BS-tzGNj.css +0 -1
@@ -572,4 +572,431 @@ export function _resetState() {
572
572
  _models.clear();
573
573
  _computations.clear();
574
574
  _privacyBudget = { spent: 0, limit: DEFAULT_CONFIG.maxBudget };
575
+ _maxActiveMpcComputations = PRIVACY_DEFAULT_MAX_ACTIVE_MPC_COMPUTATIONS;
576
+ }
577
+
578
+ /* ──────────────────────────────────────────────────────────
579
+ * V2 — Phase 91 surface (strictly additive)
580
+ * ────────────────────────────────────────────────────────── */
581
+
582
+ export const FL_STATUS_V2 = FL_STATUS;
583
+
584
+ export const MPC_STATUS_V2 = Object.freeze({
585
+ PENDING: "pending",
586
+ COMPUTING: "computing",
587
+ COMPLETED: "completed",
588
+ FAILED: "failed",
589
+ });
590
+
591
+ export const DP_MECHANISM_V2 = Object.freeze({
592
+ LAPLACE: "laplace",
593
+ GAUSSIAN: "gaussian",
594
+ EXPONENTIAL: "exponential",
595
+ });
596
+
597
+ export const HE_SCHEME_V2 = Object.freeze({
598
+ PAILLIER: "paillier",
599
+ BFV: "bfv",
600
+ CKKS: "ckks",
601
+ });
602
+
603
+ export const MPC_PROTOCOL_V2 = Object.freeze({
604
+ SHAMIR: "shamir",
605
+ BEAVER: "beaver",
606
+ GMW: "gmw",
607
+ });
608
+
609
+ export const PRIVACY_DEFAULT_MAX_ACTIVE_MPC_COMPUTATIONS = 20;
610
+
611
+ let _maxActiveMpcComputations = PRIVACY_DEFAULT_MAX_ACTIVE_MPC_COMPUTATIONS;
612
+
613
+ const FL_TRANSITIONS_V2 = new Map([
614
+ ["initializing", new Set(["training", "failed"])],
615
+ ["training", new Set(["aggregating", "failed"])],
616
+ ["aggregating", new Set(["training", "completed", "failed"])],
617
+ ]);
618
+ const FL_TERMINALS_V2 = new Set(["completed", "failed"]);
619
+
620
+ const MPC_TRANSITIONS_V2 = new Map([
621
+ ["pending", new Set(["computing", "failed"])],
622
+ ["computing", new Set(["completed", "failed"])],
623
+ ]);
624
+ const MPC_TERMINALS_V2 = new Set(["completed", "failed"]);
625
+
626
+ /* ── Config ────────────────────────────────────────────── */
627
+
628
+ export function setMaxActiveMpcComputations(n) {
629
+ if (typeof n !== "number" || Number.isNaN(n) || n < 1) {
630
+ throw new Error("maxActiveMpcComputations must be a positive integer");
631
+ }
632
+ _maxActiveMpcComputations = Math.floor(n);
633
+ }
634
+
635
+ export function getMaxActiveMpcComputations() {
636
+ return _maxActiveMpcComputations;
637
+ }
638
+
639
+ export function getActiveMpcCount() {
640
+ let count = 0;
641
+ for (const c of _computations.values()) {
642
+ if (c.status === "pending" || c.status === "computing") count += 1;
643
+ }
644
+ return count;
645
+ }
646
+
647
+ export function setPrivacyBudgetLimit(n) {
648
+ if (typeof n !== "number" || Number.isNaN(n) || n <= 0) {
649
+ throw new Error("privacyBudgetLimit must be a positive number");
650
+ }
651
+ _privacyBudget.limit = n;
652
+ }
653
+
654
+ export function getPrivacyBudgetLimit() {
655
+ return _privacyBudget.limit;
656
+ }
657
+
658
+ export function getPrivacyBudgetSpent() {
659
+ return _privacyBudget.spent;
660
+ }
661
+
662
+ export function resetPrivacyBudget() {
663
+ _privacyBudget.spent = 0;
664
+ }
665
+
666
+ /* ── Federated Learning V2 ─────────────────────────────── */
667
+
668
+ export function createModelV2(
669
+ db,
670
+ {
671
+ name,
672
+ modelType,
673
+ architecture,
674
+ totalRounds,
675
+ learningRate,
676
+ participants,
677
+ } = {},
678
+ ) {
679
+ if (!name) throw new Error("name is required");
680
+ const rounds = totalRounds ?? 10;
681
+ if (typeof rounds !== "number" || Number.isNaN(rounds) || rounds < 1) {
682
+ throw new Error("totalRounds must be a positive integer");
683
+ }
684
+ const legacy = createModel(db, name, {
685
+ modelType,
686
+ architecture,
687
+ totalRounds: rounds,
688
+ learningRate,
689
+ participants,
690
+ });
691
+ const m = _models.get(legacy.modelId);
692
+ return { ...m };
693
+ }
694
+
695
+ export function trainRoundV2(db, modelId) {
696
+ const m = _models.get(modelId);
697
+ if (!m) throw new Error(`Unknown model: ${modelId}`);
698
+ if (m.status === "initializing") m.status = "training";
699
+ if (m.status !== "training") {
700
+ throw new Error(
701
+ `Invalid transition: ${m.status} (must be training/initializing)`,
702
+ );
703
+ }
704
+
705
+ m.current_round += 1;
706
+ const baseAcc = 0.5;
707
+ const progress = m.current_round / m.total_rounds;
708
+ m.accuracy = Math.round((baseAcc + progress * 0.45) * 1000) / 1000;
709
+ m.loss = Math.round((1 - m.accuracy) * 0.5 * 1000) / 1000;
710
+ m.privacy_budget_spent += DEFAULT_CONFIG.defaultEpsilon * 0.1;
711
+ _privacyBudget.spent += DEFAULT_CONFIG.defaultEpsilon * 0.1;
712
+ m.updated_at = _now();
713
+
714
+ db.prepare(
715
+ `UPDATE fl_models SET status = ?, current_round = ?, accuracy = ?, loss = ?,
716
+ privacy_budget_spent = ?, updated_at = ? WHERE id = ?`,
717
+ ).run(
718
+ m.status,
719
+ m.current_round,
720
+ m.accuracy,
721
+ m.loss,
722
+ m.privacy_budget_spent,
723
+ m.updated_at,
724
+ modelId,
725
+ );
726
+
727
+ return { ...m };
728
+ }
729
+
730
+ export function aggregateRound(db, modelId) {
731
+ const m = _models.get(modelId);
732
+ if (!m) throw new Error(`Unknown model: ${modelId}`);
733
+ if (m.status !== "training") {
734
+ throw new Error(
735
+ `Invalid transition: ${m.status} → aggregating (must be training)`,
736
+ );
737
+ }
738
+ m.status = "aggregating";
739
+ m.updated_at = _now();
740
+ db.prepare(
741
+ "UPDATE fl_models SET status = ?, updated_at = ? WHERE id = ?",
742
+ ).run("aggregating", m.updated_at, modelId);
743
+
744
+ if (m.current_round >= m.total_rounds) {
745
+ m.status = "completed";
746
+ db.prepare(
747
+ "UPDATE fl_models SET status = ?, updated_at = ? WHERE id = ?",
748
+ ).run("completed", _now(), modelId);
749
+ } else {
750
+ m.status = "training";
751
+ db.prepare(
752
+ "UPDATE fl_models SET status = ?, updated_at = ? WHERE id = ?",
753
+ ).run("training", _now(), modelId);
754
+ }
755
+ return { ...m };
756
+ }
757
+
758
+ export function failModelV2(db, modelId, { error } = {}) {
759
+ const m = _models.get(modelId);
760
+ if (!m) throw new Error(`Unknown model: ${modelId}`);
761
+ if (FL_TERMINALS_V2.has(m.status)) {
762
+ throw new Error(`Invalid transition: ${m.status} → failed (terminal)`);
763
+ }
764
+ m.status = "failed";
765
+ m.error_message = error || null;
766
+ m.updated_at = _now();
767
+ db.prepare(
768
+ "UPDATE fl_models SET status = ?, updated_at = ? WHERE id = ?",
769
+ ).run("failed", m.updated_at, modelId);
770
+ return { ...m };
771
+ }
772
+
773
+ export function setFLStatusV2(db, modelId, newStatus, patch = {}) {
774
+ const m = _models.get(modelId);
775
+ if (!m) throw new Error(`Unknown model: ${modelId}`);
776
+ if (!Object.values(FL_STATUS).includes(newStatus)) {
777
+ throw new Error(`Unknown FL status: ${newStatus}`);
778
+ }
779
+ const allowed = FL_TRANSITIONS_V2.get(m.status);
780
+ if (!allowed || !allowed.has(newStatus)) {
781
+ throw new Error(`Invalid transition: ${m.status} → ${newStatus}`);
782
+ }
783
+ m.status = newStatus;
784
+ if (patch.errorMessage !== undefined) m.error_message = patch.errorMessage;
785
+ if (patch.accuracy !== undefined) m.accuracy = patch.accuracy;
786
+ if (patch.loss !== undefined) m.loss = patch.loss;
787
+ m.updated_at = _now();
788
+ db.prepare(
789
+ `UPDATE fl_models SET status = ?, accuracy = ?, loss = ?, updated_at = ? WHERE id = ?`,
790
+ ).run(newStatus, m.accuracy, m.loss, m.updated_at, modelId);
791
+ return { ...m };
792
+ }
793
+
794
+ /* ── MPC V2 ────────────────────────────────────────────── */
795
+
796
+ export function createComputationV2(
797
+ db,
798
+ { computationType, protocol, participantIds, sharesRequired } = {},
799
+ ) {
800
+ if (!computationType) throw new Error("computationType is required");
801
+ const proto = protocol || "shamir";
802
+ if (!Object.values(MPC_PROTOCOL_V2).includes(proto)) {
803
+ throw new Error(`Invalid protocol: ${proto}`);
804
+ }
805
+ const ids = participantIds || [];
806
+ if (!Array.isArray(ids) || ids.length === 0) {
807
+ throw new Error("participantIds must be a non-empty array");
808
+ }
809
+ const activeCount = getActiveMpcCount();
810
+ if (activeCount >= _maxActiveMpcComputations) {
811
+ throw new Error(
812
+ `Max active MPC computations reached (${activeCount}/${_maxActiveMpcComputations})`,
813
+ );
814
+ }
815
+ const legacy = createComputation(db, computationType, {
816
+ protocol: proto,
817
+ participantIds: ids,
818
+ sharesRequired,
819
+ });
820
+ const c = _computations.get(legacy.computationId);
821
+ return { ...c };
822
+ }
823
+
824
+ export function submitShareV2(db, computationId) {
825
+ const c = _computations.get(computationId);
826
+ if (!c) throw new Error(`Unknown computation: ${computationId}`);
827
+ if (MPC_TERMINALS_V2.has(c.status)) {
828
+ throw new Error(
829
+ `Invalid transition: cannot submit share to terminal (${c.status})`,
830
+ );
831
+ }
832
+ c.shares_received += 1;
833
+ if (c.status === "pending") c.status = "computing";
834
+
835
+ if (c.shares_received >= c.shares_required) {
836
+ c.status = "completed";
837
+ c.completed_at = _now();
838
+ c.computation_time_ms = c.completed_at - c.created_at;
839
+ c.result_hash = crypto
840
+ .createHash("sha256")
841
+ .update(`result-${c.id}`)
842
+ .digest("hex")
843
+ .slice(0, 16);
844
+ }
845
+
846
+ db.prepare(
847
+ `UPDATE mpc_computations SET shares_received = ?, status = ?, completed_at = ?,
848
+ computation_time_ms = ?, result_hash = ? WHERE id = ?`,
849
+ ).run(
850
+ c.shares_received,
851
+ c.status,
852
+ c.completed_at,
853
+ c.computation_time_ms,
854
+ c.result_hash,
855
+ computationId,
856
+ );
857
+
858
+ return { ...c };
859
+ }
860
+
861
+ export function failComputation(db, computationId, { error } = {}) {
862
+ const c = _computations.get(computationId);
863
+ if (!c) throw new Error(`Unknown computation: ${computationId}`);
864
+ if (MPC_TERMINALS_V2.has(c.status)) {
865
+ throw new Error(`Invalid transition: ${c.status} → failed (terminal)`);
866
+ }
867
+ c.status = "failed";
868
+ c.error_message = error || null;
869
+ c.completed_at = _now();
870
+ db.prepare(
871
+ `UPDATE mpc_computations SET status = ?, error_message = ?, completed_at = ? WHERE id = ?`,
872
+ ).run("failed", c.error_message, c.completed_at, computationId);
873
+ return { ...c };
874
+ }
875
+
876
+ export function setMPCStatusV2(db, computationId, newStatus, patch = {}) {
877
+ const c = _computations.get(computationId);
878
+ if (!c) throw new Error(`Unknown computation: ${computationId}`);
879
+ if (!Object.values(MPC_STATUS_V2).includes(newStatus)) {
880
+ throw new Error(`Unknown MPC status: ${newStatus}`);
881
+ }
882
+ const allowed = MPC_TRANSITIONS_V2.get(c.status);
883
+ if (!allowed || !allowed.has(newStatus)) {
884
+ throw new Error(`Invalid transition: ${c.status} → ${newStatus}`);
885
+ }
886
+ c.status = newStatus;
887
+ if (patch.errorMessage !== undefined) c.error_message = patch.errorMessage;
888
+ if (patch.resultHash !== undefined) c.result_hash = patch.resultHash;
889
+ if (MPC_TERMINALS_V2.has(newStatus)) {
890
+ c.completed_at = c.completed_at || _now();
891
+ if (c.computation_time_ms == null) {
892
+ c.computation_time_ms = c.completed_at - c.created_at;
893
+ }
894
+ }
895
+ db.prepare(
896
+ `UPDATE mpc_computations SET status = ?, error_message = ?, result_hash = ?,
897
+ completed_at = ?, computation_time_ms = ? WHERE id = ?`,
898
+ ).run(
899
+ newStatus,
900
+ c.error_message,
901
+ c.result_hash,
902
+ c.completed_at,
903
+ c.computation_time_ms,
904
+ computationId,
905
+ );
906
+ return { ...c };
907
+ }
908
+
909
+ /* ── DP / HE V2 ────────────────────────────────────────── */
910
+
911
+ export function dpPublishV2(
912
+ db,
913
+ { data, epsilon, delta, mechanism, sensitivity } = {},
914
+ ) {
915
+ const eps = epsilon ?? DEFAULT_CONFIG.defaultEpsilon;
916
+ const mech = mechanism || "laplace";
917
+ if (!Object.values(DP_MECHANISM_V2).includes(mech)) {
918
+ throw new Error(`Invalid DP mechanism: ${mech}`);
919
+ }
920
+ if (typeof eps !== "number" || Number.isNaN(eps) || eps <= 0) {
921
+ throw new Error("epsilon must be a positive number");
922
+ }
923
+ if (_privacyBudget.spent + eps > _privacyBudget.limit) {
924
+ throw new Error(
925
+ `Privacy budget exceeded (${_privacyBudget.spent + eps} > ${_privacyBudget.limit})`,
926
+ );
927
+ }
928
+ return dpPublish(db, {
929
+ data,
930
+ epsilon: eps,
931
+ delta,
932
+ mechanism: mech,
933
+ sensitivity,
934
+ });
935
+ }
936
+
937
+ export function heQueryV2({ data, operation, scheme } = {}) {
938
+ const sch = scheme || "paillier";
939
+ if (!Object.values(HE_SCHEME_V2).includes(sch)) {
940
+ throw new Error(`Invalid HE scheme: ${sch}`);
941
+ }
942
+ const validOps = ["sum", "product", "mean", "count"];
943
+ if (!validOps.includes(operation)) {
944
+ throw new Error(`Invalid HE operation: ${operation}`);
945
+ }
946
+ if (!Array.isArray(data) || data.length === 0) {
947
+ throw new Error("data must be a non-empty array");
948
+ }
949
+ return heQuery({ data, operation, scheme: sch });
950
+ }
951
+
952
+ /* ── V2 Stats ──────────────────────────────────────────── */
953
+
954
+ export function getPrivacyStatsV2() {
955
+ const flByStatus = {};
956
+ for (const s of Object.values(FL_STATUS)) flByStatus[s] = 0;
957
+ const mpcByStatus = {};
958
+ for (const s of Object.values(MPC_STATUS_V2)) mpcByStatus[s] = 0;
959
+ const mpcByProtocol = {};
960
+ for (const p of Object.values(MPC_PROTOCOL_V2)) mpcByProtocol[p] = 0;
961
+
962
+ let accSum = 0;
963
+ let accCount = 0;
964
+ for (const m of _models.values()) {
965
+ flByStatus[m.status] = (flByStatus[m.status] || 0) + 1;
966
+ if (m.status === "completed" && typeof m.accuracy === "number") {
967
+ accSum += m.accuracy;
968
+ accCount += 1;
969
+ }
970
+ }
971
+
972
+ let timeSum = 0;
973
+ let timeCount = 0;
974
+ for (const c of _computations.values()) {
975
+ mpcByStatus[c.status] = (mpcByStatus[c.status] || 0) + 1;
976
+ mpcByProtocol[c.protocol] = (mpcByProtocol[c.protocol] || 0) + 1;
977
+ if (c.status === "completed" && typeof c.computation_time_ms === "number") {
978
+ timeSum += c.computation_time_ms;
979
+ timeCount += 1;
980
+ }
981
+ }
982
+
983
+ return {
984
+ totalModels: _models.size,
985
+ totalComputations: _computations.size,
986
+ activeMpcCount: getActiveMpcCount(),
987
+ maxActiveMpcComputations: _maxActiveMpcComputations,
988
+ flByStatus,
989
+ mpcByStatus,
990
+ mpcByProtocol,
991
+ budget: {
992
+ spent: Math.round(_privacyBudget.spent * 1000) / 1000,
993
+ limit: _privacyBudget.limit,
994
+ remaining:
995
+ Math.round((_privacyBudget.limit - _privacyBudget.spent) * 1000) / 1000,
996
+ exhausted: _privacyBudget.spent >= _privacyBudget.limit,
997
+ },
998
+ avgAccuracy:
999
+ accCount > 0 ? Math.round((accSum / accCount) * 1000) / 1000 : 0,
1000
+ avgComputationTimeMs: timeCount > 0 ? Math.round(timeSum / timeCount) : 0,
1001
+ };
575
1002
  }