Skip to content

Commit a3c50c0

Browse files
authored
fix: zcash transaction version (#1617)
1 parent 30ba137 commit a3c50c0

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

.changeset/puny-days-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@swapkit/toolboxes": patch
3+
---
4+
5+
Fixes TX version of Zcash transactions

bun.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"devDependencies": {
33
"@biomejs/biome": "2.3.4",
4-
"@bitgo/utxo-lib": "11.13.1",
4+
"@bitgo/utxo-lib": "11.16.1",
55
"@changesets/changelog-github": "0.5.1",
66
"@changesets/cli": "2.29.7",
77
"@cosmjs/amino": "0.37.0",

packages/toolboxes/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"@bitcoinerlab/secp256k1": "~1.2.0",
4-
"@bitgo/utxo-lib": "~11.13.1",
4+
"@bitgo/utxo-lib": "11.16.1",
55
"@cosmjs/amino": "~0.37.0",
66
"@cosmjs/crypto": "0.37.0",
77
"@cosmjs/proto-signing": "~0.37.0",
@@ -52,7 +52,7 @@
5252
"description": "SwapKit - Toolboxes",
5353
"devDependencies": {
5454
"@bitcoinerlab/secp256k1": "1.2.0",
55-
"@bitgo/utxo-lib": "11.13.1",
55+
"@bitgo/utxo-lib": "11.16.1",
5656
"@cosmjs/amino": "0.37.0",
5757
"@cosmjs/crypto": "0.37.0",
5858
"@cosmjs/proto-signing": "0.37.0",

packages/toolboxes/src/utxo/toolbox/zcash.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { bitgo, crypto, ECPair, networks, address as zcashAddress } from "@bitgo/utxo-lib";
2-
import type { ZcashPsbt } from "@bitgo/utxo-lib/dist/src/bitgo";
2+
import { type ZcashPsbt, ZcashTransaction } from "@bitgo/utxo-lib/dist/src/bitgo";
33
import { HDKey } from "@scure/bip32";
44
import { mnemonicToSeedSync } from "@scure/bip39";
55
import {
@@ -143,17 +143,10 @@ async function createTransaction(buildTxParams: UTXOBuildTxParams) {
143143
throw new SwapKitError("toolbox_utxo_insufficient_balance", { assetValue, sender });
144144
}
145145

146-
const psbt = bitgo.createPsbtForNetwork({ network: getZcashNetwork() }, { version: 455 }) as ZcashPsbt;
147-
148-
const branchId = 0x4dec4df0;
149-
150-
const CONSENSUS_BRANCH_ID_KEY = Buffer.concat([Buffer.of(0xfc), Buffer.of(0x05), Buffer.from("BITGO"), Buffer.of(0)]);
151-
152-
// PSBT value must be 4-byte little-endian
153-
const value = Buffer.allocUnsafe(4);
154-
value.writeUInt32LE(branchId >>> 0, 0);
155-
156-
psbt.addUnknownKeyValToGlobal({ key: CONSENSUS_BRANCH_ID_KEY, value });
146+
const psbt = bitgo.createPsbtForNetwork(
147+
{ network: getZcashNetwork() },
148+
{ version: ZcashTransaction.VERSION4_BRANCH_NU6_1 },
149+
) as ZcashPsbt;
157150

158151
const { psbt: mappedPsbt, inputs: mappedInputs } = await addInputsAndOutputs({
159152
compiledMemo,
@@ -163,6 +156,8 @@ async function createTransaction(buildTxParams: UTXOBuildTxParams) {
163156
sender,
164157
});
165158

159+
mappedPsbt.setDefaultsForVersion(getZcashNetwork(), ZcashTransaction.VERSION4_BRANCH_NU6_1);
160+
166161
return { inputs: mappedInputs, outputs, psbt: mappedPsbt };
167162
}
168163

@@ -194,9 +189,14 @@ export async function createZcashToolbox(
194189

195190
const signedPsbt = await signer.signTransaction(psbt);
196191

192+
signedPsbt.validateSignaturesOfAllInputs();
193+
197194
signedPsbt.finalizeAllInputs();
198195

199-
return baseToolbox.broadcastTx(signedPsbt.extractTransaction().toHex());
196+
const finalTx = signedPsbt.extractTransaction();
197+
const txHex = finalTx.toHex();
198+
199+
return baseToolbox.broadcastTx(txHex);
200200
}
201201

202202
function createKeysForPath({

0 commit comments

Comments
 (0)