@obolnetwork/obol-sdk 1.0.12 → 1.0.13
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.
- package/LICENCE +21 -0
- package/README.md +33 -3
- package/dist/cjs/package.json +128 -0
- package/dist/cjs/src/ajv.js +2 -1
- package/dist/cjs/src/base.js +2 -2
- package/dist/cjs/src/constants.js +38 -13
- package/dist/cjs/src/errors.js +1 -1
- package/dist/cjs/src/index.js +24 -21
- package/dist/cjs/src/schema.js +24 -36
- package/dist/cjs/src/services.js +2 -2
- package/dist/cjs/src/types.js +0 -1
- package/dist/cjs/src/utils.js +36 -1
- package/dist/cjs/src/{verify.js → verification/common.js} +128 -155
- package/dist/cjs/src/verification/sszTypes.js +69 -0
- package/dist/cjs/src/verification/v1.6.0.js +149 -0
- package/dist/cjs/src/verification/v1.7.0.js +173 -0
- package/dist/cjs/src/verification/v1.8.0.js +183 -0
- package/dist/cjs/test/fixtures.js +281 -63
- package/dist/cjs/test/methods.test.js +58 -35
- package/dist/esm/package.json +128 -0
- package/dist/esm/src/ajv.js +2 -1
- package/dist/esm/src/base.js +2 -2
- package/dist/esm/src/constants.js +14 -12
- package/dist/esm/src/errors.js +1 -1
- package/dist/esm/src/index.js +27 -24
- package/dist/esm/src/schema.js +24 -36
- package/dist/esm/src/services.js +1 -1
- package/dist/esm/src/types.js +0 -1
- package/dist/esm/src/utils.js +34 -0
- package/dist/esm/src/{verify.js → verification/common.js} +114 -146
- package/dist/esm/src/verification/sszTypes.js +64 -0
- package/dist/esm/src/verification/v1.6.0.js +142 -0
- package/dist/esm/src/verification/v1.7.0.js +166 -0
- package/dist/esm/src/verification/v1.8.0.js +176 -0
- package/dist/esm/test/fixtures.js +280 -62
- package/dist/esm/test/methods.test.js +59 -36
- package/dist/types/src/ajv.d.ts +1 -1
- package/dist/types/src/base.d.ts +3 -3
- package/dist/types/src/constants.d.ts +8 -10
- package/dist/types/src/index.d.ts +16 -16
- package/dist/types/src/services.d.ts +1 -1
- package/dist/types/src/types.d.ts +33 -27
- package/dist/types/src/utils.d.ts +3 -0
- package/dist/types/src/verification/common.d.ts +32 -0
- package/dist/types/src/verification/sszTypes.d.ts +63 -0
- package/dist/types/src/verification/v1.6.0.d.ts +34 -0
- package/dist/types/src/verification/v1.7.0.d.ts +34 -0
- package/dist/types/src/verification/v1.8.0.d.ts +35 -0
- package/dist/types/test/fixtures.d.ts +104 -2
- package/package.json +42 -8
- package/src/ajv.ts +15 -10
- package/src/base.ts +25 -21
- package/src/constants.ts +80 -78
- package/src/errors.ts +6 -9
- package/src/index.ts +118 -81
- package/src/schema.ts +24 -36
- package/src/services.ts +15 -13
- package/src/types.ts +72 -74
- package/src/utils.ts +53 -4
- package/src/verification/common.ts +420 -0
- package/src/verification/sszTypes.ts +79 -0
- package/src/verification/v1.6.0.ts +226 -0
- package/src/verification/v1.7.0.ts +274 -0
- package/src/verification/v1.8.0.ts +281 -0
- package/dist/cjs/src/hash.js +0 -172
- package/dist/esm/src/hash.js +0 -165
- package/dist/types/src/hash.d.ts +0 -56
- package/dist/types/src/verify.d.ts +0 -4
- package/src/hash.ts +0 -250
- package/src/verify.ts +0 -479
package/src/schema.ts
CHANGED
|
@@ -1,70 +1,58 @@
|
|
|
1
1
|
export const operatorPayloadSchema = {
|
|
2
|
-
type:
|
|
2
|
+
type: 'object',
|
|
3
3
|
properties: {
|
|
4
4
|
version: {
|
|
5
|
-
type:
|
|
5
|
+
type: 'string',
|
|
6
6
|
},
|
|
7
7
|
enr: {
|
|
8
|
-
type:
|
|
8
|
+
type: 'string',
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
|
-
required: [
|
|
12
|
-
"version",
|
|
13
|
-
"enr",
|
|
14
|
-
]
|
|
11
|
+
required: ['version', 'enr'],
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
export const definitionSchema = {
|
|
18
|
-
type:
|
|
15
|
+
type: 'object',
|
|
19
16
|
properties: {
|
|
20
17
|
name: {
|
|
21
|
-
type:
|
|
18
|
+
type: 'string',
|
|
22
19
|
},
|
|
23
20
|
operators: {
|
|
24
|
-
type:
|
|
21
|
+
type: 'array',
|
|
25
22
|
minItems: 4,
|
|
26
23
|
uniqueItems: true,
|
|
27
24
|
items: {
|
|
28
|
-
type:
|
|
25
|
+
type: 'object',
|
|
29
26
|
properties: {
|
|
30
27
|
address: {
|
|
31
|
-
type:
|
|
28
|
+
type: 'string',
|
|
32
29
|
minLength: 42,
|
|
33
|
-
maxLength: 42
|
|
34
|
-
}
|
|
30
|
+
maxLength: 42,
|
|
31
|
+
},
|
|
35
32
|
},
|
|
36
|
-
required: [
|
|
37
|
-
|
|
38
|
-
]
|
|
39
|
-
}
|
|
33
|
+
required: ['address'],
|
|
34
|
+
},
|
|
40
35
|
},
|
|
41
36
|
validators: {
|
|
42
|
-
type:
|
|
37
|
+
type: 'array',
|
|
43
38
|
minItems: 1,
|
|
44
39
|
items: {
|
|
45
|
-
type:
|
|
40
|
+
type: 'object',
|
|
46
41
|
properties: {
|
|
47
42
|
fee_recipient_address: {
|
|
48
|
-
type:
|
|
43
|
+
type: 'string',
|
|
49
44
|
minLength: 42,
|
|
50
|
-
maxLength: 42
|
|
45
|
+
maxLength: 42,
|
|
51
46
|
},
|
|
52
47
|
withdrawal_address: {
|
|
53
|
-
type:
|
|
48
|
+
type: 'string',
|
|
54
49
|
minLength: 42,
|
|
55
|
-
maxLength: 42
|
|
56
|
-
}
|
|
50
|
+
maxLength: 42,
|
|
51
|
+
},
|
|
57
52
|
},
|
|
58
|
-
required: [
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
}
|
|
53
|
+
required: ['fee_recipient_address', 'withdrawal_address'],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
64
56
|
},
|
|
65
|
-
required: [
|
|
66
|
-
"name",
|
|
67
|
-
"operators",
|
|
68
|
-
"validators"
|
|
69
|
-
]
|
|
57
|
+
required: ['name', 'operators', 'validators'],
|
|
70
58
|
}
|
package/src/services.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { ClusterLock } from
|
|
2
|
-
import { isValidClusterLock } from
|
|
1
|
+
import { type ClusterLock } from './types.js'
|
|
2
|
+
import { isValidClusterLock } from './verification/common.js'
|
|
3
3
|
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
5
|
* Verifies Cluster Lock's validity.
|
|
6
6
|
* @param lock - cluster lock
|
|
7
|
-
* @returns {Promise<{ result: boolean }> } boolean result to indicate if lock is valid
|
|
7
|
+
* @returns {Promise<{ result: boolean }> } boolean result to indicate if lock is valid
|
|
8
8
|
* @throws on missing keys or values.
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* An example of how to use validateClusterLock:
|
|
11
11
|
* [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
12
12
|
*/
|
|
13
|
-
export const validateClusterLock = async (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
export const validateClusterLock = async (
|
|
14
|
+
lock: ClusterLock,
|
|
15
|
+
): Promise<boolean> => {
|
|
16
|
+
try {
|
|
17
|
+
const isLockValid = await isValidClusterLock(lock)
|
|
18
|
+
return isLockValid
|
|
19
|
+
} catch (err: any) {
|
|
20
|
+
throw err
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,210 +2,208 @@
|
|
|
2
2
|
* Permitted ChainID's
|
|
3
3
|
*/
|
|
4
4
|
export enum FORK_MAPPING {
|
|
5
|
-
|
|
6
5
|
/** Mainnet. */
|
|
7
|
-
|
|
6
|
+
'0x00000000' = 1,
|
|
8
7
|
|
|
9
8
|
/** Goerli/Prater. */
|
|
10
|
-
|
|
9
|
+
'0x00001020' = 5,
|
|
11
10
|
|
|
12
11
|
/** Gnosis Chain. */
|
|
13
|
-
|
|
12
|
+
'0x00000064' = 100,
|
|
14
13
|
|
|
15
14
|
/** Holesky. */
|
|
16
|
-
|
|
15
|
+
'0x01017000' = 17000,
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Node operator data
|
|
21
20
|
*/
|
|
22
|
-
export
|
|
23
|
-
|
|
21
|
+
export interface ClusterOperator {
|
|
24
22
|
/** The operator address. */
|
|
25
|
-
address: string
|
|
23
|
+
address: string
|
|
26
24
|
|
|
27
25
|
/** The operator ethereum node record. */
|
|
28
|
-
enr?: string
|
|
26
|
+
enr?: string
|
|
29
27
|
|
|
30
28
|
/** The cluster fork_version. */
|
|
31
|
-
fork_version?: string
|
|
29
|
+
fork_version?: string
|
|
32
30
|
|
|
33
31
|
/** The cluster version. */
|
|
34
|
-
version?: string
|
|
32
|
+
version?: string
|
|
35
33
|
|
|
36
34
|
/** The operator enr signature. */
|
|
37
|
-
enr_signature?: string
|
|
35
|
+
enr_signature?: string
|
|
38
36
|
|
|
39
37
|
/** The operator configuration signature. */
|
|
40
|
-
config_signature?: string
|
|
38
|
+
config_signature?: string
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
/**
|
|
44
42
|
* A partial view of `ClusterOperator` with `enr` and `version` as required properties.
|
|
45
43
|
*/
|
|
46
|
-
export type OperatorPayload =
|
|
44
|
+
export type OperatorPayload = Partial<ClusterOperator> &
|
|
45
|
+
Required<Pick<ClusterOperator, 'enr' | 'version'>>
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Cluster creator data
|
|
50
49
|
*/
|
|
51
|
-
export
|
|
52
|
-
|
|
50
|
+
export interface ClusterCreator {
|
|
53
51
|
/** The creator address. */
|
|
54
|
-
address: string
|
|
52
|
+
address: string
|
|
55
53
|
/** The cluster configuration signature. */
|
|
56
|
-
config_signature?: string
|
|
54
|
+
config_signature?: string
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* Validator withdrawal configuration
|
|
61
59
|
*/
|
|
62
|
-
export
|
|
63
|
-
|
|
60
|
+
export interface ClusterValidator {
|
|
64
61
|
/** The validator fee recipient address. */
|
|
65
|
-
fee_recipient_address: string
|
|
62
|
+
fee_recipient_address: string
|
|
66
63
|
|
|
67
64
|
/** The validator reward address. */
|
|
68
|
-
withdrawal_address: string
|
|
65
|
+
withdrawal_address: string
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
/**
|
|
72
69
|
* Cluster configuration
|
|
73
70
|
*/
|
|
74
|
-
export
|
|
75
|
-
|
|
71
|
+
export interface ClusterPayload {
|
|
76
72
|
/** The cluster name. */
|
|
77
|
-
name: string
|
|
73
|
+
name: string
|
|
78
74
|
|
|
79
75
|
/** The cluster nodes operators addresses. */
|
|
80
|
-
operators: ClusterOperator[]
|
|
76
|
+
operators: ClusterOperator[]
|
|
81
77
|
|
|
82
|
-
/** The
|
|
83
|
-
validators: ClusterValidator[]
|
|
84
|
-
|
|
78
|
+
/** The cluster validators information. */
|
|
79
|
+
validators: ClusterValidator[]
|
|
80
|
+
|
|
81
|
+
/** The cluster partial deposits in gwei or 32000000000. */
|
|
82
|
+
deposit_amounts?: string[]
|
|
83
|
+
}
|
|
85
84
|
|
|
86
85
|
/**
|
|
87
86
|
* Cluster definition data needed for dkg
|
|
88
87
|
*/
|
|
89
88
|
export interface ClusterDefintion extends ClusterPayload {
|
|
90
|
-
|
|
91
89
|
/** The creator of the cluster. */
|
|
92
|
-
creator: ClusterCreator
|
|
90
|
+
creator: ClusterCreator
|
|
93
91
|
|
|
94
92
|
/** The cluster configuration version. */
|
|
95
|
-
version: string
|
|
93
|
+
version: string
|
|
96
94
|
|
|
97
95
|
/** The cluster dkg algorithm. */
|
|
98
|
-
dkg_algorithm: string
|
|
96
|
+
dkg_algorithm: string
|
|
99
97
|
|
|
100
98
|
/** The cluster fork version. */
|
|
101
|
-
fork_version: string
|
|
99
|
+
fork_version: string
|
|
102
100
|
|
|
103
101
|
/** The cluster uuid. */
|
|
104
|
-
uuid: string
|
|
102
|
+
uuid: string
|
|
105
103
|
|
|
106
104
|
/** The cluster creation timestamp. */
|
|
107
|
-
timestamp: string
|
|
105
|
+
timestamp: string
|
|
108
106
|
|
|
109
107
|
/** The cluster configuration hash. */
|
|
110
|
-
config_hash: string
|
|
108
|
+
config_hash: string
|
|
111
109
|
|
|
112
110
|
/** The distributed validator threshold. */
|
|
113
|
-
threshold: number
|
|
111
|
+
threshold: number
|
|
114
112
|
|
|
115
113
|
/** The number of distributed validators in the cluster. */
|
|
116
|
-
num_validators: number
|
|
114
|
+
num_validators: number
|
|
115
|
+
|
|
116
|
+
/** The cluster partial deposits in gwei or 32000000000. */
|
|
117
|
+
deposit_amounts?: string[]
|
|
117
118
|
|
|
118
119
|
/** The hash of the cluster definition. */
|
|
119
|
-
definition_hash?: string
|
|
120
|
-
}
|
|
120
|
+
definition_hash?: string
|
|
121
|
+
}
|
|
121
122
|
|
|
122
123
|
/**
|
|
123
124
|
* Unsigned DV Builder Registration Message
|
|
124
125
|
*/
|
|
125
|
-
export
|
|
126
|
-
|
|
126
|
+
export interface BuilderRegistrationMessage {
|
|
127
127
|
/** The DV fee recipient. */
|
|
128
|
-
fee_recipient: string
|
|
128
|
+
fee_recipient: string
|
|
129
129
|
|
|
130
130
|
/** Default is 30000000. */
|
|
131
|
-
gas_limit: number
|
|
131
|
+
gas_limit: number
|
|
132
132
|
|
|
133
133
|
/** Timestamp when generating cluster lock file. */
|
|
134
|
-
timestamp: number
|
|
134
|
+
timestamp: number
|
|
135
135
|
|
|
136
136
|
/** The public key of the DV. */
|
|
137
|
-
pubkey: string
|
|
137
|
+
pubkey: string
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Pre-generated Signed Validator Builder Registration
|
|
142
142
|
*/
|
|
143
|
-
export
|
|
144
|
-
|
|
143
|
+
export interface BuilderRegistration {
|
|
145
144
|
/** Builder registration message. */
|
|
146
|
-
message: BuilderRegistrationMessage
|
|
145
|
+
message: BuilderRegistrationMessage
|
|
147
146
|
|
|
148
147
|
/** BLS signature of the builder registration message. */
|
|
149
|
-
signature: string
|
|
148
|
+
signature: string
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
/**
|
|
153
152
|
* Required deposit data for validator activation
|
|
154
153
|
*/
|
|
155
|
-
export
|
|
156
|
-
|
|
154
|
+
export interface DepositData {
|
|
157
155
|
/** The public key of the distributed validator. */
|
|
158
|
-
pubkey: string
|
|
156
|
+
pubkey: string
|
|
159
157
|
|
|
160
158
|
/** The 0x01 withdrawal address of the DV. */
|
|
161
|
-
withdrawal_credentials: string
|
|
159
|
+
withdrawal_credentials: string
|
|
162
160
|
|
|
163
161
|
/** 32 ethers. */
|
|
164
|
-
amount: string
|
|
162
|
+
amount: string
|
|
165
163
|
|
|
166
164
|
/** A checksum for DepositData fields . */
|
|
167
|
-
deposit_data_root: string
|
|
165
|
+
deposit_data_root: string
|
|
168
166
|
|
|
169
167
|
/** BLS signature of the deposit message. */
|
|
170
|
-
signature: string
|
|
168
|
+
signature: string
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
/**
|
|
174
172
|
* Required deposit data for validator activation
|
|
175
173
|
*/
|
|
176
|
-
export
|
|
177
|
-
|
|
174
|
+
export interface DistributedValidator {
|
|
178
175
|
/** The public key of the distributed validator. */
|
|
179
|
-
distributed_public_key: string
|
|
176
|
+
distributed_public_key: string
|
|
180
177
|
|
|
181
178
|
/** The public key of the node distributed validator share. */
|
|
182
|
-
public_shares: string[]
|
|
179
|
+
public_shares: string[]
|
|
180
|
+
|
|
181
|
+
/** The deposit data for activating the DV. */
|
|
182
|
+
deposit_data?: Partial<DepositData>
|
|
183
183
|
|
|
184
|
-
/** The
|
|
185
|
-
|
|
184
|
+
/** The deposit data with partial amounts or full amount for activating the DV. */
|
|
185
|
+
partial_deposit_data?: Array<Partial<DepositData>>
|
|
186
186
|
|
|
187
187
|
/** pre-generated signed validator builder registration to be sent to builder network. */
|
|
188
|
-
builder_registration
|
|
188
|
+
builder_registration?: BuilderRegistration
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
192
|
* Cluster Details after DKG is complete
|
|
193
193
|
*/
|
|
194
|
-
export
|
|
195
|
-
|
|
194
|
+
export interface ClusterLock {
|
|
196
195
|
/** The cluster definition. */
|
|
197
|
-
cluster_definition: ClusterDefintion
|
|
196
|
+
cluster_definition: ClusterDefintion
|
|
198
197
|
|
|
199
198
|
/** The cluster distributed validators. */
|
|
200
|
-
distributed_validators: DistributedValidator[]
|
|
199
|
+
distributed_validators: DistributedValidator[]
|
|
201
200
|
|
|
202
201
|
/** The cluster bls signature aggregate. */
|
|
203
|
-
signature_aggregate: string
|
|
202
|
+
signature_aggregate: string
|
|
204
203
|
|
|
205
204
|
/** The hash of the cluster lock. */
|
|
206
|
-
lock_hash: string
|
|
205
|
+
lock_hash: string
|
|
207
206
|
|
|
208
207
|
/** Node Signature for the lock hash by the node secp256k1 key. */
|
|
209
|
-
node_signatures
|
|
210
|
-
}
|
|
211
|
-
|
|
208
|
+
node_signatures?: string[]
|
|
209
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,56 @@
|
|
|
1
|
+
import { DefinitionFlow } from './constants'
|
|
2
|
+
import { type ClusterDefintion } from './types'
|
|
3
|
+
|
|
1
4
|
export const hexWithout0x = (hex: string): string => {
|
|
2
|
-
|
|
3
|
-
}
|
|
5
|
+
return hex.slice(2, hex.length)
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
export const strToUint8Array = (str: string): Uint8Array => {
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
return new TextEncoder().encode(str)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const definitionFlow = (
|
|
13
|
+
clusterDefinition: ClusterDefintion,
|
|
14
|
+
): DefinitionFlow | null => {
|
|
15
|
+
if (
|
|
16
|
+
clusterDefinition.creator.address &&
|
|
17
|
+
clusterDefinition.creator.config_signature &&
|
|
18
|
+
clusterDefinition.operators.every((operator) => {
|
|
19
|
+
return (
|
|
20
|
+
operator.address &&
|
|
21
|
+
operator.config_signature &&
|
|
22
|
+
operator.enr &&
|
|
23
|
+
operator.enr_signature
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
) {
|
|
27
|
+
return DefinitionFlow.Group
|
|
28
|
+
} else if (
|
|
29
|
+
clusterDefinition.creator.address &&
|
|
30
|
+
clusterDefinition.creator.config_signature &&
|
|
31
|
+
clusterDefinition.operators.every((operator) => {
|
|
32
|
+
return (
|
|
33
|
+
!operator.address &&
|
|
34
|
+
!operator.config_signature &&
|
|
35
|
+
operator.enr &&
|
|
36
|
+
!operator.enr_signature
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
) {
|
|
40
|
+
return DefinitionFlow.Solo
|
|
41
|
+
} else if (
|
|
42
|
+
!clusterDefinition.creator.address &&
|
|
43
|
+
!clusterDefinition.creator.config_signature &&
|
|
44
|
+
clusterDefinition.operators.every((operator) => {
|
|
45
|
+
return (
|
|
46
|
+
!operator.address &&
|
|
47
|
+
!operator.config_signature &&
|
|
48
|
+
operator.enr &&
|
|
49
|
+
!operator.enr_signature
|
|
50
|
+
)
|
|
51
|
+
})
|
|
52
|
+
) {
|
|
53
|
+
return DefinitionFlow.Charon
|
|
54
|
+
}
|
|
55
|
+
return null
|
|
56
|
+
}
|