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/dist/index.js ADDED
@@ -0,0 +1,123 @@
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.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("@xrplf/isomorphic/utils");
16
+ const { signingData, signingClaimData, multiSigningData, 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 transaction and prepare for signing with a claim
65
+ *
66
+ * @param json JSON object representing the transaction
67
+ * @param signer string representing the account to sign the transaction with
68
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
69
+ * @returns a hex string of the encoded transaction
70
+ */
71
+ function encodeForSigningClaim(json) {
72
+ if (typeof json !== 'object') {
73
+ throw new Error();
74
+ }
75
+ return (0, utils_1.bytesToHex)(signingClaimData(json));
76
+ }
77
+ exports.encodeForSigningClaim = encodeForSigningClaim;
78
+ /**
79
+ * Encode a transaction and prepare for multi-signing
80
+ *
81
+ * @param json JSON object representing the transaction
82
+ * @param signer string representing the account to sign the transaction with
83
+ * @param definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
84
+ * @returns a hex string of the encoded transaction
85
+ */
86
+ function encodeForMultisigning(json, signer, definitions) {
87
+ if (typeof json !== 'object') {
88
+ throw new Error();
89
+ }
90
+ if (json['SigningPubKey'] !== '') {
91
+ throw new Error();
92
+ }
93
+ const definitionsOpt = definitions ? { definitions } : undefined;
94
+ return (0, utils_1.bytesToHex)(multiSigningData(json, signer, definitionsOpt));
95
+ }
96
+ exports.encodeForMultisigning = encodeForMultisigning;
97
+ /**
98
+ * Encode a quality value
99
+ *
100
+ * @param value string representation of a number
101
+ * @returns a hex-string representing the quality
102
+ */
103
+ function encodeQuality(value) {
104
+ if (typeof value !== 'string') {
105
+ throw new Error();
106
+ }
107
+ return (0, utils_1.bytesToHex)(coretypes_1.quality.encode(value));
108
+ }
109
+ exports.encodeQuality = encodeQuality;
110
+ /**
111
+ * Decode a quality value
112
+ *
113
+ * @param value hex-string of a quality
114
+ * @returns a string representing the quality
115
+ */
116
+ function decodeQuality(value) {
117
+ if (typeof value !== 'string') {
118
+ throw new Error();
119
+ }
120
+ return coretypes_1.quality.decode(value).toString();
121
+ }
122
+ exports.decodeQuality = decodeQuality;
123
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyD;AACzD,mDAAkD;AAiJhD,iGAjJO,gCAAgB,OAiJP;AA9IlB,mCAIgB;AA6Id,oGAhJA,2BAAmB,OAgJA;AAFnB,kGA7IA,yBAAiB,OA6IA;AAGjB,oGA/IA,2BAAmB,OA+IA;AA7IrB,+DAA0D;AA2IxD,gGA3IO,kCAAe,OA2IP;AA1IjB,mCAAmC;AA6IjC,0FA7IO,iBAAS,OA6IP;AA5IX,mDAAoD;AAEpD,MAAM,EACJ,WAAW,EACX,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;KAC/C;IACD,OAAO,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAC1C,CAAC;AA0GC,wBAAM;AAxGR;;;;;;;GAOG;AACH,SAAS,MAAM,CAAC,IAAY,EAAE,WAAiC;IAC7D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAI,KAAK,EAAE,CAAA;KAClB;IACD,OAAO,IAAA,kBAAU,EAAC,eAAe,CAAC,IAAkB,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;AACzE,CAAC;AA4FC,wBAAM;AA1FR;;;;;;;GAOG;AACH,SAAS,gBAAgB,CACvB,IAAY,EACZ,WAAiC;I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ClC,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;AASC,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 +1 @@
1
+ {"version":3,"file":"ledger-hashes.js","sourceRoot":"","sources":["../src/ledger-hashes.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AACzD,mDAA4C;AAC5C,qCAAqC;AACrC,qCAA4D;AAC5D,+CAA0C;AAC1C,iDAA4C;AAC5C,6CAAwC;AACxC,6CAAwC;AACxC,2CAAsC;AACtC,0DAAqD;AAIrD;;;;;;GAMG;AACH,SAAS,WAAW,CAClB,QAAoE,EACpE,SAA4B;IAE5B,MAAM,GAAG,GAAG,IAAI,eAAM,EAAE,CAAA;IACxB,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC3D,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AAUD;;;;;GAKG;AACH,SAAS,mBAAmB,CAC1B,IAA2B;IAE3B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QACd,MAAM,IAAI,KAAK,EAAE,CAAA;KACl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xD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAA;AACtB,CAAC;AA+B+C,gCAAU;AA7B1D;;;;;;;GAOG;AACH,SAAS,gBAAgB,CACvB,MAAc,EACd,WAAiC;IAEjC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;KAC/C;IACD,MAAM,MAAM,GAAG,IAAI,4BAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IACpD,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,UAAU,EAAE;QACjC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,gBAAM,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QACzD,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,kBAAO,CAAC,CAAC,KAAK,EAAE;QAC7C,gBAAgB,EAAE,MAAM,CAAC,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("@xrplf/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,mDAAgE;AAEhE;;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"}
@@ -0,0 +1,100 @@
1
+ import { XrplDefinitionsBase, FieldInstance } from '../enums';
2
+ import { type SerializedType } from '../types/serialized-type';
3
+ /**
4
+ * BinaryParser is used to compute fields and values from a HexString
5
+ */
6
+ declare class BinaryParser {
7
+ private bytes;
8
+ definitions: XrplDefinitionsBase;
9
+ /**
10
+ * Initialize bytes to a hex string
11
+ *
12
+ * @param hexBytes a hex string
13
+ * @param definitions Rippled definitions used to parse the values of transaction types and such.
14
+ * Can be customized for sidechains and amendments.
15
+ */
16
+ constructor(hexBytes: string, definitions?: XrplDefinitionsBase);
17
+ /**
18
+ * Peek the first byte of the BinaryParser
19
+ *
20
+ * @returns The first byte of the BinaryParser
21
+ */
22
+ peek(): number;
23
+ /**
24
+ * Consume the first n bytes of the BinaryParser
25
+ *
26
+ * @param n the number of bytes to skip
27
+ */
28
+ skip(n: number): void;
29
+ /**
30
+ * read the first n bytes from the BinaryParser
31
+ *
32
+ * @param n The number of bytes to read
33
+ * @return The bytes
34
+ */
35
+ read(n: number): Uint8Array;
36
+ /**
37
+ * Read an integer of given size
38
+ *
39
+ * @param n The number of bytes to read
40
+ * @return The number represented by those bytes
41
+ */
42
+ readUIntN(n: number): number;
43
+ readUInt8(): number;
44
+ readUInt16(): number;
45
+ readUInt32(): number;
46
+ size(): number;
47
+ end(customEnd?: number): boolean;
48
+ /**
49
+ * Reads variable length encoded bytes
50
+ *
51
+ * @return The variable length bytes
52
+ */
53
+ readVariableLength(): Uint8Array;
54
+ /**
55
+ * Reads the length of the variable length encoded bytes
56
+ *
57
+ * @return The length of the variable length encoded bytes
58
+ */
59
+ readVariableLengthLength(): number;
60
+ /**
61
+ * Reads the field ordinal from the BinaryParser
62
+ *
63
+ * @return Field ordinal
64
+ */
65
+ readFieldOrdinal(): number;
66
+ /**
67
+ * Read the field from the BinaryParser
68
+ *
69
+ * @return The field represented by the bytes at the head of the BinaryParser
70
+ */
71
+ readField(): FieldInstance;
72
+ /**
73
+ * Read a given type from the BinaryParser
74
+ *
75
+ * @param type The type that you want to read from the BinaryParser
76
+ * @return The instance of that type read from the BinaryParser
77
+ */
78
+ readType(type: typeof SerializedType): SerializedType;
79
+ /**
80
+ * Get the type associated with a given field
81
+ *
82
+ * @param field The field that you wan to get the type of
83
+ * @return The type associated with the given field
84
+ */
85
+ typeForField(field: FieldInstance): typeof SerializedType;
86
+ /**
87
+ * Read value of the type specified by field from the BinaryParser
88
+ *
89
+ * @param field The field that you want to get the associated value for
90
+ * @return The value associated with the given field
91
+ */
92
+ readFieldValue(field: FieldInstance): SerializedType;
93
+ /**
94
+ * Get the next field and value from the BinaryParser
95
+ *
96
+ * @return The field and value
97
+ */
98
+ readFieldAndValue(): [FieldInstance, SerializedType];
99
+ }
100
+ export { BinaryParser };
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinaryParser = void 0;
4
+ const enums_1 = require("../enums");
5
+ const utils_1 = require("@xrplf/isomorphic/utils");
6
+ /**
7
+ * BinaryParser is used to compute fields and values from a HexString
8
+ */
9
+ class BinaryParser {
10
+ /**
11
+ * Initialize bytes to a hex string
12
+ *
13
+ * @param hexBytes a hex string
14
+ * @param definitions Rippled definitions used to parse the values of transaction types and such.
15
+ * Can be customized for sidechains and amendments.
16
+ */
17
+ constructor(hexBytes, definitions = enums_1.DEFAULT_DEFINITIONS) {
18
+ this.bytes = (0, utils_1.hexToBytes)(hexBytes);
19
+ this.definitions = definitions;
20
+ }
21
+ /**
22
+ * Peek the first byte of the BinaryParser
23
+ *
24
+ * @returns The first byte of the BinaryParser
25
+ */
26
+ peek() {
27
+ if (this.bytes.byteLength === 0) {
28
+ throw new Error();
29
+ }
30
+ return this.bytes[0];
31
+ }
32
+ /**
33
+ * Consume the first n bytes of the BinaryParser
34
+ *
35
+ * @param n the number of bytes to skip
36
+ */
37
+ skip(n) {
38
+ if (n > this.bytes.byteLength) {
39
+ throw new Error();
40
+ }
41
+ this.bytes = this.bytes.slice(n);
42
+ }
43
+ /**
44
+ * read the first n bytes from the BinaryParser
45
+ *
46
+ * @param n The number of bytes to read
47
+ * @return The bytes
48
+ */
49
+ read(n) {
50
+ if (n > this.bytes.byteLength) {
51
+ throw new Error();
52
+ }
53
+ const slice = this.bytes.slice(0, n);
54
+ this.skip(n);
55
+ return slice;
56
+ }
57
+ /**
58
+ * Read an integer of given size
59
+ *
60
+ * @param n The number of bytes to read
61
+ * @return The number represented by those bytes
62
+ */
63
+ readUIntN(n) {
64
+ if (0 >= n || n > 4) {
65
+ throw new Error('invalid n');
66
+ }
67
+ return this.read(n).reduce((a, b) => (a << 8) | b) >>> 0;
68
+ }
69
+ readUInt8() {
70
+ return this.readUIntN(1);
71
+ }
72
+ readUInt16() {
73
+ return this.readUIntN(2);
74
+ }
75
+ readUInt32() {
76
+ return this.readUIntN(4);
77
+ }
78
+ size() {
79
+ return this.bytes.byteLength;
80
+ }
81
+ end(customEnd) {
82
+ const length = this.bytes.byteLength;
83
+ return length === 0 || (customEnd !== undefined && length <= customEnd);
84
+ }
85
+ /**
86
+ * Reads variable length encoded bytes
87
+ *
88
+ * @return The variable length bytes
89
+ */
90
+ readVariableLength() {
91
+ return this.read(this.readVariableLengthLength());
92
+ }
93
+ /**
94
+ * Reads the length of the variable length encoded bytes
95
+ *
96
+ * @return The length of the variable length encoded bytes
97
+ */
98
+ readVariableLengthLength() {
99
+ const b1 = this.readUInt8();
100
+ if (b1 <= 192) {
101
+ return b1;
102
+ }
103
+ else if (b1 <= 240) {
104
+ const b2 = this.readUInt8();
105
+ return 193 + (b1 - 193) * 256 + b2;
106
+ }
107
+ else if (b1 <= 254) {
108
+ const b2 = this.readUInt8();
109
+ const b3 = this.readUInt8();
110
+ return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3;
111
+ }
112
+ throw new Error('Invalid variable length indicator');
113
+ }
114
+ /**
115
+ * Reads the field ordinal from the BinaryParser
116
+ *
117
+ * @return Field ordinal
118
+ */
119
+ readFieldOrdinal() {
120
+ let type = this.readUInt8();
121
+ let nth = type & 15;
122
+ type >>= 4;
123
+ if (type === 0) {
124
+ type = this.readUInt8();
125
+ if (type === 0 || type < 16) {
126
+ throw new Error('Cannot read FieldOrdinal, type_code out of range');
127
+ }
128
+ }
129
+ if (nth === 0) {
130
+ nth = this.readUInt8();
131
+ if (nth === 0 || nth < 16) {
132
+ throw new Error('Cannot read FieldOrdinal, field_code out of range');
133
+ }
134
+ }
135
+ return (type << 16) | nth;
136
+ }
137
+ /**
138
+ * Read the field from the BinaryParser
139
+ *
140
+ * @return The field represented by the bytes at the head of the BinaryParser
141
+ */
142
+ readField() {
143
+ return this.definitions.field.fromString(this.readFieldOrdinal().toString());
144
+ }
145
+ /**
146
+ * Read a given type from the BinaryParser
147
+ *
148
+ * @param type The type that you want to read from the BinaryParser
149
+ * @return The instance of that type read from the BinaryParser
150
+ */
151
+ readType(type) {
152
+ return type.fromParser(this);
153
+ }
154
+ /**
155
+ * Get the type associated with a given field
156
+ *
157
+ * @param field The field that you wan to get the type of
158
+ * @return The type associated with the given field
159
+ */
160
+ typeForField(field) {
161
+ return field.associatedType;
162
+ }
163
+ /**
164
+ * Read value of the type specified by field from the BinaryParser
165
+ *
166
+ * @param field The field that you want to get the associated value for
167
+ * @return The value associated with the given field
168
+ */
169
+ readFieldValue(field) {
170
+ const type = this.typeForField(field);
171
+ if (!type) {
172
+ throw new Error(`unsupported: (${field.name}, ${field.type.name})`);
173
+ }
174
+ const sizeHint = field.isVariableLengthEncoded
175
+ ? this.readVariableLengthLength()
176
+ : undefined;
177
+ const value = type.fromParser(this, sizeHint);
178
+ if (value === undefined) {
179
+ throw new Error(`fromParser for (${field.name}, ${field.type.name}) -> undefined `);
180
+ }
181
+ return value;
182
+ }
183
+ /**
184
+ * Get the next field and value from the BinaryParser
185
+ *
186
+ * @return The field and value
187
+ */
188
+ readFieldAndValue() {
189
+ const field = this.readField();
190
+ return [field, this.readFieldValue(field)];
191
+ }
192
+ }
193
+ exports.BinaryParser = BinaryParser;
194
+ //# sourceMappingURL=binary-parser.js.map