-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make KK parse its own TXes to avoid type hell #363
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/shapeshift/hdwallet/2WJCMZCfJ6Z6MV7QNws9YwYgyqKu |
@@ -28,7 +30,6 @@ export interface BitcoinScriptSig { | |||
* Deserialized representation of an already-signed input of a transaction. | |||
*/ | |||
interface BitcoinInputBase { | |||
valueSat: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no clue where this came from, but we don't use it anywhere.
}; | ||
|
||
type BTCSignTxInputKKNonSegwit = BTCSignTxInputKKBase & { | ||
scriptType: Exclude<BTCInputScriptType, BTCSignTxInputKKSegwit["scriptType"]>; | ||
tx: BitcoinTx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole BitcoinTx
type is non-standard and used only here. We should deprecate it in a later breaking change, and nuke it entirely.
@@ -106,12 +107,19 @@ type BTCSignTxInputKKBase = BTCSignTxInputBase & { | |||
|
|||
type BTCSignTxInputKKSegwit = BTCSignTxInputKKBase & { | |||
scriptType: BTCInputScriptType.SpendWitness | BTCInputScriptType.SpendP2SHWitness | BTCInputScriptType.External; | |||
hex?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just to make GuardedUnion
happy with BTCSignTxInputSafe
, but I don't really care at this point
const prevTx = ((): core.BitcoinTx => { | ||
if (inputTx.tx) return inputTx.tx; | ||
if (!inputTx.hex) throw new Error("non-segwit inputs must have the associated prev tx"); | ||
const tx = bitcoinjs.Transaction.fromHex(inputTx.hex); | ||
return { | ||
version: tx.version, | ||
locktime: tx.locktime, | ||
vin: tx.ins.map((input) => ({ | ||
txid: Buffer.from(input.hash).reverse().toString("hex"), | ||
vout: input.index, | ||
scriptSig: { | ||
hex: input.script.toString("hex"), | ||
}, | ||
sequence: input.sequence, | ||
})), | ||
vout: tx.outs.map((output, i) => ({ | ||
value: String(output.value), | ||
scriptPubKey: { | ||
hex: output.script.toString("hex"), | ||
}, | ||
})), | ||
}; | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parts adapted from bitcoinjs/bitcoinjs-lib#1606 (comment)
6ed43a7
to
ee00ffc
Compare
9a3c452
to
91cf696
Compare
Resolves #362