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/HISTORY.md DELETED
@@ -1,66 +0,0 @@
1
- # ripple-binary-codec Release History
2
-
3
- ## 0.2.7 (2020-08-22)
4
-
5
- - Last release of 0.2.x
6
- - Since 1.0 requires Node.js 10.22+, one reason 0.2.x could be useful is if you cannot upgrade Node.js and do not need new transaction types / features
7
- - Bump ripple-address-codec to 4.1.1 (#57)
8
- - Project internals
9
- - Improve documentation of definitions.json (#80)
10
- - Bump dependencies including babel-runtime (#50), babel-eslint (#52), fs-extra (#55), mocha (#58), handlebars (#62), eslint (#60)
11
-
12
- ## 0.2.6 (2019-12-31)
13
-
14
- - Update dependencies
15
- - decimal.js, fs-extra, mocha, handlebars, bn.js, babel-eslint, ripple-address-codec
16
-
17
- ## 0.2.5 (2019-12-14)
18
-
19
- - Add support for AccountDelete (#37)
20
-
21
- ## 0.2.4 (2019-09-04)
22
-
23
- - Update ripple-address-codec to 3.0.4
24
-
25
- ## 0.2.3 (2019-08-29)
26
-
27
- - Expand node version compatibility (#32, #33)
28
-
29
- ## 0.2.2 (2019-07-26)
30
-
31
- - Input validation - Amount and Fee should not allow fractional XRP drops ([#31](https://github.com/ripple/ripple-binary-codec/issues/31))
32
- - Fix lint errors
33
- - Update dependencies (including lodash and mocha)
34
- - Require node 10 (.nvmrc)
35
- - Remove assert-diff
36
- - Remove codecov.io as it did not appear to work. The `package.json` script was:
37
- - `"codecov": "cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"`
38
-
39
- ## 0.2.1
40
-
41
- - Add tecKILLED from amendment fix1578 (PR #27 fixes #25)
42
-
43
- ## 0.2.0
44
-
45
- - Add DepositPreauth fields
46
- - https://developers.ripple.com/depositauth.html
47
-
48
- ## 0.1.14
49
-
50
- - Skip amount validation when deserializing f72c115
51
-
52
- ## 0.1.13
53
-
54
- - Add Check, CheckCreate, CheckCash, CheckCancel
55
-
56
- ## 0.1.11
57
-
58
- - Add ledger header decode function
59
-
60
- ## 0.1.8
61
-
62
- ## 0.1.7
63
-
64
- ## 0.1.6
65
-
66
- ## 0.1.3
@@ -1,68 +0,0 @@
1
- 'use strict'; /* eslint-disable func-style */
2
-
3
- var BN = require('bn.js');
4
- var types = require('./types');var _require =
5
- require('./hash-prefixes'),HashPrefix = _require.HashPrefix;var _require2 =
6
- require('./serdes/binary-parser'),BinaryParser = _require2.BinaryParser;var _require3 =
7
- require('./serdes/binary-serializer'),BinarySerializer = _require3.BinarySerializer,BytesList = _require3.BytesList;var _require4 =
8
- require('./utils/bytes-utils'),bytesToHex = _require4.bytesToHex,slice = _require4.slice,parseBytes = _require4.parseBytes;var _require5 =
9
-
10
- require('./hashes'),sha512Half = _require5.sha512Half,transactionID = _require5.transactionID;
11
-
12
- var makeParser = function makeParser(bytes) {return new BinaryParser(bytes);};
13
- var readJSON = function readJSON(parser) {return parser.readType(types.STObject).toJSON();};
14
- var binaryToJSON = function binaryToJSON(bytes) {return readJSON(makeParser(bytes));};
15
-
16
- function serializeObject(object) {var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};var
17
- prefix = opts.prefix,suffix = opts.suffix,_opts$signingFieldsOn = opts.signingFieldsOnly,signingFieldsOnly = _opts$signingFieldsOn === undefined ? false : _opts$signingFieldsOn;
18
- var bytesList = new BytesList();
19
- if (prefix) {
20
- bytesList.put(prefix);
21
- }
22
- var filter = signingFieldsOnly ? function (f) {return f.isSigningField;} : undefined;
23
- types.STObject.from(object).toBytesSink(bytesList, filter);
24
- if (suffix) {
25
- bytesList.put(suffix);
26
- }
27
- return bytesList.toBytes();
28
- }
29
-
30
- function signingData(tx) {var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : HashPrefix.transactionSig;
31
- return serializeObject(tx, { prefix: prefix, signingFieldsOnly: true });
32
- }
33
-
34
- function signingClaimData(claim) {
35
- var prefix = HashPrefix.paymentChannelClaim;
36
- var channel = types.Hash256.from(claim.channel).toBytes();
37
- var amount = new types.UInt64(new BN(claim.amount)).toBytes();
38
-
39
- var bytesList = new BytesList();
40
-
41
- bytesList.put(prefix);
42
- bytesList.put(channel);
43
- bytesList.put(amount);
44
- return bytesList.toBytes();
45
- }
46
-
47
- function multiSigningData(tx, signingAccount) {
48
- var prefix = HashPrefix.transactionMultiSig;
49
- var suffix = types.AccountID.from(signingAccount).toBytes();
50
- return serializeObject(tx, { prefix: prefix, suffix: suffix, signingFieldsOnly: true });
51
- }
52
-
53
- module.exports = {
54
- BinaryParser: BinaryParser,
55
- BinarySerializer: BinarySerializer,
56
- BytesList: BytesList,
57
- makeParser: makeParser,
58
- serializeObject: serializeObject,
59
- readJSON: readJSON,
60
- bytesToHex: bytesToHex,
61
- parseBytes: parseBytes,
62
- multiSigningData: multiSigningData,
63
- signingData: signingData,
64
- signingClaimData: signingClaimData,
65
- binaryToJSON: binaryToJSON,
66
- sha512Half: sha512Half,
67
- transactionID: transactionID,
68
- slice: slice };
@@ -1,22 +0,0 @@
1
- 'use strict';var _ = require('lodash');
2
- var enums = require('./enums');var
3
- Field = enums.Field;
4
- var types = require('./types');
5
- var binary = require('./binary');var _require =
6
- require('./shamap'),ShaMap = _require.ShaMap;
7
- var ledgerHashes = require('./ledger-hashes');
8
- var hashes = require('./hashes');
9
- var quality = require('./quality');var _require2 =
10
- require('./hash-prefixes'),HashPrefix = _require2.HashPrefix;
11
-
12
-
13
- module.exports = _.assign({
14
- hashes: _.assign({}, hashes, ledgerHashes),
15
- binary: binary,
16
- enums: enums,
17
- quality: quality,
18
- Field: Field,
19
- HashPrefix: HashPrefix,
20
- ShaMap: ShaMap },
21
-
22
- types);
@@ -1,125 +0,0 @@
1
- 'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var assert = require('assert');
2
- var _ = require('lodash');var _require =
3
- require('./../utils/bytes-utils'),parseBytes = _require.parseBytes,serializeUIntN = _require.serializeUIntN;
4
- var makeClass = require('./../utils/make-class');
5
- var enums = require('./definitions.json');
6
-
7
- function transformWith(func, obj) {
8
- return _.transform(obj, func);
9
- }
10
-
11
- function biMap(obj, valueKey) {
12
- return _.transform(obj, function (result, value, key) {
13
- result[key] = value;
14
- result[value[valueKey]] = value;
15
- });
16
- }
17
-
18
- var EnumType = makeClass({
19
- EnumType: function EnumType(definition) {
20
- _.assign(this, definition);
21
- // At minimum
22
- assert(this.bytes instanceof Uint8Array);
23
- assert(typeof this.ordinal === 'number');
24
- assert(typeof this.name === 'string');
25
- },
26
- toString: function toString() {
27
- return this.name;
28
- },
29
- toJSON: function toJSON() {
30
- return this.name;
31
- },
32
- toBytesSink: function toBytesSink(sink) {
33
- sink.put(this.bytes);
34
- },
35
- statics: {
36
- ordinalByteWidth: 1,
37
- fromParser: function fromParser(parser) {
38
- return this.from(parser.readUIntN(this.ordinalByteWidth));
39
- },
40
- from: function from(val) {
41
- var ret = val instanceof this ? val : this[val];
42
- if (!ret) {
43
- throw new Error(
44
- val + ' is not a valid name or ordinal for ' + this.enumName);
45
- }
46
- return ret;
47
- },
48
- valuesByName: function valuesByName() {var _this = this;
49
- return _.transform(this.initVals, function (result, ordinal, name) {
50
- var bytes = serializeUIntN(ordinal, _this.ordinalByteWidth);
51
- var type = new _this({ name: name, ordinal: ordinal, bytes: bytes });
52
- result[name] = type;
53
- });
54
- },
55
- init: function init() {
56
- var mapped = this.valuesByName();
57
- _.assign(this, biMap(mapped, 'ordinal'));
58
- this.values = _.values(mapped);
59
- return this;
60
- } } });
61
-
62
-
63
-
64
- function makeEnum(name, definition) {
65
- return makeClass({
66
- inherits: EnumType,
67
- statics: _.assign(definition, { enumName: name }) });
68
-
69
- }
70
-
71
- function makeEnums(to, definition, name) {
72
- to[name] = makeEnum(name, definition);
73
- }
74
-
75
- var Enums = transformWith(makeEnums, {
76
- Type: {
77
- initVals: enums.TYPES },
78
-
79
- LedgerEntryType: {
80
- initVals: enums.LEDGER_ENTRY_TYPES, ordinalByteWidth: 2 },
81
-
82
- TransactionType: {
83
- initVals: enums.TRANSACTION_TYPES, ordinalByteWidth: 2 },
84
-
85
- TransactionResult: {
86
- initVals: enums.TRANSACTION_RESULTS, ordinalByteWidth: 1 } });
87
-
88
-
89
-
90
- Enums.Field = makeClass({
91
- inherits: EnumType,
92
- statics: {
93
- enumName: 'Field',
94
- initVals: enums.FIELDS,
95
- valuesByName: function valuesByName() {var _this2 = this;
96
- var fields = _.map(this.initVals, function (_ref) {var _ref2 = _slicedToArray(_ref, 2),name = _ref2[0],definition = _ref2[1];
97
- var type = Enums.Type[definition.type];
98
- var bytes = _this2.header(type.ordinal, definition.nth);
99
- var ordinal = type.ordinal << 16 | definition.nth;
100
- var extra = { ordinal: ordinal, name: name, type: type, bytes: bytes };
101
- return new _this2(_.assign(definition, extra));
102
- });
103
- return _.keyBy(fields, 'name');
104
- },
105
- header: function header(type, nth) {
106
- var name = nth;
107
- var header = [];
108
- var push = header.push.bind(header);
109
- if (type < 16) {
110
- if (name < 16) {
111
- push(type << 4 | name);
112
- } else {
113
- push(type << 4, name);
114
- }
115
- } else if (name < 16) {
116
- push(name, type);
117
- } else {
118
- push(0, type, name);
119
- }
120
- return parseBytes(header, Uint8Array);
121
- } } });
122
-
123
-
124
-
125
- module.exports = Enums;
@@ -1,134 +0,0 @@
1
- 'use strict'; /**
2
- * Quick script to re-number values
3
- */
4
-
5
- var input = {
6
- 'temBAD_SEND_XRP_PATHS': -283,
7
- 'temBAD_SEQUENCE': -282,
8
- 'temBAD_SIGNATURE': -281,
9
- 'temBAD_SRC_ACCOUNT': -280,
10
- 'temBAD_TRANSFER_RATE': -279,
11
- 'temDST_IS_SRC': -278,
12
- 'temDST_NEEDED': -277,
13
- 'temINVALID': -276,
14
- 'temINVALID_FLAG': -275,
15
- 'temREDUNDANT': -274,
16
- 'temRIPPLE_EMPTY': -273,
17
- 'temDISABLED': -272,
18
- 'temBAD_SIGNER': -271,
19
- 'temBAD_QUORUM': -270,
20
- 'temBAD_WEIGHT': -269,
21
- 'temBAD_TICK_SIZE': -268,
22
- 'temINVALID_ACCOUNT_ID': -267,
23
- 'temCANNOT_PREAUTH_SELF': -266,
24
-
25
- 'temUNCERTAIN': -265,
26
- 'temUNKNOWN': -264,
27
-
28
- 'tefFAILURE': -199,
29
- 'tefALREADY': -198,
30
- 'tefBAD_ADD_AUTH': -197,
31
- 'tefBAD_AUTH': -196,
32
- 'tefBAD_LEDGER': -195,
33
- 'tefCREATED': -194,
34
- 'tefEXCEPTION': -193,
35
- 'tefINTERNAL': -192,
36
- 'tefNO_AUTH_REQUIRED': -191,
37
- 'tefPAST_SEQ': -190,
38
- 'tefWRONG_PRIOR': -189,
39
- 'tefMASTER_DISABLED': -188,
40
- 'tefMAX_LEDGER': -187,
41
- 'tefBAD_SIGNATURE': -186,
42
- 'tefBAD_QUORUM': -185,
43
- 'tefNOT_MULTI_SIGNING': -184,
44
- 'tefBAD_AUTH_MASTER': -183,
45
- 'tefINVARIANT_FAILED': -182,
46
- 'tefTOO_BIG': -181,
47
-
48
- 'terRETRY': -99,
49
- 'terFUNDS_SPENT': -98,
50
- 'terINSUF_FEE_B': -97,
51
- 'terNO_ACCOUNT': -96,
52
- 'terNO_AUTH': -95,
53
- 'terNO_LINE': -94,
54
- 'terOWNERS': -93,
55
- 'terPRE_SEQ': -92,
56
- 'terLAST': -91,
57
- 'terNO_RIPPLE': -90,
58
- 'terQUEUED': -89,
59
-
60
- 'tesSUCCESS': 0,
61
-
62
- 'tecCLAIM': 100,
63
- 'tecPATH_PARTIAL': 101,
64
- 'tecUNFUNDED_ADD': 102,
65
- 'tecUNFUNDED_OFFER': 103,
66
- 'tecUNFUNDED_PAYMENT': 104,
67
- 'tecFAILED_PROCESSING': 105,
68
- 'tecDIR_FULL': 121,
69
- 'tecINSUF_RESERVE_LINE': 122,
70
- 'tecINSUF_RESERVE_OFFER': 123,
71
- 'tecNO_DST': 124,
72
- 'tecNO_DST_INSUF_XRP': 125,
73
- 'tecNO_LINE_INSUF_RESERVE': 126,
74
- 'tecNO_LINE_REDUNDANT': 127,
75
- 'tecPATH_DRY': 128,
76
- 'tecUNFUNDED': 129,
77
- 'tecNO_ALTERNATIVE_KEY': 130,
78
- 'tecNO_REGULAR_KEY': 131,
79
- 'tecOWNERS': 132,
80
- 'tecNO_ISSUER': 133,
81
- 'tecNO_AUTH': 134,
82
- 'tecNO_LINE': 135,
83
- 'tecINSUFF_FEE': 136,
84
- 'tecFROZEN': 137,
85
- 'tecNO_TARGET': 138,
86
- 'tecNO_PERMISSION': 139,
87
- 'tecNO_ENTRY': 140,
88
- 'tecINSUFFICIENT_RESERVE': 141,
89
- 'tecNEED_MASTER_KEY': 142,
90
- 'tecDST_TAG_NEEDED': 143,
91
- 'tecINTERNAL': 144,
92
- 'tecOVERSIZE': 145,
93
- 'tecCRYPTOCONDITION_ERROR': 146,
94
- 'tecINVARIANT_FAILED': 147,
95
- 'tecEXPIRED': 148,
96
- 'tecDUPLICATE': 149,
97
- 'tecKILLED': 150,
98
- 'tecHAS_OBLIGATIONS': 151,
99
- 'tecTOO_SOON': 152 };
100
-
101
-
102
- var starting_from_temBAD_SEND_XRP_PATHS = -284;
103
-
104
- var starting_from_tefFAILURE = -199;
105
-
106
- var starting_from_terRETRY = -99;
107
-
108
- var tesSUCCESS = 0;
109
-
110
- var starting_from_tecCLAIM = 100;
111
-
112
- var starting_from_tecDIR_FULL = 121;
113
-
114
- var previousKey = 'tem';
115
- Object.keys(input).forEach(function (key) {
116
- if (key.substring(0, 3) !== previousKey.substring(0, 3)) {
117
- console.log();
118
- previousKey = key;
119
- }
120
- if (key.substring(0, 3) === 'tem') {
121
- console.log(' "' + key + '": ' + starting_from_temBAD_SEND_XRP_PATHS++ + ',');
122
- } else if (key.substring(0, 3) === 'tef') {
123
- console.log(' "' + key + '": ' + starting_from_tefFAILURE++ + ',');
124
- } else if (key.substring(0, 3) === 'ter') {
125
- console.log(' "' + key + '": ' + starting_from_terRETRY++ + ',');
126
- } else if (key.substring(0, 3) === 'tes') {
127
- console.log(' "' + key + '": ' + tesSUCCESS + ',');
128
- } else if (key.substring(0, 3) === 'tec') {
129
- if (key === 'tecDIR_FULL') {
130
- starting_from_tecCLAIM = starting_from_tecDIR_FULL;
131
- }
132
- console.log(' "' + key + '": ' + starting_from_tecCLAIM++ + ',');
133
- }
134
- });
@@ -1,30 +0,0 @@
1
- 'use strict';var _require = require('./utils/bytes-utils'),serializeUIntN = _require.serializeUIntN;
2
-
3
- function bytes(uint32) {
4
- return serializeUIntN(uint32, 4);
5
- }
6
-
7
- var HashPrefix = {
8
- transactionID: bytes(0x54584E00),
9
- // transaction plus metadata
10
- transaction: bytes(0x534E4400),
11
- // account state
12
- accountStateEntry: bytes(0x4D4C4E00),
13
- // inner node in tree
14
- innerNode: bytes(0x4D494E00),
15
- // ledger master data for signing
16
- ledgerHeader: bytes(0x4C575200),
17
- // inner transaction to sign
18
- transactionSig: bytes(0x53545800),
19
- // inner transaction to sign
20
- transactionMultiSig: bytes(0x534D5400),
21
- // validation for signing
22
- validation: bytes(0x56414C00),
23
- // proposal for signing
24
- proposal: bytes(0x50525000),
25
- // payment channel claim
26
- paymentChannelClaim: bytes(0x434C4D00) };
27
-
28
-
29
- module.exports = {
30
- HashPrefix: HashPrefix };
@@ -1,42 +0,0 @@
1
- 'use strict';var makeClass = require('./utils/make-class');var _require =
2
- require('./hash-prefixes'),HashPrefix = _require.HashPrefix;var _require2 =
3
- require('./types'),Hash256 = _require2.Hash256;var _require3 =
4
- require('./utils/bytes-utils'),parseBytes = _require3.parseBytes;
5
- var createHash = require('create-hash');
6
-
7
- var Sha512Half = makeClass({
8
- Sha512Half: function Sha512Half() {
9
- this.hash = createHash('sha512');
10
- },
11
- statics: {
12
- put: function put(bytes) {
13
- return new this().put(bytes);
14
- } },
15
-
16
- put: function put(bytes) {
17
- this.hash.update(parseBytes(bytes, Buffer));
18
- return this;
19
- },
20
- finish256: function finish256() {
21
- var bytes = this.hash.digest();
22
- return bytes.slice(0, 32);
23
- },
24
- finish: function finish() {
25
- return new Hash256(this.finish256());
26
- } });
27
-
28
-
29
- function sha512Half() {
30
- var hash = new Sha512Half();for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
31
- args.forEach(function (a) {return hash.put(a);});
32
- return parseBytes(hash.finish256(), Uint8Array);
33
- }
34
-
35
- function transactionID(serialized) {
36
- return new Hash256(sha512Half(HashPrefix.transactionID, serialized));
37
- }
38
-
39
- module.exports = {
40
- Sha512Half: Sha512Half,
41
- sha512Half: sha512Half,
42
- transactionID: transactionID };
@@ -1,72 +0,0 @@
1
- 'use strict';var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {return typeof obj;} : function (obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};var assert = require('assert');
2
- var coreTypes = require('./coretypes');var
3
- quality =
4
-
5
-
6
-
7
-
8
-
9
-
10
- coreTypes.quality,_coreTypes$binary = coreTypes.binary,bytesToHex = _coreTypes$binary.bytesToHex,signingData = _coreTypes$binary.signingData,signingClaimData = _coreTypes$binary.signingClaimData,multiSigningData = _coreTypes$binary.multiSigningData,binaryToJSON = _coreTypes$binary.binaryToJSON,serializeObject = _coreTypes$binary.serializeObject,BinaryParser = _coreTypes$binary.BinaryParser;
11
-
12
- function decodeLedgerData(binary) {
13
- assert(typeof binary === 'string', 'binary must be a hex string');
14
- var parser = new BinaryParser(binary);
15
- return {
16
- ledger_index: parser.readUInt32(),
17
- total_coins: parser.readType(coreTypes.UInt64).valueOf().toString(),
18
- parent_hash: parser.readType(coreTypes.Hash256).toHex(),
19
- transaction_hash: parser.readType(coreTypes.Hash256).toHex(),
20
- account_hash: parser.readType(coreTypes.Hash256).toHex(),
21
- parent_close_time: parser.readUInt32(),
22
- close_time: parser.readUInt32(),
23
- close_time_resolution: parser.readUInt8(),
24
- close_flags: parser.readUInt8() };
25
-
26
- }
27
-
28
- function decode(binary) {
29
- assert(typeof binary === 'string', 'binary must be a hex string');
30
- return binaryToJSON(binary);
31
- }
32
-
33
- function encode(json) {
34
- assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object');
35
- return bytesToHex(serializeObject(json));
36
- }
37
-
38
- function encodeForSigning(json) {
39
- assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object');
40
- return bytesToHex(signingData(json));
41
- }
42
-
43
- function encodeForSigningClaim(json) {
44
- assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object');
45
- return bytesToHex(signingClaimData(json));
46
- }
47
-
48
- function encodeForMultisigning(json, signer) {
49
- assert((typeof json === 'undefined' ? 'undefined' : _typeof(json)) === 'object');
50
- assert.equal(json.SigningPubKey, '');
51
- return bytesToHex(multiSigningData(json, signer));
52
- }
53
-
54
- function encodeQuality(value) {
55
- assert(typeof value === 'string');
56
- return bytesToHex(quality.encode(value));
57
- }
58
-
59
- function decodeQuality(value) {
60
- assert(typeof value === 'string');
61
- return quality.decode(value).toString();
62
- }
63
-
64
- module.exports = {
65
- decode: decode,
66
- encode: encode,
67
- encodeForSigning: encodeForSigning,
68
- encodeForSigningClaim: encodeForSigningClaim,
69
- encodeForMultisigning: encodeForMultisigning,
70
- encodeQuality: encodeQuality,
71
- decodeQuality: decodeQuality,
72
- decodeLedgerData: decodeLedgerData };
@@ -1,71 +0,0 @@
1
- 'use strict';function _toConsumableArray(arr) {if (Array.isArray(arr)) {for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {arr2[i] = arr[i];}return arr2;} else {return Array.from(arr);}}var _ = require('lodash');
2
- var BN = require('bn.js');
3
- var assert = require('assert');
4
- var types = require('./types');var
5
- STObject = types.STObject,Hash256 = types.Hash256;var _require =
6
- require('./shamap'),ShaMap = _require.ShaMap;var _require2 =
7
- require('./hash-prefixes'),HashPrefix = _require2.HashPrefix;var _require3 =
8
- require('./hashes'),Sha512Half = _require3.Sha512Half;var _require4 =
9
- require('./binary'),BinarySerializer = _require4.BinarySerializer,serializeObject = _require4.serializeObject;
10
-
11
- function computeHash(itemizer, itemsJson) {
12
- var map = new ShaMap();
13
- itemsJson.forEach(function (item) {return map.addItem.apply(map, _toConsumableArray(itemizer(item)));});
14
- return map.hash();
15
- }
16
-
17
- function transactionItem(json) {
18
- assert(json.hash);
19
- var index = Hash256.from(json.hash);
20
- var item = {
21
- hashPrefix: function hashPrefix() {
22
- return HashPrefix.transaction;
23
- },
24
- toBytesSink: function toBytesSink(sink) {
25
- var serializer = new BinarySerializer(sink);
26
- serializer.writeLengthEncoded(STObject.from(json));
27
- serializer.writeLengthEncoded(STObject.from(json.metaData));
28
- } };
29
-
30
- return [index, item];
31
- }
32
-
33
- function entryItem(json) {
34
- var index = Hash256.from(json.index);
35
- var bytes = serializeObject(json);
36
- var item = {
37
- hashPrefix: function hashPrefix() {
38
- return HashPrefix.accountStateEntry;
39
- },
40
- toBytesSink: function toBytesSink(sink) {
41
- sink.put(bytes);
42
- } };
43
-
44
- return [index, item];
45
- }
46
-
47
- var transactionTreeHash = _.partial(computeHash, transactionItem);
48
- var accountStateHash = _.partial(computeHash, entryItem);
49
-
50
- function ledgerHash(header) {
51
- var hash = new Sha512Half();
52
- hash.put(HashPrefix.ledgerHeader);
53
- assert(header.parent_close_time !== undefined);
54
- assert(header.close_flags !== undefined);
55
-
56
- types.UInt32.from(header.ledger_index).toBytesSink(hash);
57
- types.UInt64.from(new BN(header.total_coins)).toBytesSink(hash);
58
- types.Hash256.from(header.parent_hash).toBytesSink(hash);
59
- types.Hash256.from(header.transaction_hash).toBytesSink(hash);
60
- types.Hash256.from(header.account_hash).toBytesSink(hash);
61
- types.UInt32.from(header.parent_close_time).toBytesSink(hash);
62
- types.UInt32.from(header.close_time).toBytesSink(hash);
63
- types.UInt8.from(header.close_time_resolution).toBytesSink(hash);
64
- types.UInt8.from(header.close_flags).toBytesSink(hash);
65
- return hash.finish();
66
- }
67
-
68
- module.exports = {
69
- accountStateHash: accountStateHash,
70
- transactionTreeHash: transactionTreeHash,
71
- ledgerHash: ledgerHash };
@@ -1,20 +0,0 @@
1
- 'use strict';var Decimal = require('decimal.js');var _require =
2
- require('./utils/bytes-utils'),bytesToHex = _require.bytesToHex,slice = _require.slice,parseBytes = _require.parseBytes;var _require2 =
3
- require('./types'),UInt64 = _require2.UInt64;
4
- var BN = require('bn.js');
5
-
6
- module.exports = {
7
- encode: function encode(arg) {
8
- var quality = arg instanceof Decimal ? arg : new Decimal(arg);
9
- var exponent = quality.e - 15;
10
- var qualityString = quality.times('1e' + -exponent).abs().toString();
11
- var bytes = new UInt64(new BN(qualityString)).toBytes();
12
- bytes[0] = exponent + 100;
13
- return bytes;
14
- },
15
- decode: function decode(arg) {
16
- var bytes = slice(parseBytes(arg), -8);
17
- var exponent = bytes[0] - 100;
18
- var mantissa = new Decimal('0x' + bytesToHex(slice(bytes, 1)));
19
- return mantissa.times('1e' + exponent);
20
- } };