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,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
+ }
@@ -0,0 +1,23 @@
1
+ import { classicAddressToXAddress } from 'ripple-address-codec'
2
+ import { deriveKeypair, deriveAddress } from 'ripple-keypairs'
3
+
4
+ /**
5
+ * Derive an X-Address from a public key and a destination tag.
6
+ *
7
+ * @param options - Public key and destination tag to encode as an X-Address.
8
+ * @param options.publicKey - The public key corresponding to an address.
9
+ * @param options.tag - A destination tag to encode into an X-address. False indicates no destination tag.
10
+ * @param options.test - Whether this address is for use in Testnet.
11
+ * @returns X-Address.
12
+ * @category Utilities
13
+ */
14
+ function deriveXAddress(options: {
15
+ publicKey: string
16
+ tag: number | false
17
+ test: boolean
18
+ }): string {
19
+ const classicAddress = deriveAddress(options.publicKey)
20
+ return classicAddressToXAddress(classicAddress, options.tag, options.test)
21
+ }
22
+
23
+ export { deriveKeypair, deriveAddress, deriveXAddress }
@@ -0,0 +1,186 @@
1
+ import BigNumber from 'bignumber.js'
2
+ import flatten from 'lodash/flatten'
3
+ import groupBy from 'lodash/groupBy'
4
+
5
+ import {
6
+ Amount,
7
+ Balance,
8
+ IssuedCurrencyAmount,
9
+ TransactionMetadata,
10
+ Node,
11
+ } from '../models'
12
+
13
+ import { dropsToXrp } from './xrpConversion'
14
+
15
+ interface BalanceChange {
16
+ account: string
17
+ balance: Balance
18
+ }
19
+ interface Fields {
20
+ Account?: string
21
+ Balance?: Amount
22
+ LowLimit?: IssuedCurrencyAmount
23
+ HighLimit?: IssuedCurrencyAmount
24
+ // eslint-disable-next-line @typescript-eslint/member-ordering -- okay here, just some of the fields are typed to make it easier
25
+ [field: string]: unknown
26
+ }
27
+
28
+ interface NormalizedNode {
29
+ // 'CreatedNode' | 'ModifiedNode' | 'DeletedNode'
30
+ NodeType: string
31
+ LedgerEntryType: string
32
+ LedgerIndex: string
33
+ NewFields?: Fields
34
+ FinalFields?: Fields
35
+ PreviousFields?: Fields
36
+ PreviousTxnID?: string
37
+ PreviousTxnLgrSeq?: number
38
+ }
39
+
40
+ function normalizeNode(affectedNode: Node): NormalizedNode {
41
+ const diffType = Object.keys(affectedNode)[0]
42
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- not quite right, but close enough
43
+ const node = affectedNode[diffType] as NormalizedNode
44
+ return {
45
+ ...node,
46
+ NodeType: diffType,
47
+ LedgerEntryType: node.LedgerEntryType,
48
+ LedgerIndex: node.LedgerIndex,
49
+ NewFields: node.NewFields,
50
+ FinalFields: node.FinalFields,
51
+ PreviousFields: node.PreviousFields,
52
+ }
53
+ }
54
+
55
+ function normalizeNodes(metadata: TransactionMetadata): NormalizedNode[] {
56
+ if (metadata.AffectedNodes.length === 0) {
57
+ return []
58
+ }
59
+ return metadata.AffectedNodes.map(normalizeNode)
60
+ }
61
+
62
+ function groupByAccount(balanceChanges: BalanceChange[]): Array<{
63
+ account: string
64
+ balances: Balance[]
65
+ }> {
66
+ const grouped = groupBy(balanceChanges, (node) => node.account)
67
+ return Object.entries(grouped).map(([account, items]) => {
68
+ return { account, balances: items.map((item) => item.balance) }
69
+ })
70
+ }
71
+
72
+ function getValue(balance: Amount): BigNumber {
73
+ if (typeof balance === 'string') {
74
+ return new BigNumber(balance)
75
+ }
76
+ return new BigNumber(balance.value)
77
+ }
78
+
79
+ function computeBalanceChange(node: NormalizedNode): BigNumber | null {
80
+ let value: BigNumber | null = null
81
+ if (node.NewFields?.Balance) {
82
+ value = getValue(node.NewFields.Balance)
83
+ } else if (node.PreviousFields?.Balance && node.FinalFields?.Balance) {
84
+ value = getValue(node.FinalFields.Balance).minus(
85
+ getValue(node.PreviousFields.Balance),
86
+ )
87
+ }
88
+ if (value === null || value.isZero()) {
89
+ return null
90
+ }
91
+ return value
92
+ }
93
+
94
+ function getXRPQuantity(
95
+ node: NormalizedNode,
96
+ ): { account: string; balance: Balance } | null {
97
+ const value = computeBalanceChange(node)
98
+
99
+ if (value === null) {
100
+ return null
101
+ }
102
+
103
+ return {
104
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- okay here
105
+ account: (node.FinalFields?.Account ?? node.NewFields?.Account) as string,
106
+ balance: {
107
+ currency: 'XRP',
108
+ value: dropsToXrp(value).toString(),
109
+ },
110
+ }
111
+ }
112
+
113
+ function flipTrustlinePerspective(balanceChange: BalanceChange): BalanceChange {
114
+ const negatedBalance = new BigNumber(balanceChange.balance.value).negated()
115
+ return {
116
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we know this is true
117
+ account: balanceChange.balance.issuer as string,
118
+ balance: {
119
+ issuer: balanceChange.account,
120
+ currency: balanceChange.balance.currency,
121
+ value: negatedBalance.toString(),
122
+ },
123
+ }
124
+ }
125
+
126
+ function getTrustlineQuantity(node: NormalizedNode): BalanceChange[] | null {
127
+ const value = computeBalanceChange(node)
128
+
129
+ if (value === null) {
130
+ return null
131
+ }
132
+
133
+ /*
134
+ * A trustline can be created with a non-zero starting balance.
135
+ * If an offer is placed to acquire an asset with no existing trustline,
136
+ * the trustline can be created when the offer is taken.
137
+ */
138
+ const fields = node.NewFields == null ? node.FinalFields : node.NewFields
139
+
140
+ // the balance is always from low node's perspective
141
+ const result = {
142
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we know that this is true
143
+ account: fields?.LowLimit?.issuer as string,
144
+ balance: {
145
+ issuer: fields?.HighLimit?.issuer,
146
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we know that this is true
147
+ currency: (fields?.Balance as IssuedCurrencyAmount).currency,
148
+ value: value.toString(),
149
+ },
150
+ }
151
+ return [result, flipTrustlinePerspective(result)]
152
+ }
153
+
154
+ /**
155
+ * Computes the complete list of every balance that changed in the ledger
156
+ * as a result of the given transaction.
157
+ *
158
+ * @param metadata - Transaction metadata.
159
+ * @returns Parsed balance changes.
160
+ * @category Utilities
161
+ */
162
+ export default function getBalanceChanges(
163
+ metadata: TransactionMetadata,
164
+ ): Array<{
165
+ account: string
166
+ balances: Balance[]
167
+ }> {
168
+ const quantities = normalizeNodes(metadata).map((node) => {
169
+ if (node.LedgerEntryType === 'AccountRoot') {
170
+ const xrpQuantity = getXRPQuantity(node)
171
+ if (xrpQuantity == null) {
172
+ return []
173
+ }
174
+ return [xrpQuantity]
175
+ }
176
+ if (node.LedgerEntryType === 'RippleState') {
177
+ const trustlineQuantity = getTrustlineQuantity(node)
178
+ if (trustlineQuantity == null) {
179
+ return []
180
+ }
181
+ return trustlineQuantity
182
+ }
183
+ return []
184
+ })
185
+ return groupByAccount(flatten(quantities))
186
+ }
@@ -0,0 +1,97 @@
1
+ import flatMap from 'lodash/flatMap'
2
+ import { decode } from 'ripple-binary-codec'
3
+
4
+ import { NFToken } from '../models/ledger/NFTokenPage'
5
+ import {
6
+ CreatedNode,
7
+ isCreatedNode,
8
+ isModifiedNode,
9
+ ModifiedNode,
10
+ TransactionMetadata,
11
+ } from '../models/transactions/metadata'
12
+
13
+ /**
14
+ * Ensures that the metadata is in a deserialized format to parse.
15
+ *
16
+ * @param meta - the metadata from a `tx` method call. Can be in json format or binary format.
17
+ * @returns the metadata in a deserialized format.
18
+ */
19
+ function ensureDecodedMeta(
20
+ meta: TransactionMetadata | string,
21
+ ): TransactionMetadata {
22
+ if (typeof meta === 'string') {
23
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Meta is either metadata or serialized metadata.
24
+ return decode(meta) as unknown as TransactionMetadata
25
+ }
26
+ return meta
27
+ }
28
+
29
+ /**
30
+ * Gets the NFTokenID for an NFT recently minted with NFTokenMint.
31
+ *
32
+ * @param meta - Metadata from the response to submitting and waiting for an NFTokenMint transaction or from a `tx` method call.
33
+ * @returns The NFTokenID for the minted NFT.
34
+ * @throws if meta is not TransactionMetadata.
35
+ */
36
+ export default function getNFTokenID(
37
+ meta: TransactionMetadata | string | undefined,
38
+ ): string | undefined {
39
+ if (typeof meta !== 'string' && meta?.AffectedNodes === undefined) {
40
+ throw new TypeError(`Unable to parse the parameter given to getNFTokenID.
41
+ 'meta' must be the metadata from an NFTokenMint transaction. Received ${JSON.stringify(
42
+ meta,
43
+ )} instead.`)
44
+ }
45
+
46
+ const decodedMeta = ensureDecodedMeta(meta)
47
+
48
+ /*
49
+ * When a mint results in splitting an existing page,
50
+ * it results in a created page and a modified node. Sometimes,
51
+ * the created node needs to be linked to a third page, resulting
52
+ * in modifying that third page's PreviousPageMin or NextPageMin
53
+ * field changing, but no NFTs within that page changing. In this
54
+ * case, there will be no previous NFTs and we need to skip.
55
+ * However, there will always be NFTs listed in the final fields,
56
+ * as rippled outputs all fields in final fields even if they were
57
+ * not changed. Thus why we add the additional condition to check
58
+ * if the PreviousFields contains NFTokens
59
+ */
60
+
61
+ const affectedNodes = decodedMeta.AffectedNodes.filter((node) => {
62
+ if (isCreatedNode(node)) {
63
+ return node.CreatedNode.LedgerEntryType === 'NFTokenPage'
64
+ }
65
+ if (isModifiedNode(node)) {
66
+ return (
67
+ node.ModifiedNode.LedgerEntryType === 'NFTokenPage' &&
68
+ Boolean(node.ModifiedNode.PreviousFields?.NFTokens)
69
+ )
70
+ }
71
+ return false
72
+ })
73
+ /* eslint-disable @typescript-eslint/consistent-type-assertions -- Necessary for parsing metadata */
74
+ const previousTokenIDSet = new Set(
75
+ flatMap(affectedNodes, (node) => {
76
+ const nftokens = isModifiedNode(node)
77
+ ? (node.ModifiedNode.PreviousFields?.NFTokens as NFToken[])
78
+ : []
79
+ return nftokens.map((token) => token.NFToken.NFTokenID)
80
+ }).filter((id) => Boolean(id)),
81
+ )
82
+
83
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition -- Cleaner to read */
84
+ const finalTokenIDs = flatMap(affectedNodes, (node) =>
85
+ (
86
+ (((node as ModifiedNode).ModifiedNode?.FinalFields?.NFTokens ??
87
+ (node as CreatedNode).CreatedNode?.NewFields?.NFTokens) as NFToken[]) ??
88
+ []
89
+ ).map((token) => token.NFToken.NFTokenID),
90
+ ).filter((nftokenID) => Boolean(nftokenID))
91
+ /* eslint-enable @typescript-eslint/consistent-type-assertions -- Necessary for parsing metadata */
92
+ /* eslint-enable @typescript-eslint/no-unnecessary-condition -- Cleaner to read */
93
+
94
+ const nftokenID = finalTokenIDs.find((id) => !previousTokenIDSet.has(id))
95
+
96
+ return nftokenID
97
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Prefix for hashing functions.
3
+ *
4
+ * These prefixes are inserted before the source material used to
5
+ * generate various hashes. This is done to put each hash in its own
6
+ * "space." This way, two different types of objects with the
7
+ * same binary data will produce different hashes.
8
+ *
9
+ * Each prefix is a 4-byte value with the last byte set to zero
10
+ * and the first three bytes formed from the ASCII equivalent of
11
+ * some arbitrary string. For example "TXN".
12
+ */
13
+
14
+ enum HashPrefix {
15
+ // transaction plus signature to give transaction ID 'TXN'
16
+ TRANSACTION_ID = 0x54584e00,
17
+
18
+ // transaction plus metadata 'TND'
19
+ TRANSACTION_NODE = 0x534e4400,
20
+
21
+ // inner node in tree 'MIN'
22
+ INNER_NODE = 0x4d494e00,
23
+
24
+ // leaf node in tree 'MLN'
25
+ LEAF_NODE = 0x4d4c4e00,
26
+
27
+ // inner transaction to sign 'STX'
28
+ TRANSACTION_SIGN = 0x53545800,
29
+
30
+ // inner transaction to sign (TESTNET) 'stx'
31
+ TRANSACTION_SIGN_TESTNET = 0x73747800,
32
+
33
+ // inner transaction to multisign 'SMT'
34
+ TRANSACTION_MULTISIGN = 0x534d5400,
35
+
36
+ // ledger 'LWR'
37
+ LEDGER = 0x4c575200,
38
+ }
39
+
40
+ export default HashPrefix