ripple-binary-codec 1.0.4-beta.1 → 1.0.4-mpt-beta

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 (336) hide show
  1. package/README.md +3 -3
  2. package/dist/binary.d.ts +34 -20
  3. package/dist/binary.js +51 -36
  4. package/dist/binary.js.map +1 -1
  5. package/dist/coretypes.d.ts +9 -9
  6. package/dist/coretypes.js +33 -9
  7. package/dist/coretypes.js.map +1 -1
  8. package/dist/enums/bytes.d.ts +25 -0
  9. package/dist/enums/bytes.js +63 -0
  10. package/dist/enums/bytes.js.map +1 -0
  11. package/dist/enums/constants.d.ts +4 -0
  12. package/dist/enums/constants.js +8 -0
  13. package/dist/enums/constants.js.map +1 -0
  14. package/dist/enums/definitions.json +3066 -1780
  15. package/dist/enums/field.d.ts +28 -0
  16. package/dist/enums/field.js +58 -0
  17. package/dist/enums/field.js.map +1 -0
  18. package/dist/enums/index.d.ts +12 -46
  19. package/dist/enums/index.js +22 -111
  20. package/dist/enums/index.js.map +1 -1
  21. package/dist/enums/src/enums/definitions.json +3073 -0
  22. package/dist/enums/utils-renumber.js +20 -20
  23. package/dist/enums/utils-renumber.js.map +1 -1
  24. package/dist/enums/xrpl-definitions-base.d.ts +44 -0
  25. package/dist/enums/xrpl-definitions-base.js +59 -0
  26. package/dist/enums/xrpl-definitions-base.js.map +1 -0
  27. package/dist/enums/xrpl-definitions.d.ts +21 -0
  28. package/dist/enums/xrpl-definitions.js +29 -0
  29. package/dist/enums/xrpl-definitions.js.map +1 -0
  30. package/dist/hash-prefixes.d.ts +1 -2
  31. package/dist/hash-prefixes.js +7 -7
  32. package/dist/hash-prefixes.js.map +1 -1
  33. package/dist/hashes.d.ts +7 -8
  34. package/dist/hashes.js +23 -44
  35. package/dist/hashes.js.map +1 -1
  36. package/dist/index.d.ts +16 -17
  37. package/dist/index.js +65 -40
  38. package/dist/index.js.map +1 -1
  39. package/dist/ledger-hashes.d.ts +7 -5
  40. package/dist/ledger-hashes.js +40 -34
  41. package/dist/ledger-hashes.js.map +1 -1
  42. package/dist/quality.d.ts +3 -4
  43. package/dist/quality.js +20 -21
  44. package/dist/quality.js.map +1 -1
  45. package/dist/serdes/binary-parser.d.ts +8 -6
  46. package/dist/serdes/binary-parser.js +74 -65
  47. package/dist/serdes/binary-parser.js.map +1 -1
  48. package/dist/serdes/binary-serializer.d.ts +10 -11
  49. package/dist/serdes/binary-serializer.js +50 -49
  50. package/dist/serdes/binary-serializer.js.map +1 -1
  51. package/dist/shamap.d.ts +6 -7
  52. package/dist/shamap.js +74 -98
  53. package/dist/shamap.js.map +1 -1
  54. package/dist/src/binary.d.ts +90 -0
  55. package/dist/src/binary.js +128 -0
  56. package/dist/src/binary.js.map +1 -0
  57. package/dist/src/coretypes.d.ts +9 -0
  58. package/dist/src/coretypes.js +48 -0
  59. package/dist/src/coretypes.js.map +1 -0
  60. package/dist/src/enums/bytes.d.ts +25 -0
  61. package/dist/src/enums/bytes.js +63 -0
  62. package/dist/src/enums/bytes.js.map +1 -0
  63. package/dist/src/enums/constants.d.ts +4 -0
  64. package/dist/src/enums/constants.js +8 -0
  65. package/dist/src/enums/constants.js.map +1 -0
  66. package/dist/src/enums/definitions.json +3068 -0
  67. package/dist/src/enums/field.d.ts +28 -0
  68. package/dist/src/enums/field.js +58 -0
  69. package/dist/src/enums/field.js.map +1 -0
  70. package/dist/src/enums/index.d.ts +12 -0
  71. package/dist/src/enums/index.js +31 -0
  72. package/dist/src/enums/index.js.map +1 -0
  73. package/dist/src/enums/utils-renumber.d.ts +101 -0
  74. package/dist/src/enums/utils-renumber.js +127 -0
  75. package/dist/src/enums/utils-renumber.js.map +1 -0
  76. package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
  77. package/dist/src/enums/xrpl-definitions-base.js +59 -0
  78. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  79. package/dist/src/enums/xrpl-definitions.d.ts +21 -0
  80. package/dist/src/enums/xrpl-definitions.js +29 -0
  81. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  82. package/dist/src/hash-prefixes.d.ts +5 -0
  83. package/dist/src/hash-prefixes.js +41 -0
  84. package/dist/src/hash-prefixes.js.map +1 -0
  85. package/dist/src/hashes.d.ts +50 -0
  86. package/dist/src/hashes.js +76 -0
  87. package/dist/src/hashes.js.map +1 -0
  88. package/dist/src/index.d.ts +64 -0
  89. package/dist/src/index.js +123 -0
  90. package/dist/src/index.js.map +1 -0
  91. package/dist/src/ledger-hashes.d.ts +48 -0
  92. package/dist/src/ledger-hashes.js +141 -0
  93. package/dist/src/ledger-hashes.js.map +1 -0
  94. package/dist/src/quality.d.ts +21 -0
  95. package/dist/src/quality.js +42 -0
  96. package/dist/src/quality.js.map +1 -0
  97. package/dist/src/serdes/binary-parser.d.ts +100 -0
  98. package/dist/src/serdes/binary-parser.js +194 -0
  99. package/dist/src/serdes/binary-parser.js.map +1 -0
  100. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  101. package/dist/src/serdes/binary-serializer.js +149 -0
  102. package/dist/src/serdes/binary-serializer.js.map +1 -0
  103. package/dist/src/shamap.d.ts +102 -0
  104. package/dist/src/shamap.js +172 -0
  105. package/dist/src/shamap.js.map +1 -0
  106. package/dist/src/types/account-id.d.ts +35 -0
  107. package/dist/src/types/account-id.js +69 -0
  108. package/dist/src/types/account-id.js.map +1 -0
  109. package/dist/src/types/amount.d.ts +91 -0
  110. package/dist/src/types/amount.js +289 -0
  111. package/dist/src/types/amount.js.map +1 -0
  112. package/dist/src/types/blob.d.ts +24 -0
  113. package/dist/src/types/blob.js +43 -0
  114. package/dist/src/types/blob.js.map +1 -0
  115. package/dist/src/types/currency.d.ts +28 -0
  116. package/dist/src/types/currency.js +127 -0
  117. package/dist/src/types/currency.js.map +1 -0
  118. package/dist/src/types/hash-128.d.ts +16 -0
  119. package/dist/src/types/hash-128.js +32 -0
  120. package/dist/src/types/hash-128.js.map +1 -0
  121. package/dist/src/types/hash-160.d.ts +10 -0
  122. package/dist/src/types/hash-160.js +19 -0
  123. package/dist/src/types/hash-160.js.map +1 -0
  124. package/dist/src/types/hash-192.d.ts +10 -0
  125. package/dist/src/types/hash-192.js +19 -0
  126. package/dist/src/types/hash-192.js.map +1 -0
  127. package/dist/src/types/hash-256.d.ts +10 -0
  128. package/dist/src/types/hash-256.js +16 -0
  129. package/dist/src/types/hash-256.js.map +1 -0
  130. package/dist/src/types/hash.d.ts +40 -0
  131. package/dist/src/types/hash.js +73 -0
  132. package/dist/src/types/hash.js.map +1 -0
  133. package/dist/src/types/index.d.ts +19 -0
  134. package/dist/src/types/index.js +64 -0
  135. package/dist/src/types/index.js.map +1 -0
  136. package/dist/src/types/issue.d.ts +38 -0
  137. package/dist/src/types/issue.js +81 -0
  138. package/dist/src/types/issue.js.map +1 -0
  139. package/dist/src/types/path-set.d.ts +36 -0
  140. package/dist/src/types/path-set.js +233 -0
  141. package/dist/src/types/path-set.js.map +1 -0
  142. package/dist/src/types/serialized-type.d.ts +70 -0
  143. package/dist/src/types/serialized-type.js +105 -0
  144. package/dist/src/types/serialized-type.js.map +1 -0
  145. package/dist/src/types/st-array.d.ts +31 -0
  146. package/dist/src/types/st-array.js +86 -0
  147. package/dist/src/types/st-array.js.map +1 -0
  148. package/dist/src/types/st-object.d.ts +32 -0
  149. package/dist/src/types/st-object.js +155 -0
  150. package/dist/src/types/st-object.js.map +1 -0
  151. package/dist/src/types/uint-16.d.ts +24 -0
  152. package/dist/src/types/uint-16.js +45 -0
  153. package/dist/src/types/uint-16.js.map +1 -0
  154. package/dist/src/types/uint-32.d.ts +24 -0
  155. package/dist/src/types/uint-32.js +50 -0
  156. package/dist/src/types/uint-32.js.map +1 -0
  157. package/dist/src/types/uint-64.d.ts +37 -0
  158. package/dist/src/types/uint-64.js +86 -0
  159. package/dist/src/types/uint-64.js.map +1 -0
  160. package/dist/src/types/uint-8.d.ts +24 -0
  161. package/dist/src/types/uint-8.js +46 -0
  162. package/dist/src/types/uint-8.js.map +1 -0
  163. package/dist/src/types/uint.d.ts +29 -0
  164. package/dist/src/types/uint.js +47 -0
  165. package/dist/src/types/uint.js.map +1 -0
  166. package/dist/src/types/vector-256.d.ts +30 -0
  167. package/dist/src/types/vector-256.js +73 -0
  168. package/dist/src/types/vector-256.js.map +1 -0
  169. package/dist/src/types/xchain-bridge.d.ts +44 -0
  170. package/dist/src/types/xchain-bridge.js +102 -0
  171. package/dist/src/types/xchain-bridge.js.map +1 -0
  172. package/dist/src/utils.d.ts +47 -0
  173. package/dist/src/utils.js +137 -0
  174. package/dist/src/utils.js.map +1 -0
  175. package/dist/tsconfig.tsbuildinfo +1 -0
  176. package/dist/types/account-id.d.ts +2 -3
  177. package/dist/types/account-id.js +29 -40
  178. package/dist/types/account-id.js.map +1 -1
  179. package/dist/types/amount.d.ts +33 -10
  180. package/dist/types/amount.js +181 -114
  181. package/dist/types/amount.js.map +1 -1
  182. package/dist/types/blob.d.ts +3 -4
  183. package/dist/types/blob.js +16 -28
  184. package/dist/types/blob.js.map +1 -1
  185. package/dist/types/currency.d.ts +5 -13
  186. package/dist/types/currency.js +53 -67
  187. package/dist/types/currency.js.map +1 -1
  188. package/dist/types/hash-128.d.ts +8 -3
  189. package/dist/types/hash-128.js +23 -23
  190. package/dist/types/hash-128.js.map +1 -1
  191. package/dist/types/hash-160.d.ts +2 -3
  192. package/dist/types/hash-160.js +7 -25
  193. package/dist/types/hash-160.js.map +1 -1
  194. package/dist/types/hash-192.d.ts +10 -0
  195. package/dist/types/hash-192.js +19 -0
  196. package/dist/types/hash-192.js.map +1 -0
  197. package/dist/types/hash-256.d.ts +2 -3
  198. package/dist/types/hash-256.js +7 -23
  199. package/dist/types/hash-256.js.map +1 -1
  200. package/dist/types/hash.d.ts +4 -5
  201. package/dist/types/hash.js +25 -40
  202. package/dist/types/hash.js.map +1 -1
  203. package/dist/types/index.d.ts +19 -33
  204. package/dist/types/index.js +44 -24
  205. package/dist/types/index.js.map +1 -1
  206. package/dist/types/issue.d.ts +38 -0
  207. package/dist/types/issue.js +81 -0
  208. package/dist/types/issue.js.map +1 -0
  209. package/dist/types/path-set.d.ts +2 -2
  210. package/dist/types/path-set.js +73 -95
  211. package/dist/types/path-set.js.map +1 -1
  212. package/dist/types/serialized-type.d.ts +27 -20
  213. package/dist/types/serialized-type.js +50 -61
  214. package/dist/types/serialized-type.js.map +1 -1
  215. package/dist/types/st-array.d.ts +7 -4
  216. package/dist/types/st-array.js +36 -48
  217. package/dist/types/st-array.js.map +1 -1
  218. package/dist/types/st-object.d.ts +8 -5
  219. package/dist/types/st-object.js +73 -75
  220. package/dist/types/st-object.js.map +1 -1
  221. package/dist/types/uint-16.d.ts +3 -4
  222. package/dist/types/uint-16.js +20 -34
  223. package/dist/types/uint-16.js.map +1 -1
  224. package/dist/types/uint-32.d.ts +3 -4
  225. package/dist/types/uint-32.js +23 -37
  226. package/dist/types/uint-32.js.map +1 -1
  227. package/dist/types/uint-64.d.ts +6 -8
  228. package/dist/types/uint-64.js +43 -58
  229. package/dist/types/uint-64.js.map +1 -1
  230. package/dist/types/uint-8.d.ts +3 -4
  231. package/dist/types/uint-8.js +21 -34
  232. package/dist/types/uint-8.js.map +1 -1
  233. package/dist/types/uint.d.ts +6 -7
  234. package/dist/types/uint.js +16 -26
  235. package/dist/types/uint.js.map +1 -1
  236. package/dist/types/vector-256.d.ts +3 -4
  237. package/dist/types/vector-256.js +28 -45
  238. package/dist/types/vector-256.js.map +1 -1
  239. package/dist/types/xchain-bridge.d.ts +44 -0
  240. package/dist/types/xchain-bridge.js +102 -0
  241. package/dist/types/xchain-bridge.js.map +1 -0
  242. package/dist/utils.d.ts +47 -0
  243. package/dist/utils.js +137 -0
  244. package/dist/utils.js.map +1 -0
  245. package/package.json +23 -36
  246. package/src/README.md +5 -0
  247. package/src/binary.ts +194 -0
  248. package/src/coretypes.ts +31 -0
  249. package/src/enums/README.md +144 -0
  250. package/src/enums/bytes.ts +74 -0
  251. package/src/enums/constants.ts +4 -0
  252. package/src/enums/definitions.json +3073 -0
  253. package/src/enums/field.ts +84 -0
  254. package/src/enums/index.ts +34 -0
  255. package/src/enums/utils-renumber.ts +134 -0
  256. package/src/enums/xrpl-definitions-base.ts +111 -0
  257. package/src/enums/xrpl-definitions.ts +32 -0
  258. package/src/hash-prefixes.ts +40 -0
  259. package/src/hashes.ts +75 -0
  260. package/src/index.ts +153 -0
  261. package/src/ledger-hashes.ts +191 -0
  262. package/src/quality.ts +38 -0
  263. package/src/serdes/binary-parser.ts +228 -0
  264. package/src/serdes/binary-serializer.ts +166 -0
  265. package/src/shamap.ts +186 -0
  266. package/src/types/account-id.ts +86 -0
  267. package/src/types/amount.ts +362 -0
  268. package/src/types/blob.ts +46 -0
  269. package/src/types/currency.ts +140 -0
  270. package/src/types/hash-128.ts +33 -0
  271. package/src/types/hash-160.ts +19 -0
  272. package/src/types/hash-192.ts +19 -0
  273. package/src/types/hash-256.ts +15 -0
  274. package/src/types/hash.ts +83 -0
  275. package/src/types/index.ts +66 -0
  276. package/src/types/issue.ts +96 -0
  277. package/src/types/path-set.ts +290 -0
  278. package/src/types/serialized-type.ts +122 -0
  279. package/src/types/st-array.ts +113 -0
  280. package/src/types/st-object.ts +192 -0
  281. package/src/types/uint-16.ts +53 -0
  282. package/src/types/uint-32.ts +59 -0
  283. package/src/types/uint-64.ts +104 -0
  284. package/src/types/uint-8.ts +52 -0
  285. package/src/types/uint.ts +60 -0
  286. package/src/types/vector-256.ts +79 -0
  287. package/src/types/xchain-bridge.ts +128 -0
  288. package/src/utils.ts +152 -0
  289. package/HISTORY.md +0 -74
  290. package/dist/index.js.LICENSE.txt +0 -17
  291. package/test/amount.test.js +0 -43
  292. package/test/binary-json.test.js +0 -47
  293. package/test/binary-parser.test.js +0 -398
  294. package/test/binary-serializer.test.js +0 -264
  295. package/test/fixtures/account-tx-transactions.db +0 -0
  296. package/test/fixtures/codec-fixtures.json +0 -4466
  297. package/test/fixtures/data-driven-tests.json +0 -3721
  298. package/test/fixtures/delivermin-tx-binary.json +0 -1
  299. package/test/fixtures/delivermin-tx.json +0 -98
  300. package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
  301. package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
  302. package/test/fixtures/deposit-preauth-tx.json +0 -58
  303. package/test/fixtures/escrow-cancel-binary.json +0 -1
  304. package/test/fixtures/escrow-cancel-tx.json +0 -6
  305. package/test/fixtures/escrow-create-binary.json +0 -1
  306. package/test/fixtures/escrow-create-tx.json +0 -10
  307. package/test/fixtures/escrow-finish-binary.json +0 -1
  308. package/test/fixtures/escrow-finish-meta-binary.json +0 -1
  309. package/test/fixtures/escrow-finish-tx.json +0 -95
  310. package/test/fixtures/ledger-full-38129.json +0 -1
  311. package/test/fixtures/ledger-full-40000.json +0 -1
  312. package/test/fixtures/negative-unl.json +0 -12
  313. package/test/fixtures/payment-channel-claim-binary.json +0 -1
  314. package/test/fixtures/payment-channel-claim-tx.json +0 -8
  315. package/test/fixtures/payment-channel-create-binary.json +0 -1
  316. package/test/fixtures/payment-channel-create-tx.json +0 -11
  317. package/test/fixtures/payment-channel-fund-binary.json +0 -1
  318. package/test/fixtures/payment-channel-fund-tx.json +0 -7
  319. package/test/fixtures/signerlistset-tx-binary.json +0 -1
  320. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  321. package/test/fixtures/signerlistset-tx.json +0 -94
  322. package/test/fixtures/ticket-create-binary.json +0 -1
  323. package/test/fixtures/ticket-create-tx.json +0 -7
  324. package/test/fixtures/x-codec-fixtures.json +0 -188
  325. package/test/hash.test.js +0 -83
  326. package/test/ledger.test.js +0 -29
  327. package/test/lower-case-hex.test.js +0 -45
  328. package/test/pseudo-transaction.test.js +0 -38
  329. package/test/quality.test.js +0 -15
  330. package/test/shamap.test.js +0 -89
  331. package/test/signing-data-encoding.test.js +0 -129
  332. package/test/tx-encode-decode.test.js +0 -97
  333. package/test/types.test.js +0 -34
  334. package/test/uint.test.js +0 -40
  335. package/test/utils.js +0 -30
  336. package/test/x-address.test.js +0 -147
@@ -1,30 +1,16 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
2
  Object.defineProperty(exports, "__esModule", { value: true });
16
3
  exports.AccountID = void 0;
17
- var ripple_address_codec_1 = require("ripple-address-codec");
18
- var hash_160_1 = require("./hash-160");
19
- var buffer_1 = require("buffer/");
20
- var HEX_REGEX = /^[A-F0-9]{40}$/;
4
+ const ripple_address_codec_1 = require("ripple-address-codec");
5
+ const hash_160_1 = require("./hash-160");
6
+ const utils_1 = require("@xrplf/isomorphic/utils");
7
+ const HEX_REGEX = /^[A-F0-9]{40}$/;
21
8
  /**
22
9
  * Class defining how to encode and decode an AccountID
23
10
  */
24
- var AccountID = /** @class */ (function (_super) {
25
- __extends(AccountID, _super);
26
- function AccountID(bytes) {
27
- return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : AccountID.defaultAccountID.bytes) || this;
11
+ class AccountID extends hash_160_1.Hash160 {
12
+ constructor(bytes) {
13
+ super(bytes !== null && bytes !== void 0 ? bytes : AccountID.defaultAccountID.bytes);
28
14
  }
29
15
  /**
30
16
  * Defines how to construct an AccountID
@@ -32,49 +18,52 @@ var AccountID = /** @class */ (function (_super) {
32
18
  * @param value either an existing AccountID, a hex-string, or a base58 r-Address
33
19
  * @returns an AccountID object
34
20
  */
35
- AccountID.from = function (value) {
21
+ static from(value) {
36
22
  if (value instanceof AccountID) {
37
23
  return value;
38
24
  }
39
- if (typeof value === "string") {
40
- if (value === "") {
25
+ if (typeof value === 'string') {
26
+ if (value === '') {
41
27
  return new AccountID();
42
28
  }
43
29
  return HEX_REGEX.test(value)
44
- ? new AccountID(buffer_1.Buffer.from(value, "hex"))
30
+ ? new AccountID((0, utils_1.hexToBytes)(value))
45
31
  : this.fromBase58(value);
46
32
  }
47
- throw new Error("Cannot construct AccountID from value given");
48
- };
33
+ throw new Error('Cannot construct AccountID from value given');
34
+ }
49
35
  /**
50
36
  * Defines how to build an AccountID from a base58 r-Address
51
37
  *
52
38
  * @param value a base58 r-Address
53
39
  * @returns an AccountID object
54
40
  */
55
- AccountID.fromBase58 = function (value) {
56
- return new AccountID(buffer_1.Buffer.from(ripple_address_codec_1.decodeAccountID(value)));
57
- };
41
+ static fromBase58(value) {
42
+ if ((0, ripple_address_codec_1.isValidXAddress)(value)) {
43
+ const classic = (0, ripple_address_codec_1.xAddressToClassicAddress)(value);
44
+ if (classic.tag !== false)
45
+ throw new Error('Only allowed to have tag on Account or Destination');
46
+ value = classic.classicAddress;
47
+ }
48
+ return new AccountID(Uint8Array.from((0, ripple_address_codec_1.decodeAccountID)(value)));
49
+ }
58
50
  /**
59
51
  * Overload of toJSON
60
52
  *
61
53
  * @returns the base58 string for this AccountID
62
54
  */
63
- AccountID.prototype.toJSON = function () {
55
+ toJSON() {
64
56
  return this.toBase58();
65
- };
57
+ }
66
58
  /**
67
59
  * Defines how to encode AccountID into a base58 address
68
60
  *
69
61
  * @returns the base58 string defined by this.bytes
70
62
  */
71
- AccountID.prototype.toBase58 = function () {
72
- /* eslint-disable @typescript-eslint/no-explicit-any */
73
- return ripple_address_codec_1.encodeAccountID(this.bytes);
74
- /* eslint-enable @typescript-eslint/no-explicit-any */
75
- };
76
- AccountID.defaultAccountID = new AccountID(buffer_1.Buffer.alloc(20));
77
- return AccountID;
78
- }(hash_160_1.Hash160));
63
+ toBase58() {
64
+ return (0, ripple_address_codec_1.encodeAccountID)(this.bytes);
65
+ }
66
+ }
79
67
  exports.AccountID = AccountID;
68
+ AccountID.defaultAccountID = new AccountID(new Uint8Array(20));
80
69
  //# sourceMappingURL=account-id.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../src/types/account-id.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAAwE;AACxE,uCAAqC;AACrC,kCAAiC;AAEjC,IAAM,SAAS,GAAG,gBAAgB,CAAC;AAEnC;;GAEG;AACH;IAAwB,6BAAO;IAG7B,mBAAY,KAAc;eACxB,kBAAM,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACI,cAAI,GAAX,UAAwC,KAAQ;QAC9C,IAAI,KAAK,YAAY,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,KAAK,KAAK,EAAE,EAAE;gBAChB,OAAO,IAAI,SAAS,EAAE,CAAC;aACxB;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1B,CAAC,CAAC,IAAI,SAAS,CAAC,eAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC1C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SAC5B;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACI,oBAAU,GAAjB,UAAkB,KAAa;QAC7B,OAAO,IAAI,SAAS,CAAC,eAAM,CAAC,IAAI,CAAC,sCAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,0BAAM,GAAN;QACE,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,4BAAQ,GAAR;QACE,uDAAuD;QACvD,OAAO,sCAAe,CAAC,IAAI,CAAC,KAAY,CAAC,CAAC;QAC1C,sDAAsD;IACxD,CAAC;IA1De,0BAAgB,GAAc,IAAI,SAAS,CAAC,eAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IA2DhF,gBAAC;CAAA,AA5DD,CAAwB,kBAAO,GA4D9B;AAEQ,8BAAS"}
1
+ {"version":3,"file":"account-id.js","sourceRoot":"","sources":["../../src/types/account-id.ts"],"names":[],"mappings":";;;AAAA,+DAK6B;AAC7B,yCAAoC;AACpC,mDAAoD;AAEpD,MAAM,SAAS,GAAG,gBAAgB,CAAA;AAElC;;GAEG;AACH,MAAM,SAAU,SAAQ,kBAAO;IAK7B,YAAY,KAAkB;QAC5B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAA6B,KAAQ;QAC9C,IAAI,KAAK,YAAY,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,IAAI,KAAK,KAAK,EAAE,EAAE;gBAChB,OAAO,IAAI,SAAS,EAAE,CAAA;aACvB;YAED,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1B,CAAC,CAAC,IAAI,SAAS,CAAC,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC;gBAClC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;SAC3B;QAED,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,IAAI,IAAA,sCAAe,EAAC,KAAK,CAAC,EAAE;YAC1B,MAAM,OAAO,GAAG,IAAA,+CAAwB,EAAC,KAAK,CAAC,CAAA;YAE/C,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK;gBACvB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;YAEvE,KAAK,GAAG,OAAO,CAAC,cAAc,CAAA;SAC/B;QAED,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAA,sCAAe,EAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC/D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,OAAO,IAAA,sCAAe,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;;AAGM,8BAAS;AAtEA,0BAAgB,GAAc,IAAI,SAAS,CACzD,IAAI,UAAU,CAAC,EAAE,CAAC,CACnB,CAAA"}
@@ -1,22 +1,26 @@
1
- import { BinaryParser } from "../serdes/binary-parser";
2
- import { JsonObject, SerializedType } from "./serialized-type";
3
- import { Buffer } from "buffer/";
4
- /**
5
- * Interface for JSON objects that represent amounts
6
- */
7
- interface AmountObject extends JsonObject {
1
+ import { BinaryParser } from '../serdes/binary-parser';
2
+ import { JsonObject, SerializedType } from './serialized-type';
3
+ interface AmountObjectIOU extends JsonObject {
8
4
  value: string;
9
5
  currency: string;
10
6
  issuer: string;
11
7
  }
8
+ interface AmountObjectMPT extends JsonObject {
9
+ value: string;
10
+ mpt_issuance_id: string;
11
+ }
12
+ /**
13
+ * Interface for JSON objects that represent amounts
14
+ */
15
+ type AmountObject = AmountObjectIOU | AmountObjectMPT;
12
16
  /**
13
17
  * Class for serializing/Deserializing Amounts
14
18
  */
15
19
  declare class Amount extends SerializedType {
16
20
  static defaultAmount: Amount;
17
- constructor(bytes: Buffer);
21
+ constructor(bytes: Uint8Array);
18
22
  /**
19
- * Construct an amount from an IOU or string amount
23
+ * Construct an amount from an IOU, MPT or string amount
20
24
  *
21
25
  * @param value An Amount, object representing an IOU, or a string
22
26
  * representing an integer amount
@@ -46,10 +50,17 @@ declare class Amount extends SerializedType {
46
50
  /**
47
51
  * Validate IOU.value amount
48
52
  *
49
- * @param decimal Decimal.js object representing IOU.value
53
+ * @param decimal BigNumber object representing IOU.value
50
54
  * @returns void, but will throw if invalid amount
51
55
  */
52
56
  private static assertIouIsValid;
57
+ /**
58
+ * Validate MPT.value amount
59
+ *
60
+ * @param decimal BigNumber object representing MPT.value
61
+ * @returns void, but will throw if invalid amount
62
+ */
63
+ private static assertMptIsValid;
53
64
  /**
54
65
  * Ensure that the value after being multiplied by the exponent does not
55
66
  * contain a decimal.
@@ -64,5 +75,17 @@ declare class Amount extends SerializedType {
64
75
  * @returns true if Native (XRP)
65
76
  */
66
77
  private isNative;
78
+ /**
79
+ * Test if this amount is in units of MPT
80
+ *
81
+ * @returns true if MPT
82
+ */
83
+ private isMPT;
84
+ /**
85
+ * Test if this amount is in units of IOU
86
+ *
87
+ * @returns true if IOU
88
+ */
89
+ private isIOU;
67
90
  }
68
91
  export { Amount, AmountObject };
@@ -1,153 +1,169 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
15
5
  Object.defineProperty(exports, "__esModule", { value: true });
16
6
  exports.Amount = void 0;
17
- var decimal_js_1 = require("decimal.js");
18
- var binary_parser_1 = require("../serdes/binary-parser");
19
- var account_id_1 = require("./account-id");
20
- var currency_1 = require("./currency");
21
- var serialized_type_1 = require("./serialized-type");
22
- var bigInt = require("big-integer");
23
- var buffer_1 = require("buffer/");
7
+ const binary_parser_1 = require("../serdes/binary-parser");
8
+ const account_id_1 = require("./account-id");
9
+ const currency_1 = require("./currency");
10
+ const serialized_type_1 = require("./serialized-type");
11
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
12
+ const utils_1 = require("@xrplf/isomorphic/utils");
13
+ const utils_2 = require("../utils");
14
+ const hash_192_1 = require("./hash-192");
24
15
  /**
25
16
  * Constants for validating amounts
26
17
  */
27
- var MIN_IOU_EXPONENT = -96;
28
- var MAX_IOU_EXPONENT = 80;
29
- var MAX_IOU_PRECISION = 16;
30
- var MAX_DROPS = new decimal_js_1.Decimal("1e17");
31
- var MIN_XRP = new decimal_js_1.Decimal("1e-6");
32
- var mask = bigInt(0x00000000ffffffff);
18
+ const MIN_IOU_EXPONENT = -96;
19
+ const MAX_IOU_EXPONENT = 80;
20
+ const MAX_IOU_PRECISION = 16;
21
+ const MAX_DROPS = new bignumber_js_1.default('1e17');
22
+ const MIN_XRP = new bignumber_js_1.default('1e-6');
23
+ const mask = BigInt(0x00000000ffffffff);
24
+ const mptMask = BigInt(0x8000000000000000);
33
25
  /**
34
- * decimal.js configuration for Amount IOUs
26
+ * BigNumber configuration for Amount IOUs
35
27
  */
36
- decimal_js_1.Decimal.config({
37
- toExpPos: MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
38
- toExpNeg: MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
28
+ bignumber_js_1.default.config({
29
+ EXPONENTIAL_AT: [
30
+ MIN_IOU_EXPONENT - MAX_IOU_PRECISION,
31
+ MAX_IOU_EXPONENT + MAX_IOU_PRECISION,
32
+ ],
39
33
  });
40
34
  /**
41
- * Type guard for AmountObject
35
+ * Type guard for AmountObjectIOU
42
36
  */
43
- function isAmountObject(arg) {
44
- var keys = Object.keys(arg).sort();
37
+ function isAmountObjectIOU(arg) {
38
+ const keys = Object.keys(arg).sort();
45
39
  return (keys.length === 3 &&
46
- keys[0] === "currency" &&
47
- keys[1] === "issuer" &&
48
- keys[2] === "value");
40
+ keys[0] === 'currency' &&
41
+ keys[1] === 'issuer' &&
42
+ keys[2] === 'value');
43
+ }
44
+ /**
45
+ * Type guard for AmountObjectMPT
46
+ */
47
+ function isAmountObjectMPT(arg) {
48
+ const keys = Object.keys(arg).sort();
49
+ return (keys.length === 2 && keys[0] === 'mpt_issuance_id' && keys[1] === 'value');
49
50
  }
50
51
  /**
51
52
  * Class for serializing/Deserializing Amounts
52
53
  */
53
- var Amount = /** @class */ (function (_super) {
54
- __extends(Amount, _super);
55
- function Amount(bytes) {
56
- return _super.call(this, bytes !== null && bytes !== void 0 ? bytes : Amount.defaultAmount.bytes) || this;
54
+ class Amount extends serialized_type_1.SerializedType {
55
+ constructor(bytes) {
56
+ super(bytes !== null && bytes !== void 0 ? bytes : Amount.defaultAmount.bytes);
57
57
  }
58
58
  /**
59
- * Construct an amount from an IOU or string amount
59
+ * Construct an amount from an IOU, MPT or string amount
60
60
  *
61
61
  * @param value An Amount, object representing an IOU, or a string
62
62
  * representing an integer amount
63
63
  * @returns An Amount object
64
64
  */
65
- Amount.from = function (value) {
65
+ static from(value) {
66
66
  if (value instanceof Amount) {
67
67
  return value;
68
68
  }
69
- var amount = buffer_1.Buffer.alloc(8);
70
- if (typeof value === "string") {
69
+ let amount = new Uint8Array(8);
70
+ if (typeof value === 'string') {
71
71
  Amount.assertXrpIsValid(value);
72
- var number = bigInt(value);
73
- var intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
74
- intBuf[0].writeUInt32BE(Number(number.shiftRight(32)), 0);
75
- intBuf[1].writeUInt32BE(Number(number.and(mask)), 0);
76
- amount = buffer_1.Buffer.concat(intBuf);
72
+ const number = BigInt(value);
73
+ const intBuf = [new Uint8Array(4), new Uint8Array(4)];
74
+ (0, utils_2.writeUInt32BE)(intBuf[0], Number(number >> BigInt(32)), 0);
75
+ (0, utils_2.writeUInt32BE)(intBuf[1], Number(number & BigInt(mask)), 0);
76
+ amount = (0, utils_1.concat)(intBuf);
77
77
  amount[0] |= 0x40;
78
78
  return new Amount(amount);
79
79
  }
80
- if (isAmountObject(value)) {
81
- var number = new decimal_js_1.Decimal(value.value);
80
+ if (isAmountObjectIOU(value)) {
81
+ const number = new bignumber_js_1.default(value.value);
82
82
  Amount.assertIouIsValid(number);
83
83
  if (number.isZero()) {
84
84
  amount[0] |= 0x80;
85
85
  }
86
86
  else {
87
- var integerNumberString = number
88
- .times("1e" + -(number.e - 15))
87
+ const integerNumberString = number
88
+ .times(`1e${-((number.e || 0) - 15)}`)
89
89
  .abs()
90
90
  .toString();
91
- var num = bigInt(integerNumberString);
92
- var intBuf = [buffer_1.Buffer.alloc(4), buffer_1.Buffer.alloc(4)];
93
- intBuf[0].writeUInt32BE(Number(num.shiftRight(32)), 0);
94
- intBuf[1].writeUInt32BE(Number(num.and(mask)), 0);
95
- amount = buffer_1.Buffer.concat(intBuf);
91
+ const num = BigInt(integerNumberString);
92
+ const intBuf = [new Uint8Array(4), new Uint8Array(4)];
93
+ (0, utils_2.writeUInt32BE)(intBuf[0], Number(num >> BigInt(32)), 0);
94
+ (0, utils_2.writeUInt32BE)(intBuf[1], Number(num & BigInt(mask)), 0);
95
+ amount = (0, utils_1.concat)(intBuf);
96
96
  amount[0] |= 0x80;
97
- if (number.gt(new decimal_js_1.Decimal(0))) {
97
+ if (number.gt(new bignumber_js_1.default(0))) {
98
98
  amount[0] |= 0x40;
99
99
  }
100
- var exponent = number.e - 15;
101
- var exponentByte = 97 + exponent;
100
+ const exponent = (number.e || 0) - 15;
101
+ const exponentByte = 97 + exponent;
102
102
  amount[0] |= exponentByte >>> 2;
103
103
  amount[1] |= (exponentByte & 0x03) << 6;
104
104
  }
105
- var currency = currency_1.Currency.from(value.currency).toBytes();
106
- var issuer = account_id_1.AccountID.from(value.issuer).toBytes();
107
- return new Amount(buffer_1.Buffer.concat([amount, currency, issuer]));
105
+ const currency = currency_1.Currency.from(value.currency).toBytes();
106
+ const issuer = account_id_1.AccountID.from(value.issuer).toBytes();
107
+ return new Amount((0, utils_1.concat)([amount, currency, issuer]));
108
108
  }
109
- throw new Error("Invalid type to construct an Amount");
110
- };
109
+ if (isAmountObjectMPT(value)) {
110
+ Amount.assertMptIsValid(value.value);
111
+ let leadingByte = new Uint8Array(1);
112
+ leadingByte[0] |= 0x60;
113
+ const num = BigInt(value.value);
114
+ const intBuf = [new Uint8Array(4), new Uint8Array(4)];
115
+ (0, utils_2.writeUInt32BE)(intBuf[0], Number(num >> BigInt(32)), 0);
116
+ (0, utils_2.writeUInt32BE)(intBuf[1], Number(num & BigInt(mask)), 0);
117
+ amount = (0, utils_1.concat)(intBuf);
118
+ const mptIssuanceID = hash_192_1.Hash192.from(value.mpt_issuance_id).toBytes();
119
+ return new Amount((0, utils_1.concat)([leadingByte, amount, mptIssuanceID]));
120
+ }
121
+ throw new Error('Invalid type to construct an Amount');
122
+ }
111
123
  /**
112
124
  * Read an amount from a BinaryParser
113
125
  *
114
126
  * @param parser BinaryParser to read the Amount from
115
127
  * @returns An Amount object
116
128
  */
117
- Amount.fromParser = function (parser) {
118
- var isXRP = parser.peek() & 0x80;
119
- var numBytes = isXRP ? 48 : 8;
129
+ static fromParser(parser) {
130
+ const isIOU = parser.peek() & 0x80;
131
+ if (isIOU)
132
+ return new Amount(parser.read(48));
133
+ // the amount can be either MPT or XRP at this point
134
+ const isMPT = parser.peek() & 0x20;
135
+ const numBytes = isMPT ? 33 : 8;
120
136
  return new Amount(parser.read(numBytes));
121
- };
137
+ }
122
138
  /**
123
139
  * Get the JSON representation of this Amount
124
140
  *
125
141
  * @returns the JSON interpretation of this.bytes
126
142
  */
127
- Amount.prototype.toJSON = function () {
143
+ toJSON() {
128
144
  if (this.isNative()) {
129
- var bytes = this.bytes;
130
- var isPositive = bytes[0] & 0x40;
131
- var sign = isPositive ? "" : "-";
145
+ const bytes = this.bytes;
146
+ const isPositive = bytes[0] & 0x40;
147
+ const sign = isPositive ? '' : '-';
132
148
  bytes[0] &= 0x3f;
133
- var msb = bigInt(bytes.slice(0, 4).readUInt32BE(0));
134
- var lsb = bigInt(bytes.slice(4).readUInt32BE(0));
135
- var num = msb.shiftLeft(32).or(lsb);
136
- return "" + sign + num.toString();
149
+ const msb = BigInt((0, utils_2.readUInt32BE)(bytes.slice(0, 4), 0));
150
+ const lsb = BigInt((0, utils_2.readUInt32BE)(bytes.slice(4), 0));
151
+ const num = (msb << BigInt(32)) | lsb;
152
+ return `${sign}${num.toString()}`;
137
153
  }
138
- else {
139
- var parser = new binary_parser_1.BinaryParser(this.toString());
140
- var mantissa = parser.read(8);
141
- var currency = currency_1.Currency.fromParser(parser);
142
- var issuer = account_id_1.AccountID.fromParser(parser);
143
- var b1 = mantissa[0];
144
- var b2 = mantissa[1];
145
- var isPositive = b1 & 0x40;
146
- var sign = isPositive ? "" : "-";
147
- var exponent = ((b1 & 0x3f) << 2) + ((b2 & 0xff) >> 6) - 97;
154
+ if (this.isIOU()) {
155
+ const parser = new binary_parser_1.BinaryParser(this.toString());
156
+ const mantissa = parser.read(8);
157
+ const currency = currency_1.Currency.fromParser(parser);
158
+ const issuer = account_id_1.AccountID.fromParser(parser);
159
+ const b1 = mantissa[0];
160
+ const b2 = mantissa[1];
161
+ const isPositive = b1 & 0x40;
162
+ const sign = isPositive ? '' : '-';
163
+ const exponent = ((b1 & 0x3f) << 2) + ((b2 & 0xff) >> 6) - 97;
148
164
  mantissa[0] = 0;
149
165
  mantissa[1] &= 0x3f;
150
- var value = new decimal_js_1.Decimal(sign + "0x" + mantissa.toString("hex")).times("1e" + exponent);
166
+ const value = new bignumber_js_1.default(`${sign}0x${(0, utils_1.bytesToHex)(mantissa)}`).times(`1e${exponent}`);
151
167
  Amount.assertIouIsValid(value);
152
168
  return {
153
169
  value: value.toString(),
@@ -155,42 +171,78 @@ var Amount = /** @class */ (function (_super) {
155
171
  issuer: issuer.toJSON(),
156
172
  };
157
173
  }
158
- };
174
+ if (this.isMPT()) {
175
+ const parser = new binary_parser_1.BinaryParser(this.toString());
176
+ const leadingByte = parser.read(1);
177
+ const amount = parser.read(8);
178
+ const mptID = hash_192_1.Hash192.fromParser(parser);
179
+ const isPositive = leadingByte[0] & 0x40;
180
+ const sign = isPositive ? '' : '-';
181
+ const msb = BigInt((0, utils_2.readUInt32BE)(amount.slice(0, 4), 0));
182
+ const lsb = BigInt((0, utils_2.readUInt32BE)(amount.slice(4), 0));
183
+ const num = (msb << BigInt(32)) | lsb;
184
+ return {
185
+ value: `${sign}${num.toString()}`,
186
+ mpt_issuance_id: mptID.toString(),
187
+ };
188
+ }
189
+ throw new Error('Invalid amount to construct JSON');
190
+ }
159
191
  /**
160
192
  * Validate XRP amount
161
193
  *
162
194
  * @param amount String representing XRP amount
163
195
  * @returns void, but will throw if invalid amount
164
196
  */
165
- Amount.assertXrpIsValid = function (amount) {
166
- if (amount.indexOf(".") !== -1) {
167
- throw new Error(amount.toString() + " is an illegal amount");
197
+ static assertXrpIsValid(amount) {
198
+ if (amount.indexOf('.') !== -1) {
199
+ throw new Error(`${amount.toString()} is an illegal amount`);
168
200
  }
169
- var decimal = new decimal_js_1.Decimal(amount);
201
+ const decimal = new bignumber_js_1.default(amount);
170
202
  if (!decimal.isZero()) {
171
203
  if (decimal.lt(MIN_XRP) || decimal.gt(MAX_DROPS)) {
172
- throw new Error(amount.toString() + " is an illegal amount");
204
+ throw new Error(`${amount.toString()} is an illegal amount`);
173
205
  }
174
206
  }
175
- };
207
+ }
176
208
  /**
177
209
  * Validate IOU.value amount
178
210
  *
179
- * @param decimal Decimal.js object representing IOU.value
211
+ * @param decimal BigNumber object representing IOU.value
180
212
  * @returns void, but will throw if invalid amount
181
213
  */
182
- Amount.assertIouIsValid = function (decimal) {
214
+ static assertIouIsValid(decimal) {
183
215
  if (!decimal.isZero()) {
184
- var p = decimal.precision();
185
- var e = decimal.e - 15;
216
+ const p = decimal.precision();
217
+ const e = (decimal.e || 0) - 15;
186
218
  if (p > MAX_IOU_PRECISION ||
187
219
  e > MAX_IOU_EXPONENT ||
188
220
  e < MIN_IOU_EXPONENT) {
189
- throw new Error("Decimal precision out of range");
221
+ throw new Error('Decimal precision out of range');
190
222
  }
191
223
  this.verifyNoDecimal(decimal);
192
224
  }
193
- };
225
+ }
226
+ /**
227
+ * Validate MPT.value amount
228
+ *
229
+ * @param decimal BigNumber object representing MPT.value
230
+ * @returns void, but will throw if invalid amount
231
+ */
232
+ static assertMptIsValid(amount) {
233
+ if (amount.indexOf('.') !== -1) {
234
+ throw new Error(`${amount.toString()} is an illegal amount`);
235
+ }
236
+ const decimal = new bignumber_js_1.default(amount);
237
+ if (!decimal.isZero()) {
238
+ if (decimal < (0, bignumber_js_1.default)(0)) {
239
+ throw new Error(`${amount.toString()} is an illegal amount`);
240
+ }
241
+ if (Number(BigInt(amount) & BigInt(mptMask)) != 0) {
242
+ throw new Error(`${amount.toString()} is an illegal amount`);
243
+ }
244
+ }
245
+ }
194
246
  /**
195
247
  * Ensure that the value after being multiplied by the exponent does not
196
248
  * contain a decimal.
@@ -198,25 +250,40 @@ var Amount = /** @class */ (function (_super) {
198
250
  * @param decimal a Decimal object
199
251
  * @returns a string of the object without a decimal
200
252
  */
201
- Amount.verifyNoDecimal = function (decimal) {
202
- var integerNumberString = decimal
203
- .times("1e" + -(decimal.e - 15))
253
+ static verifyNoDecimal(decimal) {
254
+ const integerNumberString = decimal
255
+ .times(`1e${-((decimal.e || 0) - 15)}`)
204
256
  .abs()
205
257
  .toString();
206
- if (integerNumberString.indexOf(".") !== -1) {
207
- throw new Error("Decimal place found in integerNumberString");
258
+ if (integerNumberString.indexOf('.') !== -1) {
259
+ throw new Error('Decimal place found in integerNumberString');
208
260
  }
209
- };
261
+ }
210
262
  /**
211
263
  * Test if this amount is in units of Native Currency(XRP)
212
264
  *
213
265
  * @returns true if Native (XRP)
214
266
  */
215
- Amount.prototype.isNative = function () {
216
- return (this.bytes[0] & 0x80) === 0;
217
- };
218
- Amount.defaultAmount = new Amount(buffer_1.Buffer.from("4000000000000000", "hex"));
219
- return Amount;
220
- }(serialized_type_1.SerializedType));
267
+ isNative() {
268
+ return (this.bytes[0] & 0x80) === 0 && (this.bytes[0] & 0x20) === 0;
269
+ }
270
+ /**
271
+ * Test if this amount is in units of MPT
272
+ *
273
+ * @returns true if MPT
274
+ */
275
+ isMPT() {
276
+ return (this.bytes[0] & 0x80) === 0 && (this.bytes[0] & 0x20) !== 0;
277
+ }
278
+ /**
279
+ * Test if this amount is in units of IOU
280
+ *
281
+ * @returns true if IOU
282
+ */
283
+ isIOU() {
284
+ return (this.bytes[0] & 0x80) !== 0;
285
+ }
286
+ }
221
287
  exports.Amount = Amount;
288
+ Amount.defaultAmount = new Amount((0, utils_1.hexToBytes)('4000000000000000'));
222
289
  //# sourceMappingURL=amount.js.map