diff --git a/node-registrar/client/account.go b/node-registrar/client/account.go index 4c6af57..3e44296 100644 --- a/node-registrar/client/account.go +++ b/node-registrar/client/account.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "crypto/ed25519" "encoding/base64" "encoding/json" "fmt" @@ -40,13 +41,14 @@ func (c *RegistrarClient) createAccount(relays []string, rmbEncKey string) (acco return account, errors.Wrap(err, "failed to construct registrar url") } + timestamp := time.Now().Unix() publicKeyBase64 := base64.StdEncoding.EncodeToString(c.keyPair.publicKey) - timestamp := time.Now().Unix() - signature := c.signRequest(timestamp) + challenge := []byte(fmt.Sprintf("%d:%v", timestamp, publicKeyBase64)) + signature := ed25519.Sign(c.keyPair.privateKey, challenge) data := map[string]any{ - "public_key": publicKeyBase64, + "public_key": c.keyPair.publicKey, "signature": signature, "timestamp": timestamp, "rmb_enc_key": rmbEncKey, diff --git a/node-registrar/client/client.go b/node-registrar/client/client.go index 3be0d11..7e5c41a 100644 --- a/node-registrar/client/client.go +++ b/node-registrar/client/client.go @@ -20,11 +20,11 @@ type RegistrarClient struct { baseURL string } -func NewRegistrarClient(baseURL string, privateKey []byte) (cli RegistrarClient, err error) { +func NewRegistrarClient(baseURL string, sk []byte) (cli RegistrarClient, err error) { client := http.DefaultClient - sk := ed25519.NewKeyFromSeed(privateKey) - publicKey, ok := sk.Public().(ed25519.PublicKey) + privateKey := ed25519.NewKeyFromSeed(sk) + publicKey, ok := privateKey.Public().(ed25519.PublicKey) if !ok { return cli, errors.Wrap(err, "failed to get public key of provided private key") } diff --git a/node-registrar/client/utils.go b/node-registrar/client/utils.go index a56657f..3cf3995 100644 --- a/node-registrar/client/utils.go +++ b/node-registrar/client/utils.go @@ -12,7 +12,6 @@ import ( func (c RegistrarClient) signRequest(timestamp int64) (authHeader string) { challenge := []byte(fmt.Sprintf("%d:%v", timestamp, c.twinID)) - signature := ed25519.Sign(c.keyPair.privateKey, challenge) authHeader = fmt.Sprintf(