status-go/protocol/datasync/utils.go

31 lines
718 B
Go
Raw Normal View History

package datasync
import (
"crypto/ecdsa"
2020-01-02 09:10:19 +00:00
"github.com/status-im/mvds/state"
2020-01-02 09:10:19 +00:00
"github.com/status-im/status-go/eth-node/crypto"
)
func ToGroupID(data []byte) state.GroupID {
g := state.GroupID{}
copy(g[:], data[:])
return g
}
// ToOneToOneGroupID returns a groupID for a onetoonechat, which is taken by
// concatenating the bytes of the compressed keys, in ascending order by X
func ToOneToOneGroupID(key1 *ecdsa.PublicKey, key2 *ecdsa.PublicKey) state.GroupID {
pk1 := crypto.CompressPubkey(key1)
pk2 := crypto.CompressPubkey(key2)
var groupID []byte
if key1.X.Cmp(key2.X) == -1 {
groupID = append(pk1, pk2...)
} else {
groupID = append(pk2, pk1...)
}
return ToGroupID(crypto.Keccak256(groupID))
}