@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.
Files changed (229) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/accumulative.js +38 -0
  4. package/blackjack.js +35 -0
  5. package/break.js +34 -0
  6. package/index.js +21 -0
  7. package/package.json +82 -0
  8. package/split.js +45 -0
  9. package/third-party/utils/addDashesToSpaces.d.ts +2 -0
  10. package/third-party/utils/addDashesToSpaces.js +6 -0
  11. package/third-party/utils/arrayDistinct.d.ts +2 -0
  12. package/third-party/utils/arrayDistinct.js +6 -0
  13. package/third-party/utils/arrayPartition.d.ts +7 -0
  14. package/third-party/utils/arrayPartition.js +6 -0
  15. package/third-party/utils/arrayShuffle.d.ts +4 -0
  16. package/third-party/utils/arrayShuffle.js +13 -0
  17. package/third-party/utils/arrayToDictionary.d.ts +10 -0
  18. package/third-party/utils/arrayToDictionary.js +27 -0
  19. package/third-party/utils/asciiUtils.d.ts +3 -0
  20. package/third-party/utils/asciiUtils.js +16 -0
  21. package/third-party/utils/bigNumber.d.ts +5 -0
  22. package/third-party/utils/bigNumber.js +9 -0
  23. package/third-party/utils/bufferUtils.d.ts +3 -0
  24. package/third-party/utils/bufferUtils.js +23 -0
  25. package/third-party/utils/bytesToHumanReadable.d.ts +2 -0
  26. package/third-party/utils/bytesToHumanReadable.js +15 -0
  27. package/third-party/utils/capitalizeFirstLetter.d.ts +2 -0
  28. package/third-party/utils/capitalizeFirstLetter.js +6 -0
  29. package/third-party/utils/cloneObject.d.ts +2 -0
  30. package/third-party/utils/cloneObject.js +32 -0
  31. package/third-party/utils/countBytesInString.d.ts +2 -0
  32. package/third-party/utils/countBytesInString.js +6 -0
  33. package/third-party/utils/createCooldown.d.ts +2 -0
  34. package/third-party/utils/createCooldown.js +16 -0
  35. package/third-party/utils/createDeferred.d.ts +14 -0
  36. package/third-party/utils/createDeferred.js +19 -0
  37. package/third-party/utils/createDeferredManager.d.ts +19 -0
  38. package/third-party/utils/createDeferredManager.js +67 -0
  39. package/third-party/utils/createLazy.d.ts +7 -0
  40. package/third-party/utils/createLazy.js +42 -0
  41. package/third-party/utils/createTimeoutPromise.d.ts +2 -0
  42. package/third-party/utils/createTimeoutPromise.js +6 -0
  43. package/third-party/utils/enumUtils.d.ts +6 -0
  44. package/third-party/utils/enumUtils.js +12 -0
  45. package/third-party/utils/extractUrlsFromText.d.ts +5 -0
  46. package/third-party/utils/extractUrlsFromText.js +28 -0
  47. package/third-party/utils/getLocaleSeparators.d.ts +5 -0
  48. package/third-party/utils/getLocaleSeparators.js +13 -0
  49. package/third-party/utils/getLocaleSeparators.native.d.ts +5 -0
  50. package/third-party/utils/getLocaleSeparators.native.js +17 -0
  51. package/third-party/utils/getMutex.d.ts +2 -0
  52. package/third-party/utils/getMutex.js +22 -0
  53. package/third-party/utils/getNumberFromPixelString.d.ts +2 -0
  54. package/third-party/utils/getNumberFromPixelString.js +6 -0
  55. package/third-party/utils/getRandomInt.d.ts +2 -0
  56. package/third-party/utils/getRandomInt.js +56 -0
  57. package/third-party/utils/getSynchronize.d.ts +4 -0
  58. package/third-party/utils/getSynchronize.js +10 -0
  59. package/third-party/utils/getWeakRandomId.d.ts +2 -0
  60. package/third-party/utils/getWeakRandomId.js +13 -0
  61. package/third-party/utils/getWeakRandomInt.d.ts +2 -0
  62. package/third-party/utils/getWeakRandomInt.js +11 -0
  63. package/third-party/utils/getWeakRandomNumberInRange.d.ts +2 -0
  64. package/third-party/utils/getWeakRandomNumberInRange.js +6 -0
  65. package/third-party/utils/hasUppercaseLetter.d.ts +2 -0
  66. package/third-party/utils/hasUppercaseLetter.js +7 -0
  67. package/third-party/utils/index.d.ts +52 -0
  68. package/third-party/utils/index.js +56 -0
  69. package/third-party/utils/isArrayMember.d.ts +2 -0
  70. package/third-party/utils/isArrayMember.js +6 -0
  71. package/third-party/utils/isFullPath.d.ts +2 -0
  72. package/third-party/utils/isFullPath.js +9 -0
  73. package/third-party/utils/isHex.d.ts +2 -0
  74. package/third-party/utils/isHex.js +9 -0
  75. package/third-party/utils/isNotUndefined.d.ts +2 -0
  76. package/third-party/utils/isNotUndefined.js +6 -0
  77. package/third-party/utils/isUrl.d.ts +2 -0
  78. package/third-party/utils/isUrl.js +7 -0
  79. package/third-party/utils/logs.d.ts +32 -0
  80. package/third-party/utils/logs.js +82 -0
  81. package/third-party/utils/logsManager.d.ts +17 -0
  82. package/third-party/utils/logsManager.js +53 -0
  83. package/third-party/utils/mergeDeepObject.d.ts +26 -0
  84. package/third-party/utils/mergeDeepObject.js +68 -0
  85. package/third-party/utils/objectPartition.d.ts +6 -0
  86. package/third-party/utils/objectPartition.js +12 -0
  87. package/third-party/utils/parseElectrumUrl.d.ts +6 -0
  88. package/third-party/utils/parseElectrumUrl.js +17 -0
  89. package/third-party/utils/parseHostname.d.ts +2 -0
  90. package/third-party/utils/parseHostname.js +7 -0
  91. package/third-party/utils/promiseAllSequence.d.ts +2 -0
  92. package/third-party/utils/promiseAllSequence.js +14 -0
  93. package/third-party/utils/redactUserPath.d.ts +3 -0
  94. package/third-party/utils/redactUserPath.js +7 -0
  95. package/third-party/utils/scheduleAction.d.ts +15 -0
  96. package/third-party/utils/scheduleAction.js +125 -0
  97. package/third-party/utils/splitStringEveryNCharacters.d.ts +2 -0
  98. package/third-party/utils/splitStringEveryNCharacters.js +12 -0
  99. package/third-party/utils/throttler.d.ts +11 -0
  100. package/third-party/utils/throttler.js +38 -0
  101. package/third-party/utils/throwError.d.ts +2 -0
  102. package/third-party/utils/throwError.js +8 -0
  103. package/third-party/utils/topologicalSort.d.ts +2 -0
  104. package/third-party/utils/topologicalSort.js +19 -0
  105. package/third-party/utils/truncateMiddle.d.ts +2 -0
  106. package/third-party/utils/truncateMiddle.js +12 -0
  107. package/third-party/utils/typedEventEmitter.d.ts +23 -0
  108. package/third-party/utils/typedEventEmitter.js +11 -0
  109. package/third-party/utils/urlToOnion.d.ts +4 -0
  110. package/third-party/utils/urlToOnion.js +12 -0
  111. package/third-party/utils/versionUtils.d.ts +9 -0
  112. package/third-party/utils/versionUtils.js +28 -0
  113. package/third-party/utils/xssFilters.d.ts +4 -0
  114. package/third-party/utils/xssFilters.js +13 -0
  115. package/third-party/utxo-lib/address.d.ts +17 -0
  116. package/third-party/utxo-lib/address.js +174 -0
  117. package/third-party/utxo-lib/bip32.d.ts +28 -0
  118. package/third-party/utxo-lib/bip32.js +253 -0
  119. package/third-party/utxo-lib/bs58check.d.ts +12 -0
  120. package/third-party/utxo-lib/bs58check.js +92 -0
  121. package/third-party/utxo-lib/bufferutils.d.ts +59 -0
  122. package/third-party/utxo-lib/bufferutils.js +219 -0
  123. package/third-party/utxo-lib/coinselect/coinselectUtils.d.ts +53 -0
  124. package/third-party/utxo-lib/coinselect/coinselectUtils.js +232 -0
  125. package/third-party/utxo-lib/coinselect/index.d.ts +3 -0
  126. package/third-party/utxo-lib/coinselect/index.js +19 -0
  127. package/third-party/utxo-lib/coinselect/inputs/accumulative.d.ts +3 -0
  128. package/third-party/utxo-lib/coinselect/inputs/accumulative.js +55 -0
  129. package/third-party/utxo-lib/coinselect/inputs/branchAndBound.d.ts +3 -0
  130. package/third-party/utxo-lib/coinselect/inputs/branchAndBound.js +123 -0
  131. package/third-party/utxo-lib/coinselect/outputs/split.d.ts +3 -0
  132. package/third-party/utxo-lib/coinselect/outputs/split.js +35 -0
  133. package/third-party/utxo-lib/coinselect/tryconfirmed.d.ts +3 -0
  134. package/third-party/utxo-lib/coinselect/tryconfirmed.js +65 -0
  135. package/third-party/utxo-lib/compose/index.d.ts +3 -0
  136. package/third-party/utxo-lib/compose/index.js +20 -0
  137. package/third-party/utxo-lib/compose/request.d.ts +5 -0
  138. package/third-party/utxo-lib/compose/request.js +168 -0
  139. package/third-party/utxo-lib/compose/result.d.ts +4 -0
  140. package/third-party/utxo-lib/compose/result.js +64 -0
  141. package/third-party/utxo-lib/compose/sorting/bip69SortingStrategy.d.ts +3 -0
  142. package/third-party/utxo-lib/compose/sorting/bip69SortingStrategy.js +32 -0
  143. package/third-party/utxo-lib/compose/sorting/convertOutput.d.ts +13 -0
  144. package/third-party/utxo-lib/compose/sorting/convertOutput.js +14 -0
  145. package/third-party/utxo-lib/compose/sorting/noneSortingStrategy.d.ts +3 -0
  146. package/third-party/utxo-lib/compose/sorting/noneSortingStrategy.js +19 -0
  147. package/third-party/utxo-lib/compose/sorting/randomSortingStrategy.d.ts +3 -0
  148. package/third-party/utxo-lib/compose/sorting/randomSortingStrategy.js +28 -0
  149. package/third-party/utxo-lib/compose/sorting/sortingStrategy.d.ts +9 -0
  150. package/third-party/utxo-lib/compose/sorting/sortingStrategy.js +3 -0
  151. package/third-party/utxo-lib/compose/transaction.d.ts +3 -0
  152. package/third-party/utxo-lib/compose/transaction.js +16 -0
  153. package/third-party/utxo-lib/crypto.d.ts +9 -0
  154. package/third-party/utxo-lib/crypto.js +44 -0
  155. package/third-party/utxo-lib/derivation.d.ts +24 -0
  156. package/third-party/utxo-lib/derivation.js +121 -0
  157. package/third-party/utxo-lib/discovery.d.ts +9 -0
  158. package/third-party/utxo-lib/discovery.js +30 -0
  159. package/third-party/utxo-lib/global.d.ts +62 -0
  160. package/third-party/utxo-lib/global.js +2 -0
  161. package/third-party/utxo-lib/index.d.ts +18 -0
  162. package/third-party/utxo-lib/index.js +28 -0
  163. package/third-party/utxo-lib/networks.d.ts +45 -0
  164. package/third-party/utxo-lib/networks.js +250 -0
  165. package/third-party/utxo-lib/payments/embed.d.ts +3 -0
  166. package/third-party/utxo-lib/payments/embed.js +49 -0
  167. package/third-party/utxo-lib/payments/index.d.ts +13 -0
  168. package/third-party/utxo-lib/payments/index.js +28 -0
  169. package/third-party/utxo-lib/payments/lazy.d.ts +3 -0
  170. package/third-party/utxo-lib/payments/lazy.js +33 -0
  171. package/third-party/utxo-lib/payments/p2ms.d.ts +3 -0
  172. package/third-party/utxo-lib/payments/p2ms.js +139 -0
  173. package/third-party/utxo-lib/payments/p2pk.d.ts +3 -0
  174. package/third-party/utxo-lib/payments/p2pk.js +72 -0
  175. package/third-party/utxo-lib/payments/p2pkh.d.ts +3 -0
  176. package/third-party/utxo-lib/payments/p2pkh.js +132 -0
  177. package/third-party/utxo-lib/payments/p2sh.d.ts +3 -0
  178. package/third-party/utxo-lib/payments/p2sh.js +171 -0
  179. package/third-party/utxo-lib/payments/p2tr.d.ts +3 -0
  180. package/third-party/utxo-lib/payments/p2tr.js +123 -0
  181. package/third-party/utxo-lib/payments/p2wpkh.d.ts +3 -0
  182. package/third-party/utxo-lib/payments/p2wpkh.js +137 -0
  183. package/third-party/utxo-lib/payments/p2wsh.d.ts +3 -0
  184. package/third-party/utxo-lib/payments/p2wsh.js +183 -0
  185. package/third-party/utxo-lib/payments/sstxchange.d.ts +3 -0
  186. package/third-party/utxo-lib/payments/sstxchange.js +79 -0
  187. package/third-party/utxo-lib/payments/sstxcommitment.d.ts +3 -0
  188. package/third-party/utxo-lib/payments/sstxcommitment.js +74 -0
  189. package/third-party/utxo-lib/payments/sstxpkh.d.ts +3 -0
  190. package/third-party/utxo-lib/payments/sstxpkh.js +79 -0
  191. package/third-party/utxo-lib/payments/sstxsh.d.ts +3 -0
  192. package/third-party/utxo-lib/payments/sstxsh.js +70 -0
  193. package/third-party/utxo-lib/script/index.d.ts +17 -0
  194. package/third-party/utxo-lib/script/index.js +167 -0
  195. package/third-party/utxo-lib/script/ops.d.ts +4 -0
  196. package/third-party/utxo-lib/script/ops.js +13 -0
  197. package/third-party/utxo-lib/script/scriptNumber.d.ts +3 -0
  198. package/third-party/utxo-lib/script/scriptNumber.js +62 -0
  199. package/third-party/utxo-lib/script/scriptSignature.d.ts +8 -0
  200. package/third-party/utxo-lib/script/scriptSignature.js +55 -0
  201. package/third-party/utxo-lib/transaction/base.d.ts +56 -0
  202. package/third-party/utxo-lib/transaction/base.js +108 -0
  203. package/third-party/utxo-lib/transaction/bitcoin.d.ts +4 -0
  204. package/third-party/utxo-lib/transaction/bitcoin.js +109 -0
  205. package/third-party/utxo-lib/transaction/dash.d.ts +8 -0
  206. package/third-party/utxo-lib/transaction/dash.js +105 -0
  207. package/third-party/utxo-lib/transaction/decred.d.ts +4 -0
  208. package/third-party/utxo-lib/transaction/decred.js +149 -0
  209. package/third-party/utxo-lib/transaction/index.d.ts +15 -0
  210. package/third-party/utxo-lib/transaction/index.js +44 -0
  211. package/third-party/utxo-lib/transaction/peercoin.d.ts +4 -0
  212. package/third-party/utxo-lib/transaction/peercoin.js +64 -0
  213. package/third-party/utxo-lib/transaction/zcash.d.ts +66 -0
  214. package/third-party/utxo-lib/transaction/zcash.js +451 -0
  215. package/third-party/utxo-lib/types/coinselect.d.ts +61 -0
  216. package/third-party/utxo-lib/types/coinselect.js +3 -0
  217. package/third-party/utxo-lib/types/compose.d.ts +98 -0
  218. package/third-party/utxo-lib/types/compose.js +10 -0
  219. package/third-party/utxo-lib/types/index.d.ts +5 -0
  220. package/third-party/utxo-lib/types/index.js +8 -0
  221. package/third-party/utxo-lib/types/payments.d.ts +30 -0
  222. package/third-party/utxo-lib/types/payments.js +3 -0
  223. package/third-party/utxo-lib/types/typeforce.d.ts +8 -0
  224. package/third-party/utxo-lib/types/typeforce.js +16 -0
  225. package/third-party/utxo-lib/vsize.d.ts +13 -0
  226. package/third-party/utxo-lib/vsize.js +50 -0
  227. package/utils.js +78 -0
  228. package/witness.d.ts +70 -0
  229. package/witness.js +30 -0
@@ -0,0 +1,23 @@
1
+ import { EventEmitter } from 'events';
2
+ type EventMap = Record<string, any>;
3
+ type EventKey<T extends EventMap> = string & keyof T;
4
+ type IsUnion<T, U extends T = T> = T extends unknown ? ([U] extends [T] ? 0 : 1) : 2;
5
+ type EventReceiver<T> = IsUnion<T> extends 1 ? (event: T) => void : T extends (...args: any[]) => any ? T : T extends undefined ? () => void : (event: T) => void;
6
+ export interface TypedEmitter<T extends EventMap> {
7
+ on<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
8
+ once<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
9
+ addListener<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
10
+ prependListener<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
11
+ prependOnceListener<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
12
+ off<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
13
+ removeListener<K extends EventKey<T>>(eventName: K, fn: EventReceiver<T[K]>): this;
14
+ removeAllListeners<K extends EventKey<T>>(event?: K): this;
15
+ emit<K extends EventKey<T>>(eventName: K, ...params: Parameters<EventReceiver<T[K]>>): boolean;
16
+ listeners<K extends EventKey<T>>(eventName: K): EventReceiver<T[K]>[];
17
+ rawListeners<K extends EventKey<T>>(eventName: K): EventReceiver<T[K]>[];
18
+ }
19
+ export declare class TypedEmitter<T extends EventMap> extends EventEmitter {
20
+ listenerCount<K extends EventKey<T>>(eventName: K): number;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=typedEventEmitter.d.ts.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypedEmitter = void 0;
4
+ const events_1 = require("events");
5
+ class TypedEmitter extends events_1.EventEmitter {
6
+ listenerCount(eventName) {
7
+ return super.listenerCount(eventName);
8
+ }
9
+ }
10
+ exports.TypedEmitter = TypedEmitter;
11
+ //# sourceMappingURL=typedEventEmitter.js.map
@@ -0,0 +1,4 @@
1
+ export declare const urlToOnion: (url: string, onionDomains: {
2
+ [domain: string]: string;
3
+ }) => string | undefined;
4
+ //# sourceMappingURL=urlToOnion.d.ts.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlToOnion = void 0;
4
+ const urlToOnion = (url, onionDomains) => {
5
+ var _a;
6
+ const [, protocol, subdomain, domain, rest] = (_a = url.match(/^(http|ws)s?:\/\/([^:/]+\.)?([^/.]+\.[^/.]+)(\/.*)?$/i)) !== null && _a !== void 0 ? _a : [];
7
+ if (!domain || !onionDomains[domain])
8
+ return;
9
+ return `${protocol}://${subdomain !== null && subdomain !== void 0 ? subdomain : ''}${onionDomains[domain]}${rest !== null && rest !== void 0 ? rest : ''}`;
10
+ };
11
+ exports.urlToOnion = urlToOnion;
12
+ //# sourceMappingURL=urlToOnion.js.map
@@ -0,0 +1,9 @@
1
+ type VersionArray = [number, number, number];
2
+ type VersionInput = VersionArray | string;
3
+ export declare const isVersionArray: (arr: unknown) => arr is VersionArray;
4
+ export declare const isNewer: (versionX: VersionInput, versionY: VersionInput) => boolean;
5
+ export declare const isEqual: (versionX: VersionInput, versionY: VersionInput) => boolean;
6
+ export declare const isNewerOrEqual: (versionX: VersionInput, versionY: VersionInput) => boolean;
7
+ export declare const normalizeVersion: (version: string) => string;
8
+ export {};
9
+ //# sourceMappingURL=versionUtils.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeVersion = exports.isNewerOrEqual = exports.isEqual = exports.isNewer = exports.isVersionArray = void 0;
4
+ const throwError_1 = require("./throwError");
5
+ const isVersionArray = (arr) => Array.isArray(arr) &&
6
+ arr.length === 3 &&
7
+ arr.every(number => typeof number === 'number' && number >= 0);
8
+ exports.isVersionArray = isVersionArray;
9
+ const tryParse = (version) => {
10
+ var _a;
11
+ return (_a = version
12
+ .match(/^(\d+)\.(\d+)\.(\d+)([+-].*)?$/)) === null || _a === void 0 ? void 0 : _a.slice(1, 4).map(n => Number(n));
13
+ };
14
+ const validateArray = (version) => ((0, exports.isVersionArray)(version) ? version : null);
15
+ const ensureArray = (version) => {
16
+ var _a;
17
+ return (_a = (typeof version === 'string' ? tryParse(version) : validateArray(version))) !== null && _a !== void 0 ? _a : (0, throwError_1.throwError)(`version string is in wrong format: ${version}`);
18
+ };
19
+ const compare = ([majorX, minorX, patchX], [majorY, minorY, patchY]) => majorX - majorY || minorX - minorY || patchX - patchY;
20
+ const isNewer = (versionX, versionY) => compare(ensureArray(versionX), ensureArray(versionY)) > 0;
21
+ exports.isNewer = isNewer;
22
+ const isEqual = (versionX, versionY) => compare(ensureArray(versionX), ensureArray(versionY)) === 0;
23
+ exports.isEqual = isEqual;
24
+ const isNewerOrEqual = (versionX, versionY) => compare(ensureArray(versionX), ensureArray(versionY)) >= 0;
25
+ exports.isNewerOrEqual = isNewerOrEqual;
26
+ const normalizeVersion = (version) => version.replace(/\b0+(\d)/g, '$1');
27
+ exports.normalizeVersion = normalizeVersion;
28
+ //# sourceMappingURL=versionUtils.js.map
@@ -0,0 +1,4 @@
1
+ export declare const inHTML: (value: string) => string;
2
+ export declare const inSingleQuotes: (value: string) => string;
3
+ export declare const inDoubleQuotes: (value: string) => string;
4
+ //# sourceMappingURL=xssFilters.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inDoubleQuotes = exports.inSingleQuotes = exports.inHTML = void 0;
4
+ const LT = /</g;
5
+ const SQUOT = /'/g;
6
+ const QUOT = /"/g;
7
+ const inHTML = (value) => value.replace(LT, '&lt;');
8
+ exports.inHTML = inHTML;
9
+ const inSingleQuotes = (value) => value.replace(SQUOT, '&#39;');
10
+ exports.inSingleQuotes = inSingleQuotes;
11
+ const inDoubleQuotes = (value) => value.replace(QUOT, '&quot;');
12
+ exports.inDoubleQuotes = inDoubleQuotes;
13
+ //# sourceMappingURL=xssFilters.js.map
@@ -0,0 +1,17 @@
1
+ import { Network } from './networks';
2
+ export interface Base58CheckResult {
3
+ hash: Buffer;
4
+ version: number;
5
+ }
6
+ export interface Bech32Result {
7
+ version: number;
8
+ prefix: string;
9
+ data: Buffer;
10
+ }
11
+ export declare function fromBase58Check(address: string, network?: Network): Base58CheckResult;
12
+ export declare function fromBech32(address: string): Bech32Result;
13
+ export declare function toBech32(data: Buffer, version: number, prefix: string): string;
14
+ export declare function fromOutputScript(output: Buffer, network?: Network): string;
15
+ export declare function getAddressType(address: string, network?: Network): "p2pkh" | "p2sh" | "p2tr" | "p2wpkh" | "p2wsh" | "p2w-unknown" | "unknown";
16
+ export declare function toOutputScript(address: string, network?: Network): Buffer;
17
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromBase58Check = fromBase58Check;
4
+ exports.fromBech32 = fromBech32;
5
+ exports.toBech32 = toBech32;
6
+ exports.fromOutputScript = fromOutputScript;
7
+ exports.getAddressType = getAddressType;
8
+ exports.toOutputScript = toOutputScript;
9
+ const tslib_1 = require("tslib");
10
+ const bech32_1 = require("bech32");
11
+ const bs58check = tslib_1.__importStar(require("./bs58check"));
12
+ const bscript = tslib_1.__importStar(require("./script"));
13
+ const payments = tslib_1.__importStar(require("./payments"));
14
+ const networks_1 = require("./networks");
15
+ function fromBase58Check(address, network = networks_1.bitcoin) {
16
+ return bs58check.decodeAddress(address, network);
17
+ }
18
+ function fromBech32(address) {
19
+ let result;
20
+ let version;
21
+ try {
22
+ result = bech32_1.bech32.decode(address);
23
+ }
24
+ catch (_a) {
25
+ }
26
+ if (result) {
27
+ [version] = result.words;
28
+ if (version !== 0)
29
+ throw new TypeError(`${address} uses wrong encoding`);
30
+ }
31
+ else {
32
+ result = bech32_1.bech32m.decode(address);
33
+ [version] = result.words;
34
+ if (version === 0)
35
+ throw new TypeError(`${address} uses wrong encoding`);
36
+ }
37
+ const data = bech32_1.bech32.fromWords(result.words.slice(1));
38
+ return {
39
+ version,
40
+ prefix: result.prefix,
41
+ data: Buffer.from(data),
42
+ };
43
+ }
44
+ function toBech32(data, version, prefix) {
45
+ const words = bech32_1.bech32.toWords(data);
46
+ words.unshift(version);
47
+ return version === 0 ? bech32_1.bech32.encode(prefix, words) : bech32_1.bech32m.encode(prefix, words);
48
+ }
49
+ const FUTURE_SEGWIT_MAX_SIZE = 40;
50
+ const FUTURE_SEGWIT_MIN_SIZE = 2;
51
+ const FUTURE_SEGWIT_MAX_VERSION = 16;
52
+ const FUTURE_SEGWIT_MIN_VERSION = 1;
53
+ const FUTURE_SEGWIT_VERSION_DIFF = 0x50;
54
+ function toFutureSegwitAddress(output, network = networks_1.bitcoin) {
55
+ const data = output.subarray(2);
56
+ if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE)
57
+ throw new TypeError('Invalid program length for segwit address');
58
+ const version = output[0] - FUTURE_SEGWIT_VERSION_DIFF;
59
+ if (version < FUTURE_SEGWIT_MIN_VERSION || version > FUTURE_SEGWIT_MAX_VERSION)
60
+ throw new TypeError('Invalid version for segwit address');
61
+ if (output[1] !== data.length)
62
+ throw new TypeError('Invalid script for segwit address');
63
+ return toBech32(data, version, network.bech32);
64
+ }
65
+ function fromOutputScript(output, network = networks_1.bitcoin) {
66
+ try {
67
+ return payments.p2pkh({ output, network }).address;
68
+ }
69
+ catch (_a) {
70
+ }
71
+ try {
72
+ return payments.p2sh({ output, network }).address;
73
+ }
74
+ catch (_b) {
75
+ }
76
+ try {
77
+ return payments.p2wpkh({ output, network }).address;
78
+ }
79
+ catch (_c) {
80
+ }
81
+ try {
82
+ return payments.p2wsh({ output, network }).address;
83
+ }
84
+ catch (_d) {
85
+ }
86
+ try {
87
+ return payments.p2tr({ output, network }).address;
88
+ }
89
+ catch (_e) {
90
+ }
91
+ try {
92
+ return toFutureSegwitAddress(output, network);
93
+ }
94
+ catch (_f) {
95
+ }
96
+ throw new Error(`${bscript.toASM(output)} has no matching Address`);
97
+ }
98
+ function decodeAddress(address, network) {
99
+ try {
100
+ const { hash, version } = fromBase58Check(address, network);
101
+ return { success: true, format: 'base58', version, hash };
102
+ }
103
+ catch (_a) {
104
+ try {
105
+ const { data, prefix, version } = fromBech32(address);
106
+ if (prefix === network.bech32) {
107
+ return { success: true, format: 'bech32', version, hash: data };
108
+ }
109
+ return { success: false, error: 'bech32-invalid-prefix' };
110
+ }
111
+ catch (_b) {
112
+ }
113
+ }
114
+ return { success: false, error: 'unknown-format' };
115
+ }
116
+ function identifyAddressType(format, version, hash, network) {
117
+ if (format === 'base58') {
118
+ if (version === network.pubKeyHash)
119
+ return 'p2pkh';
120
+ if (version === network.scriptHash)
121
+ return 'p2sh';
122
+ }
123
+ else if (format === 'bech32') {
124
+ if (version === 0) {
125
+ if (hash.length === 20)
126
+ return 'p2wpkh';
127
+ if (hash.length === 32)
128
+ return 'p2wsh';
129
+ }
130
+ else if (version === 1 && hash.length === 32) {
131
+ return 'p2tr';
132
+ }
133
+ else if (version >= FUTURE_SEGWIT_MIN_VERSION &&
134
+ version <= FUTURE_SEGWIT_MAX_VERSION &&
135
+ hash.length >= FUTURE_SEGWIT_MIN_SIZE &&
136
+ hash.length <= FUTURE_SEGWIT_MAX_SIZE) {
137
+ return 'p2w-unknown';
138
+ }
139
+ }
140
+ return 'unknown';
141
+ }
142
+ function createOutputScript(type, hash, version) {
143
+ switch (type) {
144
+ case 'p2pkh':
145
+ return payments.p2pkh({ hash }).output;
146
+ case 'p2sh':
147
+ return payments.p2sh({ hash }).output;
148
+ case 'p2wpkh':
149
+ return payments.p2wpkh({ hash }).output;
150
+ case 'p2wsh':
151
+ return payments.p2wsh({ hash }).output;
152
+ case 'p2tr':
153
+ case 'p2w-unknown':
154
+ return bscript.compile([version + FUTURE_SEGWIT_VERSION_DIFF, hash]);
155
+ }
156
+ }
157
+ function getAddressType(address, network = networks_1.bitcoin) {
158
+ const { success, format, version, hash } = decodeAddress(address, network);
159
+ return success ? identifyAddressType(format, version, hash, network) : 'unknown';
160
+ }
161
+ function toOutputScript(address, network = networks_1.bitcoin) {
162
+ const { success, format, version, hash, error } = decodeAddress(address, network);
163
+ if (success) {
164
+ const type = identifyAddressType(format, version, hash, network);
165
+ if (type !== 'unknown') {
166
+ return createOutputScript(type, hash, version);
167
+ }
168
+ }
169
+ else if (error === 'bech32-invalid-prefix') {
170
+ throw new Error(`${address} has an invalid prefix`);
171
+ }
172
+ throw new Error(`${address} has no matching Script`);
173
+ }
174
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1,28 @@
1
+ import type { Network } from './networks';
2
+ export interface BIP32Interface {
3
+ chainCode: Buffer;
4
+ network: Network;
5
+ lowR: boolean;
6
+ depth: number;
7
+ index: number;
8
+ parentFingerprint: number;
9
+ publicKey: Buffer;
10
+ privateKey?: Buffer;
11
+ identifier: Buffer;
12
+ fingerprint: Buffer;
13
+ compressed: boolean;
14
+ isNeutered(): boolean;
15
+ neutered(): BIP32Interface;
16
+ toBase58(): string;
17
+ toWIF(): string;
18
+ derive(index: number): BIP32Interface;
19
+ deriveHardened(index: number): BIP32Interface;
20
+ derivePath(path: string): BIP32Interface;
21
+ sign(hash: Buffer, lowR?: boolean): Buffer;
22
+ verify(hash: Buffer, signature: Buffer): boolean;
23
+ }
24
+ export declare function fromBase58(inString: string, network?: Network): BIP32Interface;
25
+ export declare function fromPrivateKey(privateKey: Buffer, chainCode: Buffer, network?: Network): BIP32Interface;
26
+ export declare function fromPublicKey(publicKey: Buffer, chainCode: Buffer, network?: Network): BIP32Interface;
27
+ export declare function fromSeed(seed: Buffer, network?: Network): BIP32Interface;
28
+ //# sourceMappingURL=bip32.d.ts.map
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromBase58 = fromBase58;
4
+ exports.fromPrivateKey = fromPrivateKey;
5
+ exports.fromPublicKey = fromPublicKey;
6
+ exports.fromSeed = fromSeed;
7
+ const tslib_1 = require("tslib");
8
+ const tiny_secp256k1_1 = tslib_1.__importDefault(require("tiny-secp256k1"));
9
+ const wif = tslib_1.__importStar(require("wif"));
10
+ const typeforce_1 = require("./types/typeforce");
11
+ const bs58check = tslib_1.__importStar(require("./bs58check"));
12
+ const crypto = tslib_1.__importStar(require("./crypto"));
13
+ const networks_1 = require("./networks");
14
+ const UINT256_TYPE = typeforce_1.typeforce.BufferN(32);
15
+ const NETWORK_TYPE = typeforce_1.typeforce.compile({
16
+ wif: typeforce_1.typeforce.UInt8,
17
+ bip32: {
18
+ public: typeforce_1.typeforce.UInt32,
19
+ private: typeforce_1.typeforce.UInt32,
20
+ },
21
+ });
22
+ const HIGHEST_BIT = 0x80000000;
23
+ const UINT31_MAX = Math.pow(2, 31) - 1;
24
+ function BIP32Path(value) {
25
+ return typeforce_1.typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) !== null;
26
+ }
27
+ function UInt31(value) {
28
+ return typeforce_1.typeforce.UInt32(value) && value <= UINT31_MAX;
29
+ }
30
+ function fromPrivateKeyLocal(privateKey, chainCode, network, depth, index, parentFingerprint) {
31
+ (0, typeforce_1.typeforce)({
32
+ privateKey: UINT256_TYPE,
33
+ chainCode: UINT256_TYPE,
34
+ }, { privateKey, chainCode });
35
+ network = network || networks_1.bitcoin;
36
+ if (!tiny_secp256k1_1.default.isPrivate(privateKey))
37
+ throw new TypeError('Private key not in range [1, n)');
38
+ return new BIP32(privateKey, undefined, chainCode, network, depth, index, parentFingerprint);
39
+ }
40
+ function fromPublicKeyLocal(publicKey, chainCode, network, depth, index, parentFingerprint) {
41
+ (0, typeforce_1.typeforce)({
42
+ publicKey: typeforce_1.typeforce.BufferN(33),
43
+ chainCode: UINT256_TYPE,
44
+ }, { publicKey, chainCode });
45
+ network = network || networks_1.bitcoin;
46
+ if (!tiny_secp256k1_1.default.isPoint(publicKey))
47
+ throw new TypeError('Point is not on the curve');
48
+ return new BIP32(undefined, publicKey, chainCode, network, depth, index, parentFingerprint);
49
+ }
50
+ class BIP32 {
51
+ constructor(__D, __Q, chainCode, network, __DEPTH = 0, __INDEX = 0, __PARENT_FINGERPRINT = 0x00000000) {
52
+ this.__D = __D;
53
+ this.__Q = __Q;
54
+ this.chainCode = chainCode;
55
+ this.network = network;
56
+ this.__DEPTH = __DEPTH;
57
+ this.__INDEX = __INDEX;
58
+ this.__PARENT_FINGERPRINT = __PARENT_FINGERPRINT;
59
+ (0, typeforce_1.typeforce)(NETWORK_TYPE, network);
60
+ this.lowR = false;
61
+ }
62
+ get depth() {
63
+ return this.__DEPTH;
64
+ }
65
+ get index() {
66
+ return this.__INDEX;
67
+ }
68
+ get parentFingerprint() {
69
+ return this.__PARENT_FINGERPRINT;
70
+ }
71
+ get publicKey() {
72
+ if (this.__Q === undefined)
73
+ this.__Q = tiny_secp256k1_1.default.pointFromScalar(this.__D, true);
74
+ return this.__Q;
75
+ }
76
+ get privateKey() {
77
+ return this.__D;
78
+ }
79
+ get identifier() {
80
+ if ((0, networks_1.isNetworkType)('decred', this.network))
81
+ return crypto.hash160blake256(this.publicKey);
82
+ return crypto.hash160(this.publicKey);
83
+ }
84
+ get fingerprint() {
85
+ return this.identifier.subarray(0, 4);
86
+ }
87
+ get compressed() {
88
+ return true;
89
+ }
90
+ isNeutered() {
91
+ return this.__D === undefined;
92
+ }
93
+ neutered() {
94
+ return fromPublicKeyLocal(this.publicKey, this.chainCode, this.network, this.depth, this.index, this.parentFingerprint);
95
+ }
96
+ toBase58() {
97
+ const { network } = this;
98
+ const version = !this.isNeutered() ? network.bip32.private : network.bip32.public;
99
+ const buffer = Buffer.allocUnsafe(78);
100
+ buffer.writeUInt32BE(version, 0);
101
+ buffer.writeUInt8(this.depth, 4);
102
+ buffer.writeUInt32BE(this.parentFingerprint, 5);
103
+ buffer.writeUInt32BE(this.index, 9);
104
+ this.chainCode.copy(buffer, 13);
105
+ if (!this.isNeutered()) {
106
+ buffer.writeUInt8(0, 45);
107
+ this.privateKey.copy(buffer, 46);
108
+ }
109
+ else {
110
+ this.publicKey.copy(buffer, 45);
111
+ }
112
+ return bs58check.encode(buffer, network);
113
+ }
114
+ toWIF() {
115
+ if (!this.privateKey)
116
+ throw new TypeError('Missing private key');
117
+ return wif.encode({
118
+ version: this.network.wif,
119
+ privateKey: this.privateKey,
120
+ compressed: true,
121
+ });
122
+ }
123
+ derive(index) {
124
+ (0, typeforce_1.typeforce)(typeforce_1.typeforce.UInt32, index);
125
+ const isHardened = index >= HIGHEST_BIT;
126
+ const data = Buffer.allocUnsafe(37);
127
+ if (isHardened) {
128
+ if (this.isNeutered())
129
+ throw new TypeError('Missing private key for hardened child key');
130
+ data[0] = 0x00;
131
+ this.privateKey.copy(data, 1);
132
+ data.writeUInt32BE(index, 33);
133
+ }
134
+ else {
135
+ this.publicKey.copy(data, 0);
136
+ data.writeUInt32BE(index, 33);
137
+ }
138
+ const I = crypto.hmacSHA512(this.chainCode, data);
139
+ const IL = I.subarray(0, 32);
140
+ const IR = I.subarray(32);
141
+ if (!tiny_secp256k1_1.default.isPrivate(IL))
142
+ return this.derive(index + 1);
143
+ let hd;
144
+ if (!this.isNeutered()) {
145
+ const ki = tiny_secp256k1_1.default.privateAdd(this.privateKey, IL);
146
+ if (ki == null)
147
+ return this.derive(index + 1);
148
+ hd = fromPrivateKeyLocal(ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0));
149
+ }
150
+ else {
151
+ const Ki = tiny_secp256k1_1.default.pointAddScalar(this.publicKey, IL, true);
152
+ if (Ki === null)
153
+ return this.derive(index + 1);
154
+ hd = fromPublicKeyLocal(Ki, IR, this.network, this.depth + 1, index, this.fingerprint.readUInt32BE(0));
155
+ }
156
+ return hd;
157
+ }
158
+ deriveHardened(index) {
159
+ (0, typeforce_1.typeforce)(UInt31, index);
160
+ return this.derive(index + HIGHEST_BIT);
161
+ }
162
+ derivePath(path) {
163
+ (0, typeforce_1.typeforce)(BIP32Path, path);
164
+ let splitPath = path.split('/');
165
+ if (splitPath[0] === 'm') {
166
+ if (this.parentFingerprint)
167
+ throw new TypeError('Expected master, got child');
168
+ splitPath = splitPath.slice(1);
169
+ }
170
+ return splitPath.reduce((prevHd, indexStr) => {
171
+ let index;
172
+ if (indexStr.slice(-1) === `'`) {
173
+ index = parseInt(indexStr.slice(0, -1), 10);
174
+ return prevHd.deriveHardened(index);
175
+ }
176
+ index = parseInt(indexStr, 10);
177
+ return prevHd.derive(index);
178
+ }, this);
179
+ }
180
+ sign(hash, lowR) {
181
+ if (!this.privateKey)
182
+ throw new Error('Missing private key');
183
+ if (lowR === undefined)
184
+ lowR = this.lowR;
185
+ if (lowR === false) {
186
+ return tiny_secp256k1_1.default.sign(hash, this.privateKey);
187
+ }
188
+ let sig = tiny_secp256k1_1.default.sign(hash, this.privateKey);
189
+ const extraData = Buffer.alloc(32, 0);
190
+ let counter = 0;
191
+ while (sig[0] > 0x7f) {
192
+ counter++;
193
+ extraData.writeUIntLE(counter, 0, 6);
194
+ sig = tiny_secp256k1_1.default.signWithEntropy(hash, this.privateKey, extraData);
195
+ }
196
+ return sig;
197
+ }
198
+ verify(hash, signature) {
199
+ return tiny_secp256k1_1.default.verify(hash, this.publicKey, signature);
200
+ }
201
+ }
202
+ function fromBase58(inString, network) {
203
+ const buffer = Buffer.from((0, networks_1.isNetworkType)('decred', network)
204
+ ? bs58check.decodeBlake256Key(inString)
205
+ : bs58check.decode(inString, network));
206
+ if (buffer.length !== 78)
207
+ throw new TypeError('Invalid buffer length');
208
+ network = network || networks_1.bitcoin;
209
+ const version = buffer.readUInt32BE(0);
210
+ if (version !== network.bip32.private && version !== network.bip32.public)
211
+ throw new TypeError('Invalid network version');
212
+ const depth = buffer[4];
213
+ const parentFingerprint = buffer.readUInt32BE(5);
214
+ if (depth === 0) {
215
+ if (parentFingerprint !== 0x00000000)
216
+ throw new TypeError('Invalid parent fingerprint');
217
+ }
218
+ const index = buffer.readUInt32BE(9);
219
+ if (depth === 0 && index !== 0)
220
+ throw new TypeError('Invalid index');
221
+ const chainCode = buffer.subarray(13, 45);
222
+ let hd;
223
+ if (version === network.bip32.private) {
224
+ if (buffer.readUInt8(45) !== 0x00)
225
+ throw new TypeError('Invalid private key');
226
+ const k = buffer.subarray(46, 78);
227
+ hd = fromPrivateKeyLocal(k, chainCode, network, depth, index, parentFingerprint);
228
+ }
229
+ else {
230
+ const X = buffer.subarray(45, 78);
231
+ hd = fromPublicKeyLocal(X, chainCode, network, depth, index, parentFingerprint);
232
+ }
233
+ return hd;
234
+ }
235
+ function fromPrivateKey(privateKey, chainCode, network) {
236
+ return fromPrivateKeyLocal(privateKey, chainCode, network);
237
+ }
238
+ function fromPublicKey(publicKey, chainCode, network) {
239
+ return fromPublicKeyLocal(publicKey, chainCode, network);
240
+ }
241
+ function fromSeed(seed, network) {
242
+ (0, typeforce_1.typeforce)(typeforce_1.typeforce.Buffer, seed);
243
+ if (seed.length < 16)
244
+ throw new TypeError('Seed should be at least 128 bits');
245
+ if (seed.length > 64)
246
+ throw new TypeError('Seed should be at most 512 bits');
247
+ network = network || networks_1.bitcoin;
248
+ const I = crypto.hmacSHA512(Buffer.from('Bitcoin seed', 'utf8'), seed);
249
+ const IL = I.subarray(0, 32);
250
+ const IR = I.subarray(32);
251
+ return fromPrivateKey(IL, IR, network);
252
+ }
253
+ //# sourceMappingURL=bip32.js.map
@@ -0,0 +1,12 @@
1
+ export declare function decodeBlake(buffer: Buffer): Buffer;
2
+ export declare function decodeBlake256Key(key: string): Buffer;
3
+ export declare function decodeBlake256(address: string): Buffer;
4
+ export declare function encodeBlake256(payload: Buffer): string;
5
+ export declare function encode(payload: Buffer, network?: import("./networks").Network): string;
6
+ export declare function decode(payload: string, network?: import("./networks").Network): Buffer | Uint8Array;
7
+ export declare function decodeAddress(address: string, network?: import("./networks").Network): {
8
+ version: number;
9
+ hash: Buffer;
10
+ };
11
+ export declare function encodeAddress(hash: Buffer, version: number, network?: import("./networks").Network): string;
12
+ //# sourceMappingURL=bs58check.d.ts.map