Skip to content

Commit 8b90b30

Browse files
committed
fix client create account signature
1 parent 7ceeea7 commit 8b90b30

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

node-registrar/client/account.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package client
22

33
import (
44
"bytes"
5+
"crypto/ed25519"
56
"encoding/base64"
67
"encoding/json"
78
"fmt"
@@ -40,13 +41,14 @@ func (c *RegistrarClient) createAccount(relays []string, rmbEncKey string) (acco
4041
return account, errors.Wrap(err, "failed to construct registrar url")
4142
}
4243

44+
timestamp := time.Now().Unix()
4345
publicKeyBase64 := base64.StdEncoding.EncodeToString(c.keyPair.publicKey)
4446

45-
timestamp := time.Now().Unix()
46-
signature := c.signRequest(timestamp)
47+
challenge := []byte(fmt.Sprintf("%d:%v", timestamp, publicKeyBase64))
48+
signature := ed25519.Sign(c.keyPair.privateKey, challenge)
4749

4850
data := map[string]any{
49-
"public_key": publicKeyBase64,
51+
"public_key": c.keyPair.publicKey,
5052
"signature": signature,
5153
"timestamp": timestamp,
5254
"rmb_enc_key": rmbEncKey,

node-registrar/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type RegistrarClient struct {
2020
baseURL string
2121
}
2222

23-
func NewRegistrarClient(baseURL string, privateKey []byte) (cli RegistrarClient, err error) {
23+
func NewRegistrarClient(baseURL string, sk []byte) (cli RegistrarClient, err error) {
2424
client := http.DefaultClient
2525

26-
sk := ed25519.NewKeyFromSeed(privateKey)
27-
publicKey, ok := sk.Public().(ed25519.PublicKey)
26+
privateKey := ed25519.NewKeyFromSeed(sk)
27+
publicKey, ok := privateKey.Public().(ed25519.PublicKey)
2828
if !ok {
2929
return cli, errors.Wrap(err, "failed to get public key of provided private key")
3030
}

node-registrar/client/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
func (c RegistrarClient) signRequest(timestamp int64) (authHeader string) {
1414
challenge := []byte(fmt.Sprintf("%d:%v", timestamp, c.twinID))
15-
1615
signature := ed25519.Sign(c.keyPair.privateKey, challenge)
1716

1817
authHeader = fmt.Sprintf(

0 commit comments

Comments
 (0)