github.com/status-im/status-go@v1.1.0/protocol/datasync/utils.go (about)

     1  package datasync
     2  
     3  import (
     4  	"crypto/ecdsa"
     5  
     6  	"github.com/status-im/mvds/state"
     7  
     8  	"github.com/status-im/status-go/eth-node/crypto"
     9  )
    10  
    11  func ToGroupID(data []byte) state.GroupID {
    12  	g := state.GroupID{}
    13  	copy(g[:], data[:])
    14  	return g
    15  }
    16  
    17  // ToOneToOneGroupID returns a groupID for a onetoonechat, which is taken by
    18  // concatenating the bytes of the compressed keys, in ascending order by X
    19  func ToOneToOneGroupID(key1 *ecdsa.PublicKey, key2 *ecdsa.PublicKey) state.GroupID {
    20  	pk1 := crypto.CompressPubkey(key1)
    21  	pk2 := crypto.CompressPubkey(key2)
    22  	var groupID []byte
    23  	if key1.X.Cmp(key2.X) == -1 {
    24  		groupID = append(pk1, pk2...)
    25  	} else {
    26  		groupID = append(pk2, pk1...)
    27  	}
    28  
    29  	return ToGroupID(crypto.Keccak256(groupID))
    30  }