xrpl 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) 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 +728 -28
  4. package/build/xrpl-latest.js.map +1 -1
  5. package/dist/npm/Wallet/walletFromSecretNumbers.d.ts +7 -0
  6. package/dist/npm/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
  7. package/dist/npm/Wallet/walletFromSecretNumbers.js +27 -0
  8. package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -0
  9. package/dist/npm/client/index.d.ts +2 -1
  10. package/dist/npm/client/index.d.ts.map +1 -1
  11. package/dist/npm/client/index.js.map +1 -1
  12. package/dist/npm/index.d.ts +1 -0
  13. package/dist/npm/index.d.ts.map +1 -1
  14. package/dist/npm/index.js +3 -1
  15. package/dist/npm/index.js.map +1 -1
  16. package/dist/npm/models/common/index.d.ts +5 -0
  17. package/dist/npm/models/common/index.d.ts.map +1 -1
  18. package/dist/npm/models/ledger/AMM.d.ts +27 -0
  19. package/dist/npm/models/ledger/AMM.d.ts.map +1 -0
  20. package/dist/npm/models/ledger/AMM.js +3 -0
  21. package/dist/npm/models/ledger/AMM.js.map +1 -0
  22. package/dist/npm/models/ledger/AccountRoot.d.ts +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/LedgerEntry.d.ts +2 -1
  27. package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
  28. package/dist/npm/models/methods/ammInfo.d.ts +39 -0
  29. package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
  30. package/dist/npm/models/methods/ammInfo.js +3 -0
  31. package/dist/npm/models/methods/ammInfo.js.map +1 -0
  32. package/dist/npm/models/methods/index.d.ts +4 -3
  33. package/dist/npm/models/methods/index.d.ts.map +1 -1
  34. package/dist/npm/models/methods/ledgerEntry.d.ts +10 -0
  35. package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
  36. package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
  37. package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
  38. package/dist/npm/models/transactions/AMMBid.js +56 -0
  39. package/dist/npm/models/transactions/AMMBid.js.map +1 -0
  40. package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
  41. package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
  42. package/dist/npm/models/transactions/AMMCreate.js +32 -0
  43. package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
  44. package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
  45. package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
  46. package/dist/npm/models/transactions/AMMDelete.js +22 -0
  47. package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
  48. package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
  49. package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
  50. package/dist/npm/models/transactions/AMMDeposit.js +51 -0
  51. package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
  52. package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
  53. package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
  54. package/dist/npm/models/transactions/AMMVote.js +32 -0
  55. package/dist/npm/models/transactions/AMMVote.js.map +1 -0
  56. package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
  57. package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
  58. package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
  59. package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
  60. package/dist/npm/models/transactions/common.d.ts +2 -1
  61. package/dist/npm/models/transactions/common.d.ts.map +1 -1
  62. package/dist/npm/models/transactions/common.js +12 -1
  63. package/dist/npm/models/transactions/common.js.map +1 -1
  64. package/dist/npm/models/transactions/index.d.ts +6 -0
  65. package/dist/npm/models/transactions/index.d.ts.map +1 -1
  66. package/dist/npm/models/transactions/index.js +5 -1
  67. package/dist/npm/models/transactions/index.js.map +1 -1
  68. package/dist/npm/models/transactions/transaction.d.ts +7 -1
  69. package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
  70. package/dist/npm/models/transactions/transaction.js +24 -0
  71. package/dist/npm/models/transactions/transaction.js.map +1 -1
  72. package/dist/npm/models/utils/flags.d.ts.map +1 -1
  73. package/dist/npm/models/utils/flags.js +14 -21
  74. package/dist/npm/models/utils/flags.js.map +1 -1
  75. package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
  76. package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
  77. package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
  78. package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
  79. package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
  80. package/dist/npm/src/client/index.d.ts +2 -1
  81. package/dist/npm/src/client/index.d.ts.map +1 -1
  82. package/dist/npm/src/client/index.js.map +1 -1
  83. package/dist/npm/src/index.d.ts +1 -0
  84. package/dist/npm/src/index.d.ts.map +1 -1
  85. package/dist/npm/src/index.js +3 -1
  86. package/dist/npm/src/index.js.map +1 -1
  87. package/dist/npm/src/models/common/index.d.ts +5 -0
  88. package/dist/npm/src/models/common/index.d.ts.map +1 -1
  89. package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
  90. package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
  91. package/dist/npm/src/models/ledger/AMM.js +3 -0
  92. package/dist/npm/src/models/ledger/AMM.js.map +1 -0
  93. package/dist/npm/src/models/ledger/AccountRoot.d.ts +2 -0
  94. package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
  95. package/dist/npm/src/models/ledger/AccountRoot.js +1 -0
  96. package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
  97. package/dist/npm/src/models/ledger/LedgerEntry.d.ts +2 -1
  98. package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
  99. package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
  100. package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
  101. package/dist/npm/src/models/methods/ammInfo.js +3 -0
  102. package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
  103. package/dist/npm/src/models/methods/index.d.ts +4 -3
  104. package/dist/npm/src/models/methods/index.d.ts.map +1 -1
  105. package/dist/npm/src/models/methods/ledgerEntry.d.ts +10 -0
  106. package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
  107. package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
  108. package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
  109. package/dist/npm/src/models/transactions/AMMBid.js +56 -0
  110. package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
  111. package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
  112. package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
  113. package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
  114. package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
  115. package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
  116. package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
  117. package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
  118. package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
  119. package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
  120. package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
  121. package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
  122. package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
  123. package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
  124. package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
  125. package/dist/npm/src/models/transactions/AMMVote.js +32 -0
  126. package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
  127. package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
  128. package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
  129. package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
  130. package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
  131. package/dist/npm/src/models/transactions/common.d.ts +2 -1
  132. package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
  133. package/dist/npm/src/models/transactions/common.js +12 -1
  134. package/dist/npm/src/models/transactions/common.js.map +1 -1
  135. package/dist/npm/src/models/transactions/index.d.ts +6 -0
  136. package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
  137. package/dist/npm/src/models/transactions/index.js +5 -1
  138. package/dist/npm/src/models/transactions/index.js.map +1 -1
  139. package/dist/npm/src/models/transactions/transaction.d.ts +7 -1
  140. package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
  141. package/dist/npm/src/models/transactions/transaction.js +24 -0
  142. package/dist/npm/src/models/transactions/transaction.js.map +1 -1
  143. package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
  144. package/dist/npm/src/models/utils/flags.js +14 -21
  145. package/dist/npm/src/models/utils/flags.js.map +1 -1
  146. package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
  147. package/dist/npm/src/sugar/autofill.js +4 -3
  148. package/dist/npm/src/sugar/autofill.js.map +1 -1
  149. package/dist/npm/sugar/autofill.d.ts.map +1 -1
  150. package/dist/npm/sugar/autofill.js +4 -3
  151. package/dist/npm/sugar/autofill.js.map +1 -1
  152. package/package.json +8 -6
  153. package/src/ECDSA.ts +6 -0
  154. package/src/Wallet/defaultFaucets.ts +82 -0
  155. package/src/Wallet/fundWallet.ts +344 -0
  156. package/src/Wallet/index.ts +504 -0
  157. package/src/Wallet/rfc1751.ts +190 -0
  158. package/src/Wallet/rfc1751Words.json +243 -0
  159. package/src/Wallet/signer.ts +173 -0
  160. package/src/Wallet/walletFromSecretNumbers.ts +37 -0
  161. package/src/client/BroadcastClient.ts +84 -0
  162. package/src/client/ConnectionManager.ts +40 -0
  163. package/src/client/ExponentialBackoff.ts +71 -0
  164. package/src/client/RequestManager.ts +194 -0
  165. package/src/client/WSWrapper.ts +106 -0
  166. package/src/client/connection.ts +593 -0
  167. package/src/client/index.ts +712 -0
  168. package/src/client/partialPayment.ts +153 -0
  169. package/src/errors.ts +161 -0
  170. package/src/index.ts +20 -0
  171. package/src/models/common/index.ts +149 -0
  172. package/src/models/index.ts +16 -0
  173. package/src/models/ledger/AMM.ts +78 -0
  174. package/src/models/ledger/AccountRoot.ts +217 -0
  175. package/src/models/ledger/Amendments.ts +45 -0
  176. package/src/models/ledger/BaseLedgerEntry.ts +3 -0
  177. package/src/models/ledger/Check.ts +70 -0
  178. package/src/models/ledger/DepositPreauth.ts +35 -0
  179. package/src/models/ledger/DirectoryNode.ts +46 -0
  180. package/src/models/ledger/Escrow.ts +74 -0
  181. package/src/models/ledger/FeeSettings.ts +52 -0
  182. package/src/models/ledger/Ledger.ts +65 -0
  183. package/src/models/ledger/LedgerEntry.ts +34 -0
  184. package/src/models/ledger/LedgerHashes.ts +24 -0
  185. package/src/models/ledger/NFTokenOffer.ts +16 -0
  186. package/src/models/ledger/NFTokenPage.ts +20 -0
  187. package/src/models/ledger/NegativeUNL.ts +34 -0
  188. package/src/models/ledger/Offer.ts +52 -0
  189. package/src/models/ledger/PayChannel.ts +107 -0
  190. package/src/models/ledger/RippleState.ts +88 -0
  191. package/src/models/ledger/SignerList.ts +56 -0
  192. package/src/models/ledger/Ticket.ts +36 -0
  193. package/src/models/ledger/index.ts +58 -0
  194. package/src/models/methods/accountChannels.ts +93 -0
  195. package/src/models/methods/accountCurrencies.ts +45 -0
  196. package/src/models/methods/accountInfo.ts +182 -0
  197. package/src/models/methods/accountLines.ts +137 -0
  198. package/src/models/methods/accountNFTs.ts +72 -0
  199. package/src/models/methods/accountObjects.ts +120 -0
  200. package/src/models/methods/accountOffers.ts +100 -0
  201. package/src/models/methods/accountTx.ts +109 -0
  202. package/src/models/methods/ammInfo.ts +145 -0
  203. package/src/models/methods/baseMethod.ts +58 -0
  204. package/src/models/methods/bookOffers.ts +96 -0
  205. package/src/models/methods/channelVerify.ts +41 -0
  206. package/src/models/methods/depositAuthorized.ts +56 -0
  207. package/src/models/methods/fee.ts +91 -0
  208. package/src/models/methods/gatewayBalances.ts +85 -0
  209. package/src/models/methods/index.ts +391 -0
  210. package/src/models/methods/ledger.ts +125 -0
  211. package/src/models/methods/ledgerClosed.ts +32 -0
  212. package/src/models/methods/ledgerCurrent.ts +31 -0
  213. package/src/models/methods/ledgerData.ts +78 -0
  214. package/src/models/methods/ledgerEntry.ts +177 -0
  215. package/src/models/methods/manifest.ts +54 -0
  216. package/src/models/methods/nftBuyOffers.ts +37 -0
  217. package/src/models/methods/nftHistory.ts +113 -0
  218. package/src/models/methods/nftInfo.ts +25 -0
  219. package/src/models/methods/nftSellOffers.ts +37 -0
  220. package/src/models/methods/norippleCheck.ts +82 -0
  221. package/src/models/methods/pathFind.ts +116 -0
  222. package/src/models/methods/ping.ts +21 -0
  223. package/src/models/methods/random.ts +23 -0
  224. package/src/models/methods/ripplePathFind.ts +81 -0
  225. package/src/models/methods/serverInfo.ts +257 -0
  226. package/src/models/methods/serverState.ts +77 -0
  227. package/src/models/methods/submit.ts +94 -0
  228. package/src/models/methods/submitMultisigned.ts +51 -0
  229. package/src/models/methods/subscribe.ts +435 -0
  230. package/src/models/methods/transactionEntry.ts +47 -0
  231. package/src/models/methods/tx.ts +69 -0
  232. package/src/models/methods/unsubscribe.ts +49 -0
  233. package/src/models/transactions/AMMBid.ts +140 -0
  234. package/src/models/transactions/AMMCreate.ts +80 -0
  235. package/src/models/transactions/AMMDelete.ts +55 -0
  236. package/src/models/transactions/AMMDeposit.ts +130 -0
  237. package/src/models/transactions/AMMVote.ts +71 -0
  238. package/src/models/transactions/AMMWithdraw.ts +126 -0
  239. package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
  240. package/src/models/transactions/NFTokenBurn.ts +48 -0
  241. package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
  242. package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
  243. package/src/models/transactions/NFTokenMint.ts +123 -0
  244. package/src/models/transactions/UNLModify.ts +20 -0
  245. package/src/models/transactions/accountDelete.ts +50 -0
  246. package/src/models/transactions/accountSet.ts +228 -0
  247. package/src/models/transactions/checkCancel.ts +34 -0
  248. package/src/models/transactions/checkCash.ts +73 -0
  249. package/src/models/transactions/checkCreate.ts +90 -0
  250. package/src/models/transactions/clawback.ts +49 -0
  251. package/src/models/transactions/common.ts +295 -0
  252. package/src/models/transactions/depositPreauth.ts +68 -0
  253. package/src/models/transactions/enableAmendment.ts +26 -0
  254. package/src/models/transactions/escrowCancel.ts +45 -0
  255. package/src/models/transactions/escrowCreate.ts +100 -0
  256. package/src/models/transactions/escrowFinish.ts +63 -0
  257. package/src/models/transactions/index.ts +66 -0
  258. package/src/models/transactions/metadata.ts +69 -0
  259. package/src/models/transactions/offerCancel.ts +37 -0
  260. package/src/models/transactions/offerCreate.ts +144 -0
  261. package/src/models/transactions/payment.ts +278 -0
  262. package/src/models/transactions/paymentChannelClaim.ts +165 -0
  263. package/src/models/transactions/paymentChannelCreate.ts +116 -0
  264. package/src/models/transactions/paymentChannelFund.ts +65 -0
  265. package/src/models/transactions/setFee.ts +48 -0
  266. package/src/models/transactions/setRegularKey.ts +33 -0
  267. package/src/models/transactions/signerListSet.ts +89 -0
  268. package/src/models/transactions/ticketCreate.ts +50 -0
  269. package/src/models/transactions/transaction.ts +303 -0
  270. package/src/models/transactions/trustSet.ts +146 -0
  271. package/src/models/utils/flags.ts +98 -0
  272. package/src/models/utils/index.ts +37 -0
  273. package/src/sugar/autofill.ts +373 -0
  274. package/src/sugar/balances.ts +123 -0
  275. package/src/sugar/getFeeXrp.ts +45 -0
  276. package/src/sugar/getLedgerIndex.ts +15 -0
  277. package/src/sugar/getOrderbook.ts +152 -0
  278. package/src/sugar/index.ts +11 -0
  279. package/src/sugar/submit.ts +305 -0
  280. package/src/sugar/utils.ts +29 -0
  281. package/src/utils/derive.ts +23 -0
  282. package/src/utils/getBalanceChanges.ts +186 -0
  283. package/src/utils/getNFTokenID.ts +97 -0
  284. package/src/utils/hashes/HashPrefix.ts +40 -0
  285. package/src/utils/hashes/README.md +65 -0
  286. package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
  287. package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
  288. package/src/utils/hashes/SHAMap/index.ts +41 -0
  289. package/src/utils/hashes/SHAMap/node.ts +14 -0
  290. package/src/utils/hashes/hashLedger.ts +236 -0
  291. package/src/utils/hashes/index.ts +187 -0
  292. package/src/utils/hashes/ledgerSpaces.ts +34 -0
  293. package/src/utils/hashes/sha512Half.ts +19 -0
  294. package/src/utils/index.ts +223 -0
  295. package/src/utils/parseNFTokenID.ts +84 -0
  296. package/src/utils/quality.ts +169 -0
  297. package/src/utils/signPaymentChannelClaim.ts +27 -0
  298. package/src/utils/stringConversion.ts +27 -0
  299. package/src/utils/timeConversion.ts +53 -0
  300. package/src/utils/verifyPaymentChannelClaim.ts +30 -0
  301. package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,295 @@
1
+ /* eslint-disable max-lines-per-function -- Necessary for validateBaseTransaction */
2
+ /* eslint-disable complexity -- Necessary for validateBaseTransaction */
3
+ /* eslint-disable max-statements -- Necessary for validateBaseTransaction */
4
+ import { TRANSACTION_TYPES } from 'ripple-binary-codec'
5
+
6
+ import { ValidationError } from '../../errors'
7
+ import { Amount, Currency, IssuedCurrencyAmount, Memo, Signer } from '../common'
8
+ import { onlyHasFields } from '../utils'
9
+
10
+ const MEMO_SIZE = 3
11
+
12
+ function isMemo(obj: { Memo?: unknown }): boolean {
13
+ if (obj.Memo == null) {
14
+ return false
15
+ }
16
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS
17
+ const memo = obj.Memo as Record<string, unknown>
18
+ const size = Object.keys(memo).length
19
+ const validData = memo.MemoData == null || typeof memo.MemoData === 'string'
20
+ const validFormat =
21
+ memo.MemoFormat == null || typeof memo.MemoFormat === 'string'
22
+ const validType = memo.MemoType == null || typeof memo.MemoType === 'string'
23
+
24
+ return (
25
+ size >= 1 &&
26
+ size <= MEMO_SIZE &&
27
+ validData &&
28
+ validFormat &&
29
+ validType &&
30
+ onlyHasFields(memo, ['MemoFormat', 'MemoData', 'MemoType'])
31
+ )
32
+ }
33
+
34
+ const SIGNER_SIZE = 3
35
+
36
+ function isSigner(obj: unknown): boolean {
37
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS
38
+ const signerWrapper = obj as Record<string, unknown>
39
+
40
+ if (signerWrapper.Signer == null) {
41
+ return false
42
+ }
43
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS and Signer is previously unknown
44
+ const signer = signerWrapper.Signer as Record<string, unknown>
45
+ return (
46
+ Object.keys(signer).length === SIGNER_SIZE &&
47
+ typeof signer.Account === 'string' &&
48
+ typeof signer.TxnSignature === 'string' &&
49
+ typeof signer.SigningPubKey === 'string'
50
+ )
51
+ }
52
+
53
+ const XRP_CURRENCY_SIZE = 1
54
+ const ISSUE_SIZE = 2
55
+ const ISSUED_CURRENCY_SIZE = 3
56
+
57
+ function isRecord(value: unknown): value is Record<string, unknown> {
58
+ return value !== null && typeof value === 'object'
59
+ }
60
+
61
+ /**
62
+ * Verify the form and type of an IssuedCurrency at runtime.
63
+ *
64
+ * @param input - The input to check the form and type of.
65
+ * @returns Whether the IssuedCurrency is properly formed.
66
+ */
67
+ export function isCurrency(input: unknown): input is Currency {
68
+ return (
69
+ isRecord(input) &&
70
+ ((Object.keys(input).length === ISSUE_SIZE &&
71
+ typeof input.issuer === 'string' &&
72
+ typeof input.currency === 'string') ||
73
+ (Object.keys(input).length === XRP_CURRENCY_SIZE &&
74
+ input.currency === 'XRP'))
75
+ )
76
+ }
77
+
78
+ /**
79
+ * Verify the form and type of an IssuedCurrencyAmount at runtime.
80
+ *
81
+ * @param input - The input to check the form and type of.
82
+ * @returns Whether the IssuedCurrencyAmount is properly formed.
83
+ */
84
+ export function isIssuedCurrency(
85
+ input: unknown,
86
+ ): input is IssuedCurrencyAmount {
87
+ return (
88
+ isRecord(input) &&
89
+ Object.keys(input).length === ISSUED_CURRENCY_SIZE &&
90
+ typeof input.value === 'string' &&
91
+ typeof input.issuer === 'string' &&
92
+ typeof input.currency === 'string'
93
+ )
94
+ }
95
+
96
+ /**
97
+ * Verify the form and type of an Amount at runtime.
98
+ *
99
+ * @param amount - The object to check the form and type of.
100
+ * @returns Whether the Amount is properly formed.
101
+ */
102
+ export function isAmount(amount: unknown): amount is Amount {
103
+ return typeof amount === 'string' || isIssuedCurrency(amount)
104
+ }
105
+
106
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface -- no global flags right now, so this is fine
107
+ export interface GlobalFlags {}
108
+
109
+ /**
110
+ * Every transaction has the same set of common fields.
111
+ */
112
+ export interface BaseTransaction {
113
+ /** The unique address of the transaction sender. */
114
+ Account: string
115
+ /**
116
+ * The type of transaction. Valid types include: `Payment`, `OfferCreate`,
117
+ * `TrustSet`, and many others.
118
+ */
119
+ TransactionType: string
120
+ /**
121
+ * Integer amount of XRP, in drops, to be destroyed as a cost for
122
+ * distributing this transaction to the network. Some transaction types have
123
+ * different minimum requirements.
124
+ */
125
+ Fee?: string
126
+ /**
127
+ * The sequence number of the account sending the transaction. A transaction
128
+ * is only valid if the Sequence number is exactly 1 greater than the previous
129
+ * transaction from the same account. The special case 0 means the transaction
130
+ * is using a Ticket instead.
131
+ */
132
+ Sequence?: number
133
+ /**
134
+ * Hash value identifying another transaction. If provided, this transaction
135
+ * is only valid if the sending account's previously-sent transaction matches
136
+ * the provided hash.
137
+ */
138
+ AccountTxnID?: string
139
+ /** Set of bit-flags for this transaction. */
140
+ Flags?: number | GlobalFlags
141
+ /**
142
+ * Highest ledger index this transaction can appear in. Specifying this field
143
+ * places a strict upper limit on how long the transaction can wait to be
144
+ * validated or rejected.
145
+ */
146
+ LastLedgerSequence?: number
147
+ /**
148
+ * Additional arbitrary information used to identify this transaction.
149
+ */
150
+ Memos?: Memo[]
151
+ /**
152
+ * Array of objects that represent a multi-signature which authorizes this
153
+ * transaction.
154
+ */
155
+ Signers?: Signer[]
156
+ /**
157
+ * Arbitrary integer used to identify the reason for this payment, or a sender
158
+ * on whose behalf this transaction is made. Conventionally, a refund should
159
+ * specify the initial payment's SourceTag as the refund payment's
160
+ * DestinationTag.
161
+ */
162
+ SourceTag?: number
163
+ /**
164
+ * Hex representation of the public key that corresponds to the private key
165
+ * used to sign this transaction. If an empty string, indicates a
166
+ * multi-signature is present in the Signers field instead.
167
+ */
168
+ SigningPubKey?: string
169
+ /**
170
+ * The sequence number of the ticket to use in place of a Sequence number. If
171
+ * this is provided, Sequence must be 0. Cannot be used with AccountTxnID.
172
+ */
173
+ TicketSequence?: number
174
+ /**
175
+ * The signature that verifies this transaction as originating from the
176
+ * account it says it is from.
177
+ */
178
+ TxnSignature?: string
179
+ /**
180
+ * The network id of the transaction.
181
+ */
182
+ NetworkID?: number
183
+ }
184
+
185
+ /**
186
+ * Verify the common fields of a transaction. The validate functionality will be
187
+ * optional, and will check transaction form at runtime. This should be called
188
+ * any time a transaction will be verified.
189
+ *
190
+ * @param common - An interface w/ common transaction fields.
191
+ * @throws When the common param is malformed.
192
+ */
193
+ export function validateBaseTransaction(common: Record<string, unknown>): void {
194
+ if (common.Account === undefined) {
195
+ throw new ValidationError('BaseTransaction: missing field Account')
196
+ }
197
+
198
+ if (typeof common.Account !== 'string') {
199
+ throw new ValidationError('BaseTransaction: Account not string')
200
+ }
201
+
202
+ if (common.TransactionType === undefined) {
203
+ throw new ValidationError('BaseTransaction: missing field TransactionType')
204
+ }
205
+
206
+ if (typeof common.TransactionType !== 'string') {
207
+ throw new ValidationError('BaseTransaction: TransactionType not string')
208
+ }
209
+
210
+ if (!TRANSACTION_TYPES.includes(common.TransactionType)) {
211
+ throw new ValidationError('BaseTransaction: Unknown TransactionType')
212
+ }
213
+
214
+ if (common.Fee !== undefined && typeof common.Fee !== 'string') {
215
+ throw new ValidationError('BaseTransaction: invalid Fee')
216
+ }
217
+
218
+ if (common.Sequence !== undefined && typeof common.Sequence !== 'number') {
219
+ throw new ValidationError('BaseTransaction: invalid Sequence')
220
+ }
221
+
222
+ if (
223
+ common.AccountTxnID !== undefined &&
224
+ typeof common.AccountTxnID !== 'string'
225
+ ) {
226
+ throw new ValidationError('BaseTransaction: invalid AccountTxnID')
227
+ }
228
+
229
+ if (
230
+ common.LastLedgerSequence !== undefined &&
231
+ typeof common.LastLedgerSequence !== 'number'
232
+ ) {
233
+ throw new ValidationError('BaseTransaction: invalid LastLedgerSequence')
234
+ }
235
+
236
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS
237
+ const memos = common.Memos as Array<{ Memo?: unknown }> | undefined
238
+ if (memos !== undefined && !memos.every(isMemo)) {
239
+ throw new ValidationError('BaseTransaction: invalid Memos')
240
+ }
241
+
242
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS
243
+ const signers = common.Signers as Array<Record<string, unknown>> | undefined
244
+
245
+ if (
246
+ signers !== undefined &&
247
+ (signers.length === 0 || !signers.every(isSigner))
248
+ ) {
249
+ throw new ValidationError('BaseTransaction: invalid Signers')
250
+ }
251
+
252
+ if (common.SourceTag !== undefined && typeof common.SourceTag !== 'number') {
253
+ throw new ValidationError('BaseTransaction: invalid SourceTag')
254
+ }
255
+
256
+ if (
257
+ common.SigningPubKey !== undefined &&
258
+ typeof common.SigningPubKey !== 'string'
259
+ ) {
260
+ throw new ValidationError('BaseTransaction: invalid SigningPubKey')
261
+ }
262
+
263
+ if (
264
+ common.TicketSequence !== undefined &&
265
+ typeof common.TicketSequence !== 'number'
266
+ ) {
267
+ throw new ValidationError('BaseTransaction: invalid TicketSequence')
268
+ }
269
+
270
+ if (
271
+ common.TxnSignature !== undefined &&
272
+ typeof common.TxnSignature !== 'string'
273
+ ) {
274
+ throw new ValidationError('BaseTransaction: invalid TxnSignature')
275
+ }
276
+ if (common.NetworkID !== undefined && typeof common.NetworkID !== 'number') {
277
+ throw new ValidationError('BaseTransaction: invalid NetworkID')
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Parse the value of an amount, expressed either in XRP or as an Issued Currency, into a number.
283
+ *
284
+ * @param amount - An Amount to parse for its value.
285
+ * @returns The parsed amount value, or NaN if the amount count not be parsed.
286
+ */
287
+ export function parseAmountValue(amount: unknown): number {
288
+ if (!isAmount(amount)) {
289
+ return NaN
290
+ }
291
+ if (typeof amount === 'string') {
292
+ return parseFloat(amount)
293
+ }
294
+ return parseFloat(amount.value)
295
+ }
@@ -0,0 +1,68 @@
1
+ /* eslint-disable complexity -- Necessary for validateDepositPreauth */
2
+ import { ValidationError } from '../../errors'
3
+
4
+ import { BaseTransaction, validateBaseTransaction } from './common'
5
+
6
+ /**
7
+ * A DepositPreauth transaction gives another account pre-approval to deliver
8
+ * payments to the sender of this transaction. This is only useful if the sender
9
+ * of this transaction is using (or plans to use) Deposit Authorization.
10
+ *
11
+ * @category Transaction Models
12
+ */
13
+ export interface DepositPreauth extends BaseTransaction {
14
+ TransactionType: 'DepositPreauth'
15
+ /** The XRP Ledger address of the sender to preauthorize. */
16
+ Authorize?: string
17
+ /**
18
+ * The XRP Ledger address of a sender whose preauthorization should be.
19
+ * revoked.
20
+ */
21
+ Unauthorize?: string
22
+ }
23
+
24
+ /**
25
+ * Verify the form and type of a DepositPreauth at runtime.
26
+ *
27
+ * @param tx - A DepositPreauth Transaction.
28
+ * @throws When the DepositPreauth is malformed.
29
+ */
30
+ export function validateDepositPreauth(tx: Record<string, unknown>): void {
31
+ validateBaseTransaction(tx)
32
+
33
+ if (tx.Authorize !== undefined && tx.Unauthorize !== undefined) {
34
+ throw new ValidationError(
35
+ "DepositPreauth: can't provide both Authorize and Unauthorize fields",
36
+ )
37
+ }
38
+
39
+ if (tx.Authorize === undefined && tx.Unauthorize === undefined) {
40
+ throw new ValidationError(
41
+ 'DepositPreauth: must provide either Authorize or Unauthorize field',
42
+ )
43
+ }
44
+
45
+ if (tx.Authorize !== undefined) {
46
+ if (typeof tx.Authorize !== 'string') {
47
+ throw new ValidationError('DepositPreauth: Authorize must be a string')
48
+ }
49
+
50
+ if (tx.Account === tx.Authorize) {
51
+ throw new ValidationError(
52
+ "DepositPreauth: Account can't preauthorize its own address",
53
+ )
54
+ }
55
+ }
56
+
57
+ if (tx.Unauthorize !== undefined) {
58
+ if (typeof tx.Unauthorize !== 'string') {
59
+ throw new ValidationError('DepositPreauth: Unauthorize must be a string')
60
+ }
61
+
62
+ if (tx.Account === tx.Unauthorize) {
63
+ throw new ValidationError(
64
+ "DepositPreauth: Account can't unauthorize its own address",
65
+ )
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,26 @@
1
+ import { BaseTransaction } from './common'
2
+
3
+ /**
4
+ * Transaction Flags for an EnableAmendment Transaction.
5
+ *
6
+ * @category Transaction Flags
7
+ */
8
+ export enum EnableAmendmentFlags {
9
+ /** Support for this amendment increased to at least 80% of trusted validators starting with this ledger version. */
10
+ tfGotMajority = 0x00010000,
11
+ /** Support for this amendment decreased to less than 80% of trusted validators starting with this ledger version. */
12
+ tfLostMajority = 0x00020000,
13
+ }
14
+
15
+ /**
16
+ * Mark a change in the status of a proposed amendment when it gains majority, looses majority, or is enabled.
17
+ *
18
+ * @category Pseudo Transaction Models
19
+ */
20
+ export interface EnableAmendment extends BaseTransaction {
21
+ TransactionType: 'EnableAmendment'
22
+ /** A unique identifier for the amendment. */
23
+ Amendment: string
24
+ /** The ledger index where this pseudo-transaction appears. */
25
+ LedgerSequence: number
26
+ }
@@ -0,0 +1,45 @@
1
+ import { ValidationError } from '../../errors'
2
+
3
+ import { BaseTransaction, validateBaseTransaction } from './common'
4
+
5
+ /**
6
+ * Return escrowed XRP to the sender.
7
+ *
8
+ * @category Transaction Models
9
+ */
10
+ export interface EscrowCancel extends BaseTransaction {
11
+ TransactionType: 'EscrowCancel'
12
+ /** Address of the source account that funded the escrow payment. */
13
+ Owner: string
14
+ /**
15
+ * Transaction sequence (or Ticket number) of EscrowCreate transaction that.
16
+ * created the escrow to cancel.
17
+ */
18
+ OfferSequence: number
19
+ }
20
+
21
+ /**
22
+ * Verify the form and type of an EscrowCancel at runtime.
23
+ *
24
+ * @param tx - An EscrowCancel Transaction.
25
+ * @throws When the EscrowCancel is Malformed.
26
+ */
27
+ export function validateEscrowCancel(tx: Record<string, unknown>): void {
28
+ validateBaseTransaction(tx)
29
+
30
+ if (tx.Owner === undefined) {
31
+ throw new ValidationError('EscrowCancel: missing Owner')
32
+ }
33
+
34
+ if (typeof tx.Owner !== 'string') {
35
+ throw new ValidationError('EscrowCancel: Owner must be a string')
36
+ }
37
+
38
+ if (tx.OfferSequence === undefined) {
39
+ throw new ValidationError('EscrowCancel: missing OfferSequence')
40
+ }
41
+
42
+ if (typeof tx.OfferSequence !== 'number') {
43
+ throw new ValidationError('EscrowCancel: OfferSequence must be a number')
44
+ }
45
+ }
@@ -0,0 +1,100 @@
1
+ /* eslint-disable complexity -- Necessary for validateEscrowCreate */
2
+ import { ValidationError } from '../../errors'
3
+
4
+ import { BaseTransaction, validateBaseTransaction } from './common'
5
+
6
+ /**
7
+ * Sequester XRP until the escrow process either finishes or is canceled.
8
+ *
9
+ * @category Transaction Models
10
+ */
11
+ export interface EscrowCreate extends BaseTransaction {
12
+ TransactionType: 'EscrowCreate'
13
+ /**
14
+ * Amount of XRP, in drops, to deduct from the sender's balance and escrow.
15
+ * Once escrowed, the XRP can either go to the Destination address (after the.
16
+ * FinishAfter time) or returned to the sender (after the CancelAfter time).
17
+ */
18
+ Amount: string
19
+ /** Address to receive escrowed XRP. */
20
+ Destination: string
21
+ /**
22
+ * The time, in seconds since the Ripple Epoch, when this escrow expires.
23
+ * This value is immutable; the funds can only be returned the sender after.
24
+ * this time.
25
+ */
26
+ CancelAfter?: number
27
+ /**
28
+ * The time, in seconds since the Ripple Epoch, when the escrowed XRP can be
29
+ * released to the recipient. This value is immutable; the funds cannot move.
30
+ * until this time is reached.
31
+ */
32
+ FinishAfter?: number
33
+ /**
34
+ * Hex value representing a PREIMAGE-SHA-256 crypto-condition . The funds can.
35
+ * only be delivered to the recipient if this condition is fulfilled.
36
+ */
37
+ Condition?: string
38
+ /**
39
+ * Arbitrary tag to further specify the destination for this escrowed.
40
+ * payment, such as a hosted recipient at the destination address.
41
+ */
42
+ DestinationTag?: number
43
+ }
44
+
45
+ /**
46
+ * Verify the form and type of an EscrowCreate at runtime.
47
+ *
48
+ * @param tx - An EscrowCreate Transaction.
49
+ * @throws When the EscrowCreate is Malformed.
50
+ */
51
+ export function validateEscrowCreate(tx: Record<string, unknown>): void {
52
+ validateBaseTransaction(tx)
53
+
54
+ if (tx.Amount === undefined) {
55
+ throw new ValidationError('EscrowCreate: missing field Amount')
56
+ }
57
+
58
+ if (typeof tx.Amount !== 'string') {
59
+ throw new ValidationError('EscrowCreate: Amount must be a string')
60
+ }
61
+
62
+ if (tx.Destination === undefined) {
63
+ throw new ValidationError('EscrowCreate: missing field Destination')
64
+ }
65
+
66
+ if (typeof tx.Destination !== 'string') {
67
+ throw new ValidationError('EscrowCreate: Destination must be a string')
68
+ }
69
+
70
+ if (tx.CancelAfter === undefined && tx.FinishAfter === undefined) {
71
+ throw new ValidationError(
72
+ 'EscrowCreate: Either CancelAfter or FinishAfter must be specified',
73
+ )
74
+ }
75
+
76
+ if (tx.FinishAfter === undefined && tx.Condition === undefined) {
77
+ throw new ValidationError(
78
+ 'EscrowCreate: Either Condition or FinishAfter must be specified',
79
+ )
80
+ }
81
+
82
+ if (tx.CancelAfter !== undefined && typeof tx.CancelAfter !== 'number') {
83
+ throw new ValidationError('EscrowCreate: CancelAfter must be a number')
84
+ }
85
+
86
+ if (tx.FinishAfter !== undefined && typeof tx.FinishAfter !== 'number') {
87
+ throw new ValidationError('EscrowCreate: FinishAfter must be a number')
88
+ }
89
+
90
+ if (tx.Condition !== undefined && typeof tx.Condition !== 'string') {
91
+ throw new ValidationError('EscrowCreate: Condition must be a string')
92
+ }
93
+
94
+ if (
95
+ tx.DestinationTag !== undefined &&
96
+ typeof tx.DestinationTag !== 'number'
97
+ ) {
98
+ throw new ValidationError('EscrowCreate: DestinationTag must be a number')
99
+ }
100
+ }
@@ -0,0 +1,63 @@
1
+ import { ValidationError } from '../../errors'
2
+
3
+ import { BaseTransaction, validateBaseTransaction } from './common'
4
+
5
+ /**
6
+ * Deliver XRP from a held payment to the recipient.
7
+ *
8
+ * @category Transaction Models
9
+ */
10
+ export interface EscrowFinish extends BaseTransaction {
11
+ TransactionType: 'EscrowFinish'
12
+ /** Address of the source account that funded the held payment. */
13
+ Owner: string
14
+ /**
15
+ * Transaction sequence of EscrowCreate transaction that created the held.
16
+ * payment to finish.
17
+ */
18
+ OfferSequence: number
19
+ /**
20
+ * Hex value matching the previously-supplied PREIMAGE-SHA-256.
21
+ * crypto-condition of the held payment.
22
+ */
23
+ Condition?: string
24
+ /**
25
+ * Hex value of the PREIMAGE-SHA-256 crypto-condition fulfillment matching.
26
+ * the held payment's Condition.
27
+ */
28
+ Fulfillment?: string
29
+ }
30
+
31
+ /**
32
+ * Verify the form and type of an EscrowFinish at runtime.
33
+ *
34
+ * @param tx - An EscrowFinish Transaction.
35
+ * @throws When the EscrowFinish is Malformed.
36
+ */
37
+ export function validateEscrowFinish(tx: Record<string, unknown>): void {
38
+ validateBaseTransaction(tx)
39
+
40
+ if (tx.Owner === undefined) {
41
+ throw new ValidationError('EscrowFinish: missing field Owner')
42
+ }
43
+
44
+ if (typeof tx.Owner !== 'string') {
45
+ throw new ValidationError('EscrowFinish: Owner must be a string')
46
+ }
47
+
48
+ if (tx.OfferSequence === undefined) {
49
+ throw new ValidationError('EscrowFinish: missing field OfferSequence')
50
+ }
51
+
52
+ if (typeof tx.OfferSequence !== 'number') {
53
+ throw new ValidationError('EscrowFinish: OfferSequence must be a number')
54
+ }
55
+
56
+ if (tx.Condition !== undefined && typeof tx.Condition !== 'string') {
57
+ throw new ValidationError('EscrowFinish: Condition must be a string')
58
+ }
59
+
60
+ if (tx.Fulfillment !== undefined && typeof tx.Fulfillment !== 'string') {
61
+ throw new ValidationError('EscrowFinish: Fulfillment must be a string')
62
+ }
63
+ }
@@ -0,0 +1,66 @@
1
+ export { BaseTransaction } from './common'
2
+ export { validate, TransactionAndMetadata, Transaction } from './transaction'
3
+ export * from './metadata'
4
+ export {
5
+ AccountSetAsfFlags,
6
+ AccountSetTfFlags,
7
+ AccountSetFlagsInterface,
8
+ AccountSet,
9
+ } from './accountSet'
10
+ export { AccountDelete } from './accountDelete'
11
+ export { AMMBid } from './AMMBid'
12
+ export { AMMDelete } from './AMMDelete'
13
+ export {
14
+ AMMDepositFlags,
15
+ AMMDepositFlagsInterface,
16
+ AMMDeposit,
17
+ } from './AMMDeposit'
18
+ export { AMMCreate } from './AMMCreate'
19
+ export { AMMVote } from './AMMVote'
20
+ export {
21
+ AMMWithdrawFlags,
22
+ AMMWithdrawFlagsInterface,
23
+ AMMWithdraw,
24
+ } from './AMMWithdraw'
25
+ export { CheckCancel } from './checkCancel'
26
+ export { CheckCash } from './checkCash'
27
+ export { CheckCreate } from './checkCreate'
28
+ export { DepositPreauth } from './depositPreauth'
29
+ export { EscrowCancel } from './escrowCancel'
30
+ export { EscrowCreate } from './escrowCreate'
31
+ export { EscrowFinish } from './escrowFinish'
32
+ export { EnableAmendment, EnableAmendmentFlags } from './enableAmendment'
33
+ export { NFTokenAcceptOffer } from './NFTokenAcceptOffer'
34
+ export { NFTokenBurn } from './NFTokenBurn'
35
+ export { NFTokenCancelOffer } from './NFTokenCancelOffer'
36
+ export {
37
+ NFTokenCreateOffer,
38
+ NFTokenCreateOfferFlags,
39
+ NFTokenCreateOfferFlagsInterface,
40
+ } from './NFTokenCreateOffer'
41
+ export {
42
+ NFTokenMint,
43
+ NFTokenMintFlags,
44
+ NFTokenMintFlagsInterface,
45
+ } from './NFTokenMint'
46
+ export { OfferCancel } from './offerCancel'
47
+ export {
48
+ OfferCreateFlags,
49
+ OfferCreateFlagsInterface,
50
+ OfferCreate,
51
+ } from './offerCreate'
52
+ export { PaymentFlags, PaymentFlagsInterface, Payment } from './payment'
53
+ export {
54
+ PaymentChannelClaimFlags,
55
+ PaymentChannelClaimFlagsInterface,
56
+ PaymentChannelClaim,
57
+ } from './paymentChannelClaim'
58
+ export { PaymentChannelCreate } from './paymentChannelCreate'
59
+ export { PaymentChannelFund } from './paymentChannelFund'
60
+ export { SetFee, SetFeePreAmendment, SetFeePostAmendment } from './setFee'
61
+ export { SetRegularKey } from './setRegularKey'
62
+ export { SignerListSet } from './signerListSet'
63
+ export { TicketCreate } from './ticketCreate'
64
+ export { TrustSetFlagsInterface, TrustSetFlags, TrustSet } from './trustSet'
65
+ export { UNLModify } from './UNLModify'
66
+ export { Clawback } from './clawback'