From ff1d800a279ab1c7a73e6a3a2a2bb8738f566b7c Mon Sep 17 00:00:00 2001 From: Lars Bahner Date: Wed, 24 Apr 2024 01:51:59 +0200 Subject: [PATCH] Fix erroneous DID for keys --- did/doc/document.go | 8 -------- key/encryption.go | 4 ++-- key/signing.go | 7 +++++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/did/doc/document.go b/did/doc/document.go index 2df5b4c..1f7a0ca 100644 --- a/did/doc/document.go +++ b/did/doc/document.go @@ -113,11 +113,3 @@ func compareSlices(a []string, b []string) bool { return slices.Compare(a, b) == 0 } - -// func (d *Document) Path() path.Path { -// return d.immutablePath -// } - -// func (d *Document) DID() did.DID { -// return d.did -// } diff --git a/key/encryption.go b/key/encryption.go index fe8826f..dcf13de 100644 --- a/key/encryption.go +++ b/key/encryption.go @@ -31,8 +31,8 @@ func NewEncryptionKey(d did.DID) (EncryptionKey, error) { return EncryptionKey{}, fmt.Errorf("NewEncryptionKey: %w", err) } - // We just mangle the base DID as this is not a pointer to a DID. - d.Fragment = name + // Create a unique identifier for the key + d = did.New(d.IPNSName(), name) // Generate a random private key var privKey [curve25519.ScalarSize]byte diff --git a/key/signing.go b/key/signing.go index 8a33a12..c9a8bbb 100644 --- a/key/signing.go +++ b/key/signing.go @@ -10,6 +10,7 @@ import ( mf "github.com/bahner/go-ma/utils" nanoid "github.com/matoous/go-nanoid/v2" "github.com/multiformats/go-multicodec" + log "github.com/sirupsen/logrus" ) const ( @@ -41,8 +42,10 @@ func NewSigningKey(d did.DID) (SigningKey, error) { if err != nil { return SigningKey{}, fmt.Errorf("NewSigningKey: %w", err) } - // We just mangle the base DID as this is not a pointer to a DID. - d.Fragment = name + + // Create a unique identifier for the key + d = did.New(d.IPNSName(), name) + log.Info("Created new DID: ", d) publicKey, privKey, err := ed25519.GenerateKey(rand.Reader) if err != nil {