ephemeral signing key can now be Octets
@@ -47,7 +47,8 @@ def _challenge(msg: String, ec: Curve, hf: HashF) -> int:
# TODO make k Union[int, Octets]
# TODO allow to sign also with WIF: String
# TODO allow to sign also with BIP32key: Union[XkeyDict, String]
-def sign(msg: String, prvkey: Union[int, Octets], k: Optional[int] = None,
+def sign(msg: String, prvkey: Union[int, Octets],
+ k: Optional[Union[int, Octets]] = None,
ec: Curve = secp256k1, hf: HashF = sha256) -> Tuple[int, int]:
"""ECDSA signature according to SEC 1 v.2 with canonical low-s encoding.
@@ -74,16 +75,17 @@ def sign(msg: String, prvkey: Union[int, Octets], k: Optional[int] = None,
if k is None:
k = _rfc6979(c, q, ec, hf) # 1
- if not 0 < k < ec.n:
- raise ValueError(f"Ephemeral key {hex(k)} not in [1, n-1]")
+ else:
+ k = int_from_prvkey(k, ec)
# second part delegated to helper function
return _sign(c, q, k, ec)
def _sign(c: int, q: int, k: int, ec: Curve) -> Tuple[int, int]:
- # Private function for test/dev purposes
- # it is assumed that q, k, and c are in [1, n-1]
+ # Private function for testing purposes: it allows to explore all
+ # possible value of the challenge c (for low-cardinality curves).
+ # It assume that c is in [0, n-1], while q and k are in [1, n-1]
# Steps numbering follows SEC 1 v.2 section 4.1.3
