@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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomSortingStrategy = void 0;
|
|
4
|
+
const utils_1 = require("../../../utils");
|
|
5
|
+
const convertOutput_1 = require("./convertOutput");
|
|
6
|
+
const randomSortingStrategy = ({ result, request, convertedInputs }) => {
|
|
7
|
+
const nonChangeOutputPermutation = [];
|
|
8
|
+
const changeOutputPermutation = [];
|
|
9
|
+
const convertedOutputs = result.outputs.map((output, index) => {
|
|
10
|
+
if (request.outputs[index]) {
|
|
11
|
+
nonChangeOutputPermutation.push(index);
|
|
12
|
+
return (0, convertOutput_1.convertOutput)(output, request.outputs[index]);
|
|
13
|
+
}
|
|
14
|
+
changeOutputPermutation.push(index);
|
|
15
|
+
return (0, convertOutput_1.convertOutput)(output, Object.assign({ type: 'change' }, request.changeAddress));
|
|
16
|
+
});
|
|
17
|
+
const permutation = [...nonChangeOutputPermutation];
|
|
18
|
+
const newPositionOfChange = (0, utils_1.getRandomInt)(0, permutation.length + 1);
|
|
19
|
+
permutation.splice(newPositionOfChange, 0, ...changeOutputPermutation);
|
|
20
|
+
const sortedOutputs = permutation.map(index => convertedOutputs[index]);
|
|
21
|
+
return {
|
|
22
|
+
inputs: (0, utils_1.arrayShuffle)(convertedInputs, { randomInt: utils_1.getRandomInt }),
|
|
23
|
+
outputs: sortedOutputs,
|
|
24
|
+
outputsPermutation: permutation,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.randomSortingStrategy = randomSortingStrategy;
|
|
28
|
+
//# sourceMappingURL=randomSortingStrategy.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CoinSelectSuccess, ComposeChangeAddress, ComposedTransaction, ComposeFinalOutput, ComposeInput, ComposeRequest } from '../../types';
|
|
2
|
+
type SortingStrategyParams<Input extends ComposeInput, Change extends ComposeChangeAddress> = {
|
|
3
|
+
request: ComposeRequest<Input, ComposeFinalOutput, Change>;
|
|
4
|
+
result: CoinSelectSuccess;
|
|
5
|
+
convertedInputs: Input[];
|
|
6
|
+
};
|
|
7
|
+
export type SortingStrategy = <Input extends ComposeInput, Change extends ComposeChangeAddress>(params: SortingStrategyParams<Input, Change>) => ComposedTransaction<Input, ComposeFinalOutput, Change>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=sortingStrategy.d.ts.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ComposeRequest, CoinSelectSuccess, ComposeInput, ComposeChangeAddress, ComposeFinalOutput, ComposedTransaction } from '../types';
|
|
2
|
+
export declare function createTransaction<Input extends ComposeInput, Change extends ComposeChangeAddress>(request: ComposeRequest<Input, ComposeFinalOutput, Change>, result: CoinSelectSuccess): ComposedTransaction<Input, ComposeFinalOutput, Change>;
|
|
3
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransaction = createTransaction;
|
|
4
|
+
const noneSortingStrategy_1 = require("./sorting/noneSortingStrategy");
|
|
5
|
+
const bip69SortingStrategy_1 = require("./sorting/bip69SortingStrategy");
|
|
6
|
+
const randomSortingStrategy_1 = require("./sorting/randomSortingStrategy");
|
|
7
|
+
const strategyMap = {
|
|
8
|
+
bip69: bip69SortingStrategy_1.bip69SortingStrategy,
|
|
9
|
+
none: noneSortingStrategy_1.noneSortingStrategy,
|
|
10
|
+
random: randomSortingStrategy_1.randomSortingStrategy,
|
|
11
|
+
};
|
|
12
|
+
function createTransaction(request, result) {
|
|
13
|
+
const convertedInputs = result.inputs.map(input => request.utxos[input.i]);
|
|
14
|
+
return strategyMap[request.sortingStrategy]({ result, request, convertedInputs });
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function ripemd160(buffer: Buffer): Buffer;
|
|
2
|
+
export declare function sha1(buffer: Buffer): Buffer;
|
|
3
|
+
export declare function sha256(buffer: Buffer): Buffer;
|
|
4
|
+
export declare function blake256(buffer: Buffer): Buffer;
|
|
5
|
+
export declare function hash160(buffer: Buffer): Buffer;
|
|
6
|
+
export declare function hash160blake256(buffer: Buffer): Buffer;
|
|
7
|
+
export declare function hash256(buffer: Buffer): Buffer;
|
|
8
|
+
export declare function hmacSHA512(key: Buffer, data: Buffer): Buffer;
|
|
9
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ripemd160 = ripemd160;
|
|
4
|
+
exports.sha1 = sha1;
|
|
5
|
+
exports.sha256 = sha256;
|
|
6
|
+
exports.blake256 = blake256;
|
|
7
|
+
exports.hash160 = hash160;
|
|
8
|
+
exports.hash160blake256 = hash160blake256;
|
|
9
|
+
exports.hash256 = hash256;
|
|
10
|
+
exports.hmacSHA512 = hmacSHA512;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const blake_hash_1 = tslib_1.__importDefault(require("blake-hash"));
|
|
13
|
+
const create_hmac_1 = tslib_1.__importDefault(require("create-hmac"));
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
function ripemd160(buffer) {
|
|
16
|
+
try {
|
|
17
|
+
return (0, crypto_1.createHash)('rmd160').update(buffer).digest();
|
|
18
|
+
}
|
|
19
|
+
catch (_a) {
|
|
20
|
+
return (0, crypto_1.createHash)('ripemd160').update(buffer).digest();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function sha1(buffer) {
|
|
24
|
+
return (0, crypto_1.createHash)('sha1').update(buffer).digest();
|
|
25
|
+
}
|
|
26
|
+
function sha256(buffer) {
|
|
27
|
+
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
28
|
+
}
|
|
29
|
+
function blake256(buffer) {
|
|
30
|
+
return (0, blake_hash_1.default)('blake256').update(buffer).digest();
|
|
31
|
+
}
|
|
32
|
+
function hash160(buffer) {
|
|
33
|
+
return ripemd160(sha256(buffer));
|
|
34
|
+
}
|
|
35
|
+
function hash160blake256(buffer) {
|
|
36
|
+
return ripemd160(blake256(buffer));
|
|
37
|
+
}
|
|
38
|
+
function hash256(buffer) {
|
|
39
|
+
return sha256(sha256(buffer));
|
|
40
|
+
}
|
|
41
|
+
function hmacSHA512(key, data) {
|
|
42
|
+
return (0, create_hmac_1.default)('sha512', key).update(data).digest();
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Network } from './networks';
|
|
2
|
+
declare const BIP32_PAYMENT_TYPES: {
|
|
3
|
+
readonly 76067358: "p2pkh";
|
|
4
|
+
readonly 77429938: "p2sh";
|
|
5
|
+
readonly 78792518: "p2wpkh";
|
|
6
|
+
readonly 70617039: "p2pkh";
|
|
7
|
+
readonly 71979618: "p2sh";
|
|
8
|
+
readonly 73342198: "p2wpkh";
|
|
9
|
+
readonly 27108450: "p2pkh";
|
|
10
|
+
readonly 28471030: "p2sh";
|
|
11
|
+
};
|
|
12
|
+
type VersionBytes = keyof typeof BIP32_PAYMENT_TYPES;
|
|
13
|
+
export type PaymentType = (typeof BIP32_PAYMENT_TYPES)[VersionBytes] | 'p2tr';
|
|
14
|
+
export declare const getXpubOrDescriptorInfo: (descriptor: string, network?: Network) => {
|
|
15
|
+
levels: string[];
|
|
16
|
+
paymentType: PaymentType;
|
|
17
|
+
node: import("./bip32").BIP32Interface;
|
|
18
|
+
};
|
|
19
|
+
export declare const deriveAddresses: (descriptor: string, type: "receive" | "change", from: number, count: number, network?: Network) => {
|
|
20
|
+
address: string;
|
|
21
|
+
path: string;
|
|
22
|
+
}[];
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=derivation.d.ts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveAddresses = exports.getXpubOrDescriptorInfo = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const bs58_1 = tslib_1.__importDefault(require("bs58"));
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const payments_1 = require("./payments");
|
|
8
|
+
const bip32_1 = require("./bip32");
|
|
9
|
+
const networks_1 = require("./networks");
|
|
10
|
+
const BIP32_PAYMENT_TYPES = {
|
|
11
|
+
0x0488b21e: 'p2pkh',
|
|
12
|
+
0x049d7cb2: 'p2sh',
|
|
13
|
+
0x04b24746: 'p2wpkh',
|
|
14
|
+
0x043587cf: 'p2pkh',
|
|
15
|
+
0x044a5262: 'p2sh',
|
|
16
|
+
0x045f1cf6: 'p2wpkh',
|
|
17
|
+
0x019da462: 'p2pkh',
|
|
18
|
+
0x01b26ef6: 'p2sh',
|
|
19
|
+
};
|
|
20
|
+
const BIP32_COIN_TYPES = {
|
|
21
|
+
0x0488b21e: "0'",
|
|
22
|
+
0x049d7cb2: "0'",
|
|
23
|
+
0x04b24746: "0'",
|
|
24
|
+
0x043587cf: "1'",
|
|
25
|
+
0x044a5262: "1'",
|
|
26
|
+
0x045f1cf6: "1'",
|
|
27
|
+
0x019da462: "2'",
|
|
28
|
+
0x01b26ef6: "2'",
|
|
29
|
+
};
|
|
30
|
+
const BIP32_PURPOSES = {
|
|
31
|
+
p2pkh: "44'",
|
|
32
|
+
p2sh: "49'",
|
|
33
|
+
p2wpkh: "84'",
|
|
34
|
+
p2tr: "86'",
|
|
35
|
+
};
|
|
36
|
+
const validateVersion = (version) => !!BIP32_PAYMENT_TYPES[version];
|
|
37
|
+
const getVersion = (xpub) => {
|
|
38
|
+
const version = Buffer.from(bs58_1.default.decode(xpub)).readUInt32BE();
|
|
39
|
+
if (!validateVersion(version))
|
|
40
|
+
throw new Error(`Unknown xpub version: ${xpub}`);
|
|
41
|
+
return version;
|
|
42
|
+
};
|
|
43
|
+
const getPubkeyToPayment = (type, network) => (pubkey) => {
|
|
44
|
+
switch (type) {
|
|
45
|
+
case 'p2pkh':
|
|
46
|
+
return (0, payments_1.p2pkh)({ pubkey, network });
|
|
47
|
+
case 'p2sh':
|
|
48
|
+
return (0, payments_1.p2sh)({
|
|
49
|
+
redeem: (0, payments_1.p2wpkh)({
|
|
50
|
+
pubkey,
|
|
51
|
+
network,
|
|
52
|
+
}),
|
|
53
|
+
network,
|
|
54
|
+
});
|
|
55
|
+
case 'p2wpkh':
|
|
56
|
+
return (0, payments_1.p2wpkh)({ pubkey, network });
|
|
57
|
+
case 'p2tr':
|
|
58
|
+
return (0, payments_1.p2tr)({ pubkey, network });
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`Unknown payment type '${type}'`);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const getBip32Node = (xpub, version, network) => (0, bip32_1.fromBase58)(xpub, Object.assign(Object.assign({}, network), { bip32: Object.assign(Object.assign({}, network.bip32), { public: version }) }));
|
|
64
|
+
const getXpubInfo = (xpub, network) => {
|
|
65
|
+
const version = getVersion(xpub);
|
|
66
|
+
const paymentType = BIP32_PAYMENT_TYPES[version];
|
|
67
|
+
const coinType = network.wif === 0xb0
|
|
68
|
+
? "2'"
|
|
69
|
+
: BIP32_COIN_TYPES[version];
|
|
70
|
+
const purpose = BIP32_PURPOSES[paymentType];
|
|
71
|
+
const node = getBip32Node(xpub, version, network);
|
|
72
|
+
const account = `${(node.index << 1) >>> 1}'`;
|
|
73
|
+
const levels = [purpose, coinType, account];
|
|
74
|
+
return {
|
|
75
|
+
levels,
|
|
76
|
+
paymentType,
|
|
77
|
+
node,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const getDescriptorInfo = (paymentType, descriptor, network) => {
|
|
81
|
+
const [_match, _script, path, xpub, _checksum] = descriptor.match(/^([a-z]+\()+\[([a-z0-9]{8}(?:\/[0-9]+'?){3,})\]([xyztuv]pub[a-zA-Z0-9]*)\/<0;1>\/\*\)+(#[a-z0-9]{8})?$/) || (0, utils_1.throwError)(`Descriptor cannot be parsed: ${descriptor}`);
|
|
82
|
+
const [_fingerprint, ...levels] = path.split('/');
|
|
83
|
+
const version = getVersion(xpub);
|
|
84
|
+
const node = getBip32Node(xpub, version, network);
|
|
85
|
+
return {
|
|
86
|
+
levels,
|
|
87
|
+
paymentType,
|
|
88
|
+
node,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const getXpubOrDescriptorInfo = (descriptor, network = networks_1.bitcoin) => {
|
|
92
|
+
if (descriptor.startsWith('pkh(')) {
|
|
93
|
+
return getDescriptorInfo('p2pkh', descriptor, network);
|
|
94
|
+
}
|
|
95
|
+
if (descriptor.startsWith('sh(wpkh(')) {
|
|
96
|
+
return getDescriptorInfo('p2sh', descriptor, network);
|
|
97
|
+
}
|
|
98
|
+
if (descriptor.startsWith('wpkh(')) {
|
|
99
|
+
return getDescriptorInfo('p2wpkh', descriptor, network);
|
|
100
|
+
}
|
|
101
|
+
if (descriptor.startsWith('tr(')) {
|
|
102
|
+
return getDescriptorInfo('p2tr', descriptor, network);
|
|
103
|
+
}
|
|
104
|
+
return getXpubInfo(descriptor, network);
|
|
105
|
+
};
|
|
106
|
+
exports.getXpubOrDescriptorInfo = getXpubOrDescriptorInfo;
|
|
107
|
+
const deriveAddresses = (descriptor, type, from, count, network = networks_1.bitcoin) => {
|
|
108
|
+
const { levels, node, paymentType } = (0, exports.getXpubOrDescriptorInfo)(descriptor, network);
|
|
109
|
+
const getAddress = getPubkeyToPayment(paymentType, network);
|
|
110
|
+
const change = type === 'receive' ? 0 : 1;
|
|
111
|
+
const changeNode = node.derive(change);
|
|
112
|
+
return Array.from(Array(count).keys())
|
|
113
|
+
.map(i => changeNode.derive(from + i).publicKey)
|
|
114
|
+
.map(a => getAddress(a).address || (0, utils_1.throwError)('Cannot convert pubkey to address'))
|
|
115
|
+
.map((address, i) => ({
|
|
116
|
+
address,
|
|
117
|
+
path: `m/${levels.join('/')}/${change}/${from + i}`,
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
exports.deriveAddresses = deriveAddresses;
|
|
121
|
+
//# sourceMappingURL=derivation.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { deriveAddresses } from './derivation';
|
|
2
|
+
import type { Network } from './networks';
|
|
3
|
+
export type AddressInfo = ReturnType<typeof deriveAddresses>[number];
|
|
4
|
+
export type AddressResult<T> = T & {
|
|
5
|
+
empty: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const countUnusedFromEnd: <T>(array: T[], isUnused: (t: T) => boolean, lookout: number) => number;
|
|
8
|
+
export declare const discovery: <T>(discover: (addr: AddressInfo) => Promise<AddressResult<T>>, xpub: string, type: "receive" | "change", network?: Network, lookout?: number) => Promise<AddressResult<T>[]>;
|
|
9
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.discovery = exports.countUnusedFromEnd = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const derivation_1 = require("./derivation");
|
|
6
|
+
const DISCOVERY_LOOKOUT = 20;
|
|
7
|
+
const countUnusedFromEnd = (array, isUnused, lookout) => {
|
|
8
|
+
const boundary = array.length > lookout ? array.length - lookout : 0;
|
|
9
|
+
for (let i = array.length; i > boundary; --i) {
|
|
10
|
+
if (!isUnused(array[i - 1])) {
|
|
11
|
+
return array.length - i;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return array.length;
|
|
15
|
+
};
|
|
16
|
+
exports.countUnusedFromEnd = countUnusedFromEnd;
|
|
17
|
+
const discovery = (discover, xpub, type, network, lookout = DISCOVERY_LOOKOUT) => {
|
|
18
|
+
const discoverRecursive = (from, prev) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const unused = (0, exports.countUnusedFromEnd)(prev, a => a.empty, lookout);
|
|
20
|
+
if (unused >= lookout)
|
|
21
|
+
return prev;
|
|
22
|
+
const moreCount = lookout - unused;
|
|
23
|
+
const addresses = (0, derivation_1.deriveAddresses)(xpub, type, from, moreCount, network);
|
|
24
|
+
const more = yield Promise.all(addresses.map(discover));
|
|
25
|
+
return discoverRecursive(from + moreCount, prev.concat(more));
|
|
26
|
+
});
|
|
27
|
+
return discoverRecursive(0, []);
|
|
28
|
+
};
|
|
29
|
+
exports.discovery = discovery;
|
|
30
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
declare module 'typeforce' {
|
|
2
|
+
interface Typeforce {
|
|
3
|
+
(type: any, value: any, strict?: any, surrogate?: any): boolean;
|
|
4
|
+
Array(value: any): value is any[];
|
|
5
|
+
ArrayN(length: number): (value: any) => value is any[];
|
|
6
|
+
Boolean(value: any): value is boolean;
|
|
7
|
+
Buffer(value: any): value is Buffer;
|
|
8
|
+
BufferN(length: number): (value: any) => value is Buffer;
|
|
9
|
+
Finite(value: any): value is number;
|
|
10
|
+
Function(value: any): value is FunctionConstructor;
|
|
11
|
+
Hex(value: any): value is string;
|
|
12
|
+
HexN(length: number): (value: any) => value is string;
|
|
13
|
+
Nil(value: any): boolean;
|
|
14
|
+
Number(value: any): value is number;
|
|
15
|
+
Object(value: any): value is ObjectConstructor;
|
|
16
|
+
Range(a: any, b: any, f: any): boolean;
|
|
17
|
+
String(value: any): value is string;
|
|
18
|
+
StringN(length: number): (value: any) => value is string;
|
|
19
|
+
Int8(value: any): value is number;
|
|
20
|
+
Int16(value: any): value is number;
|
|
21
|
+
Int32(value: any): value is number;
|
|
22
|
+
Int53(value: any): value is number;
|
|
23
|
+
UInt8(value: any): value is number;
|
|
24
|
+
UInt16(value: any): value is number;
|
|
25
|
+
UInt32(value: any): value is number;
|
|
26
|
+
UInt53(value: any): value is number;
|
|
27
|
+
arrayOf(type: any, options?: any): boolean;
|
|
28
|
+
maybe(type: any): boolean;
|
|
29
|
+
map(propertyType: any, propertyKeyType: any): boolean;
|
|
30
|
+
object(uncompiled: any): boolean;
|
|
31
|
+
anyOf(...args: any[]): (value: any) => boolean;
|
|
32
|
+
allOf(...args: any[]): boolean;
|
|
33
|
+
quacksLike<T>(type: T): type is T;
|
|
34
|
+
tuple(...args: any[]): boolean;
|
|
35
|
+
value(...expected: any[]): (value: any) => boolean;
|
|
36
|
+
compile(type: any): boolean;
|
|
37
|
+
}
|
|
38
|
+
const tf: Typeforce;
|
|
39
|
+
export = tf;
|
|
40
|
+
}
|
|
41
|
+
declare module 'bip66' {
|
|
42
|
+
function check(buffer: Buffer): boolean;
|
|
43
|
+
function decode(buffer: Buffer): {
|
|
44
|
+
r: Buffer;
|
|
45
|
+
s: Buffer;
|
|
46
|
+
};
|
|
47
|
+
function encode(r: Buffer, s: Buffer): Buffer;
|
|
48
|
+
}
|
|
49
|
+
declare module 'bitcoin-ops';
|
|
50
|
+
declare module 'minimaldata';
|
|
51
|
+
declare module 'tiny-secp256k1';
|
|
52
|
+
declare module 'pushdata-bitcoin' {
|
|
53
|
+
function encodingLength(len: number): number;
|
|
54
|
+
function encode(buffer: Buffer, number: number, offset: number): number;
|
|
55
|
+
function decode(buffer: Buffer, offset: number): {
|
|
56
|
+
opcode: number;
|
|
57
|
+
number: number;
|
|
58
|
+
size: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
declare module 'blake-hash';
|
|
62
|
+
//# sourceMappingURL=global.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as address from './address';
|
|
2
|
+
import * as bip32 from './bip32';
|
|
3
|
+
import * as bufferutils from './bufferutils';
|
|
4
|
+
import * as crypto from './crypto';
|
|
5
|
+
import * as payments from './payments';
|
|
6
|
+
import * as script from './script';
|
|
7
|
+
import * as networks from './networks';
|
|
8
|
+
import { composeTx } from './compose';
|
|
9
|
+
import { deriveAddresses, getXpubOrDescriptorInfo } from './derivation';
|
|
10
|
+
import { discovery } from './discovery';
|
|
11
|
+
export { Transaction } from './transaction';
|
|
12
|
+
export { address, bip32, bufferutils, crypto, payments, script, networks, composeTx, deriveAddresses, getXpubOrDescriptorInfo, discovery, };
|
|
13
|
+
export type { PaymentType } from './derivation';
|
|
14
|
+
export type { ComposeInput, ComposeOutput, ComposeChangeAddress, ComposeRequest, ComposeResult, ComposeResultNonFinal, ComposeResultError, ComposeResultFinal, ComposedTransaction, CoinSelectPaymentType, } from './types';
|
|
15
|
+
export type { Network } from './networks';
|
|
16
|
+
export type { BIP32Interface } from './bip32';
|
|
17
|
+
export type { TransactionInputOutputSortingStrategy } from './types/compose';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.discovery = exports.getXpubOrDescriptorInfo = exports.deriveAddresses = exports.composeTx = exports.networks = exports.script = exports.payments = exports.crypto = exports.bufferutils = exports.bip32 = exports.address = exports.Transaction = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const address = tslib_1.__importStar(require("./address"));
|
|
6
|
+
exports.address = address;
|
|
7
|
+
const bip32 = tslib_1.__importStar(require("./bip32"));
|
|
8
|
+
exports.bip32 = bip32;
|
|
9
|
+
const bufferutils = tslib_1.__importStar(require("./bufferutils"));
|
|
10
|
+
exports.bufferutils = bufferutils;
|
|
11
|
+
const crypto = tslib_1.__importStar(require("./crypto"));
|
|
12
|
+
exports.crypto = crypto;
|
|
13
|
+
const payments = tslib_1.__importStar(require("./payments"));
|
|
14
|
+
exports.payments = payments;
|
|
15
|
+
const script = tslib_1.__importStar(require("./script"));
|
|
16
|
+
exports.script = script;
|
|
17
|
+
const networks = tslib_1.__importStar(require("./networks"));
|
|
18
|
+
exports.networks = networks;
|
|
19
|
+
const compose_1 = require("./compose");
|
|
20
|
+
Object.defineProperty(exports, "composeTx", { enumerable: true, get: function () { return compose_1.composeTx; } });
|
|
21
|
+
const derivation_1 = require("./derivation");
|
|
22
|
+
Object.defineProperty(exports, "deriveAddresses", { enumerable: true, get: function () { return derivation_1.deriveAddresses; } });
|
|
23
|
+
Object.defineProperty(exports, "getXpubOrDescriptorInfo", { enumerable: true, get: function () { return derivation_1.getXpubOrDescriptorInfo; } });
|
|
24
|
+
const discovery_1 = require("./discovery");
|
|
25
|
+
Object.defineProperty(exports, "discovery", { enumerable: true, get: function () { return discovery_1.discovery; } });
|
|
26
|
+
var transaction_1 = require("./transaction");
|
|
27
|
+
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface Bip32 {
|
|
2
|
+
public: number;
|
|
3
|
+
private: number;
|
|
4
|
+
}
|
|
5
|
+
export interface Network {
|
|
6
|
+
messagePrefix: string;
|
|
7
|
+
bech32: string;
|
|
8
|
+
bip32: Bip32;
|
|
9
|
+
pubKeyHash: number;
|
|
10
|
+
scriptHash: number;
|
|
11
|
+
wif: number;
|
|
12
|
+
forkId?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const bitcoin: Network;
|
|
15
|
+
export declare const regtest: Network;
|
|
16
|
+
export declare const testnet: Network;
|
|
17
|
+
export declare const bitcoincash: Network;
|
|
18
|
+
export declare const bitcoincashTest: Network;
|
|
19
|
+
export declare const bitcoingold: Network;
|
|
20
|
+
export declare const litecoin: Network;
|
|
21
|
+
export declare const litecoinTest: Network;
|
|
22
|
+
export declare const dash: Network;
|
|
23
|
+
export declare const dashTest: Network;
|
|
24
|
+
export declare const zcash: Network;
|
|
25
|
+
export declare const zcashTest: Network;
|
|
26
|
+
export declare const peercoin: Network;
|
|
27
|
+
export declare const peercoinTest: Network;
|
|
28
|
+
export declare const komodo: Network;
|
|
29
|
+
export declare const decred: Network;
|
|
30
|
+
export declare const decredTest: Network;
|
|
31
|
+
export declare const decredSim: Network;
|
|
32
|
+
export declare const doge: Network;
|
|
33
|
+
declare const NETWORK_TYPES: {
|
|
34
|
+
bitcoinCash: Network[];
|
|
35
|
+
dash: Network[];
|
|
36
|
+
decred: Network[];
|
|
37
|
+
peercoin: Network[];
|
|
38
|
+
zcash: Network[];
|
|
39
|
+
litecoin: Network[];
|
|
40
|
+
doge: Network[];
|
|
41
|
+
};
|
|
42
|
+
export type NetworkTypes = keyof typeof NETWORK_TYPES;
|
|
43
|
+
export declare function isNetworkType(type: NetworkTypes, network?: Network): boolean;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=networks.d.ts.map
|