Skip to content
Snippets Groups Projects
Commit 792fba01 authored by Jake Taylor's avatar Jake Taylor
Browse files

add some e2e.Handler bindings

parent 6599dbfd
No related branches found
No related tags found
1 merge request!510Release
...@@ -32,6 +32,7 @@ type E2e struct { ...@@ -32,6 +32,7 @@ type E2e struct {
id int id int
} }
// GetID returns the e2eTracker ID for the E2e object
func (e *E2e) GetID() int { func (e *E2e) GetID() int {
return e.id return e.id
} }
...@@ -64,6 +65,59 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error ...@@ -64,6 +65,59 @@ func LoginE2e(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error
return e2eTrackerSingleton.make(newE2e), nil return e2eTrackerSingleton.make(newE2e), nil
} }
// LoginE2eEphemeral creates and returns a new ephemeral E2e object and adds it to the e2eTrackerSingleton
// identity should be created via MakeIdentity() and passed in here
// If callbacks is left nil, a default auth.Callbacks will be used
func LoginE2eEphemeral(cmixId int, callbacks AuthCallbacks, identity []byte) (*E2e, error) {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return nil, err
}
newIdentity, err := unmarshalIdentity(identity, cmix.api.GetStorage().GetE2EGroup())
if err != nil {
return nil, err
}
var authCallbacks auth.Callbacks
if callbacks == nil {
authCallbacks = auth.DefaultAuthCallbacks{}
} else {
authCallbacks = &authCallback{bindingsCbs: callbacks}
}
newE2e, err := xxdk.LoginEphemeral(cmix.api, authCallbacks, newIdentity)
if err != nil {
return nil, err
}
return e2eTrackerSingleton.make(newE2e), nil
}
// LoginE2eLegacy creates a new E2e backed by the xxdk.Cmix persistent versioned.KV
// Uses the pre-generated transmission ID used by xxdk.Cmix
// If callbacks is left nil, a default auth.Callbacks will be used
// This function is designed to maintain backwards compatibility with previous xx messenger designs
// and should not be used for other purposes
func LoginE2eLegacy(cmixId int, callbacks AuthCallbacks) (*E2e, error) {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return nil, err
}
var authCallbacks auth.Callbacks
if callbacks == nil {
authCallbacks = auth.DefaultAuthCallbacks{}
} else {
authCallbacks = &authCallback{bindingsCbs: callbacks}
}
newE2e, err := xxdk.LoginLegacy(cmix.api, authCallbacks)
if err != nil {
return nil, err
}
return e2eTrackerSingleton.make(newE2e), nil
}
// GetContact returns a marshalled contact.Contact object for the E2e ReceptionIdentity // GetContact returns a marshalled contact.Contact object for the E2e ReceptionIdentity
func (e *E2e) GetContact() []byte { func (e *E2e) GetContact() []byte {
return e.api.GetReceptionIdentity().GetContact(e.api.GetStorage().GetE2EGroup()).Marshal() return e.api.GetReceptionIdentity().GetContact(e.api.GetStorage().GetE2EGroup()).Marshal()
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
package bindings package bindings
import ( import (
"gitlab.com/elixxir/client/auth"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
...@@ -216,15 +215,7 @@ func (e *E2e) AddPartnerCallback(partnerID []byte, cb AuthCallbacks) error { ...@@ -216,15 +215,7 @@ func (e *E2e) AddPartnerCallback(partnerID []byte, cb AuthCallbacks) error {
return err return err
} }
var authCallbacks auth.Callbacks e.api.GetAuth().AddPartnerCallback(partnerId, &authCallback{bindingsCbs: cb})
if cb == nil {
authCallbacks = auth.DefaultAuthCallbacks{}
} else {
authCallbacks = &authCallback{bindingsCbs: cb}
}
e.api.GetAuth().AddPartnerCallback(partnerId, authCallbacks)
return nil return nil
} }
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
package bindings
import (
"encoding/json"
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/xx_network/primitives/id"
)
// IdList is a wrapper for a list of marshalled id.ID objects
type IdList struct {
Ids [][]byte
}
// GetReceptionID returns the marshalled default IDs
func (e *E2e) GetReceptionID() []byte {
return e.api.GetE2E().GetReceptionID().Marshal()
}
// GetAllPartnerIDs returns a marshalled list of all partner IDs that the user has
// an E2E relationship with.
func (e *E2e) GetAllPartnerIDs() ([]byte, error) {
partnerIds := e.api.GetE2E().GetAllPartnerIDs()
convertedIds := make([][]byte, len(partnerIds))
for i, partnerId := range partnerIds {
convertedIds[i] = partnerId.Marshal()
}
return json.Marshal(IdList{Ids: convertedIds})
}
// PayloadSize Returns the max payload size for a partitionable E2E
// message
func (e *E2e) PayloadSize() int {
return int(e.api.GetE2E().PayloadSize())
}
// SecondPartitionSize returns the max partition payload size for all
// payloads after the first payload
func (e *E2e) SecondPartitionSize() int {
return int(e.api.GetE2E().SecondPartitionSize())
}
// PartitionSize returns the partition payload size for the given
// payload index. The first payload is index 0.
func (e *E2e) PartitionSize(payloadIndex int) int {
return int(e.api.GetE2E().PartitionSize(uint(payloadIndex)))
}
// FirstPartitionSize returns the max partition payload size for the
// first payload
func (e *E2e) FirstPartitionSize() int {
return int(e.api.GetE2E().FirstPartitionSize())
}
// GetHistoricalDHPrivkey returns the user's marshalled Historical DH Private Key
func (e *E2e) GetHistoricalDHPrivkey() ([]byte, error) {
return e.api.GetE2E().GetHistoricalDHPrivkey().MarshalJSON()
}
// GetHistoricalDHPubkey returns the user's marshalled Historical DH
// Public Key
func (e *E2e) GetHistoricalDHPubkey() ([]byte, error) {
return e.api.GetE2E().GetHistoricalDHPubkey().MarshalJSON()
}
// HasAuthenticatedChannel returns true if an authenticated channel with the
// partner exists, otherwise returns false
func (e *E2e) HasAuthenticatedChannel(partnerId []byte) (bool, error) {
partner, err := id.Unmarshal(partnerId)
if err != nil {
return false, err
}
return e.api.GetE2E().HasAuthenticatedChannel(partner), nil
}
// RemoveService removes all services for the given tag
func (e *E2e) RemoveService(tag string) error {
return e.api.GetE2E().RemoveService(tag)
}
// SendE2E send a message containing the payload to the
// recipient of the passed message type, per the given
// parameters - encrypted with end-to-end encryption.
// Default parameters can be retrieved through
func (e *E2e) SendE2E(messageType int, recipientId, payload,
e2eParams []byte) ([]byte, []byte, int64, error) {
params := e2e.GetDefaultParams()
err := params.UnmarshalJSON(e2eParams)
if err != nil {
return nil, nil, 0, err
}
recipient, err := id.Unmarshal(recipientId)
if err != nil {
return nil, nil, 0, err
}
roundIds, messageId, ts, err := e.api.GetE2E().SendE2E(catalog.MessageType(messageType), recipient, payload, params)
if err != nil {
return nil, nil, 0, err
}
convertedRids, err := json.Marshal(roundIds)
return convertedRids, messageId[:], ts.UnixNano(), err
}
...@@ -22,7 +22,7 @@ type Handler interface { ...@@ -22,7 +22,7 @@ type Handler interface {
// SendE2E send a message containing the payload to the // SendE2E send a message containing the payload to the
// recipient of the passed message type, per the given // recipient of the passed message type, per the given
// parameters - encrypted with end to end encryption. // parameters - encrypted with end-to-end encryption.
// Default parameters can be retrieved through // Default parameters can be retrieved through
// GetDefaultParams() // GetDefaultParams()
// If too long, it will chunk a message up into its messages // If too long, it will chunk a message up into its messages
...@@ -165,7 +165,7 @@ type Handler interface { ...@@ -165,7 +165,7 @@ type Handler interface {
/* === Utility ====================================================== */ /* === Utility ====================================================== */
// GetGroup returns the cyclic group used for end to end encruption // GetGroup returns the cyclic group used for end-to-end encryption
GetGroup() *cyclic.Group GetGroup() *cyclic.Group
// GetHistoricalDHPubkey returns the user's Historical DH // GetHistoricalDHPubkey returns the user's Historical DH
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment