|
1 | 1 | package controllers
|
2 | 2 |
|
3 |
| -import ( |
4 |
| - "crypto/rand" |
5 |
| - "encoding/base64" |
6 |
| - "encoding/hex" |
7 |
| - "fmt" |
| 3 | +// ci "github.com/libp2p/go-libp2p-core/crypto" |
| 4 | +// peer "github.com/libp2p/go-libp2p-core/peer" |
8 | 5 |
|
9 |
| - ci "github.com/libp2p/go-libp2p-core/crypto" |
10 |
| - peer "github.com/libp2p/go-libp2p-core/peer" |
11 |
| -) |
| 6 | +// func newClusterSecret() (string, error) { |
| 7 | +// const secretLen = 32 |
| 8 | +// buf := make([]byte, secretLen) |
| 9 | +// _, err := rand.Read(buf) |
| 10 | +// if err != nil { |
| 11 | +// return "", err |
| 12 | +// } |
| 13 | +// return hex.EncodeToString(buf), nil |
| 14 | +// } |
12 | 15 |
|
13 |
| -func newClusterSecret() (string, error) { |
14 |
| - const secretLen = 32 |
15 |
| - buf := make([]byte, secretLen) |
16 |
| - _, err := rand.Read(buf) |
17 |
| - if err != nil { |
18 |
| - return "", err |
19 |
| - } |
20 |
| - return hex.EncodeToString(buf), nil |
21 |
| -} |
| 16 | +// // newKey Generates a new private key and returns that along with the identity. |
| 17 | +// func newKey() (ci.PrivKey, peer.ID, error) { |
| 18 | +// const edDSAKeyLen = 4096 |
| 19 | +// priv, pub, err := ci.GenerateKeyPair(ci.Ed25519, edDSAKeyLen) |
| 20 | +// if err != nil { |
| 21 | +// return nil, "", err |
| 22 | +// } |
| 23 | +// peerid, err := peer.IDFromPublicKey(pub) |
| 24 | +// if err != nil { |
| 25 | +// return nil, "", err |
| 26 | +// } |
| 27 | +// return priv, peerid, nil |
| 28 | +// } |
22 | 29 |
|
23 |
| -// newKey Generates a new private key and returns that along with the identity. |
24 |
| -func newKey() (ci.PrivKey, peer.ID, error) { |
25 |
| - const edDSAKeyLen = 4096 |
26 |
| - priv, pub, err := ci.GenerateKeyPair(ci.Ed25519, edDSAKeyLen) |
27 |
| - if err != nil { |
28 |
| - return nil, "", err |
29 |
| - } |
30 |
| - peerid, err := peer.IDFromPublicKey(pub) |
31 |
| - if err != nil { |
32 |
| - return nil, "", err |
33 |
| - } |
34 |
| - return priv, peerid, nil |
35 |
| -} |
36 |
| - |
37 |
| -// generateIdentity Generates a new key and returns the peer ID and private key |
38 |
| -// encoded as a base64 string using standard encoding, or an error if the key could not be generated. |
39 |
| -func generateIdentity() (peer.ID, string, error) { |
40 |
| - priv, peerid, err := newKey() |
41 |
| - if err != nil { |
42 |
| - return "", "", fmt.Errorf("cannot generate new key: %w", err) |
43 |
| - } |
44 |
| - privBytes, err := ci.MarshalPrivateKey(priv) |
45 |
| - if err != nil { |
46 |
| - return "", "", fmt.Errorf("cannot get bytes from private key: %w", err) |
47 |
| - } |
48 |
| - privStr := base64.StdEncoding.EncodeToString(privBytes) |
49 |
| - return peerid, privStr, nil |
50 |
| -} |
| 30 | +// // generateIdentity Generates a new key and returns the peer ID and private key |
| 31 | +// // encoded as a base64 string using standard encoding, or an error if the key could not be generated. |
| 32 | +// func generateIdentity() (peer.ID, string, error) { |
| 33 | +// priv, peerid, err := newKey() |
| 34 | +// if err != nil { |
| 35 | +// return "", "", fmt.Errorf("cannot generate new key: %w", err) |
| 36 | +// } |
| 37 | +// privBytes, err := ci.MarshalPrivateKey(priv) |
| 38 | +// if err != nil { |
| 39 | +// return "", "", fmt.Errorf("cannot get bytes from private key: %w", err) |
| 40 | +// } |
| 41 | +// privStr := base64.StdEncoding.EncodeToString(privBytes) |
| 42 | +// return peerid, privStr, nil |
| 43 | +// } |
0 commit comments