Skip to content

Commit

Permalink
fix: fixed the mapping between vmId and verificationMethodWithoutCont…
Browse files Browse the repository at this point in the history
…roller
  • Loading branch information
arnabghose997 committed Nov 24, 2023
1 parent b31cf65 commit 81d8533
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions x/ssi/ld-context/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ func NewJsonLdCredentialSchema(credSchema *types.CredentialSchemaDocument) *Json

// It is a similar to `Did` struct, with the exception that the `context` attribute is of type
// `contextObject` instead of `[]string`, which is meant for accomodating Context JSON body
// having arbritrary attributes. It should be used for performing Canonization. T
// having arbritrary attributes. It should be used for performing Canonization.
type JsonLdDidDocumentWithoutVM struct {
Context []contextObject `json:"@context,omitempty"`
Id string `json:"id,omitempty"`
Controller []string `json:"controller,omitempty"`
AlsoKnownAs []string `json:"alsoKnownAs,omitempty"`
Authentication []*verificationMethodWithoutController `json:"authentication,omitempty"`
AssertionMethod []*verificationMethodWithoutController `json:"assertionMethod,omitempty"`
Context []contextObject `json:"@context,omitempty"`
Id string `json:"id,omitempty"`
Controller []string `json:"controller,omitempty"`
AlsoKnownAs []string `json:"alsoKnownAs,omitempty"`
Authentication []verificationMethodWithoutController `json:"authentication,omitempty"`
AssertionMethod []verificationMethodWithoutController `json:"assertionMethod,omitempty"`
}

func (doc *JsonLdDidDocumentWithoutVM) GetContext() []contextObject {
Expand Down Expand Up @@ -226,7 +226,7 @@ func NewJsonLdDidDocumentWithoutVM(didDoc *types.DidDocument) *JsonLdDidDocument
jsonLdDoc.AlsoKnownAs = didDoc.AlsoKnownAs

// Replace verification method ids with their corresponding Verification Method object
var vmMap map[string]*verificationMethodWithoutController = map[string]*verificationMethodWithoutController{}
var vmMap map[string]verificationMethodWithoutController = map[string]verificationMethodWithoutController{}

for _, vm := range didDoc.VerificationMethod {
vmMap[vm.Id] = newVerificationMethodWithoutController(vm)
Expand All @@ -236,17 +236,19 @@ func NewJsonLdDidDocumentWithoutVM(didDoc *types.DidDocument) *JsonLdDidDocument
// verification methods in AssertionMethod
if len(didDoc.Authentication) == 0 && len(didDoc.AssertionMethod) == 0 {
for _, vm := range vmMap {
vm.Id = vm.Id + "assertionMethod"
jsonLdDoc.AssertionMethod = append(jsonLdDoc.AssertionMethod, vm)
jsonLdDoc.AssertionMethod[len(jsonLdDoc.AssertionMethod)-1].Id = jsonLdDoc.AssertionMethod[len(jsonLdDoc.AssertionMethod)-1].Id + "assertionMethod"
}
} else {
for _, vmId := range didDoc.Authentication {
vmMap[vmId].Id = vmMap[vmId].Id + "authentication"
jsonLdDoc.Authentication = append(jsonLdDoc.Authentication, vmMap[vmId])
vmObj := vmMap[vmId]
jsonLdDoc.Authentication = append(jsonLdDoc.Authentication, vmObj)
jsonLdDoc.Authentication[len(jsonLdDoc.Authentication)-1].Id = jsonLdDoc.Authentication[len(jsonLdDoc.Authentication)-1].Id + "authentication"
}
for _, vmId := range didDoc.AssertionMethod {
vmMap[vmId].Id = vmMap[vmId].Id + "assertionMethod"
jsonLdDoc.AssertionMethod = append(jsonLdDoc.AssertionMethod, vmMap[vmId])
vmObj := vmMap[vmId]
jsonLdDoc.AssertionMethod = append(jsonLdDoc.AssertionMethod, vmObj)
jsonLdDoc.AssertionMethod[len(jsonLdDoc.AssertionMethod)-1].Id = jsonLdDoc.AssertionMethod[len(jsonLdDoc.AssertionMethod)-1].Id + "assertionMethod"
}
}

Expand All @@ -259,11 +261,12 @@ type verificationMethodWithoutController struct {
PublicKeyMultibase string `json:"publicKeyMultibase,omitempty"`
}

func newVerificationMethodWithoutController(vm *types.VerificationMethod) *verificationMethodWithoutController {
var vmWithoutController *verificationMethodWithoutController = &verificationMethodWithoutController{
func newVerificationMethodWithoutController(vm *types.VerificationMethod) verificationMethodWithoutController {
var vmWithoutController verificationMethodWithoutController = verificationMethodWithoutController{
Id: vm.Id,
Type: vm.Type,
PublicKeyMultibase: vm.PublicKeyMultibase,
}
return vmWithoutController
}

0 comments on commit 81d8533

Please sign in to comment.