@lodestar/types 1.35.0-dev.e18102ed8c → 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 (85) hide show
  1. package/lib/altair/index.d.ts.map +1 -0
  2. package/lib/altair/sszTypes.d.ts +1 -1
  3. package/lib/altair/sszTypes.d.ts.map +1 -0
  4. package/lib/altair/types.d.ts.map +1 -0
  5. package/lib/bellatrix/index.d.ts.map +1 -0
  6. package/lib/bellatrix/sszTypes.d.ts +15 -15
  7. package/lib/bellatrix/sszTypes.d.ts.map +1 -0
  8. package/lib/bellatrix/types.d.ts.map +1 -0
  9. package/lib/capella/index.d.ts.map +1 -0
  10. package/lib/capella/sszTypes.d.ts +41 -41
  11. package/lib/capella/sszTypes.d.ts.map +1 -0
  12. package/lib/capella/types.d.ts.map +1 -0
  13. package/lib/deneb/index.d.ts.map +1 -0
  14. package/lib/deneb/sszTypes.d.ts +44 -44
  15. package/lib/deneb/sszTypes.d.ts.map +1 -0
  16. package/lib/deneb/types.d.ts.map +1 -0
  17. package/lib/electra/index.d.ts.map +1 -0
  18. package/lib/electra/sszTypes.d.ts +67 -67
  19. package/lib/electra/sszTypes.d.ts.map +1 -0
  20. package/lib/electra/types.d.ts.map +1 -0
  21. package/lib/fulu/index.d.ts.map +1 -0
  22. package/lib/fulu/sszTypes.d.ts +22 -22
  23. package/lib/fulu/sszTypes.d.ts.map +1 -0
  24. package/lib/fulu/types.d.ts.map +1 -0
  25. package/lib/gloas/index.d.ts.map +1 -0
  26. package/lib/gloas/sszTypes.d.ts +535 -234
  27. package/lib/gloas/sszTypes.d.ts.map +1 -0
  28. package/lib/gloas/sszTypes.js +162 -3
  29. package/lib/gloas/sszTypes.js.map +1 -1
  30. package/lib/gloas/types.d.ts +13 -0
  31. package/lib/gloas/types.d.ts.map +1 -0
  32. package/lib/index.d.ts.map +1 -0
  33. package/lib/phase0/index.d.ts.map +1 -0
  34. package/lib/phase0/sszTypes.d.ts.map +1 -0
  35. package/lib/phase0/types.d.ts.map +1 -0
  36. package/lib/phase0/validator.d.ts.map +1 -0
  37. package/lib/primitive/index.d.ts.map +1 -0
  38. package/lib/primitive/sszTypes.d.ts.map +1 -0
  39. package/lib/primitive/types.d.ts.map +1 -0
  40. package/lib/sszTypes.d.ts +1668 -1450
  41. package/lib/sszTypes.d.ts.map +1 -0
  42. package/lib/types.d.ts +1 -1
  43. package/lib/types.d.ts.map +1 -0
  44. package/lib/utils/container.d.ts.map +1 -0
  45. package/lib/utils/executionAddress.d.ts.map +1 -0
  46. package/lib/utils/stringType.d.ts.map +1 -0
  47. package/lib/utils/typeguards.d.ts.map +1 -0
  48. package/lib/utils/validatorStatus.d.ts.map +1 -0
  49. package/package.json +14 -8
  50. package/src/altair/index.ts +5 -0
  51. package/src/altair/sszTypes.ts +243 -0
  52. package/src/altair/types.ts +24 -0
  53. package/src/bellatrix/index.ts +5 -0
  54. package/src/bellatrix/sszTypes.ts +238 -0
  55. package/src/bellatrix/types.ts +24 -0
  56. package/src/capella/index.ts +5 -0
  57. package/src/capella/sszTypes.ts +281 -0
  58. package/src/capella/types.ts +33 -0
  59. package/src/deneb/index.ts +5 -0
  60. package/src/deneb/sszTypes.ts +329 -0
  61. package/src/deneb/types.ts +55 -0
  62. package/src/electra/index.ts +5 -0
  63. package/src/electra/sszTypes.ts +451 -0
  64. package/src/electra/types.ts +54 -0
  65. package/src/fulu/index.ts +5 -0
  66. package/src/fulu/sszTypes.ts +138 -0
  67. package/src/fulu/types.ts +31 -0
  68. package/src/gloas/index.ts +5 -0
  69. package/src/gloas/sszTypes.ts +234 -0
  70. package/src/gloas/types.ts +20 -0
  71. package/src/index.ts +15 -0
  72. package/src/phase0/index.ts +6 -0
  73. package/src/phase0/sszTypes.ts +514 -0
  74. package/src/phase0/types.ts +46 -0
  75. package/src/phase0/validator.ts +78 -0
  76. package/src/primitive/index.ts +3 -0
  77. package/src/primitive/sszTypes.ts +70 -0
  78. package/src/primitive/types.ts +53 -0
  79. package/src/sszTypes.ts +86 -0
  80. package/src/types.ts +375 -0
  81. package/src/utils/container.ts +38 -0
  82. package/src/utils/executionAddress.ts +48 -0
  83. package/src/utils/stringType.ts +58 -0
  84. package/src/utils/typeguards.ts +98 -0
  85. package/src/utils/validatorStatus.ts +52 -0
@@ -0,0 +1,70 @@
1
+ import {BooleanType, ByteVectorType, UintBigintType, UintNumberType} from "@chainsafe/ssz";
2
+ import {ExecutionAddressType} from "../utils/executionAddress.js";
3
+
4
+ // biome-ignore lint/suspicious/noShadowRestrictedNames: We explicitly want this name for variable
5
+ export const Boolean = new BooleanType();
6
+ export const Byte = new UintNumberType(1);
7
+ export const Bytes4 = new ByteVectorType(4);
8
+ export const Bytes8 = new ByteVectorType(8);
9
+ export const Bytes20 = new ByteVectorType(20);
10
+ export const Bytes32 = new ByteVectorType(32);
11
+ export const Bytes48 = new ByteVectorType(48);
12
+ export const Bytes96 = new ByteVectorType(96);
13
+ export const Uint8 = new UintNumberType(1);
14
+ export const Uint16 = new UintNumberType(2);
15
+ export const Uint32 = new UintNumberType(4);
16
+ export const UintNum64 = new UintNumberType(8);
17
+ export const UintNumInf64 = new UintNumberType(8, {clipInfinity: true});
18
+ export const UintBn64 = new UintBigintType(8);
19
+ export const UintBn128 = new UintBigintType(16);
20
+ export const UintBn256 = new UintBigintType(32);
21
+
22
+ // Custom types, defined for type hinting and readability
23
+
24
+ /**
25
+ * Use JS Number for performance, values must be limited to 2**52-1.
26
+ * Slot is a time unit, so in all usages it's bounded by the clock, ensuring < 2**53-1
27
+ */
28
+ export const Slot = UintNum64;
29
+ /**
30
+ * Use JS Number for performance, values must be limited to 2**52-1.
31
+ * Epoch is a time unit, so in all usages it's bounded by the clock, ensuring < 2**53-1
32
+ */
33
+ export const Epoch = UintNum64;
34
+ /** Same as @see Epoch + some validator properties must represent 2**52-1 also, which we map to `Infinity` */
35
+ export const EpochInf = UintNumInf64;
36
+ /**
37
+ * Use JS Number for performance, values must be limited to 2**52-1.
38
+ * SyncPeriod is a time unit, so in all usages it's bounded by the clock, ensuring < 2**53-1
39
+ */
40
+ export const SyncPeriod = UintNum64;
41
+ /**
42
+ * Use JS Number for performance, values must be limited to 2**52-1.
43
+ * CommitteeIndex is bounded by the max possible number of committees which is bounded by `VALIDATOR_REGISTRY_LIMIT`
44
+ */
45
+ export const CommitteeIndex = UintNum64;
46
+ /** @see CommitteeIndex */
47
+ export const SubcommitteeIndex = UintNum64;
48
+ /**
49
+ * Use JS Number for performance, values must be limited to 2**52-1.
50
+ * ValidatorIndex is bounded by `VALIDATOR_REGISTRY_LIMIT`
51
+ */
52
+ export const ValidatorIndex = UintNum64;
53
+ export const WithdrawalIndex = UintNum64;
54
+ export const DepositIndex = UintBn64;
55
+ export const Gwei = UintBn64;
56
+ export const Wei = UintBn256;
57
+ export const Root = new ByteVectorType(32);
58
+ export const BlobIndex = UintNum64;
59
+
60
+ export const Version = Bytes4;
61
+ export const DomainType = Bytes4;
62
+ export const ForkDigest = Bytes4;
63
+ export const BLSPubkey = Bytes48;
64
+ export const BLSSignature = Bytes96;
65
+ export const Domain = Bytes32;
66
+ export const ParticipationFlags = new UintNumberType(1, {setBitwiseOR: true});
67
+ export const ExecutionAddress = new ExecutionAddressType();
68
+ export const ColumnIndex = UintNum64;
69
+ export const CustodyIndex = UintNum64;
70
+ export const RowIndex = UintNum64;
@@ -0,0 +1,53 @@
1
+ import {ValueOf} from "@chainsafe/ssz";
2
+ import * as ssz from "./sszTypes.js";
3
+
4
+ // Each type exported here contains both a compile-time type
5
+ // (a typescript interface) and a run-time ssz type (a javascript variable)
6
+ // For more information, see ./index.ts
7
+
8
+ export type Bytes4 = ValueOf<typeof ssz.Bytes4>;
9
+ export type Bytes8 = ValueOf<typeof ssz.Bytes8>;
10
+ export type Bytes20 = ValueOf<typeof ssz.Bytes20>;
11
+ export type Bytes32 = ValueOf<typeof ssz.Bytes32>;
12
+ export type Bytes48 = ValueOf<typeof ssz.Bytes48>;
13
+ export type Bytes96 = ValueOf<typeof ssz.Bytes96>;
14
+ export type Uint8 = ValueOf<typeof ssz.Uint8>;
15
+ export type Uint16 = ValueOf<typeof ssz.Uint16>;
16
+ export type Uint32 = ValueOf<typeof ssz.Uint32>;
17
+ export type UintNum64 = ValueOf<typeof ssz.UintNum64>;
18
+ export type UintNumInf64 = ValueOf<typeof ssz.UintNumInf64>;
19
+ export type UintBn64 = ValueOf<typeof ssz.UintBn64>;
20
+ export type UintBn128 = ValueOf<typeof ssz.UintBn128>;
21
+ export type UintBn256 = ValueOf<typeof ssz.UintBn256>;
22
+
23
+ // Custom types, defined for type hinting and readability
24
+
25
+ export type Slot = UintNumInf64;
26
+ export type Epoch = UintNumInf64;
27
+ export type SyncPeriod = UintNum64;
28
+ export type CommitteeIndex = UintNum64;
29
+ export type SubcommitteeIndex = UintNum64;
30
+ export type ValidatorIndex = UintNum64;
31
+ export type WithdrawalIndex = UintNum64;
32
+ export type BlobIndex = UintNum64;
33
+ export type SubnetID = UintNum64;
34
+ export type Gwei = UintBn64;
35
+ export type Wei = UintBn256;
36
+ export type Root = Bytes32;
37
+ export type Version = Bytes4;
38
+ export type DomainType = Bytes4;
39
+ export type ForkDigest = Bytes4;
40
+ export type Domain = Bytes32;
41
+ export type BLSPubkey = Bytes48;
42
+ export type BLSSecretKey = Bytes32;
43
+ export type BLSSignature = Bytes96;
44
+ export type ParticipationFlags = Uint8;
45
+ export type ExecutionAddress = Bytes20;
46
+
47
+ /** Common non-spec type to represent roots as strings */
48
+ export type RootHex = string;
49
+ /** Non-spec type to signal time is represented in seconds */
50
+ export type TimeSeconds = number;
51
+ export type ColumnIndex = UintNum64;
52
+ export type CustodyIndex = UintNum64;
53
+ export type RowIndex = UintNum64;
@@ -0,0 +1,86 @@
1
+ import {CompositeType, CompositeView, CompositeViewDU, ContainerType, ValueOf} from "@chainsafe/ssz";
2
+ import {ForkName} from "@lodestar/params";
3
+ import {ssz as altairSsz} from "./altair/index.js";
4
+ import {ssz as bellatrixSsz} from "./bellatrix/index.js";
5
+ import {ssz as capellaSsz} from "./capella/index.js";
6
+ import {ssz as denebSsz} from "./deneb/index.js";
7
+ import {ssz as electraSsz} from "./electra/index.js";
8
+ import {ssz as fuluSsz} from "./fulu/index.js";
9
+ import {ssz as gloasSsz} from "./gloas/index.js";
10
+ import {ssz as phase0Ssz} from "./phase0/index.js";
11
+
12
+ export * from "./primitive/sszTypes.js";
13
+
14
+ /**
15
+ * Index the ssz types that differ by fork
16
+ * A record of AllForksSSZTypes indexed by fork
17
+ */
18
+ const typesByFork = {
19
+ [ForkName.phase0]: {...phase0Ssz},
20
+ [ForkName.altair]: {...phase0Ssz, ...altairSsz},
21
+ [ForkName.bellatrix]: {...phase0Ssz, ...altairSsz, ...bellatrixSsz},
22
+ [ForkName.capella]: {...phase0Ssz, ...altairSsz, ...bellatrixSsz, ...capellaSsz},
23
+ [ForkName.deneb]: {...phase0Ssz, ...altairSsz, ...bellatrixSsz, ...capellaSsz, ...denebSsz},
24
+ [ForkName.electra]: {...phase0Ssz, ...altairSsz, ...bellatrixSsz, ...capellaSsz, ...denebSsz, ...electraSsz},
25
+ [ForkName.fulu]: {...phase0Ssz, ...altairSsz, ...bellatrixSsz, ...capellaSsz, ...denebSsz, ...electraSsz, ...fuluSsz},
26
+ [ForkName.gloas]: {
27
+ ...phase0Ssz,
28
+ ...altairSsz,
29
+ ...bellatrixSsz,
30
+ ...capellaSsz,
31
+ ...denebSsz,
32
+ ...electraSsz,
33
+ ...fuluSsz,
34
+ ...gloasSsz,
35
+ },
36
+ };
37
+
38
+ // Export these types to ensure that each fork is a superset of the previous one (with overridden types obviously)
39
+ // This allows us to only declare types that change in each fork in each fork subdirectory
40
+
41
+ export const phase0 = typesByFork[ForkName.phase0];
42
+ export const altair = typesByFork[ForkName.altair];
43
+ export const bellatrix = typesByFork[ForkName.bellatrix];
44
+ export const capella = typesByFork[ForkName.capella];
45
+ export const deneb = typesByFork[ForkName.deneb];
46
+ export const electra = typesByFork[ForkName.electra];
47
+ export const fulu = typesByFork[ForkName.fulu];
48
+ export const gloas = typesByFork[ForkName.gloas];
49
+
50
+ /**
51
+ * A type of union of forks must accept as any parameter the UNION of all fork types.
52
+ */
53
+
54
+ // biome-ignore lint/suspicious/noExplicitAny: We need to use `any` type here
55
+ type UnionSSZForksTypeOf<UnionOfForkTypes extends ContainerType<any>> = CompositeType<
56
+ ValueOf<UnionOfForkTypes>,
57
+ CompositeView<UnionOfForkTypes>,
58
+ CompositeViewDU<UnionOfForkTypes>
59
+ >;
60
+
61
+ type SSZTypesByFork = {
62
+ [F in keyof typeof typesByFork]: {
63
+ [T in keyof (typeof typesByFork)[F]]: (typeof typesByFork)[F][T];
64
+ };
65
+ };
66
+
67
+ export type SSZTypesFor<F extends ForkName, K extends keyof SSZTypesByFork[F] | void = void> = K extends void
68
+ ? // It compiles fine, need to debug the error
69
+ // @ts-expect-error
70
+ {[K2 in keyof SSZTypesByFork[F]]: UnionSSZForksTypeOf<SSZTypesByFork[F][K2]>}
71
+ : // It compiles fine, need to debug the error
72
+ // @ts-expect-error
73
+ UnionSSZForksTypeOf<SSZTypesByFork[F][Exclude<K, void>]>;
74
+
75
+ export function sszTypesFor<F extends ForkName, K extends keyof SSZTypesByFork[F] | void = void>(
76
+ fork: F,
77
+ typeName?: K
78
+ ): SSZTypesFor<F, K> {
79
+ const sszTypes = typesByFork[fork];
80
+
81
+ if (sszTypes === undefined) {
82
+ throw Error(`SSZ types for fork ${fork} are not defined`);
83
+ }
84
+
85
+ return (typeName === undefined ? sszTypes : sszTypes[typeName as keyof SSZTypesByFork[F]]) as SSZTypesFor<F, K>;
86
+ }
package/src/types.ts ADDED
@@ -0,0 +1,375 @@
1
+ import {ForkAll, ForkName, ForkPostAltair, ForkPostBellatrix, ForkPostDeneb, ForkPostElectra} from "@lodestar/params";
2
+ import {ts as altair} from "./altair/index.js";
3
+ import {ts as bellatrix} from "./bellatrix/index.js";
4
+ import {ts as capella} from "./capella/index.js";
5
+ import {ts as deneb} from "./deneb/index.js";
6
+ import {ts as electra} from "./electra/index.js";
7
+ import {ts as fulu} from "./fulu/index.js";
8
+ import {ts as gloas} from "./gloas/index.js";
9
+ import {ts as phase0} from "./phase0/index.js";
10
+ import {Slot} from "./primitive/types.js";
11
+
12
+ export {ts as altair} from "./altair/index.js";
13
+ export {ts as bellatrix} from "./bellatrix/index.js";
14
+ export {ts as capella} from "./capella/index.js";
15
+ export {ts as deneb} from "./deneb/index.js";
16
+ export {ts as electra} from "./electra/index.js";
17
+ export {ts as fulu} from "./fulu/index.js";
18
+ export {ts as gloas} from "./gloas/index.js";
19
+ export {ts as phase0} from "./phase0/index.js";
20
+ export * from "./primitive/types.js";
21
+
22
+ /** Common non-spec type to represent roots as strings */
23
+ export type RootHex = string;
24
+
25
+ /** Handy enum to represent the block production source */
26
+ export enum ProducedBlockSource {
27
+ builder = "builder",
28
+ engine = "engine",
29
+ }
30
+
31
+ export type WithBytes<T> = {
32
+ data: T;
33
+ /** SSZ serialized `data` bytes */
34
+ bytes: Uint8Array;
35
+ };
36
+
37
+ export type WithOptionalBytes<T> = {
38
+ data: T;
39
+ /** SSZ serialized `data` bytes */
40
+ bytes?: Uint8Array | null;
41
+ };
42
+
43
+ export type SlotRootHex = {slot: Slot; root: RootHex};
44
+ export type SlotOptionalRoot = {slot: Slot; root?: RootHex};
45
+ export type RootOptionalSlot = {root: RootHex; slot?: Slot};
46
+
47
+ type TypesByFork = {
48
+ [ForkName.phase0]: {
49
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
50
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
51
+ BeaconBlock: phase0.BeaconBlock;
52
+ BeaconBlockBody: phase0.BeaconBlockBody;
53
+ BeaconState: phase0.BeaconState;
54
+ SignedBeaconBlock: phase0.SignedBeaconBlock;
55
+ Metadata: phase0.Metadata;
56
+ Status: phase0.Status;
57
+ SingleAttestation: phase0.Attestation;
58
+ Attestation: phase0.Attestation;
59
+ IndexedAttestation: phase0.IndexedAttestation;
60
+ IndexedAttestationBigint: phase0.IndexedAttestationBigint;
61
+ AttesterSlashing: phase0.AttesterSlashing;
62
+ AggregateAndProof: phase0.AggregateAndProof;
63
+ SignedAggregateAndProof: phase0.SignedAggregateAndProof;
64
+ BlockContents: {block: phase0.BeaconBlock};
65
+ SignedBlockContents: {signedBlock: phase0.SignedBeaconBlock};
66
+ };
67
+ [ForkName.altair]: {
68
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
69
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
70
+ BeaconBlock: altair.BeaconBlock;
71
+ BeaconBlockBody: altair.BeaconBlockBody;
72
+ BeaconState: altair.BeaconState;
73
+ SignedBeaconBlock: altair.SignedBeaconBlock;
74
+ Metadata: altair.Metadata;
75
+ Status: phase0.Status;
76
+ LightClientHeader: altair.LightClientHeader;
77
+ LightClientBootstrap: altair.LightClientBootstrap;
78
+ LightClientUpdate: altair.LightClientUpdate;
79
+ LightClientFinalityUpdate: altair.LightClientFinalityUpdate;
80
+ LightClientOptimisticUpdate: altair.LightClientOptimisticUpdate;
81
+ LightClientStore: altair.LightClientStore;
82
+ SyncCommittee: altair.SyncCommittee;
83
+ SyncAggregate: altair.SyncAggregate;
84
+ SingleAttestation: phase0.Attestation;
85
+ Attestation: phase0.Attestation;
86
+ IndexedAttestation: phase0.IndexedAttestation;
87
+ IndexedAttestationBigint: phase0.IndexedAttestationBigint;
88
+ AttesterSlashing: phase0.AttesterSlashing;
89
+ AggregateAndProof: phase0.AggregateAndProof;
90
+ SignedAggregateAndProof: phase0.SignedAggregateAndProof;
91
+ BlockContents: {block: altair.BeaconBlock};
92
+ SignedBlockContents: {signedBlock: altair.SignedBeaconBlock};
93
+ };
94
+ [ForkName.bellatrix]: {
95
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
96
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
97
+ BeaconBlock: bellatrix.BeaconBlock;
98
+ BeaconBlockBody: bellatrix.BeaconBlockBody;
99
+ BeaconState: bellatrix.BeaconState;
100
+ SignedBeaconBlock: bellatrix.SignedBeaconBlock;
101
+ Metadata: altair.Metadata;
102
+ Status: phase0.Status;
103
+ LightClientHeader: altair.LightClientHeader;
104
+ LightClientBootstrap: altair.LightClientBootstrap;
105
+ LightClientUpdate: altair.LightClientUpdate;
106
+ LightClientFinalityUpdate: altair.LightClientFinalityUpdate;
107
+ LightClientOptimisticUpdate: altair.LightClientOptimisticUpdate;
108
+ LightClientStore: altair.LightClientStore;
109
+ BlindedBeaconBlock: bellatrix.BlindedBeaconBlock;
110
+ BlindedBeaconBlockBody: bellatrix.BlindedBeaconBlockBody;
111
+ SignedBlindedBeaconBlock: bellatrix.SignedBlindedBeaconBlock;
112
+ ExecutionPayload: bellatrix.ExecutionPayload;
113
+ ExecutionPayloadHeader: bellatrix.ExecutionPayloadHeader;
114
+ BuilderBid: bellatrix.BuilderBid;
115
+ SignedBuilderBid: bellatrix.SignedBuilderBid;
116
+ SSEPayloadAttributes: bellatrix.SSEPayloadAttributes;
117
+ SyncCommittee: altair.SyncCommittee;
118
+ SyncAggregate: altair.SyncAggregate;
119
+ SingleAttestation: phase0.Attestation;
120
+ Attestation: phase0.Attestation;
121
+ IndexedAttestation: phase0.IndexedAttestation;
122
+ IndexedAttestationBigint: phase0.IndexedAttestationBigint;
123
+ AttesterSlashing: phase0.AttesterSlashing;
124
+ AggregateAndProof: phase0.AggregateAndProof;
125
+ SignedAggregateAndProof: phase0.SignedAggregateAndProof;
126
+ BlockContents: {block: bellatrix.BeaconBlock};
127
+ SignedBlockContents: {signedBlock: bellatrix.SignedBeaconBlock};
128
+ };
129
+ [ForkName.capella]: {
130
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
131
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
132
+ BeaconBlock: capella.BeaconBlock;
133
+ BeaconBlockBody: capella.BeaconBlockBody;
134
+ BeaconState: capella.BeaconState;
135
+ SignedBeaconBlock: capella.SignedBeaconBlock;
136
+ Metadata: altair.Metadata;
137
+ Status: phase0.Status;
138
+ LightClientHeader: capella.LightClientHeader;
139
+ LightClientBootstrap: capella.LightClientBootstrap;
140
+ LightClientUpdate: capella.LightClientUpdate;
141
+ LightClientFinalityUpdate: capella.LightClientFinalityUpdate;
142
+ LightClientOptimisticUpdate: capella.LightClientOptimisticUpdate;
143
+ LightClientStore: capella.LightClientStore;
144
+ BlindedBeaconBlock: capella.BlindedBeaconBlock;
145
+ BlindedBeaconBlockBody: capella.BlindedBeaconBlockBody;
146
+ SignedBlindedBeaconBlock: capella.SignedBlindedBeaconBlock;
147
+ ExecutionPayload: capella.ExecutionPayload;
148
+ ExecutionPayloadHeader: capella.ExecutionPayloadHeader;
149
+ BuilderBid: capella.BuilderBid;
150
+ SignedBuilderBid: capella.SignedBuilderBid;
151
+ SSEPayloadAttributes: capella.SSEPayloadAttributes;
152
+ SyncCommittee: altair.SyncCommittee;
153
+ SyncAggregate: altair.SyncAggregate;
154
+ SingleAttestation: phase0.Attestation;
155
+ Attestation: phase0.Attestation;
156
+ IndexedAttestation: phase0.IndexedAttestation;
157
+ IndexedAttestationBigint: phase0.IndexedAttestationBigint;
158
+ AttesterSlashing: phase0.AttesterSlashing;
159
+ AggregateAndProof: phase0.AggregateAndProof;
160
+ SignedAggregateAndProof: phase0.SignedAggregateAndProof;
161
+ BlockContents: {block: capella.BeaconBlock};
162
+ SignedBlockContents: {signedBlock: capella.SignedBeaconBlock};
163
+ };
164
+ [ForkName.deneb]: {
165
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
166
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
167
+ BeaconBlock: deneb.BeaconBlock;
168
+ BeaconBlockBody: deneb.BeaconBlockBody;
169
+ BeaconState: deneb.BeaconState;
170
+ SignedBeaconBlock: deneb.SignedBeaconBlock;
171
+ Metadata: altair.Metadata;
172
+ Status: phase0.Status;
173
+ LightClientHeader: deneb.LightClientHeader;
174
+ LightClientBootstrap: deneb.LightClientBootstrap;
175
+ LightClientUpdate: deneb.LightClientUpdate;
176
+ LightClientFinalityUpdate: deneb.LightClientFinalityUpdate;
177
+ LightClientOptimisticUpdate: deneb.LightClientOptimisticUpdate;
178
+ LightClientStore: deneb.LightClientStore;
179
+ BlindedBeaconBlock: deneb.BlindedBeaconBlock;
180
+ BlindedBeaconBlockBody: deneb.BlindedBeaconBlockBody;
181
+ SignedBlindedBeaconBlock: deneb.SignedBlindedBeaconBlock;
182
+ ExecutionPayload: deneb.ExecutionPayload;
183
+ ExecutionPayloadHeader: deneb.ExecutionPayloadHeader;
184
+ BuilderBid: deneb.BuilderBid;
185
+ SignedBuilderBid: deneb.SignedBuilderBid;
186
+ SSEPayloadAttributes: deneb.SSEPayloadAttributes;
187
+ BlockContents: deneb.BlockContents;
188
+ SignedBlockContents: deneb.SignedBlockContents;
189
+ ExecutionPayloadAndBlobsBundle: deneb.ExecutionPayloadAndBlobsBundle;
190
+ BlobsBundle: deneb.BlobsBundle;
191
+ SyncCommittee: altair.SyncCommittee;
192
+ SyncAggregate: altair.SyncAggregate;
193
+ SingleAttestation: phase0.Attestation;
194
+ Attestation: phase0.Attestation;
195
+ IndexedAttestation: phase0.IndexedAttestation;
196
+ IndexedAttestationBigint: phase0.IndexedAttestationBigint;
197
+ AttesterSlashing: phase0.AttesterSlashing;
198
+ AggregateAndProof: phase0.AggregateAndProof;
199
+ SignedAggregateAndProof: phase0.SignedAggregateAndProof;
200
+ };
201
+ [ForkName.electra]: {
202
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
203
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
204
+ BeaconBlock: electra.BeaconBlock;
205
+ BeaconBlockBody: electra.BeaconBlockBody;
206
+ BeaconState: electra.BeaconState;
207
+ SignedBeaconBlock: electra.SignedBeaconBlock;
208
+ Metadata: altair.Metadata;
209
+ Status: phase0.Status;
210
+ LightClientHeader: deneb.LightClientHeader;
211
+ LightClientBootstrap: electra.LightClientBootstrap;
212
+ LightClientUpdate: electra.LightClientUpdate;
213
+ LightClientFinalityUpdate: electra.LightClientFinalityUpdate;
214
+ LightClientOptimisticUpdate: electra.LightClientOptimisticUpdate;
215
+ LightClientStore: electra.LightClientStore;
216
+ BlindedBeaconBlock: electra.BlindedBeaconBlock;
217
+ BlindedBeaconBlockBody: electra.BlindedBeaconBlockBody;
218
+ SignedBlindedBeaconBlock: electra.SignedBlindedBeaconBlock;
219
+ ExecutionPayload: deneb.ExecutionPayload;
220
+ ExecutionPayloadHeader: deneb.ExecutionPayloadHeader;
221
+ BuilderBid: electra.BuilderBid;
222
+ SignedBuilderBid: electra.SignedBuilderBid;
223
+ SSEPayloadAttributes: electra.SSEPayloadAttributes;
224
+ BlockContents: electra.BlockContents;
225
+ SignedBlockContents: electra.SignedBlockContents;
226
+ ExecutionPayloadAndBlobsBundle: deneb.ExecutionPayloadAndBlobsBundle;
227
+ BlobsBundle: deneb.BlobsBundle;
228
+ SyncCommittee: altair.SyncCommittee;
229
+ SyncAggregate: altair.SyncAggregate;
230
+ SingleAttestation: electra.SingleAttestation;
231
+ Attestation: electra.Attestation;
232
+ IndexedAttestation: electra.IndexedAttestation;
233
+ IndexedAttestationBigint: electra.IndexedAttestationBigint;
234
+ AttesterSlashing: electra.AttesterSlashing;
235
+ AggregateAndProof: electra.AggregateAndProof;
236
+ SignedAggregateAndProof: electra.SignedAggregateAndProof;
237
+ ExecutionRequests: electra.ExecutionRequests;
238
+ };
239
+ [ForkName.fulu]: {
240
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
241
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
242
+ BeaconBlock: electra.BeaconBlock;
243
+ BeaconBlockBody: electra.BeaconBlockBody;
244
+ BeaconState: fulu.BeaconState;
245
+ SignedBeaconBlock: electra.SignedBeaconBlock;
246
+ Metadata: fulu.Metadata;
247
+ Status: fulu.Status;
248
+ LightClientHeader: deneb.LightClientHeader;
249
+ LightClientBootstrap: electra.LightClientBootstrap;
250
+ LightClientUpdate: electra.LightClientUpdate;
251
+ LightClientFinalityUpdate: electra.LightClientFinalityUpdate;
252
+ LightClientOptimisticUpdate: electra.LightClientOptimisticUpdate;
253
+ LightClientStore: electra.LightClientStore;
254
+ BlindedBeaconBlock: electra.BlindedBeaconBlock;
255
+ BlindedBeaconBlockBody: electra.BlindedBeaconBlockBody;
256
+ SignedBlindedBeaconBlock: electra.SignedBlindedBeaconBlock;
257
+ ExecutionPayload: deneb.ExecutionPayload;
258
+ ExecutionPayloadHeader: deneb.ExecutionPayloadHeader;
259
+ BuilderBid: electra.BuilderBid;
260
+ SignedBuilderBid: electra.SignedBuilderBid;
261
+ SSEPayloadAttributes: electra.SSEPayloadAttributes;
262
+ BlockContents: fulu.BlockContents;
263
+ SignedBlockContents: fulu.SignedBlockContents;
264
+ ExecutionPayloadAndBlobsBundle: deneb.ExecutionPayloadAndBlobsBundle;
265
+ BlobsBundle: fulu.BlobsBundle;
266
+ SyncCommittee: altair.SyncCommittee;
267
+ SyncAggregate: altair.SyncAggregate;
268
+ SingleAttestation: electra.SingleAttestation;
269
+ Attestation: electra.Attestation;
270
+ IndexedAttestation: electra.IndexedAttestation;
271
+ IndexedAttestationBigint: electra.IndexedAttestationBigint;
272
+ AttesterSlashing: electra.AttesterSlashing;
273
+ AggregateAndProof: electra.AggregateAndProof;
274
+ SignedAggregateAndProof: electra.SignedAggregateAndProof;
275
+ ExecutionRequests: electra.ExecutionRequests;
276
+ };
277
+ [ForkName.gloas]: {
278
+ BeaconBlockHeader: phase0.BeaconBlockHeader;
279
+ SignedBeaconBlockHeader: phase0.SignedBeaconBlockHeader;
280
+ BeaconBlock: gloas.BeaconBlock;
281
+ BeaconBlockBody: gloas.BeaconBlockBody;
282
+ BeaconState: gloas.BeaconState;
283
+ SignedBeaconBlock: gloas.SignedBeaconBlock;
284
+ Metadata: fulu.Metadata;
285
+ Status: fulu.Status;
286
+ LightClientHeader: deneb.LightClientHeader;
287
+ LightClientBootstrap: electra.LightClientBootstrap;
288
+ LightClientUpdate: electra.LightClientUpdate;
289
+ LightClientFinalityUpdate: electra.LightClientFinalityUpdate;
290
+ LightClientOptimisticUpdate: electra.LightClientOptimisticUpdate;
291
+ LightClientStore: electra.LightClientStore;
292
+ BlindedBeaconBlock: electra.BlindedBeaconBlock;
293
+ BlindedBeaconBlockBody: electra.BlindedBeaconBlockBody;
294
+ SignedBlindedBeaconBlock: electra.SignedBlindedBeaconBlock;
295
+ ExecutionPayload: deneb.ExecutionPayload;
296
+ ExecutionPayloadHeader: deneb.ExecutionPayloadHeader;
297
+ BuilderBid: electra.BuilderBid;
298
+ SignedBuilderBid: electra.SignedBuilderBid;
299
+ SSEPayloadAttributes: electra.SSEPayloadAttributes;
300
+ BlockContents: fulu.BlockContents;
301
+ SignedBlockContents: fulu.SignedBlockContents;
302
+ ExecutionPayloadAndBlobsBundle: deneb.ExecutionPayloadAndBlobsBundle;
303
+ BlobsBundle: fulu.BlobsBundle;
304
+ SyncCommittee: altair.SyncCommittee;
305
+ SyncAggregate: altair.SyncAggregate;
306
+ SingleAttestation: electra.SingleAttestation;
307
+ Attestation: electra.Attestation;
308
+ IndexedAttestation: electra.IndexedAttestation;
309
+ IndexedAttestationBigint: electra.IndexedAttestationBigint;
310
+ AttesterSlashing: electra.AttesterSlashing;
311
+ AggregateAndProof: electra.AggregateAndProof;
312
+ SignedAggregateAndProof: electra.SignedAggregateAndProof;
313
+ ExecutionRequests: electra.ExecutionRequests;
314
+ };
315
+ };
316
+
317
+ export type TypesFor<F extends ForkName, K extends keyof TypesByFork[F] | void = void> = K extends void
318
+ ? TypesByFork[F]
319
+ : TypesByFork[F][Exclude<K, void>];
320
+
321
+ export type BeaconBlockHeader<F extends ForkAll = ForkAll> = TypesByFork[F]["BeaconBlockHeader"];
322
+ export type SignedBeaconBlockHeader<F extends ForkAll = ForkAll> = TypesByFork[F]["SignedBeaconBlockHeader"];
323
+
324
+ export type BeaconBlock<F extends ForkAll = ForkAll> = TypesByFork[F]["BeaconBlock"];
325
+ export type BlindedBeaconBlock<F extends ForkPostBellatrix = ForkPostBellatrix> = TypesByFork[F]["BlindedBeaconBlock"];
326
+
327
+ export type SignedBeaconBlock<F extends ForkAll = ForkAll> = TypesByFork[F]["SignedBeaconBlock"];
328
+ export type SignedBlindedBeaconBlock<F extends ForkPostBellatrix = ForkPostBellatrix> =
329
+ TypesByFork[F]["SignedBlindedBeaconBlock"];
330
+
331
+ export type BeaconBlockBody<F extends ForkAll = ForkAll> = TypesByFork[F]["BeaconBlockBody"];
332
+ export type BlindedBeaconBlockBody<F extends ForkPostBellatrix = ForkPostBellatrix> =
333
+ TypesByFork[F]["BlindedBeaconBlockBody"];
334
+
335
+ export type BlockContents<F extends ForkAll = ForkAll> = TypesByFork[F]["BlockContents"];
336
+ export type SignedBlockContents<F extends ForkAll = ForkAll> = TypesByFork[F]["SignedBlockContents"];
337
+ export type SignedOrUnsignedBlockContents<F extends ForkAll = ForkAll> = BlockContents<F> | SignedBlockContents<F>;
338
+
339
+ export type ExecutionPayload<F extends ForkPostBellatrix = ForkPostBellatrix> = TypesByFork[F]["ExecutionPayload"];
340
+ export type ExecutionPayloadHeader<F extends ForkPostBellatrix = ForkPostBellatrix> =
341
+ TypesByFork[F]["ExecutionPayloadHeader"];
342
+ export type ExecutionRequests<F extends ForkPostElectra = ForkPostElectra> = TypesByFork[F]["ExecutionRequests"];
343
+
344
+ export type ExecutionPayloadAndBlobsBundle<F extends ForkPostDeneb = ForkPostDeneb> =
345
+ TypesByFork[F]["ExecutionPayloadAndBlobsBundle"];
346
+ export type BlobsBundle<F extends ForkPostDeneb = ForkPostDeneb> = TypesByFork[F]["BlobsBundle"];
347
+
348
+ export type LightClientHeader<F extends ForkPostAltair = ForkPostAltair> = TypesByFork[F]["LightClientHeader"];
349
+ export type LightClientBootstrap<F extends ForkPostAltair = ForkPostAltair> = TypesByFork[F]["LightClientBootstrap"];
350
+ export type LightClientUpdate<F extends ForkPostAltair = ForkPostAltair> = TypesByFork[F]["LightClientUpdate"];
351
+ export type LightClientFinalityUpdate<F extends ForkPostAltair = ForkPostAltair> =
352
+ TypesByFork[F]["LightClientFinalityUpdate"];
353
+ export type LightClientOptimisticUpdate<F extends ForkPostAltair = ForkPostAltair> =
354
+ TypesByFork[F]["LightClientOptimisticUpdate"];
355
+ export type LightClientStore<F extends ForkPostAltair = ForkPostAltair> = TypesByFork[F]["LightClientStore"];
356
+ export type SyncCommittee<F extends ForkPostAltair = ForkPostAltair> = TypesByFork[F]["SyncCommittee"];
357
+ export type SyncAggregate<F extends ForkPostAltair = ForkPostAltair> = TypesByFork[F]["SyncAggregate"];
358
+
359
+ export type BeaconState<F extends ForkName = ForkAll> = TypesByFork[F]["BeaconState"];
360
+
361
+ export type Metadata<F extends ForkName = ForkAll> = TypesByFork[F]["Metadata"];
362
+ export type Status<F extends ForkName = ForkAll> = TypesByFork[F]["Status"];
363
+
364
+ export type BuilderBid<F extends ForkPostBellatrix = ForkPostBellatrix> = TypesByFork[F]["BuilderBid"];
365
+ export type SignedBuilderBid<F extends ForkPostBellatrix = ForkPostBellatrix> = TypesByFork[F]["SignedBuilderBid"];
366
+ export type SSEPayloadAttributes<F extends ForkPostBellatrix = ForkPostBellatrix> =
367
+ TypesByFork[F]["SSEPayloadAttributes"];
368
+
369
+ export type Attestation<F extends ForkName = ForkAll> = TypesByFork[F]["Attestation"];
370
+ export type SingleAttestation<F extends ForkName = ForkAll> = TypesByFork[F]["SingleAttestation"];
371
+ export type IndexedAttestation<F extends ForkName = ForkAll> = TypesByFork[F]["IndexedAttestation"];
372
+ export type IndexedAttestationBigint<F extends ForkName = ForkAll> = TypesByFork[F]["IndexedAttestationBigint"];
373
+ export type AttesterSlashing<F extends ForkName = ForkAll> = TypesByFork[F]["AttesterSlashing"];
374
+ export type AggregateAndProof<F extends ForkName = ForkAll> = TypesByFork[F]["AggregateAndProof"];
375
+ export type SignedAggregateAndProof<F extends ForkName = ForkAll> = TypesByFork[F]["SignedAggregateAndProof"];
@@ -0,0 +1,38 @@
1
+ import {CompositeTypeAny, CompositeViewDU, ContainerType, Type} from "@chainsafe/ssz";
2
+
3
+ type BytesRange = {start: number; end: number};
4
+
5
+ /**
6
+ * Deserialize a state from bytes ignoring some fields.
7
+ */
8
+ export function deserializeContainerIgnoreFields<Fields extends Record<string, Type<unknown>>>(
9
+ sszType: ContainerType<Fields>,
10
+ bytes: Uint8Array,
11
+ ignoreFields: (keyof Fields)[],
12
+ fieldRanges?: BytesRange[]
13
+ ): CompositeViewDU<typeof sszType> {
14
+ const allFields = Object.keys(sszType.fields);
15
+ const object = sszType.defaultViewDU();
16
+ if (!fieldRanges) {
17
+ const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
18
+ fieldRanges = sszType.getFieldRanges(dataView, 0, bytes.length);
19
+ }
20
+
21
+ for (const [field, type] of Object.entries(sszType.fields)) {
22
+ // loaded above
23
+ if (ignoreFields.includes(field)) {
24
+ continue;
25
+ }
26
+ const fieldIndex = allFields.indexOf(field);
27
+ const fieldRange = fieldRanges[fieldIndex];
28
+ if (type.isBasic) {
29
+ object[field as keyof Fields] = type.deserialize(bytes.subarray(fieldRange.start, fieldRange.end)) as never;
30
+ } else {
31
+ object[field as keyof Fields] = (type as CompositeTypeAny).deserializeToViewDU(
32
+ bytes.subarray(fieldRange.start, fieldRange.end)
33
+ ) as never;
34
+ }
35
+ }
36
+
37
+ return object;
38
+ }
@@ -0,0 +1,48 @@
1
+ import {keccak256} from "ethereum-cryptography/keccak.js";
2
+ import {ByteVectorType} from "@chainsafe/ssz";
3
+
4
+ export type ByteVector = Uint8Array;
5
+
6
+ export class ExecutionAddressType extends ByteVectorType {
7
+ constructor() {
8
+ super(20, {typeName: "ExecutionAddress"});
9
+ }
10
+ toJson(value: ByteVector): unknown {
11
+ const str = super.toJson(value) as string;
12
+ return toChecksumAddress(str);
13
+ }
14
+ }
15
+
16
+ function isAddressValid(address: string): boolean {
17
+ return /^(0x)?[0-9a-f]{40}$/i.test(address);
18
+ }
19
+
20
+ /**
21
+ * Formats an address according to [ERC55](https://eips.ethereum.org/EIPS/eip-55)
22
+ */
23
+ export function toChecksumAddress(address: string): string {
24
+ if (!isAddressValid(address)) {
25
+ throw Error(`Invalid address: ${address}`);
26
+ }
27
+
28
+ const rawAddress = (address.startsWith("0x") ? address.slice(2) : address).toLowerCase();
29
+ const chars = rawAddress.split("");
30
+
31
+ // Inspired by https://github.com/ethers-io/ethers.js/blob/cac1da1f912c2ae9ba20f25aa51a91766673cd76/src.ts/address/address.ts#L8
32
+ const expanded = new Uint8Array(chars.length);
33
+ for (let i = 0; i < expanded.length; i++) {
34
+ expanded[i] = rawAddress[i].charCodeAt(0);
35
+ }
36
+
37
+ const hashed = keccak256(expanded);
38
+ for (let i = 0; i < chars.length; i += 2) {
39
+ if (hashed[i >> 1] >> 4 >= 8) {
40
+ chars[i] = chars[i].toUpperCase();
41
+ }
42
+ if ((hashed[i >> 1] & 0x0f) >= 8) {
43
+ chars[i + 1] = chars[i + 1].toUpperCase();
44
+ }
45
+ }
46
+
47
+ return "0x" + chars.join("");
48
+ }