diff --git a/bindings/client.go b/bindings/client.go index 0fa0b1c4dbcc1dd859609605118fc06de7b8645a..cf1dce64e5b8ec597306cfb713ee3c4f56d61d63 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -14,6 +14,7 @@ import ( "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/crypto/certs" "gitlab.com/elixxir/crypto/cyclic" + "gitlab.com/elixxir/crypto/large" "gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" @@ -146,12 +147,19 @@ func InitClient(storage Storage, loc string) error { // “Jono” // OIF3OJ5I func Register(registrationCode string, gwAddr string, numNodes int, - mint bool, grp *cyclic.Group) ([]byte, error) { + mint bool, grpJSON string) ([]byte, error) { if numNodes < 1 { return id.ZeroID[:], errors.New("invalid number of nodes") } + // Unmarshal group JSON + grp := cyclic.NewGroup(large.NewMaxInt(), large.NewMaxInt(), large.NewMaxInt()) + err := grp.UnmarshalJSON([]byte(grpJSON)) + if err != nil { + return id.ZeroID[:], err + } + UID, err := api.Register(registrationCode, gwAddr, uint(numNodes), mint, grp) if err != nil { diff --git a/bindings/client_test.go b/bindings/client_test.go index d279940165883a14968e910139667d60287705e8..341d38802c72c20b20bb0416b84d408002835741 100644 --- a/bindings/client_test.go +++ b/bindings/client_test.go @@ -147,8 +147,12 @@ func TestRegister(t *testing.T) { g := large.NewInt(2) q := large.NewInt(3) grp := cyclic.NewGroup(p, g, q) + grpJSON, err := grp.MarshalJSON() + if err != nil { + t.Errorf("Failed to marshal group JSON: %s", err) + } - regRes, err := Register(registrationCode, gwAddress, 1, false, grp) + regRes, err := Register(registrationCode, gwAddress, 1, false, string(grpJSON)) if err != nil { t.Errorf("Registration failed: %s", err.Error()) } @@ -170,8 +174,12 @@ func TestRegisterBadNumNodes(t *testing.T) { g := large.NewInt(int64(2)) q := large.NewInt(int64(3)) grp := cyclic.NewGroup(p, g, q) + grpJSON, err := grp.MarshalJSON() + if err != nil { + t.Errorf("Failed to marshal group JSON: %s", err) + } - _, err = Register(registrationCode, gwAddress, 0, false, grp) + _, err = Register(registrationCode, gwAddress, 0, false, string(grpJSON)) if err == nil { t.Errorf("Registration worked with bad numnodes! %s", err.Error()) } @@ -202,8 +210,12 @@ func TestLoginLogout(t *testing.T) { g := large.NewInt(2) q := large.NewInt(3) grp := cyclic.NewGroup(p, g, q) + grpJSON, err := grp.MarshalJSON() + if err != nil { + t.Errorf("Failed to marshal group JSON: %s", err) + } - regRes, err := Register(registrationCode, gwAddress, 1, false, grp) + regRes, err := Register(registrationCode, gwAddress, 1, false, string(grpJSON)) loginRes, err2 := Login(regRes, gwAddress, "") if err2 != nil { t.Errorf("Login failed: %s", err.Error()) @@ -216,6 +228,7 @@ func TestLoginLogout(t *testing.T) { if err3 != nil { t.Errorf("Logoutfailed: %s", err.Error()) } + globals.LocalStorage = nil } diff --git a/cmd/root.go b/cmd/root.go index 0fe6b3d0be728c6663b379c2ee829ab1688ccadf..09f44335bb81becb9ccf36a67516a82aa1822fb1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,7 +22,6 @@ import ( "gitlab.com/elixxir/client/parse" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/comms/connect" - "gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/primitives/format" "gitlab.com/elixxir/primitives/id" "gitlab.com/elixxir/primitives/switchboard" @@ -122,16 +121,10 @@ func sessionInitialization() { // FIXME Use a different encoding for the user ID command line argument, // to allow testing with IDs that are long enough to exercise more than // 64 bits - grp := cyclic.Group{} - grpBuff := []byte(viper.GetString("group")) - err := grp.UnmarshalJSON(grpBuff) - if err != nil { - fmt.Printf("Could Not Decode group from JSON: %s\n", err.Error()) - return - } + grpJSON := viper.GetString("group") regCode := new(id.User).SetUints(&[4]uint64{0, 0, 0, userId}).RegistrationCode() - _, err = bindings.Register(regCode, gwAddr, int(numNodes), mint, &grp) + _, err = bindings.Register(regCode, gwAddr, int(numNodes), mint, grpJSON) if err != nil { fmt.Printf("Could Not Register User: %s\n", err.Error()) return