postchain-client 1.22.0 → 2.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 (398) hide show
  1. package/README.md +16 -0
  2. package/built/cjs/index.js +2205 -3742
  3. package/built/cjs/index.js.map +1 -1
  4. package/built/esm/index.js +10425 -11683
  5. package/built/esm/index.js.map +1 -1
  6. package/built/index.d.ts +3 -8
  7. package/built/index.js +2 -11
  8. package/built/index.js.map +1 -1
  9. package/built/mocks/handlers.d.ts +1 -1
  10. package/built/mocks/handlers.js +62 -21
  11. package/built/mocks/handlers.js.map +1 -1
  12. package/built/src/ICCF/IccfProofTxMaterialBuilder.d.ts +3 -2
  13. package/built/src/ICCF/IccfProofTxMaterialBuilder.js +23 -10
  14. package/built/src/ICCF/IccfProofTxMaterialBuilder.js.map +1 -1
  15. package/built/src/ICCF/types.d.ts +4 -1
  16. package/built/src/ICCF/utils.js +2 -2
  17. package/built/src/ICCF/utils.js.map +1 -1
  18. package/built/src/blockchainClient/blockchainClient.js +56 -53
  19. package/built/src/blockchainClient/blockchainClient.js.map +1 -1
  20. package/built/src/blockchainClient/clientStub.js +18 -16
  21. package/built/src/blockchainClient/clientStub.js.map +1 -1
  22. package/built/src/blockchainClient/enums.d.ts +5 -0
  23. package/built/src/blockchainClient/enums.js +6 -0
  24. package/built/src/blockchainClient/enums.js.map +1 -1
  25. package/built/src/blockchainClient/errors.d.ts +20 -0
  26. package/built/src/blockchainClient/errors.js +41 -0
  27. package/built/src/blockchainClient/errors.js.map +1 -1
  28. package/built/src/{restclient → blockchainClient}/failoverStrategies.d.ts +14 -0
  29. package/built/src/{restclient → blockchainClient}/failoverStrategies.js +104 -24
  30. package/built/src/blockchainClient/failoverStrategies.js.map +1 -0
  31. package/built/src/blockchainClient/httpUtil.d.ts +4 -0
  32. package/built/src/{restclient → blockchainClient}/httpUtil.js +27 -23
  33. package/built/src/blockchainClient/httpUtil.js.map +1 -0
  34. package/built/src/blockchainClient/interface.d.ts +48 -59
  35. package/built/src/{restclient → blockchainClient}/nodeManager.d.ts +3 -0
  36. package/built/src/{restclient → blockchainClient}/nodeManager.js +7 -0
  37. package/built/src/blockchainClient/nodeManager.js.map +1 -0
  38. package/built/src/blockchainClient/requestWithFailoverStrategy.d.ts +4 -0
  39. package/built/src/blockchainClient/requestWithFailoverStrategy.js +31 -0
  40. package/built/src/blockchainClient/requestWithFailoverStrategy.js.map +1 -0
  41. package/built/src/blockchainClient/types.d.ts +64 -20
  42. package/built/src/blockchainClient/utils.d.ts +47 -12
  43. package/built/src/blockchainClient/utils.js +149 -30
  44. package/built/src/blockchainClient/utils.js.map +1 -1
  45. package/built/src/blockchainClient/validation/merkleHash.js +2 -1
  46. package/built/src/blockchainClient/validation/merkleHash.js.map +1 -1
  47. package/built/src/blockchainClient/validation/rawGtx.d.ts +2 -0
  48. package/built/src/blockchainClient/validation/rawGtx.js +22 -0
  49. package/built/src/blockchainClient/validation/rawGtx.js.map +1 -0
  50. package/built/src/blockchainClient/validation/requests.d.ts +5 -2
  51. package/built/src/blockchainClient/validation/requests.js +26 -0
  52. package/built/src/blockchainClient/validation/requests.js.map +1 -1
  53. package/built/src/blockchainClient/validation/transactionStatusReponse.d.ts +2 -0
  54. package/built/src/blockchainClient/validation/transactionStatusReponse.js +24 -0
  55. package/built/src/blockchainClient/validation/transactionStatusReponse.js.map +1 -0
  56. package/built/src/blockchainClient/validation/txRid.js +1 -1
  57. package/built/src/blockchainClient/validation/txRid.js.map +1 -1
  58. package/built/src/encryption/encryption.d.ts +0 -1
  59. package/built/src/encryption/encryption.js +0 -2
  60. package/built/src/encryption/encryption.js.map +1 -1
  61. package/built/src/formatter.d.ts +5 -7
  62. package/built/src/formatter.js +10 -29
  63. package/built/src/formatter.js.map +1 -1
  64. package/built/src/gtv/index.d.ts +3 -2
  65. package/built/src/gtv/index.js +4 -6
  66. package/built/src/gtv/index.js.map +1 -1
  67. package/built/src/gtx/errors.d.ts +2 -1
  68. package/built/src/gtx/errors.js.map +1 -1
  69. package/built/src/gtx/gtx.d.ts +5 -2
  70. package/built/src/gtx/gtx.js +0 -7
  71. package/built/src/gtx/gtx.js.map +1 -1
  72. package/built/src/gtx/serialization.d.ts +0 -1
  73. package/built/src/gtx/serialization.js +0 -1
  74. package/built/src/gtx/serialization.js.map +1 -1
  75. package/built/src/gtx/types.d.ts +0 -8
  76. package/built/src/logger.d.ts +6 -9
  77. package/built/src/logger.js +8 -14
  78. package/built/src/logger.js.map +1 -1
  79. package/built/src/promiEvent/promiEventEmitter.d.ts +1 -8
  80. package/built/src/promiEvent/promiEventEmitter.js.map +1 -1
  81. package/built/src/utils/calculateTransactionRid.d.ts +1 -1
  82. package/built/src/utils/calculateTransactionRid.js +6 -6
  83. package/built/src/utils/calculateTransactionRid.js.map +1 -1
  84. package/built/src/utils/constants.d.ts +4 -0
  85. package/built/src/utils/constants.js +5 -0
  86. package/built/src/utils/constants.js.map +1 -0
  87. package/built/src/utils/decodeTransactionToGtx.d.ts +1 -1
  88. package/built/src/utils/decodeTransactionToGtx.js +4 -3
  89. package/built/src/utils/decodeTransactionToGtx.js.map +1 -1
  90. package/built/src/utils/encodeTransaction.d.ts +1 -1
  91. package/built/src/utils/encodeTransaction.js +4 -4
  92. package/built/src/utils/encodeTransaction.js.map +1 -1
  93. package/built/test/common/mocks.d.ts +118 -0
  94. package/built/test/common/mocks.js +239 -0
  95. package/built/test/common/mocks.js.map +1 -0
  96. package/built/test/{unit/gtx → common}/serializationtestobjects.d.ts +1 -1
  97. package/built/test/common/serializationtestobjects.js.map +1 -0
  98. package/built/test/common/setups.d.ts +27 -0
  99. package/built/test/common/setups.js +137 -0
  100. package/built/test/common/setups.js.map +1 -0
  101. package/built/test/{unit → common}/signatures.d.ts +0 -1
  102. package/built/test/{unit → common}/signatures.js +0 -1
  103. package/built/test/common/signatures.js.map +1 -0
  104. package/built/test/common/testData.js.map +1 -0
  105. package/built/test/{unit/validation → common}/validationMocks.d.ts +22 -2
  106. package/built/test/{unit/validation → common}/validationMocks.js +13 -1
  107. package/built/test/common/validationMocks.js.map +1 -0
  108. package/built/test/integration/clientGetBlockInfo.test.js +51 -0
  109. package/built/test/integration/clientGetBlockInfo.test.js.map +1 -0
  110. package/built/test/integration/clientGetRejectedTransactions.test.js +28 -0
  111. package/built/test/integration/clientGetRejectedTransactions.test.js.map +1 -0
  112. package/built/test/integration/clientGetTransaction.test.js +29 -0
  113. package/built/test/integration/clientGetTransaction.test.js.map +1 -0
  114. package/built/test/integration/clientGetTransactionStatus.test.js +71 -0
  115. package/built/test/integration/clientGetTransactionStatus.test.js.map +1 -0
  116. package/built/test/integration/clientGetWaitingTransaction.test.js +34 -0
  117. package/built/test/integration/clientGetWaitingTransaction.test.js.map +1 -0
  118. package/built/test/integration/clientGetWaitingTransactions.test.js +28 -0
  119. package/built/test/integration/clientGetWaitingTransactions.test.js.map +1 -0
  120. package/built/test/integration/clientIntegration.test.js +95 -0
  121. package/built/test/integration/clientIntegration.test.js.map +1 -0
  122. package/built/test/integration/clientQuery.test.js +380 -0
  123. package/built/test/integration/clientQuery.test.js.map +1 -0
  124. package/built/test/integration/clientSendTransaction.test.js +86 -0
  125. package/built/test/integration/clientSendTransaction.test.js.map +1 -0
  126. package/built/test/integration/clientSignAndSendUniqueTransaction.test.js +75 -0
  127. package/built/test/integration/clientSignAndSendUniqueTransaction.test.js.map +1 -0
  128. package/built/test/integration/clientSignTransaction.test.js +77 -0
  129. package/built/test/integration/clientSignTransaction.test.js.map +1 -0
  130. package/built/test/integration/{blockchainClientUtils.test.js → clientUtils.test.js} +13 -8
  131. package/built/test/integration/clientUtils.test.js.map +1 -0
  132. package/built/test/integration/createClientIntegration.test.js +158 -0
  133. package/built/test/integration/createClientIntegration.test.js.map +1 -0
  134. package/built/test/integration/encodeTransaction.test.js +3 -6
  135. package/built/test/integration/encodeTransaction.test.js.map +1 -1
  136. package/built/test/integration/getTransactionsInfo.test.js +17 -26
  137. package/built/test/integration/getTransactionsInfo.test.js.map +1 -1
  138. package/built/test/integration/signAndSendUniqueTransaction.test.js +26 -19
  139. package/built/test/integration/signAndSendUniqueTransaction.test.js.map +1 -1
  140. package/built/test/integrationChromiaNetwork/createIccfProofTx.test.js +59 -0
  141. package/built/test/integrationChromiaNetwork/createIccfProofTx.test.js.map +1 -0
  142. package/built/test/{integrationDevnet → integrationChromiaNetwork}/getAnchoringStatusForBlockRid.test.js +9 -15
  143. package/built/test/integrationChromiaNetwork/getAnchoringStatusForBlockRid.test.js.map +1 -0
  144. package/built/test/{integrationDevnet → integrationChromiaNetwork}/getTransactionConfirmationLevel.test.js +7 -13
  145. package/built/test/integrationChromiaNetwork/getTransactionConfirmationLevel.test.js.map +1 -0
  146. package/built/test/integrationChromiaNetwork/getTransactionStatus.test.js +45 -0
  147. package/built/test/integrationChromiaNetwork/getTransactionStatus.test.js.map +1 -0
  148. package/built/test/integrationChromiaNetwork/isBlockAnchored.test.js +35 -0
  149. package/built/test/integrationChromiaNetwork/isBlockAnchored.test.js.map +1 -0
  150. package/built/test/integrationChromiaNetwork/merkleHashIntegration.test.d.ts +1 -0
  151. package/built/test/integrationChromiaNetwork/merkleHashIntegration.test.js +134 -0
  152. package/built/test/integrationChromiaNetwork/merkleHashIntegration.test.js.map +1 -0
  153. package/built/test/integrationChromiaNetwork/nodeDiscovery.test.d.ts +1 -0
  154. package/built/test/integrationChromiaNetwork/nodeDiscovery.test.js +26 -0
  155. package/built/test/integrationChromiaNetwork/nodeDiscovery.test.js.map +1 -0
  156. package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.d.ts +1 -0
  157. package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.js +84 -0
  158. package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.js.map +1 -0
  159. package/built/test/integrationChromiaNetwork/signAndSendUniqueTransaction.test.d.ts +1 -0
  160. package/built/test/{integrationDevnet → integrationChromiaNetwork}/signAndSendUniqueTransaction.test.js +27 -44
  161. package/built/test/integrationChromiaNetwork/signAndSendUniqueTransaction.test.js.map +1 -0
  162. package/built/test/manual/iccfManually.test.js +18 -27
  163. package/built/test/manual/iccfManually.test.js.map +1 -1
  164. package/built/test/pcctf/getSuites.test.d.ts +1 -0
  165. package/built/test/pcctf/getSuites.test.js +106 -0
  166. package/built/test/pcctf/getSuites.test.js.map +1 -0
  167. package/built/test/pcctf/helpers.d.ts +92 -0
  168. package/built/test/pcctf/helpers.js +239 -0
  169. package/built/test/pcctf/helpers.js.map +1 -0
  170. package/built/test/unit/ICCF/iccf.test.js +63 -158
  171. package/built/test/unit/ICCF/iccf.test.js.map +1 -1
  172. package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.d.ts +1 -2
  173. package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js +101 -296
  174. package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js.map +1 -1
  175. package/built/test/unit/blockchainClient/client.getRejectedTransactions.test.d.ts +1 -0
  176. package/built/test/unit/blockchainClient/client.getRejectedTransactions.test.js +48 -0
  177. package/built/test/unit/blockchainClient/client.getRejectedTransactions.test.js.map +1 -0
  178. package/built/test/unit/blockchainClient/client.getWaitingTransaction.test.d.ts +1 -0
  179. package/built/test/unit/blockchainClient/client.getWaitingTransaction.test.js +38 -0
  180. package/built/test/unit/blockchainClient/client.getWaitingTransaction.test.js.map +1 -0
  181. package/built/test/unit/blockchainClient/client.getWaitingTransactions.test.d.ts +1 -0
  182. package/built/test/unit/blockchainClient/client.getWaitingTransactions.test.js +30 -0
  183. package/built/test/unit/blockchainClient/client.getWaitingTransactions.test.js.map +1 -0
  184. package/built/test/unit/blockchainClient/client.test.d.ts +1 -0
  185. package/built/test/unit/blockchainClient/client.test.js +177 -0
  186. package/built/test/unit/blockchainClient/client.test.js.map +1 -0
  187. package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.js +26 -32
  188. package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.js.map +1 -1
  189. package/built/test/unit/blockchainClient/getAnchoringStatusForBlockRid.test.js +26 -59
  190. package/built/test/unit/blockchainClient/getAnchoringStatusForBlockRid.test.js.map +1 -1
  191. package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.js +21 -38
  192. package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.js.map +1 -1
  193. package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js +77 -127
  194. package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js.map +1 -1
  195. package/built/test/unit/blockchainClient/sendTransaction.test.js +352 -675
  196. package/built/test/unit/blockchainClient/sendTransaction.test.js.map +1 -1
  197. package/built/test/unit/blockchainClient/setMerkleVersion.test.js +14 -28
  198. package/built/test/unit/blockchainClient/setMerkleVersion.test.js.map +1 -1
  199. package/built/test/unit/blockchainClient/signAndSendUniqueTransactionPromiEvents.test.js +31 -98
  200. package/built/test/unit/blockchainClient/signAndSendUniqueTransactionPromiEvents.test.js.map +1 -1
  201. package/built/test/unit/blockchainClient/statusPollIntervals.test.js +34 -54
  202. package/built/test/unit/blockchainClient/statusPollIntervals.test.js.map +1 -1
  203. package/built/test/unit/blockchainClient/util.test.js +74 -133
  204. package/built/test/unit/blockchainClient/util.test.js.map +1 -1
  205. package/built/test/unit/decodeTransactionToGtx.test.js +3 -4
  206. package/built/test/unit/decodeTransactionToGtx.test.js.map +1 -1
  207. package/built/test/unit/dump.test.js +2 -3
  208. package/built/test/unit/dump.test.js.map +1 -1
  209. package/built/test/unit/encryption/encryption.test.js +23 -32
  210. package/built/test/unit/encryption/encryption.test.js.map +1 -1
  211. package/built/test/unit/failoverStrategies.test.js +122 -114
  212. package/built/test/unit/failoverStrategies.test.js.map +1 -1
  213. package/built/test/unit/formatter.test.js +38 -42
  214. package/built/test/unit/formatter.test.js.map +1 -1
  215. package/built/test/unit/gtv/gtvHash.test.js +5 -6
  216. package/built/test/unit/gtv/gtvHash.test.js.map +1 -1
  217. package/built/test/unit/gtx/checkGTXSignature.test.js +5 -7
  218. package/built/test/unit/gtx/checkGTXSignature.test.js.map +1 -1
  219. package/built/test/unit/gtx/newSignatureProvider.test.js +9 -10
  220. package/built/test/unit/gtx/newSignatureProvider.test.js.map +1 -1
  221. package/built/test/unit/gtx/serialization.test.js +37 -138
  222. package/built/test/unit/gtx/serialization.test.js.map +1 -1
  223. package/built/test/unit/httpUtil.test.js +27 -18
  224. package/built/test/unit/httpUtil.test.js.map +1 -1
  225. package/built/test/unit/logger.test.js +23 -25
  226. package/built/test/unit/logger.test.js.map +1 -1
  227. package/built/test/unit/nodeMananger.test.js +62 -74
  228. package/built/test/unit/nodeMananger.test.js.map +1 -1
  229. package/built/test/unit/setOrdering.test.js +9 -9
  230. package/built/test/unit/setOrdering.test.js.map +1 -1
  231. package/built/test/unit/stickyNode.test.js +44 -54
  232. package/built/test/unit/stickyNode.test.js.map +1 -1
  233. package/built/test/unit/validation/anchoringTransaction.test.js +7 -8
  234. package/built/test/unit/validation/anchoringTransaction.test.js.map +1 -1
  235. package/built/test/unit/validation/blockIdentifier.test.js +7 -9
  236. package/built/test/unit/validation/blockIdentifier.test.js.map +1 -1
  237. package/built/test/unit/validation/bufferSchema.test.js +4 -5
  238. package/built/test/unit/validation/bufferSchema.test.js.map +1 -1
  239. package/built/test/unit/validation/networkSettings.test.js +11 -13
  240. package/built/test/unit/validation/networkSettings.test.js.map +1 -1
  241. package/built/test/unit/validation/rawGtx.test.d.ts +1 -0
  242. package/built/test/unit/validation/rawGtx.test.js +84 -0
  243. package/built/test/unit/validation/rawGtx.test.js.map +1 -0
  244. package/built/test/unit/validation/requests.test.js +80 -74
  245. package/built/test/unit/validation/requests.test.js.map +1 -1
  246. package/built/test/unit/validation/signMethod.test.js +8 -10
  247. package/built/test/unit/validation/signMethod.test.js.map +1 -1
  248. package/built/test/unit/validation/statusObject.test.d.ts +1 -0
  249. package/built/test/unit/validation/statusObject.test.js +91 -0
  250. package/built/test/unit/validation/statusObject.test.js.map +1 -0
  251. package/built/test/unit/validation/txRid.test.js +7 -9
  252. package/built/test/unit/validation/txRid.test.js.map +1 -1
  253. package/built/umd/index.js +31711 -31107
  254. package/built/umd/index.js.map +1 -1
  255. package/package.json +26 -22
  256. package/built/src/chromia/chromiaClientProvider.d.ts +0 -9
  257. package/built/src/chromia/chromiaClientProvider.js +0 -36
  258. package/built/src/chromia/chromiaClientProvider.js.map +0 -1
  259. package/built/src/chromia/interfaces.d.ts +0 -4
  260. package/built/src/chromia/interfaces.js +0 -2
  261. package/built/src/chromia/interfaces.js.map +0 -1
  262. package/built/src/constants.d.ts +0 -3
  263. package/built/src/constants.js +0 -4
  264. package/built/src/constants.js.map +0 -1
  265. package/built/src/gtx/gtxclient.d.ts +0 -3
  266. package/built/src/gtx/gtxclient.js +0 -96
  267. package/built/src/gtx/gtxclient.js.map +0 -1
  268. package/built/src/gtx/interfaces.d.ts +0 -91
  269. package/built/src/gtx/interfaces.js +0 -2
  270. package/built/src/gtx/interfaces.js.map +0 -1
  271. package/built/src/merkle/binarytree.d.ts +0 -131
  272. package/built/src/merkle/binarytree.js +0 -146
  273. package/built/src/merkle/binarytree.js.map +0 -1
  274. package/built/src/merkle/binarytreefactory.d.ts +0 -86
  275. package/built/src/merkle/binarytreefactory.js +0 -251
  276. package/built/src/merkle/binarytreefactory.js.map +0 -1
  277. package/built/src/merkle/merkleHelper.d.ts +0 -18
  278. package/built/src/merkle/merkleHelper.js +0 -110
  279. package/built/src/merkle/merkleHelper.js.map +0 -1
  280. package/built/src/merkle/merklehashcalculator.d.ts +0 -37
  281. package/built/src/merkle/merklehashcalculator.js +0 -73
  282. package/built/src/merkle/merklehashcalculator.js.map +0 -1
  283. package/built/src/merkle/path.d.ts +0 -151
  284. package/built/src/merkle/path.js +0 -306
  285. package/built/src/merkle/path.js.map +0 -1
  286. package/built/src/merkle/proof/merklehashcarrier.d.ts +0 -17
  287. package/built/src/merkle/proof/merklehashcarrier.js +0 -23
  288. package/built/src/merkle/proof/merklehashcarrier.js.map +0 -1
  289. package/built/src/merkle/proof/merklehashsummaryfactory.d.ts +0 -53
  290. package/built/src/merkle/proof/merklehashsummaryfactory.js +0 -82
  291. package/built/src/merkle/proof/merklehashsummaryfactory.js.map +0 -1
  292. package/built/src/merkle/proof/merkleproof.d.ts +0 -36
  293. package/built/src/merkle/proof/merkleproof.js +0 -61
  294. package/built/src/merkle/proof/merkleproof.js.map +0 -1
  295. package/built/src/merkle/proof/merkleprooftree.d.ts +0 -124
  296. package/built/src/merkle/proof/merkleprooftree.js +0 -117
  297. package/built/src/merkle/proof/merkleprooftree.js.map +0 -1
  298. package/built/src/merkle/proof/merkleprooftreefactory.d.ts +0 -47
  299. package/built/src/merkle/proof/merkleprooftreefactory.js +0 -123
  300. package/built/src/merkle/proof/merkleprooftreefactory.js.map +0 -1
  301. package/built/src/merkle/types.d.ts +0 -11
  302. package/built/src/merkle/types.js +0 -2
  303. package/built/src/merkle/types.js.map +0 -1
  304. package/built/src/restclient/enums.d.ts +0 -4
  305. package/built/src/restclient/enums.js +0 -6
  306. package/built/src/restclient/enums.js.map +0 -1
  307. package/built/src/restclient/errors.d.ts +0 -33
  308. package/built/src/restclient/errors.js +0 -63
  309. package/built/src/restclient/errors.js.map +0 -1
  310. package/built/src/restclient/failoverStrategies.js.map +0 -1
  311. package/built/src/restclient/httpUtil.d.ts +0 -6
  312. package/built/src/restclient/httpUtil.js.map +0 -1
  313. package/built/src/restclient/interfaces.d.ts +0 -68
  314. package/built/src/restclient/interfaces.js +0 -2
  315. package/built/src/restclient/interfaces.js.map +0 -1
  316. package/built/src/restclient/nodeManager.js.map +0 -1
  317. package/built/src/restclient/restclient.d.ts +0 -18
  318. package/built/src/restclient/restclient.js +0 -200
  319. package/built/src/restclient/restclient.js.map +0 -1
  320. package/built/src/restclient/restclientutil.d.ts +0 -32
  321. package/built/src/restclient/restclientutil.js +0 -141
  322. package/built/src/restclient/restclientutil.js.map +0 -1
  323. package/built/src/restclient/types.d.ts +0 -78
  324. package/built/src/restclient/types.js +0 -2
  325. package/built/src/restclient/types.js.map +0 -1
  326. package/built/test/integration/blockchainClientIntegration.test.js +0 -1075
  327. package/built/test/integration/blockchainClientIntegration.test.js.map +0 -1
  328. package/built/test/integration/blockchainClientUtils.test.js.map +0 -1
  329. package/built/test/integration/gtxClientIntegration.test.js +0 -334
  330. package/built/test/integration/gtxClientIntegration.test.js.map +0 -1
  331. package/built/test/integration/merkleIntegration.test.js +0 -138
  332. package/built/test/integration/merkleIntegration.test.js.map +0 -1
  333. package/built/test/integration/objectGenerator.d.ts +0 -3
  334. package/built/test/integration/objectGenerator.js +0 -17
  335. package/built/test/integration/objectGenerator.js.map +0 -1
  336. package/built/test/integration/restClientIntegration.test.js +0 -170
  337. package/built/test/integration/restClientIntegration.test.js.map +0 -1
  338. package/built/test/integration/testData.js.map +0 -1
  339. package/built/test/integrationDevnet/constants.d.ts +0 -1
  340. package/built/test/integrationDevnet/constants.js +0 -2
  341. package/built/test/integrationDevnet/constants.js.map +0 -1
  342. package/built/test/integrationDevnet/getAnchoringStatusForBlockRid.test.js.map +0 -1
  343. package/built/test/integrationDevnet/getTransactionConfirmationLevel.test.js.map +0 -1
  344. package/built/test/integrationDevnet/getTransactionStatus.test.js +0 -53
  345. package/built/test/integrationDevnet/getTransactionStatus.test.js.map +0 -1
  346. package/built/test/integrationDevnet/signAndSendUniqueTransaction.test.js.map +0 -1
  347. package/built/test/manual/chromiaClientProviderManually.test.js +0 -28
  348. package/built/test/manual/chromiaClientProviderManually.test.js.map +0 -1
  349. package/built/test/manual/restClientManually.test.js +0 -52
  350. package/built/test/manual/restClientManually.test.js.map +0 -1
  351. package/built/test/unit/ICCF/util.d.ts +0 -6
  352. package/built/test/unit/ICCF/util.js +0 -21
  353. package/built/test/unit/ICCF/util.js.map +0 -1
  354. package/built/test/unit/blockchainClient/blockchainClient.test.js +0 -287
  355. package/built/test/unit/blockchainClient/blockchainClient.test.js.map +0 -1
  356. package/built/test/unit/blockchainClient/helpers/sendTransaction.d.ts +0 -25
  357. package/built/test/unit/blockchainClient/helpers/sendTransaction.js +0 -56
  358. package/built/test/unit/blockchainClient/helpers/sendTransaction.js.map +0 -1
  359. package/built/test/unit/chromiaClientProvider.test.js +0 -70
  360. package/built/test/unit/chromiaClientProvider.test.js.map +0 -1
  361. package/built/test/unit/common/mocks.d.ts +0 -34
  362. package/built/test/unit/common/mocks.js +0 -69
  363. package/built/test/unit/common/mocks.js.map +0 -1
  364. package/built/test/unit/gtx/gtxClient.test.js +0 -97
  365. package/built/test/unit/gtx/gtxClient.test.js.map +0 -1
  366. package/built/test/unit/gtx/serializationtestobjects.js.map +0 -1
  367. package/built/test/unit/merkle/merkleHelper/merkleHelperTest.js +0 -87
  368. package/built/test/unit/merkle/merkleHelper/merkleHelperTest.js.map +0 -1
  369. package/built/test/unit/requestWithFailoverStrategy.test.js +0 -146
  370. package/built/test/unit/requestWithFailoverStrategy.test.js.map +0 -1
  371. package/built/test/unit/restClient.test.js +0 -389
  372. package/built/test/unit/restClient.test.js.map +0 -1
  373. package/built/test/unit/restClientUtil.test.js +0 -226
  374. package/built/test/unit/restClientUtil.test.js.map +0 -1
  375. package/built/test/unit/signatures.js.map +0 -1
  376. package/built/test/unit/validation/validationMocks.js.map +0 -1
  377. package/changelog.md +0 -586
  378. /package/built/test/{unit/gtx → common}/serializationtestobjects.js +0 -0
  379. /package/built/test/{integration → common}/testData.d.ts +0 -0
  380. /package/built/test/{integration → common}/testData.js +0 -0
  381. /package/built/test/integration/{blockchainClientIntegration.test.d.ts → clientGetBlockInfo.test.d.ts} +0 -0
  382. /package/built/test/integration/{blockchainClientUtils.test.d.ts → clientGetRejectedTransactions.test.d.ts} +0 -0
  383. /package/built/test/integration/{gtxClientIntegration.test.d.ts → clientGetTransaction.test.d.ts} +0 -0
  384. /package/built/test/integration/{merkleIntegration.test.d.ts → clientGetTransactionStatus.test.d.ts} +0 -0
  385. /package/built/test/integration/{restClientIntegration.test.d.ts → clientGetWaitingTransaction.test.d.ts} +0 -0
  386. /package/built/test/{integrationDevnet/getAnchoringStatusForBlockRid.test.d.ts → integration/clientGetWaitingTransactions.test.d.ts} +0 -0
  387. /package/built/test/{integrationDevnet/getTransactionConfirmationLevel.test.d.ts → integration/clientIntegration.test.d.ts} +0 -0
  388. /package/built/test/{integrationDevnet/getTransactionStatus.test.d.ts → integration/clientQuery.test.d.ts} +0 -0
  389. /package/built/test/{integrationDevnet/signAndSendUniqueTransaction.test.d.ts → integration/clientSendTransaction.test.d.ts} +0 -0
  390. /package/built/test/{manual/chromiaClientProviderManually.test.d.ts → integration/clientSignAndSendUniqueTransaction.test.d.ts} +0 -0
  391. /package/built/test/{manual/restClientManually.test.d.ts → integration/clientSignTransaction.test.d.ts} +0 -0
  392. /package/built/test/{unit/blockchainClient/blockchainClient.test.d.ts → integration/clientUtils.test.d.ts} +0 -0
  393. /package/built/test/{unit/chromiaClientProvider.test.d.ts → integration/createClientIntegration.test.d.ts} +0 -0
  394. /package/built/test/{unit/gtx/gtxClient.test.d.ts → integrationChromiaNetwork/createIccfProofTx.test.d.ts} +0 -0
  395. /package/built/test/{unit/merkle/merkleHelper/merkleHelperTest.d.ts → integrationChromiaNetwork/getAnchoringStatusForBlockRid.test.d.ts} +0 -0
  396. /package/built/test/{unit/requestWithFailoverStrategy.test.d.ts → integrationChromiaNetwork/getTransactionConfirmationLevel.test.d.ts} +0 -0
  397. /package/built/test/{unit/restClient.test.d.ts → integrationChromiaNetwork/getTransactionStatus.test.d.ts} +0 -0
  398. /package/built/test/{unit/restClientUtil.test.d.ts → integrationChromiaNetwork/isBlockAnchored.test.d.ts} +0 -0
@@ -1,146 +0,0 @@
1
- "use strict";
2
- var PathLeafElement = require('./path').PathLeafElement;
3
- const HASH_PREFIX_NODE = 0;
4
- const HASH_PREFIX_LEAF = 1;
5
- const HASH_PREFIX_NODE_ARRAY = 7;
6
- const HASH_PREFIX_NODE_DICT = 8;
7
- /**
8
- *
9
- */
10
- function BinaryTreeElement() {
11
- this.pathElem = null;
12
- }
13
- BinaryTreeElement.prototype.isPath = function () {
14
- return this.pathElem != null;
15
- };
16
- BinaryTreeElement.prototype.isPathLeaf = function () {
17
- if (this.pathElem == null) {
18
- return false;
19
- }
20
- if (this.pathElem instanceof PathLeafElement) {
21
- return true;
22
- }
23
- else {
24
- return false;
25
- }
26
- };
27
- BinaryTreeElement.prototype.setPathElement = function (pathElem) {
28
- this.pathElem = pathElem;
29
- };
30
- BinaryTreeElement.prototype.getPrefixByte = function () {
31
- return HASH_PREFIX_NODE;
32
- };
33
- /**
34
- *
35
- * @param {BinaryTreeElement} left
36
- * @param {BinaryTreeElement} right
37
- */
38
- function Node(left, right) {
39
- this.left = left;
40
- this.right = right;
41
- }
42
- Node.prototype = Object.create(BinaryTreeElement.prototype);
43
- Node.prototype.constructor = Node;
44
- Node.prototype.getPrefixByte = function () {
45
- return HASH_PREFIX_NODE;
46
- };
47
- /**
48
- *
49
- * @param {BinaryTreeElement} left
50
- * @param {BinaryTreeElement} right
51
- * @param {*} content
52
- * @param {PathSet} pathElem
53
- */
54
- function SubTreeRootNode(left, right, content, pathElem) {
55
- Node.call(this, left, right);
56
- this.content = content;
57
- BinaryTreeElement.prototype.setPathElement.call(this, pathElem);
58
- }
59
- SubTreeRootNode.prototype = Object.create(Node.prototype);
60
- SubTreeRootNode.prototype.constructor = SubTreeRootNode;
61
- /**
62
- *
63
- * @param {*} content
64
- * @param {PathElement} pathElem
65
- */
66
- function Leaf(content, pathElem = null) {
67
- this.content = content;
68
- if (pathElem != null) {
69
- if (pathElem instanceof PathLeafElement) {
70
- BinaryTreeElement.prototype.setPathElement.call(this, pathElem);
71
- }
72
- else {
73
- throw new Error("The path and object structure does not match! We are at a leaf, but the path expects a sub structure.");
74
- }
75
- }
76
- }
77
- Leaf.prototype = Object.create(BinaryTreeElement.prototype);
78
- Leaf.prototype.constructor = Leaf;
79
- Leaf.prototype.getPrefixByte = function () {
80
- return HASH_PREFIX_LEAF;
81
- };
82
- function EmptyLeaf() { }
83
- EmptyLeaf.prototype = Object.create(BinaryTreeElement.prototype);
84
- EmptyLeaf.prototype.constructor = EmptyLeaf;
85
- /**
86
- * Wrapper class for the root object.
87
- * @param {BinaryTreeElement} root
88
- */
89
- function BinaryTree(root) {
90
- this.root = root;
91
- }
92
- BinaryTree.prototype.maxLevel = function () {
93
- return this.maxLevelInternal(this.root);
94
- };
95
- BinaryTree.prototype.maxLevelInternal = function (node) {
96
- if (node instanceof EmptyLeaf) {
97
- return 0;
98
- }
99
- else if (node instanceof Leaf) {
100
- return 1;
101
- }
102
- else if (node instanceof Node) {
103
- return Math.max(this.maxLevelInternal(node.left), this.maxLevelInternal(node.right)) + 1;
104
- }
105
- else {
106
- throw new Error("What is this type? " + typeof node);
107
- }
108
- };
109
- /**
110
- * Represents the top of a sub tree generated by a [Array]
111
- *
112
- * @param {*} left
113
- * @param {*} right
114
- * @param {*} content
115
- * @param {*} size
116
- * @param {PathElement} pathElem
117
- */
118
- function ArrayHeadNode(left, right, content, size, pathElem = null) {
119
- SubTreeRootNode.call(this, left, right, content, pathElem);
120
- this.size = size;
121
- }
122
- ArrayHeadNode.prototype = Object.create(SubTreeRootNode.prototype);
123
- ArrayHeadNode.prototype.constructor = ArrayHeadNode;
124
- ArrayHeadNode.prototype.getPrefixByte = function () {
125
- return HASH_PREFIX_NODE_ARRAY;
126
- };
127
- /**
128
- * Represents the top a sub tree generated by a [Dictionary]
129
- * @param {*} left
130
- * @param {*} right
131
- * @param {*} content
132
- * @param {*} size
133
- * @param {PathElement} pathElem
134
- */
135
- function DictHeadNode(left, right, content, size, pathElem = null) {
136
- SubTreeRootNode.call(this, left, right, content, pathElem);
137
- this.size = size;
138
- }
139
- DictHeadNode.prototype = Object.create(SubTreeRootNode.prototype);
140
- DictHeadNode.prototype.constructor = DictHeadNode;
141
- DictHeadNode.prototype.getPrefixByte = function () {
142
- return HASH_PREFIX_NODE_DICT;
143
- };
144
- module.exports = { HASH_PREFIX_NODE, HASH_PREFIX_LEAF, HASH_PREFIX_NODE_ARRAY, HASH_PREFIX_NODE_DICT,
145
- Node, Leaf, EmptyLeaf, SubTreeRootNode, BinaryTreeElement, BinaryTree, ArrayHeadNode, DictHeadNode };
146
- //# sourceMappingURL=binarytree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"binarytree.js","sourceRoot":"","sources":["../../../src/merkle/binarytree.js"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,IAAI,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAA;AAEvD,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAC1B,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAC1B,MAAM,sBAAsB,GAAG,CAAC,CAAA;AAChC,MAAM,qBAAqB,GAAG,CAAC,CAAA;AAE/B;;GAEG;AACH,SAAS,iBAAiB;IACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;AACtB,CAAC;AACD,iBAAiB,CAAC,SAAS,CAAC,MAAM,GAAG;IACnC,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAA;AAC9B,CAAC,CAAA;AACD,iBAAiB,CAAC,SAAS,CAAC,UAAU,GAAG;IACvC,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,YAAY,eAAe,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAA;IACb,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AACD,iBAAiB,CAAC,SAAS,CAAC,cAAc,GAAG,UAAS,QAAQ;IAC5D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;AAC1B,CAAC,CAAA;AACD,iBAAiB,CAAC,SAAS,CAAC,aAAa,GAAG;IAC1C,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAA;AAED;;;;GAIG;AACH,SAAS,IAAI,CAAC,IAAI,EAAE,KAAK;IACvB,IAAI,CAAC,IAAI,GAAG,IAAI,C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AE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;AAClB,CAAC;AAED,aAAa,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;AAClE,aAAa,CAAC,SAAS,CAAC,WAAW,GAAG,aAAa,CAAA;AACnD,aAAa,CAAC,SAAS,CAAC,aAAa,GAAG;IACtC,OAAO,sBAAsB,CAAA;AAC/B,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,GAAC,IAAI;IAC7D,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;AAClB,CAAC;AAED,YAAY,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;AACjE,YAAY,CAAC,SAAS,CAAC,WAAW,GAAG,YAAY,CAAA;AACjD,YAAY,CAAC,SAAS,CAAC,aAAa,GAAG;IACrC,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,EAAC,gBAAgB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,qBAAqB;IACjG,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAC,CAAA"}
@@ -1,86 +0,0 @@
1
- /**
2
- * The factory does the conversion between list of elements and tree of elements.
3
- *
4
- * Note: The idea is that you should sub class for each type of element you want to build.
5
- */
6
- export function BinaryTreeFactory(): void;
7
- export class BinaryTreeFactory {
8
- /**
9
- * Transforms the incoming leaf into an [BinaryTreeElement]
10
- * The idea with this function is that it can be recursive (if the leaf in turn is complex object with sub objects).
11
- *
12
- * Note: If we don't have a path here we can try to find the leaf in the cache.
13
- *
14
- * @param leaf the raw data we should wrap in a leaf
15
- * @param paths a collection of proof paths that might point to this leaf
16
- * @return the resulting [BinaryTreeElement] the leaf got converted to
17
- */
18
- handleLeaf(leaf: any, paths: any, isRoot: boolean | undefined, merkleHashVersion: any): Leaf | ArrayHeadNode | DictHeadNode;
19
- /**
20
- *
21
- */
22
- getEmptyPathSet(): PathSet;
23
- /**
24
- * At this point we should have looked in cache.
25
- *
26
- * @param leaf we should turn into a tree element
27
- * @param {PathSet} paths
28
- * @return the tree element we created.
29
- */
30
- innerHandleLeaf(leaf: any, paths: PathSet, merkleHashVersion: any): Leaf | ArrayHeadNode | DictHeadNode;
31
- /**
32
- * Just like [handleLeaf] but we know that this leaf should not be a complex type, but something we can
33
- * immediately wrap
34
- *
35
- * @param leaf
36
- * @param {PathSet} paths
37
- */
38
- handlePrimitiveLeaf(leaf: any, paths: PathSet): Leaf;
39
- /**
40
- * Calls itself until the return value only holds 1 element
41
- *
42
- * Note: This method can only create standard [Node] that fills up the area between the "top" and the leaves.
43
- * These "in-between" nodes cannot be "path leaf" or have any interesting properties.
44
- *
45
- * @param layer What layer we aim calculate
46
- * @param inList The args of nodes we should build from
47
- * @return All [BinaryTreeElement] nodes of the next layer
48
- */
49
- buildHigherLayer(layer: any, inList: any): any;
50
- build(data: any, merkleHashVersion: any): BinaryTree;
51
- /**
52
- * @param {PathSet} paths
53
- */
54
- buildWithPath(data: any, paths: PathSet, merkleHashVersion: any): BinaryTree;
55
- /**
56
- * @param {Array} array
57
- * @param {PathSet} paths
58
- */
59
- buildFromArray(array: any[], paths: PathSet, merkleHashVersion: any): ArrayHeadNode;
60
- /**
61
- *
62
- */
63
- buildFromOneLeaf(array: any, orgRoot: any, pathElem: any): ArrayHeadNode;
64
- /**
65
- * @param {PathSet} paths
66
- */
67
- buildLeafElements(leafList: any, paths: PathSet, merkleHashVersion: any): any[];
68
- /**
69
- * @param {PathSet} paths
70
- */
71
- buildFromDictionary(dict: any, paths: PathSet, merkleHashVersion: any): DictHeadNode;
72
- /**
73
- * @param {PathSet} paths
74
- */
75
- buildLeafElementFromDict(keys: any, dict: any, paths: PathSet, merkleHashVersion: any): any[];
76
- }
77
- import Leaf_1 = require("./binarytree");
78
- import Leaf = Leaf_1.Leaf;
79
- import ArrayHeadNode_1 = require("./binarytree");
80
- import ArrayHeadNode = ArrayHeadNode_1.ArrayHeadNode;
81
- import DictHeadNode_1 = require("./binarytree");
82
- import DictHeadNode = DictHeadNode_1.DictHeadNode;
83
- import PathSet_1 = require("./path");
84
- import PathSet = PathSet_1.PathSet;
85
- import BinaryTree_1 = require("./binarytree");
86
- import BinaryTree = BinaryTree_1.BinaryTree;
@@ -1,251 +0,0 @@
1
- "use strict";
2
- var util = require('../formatter');
3
- const { Buffer } = require('buffer');
4
- var PathSet = require('./path').PathSet;
5
- var PathLeafElement = require('./path').PathLeafElement;
6
- var EmptyLeaf = require('./binarytree').EmptyLeaf;
7
- var Leaf = require('./binarytree').Leaf;
8
- var Node = require('./binarytree').Node;
9
- var BinaryTree = require('./binarytree').BinaryTree;
10
- var ArrayHeadNode = require('./binarytree').ArrayHeadNode;
11
- var DictHeadNode = require('./binarytree').DictHeadNode;
12
- const NO_PATHS = new PathSet([]);
13
- /**
14
- * The factory does the conversion between list of elements and tree of elements.
15
- *
16
- * Note: The idea is that you should sub class for each type of element you want to build.
17
- */
18
- function BinaryTreeFactory() { }
19
- /**
20
- * Transforms the incoming leaf into an [BinaryTreeElement]
21
- * The idea with this function is that it can be recursive (if the leaf in turn is complex object with sub objects).
22
- *
23
- * Note: If we don't have a path here we can try to find the leaf in the cache.
24
- *
25
- * @param leaf the raw data we should wrap in a leaf
26
- * @param paths a collection of proof paths that might point to this leaf
27
- * @return the resulting [BinaryTreeElement] the leaf got converted to
28
- */
29
- BinaryTreeFactory.prototype.handleLeaf = function (leaf, paths, isRoot = false, merkleHashVersion) {
30
- if (merkleHashVersion == undefined || merkleHashVersion == null) {
31
- console.error("stack trace", new Error().stack);
32
- throw new Error("Merkle hash version is undefined or null");
33
- }
34
- if (paths.length == 0 && !isRoot) {
35
- return this.innerHandleLeaf(leaf, this.getEmptyPathSet(), merkleHashVersion);
36
- }
37
- else {
38
- return this.innerHandleLeaf(leaf, paths, merkleHashVersion);
39
- }
40
- };
41
- /**
42
- *
43
- */
44
- BinaryTreeFactory.prototype.getEmptyPathSet = function () {
45
- return NO_PATHS;
46
- };
47
- /**
48
- * At this point we should have looked in cache.
49
- *
50
- * @param leaf we should turn into a tree element
51
- * @param {PathSet} paths
52
- * @return the tree element we created.
53
- */
54
- BinaryTreeFactory.prototype.innerHandleLeaf = function (leaf, paths, merkleHashVersion) {
55
- if (leaf == null) {
56
- return this.handlePrimitiveLeaf(leaf, paths);
57
- }
58
- if (Buffer.isBuffer(leaf)) {
59
- return this.handlePrimitiveLeaf(leaf, paths);
60
- }
61
- if (typeof leaf === 'string') {
62
- return this.handlePrimitiveLeaf(leaf, paths);
63
- }
64
- if (typeof leaf === 'number') {
65
- return this.handlePrimitiveLeaf(leaf, paths);
66
- }
67
- if (typeof leaf === 'bigint') {
68
- return this.handlePrimitiveLeaf(leaf, paths);
69
- }
70
- if (typeof leaf === 'boolean') {
71
- return this.handlePrimitiveLeaf(leaf ? 1 : 0, paths);
72
- }
73
- if (leaf.constructor === Array) {
74
- return this.buildFromArray(leaf, paths, merkleHashVersion);
75
- }
76
- if (typeof leaf === 'object') {
77
- return this.buildFromDictionary(leaf, paths, merkleHashVersion);
78
- }
79
- else {
80
- throw new Error("Unsupported data type");
81
- }
82
- };
83
- /**
84
- * Just like [handleLeaf] but we know that this leaf should not be a complex type, but something we can
85
- * immediately wrap
86
- *
87
- * @param leaf
88
- * @param {PathSet} paths
89
- */
90
- BinaryTreeFactory.prototype.handlePrimitiveLeaf = function (leaf, paths) {
91
- var pathElem = paths.getPathLeafOrElseAnyCurrentPathElement();
92
- if (pathElem != null && !(pathElem instanceof PathLeafElement)) {
93
- throw new Error("Path does not match the tree structure. We are at a leaf " + leaf + " but found path element " + pathElem);
94
- }
95
- return new Leaf(leaf, pathElem);
96
- };
97
- /**
98
- * Calls itself until the return value only holds 1 element
99
- *
100
- * Note: This method can only create standard [Node] that fills up the area between the "top" and the leaves.
101
- * These "in-between" nodes cannot be "path leaf" or have any interesting properties.
102
- *
103
- * @param layer What layer we aim calculate
104
- * @param inList The args of nodes we should build from
105
- * @return All [BinaryTreeElement] nodes of the next layer
106
- */
107
- BinaryTreeFactory.prototype.buildHigherLayer = function (layer, inList) {
108
- if (inList.length === 0) {
109
- throw new Error("Cannot work on empty arrays. Layer: " + layer);
110
- }
111
- else if (inList.length === 1) {
112
- return inList;
113
- }
114
- var returnArray = new Array();
115
- var nrOfNodesToCreate = Math.floor(inList.length / 2);
116
- var leftValue = null;
117
- var isLeft = true;
118
- for (var i = 0; i < inList.length; i++) {
119
- if (isLeft) {
120
- leftValue = inList[i];
121
- isLeft = false;
122
- }
123
- else {
124
- var tempNode = new Node(leftValue, inList[i]);
125
- returnArray.push(tempNode);
126
- nrOfNodesToCreate--;
127
- isLeft = true;
128
- leftValue = null;
129
- }
130
- }
131
- if (!isLeft) {
132
- // If there is odd number of nodes, then move the last node up one level
133
- returnArray.push(leftValue);
134
- }
135
- // Extra check
136
- if (nrOfNodesToCreate != 0) {
137
- util.logDebug("Why didn't we build exactly the correct amount? Layer: " + layer + " , residue: " + nrOfNodesToCreate + " , input args size: " + inList.length + ".");
138
- }
139
- return this.buildHigherLayer((layer + 1), returnArray);
140
- };
141
- BinaryTreeFactory.prototype.build = function (data, merkleHashVersion) {
142
- return this.buildWithPath(data, NO_PATHS, merkleHashVersion);
143
- };
144
- /**
145
- * @param {PathSet} paths
146
- */
147
- BinaryTreeFactory.prototype.buildWithPath = function (data, paths, merkleHashVersion) {
148
- var result = this.handleLeaf(data, paths, true, merkleHashVersion);
149
- return new BinaryTree(result);
150
- };
151
- /**
152
- * @param {Array} array
153
- * @param {PathSet} paths
154
- */
155
- BinaryTreeFactory.prototype.buildFromArray = function (array, paths, merkleHashVersion) {
156
- if (merkleHashVersion == undefined || merkleHashVersion == null) {
157
- console.error("stack trace", new Error().stack);
158
- throw new Error("Merkle hash version is undefined or null");
159
- }
160
- var pathElem = paths.getPathLeafOrElseAnyCurrentPathElement();
161
- // 1. Build leaf layer
162
- if (array.length == 0) {
163
- return new ArrayHeadNode(new EmptyLeaf(), new EmptyLeaf(), array, 0, 0, pathElem);
164
- }
165
- var leafArray = this.buildLeafElements(array, paths, merkleHashVersion);
166
- //Merkle hash version 2 and above - check
167
- if (leafArray.length == 1 && leafArray[0] instanceof Node && merkleHashVersion >= 2) {
168
- return new ArrayHeadNode(leafArray[0], new EmptyLeaf(), array, array.length, pathElem);
169
- }
170
- // 2. Build all higher layers
171
- var result = this.buildHigherLayer(1, leafArray);
172
- // 3. Fix and return the root node
173
- var orgRoot = result[0];
174
- if (orgRoot instanceof Node) {
175
- return new ArrayHeadNode(orgRoot.left, orgRoot.right, array, array.length, pathElem);
176
- }
177
- if (orgRoot instanceof Leaf) {
178
- return this.buildFromOneLeaf(array, orgRoot, pathElem);
179
- }
180
- else {
181
- throw new Error("Should not find element of this type here");
182
- }
183
- };
184
- /**
185
- *
186
- */
187
- BinaryTreeFactory.prototype.buildFromOneLeaf = function (array, orgRoot, pathElem) {
188
- if (array.length > 1) {
189
- throw new Error("How come we got a leaf returned when we had " + array.length + " elements is the args?");
190
- }
191
- else {
192
- return new ArrayHeadNode(orgRoot, new EmptyLeaf(), array, array.length, pathElem);
193
- }
194
- };
195
- /**
196
- * @param {PathSet} paths
197
- */
198
- BinaryTreeFactory.prototype.buildLeafElements = function (leafList, paths, merkleHashVersion) {
199
- var leafArray = new Array();
200
- var onlyArrayPaths = paths.keepOnlyArrayPaths(); // For performance, since we will loop soon
201
- for (var i = 0; i < leafList.length; i++) {
202
- var pathsRelevantForThisLeaf = onlyArrayPaths.getTailIfFirstElementIsArrayOfThisIndexFromList(i);
203
- var leaf = leafList[i];
204
- var binaryTreeElement = this.handleLeaf(leaf, pathsRelevantForThisLeaf, false, merkleHashVersion);
205
- leafArray.push(binaryTreeElement);
206
- }
207
- return leafArray;
208
- };
209
- /**
210
- * @param {PathSet} paths
211
- */
212
- BinaryTreeFactory.prototype.buildFromDictionary = function (dict, paths, merkleHashVersion) {
213
- var pathElem = paths.getPathLeafOrElseAnyCurrentPathElement();
214
- // Needs to be sorted, or else the order is undefined
215
- var keys = Object.keys(dict).sort();
216
- if (keys.length == 0) {
217
- return new DictHeadNode(new EmptyLeaf(), new EmptyLeaf(), dict, keys.length, 0, pathElem);
218
- }
219
- // 1. Build first (leaf) layer
220
- var leafArray = this.buildLeafElementFromDict(keys, dict, paths, merkleHashVersion);
221
- // 2. Build all higher layers
222
- var result = this.buildHigherLayer(1, leafArray);
223
- // 3. Fix and return the root node
224
- var orgRoot = result[0];
225
- if (orgRoot instanceof Node) {
226
- return new DictHeadNode(orgRoot.left, orgRoot.right, dict, keys.length, pathElem);
227
- }
228
- else {
229
- throw new Error("Should not find element of this type here: " + typeof orgRoot);
230
- }
231
- };
232
- /**
233
- * @param {PathSet} paths
234
- */
235
- BinaryTreeFactory.prototype.buildLeafElementFromDict = function (keys, dict, paths, merkleHashVersion) {
236
- var leafArray = new Array();
237
- var onlyDictPaths = paths.keepOnlyDictPaths(); // For performance, since we will loop soon
238
- for (var i = 0; i < keys.length; i++) {
239
- // The key cannot not be proved, so NO_PATHS
240
- var key = keys[i];
241
- var keyElement = this.handleLeaf(key, NO_PATHS, false, merkleHashVersion);
242
- leafArray.push(keyElement);
243
- var content = dict[key];
244
- var pathsRelevantForThisLeaf = onlyDictPaths.getTailIfFirstElementIsDictOfThisKeyFromList(key);
245
- var contentElement = this.handleLeaf(content, pathsRelevantForThisLeaf, false, merkleHashVersion);
246
- leafArray.push(contentElement);
247
- }
248
- return leafArray;
249
- };
250
- module.exports = { BinaryTreeFactory };
251
- //# sourceMappingURL=binarytreefactory.js.map
@@ -1 +0,0 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@ -1,18 +0,0 @@
1
- /// <reference types="node" />
2
- import { Path } from "./types";
3
- import { Buffer } from "buffer";
4
- export declare function calculateRoot(hashes: Buffer[], depth?: number, leafDepth?: number): Buffer;
5
- export declare function merklePath(hashes: Buffer[], target: Buffer): Path;
6
- /**
7
- *
8
- * @param path The merkle path to validate.
9
- * Format [{side: <0|1>, hash: <hash buffer depth n-1>},
10
- * {side: <0|1>, hash: <hash buffer depth n-2>},
11
- * ...,
12
- * {side: <0|1>, hash: <hash buffer depth 1>}]
13
-
14
- * @param target the leaf hash that the path proves belongs in the merkleRoot
15
- * @param merkleRoot The merkle root that supposedly contains the target via the supplied path.
16
- * The merkle root is typically taken from a block header.
17
- */
18
- export declare function validateMerklePath(path: Path, target: Buffer, merkleRoot: Buffer): boolean;
@@ -1,110 +0,0 @@
1
- import { hashConcat } from "../encryption/encryption";
2
- import { Buffer } from "buffer";
3
- var internalNodePrefix = Buffer.alloc(1, 0);
4
- var leafPrefix = Buffer.alloc(1, 1);
5
- var nonExistingNodeHash = Buffer.alloc(32);
6
- export function calculateRoot(hashes, depth, leafDepth) {
7
- var numTransactions = hashes.length;
8
- if (numTransactions === 0) {
9
- return Buffer.alloc(32);
10
- }
11
- if (depth === undefined) {
12
- depth = 0;
13
- }
14
- if (!leafDepth) {
15
- leafDepth = Math.ceil(Math.log2(numTransactions));
16
- }
17
- if (depth === leafDepth) {
18
- return hashes[0];
19
- }
20
- var maxLeavesPerChild = Math.pow(2, leafDepth - depth - 1);
21
- var prefix = depth === leafDepth - 1 ? leafPrefix : internalNodePrefix;
22
- if (numTransactions <= maxLeavesPerChild) {
23
- var left = calculateRoot(hashes, depth + 1, leafDepth);
24
- return hashConcat([prefix, left, nonExistingNodeHash]);
25
- }
26
- var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
27
- var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
28
- return hashConcat([prefix, left, prefix, right]);
29
- }
30
- function internalMerklePath(hashes, targetIndex, depth, leafDepth) {
31
- var numTransactions = hashes.length;
32
- if (depth === leafDepth) {
33
- return [];
34
- }
35
- var maxLeavesPerChild = Math.pow(2, leafDepth - depth - 1);
36
- var prefix = depth == leafDepth - 1 ? leafPrefix : internalNodePrefix;
37
- if (numTransactions <= maxLeavesPerChild) {
38
- var path = internalMerklePath(hashes, targetIndex, depth + 1, leafDepth);
39
- path.push({ side: 1, hash: nonExistingNodeHash });
40
- return path;
41
- }
42
- if (targetIndex < maxLeavesPerChild) {
43
- var path = internalMerklePath(hashes.slice(0, maxLeavesPerChild), targetIndex, depth + 1, leafDepth);
44
- var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
45
- path.push({ side: 1, hash: right });
46
- }
47
- else {
48
- var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
49
- var path = internalMerklePath(hashes.slice(maxLeavesPerChild), targetIndex - maxLeavesPerChild, depth + 1, leafDepth);
50
- path.push({ side: 0, hash: left });
51
- }
52
- return path;
53
- }
54
- /*
55
- * a path looks like this:
56
- * {merklePath: [{side: <0|1>, hash: <hash buffer depth n-1>},
57
- * {side: <0|1>, hash: <hash buffer depth n-2>},
58
- * ...
59
- * {side: <0|1>, hash: <hash buffer depth 1>}]}
60
- */
61
- export function merklePath(hashes, target) {
62
- if (!hashes || hashes.length == 0) {
63
- throw new Error("Cannot make merkle path from empty transaction set");
64
- }
65
- var index = -1;
66
- for (var i = 0; i < hashes.length; i++) {
67
- if (hashes[i].equals(target)) {
68
- index = i;
69
- break;
70
- }
71
- }
72
- if (index === -1) {
73
- throw new Error("Target is not in list of hashes");
74
- }
75
- var leafDepth = Math.ceil(Math.log2(hashes.length));
76
- var path = internalMerklePath(hashes, index, 0, leafDepth);
77
- return path;
78
- }
79
- /**
80
- *
81
- * @param path The merkle path to validate.
82
- * Format [{side: <0|1>, hash: <hash buffer depth n-1>},
83
- * {side: <0|1>, hash: <hash buffer depth n-2>},
84
- * ...,
85
- * {side: <0|1>, hash: <hash buffer depth 1>}]
86
-
87
- * @param target the leaf hash that the path proves belongs in the merkleRoot
88
- * @param merkleRoot The merkle root that supposedly contains the target via the supplied path.
89
- * The merkle root is typically taken from a block header.
90
- */
91
- export function validateMerklePath(path, target, merkleRoot) {
92
- let currentHash = target;
93
- for (let i = 0; i < path.length; i++) {
94
- const item = path[i];
95
- const prefix = (i === 0) ? Buffer.from([1]) : Buffer.from([0]);
96
- if (item.side === 0) {
97
- currentHash = hashConcat([prefix, item.hash, prefix, currentHash]);
98
- }
99
- else {
100
- if (item.hash.equals(nonExistingNodeHash)) {
101
- currentHash = hashConcat([prefix, currentHash, nonExistingNodeHash]);
102
- }
103
- else {
104
- currentHash = hashConcat([prefix, currentHash, prefix, item.hash]);
105
- }
106
- }
107
- }
108
- return merkleRoot.equals(currentHash);
109
- }
110
- //# sourceMappingURL=merkleHelper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merkleHelper.js","sourceRoot":"","sources":["../../../src/merkle/merkleHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,IAAI,kBAAkB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5C,IAAI,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACpC,IAAI,mBAAmB,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAE3C,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,KAAc,EAAE,SAAkB;IAC/E,IAAI,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK,KAAK,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