xrpl 2.10.0 → 2.12.0-beta.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 (414) 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 +1308 -33
  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 +11 -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 +2 -0
  23. package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
  24. package/dist/npm/models/ledger/AccountRoot.js +1 -0
  25. package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
  26. package/dist/npm/models/ledger/Bridge.d.ts +17 -0
  27. package/dist/npm/models/ledger/Bridge.d.ts.map +1 -0
  28. package/dist/npm/models/ledger/Bridge.js +3 -0
  29. package/dist/npm/models/ledger/Bridge.js.map +1 -0
  30. package/dist/npm/models/ledger/LedgerEntry.d.ts +5 -1
  31. package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
  32. package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts +16 -0
  33. package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts.map +1 -0
  34. package/dist/npm/models/ledger/XChainOwnedClaimID.js +3 -0
  35. package/dist/npm/models/ledger/XChainOwnedClaimID.js.map +1 -0
  36. package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +14 -0
  37. package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -0
  38. package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.js +3 -0
  39. package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.js.map +1 -0
  40. package/dist/npm/models/ledger/index.d.ts +4 -1
  41. package/dist/npm/models/ledger/index.d.ts.map +1 -1
  42. package/dist/npm/models/ledger/index.js.map +1 -1
  43. package/dist/npm/models/methods/accountObjects.d.ts +3 -3
  44. package/dist/npm/models/methods/accountObjects.d.ts.map +1 -1
  45. package/dist/npm/models/methods/ammInfo.d.ts +39 -0
  46. package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
  47. package/dist/npm/models/methods/ammInfo.js +3 -0
  48. package/dist/npm/models/methods/ammInfo.js.map +1 -0
  49. package/dist/npm/models/methods/index.d.ts +4 -3
  50. package/dist/npm/models/methods/index.d.ts.map +1 -1
  51. package/dist/npm/models/methods/ledgerEntry.d.ts +27 -0
  52. package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
  53. package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
  54. package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
  55. package/dist/npm/models/transactions/AMMBid.js +56 -0
  56. package/dist/npm/models/transactions/AMMBid.js.map +1 -0
  57. package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
  58. package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
  59. package/dist/npm/models/transactions/AMMCreate.js +32 -0
  60. package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
  61. package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
  62. package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
  63. package/dist/npm/models/transactions/AMMDelete.js +22 -0
  64. package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
  65. package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
  66. package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
  67. package/dist/npm/models/transactions/AMMDeposit.js +51 -0
  68. package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
  69. package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
  70. package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
  71. package/dist/npm/models/transactions/AMMVote.js +32 -0
  72. package/dist/npm/models/transactions/AMMVote.js.map +1 -0
  73. package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
  74. package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
  75. package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
  76. package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
  77. package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts +11 -0
  78. package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -0
  79. package/dist/npm/models/transactions/XChainAccountCreateCommit.js +35 -0
  80. package/dist/npm/models/transactions/XChainAccountCreateCommit.js.map +1 -0
  81. package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts +18 -0
  82. package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -0
  83. package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js +77 -0
  84. package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -0
  85. package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts +17 -0
  86. package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -0
  87. package/dist/npm/models/transactions/XChainAddClaimAttestation.js +68 -0
  88. package/dist/npm/models/transactions/XChainAddClaimAttestation.js.map +1 -0
  89. package/dist/npm/models/transactions/XChainClaim.d.ts +12 -0
  90. package/dist/npm/models/transactions/XChainClaim.d.ts.map +1 -0
  91. package/dist/npm/models/transactions/XChainClaim.js +39 -0
  92. package/dist/npm/models/transactions/XChainClaim.js.map +1 -0
  93. package/dist/npm/models/transactions/XChainCommit.d.ts +11 -0
  94. package/dist/npm/models/transactions/XChainCommit.d.ts.map +1 -0
  95. package/dist/npm/models/transactions/XChainCommit.js +33 -0
  96. package/dist/npm/models/transactions/XChainCommit.js.map +1 -0
  97. package/dist/npm/models/transactions/XChainCreateBridge.d.ts +10 -0
  98. package/dist/npm/models/transactions/XChainCreateBridge.d.ts.map +1 -0
  99. package/dist/npm/models/transactions/XChainCreateBridge.js +26 -0
  100. package/dist/npm/models/transactions/XChainCreateBridge.js.map +1 -0
  101. package/dist/npm/models/transactions/XChainCreateClaimID.d.ts +10 -0
  102. package/dist/npm/models/transactions/XChainCreateClaimID.d.ts.map +1 -0
  103. package/dist/npm/models/transactions/XChainCreateClaimID.js +28 -0
  104. package/dist/npm/models/transactions/XChainCreateClaimID.js.map +1 -0
  105. package/dist/npm/models/transactions/XChainModifyBridge.d.ts +17 -0
  106. package/dist/npm/models/transactions/XChainModifyBridge.d.ts.map +1 -0
  107. package/dist/npm/models/transactions/XChainModifyBridge.js +27 -0
  108. package/dist/npm/models/transactions/XChainModifyBridge.js.map +1 -0
  109. package/dist/npm/models/transactions/common.d.ts +3 -1
  110. package/dist/npm/models/transactions/common.d.ts.map +1 -1
  111. package/dist/npm/models/transactions/common.js +22 -1
  112. package/dist/npm/models/transactions/common.js.map +1 -1
  113. package/dist/npm/models/transactions/index.d.ts +15 -1
  114. package/dist/npm/models/transactions/index.d.ts.map +1 -1
  115. package/dist/npm/models/transactions/index.js +7 -1
  116. package/dist/npm/models/transactions/index.js.map +1 -1
  117. package/dist/npm/models/transactions/transaction.d.ts +15 -1
  118. package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
  119. package/dist/npm/models/transactions/transaction.js +56 -0
  120. package/dist/npm/models/transactions/transaction.js.map +1 -1
  121. package/dist/npm/models/utils/flags.d.ts.map +1 -1
  122. package/dist/npm/models/utils/flags.js +18 -21
  123. package/dist/npm/models/utils/flags.js.map +1 -1
  124. package/dist/npm/snippets/src/bridgeTransfer.d.ts +2 -0
  125. package/dist/npm/snippets/src/bridgeTransfer.d.ts.map +1 -0
  126. package/dist/npm/snippets/src/bridgeTransfer.js +124 -0
  127. package/dist/npm/snippets/src/bridgeTransfer.js.map +1 -0
  128. package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
  129. package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
  130. package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
  131. package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
  132. package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
  133. package/dist/npm/src/client/index.d.ts +2 -1
  134. package/dist/npm/src/client/index.d.ts.map +1 -1
  135. package/dist/npm/src/client/index.js.map +1 -1
  136. package/dist/npm/src/index.d.ts +1 -0
  137. package/dist/npm/src/index.d.ts.map +1 -1
  138. package/dist/npm/src/index.js +3 -1
  139. package/dist/npm/src/index.js.map +1 -1
  140. package/dist/npm/src/models/common/index.d.ts +11 -0
  141. package/dist/npm/src/models/common/index.d.ts.map +1 -1
  142. package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
  143. package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
  144. package/dist/npm/src/models/ledger/AMM.js +3 -0
  145. package/dist/npm/src/models/ledger/AMM.js.map +1 -0
  146. package/dist/npm/src/models/ledger/AccountRoot.d.ts +2 -0
  147. package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
  148. package/dist/npm/src/models/ledger/AccountRoot.js +1 -0
  149. package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
  150. package/dist/npm/src/models/ledger/Bridge.d.ts +17 -0
  151. package/dist/npm/src/models/ledger/Bridge.d.ts.map +1 -0
  152. package/dist/npm/src/models/ledger/Bridge.js +3 -0
  153. package/dist/npm/src/models/ledger/Bridge.js.map +1 -0
  154. package/dist/npm/src/models/ledger/LedgerEntry.d.ts +5 -1
  155. package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
  156. package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts +16 -0
  157. package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts.map +1 -0
  158. package/dist/npm/src/models/ledger/XChainOwnedClaimID.js +3 -0
  159. package/dist/npm/src/models/ledger/XChainOwnedClaimID.js.map +1 -0
  160. package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +14 -0
  161. package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -0
  162. package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.js +3 -0
  163. package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.js.map +1 -0
  164. package/dist/npm/src/models/ledger/index.d.ts +4 -1
  165. package/dist/npm/src/models/ledger/index.d.ts.map +1 -1
  166. package/dist/npm/src/models/ledger/index.js.map +1 -1
  167. package/dist/npm/src/models/methods/accountObjects.d.ts +3 -3
  168. package/dist/npm/src/models/methods/accountObjects.d.ts.map +1 -1
  169. package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
  170. package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
  171. package/dist/npm/src/models/methods/ammInfo.js +3 -0
  172. package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
  173. package/dist/npm/src/models/methods/index.d.ts +4 -3
  174. package/dist/npm/src/models/methods/index.d.ts.map +1 -1
  175. package/dist/npm/src/models/methods/ledgerEntry.d.ts +27 -0
  176. package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
  177. package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
  178. package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
  179. package/dist/npm/src/models/transactions/AMMBid.js +56 -0
  180. package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
  181. package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
  182. package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
  183. package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
  184. package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
  185. package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
  186. package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
  187. package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
  188. package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
  189. package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
  190. package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
  191. package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
  192. package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
  193. package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
  194. package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
  195. package/dist/npm/src/models/transactions/AMMVote.js +32 -0
  196. package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
  197. package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
  198. package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
  199. package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
  200. package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
  201. package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts +11 -0
  202. package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -0
  203. package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js +35 -0
  204. package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js.map +1 -0
  205. package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts +18 -0
  206. package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -0
  207. package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js +77 -0
  208. package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -0
  209. package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts +17 -0
  210. package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -0
  211. package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js +68 -0
  212. package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js.map +1 -0
  213. package/dist/npm/src/models/transactions/XChainClaim.d.ts +12 -0
  214. package/dist/npm/src/models/transactions/XChainClaim.d.ts.map +1 -0
  215. package/dist/npm/src/models/transactions/XChainClaim.js +39 -0
  216. package/dist/npm/src/models/transactions/XChainClaim.js.map +1 -0
  217. package/dist/npm/src/models/transactions/XChainCommit.d.ts +11 -0
  218. package/dist/npm/src/models/transactions/XChainCommit.d.ts.map +1 -0
  219. package/dist/npm/src/models/transactions/XChainCommit.js +33 -0
  220. package/dist/npm/src/models/transactions/XChainCommit.js.map +1 -0
  221. package/dist/npm/src/models/transactions/XChainCreateBridge.d.ts +10 -0
  222. package/dist/npm/src/models/transactions/XChainCreateBridge.d.ts.map +1 -0
  223. package/dist/npm/src/models/transactions/XChainCreateBridge.js +26 -0
  224. package/dist/npm/src/models/transactions/XChainCreateBridge.js.map +1 -0
  225. package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts +10 -0
  226. package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts.map +1 -0
  227. package/dist/npm/src/models/transactions/XChainCreateClaimID.js +28 -0
  228. package/dist/npm/src/models/transactions/XChainCreateClaimID.js.map +1 -0
  229. package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts +17 -0
  230. package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts.map +1 -0
  231. package/dist/npm/src/models/transactions/XChainModifyBridge.js +27 -0
  232. package/dist/npm/src/models/transactions/XChainModifyBridge.js.map +1 -0
  233. package/dist/npm/src/models/transactions/common.d.ts +3 -1
  234. package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
  235. package/dist/npm/src/models/transactions/common.js +22 -1
  236. package/dist/npm/src/models/transactions/common.js.map +1 -1
  237. package/dist/npm/src/models/transactions/index.d.ts +15 -1
  238. package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
  239. package/dist/npm/src/models/transactions/index.js +7 -1
  240. package/dist/npm/src/models/transactions/index.js.map +1 -1
  241. package/dist/npm/src/models/transactions/transaction.d.ts +15 -1
  242. package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
  243. package/dist/npm/src/models/transactions/transaction.js +56 -0
  244. package/dist/npm/src/models/transactions/transaction.js.map +1 -1
  245. package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
  246. package/dist/npm/src/models/utils/flags.js +18 -21
  247. package/dist/npm/src/models/utils/flags.js.map +1 -1
  248. package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
  249. package/dist/npm/src/sugar/autofill.js +4 -3
  250. package/dist/npm/src/sugar/autofill.js.map +1 -1
  251. package/dist/npm/sugar/autofill.d.ts.map +1 -1
  252. package/dist/npm/sugar/autofill.js +4 -3
  253. package/dist/npm/sugar/autofill.js.map +1 -1
  254. package/package.json +8 -6
  255. package/src/ECDSA.ts +6 -0
  256. package/src/Wallet/defaultFaucets.ts +82 -0
  257. package/src/Wallet/fundWallet.ts +344 -0
  258. package/src/Wallet/index.ts +504 -0
  259. package/src/Wallet/rfc1751.ts +190 -0
  260. package/src/Wallet/rfc1751Words.json +243 -0
  261. package/src/Wallet/signer.ts +173 -0
  262. package/src/Wallet/walletFromSecretNumbers.ts +37 -0
  263. package/src/client/BroadcastClient.ts +84 -0
  264. package/src/client/ConnectionManager.ts +40 -0
  265. package/src/client/ExponentialBackoff.ts +71 -0
  266. package/src/client/RequestManager.ts +194 -0
  267. package/src/client/WSWrapper.ts +106 -0
  268. package/src/client/connection.ts +593 -0
  269. package/src/client/index.ts +712 -0
  270. package/src/client/partialPayment.ts +153 -0
  271. package/src/errors.ts +161 -0
  272. package/src/index.ts +20 -0
  273. package/src/models/common/index.ts +156 -0
  274. package/src/models/index.ts +16 -0
  275. package/src/models/ledger/AMM.ts +78 -0
  276. package/src/models/ledger/AccountRoot.ts +217 -0
  277. package/src/models/ledger/Amendments.ts +45 -0
  278. package/src/models/ledger/BaseLedgerEntry.ts +3 -0
  279. package/src/models/ledger/Bridge.ts +84 -0
  280. package/src/models/ledger/Check.ts +70 -0
  281. package/src/models/ledger/DepositPreauth.ts +35 -0
  282. package/src/models/ledger/DirectoryNode.ts +46 -0
  283. package/src/models/ledger/Escrow.ts +74 -0
  284. package/src/models/ledger/FeeSettings.ts +52 -0
  285. package/src/models/ledger/Ledger.ts +65 -0
  286. package/src/models/ledger/LedgerEntry.ts +40 -0
  287. package/src/models/ledger/LedgerHashes.ts +24 -0
  288. package/src/models/ledger/NFTokenOffer.ts +16 -0
  289. package/src/models/ledger/NFTokenPage.ts +20 -0
  290. package/src/models/ledger/NegativeUNL.ts +34 -0
  291. package/src/models/ledger/Offer.ts +52 -0
  292. package/src/models/ledger/PayChannel.ts +107 -0
  293. package/src/models/ledger/RippleState.ts +88 -0
  294. package/src/models/ledger/SignerList.ts +56 -0
  295. package/src/models/ledger/Ticket.ts +36 -0
  296. package/src/models/ledger/XChainOwnedClaimID.ts +73 -0
  297. package/src/models/ledger/XChainOwnedCreateAccountClaimID.ts +60 -0
  298. package/src/models/ledger/index.ts +64 -0
  299. package/src/models/methods/accountChannels.ts +93 -0
  300. package/src/models/methods/accountCurrencies.ts +45 -0
  301. package/src/models/methods/accountInfo.ts +182 -0
  302. package/src/models/methods/accountLines.ts +137 -0
  303. package/src/models/methods/accountNFTs.ts +72 -0
  304. package/src/models/methods/accountObjects.ts +129 -0
  305. package/src/models/methods/accountOffers.ts +100 -0
  306. package/src/models/methods/accountTx.ts +109 -0
  307. package/src/models/methods/ammInfo.ts +145 -0
  308. package/src/models/methods/baseMethod.ts +58 -0
  309. package/src/models/methods/bookOffers.ts +96 -0
  310. package/src/models/methods/channelVerify.ts +41 -0
  311. package/src/models/methods/depositAuthorized.ts +56 -0
  312. package/src/models/methods/fee.ts +91 -0
  313. package/src/models/methods/gatewayBalances.ts +85 -0
  314. package/src/models/methods/index.ts +391 -0
  315. package/src/models/methods/ledger.ts +125 -0
  316. package/src/models/methods/ledgerClosed.ts +32 -0
  317. package/src/models/methods/ledgerCurrent.ts +31 -0
  318. package/src/models/methods/ledgerData.ts +78 -0
  319. package/src/models/methods/ledgerEntry.ts +202 -0
  320. package/src/models/methods/manifest.ts +54 -0
  321. package/src/models/methods/nftBuyOffers.ts +37 -0
  322. package/src/models/methods/nftHistory.ts +113 -0
  323. package/src/models/methods/nftInfo.ts +25 -0
  324. package/src/models/methods/nftSellOffers.ts +37 -0
  325. package/src/models/methods/norippleCheck.ts +82 -0
  326. package/src/models/methods/pathFind.ts +116 -0
  327. package/src/models/methods/ping.ts +21 -0
  328. package/src/models/methods/random.ts +23 -0
  329. package/src/models/methods/ripplePathFind.ts +81 -0
  330. package/src/models/methods/serverInfo.ts +257 -0
  331. package/src/models/methods/serverState.ts +77 -0
  332. package/src/models/methods/submit.ts +94 -0
  333. package/src/models/methods/submitMultisigned.ts +51 -0
  334. package/src/models/methods/subscribe.ts +435 -0
  335. package/src/models/methods/transactionEntry.ts +47 -0
  336. package/src/models/methods/tx.ts +69 -0
  337. package/src/models/methods/unsubscribe.ts +49 -0
  338. package/src/models/transactions/AMMBid.ts +140 -0
  339. package/src/models/transactions/AMMCreate.ts +80 -0
  340. package/src/models/transactions/AMMDelete.ts +55 -0
  341. package/src/models/transactions/AMMDeposit.ts +130 -0
  342. package/src/models/transactions/AMMVote.ts +71 -0
  343. package/src/models/transactions/AMMWithdraw.ts +126 -0
  344. package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
  345. package/src/models/transactions/NFTokenBurn.ts +48 -0
  346. package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
  347. package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
  348. package/src/models/transactions/NFTokenMint.ts +123 -0
  349. package/src/models/transactions/UNLModify.ts +20 -0
  350. package/src/models/transactions/XChainAccountCreateCommit.ts +107 -0
  351. package/src/models/transactions/XChainAddAccountCreateAttestation.ts +225 -0
  352. package/src/models/transactions/XChainAddClaimAttestation.ts +198 -0
  353. package/src/models/transactions/XChainClaim.ts +103 -0
  354. package/src/models/transactions/XChainCommit.ts +95 -0
  355. package/src/models/transactions/XChainCreateBridge.ts +78 -0
  356. package/src/models/transactions/XChainCreateClaimID.ts +78 -0
  357. package/src/models/transactions/XChainModifyBridge.ts +93 -0
  358. package/src/models/transactions/accountDelete.ts +50 -0
  359. package/src/models/transactions/accountSet.ts +228 -0
  360. package/src/models/transactions/checkCancel.ts +34 -0
  361. package/src/models/transactions/checkCash.ts +73 -0
  362. package/src/models/transactions/checkCreate.ts +90 -0
  363. package/src/models/transactions/clawback.ts +49 -0
  364. package/src/models/transactions/common.ts +320 -0
  365. package/src/models/transactions/depositPreauth.ts +68 -0
  366. package/src/models/transactions/enableAmendment.ts +26 -0
  367. package/src/models/transactions/escrowCancel.ts +45 -0
  368. package/src/models/transactions/escrowCreate.ts +100 -0
  369. package/src/models/transactions/escrowFinish.ts +63 -0
  370. package/src/models/transactions/index.ts +78 -0
  371. package/src/models/transactions/metadata.ts +69 -0
  372. package/src/models/transactions/offerCancel.ts +37 -0
  373. package/src/models/transactions/offerCreate.ts +144 -0
  374. package/src/models/transactions/payment.ts +278 -0
  375. package/src/models/transactions/paymentChannelClaim.ts +165 -0
  376. package/src/models/transactions/paymentChannelCreate.ts +116 -0
  377. package/src/models/transactions/paymentChannelFund.ts +65 -0
  378. package/src/models/transactions/setFee.ts +48 -0
  379. package/src/models/transactions/setRegularKey.ts +33 -0
  380. package/src/models/transactions/signerListSet.ts +89 -0
  381. package/src/models/transactions/ticketCreate.ts +50 -0
  382. package/src/models/transactions/transaction.ts +370 -0
  383. package/src/models/transactions/trustSet.ts +146 -0
  384. package/src/models/utils/flags.ts +103 -0
  385. package/src/models/utils/index.ts +37 -0
  386. package/src/sugar/autofill.ts +373 -0
  387. package/src/sugar/balances.ts +123 -0
  388. package/src/sugar/getFeeXrp.ts +45 -0
  389. package/src/sugar/getLedgerIndex.ts +15 -0
  390. package/src/sugar/getOrderbook.ts +152 -0
  391. package/src/sugar/index.ts +11 -0
  392. package/src/sugar/submit.ts +305 -0
  393. package/src/sugar/utils.ts +29 -0
  394. package/src/utils/derive.ts +23 -0
  395. package/src/utils/getBalanceChanges.ts +186 -0
  396. package/src/utils/getNFTokenID.ts +97 -0
  397. package/src/utils/hashes/HashPrefix.ts +40 -0
  398. package/src/utils/hashes/README.md +65 -0
  399. package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
  400. package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
  401. package/src/utils/hashes/SHAMap/index.ts +41 -0
  402. package/src/utils/hashes/SHAMap/node.ts +14 -0
  403. package/src/utils/hashes/hashLedger.ts +236 -0
  404. package/src/utils/hashes/index.ts +187 -0
  405. package/src/utils/hashes/ledgerSpaces.ts +34 -0
  406. package/src/utils/hashes/sha512Half.ts +19 -0
  407. package/src/utils/index.ts +223 -0
  408. package/src/utils/parseNFTokenID.ts +84 -0
  409. package/src/utils/quality.ts +169 -0
  410. package/src/utils/signPaymentChannelClaim.ts +27 -0
  411. package/src/utils/stringConversion.ts +27 -0
  412. package/src/utils/timeConversion.ts +53 -0
  413. package/src/utils/verifyPaymentChannelClaim.ts +30 -0
  414. package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,370 @@
1
+ /* eslint-disable max-lines -- need to work with a lot of transactions in a switch statement */
2
+ /* eslint-disable complexity -- verifies many tx types hence a lot of checks needed */
3
+ /* eslint-disable max-lines-per-function -- need to work with a lot of Tx verifications */
4
+
5
+ import { ValidationError } from '../../errors'
6
+ import { IssuedCurrencyAmount, Memo } from '../common'
7
+ import { isHex } from '../utils'
8
+ import { setTransactionFlagsToNumber } from '../utils/flags'
9
+
10
+ import { AccountDelete, validateAccountDelete } from './accountDelete'
11
+ import { AccountSet, validateAccountSet } from './accountSet'
12
+ import { AMMBid, validateAMMBid } from './AMMBid'
13
+ import { AMMCreate, validateAMMCreate } from './AMMCreate'
14
+ import { AMMDelete, validateAMMDelete } from './AMMDelete'
15
+ import { AMMDeposit, validateAMMDeposit } from './AMMDeposit'
16
+ import { AMMVote, validateAMMVote } from './AMMVote'
17
+ import { AMMWithdraw, validateAMMWithdraw } from './AMMWithdraw'
18
+ import { CheckCancel, validateCheckCancel } from './checkCancel'
19
+ import { CheckCash, validateCheckCash } from './checkCash'
20
+ import { CheckCreate, validateCheckCreate } from './checkCreate'
21
+ import { Clawback, validateClawback } from './clawback'
22
+ import { isIssuedCurrency } from './common'
23
+ import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
24
+ import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
25
+ import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
26
+ import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
27
+ import { TransactionMetadata } from './metadata'
28
+ import {
29
+ NFTokenAcceptOffer,
30
+ validateNFTokenAcceptOffer,
31
+ } from './NFTokenAcceptOffer'
32
+ import { NFTokenBurn, validateNFTokenBurn } from './NFTokenBurn'
33
+ import {
34
+ NFTokenCancelOffer,
35
+ validateNFTokenCancelOffer,
36
+ } from './NFTokenCancelOffer'
37
+ import {
38
+ NFTokenCreateOffer,
39
+ validateNFTokenCreateOffer,
40
+ } from './NFTokenCreateOffer'
41
+ import { NFTokenMint, validateNFTokenMint } from './NFTokenMint'
42
+ import { OfferCancel, validateOfferCancel } from './offerCancel'
43
+ import { OfferCreate, validateOfferCreate } from './offerCreate'
44
+ import { Payment, validatePayment } from './payment'
45
+ import {
46
+ PaymentChannelClaim,
47
+ validatePaymentChannelClaim,
48
+ } from './paymentChannelClaim'
49
+ import {
50
+ PaymentChannelCreate,
51
+ validatePaymentChannelCreate,
52
+ } from './paymentChannelCreate'
53
+ import {
54
+ PaymentChannelFund,
55
+ validatePaymentChannelFund,
56
+ } from './paymentChannelFund'
57
+ import { SetRegularKey, validateSetRegularKey } from './setRegularKey'
58
+ import { SignerListSet, validateSignerListSet } from './signerListSet'
59
+ import { TicketCreate, validateTicketCreate } from './ticketCreate'
60
+ import { TrustSet, validateTrustSet } from './trustSet'
61
+ import {
62
+ XChainAccountCreateCommit,
63
+ validateXChainAccountCreateCommit,
64
+ } from './XChainAccountCreateCommit'
65
+ import {
66
+ XChainAddAccountCreateAttestation,
67
+ validateXChainAddAccountCreateAttestation,
68
+ } from './XChainAddAccountCreateAttestation'
69
+ import {
70
+ XChainAddClaimAttestation,
71
+ validateXChainAddClaimAttestation,
72
+ } from './XChainAddClaimAttestation'
73
+ import { XChainClaim, validateXChainClaim } from './XChainClaim'
74
+ import { XChainCommit, validateXChainCommit } from './XChainCommit'
75
+ import {
76
+ XChainCreateBridge,
77
+ validateXChainCreateBridge,
78
+ } from './XChainCreateBridge'
79
+ import {
80
+ XChainCreateClaimID,
81
+ validateXChainCreateClaimID,
82
+ } from './XChainCreateClaimID'
83
+ import {
84
+ XChainModifyBridge,
85
+ validateXChainModifyBridge,
86
+ } from './XChainModifyBridge'
87
+
88
+ /**
89
+ * @category Transaction Models
90
+ */
91
+ export type Transaction =
92
+ | AccountDelete
93
+ | AccountSet
94
+ | AMMBid
95
+ | AMMDelete
96
+ | AMMDeposit
97
+ | AMMCreate
98
+ | AMMVote
99
+ | AMMWithdraw
100
+ | CheckCancel
101
+ | CheckCash
102
+ | CheckCreate
103
+ | Clawback
104
+ | DepositPreauth
105
+ | EscrowCancel
106
+ | EscrowCreate
107
+ | EscrowFinish
108
+ | NFTokenAcceptOffer
109
+ | NFTokenBurn
110
+ | NFTokenCancelOffer
111
+ | NFTokenCreateOffer
112
+ | NFTokenMint
113
+ | OfferCancel
114
+ | OfferCreate
115
+ | Payment
116
+ | PaymentChannelClaim
117
+ | PaymentChannelCreate
118
+ | PaymentChannelFund
119
+ | SetRegularKey
120
+ | SignerListSet
121
+ | TicketCreate
122
+ | TrustSet
123
+ | XChainAddAccountCreateAttestation
124
+ | XChainAddClaimAttestation
125
+ | XChainClaim
126
+ | XChainCommit
127
+ | XChainCreateBridge
128
+ | XChainCreateClaimID
129
+ | XChainAccountCreateCommit
130
+ | XChainModifyBridge
131
+
132
+ /**
133
+ * @category Transaction Models
134
+ */
135
+ export interface TransactionAndMetadata {
136
+ transaction: Transaction
137
+ metadata: TransactionMetadata
138
+ }
139
+
140
+ /**
141
+ * Verifies various Transaction Types.
142
+ * Encode/decode and individual type validation.
143
+ *
144
+ * @param transaction - A Transaction.
145
+ * @throws ValidationError When the Transaction is malformed.
146
+ * @category Utilities
147
+ */
148
+ export function validate(transaction: Record<string, unknown>): void {
149
+ const tx = { ...transaction }
150
+ if (tx.TransactionType == null) {
151
+ throw new ValidationError('Object does not have a `TransactionType`')
152
+ }
153
+ if (typeof tx.TransactionType !== 'string') {
154
+ throw new ValidationError("Object's `TransactionType` is not a string")
155
+ }
156
+
157
+ /*
158
+ * - Memos have exclusively hex data.
159
+ */
160
+ if (tx.Memos != null && typeof tx.Memos !== 'object') {
161
+ throw new ValidationError('Memo must be array')
162
+ }
163
+ if (tx.Memos != null) {
164
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- needed here
165
+ ;(tx.Memos as Array<Memo | null>).forEach((memo) => {
166
+ if (memo?.Memo == null) {
167
+ throw new ValidationError('Memo data must be in a `Memo` field')
168
+ }
169
+ if (memo.Memo.MemoData) {
170
+ if (!isHex(memo.Memo.MemoData)) {
171
+ throw new ValidationError('MemoData field must be a hex value')
172
+ }
173
+ }
174
+
175
+ if (memo.Memo.MemoType) {
176
+ if (!isHex(memo.Memo.MemoType)) {
177
+ throw new ValidationError('MemoType field must be a hex value')
178
+ }
179
+ }
180
+
181
+ if (memo.Memo.MemoFormat) {
182
+ if (!isHex(memo.Memo.MemoFormat)) {
183
+ throw new ValidationError('MemoFormat field must be a hex value')
184
+ }
185
+ }
186
+ })
187
+ }
188
+
189
+ Object.keys(tx).forEach((key) => {
190
+ const standard_currency_code_len = 3
191
+ if (tx[key] && isIssuedCurrency(tx[key])) {
192
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- needed
193
+ const txCurrency = (tx[key] as IssuedCurrencyAmount).currency
194
+
195
+ if (
196
+ txCurrency.length === standard_currency_code_len &&
197
+ txCurrency.toUpperCase() === 'XRP'
198
+ ) {
199
+ throw new ValidationError(
200
+ `Cannot have an issued currency with a similar standard code to XRP (received '${txCurrency}'). XRP is not an issued currency.`,
201
+ )
202
+ }
203
+ }
204
+ })
205
+
206
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- okay here
207
+ setTransactionFlagsToNumber(tx as unknown as Transaction)
208
+ switch (tx.TransactionType) {
209
+ case 'AccountDelete':
210
+ validateAccountDelete(tx)
211
+ break
212
+
213
+ case 'AccountSet':
214
+ validateAccountSet(tx)
215
+ break
216
+
217
+ case 'AMMBid':
218
+ validateAMMBid(tx)
219
+ break
220
+
221
+ case 'AMMDelete':
222
+ validateAMMDelete(tx)
223
+ break
224
+
225
+ case 'AMMDeposit':
226
+ validateAMMDeposit(tx)
227
+ break
228
+
229
+ case 'AMMCreate':
230
+ validateAMMCreate(tx)
231
+ break
232
+
233
+ case 'AMMVote':
234
+ validateAMMVote(tx)
235
+ break
236
+
237
+ case 'AMMWithdraw':
238
+ validateAMMWithdraw(tx)
239
+ break
240
+
241
+ case 'CheckCancel':
242
+ validateCheckCancel(tx)
243
+ break
244
+
245
+ case 'CheckCash':
246
+ validateCheckCash(tx)
247
+ break
248
+
249
+ case 'CheckCreate':
250
+ validateCheckCreate(tx)
251
+ break
252
+
253
+ case 'Clawback':
254
+ validateClawback(tx)
255
+ break
256
+
257
+ case 'DepositPreauth':
258
+ validateDepositPreauth(tx)
259
+ break
260
+
261
+ case 'EscrowCancel':
262
+ validateEscrowCancel(tx)
263
+ break
264
+
265
+ case 'EscrowCreate':
266
+ validateEscrowCreate(tx)
267
+ break
268
+
269
+ case 'EscrowFinish':
270
+ validateEscrowFinish(tx)
271
+ break
272
+
273
+ case 'NFTokenAcceptOffer':
274
+ validateNFTokenAcceptOffer(tx)
275
+ break
276
+
277
+ case 'NFTokenBurn':
278
+ validateNFTokenBurn(tx)
279
+ break
280
+
281
+ case 'NFTokenCancelOffer':
282
+ validateNFTokenCancelOffer(tx)
283
+ break
284
+
285
+ case 'NFTokenCreateOffer':
286
+ validateNFTokenCreateOffer(tx)
287
+ break
288
+
289
+ case 'NFTokenMint':
290
+ validateNFTokenMint(tx)
291
+ break
292
+
293
+ case 'OfferCancel':
294
+ validateOfferCancel(tx)
295
+ break
296
+
297
+ case 'OfferCreate':
298
+ validateOfferCreate(tx)
299
+ break
300
+
301
+ case 'Payment':
302
+ validatePayment(tx)
303
+ break
304
+
305
+ case 'PaymentChannelClaim':
306
+ validatePaymentChannelClaim(tx)
307
+ break
308
+
309
+ case 'PaymentChannelCreate':
310
+ validatePaymentChannelCreate(tx)
311
+ break
312
+
313
+ case 'PaymentChannelFund':
314
+ validatePaymentChannelFund(tx)
315
+ break
316
+
317
+ case 'SetRegularKey':
318
+ validateSetRegularKey(tx)
319
+ break
320
+
321
+ case 'SignerListSet':
322
+ validateSignerListSet(tx)
323
+ break
324
+
325
+ case 'TicketCreate':
326
+ validateTicketCreate(tx)
327
+ break
328
+
329
+ case 'TrustSet':
330
+ validateTrustSet(tx)
331
+ break
332
+
333
+ case 'XChainAddAccountCreateAttestation':
334
+ validateXChainAddAccountCreateAttestation(tx)
335
+ break
336
+
337
+ case 'XChainAddClaimAttestation':
338
+ validateXChainAddClaimAttestation(tx)
339
+ break
340
+
341
+ case 'XChainClaim':
342
+ validateXChainClaim(tx)
343
+ break
344
+
345
+ case 'XChainCommit':
346
+ validateXChainCommit(tx)
347
+ break
348
+
349
+ case 'XChainCreateBridge':
350
+ validateXChainCreateBridge(tx)
351
+ break
352
+
353
+ case 'XChainCreateClaimID':
354
+ validateXChainCreateClaimID(tx)
355
+ break
356
+
357
+ case 'XChainAccountCreateCommit':
358
+ validateXChainAccountCreateCommit(tx)
359
+ break
360
+
361
+ case 'XChainModifyBridge':
362
+ validateXChainModifyBridge(tx)
363
+ break
364
+
365
+ default:
366
+ throw new ValidationError(
367
+ `Invalid field TransactionType: ${tx.TransactionType}`,
368
+ )
369
+ }
370
+ }
@@ -0,0 +1,146 @@
1
+ import { ValidationError } from '../../errors'
2
+ import { IssuedCurrencyAmount } from '../common'
3
+
4
+ import {
5
+ BaseTransaction,
6
+ GlobalFlags,
7
+ isAmount,
8
+ validateBaseTransaction,
9
+ } from './common'
10
+
11
+ /**
12
+ * Enum representing values of {@link TrustSet} transaction flags.
13
+ *
14
+ * @category Transaction Flags
15
+ */
16
+ export enum TrustSetFlags {
17
+ /**
18
+ * Authorize the other party to hold currency issued by this account. (No
19
+ * effect unless using the asfRequireAuth AccountSet flag.) Cannot be unset.
20
+ */
21
+ tfSetfAuth = 0x00010000,
22
+ /**
23
+ * Enable the No Ripple flag, which blocks rippling between two trust lines.
24
+ * of the same currency if this flag is enabled on both.
25
+ */
26
+ tfSetNoRipple = 0x00020000,
27
+ /** Disable the No Ripple flag, allowing rippling on this trust line. */
28
+ tfClearNoRipple = 0x00040000,
29
+ /** Freeze the trust line. */
30
+ tfSetFreeze = 0x00100000,
31
+ /** Unfreeze the trust line. */
32
+ tfClearFreeze = 0x00200000,
33
+ }
34
+
35
+ /**
36
+ * Map of flags to boolean values representing {@link TrustSet} transaction
37
+ * flags.
38
+ *
39
+ * @category Transaction Flags
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ *
44
+ * const trustSetTx: TrustSet = {
45
+ * TransactionType: 'TrustSet',
46
+ * Account: wallet2.getClassicAddress(),
47
+ * LimitAmount: {
48
+ * currency: 'FOO',
49
+ * issuer: wallet1.getClassicAddress(),
50
+ * value: '10000000000',
51
+ * },
52
+ * Flags: {
53
+ * tfSetNoRipple: true
54
+ * }
55
+ * }
56
+ *
57
+ * // Autofill the tx to see how flags actually look compared to the interface usage.
58
+ * const autofilledTx = await client.autofill(trustSetTx)
59
+ * console.log(autofilledTx)
60
+ * // {
61
+ * // TransactionType: 'TrustSet',
62
+ * // Account: 'r9dAdQQCBcGajVSeC9CqW3LCugjPDnAkEb',
63
+ * // LimitAmount: {
64
+ * // currency: 'FOO',
65
+ * // issuer: 'rWZzUjo5xGiAoRBqzsndyzonXz47UV8u1',
66
+ * // value: '10000000000'
67
+ * // },
68
+ * // Flags: 131072,
69
+ * // Sequence: 21971483,
70
+ * // Fee: '12',
71
+ * // LastLedgerSequence: 21971503
72
+ * // }
73
+ * ```
74
+ */
75
+ export interface TrustSetFlagsInterface extends GlobalFlags {
76
+ /**
77
+ * Authorize the other party to hold currency issued by this account. (No
78
+ * effect unless using the asfRequireAuth AccountSet flag.) Cannot be unset.
79
+ */
80
+ tfSetfAuth?: boolean
81
+ /**
82
+ * Enable the No Ripple flag, which blocks rippling between two trust lines
83
+ * of the same currency if this flag is enabled on both.
84
+ */
85
+ tfSetNoRipple?: boolean
86
+ /** Disable the No Ripple flag, allowing rippling on this trust line. */
87
+ tfClearNoRipple?: boolean
88
+ /** Freeze the trust line. */
89
+ tfSetFreeze?: boolean
90
+ /** Unfreeze the trust line. */
91
+ tfClearFreeze?: boolean
92
+ }
93
+
94
+ /**
95
+ * Create or modify a trust line linking two accounts.
96
+ *
97
+ * @category Transaction Models
98
+ */
99
+ export interface TrustSet extends BaseTransaction {
100
+ TransactionType: 'TrustSet'
101
+ /**
102
+ * Object defining the trust line to create or modify, in the format of a
103
+ * Currency Amount.
104
+ */
105
+ LimitAmount: IssuedCurrencyAmount
106
+ /**
107
+ * Value incoming balances on this trust line at the ratio of this number per
108
+ * 1,000,000,000 units. A value of 0 is shorthand for treating balances at
109
+ * face value.
110
+ */
111
+ QualityIn?: number
112
+ /**
113
+ * Value outgoing balances on this trust line at the ratio of this number per
114
+ * 1,000,000,000 units. A value of 0 is shorthand for treating balances at
115
+ * face value.
116
+ */
117
+ QualityOut?: number
118
+ Flags?: number | TrustSetFlagsInterface
119
+ }
120
+
121
+ /**
122
+ * Verify the form and type of a TrustSet at runtime.
123
+ *
124
+ * @param tx - A TrustSet Transaction.
125
+ * @throws When the TrustSet is malformed.
126
+ */
127
+ export function validateTrustSet(tx: Record<string, unknown>): void {
128
+ validateBaseTransaction(tx)
129
+ const { LimitAmount, QualityIn, QualityOut } = tx
130
+
131
+ if (LimitAmount === undefined) {
132
+ throw new ValidationError('TrustSet: missing field LimitAmount')
133
+ }
134
+
135
+ if (!isAmount(LimitAmount)) {
136
+ throw new ValidationError('TrustSet: invalid LimitAmount')
137
+ }
138
+
139
+ if (QualityIn !== undefined && typeof QualityIn !== 'number') {
140
+ throw new ValidationError('TrustSet: QualityIn must be a number')
141
+ }
142
+
143
+ if (QualityOut !== undefined && typeof QualityOut !== 'number') {
144
+ throw new ValidationError('TrustSet: QualityOut must be a number')
145
+ }
146
+ }
@@ -0,0 +1,103 @@
1
+ /* eslint-disable no-param-reassign -- param reassign is safe */
2
+ /* eslint-disable no-bitwise -- flags require bitwise operations */
3
+
4
+ import { ValidationError } from '../../errors'
5
+ import {
6
+ AccountRootFlagsInterface,
7
+ AccountRootFlags,
8
+ } from '../ledger/AccountRoot'
9
+ import { AccountSetTfFlags } from '../transactions/accountSet'
10
+ import { AMMDepositFlags } from '../transactions/AMMDeposit'
11
+ import { AMMWithdrawFlags } from '../transactions/AMMWithdraw'
12
+ import { GlobalFlags } from '../transactions/common'
13
+ import { OfferCreateFlags } from '../transactions/offerCreate'
14
+ import { PaymentFlags } from '../transactions/payment'
15
+ import { PaymentChannelClaimFlags } from '../transactions/paymentChannelClaim'
16
+ import type { Transaction } from '../transactions/transaction'
17
+ import { TrustSetFlags } from '../transactions/trustSet'
18
+ import { XChainModifyBridgeFlags } from '../transactions/XChainModifyBridge'
19
+
20
+ import { isFlagEnabled } from '.'
21
+
22
+ /**
23
+ * Convert an AccountRoot Flags number into an interface for easy interpretation.
24
+ *
25
+ * @param flags - A number which is the bitwise and of all enabled AccountRootFlagsInterface.
26
+ * @returns An interface with all flags as booleans.
27
+ */
28
+ export function parseAccountRootFlags(
29
+ flags: number,
30
+ ): AccountRootFlagsInterface {
31
+ const flagsInterface: AccountRootFlagsInterface = {}
32
+
33
+ // If we use keys all will be strings and enums are reversed during transpilation
34
+ Object.values(AccountRootFlags).forEach((flag) => {
35
+ if (
36
+ typeof flag === 'string' &&
37
+ isFlagEnabled(flags, AccountRootFlags[flag])
38
+ ) {
39
+ flagsInterface[flag] = true
40
+ }
41
+ })
42
+
43
+ return flagsInterface
44
+ }
45
+
46
+ /**
47
+ * Sets a transaction's flags to its numeric representation.
48
+ *
49
+ * @param tx - A transaction to set its flags to its numeric representation.
50
+ */
51
+ // eslint-disable-next-line complexity -- there's a lot of txs with flags
52
+ export function setTransactionFlagsToNumber(tx: Transaction): void {
53
+ if (tx.Flags == null) {
54
+ tx.Flags = 0
55
+ return
56
+ }
57
+ if (typeof tx.Flags === 'number') {
58
+ return
59
+ }
60
+
61
+ switch (tx.TransactionType) {
62
+ case 'AccountSet':
63
+ tx.Flags = convertFlagsToNumber(tx.Flags, AccountSetTfFlags)
64
+ return
65
+ case 'AMMDeposit':
66
+ tx.Flags = convertFlagsToNumber(tx.Flags, AMMDepositFlags)
67
+ return
68
+ case 'AMMWithdraw':
69
+ tx.Flags = convertFlagsToNumber(tx.Flags, AMMWithdrawFlags)
70
+ return
71
+ case 'OfferCreate':
72
+ tx.Flags = convertFlagsToNumber(tx.Flags, OfferCreateFlags)
73
+ return
74
+ case 'PaymentChannelClaim':
75
+ tx.Flags = convertFlagsToNumber(tx.Flags, PaymentChannelClaimFlags)
76
+ return
77
+ case 'Payment':
78
+ tx.Flags = convertFlagsToNumber(tx.Flags, PaymentFlags)
79
+ return
80
+ case 'TrustSet':
81
+ tx.Flags = convertFlagsToNumber(tx.Flags, TrustSetFlags)
82
+ return
83
+ case 'XChainModifyBridge':
84
+ tx.Flags = convertFlagsToNumber(tx.Flags, XChainModifyBridgeFlags)
85
+ return
86
+ default:
87
+ tx.Flags = 0
88
+ }
89
+ }
90
+
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- added ValidationError check for flagEnum
92
+ function convertFlagsToNumber(flags: GlobalFlags, flagEnum: any): number {
93
+ return Object.keys(flags).reduce((resultFlags, flag) => {
94
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
95
+ if (flagEnum[flag] == null) {
96
+ throw new ValidationError(
97
+ `flag ${flag} doesn't exist in flagEnum: ${JSON.stringify(flagEnum)}`,
98
+ )
99
+ }
100
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- safe member access
101
+ return flags[flag] ? resultFlags | flagEnum[flag] : resultFlags
102
+ }, 0)
103
+ }
@@ -0,0 +1,37 @@
1
+ const HEX_REGEX = /^[0-9A-Fa-f]+$/u
2
+
3
+ /**
4
+ * Verify that all fields of an object are in fields.
5
+ *
6
+ * @param obj - Object to verify fields.
7
+ * @param fields - Fields to verify.
8
+ * @returns True if keys in object are all in fields.
9
+ */
10
+ export function onlyHasFields(
11
+ obj: Record<string, unknown>,
12
+ fields: string[],
13
+ ): boolean {
14
+ return Object.keys(obj).every((key: string) => fields.includes(key))
15
+ }
16
+
17
+ /**
18
+ * Perform bitwise AND (&) to check if a flag is enabled within Flags (as a number).
19
+ *
20
+ * @param Flags - A number that represents flags enabled.
21
+ * @param checkFlag - A specific flag to check if it's enabled within Flags.
22
+ * @returns True if checkFlag is enabled within Flags.
23
+ */
24
+ export function isFlagEnabled(Flags: number, checkFlag: number): boolean {
25
+ // eslint-disable-next-line no-bitwise -- flags need bitwise
26
+ return (BigInt(checkFlag) & BigInt(Flags)) === BigInt(checkFlag)
27
+ }
28
+
29
+ /**
30
+ * Check if string is in hex format.
31
+ *
32
+ * @param str - The string to check if it's in hex format.
33
+ * @returns True if string is in hex format
34
+ */
35
+ export function isHex(str: string): boolean {
36
+ return HEX_REGEX.test(str)
37
+ }