From 9806179b5196821a30a6ec78a57fcb9897a4d022 Mon Sep 17 00:00:00 2001
From: Tigran Avakyan <tigran.avakyan@icloud.com>
Date: Wed, 15 May 2019 13:50:01 -0700
Subject: [PATCH] Changes to handle new primitives id interface

---
 bindings/client.go            | 10 +++++-----
 bots/bots.go                  |  2 +-
 bots/bots_test.go             |  2 +-
 bots/userDiscovery.go         |  2 +-
 cmd/root.go                   |  8 ++++----
 cmd/udb.go                    |  2 +-
 crypto/encryptdecrypt_test.go |  2 +-
 glide.yaml                    |  2 +-
 rekey/rekey_test.go           | 12 ++++++------
 user/session_test.go          |  4 ++--
 user/user.go                  |  6 +++---
 user/user_test.go             |  2 +-
 12 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/bindings/client.go b/bindings/client.go
index 28f4eabc2..72ade2fbf 100644
--- a/bindings/client.go
+++ b/bindings/client.go
@@ -70,7 +70,7 @@ type Listener interface {
 // If you pass the zero type (just zero) to Listen() you will hear messages of
 // all types.
 func (cl *Client) Listen(userId []byte, messageType int32, newListener Listener) string {
-	typedUserId := new(id.User).SetBytes(userId)
+	typedUserId := id.NewUserFromBytes(userId)
 
 	listener := &listenerProxy{proxy: newListener}
 
@@ -155,7 +155,7 @@ func (cl *Client) Register(preCan bool, registrationCode, nick,
 // This should only ever be used for testing purposes
 func (cl *Client) Login(UID []byte, email, addr string,
 	tlsCert string) (string, error) {
-	userID := new(id.User).SetBytes(UID)
+	userID := id.NewUserFromBytes(UID)
 	var err error
 	var nick string
 	if tlsCert == "default" {
@@ -170,8 +170,8 @@ func (cl *Client) Login(UID []byte, email, addr string,
 // Automatically serializes the message type before the rest of the payload
 // Returns an error if either sender or recipient are too short
 func (cl *Client) Send(m Message, encrypt bool) error {
-	sender := new(id.User).SetBytes(m.GetSender())
-	recipient := new(id.User).SetBytes(m.GetRecipient())
+	sender := id.NewUserFromBytes(m.GetSender())
+	recipient := id.NewUserFromBytes(m.GetRecipient())
 
 	var cryptoType format.CryptoType
 	if encrypt {
@@ -245,7 +245,7 @@ func (ncp *nickCallbackProxy) Callback(nick string, err error) {
 func (cl *Client) LookupNick(user []byte,
 	cb NickLookupCallback) {
 	proxy := &nickCallbackProxy{cb}
-	userID := new(id.User).SetBytes(user)
+	userID := id.NewUserFromBytes(user)
 	cl.client.LookupNick(userID, proxy)
 }
 
diff --git a/bots/bots.go b/bots/bots.go
index e7d54b895..4f241e4e2 100644
--- a/bots/bots.go
+++ b/bots/bots.go
@@ -49,7 +49,7 @@ var nicknameRequestListener nickReqListener
 
 // InitBots is called internally by the Login API
 func InitBots(s user.Session,m io.Communications) {
-	UdbID = new(id.User).SetUints(&[4]uint64{0, 0, 0, 3})
+	UdbID = id.NewUserFromUints(&[4]uint64{0, 0, 0, 3})
 
 	pushKeyResponseListener = make(channelResponseListener)
 	getKeyResponseListener = make(channelResponseListener)
diff --git a/bots/bots_test.go b/bots/bots_test.go
index beb10ab93..a39eae029 100644
--- a/bots/bots_test.go
+++ b/bots/bots_test.go
@@ -57,7 +57,7 @@ var pubKey []byte
 
 func TestMain(m *testing.M) {
 	u := &user.User{
-		User: new(id.User).SetUints(&[4]uint64{0, 0, 0, 18}),
+		User: id.NewUserFromUints(&[4]uint64{0, 0, 0, 18}),
 		Nick: "Bernie",
 	}
 	fakeSession := user.NewSession(&globals.RamStorage{},
diff --git a/bots/userDiscovery.go b/bots/userDiscovery.go
index c87475002..255ae73ab 100644
--- a/bots/userDiscovery.go
+++ b/bots/userDiscovery.go
@@ -112,7 +112,7 @@ func parseSearch(msg string) (*id.User, string) {
 	if err != nil {
 		return id.ZeroID, fmt.Sprintf("Couldn't parse search cMix UID: %s", msg)
 	}
-	cMixUID := new(id.User).SetBytes(cMixUIDBytes)
+	cMixUID := id.NewUserFromBytes(cMixUIDBytes)
 
 	return cMixUID, resParts[4]
 }
diff --git a/cmd/root.go b/cmd/root.go
index 762dba741..e96ea2587 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -141,7 +141,7 @@ func sessionInitialization() *id.User {
 		regCode := registrationCode
 		// If precanned user, use generated code instead
 		if userId != 0 {
-			regCode = new(id.User).SetUints(&[4]uint64{0, 0, 0, userId}).RegistrationCode()
+			regCode = id.NewUserFromUints(&[4]uint64{0, 0, 0, userId}).RegistrationCode()
 		}
 
 		globals.Log.INFO.Printf("Attempting to register with code %s...", regCode)
@@ -158,7 +158,7 @@ func sessionInitialization() *id.User {
 	} else {
 		// hack for session persisting with cmd line
 		// doesn't support non pre canned users
-		uid = new(id.User).SetUints(&[4]uint64{0, 0, 0, userId})
+		uid = id.NewUserFromUints(&[4]uint64{0, 0, 0, userId})
 		// clear userEmail if it was defined, since login was previously done
 		userEmail = ""
 	}
@@ -285,7 +285,7 @@ func (l *ChannelListener) Hear(item switchboard.Item, isHeardElsewhere bool) {
 	fmt.Printf("Message from channel %v, %v: ",
 		new(big.Int).SetBytes(message.Sender[:]).Text(10), senderNick)
 	typedBody, _ := parse.Parse(result.Message)
-	speakerId := new(id.User).SetBytes(result.SpeakerID)
+	speakerId := id.NewUserFromBytes(result.SpeakerID)
 	client.GetSwitchboard().Speak(&parse.Message{
 		TypedBody: *typedBody,
 		Sender:    speakerId,
@@ -345,7 +345,7 @@ var rootCmd = &cobra.Command{
 		}
 
 		// Only send a message if we have a message to send (except dummy messages)
-		recipientId := new(id.User).SetUints(&[4]uint64{0, 0, 0, destinationUserId})
+		recipientId := id.NewUserFromUints(&[4]uint64{0, 0, 0, destinationUserId})
 		if message != "" {
 			// Get the recipient's nick
 			recipientNick := ""
diff --git a/cmd/udb.go b/cmd/udb.go
index 8972fe892..9c04d1409 100644
--- a/cmd/udb.go
+++ b/cmd/udb.go
@@ -23,7 +23,7 @@ func (cs callbackSearch) Callback(userID, pubKey []byte, err error) {
 		fmt.Printf("Public Key returned is empty\n")
 	} else {
 		fmt.Printf("UDB search successful. Returned user %v\n",
-			*new(id.User).SetBytes(userID))
+			*id.NewUserFromBytes(userID))
 	}
 }
 
diff --git a/crypto/encryptdecrypt_test.go b/crypto/encryptdecrypt_test.go
index 253c7aac5..9476a225c 100644
--- a/crypto/encryptdecrypt_test.go
+++ b/crypto/encryptdecrypt_test.go
@@ -57,7 +57,7 @@ func setup() {
 
 	grp := cyclic.NewGroup(p, g, q)
 
-	UID := new(id.User).SetUints(&[4]uint64{0, 0, 0, 18})
+	UID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 18})
 	u, _ := user.Users.GetUser(UID)
 
 	nk := make([]user.NodeKeys, 5)
diff --git a/glide.yaml b/glide.yaml
index cd36fb8e9..f597c158b 100644
--- a/glide.yaml
+++ b/glide.yaml
@@ -4,7 +4,7 @@ import:
   version: master
   vcs: git
 - package: gitlab.com/elixxir/crypto
-  version: master
+  version: immutableUserNodeId-xx-1185
   repo: git@gitlab.com:elixxir/crypto
   vcs: git
 - package: gitlab.com/elixxir/comms
diff --git a/rekey/rekey_test.go b/rekey/rekey_test.go
index 77aeba9b8..2ad233dae 100644
--- a/rekey/rekey_test.go
+++ b/rekey/rekey_test.go
@@ -55,13 +55,13 @@ func TestMain(m *testing.M) {
 		grp.GetQ())
 	rng := csprng.NewSystemRNG()
 	u := &user.User{
-		User: new(id.User).SetUints(&[4]uint64{0, 0, 0, 18}),
+		User: id.NewUserFromUints(&[4]uint64{0, 0, 0, 18}),
 		Nick: "Bernie",
 	}
 	myPrivKey := params.PrivateKeyGen(rng)
 	myPrivKeyCyclic := grp.NewIntFromLargeInt(myPrivKey.GetKey())
 	myPubKey := myPrivKey.PublicKeyGen()
-	partnerID := new(id.User).SetUints(&[4]uint64{0, 0, 0, 12})
+	partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12})
 	partnerPrivKey := params.PrivateKeyGen(rng)
 	partnerPubKey := partnerPrivKey.PublicKeyGen()
 	partnerPubKeyCyclic := grp.NewIntFromLargeInt(partnerPubKey.GetKey())
@@ -114,7 +114,7 @@ func TestMain(m *testing.M) {
 
 // Test RekeyTrigger
 func TestRekeyTrigger(t *testing.T) {
-	partnerID := new(id.User).SetUints(&[4]uint64{0, 0, 0, 12})
+	partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12})
 	km := session.GetKeyStore().GetRecvManager(partnerID)
 	partnerPubKey := km.GetPubKey()
 	// Test receiving a RekeyTrigger message
@@ -168,7 +168,7 @@ func TestRekeyTrigger(t *testing.T) {
 
 // Test RekeyConfirm
 func TestRekeyConfirm(t *testing.T) {
-	partnerID := new(id.User).SetUints(&[4]uint64{0, 0, 0, 12})
+	partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12})
 	rekeyCtx := session.GetRekeyManager().GetCtx(partnerID)
 	baseKey := rekeyCtx.BaseKey
 	// Test receiving a RekeyConfirm message with wrong H(baseKey)
@@ -236,7 +236,7 @@ func TestRekeyConfirm(t *testing.T) {
 
 // Test Rekey
 func TestRekey(t *testing.T) {
-	partnerID := new(id.User).SetUints(&[4]uint64{0, 0, 0, 12})
+	partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12})
 	km := session.GetKeyStore().GetSendManager(partnerID)
 	// Generate new partner public key
 	grp := globals.InitCrypto()
@@ -296,7 +296,7 @@ func TestRekey(t *testing.T) {
 
 // Test Rekey errors
 func TestRekey_Errors(t *testing.T) {
-	partnerID := new(id.User).SetUints(&[4]uint64{0, 0, 0, 12})
+	partnerID := id.NewUserFromUints(&[4]uint64{0, 0, 0, 12})
 	km := session.GetKeyStore().GetRecvManager(partnerID)
 	partnerPubKey := km.GetPubKey()
 	// Delete RekeyKeys so that RekeyTrigger and rekey error out
diff --git a/user/session_test.go b/user/session_test.go
index b901767c9..23375add1 100644
--- a/user/session_test.go
+++ b/user/session_test.go
@@ -10,8 +10,8 @@ import (
 	"crypto/sha256"
 	"gitlab.com/elixxir/client/globals"
 	"gitlab.com/elixxir/crypto/cyclic"
-	"gitlab.com/elixxir/crypto/signature"
 	"gitlab.com/elixxir/crypto/large"
+	"gitlab.com/elixxir/crypto/signature"
 	"gitlab.com/elixxir/primitives/id"
 	"math/rand"
 	"reflect"
@@ -70,7 +70,7 @@ func TestUserSession(t *testing.T) {
 	} else {
 		pass++
 	}
-	
+
 	_, err = LoadSession(storage,
 		id.NewUserFromUint(10002, t))
 
diff --git a/user/user.go b/user/user.go
index a65640cb1..9b4da05e6 100644
--- a/user/user.go
+++ b/user/user.go
@@ -62,7 +62,7 @@ func newRegistry() Registry {
 	// Deterministically create NUM_DEMO_USERS users
 	// TODO Replace this with real user registration/discovery
 	for i := uint64(1); i <= NUM_DEMO_USERS; i++ {
-		currentID := new(id.User).SetUints(&[4]uint64{0, 0, 0, i})
+		currentID := id.NewUserFromUints(&[4]uint64{0, 0, 0, i})
 		t := new(User)
 		k := new(NodeKeys)
 
@@ -91,12 +91,12 @@ func newRegistry() Registry {
 
 	// Channels have been hardcoded to users starting with 31
 	for i := 0; i < len(DemoUserNicks); i++ {
-		currentID := new(id.User).SetUints(&[4]uint64{0, 0, 0, uint64(i) + 1})
+		currentID := id.NewUserFromUints(&[4]uint64{0, 0, 0, uint64(i) + 1})
 		uc[*currentID].Nick = DemoUserNicks[i]
 	}
 
 	for i := 0; i < len(DemoChannelNames); i++ {
-		currentID := new(id.User).SetUints(&[4]uint64{0, 0, 0, uint64(i) + 31})
+		currentID := id.NewUserFromUints(&[4]uint64{0, 0, 0, uint64(i) + 31})
 		uc[*currentID].Nick = DemoChannelNames[i]
 	}
 
diff --git a/user/user_test.go b/user/user_test.go
index 5ee814ba0..2bd573b94 100644
--- a/user/user_test.go
+++ b/user/user_test.go
@@ -15,7 +15,7 @@ import (
 )
 
 // InitGroup sets up the cryptographic constants for cMix
-func InitGroup() *cyclic.Group{
+func InitGroup() *cyclic.Group {
 
 	base := 16
 
-- 
GitLab