Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-LD signing support for Credential Schema #378

Merged
merged 4 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ paths:
credentialStatusDocument:
type: object
properties:
context:
type: array
items:
type: string
id:
type: string
revoked:
Expand All @@ -40,7 +44,7 @@ paths:
type: string
issuanceDate:
type: string
merkleRootHash:
credentialMerkleRootHash:
type: string
credentialStatusProof:
type: object
Expand Down Expand Up @@ -159,6 +163,10 @@ paths:
credentialStatusDocument:
type: object
properties:
context:
type: array
items:
type: string
id:
type: string
revoked:
Expand All @@ -171,7 +179,7 @@ paths:
type: string
issuanceDate:
type: string
merkleRootHash:
credentialMerkleRootHash:
type: string
credentialStatusProof:
type: object
Expand Down Expand Up @@ -529,6 +537,10 @@ paths:
credentialSchemaDocument:
type: object
properties:
context:
type: array
items:
type: string
type:
type: string
modelVersion:
Expand Down Expand Up @@ -677,6 +689,10 @@ paths:
credentialSchemaDocument:
type: object
properties:
context:
type: array
items:
type: string
type:
type: string
modelVersion:
Expand Down Expand Up @@ -24562,6 +24578,10 @@ definitions:
hypersign.ssi.v1.CredentialSchemaDocument:
type: object
properties:
context:
type: array
items:
type: string
type:
type: string
modelVersion:
Expand Down Expand Up @@ -24614,6 +24634,10 @@ definitions:
credentialSchemaDocument:
type: object
properties:
context:
type: array
items:
type: string
type:
type: string
modelVersion:
Expand Down Expand Up @@ -24666,6 +24690,10 @@ definitions:
hypersign.ssi.v1.CredentialStatusDocument:
type: object
properties:
context:
type: array
items:
type: string
id:
type: string
revoked:
Expand All @@ -24678,14 +24706,18 @@ definitions:
type: string
issuanceDate:
type: string
merkleRootHash:
credentialMerkleRootHash:
type: string
hypersign.ssi.v1.CredentialStatusState:
type: object
properties:
credentialStatusDocument:
type: object
properties:
context:
type: array
items:
type: string
id:
type: string
revoked:
Expand All @@ -24698,7 +24730,7 @@ definitions:
type: string
issuanceDate:
type: string
merkleRootHash:
credentialMerkleRootHash:
type: string
credentialStatusProof:
type: object
Expand Down Expand Up @@ -24902,6 +24934,10 @@ definitions:
credentialSchemaDocument:
type: object
properties:
context:
type: array
items:
type: string
type:
type: string
modelVersion:
Expand Down Expand Up @@ -24965,6 +25001,10 @@ definitions:
credentialSchemaDocument:
type: object
properties:
context:
type: array
items:
type: string
type:
type: string
modelVersion:
Expand Down Expand Up @@ -25023,6 +25063,10 @@ definitions:
credentialStatusDocument:
type: object
properties:
context:
type: array
items:
type: string
id:
type: string
revoked:
Expand All @@ -25035,7 +25079,7 @@ definitions:
type: string
issuanceDate:
type: string
merkleRootHash:
credentialMerkleRootHash:
type: string
credentialStatusProof:
type: object
Expand Down Expand Up @@ -25071,6 +25115,10 @@ definitions:
credentialStatusDocument:
type: object
properties:
context:
type: array
items:
type: string
id:
type: string
revoked:
Expand All @@ -25083,7 +25131,7 @@ definitions:
type: string
issuanceDate:
type: string
merkleRootHash:
credentialMerkleRootHash:
type: string
credentialStatusProof:
type: object
Expand Down
85 changes: 70 additions & 15 deletions cmd/hid-noded/cmd/debug_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ func signDidDocCmd() *cobra.Command {

func signSchemaDocCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "schema-doc [doc] [private-key] [signing-algo]",
Use: "schema-doc [doc] [private-key] [proof-object-without-signature]",
Short: "Schema Document signature",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
argSchemaDoc := args[0]
argPrivateKey := args[1]
argSigningAlgo := args[2]
argProofObjectWithoutSignature := args[2]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -432,38 +432,67 @@ func signSchemaDocCmd() *cobra.Command {
if err != nil {
return err
}
schemaDocBytes := schemaDoc.GetSignBytes()

// Unmarshal Proof Object
var credSchemaDocProof types.DocumentProof
err = clientCtx.Codec.UnmarshalJSON([]byte(argProofObjectWithoutSignature), &credSchemaDocProof)
if err != nil {
return err
}

// Sign Schema Document
var signature string
switch argSigningAlgo {
switch credSchemaDocProof.Type {
case types.Ed25519Signature2020:
signature, err = hidnodecli.GetEd25519Signature2020(argPrivateKey, schemaDocBytes)
credSchemaDocBytes, err := ldcontext.Ed25519Signature2020Normalize(&schemaDoc, &credSchemaDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetEd25519Signature2020(argPrivateKey, credSchemaDocBytes)
if err != nil {
return err
}
case types.EcdsaSecp256k1Signature2019:
signature, err = hidnodecli.GetEcdsaSecp256k1Signature2019(argPrivateKey, schemaDocBytes)
credSchemaDocBytes, err := ldcontext.EcdsaSecp256k1Signature2019Normalize(&schemaDoc, &credSchemaDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetEcdsaSecp256k1Signature2019(argPrivateKey, credSchemaDocBytes)
if err != nil {
return err
}
case types.EcdsaSecp256k1RecoverySignature2020:
signature, err = hidnodecli.GetEcdsaSecp256k1RecoverySignature2020(argPrivateKey, schemaDocBytes)
credSchemaDocBytes, err := ldcontext.EcdsaSecp256k1RecoverySignature2020Normalize(&schemaDoc, &credSchemaDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetEcdsaSecp256k1RecoverySignature2020(argPrivateKey, credSchemaDocBytes)
if err != nil {
return err
}
case types.BbsBlsSignature2020:
signature, err = hidnodecli.GetBbsBlsSignature2020(argPrivateKey, schemaDocBytes)
credSchemaDocBytes, err := ldcontext.BbsBlsSignature2020Normalize(&schemaDoc, &credSchemaDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetBbsBlsSignature2020(argPrivateKey, credSchemaDocBytes)
if err != nil {
return err
}
case types.BabyJubJubSignature2023:
signature, err = hidnodecli.GetBabyJubJubSignature2023(argPrivateKey, schemaDocBytes)
signature, err = hidnodecli.GetBabyJubJubSignature2023(argPrivateKey, schemaDoc.GetSignBytes())
if err != nil {
return err
}
default:
panic("recieved unsupported signing-algo. Supported algorithms are: [Ed25519Signature2020, EcdsaSecp256k1Signature2019, EcdsaSecp256k1RecoverySignature2020, BbsBlsSignature2020, BabyJubJubSignature2023]")
panic(fmt.Sprintf(
"recieved unsupported signing-algo '%v'. Supported algorithms are: [Ed25519Signature2020, EcdsaSecp256k1Signature2019, EcdsaSecp256k1RecoverySignature2020, BbsBlsSignature2020, BabyJubJubSignature2023]",
credSchemaDocProof.Type,
))
}

_, err = fmt.Fprintln(cmd.OutOrStdout(), signature)
Expand All @@ -475,13 +504,13 @@ func signSchemaDocCmd() *cobra.Command {

func signCredStatusDocCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cred-status-doc [doc] [private-key] [signing-algo]",
Use: "cred-status-doc [doc] [private-key] [proof-object-without-signature]",
Short: "Credential Status Document signature",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
argCredStatusDoc := args[0]
argPrivateKey := args[1]
argSigningAlgo := args[2]
argProofObjectWithoutSignature := args[2]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -494,33 +523,59 @@ func signCredStatusDocCmd() *cobra.Command {
if err != nil {
return err
}
credStatusDocBytes := credStatusDoc.GetSignBytes()

// Unmarshal Proof Object
var credStatusDocProof types.DocumentProof
err = clientCtx.Codec.UnmarshalJSON([]byte(argProofObjectWithoutSignature), &credStatusDocProof)
if err != nil {
return err
}

// Sign Credential Status Document
var signature string
switch argSigningAlgo {
switch credStatusDocProof.Type {
case types.Ed25519Signature2020:
credStatusDocBytes, err := ldcontext.Ed25519Signature2020Normalize(&credStatusDoc, &credStatusDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetEd25519Signature2020(argPrivateKey, credStatusDocBytes)
if err != nil {
return err
}
case types.EcdsaSecp256k1Signature2019:
credStatusDocBytes, err := ldcontext.EcdsaSecp256k1Signature2019Normalize(&credStatusDoc, &credStatusDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetEcdsaSecp256k1Signature2019(argPrivateKey, credStatusDocBytes)
if err != nil {
return err
}
case types.EcdsaSecp256k1RecoverySignature2020:
credStatusDocBytes, err := ldcontext.EcdsaSecp256k1RecoverySignature2020Normalize(&credStatusDoc, &credStatusDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetEcdsaSecp256k1RecoverySignature2020(argPrivateKey, credStatusDocBytes)
if err != nil {
return err
}
case types.BbsBlsSignature2020:
credStatusDocBytes, err := ldcontext.BbsBlsSignature2020Normalize(&credStatusDoc, &credStatusDocProof)
if err != nil {
return err
}

signature, err = hidnodecli.GetBbsBlsSignature2020(argPrivateKey, credStatusDocBytes)
if err != nil {
return err
}
case types.BabyJubJubSignature2023:
signature, err = hidnodecli.GetBabyJubJubSignature2023(argPrivateKey, credStatusDocBytes)
signature, err = hidnodecli.GetBabyJubJubSignature2023(argPrivateKey, credStatusDoc.GetSignBytes())
if err != nil {
return err
}
Expand Down
16 changes: 9 additions & 7 deletions proto/ssi/v1/credential_schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ syntax = "proto3";
package hypersign.ssi.v1;

import "ssi/v1/proof.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/hypersign-protocol/hid-node/x/ssi/types";

message CredentialSchemaDocument {
string type = 1;
string modelVersion = 2;
string id = 3;
string name = 4;
string author = 5;
string authored = 6;
CredentialSchemaProperty schema = 7;
repeated string context = 1 [json_name = "@context", (gogoproto.jsontag) = "@context"];
string type = 2;
string modelVersion = 3;
string id = 4;
string name = 5;
string author = 6;
string authored = 7;
CredentialSchemaProperty schema = 8;
}

message CredentialSchemaProperty {
Expand Down
Loading
Loading