@serfab/cadre-core 0.0.2

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 (54) hide show
  1. package/README.md +252 -0
  2. package/dist/arachnode-stub.d.ts +60 -0
  3. package/dist/arachnode-stub.js +120 -0
  4. package/dist/arachnode-stub.js.map +1 -0
  5. package/dist/cadre-node.d.ts +252 -0
  6. package/dist/cadre-node.js +753 -0
  7. package/dist/cadre-node.js.map +1 -0
  8. package/dist/control-database.d.ts +62 -0
  9. package/dist/control-database.js +295 -0
  10. package/dist/control-database.js.map +1 -0
  11. package/dist/enrollment.d.ts +76 -0
  12. package/dist/enrollment.js +126 -0
  13. package/dist/enrollment.js.map +1 -0
  14. package/dist/hibernation-manager.d.ts +68 -0
  15. package/dist/hibernation-manager.js +212 -0
  16. package/dist/hibernation-manager.js.map +1 -0
  17. package/dist/index.d.ts +12 -0
  18. package/dist/index.js +24 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/seed-bootstrap.d.ts +164 -0
  21. package/dist/seed-bootstrap.js +554 -0
  22. package/dist/seed-bootstrap.js.map +1 -0
  23. package/dist/strand-database.d.ts +39 -0
  24. package/dist/strand-database.js +108 -0
  25. package/dist/strand-database.js.map +1 -0
  26. package/dist/strand-formation-manager.d.ts +87 -0
  27. package/dist/strand-formation-manager.js +168 -0
  28. package/dist/strand-formation-manager.js.map +1 -0
  29. package/dist/strand-instance-manager.d.ts +60 -0
  30. package/dist/strand-instance-manager.js +209 -0
  31. package/dist/strand-instance-manager.js.map +1 -0
  32. package/dist/strand-solicitation.d.ts +145 -0
  33. package/dist/strand-solicitation.js +180 -0
  34. package/dist/strand-solicitation.js.map +1 -0
  35. package/dist/strand-watcher.d.ts +70 -0
  36. package/dist/strand-watcher.js +136 -0
  37. package/dist/strand-watcher.js.map +1 -0
  38. package/dist/types.d.ts +484 -0
  39. package/dist/types.js +26 -0
  40. package/dist/types.js.map +1 -0
  41. package/package.json +67 -0
  42. package/src/arachnode-stub.ts +160 -0
  43. package/src/cadre-node.ts +923 -0
  44. package/src/control-database.ts +376 -0
  45. package/src/enrollment.ts +199 -0
  46. package/src/hibernation-manager.ts +268 -0
  47. package/src/index.ts +71 -0
  48. package/src/seed-bootstrap.ts +753 -0
  49. package/src/strand-database.ts +168 -0
  50. package/src/strand-formation-manager.ts +277 -0
  51. package/src/strand-instance-manager.ts +281 -0
  52. package/src/strand-solicitation.ts +318 -0
  53. package/src/strand-watcher.ts +197 -0
  54. package/src/types.ts +553 -0
@@ -0,0 +1,160 @@
1
+ import debug from 'debug';
2
+ import type { NodeProfile, ArachnodeConfig } from './types.js';
3
+
4
+ const log = debug('sereus:cadre:arachnode');
5
+
6
+ /**
7
+ * Ring configuration for a storage node
8
+ */
9
+ export interface RingConfig {
10
+ /** Ring number (0 = full keyspace, higher = more partitions) */
11
+ ring: number;
12
+ /** Partition within the ring (depends on ring level) */
13
+ partition: number;
14
+ /** Keyspace range this node is responsible for */
15
+ keyspaceStart: Uint8Array;
16
+ keyspaceEnd: Uint8Array;
17
+ }
18
+
19
+ /**
20
+ * Stub implementation of Arachnode ring participation.
21
+ *
22
+ * Arachnode uses a concentric ring system where:
23
+ * - Ring Zulu (transaction ring): All nodes participate for transaction verification
24
+ * - Storage rings (0, 1, 2, 3...): Nodes join based on their storage capacity
25
+ * - Ring 0: Full keyspace (requires most storage)
26
+ * - Ring 1: 2 partitions
27
+ * - Ring 2: 4 partitions
28
+ * - Ring 3: 8 partitions
29
+ * - etc.
30
+ *
31
+ * This is a stub that will be replaced when arachnode is fully implemented.
32
+ */
33
+ export class ArachnodeStub {
34
+ private readonly profile: NodeProfile;
35
+ private readonly config: ArachnodeConfig;
36
+ private ringConfig?: RingConfig;
37
+ private running = false;
38
+
39
+ constructor(profile: NodeProfile, config: ArachnodeConfig) {
40
+ this.profile = profile;
41
+ this.config = config;
42
+ log('ArachnodeStub created for profile=%s, config=%o', profile, config);
43
+ }
44
+
45
+ /**
46
+ * Start participating in rings
47
+ */
48
+ async start(): Promise<void> {
49
+ if (this.running) return;
50
+ this.running = true;
51
+
52
+ // All nodes participate in Ring Zulu
53
+ if (this.config.enableRingZulu) {
54
+ log('Joining Ring Zulu (transaction ring)');
55
+ // Stub: In real implementation, would register with transaction verification network
56
+ }
57
+
58
+ // Storage nodes join storage rings
59
+ if (this.profile === 'storage' && this.config.storageRing) {
60
+ const { ring, partition = 0 } = this.config.storageRing;
61
+
62
+ log('Joining storage ring %d, partition %d', ring, partition);
63
+
64
+ // Calculate keyspace range for this partition
65
+ // Stub: Using placeholder keyspace calculation
66
+ this.ringConfig = {
67
+ ring,
68
+ partition,
69
+ keyspaceStart: this.calculateKeyspaceStart(ring, partition),
70
+ keyspaceEnd: this.calculateKeyspaceEnd(ring, partition)
71
+ };
72
+
73
+ // Stub: In real implementation, would:
74
+ // 1. Register with the storage ring
75
+ // 2. Begin accepting block storage requests for our keyspace
76
+ // 3. Participate in replication with other ring members
77
+ }
78
+
79
+ log('ArachnodeStub started');
80
+ }
81
+
82
+ /**
83
+ * Stop participating in rings
84
+ */
85
+ async stop(): Promise<void> {
86
+ if (!this.running) return;
87
+ this.running = false;
88
+
89
+ if (this.ringConfig) {
90
+ log('Leaving storage ring %d, partition %d',
91
+ this.ringConfig.ring, this.ringConfig.partition);
92
+ // Stub: In real implementation, would gracefully leave the ring
93
+ this.ringConfig = undefined;
94
+ }
95
+
96
+ if (this.config.enableRingZulu) {
97
+ log('Leaving Ring Zulu');
98
+ // Stub: In real implementation, would leave transaction ring
99
+ }
100
+
101
+ log('ArachnodeStub stopped');
102
+ }
103
+
104
+ /**
105
+ * Get current ring configuration
106
+ */
107
+ getRingConfig(): RingConfig | undefined {
108
+ return this.ringConfig;
109
+ }
110
+
111
+ /**
112
+ * Check if participating in Ring Zulu
113
+ */
114
+ isInRingZulu(): boolean {
115
+ return this.running && this.config.enableRingZulu;
116
+ }
117
+
118
+ /**
119
+ * Check if participating in a storage ring
120
+ */
121
+ isInStorageRing(): boolean {
122
+ return this.running && this.ringConfig !== undefined;
123
+ }
124
+
125
+ // Stub keyspace calculations
126
+ private calculateKeyspaceStart(ring: number, partition: number): Uint8Array {
127
+ // Stub: Real implementation would calculate based on ring partition scheme
128
+ const numPartitions = Math.pow(2, ring);
129
+ const partitionSize = 256 / numPartitions;
130
+ const start = new Uint8Array(32);
131
+ start[0] = Math.floor(partition * partitionSize);
132
+ return start;
133
+ }
134
+
135
+ private calculateKeyspaceEnd(ring: number, partition: number): Uint8Array {
136
+ // Stub: Real implementation would calculate based on ring partition scheme
137
+ const numPartitions = Math.pow(2, ring);
138
+ const partitionSize = 256 / numPartitions;
139
+ const end = new Uint8Array(32);
140
+ end[0] = Math.floor((partition + 1) * partitionSize) - 1;
141
+ end.fill(0xFF, 1); // Fill rest with max values
142
+ return end;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Create an arachnode instance for a strand
148
+ */
149
+ export function createArachnodeStub(
150
+ profile: NodeProfile,
151
+ config?: Partial<ArachnodeConfig>
152
+ ): ArachnodeStub {
153
+ const fullConfig: ArachnodeConfig = {
154
+ enableRingZulu: config?.enableRingZulu ?? true,
155
+ storageRing: profile === 'storage' ? (config?.storageRing ?? { ring: 0 }) : undefined
156
+ };
157
+
158
+ return new ArachnodeStub(profile, fullConfig);
159
+ }
160
+