Files
Igor Sirotin f3e4363808 refactor: move protocol to internal/protocol
Part of the Go project layout migration, item 27.

Pure move plus import-path rewrite across 502 files. No API or behaviour
change. `internal/` keeps the messaging application logic unimportable
from outside the module, which is what the issue asks for -- status-go is
consumed through the C-bindings in mobile/, not as a Go library.

Things that had to follow the move, beyond the Go imports:

- tools/generate-handlers/template.txt. messenger_handlers.go is
  generated, and the template hard-codes the imports it emits, so the
  generated file kept importing protocol/common and failed typecheck.
- .gitignore. The ignore rule for that generated file was pinned to the
  old path; without moving it, a 1486-line generated file starts being
  tracked.
- Makefile: the logosstorage and torrent test targets (both the archive
  packages and ./protocol itself), the archive README, migration-protocol.
- scripts/run_unit_tests.sh, which names the protocol package explicitly
  to shard its tests.
- scripts/cleanup_generated_files.sh and .golangci.yml.

scripts/migration_check.sh also needed a fix that is not specific to this
move: it validated every file the branch touched under a migration dir
against the timestamp naming rule, and a directory rename makes every
migration in it look newly added. It now excludes renames, so moving a
migration is not mistaken for adding one.

refs #7067
2026-08-21 10:11:05 +02:00

66 lines
2.0 KiB
Go

package common
import (
"crypto/ecdsa"
"github.com/status-im/status-go/internal/crypto/types"
"github.com/status-im/status-go/internal/protocol/protobuf"
messagingtypes "github.com/status-im/status-go/pkg/messaging/types"
)
// ApplicationLayer is the topmost layer and represents the application message.
type ApplicationLayer struct {
// Payload after having been unwrapped from the application layer
Payload []byte `json:"-"`
ID types.HexBytes `json:"id"`
SigPubKey *ecdsa.PublicKey `json:"-"`
Type protobuf.ApplicationMetadataMessage_Type `json:"-"`
}
// StatusMessage adds application layer on top of the messaging
type StatusMessage struct {
messagingtypes.Message
ApplicationLayer ApplicationLayer `json:"applicationLayer"`
}
// SigPubKey returns the most important signature, from the application layer to transport
func (m *StatusMessage) SigPubKey() *ecdsa.PublicKey {
if m.ApplicationLayer.SigPubKey != nil {
return m.ApplicationLayer.SigPubKey
}
return m.TransportLayer.SigPubKey
}
func NewStatusMessages(messages []*messagingtypes.Message) []*StatusMessage {
var statusMessages []*StatusMessage
for _, m := range messages {
statusMessage := &StatusMessage{
Message: *m,
}
// Ignoring error as message might not be wrapped into app layer
_ = processMessageApplicationLayer(statusMessage)
statusMessages = append(statusMessages, statusMessage)
}
return statusMessages
}
func processMessageApplicationLayer(m *StatusMessage) error {
message, err := protobuf.Unmarshal(m.EncryptionLayer.Payload)
if err != nil {
return err
}
recoveredKey, err := RecoverKey(message)
if err != nil {
return err
}
m.ApplicationLayer.SigPubKey = recoveredKey
// Calculate ID using the wrapped record
m.ApplicationLayer.ID = messagingtypes.MessageID(recoveredKey, m.EncryptionLayer.Payload)
m.ApplicationLayer.Payload = message.Payload
m.ApplicationLayer.Type = message.Type
return nil
}