@transia/ripple-binary-codec 1.4.6-alpha.8 → 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 (361) 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 +1650 -964
  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 +1652 -966
  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 -307
  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/signerlistset-tx-binary.json +0 -1
  342. package/test/fixtures/signerlistset-tx-meta-binary.json +0 -1
  343. package/test/fixtures/signerlistset-tx.json +0 -94
  344. package/test/fixtures/ticket-create-binary.json +0 -1
  345. package/test/fixtures/ticket-create-tx.json +0 -7
  346. package/test/fixtures/unl-report-binary.json +0 -1
  347. package/test/fixtures/unl-report-meta-binary.json +0 -1
  348. package/test/fixtures/unl-report.json +0 -89
  349. package/test/fixtures/x-codec-fixtures.json +0 -188
  350. package/test/hash.test.js +0 -135
  351. package/test/ledger.test.js +0 -29
  352. package/test/lower-case-hex.test.js +0 -46
  353. package/test/pseudo-transaction.test.js +0 -38
  354. package/test/quality.test.js +0 -15
  355. package/test/shamap.test.js +0 -89
  356. package/test/signing-data-encoding.test.js +0 -213
  357. package/test/tx-encode-decode.test.js +0 -119
  358. package/test/types.test.js +0 -34
  359. package/test/uint.test.js +0 -148
  360. package/test/utils.js +0 -30
  361. package/test/x-address.test.js +0 -181
package/dist/utils.js ADDED
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compare = exports.equal = exports.readInt64BE = exports.readInt32BE = exports.readUInt32BE = exports.readUInt16BE = exports.writeInt64BE = exports.writeInt32BE = exports.writeUInt32BE = exports.writeUInt16BE = exports.writeUInt8 = void 0;
4
+ /**
5
+ * Writes value to array at the specified offset. The value must be a valid unsigned 8-bit integer.
6
+ * @param array Uint8Array to be written to
7
+ * @param value Number to be written to array.
8
+ * @param offset plus the number of bytes written.
9
+ */
10
+ function writeUInt8(array, value, offset) {
11
+ value = Number(value);
12
+ array[offset] = value;
13
+ }
14
+ exports.writeUInt8 = writeUInt8;
15
+ /**
16
+ * Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer.
17
+ * @param array Uint8Array to be written to
18
+ * @param value Number to be written to array.
19
+ * @param offset plus the number of bytes written.
20
+ */
21
+ function writeUInt16BE(array, value, offset) {
22
+ value = Number(value);
23
+ array[offset] = value >>> 8;
24
+ array[offset + 1] = value;
25
+ }
26
+ exports.writeUInt16BE = writeUInt16BE;
27
+ /**
28
+ * Writes value to array at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer.
29
+ * @param array Uint8Array to be written to
30
+ * @param value Number to be written to array.
31
+ * @param offset plus the number of bytes written.
32
+ */
33
+ function writeUInt32BE(array, value, offset) {
34
+ array[offset] = (value >>> 24) & 0xff;
35
+ array[offset + 1] = (value >>> 16) & 0xff;
36
+ array[offset + 2] = (value >>> 8) & 0xff;
37
+ array[offset + 3] = value & 0xff;
38
+ }
39
+ exports.writeUInt32BE = writeUInt32BE;
40
+ /**
41
+ * Writes a signed 32-bit integer to a Uint8Array at the specified offset (big-endian).
42
+ *
43
+ * @param array - The Uint8Array to write to.
44
+ * @param value - The signed 32-bit integer to write.
45
+ * @param offset - The offset at which to write.
46
+ */
47
+ function writeInt32BE(array, value, offset) {
48
+ new DataView(array.buffer, array.byteOffset, array.byteLength).setInt32(offset, value, false);
49
+ }
50
+ exports.writeInt32BE = writeInt32BE;
51
+ /**
52
+ * Writes a signed 64-bit integer (BigInt) to a Uint8Array at the specified offset (big-endian).
53
+ *
54
+ * @param array - The Uint8Array to write to.
55
+ * @param value - The signed 64-bit integer (BigInt) to write.
56
+ * @param offset - The offset at which to write.
57
+ */
58
+ function writeInt64BE(array, value, offset) {
59
+ new DataView(array.buffer, array.byteOffset, array.byteLength).setBigInt64(offset, value, false);
60
+ }
61
+ exports.writeInt64BE = writeInt64BE;
62
+ /**
63
+ * Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
64
+ * @param array Uint8Array to read
65
+ * @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2
66
+ */
67
+ function readUInt16BE(array, offset) {
68
+ return new DataView(array.buffer).getUint16(offset, false).toString(10);
69
+ }
70
+ exports.readUInt16BE = readUInt16BE;
71
+ /**
72
+ * Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
73
+ * @param array Uint8Array to read
74
+ * @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
75
+ */
76
+ function readUInt32BE(array, offset) {
77
+ return new DataView(array.buffer).getUint32(offset, false).toString(10);
78
+ }
79
+ exports.readUInt32BE = readUInt32BE;
80
+ /**
81
+ * Reads a signed 32-bit integer from a Uint8Array at the specified offset (big-endian).
82
+ *
83
+ * @param array - The Uint8Array to read from.
84
+ * @param offset - The offset at which to start reading.
85
+ * @returns The signed 32-bit integer.
86
+ */
87
+ function readInt32BE(array, offset) {
88
+ return new DataView(array.buffer, array.byteOffset, array.byteLength).getInt32(offset, false);
89
+ }
90
+ exports.readInt32BE = readInt32BE;
91
+ /**
92
+ * Reads a signed 64-bit integer (BigInt) from a Uint8Array at the specified offset (big-endian).
93
+ *
94
+ * @param array - The Uint8Array to read from.
95
+ * @param offset - The offset at which to start reading.
96
+ * @returns The signed 64-bit integer (BigInt).
97
+ */
98
+ function readInt64BE(array, offset) {
99
+ return new DataView(array.buffer, array.byteOffset, array.byteLength).getBigInt64(offset, false);
100
+ }
101
+ exports.readInt64BE = readInt64BE;
102
+ /**
103
+ * Compares two Uint8Array or ArrayBuffers
104
+ * @param a first array to compare
105
+ * @param b second array to compare
106
+ */
107
+ function equal(a, b) {
108
+ const aUInt = a instanceof ArrayBuffer ? new Uint8Array(a, 0) : a;
109
+ const bUInt = b instanceof ArrayBuffer ? new Uint8Array(b, 0) : b;
110
+ if (aUInt.byteLength != bUInt.byteLength)
111
+ return false;
112
+ if (aligned32(aUInt) && aligned32(bUInt))
113
+ return compare32(aUInt, bUInt) === 0;
114
+ if (aligned16(aUInt) && aligned16(bUInt))
115
+ return compare16(aUInt, bUInt) === 0;
116
+ return compare8(aUInt, bUInt) === 0;
117
+ }
118
+ exports.equal = equal;
119
+ /**
120
+ * Compares two 8 bit aligned arrays
121
+ * @param a first array to compare
122
+ * @param b second array to compare
123
+ */
124
+ function compare8(a, b) {
125
+ const ua = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
126
+ const ub = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
127
+ return compare(ua, ub);
128
+ }
129
+ /**
130
+ * Compares two 16 bit aligned arrays
131
+ * @param a first array to compare
132
+ * @param b second array to compare
133
+ */
134
+ function compare16(a, b) {
135
+ const ua = new Uint16Array(a.buffer, a.byteOffset, a.byteLength / 2);
136
+ const ub = new Uint16Array(b.buffer, b.byteOffset, b.byteLength / 2);
137
+ return compare(ua, ub);
138
+ }
139
+ /**
140
+ * Compares two 32 bit aligned arrays
141
+ * @param a first array to compare
142
+ * @param b second array to compare
143
+ */
144
+ function compare32(a, b) {
145
+ const ua = new Uint32Array(a.buffer, a.byteOffset, a.byteLength / 4);
146
+ const ub = new Uint32Array(b.buffer, b.byteOffset, b.byteLength / 4);
147
+ return compare(ua, ub);
148
+ }
149
+ /**
150
+ * Compare two TypedArrays
151
+ * @param a first array to compare
152
+ * @param b second array to compare
153
+ */
154
+ function compare(a, b) {
155
+ if (a.byteLength !== b.byteLength) {
156
+ throw new Error('Cannot compare arrays of different length');
157
+ }
158
+ for (let i = 0; i < a.length - 1; i += 1) {
159
+ if (a[i] > b[i])
160
+ return 1;
161
+ if (a[i] < b[i])
162
+ return -1;
163
+ }
164
+ return 0;
165
+ }
166
+ exports.compare = compare;
167
+ /**
168
+ * Determine if TypedArray is 16 bit aligned
169
+ * @param array The array to check
170
+ */
171
+ function aligned16(array) {
172
+ return array.byteOffset % 2 === 0 && array.byteLength % 2 === 0;
173
+ }
174
+ /**
175
+ * Determine if TypedArray is 32 bit aligned
176
+ * @param array The array to check
177
+ */
178
+ function aligned32(array) {
179
+ return array.byteOffset % 4 === 0 && array.byteLength % 4 === 0;
180
+ }
181
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["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;AACjE,CAAC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAC,KAAiB;IAClC,OAAO,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,CAAA;AACjE,CAAC"}
package/package.json CHANGED
@@ -1,34 +1,38 @@
1
1
  {
2
2
  "name": "@transia/ripple-binary-codec",
3
- "version": "1.4.6-alpha.8",
3
+ "version": "2.5.1",
4
4
  "description": "XRP Ledger binary codec",
5
5
  "files": [
6
6
  "dist/*",
7
- "bin/*",
8
- "test/*"
7
+ "src/*"
9
8
  ],
10
9
  "main": "dist/",
11
10
  "directories": {
12
11
  "test": "test"
13
12
  },
14
13
  "dependencies": {
15
- "@transia/ripple-address-codec": "^4.2.8-alpha.0",
16
- "assert": "^2.0.0",
17
- "big-integer": "^1.6.48",
18
- "buffer": "5.6.0",
19
- "create-hash": "^1.2.0",
20
- "decimal.js": "^10.2.0"
14
+ "@transia/isomorphic": "^1.0.1",
15
+ "@transia/ripple-address-codec": "^5.0.0",
16
+ "bignumber.js": "^9.0.0"
21
17
  },
22
18
  "scripts": {
23
- "build": "tsc -b && copyfiles ./src/enums/definitions.json ./dist/enums/",
24
- "clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
25
- "prepare": "npm run build && npm test",
26
- "test": "jest --verbose false --silent=false ./test/*.test.js",
27
- "lint": "eslint . --ext .ts --ext .test.js"
19
+ "build": "tsc --build tsconfig.build.json && copyfiles ./src/enums/definitions.json ./dist/enums/",
20
+ "clean": "rm -rf ./dist ./coverage ./test/testCompiledForWeb tsconfig.build.tsbuildinfo",
21
+ "prepublishOnly": "npm test",
22
+ "test": "npm run build && jest --verbose false --silent=false ./test/*.test.ts",
23
+ "test:browser": "npm run build && karma start ./karma.config.js",
24
+ "lint": "eslint . --max-warnings 0",
25
+ "generateDefinitions": "node ./tools/generateDefinitions.js"
28
26
  },
27
+ "keywords": [
28
+ "ripple",
29
+ "xrp",
30
+ "xrp ledger",
31
+ "xrpl"
32
+ ],
29
33
  "repository": {
30
34
  "type": "git",
31
- "url": "git@github.com/Transia-RnD/xrpl.js/tree/beta"
35
+ "url": "git@github.com:XRPLF/xrpl.js.git"
32
36
  },
33
37
  "bugs": {
34
38
  "url": "https://github.com/XRPLF/xrpl.js/issues"
@@ -38,7 +42,7 @@
38
42
  "readmeFilename": "README.md",
39
43
  "prettier": "@xrplf/prettier-config",
40
44
  "engines": {
41
- "node": ">= 10"
45
+ "node": ">= 18"
42
46
  },
43
- "gitHead": "036312d3616ebc761b0096ba6828a29764f01221"
47
+ "gitHead": "cdaeed0dc8ccb726deb35aaaddcc229eb9aabe6c"
44
48
  }
package/src/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # ripple-binary-codec
2
+
3
+ Serialize and deserialize transactions according to the XRP Ledger protocol.
4
+
5
+ If you'd like to add a new transaction, data type, or generally modify this library, please read the [CONTRIBUTING.md](CONTRIBUTING.md)
package/src/binary.ts ADDED
@@ -0,0 +1,235 @@
1
+ /* eslint-disable func-style */
2
+
3
+ import { bytesToHex } from '@transia/isomorphic/utils'
4
+ import { coreTypes } from './types'
5
+ import { BinaryParser } from './serdes/binary-parser'
6
+ import { AccountID } from './types/account-id'
7
+ import { HashPrefix } from './hash-prefixes'
8
+ import { BinarySerializer, BytesList } from './serdes/binary-serializer'
9
+ import { sha512Half, transactionID } from './hashes'
10
+ import {
11
+ type XrplDefinitionsBase,
12
+ DEFAULT_DEFINITIONS,
13
+ type FieldInstance,
14
+ } from './enums'
15
+ import { STObject } from './types/st-object'
16
+ import { JsonObject } from './types/serialized-type'
17
+
18
+ /**
19
+ * Construct a BinaryParser
20
+ *
21
+ * @param bytes hex-string or Uint8Array to construct BinaryParser from
22
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
23
+ * Can be customized for sidechains and amendments.
24
+ * @returns BinaryParser
25
+ */
26
+ const makeParser = (
27
+ bytes: string | Uint8Array,
28
+ definitions?: XrplDefinitionsBase,
29
+ ): BinaryParser =>
30
+ new BinaryParser(
31
+ bytes instanceof Uint8Array ? bytesToHex(bytes) : bytes,
32
+ definitions,
33
+ )
34
+
35
+ /**
36
+ * Parse BinaryParser into JSON
37
+ *
38
+ * @param parser BinaryParser object
39
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
40
+ * Can be customized for sidechains and amendments.
41
+ * @returns JSON for the bytes in the BinaryParser
42
+ */
43
+ const readJSON = (
44
+ parser: BinaryParser,
45
+ definitions: XrplDefinitionsBase = DEFAULT_DEFINITIONS,
46
+ ): JsonObject =>
47
+ (parser.readType(coreTypes.STObject) as STObject).toJSON(definitions)
48
+
49
+ /**
50
+ * Parse a hex-string into its JSON interpretation
51
+ *
52
+ * @param bytes hex-string to parse into JSON
53
+ * @param definitions rippled definitions used to parse the values of transaction types and such.
54
+ * Can be customized for sidechains and amendments.
55
+ * @returns JSON
56
+ */
57
+ const binaryToJSON = (
58
+ bytes: string,
59
+ definitions?: XrplDefinitionsBase,
60
+ ): JsonObject => readJSON(makeParser(bytes, definitions), definitions)
61
+
62
+ /**
63
+ * Interface for passing parameters to SerializeObject
64
+ *
65
+ * @field set signingFieldOnly to true if you want to serialize only signing fields
66
+ */
67
+ interface OptionObject {
68
+ prefix?: Uint8Array
69
+ suffix?: Uint8Array
70
+ signingFieldsOnly?: boolean
71
+ definitions?: XrplDefinitionsBase
72
+ }
73
+
74
+ /**
75
+ * Function to serialize JSON object representing a transaction
76
+ *
77
+ * @param object JSON object to serialize
78
+ * @param opts options for serializing, including optional prefix, suffix, signingFieldOnly, and definitions
79
+ * @returns A Uint8Array containing the serialized object
80
+ */
81
+ function serializeObject(
82
+ object: JsonObject,
83
+ opts: OptionObject = {},
84
+ ): Uint8Array {
85
+ const { prefix, suffix, signingFieldsOnly = false, definitions } = opts
86
+ const bytesList = new BytesList()
87
+
88
+ if (prefix) {
89
+ bytesList.put(prefix)
90
+ }
91
+
92
+ const filter = signingFieldsOnly
93
+ ? (f: FieldInstance): boolean => f.isSigningField
94
+ : undefined
95
+ ;(coreTypes.STObject as typeof STObject)
96
+ .from(object, filter, definitions)
97
+ .toBytesSink(bytesList)
98
+
99
+ if (suffix) {
100
+ bytesList.put(suffix)
101
+ }
102
+
103
+ return bytesList.toBytes()
104
+ }
105
+
106
+ /**
107
+ * Serialize an object for signing
108
+ *
109
+ * @param transaction Transaction to serialize
110
+ * @param prefix Prefix bytes to put before the serialized object
111
+ * @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
112
+ * @returns A Uint8Array with the serialized object
113
+ */
114
+ function signingData(
115
+ transaction: JsonObject,
116
+ prefix: Uint8Array = HashPrefix.transactionSig,
117
+ opts: { definitions?: XrplDefinitionsBase } = {},
118
+ ): Uint8Array {
119
+ return serializeObject(transaction, {
120
+ prefix,
121
+ signingFieldsOnly: true,
122
+ definitions: opts.definitions,
123
+ })
124
+ }
125
+
126
+ /**
127
+ * Interface describing fields required for a Claim
128
+ */
129
+ interface ClaimObject extends JsonObject {
130
+ channel: string
131
+ amount: string | number
132
+ }
133
+
134
+ /**
135
+ * Serialize a signingClaim
136
+ *
137
+ * @param claim A claim object to serialize
138
+ * @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
139
+ * @returns the serialized object with appropriate prefix
140
+ */
141
+ function signingClaimData(claim: ClaimObject): Uint8Array {
142
+ const num = BigInt(String(claim.amount))
143
+ const prefix = HashPrefix.paymentChannelClaim
144
+ const channel = coreTypes.Hash256.from(claim.channel).toBytes()
145
+ const amount = coreTypes.UInt64.from(num).toBytes()
146
+
147
+ const bytesList = new BytesList()
148
+
149
+ bytesList.put(prefix)
150
+ bytesList.put(channel)
151
+ bytesList.put(amount)
152
+ return bytesList.toBytes()
153
+ }
154
+
155
+ /**
156
+ * Serialize a transaction object for multiSigning
157
+ *
158
+ * @param transaction transaction to serialize
159
+ * @param signingAccount Account to sign the transaction with
160
+ * @param opts.definitions Custom rippled types to use instead of the default. Used for sidechains and amendments.
161
+ * @returns serialized transaction with appropriate prefix and suffix
162
+ */
163
+ function multiSigningData(
164
+ transaction: JsonObject,
165
+ signingAccount: string | AccountID,
166
+ opts: { definitions: XrplDefinitionsBase } = {
167
+ definitions: DEFAULT_DEFINITIONS,
168
+ },
169
+ ): Uint8Array {
170
+ const prefix = HashPrefix.transactionMultiSig
171
+ const suffix = coreTypes.AccountID.from(signingAccount).toBytes()
172
+ return serializeObject(transaction, {
173
+ prefix,
174
+ suffix,
175
+ signingFieldsOnly: true,
176
+ definitions: opts.definitions,
177
+ })
178
+ }
179
+
180
+ /**
181
+ * Interface describing fields required for a Batch signer
182
+ * @property flags - Flags indicating Batch transaction properties
183
+ * @property txIDs - Array of transaction IDs included in the Batch
184
+ */
185
+ interface BatchObject extends JsonObject {
186
+ flags: number
187
+ txIDs: string[]
188
+ }
189
+
190
+ /**
191
+ * Serialize a signingClaim
192
+ *
193
+ * @param batch A Batch object to serialize.
194
+ * @returns the serialized object with appropriate prefix
195
+ */
196
+ function signingBatchData(batch: BatchObject): Uint8Array {
197
+ if (batch.flags == null) {
198
+ throw Error("No field `flags'")
199
+ }
200
+ if (batch.txIDs == null) {
201
+ throw Error('No field `txIDs`')
202
+ }
203
+ const prefix = HashPrefix.batch
204
+ const flags = coreTypes.UInt32.from(batch.flags).toBytes()
205
+ const txIDsLength = coreTypes.UInt32.from(batch.txIDs.length).toBytes()
206
+
207
+ const bytesList = new BytesList()
208
+
209
+ bytesList.put(prefix)
210
+ bytesList.put(flags)
211
+ bytesList.put(txIDsLength)
212
+ batch.txIDs.forEach((txID: string) => {
213
+ bytesList.put(coreTypes.Hash256.from(txID).toBytes())
214
+ })
215
+
216
+ return bytesList.toBytes()
217
+ }
218
+
219
+ export {
220
+ BinaryParser,
221
+ BinarySerializer,
222
+ BytesList,
223
+ ClaimObject,
224
+ BatchObject,
225
+ makeParser,
226
+ serializeObject,
227
+ readJSON,
228
+ multiSigningData,
229
+ signingData,
230
+ signingClaimData,
231
+ binaryToJSON,
232
+ sha512Half,
233
+ transactionID,
234
+ signingBatchData,
235
+ }
@@ -0,0 +1,31 @@
1
+ import {
2
+ DEFAULT_DEFINITIONS,
3
+ Field,
4
+ TransactionType,
5
+ LedgerEntryType,
6
+ Type,
7
+ TransactionResult,
8
+ } from './enums'
9
+ import * as types from './types'
10
+ import * as binary from './binary'
11
+ import { ShaMap } from './shamap'
12
+ import * as ledgerHashes from './ledger-hashes'
13
+ import * as hashes from './hashes'
14
+ import { quality } from './quality'
15
+ import { HashPrefix } from './hash-prefixes'
16
+
17
+ export {
18
+ hashes,
19
+ binary,
20
+ ledgerHashes,
21
+ DEFAULT_DEFINITIONS,
22
+ Field,
23
+ TransactionType,
24
+ LedgerEntryType,
25
+ Type,
26
+ TransactionResult,
27
+ quality,
28
+ HashPrefix,
29
+ ShaMap,
30
+ types,
31
+ }
@@ -0,0 +1,144 @@
1
+ # Definitions
2
+
3
+ This file is used to serialize/deserialize transactions and ledger objects for the XRPL. It's broken into 5 sections laid out below.
4
+
5
+ At the bottom of this README you can find instructions and examples for how to define your own types in a definitions file in order to work on a custom sidechain or develop new amendments.
6
+
7
+ ## Types
8
+
9
+ These are the [types](https://xrpl.org/serialization.html#type-list) associated with a given Serialization Field. Each type has an arbitrary [type_code](https://xrpl.org/serialization.html#type-codes), with lower codes sorting first.
10
+
11
+ ## Ledger Entry Types
12
+
13
+ Each ledger's state tree contain [ledger objects](https://xrpl.org/ledger-object-types.html), which represent all settings, balances, and relationships in the shared ledger.
14
+
15
+ ## Fields
16
+
17
+ These are Serialization Fields (`sf`) [defined in rippled's SField.cpp](https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/impl/SField.cpp). Fields with undefined values are omitted before encoding.
18
+
19
+ ### Key
20
+
21
+ The key is the string defined in the rippled source code, such as "LedgerEntry", "Transaction", etc.
22
+
23
+ ### nth
24
+
25
+ `nth` is the sort code, meaning "nth of type." It is is combined with the type code in order to construct the Field ID of this field. The Field ID is only used for sorting the fields. Since there are multiple fields with the same data type, the `nth` is used to deterministically order each field among other fields of the same data type.
26
+
27
+ Each field has a Field ID, which is used to sort fields that have the same type as one another with lower codes sorting first.
28
+
29
+ - [Field definitions](https://github.com/ripple/rippled/blob/72e6005f562a8f0818bc94803d222ac9345e1e40/src/ripple/protocol/impl/SField.cpp#L72-L266)
30
+ - [Constructing the `SField` field codes](https://github.com/ripple/rippled/blob/eaff9a0e6aec0ad077f118501791c7684debcfd5/src/ripple/protocol/SField.h#L95-L98)
31
+
32
+ For example, the `Account` field has sort code (nth) `1`, so it comes before the `Destination` field which has sort code `3`.
33
+
34
+ Sort code numbers are reused for fields of different types, but different fields of the same type never have the same sort code. When you combine the type code with the sort code, you get the field's unique _Field ID_.
35
+
36
+ The unique [Field ID](https://xrpl.org/serialization.html#field-ids) is prefixed before the field in the final serialized blob. The size of the Field ID is one to three bytes depending on the type code and the field codes it combines.
37
+
38
+ ### isVLEncoded
39
+
40
+ If true, the field is Variable Length encoded and [length-prefixed](https://xrpl.org/serialization.html#length-prefixing). The variable-length encoded fields are `STI_VL`/`Blob`, `STI_ACCOUNT`/`AccountID`, and `STI_VECTOR256`/`Vector256`.
41
+
42
+ ### isSerialized
43
+
44
+ Fields are serialized if they are not [one of these](https://github.com/ripple/rippled/blob/eaff9a0e6aec0ad077f118501791c7684debcfd5/src/ripple/protocol/impl/SField.cpp#L71-L78) or if they are not an SField.
45
+
46
+ - https://github.com/ripple/ripple-binary-codec/blob/14e76e68ead7e4bcd83c942dbdc9064d5a66869b/src/enums/definitions.json#L832
47
+ - https://github.com/ripple/rippled/search?utf8=%E2%9C%93&q=taker_gets_funded&type=
48
+
49
+ ### isSigningField
50
+
51
+ True unless the field is [specified with `SField::notSigning`](https://github.com/ripple/rippled/blob/eaff9a0e6aec0ad077f118501791c7684debcfd5/src/ripple/protocol/impl/SField.cpp#L198).
52
+
53
+ ## Transaction Results
54
+
55
+ See:
56
+
57
+ - https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/TER.h
58
+ - https://xrpl.org/transaction-results.html
59
+
60
+ To generate a new definitions file from rippled source code, use [this tool](../../tools/generateDefinitions.js).
61
+
62
+ ## Transaction Types
63
+
64
+ See https://github.com/ripple/rippled/blob/develop/src/ripple/protocol/TxFormats.h
65
+
66
+ # Defining Your Own Definitions
67
+
68
+ If you're building your own sidechain or writing an amendment for the XRPL, you may need to create new XRPL definitions.
69
+
70
+ To do that there are a couple things you need to do:
71
+
72
+ 1. Generate your own `definitions.json` file from rippled source code using [this tool](../../tools/generateDefinitions.js). The default `definitions.json` for mainnet can be found [here](https://github.com/XRPLF/xrpl.js/blob/main/packages/ripple-binary-codec/src/enums/definitions.json).
73
+ 2. Create new SerializedType classes for any new Types (So that encode/decode behavior is defined). The SerializedType classes correspond to "ST..." classes in Rippled. Note: This is very rarely required.
74
+
75
+ - For examples of how to implement that you can look at objects in the [`types` folder](../types/), such as `Amount`, `UInt8`, or `STArray`.
76
+
77
+ 3. Import your `definitions.json` file to construct your own `XrplDefinitions` object.
78
+ 4. Pass the `XrplDefinitions` object whenever you `encode` or `decode` a transaction.
79
+ 5. If you added any new transaction types, you should create an `interface` for the transaction that extends `BaseTransaction` from the `xrpl` repo to use it with the functions on `Client` (See the below example of adding a new transaction type)
80
+
81
+ ## Example of adding a new Transaction type
82
+
83
+ ```
84
+ // newDefinitionsJson is where you can import your custom defined definitions.json file
85
+ const newDefinitionsJson = require('./new-transaction-type-definitions.json')
86
+ const { XrplDefinitions, Client } = require('xrpl')
87
+
88
+ const newDefs = new XrplDefinitions(newDefinitionsJson)
89
+
90
+ // Change to point at the server you care about
91
+ const serverAddress = 'wss://s.devnet.rippletest.net:51233'
92
+ const client = new Client(serverAddress)
93
+ const wallet1 = await client.fundWallet()
94
+
95
+ // Extending BaseTransaction allows typescript to recognize this as a transaction type
96
+ interface NewTx extends BaseTransaction {
97
+ Amount: Amount
98
+ }
99
+
100
+ const tx: NewTx = {
101
+ // The TransactionType here needs to match what you added in your newDefinitionsJson file
102
+ TransactionType: 'NewTx',
103
+ Account: wallet1.address,
104
+ Amount: '100',
105
+ }
106
+
107
+ // By passing in your newDefs, your new transaction should be serializable.
108
+ // Rippled will still throw an error though if it's not a supported transaction type.
109
+ const result = await client.submitAndWait(tx, {
110
+ wallet: wallet1,
111
+ definitions: newDefs,
112
+ })
113
+ ```
114
+
115
+ ## Example of adding a new serializable Type
116
+
117
+ ```
118
+ const { XrplDefinitions } = require('../dist/coretypes')
119
+
120
+ // newDefinitionsJson is where you can import your custom defined definitions.json file
121
+ const newDefinitionsJson = require('./fixtures/new-definitions.json')
122
+
123
+
124
+ // For any new Types you create, you'll need to make a class with the same name which extends a SerializedType object
125
+ // In order to define how to serialize/deserialize that field. Here we simply make our NewType act like a UInt32.
126
+
127
+ const { UInt32 } = require('../dist/types/uint-32')
128
+ class NewType extends UInt32 {
129
+ // Should be the same as UInt32
130
+ }
131
+
132
+ const extendedCoreTypes = { NewType }
133
+
134
+ const newDefs = new XrplDefinitions(newDefinitionsJson, extendedCoreTypes)
135
+
136
+ // From this point on, we should be able to serialize / deserialize Transactions with fields that have 'NewType' as their Type.
137
+
138
+ const encoded = encode(my_tx, newDefs)
139
+ const decoded = decode(encoded, newDefs)
140
+ ```
141
+
142
+ ## Other examples
143
+
144
+ You can find other examples of how to modify `definitions.json` in `definition.test.js` which contains tests for this feature, and uses various example modified `definition` files. You can find the tests and the corresponding example `definition` files in [this folder of test cases](https://github.com/XRPLF/xrpl.js/tree/main/packages/ripple-binary-codec/test)