@@ -805,10 +805,11 @@ const randomSecretKey = (seed = randomBytes(lengths.seed)) => {
805805 const num = M ( bytesToNumBE ( seed ) , N - 1n ) ;
806806 return numTo32b ( num + 1n ) ;
807807} ;
808- const keygen = ( seed ) => {
808+ const createKeygen = ( getPublicKey ) => ( seed ) => {
809809 const secretKey = randomSecretKey ( seed ) ;
810810 return { secretKey, publicKey : getPublicKey ( secretKey ) } ;
811811} ;
812+ const keygen = createKeygen ( getPublicKey ) ;
812813/** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
813814const etc = {
814815 hexToBytes : hexToBytes ,
@@ -863,6 +864,7 @@ const challengeAsync = async (...args) => bytesModN(await taggedHashAsync(T_CHAL
863864const pubSchnorr = ( secretKey ) => {
864865 return extpubSchnorr ( secretKey ) . px ; // d'=int(sk). Fail if d'=0 or d'≥n. Ret bytes(d'⋅G)
865866} ;
867+ const keygenSchnorr = createKeygen ( pubSchnorr ) ;
866868// Common preparation fn for both sync and async signing
867869const prepSigSchnorr = ( message , secretKey , auxRand ) => {
868870 const { px, d } = extpubSchnorr ( secretKey ) ;
@@ -900,7 +902,7 @@ const signSchnorr = (message, secretKey, auxRand = randomBytes(L)) => {
900902 err ( E_INVSIG ) ;
901903 return sig ;
902904} ;
903- const signAsyncSchnorr = async ( message , secretKey , auxRand = randomBytes ( L ) ) => {
905+ const signSchnorrAsync = async ( message , secretKey , auxRand = randomBytes ( L ) ) => {
904906 const { m, px, d, a } = prepSigSchnorr ( message , secretKey , auxRand ) ;
905907 const aux = await taggedHashAsync ( T_AUX , a ) ;
906908 // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
@@ -912,7 +914,7 @@ const signAsyncSchnorr = async (message, secretKey, auxRand = randomBytes(L)) =>
912914 const e = await challengeAsync ( rx , px , m ) ;
913915 const sig = createSigSchnorr ( k , rx , e , d ) ;
914916 // If Verify(bytes(P), m, sig) (see below) returns failure, abort
915- if ( ! ( await verifyAsyncSchnorr ( sig , m , px ) ) )
917+ if ( ! ( await verifySchnorrAsync ( sig , m , px ) ) )
916918 err ( E_INVSIG ) ;
917919 return sig ;
918920} ;
@@ -956,16 +958,14 @@ const _verifSchnorr = (signature, message, publicKey, challengeFn) => {
956958 * Will swallow errors & return false except for initial type validation of arguments.
957959 */
958960const verifySchnorr = ( s , m , p ) => _verifSchnorr ( s , m , p , challenge ) ;
959- const verifyAsyncSchnorr = async ( s , m , p ) => _verifSchnorr ( s , m , p , challengeAsync ) ;
961+ const verifySchnorrAsync = async ( s , m , p ) => _verifSchnorr ( s , m , p , challengeAsync ) ;
960962const schnorr = {
963+ keygen : keygenSchnorr ,
961964 getPublicKey : pubSchnorr ,
962965 sign : signSchnorr ,
963966 verify : verifySchnorr ,
964- } ;
965- const schnorrAsync = {
966- getPublicKey : pubSchnorr ,
967- signAsync : signAsyncSchnorr ,
968- verifyAsync : verifyAsyncSchnorr ,
967+ signAsync : signSchnorrAsync ,
968+ verifyAsync : verifySchnorrAsync ,
969969} ;
970970// ## Precomputes
971971// --------------
@@ -1043,4 +1043,4 @@ const wNAF = (n) => {
10431043 return { p, f } ; // return both real and fake points for JIT
10441044} ;
10451045// !! Remove the export below to easily use in REPL / browser console
1046- export { etc , getPublicKey , getSharedSecret , hash , hashes , keygen , Point , recoverPublicKey , recoverPublicKeyAsync , schnorr , schnorrAsync , sign , signAsync , Signature , utils , verify , verifyAsync , } ;
1046+ export { etc , getPublicKey , getSharedSecret , hash , hashes , keygen , Point , recoverPublicKey , recoverPublicKeyAsync , schnorr , sign , signAsync , Signature , utils , verify , verifyAsync } ;
0 commit comments