signMessage method
Signs a given message using the ECDSA deterministic signature scheme. The message is first hashed and then signed using the private key.
Implementation
List<int> signMessage(List<int> message, String messagePrefix) {
final messgaeHash = QuickCrypto.sha256Hash(
BitcoinSignerUtils.magicMessage(message, messagePrefix));
final ECDSASignature ecdsaSign = signingKey.signDigestDeterminstic(
digest: messgaeHash, hashFunc: () => SHA256());
final n = BitcoinSignerUtils._order >> 1;
BigInt newS;
if (ecdsaSign.s.compareTo(n) > 0) {
newS = BitcoinSignerUtils._order - ecdsaSign.s;
} else {
newS = ecdsaSign.s;
}
final newSignature = ECDSASignature(ecdsaSign.r, newS);
final verify = verifyKey.verifyMessage(message, messagePrefix,
newSignature.toBytes(BitcoinSignerUtils.baselen));
if (!verify) {
throw const MessageException(
'The created signature does not pass verification.');
}
return newSignature.toBytes(BitcoinSignerUtils.baselen);
}