Browse Source
Check actual sighash flags instead of psbtInput one
psbt
junderw
6 years ago
No known key found for this signature in database
GPG Key ID: B256185D3A971908
2 changed files with
37 additions and
48 deletions
-
src/psbt.js
-
ts_src/psbt.ts
|
|
@ -815,17 +815,15 @@ function checkTxEmpty(tx) { |
|
|
|
function checkInputsForPartialSig(inputs, action) { |
|
|
|
inputs.forEach(input => { |
|
|
|
let throws = false; |
|
|
|
if ((input.partialSig || []).length > 0) { |
|
|
|
if (input.sighashType !== undefined) { |
|
|
|
if ((input.partialSig || []).length === 0) return; |
|
|
|
input.partialSig.forEach(pSig => { |
|
|
|
const { hashType } = bscript.signature.decode(pSig.signature); |
|
|
|
const whitelist = []; |
|
|
|
const isAnyoneCanPay = |
|
|
|
input.sighashType & transaction_1.Transaction.SIGHASH_ANYONECANPAY; |
|
|
|
hashType & transaction_1.Transaction.SIGHASH_ANYONECANPAY; |
|
|
|
if (isAnyoneCanPay) whitelist.push('addInput'); |
|
|
|
if (!isAnyoneCanPay && action === 'addInput') { |
|
|
|
throws = true; |
|
|
|
} |
|
|
|
const hashType = input.sighashType & 0x1f; |
|
|
|
switch (hashType) { |
|
|
|
const hashMod = hashType & 0x1f; |
|
|
|
switch (hashMod) { |
|
|
|
case transaction_1.Transaction.SIGHASH_ALL: |
|
|
|
break; |
|
|
|
case transaction_1.Transaction.SIGHASH_SINGLE: |
|
|
@ -837,10 +835,7 @@ function checkInputsForPartialSig(inputs, action) { |
|
|
|
if (whitelist.indexOf(action) === -1) { |
|
|
|
throws = true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
throws = true; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
if (throws) { |
|
|
|
throw new Error('Can not modify transaction, signatures exist.'); |
|
|
|
} |
|
|
|
|
|
@ -1028,17 +1028,14 @@ function checkTxEmpty(tx: Transaction): void { |
|
|
|
function checkInputsForPartialSig(inputs: PsbtInput[], action: string): void { |
|
|
|
inputs.forEach(input => { |
|
|
|
let throws = false; |
|
|
|
if ((input.partialSig || []).length > 0) { |
|
|
|
if (input.sighashType !== undefined) { |
|
|
|
if ((input.partialSig || []).length === 0) return; |
|
|
|
input.partialSig!.forEach(pSig => { |
|
|
|
const { hashType } = bscript.signature.decode(pSig.signature); |
|
|
|
const whitelist: string[] = []; |
|
|
|
const isAnyoneCanPay = |
|
|
|
input.sighashType & Transaction.SIGHASH_ANYONECANPAY; |
|
|
|
const isAnyoneCanPay = hashType & Transaction.SIGHASH_ANYONECANPAY; |
|
|
|
if (isAnyoneCanPay) whitelist.push('addInput'); |
|
|
|
if (!isAnyoneCanPay && action === 'addInput') { |
|
|
|
throws = true; |
|
|
|
} |
|
|
|
const hashType = input.sighashType & 0x1f; |
|
|
|
switch (hashType) { |
|
|
|
const hashMod = hashType & 0x1f; |
|
|
|
switch (hashMod) { |
|
|
|
case Transaction.SIGHASH_ALL: |
|
|
|
break; |
|
|
|
case Transaction.SIGHASH_SINGLE: |
|
|
@ -1050,10 +1047,7 @@ function checkInputsForPartialSig(inputs: PsbtInput[], action: string): void { |
|
|
|
if (whitelist.indexOf(action) === -1) { |
|
|
|
throws = true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
throws = true; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
if (throws) { |
|
|
|
throw new Error('Can not modify transaction, signatures exist.'); |
|
|
|
} |
|
|
|