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

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,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataType = void 0;
4
+ const serialized_type_1 = require("./serialized-type");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * STDataType: Encodes XRPL's "DataType" type.
8
+ *
9
+ * This type wraps an inner SerializedTypeID to indicate what type of data
10
+ * a field contains. It's encoded as a 2-byte unsigned integer representing
11
+ * the inner type.
12
+ *
13
+ * Usage:
14
+ * DataType.from({ type: "AMOUNT" })
15
+ * DataType.from("UINT64")
16
+ * DataType.fromParser(parser)
17
+ */
18
+ class DataType extends serialized_type_1.SerializedType {
19
+ /**
20
+ * Construct a DataType from bytes
21
+ * @param bytes - 2-byte Uint8Array containing the inner type ID
22
+ * @param innerType - Optional explicit inner type (used when constructing from value)
23
+ * @throws Error if bytes is not a 2-byte Uint8Array
24
+ */
25
+ constructor(bytes, innerType) {
26
+ const used = bytes !== null && bytes !== void 0 ? bytes : DataType.defaultBytes;
27
+ if (!(used instanceof Uint8Array) || used.length !== 2) {
28
+ throw new Error(`DataType must be constructed from a 2-byte Uint8Array, got ${used === null || used === void 0 ? void 0 : used.length} bytes`);
29
+ }
30
+ super(used);
31
+ // If innerType is explicitly provided, use it; otherwise read from bytes
32
+ if (innerType !== undefined) {
33
+ this.innerType = innerType;
34
+ }
35
+ else {
36
+ this.innerType = (0, utils_1.readUInt16BE)(used, 0);
37
+ }
38
+ }
39
+ /**
40
+ * Construct from various input types
41
+ *
42
+ * @param value - Can be:
43
+ * - DataType instance (returns as-is)
44
+ * - DataTypeJSON object with 'type' field
45
+ * - String type name (e.g., "AMOUNT", "UINT64")
46
+ * - SerializedTypeID enum value
47
+ * @returns DataType instance
48
+ * @throws Error if value type is not supported or type string is unknown
49
+ */
50
+ static from(value) {
51
+ if (value instanceof DataType) {
52
+ return value;
53
+ }
54
+ if (typeof value === 'object' && value !== null && 'type' in value) {
55
+ const json = value;
56
+ return DataType.fromTypeString(json.type);
57
+ }
58
+ if (typeof value === 'string') {
59
+ return DataType.fromTypeString(value);
60
+ }
61
+ if (typeof value === 'number') {
62
+ return DataType.fromTypeId(value);
63
+ }
64
+ throw new Error('DataType.from: value must be DataType, DataTypeJSON, string, or SerializedTypeID');
65
+ }
66
+ /**
67
+ * Construct from a type string
68
+ *
69
+ * @param typeStr - Type string like "AMOUNT", "UINT64", etc.
70
+ * @returns DataType instance
71
+ * @throws Error if type string is not recognized
72
+ */
73
+ static fromTypeString(typeStr) {
74
+ const typeId = serialized_type_1.TYPE_STRING_TO_ID[typeStr];
75
+ if (typeId === undefined) {
76
+ throw new Error(`DataType: unsupported type string: ${typeStr}`);
77
+ }
78
+ return DataType.fromTypeId(typeId);
79
+ }
80
+ /**
81
+ * Construct from a SerializedTypeID
82
+ *
83
+ * @param typeId - The SerializedTypeID enum value
84
+ * @returns DataType instance
85
+ */
86
+ static fromTypeId(typeId) {
87
+ const bytes = new Uint8Array(2);
88
+ (0, utils_1.writeUInt16BE)(bytes, typeId, 0);
89
+ return new DataType(bytes, typeId);
90
+ }
91
+ /**
92
+ * Read a DataType from a BinaryParser stream (2 bytes)
93
+ *
94
+ * @param parser - BinaryParser positioned at the start of a DataType
95
+ * @returns DataType instance
96
+ */
97
+ static fromParser(parser) {
98
+ const bytes = parser.read(2);
99
+ return new DataType(bytes);
100
+ }
101
+ /**
102
+ * Get the inner SerializedTypeID
103
+ *
104
+ * @returns The inner type ID
105
+ */
106
+ getInnerType() {
107
+ return this.innerType;
108
+ }
109
+ /**
110
+ * Set the inner SerializedTypeID
111
+ *
112
+ * @param typeId - The new inner type ID
113
+ */
114
+ setInnerType(typeId) {
115
+ this.innerType = typeId;
116
+ (0, utils_1.writeUInt16BE)(this.bytes, typeId, 0);
117
+ }
118
+ /**
119
+ * Get the string representation of the inner type
120
+ *
121
+ * @returns String name of the type, or numeric string if unknown
122
+ */
123
+ getInnerTypeString() {
124
+ return serialized_type_1.TYPE_ID_TO_STRING[this.innerType] || this.innerType.toString();
125
+ }
126
+ /**
127
+ * Convert to JSON representation
128
+ *
129
+ * @returns JSON object with 'type' field
130
+ */
131
+ toJSON() {
132
+ return {
133
+ type: this.getInnerTypeString(),
134
+ };
135
+ }
136
+ getSType() {
137
+ return serialized_type_1.SerializedTypeID.STI_DATATYPE;
138
+ }
139
+ }
140
+ exports.DataType = DataType;
141
+ /**
142
+ * Default bytes for DataType (STI_NOTPRESENT)
143
+ */
144
+ DataType.defaultBytes = new Uint8Array([0x00, 0x01]);
145
+ //# sourceMappingURL=dataType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataType.js","sourceRoot":"","sources":["../../src/types/dataType.ts"],"names":[],"mappings":";;;AACA,uDAM0B;AAC1B,oCAAsD;AAStD;;;;;;;;;;;GAWG;AACH,MAA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BAAQ;AAjJf;;GAEG;AACa,qBAAY,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA"}
@@ -1,17 +1,18 @@
1
1
  import { Hash } from './hash';
2
- import { Buffer } from 'buffer/';
2
+ import { SerializedTypeID } from './serialized-type';
3
3
  /**
4
4
  * Hash with a width of 128 bits
5
5
  */
6
6
  declare class Hash128 extends Hash {
7
7
  static readonly width = 16;
8
8
  static readonly ZERO_128: Hash128;
9
- constructor(bytes: Buffer);
9
+ constructor(bytes: Uint8Array);
10
10
  /**
11
11
  * Get the hex representation of a hash-128 bytes, allowing unset
12
12
  *
13
13
  * @returns hex String of this.bytes
14
14
  */
15
15
  toHex(): string;
16
+ getSType(): SerializedTypeID;
16
17
  }
17
18
  export { Hash128 };
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hash128 = void 0;
4
4
  const hash_1 = require("./hash");
5
- const buffer_1 = require("buffer/");
5
+ const utils_1 = require("@transia/isomorphic/utils");
6
+ const serialized_type_1 = require("./serialized-type");
6
7
  /**
7
8
  * Hash with a width of 128 bits
8
9
  */
@@ -19,14 +20,17 @@ class Hash128 extends hash_1.Hash {
19
20
  * @returns hex String of this.bytes
20
21
  */
21
22
  toHex() {
22
- const hex = this.toBytes().toString('hex').toUpperCase();
23
+ const hex = (0, utils_1.bytesToHex)(this.toBytes());
23
24
  if (/^0+$/.exec(hex)) {
24
25
  return '';
25
26
  }
26
27
  return hex;
27
28
  }
29
+ getSType() {
30
+ return serialized_type_1.SerializedTypeID.STI_UINT128;
31
+ }
28
32
  }
29
33
  exports.Hash128 = Hash128;
30
34
  Hash128.width = 16;
31
- Hash128.ZERO_128 = new Hash128(buffer_1.Buffer.alloc(Hash128.width));
35
+ Hash128.ZERO_128 = new Hash128(new Uint8Array(Hash128.width));
32
36
  //# sourceMappingURL=hash-128.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash-128.js","sourceRoot":"","sources":["../../src/types/hash-128.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,oCAAgC;AAEhC;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAa;QACvB,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACpB,OAAO,EAAE,CAAA;SACV;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;;AAGM,0BAAO;AAzBE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"hash-128.js","sourceRoot":"","sources":["../../src/types/hash-128.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,qDAAsD;AACtD,uDAAoD;AAEpD;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAiB;QAC3B,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QACtC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACpB,OAAO,EAAE,CAAA;SACV;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,WAAW,CAAA;IACrC,CAAC;;AAGM,0BAAO;AA7BE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -1,11 +1,12 @@
1
1
  import { Hash } from './hash';
2
- import { Buffer } from 'buffer/';
2
+ import { SerializedTypeID } from './serialized-type';
3
3
  /**
4
4
  * Hash with a width of 160 bits
5
5
  */
6
6
  declare class Hash160 extends Hash {
7
7
  static readonly width = 20;
8
8
  static readonly ZERO_160: Hash160;
9
- constructor(bytes?: Buffer);
9
+ constructor(bytes?: Uint8Array);
10
+ getSType(): SerializedTypeID;
10
11
  }
11
12
  export { Hash160 };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hash160 = void 0;
4
4
  const hash_1 = require("./hash");
5
- const buffer_1 = require("buffer/");
5
+ const serialized_type_1 = require("./serialized-type");
6
6
  /**
7
7
  * Hash with a width of 160 bits
8
8
  */
@@ -13,8 +13,11 @@ class Hash160 extends hash_1.Hash {
13
13
  }
14
14
  super(bytes !== null && bytes !== void 0 ? bytes : Hash160.ZERO_160.bytes);
15
15
  }
16
+ getSType() {
17
+ return serialized_type_1.SerializedTypeID.STI_UINT160;
18
+ }
16
19
  }
17
20
  exports.Hash160 = Hash160;
18
21
  Hash160.width = 20;
19
- Hash160.ZERO_160 = new Hash160(buffer_1.Buffer.alloc(Hash160.width));
22
+ Hash160.ZERO_160 = new Hash160(new Uint8Array(Hash160.width));
20
23
  //# sourceMappingURL=hash-160.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash-160.js","sourceRoot":"","sources":["../../src/types/hash-160.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,oCAAgC;AAEhC;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAc;QACxB,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;;AAGM,0BAAO;AAZE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"hash-160.js","sourceRoot":"","sources":["../../src/types/hash-160.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,uDAAoD;AAEpD;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAkB;QAC5B,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,WAAW,CAAA;IACrC,CAAC;;AAGM,0BAAO;AAhBE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { Hash } from './hash';
2
+ import { SerializedTypeID } from './serialized-type';
3
+ /**
4
+ * Hash with a width of 192 bits
5
+ */
6
+ declare class Hash192 extends Hash {
7
+ static readonly width = 24;
8
+ static readonly ZERO_192: Hash192;
9
+ constructor(bytes?: Uint8Array);
10
+ getSType(): SerializedTypeID;
11
+ }
12
+ export { Hash192 };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash192 = void 0;
4
+ const hash_1 = require("./hash");
5
+ const serialized_type_1 = require("./serialized-type");
6
+ /**
7
+ * Hash with a width of 192 bits
8
+ */
9
+ class Hash192 extends hash_1.Hash {
10
+ constructor(bytes) {
11
+ if (bytes && bytes.byteLength === 0) {
12
+ bytes = Hash192.ZERO_192.bytes;
13
+ }
14
+ super(bytes !== null && bytes !== void 0 ? bytes : Hash192.ZERO_192.bytes);
15
+ }
16
+ getSType() {
17
+ return serialized_type_1.SerializedTypeID.STI_UINT192;
18
+ }
19
+ }
20
+ exports.Hash192 = Hash192;
21
+ Hash192.width = 24;
22
+ Hash192.ZERO_192 = new Hash192(new Uint8Array(Hash192.width));
23
+ //# sourceMappingURL=hash-192.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-192.js","sourceRoot":"","sources":["../../src/types/hash-192.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,uDAAoD;AAEpD;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAkB;QAC5B,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,EAAE;YACnC,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;SAC/B;QAED,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,WAAW,CAAA;IACrC,CAAC;;AAGM,0BAAO;AAhBE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAY,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -1,11 +1,12 @@
1
1
  import { Hash } from './hash';
2
- import { Buffer } from 'buffer/';
2
+ import { SerializedTypeID } from './serialized-type';
3
3
  /**
4
4
  * Hash with a width of 256 bits
5
5
  */
6
6
  declare class Hash256 extends Hash {
7
7
  static readonly width = 32;
8
8
  static readonly ZERO_256: Hash256;
9
- constructor(bytes: Buffer);
9
+ constructor(bytes: Uint8Array);
10
+ getSType(): SerializedTypeID;
10
11
  }
11
12
  export { Hash256 };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hash256 = void 0;
4
4
  const hash_1 = require("./hash");
5
- const buffer_1 = require("buffer/");
5
+ const serialized_type_1 = require("./serialized-type");
6
6
  /**
7
7
  * Hash with a width of 256 bits
8
8
  */
@@ -10,8 +10,11 @@ class Hash256 extends hash_1.Hash {
10
10
  constructor(bytes) {
11
11
  super(bytes !== null && bytes !== void 0 ? bytes : Hash256.ZERO_256.bytes);
12
12
  }
13
+ getSType() {
14
+ return serialized_type_1.SerializedTypeID.STI_UINT256;
15
+ }
13
16
  }
14
17
  exports.Hash256 = Hash256;
15
18
  Hash256.width = 32;
16
- Hash256.ZERO_256 = new Hash256(buffer_1.Buffer.alloc(Hash256.width));
19
+ Hash256.ZERO_256 = new Hash256(new Uint8Array(Hash256.width));
17
20
  //# sourceMappingURL=hash-256.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash-256.js","sourceRoot":"","sources":["../../src/types/hash-256.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,oCAAgC;AAEhC;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;;AAGM,0BAAO;AARE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAG,IAAI,OAAO,CAAC,eAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"hash-256.js","sourceRoot":"","sources":["../../src/types/hash-256.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,uDAAoD;AAEpD;;GAEG;AACH,MAAM,OAAQ,SAAQ,WAAI;IAIxB,YAAY,KAAiB;QAC3B,KAAK,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED,QAAQ;QACN,OAAO,kCAAgB,CAAC,WAAW,CAAA;IACrC,CAAC;;AAGM,0BAAO;AAZE,aAAK,GAAG,EAAE,CAAA;AACV,gBAAQ,GAAG,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA"}
@@ -1,12 +1,11 @@
1
1
  import { Comparable } from './serialized-type';
2
2
  import { BinaryParser } from '../serdes/binary-parser';
3
- import { Buffer } from 'buffer/';
4
3
  /**
5
4
  * Base class defining how to encode and decode hashes
6
5
  */
7
- declare class Hash extends Comparable {
6
+ declare class Hash extends Comparable<Hash | string> {
8
7
  static readonly width: number;
9
- constructor(bytes: Buffer);
8
+ constructor(bytes: Uint8Array);
10
9
  /**
11
10
  * Construct a Hash object from an existing Hash object or a hex-string
12
11
  *
@@ -2,14 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hash = void 0;
4
4
  const serialized_type_1 = require("./serialized-type");
5
- const buffer_1 = require("buffer/");
5
+ const utils_1 = require("@transia/isomorphic/utils");
6
+ const utils_2 = require("../utils");
6
7
  /**
7
8
  * Base class defining how to encode and decode hashes
8
9
  */
9
10
  class Hash extends serialized_type_1.Comparable {
10
11
  constructor(bytes) {
11
12
  super(bytes);
12
- if (this.bytes.byteLength !== this.constructor.width) {
13
+ if (this.bytes.length !== this.constructor.width) {
13
14
  throw new Error(`Invalid Hash length ${this.bytes.byteLength}`);
14
15
  }
15
16
  }
@@ -23,7 +24,10 @@ class Hash extends serialized_type_1.Comparable {
23
24
  return value;
24
25
  }
25
26
  if (typeof value === 'string') {
26
- return new this(buffer_1.Buffer.from(value, 'hex'));
27
+ if (!utils_1.HEX_REGEX.test(value)) {
28
+ throw new Error(`Invalid hash string ${value}`);
29
+ }
30
+ return new this((0, utils_1.hexToBytes)(value));
27
31
  }
28
32
  throw new Error('Cannot construct Hash from given value');
29
33
  }
@@ -42,7 +46,7 @@ class Hash extends serialized_type_1.Comparable {
42
46
  * @param other The Hash to compare this to
43
47
  */
44
48
  compareTo(other) {
45
- return this.bytes.compare(this.constructor.from(other).bytes);
49
+ return (0, utils_2.compare)(this.bytes, this.constructor.from(other).bytes);
46
50
  }
47
51
  /**
48
52
  * @returns the hex-string representation of this Hash
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/types/hash.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAE9C,oCAAgC;AAEhC;;GAEG;AACH,MAAM,IAAK,SAAQ,4BAAU;IAG3B,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,CAAC,CAAA;QACZ,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,KAAM,IAAI,CAAC,WAA2B,CAAC,KAAK,EAAE;YACrE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAA;SAChE;IACH,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAA0B,KAAQ;QAC3C,IAAI,KAAK,YAAY,IAAI,EAAE;YACzB,OAAO,KAAK,CAAA;SACb;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,IAAI,CAAC,eAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;SAC3C;QA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,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC1B,IAAI,KAAK,GAAG,CAAC,KAAK,CAAC,EAAE;YACnB,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;SACrB;aAAM;YACL,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;SACb;QACD,OAAO,CAAC,CAAA;IACV,CAAC;CACF;AAEQ,oBAAI"}
@@ -2,8 +2,11 @@ import { AccountID } from './account-id';
2
2
  import { Amount } from './amount';
3
3
  import { Blob } from './blob';
4
4
  import { Currency } from './currency';
5
+ import { Data } from './data';
6
+ import { DataType } from './dataType';
5
7
  import { Hash128 } from './hash-128';
6
8
  import { Hash160 } from './hash-160';
9
+ import { Hash192 } from './hash-192';
7
10
  import { Hash256 } from './hash-256';
8
11
  import { PathSet } from './path-set';
9
12
  import { STArray } from './st-array';
@@ -15,4 +18,4 @@ import { UInt8 } from './uint-8';
15
18
  import { Vector256 } from './vector-256';
16
19
  import { type SerializedType } from './serialized-type';
17
20
  declare const coreTypes: Record<string, typeof SerializedType>;
18
- export { coreTypes, AccountID, Amount, Blob, Currency, Hash128, Hash160, Hash256, PathSet, STArray, STObject, UInt8, UInt16, UInt32, UInt64, Vector256, };
21
+ export { coreTypes, AccountID, Amount, Blob, Currency, Data, DataType, Hash128, Hash160, Hash192, Hash256, PathSet, STArray, STObject, UInt8, UInt16, UInt32, UInt64, Vector256, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Vector256 = exports.UInt64 = exports.UInt32 = exports.UInt16 = exports.UInt8 = exports.STObject = exports.STArray = exports.PathSet = exports.Hash256 = exports.Hash160 = exports.Hash128 = exports.Currency = exports.Blob = exports.Amount = exports.AccountID = exports.coreTypes = void 0;
3
+ exports.Vector256 = exports.UInt64 = exports.UInt32 = exports.UInt16 = exports.UInt8 = exports.STObject = exports.STArray = exports.PathSet = exports.Hash256 = exports.Hash192 = exports.Hash160 = exports.Hash128 = exports.DataType = exports.Data = exports.Currency = exports.Blob = exports.Amount = exports.AccountID = exports.coreTypes = void 0;
4
4
  const account_id_1 = require("./account-id");
5
5
  Object.defineProperty(exports, "AccountID", { enumerable: true, get: function () { return account_id_1.AccountID; } });
6
6
  const amount_1 = require("./amount");
@@ -9,12 +9,20 @@ const blob_1 = require("./blob");
9
9
  Object.defineProperty(exports, "Blob", { enumerable: true, get: function () { return blob_1.Blob; } });
10
10
  const currency_1 = require("./currency");
11
11
  Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return currency_1.Currency; } });
12
+ const data_1 = require("./data");
13
+ Object.defineProperty(exports, "Data", { enumerable: true, get: function () { return data_1.Data; } });
14
+ const dataType_1 = require("./dataType");
15
+ Object.defineProperty(exports, "DataType", { enumerable: true, get: function () { return dataType_1.DataType; } });
12
16
  const hash_128_1 = require("./hash-128");
13
17
  Object.defineProperty(exports, "Hash128", { enumerable: true, get: function () { return hash_128_1.Hash128; } });
14
18
  const hash_160_1 = require("./hash-160");
15
19
  Object.defineProperty(exports, "Hash160", { enumerable: true, get: function () { return hash_160_1.Hash160; } });
20
+ const hash_192_1 = require("./hash-192");
21
+ Object.defineProperty(exports, "Hash192", { enumerable: true, get: function () { return hash_192_1.Hash192; } });
16
22
  const hash_256_1 = require("./hash-256");
17
23
  Object.defineProperty(exports, "Hash256", { enumerable: true, get: function () { return hash_256_1.Hash256; } });
24
+ const issue_1 = require("./issue");
25
+ const st_number_1 = require("./st-number");
18
26
  const path_set_1 = require("./path-set");
19
27
  Object.defineProperty(exports, "PathSet", { enumerable: true, get: function () { return path_set_1.PathSet; } });
20
28
  const st_array_1 = require("./st-array");
@@ -31,15 +39,21 @@ const uint_8_1 = require("./uint-8");
31
39
  Object.defineProperty(exports, "UInt8", { enumerable: true, get: function () { return uint_8_1.UInt8; } });
32
40
  const vector_256_1 = require("./vector-256");
33
41
  Object.defineProperty(exports, "Vector256", { enumerable: true, get: function () { return vector_256_1.Vector256; } });
42
+ const xchain_bridge_1 = require("./xchain-bridge");
34
43
  const enums_1 = require("../enums");
35
44
  const coreTypes = {
36
45
  AccountID: account_id_1.AccountID,
37
46
  Amount: amount_1.Amount,
38
47
  Blob: blob_1.Blob,
39
48
  Currency: currency_1.Currency,
49
+ Data: data_1.Data,
50
+ DataType: dataType_1.DataType,
40
51
  Hash128: hash_128_1.Hash128,
41
52
  Hash160: hash_160_1.Hash160,
53
+ Hash192: hash_192_1.Hash192,
42
54
  Hash256: hash_256_1.Hash256,
55
+ Issue: issue_1.Issue,
56
+ Number: st_number_1.STNumber,
43
57
  PathSet: path_set_1.PathSet,
44
58
  STArray: st_array_1.STArray,
45
59
  STObject: st_object_1.STObject,
@@ -48,10 +62,11 @@ const coreTypes = {
48
62
  UInt32: uint_32_1.UInt32,
49
63
  UInt64: uint_64_1.UInt64,
50
64
  Vector256: vector_256_1.Vector256,
65
+ XChainBridge: xchain_bridge_1.XChainBridge,
51
66
  };
52
67
  exports.coreTypes = coreTypes;
53
68
  // Ensures that the DEFAULT_DEFINITIONS object connects these types to fields for serializing/deserializing
54
69
  // This is done here instead of in enums/index.ts to avoid a circular dependency
55
- // because some of the above types depend on BinarySerailizer which depends on enums/index.ts.
70
+ // because some of the above types depend on BinarySerializer which depends on enums/index.ts.
56
71
  enums_1.DEFAULT_DEFINITIONS.associateTypes(coreTypes);
57
72
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AA2CtC,0FA3CO,sBAAS,OA2CP;AA1CX,qCAAiC;AA2C/B,uFA3CO,eAAM,OA2CP;AA1CR,iCAA6B;AA2C3B,qFA3CO,WAAI,OA2CP;AA1CN,yCAAqC;AA2CnC,yFA3CO,mBAAQ,OA2CP;AA1CV,yCAAoC;AA2ClC,wFA3CO,kBAAO,OA2CP;AA1CT,yCAAoC;AA2ClC,wFA3CO,kBA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ACb,CAAA;AAQC,8BAAS;AANX,2GAA2G;AAC3G,gFAAgF;AAChF,8FAA8F;AAC9F,2BAAmB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { BinaryParser } from '../serdes/binary-parser';
2
+ import { JsonObject, SerializedType, SerializedTypeID } from './serialized-type';
3
+ interface XRPIssue extends JsonObject {
4
+ currency: string;
5
+ }
6
+ interface IOUIssue extends JsonObject {
7
+ currency: string;
8
+ issuer: string;
9
+ }
10
+ interface MPTIssue extends JsonObject {
11
+ mpt_issuance_id: string;
12
+ }
13
+ /**
14
+ * Interface for JSON objects that represent issues
15
+ */
16
+ type IssueObject = XRPIssue | IOUIssue | MPTIssue;
17
+ /**
18
+ * Class for serializing/Deserializing Amounts
19
+ */
20
+ declare class Issue extends SerializedType {
21
+ static readonly ZERO_ISSUED_CURRENCY: Issue;
22
+ constructor(bytes: Uint8Array);
23
+ /**
24
+ * Construct an amount from an IOU or string amount
25
+ *
26
+ * @param value An Amount, object representing an IOU, MPTAmount, or a string
27
+ * representing an integer amount
28
+ * @returns An Issue object
29
+ */
30
+ static from<T extends Issue | IssueObject>(value: T): Issue;
31
+ /**
32
+ * Read an amount from a BinaryParser
33
+ *
34
+ * @param parser BinaryParser to read the Amount from
35
+ * @param hint The number of bytes to consume from the parser.
36
+ * For an MPT amount, pass 24 (the fixed length for Hash192).
37
+ *
38
+ * @returns An Issue object
39
+ */
40
+ static fromParser(parser: BinaryParser, hint?: number): Issue;
41
+ /**
42
+ * Get the JSON representation of this Amount
43
+ *
44
+ * @returns the JSON interpretation of this.bytes
45
+ */
46
+ toJSON(): IssueObject;
47
+ getSType(): SerializedTypeID;
48
+ }
49
+ export { Issue, IssueObject };