import getUncompressedPublicKey from "./getUncompressedPublicKey" async function normalizeSafeSignature( signatureHex: string, publicKey: string, setUtf8Bit: boolean = true, ): Promise { // drop the leading 0x const signature = signatureHex.slice(2) const v = signature.slice(0, 2) // v is the first byte // setting the highest bit to execute the UTF-8 validation path if needed const vConverted = setUtf8Bit ? (parseInt(v, 16) + 128).toString(16) : v const signatureConverted = `${signature.slice(2)}${vConverted}` // move v to the end // recover uncompressed public key const publicKeyUncompressed = getUncompressedPublicKey(publicKey) // prefix the Bitcoin message signature with length as required by Safe. const signatureLength = 129n.toString(16) return signatureLength.concat( signatureConverted, `${publicKeyUncompressed}`.substring(2), // Trim the 04 prefix ) } export default normalizeSafeSignature