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 // HashMessage calculates the hash of a message to be safely signed by the keycard
// The hash is calulcated as // The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). // keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions. // This gives context to the signed message and prevents signing of transactions.
func HashMessage(message string) ([]byte, error) { func HashMessage(message string) ([]byte, error) {
buf := bytes.NewBufferString("\x19Ethereum Signed Message:\n") 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. // safely used to calculate a signature from.
// //
// The hash is calulcated as // The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). // keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
// //
// This gives context to the signed message and prevents signing of transactions. // 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. // safely used to calculate a signature from.
// //
// The hash is calulcated as // The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). // keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
// //
// This gives context to the signed message and prevents signing of transactions. // 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 go.uber.org/zap v1.23.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb 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/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/natefinch/lumberjack.v2 v2.0.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, // SignTypedData unmarshall data into TypedData, validate it and signs with selected account,
// if password matches selected account. // if password matches selected account.
//
//export SignTypedData //export SignTypedData
func SignTypedData(data, address, password string) string { func SignTypedData(data, address, password string) string {
var typed typeddata.TypedData 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. // HashTypedData unmarshalls data into TypedData, validates it and hashes it.
//
//export HashTypedData //export HashTypedData
func HashTypedData(data string) string { func HashTypedData(data string) string {
var typed typeddata.TypedData 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, // SignTypedDataV4 unmarshall data into TypedData, validate it and signs with selected account,
// if password matches selected account. // if password matches selected account.
//
//export SignTypedDataV4 //export SignTypedDataV4
func SignTypedDataV4(data, address, password string) string { func SignTypedDataV4(data, address, password string) string {
var typed apitypes.TypedData 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. // HashTypedDataV4 unmarshalls data into TypedData, validates it and hashes it.
//
//export HashTypedDataV4 //export HashTypedDataV4
func HashTypedDataV4(data string) string { func HashTypedDataV4(data string) string {
var typed apitypes.TypedData 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 // HashMessage calculates the hash of a message to be safely signed by the keycard
// The hash is calulcated as // The hash is calulcated as
//
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). // keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
//
// This gives context to the signed message and prevents signing of transactions. // This gives context to the signed message and prevents signing of transactions.
func HashMessage(message string) string { func HashMessage(message string) string {
hash, err := api.HashMessage(message) 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. // ExportNodeLogs reads current node log and returns content to a caller.
//
//export ExportNodeLogs //export ExportNodeLogs
func ExportNodeLogs() string { func ExportNodeLogs() string {
node := statusBackend.StatusNode() 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) m.outputToCSV(msg.TransportMessage.Timestamp, msg.ID, senderID, filter.Topic, filter.ChatID, msg.Type, ss)
logger.Debug("Handling SyncSetting", zap.Any("message", ss)) logger.Debug("Handling SyncSetting", zap.Any("message", ss))
settingField, err := m.extractSyncSetting(&ss) err := m.handleSyncSetting(messageState, &ss)
if err != nil { if err != nil {
logger.Warn("failed to handle SyncSetting", zap.Error(err)) logger.Warn("failed to handle SyncSetting", zap.Error(err))
allMessagesProcessed = false allMessagesProcessed = false
continue continue
} }
messageState.Response.Settings = append(messageState.Response.Settings, settingField)
case protobuf.RequestAddressForTransaction: case protobuf.RequestAddressForTransaction:
command := msg.ParsedMessage.Interface().(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) 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 { func (m *Messenger) HandleRequestTransaction(messageState *ReceivedMessageState, command protobuf.RequestTransaction) error {
err := ValidateReceivedRequestTransaction(&command, messageState.CurrentMessageState.WhisperTimestamp) err := ValidateReceivedRequestTransaction(&command, messageState.CurrentMessageState.WhisperTimestamp)
if err != nil { if err != nil {

View File

@ -308,6 +308,10 @@ func (r *MessengerResponse) AddCommunitySettings(c *communities.CommunitySetting
r.communitiesSettings[c.CommunityID] = c 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) { func (r *MessengerResponse) AddBookmark(bookmark *browsers.Bookmark) {
r.Bookmarks = append(r.Bookmarks, 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 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. Note, upon creation of a new client, it ok to be offline - client will keep trying to reconnect in background.
*/ */
package rpc package rpc

View File

@ -59,9 +59,11 @@ func BlockedMethods() []string {
// the upstream node; the rest is considered to be routed to // the upstream node; the rest is considered to be routed to
// the local node. // the local node.
// A list of supported methods: // A list of supported methods:
//
// curl --include \ // curl --include \
// --header "Content-Type: application/json" \ // --header "Content-Type: application/json" \
// --header "Accept: application/json" 'https://api.infura.io/v1/jsonrpc/ropsten/methods' // --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 // 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. // 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. // 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: // merge merges received records into old slice starting at provided position, example:
// [1, 2, 3] // [1, 2, 3]
//
// [2, 3, 4] // [2, 3, 4]
//
// [1, 2, 3, 4] // [1, 2, 3, 4]
// if hash doesn't match previously received hash - such block was removed due to reorg // 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 // 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) logger.Trace("Notification received", "event", jsonEvent)
} }
//export NotifyNode
// nolint: golint // nolint: golint
//
//export NotifyNode
func NotifyNode(jsonEvent *C.char) { func NotifyNode(jsonEvent *C.char) {
notificationHandlerMutex.RLock() notificationHandlerMutex.RLock()
defer notificationHandlerMutex.RUnlock() defer notificationHandlerMutex.RUnlock()
notificationHandler(C.GoString(jsonEvent)) notificationHandler(C.GoString(jsonEvent))
} }
//export TriggerTestSignal
// nolint: golint // nolint: golint
//
//export TriggerTestSignal
func TriggerTestSignal() { func TriggerTestSignal() {
str := C.CString(`{"answer": 42}`) str := C.CString(`{"answer": 42}`)
C.StatusServiceSignalEvent(str) C.StatusServiceSignalEvent(str)