utxo-lib 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/src/address.d.ts +11 -0
- package/dist/src/address.d.ts.map +1 -0
- package/dist/src/address.js +37 -0
- package/dist/src/addressFormat.d.ts +53 -0
- package/dist/src/addressFormat.d.ts.map +1 -0
- package/dist/src/addressFormat.js +110 -0
- package/dist/src/bitgo/Musig2.d.ts +51 -0
- package/dist/src/bitgo/Musig2.d.ts.map +1 -0
- package/dist/src/bitgo/Musig2.js +175 -0
- package/dist/src/bitgo/Unspent.d.ts +95 -0
- package/dist/src/bitgo/Unspent.d.ts.map +1 -0
- package/dist/src/bitgo/Unspent.js +138 -0
- package/dist/src/bitgo/UtxoPsbt.d.ts +132 -0
- package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/UtxoPsbt.js +469 -0
- package/dist/src/bitgo/UtxoTransaction.d.ts +22 -0
- package/dist/src/bitgo/UtxoTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/UtxoTransaction.js +97 -0
- package/dist/src/bitgo/UtxoTransactionBuilder.d.ts +26 -0
- package/dist/src/bitgo/UtxoTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/UtxoTransactionBuilder.js +67 -0
- package/dist/src/bitgo/bbc/DashPsbt.d.ts +12 -0
- package/dist/src/bitgo/bbc/DashPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/DashPsbt.js +27 -0
- package/dist/src/bitgo/bbc/DashTransaction.d.ts +39 -0
- package/dist/src/bitgo/bbc/DashTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/DashTransaction.js +109 -0
- package/dist/src/bitgo/bbc/DashTransactionBuilder.d.ts +14 -0
- package/dist/src/bitgo/bbc/DashTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/DashTransactionBuilder.js +28 -0
- package/dist/src/bitgo/bbc/index.d.ts +4 -0
- package/dist/src/bitgo/bbc/index.d.ts.map +1 -0
- package/dist/src/bitgo/bbc/index.js +16 -0
- package/dist/src/bitgo/bitcoincash/address.d.ts +35 -0
- package/dist/src/bitgo/bitcoincash/address.d.ts.map +1 -0
- package/dist/src/bitgo/bitcoincash/address.js +151 -0
- package/dist/src/bitgo/bitcoincash/index.d.ts +2 -0
- package/dist/src/bitgo/bitcoincash/index.d.ts.map +1 -0
- package/dist/src/bitgo/bitcoincash/index.js +14 -0
- package/dist/src/bitgo/dash/DashPsbt.d.ts +12 -0
- package/dist/src/bitgo/dash/DashPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/dash/DashPsbt.js +27 -0
- package/dist/src/bitgo/dash/DashTransaction.d.ts +39 -0
- package/dist/src/bitgo/dash/DashTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/dash/DashTransaction.js +109 -0
- package/dist/src/bitgo/dash/DashTransactionBuilder.d.ts +14 -0
- package/dist/src/bitgo/dash/DashTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/dash/DashTransactionBuilder.js +28 -0
- package/dist/src/bitgo/dash/index.d.ts +4 -0
- package/dist/src/bitgo/dash/index.d.ts.map +1 -0
- package/dist/src/bitgo/dash/index.js +16 -0
- package/dist/src/bitgo/index.d.ts +17 -0
- package/dist/src/bitgo/index.d.ts.map +1 -0
- package/dist/src/bitgo/index.js +30 -0
- package/dist/src/bitgo/keyutil.d.ts +17 -0
- package/dist/src/bitgo/keyutil.d.ts.map +1 -0
- package/dist/src/bitgo/keyutil.js +37 -0
- package/dist/src/bitgo/nonStandardHalfSigned.d.ts +7 -0
- package/dist/src/bitgo/nonStandardHalfSigned.d.ts.map +1 -0
- package/dist/src/bitgo/nonStandardHalfSigned.js +56 -0
- package/dist/src/bitgo/outputScripts.d.ts +84 -0
- package/dist/src/bitgo/outputScripts.d.ts.map +1 -0
- package/dist/src/bitgo/outputScripts.js +297 -0
- package/dist/src/bitgo/parseInput.d.ts +92 -0
- package/dist/src/bitgo/parseInput.d.ts.map +1 -0
- package/dist/src/bitgo/parseInput.js +344 -0
- package/dist/src/bitgo/psbt/fromHalfSigned.d.ts +24 -0
- package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -0
- package/dist/src/bitgo/psbt/fromHalfSigned.js +91 -0
- package/dist/src/bitgo/psbt/scriptTypes.d.ts +6 -0
- package/dist/src/bitgo/psbt/scriptTypes.d.ts.map +1 -0
- package/dist/src/bitgo/psbt/scriptTypes.js +23 -0
- package/dist/src/bitgo/signature.d.ts +84 -0
- package/dist/src/bitgo/signature.d.ts.map +1 -0
- package/dist/src/bitgo/signature.js +222 -0
- package/dist/src/bitgo/tnumber.d.ts +9 -0
- package/dist/src/bitgo/tnumber.d.ts.map +1 -0
- package/dist/src/bitgo/tnumber.js +31 -0
- package/dist/src/bitgo/transaction.d.ts +29 -0
- package/dist/src/bitgo/transaction.d.ts.map +1 -0
- package/dist/src/bitgo/transaction.js +247 -0
- package/dist/src/bitgo/types.d.ts +5 -0
- package/dist/src/bitgo/types.d.ts.map +1 -0
- package/dist/src/bitgo/types.js +12 -0
- package/dist/src/bitgo/wallet/Psbt.d.ts +47 -0
- package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/Psbt.js +232 -0
- package/dist/src/bitgo/wallet/Unspent.d.ts +47 -0
- package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/Unspent.js +154 -0
- package/dist/src/bitgo/wallet/WalletKeys.d.ts +72 -0
- package/dist/src/bitgo/wallet/WalletKeys.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletKeys.js +104 -0
- package/dist/src/bitgo/wallet/WalletOutput.d.ts +18 -0
- package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletOutput.js +69 -0
- package/dist/src/bitgo/wallet/WalletScripts.d.ts +7 -0
- package/dist/src/bitgo/wallet/WalletScripts.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletScripts.js +15 -0
- package/dist/src/bitgo/wallet/WalletUnspentSigner.d.ts +19 -0
- package/dist/src/bitgo/wallet/WalletUnspentSigner.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/WalletUnspentSigner.js +47 -0
- package/dist/src/bitgo/wallet/chains.d.ts +57 -0
- package/dist/src/bitgo/wallet/chains.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/chains.js +106 -0
- package/dist/src/bitgo/wallet/index.d.ts +8 -0
- package/dist/src/bitgo/wallet/index.d.ts.map +1 -0
- package/dist/src/bitgo/wallet/index.js +20 -0
- package/dist/src/bitgo/zcash/ZcashBufferutils.d.ts +26 -0
- package/dist/src/bitgo/zcash/ZcashBufferutils.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashBufferutils.js +157 -0
- package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +36 -0
- package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashPsbt.js +146 -0
- package/dist/src/bitgo/zcash/ZcashTransaction.d.ts +61 -0
- package/dist/src/bitgo/zcash/ZcashTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashTransaction.js +341 -0
- package/dist/src/bitgo/zcash/ZcashTransactionBuilder.d.ts +21 -0
- package/dist/src/bitgo/zcash/ZcashTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/ZcashTransactionBuilder.js +105 -0
- package/dist/src/bitgo/zcash/address.d.ts +8 -0
- package/dist/src/bitgo/zcash/address.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/address.js +57 -0
- package/dist/src/bitgo/zcash/hashZip0244.d.ts +27 -0
- package/dist/src/bitgo/zcash/hashZip0244.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/hashZip0244.js +184 -0
- package/dist/src/bitgo/zcash/index.d.ts +4 -0
- package/dist/src/bitgo/zcash/index.d.ts.map +1 -0
- package/dist/src/bitgo/zcash/index.js +16 -0
- package/dist/src/classify.d.ts +19 -0
- package/dist/src/classify.d.ts.map +1 -0
- package/dist/src/classify.js +89 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +36 -0
- package/dist/src/networks.d.ts +119 -0
- package/dist/src/networks.d.ts.map +1 -0
- package/dist/src/networks.js +477 -0
- package/dist/src/noble_ecc.d.ts +28 -0
- package/dist/src/noble_ecc.d.ts.map +1 -0
- package/dist/src/noble_ecc.js +168 -0
- package/dist/src/payments/index.d.ts +4 -0
- package/dist/src/payments/index.d.ts.map +1 -0
- package/dist/src/payments/index.js +8 -0
- package/dist/src/payments/p2tr.d.ts +3 -0
- package/dist/src/payments/p2tr.d.ts.map +1 -0
- package/dist/src/payments/p2tr.js +348 -0
- package/dist/src/payments/p2tr_ns.d.ts +3 -0
- package/dist/src/payments/p2tr_ns.d.ts.map +1 -0
- package/dist/src/payments/p2tr_ns.js +134 -0
- package/dist/src/taproot.d.ts +141 -0
- package/dist/src/taproot.d.ts.map +1 -0
- package/dist/src/taproot.js +384 -0
- package/dist/src/templates/multisig/index.d.ts +4 -0
- package/dist/src/templates/multisig/index.d.ts.map +1 -0
- package/dist/src/templates/multisig/index.js +8 -0
- package/dist/src/templates/multisig/input.d.ts +7 -0
- package/dist/src/templates/multisig/input.d.ts.map +1 -0
- package/dist/src/templates/multisig/input.js +25 -0
- package/dist/src/templates/multisig/output.d.ts +7 -0
- package/dist/src/templates/multisig/output.d.ts.map +1 -0
- package/dist/src/templates/multisig/output.js +38 -0
- package/dist/src/templates/nulldata.d.ts +10 -0
- package/dist/src/templates/nulldata.d.ts.map +1 -0
- package/dist/src/templates/nulldata.js +17 -0
- package/dist/src/templates/pubkey/index.d.ts +4 -0
- package/dist/src/templates/pubkey/index.d.ts.map +1 -0
- package/dist/src/templates/pubkey/index.js +8 -0
- package/dist/src/templates/pubkey/input.d.ts +7 -0
- package/dist/src/templates/pubkey/input.d.ts.map +1 -0
- package/dist/src/templates/pubkey/input.js +14 -0
- package/dist/src/templates/pubkey/output.d.ts +7 -0
- package/dist/src/templates/pubkey/output.d.ts.map +1 -0
- package/dist/src/templates/pubkey/output.js +15 -0
- package/dist/src/templates/pubkeyhash/index.d.ts +4 -0
- package/dist/src/templates/pubkeyhash/index.d.ts.map +1 -0
- package/dist/src/templates/pubkeyhash/index.js +8 -0
- package/dist/src/templates/pubkeyhash/input.d.ts +7 -0
- package/dist/src/templates/pubkeyhash/input.d.ts.map +1 -0
- package/dist/src/templates/pubkeyhash/input.js +16 -0
- package/dist/src/templates/pubkeyhash/output.d.ts +6 -0
- package/dist/src/templates/pubkeyhash/output.d.ts.map +1 -0
- package/dist/src/templates/pubkeyhash/output.js +20 -0
- package/dist/src/templates/scripthash/index.d.ts +4 -0
- package/dist/src/templates/scripthash/index.d.ts.map +1 -0
- package/dist/src/templates/scripthash/index.js +8 -0
- package/dist/src/templates/scripthash/input.d.ts +6 -0
- package/dist/src/templates/scripthash/input.d.ts.map +1 -0
- package/dist/src/templates/scripthash/input.js +43 -0
- package/dist/src/templates/scripthash/output.d.ts +6 -0
- package/dist/src/templates/scripthash/output.d.ts.map +1 -0
- package/dist/src/templates/scripthash/output.js +15 -0
- package/dist/src/templates/taproot/index.d.ts +4 -0
- package/dist/src/templates/taproot/index.d.ts.map +1 -0
- package/dist/src/templates/taproot/index.js +8 -0
- package/dist/src/templates/taproot/input.d.ts +6 -0
- package/dist/src/templates/taproot/input.d.ts.map +1 -0
- package/dist/src/templates/taproot/input.js +23 -0
- package/dist/src/templates/taproot/output.d.ts +6 -0
- package/dist/src/templates/taproot/output.d.ts.map +1 -0
- package/dist/src/templates/taproot/output.js +15 -0
- package/dist/src/templates/taprootnofn/index.d.ts +4 -0
- package/dist/src/templates/taprootnofn/index.d.ts.map +1 -0
- package/dist/src/templates/taprootnofn/index.js +8 -0
- package/dist/src/templates/taprootnofn/input.d.ts +7 -0
- package/dist/src/templates/taprootnofn/input.d.ts.map +1 -0
- package/dist/src/templates/taprootnofn/input.js +24 -0
- package/dist/src/templates/taprootnofn/output.d.ts +7 -0
- package/dist/src/templates/taprootnofn/output.d.ts.map +1 -0
- package/dist/src/templates/taprootnofn/output.js +28 -0
- package/dist/src/templates/witnesscommitment/index.d.ts +3 -0
- package/dist/src/templates/witnesscommitment/index.d.ts.map +1 -0
- package/dist/src/templates/witnesscommitment/index.js +6 -0
- package/dist/src/templates/witnesscommitment/output.d.ts +8 -0
- package/dist/src/templates/witnesscommitment/output.d.ts.map +1 -0
- package/dist/src/templates/witnesscommitment/output.js +31 -0
- package/dist/src/templates/witnesspubkeyhash/index.d.ts +4 -0
- package/dist/src/templates/witnesspubkeyhash/index.d.ts.map +1 -0
- package/dist/src/templates/witnesspubkeyhash/index.js +8 -0
- package/dist/src/templates/witnesspubkeyhash/input.d.ts +7 -0
- package/dist/src/templates/witnesspubkeyhash/input.d.ts.map +1 -0
- package/dist/src/templates/witnesspubkeyhash/input.js +19 -0
- package/dist/src/templates/witnesspubkeyhash/output.d.ts +6 -0
- package/dist/src/templates/witnesspubkeyhash/output.d.ts.map +1 -0
- package/dist/src/templates/witnesspubkeyhash/output.js +15 -0
- package/dist/src/templates/witnessscripthash/index.d.ts +4 -0
- package/dist/src/templates/witnessscripthash/index.d.ts.map +1 -0
- package/dist/src/templates/witnessscripthash/index.js +8 -0
- package/dist/src/templates/witnessscripthash/input.d.ts +6 -0
- package/dist/src/templates/witnessscripthash/input.d.ts.map +1 -0
- package/dist/src/templates/witnessscripthash/input.js +35 -0
- package/dist/src/templates/witnessscripthash/output.d.ts +6 -0
- package/dist/src/templates/witnessscripthash/output.d.ts.map +1 -0
- package/dist/src/templates/witnessscripthash/output.js +15 -0
- package/dist/src/testutil/index.d.ts +3 -0
- package/dist/src/testutil/index.d.ts.map +1 -0
- package/dist/src/testutil/index.js +15 -0
- package/dist/src/testutil/keys.d.ts +10 -0
- package/dist/src/testutil/keys.d.ts.map +1 -0
- package/dist/src/testutil/keys.js +40 -0
- package/dist/src/testutil/mock.d.ts +21 -0
- package/dist/src/testutil/mock.d.ts.map +1 -0
- package/dist/src/testutil/mock.js +86 -0
- package/dist/src/transaction_builder.d.ts +47 -0
- package/dist/src/transaction_builder.d.ts.map +1 -0
- package/dist/src/transaction_builder.js +1084 -0
- package/package.json +87 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ZcashPsbt = void 0;
|
4
|
+
const UtxoPsbt_1 = require("../UtxoPsbt");
|
5
|
+
const ZcashTransaction_1 = require("./ZcashTransaction");
|
6
|
+
const __1 = require("../../");
|
7
|
+
const bip174_1 = require("bip174");
|
8
|
+
const types = require("bitcoinjs-lib/src/types");
|
9
|
+
const typeforce = require('typeforce');
|
10
|
+
const CONSENSUS_BRANCH_ID_KEY = Buffer.concat([
|
11
|
+
Buffer.of(0xfc),
|
12
|
+
Buffer.of(0x05),
|
13
|
+
Buffer.from(UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER),
|
14
|
+
Buffer.of(UtxoPsbt_1.ProprietaryKeySubtype.ZEC_CONSENSUS_BRANCH_ID),
|
15
|
+
]);
|
16
|
+
class ZcashPsbt extends UtxoPsbt_1.UtxoPsbt {
|
17
|
+
static transactionFromBuffer(buffer, network) {
|
18
|
+
return ZcashTransaction_1.ZcashTransaction.fromBuffer(buffer, false, 'bigint', network);
|
19
|
+
}
|
20
|
+
static createPsbt(opts, data) {
|
21
|
+
return new ZcashPsbt(opts, data || new bip174_1.Psbt(new __1.PsbtTransaction({ tx: new ZcashTransaction_1.ZcashTransaction(opts.network) })));
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* In version < 5 of Zcash transactions, the consensus branch ID is not serialized in the transaction
|
25
|
+
* whereas in version 5 it is. If the transaction is less than a version 5, set the consensus branch id
|
26
|
+
* in the global map in the psbt. If it is a version 5 transaction, throw an error if the consensus
|
27
|
+
* branch id is set in the psbt (because it should be on the transaction already).
|
28
|
+
* @param buffer Psbt buffer
|
29
|
+
* @param opts options
|
30
|
+
*/
|
31
|
+
static fromBuffer(buffer, opts) {
|
32
|
+
var _a;
|
33
|
+
const psbt = super.fromBuffer(buffer, opts);
|
34
|
+
// Read `consensusBranchId` from the global-map
|
35
|
+
let consensusBranchId = undefined;
|
36
|
+
(_a = psbt.data.globalMap.unknownKeyVals) === null || _a === void 0 ? void 0 : _a.forEach(({ key, value }, i) => {
|
37
|
+
if (key.equals(CONSENSUS_BRANCH_ID_KEY)) {
|
38
|
+
consensusBranchId = value.readUint32LE();
|
39
|
+
}
|
40
|
+
});
|
41
|
+
switch (psbt.tx.version) {
|
42
|
+
case 4:
|
43
|
+
case ZcashTransaction_1.ZcashTransaction.VERSION4_BRANCH_CANOPY:
|
44
|
+
case ZcashTransaction_1.ZcashTransaction.VERSION4_BRANCH_NU5:
|
45
|
+
if (!consensusBranchId || !psbt.data.globalMap.unknownKeyVals) {
|
46
|
+
throw new Error('Could not find consensus branch id on psbt for version 4 Zcash transaction');
|
47
|
+
}
|
48
|
+
psbt.tx.consensusBranchId = consensusBranchId;
|
49
|
+
psbt.data.globalMap.unknownKeyVals = psbt.data.globalMap.unknownKeyVals.filter(({ key }) => key !== CONSENSUS_BRANCH_ID_KEY);
|
50
|
+
// Delete consensusBranchId from globalMap so that if we were to serialize the psbt again
|
51
|
+
// we would not add a duplicate key into the global map
|
52
|
+
psbt.data.globalMap.unknownKeyVals.pop();
|
53
|
+
return psbt;
|
54
|
+
case 5:
|
55
|
+
case ZcashTransaction_1.ZcashTransaction.VERSION5_BRANCH_NU5:
|
56
|
+
if (consensusBranchId) {
|
57
|
+
throw new Error('Found consensus branch id in psbt global-map for version 5 Zcash transaction');
|
58
|
+
}
|
59
|
+
return psbt;
|
60
|
+
default:
|
61
|
+
throw new Error(`Unsupported transaction version ${psbt.tx.version}`);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* If it is a version 4 transaction, add the consensus branch id to
|
66
|
+
* the global map. If it is a version 5 transaction, just return the
|
67
|
+
* buffer because the consensus branch id is already serialized in
|
68
|
+
* the transaction.
|
69
|
+
*/
|
70
|
+
toBuffer() {
|
71
|
+
if (this.tx.version === 5 || this.tx.version === ZcashTransaction_1.ZcashTransaction.VERSION5_BRANCH_NU5) {
|
72
|
+
return super.toBuffer();
|
73
|
+
}
|
74
|
+
const value = Buffer.alloc(4);
|
75
|
+
value.writeUint32LE(this.tx.consensusBranchId);
|
76
|
+
this.addUnknownKeyValToGlobal({ key: CONSENSUS_BRANCH_ID_KEY, value });
|
77
|
+
if (!this.data.globalMap.unknownKeyVals) {
|
78
|
+
throw new Error('Failed adding consensus branch id to unknownKeyVals');
|
79
|
+
}
|
80
|
+
const buff = super.toBuffer();
|
81
|
+
this.data.globalMap.unknownKeyVals.pop();
|
82
|
+
return buff;
|
83
|
+
}
|
84
|
+
setVersion(version, overwinter = true) {
|
85
|
+
typeforce(types.UInt32, version);
|
86
|
+
this.tx.overwintered = overwinter ? 1 : 0;
|
87
|
+
this.tx.version = version;
|
88
|
+
return this;
|
89
|
+
}
|
90
|
+
setDefaultsForVersion(network, version) {
|
91
|
+
switch (version) {
|
92
|
+
case 4:
|
93
|
+
case ZcashTransaction_1.ZcashTransaction.VERSION4_BRANCH_CANOPY:
|
94
|
+
case ZcashTransaction_1.ZcashTransaction.VERSION4_BRANCH_NU5:
|
95
|
+
this.setVersion(4);
|
96
|
+
break;
|
97
|
+
case 5:
|
98
|
+
case ZcashTransaction_1.ZcashTransaction.VERSION5_BRANCH_NU5:
|
99
|
+
this.setVersion(5);
|
100
|
+
break;
|
101
|
+
default:
|
102
|
+
throw new Error(`invalid version ${version}`);
|
103
|
+
}
|
104
|
+
this.tx.versionGroupId = ZcashTransaction_1.getDefaultVersionGroupIdForVersion(version);
|
105
|
+
this.tx.consensusBranchId = ZcashTransaction_1.getDefaultConsensusBranchIdForVersion(network, version);
|
106
|
+
}
|
107
|
+
// For Zcash transactions, we do not have to have non-witness UTXO data for non-segwit
|
108
|
+
// transactions because zcash hashes the value directly. Thus, it is unnecessary to have
|
109
|
+
// the previous transaction hash on the unspent.
|
110
|
+
signInput(inputIndex, keyPair, sighashTypes) {
|
111
|
+
return this.withUnsafeSignNonSegwitTrue(super.signInput.bind(this, inputIndex, keyPair, sighashTypes));
|
112
|
+
}
|
113
|
+
validateSignaturesOfInput(inputIndex, validator, pubkey) {
|
114
|
+
return this.withUnsafeSignNonSegwitTrue(super.validateSignaturesOfInput.bind(this, inputIndex, validator, pubkey));
|
115
|
+
}
|
116
|
+
withUnsafeSignNonSegwitTrue(fn) {
|
117
|
+
this.__CACHE.__UNSAFE_SIGN_NONSEGWIT = true;
|
118
|
+
try {
|
119
|
+
return fn();
|
120
|
+
}
|
121
|
+
finally {
|
122
|
+
this.__CACHE.__UNSAFE_SIGN_NONSEGWIT = false;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
setPropertyCheckSignatures(propName, value) {
|
126
|
+
if (this.tx[propName] === value) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
this.checkForSignatures(propName);
|
130
|
+
this.tx[propName] = value;
|
131
|
+
}
|
132
|
+
setConsensusBranchId(consensusBranchId) {
|
133
|
+
typeforce(types.UInt32, consensusBranchId);
|
134
|
+
this.setPropertyCheckSignatures('consensusBranchId', consensusBranchId);
|
135
|
+
}
|
136
|
+
setVersionGroupId(versionGroupId) {
|
137
|
+
typeforce(types.UInt32, versionGroupId);
|
138
|
+
this.setPropertyCheckSignatures('versionGroupId', versionGroupId);
|
139
|
+
}
|
140
|
+
setExpiryHeight(expiryHeight) {
|
141
|
+
typeforce(types.UInt32, expiryHeight);
|
142
|
+
this.setPropertyCheckSignatures('expiryHeight', expiryHeight);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
exports.ZcashPsbt = ZcashPsbt;
|
146
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiWmNhc2hQc2J0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4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B9XG59XG4iXX0=
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { networks } from '../../networks';
|
3
|
+
import { UtxoTransaction } from '../UtxoTransaction';
|
4
|
+
export declare type ZcashNetwork = typeof networks.zcash | typeof networks.zcashTest;
|
5
|
+
export declare class UnsupportedTransactionError extends Error {
|
6
|
+
constructor(message: string);
|
7
|
+
}
|
8
|
+
export declare function getDefaultVersionGroupIdForVersion(version: number): number;
|
9
|
+
export declare function getDefaultConsensusBranchIdForVersion(network: ZcashNetwork, version: number): number;
|
10
|
+
export declare class ZcashTransaction<TNumber extends number | bigint = number> extends UtxoTransaction<TNumber> {
|
11
|
+
network: ZcashNetwork;
|
12
|
+
static VERSION_JOINSPLITS_SUPPORT: number;
|
13
|
+
static VERSION_OVERWINTER: number;
|
14
|
+
static VERSION_SAPLING: number;
|
15
|
+
static VERSION4_BRANCH_CANOPY: number;
|
16
|
+
static VERSION4_BRANCH_NU5: number;
|
17
|
+
static VERSION5_BRANCH_NU5: number;
|
18
|
+
overwintered: number;
|
19
|
+
versionGroupId: number;
|
20
|
+
expiryHeight: number;
|
21
|
+
consensusBranchId: number;
|
22
|
+
constructor(network: ZcashNetwork, tx?: ZcashTransaction<bigint | number>, amountType?: 'bigint' | 'number');
|
23
|
+
static fromBuffer<TNumber extends number | bigint = number>(buffer: Buffer, __noStrict: boolean, amountType?: 'number' | 'bigint', network?: ZcashNetwork): ZcashTransaction<TNumber>;
|
24
|
+
static fromBufferWithVersion<TNumber extends number | bigint>(buf: Buffer, network: ZcashNetwork, version?: number, amountType?: 'number' | 'bigint'): ZcashTransaction<TNumber>;
|
25
|
+
byteLength(): number;
|
26
|
+
isSaplingCompatible(): boolean;
|
27
|
+
isOverwinterCompatible(): boolean;
|
28
|
+
supportsJoinSplits(): boolean;
|
29
|
+
/**
|
30
|
+
* Build a hash for all or none of the transaction inputs depending on the hashtype
|
31
|
+
* @param hashType
|
32
|
+
* @returns Buffer - BLAKE2b hash or 256-bit zero if doesn't apply
|
33
|
+
*/
|
34
|
+
getPrevoutHash(hashType: number): Buffer;
|
35
|
+
/**
|
36
|
+
* Build a hash for all or none of the transactions inputs sequence numbers depending on the hashtype
|
37
|
+
* @param hashType
|
38
|
+
* @returns Buffer BLAKE2b hash or 256-bit zero if doesn't apply
|
39
|
+
*/
|
40
|
+
getSequenceHash(hashType: number): Buffer;
|
41
|
+
/**
|
42
|
+
* Build a hash for one, all or none of the transaction outputs depending on the hashtype
|
43
|
+
* @param hashType
|
44
|
+
* @param inIndex
|
45
|
+
* @returns Buffer BLAKE2b hash or 256-bit zero if doesn't apply
|
46
|
+
*/
|
47
|
+
getOutputsHash(hashType: number, inIndex: number): Buffer;
|
48
|
+
/**
|
49
|
+
* Hash transaction for signing a transparent transaction in Zcash. Protected transactions are not supported.
|
50
|
+
* @param inIndex
|
51
|
+
* @param prevOutScript
|
52
|
+
* @param value
|
53
|
+
* @param hashType
|
54
|
+
* @returns Buffer BLAKE2b hash
|
55
|
+
*/
|
56
|
+
hashForSignatureByNetwork(inIndex: number | undefined, prevOutScript: Buffer, value: bigint | number | undefined, hashType: number): Buffer;
|
57
|
+
toBuffer(buffer?: Buffer, initialOffset?: number): Buffer;
|
58
|
+
getHash(forWitness?: boolean): Buffer;
|
59
|
+
clone<TN2 extends number | bigint = TNumber>(amountType?: 'bigint' | 'number'): ZcashTransaction<TN2>;
|
60
|
+
}
|
61
|
+
//# sourceMappingURL=ZcashTransaction.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ZcashTransaction.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/zcash/ZcashTransaction.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAgB,MAAM,oBAAoB,CAAC;AAMnE,oBAAY,YAAY,GAAG,OAAO,QAAQ,CAAC,KAAK,GAAG,OAAO,QAAQ,CAAC,SAAS,CAA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AAI,MAAM;IA8BpB,mBAAmB,IAAI,OAAO;IAI9B,sBAAsB,IAAI,OAAO;IAIjC,kBAAkB,IAAI,OAAO;IAI7B;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAcxC;;;;OAIG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAiBzC;;;;;OAKG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IA4BzD;;;;;;;OAOG;IACH,yBAAyB,CACvB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,GACf,MAAM;IAsFT,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,SAAI,GAAG,MAAM;IAyBpD,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM;IAUrC,KAAK,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC;CAGtG"}
|
@@ -0,0 +1,341 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ZcashTransaction = exports.getDefaultConsensusBranchIdForVersion = exports.getDefaultVersionGroupIdForVersion = exports.UnsupportedTransactionError = void 0;
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
5
|
+
const types = require("bitcoinjs-lib/src/types");
|
6
|
+
const bufferutils_1 = require("bitcoinjs-lib/src/bufferutils");
|
7
|
+
const varuint = require('varuint-bitcoin');
|
8
|
+
const typeforce = require('typeforce');
|
9
|
+
const UtxoTransaction_1 = require("../UtxoTransaction");
|
10
|
+
const ZcashBufferutils_1 = require("./ZcashBufferutils");
|
11
|
+
const hashZip0244_1 = require("./hashZip0244");
|
12
|
+
const ZERO = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
|
13
|
+
// https://github.com/zcash/zcash/blob/v4.7.0/src/primitives/transaction.h#L40
|
14
|
+
const SAPLING_VERSION_GROUP_ID = 0x892f2085;
|
15
|
+
// https://github.com/zcash/zcash/blob/v4.7.0/src/primitives/transaction.h#L52
|
16
|
+
const ZIP225_VERSION_GROUP_ID = 0x26a7270a;
|
17
|
+
// https://github.com/zcash/zcash/blob/v4.7.0/src/consensus/upgrades.cpp#L11
|
18
|
+
const OVERWINTER_BRANCH_ID = 0x5ba81b19;
|
19
|
+
const CANOPY_BRANCH_ID = 0xe9ff75a6;
|
20
|
+
const NU5_BRANCH_ID = 0xc2d6d0b4;
|
21
|
+
class UnsupportedTransactionError extends Error {
|
22
|
+
constructor(message) {
|
23
|
+
super(message);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
exports.UnsupportedTransactionError = UnsupportedTransactionError;
|
27
|
+
function getDefaultVersionGroupIdForVersion(version) {
|
28
|
+
switch (version) {
|
29
|
+
case 400:
|
30
|
+
case 450:
|
31
|
+
return SAPLING_VERSION_GROUP_ID;
|
32
|
+
case 500:
|
33
|
+
return ZIP225_VERSION_GROUP_ID;
|
34
|
+
}
|
35
|
+
throw new Error(`no value for version ${version}`);
|
36
|
+
}
|
37
|
+
exports.getDefaultVersionGroupIdForVersion = getDefaultVersionGroupIdForVersion;
|
38
|
+
function getDefaultConsensusBranchIdForVersion(network, version) {
|
39
|
+
switch (version) {
|
40
|
+
case 1:
|
41
|
+
case 2:
|
42
|
+
return 0;
|
43
|
+
case 3:
|
44
|
+
return OVERWINTER_BRANCH_ID;
|
45
|
+
case ZcashTransaction.VERSION4_BRANCH_CANOPY:
|
46
|
+
// https://zips.z.cash/zip-0251
|
47
|
+
return CANOPY_BRANCH_ID;
|
48
|
+
case 4:
|
49
|
+
case 5:
|
50
|
+
case ZcashTransaction.VERSION4_BRANCH_NU5:
|
51
|
+
case ZcashTransaction.VERSION5_BRANCH_NU5:
|
52
|
+
// https://zips.z.cash/zip-0252
|
53
|
+
return NU5_BRANCH_ID;
|
54
|
+
}
|
55
|
+
throw new Error(`no value for version ${version}`);
|
56
|
+
}
|
57
|
+
exports.getDefaultConsensusBranchIdForVersion = getDefaultConsensusBranchIdForVersion;
|
58
|
+
class ZcashTransaction extends UtxoTransaction_1.UtxoTransaction {
|
59
|
+
constructor(network, tx, amountType) {
|
60
|
+
super(network, tx, amountType);
|
61
|
+
this.network = network;
|
62
|
+
// 1 if the transaction is post overwinter upgrade, 0 otherwise
|
63
|
+
this.overwintered = 0;
|
64
|
+
// 0x03C48270 (63210096) for overwinter and 0x892F2085 (2301567109) for sapling
|
65
|
+
this.versionGroupId = 0;
|
66
|
+
// Block height after which this transactions will expire, or 0 to disable expiry
|
67
|
+
this.expiryHeight = 0;
|
68
|
+
let consensusBranchId;
|
69
|
+
if (tx) {
|
70
|
+
this.overwintered = tx.overwintered;
|
71
|
+
this.versionGroupId = tx.versionGroupId;
|
72
|
+
this.expiryHeight = tx.expiryHeight;
|
73
|
+
if (tx.consensusBranchId !== undefined) {
|
74
|
+
consensusBranchId = tx.consensusBranchId;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
this.consensusBranchId = consensusBranchId !== null && consensusBranchId !== void 0 ? consensusBranchId : getDefaultConsensusBranchIdForVersion(network, this.version);
|
78
|
+
}
|
79
|
+
static fromBuffer(buffer, __noStrict, amountType = 'number', network) {
|
80
|
+
/* istanbul ignore next */
|
81
|
+
if (!network) {
|
82
|
+
throw new Error(`must provide network`);
|
83
|
+
}
|
84
|
+
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
85
|
+
const tx = new ZcashTransaction(network);
|
86
|
+
tx.version = bufferReader.readInt32();
|
87
|
+
// Split the header into fOverwintered and nVersion
|
88
|
+
// https://github.com/zcash/zcash/blob/v4.5.1/src/primitives/transaction.h#L772
|
89
|
+
tx.overwintered = tx.version >>> 31; // Must be 1 for version 3 and up
|
90
|
+
tx.version = tx.version & 0x07fffffff; // 3 for overwinter
|
91
|
+
tx.consensusBranchId = getDefaultConsensusBranchIdForVersion(network, tx.version);
|
92
|
+
if (tx.isOverwinterCompatible()) {
|
93
|
+
tx.versionGroupId = bufferReader.readUInt32();
|
94
|
+
}
|
95
|
+
if (tx.version === 5) {
|
96
|
+
ZcashBufferutils_1.fromBufferV5(bufferReader, tx, amountType);
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
ZcashBufferutils_1.fromBufferV4(bufferReader, tx, amountType);
|
100
|
+
}
|
101
|
+
if (__noStrict)
|
102
|
+
return tx;
|
103
|
+
if (bufferReader.offset !== buffer.length) {
|
104
|
+
const trailing = buffer.slice(bufferReader.offset);
|
105
|
+
throw new Error(`Unexpected trailing bytes: ${trailing.toString('hex')}`);
|
106
|
+
}
|
107
|
+
return tx;
|
108
|
+
}
|
109
|
+
static fromBufferWithVersion(buf, network, version, amountType = 'number') {
|
110
|
+
const tx = ZcashTransaction.fromBuffer(buf, false, amountType, network);
|
111
|
+
if (version) {
|
112
|
+
tx.consensusBranchId = getDefaultConsensusBranchIdForVersion(network, version);
|
113
|
+
}
|
114
|
+
return tx;
|
115
|
+
}
|
116
|
+
byteLength() {
|
117
|
+
let byteLength = super.byteLength();
|
118
|
+
if (this.isOverwinterCompatible()) {
|
119
|
+
byteLength += 4; // nVersionGroupId
|
120
|
+
}
|
121
|
+
if (this.isOverwinterCompatible()) {
|
122
|
+
byteLength += 4; // nExpiryHeight
|
123
|
+
}
|
124
|
+
const emptyVectorLength = varuint.encodingLength(0);
|
125
|
+
if (this.version === 5) {
|
126
|
+
// https://github.com/zcash/zcash/blob/v4.5.1/src/primitives/transaction.h#L822
|
127
|
+
byteLength += 4; // consensusBranchId
|
128
|
+
byteLength += emptyVectorLength; // saplingBundle inputs
|
129
|
+
byteLength += emptyVectorLength; // saplingBundle outputs
|
130
|
+
byteLength += 1; // orchardBundle (empty)
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
if (this.isSaplingCompatible()) {
|
134
|
+
// https://github.com/zcash/zcash/blob/v4.5.1/src/primitives/transaction.h#L862
|
135
|
+
byteLength += 8; // valueBalance (uint64)
|
136
|
+
byteLength += emptyVectorLength; // inputs
|
137
|
+
byteLength += emptyVectorLength; // outputs
|
138
|
+
}
|
139
|
+
if (this.supportsJoinSplits()) {
|
140
|
+
//
|
141
|
+
byteLength += emptyVectorLength; // joinsplits
|
142
|
+
}
|
143
|
+
}
|
144
|
+
return byteLength;
|
145
|
+
}
|
146
|
+
isSaplingCompatible() {
|
147
|
+
return !!this.overwintered && this.version >= ZcashTransaction.VERSION_SAPLING;
|
148
|
+
}
|
149
|
+
isOverwinterCompatible() {
|
150
|
+
return !!this.overwintered && this.version >= ZcashTransaction.VERSION_OVERWINTER;
|
151
|
+
}
|
152
|
+
supportsJoinSplits() {
|
153
|
+
return !!this.overwintered && this.version >= ZcashTransaction.VERSION_JOINSPLITS_SUPPORT;
|
154
|
+
}
|
155
|
+
/**
|
156
|
+
* Build a hash for all or none of the transaction inputs depending on the hashtype
|
157
|
+
* @param hashType
|
158
|
+
* @returns Buffer - BLAKE2b hash or 256-bit zero if doesn't apply
|
159
|
+
*/
|
160
|
+
getPrevoutHash(hashType) {
|
161
|
+
if (!(hashType & bitcoinjs_lib_1.Transaction.SIGHASH_ANYONECANPAY)) {
|
162
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(36 * this.ins.length));
|
163
|
+
this.ins.forEach(function (txIn) {
|
164
|
+
bufferWriter.writeSlice(txIn.hash);
|
165
|
+
bufferWriter.writeUInt32(txIn.index);
|
166
|
+
});
|
167
|
+
return hashZip0244_1.getBlake2bHash(bufferWriter.buffer, 'ZcashPrevoutHash');
|
168
|
+
}
|
169
|
+
return ZERO;
|
170
|
+
}
|
171
|
+
/**
|
172
|
+
* Build a hash for all or none of the transactions inputs sequence numbers depending on the hashtype
|
173
|
+
* @param hashType
|
174
|
+
* @returns Buffer BLAKE2b hash or 256-bit zero if doesn't apply
|
175
|
+
*/
|
176
|
+
getSequenceHash(hashType) {
|
177
|
+
if (!(hashType & bitcoinjs_lib_1.Transaction.SIGHASH_ANYONECANPAY) &&
|
178
|
+
(hashType & 0x1f) !== bitcoinjs_lib_1.Transaction.SIGHASH_SINGLE &&
|
179
|
+
(hashType & 0x1f) !== bitcoinjs_lib_1.Transaction.SIGHASH_NONE) {
|
180
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(4 * this.ins.length));
|
181
|
+
this.ins.forEach(function (txIn) {
|
182
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
183
|
+
});
|
184
|
+
return hashZip0244_1.getBlake2bHash(bufferWriter.buffer, 'ZcashSequencHash');
|
185
|
+
}
|
186
|
+
return ZERO;
|
187
|
+
}
|
188
|
+
/**
|
189
|
+
* Build a hash for one, all or none of the transaction outputs depending on the hashtype
|
190
|
+
* @param hashType
|
191
|
+
* @param inIndex
|
192
|
+
* @returns Buffer BLAKE2b hash or 256-bit zero if doesn't apply
|
193
|
+
*/
|
194
|
+
getOutputsHash(hashType, inIndex) {
|
195
|
+
if ((hashType & 0x1f) !== bitcoinjs_lib_1.Transaction.SIGHASH_SINGLE && (hashType & 0x1f) !== bitcoinjs_lib_1.Transaction.SIGHASH_NONE) {
|
196
|
+
// Find out the size of the outputs and write them
|
197
|
+
const txOutsSize = this.outs.reduce(function (sum, output) {
|
198
|
+
return sum + 8 + UtxoTransaction_1.varSliceSize(output.script);
|
199
|
+
}, 0);
|
200
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(txOutsSize));
|
201
|
+
this.outs.forEach(function (out) {
|
202
|
+
bufferWriter.writeUInt64(out.value);
|
203
|
+
bufferWriter.writeVarSlice(out.script);
|
204
|
+
});
|
205
|
+
return hashZip0244_1.getBlake2bHash(bufferWriter.buffer, 'ZcashOutputsHash');
|
206
|
+
}
|
207
|
+
else if ((hashType & 0x1f) === bitcoinjs_lib_1.Transaction.SIGHASH_SINGLE && inIndex < this.outs.length) {
|
208
|
+
// Write only the output specified in inIndex
|
209
|
+
const output = this.outs[inIndex];
|
210
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(8 + UtxoTransaction_1.varSliceSize(output.script)));
|
211
|
+
bufferWriter.writeUInt64(output.value);
|
212
|
+
bufferWriter.writeVarSlice(output.script);
|
213
|
+
return hashZip0244_1.getBlake2bHash(bufferWriter.buffer, 'ZcashOutputsHash');
|
214
|
+
}
|
215
|
+
return ZERO;
|
216
|
+
}
|
217
|
+
/**
|
218
|
+
* Hash transaction for signing a transparent transaction in Zcash. Protected transactions are not supported.
|
219
|
+
* @param inIndex
|
220
|
+
* @param prevOutScript
|
221
|
+
* @param value
|
222
|
+
* @param hashType
|
223
|
+
* @returns Buffer BLAKE2b hash
|
224
|
+
*/
|
225
|
+
hashForSignatureByNetwork(inIndex, prevOutScript, value, hashType) {
|
226
|
+
if (value === undefined) {
|
227
|
+
throw new Error(`must provide value`);
|
228
|
+
}
|
229
|
+
// https://github.com/zcash/zcash/blob/v4.5.1/src/script/interpreter.cpp#L1175
|
230
|
+
if (this.version === 5) {
|
231
|
+
return hashZip0244_1.getSignatureDigest(this, inIndex, prevOutScript, value, hashType);
|
232
|
+
}
|
233
|
+
// ZCash amounts are always within Number.MAX_SAFE_INTEGER
|
234
|
+
value = typeof value === 'bigint' ? Number(value) : value;
|
235
|
+
typeforce(types.tuple(types.UInt32, types.Buffer, types.Number), [inIndex, prevOutScript, value]);
|
236
|
+
if (inIndex === undefined) {
|
237
|
+
throw new Error(`invalid inIndex`);
|
238
|
+
}
|
239
|
+
/* istanbul ignore next */
|
240
|
+
if (inIndex >= this.ins.length) {
|
241
|
+
throw new Error('Input index is out of range');
|
242
|
+
}
|
243
|
+
/* istanbul ignore next */
|
244
|
+
if (!this.isOverwinterCompatible()) {
|
245
|
+
throw new Error(`unsupported version ${this.version}`);
|
246
|
+
}
|
247
|
+
const hashPrevouts = this.getPrevoutHash(hashType);
|
248
|
+
const hashSequence = this.getSequenceHash(hashType);
|
249
|
+
const hashOutputs = this.getOutputsHash(hashType, inIndex);
|
250
|
+
const hashJoinSplits = ZERO;
|
251
|
+
const hashShieldedSpends = ZERO;
|
252
|
+
const hashShieldedOutputs = ZERO;
|
253
|
+
let baseBufferSize = 0;
|
254
|
+
baseBufferSize += 4 * 5; // header, nVersionGroupId, lock_time, nExpiryHeight, hashType
|
255
|
+
baseBufferSize += 32 * 4; // 256 hashes: hashPrevouts, hashSequence, hashOutputs, hashJoinSplits
|
256
|
+
baseBufferSize += 4 * 2; // input.index, input.sequence
|
257
|
+
baseBufferSize += 8; // value
|
258
|
+
baseBufferSize += 32; // input.hash
|
259
|
+
baseBufferSize += UtxoTransaction_1.varSliceSize(prevOutScript); // prevOutScript
|
260
|
+
if (this.isSaplingCompatible()) {
|
261
|
+
baseBufferSize += 32 * 2; // hashShieldedSpends and hashShieldedOutputs
|
262
|
+
baseBufferSize += 8; // valueBalance
|
263
|
+
}
|
264
|
+
const mask = this.overwintered ? 1 : 0;
|
265
|
+
const header = this.version | (mask << 31);
|
266
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.alloc(baseBufferSize));
|
267
|
+
bufferWriter.writeInt32(header);
|
268
|
+
bufferWriter.writeUInt32(this.versionGroupId);
|
269
|
+
bufferWriter.writeSlice(hashPrevouts);
|
270
|
+
bufferWriter.writeSlice(hashSequence);
|
271
|
+
bufferWriter.writeSlice(hashOutputs);
|
272
|
+
bufferWriter.writeSlice(hashJoinSplits);
|
273
|
+
if (this.isSaplingCompatible()) {
|
274
|
+
bufferWriter.writeSlice(hashShieldedSpends);
|
275
|
+
bufferWriter.writeSlice(hashShieldedOutputs);
|
276
|
+
}
|
277
|
+
bufferWriter.writeUInt32(this.locktime);
|
278
|
+
bufferWriter.writeUInt32(this.expiryHeight);
|
279
|
+
if (this.isSaplingCompatible()) {
|
280
|
+
bufferWriter.writeSlice(ZcashBufferutils_1.VALUE_INT64_ZERO);
|
281
|
+
}
|
282
|
+
bufferWriter.writeInt32(hashType);
|
283
|
+
// The input being signed (replacing the scriptSig with scriptCode + amount)
|
284
|
+
// The prevout may already be contained in hashPrevout, and the nSequence
|
285
|
+
// may already be contained in hashSequence.
|
286
|
+
const input = this.ins[inIndex];
|
287
|
+
bufferWriter.writeSlice(input.hash);
|
288
|
+
bufferWriter.writeUInt32(input.index);
|
289
|
+
bufferWriter.writeVarSlice(prevOutScript);
|
290
|
+
bufferWriter.writeUInt64(value);
|
291
|
+
bufferWriter.writeUInt32(input.sequence);
|
292
|
+
const personalization = Buffer.alloc(16);
|
293
|
+
const prefix = 'ZcashSigHash';
|
294
|
+
personalization.write(prefix);
|
295
|
+
personalization.writeUInt32LE(this.consensusBranchId, prefix.length);
|
296
|
+
return hashZip0244_1.getBlake2bHash(bufferWriter.buffer, personalization);
|
297
|
+
}
|
298
|
+
toBuffer(buffer, initialOffset = 0) {
|
299
|
+
if (!buffer)
|
300
|
+
buffer = Buffer.allocUnsafe(this.byteLength());
|
301
|
+
const bufferWriter = new bufferutils_1.BufferWriter(buffer, initialOffset);
|
302
|
+
if (this.isOverwinterCompatible()) {
|
303
|
+
const mask = this.overwintered ? 1 : 0;
|
304
|
+
bufferWriter.writeInt32(this.version | (mask << 31)); // Set overwinter bit
|
305
|
+
bufferWriter.writeUInt32(this.versionGroupId);
|
306
|
+
}
|
307
|
+
else {
|
308
|
+
bufferWriter.writeInt32(this.version);
|
309
|
+
}
|
310
|
+
if (this.version === 5) {
|
311
|
+
ZcashBufferutils_1.toBufferV5(bufferWriter, this);
|
312
|
+
}
|
313
|
+
else {
|
314
|
+
ZcashBufferutils_1.toBufferV4(bufferWriter, this);
|
315
|
+
}
|
316
|
+
if (initialOffset !== undefined) {
|
317
|
+
return buffer.slice(initialOffset, bufferWriter.offset);
|
318
|
+
}
|
319
|
+
return buffer;
|
320
|
+
}
|
321
|
+
getHash(forWitness) {
|
322
|
+
if (forWitness) {
|
323
|
+
throw new Error(`invalid argument`);
|
324
|
+
}
|
325
|
+
if (this.version === 5) {
|
326
|
+
return hashZip0244_1.getTxidDigest(this);
|
327
|
+
}
|
328
|
+
return bitcoinjs_lib_1.crypto.hash256(this.toBuffer());
|
329
|
+
}
|
330
|
+
clone(amountType) {
|
331
|
+
return new ZcashTransaction(this.network, this, amountType);
|
332
|
+
}
|
333
|
+
}
|
334
|
+
exports.ZcashTransaction = ZcashTransaction;
|
335
|
+
ZcashTransaction.VERSION_JOINSPLITS_SUPPORT = 2;
|
336
|
+
ZcashTransaction.VERSION_OVERWINTER = 3;
|
337
|
+
ZcashTransaction.VERSION_SAPLING = 4;
|
338
|
+
ZcashTransaction.VERSION4_BRANCH_CANOPY = 400;
|
339
|
+
ZcashTransaction.VERSION4_BRANCH_NU5 = 450;
|
340
|
+
ZcashTransaction.VERSION5_BRANCH_NU5 = 500;
|
341
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiWmNhc2hUcmFuc2FjdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby96Y2FzaC9aY2FzaFRyYW5zYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGlEQUFvRDtBQUNwRCxpREFBaUQ7QUFDakQsK0RBQTJFO0FBRTNFLE1BQU0sT0FBTyxHQUFHLE9BQU8sQ0FBQyxpQkFBaUIsQ0FBQyxDQUFDO0FBQzNDLE1BQU0sU0FBUyxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztBQUd2Qyx3REFBbUU7QUFDbkUseURBQTBHO0FBQzFHLCtDQUFrRjtBQUVsRixNQUFNLElBQUksR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLGtFQUFrRSxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBSXBHLDhFQUE4RTtBQUM5RSxNQU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