Skip to content
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

Merged
merged 10 commits into from
Nov 12, 2021
Merged

Conversation

mrnerdhair
Copy link
Contributor

Resolves #362

@vercel
Copy link

vercel bot commented Oct 26, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/shapeshift/hdwallet/2WJCMZCfJ6Z6MV7QNws9YwYgyqKu
✅ Preview: https://hdwallet-git-avoid-type-hell-shapeshift.vercel.app

@@ -28,7 +30,6 @@ export interface BitcoinScriptSig {
* Deserialized representation of an already-signed input of a transaction.
*/
interface BitcoinInputBase {
valueSat: number;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

Comment on lines +138 to +160
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"),
},
})),
};
})();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BitcoinChainAdapter in lib
1 participant