ripple-binary-codec 2.4.1 → 2.5.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.
@@ -1 +1 @@
1
- {"version":3,"file":"st-object.js","sourceRoot":"","sources":["../../src/types/st-object.ts"],"names":[],"mappings":";;;AAAA,oCAKiB;AACjB,uDAA8D;AAC9D,+DAAgF;AAChF,2DAAsD;AACtD,mEAAyE;AAEzE,yCAAoC;AACpC,uCAAkC;AAElC,MAAM,sBAAsB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AACtD,MAAM,iBAAiB,GAAG,iBAAiB,CAAA;AAC3C,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,WAAW,GAAG,aAAa,CAAA;AACjC,MAAM,OAAO,GAAG,SAAS,CAAA;AACzB,MAAM,UAAU,GAAG,WAAW,CAAA;AAC9B,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AAEjC;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAa,EAAE,QAAgB;IACrD,MAAM,OAAO,GAAG,IAAA,+CAAwB,EAAC,QAAQ,CAAC,CAAA;IAElD,IAAI,OAAO,CAAA;IACX,IAAI,KAAK,KAAK,WAAW;QAAE,OAAO,GAAG,QAAQ,CAAA;SACxC,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,GAAG,UAAU,CAAA;SAC3C,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK;QAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,gCAAgC,CAAC,CAAA;IAE3D,OAAO,OAAO,CAAC,GAAG,KAAK,KAAK;QAC1B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,EAAE;QAC7D,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAA;AAC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BAC9D,sEAAsE;gBACtE,WAAW,GAAG,IAAI,CAAA;aACnB;YACD,oHAAoH;YACpH,gBAAgB;YAChB,4GAA4G;YAC5G,MAAM,qBAAqB,GAAG,KAAK,CAAC,IAAI,IAAI,SAAS,IAAI,WAAW,CAAA;YACpE,KAAK,CAAC,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,qBAAqB,CAAC,CAAA;YACvE,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;gBACjC,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;aAClC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,WAAiC;QACtC,MAAM,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,WAAW,CAAC,CAAA;QACnE,MAAM,WAAW,GAAG,EAAE,CAAA;QAEtB,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE;YAC1B,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,EAAE,CAAA;YACtC,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE;gBACpC,MAAK;aACN;YAED,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY;iBACnC,cAAc,CAAC,KAAK,CAAC;iBACrB,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;SACnC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;CACF;AAEQ,4BAAQ"}
@@ -8,10 +8,14 @@ const enums_1 = require("../enums");
8
8
  const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/;
9
9
  const BASE10_REGEX = /^[0-9]{1,20}$/;
10
10
  const mask = BigInt(0x00000000ffffffff);
11
- function useBase10(fieldName) {
12
- return (fieldName === 'MaximumAmount' ||
13
- fieldName === 'OutstandingAmount' ||
14
- fieldName === 'MPTAmount');
11
+ const BASE10_AMOUNT_FIELDS = new Set([
12
+ 'MaximumAmount',
13
+ 'OutstandingAmount',
14
+ 'MPTAmount',
15
+ 'LockedAmount',
16
+ ]);
17
+ function isBase10(fieldName) {
18
+ return BASE10_AMOUNT_FIELDS.has(fieldName);
15
19
  }
16
20
  /**
17
21
  * Derived UInt class for serializing/deserializing 64 bit UInt
@@ -45,7 +49,7 @@ class UInt64 extends uint_1.UInt {
45
49
  return new UInt64((0, utils_1.concat)(intBuf));
46
50
  }
47
51
  if (typeof val === 'string') {
48
- if (useBase10(fieldName)) {
52
+ if (isBase10(fieldName)) {
49
53
  if (!BASE10_REGEX.test(val)) {
50
54
  throw new Error(`${fieldName} ${val} is not a valid base 10 string`);
51
55
  }
@@ -73,7 +77,7 @@ class UInt64 extends uint_1.UInt {
73
77
  */
74
78
  toJSON(_definitions = enums_1.DEFAULT_DEFINITIONS, fieldName = '') {
75
79
  const hexString = (0, utils_1.bytesToHex)(this.bytes);
76
- if (useBase10(fieldName)) {
80
+ if (isBase10(fieldName)) {
77
81
  return BigInt('0x' + hexString).toString(10);
78
82
  }
79
83
  return hexString;
@@ -1 +1 @@
1
- {"version":3,"file":"uint-64.js","sourceRoot":"","sources":["../../src/types/uint-64.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,mDAAwE;AACxE,oCAAsD;AACtD,oCAAmE;AAEnE,MAAM,SAAS,GAAG,qBAAqB,CAAA;AACvC,MAAM,YAAY,GAAG,eAAe,CAAA;AACpC,MAAM,IAAI,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEvC,SAAS,SAAS,CAAC,SAAiB;IAClC,OAAO,CACL,SAAS,KAAK,eAAe;QAC7B,SAAS,KAAK,mBAAmB;QACjC,SAAS,KAAK,WAAW,CAC1B,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,MAAO,SAAQ,WAAI;IAMvB,YAAY,KAAiB;QAC3B,KAAK,CAA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AC7D,CAAC;IAED;;;;OAIG;IACH,MAAM,CACJ,eAAoC,2BAAmB,EACvD,SAAS,GAAG,EAAE;QAEd,MAAM,SAAS,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxC,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE;YACvB,OAAO,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;SAC7C;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,MAAM,GAAG,GAAG,MAAM,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACxD,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAA;IAClC,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;;AAGM,wBAAM;AA7Ga,YAAK,GAAW,EAAE,GAAG,CAAC,CAAA,CAAC,IAAI;AACrC,oBAAa,GAAW,IAAI,MAAM,CAChD,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAC7B,CAAA"}
package/dist/utils.d.ts CHANGED
@@ -21,6 +21,22 @@ export declare function writeUInt16BE(array: Uint8Array, value: number, offset:
21
21
  * @param offset plus the number of bytes written.
22
22
  */
23
23
  export declare function writeUInt32BE(array: Uint8Array, value: number, offset: number): void;
24
+ /**
25
+ * Writes a signed 32-bit integer to a Uint8Array at the specified offset (big-endian).
26
+ *
27
+ * @param array - The Uint8Array to write to.
28
+ * @param value - The signed 32-bit integer to write.
29
+ * @param offset - The offset at which to write.
30
+ */
31
+ export declare function writeInt32BE(array: Uint8Array, value: number, offset: number): void;
32
+ /**
33
+ * Writes a signed 64-bit integer (BigInt) to a Uint8Array at the specified offset (big-endian).
34
+ *
35
+ * @param array - The Uint8Array to write to.
36
+ * @param value - The signed 64-bit integer (BigInt) to write.
37
+ * @param offset - The offset at which to write.
38
+ */
39
+ export declare function writeInt64BE(array: Uint8Array, value: bigint, offset: number): void;
24
40
  /**
25
41
  * Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
26
42
  * @param array Uint8Array to read
@@ -33,6 +49,22 @@ export declare function readUInt16BE(array: Uint8Array, offset: number): string;
33
49
  * @param offset Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4
34
50
  */
35
51
  export declare function readUInt32BE(array: Uint8Array, offset: number): string;
52
+ /**
53
+ * Reads a signed 32-bit integer from a Uint8Array at the specified offset (big-endian).
54
+ *
55
+ * @param array - The Uint8Array to read from.
56
+ * @param offset - The offset at which to start reading.
57
+ * @returns The signed 32-bit integer.
58
+ */
59
+ export declare function readInt32BE(array: Uint8Array, offset: number): number;
60
+ /**
61
+ * Reads a signed 64-bit integer (BigInt) from a Uint8Array at the specified offset (big-endian).
62
+ *
63
+ * @param array - The Uint8Array to read from.
64
+ * @param offset - The offset at which to start reading.
65
+ * @returns The signed 64-bit integer (BigInt).
66
+ */
67
+ export declare function readInt64BE(array: Uint8Array, offset: number): bigint;
36
68
  /**
37
69
  * Compares two Uint8Array or ArrayBuffers
38
70
  * @param a first array to compare
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compare = exports.equal = exports.readUInt32BE = exports.readUInt16BE = exports.writeUInt32BE = exports.writeUInt16BE = exports.writeUInt8 = void 0;
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
4
  /**
5
5
  * Writes value to array at the specified offset. The value must be a valid unsigned 8-bit integer.
6
6
  * @param array Uint8Array to be written to
@@ -37,6 +37,28 @@ function writeUInt32BE(array, value, offset) {
37
37
  array[offset + 3] = value & 0xff;
38
38
  }
39
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;
40
62
  /**
41
63
  * Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
42
64
  * @param array Uint8Array to read
@@ -55,6 +77,28 @@ function readUInt32BE(array, offset) {
55
77
  return new DataView(array.buffer).getUint32(offset, false).toString(10);
56
78
  }
57
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;
58
102
  /**
59
103
  * Compares two Uint8Array or ArrayBuffers
60
104
  * @param a first array to compare
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACH,SAAgB,UAAU,CACxB,KAAiB,EACjB,KAAa,EACb,MAAc;IAEd,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACrB,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAA;AACvB,CAAC;AAPD,gCAOC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,KAAiB,EACjB,KAAa,EACb,MAAc;IAEd,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAErB,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,CAAA;IAC3B,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;AAC3B,CAAC;AATD,sCASC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,KAAiB,EACjB,KAAa,EACb,MAAc;IAEd,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACrC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACzC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,IAAI,CAAA;IACxC,KAAK,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AAG,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;IACpE,OAAO,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,CAAa,EAAE,CAAa;IAClD,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;KAC7D;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QACxC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAA;QACzB,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,CAAA;KAC3B;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAVD,0BAUC;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;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,6 +1,6 @@
1
1
  {
2
2
  "name": "ripple-binary-codec",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "XRP Ledger binary codec",
5
5
  "files": [
6
6
  "dist/*",
@@ -43,5 +43,6 @@
43
43
  "prettier": "@xrplf/prettier-config",
44
44
  "engines": {
45
45
  "node": ">= 18"
46
- }
46
+ },
47
+ "gitHead": "e95870560312321e7f0e5c5e806a7f44cd8458c8"
47
48
  }
@@ -7,6 +7,7 @@ import { Hash160 } from './hash-160'
7
7
  import { Hash192 } from './hash-192'
8
8
  import { Hash256 } from './hash-256'
9
9
  import { Issue } from './issue'
10
+ import { STNumber } from './st-number'
10
11
  import { PathSet } from './path-set'
11
12
  import { STArray } from './st-array'
12
13
  import { STObject } from './st-object'
@@ -29,6 +30,7 @@ const coreTypes: Record<string, typeof SerializedType> = {
29
30
  Hash192,
30
31
  Hash256,
31
32
  Issue,
33
+ Number: STNumber,
32
34
  PathSet,
33
35
  STArray,
34
36
  STObject,
@@ -0,0 +1,233 @@
1
+ import { BinaryParser } from '../serdes/binary-parser'
2
+ import { SerializedType } from './serialized-type'
3
+ import { writeInt32BE, writeInt64BE, readInt32BE, readInt64BE } from '../utils'
4
+
5
+ /**
6
+ * Constants for mantissa and exponent normalization per XRPL Number spec.
7
+ * These define allowed magnitude for mantissa and exponent after normalization.
8
+ */
9
+ const MIN_MANTISSA = BigInt('1000000000000000')
10
+ const MAX_MANTISSA = BigInt('9999999999999999')
11
+ const MIN_EXPONENT = -32768
12
+ const MAX_EXPONENT = 32768
13
+ const DEFAULT_VALUE_EXPONENT = -2147483648
14
+
15
+ /**
16
+ * Extract mantissa, exponent, and sign from a number string.
17
+ *
18
+ * @param val - The string representing the number (may be integer, decimal, or scientific notation).
19
+ * @returns Object containing mantissa (BigInt), exponent (number), and isNegative (boolean).
20
+ * @throws Error if the string cannot be parsed as a valid number.
21
+ *
22
+ * Examples:
23
+ * '123' -> { mantissa: 123n, exponent: 0, isNegative: false }
24
+ * '-00123.45' -> { mantissa: -12345n, exponent: -2, isNegative: true }
25
+ * '+7.1e2' -> { mantissa: 71n, exponent: -1 + 2 = 1, isNegative: false }
26
+ */
27
+ function extractNumberPartsFromString(val: string): {
28
+ mantissa: bigint
29
+ exponent: number
30
+ isNegative: boolean
31
+ } {
32
+ /**
33
+ * Regex for parsing decimal/float/scientific number strings with optional sign, integer, decimal, and exponent parts.
34
+ *
35
+ * Pattern: /^([-+]?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/
36
+ *
37
+ * Breakdown:
38
+ * 1. ([-+]?) - Optional '+' or '-' sign at the start.
39
+ * 2. ([0-9]+) - Integer part: one or more digits (leading zeros allowed).
40
+ * 3. (?:\.([0-9]+))? - Optional decimal point followed by one or more digits.
41
+ * 4. (?:[eE]([+-]?[0-9]+))? - Optional exponent, starting with 'e' or 'E', optional sign, and digits.
42
+ *
43
+ * Notes:
44
+ * - Leading zeros are accepted and normalized by code after parsing.
45
+ * - Empty decimal ('123.') and missing integer ('.456') are NOT matched—must be fully specified.
46
+ */
47
+ const regex = /^([-+]?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/
48
+ const match = regex.exec(val)
49
+ if (!match) throw new Error(`Unable to parse number from string: ${val}`)
50
+
51
+ const [, sign, intPart, fracPart, expPart] = match
52
+ // Remove leading zeros (unless the entire intPart is zeros)
53
+ const cleanIntPart = intPart.replace(/^0+(?=\d)/, '') || '0'
54
+
55
+ let mantissaStr = cleanIntPart
56
+ let exponent = 0
57
+
58
+ if (fracPart) {
59
+ mantissaStr += fracPart
60
+ exponent -= fracPart.length
61
+ }
62
+ if (expPart) exponent += parseInt(expPart, 10)
63
+
64
+ let mantissa = BigInt(mantissaStr)
65
+ if (sign === '-') mantissa = -mantissa
66
+ const isNegative = mantissa < BigInt(0)
67
+
68
+ return { mantissa, exponent, isNegative }
69
+ }
70
+
71
+ /**
72
+ * Normalize the mantissa and exponent to XRPL constraints.
73
+ *
74
+ * Ensures that after normalization, the mantissa is between MIN_MANTISSA and MAX_MANTISSA (unless zero).
75
+ * Adjusts the exponent as needed by shifting the mantissa left/right (multiplying/dividing by 10).
76
+ *
77
+ * @param mantissa - The unnormalized mantissa (BigInt).
78
+ * @param exponent - The unnormalized exponent (number).
79
+ * @returns An object with normalized mantissa and exponent.
80
+ * @throws Error if the number cannot be normalized within allowed exponent range.
81
+ */
82
+ function normalize(
83
+ mantissa: bigint,
84
+ exponent: number,
85
+ ): { mantissa: bigint; exponent: number } {
86
+ let m = mantissa < BigInt(0) ? -mantissa : mantissa
87
+ const isNegative = mantissa < BigInt(0)
88
+
89
+ while (m !== BigInt(0) && m < MIN_MANTISSA && exponent > MIN_EXPONENT) {
90
+ exponent -= 1
91
+ m *= BigInt(10)
92
+ }
93
+ while (m > MAX_MANTISSA) {
94
+ if (exponent >= MAX_EXPONENT)
95
+ throw new Error('Mantissa and exponent are too large')
96
+ exponent += 1
97
+ m /= BigInt(10)
98
+ }
99
+ if (isNegative) m = -m
100
+ return { mantissa: m, exponent }
101
+ }
102
+
103
+ /**
104
+ * STNumber: Encodes XRPL's "Number" type.
105
+ *
106
+ * - Always encoded as 12 bytes: 8-byte signed mantissa, 4-byte signed exponent, both big-endian.
107
+ * - Can only be constructed from a valid number string or another STNumber instance.
108
+ *
109
+ * Usage:
110
+ * STNumber.from("1.2345e5")
111
+ * STNumber.from("-123")
112
+ * STNumber.fromParser(parser)
113
+ */
114
+ export class STNumber extends SerializedType {
115
+ /** 12 zero bytes, represents canonical zero. */
116
+ static defaultBytes = new Uint8Array(12)
117
+
118
+ /**
119
+ * Construct a STNumber from 12 bytes (8 for mantissa, 4 for exponent).
120
+ * @param bytes - 12-byte Uint8Array
121
+ * @throws Error if input is not a Uint8Array of length 12.
122
+ */
123
+ constructor(bytes?: Uint8Array) {
124
+ const used = bytes ?? STNumber.defaultBytes
125
+ if (!(used instanceof Uint8Array) || used.length !== 12) {
126
+ throw new Error(
127
+ `STNumber must be constructed from a 12-byte Uint8Array, got ${used?.length}`,
128
+ )
129
+ }
130
+ super(used)
131
+ }
132
+
133
+ /**
134
+ * Construct from a number string (or another STNumber).
135
+ *
136
+ * @param value - A string, or STNumber instance.
137
+ * @returns STNumber instance.
138
+ * @throws Error if not a string or STNumber.
139
+ */
140
+ static from(value: unknown): STNumber {
141
+ if (value instanceof STNumber) {
142
+ return value
143
+ }
144
+ if (typeof value === 'string') {
145
+ return STNumber.fromValue(value)
146
+ }
147
+ throw new Error(
148
+ 'STNumber.from: Only string or STNumber instance is supported',
149
+ )
150
+ }
151
+
152
+ /**
153
+ * Construct from a number string (integer, decimal, or scientific notation).
154
+ * Handles normalization to XRPL Number constraints.
155
+ *
156
+ * @param val - The number as a string (e.g. '1.23', '-123e5').
157
+ * @returns STNumber instance
158
+ * @throws Error if val is not a valid number string.
159
+ */
160
+ static fromValue(val: string): STNumber {
161
+ const { mantissa, exponent, isNegative } = extractNumberPartsFromString(val)
162
+ let normalizedMantissa: bigint
163
+ let normalizedExponent: number
164
+
165
+ if (mantissa === BigInt(0) && exponent === 0 && !isNegative) {
166
+ normalizedMantissa = BigInt(0)
167
+ normalizedExponent = DEFAULT_VALUE_EXPONENT
168
+ } else {
169
+ ;({ mantissa: normalizedMantissa, exponent: normalizedExponent } =
170
+ normalize(mantissa, exponent))
171
+ }
172
+
173
+ const bytes = new Uint8Array(12)
174
+ writeInt64BE(bytes, normalizedMantissa, 0)
175
+ writeInt32BE(bytes, normalizedExponent, 8)
176
+ return new STNumber(bytes)
177
+ }
178
+
179
+ /**
180
+ * Read a STNumber from a BinaryParser stream (12 bytes).
181
+ * @param parser - BinaryParser positioned at the start of a number
182
+ * @returns STNumber instance
183
+ */
184
+ static fromParser(parser: BinaryParser): STNumber {
185
+ return new STNumber(parser.read(12))
186
+ }
187
+
188
+ /**
189
+ * Convert this STNumber to a normalized string representation.
190
+ * The output is decimal or scientific notation, depending on exponent range.
191
+ * Follows XRPL convention: zero is "0", other values are normalized to a canonical string.
192
+ *
193
+ * @returns String representation of the value
194
+ */
195
+ // eslint-disable-next-line complexity -- required
196
+ toJSON(): string {
197
+ const b = this.bytes
198
+ if (!b || b.length !== 12)
199
+ throw new Error('STNumber internal bytes not set or wrong length')
200
+
201
+ // Signed 64-bit mantissa
202
+ const mantissa = readInt64BE(b, 0)
203
+ // Signed 32-bit exponent
204
+ const exponent = readInt32BE(b, 8)
205
+
206
+ // Special zero: XRPL encodes canonical zero as mantissa=0, exponent=DEFAULT_VALUE_EXPONENT.
207
+ if (mantissa === BigInt(0) && exponent === DEFAULT_VALUE_EXPONENT) {
208
+ return '0'
209
+ }
210
+ if (exponent === 0) return mantissa.toString()
211
+
212
+ // Use scientific notation for small/large exponents, decimal otherwise
213
+ if (exponent < -25 || exponent > -5) {
214
+ return `${mantissa}e${exponent}`
215
+ }
216
+
217
+ // Decimal rendering for -25 <= exp <= -5
218
+ const isNegative = mantissa < BigInt(0)
219
+ const mantissaAbs = mantissa < BigInt(0) ? -mantissa : mantissa
220
+
221
+ const padPrefix = 27
222
+ const padSuffix = 23
223
+ const mantissaStr = mantissaAbs.toString()
224
+ const rawValue = '0'.repeat(padPrefix) + mantissaStr + '0'.repeat(padSuffix)
225
+ const OFFSET = exponent + 43
226
+ const integerPart = rawValue.slice(0, OFFSET).replace(/^0+/, '') || '0'
227
+ const fractionPart = rawValue.slice(OFFSET).replace(/0+$/, '')
228
+
229
+ return `${isNegative ? '-' : ''}${integerPart}${
230
+ fractionPart ? '.' + fractionPart : ''
231
+ }`
232
+ }
233
+ }
@@ -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(
@@ -8,12 +8,15 @@ const HEX_REGEX = /^[a-fA-F0-9]{1,16}$/
8
8
  const BASE10_REGEX = /^[0-9]{1,20}$/
9
9
  const mask = BigInt(0x00000000ffffffff)
10
10
 
11
- function useBase10(fieldName: string): boolean {
12
- return (
13
- fieldName === 'MaximumAmount' ||
14
- fieldName === 'OutstandingAmount' ||
15
- fieldName === 'MPTAmount'
16
- )
11
+ const BASE10_AMOUNT_FIELDS = new Set([
12
+ 'MaximumAmount',
13
+ 'OutstandingAmount',
14
+ 'MPTAmount',
15
+ 'LockedAmount',
16
+ ])
17
+
18
+ function isBase10(fieldName: string): boolean {
19
+ return BASE10_AMOUNT_FIELDS.has(fieldName)
17
20
  }
18
21
 
19
22
  /**
@@ -64,7 +67,7 @@ class UInt64 extends UInt {
64
67
  }
65
68
 
66
69
  if (typeof val === 'string') {
67
- if (useBase10(fieldName)) {
70
+ if (isBase10(fieldName)) {
68
71
  if (!BASE10_REGEX.test(val)) {
69
72
  throw new Error(`${fieldName} ${val} is not a valid base 10 string`)
70
73
  }
@@ -101,7 +104,7 @@ class UInt64 extends UInt {
101
104
  fieldName = '',
102
105
  ): string {
103
106
  const hexString = bytesToHex(this.bytes)
104
- if (useBase10(fieldName)) {
107
+ if (isBase10(fieldName)) {
105
108
  return BigInt('0x' + hexString).toString(10)
106
109
  }
107
110
 
package/src/utils.ts CHANGED
@@ -50,6 +50,44 @@ export function writeUInt32BE(
50
50
  array[offset + 3] = value & 0xff
51
51
  }
52
52
 
53
+ /**
54
+ * Writes a signed 32-bit integer to a Uint8Array at the specified offset (big-endian).
55
+ *
56
+ * @param array - The Uint8Array to write to.
57
+ * @param value - The signed 32-bit integer to write.
58
+ * @param offset - The offset at which to write.
59
+ */
60
+ export function writeInt32BE(
61
+ array: Uint8Array,
62
+ value: number,
63
+ offset: number,
64
+ ): void {
65
+ new DataView(array.buffer, array.byteOffset, array.byteLength).setInt32(
66
+ offset,
67
+ value,
68
+ false,
69
+ )
70
+ }
71
+
72
+ /**
73
+ * Writes a signed 64-bit integer (BigInt) to a Uint8Array at the specified offset (big-endian).
74
+ *
75
+ * @param array - The Uint8Array to write to.
76
+ * @param value - The signed 64-bit integer (BigInt) to write.
77
+ * @param offset - The offset at which to write.
78
+ */
79
+ export function writeInt64BE(
80
+ array: Uint8Array,
81
+ value: bigint,
82
+ offset: number,
83
+ ): void {
84
+ new DataView(array.buffer, array.byteOffset, array.byteLength).setBigInt64(
85
+ offset,
86
+ value,
87
+ false,
88
+ )
89
+ }
90
+
53
91
  /**
54
92
  * Reads an unsigned, big-endian 16-bit integer from the array at the specified offset.
55
93
  * @param array Uint8Array to read
@@ -68,6 +106,36 @@ export function readUInt32BE(array: Uint8Array, offset: number): string {
68
106
  return new DataView(array.buffer).getUint32(offset, false).toString(10)
69
107
  }
70
108
 
109
+ /**
110
+ * Reads a signed 32-bit integer from a Uint8Array at the specified offset (big-endian).
111
+ *
112
+ * @param array - The Uint8Array to read from.
113
+ * @param offset - The offset at which to start reading.
114
+ * @returns The signed 32-bit integer.
115
+ */
116
+ export function readInt32BE(array: Uint8Array, offset: number): number {
117
+ return new DataView(
118
+ array.buffer,
119
+ array.byteOffset,
120
+ array.byteLength,
121
+ ).getInt32(offset, false)
122
+ }
123
+
124
+ /**
125
+ * Reads a signed 64-bit integer (BigInt) from a Uint8Array at the specified offset (big-endian).
126
+ *
127
+ * @param array - The Uint8Array to read from.
128
+ * @param offset - The offset at which to start reading.
129
+ * @returns The signed 64-bit integer (BigInt).
130
+ */
131
+ export function readInt64BE(array: Uint8Array, offset: number): bigint {
132
+ return new DataView(
133
+ array.buffer,
134
+ array.byteOffset,
135
+ array.byteLength,
136
+ ).getBigInt64(offset, false)
137
+ }
138
+
71
139
  /**
72
140
  * Compares two Uint8Array or ArrayBuffers
73
141
  * @param a first array to compare
@@ -1,19 +0,0 @@
1
- import { BinaryParser } from '../serdes/binary-parser';
2
- import { SerializedType } from './serialized-type';
3
- /**
4
- * SerializedType for the XRPL Number type (12 bytes).
5
- */
6
- export declare class SerializedNumber extends SerializedType {
7
- constructor(bytes: Uint8Array);
8
- /**
9
- * Creates a SerializedNumber from a string value.
10
- * Accepts only string input to avoid precision loss (as per XRPL and blockchain best practices).
11
- * Throws if a number or bigint is passed.
12
- * @param value string representing the number (decimal, integer, or scientific notation)
13
- * @returns SerializedNumber instance
14
- */
15
- static from(value: string): SerializedNumber;
16
- static fromValue(val: string): SerializedNumber;
17
- static fromParser(parser: BinaryParser): SerializedNumber;
18
- toJSON(): string;
19
- }