Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Nov 20, 2023
1 parent 4c446ae commit 99c4597
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions vdr/didnuts/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/nuts-foundation/go-did/did"

crypto2 "github.com/nuts-foundation/nuts-node/crypto"
nutsCrypto "github.com/nuts-foundation/nuts-node/crypto"
)

// MethodName is the DID method name used by Nuts
Expand Down Expand Up @@ -62,7 +62,7 @@ func CreateDocument() did.Document {
// Creator implements the DocCreator interface and can create Nuts DID Documents.
type Creator struct {
// KeyStore is used for getting a fresh key and use it to generate the Nuts DID
KeyStore crypto2.KeyCreator
KeyStore nutsCrypto.KeyCreator
}

// DefaultCreationOptions returns the default DIDCreationOptions when creating DID Documents.
Expand All @@ -77,14 +77,14 @@ func DefaultCreationOptions() management.DIDCreationOptions {

// didKIDNamingFunc is a function used to name a key used in newly generated DID Documents.
func didKIDNamingFunc(pKey crypto.PublicKey) (string, error) {
return getKIDName(pKey, crypto2.Thumbprint)
return getKIDName(pKey, nutsCrypto.Thumbprint)
}

// didSubKIDNamingFunc returns a KIDNamingFunc that can be used as param in the KeyStore.New function.
// It wraps the KIDNamingFunc with the context of the DID of the document.
// It returns a keyID in the form of the documents DID with the new keys thumbprint as fragment.
// E.g. for a assertionMethod key that differs from the key the DID document was created with.
func didSubKIDNamingFunc(owningDID did.DID) crypto2.KIDNamingFunc {
func didSubKIDNamingFunc(owningDID did.DID) nutsCrypto.KIDNamingFunc {
return func(pKey crypto.PublicKey) (string, error) {
return getKIDName(pKey, func(_ jwk.Key) (string, error) {
return owningDID.ID, nil
Expand Down Expand Up @@ -127,14 +127,14 @@ var ErrInvalidOptions = errors.New("create request has invalid combination of op

// Create creates a Nuts DID Document with a valid DID id based on a freshly generated keypair.
// The key is added to the verificationMethod list and referred to from the Authentication list
func (n Creator) Create(ctx context.Context, options management.DIDCreationOptions) (*did.Document, crypto2.Key, error) {
func (n Creator) Create(ctx context.Context, options management.DIDCreationOptions) (*did.Document, nutsCrypto.Key, error) {
// Validate verification method type and derive key type
keyType, err := cryptoKeyType(options.VerificationMethodType)
if err != nil {
return nil, nil, err
}

var key crypto2.Key
var key nutsCrypto.Key

if options.SelfControl && !options.KeyFlags.Is(management.CapabilityInvocationUsage) {
return nil, nil, ErrInvalidOptions
Expand Down Expand Up @@ -215,17 +215,17 @@ func applyKeyUsage(document *did.Document, keyToAdd *did.VerificationMethod, int
}
}

func cryptoKeyType(verificationMethodType ssi.KeyType) (crypto2.KeyType, error) {
var keyType crypto2.KeyType
func cryptoKeyType(verificationMethodType ssi.KeyType) (nutsCrypto.KeyType, error) {
var keyType nutsCrypto.KeyType
switch verificationMethodType {
case ssi.JsonWebKey2020:
keyType = crypto2.ECP256Key
keyType = nutsCrypto.ECP256Key
case ssi.ECDSASECP256K1VerificationKey2019:
keyType = crypto2.ECP256k1Key
keyType = nutsCrypto.ECP256k1Key
case ssi.ED25519VerificationKey2018:
keyType = crypto2.Ed25519Key
keyType = nutsCrypto.Ed25519Key
case ssi.RSAVerificationKey2018:
keyType = crypto2.RSA2048Key
keyType = nutsCrypto.RSA2048Key
default:
return "", fmt.Errorf("unsupported verification method type: %s", verificationMethodType)
}
Expand Down

0 comments on commit 99c4597

Please sign in to comment.