Created
April 8, 2024 12:37
-
-
Save xgracias/87fa6675bea44cda38fee326f16efb96 to your computer and use it in GitHub Desktop.
Sign and verify message on Keplr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const signMessage = async ( | |
chainId: string, | |
address: string, | |
): Promise<StdSignature | undefined> => { | |
const anyWindow: any = window; | |
if (!anyWindow.getOfflineSigner) { | |
throw new Error('Keplr extension is not available'); | |
} | |
const signed = await window.keplr?.signArbitrary( | |
chainId, | |
address, | |
SIGN_MSG.value, | |
); | |
return signed; | |
}; | |
export const verifyMessage = (account: Key, signed: StdSignature): boolean => { | |
const isValid = verifyADR36Amino( | |
PUBLIC_ENVIRONMENT.NEXT_PUBLIC_ADDRESS_PREFIX, | |
account.bech32Address, | |
SIGN_MSG.value, | |
fromBase64(signed.pub_key.value), | |
fromBase64(signed.signature), | |
); | |
return isValid; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment