@transia/ripple-binary-codec 1.4.6-alpha.9 → 2.5.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/dist/binary.d.ts +30 -16
  2. package/dist/binary.js +36 -16
  3. package/dist/binary.js.map +1 -1
  4. package/dist/enums/bytes.d.ts +1 -2
  5. package/dist/enums/bytes.js +3 -2
  6. package/dist/enums/bytes.js.map +1 -1
  7. package/dist/enums/constants.d.ts +1 -0
  8. package/dist/enums/constants.js +6 -5
  9. package/dist/enums/constants.js.map +1 -1
  10. package/dist/enums/definitions.json +1604 -969
  11. package/dist/enums/field.d.ts +1 -2
  12. package/dist/enums/field.js +1 -2
  13. package/dist/enums/field.js.map +1 -1
  14. package/dist/enums/index.d.ts +1 -2
  15. package/dist/enums/index.js +5 -27
  16. package/dist/enums/index.js.map +1 -1
  17. package/dist/enums/src/enums/definitions.json +1606 -971
  18. package/dist/enums/xrpl-definitions-base.d.ts +5 -3
  19. package/dist/enums/xrpl-definitions-base.js +26 -6
  20. package/dist/enums/xrpl-definitions-base.js.map +1 -1
  21. package/dist/enums/xrpl-definitions.d.ts +2 -1
  22. package/dist/enums/xrpl-definitions.js +2 -1
  23. package/dist/enums/xrpl-definitions.js.map +1 -1
  24. package/dist/hash-prefixes.d.ts +1 -2
  25. package/dist/hash-prefixes.js +8 -6
  26. package/dist/hash-prefixes.js.map +1 -1
  27. package/dist/hashes.d.ts +6 -7
  28. package/dist/hashes.js +6 -7
  29. package/dist/hashes.js.map +1 -1
  30. package/dist/index.d.ts +16 -11
  31. package/dist/index.js +53 -58
  32. package/dist/index.js.map +1 -1
  33. package/dist/ledger-hashes.d.ts +1 -2
  34. package/dist/ledger-hashes.js +11 -30
  35. package/dist/ledger-hashes.js.map +1 -1
  36. package/dist/quality.d.ts +3 -4
  37. package/dist/quality.js +10 -8
  38. package/dist/quality.js.map +1 -1
  39. package/dist/serdes/binary-parser.d.ts +2 -3
  40. package/dist/serdes/binary-parser.js +16 -32
  41. package/dist/serdes/binary-parser.js.map +1 -1
  42. package/dist/serdes/binary-serializer.d.ts +7 -8
  43. package/dist/serdes/binary-serializer.js +14 -37
  44. package/dist/serdes/binary-serializer.js.map +1 -1
  45. package/dist/shamap.d.ts +4 -5
  46. package/dist/shamap.js +5 -5
  47. package/dist/shamap.js.map +1 -1
  48. package/dist/src/binary.d.ts +106 -0
  49. package/dist/src/binary.js +154 -0
  50. package/dist/src/binary.js.map +1 -0
  51. package/dist/src/coretypes.d.ts +9 -0
  52. package/dist/src/coretypes.js +48 -0
  53. package/dist/src/coretypes.js.map +1 -0
  54. package/dist/src/enums/bytes.d.ts +25 -0
  55. package/dist/src/enums/bytes.js +65 -0
  56. package/dist/src/enums/bytes.js.map +1 -0
  57. package/dist/src/enums/constants.d.ts +5 -0
  58. package/dist/src/enums/constants.js +9 -0
  59. package/dist/src/enums/constants.js.map +1 -0
  60. package/dist/src/enums/definitions.json +3404 -0
  61. package/dist/src/enums/field.d.ts +28 -0
  62. package/dist/src/enums/field.js +58 -0
  63. package/dist/src/enums/field.js.map +1 -0
  64. package/dist/src/enums/index.d.ts +12 -0
  65. package/dist/src/enums/index.js +31 -0
  66. package/dist/src/enums/index.js.map +1 -0
  67. package/dist/src/enums/utils-renumber.d.ts +101 -0
  68. package/dist/src/enums/utils-renumber.js +127 -0
  69. package/dist/src/enums/utils-renumber.js.map +1 -0
  70. package/dist/src/enums/xrpl-definitions-base.d.ts +47 -0
  71. package/dist/src/enums/xrpl-definitions-base.js +83 -0
  72. package/dist/src/enums/xrpl-definitions-base.js.map +1 -0
  73. package/dist/src/enums/xrpl-definitions.d.ts +22 -0
  74. package/dist/src/enums/xrpl-definitions.js +30 -0
  75. package/dist/src/enums/xrpl-definitions.js.map +1 -0
  76. package/dist/src/hash-prefixes.d.ts +5 -0
  77. package/dist/src/hash-prefixes.js +43 -0
  78. package/dist/src/hash-prefixes.js.map +1 -0
  79. package/dist/src/hashes.d.ts +50 -0
  80. package/dist/src/hashes.js +76 -0
  81. package/dist/src/hashes.js.map +1 -0
  82. package/dist/src/index.d.ts +69 -0
  83. package/dist/src/index.js +134 -0
  84. package/dist/src/index.js.map +1 -0
  85. package/dist/src/ledger-hashes.d.ts +48 -0
  86. package/dist/src/ledger-hashes.js +141 -0
  87. package/dist/src/ledger-hashes.js.map +1 -0
  88. package/dist/src/quality.d.ts +21 -0
  89. package/dist/src/quality.js +42 -0
  90. package/dist/src/quality.js.map +1 -0
  91. package/dist/src/serdes/binary-parser.d.ts +100 -0
  92. package/dist/src/serdes/binary-parser.js +194 -0
  93. package/dist/src/serdes/binary-parser.js.map +1 -0
  94. package/dist/src/serdes/binary-serializer.d.ts +81 -0
  95. package/dist/src/serdes/binary-serializer.js +149 -0
  96. package/dist/src/serdes/binary-serializer.js.map +1 -0
  97. package/dist/src/shamap.d.ts +102 -0
  98. package/dist/src/shamap.js +172 -0
  99. package/dist/src/shamap.js.map +1 -0
  100. package/dist/src/types/account-id.d.ts +37 -0
  101. package/dist/src/types/account-id.js +73 -0
  102. package/dist/src/types/account-id.js.map +1 -0
  103. package/dist/src/types/amount.d.ts +92 -0
  104. package/dist/src/types/amount.js +292 -0
  105. package/dist/src/types/amount.js.map +1 -0
  106. package/dist/src/types/blob.d.ts +25 -0
  107. package/dist/src/types/blob.js +46 -0
  108. package/dist/src/types/blob.js.map +1 -0
  109. package/dist/src/types/currency.d.ts +30 -0
  110. package/dist/src/types/currency.js +131 -0
  111. package/dist/src/types/currency.js.map +1 -0
  112. package/dist/src/types/data.d.ts +104 -0
  113. package/dist/src/types/data.js +387 -0
  114. package/dist/src/types/data.js.map +1 -0
  115. package/dist/src/types/dataType.d.ts +94 -0
  116. package/dist/src/types/dataType.js +145 -0
  117. package/dist/src/types/dataType.js.map +1 -0
  118. package/dist/src/types/hash-128.d.ts +18 -0
  119. package/dist/src/types/hash-128.js +36 -0
  120. package/dist/src/types/hash-128.js.map +1 -0
  121. package/dist/src/types/hash-160.d.ts +12 -0
  122. package/dist/src/types/hash-160.js +23 -0
  123. package/dist/src/types/hash-160.js.map +1 -0
  124. package/dist/src/types/hash-192.d.ts +12 -0
  125. package/dist/src/types/hash-192.js +23 -0
  126. package/dist/src/types/hash-192.js.map +1 -0
  127. package/dist/src/types/hash-256.d.ts +12 -0
  128. package/dist/src/types/hash-256.js +20 -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 +76 -0
  132. package/dist/src/types/hash.js.map +1 -0
  133. package/dist/src/types/index.d.ts +21 -0
  134. package/dist/src/types/index.js +72 -0
  135. package/dist/src/types/index.js.map +1 -0
  136. package/dist/src/types/issue.d.ts +49 -0
  137. package/dist/src/types/issue.js +107 -0
  138. package/dist/src/types/issue.js.map +1 -0
  139. package/dist/src/types/json.d.ts +169 -0
  140. package/dist/src/types/json.js +529 -0
  141. package/dist/src/types/json.js.map +1 -0
  142. package/dist/src/types/path-set.d.ts +37 -0
  143. package/dist/src/types/path-set.js +236 -0
  144. package/dist/src/types/path-set.js.map +1 -0
  145. package/dist/src/types/serialized-type.d.ts +117 -0
  146. package/dist/src/types/serialized-type.js +242 -0
  147. package/dist/src/types/serialized-type.js.map +1 -0
  148. package/dist/src/types/st-array.d.ts +32 -0
  149. package/dist/src/types/st-array.js +89 -0
  150. package/dist/src/types/st-array.js.map +1 -0
  151. package/dist/src/types/st-number.d.ts +55 -0
  152. package/dist/src/types/st-number.js +212 -0
  153. package/dist/src/types/st-number.js.map +1 -0
  154. package/dist/src/types/st-object.d.ts +33 -0
  155. package/dist/src/types/st-object.js +176 -0
  156. package/dist/src/types/st-object.js.map +1 -0
  157. package/dist/src/types/uint-16.d.ts +26 -0
  158. package/dist/src/types/uint-16.js +49 -0
  159. package/dist/src/types/uint-16.js.map +1 -0
  160. package/dist/src/types/uint-32.d.ts +26 -0
  161. package/dist/src/types/uint-32.js +54 -0
  162. package/dist/src/types/uint-32.js.map +1 -0
  163. package/dist/src/types/uint-64.d.ts +40 -0
  164. package/dist/src/types/uint-64.js +112 -0
  165. package/dist/src/types/uint-64.js.map +1 -0
  166. package/dist/src/types/uint-8.d.ts +26 -0
  167. package/dist/src/types/uint-8.js +50 -0
  168. package/dist/src/types/uint-8.js.map +1 -0
  169. package/dist/src/types/uint.d.ts +29 -0
  170. package/dist/src/types/uint.js +47 -0
  171. package/dist/src/types/uint.js.map +1 -0
  172. package/dist/src/types/vector-256.d.ts +31 -0
  173. package/dist/src/types/vector-256.js +76 -0
  174. package/dist/src/types/vector-256.js.map +1 -0
  175. package/dist/src/types/xchain-bridge.d.ts +45 -0
  176. package/dist/src/types/xchain-bridge.js +105 -0
  177. package/dist/src/types/xchain-bridge.js.map +1 -0
  178. package/dist/src/utils.d.ts +79 -0
  179. package/dist/src/utils.js +181 -0
  180. package/dist/src/utils.js.map +1 -0
  181. package/dist/tsconfig.tsbuildinfo +1 -0
  182. package/dist/types/account-id.d.ts +3 -2
  183. package/dist/types/account-id.js +8 -6
  184. package/dist/types/account-id.js.map +1 -1
  185. package/dist/types/amount.d.ts +33 -9
  186. package/dist/types/amount.js +128 -43
  187. package/dist/types/amount.js.map +1 -1
  188. package/dist/types/blob.d.ts +3 -3
  189. package/dist/types/blob.js +8 -2
  190. package/dist/types/blob.js.map +1 -1
  191. package/dist/types/currency.d.ts +3 -2
  192. package/dist/types/currency.js +17 -13
  193. package/dist/types/currency.js.map +1 -1
  194. package/dist/types/data.d.ts +104 -0
  195. package/dist/types/data.js +387 -0
  196. package/dist/types/data.js.map +1 -0
  197. package/dist/types/dataType.d.ts +94 -0
  198. package/dist/types/dataType.js +145 -0
  199. package/dist/types/dataType.js.map +1 -0
  200. package/dist/types/hash-128.d.ts +3 -2
  201. package/dist/types/hash-128.js +7 -3
  202. package/dist/types/hash-128.js.map +1 -1
  203. package/dist/types/hash-160.d.ts +3 -2
  204. package/dist/types/hash-160.js +5 -2
  205. package/dist/types/hash-160.js.map +1 -1
  206. package/dist/types/hash-192.d.ts +12 -0
  207. package/dist/types/hash-192.js +23 -0
  208. package/dist/types/hash-192.js.map +1 -0
  209. package/dist/types/hash-256.d.ts +3 -2
  210. package/dist/types/hash-256.js +5 -2
  211. package/dist/types/hash-256.js.map +1 -1
  212. package/dist/types/hash.d.ts +2 -3
  213. package/dist/types/hash.js +8 -4
  214. package/dist/types/hash.js.map +1 -1
  215. package/dist/types/index.d.ts +4 -1
  216. package/dist/types/index.js +17 -2
  217. package/dist/types/index.js.map +1 -1
  218. package/dist/types/issue.d.ts +49 -0
  219. package/dist/types/issue.js +107 -0
  220. package/dist/types/issue.js.map +1 -0
  221. package/dist/types/json.d.ts +169 -0
  222. package/dist/types/json.js +529 -0
  223. package/dist/types/json.js.map +1 -0
  224. package/dist/types/path-set.d.ts +2 -1
  225. package/dist/types/path-set.js +15 -12
  226. package/dist/types/path-set.js.map +1 -1
  227. package/dist/types/serialized-type.d.ts +70 -16
  228. package/dist/types/serialized-type.js +153 -8
  229. package/dist/types/serialized-type.js.map +1 -1
  230. package/dist/types/st-array.d.ts +7 -3
  231. package/dist/types/st-array.js +20 -11
  232. package/dist/types/st-array.js.map +1 -1
  233. package/dist/types/st-number.d.ts +55 -0
  234. package/dist/types/st-number.js +212 -0
  235. package/dist/types/st-number.js.map +1 -0
  236. package/dist/types/st-object.d.ts +2 -1
  237. package/dist/types/st-object.js +35 -8
  238. package/dist/types/st-object.js.map +1 -1
  239. package/dist/types/uint-16.d.ts +3 -2
  240. package/dist/types/uint-16.js +10 -5
  241. package/dist/types/uint-16.js.map +1 -1
  242. package/dist/types/uint-32.d.ts +3 -2
  243. package/dist/types/uint-32.js +11 -6
  244. package/dist/types/uint-32.js.map +1 -1
  245. package/dist/types/uint-64.d.ts +8 -7
  246. package/dist/types/uint-64.js +49 -24
  247. package/dist/types/uint-64.js.map +1 -1
  248. package/dist/types/uint-8.d.ts +3 -2
  249. package/dist/types/uint-8.js +11 -5
  250. package/dist/types/uint-8.js.map +1 -1
  251. package/dist/types/uint.d.ts +5 -6
  252. package/dist/types/uint.js +5 -0
  253. package/dist/types/uint.js.map +1 -1
  254. package/dist/types/vector-256.d.ts +3 -3
  255. package/dist/types/vector-256.js +5 -4
  256. package/dist/types/vector-256.js.map +1 -1
  257. package/dist/types/xchain-bridge.d.ts +45 -0
  258. package/dist/types/xchain-bridge.js +105 -0
  259. package/dist/types/xchain-bridge.js.map +1 -0
  260. package/dist/utils.d.ts +79 -0
  261. package/dist/utils.js +181 -0
  262. package/dist/utils.js.map +1 -0
  263. package/package.json +21 -17
  264. package/src/README.md +5 -0
  265. package/src/binary.ts +235 -0
  266. package/src/coretypes.ts +31 -0
  267. package/src/enums/README.md +144 -0
  268. package/src/enums/bytes.ts +80 -0
  269. package/src/enums/constants.ts +5 -0
  270. package/src/enums/definitions.json +3409 -0
  271. package/src/enums/field.ts +84 -0
  272. package/src/enums/index.ts +34 -0
  273. package/src/enums/utils-renumber.ts +134 -0
  274. package/src/enums/xrpl-definitions-base.ts +150 -0
  275. package/src/enums/xrpl-definitions.ts +33 -0
  276. package/src/hash-prefixes.ts +42 -0
  277. package/src/hashes.ts +75 -0
  278. package/src/index.ts +166 -0
  279. package/src/ledger-hashes.ts +191 -0
  280. package/src/quality.ts +38 -0
  281. package/src/serdes/binary-parser.ts +228 -0
  282. package/src/serdes/binary-serializer.ts +166 -0
  283. package/src/shamap.ts +189 -0
  284. package/src/types/account-id.ts +91 -0
  285. package/src/types/amount.ts +366 -0
  286. package/src/types/blob.ts +50 -0
  287. package/src/types/currency.ts +145 -0
  288. package/src/types/data.ts +496 -0
  289. package/src/types/dataType.ts +178 -0
  290. package/src/types/hash-128.ts +38 -0
  291. package/src/types/hash-160.ts +24 -0
  292. package/src/types/hash-192.ts +24 -0
  293. package/src/types/hash-256.ts +20 -0
  294. package/src/types/hash.ts +86 -0
  295. package/src/types/index.ts +74 -0
  296. package/src/types/issue.ts +140 -0
  297. package/src/types/json.ts +641 -0
  298. package/src/types/path-set.ts +294 -0
  299. package/src/types/serialized-type.ts +271 -0
  300. package/src/types/st-array.ts +117 -0
  301. package/src/types/st-number.ts +238 -0
  302. package/src/types/st-object.ts +219 -0
  303. package/src/types/uint-16.ts +58 -0
  304. package/src/types/uint-32.ts +64 -0
  305. package/src/types/uint-64.ts +141 -0
  306. package/src/types/uint-8.ts +57 -0
  307. package/src/types/uint.ts +60 -0
  308. package/src/types/vector-256.ts +83 -0
  309. package/src/types/xchain-bridge.ts +132 -0
  310. package/src/utils.ts +220 -0
  311. package/test/amount.test.js +0 -43
  312. package/test/binary-json.test.js +0 -45
  313. package/test/binary-parser.test.js +0 -396
  314. package/test/binary-serializer.test.js +0 -319
  315. package/test/definitions.test.js +0 -100
  316. package/test/fixtures/account-tx-transactions.db +0 -0
  317. package/test/fixtures/codec-fixtures.json +0 -4466
  318. package/test/fixtures/data-driven-tests.json +0 -2919
  319. package/test/fixtures/delivermin-tx-binary.json +0 -1
  320. package/test/fixtures/delivermin-tx.json +0 -98
  321. package/test/fixtures/deposit-preauth-tx-binary.json +0 -1
  322. package/test/fixtures/deposit-preauth-tx-meta-binary.json +0 -1
  323. package/test/fixtures/deposit-preauth-tx.json +0 -58
  324. package/test/fixtures/escrow-cancel-binary.json +0 -1
  325. package/test/fixtures/escrow-cancel-tx.json +0 -6
  326. package/test/fixtures/escrow-create-binary.json +0 -1
  327. package/test/fixtures/escrow-create-tx.json +0 -10
  328. package/test/fixtures/escrow-finish-binary.json +0 -1
  329. package/test/fixtures/escrow-finish-meta-binary.json +0 -1
  330. package/test/fixtures/escrow-finish-tx.json +0 -95
  331. package/test/fixtures/ledger-full-38129.json +0 -1
  332. package/test/fixtures/ledger-full-40000.json +0 -1
  333. package/test/fixtures/negative-unl.json +0 -12
  334. package/test/fixtures/nf-token.json +0 -547
  335. package/test/fixtures/payment-channel-claim-binary.json +0 -1
  336. package/test/fixtures/payment-channel-claim-tx.json +0 -8
  337. package/test/fixtures/payment-channel-create-binary.json +0 -1
  338. package/test/fixtures/payment-channel-create-tx.json +0 -11
  339. package/test/fixtures/payment-channel-fund-binary.json +0 -1
  340. package/test/fixtures/payment-channel-fund-tx.json +0 -7
  341. package/test/fixtures/remit-binary.json +0 -1
  342. package/test/fixtures/remit-tx.json +0 -39
  343. package/test/fixtures/signerlistset-tx-binary.json +0 -1
  344. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  345. package/test/fixtures/signerlistset-tx.json +0 -94
  346. package/test/fixtures/ticket-create-binary.json +0 -1
  347. package/test/fixtures/ticket-create-tx.json +0 -7
  348. package/test/fixtures/unl-report-binary.json +0 -1
  349. package/test/fixtures/unl-report-meta-binary.json +0 -1
  350. package/test/fixtures/unl-report.json +0 -89
  351. package/test/fixtures/x-codec-fixtures.json +0 -188
  352. package/test/hash.test.js +0 -135
  353. package/test/ledger.test.js +0 -29
  354. package/test/lower-case-hex.test.js +0 -46
  355. package/test/pseudo-transaction.test.js +0 -38
  356. package/test/quality.test.js +0 -15
  357. package/test/shamap.test.js +0 -89
  358. package/test/signing-data-encoding.test.js +0 -213
  359. package/test/tx-encode-decode.test.js +0 -119
  360. package/test/types.test.js +0 -34
  361. package/test/uint.test.js +0 -148
  362. package/test/utils.js +0 -30
  363. package/test/x-address.test.js +0 -181
@@ -0,0 +1,50 @@
1
+ import { Hash256 } from './types';
2
+ import { BytesList } from './serdes/binary-serializer';
3
+ /**
4
+ * Class for hashing with SHA512
5
+ * @extends BytesList So SerializedTypes can write bytes to a Sha512Half
6
+ */
7
+ declare class Sha512Half extends BytesList {
8
+ private hash;
9
+ /**
10
+ * Construct a new Sha512Hash and write bytes this.hash
11
+ *
12
+ * @param bytes bytes to write to this.hash
13
+ * @returns the new Sha512Hash object
14
+ */
15
+ static put(bytes: Uint8Array): Sha512Half;
16
+ /**
17
+ * Write bytes to an existing Sha512Hash
18
+ *
19
+ * @param bytes bytes to write to object
20
+ * @returns the Sha512 object
21
+ */
22
+ put(bytes: Uint8Array): Sha512Half;
23
+ /**
24
+ * Compute SHA512 hash and slice in half
25
+ *
26
+ * @returns half of a SHA512 hash
27
+ */
28
+ finish256(): Uint8Array;
29
+ /**
30
+ * Constructs a Hash256 from the Sha512Half object
31
+ *
32
+ * @returns a Hash256 object
33
+ */
34
+ finish(): Hash256;
35
+ }
36
+ /**
37
+ * compute SHA512 hash of a list of bytes
38
+ *
39
+ * @param args zero or more arguments to hash
40
+ * @returns the sha512half hash of the arguments.
41
+ */
42
+ declare function sha512Half(...args: Uint8Array[]): Uint8Array;
43
+ /**
44
+ * Construct a transactionID from a Serialized Transaction
45
+ *
46
+ * @param serialized bytes to hash
47
+ * @returns a Hash256 object
48
+ */
49
+ declare function transactionID(serialized: Uint8Array): Hash256;
50
+ export { Sha512Half, sha512Half, transactionID };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transactionID = exports.sha512Half = exports.Sha512Half = void 0;
4
+ const hash_prefixes_1 = require("./hash-prefixes");
5
+ const types_1 = require("./types");
6
+ const binary_serializer_1 = require("./serdes/binary-serializer");
7
+ const sha512_1 = require("@transia/isomorphic/sha512");
8
+ /**
9
+ * Class for hashing with SHA512
10
+ * @extends BytesList So SerializedTypes can write bytes to a Sha512Half
11
+ */
12
+ class Sha512Half extends binary_serializer_1.BytesList {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.hash = sha512_1.sha512.create();
16
+ }
17
+ /**
18
+ * Construct a new Sha512Hash and write bytes this.hash
19
+ *
20
+ * @param bytes bytes to write to this.hash
21
+ * @returns the new Sha512Hash object
22
+ */
23
+ static put(bytes) {
24
+ return new Sha512Half().put(bytes);
25
+ }
26
+ /**
27
+ * Write bytes to an existing Sha512Hash
28
+ *
29
+ * @param bytes bytes to write to object
30
+ * @returns the Sha512 object
31
+ */
32
+ put(bytes) {
33
+ this.hash.update(bytes);
34
+ return this;
35
+ }
36
+ /**
37
+ * Compute SHA512 hash and slice in half
38
+ *
39
+ * @returns half of a SHA512 hash
40
+ */
41
+ finish256() {
42
+ return Uint8Array.from(this.hash.digest().slice(0, 32));
43
+ }
44
+ /**
45
+ * Constructs a Hash256 from the Sha512Half object
46
+ *
47
+ * @returns a Hash256 object
48
+ */
49
+ finish() {
50
+ return new types_1.Hash256(this.finish256());
51
+ }
52
+ }
53
+ exports.Sha512Half = Sha512Half;
54
+ /**
55
+ * compute SHA512 hash of a list of bytes
56
+ *
57
+ * @param args zero or more arguments to hash
58
+ * @returns the sha512half hash of the arguments.
59
+ */
60
+ function sha512Half(...args) {
61
+ const hash = new Sha512Half();
62
+ args.forEach((a) => hash.put(a));
63
+ return hash.finish256();
64
+ }
65
+ exports.sha512Half = sha512Half;
66
+ /**
67
+ * Construct a transactionID from a Serialized Transaction
68
+ *
69
+ * @param serialized bytes to hash
70
+ * @returns a Hash256 object
71
+ */
72
+ function transactionID(serialized) {
73
+ return new types_1.Hash256(sha512Half(hash_prefixes_1.HashPrefix.transactionID, serialized));
74
+ }
75
+ exports.transactionID = transactionID;
76
+ //# sourceMappingURL=hashes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src/hashes.ts"],"names":[],"mappings":";;;AAAA,mDAA4C;AAC5C,mCAAiC;AACjC,kEAAsD;AACtD,uDAAmD;AAEnD;;;GAGG;AACH,MAAM,UAAW,SAAQ,6BAAS;IAAlC;;QACU,SAAI,GAAG,eAAM,CAAC,MAAM,EAAE,CAAA;IAwChC,CAAC;IAtCC;;;;;OAKG;IACH,MAAM,CAAC,GAAG,CAAC,KAAiB;QAC1B,OAAO,IAAI,UAAU,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,KAAiB;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACvB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACzD,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,IAAI,eAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;IACtC,CAAC;CACF;AAwBQ,gCAAU;AAtBnB;;;;;GAKG;AACH,SAAS,UAAU,CAAC,GAAG,IAAkB;IACvC,MAAM,IAAI,GAAG,IAAI,UAAU,EAAE,CAAA;IAC7B,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAChC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAA;AACzB,CAAC;AAYoB,gCAAU;AAV/B;;;;;GAKG;AACH,SAAS,aAAa,CAAC,UAAsB;IAC3C,OAAO,IAAI,eAAO,CAAC,UAAU,CAAC,0BAAU,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAA;AACtE,CAAC;AAEgC,sCAAa"}
@@ -0,0 +1,69 @@
1
+ import { decodeLedgerData } from './ledger-hashes';
2
+ import { JsonObject } from './types/serialized-type';
3
+ import { XrplDefinitionsBase, TRANSACTION_TYPES, DEFAULT_DEFINITIONS } from './enums';
4
+ import { XrplDefinitions } from './enums/xrpl-definitions';
5
+ import { coreTypes } from './types';
6
+ /**
7
+ * Decode a transaction
8
+ *
9
+ * @param binary hex-string of the encoded transaction
10
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
11
+ * @returns the JSON representation of the transaction
12
+ */
13
+ declare function decode(binary: string, definitions?: XrplDefinitionsBase): JsonObject;
14
+ /**
15
+ * Encode a transaction
16
+ *
17
+ * @param json The JSON representation of a transaction
18
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
19
+ *
20
+ * @returns A hex-string of the encoded transaction
21
+ */
22
+ declare function encode(json: object, definitions?: XrplDefinitionsBase): string;
23
+ /**
24
+ * Encode a transaction and prepare for signing
25
+ *
26
+ * @param json JSON object representing the transaction
27
+ * @param signer string representing the account to sign the transaction with
28
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
29
+ * @returns a hex string of the encoded transaction
30
+ */
31
+ declare function encodeForSigning(json: object, definitions?: XrplDefinitionsBase): string;
32
+ /**
33
+ * Encode a payment channel claim for signing.
34
+ *
35
+ * @param json JSON object representing the claim.
36
+ * @returns a hex string of the encoded claim.
37
+ */
38
+ declare function encodeForSigningClaim(json: object): string;
39
+ /**
40
+ * Encode a transaction and prepare for multi-signing.
41
+ *
42
+ * @param json JSON object representing the transaction.
43
+ * @param signer string representing the account to sign the transaction with.
44
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
45
+ * @returns a hex string of the encoded transaction.
46
+ */
47
+ declare function encodeForMultisigning(json: object, signer: string, definitions?: XrplDefinitionsBase): string;
48
+ /**
49
+ * Encode a Batch transaction for signing.
50
+ *
51
+ * @param json JSON object representing the transaction.
52
+ * @returns a hex string of the encoded transaction.
53
+ */
54
+ declare function encodeForSigningBatch(json: object): string;
55
+ /**
56
+ * Encode a quality value
57
+ *
58
+ * @param value string representation of a number
59
+ * @returns a hex-string representing the quality
60
+ */
61
+ declare function encodeQuality(value: string): string;
62
+ /**
63
+ * Decode a quality value
64
+ *
65
+ * @param value hex-string of a quality
66
+ * @returns a string representing the quality
67
+ */
68
+ declare function decodeQuality(value: string): string;
69
+ export { decode, encode, encodeForSigning, encodeForSigningClaim, encodeForMultisigning, encodeForSigningBatch, encodeQuality, decodeQuality, decodeLedgerData, TRANSACTION_TYPES, XrplDefinitions, XrplDefinitionsBase, DEFAULT_DEFINITIONS, coreTypes, };
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.coreTypes = exports.DEFAULT_DEFINITIONS = exports.XrplDefinitionsBase = exports.XrplDefinitions = exports.TRANSACTION_TYPES = exports.decodeLedgerData = exports.decodeQuality = exports.encodeQuality = exports.encodeForSigningBatch = exports.encodeForMultisigning = exports.encodeForSigningClaim = exports.encodeForSigning = exports.encode = exports.decode = void 0;
4
+ const coretypes_1 = require("./coretypes");
5
+ const ledger_hashes_1 = require("./ledger-hashes");
6
+ Object.defineProperty(exports, "decodeLedgerData", { enumerable: true, get: function () { return ledger_hashes_1.decodeLedgerData; } });
7
+ const enums_1 = require("./enums");
8
+ Object.defineProperty(exports, "XrplDefinitionsBase", { enumerable: true, get: function () { return enums_1.XrplDefinitionsBase; } });
9
+ Object.defineProperty(exports, "TRANSACTION_TYPES", { enumerable: true, get: function () { return enums_1.TRANSACTION_TYPES; } });
10
+ Object.defineProperty(exports, "DEFAULT_DEFINITIONS", { enumerable: true, get: function () { return enums_1.DEFAULT_DEFINITIONS; } });
11
+ const xrpl_definitions_1 = require("./enums/xrpl-definitions");
12
+ Object.defineProperty(exports, "XrplDefinitions", { enumerable: true, get: function () { return xrpl_definitions_1.XrplDefinitions; } });
13
+ const types_1 = require("./types");
14
+ Object.defineProperty(exports, "coreTypes", { enumerable: true, get: function () { return types_1.coreTypes; } });
15
+ const utils_1 = require("@transia/isomorphic/utils");
16
+ const { signingData, signingClaimData, multiSigningData, signingBatchData, binaryToJSON, serializeObject, } = coretypes_1.binary;
17
+ /**
18
+ * Decode a transaction
19
+ *
20
+ * @param binary hex-string of the encoded transaction
21
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
22
+ * @returns the JSON representation of the transaction
23
+ */
24
+ function decode(binary, definitions) {
25
+ if (typeof binary !== 'string') {
26
+ throw new Error('binary must be a hex string');
27
+ }
28
+ return binaryToJSON(binary, definitions);
29
+ }
30
+ exports.decode = decode;
31
+ /**
32
+ * Encode a transaction
33
+ *
34
+ * @param json The JSON representation of a transaction
35
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
36
+ *
37
+ * @returns A hex-string of the encoded transaction
38
+ */
39
+ function encode(json, definitions) {
40
+ if (typeof json !== 'object') {
41
+ throw new Error();
42
+ }
43
+ return (0, utils_1.bytesToHex)(serializeObject(json, { definitions }));
44
+ }
45
+ exports.encode = encode;
46
+ /**
47
+ * Encode a transaction and prepare for signing
48
+ *
49
+ * @param json JSON object representing the transaction
50
+ * @param signer string representing the account to sign the transaction with
51
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
52
+ * @returns a hex string of the encoded transaction
53
+ */
54
+ function encodeForSigning(json, definitions) {
55
+ if (typeof json !== 'object') {
56
+ throw new Error();
57
+ }
58
+ return (0, utils_1.bytesToHex)(signingData(json, coretypes_1.HashPrefix.transactionSig, {
59
+ definitions,
60
+ }));
61
+ }
62
+ exports.encodeForSigning = encodeForSigning;
63
+ /**
64
+ * Encode a payment channel claim for signing.
65
+ *
66
+ * @param json JSON object representing the claim.
67
+ * @returns a hex string of the encoded claim.
68
+ */
69
+ function encodeForSigningClaim(json) {
70
+ if (typeof json !== 'object') {
71
+ throw new Error();
72
+ }
73
+ return (0, utils_1.bytesToHex)(signingClaimData(json));
74
+ }
75
+ exports.encodeForSigningClaim = encodeForSigningClaim;
76
+ /**
77
+ * Encode a transaction and prepare for multi-signing.
78
+ *
79
+ * @param json JSON object representing the transaction.
80
+ * @param signer string representing the account to sign the transaction with.
81
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
82
+ * @returns a hex string of the encoded transaction.
83
+ */
84
+ function encodeForMultisigning(json, signer, definitions) {
85
+ if (typeof json !== 'object') {
86
+ throw new Error();
87
+ }
88
+ if (json['SigningPubKey'] !== '') {
89
+ throw new Error();
90
+ }
91
+ const definitionsOpt = definitions ? { definitions } : undefined;
92
+ return (0, utils_1.bytesToHex)(multiSigningData(json, signer, definitionsOpt));
93
+ }
94
+ exports.encodeForMultisigning = encodeForMultisigning;
95
+ /**
96
+ * Encode a Batch transaction for signing.
97
+ *
98
+ * @param json JSON object representing the transaction.
99
+ * @returns a hex string of the encoded transaction.
100
+ */
101
+ function encodeForSigningBatch(json) {
102
+ if (typeof json !== 'object') {
103
+ throw new Error('Need an object to encode a Batch transaction');
104
+ }
105
+ return (0, utils_1.bytesToHex)(signingBatchData(json));
106
+ }
107
+ exports.encodeForSigningBatch = encodeForSigningBatch;
108
+ /**
109
+ * Encode a quality value
110
+ *
111
+ * @param value string representation of a number
112
+ * @returns a hex-string representing the quality
113
+ */
114
+ function encodeQuality(value) {
115
+ if (typeof value !== 'string') {
116
+ throw new Error();
117
+ }
118
+ return (0, utils_1.bytesToHex)(coretypes_1.quality.encode(value));
119
+ }
120
+ exports.encodeQuality = encodeQuality;
121
+ /**
122
+ * Decode a quality value
123
+ *
124
+ * @param value hex-string of a quality
125
+ * @returns a string representing the quality
126
+ */
127
+ function decodeQuality(value) {
128
+ if (typeof value !== 'string') {
129
+ throw new Error();
130
+ }
131
+ return coretypes_1.quality.decode(value).toString();
132
+ }
133
+ exports.decodeQuality = decodeQuality;
134
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AACzD,mDAAkD;AA8JhD,iGA9JO,gCAAgB,OA8JP;AA3JlB,mCAIgB;AA0Jd,oGA7JA,2BAAmB,OA6JA;AAFnB,kGA1JA,yBAAiB,OA0JA;AAGjB,oGA5JA,2BAAmB,OA4JA;AA1JrB,+DAA0D;AAwJxD,gGAxJO,kCAAe,OAwJP;AAvJjB,mCAAmC;AA0JjC,0FA1JO,iBAAS,OA0JP;AAzJX,qDAAsD;AAEtD,MAAM,EACJ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,eAAe,GAChB,GAAG,kBAAM,CAAA;AAEV;;;;;;GAMG;AACH,SAAS,MAAM,CAAC,MAAc,EAAE,WAAiC;IAC/D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;K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CAAA;IAChE,OAAO,IAAA,kBAAU,EACf,gBAAgB,CAAC,IAAkB,EAAE,MAAM,EAAE,cAAc,CAAC,CAC7D,CAAA;AACH,CAAC;AA8CC,sDAAqB;AA5CvB;;;;;GAKG;AACH,SAAS,qBAAqB,CAAC,IAAY;IACzC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;IACD,OAAO,IAAA,kBAAU,EAAC,gBAAgB,CAAC,IAAmB,CAAC,CAAC,CAAA;AAC1D,CAAC;AAkCC,sDAAqB;AAhCvB;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,IAAA,kBAAU,EAAC,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAC1C,CAAC;AAsBC,sCAAa;AApBf;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,mBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAA;AACzC,CAAC;AAUC,sCAAa"}
@@ -0,0 +1,48 @@
1
+ import { Hash256 } from './types/hash-256';
2
+ import { JsonObject } from './types/serialized-type';
3
+ import { XrplDefinitionsBase } from './enums';
4
+ /**
5
+ * Function computing the hash of a transaction tree
6
+ *
7
+ * @param param An array of transaction objects to hash
8
+ * @returns A Hash256 object
9
+ */
10
+ declare function transactionTreeHash(param: Array<JsonObject>): Hash256;
11
+ /**
12
+ * Function computing the hash of accountState
13
+ *
14
+ * @param param A list of accountStates hash
15
+ * @returns A Hash256 object
16
+ */
17
+ declare function accountStateHash(param: Array<JsonObject>): Hash256;
18
+ /**
19
+ * Interface describing a ledger header
20
+ */
21
+ interface ledgerObject {
22
+ ledger_index: number;
23
+ total_coins: string | number | bigint;
24
+ parent_hash: string;
25
+ transaction_hash: string;
26
+ account_hash: string;
27
+ parent_close_time: number;
28
+ close_time: number;
29
+ close_time_resolution: number;
30
+ close_flags: number;
31
+ }
32
+ /**
33
+ * Serialize and hash a ledger header
34
+ *
35
+ * @param header a ledger header
36
+ * @returns the hash of header
37
+ */
38
+ declare function ledgerHash(header: ledgerObject): Hash256;
39
+ /**
40
+ * Decodes a serialized ledger header
41
+ *
42
+ * @param binary A serialized ledger header
43
+ * @param definitions Type definitions to parse the ledger objects.
44
+ * Used if there are non-default ledger objects to decode.
45
+ * @returns A JSON object describing a ledger header
46
+ */
47
+ declare function decodeLedgerData(binary: string, definitions?: XrplDefinitionsBase): object;
48
+ export { accountStateHash, transactionTreeHash, ledgerHash, decodeLedgerData };
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeLedgerData = exports.ledgerHash = exports.transactionTreeHash = exports.accountStateHash = void 0;
4
+ const shamap_1 = require("./shamap");
5
+ const hash_prefixes_1 = require("./hash-prefixes");
6
+ const hashes_1 = require("./hashes");
7
+ const binary_1 = require("./binary");
8
+ const hash_256_1 = require("./types/hash-256");
9
+ const st_object_1 = require("./types/st-object");
10
+ const uint_64_1 = require("./types/uint-64");
11
+ const uint_32_1 = require("./types/uint-32");
12
+ const uint_8_1 = require("./types/uint-8");
13
+ const binary_parser_1 = require("./serdes/binary-parser");
14
+ /**
15
+ * Computes the hash of a list of objects
16
+ *
17
+ * @param itemizer Converts an item into a format that can be added to SHAMap
18
+ * @param itemsJson Array of items to add to a SHAMap
19
+ * @returns the hash of the SHAMap
20
+ */
21
+ function computeHash(itemizer, itemsJson) {
22
+ const map = new shamap_1.ShaMap();
23
+ itemsJson.forEach((item) => map.addItem(...itemizer(item)));
24
+ return map.hash();
25
+ }
26
+ /**
27
+ * Convert a transaction into an index and an item
28
+ *
29
+ * @param json transaction with metadata
30
+ * @returns a tuple of index and item to be added to SHAMap
31
+ */
32
+ function transactionItemizer(json) {
33
+ if (!json.hash) {
34
+ throw new Error();
35
+ }
36
+ const index = hash_256_1.Hash256.from(json.hash);
37
+ const item = {
38
+ hashPrefix() {
39
+ return hash_prefixes_1.HashPrefix.transaction;
40
+ },
41
+ toBytesSink(sink) {
42
+ const serializer = new binary_1.BinarySerializer(sink);
43
+ serializer.writeLengthEncoded(st_object_1.STObject.from(json));
44
+ serializer.writeLengthEncoded(st_object_1.STObject.from(json.metaData));
45
+ },
46
+ };
47
+ return [index, item, undefined];
48
+ }
49
+ /**
50
+ * Convert an entry to a pair Hash256 and ShaMapNode
51
+ *
52
+ * @param json JSON describing a ledger entry item
53
+ * @returns a tuple of index and item to be added to SHAMap
54
+ */
55
+ function entryItemizer(json) {
56
+ const index = hash_256_1.Hash256.from(json.index);
57
+ const bytes = (0, binary_1.serializeObject)(json);
58
+ const item = {
59
+ hashPrefix() {
60
+ return hash_prefixes_1.HashPrefix.accountStateEntry;
61
+ },
62
+ toBytesSink(sink) {
63
+ sink.put(bytes);
64
+ },
65
+ };
66
+ return [index, item, undefined];
67
+ }
68
+ /**
69
+ * Function computing the hash of a transaction tree
70
+ *
71
+ * @param param An array of transaction objects to hash
72
+ * @returns A Hash256 object
73
+ */
74
+ function transactionTreeHash(param) {
75
+ const itemizer = transactionItemizer;
76
+ return computeHash(itemizer, param);
77
+ }
78
+ exports.transactionTreeHash = transactionTreeHash;
79
+ /**
80
+ * Function computing the hash of accountState
81
+ *
82
+ * @param param A list of accountStates hash
83
+ * @returns A Hash256 object
84
+ */
85
+ function accountStateHash(param) {
86
+ const itemizer = entryItemizer;
87
+ return computeHash(itemizer, param);
88
+ }
89
+ exports.accountStateHash = accountStateHash;
90
+ /**
91
+ * Serialize and hash a ledger header
92
+ *
93
+ * @param header a ledger header
94
+ * @returns the hash of header
95
+ */
96
+ function ledgerHash(header) {
97
+ const hash = new hashes_1.Sha512Half();
98
+ hash.put(hash_prefixes_1.HashPrefix.ledgerHeader);
99
+ if (header.parent_close_time === undefined ||
100
+ header.close_flags === undefined) {
101
+ throw new Error();
102
+ }
103
+ uint_32_1.UInt32.from(header.ledger_index).toBytesSink(hash);
104
+ uint_64_1.UInt64.from(BigInt(String(header.total_coins))).toBytesSink(hash);
105
+ hash_256_1.Hash256.from(header.parent_hash).toBytesSink(hash);
106
+ hash_256_1.Hash256.from(header.transaction_hash).toBytesSink(hash);
107
+ hash_256_1.Hash256.from(header.account_hash).toBytesSink(hash);
108
+ uint_32_1.UInt32.from(header.parent_close_time).toBytesSink(hash);
109
+ uint_32_1.UInt32.from(header.close_time).toBytesSink(hash);
110
+ uint_8_1.UInt8.from(header.close_time_resolution).toBytesSink(hash);
111
+ uint_8_1.UInt8.from(header.close_flags).toBytesSink(hash);
112
+ return hash.finish();
113
+ }
114
+ exports.ledgerHash = ledgerHash;
115
+ /**
116
+ * Decodes a serialized ledger header
117
+ *
118
+ * @param binary A serialized ledger header
119
+ * @param definitions Type definitions to parse the ledger objects.
120
+ * Used if there are non-default ledger objects to decode.
121
+ * @returns A JSON object describing a ledger header
122
+ */
123
+ function decodeLedgerData(binary, definitions) {
124
+ if (typeof binary !== 'string') {
125
+ throw new Error('binary must be a hex string');
126
+ }
127
+ const parser = new binary_parser_1.BinaryParser(binary, definitions);
128
+ return {
129
+ ledger_index: parser.readUInt32(),
130
+ total_coins: parser.readType(uint_64_1.UInt64).valueOf().toString(),
131
+ parent_hash: parser.readType(hash_256_1.Hash256).toHex(),
132
+ transaction_hash: parser.readType(hash_256_1.Hash256).toHex(),
133
+ account_hash: parser.readType(hash_256_1.Hash256).toHex(),
134
+ parent_close_time: parser.readUInt32(),
135
+ close_time: parser.readUInt32(),
136
+ close_time_resolution: parser.readUInt8(),
137
+ close_flags: parser.readUInt8(),
138
+ };
139
+ }
140
+ exports.decodeLedgerData = decodeLedgerData;
141
+ //# sourceMappingURL=ledger-hashes.js.map
@@ -0,0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,QAAQ,CAAC,kBAAO,CAAC,CAAC,KAAK,EAAE;QAClD,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,kBAAO,CAAC,CAAC,KAAK,EAAE;QAC9C,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE;QACtC,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;QAC/B,qBAAqB,EAAE,MAAM,CAAC,SAAS,EAAE;QACzC,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE;KAChC,CAAA;AACH,CAAC;AAE2D,4CAAgB"}
@@ -0,0 +1,21 @@
1
+ import BigNumber from 'bignumber.js';
2
+ /**
3
+ * class for encoding and decoding quality
4
+ */
5
+ declare class quality {
6
+ /**
7
+ * Encode quality amount
8
+ *
9
+ * @param arg string representation of an amount
10
+ * @returns Serialized quality
11
+ */
12
+ static encode(quality: string): Uint8Array;
13
+ /**
14
+ * Decode quality amount
15
+ *
16
+ * @param arg hex-string denoting serialized quality
17
+ * @returns deserialized quality
18
+ */
19
+ static decode(quality: string): BigNumber;
20
+ }
21
+ export { quality };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.quality = void 0;
7
+ const types_1 = require("./types");
8
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
9
+ const utils_1 = require("@transia/isomorphic/utils");
10
+ /**
11
+ * class for encoding and decoding quality
12
+ */
13
+ class quality {
14
+ /**
15
+ * Encode quality amount
16
+ *
17
+ * @param arg string representation of an amount
18
+ * @returns Serialized quality
19
+ */
20
+ static encode(quality) {
21
+ const decimal = (0, bignumber_js_1.default)(quality);
22
+ const exponent = ((decimal === null || decimal === void 0 ? void 0 : decimal.e) || 0) - 15;
23
+ const qualityString = decimal.times(`1e${-exponent}`).abs().toString();
24
+ const bytes = types_1.coreTypes.UInt64.from(BigInt(qualityString)).toBytes();
25
+ bytes[0] = exponent + 100;
26
+ return bytes;
27
+ }
28
+ /**
29
+ * Decode quality amount
30
+ *
31
+ * @param arg hex-string denoting serialized quality
32
+ * @returns deserialized quality
33
+ */
34
+ static decode(quality) {
35
+ const bytes = (0, utils_1.hexToBytes)(quality).slice(-8);
36
+ const exponent = bytes[0] - 100;
37
+ const mantissa = new bignumber_js_1.default(`0x${(0, utils_1.bytesToHex)(bytes.slice(1))}`);
38
+ return mantissa.times(`1e${exponent}`);
39
+ }
40
+ }
41
+ exports.quality = quality;
42
+ //# sourceMappingURL=quality.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quality.js","sourceRoot":"","sources":["../../src/quality.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AACnC,gEAAoC;AACpC,qDAAkE;AAElE;;GAEG;AACH,MAAM,OAAO;IACX;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,OAAO,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,CAAA;QAClC,MAAM,QAAQ,GAAG,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,CAAC,KAAI,CAAC,CAAC,GAAG,EAAE,CAAA;QACvC,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAA;QACtE,MAAM,KAAK,GAAG,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;QACpE,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,GAAG,CAAA;QACzB,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,OAAe;QAC3B,MAAM,KAAK,GAAG,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;QAC/B,MAAM,QAAQ,GAAG,IAAI,sBAAS,CAAC,KAAK,IAAA,kBAAU,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACjE,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAEQ,0BAAO"}