@@ -37,6 +37,49 @@ pub fn g1_to_json(p: &G1) -> G1Json {
3737 }
3838}
3939
40+ pub fn g1_from_json( p : & G1Json ) -> Result < G1 , String > {
41+ let x = Fq :: from_str ( & p. x ) . map_err ( |_| format ! ( "Invalid x: {}" , p. x) ) ?;
42+ let y = Fq :: from_str ( & p. y ) . map_err ( |_| format ! ( "Invalid y: {}" , p. y) ) ?;
43+ Ok ( G1 :: new_unchecked ( x, y) )
44+ #![ allow( non_snake_case, dead_code) ]
45+
46+ use ark_bn254:: { Fq , Fq2 , Fr as Scalar , G1Affine as G1 , G2Affine as G2 } ;
47+ use bbs:: structs:: { Messages , Params , PrivateKey , PublicKey , Signature } ;
48+ use serde:: { Deserialize , Serialize } ;
49+ use std:: str:: FromStr ;
50+
51+ pub fn set_panic_hook ( ) {
52+ // When the `console_error_panic_hook` feature is enabled, we can call the
53+ // `set_panic_hook` function at least once during initialization, and then
54+ // we will get better error messages if our code ever panics.
55+ console_error_panic_hook:: set_once ( ) ;
56+ }
57+
58+ #[ derive( Serialize , Deserialize ) ]
59+ pub struct G1Json {
60+ pub x : String ,
61+ pub y : String ,
62+ }
63+
64+ #[ derive( Serialize , Deserialize ) ]
65+ pub struct Fq2Json {
66+ pub c0 : String ,
67+ pub c1 : String ,
68+ }
69+
70+ #[ derive( Serialize , Deserialize ) ]
71+ pub struct G2Json {
72+ pub x : Fq2Json ,
73+ pub y : Fq2Json ,
74+ }
75+
76+ pub fn g1_to_json ( p : & G1 ) -> G1Json {
77+ G1Json {
78+ x : p. x . to_string ( ) ,
79+ y : p. y . to_string ( ) ,
80+ }
81+ }
82+
4083pub fn g1_from_json ( p : & G1Json ) -> Result < G1 , String > {
4184 let x = Fq :: from_str ( & p. x ) . map_err ( |_| format ! ( "Invalid x: {}" , p. x) ) ?;
4285 let y = Fq :: from_str ( & p. y ) . map_err ( |_| format ! ( "Invalid y: {}" , p. y) ) ?;
0 commit comments