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
@@ -1,4 +1,5 @@
1
1
  import { Hash } from './hash'
2
+ import { SerializedTypeID } from './serialized-type'
2
3
 
3
4
  /**
4
5
  * Hash with a width of 160 bits
@@ -14,6 +15,10 @@ class Hash160 extends Hash {
14
15
 
15
16
  super(bytes ?? Hash160.ZERO_160.bytes)
16
17
  }
18
+
19
+ getSType(): SerializedTypeID {
20
+ return SerializedTypeID.STI_UINT160
21
+ }
17
22
  }
18
23
 
19
24
  export { Hash160 }
@@ -1,4 +1,5 @@
1
1
  import { Hash } from './hash'
2
+ import { SerializedTypeID } from './serialized-type'
2
3
 
3
4
  /**
4
5
  * Hash with a width of 192 bits
@@ -14,6 +15,10 @@ class Hash192 extends Hash {
14
15
 
15
16
  super(bytes ?? Hash192.ZERO_192.bytes)
16
17
  }
18
+
19
+ getSType(): SerializedTypeID {
20
+ return SerializedTypeID.STI_UINT192
21
+ }
17
22
  }
18
23
 
19
24
  export { Hash192 }
@@ -1,4 +1,5 @@
1
1
  import { Hash } from './hash'
2
+ import { SerializedTypeID } from './serialized-type'
2
3
 
3
4
  /**
4
5
  * Hash with a width of 256 bits
@@ -10,6 +11,10 @@ class Hash256 extends Hash {
10
11
  constructor(bytes: Uint8Array) {
11
12
  super(bytes ?? Hash256.ZERO_256.bytes)
12
13
  }
14
+
15
+ getSType(): SerializedTypeID {
16
+ return SerializedTypeID.STI_UINT256
17
+ }
13
18
  }
14
19
 
15
20
  export { Hash256 }
@@ -2,6 +2,8 @@ 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'
7
9
  import { Hash192 } from './hash-192'
@@ -26,6 +28,8 @@ const coreTypes: Record<string, typeof SerializedType> = {
26
28
  Amount,
27
29
  Blob,
28
30
  Currency,
31
+ Data,
32
+ DataType,
29
33
  Hash128,
30
34
  Hash160,
31
35
  Hash192,
@@ -55,6 +59,8 @@ export {
55
59
  Amount,
56
60
  Blob,
57
61
  Currency,
62
+ Data,
63
+ DataType,
58
64
  Hash128,
59
65
  Hash160,
60
66
  Hash192,
@@ -1,26 +1,37 @@
1
- import { UInt } from './uint'
1
+ import { Int } from './int'
2
2
  import { BinaryParser } from '../serdes/binary-parser'
3
3
  import { readInt32BE, writeInt32BE } from '../utils'
4
4
 
5
5
  /**
6
- * Derived Int class for serializing/deserializing 32 bit Int
6
+ * Derived Int class for serializing/deserializing signed 32-bit integers.
7
7
  */
8
- class Int32 extends UInt {
9
- protected static readonly width: number = 32 / 8 // 4
8
+ class Int32 extends Int {
9
+ protected static readonly width: number = 32 / 8 // 4 bytes
10
10
  static readonly defaultInt32: Int32 = new Int32(new Uint8Array(Int32.width))
11
11
 
12
+ // Signed 32-bit integer range
13
+ static readonly MIN_VALUE: number = -2147483648 // -2^31
14
+ static readonly MAX_VALUE: number = 2147483647 // 2^31 - 1
15
+
12
16
  constructor(bytes: Uint8Array) {
13
17
  super(bytes ?? Int32.defaultInt32.bytes)
14
18
  }
15
19
 
16
- static fromParser(parser: BinaryParser): UInt {
20
+ /**
21
+ * Construct an Int32 from a BinaryParser
22
+ *
23
+ * @param parser BinaryParser to read Int32 from
24
+ * @returns An Int32 object
25
+ */
26
+ static fromParser(parser: BinaryParser): Int {
17
27
  return new Int32(parser.read(Int32.width))
18
28
  }
19
29
 
20
30
  /**
21
- * Construct a Int32 object from a number
31
+ * Construct an Int32 object from a number or string
22
32
  *
23
- * @param val Int32 object or number
33
+ * @param val Int32 object, number, or string
34
+ * @returns An Int32 object
24
35
  */
25
36
  static from<T extends Int32 | number | string>(val: T): Int32 {
26
37
  if (val instanceof Int32) {
@@ -30,13 +41,17 @@ class Int32 extends UInt {
30
41
  const buf = new Uint8Array(Int32.width)
31
42
 
32
43
  if (typeof val === 'string') {
33
- const num = Number.parseInt(val)
44
+ const num = Number(val)
45
+ if (!Number.isFinite(num) || !Number.isInteger(num)) {
46
+ throw new Error(`Cannot construct Int32 from string: ${val}`)
47
+ }
48
+ Int32.checkIntRange('Int32', num, Int32.MIN_VALUE, Int32.MAX_VALUE)
34
49
  writeInt32BE(buf, num, 0)
35
50
  return new Int32(buf)
36
51
  }
37
52
 
38
- if (typeof val === 'number') {
39
- Int32.checkUintRange(val, -2147483648, 2147483647)
53
+ if (typeof val === 'number' && Number.isInteger(val)) {
54
+ Int32.checkIntRange('Int32', val, Int32.MIN_VALUE, Int32.MAX_VALUE)
40
55
  writeInt32BE(buf, val, 0)
41
56
  return new Int32(buf)
42
57
  }
@@ -45,9 +60,9 @@ class Int32 extends UInt {
45
60
  }
46
61
 
47
62
  /**
48
- * get the value of a Int32 object
63
+ * Get the value of the Int32 object
49
64
  *
50
- * @returns the number represented by this.bytes
65
+ * @returns the signed 32-bit integer represented by this.bytes
51
66
  */
52
67
  valueOf(): number {
53
68
  return readInt32BE(this.bytes, 0)
@@ -0,0 +1,75 @@
1
+ import { Comparable } from './serialized-type'
2
+
3
+ /**
4
+ * Compare numbers and bigInts n1 and n2
5
+ *
6
+ * @param n1 First object to compare
7
+ * @param n2 Second object to compare
8
+ * @returns -1, 0, or 1, depending on how the two objects compare
9
+ */
10
+ function compare(n1: number | bigint, n2: number | bigint): number {
11
+ return n1 < n2 ? -1 : n1 == n2 ? 0 : 1
12
+ }
13
+
14
+ /**
15
+ * Base class for serializing and deserializing signed integers.
16
+ */
17
+ abstract class Int extends Comparable<Int | number> {
18
+ protected static width: number
19
+
20
+ constructor(bytes: Uint8Array) {
21
+ super(bytes)
22
+ }
23
+
24
+ /**
25
+ * Overload of compareTo for Comparable
26
+ *
27
+ * @param other other Int to compare this to
28
+ * @returns -1, 0, or 1 depending on how the objects relate to each other
29
+ */
30
+ compareTo(other: Int | number): number {
31
+ return compare(this.valueOf(), other.valueOf())
32
+ }
33
+
34
+ /**
35
+ * Convert an Int object to JSON
36
+ *
37
+ * @returns number or string represented by this.bytes
38
+ */
39
+ toJSON(): number | string {
40
+ const val = this.valueOf()
41
+ return typeof val === 'number' ? val : val.toString()
42
+ }
43
+
44
+ /**
45
+ * Get the value of the Int represented by this.bytes
46
+ *
47
+ * @returns the value
48
+ */
49
+ abstract valueOf(): number | bigint
50
+
51
+ /**
52
+ * Validate that a number is within the specified signed integer range
53
+ *
54
+ * @param typeName The name of the type (for error messages)
55
+ * @param val The number to validate
56
+ * @param min The minimum allowed value
57
+ * @param max The maximum allowed value
58
+ * @throws Error if the value is out of range
59
+ */
60
+ // eslint-disable-next-line max-params -- for error clarity in browsers
61
+ static checkIntRange(
62
+ typeName: string,
63
+ val: number | bigint,
64
+ min: number | bigint,
65
+ max: number | bigint,
66
+ ): void {
67
+ if (val < min || val > max) {
68
+ throw new Error(
69
+ `Invalid ${typeName}: ${val} must be >= ${min} and <= ${max}`,
70
+ )
71
+ }
72
+ }
73
+ }
74
+
75
+ export { Int }
@@ -3,7 +3,7 @@ import { BinaryParser } from '../serdes/binary-parser'
3
3
 
4
4
  import { AccountID } from './account-id'
5
5
  import { Currency } from './currency'
6
- import { JsonObject, SerializedType } from './serialized-type'
6
+ import { JsonObject, SerializedType, SerializedTypeID } from './serialized-type'
7
7
  import { Hash192 } from './hash-192'
8
8
  import { readUInt32BE, writeUInt32BE } from '../utils'
9
9
 
@@ -158,6 +158,10 @@ class Issue extends SerializedType {
158
158
  issuer: issuer.toJSON(),
159
159
  }
160
160
  }
161
+
162
+ getSType(): SerializedTypeID {
163
+ return SerializedTypeID.STI_ISSUE
164
+ }
161
165
  }
162
166
 
163
167
  export { Issue, IssueObject }