@lodestar/types 1.35.0-dev.e9dd48f165 → 1.35.0-dev.f45a2be721

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 (106) hide show
  1. package/lib/altair/index.d.ts.map +1 -0
  2. package/lib/altair/index.js.map +1 -1
  3. package/lib/altair/sszTypes.d.ts +1 -1
  4. package/lib/altair/sszTypes.d.ts.map +1 -0
  5. package/lib/altair/types.d.ts.map +1 -0
  6. package/lib/bellatrix/index.d.ts.map +1 -0
  7. package/lib/bellatrix/index.js.map +1 -1
  8. package/lib/bellatrix/sszTypes.d.ts +15 -15
  9. package/lib/bellatrix/sszTypes.d.ts.map +1 -0
  10. package/lib/bellatrix/types.d.ts.map +1 -0
  11. package/lib/capella/index.d.ts.map +1 -0
  12. package/lib/capella/index.js.map +1 -1
  13. package/lib/capella/sszTypes.d.ts +41 -41
  14. package/lib/capella/sszTypes.d.ts.map +1 -0
  15. package/lib/capella/types.d.ts.map +1 -0
  16. package/lib/deneb/index.d.ts.map +1 -0
  17. package/lib/deneb/index.js.map +1 -1
  18. package/lib/deneb/sszTypes.d.ts +44 -44
  19. package/lib/deneb/sszTypes.d.ts.map +1 -0
  20. package/lib/deneb/types.d.ts.map +1 -0
  21. package/lib/electra/index.d.ts.map +1 -0
  22. package/lib/electra/index.js.map +1 -1
  23. package/lib/electra/sszTypes.d.ts +67 -67
  24. package/lib/electra/sszTypes.d.ts.map +1 -0
  25. package/lib/electra/types.d.ts.map +1 -0
  26. package/lib/fulu/index.d.ts.map +1 -0
  27. package/lib/fulu/index.js.map +1 -1
  28. package/lib/fulu/sszTypes.d.ts +22 -22
  29. package/lib/fulu/sszTypes.d.ts.map +1 -0
  30. package/lib/fulu/sszTypes.js.map +1 -1
  31. package/lib/fulu/types.d.ts.map +1 -0
  32. package/lib/gloas/index.d.ts.map +1 -0
  33. package/lib/gloas/index.js.map +1 -1
  34. package/lib/gloas/sszTypes.d.ts +535 -234
  35. package/lib/gloas/sszTypes.d.ts.map +1 -0
  36. package/lib/gloas/sszTypes.js +162 -3
  37. package/lib/gloas/sszTypes.js.map +1 -1
  38. package/lib/gloas/types.d.ts +13 -0
  39. package/lib/gloas/types.d.ts.map +1 -0
  40. package/lib/index.d.ts +4 -3
  41. package/lib/index.d.ts.map +1 -0
  42. package/lib/index.js +5 -4
  43. package/lib/index.js.map +1 -1
  44. package/lib/phase0/index.d.ts +1 -0
  45. package/lib/phase0/index.d.ts.map +1 -0
  46. package/lib/phase0/index.js +1 -0
  47. package/lib/phase0/index.js.map +1 -1
  48. package/lib/phase0/sszTypes.d.ts.map +1 -0
  49. package/lib/phase0/types.d.ts.map +1 -0
  50. package/lib/phase0/validator.d.ts.map +1 -0
  51. package/lib/primitive/index.d.ts.map +1 -0
  52. package/lib/primitive/sszTypes.d.ts.map +1 -0
  53. package/lib/primitive/types.d.ts.map +1 -0
  54. package/lib/sszTypes.d.ts +1668 -1450
  55. package/lib/sszTypes.d.ts.map +1 -0
  56. package/lib/types.d.ts +7 -3
  57. package/lib/types.d.ts.map +1 -0
  58. package/lib/types.js +2 -2
  59. package/lib/types.js.map +1 -1
  60. package/lib/utils/container.d.ts.map +1 -0
  61. package/lib/utils/container.js.map +1 -1
  62. package/lib/utils/executionAddress.d.ts.map +1 -0
  63. package/lib/utils/executionAddress.js +1 -1
  64. package/lib/utils/executionAddress.js.map +1 -1
  65. package/lib/utils/stringType.d.ts.map +1 -0
  66. package/lib/utils/stringType.js +5 -8
  67. package/lib/utils/stringType.js.map +1 -1
  68. package/lib/utils/typeguards.d.ts.map +1 -0
  69. package/lib/utils/validatorStatus.d.ts.map +1 -0
  70. package/package.json +17 -8
  71. package/src/altair/index.ts +5 -0
  72. package/src/altair/sszTypes.ts +243 -0
  73. package/src/altair/types.ts +24 -0
  74. package/src/bellatrix/index.ts +5 -0
  75. package/src/bellatrix/sszTypes.ts +238 -0
  76. package/src/bellatrix/types.ts +24 -0
  77. package/src/capella/index.ts +5 -0
  78. package/src/capella/sszTypes.ts +281 -0
  79. package/src/capella/types.ts +33 -0
  80. package/src/deneb/index.ts +5 -0
  81. package/src/deneb/sszTypes.ts +329 -0
  82. package/src/deneb/types.ts +55 -0
  83. package/src/electra/index.ts +5 -0
  84. package/src/electra/sszTypes.ts +451 -0
  85. package/src/electra/types.ts +54 -0
  86. package/src/fulu/index.ts +5 -0
  87. package/src/fulu/sszTypes.ts +138 -0
  88. package/src/fulu/types.ts +31 -0
  89. package/src/gloas/index.ts +5 -0
  90. package/src/gloas/sszTypes.ts +234 -0
  91. package/src/gloas/types.ts +20 -0
  92. package/src/index.ts +15 -0
  93. package/src/phase0/index.ts +6 -0
  94. package/src/phase0/sszTypes.ts +514 -0
  95. package/src/phase0/types.ts +46 -0
  96. package/src/phase0/validator.ts +78 -0
  97. package/src/primitive/index.ts +3 -0
  98. package/src/primitive/sszTypes.ts +70 -0
  99. package/src/primitive/types.ts +53 -0
  100. package/src/sszTypes.ts +86 -0
  101. package/src/types.ts +375 -0
  102. package/src/utils/container.ts +38 -0
  103. package/src/utils/executionAddress.ts +48 -0
  104. package/src/utils/stringType.ts +58 -0
  105. package/src/utils/typeguards.ts +98 -0
  106. package/src/utils/validatorStatus.ts +52 -0
@@ -0,0 +1,514 @@
1
+ import {
2
+ BitListType,
3
+ BitVectorType,
4
+ ContainerType,
5
+ ListBasicType,
6
+ ListCompositeType,
7
+ ListUintNum64Type,
8
+ VectorBasicType,
9
+ VectorCompositeType,
10
+ } from "@chainsafe/ssz";
11
+ import {
12
+ ATTESTATION_SUBNET_COUNT,
13
+ DEPOSIT_CONTRACT_TREE_DEPTH,
14
+ EPOCHS_PER_ETH1_VOTING_PERIOD,
15
+ EPOCHS_PER_HISTORICAL_VECTOR,
16
+ EPOCHS_PER_SLASHINGS_VECTOR,
17
+ HISTORICAL_ROOTS_LIMIT,
18
+ JUSTIFICATION_BITS_LENGTH,
19
+ MAX_ATTESTATIONS,
20
+ MAX_ATTESTER_SLASHINGS,
21
+ MAX_DEPOSITS,
22
+ MAX_PROPOSER_SLASHINGS,
23
+ MAX_VALIDATORS_PER_COMMITTEE,
24
+ MAX_VOLUNTARY_EXITS,
25
+ SLOTS_PER_EPOCH,
26
+ SLOTS_PER_HISTORICAL_ROOT,
27
+ VALIDATOR_REGISTRY_LIMIT,
28
+ } from "@lodestar/params";
29
+ import * as primitiveSsz from "../primitive/sszTypes.js";
30
+ import {ValidatorNodeStruct} from "./validator.js";
31
+
32
+ const {
33
+ Bytes32,
34
+ UintNum64,
35
+ UintBn64,
36
+ Slot,
37
+ Epoch,
38
+ CommitteeIndex,
39
+ ValidatorIndex,
40
+ Root,
41
+ Version,
42
+ ForkDigest,
43
+ BLSPubkey,
44
+ BLSSignature,
45
+ Domain,
46
+ } = primitiveSsz;
47
+
48
+ // Misc types
49
+ // ==========
50
+
51
+ export const AttestationSubnets = new BitVectorType(ATTESTATION_SUBNET_COUNT);
52
+
53
+ /** BeaconBlockHeader where slot is bounded by the clock, and values above it are invalid */
54
+ export const BeaconBlockHeader = new ContainerType(
55
+ {
56
+ slot: Slot,
57
+ proposerIndex: ValidatorIndex,
58
+ parentRoot: Root,
59
+ stateRoot: Root,
60
+ bodyRoot: Root,
61
+ },
62
+ {typeName: "BeaconBlockHeader", jsonCase: "eth2", cachePermanentRootStruct: true}
63
+ );
64
+
65
+ /** BeaconBlockHeader where slot is NOT bounded by the clock, i.e. slashings. So slot is a bigint. */
66
+ export const BeaconBlockHeaderBigint = new ContainerType(
67
+ {
68
+ slot: UintBn64,
69
+ proposerIndex: ValidatorIndex,
70
+ parentRoot: Root,
71
+ stateRoot: Root,
72
+ bodyRoot: Root,
73
+ },
74
+ {typeName: "BeaconBlockHeader", jsonCase: "eth2", cachePermanentRootStruct: true}
75
+ );
76
+
77
+ export const SignedBeaconBlockHeader = new ContainerType(
78
+ {
79
+ message: BeaconBlockHeader,
80
+ signature: BLSSignature,
81
+ },
82
+ {typeName: "SignedBeaconBlockHeader", jsonCase: "eth2"}
83
+ );
84
+
85
+ /** Same as `SignedBeaconBlockHeader` but slot is not bounded by the clock and must be a bigint */
86
+ export const SignedBeaconBlockHeaderBigint = new ContainerType(
87
+ {
88
+ message: BeaconBlockHeaderBigint,
89
+ signature: BLSSignature,
90
+ },
91
+ {typeName: "SignedBeaconBlockHeader", jsonCase: "eth2"}
92
+ );
93
+
94
+ /** Checkpoint where epoch is bounded by the clock, and values above it are invalid */
95
+ export const Checkpoint = new ContainerType(
96
+ {
97
+ epoch: Epoch,
98
+ root: Root,
99
+ },
100
+ {typeName: "Checkpoint", jsonCase: "eth2"}
101
+ );
102
+
103
+ /** Checkpoint where epoch is NOT bounded by the clock, so must be a bigint */
104
+ export const CheckpointBigint = new ContainerType(
105
+ {
106
+ epoch: UintBn64,
107
+ root: Root,
108
+ },
109
+ {typeName: "Checkpoint", jsonCase: "eth2"}
110
+ );
111
+
112
+ export const CommitteeBits = new BitListType(MAX_VALIDATORS_PER_COMMITTEE);
113
+
114
+ export const CommitteeIndices = new ListBasicType(ValidatorIndex, MAX_VALIDATORS_PER_COMMITTEE);
115
+
116
+ export const DepositMessage = new ContainerType(
117
+ {
118
+ pubkey: BLSPubkey,
119
+ withdrawalCredentials: Bytes32,
120
+ amount: UintNum64,
121
+ },
122
+ {typeName: "DepositMessage", jsonCase: "eth2"}
123
+ );
124
+
125
+ export const DepositData = new ContainerType(
126
+ {
127
+ pubkey: BLSPubkey,
128
+ withdrawalCredentials: Bytes32,
129
+ amount: UintNum64,
130
+ signature: BLSSignature,
131
+ },
132
+ {typeName: "DepositData", jsonCase: "eth2"}
133
+ );
134
+
135
+ export const DepositDataRootList = new ListCompositeType(Root, 2 ** DEPOSIT_CONTRACT_TREE_DEPTH);
136
+
137
+ export const DepositEvent = new ContainerType(
138
+ {
139
+ depositData: DepositData,
140
+ blockNumber: UintNum64,
141
+ index: UintNum64,
142
+ },
143
+ {typeName: "DepositEvent", jsonCase: "eth2"}
144
+ );
145
+
146
+ export const Eth1Data = new ContainerType(
147
+ {
148
+ depositRoot: Root,
149
+ depositCount: UintNum64,
150
+ blockHash: Bytes32,
151
+ },
152
+ {typeName: "Eth1Data", jsonCase: "eth2"}
153
+ );
154
+
155
+ export const Eth1DataVotes = new ListCompositeType(Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH);
156
+
157
+ export const Eth1DataOrdered = new ContainerType(
158
+ {
159
+ depositRoot: Root,
160
+ depositCount: UintNum64,
161
+ blockHash: Bytes32,
162
+ blockNumber: UintNum64,
163
+ },
164
+ {typeName: "Eth1DataOrdered", jsonCase: "eth2"}
165
+ );
166
+
167
+ /** Spec'ed but only used in lodestar as a type */
168
+ export const Eth1Block = new ContainerType(
169
+ {
170
+ timestamp: UintNum64,
171
+ depositRoot: Root,
172
+ depositCount: UintNum64,
173
+ },
174
+ {typeName: "Eth1Block", jsonCase: "eth2"}
175
+ );
176
+
177
+ export const Fork = new ContainerType(
178
+ {
179
+ previousVersion: Version,
180
+ currentVersion: Version,
181
+ epoch: Epoch,
182
+ },
183
+ {typeName: "Fork", jsonCase: "eth2"}
184
+ );
185
+
186
+ export const ForkData = new ContainerType(
187
+ {
188
+ currentVersion: Version,
189
+ genesisValidatorsRoot: Root,
190
+ },
191
+ {typeName: "ForkData", jsonCase: "eth2"}
192
+ );
193
+
194
+ export const ENRForkID = new ContainerType(
195
+ {
196
+ forkDigest: ForkDigest,
197
+ nextForkVersion: Version,
198
+ nextForkEpoch: Epoch,
199
+ },
200
+ {typeName: "ENRForkID", jsonCase: "eth2"}
201
+ );
202
+
203
+ export const HistoricalBlockRoots = new VectorCompositeType(Root, SLOTS_PER_HISTORICAL_ROOT);
204
+ export const HistoricalStateRoots = new VectorCompositeType(Root, SLOTS_PER_HISTORICAL_ROOT);
205
+
206
+ export const HistoricalBatch = new ContainerType(
207
+ {
208
+ blockRoots: HistoricalBlockRoots,
209
+ stateRoots: HistoricalStateRoots,
210
+ },
211
+ {typeName: "HistoricalBatch", jsonCase: "eth2"}
212
+ );
213
+
214
+ /**
215
+ * Non-spec'ed helper type to allow efficient hashing in epoch transition.
216
+ * This type is like a 'Header' of HistoricalBatch where its fields are hashed.
217
+ */
218
+ export const HistoricalBatchRoots = new ContainerType(
219
+ {
220
+ blockRoots: Root, // Hashed HistoricalBlockRoots
221
+ stateRoots: Root, // Hashed HistoricalStateRoots
222
+ },
223
+ {typeName: "HistoricalBatchRoots", jsonCase: "eth2"}
224
+ );
225
+
226
+ // The main Validator type is the 'ContainerNodeStructType' version
227
+ export const Validator = ValidatorNodeStruct;
228
+
229
+ // Export as stand-alone for direct tree optimizations
230
+ export const Validators = new ListCompositeType(ValidatorNodeStruct, VALIDATOR_REGISTRY_LIMIT);
231
+ // this ListUintNum64Type is used to cache Leaf Nodes of BeaconState.balances after epoch transition
232
+ export const Balances = new ListUintNum64Type(VALIDATOR_REGISTRY_LIMIT);
233
+ export const RandaoMixes = new VectorCompositeType(Bytes32, EPOCHS_PER_HISTORICAL_VECTOR);
234
+ /**
235
+ * This is initially a Gwei (BigInt) vector, however since Nov 2023 it's converted to UintNum64 (number) vector in the state transition because:
236
+ * - state.slashings[nextEpoch % EPOCHS_PER_SLASHINGS_VECTOR] is reset per epoch in processSlashingsReset()
237
+ * - max slashed validators per epoch is SLOTS_PER_EPOCH * MAX_ATTESTER_SLASHINGS * MAX_VALIDATORS_PER_COMMITTEE which is 32 * 2 * 2048 = 131072 on mainnet
238
+ * - with that and 32_000_000_000 MAX_EFFECTIVE_BALANCE or 2048_000_000_000 MAX_EFFECTIVE_BALANCE_ELECTRA, it still fits in a number given that Math.floor(Number.MAX_SAFE_INTEGER / 32_000_000_000) = 281474
239
+ * - we don't need to compute the total slashings from state.slashings, it's handled by totalSlashingsByIncrement in EpochCache
240
+ */
241
+ export const Slashings = new VectorBasicType(UintNum64, EPOCHS_PER_SLASHINGS_VECTOR);
242
+ export const JustificationBits = new BitVectorType(JUSTIFICATION_BITS_LENGTH);
243
+
244
+ // Misc dependants
245
+
246
+ export const AttestationData = new ContainerType(
247
+ {
248
+ slot: Slot,
249
+ index: CommitteeIndex,
250
+ beaconBlockRoot: Root,
251
+ source: Checkpoint,
252
+ target: Checkpoint,
253
+ },
254
+ {typeName: "AttestationData", jsonCase: "eth2", cachePermanentRootStruct: true}
255
+ );
256
+
257
+ /** Same as `AttestationData` but epoch, slot and index are not bounded and must be a bigint */
258
+ export const AttestationDataBigint = new ContainerType(
259
+ {
260
+ slot: UintBn64,
261
+ index: UintBn64,
262
+ beaconBlockRoot: Root,
263
+ source: CheckpointBigint,
264
+ target: CheckpointBigint,
265
+ },
266
+ {typeName: "AttestationData", jsonCase: "eth2", cachePermanentRootStruct: true}
267
+ );
268
+
269
+ export const IndexedAttestation = new ContainerType(
270
+ {
271
+ attestingIndices: CommitteeIndices,
272
+ data: AttestationData,
273
+ signature: BLSSignature,
274
+ },
275
+ {typeName: "IndexedAttestation", jsonCase: "eth2"}
276
+ );
277
+
278
+ /** Same as `IndexedAttestation` but epoch, slot and index are not bounded and must be a bigint */
279
+ export const IndexedAttestationBigint = new ContainerType(
280
+ {
281
+ attestingIndices: CommitteeIndices,
282
+ data: AttestationDataBigint,
283
+ signature: BLSSignature,
284
+ },
285
+ {typeName: "IndexedAttestation", jsonCase: "eth2"}
286
+ );
287
+
288
+ export const PendingAttestation = new ContainerType(
289
+ {
290
+ aggregationBits: CommitteeBits,
291
+ data: AttestationData,
292
+ inclusionDelay: Slot,
293
+ proposerIndex: ValidatorIndex,
294
+ },
295
+ {typeName: "PendingAttestation", jsonCase: "eth2"}
296
+ );
297
+
298
+ export const SigningData = new ContainerType(
299
+ {
300
+ objectRoot: Root,
301
+ domain: Domain,
302
+ },
303
+ {typeName: "SigningData", jsonCase: "eth2"}
304
+ );
305
+
306
+ // Operations types
307
+ // ================
308
+
309
+ export const Attestation = new ContainerType(
310
+ {
311
+ aggregationBits: CommitteeBits,
312
+ data: AttestationData,
313
+ signature: BLSSignature,
314
+ },
315
+ {typeName: "Attestation", jsonCase: "eth2"}
316
+ );
317
+
318
+ export const SingleAttestation = Attestation;
319
+
320
+ export const AttesterSlashing = new ContainerType(
321
+ {
322
+ // In state transition, AttesterSlashing attestations are only partially validated. Their slot and epoch could
323
+ // be higher than the clock and the slashing would still be valid. Same applies to attestation data index, which
324
+ // can be any arbitrary value. Must use bigint variants to hash correctly to all possible values
325
+ attestation1: IndexedAttestationBigint,
326
+ attestation2: IndexedAttestationBigint,
327
+ },
328
+ {typeName: "AttesterSlashing", jsonCase: "eth2"}
329
+ );
330
+
331
+ export const Deposit = new ContainerType(
332
+ {
333
+ proof: new VectorCompositeType(Bytes32, DEPOSIT_CONTRACT_TREE_DEPTH + 1),
334
+ data: DepositData,
335
+ },
336
+ {typeName: "Deposit", jsonCase: "eth2"}
337
+ );
338
+
339
+ export const ProposerSlashing = new ContainerType(
340
+ {
341
+ // In state transition, ProposerSlashing headers are only partially validated. Their slot could be higher than the
342
+ // clock and the slashing would still be valid. Must use bigint variants to hash correctly to all possible values
343
+ signedHeader1: SignedBeaconBlockHeaderBigint,
344
+ signedHeader2: SignedBeaconBlockHeaderBigint,
345
+ },
346
+ {typeName: "ProposerSlashing", jsonCase: "eth2"}
347
+ );
348
+
349
+ export const VoluntaryExit = new ContainerType(
350
+ {
351
+ epoch: Epoch,
352
+ validatorIndex: ValidatorIndex,
353
+ },
354
+ {typeName: "VoluntaryExit", jsonCase: "eth2", cachePermanentRootStruct: true}
355
+ );
356
+
357
+ export const SignedVoluntaryExit = new ContainerType(
358
+ {
359
+ message: VoluntaryExit,
360
+ signature: BLSSignature,
361
+ },
362
+ {typeName: "SignedVoluntaryExit", jsonCase: "eth2"}
363
+ );
364
+
365
+ // Block types
366
+ // ===========
367
+
368
+ export const BeaconBlockBody = new ContainerType(
369
+ {
370
+ randaoReveal: BLSSignature,
371
+ eth1Data: Eth1Data,
372
+ graffiti: Bytes32,
373
+ proposerSlashings: new ListCompositeType(ProposerSlashing, MAX_PROPOSER_SLASHINGS),
374
+ attesterSlashings: new ListCompositeType(AttesterSlashing, MAX_ATTESTER_SLASHINGS),
375
+ attestations: new ListCompositeType(Attestation, MAX_ATTESTATIONS),
376
+ deposits: new ListCompositeType(Deposit, MAX_DEPOSITS),
377
+ voluntaryExits: new ListCompositeType(SignedVoluntaryExit, MAX_VOLUNTARY_EXITS),
378
+ },
379
+ {typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true}
380
+ );
381
+
382
+ export const BeaconBlock = new ContainerType(
383
+ {
384
+ slot: Slot,
385
+ proposerIndex: ValidatorIndex,
386
+ parentRoot: Root,
387
+ stateRoot: Root,
388
+ body: BeaconBlockBody,
389
+ },
390
+ {typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true}
391
+ );
392
+
393
+ export const SignedBeaconBlock = new ContainerType(
394
+ {
395
+ message: BeaconBlock,
396
+ signature: BLSSignature,
397
+ },
398
+ {typeName: "SignedBeaconBlock", jsonCase: "eth2"}
399
+ );
400
+
401
+ // State types
402
+ // ===========
403
+
404
+ export const EpochAttestations = new ListCompositeType(PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH);
405
+
406
+ export const BeaconState = new ContainerType(
407
+ {
408
+ // Misc
409
+ genesisTime: UintNum64,
410
+ genesisValidatorsRoot: Root,
411
+ slot: Slot,
412
+ fork: Fork,
413
+ // History
414
+ latestBlockHeader: BeaconBlockHeader,
415
+ blockRoots: HistoricalBlockRoots,
416
+ stateRoots: HistoricalStateRoots,
417
+ historicalRoots: new ListCompositeType(Root, HISTORICAL_ROOTS_LIMIT),
418
+ // Eth1
419
+ eth1Data: Eth1Data,
420
+ eth1DataVotes: Eth1DataVotes,
421
+ eth1DepositIndex: UintNum64,
422
+ // Registry
423
+ validators: Validators,
424
+ balances: Balances,
425
+ randaoMixes: RandaoMixes,
426
+ // Slashings
427
+ slashings: Slashings,
428
+ // Attestations
429
+ previousEpochAttestations: EpochAttestations,
430
+ currentEpochAttestations: EpochAttestations,
431
+ // Finality
432
+ justificationBits: JustificationBits,
433
+ previousJustifiedCheckpoint: Checkpoint,
434
+ currentJustifiedCheckpoint: Checkpoint,
435
+ finalizedCheckpoint: Checkpoint,
436
+ },
437
+ {typeName: "BeaconState", jsonCase: "eth2"}
438
+ );
439
+
440
+ // Validator types
441
+ // ===============
442
+
443
+ export const CommitteeAssignment = new ContainerType(
444
+ {
445
+ validators: CommitteeIndices,
446
+ committeeIndex: CommitteeIndex,
447
+ slot: Slot,
448
+ },
449
+ {typeName: "CommitteeAssignment", jsonCase: "eth2"}
450
+ );
451
+
452
+ export const AggregateAndProof = new ContainerType(
453
+ {
454
+ aggregatorIndex: ValidatorIndex,
455
+ aggregate: Attestation,
456
+ selectionProof: BLSSignature,
457
+ },
458
+ {typeName: "AggregateAndProof", jsonCase: "eth2", cachePermanentRootStruct: true}
459
+ );
460
+
461
+ export const SignedAggregateAndProof = new ContainerType(
462
+ {
463
+ message: AggregateAndProof,
464
+ signature: BLSSignature,
465
+ },
466
+ {typeName: "SignedAggregateAndProof", jsonCase: "eth2"}
467
+ );
468
+
469
+ // ReqResp types
470
+ // =============
471
+
472
+ export const Status = new ContainerType(
473
+ {
474
+ forkDigest: ForkDigest,
475
+ finalizedRoot: Root,
476
+ finalizedEpoch: Epoch,
477
+ headRoot: Root,
478
+ headSlot: Slot,
479
+ },
480
+ {typeName: "Status", jsonCase: "eth2"}
481
+ );
482
+
483
+ export const Goodbye = UintBn64;
484
+
485
+ export const Ping = UintBn64;
486
+
487
+ export const Metadata = new ContainerType(
488
+ {
489
+ seqNumber: UintBn64,
490
+ attnets: AttestationSubnets,
491
+ },
492
+ {typeName: "Metadata", jsonCase: "eth2"}
493
+ );
494
+
495
+ export const BeaconBlocksByRangeRequest = new ContainerType(
496
+ {
497
+ startSlot: Slot,
498
+ count: UintNum64,
499
+ step: UintNum64,
500
+ },
501
+ {typeName: "BeaconBlocksByRangeRequest", jsonCase: "eth2"}
502
+ );
503
+
504
+ // Api types
505
+ // =========
506
+
507
+ export const Genesis = new ContainerType(
508
+ {
509
+ genesisValidatorsRoot: Root,
510
+ genesisTime: UintNum64,
511
+ genesisForkVersion: Version,
512
+ },
513
+ {typeName: "Genesis", jsonCase: "eth2"}
514
+ );
@@ -0,0 +1,46 @@
1
+ import {ValueOf} from "@chainsafe/ssz";
2
+ import * as ssz from "./sszTypes.js";
3
+
4
+ export type AttestationSubnets = ValueOf<typeof ssz.AttestationSubnets>;
5
+ export type BeaconBlockHeader = ValueOf<typeof ssz.BeaconBlockHeader>;
6
+ export type BeaconBlockHeaderBigint = ValueOf<typeof ssz.BeaconBlockHeaderBigint>;
7
+ export type SignedBeaconBlockHeader = ValueOf<typeof ssz.SignedBeaconBlockHeader>;
8
+ export type SignedBeaconBlockHeaderBigint = ValueOf<typeof ssz.SignedBeaconBlockHeaderBigint>;
9
+ export type Checkpoint = ValueOf<typeof ssz.Checkpoint>;
10
+ export type DepositMessage = ValueOf<typeof ssz.DepositMessage>;
11
+ export type DepositData = ValueOf<typeof ssz.DepositData>;
12
+ export type DepositEvent = ValueOf<typeof ssz.DepositEvent>;
13
+ export type Eth1Data = ValueOf<typeof ssz.Eth1Data>;
14
+ export type Eth1DataOrdered = ValueOf<typeof ssz.Eth1DataOrdered>;
15
+ export type Eth1Block = ValueOf<typeof ssz.Eth1Block>;
16
+ export type Fork = ValueOf<typeof ssz.Fork>;
17
+ export type ForkData = ValueOf<typeof ssz.ForkData>;
18
+ export type ENRForkID = ValueOf<typeof ssz.ENRForkID>;
19
+ export type HistoricalBatch = ValueOf<typeof ssz.HistoricalBatch>;
20
+ export type Validator = ValueOf<typeof ssz.Validator>;
21
+ export type Validators = ValueOf<typeof ssz.Validators>;
22
+ export type AttestationData = ValueOf<typeof ssz.AttestationData>;
23
+ export type AttestationDataBigint = ValueOf<typeof ssz.AttestationDataBigint>;
24
+ export type IndexedAttestation = ValueOf<typeof ssz.IndexedAttestation>;
25
+ export type IndexedAttestationBigint = ValueOf<typeof ssz.IndexedAttestationBigint>;
26
+ export type PendingAttestation = ValueOf<typeof ssz.PendingAttestation>;
27
+ export type SigningData = ValueOf<typeof ssz.SigningData>;
28
+ export type Attestation = ValueOf<typeof ssz.Attestation>;
29
+ export type AttesterSlashing = ValueOf<typeof ssz.AttesterSlashing>;
30
+ export type Deposit = ValueOf<typeof ssz.Deposit>;
31
+ export type ProposerSlashing = ValueOf<typeof ssz.ProposerSlashing>;
32
+ export type VoluntaryExit = ValueOf<typeof ssz.VoluntaryExit>;
33
+ export type SignedVoluntaryExit = ValueOf<typeof ssz.SignedVoluntaryExit>;
34
+ export type BeaconBlockBody = ValueOf<typeof ssz.BeaconBlockBody>;
35
+ export type BeaconBlock = ValueOf<typeof ssz.BeaconBlock>;
36
+ export type SignedBeaconBlock = ValueOf<typeof ssz.SignedBeaconBlock>;
37
+ export type BeaconState = ValueOf<typeof ssz.BeaconState>;
38
+ export type CommitteeAssignment = ValueOf<typeof ssz.CommitteeAssignment>;
39
+ export type AggregateAndProof = ValueOf<typeof ssz.AggregateAndProof>;
40
+ export type SignedAggregateAndProof = ValueOf<typeof ssz.SignedAggregateAndProof>;
41
+ export type Status = ValueOf<typeof ssz.Status>;
42
+ export type Goodbye = ValueOf<typeof ssz.Goodbye>;
43
+ export type Ping = ValueOf<typeof ssz.Ping>;
44
+ export type Metadata = ValueOf<typeof ssz.Metadata>;
45
+ export type BeaconBlocksByRangeRequest = ValueOf<typeof ssz.BeaconBlocksByRangeRequest>;
46
+ export type Genesis = ValueOf<typeof ssz.Genesis>;
@@ -0,0 +1,78 @@
1
+ import {ByteViews, ContainerNodeStructType, ValueOfFields} from "@chainsafe/ssz";
2
+ import * as primitiveSsz from "../primitive/sszTypes.js";
3
+
4
+ // biome-ignore lint/suspicious/noShadowRestrictedNames: We explicitly want `Boolean` name to be imported
5
+ const {Boolean, Bytes32, UintNum64, BLSPubkey, EpochInf} = primitiveSsz;
6
+
7
+ // this is to work with uint32, see https://github.com/ChainSafe/ssz/blob/ssz-v0.15.1/packages/ssz/src/type/uint.ts
8
+ const NUMBER_2_POW_32 = 2 ** 32;
9
+
10
+ /*
11
+ * Below constants are respective to their ssz type in `ValidatorType`.
12
+ */
13
+ const UINT32_SIZE = 4;
14
+ const PUBKEY_SIZE = 48;
15
+ const WITHDRAWAL_CREDENTIALS_SIZE = 32;
16
+ const SLASHED_SIZE = 1;
17
+
18
+ export const ValidatorType = {
19
+ pubkey: BLSPubkey,
20
+ withdrawalCredentials: Bytes32,
21
+ effectiveBalance: UintNum64,
22
+ slashed: Boolean,
23
+ activationEligibilityEpoch: EpochInf,
24
+ activationEpoch: EpochInf,
25
+ exitEpoch: EpochInf,
26
+ withdrawableEpoch: EpochInf,
27
+ };
28
+
29
+ /**
30
+ * Improve serialization performance for state.validators.serialize();
31
+ */
32
+ export class ValidatorNodeStructType extends ContainerNodeStructType<typeof ValidatorType> {
33
+ constructor() {
34
+ super(ValidatorType, {typeName: "Validator", jsonCase: "eth2"});
35
+ }
36
+
37
+ // biome-ignore lint/style/useNamingConvention: Keep the naming consistent with ssz pattern
38
+ value_serializeToBytes(
39
+ {uint8Array: output, dataView}: ByteViews,
40
+ offset: number,
41
+ validator: ValueOfFields<typeof ValidatorType>
42
+ ): number {
43
+ output.set(validator.pubkey, offset);
44
+ offset += PUBKEY_SIZE;
45
+ output.set(validator.withdrawalCredentials, offset);
46
+ offset += WITHDRAWAL_CREDENTIALS_SIZE;
47
+ const {effectiveBalance, activationEligibilityEpoch, activationEpoch, exitEpoch, withdrawableEpoch} = validator;
48
+ // effectiveBalance is UintNum64
49
+ dataView.setUint32(offset, effectiveBalance & 0xffffffff, true);
50
+ offset += UINT32_SIZE;
51
+ dataView.setUint32(offset, (effectiveBalance / NUMBER_2_POW_32) & 0xffffffff, true);
52
+ offset += UINT32_SIZE;
53
+ output[offset] = validator.slashed ? 1 : 0;
54
+ offset += SLASHED_SIZE;
55
+ offset = writeEpochInf(dataView, offset, activationEligibilityEpoch);
56
+ offset = writeEpochInf(dataView, offset, activationEpoch);
57
+ offset = writeEpochInf(dataView, offset, exitEpoch);
58
+ offset = writeEpochInf(dataView, offset, withdrawableEpoch);
59
+
60
+ return offset;
61
+ }
62
+ }
63
+
64
+ function writeEpochInf(dataView: DataView, offset: number, value: number): number {
65
+ if (value === Infinity) {
66
+ dataView.setUint32(offset, 0xffffffff, true);
67
+ offset += UINT32_SIZE;
68
+ dataView.setUint32(offset, 0xffffffff, true);
69
+ offset += UINT32_SIZE;
70
+ } else {
71
+ dataView.setUint32(offset, value & 0xffffffff, true);
72
+ offset += UINT32_SIZE;
73
+ dataView.setUint32(offset, (value / NUMBER_2_POW_32) & 0xffffffff, true);
74
+ offset += UINT32_SIZE;
75
+ }
76
+ return offset;
77
+ }
78
+ export const ValidatorNodeStruct = new ValidatorNodeStructType();
@@ -0,0 +1,3 @@
1
+ import * as ssz from "./sszTypes.js";
2
+ import * as ts from "./types.js";
3
+ export {ts, ssz};