@airgap/tezos 0.13.7-beta.11

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 (370) hide show
  1. package/LICENSE.md +7 -0
  2. package/actions/GetKtAccountsAction.d.ts +8 -0
  3. package/actions/GetKtAccountsAction.js +85 -0
  4. package/actions/GetKtAccountsAction.js.map +1 -0
  5. package/airgap-coinlib-tezos.min.js +103587 -0
  6. package/constants.d.ts +18 -0
  7. package/constants.js +28 -0
  8. package/constants.js.map +1 -0
  9. package/index.d.ts +46 -0
  10. package/index.js +103 -0
  11. package/index.js.map +1 -0
  12. package/package.json +70 -0
  13. package/protocol/TezosAddress.d.ts +11 -0
  14. package/protocol/TezosAddress.js +102 -0
  15. package/protocol/TezosAddress.js.map +1 -0
  16. package/protocol/TezosCryptoClient.d.ts +15 -0
  17. package/protocol/TezosCryptoClient.js +152 -0
  18. package/protocol/TezosCryptoClient.js.map +1 -0
  19. package/protocol/TezosProtocol.d.ts +349 -0
  20. package/protocol/TezosProtocol.js +1853 -0
  21. package/protocol/TezosProtocol.js.map +1 -0
  22. package/protocol/TezosProtocolOptions.d.ts +29 -0
  23. package/protocol/TezosProtocolOptions.js +114 -0
  24. package/protocol/TezosProtocolOptions.js.map +1 -0
  25. package/protocol/TezosUtils.d.ts +40 -0
  26. package/protocol/TezosUtils.js +296 -0
  27. package/protocol/TezosUtils.js.map +1 -0
  28. package/protocol/contract/TezosContract.d.ts +52 -0
  29. package/protocol/contract/TezosContract.js +509 -0
  30. package/protocol/contract/TezosContract.js.map +1 -0
  31. package/protocol/contract/TezosContractCall.d.ts +10 -0
  32. package/protocol/contract/TezosContractCall.js +23 -0
  33. package/protocol/contract/TezosContractCall.js.map +1 -0
  34. package/protocol/contract/TezosContractEntrypoint.d.ts +8 -0
  35. package/protocol/contract/TezosContractEntrypoint.js +27 -0
  36. package/protocol/contract/TezosContractEntrypoint.js.map +1 -0
  37. package/protocol/contract/TezosContractStorage.d.ts +7 -0
  38. package/protocol/contract/TezosContractStorage.js +16 -0
  39. package/protocol/contract/TezosContractStorage.js.map +1 -0
  40. package/protocol/contract/remote-data/TezosContractRemoteDataFactory.d.ts +11 -0
  41. package/protocol/contract/remote-data/TezosContractRemoteDataFactory.js +34 -0
  42. package/protocol/contract/remote-data/TezosContractRemoteDataFactory.js.map +1 -0
  43. package/protocol/contract/remote-data/TezosStorageRemoteData.d.ts +12 -0
  44. package/protocol/contract/remote-data/TezosStorageRemoteData.js +151 -0
  45. package/protocol/contract/remote-data/TezosStorageRemoteData.js.map +1 -0
  46. package/protocol/domains/TezosDomains.d.ts +20 -0
  47. package/protocol/domains/TezosDomains.js +306 -0
  48. package/protocol/domains/TezosDomains.js.map +1 -0
  49. package/protocol/fa/TezosBTC.d.ts +12 -0
  50. package/protocol/fa/TezosBTC.js +107 -0
  51. package/protocol/fa/TezosBTC.js.map +1 -0
  52. package/protocol/fa/TezosBTCtez.d.ts +10 -0
  53. package/protocol/fa/TezosBTCtez.js +54 -0
  54. package/protocol/fa/TezosBTCtez.js.map +1 -0
  55. package/protocol/fa/TezosCTez.d.ts +10 -0
  56. package/protocol/fa/TezosCTez.js +51 -0
  57. package/protocol/fa/TezosCTez.js.map +1 -0
  58. package/protocol/fa/TezosDOGA.d.ts +10 -0
  59. package/protocol/fa/TezosDOGA.js +51 -0
  60. package/protocol/fa/TezosDOGA.js.map +1 -0
  61. package/protocol/fa/TezosETHtz.d.ts +9 -0
  62. package/protocol/fa/TezosETHtz.js +72 -0
  63. package/protocol/fa/TezosETHtz.js.map +1 -0
  64. package/protocol/fa/TezosFA1Protocol.d.ts +27 -0
  65. package/protocol/fa/TezosFA1Protocol.js +310 -0
  66. package/protocol/fa/TezosFA1Protocol.js.map +1 -0
  67. package/protocol/fa/TezosFA1p2Protocol.d.ts +8 -0
  68. package/protocol/fa/TezosFA1p2Protocol.js +117 -0
  69. package/protocol/fa/TezosFA1p2Protocol.js.map +1 -0
  70. package/protocol/fa/TezosFA2Protocol.d.ts +58 -0
  71. package/protocol/fa/TezosFA2Protocol.js +449 -0
  72. package/protocol/fa/TezosFA2Protocol.js.map +1 -0
  73. package/protocol/fa/TezosFAProtocol.d.ts +65 -0
  74. package/protocol/fa/TezosFAProtocol.js +510 -0
  75. package/protocol/fa/TezosFAProtocol.js.map +1 -0
  76. package/protocol/fa/TezosFAProtocolOptions.d.ts +54 -0
  77. package/protocol/fa/TezosFAProtocolOptions.js +228 -0
  78. package/protocol/fa/TezosFAProtocolOptions.js.map +1 -0
  79. package/protocol/fa/TezosKolibriUSD.d.ts +10 -0
  80. package/protocol/fa/TezosKolibriUSD.js +74 -0
  81. package/protocol/fa/TezosKolibriUSD.js.map +1 -0
  82. package/protocol/fa/TezosPlanty.d.ts +10 -0
  83. package/protocol/fa/TezosPlanty.js +51 -0
  84. package/protocol/fa/TezosPlanty.js.map +1 -0
  85. package/protocol/fa/TezosQUIPU.d.ts +10 -0
  86. package/protocol/fa/TezosQUIPU.js +54 -0
  87. package/protocol/fa/TezosQUIPU.js.map +1 -0
  88. package/protocol/fa/TezosSIRS.d.ts +10 -0
  89. package/protocol/fa/TezosSIRS.js +51 -0
  90. package/protocol/fa/TezosSIRS.js.map +1 -0
  91. package/protocol/fa/TezosStaker.d.ts +10 -0
  92. package/protocol/fa/TezosStaker.js +74 -0
  93. package/protocol/fa/TezosStaker.js.map +1 -0
  94. package/protocol/fa/TezosUBTC.d.ts +10 -0
  95. package/protocol/fa/TezosUBTC.js +54 -0
  96. package/protocol/fa/TezosUBTC.js.map +1 -0
  97. package/protocol/fa/TezosUDEFI.d.ts +10 -0
  98. package/protocol/fa/TezosUDEFI.js +54 -0
  99. package/protocol/fa/TezosUDEFI.js.map +1 -0
  100. package/protocol/fa/TezosUSD.d.ts +10 -0
  101. package/protocol/fa/TezosUSD.js +74 -0
  102. package/protocol/fa/TezosUSD.js.map +1 -0
  103. package/protocol/fa/TezosUSDT.d.ts +10 -0
  104. package/protocol/fa/TezosUSDT.js +54 -0
  105. package/protocol/fa/TezosUSDT.js.map +1 -0
  106. package/protocol/fa/TezosUUSD.d.ts +6 -0
  107. package/protocol/fa/TezosUUSD.js +31 -0
  108. package/protocol/fa/TezosUUSD.js.map +1 -0
  109. package/protocol/fa/TezosWRAP.d.ts +10 -0
  110. package/protocol/fa/TezosWRAP.js +54 -0
  111. package/protocol/fa/TezosWRAP.js.map +1 -0
  112. package/protocol/fa/TezosWrapped.d.ts +10 -0
  113. package/protocol/fa/TezosWrapped.js +74 -0
  114. package/protocol/fa/TezosWrapped.js.map +1 -0
  115. package/protocol/fa/TezosYOU.d.ts +6 -0
  116. package/protocol/fa/TezosYOU.js +31 -0
  117. package/protocol/fa/TezosYOU.js.map +1 -0
  118. package/protocol/indexerClient/TezosIndexerClient.d.ts +25 -0
  119. package/protocol/indexerClient/TezosIndexerClient.js +251 -0
  120. package/protocol/indexerClient/TezosIndexerClient.js.map +1 -0
  121. package/protocol/indexerClient/TezosProtocolIndexerClient.d.ts +26 -0
  122. package/protocol/indexerClient/TezosProtocolIndexerClient.js +3 -0
  123. package/protocol/indexerClient/TezosProtocolIndexerClient.js.map +1 -0
  124. package/protocol/kt/TezosKtAddress.d.ts +5 -0
  125. package/protocol/kt/TezosKtAddress.js +72 -0
  126. package/protocol/kt/TezosKtAddress.js.map +1 -0
  127. package/protocol/kt/TezosKtProtocol.d.ts +30 -0
  128. package/protocol/kt/TezosKtProtocol.js +317 -0
  129. package/protocol/kt/TezosKtProtocol.js.map +1 -0
  130. package/protocol/sapling/TezosSaplingAddress.d.ts +12 -0
  131. package/protocol/sapling/TezosSaplingAddress.js +134 -0
  132. package/protocol/sapling/TezosSaplingAddress.js.map +1 -0
  133. package/protocol/sapling/TezosSaplingCryptoClient.d.ts +34 -0
  134. package/protocol/sapling/TezosSaplingCryptoClient.js +241 -0
  135. package/protocol/sapling/TezosSaplingCryptoClient.js.map +1 -0
  136. package/protocol/sapling/TezosSaplingProtocol.d.ts +130 -0
  137. package/protocol/sapling/TezosSaplingProtocol.js +1101 -0
  138. package/protocol/sapling/TezosSaplingProtocol.js.map +1 -0
  139. package/protocol/sapling/TezosSaplingProtocolOptions.d.ts +43 -0
  140. package/protocol/sapling/TezosSaplingProtocolOptions.js +78 -0
  141. package/protocol/sapling/TezosSaplingProtocolOptions.js.map +1 -0
  142. package/protocol/sapling/TezosShieldedTezProtocol.d.ts +9 -0
  143. package/protocol/sapling/TezosShieldedTezProtocol.js +109 -0
  144. package/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -0
  145. package/protocol/sapling/node/TezosSaplingNodeClient.d.ts +8 -0
  146. package/protocol/sapling/node/TezosSaplingNodeClient.js +78 -0
  147. package/protocol/sapling/node/TezosSaplingNodeClient.js.map +1 -0
  148. package/protocol/sapling/utils/TezosSaplingBookkeeper.d.ts +34 -0
  149. package/protocol/sapling/utils/TezosSaplingBookkeeper.js +586 -0
  150. package/protocol/sapling/utils/TezosSaplingBookkeeper.js.map +1 -0
  151. package/protocol/sapling/utils/TezosSaplingEncoder.d.ts +22 -0
  152. package/protocol/sapling/utils/TezosSaplingEncoder.js +158 -0
  153. package/protocol/sapling/utils/TezosSaplingEncoder.js.map +1 -0
  154. package/protocol/sapling/utils/TezosSaplingForger.d.ts +26 -0
  155. package/protocol/sapling/utils/TezosSaplingForger.js +278 -0
  156. package/protocol/sapling/utils/TezosSaplingForger.js.map +1 -0
  157. package/protocol/sapling/utils/TezosSaplingState.d.ts +17 -0
  158. package/protocol/sapling/utils/TezosSaplingState.js +260 -0
  159. package/protocol/sapling/utils/TezosSaplingState.js.map +1 -0
  160. package/protocol/types/TezosAddressCursor.d.ts +3 -0
  161. package/protocol/types/TezosAddressCursor.js +3 -0
  162. package/protocol/types/TezosAddressCursor.js.map +1 -0
  163. package/protocol/types/TezosAddressResult.d.ts +4 -0
  164. package/protocol/types/TezosAddressResult.js +3 -0
  165. package/protocol/types/TezosAddressResult.js.map +1 -0
  166. package/protocol/types/TezosBlockHeader.d.ts +13 -0
  167. package/protocol/types/TezosBlockHeader.js +3 -0
  168. package/protocol/types/TezosBlockHeader.js.map +1 -0
  169. package/protocol/types/TezosBlockMetadata.d.ts +7 -0
  170. package/protocol/types/TezosBlockMetadata.js +3 -0
  171. package/protocol/types/TezosBlockMetadata.js.map +1 -0
  172. package/protocol/types/TezosContractCode.d.ts +5 -0
  173. package/protocol/types/TezosContractCode.js +3 -0
  174. package/protocol/types/TezosContractCode.js.map +1 -0
  175. package/protocol/types/TezosOperationType.d.ts +13 -0
  176. package/protocol/types/TezosOperationType.js +18 -0
  177. package/protocol/types/TezosOperationType.js.map +1 -0
  178. package/protocol/types/TezosTransactionCursor.d.ts +3 -0
  179. package/protocol/types/TezosTransactionCursor.js +3 -0
  180. package/protocol/types/TezosTransactionCursor.js.map +1 -0
  181. package/protocol/types/TezosTransactionResult.d.ts +6 -0
  182. package/protocol/types/TezosTransactionResult.js +3 -0
  183. package/protocol/types/TezosTransactionResult.js.map +1 -0
  184. package/protocol/types/TezosWrappedOperation.d.ts +5 -0
  185. package/protocol/types/TezosWrappedOperation.js +3 -0
  186. package/protocol/types/TezosWrappedOperation.js.map +1 -0
  187. package/protocol/types/contract/BigMap.d.ts +7 -0
  188. package/protocol/types/contract/BigMap.js +3 -0
  189. package/protocol/types/contract/BigMap.js.map +1 -0
  190. package/protocol/types/contract/BigMapEnrtyFilter.d.ts +5 -0
  191. package/protocol/types/contract/BigMapEnrtyFilter.js +3 -0
  192. package/protocol/types/contract/BigMapEnrtyFilter.js.map +1 -0
  193. package/protocol/types/contract/BigMapEntry.d.ts +7 -0
  194. package/protocol/types/contract/BigMapEntry.js +3 -0
  195. package/protocol/types/contract/BigMapEntry.js.map +1 -0
  196. package/protocol/types/contract/BigMapRequest.d.ts +8 -0
  197. package/protocol/types/contract/BigMapRequest.js +3 -0
  198. package/protocol/types/contract/BigMapRequest.js.map +1 -0
  199. package/protocol/types/contract/TezosContractMetadata.d.ts +61 -0
  200. package/protocol/types/contract/TezosContractMetadata.js +3 -0
  201. package/protocol/types/contract/TezosContractMetadata.js.map +1 -0
  202. package/protocol/types/domains/TezosDomainsRecord.d.ts +8 -0
  203. package/protocol/types/domains/TezosDomainsRecord.js +3 -0
  204. package/protocol/types/domains/TezosDomainsRecord.js.map +1 -0
  205. package/protocol/types/domains/TezosDomainsReverseRecord.d.ts +5 -0
  206. package/protocol/types/domains/TezosDomainsReverseRecord.js +3 -0
  207. package/protocol/types/domains/TezosDomainsReverseRecord.js.map +1 -0
  208. package/protocol/types/fa/TezosFA2BalanceOfRequest.d.ts +4 -0
  209. package/protocol/types/fa/TezosFA2BalanceOfRequest.js +3 -0
  210. package/protocol/types/fa/TezosFA2BalanceOfRequest.js.map +1 -0
  211. package/protocol/types/fa/TezosFA2BalanceOfResponse.d.ts +5 -0
  212. package/protocol/types/fa/TezosFA2BalanceOfResponse.js +3 -0
  213. package/protocol/types/fa/TezosFA2BalanceOfResponse.js.map +1 -0
  214. package/protocol/types/fa/TezosFA2TransferRequest.d.ts +8 -0
  215. package/protocol/types/fa/TezosFA2TransferRequest.js +3 -0
  216. package/protocol/types/fa/TezosFA2TransferRequest.js.map +1 -0
  217. package/protocol/types/fa/TezosFA2UpdateOperatorRequest.d.ts +6 -0
  218. package/protocol/types/fa/TezosFA2UpdateOperatorRequest.js +3 -0
  219. package/protocol/types/fa/TezosFA2UpdateOperatorRequest.js.map +1 -0
  220. package/protocol/types/fa/TezosFATokenMetadata.d.ts +6 -0
  221. package/protocol/types/fa/TezosFATokenMetadata.js +3 -0
  222. package/protocol/types/fa/TezosFATokenMetadata.js.map +1 -0
  223. package/protocol/types/kt/TezosKtAddressCursor.d.ts +4 -0
  224. package/protocol/types/kt/TezosKtAddressCursor.js +3 -0
  225. package/protocol/types/kt/TezosKtAddressCursor.js.map +1 -0
  226. package/protocol/types/kt/TezosKtAddressResult.d.ts +5 -0
  227. package/protocol/types/kt/TezosKtAddressResult.js +3 -0
  228. package/protocol/types/kt/TezosKtAddressResult.js.map +1 -0
  229. package/protocol/types/micheline/MichelineNode.d.ts +15 -0
  230. package/protocol/types/micheline/MichelineNode.js +5 -0
  231. package/protocol/types/micheline/MichelineNode.js.map +1 -0
  232. package/protocol/types/micheline/MichelineNodeUtils.d.ts +6 -0
  233. package/protocol/types/micheline/MichelineNodeUtils.js +40 -0
  234. package/protocol/types/micheline/MichelineNodeUtils.js.map +1 -0
  235. package/protocol/types/michelson/MichelsonType.d.ts +11 -0
  236. package/protocol/types/michelson/MichelsonType.js +22 -0
  237. package/protocol/types/michelson/MichelsonType.js.map +1 -0
  238. package/protocol/types/michelson/MichelsonTypeMeta.d.ts +33 -0
  239. package/protocol/types/michelson/MichelsonTypeMeta.js +132 -0
  240. package/protocol/types/michelson/MichelsonTypeMeta.js.map +1 -0
  241. package/protocol/types/michelson/MichelsonTypeUtils.d.ts +19 -0
  242. package/protocol/types/michelson/MichelsonTypeUtils.js +249 -0
  243. package/protocol/types/michelson/MichelsonTypeUtils.js.map +1 -0
  244. package/protocol/types/michelson/generics/MichelsonList.d.ts +11 -0
  245. package/protocol/types/michelson/generics/MichelsonList.js +68 -0
  246. package/protocol/types/michelson/generics/MichelsonList.js.map +1 -0
  247. package/protocol/types/michelson/generics/MichelsonMap.d.ts +14 -0
  248. package/protocol/types/michelson/generics/MichelsonMap.js +118 -0
  249. package/protocol/types/michelson/generics/MichelsonMap.js.map +1 -0
  250. package/protocol/types/michelson/generics/MichelsonOption.d.ts +25 -0
  251. package/protocol/types/michelson/generics/MichelsonOption.js +119 -0
  252. package/protocol/types/michelson/generics/MichelsonOption.js.map +1 -0
  253. package/protocol/types/michelson/generics/MichelsonOr.d.ts +25 -0
  254. package/protocol/types/michelson/generics/MichelsonOr.js +132 -0
  255. package/protocol/types/michelson/generics/MichelsonOr.js.map +1 -0
  256. package/protocol/types/michelson/generics/MichelsonPair.d.ts +17 -0
  257. package/protocol/types/michelson/generics/MichelsonPair.js +135 -0
  258. package/protocol/types/michelson/generics/MichelsonPair.js.map +1 -0
  259. package/protocol/types/michelson/grammar/MichelsonGrammarData.d.ts +2 -0
  260. package/protocol/types/michelson/grammar/MichelsonGrammarData.js +4 -0
  261. package/protocol/types/michelson/grammar/MichelsonGrammarData.js.map +1 -0
  262. package/protocol/types/michelson/grammar/MichelsonGrammarInstruction.d.ts +1 -0
  263. package/protocol/types/michelson/grammar/MichelsonGrammarInstruction.js +4 -0
  264. package/protocol/types/michelson/grammar/MichelsonGrammarInstruction.js.map +1 -0
  265. package/protocol/types/michelson/grammar/MichelsonGrammarType.d.ts +1 -0
  266. package/protocol/types/michelson/grammar/MichelsonGrammarType.js +4 -0
  267. package/protocol/types/michelson/grammar/MichelsonGrammarType.js.map +1 -0
  268. package/protocol/types/michelson/primitives/MichelsonAddress.d.ts +15 -0
  269. package/protocol/types/michelson/primitives/MichelsonAddress.js +72 -0
  270. package/protocol/types/michelson/primitives/MichelsonAddress.js.map +1 -0
  271. package/protocol/types/michelson/primitives/MichelsonBool.d.ts +12 -0
  272. package/protocol/types/michelson/primitives/MichelsonBool.js +57 -0
  273. package/protocol/types/michelson/primitives/MichelsonBool.js.map +1 -0
  274. package/protocol/types/michelson/primitives/MichelsonBytes.d.ts +14 -0
  275. package/protocol/types/michelson/primitives/MichelsonBytes.js +75 -0
  276. package/protocol/types/michelson/primitives/MichelsonBytes.js.map +1 -0
  277. package/protocol/types/michelson/primitives/MichelsonInt.d.ts +14 -0
  278. package/protocol/types/michelson/primitives/MichelsonInt.js +72 -0
  279. package/protocol/types/michelson/primitives/MichelsonInt.js.map +1 -0
  280. package/protocol/types/michelson/primitives/MichelsonString.d.ts +14 -0
  281. package/protocol/types/michelson/primitives/MichelsonString.js +74 -0
  282. package/protocol/types/michelson/primitives/MichelsonString.js.map +1 -0
  283. package/protocol/types/michelson/primitives/MichelsonUnit.d.ts +9 -0
  284. package/protocol/types/michelson/primitives/MichelsonUnit.js +53 -0
  285. package/protocol/types/michelson/primitives/MichelsonUnit.js.map +1 -0
  286. package/protocol/types/operations/ActivateAccount.d.ts +7 -0
  287. package/protocol/types/operations/ActivateAccount.js +3 -0
  288. package/protocol/types/operations/ActivateAccount.js.map +1 -0
  289. package/protocol/types/operations/Ballot.d.ts +9 -0
  290. package/protocol/types/operations/Ballot.js +3 -0
  291. package/protocol/types/operations/Ballot.js.map +1 -0
  292. package/protocol/types/operations/Delegation.d.ts +11 -0
  293. package/protocol/types/operations/Delegation.js +3 -0
  294. package/protocol/types/operations/Delegation.js.map +1 -0
  295. package/protocol/types/operations/DoubleBakingEvidence.d.ts +8 -0
  296. package/protocol/types/operations/DoubleBakingEvidence.js +3 -0
  297. package/protocol/types/operations/DoubleBakingEvidence.js.map +1 -0
  298. package/protocol/types/operations/DoubleEndorsementEvidence.d.ts +16 -0
  299. package/protocol/types/operations/DoubleEndorsementEvidence.js +3 -0
  300. package/protocol/types/operations/DoubleEndorsementEvidence.js.map +1 -0
  301. package/protocol/types/operations/Endorsement.d.ts +6 -0
  302. package/protocol/types/operations/Endorsement.js +3 -0
  303. package/protocol/types/operations/Endorsement.js.map +1 -0
  304. package/protocol/types/operations/Origination.d.ts +13 -0
  305. package/protocol/types/operations/Origination.js +3 -0
  306. package/protocol/types/operations/Origination.js.map +1 -0
  307. package/protocol/types/operations/Proposal.d.ts +7 -0
  308. package/protocol/types/operations/Proposal.js +3 -0
  309. package/protocol/types/operations/Proposal.js.map +1 -0
  310. package/protocol/types/operations/Reveal.d.ts +11 -0
  311. package/protocol/types/operations/Reveal.js +3 -0
  312. package/protocol/types/operations/Reveal.js.map +1 -0
  313. package/protocol/types/operations/SeedNonceRevelation.d.ts +7 -0
  314. package/protocol/types/operations/SeedNonceRevelation.js +3 -0
  315. package/protocol/types/operations/SeedNonceRevelation.js.map +1 -0
  316. package/protocol/types/operations/TezosOperation.d.ts +4 -0
  317. package/protocol/types/operations/TezosOperation.js +3 -0
  318. package/protocol/types/operations/TezosOperation.js.map +1 -0
  319. package/protocol/types/operations/Transaction.d.ts +23 -0
  320. package/protocol/types/operations/Transaction.js +3 -0
  321. package/protocol/types/operations/Transaction.js.map +1 -0
  322. package/protocol/types/sapling/TezosSaplingAddressCursor.d.ts +4 -0
  323. package/protocol/types/sapling/TezosSaplingAddressCursor.js +3 -0
  324. package/protocol/types/sapling/TezosSaplingAddressCursor.js.map +1 -0
  325. package/protocol/types/sapling/TezosSaplingAddressResult.d.ts +4 -0
  326. package/protocol/types/sapling/TezosSaplingAddressResult.js +3 -0
  327. package/protocol/types/sapling/TezosSaplingAddressResult.js.map +1 -0
  328. package/protocol/types/sapling/TezosSaplingCiphertext.d.ts +8 -0
  329. package/protocol/types/sapling/TezosSaplingCiphertext.js +3 -0
  330. package/protocol/types/sapling/TezosSaplingCiphertext.js.map +1 -0
  331. package/protocol/types/sapling/TezosSaplingInput.d.ts +6 -0
  332. package/protocol/types/sapling/TezosSaplingInput.js +3 -0
  333. package/protocol/types/sapling/TezosSaplingInput.js.map +1 -0
  334. package/protocol/types/sapling/TezosSaplingOutput.d.ts +6 -0
  335. package/protocol/types/sapling/TezosSaplingOutput.js +3 -0
  336. package/protocol/types/sapling/TezosSaplingOutput.js.map +1 -0
  337. package/protocol/types/sapling/TezosSaplingStateDiff.d.ts +6 -0
  338. package/protocol/types/sapling/TezosSaplingStateDiff.js +3 -0
  339. package/protocol/types/sapling/TezosSaplingStateDiff.js.map +1 -0
  340. package/protocol/types/sapling/TezosSaplingStateTree.d.ts +7 -0
  341. package/protocol/types/sapling/TezosSaplingStateTree.js +3 -0
  342. package/protocol/types/sapling/TezosSaplingStateTree.js.map +1 -0
  343. package/protocol/types/sapling/TezosSaplingTransaction.d.ts +23 -0
  344. package/protocol/types/sapling/TezosSaplingTransaction.js +3 -0
  345. package/protocol/types/sapling/TezosSaplingTransaction.js.map +1 -0
  346. package/protocol/types/sapling/TezosSaplingTransactionCursor.d.ts +3 -0
  347. package/protocol/types/sapling/TezosSaplingTransactionCursor.js +3 -0
  348. package/protocol/types/sapling/TezosSaplingTransactionCursor.js.map +1 -0
  349. package/protocol/types/sapling/TezosSaplingTransactionResult.d.ts +6 -0
  350. package/protocol/types/sapling/TezosSaplingTransactionResult.js +3 -0
  351. package/protocol/types/sapling/TezosSaplingTransactionResult.js.map +1 -0
  352. package/protocol/types/utils.d.ts +8 -0
  353. package/protocol/types/utils.js +41 -0
  354. package/protocol/types/utils.js.map +1 -0
  355. package/readme.md +121 -0
  356. package/types/signed-transaction-tezos-sapling.d.ts +3 -0
  357. package/types/signed-transaction-tezos-sapling.js +3 -0
  358. package/types/signed-transaction-tezos-sapling.js.map +1 -0
  359. package/types/signed-transaction-tezos.d.ts +5 -0
  360. package/types/signed-transaction-tezos.js +3 -0
  361. package/types/signed-transaction-tezos.js.map +1 -0
  362. package/types/transaction-tezos.d.ts +14 -0
  363. package/types/transaction-tezos.js +3 -0
  364. package/types/transaction-tezos.js.map +1 -0
  365. package/types/unsigned-transaction-tezos-sapling.d.ts +38 -0
  366. package/types/unsigned-transaction-tezos-sapling.js +3 -0
  367. package/types/unsigned-transaction-tezos-sapling.js.map +1 -0
  368. package/types/unsigned-transaction-tezos.d.ts +8 -0
  369. package/types/unsigned-transaction-tezos.js +3 -0
  370. package/types/unsigned-transaction-tezos.js.map +1 -0
@@ -0,0 +1,1853 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
29
+ }) : (function(o, m, k, k2) {
30
+ if (k2 === undefined) k2 = k;
31
+ o[k2] = m[k];
32
+ }));
33
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
34
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
35
+ }) : function(o, v) {
36
+ o["default"] = v;
37
+ });
38
+ var __importStar = (this && this.__importStar) || function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
46
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
+ return new (P || (P = Promise))(function (resolve, reject) {
48
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
49
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
50
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
51
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
52
+ });
53
+ };
54
+ var __generator = (this && this.__generator) || function (thisArg, body) {
55
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
56
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
57
+ function verb(n) { return function (v) { return step([n, v]); }; }
58
+ function step(op) {
59
+ if (f) throw new TypeError("Generator is already executing.");
60
+ while (_) try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
62
+ if (y = 0, t) op = [op[0] & 2, t.value];
63
+ switch (op[0]) {
64
+ case 0: case 1: t = op; break;
65
+ case 4: _.label++; return { value: op[1], done: false };
66
+ case 5: _.label++; y = op[1]; op = [0]; continue;
67
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
68
+ default:
69
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
70
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
71
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
72
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
73
+ if (t[2]) _.ops.pop();
74
+ _.trys.pop(); continue;
75
+ }
76
+ op = body.call(thisArg, _);
77
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
78
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
79
+ }
80
+ };
81
+ var __importDefault = (this && this.__importDefault) || function (mod) {
82
+ return (mod && mod.__esModule) ? mod : { "default": mod };
83
+ };
84
+ var _a, _b;
85
+ Object.defineProperty(exports, "__esModule", { value: true });
86
+ exports.TezosProtocol = exports.TezosNetwork = exports.TezosDelegatorAction = void 0;
87
+ var taquito_local_forging_1 = require("@airgap/coinlib-core/dependencies/src/@taquito/local-forging-8.0.1-beta.1/packages/taquito-local-forging/src/taquito-local-forging");
88
+ var index_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/axios-0.19.0/index"));
89
+ var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
90
+ var index_2 = require("@airgap/coinlib-core/dependencies/src/bip39-2.5.0/index");
91
+ var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2/index"));
92
+ var index_3 = require("@airgap/coinlib-core/dependencies/src/hd-wallet-js-b216450e56954a6e82ace0aade9474673de5d9d5/src/index");
93
+ var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
94
+ var index_4 = require("@airgap/coinlib-core/errors/index");
95
+ var NonExtendedProtocol_1 = require("@airgap/coinlib-core/protocols/NonExtendedProtocol");
96
+ var assert_1 = require("@airgap/coinlib-core/utils/assert");
97
+ var ProtocolSymbols_1 = require("@airgap/coinlib-core/utils/ProtocolSymbols");
98
+ var TezosAddress_1 = require("./TezosAddress");
99
+ var TezosCryptoClient_1 = require("./TezosCryptoClient");
100
+ var TezosProtocolOptions_1 = require("./TezosProtocolOptions");
101
+ var TezosUtils_1 = require("./TezosUtils");
102
+ var TezosOperationType_1 = require("./types/TezosOperationType");
103
+ var MAX_OPERATIONS_PER_GROUP = 200;
104
+ var MAX_GAS_PER_BLOCK = 5200000;
105
+ var GAS_LIMIT_PLACEHOLDER = '1040000';
106
+ var STORAGE_LIMIT_PLACEHOLDER = '60000';
107
+ var FEE_PLACEHOLDER = '0';
108
+ var MINIMAL_FEE = 100;
109
+ var MINIMAL_FEE_PER_GAS_UNIT = 0.1;
110
+ var MINIMAL_FEE_PER_BYTE = 1;
111
+ var TezosDelegatorAction;
112
+ (function (TezosDelegatorAction) {
113
+ TezosDelegatorAction["DELEGATE"] = "delegate";
114
+ TezosDelegatorAction["UNDELEGATE"] = "undelegate";
115
+ TezosDelegatorAction["CHANGE_BAKER"] = "change_baker";
116
+ })(TezosDelegatorAction = exports.TezosDelegatorAction || (exports.TezosDelegatorAction = {}));
117
+ // 8.25%
118
+ var SELF_BOND_REQUIREMENT = 0.0825;
119
+ var TezosNetwork;
120
+ (function (TezosNetwork) {
121
+ TezosNetwork["MAINNET"] = "mainnet";
122
+ TezosNetwork["GHOSTNET"] = "ghostnet";
123
+ })(TezosNetwork = exports.TezosNetwork || (exports.TezosNetwork = {}));
124
+ var TezosProtocol = /** @class */ (function (_super) {
125
+ __extends(TezosProtocol, _super);
126
+ function TezosProtocol(options) {
127
+ if (options === void 0) { options = new TezosProtocolOptions_1.TezosProtocolOptions(); }
128
+ var _this = _super.call(this) || this;
129
+ _this.options = options;
130
+ _this.symbol = 'XTZ';
131
+ _this.name = 'Tezos';
132
+ _this.marketSymbol = 'xtz';
133
+ _this.feeSymbol = 'xtz';
134
+ _this.decimals = 6;
135
+ _this.feeDecimals = 6; // micro tez is the smallest, 1000000 microtez is 1 tez
136
+ _this.identifier = ProtocolSymbols_1.MainProtocolSymbols.XTZ;
137
+ // tezbox default
138
+ _this.feeDefaults = {
139
+ low: '0.001420',
140
+ medium: '0.001520',
141
+ high: '0.003000'
142
+ };
143
+ _this.units = [
144
+ {
145
+ unitSymbol: 'XTZ',
146
+ factor: '1'
147
+ }
148
+ ];
149
+ _this.supportsHD = false;
150
+ _this.standardDerivationPath = "m/44h/1729h/0h/0h";
151
+ _this.addressIsCaseSensitive = true;
152
+ _this.addressValidationPattern = '^((tz1|tz2|tz3|KT1)[1-9A-Za-z]{33}|zet1[1-9A-Za-z]{65})$';
153
+ _this.addressPlaceholder = 'tz1...';
154
+ // https://gitlab.com/tezos/tezos/-/blob/master/docs/whitedoc/proof_of_stake.rst
155
+ // cycle has 4096 blocks, which are at least one minute apart
156
+ _this.minCycleDuration = 4096 * 60 * 1000; // ms
157
+ _this.transactionFee = new bignumber_1.default('1400');
158
+ _this.originationSize = new bignumber_1.default('257');
159
+ _this.storageCostPerByte = new bignumber_1.default('1000');
160
+ _this.revealFee = new bignumber_1.default('1300');
161
+ _this.activationBurn = _this.originationSize.times(_this.storageCostPerByte);
162
+ _this.originationBurn = _this.originationSize.times(_this.storageCostPerByte); // https://tezos.stackexchange.com/a/787
163
+ _this.cryptoClient = new TezosCryptoClient_1.TezosCryptoClient(TezosUtils_1.TezosUtils.tezosPrefixes.edsig);
164
+ return _this;
165
+ }
166
+ Object.defineProperty(TezosProtocol.prototype, "jsonRPCAPI", {
167
+ // TODO: Should we remove these getters and replace the calls to `this.options.network...`?
168
+ get: function () {
169
+ return this.options.network.rpcUrl;
170
+ },
171
+ enumerable: false,
172
+ configurable: true
173
+ });
174
+ TezosProtocol.prototype.getSymbol = function () {
175
+ return __awaiter(this, void 0, void 0, function () {
176
+ return __generator(this, function (_a) {
177
+ return [2 /*return*/, this.symbol];
178
+ });
179
+ });
180
+ };
181
+ TezosProtocol.prototype.getName = function () {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ return __generator(this, function (_a) {
184
+ return [2 /*return*/, this.name];
185
+ });
186
+ });
187
+ };
188
+ TezosProtocol.prototype.getMarketSymbol = function () {
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ return __generator(this, function (_a) {
191
+ return [2 /*return*/, this.marketSymbol];
192
+ });
193
+ });
194
+ };
195
+ TezosProtocol.prototype.getFeeSymbol = function () {
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ return __generator(this, function (_a) {
198
+ return [2 /*return*/, this.feeSymbol];
199
+ });
200
+ });
201
+ };
202
+ TezosProtocol.prototype.getDecimals = function () {
203
+ return __awaiter(this, void 0, void 0, function () {
204
+ return __generator(this, function (_a) {
205
+ return [2 /*return*/, this.decimals];
206
+ });
207
+ });
208
+ };
209
+ TezosProtocol.prototype.getFeeDecimals = function () {
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ return __generator(this, function (_a) {
212
+ return [2 /*return*/, this.feeDecimals];
213
+ });
214
+ });
215
+ };
216
+ TezosProtocol.prototype.getIdentifier = function () {
217
+ return __awaiter(this, void 0, void 0, function () {
218
+ return __generator(this, function (_a) {
219
+ return [2 /*return*/, this.identifier];
220
+ });
221
+ });
222
+ };
223
+ TezosProtocol.prototype.getFeeDefaults = function () {
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ return __generator(this, function (_a) {
226
+ return [2 /*return*/, this.feeDefaults];
227
+ });
228
+ });
229
+ };
230
+ TezosProtocol.prototype.getUnits = function () {
231
+ return __awaiter(this, void 0, void 0, function () {
232
+ return __generator(this, function (_a) {
233
+ return [2 /*return*/, this.units];
234
+ });
235
+ });
236
+ };
237
+ TezosProtocol.prototype.getSupportsHD = function () {
238
+ return __awaiter(this, void 0, void 0, function () {
239
+ return __generator(this, function (_a) {
240
+ return [2 /*return*/, this.supportsHD];
241
+ });
242
+ });
243
+ };
244
+ TezosProtocol.prototype.getStandardDerivationPath = function () {
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ return __generator(this, function (_a) {
247
+ return [2 /*return*/, this.standardDerivationPath];
248
+ });
249
+ });
250
+ };
251
+ TezosProtocol.prototype.getAddressIsCaseSensitive = function () {
252
+ return __awaiter(this, void 0, void 0, function () {
253
+ return __generator(this, function (_a) {
254
+ return [2 /*return*/, this.addressIsCaseSensitive];
255
+ });
256
+ });
257
+ };
258
+ TezosProtocol.prototype.getAddressValidationPattern = function () {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ return __generator(this, function (_a) {
261
+ return [2 /*return*/, this.addressValidationPattern];
262
+ });
263
+ });
264
+ };
265
+ TezosProtocol.prototype.getAddressPlaceholder = function () {
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ return __generator(this, function (_a) {
268
+ return [2 /*return*/, this.addressPlaceholder];
269
+ });
270
+ });
271
+ };
272
+ TezosProtocol.prototype.getOptions = function () {
273
+ return __awaiter(this, void 0, void 0, function () {
274
+ return __generator(this, function (_a) {
275
+ return [2 /*return*/, this.options];
276
+ });
277
+ });
278
+ };
279
+ TezosProtocol.prototype.getBlockExplorerLinkForAddress = function (address) {
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ return __generator(this, function (_a) {
282
+ return [2 /*return*/, this.options.network.blockExplorer.getAddressLink(address)];
283
+ });
284
+ });
285
+ };
286
+ TezosProtocol.prototype.getBlockExplorerLinkForTxId = function (txId) {
287
+ return __awaiter(this, void 0, void 0, function () {
288
+ return __generator(this, function (_a) {
289
+ return [2 /*return*/, this.options.network.blockExplorer.getTransactionLink(txId)];
290
+ });
291
+ });
292
+ };
293
+ TezosProtocol.prototype.getPublicKeyFromMnemonic = function (mnemonic, derivationPath, password) {
294
+ return __awaiter(this, void 0, void 0, function () {
295
+ var secret;
296
+ return __generator(this, function (_a) {
297
+ secret = index_2.mnemonicToSeed(mnemonic, password);
298
+ return [2 /*return*/, this.getPublicKeyFromHexSecret(secret, derivationPath)];
299
+ });
300
+ });
301
+ };
302
+ TezosProtocol.prototype.getPrivateKeyFromMnemonic = function (mnemonic, derivationPath, password) {
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var secret;
305
+ return __generator(this, function (_a) {
306
+ secret = index_2.mnemonicToSeed(mnemonic, password);
307
+ return [2 /*return*/, this.getPrivateKeyFromHexSecret(secret, derivationPath)];
308
+ });
309
+ });
310
+ };
311
+ /**
312
+ * Returns the PublicKey as String, derived from a supplied hex-string
313
+ * @param secret HEX-Secret from BIP39
314
+ * @param derivationPath DerivationPath for Key
315
+ */
316
+ TezosProtocol.prototype.getPublicKeyFromHexSecret = function (secret, derivationPath) {
317
+ return __awaiter(this, void 0, void 0, function () {
318
+ var publicKey;
319
+ return __generator(this, function (_a) {
320
+ publicKey = index_3.generateWalletUsingDerivationPath(Buffer.from(secret, 'hex'), derivationPath) // TODO: Look into typings
321
+ .publicKey;
322
+ return [2 /*return*/, Buffer.from(publicKey).toString('hex')];
323
+ });
324
+ });
325
+ };
326
+ /**
327
+ * Returns the PrivateKey as Buffer, derived from a supplied hex-string
328
+ * @param secret HEX-Secret from BIP39
329
+ * @param derivationPath DerivationPath for Key
330
+ */
331
+ TezosProtocol.prototype.getPrivateKeyFromHexSecret = function (secret, derivationPath) {
332
+ return __awaiter(this, void 0, void 0, function () {
333
+ var secretKey;
334
+ return __generator(this, function (_a) {
335
+ secretKey = index_3.generateWalletUsingDerivationPath(Buffer.from(secret, 'hex'), derivationPath) // TODO: Look into typings
336
+ .secretKey;
337
+ return [2 /*return*/, Buffer.from(secretKey).toString('hex')];
338
+ });
339
+ });
340
+ };
341
+ TezosProtocol.prototype.getAddressFromPublicKey = function (publicKey, cursor) {
342
+ return __awaiter(this, void 0, void 0, function () {
343
+ var address;
344
+ return __generator(this, function (_a) {
345
+ switch (_a.label) {
346
+ case 0: return [4 /*yield*/, TezosAddress_1.TezosAddress.fromPublicKey(publicKey)];
347
+ case 1:
348
+ address = _a.sent();
349
+ return [2 /*return*/, {
350
+ address: address.asString(),
351
+ cursor: { hasNext: false }
352
+ }];
353
+ }
354
+ });
355
+ });
356
+ };
357
+ TezosProtocol.prototype.getAddressesFromPublicKey = function (publicKey, cursor) {
358
+ return __awaiter(this, void 0, void 0, function () {
359
+ var address;
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey, cursor)];
363
+ case 1:
364
+ address = _a.sent();
365
+ return [2 /*return*/, [address]];
366
+ }
367
+ });
368
+ });
369
+ };
370
+ TezosProtocol.prototype.getTransactionsFromPublicKey = function (publicKey, limit, cursor) {
371
+ return __awaiter(this, void 0, void 0, function () {
372
+ var addresses;
373
+ return __generator(this, function (_a) {
374
+ switch (_a.label) {
375
+ case 0: return [4 /*yield*/, this.getAddressesFromPublicKey(publicKey).then(function (addresses) {
376
+ return addresses.map(function (address) { return address.address; });
377
+ })];
378
+ case 1:
379
+ addresses = _a.sent();
380
+ return [2 /*return*/, this.getTransactionsFromAddresses(addresses, limit, cursor)];
381
+ }
382
+ });
383
+ });
384
+ };
385
+ TezosProtocol.prototype.getTransactionsFromAddresses = function (addresses, limit, cursor) {
386
+ var _a;
387
+ return __awaiter(this, void 0, void 0, function () {
388
+ var address, results;
389
+ var _this = this;
390
+ return __generator(this, function (_b) {
391
+ switch (_b.label) {
392
+ case 0:
393
+ address = addresses[0];
394
+ return [4 /*yield*/, this.options.network.extras.indexerClient.getTransactions(address, limit, cursor === null || cursor === void 0 ? void 0 : cursor.offset)];
395
+ case 1:
396
+ results = _b.sent();
397
+ return [2 /*return*/, {
398
+ transactions: results.map(function (transaction) { return (__assign(__assign({}, transaction), { protocolIdentifier: _this.identifier, network: _this.options.network })); }),
399
+ cursor: { offset: ((_a = cursor === null || cursor === void 0 ? void 0 : cursor.offset) !== null && _a !== void 0 ? _a : 0) + results.length }
400
+ }];
401
+ }
402
+ });
403
+ });
404
+ };
405
+ TezosProtocol.prototype.signWithPrivateKey = function (privateKey, transaction) {
406
+ return __awaiter(this, void 0, void 0, function () {
407
+ var opSignature, signedOpBytes;
408
+ return __generator(this, function (_a) {
409
+ switch (_a.label) {
410
+ case 0: return [4 /*yield*/, this.cryptoClient.operationSignature(Buffer.from(privateKey, 'hex'), transaction)];
411
+ case 1:
412
+ opSignature = _a.sent();
413
+ signedOpBytes = Buffer.concat([Buffer.from(transaction.binaryTransaction, 'hex'), Buffer.from(opSignature)]);
414
+ return [2 /*return*/, signedOpBytes.toString('hex')];
415
+ }
416
+ });
417
+ });
418
+ };
419
+ TezosProtocol.prototype.getTransactionDetails = function (unsignedTx) {
420
+ return __awaiter(this, void 0, void 0, function () {
421
+ var binaryTransaction, wrappedOperations;
422
+ return __generator(this, function (_a) {
423
+ switch (_a.label) {
424
+ case 0:
425
+ binaryTransaction = unsignedTx.transaction.binaryTransaction;
426
+ return [4 /*yield*/, this.unforgeUnsignedTezosWrappedOperation(binaryTransaction)];
427
+ case 1:
428
+ wrappedOperations = _a.sent();
429
+ return [2 /*return*/, this.getAirGapTxFromWrappedOperations(wrappedOperations)];
430
+ }
431
+ });
432
+ });
433
+ };
434
+ TezosProtocol.prototype.getTransactionDetailsFromSigned = function (signedTx) {
435
+ return __awaiter(this, void 0, void 0, function () {
436
+ var binaryTransaction, wrappedOperations;
437
+ return __generator(this, function (_a) {
438
+ switch (_a.label) {
439
+ case 0:
440
+ binaryTransaction = signedTx.transaction;
441
+ return [4 /*yield*/, this.unforgeSignedTezosWrappedOperation(binaryTransaction)];
442
+ case 1:
443
+ wrappedOperations = _a.sent();
444
+ return [2 /*return*/, this.getAirGapTxFromWrappedOperations(wrappedOperations)];
445
+ }
446
+ });
447
+ });
448
+ };
449
+ TezosProtocol.prototype.getAirGapTxFromWrappedOperations = function (wrappedOperations) {
450
+ return __awaiter(this, void 0, void 0, function () {
451
+ var assertNever;
452
+ var _this = this;
453
+ return __generator(this, function (_a) {
454
+ assertNever = function (_x) { return undefined; };
455
+ return [2 /*return*/, Promise.all(wrappedOperations.contents.map(function (tezosOperation) { return __awaiter(_this, void 0, void 0, function () {
456
+ var operation, partialTxs, _a, tezosSpendOperation_1, tezosOriginationOperation, delegate, delegate;
457
+ var _this = this;
458
+ return __generator(this, function (_b) {
459
+ switch (_b.label) {
460
+ case 0:
461
+ partialTxs = [];
462
+ _a = tezosOperation.kind;
463
+ switch (_a) {
464
+ case TezosOperationType_1.TezosOperationType.REVEAL: return [3 /*break*/, 1];
465
+ case TezosOperationType_1.TezosOperationType.TRANSACTION: return [3 /*break*/, 2];
466
+ case TezosOperationType_1.TezosOperationType.ORIGINATION: return [3 /*break*/, 4];
467
+ case TezosOperationType_1.TezosOperationType.DELEGATION: return [3 /*break*/, 5];
468
+ case TezosOperationType_1.TezosOperationType.ENDORSEMENT: return [3 /*break*/, 6];
469
+ case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION: return [3 /*break*/, 6];
470
+ case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE: return [3 /*break*/, 6];
471
+ case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE: return [3 /*break*/, 6];
472
+ case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT: return [3 /*break*/, 6];
473
+ case TezosOperationType_1.TezosOperationType.PROPOSALS: return [3 /*break*/, 6];
474
+ case TezosOperationType_1.TezosOperationType.BALLOT: return [3 /*break*/, 6];
475
+ }
476
+ return [3 /*break*/, 7];
477
+ case 1:
478
+ operation = tezosOperation;
479
+ partialTxs = [
480
+ {
481
+ from: [operation.source],
482
+ to: ['Reveal']
483
+ }
484
+ ];
485
+ return [3 /*break*/, 8];
486
+ case 2:
487
+ tezosSpendOperation_1 = tezosOperation;
488
+ operation = tezosSpendOperation_1;
489
+ return [4 /*yield*/, this.getTransactionOperationDetails(tezosSpendOperation_1)];
490
+ case 3:
491
+ partialTxs = (_b.sent()).map(function (tx) { return (__assign(__assign({}, tx), { extra: __assign(__assign({}, tx.extra), { parameters: tezosSpendOperation_1.parameters }) })); });
492
+ return [3 /*break*/, 8];
493
+ case 4:
494
+ {
495
+ tezosOriginationOperation = tezosOperation;
496
+ operation = tezosOriginationOperation;
497
+ delegate = tezosOriginationOperation.delegate;
498
+ partialTxs = [
499
+ {
500
+ from: [operation.source],
501
+ amount: new bignumber_1.default(tezosOriginationOperation.balance).toFixed(),
502
+ to: [delegate ? "Delegate: " + delegate : 'Origination']
503
+ }
504
+ ];
505
+ }
506
+ return [3 /*break*/, 8];
507
+ case 5:
508
+ {
509
+ operation = tezosOperation;
510
+ delegate = operation.delegate;
511
+ partialTxs = [
512
+ {
513
+ from: [operation.source],
514
+ to: [delegate ? delegate : 'Undelegate']
515
+ }
516
+ ];
517
+ }
518
+ return [3 /*break*/, 8];
519
+ case 6: throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, 'operation not supported: ' + JSON.stringify(tezosOperation.kind));
520
+ case 7:
521
+ // Exhaustive switch
522
+ assertNever(tezosOperation.kind);
523
+ throw new index_4.NotFoundError(coinlib_error_1.Domain.TEZOS, 'no operation to unforge found');
524
+ case 8: return [2 /*return*/, partialTxs.map(function (partialTx) {
525
+ return __assign({ amount: '0', fee: operation !== undefined ? new bignumber_1.default(operation.fee).toString(10) : '0', from: [], isInbound: false, protocolIdentifier: _this.identifier, network: _this.options.network, to: [], transactionDetails: tezosOperation }, partialTx);
526
+ })];
527
+ }
528
+ });
529
+ }); })).then(function (airGapTxs) {
530
+ return airGapTxs.reduce(function (flatten, next) { return flatten.concat(next); }, []);
531
+ })];
532
+ });
533
+ });
534
+ };
535
+ TezosProtocol.prototype.getBalanceOfAddresses = function (addresses, _data) {
536
+ return __awaiter(this, void 0, void 0, function () {
537
+ var balance, _i, addresses_1, address, data, error_1;
538
+ return __generator(this, function (_a) {
539
+ switch (_a.label) {
540
+ case 0:
541
+ balance = new bignumber_1.default(0);
542
+ _i = 0, addresses_1 = addresses;
543
+ _a.label = 1;
544
+ case 1:
545
+ if (!(_i < addresses_1.length)) return [3 /*break*/, 6];
546
+ address = addresses_1[_i];
547
+ _a.label = 2;
548
+ case 2:
549
+ _a.trys.push([2, 4, , 5]);
550
+ return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address + "/balance")];
551
+ case 3:
552
+ data = (_a.sent()).data;
553
+ balance = balance.plus(new bignumber_1.default(data));
554
+ return [3 /*break*/, 5];
555
+ case 4:
556
+ error_1 = _a.sent();
557
+ // if node returns 404 (which means 'no account found'), go with 0 balance
558
+ if (error_1.response && error_1.response.status !== 404) {
559
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error_1);
560
+ }
561
+ return [3 /*break*/, 5];
562
+ case 5:
563
+ _i++;
564
+ return [3 /*break*/, 1];
565
+ case 6: return [2 /*return*/, balance.toString(10)];
566
+ }
567
+ });
568
+ });
569
+ };
570
+ TezosProtocol.prototype.getBalanceOfPublicKey = function (publicKey, data) {
571
+ return __awaiter(this, void 0, void 0, function () {
572
+ var address;
573
+ return __generator(this, function (_a) {
574
+ switch (_a.label) {
575
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
576
+ case 1:
577
+ address = _a.sent();
578
+ return [2 /*return*/, this.getBalanceOfAddresses([address.address], data)];
579
+ }
580
+ });
581
+ });
582
+ };
583
+ TezosProtocol.prototype.getBalanceOfPublicKeyForSubProtocols = function (publicKey, subProtocols) {
584
+ return __awaiter(this, void 0, void 0, function () {
585
+ return __generator(this, function (_a) {
586
+ return [2 /*return*/, Promise.all(subProtocols.map(function (subProtocol) { return subProtocol.getBalanceOfPublicKey(publicKey).catch(function () { return '0'; }); }))];
587
+ });
588
+ });
589
+ };
590
+ TezosProtocol.prototype.getAvailableBalanceOfAddresses = function (addresses, data) {
591
+ return __awaiter(this, void 0, void 0, function () {
592
+ return __generator(this, function (_a) {
593
+ return [2 /*return*/, this.getBalanceOfAddresses(addresses, data)];
594
+ });
595
+ });
596
+ };
597
+ TezosProtocol.prototype.estimateMaxTransactionValueFromPublicKey = function (publicKey, recipients, fee) {
598
+ return __awaiter(this, void 0, void 0, function () {
599
+ var balance, balanceWrapper;
600
+ return __generator(this, function (_a) {
601
+ switch (_a.label) {
602
+ case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
603
+ case 1:
604
+ balance = _a.sent();
605
+ balanceWrapper = new bignumber_1.default(balance).minus(1) // Tezos accounts can never be empty. We must leave at least 1 mutez behind.
606
+ ;
607
+ return [2 /*return*/, this.estimateMaxTansactionValueWithBalance(publicKey, balanceWrapper, recipients, fee)];
608
+ }
609
+ });
610
+ });
611
+ };
612
+ TezosProtocol.prototype.estimateMaxTansactionValueWithBalance = function (publicKey, balance, recipients, fee) {
613
+ return __awaiter(this, void 0, void 0, function () {
614
+ var maxFee, estimatedFeeDefaults, error_2, rpcErrors, balanceTooLowError, excess, newMaxBalance, amountWithoutFees;
615
+ return __generator(this, function (_a) {
616
+ switch (_a.label) {
617
+ case 0:
618
+ maxFee = new bignumber_1.default(0);
619
+ if (!(fee !== undefined)) return [3 /*break*/, 1];
620
+ maxFee = new bignumber_1.default(fee);
621
+ return [3 /*break*/, 4];
622
+ case 1:
623
+ _a.trys.push([1, 3, , 4]);
624
+ return [4 /*yield*/, this.estimateFeeDefaultsFromPublicKey(publicKey, recipients, [balance.toFixed()])];
625
+ case 2:
626
+ estimatedFeeDefaults = _a.sent();
627
+ maxFee = new bignumber_1.default(estimatedFeeDefaults.medium).shiftedBy(this.decimals);
628
+ if (maxFee.gte(balance)) {
629
+ maxFee = new bignumber_1.default(0);
630
+ }
631
+ return [3 /*break*/, 4];
632
+ case 3:
633
+ error_2 = _a.sent();
634
+ if (error_2.code !== undefined && error_2.code === index_4.ProtocolErrorType.TRANSACTION_FAILED && Array.isArray(error_2.data)) {
635
+ rpcErrors = error_2.data;
636
+ balanceTooLowError = rpcErrors.find(function (error) { return error.id.endsWith('.contract.balance_too_low'); });
637
+ if (balanceTooLowError !== undefined && balanceTooLowError.amount !== undefined && balanceTooLowError.balance !== undefined) {
638
+ excess = new bignumber_1.default(balanceTooLowError.amount).minus(new bignumber_1.default(balanceTooLowError.balance).minus(1));
639
+ newMaxBalance = balance.minus(excess);
640
+ if (newMaxBalance.gt(0)) {
641
+ return [2 /*return*/, this.estimateMaxTansactionValueWithBalance(publicKey, newMaxBalance, recipients, fee)];
642
+ }
643
+ }
644
+ }
645
+ throw error_2;
646
+ case 4:
647
+ amountWithoutFees = balance.minus(maxFee);
648
+ if (amountWithoutFees.isNegative()) {
649
+ amountWithoutFees = new bignumber_1.default(0);
650
+ }
651
+ return [2 /*return*/, amountWithoutFees.toFixed()];
652
+ }
653
+ });
654
+ });
655
+ };
656
+ TezosProtocol.prototype.estimateFeeDefaultsFromPublicKey = function (publicKey, recipients, values, _data) {
657
+ return __awaiter(this, void 0, void 0, function () {
658
+ var operations, i, recipient, transaction;
659
+ return __generator(this, function (_a) {
660
+ if (recipients.length !== values.length) {
661
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
662
+ }
663
+ operations = [];
664
+ for (i = 0; i < values.length; ++i) {
665
+ recipient = recipients[i];
666
+ transaction = {
667
+ kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
668
+ amount: values[i],
669
+ destination: recipient,
670
+ fee: '0'
671
+ };
672
+ operations.push(transaction);
673
+ }
674
+ if (recipients.length === 0) {
675
+ return [2 /*return*/, this.feeDefaults];
676
+ }
677
+ return [2 /*return*/, this.estimateFeeDefaultsForOperations(publicKey, operations)];
678
+ });
679
+ });
680
+ };
681
+ TezosProtocol.prototype.estimateFeeDefaultsForOperations = function (publicKey, operations) {
682
+ return __awaiter(this, void 0, void 0, function () {
683
+ var estimated, hasReveal, estimatedFee, feeStepFactor, lowFee, mediumFee, highFee;
684
+ return __generator(this, function (_a) {
685
+ switch (_a.label) {
686
+ case 0: return [4 /*yield*/, this.prepareOperations(publicKey, operations)];
687
+ case 1:
688
+ estimated = _a.sent();
689
+ hasReveal = estimated.contents.some(function (op) { return op.kind === TezosOperationType_1.TezosOperationType.REVEAL; });
690
+ estimatedFee = estimated.contents
691
+ .reduce(function (current, next) {
692
+ if (next.fee !== undefined) {
693
+ return current.plus(new bignumber_1.default(next.fee));
694
+ }
695
+ return current;
696
+ }, new bignumber_1.default(0))
697
+ .minus(hasReveal ? this.revealFee : 0)
698
+ .div(hasReveal ? estimated.contents.length - 1 : estimated.contents.length);
699
+ feeStepFactor = new bignumber_1.default(0.2);
700
+ lowFee = estimatedFee;
701
+ mediumFee = lowFee.plus(lowFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
702
+ highFee = mediumFee.plus(mediumFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
703
+ return [2 /*return*/, {
704
+ low: lowFee.shiftedBy(-this.feeDecimals).toFixed(),
705
+ medium: mediumFee.shiftedBy(-this.feeDecimals).toFixed(),
706
+ high: highFee.shiftedBy(-this.feeDecimals).toFixed()
707
+ }];
708
+ }
709
+ });
710
+ });
711
+ };
712
+ TezosProtocol.prototype.prepareTransactionFromPublicKey = function (publicKey, recipients, values, fee, data) {
713
+ return __awaiter(this, void 0, void 0, function () {
714
+ var transactions;
715
+ return __generator(this, function (_a) {
716
+ switch (_a.label) {
717
+ case 0:
718
+ if (recipients.length !== values.length) {
719
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
720
+ }
721
+ if (recipients.length > MAX_OPERATIONS_PER_GROUP) {
722
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, "this transaction exceeds the maximum allowed number of transactions per operation (" + MAX_OPERATIONS_PER_GROUP + "). Please use the \"prepareTransactionsFromPublicKey\" method instead.");
723
+ }
724
+ return [4 /*yield*/, this.prepareTransactionsFromPublicKey(publicKey, recipients, values, fee, data)];
725
+ case 1:
726
+ transactions = _a.sent();
727
+ if (transactions.length === 1) {
728
+ return [2 /*return*/, transactions[0]];
729
+ }
730
+ else {
731
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'Transaction could not be prepared. More or less than 1 operations have been generated.');
732
+ }
733
+ return [2 /*return*/];
734
+ }
735
+ });
736
+ });
737
+ };
738
+ TezosProtocol.prototype.prepareTransactionsFromPublicKey = function (publicKey, recipients, values, fee, data, operationsPerGroup) {
739
+ if (operationsPerGroup === void 0) { operationsPerGroup = MAX_OPERATIONS_PER_GROUP; }
740
+ return __awaiter(this, void 0, void 0, function () {
741
+ var wrappedValues, wrappedFee, operations, addressIndex, addresses, address, results, currentCounter, counter, branch, accountManager, _a, _b, balance, _c, wrappedOperations, allOperations, numberOfGroups, startingCounter, i, start, end, operationsGroup, wrappedOperationWithEstimatedGas, _d, _e;
742
+ return __generator(this, function (_f) {
743
+ switch (_f.label) {
744
+ case 0:
745
+ wrappedValues = values.map(function (value) { return new bignumber_1.default(value); });
746
+ wrappedFee = new bignumber_1.default(fee);
747
+ if (recipients.length !== wrappedValues.length) {
748
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'length of recipients and values does not match!');
749
+ }
750
+ operations = [];
751
+ addressIndex = data && data.addressIndex ? data.addressIndex : 0;
752
+ return [4 /*yield*/, this.getAddressesFromPublicKey(publicKey).then(function (addresses) {
753
+ return addresses.map(function (address) { return address.address; });
754
+ })];
755
+ case 1:
756
+ addresses = _f.sent();
757
+ if (!addresses[addressIndex]) {
758
+ throw new index_4.NotFoundError(coinlib_error_1.Domain.TEZOS, 'no kt-address with this index exists');
759
+ }
760
+ address = addresses[addressIndex];
761
+ return [4 /*yield*/, Promise.all([
762
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address + "/counter"),
763
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head~2/hash"),
764
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address + "/manager_key")
765
+ ]).catch(function (error) {
766
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
767
+ })];
768
+ case 2:
769
+ results = _f.sent();
770
+ currentCounter = new bignumber_1.default(results[0].data);
771
+ counter = currentCounter.plus(1);
772
+ branch = results[1].data;
773
+ accountManager = results[2].data;
774
+ if (!!accountManager) return [3 /*break*/, 4];
775
+ _b = (_a = operations).push;
776
+ return [4 /*yield*/, this.createRevealOperation(counter, publicKey, address)];
777
+ case 3:
778
+ _b.apply(_a, [_f.sent()]);
779
+ counter = counter.plus(1);
780
+ _f.label = 4;
781
+ case 4:
782
+ _c = bignumber_1.default.bind;
783
+ return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
784
+ case 5:
785
+ balance = new (_c.apply(bignumber_1.default, [void 0, _f.sent()]))();
786
+ wrappedOperations = [];
787
+ return [4 /*yield*/, this.createTransactionOperations(operations, recipients, wrappedValues, wrappedFee, address, counter, balance)];
788
+ case 6:
789
+ allOperations = _f.sent();
790
+ allOperations = operations.concat(allOperations); // if we have a reveal in operations, we need to make sure it is present in the allOperations array
791
+ numberOfGroups = Math.ceil(allOperations.length / operationsPerGroup);
792
+ startingCounter = numberOfGroups > 1 ? currentCounter.plus(1) : undefined;
793
+ i = 0;
794
+ _f.label = 7;
795
+ case 7:
796
+ if (!(i < numberOfGroups)) return [3 /*break*/, 11];
797
+ start = i * operationsPerGroup;
798
+ end = start + operationsPerGroup;
799
+ operationsGroup = allOperations.slice(start, end);
800
+ return [4 /*yield*/, this.estimateAndReplaceLimitsAndFee({
801
+ branch: branch,
802
+ contents: operationsGroup
803
+ }, false, startingCounter)];
804
+ case 8:
805
+ wrappedOperationWithEstimatedGas = _f.sent();
806
+ _e = (_d = wrappedOperations).push;
807
+ return [4 /*yield*/, this.forgeAndWrapOperations(wrappedOperationWithEstimatedGas)];
808
+ case 9:
809
+ _e.apply(_d, [_f.sent()]);
810
+ _f.label = 10;
811
+ case 10:
812
+ i++;
813
+ return [3 /*break*/, 7];
814
+ case 11: return [2 /*return*/, wrappedOperations];
815
+ }
816
+ });
817
+ });
818
+ };
819
+ TezosProtocol.prototype.getTransactionOperationDetails = function (transactionOperation) {
820
+ return __awaiter(this, void 0, void 0, function () {
821
+ return __generator(this, function (_a) {
822
+ return [2 /*return*/, [
823
+ {
824
+ from: [transactionOperation.source],
825
+ amount: new bignumber_1.default(transactionOperation.amount).toFixed(),
826
+ to: [transactionOperation.destination] // contract destination but should be the address of actual receiver
827
+ }
828
+ ]];
829
+ });
830
+ });
831
+ };
832
+ TezosProtocol.prototype.createTransactionOperations = function (previousOperations, recipients, wrappedValues, wrappedFee, address, counter, balance) {
833
+ return __awaiter(this, void 0, void 0, function () {
834
+ var amountUsedByPreviousOperations, operations, i, receivingBalance, _a, spendOperation;
835
+ return __generator(this, function (_b) {
836
+ switch (_b.label) {
837
+ case 0:
838
+ amountUsedByPreviousOperations = this.getAmountUsedByPreviousOperations(previousOperations);
839
+ operations = [];
840
+ if (!amountUsedByPreviousOperations.isZero()) {
841
+ if (balance.isLessThan(wrappedValues[0].plus(wrappedFee).plus(amountUsedByPreviousOperations))) {
842
+ // if not, make room for the init fee
843
+ wrappedValues[0] = wrappedValues[0].minus(amountUsedByPreviousOperations); // deduct fee from balance
844
+ }
845
+ }
846
+ i = 0;
847
+ _b.label = 1;
848
+ case 1:
849
+ if (!(i < recipients.length)) return [3 /*break*/, 4];
850
+ _a = bignumber_1.default.bind;
851
+ return [4 /*yield*/, this.getBalanceOfAddresses([recipients[i]])];
852
+ case 2:
853
+ receivingBalance = new (_a.apply(bignumber_1.default, [void 0, _b.sent()]))();
854
+ // if our receiver has 0 balance, the account is not activated yet.
855
+ if (receivingBalance.isZero() && recipients[i].toLowerCase().startsWith('tz')) {
856
+ // We have to supply an additional 0.257 XTZ fee for storage_limit costs, which gets automatically deducted from the sender so we just have to make sure enough balance is around
857
+ if (balance.isLessThan(this.activationBurn.plus(wrappedFee))) {
858
+ // If we don't have enough funds to pay the activation + fee, we throw an error
859
+ throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'Insufficient balance to pay activation burn!');
860
+ }
861
+ else if (balance.isLessThan(wrappedValues[i].plus(wrappedFee).plus(this.activationBurn))) {
862
+ // Check whether the sender has enough to cover the amount to send + fee + activation
863
+ // If not, we deduct it from amount sent to make room for the activation burn
864
+ wrappedValues[i] = wrappedValues[i].minus(this.activationBurn); // deduct fee from balance
865
+ }
866
+ }
867
+ if (balance.isEqualTo(wrappedValues[i].plus(wrappedFee))) {
868
+ // Tezos accounts can never be empty. If user tries to send everything, we must leave 1 mutez behind.
869
+ wrappedValues[i] = wrappedValues[i].minus(1);
870
+ }
871
+ else if (balance.isLessThan(wrappedValues[i].plus(wrappedFee))) {
872
+ throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'not enough balance');
873
+ }
874
+ spendOperation = {
875
+ kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
876
+ fee: wrappedFee.toFixed(),
877
+ gas_limit: GAS_LIMIT_PLACEHOLDER,
878
+ storage_limit: STORAGE_LIMIT_PLACEHOLDER,
879
+ amount: wrappedValues[i].toFixed(),
880
+ counter: counter.plus(i).toFixed(),
881
+ destination: recipients[i],
882
+ source: address
883
+ };
884
+ operations.push(spendOperation);
885
+ _b.label = 3;
886
+ case 3:
887
+ i++;
888
+ return [3 /*break*/, 1];
889
+ case 4: return [2 /*return*/, operations];
890
+ }
891
+ });
892
+ });
893
+ };
894
+ TezosProtocol.prototype.forgeAndWrapOperations = function (tezosWrappedOperation) {
895
+ return __awaiter(this, void 0, void 0, function () {
896
+ var binaryTx, error_3;
897
+ return __generator(this, function (_a) {
898
+ switch (_a.label) {
899
+ case 0:
900
+ _a.trys.push([0, 2, , 3]);
901
+ return [4 /*yield*/, this.forgeTezosOperation(tezosWrappedOperation)];
902
+ case 1:
903
+ binaryTx = _a.sent();
904
+ return [2 /*return*/, { binaryTransaction: binaryTx }];
905
+ case 2:
906
+ error_3 = _a.sent();
907
+ throw new index_4.OperationFailedError(coinlib_error_1.Domain.TEZOS, "Forging Tezos TX failed with " + JSON.stringify(error_3.message));
908
+ case 3: return [2 /*return*/];
909
+ }
910
+ });
911
+ });
912
+ };
913
+ TezosProtocol.prototype.getDefaultDelegatee = function () {
914
+ return __awaiter(this, void 0, void 0, function () {
915
+ var activeBakers;
916
+ return __generator(this, function (_a) {
917
+ switch (_a.label) {
918
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/delegates?active")];
919
+ case 1:
920
+ activeBakers = (_a.sent()).data;
921
+ return [2 /*return*/, activeBakers[0] || ''];
922
+ }
923
+ });
924
+ });
925
+ };
926
+ TezosProtocol.prototype.getCurrentDelegateesForPublicKey = function (publicKey) {
927
+ return __awaiter(this, void 0, void 0, function () {
928
+ var address;
929
+ return __generator(this, function (_a) {
930
+ switch (_a.label) {
931
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
932
+ case 1:
933
+ address = _a.sent();
934
+ return [2 /*return*/, this.getCurrentDelegateesForAddress(address.address)];
935
+ }
936
+ });
937
+ });
938
+ };
939
+ TezosProtocol.prototype.getCurrentDelegateesForAddress = function (address) {
940
+ return __awaiter(this, void 0, void 0, function () {
941
+ var data;
942
+ return __generator(this, function (_a) {
943
+ switch (_a.label) {
944
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address)];
945
+ case 1:
946
+ data = (_a.sent()).data;
947
+ return [2 /*return*/, data.delegate ? [data.delegate] : []];
948
+ }
949
+ });
950
+ });
951
+ };
952
+ TezosProtocol.prototype.getDelegateeDetails = function (address) {
953
+ return __awaiter(this, void 0, void 0, function () {
954
+ var response, isBakingActive;
955
+ return __generator(this, function (_a) {
956
+ switch (_a.label) {
957
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/delegates/" + address + "/deactivated")];
958
+ case 1:
959
+ response = _a.sent();
960
+ isBakingActive = !response.data;
961
+ return [2 /*return*/, {
962
+ status: isBakingActive ? 'Active' : 'Inactive',
963
+ address: address
964
+ }];
965
+ }
966
+ });
967
+ });
968
+ };
969
+ TezosProtocol.prototype.isPublicKeyDelegating = function (publicKey) {
970
+ return __awaiter(this, void 0, void 0, function () {
971
+ var address;
972
+ return __generator(this, function (_a) {
973
+ switch (_a.label) {
974
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
975
+ case 1:
976
+ address = _a.sent();
977
+ return [2 /*return*/, this.isAddressDelegating(address.address)];
978
+ }
979
+ });
980
+ });
981
+ };
982
+ TezosProtocol.prototype.isAddressDelegating = function (address) {
983
+ return __awaiter(this, void 0, void 0, function () {
984
+ var data;
985
+ return __generator(this, function (_a) {
986
+ switch (_a.label) {
987
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address)];
988
+ case 1:
989
+ data = (_a.sent()).data;
990
+ return [2 /*return*/, !!data.delegate];
991
+ }
992
+ });
993
+ });
994
+ };
995
+ TezosProtocol.prototype.getDelegatorDetailsFromPublicKey = function (publicKey) {
996
+ return __awaiter(this, void 0, void 0, function () {
997
+ var address;
998
+ return __generator(this, function (_a) {
999
+ switch (_a.label) {
1000
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
1001
+ case 1:
1002
+ address = _a.sent();
1003
+ return [2 /*return*/, this.getDelegatorDetailsFromAddress(address.address)];
1004
+ }
1005
+ });
1006
+ });
1007
+ };
1008
+ TezosProtocol.prototype.getDelegatorDetailsFromAddress = function (address) {
1009
+ return __awaiter(this, void 0, void 0, function () {
1010
+ return __generator(this, function (_a) {
1011
+ return [2 /*return*/, this.getDelegatorDetails(address)];
1012
+ });
1013
+ });
1014
+ };
1015
+ TezosProtocol.prototype.getDelegationDetailsFromPublicKey = function (publicKey, delegatees) {
1016
+ return __awaiter(this, void 0, void 0, function () {
1017
+ var address;
1018
+ return __generator(this, function (_a) {
1019
+ switch (_a.label) {
1020
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
1021
+ case 1:
1022
+ address = _a.sent();
1023
+ return [2 /*return*/, this.getDelegationDetailsFromAddress(address.address, delegatees)];
1024
+ }
1025
+ });
1026
+ });
1027
+ };
1028
+ TezosProtocol.prototype.getDelegationDetailsFromAddress = function (address, delegatees) {
1029
+ return __awaiter(this, void 0, void 0, function () {
1030
+ var bakerAddress, results, delegatorDetails, bakerDetails;
1031
+ return __generator(this, function (_a) {
1032
+ switch (_a.label) {
1033
+ case 0:
1034
+ if (delegatees.length > 1) {
1035
+ return [2 /*return*/, Promise.reject('Multiple delegation is not supported.')];
1036
+ }
1037
+ bakerAddress = delegatees[0];
1038
+ return [4 /*yield*/, Promise.all([this.getDelegatorDetails(address, bakerAddress), this.getDelegateeDetails(bakerAddress)])];
1039
+ case 1:
1040
+ results = _a.sent();
1041
+ delegatorDetails = results[0];
1042
+ bakerDetails = results[1];
1043
+ return [2 /*return*/, {
1044
+ delegator: delegatorDetails,
1045
+ delegatees: [bakerDetails]
1046
+ }];
1047
+ }
1048
+ });
1049
+ });
1050
+ };
1051
+ TezosProtocol.prototype.getDelegatorDetails = function (address, bakerAddress) {
1052
+ return __awaiter(this, void 0, void 0, function () {
1053
+ var results, accountDetails, balance, isDelegating, availableActions;
1054
+ return __generator(this, function (_a) {
1055
+ switch (_a.label) {
1056
+ case 0: return [4 /*yield*/, Promise.all([
1057
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address)
1058
+ // this.getDelegationRewardsForAddress(address).catch(() => [] as DelegationRewardInfo[])
1059
+ ])];
1060
+ case 1:
1061
+ results = _a.sent();
1062
+ accountDetails = results[0].data;
1063
+ balance = accountDetails.balance;
1064
+ isDelegating = !!accountDetails.delegate;
1065
+ availableActions = [];
1066
+ if (!isDelegating) {
1067
+ availableActions.push({
1068
+ type: TezosDelegatorAction.DELEGATE,
1069
+ args: ['delegate']
1070
+ });
1071
+ }
1072
+ else if (!bakerAddress || accountDetails.delegate === bakerAddress) {
1073
+ availableActions.push({
1074
+ type: TezosDelegatorAction.UNDELEGATE
1075
+ });
1076
+ }
1077
+ else {
1078
+ availableActions.push({
1079
+ type: TezosDelegatorAction.CHANGE_BAKER,
1080
+ args: ['delegate']
1081
+ });
1082
+ }
1083
+ // const rewards = isDelegating
1084
+ // ? rewardInfo.map((reward) => ({
1085
+ // index: reward.cycle,
1086
+ // amount: reward.reward.toFixed(),
1087
+ // collected: reward.payout < new Date(),
1088
+ // timestamp: reward.payout.getTime()
1089
+ // }))
1090
+ // : []
1091
+ return [2 /*return*/, {
1092
+ address: address,
1093
+ balance: balance,
1094
+ delegatees: [accountDetails.delegate],
1095
+ availableActions: availableActions
1096
+ // rewards
1097
+ }];
1098
+ }
1099
+ });
1100
+ });
1101
+ };
1102
+ TezosProtocol.prototype.prepareDelegatorActionFromPublicKey = function (publicKey, type, data) {
1103
+ return __awaiter(this, void 0, void 0, function () {
1104
+ var _a;
1105
+ return __generator(this, function (_b) {
1106
+ switch (_b.label) {
1107
+ case 0:
1108
+ _a = type;
1109
+ switch (_a) {
1110
+ case TezosDelegatorAction.DELEGATE: return [3 /*break*/, 1];
1111
+ case TezosDelegatorAction.CHANGE_BAKER: return [3 /*break*/, 1];
1112
+ case TezosDelegatorAction.UNDELEGATE: return [3 /*break*/, 3];
1113
+ }
1114
+ return [3 /*break*/, 5];
1115
+ case 1:
1116
+ if (!data || !data.delegate) {
1117
+ return [2 /*return*/, Promise.reject("Invalid arguments passed for " + type + " action, delegate is missing.")];
1118
+ }
1119
+ return [4 /*yield*/, this.delegate(publicKey, data.delegate)];
1120
+ case 2: return [2 /*return*/, [_b.sent()]];
1121
+ case 3: return [4 /*yield*/, this.undelegate(publicKey)];
1122
+ case 4: return [2 /*return*/, [_b.sent()]];
1123
+ case 5: return [2 /*return*/, Promise.reject('Unsupported delegator action.')];
1124
+ }
1125
+ });
1126
+ });
1127
+ };
1128
+ TezosProtocol.prototype.prepareOperations = function (publicKey, operationRequests, overrideParameters) {
1129
+ if (overrideParameters === void 0) { overrideParameters = true; }
1130
+ return __awaiter(this, void 0, void 0, function () {
1131
+ var counter, branch, operations, address, results, accountManager, hasRevealInOperationRequests, _a, _b, operationPromises, _c, _d, _e, tezosWrappedOperation;
1132
+ var _this = this;
1133
+ return __generator(this, function (_f) {
1134
+ switch (_f.label) {
1135
+ case 0:
1136
+ counter = new bignumber_1.default(1);
1137
+ operations = [];
1138
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey).then(function (address) { return address.address; })];
1139
+ case 1:
1140
+ address = _f.sent();
1141
+ return [4 /*yield*/, Promise.all([
1142
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address + "/counter"),
1143
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head~2/hash"),
1144
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + address + "/manager_key")
1145
+ ]).catch(function (error) {
1146
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
1147
+ })];
1148
+ case 2:
1149
+ results = _f.sent();
1150
+ counter = new bignumber_1.default(results[0].data).plus(1);
1151
+ branch = results[1].data;
1152
+ accountManager = results[2].data;
1153
+ hasRevealInOperationRequests = operationRequests.some(function (request) { return request.kind === TezosOperationType_1.TezosOperationType.REVEAL; });
1154
+ if (!(!accountManager && !hasRevealInOperationRequests)) return [3 /*break*/, 4];
1155
+ _b = (_a = operations).push;
1156
+ return [4 /*yield*/, this.createRevealOperation(counter, publicKey, address)];
1157
+ case 3:
1158
+ _b.apply(_a, [_f.sent()]);
1159
+ counter = counter.plus(1);
1160
+ _f.label = 4;
1161
+ case 4:
1162
+ operationPromises = operationRequests.map(function (operationRequest, index) { return __awaiter(_this, void 0, void 0, function () {
1163
+ var recipient, receivingBalance, _a, defaultCounter, defaultFee, defaultGasLimit, defaultStorageLimit, revealOperation, delegationOperation, transactionOperation, originationOperation;
1164
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1165
+ return __generator(this, function (_y) {
1166
+ switch (_y.label) {
1167
+ case 0:
1168
+ // TODO: Handle activation burn
1169
+ if (!operationRequest.kind) {
1170
+ throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "kind" was not defined');
1171
+ }
1172
+ recipient = operationRequest.destination;
1173
+ if (!(recipient && recipient.toLowerCase().startsWith('tz'))) return [3 /*break*/, 2];
1174
+ _a = bignumber_1.default.bind;
1175
+ return [4 /*yield*/, this.getBalanceOfAddresses([recipient])];
1176
+ case 1:
1177
+ receivingBalance = new (_a.apply(bignumber_1.default, [void 0, _y.sent()]))();
1178
+ _y.label = 2;
1179
+ case 2:
1180
+ defaultCounter = counter.plus(index).toFixed() // TODO: Handle counter if we have some operations without counters in the array
1181
+ ;
1182
+ defaultFee = FEE_PLACEHOLDER;
1183
+ defaultGasLimit = '10300';
1184
+ defaultStorageLimit = receivingBalance && receivingBalance.isZero() && recipient && recipient.toLowerCase().startsWith('tz') ? '300' : '0' // taken from eztz
1185
+ ;
1186
+ switch (operationRequest.kind) {
1187
+ // TODO: Handle if the dApp already provides a reveal operation
1188
+ case TezosOperationType_1.TezosOperationType.REVEAL:
1189
+ revealOperation = operationRequest;
1190
+ if (!revealOperation.public_key) {
1191
+ throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "public_key" was not defined');
1192
+ }
1193
+ revealOperation.source = (_b = revealOperation.source) !== null && _b !== void 0 ? _b : address;
1194
+ revealOperation.counter = (_c = revealOperation.counter) !== null && _c !== void 0 ? _c : defaultCounter;
1195
+ revealOperation.fee = (_d = revealOperation.fee) !== null && _d !== void 0 ? _d : defaultFee;
1196
+ revealOperation.gas_limit = (_e = revealOperation.gas_limit) !== null && _e !== void 0 ? _e : defaultGasLimit;
1197
+ revealOperation.storage_limit = (_f = revealOperation.storage_limit) !== null && _f !== void 0 ? _f : defaultStorageLimit;
1198
+ return [2 /*return*/, revealOperation];
1199
+ case TezosOperationType_1.TezosOperationType.DELEGATION:
1200
+ delegationOperation = operationRequest;
1201
+ // The delegate property is optional, so we don't have any mandatory properties to check for
1202
+ delegationOperation.source = (_g = delegationOperation.source) !== null && _g !== void 0 ? _g : address;
1203
+ delegationOperation.counter = (_h = delegationOperation.counter) !== null && _h !== void 0 ? _h : defaultCounter;
1204
+ delegationOperation.fee = (_j = delegationOperation.fee) !== null && _j !== void 0 ? _j : defaultFee;
1205
+ delegationOperation.gas_limit = (_k = delegationOperation.gas_limit) !== null && _k !== void 0 ? _k : defaultGasLimit;
1206
+ delegationOperation.storage_limit = (_l = delegationOperation.storage_limit) !== null && _l !== void 0 ? _l : defaultStorageLimit;
1207
+ return [2 /*return*/, delegationOperation];
1208
+ case TezosOperationType_1.TezosOperationType.TRANSACTION:
1209
+ transactionOperation = operationRequest;
1210
+ if (!transactionOperation.amount) {
1211
+ throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "amount" was not defined');
1212
+ }
1213
+ if (!transactionOperation.destination) {
1214
+ throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "destination" was not defined');
1215
+ }
1216
+ transactionOperation.source = (_m = transactionOperation.source) !== null && _m !== void 0 ? _m : address;
1217
+ transactionOperation.counter = (_o = transactionOperation.counter) !== null && _o !== void 0 ? _o : defaultCounter;
1218
+ transactionOperation.fee = (_p = transactionOperation.fee) !== null && _p !== void 0 ? _p : defaultFee;
1219
+ transactionOperation.gas_limit = (_q = transactionOperation.gas_limit) !== null && _q !== void 0 ? _q : GAS_LIMIT_PLACEHOLDER;
1220
+ transactionOperation.storage_limit = (_r = transactionOperation.storage_limit) !== null && _r !== void 0 ? _r : STORAGE_LIMIT_PLACEHOLDER;
1221
+ return [2 /*return*/, transactionOperation];
1222
+ case TezosOperationType_1.TezosOperationType.ORIGINATION:
1223
+ originationOperation = operationRequest;
1224
+ if (!originationOperation.balance) {
1225
+ throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "balance" was not defined');
1226
+ }
1227
+ if (!originationOperation.script) {
1228
+ throw new index_4.PropertyUndefinedError(coinlib_error_1.Domain.TEZOS, 'property "script" was not defined');
1229
+ }
1230
+ originationOperation.source = (_s = originationOperation.source) !== null && _s !== void 0 ? _s : address;
1231
+ originationOperation.counter = (_t = originationOperation.counter) !== null && _t !== void 0 ? _t : defaultCounter;
1232
+ originationOperation.fee = (_u = originationOperation.fee) !== null && _u !== void 0 ? _u : defaultFee;
1233
+ originationOperation.gas_limit = (_v = originationOperation.gas_limit) !== null && _v !== void 0 ? _v : GAS_LIMIT_PLACEHOLDER;
1234
+ originationOperation.storage_limit = (_w = originationOperation.storage_limit) !== null && _w !== void 0 ? _w : STORAGE_LIMIT_PLACEHOLDER;
1235
+ return [2 /*return*/, originationOperation];
1236
+ case TezosOperationType_1.TezosOperationType.ENDORSEMENT:
1237
+ case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION:
1238
+ case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE:
1239
+ case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE:
1240
+ case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT:
1241
+ case TezosOperationType_1.TezosOperationType.PROPOSALS:
1242
+ case TezosOperationType_1.TezosOperationType.BALLOT:
1243
+ // Do not change anything
1244
+ return [2 /*return*/, operationRequest];
1245
+ default:
1246
+ assert_1.assertNever(operationRequest.kind);
1247
+ throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, "unsupported operation type \"" + JSON.stringify(operationRequest.kind) + "\"");
1248
+ }
1249
+ return [2 /*return*/];
1250
+ }
1251
+ });
1252
+ }); });
1253
+ _d = (_c = operations.push).apply;
1254
+ _e = [operations];
1255
+ return [4 /*yield*/, Promise.all(operationPromises)];
1256
+ case 5:
1257
+ _d.apply(_c, _e.concat([(_f.sent())]));
1258
+ tezosWrappedOperation = {
1259
+ branch: branch,
1260
+ contents: operations
1261
+ };
1262
+ return [4 /*yield*/, this.estimateAndReplaceLimitsAndFee(tezosWrappedOperation, overrideParameters)];
1263
+ case 6: return [2 /*return*/, _f.sent()];
1264
+ }
1265
+ });
1266
+ });
1267
+ };
1268
+ TezosProtocol.prototype.estimateAndReplaceLimitsAndFee = function (tezosWrappedOperation, overrideParameters, startingCounter) {
1269
+ if (overrideParameters === void 0) { overrideParameters = true; }
1270
+ return __awaiter(this, void 0, void 0, function () {
1271
+ var fakeSignature, opKinds, contents, block, body, forgedOperation, gasLimitTotal, response, fee, nonRevealOperations, feePerOperation_1;
1272
+ return __generator(this, function (_a) {
1273
+ switch (_a.label) {
1274
+ case 0:
1275
+ fakeSignature = 'sigUHx32f9wesZ1n2BWpixXz4AQaZggEtchaQNHYGRCoWNAXx45WGW2ua3apUUUAGMLPwAU41QoaFCzVSL61VaessLg4YbbP';
1276
+ opKinds = [
1277
+ TezosOperationType_1.TezosOperationType.TRANSACTION,
1278
+ TezosOperationType_1.TezosOperationType.REVEAL,
1279
+ TezosOperationType_1.TezosOperationType.ORIGINATION,
1280
+ TezosOperationType_1.TezosOperationType.DELEGATION
1281
+ ];
1282
+ contents = tezosWrappedOperation.contents.map(function (operation, i) {
1283
+ if (!opKinds.includes(operation.kind)) {
1284
+ return operation;
1285
+ }
1286
+ var op = operation;
1287
+ var gasValue = new bignumber_1.default(MAX_GAS_PER_BLOCK).dividedToIntegerBy(tezosWrappedOperation.contents.length);
1288
+ var gas_limit = new bignumber_1.default(GAS_LIMIT_PLACEHOLDER).gt(gasValue) ? gasValue : GAS_LIMIT_PLACEHOLDER;
1289
+ var counter = startingCounter ? startingCounter.plus(i).toString() : op.counter;
1290
+ return __assign(__assign({}, operation), { gas_limit: gas_limit, counter: counter });
1291
+ });
1292
+ return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head")];
1293
+ case 1:
1294
+ block = (_a.sent()).data;
1295
+ body = {
1296
+ chain_id: block.chain_id,
1297
+ operation: {
1298
+ branch: tezosWrappedOperation.branch,
1299
+ contents: contents,
1300
+ signature: fakeSignature // signature will not be checked, so it is ok to always use this one
1301
+ }
1302
+ };
1303
+ return [4 /*yield*/, this.forgeTezosOperation(tezosWrappedOperation)];
1304
+ case 2:
1305
+ forgedOperation = _a.sent();
1306
+ gasLimitTotal = 0;
1307
+ return [4 /*yield*/, index_1.default
1308
+ .post(this.options.network.rpcUrl + "/chains/main/blocks/head/helpers/scripts/run_operation", body, {
1309
+ headers: { 'Content-Type': 'application/json' }
1310
+ })
1311
+ .catch(function (runOperationError) {
1312
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, runOperationError);
1313
+ })];
1314
+ case 3:
1315
+ response = _a.sent();
1316
+ if (tezosWrappedOperation.contents.length !== response.data.contents.length) {
1317
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, "Run Operation did not return same number of operations. Locally we have " + tezosWrappedOperation.contents.length + ", but got back " + response.data.contents.length);
1318
+ }
1319
+ tezosWrappedOperation.contents.forEach(function (content, i) {
1320
+ var metadata = response.data.contents[i].metadata;
1321
+ if (metadata.operation_result) {
1322
+ var operation = content;
1323
+ var result = metadata.operation_result;
1324
+ var gasLimit_1 = 0;
1325
+ var storageLimit_1 = 0;
1326
+ // If there are internal operations, we first add gas and storage used of internal operations
1327
+ if (metadata.internal_operation_results) {
1328
+ metadata.internal_operation_results.forEach(function (internalOperation) {
1329
+ if (internalOperation === null || internalOperation === void 0 ? void 0 : internalOperation.result) {
1330
+ if (internalOperation.result.errors) {
1331
+ throw new index_4.TransactionError(coinlib_error_1.Domain.TEZOS, 'An internal operation produced an error', internalOperation.result.errors);
1332
+ }
1333
+ gasLimit_1 += Math.ceil(Number(internalOperation.result.consumed_milligas) / 1000);
1334
+ if (internalOperation.result.paid_storage_size_diff) {
1335
+ storageLimit_1 += Number(internalOperation.result.paid_storage_size_diff);
1336
+ }
1337
+ if (internalOperation.result.originated_contracts) {
1338
+ storageLimit_1 += internalOperation.result.originated_contracts.length * 257;
1339
+ }
1340
+ if (internalOperation.result.allocated_destination_contract) {
1341
+ storageLimit_1 += 257;
1342
+ }
1343
+ }
1344
+ });
1345
+ }
1346
+ if (result.errors) {
1347
+ throw new index_4.TransactionError(coinlib_error_1.Domain.TEZOS, 'The operation produced an error', result.errors);
1348
+ }
1349
+ // Add gas and storage used by operation
1350
+ gasLimit_1 += Math.ceil(Number(result.consumed_milligas) / 1000);
1351
+ if (result.paid_storage_size_diff) {
1352
+ storageLimit_1 += Number(result.paid_storage_size_diff);
1353
+ }
1354
+ if (result.originated_contracts) {
1355
+ storageLimit_1 += result.originated_contracts.length * 257;
1356
+ }
1357
+ if (result.allocated_destination_contract) {
1358
+ storageLimit_1 += 257;
1359
+ }
1360
+ // in prepareTransactionsFromPublicKey() we invoke this method with overrideParameters = false
1361
+ if ((operation.gas_limit && overrideParameters) || operation.gas_limit === GAS_LIMIT_PLACEHOLDER) {
1362
+ ;
1363
+ operation.gas_limit = gasLimit_1.toString();
1364
+ }
1365
+ if ((operation.storage_limit && overrideParameters) || operation.storage_limit === STORAGE_LIMIT_PLACEHOLDER) {
1366
+ ;
1367
+ operation.storage_limit = storageLimit_1.toString();
1368
+ }
1369
+ gasLimitTotal += gasLimit_1;
1370
+ }
1371
+ });
1372
+ if (overrideParameters || tezosWrappedOperation.contents.some(function (operation) { var _a; return ((_a = operation) === null || _a === void 0 ? void 0 : _a.fee) === FEE_PLACEHOLDER; })) {
1373
+ fee = MINIMAL_FEE +
1374
+ MINIMAL_FEE_PER_BYTE * Math.ceil((forgedOperation.length + 128) / 2) + // 128 is the length of a hex signature
1375
+ MINIMAL_FEE_PER_GAS_UNIT * gasLimitTotal +
1376
+ 100 // add 100 for safety
1377
+ ;
1378
+ nonRevealOperations = tezosWrappedOperation.contents.filter(function (operation) { return operation.kind !== 'reveal'; });
1379
+ feePerOperation_1 = Math.ceil(fee / nonRevealOperations.length);
1380
+ tezosWrappedOperation.contents.forEach(function (operation) {
1381
+ if (operation.fee && operation.kind !== 'reveal') {
1382
+ ;
1383
+ operation.fee = feePerOperation_1.toString();
1384
+ }
1385
+ });
1386
+ }
1387
+ return [2 /*return*/, tezosWrappedOperation];
1388
+ }
1389
+ });
1390
+ });
1391
+ };
1392
+ TezosProtocol.prototype.getDelegationInfo = function (delegatedAddress, fetchExtraInfo) {
1393
+ if (fetchExtraInfo === void 0) { fetchExtraInfo = true; }
1394
+ return __awaiter(this, void 0, void 0, function () {
1395
+ var data, delegatedOpLevel, delegatedDate, recentTransactionData;
1396
+ return __generator(this, function (_a) {
1397
+ switch (_a.label) {
1398
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + delegatedAddress)];
1399
+ case 1:
1400
+ data = (_a.sent()).data;
1401
+ if (!(data.delegate && fetchExtraInfo)) return [3 /*break*/, 3];
1402
+ return [4 /*yield*/, this.options.network.extras.indexerClient.getDelegationInfo(delegatedAddress)];
1403
+ case 2:
1404
+ recentTransactionData = _a.sent();
1405
+ if (recentTransactionData) {
1406
+ delegatedDate = recentTransactionData.date;
1407
+ delegatedOpLevel = recentTransactionData.level;
1408
+ }
1409
+ _a.label = 3;
1410
+ case 3: return [2 /*return*/, {
1411
+ isDelegated: data.delegate ? true : false,
1412
+ value: data.delegate,
1413
+ delegatedDate: delegatedDate,
1414
+ delegatedOpLevel: delegatedOpLevel
1415
+ }];
1416
+ }
1417
+ });
1418
+ });
1419
+ };
1420
+ TezosProtocol.prototype.bakerInfo = function (tzAddress) {
1421
+ var _a, _b, _c, _d;
1422
+ return __awaiter(this, void 0, void 0, function () {
1423
+ var results, tzBalance, delegatedBalance, stakingBalance, selfBond, stakingCapacity, bakerInfo;
1424
+ return __generator(this, function (_e) {
1425
+ switch (_e.label) {
1426
+ case 0:
1427
+ if (!tzAddress ||
1428
+ !(tzAddress.toLowerCase().startsWith('tz1') || tzAddress.toLowerCase().startsWith('tz2') || tzAddress.toLowerCase().startsWith('tz3'))) {
1429
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'non tz-address supplied');
1430
+ }
1431
+ return [4 /*yield*/, Promise.all([
1432
+ index_1.default
1433
+ .get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/delegates/" + tzAddress + "/balance")
1434
+ .catch(function (_error) { return undefined; }),
1435
+ index_1.default
1436
+ .get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/delegates/" + tzAddress + "/full_balance")
1437
+ .catch(function (_error) { return undefined; }),
1438
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/delegates/" + tzAddress + "/delegated_balance"),
1439
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/delegates/" + tzAddress + "/staking_balance")
1440
+ ]).catch(function (error) {
1441
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
1442
+ })];
1443
+ case 1:
1444
+ results = _e.sent();
1445
+ tzBalance = new bignumber_1.default((_b = ((_a = results[0]) !== null && _a !== void 0 ? _a : results[1])) === null || _b === void 0 ? void 0 : _b.data);
1446
+ delegatedBalance = new bignumber_1.default((_c = results[2]) === null || _c === void 0 ? void 0 : _c.data);
1447
+ stakingBalance = new bignumber_1.default((_d = results[3]) === null || _d === void 0 ? void 0 : _d.data);
1448
+ selfBond = stakingBalance.minus(delegatedBalance);
1449
+ stakingCapacity = stakingBalance.div(selfBond.div(SELF_BOND_REQUIREMENT));
1450
+ bakerInfo = {
1451
+ balance: tzBalance,
1452
+ delegatedBalance: delegatedBalance,
1453
+ stakingBalance: stakingBalance,
1454
+ selfBond: selfBond,
1455
+ bakerCapacity: stakingBalance.div(stakingCapacity),
1456
+ bakerUsage: stakingCapacity
1457
+ };
1458
+ return [2 /*return*/, bakerInfo];
1459
+ }
1460
+ });
1461
+ });
1462
+ };
1463
+ TezosProtocol.prototype.getDelegationRewardsForAddress = function (address) {
1464
+ return __awaiter(this, void 0, void 0, function () {
1465
+ var status;
1466
+ return __generator(this, function (_a) {
1467
+ switch (_a.label) {
1468
+ case 0: return [4 /*yield*/, this.getDelegationInfo(address)];
1469
+ case 1:
1470
+ status = _a.sent();
1471
+ if (!status.isDelegated || !status.value) {
1472
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'address not delegated');
1473
+ }
1474
+ return [2 /*return*/, this.getDelegationRewards(status.value, address)];
1475
+ }
1476
+ });
1477
+ });
1478
+ };
1479
+ TezosProtocol.prototype.getDelegationRewards = function (bakerAddress, delegatorAddress) {
1480
+ return __awaiter(this, void 0, void 0, function () {
1481
+ return __generator(this, function (_a) {
1482
+ // TODO: use the adapt logic for ithaca upgrade
1483
+ return [2 /*return*/, []
1484
+ // const { data: frozenBalance }: AxiosResponse<TezosFrozenBalance[]> = await axios.get(
1485
+ // `${this.options.network.rpcUrl}/chains/main/blocks/head/context/delegates/${bakerAddress}/frozen_balance_by_cycle`
1486
+ // )
1487
+ // const lastConfirmedCycle: number = frozenBalance[0].cycle - 1
1488
+ // const mostRecentCycle: number = frozenBalance[frozenBalance.length - 1].cycle
1489
+ // const { data: mostRecentBlock } = await axios.get(
1490
+ // `${this.options.network.rpcUrl}/chains/main/blocks/${this.cycleToBlockLevel(mostRecentCycle)}`
1491
+ // )
1492
+ // const timestamp: Date = new Date(mostRecentBlock.header.timestamp)
1493
+ // const address = delegatorAddress ?? bakerAddress
1494
+ // const delegationInfo: DelegationRewardInfo[] = await Promise.all(
1495
+ // frozenBalance.slice(0, 5).map(async (obj) => {
1496
+ // const rewards = await this.calculateRewards(bakerAddress, obj.cycle, mostRecentCycle, false)
1497
+ // let delegatedBalance = '0'
1498
+ // let payoutAmount = '0'
1499
+ // if (rewards.delegatedContracts.includes(address)) {
1500
+ // const payout = await this.calculatePayout(address, rewards)
1501
+ // delegatedBalance = payout.balance
1502
+ // payoutAmount = payout.payout
1503
+ // }
1504
+ // return {
1505
+ // cycle: obj.cycle,
1506
+ // totalRewards: new BigNumber(obj.rewards),
1507
+ // totalFees: new BigNumber(obj.fees),
1508
+ // deposit: new BigNumber(obj.deposit ?? obj.deposits),
1509
+ // delegatedBalance: new BigNumber(delegatedBalance),
1510
+ // stakingBalance: new BigNumber(rewards.stakingBalance),
1511
+ // reward: new BigNumber(payoutAmount),
1512
+ // payout: new Date(timestamp.getTime() + this.timeIntervalBetweenCycles(lastConfirmedCycle, obj.cycle))
1513
+ // }
1514
+ // })
1515
+ // )
1516
+ // return delegationInfo
1517
+ ];
1518
+ });
1519
+ });
1520
+ };
1521
+ TezosProtocol.prototype.undelegate = function (publicKey) {
1522
+ return __awaiter(this, void 0, void 0, function () {
1523
+ return __generator(this, function (_a) {
1524
+ return [2 /*return*/, this.delegate(publicKey)];
1525
+ });
1526
+ });
1527
+ };
1528
+ TezosProtocol.prototype.delegate = function (publicKey, delegate) {
1529
+ return __awaiter(this, void 0, void 0, function () {
1530
+ var counter, branch, operations, tzAddress, results, accountManager, _a, _b, balance, _c, fee, delegationOperation, tezosWrappedOperation, binaryTx, error_4;
1531
+ return __generator(this, function (_d) {
1532
+ switch (_d.label) {
1533
+ case 0:
1534
+ counter = new bignumber_1.default(1);
1535
+ branch = '';
1536
+ operations = [];
1537
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey).then(function (address) { return address.address; })];
1538
+ case 1:
1539
+ tzAddress = _d.sent();
1540
+ return [4 /*yield*/, Promise.all([
1541
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + tzAddress + "/counter"),
1542
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head~2/hash"),
1543
+ index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/head/context/contracts/" + tzAddress + "/manager_key")
1544
+ ]).catch(function (error) {
1545
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
1546
+ })];
1547
+ case 2:
1548
+ results = _d.sent();
1549
+ counter = new bignumber_1.default(results[0].data).plus(1);
1550
+ branch = results[1].data;
1551
+ accountManager = results[2].data;
1552
+ if (!!accountManager) return [3 /*break*/, 4];
1553
+ _b = (_a = operations).push;
1554
+ return [4 /*yield*/, this.createRevealOperation(counter, publicKey, tzAddress)];
1555
+ case 3:
1556
+ _b.apply(_a, [_d.sent()]);
1557
+ counter = counter.plus(1);
1558
+ _d.label = 4;
1559
+ case 4:
1560
+ _c = bignumber_1.default.bind;
1561
+ return [4 /*yield*/, this.getBalanceOfAddresses([tzAddress])];
1562
+ case 5:
1563
+ balance = new (_c.apply(bignumber_1.default, [void 0, _d.sent()]))();
1564
+ fee = new bignumber_1.default(1420);
1565
+ if (balance.isLessThan(fee)) {
1566
+ throw new index_4.BalanceError(coinlib_error_1.Domain.TEZOS, 'not enough balance');
1567
+ }
1568
+ delegationOperation = {
1569
+ kind: TezosOperationType_1.TezosOperationType.DELEGATION,
1570
+ source: tzAddress,
1571
+ fee: fee.toFixed(),
1572
+ counter: counter.toFixed(),
1573
+ gas_limit: '10000',
1574
+ storage_limit: '0',
1575
+ delegate: Array.isArray(delegate) ? delegate[0] : delegate
1576
+ };
1577
+ operations.push(delegationOperation);
1578
+ _d.label = 6;
1579
+ case 6:
1580
+ _d.trys.push([6, 8, , 9]);
1581
+ tezosWrappedOperation = {
1582
+ branch: branch,
1583
+ contents: operations
1584
+ };
1585
+ return [4 /*yield*/, this.forgeTezosOperation(tezosWrappedOperation)];
1586
+ case 7:
1587
+ binaryTx = _d.sent();
1588
+ return [2 /*return*/, { binaryTransaction: binaryTx }];
1589
+ case 8:
1590
+ error_4 = _d.sent();
1591
+ throw new index_4.OperationFailedError(coinlib_error_1.Domain.TEZOS, "Forging Tezos TX failed with " + JSON.stringify(error_4.message));
1592
+ case 9: return [2 /*return*/];
1593
+ }
1594
+ });
1595
+ });
1596
+ };
1597
+ TezosProtocol.prototype.getAmountUsedByPreviousOperations = function (operations) {
1598
+ var amountUsed = new bignumber_1.default(0);
1599
+ operations.forEach(function (operation) {
1600
+ switch (operation.kind) {
1601
+ case TezosOperationType_1.TezosOperationType.REVEAL:
1602
+ var revealOperation = operation;
1603
+ amountUsed = amountUsed.plus(revealOperation.fee);
1604
+ break;
1605
+ case TezosOperationType_1.TezosOperationType.ORIGINATION:
1606
+ var originationOperation = operation;
1607
+ amountUsed = amountUsed.plus(originationOperation.fee);
1608
+ amountUsed = amountUsed.plus(originationOperation.balance);
1609
+ break;
1610
+ case TezosOperationType_1.TezosOperationType.DELEGATION:
1611
+ var delegationOperation = operation;
1612
+ amountUsed = amountUsed.plus(delegationOperation.fee);
1613
+ break;
1614
+ case TezosOperationType_1.TezosOperationType.TRANSACTION:
1615
+ var spendOperation = operation;
1616
+ amountUsed = amountUsed.plus(spendOperation.fee);
1617
+ amountUsed = amountUsed.plus(spendOperation.amount);
1618
+ break;
1619
+ case TezosOperationType_1.TezosOperationType.ENDORSEMENT:
1620
+ case TezosOperationType_1.TezosOperationType.SEED_NONCE_REVELATION:
1621
+ case TezosOperationType_1.TezosOperationType.DOUBLE_ENDORSEMENT_EVIDENCE:
1622
+ case TezosOperationType_1.TezosOperationType.DOUBLE_BAKING_EVIDENCE:
1623
+ case TezosOperationType_1.TezosOperationType.ACTIVATE_ACCOUNT:
1624
+ case TezosOperationType_1.TezosOperationType.PROPOSALS:
1625
+ case TezosOperationType_1.TezosOperationType.BALLOT:
1626
+ break;
1627
+ default:
1628
+ // Exhaustive switch
1629
+ assert_1.assertNever(operation.kind);
1630
+ throw new index_4.UnsupportedError(coinlib_error_1.Domain.TEZOS, "operation type not supported " + JSON.stringify(operation.kind));
1631
+ }
1632
+ });
1633
+ return amountUsed;
1634
+ };
1635
+ TezosProtocol.prototype.broadcastTransaction = function (rawTransaction) {
1636
+ return __awaiter(this, void 0, void 0, function () {
1637
+ var payload, injectionResponse;
1638
+ return __generator(this, function (_a) {
1639
+ switch (_a.label) {
1640
+ case 0:
1641
+ payload = rawTransaction;
1642
+ return [4 /*yield*/, index_1.default
1643
+ .post(this.options.network.rpcUrl + "/injection/operation?chain=main", JSON.stringify(payload), {
1644
+ headers: { 'content-type': 'application/json' }
1645
+ })
1646
+ .catch(function (error) {
1647
+ throw new index_4.NetworkError(coinlib_error_1.Domain.TEZOS, error);
1648
+ })
1649
+ // returns hash if successful
1650
+ ];
1651
+ case 1:
1652
+ injectionResponse = (_a.sent()).data;
1653
+ // returns hash if successful
1654
+ return [2 /*return*/, injectionResponse];
1655
+ }
1656
+ });
1657
+ });
1658
+ };
1659
+ TezosProtocol.prototype.checkAndRemovePrefixToHex = function (base58CheckEncodedPayload, tezosPrefix) {
1660
+ var prefixHex = Buffer.from(tezosPrefix).toString('hex');
1661
+ var payload = bs58check.decode(base58CheckEncodedPayload).toString('hex');
1662
+ if (payload.startsWith(prefixHex)) {
1663
+ return payload.substring(tezosPrefix.length * 2);
1664
+ }
1665
+ else {
1666
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, "payload did not match prefix: " + prefixHex);
1667
+ }
1668
+ };
1669
+ TezosProtocol.prototype.unforgeSignedTezosWrappedOperation = function (hexString) {
1670
+ return __awaiter(this, void 0, void 0, function () {
1671
+ return __generator(this, function (_a) {
1672
+ if (hexString.length <= 128) {
1673
+ throw new index_4.ConditionViolationError(coinlib_error_1.Domain.TEZOS, 'Not a valid signed transaction');
1674
+ }
1675
+ return [2 /*return*/, this.unforgeUnsignedTezosWrappedOperation(hexString.substring(0, hexString.length - 128))];
1676
+ });
1677
+ });
1678
+ };
1679
+ TezosProtocol.prototype.unforgeUnsignedTezosWrappedOperation = function (hexString) {
1680
+ return __awaiter(this, void 0, void 0, function () {
1681
+ return __generator(this, function (_a) {
1682
+ return [2 /*return*/, taquito_local_forging_1.localForger.parse(hexString)];
1683
+ });
1684
+ });
1685
+ };
1686
+ TezosProtocol.prototype.forgeTezosOperation = function (tezosWrappedOperation) {
1687
+ return __awaiter(this, void 0, void 0, function () {
1688
+ return __generator(this, function (_a) {
1689
+ return [2 /*return*/, taquito_local_forging_1.localForger.forge(tezosWrappedOperation)];
1690
+ });
1691
+ });
1692
+ };
1693
+ TezosProtocol.prototype.createRevealOperation = function (counter, publicKey, address, fee) {
1694
+ if (fee === void 0) { fee = this.revealFee.toFixed(); }
1695
+ return __awaiter(this, void 0, void 0, function () {
1696
+ var operation;
1697
+ return __generator(this, function (_a) {
1698
+ operation = {
1699
+ kind: TezosOperationType_1.TezosOperationType.REVEAL,
1700
+ fee: fee,
1701
+ gas_limit: '10000',
1702
+ storage_limit: '0',
1703
+ counter: counter.toFixed(),
1704
+ public_key: bs58check.encode(Buffer.concat([TezosUtils_1.TezosUtils.tezosPrefixes.edpk, Buffer.from(publicKey, 'hex')])),
1705
+ source: address
1706
+ };
1707
+ return [2 /*return*/, operation];
1708
+ });
1709
+ });
1710
+ };
1711
+ TezosProtocol.prototype.getTezosVotingInfo = function (blockHash) {
1712
+ return __awaiter(this, void 0, void 0, function () {
1713
+ var response;
1714
+ return __generator(this, function (_a) {
1715
+ switch (_a.label) {
1716
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/" + blockHash + "/votes/listings")];
1717
+ case 1:
1718
+ response = _a.sent();
1719
+ return [2 /*return*/, response.data];
1720
+ }
1721
+ });
1722
+ });
1723
+ };
1724
+ TezosProtocol.prototype.fetchCurrentCycle = function () {
1725
+ return __awaiter(this, void 0, void 0, function () {
1726
+ var headMetadata, currentCycle;
1727
+ return __generator(this, function (_a) {
1728
+ switch (_a.label) {
1729
+ case 0: return [4 /*yield*/, this.fetchBlockMetadata('head')];
1730
+ case 1:
1731
+ headMetadata = _a.sent();
1732
+ currentCycle = headMetadata.level_info.cycle;
1733
+ return [2 /*return*/, currentCycle];
1734
+ }
1735
+ });
1736
+ });
1737
+ };
1738
+ TezosProtocol.prototype.timeIntervalBetweenCycles = function (fromCycle, toCycle) {
1739
+ var cycle1 = Math.min(fromCycle, toCycle);
1740
+ var cycle2 = Math.max(fromCycle, toCycle);
1741
+ var timeBetweenBlocks = TezosProtocol.TIME_BETWEEN_BLOCKS[this.options.network.extras.network];
1742
+ var blocksPerCycle = TezosProtocol.BLOCKS_PER_CYCLE[this.options.network.extras.network];
1743
+ if (this.options.network.extras.network === TezosNetwork.MAINNET && cycle2 > TezosProtocol.FIRST_010_CYCLE) {
1744
+ if (cycle1 < TezosProtocol.FIRST_010_CYCLE) {
1745
+ return (((TezosProtocol.FIRST_010_CYCLE - cycle1) * blocksPerCycle[0] * timeBetweenBlocks[0] +
1746
+ (cycle2 - TezosProtocol.FIRST_010_CYCLE) * blocksPerCycle[1] * timeBetweenBlocks[1]) *
1747
+ 1000);
1748
+ }
1749
+ return (cycle2 - cycle1) * blocksPerCycle[1] * timeBetweenBlocks[1] * 1000;
1750
+ }
1751
+ return (cycle2 - cycle1) * blocksPerCycle[0] * timeBetweenBlocks[0] * 1000;
1752
+ };
1753
+ TezosProtocol.prototype.cycleToBlockLevel = function (cycle) {
1754
+ var blocksPerCycle = TezosProtocol.BLOCKS_PER_CYCLE[this.options.network.extras.network];
1755
+ if (this.options.network.extras.network === TezosNetwork.MAINNET && cycle > TezosProtocol.FIRST_010_CYCLE) {
1756
+ return TezosProtocol.FIRST_010_CYCLE * blocksPerCycle[0] + (cycle - TezosProtocol.FIRST_010_CYCLE) * blocksPerCycle[1] + 1;
1757
+ }
1758
+ return cycle * blocksPerCycle[0] + 1;
1759
+ };
1760
+ TezosProtocol.prototype.blockLevelToCycle = function (blockLevel) {
1761
+ var blocksPerCycle = TezosProtocol.BLOCKS_PER_CYCLE[this.options.network.extras.network];
1762
+ if (this.options.network.extras.network === TezosNetwork.MAINNET) {
1763
+ var last009BlockLevel = TezosProtocol.FIRST_010_CYCLE * blocksPerCycle[0];
1764
+ if (blockLevel > last009BlockLevel) {
1765
+ var deltaLevels = blockLevel - last009BlockLevel;
1766
+ var deltaCycles = Math.floor(deltaLevels / blocksPerCycle[1]);
1767
+ if (deltaLevels % blocksPerCycle[1] === 0) {
1768
+ deltaCycles -= 1;
1769
+ }
1770
+ return TezosProtocol.FIRST_010_CYCLE + deltaCycles;
1771
+ }
1772
+ }
1773
+ var cycle = Math.floor(blockLevel / blocksPerCycle[0]);
1774
+ if (blockLevel % blocksPerCycle[0] === 0) {
1775
+ cycle -= 1;
1776
+ }
1777
+ return cycle;
1778
+ };
1779
+ TezosProtocol.prototype.fetchBlockMetadata = function (block) {
1780
+ return __awaiter(this, void 0, void 0, function () {
1781
+ var result;
1782
+ return __generator(this, function (_a) {
1783
+ switch (_a.label) {
1784
+ case 0: return [4 /*yield*/, index_1.default.get(this.options.network.rpcUrl + "/chains/main/blocks/" + block + "/metadata")];
1785
+ case 1:
1786
+ result = _a.sent();
1787
+ return [2 /*return*/, result.data];
1788
+ }
1789
+ });
1790
+ });
1791
+ };
1792
+ TezosProtocol.prototype.signMessage = function (message, keypair) {
1793
+ return __awaiter(this, void 0, void 0, function () {
1794
+ return __generator(this, function (_a) {
1795
+ return [2 /*return*/, this.cryptoClient.signMessage(message, keypair)];
1796
+ });
1797
+ });
1798
+ };
1799
+ TezosProtocol.prototype.verifyMessage = function (message, signature, publicKey) {
1800
+ return __awaiter(this, void 0, void 0, function () {
1801
+ return __generator(this, function (_a) {
1802
+ return [2 /*return*/, this.cryptoClient.verifyMessage(message, signature, publicKey)];
1803
+ });
1804
+ });
1805
+ };
1806
+ TezosProtocol.prototype.encryptAsymmetric = function (message, publicKey) {
1807
+ return __awaiter(this, void 0, void 0, function () {
1808
+ return __generator(this, function (_a) {
1809
+ return [2 /*return*/, this.cryptoClient.encryptAsymmetric(message, publicKey)];
1810
+ });
1811
+ });
1812
+ };
1813
+ TezosProtocol.prototype.decryptAsymmetric = function (message, keypair) {
1814
+ return __awaiter(this, void 0, void 0, function () {
1815
+ return __generator(this, function (_a) {
1816
+ return [2 /*return*/, this.cryptoClient.decryptAsymmetric(message, keypair)];
1817
+ });
1818
+ });
1819
+ };
1820
+ TezosProtocol.prototype.encryptAES = function (message, privateKey) {
1821
+ return __awaiter(this, void 0, void 0, function () {
1822
+ return __generator(this, function (_a) {
1823
+ return [2 /*return*/, this.cryptoClient.encryptAES(message, privateKey)];
1824
+ });
1825
+ });
1826
+ };
1827
+ TezosProtocol.prototype.decryptAES = function (message, privateKey) {
1828
+ return __awaiter(this, void 0, void 0, function () {
1829
+ return __generator(this, function (_a) {
1830
+ return [2 /*return*/, this.cryptoClient.decryptAES(message, privateKey)];
1831
+ });
1832
+ });
1833
+ };
1834
+ TezosProtocol.prototype.getTransactionStatuses = function (transactionHashes) {
1835
+ return __awaiter(this, void 0, void 0, function () {
1836
+ return __generator(this, function (_a) {
1837
+ throw new Error('Method not implemented.');
1838
+ });
1839
+ });
1840
+ };
1841
+ TezosProtocol.FIRST_010_CYCLE = 388;
1842
+ TezosProtocol.BLOCKS_PER_CYCLE = (_a = {},
1843
+ _a[TezosNetwork.MAINNET] = [4096, 8192],
1844
+ _a[TezosNetwork.GHOSTNET] = [4096],
1845
+ _a);
1846
+ TezosProtocol.TIME_BETWEEN_BLOCKS = (_b = {},
1847
+ _b[TezosNetwork.MAINNET] = [60, 30],
1848
+ _b[TezosNetwork.GHOSTNET] = [30],
1849
+ _b);
1850
+ return TezosProtocol;
1851
+ }(NonExtendedProtocol_1.NonExtendedProtocol));
1852
+ exports.TezosProtocol = TezosProtocol;
1853
+ //# sourceMappingURL=TezosProtocol.js.map