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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-parser.js","sourceRoot":"","sources":["../../src/serdes/binary-parser.ts"],"names":[],"mappings":";;;AAAA,oCAIiB;AAEjB,mDAAoD;AAEpD;;GAEG;AACH,MAAM,YAAY;IAIhB;;;;;;OAMG;IACH,YACE,QAAgB,EAChB,cAAmC,2BAAmB;QAEtD,IAAI,CAAC,KAAK,GAAG,IAAA,kBAAU,EAAC,QAAQ,CAAC,CAAA;QACjC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,IAAI,IA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IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAC7C,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,mBAAmB,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,iBAAiB,CACnE,CAAA;SACF;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;OAIG;IACH,iBAAiB;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAA;QAC9B,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;IAC5C,CAAC;CACF;AAEQ,oCAAY"}
@@ -0,0 +1,81 @@
1
+ import { FieldInstance } from '../enums';
2
+ import { type SerializedType } from '../types/serialized-type';
3
+ /**
4
+ * Bytes list is a collection of Uint8Array objects
5
+ */
6
+ declare class BytesList {
7
+ private bytesArray;
8
+ /**
9
+ * Get the total number of bytes in the BytesList
10
+ *
11
+ * @return the number of bytes
12
+ */
13
+ getLength(): number;
14
+ /**
15
+ * Put bytes in the BytesList
16
+ *
17
+ * @param bytesArg A Uint8Array
18
+ * @return this BytesList
19
+ */
20
+ put(bytesArg: Uint8Array): BytesList;
21
+ /**
22
+ * Write this BytesList to the back of another bytes list
23
+ *
24
+ * @param list The BytesList to write to
25
+ */
26
+ toBytesSink(list: BytesList): void;
27
+ toBytes(): Uint8Array;
28
+ toHex(): string;
29
+ }
30
+ /**
31
+ * BinarySerializer is used to write fields and values to Uint8Arrays
32
+ */
33
+ declare class BinarySerializer {
34
+ private sink;
35
+ constructor(sink: BytesList);
36
+ /**
37
+ * Write a value to this BinarySerializer
38
+ *
39
+ * @param value a SerializedType value
40
+ */
41
+ write(value: SerializedType): void;
42
+ /**
43
+ * Write bytes to this BinarySerializer
44
+ *
45
+ * @param bytes the bytes to write
46
+ */
47
+ put(bytes: Uint8Array): void;
48
+ /**
49
+ * Write a value of a given type to this BinarySerializer
50
+ *
51
+ * @param type the type to write
52
+ * @param value a value of that type
53
+ */
54
+ writeType(type: typeof SerializedType, value: SerializedType): void;
55
+ /**
56
+ * Write BytesList to this BinarySerializer
57
+ *
58
+ * @param bl BytesList to write to BinarySerializer
59
+ */
60
+ writeBytesList(bl: BytesList): void;
61
+ /**
62
+ * Calculate the header of Variable Length encoded bytes
63
+ *
64
+ * @param length the length of the bytes
65
+ */
66
+ private encodeVariableLength;
67
+ /**
68
+ * Write field and value to BinarySerializer
69
+ *
70
+ * @param field field to write to BinarySerializer
71
+ * @param value value to write to BinarySerializer
72
+ */
73
+ writeFieldAndValue(field: FieldInstance, value: SerializedType, isUnlModifyWorkaround?: boolean): void;
74
+ /**
75
+ * Write a variable length encoded value to the BinarySerializer
76
+ *
77
+ * @param value length encoded value to write to BytesList
78
+ */
79
+ writeLengthEncoded(value: SerializedType, isUnlModifyWorkaround?: boolean): void;
80
+ }
81
+ export { BytesList, BinarySerializer };
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinarySerializer = exports.BytesList = void 0;
4
+ const utils_1 = require("@xrplf/isomorphic/utils");
5
+ /**
6
+ * Bytes list is a collection of Uint8Array objects
7
+ */
8
+ class BytesList {
9
+ constructor() {
10
+ this.bytesArray = [];
11
+ }
12
+ /**
13
+ * Get the total number of bytes in the BytesList
14
+ *
15
+ * @return the number of bytes
16
+ */
17
+ getLength() {
18
+ return (0, utils_1.concat)(this.bytesArray).byteLength;
19
+ }
20
+ /**
21
+ * Put bytes in the BytesList
22
+ *
23
+ * @param bytesArg A Uint8Array
24
+ * @return this BytesList
25
+ */
26
+ put(bytesArg) {
27
+ const bytes = Uint8Array.from(bytesArg); // Temporary, to catch instances of Uint8Array being passed in
28
+ this.bytesArray.push(bytes);
29
+ return this;
30
+ }
31
+ /**
32
+ * Write this BytesList to the back of another bytes list
33
+ *
34
+ * @param list The BytesList to write to
35
+ */
36
+ toBytesSink(list) {
37
+ list.put(this.toBytes());
38
+ }
39
+ toBytes() {
40
+ return (0, utils_1.concat)(this.bytesArray);
41
+ }
42
+ toHex() {
43
+ return (0, utils_1.bytesToHex)(this.toBytes());
44
+ }
45
+ }
46
+ exports.BytesList = BytesList;
47
+ /**
48
+ * BinarySerializer is used to write fields and values to Uint8Arrays
49
+ */
50
+ class BinarySerializer {
51
+ constructor(sink) {
52
+ this.sink = new BytesList();
53
+ this.sink = sink;
54
+ }
55
+ /**
56
+ * Write a value to this BinarySerializer
57
+ *
58
+ * @param value a SerializedType value
59
+ */
60
+ write(value) {
61
+ value.toBytesSink(this.sink);
62
+ }
63
+ /**
64
+ * Write bytes to this BinarySerializer
65
+ *
66
+ * @param bytes the bytes to write
67
+ */
68
+ put(bytes) {
69
+ this.sink.put(bytes);
70
+ }
71
+ /**
72
+ * Write a value of a given type to this BinarySerializer
73
+ *
74
+ * @param type the type to write
75
+ * @param value a value of that type
76
+ */
77
+ writeType(type, value) {
78
+ this.write(type.from(value));
79
+ }
80
+ /**
81
+ * Write BytesList to this BinarySerializer
82
+ *
83
+ * @param bl BytesList to write to BinarySerializer
84
+ */
85
+ writeBytesList(bl) {
86
+ bl.toBytesSink(this.sink);
87
+ }
88
+ /**
89
+ * Calculate the header of Variable Length encoded bytes
90
+ *
91
+ * @param length the length of the bytes
92
+ */
93
+ encodeVariableLength(length) {
94
+ const lenBytes = new Uint8Array(3);
95
+ if (length <= 192) {
96
+ lenBytes[0] = length;
97
+ return lenBytes.slice(0, 1);
98
+ }
99
+ else if (length <= 12480) {
100
+ length -= 193;
101
+ lenBytes[0] = 193 + (length >>> 8);
102
+ lenBytes[1] = length & 0xff;
103
+ return lenBytes.slice(0, 2);
104
+ }
105
+ else if (length <= 918744) {
106
+ length -= 12481;
107
+ lenBytes[0] = 241 + (length >>> 16);
108
+ lenBytes[1] = (length >> 8) & 0xff;
109
+ lenBytes[2] = length & 0xff;
110
+ return lenBytes.slice(0, 3);
111
+ }
112
+ throw new Error('Overflow error');
113
+ }
114
+ /**
115
+ * Write field and value to BinarySerializer
116
+ *
117
+ * @param field field to write to BinarySerializer
118
+ * @param value value to write to BinarySerializer
119
+ */
120
+ writeFieldAndValue(field, value, isUnlModifyWorkaround = false) {
121
+ const associatedValue = field.associatedType.from(value);
122
+ if (associatedValue.toBytesSink === undefined || field.name === undefined) {
123
+ throw new Error();
124
+ }
125
+ this.sink.put(field.header);
126
+ if (field.isVariableLengthEncoded) {
127
+ this.writeLengthEncoded(associatedValue, isUnlModifyWorkaround);
128
+ }
129
+ else {
130
+ associatedValue.toBytesSink(this.sink);
131
+ }
132
+ }
133
+ /**
134
+ * Write a variable length encoded value to the BinarySerializer
135
+ *
136
+ * @param value length encoded value to write to BytesList
137
+ */
138
+ writeLengthEncoded(value, isUnlModifyWorkaround = false) {
139
+ const bytes = new BytesList();
140
+ if (!isUnlModifyWorkaround) {
141
+ // this part doesn't happen for the Account field in a UNLModify transaction
142
+ value.toBytesSink(bytes);
143
+ }
144
+ this.put(this.encodeVariableLength(bytes.getLength()));
145
+ this.writeBytesList(bytes);
146
+ }
147
+ }
148
+ exports.BinarySerializer = BinarySerializer;
149
+ //# sourceMappingURL=binary-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-serializer.js","sourceRoot":"","sources":["../../src/serdes/binary-serializer.ts"],"names":[],"mappings":";;;AAEA,mDAA4D;AAE5D;;GAEG;AACH,MAAM,SAAS;IAAf;QACU,eAAU,GAAsB,EAAE,CAAA;IAuC5C,CAAC;IArCC;;;;OAIG;IACI,SAAS;QACd,OAAO,IAAA,cAAM,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC,UAAU,CAAA;IAC3C,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,QAAoB;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA,CAAC,8DAA8D;QACtG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC3B,O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,CAAC,IAAI,CAAC,CAAA;SACvC;IACH,CAAC;IAED;;;;OAIG;IACI,kBAAkB,CACvB,KAAqB,EACrB,qBAAqB,GAAG,KAAK;QAE7B,MAAM,KAAK,GAAG,IAAI,SAAS,EAAE,CAAA;QAC7B,IAAI,CAAC,qBAAqB,EAAE;YAC1B,4EAA4E;YAC5E,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;SACzB;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QACtD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;CACF;AAEmB,4CAAgB"}
@@ -0,0 +1,102 @@
1
+ import { Hash256 } from './types/hash-256';
2
+ import { BytesList } from './serdes/binary-serializer';
3
+ /**
4
+ * Abstract class describing a SHAMapNode
5
+ */
6
+ declare abstract class ShaMapNode {
7
+ abstract hashPrefix(): Uint8Array;
8
+ abstract isLeaf(): boolean;
9
+ abstract isInner(): boolean;
10
+ abstract toBytesSink(list: BytesList): void;
11
+ abstract hash(): Hash256;
12
+ }
13
+ /**
14
+ * Class describing a Leaf of SHAMap
15
+ */
16
+ declare class ShaMapLeaf extends ShaMapNode {
17
+ index: Hash256;
18
+ item?: ShaMapNode | undefined;
19
+ constructor(index: Hash256, item?: ShaMapNode | undefined);
20
+ /**
21
+ * @returns true as ShaMapLeaf is a leaf node
22
+ */
23
+ isLeaf(): boolean;
24
+ /**
25
+ * @returns false as ShaMapLeaf is not an inner node
26
+ */
27
+ isInner(): boolean;
28
+ /**
29
+ * Get the prefix of the this.item
30
+ *
31
+ * @returns The hash prefix, unless this.item is undefined, then it returns an empty Uint8Array
32
+ */
33
+ hashPrefix(): Uint8Array;
34
+ /**
35
+ * Hash the bytes representation of this
36
+ *
37
+ * @returns hash of this.item concatenated with this.index
38
+ */
39
+ hash(): Hash256;
40
+ /**
41
+ * Write the bytes representation of this to a BytesList
42
+ * @param list BytesList to write bytes to
43
+ */
44
+ toBytesSink(list: BytesList): void;
45
+ }
46
+ /**
47
+ * Class defining an Inner Node of a SHAMap
48
+ */
49
+ declare class ShaMapInner extends ShaMapNode {
50
+ private depth;
51
+ private slotBits;
52
+ private branches;
53
+ constructor(depth?: number);
54
+ /**
55
+ * @returns true as ShaMapInner is an inner node
56
+ */
57
+ isInner(): boolean;
58
+ /**
59
+ * @returns false as ShaMapInner is not a leaf node
60
+ */
61
+ isLeaf(): boolean;
62
+ /**
63
+ * Get the hash prefix for this node
64
+ *
65
+ * @returns hash prefix describing an inner node
66
+ */
67
+ hashPrefix(): Uint8Array;
68
+ /**
69
+ * Set a branch of this node to be another node
70
+ *
71
+ * @param slot Slot to add branch to this.branches
72
+ * @param branch Branch to add
73
+ */
74
+ setBranch(slot: number, branch: ShaMapNode): void;
75
+ /**
76
+ * @returns true if node is empty
77
+ */
78
+ empty(): boolean;
79
+ /**
80
+ * Compute the hash of this node
81
+ *
82
+ * @returns The hash of this node
83
+ */
84
+ hash(): Hash256;
85
+ /**
86
+ * Writes the bytes representation of this node to a BytesList
87
+ *
88
+ * @param list BytesList to write bytes to
89
+ */
90
+ toBytesSink(list: BytesList): void;
91
+ /**
92
+ * Add item to the SHAMap
93
+ *
94
+ * @param index Hash of the index of the item being inserted
95
+ * @param item Item to insert in the map
96
+ * @param leaf Leaf node to insert when branch doesn't exist
97
+ */
98
+ addItem(index?: Hash256, item?: ShaMapNode, leaf?: ShaMapLeaf): void;
99
+ }
100
+ declare class ShaMap extends ShaMapInner {
101
+ }
102
+ export { ShaMap, ShaMapNode, ShaMapLeaf };
package/dist/shamap.js ADDED
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShaMapLeaf = exports.ShaMapNode = exports.ShaMap = void 0;
4
+ const types_1 = require("./types");
5
+ const hash_prefixes_1 = require("./hash-prefixes");
6
+ const hashes_1 = require("./hashes");
7
+ /**
8
+ * Abstract class describing a SHAMapNode
9
+ */
10
+ class ShaMapNode {
11
+ }
12
+ exports.ShaMapNode = ShaMapNode;
13
+ /**
14
+ * Class describing a Leaf of SHAMap
15
+ */
16
+ class ShaMapLeaf extends ShaMapNode {
17
+ constructor(index, item) {
18
+ super();
19
+ this.index = index;
20
+ this.item = item;
21
+ }
22
+ /**
23
+ * @returns true as ShaMapLeaf is a leaf node
24
+ */
25
+ isLeaf() {
26
+ return true;
27
+ }
28
+ /**
29
+ * @returns false as ShaMapLeaf is not an inner node
30
+ */
31
+ isInner() {
32
+ return false;
33
+ }
34
+ /**
35
+ * Get the prefix of the this.item
36
+ *
37
+ * @returns The hash prefix, unless this.item is undefined, then it returns an empty Uint8Array
38
+ */
39
+ hashPrefix() {
40
+ return this.item === undefined ? new Uint8Array(0) : this.item.hashPrefix();
41
+ }
42
+ /**
43
+ * Hash the bytes representation of this
44
+ *
45
+ * @returns hash of this.item concatenated with this.index
46
+ */
47
+ hash() {
48
+ const hash = hashes_1.Sha512Half.put(this.hashPrefix());
49
+ this.toBytesSink(hash);
50
+ return hash.finish();
51
+ }
52
+ /**
53
+ * Write the bytes representation of this to a BytesList
54
+ * @param list BytesList to write bytes to
55
+ */
56
+ toBytesSink(list) {
57
+ if (this.item !== undefined) {
58
+ this.item.toBytesSink(list);
59
+ }
60
+ this.index.toBytesSink(list);
61
+ }
62
+ }
63
+ exports.ShaMapLeaf = ShaMapLeaf;
64
+ /**
65
+ * Class defining an Inner Node of a SHAMap
66
+ */
67
+ class ShaMapInner extends ShaMapNode {
68
+ constructor(depth = 0) {
69
+ super();
70
+ this.depth = depth;
71
+ this.slotBits = 0;
72
+ this.branches = Array(16);
73
+ }
74
+ /**
75
+ * @returns true as ShaMapInner is an inner node
76
+ */
77
+ isInner() {
78
+ return true;
79
+ }
80
+ /**
81
+ * @returns false as ShaMapInner is not a leaf node
82
+ */
83
+ isLeaf() {
84
+ return false;
85
+ }
86
+ /**
87
+ * Get the hash prefix for this node
88
+ *
89
+ * @returns hash prefix describing an inner node
90
+ */
91
+ hashPrefix() {
92
+ return hash_prefixes_1.HashPrefix.innerNode;
93
+ }
94
+ /**
95
+ * Set a branch of this node to be another node
96
+ *
97
+ * @param slot Slot to add branch to this.branches
98
+ * @param branch Branch to add
99
+ */
100
+ setBranch(slot, branch) {
101
+ this.slotBits = this.slotBits | (1 << slot);
102
+ this.branches[slot] = branch;
103
+ }
104
+ /**
105
+ * @returns true if node is empty
106
+ */
107
+ empty() {
108
+ return this.slotBits === 0;
109
+ }
110
+ /**
111
+ * Compute the hash of this node
112
+ *
113
+ * @returns The hash of this node
114
+ */
115
+ hash() {
116
+ if (this.empty()) {
117
+ return types_1.coreTypes.Hash256.ZERO_256;
118
+ }
119
+ const hash = hashes_1.Sha512Half.put(this.hashPrefix());
120
+ this.toBytesSink(hash);
121
+ return hash.finish();
122
+ }
123
+ /**
124
+ * Writes the bytes representation of this node to a BytesList
125
+ *
126
+ * @param list BytesList to write bytes to
127
+ */
128
+ toBytesSink(list) {
129
+ for (let i = 0; i < this.branches.length; i++) {
130
+ const branch = this.branches[i];
131
+ const hash = branch
132
+ ? branch.hash()
133
+ : types_1.coreTypes.Hash256.ZERO_256;
134
+ hash.toBytesSink(list);
135
+ }
136
+ }
137
+ /**
138
+ * Add item to the SHAMap
139
+ *
140
+ * @param index Hash of the index of the item being inserted
141
+ * @param item Item to insert in the map
142
+ * @param leaf Leaf node to insert when branch doesn't exist
143
+ */
144
+ addItem(index, item, leaf) {
145
+ if (index === undefined) {
146
+ throw new Error();
147
+ }
148
+ if (index !== undefined) {
149
+ const nibble = index.nibblet(this.depth);
150
+ const existing = this.branches[nibble];
151
+ if (existing === undefined) {
152
+ this.setBranch(nibble, leaf || new ShaMapLeaf(index, item));
153
+ }
154
+ else if (existing instanceof ShaMapLeaf) {
155
+ const newInner = new ShaMapInner(this.depth + 1);
156
+ newInner.addItem(existing.index, undefined, existing);
157
+ newInner.addItem(index, item, leaf);
158
+ this.setBranch(nibble, newInner);
159
+ }
160
+ else if (existing instanceof ShaMapInner) {
161
+ existing.addItem(index, item, leaf);
162
+ }
163
+ else {
164
+ throw new Error('invalid ShaMap.addItem call');
165
+ }
166
+ }
167
+ }
168
+ }
169
+ class ShaMap extends ShaMapInner {
170
+ }
171
+ exports.ShaMap = ShaMap;
172
+ //# sourceMappingURL=shamap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shamap.js","sourceRoot":"","sources":["../src/shamap.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,mDAA4C;AAC5C,qCAAqC;AAIrC;;GAEG;AACH,MAAe,UAAU;CAMxB;AA0KgB,gCAAU;AAxK3B;;GAEG;AACH,MAAM,UAAW,SAAQ,UAAU;IACjC,YAAmB,KAAc,EAAS,IAAiB;QACzD,KAAK,EAAE,CAAA;QADU,UAAK,GAAL,KAAK,CAAS;QAAS,SAAI,GAAJ,IAAI,CAAa;IAE3D,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;OAIG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAC7E,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,MAAM,IAAI,GAAG,mBAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;QAC9C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACtB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;IACtB,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,IAAe;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,C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,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;aACpC;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;aAC/C;SACF;IACH,CAAC;CACF;AAED,MAAM,MAAO,SAAQ,WAAW;CAAG;AAE1B,wBAAM"}
@@ -0,0 +1,90 @@
1
+ import { BinaryParser } from './serdes/binary-parser';
2
+ import { AccountID } from './types/account-id';
3
+ import { BinarySerializer, BytesList } from './serdes/binary-serializer';
4
+ import { sha512Half, transactionID } from './hashes';
5
+ import { type XrplDefinitionsBase } from './enums';
6
+ import { JsonObject } from './types/serialized-type';
7
+ /**
8
+ * Construct a BinaryParser
9
+ *
10
+ * @param bytes hex-string or Uint8Array to construct BinaryParser from
11
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
12
+ * Can be customized for sidechains and amendments.
13
+ * @returns BinaryParser
14
+ */
15
+ declare const makeParser: (bytes: string | Uint8Array, definitions?: XrplDefinitionsBase) => BinaryParser;
16
+ /**
17
+ * Parse BinaryParser into JSON
18
+ *
19
+ * @param parser BinaryParser object
20
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
21
+ * Can be customized for sidechains and amendments.
22
+ * @returns JSON for the bytes in the BinaryParser
23
+ */
24
+ declare const readJSON: (parser: BinaryParser, definitions?: XrplDefinitionsBase) => JsonObject;
25
+ /**
26
+ * Parse a hex-string into its JSON interpretation
27
+ *
28
+ * @param bytes hex-string to parse into JSON
29
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
30
+ * Can be customized for sidechains and amendments.
31
+ * @returns JSON
32
+ */
33
+ declare const binaryToJSON: (bytes: string, definitions?: XrplDefinitionsBase) => JsonObject;
34
+ /**
35
+ * Interface for passing parameters to SerializeObject
36
+ *
37
+ * @field set signingFieldOnly to true if you want to serialize only signing fields
38
+ */
39
+ interface OptionObject {
40
+ prefix?: Uint8Array;
41
+ suffix?: Uint8Array;
42
+ signingFieldsOnly?: boolean;
43
+ definitions?: XrplDefinitionsBase;
44
+ }
45
+ /**
46
+ * Function to serialize JSON object representing a transaction
47
+ *
48
+ * @param object JSON object to serialize
49
+ * @param opts options for serializing, including optional prefix, suffix, signingFieldOnly, and definitions
50
+ * @returns A Uint8Array containing the serialized object
51
+ */
52
+ declare function serializeObject(object: JsonObject, opts?: OptionObject): Uint8Array;
53
+ /**
54
+ * Serialize an object for signing
55
+ *
56
+ * @param transaction Transaction to serialize
57
+ * @param prefix Prefix bytes to put before the serialized object
58
+ * @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
59
+ * @returns A Uint8Array with the serialized object
60
+ */
61
+ declare function signingData(transaction: JsonObject, prefix?: Uint8Array, opts?: {
62
+ definitions?: XrplDefinitionsBase;
63
+ }): Uint8Array;
64
+ /**
65
+ * Interface describing fields required for a Claim
66
+ */
67
+ interface ClaimObject extends JsonObject {
68
+ channel: string;
69
+ amount: string | number;
70
+ }
71
+ /**
72
+ * Serialize a signingClaim
73
+ *
74
+ * @param claim A claim object to serialize
75
+ * @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
76
+ * @returns the serialized object with appropriate prefix
77
+ */
78
+ declare function signingClaimData(claim: ClaimObject): Uint8Array;
79
+ /**
80
+ * Serialize a transaction object for multiSigning
81
+ *
82
+ * @param transaction transaction to serialize
83
+ * @param signingAccount Account to sign the transaction with
84
+ * @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
85
+ * @returns serialized transaction with appropriate prefix and suffix
86
+ */
87
+ declare function multiSigningData(transaction: JsonObject, signingAccount: string | AccountID, opts?: {
88
+ definitions: XrplDefinitionsBase;
89
+ }): Uint8Array;
90
+ export { BinaryParser, BinarySerializer, BytesList, ClaimObject, makeParser, serializeObject, readJSON, multiSigningData, signingData, signingClaimData, binaryToJSON, sha512Half, transactionID, };