Skip to content

Commit

Permalink
fix: Change new identity keys to hex format (#2773)
Browse files Browse the repository at this point in the history
## Relevant issue(s)
Resolves #2770 

## Description
- Return the priv/pub keys in hex

Specify the platform(s) on which this was tested:
- WSL2
  • Loading branch information
shahzadlone authored Jun 25, 2024
1 parent a9f8dee commit 0a0657f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
21 changes: 13 additions & 8 deletions acp/identity/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@

package identity

import "github.com/sourcenetwork/defradb/crypto"
import (
"encoding/hex"

"github.com/sourcenetwork/defradb/crypto"
)

// RawIdentity holds the raw bytes that make up an actor's identity.
type RawIdentity struct {
// An actor's private key.
PrivateKey []byte
// PrivateKey is a secp256k1 private key that is a 256-bit big-endian
// binary-encoded number, padded to a length of 32 bytes in HEX format.
PrivateKey string

// An actor's corresponding public key address.
PublicKey []byte
// PublicKey is a compressed 33-byte secp256k1 public key in HEX format.
PublicKey string

// An actor's DID. Generated from the public key address.
// DID is `did:key` key generated from the public key address.
DID string
}

Expand All @@ -43,8 +48,8 @@ func Generate() (RawIdentity, error) {
newIdentity := maybeNewIdentity.Value()

return RawIdentity{
PrivateKey: newIdentity.PrivateKey.Serialize(),
PublicKey: newIdentity.PublicKey.SerializeUncompressed(),
PrivateKey: hex.EncodeToString(newIdentity.PrivateKey.Serialize()),
PublicKey: hex.EncodeToString(newIdentity.PublicKey.SerializeCompressed()),
DID: newIdentity.DID,
}, nil
}
6 changes: 6 additions & 0 deletions cli/identity_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func MakeIdentityNewCommand() *cobra.Command {
Short: "Generate a new identity",
Long: `Generate a new identity
The generated identity contains:
- A secp256k1 private key that is a 256-bit big-endian binary-encoded number,
padded to a length of 32 bytes in HEX format.
- A compressed 33-byte secp256k1 public key in HEX format.
- A "did:key" generated from the public key.
Example: generate a new identity:
defradb identity new
Expand Down
6 changes: 6 additions & 0 deletions docs/website/references/cli/defradb_identity_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Generate a new identity

Generate a new identity

The generated identity contains:
- A secp256k1 private key that is a 256-bit big-endian binary-encoded number,
padded to a length of 32 bytes in HEX format.
- A compressed 33-byte secp256k1 public key in HEX format.
- A "did:key" generated from the public key.

Example: generate a new identity:
defradb identity new

Expand Down

0 comments on commit 0a0657f

Please sign in to comment.