From 7e5bb6a1d88aa40152b3319c90bd0cb7130303c5 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Tue, 25 Jun 2024 13:58:02 -0400 Subject: [PATCH 1/3] PR: Change the keys to HEX formats --- acp/identity/generate.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/acp/identity/generate.go b/acp/identity/generate.go index 11c9188ff0..cf37ce6e46 100644 --- a/acp/identity/generate.go +++ b/acp/identity/generate.go @@ -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 } @@ -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 } From 31d857e9f1e20962ef37eff3b249a7cfa2e2fdce Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Tue, 25 Jun 2024 14:08:26 -0400 Subject: [PATCH 2/3] PR: Add documentation about key encoding. --- cli/identity_new.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/identity_new.go b/cli/identity_new.go index cd903979fc..e7101c1bae 100644 --- a/cli/identity_new.go +++ b/cli/identity_new.go @@ -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 From cfaf40e55b08b2350ce1fed08aedadfe60f9ff05 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Tue, 25 Jun 2024 14:09:12 -0400 Subject: [PATCH 3/3] PR(DOCS): Make cli docs --- docs/website/references/cli/defradb_identity_new.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/website/references/cli/defradb_identity_new.md b/docs/website/references/cli/defradb_identity_new.md index dd8cf0af7b..24a995e8f8 100644 --- a/docs/website/references/cli/defradb_identity_new.md +++ b/docs/website/references/cli/defradb_identity_new.md @@ -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