@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,105 @@
|
|
|
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 bufferutils_1 = require("../bufferutils");
|
|
8
|
+
const base_1 = require("./base");
|
|
9
|
+
const DASH_NORMAL = 0;
|
|
10
|
+
const DASH_QUORUM_COMMITMENT = 6;
|
|
11
|
+
function byteLength(tx, _ALLOW_WITNESS = true) {
|
|
12
|
+
var _a;
|
|
13
|
+
const hasWitnesses = _ALLOW_WITNESS && tx.hasWitnesses();
|
|
14
|
+
return ((hasWitnesses ? 10 : 8) +
|
|
15
|
+
(tx.timestamp ? 4 : 0) +
|
|
16
|
+
varuint.encodingLength(tx.ins.length) +
|
|
17
|
+
varuint.encodingLength(tx.outs.length) +
|
|
18
|
+
tx.ins.reduce((sum, input) => sum + 40 + (0, base_1.varSliceSize)(input.script), 0) +
|
|
19
|
+
tx.outs.reduce((sum, output) => sum + 8 + (0, base_1.varSliceSize)(output.script), 0) +
|
|
20
|
+
(((_a = tx.specific) === null || _a === void 0 ? void 0 : _a.extraPayload) ? (0, base_1.varSliceSize)(tx.specific.extraPayload) : 0) +
|
|
21
|
+
(hasWitnesses ? tx.ins.reduce((sum, input) => sum + (0, base_1.vectorSize)(input.witness), 0) : 0));
|
|
22
|
+
}
|
|
23
|
+
function toBuffer(tx, buffer, initialOffset, _ALLOW_WITNESS = true) {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!buffer)
|
|
26
|
+
buffer = Buffer.allocUnsafe(tx.byteLength(_ALLOW_WITNESS));
|
|
27
|
+
const bufferWriter = new bufferutils_1.BufferWriter(buffer, initialOffset || 0);
|
|
28
|
+
if (tx.version >= 3 && tx.type !== DASH_NORMAL) {
|
|
29
|
+
bufferWriter.writeUInt16(tx.version);
|
|
30
|
+
bufferWriter.writeUInt16(tx.type);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
bufferWriter.writeInt32(tx.version);
|
|
34
|
+
}
|
|
35
|
+
bufferWriter.writeVarInt(tx.ins.length);
|
|
36
|
+
tx.ins.forEach(txIn => {
|
|
37
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
38
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
39
|
+
bufferWriter.writeVarSlice(txIn.script);
|
|
40
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
41
|
+
});
|
|
42
|
+
bufferWriter.writeVarInt(tx.outs.length);
|
|
43
|
+
tx.outs.forEach(txOut => {
|
|
44
|
+
bufferWriter.writeUInt64(txOut.value);
|
|
45
|
+
bufferWriter.writeVarSlice(txOut.script);
|
|
46
|
+
});
|
|
47
|
+
bufferWriter.writeUInt32(tx.locktime);
|
|
48
|
+
if ((_a = tx.specific) === null || _a === void 0 ? void 0 : _a.extraPayload)
|
|
49
|
+
bufferWriter.writeVarSlice(tx.specific.extraPayload);
|
|
50
|
+
if (initialOffset !== undefined)
|
|
51
|
+
return buffer.subarray(initialOffset, bufferWriter.offset);
|
|
52
|
+
return buffer;
|
|
53
|
+
}
|
|
54
|
+
function getExtraData(tx) {
|
|
55
|
+
var _a;
|
|
56
|
+
if (!((_a = tx.specific) === null || _a === void 0 ? void 0 : _a.extraPayload))
|
|
57
|
+
return;
|
|
58
|
+
const { buffer: extraDataLength } = varuint.encode(tx.specific.extraPayload.length);
|
|
59
|
+
return Buffer.concat([extraDataLength, tx.specific.extraPayload]);
|
|
60
|
+
}
|
|
61
|
+
function fromConstructor(options) {
|
|
62
|
+
const tx = new base_1.TransactionBase(options);
|
|
63
|
+
tx.specific = tx.specific || { type: 'dash' };
|
|
64
|
+
tx.byteLength = byteLength.bind(null, tx);
|
|
65
|
+
tx.toBuffer = toBuffer.bind(null, tx);
|
|
66
|
+
tx.getExtraData = getExtraData.bind(null, tx);
|
|
67
|
+
return tx;
|
|
68
|
+
}
|
|
69
|
+
function fromBuffer(buffer, options) {
|
|
70
|
+
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
|
71
|
+
const tx = fromConstructor(options);
|
|
72
|
+
tx.version = bufferReader.readInt32();
|
|
73
|
+
tx.type = tx.version >> 16;
|
|
74
|
+
tx.version &= 0xffff;
|
|
75
|
+
if (tx.version === 3 && (tx.type < DASH_NORMAL || tx.type > DASH_QUORUM_COMMITMENT)) {
|
|
76
|
+
throw new Error('Unsupported Dash transaction type');
|
|
77
|
+
}
|
|
78
|
+
const vinLen = bufferReader.readVarInt();
|
|
79
|
+
for (let i = 0; i < vinLen; ++i) {
|
|
80
|
+
tx.ins.push({
|
|
81
|
+
hash: bufferReader.readSlice(32),
|
|
82
|
+
index: bufferReader.readUInt32(),
|
|
83
|
+
script: bufferReader.readVarSlice(),
|
|
84
|
+
sequence: bufferReader.readUInt32(),
|
|
85
|
+
witness: [],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const voutLen = bufferReader.readVarInt();
|
|
89
|
+
for (let i = 0; i < voutLen; ++i) {
|
|
90
|
+
tx.outs.push({
|
|
91
|
+
value: bufferReader.readUInt64String(),
|
|
92
|
+
script: bufferReader.readVarSlice(),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
tx.locktime = bufferReader.readUInt32();
|
|
96
|
+
if (tx.version >= 3 && tx.type !== DASH_NORMAL) {
|
|
97
|
+
tx.specific.extraPayload = bufferReader.readVarSlice();
|
|
98
|
+
}
|
|
99
|
+
if (options.nostrict)
|
|
100
|
+
return tx;
|
|
101
|
+
if (bufferReader.offset !== buffer.length)
|
|
102
|
+
throw new Error('Transaction has unexpected data');
|
|
103
|
+
return tx;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=dash.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransactionBase, TransactionOptions } from './base';
|
|
2
|
+
export declare function fromConstructor(options: TransactionOptions): TransactionBase<undefined>;
|
|
3
|
+
export declare function fromBuffer(buffer: Buffer, options: TransactionOptions): TransactionBase<undefined>;
|
|
4
|
+
//# sourceMappingURL=decred.d.ts.map
|
|
@@ -0,0 +1,149 @@
|
|
|
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 bufferutils_1 = require("../bufferutils");
|
|
8
|
+
const bcrypto = tslib_1.__importStar(require("../crypto"));
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
const DECRED_TX_VERSION = 1;
|
|
11
|
+
const DECRED_TX_SERIALIZE_FULL = 0;
|
|
12
|
+
const DECRED_TX_SERIALIZE_NO_WITNESS = 1;
|
|
13
|
+
const DECRED_SCRIPT_VERSION = 0;
|
|
14
|
+
function hasWitnesses(tx) {
|
|
15
|
+
return tx.type === DECRED_TX_SERIALIZE_FULL;
|
|
16
|
+
}
|
|
17
|
+
function byteLength(tx, _ALLOW_WITNESS = true) {
|
|
18
|
+
let byteLength = 4 + varuint.encodingLength(tx.ins.length);
|
|
19
|
+
let nWitness = 0;
|
|
20
|
+
const hasWitnesses = _ALLOW_WITNESS && tx.hasWitnesses();
|
|
21
|
+
byteLength += tx.ins.reduce((sum, input) => {
|
|
22
|
+
sum += 32 + 4 + 1 + 4;
|
|
23
|
+
if (hasWitnesses) {
|
|
24
|
+
nWitness += 1;
|
|
25
|
+
sum += 8 + 4 + 4;
|
|
26
|
+
sum += (0, base_1.varSliceSize)(input.decredWitness.script);
|
|
27
|
+
}
|
|
28
|
+
return sum;
|
|
29
|
+
}, 0);
|
|
30
|
+
if (hasWitnesses) {
|
|
31
|
+
byteLength += varuint.encodingLength(nWitness);
|
|
32
|
+
}
|
|
33
|
+
byteLength += varuint.encodingLength(tx.outs.length);
|
|
34
|
+
byteLength += tx.outs.reduce((sum, output) => {
|
|
35
|
+
sum += 8 + 2;
|
|
36
|
+
sum += (0, base_1.varSliceSize)(output.script);
|
|
37
|
+
return sum;
|
|
38
|
+
}, 0);
|
|
39
|
+
byteLength += 4 + 4;
|
|
40
|
+
return byteLength;
|
|
41
|
+
}
|
|
42
|
+
function toBuffer(tx, buffer, initialOffset, _ALLOW_WITNESS = true) {
|
|
43
|
+
if (!buffer)
|
|
44
|
+
buffer = Buffer.allocUnsafe(byteLength(tx, _ALLOW_WITNESS));
|
|
45
|
+
const bufferWriter = new bufferutils_1.BufferWriter(buffer, initialOffset || 0);
|
|
46
|
+
bufferWriter.writeUInt16(tx.version);
|
|
47
|
+
bufferWriter.writeUInt16(_ALLOW_WITNESS ? tx.type : DECRED_TX_SERIALIZE_NO_WITNESS);
|
|
48
|
+
bufferWriter.writeVarInt(tx.ins.length);
|
|
49
|
+
tx.ins.forEach(txIn => {
|
|
50
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
51
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
52
|
+
bufferWriter.writeUInt8(txIn.decredTree);
|
|
53
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
54
|
+
});
|
|
55
|
+
bufferWriter.writeVarInt(tx.outs.length);
|
|
56
|
+
tx.outs.forEach(txOut => {
|
|
57
|
+
bufferWriter.writeUInt64(txOut.value);
|
|
58
|
+
bufferWriter.writeUInt16(txOut.decredVersion);
|
|
59
|
+
bufferWriter.writeVarSlice(txOut.script);
|
|
60
|
+
});
|
|
61
|
+
bufferWriter.writeUInt32(tx.locktime);
|
|
62
|
+
bufferWriter.writeUInt32(tx.expiry);
|
|
63
|
+
if (_ALLOW_WITNESS && tx.hasWitnesses()) {
|
|
64
|
+
bufferWriter.writeVarInt(tx.ins.length);
|
|
65
|
+
tx.ins.forEach(input => {
|
|
66
|
+
bufferWriter.writeUInt64(input.decredWitness.value);
|
|
67
|
+
bufferWriter.writeUInt32(input.decredWitness.height);
|
|
68
|
+
bufferWriter.writeUInt32(input.decredWitness.blockIndex);
|
|
69
|
+
bufferWriter.writeVarSlice(input.decredWitness.script);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (initialOffset !== undefined)
|
|
73
|
+
return buffer.subarray(initialOffset, bufferWriter.offset);
|
|
74
|
+
return buffer;
|
|
75
|
+
}
|
|
76
|
+
function getHash(tx, forWitness = false) {
|
|
77
|
+
if (forWitness && tx.isCoinbase())
|
|
78
|
+
return Buffer.alloc(32, 0);
|
|
79
|
+
return bcrypto.blake256(toBuffer(tx, undefined, undefined, forWitness));
|
|
80
|
+
}
|
|
81
|
+
function weight(tx) {
|
|
82
|
+
return tx.byteLength(true);
|
|
83
|
+
}
|
|
84
|
+
function fromConstructor(options) {
|
|
85
|
+
const tx = new base_1.TransactionBase(options);
|
|
86
|
+
tx.byteLength = byteLength.bind(null, tx);
|
|
87
|
+
tx.toBuffer = toBuffer.bind(null, tx);
|
|
88
|
+
tx.hasWitnesses = hasWitnesses.bind(null, tx);
|
|
89
|
+
tx.getHash = getHash.bind(null, tx);
|
|
90
|
+
tx.weight = weight.bind(null, tx);
|
|
91
|
+
return tx;
|
|
92
|
+
}
|
|
93
|
+
function fromBuffer(buffer, options) {
|
|
94
|
+
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
|
95
|
+
const tx = fromConstructor(options);
|
|
96
|
+
tx.version = bufferReader.readInt32();
|
|
97
|
+
tx.type = tx.version >> 16;
|
|
98
|
+
tx.version &= 0xffff;
|
|
99
|
+
if (tx.version !== DECRED_TX_VERSION) {
|
|
100
|
+
throw new Error('Unsupported Decred transaction version');
|
|
101
|
+
}
|
|
102
|
+
if (tx.type !== DECRED_TX_SERIALIZE_FULL && tx.type !== DECRED_TX_SERIALIZE_NO_WITNESS) {
|
|
103
|
+
throw new Error('Unsupported Decred transaction type');
|
|
104
|
+
}
|
|
105
|
+
const vinLen = bufferReader.readVarInt();
|
|
106
|
+
for (let i = 0; i < vinLen; ++i) {
|
|
107
|
+
tx.ins.push({
|
|
108
|
+
hash: bufferReader.readSlice(32),
|
|
109
|
+
index: bufferReader.readUInt32(),
|
|
110
|
+
decredTree: bufferReader.readUInt8(),
|
|
111
|
+
sequence: bufferReader.readUInt32(),
|
|
112
|
+
script: base_1.EMPTY_SCRIPT,
|
|
113
|
+
witness: [],
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const voutLen = bufferReader.readVarInt();
|
|
117
|
+
for (let i = 0; i < voutLen; i++) {
|
|
118
|
+
const value = bufferReader.readUInt64String();
|
|
119
|
+
const version = bufferReader.readUInt16();
|
|
120
|
+
if (version !== DECRED_SCRIPT_VERSION)
|
|
121
|
+
throw new Error('Unsupported Decred script version');
|
|
122
|
+
tx.outs.push({
|
|
123
|
+
value,
|
|
124
|
+
decredVersion: version,
|
|
125
|
+
script: bufferReader.readVarSlice(),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
tx.locktime = bufferReader.readUInt32();
|
|
129
|
+
tx.expiry = bufferReader.readUInt32();
|
|
130
|
+
if (tx.type === DECRED_TX_SERIALIZE_FULL) {
|
|
131
|
+
const count = bufferReader.readVarInt();
|
|
132
|
+
if (count !== vinLen)
|
|
133
|
+
throw new Error('Non equal number of ins and witnesses');
|
|
134
|
+
tx.ins.forEach(vin => {
|
|
135
|
+
vin.decredWitness = {
|
|
136
|
+
value: bufferReader.readUInt64String(),
|
|
137
|
+
height: bufferReader.readUInt32(),
|
|
138
|
+
blockIndex: bufferReader.readUInt32(),
|
|
139
|
+
script: bufferReader.readVarSlice(),
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (options.nostrict)
|
|
144
|
+
return tx;
|
|
145
|
+
if (bufferReader.offset !== buffer.length)
|
|
146
|
+
throw new Error('Transaction has unexpected data');
|
|
147
|
+
return tx;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=decred.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TransactionBase, TransactionOptions } from './base';
|
|
2
|
+
import * as dash from './dash';
|
|
3
|
+
import * as zcash from './zcash';
|
|
4
|
+
export type TxOptions = TransactionOptions & {
|
|
5
|
+
txSpecific?: dash.DashSpecific | zcash.ZcashSpecific;
|
|
6
|
+
};
|
|
7
|
+
declare class Transaction extends TransactionBase<dash.DashSpecific | zcash.ZcashSpecific> {
|
|
8
|
+
constructor(options?: TxOptions);
|
|
9
|
+
static isCoinbaseHash(buffer: Buffer): boolean;
|
|
10
|
+
static fromBuffer(buffer: Buffer, options?: TransactionOptions): TransactionBase<undefined> | TransactionBase<dash.DashSpecific> | TransactionBase<zcash.ZcashSpecific>;
|
|
11
|
+
static fromHex(hex: string, options?: TransactionOptions): TransactionBase<undefined> | TransactionBase<dash.DashSpecific> | TransactionBase<zcash.ZcashSpecific>;
|
|
12
|
+
}
|
|
13
|
+
export type { TransactionOptions } from './base';
|
|
14
|
+
export { Transaction };
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transaction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const networks_1 = require("../networks");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
const bitcoin = tslib_1.__importStar(require("./bitcoin"));
|
|
8
|
+
const dash = tslib_1.__importStar(require("./dash"));
|
|
9
|
+
const decred = tslib_1.__importStar(require("./decred"));
|
|
10
|
+
const peercoin = tslib_1.__importStar(require("./peercoin"));
|
|
11
|
+
const zcash = tslib_1.__importStar(require("./zcash"));
|
|
12
|
+
class Transaction extends base_1.TransactionBase {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super(options);
|
|
15
|
+
if ((0, networks_1.isNetworkType)('dash', this.network))
|
|
16
|
+
return dash.fromConstructor(options);
|
|
17
|
+
if ((0, networks_1.isNetworkType)('decred', this.network))
|
|
18
|
+
return decred.fromConstructor(options);
|
|
19
|
+
if ((0, networks_1.isNetworkType)('peercoin', this.network))
|
|
20
|
+
return peercoin.fromConstructor(options);
|
|
21
|
+
if ((0, networks_1.isNetworkType)('zcash', this.network))
|
|
22
|
+
return zcash.fromConstructor(options);
|
|
23
|
+
return bitcoin.fromConstructor(options);
|
|
24
|
+
}
|
|
25
|
+
static isCoinbaseHash(buffer) {
|
|
26
|
+
return (0, base_1.isCoinbaseHash)(buffer);
|
|
27
|
+
}
|
|
28
|
+
static fromBuffer(buffer, options = {}) {
|
|
29
|
+
if ((0, networks_1.isNetworkType)('dash', options.network))
|
|
30
|
+
return dash.fromBuffer(buffer, options);
|
|
31
|
+
if ((0, networks_1.isNetworkType)('decred', options.network))
|
|
32
|
+
return decred.fromBuffer(buffer, options);
|
|
33
|
+
if ((0, networks_1.isNetworkType)('peercoin', options.network))
|
|
34
|
+
return peercoin.fromBuffer(buffer, options);
|
|
35
|
+
if ((0, networks_1.isNetworkType)('zcash', options.network))
|
|
36
|
+
return zcash.fromBuffer(buffer, options);
|
|
37
|
+
return bitcoin.fromBuffer(buffer, options);
|
|
38
|
+
}
|
|
39
|
+
static fromHex(hex, options = {}) {
|
|
40
|
+
return this.fromBuffer(Buffer.from(hex, 'hex'), Object.assign(Object.assign({}, options), { nostrict: false }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Transaction = Transaction;
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransactionBase, TransactionOptions } from './base';
|
|
2
|
+
export declare function fromConstructor(options: TransactionOptions): TransactionBase<undefined>;
|
|
3
|
+
export declare function fromBuffer(buffer: Buffer, options: TransactionOptions): TransactionBase<undefined>;
|
|
4
|
+
//# sourceMappingURL=peercoin.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromConstructor = fromConstructor;
|
|
4
|
+
exports.fromBuffer = fromBuffer;
|
|
5
|
+
const bufferutils_1 = require("../bufferutils");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
function toBuffer(tx, buffer, initialOffset) {
|
|
8
|
+
if (!buffer)
|
|
9
|
+
buffer = Buffer.allocUnsafe(tx.byteLength(false));
|
|
10
|
+
const bufferWriter = new bufferutils_1.BufferWriter(buffer, initialOffset || 0);
|
|
11
|
+
bufferWriter.writeInt32(tx.version);
|
|
12
|
+
bufferWriter.writeUInt32(tx.timestamp);
|
|
13
|
+
bufferWriter.writeVarInt(tx.ins.length);
|
|
14
|
+
tx.ins.forEach(txIn => {
|
|
15
|
+
bufferWriter.writeSlice(txIn.hash);
|
|
16
|
+
bufferWriter.writeUInt32(txIn.index);
|
|
17
|
+
bufferWriter.writeVarSlice(txIn.script);
|
|
18
|
+
bufferWriter.writeUInt32(txIn.sequence);
|
|
19
|
+
});
|
|
20
|
+
bufferWriter.writeVarInt(tx.outs.length);
|
|
21
|
+
tx.outs.forEach(txOut => {
|
|
22
|
+
bufferWriter.writeUInt64(txOut.value);
|
|
23
|
+
bufferWriter.writeVarSlice(txOut.script);
|
|
24
|
+
});
|
|
25
|
+
bufferWriter.writeUInt32(tx.locktime);
|
|
26
|
+
if (initialOffset !== undefined)
|
|
27
|
+
return buffer.subarray(initialOffset, bufferWriter.offset);
|
|
28
|
+
return buffer;
|
|
29
|
+
}
|
|
30
|
+
function fromConstructor(options) {
|
|
31
|
+
const tx = new base_1.TransactionBase(options);
|
|
32
|
+
tx.toBuffer = toBuffer.bind(null, tx);
|
|
33
|
+
return tx;
|
|
34
|
+
}
|
|
35
|
+
function fromBuffer(buffer, options) {
|
|
36
|
+
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
|
37
|
+
const tx = fromConstructor(options);
|
|
38
|
+
tx.version = bufferReader.readInt32();
|
|
39
|
+
tx.timestamp = bufferReader.readUInt32();
|
|
40
|
+
const vinLen = bufferReader.readVarInt();
|
|
41
|
+
for (let i = 0; i < vinLen; ++i) {
|
|
42
|
+
tx.ins.push({
|
|
43
|
+
hash: bufferReader.readSlice(32),
|
|
44
|
+
index: bufferReader.readUInt32(),
|
|
45
|
+
script: bufferReader.readVarSlice(),
|
|
46
|
+
sequence: bufferReader.readUInt32(),
|
|
47
|
+
witness: [],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const voutLen = bufferReader.readVarInt();
|
|
51
|
+
for (let i = 0; i < voutLen; ++i) {
|
|
52
|
+
tx.outs.push({
|
|
53
|
+
value: bufferReader.readUInt64String(),
|
|
54
|
+
script: bufferReader.readVarSlice(),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
tx.locktime = bufferReader.readUInt32();
|
|
58
|
+
if (options.nostrict)
|
|
59
|
+
return tx;
|
|
60
|
+
if (bufferReader.offset !== buffer.length)
|
|
61
|
+
throw new Error('Transaction has unexpected data');
|
|
62
|
+
return tx;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=peercoin.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TransactionBase, TransactionOptions } from './base';
|
|
2
|
+
export interface ZcashCompressedG {
|
|
3
|
+
x: Buffer;
|
|
4
|
+
yLsb: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ZcashSaplingZKProof {
|
|
7
|
+
type: 'sapling';
|
|
8
|
+
sA: Buffer;
|
|
9
|
+
sB: Buffer;
|
|
10
|
+
sC: Buffer;
|
|
11
|
+
}
|
|
12
|
+
export interface ZcashJoinSplitZKProof {
|
|
13
|
+
type: 'joinsplit';
|
|
14
|
+
gA: ZcashCompressedG;
|
|
15
|
+
gAPrime: ZcashCompressedG;
|
|
16
|
+
gB: ZcashCompressedG;
|
|
17
|
+
gBPrime: ZcashCompressedG;
|
|
18
|
+
gC: ZcashCompressedG;
|
|
19
|
+
gCPrime: ZcashCompressedG;
|
|
20
|
+
gK: ZcashCompressedG;
|
|
21
|
+
gH: ZcashCompressedG;
|
|
22
|
+
}
|
|
23
|
+
export interface ZcashJoinSplits {
|
|
24
|
+
vpubOld: number;
|
|
25
|
+
vpubNew: number;
|
|
26
|
+
anchor: Buffer;
|
|
27
|
+
nullifiers: Buffer[];
|
|
28
|
+
commitments: Buffer[];
|
|
29
|
+
ephemeralKey: Buffer;
|
|
30
|
+
randomSeed: Buffer;
|
|
31
|
+
macs: Buffer[];
|
|
32
|
+
zkproof: ZcashSaplingZKProof | ZcashJoinSplitZKProof;
|
|
33
|
+
ciphertexts: Buffer[];
|
|
34
|
+
}
|
|
35
|
+
export interface ZcashVShieldedSpend {
|
|
36
|
+
cv: Buffer;
|
|
37
|
+
anchor: Buffer;
|
|
38
|
+
nullifier: Buffer;
|
|
39
|
+
rk: Buffer;
|
|
40
|
+
zkproof: ZcashSaplingZKProof;
|
|
41
|
+
spendAuthSig: Buffer;
|
|
42
|
+
}
|
|
43
|
+
export interface ZcashVShieldedOutput {
|
|
44
|
+
cv: Buffer;
|
|
45
|
+
cmu: Buffer;
|
|
46
|
+
ephemeralKey: Buffer;
|
|
47
|
+
encCiphertext: Buffer;
|
|
48
|
+
outCiphertext: Buffer;
|
|
49
|
+
zkproof: ZcashSaplingZKProof;
|
|
50
|
+
}
|
|
51
|
+
export interface ZcashSpecific {
|
|
52
|
+
type: 'zcash';
|
|
53
|
+
joinsplits: ZcashJoinSplits[];
|
|
54
|
+
joinsplitPubkey: Buffer;
|
|
55
|
+
joinsplitSig: Buffer;
|
|
56
|
+
overwintered: number;
|
|
57
|
+
versionGroupId: number;
|
|
58
|
+
valueBalance: number;
|
|
59
|
+
vShieldedSpend: ZcashVShieldedSpend[];
|
|
60
|
+
vShieldedOutput: ZcashVShieldedOutput[];
|
|
61
|
+
bindingSig: Buffer;
|
|
62
|
+
consensusBranchId: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function fromConstructor(options: TransactionOptions): TransactionBase<ZcashSpecific>;
|
|
65
|
+
export declare function fromBuffer(buffer: Buffer, options: TransactionOptions): TransactionBase<ZcashSpecific>;
|
|
66
|
+
//# sourceMappingURL=zcash.d.ts.map
|