starknet 11.0.1 → 11.0.2
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 +6 -0
- package/dist/index.d.ts +315 -112
- package/dist/index.global.js +289 -110
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +289 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +289 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -246,6 +246,7 @@ __export(constants_exports, {
|
|
|
246
246
|
OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
|
|
247
247
|
PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
|
|
248
248
|
PRIME: () => PRIME,
|
|
249
|
+
RANGE_CLASS_HASH: () => RANGE_CLASS_HASH,
|
|
249
250
|
RANGE_CONTRACT_ADDRESS: () => RANGE_CONTRACT_ADDRESS,
|
|
250
251
|
RANGE_ETH_ADDRESS: () => RANGE_ETH_ADDRESS,
|
|
251
252
|
RANGE_FELT: () => RANGE_FELT,
|
|
@@ -484,6 +485,7 @@ var RANGE_I64 = range(-(2n ** 63n), 2n ** 63n - 1n);
|
|
|
484
485
|
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
485
486
|
var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
|
|
486
487
|
var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
|
|
488
|
+
var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
|
|
487
489
|
var LegacyUDC = {
|
|
488
490
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
489
491
|
ENTRYPOINT: "deployContract"
|
|
@@ -961,6 +963,7 @@ __export(num_exports, {
|
|
|
961
963
|
hexToBytes: () => hexToBytes,
|
|
962
964
|
hexToDecimalString: () => hexToDecimalString,
|
|
963
965
|
isBigNumberish: () => isBigNumberish,
|
|
966
|
+
isEmptyHex: () => isEmptyHex,
|
|
964
967
|
isHex: () => isHex,
|
|
965
968
|
isHexString: () => isHexString2,
|
|
966
969
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
@@ -1016,6 +1019,7 @@ function isHex(hex) {
|
|
|
1016
1019
|
}
|
|
1017
1020
|
var isHexString2 = isHex;
|
|
1018
1021
|
function toBigInt(value) {
|
|
1022
|
+
assert(!isEmptyHex(value), "Invalid input: '0x' holds no hexadecimal digit");
|
|
1019
1023
|
return BigInt(value);
|
|
1020
1024
|
}
|
|
1021
1025
|
function tryToBigInt(value) {
|
|
@@ -1040,13 +1044,13 @@ function hexToDecimalString(hex) {
|
|
|
1040
1044
|
return BigInt(addHexPrefix(hex)).toString(10);
|
|
1041
1045
|
}
|
|
1042
1046
|
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
1043
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
1044
1047
|
const inputBigInt = BigInt(input);
|
|
1045
1048
|
const lowerBoundBigInt = BigInt(lowerBound);
|
|
1046
1049
|
const upperBoundBigInt = BigInt(upperBound);
|
|
1050
|
+
const rangeName = inputName === "" ? "range" : `${inputName} range`;
|
|
1047
1051
|
assert(
|
|
1048
1052
|
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
1049
|
-
`
|
|
1053
|
+
`Value is out of ${rangeName} [${lowerBoundBigInt}, ${upperBoundBigInt}]`
|
|
1050
1054
|
);
|
|
1051
1055
|
}
|
|
1052
1056
|
function bigNumberishArrayToDecimalStringArray(data) {
|
|
@@ -1099,8 +1103,11 @@ function stringToSha256ToArrayBuff4(str) {
|
|
|
1099
1103
|
const result = int31(BigInt(addHexPrefix(buf2hex((0, import_sha2.sha256)((0, import_utils2.utf8ToBytes)(str))))));
|
|
1100
1104
|
return hexToBytes(toHex(result));
|
|
1101
1105
|
}
|
|
1106
|
+
function isEmptyHex(value) {
|
|
1107
|
+
return isString(value) && /^0x$/i.test(value);
|
|
1108
|
+
}
|
|
1102
1109
|
function isBigNumberish(input) {
|
|
1103
|
-
return isNumber(input) || isBigInt(input) || isString(input) && (isHex(input) || isStringWholeNumber(input));
|
|
1110
|
+
return isNumber(input) || isBigInt(input) || isString(input) && (isHex(input) && !isEmptyHex(input) || isStringWholeNumber(input));
|
|
1104
1111
|
}
|
|
1105
1112
|
function getNext(iterator) {
|
|
1106
1113
|
const it = iterator.next();
|
|
@@ -1684,16 +1691,18 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1684
1691
|
/**
|
|
1685
1692
|
* Throw unless the value can be carried by a felt252.
|
|
1686
1693
|
*
|
|
1687
|
-
* Null, undefined
|
|
1688
|
-
* message, then the value is converted and its range checked. A negative number does not
|
|
1689
|
-
* that range check : converting it fails earlier, and the message comes from the conversion.
|
|
1694
|
+
* Null, undefined, any type this class does not read, and `'0x'` are refused first, each with its
|
|
1695
|
+
* own message, then the value is converted and its range checked. A negative number does not
|
|
1696
|
+
* reach that range check : converting it fails earlier, and the message comes from the conversion.
|
|
1690
1697
|
* @param {BigNumberish | boolean} data the value to check
|
|
1691
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, P)
|
|
1698
|
+
* @throws {Error} when the value is null, undefined, of an unread type, `'0x'`, or outside [0, P)
|
|
1692
1699
|
* @example
|
|
1693
1700
|
* ```typescript
|
|
1694
1701
|
* CairoFelt252.validate('Hello'); // passes
|
|
1695
1702
|
* CairoFelt252.validate({});
|
|
1696
1703
|
* // throws Error("Unsupported data type 'object' for felt252. Expected string, number, bigint, or boolean")
|
|
1704
|
+
* CairoFelt252.validate('0x');
|
|
1705
|
+
* // throws Error("Invalid input: '0x' holds no hexadecimal digit")
|
|
1697
1706
|
* CairoFelt252.validate(-1);
|
|
1698
1707
|
* // throws Error("Cannot convert negative bigint -1 to Uint8Array")
|
|
1699
1708
|
* ```
|
|
@@ -1705,6 +1714,7 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1705
1714
|
isString(data) || isNumber(data) || isBigInt(data) || isBoolean(data),
|
|
1706
1715
|
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
1707
1716
|
);
|
|
1717
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
1708
1718
|
const value = _CairoFelt252.__processData(data);
|
|
1709
1719
|
const bn = uint8ArrayToBigInt(value);
|
|
1710
1720
|
_CairoFelt252.assertRange(bn);
|
|
@@ -2521,7 +2531,7 @@ var CairoUint32 = class _CairoUint32 {
|
|
|
2521
2531
|
* otherwise. Text therefore only fits here up to 4 ASCII characters : one more already
|
|
2522
2532
|
* makes a number past 4294967295.
|
|
2523
2533
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 4294967295]
|
|
2524
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
2534
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
2525
2535
|
* @example
|
|
2526
2536
|
* ```typescript
|
|
2527
2537
|
* const result = new CairoUint32('abcd').toApiRequest();
|
|
@@ -2609,11 +2619,11 @@ var CairoUint32 = class _CairoUint32 {
|
|
|
2609
2619
|
/**
|
|
2610
2620
|
* Throw unless the value can be carried by a u32.
|
|
2611
2621
|
*
|
|
2612
|
-
*
|
|
2613
|
-
* an array, a number with a decimal part, and a value outside [0, 4294967295]. A text string reaches
|
|
2622
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
2623
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 4294967295]. A text string reaches
|
|
2614
2624
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
2615
2625
|
* @param {BigNumberish | boolean} data the value to check
|
|
2616
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
2626
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
2617
2627
|
* @example
|
|
2618
2628
|
* ```typescript
|
|
2619
2629
|
* CairoUint32.validate(70000); // passes
|
|
@@ -2628,6 +2638,7 @@ var CairoUint32 = class _CairoUint32 {
|
|
|
2628
2638
|
!isNumber(data) || Number.isInteger(data),
|
|
2629
2639
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
2630
2640
|
);
|
|
2641
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
2631
2642
|
const value = _CairoUint32.__processData(data);
|
|
2632
2643
|
assert(
|
|
2633
2644
|
value >= RANGE_U32.min && value <= RANGE_U32.max,
|
|
@@ -3259,25 +3270,37 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3259
3270
|
* Throw unless a whole value can be represented as a u256, and give back its number.
|
|
3260
3271
|
*
|
|
3261
3272
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
3262
|
-
* refused
|
|
3273
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint256`
|
|
3274
|
+
* one included : its two halves are checked by {@link CairoUint256.validateProps}, which is what
|
|
3275
|
+
* the constructor calls for it.
|
|
3263
3276
|
* @param {BigNumberish} bigNumberish the value to check
|
|
3264
3277
|
* @returns {bigint} the value as a number, once accepted
|
|
3265
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or out of range
|
|
3278
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
3266
3279
|
* @example
|
|
3267
3280
|
* ```typescript
|
|
3268
3281
|
* const result = CairoUint256.validate(255);
|
|
3269
3282
|
* // result = 255n
|
|
3270
3283
|
* CairoUint256.validate(-1);
|
|
3271
3284
|
* // throws Error("bigNumberish is smaller than UINT_256_MIN")
|
|
3285
|
+
* CairoUint256.validate('abc');
|
|
3286
|
+
* // throws Error("Invalid input: a u256 cannot be built from text")
|
|
3287
|
+
* CairoUint256.validate(1.5);
|
|
3288
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
3272
3289
|
* ```
|
|
3273
3290
|
*/
|
|
3274
3291
|
static validate(bigNumberish) {
|
|
3275
3292
|
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
3276
3293
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
3294
|
+
assert(!isText(bigNumberish), "Invalid input: a u256 cannot be built from text");
|
|
3295
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3277
3296
|
assert(
|
|
3278
|
-
isBigNumberish(bigNumberish)
|
|
3297
|
+
isBigNumberish(bigNumberish),
|
|
3279
3298
|
`Unsupported data type '${typeof bigNumberish}' for u256. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint256 object`
|
|
3280
3299
|
);
|
|
3300
|
+
assert(
|
|
3301
|
+
!isNumber(bigNumberish) || Number.isInteger(bigNumberish),
|
|
3302
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
3303
|
+
);
|
|
3281
3304
|
const bigInt = BigInt(bigNumberish);
|
|
3282
3305
|
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
3283
3306
|
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
@@ -3291,18 +3314,31 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3291
3314
|
* @param {BigNumberish} low the bottom 128 bits
|
|
3292
3315
|
* @param {BigNumberish} high the top 128 bits
|
|
3293
3316
|
* @returns {{low: bigint, high: bigint}} the two halves as numbers
|
|
3294
|
-
* @throws {Error} when either half is outside the u128 range
|
|
3317
|
+
* @throws {Error} when either half is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
3295
3318
|
* @example
|
|
3296
3319
|
* ```typescript
|
|
3297
3320
|
* const result = CairoUint256.validateProps(5, 4);
|
|
3298
3321
|
* // result = { low: 5n, high: 4n }
|
|
3299
3322
|
* CairoUint256.validateProps(-1, 4);
|
|
3300
3323
|
* // throws Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX")
|
|
3324
|
+
* CairoUint256.validateProps(1.5, 4);
|
|
3325
|
+
* // throws Error("low must be an integer")
|
|
3326
|
+
* CairoUint256.validateProps('abc', 4);
|
|
3327
|
+
* // throws Error("low cannot be built from text")
|
|
3301
3328
|
* ```
|
|
3302
3329
|
*/
|
|
3303
3330
|
static validateProps(low, high) {
|
|
3304
|
-
const
|
|
3305
|
-
|
|
3331
|
+
const validateHalf = (half, name) => {
|
|
3332
|
+
assert(half !== null, `${name} cannot be null`);
|
|
3333
|
+
assert(half !== void 0, `${name} cannot be undefined`);
|
|
3334
|
+
assert(!isText(half), `${name} cannot be built from text`);
|
|
3335
|
+
assert(!isEmptyHex(half), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
3336
|
+
assert(isBigNumberish(half), `${name} must be a BigNumberish`);
|
|
3337
|
+
assert(!isNumber(half) || Number.isInteger(half), `${name} must be an integer`);
|
|
3338
|
+
return BigInt(half);
|
|
3339
|
+
};
|
|
3340
|
+
const bigIntLow = validateHalf(low, "low");
|
|
3341
|
+
const bigIntHigh = validateHalf(high, "high");
|
|
3306
3342
|
assert(
|
|
3307
3343
|
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
3308
3344
|
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
@@ -3511,25 +3547,37 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3511
3547
|
* Throw unless a whole value can be represented as a u512, and give back its number.
|
|
3512
3548
|
*
|
|
3513
3549
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
3514
|
-
* refused
|
|
3550
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint512`
|
|
3551
|
+
* one included : its four limbs are checked by {@link CairoUint512.validateProps}, which is what
|
|
3552
|
+
* the constructor calls for it.
|
|
3515
3553
|
* @param {BigNumberish} bigNumberish the value to check
|
|
3516
3554
|
* @returns {bigint} the value as a number, once accepted
|
|
3517
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or out of range
|
|
3555
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
3518
3556
|
* @example
|
|
3519
3557
|
* ```typescript
|
|
3520
3558
|
* const result = CairoUint512.validate(255);
|
|
3521
3559
|
* // result = 255n
|
|
3522
3560
|
* CairoUint512.validate(-1);
|
|
3523
3561
|
* // throws Error("bigNumberish is smaller than UINT_512_MIN.")
|
|
3562
|
+
* CairoUint512.validate('abc');
|
|
3563
|
+
* // throws Error("Invalid input: a u512 cannot be built from text")
|
|
3564
|
+
* CairoUint512.validate(1.5);
|
|
3565
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
3524
3566
|
* ```
|
|
3525
3567
|
*/
|
|
3526
3568
|
static validate(bigNumberish) {
|
|
3527
3569
|
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
3528
3570
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
3571
|
+
assert(!isText(bigNumberish), "Invalid input: a u512 cannot be built from text");
|
|
3572
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3529
3573
|
assert(
|
|
3530
|
-
isBigNumberish(bigNumberish)
|
|
3574
|
+
isBigNumberish(bigNumberish),
|
|
3531
3575
|
`Unsupported data type '${typeof bigNumberish}' for u512. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint512 object`
|
|
3532
3576
|
);
|
|
3577
|
+
assert(
|
|
3578
|
+
!isNumber(bigNumberish) || Number.isInteger(bigNumberish),
|
|
3579
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
3580
|
+
);
|
|
3533
3581
|
const bigInt = BigInt(bigNumberish);
|
|
3534
3582
|
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
3535
3583
|
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
@@ -3545,20 +3593,33 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3545
3593
|
* @param {BigNumberish} limb2 bits 256 to 383
|
|
3546
3594
|
* @param {BigNumberish} limb3 bits 384 to 511
|
|
3547
3595
|
* @returns {{limb0: bigint, limb1: bigint, limb2: bigint, limb3: bigint}} the four limbs as numbers
|
|
3548
|
-
* @throws {Error} when any limb is outside the u128 range
|
|
3596
|
+
* @throws {Error} when any limb is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
3549
3597
|
* @example
|
|
3550
3598
|
* ```typescript
|
|
3551
3599
|
* const result = CairoUint512.validateProps(7, 0, 0, 64);
|
|
3552
3600
|
* // result = { limb0: 7n, limb1: 0n, limb2: 0n, limb3: 64n }
|
|
3553
3601
|
* CairoUint512.validateProps(-1, 0, 0, 0);
|
|
3554
3602
|
* // throws Error("limb0 is not in the range of a u128 number")
|
|
3603
|
+
* CairoUint512.validateProps(1.5, 0, 0, 0);
|
|
3604
|
+
* // throws Error("limb0 must be an integer")
|
|
3605
|
+
* CairoUint512.validateProps('abc', 0, 0, 0);
|
|
3606
|
+
* // throws Error("limb0 cannot be built from text")
|
|
3555
3607
|
* ```
|
|
3556
3608
|
*/
|
|
3557
3609
|
static validateProps(limb0, limb1, limb2, limb3) {
|
|
3558
|
-
const
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3610
|
+
const validateLimb = (limb, name) => {
|
|
3611
|
+
assert(limb !== null, `${name} cannot be null`);
|
|
3612
|
+
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
3613
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
3614
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
3615
|
+
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
3616
|
+
assert(!isNumber(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
3617
|
+
return BigInt(limb);
|
|
3618
|
+
};
|
|
3619
|
+
const l0 = validateLimb(limb0, "limb0");
|
|
3620
|
+
const l1 = validateLimb(limb1, "limb1");
|
|
3621
|
+
const l2 = validateLimb(limb2, "limb2");
|
|
3622
|
+
const l3 = validateLimb(limb3, "limb3");
|
|
3562
3623
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
3563
3624
|
assert(
|
|
3564
3625
|
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
@@ -3730,7 +3791,7 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3730
3791
|
* otherwise. Text therefore only fits here up to 12 ASCII characters : one more already
|
|
3731
3792
|
* makes a number past 79228162514264337593543950335.
|
|
3732
3793
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 79228162514264337593543950335]
|
|
3733
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
3794
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
3734
3795
|
* @example
|
|
3735
3796
|
* ```typescript
|
|
3736
3797
|
* const result = new CairoUint96('abcdefghijkl').toApiRequest();
|
|
@@ -3818,11 +3879,11 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3818
3879
|
/**
|
|
3819
3880
|
* Throw unless the value can be carried by a u96.
|
|
3820
3881
|
*
|
|
3821
|
-
*
|
|
3822
|
-
* an array, a number with a decimal part, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
3882
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
3883
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
3823
3884
|
* that last check as the number its bytes spell, so `'abcdefghijklm'` is refused for being out of range.
|
|
3824
3885
|
* @param {BigNumberish | boolean} data the value to check
|
|
3825
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
3886
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
3826
3887
|
* @example
|
|
3827
3888
|
* ```typescript
|
|
3828
3889
|
* CairoUint96.validate(5000000000); // passes
|
|
@@ -3837,6 +3898,7 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3837
3898
|
!isNumber(data) || Number.isInteger(data),
|
|
3838
3899
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
3839
3900
|
);
|
|
3901
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3840
3902
|
const value = _CairoUint96.__processData(data);
|
|
3841
3903
|
assert(
|
|
3842
3904
|
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
@@ -4223,7 +4285,7 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4223
4285
|
* otherwise. Text therefore only fits here while it is a single ASCII character : two characters
|
|
4224
4286
|
* already make a number past 255.
|
|
4225
4287
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 255]
|
|
4226
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4288
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4227
4289
|
* @example
|
|
4228
4290
|
* ```typescript
|
|
4229
4291
|
* const result = new CairoUint8('a').toApiRequest();
|
|
@@ -4313,11 +4375,11 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4313
4375
|
/**
|
|
4314
4376
|
* Throw unless the value can be carried by a u8.
|
|
4315
4377
|
*
|
|
4316
|
-
*
|
|
4317
|
-
* an array, a number with a decimal part, and a value outside [0, 255]. A text string reaches
|
|
4378
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4379
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 255]. A text string reaches
|
|
4318
4380
|
* that last check as the number its bytes spell, so `'ab'` is refused for being out of range.
|
|
4319
4381
|
* @param {BigNumberish | boolean} data the value to check
|
|
4320
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4382
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4321
4383
|
* @example
|
|
4322
4384
|
* ```typescript
|
|
4323
4385
|
* CairoUint8.validate(44); // passes
|
|
@@ -4332,6 +4394,7 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4332
4394
|
!isNumber(data) || Number.isInteger(data),
|
|
4333
4395
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4334
4396
|
);
|
|
4397
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4335
4398
|
const value = _CairoUint8.__processData(data);
|
|
4336
4399
|
assert(
|
|
4337
4400
|
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
@@ -4422,7 +4485,7 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4422
4485
|
* otherwise. Text therefore only fits here up to 2 ASCII characters : one more already
|
|
4423
4486
|
* makes a number past 65535.
|
|
4424
4487
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 65535]
|
|
4425
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4488
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4426
4489
|
* @example
|
|
4427
4490
|
* ```typescript
|
|
4428
4491
|
* const result = new CairoUint16('ab').toApiRequest();
|
|
@@ -4510,11 +4573,11 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4510
4573
|
/**
|
|
4511
4574
|
* Throw unless the value can be carried by a u16.
|
|
4512
4575
|
*
|
|
4513
|
-
*
|
|
4514
|
-
* an array, a number with a decimal part, and a value outside [0, 65535]. A text string reaches
|
|
4576
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4577
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 65535]. A text string reaches
|
|
4515
4578
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
4516
4579
|
* @param {BigNumberish | boolean} data the value to check
|
|
4517
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4580
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4518
4581
|
* @example
|
|
4519
4582
|
* ```typescript
|
|
4520
4583
|
* CairoUint16.validate(300); // passes
|
|
@@ -4529,6 +4592,7 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4529
4592
|
!isNumber(data) || Number.isInteger(data),
|
|
4530
4593
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4531
4594
|
);
|
|
4595
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4532
4596
|
const value = _CairoUint16.__processData(data);
|
|
4533
4597
|
assert(
|
|
4534
4598
|
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
@@ -4619,7 +4683,7 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4619
4683
|
* otherwise. Text therefore only fits here up to 8 ASCII characters : one more already
|
|
4620
4684
|
* makes a number past 18446744073709551615.
|
|
4621
4685
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 18446744073709551615]
|
|
4622
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4686
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4623
4687
|
* @example
|
|
4624
4688
|
* ```typescript
|
|
4625
4689
|
* const result = new CairoUint64('abcdefgh').toApiRequest();
|
|
@@ -4707,11 +4771,11 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4707
4771
|
/**
|
|
4708
4772
|
* Throw unless the value can be carried by a u64.
|
|
4709
4773
|
*
|
|
4710
|
-
*
|
|
4711
|
-
* an array, a number with a decimal part, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
4774
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4775
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
4712
4776
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
4713
4777
|
* @param {BigNumberish | boolean} data the value to check
|
|
4714
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4778
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4715
4779
|
* @example
|
|
4716
4780
|
* ```typescript
|
|
4717
4781
|
* CairoUint64.validate(5000000000); // passes
|
|
@@ -4726,6 +4790,7 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4726
4790
|
!isNumber(data) || Number.isInteger(data),
|
|
4727
4791
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4728
4792
|
);
|
|
4793
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4729
4794
|
const value = _CairoUint64.__processData(data);
|
|
4730
4795
|
assert(
|
|
4731
4796
|
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
@@ -4816,7 +4881,7 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4816
4881
|
* otherwise. Text therefore only fits here up to 16 ASCII characters : one more already
|
|
4817
4882
|
* makes a number past 340282366920938463463374607431768211455.
|
|
4818
4883
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 340282366920938463463374607431768211455]
|
|
4819
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4884
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4820
4885
|
* @example
|
|
4821
4886
|
* ```typescript
|
|
4822
4887
|
* const result = new CairoUint128('abcdefghijklmnop').toApiRequest();
|
|
@@ -4904,11 +4969,11 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4904
4969
|
/**
|
|
4905
4970
|
* Throw unless the value can be carried by a u128.
|
|
4906
4971
|
*
|
|
4907
|
-
*
|
|
4908
|
-
* an array, a number with a decimal part, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
4972
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4973
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
4909
4974
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
4910
4975
|
* @param {BigNumberish | boolean} data the value to check
|
|
4911
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4976
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4912
4977
|
* @example
|
|
4913
4978
|
* ```typescript
|
|
4914
4979
|
* CairoUint128.validate(5000000000); // passes
|
|
@@ -4923,6 +4988,7 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4923
4988
|
!isNumber(data) || Number.isInteger(data),
|
|
4924
4989
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4925
4990
|
);
|
|
4991
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4926
4992
|
const value = _CairoUint128.__processData(data);
|
|
4927
4993
|
assert(
|
|
4928
4994
|
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
@@ -5009,15 +5075,17 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5009
5075
|
/**
|
|
5010
5076
|
* Build from a number, a string or a boolean, refusing anything out of the i8 range.
|
|
5011
5077
|
*
|
|
5012
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5013
|
-
* otherwise. Text therefore only fits here up to a single
|
|
5014
|
-
* makes a number past 127.
|
|
5078
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5079
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to a single
|
|
5080
|
+
* ASCII character : one more already makes a number past 127.
|
|
5015
5081
|
* @param {BigNumberish | boolean} data the value to carry, within [-128, 127]
|
|
5016
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5082
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5017
5083
|
* @example
|
|
5018
5084
|
* ```typescript
|
|
5019
5085
|
* const result = new CairoInt8('a').toApiRequest();
|
|
5020
5086
|
* // result = ["97"]
|
|
5087
|
+
* const result2 = new CairoInt8('-5').toApiRequest();
|
|
5088
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5021
5089
|
* ```
|
|
5022
5090
|
*/
|
|
5023
5091
|
constructor(data) {
|
|
@@ -5029,6 +5097,9 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5029
5097
|
*
|
|
5030
5098
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5031
5099
|
* far outside the i8 range comes back untouched rather than raising.
|
|
5100
|
+
*
|
|
5101
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5102
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5032
5103
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5033
5104
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5034
5105
|
* @example
|
|
@@ -5037,9 +5108,14 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5037
5108
|
* // result = 97n
|
|
5038
5109
|
* const result2 = CairoInt8.__processData('ab');
|
|
5039
5110
|
* // result2 = 24930n (past the i8 range, and returned all the same)
|
|
5111
|
+
* const result3 = CairoInt8.__processData('-0x5');
|
|
5112
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5040
5113
|
* ```
|
|
5041
5114
|
*/
|
|
5042
5115
|
static __processData(data) {
|
|
5116
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5117
|
+
return -BigInt(data.slice(1));
|
|
5118
|
+
}
|
|
5043
5119
|
if (isString(data) && isText(data)) {
|
|
5044
5120
|
return utf8ToBigInt(data);
|
|
5045
5121
|
}
|
|
@@ -5118,11 +5194,12 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5118
5194
|
/**
|
|
5119
5195
|
* Throw unless the value can be carried by an i8.
|
|
5120
5196
|
*
|
|
5121
|
-
*
|
|
5122
|
-
* an array, a number with a decimal part, and a value outside [-128, 127]. A text string
|
|
5123
|
-
* that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
5197
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5198
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-128, 127]. A text string
|
|
5199
|
+
* reaches that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
5200
|
+
* range.
|
|
5124
5201
|
* @param {BigNumberish | boolean} data the value to check
|
|
5125
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5202
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5126
5203
|
* @example
|
|
5127
5204
|
* ```typescript
|
|
5128
5205
|
* CairoInt8.validate(5); // passes
|
|
@@ -5137,6 +5214,7 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5137
5214
|
!isNumber(data) || Number.isInteger(data),
|
|
5138
5215
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5139
5216
|
);
|
|
5217
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5140
5218
|
const value = _CairoInt8.__processData(data);
|
|
5141
5219
|
assert(
|
|
5142
5220
|
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
@@ -5227,15 +5305,17 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5227
5305
|
/**
|
|
5228
5306
|
* Build from a number, a string or a boolean, refusing anything out of the i16 range.
|
|
5229
5307
|
*
|
|
5230
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5231
|
-
* otherwise. Text therefore only fits here up to 2 ASCII
|
|
5232
|
-
* makes a number past 32767.
|
|
5308
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5309
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 2 ASCII
|
|
5310
|
+
* characters : one more already makes a number past 32767.
|
|
5233
5311
|
* @param {BigNumberish | boolean} data the value to carry, within [-32768, 32767]
|
|
5234
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5312
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5235
5313
|
* @example
|
|
5236
5314
|
* ```typescript
|
|
5237
5315
|
* const result = new CairoInt16('ab').toApiRequest();
|
|
5238
5316
|
* // result = ["24930"]
|
|
5317
|
+
* const result2 = new CairoInt16('-5').toApiRequest();
|
|
5318
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5239
5319
|
* ```
|
|
5240
5320
|
*/
|
|
5241
5321
|
constructor(data) {
|
|
@@ -5247,6 +5327,9 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5247
5327
|
*
|
|
5248
5328
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5249
5329
|
* far outside the i16 range comes back untouched rather than raising.
|
|
5330
|
+
*
|
|
5331
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5332
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5250
5333
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5251
5334
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5252
5335
|
* @example
|
|
@@ -5255,9 +5338,14 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5255
5338
|
* // result = 24930n
|
|
5256
5339
|
* const result2 = CairoInt16.__processData('abc');
|
|
5257
5340
|
* // result2 = 6382179n (past the i16 range, and returned all the same)
|
|
5341
|
+
* const result3 = CairoInt16.__processData('-0x5');
|
|
5342
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5258
5343
|
* ```
|
|
5259
5344
|
*/
|
|
5260
5345
|
static __processData(data) {
|
|
5346
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5347
|
+
return -BigInt(data.slice(1));
|
|
5348
|
+
}
|
|
5261
5349
|
if (isString(data) && isText(data)) {
|
|
5262
5350
|
return utf8ToBigInt(data);
|
|
5263
5351
|
}
|
|
@@ -5336,11 +5424,11 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5336
5424
|
/**
|
|
5337
5425
|
* Throw unless the value can be carried by an i16.
|
|
5338
5426
|
*
|
|
5339
|
-
*
|
|
5340
|
-
* an array, a number with a decimal part, and a value outside [-32768, 32767]. A text string reaches
|
|
5427
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5428
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-32768, 32767]. A text string reaches
|
|
5341
5429
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
5342
5430
|
* @param {BigNumberish | boolean} data the value to check
|
|
5343
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5431
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5344
5432
|
* @example
|
|
5345
5433
|
* ```typescript
|
|
5346
5434
|
* CairoInt16.validate(300); // passes
|
|
@@ -5355,6 +5443,7 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5355
5443
|
!isNumber(data) || Number.isInteger(data),
|
|
5356
5444
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5357
5445
|
);
|
|
5446
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5358
5447
|
const value = _CairoInt16.__processData(data);
|
|
5359
5448
|
assert(
|
|
5360
5449
|
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
@@ -5445,15 +5534,17 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5445
5534
|
/**
|
|
5446
5535
|
* Build from a number, a string or a boolean, refusing anything out of the i32 range.
|
|
5447
5536
|
*
|
|
5448
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5449
|
-
* otherwise. Text therefore only fits here up to 4 ASCII
|
|
5450
|
-
* makes a number past 2147483647.
|
|
5537
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5538
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 4 ASCII
|
|
5539
|
+
* characters : one more already makes a number past 2147483647.
|
|
5451
5540
|
* @param {BigNumberish | boolean} data the value to carry, within [-2147483648, 2147483647]
|
|
5452
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5541
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5453
5542
|
* @example
|
|
5454
5543
|
* ```typescript
|
|
5455
5544
|
* const result = new CairoInt32('abcd').toApiRequest();
|
|
5456
5545
|
* // result = ["1633837924"]
|
|
5546
|
+
* const result2 = new CairoInt32('-5').toApiRequest();
|
|
5547
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5457
5548
|
* ```
|
|
5458
5549
|
*/
|
|
5459
5550
|
constructor(data) {
|
|
@@ -5465,6 +5556,9 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5465
5556
|
*
|
|
5466
5557
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5467
5558
|
* far outside the i32 range comes back untouched rather than raising.
|
|
5559
|
+
*
|
|
5560
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5561
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5468
5562
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5469
5563
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5470
5564
|
* @example
|
|
@@ -5473,9 +5567,14 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5473
5567
|
* // result = 1633837924n
|
|
5474
5568
|
* const result2 = CairoInt32.__processData('abcde');
|
|
5475
5569
|
* // result2 = 418262508645n (past the i32 range, and returned all the same)
|
|
5570
|
+
* const result3 = CairoInt32.__processData('-0x5');
|
|
5571
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5476
5572
|
* ```
|
|
5477
5573
|
*/
|
|
5478
5574
|
static __processData(data) {
|
|
5575
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5576
|
+
return -BigInt(data.slice(1));
|
|
5577
|
+
}
|
|
5479
5578
|
if (isString(data) && isText(data)) {
|
|
5480
5579
|
return utf8ToBigInt(data);
|
|
5481
5580
|
}
|
|
@@ -5554,11 +5653,11 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5554
5653
|
/**
|
|
5555
5654
|
* Throw unless the value can be carried by an i32.
|
|
5556
5655
|
*
|
|
5557
|
-
*
|
|
5558
|
-
* an array, a number with a decimal part, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
5656
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5657
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
5559
5658
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
5560
5659
|
* @param {BigNumberish | boolean} data the value to check
|
|
5561
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5660
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5562
5661
|
* @example
|
|
5563
5662
|
* ```typescript
|
|
5564
5663
|
* CairoInt32.validate(70000); // passes
|
|
@@ -5573,6 +5672,7 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5573
5672
|
!isNumber(data) || Number.isInteger(data),
|
|
5574
5673
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5575
5674
|
);
|
|
5675
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5576
5676
|
const value = _CairoInt32.__processData(data);
|
|
5577
5677
|
assert(
|
|
5578
5678
|
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
@@ -5663,15 +5763,17 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5663
5763
|
/**
|
|
5664
5764
|
* Build from a number, a string or a boolean, refusing anything out of the i64 range.
|
|
5665
5765
|
*
|
|
5666
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5667
|
-
* otherwise. Text therefore only fits here up to 8 ASCII
|
|
5668
|
-
* makes a number past 9223372036854775807.
|
|
5766
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5767
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 8 ASCII
|
|
5768
|
+
* characters : one more already makes a number past 9223372036854775807.
|
|
5669
5769
|
* @param {BigNumberish | boolean} data the value to carry, within [-9223372036854775808, 9223372036854775807]
|
|
5670
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5770
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5671
5771
|
* @example
|
|
5672
5772
|
* ```typescript
|
|
5673
5773
|
* const result = new CairoInt64('abcdefgh').toApiRequest();
|
|
5674
5774
|
* // result = ["7017280452245743464"]
|
|
5775
|
+
* const result2 = new CairoInt64('-5').toApiRequest();
|
|
5776
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5675
5777
|
* ```
|
|
5676
5778
|
*/
|
|
5677
5779
|
constructor(data) {
|
|
@@ -5683,6 +5785,9 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5683
5785
|
*
|
|
5684
5786
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5685
5787
|
* far outside the i64 range comes back untouched rather than raising.
|
|
5788
|
+
*
|
|
5789
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5790
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5686
5791
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5687
5792
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5688
5793
|
* @example
|
|
@@ -5691,9 +5796,14 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5691
5796
|
* // result = 7017280452245743464n
|
|
5692
5797
|
* const result2 = CairoInt64.__processData('abcdefghi');
|
|
5693
5798
|
* // result2 = 1796423795774910326889n (past the i64 range, and returned all the same)
|
|
5799
|
+
* const result3 = CairoInt64.__processData('-0x5');
|
|
5800
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5694
5801
|
* ```
|
|
5695
5802
|
*/
|
|
5696
5803
|
static __processData(data) {
|
|
5804
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5805
|
+
return -BigInt(data.slice(1));
|
|
5806
|
+
}
|
|
5697
5807
|
if (isString(data) && isText(data)) {
|
|
5698
5808
|
return utf8ToBigInt(data);
|
|
5699
5809
|
}
|
|
@@ -5772,11 +5882,11 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5772
5882
|
/**
|
|
5773
5883
|
* Throw unless the value can be carried by an i64.
|
|
5774
5884
|
*
|
|
5775
|
-
*
|
|
5776
|
-
* an array, a number with a decimal part, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
5885
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5886
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
5777
5887
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
5778
5888
|
* @param {BigNumberish | boolean} data the value to check
|
|
5779
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5889
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5780
5890
|
* @example
|
|
5781
5891
|
* ```typescript
|
|
5782
5892
|
* CairoInt64.validate(5000000000); // passes
|
|
@@ -5791,6 +5901,7 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5791
5901
|
!isNumber(data) || Number.isInteger(data),
|
|
5792
5902
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5793
5903
|
);
|
|
5904
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5794
5905
|
const value = _CairoInt64.__processData(data);
|
|
5795
5906
|
assert(
|
|
5796
5907
|
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
@@ -5881,15 +5992,17 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5881
5992
|
/**
|
|
5882
5993
|
* Build from a number, a string or a boolean, refusing anything out of the i128 range.
|
|
5883
5994
|
*
|
|
5884
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5885
|
-
* otherwise. Text therefore only fits here up to 16 ASCII
|
|
5886
|
-
* makes a number past 170141183460469231731687303715884105727.
|
|
5995
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5996
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 16 ASCII
|
|
5997
|
+
* characters : one more already makes a number past 170141183460469231731687303715884105727.
|
|
5887
5998
|
* @param {BigNumberish | boolean} data the value to carry, within [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]
|
|
5888
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5999
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5889
6000
|
* @example
|
|
5890
6001
|
* ```typescript
|
|
5891
6002
|
* const result = new CairoInt128('abcdefghijklmnop').toApiRequest();
|
|
5892
6003
|
* // result = ["129445976596022050476432668810952994672"]
|
|
6004
|
+
* const result2 = new CairoInt128('-5').toApiRequest();
|
|
6005
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5893
6006
|
* ```
|
|
5894
6007
|
*/
|
|
5895
6008
|
constructor(data) {
|
|
@@ -5901,6 +6014,9 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5901
6014
|
*
|
|
5902
6015
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5903
6016
|
* far outside the i128 range comes back untouched rather than raising.
|
|
6017
|
+
*
|
|
6018
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
6019
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5904
6020
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5905
6021
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5906
6022
|
* @example
|
|
@@ -5909,9 +6025,14 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5909
6025
|
* // result = 129445976596022050476432668810952994672n
|
|
5910
6026
|
* const result2 = CairoInt128.__processData('abcdefghijklmnopq');
|
|
5911
6027
|
* // result2 = 33138170008581644921966763215603966636145n (past the i128 range, and returned all the same)
|
|
6028
|
+
* const result3 = CairoInt128.__processData('-0x5');
|
|
6029
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5912
6030
|
* ```
|
|
5913
6031
|
*/
|
|
5914
6032
|
static __processData(data) {
|
|
6033
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
6034
|
+
return -BigInt(data.slice(1));
|
|
6035
|
+
}
|
|
5915
6036
|
if (isString(data) && isText(data)) {
|
|
5916
6037
|
return utf8ToBigInt(data);
|
|
5917
6038
|
}
|
|
@@ -5990,11 +6111,11 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5990
6111
|
/**
|
|
5991
6112
|
* Throw unless the value can be carried by an i128.
|
|
5992
6113
|
*
|
|
5993
|
-
*
|
|
5994
|
-
* an array, a number with a decimal part, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
6114
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
6115
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
5995
6116
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
5996
6117
|
* @param {BigNumberish | boolean} data the value to check
|
|
5997
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
6118
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5998
6119
|
* @example
|
|
5999
6120
|
* ```typescript
|
|
6000
6121
|
* CairoInt128.validate(5000000000); // passes
|
|
@@ -6009,6 +6130,7 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
6009
6130
|
!isNumber(data) || Number.isInteger(data),
|
|
6010
6131
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
6011
6132
|
);
|
|
6133
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
6012
6134
|
const value = _CairoInt128.__processData(data);
|
|
6013
6135
|
assert(
|
|
6014
6136
|
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
@@ -6099,7 +6221,7 @@ var CairoBool = class _CairoBool {
|
|
|
6099
6221
|
/**
|
|
6100
6222
|
* Build from a boolean, or from the numbers 0 and 1.
|
|
6101
6223
|
* @param {BigNumberish | boolean} data the value to carry : a boolean, 0 or 1
|
|
6102
|
-
* @throws {Error} when the value is text,
|
|
6224
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
6103
6225
|
* @example
|
|
6104
6226
|
* ```typescript
|
|
6105
6227
|
* const result = new CairoBool(false).toApiRequest();
|
|
@@ -6172,21 +6294,28 @@ var CairoBool = class _CairoBool {
|
|
|
6172
6294
|
/**
|
|
6173
6295
|
* Throw unless the value can be carried by a bool.
|
|
6174
6296
|
*
|
|
6175
|
-
* Text is refused first, then
|
|
6176
|
-
*
|
|
6177
|
-
*
|
|
6297
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
6298
|
+
* is, so that a negative one reaches the last check. Anything else is read as a felt252 — which
|
|
6299
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked to be
|
|
6300
|
+
* one of the only two numbers a bool can hold.
|
|
6178
6301
|
* @param {BigNumberish | boolean} data the value to check
|
|
6179
|
-
* @throws {Error} when the value is text,
|
|
6302
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
6180
6303
|
* @example
|
|
6181
6304
|
* ```typescript
|
|
6182
6305
|
* CairoBool.validate(true); // passes
|
|
6183
6306
|
* CairoBool.validate(2);
|
|
6184
6307
|
* // throws Error("Only values 0 or 1 are possible in a core::bool, received 2")
|
|
6308
|
+
* CairoBool.validate(-1);
|
|
6309
|
+
* // throws Error("Only values 0 or 1 are possible in a core::bool, received -1")
|
|
6185
6310
|
* ```
|
|
6186
6311
|
*/
|
|
6187
6312
|
static validate(data) {
|
|
6188
6313
|
assert(!isText(data), "Invalid input: a core::bool cannot be built from text");
|
|
6189
|
-
|
|
6314
|
+
assert(
|
|
6315
|
+
!isNumber(data) || Number.isInteger(data),
|
|
6316
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6317
|
+
);
|
|
6318
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
6190
6319
|
assert(
|
|
6191
6320
|
value === 0n || value === 1n,
|
|
6192
6321
|
`Only values 0 or 1 are possible in a core::bool, received ${value}`
|
|
@@ -6301,7 +6430,9 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6301
6430
|
/**
|
|
6302
6431
|
* @param {any[]} arr either one value — a 512-bit number or a {@link Secp256k1PointStruct} — or
|
|
6303
6432
|
* the four limbs
|
|
6304
|
-
* @throws {Error} when a value is
|
|
6433
|
+
* @throws {Error} when a value is null, undefined, of an unread type, text, a decimal number, or out
|
|
6434
|
+
* of range — see {@link CairoSecp256k1Point.validate} and {@link CairoSecp256k1Point.validateProps}
|
|
6435
|
+
* — or when the argument count is neither 1 nor 4
|
|
6305
6436
|
* @example
|
|
6306
6437
|
* ```typescript
|
|
6307
6438
|
* const result = new CairoSecp256k1Point(1n).toApiRequest();
|
|
@@ -6348,22 +6479,32 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6348
6479
|
* the constructor needs it, and computing it twice would mean splitting a 512-bit value twice.
|
|
6349
6480
|
* @param {BigNumberish} input the 512-bit value to check
|
|
6350
6481
|
* @returns {bigint} the value, once checked
|
|
6351
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, 2^512 - 1]
|
|
6482
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or outside [0, 2^512 - 1]
|
|
6352
6483
|
* @example
|
|
6353
6484
|
* ```typescript
|
|
6354
6485
|
* const result = CairoSecp256k1Point.validate('0x1234');
|
|
6355
6486
|
* // result = 4660n
|
|
6356
6487
|
* CairoSecp256k1Point.validate(SECP256K1_POINT_MAX + 1n);
|
|
6357
6488
|
* // throws Error("input is bigger than SECP256K1_POINT_MAX")
|
|
6489
|
+
* CairoSecp256k1Point.validate('abc');
|
|
6490
|
+
* // throws Error("Invalid input: a Secp256k1Point cannot be built from text")
|
|
6491
|
+
* CairoSecp256k1Point.validate(1.5);
|
|
6492
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
6358
6493
|
* ```
|
|
6359
6494
|
*/
|
|
6360
6495
|
static validate(input) {
|
|
6361
6496
|
assert(input !== null, "null value is not allowed for Secp256k1Point");
|
|
6362
6497
|
assert(input !== void 0, "undefined value is not allowed for Secp256k1Point");
|
|
6498
|
+
assert(!isText(input), "Invalid input: a Secp256k1Point cannot be built from text");
|
|
6499
|
+
assert(!isEmptyHex(input), "Invalid input: '0x' holds no hexadecimal digit");
|
|
6363
6500
|
assert(
|
|
6364
6501
|
isBigNumberish(input),
|
|
6365
6502
|
`Unsupported input for Secp256k1Point. Expected a number, a bigint, or a string spelling one, received '${typeof input}'`
|
|
6366
6503
|
);
|
|
6504
|
+
assert(
|
|
6505
|
+
!isNumber(input) || Number.isInteger(input),
|
|
6506
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6507
|
+
);
|
|
6367
6508
|
const bigInt = BigInt(input);
|
|
6368
6509
|
assert(bigInt >= SECP256K1_POINT_MIN, "input is smaller than SECP256K1_POINT_MIN");
|
|
6369
6510
|
assert(bigInt <= SECP256K1_POINT_MAX, "input is bigger than SECP256K1_POINT_MAX");
|
|
@@ -6376,20 +6517,27 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6376
6517
|
* @param {BigNumberish} yLow the low 128 bits of y
|
|
6377
6518
|
* @param {BigNumberish} yHigh the high 128 bits of y
|
|
6378
6519
|
* @returns {{xLow: bigint, xHigh: bigint, yLow: bigint, yHigh: bigint}} the four limbs, checked
|
|
6379
|
-
* @throws {Error} when a limb is null, undefined, not a number, negative, or wider than 128 bits
|
|
6520
|
+
* @throws {Error} when a limb is null, undefined, text, `'0x'`, not a number, a decimal number, negative, or wider than 128 bits
|
|
6380
6521
|
* @example
|
|
6381
6522
|
* ```typescript
|
|
6382
6523
|
* const result = CairoSecp256k1Point.validateProps(1, 2, 3, 4);
|
|
6383
6524
|
* // result = { xLow: 1n, xHigh: 2n, yLow: 3n, yHigh: 4n }
|
|
6384
6525
|
* CairoSecp256k1Point.validateProps(1, 2, 3, 2n ** 128n);
|
|
6385
6526
|
* // throws Error("yHigh must fit in 128 bits")
|
|
6527
|
+
* CairoSecp256k1Point.validateProps(1.5, 2, 3, 4);
|
|
6528
|
+
* // throws Error("xLow must be an integer")
|
|
6529
|
+
* CairoSecp256k1Point.validateProps('abc', 2, 3, 4);
|
|
6530
|
+
* // throws Error("xLow cannot be built from text")
|
|
6386
6531
|
* ```
|
|
6387
6532
|
*/
|
|
6388
6533
|
static validateProps(xLow, xHigh, yLow, yHigh) {
|
|
6389
6534
|
const validateLimb = (limb, name) => {
|
|
6390
6535
|
assert(limb !== null, `${name} cannot be null`);
|
|
6391
6536
|
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
6537
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
6538
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
6392
6539
|
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
6540
|
+
assert(!isNumber(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
6393
6541
|
const bigInt = BigInt(limb);
|
|
6394
6542
|
assert(bigInt >= 0n, `${name} must be non-negative`);
|
|
6395
6543
|
assert(bigInt <= UINT_128_MAX, `${name} must fit in 128 bits`);
|
|
@@ -7532,9 +7680,9 @@ var CairoClassHash = class _CairoClassHash {
|
|
|
7532
7680
|
*/
|
|
7533
7681
|
static abiSelector = Literal.ClassHash;
|
|
7534
7682
|
/**
|
|
7535
|
-
* Build from a number or a numeric string, refusing text and anything
|
|
7536
|
-
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^
|
|
7537
|
-
* @throws {Error} when the value is text,
|
|
7683
|
+
* Build from a number or a numeric string, refusing text and anything outside the ClassHash range.
|
|
7684
|
+
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^251 - 1]
|
|
7685
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
7538
7686
|
* @example
|
|
7539
7687
|
* ```typescript
|
|
7540
7688
|
* const result = new CairoClassHash('0x1234').toApiRequest();
|
|
@@ -7589,21 +7737,34 @@ var CairoClassHash = class _CairoClassHash {
|
|
|
7589
7737
|
/**
|
|
7590
7738
|
* Throw unless the value can be carried by a ClassHash.
|
|
7591
7739
|
*
|
|
7592
|
-
* Text is refused first, then
|
|
7593
|
-
*
|
|
7594
|
-
* a
|
|
7740
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
7741
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
7742
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
7743
|
+
* the range of the Cairo `ClassHash` type, [0, 2^251), which is narrower than the field.
|
|
7595
7744
|
* @param {BigNumberish | boolean} data the value to check
|
|
7596
|
-
* @throws {Error} when the value is text,
|
|
7745
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
7597
7746
|
* @example
|
|
7598
7747
|
* ```typescript
|
|
7599
7748
|
* CairoClassHash.validate('0x1234'); // passes
|
|
7600
7749
|
* CairoClassHash.validate('abc');
|
|
7601
7750
|
* // throws Error("Invalid input: a ClassHash cannot be built from text")
|
|
7751
|
+
* CairoClassHash.validate(2n ** 251n);
|
|
7752
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
7753
|
+
* CairoClassHash.validate(-1);
|
|
7754
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
7602
7755
|
* ```
|
|
7603
7756
|
*/
|
|
7604
7757
|
static validate(data) {
|
|
7605
7758
|
assert(!isText(data), "Invalid input: a ClassHash cannot be built from text");
|
|
7606
|
-
|
|
7759
|
+
assert(
|
|
7760
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7761
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7762
|
+
);
|
|
7763
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7764
|
+
assert(
|
|
7765
|
+
value >= RANGE_CLASS_HASH.min && value <= RANGE_CLASS_HASH.max,
|
|
7766
|
+
`Value is out of ClassHash range [${RANGE_CLASS_HASH.min}, ${RANGE_CLASS_HASH.max}]`
|
|
7767
|
+
);
|
|
7607
7768
|
}
|
|
7608
7769
|
/**
|
|
7609
7770
|
* Can this value be carried by a ClassHash?
|
|
@@ -7682,7 +7843,7 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7682
7843
|
/**
|
|
7683
7844
|
* Build from a number or a numeric string, refusing text and anything wider than 252 bits.
|
|
7684
7845
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^252 - 1]
|
|
7685
|
-
* @throws {Error} when the value is text,
|
|
7846
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
7686
7847
|
* @example
|
|
7687
7848
|
* ```typescript
|
|
7688
7849
|
* const result = new CairoContractAddress('0x1234').toApiRequest();
|
|
@@ -7737,11 +7898,12 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7737
7898
|
/**
|
|
7738
7899
|
* Throw unless the value can be carried by a ContractAddress.
|
|
7739
7900
|
*
|
|
7740
|
-
* Text is refused first, then
|
|
7741
|
-
*
|
|
7742
|
-
* is
|
|
7901
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
7902
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
7903
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
7904
|
+
* the bound an address has, which is narrower than the field.
|
|
7743
7905
|
* @param {BigNumberish | boolean} data the value to check
|
|
7744
|
-
* @throws {Error} when the value is text,
|
|
7906
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
7745
7907
|
* @example
|
|
7746
7908
|
* ```typescript
|
|
7747
7909
|
* CairoContractAddress.validate('0x1234'); // passes
|
|
@@ -7749,11 +7911,17 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7749
7911
|
* // throws Error("Invalid input: a ContractAddress cannot be built from text")
|
|
7750
7912
|
* CairoContractAddress.validate(2n ** 251n);
|
|
7751
7913
|
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
7914
|
+
* CairoContractAddress.validate(-1);
|
|
7915
|
+
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
7752
7916
|
* ```
|
|
7753
7917
|
*/
|
|
7754
7918
|
static validate(data) {
|
|
7755
7919
|
assert(!isText(data), "Invalid input: a ContractAddress cannot be built from text");
|
|
7756
|
-
|
|
7920
|
+
assert(
|
|
7921
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7922
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7923
|
+
);
|
|
7924
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7757
7925
|
assert(
|
|
7758
7926
|
value >= RANGE_CONTRACT_ADDRESS.min && value <= RANGE_CONTRACT_ADDRESS.max,
|
|
7759
7927
|
`Value is out of ContractAddress range [${RANGE_CONTRACT_ADDRESS.min}, ${RANGE_CONTRACT_ADDRESS.max}]`
|
|
@@ -7838,7 +8006,7 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7838
8006
|
/**
|
|
7839
8007
|
* Build from a number or a numeric string, refusing text and anything wider than 160 bits.
|
|
7840
8008
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^160 - 1]
|
|
7841
|
-
* @throws {Error} when the value is text,
|
|
8009
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
7842
8010
|
* @example
|
|
7843
8011
|
* ```typescript
|
|
7844
8012
|
* const result = new CairoEthAddress('0x1234').toApiRequest();
|
|
@@ -7894,10 +8062,12 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7894
8062
|
* Throw unless the value can be carried by an EthAddress.
|
|
7895
8063
|
*
|
|
7896
8064
|
* Text is refused first, since an address spelled as words is a mistake rather than a value to
|
|
7897
|
-
* encode
|
|
7898
|
-
*
|
|
8065
|
+
* encode, then a number with a decimal part. A number or a bigint is read as it is, so that a
|
|
8066
|
+
* negative one reaches the range check below. Anything else is read as a felt252 — which is what
|
|
8067
|
+
* refuses a null, an object or an unsupported type. The value is finally checked against the 160
|
|
8068
|
+
* bits an Ethereum address occupies.
|
|
7899
8069
|
* @param {BigNumberish | boolean} data the value to check
|
|
7900
|
-
* @throws {Error} when the value is text,
|
|
8070
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
7901
8071
|
* @example
|
|
7902
8072
|
* ```typescript
|
|
7903
8073
|
* CairoEthAddress.validate('0x1234'); // passes
|
|
@@ -7905,11 +8075,17 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7905
8075
|
* // throws Error("Invalid input: an EthAddress cannot be built from text")
|
|
7906
8076
|
* CairoEthAddress.validate(2n ** 160n);
|
|
7907
8077
|
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
8078
|
+
* CairoEthAddress.validate(-1);
|
|
8079
|
+
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
7908
8080
|
* ```
|
|
7909
8081
|
*/
|
|
7910
8082
|
static validate(data) {
|
|
7911
8083
|
assert(!isText(data), "Invalid input: an EthAddress cannot be built from text");
|
|
7912
|
-
|
|
8084
|
+
assert(
|
|
8085
|
+
!isNumber(data) || Number.isInteger(data),
|
|
8086
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
8087
|
+
);
|
|
8088
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7913
8089
|
assert(
|
|
7914
8090
|
value >= RANGE_ETH_ADDRESS.min && value <= RANGE_ETH_ADDRESS.max,
|
|
7915
8091
|
`Value is out of EthAddress range [${RANGE_ETH_ADDRESS.min}, ${RANGE_ETH_ADDRESS.max}]`
|
|
@@ -13626,7 +13802,7 @@ function ethRandomPrivateKey() {
|
|
|
13626
13802
|
return sanitizeHex(buf2hex(import_secp256k1.secp256k1.utils.randomSecretKey()));
|
|
13627
13803
|
}
|
|
13628
13804
|
function validateAndParseEthAddress(address) {
|
|
13629
|
-
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address
|
|
13805
|
+
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address");
|
|
13630
13806
|
const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
|
|
13631
13807
|
assert(Boolean(result.match(/^(0x)?[0-9a-f]{40}$/)), "Invalid Ethereum Address Format");
|
|
13632
13808
|
return result;
|
|
@@ -17780,6 +17956,9 @@ function addAddressPadding(address) {
|
|
|
17780
17956
|
return addHexPrefix(padded);
|
|
17781
17957
|
}
|
|
17782
17958
|
function validateAndParseAddress(address) {
|
|
17959
|
+
if (isString(address) && !/^(0x)?[0-9a-f]+$/i.test(address)) {
|
|
17960
|
+
throw new Error("Invalid Address Format");
|
|
17961
|
+
}
|
|
17783
17962
|
const result = addAddressPadding(address);
|
|
17784
17963
|
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
17785
17964
|
throw new Error("Invalid Address Format");
|