Skip to content

Commit

Permalink
Problem: encryption-key cmd is not supported (crypto-org-chain#1409)
Browse files Browse the repository at this point in the history
* Problem: encryption-key cmd is not supported

* gen doc

* add validate
  • Loading branch information
mmsqe authored and yihuang committed Apr 30, 2024
1 parent 45f0f62 commit d3592da
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

* (rpc) [#1397](https://github.com/crypto-org-chain/cronos/pull/1397) Avoid panic on invalid elasticity_multiplier.

### Features

* [#1406](https://github.com/crypto-org-chain/cronos/pull/1406) Add set-encryption-key for encryption module.

*April 8, 2024*

## v1.2.0
Expand Down
8 changes: 8 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
}
}
},
{
"url": "./tmp-swagger-gen/e2ee/query.swagger.json",
"operationIds": {
"rename": {
"Params": "Keys"
}
}
},
{
"url": "./tmp-swagger-gen/ethermint/evm/v1/query.swagger.json",
"operationIds": {
Expand Down
50 changes: 50 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,49 @@ paths:
type: string
tags:
- Query
/e2ee/v1/key/{address}:
get:
summary: Key queries the encryption key of a given address
operationId: Key
responses:
'200':
description: A successful response.
schema:
type: object
properties:
key:
type: string
format: byte
description: KeyResponse is the response type for the Query/Key RPC method.
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: address
in: path
required: true
type: string
tags:
- Query
/ethermint/evm/v1/account/{address}:
get:
summary: Account queries an Ethereum account.
Expand Down Expand Up @@ -43217,6 +43260,13 @@ definitions:
"@type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}
e2ee.KeyResponse:
type: object
properties:
key:
type: string
format: byte
description: KeyResponse is the response type for the Query/Key RPC method.
ethermint.evm.v1.ChainConfig:
type: object
properties:
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
ibc_cro_denom: '${IBC_CRO_DENOM}',
},
},
e2ee: {
keys: [{
address: 'crc16z0herz998946wr659lr84c8c556da55dc34hh',
key: std.base64('key'),
}],
},
gov: {
params: {
voting_period: '10s',
Expand Down
30 changes: 30 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,3 +1814,33 @@ def event_query_tx_for(self, hash):
def query_bank_send(self):
res = json.loads(self.raw("q", "bank", "send-enabled", home=self.data_dir))
return res["send_enabled"]

def query_e2ee_key(self, address):
return json.loads(
self.raw(
"q",
"e2ee",
"key",
address,
home=self.data_dir,
output="json",
)
)

def set_e2ee_key(self, key, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
kwargs.setdefault("gas", DEFAULT_GAS)
rsp = json.loads(
self.raw(
"tx",
"e2ee",
"set-encryption-key",
key,
"-y",
home=self.data_dir,
**kwargs,
)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp
10 changes: 10 additions & 0 deletions integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import base64


def test_set_key(cronos):
cli = cronos.cosmos_cli()
key = base64.b64encode(b"new_key").decode("utf-8")
cli.set_e2ee_key(key, _from="community")
adr = cli.address("community")
p = cli.query_e2ee_key(adr)
assert p["key"] == key
13 changes: 13 additions & 0 deletions x/e2ee/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,18 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: "e2ee.Msg",
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "RegisterEncryptionKey",
Use: "set-encryption-key [key]",
Short: "Set encryption key is stored associated with the user address.",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "key"},
},
},
},
},
}
}
5 changes: 5 additions & 0 deletions x/e2ee/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ func DefaultGenesis() *GenesisState {
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
for _, key := range gs.Keys {
if err := key.Validate(); err != nil {
return err
}
}
return nil
}
13 changes: 13 additions & 0 deletions x/e2ee/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -27,3 +29,14 @@ func KeyPrefix(addr sdk.AccAddress) []byte {
copy(key[1:], addr)
return key
}

// Validate checks for address and key correctness.
func (e EncryptionKeyEntry) Validate() error {
if _, err := sdk.AccAddressFromBech32(e.Address); err != nil {
return err
}
if e.Key == nil {
return errors.New("key can't be nil")
}
return nil
}

0 comments on commit d3592da

Please sign in to comment.