-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmessage_blockchain.go
41 lines (35 loc) · 1.11 KB
/
message_blockchain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package chat
import (
"time"
"github.com/pkg/errors"
chatpb "github.com/code-payments/code-protobuf-api/generated/go/chat/v1"
"github.com/code-payments/code-server/pkg/code/common"
"github.com/code-payments/code-server/pkg/code/thirdparty"
)
// ToBlockchainMessage takes a raw blockchain message and turns it into a protobuf
// chat message that can be injected into the merchant domain's chat.
func ToBlockchainMessage(
signature string,
sender *common.Account,
blockchainMessage *thirdparty.BlockchainMessage,
ts time.Time,
) (*chatpb.ChatMessage, error) {
var content []*chatpb.Content
switch blockchainMessage.Type {
case thirdparty.NaclBoxBlockchainMessage:
content = []*chatpb.Content{
{
Type: &chatpb.Content_NaclBox{
NaclBox: &chatpb.NaclBoxEncryptedContent{
PeerPublicKey: sender.ToProto(),
Nonce: blockchainMessage.Nonce,
EncryptedPayload: blockchainMessage.EncryptedMessage,
},
},
},
}
default:
return nil, errors.Errorf("%d blockchain message type not supported", blockchainMessage.Type)
}
return newProtoChatMessage(signature, content, ts)
}