From 1fb63cb38522efd3160213d1e18f1e2c0bda535d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8r=E2=88=82=C2=A1?= Date: Fri, 5 Feb 2021 17:27:41 +0100 Subject: [PATCH] Minor arrangement --- src/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3a0247e..b4362c8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,14 +37,6 @@ export function decodePoint(hexPoint: string): Point { return secp256k1.keyFromPublic(Buffer.from(hexPoint, "hex")).getPublic() } -function random(bytes: number) { - let k: BigNumber - do { - k = new BigNumber(randomBytes(bytes)) - } while (k.toString() == "0" && k.gcd(n).toString() != "1") - return k -} - export function newKeyPair() { const sk = random(32) return { sk: sk, pk: G.mul(sk) } @@ -141,6 +133,16 @@ export function signatureFromHex(hexSignature: string): UnblindedSignature { return { s, f } } +// HELPERS + +function random(bytes: number) { + let k: BigNumber + do { + k = new BigNumber(randomBytes(bytes)) + } while (k.toString() == "0" && k.gcd(n).toString() != "1") + return k +} + function zeroPad(hexString: string, byteLength: number) { if (hexString.length > (byteLength * 2)) throw new Error("Out of bounds") while (hexString.length < (byteLength * 2)) {