2018-09-24 18:07:34 +00:00
|
|
|
package chat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-09-25 07:05:38 +00:00
|
|
|
whisper "github.com/status-im/whisper/whisperv6"
|
2018-09-24 18:07:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var discoveryTopic = "contact-discovery"
|
|
|
|
var discoveryTopicBytes = toTopic(discoveryTopic)
|
|
|
|
|
|
|
|
func toTopic(s string) whisper.TopicType {
|
|
|
|
return whisper.BytesToTopic(crypto.Keccak256([]byte(s)))
|
|
|
|
}
|
|
|
|
|
2018-10-16 10:31:05 +00:00
|
|
|
func defaultWhisperMessage() whisper.NewMessage {
|
|
|
|
msg := whisper.NewMessage{}
|
2018-09-24 18:07:34 +00:00
|
|
|
|
|
|
|
msg.TTL = 10
|
|
|
|
msg.PowTarget = 0.002
|
|
|
|
msg.PowTime = 1
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
2018-10-16 10:31:05 +00:00
|
|
|
func PublicMessageToWhisper(rpcMsg SendPublicMessageRPC, payload []byte) whisper.NewMessage {
|
2018-09-24 18:07:34 +00:00
|
|
|
msg := defaultWhisperMessage()
|
|
|
|
|
|
|
|
msg.Topic = toTopic(rpcMsg.Chat)
|
|
|
|
|
|
|
|
msg.Payload = payload
|
|
|
|
msg.Sig = rpcMsg.Sig
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
2018-10-16 10:31:05 +00:00
|
|
|
func DirectMessageToWhisper(rpcMsg SendDirectMessageRPC, payload []byte) whisper.NewMessage {
|
2018-09-24 18:07:34 +00:00
|
|
|
|
|
|
|
msg := defaultWhisperMessage()
|
|
|
|
|
|
|
|
msg.Topic = discoveryTopicBytes
|
|
|
|
|
|
|
|
msg.Payload = payload
|
|
|
|
msg.Sig = rpcMsg.Sig
|
|
|
|
msg.PublicKey = rpcMsg.PubKey
|
|
|
|
|
|
|
|
return msg
|
|
|
|
}
|