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
package/HISTORY.md DELETED
@@ -1,74 +0,0 @@
1
- # ripple-binary-codec Release History
2
-
3
- ## 1.0.2 (2020-09-11)
4
- - Allow currencies to be encoded from any 3 character ASCII code.
5
-
6
- ## 1.0.1 (2020-09-08)
7
- - Filter out fields with undefined values
8
-
9
- ## 1.0.0 (2020-08-17)
10
-
11
- - Migrate to TypeScript
12
- - Javascript classes used
13
- - Generics for constructing core types
14
- - Reduced dependencies
15
- - Dependent on create-hash, decimal.js, ripple-address-codec
16
- - Migrate testing to Jest and added tests
17
- - Tests for pseudo-transactions
18
- - Added support for NegativeUNL pseudo-transactions
19
-
20
- ## 0.2.6 (2019-12-31)
21
-
22
- - Update dependencies
23
- - decimal.js, fs-extra, mocha, handlebars, bn.js, babel-eslint, ripple-address-codec
24
-
25
- ## 0.2.5 (2019-12-14)
26
-
27
- - Add support for AccountDelete (#37)
28
-
29
- ## 0.2.4 (2019-09-04)
30
-
31
- - Update ripple-address-codec to 3.0.4
32
-
33
- ## 0.2.3 (2019-08-29)
34
-
35
- - Expand node version compatibility (#32, #33)
36
-
37
- ## 0.2.2 (2019-07-26)
38
-
39
- - Input validation - Amount and Fee should not allow fractional XRP drops ([#31](https://github.com/ripple/ripple-binary-codec/issues/31))
40
- - Fix lint errors
41
- - Update dependencies (including lodash and mocha)
42
- - Require node 10 (.nvmrc)
43
- - Remove assert-diff
44
- - Remove codecov.io as it did not appear to work. The `package.json` script was:
45
- - `"codecov": "cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"`
46
-
47
- ## 0.2.1
48
-
49
- - Add tecKILLED from amendment fix1578 (PR #27 fixes #25)
50
-
51
- ## 0.2.0
52
-
53
- - Add DepositPreauth fields
54
- - https://developers.ripple.com/depositauth.html
55
-
56
- ## 0.1.14
57
-
58
- - Skip amount validation when deserializing f72c115
59
-
60
- ## 0.1.13
61
-
62
- - Add Check, CheckCreate, CheckCash, CheckCancel
63
-
64
- ## 0.1.11
65
-
66
- - Add ledger header decode function
67
-
68
- ## 0.1.8
69
-
70
- ## 0.1.7
71
-
72
- ## 0.1.6
73
-
74
- ## 0.1.3
@@ -1,17 +0,0 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*!
9
- * The buffer module from node.js, for the browser.
10
- *
11
- * @author Feross Aboukhadijeh <https://feross.org>
12
- * @license MIT
13
- */
14
-
15
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
16
-
17
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -1,43 +0,0 @@
1
- const { loadFixture } = require("./utils");
2
- const { coreTypes } = require("../dist/types");
3
- const { Amount } = coreTypes;
4
- const fixtures = loadFixture("data-driven-tests.json");
5
-
6
- function amountErrorTests() {
7
- fixtures.values_tests
8
- .filter((obj) => obj.type === "Amount")
9
- .forEach((f) => {
10
- // We only want these with errors
11
- if (!f.error) {
12
- return;
13
- }
14
- const testName =
15
- `${JSON.stringify(f.test_json)}\n\tis invalid ` + `because: ${f.error}`;
16
- it(testName, () => {
17
- expect(() => {
18
- Amount.from(f.test_json);
19
- JSON.stringify(f.test_json);
20
- }).toThrow();
21
- });
22
- });
23
- }
24
-
25
- describe("Amount", function () {
26
- it("can be parsed from", function () {
27
- expect(Amount.from("1000000") instanceof Amount).toBe(true);
28
- expect(Amount.from("1000000").toJSON()).toEqual("1000000");
29
- const fixture = {
30
- value: "1",
31
- issuer: "0000000000000000000000000000000000000000",
32
- currency: "USD",
33
- };
34
- const amt = Amount.from(fixture);
35
- const rewritten = {
36
- value: "1",
37
- issuer: "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
38
- currency: "USD",
39
- };
40
- expect(amt.toJSON()).toEqual(rewritten);
41
- });
42
- amountErrorTests();
43
- });
@@ -1,47 +0,0 @@
1
- const fixtures = require("./fixtures/codec-fixtures.json");
2
- const { decode, encode, decodeLedgerData } = require("../dist");
3
-
4
- function json(object) {
5
- return JSON.stringify(object);
6
- }
7
-
8
- function truncateForDisplay(longStr) {
9
- return `${longStr.slice(0, 10)} ... ${longStr.slice(-10)}`;
10
- }
11
-
12
- describe("ripple-binary-codec", function () {
13
- function makeSuite(name, entries) {
14
- describe(name, function () {
15
- entries.forEach((t, testN) => {
16
- // eslint-disable-next-line max-len
17
- test(`${name}[${testN}] can encode ${truncateForDisplay(
18
- json(t.json)
19
- )} to ${truncateForDisplay(t.binary)}`, () => {
20
- expect(encode(t.json)).toEqual(t.binary);
21
- });
22
- // eslint-disable-next-line max-len
23
- test(`${name}[${testN}] can decode ${truncateForDisplay(
24
- t.binary
25
- )} to ${truncateForDisplay(json(t.json))}`, () => {
26
- const decoded = decode(t.binary);
27
- expect(decoded).toEqual(t.json);
28
- });
29
- });
30
- });
31
- }
32
- makeSuite("transactions", fixtures.transactions);
33
- makeSuite("accountState", fixtures.accountState);
34
-
35
- describe("ledgerData", function () {
36
- if (fixtures.ledgerData) {
37
- fixtures.ledgerData.forEach((t, testN) => {
38
- test(`ledgerData[${testN}] can decode ${t.binary} to ${json(
39
- t.json
40
- )}`, () => {
41
- const decoded = decodeLedgerData(t.binary);
42
- expect(t.json).toEqual(decoded);
43
- });
44
- });
45
- }
46
- });
47
- });
@@ -1,398 +0,0 @@
1
- /* eslint-disable func-style */
2
-
3
- const { coreTypes } = require("../dist/types");
4
- const Decimal = require("decimal.js");
5
-
6
- const { encodeAccountID } = require("ripple-address-codec");
7
- const { binary } = require("../dist/coretypes");
8
- const { Amount, Hash160 } = coreTypes;
9
- const { makeParser, readJSON } = binary;
10
- const { Field, TransactionType } = require("./../dist/enums");
11
- const { parseHexOnly, hexOnly, loadFixture } = require("./utils");
12
- const fixtures = loadFixture("data-driven-tests.json");
13
- const { BytesList } = require("../dist/serdes/binary-serializer");
14
- const { Buffer } = require("buffer/");
15
-
16
- const __ = hexOnly;
17
- function toJSON(v) {
18
- return v.toJSON ? v.toJSON() : v;
19
- }
20
-
21
- function assertEqualAmountJSON(actual, expected) {
22
- expect(typeof actual === typeof expected).toBe(true);
23
- if (typeof actual === "string") {
24
- expect(actual).toEqual(expected);
25
- return;
26
- }
27
- expect(actual.currency).toEqual(expected.currency);
28
- expect(actual.issuer).toEqual(expected.issuer);
29
- expect(
30
- actual.value === expected.value ||
31
- new Decimal(actual.value).equals(new Decimal(expected.value))
32
- ).toBe(true);
33
- }
34
-
35
- function basicApiTests() {
36
- const bytes = parseHexOnly("00,01020304,0506", Uint8Array);
37
- test("can read slices of bytes", () => {
38
- const parser = makeParser(bytes);
39
- expect(parser.bytes instanceof Buffer).toBe(true);
40
- const read1 = parser.read(1);
41
- expect(read1 instanceof Buffer).toBe(true);
42
- expect(read1).toEqual(Buffer.from([0]));
43
- expect(parser.read(4)).toEqual(Buffer.from([1, 2, 3, 4]));
44
- expect(parser.read(2)).toEqual(Buffer.from([5, 6]));
45
- expect(() => parser.read(1)).toThrow();
46
- });
47
- test("can read a Uint32 at full", () => {
48
- const parser = makeParser("FFFFFFFF");
49
- expect(parser.readUInt32()).toEqual(0xffffffff);
50
- });
51
- }
52
-
53
- function transactionParsingTests() {
54
- const transaction = {
55
- json: {
56
- Account: "raD5qJMAShLeHZXf9wjUmo6vRK4arj9cF3",
57
- Fee: "10",
58
- Flags: 0,
59
- Sequence: 103929,
60
- SigningPubKey:
61
- "028472865AF4CB32AA285834B57576B7290AA8C31B459047DB27E16F418D6A7166",
62
- TakerGets: {
63
- currency: "ILS",
64
- issuer: "rNPRNzBB92BVpAhhZr4iXDTveCgV5Pofm9",
65
- value: "1694.768",
66
- },
67
- TakerPays: "98957503520",
68
- TransactionType: "OfferCreate",
69
- TxnSignature: __(`
70
- 304502202ABE08D5E78D1E74A4C18F2714F64E87B8BD57444AF
71
- A5733109EB3C077077520022100DB335EE97386E4C0591CAC02
72
- 4D50E9230D8F171EEB901B5E5E4BD6D1E0AEF98C`),
73
- },
74
- binary: __(`
75
- 120007220000000024000195F964400000170A53AC2065D5460561E
76
- C9DE000000000000000000000000000494C53000000000092D70596
77
- 8936C419CE614BF264B5EEB1CEA47FF468400000000000000A73210
78
- 28472865AF4CB32AA285834B57576B7290AA8C31B459047DB27E16F
79
- 418D6A71667447304502202ABE08D5E78D1E74A4C18F2714F64E87B
80
- 8BD57444AFA5733109EB3C077077520022100DB335EE97386E4C059
81
- 1CAC024D50E9230D8F171EEB901B5E5E4BD6D1E0AEF98C811439408
82
- A69F0895E62149CFCC006FB89FA7D1E6E5D`),
83
- };
84
-
85
- const tx_json = transaction.json;
86
- // These tests are basically development logs
87
-
88
- test("can be done with low level apis", () => {
89
- const parser = makeParser(transaction.binary);
90
-
91
- expect(parser.readField()).toEqual(Field.TransactionType);
92
- expect(parser.readUInt16()).toEqual(7);
93
- expect(parser.readField()).toEqual(Field.Flags);
94
- expect(parser.readUInt32()).toEqual(0);
95
- expect(parser.readField()).toEqual(Field.Sequence);
96
- expect(parser.readUInt32()).toEqual(103929);
97
- expect(parser.readField()).toEqual(Field.TakerPays);
98
- parser.read(8);
99
- expect(parser.readField()).toEqual(Field.TakerGets);
100
- // amount value
101
- expect(parser.read(8)).not.toBe([]);
102
- // amount currency
103
- expect(Hash160.fromParser(parser)).not.toBe([]);
104
- expect(encodeAccountID(parser.read(20))).toEqual(tx_json.TakerGets.issuer);
105
- expect(parser.readField()).toEqual(Field.Fee);
106
- expect(parser.read(8)).not.toEqual([]);
107
- expect(parser.readField()).toEqual(Field.SigningPubKey);
108
- expect(parser.readVariableLengthLength()).toBe(33);
109
- expect(parser.read(33).toString("hex").toUpperCase()).toEqual(
110
- tx_json.SigningPubKey
111
- );
112
- expect(parser.readField()).toEqual(Field.TxnSignature);
113
- expect(parser.readVariableLength().toString("hex").toUpperCase()).toEqual(
114
- tx_json.TxnSignature
115
- );
116
- expect(parser.readField()).toEqual(Field.Account);
117
- expect(encodeAccountID(parser.readVariableLength())).toEqual(
118
- tx_json.Account
119
- );
120
- expect(parser.end()).toBe(true);
121
- });
122
-
123
- test("can be done with high level apis", () => {
124
- const parser = makeParser(transaction.binary);
125
- function readField() {
126
- return parser.readFieldAndValue();
127
- }
128
- {
129
- const [field, value] = readField();
130
- expect(field).toEqual(Field.TransactionType);
131
- expect(value).toEqual(TransactionType.OfferCreate);
132
- }
133
- {
134
- const [field, value] = readField();
135
- expect(field).toEqual(Field.Flags);
136
- expect(value.valueOf()).toEqual(0);
137
- }
138
- {
139
- const [field, value] = readField();
140
- expect(field).toEqual(Field.Sequence);
141
- expect(value.valueOf()).toEqual(103929);
142
- }
143
- {
144
- const [field, value] = readField();
145
- expect(field).toEqual(Field.TakerPays);
146
- expect(value.isNative()).toEqual(true);
147
- expect(value.toJSON()).toEqual("98957503520");
148
- }
149
- {
150
- const [field, value] = readField();
151
- expect(field).toEqual(Field.TakerGets);
152
- expect(value.isNative()).toEqual(false);
153
- expect(value.toJSON().issuer).toEqual(tx_json.TakerGets.issuer);
154
- }
155
- {
156
- const [field, value] = readField();
157
- expect(field).toEqual(Field.Fee);
158
- expect(value.isNative()).toEqual(true);
159
- }
160
- {
161
- const [field, value] = readField();
162
- expect(field).toEqual(Field.SigningPubKey);
163
- expect(value.toJSON()).toEqual(tx_json.SigningPubKey);
164
- }
165
- {
166
- const [field, value] = readField();
167
- expect(field).toEqual(Field.TxnSignature);
168
- expect(value.toJSON()).toEqual(tx_json.TxnSignature);
169
- }
170
- {
171
- const [field, value] = readField();
172
- expect(field).toEqual(Field.Account);
173
- expect(value.toJSON()).toEqual(tx_json.Account);
174
- }
175
- expect(parser.end()).toBe(true);
176
- });
177
-
178
- test("can be done with higher level apis", () => {
179
- const parser = makeParser(transaction.binary);
180
- const jsonFromBinary = readJSON(parser);
181
- expect(jsonFromBinary).toEqual(tx_json);
182
- });
183
-
184
- test("readJSON (binary.decode) does not return STObject ", () => {
185
- const parser = makeParser(transaction.binary);
186
- const jsonFromBinary = readJSON(parser);
187
- expect(jsonFromBinary instanceof coreTypes.STObject).toBe(false);
188
- expect(jsonFromBinary instanceof Object).toBe(true);
189
- expect(jsonFromBinary.prototype).toBe(undefined);
190
- });
191
- }
192
-
193
- function amountParsingTests() {
194
- fixtures.values_tests
195
- .filter((obj) => obj.type === "Amount")
196
- .forEach((f, i) => {
197
- if (f.error) {
198
- return;
199
- }
200
- const parser = makeParser(f.expected_hex);
201
- const testName = `values_tests[${i}] parses ${f.expected_hex.slice(
202
- 0,
203
- 16
204
- )}...
205
- as ${JSON.stringify(f.test_json)}`;
206
- test(testName, () => {
207
- const value = parser.readType(Amount);
208
- // May not actually be in canonical form. The fixtures are to be used
209
- // also for json -> binary;
210
- const json = toJSON(value);
211
- assertEqualAmountJSON(json, f.test_json);
212
- if (f.exponent) {
213
- const exponent = new Decimal(json.value);
214
- expect(exponent.e - 15).toEqual(f.exponent);
215
- }
216
- });
217
- });
218
- }
219
-
220
- function fieldParsingTests() {
221
- fixtures.fields_tests.forEach((f, i) => {
222
- const parser = makeParser(f.expected_hex);
223
- test(`fields[${i}]: parses ${f.expected_hex} as ${f.name}`, () => {
224
- const field = parser.readField();
225
- expect(field.name).toEqual(f.name);
226
- expect(field.type.name).toEqual(f.type_name);
227
- });
228
- });
229
- test("Field throws when type code out of range", () => {
230
- const parser = makeParser("0101");
231
- expect(() => parser.readField()).toThrow(
232
- new Error("Cannot read FieldOrdinal, type_code out of range")
233
- );
234
- });
235
- test("Field throws when field code out of range", () => {
236
- const parser = makeParser("1001");
237
- expect(() => parser.readFieldOrdinal()).toThrowError(
238
- new Error("Cannot read FieldOrdinal, field_code out of range")
239
- );
240
- });
241
- test("Field throws when both type and field code out of range", () => {
242
- const parser = makeParser("000101");
243
- expect(() => parser.readFieldOrdinal()).toThrowError(
244
- new Error("Cannot read FieldOrdinal, type_code out of range")
245
- );
246
- });
247
- }
248
-
249
- function assertRecyclable(json, forField) {
250
- const Type = forField.associatedType;
251
- const recycled = Type.from(json).toJSON();
252
- expect(recycled).toEqual(json);
253
- const sink = new BytesList();
254
- Type.from(recycled).toBytesSink(sink);
255
- const recycledAgain = makeParser(sink.toHex()).readType(Type).toJSON();
256
- expect(recycledAgain).toEqual(json);
257
- }
258
-
259
- function nestedObjectTests() {
260
- fixtures.whole_objects.forEach((f, i) => {
261
- test(`whole_objects[${i}]: can parse blob into
262
- ${JSON.stringify(
263
- f.tx_json
264
- )}`, /* */ () => {
265
- const parser = makeParser(f.blob_with_no_signing);
266
- let ix = 0;
267
- while (!parser.end()) {
268
- const [field, value] = parser.readFieldAndValue();
269
- const expected = f.fields[ix];
270
- const expectedJSON = expected[1].json;
271
- const expectedField = expected[0];
272
- const actual = toJSON(value);
273
-
274
- try {
275
- expect(actual).toEqual(expectedJSON);
276
- } catch (e) {
277
- throw new Error(`${e} ${field} a: ${actual} e: ${expectedJSON}`);
278
- }
279
- expect(field.name).toEqual(expectedField);
280
- assertRecyclable(actual, field);
281
- ix++;
282
- }
283
- });
284
- });
285
- }
286
-
287
- function pathSetBinaryTests() {
288
- const bytes = __(
289
- `1200002200000000240000002E2E00004BF161D4C71AFD498D00000000000000
290
- 0000000000000055534400000000000A20B3C85F482532A9578DBB3950B85CA0
291
- 6594D168400000000000000A69D446F8038585E9400000000000000000000000
292
- 00425443000000000078CA21A6014541AB7B26C3929B9E0CD8C284D61C732103
293
- A4665B1F0B7AE2BCA12E2DB80A192125BBEA660F80E9CEE137BA444C1B0769EC
294
- 7447304502205A964536805E35785C659D1F9670D057749AE39668175D6AA75D
295
- 25B218FE682E0221009252C0E5DDD5F2712A48F211669DE17B54113918E0D2C2
296
- 66F818095E9339D7D3811478CA21A6014541AB7B26C3929B9E0CD8C284D61C83
297
- 140A20B3C85F482532A9578DBB3950B85CA06594D1011231585E1F3BD02A15D6
298
- 185F8BB9B57CC60DEDDB37C10000000000000000000000004254430000000000
299
- 585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D694C
300
- 8531CDEECBE84F33670000000000000000000000004254430000000000E4FE68
301
- 7C90257D3D2D694C8531CDEECBE84F3367310A20B3C85F482532A9578DBB3950
302
- B85CA06594D100000000000000000000000042544300000000000A20B3C85F48
303
- 2532A9578DBB3950B85CA06594D1300000000000000000000000005553440000
304
- 0000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A15
305
- D6185F8BB9B57CC60DEDDB37C100000000000000000000000042544300000000
306
- 00585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C131E4FE687C90257D3D2D69
307
- 4C8531CDEECBE84F33670000000000000000000000004254430000000000E4FE
308
- 687C90257D3D2D694C8531CDEECBE84F33673115036E2D3F5437A83E5AC3CAEE
309
- 34FF2C21DEB618000000000000000000000000425443000000000015036E2D3F
310
- 5437A83E5AC3CAEE34FF2C21DEB6183000000000000000000000000055534400
311
- 000000000A20B3C85F482532A9578DBB3950B85CA06594D1FF31585E1F3BD02A
312
- 15D6185F8BB9B57CC60DEDDB37C1000000000000000000000000425443000000
313
- 0000585E1F3BD02A15D6185F8BB9B57CC60DEDDB37C13157180C769B66D942EE
314
- 69E6DCC940CA48D82337AD000000000000000000000000425443000000000057
315
- 180C769B66D942EE69E6DCC940CA48D82337AD10000000000000000000000000
316
- 58525000000000003000000000000000000000000055534400000000000A20B3
317
- C85F482532A9578DBB3950B85CA06594D100`
318
- );
319
-
320
- const expectedJSON = [
321
- [
322
- {
323
- account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
324
- currency: "BTC",
325
- issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
326
- },
327
- {
328
- account: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
329
- currency: "BTC",
330
- issuer: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
331
- },
332
- {
333
- account: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
334
- currency: "BTC",
335
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
336
- },
337
- {
338
- currency: "USD",
339
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
340
- },
341
- ],
342
- [
343
- {
344
- account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
345
- currency: "BTC",
346
- issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
347
- },
348
- {
349
- account: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
350
- currency: "BTC",
351
- issuer: "rM1oqKtfh1zgjdAgbFmaRm3btfGBX25xVo",
352
- },
353
- {
354
- account: "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi",
355
- currency: "BTC",
356
- issuer: "rpvfJ4mR6QQAeogpXEKnuyGBx8mYCSnYZi",
357
- },
358
- {
359
- currency: "USD",
360
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
361
- },
362
- ],
363
- [
364
- {
365
- account: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
366
- currency: "BTC",
367
- issuer: "r9hEDb4xBGRfBCcX3E4FirDWQBAYtpxC8K",
368
- },
369
- {
370
- account: "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn",
371
- currency: "BTC",
372
- issuer: "r3AWbdp2jQLXLywJypdoNwVSvr81xs3uhn",
373
- },
374
- { currency: "0000000000000000000000005852500000000000" },
375
- {
376
- currency: "USD",
377
- issuer: "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
378
- },
379
- ],
380
- ];
381
-
382
- test("works with long paths", () => {
383
- const parser = makeParser(bytes);
384
- const txn = readJSON(parser);
385
- expect(txn.Paths).toEqual(expectedJSON);
386
- // TODO: this should go elsewhere
387
- expect(coreTypes.PathSet.from(txn.Paths).toJSON()).toEqual(expectedJSON);
388
- });
389
- }
390
-
391
- describe("Binary Parser", function () {
392
- describe("pathSetBinaryTests", () => pathSetBinaryTests());
393
- describe("nestedObjectTests", () => nestedObjectTests());
394
- describe("fieldParsingTests", () => fieldParsingTests());
395
- describe("amountParsingTests", () => amountParsingTests());
396
- describe("transactionParsingTests", () => transactionParsingTests());
397
- describe("basicApiTests", () => basicApiTests());
398
- });