Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion modules/utxo-bin/src/InputParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utxolib from '@bitgo/utxo-lib';
import { script, ScriptSignature } from 'bitcoinjs-lib';
import { script, ScriptSignature, Transaction } from 'bitcoinjs-lib';

import { Parser, ParserNode } from './Parser';
import { getParserTxInputProperties, getPrevOut, ParserTx, ParserTxInput } from './ParserTx';
Expand All @@ -10,6 +10,48 @@ import { OutputParser } from './OutputParser';
import { parseUnknown } from './parseUnknown';
import { ScriptParser } from './ScriptParser';

/**
* Convert a numeric hashType to a human-readable sighash string.
* Handles combinations of base types and flags (ANYONECANPAY, FORKID).
*/
function getSighashName(hashType: number): string {
const parts: string[] = [];

// Extract flags
const hasAnyoneCanPay = (hashType & Transaction.SIGHASH_ANYONECANPAY) !== 0;
const hasForkId = (hashType & utxolib.bitgo.UtxoTransaction.SIGHASH_FORKID) !== 0;

// Get the base type (mask off the flags)
const baseType = hashType & Transaction.SIGHASH_OUTPUT_MASK;

switch (baseType) {
case Transaction.SIGHASH_DEFAULT:
parts.push('DEFAULT');
break;
case Transaction.SIGHASH_ALL:
parts.push('ALL');
break;
case Transaction.SIGHASH_NONE:
parts.push('NONE');
break;
case Transaction.SIGHASH_SINGLE:
parts.push('SINGLE');
break;
default:
parts.push(`UNKNOWN(${baseType})`);
}

if (hasForkId) {
parts.push('FORKID');
}

if (hasAnyoneCanPay) {
parts.push('ANYONECANPAY');
}

return parts.join('|');
}

type ParsedSignatureScript =
| utxolib.bitgo.ParsedSignatureScriptP2ms
| utxolib.bitgo.ParsedSignatureScriptP2shP2pk
Expand Down Expand Up @@ -164,6 +206,7 @@ export class InputParser extends Parser {
nodes.push(
this.node('isCanonical', script.isCanonicalScriptSignature(buf)),
this.node('hashType', hashType),
this.node('sighashType', getSighashName(hashType)),
this.node('r', r),
this.node('s', s),
this.node('highS', isHighS(s))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ transaction: a7b64a92c6fb7e0c6ea0b95c0db8a3253347d22f76562df4dc187ed5d442767b
│ │ │ ├── signedBy: user
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: cb6125485a4e9e2d98dafde8074a29d43ef28ffdd34f0d7f8048423f1fd54c01 (32 bytes)
│ │ │ ├── s: 65798d67d21f18383db7c4e9532e497b1b54d7e9c3676a079d9502cd0663963c (32 bytes)
│ │ │ └── highS: false
Expand All @@ -51,6 +52,7 @@ transaction: a7b64a92c6fb7e0c6ea0b95c0db8a3253347d22f76562df4dc187ed5d442767b
│ │ ├── signedBy: bitgo
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: c3a36135223671fac881d4a48f16b2698500887ac91530b4145000ba49509679 (32 bytes)
│ │ ├── s: 0737c216d2cc705b3d6d88d8443870be168c9bfad2525795ac14ec4ea3598ca8 (32 bytes)
│ │ └── highS: false
Expand Down Expand Up @@ -86,6 +88,7 @@ transaction: a7b64a92c6fb7e0c6ea0b95c0db8a3253347d22f76562df4dc187ed5d442767b
│ │ ├── signedBy: user
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: f0279fa27d0f85c4c3ee7ea3104963bd88ec02f62f23ae0b73d122293e58c7b8 (32 bytes)
│ │ ├── s: 24b8c9dca8d9d77bda69da70282a45422c2baf0d4a05ecbe57a48b65f92d950d (32 bytes)
│ │ └── highS: false
Expand All @@ -95,6 +98,7 @@ transaction: a7b64a92c6fb7e0c6ea0b95c0db8a3253347d22f76562df4dc187ed5d442767b
│ ├── signedBy: bitgo
│ ├── isCanonical: true
│ ├── hashType: 1
│ ├── sighashType: ALL
│ ├── r: 3bb213db0b4842ea5f8c1b9290c8b42dbe65f72bee29e4ad7e8d57e5f1639001 (32 bytes)
│ ├── s: 347df34c34a4df5fabe8571c7168c8111df7275a56672126f434bdc44fea6c59 (32 bytes)
│ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ transaction: 06e71efcabe05c7edc7fe77f1c4af3e5e21d74875ba6ada824718ead0299bde8
│ │ │ ├── bytes: 304402200bb8d9eff7f7f867828f7cbd22cc0d7d00fb0092cd61708f9cd2ceaef4db23ca02200517e29722fa4d880fe974c1a947f93a5d5b34be73ca73bae17fae01ab493d8e01 (71 bytes)
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: 0bb8d9eff7f7f867828f7cbd22cc0d7d00fb0092cd61708f9cd2ceaef4db23ca (32 bytes)
│ │ │ ├── s: 0517e29722fa4d880fe974c1a947f93a5d5b34be73ca73bae17fae01ab493d8e (32 bytes)
│ │ │ └── highS: false
│ │ └─┬ 1
│ │ ├── bytes: 30440220113e9e9019e5924e187e83a6a20b061e9e8fb2e308ab84594ad3845cbd2c614302202ea3d3067026e5e2ea3b0dae806978898b19e63c2c9da59d4506bbc084f1e39101 (71 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: 113e9e9019e5924e187e83a6a20b061e9e8fb2e308ab84594ad3845cbd2c6143 (32 bytes)
│ │ ├── s: 2ea3d3067026e5e2ea3b0dae806978898b19e63c2c9da59d4506bbc084f1e391 (32 bytes)
│ │ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ transaction: e4f8816466a730d07e51b5a545e072b4ca1ee78ad58a6d5c06b6dcd5fc492e87
│ │ ├── bytes: 304402200bb8d9eff7f7f867828f7cbd22cc0d7d00fb0092cd61708f9cd2ceaef4db23ca02200517e29722fa4d880fe974c1a947f93a5d5b34be73ca73bae17fae01ab493d8e01 (71 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: 0bb8d9eff7f7f867828f7cbd22cc0d7d00fb0092cd61708f9cd2ceaef4db23ca (32 bytes)
│ │ ├── s: 0517e29722fa4d880fe974c1a947f93a5d5b34be73ca73bae17fae01ab493d8e (32 bytes)
│ │ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ transaction: 58603ea06d55bd9dd6fec9b0d1ea5662d622f923e0f10045507723a893388e7f
│ │ │ ├── signedBy: user
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: 48a059c22437630fdd5bc3c46bd1e30438a3623a59050d5e5f2fb1a36686fd9e (32 bytes)
│ │ │ ├── s: 2ed8206b2f2472efd3ea145bc3c52703a7874fc747bdccc97cd5b862c8d62b74 (32 bytes)
│ │ │ └── highS: false
Expand All @@ -47,6 +48,7 @@ transaction: 58603ea06d55bd9dd6fec9b0d1ea5662d622f923e0f10045507723a893388e7f
│ │ ├── signedBy: bitgo
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: 138087371ab51032457bdca8ef134eb566a61b16631cf6bc296c8b243f938bf7 (32 bytes)
│ │ ├── s: 720ab74bfa5e39f2c764d1879dd6fea9b1f287611b1ea714fe5b0928bd13d469 (32 bytes)
│ │ └── highS: false
Expand Down Expand Up @@ -78,6 +80,7 @@ transaction: 58603ea06d55bd9dd6fec9b0d1ea5662d622f923e0f10045507723a893388e7f
│ │ ├── signedBy: user
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: afde55c0cfa9dc3a20fb8706c5a7f86c754efcbbaf866e09e84a18668c531484 (32 bytes)
│ │ ├── s: 3a7e0bb62cd5a951def97181f6a26d78b70c7ac22af79029f22b5b130785939f (32 bytes)
│ │ └── highS: false
Expand All @@ -87,6 +90,7 @@ transaction: 58603ea06d55bd9dd6fec9b0d1ea5662d622f923e0f10045507723a893388e7f
│ ├── signedBy: bitgo
│ ├── isCanonical: true
│ ├── hashType: 1
│ ├── sighashType: ALL
│ ├── r: 33ae8e7c8ef2109b804bc338e884109e5ed9e534307761aa5695a0eea3ce0615 (32 bytes)
│ ├── s: 45b4af31359339b6c696ca0f956e844baa8dd642b0e74ad2475e8fe5b4c055e8 (32 bytes)
│ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ transaction: a2fd68ec218a13fd3027692d3e4ef39e9f6ce4d5772815b7ed95bcb645d21c00
│ │ │ ├── bytes: 3044022044d9ee7818eab6a80ba2c80d2489ac310c78310005d365803c25ee7aca4f087a02206e3d4c3721cd33b41dae9025be1b55e8b4bc2d96319f4930b8d4ff6660f1658e01 (71 bytes)
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: 44d9ee7818eab6a80ba2c80d2489ac310c78310005d365803c25ee7aca4f087a (32 bytes)
│ │ │ ├── s: 6e3d4c3721cd33b41dae9025be1b55e8b4bc2d96319f4930b8d4ff6660f1658e (32 bytes)
│ │ │ └── highS: false
│ │ └─┬ 1
│ │ ├── bytes: 3045022100f1156445f152e400a7d38739010fb928fb26bd87bcfc20ab18a336b627c519d50220109cbf8e83b8f41f41bac98f70a20b4b252aa8b2df4177551a0d4ab379a1245701 (72 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: f1156445f152e400a7d38739010fb928fb26bd87bcfc20ab18a336b627c519d5 (32 bytes)
│ │ ├── s: 109cbf8e83b8f41f41bac98f70a20b4b252aa8b2df4177551a0d4ab379a12457 (32 bytes)
│ │ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ transaction: e97e9dfaff81a6c4ef02fa48c2af420639dd24921e25985af234599cdbb3134d
│ │ ├── bytes: 3044022044d9ee7818eab6a80ba2c80d2489ac310c78310005d365803c25ee7aca4f087a02206e3d4c3721cd33b41dae9025be1b55e8b4bc2d96319f4930b8d4ff6660f1658e01 (71 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: 44d9ee7818eab6a80ba2c80d2489ac310c78310005d365803c25ee7aca4f087a (32 bytes)
│ │ ├── s: 6e3d4c3721cd33b41dae9025be1b55e8b4bc2d96319f4930b8d4ff6660f1658e (32 bytes)
│ │ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ transaction: 2fedaa3661f6251d1a4ca23e5d4bb03fab5b75e8e471281f554755c439cd9924
│ │ │ ├── signedBy: user
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: e665acb4a9237b32d00052b4419ed699db1cd01522cec80d4714d66452efb982 (32 bytes)
│ │ │ ├── s: 29a3272a95f61e6a7d85b4605f735ffc4062c155d78c0b4bb3e35191997a6762 (32 bytes)
│ │ │ └── highS: false
Expand All @@ -47,6 +48,7 @@ transaction: 2fedaa3661f6251d1a4ca23e5d4bb03fab5b75e8e471281f554755c439cd9924
│ │ ├── signedBy: bitgo
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: 11f825047fcf6a13c7da282d27be5d5d4d82759b8c7f987f1dcaef88b4b104b1 (32 bytes)
│ │ ├── s: 5c333b6ac321bf7150823833452e5d3073c77dbab053430a4de5c3398e9cb370 (32 bytes)
│ │ └── highS: false
Expand Down Expand Up @@ -78,6 +80,7 @@ transaction: 2fedaa3661f6251d1a4ca23e5d4bb03fab5b75e8e471281f554755c439cd9924
│ │ ├── signedBy: user
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: 021aff10c307d538600552a18b7a4187bffd43390d7944164c8054d15645673f (32 bytes)
│ │ ├── s: 26a05412302b0c2c98b8805effc4e99e716e4f6f485dbce1a8c92a8440c498dc (32 bytes)
│ │ └── highS: false
Expand All @@ -87,6 +90,7 @@ transaction: 2fedaa3661f6251d1a4ca23e5d4bb03fab5b75e8e471281f554755c439cd9924
│ ├── signedBy: bitgo
│ ├── isCanonical: true
│ ├── hashType: 1
│ ├── sighashType: ALL
│ ├── r: 3436df8e3ce0c6e16d12a5f50f8c89a206e11cfd515c9e39f6f361f8f22a8b7a (32 bytes)
│ ├── s: 2c180bd360669abab214687aa520cb6a0ca4973cc65e58f40f0b7a982489e2a1 (32 bytes)
│ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ transaction: 91d1162f0975c30e2422f2b6e3d0cf6174ce217d2987519f1e7d3894e035a721
│ │ │ ├── bytes: 3045022100cd89f929b9c83a3de22a663c151811b0a4fa99a9611285c0b18879306eec25d602205b579499e3405fa2fd0b709335c53733dee14e5f245e4bd64786257f6d93f97b01 (72 bytes)
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: cd89f929b9c83a3de22a663c151811b0a4fa99a9611285c0b18879306eec25d6 (32 bytes)
│ │ │ ├── s: 5b579499e3405fa2fd0b709335c53733dee14e5f245e4bd64786257f6d93f97b (32 bytes)
│ │ │ └── highS: false
│ │ └─┬ 1
│ │ ├── bytes: 3045022100f38d2028cea38e7b0f34d8a55bc770d256663052a3b05fd8664ae6b7390d31ea02202832d00bea346aca4af6de97b0dcdfbe225d6f1f3fc972077ad935aff7de3b4701 (72 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: f38d2028cea38e7b0f34d8a55bc770d256663052a3b05fd8664ae6b7390d31ea (32 bytes)
│ │ ├── s: 2832d00bea346aca4af6de97b0dcdfbe225d6f1f3fc972077ad935aff7de3b47 (32 bytes)
│ │ └── highS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ transaction: 91d1162f0975c30e2422f2b6e3d0cf6174ce217d2987519f1e7d3894e035a721
│ │ ├── bytes: 3045022100cd89f929b9c83a3de22a663c151811b0a4fa99a9611285c0b18879306eec25d602205b579499e3405fa2fd0b709335c53733dee14e5f245e4bd64786257f6d93f97b01 (72 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: cd89f929b9c83a3de22a663c151811b0a4fa99a9611285c0b18879306eec25d6 (32 bytes)
│ │ ├── s: 5b579499e3405fa2fd0b709335c53733dee14e5f245e4bd64786257f6d93f97b (32 bytes)
│ │ └── highS: false
Expand Down
2 changes: 2 additions & 0 deletions modules/utxo-bin/test/fixtures/psbt/5.sign.psbt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ transaction: 6725a9fe23fc611d26173cf24169530c7c599794a1b57e8b8364ff34e94a8a52
│ │ │ ├── bytes: 3045022100ca24680ba04a934ea1ee49c696fae83c05e55bc57155bcb6bedc45f21d25e65d02204030196a0bb02e83b70205996082215f454421d8f0a2ea8d60f2db9c8701401a01 (72 bytes)
│ │ │ ├── isCanonical: true
│ │ │ ├── hashType: 1
│ │ │ ├── sighashType: ALL
│ │ │ ├── r: ca24680ba04a934ea1ee49c696fae83c05e55bc57155bcb6bedc45f21d25e65d (32 bytes)
│ │ │ ├── s: 4030196a0bb02e83b70205996082215f454421d8f0a2ea8d60f2db9c8701401a (32 bytes)
│ │ │ └── highS: false
│ │ └─┬ 1
│ │ ├── bytes: 3045022100e6caa18f00638ccf4df22cc194900313e503825c35934bf9c3adfc7b287328c702206c70e7596ded5231efe43c6fef3e8dd6a43d9d318ae86436d6624c80ba760c5201 (72 bytes)
│ │ ├── isCanonical: true
│ │ ├── hashType: 1
│ │ ├── sighashType: ALL
│ │ ├── r: e6caa18f00638ccf4df22cc194900313e503825c35934bf9c3adfc7b287328c7 (32 bytes)
│ │ ├── s: 6c70e7596ded5231efe43c6fef3e8dd6a43d9d318ae86436d6624c80ba760c52 (32 bytes)
│ │ └── highS: false
Expand Down
Loading