Not sure if this is helpful(or which library you were referring to), but:(looks like this is just verification…I think you need signing)
In the given Motoko code, the value “v” is not explicitly calculated, but rather it is implicitly derived as a part of the signature verification process using the values “r” and “s” from the signature, and the public key and the message being verified.
Specifically, the code first checks that “r” and “s” are valid and within the curve’s range, and then converts them to Fp elements “r” and “s” using the curve’s modulus “r”. It then calculates the hash “h” of the message using SHA256 and converts it to an Fp element.
Next, the code calculates the inverse of “s” as “sInverse”, and uses it to compute two Fp elements “a” and “b” as:
a = h * sInverse
b = r * sInverse
These values are then used to calculate a point on the curve using the Jacobi function, as:
Jacobi.add(
Jacobi.mulBase(a.value, curve),
Jacobi.mul(Jacobi.fromAffine(#point (x, y, curve)), b.value)
)
This point is then checked to see if it matches the value of “r”, which is the x-coordinate of the signature point. If it does match, then the signature is considered valid and the function returns “true”. Otherwise, it returns “false”.
So, while the code doesn’t explicitly calculate the value of “v”, it does use “r” and “s” to calculate a point on the curve, and then checks whether the x-coordinate of that point matches “r”. This effectively determines the value of “v” and ensures that the signature is valid.