normalize Signature
Normalizes a DER-encoded secp256r1 signature to compact format with low-S normalization.
This function performs the following steps:
Parses DER format via parseDerSignature, which returns R and S as BigIntegers
Normalizes S to low-S form if S > halfOrder
Pads both R and S to exactly 32 bytes
Returns concatenated R || S (64 bytes total)
Low-S normalization ensures that s values greater than half the curve order are converted to their complements (n - s), which is required for Stellar/Soroban signature verification.
Return
Compact 64-byte signature (32-byte r || 32-byte s)
Parameters
der Signature
DER-encoded signature bytes
Throws
if the DER format is invalid
Example:
val derSig = byteArrayOf(...) // DER-encoded signature from WebAuthn
val compactSig = SmartAccountUtils.normalizeSignature(derSig)
// compactSig is now 64 bytes: r (32 bytes) || s (32 bytes)Content copied to clipboard