ripple-binary-codec 2.7.0-smartescrow.0 → 2.8.0-smartcontract.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/enums/definitions.json +173 -270
  2. package/dist/enums/src/enums/definitions.json +173 -270
  3. package/dist/quality.js +15 -3
  4. package/dist/quality.js.map +1 -1
  5. package/dist/serdes/binary-parser.js +8 -2
  6. package/dist/serdes/binary-parser.js.map +1 -1
  7. package/dist/serdes/binary-serializer.d.ts +1 -1
  8. package/dist/serdes/binary-serializer.js +2 -2
  9. package/dist/serdes/binary-serializer.js.map +1 -1
  10. package/dist/src/enums/definitions.json +173 -270
  11. package/dist/src/quality.js +15 -3
  12. package/dist/src/quality.js.map +1 -1
  13. package/dist/src/serdes/binary-parser.js +8 -2
  14. package/dist/src/serdes/binary-parser.js.map +1 -1
  15. package/dist/src/serdes/binary-serializer.d.ts +1 -1
  16. package/dist/src/serdes/binary-serializer.js +2 -2
  17. package/dist/src/serdes/binary-serializer.js.map +1 -1
  18. package/dist/src/types/account-id.d.ts +2 -0
  19. package/dist/src/types/account-id.js +4 -0
  20. package/dist/src/types/account-id.js.map +1 -1
  21. package/dist/src/types/amount.d.ts +2 -1
  22. package/dist/src/types/amount.js +25 -4
  23. package/dist/src/types/amount.js.map +1 -1
  24. package/dist/src/types/blob.d.ts +2 -1
  25. package/dist/src/types/blob.js +3 -0
  26. package/dist/src/types/blob.js.map +1 -1
  27. package/dist/src/types/currency.d.ts +2 -0
  28. package/dist/src/types/currency.js +4 -0
  29. package/dist/src/types/currency.js.map +1 -1
  30. package/dist/src/types/data.d.ts +86 -0
  31. package/dist/src/types/data.js +252 -0
  32. package/dist/src/types/data.js.map +1 -0
  33. package/dist/src/types/dataType.d.ts +94 -0
  34. package/dist/src/types/dataType.js +145 -0
  35. package/dist/src/types/dataType.js.map +1 -0
  36. package/dist/src/types/hash-128.d.ts +2 -0
  37. package/dist/src/types/hash-128.js +4 -0
  38. package/dist/src/types/hash-128.js.map +1 -1
  39. package/dist/src/types/hash-160.d.ts +2 -0
  40. package/dist/src/types/hash-160.js +4 -0
  41. package/dist/src/types/hash-160.js.map +1 -1
  42. package/dist/src/types/hash-192.d.ts +2 -0
  43. package/dist/src/types/hash-192.js +4 -0
  44. package/dist/src/types/hash-192.js.map +1 -1
  45. package/dist/src/types/hash-256.d.ts +2 -0
  46. package/dist/src/types/hash-256.js +4 -0
  47. package/dist/src/types/hash-256.js.map +1 -1
  48. package/dist/src/types/index.d.ts +3 -1
  49. package/dist/src/types/index.js +7 -1
  50. package/dist/src/types/index.js.map +1 -1
  51. package/dist/src/types/int-32.d.ts +17 -8
  52. package/dist/src/types/int-32.js +25 -11
  53. package/dist/src/types/int-32.js.map +1 -1
  54. package/dist/src/types/int.d.ts +38 -0
  55. package/dist/src/types/int.js +57 -0
  56. package/dist/src/types/int.js.map +1 -0
  57. package/dist/src/types/issue.d.ts +2 -1
  58. package/dist/src/types/issue.js +3 -0
  59. package/dist/src/types/issue.js.map +1 -1
  60. package/dist/src/types/json.d.ts +173 -0
  61. package/dist/src/types/json.js +531 -0
  62. package/dist/src/types/json.js.map +1 -0
  63. package/dist/src/types/path-set.d.ts +2 -1
  64. package/dist/src/types/path-set.js +3 -0
  65. package/dist/src/types/path-set.js.map +1 -1
  66. package/dist/src/types/serialized-type.d.ts +43 -0
  67. package/dist/src/types/serialized-type.js +63 -1
  68. package/dist/src/types/serialized-type.js.map +1 -1
  69. package/dist/src/types/st-array.d.ts +2 -1
  70. package/dist/src/types/st-array.js +3 -0
  71. package/dist/src/types/st-array.js.map +1 -1
  72. package/dist/src/types/st-number.d.ts +2 -1
  73. package/dist/src/types/st-number.js +3 -0
  74. package/dist/src/types/st-number.js.map +1 -1
  75. package/dist/src/types/st-object.d.ts +2 -1
  76. package/dist/src/types/st-object.js +9 -1
  77. package/dist/src/types/st-object.js.map +1 -1
  78. package/dist/src/types/uint-16.d.ts +2 -0
  79. package/dist/src/types/uint-16.js +4 -0
  80. package/dist/src/types/uint-16.js.map +1 -1
  81. package/dist/src/types/uint-32.d.ts +2 -0
  82. package/dist/src/types/uint-32.js +4 -0
  83. package/dist/src/types/uint-32.js.map +1 -1
  84. package/dist/src/types/uint-64.d.ts +2 -0
  85. package/dist/src/types/uint-64.js +4 -0
  86. package/dist/src/types/uint-64.js.map +1 -1
  87. package/dist/src/types/uint-8.d.ts +2 -0
  88. package/dist/src/types/uint-8.js +4 -0
  89. package/dist/src/types/uint-8.js.map +1 -1
  90. package/dist/src/types/vector-256.d.ts +2 -1
  91. package/dist/src/types/vector-256.js +3 -0
  92. package/dist/src/types/vector-256.js.map +1 -1
  93. package/dist/src/types/xchain-bridge.d.ts +2 -1
  94. package/dist/src/types/xchain-bridge.js +3 -0
  95. package/dist/src/types/xchain-bridge.js.map +1 -1
  96. package/dist/src/utils.js +1 -1
  97. package/dist/src/utils.js.map +1 -1
  98. package/dist/tsconfig.tsbuildinfo +1 -1
  99. package/dist/types/account-id.d.ts +2 -0
  100. package/dist/types/account-id.js +4 -0
  101. package/dist/types/account-id.js.map +1 -1
  102. package/dist/types/amount.d.ts +2 -1
  103. package/dist/types/amount.js +25 -4
  104. package/dist/types/amount.js.map +1 -1
  105. package/dist/types/blob.d.ts +2 -1
  106. package/dist/types/blob.js +3 -0
  107. package/dist/types/blob.js.map +1 -1
  108. package/dist/types/currency.d.ts +2 -0
  109. package/dist/types/currency.js +4 -0
  110. package/dist/types/currency.js.map +1 -1
  111. package/dist/types/data.d.ts +86 -0
  112. package/dist/types/data.js +252 -0
  113. package/dist/types/data.js.map +1 -0
  114. package/dist/types/dataType.d.ts +94 -0
  115. package/dist/types/dataType.js +145 -0
  116. package/dist/types/dataType.js.map +1 -0
  117. package/dist/types/hash-128.d.ts +2 -0
  118. package/dist/types/hash-128.js +4 -0
  119. package/dist/types/hash-128.js.map +1 -1
  120. package/dist/types/hash-160.d.ts +2 -0
  121. package/dist/types/hash-160.js +4 -0
  122. package/dist/types/hash-160.js.map +1 -1
  123. package/dist/types/hash-192.d.ts +2 -0
  124. package/dist/types/hash-192.js +4 -0
  125. package/dist/types/hash-192.js.map +1 -1
  126. package/dist/types/hash-256.d.ts +2 -0
  127. package/dist/types/hash-256.js +4 -0
  128. package/dist/types/hash-256.js.map +1 -1
  129. package/dist/types/index.d.ts +3 -1
  130. package/dist/types/index.js +7 -1
  131. package/dist/types/index.js.map +1 -1
  132. package/dist/types/int-32.d.ts +17 -8
  133. package/dist/types/int-32.js +25 -11
  134. package/dist/types/int-32.js.map +1 -1
  135. package/dist/types/int.d.ts +38 -0
  136. package/dist/types/int.js +57 -0
  137. package/dist/types/int.js.map +1 -0
  138. package/dist/types/issue.d.ts +2 -1
  139. package/dist/types/issue.js +3 -0
  140. package/dist/types/issue.js.map +1 -1
  141. package/dist/types/json.d.ts +173 -0
  142. package/dist/types/json.js +531 -0
  143. package/dist/types/json.js.map +1 -0
  144. package/dist/types/path-set.d.ts +2 -1
  145. package/dist/types/path-set.js +3 -0
  146. package/dist/types/path-set.js.map +1 -1
  147. package/dist/types/serialized-type.d.ts +43 -0
  148. package/dist/types/serialized-type.js +63 -1
  149. package/dist/types/serialized-type.js.map +1 -1
  150. package/dist/types/st-array.d.ts +2 -1
  151. package/dist/types/st-array.js +3 -0
  152. package/dist/types/st-array.js.map +1 -1
  153. package/dist/types/st-number.d.ts +2 -1
  154. package/dist/types/st-number.js +3 -0
  155. package/dist/types/st-number.js.map +1 -1
  156. package/dist/types/st-object.d.ts +2 -1
  157. package/dist/types/st-object.js +9 -1
  158. package/dist/types/st-object.js.map +1 -1
  159. package/dist/types/uint-16.d.ts +2 -0
  160. package/dist/types/uint-16.js +4 -0
  161. package/dist/types/uint-16.js.map +1 -1
  162. package/dist/types/uint-32.d.ts +2 -0
  163. package/dist/types/uint-32.js +4 -0
  164. package/dist/types/uint-32.js.map +1 -1
  165. package/dist/types/uint-64.d.ts +2 -0
  166. package/dist/types/uint-64.js +4 -0
  167. package/dist/types/uint-64.js.map +1 -1
  168. package/dist/types/uint-8.d.ts +2 -0
  169. package/dist/types/uint-8.js +4 -0
  170. package/dist/types/uint-8.js.map +1 -1
  171. package/dist/types/vector-256.d.ts +2 -1
  172. package/dist/types/vector-256.js +3 -0
  173. package/dist/types/vector-256.js.map +1 -1
  174. package/dist/types/xchain-bridge.d.ts +2 -1
  175. package/dist/types/xchain-bridge.js +3 -0
  176. package/dist/types/xchain-bridge.js.map +1 -1
  177. package/dist/utils.js +1 -1
  178. package/dist/utils.js.map +1 -1
  179. package/package.json +2 -2
  180. package/src/enums/definitions.json +173 -270
  181. package/src/quality.ts +13 -3
  182. package/src/serdes/binary-parser.ts +12 -2
  183. package/src/serdes/binary-serializer.ts +2 -2
  184. package/src/types/account-id.ts +5 -0
  185. package/src/types/amount.ts +25 -6
  186. package/src/types/blob.ts +5 -1
  187. package/src/types/currency.ts +5 -0
  188. package/src/types/data.ts +294 -0
  189. package/src/types/dataType.ts +178 -0
  190. package/src/types/hash-128.ts +5 -0
  191. package/src/types/hash-160.ts +5 -0
  192. package/src/types/hash-192.ts +5 -0
  193. package/src/types/hash-256.ts +5 -0
  194. package/src/types/index.ts +6 -0
  195. package/src/types/int-32.ts +27 -12
  196. package/src/types/int.ts +75 -0
  197. package/src/types/issue.ts +5 -1
  198. package/src/types/json.ts +650 -0
  199. package/src/types/path-set.ts +5 -1
  200. package/src/types/serialized-type.ts +67 -0
  201. package/src/types/st-array.ts +5 -1
  202. package/src/types/st-number.ts +5 -1
  203. package/src/types/st-object.ts +12 -2
  204. package/src/types/uint-16.ts +5 -0
  205. package/src/types/uint-32.ts +5 -0
  206. package/src/types/uint-64.ts +6 -1
  207. package/src/types/uint-8.ts +5 -0
  208. package/src/types/vector-256.ts +5 -1
  209. package/src/types/xchain-bridge.ts +5 -1
  210. package/src/utils.ts +1 -1
@@ -2,6 +2,69 @@ import { BytesList } from '../serdes/binary-serializer'
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { XrplDefinitionsBase } from '../enums'
4
4
  import { bytesToHex } from '@xrplf/isomorphic/utils'
5
+ import definitions from '../enums/definitions.json'
6
+
7
+ /**
8
+ * Enum for SerializedTypeID values used in XRPL
9
+ * These match the C++ implementation's STI_ constants
10
+ */
11
+ export enum SerializedTypeID {
12
+ STI_NOTPRESENT = 0,
13
+ STI_UINT16 = 1,
14
+ STI_UINT32 = 2,
15
+ STI_UINT64 = 3,
16
+ STI_UINT128 = 4,
17
+ STI_UINT256 = 5,
18
+ STI_AMOUNT = 6,
19
+ STI_VL = 7,
20
+ STI_ACCOUNT = 8,
21
+ STI_NUMBER = 9,
22
+ STI_INT32 = 10,
23
+ STI_INT64 = 11,
24
+
25
+ STI_OBJECT = 14,
26
+ STI_ARRAY = 15,
27
+
28
+ STI_UINT8 = 16,
29
+ STI_UINT160 = 17,
30
+ STI_PATHSET = 18,
31
+ STI_VECTOR256 = 19,
32
+ STI_UINT96 = 20,
33
+ STI_UINT192 = 21,
34
+ STI_UINT384 = 22,
35
+ STI_UINT512 = 23,
36
+ STI_ISSUE = 24,
37
+ STI_XCHAIN_BRIDGE = 25,
38
+ STI_CURRENCY = 26,
39
+ STI_DATA = 27,
40
+ STI_DATATYPE = 28,
41
+ STI_JSON = 29,
42
+ }
43
+
44
+ /**
45
+ * Maps built dynamically from definitions.json TYPES.
46
+ * This ensures type string names (e.g. "Hash256", "Hash128") stay in sync
47
+ * with the canonical definitions rather than using hardcoded uppercase variants.
48
+ */
49
+
50
+ // Map of type name strings to SerializedTypeID values
51
+ export const TYPE_STRING_TO_ID: Record<string, SerializedTypeID> = {}
52
+
53
+ // Map of numeric type codes to SerializedTypeID values
54
+ export const TYPE_NUMBER_TO_ID: Record<number, SerializedTypeID> = {}
55
+
56
+ // Map of SerializedTypeID values to type name strings
57
+ export const TYPE_ID_TO_STRING: Record<number, string> = {}
58
+
59
+ // Populate all three maps from definitions.json TYPES
60
+ for (const [name, id] of Object.entries(definitions.TYPES)) {
61
+ if (id >= 0) {
62
+ const typeId = id as SerializedTypeID
63
+ TYPE_STRING_TO_ID[name] = typeId
64
+ TYPE_NUMBER_TO_ID[id] = typeId
65
+ TYPE_ID_TO_STRING[typeId] = name
66
+ }
67
+ }
5
68
 
6
69
  type JSON = string | number | boolean | null | undefined | JSON[] | JsonObject
7
70
 
@@ -77,6 +140,10 @@ class SerializedType {
77
140
  toString(): string {
78
141
  return this.toHex()
79
142
  }
143
+
144
+ getSType(): SerializedTypeID {
145
+ return this.getSType()
146
+ }
80
147
  }
81
148
 
82
149
  /**
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_DEFINITIONS, XrplDefinitionsBase } from '../enums'
2
- import { SerializedType, JsonObject } from './serialized-type'
2
+ import { SerializedType, JsonObject, SerializedTypeID } from './serialized-type'
3
3
  import { STObject } from './st-object'
4
4
  import { BinaryParser } from '../serdes/binary-parser'
5
5
  import { concat } from '@xrplf/isomorphic/utils'
@@ -108,6 +108,10 @@ class STArray extends SerializedType {
108
108
 
109
109
  return result
110
110
  }
111
+
112
+ getSType(): SerializedTypeID {
113
+ return SerializedTypeID.STI_ARRAY
114
+ }
111
115
  }
112
116
 
113
117
  export { STArray }
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable complexity -- required for various checks */
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
- import { SerializedType } from './serialized-type'
3
+ import { SerializedType, SerializedTypeID } from './serialized-type'
4
4
  import { writeInt32BE, writeInt64BE, readInt32BE, readInt64BE } from '../utils'
5
5
 
6
6
  /**
@@ -307,4 +307,8 @@ export class STNumber extends SerializedType {
307
307
  fractionPart ? '.' + fractionPart : ''
308
308
  }`
309
309
  }
310
+
311
+ getSType(): SerializedTypeID {
312
+ return SerializedTypeID.STI_NUMBER
313
+ }
310
314
  }
@@ -4,7 +4,7 @@ import {
4
4
  Bytes,
5
5
  XrplDefinitionsBase,
6
6
  } from '../enums'
7
- import { SerializedType, JsonObject } from './serialized-type'
7
+ import { SerializedType, JsonObject, SerializedTypeID } from './serialized-type'
8
8
  import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
9
9
  import { BinaryParser } from '../serdes/binary-parser'
10
10
  import { BinarySerializer, BytesList } from '../serdes/binary-serializer'
@@ -151,7 +151,13 @@ class STObject extends SerializedType {
151
151
  ? STArray.from(xAddressDecoded[field.name], definitions)
152
152
  : field.type.name === 'UInt64'
153
153
  ? UInt64.from(xAddressDecoded[field.name], field.name)
154
- : field.associatedType.from(xAddressDecoded[field.name])
154
+ : field.associatedType?.from
155
+ ? field.associatedType.from(xAddressDecoded[field.name])
156
+ : (() => {
157
+ throw new Error(
158
+ `Type ${field.type.name} for field ${field.name} is missing associatedType.from`,
159
+ )
160
+ })()
155
161
 
156
162
  if (associatedValue == undefined) {
157
163
  throw new TypeError(
@@ -201,6 +207,10 @@ class STObject extends SerializedType {
201
207
 
202
208
  return accumulator
203
209
  }
210
+
211
+ getSType(): SerializedTypeID {
212
+ return SerializedTypeID.STI_OBJECT
213
+ }
204
214
  }
205
215
 
206
216
  export { STObject }
@@ -1,6 +1,7 @@
1
1
  import { UInt } from './uint'
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { readUInt16BE, writeUInt16BE } from '../utils'
4
+ import { SerializedTypeID } from './serialized-type'
4
5
 
5
6
  /**
6
7
  * Derived UInt class for serializing/deserializing 16 bit UInt
@@ -48,6 +49,10 @@ class UInt16 extends UInt {
48
49
  valueOf(): number {
49
50
  return parseInt(readUInt16BE(this.bytes, 0))
50
51
  }
52
+
53
+ getSType(): SerializedTypeID {
54
+ return SerializedTypeID.STI_UINT16
55
+ }
51
56
  }
52
57
 
53
58
  export { UInt16 }
@@ -1,6 +1,7 @@
1
1
  import { UInt } from './uint'
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { readUInt32BE, writeUInt32BE } from '../utils'
4
+ import { SerializedTypeID } from './serialized-type'
4
5
 
5
6
  /**
6
7
  * Derived UInt class for serializing/deserializing 32 bit UInt
@@ -54,6 +55,10 @@ class UInt32 extends UInt {
54
55
  valueOf(): number {
55
56
  return parseInt(readUInt32BE(this.bytes, 0), 10)
56
57
  }
58
+
59
+ getSType(): SerializedTypeID {
60
+ return SerializedTypeID.STI_UINT32
61
+ }
57
62
  }
58
63
 
59
64
  export { UInt32 }
@@ -3,6 +3,7 @@ import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { bytesToHex, concat, hexToBytes } from '@xrplf/isomorphic/utils'
4
4
  import { readUInt32BE, writeUInt32BE } from '../utils'
5
5
  import { DEFAULT_DEFINITIONS, XrplDefinitionsBase } from '../enums'
6
+ import { SerializedTypeID } from './serialized-type'
6
7
 
7
8
  const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/
8
9
  const BASE10_REGEX = /^[0-9]{1,20}$/
@@ -51,7 +52,7 @@ class UInt64 extends UInt {
51
52
  return val
52
53
  }
53
54
 
54
- let buf = new Uint8Array(UInt64.width)
55
+ let buf: Uint8Array = new Uint8Array(UInt64.width)
55
56
 
56
57
  if (typeof val === 'number' && Number.isInteger(val)) {
57
58
  if (val < 0) {
@@ -131,6 +132,10 @@ class UInt64 extends UInt {
131
132
  toBytes(): Uint8Array {
132
133
  return this.bytes
133
134
  }
135
+
136
+ getSType(): SerializedTypeID {
137
+ return SerializedTypeID.STI_UINT64
138
+ }
134
139
  }
135
140
 
136
141
  export { UInt64 }
@@ -2,6 +2,7 @@ import { UInt } from './uint'
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { bytesToHex } from '@xrplf/isomorphic/utils'
4
4
  import { writeUInt8 } from '../utils'
5
+ import { SerializedTypeID } from './serialized-type'
5
6
 
6
7
  /**
7
8
  * Derived UInt class for serializing/deserializing 8 bit UInt
@@ -47,6 +48,10 @@ class UInt8 extends UInt {
47
48
  valueOf(): number {
48
49
  return parseInt(bytesToHex(this.bytes), 16)
49
50
  }
51
+
52
+ getSType(): SerializedTypeID {
53
+ return SerializedTypeID.STI_UINT8
54
+ }
50
55
  }
51
56
 
52
57
  export { UInt8 }
@@ -1,4 +1,4 @@
1
- import { SerializedType } from './serialized-type'
1
+ import { SerializedType, SerializedTypeID } from './serialized-type'
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { Hash256 } from './hash-256'
4
4
  import { BytesList } from '../serdes/binary-serializer'
@@ -74,6 +74,10 @@ class Vector256 extends SerializedType {
74
74
  }
75
75
  return result
76
76
  }
77
+
78
+ getSType(): SerializedTypeID {
79
+ return SerializedTypeID.STI_VECTOR256
80
+ }
77
81
  }
78
82
 
79
83
  export { Vector256 }
@@ -1,7 +1,7 @@
1
1
  import { BinaryParser } from '../serdes/binary-parser'
2
2
 
3
3
  import { AccountID } from './account-id'
4
- import { JsonObject, SerializedType } from './serialized-type'
4
+ import { JsonObject, SerializedType, SerializedTypeID } from './serialized-type'
5
5
  import { Issue, IssueObject } from './issue'
6
6
  import { concat } from '@xrplf/isomorphic/utils'
7
7
 
@@ -123,6 +123,10 @@ class XChainBridge extends SerializedType {
123
123
  })
124
124
  return json as XChainBridgeObject
125
125
  }
126
+
127
+ getSType(): SerializedTypeID {
128
+ return SerializedTypeID.STI_XCHAIN_BRIDGE
129
+ }
126
130
  }
127
131
 
128
132
  export { XChainBridge, XChainBridgeObject }
package/src/utils.ts CHANGED
@@ -196,7 +196,7 @@ export function compare(a: TypedArray, b: TypedArray): 1 | -1 | 0 {
196
196
  throw new Error('Cannot compare arrays of different length')
197
197
  }
198
198
 
199
- for (let i = 0; i < a.length - 1; i += 1) {
199
+ for (let i = 0; i < a.length; i += 1) {
200
200
  if (a[i] > b[i]) return 1
201
201
  if (a[i] < b[i]) return -1
202
202
  }