From 465e9fabfd65adb02bdead0d5d201e6d71bbdc6e Mon Sep 17 00:00:00 2001
From: Jake Taylor <jake@elixxir.io>
Date: Thu, 16 Jun 2022 15:56:14 -0500
Subject: [PATCH] added default authcallbacks

---
 auth/{partnerCallbacks.go => callbacks.go} | 26 +++++++++++++++++++++
 bindings/e2e.go                            | 27 ++++++++++++++--------
 2 files changed, 44 insertions(+), 9 deletions(-)
 rename auth/{partnerCallbacks.go => callbacks.go} (56%)

diff --git a/auth/partnerCallbacks.go b/auth/callbacks.go
similarity index 56%
rename from auth/partnerCallbacks.go
rename to auth/callbacks.go
index 79264cf16..781164bb8 100644
--- a/auth/partnerCallbacks.go
+++ b/auth/callbacks.go
@@ -7,6 +7,10 @@
 package auth
 
 import (
+	jww "github.com/spf13/jwalterweatherman"
+	"gitlab.com/elixxir/client/cmix/identity/receptionID"
+	"gitlab.com/elixxir/client/cmix/rounds"
+	"gitlab.com/elixxir/crypto/contact"
 	"gitlab.com/xx_network/primitives/id"
 	"sync"
 )
@@ -40,3 +44,25 @@ func (p *partnerCallbacks) DeletePartnerCallback(partnerId *id.ID) {
 func (p *partnerCallbacks) getPartnerCallback(partnerId *id.ID) Callbacks {
 	return p.callbacks[*partnerId]
 }
+
+// DefaultAuthCallbacks is a simple structure for providing a default Callbacks implementation
+// It should generally not be used.
+type DefaultAuthCallbacks struct{}
+
+// Confirm will be called when an auth Confirm message is processed.
+func (a DefaultAuthCallbacks) Confirm(requestor contact.Contact,
+	receptionID receptionID.EphemeralIdentity, round rounds.Round) {
+	jww.ERROR.Printf("No valid auth callback assigned!")
+}
+
+// Request will be called when an auth Request message is processed.
+func (a DefaultAuthCallbacks) Request(requestor contact.Contact,
+	receptionID receptionID.EphemeralIdentity, round rounds.Round) {
+	jww.ERROR.Printf("No valid auth callback assigned!")
+}
+
+// Reset will be called when an auth Reset operation occurs.
+func (a DefaultAuthCallbacks) Reset(requestor contact.Contact,
+	receptionID receptionID.EphemeralIdentity, round rounds.Round) {
+	jww.ERROR.Printf("No valid auth callback assigned!")
+}
diff --git a/bindings/e2e.go b/bindings/e2e.go
index c16162694..9c50ef820 100644
--- a/bindings/e2e.go
+++ b/bindings/e2e.go
@@ -7,6 +7,7 @@
 package bindings
 
 import (
+	"gitlab.com/elixxir/client/auth"
 	"gitlab.com/elixxir/client/cmix/identity/receptionID"
 	"gitlab.com/elixxir/client/cmix/rounds"
 	"gitlab.com/elixxir/client/xxdk"
@@ -27,10 +28,9 @@ type E2e struct {
 	id  int
 }
 
-// Login creates and returns a new E2e object
-// and adds it to the e2eTrackerSingleton
-// identity can be left nil such that a new
-// TransmissionIdentity will be created automatically
+// Login creates and returns a new E2e object and adds it to the e2eTrackerSingleton
+// identity can be left nil such that a new TransmissionIdentity will be created automatically
+// callbacks can be left nil and a default will be used
 func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) {
 	cmix, err := cmixTrackerSingleton.get(cmixId)
 	if err != nil {
@@ -47,12 +47,21 @@ func (e *E2e) Login(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e,
 		}
 	}
 
-	authCallbacks := authCallback{bindingsCbs: callbacks}
-	newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity)
-	if err != nil {
-		return nil, err
+	if callbacks == nil {
+		authCallbacks := auth.DefaultAuthCallbacks{}
+		newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity)
+		if err != nil {
+			return nil, err
+		}
+		return e2eTrackerSingleton.make(newE2e), nil
+	} else {
+		authCallbacks := authCallback{bindingsCbs: callbacks}
+		newE2e, err := xxdk.Login(cmix.api, authCallbacks, newIdentity)
+		if err != nil {
+			return nil, err
+		}
+		return e2eTrackerSingleton.make(newE2e), nil
 	}
-	return e2eTrackerSingleton.make(newE2e), nil
 }
 
 // AuthCallbacks is the bindings-specific interface for auth.Callbacks methods.
-- 
GitLab