Add code comment for impossible error (#86)

This commit is contained in:
Hans Bergren
2020-01-24 09:06:53 -05:00
parent 45911b7190
commit fb3f42751c

View File

@@ -20,6 +20,14 @@ function deriveScalar(bytes, discrim?: number) {
return key
}
}
/* This error is practically impossible to reach.
* The order of the curve describes the (finite) amount of points on the curve
* https://github.com/indutny/elliptic/blob/master/lib/elliptic/curves.js#L182
* How often will an (essentially) random number generated by Sha512 be larger than that?
* There's 2^32 chances (the for loop) to get a number smaller than the order,
* so it's rare that you'll even get past the first loop iteration.
* Note that in TypeScript we actually need the throw, otherwise the function signature would be BN | undefined
*/
/* istanbul ignore next */
throw new Error('impossible unicorn ;)')
}