status-go/waku/bridge/public_wakuv2_api.go
2025-01-21 08:20:18 +01:00

65 lines
2.1 KiB
Go

package bridge
import (
"context"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/wakuv2"
wakutypes "github.com/status-im/status-go/waku/types"
)
type gethPublicWakuV2APIWrapper struct {
api *wakuv2.PublicWakuAPI
}
// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
func NewGethPublicWakuV2APIWrapper(api *wakuv2.PublicWakuAPI) wakutypes.PublicWakuAPI {
if api == nil {
panic("PublicWakuV2API cannot be nil")
}
return &gethPublicWakuV2APIWrapper{
api: api,
}
}
// AddPrivateKey imports the given private key.
func (w *gethPublicWakuV2APIWrapper) AddPrivateKey(ctx context.Context, privateKey types.HexBytes) (string, error) {
return w.api.AddPrivateKey(ctx, hexutil.Bytes(privateKey))
}
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
func (w *gethPublicWakuV2APIWrapper) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) {
return w.api.GenerateSymKeyFromPassword(ctx, passwd)
}
// DeleteKeyPair removes the key with the given key if it exists.
func (w *gethPublicWakuV2APIWrapper) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
return w.api.DeleteKeyPair(ctx, key)
}
func (w *gethPublicWakuV2APIWrapper) BloomFilter() []byte {
return w.api.BloomFilter()
}
// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.
func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req wakutypes.Criteria) (string, error) {
return w.api.NewMessageFilter(req)
}
// GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now.
func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*wakutypes.Message, error) {
return w.api.GetFilterMessages(id)
}
// Post posts a message on the network.
// returns the hash of the message in case of success.
func (w *gethPublicWakuV2APIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) {
return w.api.Post(ctx, req)
}