beignet 0.0.1

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 (329) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc +40 -0
  3. package/.prettierrc +9 -0
  4. package/LICENSE +21 -0
  5. package/README.md +166 -0
  6. package/dist/electrum/constants.js +31 -0
  7. package/dist/electrum/constants.js.map +1 -0
  8. package/dist/electrum/index.js +552 -0
  9. package/dist/electrum/index.js.map +1 -0
  10. package/dist/index.js +23 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/shapes/electrum.js +14 -0
  13. package/dist/shapes/electrum.js.map +1 -0
  14. package/dist/shapes/index.js +19 -0
  15. package/dist/shapes/index.js.map +1 -0
  16. package/dist/shapes/wallet.js +115 -0
  17. package/dist/shapes/wallet.js.map +1 -0
  18. package/dist/transaction/index.js +692 -0
  19. package/dist/transaction/index.js.map +1 -0
  20. package/dist/types/electrum/constants.d.ts +7 -0
  21. package/dist/types/electrum/index.d.ts +85 -0
  22. package/dist/types/electrum.js +9 -0
  23. package/dist/types/electrum.js.map +1 -0
  24. package/dist/types/index.d.ts +6 -0
  25. package/dist/types/index.js +20 -0
  26. package/dist/types/index.js.map +1 -0
  27. package/dist/types/shapes/electrum.d.ts +5 -0
  28. package/dist/types/shapes/index.d.ts +2 -0
  29. package/dist/types/shapes/wallet.d.ts +10 -0
  30. package/dist/types/transaction/index.d.ts +92 -0
  31. package/dist/types/transaction.js +12 -0
  32. package/dist/types/transaction.js.map +1 -0
  33. package/dist/types/types/electrum.d.ts +113 -0
  34. package/dist/types/types/index.d.ts +3 -0
  35. package/dist/types/types/transaction.d.ts +51 -0
  36. package/dist/types/types/wallet.d.ts +400 -0
  37. package/dist/types/utils/conversion.d.ts +10 -0
  38. package/dist/types/utils/derivation-path.d.ts +19 -0
  39. package/dist/types/utils/electrum.d.ts +10 -0
  40. package/dist/types/utils/exchange-rate.d.ts +30 -0
  41. package/dist/types/utils/helpers.d.ts +23 -0
  42. package/dist/types/utils/index.d.ts +7 -0
  43. package/dist/types/utils/result.d.ts +16 -0
  44. package/dist/types/utils/transaction.d.ts +21 -0
  45. package/dist/types/utils/wallet.d.ts +47 -0
  46. package/dist/types/wallet/constants.d.ts +12 -0
  47. package/dist/types/wallet/index.d.ts +214 -0
  48. package/dist/types/wallet.js +36 -0
  49. package/dist/types/wallet.js.map +1 -0
  50. package/dist/utils/conversion.js +52 -0
  51. package/dist/utils/conversion.js.map +1 -0
  52. package/dist/utils/derivation-path.js +104 -0
  53. package/dist/utils/derivation-path.js.map +1 -0
  54. package/dist/utils/electrum.js +149 -0
  55. package/dist/utils/electrum.js.map +1 -0
  56. package/dist/utils/exchange-rate.js +49 -0
  57. package/dist/utils/exchange-rate.js.map +1 -0
  58. package/dist/utils/helpers.js +137 -0
  59. package/dist/utils/helpers.js.map +1 -0
  60. package/dist/utils/index.js +24 -0
  61. package/dist/utils/index.js.map +1 -0
  62. package/dist/utils/result.js +36 -0
  63. package/dist/utils/result.js.map +1 -0
  64. package/dist/utils/transaction.js +327 -0
  65. package/dist/utils/transaction.js.map +1 -0
  66. package/dist/utils/wallet.js +227 -0
  67. package/dist/utils/wallet.js.map +1 -0
  68. package/dist/wallet/constants.js +15 -0
  69. package/dist/wallet/constants.js.map +1 -0
  70. package/dist/wallet/index.js +2113 -0
  71. package/dist/wallet/index.js.map +1 -0
  72. package/docs/html/.nojekyll +1 -0
  73. package/docs/html/assets/highlight.css +22 -0
  74. package/docs/html/assets/main.js +58 -0
  75. package/docs/html/assets/search.js +1 -0
  76. package/docs/html/assets/style.css +1367 -0
  77. package/docs/html/classes/Electrum.html +812 -0
  78. package/docs/html/classes/Transaction.html +687 -0
  79. package/docs/html/classes/Wallet.html +2030 -0
  80. package/docs/html/enums/EAddressType.html +227 -0
  81. package/docs/html/enums/EAvailableNetworks.html +255 -0
  82. package/docs/html/enums/EBoostType.html +220 -0
  83. package/docs/html/enums/EFeeId.html +241 -0
  84. package/docs/html/enums/EPaymentType.html +220 -0
  85. package/docs/html/enums/EProtocol.html +220 -0
  86. package/docs/html/enums/EUnit.html +227 -0
  87. package/docs/html/functions/availableNetworks.html +200 -0
  88. package/docs/html/functions/constructByteCountParam.html +210 -0
  89. package/docs/html/functions/decodeOpReturnMessage.html +202 -0
  90. package/docs/html/functions/decodeRawTransaction.html +210 -0
  91. package/docs/html/functions/err.html +214 -0
  92. package/docs/html/functions/formatKeyDerivationPath.html +219 -0
  93. package/docs/html/functions/formatPeerData.html +207 -0
  94. package/docs/html/functions/generateMnemonic.html +223 -0
  95. package/docs/html/functions/generateWalletId.html +202 -0
  96. package/docs/html/functions/getAddressFromScriptPubKey.html +209 -0
  97. package/docs/html/functions/getAddressTypeFromPath.html +206 -0
  98. package/docs/html/functions/getByteCount.html +206 -0
  99. package/docs/html/functions/getDataFallback.html +207 -0
  100. package/docs/html/functions/getDefaultPort.html +209 -0
  101. package/docs/html/functions/getDefaultWalletData.html +200 -0
  102. package/docs/html/functions/getDefaultWalletDataKeys.html +200 -0
  103. package/docs/html/functions/getExchangeRates.html +200 -0
  104. package/docs/html/functions/getHighestUsedIndexFromTxHashes.html +216 -0
  105. package/docs/html/functions/getKeyDerivationPath.html +211 -0
  106. package/docs/html/functions/getKeyDerivationPathObject.html +216 -0
  107. package/docs/html/functions/getKeyDerivationPathString.html +220 -0
  108. package/docs/html/functions/getKeyValue.html +206 -0
  109. package/docs/html/functions/getPeers.html +211 -0
  110. package/docs/html/functions/getProtocolForPort.html +209 -0
  111. package/docs/html/functions/getScriptHash.html +210 -0
  112. package/docs/html/functions/getSeed.html +209 -0
  113. package/docs/html/functions/getSeedHash.html +206 -0
  114. package/docs/html/functions/getSha256.html +206 -0
  115. package/docs/html/functions/getStorageKeyValues.html +209 -0
  116. package/docs/html/functions/getTxFee.html +210 -0
  117. package/docs/html/functions/getWalletDataStorageKey.html +206 -0
  118. package/docs/html/functions/isValidBech32mEncodedString.html +211 -0
  119. package/docs/html/functions/objectKeys-1.html +211 -0
  120. package/docs/html/functions/objectsMatch.html +210 -0
  121. package/docs/html/functions/ok.html +214 -0
  122. package/docs/html/functions/parseOnChainPaymentRequest.html +204 -0
  123. package/docs/html/functions/reduceValue.html +215 -0
  124. package/docs/html/functions/removeDustOutputs.html +206 -0
  125. package/docs/html/functions/setReplaceByFee.html +210 -0
  126. package/docs/html/functions/shuffleArray.html +211 -0
  127. package/docs/html/functions/validateAddress.html +216 -0
  128. package/docs/html/functions/validateMnemonic.html +206 -0
  129. package/docs/html/functions/validateTransaction.html +206 -0
  130. package/docs/html/index.html +360 -0
  131. package/docs/html/interfaces/IAddInput.html +231 -0
  132. package/docs/html/interfaces/IAddress.html +247 -0
  133. package/docs/html/interfaces/IAddressData.html +231 -0
  134. package/docs/html/interfaces/IAddressType.html +199 -0
  135. package/docs/html/interfaces/IAddressTypeData.html +252 -0
  136. package/docs/html/interfaces/IAddresses.html +199 -0
  137. package/docs/html/interfaces/IBoostedTransaction.html +238 -0
  138. package/docs/html/interfaces/IBoostedTransactions.html +199 -0
  139. package/docs/html/interfaces/ICreateTransaction.html +224 -0
  140. package/docs/html/interfaces/ICustomGetAddress.html +231 -0
  141. package/docs/html/interfaces/ICustomGetScriptHash.html +224 -0
  142. package/docs/html/interfaces/IElectrumGetAddressBalanceRes.html +235 -0
  143. package/docs/html/interfaces/IExchangeRates.html +210 -0
  144. package/docs/html/interfaces/IFormattedPeerData.html +245 -0
  145. package/docs/html/interfaces/IFormattedTransaction.html +343 -0
  146. package/docs/html/interfaces/IFormattedTransactions.html +199 -0
  147. package/docs/html/interfaces/IGenerateAddresses.html +252 -0
  148. package/docs/html/interfaces/IGenerateAddressesResponse.html +224 -0
  149. package/docs/html/interfaces/IGetAddress.html +231 -0
  150. package/docs/html/interfaces/IGetAddressBalanceRes.html +226 -0
  151. package/docs/html/interfaces/IGetAddressByPath.html +224 -0
  152. package/docs/html/interfaces/IGetAddressHistoryResponse.html +269 -0
  153. package/docs/html/interfaces/IGetAddressResponse.html +231 -0
  154. package/docs/html/interfaces/IGetAddressScriptHashesHistoryResponse.html +245 -0
  155. package/docs/html/interfaces/IGetDerivationPath.html +259 -0
  156. package/docs/html/interfaces/IGetFeeEstimatesResponse.html +238 -0
  157. package/docs/html/interfaces/IGetHeaderResponse.html +245 -0
  158. package/docs/html/interfaces/IGetNextAvailableAddressResponse.html +238 -0
  159. package/docs/html/interfaces/IGetTransactions.html +245 -0
  160. package/docs/html/interfaces/IGetTransactionsFromInputs.html +245 -0
  161. package/docs/html/interfaces/IGetUtxosResponse.html +224 -0
  162. package/docs/html/interfaces/IHeader.html +231 -0
  163. package/docs/html/interfaces/IIndexes.html +238 -0
  164. package/docs/html/interfaces/IKeyDerivationPath.html +247 -0
  165. package/docs/html/interfaces/IKeyDerivationPathData.html +224 -0
  166. package/docs/html/interfaces/INewBlock.html +224 -0
  167. package/docs/html/interfaces/IOnchainFees.html +245 -0
  168. package/docs/html/interfaces/IOutput.html +231 -0
  169. package/docs/html/interfaces/IPeerData.html +231 -0
  170. package/docs/html/interfaces/IRbfData.html +252 -0
  171. package/docs/html/interfaces/ISend.html +224 -0
  172. package/docs/html/interfaces/ISendTransaction.html +322 -0
  173. package/docs/html/interfaces/ISendTx.html +231 -0
  174. package/docs/html/interfaces/ISetupTransaction.html +238 -0
  175. package/docs/html/interfaces/ISubscribeToAddress.html +247 -0
  176. package/docs/html/interfaces/ISubscribeToHeader.html +245 -0
  177. package/docs/html/interfaces/ITargets.html +238 -0
  178. package/docs/html/interfaces/ITransaction.html +281 -0
  179. package/docs/html/interfaces/ITxHash.html +217 -0
  180. package/docs/html/interfaces/ITxHashes.html +235 -0
  181. package/docs/html/interfaces/IUtxo.html +275 -0
  182. package/docs/html/interfaces/IVin.html +252 -0
  183. package/docs/html/interfaces/IVout.html +246 -0
  184. package/docs/html/interfaces/IWallet.html +350 -0
  185. package/docs/html/interfaces/IWalletData.html +343 -0
  186. package/docs/html/types/ElectrumConnectionPubSub.html +233 -0
  187. package/docs/html/types/ElectrumConnectionSubscription.html +204 -0
  188. package/docs/html/types/InputData.html +203 -0
  189. package/docs/html/types/ObjectKeys.html +198 -0
  190. package/docs/html/types/Result.html +201 -0
  191. package/docs/html/types/TAddressIndexInfo.html +204 -0
  192. package/docs/html/types/TAddressLabel.html +193 -0
  193. package/docs/html/types/TAddressType.html +193 -0
  194. package/docs/html/types/TAddressTypeContent.html +198 -0
  195. package/docs/html/types/TAddressTypes.html +193 -0
  196. package/docs/html/types/TAvailableNetworks.html +193 -0
  197. package/docs/html/types/TConnectToElectrumRes.html +193 -0
  198. package/docs/html/types/TDecodeRawTx.html +214 -0
  199. package/docs/html/types/TElectrumNetworks.html +193 -0
  200. package/docs/html/types/TGetAddressHistory.html +200 -0
  201. package/docs/html/types/TGetByteCountInput.html +193 -0
  202. package/docs/html/types/TGetByteCountInputs.html +193 -0
  203. package/docs/html/types/TGetByteCountOutput.html +193 -0
  204. package/docs/html/types/TGetByteCountOutputs.html +193 -0
  205. package/docs/html/types/TGetData.html +211 -0
  206. package/docs/html/types/TGetTotalFeeObj.html +204 -0
  207. package/docs/html/types/TKeyDerivationAccount.html +193 -0
  208. package/docs/html/types/TKeyDerivationChange.html +193 -0
  209. package/docs/html/types/TKeyDerivationCoinType.html +193 -0
  210. package/docs/html/types/TKeyDerivationIndex.html +193 -0
  211. package/docs/html/types/TKeyDerivationPurpose.html +193 -0
  212. package/docs/html/types/TMessageDataMap.html +210 -0
  213. package/docs/html/types/TMessageKeys.html +193 -0
  214. package/docs/html/types/TOnMessage.html +213 -0
  215. package/docs/html/types/TProcessUnconfirmedTransactions.html +202 -0
  216. package/docs/html/types/TProtocol.html +193 -0
  217. package/docs/html/types/TServer.html +204 -0
  218. package/docs/html/types/TSetData.html +213 -0
  219. package/docs/html/types/TSetupTransactionResponse.html +193 -0
  220. package/docs/html/types/TStorage.html +200 -0
  221. package/docs/html/types/TSubscribedReceive.html +193 -0
  222. package/docs/html/types/TTransactionMessage.html +198 -0
  223. package/docs/html/types/TTxResponse.html +206 -0
  224. package/docs/html/types/TTxResult.html +200 -0
  225. package/docs/html/types/TUnspentAddressScriptHashData.html +198 -0
  226. package/docs/html/types/TWalletDataKeys.html +193 -0
  227. package/docs/html/variables/defaultElectrumPorts.html +193 -0
  228. package/docs/html/variables/electrumConnection.html +199 -0
  229. package/docs/html/variables/mostUsedExchangeTickers.html +241 -0
  230. package/docs/markdown/.nojekyll +1 -0
  231. package/docs/markdown/README.md +1875 -0
  232. package/docs/markdown/classes/Electrum.md +718 -0
  233. package/docs/markdown/classes/Transaction.md +536 -0
  234. package/docs/markdown/classes/Wallet.md +2189 -0
  235. package/docs/markdown/enums/EAddressType.md +41 -0
  236. package/docs/markdown/enums/EAvailableNetworks.md +85 -0
  237. package/docs/markdown/enums/EBoostType.md +30 -0
  238. package/docs/markdown/enums/EFeeId.md +63 -0
  239. package/docs/markdown/enums/EPaymentType.md +30 -0
  240. package/docs/markdown/enums/EProtocol.md +30 -0
  241. package/docs/markdown/enums/EUnit.md +41 -0
  242. package/docs/markdown/interfaces/IAddInput.md +41 -0
  243. package/docs/markdown/interfaces/IAddress.md +69 -0
  244. package/docs/markdown/interfaces/IAddressData.md +41 -0
  245. package/docs/markdown/interfaces/IAddressType.md +7 -0
  246. package/docs/markdown/interfaces/IAddressTypeData.md +74 -0
  247. package/docs/markdown/interfaces/IAddresses.md +7 -0
  248. package/docs/markdown/interfaces/IBoostedTransaction.md +52 -0
  249. package/docs/markdown/interfaces/IBoostedTransactions.md +7 -0
  250. package/docs/markdown/interfaces/ICreateTransaction.md +30 -0
  251. package/docs/markdown/interfaces/ICustomGetAddress.md +41 -0
  252. package/docs/markdown/interfaces/ICustomGetScriptHash.md +30 -0
  253. package/docs/markdown/interfaces/IElectrumGetAddressBalanceRes.md +55 -0
  254. package/docs/markdown/interfaces/IExchangeRates.md +7 -0
  255. package/docs/markdown/interfaces/IFormattedPeerData.md +63 -0
  256. package/docs/markdown/interfaces/IFormattedTransaction.md +217 -0
  257. package/docs/markdown/interfaces/IFormattedTransactions.md +7 -0
  258. package/docs/markdown/interfaces/IGenerateAddresses.md +74 -0
  259. package/docs/markdown/interfaces/IGenerateAddressesResponse.md +30 -0
  260. package/docs/markdown/interfaces/IGetAddress.md +41 -0
  261. package/docs/markdown/interfaces/IGetAddressBalanceRes.md +36 -0
  262. package/docs/markdown/interfaces/IGetAddressByPath.md +30 -0
  263. package/docs/markdown/interfaces/IGetAddressHistoryResponse.md +121 -0
  264. package/docs/markdown/interfaces/IGetAddressResponse.md +41 -0
  265. package/docs/markdown/interfaces/IGetAddressScriptHashesHistoryResponse.md +63 -0
  266. package/docs/markdown/interfaces/IGetDerivationPath.md +100 -0
  267. package/docs/markdown/interfaces/IGetFeeEstimatesResponse.md +52 -0
  268. package/docs/markdown/interfaces/IGetHeaderResponse.md +63 -0
  269. package/docs/markdown/interfaces/IGetNextAvailableAddressResponse.md +52 -0
  270. package/docs/markdown/interfaces/IGetTransactions.md +63 -0
  271. package/docs/markdown/interfaces/IGetTransactionsFromInputs.md +63 -0
  272. package/docs/markdown/interfaces/IGetUtxosResponse.md +30 -0
  273. package/docs/markdown/interfaces/IHeader.md +41 -0
  274. package/docs/markdown/interfaces/IIndexes.md +52 -0
  275. package/docs/markdown/interfaces/IKeyDerivationPath.md +69 -0
  276. package/docs/markdown/interfaces/IKeyDerivationPathData.md +30 -0
  277. package/docs/markdown/interfaces/INewBlock.md +30 -0
  278. package/docs/markdown/interfaces/IOnchainFees.md +63 -0
  279. package/docs/markdown/interfaces/IOutput.md +41 -0
  280. package/docs/markdown/interfaces/IPeerData.md +41 -0
  281. package/docs/markdown/interfaces/IRbfData.md +74 -0
  282. package/docs/markdown/interfaces/ISend.md +30 -0
  283. package/docs/markdown/interfaces/ISendTransaction.md +184 -0
  284. package/docs/markdown/interfaces/ISendTx.md +41 -0
  285. package/docs/markdown/interfaces/ISetupTransaction.md +52 -0
  286. package/docs/markdown/interfaces/ISubscribeToAddress.md +60 -0
  287. package/docs/markdown/interfaces/ISubscribeToHeader.md +59 -0
  288. package/docs/markdown/interfaces/ITargets.md +52 -0
  289. package/docs/markdown/interfaces/ITransaction.md +88 -0
  290. package/docs/markdown/interfaces/ITxHash.md +19 -0
  291. package/docs/markdown/interfaces/ITxHashes.md +55 -0
  292. package/docs/markdown/interfaces/IUtxo.md +112 -0
  293. package/docs/markdown/interfaces/IVin.md +70 -0
  294. package/docs/markdown/interfaces/IVout.md +52 -0
  295. package/docs/markdown/interfaces/IWallet.md +209 -0
  296. package/docs/markdown/interfaces/IWalletData.md +217 -0
  297. package/example/helpers.ts +76 -0
  298. package/example/index.ts +77 -0
  299. package/package.json +69 -0
  300. package/src/electrum/constants.ts +28 -0
  301. package/src/electrum/index.ts +838 -0
  302. package/src/index.ts +6 -0
  303. package/src/shapes/electrum.ts +13 -0
  304. package/src/shapes/index.ts +2 -0
  305. package/src/shapes/wallet.ts +133 -0
  306. package/src/transaction/index.ts +1078 -0
  307. package/src/types/electrum.ts +139 -0
  308. package/src/types/index.ts +3 -0
  309. package/src/types/transaction.ts +58 -0
  310. package/src/types/wallet.ts +503 -0
  311. package/src/utils/conversion.ts +88 -0
  312. package/src/utils/derivation-path.ts +171 -0
  313. package/src/utils/electrum.ts +188 -0
  314. package/src/utils/exchange-rate.ts +70 -0
  315. package/src/utils/helpers.ts +191 -0
  316. package/src/utils/index.ts +7 -0
  317. package/src/utils/result.ts +79 -0
  318. package/src/utils/transaction.ts +417 -0
  319. package/src/utils/wallet.ts +351 -0
  320. package/src/wallet/constants.ts +24 -0
  321. package/src/wallet/index.ts +3304 -0
  322. package/tests/constants.ts +9 -0
  323. package/tests/derivation.test.ts +146 -0
  324. package/tests/electrum.test.ts +137 -0
  325. package/tests/storage.test.ts +222 -0
  326. package/tests/transaction.test.ts +187 -0
  327. package/tests/wallet.test.ts +307 -0
  328. package/tsconfig.json +32 -0
  329. package/typedoc.json +5 -0
@@ -0,0 +1,9 @@
1
+ export const TEST_MNEMONIC =
2
+ 'decorate grass round powder swarm syrup identify resemble mass online grunt cruise';
3
+ export const TRANSACTION_TEST_MNEMONIC =
4
+ 'magic skull comfort major potato local giggle adjust post very olympic fortune';
5
+ export const EXAMPLE_MNEMONIC =
6
+ 'shaft lottery soda estate trade bounce scout acid axis weather pole indicate';
7
+ export const HIGHT_ACTIVITY_MNEMONIC =
8
+ 'above diet topic latin van chief load early faith clump alpha truly';
9
+ export const NETWORK = 'testnet';
@@ -0,0 +1,146 @@
1
+ import * as chai from 'chai';
2
+ import {
3
+ EAddressType,
4
+ EAvailableNetworks,
5
+ getAddressTypeFromPath,
6
+ getKeyDerivationPath,
7
+ getKeyDerivationPathObject,
8
+ getKeyDerivationPathString
9
+ } from '../src';
10
+
11
+ const expect = chai.expect;
12
+
13
+ describe('Derivation Methods', () => {
14
+ it('Should return default derivation path object for p2wpkh', () => {
15
+ const pathRes = getKeyDerivationPath({
16
+ addressType: EAddressType.p2wpkh,
17
+ network: EAvailableNetworks.mainnet
18
+ });
19
+ expect(pathRes.isErr()).to.equal(false);
20
+ if (pathRes.isErr()) return;
21
+ expect(pathRes.value.purpose).to.equal('84');
22
+ expect(pathRes.value.coinType).to.equal('0');
23
+ expect(pathRes.value.account).to.equal('0');
24
+ expect(pathRes.value.change).to.equal('0');
25
+ expect(pathRes.value.index).to.equal('0');
26
+ });
27
+ it('Should return default derivation path object for p2sh', () => {
28
+ const pathRes = getKeyDerivationPath({
29
+ addressType: EAddressType.p2sh,
30
+ network: EAvailableNetworks.mainnet
31
+ });
32
+ expect(pathRes.isErr()).to.equal(false);
33
+ if (pathRes.isErr()) return;
34
+ expect(pathRes.value.purpose).to.equal('49');
35
+ expect(pathRes.value.coinType).to.equal('0');
36
+ expect(pathRes.value.account).to.equal('0');
37
+ expect(pathRes.value.change).to.equal('0');
38
+ expect(pathRes.value.index).to.equal('0');
39
+ });
40
+ it('Should return default derivation path object for p2pkh', () => {
41
+ const pathRes = getKeyDerivationPath({
42
+ addressType: EAddressType.p2pkh,
43
+ network: EAvailableNetworks.mainnet
44
+ });
45
+ expect(pathRes.isErr()).to.equal(false);
46
+ if (pathRes.isErr()) return;
47
+ expect(pathRes.value.purpose).to.equal('44');
48
+ expect(pathRes.value.coinType).to.equal('0');
49
+ expect(pathRes.value.account).to.equal('0');
50
+ expect(pathRes.value.change).to.equal('0');
51
+ expect(pathRes.value.index).to.equal('0');
52
+ });
53
+
54
+ it('Should return a valid mainnet bech32 change address derivation string at index 0', () => {
55
+ const pathRes = getKeyDerivationPathString({
56
+ addressType: EAddressType.p2wpkh,
57
+ changeAddress: true,
58
+ index: 0,
59
+ network: EAvailableNetworks.mainnet
60
+ });
61
+ expect(pathRes.isErr()).to.equal(false);
62
+ if (pathRes.isErr()) return;
63
+ expect(pathRes.value).to.equal("m/84'/0'/0'/1/0");
64
+ });
65
+ it('Should return a valid testnet p2sh derivation string at index 40', () => {
66
+ const pathRes = getKeyDerivationPathString({
67
+ addressType: EAddressType.p2sh,
68
+ changeAddress: false,
69
+ index: '40',
70
+ network: EAvailableNetworks.testnet
71
+ });
72
+ expect(pathRes.isErr()).to.equal(false);
73
+ if (pathRes.isErr()) return;
74
+ expect(pathRes.value).to.equal("m/49'/1'/0'/0/40");
75
+ });
76
+ it('Should return a valid mainnet p2pkh derivation string at index 8', () => {
77
+ const pathRes = getKeyDerivationPathString({
78
+ addressType: EAddressType.p2pkh,
79
+ changeAddress: false,
80
+ index: 8,
81
+ network: EAvailableNetworks.mainnet
82
+ });
83
+ expect(pathRes.isErr()).to.equal(false);
84
+ if (pathRes.isErr()) return;
85
+ expect(pathRes.value).to.equal("m/44'/0'/0'/0/8");
86
+ });
87
+
88
+ it('Should return a valid mainnet bech32 change address derivation object at index 0', () => {
89
+ const pathRes = getKeyDerivationPathObject({
90
+ path: "m/84'/0'/0'/1/0",
91
+ network: EAvailableNetworks.mainnet
92
+ });
93
+ expect(pathRes.isErr()).to.equal(false);
94
+ if (pathRes.isErr()) return;
95
+ expect(pathRes.value.purpose).to.equal('84');
96
+ expect(pathRes.value.coinType).to.equal('0');
97
+ expect(pathRes.value.account).to.equal('0');
98
+ expect(pathRes.value.change).to.equal('1');
99
+ expect(pathRes.value.index).to.equal('0');
100
+ });
101
+ it('Should return a valid testnet p2sh derivation object at index 40', () => {
102
+ const pathRes = getKeyDerivationPathObject({
103
+ path: "m/49'/1'/0'/0/40",
104
+ network: EAvailableNetworks.testnet
105
+ });
106
+ expect(pathRes.isErr()).to.equal(false);
107
+ if (pathRes.isErr()) return;
108
+ expect(pathRes.value.purpose).to.equal('49');
109
+ expect(pathRes.value.coinType).to.equal('1');
110
+ expect(pathRes.value.account).to.equal('0');
111
+ expect(pathRes.value.change).to.equal('0');
112
+ expect(pathRes.value.index).to.equal('40');
113
+ });
114
+ it('Should return a valid mainnet p2pkh object at index 8', () => {
115
+ const pathRes = getKeyDerivationPathObject({
116
+ path: "m/44'/0'/0'/0/8",
117
+ network: EAvailableNetworks.mainnet
118
+ });
119
+ expect(pathRes.isErr()).to.equal(false);
120
+ if (pathRes.isErr()) return;
121
+ expect(pathRes.value.purpose).to.equal('44');
122
+ expect(pathRes.value.coinType).to.equal('0');
123
+ expect(pathRes.value.account).to.equal('0');
124
+ expect(pathRes.value.change).to.equal('0');
125
+ expect(pathRes.value.index).to.equal('8');
126
+ });
127
+
128
+ it('Should return a valid address type from p2wpkh path', () => {
129
+ const pathRes = getAddressTypeFromPath("m/84'/0'/0'/0/0");
130
+ expect(pathRes.isErr()).to.equal(false);
131
+ if (pathRes.isErr()) return;
132
+ expect(pathRes.value).to.equal(EAddressType.p2wpkh);
133
+ });
134
+ it('Should return a valid address type from p2sh path', () => {
135
+ const pathRes = getAddressTypeFromPath("m/49'/0'/0'/0/0");
136
+ expect(pathRes.isErr()).to.equal(false);
137
+ if (pathRes.isErr()) return;
138
+ expect(pathRes.value).to.equal(EAddressType.p2sh);
139
+ });
140
+ it('Should return a valid address type from p2pkh path', () => {
141
+ const pathRes = getAddressTypeFromPath("m/44'/0'/0'/0/0");
142
+ expect(pathRes.isErr()).to.equal(false);
143
+ if (pathRes.isErr()) return;
144
+ expect(pathRes.value).to.equal(EAddressType.p2pkh);
145
+ });
146
+ });
@@ -0,0 +1,137 @@
1
+ import * as chai from 'chai';
2
+ import { Wallet } from '../';
3
+ import { EAvailableNetworks, EAddressType, IGetUtxosResponse } from '../src';
4
+ import { TEST_MNEMONIC } from './constants';
5
+ import { Result } from '../src';
6
+ const expect = chai.expect;
7
+
8
+ const testTimeout = 60000;
9
+
10
+ let wallet;
11
+
12
+ before(async function () {
13
+ this.timeout(testTimeout);
14
+ const res = await Wallet.create({
15
+ mnemonic: TEST_MNEMONIC,
16
+ network: EAvailableNetworks.testnet,
17
+ addressType: EAddressType.p2wpkh
18
+ });
19
+ if (res.isErr()) {
20
+ console.log('error: ', res.error.message);
21
+ //throw new Error(res.error.message);
22
+ return;
23
+ }
24
+ wallet = res.value;
25
+ });
26
+
27
+ describe('Electrum Methods', async function (): Promise<void> {
28
+ this.timeout(testTimeout);
29
+ it('connectToElectrum: Should connect to a random Electrum server', async () => {
30
+ const connectResponse = await wallet.connectToElectrum();
31
+ expect(connectResponse.isErr()).to.equal(false);
32
+ expect(connectResponse.value).to.equal('Connected to Electrum server.');
33
+ });
34
+
35
+ it('isConnected: Should return true if connected to an Electrum server', async () => {
36
+ const isConnected = await wallet.electrum.isConnected();
37
+ expect(isConnected).to.equal(true);
38
+ });
39
+
40
+ it('getAddressBalance: Should return the balance (in sats) of the provided address', async () => {
41
+ const addressBalance = await wallet.getAddressBalance(
42
+ 'tb1qyvc8r7338383xjshqsz38mfn2eql879nhrf8y0'
43
+ );
44
+ expect(addressBalance.isErr()).to.equal(false);
45
+ if (addressBalance.isErr()) return;
46
+ expect(addressBalance.value.confirmed).to.equal(20000);
47
+ });
48
+
49
+ it('getNextAvailableAddress: Should return the next available address/change index and the last used address/change index', async () => {
50
+ const expectedResult = {
51
+ addressIndex: {
52
+ address: 'tb1qqcmg5vwk736mmr3fnkx5us9hq4czl6cx5w5g0x',
53
+ path: "m/84'/1'/0'/0/5",
54
+ publicKey:
55
+ '0345f71b1a5f9ce1c08ef2dbb1fb1076296b0fdf1f09f6fe7f53ed22383ad9d1c9',
56
+ index: 5,
57
+ scriptHash:
58
+ '448ae601fb40d7a6de824eb34479286a06d41015250fc75544dbb6d2893bd0e5'
59
+ },
60
+ lastUsedChangeAddressIndex: {
61
+ address: 'tb1q926j5y9mwjc49axf5w25y2jrm0ew8w6uks0vdm',
62
+ index: 9,
63
+ path: "m/84'/1'/0'/1/9",
64
+ publicKey:
65
+ '02e9085f8d23072244620f0549e6f1c6ff04c8c8b1dd238edce106ce6ef54b358e',
66
+ scriptHash:
67
+ '640d69f5b22996bdc95dbac8863e9e94e198f40569c1ec46b6336edd740c0007'
68
+ },
69
+ changeAddressIndex: {
70
+ address: 'tb1q32eaj0c805mry76wa0g6hlcunu7ttu96833072',
71
+ path: "m/84'/1'/0'/1/10",
72
+ publicKey:
73
+ '038813820d10cca28ce1fdb6a8b346a4ab9de6b520adc46e2c4442a7ba94de10a1',
74
+ index: 10,
75
+ scriptHash:
76
+ '3198ad3b2b39efcdeeb6b338c1f28ccede385c2092dbb9854e265b6eec8a0dab'
77
+ },
78
+ lastUsedAddressIndex: {
79
+ address: 'tb1qyxugs6zkcj3r4u09qks7khgf7hkktf8mnzz5ze',
80
+ path: "m/84'/1'/0'/0/4",
81
+ publicKey:
82
+ '03f01a817e07ff424f00d6be3b93f7bec658aaf8fbfed5cd2c18f95f3cfd47f7a8',
83
+ index: 4,
84
+ scriptHash:
85
+ '7f07103d4580005b27b856434bba9be63a7e58a83cb456b603f4af3ae88d1023'
86
+ }
87
+ };
88
+ const r = await wallet.getNextAvailableAddress();
89
+ expect(r.isErr()).to.equal(false);
90
+ if (r.isErr()) return;
91
+ expect(r.value).to.deep.equal(expectedResult);
92
+ });
93
+
94
+ it("Should return available UTXO's", async () => {
95
+ const expectedResult = {
96
+ utxos: [
97
+ {
98
+ address: 'tb1qy45r5c84eh7tuke772lrvj2q5kqlylp2ghgdlk',
99
+ path: "m/84'/1'/0'/0/1",
100
+ publicKey:
101
+ '03f8c98bf09b3e069714a05a530a735761453d94d1f4355239bfcb6b78c25a2592',
102
+ index: 1,
103
+ scriptHash:
104
+ 'bdb8f18267b816706378c2c9282e0be7b05dcc5a3e63dd2468f145c6431f2002',
105
+ tx_hash:
106
+ '7a6e9a985de1e5bed1138d1fe1bf2f169a4f838d802ecdf96d1376378391a350',
107
+ tx_pos: 0,
108
+ height: 2539268,
109
+ value: 1000
110
+ },
111
+ {
112
+ address: 'tb1q926j5y9mwjc49axf5w25y2jrm0ew8w6uks0vdm',
113
+ path: "m/84'/1'/0'/1/9",
114
+ publicKey:
115
+ '02e9085f8d23072244620f0549e6f1c6ff04c8c8b1dd238edce106ce6ef54b358e',
116
+ index: 9,
117
+ scriptHash:
118
+ '640d69f5b22996bdc95dbac8863e9e94e198f40569c1ec46b6336edd740c0007',
119
+ tx_hash:
120
+ '7a6e9a985de1e5bed1138d1fe1bf2f169a4f838d802ecdf96d1376378391a350',
121
+ tx_pos: 1,
122
+ height: 2539268,
123
+ value: 3855
124
+ }
125
+ ],
126
+ balance: 4855
127
+ };
128
+
129
+ const getUtxosRes: Result<IGetUtxosResponse> = await wallet.getUtxos({});
130
+ expect(getUtxosRes.isErr()).to.equal(false);
131
+ if (getUtxosRes.isErr()) return;
132
+ expect(Array.isArray(getUtxosRes.value.utxos)).to.equal(true);
133
+ expect(getUtxosRes.value.utxos.length).to.equal(2);
134
+ expect(getUtxosRes.value.balance).to.equal(4855);
135
+ expect(getUtxosRes.value).to.deep.equal(expectedResult);
136
+ });
137
+ });
@@ -0,0 +1,222 @@
1
+ import * as chai from 'chai';
2
+ import { validateMnemonic } from 'bip39';
3
+ import { Wallet } from '../';
4
+ import {
5
+ EAddressType,
6
+ EAvailableNetworks,
7
+ IGetUtxosResponse,
8
+ Result,
9
+ generateMnemonic
10
+ } from '../src';
11
+ import { TEST_MNEMONIC } from './constants';
12
+ import { deleteDirectory, getData, setData } from '../example/helpers';
13
+
14
+ const expect = chai.expect;
15
+
16
+ const testTimeout = 60000;
17
+
18
+ let wallet;
19
+ const WALLET_NAME = 'storagetestwallet0';
20
+
21
+ before(async function () {
22
+ this.timeout(testTimeout);
23
+ await deleteDirectory('example/walletData'); // Start test with clean slate.
24
+ const res = await Wallet.create({
25
+ mnemonic: TEST_MNEMONIC,
26
+ network: EAvailableNetworks.testnet,
27
+ name: WALLET_NAME,
28
+ addressType: EAddressType.p2wpkh,
29
+ storage: {
30
+ getData,
31
+ setData
32
+ }
33
+ });
34
+ if (res.isErr()) {
35
+ console.log('error: ', res.error.message);
36
+ //throw new Error(res.error.message);
37
+ return;
38
+ }
39
+ wallet = res.value;
40
+ });
41
+
42
+ describe('Storage Test', async function (): Promise<void> {
43
+ this.timeout(testTimeout);
44
+ it('Should successfully create a wallet.', () => {
45
+ expect(wallet).not.to.be.null;
46
+ });
47
+
48
+ it('Should generate a valid, random mnemonic', () => {
49
+ const randomMnemonic = generateMnemonic();
50
+ expect(validateMnemonic(randomMnemonic)).to.equal(true);
51
+ });
52
+
53
+ it('Should determine that the wallet mnemonic is invalid', () => {
54
+ const invalidMnemonic =
55
+ 'corn core humor loud lady wealth avoid purse next subject focus dilemma';
56
+ const isValid = wallet.isValid(invalidMnemonic);
57
+ expect(isValid).to.equal(false);
58
+ });
59
+
60
+ it('Should determine that the current wallet instance is valid', () => {
61
+ const isValid = wallet.isValid(TEST_MNEMONIC);
62
+ expect(isValid).to.equal(true);
63
+ });
64
+
65
+ it('Should generate a bech32 receiving address at index 0', async () => {
66
+ const address = await wallet.getAddress({
67
+ addressType: EAddressType.p2wpkh,
68
+ changeAddress: false,
69
+ index: '0'
70
+ });
71
+ expect(address).to.equal('tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66');
72
+ });
73
+
74
+ it('Should generate a segwit change address at index 1', async () => {
75
+ const address = await wallet.getAddress({
76
+ addressType: EAddressType.p2sh,
77
+ changeAddress: true,
78
+ index: '1'
79
+ });
80
+ expect(address).to.equal('2NDRG1ZGhWMGGNW7Mp58BKcyBs4Hyat8Law');
81
+ });
82
+
83
+ it('Should generate a legacy receiving address at index 5', async () => {
84
+ const address = await wallet.getAddress({
85
+ addressType: EAddressType.p2pkh,
86
+ changeAddress: false,
87
+ index: '5'
88
+ });
89
+ expect(address).to.equal('mohdq3fadTtT4uSH4oNr4F1Dp3YM4pR3VF');
90
+ });
91
+
92
+ it('Should generate a bech32 receiving address at index 0 via its path', async () => {
93
+ const address = await wallet.getAddressByPath({ path: "m/84'/1'/0'/0/0" });
94
+ expect(address.isErr()).to.equal(false);
95
+ if (address.isErr()) return;
96
+ expect(address.value.address).to.equal(
97
+ 'tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66'
98
+ );
99
+ });
100
+
101
+ it('Should generate a segwit change address at index 1 via its path', async () => {
102
+ const address = await wallet.getAddressByPath({ path: "m/49'/1'/0'/1/1" });
103
+ expect(address.isErr()).to.equal(false);
104
+ if (address.isErr()) return;
105
+ expect(address.value.address).to.equal(
106
+ '2NDRG1ZGhWMGGNW7Mp58BKcyBs4Hyat8Law'
107
+ );
108
+ });
109
+
110
+ it('Should generate a testnet legacy receiving address at index 5 via its path', async () => {
111
+ const address = await wallet.getAddressByPath({ path: "m/44'/1'/0'/0/5" });
112
+ expect(address.isErr()).to.equal(false);
113
+ if (address.isErr()) return;
114
+ expect(address.value.address).to.equal(
115
+ 'mohdq3fadTtT4uSH4oNr4F1Dp3YM4pR3VF'
116
+ );
117
+ });
118
+
119
+ it('getNextAvailableAddress: Should return the next available address/change index and the last used address/change index', async () => {
120
+ const expectedResult = {
121
+ addressIndex: {
122
+ address: 'tb1qqcmg5vwk736mmr3fnkx5us9hq4czl6cx5w5g0x',
123
+ path: "m/84'/1'/0'/0/5",
124
+ publicKey:
125
+ '0345f71b1a5f9ce1c08ef2dbb1fb1076296b0fdf1f09f6fe7f53ed22383ad9d1c9',
126
+ index: 5,
127
+ scriptHash:
128
+ '448ae601fb40d7a6de824eb34479286a06d41015250fc75544dbb6d2893bd0e5'
129
+ },
130
+ lastUsedChangeAddressIndex: {
131
+ address: 'tb1q926j5y9mwjc49axf5w25y2jrm0ew8w6uks0vdm',
132
+ index: 9,
133
+ path: "m/84'/1'/0'/1/9",
134
+ publicKey:
135
+ '02e9085f8d23072244620f0549e6f1c6ff04c8c8b1dd238edce106ce6ef54b358e',
136
+ scriptHash:
137
+ '640d69f5b22996bdc95dbac8863e9e94e198f40569c1ec46b6336edd740c0007'
138
+ },
139
+ changeAddressIndex: {
140
+ address: 'tb1q32eaj0c805mry76wa0g6hlcunu7ttu96833072',
141
+ path: "m/84'/1'/0'/1/10",
142
+ publicKey:
143
+ '038813820d10cca28ce1fdb6a8b346a4ab9de6b520adc46e2c4442a7ba94de10a1',
144
+ index: 10,
145
+ scriptHash:
146
+ '3198ad3b2b39efcdeeb6b338c1f28ccede385c2092dbb9854e265b6eec8a0dab'
147
+ },
148
+ lastUsedAddressIndex: {
149
+ address: 'tb1qyxugs6zkcj3r4u09qks7khgf7hkktf8mnzz5ze',
150
+ path: "m/84'/1'/0'/0/4",
151
+ publicKey:
152
+ '03f01a817e07ff424f00d6be3b93f7bec658aaf8fbfed5cd2c18f95f3cfd47f7a8',
153
+ index: 4,
154
+ scriptHash:
155
+ '7f07103d4580005b27b856434bba9be63a7e58a83cb456b603f4af3ae88d1023'
156
+ }
157
+ };
158
+ const r = await wallet.getNextAvailableAddress();
159
+ expect(r.isErr()).to.equal(false);
160
+ if (r.isErr()) return;
161
+ expect(r.value).to.deep.equal(expectedResult);
162
+ });
163
+
164
+ it("Should return available UTXO's", async () => {
165
+ const expectedResult = {
166
+ utxos: [
167
+ {
168
+ address: 'tb1qy45r5c84eh7tuke772lrvj2q5kqlylp2ghgdlk',
169
+ path: "m/84'/1'/0'/0/1",
170
+ publicKey:
171
+ '03f8c98bf09b3e069714a05a530a735761453d94d1f4355239bfcb6b78c25a2592',
172
+ index: 1,
173
+ scriptHash:
174
+ 'bdb8f18267b816706378c2c9282e0be7b05dcc5a3e63dd2468f145c6431f2002',
175
+ tx_hash:
176
+ '7a6e9a985de1e5bed1138d1fe1bf2f169a4f838d802ecdf96d1376378391a350',
177
+ tx_pos: 0,
178
+ height: 2539268,
179
+ value: 1000
180
+ },
181
+ {
182
+ address: 'tb1q926j5y9mwjc49axf5w25y2jrm0ew8w6uks0vdm',
183
+ path: "m/84'/1'/0'/1/9",
184
+ publicKey:
185
+ '02e9085f8d23072244620f0549e6f1c6ff04c8c8b1dd238edce106ce6ef54b358e',
186
+ index: 9,
187
+ scriptHash:
188
+ '640d69f5b22996bdc95dbac8863e9e94e198f40569c1ec46b6336edd740c0007',
189
+ tx_hash:
190
+ '7a6e9a985de1e5bed1138d1fe1bf2f169a4f838d802ecdf96d1376378391a350',
191
+ tx_pos: 1,
192
+ height: 2539268,
193
+ value: 3855
194
+ }
195
+ ],
196
+ balance: 4855
197
+ };
198
+
199
+ const getUtxosRes: Result<IGetUtxosResponse> = await wallet.getUtxos({});
200
+ expect(getUtxosRes.isErr()).to.equal(false);
201
+ if (getUtxosRes.isErr()) return;
202
+ expect(Array.isArray(getUtxosRes.value.utxos)).to.equal(true);
203
+ expect(getUtxosRes.value.utxos.length).to.equal(2);
204
+ expect(getUtxosRes.value.balance).to.equal(4855);
205
+ expect(getUtxosRes.value).to.deep.equal(expectedResult);
206
+ });
207
+
208
+ // it('Attempts to create a new wallet using the same name of an existing wallet in storage.', async () => {
209
+ // const createRes = await Wallet.create({
210
+ // mnemonic: generateMnemonic(),
211
+ // network: EAvailableNetworks.testnet,
212
+ // name: WALLET_NAME,
213
+ // addressType: EAddressType.p2wpkh,
214
+ // storage: {
215
+ // getData,
216
+ // setData
217
+ // }
218
+ // });
219
+ // expect(createRes.isOk()).to.equal(false);
220
+ // if (createRes.isOk()) return;
221
+ // });
222
+ });
@@ -0,0 +1,187 @@
1
+ import * as chai from 'chai';
2
+ import { decodeRawTransaction, Wallet } from '../';
3
+ import { EAvailableNetworks } from '../src';
4
+ import { TRANSACTION_TEST_MNEMONIC } from './constants';
5
+
6
+ const expect = chai.expect;
7
+
8
+ const testTimeout = 60000;
9
+
10
+ let wallet;
11
+
12
+ before(async function () {
13
+ this.timeout(testTimeout);
14
+ const res = await Wallet.create({
15
+ mnemonic: TRANSACTION_TEST_MNEMONIC,
16
+ network: EAvailableNetworks.testnet
17
+ });
18
+ if (res.isErr()) {
19
+ console.log('error: ', res.error.message);
20
+ return;
21
+ }
22
+ wallet = res.value;
23
+ });
24
+
25
+ describe('Transaction Test', async function (): Promise<void> {
26
+ this.timeout(testTimeout);
27
+
28
+ it('Should successfully create a wallet.', (): void => {
29
+ expect(wallet).not.to.be.null;
30
+ });
31
+
32
+ it('Should successfully return fee information.', (): void => {
33
+ const feeInfo = wallet.getFeeInfo({ satsPerByte: 5 });
34
+ expect(feeInfo.isErr()).to.equal(false);
35
+ if (feeInfo.isErr()) return;
36
+ expect(feeInfo).not.to.be.null;
37
+ expect(feeInfo.value.satsPerByte).to.equal(5);
38
+ expect(feeInfo.value.totalFee).to.equal(705);
39
+ expect(feeInfo.value.transactionByteCount).to.equal(141);
40
+ expect(feeInfo.value.maxSatPerByte).to.equal(283);
41
+ });
42
+
43
+ it('Should successfully create and decode a transaction.', async (): Promise<void> => {
44
+ // Get a receiving address.
45
+ const sendRes = await wallet.send({
46
+ address: 'tb1q8ud85xqzudmaq9sz4ncu44qrx68d8wuf2cwdqg',
47
+ amount: 5000,
48
+ satsPerByte: 5,
49
+ broadcast: false,
50
+ shuffleOutputs: false,
51
+ rbf: true
52
+ });
53
+ expect(sendRes.isErr()).to.equal(false);
54
+ if (sendRes.isErr()) return;
55
+ expect(sendRes.value).to.equal(
56
+ '020000000001014b44d379e48a8100d1c26f7220b8bbf7a4894ff015d5bc4064a28d08d25d808d0000000000000000000288130000000000001600143f1a7a1802e377d01602acf1cad403368ed3bb893722010000000000160014a6bd95db4dd6979189cad389daad006e236f4ba8024730440220078f087ba08b79c02e7cb97593d7e698670dd6e7537e3639dec70b4d354f8fa8022018a20a64618a405427eb2e0e67ef9ae2b89bfe1b51cdb365d44b5314b9728a06012102e86b90924963237c59e5389aab1cc5350c114549d1c5e7186a56ef33aea24ff900000000'
57
+ );
58
+
59
+ const decodeRes = decodeRawTransaction(sendRes.value, wallet.network);
60
+ expect(decodeRes.isErr()).to.equal(false);
61
+ if (decodeRes.isErr()) return;
62
+ const expectedDecodeRes = {
63
+ txid: '786c97889108849e7970651a0dbd10e08ffe7b4ddfd282be54e465441b985308',
64
+ tx_hash:
65
+ 'a5ad458d02cc905593e4b6d3c88cdbedcfff31a192691f24abdab92b4cef74ea',
66
+ size: 222,
67
+ vsize: 141,
68
+ weight: 561,
69
+ version: 2,
70
+ locktime: 0,
71
+ vin: [
72
+ {
73
+ txid: '8d805dd2088da26440bcd515f04f89a4f7bbb820726fc2d100818ae479d3444b',
74
+ vout: 0,
75
+ scriptSig: { asm: '', hex: '' },
76
+ txinwitness: [
77
+ '30440220078f087ba08b79c02e7cb97593d7e698670dd6e7537e3639dec70b4d354f8fa8022018a20a64618a405427eb2e0e67ef9ae2b89bfe1b51cdb365d44b5314b9728a0601',
78
+ '02e86b90924963237c59e5389aab1cc5350c114549d1c5e7186a56ef33aea24ff9'
79
+ ],
80
+ sequence: 0
81
+ }
82
+ ],
83
+ vout: [
84
+ {
85
+ value: 5000,
86
+ n: 0,
87
+ scriptPubKey: {
88
+ asm: 'OP_0 3f1a7a1802e377d01602acf1cad403368ed3bb89',
89
+ hex: '00143f1a7a1802e377d01602acf1cad403368ed3bb89',
90
+ address: 'tb1q8ud85xqzudmaq9sz4ncu44qrx68d8wuf2cwdqg'
91
+ }
92
+ },
93
+ {
94
+ value: 74295,
95
+ n: 1,
96
+ scriptPubKey: {
97
+ asm: 'OP_0 a6bd95db4dd6979189cad389daad006e236f4ba8',
98
+ hex: '0014a6bd95db4dd6979189cad389daad006e236f4ba8',
99
+ address: 'tb1q567etk6d66terzw26wya4tgqdc3k7jag0zcw3r'
100
+ }
101
+ }
102
+ ]
103
+ };
104
+ expect(decodeRes.value).to.deep.equal(expectedDecodeRes);
105
+ });
106
+
107
+ it('Should successfully create and decode a sendMany transaction.', async (): Promise<void> => {
108
+ // Get a receiving address.
109
+ const sendManyRes = await wallet.sendMany({
110
+ txs: [
111
+ {
112
+ address: 'tb1q56mkp64fd2d6jxawj3jal382hec3u8t8af83d7',
113
+ amount: 5000
114
+ },
115
+ {
116
+ address: 'tb1qd08eypv4uzd4mrmm35pmx6226vzh2u5fqkpeyd',
117
+ amount: 6000
118
+ }
119
+ ],
120
+ broadcast: false,
121
+ shuffleOutputs: false,
122
+ satsPerByte: 5,
123
+ rbf: true
124
+ });
125
+ expect(sendManyRes.isErr()).to.equal(false);
126
+ if (sendManyRes.isErr()) return;
127
+ expect(sendManyRes.value).to.equal(
128
+ '020000000001014b44d379e48a8100d1c26f7220b8bbf7a4894ff015d5bc4064a28d08d25d808d000000000000000000038813000000000000160014a6b760eaa96a9ba91bae9465dfc4eabe711e1d6770170000000000001600146bcf920595e09b5d8f7b8d03b3694ad3057572892c0a010000000000160014a6bd95db4dd6979189cad389daad006e236f4ba80247304402207e7b5de41cb9bf33e434c2136390bf40d6b6552b69234a62f6bf48b89f0d44ac022056121c9a9d79d9d84896c9896a6fddb358b48667021ff2832b5c5871d90b701a012102e86b90924963237c59e5389aab1cc5350c114549d1c5e7186a56ef33aea24ff900000000'
129
+ );
130
+
131
+ const decodeRes = decodeRawTransaction(sendManyRes.value, wallet.network);
132
+ expect(decodeRes.isErr()).to.equal(false);
133
+ if (decodeRes.isErr()) return;
134
+ const expectedDecodeRes = {
135
+ txid: '3fb40fc55d80c46d08f412c2c9a6b18e6b46264a6ae6fd4be8409480d1a53b45',
136
+ tx_hash:
137
+ '6b124dc403f6db7ce9c7967b8b3b5b3223d4df98626ece3b5d253450c47c9b88',
138
+ size: 253,
139
+ vsize: 172,
140
+ weight: 685,
141
+ version: 2,
142
+ locktime: 0,
143
+ vin: [
144
+ {
145
+ txid: '8d805dd2088da26440bcd515f04f89a4f7bbb820726fc2d100818ae479d3444b',
146
+ vout: 0,
147
+ scriptSig: { asm: '', hex: '' },
148
+ txinwitness: [
149
+ '304402207e7b5de41cb9bf33e434c2136390bf40d6b6552b69234a62f6bf48b89f0d44ac022056121c9a9d79d9d84896c9896a6fddb358b48667021ff2832b5c5871d90b701a01',
150
+ '02e86b90924963237c59e5389aab1cc5350c114549d1c5e7186a56ef33aea24ff9'
151
+ ],
152
+ sequence: 0
153
+ }
154
+ ],
155
+ vout: [
156
+ {
157
+ value: 5000,
158
+ n: 0,
159
+ scriptPubKey: {
160
+ asm: 'OP_0 a6b760eaa96a9ba91bae9465dfc4eabe711e1d67',
161
+ hex: '0014a6b760eaa96a9ba91bae9465dfc4eabe711e1d67',
162
+ address: 'tb1q56mkp64fd2d6jxawj3jal382hec3u8t8af83d7'
163
+ }
164
+ },
165
+ {
166
+ value: 6000,
167
+ n: 1,
168
+ scriptPubKey: {
169
+ asm: 'OP_0 6bcf920595e09b5d8f7b8d03b3694ad305757289',
170
+ hex: '00146bcf920595e09b5d8f7b8d03b3694ad305757289',
171
+ address: 'tb1qd08eypv4uzd4mrmm35pmx6226vzh2u5fqkpeyd'
172
+ }
173
+ },
174
+ {
175
+ value: 68140,
176
+ n: 2,
177
+ scriptPubKey: {
178
+ asm: 'OP_0 a6bd95db4dd6979189cad389daad006e236f4ba8',
179
+ hex: '0014a6bd95db4dd6979189cad389daad006e236f4ba8',
180
+ address: 'tb1q567etk6d66terzw26wya4tgqdc3k7jag0zcw3r'
181
+ }
182
+ }
183
+ ]
184
+ };
185
+ expect(decodeRes.value).to.deep.equal(expectedDecodeRes);
186
+ });
187
+ });