From efeca9f47840db17bf6cc13efbabd6a795b85194 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Wed, 27 Mar 2024 11:11:53 +0000 Subject: [PATCH] Add hex tests --- test/basic.test.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/basic.test.js b/test/basic.test.js index 7ebcd0c..44aedf9 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -2,7 +2,7 @@ import { deepStrictEqual, throws } from 'assert'; import { should, describe } from 'micro-should'; import * as fc from 'fast-check'; import * as mod from '../esm/abstract/modular.js'; -import { bytesToHex as toHex } from '../esm/abstract/utils.js'; +import { bytesToHex, isBytes, bytesToHex as toHex } from '../esm/abstract/utils.js'; // Generic tests for all curves in package import { secp192r1, secp224r1 } from './_more-curves.helpers.js'; import { secp256r1 } from '../esm/p256.js'; @@ -595,6 +595,18 @@ for (const name in CURVES) { { numRuns: NUM_RUNS } ) ); + should('.verify() should verify random signatures in hex', () => + fc.assert( + fc.property(fc.hexaString({ minLength: 64, maxLength: 64 }), (msg) => { + const priv = toHex(C.utils.randomPrivateKey()); + const pub = toHex(C.getPublicKey(priv)); + const sig = C.sign(msg, priv); + let sighex = isBytes(sig) ? toHex(sig) : sig.toCompactHex(); + deepStrictEqual(C.verify(sighex, msg, pub), true, `priv=${priv},pub=${pub},msg=${msg}`); + }), + { numRuns: NUM_RUNS } + ) + ); should('.verify() should verify empty signatures', () => { const msg = new Uint8Array([]); const priv = C.utils.randomPrivateKey();