Skip to content

Commit

Permalink
feat(client/v2/offchain): sign and verify file (#18626)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 24, 2024
1 parent bda2d11 commit 61c367d
Show file tree
Hide file tree
Showing 16 changed files with 2,035 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* [#18626](https://github.com/cosmos/cosmos-sdk/pull/18626) Support for off-chain signing and verification of a file.
* [#18461](https://github.com/cosmos/cosmos-sdk/pull/18461) Support governance proposals.
* [#19039](https://github.com/cosmos/cosmos-sdk/pull/19039) Add support for pubkey in autocli.

Expand Down
57 changes: 57 additions & 0 deletions client/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,60 @@ https://github.com/cosmos/cosmos-sdk/blob/main/client/grpc/cmtservice/autocli.go
To further enhance your CLI experience with Cosmos SDK-based blockchains, you can use `hubl`. `hubl` is a tool that allows you to query any Cosmos SDK-based blockchain using the new AutoCLI feature of the Cosmos SDK. With `hubl`, you can easily configure a new chain and query modules with just a few simple commands.

For more information on `hubl`, including how to configure a new chain and query a module, see the [Hubl documentation](https://docs.cosmos.network/main/tooling/hubl).

# Off-Chain

Off-chain functionalities allow you to sign and verify files with two commands:
+ `sign-file` for signing a file.
+ `verify-file` for verifying a previously signed file.

Signing a file will result in a Tx with a `MsgSignArbitraryData` as described in the [Off-chain CIP](https://github.com/cosmos/cips/blob/main/cips/cip-X.md).

## Sign a file

To sign a file `sign-file` command offers some helpful flags:
```text
--encoding string Choose an encoding method for the file content to be added as msg data (no-encoding|base64|hex) (default "no-encoding")
--indent string Choose an indent for the tx (default " ")
--notEmitUnpopulated Don't show unpopulated fields in the tx
--output string Choose an output format for the tx (json|text (default "json")
--output-document string The document will be written to the given file instead of STDOUT
```

The `encoding` flag lets you choose how the contents of the file should be encoded. For example:
+ `simd off-chain sign-file alice myFile.json`
+ ```json
{
"@type": "/offchain.MsgSignArbitraryData",
"appDomain": "simd",
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
"data": "Hello World!\n"
}
```
+ `simd off-chain sign-file alice myFile.json --encoding base64`
+ ```json
{
"@type": "/offchain.MsgSignArbitraryData",
"appDomain": "simd",
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
"data": "SGVsbG8gV29ybGQhCg=="
}
```
+ `simd off-chain sign-file alice myFile.json --encoding hex`
+ ```json
{
"@type": "/offchain.MsgSignArbitraryData",
"appDomain": "simd",
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
"data": "48656c6c6f20576f726c64210a"
}
```

## Verify a file

To verify a file only the key name used and the previously signed file are needed.

```text
➜ simd off-chain verify-file alice signedFile.json
Verification OK!
```
20 changes: 20 additions & 0 deletions client/v2/internal/offchain/msgSignArbitraryData.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package offchain;

import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";

// MsgSignArbitraryData defines an arbitrary, general-purpose, off-chain message
message MsgSignArbitraryData {
option (amino.name) = "offchain/MsgSignArbitraryData";
option (cosmos.msg.v1.signer) = "signer";
// AppDomain is the application requesting off-chain message signing
string app_domain = 1;
// Signer is the sdk.AccAddress of the message signer
string signer = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Data represents the raw bytes of the content that is signed (text, json, etc)
string data = 3;
}

Loading

0 comments on commit 61c367d

Please sign in to comment.