Skip to content

Commit

Permalink
expose it in cmd flags and API
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Oct 26, 2023
1 parent eb7c635 commit 36056b2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions crypto/util/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ var oidNamedCurveP256k1 = asn1.ObjectIdentifier{1, 3, 132, 0, 10}
var oidPublicKeyECDSA = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1}

type asn1PKCS8Container struct {
Algo pkix.AlgorithmIdentifier
Data []byte
Version int
Algo pkix.AlgorithmIdentifier
Data []byte
}

type asn1ECPrivateKey struct {
Expand Down
5 changes: 4 additions & 1 deletion vdr/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (a *Wrapper) AddNewVerificationMethod(ctx context.Context, request AddNewVe
if request.Body.Type == nil {
verificationMethodType = ssi.JsonWebKey2020
} else {
verificationMethodType = *request.Body.Type
verificationMethodType = ssi.KeyType(*request.Body.Type)
}
vm, err := a.DocManipulator.AddVerificationMethod(ctx, *d, opts.ToFlags(didnuts.DefaultCreationOptions().KeyFlags), verificationMethodType)
if err != nil {
Expand Down Expand Up @@ -136,6 +136,9 @@ func (a *Wrapper) CreateDID(ctx context.Context, request CreateDIDRequestObject)
if request.Body.SelfControl != nil {
options.SelfControl = *request.Body.SelfControl
}
if request.Body.Type != nil {
options.VerificationMethodType = ssi.KeyType(*request.Body.Type)
}

doc, _, err := a.VDR.Create(ctx, options)
// if this operation leads to an error, it may return a 500
Expand Down
3 changes: 1 addition & 2 deletions vdr/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package v1

import (
ssi "github.com/nuts-foundation/go-did"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/vdr/management"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
Expand Down Expand Up @@ -64,7 +63,7 @@ type VerificationMethodRelationship struct {
KeyAgreement *bool `json:"keyAgreement,omitempty"`

// KeyType is the type of key to generate.
Type *ssi.KeyType `json:"verificationMethodType,omitempty"`
Type *string `json:"verificationMethodType,omitempty"`
}

// ToFlags takes default key flags, and enabled/disables the flags which are set on the VerificationMethodRelationship,
Expand Down
2 changes: 2 additions & 0 deletions vdr/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func createCmd() *cobra.Command {
CapabilityDelegation: new(bool),
CapabilityInvocation: new(bool),
KeyAgreement: new(bool),
Type: new(string),
},
Controllers: new([]string),
SelfControl: new(bool),
Expand Down Expand Up @@ -107,6 +108,7 @@ func createCmd() *cobra.Command {
result.Flags().BoolVar(createRequest.KeyAgreement, "keyAgreement", defs.KeyFlags.Is(management.KeyAgreementUsage), setUsage(defs.KeyFlags.Is(management.KeyAgreementUsage), "Pass '%t' to %s keyAgreement capabilities."))
result.Flags().BoolVar(createRequest.SelfControl, "selfControl", defs.SelfControl, setUsage(defs.SelfControl, "Pass '%t' to %s DID Document control."))
result.Flags().StringSliceVar(createRequest.Controllers, "controllers", []string{}, "Comma-separated list of DIDs that can control the generated DID Document.")
result.Flags().StringVar(createRequest.Type, "verificationMethodType", string(defs.VerificationMethodType), "The type of key to generate. Valid values are: JsonWebKey2020, EcdsaSecp256k1VerificationKey2019, Ed25519VerificationKey2018, RsaVerificationKey2018")

return result
}
Expand Down
7 changes: 4 additions & 3 deletions vdr/didnuts/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ type Creator struct {
// DefaultCreationOptions returns the default DIDCreationOptions when creating DID Documents.
func DefaultCreationOptions() management.DIDCreationOptions {
return management.DIDCreationOptions{
Controllers: []did.DID{},
KeyFlags: management.AssertionMethodUsage | management.CapabilityInvocationUsage | management.KeyAgreementUsage,
SelfControl: true,
Controllers: []did.DID{},
KeyFlags: management.AssertionMethodUsage | management.CapabilityInvocationUsage | management.KeyAgreementUsage,
SelfControl: true,
VerificationMethodType: ssi.JsonWebKey2020,
}
}

Expand Down

0 comments on commit 36056b2

Please sign in to comment.