diff --git a/cmd/replication/main.go b/cmd/replication/main.go index 467f97d4..1028f77a 100644 --- a/cmd/replication/main.go +++ b/cmd/replication/main.go @@ -14,6 +14,7 @@ import ( "github.com/xmtp/xmtpd/pkg/registry" "github.com/xmtp/xmtpd/pkg/server" "github.com/xmtp/xmtpd/pkg/tracing" + "github.com/xmtp/xmtpd/pkg/utils" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -46,15 +47,32 @@ func main() { options.DB.WaitForDB, options.DB.ReadTimeout, ) + if err != nil { log.Fatal("initializing database", zap.Error(err)) } + privateKey, err := utils.ParseEcdsaPrivateKey(options.SignerPrivateKey) + if err != nil { + log.Fatal("parsing private key", zap.Error(err)) + } + s, err := server.NewReplicationServer( ctx, log, options, - registry.NewFixedNodeRegistry([]registry.Node{}), + // TODO:nm replace with real node + registry.NewFixedNodeRegistry( + []registry.Node{ + { + NodeID: 0, + SigningKey: &privateKey.PublicKey, + IsHealthy: true, + HttpAddress: "http://example.com", + IsValidConfig: true, + }, + }, + ), db, ) if err != nil { diff --git a/pkg/registrant/registrant.go b/pkg/registrant/registrant.go index 38fdb458..c0c9319b 100644 --- a/pkg/registrant/registrant.go +++ b/pkg/registrant/registrant.go @@ -6,7 +6,6 @@ import ( "crypto/ecdsa" "fmt" "slices" - "strings" "github.com/ethereum/go-ethereum/crypto" "github.com/xmtp/xmtpd/pkg/db/queries" @@ -28,7 +27,7 @@ func NewRegistrant( nodeRegistry registry.NodeRegistry, privateKeyString string, ) (*Registrant, error) { - privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(privateKeyString, "0x")) + privateKey, err := utils.PrivateKeyFromString(privateKeyString) if err != nil { return nil, fmt.Errorf("unable to parse private key: %v", err) } diff --git a/pkg/utils/keys.go b/pkg/utils/keys.go new file mode 100644 index 00000000..c29a83b0 --- /dev/null +++ b/pkg/utils/keys.go @@ -0,0 +1,12 @@ +package utils + +import ( + "crypto/ecdsa" + "strings" + + "github.com/ethereum/go-ethereum/crypto" +) + +func ParseEcdsaPrivateKey(key string) (*ecdsa.PrivateKey, error) { + return crypto.HexToECDSA(strings.TrimPrefix(key, "0x")) +}