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/CHANGELOG.md +13 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.global.js +35 -26
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +35 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1323,31 +1323,6 @@ function addCompiledFlag(compiled) {
|
|
|
1323
1323
|
}
|
|
1324
1324
|
|
|
1325
1325
|
// src/utils/cairoDataTypes/felt.ts
|
|
1326
|
-
function CairoFelt(it) {
|
|
1327
|
-
if (isBigInt(it) || Number.isInteger(it)) {
|
|
1328
|
-
return it.toString();
|
|
1329
|
-
}
|
|
1330
|
-
if (isString(it)) {
|
|
1331
|
-
if (isHex(it)) {
|
|
1332
|
-
return BigInt(it).toString();
|
|
1333
|
-
}
|
|
1334
|
-
if (isText(it)) {
|
|
1335
|
-
if (!isShortString(it)) {
|
|
1336
|
-
throw new Error(
|
|
1337
|
-
`${it} is a long string > 31 chars. Please split it into an array of short strings.`
|
|
1338
|
-
);
|
|
1339
|
-
}
|
|
1340
|
-
return BigInt(encodeShortString(it)).toString();
|
|
1341
|
-
}
|
|
1342
|
-
if (isStringWholeNumber(it)) {
|
|
1343
|
-
return it;
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
if (isBoolean(it)) {
|
|
1347
|
-
return `${+it}`;
|
|
1348
|
-
}
|
|
1349
|
-
throw new Error(`${it} can't be computed by felt()`);
|
|
1350
|
-
}
|
|
1351
1326
|
var CairoFelt252 = class _CairoFelt252 {
|
|
1352
1327
|
/**
|
|
1353
1328
|
* byte representation of the felt252
|
|
@@ -1386,6 +1361,9 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1386
1361
|
toApiRequest() {
|
|
1387
1362
|
return addCompiledFlag([this.toHexString()]);
|
|
1388
1363
|
}
|
|
1364
|
+
static assertRange(val) {
|
|
1365
|
+
assert(val >= 0n && val < PRIME, `Value ${val} is out of felt252 range [0, ${PRIME})`);
|
|
1366
|
+
}
|
|
1389
1367
|
static validate(data) {
|
|
1390
1368
|
assert(data !== null, "null value is not allowed for felt252");
|
|
1391
1369
|
assert(data !== void 0, "undefined value is not allowed for felt252");
|
|
@@ -1395,7 +1373,7 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1395
1373
|
);
|
|
1396
1374
|
const value = _CairoFelt252.__processData(data);
|
|
1397
1375
|
const bn = uint8ArrayToBigInt(value);
|
|
1398
|
-
|
|
1376
|
+
_CairoFelt252.assertRange(bn);
|
|
1399
1377
|
}
|
|
1400
1378
|
static is(data) {
|
|
1401
1379
|
try {
|
|
@@ -1412,6 +1390,37 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1412
1390
|
return new _CairoFelt252(getNext(responseIterator));
|
|
1413
1391
|
}
|
|
1414
1392
|
};
|
|
1393
|
+
function CairoFelt(it) {
|
|
1394
|
+
if (isBigInt(it) || Number.isInteger(it)) {
|
|
1395
|
+
const val = BigInt(it);
|
|
1396
|
+
CairoFelt252.assertRange(val);
|
|
1397
|
+
return val.toString();
|
|
1398
|
+
}
|
|
1399
|
+
if (isString(it)) {
|
|
1400
|
+
if (isHex(it)) {
|
|
1401
|
+
const val = BigInt(it);
|
|
1402
|
+
CairoFelt252.assertRange(val);
|
|
1403
|
+
return val.toString();
|
|
1404
|
+
}
|
|
1405
|
+
if (isText(it)) {
|
|
1406
|
+
if (!isShortString(it)) {
|
|
1407
|
+
throw new Error(
|
|
1408
|
+
`${it} is a long string > 31 chars. Please split it into an array of short strings.`
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
return BigInt(encodeShortString(it)).toString();
|
|
1412
|
+
}
|
|
1413
|
+
if (isStringWholeNumber(it)) {
|
|
1414
|
+
const val = BigInt(it);
|
|
1415
|
+
CairoFelt252.assertRange(val);
|
|
1416
|
+
return val.toString();
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
if (isBoolean(it)) {
|
|
1420
|
+
return `${+it}`;
|
|
1421
|
+
}
|
|
1422
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
1423
|
+
}
|
|
1415
1424
|
|
|
1416
1425
|
// src/utils/cairoDataTypes/uint256.ts
|
|
1417
1426
|
var UINT_128_MAX = (1n << 128n) - 1n;
|