@airgap/tezos 0.13.45-beta.3 → 0.13.45-beta.4

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 (421) hide show
  1. package/package.json +5 -5
  2. package/v0/actions/GetKtAccountsAction.js +81 -11
  3. package/v0/actions/GetKtAccountsAction.js.map +1 -1
  4. package/v0/constants.js +6 -6
  5. package/v0/constants.js.map +1 -1
  6. package/v0/index.js +38 -38
  7. package/v0/index.js.map +1 -1
  8. package/v0/protocol/TezosAddress.d.ts +1 -0
  9. package/v0/protocol/TezosAddress.js +81 -41
  10. package/v0/protocol/TezosAddress.js.map +1 -1
  11. package/v0/protocol/TezosCryptoClient.d.ts +1 -0
  12. package/v0/protocol/TezosCryptoClient.js +123 -68
  13. package/v0/protocol/TezosCryptoClient.js.map +1 -1
  14. package/v0/protocol/TezosProtocol.js +1631 -978
  15. package/v0/protocol/TezosProtocol.js.map +1 -1
  16. package/v0/protocol/TezosProtocolOptions.d.ts +1 -1
  17. package/v0/protocol/TezosProtocolOptions.js +98 -26
  18. package/v0/protocol/TezosProtocolOptions.js.map +1 -1
  19. package/v0/protocol/TezosUtils.d.ts +1 -0
  20. package/v0/protocol/TezosUtils.js +165 -131
  21. package/v0/protocol/TezosUtils.js.map +1 -1
  22. package/v0/protocol/contract/TezosContract.js +472 -243
  23. package/v0/protocol/contract/TezosContract.js.map +1 -1
  24. package/v0/protocol/contract/TezosContractCall.js +10 -8
  25. package/v0/protocol/contract/TezosContractCall.js.map +1 -1
  26. package/v0/protocol/contract/TezosContractEntrypoint.js +19 -14
  27. package/v0/protocol/contract/TezosContractEntrypoint.js.map +1 -1
  28. package/v0/protocol/contract/TezosContractStorage.js +9 -8
  29. package/v0/protocol/contract/TezosContractStorage.js.map +1 -1
  30. package/v0/protocol/contract/remote-data/TezosContractRemoteDataFactory.js +25 -8
  31. package/v0/protocol/contract/remote-data/TezosContractRemoteDataFactory.js.map +1 -1
  32. package/v0/protocol/contract/remote-data/TezosStorageRemoteData.js +113 -39
  33. package/v0/protocol/contract/remote-data/TezosStorageRemoteData.js.map +1 -1
  34. package/v0/protocol/domains/TezosDomains.js +270 -165
  35. package/v0/protocol/domains/TezosDomains.js.map +1 -1
  36. package/v0/protocol/fa/TezosBTC.js +98 -19
  37. package/v0/protocol/fa/TezosBTC.js.map +1 -1
  38. package/v0/protocol/fa/TezosBTCtez.js +48 -17
  39. package/v0/protocol/fa/TezosBTCtez.js.map +1 -1
  40. package/v0/protocol/fa/TezosCTez.js +45 -17
  41. package/v0/protocol/fa/TezosCTez.js.map +1 -1
  42. package/v0/protocol/fa/TezosDOGA.js +45 -17
  43. package/v0/protocol/fa/TezosDOGA.js.map +1 -1
  44. package/v0/protocol/fa/TezosETHtz.js +68 -10
  45. package/v0/protocol/fa/TezosETHtz.js.map +1 -1
  46. package/v0/protocol/fa/TezosFA1Protocol.js +276 -119
  47. package/v0/protocol/fa/TezosFA1Protocol.js.map +1 -1
  48. package/v0/protocol/fa/TezosFA1p2Protocol.js +101 -22
  49. package/v0/protocol/fa/TezosFA1p2Protocol.js.map +1 -1
  50. package/v0/protocol/fa/TezosFA2Protocol.js +402 -213
  51. package/v0/protocol/fa/TezosFA2Protocol.js.map +1 -1
  52. package/v0/protocol/fa/TezosFAProtocol.js +418 -211
  53. package/v0/protocol/fa/TezosFAProtocol.js.map +1 -1
  54. package/v0/protocol/fa/TezosFAProtocolOptions.d.ts +2 -2
  55. package/v0/protocol/fa/TezosFAProtocolOptions.js +195 -92
  56. package/v0/protocol/fa/TezosFAProtocolOptions.js.map +1 -1
  57. package/v0/protocol/fa/TezosKolibriUSD.js +70 -11
  58. package/v0/protocol/fa/TezosKolibriUSD.js.map +1 -1
  59. package/v0/protocol/fa/TezosPlanty.js +45 -17
  60. package/v0/protocol/fa/TezosPlanty.js.map +1 -1
  61. package/v0/protocol/fa/TezosQUIPU.js +48 -17
  62. package/v0/protocol/fa/TezosQUIPU.js.map +1 -1
  63. package/v0/protocol/fa/TezosSIRS.js +45 -17
  64. package/v0/protocol/fa/TezosSIRS.js.map +1 -1
  65. package/v0/protocol/fa/TezosStaker.js +70 -11
  66. package/v0/protocol/fa/TezosStaker.js.map +1 -1
  67. package/v0/protocol/fa/TezosUBTC.js +48 -17
  68. package/v0/protocol/fa/TezosUBTC.js.map +1 -1
  69. package/v0/protocol/fa/TezosUDEFI.js +48 -17
  70. package/v0/protocol/fa/TezosUDEFI.js.map +1 -1
  71. package/v0/protocol/fa/TezosUSD.js +70 -11
  72. package/v0/protocol/fa/TezosUSD.js.map +1 -1
  73. package/v0/protocol/fa/TezosUSDT.js +48 -17
  74. package/v0/protocol/fa/TezosUSDT.js.map +1 -1
  75. package/v0/protocol/fa/TezosUUSD.js +27 -8
  76. package/v0/protocol/fa/TezosUUSD.js.map +1 -1
  77. package/v0/protocol/fa/TezosUXTZ.js +48 -17
  78. package/v0/protocol/fa/TezosUXTZ.js.map +1 -1
  79. package/v0/protocol/fa/TezosWRAP.js +48 -17
  80. package/v0/protocol/fa/TezosWRAP.js.map +1 -1
  81. package/v0/protocol/fa/TezosWrapped.js +70 -11
  82. package/v0/protocol/fa/TezosWrapped.js.map +1 -1
  83. package/v0/protocol/fa/TezosYOU.js +27 -8
  84. package/v0/protocol/fa/TezosYOU.js.map +1 -1
  85. package/v0/protocol/fa/metadata/BigMapTokenMetadataIndexer.js +162 -84
  86. package/v0/protocol/fa/metadata/BigMapTokenMetadataIndexer.js.map +1 -1
  87. package/v0/protocol/fa/metadata/ObjktTokenMetadataIndexer.js +87 -37
  88. package/v0/protocol/fa/metadata/ObjktTokenMetadataIndexer.js.map +1 -1
  89. package/v0/protocol/indexerClient/TezosIndexerClient.js +259 -115
  90. package/v0/protocol/indexerClient/TezosIndexerClient.js.map +1 -1
  91. package/v0/protocol/kt/TezosKtAddress.js +67 -7
  92. package/v0/protocol/kt/TezosKtAddress.js.map +1 -1
  93. package/v0/protocol/kt/TezosKtProtocol.js +309 -161
  94. package/v0/protocol/kt/TezosKtProtocol.js.map +1 -1
  95. package/v0/protocol/sapling/TezosSaplingAddress.d.ts +1 -0
  96. package/v0/protocol/sapling/TezosSaplingAddress.js +117 -46
  97. package/v0/protocol/sapling/TezosSaplingAddress.js.map +1 -1
  98. package/v0/protocol/sapling/TezosSaplingCryptoClient.d.ts +1 -0
  99. package/v0/protocol/sapling/TezosSaplingCryptoClient.js +220 -125
  100. package/v0/protocol/sapling/TezosSaplingCryptoClient.js.map +1 -1
  101. package/v0/protocol/sapling/TezosSaplingProtocol.d.ts +1 -0
  102. package/v0/protocol/sapling/TezosSaplingProtocol.js +1127 -600
  103. package/v0/protocol/sapling/TezosSaplingProtocol.js.map +1 -1
  104. package/v0/protocol/sapling/TezosSaplingProtocolOptions.d.ts +1 -0
  105. package/v0/protocol/sapling/TezosSaplingProtocolOptions.js +61 -32
  106. package/v0/protocol/sapling/TezosSaplingProtocolOptions.js.map +1 -1
  107. package/v0/protocol/sapling/TezosShieldedTezProtocol.js +134 -50
  108. package/v0/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -1
  109. package/v0/protocol/sapling/injector/TezosSaplingInjectorClient.js +56 -10
  110. package/v0/protocol/sapling/injector/TezosSaplingInjectorClient.js.map +1 -1
  111. package/v0/protocol/sapling/node/TezosSaplingNodeClient.js +67 -12
  112. package/v0/protocol/sapling/node/TezosSaplingNodeClient.js.map +1 -1
  113. package/v0/protocol/sapling/utils/TezosSaplingBookkeeper.d.ts +1 -0
  114. package/v0/protocol/sapling/utils/TezosSaplingBookkeeper.js +539 -221
  115. package/v0/protocol/sapling/utils/TezosSaplingBookkeeper.js.map +1 -1
  116. package/v0/protocol/sapling/utils/TezosSaplingEncoder.d.ts +1 -0
  117. package/v0/protocol/sapling/utils/TezosSaplingEncoder.js +104 -101
  118. package/v0/protocol/sapling/utils/TezosSaplingEncoder.js.map +1 -1
  119. package/v0/protocol/sapling/utils/TezosSaplingForger.d.ts +1 -0
  120. package/v0/protocol/sapling/utils/TezosSaplingForger.js +266 -107
  121. package/v0/protocol/sapling/utils/TezosSaplingForger.js.map +1 -1
  122. package/v0/protocol/sapling/utils/TezosSaplingState.js +239 -110
  123. package/v0/protocol/sapling/utils/TezosSaplingState.js.map +1 -1
  124. package/v0/protocol/types/TezosOperationType.js +1 -1
  125. package/v0/protocol/types/TezosOperationType.js.map +1 -1
  126. package/v0/protocol/types/contract/BigMapEntry.d.ts +1 -1
  127. package/v0/protocol/types/contract/TezosContractMetadata.d.ts +2 -2
  128. package/v0/protocol/types/micheline/MichelineNode.d.ts +7 -7
  129. package/v0/protocol/types/micheline/MichelineNodeUtils.js +13 -9
  130. package/v0/protocol/types/micheline/MichelineNodeUtils.js.map +1 -1
  131. package/v0/protocol/types/michelson/MichelsonType.d.ts +1 -0
  132. package/v0/protocol/types/michelson/MichelsonType.js +12 -11
  133. package/v0/protocol/types/michelson/MichelsonType.js.map +1 -1
  134. package/v0/protocol/types/michelson/MichelsonTypeMeta.js +92 -45
  135. package/v0/protocol/types/michelson/MichelsonTypeMeta.js.map +1 -1
  136. package/v0/protocol/types/michelson/MichelsonTypeUtils.d.ts +1 -0
  137. package/v0/protocol/types/michelson/MichelsonTypeUtils.js +219 -58
  138. package/v0/protocol/types/michelson/MichelsonTypeUtils.js.map +1 -1
  139. package/v0/protocol/types/michelson/generics/MichelsonList.js +43 -24
  140. package/v0/protocol/types/michelson/generics/MichelsonList.js.map +1 -1
  141. package/v0/protocol/types/michelson/generics/MichelsonMap.js +61 -39
  142. package/v0/protocol/types/michelson/generics/MichelsonMap.js.map +1 -1
  143. package/v0/protocol/types/michelson/generics/MichelsonOption.d.ts +1 -1
  144. package/v0/protocol/types/michelson/generics/MichelsonOption.js +75 -46
  145. package/v0/protocol/types/michelson/generics/MichelsonOption.js.map +1 -1
  146. package/v0/protocol/types/michelson/generics/MichelsonOr.d.ts +1 -1
  147. package/v0/protocol/types/michelson/generics/MichelsonOr.js +76 -50
  148. package/v0/protocol/types/michelson/generics/MichelsonOr.js.map +1 -1
  149. package/v0/protocol/types/michelson/generics/MichelsonPair.js +85 -52
  150. package/v0/protocol/types/michelson/generics/MichelsonPair.js.map +1 -1
  151. package/v0/protocol/types/michelson/grammar/MichelsonGrammarData.d.ts +1 -1
  152. package/v0/protocol/types/michelson/grammar/MichelsonGrammarInstruction.d.ts +1 -1
  153. package/v0/protocol/types/michelson/grammar/MichelsonGrammarType.d.ts +1 -1
  154. package/v0/protocol/types/michelson/primitives/MichelsonAddress.d.ts +1 -0
  155. package/v0/protocol/types/michelson/primitives/MichelsonAddress.js +47 -28
  156. package/v0/protocol/types/michelson/primitives/MichelsonAddress.js.map +1 -1
  157. package/v0/protocol/types/michelson/primitives/MichelsonBool.js +39 -20
  158. package/v0/protocol/types/michelson/primitives/MichelsonBool.js.map +1 -1
  159. package/v0/protocol/types/michelson/primitives/MichelsonBytes.d.ts +1 -0
  160. package/v0/protocol/types/michelson/primitives/MichelsonBytes.js +54 -35
  161. package/v0/protocol/types/michelson/primitives/MichelsonBytes.js.map +1 -1
  162. package/v0/protocol/types/michelson/primitives/MichelsonInt.d.ts +1 -0
  163. package/v0/protocol/types/michelson/primitives/MichelsonInt.js +49 -30
  164. package/v0/protocol/types/michelson/primitives/MichelsonInt.js.map +1 -1
  165. package/v0/protocol/types/michelson/primitives/MichelsonString.d.ts +1 -0
  166. package/v0/protocol/types/michelson/primitives/MichelsonString.js +52 -33
  167. package/v0/protocol/types/michelson/primitives/MichelsonString.js.map +1 -1
  168. package/v0/protocol/types/michelson/primitives/MichelsonUnit.js +34 -14
  169. package/v0/protocol/types/michelson/primitives/MichelsonUnit.js.map +1 -1
  170. package/v0/protocol/types/sapling/TezosSaplingStateTree.d.ts +1 -1
  171. package/v0/protocol/types/sapling/TezosSaplingTransaction.d.ts +1 -0
  172. package/v0/protocol/types/utils.js +10 -8
  173. package/v0/protocol/types/utils.js.map +1 -1
  174. package/v0/serializer/validators/transaction-validator.js +78 -29
  175. package/v0/serializer/validators/transaction-validator.js.map +1 -1
  176. package/v0/serializer/validators/transaction-xtz-btc-validator.js +129 -55
  177. package/v0/serializer/validators/transaction-xtz-btc-validator.js.map +1 -1
  178. package/v0/serializer/validators/validators.js +103 -43
  179. package/v0/serializer/validators/validators.js.map +1 -1
  180. package/v1/block-explorer/TzKTBlockExplorer.js +61 -12
  181. package/v1/block-explorer/TzKTBlockExplorer.js.map +1 -1
  182. package/v1/block-explorer/factory.js +5 -4
  183. package/v1/block-explorer/factory.js.map +1 -1
  184. package/v1/contract/TezosContract.js +471 -242
  185. package/v1/contract/TezosContract.js.map +1 -1
  186. package/v1/contract/TezosContractCall.js +10 -8
  187. package/v1/contract/TezosContractCall.js.map +1 -1
  188. package/v1/contract/TezosContractEntrypoint.d.ts +1 -1
  189. package/v1/contract/TezosContractEntrypoint.js +19 -14
  190. package/v1/contract/TezosContractEntrypoint.js.map +1 -1
  191. package/v1/contract/TezosContractStorage.js +9 -8
  192. package/v1/contract/TezosContractStorage.js.map +1 -1
  193. package/v1/contract/remote-data/TezosContractRemoteDataFactory.js +25 -8
  194. package/v1/contract/remote-data/TezosContractRemoteDataFactory.js.map +1 -1
  195. package/v1/contract/remote-data/TezosStorageRemoteData.js +113 -39
  196. package/v1/contract/remote-data/TezosStorageRemoteData.js.map +1 -1
  197. package/v1/crypto/TezosCryptoClient.d.ts +1 -0
  198. package/v1/crypto/TezosCryptoClient.js +117 -64
  199. package/v1/crypto/TezosCryptoClient.js.map +1 -1
  200. package/v1/crypto/TezosSaplingCryptoClient.d.ts +1 -0
  201. package/v1/crypto/TezosSaplingCryptoClient.js +194 -116
  202. package/v1/crypto/TezosSaplingCryptoClient.js.map +1 -1
  203. package/v1/data/TezosAddress.js +14 -13
  204. package/v1/data/TezosAddress.js.map +1 -1
  205. package/v1/data/TezosSaplingAddress.d.ts +1 -0
  206. package/v1/data/TezosSaplingAddress.js +94 -29
  207. package/v1/data/TezosSaplingAddress.js.map +1 -1
  208. package/v1/domains/TezosDomains.js +270 -165
  209. package/v1/domains/TezosDomains.js.map +1 -1
  210. package/v1/index.js +39 -39
  211. package/v1/index.js.map +1 -1
  212. package/v1/indexer/TzKTIndexerClient.js +270 -126
  213. package/v1/indexer/TzKTIndexerClient.js.map +1 -1
  214. package/v1/indexer/factory.js +5 -4
  215. package/v1/indexer/factory.js.map +1 -1
  216. package/v1/indexer/token-metadata/BigMapTokenMetadataIndexerClient.js +161 -83
  217. package/v1/indexer/token-metadata/BigMapTokenMetadataIndexerClient.js.map +1 -1
  218. package/v1/indexer/token-metadata/ObjktTokenMetadataIndexerClient.js +85 -36
  219. package/v1/indexer/token-metadata/ObjktTokenMetadataIndexerClient.js.map +1 -1
  220. package/v1/injector/TezosSaplingInjectorClient.js +56 -10
  221. package/v1/injector/TezosSaplingInjectorClient.js.map +1 -1
  222. package/v1/module/TezosModule.js +155 -88
  223. package/v1/module/TezosModule.js.map +1 -1
  224. package/v1/module.js +3 -2
  225. package/v1/module.js.map +1 -1
  226. package/v1/node/TezosSaplingNodeClient.js +67 -12
  227. package/v1/node/TezosSaplingNodeClient.js.map +1 -1
  228. package/v1/protocol/TezosProtocol.js +1385 -848
  229. package/v1/protocol/TezosProtocol.js.map +1 -1
  230. package/v1/protocol/fa/TezosFA1Protocol.js +205 -81
  231. package/v1/protocol/fa/TezosFA1Protocol.js.map +1 -1
  232. package/v1/protocol/fa/TezosFA1p2Protocol.js +111 -32
  233. package/v1/protocol/fa/TezosFA1p2Protocol.js.map +1 -1
  234. package/v1/protocol/fa/TezosFA2Protocol.js +332 -174
  235. package/v1/protocol/fa/TezosFA2Protocol.js.map +1 -1
  236. package/v1/protocol/fa/TezosFAProtocol.js +528 -255
  237. package/v1/protocol/fa/TezosFAProtocol.js.map +1 -1
  238. package/v1/protocol/fa/tokens/BTCTezProtocol.d.ts +2 -2
  239. package/v1/protocol/fa/tokens/BTCTezProtocol.js +47 -30
  240. package/v1/protocol/fa/tokens/BTCTezProtocol.js.map +1 -1
  241. package/v1/protocol/fa/tokens/CTezProtocol.d.ts +2 -2
  242. package/v1/protocol/fa/tokens/CTezProtocol.js +47 -27
  243. package/v1/protocol/fa/tokens/CTezProtocol.js.map +1 -1
  244. package/v1/protocol/fa/tokens/DogamiProtocol.d.ts +2 -2
  245. package/v1/protocol/fa/tokens/DogamiProtocol.js +47 -27
  246. package/v1/protocol/fa/tokens/DogamiProtocol.js.map +1 -1
  247. package/v1/protocol/fa/tokens/ETHTezProtocol.d.ts +2 -2
  248. package/v1/protocol/fa/tokens/ETHTezProtocol.js +90 -30
  249. package/v1/protocol/fa/tokens/ETHTezProtocol.js.map +1 -1
  250. package/v1/protocol/fa/tokens/KolibriUSDProtocol.d.ts +2 -2
  251. package/v1/protocol/fa/tokens/KolibriUSDProtocol.js +90 -30
  252. package/v1/protocol/fa/tokens/KolibriUSDProtocol.js.map +1 -1
  253. package/v1/protocol/fa/tokens/PlentyProtocol.d.ts +2 -2
  254. package/v1/protocol/fa/tokens/PlentyProtocol.js +90 -30
  255. package/v1/protocol/fa/tokens/PlentyProtocol.js.map +1 -1
  256. package/v1/protocol/fa/tokens/QuipuswapProtocol.d.ts +2 -2
  257. package/v1/protocol/fa/tokens/QuipuswapProtocol.js +47 -30
  258. package/v1/protocol/fa/tokens/QuipuswapProtocol.js.map +1 -1
  259. package/v1/protocol/fa/tokens/SiriusProtocol.d.ts +2 -2
  260. package/v1/protocol/fa/tokens/SiriusProtocol.js +47 -27
  261. package/v1/protocol/fa/tokens/SiriusProtocol.js.map +1 -1
  262. package/v1/protocol/fa/tokens/StakerProtocol.d.ts +2 -2
  263. package/v1/protocol/fa/tokens/StakerProtocol.js +90 -30
  264. package/v1/protocol/fa/tokens/StakerProtocol.js.map +1 -1
  265. package/v1/protocol/fa/tokens/TetherUSDProtocol.d.ts +2 -2
  266. package/v1/protocol/fa/tokens/TetherUSDProtocol.js +47 -30
  267. package/v1/protocol/fa/tokens/TetherUSDProtocol.js.map +1 -1
  268. package/v1/protocol/fa/tokens/TzBTCProtocol.d.ts +2 -2
  269. package/v1/protocol/fa/tokens/TzBTCProtocol.js +47 -27
  270. package/v1/protocol/fa/tokens/TzBTCProtocol.js.map +1 -1
  271. package/v1/protocol/fa/tokens/UBTCProtocol.d.ts +2 -2
  272. package/v1/protocol/fa/tokens/UBTCProtocol.js +47 -30
  273. package/v1/protocol/fa/tokens/UBTCProtocol.js.map +1 -1
  274. package/v1/protocol/fa/tokens/UDEFIProtocol.d.ts +2 -2
  275. package/v1/protocol/fa/tokens/UDEFIProtocol.js +47 -30
  276. package/v1/protocol/fa/tokens/UDEFIProtocol.js.map +1 -1
  277. package/v1/protocol/fa/tokens/USDTezProtocol.d.ts +2 -2
  278. package/v1/protocol/fa/tokens/USDTezProtocol.js +47 -27
  279. package/v1/protocol/fa/tokens/USDTezProtocol.js.map +1 -1
  280. package/v1/protocol/fa/tokens/UUSDProtocol.d.ts +2 -2
  281. package/v1/protocol/fa/tokens/UUSDProtocol.js +47 -30
  282. package/v1/protocol/fa/tokens/UUSDProtocol.js.map +1 -1
  283. package/v1/protocol/fa/tokens/UXTZProtocol.d.ts +2 -2
  284. package/v1/protocol/fa/tokens/UXTZProtocol.js +47 -30
  285. package/v1/protocol/fa/tokens/UXTZProtocol.js.map +1 -1
  286. package/v1/protocol/fa/tokens/WrapProtocol.d.ts +2 -2
  287. package/v1/protocol/fa/tokens/WrapProtocol.js +47 -30
  288. package/v1/protocol/fa/tokens/WrapProtocol.js.map +1 -1
  289. package/v1/protocol/fa/tokens/WrappedTezosProtocol.d.ts +2 -2
  290. package/v1/protocol/fa/tokens/WrappedTezosProtocol.js +47 -27
  291. package/v1/protocol/fa/tokens/WrappedTezosProtocol.js.map +1 -1
  292. package/v1/protocol/fa/tokens/YouProtocol.d.ts +2 -2
  293. package/v1/protocol/fa/tokens/YouProtocol.js +47 -30
  294. package/v1/protocol/fa/tokens/YouProtocol.js.map +1 -1
  295. package/v1/protocol/fa/tokens/stXTZProtocol.d.ts +2 -2
  296. package/v1/protocol/fa/tokens/stXTZProtocol.js +47 -30
  297. package/v1/protocol/fa/tokens/stXTZProtocol.js.map +1 -1
  298. package/v1/protocol/kt/TezosKtProtocol.js +498 -254
  299. package/v1/protocol/kt/TezosKtProtocol.js.map +1 -1
  300. package/v1/protocol/sapling/TezosSaplingProtocol.d.ts +1 -0
  301. package/v1/protocol/sapling/TezosSaplingProtocol.js +933 -532
  302. package/v1/protocol/sapling/TezosSaplingProtocol.js.map +1 -1
  303. package/v1/protocol/sapling/TezosShieldedTezProtocol.js +164 -72
  304. package/v1/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -1
  305. package/v1/serializer/v3/schemas/converter/transaction-converter.js +26 -14
  306. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  307. package/v1/serializer/v3/serializer-companion.js +188 -103
  308. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  309. package/v1/serializer/v3/validators/transaction-validator.js +143 -54
  310. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  311. package/v1/serializer/v3/validators/validators.js +100 -40
  312. package/v1/serializer/v3/validators/validators.js.map +1 -1
  313. package/v1/types/block-explorer.d.ts +1 -1
  314. package/v1/types/contract/TezosContractMetadata.d.ts +2 -2
  315. package/v1/types/contract/bigmap/BigMapEntry.d.ts +1 -1
  316. package/v1/types/crypto.d.ts +2 -2
  317. package/v1/types/fa/TezosFA1ContractEntrypoint.d.ts +1 -1
  318. package/v1/types/fa/TezosFA1p2ContractEntrypoint.d.ts +1 -1
  319. package/v1/types/fa/TezosFA2ContractEntrypoint.d.ts +1 -1
  320. package/v1/types/indexer.d.ts +1 -1
  321. package/v1/types/micheline/MichelineNode.d.ts +7 -7
  322. package/v1/types/micheline/MichelineNodeUtils.js +13 -9
  323. package/v1/types/micheline/MichelineNodeUtils.js.map +1 -1
  324. package/v1/types/michelson/MichelsonType.d.ts +1 -0
  325. package/v1/types/michelson/MichelsonType.js +12 -11
  326. package/v1/types/michelson/MichelsonType.js.map +1 -1
  327. package/v1/types/michelson/MichelsonTypeMeta.js +92 -45
  328. package/v1/types/michelson/MichelsonTypeMeta.js.map +1 -1
  329. package/v1/types/michelson/MichelsonTypeUtils.d.ts +1 -0
  330. package/v1/types/michelson/MichelsonTypeUtils.js +219 -58
  331. package/v1/types/michelson/MichelsonTypeUtils.js.map +1 -1
  332. package/v1/types/michelson/generics/MichelsonList.js +43 -24
  333. package/v1/types/michelson/generics/MichelsonList.js.map +1 -1
  334. package/v1/types/michelson/generics/MichelsonMap.js +61 -39
  335. package/v1/types/michelson/generics/MichelsonMap.js.map +1 -1
  336. package/v1/types/michelson/generics/MichelsonOption.d.ts +1 -1
  337. package/v1/types/michelson/generics/MichelsonOption.js +75 -46
  338. package/v1/types/michelson/generics/MichelsonOption.js.map +1 -1
  339. package/v1/types/michelson/generics/MichelsonOr.d.ts +1 -1
  340. package/v1/types/michelson/generics/MichelsonOr.js +76 -50
  341. package/v1/types/michelson/generics/MichelsonOr.js.map +1 -1
  342. package/v1/types/michelson/generics/MichelsonPair.js +85 -52
  343. package/v1/types/michelson/generics/MichelsonPair.js.map +1 -1
  344. package/v1/types/michelson/grammar/MichelsonGrammarData.d.ts +1 -1
  345. package/v1/types/michelson/grammar/MichelsonGrammarInstruction.d.ts +1 -1
  346. package/v1/types/michelson/grammar/MichelsonGrammarType.d.ts +1 -1
  347. package/v1/types/michelson/primitives/MichelsonAddress.d.ts +1 -0
  348. package/v1/types/michelson/primitives/MichelsonAddress.js +47 -28
  349. package/v1/types/michelson/primitives/MichelsonAddress.js.map +1 -1
  350. package/v1/types/michelson/primitives/MichelsonBool.js +39 -20
  351. package/v1/types/michelson/primitives/MichelsonBool.js.map +1 -1
  352. package/v1/types/michelson/primitives/MichelsonBytes.d.ts +1 -0
  353. package/v1/types/michelson/primitives/MichelsonBytes.js +54 -35
  354. package/v1/types/michelson/primitives/MichelsonBytes.js.map +1 -1
  355. package/v1/types/michelson/primitives/MichelsonInt.d.ts +1 -0
  356. package/v1/types/michelson/primitives/MichelsonInt.js +49 -30
  357. package/v1/types/michelson/primitives/MichelsonInt.js.map +1 -1
  358. package/v1/types/michelson/primitives/MichelsonString.d.ts +1 -0
  359. package/v1/types/michelson/primitives/MichelsonString.js +52 -33
  360. package/v1/types/michelson/primitives/MichelsonString.js.map +1 -1
  361. package/v1/types/michelson/primitives/MichelsonUnit.js +34 -14
  362. package/v1/types/michelson/primitives/MichelsonUnit.js.map +1 -1
  363. package/v1/types/network.js +1 -1
  364. package/v1/types/network.js.map +1 -1
  365. package/v1/types/operations/TezosOperationType.js +1 -1
  366. package/v1/types/operations/TezosOperationType.js.map +1 -1
  367. package/v1/types/protocol.d.ts +3 -3
  368. package/v1/types/sapling/TezosSaplingExternalMethodProvider.d.ts +1 -0
  369. package/v1/types/sapling/TezosSaplingStateTree.d.ts +1 -1
  370. package/v1/types/sapling/TezosSaplingTransaction.d.ts +1 -0
  371. package/v1/types/staking/TezosDelegatorAction.js +1 -1
  372. package/v1/types/staking/TezosDelegatorAction.js.map +1 -1
  373. package/v1/utils/address.js +7 -6
  374. package/v1/utils/address.js.map +1 -1
  375. package/v1/utils/bip.d.ts +1 -0
  376. package/v1/utils/bip.js +7 -6
  377. package/v1/utils/bip.js.map +1 -1
  378. package/v1/utils/convert.js +8 -7
  379. package/v1/utils/convert.js.map +1 -1
  380. package/v1/utils/encoding.d.ts +1 -0
  381. package/v1/utils/encoding.js +64 -74
  382. package/v1/utils/encoding.js.map +1 -1
  383. package/v1/utils/fa.js +3 -2
  384. package/v1/utils/fa.js.map +1 -1
  385. package/v1/utils/key.js +12 -9
  386. package/v1/utils/key.js.map +1 -1
  387. package/v1/utils/micheline.js +10 -8
  388. package/v1/utils/micheline.js.map +1 -1
  389. package/v1/utils/operations.js +22 -21
  390. package/v1/utils/operations.js.map +1 -1
  391. package/v1/utils/pack.d.ts +1 -0
  392. package/v1/utils/pack.js +107 -65
  393. package/v1/utils/pack.js.map +1 -1
  394. package/v1/utils/protocol/fa/TezosFA1Accountant.js +52 -24
  395. package/v1/utils/protocol/fa/TezosFA1Accountant.js.map +1 -1
  396. package/v1/utils/protocol/fa/TezosFA2Accountant.js +77 -40
  397. package/v1/utils/protocol/fa/TezosFA2Accountant.js.map +1 -1
  398. package/v1/utils/protocol/fa/TezosFAAccountant.js +89 -21
  399. package/v1/utils/protocol/fa/TezosFAAccountant.js.map +1 -1
  400. package/v1/utils/protocol/instance.js +26 -90
  401. package/v1/utils/protocol/instance.js.map +1 -1
  402. package/v1/utils/protocol/sapling/TezosSaplingAccountant.d.ts +1 -0
  403. package/v1/utils/protocol/sapling/TezosSaplingAccountant.js +539 -221
  404. package/v1/utils/protocol/sapling/TezosSaplingAccountant.js.map +1 -1
  405. package/v1/utils/protocol/sapling/TezosSaplingEncoder.d.ts +1 -0
  406. package/v1/utils/protocol/sapling/TezosSaplingEncoder.js +104 -101
  407. package/v1/utils/protocol/sapling/TezosSaplingEncoder.js.map +1 -1
  408. package/v1/utils/protocol/sapling/TezosSaplingForger.d.ts +1 -0
  409. package/v1/utils/protocol/sapling/TezosSaplingForger.js +266 -107
  410. package/v1/utils/protocol/sapling/TezosSaplingForger.js.map +1 -1
  411. package/v1/utils/protocol/sapling/TezosSaplingState.js +239 -110
  412. package/v1/utils/protocol/sapling/TezosSaplingState.js.map +1 -1
  413. package/v1/utils/protocol/tezos/TezosAccountant.js +166 -97
  414. package/v1/utils/protocol/tezos/TezosAccountant.js.map +1 -1
  415. package/v1/utils/protocol/tezos/TezosForger.js +76 -21
  416. package/v1/utils/protocol/tezos/TezosForger.js.map +1 -1
  417. package/v1/utils/signature.js +6 -5
  418. package/v1/utils/signature.js.map +1 -1
  419. package/v1/utils/transaction.d.ts +5 -4
  420. package/v1/utils/transaction.js +3 -3
  421. package/v1/utils/transaction.js.map +1 -1
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -15,77 +26,105 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
26
  }) : function(o, v) {
16
27
  o["default"] = v;
17
28
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (_) try {
52
+ 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;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
+ if (ar || !(i in from)) {
75
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
+ ar[i] = from[i];
77
+ }
78
+ }
79
+ return to.concat(ar || Array.prototype.slice.call(from));
80
+ };
35
81
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
82
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
83
  };
38
84
  Object.defineProperty(exports, "__esModule", { value: true });
39
85
  exports.TezosSaplingProtocolImpl = void 0;
40
- const coinlib_core_1 = require("@airgap/coinlib-core");
41
- const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
42
- const errors_1 = require("@airgap/coinlib-core/errors");
43
- const array_1 = require("@airgap/coinlib-core/utils/array");
44
- const crypto_1 = require("@airgap/crypto");
45
- const module_kit_1 = require("@airgap/module-kit");
46
- const sapling = __importStar(require("@airgap/sapling-wasm"));
47
- const random_1 = require("@stablelib/random");
48
- const TezosContract_1 = require("../../contract/TezosContract");
49
- const TezosSaplingCryptoClient_1 = require("../../crypto/TezosSaplingCryptoClient");
50
- const TezosAddress_1 = require("../../data/TezosAddress");
51
- const TezosSaplingAddress_1 = require("../../data/TezosSaplingAddress");
52
- const TezosSaplingInjectorClient_1 = require("../../injector/TezosSaplingInjectorClient");
53
- const TezosSaplingNodeClient_1 = require("../../node/TezosSaplingNodeClient");
54
- const MichelsonAddress_1 = require("../../types/michelson/primitives/MichelsonAddress");
55
- const TezosOperationType_1 = require("../../types/operations/TezosOperationType");
56
- const key_1 = require("../../utils/key");
57
- const pack_1 = require("../../utils/pack");
58
- const TezosSaplingAccountant_1 = require("../../utils/protocol/sapling/TezosSaplingAccountant");
59
- const TezosSaplingEncoder_1 = require("../../utils/protocol/sapling/TezosSaplingEncoder");
60
- const TezosSaplingForger_1 = require("../../utils/protocol/sapling/TezosSaplingForger");
61
- const TezosSaplingState_1 = require("../../utils/protocol/sapling/TezosSaplingState");
62
- const transaction_1 = require("../../utils/transaction");
63
- const TezosProtocol_1 = require("../TezosProtocol");
86
+ var coinlib_core_1 = require("@airgap/coinlib-core");
87
+ var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
88
+ var errors_1 = require("@airgap/coinlib-core/errors");
89
+ var array_1 = require("@airgap/coinlib-core/utils/array");
90
+ var crypto_1 = require("@airgap/crypto");
91
+ var module_kit_1 = require("@airgap/module-kit");
92
+ var sapling = __importStar(require("@airgap/sapling-wasm"));
93
+ var random_1 = require("@stablelib/random");
94
+ var TezosContract_1 = require("../../contract/TezosContract");
95
+ var TezosSaplingCryptoClient_1 = require("../../crypto/TezosSaplingCryptoClient");
96
+ var TezosAddress_1 = require("../../data/TezosAddress");
97
+ var TezosSaplingAddress_1 = require("../../data/TezosSaplingAddress");
98
+ var TezosSaplingInjectorClient_1 = require("../../injector/TezosSaplingInjectorClient");
99
+ var TezosSaplingNodeClient_1 = require("../../node/TezosSaplingNodeClient");
100
+ var MichelsonAddress_1 = require("../../types/michelson/primitives/MichelsonAddress");
101
+ var TezosOperationType_1 = require("../../types/operations/TezosOperationType");
102
+ var key_1 = require("../../utils/key");
103
+ var pack_1 = require("../../utils/pack");
104
+ var TezosSaplingAccountant_1 = require("../../utils/protocol/sapling/TezosSaplingAccountant");
105
+ var TezosSaplingEncoder_1 = require("../../utils/protocol/sapling/TezosSaplingEncoder");
106
+ var TezosSaplingForger_1 = require("../../utils/protocol/sapling/TezosSaplingForger");
107
+ var TezosSaplingState_1 = require("../../utils/protocol/sapling/TezosSaplingState");
108
+ var transaction_1 = require("../../utils/transaction");
109
+ var TezosProtocol_1 = require("../TezosProtocol");
64
110
  // Implementation
65
- class TezosSaplingProtocolImpl {
66
- constructor(options) {
111
+ var TezosSaplingProtocolImpl = /** @class */ (function () {
112
+ function TezosSaplingProtocolImpl(options) {
113
+ var _a;
67
114
  this.isTezosSaplingProtocol = true;
68
115
  // Offline
69
116
  this.cryptoConfiguration = {
70
117
  algorithm: 'sapling',
71
118
  secretType: 'miniSecretXor'
72
119
  };
73
- this.metadata = {
74
- ...options.metadata,
75
- fee: {
76
- ...(options.metadata.fee ?? {}),
77
- units: TezosProtocol_1.TEZOS_UNITS,
78
- mainUnit: 'tez'
79
- },
80
- account: {
120
+ this.metadata = __assign(__assign({}, options.metadata), { fee: __assign(__assign({}, ((_a = options.metadata.fee) !== null && _a !== void 0 ? _a : {})), { units: TezosProtocol_1.TEZOS_UNITS, mainUnit: 'tez' }), account: {
81
121
  standardDerivationPath: options.metadata.account.standardDerivationPath,
82
122
  address: {
83
123
  isCaseSensitive: true,
84
124
  placeholder: 'zet1...',
85
125
  regex: '^(zet1[1-9A-Za-z]{65}|tz1[1-9A-Za-z]{33})$'
86
126
  }
87
- }
88
- };
127
+ } });
89
128
  this.network = options.network;
90
129
  this.memoSize = options.memoSize;
91
130
  this.tezos = (0, TezosProtocol_1.createTezosProtocol)({ network: options.network });
@@ -104,467 +143,799 @@ class TezosSaplingProtocolImpl {
104
143
  ? new TezosSaplingInjectorClient_1.TezosSaplingInjectorClient(this.network.injectorUrl, this.network.contractAddress)
105
144
  : undefined;
106
145
  }
107
- async getMetadata() {
108
- return this.metadata;
109
- }
110
- async getAddressFromPublicKey(publicKey) {
111
- const address = await TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(publicKey);
112
- return {
113
- address: address.asString(),
114
- cursor: {
115
- hasNext: address.diversifierIndex !== undefined,
116
- diversifierIndex: address.diversifierIndex
117
- }
118
- };
119
- }
120
- async getInitialAddressesFromPublicKey(publicKey) {
121
- return [await this.getAddressFromPublicKey(publicKey)];
122
- }
123
- async getNextAddressFromPublicKey(publicKey, cursor) {
124
- if (!cursor.hasNext) {
125
- return undefined;
126
- }
127
- const current = await TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(publicKey, cursor.diversifierIndex);
128
- const next = await TezosSaplingAddress_1.TezosSaplingAddress.next(publicKey, current);
129
- return {
130
- address: next.asString(),
131
- cursor: {
132
- hasNext: next.diversifierIndex !== undefined,
133
- diversifierIndex: next.diversifierIndex
134
- }
135
- };
136
- }
137
- async getContractAddress() {
138
- return this.network.contractAddress;
139
- }
140
- async setContractAddress(address) {
141
- this.network.contractAddress = address;
142
- this.contract = new TezosContract_1.TezosContract(address, this.network);
143
- this.nodeClient = new TezosSaplingNodeClient_1.TezosSaplingNodeClient(this.network.rpcUrl, address);
144
- if (this.network.injectorUrl !== undefined) {
145
- this.injectorClient = new TezosSaplingInjectorClient_1.TezosSaplingInjectorClient(this.network.injectorUrl, address);
146
- }
147
- }
148
- async getDetailsFromTransaction(transaction, publicKey, knownViewingKeys) {
149
- switch (transaction.type) {
150
- case 'signed':
151
- return this.getDetailsFromSignedTransaction(transaction, knownViewingKeys);
152
- case 'unsigned':
153
- return this.getDetailsFromUnsignedTransaction(transaction, publicKey, knownViewingKeys);
154
- default:
155
- (0, coinlib_core_1.assertNever)(transaction);
156
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Unsupported transaction type.');
157
- }
158
- }
159
- async getDetailsFromSignedTransaction(transaction, knownViewingKeys) {
160
- const airGapTxs = [];
161
- const binary = transaction.binary;
162
- const defaultDetails = {
163
- from: ['Shielded Pool'],
164
- to: ['Shielded Pool'],
165
- isInbound: false,
166
- amount: (0, module_kit_1.newAmount)(0, 'blockchain'),
167
- fee: (0, module_kit_1.newAmount)(0, 'blockchain'),
168
- network: this.network
169
- };
170
- if (this.contract?.areValidParameters(binary)) {
171
- const partialDetails = await this.getPartialDetailsFromContractParameters(binary, knownViewingKeys);
172
- airGapTxs.push(...partialDetails.map((partial) => ({
173
- ...defaultDetails,
174
- ...partial
175
- })));
176
- }
177
- else {
178
- try {
179
- const wrappedOperation = await this.tezos.unforgeOperation(binary, 'signed');
180
- airGapTxs.push(...(await this.getDetailsFromWrappedOperation(wrappedOperation, knownViewingKeys)));
181
- }
182
- catch {
183
- const partialDetails = await this.accountant.getTransactionsPartialDetails([binary], knownViewingKeys);
184
- airGapTxs.push(...partialDetails.map((partial) => ({
185
- ...defaultDetails,
186
- ...partial
187
- })));
188
- }
189
- }
190
- return this.filterOutPaybacks(airGapTxs);
191
- }
192
- async getDetailsFromUnsignedTransaction(transaction, viewingKey, knownViewingKeys) {
193
- const airGapTxs = [];
194
- if ((0, transaction_1.isUnsignedSaplingTransaction)(transaction)) {
195
- const unshieldTarget = transaction.unshieldTarget.length > 0 ? transaction.unshieldTarget : undefined;
196
- const from = await this.getAddressFromPublicKey(viewingKey).then((address) => TezosSaplingAddress_1.TezosSaplingAddress.fromValue(address.address, address.cursor.diversifierIndex));
197
- const details = this.accountant
198
- .getUnsignedTransactionDetails(from, transaction.ins, transaction.outs, unshieldTarget)
199
- .map((details) => ({
200
- ...details,
201
- extra: {
202
- ...(details.extra ?? {}),
203
- destination: transaction.contractAddress,
204
- chainId: transaction.chainId
146
+ TezosSaplingProtocolImpl.prototype.getMetadata = function () {
147
+ return __awaiter(this, void 0, void 0, function () {
148
+ return __generator(this, function (_a) {
149
+ return [2 /*return*/, this.metadata];
150
+ });
151
+ });
152
+ };
153
+ TezosSaplingProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var address;
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0: return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(publicKey)];
159
+ case 1:
160
+ address = _a.sent();
161
+ return [2 /*return*/, {
162
+ address: address.asString(),
163
+ cursor: {
164
+ hasNext: address.diversifierIndex !== undefined,
165
+ diversifierIndex: address.diversifierIndex
166
+ }
167
+ }];
205
168
  }
206
- }));
207
- airGapTxs.push(...details);
208
- }
209
- else {
210
- const wrappedOperation = await this.tezos.unforgeOperation(transaction.binary, 'unsigned');
211
- airGapTxs.push(...(await this.getDetailsFromWrappedOperation(wrappedOperation, knownViewingKeys)));
212
- }
213
- return this.filterOutPaybacks(airGapTxs);
214
- }
215
- async getDetailsFromWrappedOperation(operation, knownViewingKeys = []) {
216
- const contractOperations = operation.contents.filter((content) => content.kind === TezosOperationType_1.TezosOperationType.TRANSACTION && content.parameters !== undefined);
217
- const details = await Promise.all(contractOperations.map(async (operation) => {
218
- const saplingDetails = await this.getPartialDetailsFromContractParameters(operation.parameters, knownViewingKeys);
219
- return saplingDetails.map((partials) => ({
220
- from: [operation.source],
221
- to: ['Shielded Pool'],
222
- isInbound: false,
223
- amount: (0, module_kit_1.newAmount)(operation.amount, 'blockchain'),
224
- fee: (0, module_kit_1.newAmount)(operation.fee, 'blockchain'),
225
- network: this.network,
226
- ...partials,
227
- transactionDetails: operation
228
- }));
229
- }));
230
- return (0, array_1.flattenArray)(details);
231
- }
232
- async getPartialDetailsFromContractParameters(rawOrParsed, knownViewingKeys = []) {
233
- const parameters = typeof rawOrParsed === 'string' ? (this.contract ? this.contract.parseParameters(rawOrParsed) : JSON.parse(rawOrParsed)) : rawOrParsed;
234
- const txs = await this.parseParameters(parameters);
235
- return this.accountant.getTransactionsPartialDetails(txs, knownViewingKeys);
236
- }
237
- filterOutPaybacks(airGapTxs) {
238
- const filtered = airGapTxs.filter((details) => {
169
+ });
170
+ });
171
+ };
172
+ TezosSaplingProtocolImpl.prototype.getInitialAddressesFromPublicKey = function (publicKey) {
173
+ return __awaiter(this, void 0, void 0, function () {
174
+ return __generator(this, function (_a) {
175
+ switch (_a.label) {
176
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
177
+ case 1: return [2 /*return*/, [_a.sent()]];
178
+ }
179
+ });
180
+ });
181
+ };
182
+ TezosSaplingProtocolImpl.prototype.getNextAddressFromPublicKey = function (publicKey, cursor) {
183
+ return __awaiter(this, void 0, void 0, function () {
184
+ var current, next;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0:
188
+ if (!cursor.hasNext) {
189
+ return [2 /*return*/, undefined];
190
+ }
191
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(publicKey, cursor.diversifierIndex)];
192
+ case 1:
193
+ current = _a.sent();
194
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.next(publicKey, current)];
195
+ case 2:
196
+ next = _a.sent();
197
+ return [2 /*return*/, {
198
+ address: next.asString(),
199
+ cursor: {
200
+ hasNext: next.diversifierIndex !== undefined,
201
+ diversifierIndex: next.diversifierIndex
202
+ }
203
+ }];
204
+ }
205
+ });
206
+ });
207
+ };
208
+ TezosSaplingProtocolImpl.prototype.getContractAddress = function () {
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ return __generator(this, function (_a) {
211
+ return [2 /*return*/, this.network.contractAddress];
212
+ });
213
+ });
214
+ };
215
+ TezosSaplingProtocolImpl.prototype.setContractAddress = function (address) {
216
+ return __awaiter(this, void 0, void 0, function () {
217
+ return __generator(this, function (_a) {
218
+ this.network.contractAddress = address;
219
+ this.contract = new TezosContract_1.TezosContract(address, this.network);
220
+ this.nodeClient = new TezosSaplingNodeClient_1.TezosSaplingNodeClient(this.network.rpcUrl, address);
221
+ if (this.network.injectorUrl !== undefined) {
222
+ this.injectorClient = new TezosSaplingInjectorClient_1.TezosSaplingInjectorClient(this.network.injectorUrl, address);
223
+ }
224
+ return [2 /*return*/];
225
+ });
226
+ });
227
+ };
228
+ TezosSaplingProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey, knownViewingKeys) {
229
+ return __awaiter(this, void 0, void 0, function () {
230
+ return __generator(this, function (_a) {
231
+ switch (transaction.type) {
232
+ case 'signed':
233
+ return [2 /*return*/, this.getDetailsFromSignedTransaction(transaction, knownViewingKeys)];
234
+ case 'unsigned':
235
+ return [2 /*return*/, this.getDetailsFromUnsignedTransaction(transaction, publicKey, knownViewingKeys)];
236
+ default:
237
+ (0, coinlib_core_1.assertNever)(transaction);
238
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Unsupported transaction type.');
239
+ }
240
+ return [2 /*return*/];
241
+ });
242
+ });
243
+ };
244
+ TezosSaplingProtocolImpl.prototype.getDetailsFromSignedTransaction = function (transaction, knownViewingKeys) {
245
+ var _a;
246
+ return __awaiter(this, void 0, void 0, function () {
247
+ var airGapTxs, binary, defaultDetails, partialDetails, wrappedOperation, _b, _c, _d, _e, partialDetails;
248
+ return __generator(this, function (_f) {
249
+ switch (_f.label) {
250
+ case 0:
251
+ airGapTxs = [];
252
+ binary = transaction.binary;
253
+ defaultDetails = {
254
+ from: ['Shielded Pool'],
255
+ to: ['Shielded Pool'],
256
+ isInbound: false,
257
+ amount: (0, module_kit_1.newAmount)(0, 'blockchain'),
258
+ fee: (0, module_kit_1.newAmount)(0, 'blockchain'),
259
+ network: this.network
260
+ };
261
+ if (!((_a = this.contract) === null || _a === void 0 ? void 0 : _a.areValidParameters(binary))) return [3 /*break*/, 2];
262
+ return [4 /*yield*/, this.getPartialDetailsFromContractParameters(binary, knownViewingKeys)];
263
+ case 1:
264
+ partialDetails = _f.sent();
265
+ airGapTxs.push.apply(airGapTxs, partialDetails.map(function (partial) { return (__assign(__assign({}, defaultDetails), partial)); }));
266
+ return [3 /*break*/, 7];
267
+ case 2:
268
+ _f.trys.push([2, 5, , 7]);
269
+ return [4 /*yield*/, this.tezos.unforgeOperation(binary, 'signed')];
270
+ case 3:
271
+ wrappedOperation = _f.sent();
272
+ _c = (_b = airGapTxs.push).apply;
273
+ _d = [airGapTxs];
274
+ return [4 /*yield*/, this.getDetailsFromWrappedOperation(wrappedOperation, knownViewingKeys)];
275
+ case 4:
276
+ _c.apply(_b, _d.concat([(_f.sent())]));
277
+ return [3 /*break*/, 7];
278
+ case 5:
279
+ _e = _f.sent();
280
+ return [4 /*yield*/, this.accountant.getTransactionsPartialDetails([binary], knownViewingKeys)];
281
+ case 6:
282
+ partialDetails = _f.sent();
283
+ airGapTxs.push.apply(airGapTxs, partialDetails.map(function (partial) { return (__assign(__assign({}, defaultDetails), partial)); }));
284
+ return [3 /*break*/, 7];
285
+ case 7: return [2 /*return*/, this.filterOutPaybacks(airGapTxs)];
286
+ }
287
+ });
288
+ });
289
+ };
290
+ TezosSaplingProtocolImpl.prototype.getDetailsFromUnsignedTransaction = function (transaction, viewingKey, knownViewingKeys) {
291
+ return __awaiter(this, void 0, void 0, function () {
292
+ var airGapTxs, unshieldTarget, from, details, wrappedOperation, _a, _b, _c;
293
+ return __generator(this, function (_d) {
294
+ switch (_d.label) {
295
+ case 0:
296
+ airGapTxs = [];
297
+ if (!(0, transaction_1.isUnsignedSaplingTransaction)(transaction)) return [3 /*break*/, 2];
298
+ unshieldTarget = transaction.unshieldTarget.length > 0 ? transaction.unshieldTarget : undefined;
299
+ return [4 /*yield*/, this.getAddressFromPublicKey(viewingKey).then(function (address) {
300
+ return TezosSaplingAddress_1.TezosSaplingAddress.fromValue(address.address, address.cursor.diversifierIndex);
301
+ })];
302
+ case 1:
303
+ from = _d.sent();
304
+ details = this.accountant
305
+ .getUnsignedTransactionDetails(from, transaction.ins, transaction.outs, unshieldTarget)
306
+ .map(function (details) {
307
+ var _a;
308
+ return (__assign(__assign({}, details), { extra: __assign(__assign({}, ((_a = details.extra) !== null && _a !== void 0 ? _a : {})), { destination: transaction.contractAddress, chainId: transaction.chainId }) }));
309
+ });
310
+ airGapTxs.push.apply(airGapTxs, details);
311
+ return [3 /*break*/, 5];
312
+ case 2: return [4 /*yield*/, this.tezos.unforgeOperation(transaction.binary, 'unsigned')];
313
+ case 3:
314
+ wrappedOperation = _d.sent();
315
+ _b = (_a = airGapTxs.push).apply;
316
+ _c = [airGapTxs];
317
+ return [4 /*yield*/, this.getDetailsFromWrappedOperation(wrappedOperation, knownViewingKeys)];
318
+ case 4:
319
+ _b.apply(_a, _c.concat([(_d.sent())]));
320
+ _d.label = 5;
321
+ case 5: return [2 /*return*/, this.filterOutPaybacks(airGapTxs)];
322
+ }
323
+ });
324
+ });
325
+ };
326
+ TezosSaplingProtocolImpl.prototype.getDetailsFromWrappedOperation = function (operation, knownViewingKeys) {
327
+ if (knownViewingKeys === void 0) { knownViewingKeys = []; }
328
+ return __awaiter(this, void 0, void 0, function () {
329
+ var contractOperations, details;
330
+ var _this = this;
331
+ return __generator(this, function (_a) {
332
+ switch (_a.label) {
333
+ case 0:
334
+ contractOperations = operation.contents.filter(function (content) {
335
+ return content.kind === TezosOperationType_1.TezosOperationType.TRANSACTION && content.parameters !== undefined;
336
+ });
337
+ return [4 /*yield*/, Promise.all(contractOperations.map(function (operation) { return __awaiter(_this, void 0, void 0, function () {
338
+ var saplingDetails;
339
+ var _this = this;
340
+ return __generator(this, function (_a) {
341
+ switch (_a.label) {
342
+ case 0: return [4 /*yield*/, this.getPartialDetailsFromContractParameters(operation.parameters, knownViewingKeys)];
343
+ case 1:
344
+ saplingDetails = _a.sent();
345
+ return [2 /*return*/, saplingDetails.map(function (partials) { return (__assign(__assign({ from: [operation.source], to: ['Shielded Pool'], isInbound: false, amount: (0, module_kit_1.newAmount)(operation.amount, 'blockchain'), fee: (0, module_kit_1.newAmount)(operation.fee, 'blockchain'), network: _this.network }, partials), { transactionDetails: operation })); })];
346
+ }
347
+ });
348
+ }); }))];
349
+ case 1:
350
+ details = _a.sent();
351
+ return [2 /*return*/, (0, array_1.flattenArray)(details)];
352
+ }
353
+ });
354
+ });
355
+ };
356
+ TezosSaplingProtocolImpl.prototype.getPartialDetailsFromContractParameters = function (rawOrParsed, knownViewingKeys) {
357
+ if (knownViewingKeys === void 0) { knownViewingKeys = []; }
358
+ return __awaiter(this, void 0, void 0, function () {
359
+ var parameters, txs;
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0:
363
+ parameters = typeof rawOrParsed === 'string' ? (this.contract ? this.contract.parseParameters(rawOrParsed) : JSON.parse(rawOrParsed)) : rawOrParsed;
364
+ return [4 /*yield*/, this.parseParameters(parameters)];
365
+ case 1:
366
+ txs = _a.sent();
367
+ return [2 /*return*/, this.accountant.getTransactionsPartialDetails(txs, knownViewingKeys)];
368
+ }
369
+ });
370
+ });
371
+ };
372
+ TezosSaplingProtocolImpl.prototype.filterOutPaybacks = function (airGapTxs) {
373
+ var filtered = airGapTxs.filter(function (details) {
239
374
  if (details.from.length !== details.to.length) {
240
375
  return true;
241
376
  }
242
- const fromSet = new Set(details.from);
243
- const toSet = new Set(details.to);
244
- return Array.from(fromSet).some((address) => !toSet.has(address));
377
+ var fromSet = new Set(details.from);
378
+ var toSet = new Set(details.to);
379
+ return Array.from(fromSet).some(function (address) { return !toSet.has(address); });
245
380
  });
246
381
  return filtered.length > 0 ? filtered : airGapTxs;
247
- }
248
- async getCryptoConfiguration() {
249
- return this.cryptoConfiguration;
250
- }
251
- async getKeyPairFromDerivative(derivative) {
252
- const zip32Node = (0, crypto_1.encodeDerivative)('zip32', derivative);
253
- return {
254
- secretKey: (0, module_kit_1.newSecretKey)(zip32Node.secretKey, 'hex'),
255
- publicKey: (0, module_kit_1.newPublicKey)(zip32Node.publicKey, 'hex')
256
- };
257
- }
258
- async signTransactionWithSecretKey(transaction, secretKey) {
259
- const hexSecretKey = (0, key_1.convertSecretKey)(secretKey, 'hex', 'saplingSpendingKey');
260
- const stateTree = await this.state.getStateTreeFromStateDiff(transaction.stateDiff);
261
- const boundData = transaction.unshieldTarget && transaction.unshieldTarget.length > 0
262
- ? this.createAddressBoundData(transaction.unshieldTarget)
263
- : undefined;
264
- const forgedTransaction = await this.forger.forgeSaplingTransaction(transaction.ins, transaction.outs, stateTree, this.getAntiReplay(transaction.chainId, transaction.contractAddress), boundData, Buffer.from(hexSecretKey.value, 'hex'));
265
- return (0, module_kit_1.newSignedTransaction)({
266
- binary: this.encoder.encodeTransaction(forgedTransaction).toString('hex')
382
+ };
383
+ TezosSaplingProtocolImpl.prototype.getCryptoConfiguration = function () {
384
+ return __awaiter(this, void 0, void 0, function () {
385
+ return __generator(this, function (_a) {
386
+ return [2 /*return*/, this.cryptoConfiguration];
387
+ });
267
388
  });
268
- }
389
+ };
390
+ TezosSaplingProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
391
+ return __awaiter(this, void 0, void 0, function () {
392
+ var zip32Node;
393
+ return __generator(this, function (_a) {
394
+ zip32Node = (0, crypto_1.encodeDerivative)('zip32', derivative);
395
+ return [2 /*return*/, {
396
+ secretKey: (0, module_kit_1.newSecretKey)(zip32Node.secretKey, 'hex'),
397
+ publicKey: (0, module_kit_1.newPublicKey)(zip32Node.publicKey, 'hex')
398
+ }];
399
+ });
400
+ });
401
+ };
402
+ TezosSaplingProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
403
+ return __awaiter(this, void 0, void 0, function () {
404
+ var hexSecretKey, stateTree, boundData, forgedTransaction;
405
+ return __generator(this, function (_a) {
406
+ switch (_a.label) {
407
+ case 0:
408
+ hexSecretKey = (0, key_1.convertSecretKey)(secretKey, 'hex', 'saplingSpendingKey');
409
+ return [4 /*yield*/, this.state.getStateTreeFromStateDiff(transaction.stateDiff)];
410
+ case 1:
411
+ stateTree = _a.sent();
412
+ boundData = transaction.unshieldTarget && transaction.unshieldTarget.length > 0
413
+ ? this.createAddressBoundData(transaction.unshieldTarget)
414
+ : undefined;
415
+ return [4 /*yield*/, this.forger.forgeSaplingTransaction(transaction.ins, transaction.outs, stateTree, this.getAntiReplay(transaction.chainId, transaction.contractAddress), boundData, Buffer.from(hexSecretKey.value, 'hex'))];
416
+ case 2:
417
+ forgedTransaction = _a.sent();
418
+ return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({
419
+ binary: this.encoder.encodeTransaction(forgedTransaction).toString('hex')
420
+ })];
421
+ }
422
+ });
423
+ });
424
+ };
269
425
  // Online
270
- async getNetwork() {
271
- return this.network;
272
- }
273
- async getTransactionsForPublicKey(publicKey, limit, cursor) {
274
- if (this.nodeClient === undefined) {
275
- return {
276
- transactions: [],
277
- cursor: {
278
- hasNext: false
426
+ TezosSaplingProtocolImpl.prototype.getNetwork = function () {
427
+ return __awaiter(this, void 0, void 0, function () {
428
+ return __generator(this, function (_a) {
429
+ return [2 /*return*/, this.network];
430
+ });
431
+ });
432
+ };
433
+ TezosSaplingProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
434
+ var _a;
435
+ return __awaiter(this, void 0, void 0, function () {
436
+ var hexPublicKey, saplingStateDiff, incoming, outgoing, page, pageStart, pageEnd, hasNext, commitmentsAndCiphertexts, inputs, airGapIncoming, airGapOutgoing;
437
+ var _this = this;
438
+ return __generator(this, function (_b) {
439
+ switch (_b.label) {
440
+ case 0:
441
+ if (this.nodeClient === undefined) {
442
+ return [2 /*return*/, {
443
+ transactions: [],
444
+ cursor: {
445
+ hasNext: false
446
+ }
447
+ }];
448
+ }
449
+ hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex', 'saplingViewingKey');
450
+ return [4 /*yield*/, this.nodeClient.getSaplingStateDiff()];
451
+ case 1:
452
+ saplingStateDiff = _b.sent();
453
+ incoming = [];
454
+ outgoing = [];
455
+ page = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.page) !== null && _a !== void 0 ? _a : 0;
456
+ pageStart = page * limit;
457
+ pageEnd = pageStart + limit;
458
+ hasNext = pageStart < saplingStateDiff.commitments_and_ciphertexts.length;
459
+ _b.label = 2;
460
+ case 2:
461
+ if (!(incoming.length + outgoing.length < limit && hasNext)) return [3 /*break*/, 4];
462
+ commitmentsAndCiphertexts = saplingStateDiff.commitments_and_ciphertexts
463
+ .map(function (_a, index) {
464
+ var commitment = _a[0], ciphertext = _a[1];
465
+ return [commitment, ciphertext, new bignumber_1.default(index)];
466
+ })
467
+ .reverse()
468
+ .slice(pageStart, pageEnd);
469
+ return [4 /*yield*/, Promise.all([
470
+ this.accountant.getIncomingInputs(hexPublicKey.value, commitmentsAndCiphertexts),
471
+ this.accountant.getOutgoingInputs(hexPublicKey.value, commitmentsAndCiphertexts)
472
+ ])];
473
+ case 3:
474
+ inputs = _b.sent();
475
+ incoming.push.apply(incoming, inputs[0]);
476
+ outgoing.push.apply(outgoing, inputs[1]);
477
+ page += 1;
478
+ pageStart += limit;
479
+ pageEnd += limit;
480
+ hasNext = pageStart < saplingStateDiff.commitments_and_ciphertexts.length;
481
+ return [3 /*break*/, 2];
482
+ case 4: return [4 /*yield*/, Promise.all(incoming.map(function (input) { return __awaiter(_this, void 0, void 0, function () {
483
+ return __generator(this, function (_a) {
484
+ return [2 /*return*/, ({
485
+ from: ['Shielded Pool'],
486
+ to: [input.address],
487
+ isInbound: true,
488
+ amount: (0, module_kit_1.newAmount)(input.value, 'blockchain'),
489
+ fee: (0, module_kit_1.newAmount)(0, 'blockchain'),
490
+ network: this.network
491
+ })];
492
+ });
493
+ }); }))];
494
+ case 5:
495
+ airGapIncoming = _b.sent();
496
+ return [4 /*yield*/, Promise.all(outgoing.map(function (input) { return __awaiter(_this, void 0, void 0, function () {
497
+ var _a;
498
+ return __generator(this, function (_b) {
499
+ switch (_b.label) {
500
+ case 0:
501
+ _a = {};
502
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
503
+ case 1: return [2 /*return*/, (_a.from = [(_b.sent()).address],
504
+ _a.to = [input.address],
505
+ _a.isInbound = false,
506
+ _a.amount = (0, module_kit_1.newAmount)(input.value, 'blockchain'),
507
+ _a.fee = (0, module_kit_1.newAmount)(0, 'blockchain'),
508
+ _a.network = this.network,
509
+ _a)];
510
+ }
511
+ });
512
+ }); }))];
513
+ case 6:
514
+ airGapOutgoing = _b.sent();
515
+ return [2 /*return*/, {
516
+ transactions: airGapIncoming.concat(airGapOutgoing),
517
+ cursor: {
518
+ hasNext: hasNext,
519
+ page: hasNext ? page + 1 : undefined
520
+ }
521
+ }];
279
522
  }
280
- };
281
- }
282
- const hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex', 'saplingViewingKey');
283
- const saplingStateDiff = await this.nodeClient.getSaplingStateDiff();
284
- const incoming = [];
285
- const outgoing = [];
286
- let page = cursor?.page ?? 0;
287
- let pageStart = page * limit;
288
- let pageEnd = pageStart + limit;
289
- let hasNext = pageStart < saplingStateDiff.commitments_and_ciphertexts.length;
290
- while (incoming.length + outgoing.length < limit && hasNext) {
291
- const commitmentsAndCiphertexts = saplingStateDiff.commitments_and_ciphertexts
292
- .map(([commitment, ciphertext], index) => [commitment, ciphertext, new bignumber_1.default(index)])
293
- .reverse()
294
- .slice(pageStart, pageEnd);
295
- const inputs = await Promise.all([
296
- this.accountant.getIncomingInputs(hexPublicKey.value, commitmentsAndCiphertexts),
297
- this.accountant.getOutgoingInputs(hexPublicKey.value, commitmentsAndCiphertexts)
298
- ]);
299
- incoming.push(...inputs[0]);
300
- outgoing.push(...inputs[1]);
301
- page += 1;
302
- pageStart += limit;
303
- pageEnd += limit;
304
- hasNext = pageStart < saplingStateDiff.commitments_and_ciphertexts.length;
305
- }
306
- const airGapIncoming = await Promise.all(incoming.map(async (input) => ({
307
- from: ['Shielded Pool'],
308
- to: [input.address],
309
- isInbound: true,
310
- amount: (0, module_kit_1.newAmount)(input.value, 'blockchain'),
311
- fee: (0, module_kit_1.newAmount)(0, 'blockchain'),
312
- network: this.network
313
- })));
314
- const airGapOutgoing = await Promise.all(outgoing.map(async (input) => ({
315
- from: [(await this.getAddressFromPublicKey(publicKey)).address],
316
- to: [input.address],
317
- isInbound: false,
318
- amount: (0, module_kit_1.newAmount)(input.value, 'blockchain'),
319
- fee: (0, module_kit_1.newAmount)(0, 'blockchain'),
320
- network: this.network
321
- })));
322
- return {
323
- transactions: airGapIncoming.concat(airGapOutgoing),
324
- cursor: {
325
- hasNext,
326
- page: hasNext ? page + 1 : undefined
327
- }
328
- };
329
- }
330
- async getBalanceOfPublicKey(publicKey) {
331
- if (this.nodeClient === undefined) {
332
- return { total: (0, module_kit_1.newAmount)(0, 'blockchain') };
333
- }
334
- const hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex', 'saplingViewingKey');
335
- const saplingStateDiff = await this.nodeClient.getSaplingStateDiff();
336
- const unspends = await this.accountant.getUnspends(hexPublicKey.value, saplingStateDiff.commitments_and_ciphertexts, saplingStateDiff.nullifiers);
337
- const balance = unspends.reduce((sum, next) => sum.plus(next.value), new bignumber_1.default(0));
338
- return { total: (0, module_kit_1.newAmount)(balance, 'blockchain') };
339
- }
340
- async getTransactionMaxAmountWithPublicKey(publicKey, _to, _configuration) {
341
- const balance = await this.getBalanceOfPublicKey(publicKey);
342
- return balance.total;
343
- }
344
- async getTransactionFeeWithPublicKey(_publicKey, _details, _configuration) {
345
- return undefined;
346
- }
347
- async prepareTransactionWithPublicKey(publicKey, details, configuration) {
348
- if (details.length > 1) {
349
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
350
- }
351
- const recipient = details[0].to;
352
- if (TezosAddress_1.TezosAddress.isTzAddress(recipient)) {
353
- return this.prepareUnshieldTransaction(publicKey, details, configuration);
354
- }
355
- else if (TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
356
- return this.prepareSaplingTransaction(publicKey, details, configuration);
357
- }
358
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.TEZOS, `Invalid recpient, expected a 'tz' or 'zet' address, got ${recipient}`);
359
- }
360
- async broadcastTransaction(transaction) {
361
- if (!this.injectorClient) {
362
- throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, "Can't broadcast a sapling transaction, an injector service URL or contract address has not be set.");
363
- }
364
- try {
365
- const hash = await this.injectorClient.injectTransaction(transaction.binary);
366
- return hash;
367
- }
368
- catch (error) {
369
- throw new errors_1.NetworkError(coinlib_core_1.Domain.TEZOS, error);
370
- }
371
- }
372
- async getInjectorUrl() {
373
- return this.network.injectorUrl;
374
- }
375
- async setInjectorUrl(url) {
376
- this.network.injectorUrl = url;
377
- if (this.network.contractAddress !== undefined) {
378
- this.injectorClient = new TezosSaplingInjectorClient_1.TezosSaplingInjectorClient(url, this.network.contractAddress);
379
- }
380
- }
381
- async initParameters(spendParams, outputParams) {
382
- const externalInitParameters = this.externalProvider ? this.externalProvider.initParameters?.bind(this.externalProvider) : undefined;
383
- if (externalInitParameters !== undefined) {
384
- await externalInitParameters(spendParams, outputParams);
385
- }
386
- else {
387
- await sapling.initParameters(spendParams, outputParams);
388
- }
389
- }
390
- async getAddressFromViewingKey(viewingKey, index) {
391
- const address = await TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(viewingKey, index);
392
- return {
393
- address: address.asString(),
394
- cursor: {
395
- hasNext: address.diversifierIndex !== undefined,
396
- diversifierIndex: address.diversifierIndex
397
- }
398
- };
399
- }
400
- async prepareShieldTransaction(publicKey, details, configuration) {
401
- if (details.length > 1) {
402
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
403
- }
404
- const recipient = details[0].to;
405
- const value = (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.metadata.units).value;
406
- const encodedTransaction = await this.mint(recipient, value);
407
- return this.wrapSaplingTransactions(publicKey, [encodedTransaction], configuration);
408
- }
409
- async prepareSaplingTransaction(viewingKey, details, configuration) {
410
- if (details.length > 1) {
411
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
412
- }
413
- if (this.nodeClient === undefined || this.network.contractAddress === undefined) {
414
- throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
415
- }
416
- const recipient = details[0].to;
417
- const value = (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.metadata.units).value;
418
- if (!TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
419
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.TEZOS, `Invalid recpient, expected a 'zet' address, got ${recipient}`);
420
- }
421
- const dummyInputsAmount = Math.max(new bignumber_1.default(configuration?.dummyInputs ?? 0).toNumber(), 0);
422
- const dummyOutputsAmount = Math.max(new bignumber_1.default(configuration?.dummyOutputs ?? 0).toNumber(), 0);
423
- const [stateDiff, chainId] = await Promise.all([
424
- this.nodeClient.getSaplingStateDiff(),
425
- this.nodeClient.getChainId()
426
- ]);
427
- const hexViewingKey = (0, key_1.convertPublicKey)(viewingKey, 'hex', 'saplingViewingKey');
428
- const [inputs, toSpend] = await this.chooseInputs(hexViewingKey.value, stateDiff.commitments_and_ciphertexts, stateDiff.nullifiers, value);
429
- const address = await this.getAddressFromPublicKey(viewingKey).then((address) => TezosSaplingAddress_1.TezosSaplingAddress.fromValue(address.address, address.cursor.diversifierIndex));
430
- const paymentOutput = this.createPaymentOutput(await TezosSaplingAddress_1.TezosSaplingAddress.fromValue(recipient), value);
431
- const paybackOutput = this.createPaybackOutput(address, toSpend, value);
432
- const [dummyInputs, dummyOutputs] = await Promise.all([
433
- Promise.all(Array.from({ length: dummyInputsAmount }, (_v, _k) => this.createDummyInput(address))),
434
- Promise.all(Array.from({ length: dummyOutputsAmount }, (_v, _k) => this.createDummyOutput()))
435
- ]);
436
- return (0, module_kit_1.newUnsignedTransaction)({
437
- ins: inputs.concat(dummyInputs),
438
- outs: [paymentOutput, paybackOutput, ...dummyOutputs].filter((output) => output !== undefined),
439
- contractAddress: this.network.contractAddress,
440
- chainId,
441
- stateDiff,
442
- unshieldTarget: ''
523
+ });
443
524
  });
444
- }
445
- async prepareUnshieldTransaction(viewingKey, details, _configuration) {
446
- if (details.length > 1) {
447
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
448
- }
449
- const recipient = details[0].to;
450
- const value = (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.metadata.units).value;
451
- const burnTransaction = await this.burn(viewingKey, value);
452
- return {
453
- ...burnTransaction,
454
- unshieldTarget: recipient
455
- };
456
- }
457
- async wrapSaplingTransactions(publicKey, transactions, configuration) {
458
- if (this.contract === undefined) {
459
- throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
460
- }
461
- const tezosMetadata = await this.tezos.getMetadata();
462
- const fee = configuration?.fee ? (0, module_kit_1.newAmount)(configuration.fee).blockchain(tezosMetadata.units).value : '0';
463
- const overrideFees = configuration?.fee === undefined;
464
- let operations = [];
465
- if (typeof transactions === 'string' && this.contract.areValidParameters(transactions)) {
466
- const parameters = this.contract.parseParameters(transactions);
467
- operations = [this.prepareTezosOperation(parameters, fee)];
468
- }
469
- else {
470
- const normalizedTransactions = Array.isArray(transactions) ? transactions : [transactions];
471
- const contractCalls = await this.prepareContractCalls(normalizedTransactions);
472
- operations = contractCalls.map((contractCall) => this.prepareTezosOperation(contractCall.toJSON(), fee, contractCall.amount?.toString()));
473
- }
474
- try {
475
- const tezosWrappedOperation = await this.tezos.prepareOperations(publicKey, operations, overrideFees);
476
- const binaryTx = await this.tezos.forgeOperation(tezosWrappedOperation);
477
- return (0, module_kit_1.newUnsignedTransaction)({ binary: binaryTx });
478
- }
479
- catch (error) {
480
- console.error(error);
481
- if (error.code !== undefined && error.code === errors_1.ProtocolErrorType.TRANSACTION_FAILED) {
482
- const rpcErrors = error.data;
483
- const cannotPayStorageFee = rpcErrors.find((error) => error.id.endsWith('.contract.cannot_pay_storage_fee'));
484
- if (cannotPayStorageFee) {
485
- throw new errors_1.BalanceError(coinlib_core_1.Domain.TEZOS, 'Balance too low, cannot pay for storage fee');
525
+ };
526
+ TezosSaplingProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
527
+ return __awaiter(this, void 0, void 0, function () {
528
+ var hexPublicKey, saplingStateDiff, unspends, balance;
529
+ return __generator(this, function (_a) {
530
+ switch (_a.label) {
531
+ case 0:
532
+ if (this.nodeClient === undefined) {
533
+ return [2 /*return*/, { total: (0, module_kit_1.newAmount)(0, 'blockchain') }];
534
+ }
535
+ hexPublicKey = (0, key_1.convertPublicKey)(publicKey, 'hex', 'saplingViewingKey');
536
+ return [4 /*yield*/, this.nodeClient.getSaplingStateDiff()];
537
+ case 1:
538
+ saplingStateDiff = _a.sent();
539
+ return [4 /*yield*/, this.accountant.getUnspends(hexPublicKey.value, saplingStateDiff.commitments_and_ciphertexts, saplingStateDiff.nullifiers)];
540
+ case 2:
541
+ unspends = _a.sent();
542
+ balance = unspends.reduce(function (sum, next) { return sum.plus(next.value); }, new bignumber_1.default(0));
543
+ return [2 /*return*/, { total: (0, module_kit_1.newAmount)(balance, 'blockchain') }];
486
544
  }
487
- const balanceTooLowError = rpcErrors.find((error) => error.id.endsWith('.contract.balance_too_low'));
488
- if (balanceTooLowError) {
489
- throw new errors_1.BalanceError(coinlib_core_1.Domain.TEZOS, 'Balance too low');
545
+ });
546
+ });
547
+ };
548
+ TezosSaplingProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, _to, _configuration) {
549
+ return __awaiter(this, void 0, void 0, function () {
550
+ var balance;
551
+ return __generator(this, function (_a) {
552
+ switch (_a.label) {
553
+ case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
554
+ case 1:
555
+ balance = _a.sent();
556
+ return [2 /*return*/, balance.total];
490
557
  }
491
- }
492
- throw error;
493
- }
494
- }
495
- async mint(recipient, value) {
496
- if (this.nodeClient === undefined || this.network.contractAddress === undefined) {
497
- throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
498
- }
499
- if (!TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
500
- return Promise.reject(`Invalid recipient, expected a 'zet' address, got ${recipient}`);
501
- }
502
- const [saplingStateDiff, chainId] = await Promise.all([
503
- this.nodeClient.getSaplingStateDiff(),
504
- this.nodeClient.getChainId()
505
- ]);
506
- const output = {
507
- address: (await TezosSaplingAddress_1.TezosSaplingAddress.fromValue(recipient)).asString(),
508
- value,
509
- memo: Buffer.alloc(this.memoSize).toString('hex'),
510
- browsable: true
511
- };
512
- const stateTree = await this.state.getStateTreeFromStateDiff(saplingStateDiff, true);
513
- const forgedTransaction = await this.forger.forgeSaplingTransaction([], [output], stateTree, this.getAntiReplay(chainId, this.network.contractAddress));
514
- return this.encoder.encodeTransaction(forgedTransaction).toString('hex');
515
- }
516
- async burn(viewingKey, value) {
517
- if (this.nodeClient === undefined || this.network.contractAddress === undefined) {
518
- throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
519
- }
520
- const [stateDiff, chainId] = await Promise.all([
521
- this.nodeClient.getSaplingStateDiff(),
522
- this.nodeClient.getChainId()
523
- ]);
524
- const hexViewingKey = (0, key_1.convertPublicKey)(viewingKey, 'hex', 'saplingViewingKey');
525
- const [inputs, toSpend] = await this.chooseInputs(hexViewingKey.value, stateDiff.commitments_and_ciphertexts, stateDiff.nullifiers, value);
526
- const paybackOutput = {
527
- address: (await this.getAddressFromPublicKey(viewingKey)).address,
528
- value: toSpend.minus(value).toString(),
529
- memo: Buffer.alloc(this.memoSize).toString('hex'),
530
- browsable: true
531
- };
532
- return (0, module_kit_1.newUnsignedTransaction)({
533
- ins: inputs,
534
- outs: [paybackOutput],
535
- contractAddress: this.network.contractAddress,
536
- chainId,
537
- stateDiff,
538
- unshieldTarget: ''
558
+ });
539
559
  });
540
- }
541
- async chooseInputs(viewingKey, commitmentsWithCiphertext, nullifiers, value) {
542
- const unspends = await this.accountant.getUnspends(viewingKey, commitmentsWithCiphertext, nullifiers);
543
- const balance = this.accountant.sumNotes(unspends);
544
- if (balance.lt(value)) {
545
- return Promise.reject('Not enough balance');
546
- }
547
- const chosenUnspends = [];
548
- let toSpend = new bignumber_1.default(0);
549
- for (const unspend of unspends) {
550
- if (toSpend.gte(value)) {
551
- break;
552
- }
553
- toSpend = toSpend.plus(unspend.value);
554
- chosenUnspends.push(unspend);
555
- }
556
- return [chosenUnspends, toSpend];
557
- }
558
- createPaymentOutput(address, value, memo = Buffer.alloc(this.memoSize)) {
560
+ };
561
+ TezosSaplingProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (_publicKey, _details, _configuration) {
562
+ return __awaiter(this, void 0, void 0, function () {
563
+ return __generator(this, function (_a) {
564
+ return [2 /*return*/, undefined];
565
+ });
566
+ });
567
+ };
568
+ TezosSaplingProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
569
+ return __awaiter(this, void 0, void 0, function () {
570
+ var recipient;
571
+ return __generator(this, function (_a) {
572
+ if (details.length > 1) {
573
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
574
+ }
575
+ recipient = details[0].to;
576
+ if (TezosAddress_1.TezosAddress.isTzAddress(recipient)) {
577
+ return [2 /*return*/, this.prepareUnshieldTransaction(publicKey, details, configuration)];
578
+ }
579
+ else if (TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
580
+ return [2 /*return*/, this.prepareSaplingTransaction(publicKey, details, configuration)];
581
+ }
582
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.TEZOS, "Invalid recpient, expected a 'tz' or 'zet' address, got ".concat(recipient));
583
+ });
584
+ });
585
+ };
586
+ TezosSaplingProtocolImpl.prototype.broadcastTransaction = function (transaction) {
587
+ return __awaiter(this, void 0, void 0, function () {
588
+ var hash, error_1;
589
+ return __generator(this, function (_a) {
590
+ switch (_a.label) {
591
+ case 0:
592
+ if (!this.injectorClient) {
593
+ throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, "Can't broadcast a sapling transaction, an injector service URL or contract address has not be set.");
594
+ }
595
+ _a.label = 1;
596
+ case 1:
597
+ _a.trys.push([1, 3, , 4]);
598
+ return [4 /*yield*/, this.injectorClient.injectTransaction(transaction.binary)];
599
+ case 2:
600
+ hash = _a.sent();
601
+ return [2 /*return*/, hash];
602
+ case 3:
603
+ error_1 = _a.sent();
604
+ throw new errors_1.NetworkError(coinlib_core_1.Domain.TEZOS, error_1);
605
+ case 4: return [2 /*return*/];
606
+ }
607
+ });
608
+ });
609
+ };
610
+ TezosSaplingProtocolImpl.prototype.getInjectorUrl = function () {
611
+ return __awaiter(this, void 0, void 0, function () {
612
+ return __generator(this, function (_a) {
613
+ return [2 /*return*/, this.network.injectorUrl];
614
+ });
615
+ });
616
+ };
617
+ TezosSaplingProtocolImpl.prototype.setInjectorUrl = function (url) {
618
+ return __awaiter(this, void 0, void 0, function () {
619
+ return __generator(this, function (_a) {
620
+ this.network.injectorUrl = url;
621
+ if (this.network.contractAddress !== undefined) {
622
+ this.injectorClient = new TezosSaplingInjectorClient_1.TezosSaplingInjectorClient(url, this.network.contractAddress);
623
+ }
624
+ return [2 /*return*/];
625
+ });
626
+ });
627
+ };
628
+ TezosSaplingProtocolImpl.prototype.initParameters = function (spendParams, outputParams) {
629
+ var _a;
630
+ return __awaiter(this, void 0, void 0, function () {
631
+ var externalInitParameters;
632
+ return __generator(this, function (_b) {
633
+ switch (_b.label) {
634
+ case 0:
635
+ externalInitParameters = this.externalProvider ? (_a = this.externalProvider.initParameters) === null || _a === void 0 ? void 0 : _a.bind(this.externalProvider) : undefined;
636
+ if (!(externalInitParameters !== undefined)) return [3 /*break*/, 2];
637
+ return [4 /*yield*/, externalInitParameters(spendParams, outputParams)];
638
+ case 1:
639
+ _b.sent();
640
+ return [3 /*break*/, 4];
641
+ case 2: return [4 /*yield*/, sapling.initParameters(spendParams, outputParams)];
642
+ case 3:
643
+ _b.sent();
644
+ _b.label = 4;
645
+ case 4: return [2 /*return*/];
646
+ }
647
+ });
648
+ });
649
+ };
650
+ TezosSaplingProtocolImpl.prototype.getAddressFromViewingKey = function (viewingKey, index) {
651
+ return __awaiter(this, void 0, void 0, function () {
652
+ var address;
653
+ return __generator(this, function (_a) {
654
+ switch (_a.label) {
655
+ case 0: return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(viewingKey, index)];
656
+ case 1:
657
+ address = _a.sent();
658
+ return [2 /*return*/, {
659
+ address: address.asString(),
660
+ cursor: {
661
+ hasNext: address.diversifierIndex !== undefined,
662
+ diversifierIndex: address.diversifierIndex
663
+ }
664
+ }];
665
+ }
666
+ });
667
+ });
668
+ };
669
+ TezosSaplingProtocolImpl.prototype.prepareShieldTransaction = function (publicKey, details, configuration) {
670
+ return __awaiter(this, void 0, void 0, function () {
671
+ var recipient, value, encodedTransaction;
672
+ return __generator(this, function (_a) {
673
+ switch (_a.label) {
674
+ case 0:
675
+ if (details.length > 1) {
676
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
677
+ }
678
+ recipient = details[0].to;
679
+ value = (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.metadata.units).value;
680
+ return [4 /*yield*/, this.mint(recipient, value)];
681
+ case 1:
682
+ encodedTransaction = _a.sent();
683
+ return [2 /*return*/, this.wrapSaplingTransactions(publicKey, [encodedTransaction], configuration)];
684
+ }
685
+ });
686
+ });
687
+ };
688
+ TezosSaplingProtocolImpl.prototype.prepareSaplingTransaction = function (viewingKey, details, configuration) {
689
+ var _a, _b;
690
+ return __awaiter(this, void 0, void 0, function () {
691
+ var recipient, value, dummyInputsAmount, dummyOutputsAmount, _c, stateDiff, chainId, hexViewingKey, _d, inputs, toSpend, address, paymentOutput, _e, paybackOutput, _f, dummyInputs, dummyOutputs;
692
+ var _this = this;
693
+ return __generator(this, function (_g) {
694
+ switch (_g.label) {
695
+ case 0:
696
+ if (details.length > 1) {
697
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
698
+ }
699
+ if (this.nodeClient === undefined || this.network.contractAddress === undefined) {
700
+ throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
701
+ }
702
+ recipient = details[0].to;
703
+ value = (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.metadata.units).value;
704
+ if (!TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
705
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.TEZOS, "Invalid recpient, expected a 'zet' address, got ".concat(recipient));
706
+ }
707
+ dummyInputsAmount = Math.max(new bignumber_1.default((_a = configuration === null || configuration === void 0 ? void 0 : configuration.dummyInputs) !== null && _a !== void 0 ? _a : 0).toNumber(), 0);
708
+ dummyOutputsAmount = Math.max(new bignumber_1.default((_b = configuration === null || configuration === void 0 ? void 0 : configuration.dummyOutputs) !== null && _b !== void 0 ? _b : 0).toNumber(), 0);
709
+ return [4 /*yield*/, Promise.all([
710
+ this.nodeClient.getSaplingStateDiff(),
711
+ this.nodeClient.getChainId()
712
+ ])];
713
+ case 1:
714
+ _c = _g.sent(), stateDiff = _c[0], chainId = _c[1];
715
+ hexViewingKey = (0, key_1.convertPublicKey)(viewingKey, 'hex', 'saplingViewingKey');
716
+ return [4 /*yield*/, this.chooseInputs(hexViewingKey.value, stateDiff.commitments_and_ciphertexts, stateDiff.nullifiers, value)];
717
+ case 2:
718
+ _d = _g.sent(), inputs = _d[0], toSpend = _d[1];
719
+ return [4 /*yield*/, this.getAddressFromPublicKey(viewingKey).then(function (address) {
720
+ return TezosSaplingAddress_1.TezosSaplingAddress.fromValue(address.address, address.cursor.diversifierIndex);
721
+ })];
722
+ case 3:
723
+ address = _g.sent();
724
+ _e = this.createPaymentOutput;
725
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromValue(recipient)];
726
+ case 4:
727
+ paymentOutput = _e.apply(this, [_g.sent(), value]);
728
+ paybackOutput = this.createPaybackOutput(address, toSpend, value);
729
+ return [4 /*yield*/, Promise.all([
730
+ Promise.all(Array.from({ length: dummyInputsAmount }, function (_v, _k) { return _this.createDummyInput(address); })),
731
+ Promise.all(Array.from({ length: dummyOutputsAmount }, function (_v, _k) { return _this.createDummyOutput(); }))
732
+ ])];
733
+ case 5:
734
+ _f = _g.sent(), dummyInputs = _f[0], dummyOutputs = _f[1];
735
+ return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
736
+ ins: inputs.concat(dummyInputs),
737
+ outs: __spreadArray([paymentOutput, paybackOutput], dummyOutputs, true).filter(function (output) { return output !== undefined; }),
738
+ contractAddress: this.network.contractAddress,
739
+ chainId: chainId,
740
+ stateDiff: stateDiff,
741
+ unshieldTarget: ''
742
+ })];
743
+ }
744
+ });
745
+ });
746
+ };
747
+ TezosSaplingProtocolImpl.prototype.prepareUnshieldTransaction = function (viewingKey, details, _configuration) {
748
+ return __awaiter(this, void 0, void 0, function () {
749
+ var recipient, value, burnTransaction;
750
+ return __generator(this, function (_a) {
751
+ switch (_a.label) {
752
+ case 0:
753
+ if (details.length > 1) {
754
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.TEZOS, 'Multiple sapling transactions are not supported yet');
755
+ }
756
+ recipient = details[0].to;
757
+ value = (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.metadata.units).value;
758
+ return [4 /*yield*/, this.burn(viewingKey, value)];
759
+ case 1:
760
+ burnTransaction = _a.sent();
761
+ return [2 /*return*/, __assign(__assign({}, burnTransaction), { unshieldTarget: recipient })];
762
+ }
763
+ });
764
+ });
765
+ };
766
+ TezosSaplingProtocolImpl.prototype.wrapSaplingTransactions = function (publicKey, transactions, configuration) {
767
+ return __awaiter(this, void 0, void 0, function () {
768
+ var tezosMetadata, fee, overrideFees, operations, parameters, normalizedTransactions, contractCalls, tezosWrappedOperation, binaryTx, error_2, rpcErrors, cannotPayStorageFee, balanceTooLowError;
769
+ var _this = this;
770
+ return __generator(this, function (_a) {
771
+ switch (_a.label) {
772
+ case 0:
773
+ if (this.contract === undefined) {
774
+ throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
775
+ }
776
+ return [4 /*yield*/, this.tezos.getMetadata()];
777
+ case 1:
778
+ tezosMetadata = _a.sent();
779
+ fee = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) ? (0, module_kit_1.newAmount)(configuration.fee).blockchain(tezosMetadata.units).value : '0';
780
+ overrideFees = (configuration === null || configuration === void 0 ? void 0 : configuration.fee) === undefined;
781
+ operations = [];
782
+ if (!(typeof transactions === 'string' && this.contract.areValidParameters(transactions))) return [3 /*break*/, 2];
783
+ parameters = this.contract.parseParameters(transactions);
784
+ operations = [this.prepareTezosOperation(parameters, fee)];
785
+ return [3 /*break*/, 4];
786
+ case 2:
787
+ normalizedTransactions = Array.isArray(transactions) ? transactions : [transactions];
788
+ return [4 /*yield*/, this.prepareContractCalls(normalizedTransactions)];
789
+ case 3:
790
+ contractCalls = _a.sent();
791
+ operations = contractCalls.map(function (contractCall) { var _a; return _this.prepareTezosOperation(contractCall.toJSON(), fee, (_a = contractCall.amount) === null || _a === void 0 ? void 0 : _a.toString()); });
792
+ _a.label = 4;
793
+ case 4:
794
+ _a.trys.push([4, 7, , 8]);
795
+ return [4 /*yield*/, this.tezos.prepareOperations(publicKey, operations, overrideFees)];
796
+ case 5:
797
+ tezosWrappedOperation = _a.sent();
798
+ return [4 /*yield*/, this.tezos.forgeOperation(tezosWrappedOperation)];
799
+ case 6:
800
+ binaryTx = _a.sent();
801
+ return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({ binary: binaryTx })];
802
+ case 7:
803
+ error_2 = _a.sent();
804
+ console.error(error_2);
805
+ if (error_2.code !== undefined && error_2.code === errors_1.ProtocolErrorType.TRANSACTION_FAILED) {
806
+ rpcErrors = error_2.data;
807
+ cannotPayStorageFee = rpcErrors.find(function (error) { return error.id.endsWith('.contract.cannot_pay_storage_fee'); });
808
+ if (cannotPayStorageFee) {
809
+ throw new errors_1.BalanceError(coinlib_core_1.Domain.TEZOS, 'Balance too low, cannot pay for storage fee');
810
+ }
811
+ balanceTooLowError = rpcErrors.find(function (error) { return error.id.endsWith('.contract.balance_too_low'); });
812
+ if (balanceTooLowError) {
813
+ throw new errors_1.BalanceError(coinlib_core_1.Domain.TEZOS, 'Balance too low');
814
+ }
815
+ }
816
+ throw error_2;
817
+ case 8: return [2 /*return*/];
818
+ }
819
+ });
820
+ });
821
+ };
822
+ TezosSaplingProtocolImpl.prototype.mint = function (recipient, value) {
823
+ return __awaiter(this, void 0, void 0, function () {
824
+ var _a, saplingStateDiff, chainId, output, stateTree, forgedTransaction;
825
+ var _b;
826
+ return __generator(this, function (_c) {
827
+ switch (_c.label) {
828
+ case 0:
829
+ if (this.nodeClient === undefined || this.network.contractAddress === undefined) {
830
+ throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
831
+ }
832
+ if (!TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
833
+ return [2 /*return*/, Promise.reject("Invalid recipient, expected a 'zet' address, got ".concat(recipient))];
834
+ }
835
+ return [4 /*yield*/, Promise.all([
836
+ this.nodeClient.getSaplingStateDiff(),
837
+ this.nodeClient.getChainId()
838
+ ])];
839
+ case 1:
840
+ _a = _c.sent(), saplingStateDiff = _a[0], chainId = _a[1];
841
+ _b = {};
842
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromValue(recipient)];
843
+ case 2:
844
+ output = (_b.address = (_c.sent()).asString(),
845
+ _b.value = value,
846
+ _b.memo = Buffer.alloc(this.memoSize).toString('hex'),
847
+ _b.browsable = true,
848
+ _b);
849
+ return [4 /*yield*/, this.state.getStateTreeFromStateDiff(saplingStateDiff, true)];
850
+ case 3:
851
+ stateTree = _c.sent();
852
+ return [4 /*yield*/, this.forger.forgeSaplingTransaction([], [output], stateTree, this.getAntiReplay(chainId, this.network.contractAddress))];
853
+ case 4:
854
+ forgedTransaction = _c.sent();
855
+ return [2 /*return*/, this.encoder.encodeTransaction(forgedTransaction).toString('hex')];
856
+ }
857
+ });
858
+ });
859
+ };
860
+ TezosSaplingProtocolImpl.prototype.burn = function (viewingKey, value) {
861
+ return __awaiter(this, void 0, void 0, function () {
862
+ var _a, stateDiff, chainId, hexViewingKey, _b, inputs, toSpend, paybackOutput;
863
+ var _c;
864
+ return __generator(this, function (_d) {
865
+ switch (_d.label) {
866
+ case 0:
867
+ if (this.nodeClient === undefined || this.network.contractAddress === undefined) {
868
+ throw new errors_1.PropertyUndefinedError(coinlib_core_1.Domain.TEZOS, 'Contract address not set.');
869
+ }
870
+ return [4 /*yield*/, Promise.all([
871
+ this.nodeClient.getSaplingStateDiff(),
872
+ this.nodeClient.getChainId()
873
+ ])];
874
+ case 1:
875
+ _a = _d.sent(), stateDiff = _a[0], chainId = _a[1];
876
+ hexViewingKey = (0, key_1.convertPublicKey)(viewingKey, 'hex', 'saplingViewingKey');
877
+ return [4 /*yield*/, this.chooseInputs(hexViewingKey.value, stateDiff.commitments_and_ciphertexts, stateDiff.nullifiers, value)];
878
+ case 2:
879
+ _b = _d.sent(), inputs = _b[0], toSpend = _b[1];
880
+ _c = {};
881
+ return [4 /*yield*/, this.getAddressFromPublicKey(viewingKey)];
882
+ case 3:
883
+ paybackOutput = (_c.address = (_d.sent()).address,
884
+ _c.value = toSpend.minus(value).toString(),
885
+ _c.memo = Buffer.alloc(this.memoSize).toString('hex'),
886
+ _c.browsable = true,
887
+ _c);
888
+ return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
889
+ ins: inputs,
890
+ outs: [paybackOutput],
891
+ contractAddress: this.network.contractAddress,
892
+ chainId: chainId,
893
+ stateDiff: stateDiff,
894
+ unshieldTarget: ''
895
+ })];
896
+ }
897
+ });
898
+ });
899
+ };
900
+ TezosSaplingProtocolImpl.prototype.chooseInputs = function (viewingKey, commitmentsWithCiphertext, nullifiers, value) {
901
+ return __awaiter(this, void 0, void 0, function () {
902
+ var unspends, balance, chosenUnspends, toSpend, _i, unspends_1, unspend;
903
+ return __generator(this, function (_a) {
904
+ switch (_a.label) {
905
+ case 0: return [4 /*yield*/, this.accountant.getUnspends(viewingKey, commitmentsWithCiphertext, nullifiers)];
906
+ case 1:
907
+ unspends = _a.sent();
908
+ balance = this.accountant.sumNotes(unspends);
909
+ if (balance.lt(value)) {
910
+ return [2 /*return*/, Promise.reject('Not enough balance')];
911
+ }
912
+ chosenUnspends = [];
913
+ toSpend = new bignumber_1.default(0);
914
+ for (_i = 0, unspends_1 = unspends; _i < unspends_1.length; _i++) {
915
+ unspend = unspends_1[_i];
916
+ if (toSpend.gte(value)) {
917
+ break;
918
+ }
919
+ toSpend = toSpend.plus(unspend.value);
920
+ chosenUnspends.push(unspend);
921
+ }
922
+ return [2 /*return*/, [chosenUnspends, toSpend]];
923
+ }
924
+ });
925
+ });
926
+ };
927
+ TezosSaplingProtocolImpl.prototype.createPaymentOutput = function (address, value, memo) {
928
+ if (memo === void 0) { memo = Buffer.alloc(this.memoSize); }
559
929
  return {
560
930
  address: address.asString(),
561
931
  value: new bignumber_1.default(value).toString(),
562
932
  memo: memo.toString('hex'),
563
933
  browsable: true
564
934
  };
565
- }
566
- createPaybackOutput(address, toSpend, value, memo = Buffer.alloc(this.memoSize)) {
567
- const paybackValue = toSpend.minus(value);
935
+ };
936
+ TezosSaplingProtocolImpl.prototype.createPaybackOutput = function (address, toSpend, value, memo) {
937
+ if (memo === void 0) { memo = Buffer.alloc(this.memoSize); }
938
+ var paybackValue = toSpend.minus(value);
568
939
  return paybackValue.gt(0)
569
940
  ? {
570
941
  address: address.asString(),
@@ -573,48 +944,78 @@ class TezosSaplingProtocolImpl {
573
944
  browsable: true
574
945
  }
575
946
  : undefined;
576
- }
577
- async createDummyInput(address) {
578
- const rcm = await sapling.randR();
579
- return {
580
- rcm: rcm.toString('hex'),
581
- pos: '0',
582
- value: '0',
583
- address: address.asString()
584
- };
585
- }
586
- async createDummyOutput() {
587
- const address = await this.getDummyAddress();
588
- const memo = (0, random_1.randomBytes)(this.memoSize);
589
- return {
590
- address: address.address,
591
- value: '0',
592
- memo: Buffer.from(memo).toString('hex'),
593
- browsable: false
594
- };
595
- }
596
- async getDummyAddress() {
597
- const seed = (0, random_1.randomBytes)(32);
598
- const xfvk = await sapling.getExtendedFullViewingKey(seed, this.metadata.account.standardDerivationPath);
599
- const publicKey = (0, module_kit_1.newPublicKey)(xfvk.toString('hex'), 'hex');
600
- return this.getAddressFromPublicKey(publicKey);
601
- }
602
- createAddressBoundData(address) {
603
- const michelson = MichelsonAddress_1.MichelsonAddress.from((0, pack_1.encodeTzAddress)(address));
947
+ };
948
+ TezosSaplingProtocolImpl.prototype.createDummyInput = function (address) {
949
+ return __awaiter(this, void 0, void 0, function () {
950
+ var rcm;
951
+ return __generator(this, function (_a) {
952
+ switch (_a.label) {
953
+ case 0: return [4 /*yield*/, sapling.randR()];
954
+ case 1:
955
+ rcm = _a.sent();
956
+ return [2 /*return*/, {
957
+ rcm: rcm.toString('hex'),
958
+ pos: '0',
959
+ value: '0',
960
+ address: address.asString()
961
+ }];
962
+ }
963
+ });
964
+ });
965
+ };
966
+ TezosSaplingProtocolImpl.prototype.createDummyOutput = function () {
967
+ return __awaiter(this, void 0, void 0, function () {
968
+ var address, memo;
969
+ return __generator(this, function (_a) {
970
+ switch (_a.label) {
971
+ case 0: return [4 /*yield*/, this.getDummyAddress()];
972
+ case 1:
973
+ address = _a.sent();
974
+ memo = (0, random_1.randomBytes)(this.memoSize);
975
+ return [2 /*return*/, {
976
+ address: address.address,
977
+ value: '0',
978
+ memo: Buffer.from(memo).toString('hex'),
979
+ browsable: false
980
+ }];
981
+ }
982
+ });
983
+ });
984
+ };
985
+ TezosSaplingProtocolImpl.prototype.getDummyAddress = function () {
986
+ return __awaiter(this, void 0, void 0, function () {
987
+ var seed, xfvk, publicKey;
988
+ return __generator(this, function (_a) {
989
+ switch (_a.label) {
990
+ case 0:
991
+ seed = (0, random_1.randomBytes)(32);
992
+ return [4 /*yield*/, sapling.getExtendedFullViewingKey(seed, this.metadata.account.standardDerivationPath)];
993
+ case 1:
994
+ xfvk = _a.sent();
995
+ publicKey = (0, module_kit_1.newPublicKey)(xfvk.toString('hex'), 'hex');
996
+ return [2 /*return*/, this.getAddressFromPublicKey(publicKey)];
997
+ }
998
+ });
999
+ });
1000
+ };
1001
+ TezosSaplingProtocolImpl.prototype.createAddressBoundData = function (address) {
1002
+ var michelson = MichelsonAddress_1.MichelsonAddress.from((0, pack_1.encodeTzAddress)(address));
604
1003
  return (0, pack_1.packMichelsonType)(michelson);
605
- }
606
- getAntiReplay(chainId, contractAddress) {
1004
+ };
1005
+ TezosSaplingProtocolImpl.prototype.getAntiReplay = function (chainId, contractAddress) {
607
1006
  return contractAddress + chainId;
608
- }
609
- prepareTezosOperation(parameters, fee, amount = '0') {
1007
+ };
1008
+ TezosSaplingProtocolImpl.prototype.prepareTezosOperation = function (parameters, fee, amount) {
1009
+ if (amount === void 0) { amount = '0'; }
610
1010
  return {
611
1011
  kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
612
- fee,
613
- amount,
1012
+ fee: fee,
1013
+ amount: amount,
614
1014
  destination: this.network.contractAddress,
615
- parameters
1015
+ parameters: parameters
616
1016
  };
617
- }
618
- }
1017
+ };
1018
+ return TezosSaplingProtocolImpl;
1019
+ }());
619
1020
  exports.TezosSaplingProtocolImpl = TezosSaplingProtocolImpl;
620
1021
  //# sourceMappingURL=TezosSaplingProtocol.js.map