-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssz_schema.cue
More file actions
77 lines (62 loc) · 2.16 KB
/
ssz_schema.cue
File metadata and controls
77 lines (62 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package cuessz
import (
"list"
)
// SSZ uses 4-byte (uint32) length prefixes for variable-length types
#MaxSSZSize: 4294967296 // 2^32
// SSZType defines all valid SSZ type names
#SSZType: "uint8" | "uint16" | "uint32" | "uint64" | "uint128" | "uint256" | "boolean" |
"container" | "progressive_container" | "vector" | "list" |
"bitvector" | "bitlist" | "union" | "ref"
// Def represents an SSZ type definition
#Def: {
type: #SSZType
// Optional documentation for this type
description?: string
// this is the size for vectors and bitvectors (max uint32 due to 4-byte SSZ prefix)
if list.Contains(["vector", "bitvector"], type) {
size: uint & >0 & <=#MaxSSZSize
}
// this is the max length for lists and bitlists (max uint32 due to 4-byte SSZ prefix)
if list.Contains(["list", "bitlist"], type) {
limit: uint & >0 & <=#MaxSSZSize
}
// container, progressive_container, vector, list, union have children
if list.Contains(["container", "progressive_container", "union"], type) {
children: [...#Field]
} // NOTE: it would be great to have cue if-else semantics here...
// but for vector and list, it contains children, and it must be must be exactly length 1
if list.Contains(["vector", "list"], type) {
children: [...#Field] & list.MinItems(1) & list.MaxItems(1)
}
// ref types must provide a string ref
if type == "ref" {
ref: string
}
if type == "progressive_container" {
// Bitset indicating which merkle tree positions contain actual fields (0 = skip, 1 = field present)
// - Length can be up to 256
// - Count of 1s must equal number of children
// - Last element must be 1 if present (cannot end in 0)
active_fields: [...int]
}
}
// Field represents a named field within a container (used in children arrays)
#Field: {
name: string
def: #Def
description?: string // Optional documentation for this field
}
// Schema represents a collection of named type definitions
#Schema: {
// Schema version for compatibility tracking
version: string | *"1.0.0"
// type definitions (the actual business)
defs: {[string]: #Def}
// Optional metadata
metadata?: {
namespace?: string
description?: string
authors?: [...string]
}
}