@@ -768,13 +768,27 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
768768 } ;
769769 }
770770
771- public async sign ( data : Buffer , hashed : boolean = false , secp256k1Precompute ?: Secp256k1PrecomputedClient ) : Promise < Buffer > {
771+ public async sign (
772+ data : Buffer ,
773+ opts : {
774+ hashed ?: boolean ;
775+ secp256k1Precompute ?: Secp256k1PrecomputedClient ;
776+ keyTweak ?: BN ;
777+ }
778+ ) : Promise < Buffer > {
772779 this . wasmLib = await this . loadTssWasm ( ) ;
773780 if ( this . _sigType === "ecdsa-secp256k1" ) {
774- const sig = await this . sign_ECDSA_secp256k1 ( data , hashed , secp256k1Precompute ) ;
781+ if ( opts . keyTweak ) {
782+ throw CoreKitError . default ( "key tweaking not supported for ecdsa-secp256k1" ) ;
783+ }
784+ const sig = await this . sign_ECDSA_secp256k1 ( data , opts . hashed , opts . secp256k1Precompute ) ;
775785 return Buffer . concat ( [ sig . r , sig . s , Buffer . from ( [ sig . v ] ) ] ) ;
776786 } else if ( this . _sigType === "ed25519" || this . _sigType === "bip340" ) {
777- return this . sign_frost ( data , hashed ) ;
787+ if ( opts . hashed ) {
788+ throw CoreKitError . default ( `hashed data not supported for bip340` ) ;
789+ }
790+
791+ return this . sign_frost ( data , opts . keyTweak ) ;
778792 }
779793 throw CoreKitError . default ( `sign not supported for key type ${ this . keyType } ` ) ;
780794 }
@@ -1407,11 +1421,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
14071421 }
14081422 }
14091423
1410- private async sign_frost ( data : Buffer , hashed : boolean = false ) : Promise < Buffer > {
1411- if ( hashed ) {
1412- throw CoreKitError . default ( `hashed data not supported for ${ this . _sigType } ` ) ;
1413- }
1414-
1424+ private async sign_frost ( data : Buffer , keyTweak ?: BN ) : Promise < Buffer > {
14151425 const nodeDetails = fetchLocalConfig ( this . options . web3AuthNetwork , this . keyType , this . _sigType ) ;
14161426 if ( ! nodeDetails . torusNodeTSSEndpoints ) {
14171427 throw CoreKitError . default ( "could not fetch tss node endpoints" ) ;
@@ -1439,7 +1449,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
14391449 const { serverCoefficients, clientCoefficient } = deriveShareCoefficients ( ec , serverXCoords , clientXCoord , this . state . tssShareIndex ) ;
14401450
14411451 // Get pub key.
1442- const tssPubKey = await this . getPubKey ( ) ;
1452+ const tssPubKey = this . getPubKey ( ) ;
14431453 const tssPubKeyPoint = ec . keyFromPublic ( tssPubKey ) . getPublic ( ) ;
14441454
14451455 // Get client key share and adjust by coefficient.
@@ -1469,7 +1479,8 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
14691479 clientShareAdjustedHex ,
14701480 pubKeyHex ,
14711481 data ,
1472- serverCoefficientsHex
1482+ serverCoefficientsHex ,
1483+ keyTweak ?. toString ( "hex" )
14731484 ) ;
14741485
14751486 log . info ( `signature: ${ signature } ` ) ;
0 commit comments