@xyo-network/xl1-protocol-sdk 1.26.46 → 1.26.48

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.
@@ -790,6 +790,279 @@ async function validateTransactionsOpcodes(txs) {
790
790
  return txElevatedPayloads;
791
791
  }
792
792
 
793
+ // src/capabilities/Backing.ts
794
+ function backingsSatisfied(required, available) {
795
+ for (const need of required) {
796
+ const matched = available.some((a) => a.backing === need.backing && (a.mode === "write" || need.mode === "read"));
797
+ if (!matched) return false;
798
+ }
799
+ return true;
800
+ }
801
+ function unmetBackings(required, available) {
802
+ return required.filter((need) => {
803
+ return !available.some((a) => a.backing === need.backing && (a.mode === "write" || need.mode === "read"));
804
+ });
805
+ }
806
+
807
+ // src/capabilities/Capability.ts
808
+ var CapabilityRegistry = class {
809
+ _entries = /* @__PURE__ */ new Map();
810
+ get(id) {
811
+ const cap = this._entries.get(id);
812
+ if (!cap) throw new Error(`Capability not found: ${id}`);
813
+ return cap;
814
+ }
815
+ register(cap) {
816
+ if (this._entries.has(cap.id)) {
817
+ throw new Error(`Capability already registered: ${cap.id}`);
818
+ }
819
+ this._entries.set(cap.id, cap);
820
+ return this;
821
+ }
822
+ toJson() {
823
+ const result = {};
824
+ for (const [id, cap] of this._entries.entries()) {
825
+ const { id: _, ...rest } = cap;
826
+ result[id] = rest;
827
+ }
828
+ return result;
829
+ }
830
+ tryGet(id) {
831
+ return this._entries.get(id);
832
+ }
833
+ };
834
+ function createCapabilityRegistry() {
835
+ return new CapabilityRegistry();
836
+ }
837
+
838
+ // src/capabilities/surfaceMap.ts
839
+ var BRANCH_SURFACE = {
840
+ // Connection-level branches.
841
+ "network": "node",
842
+ "networkStake": "indexed",
843
+ "runner": "node",
844
+ "storage": "indexed",
845
+ // viewer.* branches.
846
+ "viewer.block": "node",
847
+ "viewer.transaction": "node",
848
+ "viewer.mempool": "node",
849
+ "viewer.finalization": "node",
850
+ "viewer.time": "node",
851
+ // AccountBalanceViewer is a point query (`f(address) → balance`) — node-surface,
852
+ // even though indexer-backed today via summary maps.
853
+ "viewer.account.balance": "node",
854
+ // Cross-key indexes — indexer-surface.
855
+ "viewer.networkStake": "indexed",
856
+ "viewer.stake": "indexed",
857
+ "viewer.step": "indexed"
858
+ };
859
+ function surfaceForBranch(branch) {
860
+ return BRANCH_SURFACE[branch];
861
+ }
862
+ var VIEWER_BRANCH_KEYS = [
863
+ ["block", "viewer.block"],
864
+ ["transaction", "viewer.transaction"],
865
+ ["mempool", "viewer.mempool"],
866
+ ["finalization", "viewer.finalization"],
867
+ ["time", "viewer.time"],
868
+ ["account", "viewer.account.balance"],
869
+ ["networkStake", "viewer.networkStake"],
870
+ ["stake", "viewer.stake"],
871
+ ["step", "viewer.step"]
872
+ ];
873
+
874
+ // src/capabilities/connectionSubsetBySurface.ts
875
+ function connectionSubsetBySurface(connection, surface) {
876
+ const result = { moniker: connection.moniker };
877
+ if (connection.network && surfaceForBranch("network") === surface) result.network = connection.network;
878
+ if (connection.networkStake && surfaceForBranch("networkStake") === surface) result.networkStake = connection.networkStake;
879
+ if (connection.runner && surfaceForBranch("runner") === surface) result.runner = connection.runner;
880
+ if (connection.storage && surfaceForBranch("storage") === surface) result.storage = connection.storage;
881
+ if (connection.viewer) {
882
+ const viewer = filterViewerBySurface(connection.viewer, surface);
883
+ if (viewer) result.viewer = viewer;
884
+ }
885
+ return result;
886
+ }
887
+ function filterViewerBySurface(viewer, surface) {
888
+ const filtered = {};
889
+ let kept = false;
890
+ for (const [viewerKey, branchKey] of VIEWER_BRANCH_KEYS) {
891
+ const value = viewer[viewerKey] ?? void 0;
892
+ if (value === void 0) continue;
893
+ if (surfaceForBranch(branchKey) !== surface) continue;
894
+ filtered[viewerKey] = value;
895
+ kept = true;
896
+ }
897
+ if (!kept) return void 0;
898
+ return {
899
+ ...filtered,
900
+ moniker: viewer.moniker
901
+ };
902
+ }
903
+
904
+ // src/capabilities/factoryBrand.ts
905
+ function backedFactory(_backings, factory) {
906
+ return factory;
907
+ }
908
+ function networkBackedFactory(factory) {
909
+ return factory;
910
+ }
911
+ function factoryBackingsCompatible(declared, available) {
912
+ return backingsSatisfied(declared, available);
913
+ }
914
+
915
+ // src/capabilities/resolveProviders.ts
916
+ var MissingCapabilityError = class extends Error {
917
+ moniker;
918
+ reasons;
919
+ constructor(moniker, reasons) {
920
+ const detail = reasons.length === 0 ? "(no candidates registered)" : reasons.join("; ");
921
+ super(`No provider satisfies capability '${moniker}': ${detail}`);
922
+ this.name = "MissingCapabilityError";
923
+ this.moniker = moniker;
924
+ this.reasons = reasons;
925
+ }
926
+ };
927
+ function resolveProviders(needs, candidates, ctx, options = {}) {
928
+ const wanted = expandNeeds(needs, ctx);
929
+ const { backingFiltered, backingRejected } = filterByBackings(candidates, options.availableBackings);
930
+ const { surviving, rejected: preconditionRejected } = filterByPreconditions(backingFiltered, ctx);
931
+ const rejected = [...backingRejected, ...preconditionRejected];
932
+ const byCapability = groupByCapability(surviving, wanted);
933
+ const { bindings, selectedById } = pickWinners(wanted, byCapability, rejected, candidates);
934
+ const selected = topoSort([...selectedById.values()], ctx);
935
+ return {
936
+ bindings,
937
+ rejected,
938
+ selected
939
+ };
940
+ }
941
+ function filterByBackings(candidates, availableBackings) {
942
+ if (!availableBackings) {
943
+ return { backingFiltered: [...candidates], backingRejected: [] };
944
+ }
945
+ const backingFiltered = [];
946
+ const backingRejected = [];
947
+ for (const descriptor of candidates) {
948
+ if (backingsSatisfied(descriptor.backings, availableBackings)) {
949
+ backingFiltered.push(descriptor);
950
+ } else {
951
+ const missing = unmetBackings(descriptor.backings, availableBackings);
952
+ const rendered = missing.map((m) => `${m.backing}:${m.mode}`).join(", ");
953
+ backingRejected.push({ descriptor, reason: `missing backings [${rendered}]` });
954
+ }
955
+ }
956
+ return { backingFiltered, backingRejected };
957
+ }
958
+ function expandNeeds(needs, ctx) {
959
+ const wanted = new Set(needs);
960
+ const stack = [...needs];
961
+ while (stack.length > 0) {
962
+ const moniker = stack.pop();
963
+ const cap = ctx.capabilities.tryGet(moniker);
964
+ if (!cap?.implies) continue;
965
+ for (const dep of cap.implies) {
966
+ if (!wanted.has(dep)) {
967
+ wanted.add(dep);
968
+ stack.push(dep);
969
+ }
970
+ }
971
+ }
972
+ return wanted;
973
+ }
974
+ function filterByPreconditions(candidates, ctx) {
975
+ const surviving = [];
976
+ const rejected = [];
977
+ for (const descriptor of candidates) {
978
+ try {
979
+ if (descriptor.preconditions(ctx)) {
980
+ surviving.push(descriptor);
981
+ } else {
982
+ rejected.push({ descriptor, reason: "preconditions returned false" });
983
+ }
984
+ } catch (err) {
985
+ rejected.push({
986
+ descriptor,
987
+ reason: `preconditions threw: ${err instanceof Error ? err.message : String(err)}`
988
+ });
989
+ }
990
+ }
991
+ return { surviving, rejected };
992
+ }
993
+ function groupByCapability(surviving, wanted) {
994
+ const byCapability = /* @__PURE__ */ new Map();
995
+ for (const descriptor of surviving) {
996
+ for (const moniker of descriptor.satisfies) {
997
+ if (!wanted.has(moniker)) continue;
998
+ const list = byCapability.get(moniker) ?? [];
999
+ list.push(descriptor);
1000
+ byCapability.set(moniker, list);
1001
+ }
1002
+ }
1003
+ return byCapability;
1004
+ }
1005
+ function pickWinners(wanted, byCapability, rejected, allCandidates) {
1006
+ const bindings = {};
1007
+ const selectedById = /* @__PURE__ */ new Map();
1008
+ for (const moniker of wanted) {
1009
+ const group = byCapability.get(moniker);
1010
+ if (!group || group.length === 0) {
1011
+ throw new MissingCapabilityError(moniker, reasonsFor(moniker, rejected, allCandidates));
1012
+ }
1013
+ const sorted = group.toSorted(compareDescriptors);
1014
+ const winner = sorted[0];
1015
+ bindings[moniker] = winner.id;
1016
+ selectedById.set(winner.id, winner);
1017
+ for (const loser of sorted.slice(1)) {
1018
+ rejected.push({
1019
+ descriptor: loser,
1020
+ reason: `tier ${loser.tier} lost to ${winner.id} (tier ${winner.tier}) for ${moniker}`
1021
+ });
1022
+ }
1023
+ }
1024
+ return { bindings, selectedById };
1025
+ }
1026
+ function reasonsFor(moniker, rejected, allCandidates) {
1027
+ const candidatesForMoniker = allCandidates.filter((c) => c.satisfies.includes(moniker));
1028
+ if (candidatesForMoniker.length === 0) return [];
1029
+ return rejected.filter((r) => r.descriptor.satisfies.includes(moniker)).map((r) => `${r.descriptor.id}: ${r.reason}`);
1030
+ }
1031
+ function compareDescriptors(a, b) {
1032
+ if (a.tier !== b.tier) return a.tier - b.tier;
1033
+ const pa = a.priority ?? 0;
1034
+ const pb = b.priority ?? 0;
1035
+ if (pa !== pb) return pb - pa;
1036
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
1037
+ }
1038
+ function topoSort(descriptors, ctx) {
1039
+ const byMoniker = /* @__PURE__ */ new Map();
1040
+ for (const d of descriptors) for (const m of d.satisfies) byMoniker.set(m, d);
1041
+ const order = [];
1042
+ const seen = /* @__PURE__ */ new Set();
1043
+ const visiting = /* @__PURE__ */ new Set();
1044
+ const visit = (d) => {
1045
+ if (seen.has(d.id)) return;
1046
+ if (visiting.has(d.id)) {
1047
+ throw new Error(`Cycle detected through provider ${d.id}`);
1048
+ }
1049
+ visiting.add(d.id);
1050
+ for (const moniker of d.satisfies) {
1051
+ const cap = ctx.capabilities.tryGet(moniker);
1052
+ if (!cap?.implies) continue;
1053
+ for (const dep of cap.implies) {
1054
+ const depDesc = byMoniker.get(dep);
1055
+ if (depDesc) visit(depDesc);
1056
+ }
1057
+ }
1058
+ visiting.delete(d.id);
1059
+ seen.add(d.id);
1060
+ order.push(d);
1061
+ };
1062
+ for (const d of descriptors) visit(d);
1063
+ return order;
1064
+ }
1065
+
793
1066
  // src/config/Actor.ts
794
1067
  import {
795
1068
  zodAsFactory as zodAsFactory3,
@@ -6381,6 +6654,7 @@ export {
6381
6654
  LruCacheMap,
6382
6655
  MemoryMap,
6383
6656
  MemoryPermissionsStore,
6657
+ MissingCapabilityError,
6384
6658
  MnemonicStringZod,
6385
6659
  PRODUCER_DIVERSITY_BONUS,
6386
6660
  PostMessageRpcRemoteConfigZod,
@@ -6435,6 +6709,7 @@ export {
6435
6709
  TypedDataTypesZod,
6436
6710
  TypedDataValueZod,
6437
6711
  UsageMetaSchema,
6712
+ VIEWER_BRANCH_KEYS,
6438
6713
  WALLET_COMPLIANCE,
6439
6714
  XL1Amount,
6440
6715
  XL1_NETWORK_STAKING_GENESIS_PERIOD_END_EPOCH,
@@ -6470,6 +6745,8 @@ export {
6470
6745
  asSchemasStepSummaryWithStorageMeta,
6471
6746
  asTransfersStepSummary,
6472
6747
  asTransfersStepSummaryWithStorageMeta,
6748
+ backedFactory,
6749
+ backingsSatisfied,
6473
6750
  balancesStepSummaryFromRange,
6474
6751
  balancesSummary,
6475
6752
  blockFromBlockNumber,
@@ -6486,12 +6763,14 @@ export {
6486
6763
  calculateTimeRate,
6487
6764
  chainStepRewardAddress,
6488
6765
  confirmSubmittedTransaction,
6766
+ connectionSubsetBySurface,
6489
6767
  contextCache,
6490
6768
  crackOperation,
6491
6769
  crackOperations,
6492
6770
  creatableProvider,
6493
6771
  createBlockHydrator,
6494
6772
  createBoundWitnessHydrator,
6773
+ createCapabilityRegistry,
6495
6774
  createDeclarationIntent,
6496
6775
  createTransactionHydrator,
6497
6776
  createTransferPayload,
@@ -6499,6 +6778,7 @@ export {
6499
6778
  externalBlockNumberFromXL1BlockNumber,
6500
6779
  externalBlockRangeFromStep,
6501
6780
  externalBlockRangeFromXL1BlockRange,
6781
+ factoryBackingsCompatible,
6502
6782
  findBestUncle,
6503
6783
  findMostRecentBlock,
6504
6784
  findUncles,
@@ -6557,6 +6837,7 @@ export {
6557
6837
  netBalancesForPayloads,
6558
6838
  netSchemasForPayloads,
6559
6839
  netTransfersForPayloads,
6840
+ networkBackedFactory,
6560
6841
  networkStakeStepRewardPositionWeight,
6561
6842
  parseSignedBigInt,
6562
6843
  payloadMapFromStore,
@@ -6567,6 +6848,7 @@ export {
6567
6848
  registerCreatableProviderFactories,
6568
6849
  registerCreatableProviderFactory,
6569
6850
  resolveConfig,
6851
+ resolveProviders,
6570
6852
  rewardFromBlockNumber,
6571
6853
  schemasStepSummaryFromRange,
6572
6854
  schemasSummary,
@@ -6583,6 +6865,7 @@ export {
6583
6865
  stepsRewardTotal,
6584
6866
  stepsRewardTotalGenesisPeriod,
6585
6867
  stepsRewardTotalRange,
6868
+ surfaceForBranch,
6586
6869
  timeDurations,
6587
6870
  toActorConfig,
6588
6871
  toActorConfigContext,
@@ -6610,6 +6893,7 @@ export {
6610
6893
  tryUnflattenHydratedTransaction,
6611
6894
  unflattenHydratedBlock,
6612
6895
  unflattenHydratedTransaction,
6896
+ unmetBackings,
6613
6897
  validateTransactionsOpcodes,
6614
6898
  verifyEIP712Message,
6615
6899
  weightedStakeForRangeByPosition,