Skip to content

Commit ed6203b

Browse files
authored
Merge pull request #395 from hypersign-protocol/develop
Merging develop to main for v0.3.0 upgrade
2 parents ad30181 + 6013841 commit ed6203b

File tree

15 files changed

+490
-68
lines changed

15 files changed

+490
-68
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
with:
2424
args: --timeout 10m
2525
github-token: ${{ secrets.GITHUB_TOKEN }}
26-
version: latest
26+
version: v1.59.1

app/app.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ func NewHypersignApp(
455455
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
456456
)
457457

458+
app.UpgradeKeeper.SetUpgradeHandler("v030", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
459+
ctx.Logger().Info("v0.3.0 upgrade")
460+
return fromVM, nil
461+
})
462+
458463
app.IBCKeeper = ibckeeper.NewKeeper(
459464
appCodec,
460465
keys[ibcexported.StoreKey],

cmd/hid-noded/cmd/debug_extensions_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func getDocumentSignature(doc types.SsiMsg, docProof *types.DocumentProof, priva
8484
}
8585
case types.BJJSignature2021:
8686
var docBytes []byte
87-
docBytes, err := ldcontext.BJJSignature2021Normalize(doc)
87+
docBytes, err := ldcontext.BJJSignature2021Normalize(doc, docProof)
8888
if err != nil {
8989
return "", err
9090
}

x/ssi/ld-context/context.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const X25519KeyAgreementKeyEIP5630Context string = "https://raw.githubuserconten
1010
const CredentialStatusContext string = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/CredentialStatus.jsonld"
1111
const CredentialSchemaContext string = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/CredentialSchema.jsonld"
1212
const BabyJubJubKey2021Context string = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/BabyJubJubKey2021.jsonld"
13+
const BJJSignature2021Context string = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/BJJSignature2021.jsonld"
14+
const LinkedDomainsContext string = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/LinkedDomains.jsonld"
1315

1416
// As hid-node is not supposed to perform any GET request, the complete Context body of their
1517
// respective Context urls has been maintained below.
@@ -745,4 +747,119 @@ var ContextUrlMap map[string]contextObject = map[string]contextObject{
745747
},
746748
},
747749
},
750+
751+
BJJSignature2021Context: {
752+
"@version": 1.1,
753+
"id": "@id",
754+
"type": "@type",
755+
"proof": map[string]interface{}{
756+
"@id": "https://w3id.org/security#proof",
757+
"@type": "@id",
758+
"@container": "@graph",
759+
},
760+
"BJJSignature2021": map[string]interface{}{
761+
"@id": "https://w3id.org/security#BJJSignature2021",
762+
"@context": map[string]interface{}{
763+
"@version": 1.1,
764+
"@protected": true,
765+
"id": "@id",
766+
"type": "@type",
767+
"challenge": "https://w3id.org/security#challenge",
768+
"created": map[string]interface{}{
769+
"@id": "http://purl.org/dc/terms/created",
770+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
771+
},
772+
"domain": "https://w3id.org/security#domain",
773+
"proofValue": "https://w3id.org/security#proofValue",
774+
"credentialRoot": "https://w3id.org/security#credentialRoot",
775+
"nonce": "https://w3id.org/security#nonce",
776+
"proofPurpose": map[string]interface{}{
777+
"@id": "https://w3id.org/security#proofPurpose",
778+
"@type": "@vocab",
779+
"@context": map[string]interface{}{
780+
"@version": 1.1,
781+
"@protected": true,
782+
"id": "@id",
783+
"type": "@type",
784+
"assertionMethod": map[string]interface{}{
785+
"@id": "https://w3id.org/security#assertionMethod",
786+
"@type": "@id",
787+
"@container": "@set",
788+
},
789+
"authentication": map[string]interface{}{
790+
"@id": "https://w3id.org/security#authenticationMethod",
791+
"@type": "@id",
792+
"@container": "@set",
793+
},
794+
},
795+
},
796+
"verificationMethod": map[string]interface{}{
797+
"@id": "https://w3id.org/security#verificationMethod",
798+
"@type": "@id",
799+
},
800+
},
801+
},
802+
"BabyJubJubSignatureProof2021": map[string]interface{}{
803+
"@id": "https://w3id.org/security#BabyJubJubSignatureProof2021",
804+
"@context": map[string]interface{}{
805+
"@version": 1.1,
806+
"@protected": true,
807+
"id": "@id",
808+
"type": "@type",
809+
"challenge": "https://w3id.org/security#challenge",
810+
"created": map[string]interface{}{
811+
"@id": "http://purl.org/dc/terms/created",
812+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime",
813+
},
814+
"domain": "https://w3id.org/security#domain",
815+
"nonce": "https://w3id.org/security#nonce",
816+
"proofPurpose": map[string]interface{}{
817+
"@id": "https://w3id.org/security#proofPurpose",
818+
"@type": "@vocab",
819+
"@context": map[string]interface{}{
820+
"@version": 1.1,
821+
"@protected": true,
822+
"id": "@id",
823+
"type": "@type",
824+
"sec": "https://w3id.org/security#",
825+
"assertionMethod": map[string]interface{}{
826+
"@id": "https://w3id.org/security#assertionMethod",
827+
"@type": "@id",
828+
"@container": "@set",
829+
},
830+
"authentication": map[string]interface{}{
831+
"@id": "https://w3id.org/security#authenticationMethod",
832+
"@type": "@id",
833+
"@container": "@set",
834+
},
835+
},
836+
},
837+
"proofValue": "https://w3id.org/security#proofValue",
838+
"credentialRoot": "https://w3id.org/security#credentialRoot",
839+
"verificationMethod": map[string]interface{}{
840+
"@id": "https://w3id.org/security#verificationMethod",
841+
"@type": "@id",
842+
},
843+
},
844+
},
845+
},
846+
LinkedDomainsContext: {
847+
848+
"@protected": true,
849+
"id": "@id",
850+
"type": "@type",
851+
"LinkedDomains": map[string]interface{}{
852+
"@id": "https://www.w3.org/ns/did#LinkedDomains",
853+
"@type": "@id",
854+
"@context": map[string]interface{}{
855+
"@protected": true,
856+
"id": "@id",
857+
"type": "@type",
858+
"serviceEndpoint": map[string]interface{}{
859+
"@id": "https://www.w3.org/ns/did#serviceEndpoint",
860+
"@type": "@id",
861+
},
862+
},
863+
},
864+
},
748865
}

x/ssi/ld-context/cryptosuite.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,25 @@ func EcdsaSecp256k1Signature2019Normalize(ssiMsg types.SsiMsg, docProof *types.D
129129

130130
// BJJSignature2021Normalize performs canonization of SSI documents
131131
// based on the spec: https://iden3-communication.io/BJJSignature2021/
132-
func BJJSignature2021Normalize(ssiMsg types.SsiMsg) ([]byte, error) {
132+
func BJJSignature2021Normalize(ssiMsg types.SsiMsg, docProof *types.DocumentProof) ([]byte, error) {
133133
var jsonLDString string
134134
switch doc := ssiMsg.(type) {
135135
case *types.DidDocument:
136-
jsonLDBytes, err := json.Marshal(NewJsonLdDidDocumentWithoutVM(doc))
136+
jsonLDBytes, err := json.Marshal(NewJsonLdDidDocumentWithoutVM(doc, docProof))
137137
if err != nil {
138138
return nil, err
139139
}
140140
jsonLDString = string(jsonLDBytes)
141141
case *types.CredentialSchemaDocument:
142-
jsonLDBytes, err := json.Marshal(NewJsonLdCredentialSchema(doc))
142+
credentialSchemaDocument := NewJsonLdCredentialSchemaBJJ(doc, docProof)
143+
jsonLDBytes, err := json.Marshal(credentialSchemaDocument)
143144
if err != nil {
144145
return nil, err
145146
}
146147
jsonLDString = string(jsonLDBytes)
147148
case *types.CredentialStatusDocument:
148-
jsonLDBytes, err := json.Marshal(NewJsonLdCredentialStatus(doc))
149+
credentialStatusDocument := NewJsonLdCredentialStatusBJJ(doc, docProof)
150+
jsonLDBytes, err := json.Marshal(credentialStatusDocument)
149151
if err != nil {
150152
return nil, err
151153
}

x/ssi/ld-context/normalize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NormalizeByProofType(ssiMsg types.SsiMsg, didDocumentProof *types.DocumentP
3636
}
3737
return msgBytes, nil
3838
case types.BJJSignature2021:
39-
msgBytes, err := BJJSignature2021Normalize(ssiMsg)
39+
msgBytes, err := BJJSignature2021Normalize(ssiMsg, didDocumentProof)
4040
if err != nil {
4141
return nil, err
4242
}

x/ssi/ld-context/types.go

Lines changed: 129 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ func (doc *JsonLdCredentialStatus) GetContext() []contextObject {
8181
return doc.Context
8282
}
8383

84+
type JsonLdCredentialStatusBJJ struct {
85+
Context []contextObject `json:"@context,omitempty"`
86+
Id string `json:"id,omitempty"`
87+
Revoked bool `json:"revoked,omitempty"`
88+
Suspended bool `json:"suspended,omitempty"`
89+
Remarks string `json:"remarks,omitempty"`
90+
Issuer string `json:"issuer,omitempty"`
91+
IssuanceDate string `json:"issuanceDate,omitempty"`
92+
CredentialMerkleRootHash string `json:"credentialMerkleRootHash,omitempty"`
93+
Proof JsonLdDocumentProof `json:"proof,omitempty"`
94+
}
95+
96+
func (doc *JsonLdCredentialStatusBJJ) GetContext() []contextObject {
97+
return doc.Context
98+
}
99+
84100
// NewJsonLdCredentialStatus returns a new JsonLdCredentialStatus struct from input Credential Status
85101
func NewJsonLdCredentialStatus(credStatusDoc *types.CredentialStatusDocument) *JsonLdCredentialStatus {
86102
if len(credStatusDoc.Context) == 0 {
@@ -108,6 +124,37 @@ func NewJsonLdCredentialStatus(credStatusDoc *types.CredentialStatusDocument) *J
108124
return jsonLdCredentialStatus
109125
}
110126

127+
func NewJsonLdCredentialStatusBJJ(credStatusDoc *types.CredentialStatusDocument, docProof *types.DocumentProof) *JsonLdCredentialStatusBJJ {
128+
if len(credStatusDoc.Context) == 0 {
129+
panic("atleast one context url must be provided in the Credential Status Document for Canonization")
130+
}
131+
132+
var jsonLdCredentialStatus *JsonLdCredentialStatusBJJ = &JsonLdCredentialStatusBJJ{}
133+
134+
for _, url := range credStatusDoc.Context {
135+
contextObj, ok := ContextUrlMap[url]
136+
if !ok {
137+
panic(fmt.Sprintf("invalid or unsupported context url: %v", url))
138+
}
139+
jsonLdCredentialStatus.Context = append(jsonLdCredentialStatus.Context, contextObj)
140+
}
141+
142+
jsonLdCredentialStatus.Id = credStatusDoc.Id
143+
jsonLdCredentialStatus.Revoked = credStatusDoc.Revoked
144+
jsonLdCredentialStatus.Remarks = credStatusDoc.Remarks
145+
jsonLdCredentialStatus.Suspended = credStatusDoc.Suspended
146+
jsonLdCredentialStatus.Issuer = credStatusDoc.Issuer
147+
jsonLdCredentialStatus.IssuanceDate = credStatusDoc.IssuanceDate
148+
jsonLdCredentialStatus.CredentialMerkleRootHash = credStatusDoc.CredentialMerkleRootHash
149+
150+
jsonLdCredentialStatus.Proof.Type = docProof.Type
151+
jsonLdCredentialStatus.Proof.Created = docProof.Created
152+
jsonLdCredentialStatus.Proof.ProofPurpose = docProof.ProofPurpose
153+
jsonLdCredentialStatus.Proof.VerificationMethod = docProof.VerificationMethod
154+
155+
return jsonLdCredentialStatus
156+
}
157+
111158
// Document Proof
112159

113160
type JsonLdDocumentProof struct {
@@ -163,6 +210,22 @@ func (doc *JsonLdCredentialSchema) GetContext() []contextObject {
163210
return doc.Context
164211
}
165212

213+
type JsonLdCredentialSchemaBJJ struct {
214+
Context []contextObject `json:"@context,omitempty"`
215+
Type string `json:"type,omitempty"`
216+
ModelVersion string `json:"modelVersion,omitempty"`
217+
Id string `json:"id,omitempty"`
218+
Name string `json:"name,omitempty"`
219+
Author string `json:"author,omitempty"`
220+
Authored string `json:"authored,omitempty"`
221+
Schema *types.CredentialSchemaProperty `json:"schema,omitempty"`
222+
Proof JsonLdDocumentProof `json:"proof,omitempty"`
223+
}
224+
225+
func (doc *JsonLdCredentialSchemaBJJ) GetContext() []contextObject {
226+
return doc.Context
227+
}
228+
166229
func NewJsonLdCredentialSchema(credSchema *types.CredentialSchemaDocument) *JsonLdCredentialSchema {
167230
if len(credSchema.Context) == 0 {
168231
panic("atleast one context url must be provided for DID Document for Canonization")
@@ -189,24 +252,60 @@ func NewJsonLdCredentialSchema(credSchema *types.CredentialSchemaDocument) *Json
189252
return jsonLdDoc
190253
}
191254

255+
func NewJsonLdCredentialSchemaBJJ(credSchema *types.CredentialSchemaDocument, docProof *types.DocumentProof) *JsonLdCredentialSchemaBJJ {
256+
if len(credSchema.Context) == 0 {
257+
panic("atleast one context url must be provided for DID Document for Canonization")
258+
}
259+
260+
var jsonLdDoc *JsonLdCredentialSchemaBJJ = &JsonLdCredentialSchemaBJJ{}
261+
262+
for _, url := range credSchema.Context {
263+
contextObj, ok := ContextUrlMap[url]
264+
if !ok {
265+
panic(fmt.Sprintf("invalid or unsupported context url: %v", url))
266+
}
267+
jsonLdDoc.Context = append(jsonLdDoc.Context, contextObj)
268+
}
269+
270+
jsonLdDoc.Type = credSchema.Type
271+
jsonLdDoc.ModelVersion = credSchema.ModelVersion
272+
jsonLdDoc.Id = credSchema.Id
273+
jsonLdDoc.Name = credSchema.Name
274+
jsonLdDoc.Author = credSchema.Author
275+
jsonLdDoc.Authored = credSchema.Authored
276+
jsonLdDoc.Schema = credSchema.Schema
277+
278+
jsonLdDoc.Proof.Type = docProof.Type
279+
jsonLdDoc.Proof.Created = docProof.Created
280+
jsonLdDoc.Proof.ProofPurpose = docProof.ProofPurpose
281+
jsonLdDoc.Proof.VerificationMethod = docProof.VerificationMethod
282+
283+
return jsonLdDoc
284+
}
285+
192286
// It is a similar to `Did` struct, with the exception that the `context` attribute is of type
193287
// `contextObject` instead of `[]string`, which is meant for accomodating Context JSON body
194288
// having arbritrary attributes. It should be used for performing Canonization.
195289
type JsonLdDidDocumentWithoutVM struct {
196-
Context []contextObject `json:"@context,omitempty"`
197-
Id string `json:"id,omitempty"`
198-
Controller []string `json:"controller,omitempty"`
199-
AlsoKnownAs []string `json:"alsoKnownAs,omitempty"`
200-
Authentication []verificationMethodWithoutController `json:"authentication,omitempty"`
201-
AssertionMethod []verificationMethodWithoutController `json:"assertionMethod,omitempty"`
290+
Context []contextObject `json:"@context,omitempty"`
291+
Id string `json:"id,omitempty"`
292+
Controller []string `json:"controller,omitempty"`
293+
// AlsoKnownAs []string `json:"alsoKnownAs,omitempty"`
294+
Authentication []verificationMethodWithoutController `json:"authentication,omitempty"`
295+
AssertionMethod []verificationMethodWithoutController `json:"assertionMethod,omitempty"`
296+
CapabilityDelegation []verificationMethodWithoutController `json:"capabilityDelegation,omitempty"`
297+
CapabilityInvocation []verificationMethodWithoutController `json:"capabilityInvocation,omitempty"`
298+
KeyAgreement []verificationMethodWithoutController `json:"keyAgreement,omitempty"`
299+
Proof JsonLdDocumentProof `json:"proof,omitempty"`
300+
Service []*types.Service `protobuf:"bytes,11,rep,name=service,proto3" json:"service,omitempty"`
202301
}
203302

204303
func (doc *JsonLdDidDocumentWithoutVM) GetContext() []contextObject {
205304
return doc.Context
206305
}
207306

208307
// NewJsonLdDidDocument returns a new JsonLdDid struct from input Did
209-
func NewJsonLdDidDocumentWithoutVM(didDoc *types.DidDocument) *JsonLdDidDocumentWithoutVM {
308+
func NewJsonLdDidDocumentWithoutVM(didDoc *types.DidDocument, docProof *types.DocumentProof) *JsonLdDidDocumentWithoutVM {
210309
if len(didDoc.Context) == 0 {
211310
panic("atleast one context url must be provided for DID Document for Canonization")
212311
}
@@ -223,8 +322,6 @@ func NewJsonLdDidDocumentWithoutVM(didDoc *types.DidDocument) *JsonLdDidDocument
223322

224323
jsonLdDoc.Id = didDoc.Id
225324
jsonLdDoc.Controller = didDoc.Controller
226-
jsonLdDoc.AlsoKnownAs = didDoc.AlsoKnownAs
227-
228325
// Replace verification method ids with their corresponding Verification Method object
229326
var vmMap map[string]verificationMethodWithoutController = map[string]verificationMethodWithoutController{}
230327

@@ -250,8 +347,31 @@ func NewJsonLdDidDocumentWithoutVM(didDoc *types.DidDocument) *JsonLdDidDocument
250347
jsonLdDoc.AssertionMethod = append(jsonLdDoc.AssertionMethod, vmObj)
251348
jsonLdDoc.AssertionMethod[len(jsonLdDoc.AssertionMethod)-1].Id = jsonLdDoc.AssertionMethod[len(jsonLdDoc.AssertionMethod)-1].Id + "assertionMethod"
252349
}
350+
351+
for _, vmId := range didDoc.CapabilityDelegation {
352+
vmObj := vmMap[vmId]
353+
jsonLdDoc.CapabilityDelegation = append(jsonLdDoc.CapabilityDelegation, vmObj)
354+
jsonLdDoc.CapabilityDelegation[len(jsonLdDoc.CapabilityDelegation)-1].Id = jsonLdDoc.CapabilityDelegation[len(jsonLdDoc.CapabilityDelegation)-1].Id + "capabilityDelegation"
355+
}
356+
357+
for _, vmId := range didDoc.CapabilityInvocation {
358+
vmObj := vmMap[vmId]
359+
jsonLdDoc.CapabilityInvocation = append(jsonLdDoc.CapabilityInvocation, vmObj)
360+
jsonLdDoc.CapabilityInvocation[len(jsonLdDoc.CapabilityInvocation)-1].Id = jsonLdDoc.CapabilityInvocation[len(jsonLdDoc.CapabilityInvocation)-1].Id + "capabilityInvocation"
361+
}
362+
363+
for _, vmId := range didDoc.KeyAgreement {
364+
vmObj := vmMap[vmId]
365+
jsonLdDoc.KeyAgreement = append(jsonLdDoc.KeyAgreement, vmObj)
366+
jsonLdDoc.KeyAgreement[len(jsonLdDoc.KeyAgreement)-1].Id = jsonLdDoc.KeyAgreement[len(jsonLdDoc.KeyAgreement)-1].Id + "keyAgreement"
367+
}
253368
}
254369

370+
jsonLdDoc.Proof.Type = docProof.Type
371+
jsonLdDoc.Proof.Created = docProof.Created
372+
jsonLdDoc.Proof.ProofPurpose = docProof.ProofPurpose
373+
jsonLdDoc.Proof.VerificationMethod = docProof.VerificationMethod + docProof.ProofPurpose
374+
jsonLdDoc.Service = didDoc.Service
255375
return jsonLdDoc
256376
}
257377

0 commit comments

Comments
 (0)