diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index eea1f8a..3971cbd 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -11875,7 +11875,174 @@ paths: properties: '@type': type: string + description: >- + A URL/resource name that uniquely identifies the type of + the serialized + + protocol buffer message. This string must contain at + least + + one "/" character. The last segment of the URL's path + must represent + + the fully qualified name of the type (as in + + `path/google.protobuf.Duration`). The name should be in + a canonical form + + (e.g., leading "." is not accepted). + + + In practice, teams usually precompile into the binary + all types that they + + expect it to use in the context of Any. However, for + URLs which use the + + scheme `http`, `https`, or no scheme, one can optionally + set up a type + + server that maps type URLs to message definitions as + follows: + + + * If no scheme is provided, `https` is assumed. + + * An HTTP GET on the URL must yield a + [google.protobuf.Type][] + value in binary format, or produce an error. + * Applications are allowed to cache lookup results based + on the + URL, or have them precompiled into a binary to avoid any + lookup. Therefore, binary compatibility needs to be preserved + on changes to types. (Use versioned type names to manage + breaking changes.) + + Note: this functionality is not currently available in + the official + + protobuf release, and it is not used for type URLs + beginning with + + type.googleapis.com. + + + Schemes other than `http`, `https` (or the empty scheme) + might be + + used with implementation specific semantics. additionalProperties: {} + description: >- + `Any` contains an arbitrary serialized protocol buffer + message along with a + + URL that describes the type of the serialized message. + + + Protobuf library provides support to pack/unpack Any values + in the form + + of utility functions or additional generated methods of the + Any type. + + + Example 1: Pack and unpack a message in C++. + + Foo foo = ...; + Any any; + any.PackFrom(foo); + ... + if (any.UnpackTo(&foo)) { + ... + } + + Example 2: Pack and unpack a message in Java. + + Foo foo = ...; + Any any = Any.pack(foo); + ... + if (any.is(Foo.class)) { + foo = any.unpack(Foo.class); + } + + Example 3: Pack and unpack a message in Python. + + foo = Foo(...) + any = Any() + any.Pack(foo) + ... + if any.Is(Foo.DESCRIPTOR): + any.Unpack(foo) + ... + + Example 4: Pack and unpack a message in Go + + foo := &pb.Foo{...} + any, err := anypb.New(foo) + if err != nil { + ... + } + ... + foo := &pb.Foo{} + if err := any.UnmarshalTo(foo); err != nil { + ... + } + + The pack methods provided by protobuf library will by + default use + + 'type.googleapis.com/full.type.name' as the type URL and the + unpack + + methods only use the fully qualified type name after the + last '/' + + in the type URL, for example "foo.bar.com/x/y.z" will yield + type + + name "y.z". + + + + JSON + + ==== + + The JSON representation of an `Any` value uses the regular + + representation of the deserialized, embedded message, with + an + + additional field `@type` which contains the type URL. + Example: + + package google.profile; + message Person { + string first_name = 1; + string last_name = 2; + } + + { + "@type": "type.googleapis.com/google.profile.Person", + "firstName": , + "lastName": + } + + If the embedded message type is well-known and has a custom + JSON + + representation, that representation will be embedded adding + a field + + `value` which holds the custom JSON in addition to the + `@type` + + field. Example (for message [google.protobuf.Duration][]): + + { + "@type": "type.googleapis.com/google.protobuf.Duration", + "value": "1.212s" + } tags: - Query /ibc/apps/transfer/v1/denom_traces: @@ -19893,6 +20060,12 @@ definitions: id: type: string format: uint64 + hypersignprotocol.hidnode.ssi.MsgCreateSchemaResponse: + type: object + properties: + id: + type: string + format: uint64 hypersignprotocol.hidnode.ssi.MsgUpdateDIDResponse: type: object properties: @@ -19919,6 +20092,55 @@ definitions: description: params holds all the parameters of this module. type: object description: QueryParamsResponse is response type for the Query/Params RPC method. + hypersignprotocol.hidnode.ssi.Schema: + type: object + properties: + type: + type: string + modelVersion: + type: string + id: + type: string + name: + type: string + author: + type: string + authored: + type: string + schema: + type: object + properties: + schema: + type: string + description: + type: string + type: + type: string + properties: + type: string + required: + type: array + items: + type: string + additionalProperties: + type: boolean + hypersignprotocol.hidnode.ssi.SchemaProperty: + type: object + properties: + schema: + type: string + description: + type: string + type: + type: string + properties: + type: string + required: + type: array + items: + type: string + additionalProperties: + type: boolean hypersignprotocol.hidnode.ssi.SignInfo: type: object properties: diff --git a/proto/ssi/v1/schema.proto b/proto/ssi/v1/schema.proto new file mode 100644 index 0000000..f6453df --- /dev/null +++ b/proto/ssi/v1/schema.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package hypersignprotocol.hidnode.ssi; +option go_package = "github.com/hypersign-protocol/hid-node/x/ssi/types"; + +import "google/protobuf/any.proto"; + +message Schema { + string type = 1; + string modelVersion = 2; + string id = 3; + string name = 4; + string author = 5; + string authored = 6; + SchemaProperty schema = 7; +} + + +message SchemaProperty { + string schema = 1; + string description = 2; + string type = 3; + string properties = 4; + repeated string required = 5; + bool additionalProperties = 6; +} \ No newline at end of file diff --git a/proto/ssi/v1/tx.proto b/proto/ssi/v1/tx.proto index d637bd4..94ae5bd 100644 --- a/proto/ssi/v1/tx.proto +++ b/proto/ssi/v1/tx.proto @@ -5,10 +5,13 @@ package hypersignprotocol.hidnode.ssi; option go_package = "github.com/hypersign-protocol/hid-node/x/ssi/types"; +import "ssi/v1/schema.proto"; + // Msg defines the Msg service. service Msg { rpc CreateDID(MsgCreateDID) returns (MsgCreateDIDResponse); rpc UpdateDID(MsgUpdateDID) returns (MsgUpdateDIDResponse); + rpc CreateSchema(MsgCreateSchema) returns (MsgCreateSchemaResponse); // this line is used by starport scaffolding # proto/tx/rpc } @@ -72,4 +75,14 @@ message MsgUpdateDIDResponse { string updateId = 1; } +message MsgCreateSchema { + string creator = 1; + Schema schema = 2; + repeated SignInfo signatures = 3; +} + +message MsgCreateSchemaResponse { + uint64 id = 1; +} + // this line is used by starport scaffolding # proto/tx/message \ No newline at end of file diff --git a/utils/string.go b/utils/string.go index bf6ea0c..da92dd6 100644 --- a/utils/string.go +++ b/utils/string.go @@ -2,6 +2,7 @@ package utils import ( "reflect" + "strings" "unsafe" ) @@ -24,3 +25,13 @@ func UnsafeStrToBytes(s string) []byte { func UnsafeBytesToStr(b []byte) string { return *(*string)(unsafe.Pointer(&b)) } + +func ExtractIDFromSchema(id string) string { + // Seperate `id` with seperator `;` + extract_list := strings.Split(id, ";") + + // Second element of extract_list has the id. + // Split that element with seperator `=` + id_val := strings.Split(extract_list[1], "=")[1] + return id_val +} diff --git a/x/ssi/client/cli/tx.go b/x/ssi/client/cli/tx.go index 5a949af..b669da9 100644 --- a/x/ssi/client/cli/tx.go +++ b/x/ssi/client/cli/tx.go @@ -32,6 +32,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(CmdCreateDID()) cmd.AddCommand(CmdUpdateDID()) + cmd.AddCommand(CmdCreateSchema()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/ssi/client/cli/tx_ssi.go b/x/ssi/client/cli/tx_ssi.go index 882fb9e..39772b3 100644 --- a/x/ssi/client/cli/tx_ssi.go +++ b/x/ssi/client/cli/tx_ssi.go @@ -119,3 +119,56 @@ func CmdUpdateDID() *cobra.Command { cmd.Flags().String(VerKeyFlag, "", "Base64 encoded ed25519 private key to sign identity message with. ") return cmd } + +func CmdCreateSchema() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-schema [schema] [verification-method-id]", + Short: "Broadcast message createSchema", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + argSchema := args[0] + argVerificationMethodId := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + // Unmarshal Schema + var schema types.Schema + err = clientCtx.Codec.UnmarshalJSON([]byte(argSchema), &schema) + if err != nil { + return err + } + + verKeyPriv, err := getVerKey(cmd, clientCtx) + if err != nil { + return err + } + + signBytes := schema.GetSignBytes() + signatureBytes := ed25519.Sign(verKeyPriv, signBytes) + + signInfo := types.SignInfo{ + VerificationMethodId: argVerificationMethodId, + Signature: base64.StdEncoding.EncodeToString(signatureBytes), + } + + msg := types.MsgCreateSchema{ + Schema: &schema, + Signatures: []*types.SignInfo{&signInfo}, + Creator: clientCtx.GetFromAddress().String(), + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + cmd.Flags().String(VerKeyFlag, "", "Base64 encoded ed25519 private key to sign identity message with. ") + return cmd +} diff --git a/x/ssi/handler.go b/x/ssi/handler.go index ace6f4c..3861c70 100644 --- a/x/ssi/handler.go +++ b/x/ssi/handler.go @@ -23,6 +23,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler { case *types.MsgUpdateDID: res, err := msgServer.UpdateDID(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) + case *types.MsgCreateSchema: + res, err := msgServer.CreateSchema(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) diff --git a/x/ssi/keeper/msg_server_create_did.go b/x/ssi/keeper/msg_server_create_did.go index ab94226..8fae9b3 100644 --- a/x/ssi/keeper/msg_server_create_did.go +++ b/x/ssi/keeper/msg_server_create_did.go @@ -37,17 +37,17 @@ func (k msgServer) CreateDID(goCtx context.Context, msg *types.MsgCreateDID) (*t } var didSpec = types.Did{ - Context: didMsg.GetContext(), - Type: didMsg.GetType(), - Id: didMsg.GetId(), - Name: didMsg.GetName(), - PublicKey: didMsg.GetPublicKey(), - Authentication: didMsg.GetAuthentication(), - AssertionMethod: didMsg.GetAssertionMethod(), - KeyAgreement: didMsg.GetKeyAgreement(), + Context: didMsg.GetContext(), + Type: didMsg.GetType(), + Id: didMsg.GetId(), + Name: didMsg.GetName(), + PublicKey: didMsg.GetPublicKey(), + Authentication: didMsg.GetAuthentication(), + AssertionMethod: didMsg.GetAssertionMethod(), + KeyAgreement: didMsg.GetKeyAgreement(), CapabilityInvocation: didMsg.GetCapabilityInvocation(), - Created: didMsg.GetCreated(), - Updated: didMsg.GetUpdated(), + Created: didMsg.GetCreated(), + Updated: didMsg.GetUpdated(), } // Add a DID to the store and get back the ID id := k.AppendDID(ctx, didSpec) diff --git a/x/ssi/keeper/msg_server_create_schema.go b/x/ssi/keeper/msg_server_create_schema.go new file mode 100644 index 0000000..1794227 --- /dev/null +++ b/x/ssi/keeper/msg_server_create_schema.go @@ -0,0 +1,52 @@ +package keeper + +import ( + "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + "github.com/hypersign-protocol/hid-node/x/ssi/utils" +) + +func (k msgServer) CreateSchema(goCtx context.Context, msg *types.MsgCreateSchema) (*types.MsgCreateSchemaResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + schemaMsg := msg.GetSchema() + schemaID := schemaMsg.GetId() + + if err := utils.IsValidSchemaID(schemaID); err != nil { + return nil, sdkerrors.Wrap(types.ErrInvalidSchemaID, err.Error()) + } + + + if k.HasSchema(ctx, schemaID) { + return nil, sdkerrors.Wrap(types.ErrSchemaExists, fmt.Sprintf("Schema ID: %s", schemaID)) + } + + //Get the DID of SChema's Author + authorDID, err := k.GetDid(&ctx, schemaMsg.GetAuthor()) + if err != nil { + return nil, sdkerrors.Wrap(err, fmt.Sprintf("The DID %s is not available", schemaMsg.GetAuthor())) + } + + // Signature check + if err := k.VerifySignatureOnCreateSchema(&ctx, schemaMsg, authorDID.GetSigners(), msg.GetSignatures()); err != nil { + return nil, err + } + + var schema = types.Schema{ + Type: schemaMsg.GetType(), + ModelVersion: schemaMsg.GetModelVersion(), + Id: schemaMsg.GetId(), + Name: schemaMsg.GetName(), + Author: schemaMsg.GetAuthor(), + Authored: schemaMsg.GetAuthored(), + Schema: schemaMsg.GetSchema(), + } + + id := k.AppendSchema(ctx, schema) + + return &types.MsgCreateSchemaResponse{Id: id}, nil +} diff --git a/x/ssi/keeper/schema.go b/x/ssi/keeper/schema.go new file mode 100644 index 0000000..eb555cd --- /dev/null +++ b/x/ssi/keeper/schema.go @@ -0,0 +1,87 @@ +package keeper + +import ( + "encoding/binary" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/utils" + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + +func (k Keeper) GetSchemaCount(ctx sdk.Context) uint64 { + // Get the store using storeKey (which is "blog") and PostCountKey (which is "Post-count-") + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.SchemaCountKey)) + // Convert the PostCountKey to bytes + byteKey := []byte(types.SchemaCountKey) + // Get the value of the count + bz := store.Get(byteKey) + // Return zero if the count value is not found (for example, it's the first post) + if bz == nil { + return 0 + } + // Convert the count into a uint64 + return binary.BigEndian.Uint64(bz) +} + +// Check whether the given DID is already present in the store +func (k Keeper) HasSchema(ctx sdk.Context, id string) bool { + extractedID := utils.ExtractIDFromSchema(id) + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.SchemaKey)) + return store.Has(utils.UnsafeStrToBytes(extractedID)) +} + +// Retrieves the DID from the store +// func (k Keeper) GetDid(ctx *sdk.Context, id string) (*types.DidDocStructCreateDID, error) { +// store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidKey)) + +// if !k.HasDid(*ctx, id) { +// return nil, sdkerrors.ErrNotFound +// } + +// // TODO: Currently, we can interchange DidDocStructCreateDID with DidDocStructUpdateDID +// // as they are similar. They need to have a similar Interface +// var value types.DidDocStructCreateDID +// var bytes = store.Get([]byte(id)) +// if err := k.cdc.Unmarshal(bytes, &value); err != nil { +// return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidType, err.Error()) +// } + +// return &value, nil +// } + +func (k Keeper) SetSchemaCount(ctx sdk.Context, count uint64) { + // Get the store using storeKey (which is "blog") and PostCountKey (which is "Post-count-") + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.SchemaCountKey)) + // Convert the PostCountKey to bytes + byteKey := []byte(types.SchemaCountKey) + // Convert count from uint64 to string and get bytes + bz := make([]byte, 8) + binary.BigEndian.PutUint64(bz, count) + // Set the value of Post-count- to count + store.Set(byteKey, bz) +} + +// SetDid set a specific did in the store +// func (k Keeper) SetDid(ctx sdk.Context, did types.Did) error { +// store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DidKey)) +// b := k.cdc.MustMarshal(&did) +// store.Set([]byte(did.Id), b) +// return nil +// } + +func (k Keeper) AppendSchema(ctx sdk.Context, schema types.Schema) uint64 { + // Get the current number of posts in the store + count := k.GetDidCount(ctx) + // Get the store + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.SchemaKey)) + // Convert the post ID into bytes + // Marshal the post into bytes + schemaBytes := k.cdc.MustMarshal(&schema) + // Strip the id part from schema.ID + schemaID := utils.ExtractIDFromSchema(schema.Id) + store.Set(utils.UnsafeStrToBytes(schemaID), schemaBytes) + // Update the post count + k.SetDidCount(ctx, count+1) + return count +} diff --git a/x/ssi/keeper/verify.go b/x/ssi/keeper/verify.go index 307b6d5..bb94b76 100644 --- a/x/ssi/keeper/verify.go +++ b/x/ssi/keeper/verify.go @@ -4,6 +4,7 @@ import ( "crypto/ed25519" "encoding/base64" "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/hypersign-protocol/hid-node/x/ssi/types" @@ -42,7 +43,7 @@ func VerifyIdentitySignature(signer types.Signer, signatures []*types.SignInfo, func (k msgServer) VerifySignatureOnDidUpdate(ctx *sdk.Context, oldDIDDoc *types.DidDocStructCreateDID, newDIDDoc *types.DidDocStructUpdateDID, signatures []*types.SignInfo) error { var signers []types.Signer - // TODO: Implement when controller feild is used. + // TODO: Implement when controller feild is used. // Get Old DID Doc controller if it's nil then assign self // oldController := oldDIDDoc.Controller // if len(oldController) == 0 { @@ -52,7 +53,7 @@ func (k msgServer) VerifySignatureOnDidUpdate(ctx *sdk.Context, oldDIDDoc *types // for _, controller := range oldController { // signers = append(signers, types.Signer{Signer: controller}) // } - + // TODO: Implement this when `controller` field is added // for _, oldVM := range oldDIDDoc.PublicKey { // newVM := utils.FindVerificationMethod(newDIDDoc.PublicKey, oldVM.Id) @@ -141,3 +142,45 @@ func (k *Keeper) VerifySignature(ctx *sdk.Context, msg types.IdentityMsg, signer return nil } + +func (k *Keeper) VerifySignatureOnCreateSchema(ctx *sdk.Context, msg *types.Schema, signers []types.Signer, signatures []*types.SignInfo) error { + if len(signers) == 0 { + return types.ErrInvalidSignature.Wrap("At least one signer should be present") + } + + if len(signatures) == 0 { + return types.ErrInvalidSignature.Wrap("At least one signature should be present") + } + + signingInput := msg.GetSignBytes() + + for _, signer := range signers { + // TODO: Understand stateValue part of it on Cheqd + // if signer.PublicKeyStruct == nil { + // state, err := k.GetDid(ctx, signer.Signer) + // if err != nil { + // return types.ErrDidDocNotFound.Wrap(signer.Signer) + // } + + // didDoc, err := state.UnpackDataAsDid() + // if err != nil { + // return types.ErrDidDocNotFound.Wrap(signer.Signer) + // } + + // signer.Authentication = didDoc.Authentication + // signer.PublicKeyStruct = didDoc.PublicKeyStruct + // } + + valid, err := VerifyIdentitySignature(signer, signatures, signingInput) + if err != nil { + return sdkerrors.Wrap(types.ErrInvalidSignature, err.Error()) + } + + if !valid { + // return sdkerrors.Wrap(types.ErrInvalidSignature, signer.Signer) + return sdkerrors.Wrap(types.ErrInvalidSignature, string(signingInput)) + } + } + + return nil +} diff --git a/x/ssi/types/codec.go b/x/ssi/types/codec.go index 5de3e47..815ce22 100644 --- a/x/ssi/types/codec.go +++ b/x/ssi/types/codec.go @@ -10,6 +10,7 @@ import ( func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgCreateDID{}, "ssi/CreateDID", nil) cdc.RegisterConcrete(&MsgUpdateDID{}, "ssi/UpdateDID", nil) + cdc.RegisterConcrete(&MsgCreateSchema{}, "ssi/CreateSchema", nil) // this line is used by starport scaffolding # 2 } @@ -20,6 +21,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUpdateDID{}, ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgCreateSchema{}, + ) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/ssi/types/errors.go b/x/ssi/types/errors.go index 550fb4f..060e8dd 100644 --- a/x/ssi/types/errors.go +++ b/x/ssi/types/errors.go @@ -16,4 +16,6 @@ var ( ErrInvalidPublicKey = sdkerrors.Register(ModuleName, 106, "invalid public key") ErrInvalidSignature = sdkerrors.Register(ModuleName, 107, "invalid signature detected") ErrDidDocNotFound = sdkerrors.Register(ModuleName, 108, "DID Doc not found") + ErrSchemaExists = sdkerrors.Register(ModuleName, 109, "Schema already exists") + ErrInvalidSchemaID = sdkerrors.Register(ModuleName, 110, "Invalid schema Id") ) diff --git a/x/ssi/types/keys.go b/x/ssi/types/keys.go index 6800638..27e504c 100644 --- a/x/ssi/types/keys.go +++ b/x/ssi/types/keys.go @@ -20,6 +20,9 @@ const ( const ( DidKey = "Did-value-" DidCountKey = "Did-count-" + + SchemaKey = "Schema-value-" + SchemaCountKey = "Schema-count-" ) func KeyPrefix(p string) []byte { diff --git a/x/ssi/types/message_create_schema.go b/x/ssi/types/message_create_schema.go new file mode 100644 index 0000000..ad60f37 --- /dev/null +++ b/x/ssi/types/message_create_schema.go @@ -0,0 +1,52 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgCreateSchema = "create_schema" + +var _ sdk.Msg = &MsgCreateSchema{} + +func NewMsgCreateSchema(creator string, schema *Schema, signatures []*SignInfo) *MsgCreateSchema { + return &MsgCreateSchema{ + Creator: creator, + Schema: schema, + Signatures: signatures, + } +} + +func (msg *MsgCreateSchema) Route() string { + return RouterKey +} + +func (msg *MsgCreateSchema) Type() string { + return TypeMsgCreateSchema +} + +func (msg *MsgCreateSchema) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgCreateSchema) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *Schema) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCreateSchema) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/ssi/types/message_update_did.go b/x/ssi/types/message_update_did.go index 1f35ff1..56b148e 100644 --- a/x/ssi/types/message_update_did.go +++ b/x/ssi/types/message_update_did.go @@ -43,7 +43,6 @@ func (msg *DidDocStructUpdateDID) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } - func (msg *MsgUpdateDID) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { @@ -85,4 +84,4 @@ func (msg *DidDocStructUpdateDID) GetSigners() []Signer { } return []Signer{} -} \ No newline at end of file +} diff --git a/x/ssi/types/schema.pb.go b/x/ssi/types/schema.pb.go new file mode 100644 index 0000000..50f7a9f --- /dev/null +++ b/x/ssi/types/schema.pb.go @@ -0,0 +1,1062 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ssi/v1/schema.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/codec/types" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Schema struct { + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + ModelVersion string `protobuf:"bytes,2,opt,name=modelVersion,proto3" json:"modelVersion,omitempty"` + Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` + Author string `protobuf:"bytes,5,opt,name=author,proto3" json:"author,omitempty"` + Authored string `protobuf:"bytes,6,opt,name=authored,proto3" json:"authored,omitempty"` + Schema *SchemaProperty `protobuf:"bytes,7,opt,name=schema,proto3" json:"schema,omitempty"` +} + +func (m *Schema) Reset() { *m = Schema{} } +func (m *Schema) String() string { return proto.CompactTextString(m) } +func (*Schema) ProtoMessage() {} +func (*Schema) Descriptor() ([]byte, []int) { + return fileDescriptor_3d55333c8301c7bb, []int{0} +} +func (m *Schema) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Schema) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Schema.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Schema) XXX_Merge(src proto.Message) { + xxx_messageInfo_Schema.Merge(m, src) +} +func (m *Schema) XXX_Size() int { + return m.Size() +} +func (m *Schema) XXX_DiscardUnknown() { + xxx_messageInfo_Schema.DiscardUnknown(m) +} + +var xxx_messageInfo_Schema proto.InternalMessageInfo + +func (m *Schema) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *Schema) GetModelVersion() string { + if m != nil { + return m.ModelVersion + } + return "" +} + +func (m *Schema) GetId() string { + if m != nil { + return m.Id + } + return "" +} + +func (m *Schema) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Schema) GetAuthor() string { + if m != nil { + return m.Author + } + return "" +} + +func (m *Schema) GetAuthored() string { + if m != nil { + return m.Authored + } + return "" +} + +func (m *Schema) GetSchema() *SchemaProperty { + if m != nil { + return m.Schema + } + return nil +} + +type SchemaProperty struct { + Schema string `protobuf:"bytes,1,opt,name=schema,proto3" json:"schema,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` + Properties string `protobuf:"bytes,4,opt,name=properties,proto3" json:"properties,omitempty"` + Required []string `protobuf:"bytes,5,rep,name=required,proto3" json:"required,omitempty"` + AdditionalProperties bool `protobuf:"varint,6,opt,name=additionalProperties,proto3" json:"additionalProperties,omitempty"` +} + +func (m *SchemaProperty) Reset() { *m = SchemaProperty{} } +func (m *SchemaProperty) String() string { return proto.CompactTextString(m) } +func (*SchemaProperty) ProtoMessage() {} +func (*SchemaProperty) Descriptor() ([]byte, []int) { + return fileDescriptor_3d55333c8301c7bb, []int{1} +} +func (m *SchemaProperty) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SchemaProperty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SchemaProperty.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SchemaProperty) XXX_Merge(src proto.Message) { + xxx_messageInfo_SchemaProperty.Merge(m, src) +} +func (m *SchemaProperty) XXX_Size() int { + return m.Size() +} +func (m *SchemaProperty) XXX_DiscardUnknown() { + xxx_messageInfo_SchemaProperty.DiscardUnknown(m) +} + +var xxx_messageInfo_SchemaProperty proto.InternalMessageInfo + +func (m *SchemaProperty) GetSchema() string { + if m != nil { + return m.Schema + } + return "" +} + +func (m *SchemaProperty) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + +func (m *SchemaProperty) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *SchemaProperty) GetProperties() string { + if m != nil { + return m.Properties + } + return "" +} + +func (m *SchemaProperty) GetRequired() []string { + if m != nil { + return m.Required + } + return nil +} + +func (m *SchemaProperty) GetAdditionalProperties() bool { + if m != nil { + return m.AdditionalProperties + } + return false +} + +func init() { + proto.RegisterType((*Schema)(nil), "hypersignprotocol.hidnode.ssi.Schema") + proto.RegisterType((*SchemaProperty)(nil), "hypersignprotocol.hidnode.ssi.SchemaProperty") +} + +func init() { proto.RegisterFile("ssi/v1/schema.proto", fileDescriptor_3d55333c8301c7bb) } + +var fileDescriptor_3d55333c8301c7bb = []byte{ + // 360 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xbd, 0x4e, 0xfb, 0x30, + 0x14, 0xc5, 0xeb, 0x7e, 0xe4, 0xdf, 0xbf, 0x8b, 0x3a, 0x18, 0x84, 0x4c, 0x25, 0xac, 0xa8, 0x53, + 0x97, 0xc6, 0xa2, 0xbc, 0x01, 0x12, 0x1b, 0x43, 0x55, 0x24, 0x06, 0xb6, 0x34, 0x36, 0x89, 0xa5, + 0x24, 0x0e, 0x76, 0x82, 0xc8, 0x5b, 0xf0, 0x58, 0x4c, 0xa8, 0x23, 0x1b, 0xa8, 0x7d, 0x11, 0x64, + 0x3b, 0xfd, 0x92, 0x10, 0xdb, 0x3d, 0xf7, 0xc8, 0x47, 0xf7, 0x77, 0x64, 0x78, 0xaa, 0xb5, 0xa0, + 0x2f, 0x57, 0x54, 0x47, 0x09, 0xcf, 0xc2, 0xa0, 0x50, 0xb2, 0x94, 0xe8, 0x32, 0xa9, 0x0b, 0xae, + 0xb4, 0x88, 0x73, 0xab, 0x23, 0x99, 0x06, 0x89, 0x60, 0xb9, 0x64, 0x3c, 0xd0, 0x5a, 0x8c, 0x2e, + 0x62, 0x29, 0xe3, 0x94, 0x53, 0x6b, 0x2e, 0xab, 0x27, 0x1a, 0xe6, 0xb5, 0x7b, 0x39, 0xfe, 0x02, + 0xd0, 0xbb, 0xb7, 0x51, 0x08, 0xc1, 0x6e, 0x59, 0x17, 0x1c, 0x03, 0x1f, 0x4c, 0xfe, 0x2f, 0xec, + 0x8c, 0xc6, 0xf0, 0x24, 0x93, 0x8c, 0xa7, 0x0f, 0x26, 0x5d, 0xe6, 0xb8, 0x6d, 0xbd, 0xa3, 0x1d, + 0x1a, 0xc2, 0xb6, 0x60, 0xb8, 0x63, 0x9d, 0xb6, 0x60, 0x26, 0x27, 0x0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, 0x9a, 0x3f, 0x58, 0x02, 0x00, 0x00, +} + +func (m *Schema) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Schema) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Schema) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Schema != nil { + { + size, err := m.Schema.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSchema(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + if len(m.Authored) > 0 { + i -= len(m.Authored) + copy(dAtA[i:], m.Authored) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Authored))) + i-- + dAtA[i] = 0x32 + } + if len(m.Author) > 0 { + i -= len(m.Author) + copy(dAtA[i:], m.Author) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Author))) + i-- + dAtA[i] = 0x2a + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x22 + } + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0x1a + } + if len(m.ModelVersion) > 0 { + i -= len(m.ModelVersion) + copy(dAtA[i:], m.ModelVersion) + i = encodeVarintSchema(dAtA, i, uint64(len(m.ModelVersion))) + i-- + dAtA[i] = 0x12 + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SchemaProperty) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SchemaProperty) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SchemaProperty) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AdditionalProperties { + i-- + if m.AdditionalProperties { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x30 + } + if len(m.Required) > 0 { + for iNdEx := len(m.Required) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Required[iNdEx]) + copy(dAtA[i:], m.Required[iNdEx]) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Required[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.Properties) > 0 { + i -= len(m.Properties) + copy(dAtA[i:], m.Properties) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Properties))) + i-- + dAtA[i] = 0x22 + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Schema) > 0 { + i -= len(m.Schema) + copy(dAtA[i:], m.Schema) + i = encodeVarintSchema(dAtA, i, uint64(len(m.Schema))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintSchema(dAtA []byte, offset int, v uint64) int { + offset -= sovSchema(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Schema) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Type) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.ModelVersion) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Id) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Author) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Authored) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + if m.Schema != nil { + l = m.Schema.Size() + n += 1 + l + sovSchema(uint64(l)) + } + return n +} + +func (m *SchemaProperty) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Schema) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Type) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + l = len(m.Properties) + if l > 0 { + n += 1 + l + sovSchema(uint64(l)) + } + if len(m.Required) > 0 { + for _, s := range m.Required { + l = len(s) + n += 1 + l + sovSchema(uint64(l)) + } + } + if m.AdditionalProperties { + n += 2 + } + return n +} + +func sovSchema(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozSchema(x uint64) (n int) { + return sovSchema(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Schema) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Schema: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Schema: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ModelVersion", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ModelVersion = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Author", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Author = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authored", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authored = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Schema", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Schema == nil { + m.Schema = &SchemaProperty{} + } + if err := m.Schema.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSchema(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchema + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SchemaProperty) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SchemaProperty: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SchemaProperty: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Schema", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Schema = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Properties", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Properties = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Required", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthSchema + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSchema + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Required = append(m.Required, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AdditionalProperties", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSchema + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.AdditionalProperties = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipSchema(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSchema + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipSchema(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchema + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchema + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowSchema + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthSchema + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupSchema + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthSchema + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthSchema = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowSchema = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupSchema = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/ssi/types/tx.pb.go b/x/ssi/types/tx.pb.go index b23511f..3c077b7 100644 --- a/x/ssi/types/tx.pb.go +++ b/x/ssi/types/tx.pb.go @@ -603,6 +603,110 @@ func (m *MsgUpdateDIDResponse) GetUpdateId() string { return "" } +type MsgCreateSchema struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Schema *Schema `protobuf:"bytes,2,opt,name=schema,proto3" json:"schema,omitempty"` + Signatures []*SignInfo `protobuf:"bytes,3,rep,name=signatures,proto3" json:"signatures,omitempty"` +} + +func (m *MsgCreateSchema) Reset() { *m = MsgCreateSchema{} } +func (m *MsgCreateSchema) String() string { return proto.CompactTextString(m) } +func (*MsgCreateSchema) ProtoMessage() {} +func (*MsgCreateSchema) Descriptor() ([]byte, []int) { + return fileDescriptor_73a1aa6c7279248b, []int{8} +} +func (m *MsgCreateSchema) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateSchema) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateSchema.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateSchema) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateSchema.Merge(m, src) +} +func (m *MsgCreateSchema) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateSchema) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateSchema.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateSchema proto.InternalMessageInfo + +func (m *MsgCreateSchema) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCreateSchema) GetSchema() *Schema { + if m != nil { + return m.Schema + } + return nil +} + +func (m *MsgCreateSchema) GetSignatures() []*SignInfo { + if m != nil { + return m.Signatures + } + return nil +} + +type MsgCreateSchemaResponse struct { + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *MsgCreateSchemaResponse) Reset() { *m = MsgCreateSchemaResponse{} } +func (m *MsgCreateSchemaResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreateSchemaResponse) ProtoMessage() {} +func (*MsgCreateSchemaResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_73a1aa6c7279248b, []int{9} +} +func (m *MsgCreateSchemaResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreateSchemaResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreateSchemaResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCreateSchemaResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreateSchemaResponse.Merge(m, src) +} +func (m *MsgCreateSchemaResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreateSchemaResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreateSchemaResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreateSchemaResponse proto.InternalMessageInfo + +func (m *MsgCreateSchemaResponse) GetId() uint64 { + if m != nil { + return m.Id + } + return 0 +} + func init() { proto.RegisterType((*MsgCreateDID)(nil), "hypersignprotocol.hidnode.ssi.MsgCreateDID") proto.RegisterType((*DidDocStructCreateDID)(nil), "hypersignprotocol.hidnode.ssi.DidDocStructCreateDID") @@ -612,50 +716,57 @@ func init() { proto.RegisterType((*SignInfo)(nil), "hypersignprotocol.hidnode.ssi.SignInfo") proto.RegisterType((*MsgUpdateDID)(nil), "hypersignprotocol.hidnode.ssi.MsgUpdateDID") proto.RegisterType((*MsgUpdateDIDResponse)(nil), "hypersignprotocol.hidnode.ssi.MsgUpdateDIDResponse") + proto.RegisterType((*MsgCreateSchema)(nil), "hypersignprotocol.hidnode.ssi.MsgCreateSchema") + proto.RegisterType((*MsgCreateSchemaResponse)(nil), "hypersignprotocol.hidnode.ssi.MsgCreateSchemaResponse") } func init() { proto.RegisterFile("ssi/v1/tx.proto", fileDescriptor_73a1aa6c7279248b) } var fileDescriptor_73a1aa6c7279248b = []byte{ - // 602 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x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xdc, 0x5a, 0x7a, 0xef, 0x86, 0x4c, 0x45, - 0xd9, 0xcc, 0x0e, 0x44, 0xec, 0x34, 0xc4, 0xbb, 0x35, 0xb3, 0x13, 0x31, 0xb2, 0x5b, 0x50, 0x3b, - 0x17, 0x4e, 0xf1, 0xdf, 0x5a, 0x7c, 0xe6, 0x72, 0xb6, 0xa2, 0xcb, 0x7b, 0x3f, 0x02, 0x00, 0x00, - 0xff, 0xff, 0x88, 0x58, 0xba, 0x77, 0x6f, 0x07, 0x00, 0x00, + // 680 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0x4f, 0x6b, 0xd4, 0x40, + 0x14, 0x6f, 0x36, 0xb5, 0x6d, 0xde, 0x2e, 0x5d, 0x18, 0xab, 0x86, 0x45, 0x97, 0x25, 0x60, 0x5d, + 0x91, 0x66, 0x31, 0xad, 0xe2, 0xc5, 0x83, 0x75, 0x41, 0x16, 0x5b, 0x90, 0x14, 0x41, 0x3c, 0x58, + 0xb2, 0xc9, 0x34, 0x19, 0x6c, 0x66, 0x42, 0x66, 0x76, 0xe9, 0x7e, 0x0b, 0x2f, 0x7e, 0x12, 0xbf, + 0x84, 0xe0, 0xa5, 0x47, 0xc1, 0x8b, 0xb4, 0x5f, 0x44, 0x32, 0xf9, 0xb3, 0xd9, 0xb4, 0xba, 0x5b, + 0x05, 0xbd, 0x78, 0xcb, 0x7b, 0xef, 0xf7, 0xfe, 0xcc, 0xef, 0x37, 0xbc, 0x09, 0x34, 0x39, 0x27, + 0xbd, 0xf1, 0xc3, 0x9e, 0x38, 0x31, 0xa3, 0x98, 0x09, 0x86, 0xee, 0x04, 0x93, 0x08, 0xc7, 0x9c, + 0xf8, 0x54, 0xda, 0x2e, 0x3b, 0x36, 0x03, 0xe2, 0x51, 0xe6, 0x61, 0x93, 0x73, 0xd2, 0xba, 0x9e, + 0xe1, 0xb9, 0x1b, 0xe0, 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ference imports to suppress errors if they are not otherwise used. @@ -672,6 +783,7 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { CreateDID(ctx context.Context, in *MsgCreateDID, opts ...grpc.CallOption) (*MsgCreateDIDResponse, error) UpdateDID(ctx context.Context, in *MsgUpdateDID, opts ...grpc.CallOption) (*MsgUpdateDIDResponse, error) + CreateSchema(ctx context.Context, in *MsgCreateSchema, opts ...grpc.CallOption) (*MsgCreateSchemaResponse, error) } type msgClient struct { @@ -700,10 +812,20 @@ func (c *msgClient) UpdateDID(ctx context.Context, in *MsgUpdateDID, opts ...grp return out, nil } +func (c *msgClient) CreateSchema(ctx context.Context, in *MsgCreateSchema, opts ...grpc.CallOption) (*MsgCreateSchemaResponse, error) { + out := new(MsgCreateSchemaResponse) + err := c.cc.Invoke(ctx, "/hypersignprotocol.hidnode.ssi.Msg/CreateSchema", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { CreateDID(context.Context, *MsgCreateDID) (*MsgCreateDIDResponse, error) UpdateDID(context.Context, *MsgUpdateDID) (*MsgUpdateDIDResponse, error) + CreateSchema(context.Context, *MsgCreateSchema) (*MsgCreateSchemaResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -716,6 +838,9 @@ func (*UnimplementedMsgServer) CreateDID(ctx context.Context, req *MsgCreateDID) func (*UnimplementedMsgServer) UpdateDID(ctx context.Context, req *MsgUpdateDID) (*MsgUpdateDIDResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdateDID not implemented") } +func (*UnimplementedMsgServer) CreateSchema(ctx context.Context, req *MsgCreateSchema) (*MsgCreateSchemaResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateSchema not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -757,6 +882,24 @@ func _Msg_UpdateDID_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +func _Msg_CreateSchema_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreateSchema) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreateSchema(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/hypersignprotocol.hidnode.ssi.Msg/CreateSchema", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreateSchema(ctx, req.(*MsgCreateSchema)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "hypersignprotocol.hidnode.ssi.Msg", HandlerType: (*MsgServer)(nil), @@ -769,6 +912,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UpdateDID", Handler: _Msg_UpdateDID_Handler, }, + { + MethodName: "CreateSchema", + Handler: _Msg_CreateSchema_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "ssi/v1/tx.proto", @@ -1266,6 +1413,90 @@ func (m *MsgUpdateDIDResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgCreateSchema) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateSchema) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateSchema) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signatures) > 0 { + for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Signatures[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Schema != nil { + { + size, err := m.Schema.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreateSchemaResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCreateSchemaResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreateSchemaResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Id != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Id)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1520,6 +1751,41 @@ func (m *MsgUpdateDIDResponse) Size() (n int) { return n } +func (m *MsgCreateSchema) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Schema != nil { + l = m.Schema.Size() + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Signatures) > 0 { + for _, e := range m.Signatures { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgCreateSchemaResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Id != 0 { + n += 1 + sovTx(uint64(m.Id)) + } + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -3081,6 +3347,227 @@ func (m *MsgUpdateDIDResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgCreateSchema) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateSchema: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateSchema: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Schema", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Schema == nil { + m.Schema = &Schema{} + } + if err := m.Schema.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signatures = append(m.Signatures, &SignInfo{}) + if err := m.Signatures[len(m.Signatures)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreateSchemaResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCreateSchemaResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreateSchemaResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + m.Id = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Id |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/ssi/utils/utils.go b/x/ssi/utils/utils.go index bbdf4ed..44fcfa8 100644 --- a/x/ssi/utils/utils.go +++ b/x/ssi/utils/utils.go @@ -3,7 +3,9 @@ package utils import ( "crypto/ed25519" "encoding/base64" + "errors" "fmt" + "regexp" "strings" "github.com/hypersign-protocol/hid-node/x/ssi/types" @@ -124,3 +126,25 @@ func FindVerificationMethod(vms []*types.PublicKeyStruct, id string) *types.Publ return nil } + +func IsValidSchemaID(schemaId string) error { + IdComponents := strings.Split(schemaId, ";") + if len(IdComponents) != 3 { + return errors.New("Expected 3 components in schema ID after being seperated by `;`, got " + fmt.Sprint(len(IdComponents)) + " components. The Schema ID is `" + schemaId + "` ") + } + + //Checking the prefix + if !strings.HasPrefix(IdComponents[0], "did:hs:") { + return errors.New("Expected did:hs as prefix in schema ID, The Schema ID is " + schemaId) + } + + //Checking the type of version + versionNumber := strings.Split(IdComponents[2], "=")[1] + // TODO: The regex pattern should be configurable to match the version format. + // Currently it's set for floating point validation + regexPatternForVersion := regexp.MustCompile(`^(?:(?:0|[1-9]\d*)(?:\.\d*)?|\.\d+)$`) + if !regexPatternForVersion.MatchString(versionNumber) { + return fmt.Errorf("input version Id -> `%s`, is an invalid format", versionNumber) + } + return nil +}