-
Notifications
You must be signed in to change notification settings - Fork 249
/
message_builder.go
66 lines (50 loc) · 1.63 KB
/
message_builder.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package protocol
import (
"crypto/ecdsa"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/identity/alias"
"github.com/status-im/status-go/protocol/identity/identicon"
)
func extendMessageFromChat(message *common.Message, chat *Chat, key *ecdsa.PublicKey, timesource common.TimeSource) error {
clock, timestamp := chat.NextClockAndTimestamp(timesource)
message.LocalChatID = chat.ID
message.Clock = clock
message.Timestamp = timestamp
message.From = types.EncodeHex(crypto.FromECDSAPub(key))
message.SigPubKey = key
message.WhisperTimestamp = timestamp
message.Seen = true
message.OutgoingStatus = common.OutgoingStatusSending
identicon, err := identicon.GenerateBase64(message.From)
if err != nil {
return err
}
message.Identicon = identicon
alias, err := alias.GenerateFromPublicKeyString(message.From)
if err != nil {
return err
}
message.Alias = alias
return nil
}
func extendPinMessageFromChat(message *common.PinMessage, chat *Chat, key *ecdsa.PublicKey, timesource common.TimeSource) error {
clock, timestamp := chat.NextClockAndTimestamp(timesource)
message.LocalChatID = chat.ID
message.Clock = clock
message.From = types.EncodeHex(crypto.FromECDSAPub(key))
message.SigPubKey = key
message.WhisperTimestamp = timestamp
identicon, err := identicon.GenerateBase64(message.From)
if err != nil {
return err
}
message.Identicon = identicon
alias, err := alias.GenerateFromPublicKeyString(message.From)
if err != nil {
return err
}
message.Alias = alias
return nil
}