ripple-binary-codec 0.2.7 → 1.0.0-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 (364) hide show
  1. package/README.md +104 -2
  2. package/dist/binary.d.ts +90 -0
  3. package/dist/binary.js +128 -0
  4. package/dist/binary.js.map +1 -0
  5. package/dist/coretypes.d.ts +9 -0
  6. package/dist/coretypes.js +48 -0
  7. package/dist/coretypes.js.map +1 -0
  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 +2956 -0
  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 -0
  19. package/dist/enums/index.js +31 -0
  20. package/dist/enums/index.js.map +1 -0
  21. package/{distrib/npm → dist/enums/src}/enums/definitions.json +1709 -438
  22. package/dist/enums/utils-renumber.d.ts +101 -0
  23. package/dist/enums/utils-renumber.js +127 -0
  24. package/dist/enums/utils-renumber.js.map +1 -0
  25. package/dist/enums/xrpl-definitions-base.d.ts +44 -0
  26. package/dist/enums/xrpl-definitions-base.js +59 -0
  27. package/dist/enums/xrpl-definitions-base.js.map +1 -0
  28. package/dist/enums/xrpl-definitions.d.ts +21 -0
  29. package/dist/enums/xrpl-definitions.js +29 -0
  30. package/dist/enums/xrpl-definitions.js.map +1 -0
  31. package/dist/hash-prefixes.d.ts +5 -0
  32. package/dist/hash-prefixes.js +41 -0
  33. package/dist/hash-prefixes.js.map +1 -0
  34. package/dist/hashes.d.ts +50 -0
  35. package/dist/hashes.js +76 -0
  36. package/dist/hashes.js.map +1 -0
  37. package/dist/index.d.ts +64 -0
  38. package/dist/index.js +123 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/ledger-hashes.d.ts +48 -0
  41. package/dist/ledger-hashes.js +141 -0
  42. package/dist/ledger-hashes.js.map +1 -0
  43. package/dist/quality.d.ts +21 -0
  44. package/dist/quality.js +42 -0
  45. package/dist/quality.js.map +1 -0
  46. package/dist/serdes/binary-parser.d.ts +100 -0
  47. package/dist/serdes/binary-parser.js +194 -0
  48. package/dist/serdes/binary-parser.js.map +1 -0
  49. package/dist/serdes/binary-serializer.d.ts +81 -0
  50. package/dist/serdes/binary-serializer.js +149 -0
  51. package/dist/serdes/binary-serializer.js.map +1 -0
  52. package/dist/shamap.d.ts +102 -0
  53. package/dist/shamap.js +172 -0
  54. package/dist/shamap.js.map +1 -0
  55. package/dist/src/binary.d.ts +90 -0
  56. package/dist/src/binary.js +128 -0
  57. package/dist/src/binary.js.map +1 -0
  58. package/dist/src/coretypes.d.ts +9 -0
  59. package/dist/src/coretypes.js +48 -0
  60. package/dist/src/coretypes.js.map +1 -0
  61. package/dist/src/enums/bytes.d.ts +25 -0
  62. package/dist/src/enums/bytes.js +63 -0
  63. package/dist/src/enums/bytes.js.map +1 -0
  64. package/dist/src/enums/constants.d.ts +4 -0
  65. package/dist/src/enums/constants.js +8 -0
  66. package/dist/src/enums/constants.js.map +1 -0
  67. package/dist/src/enums/definitions.json +2956 -0
  68. package/dist/src/enums/field.d.ts +28 -0
  69. package/dist/src/enums/field.js +58 -0
  70. package/dist/src/enums/field.js.map +1 -0
  71. package/dist/src/enums/index.d.ts +12 -0
  72. package/dist/src/enums/index.js +31 -0
  73. package/dist/src/enums/index.js.map +1 -0
  74. package/dist/src/enums/utils-renumber.d.ts +101 -0
  75. package/dist/src/enums/utils-renumber.js +127 -0
  76. package/dist/src/enums/utils-renumber.js.map +1 -0
  77. package/dist/src/enums/xrpl-definitions-base.d.ts +44 -0
  78. package/dist/src/enums/xrpl-definitions-base.js +59 -0
  79. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  80. package/dist/src/enums/xrpl-definitions.d.ts +21 -0
  81. package/dist/src/enums/xrpl-definitions.js +29 -0
  82. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  83. package/dist/src/hash-prefixes.d.ts +5 -0
  84. package/dist/src/hash-prefixes.js +41 -0
  85. package/dist/src/hash-prefixes.js.map +1 -0
  86. package/dist/src/hashes.d.ts +50 -0
  87. package/dist/src/hashes.js +76 -0
  88. package/dist/src/hashes.js.map +1 -0
  89. package/dist/src/index.d.ts +64 -0
  90. package/dist/src/index.js +123 -0
  91. package/dist/src/index.js.map +1 -0
  92. package/dist/src/ledger-hashes.d.ts +48 -0
  93. package/dist/src/ledger-hashes.js +141 -0
  94. package/dist/src/ledger-hashes.js.map +1 -0
  95. package/dist/src/quality.d.ts +21 -0
  96. package/dist/src/quality.js +42 -0
  97. package/dist/src/quality.js.map +1 -0
  98. package/dist/src/serdes/binary-parser.d.ts +100 -0
  99. package/dist/src/serdes/binary-parser.js +194 -0
  100. package/dist/src/serdes/binary-parser.js.map +1 -0
  101. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  102. package/dist/src/serdes/binary-serializer.js +149 -0
  103. package/dist/src/serdes/binary-serializer.js.map +1 -0
  104. package/dist/src/shamap.d.ts +102 -0
  105. package/dist/src/shamap.js +172 -0
  106. package/dist/src/shamap.js.map +1 -0
  107. package/dist/src/types/account-id.d.ts +35 -0
  108. package/dist/src/types/account-id.js +69 -0
  109. package/dist/src/types/account-id.js.map +1 -0
  110. package/dist/src/types/amount.d.ts +91 -0
  111. package/dist/src/types/amount.js +289 -0
  112. package/dist/src/types/amount.js.map +1 -0
  113. package/dist/src/types/blob.d.ts +24 -0
  114. package/dist/src/types/blob.js +40 -0
  115. package/dist/src/types/blob.js.map +1 -0
  116. package/dist/src/types/currency.d.ts +28 -0
  117. package/dist/src/types/currency.js +127 -0
  118. package/dist/src/types/currency.js.map +1 -0
  119. package/dist/src/types/hash-128.d.ts +16 -0
  120. package/dist/src/types/hash-128.js +32 -0
  121. package/dist/src/types/hash-128.js.map +1 -0
  122. package/dist/src/types/hash-160.d.ts +10 -0
  123. package/dist/src/types/hash-160.js +19 -0
  124. package/dist/src/types/hash-160.js.map +1 -0
  125. package/dist/src/types/hash-192.d.ts +10 -0
  126. package/dist/src/types/hash-192.js +19 -0
  127. package/dist/src/types/hash-192.js.map +1 -0
  128. package/dist/src/types/hash-256.d.ts +10 -0
  129. package/dist/src/types/hash-256.js +16 -0
  130. package/dist/src/types/hash-256.js.map +1 -0
  131. package/dist/src/types/hash.d.ts +40 -0
  132. package/dist/src/types/hash.js +73 -0
  133. package/dist/src/types/hash.js.map +1 -0
  134. package/dist/src/types/index.d.ts +19 -0
  135. package/dist/src/types/index.js +64 -0
  136. package/dist/src/types/index.js.map +1 -0
  137. package/dist/src/types/issue.d.ts +38 -0
  138. package/dist/src/types/issue.js +81 -0
  139. package/dist/src/types/issue.js.map +1 -0
  140. package/dist/src/types/path-set.d.ts +36 -0
  141. package/dist/src/types/path-set.js +233 -0
  142. package/dist/src/types/path-set.js.map +1 -0
  143. package/dist/src/types/serialized-type.d.ts +70 -0
  144. package/dist/src/types/serialized-type.js +105 -0
  145. package/dist/src/types/serialized-type.js.map +1 -0
  146. package/dist/src/types/st-array.d.ts +31 -0
  147. package/dist/src/types/st-array.js +83 -0
  148. package/dist/src/types/st-array.js.map +1 -0
  149. package/dist/src/types/st-object.d.ts +32 -0
  150. package/dist/src/types/st-object.js +155 -0
  151. package/dist/src/types/st-object.js.map +1 -0
  152. package/dist/src/types/uint-16.d.ts +24 -0
  153. package/dist/src/types/uint-16.js +45 -0
  154. package/dist/src/types/uint-16.js.map +1 -0
  155. package/dist/src/types/uint-32.d.ts +24 -0
  156. package/dist/src/types/uint-32.js +50 -0
  157. package/dist/src/types/uint-32.js.map +1 -0
  158. package/dist/src/types/uint-64.d.ts +37 -0
  159. package/dist/src/types/uint-64.js +86 -0
  160. package/dist/src/types/uint-64.js.map +1 -0
  161. package/dist/src/types/uint-8.d.ts +24 -0
  162. package/dist/src/types/uint-8.js +46 -0
  163. package/dist/src/types/uint-8.js.map +1 -0
  164. package/dist/src/types/uint.d.ts +29 -0
  165. package/dist/src/types/uint.js +47 -0
  166. package/dist/src/types/uint.js.map +1 -0
  167. package/dist/src/types/vector-256.d.ts +30 -0
  168. package/dist/src/types/vector-256.js +73 -0
  169. package/dist/src/types/vector-256.js.map +1 -0
  170. package/dist/src/types/xchain-bridge.d.ts +44 -0
  171. package/dist/src/types/xchain-bridge.js +102 -0
  172. package/dist/src/types/xchain-bridge.js.map +1 -0
  173. package/dist/src/utils.d.ts +47 -0
  174. package/dist/src/utils.js +137 -0
  175. package/dist/src/utils.js.map +1 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/dist/types/account-id.d.ts +35 -0
  178. package/dist/types/account-id.js +69 -0
  179. package/dist/types/account-id.js.map +1 -0
  180. package/dist/types/amount.d.ts +91 -0
  181. package/dist/types/amount.js +289 -0
  182. package/dist/types/amount.js.map +1 -0
  183. package/dist/types/blob.d.ts +24 -0
  184. package/dist/types/blob.js +40 -0
  185. package/dist/types/blob.js.map +1 -0
  186. package/dist/types/currency.d.ts +28 -0
  187. package/dist/types/currency.js +127 -0
  188. package/dist/types/currency.js.map +1 -0
  189. package/dist/types/hash-128.d.ts +16 -0
  190. package/dist/types/hash-128.js +32 -0
  191. package/dist/types/hash-128.js.map +1 -0
  192. package/dist/types/hash-160.d.ts +10 -0
  193. package/dist/types/hash-160.js +19 -0
  194. package/dist/types/hash-160.js.map +1 -0
  195. package/dist/types/hash-192.d.ts +10 -0
  196. package/dist/types/hash-192.js +19 -0
  197. package/dist/types/hash-192.js.map +1 -0
  198. package/dist/types/hash-256.d.ts +10 -0
  199. package/dist/types/hash-256.js +16 -0
  200. package/dist/types/hash-256.js.map +1 -0
  201. package/dist/types/hash.d.ts +40 -0
  202. package/dist/types/hash.js +73 -0
  203. package/dist/types/hash.js.map +1 -0
  204. package/dist/types/index.d.ts +19 -0
  205. package/dist/types/index.js +64 -0
  206. package/dist/types/index.js.map +1 -0
  207. package/dist/types/issue.d.ts +38 -0
  208. package/dist/types/issue.js +81 -0
  209. package/dist/types/issue.js.map +1 -0
  210. package/dist/types/path-set.d.ts +36 -0
  211. package/dist/types/path-set.js +233 -0
  212. package/dist/types/path-set.js.map +1 -0
  213. package/dist/types/serialized-type.d.ts +70 -0
  214. package/dist/types/serialized-type.js +105 -0
  215. package/dist/types/serialized-type.js.map +1 -0
  216. package/dist/types/st-array.d.ts +31 -0
  217. package/dist/types/st-array.js +83 -0
  218. package/dist/types/st-array.js.map +1 -0
  219. package/dist/types/st-object.d.ts +32 -0
  220. package/dist/types/st-object.js +155 -0
  221. package/dist/types/st-object.js.map +1 -0
  222. package/dist/types/uint-16.d.ts +24 -0
  223. package/dist/types/uint-16.js +45 -0
  224. package/dist/types/uint-16.js.map +1 -0
  225. package/dist/types/uint-32.d.ts +24 -0
  226. package/dist/types/uint-32.js +50 -0
  227. package/dist/types/uint-32.js.map +1 -0
  228. package/dist/types/uint-64.d.ts +37 -0
  229. package/dist/types/uint-64.js +86 -0
  230. package/dist/types/uint-64.js.map +1 -0
  231. package/dist/types/uint-8.d.ts +24 -0
  232. package/dist/types/uint-8.js +46 -0
  233. package/dist/types/uint-8.js.map +1 -0
  234. package/dist/types/uint.d.ts +29 -0
  235. package/dist/types/uint.js +47 -0
  236. package/dist/types/uint.js.map +1 -0
  237. package/dist/types/vector-256.d.ts +30 -0
  238. package/dist/types/vector-256.js +73 -0
  239. package/dist/types/vector-256.js.map +1 -0
  240. package/dist/types/xchain-bridge.d.ts +44 -0
  241. package/dist/types/xchain-bridge.js +102 -0
  242. package/dist/types/xchain-bridge.js.map +1 -0
  243. package/dist/utils.d.ts +47 -0
  244. package/dist/utils.js +137 -0
  245. package/dist/utils.js.map +1 -0
  246. package/package.json +28 -33
  247. package/src/README.md +5 -0
  248. package/src/binary.ts +194 -0
  249. package/src/coretypes.ts +31 -0
  250. package/src/enums/README.md +144 -0
  251. package/src/enums/bytes.ts +74 -0
  252. package/src/enums/constants.ts +4 -0
  253. package/src/enums/definitions.json +2961 -0
  254. package/src/enums/field.ts +84 -0
  255. package/src/enums/index.ts +34 -0
  256. package/src/enums/utils-renumber.ts +134 -0
  257. package/src/enums/xrpl-definitions-base.ts +111 -0
  258. package/src/enums/xrpl-definitions.ts +32 -0
  259. package/src/hash-prefixes.ts +40 -0
  260. package/src/hashes.ts +75 -0
  261. package/src/index.ts +153 -0
  262. package/src/ledger-hashes.ts +191 -0
  263. package/src/quality.ts +38 -0
  264. package/src/serdes/binary-parser.ts +224 -0
  265. package/src/serdes/binary-serializer.ts +166 -0
  266. package/src/shamap.ts +186 -0
  267. package/src/types/account-id.ts +86 -0
  268. package/src/types/amount.ts +362 -0
  269. package/src/types/blob.ts +43 -0
  270. package/src/types/currency.ts +140 -0
  271. package/src/types/hash-128.ts +33 -0
  272. package/src/types/hash-160.ts +19 -0
  273. package/src/types/hash-192.ts +19 -0
  274. package/src/types/hash-256.ts +15 -0
  275. package/src/types/hash.ts +83 -0
  276. package/src/types/index.ts +66 -0
  277. package/src/types/issue.ts +96 -0
  278. package/src/types/path-set.ts +290 -0
  279. package/src/types/serialized-type.ts +122 -0
  280. package/src/types/st-array.ts +107 -0
  281. package/src/types/st-object.ts +192 -0
  282. package/src/types/uint-16.ts +53 -0
  283. package/src/types/uint-32.ts +59 -0
  284. package/src/types/uint-64.ts +104 -0
  285. package/src/types/uint-8.ts +52 -0
  286. package/src/types/uint.ts +60 -0
  287. package/src/types/vector-256.ts +79 -0
  288. package/src/types/xchain-bridge.ts +128 -0
  289. package/src/utils.ts +152 -0
  290. package/HISTORY.md +0 -66
  291. package/distrib/npm/binary.js +0 -68
  292. package/distrib/npm/coretypes.js +0 -22
  293. package/distrib/npm/enums/index.js +0 -125
  294. package/distrib/npm/enums/utils-renumber.js +0 -134
  295. package/distrib/npm/hash-prefixes.js +0 -30
  296. package/distrib/npm/hashes.js +0 -42
  297. package/distrib/npm/index.js +0 -72
  298. package/distrib/npm/ledger-hashes.js +0 -71
  299. package/distrib/npm/quality.js +0 -20
  300. package/distrib/npm/serdes/binary-parser.js +0 -98
  301. package/distrib/npm/serdes/binary-serializer.js +0 -106
  302. package/distrib/npm/shamap.js +0 -107
  303. package/distrib/npm/types/account-id.js +0 -41
  304. package/distrib/npm/types/amount.js +0 -215
  305. package/distrib/npm/types/blob.js +0 -28
  306. package/distrib/npm/types/currency.js +0 -91
  307. package/distrib/npm/types/hash-128.js +0 -10
  308. package/distrib/npm/types/hash-160.js +0 -10
  309. package/distrib/npm/types/hash-256.js +0 -15
  310. package/distrib/npm/types/hash.js +0 -45
  311. package/distrib/npm/types/index.js +0 -45
  312. package/distrib/npm/types/path-set.js +0 -112
  313. package/distrib/npm/types/serialized-type.js +0 -63
  314. package/distrib/npm/types/st-array.js +0 -37
  315. package/distrib/npm/types/st-object.js +0 -65
  316. package/distrib/npm/types/uint-16.js +0 -10
  317. package/distrib/npm/types/uint-32.js +0 -10
  318. package/distrib/npm/types/uint-64.js +0 -49
  319. package/distrib/npm/types/uint-8.js +0 -10
  320. package/distrib/npm/types/uint.js +0 -60
  321. package/distrib/npm/types/vector-256.js +0 -31
  322. package/distrib/npm/utils/bytes-utils.js +0 -112
  323. package/distrib/npm/utils/make-class.js +0 -83
  324. package/test/amount-test.js +0 -43
  325. package/test/binary-json-test.js +0 -43
  326. package/test/binary-parser-test.js +0 -341
  327. package/test/binary-serializer-test.js +0 -194
  328. package/test/bytes-utils-test.js +0 -72
  329. package/test/fixtures/account-tx-transactions.db +0 -0
  330. package/test/fixtures/codec-fixtures.json +0 -4466
  331. package/test/fixtures/data-driven-tests.json +0 -3721
  332. package/test/fixtures/delivermin-tx-binary.json +0 -1
  333. package/test/fixtures/delivermin-tx.json +0 -98
  334. package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
  335. package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
  336. package/test/fixtures/deposit-preauth-tx.json +0 -58
  337. package/test/fixtures/escrow-cancel-binary.json +0 -1
  338. package/test/fixtures/escrow-cancel-tx.json +0 -6
  339. package/test/fixtures/escrow-create-binary.json +0 -1
  340. package/test/fixtures/escrow-create-tx.json +0 -10
  341. package/test/fixtures/escrow-finish-binary.json +0 -1
  342. package/test/fixtures/escrow-finish-meta-binary.json +0 -1
  343. package/test/fixtures/escrow-finish-tx.json +0 -95
  344. package/test/fixtures/ledger-full-38129.json +0 -1
  345. package/test/fixtures/ledger-full-40000.json +0 -1
  346. package/test/fixtures/payment-channel-claim-binary.json +0 -1
  347. package/test/fixtures/payment-channel-claim-tx.json +0 -8
  348. package/test/fixtures/payment-channel-create-binary.json +0 -1
  349. package/test/fixtures/payment-channel-create-tx.json +0 -11
  350. package/test/fixtures/payment-channel-fund-binary.json +0 -1
  351. package/test/fixtures/payment-channel-fund-tx.json +0 -7
  352. package/test/fixtures/signerlistset-tx-binary.json +0 -1
  353. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  354. package/test/fixtures/signerlistset-tx.json +0 -94
  355. package/test/hash-test.js +0 -58
  356. package/test/ledger-test.js +0 -26
  357. package/test/mocha.opts +0 -1
  358. package/test/quality-test.js +0 -16
  359. package/test/shamap-test.js +0 -88
  360. package/test/signing-data-encoding-test.js +0 -120
  361. package/test/tx-encode-decode-test.js +0 -124
  362. package/test/types-test.js +0 -38
  363. package/test/uint-test.js +0 -38
  364. package/test/utils.js +0 -93
package/test/hash-test.js DELETED
@@ -1,58 +0,0 @@
1
- const assert = require('assert');
2
- const {Hash160, Hash256, Currency, AccountID} = require('../src/coretypes');
3
-
4
- describe('Hash160', function() {
5
- it('has a static width membmer', function() {
6
- assert.equal(Hash160.width, 20);
7
- });
8
- it('inherited by subclasses', function() {
9
- assert.equal(AccountID.width, 20);
10
- assert.equal(Currency.width, 20);
11
- });
12
- it('can be compared against another', function() {
13
- const h1 = Hash160.from('1000000000000000000000000000000000000000');
14
- const h2 = Hash160.from('2000000000000000000000000000000000000000');
15
- const h3 = Hash160.from('0000000000000000000000000000000000000003');
16
- assert(h1.lt(h2));
17
- assert(h3.lt(h2));
18
- });
19
- });
20
-
21
- describe('Hash256', function() {
22
- it('has a static width membmer', function() {
23
- assert.equal(Hash256.width, 32);
24
- });
25
- it('has a ZERO_256 member', function() {
26
- assert.equal(
27
- Hash256.ZERO_256.toJSON(),
28
- '0000000000000000000000000000000000000000000000000000000000000000');
29
- });
30
- it('supports getting the nibblet values at given positions', function() {
31
- const h = Hash256.from(
32
- '1359BD0000000000000000000000000000000000000000000000000000000000');
33
- assert.equal(h.nibblet(0), 0x1);
34
- assert.equal(h.nibblet(1), 0x3);
35
- assert.equal(h.nibblet(2), 0x5);
36
- assert.equal(h.nibblet(3), 0x9);
37
- assert.equal(h.nibblet(4), 0x0b);
38
- assert.equal(h.nibblet(5), 0xd);
39
- });
40
- });
41
-
42
- describe('Currency', function() {
43
- it('Will have a null iso() for dodgy XRP ', function() {
44
- const bad = Currency.from('0000000000000000000000005852500000000000');
45
- assert.equal(bad.iso(), null);
46
- assert.equal(bad.isNative(), false);
47
- });
48
- it('can be constructed from an Array', function() {
49
- const xrp = Currency.from(new Uint8Array(20));
50
- assert.equal(xrp.iso(), 'XRP');
51
- });
52
- it('throws on invalid reprs', function() {
53
- assert.throws(() => Currency.from(new Uint8Array(19)));
54
- assert.throws(() => Currency.from(1));
55
- assert.throws(() => Currency.from(
56
- '00000000000000000000000000000000000000m'));
57
- });
58
- });
@@ -1,26 +0,0 @@
1
- const assert = require('assert');
2
- const {loadFixture} = require('./utils');
3
- const ledgerHashes = require('../src/ledger-hashes');
4
- const {transactionTreeHash, ledgerHash, accountStateHash} = ledgerHashes;
5
-
6
- describe('Ledger Hashes', function() {
7
- function testFactory(ledgerFixture) {
8
- describe(`can calculate hashes for ${ledgerFixture}`, function() {
9
- const ledger = loadFixture(ledgerFixture);
10
- it('computes correct account state hash', function() {
11
- assert.equal(accountStateHash(ledger.accountState).toHex(),
12
- ledger.account_hash);
13
- });
14
- it('computes correct transaction tree hash', function() {
15
- assert.equal(transactionTreeHash(ledger.transactions).toHex(),
16
- ledger.transaction_hash);
17
- });
18
- it('computes correct ledger header hash', function() {
19
- assert.equal(ledgerHash(ledger).toHex(), ledger.hash);
20
- });
21
- });
22
- }
23
- testFactory('ledger-full-40000.json');
24
- testFactory('ledger-full-38129.json');
25
- });
26
-
package/test/mocha.opts DELETED
@@ -1 +0,0 @@
1
- --reporter spec --slow 500 --require babel-core/register
@@ -1,16 +0,0 @@
1
- const assert = require('assert');
2
- const {quality, binary: {bytesToHex}} = require('../src/coretypes');
3
-
4
- describe('Quality encode/decode', function() {
5
- const bookDirectory =
6
- '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0';
7
- const expectedQuality = '195796912.5171664';
8
- it('can decode', function() {
9
- const decimal = quality.decode(bookDirectory);
10
- assert.equal(decimal.toString(), expectedQuality);
11
- });
12
- it('can encode', function() {
13
- const bytes = quality.encode(expectedQuality);
14
- assert.equal(bytesToHex(bytes), bookDirectory.slice(-16));
15
- });
16
- });
@@ -1,88 +0,0 @@
1
- const assert = require('assert');
2
- const {ShaMap} = require('../src/shamap.js');
3
- const {binary: {serializeObject}, Hash256, HashPrefix}
4
- = require('../src/coretypes');
5
- const {loadFixture} = require('./utils');
6
-
7
- function now() {
8
- return (Number(Date.now())) / 1000;
9
- }
10
-
11
- const ZERO =
12
- '0000000000000000000000000000000000000000000000000000000000000000';
13
-
14
- function makeItem(indexArg) {
15
- let str = indexArg;
16
- while (str.length < 64) {
17
- str += '0';
18
- }
19
- const index = Hash256.from(str);
20
- const item = {
21
- toBytesSink(sink) {
22
- index.toBytesSink(sink);
23
- },
24
- hashPrefix() {
25
- return [1, 3, 3, 7];
26
- }
27
- };
28
- return [index, item];
29
- }
30
-
31
- describe('ShaMap', () => {
32
- now();
33
-
34
- it('hashes to zero when empty', () => {
35
- const map = new ShaMap();
36
- assert.equal(map.hash().toHex(), ZERO);
37
- });
38
- it('creates the same hash no matter which order items are added', () => {
39
- let map = new ShaMap();
40
- const items = [
41
- '0',
42
- '1',
43
- '11',
44
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E20000000000000000',
45
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E21000000000000000',
46
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E22000000000000000',
47
- '7000DE445E22CB9BB7E1717589FA858736BAA5FD192310E23000000000000000',
48
- '12',
49
- '122'
50
- ];
51
- items.forEach(i => map.addItem(...makeItem(i)));
52
- const h1 = map.hash();
53
- assert(h1.eq(h1));
54
- map = new ShaMap();
55
- items.reverse().forEach(i => map.addItem(...makeItem(i)));
56
- assert(map.hash().eq(h1));
57
- });
58
- function factory(fixture) {
59
- it(`recreate account state hash from ${fixture}`, () => {
60
- const map = new ShaMap();
61
- const ledger = loadFixture(fixture);
62
- // const t = now();
63
- const leafNodePrefix = HashPrefix.accountStateEntry;
64
- ledger.accountState.map((e, i) => {
65
- if (i > 1000 & (i % 1000) === 0) {
66
- console.log(e.index);
67
- console.log(i);
68
- }
69
- const bytes = serializeObject(e);
70
- return {
71
- index: Hash256.from(e.index),
72
- hashPrefix() {
73
- return leafNodePrefix;
74
- },
75
- toBytesSink(sink) {
76
- sink.put(bytes);
77
- }
78
- };
79
- }).forEach(so => map.addItem(so.index, so));
80
- assert.equal(map.hash().toHex(), ledger.account_hash);
81
- // console.log('took seconds: ', (now() - t));
82
- });
83
- }
84
- factory('ledger-full-38129.json');
85
- factory('ledger-full-40000.json');
86
- // factory('ledger-4320277.json');
87
- // factory('14280680.json');
88
- });
@@ -1,120 +0,0 @@
1
- const _ = require('lodash');
2
- const assert = require('assert');
3
- const {encodeForSigning, encodeForSigningClaim, encodeForMultisigning} =
4
- require('../src');
5
-
6
- const tx_json = {
7
- Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
8
- Amount: '1000',
9
- Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
10
- Fee: '10',
11
- Flags: 2147483648,
12
- Sequence: 1,
13
- TransactionType: 'Payment',
14
- TxnSignature: '30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1' +
15
- 'E721B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80' +
16
- 'ECA3CD7B9B',
17
- Signature: '30440220718D264EF05CAED7C781FF6DE298DCAC68D002562C9BF3A07C1E72' +
18
- '1B420C0DAB02203A5A4779EF4D2CCC7BC3EF886676D803A9981B928D3B8ACA483B80ECA' +
19
- '3CD7B9B',
20
- SigningPubKey:
21
- 'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A'
22
- };
23
-
24
- describe('Signing data', function() {
25
- it('can create single signing blobs', function() {
26
- const actual = encodeForSigning(tx_json);
27
- assert.equal(actual,
28
- ['53545800', // signingPrefix
29
- // TransactionType
30
- '12',
31
- '0000',
32
- // Flags
33
- '22',
34
- '80000000',
35
- // Sequence
36
- '24',
37
- '00000001',
38
- // Amount
39
- '61',
40
- // native amount
41
- '40000000000003E8',
42
- // Fee
43
- '68',
44
- // native amount
45
- '400000000000000A',
46
- // SigningPubKey
47
- '73',
48
- // VLLength
49
- '21',
50
- 'ED5F5AC8B98974A3CA843326D9B88CEBD0560177B973EE0B149F782CFAA06DC66A',
51
- // Account
52
- '81',
53
- // VLLength
54
- '14',
55
- '5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
56
- // Destination
57
- '83',
58
- // VLLength
59
- '14',
60
- 'B5F762798A53D543A014CAF8B297CFF8F2F937E8'].join('')
61
- );
62
- });
63
- it('can create multi signing blobs', function() {
64
- const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN';
65
- const signingJson = _.assign({}, tx_json, {SigningPubKey: ''});
66
- const actual = encodeForMultisigning(signingJson, signingAccount);
67
- assert.equal(actual,
68
- ['534D5400', // signingPrefix
69
- // TransactionType
70
- '12',
71
- '0000',
72
- // Flags
73
- '22',
74
- '80000000',
75
- // Sequence
76
- '24',
77
- '00000001',
78
- // Amount
79
- '61',
80
- // native amount
81
- '40000000000003E8',
82
- // Fee
83
- '68',
84
- // native amount
85
- '400000000000000A',
86
- // SigningPubKey
87
- '73',
88
- // VLLength
89
- '00',
90
- // '',
91
- // Account
92
- '81',
93
- // VLLength
94
- '14',
95
- '5B812C9D57731E27A2DA8B1830195F88EF32A3B6',
96
- // Destination
97
- '83',
98
- // VLLength
99
- '14',
100
- 'B5F762798A53D543A014CAF8B297CFF8F2F937E8',
101
- // signingAccount suffix
102
- 'C0A5ABEF242802EFED4B041E8F2D4A8CC86AE3D1'].join('')
103
- );
104
- });
105
- it('can create claim blob', function() {
106
- const channel =
107
- '43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1'
108
- const amount = '1000'
109
- const json = {channel, amount}
110
- const actual = encodeForSigningClaim(json)
111
- assert.equal(actual, [
112
- // hash prefix
113
- '434C4D00',
114
- // channel ID
115
- '43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1',
116
- // amount as a uint64
117
- '00000000000003E8'
118
- ].join(''))
119
- })
120
- });
@@ -1,124 +0,0 @@
1
- const assert = require('assert');
2
- const {
3
- encode,
4
- decode
5
- } = require('../src')
6
-
7
- // Notice: no Amount or Fee
8
- const tx_json = {
9
- Account: 'r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ',
10
- // Amount: '1000',
11
- Destination: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
12
- // Fee: '10',
13
-
14
- // JavaScript converts operands to 32-bit signed ints after doing bitwise
15
- // operations. We need to convert it back to an unsigned int with >>> 0.
16
- Flags: ((1 << 31) >>> 0), // tfFullyCanonicalSig
17
-
18
- Sequence: 1,
19
- TransactionType: 'Payment'
20
- // TxnSignature,
21
- // Signature,
22
- // SigningPubKey
23
- };
24
-
25
- const amount_parameters_message = input => {
26
- // disables the ESLint rule on the whole rest of the file
27
- /* eslint-disable max-len */
28
- return `${input} is an illegal amount
29
-
30
- Native values must be described in drops, a million of which equal one XRP.
31
- This must be an integer number, with the absolute value not exceeding 100000000000000000
32
-
33
- IOU values must have a maximum precision of 16 significant digits. They are serialized as
34
- a canonicalised mantissa and exponent.
35
-
36
- The valid range for a mantissa is between 1000000000000000 and 9999999999999999
37
- The exponent must be >= -96 and <= 80
38
-
39
- Thus the largest serializable IOU value is:
40
- 999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000
41
-
42
- And the smallest:
43
- 0.000000000000000000000000000000000000000000000000000000000000000000000000000000001
44
- `;
45
- };
46
-
47
- describe('encoding and decoding tx_json', function() {
48
- it('can encode tx_json without Amount or Fee', function() {
49
- const encoded = encode(tx_json);
50
- const decoded = decode(encoded);
51
- assert.deepStrictEqual(tx_json, decoded);
52
- });
53
- it('can encode tx_json with Amount and Fee', function() {
54
- const my_tx = Object.assign({}, tx_json, {
55
- Amount: '1000',
56
- Fee: '10'
57
- });
58
- const encoded = encode(my_tx);
59
- const decoded = decode(encoded);
60
- assert.deepStrictEqual(my_tx, decoded);
61
- });
62
- it('throws when Amount is invalid', function() {
63
- const my_tx = Object.assign({}, tx_json, {
64
- Amount: '1000.001',
65
- Fee: '10'
66
- });
67
- assert.throws(() => {
68
- encode(my_tx);
69
- }, {
70
- name: 'Error',
71
- message: amount_parameters_message('1000.001')
72
- });
73
- });
74
- it('throws when Fee is invalid', function() {
75
- const my_tx = Object.assign({}, tx_json, {
76
- Amount: '1000',
77
- Fee: '10.123'
78
- });
79
- assert.throws(() => {
80
- encode(my_tx);
81
- }, {
82
- name: 'Error',
83
- message: amount_parameters_message('10.123')
84
- });
85
- });
86
- it('throws when Amount and Fee are invalid', function() {
87
- const my_tx = Object.assign({}, tx_json, {
88
- Amount: '1000.789',
89
- Fee: '10.123'
90
- });
91
- assert.throws(() => {
92
- encode(my_tx);
93
- }, {
94
- name: 'Error',
95
- message: amount_parameters_message('1000.789')
96
- });
97
- });
98
- it('throws when Amount is a number instead of a string-encoded integer',
99
- function() {
100
- const my_tx = Object.assign({}, tx_json, {
101
- Amount: 1000.789
102
- });
103
- assert.throws(() => {
104
- encode(my_tx);
105
- },
106
- {
107
- name: 'Error',
108
- message: 'unsupported value: 1000.789'
109
- });
110
- });
111
- it('throws when Fee is a number instead of a string-encoded integer',
112
- function() {
113
- const my_tx = Object.assign({}, tx_json, {
114
- Amount: 1234.56
115
- });
116
- assert.throws(() => {
117
- encode(my_tx);
118
- },
119
- {
120
- name: 'Error',
121
- message: 'unsupported value: 1234.56'
122
- });
123
- });
124
- });
@@ -1,38 +0,0 @@
1
- const _ = require('lodash');
2
- const assert = require('assert');
3
- const coreTypes = require('../src/types');
4
- const {SerializedType} = require('../src/types/serialized-type');
5
-
6
- describe('SerializedType interfaces', () => {
7
- _.forOwn(coreTypes, (Value, name) => {
8
- it(`${name} has a \`from\` static constructor`, () => {
9
- assert(Value.from && Value.from !== Array.from);
10
- });
11
- it(`${name} has a default constructor`, () => {
12
- /* eslint-disable no-new*/
13
- new Value();
14
- /* eslint-enable no-new*/
15
- });
16
- it(`${name}.from will return the same object`, () => {
17
- const instance = new Value();
18
- assert(Value.from(instance) === instance);
19
- });
20
- it(`${name} instances have toBytesSink`, () => {
21
- assert(new Value().toBytesSink);
22
- });
23
- it(`${name} instances have toJSON`, () => {
24
- assert(new Value().toJSON);
25
- });
26
- it(`${name}.from(json).toJSON() == json`, () => {
27
- const newJSON = new Value().toJSON();
28
- assert.deepEqual(Value.from(newJSON).toJSON(), newJSON);
29
- });
30
- describe(`${name} supports all methods of the SerializedType mixin`, () => {
31
- _.keys(SerializedType).forEach(k => {
32
- it(`new ${name}.prototype.${k} !== undefined`, () => {
33
- assert.notEqual(Value.prototype[k], undefined);
34
- });
35
- });
36
- });
37
- });
38
- });
package/test/uint-test.js DELETED
@@ -1,38 +0,0 @@
1
- const assert = require('assert');
2
- const coreTypes = require('../src/coretypes');
3
- /* eslint-disable no-unused-vars */
4
- const {UInt8, UInt16, UInt32, UInt64} = coreTypes;
5
- /* eslint-enable no-unused-vars */
6
-
7
- function compareToTests() {
8
-
9
- function check(expr, is) {
10
- it(expr, function() {
11
- /* eslint-disable no-eval */
12
- assert.equal(eval(expr), is);
13
- /* eslint-enable no-eval */
14
- });
15
- }
16
- check('UInt8.from(124).compareTo(UInt64.from(124))', 0);
17
- check('UInt64.from(124).compareTo(UInt8.from(124))', 0);
18
- check('UInt64.from(124).compareTo(UInt8.from(123))', 1);
19
- check('UInt8.from(124).compareTo(UInt8.from(13))', 1);
20
- check('UInt8.from(124).compareTo(124)', 0);
21
- check('UInt64.from(124).compareTo(124)', 0);
22
- check('UInt64.from(124).compareTo(123)', 1);
23
- check('UInt8.from(124).compareTo(13)', 1);
24
- }
25
-
26
- function valueOfTests() {
27
- it('The Uint classes work with |= operator', function() {
28
- let val = UInt8.from(1);
29
- val |= 0x2;
30
- assert.equal(val, 3);
31
- });
32
- }
33
-
34
- describe('Uint*', function() {
35
- describe('compareToTests', compareToTests);
36
- describe('valueOfTests', valueOfTests);
37
- });
38
-
package/test/utils.js DELETED
@@ -1,93 +0,0 @@
1
- const intercept = require('intercept-stdout');
2
- const fs = require('fs');
3
- const fsExtra = require('fs-extra');
4
- const assert = require('assert');
5
- const Decimal = require('decimal.js');
6
- const {parseBytes} = require('../src/utils/bytes-utils');
7
-
8
- function hexOnly(hex) {
9
- return hex.replace(/[^a-fA-F0-9]/g, '');
10
- }
11
-
12
- function unused() {}
13
-
14
- function captureLogsAsync() {
15
- let log = '';
16
- const unhook = intercept(txt => {
17
- log += txt;
18
- return '';
19
- });
20
- return function() {
21
- unhook();
22
- return log;
23
- };
24
- }
25
-
26
- function captureLogs(func) {
27
- const finished = captureLogsAsync();
28
- try {
29
- func();
30
- } catch (e) {
31
- const log = finished();
32
- console.error(log);
33
- throw e;
34
- }
35
- return finished();
36
- }
37
-
38
- function parseHexOnly(hex, to) {
39
- return parseBytes(hexOnly(hex), to);
40
- }
41
-
42
- function loadFixture(relativePath) {
43
- const fn = __dirname + '/fixtures/' + relativePath;
44
- return require(fn);
45
- }
46
-
47
- function isBufferOrString(val) {
48
- return Buffer.isBuffer(val) || (typeof val === 'string');
49
- }
50
-
51
- function loadFixtureText(relativePath) {
52
- const fn = __dirname + '/fixtures/' + relativePath;
53
- return fs.readFileSync(fn).toString('utf8');
54
- }
55
-
56
- function fixturePath(relativePath) {
57
- return __dirname + '/fixtures/' + relativePath;
58
- }
59
-
60
- function prettyJSON(val) {
61
- return JSON.stringify(val, null, 2);
62
- }
63
-
64
- function writeFixture(relativePath, data) {
65
- const out = isBufferOrString(data) ? data : prettyJSON(data);
66
- return fsExtra.outputFileSync(fixturePath(relativePath), out);
67
- }
68
-
69
- function assertEqualAmountJSON(actual, expected) {
70
- const typeA = (typeof actual);
71
- assert(typeA === (typeof expected));
72
- if (typeA === 'string') {
73
- assert.equal(actual, expected);
74
- return;
75
- }
76
- assert.equal(actual.currency, expected.currency);
77
- assert.equal(actual.issuer, expected.issuer);
78
- assert(actual.value === expected.value ||
79
- new Decimal(actual.value).equals(
80
- new Decimal(expected.value)));
81
- }
82
-
83
- module.exports = {
84
- hexOnly,
85
- parseHexOnly,
86
- loadFixture,
87
- loadFixtureText,
88
- assertEqualAmountJSON,
89
- writeFixture,
90
- unused,
91
- captureLogs,
92
- captureLogsAsync
93
- };