xrpl 2.9.1 → 2.11.0

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 (325) hide show
  1. package/build/xrpl-latest-min.js +1 -1
  2. package/build/xrpl-latest-min.js.map +1 -1
  3. package/build/xrpl-latest.js +2680 -481
  4. package/build/xrpl-latest.js.map +1 -1
  5. package/dist/npm/Wallet/walletFromSecretNumbers.d.ts +7 -0
  6. package/dist/npm/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
  7. package/dist/npm/Wallet/walletFromSecretNumbers.js +27 -0
  8. package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -0
  9. package/dist/npm/client/index.d.ts +2 -1
  10. package/dist/npm/client/index.d.ts.map +1 -1
  11. package/dist/npm/client/index.js.map +1 -1
  12. package/dist/npm/index.d.ts +1 -0
  13. package/dist/npm/index.d.ts.map +1 -1
  14. package/dist/npm/index.js +3 -1
  15. package/dist/npm/index.js.map +1 -1
  16. package/dist/npm/models/common/index.d.ts +5 -0
  17. package/dist/npm/models/common/index.d.ts.map +1 -1
  18. package/dist/npm/models/ledger/AMM.d.ts +27 -0
  19. package/dist/npm/models/ledger/AMM.d.ts.map +1 -0
  20. package/dist/npm/models/ledger/AMM.js +3 -0
  21. package/dist/npm/models/ledger/AMM.js.map +1 -0
  22. package/dist/npm/models/ledger/AccountRoot.d.ts +5 -1
  23. package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
  24. package/dist/npm/models/ledger/AccountRoot.js +2 -0
  25. package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
  26. package/dist/npm/models/ledger/LedgerEntry.d.ts +2 -1
  27. package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
  28. package/dist/npm/models/methods/accountInfo.d.ts +1 -0
  29. package/dist/npm/models/methods/accountInfo.d.ts.map +1 -1
  30. package/dist/npm/models/methods/ammInfo.d.ts +39 -0
  31. package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
  32. package/dist/npm/models/methods/ammInfo.js +3 -0
  33. package/dist/npm/models/methods/ammInfo.js.map +1 -0
  34. package/dist/npm/models/methods/index.d.ts +4 -3
  35. package/dist/npm/models/methods/index.d.ts.map +1 -1
  36. package/dist/npm/models/methods/ledgerEntry.d.ts +10 -0
  37. package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
  38. package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
  39. package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
  40. package/dist/npm/models/transactions/AMMBid.js +56 -0
  41. package/dist/npm/models/transactions/AMMBid.js.map +1 -0
  42. package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
  43. package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
  44. package/dist/npm/models/transactions/AMMCreate.js +32 -0
  45. package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
  46. package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
  47. package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
  48. package/dist/npm/models/transactions/AMMDelete.js +22 -0
  49. package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
  50. package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
  51. package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
  52. package/dist/npm/models/transactions/AMMDeposit.js +51 -0
  53. package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
  54. package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
  55. package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
  56. package/dist/npm/models/transactions/AMMVote.js +32 -0
  57. package/dist/npm/models/transactions/AMMVote.js.map +1 -0
  58. package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
  59. package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
  60. package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
  61. package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
  62. package/dist/npm/models/transactions/accountSet.d.ts +2 -1
  63. package/dist/npm/models/transactions/accountSet.d.ts.map +1 -1
  64. package/dist/npm/models/transactions/accountSet.js +1 -0
  65. package/dist/npm/models/transactions/accountSet.js.map +1 -1
  66. package/dist/npm/models/transactions/clawback.d.ts +9 -0
  67. package/dist/npm/models/transactions/clawback.d.ts.map +1 -0
  68. package/dist/npm/models/transactions/clawback.js +19 -0
  69. package/dist/npm/models/transactions/clawback.js.map +1 -0
  70. package/dist/npm/models/transactions/common.d.ts +2 -1
  71. package/dist/npm/models/transactions/common.d.ts.map +1 -1
  72. package/dist/npm/models/transactions/common.js +12 -1
  73. package/dist/npm/models/transactions/common.js.map +1 -1
  74. package/dist/npm/models/transactions/index.d.ts +7 -0
  75. package/dist/npm/models/transactions/index.d.ts.map +1 -1
  76. package/dist/npm/models/transactions/index.js +5 -1
  77. package/dist/npm/models/transactions/index.js.map +1 -1
  78. package/dist/npm/models/transactions/transaction.d.ts +8 -1
  79. package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
  80. package/dist/npm/models/transactions/transaction.js +28 -0
  81. package/dist/npm/models/transactions/transaction.js.map +1 -1
  82. package/dist/npm/models/utils/flags.d.ts.map +1 -1
  83. package/dist/npm/models/utils/flags.js +17 -23
  84. package/dist/npm/models/utils/flags.js.map +1 -1
  85. package/dist/npm/models/utils/index.js +1 -1
  86. package/dist/npm/models/utils/index.js.map +1 -1
  87. package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
  88. package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
  89. package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
  90. package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
  91. package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
  92. package/dist/npm/src/client/index.d.ts +2 -1
  93. package/dist/npm/src/client/index.d.ts.map +1 -1
  94. package/dist/npm/src/client/index.js.map +1 -1
  95. package/dist/npm/src/index.d.ts +1 -0
  96. package/dist/npm/src/index.d.ts.map +1 -1
  97. package/dist/npm/src/index.js +3 -1
  98. package/dist/npm/src/index.js.map +1 -1
  99. package/dist/npm/src/models/common/index.d.ts +5 -0
  100. package/dist/npm/src/models/common/index.d.ts.map +1 -1
  101. package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
  102. package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
  103. package/dist/npm/src/models/ledger/AMM.js +3 -0
  104. package/dist/npm/src/models/ledger/AMM.js.map +1 -0
  105. package/dist/npm/src/models/ledger/AccountRoot.d.ts +5 -1
  106. package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
  107. package/dist/npm/src/models/ledger/AccountRoot.js +2 -0
  108. package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
  109. package/dist/npm/src/models/ledger/LedgerEntry.d.ts +2 -1
  110. package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
  111. package/dist/npm/src/models/methods/accountInfo.d.ts +1 -0
  112. package/dist/npm/src/models/methods/accountInfo.d.ts.map +1 -1
  113. package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
  114. package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
  115. package/dist/npm/src/models/methods/ammInfo.js +3 -0
  116. package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
  117. package/dist/npm/src/models/methods/index.d.ts +4 -3
  118. package/dist/npm/src/models/methods/index.d.ts.map +1 -1
  119. package/dist/npm/src/models/methods/ledgerEntry.d.ts +10 -0
  120. package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
  121. package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
  122. package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
  123. package/dist/npm/src/models/transactions/AMMBid.js +56 -0
  124. package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
  125. package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
  126. package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
  127. package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
  128. package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
  129. package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
  130. package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
  131. package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
  132. package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
  133. package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
  134. package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
  135. package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
  136. package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
  137. package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
  138. package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
  139. package/dist/npm/src/models/transactions/AMMVote.js +32 -0
  140. package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
  141. package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
  142. package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
  143. package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
  144. package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
  145. package/dist/npm/src/models/transactions/accountSet.d.ts +2 -1
  146. package/dist/npm/src/models/transactions/accountSet.d.ts.map +1 -1
  147. package/dist/npm/src/models/transactions/accountSet.js +1 -0
  148. package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
  149. package/dist/npm/src/models/transactions/clawback.d.ts +9 -0
  150. package/dist/npm/src/models/transactions/clawback.d.ts.map +1 -0
  151. package/dist/npm/src/models/transactions/clawback.js +19 -0
  152. package/dist/npm/src/models/transactions/clawback.js.map +1 -0
  153. package/dist/npm/src/models/transactions/common.d.ts +2 -1
  154. package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
  155. package/dist/npm/src/models/transactions/common.js +12 -1
  156. package/dist/npm/src/models/transactions/common.js.map +1 -1
  157. package/dist/npm/src/models/transactions/index.d.ts +7 -0
  158. package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
  159. package/dist/npm/src/models/transactions/index.js +5 -1
  160. package/dist/npm/src/models/transactions/index.js.map +1 -1
  161. package/dist/npm/src/models/transactions/transaction.d.ts +8 -1
  162. package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
  163. package/dist/npm/src/models/transactions/transaction.js +28 -0
  164. package/dist/npm/src/models/transactions/transaction.js.map +1 -1
  165. package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
  166. package/dist/npm/src/models/utils/flags.js +17 -23
  167. package/dist/npm/src/models/utils/flags.js.map +1 -1
  168. package/dist/npm/src/models/utils/index.js +1 -1
  169. package/dist/npm/src/models/utils/index.js.map +1 -1
  170. package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
  171. package/dist/npm/src/sugar/autofill.js +4 -3
  172. package/dist/npm/src/sugar/autofill.js.map +1 -1
  173. package/dist/npm/sugar/autofill.d.ts.map +1 -1
  174. package/dist/npm/sugar/autofill.js +4 -3
  175. package/dist/npm/sugar/autofill.js.map +1 -1
  176. package/package.json +8 -6
  177. package/src/ECDSA.ts +6 -0
  178. package/src/Wallet/defaultFaucets.ts +82 -0
  179. package/src/Wallet/fundWallet.ts +344 -0
  180. package/src/Wallet/index.ts +504 -0
  181. package/src/Wallet/rfc1751.ts +190 -0
  182. package/src/Wallet/rfc1751Words.json +243 -0
  183. package/src/Wallet/signer.ts +173 -0
  184. package/src/Wallet/walletFromSecretNumbers.ts +37 -0
  185. package/src/client/BroadcastClient.ts +84 -0
  186. package/src/client/ConnectionManager.ts +40 -0
  187. package/src/client/ExponentialBackoff.ts +71 -0
  188. package/src/client/RequestManager.ts +194 -0
  189. package/src/client/WSWrapper.ts +106 -0
  190. package/src/client/connection.ts +593 -0
  191. package/src/client/index.ts +712 -0
  192. package/src/client/partialPayment.ts +153 -0
  193. package/src/errors.ts +161 -0
  194. package/src/index.ts +20 -0
  195. package/src/models/common/index.ts +149 -0
  196. package/src/models/index.ts +16 -0
  197. package/src/models/ledger/AMM.ts +78 -0
  198. package/src/models/ledger/AccountRoot.ts +217 -0
  199. package/src/models/ledger/Amendments.ts +45 -0
  200. package/src/models/ledger/BaseLedgerEntry.ts +3 -0
  201. package/src/models/ledger/Check.ts +70 -0
  202. package/src/models/ledger/DepositPreauth.ts +35 -0
  203. package/src/models/ledger/DirectoryNode.ts +46 -0
  204. package/src/models/ledger/Escrow.ts +74 -0
  205. package/src/models/ledger/FeeSettings.ts +52 -0
  206. package/src/models/ledger/Ledger.ts +65 -0
  207. package/src/models/ledger/LedgerEntry.ts +34 -0
  208. package/src/models/ledger/LedgerHashes.ts +24 -0
  209. package/src/models/ledger/NFTokenOffer.ts +16 -0
  210. package/src/models/ledger/NFTokenPage.ts +20 -0
  211. package/src/models/ledger/NegativeUNL.ts +34 -0
  212. package/src/models/ledger/Offer.ts +52 -0
  213. package/src/models/ledger/PayChannel.ts +107 -0
  214. package/src/models/ledger/RippleState.ts +88 -0
  215. package/src/models/ledger/SignerList.ts +56 -0
  216. package/src/models/ledger/Ticket.ts +36 -0
  217. package/src/models/ledger/index.ts +58 -0
  218. package/src/models/methods/accountChannels.ts +93 -0
  219. package/src/models/methods/accountCurrencies.ts +45 -0
  220. package/src/models/methods/accountInfo.ts +182 -0
  221. package/src/models/methods/accountLines.ts +137 -0
  222. package/src/models/methods/accountNFTs.ts +72 -0
  223. package/src/models/methods/accountObjects.ts +120 -0
  224. package/src/models/methods/accountOffers.ts +100 -0
  225. package/src/models/methods/accountTx.ts +109 -0
  226. package/src/models/methods/ammInfo.ts +145 -0
  227. package/src/models/methods/baseMethod.ts +58 -0
  228. package/src/models/methods/bookOffers.ts +96 -0
  229. package/src/models/methods/channelVerify.ts +41 -0
  230. package/src/models/methods/depositAuthorized.ts +56 -0
  231. package/src/models/methods/fee.ts +91 -0
  232. package/src/models/methods/gatewayBalances.ts +85 -0
  233. package/src/models/methods/index.ts +391 -0
  234. package/src/models/methods/ledger.ts +125 -0
  235. package/src/models/methods/ledgerClosed.ts +32 -0
  236. package/src/models/methods/ledgerCurrent.ts +31 -0
  237. package/src/models/methods/ledgerData.ts +78 -0
  238. package/src/models/methods/ledgerEntry.ts +177 -0
  239. package/src/models/methods/manifest.ts +54 -0
  240. package/src/models/methods/nftBuyOffers.ts +37 -0
  241. package/src/models/methods/nftHistory.ts +113 -0
  242. package/src/models/methods/nftInfo.ts +25 -0
  243. package/src/models/methods/nftSellOffers.ts +37 -0
  244. package/src/models/methods/norippleCheck.ts +82 -0
  245. package/src/models/methods/pathFind.ts +116 -0
  246. package/src/models/methods/ping.ts +21 -0
  247. package/src/models/methods/random.ts +23 -0
  248. package/src/models/methods/ripplePathFind.ts +81 -0
  249. package/src/models/methods/serverInfo.ts +257 -0
  250. package/src/models/methods/serverState.ts +77 -0
  251. package/src/models/methods/submit.ts +94 -0
  252. package/src/models/methods/submitMultisigned.ts +51 -0
  253. package/src/models/methods/subscribe.ts +435 -0
  254. package/src/models/methods/transactionEntry.ts +47 -0
  255. package/src/models/methods/tx.ts +69 -0
  256. package/src/models/methods/unsubscribe.ts +49 -0
  257. package/src/models/transactions/AMMBid.ts +140 -0
  258. package/src/models/transactions/AMMCreate.ts +80 -0
  259. package/src/models/transactions/AMMDelete.ts +55 -0
  260. package/src/models/transactions/AMMDeposit.ts +130 -0
  261. package/src/models/transactions/AMMVote.ts +71 -0
  262. package/src/models/transactions/AMMWithdraw.ts +126 -0
  263. package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
  264. package/src/models/transactions/NFTokenBurn.ts +48 -0
  265. package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
  266. package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
  267. package/src/models/transactions/NFTokenMint.ts +123 -0
  268. package/src/models/transactions/UNLModify.ts +20 -0
  269. package/src/models/transactions/accountDelete.ts +50 -0
  270. package/src/models/transactions/accountSet.ts +228 -0
  271. package/src/models/transactions/checkCancel.ts +34 -0
  272. package/src/models/transactions/checkCash.ts +73 -0
  273. package/src/models/transactions/checkCreate.ts +90 -0
  274. package/src/models/transactions/clawback.ts +49 -0
  275. package/src/models/transactions/common.ts +295 -0
  276. package/src/models/transactions/depositPreauth.ts +68 -0
  277. package/src/models/transactions/enableAmendment.ts +26 -0
  278. package/src/models/transactions/escrowCancel.ts +45 -0
  279. package/src/models/transactions/escrowCreate.ts +100 -0
  280. package/src/models/transactions/escrowFinish.ts +63 -0
  281. package/src/models/transactions/index.ts +66 -0
  282. package/src/models/transactions/metadata.ts +69 -0
  283. package/src/models/transactions/offerCancel.ts +37 -0
  284. package/src/models/transactions/offerCreate.ts +144 -0
  285. package/src/models/transactions/payment.ts +278 -0
  286. package/src/models/transactions/paymentChannelClaim.ts +165 -0
  287. package/src/models/transactions/paymentChannelCreate.ts +116 -0
  288. package/src/models/transactions/paymentChannelFund.ts +65 -0
  289. package/src/models/transactions/setFee.ts +48 -0
  290. package/src/models/transactions/setRegularKey.ts +33 -0
  291. package/src/models/transactions/signerListSet.ts +89 -0
  292. package/src/models/transactions/ticketCreate.ts +50 -0
  293. package/src/models/transactions/transaction.ts +303 -0
  294. package/src/models/transactions/trustSet.ts +146 -0
  295. package/src/models/utils/flags.ts +98 -0
  296. package/src/models/utils/index.ts +37 -0
  297. package/src/sugar/autofill.ts +373 -0
  298. package/src/sugar/balances.ts +123 -0
  299. package/src/sugar/getFeeXrp.ts +45 -0
  300. package/src/sugar/getLedgerIndex.ts +15 -0
  301. package/src/sugar/getOrderbook.ts +152 -0
  302. package/src/sugar/index.ts +11 -0
  303. package/src/sugar/submit.ts +305 -0
  304. package/src/sugar/utils.ts +29 -0
  305. package/src/utils/derive.ts +23 -0
  306. package/src/utils/getBalanceChanges.ts +186 -0
  307. package/src/utils/getNFTokenID.ts +97 -0
  308. package/src/utils/hashes/HashPrefix.ts +40 -0
  309. package/src/utils/hashes/README.md +65 -0
  310. package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
  311. package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
  312. package/src/utils/hashes/SHAMap/index.ts +41 -0
  313. package/src/utils/hashes/SHAMap/node.ts +14 -0
  314. package/src/utils/hashes/hashLedger.ts +236 -0
  315. package/src/utils/hashes/index.ts +187 -0
  316. package/src/utils/hashes/ledgerSpaces.ts +34 -0
  317. package/src/utils/hashes/sha512Half.ts +19 -0
  318. package/src/utils/index.ts +223 -0
  319. package/src/utils/parseNFTokenID.ts +84 -0
  320. package/src/utils/quality.ts +169 -0
  321. package/src/utils/signPaymentChannelClaim.ts +27 -0
  322. package/src/utils/stringConversion.ts +27 -0
  323. package/src/utils/timeConversion.ts +53 -0
  324. package/src/utils/verifyPaymentChannelClaim.ts +30 -0
  325. package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,123 @@
1
+ import flatMap from 'lodash/flatMap'
2
+
3
+ import type { Balance, Client } from '..'
4
+ import {
5
+ AccountLinesRequest,
6
+ AccountLinesTrustline,
7
+ LedgerIndex,
8
+ AccountInfoRequest,
9
+ } from '../models'
10
+ import { dropsToXrp } from '../utils'
11
+
12
+ function formatBalances(trustlines: AccountLinesTrustline[]): Balance[] {
13
+ return trustlines.map((trustline) => ({
14
+ value: trustline.balance,
15
+ currency: trustline.currency,
16
+ issuer: trustline.account,
17
+ }))
18
+ }
19
+
20
+ /**
21
+ * Get the XRP balance for an account.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const client = new Client(wss://s.altnet.rippletest.net:51233)
26
+ * const balance = await client.getXrpBalance('rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn')
27
+ * console.log(balance)
28
+ * /// '200'
29
+ * ```
30
+ *
31
+ * @param this - Client.
32
+ * @param address - Address of the account to retrieve XRP balance.
33
+ * @param options - Options to include for getting the XRP balance.
34
+ * @param options.ledger_index - Retrieve the account balances at a given
35
+ * ledger_index.
36
+ * @param options.ledger_hash - Retrieve the account balances at the ledger with
37
+ * a given ledger_hash.
38
+ * @returns The XRP balance of the account (as a string).
39
+ */
40
+ async function getXrpBalance(
41
+ this: Client,
42
+ address: string,
43
+ options: {
44
+ ledger_hash?: string
45
+ ledger_index?: LedgerIndex
46
+ } = {},
47
+ ): Promise<string> {
48
+ const xrpRequest: AccountInfoRequest = {
49
+ command: 'account_info',
50
+ account: address,
51
+ ledger_index: options.ledger_index ?? 'validated',
52
+ ledger_hash: options.ledger_hash,
53
+ }
54
+ const response = await this.request(xrpRequest)
55
+ return dropsToXrp(response.result.account_data.Balance)
56
+ }
57
+
58
+ /**
59
+ * Get XRP/non-XRP balances for an account.
60
+ *
61
+ * @param this - Client.
62
+ * @param address - Address of the account to retrieve balances for.
63
+ * @param options - Allows the client to specify a ledger_hash, ledger_index,
64
+ * filter by peer, and/or limit number of balances.
65
+ * @param options.ledger_index - Retrieve the account balances at a given
66
+ * ledger_index.
67
+ * @param options.ledger_hash - Retrieve the account balances at the ledger with
68
+ * a given ledger_hash.
69
+ * @param options.peer - Filter balances by peer.
70
+ * @param options.limit - Limit number of balances to return.
71
+ * @returns An array of XRP/non-XRP balances for the given account.
72
+ */
73
+ // eslint-disable-next-line max-lines-per-function -- Longer definition is required for end users to see the definition.
74
+ async function getBalances(
75
+ this: Client,
76
+ address: string,
77
+ options: {
78
+ ledger_hash?: string
79
+ ledger_index?: LedgerIndex
80
+ peer?: string
81
+ limit?: number
82
+ } = {},
83
+ ): Promise<
84
+ Array<{ value: string; currency: string; issuer?: string | undefined }>
85
+ > {
86
+ const balances: Balance[] = []
87
+
88
+ // get XRP balance
89
+ let xrpPromise: Promise<string> = Promise.resolve('')
90
+ if (!options.peer) {
91
+ xrpPromise = this.getXrpBalance(address, {
92
+ ledger_hash: options.ledger_hash,
93
+ ledger_index: options.ledger_index,
94
+ })
95
+ }
96
+
97
+ // get non-XRP balances
98
+ const linesRequest: AccountLinesRequest = {
99
+ command: 'account_lines',
100
+ account: address,
101
+ ledger_index: options.ledger_index ?? 'validated',
102
+ ledger_hash: options.ledger_hash,
103
+ peer: options.peer,
104
+ limit: options.limit,
105
+ }
106
+ const linesPromise = this.requestAll(linesRequest)
107
+
108
+ // combine results
109
+ await Promise.all([xrpPromise, linesPromise]).then(
110
+ ([xrpBalance, linesResponses]) => {
111
+ const accountLinesBalance = flatMap(linesResponses, (response) =>
112
+ formatBalances(response.result.lines),
113
+ )
114
+ if (xrpBalance !== '') {
115
+ balances.push({ currency: 'XRP', value: xrpBalance })
116
+ }
117
+ balances.push(...accountLinesBalance)
118
+ },
119
+ )
120
+ return balances.slice(0, options.limit)
121
+ }
122
+
123
+ export { getXrpBalance, getBalances }
@@ -0,0 +1,45 @@
1
+ import BigNumber from 'bignumber.js'
2
+
3
+ import type { Client } from '..'
4
+ import { XrplError } from '../errors'
5
+
6
+ const NUM_DECIMAL_PLACES = 6
7
+ const BASE_10 = 10
8
+
9
+ /**
10
+ * Calculates the current transaction fee for the ledger.
11
+ * Note: This is a public API that can be called directly.
12
+ *
13
+ * @param client - The Client used to connect to the ledger.
14
+ * @param cushion - The fee cushion to use.
15
+ * @returns The transaction fee.
16
+ */
17
+ export default async function getFeeXrp(
18
+ client: Client,
19
+ cushion?: number,
20
+ ): Promise<string> {
21
+ const feeCushion = cushion ?? client.feeCushion
22
+
23
+ const serverInfo = (await client.request({ command: 'server_info' })).result
24
+ .info
25
+
26
+ const baseFee = serverInfo.validated_ledger?.base_fee_xrp
27
+
28
+ if (baseFee == null) {
29
+ throw new XrplError(
30
+ 'getFeeXrp: Could not get base_fee_xrp from server_info',
31
+ )
32
+ }
33
+
34
+ const baseFeeXrp = new BigNumber(baseFee)
35
+ if (serverInfo.load_factor == null) {
36
+ // https://github.com/ripple/rippled/issues/3812#issuecomment-816871100
37
+ serverInfo.load_factor = 1
38
+ }
39
+ let fee = baseFeeXrp.times(serverInfo.load_factor).times(feeCushion)
40
+
41
+ // Cap fee to `client.maxFeeXRP`
42
+ fee = BigNumber.min(fee, client.maxFeeXRP)
43
+ // Round fee to 6 decimal places
44
+ return new BigNumber(fee.toFixed(NUM_DECIMAL_PLACES)).toString(BASE_10)
45
+ }
@@ -0,0 +1,15 @@
1
+ import type { Client } from '..'
2
+
3
+ /**
4
+ * Returns the index of the most recently validated ledger.
5
+ *
6
+ * @param this - The Client used to connect to the ledger.
7
+ * @returns The most recently validated ledger index.
8
+ */
9
+ export default async function getLedgerIndex(this: Client): Promise<number> {
10
+ const ledgerResponse = await this.request({
11
+ command: 'ledger',
12
+ ledger_index: 'validated',
13
+ })
14
+ return ledgerResponse.result.ledger_index
15
+ }
@@ -0,0 +1,152 @@
1
+ /* eslint-disable max-lines-per-function -- Needs to process orderbooks. */
2
+ import BigNumber from 'bignumber.js'
3
+ import flatMap from 'lodash/flatMap'
4
+
5
+ import type { Client } from '../client'
6
+ import { ValidationError } from '../errors'
7
+ import { LedgerIndex } from '../models/common'
8
+ import { OfferFlags } from '../models/ledger/Offer'
9
+ import {
10
+ BookOffer,
11
+ BookOfferCurrency,
12
+ BookOffersRequest,
13
+ } from '../models/methods/bookOffers'
14
+
15
+ const DEFAULT_LIMIT = 20
16
+
17
+ function sortOffers(offers: BookOffer[]): BookOffer[] {
18
+ return offers.sort((offerA, offerB) => {
19
+ const qualityA = offerA.quality ?? 0
20
+ const qualityB = offerB.quality ?? 0
21
+
22
+ return new BigNumber(qualityA).comparedTo(qualityB)
23
+ })
24
+ }
25
+
26
+ const getOrderbookOptionsSet = new Set([
27
+ 'limit',
28
+ 'ledger_index',
29
+ 'ledger_hash',
30
+ 'taker',
31
+ ])
32
+
33
+ /**
34
+ * Fetch orderbook (buy/sell orders) between two currency pairs. This checks both sides of the orderbook
35
+ * by making two `order_book` requests (with the second reversing takerPays and takerGets). Returned offers are
36
+ * not normalized in this function, so either currency could be takerGets or takerPays.
37
+ *
38
+ * @param this - Client.
39
+ * @param currency1 - Specification of one currency involved. (With a currency code and optionally an issuer)
40
+ * @param currency2 - Specification of a second currency involved. (With a currency code and optionally an issuer)
41
+ * @param options - Options allowing the client to specify ledger_index,
42
+ * ledger_hash, filter by taker, and/or limit number of orders.
43
+ * @param options.ledger_index - Retrieve the orderbook at a given ledger_index.
44
+ * @param options.ledger_hash - Retrieve the orderbook at the ledger with a
45
+ * given ledger_hash.
46
+ * @param options.taker - Filter orders by taker.
47
+ * @param options.limit - The limit passed into each book_offers request.
48
+ * Can return more than this due to two calls being made. Defaults to 20.
49
+ * @returns An object containing buy and sell objects.
50
+ */
51
+ // eslint-disable-next-line max-params, complexity -- Once bound to Client, getOrderbook only has 3 parameters.
52
+ async function getOrderbook(
53
+ this: Client,
54
+ currency1: BookOfferCurrency,
55
+ currency2: BookOfferCurrency,
56
+ options: {
57
+ limit?: number
58
+ ledger_index?: LedgerIndex
59
+ ledger_hash?: string | null
60
+ taker?: string | null
61
+ } = {},
62
+ ): Promise<{
63
+ buy: BookOffer[]
64
+ sell: BookOffer[]
65
+ }> {
66
+ Object.keys(options).forEach((key) => {
67
+ if (!getOrderbookOptionsSet.has(key)) {
68
+ throw new ValidationError(`Unexpected option: ${key}`, options)
69
+ }
70
+ })
71
+
72
+ if (options.limit && typeof options.limit !== 'number') {
73
+ throw new ValidationError('limit must be a number', options.limit)
74
+ }
75
+
76
+ if (
77
+ options.ledger_index &&
78
+ !(
79
+ typeof options.ledger_index === 'number' ||
80
+ (typeof options.ledger_index === 'string' &&
81
+ ['validated', 'closed', 'current'].includes(options.ledger_index))
82
+ )
83
+ ) {
84
+ throw new ValidationError(
85
+ 'ledger_index must be a number or a string of "validated", "closed", or "current"',
86
+ options.ledger_index,
87
+ )
88
+ }
89
+
90
+ if (
91
+ options.ledger_hash !== undefined &&
92
+ options.ledger_hash !== null &&
93
+ typeof options.ledger_hash !== 'string'
94
+ ) {
95
+ throw new ValidationError(
96
+ 'ledger_hash must be a string',
97
+ options.ledger_hash,
98
+ )
99
+ }
100
+
101
+ if (options.taker !== undefined && typeof options.taker !== 'string') {
102
+ throw new ValidationError('taker must be a string', options.taker)
103
+ }
104
+
105
+ const request: BookOffersRequest = {
106
+ command: 'book_offers',
107
+ taker_pays: currency1,
108
+ taker_gets: currency2,
109
+ ledger_index: options.ledger_index ?? 'validated',
110
+ ledger_hash: options.ledger_hash === null ? undefined : options.ledger_hash,
111
+ limit: options.limit ?? DEFAULT_LIMIT,
112
+ taker: options.taker ? options.taker : undefined,
113
+ }
114
+ // 2. Make Request
115
+ const directOfferResults = await this.requestAll(request)
116
+ request.taker_gets = currency1
117
+ request.taker_pays = currency2
118
+ const reverseOfferResults = await this.requestAll(request)
119
+ // 3. Return Formatted Response
120
+ const directOffers = flatMap(
121
+ directOfferResults,
122
+ (directOfferResult) => directOfferResult.result.offers,
123
+ )
124
+ const reverseOffers = flatMap(
125
+ reverseOfferResults,
126
+ (reverseOfferResult) => reverseOfferResult.result.offers,
127
+ )
128
+
129
+ const orders = [...directOffers, ...reverseOffers]
130
+ // separate out the buy and sell orders
131
+ const buy: BookOffer[] = []
132
+ const sell: BookOffer[] = []
133
+ orders.forEach((order) => {
134
+ // eslint-disable-next-line no-bitwise -- necessary for flags check
135
+ if ((order.Flags & OfferFlags.lsfSell) === 0) {
136
+ buy.push(order)
137
+ } else {
138
+ sell.push(order)
139
+ }
140
+ })
141
+ /*
142
+ * Sort the orders
143
+ * for both buys and sells, lowest quality is closest to mid-market
144
+ * we sort the orders so that earlier orders are closer to mid-market
145
+ */
146
+ return {
147
+ buy: sortOffers(buy).slice(0, options.limit),
148
+ sell: sortOffers(sell).slice(0, options.limit),
149
+ }
150
+ }
151
+
152
+ export default getOrderbook
@@ -0,0 +1,11 @@
1
+ export { default as autofill } from './autofill'
2
+
3
+ export { getBalances, getXrpBalance } from './balances'
4
+
5
+ export { default as getLedgerIndex } from './getLedgerIndex'
6
+
7
+ export { default as getOrderbook } from './getOrderbook'
8
+
9
+ export * from './submit'
10
+
11
+ export * from './utils'
@@ -0,0 +1,305 @@
1
+ import { decode, encode } from 'ripple-binary-codec'
2
+
3
+ import type { Client, SubmitRequest, SubmitResponse, Wallet } from '..'
4
+ import { ValidationError, XrplError } from '../errors'
5
+ import { Signer } from '../models/common'
6
+ import { TxRequest, TxResponse } from '../models/methods'
7
+ import { Transaction } from '../models/transactions'
8
+ import { BaseTransaction } from '../models/transactions/common'
9
+ import { hashes } from '../utils'
10
+
11
+ /** Approximate time for a ledger to close, in milliseconds */
12
+ const LEDGER_CLOSE_TIME = 1000
13
+
14
+ async function sleep(ms: number): Promise<void> {
15
+ return new Promise((resolve) => {
16
+ setTimeout(resolve, ms)
17
+ })
18
+ }
19
+
20
+ /**
21
+ * Submits a signed/unsigned transaction.
22
+ * Steps performed on a transaction:
23
+ * 1. Autofill.
24
+ * 2. Sign & Encode.
25
+ * 3. Submit.
26
+ *
27
+ * @param this - A Client.
28
+ * @param transaction - A transaction to autofill, sign & encode, and submit.
29
+ * @param opts - (Optional) Options used to sign and submit a transaction.
30
+ * @param opts.autofill - If true, autofill a transaction.
31
+ * @param opts.failHard - If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
32
+ * @param opts.wallet - A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
33
+ * @returns A promise that contains SubmitResponse.
34
+ * @throws RippledError if submit request fails.
35
+ */
36
+ async function submit(
37
+ this: Client,
38
+ transaction: Transaction | string,
39
+ opts?: {
40
+ // If true, autofill a transaction.
41
+ autofill?: boolean
42
+ // If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
43
+ failHard?: boolean
44
+ // A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
45
+ wallet?: Wallet
46
+ },
47
+ ): Promise<SubmitResponse> {
48
+ const signedTx = await getSignedTx(this, transaction, opts)
49
+ return submitRequest(this, signedTx, opts?.failHard)
50
+ }
51
+
52
+ /**
53
+ * Asynchronously submits a transaction and verifies that it has been included in a
54
+ * validated ledger (or has errored/will not be included for some reason).
55
+ * See [Reliable Transaction Submission](https://xrpl.org/reliable-transaction-submission.html).
56
+ *
57
+ * @example
58
+ *
59
+ * ```ts
60
+ * const { Client, Wallet } = require('xrpl')
61
+ * const client = new Client('wss://s.altnet.rippletest.net:51233')
62
+ *
63
+ * async function submitTransaction() {
64
+ * const senderWallet = client.fundWallet()
65
+ * const recipientWallet = client.fundWallet()
66
+ *
67
+ * const transaction = {
68
+ * TransactionType: 'Payment',
69
+ * Account: senderWallet.address,
70
+ * Destination: recipientWallet.address,
71
+ * Amount: '10'
72
+ * }
73
+ *
74
+ * try {
75
+ * await client.submit(signedTransaction, { wallet: senderWallet })
76
+ * console.log(result)
77
+ * } catch (error) {
78
+ * console.error(`Failed to submit transaction: ${error}`)
79
+ * }
80
+ * }
81
+ *
82
+ * submitTransaction()
83
+ * ```
84
+ *
85
+ * In this example we submit a payment transaction between two newly created testnet accounts.
86
+ *
87
+ * Under the hood, `submit` will call `client.autofill` by default, and because we've passed in a `Wallet` it
88
+ * Will also sign the transaction for us before submitting the signed transaction binary blob to the ledger.
89
+ *
90
+ * This is similar to `submitAndWait` which does all of the above, but also waits to see if the transaction has been validated.
91
+ * @param this - A Client.
92
+ * @param transaction - A transaction to autofill, sign & encode, and submit.
93
+ * @param opts - (Optional) Options used to sign and submit a transaction.
94
+ * @param opts.autofill - If true, autofill a transaction.
95
+ * @param opts.failHard - If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
96
+ * @param opts.wallet - A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
97
+ * @throws Connection errors: If the `Client` object is unable to establish a connection to the specified WebSocket endpoint,
98
+ * an error will be thrown.
99
+ * @throws Transaction errors: If the submitted transaction is invalid or cannot be included in a validated ledger for any
100
+ * reason, the promise returned by `submitAndWait()` will be rejected with an error. This could include issues with insufficient
101
+ * balance, invalid transaction fields, or other issues specific to the transaction being submitted.
102
+ * @throws Ledger errors: If the ledger being used to submit the transaction is undergoing maintenance or otherwise unavailable,
103
+ * an error will be thrown.
104
+ * @throws Timeout errors: If the transaction takes longer than the specified timeout period to be included in a validated
105
+ * ledger, the promise returned by `submitAndWait()` will be rejected with an error.
106
+ * @returns A promise that contains TxResponse, that will return when the transaction has been validated.
107
+ */
108
+ async function submitAndWait<T extends Transaction = Transaction>(
109
+ this: Client,
110
+ transaction: T | string,
111
+ opts?: {
112
+ // If true, autofill a transaction.
113
+ autofill?: boolean
114
+ // If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
115
+ failHard?: boolean
116
+ // A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
117
+ wallet?: Wallet
118
+ },
119
+ ): Promise<TxResponse<T>> {
120
+ const signedTx = await getSignedTx(this, transaction, opts)
121
+
122
+ const lastLedger = getLastLedgerSequence(signedTx)
123
+ if (lastLedger == null) {
124
+ throw new ValidationError(
125
+ 'Transaction must contain a LastLedgerSequence value for reliable submission.',
126
+ )
127
+ }
128
+
129
+ const response = await submitRequest(this, signedTx, opts?.failHard)
130
+
131
+ const txHash = hashes.hashSignedTx(signedTx)
132
+ return waitForFinalTransactionOutcome(
133
+ this,
134
+ txHash,
135
+ lastLedger,
136
+ response.result.engine_result,
137
+ )
138
+ }
139
+
140
+ // Helper functions
141
+
142
+ // Encodes and submits a signed transaction.
143
+ async function submitRequest(
144
+ client: Client,
145
+ signedTransaction: Transaction | string,
146
+ failHard = false,
147
+ ): Promise<SubmitResponse> {
148
+ if (!isSigned(signedTransaction)) {
149
+ throw new ValidationError('Transaction must be signed')
150
+ }
151
+
152
+ const signedTxEncoded =
153
+ typeof signedTransaction === 'string'
154
+ ? signedTransaction
155
+ : encode(signedTransaction)
156
+ const request: SubmitRequest = {
157
+ command: 'submit',
158
+ tx_blob: signedTxEncoded,
159
+ fail_hard: isAccountDelete(signedTransaction) || failHard,
160
+ }
161
+ return client.request(request)
162
+ }
163
+
164
+ /*
165
+ * The core logic of reliable submission. This polls the ledger until the result of the
166
+ * transaction can be considered final, meaning it has either been included in a
167
+ * validated ledger, or the transaction's lastLedgerSequence has been surpassed by the
168
+ * latest ledger sequence (meaning it will never be included in a validated ledger).
169
+ */
170
+ // eslint-disable-next-line max-params, max-lines-per-function -- this function needs to display and do with more information.
171
+ async function waitForFinalTransactionOutcome<
172
+ T extends BaseTransaction = Transaction,
173
+ >(
174
+ client: Client,
175
+ txHash: string,
176
+ lastLedger: number,
177
+ submissionResult: string,
178
+ ): Promise<TxResponse<T>> {
179
+ await sleep(LEDGER_CLOSE_TIME)
180
+
181
+ const latestLedger = await client.getLedgerIndex()
182
+
183
+ if (lastLedger < latestLedger) {
184
+ throw new XrplError(
185
+ `The latest ledger sequence ${latestLedger} is greater than the transaction's LastLedgerSequence (${lastLedger}).\n` +
186
+ `Preliminary result: ${submissionResult}`,
187
+ )
188
+ }
189
+
190
+ const txResponse = await client
191
+ .request<TxRequest, TxResponse<T>>({
192
+ command: 'tx',
193
+ transaction: txHash,
194
+ })
195
+ .catch(async (error) => {
196
+ // error is of an unknown type and hence we assert type to extract the value we need.
197
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions,@typescript-eslint/no-unsafe-member-access -- ^
198
+ const message = error?.data?.error as string
199
+ if (message === 'txnNotFound') {
200
+ return waitForFinalTransactionOutcome<T>(
201
+ client,
202
+ txHash,
203
+ lastLedger,
204
+ submissionResult,
205
+ )
206
+ }
207
+ throw new Error(
208
+ `${message} \n Preliminary result: ${submissionResult}.\nFull error details: ${String(
209
+ error,
210
+ )}`,
211
+ )
212
+ })
213
+
214
+ if (txResponse.result.validated) {
215
+ return txResponse
216
+ }
217
+
218
+ return waitForFinalTransactionOutcome<T>(
219
+ client,
220
+ txHash,
221
+ lastLedger,
222
+ submissionResult,
223
+ )
224
+ }
225
+
226
+ // checks if the transaction has been signed
227
+ function isSigned(transaction: Transaction | string): boolean {
228
+ const tx = typeof transaction === 'string' ? decode(transaction) : transaction
229
+ if (typeof tx === 'string') {
230
+ return false
231
+ }
232
+ if (tx.Signers != null) {
233
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we know that tx.Signers is an array of Signers
234
+ const signers = tx.Signers as Signer[]
235
+ for (const signer of signers) {
236
+ // eslint-disable-next-line max-depth -- necessary for checking if signer is signed
237
+ if (
238
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- necessary check
239
+ signer.Signer.SigningPubKey == null ||
240
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- necessary check
241
+ signer.Signer.TxnSignature == null
242
+ ) {
243
+ return false
244
+ }
245
+ }
246
+ return true
247
+ }
248
+ return tx.SigningPubKey != null && tx.TxnSignature != null
249
+ }
250
+
251
+ // initializes a transaction for a submit request
252
+ async function getSignedTx(
253
+ client: Client,
254
+ transaction: Transaction | string,
255
+ {
256
+ autofill = true,
257
+ wallet,
258
+ }: {
259
+ // If true, autofill a transaction.
260
+ autofill?: boolean
261
+ // If true, and the transaction fails locally, do not retry or relay the transaction to other servers.
262
+ failHard?: boolean
263
+ // A wallet to sign a transaction. It must be provided when submitting an unsigned transaction.
264
+ wallet?: Wallet
265
+ } = {},
266
+ ): Promise<Transaction | string> {
267
+ if (isSigned(transaction)) {
268
+ return transaction
269
+ }
270
+
271
+ if (!wallet) {
272
+ throw new ValidationError(
273
+ 'Wallet must be provided when submitting an unsigned transaction',
274
+ )
275
+ }
276
+
277
+ let tx =
278
+ typeof transaction === 'string'
279
+ ? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- converts JsonObject to correct Transaction type
280
+ (decode(transaction) as unknown as Transaction)
281
+ : transaction
282
+
283
+ if (autofill) {
284
+ tx = await client.autofill(tx)
285
+ }
286
+
287
+ return wallet.sign(tx).tx_blob
288
+ }
289
+
290
+ // checks if there is a LastLedgerSequence as a part of the transaction
291
+ function getLastLedgerSequence(
292
+ transaction: Transaction | string,
293
+ ): number | null {
294
+ const tx = typeof transaction === 'string' ? decode(transaction) : transaction
295
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- converts LastLedgSeq to number if present.
296
+ return tx.LastLedgerSequence as number | null
297
+ }
298
+
299
+ // checks if the transaction is an AccountDelete transaction
300
+ function isAccountDelete(transaction: Transaction | string): boolean {
301
+ const tx = typeof transaction === 'string' ? decode(transaction) : transaction
302
+ return tx.TransactionType === 'AccountDelete'
303
+ }
304
+
305
+ export { submit, submitAndWait }
@@ -0,0 +1,29 @@
1
+ import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
2
+
3
+ /**
4
+ * If an address is an X-Address, converts it to a classic address.
5
+ *
6
+ * @param account - A classic address or X-address.
7
+ * @returns The account's classic address.
8
+ * @throws Error if the X-Address has an associated tag.
9
+ */
10
+ export function ensureClassicAddress(account: string): string {
11
+ if (isValidXAddress(account)) {
12
+ const { classicAddress, tag } = xAddressToClassicAddress(account)
13
+
14
+ /*
15
+ * Except for special cases, X-addresses used for requests
16
+ * must not have an embedded tag. In other words,
17
+ * `tag` should be `false`.
18
+ */
19
+ if (tag !== false) {
20
+ throw new Error(
21
+ 'This command does not support the use of a tag. Use an address without a tag.',
22
+ )
23
+ }
24
+
25
+ // For rippled requests that use an account, always use a classic address.
26
+ return classicAddress
27
+ }
28
+ return account
29
+ }