diff --git a/src/App.tsx b/src/App.tsx index 71d3871..35b64b8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,9 +3,11 @@ import {getKeplrFromWindow} from "./util/getKeplrFromWindow"; import {OsmosisChainInfo} from "./constants"; import {Balances} from "./types/balance"; import {Dec, DecUtils} from "@keplr-wallet/unit"; +import {encodeSecp256k1Signature} from "@keplr-wallet/cosmos" import {sendMsgs} from "./util/sendMsgs"; import {api} from "./util/api"; import {simulateMsgs} from "./util/simulateMsgs"; +import { StdSignature } from "@keplr-wallet/types"; import {MsgSend} from "./proto-types-gen/src/cosmos/bank/v1beta1/tx"; import "./styles/container.css"; import "./styles/button.css"; @@ -17,6 +19,12 @@ function App() { const [recipient, setRecipient] = React.useState(''); const [amount, setAmount] = React.useState(''); + const [message, setMessage] = React.useState(''); + const [stdSignature, setStdSignature] = React.useState(undefined); + + const [verifyMessage, setVerifyMessage] = React.useState(''); + const [verifyStdSignature, setVerifyStdSignature] = React.useState(undefined); + const [verificationResult, setVerificationResult] = React.useState(false); useEffect(() => { init(); @@ -109,6 +117,43 @@ function App() { } } + const signMessage = async () => { + if (window.keplr) { + const key = await window.keplr.getKey(OsmosisChainInfo.chainId); + + try { + const signature = await window.keplr.signArbitrary(OsmosisChainInfo.chainId, key.bech32Address, message); + setStdSignature(signature); + setVerifyMessage(message); + setVerifyStdSignature(signature); + } catch (e) { + if (e instanceof Error) { + console.log(e.message); + } + } + } + } + + const verifySignature = async () => { + if (window.keplr) { + const key = await window.keplr.getKey(OsmosisChainInfo.chainId); + + try { + if (!verifyStdSignature) { + return; + } + + const result = await window.keplr.verifyArbitrary(OsmosisChainInfo.chainId, key.bech32Address, verifyMessage, verifyStdSignature); + setVerificationResult(result); + } catch (e) { + if (e instanceof Error) { + console.log(e.message); + setVerificationResult(false); + } + } + } + } + return (
@@ -177,6 +222,68 @@ function App() {
+ +
+
+ Sign Message +
+ +
+
+ Message: + setMessage(e.target.value)} /> +
+ +
+ Signature: + +
+ + +
+ +
+ +
+
+ Verify Signature +
+ +
+
+ Data: + setVerifyMessage(e.target.value)} /> +
+ +
+ Signature: + { + if (verifyStdSignature?.pub_key) { + setVerifyStdSignature({ pub_key: verifyStdSignature.pub_key, signature: e.target.value }) + } + }} /> +
+ +
+ Result: {verificationResult ? 'VALID' : 'FAILED'} +
+ + +
+ +
);