Skip to content

Commit

Permalink
Merge pull request #102 from MicahZoltu/patch-2
Browse files Browse the repository at this point in the history
Corrects type of `sign` and `signAsync`
  • Loading branch information
paulmillr authored Apr 29, 2023
2 parents 3e2a7e0 + 474c7c9 commit 0fb0d8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ let _hmacSync: HmacFnSync; // Can be redefined by use in utils; built-ins don
const optS: { lowS?: boolean; extraEntropy?: boolean | Hex; } = { lowS: true }; // opts for sign()
const optV: { lowS?: boolean } = { lowS: true }; // standard opts for verify()
type BC = { seed: Bytes, k2sig : (kb: Bytes) => Signature | undefined }; // Bytes+predicate checker
function prepSig(msgh: Hex, priv: Hex, opts = optS): BC { // prepare for RFC6979 sig generation
function prepSig(msgh: Hex, priv: PrivKey, opts = optS): BC { // prepare for RFC6979 sig generation
if (['der', 'recovered', 'canonical'].some(k => k in opts)) // Ban legacy options
err('sign() legacy options not supported');
let { lowS } = opts; // generates low-s sigs by default
Expand Down Expand Up @@ -313,11 +313,11 @@ function hmacDrbg<T>(asynchronous: boolean) { // HMAC-DRBG async
}
}
// ECDSA signature generation. via secg.org/sec1-v2.pdf 4.1.2 + RFC6979 deterministic k
async function signAsync(msgh: Hex, priv: Hex, opts = optS): Promise<Signature> {
async function signAsync(msgh: Hex, priv: PrivKey, opts = optS): Promise<Signature> {
const { seed, k2sig } = prepSig(msgh, priv, opts); // Extract arguments for hmac-drbg
return hmacDrbg<Signature>(true)(seed, k2sig); // Re-run hmac-drbg until k2sig returns ok
}
function sign(msgh: Hex, priv: Hex, opts = optS): Signature {
function sign(msgh: Hex, priv: PrivKey, opts = optS): Signature {
const { seed, k2sig } = prepSig(msgh, priv, opts); // Extract arguments for hmac-drbg
return hmacDrbg<Signature>(false)(seed, k2sig); // Re-run hmac-drbg until k2sig returns ok
}
Expand Down

0 comments on commit 0fb0d8e

Please sign in to comment.