@@ -21,21 +21,60 @@ import (
2121 "embed"
2222 "errors"
2323 "hash"
24+ "reflect"
2425 "sync/atomic"
26+
27+ "github.com/XinFinOrg/XDPoSChain/common/hexutil"
2528)
2629
2730//go:embed trusted_setup.json
2831var content embed.FS
2932
33+ var (
34+ blobT = reflect .TypeOf (Blob {})
35+ commitmentT = reflect .TypeOf (Commitment {})
36+ proofT = reflect .TypeOf (Proof {})
37+ )
38+
3039// Blob represents a 4844 data blob.
3140type Blob [131072 ]byte
3241
42+ // UnmarshalJSON parses a blob in hex syntax.
43+ func (b * Blob ) UnmarshalJSON (input []byte ) error {
44+ return hexutil .UnmarshalFixedJSON (blobT , input , b [:])
45+ }
46+
47+ // MarshalText returns the hex representation of b.
48+ func (b Blob ) MarshalText () ([]byte , error ) {
49+ return hexutil .Bytes (b [:]).MarshalText ()
50+ }
51+
3352// Commitment is a serialized commitment to a polynomial.
3453type Commitment [48 ]byte
3554
55+ // UnmarshalJSON parses a commitment in hex syntax.
56+ func (c * Commitment ) UnmarshalJSON (input []byte ) error {
57+ return hexutil .UnmarshalFixedJSON (commitmentT , input , c [:])
58+ }
59+
60+ // MarshalText returns the hex representation of c.
61+ func (c Commitment ) MarshalText () ([]byte , error ) {
62+ return hexutil .Bytes (c [:]).MarshalText ()
63+ }
64+
3665// Proof is a serialized commitment to the quotient polynomial.
3766type Proof [48 ]byte
3867
68+ // UnmarshalJSON parses a proof in hex syntax.
69+ func (p * Proof ) UnmarshalJSON (input []byte ) error {
70+ return hexutil .UnmarshalFixedJSON (proofT , input , p [:])
71+ }
72+
73+ // MarshalText returns the hex representation of p.
74+ func (p Proof ) MarshalText () ([]byte , error ) {
75+ return hexutil .Bytes (p [:]).MarshalText ()
76+ }
77+
3978// Point is a BLS field element.
4079type Point [32 ]byte
4180
0 commit comments