starknet 11.9.2 → 11.9.3

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [11.9.3](https://github.com/starknet-io/starknet.js/compare/v11.9.2...v11.9.3) (2026-11-26)
2
+
3
+ ### Bug Fixes
4
+
5
+ - toHex() refuses a negative value instead of returning 0x-5 ([#1767](https://github.com/starknet-io/starknet.js/issues/1767)) ([e2036f1](https://github.com/starknet-io/starknet.js/commit/e2036f13326f140b4cb78aede5d10361a0cff8de))
6
+
1
7
  ## [11.9.2](https://github.com/starknet-io/starknet.js/compare/v11.9.1...v11.9.2) (2026-11-25)
2
8
 
3
9
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -12283,13 +12283,16 @@ declare function tryToBigInt(value: BigNumberish | undefined): bigint | undefine
12283
12283
  /**
12284
12284
  * Convert BigNumberish to hex-string
12285
12285
  *
12286
+ * A negative value is refused: a hex-string has no sign, and `'0x-5'` is not one.
12286
12287
  * @param {BigNumberish} value value to convert
12287
12288
  * @returns {string} converted number in hex-string format
12289
+ * @throws {Error} when the value is negative, or cannot be read by {@link toBigInt}
12288
12290
  * @example
12289
12291
  * ```typescript
12290
12292
  * toHex(100); // '0x64'
12291
12293
  * toHex('200'); // '0xc8'
12292
12294
  * toHex('0x00023AB'); // '0x23ab'
12295
+ * toHex(-5); // throws Error('Invalid input: -5 is negative, a hex-string cannot hold a sign')
12293
12296
  * ```
12294
12297
  */
12295
12298
  declare function toHex(value: BigNumberish): string;
@@ -3089,17 +3089,21 @@ ${indent}}` : "}";
3089
3089
  return value ? BigInt(value) : void 0;
3090
3090
  }
3091
3091
  function toHex(value) {
3092
- return addHexPrefix(toBigInt(value).toString(16));
3092
+ const bn = toBigInt(value);
3093
+ if (bn < 0n) {
3094
+ throw new Error(`Invalid input: ${bn} is negative, a hex-string cannot hold a sign`);
3095
+ }
3096
+ return addHexPrefix(bn.toString(16));
3093
3097
  }
3094
3098
  var toHexString = toHex;
3095
3099
  function cleanHex(hex) {
3096
3100
  return toHex(hex);
3097
3101
  }
3098
3102
  function toStorageKey(number) {
3099
- return addHexPrefix(toBigInt(number).toString(16).padStart(64, "0"));
3103
+ return addHexPrefix(removeHexPrefix(toHex(number)).padStart(64, "0"));
3100
3104
  }
3101
3105
  function toHex64(number) {
3102
- const res = addHexPrefix(toBigInt(number).toString(16).padStart(64, "0"));
3106
+ const res = addHexPrefix(removeHexPrefix(toHex(number)).padStart(64, "0"));
3103
3107
  if (res.length !== 66) throw TypeError("number is too big for hex 0x(64) representation");
3104
3108
  return res;
3105
3109
  }
@@ -21779,14 +21783,16 @@ ${indent}}` : "}";
21779
21783
  return void 0;
21780
21784
  }
21781
21785
  function getHex(value) {
21786
+ let bn;
21782
21787
  try {
21783
- return toHex(value);
21788
+ bn = toBigInt(value);
21784
21789
  } catch (e) {
21785
21790
  if (isString(value)) {
21786
21791
  return toHex(CairoBytes31.fromText(value).toBigInt());
21787
21792
  }
21788
21793
  throw new Error(`Invalid BigNumberish: ${value}`);
21789
21794
  }
21795
+ return toHex(bn);
21790
21796
  }
21791
21797
  function validateTypedData(data) {
21792
21798
  const typedData = data;