@@ -1037,79 +1037,12 @@ function checkFees(psbt, cache, opts) {
10371037function checkInputsForPartialSig ( inputs , action ) {
10381038 inputs . forEach ( input => {
10391039 const throws = ( 0 , bip371_1 . isTaprootInput ) ( input )
1040- ? checkTaprootInputForSigs ( input , action )
1041- : checkInputForSig ( input , action ) ;
1040+ ? ( 0 , bip371_1 . checkTaprootInputForSigs ) ( input , action )
1041+ : ( 0 , psbtutils_1 . checkInputForSig ) ( input , action ) ;
10421042 if ( throws )
10431043 throw new Error ( 'Can not modify transaction, signatures exist.' ) ;
10441044 } ) ;
10451045}
1046- function checkInputForSig ( input , action ) {
1047- const pSigs = extractPartialSigs ( input ) ;
1048- return pSigs . some ( pSig =>
1049- signatureBlocksAction ( pSig , bscript . signature . decode , action ) ,
1050- ) ;
1051- }
1052- function checkTaprootInputForSigs ( input , action ) {
1053- const sigs = extractTaprootSigs ( input ) ;
1054- return sigs . some ( sig =>
1055- signatureBlocksAction ( sig , decodeSchnorSignature , action ) ,
1056- ) ;
1057- }
1058- function decodeSchnorSignature ( signature ) {
1059- return {
1060- signature : signature . slice ( 0 , 64 ) ,
1061- hashType :
1062- signature . slice ( 64 ) [ 0 ] || transaction_1 . Transaction . SIGHASH_DEFAULT ,
1063- } ;
1064- }
1065- function extractTaprootSigs ( input ) {
1066- const sigs = [ ] ;
1067- if ( input . tapKeySig ) sigs . push ( input . tapKeySig ) ;
1068- if ( input . tapScriptSig )
1069- sigs . push ( ...input . tapScriptSig . map ( s => s . signature ) ) ;
1070- if ( ! sigs . length ) {
1071- const finalTapKeySig = getTapKeySigFromWithness ( input . finalScriptWitness ) ;
1072- if ( finalTapKeySig ) sigs . push ( finalTapKeySig ) ;
1073- }
1074- return sigs ;
1075- }
1076- function getTapKeySigFromWithness ( finalScriptWitness ) {
1077- if ( ! finalScriptWitness ) return ;
1078- const witness = finalScriptWitness . slice ( 2 ) ;
1079- // todo: add schnor signature validation
1080- if ( witness . length === 64 || witness . length === 65 ) return witness ;
1081- }
1082- function extractPartialSigs ( input ) {
1083- let pSigs = [ ] ;
1084- if ( ( input . partialSig || [ ] ) . length === 0 ) {
1085- if ( ! input . finalScriptSig && ! input . finalScriptWitness ) return [ ] ;
1086- pSigs = getPsigsFromInputFinalScripts ( input ) ;
1087- } else {
1088- pSigs = input . partialSig ;
1089- }
1090- return pSigs . map ( p => p . signature ) ;
1091- }
1092- function signatureBlocksAction ( signature , signatureDecodeFn , action ) {
1093- const { hashType } = signatureDecodeFn ( signature ) ;
1094- const whitelist = [ ] ;
1095- const isAnyoneCanPay =
1096- hashType & transaction_1 . Transaction . SIGHASH_ANYONECANPAY ;
1097- if ( isAnyoneCanPay ) whitelist . push ( 'addInput' ) ;
1098- const hashMod = hashType & 0x1f ;
1099- switch ( hashMod ) {
1100- case transaction_1 . Transaction . SIGHASH_ALL :
1101- break ;
1102- case transaction_1 . Transaction . SIGHASH_SINGLE :
1103- case transaction_1 . Transaction . SIGHASH_NONE :
1104- whitelist . push ( 'addOutput' ) ;
1105- whitelist . push ( 'setInputSequence' ) ;
1106- break ;
1107- }
1108- if ( whitelist . indexOf ( action ) === - 1 ) {
1109- return true ;
1110- }
1111- return false ;
1112- }
11131046function checkPartialSigSighashes ( input ) {
11141047 if ( ! input . sighashType || ! input . partialSig ) return ;
11151048 const { partialSig, sighashType } = input ;
@@ -1459,20 +1392,6 @@ function getPayment(script, scriptType, partialSig) {
14591392 }
14601393 return payment ;
14611394}
1462- function getPsigsFromInputFinalScripts ( input ) {
1463- const scriptItems = ! input . finalScriptSig
1464- ? [ ]
1465- : bscript . decompile ( input . finalScriptSig ) || [ ] ;
1466- const witnessItems = ! input . finalScriptWitness
1467- ? [ ]
1468- : bscript . decompile ( input . finalScriptWitness ) || [ ] ;
1469- return scriptItems
1470- . concat ( witnessItems )
1471- . filter ( item => {
1472- return Buffer . isBuffer ( item ) && bscript . isCanonicalScriptSignature ( item ) ;
1473- } )
1474- . map ( sig => ( { signature : sig } ) ) ;
1475- }
14761395function getScriptFromInput ( inputIndex , input , cache ) {
14771396 const unsignedTx = cache . __TX ;
14781397 const res = {
0 commit comments