synchronize display name (#2989)

This commit is contained in:
frank 2022-12-29 14:16:19 +08:00 committed by GitHub
parent dd78445c22
commit 9137257638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 66 additions and 31 deletions

View File

@ -22,7 +22,9 @@ func RunAsync(f func() error) <-chan error {
// HashMessage calculates the hash of a message to be safely signed by the keycard
// The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions.
func HashMessage(message string) ([]byte, error) {
buf := bytes.NewBufferString("\x19Ethereum Signed Message:\n")

View File

@ -202,6 +202,7 @@ func generateSecureRandomData(length int) ([]byte, error) {
// safely used to calculate a signature from.
//
// The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions.
@ -214,6 +215,7 @@ func TextHash(data []byte) []byte {
// safely used to calculate a signature from.
//
// The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions.

2
go.mod
View File

@ -68,7 +68,7 @@ require (
go.uber.org/zap v1.23.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.28.1
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0

View File

@ -442,6 +442,7 @@ func SignMessage(rpcParams string) string {
// SignTypedData unmarshall data into TypedData, validate it and signs with selected account,
// if password matches selected account.
//
//export SignTypedData
func SignTypedData(data, address, password string) string {
var typed typeddata.TypedData
@ -457,6 +458,7 @@ func SignTypedData(data, address, password string) string {
}
// HashTypedData unmarshalls data into TypedData, validates it and hashes it.
//
//export HashTypedData
func HashTypedData(data string) string {
var typed typeddata.TypedData
@ -473,6 +475,7 @@ func HashTypedData(data string) string {
// SignTypedDataV4 unmarshall data into TypedData, validate it and signs with selected account,
// if password matches selected account.
//
//export SignTypedDataV4
func SignTypedDataV4(data, address, password string) string {
var typed apitypes.TypedData
@ -485,6 +488,7 @@ func SignTypedDataV4(data, address, password string) string {
}
// HashTypedDataV4 unmarshalls data into TypedData, validates it and hashes it.
//
//export HashTypedDataV4
func HashTypedDataV4(data string) string {
var typed apitypes.TypedData
@ -586,7 +590,9 @@ func HashTransaction(txArgsJSON string) string {
// HashMessage calculates the hash of a message to be safely signed by the keycard
// The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions.
func HashMessage(message string) string {
hash, err := api.HashMessage(message)
@ -675,6 +681,7 @@ func SetSignalEventCallback(cb unsafe.Pointer) {
}
// ExportNodeLogs reads current node log and returns content to a caller.
//
//export ExportNodeLogs
func ExportNodeLogs() string {
node := statusBackend.StatusNode()

View File

@ -3708,13 +3708,12 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
m.outputToCSV(msg.TransportMessage.Timestamp, msg.ID, senderID, filter.Topic, filter.ChatID, msg.Type, ss)
logger.Debug("Handling SyncSetting", zap.Any("message", ss))
settingField, err := m.extractSyncSetting(&ss)
err := m.handleSyncSetting(messageState, &ss)
if err != nil {
logger.Warn("failed to handle SyncSetting", zap.Error(err))
allMessagesProcessed = false
continue
}
messageState.Response.Settings = append(messageState.Response.Settings, settingField)
case protobuf.RequestAddressForTransaction:
command := msg.ParsedMessage.Interface().(protobuf.RequestAddressForTransaction)

View File

@ -1718,6 +1718,22 @@ func (m *Messenger) HandleRequestAddressForTransaction(messageState *ReceivedMes
return m.handleCommandMessage(messageState, message)
}
func (m *Messenger) handleSyncSetting(messageState *ReceivedMessageState, message *protobuf.SyncSetting) error {
settingField, err := m.extractSyncSetting(message)
if err != nil {
return err
}
if message.GetType() == protobuf.SyncSetting_DISPLAY_NAME {
m.account.Name = message.GetValueString()
err = m.multiAccounts.SaveAccount(*m.account)
if err != nil {
return err
}
}
messageState.Response.AddSetting(settingField)
return nil
}
func (m *Messenger) HandleRequestTransaction(messageState *ReceivedMessageState, command protobuf.RequestTransaction) error {
err := ValidateReceivedRequestTransaction(&command, messageState.CurrentMessageState.WhisperTimestamp)
if err != nil {

View File

@ -308,6 +308,10 @@ func (r *MessengerResponse) AddCommunitySettings(c *communities.CommunitySetting
r.communitiesSettings[c.CommunityID] = c
}
func (r *MessengerResponse) AddSetting(s *settings.SyncSettingField) {
r.Settings = append(r.Settings, s)
}
func (r *MessengerResponse) AddBookmark(bookmark *browsers.Bookmark) {
r.Bookmarks = append(r.Bookmarks, bookmark)
}

View File

@ -15,7 +15,6 @@ Routing rules are following:
List of methods to be routed is currently available here: https://docs.google.com/spreadsheets/d/1N1nuzVN5tXoDmzkBLeC9_mwIlVH8DGF7YD2XwxA8BAE/edit#gid=0
Note, upon creation of a new client, it ok to be offline - client will keep trying to reconnect in background.
*/
package rpc

View File

@ -59,9 +59,11 @@ func BlockedMethods() []string {
// the upstream node; the rest is considered to be routed to
// the local node.
// A list of supported methods:
//
// curl --include \
// --header "Content-Type: application/json" \
// --header "Accept: application/json" 'https://api.infura.io/v1/jsonrpc/ropsten/methods'
//
// Although it's tempting to only list methods coming to the local node as there're fewer of them
// but it's deceptive: we want to ensure that only known requests leave our zone of responsibility.
// Also, we want new requests in newer Geth versions not to be accidentally routed to the upstream.

View File

@ -85,7 +85,9 @@ func checkLogsAreInOrder(records []cacheRecord) error {
// merge merges received records into old slice starting at provided position, example:
// [1, 2, 3]
//
// [2, 3, 4]
//
// [1, 2, 3, 4]
// if hash doesn't match previously received hash - such block was removed due to reorg
// logs that were a part of that block will be returned with Removed set to true

View File

@ -87,16 +87,18 @@ func TriggerDefaultNodeNotificationHandler(jsonEvent string) {
logger.Trace("Notification received", "event", jsonEvent)
}
//export NotifyNode
// nolint: golint
//
//export NotifyNode
func NotifyNode(jsonEvent *C.char) {
notificationHandlerMutex.RLock()
defer notificationHandlerMutex.RUnlock()
notificationHandler(C.GoString(jsonEvent))
}
//export TriggerTestSignal
// nolint: golint
//
//export TriggerTestSignal
func TriggerTestSignal() {
str := C.CString(`{"answer": 42}`)
C.StatusServiceSignalEvent(str)