Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: encryption-key cmd is not supported #1409

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-rc1
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 @@ -884,6 +884,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 @@ -45506,6 +45549,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 @@ -87,6 +87,12 @@
ibc_cro_denom: '${IBC_CRO_DENOM}',
},
},
e2ee: {
keys: [{
address: 'crc16z0herz998946wr659lr84c8c556da55dc34hh',
key: std.base64('key'),
}],
},
gov: {
params: {
expedited_voting_period: '1s',
Expand Down
30 changes: 30 additions & 0 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,3 +1840,33 @@ def query_bank_send(self, *denoms):
output="json",
)
).get("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 @@
// 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

Check warning on line 13 in x/e2ee/types/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/genesis.go#L13

Added line #L13 was not covered by tests
}
}
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 @@
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

Check warning on line 36 in x/e2ee/types/keys.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/keys.go#L36

Added line #L36 was not covered by tests
}
if e.Key == nil {
return errors.New("key can't be nil")

Check warning on line 39 in x/e2ee/types/keys.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/keys.go#L39

Added line #L39 was not covered by tests
}
return nil
}
Loading