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

feat: add amino signing support #69

Merged
merged 30 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d79e95d
feat: add amino signing support
ryanchristo May 23, 2023
aabd1da
Merge branch 'main' into ryan/10-amino-signing-support
ryanchristo Jun 12, 2023
98d80ad
encoded msg and comments
ryanchristo Jun 13, 2023
18acc7c
auto or only amino
ryanchristo Jun 13, 2023
9793b17
metadata whitepace
ryanchristo Jun 15, 2023
6e51ea2
policy as admin todo
ryanchristo Jun 15, 2023
c524286
todo and format
ryanchristo Jun 15, 2023
6927a41
Merge branch 'main' into ryan/10-amino-signing-support
ryanchristo Jun 15, 2023
788256c
bump regen api version
ryanchristo Jun 15, 2023
23bda00
update create group policy
ryanchristo Jun 15, 2023
4f07e1f
vote metadata and todo
ryanchristo Jun 15, 2023
cda072a
update notes and todos
ryanchristo Jun 16, 2023
85de73e
fix create group with policy
ryanchristo Jun 29, 2023
f5c3bea
fix vote on proposal
ryanchristo Jun 29, 2023
82912bd
fix group amino converters
ryanchristo Jul 3, 2023
37e6dc8
fix group amino converters
ryanchristo Jul 3, 2023
a4189bb
fix group amino converters
ryanchristo Jul 3, 2023
14ec299
resolve internal ts and cleanup
ryanchristo Jul 4, 2023
868b9d5
Merge branch 'dev' into ryan/10-amino-signing-support
ryanchristo Jul 10, 2023
e2ec043
Merge branch 'dev' into ryan/10-amino-signing-support
ryanchristo Jul 10, 2023
e0db481
Merge branch 'dev' into ryan/10-amino-signing-support
ryanchristo Jul 12, 2023
57173db
fix internal typescript error
ryanchristo Jul 12, 2023
29e58c4
bump api package and cleanup
ryanchristo Jul 13, 2023
335c7d6
update comments and todos
ryanchristo Jul 13, 2023
5788aea
Merge branch 'dev' into ryan/10-amino-signing-support
ryanchristo Jul 18, 2023
a08e5d5
fix and add amino converters to workaround
ryanchristo Jul 18, 2023
de9fe9f
fix update decision policy proposal
ryanchristo Jul 24, 2023
04d9932
fix update group members proposal
ryanchristo Jul 24, 2023
8cb810a
bump api package version
ryanchristo Jul 24, 2023
fa6f45d
fix: MsgSubmitProposal with update decision policy toAmino converter …
blushi Jul 25, 2023
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"@chakra-ui/react": "^2.7.0",
"@cosmjs/amino": "0.29.5",
"@cosmjs/launchpad": "^0.27.1",
"@cosmjs/proto-signing": "0.29.4",
"@cosmjs/stargate": "0.29.4",
"@cosmjs/tendermint-rpc": "^0.29.4",
"@cosmjs/proto-signing": "0.29.5",
"@cosmjs/stargate": "0.29.5",
"@cosmjs/tendermint-rpc": "^0.29.5",
"@emotion/react": "^11.10.8",
"@emotion/styled": "^11.10.8",
"@hookform/resolvers": "^3.1.0",
"@keplr-wallet/cosmos": "^0.11.59",
"@keplr-wallet/stores": "^0.11.59",
"@osmonauts/helpers": "^0.7.0",
"@regen-network/api": "^1.0.0-alpha1",
"@regen-network/api": "../regen-js/packages/api",
"@tanstack/react-query": "^4.29.5",
"@tanstack/react-table": "^8.9.1",
"chakra-react-select": "^4.4.3",
Expand Down
12 changes: 10 additions & 2 deletions src/api/group.messages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { MsgCreateGroupWithPolicyEncoded } from '@regen-network/api/types/codegen/cosmos/group/v1/tx'
import Long from 'long'

import type { GroupWithPolicyFormValues, UIGroupMetadata } from 'types'
Expand All @@ -20,7 +21,9 @@ export function msgCreateGroupWithPolicy(values: GroupWithPolicyFormValues) {
policyType,
votingWindow,
} = values
return GroupMsgWithTypeUrl.createGroupWithPolicy({
// NOTE: We use the encoded msg type to support amino signing with nested types.
// See https://github.com/osmosis-labs/telescope/issues/281
const encodedMsg: MsgCreateGroupWithPolicyEncoded = {
admin,
groupPolicyMetadata: '',
groupPolicyAsAdmin: policyAsAdmin === 'true',
Expand All @@ -43,7 +46,12 @@ export function msgCreateGroupWithPolicy(values: GroupWithPolicyFormValues) {
metadata: '',
// metadata: JSON.stringify(m.metadata),
})),
})
}

return {
typeUrl: '/cosmos.group.v1.MsgCreateGroupWithPolicy',
value: encodedMsg,
}
}

export function msgUpdateGroupMetadata({
Expand Down
41 changes: 24 additions & 17 deletions src/api/policy.messages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { MsgUpdateGroupPolicyDecisionPolicyEncoded } from '@regen-network/api/types/codegen/cosmos/group/v1/tx'

import { GroupPolicyFormValues } from 'types'
import { daysToDuration, secondsToDuration } from 'util/date'
import { throwError } from 'util/errors'
import { numToPercentStr } from 'util/helpers'

import { GroupMsgWithTypeUrl, groupV1 } from './cosmosgroups'
import { groupV1 } from './cosmosgroups'

export function msgUpdateDecisionPolicy({
admin,
Expand All @@ -20,7 +22,9 @@ export function msgUpdateDecisionPolicy({
threshold?: number
votingWindow: number
}) {
return GroupMsgWithTypeUrl.updateGroupPolicyDecisionPolicy({
// NOTE: We use the encoded msg type to support amino signing with nested types.
// See https://github.com/osmosis-labs/telescope/issues/281
const encodedMsg: MsgUpdateGroupPolicyDecisionPolicyEncoded = {
admin,
decisionPolicy: encodeDecisionPolicy({
percentage,
Expand All @@ -29,7 +33,12 @@ export function msgUpdateDecisionPolicy({
votingWindow,
}),
groupPolicyAddress: policyAddress,
})
}

return {
typeUrl: '/cosmos.group.v1.MsgUpdateGroupPolicyDecisionPolicy',
value: encodedMsg,
}
}

/** @returns gogo `Any` shaped encoded decision policy: `ThresholdDecisionPolicy`
Expand All @@ -55,22 +64,20 @@ export function encodeDecisionPolicy({
}
if (policyType === 'percentage') {
if (!percentage) throwError('Must provide percentage value')
return {
typeUrl: '/cosmos.group.v1.PercentageDecisionPolicy',
value: groupV1.PercentageDecisionPolicy.encode({
percentage: numToPercentStr(percentage),
windows,
}).finish(),
}
// NOTE: We convert the decision policy to a proto msg to support amino signing with nested types.
// See https://github.com/osmosis-labs/telescope/issues/281
return groupV1.PercentageDecisionPolicy.toProtoMsg({
percentage: numToPercentStr(percentage),
windows,
})
} else if (policyType === 'threshold') {
if (!threshold) throwError('Must provide threshold value')
return {
typeUrl: '/cosmos.group.v1.ThresholdDecisionPolicy',
value: groupV1.ThresholdDecisionPolicy.encode({
threshold: threshold.toString(),
windows,
}).finish(),
}
// NOTE: We convert the decision policy to a proto msg to support amino signing with nested types.
// See https://github.com/osmosis-labs/telescope/issues/281
return groupV1.ThresholdDecisionPolicy.toProtoMsg({
threshold: threshold.toString(),
windows,
})
} else {
throwError('Invalid policy type: ' + policyType)
}
Expand Down
16 changes: 16 additions & 0 deletions src/api/proposal.messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import { Exec } from '@regen-network/api/types/codegen/cosmos/group/v1/tx'
// import type { MsgSubmitProposalEncoded } from '@regen-network/api/types/codegen/cosmos/group/v1/tx'
import type { Any } from 'types'

import { GroupMsgWithTypeUrl } from './cosmosgroups'
Expand All @@ -25,4 +26,19 @@ export function msgSubmitProposal({
metadata,
proposers,
})

// NOTE: We use the encoded msg type to support amino signing with nested types.
// See https://github.com/osmosis-labs/telescope/issues/281
// const encodedMsg: MsgSubmitProposalEncoded = {
// exec,
// groupPolicyAddress,
// messages,
// metadata,
// proposers,
// }
//
// return {
// typeUrl: '/cosmos.group.v1.MsgSubmitProposal',
// value: encodedMsg,
// }
}
4 changes: 3 additions & 1 deletion src/components/organisms/proposal-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export const StakeReview = ({
{'toValidator' in values && (
<ReviewItem label="To validator">{values.toValidator}</ReviewItem>
)}
{'amount' in values && <ReviewItem label="Amount">{`${values.amount} ${values.denom}`}</ReviewItem>}
{'amount' in values && (
<ReviewItem label="Amount">{`${values.amount} ${values.denom}`}</ReviewItem>
)}
</Stack>
</FormCard>
)
Expand Down
33 changes: 26 additions & 7 deletions src/store/wallet.store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { type AccountData, coins, type EncodeObject } from '@cosmjs/proto-signing'
import type { SigningStargateClient } from '@cosmjs/stargate'
import { cosmos, getSigningCosmosClient } from '@regen-network/api'
import { Registry } from '@cosmjs/proto-signing'
import { AminoTypes, SigningStargateClient } from '@cosmjs/stargate'
import {
cosmos,
cosmosAminoConverters,
cosmosProtoRegistry,
getSigningCosmosClient,
} from '@regen-network/api'
import { proxy } from 'valtio'

import { logError, throwError } from 'util/errors'
Expand Down Expand Up @@ -35,12 +41,25 @@ export async function bootstrapKeplr() {
try {
await keplr.experimentalSuggestChain(Chain.active)
await keplr.enable(chainId)
const offlineSigner = keplr.getOfflineSigner(chainId)
// NOTE: We use "auto" to support amino signing with ledger devices.
// const offlineSigner = await keplr.getOfflineSignerAuto(chainId)
// NOTE: We use "only amino" to support amino signing with ledger devices.
// Using "only amino" also ensures messages are human-readable within keplr.
const offlineSigner = await keplr.getOfflineSignerOnlyAmino(chainId)
const [account] = await offlineSigner.getAccounts()
const signingClient = await getSigningCosmosClient({
rpcEndpoint: Chain.active.rpc,
signer: offlineSigner,
})
// const signingClient = await getSigningCosmosClient({
// rpcEndpoint: Chain.active.rpc,
// signer: offlineSigner,
// })

// NOTE: We use signing stargate client so that we can register types.
const registry = new Registry(cosmosProtoRegistry)
const signingClient = await SigningStargateClient.connectWithSigner(
Chain.active.rpc,
offlineSigner,
{ registry, aminoTypes: new AminoTypes({ ...cosmosAminoConverters }) },
)

const lcdClient = await cosmos.ClientFactory.createLCDClient({
restEndpoint: Chain.active.rest,
})
Expand Down
75 changes: 25 additions & 50 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2262,17 +2262,7 @@
"@cosmjs/math" "^0.29.0"
"@cosmjs/utils" "^0.29.0"

"@cosmjs/amino@0.29.4":
version "0.29.4"
resolved "https://registry.yarnpkg.com/@cosmjs/amino/-/amino-0.29.4.tgz#93d5f90033cb2af1573627582cd2cf8a515c3ef4"
integrity sha512-FBjaJ4oUKFtH34O7XjUk370x8sF7EbXD29miXrm0Rl5GEtEORJgQwutXQllHo5gBkpOxC+ZQ40CibXhPzH7G7A==
dependencies:
"@cosmjs/crypto" "^0.29.4"
"@cosmjs/encoding" "^0.29.4"
"@cosmjs/math" "^0.29.4"
"@cosmjs/utils" "^0.29.4"

"@cosmjs/amino@0.29.5", "@cosmjs/amino@^0.29.0", "@cosmjs/amino@^0.29.4", "@cosmjs/amino@^0.29.5":
"@cosmjs/amino@0.29.5", "@cosmjs/amino@^0.29.0", "@cosmjs/amino@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/amino/-/amino-0.29.5.tgz#053b4739a90b15b9e2b781ccd484faf64bd49aec"
integrity sha512-Qo8jpC0BiziTSUqpkNatBcwtKNhCovUnFul9SlT/74JUCdLYaeG5hxr3q1cssQt++l4LvlcpF+OUXL48XjNjLw==
Expand Down Expand Up @@ -2311,7 +2301,7 @@
elliptic "^6.5.3"
libsodium-wrappers "^0.7.6"

"@cosmjs/crypto@^0.29.0", "@cosmjs/crypto@^0.29.4", "@cosmjs/crypto@^0.29.5":
"@cosmjs/crypto@^0.29.0", "@cosmjs/crypto@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/crypto/-/crypto-0.29.5.tgz#ab99fc382b93d8a8db075780cf07487a0f9519fd"
integrity sha512-2bKkaLGictaNL0UipQCL6C1afaisv6k8Wr/GCLx9FqiyFkh9ZgRHDyetD64ZsjnWV/N/D44s/esI+k6oPREaiQ==
Expand Down Expand Up @@ -2342,7 +2332,7 @@
bech32 "^1.1.4"
readonly-date "^1.0.0"

"@cosmjs/encoding@^0.29.0", "@cosmjs/encoding@^0.29.4", "@cosmjs/encoding@^0.29.5":
"@cosmjs/encoding@^0.29.0", "@cosmjs/encoding@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.29.5.tgz#009a4b1c596cdfd326f30ccfa79f5e56daa264f2"
integrity sha512-G4rGl/Jg4dMCw5u6PEZHZcoHnUBlukZODHbm/wcL4Uu91fkn5jVo5cXXZcvs4VCkArVGrEj/52eUgTZCmOBGWQ==
Expand Down Expand Up @@ -2386,7 +2376,7 @@
dependencies:
bn.js "^4.11.8"

"@cosmjs/math@^0.29.0", "@cosmjs/math@^0.29.4", "@cosmjs/math@^0.29.5":
"@cosmjs/math@^0.29.0", "@cosmjs/math@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/math/-/math-0.29.5.tgz#722c96e080d6c2b62215ce9f4c70da7625b241b6"
integrity sha512-2GjKcv+A9f86MAWYLUkjhw1/WpRl2R1BTb3m9qPG7lzMA7ioYff9jY5SPCfafKdxM4TIQGxXQlYGewQL16O68Q==
Expand All @@ -2406,20 +2396,7 @@
cosmjs-types "^0.5.0"
long "^4.0.0"

"@cosmjs/proto-signing@0.29.4":
version "0.29.4"
resolved "https://registry.yarnpkg.com/@cosmjs/proto-signing/-/proto-signing-0.29.4.tgz#8f314a936f07d15f5414280bec8aabb6de4078db"
integrity sha512-GdLOhMd54LZgG+kHf7uAWGYDT628yVhXPMWaG/1i3f3Kq4VsZgFBwJhhziM5kWblmFjBOhooGRwLrBnOxMusCg==
dependencies:
"@cosmjs/amino" "^0.29.4"
"@cosmjs/crypto" "^0.29.4"
"@cosmjs/encoding" "^0.29.4"
"@cosmjs/math" "^0.29.4"
"@cosmjs/utils" "^0.29.4"
cosmjs-types "^0.5.2"
long "^4.0.0"

"@cosmjs/proto-signing@^0.29.0", "@cosmjs/proto-signing@^0.29.4":
"@cosmjs/proto-signing@0.29.5", "@cosmjs/proto-signing@^0.29.0", "@cosmjs/proto-signing@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/proto-signing/-/proto-signing-0.29.5.tgz#af3b62a46c2c2f1d2327d678b13b7262db1fe87c"
integrity sha512-QRrS7CiKaoETdgIqvi/7JC2qCwCR7lnWaUsTzh/XfRy3McLkEd+cXbKAW3cygykv7IN0VAEIhZd2lyIfT8KwNA==
Expand Down Expand Up @@ -2460,32 +2437,32 @@
protobufjs "~6.11.3"
xstream "^11.14.0"

"@cosmjs/stargate@0.29.4":
version "0.29.4"
resolved "https://registry.yarnpkg.com/@cosmjs/stargate/-/stargate-0.29.4.tgz#d66494ab8de8a886aedd46706a7560482cf18ad5"
integrity sha512-MEzBkOhYX0tdGgJg4mxFDjf7NMJYKNtXHX0Fu4HVACdBrxLlStf630KodmzPFlLOHfiz3CB/mqj3TobZZz8mTw==
"@cosmjs/stargate@0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/stargate/-/stargate-0.29.5.tgz#d597af1c85a3c2af7b5bdbec34d5d40692cc09e4"
integrity sha512-hjEv8UUlJruLrYGJcUZXM/CziaINOKwfVm2BoSdUnNTMxGvY/jC1ABHKeZUYt9oXHxEJ1n9+pDqzbKc8pT0nBw==
dependencies:
"@confio/ics23" "^0.6.8"
"@cosmjs/amino" "^0.29.4"
"@cosmjs/encoding" "^0.29.4"
"@cosmjs/math" "^0.29.4"
"@cosmjs/proto-signing" "^0.29.4"
"@cosmjs/stream" "^0.29.4"
"@cosmjs/tendermint-rpc" "^0.29.4"
"@cosmjs/utils" "^0.29.4"
"@cosmjs/amino" "^0.29.5"
"@cosmjs/encoding" "^0.29.5"
"@cosmjs/math" "^0.29.5"
"@cosmjs/proto-signing" "^0.29.5"
"@cosmjs/stream" "^0.29.5"
"@cosmjs/tendermint-rpc" "^0.29.5"
"@cosmjs/utils" "^0.29.5"
cosmjs-types "^0.5.2"
long "^4.0.0"
protobufjs "~6.11.3"
xstream "^11.14.0"

"@cosmjs/stream@^0.29.0", "@cosmjs/stream@^0.29.4", "@cosmjs/stream@^0.29.5":
"@cosmjs/stream@^0.29.0", "@cosmjs/stream@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/stream/-/stream-0.29.5.tgz#350981cac496d04939b92ee793b9b19f44bc1d4e"
integrity sha512-TToTDWyH1p05GBtF0Y8jFw2C+4783ueDCmDyxOMM6EU82IqpmIbfwcdMOCAm0JhnyMh+ocdebbFvnX/sGKzRAA==
dependencies:
xstream "^11.14.0"

"@cosmjs/tendermint-rpc@^0.29.0", "@cosmjs/tendermint-rpc@^0.29.4":
"@cosmjs/tendermint-rpc@^0.29.0", "@cosmjs/tendermint-rpc@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.29.5.tgz#f205c10464212bdf843f91bb2e4a093b618cb5c2"
integrity sha512-ar80twieuAxsy0x2za/aO3kBr2DFPAXDmk2ikDbmkda+qqfXgl35l9CVAAjKRqd9d+cRvbQyb5M4wy6XQpEV6w==
Expand All @@ -2511,7 +2488,7 @@
resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.20.1.tgz#4d239b7d93c15523cdf109f225cbf61326fb69cd"
integrity sha512-xl9YnIrAAaBd6nFffwFbyrnKjqjD9zKGP8OBKxzyglxamHfqAS+PcJPEiaEpt+oUt7HAIOyhL3KK75Dh52hGvA==

"@cosmjs/utils@^0.29.0", "@cosmjs/utils@^0.29.4", "@cosmjs/utils@^0.29.5":
"@cosmjs/utils@^0.29.0", "@cosmjs/utils@^0.29.5":
version "0.29.5"
resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.29.5.tgz#3fed1b3528ae8c5f1eb5d29b68755bebfd3294ee"
integrity sha512-m7h+RXDUxOzEOGt4P+3OVPX7PuakZT3GBmaM/Y2u+abN3xZkziykD/NvedYFvvCCdQo714XcGl33bwifS9FZPQ==
Expand Down Expand Up @@ -3949,16 +3926,14 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@regen-network/api@^1.0.0-alpha1":
version "1.0.0-alpha1"
resolved "https://registry.yarnpkg.com/@regen-network/api/-/api-1.0.0-alpha1.tgz#9dfd939556cf908c3239878a35aa5a524064d847"
integrity sha512-mkiXXK7H/uC5F+eXWFJIKkX+uPTbSNiidZT0dYiGI/QOxRfo0/HDzWLKZuvuqes4UgwKybz4zMNAFoMFp+7Hvg==
"@regen-network/api@../regen-js/packages/api":
version "1.0.0-beta1"
dependencies:
"@babel/runtime" "^7.19.4"
"@cosmjs/amino" "0.29.4"
"@cosmjs/proto-signing" "0.29.4"
"@cosmjs/stargate" "0.29.4"
"@cosmjs/tendermint-rpc" "^0.29.4"
"@cosmjs/amino" "0.29.5"
"@cosmjs/proto-signing" "0.29.5"
"@cosmjs/stargate" "0.29.5"
"@cosmjs/tendermint-rpc" "^0.29.5"
"@osmonauts/lcd" "^0.11.1"
protobufjs "^6.11.2"

Expand Down