Skip to content

Commit

Permalink
adding arbitrary operation signing
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Jun 13, 2024
1 parent 0824b39 commit 5dca9be
Show file tree
Hide file tree
Showing 16 changed files with 829 additions and 88 deletions.
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,18 @@ require (
github.com/tidwall/sjson v1.2.5
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/net v0.24.0
golang.org/x/text v0.14.0
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
golang.org/x/text v0.15.0
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
sigs.k8s.io/yaml v1.4.0
)

require github.com/rs/zerolog v1.29.1 // indirect

require (
cloud.google.com/go v0.112.2 // indirect
cloud.google.com/go/compute v1.25.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/storage v1.39.1 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
Expand Down Expand Up @@ -93,6 +92,7 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/github/smimesign v0.2.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
Expand All @@ -117,7 +117,7 @@ require (
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down Expand Up @@ -197,15 +197,14 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.170.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
32 changes: 15 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,12 @@ cloud.google.com/go/compute v1.12.1/go.mod h1:e8yNOBcBONZU1vJKCvCoDw/4JQsA0dpM4x
cloud.google.com/go/compute v1.13.0/go.mod h1:5aPTS0cUNMIc1CE546K+Th6weJUNQErARyZtRXDJ8GE=
cloud.google.com/go/compute v1.14.0/go.mod h1:YfLtxrj9sU4Yxv+sXzZkyPjEyPBZfXHUvjxega5vAdo=
cloud.google.com/go/compute v1.18.0/go.mod h1:1X7yHxec2Ga+Ss6jPyjxRxpu2uu7PLgsOVXvgU0yacs=
cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU=
cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls=
cloud.google.com/go/compute/metadata v0.1.0/go.mod h1:Z1VN+bulIf6bt4P/C37K4DyZYZEXYonfTBHHFPO/4UU=
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
cloud.google.com/go/compute/metadata v0.2.1/go.mod h1:jgHgmJd2RKBGzXqF5LR2EZMGxBkeanZ9wwa75XHJgOM=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
cloud.google.com/go/contactcenterinsights v1.3.0/go.mod h1:Eu2oemoePuEFc/xKFPjbTuPSj0fYJcPls9TFlPNnHHY=
cloud.google.com/go/contactcenterinsights v1.4.0/go.mod h1:L2YzkGbPsv+vMQMCADxJoT9YiTTnSEd6fEvCeHTYVck=
cloud.google.com/go/contactcenterinsights v1.6.0/go.mod h1:IIDlT6CLcDoyv79kDv8iWxMSTZhLxSCofVV5W6YFM/w=
Expand Down Expand Up @@ -809,6 +808,7 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -1045,8 +1045,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 h1:/c3QmbOGMGTOumP2iT/rCwB7b0QDGLKzqOmktBjT+Is=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1/go.mod h1:5SN9VR2LTsRFsrEC6FHgRbTWrTHu6tqPeKxEQv15giM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down Expand Up @@ -1832,8 +1832,8 @@ golang.org/x/oauth2 v0.0.0-20221006150949-b44042a4b9c1/go.mod h1:h4gKUeWbJ4rQPri
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg=
golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I=
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI=
golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8=
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -1993,8 +1993,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -2161,8 +2161,6 @@ google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down Expand Up @@ -2296,10 +2294,10 @@ google.golang.org/genproto v0.0.0-20230222225845-10f96fb3dbec/go.mod h1:3Dl5ZL0q
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s=
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be h1:g4aX8SUFA8V5F4LrSY5EclyGYw1OZN4HS1jTyjB9ZDc=
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be/go.mod h1:FeSdT5fk+lkxatqJP38MsUicGqHax5cLtmy/6TAuxO4=
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be h1:Zz7rLWqp0ApfsR/l7+zSHhY3PMiH2xqgxlfYfAfNpoU=
google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be/go.mod h1:dvdCTIoAGbkWbcIKBniID56/7XHTt6WfxXNMxuziJ+w=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be h1:LG9vZxsWGOmUKieR8wPAUR3u3MpnYFQZROPIMaXh7/A=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No=
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM=
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
Expand All @@ -2319,8 +2317,8 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
12 changes: 12 additions & 0 deletions proto/rarimocore/op_arbitrary.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package rarimo.rarimocore.rarimocore;

import "rarimocore/params.proto";

option go_package = "github.com/rarimo/rarimo-core/x/rarimocore/types";

message Arbitrary {
// Hex encoded data to be signed. AWARE do not make collisions with existing operations.
string data = 1;
}

1 change: 1 addition & 0 deletions proto/rarimocore/operation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum OpType {
IDENTITY_STATE_TRANSFER = 7;
WORLDCOIN_IDENTITY_TRANSFER = 8;
CSCA_ROOT_UPDATE = 9;
ARBITRARY = 10;
}

enum OpStatus {
Expand Down
7 changes: 7 additions & 0 deletions proto/rarimocore/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ message SlashProposal {
message DropPartiesProposal {
string title = 1;
string description = 2;
}

message ArbitrarySigningProposal {
string title = 1;
string description = 2;
// Hex encoded data to be signed. AWARE do not make collisions with existing operations.
string data = 3;
}
24 changes: 24 additions & 0 deletions x/rarimocore/crypto/operation/op_arbitrary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package operation

import (
"bytes"

eth "github.com/ethereum/go-ethereum/crypto"
merkle "github.com/rarimo/go-merkle"
)

// ArbitraryContent implements the Content interface provided by go-merkle and represents the content stored in the tree.
type ArbitraryContent struct {
Data []byte
}

var _ merkle.Content = ArbitraryContent{}

func (c ArbitraryContent) CalculateHash() []byte {
return eth.Keccak256(c.Data)
}

// Equals tests for equality of two Contents
func (c ArbitraryContent) Equals(other merkle.Content) bool {
return bytes.Equal(other.CalculateHash(), c.CalculateHash())
}
19 changes: 19 additions & 0 deletions x/rarimocore/crypto/pkg/content/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func GetContents(client *grpc.ClientConn, operations ...*types.Operation) ([]mer
return nil, err
}

if content != nil {
contents = append(contents, content)
}
case types.OpType_ARBITRARY:
content, err := GetArbitraryContent(op)
if err != nil {
return nil, err
}

if content != nil {
contents = append(contents, content)
}
Expand Down Expand Up @@ -251,3 +260,13 @@ func GetCSCARootUpdateContent(op *types.Operation) (merkle.Content, error) {
content, err := pkg.GetCSCARootUpdateContent(update)
return content, errors.Wrap(err, "error creating content")
}

func GetArbitraryContent(op *types.Operation) (merkle.Content, error) {
update, err := pkg.GetArbitrary(*op)
if err != nil {
return nil, errors.Wrap(err, "error parsing operation details")
}

content, err := pkg.GetArbitraryContent(update)
return content, errors.Wrap(err, "error creating content")
}
24 changes: 24 additions & 0 deletions x/rarimocore/crypto/pkg/op_arbitrary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pkg

import (
"cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/gogo/protobuf/proto"
"github.com/rarimo/rarimo-core/x/rarimocore/crypto/operation"
"github.com/rarimo/rarimo-core/x/rarimocore/types"
)

func GetArbitrary(operation types.Operation) (*types.Arbitrary, error) {
if operation.OperationType == types.OpType_ARBITRARY {
op := new(types.Arbitrary)
return op, proto.Unmarshal(operation.Details.Value, op)
}
return nil, errors.Wrap(sdkerrors.ErrInvalidType, "invalid operation type")
}

func GetArbitraryContent(op *types.Arbitrary) (*operation.ArbitraryContent, error) {
return &operation.ArbitraryContent{
Data: hexutil.MustDecode(op.Data),
}, nil
}
38 changes: 38 additions & 0 deletions x/rarimocore/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,44 @@ func (k Keeper) CreateCSCARootUpdateOperation(ctx sdk.Context, creator string, u
return operation.Index, nil
}

func (k Keeper) CreateArbitraryOperation(ctx sdk.Context, creator string, arbitrary *types.Arbitrary) error {
details, err := cosmostypes.NewAnyWithValue(arbitrary)
if err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "error parsing details: %s", err.Error())
}

content, err := pkg.GetArbitraryContent(arbitrary)
if err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "error creating content: %s", err.Error())
}

operation := types.Operation{
Index: hexutil.Encode(content.CalculateHash()),
OperationType: types.OpType_ARBITRARY,
Details: details,
Status: types.OpStatus_INITIALIZED,
Creator: creator,
Timestamp: uint64(ctx.BlockTime().Unix()),
}

if _, ok := k.GetOperation(ctx, operation.Index); ok {
return errors.Wrapf(sdkerrors.ErrInvalidRequest, "that operation can not be changed")
}
k.SetOperation(ctx, operation)

ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeNewOperation,
sdk.NewAttribute(types.AttributeKeyOperationId, operation.Index),
sdk.NewAttribute(types.AttributeKeyOperationType, operation.OperationType.String()),
))

// Operation is auto-approved (cause created by EndBlock)
if err = k.ApproveOperation(ctx, operation); err != nil {
return errors.Wrap(err, "failed to auto-approve operation")
}

return nil
}

func (k Keeper) GetTransfer(ctx sdk.Context, msg *oracletypes.MsgCreateTransferOp) (*types.Transfer, error) {
hash := origin.NewDefaultOriginBuilder().
SetTxHash(msg.Tx).
Expand Down
4 changes: 4 additions & 0 deletions x/rarimocore/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ func (k Keeper) DropPartiesProposal(ctx sdk.Context, _ *types.DropPartiesProposa
k.SetParams(ctx, params)
return nil
}

func (k Keeper) ArbitrarySigningProposal(ctx sdk.Context, proposal *types.ArbitrarySigningProposal) error {
return k.CreateArbitraryOperation(ctx, types.ModuleName, &types.Arbitrary{Data: proposal.Data})
}
2 changes: 2 additions & 0 deletions x/rarimocore/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func NewProposalHandler(k keeper.Keeper) govv1beta1.Handler {
return k.SlashProposal(ctx, c)
case *types.DropPartiesProposal:
return k.DropPartiesProposal(ctx, c)
case *types.ArbitrarySigningProposal:
return k.ArbitrarySigningProposal(ctx, c)
default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized proposal content type: %T", c)
}
Expand Down
6 changes: 6 additions & 0 deletions x/rarimocore/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&ReshareKeysProposal{}, "rarimocore/ReshareKeysProposal", nil)
cdc.RegisterConcrete(&SlashProposal{}, "rarimocore/SlashProposal", nil)
cdc.RegisterConcrete(&DropPartiesProposal{}, "rarimocore/DropPartiesProposal", nil)
cdc.RegisterConcrete(&ArbitrarySigningProposal{}, "rarimocore/ArbitrarySigningProposal", nil)
// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -73,6 +74,11 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&DropPartiesProposal{},
)

registry.RegisterImplementations(
(*govv1beta1.Content)(nil),
&ArbitrarySigningProposal{},
)

registry.RegisterInterface(
"rarimo.rarimocore.rarimocore.Transfer",
(*proto.Message)(nil),
Expand Down
Loading

0 comments on commit 5dca9be

Please sign in to comment.