Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
792fba01
Commit
792fba01
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
add some e2e.Handler bindings
parent
6599dbfd
No related branches found
No related tags found
1 merge request
!510
Release
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
bindings/e2e.go
+54
-0
54 additions, 0 deletions
bindings/e2e.go
bindings/e2eAuth.go
+1
-10
1 addition, 10 deletions
bindings/e2eAuth.go
bindings/e2eHandler.go
+111
-0
111 additions, 0 deletions
bindings/e2eHandler.go
e2e/interface.go
+2
-2
2 additions, 2 deletions
e2e/interface.go
with
168 additions
and
12 deletions
bindings/e2e.go
+
54
−
0
View file @
792fba01
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
bindings/e2eAuth.go
+
1
−
10
View file @
792fba01
...
@@ -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
}
}
...
...
This diff is collapsed.
Click to expand it.
bindings/e2eHandler.go
0 → 100644
+
111
−
0
View file @
792fba01
////////////////////////////////////////////////////////////////////////////////
// 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
}
This diff is collapsed.
Click to expand it.
e2e/interface.go
+
2
−
2
View file @
792fba01
...
@@ -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 encr
u
ption
// GetGroup returns the cyclic group used for end
-
to
-
end encr
y
ption
GetGroup
()
*
cyclic
.
Group
GetGroup
()
*
cyclic
.
Group
// GetHistoricalDHPubkey returns the user's Historical DH
// GetHistoricalDHPubkey returns the user's Historical DH
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment