Created
February 7, 2024 00:21
-
-
Save justinbarry/48e3d9eebbb48b1262d6c1fdf3784806 to your computer and use it in GitHub Desktop.
This file contains 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
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