Pascal Precht c01ad05525 feat(common): add ThirdPartyID to Message and protobuf.WakuMessage
Usually, message IDs are generated by their payload and signature and
in receiving nodes calculated in based on the same data as well.

There's no ID attached to messages in-flight.

This turns out to be a bit of a problem for messages that are being
imported from third party systems like discord, as the conversion
and saving of such messages and handling of their possible assets and
attachments are done in separate steps, which changes the message
payloads after their IDs have been generated.

Hence, we're introducing a `ThirdPartyID` property to `common.Message`
and `protobuf.WakuMessage` so receiving nodes of such messages (via the
archive protocol primarily) can easily detect third party/imported
messages and give them special treatment.
2022-09-29 11:15:47 +02:00

93 lines
3.6 KiB
Go

package types
import (
"context"
)
// NewMessage represents a new whisper message that is posted through the RPC.
type NewMessage struct {
SymKeyID string `json:"symKeyID"`
PublicKey []byte `json:"pubKey"`
SigID string `json:"sig"`
TTL uint32 `json:"ttl"`
Topic TopicType `json:"topic"`
Payload []byte `json:"payload"`
Padding []byte `json:"padding"`
PowTime uint32 `json:"powTime"`
PowTarget float64 `json:"powTarget"`
TargetPeer string `json:"targetPeer"`
}
// Message is the RPC representation of a whisper message.
type Message struct {
Sig []byte `json:"sig,omitempty"`
TTL uint32 `json:"ttl"`
Timestamp uint32 `json:"timestamp"`
Topic TopicType `json:"topic"`
Payload []byte `json:"payload"`
Padding []byte `json:"padding"`
PoW float64 `json:"pow"`
Hash []byte `json:"hash"`
Dst []byte `json:"recipientPublicKey,omitempty"`
P2P bool `json:"bool,omitempty"`
ThirdPartyID string `json:"thirdPartyId,omitempty"`
}
// Criteria holds various filter options for inbound messages.
type Criteria struct {
SymKeyID string `json:"symKeyID"`
PrivateKeyID string `json:"privateKeyID"`
Sig []byte `json:"sig"`
MinPow float64 `json:"minPow"`
Topics []TopicType `json:"topics"`
AllowP2P bool `json:"allowP2P"`
}
// PublicWhisperAPI provides the whisper RPC service that can be
// use publicly without security implications.
type PublicWhisperAPI interface {
// AddPrivateKey imports the given private key.
AddPrivateKey(ctx context.Context, privateKey HexBytes) (string, error)
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error)
// DeleteKeyPair removes the key with the given key if it exists.
DeleteKeyPair(ctx context.Context, key string) (bool, error)
// Post posts a message on the Whisper network.
// returns the hash of the message in case of success.
Post(ctx context.Context, req NewMessage) ([]byte, error)
// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.
NewMessageFilter(req Criteria) (string, error)
// GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now.
GetFilterMessages(id string) ([]*Message, error)
// BloomFilter returns the current bloomfilter of the node
BloomFilter() []byte
}
// PublicWakuAPI provides the waku RPC service that can be
// use publicly without security implications.
type PublicWakuAPI interface {
// AddPrivateKey imports the given private key.
AddPrivateKey(ctx context.Context, privateKey HexBytes) (string, error)
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error)
// DeleteKeyPair removes the key with the given key if it exists.
DeleteKeyPair(ctx context.Context, key string) (bool, error)
// Post posts a message on the Whisper network.
// returns the hash of the message in case of success.
Post(ctx context.Context, req NewMessage) ([]byte, error)
// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.
NewMessageFilter(req Criteria) (string, error)
// GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now.
GetFilterMessages(id string) ([]*Message, error)
BloomFilter() []byte
}