Skip to content

Commit

Permalink
fix: pubkey marshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Apr 25, 2022
1 parent 85ba54f commit fe50f12
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 3 additions & 3 deletions nodecfg/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
}
}

Expand Down
22 changes: 20 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion services/ext/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fe50f12

Please sign in to comment.