@airgap/tezos 0.13.7-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/LICENSE.md +7 -0
  2. package/actions/GetKtAccountsAction.d.ts +8 -0
  3. package/actions/GetKtAccountsAction.js +85 -0
  4. package/actions/GetKtAccountsAction.js.map +1 -0
  5. package/airgap-coinlib-tezos.min.js +103587 -0
  6. package/constants.d.ts +18 -0
  7. package/constants.js +28 -0
  8. package/constants.js.map +1 -0
  9. package/index.d.ts +46 -0
  10. package/index.js +103 -0
  11. package/index.js.map +1 -0
  12. package/package.json +70 -0
  13. package/protocol/TezosAddress.d.ts +11 -0
  14. package/protocol/TezosAddress.js +102 -0
  15. package/protocol/TezosAddress.js.map +1 -0
  16. package/protocol/TezosCryptoClient.d.ts +15 -0
  17. package/protocol/TezosCryptoClient.js +152 -0
  18. package/protocol/TezosCryptoClient.js.map +1 -0
  19. package/protocol/TezosProtocol.d.ts +349 -0
  20. package/protocol/TezosProtocol.js +1853 -0
  21. package/protocol/TezosProtocol.js.map +1 -0
  22. package/protocol/TezosProtocolOptions.d.ts +29 -0
  23. package/protocol/TezosProtocolOptions.js +114 -0
  24. package/protocol/TezosProtocolOptions.js.map +1 -0
  25. package/protocol/TezosUtils.d.ts +40 -0
  26. package/protocol/TezosUtils.js +296 -0
  27. package/protocol/TezosUtils.js.map +1 -0
  28. package/protocol/contract/TezosContract.d.ts +52 -0
  29. package/protocol/contract/TezosContract.js +509 -0
  30. package/protocol/contract/TezosContract.js.map +1 -0
  31. package/protocol/contract/TezosContractCall.d.ts +10 -0
  32. package/protocol/contract/TezosContractCall.js +23 -0
  33. package/protocol/contract/TezosContractCall.js.map +1 -0
  34. package/protocol/contract/TezosContractEntrypoint.d.ts +8 -0
  35. package/protocol/contract/TezosContractEntrypoint.js +27 -0
  36. package/protocol/contract/TezosContractEntrypoint.js.map +1 -0
  37. package/protocol/contract/TezosContractStorage.d.ts +7 -0
  38. package/protocol/contract/TezosContractStorage.js +16 -0
  39. package/protocol/contract/TezosContractStorage.js.map +1 -0
  40. package/protocol/contract/remote-data/TezosContractRemoteDataFactory.d.ts +11 -0
  41. package/protocol/contract/remote-data/TezosContractRemoteDataFactory.js +34 -0
  42. package/protocol/contract/remote-data/TezosContractRemoteDataFactory.js.map +1 -0
  43. package/protocol/contract/remote-data/TezosStorageRemoteData.d.ts +12 -0
  44. package/protocol/contract/remote-data/TezosStorageRemoteData.js +151 -0
  45. package/protocol/contract/remote-data/TezosStorageRemoteData.js.map +1 -0
  46. package/protocol/domains/TezosDomains.d.ts +20 -0
  47. package/protocol/domains/TezosDomains.js +306 -0
  48. package/protocol/domains/TezosDomains.js.map +1 -0
  49. package/protocol/fa/TezosBTC.d.ts +12 -0
  50. package/protocol/fa/TezosBTC.js +107 -0
  51. package/protocol/fa/TezosBTC.js.map +1 -0
  52. package/protocol/fa/TezosBTCtez.d.ts +10 -0
  53. package/protocol/fa/TezosBTCtez.js +54 -0
  54. package/protocol/fa/TezosBTCtez.js.map +1 -0
  55. package/protocol/fa/TezosCTez.d.ts +10 -0
  56. package/protocol/fa/TezosCTez.js +51 -0
  57. package/protocol/fa/TezosCTez.js.map +1 -0
  58. package/protocol/fa/TezosDOGA.d.ts +10 -0
  59. package/protocol/fa/TezosDOGA.js +51 -0
  60. package/protocol/fa/TezosDOGA.js.map +1 -0
  61. package/protocol/fa/TezosETHtz.d.ts +9 -0
  62. package/protocol/fa/TezosETHtz.js +72 -0
  63. package/protocol/fa/TezosETHtz.js.map +1 -0
  64. package/protocol/fa/TezosFA1Protocol.d.ts +27 -0
  65. package/protocol/fa/TezosFA1Protocol.js +310 -0
  66. package/protocol/fa/TezosFA1Protocol.js.map +1 -0
  67. package/protocol/fa/TezosFA1p2Protocol.d.ts +8 -0
  68. package/protocol/fa/TezosFA1p2Protocol.js +117 -0
  69. package/protocol/fa/TezosFA1p2Protocol.js.map +1 -0
  70. package/protocol/fa/TezosFA2Protocol.d.ts +58 -0
  71. package/protocol/fa/TezosFA2Protocol.js +449 -0
  72. package/protocol/fa/TezosFA2Protocol.js.map +1 -0
  73. package/protocol/fa/TezosFAProtocol.d.ts +65 -0
  74. package/protocol/fa/TezosFAProtocol.js +510 -0
  75. package/protocol/fa/TezosFAProtocol.js.map +1 -0
  76. package/protocol/fa/TezosFAProtocolOptions.d.ts +54 -0
  77. package/protocol/fa/TezosFAProtocolOptions.js +228 -0
  78. package/protocol/fa/TezosFAProtocolOptions.js.map +1 -0
  79. package/protocol/fa/TezosKolibriUSD.d.ts +10 -0
  80. package/protocol/fa/TezosKolibriUSD.js +74 -0
  81. package/protocol/fa/TezosKolibriUSD.js.map +1 -0
  82. package/protocol/fa/TezosPlanty.d.ts +10 -0
  83. package/protocol/fa/TezosPlanty.js +51 -0
  84. package/protocol/fa/TezosPlanty.js.map +1 -0
  85. package/protocol/fa/TezosQUIPU.d.ts +10 -0
  86. package/protocol/fa/TezosQUIPU.js +54 -0
  87. package/protocol/fa/TezosQUIPU.js.map +1 -0
  88. package/protocol/fa/TezosSIRS.d.ts +10 -0
  89. package/protocol/fa/TezosSIRS.js +51 -0
  90. package/protocol/fa/TezosSIRS.js.map +1 -0
  91. package/protocol/fa/TezosStaker.d.ts +10 -0
  92. package/protocol/fa/TezosStaker.js +74 -0
  93. package/protocol/fa/TezosStaker.js.map +1 -0
  94. package/protocol/fa/TezosUBTC.d.ts +10 -0
  95. package/protocol/fa/TezosUBTC.js +54 -0
  96. package/protocol/fa/TezosUBTC.js.map +1 -0
  97. package/protocol/fa/TezosUDEFI.d.ts +10 -0
  98. package/protocol/fa/TezosUDEFI.js +54 -0
  99. package/protocol/fa/TezosUDEFI.js.map +1 -0
  100. package/protocol/fa/TezosUSD.d.ts +10 -0
  101. package/protocol/fa/TezosUSD.js +74 -0
  102. package/protocol/fa/TezosUSD.js.map +1 -0
  103. package/protocol/fa/TezosUSDT.d.ts +10 -0
  104. package/protocol/fa/TezosUSDT.js +54 -0
  105. package/protocol/fa/TezosUSDT.js.map +1 -0
  106. package/protocol/fa/TezosUUSD.d.ts +6 -0
  107. package/protocol/fa/TezosUUSD.js +31 -0
  108. package/protocol/fa/TezosUUSD.js.map +1 -0
  109. package/protocol/fa/TezosWRAP.d.ts +10 -0
  110. package/protocol/fa/TezosWRAP.js +54 -0
  111. package/protocol/fa/TezosWRAP.js.map +1 -0
  112. package/protocol/fa/TezosWrapped.d.ts +10 -0
  113. package/protocol/fa/TezosWrapped.js +74 -0
  114. package/protocol/fa/TezosWrapped.js.map +1 -0
  115. package/protocol/fa/TezosYOU.d.ts +6 -0
  116. package/protocol/fa/TezosYOU.js +31 -0
  117. package/protocol/fa/TezosYOU.js.map +1 -0
  118. package/protocol/indexerClient/TezosIndexerClient.d.ts +25 -0
  119. package/protocol/indexerClient/TezosIndexerClient.js +251 -0
  120. package/protocol/indexerClient/TezosIndexerClient.js.map +1 -0
  121. package/protocol/indexerClient/TezosProtocolIndexerClient.d.ts +26 -0
  122. package/protocol/indexerClient/TezosProtocolIndexerClient.js +3 -0
  123. package/protocol/indexerClient/TezosProtocolIndexerClient.js.map +1 -0
  124. package/protocol/kt/TezosKtAddress.d.ts +5 -0
  125. package/protocol/kt/TezosKtAddress.js +72 -0
  126. package/protocol/kt/TezosKtAddress.js.map +1 -0
  127. package/protocol/kt/TezosKtProtocol.d.ts +30 -0
  128. package/protocol/kt/TezosKtProtocol.js +317 -0
  129. package/protocol/kt/TezosKtProtocol.js.map +1 -0
  130. package/protocol/sapling/TezosSaplingAddress.d.ts +12 -0
  131. package/protocol/sapling/TezosSaplingAddress.js +134 -0
  132. package/protocol/sapling/TezosSaplingAddress.js.map +1 -0
  133. package/protocol/sapling/TezosSaplingCryptoClient.d.ts +34 -0
  134. package/protocol/sapling/TezosSaplingCryptoClient.js +241 -0
  135. package/protocol/sapling/TezosSaplingCryptoClient.js.map +1 -0
  136. package/protocol/sapling/TezosSaplingProtocol.d.ts +130 -0
  137. package/protocol/sapling/TezosSaplingProtocol.js +1101 -0
  138. package/protocol/sapling/TezosSaplingProtocol.js.map +1 -0
  139. package/protocol/sapling/TezosSaplingProtocolOptions.d.ts +43 -0
  140. package/protocol/sapling/TezosSaplingProtocolOptions.js +78 -0
  141. package/protocol/sapling/TezosSaplingProtocolOptions.js.map +1 -0
  142. package/protocol/sapling/TezosShieldedTezProtocol.d.ts +9 -0
  143. package/protocol/sapling/TezosShieldedTezProtocol.js +109 -0
  144. package/protocol/sapling/TezosShieldedTezProtocol.js.map +1 -0
  145. package/protocol/sapling/node/TezosSaplingNodeClient.d.ts +8 -0
  146. package/protocol/sapling/node/TezosSaplingNodeClient.js +78 -0
  147. package/protocol/sapling/node/TezosSaplingNodeClient.js.map +1 -0
  148. package/protocol/sapling/utils/TezosSaplingBookkeeper.d.ts +34 -0
  149. package/protocol/sapling/utils/TezosSaplingBookkeeper.js +586 -0
  150. package/protocol/sapling/utils/TezosSaplingBookkeeper.js.map +1 -0
  151. package/protocol/sapling/utils/TezosSaplingEncoder.d.ts +22 -0
  152. package/protocol/sapling/utils/TezosSaplingEncoder.js +158 -0
  153. package/protocol/sapling/utils/TezosSaplingEncoder.js.map +1 -0
  154. package/protocol/sapling/utils/TezosSaplingForger.d.ts +26 -0
  155. package/protocol/sapling/utils/TezosSaplingForger.js +278 -0
  156. package/protocol/sapling/utils/TezosSaplingForger.js.map +1 -0
  157. package/protocol/sapling/utils/TezosSaplingState.d.ts +17 -0
  158. package/protocol/sapling/utils/TezosSaplingState.js +260 -0
  159. package/protocol/sapling/utils/TezosSaplingState.js.map +1 -0
  160. package/protocol/types/TezosAddressCursor.d.ts +3 -0
  161. package/protocol/types/TezosAddressCursor.js +3 -0
  162. package/protocol/types/TezosAddressCursor.js.map +1 -0
  163. package/protocol/types/TezosAddressResult.d.ts +4 -0
  164. package/protocol/types/TezosAddressResult.js +3 -0
  165. package/protocol/types/TezosAddressResult.js.map +1 -0
  166. package/protocol/types/TezosBlockHeader.d.ts +13 -0
  167. package/protocol/types/TezosBlockHeader.js +3 -0
  168. package/protocol/types/TezosBlockHeader.js.map +1 -0
  169. package/protocol/types/TezosBlockMetadata.d.ts +7 -0
  170. package/protocol/types/TezosBlockMetadata.js +3 -0
  171. package/protocol/types/TezosBlockMetadata.js.map +1 -0
  172. package/protocol/types/TezosContractCode.d.ts +5 -0
  173. package/protocol/types/TezosContractCode.js +3 -0
  174. package/protocol/types/TezosContractCode.js.map +1 -0
  175. package/protocol/types/TezosOperationType.d.ts +13 -0
  176. package/protocol/types/TezosOperationType.js +18 -0
  177. package/protocol/types/TezosOperationType.js.map +1 -0
  178. package/protocol/types/TezosTransactionCursor.d.ts +3 -0
  179. package/protocol/types/TezosTransactionCursor.js +3 -0
  180. package/protocol/types/TezosTransactionCursor.js.map +1 -0
  181. package/protocol/types/TezosTransactionResult.d.ts +6 -0
  182. package/protocol/types/TezosTransactionResult.js +3 -0
  183. package/protocol/types/TezosTransactionResult.js.map +1 -0
  184. package/protocol/types/TezosWrappedOperation.d.ts +5 -0
  185. package/protocol/types/TezosWrappedOperation.js +3 -0
  186. package/protocol/types/TezosWrappedOperation.js.map +1 -0
  187. package/protocol/types/contract/BigMap.d.ts +7 -0
  188. package/protocol/types/contract/BigMap.js +3 -0
  189. package/protocol/types/contract/BigMap.js.map +1 -0
  190. package/protocol/types/contract/BigMapEnrtyFilter.d.ts +5 -0
  191. package/protocol/types/contract/BigMapEnrtyFilter.js +3 -0
  192. package/protocol/types/contract/BigMapEnrtyFilter.js.map +1 -0
  193. package/protocol/types/contract/BigMapEntry.d.ts +7 -0
  194. package/protocol/types/contract/BigMapEntry.js +3 -0
  195. package/protocol/types/contract/BigMapEntry.js.map +1 -0
  196. package/protocol/types/contract/BigMapRequest.d.ts +8 -0
  197. package/protocol/types/contract/BigMapRequest.js +3 -0
  198. package/protocol/types/contract/BigMapRequest.js.map +1 -0
  199. package/protocol/types/contract/TezosContractMetadata.d.ts +61 -0
  200. package/protocol/types/contract/TezosContractMetadata.js +3 -0
  201. package/protocol/types/contract/TezosContractMetadata.js.map +1 -0
  202. package/protocol/types/domains/TezosDomainsRecord.d.ts +8 -0
  203. package/protocol/types/domains/TezosDomainsRecord.js +3 -0
  204. package/protocol/types/domains/TezosDomainsRecord.js.map +1 -0
  205. package/protocol/types/domains/TezosDomainsReverseRecord.d.ts +5 -0
  206. package/protocol/types/domains/TezosDomainsReverseRecord.js +3 -0
  207. package/protocol/types/domains/TezosDomainsReverseRecord.js.map +1 -0
  208. package/protocol/types/fa/TezosFA2BalanceOfRequest.d.ts +4 -0
  209. package/protocol/types/fa/TezosFA2BalanceOfRequest.js +3 -0
  210. package/protocol/types/fa/TezosFA2BalanceOfRequest.js.map +1 -0
  211. package/protocol/types/fa/TezosFA2BalanceOfResponse.d.ts +5 -0
  212. package/protocol/types/fa/TezosFA2BalanceOfResponse.js +3 -0
  213. package/protocol/types/fa/TezosFA2BalanceOfResponse.js.map +1 -0
  214. package/protocol/types/fa/TezosFA2TransferRequest.d.ts +8 -0
  215. package/protocol/types/fa/TezosFA2TransferRequest.js +3 -0
  216. package/protocol/types/fa/TezosFA2TransferRequest.js.map +1 -0
  217. package/protocol/types/fa/TezosFA2UpdateOperatorRequest.d.ts +6 -0
  218. package/protocol/types/fa/TezosFA2UpdateOperatorRequest.js +3 -0
  219. package/protocol/types/fa/TezosFA2UpdateOperatorRequest.js.map +1 -0
  220. package/protocol/types/fa/TezosFATokenMetadata.d.ts +6 -0
  221. package/protocol/types/fa/TezosFATokenMetadata.js +3 -0
  222. package/protocol/types/fa/TezosFATokenMetadata.js.map +1 -0
  223. package/protocol/types/kt/TezosKtAddressCursor.d.ts +4 -0
  224. package/protocol/types/kt/TezosKtAddressCursor.js +3 -0
  225. package/protocol/types/kt/TezosKtAddressCursor.js.map +1 -0
  226. package/protocol/types/kt/TezosKtAddressResult.d.ts +5 -0
  227. package/protocol/types/kt/TezosKtAddressResult.js +3 -0
  228. package/protocol/types/kt/TezosKtAddressResult.js.map +1 -0
  229. package/protocol/types/micheline/MichelineNode.d.ts +15 -0
  230. package/protocol/types/micheline/MichelineNode.js +5 -0
  231. package/protocol/types/micheline/MichelineNode.js.map +1 -0
  232. package/protocol/types/micheline/MichelineNodeUtils.d.ts +6 -0
  233. package/protocol/types/micheline/MichelineNodeUtils.js +40 -0
  234. package/protocol/types/micheline/MichelineNodeUtils.js.map +1 -0
  235. package/protocol/types/michelson/MichelsonType.d.ts +11 -0
  236. package/protocol/types/michelson/MichelsonType.js +22 -0
  237. package/protocol/types/michelson/MichelsonType.js.map +1 -0
  238. package/protocol/types/michelson/MichelsonTypeMeta.d.ts +33 -0
  239. package/protocol/types/michelson/MichelsonTypeMeta.js +132 -0
  240. package/protocol/types/michelson/MichelsonTypeMeta.js.map +1 -0
  241. package/protocol/types/michelson/MichelsonTypeUtils.d.ts +19 -0
  242. package/protocol/types/michelson/MichelsonTypeUtils.js +249 -0
  243. package/protocol/types/michelson/MichelsonTypeUtils.js.map +1 -0
  244. package/protocol/types/michelson/generics/MichelsonList.d.ts +11 -0
  245. package/protocol/types/michelson/generics/MichelsonList.js +68 -0
  246. package/protocol/types/michelson/generics/MichelsonList.js.map +1 -0
  247. package/protocol/types/michelson/generics/MichelsonMap.d.ts +14 -0
  248. package/protocol/types/michelson/generics/MichelsonMap.js +118 -0
  249. package/protocol/types/michelson/generics/MichelsonMap.js.map +1 -0
  250. package/protocol/types/michelson/generics/MichelsonOption.d.ts +25 -0
  251. package/protocol/types/michelson/generics/MichelsonOption.js +119 -0
  252. package/protocol/types/michelson/generics/MichelsonOption.js.map +1 -0
  253. package/protocol/types/michelson/generics/MichelsonOr.d.ts +25 -0
  254. package/protocol/types/michelson/generics/MichelsonOr.js +132 -0
  255. package/protocol/types/michelson/generics/MichelsonOr.js.map +1 -0
  256. package/protocol/types/michelson/generics/MichelsonPair.d.ts +17 -0
  257. package/protocol/types/michelson/generics/MichelsonPair.js +135 -0
  258. package/protocol/types/michelson/generics/MichelsonPair.js.map +1 -0
  259. package/protocol/types/michelson/grammar/MichelsonGrammarData.d.ts +2 -0
  260. package/protocol/types/michelson/grammar/MichelsonGrammarData.js +4 -0
  261. package/protocol/types/michelson/grammar/MichelsonGrammarData.js.map +1 -0
  262. package/protocol/types/michelson/grammar/MichelsonGrammarInstruction.d.ts +1 -0
  263. package/protocol/types/michelson/grammar/MichelsonGrammarInstruction.js +4 -0
  264. package/protocol/types/michelson/grammar/MichelsonGrammarInstruction.js.map +1 -0
  265. package/protocol/types/michelson/grammar/MichelsonGrammarType.d.ts +1 -0
  266. package/protocol/types/michelson/grammar/MichelsonGrammarType.js +4 -0
  267. package/protocol/types/michelson/grammar/MichelsonGrammarType.js.map +1 -0
  268. package/protocol/types/michelson/primitives/MichelsonAddress.d.ts +15 -0
  269. package/protocol/types/michelson/primitives/MichelsonAddress.js +72 -0
  270. package/protocol/types/michelson/primitives/MichelsonAddress.js.map +1 -0
  271. package/protocol/types/michelson/primitives/MichelsonBool.d.ts +12 -0
  272. package/protocol/types/michelson/primitives/MichelsonBool.js +57 -0
  273. package/protocol/types/michelson/primitives/MichelsonBool.js.map +1 -0
  274. package/protocol/types/michelson/primitives/MichelsonBytes.d.ts +14 -0
  275. package/protocol/types/michelson/primitives/MichelsonBytes.js +75 -0
  276. package/protocol/types/michelson/primitives/MichelsonBytes.js.map +1 -0
  277. package/protocol/types/michelson/primitives/MichelsonInt.d.ts +14 -0
  278. package/protocol/types/michelson/primitives/MichelsonInt.js +72 -0
  279. package/protocol/types/michelson/primitives/MichelsonInt.js.map +1 -0
  280. package/protocol/types/michelson/primitives/MichelsonString.d.ts +14 -0
  281. package/protocol/types/michelson/primitives/MichelsonString.js +74 -0
  282. package/protocol/types/michelson/primitives/MichelsonString.js.map +1 -0
  283. package/protocol/types/michelson/primitives/MichelsonUnit.d.ts +9 -0
  284. package/protocol/types/michelson/primitives/MichelsonUnit.js +53 -0
  285. package/protocol/types/michelson/primitives/MichelsonUnit.js.map +1 -0
  286. package/protocol/types/operations/ActivateAccount.d.ts +7 -0
  287. package/protocol/types/operations/ActivateAccount.js +3 -0
  288. package/protocol/types/operations/ActivateAccount.js.map +1 -0
  289. package/protocol/types/operations/Ballot.d.ts +9 -0
  290. package/protocol/types/operations/Ballot.js +3 -0
  291. package/protocol/types/operations/Ballot.js.map +1 -0
  292. package/protocol/types/operations/Delegation.d.ts +11 -0
  293. package/protocol/types/operations/Delegation.js +3 -0
  294. package/protocol/types/operations/Delegation.js.map +1 -0
  295. package/protocol/types/operations/DoubleBakingEvidence.d.ts +8 -0
  296. package/protocol/types/operations/DoubleBakingEvidence.js +3 -0
  297. package/protocol/types/operations/DoubleBakingEvidence.js.map +1 -0
  298. package/protocol/types/operations/DoubleEndorsementEvidence.d.ts +16 -0
  299. package/protocol/types/operations/DoubleEndorsementEvidence.js +3 -0
  300. package/protocol/types/operations/DoubleEndorsementEvidence.js.map +1 -0
  301. package/protocol/types/operations/Endorsement.d.ts +6 -0
  302. package/protocol/types/operations/Endorsement.js +3 -0
  303. package/protocol/types/operations/Endorsement.js.map +1 -0
  304. package/protocol/types/operations/Origination.d.ts +13 -0
  305. package/protocol/types/operations/Origination.js +3 -0
  306. package/protocol/types/operations/Origination.js.map +1 -0
  307. package/protocol/types/operations/Proposal.d.ts +7 -0
  308. package/protocol/types/operations/Proposal.js +3 -0
  309. package/protocol/types/operations/Proposal.js.map +1 -0
  310. package/protocol/types/operations/Reveal.d.ts +11 -0
  311. package/protocol/types/operations/Reveal.js +3 -0
  312. package/protocol/types/operations/Reveal.js.map +1 -0
  313. package/protocol/types/operations/SeedNonceRevelation.d.ts +7 -0
  314. package/protocol/types/operations/SeedNonceRevelation.js +3 -0
  315. package/protocol/types/operations/SeedNonceRevelation.js.map +1 -0
  316. package/protocol/types/operations/TezosOperation.d.ts +4 -0
  317. package/protocol/types/operations/TezosOperation.js +3 -0
  318. package/protocol/types/operations/TezosOperation.js.map +1 -0
  319. package/protocol/types/operations/Transaction.d.ts +23 -0
  320. package/protocol/types/operations/Transaction.js +3 -0
  321. package/protocol/types/operations/Transaction.js.map +1 -0
  322. package/protocol/types/sapling/TezosSaplingAddressCursor.d.ts +4 -0
  323. package/protocol/types/sapling/TezosSaplingAddressCursor.js +3 -0
  324. package/protocol/types/sapling/TezosSaplingAddressCursor.js.map +1 -0
  325. package/protocol/types/sapling/TezosSaplingAddressResult.d.ts +4 -0
  326. package/protocol/types/sapling/TezosSaplingAddressResult.js +3 -0
  327. package/protocol/types/sapling/TezosSaplingAddressResult.js.map +1 -0
  328. package/protocol/types/sapling/TezosSaplingCiphertext.d.ts +8 -0
  329. package/protocol/types/sapling/TezosSaplingCiphertext.js +3 -0
  330. package/protocol/types/sapling/TezosSaplingCiphertext.js.map +1 -0
  331. package/protocol/types/sapling/TezosSaplingInput.d.ts +6 -0
  332. package/protocol/types/sapling/TezosSaplingInput.js +3 -0
  333. package/protocol/types/sapling/TezosSaplingInput.js.map +1 -0
  334. package/protocol/types/sapling/TezosSaplingOutput.d.ts +6 -0
  335. package/protocol/types/sapling/TezosSaplingOutput.js +3 -0
  336. package/protocol/types/sapling/TezosSaplingOutput.js.map +1 -0
  337. package/protocol/types/sapling/TezosSaplingStateDiff.d.ts +6 -0
  338. package/protocol/types/sapling/TezosSaplingStateDiff.js +3 -0
  339. package/protocol/types/sapling/TezosSaplingStateDiff.js.map +1 -0
  340. package/protocol/types/sapling/TezosSaplingStateTree.d.ts +7 -0
  341. package/protocol/types/sapling/TezosSaplingStateTree.js +3 -0
  342. package/protocol/types/sapling/TezosSaplingStateTree.js.map +1 -0
  343. package/protocol/types/sapling/TezosSaplingTransaction.d.ts +23 -0
  344. package/protocol/types/sapling/TezosSaplingTransaction.js +3 -0
  345. package/protocol/types/sapling/TezosSaplingTransaction.js.map +1 -0
  346. package/protocol/types/sapling/TezosSaplingTransactionCursor.d.ts +3 -0
  347. package/protocol/types/sapling/TezosSaplingTransactionCursor.js +3 -0
  348. package/protocol/types/sapling/TezosSaplingTransactionCursor.js.map +1 -0
  349. package/protocol/types/sapling/TezosSaplingTransactionResult.d.ts +6 -0
  350. package/protocol/types/sapling/TezosSaplingTransactionResult.js +3 -0
  351. package/protocol/types/sapling/TezosSaplingTransactionResult.js.map +1 -0
  352. package/protocol/types/utils.d.ts +8 -0
  353. package/protocol/types/utils.js +41 -0
  354. package/protocol/types/utils.js.map +1 -0
  355. package/readme.md +121 -0
  356. package/types/signed-transaction-tezos-sapling.d.ts +3 -0
  357. package/types/signed-transaction-tezos-sapling.js +3 -0
  358. package/types/signed-transaction-tezos-sapling.js.map +1 -0
  359. package/types/signed-transaction-tezos.d.ts +5 -0
  360. package/types/signed-transaction-tezos.js +3 -0
  361. package/types/signed-transaction-tezos.js.map +1 -0
  362. package/types/transaction-tezos.d.ts +14 -0
  363. package/types/transaction-tezos.js +3 -0
  364. package/types/transaction-tezos.js.map +1 -0
  365. package/types/unsigned-transaction-tezos-sapling.d.ts +38 -0
  366. package/types/unsigned-transaction-tezos-sapling.js +3 -0
  367. package/types/unsigned-transaction-tezos-sapling.js.map +1 -0
  368. package/types/unsigned-transaction-tezos.d.ts +8 -0
  369. package/types/unsigned-transaction-tezos.js +3 -0
  370. package/types/unsigned-transaction-tezos.js.map +1 -0
@@ -0,0 +1,1101 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
29
+ }) : (function(o, m, k, k2) {
30
+ if (k2 === undefined) k2 = k;
31
+ o[k2] = m[k];
32
+ }));
33
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
34
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
35
+ }) : function(o, v) {
36
+ o["default"] = v;
37
+ });
38
+ var __importStar = (this && this.__importStar) || function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
46
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
+ return new (P || (P = Promise))(function (resolve, reject) {
48
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
49
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
50
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
51
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
52
+ });
53
+ };
54
+ var __generator = (this && this.__generator) || function (thisArg, body) {
55
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
56
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
57
+ function verb(n) { return function (v) { return step([n, v]); }; }
58
+ function step(op) {
59
+ if (f) throw new TypeError("Generator is already executing.");
60
+ while (_) try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
62
+ if (y = 0, t) op = [op[0] & 2, t.value];
63
+ switch (op[0]) {
64
+ case 0: case 1: t = op; break;
65
+ case 4: _.label++; return { value: op[1], done: false };
66
+ case 5: _.label++; y = op[1]; op = [0]; continue;
67
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
68
+ default:
69
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
70
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
71
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
72
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
73
+ if (t[2]) _.ops.pop();
74
+ _.trys.pop(); continue;
75
+ }
76
+ op = body.call(thisArg, _);
77
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
78
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
79
+ }
80
+ };
81
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
82
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
83
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
84
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
85
+ r[k] = a[j];
86
+ return r;
87
+ };
88
+ var __importDefault = (this && this.__importDefault) || function (mod) {
89
+ return (mod && mod.__esModule) ? mod : { "default": mod };
90
+ };
91
+ Object.defineProperty(exports, "__esModule", { value: true });
92
+ exports.TezosSaplingProtocol = void 0;
93
+ var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
94
+ var bip39_2_5_0_1 = require("@airgap/coinlib-core/dependencies/src/bip39-2.5.0");
95
+ var errors_1 = require("@airgap/coinlib-core/errors");
96
+ var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
97
+ var NonExtendedProtocol_1 = require("@airgap/coinlib-core/protocols/NonExtendedProtocol");
98
+ var array_1 = require("@airgap/coinlib-core/utils/array");
99
+ var sapling = __importStar(require("@airgap/sapling-wasm"));
100
+ var random_1 = require("@stablelib/random");
101
+ var TezosContract_1 = require("../contract/TezosContract");
102
+ var TezosAddress_1 = require("../TezosAddress");
103
+ var TezosProtocol_1 = require("../TezosProtocol");
104
+ var TezosProtocolOptions_1 = require("../TezosProtocolOptions");
105
+ var TezosUtils_1 = require("../TezosUtils");
106
+ var MichelsonAddress_1 = require("../types/michelson/primitives/MichelsonAddress");
107
+ var TezosOperationType_1 = require("../types/TezosOperationType");
108
+ var TezosSaplingNodeClient_1 = require("./node/TezosSaplingNodeClient");
109
+ var TezosSaplingAddress_1 = require("./TezosSaplingAddress");
110
+ var TezosSaplingCryptoClient_1 = require("./TezosSaplingCryptoClient");
111
+ var TezosSaplingBookkeeper_1 = require("./utils/TezosSaplingBookkeeper");
112
+ var TezosSaplingEncoder_1 = require("./utils/TezosSaplingEncoder");
113
+ var TezosSaplingForger_1 = require("./utils/TezosSaplingForger");
114
+ var TezosSaplingState_1 = require("./utils/TezosSaplingState");
115
+ var TezosSaplingProtocol = /** @class */ (function (_super) {
116
+ __extends(TezosSaplingProtocol, _super);
117
+ function TezosSaplingProtocol(options) {
118
+ var _a, _b, _c, _d, _e, _f;
119
+ var _this = _super.call(this) || this;
120
+ _this.options = options;
121
+ _this.supportsHD = false;
122
+ _this.addressIsCaseSensitive = true;
123
+ _this.addressValidationPattern = '^(zet1[1-9A-Za-z]{65}|tz1[1-9A-Za-z]{33})$';
124
+ _this.addressPlaceholder = 'zet1...';
125
+ _this.tezosProtocol = new TezosProtocol_1.TezosProtocol(new TezosProtocolOptions_1.TezosProtocolOptions(_this.options.network, new TezosProtocolOptions_1.TezosProtocolConfig()));
126
+ _this.name = options.config.name;
127
+ _this.symbol = (_a = options.config.symbol) !== null && _a !== void 0 ? _a : _this.tezosProtocol.symbol;
128
+ _this.marketSymbol = (_b = options.config.marketSymbol) !== null && _b !== void 0 ? _b : _this.tezosProtocol.marketSymbol;
129
+ _this.feeSymbol = _this.tezosProtocol.feeSymbol;
130
+ _this.feeDefaults = (_c = options.config.feeDefaults) !== null && _c !== void 0 ? _c : _this.tezosProtocol.feeDefaults;
131
+ _this.decimals = (_d = options.config.decimals) !== null && _d !== void 0 ? _d : _this.tezosProtocol.decimals;
132
+ _this.feeDecimals = _this.tezosProtocol.feeDecimals;
133
+ _this.identifier = (_e = options.config.identifier) !== null && _e !== void 0 ? _e : _this.tezosProtocol.identifier;
134
+ _this.units = (_f = _this.options.config.units) !== null && _f !== void 0 ? _f : _this.tezosProtocol.units;
135
+ _this.standardDerivationPath = _this.tezosProtocol.standardDerivationPath;
136
+ _this.cryptoClient = new TezosSaplingCryptoClient_1.TezosSaplingCryptoClient(_this.tezosProtocol.cryptoClient);
137
+ _this.nodeClient = new TezosSaplingNodeClient_1.TezosSaplingNodeClient(_this.options.network.rpcUrl, _this.options.config.contractAddress);
138
+ _this.contract = new TezosContract_1.TezosContract(_this.options.config.contractAddress, _this.options.network);
139
+ _this.state = new TezosSaplingState_1.TezosSaplingState(_this.options.config.merkleTreeHeight);
140
+ _this.encoder = new TezosSaplingEncoder_1.TezosSaplingEncoder();
141
+ _this.forger = new TezosSaplingForger_1.TezosSaplingForger(_this.cryptoClient, _this.state, _this.encoder, _this.options.config.externalProvider);
142
+ _this.bookkeeper = new TezosSaplingBookkeeper_1.TezosSaplingBookkeeper(_this.identifier, _this.options.network, _this.cryptoClient, _this.encoder);
143
+ return _this;
144
+ }
145
+ TezosSaplingProtocol.prototype.getSymbol = function () {
146
+ return __awaiter(this, void 0, void 0, function () {
147
+ return __generator(this, function (_a) {
148
+ return [2 /*return*/, this.symbol];
149
+ });
150
+ });
151
+ };
152
+ TezosSaplingProtocol.prototype.getName = function () {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ return __generator(this, function (_a) {
155
+ return [2 /*return*/, this.name];
156
+ });
157
+ });
158
+ };
159
+ TezosSaplingProtocol.prototype.getMarketSymbol = function () {
160
+ return __awaiter(this, void 0, void 0, function () {
161
+ return __generator(this, function (_a) {
162
+ return [2 /*return*/, this.marketSymbol];
163
+ });
164
+ });
165
+ };
166
+ TezosSaplingProtocol.prototype.getFeeSymbol = function () {
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ return __generator(this, function (_a) {
169
+ return [2 /*return*/, this.feeSymbol];
170
+ });
171
+ });
172
+ };
173
+ TezosSaplingProtocol.prototype.getDecimals = function () {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ return __generator(this, function (_a) {
176
+ return [2 /*return*/, this.decimals];
177
+ });
178
+ });
179
+ };
180
+ TezosSaplingProtocol.prototype.getFeeDecimals = function () {
181
+ return __awaiter(this, void 0, void 0, function () {
182
+ return __generator(this, function (_a) {
183
+ return [2 /*return*/, this.feeDecimals];
184
+ });
185
+ });
186
+ };
187
+ TezosSaplingProtocol.prototype.getIdentifier = function () {
188
+ return __awaiter(this, void 0, void 0, function () {
189
+ return __generator(this, function (_a) {
190
+ return [2 /*return*/, this.identifier];
191
+ });
192
+ });
193
+ };
194
+ TezosSaplingProtocol.prototype.getFeeDefaults = function () {
195
+ return __awaiter(this, void 0, void 0, function () {
196
+ return __generator(this, function (_a) {
197
+ return [2 /*return*/, this.feeDefaults];
198
+ });
199
+ });
200
+ };
201
+ TezosSaplingProtocol.prototype.getUnits = function () {
202
+ return __awaiter(this, void 0, void 0, function () {
203
+ return __generator(this, function (_a) {
204
+ return [2 /*return*/, this.units];
205
+ });
206
+ });
207
+ };
208
+ TezosSaplingProtocol.prototype.getSupportsHD = function () {
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ return __generator(this, function (_a) {
211
+ return [2 /*return*/, this.supportsHD];
212
+ });
213
+ });
214
+ };
215
+ TezosSaplingProtocol.prototype.getStandardDerivationPath = function () {
216
+ return __awaiter(this, void 0, void 0, function () {
217
+ return __generator(this, function (_a) {
218
+ return [2 /*return*/, this.standardDerivationPath];
219
+ });
220
+ });
221
+ };
222
+ TezosSaplingProtocol.prototype.getAddressIsCaseSensitive = function () {
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ return __generator(this, function (_a) {
225
+ return [2 /*return*/, this.addressIsCaseSensitive];
226
+ });
227
+ });
228
+ };
229
+ TezosSaplingProtocol.prototype.getAddressValidationPattern = function () {
230
+ return __awaiter(this, void 0, void 0, function () {
231
+ return __generator(this, function (_a) {
232
+ return [2 /*return*/, this.addressValidationPattern];
233
+ });
234
+ });
235
+ };
236
+ TezosSaplingProtocol.prototype.getAddressPlaceholder = function () {
237
+ return __awaiter(this, void 0, void 0, function () {
238
+ return __generator(this, function (_a) {
239
+ return [2 /*return*/, this.addressPlaceholder];
240
+ });
241
+ });
242
+ };
243
+ TezosSaplingProtocol.prototype.getOptions = function () {
244
+ return __awaiter(this, void 0, void 0, function () {
245
+ return __generator(this, function (_a) {
246
+ return [2 /*return*/, this.options];
247
+ });
248
+ });
249
+ };
250
+ TezosSaplingProtocol.prototype.initParameters = function (spendParams, outputParams) {
251
+ var _a;
252
+ return __awaiter(this, void 0, void 0, function () {
253
+ var externalInitParameters;
254
+ return __generator(this, function (_b) {
255
+ switch (_b.label) {
256
+ case 0:
257
+ externalInitParameters = (_a = this.options.config.externalProvider) === null || _a === void 0 ? void 0 : _a.initParameters;
258
+ if (!(externalInitParameters !== undefined)) return [3 /*break*/, 2];
259
+ return [4 /*yield*/, externalInitParameters(spendParams, outputParams)];
260
+ case 1:
261
+ _b.sent();
262
+ return [3 /*break*/, 4];
263
+ case 2: return [4 /*yield*/, sapling.initParameters(spendParams, outputParams)];
264
+ case 3:
265
+ _b.sent();
266
+ _b.label = 4;
267
+ case 4: return [2 /*return*/];
268
+ }
269
+ });
270
+ });
271
+ };
272
+ TezosSaplingProtocol.prototype.getBlockExplorerLinkForTxId = function (txId) {
273
+ return __awaiter(this, void 0, void 0, function () {
274
+ return __generator(this, function (_a) {
275
+ return [2 /*return*/, this.tezosProtocol.getBlockExplorerLinkForTxId(txId)];
276
+ });
277
+ });
278
+ };
279
+ TezosSaplingProtocol.prototype.getPublicKeyFromMnemonic = function (mnemonic, derivationPath, password) {
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ var seed;
282
+ return __generator(this, function (_a) {
283
+ seed = this.getSeedFromMnemonic(mnemonic, password);
284
+ return [2 /*return*/, this.getPublicKeyFromHexSecret(seed.toString('hex'), derivationPath)];
285
+ });
286
+ });
287
+ };
288
+ TezosSaplingProtocol.prototype.getPrivateKeyFromMnemonic = function (mnemonic, derivationPath, password) {
289
+ return __awaiter(this, void 0, void 0, function () {
290
+ var seed;
291
+ return __generator(this, function (_a) {
292
+ seed = this.getSeedFromMnemonic(mnemonic, password);
293
+ return [2 /*return*/, this.getPrivateKeyFromHexSecret(seed.toString('hex'), derivationPath)];
294
+ });
295
+ });
296
+ };
297
+ TezosSaplingProtocol.prototype.getSeedFromMnemonic = function (mnemonic, password) {
298
+ var seed = bip39_2_5_0_1.mnemonicToSeed(mnemonic, password);
299
+ // We xor the two halves of the BIP-39 seed, as does `tezos-client`
300
+ var first32 = seed.slice(0, 32);
301
+ var second32 = seed.slice(32);
302
+ return Buffer.from(first32.map(function (byte, index) { return byte ^ second32[index]; }));
303
+ };
304
+ TezosSaplingProtocol.prototype.getPublicKeyFromHexSecret = function (secret, derivationPath) {
305
+ return __awaiter(this, void 0, void 0, function () {
306
+ var viewingKey;
307
+ return __generator(this, function (_a) {
308
+ switch (_a.label) {
309
+ case 0: return [4 /*yield*/, sapling.getExtendedFullViewingKey(secret, derivationPath)];
310
+ case 1:
311
+ viewingKey = _a.sent();
312
+ return [2 /*return*/, viewingKey.toString('hex')];
313
+ }
314
+ });
315
+ });
316
+ };
317
+ TezosSaplingProtocol.prototype.getPrivateKeyFromHexSecret = function (secret, derivationPath) {
318
+ return __awaiter(this, void 0, void 0, function () {
319
+ var xsk;
320
+ return __generator(this, function (_a) {
321
+ switch (_a.label) {
322
+ case 0: return [4 /*yield*/, sapling.getExtendedSpendingKey(secret, derivationPath)];
323
+ case 1:
324
+ xsk = _a.sent();
325
+ return [2 /*return*/, xsk.toString('hex')];
326
+ }
327
+ });
328
+ });
329
+ };
330
+ TezosSaplingProtocol.prototype.getAddressFromPublicKey = function (viewingKey, cursor) {
331
+ return __awaiter(this, void 0, void 0, function () {
332
+ var current, _a, address, _b;
333
+ return __generator(this, function (_c) {
334
+ switch (_c.label) {
335
+ case 0:
336
+ if (!((cursor === null || cursor === void 0 ? void 0 : cursor.hasNext) && (cursor === null || cursor === void 0 ? void 0 : cursor.diversifierIndex))) return [3 /*break*/, 2];
337
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(viewingKey, cursor.diversifierIndex)];
338
+ case 1:
339
+ _a = _c.sent();
340
+ return [3 /*break*/, 3];
341
+ case 2:
342
+ _a = undefined;
343
+ _c.label = 3;
344
+ case 3:
345
+ current = _a;
346
+ if (!current) return [3 /*break*/, 5];
347
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.next(viewingKey, current)];
348
+ case 4:
349
+ _b = _c.sent();
350
+ return [3 /*break*/, 7];
351
+ case 5: return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(viewingKey)];
352
+ case 6:
353
+ _b = _c.sent();
354
+ _c.label = 7;
355
+ case 7:
356
+ address = _b;
357
+ return [2 /*return*/, {
358
+ address: address.asString(),
359
+ cursor: {
360
+ hasNext: address.diversifierIndex !== undefined,
361
+ diversifierIndex: address.diversifierIndex
362
+ }
363
+ }];
364
+ }
365
+ });
366
+ });
367
+ };
368
+ TezosSaplingProtocol.prototype.getAddressesFromPublicKey = function (viewingKey, cursor) {
369
+ return __awaiter(this, void 0, void 0, function () {
370
+ return __generator(this, function (_a) {
371
+ switch (_a.label) {
372
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(viewingKey, cursor)];
373
+ case 1: return [2 /*return*/, [_a.sent()]];
374
+ }
375
+ });
376
+ });
377
+ };
378
+ TezosSaplingProtocol.prototype.getAddressFromViewingKey = function (viewingKey, index) {
379
+ return __awaiter(this, void 0, void 0, function () {
380
+ var address;
381
+ return __generator(this, function (_a) {
382
+ switch (_a.label) {
383
+ case 0: return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromViewingKey(viewingKey, index)];
384
+ case 1:
385
+ address = _a.sent();
386
+ return [2 /*return*/, {
387
+ address: address.asString(),
388
+ cursor: {
389
+ hasNext: address.diversifierIndex !== undefined,
390
+ diversifierIndex: address.diversifierIndex
391
+ }
392
+ }];
393
+ }
394
+ });
395
+ });
396
+ };
397
+ TezosSaplingProtocol.prototype.getTransactionsFromPublicKey = function (publicKey, limit, cursor) {
398
+ var _a;
399
+ return __awaiter(this, void 0, void 0, function () {
400
+ var saplingStateDiff, incoming, outgoing, page, pageStart, pageEnd, commitmentsAndCiphertexts, inputs, airGapIncoming, airGapOutgoing;
401
+ var _this = this;
402
+ return __generator(this, function (_b) {
403
+ switch (_b.label) {
404
+ case 0: return [4 /*yield*/, this.nodeClient.getSaplingStateDiff()];
405
+ case 1:
406
+ saplingStateDiff = _b.sent();
407
+ incoming = [];
408
+ outgoing = [];
409
+ page = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.page) !== null && _a !== void 0 ? _a : 0;
410
+ pageStart = page * limit;
411
+ pageEnd = pageStart + limit;
412
+ _b.label = 2;
413
+ case 2:
414
+ if (!(incoming.length + outgoing.length < limit && pageStart < saplingStateDiff.commitments_and_ciphertexts.length)) return [3 /*break*/, 4];
415
+ commitmentsAndCiphertexts = saplingStateDiff.commitments_and_ciphertexts
416
+ .map(function (_a, index) {
417
+ var commitment = _a[0], ciphertext = _a[1];
418
+ return [commitment, ciphertext, new bignumber_1.default(index)];
419
+ })
420
+ .reverse()
421
+ .slice(pageStart, pageEnd);
422
+ return [4 /*yield*/, Promise.all([
423
+ this.bookkeeper.getIncomingInputs(publicKey, commitmentsAndCiphertexts),
424
+ this.bookkeeper.getOutgoingInputs(publicKey, commitmentsAndCiphertexts)
425
+ ])];
426
+ case 3:
427
+ inputs = _b.sent();
428
+ incoming.push.apply(incoming, inputs[0]);
429
+ outgoing.push.apply(outgoing, inputs[1]);
430
+ page += 1;
431
+ pageStart += limit;
432
+ pageEnd += limit;
433
+ return [3 /*break*/, 2];
434
+ case 4: return [4 /*yield*/, Promise.all(incoming.map(function (input) { return __awaiter(_this, void 0, void 0, function () {
435
+ return __generator(this, function (_a) {
436
+ return [2 /*return*/, ({
437
+ from: ['Shielded Pool'],
438
+ to: [input.address],
439
+ isInbound: true,
440
+ amount: input.value,
441
+ fee: '0',
442
+ protocolIdentifier: this.identifier,
443
+ network: this.options.network
444
+ })];
445
+ });
446
+ }); }))];
447
+ case 5:
448
+ airGapIncoming = _b.sent();
449
+ return [4 /*yield*/, Promise.all(outgoing.map(function (input) { return __awaiter(_this, void 0, void 0, function () {
450
+ var _a;
451
+ return __generator(this, function (_b) {
452
+ switch (_b.label) {
453
+ case 0:
454
+ _a = {};
455
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
456
+ case 1: return [2 /*return*/, (_a.from = [(_b.sent()).address],
457
+ _a.to = [input.address],
458
+ _a.isInbound = false,
459
+ _a.amount = input.value,
460
+ _a.fee = '0',
461
+ _a.protocolIdentifier = this.identifier,
462
+ _a.network = this.options.network,
463
+ _a)];
464
+ }
465
+ });
466
+ }); }))];
467
+ case 6:
468
+ airGapOutgoing = _b.sent();
469
+ return [2 /*return*/, {
470
+ transactions: airGapIncoming.concat(airGapOutgoing),
471
+ cursor: { page: page + 1 }
472
+ }];
473
+ }
474
+ });
475
+ });
476
+ };
477
+ TezosSaplingProtocol.prototype.signWithPrivateKey = function (privateKey, transaction) {
478
+ return __awaiter(this, void 0, void 0, function () {
479
+ var stateTree, boundData, forgedTransaction;
480
+ return __generator(this, function (_a) {
481
+ switch (_a.label) {
482
+ case 0: return [4 /*yield*/, this.state.getStateTreeFromStateDiff(transaction.stateDiff)];
483
+ case 1:
484
+ stateTree = _a.sent();
485
+ boundData = transaction.unshieldTarget && transaction.unshieldTarget.length > 0
486
+ ? this.createAddressBoundData(transaction.unshieldTarget)
487
+ : undefined;
488
+ return [4 /*yield*/, this.forger.forgeSaplingTransaction(transaction.ins, transaction.outs, stateTree, this.getAntiReplay(transaction.chainId, transaction.contractAddress), boundData, Buffer.from(privateKey, 'hex'))];
489
+ case 2:
490
+ forgedTransaction = _a.sent();
491
+ return [2 /*return*/, this.encoder.encodeTransaction(forgedTransaction).toString('hex')];
492
+ }
493
+ });
494
+ });
495
+ };
496
+ TezosSaplingProtocol.prototype.getTransactionDetails = function (transaction, data) {
497
+ return __awaiter(this, void 0, void 0, function () {
498
+ var tx, airGapTxs, unshieldTarget, from, details, wrappedOperation, _a, _b, _c;
499
+ return __generator(this, function (_d) {
500
+ switch (_d.label) {
501
+ case 0:
502
+ tx = transaction.transaction;
503
+ airGapTxs = [];
504
+ if (!this.isRawTezosSaplingTransaction(tx)) return [3 /*break*/, 2];
505
+ unshieldTarget = tx.unshieldTarget.length > 0 ? tx.unshieldTarget : undefined;
506
+ return [4 /*yield*/, this.getAddressFromPublicKey(transaction.publicKey).then(function (address) { return TezosSaplingAddress_1.TezosSaplingAddress.fromValue(address.address, address.cursor.diversifierIndex); })];
507
+ case 1:
508
+ from = _d.sent();
509
+ details = this.bookkeeper
510
+ .getUnsignedTransactionDetails(from, tx.ins, tx.outs, unshieldTarget)
511
+ .map(function (details) { return (__assign(__assign({}, details), { extra: __assign(__assign({}, details.extra), { destination: tx.contractAddress, chainId: tx.chainId }), transactionDetails: tx })); });
512
+ airGapTxs.push.apply(airGapTxs, details);
513
+ return [3 /*break*/, 5];
514
+ case 2: return [4 /*yield*/, this.tezosProtocol.unforgeUnsignedTezosWrappedOperation(tx.binaryTransaction)];
515
+ case 3:
516
+ wrappedOperation = _d.sent();
517
+ _b = (_a = airGapTxs.push).apply;
518
+ _c = [airGapTxs];
519
+ return [4 /*yield*/, this.getTransactionDetailsFromWrappedOperation(wrappedOperation, data === null || data === void 0 ? void 0 : data.knownViewingKeys)];
520
+ case 4:
521
+ _b.apply(_a, _c.concat([(_d.sent())]));
522
+ _d.label = 5;
523
+ case 5: return [2 /*return*/, this.filterOutPaybacks(airGapTxs)];
524
+ }
525
+ });
526
+ });
527
+ };
528
+ TezosSaplingProtocol.prototype.getTransactionDetailsFromSigned = function (transaction, data) {
529
+ return __awaiter(this, void 0, void 0, function () {
530
+ var airGapTxs, tx, defaultDetails, partialDetails, wrappedOperation, _a, _b, _c, _d, partialDetails;
531
+ return __generator(this, function (_e) {
532
+ switch (_e.label) {
533
+ case 0:
534
+ airGapTxs = [];
535
+ tx = transaction.transaction;
536
+ defaultDetails = {
537
+ from: ['Shielded Pool'],
538
+ to: ['Shielded Pool'],
539
+ isInbound: false,
540
+ amount: '0',
541
+ fee: '0',
542
+ protocolIdentifier: this.identifier,
543
+ network: this.options.network
544
+ };
545
+ if (!this.contract.areValidParameters(tx)) return [3 /*break*/, 2];
546
+ return [4 /*yield*/, this.getPartialDetailsFromContractParameters(tx, data === null || data === void 0 ? void 0 : data.knownViewingKeys)];
547
+ case 1:
548
+ partialDetails = _e.sent();
549
+ airGapTxs.push.apply(airGapTxs, partialDetails.map(function (partial) { return (__assign(__assign({}, defaultDetails), partial)); }));
550
+ return [3 /*break*/, 7];
551
+ case 2:
552
+ _e.trys.push([2, 5, , 7]);
553
+ return [4 /*yield*/, this.tezosProtocol.unforgeSignedTezosWrappedOperation(tx)];
554
+ case 3:
555
+ wrappedOperation = _e.sent();
556
+ _b = (_a = airGapTxs.push).apply;
557
+ _c = [airGapTxs];
558
+ return [4 /*yield*/, this.getTransactionDetailsFromWrappedOperation(wrappedOperation, data === null || data === void 0 ? void 0 : data.knownViewingKeys)];
559
+ case 4:
560
+ _b.apply(_a, _c.concat([(_e.sent())]));
561
+ return [3 /*break*/, 7];
562
+ case 5:
563
+ _d = _e.sent();
564
+ return [4 /*yield*/, this.bookkeeper.getTransactionsPartialDetails([tx], data === null || data === void 0 ? void 0 : data.knownViewingKeys)];
565
+ case 6:
566
+ partialDetails = _e.sent();
567
+ airGapTxs.push.apply(airGapTxs, partialDetails.map(function (partial) { return (__assign(__assign({}, defaultDetails), partial)); }));
568
+ return [3 /*break*/, 7];
569
+ case 7: return [2 /*return*/, this.filterOutPaybacks(airGapTxs)];
570
+ }
571
+ });
572
+ });
573
+ };
574
+ TezosSaplingProtocol.prototype.getTransactionDetailsFromWrappedOperation = function (operation, knownViewingKeys) {
575
+ if (knownViewingKeys === void 0) { knownViewingKeys = []; }
576
+ return __awaiter(this, void 0, void 0, function () {
577
+ var contractOperations, details;
578
+ var _this = this;
579
+ return __generator(this, function (_a) {
580
+ switch (_a.label) {
581
+ case 0:
582
+ contractOperations = operation.contents.filter(function (content) {
583
+ return content.kind === TezosOperationType_1.TezosOperationType.TRANSACTION && content.parameters !== undefined;
584
+ });
585
+ return [4 /*yield*/, Promise.all(contractOperations.map(function (operation) { return __awaiter(_this, void 0, void 0, function () {
586
+ var saplingDetails;
587
+ var _this = this;
588
+ return __generator(this, function (_a) {
589
+ switch (_a.label) {
590
+ case 0: return [4 /*yield*/, this.getPartialDetailsFromContractParameters(operation.parameters, knownViewingKeys)];
591
+ case 1:
592
+ saplingDetails = _a.sent();
593
+ return [2 /*return*/, saplingDetails.map(function (partials) { return (__assign(__assign({ from: [operation.source], to: ['Shielded Pool'], isInbound: false, amount: operation.amount, fee: operation.fee, protocolIdentifier: _this.identifier, network: _this.options.network }, partials), { transactionDetails: operation })); })];
594
+ }
595
+ });
596
+ }); }))];
597
+ case 1:
598
+ details = _a.sent();
599
+ return [2 /*return*/, array_1.flattenArray(details)];
600
+ }
601
+ });
602
+ });
603
+ };
604
+ TezosSaplingProtocol.prototype.getPartialDetailsFromContractParameters = function (rawOrParsed, knownViewingKeys) {
605
+ if (knownViewingKeys === void 0) { knownViewingKeys = []; }
606
+ return __awaiter(this, void 0, void 0, function () {
607
+ var parameters, txs;
608
+ return __generator(this, function (_a) {
609
+ switch (_a.label) {
610
+ case 0:
611
+ parameters = typeof rawOrParsed === 'string' ? this.contract.parseParameters(rawOrParsed) : rawOrParsed;
612
+ return [4 /*yield*/, this.parseParameters(parameters)];
613
+ case 1:
614
+ txs = _a.sent();
615
+ return [2 /*return*/, this.bookkeeper.getTransactionsPartialDetails(txs, knownViewingKeys)];
616
+ }
617
+ });
618
+ });
619
+ };
620
+ TezosSaplingProtocol.prototype.filterOutPaybacks = function (airGapTxs) {
621
+ var filtered = airGapTxs.filter(function (details) {
622
+ if (details.from.length !== details.to.length) {
623
+ return true;
624
+ }
625
+ var fromSet = new Set(details.from);
626
+ var toSet = new Set(details.to);
627
+ return Array.from(fromSet).some(function (address) { return !toSet.has(address); });
628
+ });
629
+ return filtered.length > 0 ? filtered : airGapTxs;
630
+ };
631
+ TezosSaplingProtocol.prototype.getBalanceOfPublicKey = function (publicKey) {
632
+ return __awaiter(this, void 0, void 0, function () {
633
+ var saplingStateDiff, unspends, balance;
634
+ return __generator(this, function (_a) {
635
+ switch (_a.label) {
636
+ case 0: return [4 /*yield*/, this.nodeClient.getSaplingStateDiff()];
637
+ case 1:
638
+ saplingStateDiff = _a.sent();
639
+ return [4 /*yield*/, this.bookkeeper.getUnspends(publicKey, saplingStateDiff.commitments_and_ciphertexts, saplingStateDiff.nullifiers)];
640
+ case 2:
641
+ unspends = _a.sent();
642
+ balance = unspends.reduce(function (sum, next) { return sum.plus(next.value); }, new bignumber_1.default(0));
643
+ return [2 /*return*/, balance.toString()];
644
+ }
645
+ });
646
+ });
647
+ };
648
+ TezosSaplingProtocol.prototype.getTransactionStatuses = function (transactionHash) {
649
+ return __awaiter(this, void 0, void 0, function () {
650
+ return __generator(this, function (_a) {
651
+ throw new Error('Method not implemented.');
652
+ });
653
+ });
654
+ };
655
+ TezosSaplingProtocol.prototype.estimateMaxTransactionValueFromPublicKey = function (publicKey, recipients, fee) {
656
+ return __awaiter(this, void 0, void 0, function () {
657
+ return __generator(this, function (_a) {
658
+ return [2 /*return*/, this.getBalanceOfPublicKey(publicKey)];
659
+ });
660
+ });
661
+ };
662
+ TezosSaplingProtocol.prototype.prepareTransactionFromPublicKey = function (publicKey, recipients, values, fee, data) {
663
+ return __awaiter(this, void 0, void 0, function () {
664
+ var recipient, value;
665
+ return __generator(this, function (_a) {
666
+ if (recipients.length > 1 && values.length > 1) {
667
+ return [2 /*return*/, Promise.reject('Multiple sapling transactions are not supported')];
668
+ }
669
+ if (recipients.length === 0 && values.length === 0) {
670
+ return [2 /*return*/, Promise.reject('No recpients and values have been provided')];
671
+ }
672
+ recipient = recipients[0];
673
+ value = values[0];
674
+ if (TezosAddress_1.TezosAddress.isTzAddress(recipient)) {
675
+ return [2 /*return*/, this.prepareUnshieldTransaction(publicKey, recipient, value, data)];
676
+ }
677
+ else if (TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
678
+ return [2 /*return*/, this.prepareSaplingTransaction(publicKey, recipient, value, data)];
679
+ }
680
+ return [2 /*return*/, Promise.reject("Invalid recpient, expected a 'tz' or 'zet' address, got " + recipient)];
681
+ });
682
+ });
683
+ };
684
+ TezosSaplingProtocol.prototype.wrapSaplingTransactions = function (publicKey, transactionsOrString, fee, overrideFees) {
685
+ if (overrideFees === void 0) { overrideFees = false; }
686
+ return __awaiter(this, void 0, void 0, function () {
687
+ var operations, parameters, transactions, contractCalls, tezosWrappedOperation, binaryTx, error_1, rpcErrors, cannotPayStorageFee, balanceTooLowError;
688
+ var _this = this;
689
+ return __generator(this, function (_a) {
690
+ switch (_a.label) {
691
+ case 0:
692
+ if (!(typeof transactionsOrString === 'string' && this.contract.areValidParameters(transactionsOrString))) return [3 /*break*/, 1];
693
+ parameters = this.contract.parseParameters(transactionsOrString);
694
+ operations = [this.prepareTezosOperation(parameters, fee)];
695
+ return [3 /*break*/, 3];
696
+ case 1:
697
+ transactions = Array.isArray(transactionsOrString) ? transactionsOrString : [transactionsOrString];
698
+ return [4 /*yield*/, this.prepareContractCalls(transactions)];
699
+ case 2:
700
+ contractCalls = _a.sent();
701
+ operations = contractCalls.map(function (contractCall) { var _a; return _this.prepareTezosOperation(contractCall.toJSON(), fee, (_a = contractCall.amount) === null || _a === void 0 ? void 0 : _a.toString()); });
702
+ _a.label = 3;
703
+ case 3:
704
+ _a.trys.push([3, 6, , 7]);
705
+ return [4 /*yield*/, this.tezosProtocol.prepareOperations(publicKey, operations, overrideFees)];
706
+ case 4:
707
+ tezosWrappedOperation = _a.sent();
708
+ return [4 /*yield*/, this.tezosProtocol.forgeTezosOperation(tezosWrappedOperation)];
709
+ case 5:
710
+ binaryTx = _a.sent();
711
+ return [2 /*return*/, { binaryTransaction: binaryTx }];
712
+ case 6:
713
+ error_1 = _a.sent();
714
+ console.error(error_1);
715
+ if (error_1.code !== undefined && error_1.code === errors_1.ProtocolErrorType.TRANSACTION_FAILED) {
716
+ rpcErrors = error_1.data;
717
+ cannotPayStorageFee = rpcErrors.find(function (error) { return error.id.endsWith('.contract.cannot_pay_storage_fee'); });
718
+ if (cannotPayStorageFee) {
719
+ throw new errors_1.BalanceError(coinlib_error_1.Domain.TEZOS, 'Balance too low, cannot pay for storage fee');
720
+ }
721
+ balanceTooLowError = rpcErrors.find(function (error) { return error.id.endsWith('.contract.balance_too_low'); });
722
+ if (balanceTooLowError) {
723
+ throw new errors_1.BalanceError(coinlib_error_1.Domain.TEZOS, 'Balance too low');
724
+ }
725
+ }
726
+ throw error_1;
727
+ case 7: return [2 /*return*/];
728
+ }
729
+ });
730
+ });
731
+ };
732
+ TezosSaplingProtocol.prototype.prepareTezosOperation = function (parameters, fee, amount) {
733
+ if (amount === void 0) { amount = '0'; }
734
+ return {
735
+ kind: TezosOperationType_1.TezosOperationType.TRANSACTION,
736
+ fee: fee,
737
+ amount: amount,
738
+ destination: this.options.config.contractAddress,
739
+ parameters: parameters
740
+ };
741
+ };
742
+ TezosSaplingProtocol.prototype.prepareShieldTransaction = function (publicKey, recipient, value, fee, data) {
743
+ return __awaiter(this, void 0, void 0, function () {
744
+ var encodedTransaction;
745
+ return __generator(this, function (_a) {
746
+ switch (_a.label) {
747
+ case 0: return [4 /*yield*/, this.mint(recipient, value)];
748
+ case 1:
749
+ encodedTransaction = _a.sent();
750
+ return [2 /*return*/, this.wrapSaplingTransactions(publicKey, [encodedTransaction], fee, data === null || data === void 0 ? void 0 : data.overrideFees)];
751
+ }
752
+ });
753
+ });
754
+ };
755
+ TezosSaplingProtocol.prototype.prepareUnshieldTransaction = function (viewingKey, recipient, value, data) {
756
+ return __awaiter(this, void 0, void 0, function () {
757
+ var burnTransaction;
758
+ return __generator(this, function (_a) {
759
+ switch (_a.label) {
760
+ case 0:
761
+ if (!TezosAddress_1.TezosAddress.isTzAddress(recipient)) {
762
+ return [2 /*return*/, Promise.reject("Invalid recpient, expected a 'tz' address, got " + recipient)];
763
+ }
764
+ return [4 /*yield*/, this.burn(viewingKey, value)];
765
+ case 1:
766
+ burnTransaction = _a.sent();
767
+ return [2 /*return*/, __assign(__assign({}, burnTransaction), { unshieldTarget: recipient })];
768
+ }
769
+ });
770
+ });
771
+ };
772
+ TezosSaplingProtocol.prototype.prepareSaplingTransaction = function (viewingKey, recipient, value, data) {
773
+ var _a, _b;
774
+ return __awaiter(this, void 0, void 0, function () {
775
+ var dummyInputsAmount, dummyOutputsAmount, _c, stateDiff, chainId, _d, inputs, toSpend, address, paymentOutput, _e, paybackOutput, _f, dummyInputs, dummyOutputs;
776
+ var _this = this;
777
+ return __generator(this, function (_g) {
778
+ switch (_g.label) {
779
+ case 0:
780
+ if (!TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
781
+ return [2 /*return*/, Promise.reject("Invalid recpient, expected a 'zet' address, got " + recipient)];
782
+ }
783
+ dummyInputsAmount = Math.max(new bignumber_1.default((_a = data === null || data === void 0 ? void 0 : data.dummyInputs) !== null && _a !== void 0 ? _a : 0).toNumber(), 0);
784
+ dummyOutputsAmount = Math.max(new bignumber_1.default((_b = data === null || data === void 0 ? void 0 : data.dummyOutputs) !== null && _b !== void 0 ? _b : 0).toNumber(), 0);
785
+ return [4 /*yield*/, Promise.all([
786
+ this.nodeClient.getSaplingStateDiff(),
787
+ this.nodeClient.getChainId()
788
+ ])];
789
+ case 1:
790
+ _c = _g.sent(), stateDiff = _c[0], chainId = _c[1];
791
+ return [4 /*yield*/, this.chooseInputs(viewingKey, stateDiff.commitments_and_ciphertexts, stateDiff.nullifiers, value)];
792
+ case 2:
793
+ _d = _g.sent(), inputs = _d[0], toSpend = _d[1];
794
+ return [4 /*yield*/, this.getAddressFromPublicKey(viewingKey).then(function (address) {
795
+ return TezosSaplingAddress_1.TezosSaplingAddress.fromValue(address.address, address.cursor.diversifierIndex);
796
+ })];
797
+ case 3:
798
+ address = _g.sent();
799
+ _e = this.createPaymentOutput;
800
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromValue(recipient)];
801
+ case 4:
802
+ paymentOutput = _e.apply(this, [_g.sent(), value]);
803
+ paybackOutput = this.createPaybackOutput(address, toSpend, value);
804
+ return [4 /*yield*/, Promise.all([
805
+ Promise.all(Array.from({ length: dummyInputsAmount }, function (_v, _k) { return _this.createDummyInput(address); })),
806
+ Promise.all(Array.from({ length: dummyOutputsAmount }, function (_v, _k) { return _this.createDummyOutput(); }))
807
+ ])];
808
+ case 5:
809
+ _f = _g.sent(), dummyInputs = _f[0], dummyOutputs = _f[1];
810
+ return [2 /*return*/, {
811
+ ins: inputs.concat(dummyInputs),
812
+ outs: __spreadArrays([paymentOutput, paybackOutput], dummyOutputs).filter(function (output) { return output !== undefined; }),
813
+ contractAddress: this.options.config.contractAddress,
814
+ chainId: chainId,
815
+ stateDiff: stateDiff,
816
+ unshieldTarget: ''
817
+ }];
818
+ }
819
+ });
820
+ });
821
+ };
822
+ TezosSaplingProtocol.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 (!TezosSaplingAddress_1.TezosSaplingAddress.isZetAddress(recipient)) {
830
+ return [2 /*return*/, Promise.reject("Invalid recipient, expected a 'zet' address, got " + recipient)];
831
+ }
832
+ return [4 /*yield*/, Promise.all([
833
+ this.nodeClient.getSaplingStateDiff(),
834
+ this.nodeClient.getChainId()
835
+ ])];
836
+ case 1:
837
+ _a = _c.sent(), saplingStateDiff = _a[0], chainId = _a[1];
838
+ _b = {};
839
+ return [4 /*yield*/, TezosSaplingAddress_1.TezosSaplingAddress.fromValue(recipient)];
840
+ case 2:
841
+ output = (_b.address = (_c.sent()).asString(),
842
+ _b.value = value,
843
+ _b.memo = Buffer.alloc(this.options.config.memoSize).toString('hex'),
844
+ _b.browsable = true,
845
+ _b);
846
+ return [4 /*yield*/, this.state.getStateTreeFromStateDiff(saplingStateDiff, true)];
847
+ case 3:
848
+ stateTree = _c.sent();
849
+ return [4 /*yield*/, this.forger.forgeSaplingTransaction([], [output], stateTree, this.getAntiReplay(chainId))];
850
+ case 4:
851
+ forgedTransaction = _c.sent();
852
+ return [2 /*return*/, this.encoder.encodeTransaction(forgedTransaction).toString('hex')];
853
+ }
854
+ });
855
+ });
856
+ };
857
+ TezosSaplingProtocol.prototype.burn = function (viewingKey, value) {
858
+ return __awaiter(this, void 0, void 0, function () {
859
+ var _a, stateDiff, chainId, _b, inputs, toSpend, paybackOutput;
860
+ var _c;
861
+ return __generator(this, function (_d) {
862
+ switch (_d.label) {
863
+ case 0: return [4 /*yield*/, Promise.all([
864
+ this.nodeClient.getSaplingStateDiff(),
865
+ this.nodeClient.getChainId()
866
+ ])];
867
+ case 1:
868
+ _a = _d.sent(), stateDiff = _a[0], chainId = _a[1];
869
+ return [4 /*yield*/, this.chooseInputs(viewingKey, stateDiff.commitments_and_ciphertexts, stateDiff.nullifiers, value)];
870
+ case 2:
871
+ _b = _d.sent(), inputs = _b[0], toSpend = _b[1];
872
+ _c = {};
873
+ return [4 /*yield*/, this.getAddressFromPublicKey(viewingKey)];
874
+ case 3:
875
+ paybackOutput = (_c.address = (_d.sent()).address,
876
+ _c.value = toSpend.minus(value).toString(),
877
+ _c.memo = Buffer.alloc(this.options.config.memoSize).toString('hex'),
878
+ _c.browsable = true,
879
+ _c);
880
+ return [2 /*return*/, {
881
+ ins: inputs,
882
+ outs: [paybackOutput],
883
+ contractAddress: this.options.config.contractAddress,
884
+ chainId: chainId,
885
+ stateDiff: stateDiff,
886
+ unshieldTarget: ''
887
+ }];
888
+ }
889
+ });
890
+ });
891
+ };
892
+ TezosSaplingProtocol.prototype.chooseInputs = function (viewingKey, commitmentsWithCiphertext, nullifiers, value) {
893
+ return __awaiter(this, void 0, void 0, function () {
894
+ var unspends, balance, chosenUnspends, toSpend, _i, unspends_1, unspend;
895
+ return __generator(this, function (_a) {
896
+ switch (_a.label) {
897
+ case 0: return [4 /*yield*/, this.bookkeeper.getUnspends(viewingKey, commitmentsWithCiphertext, nullifiers)];
898
+ case 1:
899
+ unspends = _a.sent();
900
+ balance = this.bookkeeper.sumNotes(unspends);
901
+ if (balance.lt(value)) {
902
+ return [2 /*return*/, Promise.reject('Not enough balance')];
903
+ }
904
+ chosenUnspends = [];
905
+ toSpend = new bignumber_1.default(0);
906
+ for (_i = 0, unspends_1 = unspends; _i < unspends_1.length; _i++) {
907
+ unspend = unspends_1[_i];
908
+ if (toSpend.gte(value)) {
909
+ break;
910
+ }
911
+ toSpend = toSpend.plus(unspend.value);
912
+ chosenUnspends.push(unspend);
913
+ }
914
+ return [2 /*return*/, [chosenUnspends, toSpend]];
915
+ }
916
+ });
917
+ });
918
+ };
919
+ TezosSaplingProtocol.prototype.createPaymentOutput = function (address, value, memo) {
920
+ if (memo === void 0) { memo = Buffer.alloc(this.options.config.memoSize); }
921
+ return {
922
+ address: address.asString(),
923
+ value: new bignumber_1.default(value).toString(),
924
+ memo: memo.toString('hex'),
925
+ browsable: true
926
+ };
927
+ };
928
+ TezosSaplingProtocol.prototype.createPaybackOutput = function (address, toSpend, value, memo) {
929
+ if (memo === void 0) { memo = Buffer.alloc(this.options.config.memoSize); }
930
+ var paybackValue = toSpend.minus(value);
931
+ return paybackValue.gt(0)
932
+ ? {
933
+ address: address.asString(),
934
+ value: paybackValue.toString(),
935
+ memo: memo.toString('hex'),
936
+ browsable: true
937
+ }
938
+ : undefined;
939
+ };
940
+ TezosSaplingProtocol.prototype.createDummyInput = function (address) {
941
+ return __awaiter(this, void 0, void 0, function () {
942
+ var rcm;
943
+ return __generator(this, function (_a) {
944
+ switch (_a.label) {
945
+ case 0: return [4 /*yield*/, sapling.randR()];
946
+ case 1:
947
+ rcm = _a.sent();
948
+ return [2 /*return*/, {
949
+ rcm: rcm.toString('hex'),
950
+ pos: '0',
951
+ value: '0',
952
+ address: address.asString()
953
+ }];
954
+ }
955
+ });
956
+ });
957
+ };
958
+ TezosSaplingProtocol.prototype.createDummyOutput = function () {
959
+ return __awaiter(this, void 0, void 0, function () {
960
+ var address, memo;
961
+ return __generator(this, function (_a) {
962
+ switch (_a.label) {
963
+ case 0: return [4 /*yield*/, this.getDummyAddress()];
964
+ case 1:
965
+ address = _a.sent();
966
+ memo = random_1.randomBytes(this.options.config.memoSize);
967
+ return [2 /*return*/, {
968
+ address: address.address,
969
+ value: '0',
970
+ memo: Buffer.from(memo).toString('hex'),
971
+ browsable: false
972
+ }];
973
+ }
974
+ });
975
+ });
976
+ };
977
+ TezosSaplingProtocol.prototype.getDummyAddress = function () {
978
+ return __awaiter(this, void 0, void 0, function () {
979
+ var seed, viewingKey;
980
+ return __generator(this, function (_a) {
981
+ switch (_a.label) {
982
+ case 0:
983
+ seed = random_1.randomBytes(32);
984
+ return [4 /*yield*/, this.getPublicKeyFromHexSecret(Buffer.from(seed).toString('hex'), this.standardDerivationPath)];
985
+ case 1:
986
+ viewingKey = _a.sent();
987
+ return [2 /*return*/, this.getAddressFromPublicKey(viewingKey)];
988
+ }
989
+ });
990
+ });
991
+ };
992
+ TezosSaplingProtocol.prototype.createAddressBoundData = function (address) {
993
+ var michelson = MichelsonAddress_1.MichelsonAddress.from(TezosUtils_1.TezosUtils.encodeTzAddress(address));
994
+ return TezosUtils_1.TezosUtils.packMichelsonType(michelson);
995
+ };
996
+ TezosSaplingProtocol.prototype.getAntiReplay = function (chainId, contractAddress) {
997
+ return (contractAddress !== null && contractAddress !== void 0 ? contractAddress : this.options.config.contractAddress) + chainId;
998
+ };
999
+ TezosSaplingProtocol.prototype.broadcastTransaction = function (rawTransaction) {
1000
+ return __awaiter(this, void 0, void 0, function () {
1001
+ return __generator(this, function (_a) {
1002
+ return [2 /*return*/, this.tezosProtocol.broadcastTransaction(rawTransaction)];
1003
+ });
1004
+ });
1005
+ };
1006
+ TezosSaplingProtocol.prototype.signMessage = function (message, keypair) {
1007
+ return __awaiter(this, void 0, void 0, function () {
1008
+ return __generator(this, function (_a) {
1009
+ return [2 /*return*/, this.tezosProtocol.signMessage(message, keypair)];
1010
+ });
1011
+ });
1012
+ };
1013
+ TezosSaplingProtocol.prototype.verifyMessage = function (message, signature, publicKey) {
1014
+ return __awaiter(this, void 0, void 0, function () {
1015
+ return __generator(this, function (_a) {
1016
+ return [2 /*return*/, this.tezosProtocol.verifyMessage(message, signature, publicKey)];
1017
+ });
1018
+ });
1019
+ };
1020
+ TezosSaplingProtocol.prototype.encryptAsymmetric = function (payload, publicKey) {
1021
+ return __awaiter(this, void 0, void 0, function () {
1022
+ return __generator(this, function (_a) {
1023
+ return [2 /*return*/, this.encryptAsymmetric(payload, publicKey)];
1024
+ });
1025
+ });
1026
+ };
1027
+ TezosSaplingProtocol.prototype.decryptAsymmetric = function (encryptedPayload, keypair) {
1028
+ return __awaiter(this, void 0, void 0, function () {
1029
+ return __generator(this, function (_a) {
1030
+ return [2 /*return*/, this.decryptAsymmetric(encryptedPayload, keypair)];
1031
+ });
1032
+ });
1033
+ };
1034
+ TezosSaplingProtocol.prototype.encryptAES = function (payload, privateKey) {
1035
+ return __awaiter(this, void 0, void 0, function () {
1036
+ return __generator(this, function (_a) {
1037
+ return [2 /*return*/, this.encryptAES(payload, privateKey)];
1038
+ });
1039
+ });
1040
+ };
1041
+ TezosSaplingProtocol.prototype.decryptAES = function (encryptedPayload, privateKey) {
1042
+ return __awaiter(this, void 0, void 0, function () {
1043
+ return __generator(this, function (_a) {
1044
+ return [2 /*return*/, this.decryptAES(encryptedPayload, privateKey)];
1045
+ });
1046
+ });
1047
+ };
1048
+ TezosSaplingProtocol.prototype.getBlockExplorerLinkForAddress = function (address) {
1049
+ return __awaiter(this, void 0, void 0, function () {
1050
+ return __generator(this, function (_a) {
1051
+ throw new Error('Method `getBlockExplorerLinkForAddress` not supported.');
1052
+ });
1053
+ });
1054
+ };
1055
+ TezosSaplingProtocol.prototype.getTransactionsFromAddresses = function (addresses, limit, cursor) {
1056
+ return __awaiter(this, void 0, void 0, function () {
1057
+ return __generator(this, function (_a) {
1058
+ throw new Error('Method `getTransactionsFromAddresses` not supported.');
1059
+ });
1060
+ });
1061
+ };
1062
+ TezosSaplingProtocol.prototype.getBalanceOfAddresses = function (addresses) {
1063
+ return __awaiter(this, void 0, void 0, function () {
1064
+ return __generator(this, function (_a) {
1065
+ throw new Error('Method `getBalanceOfAddresses` not supported.');
1066
+ });
1067
+ });
1068
+ };
1069
+ TezosSaplingProtocol.prototype.getAvailableBalanceOfAddresses = function (addresses) {
1070
+ return __awaiter(this, void 0, void 0, function () {
1071
+ return __generator(this, function (_a) {
1072
+ throw new Error('Method `getAvailableBalanceOfAddresses` not supported.');
1073
+ });
1074
+ });
1075
+ };
1076
+ TezosSaplingProtocol.prototype.getBalanceOfPublicKeyForSubProtocols = function (publicKey, subProtocols) {
1077
+ return __awaiter(this, void 0, void 0, function () {
1078
+ return __generator(this, function (_a) {
1079
+ throw new Error('Method `getBalanceOfPublicKeyForSubProtocols` not supported.');
1080
+ });
1081
+ });
1082
+ };
1083
+ TezosSaplingProtocol.prototype.estimateFeeDefaultsFromPublicKey = function (publicKey, recipients, values, data) {
1084
+ return __awaiter(this, void 0, void 0, function () {
1085
+ return __generator(this, function (_a) {
1086
+ throw new Error('Method `estimateFeeDefaultsFromPublicKey` not supported.');
1087
+ });
1088
+ });
1089
+ };
1090
+ TezosSaplingProtocol.prototype.isRawTezosSaplingTransaction = function (transaction) {
1091
+ return (transaction instanceof Object &&
1092
+ 'ins' in transaction &&
1093
+ 'outs' in transaction &&
1094
+ 'contractAddress' in transaction &&
1095
+ 'chainId' in transaction &&
1096
+ 'stateDiff' in transaction);
1097
+ };
1098
+ return TezosSaplingProtocol;
1099
+ }(NonExtendedProtocol_1.NonExtendedProtocol));
1100
+ exports.TezosSaplingProtocol = TezosSaplingProtocol;
1101
+ //# sourceMappingURL=TezosSaplingProtocol.js.map