113
vendor/github.com/status-im/status-go/eth-node/bridge/geth/ens/ens.go
generated
vendored
Normal file
113
vendor/github.com/status-im/status-go/eth-node/bridge/geth/ens/ens.go
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
package ens
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/elliptic"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
ens "github.com/wealdtech/go-ens/v3"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
enstypes "github.com/status-im/status-go/eth-node/types/ens"
|
||||
)
|
||||
|
||||
const (
|
||||
contractQueryTimeout = 5000 * time.Millisecond
|
||||
)
|
||||
|
||||
type Verifier struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewVerifier returns a Verifier attached to the specified logger
|
||||
func NewVerifier(logger *zap.Logger) *Verifier {
|
||||
return &Verifier{logger: logger}
|
||||
}
|
||||
|
||||
func (m *Verifier) ReverseResolve(address common.Address, rpcEndpoint string) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), contractQueryTimeout)
|
||||
defer cancel()
|
||||
|
||||
ethClient, err := ethclient.DialContext(ctx, rpcEndpoint)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return ens.ReverseResolve(ethClient, address)
|
||||
}
|
||||
|
||||
func (m *Verifier) verifyENSName(ensInfo enstypes.ENSDetails, ethclient *ethclient.Client) enstypes.ENSResponse {
|
||||
publicKeyStr := ensInfo.PublicKeyString
|
||||
ensName := ensInfo.Name
|
||||
m.logger.Info("Resolving ENS name", zap.String("name", ensName), zap.String("publicKey", publicKeyStr))
|
||||
response := enstypes.ENSResponse{
|
||||
Name: ensName,
|
||||
PublicKeyString: publicKeyStr,
|
||||
VerifiedAt: time.Now().Unix(),
|
||||
}
|
||||
|
||||
expectedPubKeyBytes, err := hex.DecodeString(publicKeyStr)
|
||||
if err != nil {
|
||||
response.Error = err
|
||||
return response
|
||||
}
|
||||
|
||||
publicKey, err := crypto.UnmarshalPubkey(expectedPubKeyBytes)
|
||||
if err != nil {
|
||||
response.Error = err
|
||||
return response
|
||||
}
|
||||
|
||||
// Resolve ensName
|
||||
resolver, err := ens.NewResolver(ethclient, ensName)
|
||||
if err != nil {
|
||||
m.logger.Error("error while creating ENS name resolver", zap.String("ensName", ensName), zap.Error(err))
|
||||
response.Error = err
|
||||
return response
|
||||
}
|
||||
x, y, err := resolver.PubKey()
|
||||
if err != nil {
|
||||
m.logger.Error("error while resolving public key from ENS name", zap.String("ensName", ensName), zap.Error(err))
|
||||
response.Error = err
|
||||
return response
|
||||
}
|
||||
|
||||
// Assemble the bytes returned for the pubkey
|
||||
pubKeyBytes := elliptic.Marshal(crypto.S256(), new(big.Int).SetBytes(x[:]), new(big.Int).SetBytes(y[:]))
|
||||
|
||||
response.PublicKey = publicKey
|
||||
response.Verified = bytes.Equal(pubKeyBytes, expectedPubKeyBytes)
|
||||
return response
|
||||
}
|
||||
|
||||
// CheckBatch verifies that a registered ENS name matches the expected public key
|
||||
func (m *Verifier) CheckBatch(ensDetails []enstypes.ENSDetails, rpcEndpoint, contractAddress string) (map[string]enstypes.ENSResponse, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), contractQueryTimeout)
|
||||
defer cancel()
|
||||
|
||||
ch := make(chan enstypes.ENSResponse)
|
||||
response := make(map[string]enstypes.ENSResponse)
|
||||
|
||||
ethclient, err := ethclient.DialContext(ctx, rpcEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, ensInfo := range ensDetails {
|
||||
go func(info enstypes.ENSDetails) { ch <- m.verifyENSName(info, ethclient) }(ensInfo)
|
||||
}
|
||||
|
||||
for range ensDetails {
|
||||
r := <-ch
|
||||
response[r.PublicKeyString] = r
|
||||
}
|
||||
close(ch)
|
||||
|
||||
return response, nil
|
||||
}
|
||||
58
vendor/github.com/status-im/status-go/eth-node/bridge/geth/envelope.go
generated
vendored
Normal file
58
vendor/github.com/status-im/status-go/eth-node/bridge/geth/envelope.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
waku "github.com/status-im/status-go/waku/common"
|
||||
)
|
||||
|
||||
type wakuEnvelope struct {
|
||||
env *waku.Envelope
|
||||
}
|
||||
|
||||
// NewWakuEnvelope returns an object that wraps Geth's Waku Envelope in a types interface.
|
||||
func NewWakuEnvelope(e *waku.Envelope) types.Envelope {
|
||||
return &wakuEnvelope{env: e}
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) Unwrap() interface{} {
|
||||
return w.env
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) Hash() types.Hash {
|
||||
return types.Hash(w.env.Hash())
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) Bloom() []byte {
|
||||
return w.env.Bloom()
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) PoW() float64 {
|
||||
return w.env.PoW()
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) Expiry() uint32 {
|
||||
return w.env.Expiry
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) TTL() uint32 {
|
||||
return w.env.TTL
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) Topic() types.TopicType {
|
||||
return types.TopicType(w.env.Topic)
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) Size() int {
|
||||
return len(w.env.Data)
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) DecodeRLP(s *rlp.Stream) error {
|
||||
return w.env.DecodeRLP(s)
|
||||
}
|
||||
|
||||
func (w *wakuEnvelope) EncodeRLP(writer io.Writer) error {
|
||||
return rlp.Encode(writer, w.env)
|
||||
}
|
||||
43
vendor/github.com/status-im/status-go/eth-node/bridge/geth/envelope_error.go
generated
vendored
Normal file
43
vendor/github.com/status-im/status-go/eth-node/bridge/geth/envelope_error.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
waku "github.com/status-im/status-go/waku/common"
|
||||
wakuv2 "github.com/status-im/status-go/wakuv2/common"
|
||||
)
|
||||
|
||||
// NewWakuEnvelopeErrorWrapper returns a types.EnvelopeError object that mimics Geth's EnvelopeError
|
||||
func NewWakuEnvelopeErrorWrapper(envelopeError *waku.EnvelopeError) *types.EnvelopeError {
|
||||
if envelopeError == nil {
|
||||
panic("envelopeError should not be nil")
|
||||
}
|
||||
|
||||
return &types.EnvelopeError{
|
||||
Hash: types.Hash(envelopeError.Hash),
|
||||
Code: mapGethErrorCode(envelopeError.Code),
|
||||
Description: envelopeError.Description,
|
||||
}
|
||||
}
|
||||
|
||||
// NewWakuEnvelopeErrorWrapper returns a types.EnvelopeError object that mimics Geth's EnvelopeError
|
||||
func NewWakuV2EnvelopeErrorWrapper(envelopeError *wakuv2.EnvelopeError) *types.EnvelopeError {
|
||||
if envelopeError == nil {
|
||||
panic("envelopeError should not be nil")
|
||||
}
|
||||
|
||||
return &types.EnvelopeError{
|
||||
Hash: types.Hash(envelopeError.Hash),
|
||||
Code: mapGethErrorCode(envelopeError.Code),
|
||||
Description: envelopeError.Description,
|
||||
}
|
||||
}
|
||||
|
||||
func mapGethErrorCode(code uint) uint {
|
||||
switch code {
|
||||
case waku.EnvelopeTimeNotSynced:
|
||||
return types.EnvelopeTimeNotSynced
|
||||
case waku.EnvelopeOtherError:
|
||||
return types.EnvelopeOtherError
|
||||
}
|
||||
return types.EnvelopeOtherError
|
||||
}
|
||||
60
vendor/github.com/status-im/status-go/eth-node/bridge/geth/envelope_event.go
generated
vendored
Normal file
60
vendor/github.com/status-im/status-go/eth-node/bridge/geth/envelope_event.go
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/waku"
|
||||
"github.com/status-im/status-go/wakuv2"
|
||||
|
||||
wakucommon "github.com/status-im/status-go/waku/common"
|
||||
wakuv2common "github.com/status-im/status-go/wakuv2/common"
|
||||
)
|
||||
|
||||
// NewWakuEnvelopeEventWrapper returns a types.EnvelopeEvent object that mimics Geth's EnvelopeEvent
|
||||
func NewWakuEnvelopeEventWrapper(envelopeEvent *wakucommon.EnvelopeEvent) *types.EnvelopeEvent {
|
||||
if envelopeEvent == nil {
|
||||
panic("envelopeEvent should not be nil")
|
||||
}
|
||||
|
||||
wrappedData := envelopeEvent.Data
|
||||
switch data := envelopeEvent.Data.(type) {
|
||||
case []wakucommon.EnvelopeError:
|
||||
wrappedData := make([]types.EnvelopeError, len(data))
|
||||
for index := range data {
|
||||
wrappedData[index] = *NewWakuEnvelopeErrorWrapper(&data[index])
|
||||
}
|
||||
case *waku.MailServerResponse:
|
||||
wrappedData = NewWakuMailServerResponseWrapper(data)
|
||||
}
|
||||
return &types.EnvelopeEvent{
|
||||
Event: types.EventType(envelopeEvent.Event),
|
||||
Hash: types.Hash(envelopeEvent.Hash),
|
||||
Batch: types.Hash(envelopeEvent.Batch),
|
||||
Peer: types.EnodeID(envelopeEvent.Peer),
|
||||
Data: wrappedData,
|
||||
}
|
||||
}
|
||||
|
||||
// NewWakuV2EnvelopeEventWrapper returns a types.EnvelopeEvent object that mimics Geth's EnvelopeEvent
|
||||
func NewWakuV2EnvelopeEventWrapper(envelopeEvent *wakuv2common.EnvelopeEvent) *types.EnvelopeEvent {
|
||||
if envelopeEvent == nil {
|
||||
panic("envelopeEvent should not be nil")
|
||||
}
|
||||
|
||||
wrappedData := envelopeEvent.Data
|
||||
switch data := envelopeEvent.Data.(type) {
|
||||
case []wakuv2common.EnvelopeError:
|
||||
wrappedData := make([]types.EnvelopeError, len(data))
|
||||
for index := range data {
|
||||
wrappedData[index] = *NewWakuV2EnvelopeErrorWrapper(&data[index])
|
||||
}
|
||||
case *wakuv2.MailServerResponse:
|
||||
wrappedData = NewWakuV2MailServerResponseWrapper(data)
|
||||
}
|
||||
return &types.EnvelopeEvent{
|
||||
Event: types.EventType(envelopeEvent.Event),
|
||||
Hash: types.Hash(envelopeEvent.Hash),
|
||||
Batch: types.Hash(envelopeEvent.Batch),
|
||||
Peer: types.EnodeID(envelopeEvent.Peer),
|
||||
Data: wrappedData,
|
||||
}
|
||||
}
|
||||
103
vendor/github.com/status-im/status-go/eth-node/bridge/geth/keystore.go
generated
vendored
Normal file
103
vendor/github.com/status-im/status-go/eth-node/bridge/geth/keystore.go
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/extkeys"
|
||||
)
|
||||
|
||||
type gethKeyStoreAdapter struct {
|
||||
keystore *keystore.KeyStore
|
||||
}
|
||||
|
||||
// WrapKeyStore creates a types.KeyStore wrapper over a keystore.KeyStore object
|
||||
func WrapKeyStore(keystore *keystore.KeyStore) types.KeyStore {
|
||||
return &gethKeyStoreAdapter{keystore: keystore}
|
||||
}
|
||||
|
||||
func (k *gethKeyStoreAdapter) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (types.Account, error) {
|
||||
gethAccount, err := k.keystore.ImportECDSA(priv, passphrase)
|
||||
return accountFrom(gethAccount), err
|
||||
}
|
||||
|
||||
func (k *gethKeyStoreAdapter) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, passphrase string) (types.Account, error) {
|
||||
gethAccount, err := k.keystore.ImportSingleExtendedKey(extKey, passphrase)
|
||||
return accountFrom(gethAccount), err
|
||||
}
|
||||
|
||||
func (k *gethKeyStoreAdapter) ImportExtendedKeyForPurpose(keyPurpose extkeys.KeyPurpose, extKey *extkeys.ExtendedKey, passphrase string) (types.Account, error) {
|
||||
gethAccount, err := k.keystore.ImportExtendedKeyForPurpose(keyPurpose, extKey, passphrase)
|
||||
return accountFrom(gethAccount), err
|
||||
}
|
||||
|
||||
func (k *gethKeyStoreAdapter) AccountDecryptedKey(a types.Account, auth string) (types.Account, *types.Key, error) {
|
||||
gethAccount, err := gethAccountFrom(a)
|
||||
if err != nil {
|
||||
return types.Account{}, nil, err
|
||||
}
|
||||
|
||||
var gethKey *keystore.Key
|
||||
gethAccount, gethKey, err = k.keystore.AccountDecryptedKey(gethAccount, auth)
|
||||
return accountFrom(gethAccount), keyFrom(gethKey), err
|
||||
}
|
||||
|
||||
func (k *gethKeyStoreAdapter) Delete(a types.Account) error {
|
||||
gethAccount, err := gethAccountFrom(a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.keystore.Delete(gethAccount)
|
||||
}
|
||||
|
||||
// parseGethURL converts a user supplied URL into the accounts specific structure.
|
||||
func parseGethURL(url string) (accounts.URL, error) {
|
||||
parts := strings.Split(url, "://")
|
||||
if len(parts) != 2 || parts[0] == "" {
|
||||
return accounts.URL{}, errors.New("protocol scheme missing")
|
||||
}
|
||||
return accounts.URL{
|
||||
Scheme: parts[0],
|
||||
Path: parts[1],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func gethAccountFrom(account types.Account) (accounts.Account, error) {
|
||||
var (
|
||||
gethAccount accounts.Account
|
||||
err error
|
||||
)
|
||||
gethAccount.Address = common.Address(account.Address)
|
||||
if account.URL != "" {
|
||||
gethAccount.URL, err = parseGethURL(account.URL)
|
||||
}
|
||||
return gethAccount, err
|
||||
}
|
||||
|
||||
func accountFrom(gethAccount accounts.Account) types.Account {
|
||||
return types.Account{
|
||||
Address: types.Address(gethAccount.Address),
|
||||
URL: gethAccount.URL.String(),
|
||||
}
|
||||
}
|
||||
|
||||
func keyFrom(k *keystore.Key) *types.Key {
|
||||
if k == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &types.Key{
|
||||
ID: k.Id,
|
||||
Address: types.Address(k.Address),
|
||||
PrivateKey: k.PrivateKey,
|
||||
ExtendedKey: k.ExtendedKey,
|
||||
SubAccountIndex: k.SubAccountIndex,
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/status-im/status-go/eth-node/bridge/geth/mailserver_response.go
generated
vendored
Normal file
33
vendor/github.com/status-im/status-go/eth-node/bridge/geth/mailserver_response.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/waku"
|
||||
"github.com/status-im/status-go/wakuv2"
|
||||
)
|
||||
|
||||
// NewWakuMailServerResponseWrapper returns a types.MailServerResponse object that mimics Geth's MailServerResponse
|
||||
func NewWakuMailServerResponseWrapper(mailServerResponse *waku.MailServerResponse) *types.MailServerResponse {
|
||||
if mailServerResponse == nil {
|
||||
panic("mailServerResponse should not be nil")
|
||||
}
|
||||
|
||||
return &types.MailServerResponse{
|
||||
LastEnvelopeHash: types.Hash(mailServerResponse.LastEnvelopeHash),
|
||||
Cursor: mailServerResponse.Cursor,
|
||||
Error: mailServerResponse.Error,
|
||||
}
|
||||
}
|
||||
|
||||
// NewWakuV2MailServerResponseWrapper returns a types.MailServerResponse object that mimics Geth's MailServerResponse
|
||||
func NewWakuV2MailServerResponseWrapper(mailServerResponse *wakuv2.MailServerResponse) *types.MailServerResponse {
|
||||
if mailServerResponse == nil {
|
||||
panic("mailServerResponse should not be nil")
|
||||
}
|
||||
|
||||
return &types.MailServerResponse{
|
||||
LastEnvelopeHash: types.Hash(mailServerResponse.LastEnvelopeHash),
|
||||
Cursor: mailServerResponse.Cursor,
|
||||
Error: mailServerResponse.Error,
|
||||
}
|
||||
}
|
||||
88
vendor/github.com/status-im/status-go/eth-node/bridge/geth/node.go
generated
vendored
Normal file
88
vendor/github.com/status-im/status-go/eth-node/bridge/geth/node.go
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/waku"
|
||||
"github.com/status-im/status-go/wakuv2"
|
||||
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
|
||||
gethens "github.com/status-im/status-go/eth-node/bridge/geth/ens"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
enstypes "github.com/status-im/status-go/eth-node/types/ens"
|
||||
)
|
||||
|
||||
type gethNodeWrapper struct {
|
||||
stack *node.Node
|
||||
waku1 *waku.Waku
|
||||
waku2 *wakuv2.Waku
|
||||
}
|
||||
|
||||
func NewNodeBridge(stack *node.Node, waku1 *waku.Waku, waku2 *wakuv2.Waku) types.Node {
|
||||
return &gethNodeWrapper{stack: stack, waku1: waku1, waku2: waku2}
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) Poll() {
|
||||
// noop
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) NewENSVerifier(logger *zap.Logger) enstypes.ENSVerifier {
|
||||
return gethens.NewVerifier(logger)
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) SetWaku1(waku *waku.Waku) {
|
||||
w.waku1 = waku
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) SetWaku2(waku *wakuv2.Waku) {
|
||||
w.waku2 = waku
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) GetWaku(ctx interface{}) (types.Waku, error) {
|
||||
if w.waku1 == nil {
|
||||
return nil, errors.New("waku service is not available")
|
||||
}
|
||||
|
||||
return NewGethWakuWrapper(w.waku1), nil
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) GetWakuV2(ctx interface{}) (types.Waku, error) {
|
||||
if w.waku2 == nil {
|
||||
return nil, errors.New("waku service is not available")
|
||||
}
|
||||
|
||||
return NewGethWakuV2Wrapper(w.waku2), nil
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) AddPeer(url string) error {
|
||||
parsedNode, err := enode.ParseV4(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w.stack.Server().AddPeer(parsedNode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) RemovePeer(url string) error {
|
||||
parsedNode, err := enode.ParseV4(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w.stack.Server().RemovePeer(parsedNode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *gethNodeWrapper) PeersCount() int {
|
||||
if w.stack.Server() == nil {
|
||||
return 0
|
||||
}
|
||||
return len(w.stack.Server().Peers())
|
||||
}
|
||||
109
vendor/github.com/status-im/status-go/eth-node/bridge/geth/public_waku_api.go
generated
vendored
Normal file
109
vendor/github.com/status-im/status-go/eth-node/bridge/geth/public_waku_api.go
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/waku"
|
||||
wakucommon "github.com/status-im/status-go/waku/common"
|
||||
)
|
||||
|
||||
type GethPublicWakuAPIWrapper struct {
|
||||
api *waku.PublicWakuAPI
|
||||
}
|
||||
|
||||
// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
|
||||
func NewGethPublicWakuAPIWrapper(api *waku.PublicWakuAPI) types.PublicWakuAPI {
|
||||
if api == nil {
|
||||
panic("PublicWakuAPI cannot be nil")
|
||||
}
|
||||
|
||||
return &GethPublicWakuAPIWrapper{
|
||||
api: api,
|
||||
}
|
||||
}
|
||||
|
||||
// AddPrivateKey imports the given private key.
|
||||
func (w *GethPublicWakuAPIWrapper) 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 *GethPublicWakuAPIWrapper) 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 *GethPublicWakuAPIWrapper) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
|
||||
return w.api.DeleteKeyPair(ctx, key)
|
||||
}
|
||||
|
||||
// NewMessageFilter creates a new filter that can be used to poll for
|
||||
// (new) messages that satisfy the given criteria.
|
||||
func (w *GethPublicWakuAPIWrapper) NewMessageFilter(req types.Criteria) (string, error) {
|
||||
topics := make([]wakucommon.TopicType, len(req.Topics))
|
||||
for index, tt := range req.Topics {
|
||||
topics[index] = wakucommon.TopicType(tt)
|
||||
}
|
||||
|
||||
criteria := waku.Criteria{
|
||||
SymKeyID: req.SymKeyID,
|
||||
PrivateKeyID: req.PrivateKeyID,
|
||||
Sig: req.Sig,
|
||||
MinPow: req.MinPow,
|
||||
Topics: topics,
|
||||
AllowP2P: req.AllowP2P,
|
||||
}
|
||||
return w.api.NewMessageFilter(criteria)
|
||||
}
|
||||
|
||||
func (w *GethPublicWakuAPIWrapper) BloomFilter() []byte {
|
||||
return w.api.BloomFilter()
|
||||
}
|
||||
|
||||
// GetFilterMessages returns the messages that match the filter criteria and
|
||||
// are received between the last poll and now.
|
||||
func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*types.Message, error) {
|
||||
msgs, err := w.api.GetFilterMessages(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wrappedMsgs := make([]*types.Message, len(msgs))
|
||||
for index, msg := range msgs {
|
||||
wrappedMsgs[index] = &types.Message{
|
||||
Sig: msg.Sig,
|
||||
TTL: msg.TTL,
|
||||
Timestamp: msg.Timestamp,
|
||||
Topic: types.TopicType(msg.Topic),
|
||||
Payload: msg.Payload,
|
||||
Padding: msg.Padding,
|
||||
PoW: msg.PoW,
|
||||
Hash: msg.Hash,
|
||||
Dst: msg.Dst,
|
||||
P2P: msg.P2P,
|
||||
}
|
||||
}
|
||||
return wrappedMsgs, nil
|
||||
}
|
||||
|
||||
// Post posts a message on the network.
|
||||
// returns the hash of the message in case of success.
|
||||
func (w *GethPublicWakuAPIWrapper) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
|
||||
msg := waku.NewMessage{
|
||||
SymKeyID: req.SymKeyID,
|
||||
PublicKey: req.PublicKey,
|
||||
Sig: req.SigID, // Sig is really a SigID
|
||||
TTL: req.TTL,
|
||||
Topic: wakucommon.TopicType(req.Topic),
|
||||
Payload: req.Payload,
|
||||
Padding: req.Padding,
|
||||
PowTime: req.PowTime,
|
||||
PowTarget: req.PowTarget,
|
||||
TargetPeer: req.TargetPeer,
|
||||
Ephemeral: req.Ephemeral,
|
||||
}
|
||||
return w.api.Post(ctx, msg)
|
||||
}
|
||||
104
vendor/github.com/status-im/status-go/eth-node/bridge/geth/public_wakuv2_api.go
generated
vendored
Normal file
104
vendor/github.com/status-im/status-go/eth-node/bridge/geth/public_wakuv2_api.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
package gethbridge
|
||||
|
||||
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"
|
||||
wakucommon "github.com/status-im/status-go/wakuv2/common"
|
||||
)
|
||||
|
||||
type gethPublicWakuV2APIWrapper struct {
|
||||
api *wakuv2.PublicWakuAPI
|
||||
}
|
||||
|
||||
// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
|
||||
func NewGethPublicWakuV2APIWrapper(api *wakuv2.PublicWakuAPI) types.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 types.Criteria) (string, error) {
|
||||
topics := make([]wakucommon.TopicType, len(req.Topics))
|
||||
for index, tt := range req.Topics {
|
||||
topics[index] = wakucommon.TopicType(tt)
|
||||
}
|
||||
|
||||
criteria := wakuv2.Criteria{
|
||||
SymKeyID: req.SymKeyID,
|
||||
PrivateKeyID: req.PrivateKeyID,
|
||||
Sig: req.Sig,
|
||||
PubsubTopic: req.PubsubTopic,
|
||||
ContentTopics: topics,
|
||||
}
|
||||
return w.api.NewMessageFilter(criteria)
|
||||
}
|
||||
|
||||
// GetFilterMessages returns the messages that match the filter criteria and
|
||||
// are received between the last poll and now.
|
||||
func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*types.Message, error) {
|
||||
msgs, err := w.api.GetFilterMessages(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wrappedMsgs := make([]*types.Message, len(msgs))
|
||||
for index, msg := range msgs {
|
||||
wrappedMsgs[index] = &types.Message{
|
||||
Sig: msg.Sig,
|
||||
Timestamp: msg.Timestamp,
|
||||
PubsubTopic: msg.PubsubTopic,
|
||||
Topic: types.TopicType(msg.ContentTopic),
|
||||
Payload: msg.Payload,
|
||||
Padding: msg.Padding,
|
||||
Hash: msg.Hash,
|
||||
Dst: msg.Dst,
|
||||
}
|
||||
}
|
||||
return wrappedMsgs, nil
|
||||
}
|
||||
|
||||
// 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 types.NewMessage) ([]byte, error) {
|
||||
msg := wakuv2.NewMessage{
|
||||
SymKeyID: req.SymKeyID,
|
||||
PublicKey: req.PublicKey,
|
||||
Sig: req.SigID, // Sig is really a SigID
|
||||
PubsubTopic: req.PubsubTopic,
|
||||
ContentTopic: wakucommon.TopicType(req.Topic),
|
||||
Payload: req.Payload,
|
||||
Padding: req.Padding,
|
||||
TargetPeer: req.TargetPeer,
|
||||
Ephemeral: req.Ephemeral,
|
||||
}
|
||||
return w.api.Post(ctx, msg)
|
||||
}
|
||||
30
vendor/github.com/status-im/status-go/eth-node/bridge/geth/subscription.go
generated
vendored
Normal file
30
vendor/github.com/status-im/status-go/eth-node/bridge/geth/subscription.go
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
type gethSubscriptionWrapper struct {
|
||||
subscription event.Subscription
|
||||
}
|
||||
|
||||
// NewGethSubscriptionWrapper returns an object that wraps Geth's Subscription in a types interface
|
||||
func NewGethSubscriptionWrapper(subscription event.Subscription) types.Subscription {
|
||||
if subscription == nil {
|
||||
panic("subscription cannot be nil")
|
||||
}
|
||||
|
||||
return &gethSubscriptionWrapper{
|
||||
subscription: subscription,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *gethSubscriptionWrapper) Err() <-chan error {
|
||||
return w.subscription.Err()
|
||||
}
|
||||
|
||||
func (w *gethSubscriptionWrapper) Unsubscribe() {
|
||||
w.subscription.Unsubscribe()
|
||||
}
|
||||
316
vendor/github.com/status-im/status-go/eth-node/bridge/geth/waku.go
generated
vendored
Normal file
316
vendor/github.com/status-im/status-go/eth-node/bridge/geth/waku.go
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/status-im/status-go/connection"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/waku"
|
||||
wakucommon "github.com/status-im/status-go/waku/common"
|
||||
)
|
||||
|
||||
type GethWakuWrapper struct {
|
||||
waku *waku.Waku
|
||||
}
|
||||
|
||||
// NewGethWakuWrapper returns an object that wraps Geth's Waku in a types interface
|
||||
func NewGethWakuWrapper(w *waku.Waku) types.Waku {
|
||||
if w == nil {
|
||||
panic("waku cannot be nil")
|
||||
}
|
||||
|
||||
return &GethWakuWrapper{
|
||||
waku: w,
|
||||
}
|
||||
}
|
||||
|
||||
// GetGethWhisperFrom retrieves the underlying whisper Whisper struct from a wrapped Whisper interface
|
||||
func GetGethWakuFrom(m types.Waku) *waku.Waku {
|
||||
return m.(*GethWakuWrapper).waku
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) PublicWakuAPI() types.PublicWakuAPI {
|
||||
return NewGethPublicWakuAPIWrapper(waku.NewPublicWakuAPI(w.waku))
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) Version() uint {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) PeerCount() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// Added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) StartDiscV5() error {
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// Added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) StopDiscV5() error {
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// PeerCount function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) AddStorePeer(address string) (peer.ID, error) {
|
||||
return "", errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// SubscribeToPubsubTopic function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) SubscribeToPubsubTopic(topic string, optPublicKey *ecdsa.PublicKey) error {
|
||||
// not available in WakuV1
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) UnsubscribeFromPubsubTopic(topic string) error {
|
||||
// not available in WakuV1
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) RetrievePubsubTopicKey(topic string) (*ecdsa.PrivateKey, error) {
|
||||
// not available in WakuV1
|
||||
return nil, errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) StorePubsubTopicKey(topic string, privKey *ecdsa.PrivateKey) error {
|
||||
// not available in WakuV1
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) RemovePubsubTopicKey(topic string) error {
|
||||
// not available in WakuV1
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// AddRelayPeer function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) AddRelayPeer(address string) (peer.ID, error) {
|
||||
return "", errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// DialPeer function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) DialPeer(address string) error {
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// DialPeerByID function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) DialPeerByID(peerID string) error {
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// ListenAddresses function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) ListenAddresses() ([]string, error) {
|
||||
return nil, errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// PeerCount function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) DropPeer(peerID string) error {
|
||||
return errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) SubscribeToConnStatusChanges() (*types.ConnStatusSubscription, error) {
|
||||
return nil, errors.New("not available in WakuV1")
|
||||
}
|
||||
|
||||
// Peers function only added for compatibility with waku V2
|
||||
func (w *GethWakuWrapper) Peers() map[string]types.WakuV2Peer {
|
||||
p := make(map[string]types.WakuV2Peer)
|
||||
return p
|
||||
}
|
||||
|
||||
// MinPow returns the PoW value required by this node.
|
||||
func (w *GethWakuWrapper) MinPow() float64 {
|
||||
return w.waku.MinPow()
|
||||
}
|
||||
|
||||
// MaxMessageSize returns the MaxMessageSize set
|
||||
func (w *GethWakuWrapper) MaxMessageSize() uint32 {
|
||||
return w.waku.MaxMessageSize()
|
||||
}
|
||||
|
||||
// BloomFilter returns the aggregated bloom filter for all the topics of interest.
|
||||
// The nodes are required to send only messages that match the advertised bloom filter.
|
||||
// If a message does not match the bloom, it will tantamount to spam, and the peer will
|
||||
// be disconnected.
|
||||
func (w *GethWakuWrapper) BloomFilter() []byte {
|
||||
return w.waku.BloomFilter()
|
||||
}
|
||||
|
||||
// GetCurrentTime returns current time.
|
||||
func (w *GethWakuWrapper) GetCurrentTime() time.Time {
|
||||
return w.waku.CurrentTime()
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) SubscribeEnvelopeEvents(eventsProxy chan<- types.EnvelopeEvent) types.Subscription {
|
||||
events := make(chan wakucommon.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper
|
||||
go func() {
|
||||
for e := range events {
|
||||
eventsProxy <- *NewWakuEnvelopeEventWrapper(&e)
|
||||
}
|
||||
}()
|
||||
|
||||
return NewGethSubscriptionWrapper(w.waku.SubscribeEnvelopeEvents(events))
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) {
|
||||
return w.waku.GetPrivateKey(id)
|
||||
}
|
||||
|
||||
// AddKeyPair imports a asymmetric private key and returns a deterministic identifier.
|
||||
func (w *GethWakuWrapper) AddKeyPair(key *ecdsa.PrivateKey) (string, error) {
|
||||
return w.waku.AddKeyPair(key)
|
||||
}
|
||||
|
||||
// DeleteKeyPair deletes the key with the specified ID if it exists.
|
||||
func (w *GethWakuWrapper) DeleteKeyPair(keyID string) bool {
|
||||
return w.waku.DeleteKeyPair(keyID)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) AddSymKeyDirect(key []byte) (string, error) {
|
||||
return w.waku.AddSymKeyDirect(key)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) AddSymKeyFromPassword(password string) (string, error) {
|
||||
return w.waku.AddSymKeyFromPassword(password)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) DeleteSymKey(id string) bool {
|
||||
return w.waku.DeleteSymKey(id)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) GetSymKey(id string) ([]byte, error) {
|
||||
return w.waku.GetSymKey(id)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) Subscribe(opts *types.SubscriptionOptions) (string, error) {
|
||||
var (
|
||||
err error
|
||||
keyAsym *ecdsa.PrivateKey
|
||||
keySym []byte
|
||||
)
|
||||
|
||||
if opts.SymKeyID != "" {
|
||||
keySym, err = w.GetSymKey(opts.SymKeyID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if opts.PrivateKeyID != "" {
|
||||
keyAsym, err = w.GetPrivateKey(opts.PrivateKeyID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
f, err := w.createFilterWrapper("", keyAsym, keySym, opts.PoW, opts.Topics)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
id, err := w.waku.Subscribe(GetWakuFilterFrom(f))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
f.(*wakuFilterWrapper).id = id
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) GetStats() types.StatsSummary {
|
||||
return w.waku.GetStats()
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) GetFilter(id string) types.Filter {
|
||||
return NewWakuFilterWrapper(w.waku.GetFilter(id), id)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) Unsubscribe(ctx context.Context, id string) error {
|
||||
return w.waku.Unsubscribe(id)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) UnsubscribeMany(ids []string) error {
|
||||
return w.waku.UnsubscribeMany(ids)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) createFilterWrapper(id string, keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, topics [][]byte) (types.Filter, error) {
|
||||
return NewWakuFilterWrapper(&wakucommon.Filter{
|
||||
KeyAsym: keyAsym,
|
||||
KeySym: keySym,
|
||||
PoW: pow,
|
||||
AllowP2P: true,
|
||||
Topics: topics,
|
||||
Messages: wakucommon.NewMemoryMessageStore(),
|
||||
}, id), nil
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) SendMessagesRequest(peerID []byte, r types.MessagesRequest) error {
|
||||
return w.waku.SendMessagesRequest(peerID, wakucommon.MessagesRequest{
|
||||
ID: r.ID,
|
||||
From: r.From,
|
||||
To: r.To,
|
||||
Limit: r.Limit,
|
||||
Cursor: r.Cursor,
|
||||
Bloom: r.Bloom,
|
||||
Topics: r.ContentTopics,
|
||||
})
|
||||
}
|
||||
|
||||
// RequestHistoricMessages sends a message with p2pRequestCode to a specific peer,
|
||||
// which is known to implement MailServer interface, and is supposed to process this
|
||||
// request and respond with a number of peer-to-peer messages (possibly expired),
|
||||
// which are not supposed to be forwarded any further.
|
||||
// The whisper protocol is agnostic of the format and contents of envelope.
|
||||
func (w *GethWakuWrapper) RequestHistoricMessagesWithTimeout(peerID []byte, envelope types.Envelope, timeout time.Duration) error {
|
||||
return w.waku.RequestHistoricMessagesWithTimeout(peerID, envelope.Unwrap().(*wakucommon.Envelope), timeout)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) ProcessingP2PMessages() bool {
|
||||
return w.waku.ProcessingP2PMessages()
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) MarkP2PMessageAsProcessed(hash common.Hash) {
|
||||
w.waku.MarkP2PMessageAsProcessed(hash)
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) RequestStoreMessages(ctx context.Context, peerID []byte, r types.MessagesRequest, processEnvelopes bool) (*types.StoreRequestCursor, int, error) {
|
||||
return nil, 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (w *GethWakuWrapper) ConnectionChanged(_ connection.State) {}
|
||||
|
||||
func (w *GethWakuWrapper) ClearEnvelopesCache() {
|
||||
w.waku.ClearEnvelopesCache()
|
||||
}
|
||||
|
||||
type wakuFilterWrapper struct {
|
||||
filter *wakucommon.Filter
|
||||
id string
|
||||
}
|
||||
|
||||
// NewWakuFilterWrapper returns an object that wraps Geth's Filter in a types interface
|
||||
func NewWakuFilterWrapper(f *wakucommon.Filter, id string) types.Filter {
|
||||
if f.Messages == nil {
|
||||
panic("Messages should not be nil")
|
||||
}
|
||||
|
||||
return &wakuFilterWrapper{
|
||||
filter: f,
|
||||
id: id,
|
||||
}
|
||||
}
|
||||
|
||||
// GetWakuFilterFrom retrieves the underlying whisper Filter struct from a wrapped Filter interface
|
||||
func GetWakuFilterFrom(f types.Filter) *wakucommon.Filter {
|
||||
return f.(*wakuFilterWrapper).filter
|
||||
}
|
||||
|
||||
// ID returns the filter ID
|
||||
func (w *wakuFilterWrapper) ID() string {
|
||||
return w.id
|
||||
}
|
||||
329
vendor/github.com/status-im/status-go/eth-node/bridge/geth/wakuv2.go
generated
vendored
Normal file
329
vendor/github.com/status-im/status-go/eth-node/bridge/geth/wakuv2.go
generated
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
package gethbridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol/store"
|
||||
storepb "github.com/waku-org/go-waku/waku/v2/protocol/store/pb"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/status-im/status-go/connection"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/wakuv2"
|
||||
wakucommon "github.com/status-im/status-go/wakuv2/common"
|
||||
)
|
||||
|
||||
type gethWakuV2Wrapper struct {
|
||||
waku *wakuv2.Waku
|
||||
}
|
||||
|
||||
// NewGethWakuWrapper returns an object that wraps Geth's Waku in a types interface
|
||||
func NewGethWakuV2Wrapper(w *wakuv2.Waku) types.Waku {
|
||||
if w == nil {
|
||||
panic("waku cannot be nil")
|
||||
}
|
||||
|
||||
return &gethWakuV2Wrapper{
|
||||
waku: w,
|
||||
}
|
||||
}
|
||||
|
||||
// GetGethWhisperFrom retrieves the underlying whisper Whisper struct from a wrapped Whisper interface
|
||||
func GetGethWakuV2From(m types.Waku) *wakuv2.Waku {
|
||||
return m.(*gethWakuV2Wrapper).waku
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) PublicWakuAPI() types.PublicWakuAPI {
|
||||
return NewGethPublicWakuV2APIWrapper(wakuv2.NewPublicWakuAPI(w.waku))
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) Version() uint {
|
||||
return 2
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) PeerCount() int {
|
||||
return w.waku.PeerCount()
|
||||
}
|
||||
|
||||
// DEPRECATED: Not used in WakuV2
|
||||
func (w *gethWakuV2Wrapper) MinPow() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// MaxMessageSize returns the MaxMessageSize set
|
||||
func (w *gethWakuV2Wrapper) MaxMessageSize() uint32 {
|
||||
return w.waku.MaxMessageSize()
|
||||
}
|
||||
|
||||
// DEPRECATED: not used in WakuV2
|
||||
func (w *gethWakuV2Wrapper) BloomFilter() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCurrentTime returns current time.
|
||||
func (w *gethWakuV2Wrapper) GetCurrentTime() time.Time {
|
||||
return w.waku.CurrentTime()
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) SubscribeEnvelopeEvents(eventsProxy chan<- types.EnvelopeEvent) types.Subscription {
|
||||
events := make(chan wakucommon.EnvelopeEvent, 100) // must be buffered to prevent blocking whisper
|
||||
go func() {
|
||||
for e := range events {
|
||||
eventsProxy <- *NewWakuV2EnvelopeEventWrapper(&e)
|
||||
}
|
||||
}()
|
||||
|
||||
return NewGethSubscriptionWrapper(w.waku.SubscribeEnvelopeEvents(events))
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) GetPrivateKey(id string) (*ecdsa.PrivateKey, error) {
|
||||
return w.waku.GetPrivateKey(id)
|
||||
}
|
||||
|
||||
// AddKeyPair imports a asymmetric private key and returns a deterministic identifier.
|
||||
func (w *gethWakuV2Wrapper) AddKeyPair(key *ecdsa.PrivateKey) (string, error) {
|
||||
return w.waku.AddKeyPair(key)
|
||||
}
|
||||
|
||||
// DeleteKeyPair deletes the key with the specified ID if it exists.
|
||||
func (w *gethWakuV2Wrapper) DeleteKeyPair(keyID string) bool {
|
||||
return w.waku.DeleteKeyPair(keyID)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) AddSymKeyDirect(key []byte) (string, error) {
|
||||
return w.waku.AddSymKeyDirect(key)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) AddSymKeyFromPassword(password string) (string, error) {
|
||||
return w.waku.AddSymKeyFromPassword(password)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) DeleteSymKey(id string) bool {
|
||||
return w.waku.DeleteSymKey(id)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) GetSymKey(id string) ([]byte, error) {
|
||||
return w.waku.GetSymKey(id)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) Subscribe(opts *types.SubscriptionOptions) (string, error) {
|
||||
var (
|
||||
err error
|
||||
keyAsym *ecdsa.PrivateKey
|
||||
keySym []byte
|
||||
)
|
||||
|
||||
if opts.SymKeyID != "" {
|
||||
keySym, err = w.GetSymKey(opts.SymKeyID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
if opts.PrivateKeyID != "" {
|
||||
keyAsym, err = w.GetPrivateKey(opts.PrivateKeyID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
f, err := w.createFilterWrapper("", keyAsym, keySym, opts.PoW, opts.PubsubTopic, opts.Topics)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
id, err := w.waku.Subscribe(GetWakuV2FilterFrom(f))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
f.(*wakuV2FilterWrapper).id = id
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) GetStats() types.StatsSummary {
|
||||
return w.waku.GetStats()
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) GetFilter(id string) types.Filter {
|
||||
return NewWakuV2FilterWrapper(w.waku.GetFilter(id), id)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) Unsubscribe(ctx context.Context, id string) error {
|
||||
return w.waku.Unsubscribe(ctx, id)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) UnsubscribeMany(ids []string) error {
|
||||
return w.waku.UnsubscribeMany(ids)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) createFilterWrapper(id string, keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, pubsubTopic string, topics [][]byte) (types.Filter, error) {
|
||||
return NewWakuV2FilterWrapper(&wakucommon.Filter{
|
||||
KeyAsym: keyAsym,
|
||||
KeySym: keySym,
|
||||
ContentTopics: wakucommon.NewTopicSetFromBytes(topics),
|
||||
PubsubTopic: pubsubTopic,
|
||||
Messages: wakucommon.NewMemoryMessageStore(),
|
||||
}, id), nil
|
||||
}
|
||||
|
||||
// DEPRECATED: Not used in waku V2
|
||||
func (w *gethWakuV2Wrapper) SendMessagesRequest(peerID []byte, r types.MessagesRequest) error {
|
||||
return errors.New("DEPRECATED")
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) RequestStoreMessages(ctx context.Context, peerID []byte, r types.MessagesRequest, processEnvelopes bool) (*types.StoreRequestCursor, int, error) {
|
||||
var options []store.HistoryRequestOption
|
||||
|
||||
peer, err := peer.Decode(string(peerID))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
options = []store.HistoryRequestOption{
|
||||
store.WithPaging(false, uint64(r.Limit)),
|
||||
}
|
||||
|
||||
if r.StoreCursor != nil {
|
||||
options = append(options, store.WithCursor(&storepb.Index{
|
||||
Digest: r.StoreCursor.Digest,
|
||||
ReceiverTime: r.StoreCursor.ReceiverTime,
|
||||
SenderTime: r.StoreCursor.SenderTime,
|
||||
PubsubTopic: r.StoreCursor.PubsubTopic,
|
||||
}))
|
||||
}
|
||||
|
||||
var contentTopics []wakucommon.TopicType
|
||||
for _, topic := range r.ContentTopics {
|
||||
contentTopics = append(contentTopics, wakucommon.BytesToTopic(topic))
|
||||
}
|
||||
|
||||
pbCursor, envelopesCount, err := w.waku.Query(ctx, peer, r.PubsubTopic, contentTopics, uint64(r.From), uint64(r.To), options, processEnvelopes)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if pbCursor != nil {
|
||||
return &types.StoreRequestCursor{
|
||||
Digest: pbCursor.Digest,
|
||||
ReceiverTime: pbCursor.ReceiverTime,
|
||||
SenderTime: pbCursor.SenderTime,
|
||||
PubsubTopic: pbCursor.PubsubTopic,
|
||||
}, envelopesCount, nil
|
||||
}
|
||||
|
||||
return nil, envelopesCount, nil
|
||||
}
|
||||
|
||||
// DEPRECATED: Not used in waku V2
|
||||
func (w *gethWakuV2Wrapper) RequestHistoricMessagesWithTimeout(peerID []byte, envelope types.Envelope, timeout time.Duration) error {
|
||||
return errors.New("DEPRECATED")
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) StartDiscV5() error {
|
||||
return w.waku.StartDiscV5()
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) StopDiscV5() error {
|
||||
return w.waku.StopDiscV5()
|
||||
}
|
||||
|
||||
// Subscribe to a pubsub topic, passing an optional public key if the pubsub topic is protected
|
||||
func (w *gethWakuV2Wrapper) SubscribeToPubsubTopic(topic string, optPublicKey *ecdsa.PublicKey) error {
|
||||
return w.waku.SubscribeToPubsubTopic(topic, optPublicKey)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) UnsubscribeFromPubsubTopic(topic string) error {
|
||||
return w.waku.UnsubscribeFromPubsubTopic(topic)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) RetrievePubsubTopicKey(topic string) (*ecdsa.PrivateKey, error) {
|
||||
return w.waku.RetrievePubsubTopicKey(topic)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) StorePubsubTopicKey(topic string, privKey *ecdsa.PrivateKey) error {
|
||||
return w.waku.StorePubsubTopicKey(topic, privKey)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) RemovePubsubTopicKey(topic string) error {
|
||||
return w.waku.RemovePubsubTopicKey(topic)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) AddStorePeer(address string) (peer.ID, error) {
|
||||
return w.waku.AddStorePeer(address)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) AddRelayPeer(address string) (peer.ID, error) {
|
||||
return w.waku.AddRelayPeer(address)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) Peers() map[string]types.WakuV2Peer {
|
||||
return w.waku.Peers()
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) DialPeer(address string) error {
|
||||
return w.waku.DialPeer(address)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) DialPeerByID(peerID string) error {
|
||||
return w.waku.DialPeerByID(peerID)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) ListenAddresses() ([]string, error) {
|
||||
return w.waku.ListenAddresses(), nil
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) DropPeer(peerID string) error {
|
||||
return w.waku.DropPeer(peerID)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) ProcessingP2PMessages() bool {
|
||||
return w.waku.ProcessingP2PMessages()
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) MarkP2PMessageAsProcessed(hash common.Hash) {
|
||||
w.waku.MarkP2PMessageAsProcessed(hash)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) SubscribeToConnStatusChanges() (*types.ConnStatusSubscription, error) {
|
||||
return w.waku.SubscribeToConnStatusChanges(), nil
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) ConnectionChanged(state connection.State) {
|
||||
w.waku.ConnectionChanged(state)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) ClearEnvelopesCache() {
|
||||
w.waku.ClearEnvelopesCache()
|
||||
}
|
||||
|
||||
type wakuV2FilterWrapper struct {
|
||||
filter *wakucommon.Filter
|
||||
id string
|
||||
}
|
||||
|
||||
// NewWakuFilterWrapper returns an object that wraps Geth's Filter in a types interface
|
||||
func NewWakuV2FilterWrapper(f *wakucommon.Filter, id string) types.Filter {
|
||||
if f.Messages == nil {
|
||||
panic("Messages should not be nil")
|
||||
}
|
||||
|
||||
return &wakuV2FilterWrapper{
|
||||
filter: f,
|
||||
id: id,
|
||||
}
|
||||
}
|
||||
|
||||
// GetWakuFilterFrom retrieves the underlying whisper Filter struct from a wrapped Filter interface
|
||||
func GetWakuV2FilterFrom(f types.Filter) *wakucommon.Filter {
|
||||
return f.(*wakuV2FilterWrapper).filter
|
||||
}
|
||||
|
||||
// ID returns the filter ID
|
||||
func (w *wakuV2FilterWrapper) ID() string {
|
||||
return w.id
|
||||
}
|
||||
Reference in New Issue
Block a user