@onetokenfe/coinselect 3.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/accumulative.js +38 -0
- package/blackjack.js +35 -0
- package/break.js +34 -0
- package/index.js +21 -0
- package/package.json +82 -0
- package/split.js +45 -0
- package/third-party/utils/addDashesToSpaces.d.ts +2 -0
- package/third-party/utils/addDashesToSpaces.js +6 -0
- package/third-party/utils/arrayDistinct.d.ts +2 -0
- package/third-party/utils/arrayDistinct.js +6 -0
- package/third-party/utils/arrayPartition.d.ts +7 -0
- package/third-party/utils/arrayPartition.js +6 -0
- package/third-party/utils/arrayShuffle.d.ts +4 -0
- package/third-party/utils/arrayShuffle.js +13 -0
- package/third-party/utils/arrayToDictionary.d.ts +10 -0
- package/third-party/utils/arrayToDictionary.js +27 -0
- package/third-party/utils/asciiUtils.d.ts +3 -0
- package/third-party/utils/asciiUtils.js +16 -0
- package/third-party/utils/bigNumber.d.ts +5 -0
- package/third-party/utils/bigNumber.js +9 -0
- package/third-party/utils/bufferUtils.d.ts +3 -0
- package/third-party/utils/bufferUtils.js +23 -0
- package/third-party/utils/bytesToHumanReadable.d.ts +2 -0
- package/third-party/utils/bytesToHumanReadable.js +15 -0
- package/third-party/utils/capitalizeFirstLetter.d.ts +2 -0
- package/third-party/utils/capitalizeFirstLetter.js +6 -0
- package/third-party/utils/cloneObject.d.ts +2 -0
- package/third-party/utils/cloneObject.js +32 -0
- package/third-party/utils/countBytesInString.d.ts +2 -0
- package/third-party/utils/countBytesInString.js +6 -0
- package/third-party/utils/createCooldown.d.ts +2 -0
- package/third-party/utils/createCooldown.js +16 -0
- package/third-party/utils/createDeferred.d.ts +14 -0
- package/third-party/utils/createDeferred.js +19 -0
- package/third-party/utils/createDeferredManager.d.ts +19 -0
- package/third-party/utils/createDeferredManager.js +67 -0
- package/third-party/utils/createLazy.d.ts +7 -0
- package/third-party/utils/createLazy.js +42 -0
- package/third-party/utils/createTimeoutPromise.d.ts +2 -0
- package/third-party/utils/createTimeoutPromise.js +6 -0
- package/third-party/utils/enumUtils.d.ts +6 -0
- package/third-party/utils/enumUtils.js +12 -0
- package/third-party/utils/extractUrlsFromText.d.ts +5 -0
- package/third-party/utils/extractUrlsFromText.js +28 -0
- package/third-party/utils/getLocaleSeparators.d.ts +5 -0
- package/third-party/utils/getLocaleSeparators.js +13 -0
- package/third-party/utils/getLocaleSeparators.native.d.ts +5 -0
- package/third-party/utils/getLocaleSeparators.native.js +17 -0
- package/third-party/utils/getMutex.d.ts +2 -0
- package/third-party/utils/getMutex.js +22 -0
- package/third-party/utils/getNumberFromPixelString.d.ts +2 -0
- package/third-party/utils/getNumberFromPixelString.js +6 -0
- package/third-party/utils/getRandomInt.d.ts +2 -0
- package/third-party/utils/getRandomInt.js +56 -0
- package/third-party/utils/getSynchronize.d.ts +4 -0
- package/third-party/utils/getSynchronize.js +10 -0
- package/third-party/utils/getWeakRandomId.d.ts +2 -0
- package/third-party/utils/getWeakRandomId.js +13 -0
- package/third-party/utils/getWeakRandomInt.d.ts +2 -0
- package/third-party/utils/getWeakRandomInt.js +11 -0
- package/third-party/utils/getWeakRandomNumberInRange.d.ts +2 -0
- package/third-party/utils/getWeakRandomNumberInRange.js +6 -0
- package/third-party/utils/hasUppercaseLetter.d.ts +2 -0
- package/third-party/utils/hasUppercaseLetter.js +7 -0
- package/third-party/utils/index.d.ts +52 -0
- package/third-party/utils/index.js +56 -0
- package/third-party/utils/isArrayMember.d.ts +2 -0
- package/third-party/utils/isArrayMember.js +6 -0
- package/third-party/utils/isFullPath.d.ts +2 -0
- package/third-party/utils/isFullPath.js +9 -0
- package/third-party/utils/isHex.d.ts +2 -0
- package/third-party/utils/isHex.js +9 -0
- package/third-party/utils/isNotUndefined.d.ts +2 -0
- package/third-party/utils/isNotUndefined.js +6 -0
- package/third-party/utils/isUrl.d.ts +2 -0
- package/third-party/utils/isUrl.js +7 -0
- package/third-party/utils/logs.d.ts +32 -0
- package/third-party/utils/logs.js +82 -0
- package/third-party/utils/logsManager.d.ts +17 -0
- package/third-party/utils/logsManager.js +53 -0
- package/third-party/utils/mergeDeepObject.d.ts +26 -0
- package/third-party/utils/mergeDeepObject.js +68 -0
- package/third-party/utils/objectPartition.d.ts +6 -0
- package/third-party/utils/objectPartition.js +12 -0
- package/third-party/utils/parseElectrumUrl.d.ts +6 -0
- package/third-party/utils/parseElectrumUrl.js +17 -0
- package/third-party/utils/parseHostname.d.ts +2 -0
- package/third-party/utils/parseHostname.js +7 -0
- package/third-party/utils/promiseAllSequence.d.ts +2 -0
- package/third-party/utils/promiseAllSequence.js +14 -0
- package/third-party/utils/redactUserPath.d.ts +3 -0
- package/third-party/utils/redactUserPath.js +7 -0
- package/third-party/utils/scheduleAction.d.ts +15 -0
- package/third-party/utils/scheduleAction.js +125 -0
- package/third-party/utils/splitStringEveryNCharacters.d.ts +2 -0
- package/third-party/utils/splitStringEveryNCharacters.js +12 -0
- package/third-party/utils/throttler.d.ts +11 -0
- package/third-party/utils/throttler.js +38 -0
- package/third-party/utils/throwError.d.ts +2 -0
- package/third-party/utils/throwError.js +8 -0
- package/third-party/utils/topologicalSort.d.ts +2 -0
- package/third-party/utils/topologicalSort.js +19 -0
- package/third-party/utils/truncateMiddle.d.ts +2 -0
- package/third-party/utils/truncateMiddle.js +12 -0
- package/third-party/utils/typedEventEmitter.d.ts +23 -0
- package/third-party/utils/typedEventEmitter.js +11 -0
- package/third-party/utils/urlToOnion.d.ts +4 -0
- package/third-party/utils/urlToOnion.js +12 -0
- package/third-party/utils/versionUtils.d.ts +9 -0
- package/third-party/utils/versionUtils.js +28 -0
- package/third-party/utils/xssFilters.d.ts +4 -0
- package/third-party/utils/xssFilters.js +13 -0
- package/third-party/utxo-lib/address.d.ts +17 -0
- package/third-party/utxo-lib/address.js +174 -0
- package/third-party/utxo-lib/bip32.d.ts +28 -0
- package/third-party/utxo-lib/bip32.js +253 -0
- package/third-party/utxo-lib/bs58check.d.ts +12 -0
- package/third-party/utxo-lib/bs58check.js +92 -0
- package/third-party/utxo-lib/bufferutils.d.ts +59 -0
- package/third-party/utxo-lib/bufferutils.js +219 -0
- package/third-party/utxo-lib/coinselect/coinselectUtils.d.ts +53 -0
- package/third-party/utxo-lib/coinselect/coinselectUtils.js +232 -0
- package/third-party/utxo-lib/coinselect/index.d.ts +3 -0
- package/third-party/utxo-lib/coinselect/index.js +19 -0
- package/third-party/utxo-lib/coinselect/inputs/accumulative.d.ts +3 -0
- package/third-party/utxo-lib/coinselect/inputs/accumulative.js +55 -0
- package/third-party/utxo-lib/coinselect/inputs/branchAndBound.d.ts +3 -0
- package/third-party/utxo-lib/coinselect/inputs/branchAndBound.js +123 -0
- package/third-party/utxo-lib/coinselect/outputs/split.d.ts +3 -0
- package/third-party/utxo-lib/coinselect/outputs/split.js +35 -0
- package/third-party/utxo-lib/coinselect/tryconfirmed.d.ts +3 -0
- package/third-party/utxo-lib/coinselect/tryconfirmed.js +65 -0
- package/third-party/utxo-lib/compose/index.d.ts +3 -0
- package/third-party/utxo-lib/compose/index.js +20 -0
- package/third-party/utxo-lib/compose/request.d.ts +5 -0
- package/third-party/utxo-lib/compose/request.js +168 -0
- package/third-party/utxo-lib/compose/result.d.ts +4 -0
- package/third-party/utxo-lib/compose/result.js +64 -0
- package/third-party/utxo-lib/compose/sorting/bip69SortingStrategy.d.ts +3 -0
- package/third-party/utxo-lib/compose/sorting/bip69SortingStrategy.js +32 -0
- package/third-party/utxo-lib/compose/sorting/convertOutput.d.ts +13 -0
- package/third-party/utxo-lib/compose/sorting/convertOutput.js +14 -0
- package/third-party/utxo-lib/compose/sorting/noneSortingStrategy.d.ts +3 -0
- package/third-party/utxo-lib/compose/sorting/noneSortingStrategy.js +19 -0
- package/third-party/utxo-lib/compose/sorting/randomSortingStrategy.d.ts +3 -0
- package/third-party/utxo-lib/compose/sorting/randomSortingStrategy.js +28 -0
- package/third-party/utxo-lib/compose/sorting/sortingStrategy.d.ts +9 -0
- package/third-party/utxo-lib/compose/sorting/sortingStrategy.js +3 -0
- package/third-party/utxo-lib/compose/transaction.d.ts +3 -0
- package/third-party/utxo-lib/compose/transaction.js +16 -0
- package/third-party/utxo-lib/crypto.d.ts +9 -0
- package/third-party/utxo-lib/crypto.js +44 -0
- package/third-party/utxo-lib/derivation.d.ts +24 -0
- package/third-party/utxo-lib/derivation.js +121 -0
- package/third-party/utxo-lib/discovery.d.ts +9 -0
- package/third-party/utxo-lib/discovery.js +30 -0
- package/third-party/utxo-lib/global.d.ts +62 -0
- package/third-party/utxo-lib/global.js +2 -0
- package/third-party/utxo-lib/index.d.ts +18 -0
- package/third-party/utxo-lib/index.js +28 -0
- package/third-party/utxo-lib/networks.d.ts +45 -0
- package/third-party/utxo-lib/networks.js +250 -0
- package/third-party/utxo-lib/payments/embed.d.ts +3 -0
- package/third-party/utxo-lib/payments/embed.js +49 -0
- package/third-party/utxo-lib/payments/index.d.ts +13 -0
- package/third-party/utxo-lib/payments/index.js +28 -0
- package/third-party/utxo-lib/payments/lazy.d.ts +3 -0
- package/third-party/utxo-lib/payments/lazy.js +33 -0
- package/third-party/utxo-lib/payments/p2ms.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2ms.js +139 -0
- package/third-party/utxo-lib/payments/p2pk.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2pk.js +72 -0
- package/third-party/utxo-lib/payments/p2pkh.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2pkh.js +132 -0
- package/third-party/utxo-lib/payments/p2sh.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2sh.js +171 -0
- package/third-party/utxo-lib/payments/p2tr.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2tr.js +123 -0
- package/third-party/utxo-lib/payments/p2wpkh.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2wpkh.js +137 -0
- package/third-party/utxo-lib/payments/p2wsh.d.ts +3 -0
- package/third-party/utxo-lib/payments/p2wsh.js +183 -0
- package/third-party/utxo-lib/payments/sstxchange.d.ts +3 -0
- package/third-party/utxo-lib/payments/sstxchange.js +79 -0
- package/third-party/utxo-lib/payments/sstxcommitment.d.ts +3 -0
- package/third-party/utxo-lib/payments/sstxcommitment.js +74 -0
- package/third-party/utxo-lib/payments/sstxpkh.d.ts +3 -0
- package/third-party/utxo-lib/payments/sstxpkh.js +79 -0
- package/third-party/utxo-lib/payments/sstxsh.d.ts +3 -0
- package/third-party/utxo-lib/payments/sstxsh.js +70 -0
- package/third-party/utxo-lib/script/index.d.ts +17 -0
- package/third-party/utxo-lib/script/index.js +167 -0
- package/third-party/utxo-lib/script/ops.d.ts +4 -0
- package/third-party/utxo-lib/script/ops.js +13 -0
- package/third-party/utxo-lib/script/scriptNumber.d.ts +3 -0
- package/third-party/utxo-lib/script/scriptNumber.js +62 -0
- package/third-party/utxo-lib/script/scriptSignature.d.ts +8 -0
- package/third-party/utxo-lib/script/scriptSignature.js +55 -0
- package/third-party/utxo-lib/transaction/base.d.ts +56 -0
- package/third-party/utxo-lib/transaction/base.js +108 -0
- package/third-party/utxo-lib/transaction/bitcoin.d.ts +4 -0
- package/third-party/utxo-lib/transaction/bitcoin.js +109 -0
- package/third-party/utxo-lib/transaction/dash.d.ts +8 -0
- package/third-party/utxo-lib/transaction/dash.js +105 -0
- package/third-party/utxo-lib/transaction/decred.d.ts +4 -0
- package/third-party/utxo-lib/transaction/decred.js +149 -0
- package/third-party/utxo-lib/transaction/index.d.ts +15 -0
- package/third-party/utxo-lib/transaction/index.js +44 -0
- package/third-party/utxo-lib/transaction/peercoin.d.ts +4 -0
- package/third-party/utxo-lib/transaction/peercoin.js +64 -0
- package/third-party/utxo-lib/transaction/zcash.d.ts +66 -0
- package/third-party/utxo-lib/transaction/zcash.js +451 -0
- package/third-party/utxo-lib/types/coinselect.d.ts +61 -0
- package/third-party/utxo-lib/types/coinselect.js +3 -0
- package/third-party/utxo-lib/types/compose.d.ts +98 -0
- package/third-party/utxo-lib/types/compose.js +10 -0
- package/third-party/utxo-lib/types/index.d.ts +5 -0
- package/third-party/utxo-lib/types/index.js +8 -0
- package/third-party/utxo-lib/types/payments.d.ts +30 -0
- package/third-party/utxo-lib/types/payments.js +3 -0
- package/third-party/utxo-lib/types/typeforce.d.ts +8 -0
- package/third-party/utxo-lib/types/typeforce.js +16 -0
- package/third-party/utxo-lib/vsize.d.ts +13 -0
- package/third-party/utxo-lib/vsize.js +50 -0
- package/utils.js +78 -0
- package/witness.d.ts +70 -0
- package/witness.js +30 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromConstructor = fromConstructor;
|
|
4
|
+
exports.fromBuffer = fromBuffer;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const varuint = tslib_1.__importStar(require("varuint-bitcoin"));
|
|
7
|
+
const blakejs_1 = require("blakejs");
|
|
8
|
+
const bufferutils_1 = require("../bufferutils");
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
const crypto_1 = require("../crypto");
|
|
11
|
+
const ZCASH_JOINSPLITS_SUPPORT_VERSION = 2;
|
|
12
|
+
const ZCASH_OVERWINTER_VERSION = 3;
|
|
13
|
+
const ZCASH_SAPLING_VERSION = 4;
|
|
14
|
+
const ZCASH_NU5_VERSION = 5;
|
|
15
|
+
const ZCASH_NUM_JOINSPLITS_INPUTS = 2;
|
|
16
|
+
const ZCASH_NUM_JOINSPLITS_OUTPUTS = 2;
|
|
17
|
+
const ZCASH_NOTECIPHERTEXT_SIZE = 1 + 8 + 32 + 32 + 512 + 16;
|
|
18
|
+
const ZCASH_G1_PREFIX_MASK = 0x02;
|
|
19
|
+
const ZCASH_G2_PREFIX_MASK = 0x0a;
|
|
20
|
+
function byteLength(tx) {
|
|
21
|
+
const overwinterSize = tx.version >= ZCASH_OVERWINTER_VERSION
|
|
22
|
+
? 4 +
|
|
23
|
+
4
|
|
24
|
+
: 0;
|
|
25
|
+
const txSpecific = tx.specific;
|
|
26
|
+
const getJoinSplitsSize = () => {
|
|
27
|
+
if (tx.version < ZCASH_JOINSPLITS_SUPPORT_VERSION || tx.version >= ZCASH_NU5_VERSION)
|
|
28
|
+
return 0;
|
|
29
|
+
const joinSplitsLen = txSpecific.joinsplits.length;
|
|
30
|
+
if (joinSplitsLen < 1)
|
|
31
|
+
return (0, bufferutils_1.varIntSize)(joinSplitsLen);
|
|
32
|
+
return ((0, bufferutils_1.varIntSize)(joinSplitsLen) +
|
|
33
|
+
(tx.version >= ZCASH_SAPLING_VERSION ? 1698 * joinSplitsLen : 1802 * joinSplitsLen) +
|
|
34
|
+
32 +
|
|
35
|
+
64);
|
|
36
|
+
};
|
|
37
|
+
const saplingSize = tx.version === ZCASH_SAPLING_VERSION
|
|
38
|
+
? 8 +
|
|
39
|
+
varuint.encodingLength(txSpecific.vShieldedSpend.length) +
|
|
40
|
+
384 * txSpecific.vShieldedSpend.length +
|
|
41
|
+
varuint.encodingLength(txSpecific.vShieldedOutput.length) +
|
|
42
|
+
948 * txSpecific.vShieldedOutput.length +
|
|
43
|
+
(txSpecific.vShieldedSpend.length + txSpecific.vShieldedOutput.length > 0 ? 64 : 0)
|
|
44
|
+
: 0;
|
|
45
|
+
const NU5size = tx.version >= ZCASH_NU5_VERSION
|
|
46
|
+
? 4 +
|
|
47
|
+
1 +
|
|
48
|
+
1 +
|
|
49
|
+
1
|
|
50
|
+
: 0;
|
|
51
|
+
return (4 +
|
|
52
|
+
varuint.encodingLength(tx.ins.length) +
|
|
53
|
+
varuint.encodingLength(tx.outs.length) +
|
|
54
|
+
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) +
|
|
55
|
+
tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) +
|
|
56
|
+
4 +
|
|
57
|
+
overwinterSize +
|
|
58
|
+
getJoinSplitsSize() +
|
|
59
|
+
saplingSize +
|
|
60
|
+
NU5size);
|
|
61
|
+
}
|
|
62
|
+
function toBuffer(tx, buffer, initialOffset) {
|
|
63
|
+
if (!buffer)
|
|
64
|
+
buffer = Buffer.allocUnsafe(byteLength(tx));
|
|
65
|
+
const bufferWriter = new bufferutils_1.BufferWriter(buffer, initialOffset || 0);
|
|
66
|
+
const txSpecific = tx.specific;
|
|
67
|
+
if (tx.version >= ZCASH_OVERWINTER_VERSION) {
|
|
68
|
+
const mask = txSpecific.overwintered ? 1 : 0;
|
|
69
|
+
bufferWriter.writeInt32(tx.version | (mask << 31));
|
|
70
|
+
bufferWriter.writeUInt32(txSpecific.versionGroupId);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
bufferWriter.writeInt32(tx.version);
|
|
74
|
+
}
|
|
75
|
+
if (tx.version >= ZCASH_NU5_VERSION) {
|
|
76
|
+
bufferWriter.writeUInt32(txSpecific.consensusBranchId);
|
|
77
|
+
bufferWriter.writeUInt32(tx.locktime);
|
|
78
|
+
bufferWriter.writeUInt32(tx.expiry);
|
|
79
|
+
}
|
|
80
|
+
bufferWriter.writeVarInt(tx.ins.length);
|
|
81
|
+
tx.ins.forEach(txIn => {
|
|
82
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
83
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
84
|
+
bufferWriter.writeVarSlice(txIn.script);
|
|
85
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
86
|
+
});
|
|
87
|
+
bufferWriter.writeVarInt(tx.outs.length);
|
|
88
|
+
tx.outs.forEach(txOut => {
|
|
89
|
+
bufferWriter.writeUInt64(txOut.value);
|
|
90
|
+
bufferWriter.writeVarSlice(txOut.script);
|
|
91
|
+
});
|
|
92
|
+
if (tx.version < ZCASH_NU5_VERSION) {
|
|
93
|
+
bufferWriter.writeUInt32(tx.locktime);
|
|
94
|
+
if (tx.version >= ZCASH_OVERWINTER_VERSION) {
|
|
95
|
+
bufferWriter.writeUInt32(tx.expiry);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (tx.version === ZCASH_SAPLING_VERSION) {
|
|
99
|
+
bufferWriter.writeInt64(txSpecific.valueBalance);
|
|
100
|
+
bufferWriter.writeVarInt(txSpecific.vShieldedSpend.length);
|
|
101
|
+
txSpecific.vShieldedSpend.forEach(shieldedSpend => {
|
|
102
|
+
bufferWriter.writeSlice(shieldedSpend.cv);
|
|
103
|
+
bufferWriter.writeSlice(shieldedSpend.anchor);
|
|
104
|
+
bufferWriter.writeSlice(shieldedSpend.nullifier);
|
|
105
|
+
bufferWriter.writeSlice(shieldedSpend.rk);
|
|
106
|
+
bufferWriter.writeSlice(shieldedSpend.zkproof.sA);
|
|
107
|
+
bufferWriter.writeSlice(shieldedSpend.zkproof.sB);
|
|
108
|
+
bufferWriter.writeSlice(shieldedSpend.zkproof.sC);
|
|
109
|
+
bufferWriter.writeSlice(shieldedSpend.spendAuthSig);
|
|
110
|
+
});
|
|
111
|
+
bufferWriter.writeVarInt(txSpecific.vShieldedOutput.length);
|
|
112
|
+
txSpecific.vShieldedOutput.forEach(shieldedOutput => {
|
|
113
|
+
bufferWriter.writeSlice(shieldedOutput.cv);
|
|
114
|
+
bufferWriter.writeSlice(shieldedOutput.cmu);
|
|
115
|
+
bufferWriter.writeSlice(shieldedOutput.ephemeralKey);
|
|
116
|
+
bufferWriter.writeSlice(shieldedOutput.encCiphertext);
|
|
117
|
+
bufferWriter.writeSlice(shieldedOutput.outCiphertext);
|
|
118
|
+
bufferWriter.writeSlice(shieldedOutput.zkproof.sA);
|
|
119
|
+
bufferWriter.writeSlice(shieldedOutput.zkproof.sB);
|
|
120
|
+
bufferWriter.writeSlice(shieldedOutput.zkproof.sC);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function writeCompressedG1(i) {
|
|
124
|
+
bufferWriter.writeUInt8(ZCASH_G1_PREFIX_MASK | i.yLsb);
|
|
125
|
+
bufferWriter.writeSlice(i.x);
|
|
126
|
+
}
|
|
127
|
+
function writeCompressedG2(i) {
|
|
128
|
+
bufferWriter.writeUInt8(ZCASH_G2_PREFIX_MASK | i.yLsb);
|
|
129
|
+
bufferWriter.writeSlice(i.x);
|
|
130
|
+
}
|
|
131
|
+
if (tx.version >= ZCASH_JOINSPLITS_SUPPORT_VERSION && tx.version < ZCASH_NU5_VERSION) {
|
|
132
|
+
bufferWriter.writeVarInt(txSpecific.joinsplits.length);
|
|
133
|
+
txSpecific.joinsplits.forEach(joinsplit => {
|
|
134
|
+
bufferWriter.writeUInt64(joinsplit.vpubOld);
|
|
135
|
+
bufferWriter.writeUInt64(joinsplit.vpubNew);
|
|
136
|
+
bufferWriter.writeSlice(joinsplit.anchor);
|
|
137
|
+
joinsplit.nullifiers.forEach(nullifier => {
|
|
138
|
+
bufferWriter.writeSlice(nullifier);
|
|
139
|
+
});
|
|
140
|
+
joinsplit.commitments.forEach(nullifier => {
|
|
141
|
+
bufferWriter.writeSlice(nullifier);
|
|
142
|
+
});
|
|
143
|
+
bufferWriter.writeSlice(joinsplit.ephemeralKey);
|
|
144
|
+
bufferWriter.writeSlice(joinsplit.randomSeed);
|
|
145
|
+
joinsplit.macs.forEach(nullifier => {
|
|
146
|
+
bufferWriter.writeSlice(nullifier);
|
|
147
|
+
});
|
|
148
|
+
if (joinsplit.zkproof.type === 'sapling') {
|
|
149
|
+
bufferWriter.writeSlice(joinsplit.zkproof.sA);
|
|
150
|
+
bufferWriter.writeSlice(joinsplit.zkproof.sB);
|
|
151
|
+
bufferWriter.writeSlice(joinsplit.zkproof.sC);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
writeCompressedG1(joinsplit.zkproof.gA);
|
|
155
|
+
writeCompressedG1(joinsplit.zkproof.gAPrime);
|
|
156
|
+
writeCompressedG2(joinsplit.zkproof.gB);
|
|
157
|
+
writeCompressedG1(joinsplit.zkproof.gBPrime);
|
|
158
|
+
writeCompressedG1(joinsplit.zkproof.gC);
|
|
159
|
+
writeCompressedG1(joinsplit.zkproof.gCPrime);
|
|
160
|
+
writeCompressedG1(joinsplit.zkproof.gK);
|
|
161
|
+
writeCompressedG1(joinsplit.zkproof.gH);
|
|
162
|
+
}
|
|
163
|
+
joinsplit.ciphertexts.forEach(ciphertext => {
|
|
164
|
+
bufferWriter.writeSlice(ciphertext);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
if (txSpecific.joinsplits.length > 0) {
|
|
168
|
+
bufferWriter.writeSlice(txSpecific.joinsplitPubkey);
|
|
169
|
+
bufferWriter.writeSlice(txSpecific.joinsplitSig);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (tx.version >= ZCASH_SAPLING_VERSION &&
|
|
173
|
+
txSpecific.vShieldedSpend.length + txSpecific.vShieldedOutput.length > 0) {
|
|
174
|
+
bufferWriter.writeSlice(txSpecific.bindingSig);
|
|
175
|
+
}
|
|
176
|
+
if (tx.version === ZCASH_NU5_VERSION) {
|
|
177
|
+
bufferWriter.writeVarInt(0);
|
|
178
|
+
bufferWriter.writeVarInt(0);
|
|
179
|
+
bufferWriter.writeUInt8(0x00);
|
|
180
|
+
}
|
|
181
|
+
if (initialOffset !== undefined)
|
|
182
|
+
return buffer.subarray(initialOffset, bufferWriter.offset);
|
|
183
|
+
return buffer;
|
|
184
|
+
}
|
|
185
|
+
function getExtraData(tx) {
|
|
186
|
+
if (tx.version < ZCASH_JOINSPLITS_SUPPORT_VERSION || tx.version >= ZCASH_NU5_VERSION)
|
|
187
|
+
return;
|
|
188
|
+
const offset = 4 +
|
|
189
|
+
(tx.version >= ZCASH_OVERWINTER_VERSION ? 8 : 0) +
|
|
190
|
+
varuint.encodingLength(tx.ins.length) +
|
|
191
|
+
varuint.encodingLength(tx.outs.length) +
|
|
192
|
+
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) +
|
|
193
|
+
tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) +
|
|
194
|
+
4;
|
|
195
|
+
return tx.toBuffer().subarray(offset);
|
|
196
|
+
}
|
|
197
|
+
function getBlake2bDigestHash(buffer, personalization) {
|
|
198
|
+
const hash = (0, blakejs_1.blake2b)(buffer, undefined, 32, undefined, Buffer.from(personalization));
|
|
199
|
+
return Buffer.from(hash);
|
|
200
|
+
}
|
|
201
|
+
function getHeaderDigest(tx) {
|
|
202
|
+
const mask = tx.specific.overwintered ? 1 : 0;
|
|
203
|
+
const writer = new bufferutils_1.BufferWriter(Buffer.alloc(4 * 5));
|
|
204
|
+
writer.writeInt32(tx.version | (mask << 31));
|
|
205
|
+
writer.writeUInt32(tx.specific.versionGroupId);
|
|
206
|
+
writer.writeUInt32(tx.specific.consensusBranchId);
|
|
207
|
+
writer.writeUInt32(tx.locktime);
|
|
208
|
+
writer.writeUInt32(tx.expiry);
|
|
209
|
+
return getBlake2bDigestHash(writer.buffer, 'ZTxIdHeadersHash');
|
|
210
|
+
}
|
|
211
|
+
function getPrevoutsDigest(ins) {
|
|
212
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(36 * ins.length));
|
|
213
|
+
ins.forEach(txIn => {
|
|
214
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
215
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
216
|
+
});
|
|
217
|
+
return getBlake2bDigestHash(bufferWriter.buffer, 'ZTxIdPrevoutHash');
|
|
218
|
+
}
|
|
219
|
+
function getSequenceDigest(ins) {
|
|
220
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(4 * ins.length));
|
|
221
|
+
ins.forEach(txIn => {
|
|
222
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
223
|
+
});
|
|
224
|
+
return getBlake2bDigestHash(bufferWriter.buffer, 'ZTxIdSequencHash');
|
|
225
|
+
}
|
|
226
|
+
function getOutputsDigest(outs) {
|
|
227
|
+
const txOutsSize = outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0);
|
|
228
|
+
const bufferWriter = new bufferutils_1.BufferWriter(Buffer.allocUnsafe(txOutsSize));
|
|
229
|
+
outs.forEach(out => {
|
|
230
|
+
bufferWriter.writeUInt64(out.value);
|
|
231
|
+
bufferWriter.writeVarSlice(out.script);
|
|
232
|
+
});
|
|
233
|
+
return getBlake2bDigestHash(bufferWriter.buffer, 'ZTxIdOutputsHash');
|
|
234
|
+
}
|
|
235
|
+
function getTransparentDigest(tx) {
|
|
236
|
+
let buffer;
|
|
237
|
+
if (tx.ins.length || tx.outs.length) {
|
|
238
|
+
const writer = new bufferutils_1.BufferWriter(Buffer.alloc(32 * 3));
|
|
239
|
+
writer.writeSlice(getPrevoutsDigest(tx.ins));
|
|
240
|
+
writer.writeSlice(getSequenceDigest(tx.ins));
|
|
241
|
+
writer.writeSlice(getOutputsDigest(tx.outs));
|
|
242
|
+
buffer = writer.buffer;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
buffer = Buffer.of();
|
|
246
|
+
}
|
|
247
|
+
return getBlake2bDigestHash(buffer, 'ZTxIdTranspaHash');
|
|
248
|
+
}
|
|
249
|
+
function getHash(tx, _forWitness = false) {
|
|
250
|
+
if (tx.version < ZCASH_NU5_VERSION) {
|
|
251
|
+
return (0, crypto_1.hash256)(toBuffer(tx));
|
|
252
|
+
}
|
|
253
|
+
const writer = new bufferutils_1.BufferWriter(Buffer.alloc(32 * 4));
|
|
254
|
+
writer.writeSlice(getHeaderDigest(tx));
|
|
255
|
+
writer.writeSlice(getTransparentDigest(tx));
|
|
256
|
+
writer.writeSlice(getBlake2bDigestHash(Buffer.of(), 'ZTxIdSaplingHash'));
|
|
257
|
+
writer.writeSlice(getBlake2bDigestHash(Buffer.of(), 'ZTxIdOrchardHash'));
|
|
258
|
+
const personalizationTag = 'ZcashTxHash_';
|
|
259
|
+
const personalization = new bufferutils_1.BufferWriter(Buffer.alloc(personalizationTag.length + 4));
|
|
260
|
+
personalization.writeSlice(Buffer.from(personalizationTag));
|
|
261
|
+
personalization.writeUInt32(tx.specific.consensusBranchId);
|
|
262
|
+
return getBlake2bDigestHash(writer.buffer, personalization.buffer);
|
|
263
|
+
}
|
|
264
|
+
function fromConstructor(options) {
|
|
265
|
+
const tx = new base_1.TransactionBase(options);
|
|
266
|
+
tx.specific = tx.specific || {
|
|
267
|
+
type: 'zcash',
|
|
268
|
+
joinsplits: [],
|
|
269
|
+
joinsplitPubkey: base_1.EMPTY_SCRIPT,
|
|
270
|
+
joinsplitSig: base_1.EMPTY_SCRIPT,
|
|
271
|
+
overwintered: 0,
|
|
272
|
+
versionGroupId: 0,
|
|
273
|
+
valueBalance: 0,
|
|
274
|
+
vShieldedSpend: [],
|
|
275
|
+
vShieldedOutput: [],
|
|
276
|
+
bindingSig: base_1.EMPTY_SCRIPT,
|
|
277
|
+
consensusBranchId: 0,
|
|
278
|
+
};
|
|
279
|
+
tx.byteLength = byteLength.bind(null, tx);
|
|
280
|
+
tx.toBuffer = toBuffer.bind(null, tx);
|
|
281
|
+
tx.getExtraData = getExtraData.bind(null, tx);
|
|
282
|
+
tx.getHash = getHash.bind(null, tx);
|
|
283
|
+
return tx;
|
|
284
|
+
}
|
|
285
|
+
function fromBuffer(buffer, options) {
|
|
286
|
+
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
|
287
|
+
const tx = fromConstructor(options);
|
|
288
|
+
const txSpecific = tx.specific;
|
|
289
|
+
tx.version = bufferReader.readInt32();
|
|
290
|
+
txSpecific.overwintered = tx.version >>> 31;
|
|
291
|
+
tx.version &= 0x07fffffff;
|
|
292
|
+
if (tx.version >= ZCASH_OVERWINTER_VERSION) {
|
|
293
|
+
txSpecific.versionGroupId = bufferReader.readUInt32();
|
|
294
|
+
}
|
|
295
|
+
if (tx.version >= ZCASH_NU5_VERSION) {
|
|
296
|
+
txSpecific.consensusBranchId = bufferReader.readUInt32();
|
|
297
|
+
tx.locktime = bufferReader.readUInt32();
|
|
298
|
+
tx.expiry = bufferReader.readUInt32();
|
|
299
|
+
}
|
|
300
|
+
const vinLen = bufferReader.readVarInt();
|
|
301
|
+
for (let i = 0; i < vinLen; ++i) {
|
|
302
|
+
tx.ins.push({
|
|
303
|
+
hash: bufferReader.readSlice(32),
|
|
304
|
+
index: bufferReader.readUInt32(),
|
|
305
|
+
script: bufferReader.readVarSlice(),
|
|
306
|
+
sequence: bufferReader.readUInt32(),
|
|
307
|
+
witness: [],
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
const voutLen = bufferReader.readVarInt();
|
|
311
|
+
for (let i = 0; i < voutLen; ++i) {
|
|
312
|
+
tx.outs.push({
|
|
313
|
+
value: bufferReader.readUInt64String(),
|
|
314
|
+
script: bufferReader.readVarSlice(),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (tx.version < ZCASH_NU5_VERSION) {
|
|
318
|
+
tx.locktime = bufferReader.readUInt32();
|
|
319
|
+
tx.expiry = tx.version >= ZCASH_OVERWINTER_VERSION ? bufferReader.readUInt32() : 0;
|
|
320
|
+
}
|
|
321
|
+
function readCompressedG1() {
|
|
322
|
+
const yLsb = bufferReader.readUInt8() & 1;
|
|
323
|
+
const x = bufferReader.readSlice(32);
|
|
324
|
+
return {
|
|
325
|
+
x,
|
|
326
|
+
yLsb,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function readCompressedG2() {
|
|
330
|
+
const yLsb = bufferReader.readUInt8() & 1;
|
|
331
|
+
const x = bufferReader.readSlice(64);
|
|
332
|
+
return {
|
|
333
|
+
x,
|
|
334
|
+
yLsb,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function readSaplingZKProof() {
|
|
338
|
+
return {
|
|
339
|
+
type: 'sapling',
|
|
340
|
+
sA: bufferReader.readSlice(48),
|
|
341
|
+
sB: bufferReader.readSlice(96),
|
|
342
|
+
sC: bufferReader.readSlice(48),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function readZKProof() {
|
|
346
|
+
if (tx.version >= ZCASH_SAPLING_VERSION) {
|
|
347
|
+
return readSaplingZKProof();
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
type: 'joinsplit',
|
|
351
|
+
gA: readCompressedG1(),
|
|
352
|
+
gAPrime: readCompressedG1(),
|
|
353
|
+
gB: readCompressedG2(),
|
|
354
|
+
gBPrime: readCompressedG1(),
|
|
355
|
+
gC: readCompressedG1(),
|
|
356
|
+
gCPrime: readCompressedG1(),
|
|
357
|
+
gK: readCompressedG1(),
|
|
358
|
+
gH: readCompressedG1(),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
if (tx.version === ZCASH_SAPLING_VERSION) {
|
|
362
|
+
txSpecific.valueBalance = bufferReader.readInt64();
|
|
363
|
+
const nShieldedSpend = bufferReader.readVarInt();
|
|
364
|
+
for (let i = 0; i < nShieldedSpend; ++i) {
|
|
365
|
+
txSpecific.vShieldedSpend.push({
|
|
366
|
+
cv: bufferReader.readSlice(32),
|
|
367
|
+
anchor: bufferReader.readSlice(32),
|
|
368
|
+
nullifier: bufferReader.readSlice(32),
|
|
369
|
+
rk: bufferReader.readSlice(32),
|
|
370
|
+
zkproof: readSaplingZKProof(),
|
|
371
|
+
spendAuthSig: bufferReader.readSlice(64),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const nShieldedOutput = bufferReader.readVarInt();
|
|
375
|
+
for (let i = 0; i < nShieldedOutput; ++i) {
|
|
376
|
+
txSpecific.vShieldedOutput.push({
|
|
377
|
+
cv: bufferReader.readSlice(32),
|
|
378
|
+
cmu: bufferReader.readSlice(32),
|
|
379
|
+
ephemeralKey: bufferReader.readSlice(32),
|
|
380
|
+
encCiphertext: bufferReader.readSlice(580),
|
|
381
|
+
outCiphertext: bufferReader.readSlice(80),
|
|
382
|
+
zkproof: readSaplingZKProof(),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (tx.version >= ZCASH_JOINSPLITS_SUPPORT_VERSION && tx.version < ZCASH_NU5_VERSION) {
|
|
387
|
+
const joinSplitsLen = bufferReader.readVarInt();
|
|
388
|
+
for (let i = 0; i < joinSplitsLen; ++i) {
|
|
389
|
+
let j;
|
|
390
|
+
const vpubOld = bufferReader.readUInt64();
|
|
391
|
+
const vpubNew = bufferReader.readUInt64();
|
|
392
|
+
const anchor = bufferReader.readSlice(32);
|
|
393
|
+
const nullifiers = [];
|
|
394
|
+
for (j = 0; j < ZCASH_NUM_JOINSPLITS_INPUTS; j++) {
|
|
395
|
+
nullifiers.push(bufferReader.readSlice(32));
|
|
396
|
+
}
|
|
397
|
+
const commitments = [];
|
|
398
|
+
for (j = 0; j < ZCASH_NUM_JOINSPLITS_OUTPUTS; j++) {
|
|
399
|
+
commitments.push(bufferReader.readSlice(32));
|
|
400
|
+
}
|
|
401
|
+
const ephemeralKey = bufferReader.readSlice(32);
|
|
402
|
+
const randomSeed = bufferReader.readSlice(32);
|
|
403
|
+
const macs = [];
|
|
404
|
+
for (j = 0; j < ZCASH_NUM_JOINSPLITS_INPUTS; j++) {
|
|
405
|
+
macs.push(bufferReader.readSlice(32));
|
|
406
|
+
}
|
|
407
|
+
const zkproof = readZKProof();
|
|
408
|
+
const ciphertexts = [];
|
|
409
|
+
for (j = 0; j < ZCASH_NUM_JOINSPLITS_OUTPUTS; j++) {
|
|
410
|
+
ciphertexts.push(bufferReader.readSlice(ZCASH_NOTECIPHERTEXT_SIZE));
|
|
411
|
+
}
|
|
412
|
+
txSpecific.joinsplits.push({
|
|
413
|
+
vpubOld,
|
|
414
|
+
vpubNew,
|
|
415
|
+
anchor,
|
|
416
|
+
nullifiers,
|
|
417
|
+
commitments,
|
|
418
|
+
ephemeralKey,
|
|
419
|
+
randomSeed,
|
|
420
|
+
macs,
|
|
421
|
+
zkproof,
|
|
422
|
+
ciphertexts,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
if (joinSplitsLen > 0) {
|
|
426
|
+
txSpecific.joinsplitPubkey = bufferReader.readSlice(32);
|
|
427
|
+
txSpecific.joinsplitSig = bufferReader.readSlice(64);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (tx.version >= ZCASH_SAPLING_VERSION &&
|
|
431
|
+
txSpecific.vShieldedSpend.length + txSpecific.vShieldedOutput.length > 0) {
|
|
432
|
+
txSpecific.bindingSig = bufferReader.readSlice(64);
|
|
433
|
+
}
|
|
434
|
+
if (tx.version === ZCASH_NU5_VERSION) {
|
|
435
|
+
if (bufferReader.readVarInt() !== 0) {
|
|
436
|
+
throw Error('Unexpected vSpendsSapling vector');
|
|
437
|
+
}
|
|
438
|
+
if (bufferReader.readVarInt() !== 0) {
|
|
439
|
+
throw Error('Unexpected vOutputsSapling vector');
|
|
440
|
+
}
|
|
441
|
+
if (bufferReader.readUInt8() !== 0x00) {
|
|
442
|
+
throw Error('Unexpected orchard byte');
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (options.nostrict)
|
|
446
|
+
return tx;
|
|
447
|
+
if (bufferReader.offset !== buffer.length)
|
|
448
|
+
throw new Error('Transaction has unexpected data');
|
|
449
|
+
return tx;
|
|
450
|
+
}
|
|
451
|
+
//# sourceMappingURL=zcash.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
import { TransactionInputOutputSortingStrategy } from './compose';
|
|
3
|
+
export type CoinSelectPaymentType = 'p2pkh' | 'p2sh' | 'p2tr' | 'p2wpkh' | 'p2wsh';
|
|
4
|
+
export interface CoinSelectOptions {
|
|
5
|
+
txType: CoinSelectPaymentType;
|
|
6
|
+
changeOutput?: CoinSelectOutput;
|
|
7
|
+
dustThreshold?: number;
|
|
8
|
+
longTermFeeRate?: number;
|
|
9
|
+
own?: number;
|
|
10
|
+
other?: number;
|
|
11
|
+
coinbase?: number;
|
|
12
|
+
baseFee?: number;
|
|
13
|
+
floorBaseFee?: boolean;
|
|
14
|
+
sortingStrategy: TransactionInputOutputSortingStrategy;
|
|
15
|
+
feePolicy?: 'bitcoin' | 'doge' | 'zcash';
|
|
16
|
+
}
|
|
17
|
+
export interface CoinSelectInput {
|
|
18
|
+
type: CoinSelectPaymentType;
|
|
19
|
+
i: number;
|
|
20
|
+
script: {
|
|
21
|
+
length: number;
|
|
22
|
+
};
|
|
23
|
+
value: BN;
|
|
24
|
+
confirmations: number;
|
|
25
|
+
coinbase?: boolean;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
own?: boolean;
|
|
28
|
+
weight?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CoinSelectOutput {
|
|
31
|
+
script: {
|
|
32
|
+
length: number;
|
|
33
|
+
};
|
|
34
|
+
value?: BN;
|
|
35
|
+
weight?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface CoinSelectOutputFinal {
|
|
38
|
+
script: {
|
|
39
|
+
length: number;
|
|
40
|
+
};
|
|
41
|
+
value: BN;
|
|
42
|
+
}
|
|
43
|
+
export interface CoinSelectRequest extends CoinSelectOptions {
|
|
44
|
+
inputs: CoinSelectInput[];
|
|
45
|
+
outputs: CoinSelectOutput[];
|
|
46
|
+
sendMaxOutputIndex: number;
|
|
47
|
+
feeRate: number;
|
|
48
|
+
}
|
|
49
|
+
export type CoinSelectAlgorithm = (inputs: CoinSelectInput[], outputs: CoinSelectOutput[], feeRate: number, options: CoinSelectOptions) => CoinSelectResult;
|
|
50
|
+
export interface CoinSelectSuccess {
|
|
51
|
+
fee: number;
|
|
52
|
+
inputs: CoinSelectInput[];
|
|
53
|
+
outputs: CoinSelectOutputFinal[];
|
|
54
|
+
}
|
|
55
|
+
export interface CoinSelectFailure {
|
|
56
|
+
fee: number;
|
|
57
|
+
inputs?: typeof undefined;
|
|
58
|
+
outputs?: typeof undefined;
|
|
59
|
+
}
|
|
60
|
+
export type CoinSelectResult = CoinSelectSuccess | CoinSelectFailure;
|
|
61
|
+
//# sourceMappingURL=coinselect.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Network } from '../networks';
|
|
2
|
+
import type { CoinSelectPaymentType } from './coinselect';
|
|
3
|
+
export interface ComposeInput {
|
|
4
|
+
vout: number;
|
|
5
|
+
txid: string;
|
|
6
|
+
amount: string;
|
|
7
|
+
coinbase: boolean;
|
|
8
|
+
own: boolean;
|
|
9
|
+
confirmations: number;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ComposeOutputPayment {
|
|
13
|
+
type: 'payment';
|
|
14
|
+
address: string;
|
|
15
|
+
amount: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ComposeOutputPaymentNoAddress {
|
|
18
|
+
type: 'payment-noaddress';
|
|
19
|
+
amount: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ComposeOutputSendMax {
|
|
22
|
+
type: 'send-max';
|
|
23
|
+
address: string;
|
|
24
|
+
amount?: typeof undefined;
|
|
25
|
+
}
|
|
26
|
+
export interface ComposeOutputSendMaxNoAddress {
|
|
27
|
+
type: 'send-max-noaddress';
|
|
28
|
+
amount?: typeof undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface ComposeOutputOpreturn {
|
|
31
|
+
type: 'opreturn';
|
|
32
|
+
dataHex: string;
|
|
33
|
+
amount?: typeof undefined;
|
|
34
|
+
address?: typeof undefined;
|
|
35
|
+
}
|
|
36
|
+
export interface ComposeOutputChange {
|
|
37
|
+
type: 'change';
|
|
38
|
+
amount: string;
|
|
39
|
+
}
|
|
40
|
+
export type ComposeFinalOutput = ComposeOutputPayment | ComposeOutputSendMax | ComposeOutputOpreturn;
|
|
41
|
+
export type ComposeNotFinalOutput = ComposeOutputPaymentNoAddress | ComposeOutputSendMaxNoAddress;
|
|
42
|
+
export type ComposeOutput = ComposeFinalOutput | ComposeNotFinalOutput;
|
|
43
|
+
export interface ComposeChangeAddress {
|
|
44
|
+
address: string;
|
|
45
|
+
}
|
|
46
|
+
export type TransactionInputOutputSortingStrategy = 'bip69' | 'random' | 'none';
|
|
47
|
+
export type ComposeRequest<Input extends ComposeInput, Output extends ComposeOutput, Change extends ComposeChangeAddress> = {
|
|
48
|
+
txType?: CoinSelectPaymentType;
|
|
49
|
+
utxos: Input[];
|
|
50
|
+
outputs: Output[];
|
|
51
|
+
feeRate: string | number;
|
|
52
|
+
longTermFeeRate?: string | number;
|
|
53
|
+
network: Network;
|
|
54
|
+
changeAddress: Change;
|
|
55
|
+
dustThreshold: number;
|
|
56
|
+
baseFee?: number;
|
|
57
|
+
floorBaseFee?: boolean;
|
|
58
|
+
skipUtxoSelection?: boolean;
|
|
59
|
+
sortingStrategy: TransactionInputOutputSortingStrategy;
|
|
60
|
+
};
|
|
61
|
+
type ComposedTransactionOutputs<T> = T extends ComposeOutputSendMax ? Omit<T, 'type'> & ComposeOutputPayment : T extends ComposeFinalOutput ? T : never;
|
|
62
|
+
export interface ComposedTransaction<Input extends ComposeInput, Output extends ComposeOutput, Change extends ComposeChangeAddress> {
|
|
63
|
+
inputs: Input[];
|
|
64
|
+
outputs: (ComposedTransactionOutputs<Output> | (Change & ComposeOutputChange))[];
|
|
65
|
+
outputsPermutation: number[];
|
|
66
|
+
}
|
|
67
|
+
export declare const COMPOSE_ERROR_TYPES: readonly ["MISSING-UTXOS", "MISSING-OUTPUTS", "INCORRECT-FEE-RATE", "NOT-ENOUGH-FUNDS"];
|
|
68
|
+
export type ComposeResultError = {
|
|
69
|
+
type: 'error';
|
|
70
|
+
error: (typeof COMPOSE_ERROR_TYPES)[number];
|
|
71
|
+
} | {
|
|
72
|
+
type: 'error';
|
|
73
|
+
error: 'INCORRECT-UTXO' | 'INCORRECT-OUTPUT' | 'COINSELECT';
|
|
74
|
+
message: string;
|
|
75
|
+
};
|
|
76
|
+
export interface ComposeResultNonFinal<Input extends ComposeInput> {
|
|
77
|
+
type: 'nonfinal';
|
|
78
|
+
max?: string;
|
|
79
|
+
totalSpent: string;
|
|
80
|
+
fee: string;
|
|
81
|
+
feePerByte: string;
|
|
82
|
+
bytes: number;
|
|
83
|
+
inputs: Input[];
|
|
84
|
+
}
|
|
85
|
+
export interface ComposeResultFinal<Input extends ComposeInput, Output extends ComposeOutput, Change extends ComposeChangeAddress> extends ComposedTransaction<Input, Output, Change> {
|
|
86
|
+
type: 'final';
|
|
87
|
+
max?: string;
|
|
88
|
+
totalSpent: string;
|
|
89
|
+
fee: string;
|
|
90
|
+
feePerByte: string;
|
|
91
|
+
bytes: number;
|
|
92
|
+
inputs: Input[];
|
|
93
|
+
outputs: (ComposedTransactionOutputs<Output> | (Change & ComposeOutputChange))[];
|
|
94
|
+
outputsPermutation: number[];
|
|
95
|
+
}
|
|
96
|
+
export type ComposeResult<Input extends ComposeInput, Output extends ComposeOutput, Change extends ComposeChangeAddress> = ComposeResultError | ComposeResultNonFinal<Input> | ComposeResultFinal<Input, Output, Change>;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPOSE_ERROR_TYPES = void 0;
|
|
4
|
+
exports.COMPOSE_ERROR_TYPES = [
|
|
5
|
+
'MISSING-UTXOS',
|
|
6
|
+
'MISSING-OUTPUTS',
|
|
7
|
+
'INCORRECT-FEE-RATE',
|
|
8
|
+
'NOT-ENOUGH-FUNDS',
|
|
9
|
+
];
|
|
10
|
+
//# sourceMappingURL=compose.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./coinselect"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./compose"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./payments"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./typeforce"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Network } from '../networks';
|
|
2
|
+
export type PaymentName = 'p2pk' | 'p2pkh' | 'p2sh' | 'p2tr' | 'p2wpkh' | 'p2wsh' | 'p2ms' | 'embed' | 'sstxchange' | 'sstxcommitment' | 'sstxpkh' | 'sstxsh';
|
|
3
|
+
export interface Payment {
|
|
4
|
+
name?: PaymentName;
|
|
5
|
+
network?: Network;
|
|
6
|
+
output?: Buffer;
|
|
7
|
+
data?: Buffer[];
|
|
8
|
+
m?: number;
|
|
9
|
+
n?: number;
|
|
10
|
+
pubkeys?: Buffer[];
|
|
11
|
+
input?: Buffer;
|
|
12
|
+
signatures?: Buffer[];
|
|
13
|
+
pubkey?: Buffer;
|
|
14
|
+
signature?: Buffer;
|
|
15
|
+
address?: string;
|
|
16
|
+
hash?: Buffer;
|
|
17
|
+
redeem?: Payment;
|
|
18
|
+
witness?: Buffer[];
|
|
19
|
+
amount?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare type PaymentCreator = (a: Payment, opts?: PaymentOpts) => Payment;
|
|
22
|
+
export declare type PaymentFunction = () => Payment;
|
|
23
|
+
export interface PaymentOpts {
|
|
24
|
+
validate?: boolean;
|
|
25
|
+
allowIncomplete?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type StackElement = Buffer | number;
|
|
28
|
+
export type Stack = StackElement[];
|
|
29
|
+
export type StackFunction = () => Stack;
|
|
30
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import typeforce from 'typeforce';
|
|
2
|
+
export declare function Satoshi(value: number): boolean;
|
|
3
|
+
export declare const Buffer256bit: (value: any) => value is Buffer;
|
|
4
|
+
export declare const Hash160bit: (value: any) => value is Buffer;
|
|
5
|
+
export declare const Hash256bit: (value: any) => value is Buffer;
|
|
6
|
+
export declare const Number: (value: any) => value is number, Array: (value: any) => value is any[], Boolean: (value: any) => value is boolean, String: (value: any) => value is string, Buffer: (value: any) => value is Buffer, Hex: (value: any) => value is string, maybe: (type: any) => boolean, tuple: (...args: any[]) => boolean, UInt8: (value: any) => value is number, UInt16: (value: any) => value is number, UInt32: (value: any) => value is number, Function: (value: any) => value is FunctionConstructor, BufferN: (length: number) => (value: any) => value is Buffer, Nil: (value: any) => boolean, anyOf: (...args: any[]) => (value: any) => boolean;
|
|
7
|
+
export { typeforce };
|
|
8
|
+
//# sourceMappingURL=typeforce.d.ts.map
|