@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,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.p2wsh = p2wsh;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1"));
|
|
6
|
+
const bech32_1 = require("bech32");
|
|
7
|
+
const bcrypto = tslib_1.__importStar(require("../crypto"));
|
|
8
|
+
const networks_1 = require("../networks");
|
|
9
|
+
const bscript = tslib_1.__importStar(require("../script"));
|
|
10
|
+
const lazy = tslib_1.__importStar(require("./lazy"));
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const { OPS } = bscript;
|
|
13
|
+
const EMPTY_BUFFER = Buffer.alloc(0);
|
|
14
|
+
function stacksEqual(a, b) {
|
|
15
|
+
if (a.length !== b.length)
|
|
16
|
+
return false;
|
|
17
|
+
return a.every((x, i) => x.equals(b[i]));
|
|
18
|
+
}
|
|
19
|
+
function chunkHasUncompressedPubkey(chunk) {
|
|
20
|
+
if (Buffer.isBuffer(chunk) && chunk.length === 65 && chunk[0] === 0x04 && tiny_secp256k1_1.default.isPoint(chunk)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function p2wsh(a, opts) {
|
|
26
|
+
if (!a.address && !a.hash && !a.output && !a.redeem && !a.witness)
|
|
27
|
+
throw new TypeError('Not enough data');
|
|
28
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
29
|
+
(0, types_1.typeforce)({
|
|
30
|
+
network: types_1.typeforce.maybe(types_1.typeforce.Object),
|
|
31
|
+
address: types_1.typeforce.maybe(types_1.typeforce.String),
|
|
32
|
+
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(32)),
|
|
33
|
+
output: types_1.typeforce.maybe(types_1.typeforce.BufferN(34)),
|
|
34
|
+
redeem: types_1.typeforce.maybe({
|
|
35
|
+
input: types_1.typeforce.maybe(types_1.typeforce.Buffer),
|
|
36
|
+
network: types_1.typeforce.maybe(types_1.typeforce.Object),
|
|
37
|
+
output: types_1.typeforce.maybe(types_1.typeforce.Buffer),
|
|
38
|
+
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)),
|
|
39
|
+
}),
|
|
40
|
+
input: types_1.typeforce.maybe(types_1.typeforce.BufferN(0)),
|
|
41
|
+
witness: types_1.typeforce.maybe(types_1.typeforce.arrayOf(types_1.typeforce.Buffer)),
|
|
42
|
+
}, a);
|
|
43
|
+
const _address = lazy.value(() => {
|
|
44
|
+
const result = bech32_1.bech32.decode(a.address);
|
|
45
|
+
const version = result.words.shift();
|
|
46
|
+
const data = bech32_1.bech32.fromWords(result.words);
|
|
47
|
+
return {
|
|
48
|
+
version,
|
|
49
|
+
prefix: result.prefix,
|
|
50
|
+
data: Buffer.from(data),
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
const _rchunks = lazy.value(() => bscript.decompile(a.redeem.input));
|
|
54
|
+
let { network } = a;
|
|
55
|
+
if (!network) {
|
|
56
|
+
network = (a.redeem && a.redeem.network) || networks_1.bitcoin;
|
|
57
|
+
}
|
|
58
|
+
const o = { name: 'p2wsh', network };
|
|
59
|
+
lazy.prop(o, 'address', () => {
|
|
60
|
+
if (!o.hash)
|
|
61
|
+
return;
|
|
62
|
+
const words = bech32_1.bech32.toWords(o.hash);
|
|
63
|
+
words.unshift(0x00);
|
|
64
|
+
return bech32_1.bech32.encode(network.bech32, words);
|
|
65
|
+
});
|
|
66
|
+
lazy.prop(o, 'hash', () => {
|
|
67
|
+
if (a.output)
|
|
68
|
+
return a.output.subarray(2);
|
|
69
|
+
if (a.address)
|
|
70
|
+
return _address().data;
|
|
71
|
+
if (o.redeem && o.redeem.output)
|
|
72
|
+
return bcrypto.sha256(o.redeem.output);
|
|
73
|
+
});
|
|
74
|
+
lazy.prop(o, 'output', () => {
|
|
75
|
+
if (!o.hash)
|
|
76
|
+
return;
|
|
77
|
+
return bscript.compile([OPS.OP_0, o.hash]);
|
|
78
|
+
});
|
|
79
|
+
lazy.prop(o, 'redeem', () => {
|
|
80
|
+
if (!a.witness)
|
|
81
|
+
return;
|
|
82
|
+
return {
|
|
83
|
+
output: a.witness[a.witness.length - 1],
|
|
84
|
+
input: EMPTY_BUFFER,
|
|
85
|
+
witness: a.witness.slice(0, -1),
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
lazy.prop(o, 'input', () => {
|
|
89
|
+
if (!o.witness)
|
|
90
|
+
return;
|
|
91
|
+
return EMPTY_BUFFER;
|
|
92
|
+
});
|
|
93
|
+
lazy.prop(o, 'witness', () => {
|
|
94
|
+
if (a.redeem &&
|
|
95
|
+
a.redeem.input &&
|
|
96
|
+
a.redeem.input.length > 0 &&
|
|
97
|
+
a.redeem.output &&
|
|
98
|
+
a.redeem.output.length > 0) {
|
|
99
|
+
const stack = bscript.toStack(_rchunks());
|
|
100
|
+
o.redeem = Object.assign({ witness: stack }, a.redeem);
|
|
101
|
+
o.redeem.input = EMPTY_BUFFER;
|
|
102
|
+
return [].concat(stack, a.redeem.output);
|
|
103
|
+
}
|
|
104
|
+
if (!a.redeem)
|
|
105
|
+
return;
|
|
106
|
+
if (!a.redeem.output)
|
|
107
|
+
return;
|
|
108
|
+
if (!a.redeem.witness)
|
|
109
|
+
return;
|
|
110
|
+
return [].concat(a.redeem.witness, a.redeem.output);
|
|
111
|
+
});
|
|
112
|
+
lazy.prop(o, 'name', () => {
|
|
113
|
+
const nameParts = ['p2wsh'];
|
|
114
|
+
if (o.redeem !== undefined && o.redeem.name !== undefined)
|
|
115
|
+
nameParts.push(o.redeem.name);
|
|
116
|
+
return nameParts.join('-');
|
|
117
|
+
});
|
|
118
|
+
if (opts.validate) {
|
|
119
|
+
let hash = Buffer.from([]);
|
|
120
|
+
if (a.address) {
|
|
121
|
+
const { prefix, version, data } = _address();
|
|
122
|
+
if (prefix !== network.bech32)
|
|
123
|
+
throw new TypeError('Invalid prefix or Network mismatch');
|
|
124
|
+
if (version !== 0x00)
|
|
125
|
+
throw new TypeError('Invalid address version');
|
|
126
|
+
if (data.length !== 32)
|
|
127
|
+
throw new TypeError('Invalid address data');
|
|
128
|
+
hash = data;
|
|
129
|
+
}
|
|
130
|
+
if (a.hash) {
|
|
131
|
+
if (hash.length > 0 && !hash.equals(a.hash))
|
|
132
|
+
throw new TypeError('Hash mismatch');
|
|
133
|
+
else
|
|
134
|
+
hash = a.hash;
|
|
135
|
+
}
|
|
136
|
+
if (a.output) {
|
|
137
|
+
if (a.output.length !== 34 || a.output[0] !== OPS.OP_0 || a.output[1] !== 0x20)
|
|
138
|
+
throw new TypeError('Output is invalid');
|
|
139
|
+
const hash2 = a.output.subarray(2);
|
|
140
|
+
if (hash.length > 0 && !hash.equals(hash2))
|
|
141
|
+
throw new TypeError('Hash mismatch');
|
|
142
|
+
else
|
|
143
|
+
hash = hash2;
|
|
144
|
+
}
|
|
145
|
+
if (a.redeem) {
|
|
146
|
+
if (a.redeem.network && a.redeem.network !== network)
|
|
147
|
+
throw new TypeError('Network mismatch');
|
|
148
|
+
if (a.redeem.input &&
|
|
149
|
+
a.redeem.input.length > 0 &&
|
|
150
|
+
a.redeem.witness &&
|
|
151
|
+
a.redeem.witness.length > 0)
|
|
152
|
+
throw new TypeError('Ambiguous witness source');
|
|
153
|
+
if (a.redeem.output) {
|
|
154
|
+
if (bscript.decompile(a.redeem.output).length === 0)
|
|
155
|
+
throw new TypeError('Redeem.output is invalid');
|
|
156
|
+
const hash2 = bcrypto.sha256(a.redeem.output);
|
|
157
|
+
if (hash.length > 0 && !hash.equals(hash2))
|
|
158
|
+
throw new TypeError('Hash mismatch');
|
|
159
|
+
else
|
|
160
|
+
hash = hash2;
|
|
161
|
+
}
|
|
162
|
+
if (a.redeem.input && !bscript.isPushOnly(_rchunks()))
|
|
163
|
+
throw new TypeError('Non push-only scriptSig');
|
|
164
|
+
if (a.witness && a.redeem.witness && !stacksEqual(a.witness, a.redeem.witness))
|
|
165
|
+
throw new TypeError('Witness and redeem.witness mismatch');
|
|
166
|
+
if ((a.redeem.input && _rchunks().some(chunkHasUncompressedPubkey)) ||
|
|
167
|
+
(a.redeem.output &&
|
|
168
|
+
(bscript.decompile(a.redeem.output) || []).some(chunkHasUncompressedPubkey))) {
|
|
169
|
+
throw new TypeError('redeem.input or redeem.output contains uncompressed pubkey');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (a.witness && a.witness.length > 0) {
|
|
173
|
+
const wScript = a.witness[a.witness.length - 1];
|
|
174
|
+
if (a.redeem && a.redeem.output && !a.redeem.output.equals(wScript))
|
|
175
|
+
throw new TypeError('Witness and redeem.output mismatch');
|
|
176
|
+
if (a.witness.some(chunkHasUncompressedPubkey) ||
|
|
177
|
+
(bscript.decompile(wScript) || []).some(chunkHasUncompressedPubkey))
|
|
178
|
+
throw new TypeError('Witness contains uncompressed pubkey');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return Object.assign(o, a);
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=p2wsh.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sstxchange = sstxchange;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bs58check = tslib_1.__importStar(require("../bs58check"));
|
|
6
|
+
const networks_1 = require("../networks");
|
|
7
|
+
const bscript = tslib_1.__importStar(require("../script"));
|
|
8
|
+
const lazy = tslib_1.__importStar(require("./lazy"));
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const { OPS } = bscript;
|
|
11
|
+
function sstxchange(a, opts) {
|
|
12
|
+
if (!a.address && !a.hash && !a.output)
|
|
13
|
+
throw new TypeError('Not enough data');
|
|
14
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
15
|
+
(0, types_1.typeforce)({
|
|
16
|
+
network: types_1.typeforce.maybe(types_1.typeforce.Object),
|
|
17
|
+
address: types_1.typeforce.maybe(types_1.typeforce.String),
|
|
18
|
+
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)),
|
|
19
|
+
output: types_1.typeforce.maybe(types_1.typeforce.Buffer),
|
|
20
|
+
}, a);
|
|
21
|
+
const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network));
|
|
22
|
+
const network = a.network || networks_1.decred;
|
|
23
|
+
const o = { name: 'sstxchange', network };
|
|
24
|
+
lazy.prop(o, 'address', () => {
|
|
25
|
+
if (!o.hash)
|
|
26
|
+
return;
|
|
27
|
+
return bs58check.encodeAddress(o.hash, network.pubKeyHash, network);
|
|
28
|
+
});
|
|
29
|
+
lazy.prop(o, 'hash', () => {
|
|
30
|
+
if (a.output)
|
|
31
|
+
return a.output.subarray(4, 24);
|
|
32
|
+
if (a.address)
|
|
33
|
+
return _address().hash;
|
|
34
|
+
});
|
|
35
|
+
lazy.prop(o, 'output', () => {
|
|
36
|
+
if (!o.hash)
|
|
37
|
+
return;
|
|
38
|
+
return bscript.compile([
|
|
39
|
+
OPS.OP_SSTXCHANGE,
|
|
40
|
+
OPS.OP_DUP,
|
|
41
|
+
OPS.OP_HASH160,
|
|
42
|
+
o.hash,
|
|
43
|
+
OPS.OP_EQUALVERIFY,
|
|
44
|
+
OPS.OP_CHECKSIG,
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
if (opts.validate) {
|
|
48
|
+
let hash = Buffer.from([]);
|
|
49
|
+
if (a.address) {
|
|
50
|
+
const { version, hash: aHash } = _address();
|
|
51
|
+
if (version !== network.pubKeyHash)
|
|
52
|
+
throw new TypeError('Invalid version or Network mismatch');
|
|
53
|
+
if (aHash.length !== 20)
|
|
54
|
+
throw new TypeError('Invalid address');
|
|
55
|
+
hash = aHash;
|
|
56
|
+
}
|
|
57
|
+
if (a.hash) {
|
|
58
|
+
if (hash.length > 0 && !hash.equals(a.hash))
|
|
59
|
+
throw new TypeError('Hash mismatch');
|
|
60
|
+
else
|
|
61
|
+
hash = a.hash;
|
|
62
|
+
}
|
|
63
|
+
if (a.output) {
|
|
64
|
+
if (a.output.length !== 26 ||
|
|
65
|
+
a.output[0] !== OPS.OP_SSTXCHANGE ||
|
|
66
|
+
a.output[1] !== OPS.OP_DUP ||
|
|
67
|
+
a.output[2] !== OPS.OP_HASH160 ||
|
|
68
|
+
a.output[3] !== 0x14 ||
|
|
69
|
+
a.output[24] !== OPS.OP_EQUALVERIFY ||
|
|
70
|
+
a.output[25] !== OPS.OP_CHECKSIG)
|
|
71
|
+
throw new TypeError('sstxchange output is invalid');
|
|
72
|
+
const hash2 = a.output.subarray(4, 24);
|
|
73
|
+
if (hash.length > 0 && !hash.equals(hash2))
|
|
74
|
+
throw new TypeError('Hash mismatch');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return Object.assign(o, a);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=sstxchange.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sstxcommitment = sstxcommitment;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bufferutils_1 = require("../bufferutils");
|
|
6
|
+
const bs58check = tslib_1.__importStar(require("../bs58check"));
|
|
7
|
+
const networks_1 = require("../networks");
|
|
8
|
+
const bscript = tslib_1.__importStar(require("../script"));
|
|
9
|
+
const lazy = tslib_1.__importStar(require("./lazy"));
|
|
10
|
+
const types_1 = require("../types");
|
|
11
|
+
const { OPS } = bscript;
|
|
12
|
+
function sstxcommitment(a, opts) {
|
|
13
|
+
if (!a.address && !a.amount && !a.hash && !a.output)
|
|
14
|
+
throw new TypeError('Not enough data');
|
|
15
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
16
|
+
(0, types_1.typeforce)({
|
|
17
|
+
network: types_1.typeforce.maybe(types_1.typeforce.Object),
|
|
18
|
+
address: types_1.typeforce.maybe(types_1.typeforce.String),
|
|
19
|
+
amount: types_1.typeforce.maybe(types_1.typeforce.String),
|
|
20
|
+
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)),
|
|
21
|
+
output: types_1.typeforce.maybe(types_1.typeforce.Buffer),
|
|
22
|
+
}, a);
|
|
23
|
+
const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network));
|
|
24
|
+
const network = a.network || networks_1.decred;
|
|
25
|
+
const o = { name: 'sstxcommitment', network };
|
|
26
|
+
lazy.prop(o, 'address', () => {
|
|
27
|
+
if (!o.hash)
|
|
28
|
+
return;
|
|
29
|
+
return bs58check.encodeAddress(o.hash, network.pubKeyHash, network);
|
|
30
|
+
});
|
|
31
|
+
lazy.prop(o, 'hash', () => {
|
|
32
|
+
if (a.output)
|
|
33
|
+
return a.output.subarray(2, 22);
|
|
34
|
+
if (a.address)
|
|
35
|
+
return _address().hash;
|
|
36
|
+
});
|
|
37
|
+
lazy.prop(o, 'output', () => {
|
|
38
|
+
if (!o.hash || !a.amount)
|
|
39
|
+
return;
|
|
40
|
+
const buf = Buffer.allocUnsafe(o.hash.length + 10);
|
|
41
|
+
const writer = new bufferutils_1.BufferWriter(buf);
|
|
42
|
+
writer.writeSlice(o.hash);
|
|
43
|
+
writer.writeUInt64(a.amount);
|
|
44
|
+
writer.writeUInt8(0);
|
|
45
|
+
writer.writeUInt8(88);
|
|
46
|
+
return bscript.compile([OPS.OP_RETURN, buf]);
|
|
47
|
+
});
|
|
48
|
+
if (opts.validate) {
|
|
49
|
+
let hash = Buffer.from([]);
|
|
50
|
+
if (a.address) {
|
|
51
|
+
const { version, hash: aHash } = _address();
|
|
52
|
+
if (version !== network.pubKeyHash)
|
|
53
|
+
throw new TypeError('Invalid version or Network mismatch');
|
|
54
|
+
if (aHash.length !== 20)
|
|
55
|
+
throw new TypeError('Invalid address');
|
|
56
|
+
hash = aHash;
|
|
57
|
+
}
|
|
58
|
+
if (a.hash) {
|
|
59
|
+
if (hash.length > 0 && !hash.equals(a.hash))
|
|
60
|
+
throw new TypeError('Hash mismatch');
|
|
61
|
+
else
|
|
62
|
+
hash = a.hash;
|
|
63
|
+
}
|
|
64
|
+
if (a.output) {
|
|
65
|
+
if (a.output.length !== 32 || a.output[0] !== OPS.OP_RETURN)
|
|
66
|
+
throw new TypeError('sstxcommitment output is invalid');
|
|
67
|
+
const hash2 = a.output.subarray(2, 22);
|
|
68
|
+
if (hash.length > 0 && !hash.equals(hash2))
|
|
69
|
+
throw new TypeError('Hash mismatch');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Object.assign(o, a);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=sstxcommitment.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sstxpkh = sstxpkh;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bs58check = tslib_1.__importStar(require("../bs58check"));
|
|
6
|
+
const networks_1 = require("../networks");
|
|
7
|
+
const bscript = tslib_1.__importStar(require("../script"));
|
|
8
|
+
const lazy = tslib_1.__importStar(require("./lazy"));
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const { OPS } = bscript;
|
|
11
|
+
function sstxpkh(a, opts) {
|
|
12
|
+
if (!a.address && !a.hash && !a.output)
|
|
13
|
+
throw new TypeError('Not enough data');
|
|
14
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
15
|
+
(0, types_1.typeforce)({
|
|
16
|
+
network: types_1.typeforce.maybe(types_1.typeforce.Object),
|
|
17
|
+
address: types_1.typeforce.maybe(types_1.typeforce.String),
|
|
18
|
+
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)),
|
|
19
|
+
output: types_1.typeforce.maybe(types_1.typeforce.Buffer),
|
|
20
|
+
}, a);
|
|
21
|
+
const _address = lazy.value(() => bs58check.decodeAddress(a.address, a.network));
|
|
22
|
+
const network = a.network || networks_1.decred;
|
|
23
|
+
const o = { name: 'sstxpkh', network };
|
|
24
|
+
lazy.prop(o, 'address', () => {
|
|
25
|
+
if (!o.hash)
|
|
26
|
+
return;
|
|
27
|
+
return bs58check.encodeAddress(o.hash, network.pubKeyHash, network);
|
|
28
|
+
});
|
|
29
|
+
lazy.prop(o, 'hash', () => {
|
|
30
|
+
if (a.output)
|
|
31
|
+
return a.output.subarray(4, 24);
|
|
32
|
+
if (a.address)
|
|
33
|
+
return _address().hash;
|
|
34
|
+
});
|
|
35
|
+
lazy.prop(o, 'output', () => {
|
|
36
|
+
if (!o.hash)
|
|
37
|
+
return;
|
|
38
|
+
return bscript.compile([
|
|
39
|
+
OPS.OP_SSTX,
|
|
40
|
+
OPS.OP_DUP,
|
|
41
|
+
OPS.OP_HASH160,
|
|
42
|
+
o.hash,
|
|
43
|
+
OPS.OP_EQUALVERIFY,
|
|
44
|
+
OPS.OP_CHECKSIG,
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
if (opts.validate) {
|
|
48
|
+
let hash = Buffer.from([]);
|
|
49
|
+
if (a.address) {
|
|
50
|
+
const { version, hash: aHash } = _address();
|
|
51
|
+
if (version !== network.pubKeyHash)
|
|
52
|
+
throw new TypeError('Invalid version or Network mismatch');
|
|
53
|
+
if (aHash.length !== 20)
|
|
54
|
+
throw new TypeError('Invalid address');
|
|
55
|
+
hash = aHash;
|
|
56
|
+
}
|
|
57
|
+
if (a.hash) {
|
|
58
|
+
if (hash.length > 0 && !hash.equals(a.hash))
|
|
59
|
+
throw new TypeError('Hash mismatch');
|
|
60
|
+
else
|
|
61
|
+
hash = a.hash;
|
|
62
|
+
}
|
|
63
|
+
if (a.output) {
|
|
64
|
+
if (a.output.length !== 26 ||
|
|
65
|
+
a.output[0] !== OPS.OP_SSTX ||
|
|
66
|
+
a.output[1] !== OPS.OP_DUP ||
|
|
67
|
+
a.output[2] !== OPS.OP_HASH160 ||
|
|
68
|
+
a.output[3] !== 0x14 ||
|
|
69
|
+
a.output[24] !== OPS.OP_EQUALVERIFY ||
|
|
70
|
+
a.output[25] !== OPS.OP_CHECKSIG)
|
|
71
|
+
throw new TypeError('sstxpkh output is invalid');
|
|
72
|
+
const hash2 = a.output.subarray(4, 24);
|
|
73
|
+
if (hash.length > 0 && !hash.equals(hash2))
|
|
74
|
+
throw new TypeError('Hash mismatch');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return Object.assign(o, a);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=sstxpkh.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sstxsh = sstxsh;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bs58check = tslib_1.__importStar(require("../bs58check"));
|
|
6
|
+
const networks_1 = require("../networks");
|
|
7
|
+
const bscript = tslib_1.__importStar(require("../script"));
|
|
8
|
+
const lazy = tslib_1.__importStar(require("./lazy"));
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const { OPS } = bscript;
|
|
11
|
+
function sstxsh(a, opts) {
|
|
12
|
+
if (!a.address && !a.hash && !a.output)
|
|
13
|
+
throw new TypeError('Not enough data');
|
|
14
|
+
opts = Object.assign({ validate: true }, opts || {});
|
|
15
|
+
(0, types_1.typeforce)({
|
|
16
|
+
network: types_1.typeforce.maybe(types_1.typeforce.Object),
|
|
17
|
+
address: types_1.typeforce.maybe(types_1.typeforce.String),
|
|
18
|
+
hash: types_1.typeforce.maybe(types_1.typeforce.BufferN(20)),
|
|
19
|
+
output: types_1.typeforce.maybe(types_1.typeforce.Buffer),
|
|
20
|
+
}, a);
|
|
21
|
+
const network = a.network || networks_1.decred;
|
|
22
|
+
const o = { name: 'sstxsh', network };
|
|
23
|
+
const _address = lazy.value(() => bs58check.decodeAddress(a.address, network));
|
|
24
|
+
lazy.prop(o, 'address', () => {
|
|
25
|
+
if (!o.hash)
|
|
26
|
+
return;
|
|
27
|
+
return bs58check.encodeAddress(o.hash, network.scriptHash, network);
|
|
28
|
+
});
|
|
29
|
+
lazy.prop(o, 'hash', () => {
|
|
30
|
+
if (a.output)
|
|
31
|
+
return a.output.subarray(3, 23);
|
|
32
|
+
if (a.address)
|
|
33
|
+
return _address().hash;
|
|
34
|
+
});
|
|
35
|
+
lazy.prop(o, 'output', () => {
|
|
36
|
+
if (!o.hash)
|
|
37
|
+
return;
|
|
38
|
+
return bscript.compile([OPS.OP_SSTX, OPS.OP_HASH160, o.hash, OPS.OP_EQUAL]);
|
|
39
|
+
});
|
|
40
|
+
if (opts.validate) {
|
|
41
|
+
let hash = Buffer.from([]);
|
|
42
|
+
if (a.address) {
|
|
43
|
+
const { version, hash: aHash } = _address();
|
|
44
|
+
if (version !== network.scriptHash)
|
|
45
|
+
throw new TypeError('Invalid version or Network mismatch');
|
|
46
|
+
if (aHash.length !== 20)
|
|
47
|
+
throw new TypeError('Invalid address');
|
|
48
|
+
hash = aHash;
|
|
49
|
+
}
|
|
50
|
+
if (a.hash) {
|
|
51
|
+
if (hash.length > 0 && !hash.equals(a.hash))
|
|
52
|
+
throw new TypeError('Hash mismatch');
|
|
53
|
+
else
|
|
54
|
+
hash = a.hash;
|
|
55
|
+
}
|
|
56
|
+
if (a.output) {
|
|
57
|
+
if (a.output.length !== 24 ||
|
|
58
|
+
a.output[0] !== OPS.OP_SSTX ||
|
|
59
|
+
a.output[1] !== OPS.OP_HASH160 ||
|
|
60
|
+
a.output[2] !== 0x14 ||
|
|
61
|
+
a.output[23] !== OPS.OP_EQUAL)
|
|
62
|
+
throw new TypeError('sstxsh output is invalid');
|
|
63
|
+
const hash2 = a.output.subarray(3, 23);
|
|
64
|
+
if (hash.length > 0 && !hash.equals(hash2))
|
|
65
|
+
throw new TypeError('Hash mismatch');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return Object.assign(o, a);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=sstxsh.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as scriptNumber from './scriptNumber';
|
|
2
|
+
import * as scriptSignature from './scriptSignature';
|
|
3
|
+
import * as types from '../types';
|
|
4
|
+
import { Stack } from '../types';
|
|
5
|
+
export declare function isPushOnly(value: Stack): boolean;
|
|
6
|
+
export declare function compile(chunks: Buffer | Stack): Buffer;
|
|
7
|
+
export declare function decompile(buffer: Buffer | Stack): types.Stack;
|
|
8
|
+
export declare function toASM(chunks: Buffer | Stack): string;
|
|
9
|
+
export declare function fromASM(asm: string): Buffer;
|
|
10
|
+
export declare function toStack(chunks0: Buffer | Stack): Buffer[];
|
|
11
|
+
export declare function isCanonicalPubKey(buffer: Buffer): any;
|
|
12
|
+
export declare function isDefinedHashType(hashType: number): boolean;
|
|
13
|
+
export declare function isCanonicalScriptSignature(buffer: Buffer): boolean;
|
|
14
|
+
export declare const number: typeof scriptNumber;
|
|
15
|
+
export declare const signature: typeof scriptSignature;
|
|
16
|
+
export { OPS } from './ops';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|