From fb3f42751cf99b9eab85a872a000aa07cbe174ea Mon Sep 17 00:00:00 2001 From: Hans Bergren Date: Fri, 24 Jan 2020 09:06:53 -0500 Subject: [PATCH] Add code comment for impossible error (#86) --- packages/ripple-keypairs/src/secp256k1.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/ripple-keypairs/src/secp256k1.ts b/packages/ripple-keypairs/src/secp256k1.ts index d55daadc..df520259 100644 --- a/packages/ripple-keypairs/src/secp256k1.ts +++ b/packages/ripple-keypairs/src/secp256k1.ts @@ -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 ;)') }