starknet 10.0.3 → 10.0.4

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
+ ## [10.0.4](https://github.com/starknet-io/starknet.js/compare/v10.0.3...v10.0.4) (2026-06-04)
2
+
3
+ ### Bug Fixes
4
+
5
+ - add validation to cairofelt to ensure numbers are valid felt252 numbers ([f056836](https://github.com/starknet-io/starknet.js/commit/f0568369781e602a8a47dee76bb7ac13d152faaf))
6
+
1
7
  ## [10.0.3](https://github.com/starknet-io/starknet.js/compare/v10.0.2...v10.0.3) (2026-05-29)
2
8
 
3
9
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -9325,12 +9325,6 @@ declare class CairoBytes31 {
9325
9325
  static factoryFromApiResponse(responseIterator: Iterator<string>): CairoBytes31;
9326
9326
  }
9327
9327
 
9328
- /**
9329
- * @deprecated use the CairoFelt252 class instead, this one is limited to ASCII strings
9330
- * Create felt Cairo type (cairo type helper)
9331
- * @returns format: felt-string
9332
- */
9333
- declare function CairoFelt(it: BigNumberish): string;
9334
9328
  /**
9335
9329
  * felt252 is the basic field element used in Cairo.
9336
9330
  * It corresponds to an integer in the range 0 ≤ x < P where P is a very large prime number currently equal to 2^251 + 17⋅2^192 + 1.
@@ -9349,11 +9343,18 @@ declare class CairoFelt252 {
9349
9343
  decodeUtf8(): string;
9350
9344
  toHexString(): string;
9351
9345
  toApiRequest(): string[];
9346
+ static assertRange(val: bigint): void;
9352
9347
  static validate(data: BigNumberish | boolean | unknown): void;
9353
9348
  static is(data: BigNumberish | boolean | unknown): boolean;
9354
9349
  static isAbiType(abiType: string): boolean;
9355
9350
  static factoryFromApiResponse(responseIterator: Iterator<string>): CairoFelt252;
9356
9351
  }
9352
+ /**
9353
+ * @deprecated use the CairoFelt252 class instead, this one is limited to ASCII strings
9354
+ * Create felt Cairo type (cairo type helper)
9355
+ * @returns format: felt-string
9356
+ */
9357
+ declare function CairoFelt(it: BigNumberish): string;
9357
9358
 
9358
9359
  declare class CairoUint32 {
9359
9360
  data: bigint;
@@ -5547,31 +5547,6 @@ ${indent}}` : "}";
5547
5547
  }
5548
5548
 
5549
5549
  // src/utils/cairoDataTypes/felt.ts
5550
- function CairoFelt(it) {
5551
- if (isBigInt(it) || Number.isInteger(it)) {
5552
- return it.toString();
5553
- }
5554
- if (isString(it)) {
5555
- if (isHex2(it)) {
5556
- return BigInt(it).toString();
5557
- }
5558
- if (isText(it)) {
5559
- if (!isShortString(it)) {
5560
- throw new Error(
5561
- `${it} is a long string > 31 chars. Please split it into an array of short strings.`
5562
- );
5563
- }
5564
- return BigInt(encodeShortString(it)).toString();
5565
- }
5566
- if (isStringWholeNumber(it)) {
5567
- return it;
5568
- }
5569
- }
5570
- if (isBoolean(it)) {
5571
- return `${+it}`;
5572
- }
5573
- throw new Error(`${it} can't be computed by felt()`);
5574
- }
5575
5550
  var CairoFelt252 = class _CairoFelt252 {
5576
5551
  /**
5577
5552
  * byte representation of the felt252
@@ -5610,6 +5585,9 @@ ${indent}}` : "}";
5610
5585
  toApiRequest() {
5611
5586
  return addCompiledFlag([this.toHexString()]);
5612
5587
  }
5588
+ static assertRange(val) {
5589
+ assert(val >= 0n && val < PRIME, `Value ${val} is out of felt252 range [0, ${PRIME})`);
5590
+ }
5613
5591
  static validate(data) {
5614
5592
  assert(data !== null, "null value is not allowed for felt252");
5615
5593
  assert(data !== void 0, "undefined value is not allowed for felt252");
@@ -5619,7 +5597,7 @@ ${indent}}` : "}";
5619
5597
  );
5620
5598
  const value = _CairoFelt252.__processData(data);
5621
5599
  const bn = uint8ArrayToBigInt(value);
5622
- assert(bn >= 0n && bn < PRIME, `Value ${value} is out of felt252 range [0, ${PRIME})`);
5600
+ _CairoFelt252.assertRange(bn);
5623
5601
  }
5624
5602
  static is(data) {
5625
5603
  try {
@@ -5636,6 +5614,37 @@ ${indent}}` : "}";
5636
5614
  return new _CairoFelt252(getNext(responseIterator));
5637
5615
  }
5638
5616
  };
5617
+ function CairoFelt(it) {
5618
+ if (isBigInt(it) || Number.isInteger(it)) {
5619
+ const val = BigInt(it);
5620
+ CairoFelt252.assertRange(val);
5621
+ return val.toString();
5622
+ }
5623
+ if (isString(it)) {
5624
+ if (isHex2(it)) {
5625
+ const val = BigInt(it);
5626
+ CairoFelt252.assertRange(val);
5627
+ return val.toString();
5628
+ }
5629
+ if (isText(it)) {
5630
+ if (!isShortString(it)) {
5631
+ throw new Error(
5632
+ `${it} is a long string > 31 chars. Please split it into an array of short strings.`
5633
+ );
5634
+ }
5635
+ return BigInt(encodeShortString(it)).toString();
5636
+ }
5637
+ if (isStringWholeNumber(it)) {
5638
+ const val = BigInt(it);
5639
+ CairoFelt252.assertRange(val);
5640
+ return val.toString();
5641
+ }
5642
+ }
5643
+ if (isBoolean(it)) {
5644
+ return `${+it}`;
5645
+ }
5646
+ throw new Error(`${it} can't be computed by felt()`);
5647
+ }
5639
5648
 
5640
5649
  // src/utils/cairoDataTypes/uint256.ts
5641
5650
  var UINT_128_MAX = (1n << 128n) - 1n;