Skip to content

Commit

Permalink
Merge pull request #20 from eco-stake/configurable-prevent-authz-exec…
Browse files Browse the repository at this point in the history
…-types

Configurable prevented authz exec types
  • Loading branch information
tombeynon authored Jun 23, 2023
2 parents 43dfe3d + f38a597 commit c53fca3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
7 changes: 7 additions & 0 deletions src/adapters/DefaultSigningAdapter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ export default class DefaultSigningAdapter {
throw new Error('This chain does not fully support amino conversion for Authz messages, using signDirect instead')
}
}
if(message.typeUrl === '/cosmos.authz.v1beta1.MsgExec'){
const execTypes = message.value.msgs.map(msg => msg.typeUrl)
const preventedTypes = execTypes.filter(type => this.network.authzAminoExecPreventTypes.some(prevent => type.match(_.escapeRegExp(prevent))))
if(preventedTypes.length > 0){
throw new Error(`This chain does not support amino conversion for Authz Exec with types: ${preventedTypes.join(', ')}`)
}
}
let aminoMessage = this.aminoTypes.toAmino(message)
if(this.network.authzAminoLiftedValues){
switch (aminoMessage.type) {
Expand Down
16 changes: 0 additions & 16 deletions src/adapters/OsmosisSigningAdapter.mjs

This file was deleted.

30 changes: 24 additions & 6 deletions src/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"maxPerDay": 1,
"apiVersions": {
"gov": "v1beta1"
}
},
"authzAminoExecPreventTypes": [
"/cosmos.gov."
]
},
{
"name": "juno",
Expand All @@ -28,7 +31,10 @@
},
{
"name": "regen",
"ownerAddress": "regenvaloper1c4y3j05qx652rnxm5mg4yesqdkmhz2f6dl7hhk"
"ownerAddress": "regenvaloper1c4y3j05qx652rnxm5mg4yesqdkmhz2f6dl7hhk",
"authzAminoExecPreventTypes": [
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"
]
},
{
"name": "terra",
Expand Down Expand Up @@ -58,7 +64,10 @@
},
{
"name": "cryptoorgchain",
"ownerAddress": "crocncl10mfs428fyntu296dgh5fmhvdzrr2stlaekcrp9"
"ownerAddress": "crocncl10mfs428fyntu296dgh5fmhvdzrr2stlaekcrp9",
"authzAminoExecPreventTypes": [
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"
]
},
{
"name": "evmos",
Expand All @@ -81,7 +90,10 @@
"ownerAddress": "comdexvaloper17f70yjkvmvld379904jaddx9h0f74n32pjtmp6",
"apiVersions": {
"gov": "v1beta1"
}
},
"authzAminoExecPreventTypes": [
"/cosmos.gov."
]
},
{
"name": "cheqd"
Expand Down Expand Up @@ -209,7 +221,10 @@
},
{
"name": "mars",
"ownerAddress": "marsvaloper1hvtaqw9mlwc0a4cdx6g3klk8acfc6z3yazzk8a"
"ownerAddress": "marsvaloper1hvtaqw9mlwc0a4cdx6g3klk8acfc6z3yazzk8a",
"authzAminoExecPreventTypes": [
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"
]
},
{
"name": "planq"
Expand All @@ -223,7 +238,10 @@
},
{
"name": "kyve",
"ownerAddress": "kyvevaloper1egqphd8yjdfv84fl825grwgna0pf2emagdmnz8"
"ownerAddress": "kyvevaloper1egqphd8yjdfv84fl825grwgna0pf2emagdmnz8",
"authzAminoExecPreventTypes": [
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"
]
},
{
"name": "quicksilver",
Expand Down
2 changes: 2 additions & 0 deletions src/utils/Chain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Chain = (data) => {
const authzAminoSupport = data.authzAminoSupport ?? true
const authzAminoGenericOnly = authzAminoSupport && (data.authzAminoGenericOnly ?? !sdkAuthzAminoSupport)
const authzAminoLiftedValues = authzAminoSupport && (data.authzAminoLiftedValues ?? authzAminoGenericOnly)
const authzAminoExecPreventTypes = data.authzAminoExecPreventTypes || []
const apiVersions = {
gov: sdk46OrLater ? 'v1' : 'v1beta1',
...data.apiVersions || {}
Expand All @@ -30,6 +31,7 @@ const Chain = (data) => {
authzAminoSupport,
authzAminoGenericOnly,
authzAminoLiftedValues,
authzAminoExecPreventTypes,
apiVersions,
denom: data.denom || baseAsset?.base?.denom,
display: data.display || baseAsset?.display?.denom,
Expand Down
1 change: 1 addition & 0 deletions src/utils/Network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Network {
this.authzAminoSupport = this.chain.authzAminoSupport
this.authzAminoGenericOnly = this.chain.authzAminoGenericOnly
this.authzAminoLiftedValues = this.chain.authzAminoLiftedValues
this.authzAminoExecPreventTypes = this.chain.authzAminoExecPreventTypes
this.txTimeout = this.data.txTimeout || 60_000
this.keywords = this.buildKeywords()

Expand Down
2 changes: 0 additions & 2 deletions src/utils/SigningClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx.js";

import { coin } from './Helpers.mjs'
import DefaultSigningAdapter from '../adapters/DefaultSigningAdapter.mjs';
import OsmosisSigningAdapter from '../adapters/OsmosisSigningAdapter.mjs';
import TerraSigningAdapter from '../adapters/TerraSigningAdapter.mjs';

const adapters = {
osmosis: OsmosisSigningAdapter,
terra: TerraSigningAdapter
}

Expand Down

0 comments on commit c53fca3

Please sign in to comment.