starknet 10.0.2 → 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/dist/index.mjs CHANGED
@@ -1143,31 +1143,6 @@ function addCompiledFlag(compiled) {
1143
1143
  }
1144
1144
 
1145
1145
  // src/utils/cairoDataTypes/felt.ts
1146
- function CairoFelt(it) {
1147
- if (isBigInt(it) || Number.isInteger(it)) {
1148
- return it.toString();
1149
- }
1150
- if (isString(it)) {
1151
- if (isHex(it)) {
1152
- return BigInt(it).toString();
1153
- }
1154
- if (isText(it)) {
1155
- if (!isShortString(it)) {
1156
- throw new Error(
1157
- `${it} is a long string > 31 chars. Please split it into an array of short strings.`
1158
- );
1159
- }
1160
- return BigInt(encodeShortString(it)).toString();
1161
- }
1162
- if (isStringWholeNumber(it)) {
1163
- return it;
1164
- }
1165
- }
1166
- if (isBoolean(it)) {
1167
- return `${+it}`;
1168
- }
1169
- throw new Error(`${it} can't be computed by felt()`);
1170
- }
1171
1146
  var CairoFelt252 = class _CairoFelt252 {
1172
1147
  /**
1173
1148
  * byte representation of the felt252
@@ -1206,6 +1181,9 @@ var CairoFelt252 = class _CairoFelt252 {
1206
1181
  toApiRequest() {
1207
1182
  return addCompiledFlag([this.toHexString()]);
1208
1183
  }
1184
+ static assertRange(val) {
1185
+ assert(val >= 0n && val < PRIME, `Value ${val} is out of felt252 range [0, ${PRIME})`);
1186
+ }
1209
1187
  static validate(data) {
1210
1188
  assert(data !== null, "null value is not allowed for felt252");
1211
1189
  assert(data !== void 0, "undefined value is not allowed for felt252");
@@ -1215,7 +1193,7 @@ var CairoFelt252 = class _CairoFelt252 {
1215
1193
  );
1216
1194
  const value = _CairoFelt252.__processData(data);
1217
1195
  const bn = uint8ArrayToBigInt(value);
1218
- assert(bn >= 0n && bn < PRIME, `Value ${value} is out of felt252 range [0, ${PRIME})`);
1196
+ _CairoFelt252.assertRange(bn);
1219
1197
  }
1220
1198
  static is(data) {
1221
1199
  try {
@@ -1232,6 +1210,37 @@ var CairoFelt252 = class _CairoFelt252 {
1232
1210
  return new _CairoFelt252(getNext(responseIterator));
1233
1211
  }
1234
1212
  };
1213
+ function CairoFelt(it) {
1214
+ if (isBigInt(it) || Number.isInteger(it)) {
1215
+ const val = BigInt(it);
1216
+ CairoFelt252.assertRange(val);
1217
+ return val.toString();
1218
+ }
1219
+ if (isString(it)) {
1220
+ if (isHex(it)) {
1221
+ const val = BigInt(it);
1222
+ CairoFelt252.assertRange(val);
1223
+ return val.toString();
1224
+ }
1225
+ if (isText(it)) {
1226
+ if (!isShortString(it)) {
1227
+ throw new Error(
1228
+ `${it} is a long string > 31 chars. Please split it into an array of short strings.`
1229
+ );
1230
+ }
1231
+ return BigInt(encodeShortString(it)).toString();
1232
+ }
1233
+ if (isStringWholeNumber(it)) {
1234
+ const val = BigInt(it);
1235
+ CairoFelt252.assertRange(val);
1236
+ return val.toString();
1237
+ }
1238
+ }
1239
+ if (isBoolean(it)) {
1240
+ return `${+it}`;
1241
+ }
1242
+ throw new Error(`${it} can't be computed by felt()`);
1243
+ }
1235
1244
 
1236
1245
  // src/utils/cairoDataTypes/uint256.ts
1237
1246
  var UINT_128_MAX = (1n << 128n) - 1n;