From c46914f1bc0326adcb1d3b269c1207be88d59cb1 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Wed, 25 Jan 2023 07:21:48 +0000 Subject: [PATCH] weierstrass: remove most private utils --- src/abstract/weierstrass.ts | 10 ---------- test/secp256k1.test.js | 6 +++--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/abstract/weierstrass.ts b/src/abstract/weierstrass.ts index 2daabf4..c262307 100644 --- a/src/abstract/weierstrass.ts +++ b/src/abstract/weierstrass.ts @@ -641,12 +641,7 @@ export type CurveFn = { ProjectivePoint: ProjConstructor; Signature: SignatureConstructor; utils: { - _bigintToBytes: (num: bigint) => Uint8Array; - _bigintToString: (num: bigint) => string; _normalizePrivateKey: (key: PrivKey) => bigint; - _isWithinCurveOrder: (num: bigint) => boolean; - _isValidFieldElement: (num: bigint) => boolean; - _weierstrassEquation: (x: bigint) => bigint; isValidPrivateKey(privateKey: PrivKey): boolean; hashToPrivateKey: (hash: Hex) => Uint8Array; randomPrivateKey: () => Uint8Array; @@ -884,12 +879,7 @@ export function weierstrass(curveDef: CurveType): CurveFn { return false; } }, - _bigintToBytes: numToField, - _bigintToString: numToFieldStr, _normalizePrivateKey: normalizePrivateKey, - _isWithinCurveOrder: isWithinCurveOrder, - _isValidFieldElement: isValidFieldElement, - _weierstrassEquation: weierstrassEquation, /** * Converts some bytes to a valid private key. Needs at least (nBitLength+64) bytes. diff --git a/test/secp256k1.test.js b/test/secp256k1.test.js index c18425a..84f8fe5 100644 --- a/test/secp256k1.test.js +++ b/test/secp256k1.test.js @@ -1,6 +1,7 @@ import * as fc from 'fast-check'; import { secp256k1, schnorr } from '../lib/esm/secp256k1.js'; import { Fp } from '../lib/esm/abstract/modular.js'; +import { bytesToNumberBE, numberToBytesBE } from '../lib/esm/abstract/utils.js'; import { readFileSync } from 'fs'; import { default as ecdsa } from './vectors/ecdsa.json' assert { type: 'json' }; import { default as ecdh } from './vectors/ecdh.json' assert { type: 'json' }; @@ -464,12 +465,11 @@ describe('secp256k1', () => { privateAdd: (privateKey, tweak) => { const p = normal(privateKey); const t = normal(tweak); - return secp.utils._bigintToBytes(Fn.create(p + t)); + return numberToBytesBE(Fn.create(p + t), 32); }, privateNegate: (privateKey) => { - const p = normal(privateKey); - return secp.utils._bigintToBytes(Fn.negate(p)); + return numberToBytesBE(Fn.negate(normal(privateKey)), 32); }, pointAddScalar: (p, tweak, isCompressed) => {