Skip to content

Commit 5426797

Browse files
author
Danny Diekroeger
committed
updated signed to successfully sign zcash and bch
1 parent d6e55de commit 5426797

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/sign.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
9191
}
9292

9393
const isBCH = recoveryRequest.coin === 'bch' || recoveryRequest.coin === 'tbch';
94+
const isZEC = recoveryRequest.coin === 'zec' || recoveryRequest.coin === 'tzec';
9495
const transaction = utxoLib.Transaction.fromHex(recoveryRequest.transactionHex, network);
9596

9697
const outputs = transaction.outs.map(out => ({
@@ -110,15 +111,21 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
110111
// force override network as we use btc mainnet xpubs for all utxo coins
111112
backupKeyNode.keyPair.network = network;
112113

113-
// For BCH we need to add the input values to each input, because input values must be signed
114-
if (isBCH) {
114+
115+
// For BCH and ZEC we need to add the input values to each input, because input values must be signed
116+
if (isBCH || isZEC) {
115117
transaction.ins.forEach(function (input, i) {
116118
transaction.ins[i].value = recoveryRequest.inputs[i].amount;
117119
})
118120
}
119121

120122
const txBuilder = utxoLib.TransactionBuilder.fromTransaction(transaction, network);
121123

124+
if(isZEC) {
125+
txBuilder.setVersion(utxoLib.Transaction.ZCASH_SAPLING_VERSION);
126+
txBuilder.setVersionGroupId(0x892f2085);
127+
}
128+
122129
_.forEach(recoveryRequest.inputs, function(input, i) {
123130
const isBech32 = !input.redeemScript;
124131
const isSegwit = !!input.witnessScript;
@@ -147,7 +154,7 @@ const handleSignUtxo = function(recoveryRequest, key, skipConfirm) {
147154
const witnessScript = new Buffer(input.witnessScript, 'hex');
148155
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript, utxoLib.Transaction.SIGHASH_ALL, input.amount, witnessScript)
149156
} else {
150-
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript, utxoLib.Transaction.SIGHASH_ALL);
157+
txBuilder.sign(i, derivedHDNode.keyPair, redeemScript, utxoLib.Transaction.SIGHASH_ALL, input.amount);
151158
}
152159
}
153160
}

0 commit comments

Comments
 (0)