@@ -3765,6 +3765,123 @@ describe('V2 Wallet:', function () {
37653765 } ) ;
37663766 } ) ;
37673767
3768+ describe ( 'ensureCleanSigSharesAndSignTransaction' , function ( ) {
3769+ const exampleSignedTx = {
3770+ txHex : '0x123' ,
3771+ txid : '0x456' ,
3772+ status : 'signed' ,
3773+ } ;
3774+
3775+ const partiallySignedTxRequest : TxRequest = {
3776+ txRequestId : 'test-tx-id' ,
3777+ walletId : 'test-wallet-id' ,
3778+ walletType : 'hot' ,
3779+ version : 1 ,
3780+ state : 'initialized' ,
3781+ date : '2025-10-15' ,
3782+ userId : 'user-123' ,
3783+ intent : { } ,
3784+ policiesChecked : false ,
3785+ unsignedTxs : [ ] ,
3786+ apiVersion : 'full' ,
3787+ latest : true ,
3788+ transactions : [
3789+ {
3790+ state : 'pendingSignature' ,
3791+ unsignedTx : {
3792+ serializedTxHex : 'abc123' ,
3793+ signableHex : 'def456' ,
3794+ derivationPath : 'm/0' ,
3795+ } ,
3796+ signatureShares : [
3797+ {
3798+ from : 'user' ,
3799+ to : 'bitgo' ,
3800+ share : 'partial-share-data' ,
3801+ } ,
3802+ ] ,
3803+ } ,
3804+ ] ,
3805+ } ;
3806+
3807+ const cleanTxRequest : TxRequest = {
3808+ ...partiallySignedTxRequest ,
3809+ transactions : [
3810+ {
3811+ state : 'initialized' ,
3812+ unsignedTx : {
3813+ serializedTxHex : 'abc123' ,
3814+ signableHex : 'def456' ,
3815+ derivationPath : 'm/0' ,
3816+ } ,
3817+ signatureShares : [ ] ,
3818+ } ,
3819+ ] ,
3820+ } ;
3821+
3822+ afterEach ( async function ( ) {
3823+ sandbox . restore ( ) ;
3824+ } ) ;
3825+
3826+ it ( 'should delete signature shares for partially signed Full TxRequest before signing' , async function ( ) {
3827+ const getTxRequestSpy = sandbox . stub ( TssUtils . prototype , 'getTxRequest' ) ;
3828+ getTxRequestSpy . resolves ( partiallySignedTxRequest ) ;
3829+
3830+ const deleteSignatureSharesSpy = sandbox . stub ( TssUtils . prototype , 'deleteSignatureShares' ) ;
3831+ deleteSignatureSharesSpy . resolves ( [ ] ) ;
3832+
3833+ const signTransactionSpy = sandbox . stub ( tssSolWallet , 'signTransaction' ) ;
3834+ signTransactionSpy . resolves ( exampleSignedTx ) ;
3835+
3836+ const signedTx = await tssSolWallet . ensureCleanSigSharesAndSignTransaction ( {
3837+ txRequestId : 'test-tx-id' ,
3838+ walletPassphrase : 'passphrase' ,
3839+ } ) ;
3840+
3841+ sandbox . assert . calledOnce ( getTxRequestSpy ) ;
3842+ sandbox . assert . calledOnce ( deleteSignatureSharesSpy ) ;
3843+ sandbox . assert . calledOnce ( signTransactionSpy ) ;
3844+ signedTx . should . deepEqual ( exampleSignedTx ) ;
3845+ } ) ;
3846+
3847+ it ( 'should not delete signature shares for clean Full TxRequest' , async function ( ) {
3848+ const getTxRequestSpy = sandbox . stub ( TssUtils . prototype , 'getTxRequest' ) ;
3849+ getTxRequestSpy . resolves ( cleanTxRequest ) ;
3850+
3851+ const deleteSignatureSharesSpy = sandbox . stub ( TssUtils . prototype , 'deleteSignatureShares' ) ;
3852+
3853+ const signTransactionSpy = sandbox . stub ( tssSolWallet , 'signTransaction' ) ;
3854+ signTransactionSpy . resolves ( exampleSignedTx ) ;
3855+
3856+ const signedTx = await tssSolWallet . ensureCleanSigSharesAndSignTransaction ( {
3857+ txRequestId : 'test-tx-id' ,
3858+ walletPassphrase : 'passphrase' ,
3859+ } ) ;
3860+
3861+ sandbox . assert . calledOnce ( getTxRequestSpy ) ;
3862+ sandbox . assert . notCalled ( deleteSignatureSharesSpy ) ;
3863+ sandbox . assert . calledOnce ( signTransactionSpy ) ;
3864+ signedTx . should . deepEqual ( exampleSignedTx ) ;
3865+ } ) ;
3866+
3867+ it ( 'should sign transaction directly when no txRequestId provided' , async function ( ) {
3868+ const getTxRequestSpy = sandbox . stub ( TssUtils . prototype , 'getTxRequest' ) ;
3869+ const deleteSignatureSharesSpy = sandbox . stub ( TssUtils . prototype , 'deleteSignatureShares' ) ;
3870+
3871+ const signTransactionSpy = sandbox . stub ( tssSolWallet , 'signTransaction' ) ;
3872+ signTransactionSpy . resolves ( exampleSignedTx ) ;
3873+
3874+ const signedTx = await tssSolWallet . ensureCleanSigSharesAndSignTransaction ( {
3875+ walletPassphrase : 'passphrase' ,
3876+ } ) ;
3877+
3878+ sandbox . assert . notCalled ( getTxRequestSpy ) ;
3879+ sandbox . assert . notCalled ( deleteSignatureSharesSpy ) ;
3880+ sandbox . assert . calledOnce ( signTransactionSpy ) ;
3881+ signedTx . should . deepEqual ( exampleSignedTx ) ;
3882+ } ) ;
3883+ } ) ;
3884+
37683885 describe ( 'Message Signing' , function ( ) {
37693886 const txHash = '0xrrrsss1b' ;
37703887 const messageRaw = 'hello world' ;
0 commit comments