fix: pubkey marshalling

This commit is contained in:
Richard Ramos 2022-04-25 15:27:40 +04:00
parent 85ba54f24f
commit fe50f12ac9
3 changed files with 29 additions and 6 deletions

View File

@ -207,8 +207,8 @@ func insertShhExtConfig(tx *sql.Tx, c *params.NodeConfig) error {
return err
}
for _, pubKey := range c.ShhextConfig.DefaultPushNotificationsServers {
hexpubk := hexutil.Encode(crypto.FromECDSAPub(pubKey))
for _, pushNotifServ := range c.ShhextConfig.DefaultPushNotificationsServers {
hexpubk := hexutil.Encode(crypto.FromECDSAPub(pushNotifServ.PublicKey))
_, err := tx.Exec(`INSERT OR REPLACE INTO shhext_default_push_notification_servers (public_key, synthetic_id) VALUES (?, 'id')`, hexpubk)
if err != nil {
return err
@ -637,7 +637,7 @@ func loadNodeConfig(tx *sql.Tx) (*params.NodeConfig, error) {
if err != nil {
return nil, err
}
nodecfg.ShhextConfig.DefaultPushNotificationsServers = append(nodecfg.ShhextConfig.DefaultPushNotificationsServers, pubKey)
nodecfg.ShhextConfig.DefaultPushNotificationsServers = append(nodecfg.ShhextConfig.DefaultPushNotificationsServers, &params.PushNotificationServer{PublicKey: pubKey})
}
}

View File

@ -539,6 +539,24 @@ type BridgeConfig struct {
Enabled bool
}
type PushNotificationServer struct {
*ecdsa.PublicKey
}
func (p *PushNotificationServer) MarshalText() ([]byte, error) {
return []byte(hex.EncodeToString(crypto.FromECDSAPub(p.PublicKey))), nil
}
func (p *PushNotificationServer) UnmarshalText(data []byte) error {
pk, err := crypto.UnmarshalPubkey(data)
if err != nil {
return err
}
p.PublicKey = pk
return nil
}
// ShhextConfig defines options used by shhext service.
type ShhextConfig struct {
PFSEnabled bool
@ -590,7 +608,7 @@ type ShhextConfig struct {
VerifyTransactionChainID int64
// DefaultPushNotificationsServers is the default-status run push notification servers
DefaultPushNotificationsServers []*ecdsa.PublicKey
DefaultPushNotificationsServers []*PushNotificationServer
// AnonMetricsSendID is the public key used by a metrics node to decrypt metrics protobufs
AnonMetricsSendID string
@ -722,7 +740,7 @@ func (c *NodeConfig) setDefaultPushNotificationsServers() error {
if err != nil {
return err
}
c.ShhextConfig.DefaultPushNotificationsServers = append(c.ShhextConfig.DefaultPushNotificationsServers, key)
c.ShhextConfig.DefaultPushNotificationsServers = append(c.ShhextConfig.DefaultPushNotificationsServers, &PushNotificationServer{PublicKey: key})
}
}
return nil

View File

@ -464,8 +464,13 @@ func buildMessengerOptions(
options = append(options, protocol.WithPushNotificationServerConfig(config))
}
var pushNotifServKey []*ecdsa.PublicKey
for _, d := range config.ShhextConfig.DefaultPushNotificationsServers {
pushNotifServKey = append(pushNotifServKey, d.PublicKey)
}
options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{
DefaultServers: config.ShhextConfig.DefaultPushNotificationsServers,
DefaultServers: pushNotifServKey,
BlockMentions: settings.PushNotificationsBlockMentions,
SendEnabled: settings.SendPushNotifications,
AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly,