mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
nit changes on psbt signatures pre-filling
This commit is contained in:
parent
af82f7d399
commit
2fa7405d46
1 changed files with 15 additions and 8 deletions
|
|
@ -1141,25 +1141,28 @@ function fromBuffer(buffer: Uint8Array, network: string, inputs?: { key: Uint8Ar
|
|||
vin.inner_witnessscript_asm = convertScriptSigAsm(vin.witness[vin.witness.length - 1]);
|
||||
}
|
||||
|
||||
|
||||
// Fill partial signatures
|
||||
for (const record of groups.partialSigs) {
|
||||
const signature = record.value;
|
||||
const scriptpubkey_type = vin.prevout?.scriptpubkey_type;
|
||||
if (scriptpubkey_type === 'v0_p2wsh' && !finalizedWitness) {
|
||||
vin.witness = vin.witness || [];
|
||||
vin.witness.unshift(uint8ArrayToHexString(record.value));
|
||||
if (scriptpubkey_type === 'multisig' && !finalizedScriptSig) {
|
||||
if (signature.length > 74) {
|
||||
throw new Error("Signature must be <= 74 bytes");
|
||||
}
|
||||
const pushOpcode = new Uint8Array([signature.length]);
|
||||
vin.scriptsig = uint8ArrayToHexString(pushOpcode) + uint8ArrayToHexString(signature) + (vin.scriptsig || '');
|
||||
vin.scriptsig_asm = convertScriptSigAsm(vin.scriptsig);
|
||||
}
|
||||
if (scriptpubkey_type === 'p2sh') {
|
||||
const redeemScriptStr = vin.scriptsig_asm ? vin.scriptsig_asm.split(' ').reverse()[0] : '';
|
||||
if (redeemScriptStr.startsWith('00') && redeemScriptStr.length === 68 && vin.witness?.length) {
|
||||
if (!finalizedWitness) {
|
||||
vin.witness.unshift(uint8ArrayToHexString(record.value));
|
||||
vin.witness.unshift(uint8ArrayToHexString(signature));
|
||||
}
|
||||
} else {
|
||||
if (!finalizedScriptSig) {
|
||||
const signature = record.value;
|
||||
if (signature.length > 73) {
|
||||
throw new Error("Signature must be <= 73 bytes");
|
||||
if (signature.length > 74) {
|
||||
throw new Error("Signature must be <= 74 bytes");
|
||||
}
|
||||
const pushOpcode = new Uint8Array([signature.length]);
|
||||
vin.scriptsig = uint8ArrayToHexString(pushOpcode) + uint8ArrayToHexString(signature) + (vin.scriptsig || '');
|
||||
|
|
@ -1167,6 +1170,10 @@ function fromBuffer(buffer: Uint8Array, network: string, inputs?: { key: Uint8Ar
|
|||
}
|
||||
}
|
||||
}
|
||||
if (scriptpubkey_type === 'v0_p2wsh' && !finalizedWitness) {
|
||||
vin.witness = vin.witness || [];
|
||||
vin.witness.unshift(uint8ArrayToHexString(signature));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue