I am prototyping a TUI app that will run your protocol over libp2p with nice UX. So far so good! But I need to save the Config for future use in signing, so I'm trying to marshal it with cbor (I also tried JSON but that didnt work either). I am new to Go, so may be missing something obvious, but here is a failing test that shows what I'm attempting...
// Add this test to keygen_test.go and run it
func TestMarshallConfig(t *testing.T) {
pl := pool.NewPool(0)
defer pl.TearDown()
group := curve.Secp256k1{}
N := 2
T := N - 1
configs := FakeData(group, N, T, mrand.New(mrand.NewSource(1)), pl)
// Grab one config
var cfg *Config
for _, v := range configs {
cfg = v
}
b, err := cbor.Marshal(cfg)
if err != nil {
t.Fatalf("encode: %v", err)
}
t.Logf("%+v", hex.EncodeToString(b))
// Paste hex into http://cbor.me/ for diagnostic view
// Unmarshal into this empty Config doesnt work
// rehydratedConfig := &Config{}
// Trying to figure out the sturcture necessary to get Unmarshal to work...
// Stuck at this error -- decode: cbor: cannot unmarshal byte string into Go struct field keygen.Config.Public of type curve.Point
// Do you have to use cbor.NewTagSet() or something?
rehydratedConfig := &Config{Group: curve.Secp256k1{}, ECDSA: curve.Secp256k1{}.NewScalar()}
err = cbor.Unmarshal(b, rehydratedConfig)
if err != nil {
t.Fatalf("decode: %v", err)
}
t.Logf("rehydratedConfig: %+v", rehydratedConfig)
}
I am prototyping a TUI app that will run your protocol over libp2p with nice UX. So far so good! But I need to save the Config for future use in signing, so I'm trying to marshal it with
cbor
(I also tried JSON but that didnt work either). I am new to Go, so may be missing something obvious, but here is a failing test that shows what I'm attempting...