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,69 @@
1
+ import { Amount } from '../common'
2
+
3
+ export interface CreatedNode {
4
+ CreatedNode: {
5
+ LedgerEntryType: string
6
+ LedgerIndex: string
7
+ NewFields: { [field: string]: unknown }
8
+ }
9
+ }
10
+
11
+ export interface ModifiedNode {
12
+ ModifiedNode: {
13
+ LedgerEntryType: string
14
+ LedgerIndex: string
15
+ FinalFields?: { [field: string]: unknown }
16
+ PreviousFields?: { [field: string]: unknown }
17
+ PreviousTxnID?: string
18
+ PreviousTxnLgrSeq?: number
19
+ }
20
+ }
21
+
22
+ export interface DeletedNode {
23
+ DeletedNode: {
24
+ LedgerEntryType: string
25
+ LedgerIndex: string
26
+ FinalFields: { [field: string]: unknown }
27
+ }
28
+ }
29
+
30
+ export type Node = CreatedNode | ModifiedNode | DeletedNode
31
+
32
+ /**
33
+ * A typeguard to check if a node is a CreatedNode.
34
+ *
35
+ * @param node - A node from metadata.
36
+ * @returns whether the given node is a CreatedNode.
37
+ */
38
+ export function isCreatedNode(node: Node): node is CreatedNode {
39
+ return Object.prototype.hasOwnProperty.call(node, `CreatedNode`)
40
+ }
41
+
42
+ /**
43
+ * A typeguard to check if a node is a ModifiedNode.
44
+ *
45
+ * @param node - A node from metadata.
46
+ * @returns whether the given node is a ModifiedNode.
47
+ */
48
+ export function isModifiedNode(node: Node): node is ModifiedNode {
49
+ return Object.prototype.hasOwnProperty.call(node, `ModifiedNode`)
50
+ }
51
+
52
+ /**
53
+ * A typeguard to check if a node is a DeletedNode.
54
+ *
55
+ * @param node - A node from metadata.
56
+ * @returns whether the given node is a DeletedNode.
57
+ */
58
+ export function isDeletedNode(node: Node): node is DeletedNode {
59
+ return Object.prototype.hasOwnProperty.call(node, `DeletedNode`)
60
+ }
61
+
62
+ export interface TransactionMetadata {
63
+ AffectedNodes: Node[]
64
+ DeliveredAmount?: Amount
65
+ // "unavailable" possible for transactions before 2014-01-20
66
+ delivered_amount?: Amount | 'unavailable'
67
+ TransactionIndex: number
68
+ TransactionResult: string
69
+ }
@@ -0,0 +1,37 @@
1
+ import { ValidationError } from '../../errors'
2
+
3
+ import { BaseTransaction, validateBaseTransaction } from './common'
4
+
5
+ /**
6
+ * An OfferCancel transaction removes an Offer object from the XRP Ledger.
7
+ *
8
+ * @category Transaction Models
9
+ */
10
+ export interface OfferCancel extends BaseTransaction {
11
+ TransactionType: 'OfferCancel'
12
+ /**
13
+ * The sequence number (or Ticket number) of a previous OfferCreate
14
+ * transaction. If specified, cancel any offer object in the ledger that was
15
+ * created by that transaction. It is not considered an error if the offer.
16
+ * specified does not exist.
17
+ */
18
+ OfferSequence: number
19
+ }
20
+
21
+ /**
22
+ * Verify the form and type of an OfferCancel at runtime.
23
+ *
24
+ * @param tx - An OfferCancel Transaction.
25
+ * @throws When the OfferCancel is Malformed.
26
+ */
27
+ export function validateOfferCancel(tx: Record<string, unknown>): void {
28
+ validateBaseTransaction(tx)
29
+
30
+ if (tx.OfferSequence === undefined) {
31
+ throw new ValidationError('OfferCancel: missing field OfferSequence')
32
+ }
33
+
34
+ if (typeof tx.OfferSequence !== 'number') {
35
+ throw new ValidationError('OfferCancel: OfferSequence must be a number')
36
+ }
37
+ }
@@ -0,0 +1,144 @@
1
+ /* eslint-disable complexity -- Necessary for validateOfferCreate */
2
+ import { ValidationError } from '../../errors'
3
+ import { Amount } from '../common'
4
+
5
+ import {
6
+ BaseTransaction,
7
+ GlobalFlags,
8
+ validateBaseTransaction,
9
+ isAmount,
10
+ } from './common'
11
+
12
+ /**
13
+ * Transaction Flags for an OfferCreate Transaction.
14
+ *
15
+ * @category Transaction Flags
16
+ */
17
+ export enum OfferCreateFlags {
18
+ /**
19
+ * If enabled, the offer does not consume offers that exactly match it, and
20
+ * instead becomes an Offer object in the ledger. It still consumes offers
21
+ * that cross it.
22
+ */
23
+ tfPassive = 0x00010000,
24
+ /**
25
+ * Treat the offer as an Immediate or Cancel order. If enabled, the offer
26
+ * never becomes a ledger object: it only tries to match existing offers in
27
+ * the ledger. If the offer cannot match any offers immediately, it executes
28
+ * "successfully" without trading any currency. In this case, the transaction
29
+ * has the result code tesSUCCESS, but creates no Offer objects in the ledger.
30
+ */
31
+ tfImmediateOrCancel = 0x00020000,
32
+ /**
33
+ * Treat the offer as a Fill or Kill order . Only try to match existing
34
+ * offers in the ledger, and only do so if the entire TakerPays quantity can
35
+ * be obtained. If the fix1578 amendment is enabled and the offer cannot be
36
+ * executed when placed, the transaction has the result code tecKILLED;
37
+ * otherwise, the transaction uses the result code tesSUCCESS even when it was
38
+ * killed without trading any currency.
39
+ */
40
+ tfFillOrKill = 0x00040000,
41
+ /**
42
+ * Exchange the entire TakerGets amount, even if it means obtaining more than
43
+ * the TakerPays amount in exchange.
44
+ */
45
+ tfSell = 0x00080000,
46
+ }
47
+
48
+ /**
49
+ * Map of flags to boolean values representing {@link OfferCreate} transaction
50
+ * flags.
51
+ *
52
+ * @category Transaction Flags
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const tx: OfferCreate = {
57
+ * Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
58
+ * TakerGets: '43000.51',
59
+ * TakerPays: '12928290425',
60
+ * TransactionType: 'OfferCreate',
61
+ * Flags: {
62
+ * tfPassive: true,
63
+ * tfFillOrKill: true,
64
+ * },
65
+ * }
66
+ *
67
+ * // Autofill the tx to see how flags actually look compared to the interface usage.
68
+ * const autofilledTx = await client.autofill(tx)
69
+ * console.log(autofilledTx)
70
+ * // {
71
+ * // Account: 'rhFcpWDHLqpBmX4ezWiA5VLSS4e1BHqhHd',
72
+ * // TakerGets: '43000.51',
73
+ * // TakerPays: '12928290425',
74
+ * // TransactionType: 'OfferCreate',
75
+ * // Flags: 327680,
76
+ * // Sequence: 21970384,
77
+ * // Fee: '12',
78
+ * // LastLedgerSequence: 21970404
79
+ * // }
80
+ * ```
81
+ */
82
+ export interface OfferCreateFlagsInterface extends GlobalFlags {
83
+ tfPassive?: boolean
84
+ tfImmediateOrCancel?: boolean
85
+ tfFillOrKill?: boolean
86
+ tfSell?: boolean
87
+ }
88
+
89
+ /**
90
+ * An OfferCreate transaction is effectively a limit order . It defines an
91
+ * intent to exchange currencies, and creates an Offer object if not completely.
92
+ * Fulfilled when placed. Offers can be partially fulfilled.
93
+ *
94
+ * @category Transaction Models
95
+ */
96
+ export interface OfferCreate extends BaseTransaction {
97
+ TransactionType: 'OfferCreate'
98
+ Flags?: number | OfferCreateFlagsInterface
99
+ /**
100
+ * Time after which the offer is no longer active, in seconds since the.
101
+ * Ripple Epoch.
102
+ */
103
+ Expiration?: number
104
+ /** An offer to delete first, specified in the same way as OfferCancel. */
105
+ OfferSequence?: number
106
+ /** The amount and type of currency being provided by the offer creator. */
107
+ TakerGets: Amount
108
+ /** The amount and type of currency being requested by the offer creator. */
109
+ TakerPays: Amount
110
+ }
111
+
112
+ /**
113
+ * Verify the form and type of an OfferCreate at runtime.
114
+ *
115
+ * @param tx - An OfferCreate Transaction.
116
+ * @throws When the OfferCreate is Malformed.
117
+ */
118
+ export function validateOfferCreate(tx: Record<string, unknown>): void {
119
+ validateBaseTransaction(tx)
120
+
121
+ if (tx.TakerGets === undefined) {
122
+ throw new ValidationError('OfferCreate: missing field TakerGets')
123
+ }
124
+
125
+ if (tx.TakerPays === undefined) {
126
+ throw new ValidationError('OfferCreate: missing field TakerPays')
127
+ }
128
+
129
+ if (typeof tx.TakerGets !== 'string' && !isAmount(tx.TakerGets)) {
130
+ throw new ValidationError('OfferCreate: invalid TakerGets')
131
+ }
132
+
133
+ if (typeof tx.TakerPays !== 'string' && !isAmount(tx.TakerPays)) {
134
+ throw new ValidationError('OfferCreate: invalid TakerPays')
135
+ }
136
+
137
+ if (tx.Expiration !== undefined && typeof tx.Expiration !== 'number') {
138
+ throw new ValidationError('OfferCreate: invalid Expiration')
139
+ }
140
+
141
+ if (tx.OfferSequence !== undefined && typeof tx.OfferSequence !== 'number') {
142
+ throw new ValidationError('OfferCreate: invalid OfferSequence')
143
+ }
144
+ }
@@ -0,0 +1,278 @@
1
+ /* eslint-disable complexity -- Necessary for validatePayment */
2
+ import { ValidationError } from '../../errors'
3
+ import { Amount, Path } from '../common'
4
+ import { isFlagEnabled } from '../utils'
5
+
6
+ import {
7
+ BaseTransaction,
8
+ isAmount,
9
+ GlobalFlags,
10
+ validateBaseTransaction,
11
+ } from './common'
12
+
13
+ /**
14
+ * Enum representing values for Payment Transaction Flags.
15
+ *
16
+ * @category Transaction Flags
17
+ */
18
+ export enum PaymentFlags {
19
+ /**
20
+ * Do not use the default path; only use paths included in the Paths field.
21
+ * This is intended to force the transaction to take arbitrage opportunities.
22
+ * Most clients do not need this.
23
+ */
24
+ tfNoDirectRipple = 0x00010000,
25
+ /**
26
+ * If the specified Amount cannot be sent without spending more than SendMax,
27
+ * reduce the received amount instead of failing outright. See Partial.
28
+ * Payments for more details.
29
+ */
30
+ tfPartialPayment = 0x00020000,
31
+ /**
32
+ * Only take paths where all the conversions have an input:output ratio that
33
+ * is equal or better than the ratio of Amount:SendMax. See Limit Quality for
34
+ * details.
35
+ */
36
+ tfLimitQuality = 0x00040000,
37
+ }
38
+
39
+ /**
40
+ * Map of flags to boolean values representing {@link Payment} transaction
41
+ * flags.
42
+ *
43
+ * @category Transaction Flags
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const partialPayment: Payment = {
48
+ * TransactionType: 'Payment',
49
+ * Account: 'rM9WCfJU6udpFkvKThRaFHDMsp7L8rpgN',
50
+ * Amount: {
51
+ * currency: 'FOO',
52
+ * value: '4000',
53
+ * issuer: 'rPzwM2JfCSDjhbesdTCqFjWWdK7eFtTwZz',
54
+ * },
55
+ * Destination: 'rPzwM2JfCSDjhbesdTCqFjWWdK7eFtTwZz',
56
+ * Flags: {
57
+ * tfPartialPayment: true
58
+ * }
59
+ * }
60
+ *
61
+ * // Autofill the tx to see how flags actually look compared to the interface usage.
62
+ * const autofilledTx = await client.autofill(partialPayment)
63
+ * console.log(autofilledTx)
64
+ * // {
65
+ * // TransactionType: 'Payment',
66
+ * // Account: 'rM9WCfJU6udpFkvKThRaFHDMsp7L8rpgN',
67
+ * // Amount: {
68
+ * // currency: 'FOO',
69
+ * // value: '4000',
70
+ * // issuer: 'rPzwM2JfCSDjhbesdTCqFjWWdK7eFtTwZz'
71
+ * // },
72
+ * // Destination: 'rPzwM2JfCSDjhbesdTCqFjWWdK7eFtTwZz',
73
+ * // Flags: 131072,
74
+ * // Sequence: 21970996,
75
+ * // Fee: '12',
76
+ * // LastLedgerSequence: 21971016
77
+ * // }
78
+ * ```
79
+ */
80
+ export interface PaymentFlagsInterface extends GlobalFlags {
81
+ /**
82
+ * Do not use the default path; only use paths included in the Paths field.
83
+ * This is intended to force the transaction to take arbitrage opportunities.
84
+ * Most clients do not need this.
85
+ */
86
+ tfNoDirectRipple?: boolean
87
+ /**
88
+ * If the specified Amount cannot be sent without spending more than SendMax,
89
+ * reduce the received amount instead of failing outright. See Partial.
90
+ * Payments for more details.
91
+ */
92
+ tfPartialPayment?: boolean
93
+ /**
94
+ * Only take paths where all the conversions have an input:output ratio that
95
+ * is equal or better than the ratio of Amount:SendMax. See Limit Quality for
96
+ * details.
97
+ */
98
+ tfLimitQuality?: boolean
99
+ }
100
+
101
+ /**
102
+ * A Payment transaction represents a transfer of value from one account to
103
+ * another.
104
+ *
105
+ * @category Transaction Models
106
+ */
107
+ export interface Payment extends BaseTransaction {
108
+ TransactionType: 'Payment'
109
+ /**
110
+ * The amount of currency to deliver. For non-XRP amounts, the nested field
111
+ * names MUST be lower-case. If the tfPartialPayment flag is set, deliver up
112
+ * to this amount instead.
113
+ */
114
+ Amount: Amount
115
+ /** The unique address of the account receiving the payment. */
116
+ Destination: string
117
+ /**
118
+ * Arbitrary tag that identifies the reason for the payment to the
119
+ * destination, or a hosted recipient to pay.
120
+ */
121
+ DestinationTag?: number
122
+ /**
123
+ * Arbitrary 256-bit hash representing a specific reason or identifier for
124
+ * this payment.
125
+ */
126
+ InvoiceID?: string
127
+ /**
128
+ * Array of payment paths to be used for this transaction. Must be omitted
129
+ * for XRP-to-XRP transactions.
130
+ */
131
+ Paths?: Path[]
132
+ /**
133
+ * Highest amount of source currency this transaction is allowed to cost,
134
+ * including transfer fees, exchange rates, and slippage . Does not include
135
+ * the XRP destroyed as a cost for submitting the transaction. For non-XRP
136
+ * amounts, the nested field names MUST be lower-case. Must be supplied for
137
+ * cross-currency/cross-issue payments. Must be omitted for XRP-to-XRP
138
+ * Payments.
139
+ */
140
+ SendMax?: Amount
141
+ /**
142
+ * Minimum amount of destination currency this transaction should deliver.
143
+ * Only valid if this is a partial payment. For non-XRP amounts, the nested
144
+ * field names are lower-case.
145
+ */
146
+ DeliverMin?: Amount
147
+ Flags?: number | PaymentFlagsInterface
148
+ }
149
+
150
+ /**
151
+ * Verify the form and type of a Payment at runtime.
152
+ *
153
+ * @param tx - A Payment Transaction.
154
+ * @throws When the Payment is malformed.
155
+ */
156
+ export function validatePayment(tx: Record<string, unknown>): void {
157
+ validateBaseTransaction(tx)
158
+
159
+ if (tx.Amount === undefined) {
160
+ throw new ValidationError('PaymentTransaction: missing field Amount')
161
+ }
162
+
163
+ if (!isAmount(tx.Amount)) {
164
+ throw new ValidationError('PaymentTransaction: invalid Amount')
165
+ }
166
+
167
+ if (tx.Destination === undefined) {
168
+ throw new ValidationError('PaymentTransaction: missing field Destination')
169
+ }
170
+
171
+ if (!isAmount(tx.Destination)) {
172
+ throw new ValidationError('PaymentTransaction: invalid Destination')
173
+ }
174
+
175
+ if (tx.DestinationTag != null && typeof tx.DestinationTag !== 'number') {
176
+ throw new ValidationError(
177
+ 'PaymentTransaction: DestinationTag must be a number',
178
+ )
179
+ }
180
+
181
+ if (tx.InvoiceID !== undefined && typeof tx.InvoiceID !== 'string') {
182
+ throw new ValidationError('PaymentTransaction: InvoiceID must be a string')
183
+ }
184
+
185
+ if (
186
+ tx.Paths !== undefined &&
187
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS
188
+ !isPaths(tx.Paths as Array<Array<Record<string, unknown>>>)
189
+ ) {
190
+ throw new ValidationError('PaymentTransaction: invalid Paths')
191
+ }
192
+
193
+ if (tx.SendMax !== undefined && !isAmount(tx.SendMax)) {
194
+ throw new ValidationError('PaymentTransaction: invalid SendMax')
195
+ }
196
+
197
+ checkPartialPayment(tx)
198
+ }
199
+
200
+ function checkPartialPayment(tx: Record<string, unknown>): void {
201
+ if (tx.DeliverMin != null) {
202
+ if (tx.Flags == null) {
203
+ throw new ValidationError(
204
+ 'PaymentTransaction: tfPartialPayment flag required with DeliverMin',
205
+ )
206
+ }
207
+
208
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Only used by JS
209
+ const flags = tx.Flags as number | PaymentFlagsInterface
210
+ const isTfPartialPayment =
211
+ typeof flags === 'number'
212
+ ? isFlagEnabled(flags, PaymentFlags.tfPartialPayment)
213
+ : flags.tfPartialPayment ?? false
214
+
215
+ if (!isTfPartialPayment) {
216
+ throw new ValidationError(
217
+ 'PaymentTransaction: tfPartialPayment flag required with DeliverMin',
218
+ )
219
+ }
220
+
221
+ if (!isAmount(tx.DeliverMin)) {
222
+ throw new ValidationError('PaymentTransaction: invalid DeliverMin')
223
+ }
224
+ }
225
+ }
226
+
227
+ function isPathStep(pathStep: Record<string, unknown>): boolean {
228
+ if (pathStep.account !== undefined && typeof pathStep.account !== 'string') {
229
+ return false
230
+ }
231
+ if (
232
+ pathStep.currency !== undefined &&
233
+ typeof pathStep.currency !== 'string'
234
+ ) {
235
+ return false
236
+ }
237
+ if (pathStep.issuer !== undefined && typeof pathStep.issuer !== 'string') {
238
+ return false
239
+ }
240
+ if (
241
+ pathStep.account !== undefined &&
242
+ pathStep.currency === undefined &&
243
+ pathStep.issuer === undefined
244
+ ) {
245
+ return true
246
+ }
247
+ if (pathStep.currency !== undefined || pathStep.issuer !== undefined) {
248
+ return true
249
+ }
250
+ return false
251
+ }
252
+
253
+ function isPath(path: Array<Record<string, unknown>>): boolean {
254
+ for (const pathStep of path) {
255
+ if (!isPathStep(pathStep)) {
256
+ return false
257
+ }
258
+ }
259
+ return true
260
+ }
261
+
262
+ function isPaths(paths: Array<Array<Record<string, unknown>>>): boolean {
263
+ if (!Array.isArray(paths) || paths.length === 0) {
264
+ return false
265
+ }
266
+
267
+ for (const path of paths) {
268
+ if (!Array.isArray(path) || path.length === 0) {
269
+ return false
270
+ }
271
+
272
+ if (!isPath(path)) {
273
+ return false
274
+ }
275
+ }
276
+
277
+ return true
278
+ }
@@ -0,0 +1,165 @@
1
+ /* eslint-disable complexity -- Necessary for validatePaymentChannelClaim */
2
+ import { ValidationError } from '../../errors'
3
+
4
+ import { BaseTransaction, GlobalFlags, validateBaseTransaction } from './common'
5
+
6
+ /**
7
+ * Enum representing values for PaymentChannelClaim transaction flags.
8
+ *
9
+ * @category Transaction Flags
10
+ */
11
+ export enum PaymentChannelClaimFlags {
12
+ /**
13
+ * Clear the channel's Expiration time. (Expiration is different from the
14
+ * channel's immutable CancelAfter time.) Only the source address of the
15
+ * payment channel can use this flag.
16
+ */
17
+ tfRenew = 0x00010000,
18
+ /**
19
+ * Request to close the channel. Only the channel source and destination
20
+ * addresses can use this flag. This flag closes the channel immediately if it
21
+ * has no more XRP allocated to it after processing the current claim, or if
22
+ * the destination address uses it. If the source address uses this flag when
23
+ * the channel still holds XRP, this schedules the channel to close after
24
+ * SettleDelay seconds have passed. (Specifically, this sets the Expiration of
25
+ * the channel to the close time of the previous ledger plus the channel's
26
+ * SettleDelay time, unless the channel already has an earlier Expiration
27
+ * time.) If the destination address uses this flag when the channel still
28
+ * holds XRP, any XRP that remains after processing the claim is returned to
29
+ * the source address.
30
+ */
31
+ tfClose = 0x00020000,
32
+ }
33
+
34
+ /**
35
+ * Map of flags to boolean values representing {@link PaymentChannelClaim}
36
+ * transaction flags.
37
+ *
38
+ * @category Transaction Flags
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const paymentChannelClaim: PaymentChannelClaim = {
43
+ * Account: 'rMpxZpuy5RBSP47oK2hDWUtk3B5BNQHfGj,
44
+ * TransactionType: 'PaymentChannelClaim',
45
+ * Channel: hashes.hashPaymentChannel(
46
+ * 'rMpxZpuy5RBSP47oK2hDWUtk3B5BNQHfGj',
47
+ * 'rQGYqiyH5Ue9J96p4E6Qt6AvqxK4sDhnS5',
48
+ * 21970712,
49
+ * ),
50
+ * Amount: '100',
51
+ * Flags: {
52
+ * tfClose: true
53
+ * }
54
+ *}
55
+ *
56
+ * // Autofill the tx to see how flags actually look compared to the interface usage.
57
+ * const autofilledTx = await client.autofill(paymentChannelClaim)
58
+ * console.log(autofilledTx)
59
+ * // {
60
+ * // Account: 'rMpxZpuy5RBSP47oK2hDWUtk3B5BNQHfGj',
61
+ * // TransactionType: 'PaymentChannelClaim',
62
+ * // Channel: 'FC14BF9245D731DC1749EE0F070765E4EB4E993F8ECEE3D00F7E6E26D6EF98CF',
63
+ * // Amount: '100',
64
+ * // Flags: 131072,
65
+ * // Sequence: 21970713,
66
+ * // Fee: '12',
67
+ * // LastLedgerSequence: 21970658
68
+ * // }
69
+ * ```
70
+ */
71
+ export interface PaymentChannelClaimFlagsInterface extends GlobalFlags {
72
+ /**
73
+ * Clear the channel's Expiration time. (Expiration is different from the
74
+ * channel's immutable CancelAfter time.) Only the source address of the
75
+ * payment channel can use this flag.
76
+ */
77
+ tfRenew?: boolean
78
+ /**
79
+ * Request to close the channel. Only the channel source and destination
80
+ * addresses can use this flag. This flag closes the channel immediately if it
81
+ * has no more XRP allocated to it after processing the current claim, or if
82
+ * the destination address uses it. If the source address uses this flag when
83
+ * the channel still holds XRP, this schedules the channel to close after
84
+ * SettleDelay seconds have passed. (Specifically, this sets the Expiration of
85
+ * the channel to the close time of the previous ledger plus the channel's
86
+ * SettleDelay time, unless the channel already has an earlier Expiration
87
+ * time.) If the destination address uses this flag when the channel still
88
+ * holds XRP, any XRP that remains after processing the claim is returned to
89
+ * the source address.
90
+ */
91
+ tfClose?: boolean
92
+ }
93
+
94
+ /**
95
+ * Claim XRP from a payment channel, adjust the payment channel's expiration,
96
+ * or both.
97
+ *
98
+ * @category Transaction Models
99
+ */
100
+ export interface PaymentChannelClaim extends BaseTransaction {
101
+ TransactionType: 'PaymentChannelClaim'
102
+ Flags?: number | PaymentChannelClaimFlagsInterface
103
+ /** The unique ID of the channel as a 64-character hexadecimal string. */
104
+ Channel: string
105
+ /**
106
+ * Total amount of XRP, in drops, delivered by this channel after processing
107
+ * this claim. Required to deliver XRP. Must be more than the total amount
108
+ * delivered by the channel so far, but not greater than the Amount of the
109
+ * signed claim. Must be provided except when closing the channel.
110
+ */
111
+ Balance?: string
112
+ /**
113
+ * The amount of XRP, in drops, authorized by the Signature. This must match
114
+ * the amount in the signed message. This is the cumulative amount of XRP that
115
+ * can be dispensed by the channel, including XRP previously redeemed.
116
+ */
117
+ Amount?: string
118
+ /**
119
+ * The signature of this claim, as hexadecimal. The signed message contains
120
+ * the channel ID and the amount of the claim. Required unless the sender of
121
+ * the transaction is the source address of the channel.
122
+ */
123
+ Signature?: string
124
+ /**
125
+ * The public key used for the signature, as hexadecimal. This must match the
126
+ * PublicKey stored in the ledger for the channel. Required unless the sender
127
+ * of the transaction is the source address of the channel and the Signature
128
+ * field is omitted.
129
+ */
130
+ PublicKey?: string
131
+ }
132
+
133
+ /**
134
+ * Verify the form and type of an PaymentChannelClaim at runtime.
135
+ *
136
+ * @param tx - An PaymentChannelClaim Transaction.
137
+ * @throws When the PaymentChannelClaim is Malformed.
138
+ */
139
+ export function validatePaymentChannelClaim(tx: Record<string, unknown>): void {
140
+ validateBaseTransaction(tx)
141
+
142
+ if (tx.Channel === undefined) {
143
+ throw new ValidationError('PaymentChannelClaim: missing Channel')
144
+ }
145
+
146
+ if (typeof tx.Channel !== 'string') {
147
+ throw new ValidationError('PaymentChannelClaim: Channel must be a string')
148
+ }
149
+
150
+ if (tx.Balance !== undefined && typeof tx.Balance !== 'string') {
151
+ throw new ValidationError('PaymentChannelClaim: Balance must be a string')
152
+ }
153
+
154
+ if (tx.Amount !== undefined && typeof tx.Amount !== 'string') {
155
+ throw new ValidationError('PaymentChannelClaim: Amount must be a string')
156
+ }
157
+
158
+ if (tx.Signature !== undefined && typeof tx.Signature !== 'string') {
159
+ throw new ValidationError('PaymentChannelClaim: Signature must be a string')
160
+ }
161
+
162
+ if (tx.PublicKey !== undefined && typeof tx.PublicKey !== 'string') {
163
+ throw new ValidationError('PaymentChannelClaim: PublicKey must be a string')
164
+ }
165
+ }