Derive pubkey from partial
This commit is contained in:
parent
18590a7d65
commit
833cd53ff5
@ -4,6 +4,7 @@
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@cerc-io/registry-sdk": "^0.2.5",
|
||||
"@cosmjs/crypto": "^0.32.4",
|
||||
"@cosmjs/encoding": "^0.32.4",
|
||||
"@cosmjs/proto-signing": "^0.32.4",
|
||||
"@cosmjs/stargate": "^0.32.4",
|
||||
|
@ -4,19 +4,22 @@ import { enqueueSnackbar } from 'notistack';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { MsgCreateValidatorEncodeObject } from '@cosmjs/stargate';
|
||||
import { fromBech32, toBech32 } from '@cosmjs/encoding';
|
||||
import {MsgCreateValidator} from '@cerc-io/registry-sdk';
|
||||
import { fromBase64, fromBech32, toBech32 } from '@cosmjs/encoding';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import { encodePubkey } from '@cosmjs/proto-signing';
|
||||
import { Registry } from '@cerc-io/registry-sdk';
|
||||
|
||||
import { useWalletConnectContext } from '../context/WalletConnectContext'
|
||||
import { Participant } from '../types';
|
||||
import { PubKey as CosmosCryptoEd25519Pubkey } from 'cosmjs-types/cosmos/crypto/ed25519/keys';
|
||||
import { Any } from 'cosmjs-types/google/protobuf/any';
|
||||
|
||||
const CreateValidator = () => {
|
||||
const {session, signClient} = useWalletConnectContext();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [cosmosAddress, setCosmosAddress] = useState('');
|
||||
const [cosmosAddress, setCosmosAddress] = useState('laconic1z4l4556v8jnk7k456ujme720nk8mzjwhka7qvw');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [pubkey, setPubkey] = useState('d5aOEYaCIHaDn6kG0tAg699D7sLgAgkJI5reTMl0o5U=');
|
||||
const [participant, setParticipant] = useState<Participant | null>(null);
|
||||
@ -25,42 +28,49 @@ const CreateValidator = () => {
|
||||
navigate("/connect-wallet")
|
||||
}
|
||||
|
||||
const changePrefix = (address: string, newPrefix: string): string => {
|
||||
return toBech32(newPrefix, fromBech32(address).data);
|
||||
}
|
||||
const pubkeyProto = CosmosCryptoEd25519Pubkey.fromPartial({
|
||||
key: fromBase64(pubkey)
|
||||
});
|
||||
|
||||
const createValidatorMessage: MsgCreateValidatorEncodeObject =
|
||||
const updatedPubKey = Any.fromPartial({
|
||||
typeUrl: '/cosmos.crypto.ed25519.PubKey',
|
||||
value: Uint8Array.from(CosmosCryptoEd25519Pubkey.encode(pubkeyProto).finish())
|
||||
});
|
||||
|
||||
const msgCreateValidator: MsgCreateValidator =
|
||||
useMemo(() => {
|
||||
return {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator",
|
||||
description: {
|
||||
moniker: "dockerNode",
|
||||
identity: "",
|
||||
website: "",
|
||||
securityContact: "",
|
||||
details: "",
|
||||
},
|
||||
commission: {
|
||||
maxChangeRate: "10000000000000000", // 0.01
|
||||
maxRate: "200000000000000000", // 0.2
|
||||
rate: "100000000000000000", // 0.1
|
||||
},
|
||||
minSelfDelegation: "1",
|
||||
delegatorAddress: cosmosAddress,
|
||||
validatorAddress: toBech32('laconicvaloper', fromBech32(cosmosAddress).data),
|
||||
// pubkey: encodePubkey({
|
||||
// type: "tendermint/PubKeyEd25519",
|
||||
// value: pubkey,
|
||||
// }),
|
||||
pubkey: updatedPubKey,
|
||||
value: {
|
||||
description: {
|
||||
moniker: "dockerNode",
|
||||
identity: "",
|
||||
website: "",
|
||||
securityContact: "",
|
||||
details: "",
|
||||
},
|
||||
commission: {
|
||||
maxChangeRate: "10000000000000000", // 0.01
|
||||
maxRate: "200000000000000000", // 0.2
|
||||
rate: "100000000000000000", // 0.1
|
||||
},
|
||||
minSelfDelegation: "1",
|
||||
delegatorAddress: cosmosAddress,
|
||||
// validatorAddress: changePrefix(cosmosAddress, "laconicvaloper"),
|
||||
validatorAddress: "laconicvaloper1ru0s5tu0cj3xmt8zdfrmz74p0c6lj73nqfpt2q",
|
||||
pubkey: encodePubkey({
|
||||
type: "tendermint/PubKeyEd25519",
|
||||
value: pubkey,
|
||||
}),
|
||||
value: {
|
||||
amount: process.env.REACT_APP_STAKING_AMOUNT!,
|
||||
denom: process.env.REACT_APP_LACONICD_DENOM!,
|
||||
},
|
||||
amount: process.env.REACT_APP_STAKING_AMOUNT!,
|
||||
denom: process.env.REACT_APP_LACONICD_DENOM!,
|
||||
},
|
||||
};
|
||||
}, [cosmosAddress, pubkey]);
|
||||
}, [cosmosAddress, updatedPubKey]);
|
||||
|
||||
const msgCreateValidatorEncodeObject: MsgCreateValidatorEncodeObject = {
|
||||
typeUrl: '/cosmos.staking.v1beta1.MsgCreateValidator',
|
||||
value: msgCreateValidator
|
||||
};
|
||||
|
||||
const sendTransaction = async (
|
||||
transactionMessage: MsgCreateValidatorEncodeObject
|
||||
@ -193,14 +203,15 @@ const CreateValidator = () => {
|
||||
}}
|
||||
>
|
||||
<pre style={{ whiteSpace: "pre-wrap", margin: 0 }}>
|
||||
{JSON.stringify(createValidatorMessage, null, 2)}
|
||||
{JSON.stringify(msgCreateValidator, null, 2)}
|
||||
</pre>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
<LoadingButton
|
||||
variant="contained"
|
||||
onClick={async () => {
|
||||
await sendTransaction(createValidatorMessage);
|
||||
console.log(msgCreateValidatorEncodeObject);
|
||||
await sendTransaction(msgCreateValidatorEncodeObject);
|
||||
}}
|
||||
loading={isLoading}
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user