Skip to content

Instantly share code, notes, and snippets.

@justinbarry
Created February 7, 2024 00:21
Show Gist options
  • Save justinbarry/48e3d9eebbb48b1262d6c1fdf3784806 to your computer and use it in GitHub Desktop.
Save justinbarry/48e3d9eebbb48b1262d6c1fdf3784806 to your computer and use it in GitHub Desktop.
import { makeADR36AminoSignDoc, serializeSignDoc } from "@keplr-wallet/cosmos";
import { Hash, PrivKeySecp256k1 } from "@keplr-wallet/crypto";
function signArbFn(address: string, privateKey: string) {
const cryptoPrivKey = new PrivKeySecp256k1(fromHex(privateKey));
return async (message: string | Uint8Array): Promise<string> => {
const signDoc = makeADR36AminoSignDoc(address, message);
const serializedSignDoc = serializeSignDoc(signDoc);
const digest = Hash.sha256(serializedSignDoc);
const signature = cryptoPrivKey.signDigest32(digest);
return Buffer.from(
new Uint8Array([...signature.r, ...signature.s])
).toString("base64");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment