Skip to content
Snippets Groups Projects
Select Git revision
  • 0f3adb84d3d78a1aa1e805c06a7c83221453341b
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

params.go

Blame
  • proto.go 2.33 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 Privategrity Corporation                                   /
    //                                                                             /
    // All rights reserved.                                                        /
    ////////////////////////////////////////////////////////////////////////////////
    
    package cmd
    
    import (
    	"encoding/json"
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"github.com/spf13/viper"
    	"gitlab.com/elixxir/client/storage/user"
    	"gitlab.com/elixxir/client/xxdk"
    	"gitlab.com/xx_network/primitives/utils"
    	"io/fs"
    	"io/ioutil"
    	"os"
    )
    
    // loadOrInitProto will build a new xxdk.E2e from existing storage
    // or from a new storage that it will create if none already exists
    func loadOrInitProto(protoUserPath string, password []byte, storeDir string,
    	cmixParams xxdk.CMIXParams, e2eParams xxdk.E2EParams) *xxdk.E2e {
    
    	// create a new client if none exist
    	var baseClient *xxdk.Cmix
    	var identity xxdk.ReceptionIdentity
    	if _, err := os.Stat(storeDir); errors.Is(err, fs.ErrNotExist) {
    		// Initialize from scratch
    		ndfJson, err := ioutil.ReadFile(viper.GetString("ndf"))
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    
    		protoUserJson, err := utils.ReadFile(protoUserPath)
    		if err != nil {
    			jww.FATAL.Panicf("%v", err)
    		}
    
    		protoUser := &user.Proto{}
    		err = json.Unmarshal(protoUserJson, protoUser)
    		if err != nil {
    			jww.FATAL.Panicf("%v", err)
    		}
    
    		// TODO: Separate identity from this call
    		identity, err = xxdk.NewProtoClient_Unsafe(string(ndfJson), storeDir,
    			password, protoUser)
    		baseClient, err = xxdk.LoadCmix(storeDir, password, cmixParams)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    
    		err = xxdk.StoreReceptionIdentity(identityStorageKey, identity, baseClient)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    	} else {
    		// Initialize from storage
    		baseClient, err = xxdk.LoadCmix(storeDir, password, cmixParams)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    		identity, err = xxdk.LoadReceptionIdentity(identityStorageKey, baseClient)
    		if err != nil {
    			jww.FATAL.Panicf("%+v", err)
    		}
    	}
    
    	jww.INFO.Printf("Using Login for proto sender")
    	client, err := xxdk.Login(baseClient, authCbs, identity, e2eParams)
    	if err != nil {
    		jww.FATAL.Panicf("%+v", err)
    	}
    	return client
    }