Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change new identity keys to hex format #2773

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading