@stellar/stellar-sdk 12.3.0 → 13.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (514) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +29 -7
  3. package/dist/stellar-sdk-minimal.js +46009 -0
  4. package/dist/stellar-sdk-minimal.min.js +2 -0
  5. package/dist/stellar-sdk-minimal.min.js.LICENSE.txt +69 -0
  6. package/dist/stellar-sdk-no-axios.js +56648 -0
  7. package/dist/stellar-sdk-no-axios.min.js +2 -0
  8. package/dist/stellar-sdk-no-axios.min.js.LICENSE.txt +71 -0
  9. package/dist/stellar-sdk-no-eventsource.js +49822 -0
  10. package/dist/stellar-sdk-no-eventsource.min.js +2 -0
  11. package/dist/stellar-sdk-no-eventsource.min.js.LICENSE.txt +69 -0
  12. package/dist/stellar-sdk.js +28279 -27350
  13. package/dist/stellar-sdk.min.js +1 -1
  14. package/lib/browser.d.ts +2 -2
  15. package/lib/browser.js +5 -7
  16. package/lib/config.d.ts +31 -19
  17. package/lib/contract/assembled_transaction.d.ts +22 -14
  18. package/lib/contract/assembled_transaction.js +159 -128
  19. package/lib/contract/basic_node_signer.d.ts +6 -1
  20. package/lib/contract/client.d.ts +24 -24
  21. package/lib/contract/rust_result.d.ts +22 -12
  22. package/lib/contract/sent_transaction.d.ts +9 -4
  23. package/lib/contract/sent_transaction.js +6 -6
  24. package/lib/contract/spec.d.ts +8 -14
  25. package/lib/contract/types.d.ts +81 -13
  26. package/lib/contract/utils.d.ts +8 -1
  27. package/lib/errors/account_requires_memo.d.ts +24 -0
  28. package/lib/errors/account_requires_memo.js +38 -0
  29. package/lib/errors/bad_request.d.ts +14 -0
  30. package/lib/errors/bad_request.js +34 -0
  31. package/lib/errors/bad_response.d.ts +17 -0
  32. package/lib/errors/bad_response.js +34 -0
  33. package/lib/errors/index.d.ts +5 -0
  34. package/lib/errors/index.js +60 -0
  35. package/lib/errors/network.d.ts +33 -0
  36. package/lib/{errors.js → errors/network.js} +1 -59
  37. package/lib/errors/not_found.d.ts +14 -0
  38. package/lib/errors/not_found.js +34 -0
  39. package/lib/federation/api.d.ts +21 -0
  40. package/lib/federation/index.d.ts +1 -1
  41. package/lib/federation/index.js +16 -6
  42. package/lib/federation/server.d.ts +36 -38
  43. package/lib/federation/server.js +2 -2
  44. package/lib/horizon/account_call_builder.d.ts +10 -8
  45. package/lib/horizon/account_response.d.ts +5 -2
  46. package/lib/horizon/assets_call_builder.d.ts +3 -2
  47. package/lib/horizon/call_builder.js +9 -3
  48. package/lib/horizon/claimable_balances_call_builder.d.ts +10 -8
  49. package/lib/horizon/effect_call_builder.d.ts +8 -7
  50. package/lib/horizon/horizon_axios_client.d.ts +13 -6
  51. package/lib/horizon/horizon_axios_client.js +16 -4
  52. package/lib/horizon/index.d.ts +2 -1
  53. package/lib/horizon/index.js +1 -1
  54. package/lib/horizon/ledger_call_builder.d.ts +6 -4
  55. package/lib/horizon/liquidity_pool_call_builder.d.ts +3 -2
  56. package/lib/horizon/offer_call_builder.d.ts +12 -10
  57. package/lib/horizon/operation_call_builder.d.ts +11 -9
  58. package/lib/horizon/orderbook_call_builder.d.ts +7 -2
  59. package/lib/horizon/path_call_builder.d.ts +7 -2
  60. package/lib/horizon/payment_call_builder.d.ts +10 -6
  61. package/lib/horizon/server.d.ts +64 -55
  62. package/lib/horizon/server.js +6 -5
  63. package/lib/horizon/server_api.d.ts +0 -15
  64. package/lib/horizon/strict_receive_path_call_builder.d.ts +7 -2
  65. package/lib/horizon/strict_send_path_call_builder.d.ts +7 -2
  66. package/lib/horizon/trade_aggregation_call_builder.d.ts +4 -2
  67. package/lib/horizon/trades_call_builder.d.ts +8 -5
  68. package/lib/horizon/transaction_call_builder.d.ts +10 -7
  69. package/lib/horizon/types/assets.d.ts +0 -2
  70. package/lib/http-client/axios-client.d.ts +2 -0
  71. package/lib/http-client/axios-client.js +10 -0
  72. package/lib/http-client/fetch-client.d.ts +11 -0
  73. package/lib/http-client/fetch-client.js +229 -0
  74. package/lib/http-client/index.d.ts +5 -0
  75. package/lib/http-client/index.js +33 -0
  76. package/lib/http-client/types.d.ts +69 -0
  77. package/lib/http-client/types.js +34 -0
  78. package/lib/index.d.ts +3 -8
  79. package/lib/index.js +8 -5
  80. package/lib/minimal/browser.d.ts +6 -0
  81. package/lib/minimal/browser.js +35 -0
  82. package/lib/minimal/config.d.ts +64 -0
  83. package/lib/minimal/config.js +51 -0
  84. package/lib/minimal/contract/assembled_transaction.d.ts +555 -0
  85. package/lib/minimal/contract/assembled_transaction.js +752 -0
  86. package/lib/minimal/contract/basic_node_signer.d.ts +17 -0
  87. package/lib/minimal/contract/basic_node_signer.js +52 -0
  88. package/lib/minimal/contract/client.d.ts +52 -0
  89. package/lib/minimal/contract/client.js +180 -0
  90. package/lib/minimal/contract/index.d.ts +7 -0
  91. package/lib/minimal/contract/index.js +82 -0
  92. package/lib/minimal/contract/rust_result.d.ts +81 -0
  93. package/lib/minimal/contract/rust_result.js +66 -0
  94. package/lib/minimal/contract/sent_transaction.d.ts +84 -0
  95. package/lib/minimal/contract/sent_transaction.js +151 -0
  96. package/lib/minimal/contract/spec.d.ts +152 -0
  97. package/lib/minimal/contract/spec.js +1020 -0
  98. package/lib/minimal/contract/types.d.ts +180 -0
  99. package/lib/minimal/contract/types.js +8 -0
  100. package/lib/minimal/contract/utils.d.ts +46 -0
  101. package/lib/minimal/contract/utils.js +123 -0
  102. package/lib/minimal/errors/account_requires_memo.d.ts +24 -0
  103. package/lib/minimal/errors/account_requires_memo.js +38 -0
  104. package/lib/minimal/errors/bad_request.d.ts +14 -0
  105. package/lib/minimal/errors/bad_request.js +34 -0
  106. package/lib/minimal/errors/bad_response.d.ts +17 -0
  107. package/lib/minimal/errors/bad_response.js +34 -0
  108. package/lib/minimal/errors/index.d.ts +5 -0
  109. package/lib/minimal/errors/index.js +60 -0
  110. package/lib/minimal/errors/network.d.ts +33 -0
  111. package/lib/minimal/errors/network.js +41 -0
  112. package/lib/minimal/errors/not_found.d.ts +14 -0
  113. package/lib/minimal/errors/not_found.js +34 -0
  114. package/lib/minimal/federation/api.d.ts +32 -0
  115. package/lib/minimal/federation/api.js +7 -0
  116. package/lib/minimal/federation/index.d.ts +2 -0
  117. package/lib/minimal/federation/index.js +34 -0
  118. package/lib/minimal/federation/server.d.ts +116 -0
  119. package/lib/minimal/federation/server.js +252 -0
  120. package/lib/minimal/friendbot/index.d.ts +5 -0
  121. package/lib/minimal/friendbot/index.js +7 -0
  122. package/lib/minimal/horizon/account_call_builder.d.ts +56 -0
  123. package/lib/minimal/horizon/account_call_builder.js +62 -0
  124. package/lib/minimal/horizon/account_response.d.ts +61 -0
  125. package/lib/minimal/horizon/account_response.js +49 -0
  126. package/lib/minimal/horizon/assets_call_builder.d.ts +27 -0
  127. package/lib/minimal/horizon/assets_call_builder.js +43 -0
  128. package/lib/minimal/horizon/call_builder.d.ts +128 -0
  129. package/lib/minimal/horizon/call_builder.js +362 -0
  130. package/lib/minimal/horizon/claimable_balances_call_builder.d.ts +50 -0
  131. package/lib/minimal/horizon/claimable_balances_call_builder.js +56 -0
  132. package/lib/minimal/horizon/effect_call_builder.d.ts +53 -0
  133. package/lib/minimal/horizon/effect_call_builder.js +56 -0
  134. package/lib/minimal/horizon/friendbot_builder.d.ts +4 -0
  135. package/lib/minimal/horizon/friendbot_builder.js +32 -0
  136. package/lib/minimal/horizon/horizon_api.d.ts +527 -0
  137. package/lib/minimal/horizon/horizon_api.js +96 -0
  138. package/lib/minimal/horizon/horizon_axios_client.d.ts +37 -0
  139. package/lib/minimal/horizon/horizon_axios_client.js +60 -0
  140. package/lib/minimal/horizon/index.d.ts +8 -0
  141. package/lib/minimal/horizon/index.js +78 -0
  142. package/lib/minimal/horizon/ledger_call_builder.d.ts +23 -0
  143. package/lib/minimal/horizon/ledger_call_builder.js +37 -0
  144. package/lib/minimal/horizon/liquidity_pool_call_builder.d.ts +37 -0
  145. package/lib/minimal/horizon/liquidity_pool_call_builder.js +59 -0
  146. package/lib/minimal/horizon/offer_call_builder.d.ts +65 -0
  147. package/lib/minimal/horizon/offer_call_builder.js +79 -0
  148. package/lib/minimal/horizon/operation_call_builder.d.ts +69 -0
  149. package/lib/minimal/horizon/operation_call_builder.js +69 -0
  150. package/lib/minimal/horizon/orderbook_call_builder.d.ts +20 -0
  151. package/lib/minimal/horizon/orderbook_call_builder.js +45 -0
  152. package/lib/minimal/horizon/path_call_builder.d.ts +35 -0
  153. package/lib/minimal/horizon/path_call_builder.js +41 -0
  154. package/lib/minimal/horizon/payment_call_builder.d.ts +39 -0
  155. package/lib/minimal/horizon/payment_call_builder.js +46 -0
  156. package/lib/minimal/horizon/server.d.ts +389 -0
  157. package/lib/minimal/horizon/server.js +550 -0
  158. package/lib/minimal/horizon/server_api.d.ts +263 -0
  159. package/lib/minimal/horizon/server_api.js +19 -0
  160. package/lib/minimal/horizon/strict_receive_path_call_builder.d.ts +38 -0
  161. package/lib/minimal/horizon/strict_receive_path_call_builder.js +50 -0
  162. package/lib/minimal/horizon/strict_send_path_call_builder.d.ts +38 -0
  163. package/lib/minimal/horizon/strict_send_path_call_builder.js +50 -0
  164. package/lib/minimal/horizon/trade_aggregation_call_builder.d.ts +49 -0
  165. package/lib/minimal/horizon/trade_aggregation_call_builder.js +76 -0
  166. package/lib/minimal/horizon/trades_call_builder.d.ts +52 -0
  167. package/lib/minimal/horizon/trades_call_builder.js +72 -0
  168. package/lib/minimal/horizon/transaction_call_builder.d.ts +60 -0
  169. package/lib/minimal/horizon/transaction_call_builder.js +64 -0
  170. package/lib/minimal/horizon/types/account.d.ts +5 -0
  171. package/lib/minimal/horizon/types/account.js +5 -0
  172. package/lib/minimal/horizon/types/assets.d.ts +17 -0
  173. package/lib/minimal/horizon/types/assets.js +5 -0
  174. package/lib/minimal/horizon/types/effects.d.ts +285 -0
  175. package/lib/minimal/horizon/types/effects.js +62 -0
  176. package/lib/minimal/horizon/types/offer.d.ts +20 -0
  177. package/lib/minimal/horizon/types/offer.js +5 -0
  178. package/lib/minimal/horizon/types/trade.d.ts +13 -0
  179. package/lib/minimal/horizon/types/trade.js +5 -0
  180. package/lib/minimal/http-client/axios-client.d.ts +2 -0
  181. package/lib/minimal/http-client/axios-client.js +10 -0
  182. package/lib/minimal/http-client/fetch-client.d.ts +11 -0
  183. package/lib/minimal/http-client/fetch-client.js +229 -0
  184. package/lib/minimal/http-client/index.d.ts +5 -0
  185. package/lib/minimal/http-client/index.js +33 -0
  186. package/lib/minimal/http-client/types.d.ts +69 -0
  187. package/lib/minimal/http-client/types.js +34 -0
  188. package/lib/minimal/index.d.ts +32 -0
  189. package/lib/minimal/index.js +80 -0
  190. package/lib/minimal/rpc/api.d.ts +362 -0
  191. package/lib/minimal/rpc/api.js +32 -0
  192. package/lib/minimal/rpc/axios.d.ts +4 -0
  193. package/lib/minimal/rpc/axios.js +15 -0
  194. package/lib/minimal/rpc/browser.d.ts +4 -0
  195. package/lib/minimal/rpc/browser.js +27 -0
  196. package/lib/minimal/rpc/index.d.ts +8 -0
  197. package/lib/minimal/rpc/index.js +86 -0
  198. package/lib/minimal/rpc/jsonrpc.d.ts +35 -0
  199. package/lib/minimal/rpc/jsonrpc.js +52 -0
  200. package/lib/minimal/rpc/parsers.d.ts +39 -0
  201. package/lib/minimal/rpc/parsers.js +155 -0
  202. package/lib/minimal/rpc/server.d.ts +622 -0
  203. package/lib/minimal/rpc/server.js +877 -0
  204. package/lib/minimal/rpc/transaction.d.ts +21 -0
  205. package/lib/minimal/rpc/transaction.js +53 -0
  206. package/lib/minimal/rpc/utils.d.ts +1 -0
  207. package/lib/minimal/rpc/utils.js +9 -0
  208. package/lib/minimal/stellartoml/index.d.ts +131 -0
  209. package/lib/minimal/stellartoml/index.js +77 -0
  210. package/lib/minimal/utils.d.ts +20 -0
  211. package/lib/minimal/utils.js +38 -0
  212. package/lib/minimal/webauth/errors.d.ts +13 -0
  213. package/lib/minimal/webauth/errors.js +36 -0
  214. package/lib/minimal/webauth/index.d.ts +2 -0
  215. package/lib/minimal/webauth/index.js +27 -0
  216. package/lib/minimal/webauth/utils.d.ts +307 -0
  217. package/lib/minimal/webauth/utils.js +332 -0
  218. package/lib/no-axios/browser.d.ts +6 -0
  219. package/lib/no-axios/browser.js +35 -0
  220. package/lib/no-axios/config.d.ts +64 -0
  221. package/lib/no-axios/config.js +51 -0
  222. package/lib/no-axios/contract/assembled_transaction.d.ts +555 -0
  223. package/lib/no-axios/contract/assembled_transaction.js +752 -0
  224. package/lib/no-axios/contract/basic_node_signer.d.ts +17 -0
  225. package/lib/no-axios/contract/basic_node_signer.js +52 -0
  226. package/lib/no-axios/contract/client.d.ts +52 -0
  227. package/lib/no-axios/contract/client.js +180 -0
  228. package/lib/no-axios/contract/index.d.ts +7 -0
  229. package/lib/no-axios/contract/index.js +82 -0
  230. package/lib/no-axios/contract/rust_result.d.ts +81 -0
  231. package/lib/no-axios/contract/rust_result.js +66 -0
  232. package/lib/no-axios/contract/sent_transaction.d.ts +84 -0
  233. package/lib/no-axios/contract/sent_transaction.js +151 -0
  234. package/lib/no-axios/contract/spec.d.ts +152 -0
  235. package/lib/no-axios/contract/spec.js +1020 -0
  236. package/lib/no-axios/contract/types.d.ts +180 -0
  237. package/lib/no-axios/contract/types.js +8 -0
  238. package/lib/no-axios/contract/utils.d.ts +46 -0
  239. package/lib/no-axios/contract/utils.js +123 -0
  240. package/lib/no-axios/errors/account_requires_memo.d.ts +24 -0
  241. package/lib/no-axios/errors/account_requires_memo.js +38 -0
  242. package/lib/no-axios/errors/bad_request.d.ts +14 -0
  243. package/lib/no-axios/errors/bad_request.js +34 -0
  244. package/lib/no-axios/errors/bad_response.d.ts +17 -0
  245. package/lib/no-axios/errors/bad_response.js +34 -0
  246. package/lib/no-axios/errors/index.d.ts +5 -0
  247. package/lib/no-axios/errors/index.js +60 -0
  248. package/lib/no-axios/errors/network.d.ts +33 -0
  249. package/lib/no-axios/errors/network.js +41 -0
  250. package/lib/no-axios/errors/not_found.d.ts +14 -0
  251. package/lib/no-axios/errors/not_found.js +34 -0
  252. package/lib/no-axios/federation/api.d.ts +32 -0
  253. package/lib/no-axios/federation/api.js +7 -0
  254. package/lib/no-axios/federation/index.d.ts +2 -0
  255. package/lib/no-axios/federation/index.js +34 -0
  256. package/lib/no-axios/federation/server.d.ts +116 -0
  257. package/lib/no-axios/federation/server.js +252 -0
  258. package/lib/no-axios/friendbot/index.d.ts +5 -0
  259. package/lib/no-axios/friendbot/index.js +7 -0
  260. package/lib/no-axios/horizon/account_call_builder.d.ts +56 -0
  261. package/lib/no-axios/horizon/account_call_builder.js +62 -0
  262. package/lib/no-axios/horizon/account_response.d.ts +61 -0
  263. package/lib/no-axios/horizon/account_response.js +49 -0
  264. package/lib/no-axios/horizon/assets_call_builder.d.ts +27 -0
  265. package/lib/no-axios/horizon/assets_call_builder.js +43 -0
  266. package/lib/no-axios/horizon/call_builder.d.ts +128 -0
  267. package/lib/no-axios/horizon/call_builder.js +362 -0
  268. package/lib/no-axios/horizon/claimable_balances_call_builder.d.ts +50 -0
  269. package/lib/no-axios/horizon/claimable_balances_call_builder.js +56 -0
  270. package/lib/no-axios/horizon/effect_call_builder.d.ts +53 -0
  271. package/lib/no-axios/horizon/effect_call_builder.js +56 -0
  272. package/lib/no-axios/horizon/friendbot_builder.d.ts +4 -0
  273. package/lib/no-axios/horizon/friendbot_builder.js +32 -0
  274. package/lib/no-axios/horizon/horizon_api.d.ts +527 -0
  275. package/lib/no-axios/horizon/horizon_api.js +96 -0
  276. package/lib/no-axios/horizon/horizon_axios_client.d.ts +37 -0
  277. package/lib/no-axios/horizon/horizon_axios_client.js +60 -0
  278. package/lib/no-axios/horizon/index.d.ts +8 -0
  279. package/lib/no-axios/horizon/index.js +78 -0
  280. package/lib/no-axios/horizon/ledger_call_builder.d.ts +23 -0
  281. package/lib/no-axios/horizon/ledger_call_builder.js +37 -0
  282. package/lib/no-axios/horizon/liquidity_pool_call_builder.d.ts +37 -0
  283. package/lib/no-axios/horizon/liquidity_pool_call_builder.js +59 -0
  284. package/lib/no-axios/horizon/offer_call_builder.d.ts +65 -0
  285. package/lib/no-axios/horizon/offer_call_builder.js +79 -0
  286. package/lib/no-axios/horizon/operation_call_builder.d.ts +69 -0
  287. package/lib/no-axios/horizon/operation_call_builder.js +69 -0
  288. package/lib/no-axios/horizon/orderbook_call_builder.d.ts +20 -0
  289. package/lib/no-axios/horizon/orderbook_call_builder.js +45 -0
  290. package/lib/no-axios/horizon/path_call_builder.d.ts +35 -0
  291. package/lib/no-axios/horizon/path_call_builder.js +41 -0
  292. package/lib/no-axios/horizon/payment_call_builder.d.ts +39 -0
  293. package/lib/no-axios/horizon/payment_call_builder.js +46 -0
  294. package/lib/no-axios/horizon/server.d.ts +389 -0
  295. package/lib/no-axios/horizon/server.js +550 -0
  296. package/lib/no-axios/horizon/server_api.d.ts +263 -0
  297. package/lib/no-axios/horizon/server_api.js +19 -0
  298. package/lib/no-axios/horizon/strict_receive_path_call_builder.d.ts +38 -0
  299. package/lib/no-axios/horizon/strict_receive_path_call_builder.js +50 -0
  300. package/lib/no-axios/horizon/strict_send_path_call_builder.d.ts +38 -0
  301. package/lib/no-axios/horizon/strict_send_path_call_builder.js +50 -0
  302. package/lib/no-axios/horizon/trade_aggregation_call_builder.d.ts +49 -0
  303. package/lib/no-axios/horizon/trade_aggregation_call_builder.js +76 -0
  304. package/lib/no-axios/horizon/trades_call_builder.d.ts +52 -0
  305. package/lib/no-axios/horizon/trades_call_builder.js +72 -0
  306. package/lib/no-axios/horizon/transaction_call_builder.d.ts +60 -0
  307. package/lib/no-axios/horizon/transaction_call_builder.js +64 -0
  308. package/lib/no-axios/horizon/types/account.d.ts +5 -0
  309. package/lib/no-axios/horizon/types/account.js +5 -0
  310. package/lib/no-axios/horizon/types/assets.d.ts +17 -0
  311. package/lib/no-axios/horizon/types/assets.js +5 -0
  312. package/lib/no-axios/horizon/types/effects.d.ts +285 -0
  313. package/lib/no-axios/horizon/types/effects.js +62 -0
  314. package/lib/no-axios/horizon/types/offer.d.ts +20 -0
  315. package/lib/no-axios/horizon/types/offer.js +5 -0
  316. package/lib/no-axios/horizon/types/trade.d.ts +13 -0
  317. package/lib/no-axios/horizon/types/trade.js +5 -0
  318. package/lib/no-axios/http-client/axios-client.d.ts +2 -0
  319. package/lib/no-axios/http-client/axios-client.js +10 -0
  320. package/lib/no-axios/http-client/fetch-client.d.ts +11 -0
  321. package/lib/no-axios/http-client/fetch-client.js +229 -0
  322. package/lib/no-axios/http-client/index.d.ts +5 -0
  323. package/lib/no-axios/http-client/index.js +33 -0
  324. package/lib/no-axios/http-client/types.d.ts +69 -0
  325. package/lib/no-axios/http-client/types.js +34 -0
  326. package/lib/no-axios/index.d.ts +32 -0
  327. package/lib/no-axios/index.js +80 -0
  328. package/lib/no-axios/rpc/api.d.ts +362 -0
  329. package/lib/no-axios/rpc/api.js +32 -0
  330. package/lib/no-axios/rpc/axios.d.ts +4 -0
  331. package/lib/no-axios/rpc/axios.js +15 -0
  332. package/lib/no-axios/rpc/browser.d.ts +4 -0
  333. package/lib/no-axios/rpc/browser.js +27 -0
  334. package/lib/no-axios/rpc/index.d.ts +8 -0
  335. package/lib/no-axios/rpc/index.js +86 -0
  336. package/lib/no-axios/rpc/jsonrpc.d.ts +35 -0
  337. package/lib/no-axios/rpc/jsonrpc.js +52 -0
  338. package/lib/no-axios/rpc/parsers.d.ts +39 -0
  339. package/lib/no-axios/rpc/parsers.js +155 -0
  340. package/lib/no-axios/rpc/server.d.ts +622 -0
  341. package/lib/no-axios/rpc/server.js +877 -0
  342. package/lib/no-axios/rpc/transaction.d.ts +21 -0
  343. package/lib/no-axios/rpc/transaction.js +53 -0
  344. package/lib/no-axios/rpc/utils.d.ts +1 -0
  345. package/lib/no-axios/rpc/utils.js +9 -0
  346. package/lib/no-axios/stellartoml/index.d.ts +131 -0
  347. package/lib/no-axios/stellartoml/index.js +77 -0
  348. package/lib/no-axios/utils.d.ts +20 -0
  349. package/lib/no-axios/utils.js +38 -0
  350. package/lib/no-axios/webauth/errors.d.ts +13 -0
  351. package/lib/no-axios/webauth/errors.js +36 -0
  352. package/lib/no-axios/webauth/index.d.ts +2 -0
  353. package/lib/no-axios/webauth/index.js +27 -0
  354. package/lib/no-axios/webauth/utils.d.ts +307 -0
  355. package/lib/no-axios/webauth/utils.js +332 -0
  356. package/lib/no-eventsource/browser.d.ts +6 -0
  357. package/lib/no-eventsource/browser.js +35 -0
  358. package/lib/no-eventsource/config.d.ts +64 -0
  359. package/lib/no-eventsource/config.js +51 -0
  360. package/lib/no-eventsource/contract/assembled_transaction.d.ts +555 -0
  361. package/lib/no-eventsource/contract/assembled_transaction.js +752 -0
  362. package/lib/no-eventsource/contract/basic_node_signer.d.ts +17 -0
  363. package/lib/no-eventsource/contract/basic_node_signer.js +52 -0
  364. package/lib/no-eventsource/contract/client.d.ts +52 -0
  365. package/lib/no-eventsource/contract/client.js +180 -0
  366. package/lib/no-eventsource/contract/index.d.ts +7 -0
  367. package/lib/no-eventsource/contract/index.js +82 -0
  368. package/lib/no-eventsource/contract/rust_result.d.ts +81 -0
  369. package/lib/no-eventsource/contract/rust_result.js +66 -0
  370. package/lib/no-eventsource/contract/sent_transaction.d.ts +84 -0
  371. package/lib/no-eventsource/contract/sent_transaction.js +151 -0
  372. package/lib/no-eventsource/contract/spec.d.ts +152 -0
  373. package/lib/no-eventsource/contract/spec.js +1020 -0
  374. package/lib/no-eventsource/contract/types.d.ts +180 -0
  375. package/lib/no-eventsource/contract/types.js +8 -0
  376. package/lib/no-eventsource/contract/utils.d.ts +46 -0
  377. package/lib/no-eventsource/contract/utils.js +123 -0
  378. package/lib/no-eventsource/errors/account_requires_memo.d.ts +24 -0
  379. package/lib/no-eventsource/errors/account_requires_memo.js +38 -0
  380. package/lib/no-eventsource/errors/bad_request.d.ts +14 -0
  381. package/lib/no-eventsource/errors/bad_request.js +34 -0
  382. package/lib/no-eventsource/errors/bad_response.d.ts +17 -0
  383. package/lib/no-eventsource/errors/bad_response.js +34 -0
  384. package/lib/no-eventsource/errors/index.d.ts +5 -0
  385. package/lib/no-eventsource/errors/index.js +60 -0
  386. package/lib/no-eventsource/errors/network.d.ts +33 -0
  387. package/lib/no-eventsource/errors/network.js +41 -0
  388. package/lib/no-eventsource/errors/not_found.d.ts +14 -0
  389. package/lib/no-eventsource/errors/not_found.js +34 -0
  390. package/lib/no-eventsource/federation/api.d.ts +32 -0
  391. package/lib/no-eventsource/federation/api.js +7 -0
  392. package/lib/no-eventsource/federation/index.d.ts +2 -0
  393. package/lib/no-eventsource/federation/index.js +34 -0
  394. package/lib/no-eventsource/federation/server.d.ts +116 -0
  395. package/lib/no-eventsource/federation/server.js +252 -0
  396. package/lib/no-eventsource/friendbot/index.d.ts +5 -0
  397. package/lib/no-eventsource/friendbot/index.js +7 -0
  398. package/lib/no-eventsource/horizon/account_call_builder.d.ts +56 -0
  399. package/lib/no-eventsource/horizon/account_call_builder.js +62 -0
  400. package/lib/no-eventsource/horizon/account_response.d.ts +61 -0
  401. package/lib/no-eventsource/horizon/account_response.js +49 -0
  402. package/lib/no-eventsource/horizon/assets_call_builder.d.ts +27 -0
  403. package/lib/no-eventsource/horizon/assets_call_builder.js +43 -0
  404. package/lib/no-eventsource/horizon/call_builder.d.ts +128 -0
  405. package/lib/no-eventsource/horizon/call_builder.js +362 -0
  406. package/lib/no-eventsource/horizon/claimable_balances_call_builder.d.ts +50 -0
  407. package/lib/no-eventsource/horizon/claimable_balances_call_builder.js +56 -0
  408. package/lib/no-eventsource/horizon/effect_call_builder.d.ts +53 -0
  409. package/lib/no-eventsource/horizon/effect_call_builder.js +56 -0
  410. package/lib/no-eventsource/horizon/friendbot_builder.d.ts +4 -0
  411. package/lib/no-eventsource/horizon/friendbot_builder.js +32 -0
  412. package/lib/no-eventsource/horizon/horizon_api.d.ts +527 -0
  413. package/lib/no-eventsource/horizon/horizon_api.js +96 -0
  414. package/lib/no-eventsource/horizon/horizon_axios_client.d.ts +37 -0
  415. package/lib/no-eventsource/horizon/horizon_axios_client.js +60 -0
  416. package/lib/no-eventsource/horizon/index.d.ts +8 -0
  417. package/lib/no-eventsource/horizon/index.js +78 -0
  418. package/lib/no-eventsource/horizon/ledger_call_builder.d.ts +23 -0
  419. package/lib/no-eventsource/horizon/ledger_call_builder.js +37 -0
  420. package/lib/no-eventsource/horizon/liquidity_pool_call_builder.d.ts +37 -0
  421. package/lib/no-eventsource/horizon/liquidity_pool_call_builder.js +59 -0
  422. package/lib/no-eventsource/horizon/offer_call_builder.d.ts +65 -0
  423. package/lib/no-eventsource/horizon/offer_call_builder.js +79 -0
  424. package/lib/no-eventsource/horizon/operation_call_builder.d.ts +69 -0
  425. package/lib/no-eventsource/horizon/operation_call_builder.js +69 -0
  426. package/lib/no-eventsource/horizon/orderbook_call_builder.d.ts +20 -0
  427. package/lib/no-eventsource/horizon/orderbook_call_builder.js +45 -0
  428. package/lib/no-eventsource/horizon/path_call_builder.d.ts +35 -0
  429. package/lib/no-eventsource/horizon/path_call_builder.js +41 -0
  430. package/lib/no-eventsource/horizon/payment_call_builder.d.ts +39 -0
  431. package/lib/no-eventsource/horizon/payment_call_builder.js +46 -0
  432. package/lib/no-eventsource/horizon/server.d.ts +389 -0
  433. package/lib/no-eventsource/horizon/server.js +550 -0
  434. package/lib/no-eventsource/horizon/server_api.d.ts +263 -0
  435. package/lib/no-eventsource/horizon/server_api.js +19 -0
  436. package/lib/no-eventsource/horizon/strict_receive_path_call_builder.d.ts +38 -0
  437. package/lib/no-eventsource/horizon/strict_receive_path_call_builder.js +50 -0
  438. package/lib/no-eventsource/horizon/strict_send_path_call_builder.d.ts +38 -0
  439. package/lib/no-eventsource/horizon/strict_send_path_call_builder.js +50 -0
  440. package/lib/no-eventsource/horizon/trade_aggregation_call_builder.d.ts +49 -0
  441. package/lib/no-eventsource/horizon/trade_aggregation_call_builder.js +76 -0
  442. package/lib/no-eventsource/horizon/trades_call_builder.d.ts +52 -0
  443. package/lib/no-eventsource/horizon/trades_call_builder.js +72 -0
  444. package/lib/no-eventsource/horizon/transaction_call_builder.d.ts +60 -0
  445. package/lib/no-eventsource/horizon/transaction_call_builder.js +64 -0
  446. package/lib/no-eventsource/horizon/types/account.d.ts +5 -0
  447. package/lib/no-eventsource/horizon/types/account.js +5 -0
  448. package/lib/no-eventsource/horizon/types/assets.d.ts +17 -0
  449. package/lib/no-eventsource/horizon/types/assets.js +5 -0
  450. package/lib/no-eventsource/horizon/types/effects.d.ts +285 -0
  451. package/lib/no-eventsource/horizon/types/effects.js +62 -0
  452. package/lib/no-eventsource/horizon/types/offer.d.ts +20 -0
  453. package/lib/no-eventsource/horizon/types/offer.js +5 -0
  454. package/lib/no-eventsource/horizon/types/trade.d.ts +13 -0
  455. package/lib/no-eventsource/horizon/types/trade.js +5 -0
  456. package/lib/no-eventsource/http-client/axios-client.d.ts +2 -0
  457. package/lib/no-eventsource/http-client/axios-client.js +10 -0
  458. package/lib/no-eventsource/http-client/fetch-client.d.ts +11 -0
  459. package/lib/no-eventsource/http-client/fetch-client.js +229 -0
  460. package/lib/no-eventsource/http-client/index.d.ts +5 -0
  461. package/lib/no-eventsource/http-client/index.js +33 -0
  462. package/lib/no-eventsource/http-client/types.d.ts +69 -0
  463. package/lib/no-eventsource/http-client/types.js +34 -0
  464. package/lib/no-eventsource/index.d.ts +32 -0
  465. package/lib/no-eventsource/index.js +80 -0
  466. package/lib/no-eventsource/rpc/api.d.ts +362 -0
  467. package/lib/no-eventsource/rpc/api.js +32 -0
  468. package/lib/no-eventsource/rpc/axios.d.ts +4 -0
  469. package/lib/no-eventsource/rpc/axios.js +15 -0
  470. package/lib/no-eventsource/rpc/browser.d.ts +4 -0
  471. package/lib/no-eventsource/rpc/browser.js +27 -0
  472. package/lib/no-eventsource/rpc/index.d.ts +8 -0
  473. package/lib/no-eventsource/rpc/index.js +86 -0
  474. package/lib/no-eventsource/rpc/jsonrpc.d.ts +35 -0
  475. package/lib/no-eventsource/rpc/jsonrpc.js +52 -0
  476. package/lib/no-eventsource/rpc/parsers.d.ts +39 -0
  477. package/lib/no-eventsource/rpc/parsers.js +155 -0
  478. package/lib/no-eventsource/rpc/server.d.ts +622 -0
  479. package/lib/no-eventsource/rpc/server.js +877 -0
  480. package/lib/no-eventsource/rpc/transaction.d.ts +21 -0
  481. package/lib/no-eventsource/rpc/transaction.js +53 -0
  482. package/lib/no-eventsource/rpc/utils.d.ts +1 -0
  483. package/lib/no-eventsource/rpc/utils.js +9 -0
  484. package/lib/no-eventsource/stellartoml/index.d.ts +131 -0
  485. package/lib/no-eventsource/stellartoml/index.js +77 -0
  486. package/lib/no-eventsource/utils.d.ts +20 -0
  487. package/lib/no-eventsource/utils.js +38 -0
  488. package/lib/no-eventsource/webauth/errors.d.ts +13 -0
  489. package/lib/no-eventsource/webauth/errors.js +36 -0
  490. package/lib/no-eventsource/webauth/index.d.ts +2 -0
  491. package/lib/no-eventsource/webauth/index.js +27 -0
  492. package/lib/no-eventsource/webauth/utils.d.ts +307 -0
  493. package/lib/no-eventsource/webauth/utils.js +332 -0
  494. package/lib/rpc/api.d.ts +25 -11
  495. package/lib/rpc/axios.d.ts +3 -2
  496. package/lib/rpc/axios.js +3 -4
  497. package/lib/rpc/browser.d.ts +0 -2
  498. package/lib/rpc/browser.js +1 -11
  499. package/lib/rpc/index.d.ts +2 -1
  500. package/lib/rpc/index.js +15 -1
  501. package/lib/rpc/jsonrpc.d.ts +9 -1
  502. package/lib/rpc/parsers.d.ts +31 -11
  503. package/lib/rpc/parsers.js +14 -14
  504. package/lib/rpc/server.d.ts +207 -99
  505. package/lib/rpc/server.js +273 -133
  506. package/lib/rpc/transaction.d.ts +11 -9
  507. package/lib/stellartoml/index.d.ts +21 -11
  508. package/lib/stellartoml/index.js +3 -3
  509. package/lib/utils.d.ts +12 -4
  510. package/lib/utils.js +7 -0
  511. package/lib/webauth/errors.d.ts +9 -0
  512. package/lib/webauth/utils.d.ts +67 -54
  513. package/package.json +73 -21
  514. package/lib/errors.d.ts +0 -59
@@ -0,0 +1,307 @@
1
+ /**
2
+ * Stellar Web Authentication
3
+ * @module WebAuth
4
+ * @see {@link https://stellar.org/protocol-10 | SEP-10 Specification}
5
+ */
6
+ import { FeeBumpTransaction, Keypair, Transaction } from "@stellar/stellar-base";
7
+ import { ServerApi } from "../horizon/server_api";
8
+ /**
9
+ * Returns a valid {@link https://stellar.org/protocol/sep-10 | SEP-10}
10
+ * challenge transaction which you can use for Stellar Web Authentication.
11
+ *
12
+ * @param {Keypair} serverKeypair Keypair for server's signing account.
13
+ * @param {string} clientAccountID The stellar account (G...) or muxed account
14
+ * (M...) that the wallet wishes to authenticate with the server.
15
+ * @param {string} homeDomain The fully qualified domain name of the service
16
+ * requiring authentication
17
+ * @param {number} [timeout=300] Challenge duration (default to 5 minutes).
18
+ * @param {string} networkPassphrase The network passphrase. If you pass this
19
+ * argument then timeout is required.
20
+ * @param {string} webAuthDomain The fully qualified domain name of the service
21
+ * issuing the challenge.
22
+ * @param {string} [memo] The memo to attach to the challenge transaction. The
23
+ * memo must be of type `id`. If the `clientaccountID` is a muxed account,
24
+ * memos cannot be used.
25
+ * @param {string} [clientDomain] The fully qualified domain of the client
26
+ * requesting the challenge. Only necessary when the the 'client_domain'
27
+ * parameter is passed.
28
+ * @param {string} [clientSigningKey] The public key assigned to the SIGNING_KEY
29
+ * attribute specified on the stellar.toml hosted on the client domain. Only
30
+ * necessary when the 'client_domain' parameter is passed.
31
+ * @returns {string} A base64 encoded string of the raw TransactionEnvelope xdr
32
+ * struct for the transaction.
33
+ * @throws {Error} Will throw if `clientAccountID is a muxed account, and `memo`
34
+ * is present.
35
+ * @throws {Error} Will throw if `clientDomain` is provided, but
36
+ * `clientSigningKey` is missing
37
+ *
38
+ * @see {@link https://stellar.org/protocol/sep-10 | SEP-10: Stellar Web Auth}
39
+ *
40
+ * @example
41
+ * import { Keypair, Networks, WebAuth } from 'stellar-sdk'
42
+ *
43
+ * let serverKeyPair = Keypair.fromSecret("server-secret")
44
+ * let challenge = WebAuth.buildChallengeTx(
45
+ * serverKeyPair,
46
+ * "client-stellar-account-id",
47
+ * "stellar.org",
48
+ * 300,
49
+ * Networks.TESTNET);
50
+ */
51
+ export declare function buildChallengeTx(serverKeypair: Keypair, clientAccountID: string, homeDomain: string, timeout: number | undefined, networkPassphrase: string, webAuthDomain: string, memo?: string | null, clientDomain?: string | null, clientSigningKey?: string | null): string;
52
+ /**
53
+ * A parsed and validated challenge transaction, and some of its constituent details.
54
+ * @memberof module:WebAuth
55
+ */
56
+ export type ChallengeTxDetails = {
57
+ /** The challenge transaction. */
58
+ tx: Transaction;
59
+ /** The Stellar public key (master key) used to sign the Manage Data operation. */
60
+ clientAccountId: string;
61
+ /** The matched home domain. */
62
+ matchedHomeDomain: string;
63
+ /** The memo attached to the transaction, which will be null if not present */
64
+ memo?: string;
65
+ };
66
+ /**
67
+ * Reads a SEP-10 challenge transaction and returns the decoded transaction and
68
+ * client account ID contained within.
69
+ *
70
+ * It also verifies that the transaction has been signed by the server.
71
+ *
72
+ * It does not verify that the transaction has been signed by the client or that
73
+ * any signatures other than the server's on the transaction are valid. Use one
74
+ * of the following functions to completely verify the transaction:
75
+ *
76
+ * - {@link module:WebAuth~verifyChallengeTxThreshold}
77
+ * - {@link module:WebAuth~verifyChallengeTxSigners}
78
+ *
79
+ * @param {string} challengeTx SEP0010 challenge transaction in base64.
80
+ * @param {string} serverAccountID The server's stellar account (public key).
81
+ * @param {string} networkPassphrase The network passphrase, e.g.: 'Test SDF
82
+ * Network ; September 2015' (see {@link Networks})
83
+ * @param {string | Array.<string>} homeDomains The home domain that is expected
84
+ * to be included in the first Manage Data operation's string key. If an
85
+ * array is provided, one of the domain names in the array must match.
86
+ * @param {string} webAuthDomain The home domain that is expected to be included
87
+ * as the value of the Manage Data operation with the 'web_auth_domain' key.
88
+ * If no such operation is included, this parameter is not used.
89
+ * @returns {module:WebAuth.ChallengeTxDetails} The actual transaction and the
90
+ * Stellar public key (master key) used to sign the Manage Data operation,
91
+ * the matched home domain, and the memo attached to the transaction, which
92
+ * will be null if not present.
93
+ *
94
+ * @see {@link https://stellar.org/protocol/sep-10 | SEP-10: Stellar Web Auth}
95
+ */
96
+ export declare function readChallengeTx(challengeTx: string, serverAccountID: string, networkPassphrase: string, homeDomains: string | string[], webAuthDomain: string): {
97
+ tx: Transaction;
98
+ clientAccountID: string;
99
+ matchedHomeDomain: string;
100
+ memo: string | null;
101
+ };
102
+ /**
103
+ * Verifies that for a SEP-10 challenge transaction all signatures on the
104
+ * transaction are accounted for and that the signatures meet a threshold on an
105
+ * account. A transaction is verified if it is signed by the server account, and
106
+ * all other signatures match a signer that has been provided as an argument,
107
+ * and those signatures meet a threshold on the account.
108
+ *
109
+ * Signers that are not prefixed as an address/account ID strkey (G...) will be
110
+ * ignored.
111
+ *
112
+ * Errors will be raised if:
113
+ * - The transaction is invalid according to
114
+ * {@link module:WebAuth~readChallengeTx}.
115
+ * - No client signatures are found on the transaction.
116
+ * - One or more signatures in the transaction are not identifiable as the
117
+ * server account or one of the signers provided in the arguments.
118
+ * - The signatures are all valid but do not meet the threshold.
119
+ *
120
+ * @param {string} challengeTx SEP0010 challenge transaction in base64.
121
+ * @param {string} serverAccountID The server's stellar account (public key).
122
+ * @param {string} networkPassphrase The network passphrase, e.g.: 'Test SDF
123
+ * Network ; September 2015' (see {@link Networks}).
124
+ * @param {number} threshold The required signatures threshold for verifying
125
+ * this transaction.
126
+ * @param {Array.<ServerApi.AccountRecordSigners>} signerSummary a map of all
127
+ * authorized signers to their weights. It's used to validate if the
128
+ * transaction signatures have met the given threshold.
129
+ * @param {string | Array.<string>} homeDomains The home domain(s) that should
130
+ * be included in the first Manage Data operation's string key. Required in
131
+ * verifyChallengeTxSigners() => readChallengeTx().
132
+ * @param {string} webAuthDomain The home domain that is expected to be included
133
+ * as the value of the Manage Data operation with the 'web_auth_domain' key,
134
+ * if present. Used in verifyChallengeTxSigners() => readChallengeTx().
135
+ * @returns {Array.<string>} The list of signers public keys that have signed
136
+ * the transaction, excluding the server account ID, given that the threshold
137
+ * was met.
138
+ * @throws {module:WebAuth.InvalidChallengeError} Will throw if the collective
139
+ * weight of the transaction's signers does not meet the necessary threshold
140
+ * to verify this transaction.
141
+ *
142
+ * @see {@link https://stellar.org/protocol/sep-10 | SEP-10: Stellar Web Auth}
143
+ *
144
+ * @example
145
+ * import { Networks, TransactionBuilder, WebAuth } from 'stellar-sdk';
146
+ *
147
+ * const serverKP = Keypair.random();
148
+ * const clientKP1 = Keypair.random();
149
+ * const clientKP2 = Keypair.random();
150
+ *
151
+ * // Challenge, possibly built in the server side
152
+ * const challenge = WebAuth.buildChallengeTx(
153
+ * serverKP,
154
+ * clientKP1.publicKey(),
155
+ * "SDF",
156
+ * 300,
157
+ * Networks.TESTNET
158
+ * );
159
+ *
160
+ * // clock.tick(200); // Simulates a 200 ms delay when communicating from server to client
161
+ *
162
+ * // Transaction gathered from a challenge, possibly from the client side
163
+ * const transaction = TransactionBuilder.fromXDR(challenge, Networks.TESTNET);
164
+ * transaction.sign(clientKP1, clientKP2);
165
+ * const signedChallenge = transaction
166
+ * .toEnvelope()
167
+ * .toXDR("base64")
168
+ * .toString();
169
+ *
170
+ * // Defining the threshold and signerSummary
171
+ * const threshold = 3;
172
+ * const signerSummary = [
173
+ * {
174
+ * key: this.clientKP1.publicKey(),
175
+ * weight: 1,
176
+ * },
177
+ * {
178
+ * key: this.clientKP2.publicKey(),
179
+ * weight: 2,
180
+ * },
181
+ * ];
182
+ *
183
+ * // The result below should be equal to [clientKP1.publicKey(), clientKP2.publicKey()]
184
+ * WebAuth.verifyChallengeTxThreshold(
185
+ * signedChallenge,
186
+ * serverKP.publicKey(),
187
+ * Networks.TESTNET,
188
+ * threshold,
189
+ * signerSummary
190
+ * );
191
+ */
192
+ export declare function verifyChallengeTxThreshold(challengeTx: string, serverAccountID: string, networkPassphrase: string, threshold: number, signerSummary: ServerApi.AccountRecordSigners[], homeDomains: string | string[], webAuthDomain: string): string[];
193
+ /**
194
+ * Verifies that for a SEP 10 challenge transaction all signatures on the
195
+ * transaction are accounted for. A transaction is verified if it is signed by
196
+ * the server account, and all other signatures match a signer that has been
197
+ * provided as an argument (as the accountIDs list). Additional signers can be
198
+ * provided that do not have a signature, but all signatures must be matched to
199
+ * a signer (accountIDs) for verification to succeed. If verification succeeds,
200
+ * a list of signers that were found is returned, not including the server
201
+ * account ID.
202
+ *
203
+ * Signers that are not prefixed as an address/account ID strkey (G...) will be
204
+ * ignored.
205
+ *
206
+ * Errors will be raised if:
207
+ * - The transaction is invalid according to
208
+ * {@link module:WebAuth~readChallengeTx}.
209
+ * - No client signatures are found on the transaction.
210
+ * - One or more signatures in the transaction are not identifiable as the
211
+ * server account or one of the signers provided in the arguments.
212
+ *
213
+ * @param {string} challengeTx SEP0010 challenge transaction in base64.
214
+ * @param {string} serverAccountID The server's stellar account (public key).
215
+ * @param {string} networkPassphrase The network passphrase, e.g.: 'Test SDF
216
+ * Network ; September 2015' (see {@link Networks}).
217
+ * @param {Array.<string>} signers The signers public keys. This list should
218
+ * contain the public keys for all signers that have signed the transaction.
219
+ * @param {string | Array.<string>} [homeDomains] The home domain(s) that should
220
+ * be included in the first Manage Data operation's string key. Required in
221
+ * readChallengeTx().
222
+ * @param {string} webAuthDomain The home domain that is expected to be included
223
+ * as the value of the Manage Data operation with the 'web_auth_domain' key,
224
+ * if present. Used in readChallengeTx().
225
+ * @returns {Array.<string>} The list of signers public keys that have signed
226
+ * the transaction, excluding the server account ID.
227
+ *
228
+ * @see {@link https://stellar.org/protocol/sep-10|SEP-10: Stellar Web Auth}
229
+ * @example
230
+ * import { Networks, TransactionBuilder, WebAuth } from 'stellar-sdk';
231
+ *
232
+ * const serverKP = Keypair.random();
233
+ * const clientKP1 = Keypair.random();
234
+ * const clientKP2 = Keypair.random();
235
+ *
236
+ * // Challenge, possibly built in the server side
237
+ * const challenge = WebAuth.buildChallengeTx(
238
+ * serverKP,
239
+ * clientKP1.publicKey(),
240
+ * "SDF",
241
+ * 300,
242
+ * Networks.TESTNET
243
+ * );
244
+ *
245
+ * // clock.tick(200); // Simulates a 200 ms delay when communicating from server to client
246
+ *
247
+ * // Transaction gathered from a challenge, possibly from the client side
248
+ * const transaction = TransactionBuilder.fromXDR(challenge, Networks.TESTNET);
249
+ * transaction.sign(clientKP1, clientKP2);
250
+ * const signedChallenge = transaction
251
+ * .toEnvelope()
252
+ * .toXDR("base64")
253
+ * .toString();
254
+ *
255
+ * // The result below should be equal to [clientKP1.publicKey(), clientKP2.publicKey()]
256
+ * WebAuth.verifyChallengeTxSigners(
257
+ * signedChallenge,
258
+ * serverKP.publicKey(),
259
+ * Networks.TESTNET,
260
+ * threshold,
261
+ * [clientKP1.publicKey(), clientKP2.publicKey()]
262
+ * );
263
+ */
264
+ export declare function verifyChallengeTxSigners(challengeTx: string, serverAccountID: string, networkPassphrase: string, signers: string[], homeDomains: string | string[], webAuthDomain: string): string[];
265
+ /**
266
+ * Verifies if a transaction was signed by the given account id.
267
+ *
268
+ * @param {Transaction | FeeBumpTransaction} transaction The signed transaction.
269
+ * @param {string} accountID The signer's public key.
270
+ * @returns {boolean} Whether or not `accountID` was found to have signed the
271
+ * transaction.
272
+ *
273
+ * @example
274
+ * let keypair = Keypair.random();
275
+ * const account = new StellarSdk.Account(keypair.publicKey(), "-1");
276
+ *
277
+ * const transaction = new TransactionBuilder(account, { fee: 100 })
278
+ * .setTimeout(30)
279
+ * .build();
280
+ *
281
+ * transaction.sign(keypair)
282
+ * WebAuth.verifyTxSignedBy(transaction, keypair.publicKey())
283
+ */
284
+ export declare function verifyTxSignedBy(transaction: FeeBumpTransaction | Transaction, accountID: string): boolean;
285
+ /**
286
+ * Checks if a transaction has been signed by one or more of the given signers,
287
+ * returning a list of non-repeated signers that were found to have signed the
288
+ * given transaction.
289
+ *
290
+ * @param {Transaction | FeeBumpTransaction} transaction The signed transaction.
291
+ * @param {Array.<string>} signers The signer's public keys.
292
+ * @returns {Array.<string>} A list of signers that were found to have signed
293
+ * the transaction.
294
+ *
295
+ * @example
296
+ * let keypair1 = Keypair.random();
297
+ * let keypair2 = Keypair.random();
298
+ * const account = new StellarSdk.Account(keypair1.publicKey(), "-1");
299
+ *
300
+ * const transaction = new TransactionBuilder(account, { fee: 100 })
301
+ * .setTimeout(30)
302
+ * .build();
303
+ *
304
+ * transaction.sign(keypair1, keypair2)
305
+ * WebAuth.gatherTxSigners(transaction, [keypair1.publicKey(), keypair2.publicKey()])
306
+ */
307
+ export declare function gatherTxSigners(transaction: FeeBumpTransaction | Transaction, signers: string[]): string[];
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildChallengeTx = buildChallengeTx;
7
+ exports.gatherTxSigners = gatherTxSigners;
8
+ exports.readChallengeTx = readChallengeTx;
9
+ exports.verifyChallengeTxSigners = verifyChallengeTxSigners;
10
+ exports.verifyChallengeTxThreshold = verifyChallengeTxThreshold;
11
+ exports.verifyTxSignedBy = verifyTxSignedBy;
12
+ var _randombytes = _interopRequireDefault(require("randombytes"));
13
+ var _stellarBase = require("@stellar/stellar-base");
14
+ var _utils = require("../utils");
15
+ var _errors = require("./errors");
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
18
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
20
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
21
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
22
+ function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
23
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
25
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
26
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
27
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
28
+ function buildChallengeTx(serverKeypair, clientAccountID, homeDomain) {
29
+ var timeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 300;
30
+ var networkPassphrase = arguments.length > 4 ? arguments[4] : undefined;
31
+ var webAuthDomain = arguments.length > 5 ? arguments[5] : undefined;
32
+ var memo = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
33
+ var clientDomain = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
34
+ var clientSigningKey = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
35
+ if (clientAccountID.startsWith("M") && memo) {
36
+ throw Error("memo cannot be used if clientAccountID is a muxed account");
37
+ }
38
+ var account = new _stellarBase.Account(serverKeypair.publicKey(), "-1");
39
+ var now = Math.floor(Date.now() / 1000);
40
+ var value = (0, _randombytes.default)(48).toString("base64");
41
+ var builder = new _stellarBase.TransactionBuilder(account, {
42
+ fee: _stellarBase.BASE_FEE,
43
+ networkPassphrase: networkPassphrase,
44
+ timebounds: {
45
+ minTime: now,
46
+ maxTime: now + timeout
47
+ }
48
+ }).addOperation(_stellarBase.Operation.manageData({
49
+ name: "".concat(homeDomain, " auth"),
50
+ value: value,
51
+ source: clientAccountID
52
+ })).addOperation(_stellarBase.Operation.manageData({
53
+ name: "web_auth_domain",
54
+ value: webAuthDomain,
55
+ source: account.accountId()
56
+ }));
57
+ if (clientDomain) {
58
+ if (!clientSigningKey) {
59
+ throw Error("clientSigningKey is required if clientDomain is provided");
60
+ }
61
+ builder.addOperation(_stellarBase.Operation.manageData({
62
+ name: "client_domain",
63
+ value: clientDomain,
64
+ source: clientSigningKey
65
+ }));
66
+ }
67
+ if (memo) {
68
+ builder.addMemo(_stellarBase.Memo.id(memo));
69
+ }
70
+ var transaction = builder.build();
71
+ transaction.sign(serverKeypair);
72
+ return transaction.toEnvelope().toXDR("base64").toString();
73
+ }
74
+ function readChallengeTx(challengeTx, serverAccountID, networkPassphrase, homeDomains, webAuthDomain) {
75
+ var _transaction$timeBoun;
76
+ if (serverAccountID.startsWith("M")) {
77
+ throw Error("Invalid serverAccountID: multiplexed accounts are not supported.");
78
+ }
79
+ var transaction;
80
+ try {
81
+ transaction = new _stellarBase.Transaction(challengeTx, networkPassphrase);
82
+ } catch (_unused) {
83
+ try {
84
+ transaction = new _stellarBase.FeeBumpTransaction(challengeTx, networkPassphrase);
85
+ } catch (_unused2) {
86
+ throw new _errors.InvalidChallengeError("Invalid challenge: unable to deserialize challengeTx transaction string");
87
+ }
88
+ throw new _errors.InvalidChallengeError("Invalid challenge: expected a Transaction but received a FeeBumpTransaction");
89
+ }
90
+ var sequence = Number.parseInt(transaction.sequence, 10);
91
+ if (sequence !== 0) {
92
+ throw new _errors.InvalidChallengeError("The transaction sequence number should be zero");
93
+ }
94
+ if (transaction.source !== serverAccountID) {
95
+ throw new _errors.InvalidChallengeError("The transaction source account is not equal to the server's account");
96
+ }
97
+ if (transaction.operations.length < 1) {
98
+ throw new _errors.InvalidChallengeError("The transaction should contain at least one operation");
99
+ }
100
+ var _transaction$operatio = _toArray(transaction.operations),
101
+ operation = _transaction$operatio[0],
102
+ subsequentOperations = _transaction$operatio.slice(1);
103
+ if (!operation.source) {
104
+ throw new _errors.InvalidChallengeError("The transaction's operation should contain a source account");
105
+ }
106
+ var clientAccountID = operation.source;
107
+ var memo = null;
108
+ if (transaction.memo.type !== _stellarBase.MemoNone) {
109
+ if (clientAccountID.startsWith("M")) {
110
+ throw new _errors.InvalidChallengeError("The transaction has a memo but the client account ID is a muxed account");
111
+ }
112
+ if (transaction.memo.type !== _stellarBase.MemoID) {
113
+ throw new _errors.InvalidChallengeError("The transaction's memo must be of type `id`");
114
+ }
115
+ memo = transaction.memo.value;
116
+ }
117
+ if (operation.type !== "manageData") {
118
+ throw new _errors.InvalidChallengeError("The transaction's operation type should be 'manageData'");
119
+ }
120
+ if (transaction.timeBounds && Number.parseInt((_transaction$timeBoun = transaction.timeBounds) === null || _transaction$timeBoun === void 0 ? void 0 : _transaction$timeBoun.maxTime, 10) === _stellarBase.TimeoutInfinite) {
121
+ throw new _errors.InvalidChallengeError("The transaction requires non-infinite timebounds");
122
+ }
123
+ if (!_utils.Utils.validateTimebounds(transaction, 60 * 5)) {
124
+ throw new _errors.InvalidChallengeError("The transaction has expired");
125
+ }
126
+ if (operation.value === undefined) {
127
+ throw new _errors.InvalidChallengeError("The transaction's operation values should not be null");
128
+ }
129
+ if (!operation.value) {
130
+ throw new _errors.InvalidChallengeError("The transaction's operation value should not be null");
131
+ }
132
+ if (Buffer.from(operation.value.toString(), "base64").length !== 48) {
133
+ throw new _errors.InvalidChallengeError("The transaction's operation value should be a 64 bytes base64 random string");
134
+ }
135
+ if (!homeDomains) {
136
+ throw new _errors.InvalidChallengeError("Invalid homeDomains: a home domain must be provided for verification");
137
+ }
138
+ var matchedHomeDomain;
139
+ if (typeof homeDomains === "string") {
140
+ if ("".concat(homeDomains, " auth") === operation.name) {
141
+ matchedHomeDomain = homeDomains;
142
+ }
143
+ } else if (Array.isArray(homeDomains)) {
144
+ matchedHomeDomain = homeDomains.find(function (domain) {
145
+ return "".concat(domain, " auth") === operation.name;
146
+ });
147
+ } else {
148
+ throw new _errors.InvalidChallengeError("Invalid homeDomains: homeDomains type is ".concat(_typeof(homeDomains), " but should be a string or an array"));
149
+ }
150
+ if (!matchedHomeDomain) {
151
+ throw new _errors.InvalidChallengeError("Invalid homeDomains: the transaction's operation key name does not match the expected home domain");
152
+ }
153
+ var _iterator = _createForOfIteratorHelper(subsequentOperations),
154
+ _step;
155
+ try {
156
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
157
+ var op = _step.value;
158
+ if (op.type !== "manageData") {
159
+ throw new _errors.InvalidChallengeError("The transaction has operations that are not of type 'manageData'");
160
+ }
161
+ if (op.source !== serverAccountID && op.name !== "client_domain") {
162
+ throw new _errors.InvalidChallengeError("The transaction has operations that are unrecognized");
163
+ }
164
+ if (op.name === "web_auth_domain") {
165
+ if (op.value === undefined) {
166
+ throw new _errors.InvalidChallengeError("'web_auth_domain' operation value should not be null");
167
+ }
168
+ if (op.value.compare(Buffer.from(webAuthDomain))) {
169
+ throw new _errors.InvalidChallengeError("'web_auth_domain' operation value does not match ".concat(webAuthDomain));
170
+ }
171
+ }
172
+ }
173
+ } catch (err) {
174
+ _iterator.e(err);
175
+ } finally {
176
+ _iterator.f();
177
+ }
178
+ if (!verifyTxSignedBy(transaction, serverAccountID)) {
179
+ throw new _errors.InvalidChallengeError("Transaction not signed by server: '".concat(serverAccountID, "'"));
180
+ }
181
+ return {
182
+ tx: transaction,
183
+ clientAccountID: clientAccountID,
184
+ matchedHomeDomain: matchedHomeDomain,
185
+ memo: memo
186
+ };
187
+ }
188
+ function verifyChallengeTxThreshold(challengeTx, serverAccountID, networkPassphrase, threshold, signerSummary, homeDomains, webAuthDomain) {
189
+ var signers = signerSummary.map(function (signer) {
190
+ return signer.key;
191
+ });
192
+ var signersFound = verifyChallengeTxSigners(challengeTx, serverAccountID, networkPassphrase, signers, homeDomains, webAuthDomain);
193
+ var weight = 0;
194
+ var _loop = function _loop() {
195
+ var _signerSummary$find;
196
+ var signer = _signersFound[_i];
197
+ var sigWeight = ((_signerSummary$find = signerSummary.find(function (s) {
198
+ return s.key === signer;
199
+ })) === null || _signerSummary$find === void 0 ? void 0 : _signerSummary$find.weight) || 0;
200
+ weight += sigWeight;
201
+ };
202
+ for (var _i = 0, _signersFound = signersFound; _i < _signersFound.length; _i++) {
203
+ _loop();
204
+ }
205
+ if (weight < threshold) {
206
+ throw new _errors.InvalidChallengeError("signers with weight ".concat(weight, " do not meet threshold ").concat(threshold, "\""));
207
+ }
208
+ return signersFound;
209
+ }
210
+ function verifyChallengeTxSigners(challengeTx, serverAccountID, networkPassphrase, signers, homeDomains, webAuthDomain) {
211
+ var _readChallengeTx = readChallengeTx(challengeTx, serverAccountID, networkPassphrase, homeDomains, webAuthDomain),
212
+ tx = _readChallengeTx.tx;
213
+ var serverKP;
214
+ try {
215
+ serverKP = _stellarBase.Keypair.fromPublicKey(serverAccountID);
216
+ } catch (err) {
217
+ throw new Error("Couldn't infer keypair from the provided 'serverAccountID': ".concat(err.message));
218
+ }
219
+ var clientSigners = new Set();
220
+ var _iterator2 = _createForOfIteratorHelper(signers),
221
+ _step2;
222
+ try {
223
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
224
+ var _signer = _step2.value;
225
+ if (_signer === serverKP.publicKey()) {
226
+ continue;
227
+ }
228
+ if (_signer.charAt(0) !== "G") {
229
+ continue;
230
+ }
231
+ clientSigners.add(_signer);
232
+ }
233
+ } catch (err) {
234
+ _iterator2.e(err);
235
+ } finally {
236
+ _iterator2.f();
237
+ }
238
+ if (clientSigners.size === 0) {
239
+ throw new _errors.InvalidChallengeError("No verifiable client signers provided, at least one G... address must be provided");
240
+ }
241
+ var clientSigningKey;
242
+ var _iterator3 = _createForOfIteratorHelper(tx.operations),
243
+ _step3;
244
+ try {
245
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
246
+ var op = _step3.value;
247
+ if (op.type === "manageData" && op.name === "client_domain") {
248
+ if (clientSigningKey) {
249
+ throw new _errors.InvalidChallengeError("Found more than one client_domain operation");
250
+ }
251
+ clientSigningKey = op.source;
252
+ }
253
+ }
254
+ } catch (err) {
255
+ _iterator3.e(err);
256
+ } finally {
257
+ _iterator3.f();
258
+ }
259
+ var allSigners = [serverKP.publicKey()].concat(_toConsumableArray(Array.from(clientSigners)));
260
+ if (clientSigningKey) {
261
+ allSigners.push(clientSigningKey);
262
+ }
263
+ var signersFound = gatherTxSigners(tx, allSigners);
264
+ var serverSignatureFound = false;
265
+ var clientSigningKeySignatureFound = false;
266
+ for (var _i2 = 0, _signersFound2 = signersFound; _i2 < _signersFound2.length; _i2++) {
267
+ var signer = _signersFound2[_i2];
268
+ if (signer === serverKP.publicKey()) {
269
+ serverSignatureFound = true;
270
+ }
271
+ if (signer === clientSigningKey) {
272
+ clientSigningKeySignatureFound = true;
273
+ }
274
+ }
275
+ if (!serverSignatureFound) {
276
+ throw new _errors.InvalidChallengeError("Transaction not signed by server: '".concat(serverKP.publicKey(), "'"));
277
+ }
278
+ if (clientSigningKey && !clientSigningKeySignatureFound) {
279
+ throw new _errors.InvalidChallengeError("Transaction not signed by the source account of the 'client_domain' " + "ManageData operation");
280
+ }
281
+ if (signersFound.length === 1) {
282
+ throw new _errors.InvalidChallengeError("None of the given signers match the transaction signatures");
283
+ }
284
+ if (signersFound.length !== tx.signatures.length) {
285
+ throw new _errors.InvalidChallengeError("Transaction has unrecognized signatures");
286
+ }
287
+ signersFound.splice(signersFound.indexOf(serverKP.publicKey()), 1);
288
+ if (clientSigningKey) {
289
+ signersFound.splice(signersFound.indexOf(clientSigningKey), 1);
290
+ }
291
+ return signersFound;
292
+ }
293
+ function verifyTxSignedBy(transaction, accountID) {
294
+ return gatherTxSigners(transaction, [accountID]).length !== 0;
295
+ }
296
+ function gatherTxSigners(transaction, signers) {
297
+ var hashedSignatureBase = transaction.hash();
298
+ var txSignatures = _toConsumableArray(transaction.signatures);
299
+ var signersFound = new Set();
300
+ var _iterator4 = _createForOfIteratorHelper(signers),
301
+ _step4;
302
+ try {
303
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
304
+ var signer = _step4.value;
305
+ if (txSignatures.length === 0) {
306
+ break;
307
+ }
308
+ var keypair = void 0;
309
+ try {
310
+ keypair = _stellarBase.Keypair.fromPublicKey(signer);
311
+ } catch (err) {
312
+ throw new _errors.InvalidChallengeError("Signer is not a valid address: ".concat(err.message));
313
+ }
314
+ for (var i = 0; i < txSignatures.length; i++) {
315
+ var decSig = txSignatures[i];
316
+ if (!decSig.hint().equals(keypair.signatureHint())) {
317
+ continue;
318
+ }
319
+ if (keypair.verify(hashedSignatureBase, decSig.signature())) {
320
+ signersFound.add(signer);
321
+ txSignatures.splice(i, 1);
322
+ break;
323
+ }
324
+ }
325
+ }
326
+ } catch (err) {
327
+ _iterator4.e(err);
328
+ } finally {
329
+ _iterator4.f();
330
+ }
331
+ return Array.from(signersFound);
332
+ }