Skip to content

Instantly share code, notes, and snippets.

@bullishgopher
Created April 8, 2024 12:37
Show Gist options
  • Save bullishgopher/87fa6675bea44cda38fee326f16efb96 to your computer and use it in GitHub Desktop.
Save bullishgopher/87fa6675bea44cda38fee326f16efb96 to your computer and use it in GitHub Desktop.
Sign and verify message on Keplr
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