Skip to content

Commit

Permalink
Merge pull request #49 from hypersign-protocol/create-schema-module-ssi
Browse files Browse the repository at this point in the history
initial version of create-schema rpc
  • Loading branch information
arnabghose997 committed Feb 12, 2022
2 parents 93bfc82 + 10aab43 commit 95dde6a
Show file tree
Hide file tree
Showing 19 changed files with 2,196 additions and 53 deletions.
222 changes: 222 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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": <string>,
"lastName": <string>
}

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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions proto/ssi/v1/schema.proto
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions proto/ssi/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions utils/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"reflect"
"strings"
"unsafe"
)

Expand All @@ -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
}
1 change: 1 addition & 0 deletions x/ssi/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions x/ssi/client/cli/tx_ssi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions x/ssi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 95dde6a

Please sign in to comment.