Skip to content

Commit

Permalink
fix client create account signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Feb 20, 2025
1 parent 7ceeea7 commit 8b90b30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 5 additions & 3 deletions node-registrar/client/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"bytes"
"crypto/ed25519"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions node-registrar/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
1 change: 0 additions & 1 deletion node-registrar/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8b90b30

Please sign in to comment.