starknet 11.0.1 → 11.0.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 +12 -0
- package/dist/index.d.ts +325 -116
- package/dist/index.global.js +313 -136
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +313 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +313 -136
- 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,
|
|
@@ -3215,7 +3226,6 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3215
3226
|
* ```
|
|
3216
3227
|
*/
|
|
3217
3228
|
low;
|
|
3218
|
-
// TODO should be u128
|
|
3219
3229
|
/**
|
|
3220
3230
|
* The top 128 bits of the value.
|
|
3221
3231
|
* @example
|
|
@@ -3225,7 +3235,6 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3225
3235
|
* ```
|
|
3226
3236
|
*/
|
|
3227
3237
|
high;
|
|
3228
|
-
// TODO should be u128
|
|
3229
3238
|
/**
|
|
3230
3239
|
* The abi type this class serializes.
|
|
3231
3240
|
* @example
|
|
@@ -3259,25 +3268,37 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3259
3268
|
* Throw unless a whole value can be represented as a u256, and give back its number.
|
|
3260
3269
|
*
|
|
3261
3270
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
3262
|
-
* refused
|
|
3271
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint256`
|
|
3272
|
+
* one included : its two halves are checked by {@link CairoUint256.validateProps}, which is what
|
|
3273
|
+
* the constructor calls for it.
|
|
3263
3274
|
* @param {BigNumberish} bigNumberish the value to check
|
|
3264
3275
|
* @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
|
|
3276
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
3266
3277
|
* @example
|
|
3267
3278
|
* ```typescript
|
|
3268
3279
|
* const result = CairoUint256.validate(255);
|
|
3269
3280
|
* // result = 255n
|
|
3270
3281
|
* CairoUint256.validate(-1);
|
|
3271
3282
|
* // throws Error("bigNumberish is smaller than UINT_256_MIN")
|
|
3283
|
+
* CairoUint256.validate('abc');
|
|
3284
|
+
* // throws Error("Invalid input: a u256 cannot be built from text")
|
|
3285
|
+
* CairoUint256.validate(1.5);
|
|
3286
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
3272
3287
|
* ```
|
|
3273
3288
|
*/
|
|
3274
3289
|
static validate(bigNumberish) {
|
|
3275
3290
|
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
3276
3291
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
3292
|
+
assert(!isText(bigNumberish), "Invalid input: a u256 cannot be built from text");
|
|
3293
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3277
3294
|
assert(
|
|
3278
|
-
isBigNumberish(bigNumberish)
|
|
3295
|
+
isBigNumberish(bigNumberish),
|
|
3279
3296
|
`Unsupported data type '${typeof bigNumberish}' for u256. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint256 object`
|
|
3280
3297
|
);
|
|
3298
|
+
assert(
|
|
3299
|
+
!isNumber(bigNumberish) || Number.isInteger(bigNumberish),
|
|
3300
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
3301
|
+
);
|
|
3281
3302
|
const bigInt = BigInt(bigNumberish);
|
|
3282
3303
|
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
3283
3304
|
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
@@ -3291,18 +3312,31 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3291
3312
|
* @param {BigNumberish} low the bottom 128 bits
|
|
3292
3313
|
* @param {BigNumberish} high the top 128 bits
|
|
3293
3314
|
* @returns {{low: bigint, high: bigint}} the two halves as numbers
|
|
3294
|
-
* @throws {Error} when either half is outside the u128 range
|
|
3315
|
+
* @throws {Error} when either half is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
3295
3316
|
* @example
|
|
3296
3317
|
* ```typescript
|
|
3297
3318
|
* const result = CairoUint256.validateProps(5, 4);
|
|
3298
3319
|
* // result = { low: 5n, high: 4n }
|
|
3299
3320
|
* CairoUint256.validateProps(-1, 4);
|
|
3300
3321
|
* // throws Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX")
|
|
3322
|
+
* CairoUint256.validateProps(1.5, 4);
|
|
3323
|
+
* // throws Error("low must be an integer")
|
|
3324
|
+
* CairoUint256.validateProps('abc', 4);
|
|
3325
|
+
* // throws Error("low cannot be built from text")
|
|
3301
3326
|
* ```
|
|
3302
3327
|
*/
|
|
3303
3328
|
static validateProps(low, high) {
|
|
3304
|
-
const
|
|
3305
|
-
|
|
3329
|
+
const validateHalf = (half, name) => {
|
|
3330
|
+
assert(half !== null, `${name} cannot be null`);
|
|
3331
|
+
assert(half !== void 0, `${name} cannot be undefined`);
|
|
3332
|
+
assert(!isText(half), `${name} cannot be built from text`);
|
|
3333
|
+
assert(!isEmptyHex(half), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
3334
|
+
assert(isBigNumberish(half), `${name} must be a BigNumberish`);
|
|
3335
|
+
assert(!isNumber(half) || Number.isInteger(half), `${name} must be an integer`);
|
|
3336
|
+
return BigInt(half);
|
|
3337
|
+
};
|
|
3338
|
+
const bigIntLow = validateHalf(low, "low");
|
|
3339
|
+
const bigIntHigh = validateHalf(high, "high");
|
|
3306
3340
|
assert(
|
|
3307
3341
|
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
3308
3342
|
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
@@ -3439,7 +3473,6 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3439
3473
|
* ```
|
|
3440
3474
|
*/
|
|
3441
3475
|
limb0;
|
|
3442
|
-
// TODO should be u128
|
|
3443
3476
|
/**
|
|
3444
3477
|
* Bits 128 to 255 of the value.
|
|
3445
3478
|
* @example
|
|
@@ -3449,7 +3482,6 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3449
3482
|
* ```
|
|
3450
3483
|
*/
|
|
3451
3484
|
limb1;
|
|
3452
|
-
// TODO should be u128
|
|
3453
3485
|
/**
|
|
3454
3486
|
* Bits 256 to 383 of the value.
|
|
3455
3487
|
* @example
|
|
@@ -3459,7 +3491,6 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3459
3491
|
* ```
|
|
3460
3492
|
*/
|
|
3461
3493
|
limb2;
|
|
3462
|
-
// TODO should be u128
|
|
3463
3494
|
/**
|
|
3464
3495
|
* Bits 384 to 511 of the value.
|
|
3465
3496
|
* @example
|
|
@@ -3469,7 +3500,6 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3469
3500
|
* ```
|
|
3470
3501
|
*/
|
|
3471
3502
|
limb3;
|
|
3472
|
-
// TODO should be u128
|
|
3473
3503
|
/**
|
|
3474
3504
|
* The abi type this class serializes.
|
|
3475
3505
|
* @example
|
|
@@ -3511,25 +3541,37 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3511
3541
|
* Throw unless a whole value can be represented as a u512, and give back its number.
|
|
3512
3542
|
*
|
|
3513
3543
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
3514
|
-
* refused
|
|
3544
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint512`
|
|
3545
|
+
* one included : its four limbs are checked by {@link CairoUint512.validateProps}, which is what
|
|
3546
|
+
* the constructor calls for it.
|
|
3515
3547
|
* @param {BigNumberish} bigNumberish the value to check
|
|
3516
3548
|
* @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
|
|
3549
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
3518
3550
|
* @example
|
|
3519
3551
|
* ```typescript
|
|
3520
3552
|
* const result = CairoUint512.validate(255);
|
|
3521
3553
|
* // result = 255n
|
|
3522
3554
|
* CairoUint512.validate(-1);
|
|
3523
3555
|
* // throws Error("bigNumberish is smaller than UINT_512_MIN.")
|
|
3556
|
+
* CairoUint512.validate('abc');
|
|
3557
|
+
* // throws Error("Invalid input: a u512 cannot be built from text")
|
|
3558
|
+
* CairoUint512.validate(1.5);
|
|
3559
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
3524
3560
|
* ```
|
|
3525
3561
|
*/
|
|
3526
3562
|
static validate(bigNumberish) {
|
|
3527
3563
|
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
3528
3564
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
3565
|
+
assert(!isText(bigNumberish), "Invalid input: a u512 cannot be built from text");
|
|
3566
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3529
3567
|
assert(
|
|
3530
|
-
isBigNumberish(bigNumberish)
|
|
3568
|
+
isBigNumberish(bigNumberish),
|
|
3531
3569
|
`Unsupported data type '${typeof bigNumberish}' for u512. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint512 object`
|
|
3532
3570
|
);
|
|
3571
|
+
assert(
|
|
3572
|
+
!isNumber(bigNumberish) || Number.isInteger(bigNumberish),
|
|
3573
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
3574
|
+
);
|
|
3533
3575
|
const bigInt = BigInt(bigNumberish);
|
|
3534
3576
|
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
3535
3577
|
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
@@ -3545,20 +3587,33 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3545
3587
|
* @param {BigNumberish} limb2 bits 256 to 383
|
|
3546
3588
|
* @param {BigNumberish} limb3 bits 384 to 511
|
|
3547
3589
|
* @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
|
|
3590
|
+
* @throws {Error} when any limb is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
3549
3591
|
* @example
|
|
3550
3592
|
* ```typescript
|
|
3551
3593
|
* const result = CairoUint512.validateProps(7, 0, 0, 64);
|
|
3552
3594
|
* // result = { limb0: 7n, limb1: 0n, limb2: 0n, limb3: 64n }
|
|
3553
3595
|
* CairoUint512.validateProps(-1, 0, 0, 0);
|
|
3554
3596
|
* // throws Error("limb0 is not in the range of a u128 number")
|
|
3597
|
+
* CairoUint512.validateProps(1.5, 0, 0, 0);
|
|
3598
|
+
* // throws Error("limb0 must be an integer")
|
|
3599
|
+
* CairoUint512.validateProps('abc', 0, 0, 0);
|
|
3600
|
+
* // throws Error("limb0 cannot be built from text")
|
|
3555
3601
|
* ```
|
|
3556
3602
|
*/
|
|
3557
3603
|
static validateProps(limb0, limb1, limb2, limb3) {
|
|
3558
|
-
const
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3604
|
+
const validateLimb = (limb, name) => {
|
|
3605
|
+
assert(limb !== null, `${name} cannot be null`);
|
|
3606
|
+
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
3607
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
3608
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
3609
|
+
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
3610
|
+
assert(!isNumber(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
3611
|
+
return BigInt(limb);
|
|
3612
|
+
};
|
|
3613
|
+
const l0 = validateLimb(limb0, "limb0");
|
|
3614
|
+
const l1 = validateLimb(limb1, "limb1");
|
|
3615
|
+
const l2 = validateLimb(limb2, "limb2");
|
|
3616
|
+
const l3 = validateLimb(limb3, "limb3");
|
|
3562
3617
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
3563
3618
|
assert(
|
|
3564
3619
|
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
@@ -3730,7 +3785,7 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3730
3785
|
* otherwise. Text therefore only fits here up to 12 ASCII characters : one more already
|
|
3731
3786
|
* makes a number past 79228162514264337593543950335.
|
|
3732
3787
|
* @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
|
|
3788
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
3734
3789
|
* @example
|
|
3735
3790
|
* ```typescript
|
|
3736
3791
|
* const result = new CairoUint96('abcdefghijkl').toApiRequest();
|
|
@@ -3818,11 +3873,11 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3818
3873
|
/**
|
|
3819
3874
|
* Throw unless the value can be carried by a u96.
|
|
3820
3875
|
*
|
|
3821
|
-
*
|
|
3822
|
-
* an array, a number with a decimal part, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
3876
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
3877
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
3823
3878
|
* that last check as the number its bytes spell, so `'abcdefghijklm'` is refused for being out of range.
|
|
3824
3879
|
* @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
|
|
3880
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
3826
3881
|
* @example
|
|
3827
3882
|
* ```typescript
|
|
3828
3883
|
* CairoUint96.validate(5000000000); // passes
|
|
@@ -3837,6 +3892,7 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3837
3892
|
!isNumber(data) || Number.isInteger(data),
|
|
3838
3893
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
3839
3894
|
);
|
|
3895
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3840
3896
|
const value = _CairoUint96.__processData(data);
|
|
3841
3897
|
assert(
|
|
3842
3898
|
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
@@ -4223,7 +4279,7 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4223
4279
|
* otherwise. Text therefore only fits here while it is a single ASCII character : two characters
|
|
4224
4280
|
* already make a number past 255.
|
|
4225
4281
|
* @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
|
|
4282
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4227
4283
|
* @example
|
|
4228
4284
|
* ```typescript
|
|
4229
4285
|
* const result = new CairoUint8('a').toApiRequest();
|
|
@@ -4313,11 +4369,11 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4313
4369
|
/**
|
|
4314
4370
|
* Throw unless the value can be carried by a u8.
|
|
4315
4371
|
*
|
|
4316
|
-
*
|
|
4317
|
-
* an array, a number with a decimal part, and a value outside [0, 255]. A text string reaches
|
|
4372
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4373
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 255]. A text string reaches
|
|
4318
4374
|
* that last check as the number its bytes spell, so `'ab'` is refused for being out of range.
|
|
4319
4375
|
* @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
|
|
4376
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4321
4377
|
* @example
|
|
4322
4378
|
* ```typescript
|
|
4323
4379
|
* CairoUint8.validate(44); // passes
|
|
@@ -4332,6 +4388,7 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4332
4388
|
!isNumber(data) || Number.isInteger(data),
|
|
4333
4389
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4334
4390
|
);
|
|
4391
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4335
4392
|
const value = _CairoUint8.__processData(data);
|
|
4336
4393
|
assert(
|
|
4337
4394
|
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
@@ -4422,7 +4479,7 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4422
4479
|
* otherwise. Text therefore only fits here up to 2 ASCII characters : one more already
|
|
4423
4480
|
* makes a number past 65535.
|
|
4424
4481
|
* @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
|
|
4482
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4426
4483
|
* @example
|
|
4427
4484
|
* ```typescript
|
|
4428
4485
|
* const result = new CairoUint16('ab').toApiRequest();
|
|
@@ -4510,11 +4567,11 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4510
4567
|
/**
|
|
4511
4568
|
* Throw unless the value can be carried by a u16.
|
|
4512
4569
|
*
|
|
4513
|
-
*
|
|
4514
|
-
* an array, a number with a decimal part, and a value outside [0, 65535]. A text string reaches
|
|
4570
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4571
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 65535]. A text string reaches
|
|
4515
4572
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
4516
4573
|
* @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
|
|
4574
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4518
4575
|
* @example
|
|
4519
4576
|
* ```typescript
|
|
4520
4577
|
* CairoUint16.validate(300); // passes
|
|
@@ -4529,6 +4586,7 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4529
4586
|
!isNumber(data) || Number.isInteger(data),
|
|
4530
4587
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4531
4588
|
);
|
|
4589
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4532
4590
|
const value = _CairoUint16.__processData(data);
|
|
4533
4591
|
assert(
|
|
4534
4592
|
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
@@ -4619,7 +4677,7 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4619
4677
|
* otherwise. Text therefore only fits here up to 8 ASCII characters : one more already
|
|
4620
4678
|
* makes a number past 18446744073709551615.
|
|
4621
4679
|
* @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
|
|
4680
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4623
4681
|
* @example
|
|
4624
4682
|
* ```typescript
|
|
4625
4683
|
* const result = new CairoUint64('abcdefgh').toApiRequest();
|
|
@@ -4707,11 +4765,11 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4707
4765
|
/**
|
|
4708
4766
|
* Throw unless the value can be carried by a u64.
|
|
4709
4767
|
*
|
|
4710
|
-
*
|
|
4711
|
-
* an array, a number with a decimal part, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
4768
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4769
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
4712
4770
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
4713
4771
|
* @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
|
|
4772
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4715
4773
|
* @example
|
|
4716
4774
|
* ```typescript
|
|
4717
4775
|
* CairoUint64.validate(5000000000); // passes
|
|
@@ -4726,6 +4784,7 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4726
4784
|
!isNumber(data) || Number.isInteger(data),
|
|
4727
4785
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4728
4786
|
);
|
|
4787
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4729
4788
|
const value = _CairoUint64.__processData(data);
|
|
4730
4789
|
assert(
|
|
4731
4790
|
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
@@ -4816,7 +4875,7 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4816
4875
|
* otherwise. Text therefore only fits here up to 16 ASCII characters : one more already
|
|
4817
4876
|
* makes a number past 340282366920938463463374607431768211455.
|
|
4818
4877
|
* @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
|
|
4878
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4820
4879
|
* @example
|
|
4821
4880
|
* ```typescript
|
|
4822
4881
|
* const result = new CairoUint128('abcdefghijklmnop').toApiRequest();
|
|
@@ -4904,11 +4963,11 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4904
4963
|
/**
|
|
4905
4964
|
* Throw unless the value can be carried by a u128.
|
|
4906
4965
|
*
|
|
4907
|
-
*
|
|
4908
|
-
* an array, a number with a decimal part, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
4966
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4967
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
4909
4968
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
4910
4969
|
* @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
|
|
4970
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4912
4971
|
* @example
|
|
4913
4972
|
* ```typescript
|
|
4914
4973
|
* CairoUint128.validate(5000000000); // passes
|
|
@@ -4923,6 +4982,7 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4923
4982
|
!isNumber(data) || Number.isInteger(data),
|
|
4924
4983
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4925
4984
|
);
|
|
4985
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4926
4986
|
const value = _CairoUint128.__processData(data);
|
|
4927
4987
|
assert(
|
|
4928
4988
|
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
@@ -5009,15 +5069,17 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5009
5069
|
/**
|
|
5010
5070
|
* Build from a number, a string or a boolean, refusing anything out of the i8 range.
|
|
5011
5071
|
*
|
|
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.
|
|
5072
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5073
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to a single
|
|
5074
|
+
* ASCII character : one more already makes a number past 127.
|
|
5015
5075
|
* @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
|
|
5076
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5017
5077
|
* @example
|
|
5018
5078
|
* ```typescript
|
|
5019
5079
|
* const result = new CairoInt8('a').toApiRequest();
|
|
5020
5080
|
* // result = ["97"]
|
|
5081
|
+
* const result2 = new CairoInt8('-5').toApiRequest();
|
|
5082
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5021
5083
|
* ```
|
|
5022
5084
|
*/
|
|
5023
5085
|
constructor(data) {
|
|
@@ -5029,6 +5091,9 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5029
5091
|
*
|
|
5030
5092
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5031
5093
|
* far outside the i8 range comes back untouched rather than raising.
|
|
5094
|
+
*
|
|
5095
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5096
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5032
5097
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5033
5098
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5034
5099
|
* @example
|
|
@@ -5037,9 +5102,14 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5037
5102
|
* // result = 97n
|
|
5038
5103
|
* const result2 = CairoInt8.__processData('ab');
|
|
5039
5104
|
* // result2 = 24930n (past the i8 range, and returned all the same)
|
|
5105
|
+
* const result3 = CairoInt8.__processData('-0x5');
|
|
5106
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5040
5107
|
* ```
|
|
5041
5108
|
*/
|
|
5042
5109
|
static __processData(data) {
|
|
5110
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5111
|
+
return -BigInt(data.slice(1));
|
|
5112
|
+
}
|
|
5043
5113
|
if (isString(data) && isText(data)) {
|
|
5044
5114
|
return utf8ToBigInt(data);
|
|
5045
5115
|
}
|
|
@@ -5118,11 +5188,12 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5118
5188
|
/**
|
|
5119
5189
|
* Throw unless the value can be carried by an i8.
|
|
5120
5190
|
*
|
|
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
|
|
5191
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5192
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-128, 127]. A text string
|
|
5193
|
+
* reaches that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
5194
|
+
* range.
|
|
5124
5195
|
* @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
|
|
5196
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5126
5197
|
* @example
|
|
5127
5198
|
* ```typescript
|
|
5128
5199
|
* CairoInt8.validate(5); // passes
|
|
@@ -5137,6 +5208,7 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
5137
5208
|
!isNumber(data) || Number.isInteger(data),
|
|
5138
5209
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5139
5210
|
);
|
|
5211
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5140
5212
|
const value = _CairoInt8.__processData(data);
|
|
5141
5213
|
assert(
|
|
5142
5214
|
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
@@ -5227,15 +5299,17 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5227
5299
|
/**
|
|
5228
5300
|
* Build from a number, a string or a boolean, refusing anything out of the i16 range.
|
|
5229
5301
|
*
|
|
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.
|
|
5302
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5303
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 2 ASCII
|
|
5304
|
+
* characters : one more already makes a number past 32767.
|
|
5233
5305
|
* @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
|
|
5306
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5235
5307
|
* @example
|
|
5236
5308
|
* ```typescript
|
|
5237
5309
|
* const result = new CairoInt16('ab').toApiRequest();
|
|
5238
5310
|
* // result = ["24930"]
|
|
5311
|
+
* const result2 = new CairoInt16('-5').toApiRequest();
|
|
5312
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5239
5313
|
* ```
|
|
5240
5314
|
*/
|
|
5241
5315
|
constructor(data) {
|
|
@@ -5247,6 +5321,9 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5247
5321
|
*
|
|
5248
5322
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5249
5323
|
* far outside the i16 range comes back untouched rather than raising.
|
|
5324
|
+
*
|
|
5325
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5326
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5250
5327
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5251
5328
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5252
5329
|
* @example
|
|
@@ -5255,9 +5332,14 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5255
5332
|
* // result = 24930n
|
|
5256
5333
|
* const result2 = CairoInt16.__processData('abc');
|
|
5257
5334
|
* // result2 = 6382179n (past the i16 range, and returned all the same)
|
|
5335
|
+
* const result3 = CairoInt16.__processData('-0x5');
|
|
5336
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5258
5337
|
* ```
|
|
5259
5338
|
*/
|
|
5260
5339
|
static __processData(data) {
|
|
5340
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5341
|
+
return -BigInt(data.slice(1));
|
|
5342
|
+
}
|
|
5261
5343
|
if (isString(data) && isText(data)) {
|
|
5262
5344
|
return utf8ToBigInt(data);
|
|
5263
5345
|
}
|
|
@@ -5336,11 +5418,11 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5336
5418
|
/**
|
|
5337
5419
|
* Throw unless the value can be carried by an i16.
|
|
5338
5420
|
*
|
|
5339
|
-
*
|
|
5340
|
-
* an array, a number with a decimal part, and a value outside [-32768, 32767]. A text string reaches
|
|
5421
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5422
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-32768, 32767]. A text string reaches
|
|
5341
5423
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
5342
5424
|
* @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
|
|
5425
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5344
5426
|
* @example
|
|
5345
5427
|
* ```typescript
|
|
5346
5428
|
* CairoInt16.validate(300); // passes
|
|
@@ -5355,6 +5437,7 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5355
5437
|
!isNumber(data) || Number.isInteger(data),
|
|
5356
5438
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5357
5439
|
);
|
|
5440
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5358
5441
|
const value = _CairoInt16.__processData(data);
|
|
5359
5442
|
assert(
|
|
5360
5443
|
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
@@ -5445,15 +5528,17 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5445
5528
|
/**
|
|
5446
5529
|
* Build from a number, a string or a boolean, refusing anything out of the i32 range.
|
|
5447
5530
|
*
|
|
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.
|
|
5531
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5532
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 4 ASCII
|
|
5533
|
+
* characters : one more already makes a number past 2147483647.
|
|
5451
5534
|
* @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
|
|
5535
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5453
5536
|
* @example
|
|
5454
5537
|
* ```typescript
|
|
5455
5538
|
* const result = new CairoInt32('abcd').toApiRequest();
|
|
5456
5539
|
* // result = ["1633837924"]
|
|
5540
|
+
* const result2 = new CairoInt32('-5').toApiRequest();
|
|
5541
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5457
5542
|
* ```
|
|
5458
5543
|
*/
|
|
5459
5544
|
constructor(data) {
|
|
@@ -5465,6 +5550,9 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5465
5550
|
*
|
|
5466
5551
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5467
5552
|
* far outside the i32 range comes back untouched rather than raising.
|
|
5553
|
+
*
|
|
5554
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5555
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5468
5556
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5469
5557
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5470
5558
|
* @example
|
|
@@ -5473,9 +5561,14 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5473
5561
|
* // result = 1633837924n
|
|
5474
5562
|
* const result2 = CairoInt32.__processData('abcde');
|
|
5475
5563
|
* // result2 = 418262508645n (past the i32 range, and returned all the same)
|
|
5564
|
+
* const result3 = CairoInt32.__processData('-0x5');
|
|
5565
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5476
5566
|
* ```
|
|
5477
5567
|
*/
|
|
5478
5568
|
static __processData(data) {
|
|
5569
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5570
|
+
return -BigInt(data.slice(1));
|
|
5571
|
+
}
|
|
5479
5572
|
if (isString(data) && isText(data)) {
|
|
5480
5573
|
return utf8ToBigInt(data);
|
|
5481
5574
|
}
|
|
@@ -5554,11 +5647,11 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5554
5647
|
/**
|
|
5555
5648
|
* Throw unless the value can be carried by an i32.
|
|
5556
5649
|
*
|
|
5557
|
-
*
|
|
5558
|
-
* an array, a number with a decimal part, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
5650
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5651
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
5559
5652
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
5560
5653
|
* @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
|
|
5654
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5562
5655
|
* @example
|
|
5563
5656
|
* ```typescript
|
|
5564
5657
|
* CairoInt32.validate(70000); // passes
|
|
@@ -5573,6 +5666,7 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5573
5666
|
!isNumber(data) || Number.isInteger(data),
|
|
5574
5667
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5575
5668
|
);
|
|
5669
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5576
5670
|
const value = _CairoInt32.__processData(data);
|
|
5577
5671
|
assert(
|
|
5578
5672
|
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
@@ -5663,15 +5757,17 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5663
5757
|
/**
|
|
5664
5758
|
* Build from a number, a string or a boolean, refusing anything out of the i64 range.
|
|
5665
5759
|
*
|
|
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.
|
|
5760
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5761
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 8 ASCII
|
|
5762
|
+
* characters : one more already makes a number past 9223372036854775807.
|
|
5669
5763
|
* @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
|
|
5764
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5671
5765
|
* @example
|
|
5672
5766
|
* ```typescript
|
|
5673
5767
|
* const result = new CairoInt64('abcdefgh').toApiRequest();
|
|
5674
5768
|
* // result = ["7017280452245743464"]
|
|
5769
|
+
* const result2 = new CairoInt64('-5').toApiRequest();
|
|
5770
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5675
5771
|
* ```
|
|
5676
5772
|
*/
|
|
5677
5773
|
constructor(data) {
|
|
@@ -5683,6 +5779,9 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5683
5779
|
*
|
|
5684
5780
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5685
5781
|
* far outside the i64 range comes back untouched rather than raising.
|
|
5782
|
+
*
|
|
5783
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5784
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5686
5785
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5687
5786
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5688
5787
|
* @example
|
|
@@ -5691,9 +5790,14 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5691
5790
|
* // result = 7017280452245743464n
|
|
5692
5791
|
* const result2 = CairoInt64.__processData('abcdefghi');
|
|
5693
5792
|
* // result2 = 1796423795774910326889n (past the i64 range, and returned all the same)
|
|
5793
|
+
* const result3 = CairoInt64.__processData('-0x5');
|
|
5794
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5694
5795
|
* ```
|
|
5695
5796
|
*/
|
|
5696
5797
|
static __processData(data) {
|
|
5798
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5799
|
+
return -BigInt(data.slice(1));
|
|
5800
|
+
}
|
|
5697
5801
|
if (isString(data) && isText(data)) {
|
|
5698
5802
|
return utf8ToBigInt(data);
|
|
5699
5803
|
}
|
|
@@ -5772,11 +5876,11 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5772
5876
|
/**
|
|
5773
5877
|
* Throw unless the value can be carried by an i64.
|
|
5774
5878
|
*
|
|
5775
|
-
*
|
|
5776
|
-
* an array, a number with a decimal part, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
5879
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5880
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
5777
5881
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
5778
5882
|
* @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
|
|
5883
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5780
5884
|
* @example
|
|
5781
5885
|
* ```typescript
|
|
5782
5886
|
* CairoInt64.validate(5000000000); // passes
|
|
@@ -5791,6 +5895,7 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5791
5895
|
!isNumber(data) || Number.isInteger(data),
|
|
5792
5896
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5793
5897
|
);
|
|
5898
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5794
5899
|
const value = _CairoInt64.__processData(data);
|
|
5795
5900
|
assert(
|
|
5796
5901
|
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
@@ -5881,15 +5986,17 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5881
5986
|
/**
|
|
5882
5987
|
* Build from a number, a string or a boolean, refusing anything out of the i128 range.
|
|
5883
5988
|
*
|
|
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.
|
|
5989
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5990
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 16 ASCII
|
|
5991
|
+
* characters : one more already makes a number past 170141183460469231731687303715884105727.
|
|
5887
5992
|
* @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
|
|
5993
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5889
5994
|
* @example
|
|
5890
5995
|
* ```typescript
|
|
5891
5996
|
* const result = new CairoInt128('abcdefghijklmnop').toApiRequest();
|
|
5892
5997
|
* // result = ["129445976596022050476432668810952994672"]
|
|
5998
|
+
* const result2 = new CairoInt128('-5').toApiRequest();
|
|
5999
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5893
6000
|
* ```
|
|
5894
6001
|
*/
|
|
5895
6002
|
constructor(data) {
|
|
@@ -5901,6 +6008,9 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5901
6008
|
*
|
|
5902
6009
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5903
6010
|
* far outside the i128 range comes back untouched rather than raising.
|
|
6011
|
+
*
|
|
6012
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
6013
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5904
6014
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5905
6015
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5906
6016
|
* @example
|
|
@@ -5909,9 +6019,14 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5909
6019
|
* // result = 129445976596022050476432668810952994672n
|
|
5910
6020
|
* const result2 = CairoInt128.__processData('abcdefghijklmnopq');
|
|
5911
6021
|
* // result2 = 33138170008581644921966763215603966636145n (past the i128 range, and returned all the same)
|
|
6022
|
+
* const result3 = CairoInt128.__processData('-0x5');
|
|
6023
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5912
6024
|
* ```
|
|
5913
6025
|
*/
|
|
5914
6026
|
static __processData(data) {
|
|
6027
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
6028
|
+
return -BigInt(data.slice(1));
|
|
6029
|
+
}
|
|
5915
6030
|
if (isString(data) && isText(data)) {
|
|
5916
6031
|
return utf8ToBigInt(data);
|
|
5917
6032
|
}
|
|
@@ -5990,11 +6105,11 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5990
6105
|
/**
|
|
5991
6106
|
* Throw unless the value can be carried by an i128.
|
|
5992
6107
|
*
|
|
5993
|
-
*
|
|
5994
|
-
* an array, a number with a decimal part, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
6108
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
6109
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
5995
6110
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
5996
6111
|
* @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
|
|
6112
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5998
6113
|
* @example
|
|
5999
6114
|
* ```typescript
|
|
6000
6115
|
* CairoInt128.validate(5000000000); // passes
|
|
@@ -6009,6 +6124,7 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
6009
6124
|
!isNumber(data) || Number.isInteger(data),
|
|
6010
6125
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
6011
6126
|
);
|
|
6127
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
6012
6128
|
const value = _CairoInt128.__processData(data);
|
|
6013
6129
|
assert(
|
|
6014
6130
|
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
@@ -6099,7 +6215,7 @@ var CairoBool = class _CairoBool {
|
|
|
6099
6215
|
/**
|
|
6100
6216
|
* Build from a boolean, or from the numbers 0 and 1.
|
|
6101
6217
|
* @param {BigNumberish | boolean} data the value to carry : a boolean, 0 or 1
|
|
6102
|
-
* @throws {Error} when the value is text,
|
|
6218
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
6103
6219
|
* @example
|
|
6104
6220
|
* ```typescript
|
|
6105
6221
|
* const result = new CairoBool(false).toApiRequest();
|
|
@@ -6172,21 +6288,28 @@ var CairoBool = class _CairoBool {
|
|
|
6172
6288
|
/**
|
|
6173
6289
|
* Throw unless the value can be carried by a bool.
|
|
6174
6290
|
*
|
|
6175
|
-
* Text is refused first, then
|
|
6176
|
-
*
|
|
6177
|
-
*
|
|
6291
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
6292
|
+
* is, so that a negative one reaches the last check. Anything else is read as a felt252 — which
|
|
6293
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked to be
|
|
6294
|
+
* one of the only two numbers a bool can hold.
|
|
6178
6295
|
* @param {BigNumberish | boolean} data the value to check
|
|
6179
|
-
* @throws {Error} when the value is text,
|
|
6296
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
6180
6297
|
* @example
|
|
6181
6298
|
* ```typescript
|
|
6182
6299
|
* CairoBool.validate(true); // passes
|
|
6183
6300
|
* CairoBool.validate(2);
|
|
6184
6301
|
* // throws Error("Only values 0 or 1 are possible in a core::bool, received 2")
|
|
6302
|
+
* CairoBool.validate(-1);
|
|
6303
|
+
* // throws Error("Only values 0 or 1 are possible in a core::bool, received -1")
|
|
6185
6304
|
* ```
|
|
6186
6305
|
*/
|
|
6187
6306
|
static validate(data) {
|
|
6188
6307
|
assert(!isText(data), "Invalid input: a core::bool cannot be built from text");
|
|
6189
|
-
|
|
6308
|
+
assert(
|
|
6309
|
+
!isNumber(data) || Number.isInteger(data),
|
|
6310
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6311
|
+
);
|
|
6312
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
6190
6313
|
assert(
|
|
6191
6314
|
value === 0n || value === 1n,
|
|
6192
6315
|
`Only values 0 or 1 are possible in a core::bool, received ${value}`
|
|
@@ -6301,7 +6424,9 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6301
6424
|
/**
|
|
6302
6425
|
* @param {any[]} arr either one value — a 512-bit number or a {@link Secp256k1PointStruct} — or
|
|
6303
6426
|
* the four limbs
|
|
6304
|
-
* @throws {Error} when a value is
|
|
6427
|
+
* @throws {Error} when a value is null, undefined, of an unread type, text, a decimal number, or out
|
|
6428
|
+
* of range — see {@link CairoSecp256k1Point.validate} and {@link CairoSecp256k1Point.validateProps}
|
|
6429
|
+
* — or when the argument count is neither 1 nor 4
|
|
6305
6430
|
* @example
|
|
6306
6431
|
* ```typescript
|
|
6307
6432
|
* const result = new CairoSecp256k1Point(1n).toApiRequest();
|
|
@@ -6348,22 +6473,32 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6348
6473
|
* the constructor needs it, and computing it twice would mean splitting a 512-bit value twice.
|
|
6349
6474
|
* @param {BigNumberish} input the 512-bit value to check
|
|
6350
6475
|
* @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]
|
|
6476
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or outside [0, 2^512 - 1]
|
|
6352
6477
|
* @example
|
|
6353
6478
|
* ```typescript
|
|
6354
6479
|
* const result = CairoSecp256k1Point.validate('0x1234');
|
|
6355
6480
|
* // result = 4660n
|
|
6356
6481
|
* CairoSecp256k1Point.validate(SECP256K1_POINT_MAX + 1n);
|
|
6357
6482
|
* // throws Error("input is bigger than SECP256K1_POINT_MAX")
|
|
6483
|
+
* CairoSecp256k1Point.validate('abc');
|
|
6484
|
+
* // throws Error("Invalid input: a Secp256k1Point cannot be built from text")
|
|
6485
|
+
* CairoSecp256k1Point.validate(1.5);
|
|
6486
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
6358
6487
|
* ```
|
|
6359
6488
|
*/
|
|
6360
6489
|
static validate(input) {
|
|
6361
6490
|
assert(input !== null, "null value is not allowed for Secp256k1Point");
|
|
6362
6491
|
assert(input !== void 0, "undefined value is not allowed for Secp256k1Point");
|
|
6492
|
+
assert(!isText(input), "Invalid input: a Secp256k1Point cannot be built from text");
|
|
6493
|
+
assert(!isEmptyHex(input), "Invalid input: '0x' holds no hexadecimal digit");
|
|
6363
6494
|
assert(
|
|
6364
6495
|
isBigNumberish(input),
|
|
6365
6496
|
`Unsupported input for Secp256k1Point. Expected a number, a bigint, or a string spelling one, received '${typeof input}'`
|
|
6366
6497
|
);
|
|
6498
|
+
assert(
|
|
6499
|
+
!isNumber(input) || Number.isInteger(input),
|
|
6500
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6501
|
+
);
|
|
6367
6502
|
const bigInt = BigInt(input);
|
|
6368
6503
|
assert(bigInt >= SECP256K1_POINT_MIN, "input is smaller than SECP256K1_POINT_MIN");
|
|
6369
6504
|
assert(bigInt <= SECP256K1_POINT_MAX, "input is bigger than SECP256K1_POINT_MAX");
|
|
@@ -6376,20 +6511,27 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6376
6511
|
* @param {BigNumberish} yLow the low 128 bits of y
|
|
6377
6512
|
* @param {BigNumberish} yHigh the high 128 bits of y
|
|
6378
6513
|
* @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
|
|
6514
|
+
* @throws {Error} when a limb is null, undefined, text, `'0x'`, not a number, a decimal number, negative, or wider than 128 bits
|
|
6380
6515
|
* @example
|
|
6381
6516
|
* ```typescript
|
|
6382
6517
|
* const result = CairoSecp256k1Point.validateProps(1, 2, 3, 4);
|
|
6383
6518
|
* // result = { xLow: 1n, xHigh: 2n, yLow: 3n, yHigh: 4n }
|
|
6384
6519
|
* CairoSecp256k1Point.validateProps(1, 2, 3, 2n ** 128n);
|
|
6385
6520
|
* // throws Error("yHigh must fit in 128 bits")
|
|
6521
|
+
* CairoSecp256k1Point.validateProps(1.5, 2, 3, 4);
|
|
6522
|
+
* // throws Error("xLow must be an integer")
|
|
6523
|
+
* CairoSecp256k1Point.validateProps('abc', 2, 3, 4);
|
|
6524
|
+
* // throws Error("xLow cannot be built from text")
|
|
6386
6525
|
* ```
|
|
6387
6526
|
*/
|
|
6388
6527
|
static validateProps(xLow, xHigh, yLow, yHigh) {
|
|
6389
6528
|
const validateLimb = (limb, name) => {
|
|
6390
6529
|
assert(limb !== null, `${name} cannot be null`);
|
|
6391
6530
|
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
6531
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
6532
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
6392
6533
|
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
6534
|
+
assert(!isNumber(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
6393
6535
|
const bigInt = BigInt(limb);
|
|
6394
6536
|
assert(bigInt >= 0n, `${name} must be non-negative`);
|
|
6395
6537
|
assert(bigInt <= UINT_128_MAX, `${name} must fit in 128 bits`);
|
|
@@ -7532,9 +7674,9 @@ var CairoClassHash = class _CairoClassHash {
|
|
|
7532
7674
|
*/
|
|
7533
7675
|
static abiSelector = Literal.ClassHash;
|
|
7534
7676
|
/**
|
|
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,
|
|
7677
|
+
* Build from a number or a numeric string, refusing text and anything outside the ClassHash range.
|
|
7678
|
+
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^251 - 1]
|
|
7679
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
7538
7680
|
* @example
|
|
7539
7681
|
* ```typescript
|
|
7540
7682
|
* const result = new CairoClassHash('0x1234').toApiRequest();
|
|
@@ -7589,21 +7731,34 @@ var CairoClassHash = class _CairoClassHash {
|
|
|
7589
7731
|
/**
|
|
7590
7732
|
* Throw unless the value can be carried by a ClassHash.
|
|
7591
7733
|
*
|
|
7592
|
-
* Text is refused first, then
|
|
7593
|
-
*
|
|
7594
|
-
* a
|
|
7734
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
7735
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
7736
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
7737
|
+
* the range of the Cairo `ClassHash` type, [0, 2^251), which is narrower than the field.
|
|
7595
7738
|
* @param {BigNumberish | boolean} data the value to check
|
|
7596
|
-
* @throws {Error} when the value is text,
|
|
7739
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
7597
7740
|
* @example
|
|
7598
7741
|
* ```typescript
|
|
7599
7742
|
* CairoClassHash.validate('0x1234'); // passes
|
|
7600
7743
|
* CairoClassHash.validate('abc');
|
|
7601
7744
|
* // throws Error("Invalid input: a ClassHash cannot be built from text")
|
|
7745
|
+
* CairoClassHash.validate(2n ** 251n);
|
|
7746
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
7747
|
+
* CairoClassHash.validate(-1);
|
|
7748
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
7602
7749
|
* ```
|
|
7603
7750
|
*/
|
|
7604
7751
|
static validate(data) {
|
|
7605
7752
|
assert(!isText(data), "Invalid input: a ClassHash cannot be built from text");
|
|
7606
|
-
|
|
7753
|
+
assert(
|
|
7754
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7755
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7756
|
+
);
|
|
7757
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7758
|
+
assert(
|
|
7759
|
+
value >= RANGE_CLASS_HASH.min && value <= RANGE_CLASS_HASH.max,
|
|
7760
|
+
`Value is out of ClassHash range [${RANGE_CLASS_HASH.min}, ${RANGE_CLASS_HASH.max}]`
|
|
7761
|
+
);
|
|
7607
7762
|
}
|
|
7608
7763
|
/**
|
|
7609
7764
|
* Can this value be carried by a ClassHash?
|
|
@@ -7682,7 +7837,7 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7682
7837
|
/**
|
|
7683
7838
|
* Build from a number or a numeric string, refusing text and anything wider than 252 bits.
|
|
7684
7839
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^252 - 1]
|
|
7685
|
-
* @throws {Error} when the value is text,
|
|
7840
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
7686
7841
|
* @example
|
|
7687
7842
|
* ```typescript
|
|
7688
7843
|
* const result = new CairoContractAddress('0x1234').toApiRequest();
|
|
@@ -7737,11 +7892,12 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7737
7892
|
/**
|
|
7738
7893
|
* Throw unless the value can be carried by a ContractAddress.
|
|
7739
7894
|
*
|
|
7740
|
-
* Text is refused first, then
|
|
7741
|
-
*
|
|
7742
|
-
* is
|
|
7895
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
7896
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
7897
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
7898
|
+
* the bound an address has, which is narrower than the field.
|
|
7743
7899
|
* @param {BigNumberish | boolean} data the value to check
|
|
7744
|
-
* @throws {Error} when the value is text,
|
|
7900
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
7745
7901
|
* @example
|
|
7746
7902
|
* ```typescript
|
|
7747
7903
|
* CairoContractAddress.validate('0x1234'); // passes
|
|
@@ -7749,11 +7905,17 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7749
7905
|
* // throws Error("Invalid input: a ContractAddress cannot be built from text")
|
|
7750
7906
|
* CairoContractAddress.validate(2n ** 251n);
|
|
7751
7907
|
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
7908
|
+
* CairoContractAddress.validate(-1);
|
|
7909
|
+
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
7752
7910
|
* ```
|
|
7753
7911
|
*/
|
|
7754
7912
|
static validate(data) {
|
|
7755
7913
|
assert(!isText(data), "Invalid input: a ContractAddress cannot be built from text");
|
|
7756
|
-
|
|
7914
|
+
assert(
|
|
7915
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7916
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7917
|
+
);
|
|
7918
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7757
7919
|
assert(
|
|
7758
7920
|
value >= RANGE_CONTRACT_ADDRESS.min && value <= RANGE_CONTRACT_ADDRESS.max,
|
|
7759
7921
|
`Value is out of ContractAddress range [${RANGE_CONTRACT_ADDRESS.min}, ${RANGE_CONTRACT_ADDRESS.max}]`
|
|
@@ -7838,7 +8000,7 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7838
8000
|
/**
|
|
7839
8001
|
* Build from a number or a numeric string, refusing text and anything wider than 160 bits.
|
|
7840
8002
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^160 - 1]
|
|
7841
|
-
* @throws {Error} when the value is text,
|
|
8003
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
7842
8004
|
* @example
|
|
7843
8005
|
* ```typescript
|
|
7844
8006
|
* const result = new CairoEthAddress('0x1234').toApiRequest();
|
|
@@ -7894,10 +8056,12 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7894
8056
|
* Throw unless the value can be carried by an EthAddress.
|
|
7895
8057
|
*
|
|
7896
8058
|
* Text is refused first, since an address spelled as words is a mistake rather than a value to
|
|
7897
|
-
* encode
|
|
7898
|
-
*
|
|
8059
|
+
* encode, then a number with a decimal part. A number or a bigint is read as it is, so that a
|
|
8060
|
+
* negative one reaches the range check below. Anything else is read as a felt252 — which is what
|
|
8061
|
+
* refuses a null, an object or an unsupported type. The value is finally checked against the 160
|
|
8062
|
+
* bits an Ethereum address occupies.
|
|
7899
8063
|
* @param {BigNumberish | boolean} data the value to check
|
|
7900
|
-
* @throws {Error} when the value is text,
|
|
8064
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
7901
8065
|
* @example
|
|
7902
8066
|
* ```typescript
|
|
7903
8067
|
* CairoEthAddress.validate('0x1234'); // passes
|
|
@@ -7905,11 +8069,17 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7905
8069
|
* // throws Error("Invalid input: an EthAddress cannot be built from text")
|
|
7906
8070
|
* CairoEthAddress.validate(2n ** 160n);
|
|
7907
8071
|
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
8072
|
+
* CairoEthAddress.validate(-1);
|
|
8073
|
+
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
7908
8074
|
* ```
|
|
7909
8075
|
*/
|
|
7910
8076
|
static validate(data) {
|
|
7911
8077
|
assert(!isText(data), "Invalid input: an EthAddress cannot be built from text");
|
|
7912
|
-
|
|
8078
|
+
assert(
|
|
8079
|
+
!isNumber(data) || Number.isInteger(data),
|
|
8080
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
8081
|
+
);
|
|
8082
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7913
8083
|
assert(
|
|
7914
8084
|
value >= RANGE_ETH_ADDRESS.min && value <= RANGE_ETH_ADDRESS.max,
|
|
7915
8085
|
`Value is out of EthAddress range [${RANGE_ETH_ADDRESS.min}, ${RANGE_ETH_ADDRESS.max}]`
|
|
@@ -8584,7 +8754,13 @@ var CairoTypeOption = class _CairoTypeOption {
|
|
|
8584
8754
|
* Build an option, from a value a caller passed or from the felts of a response.
|
|
8585
8755
|
*
|
|
8586
8756
|
* A {@link CairoOption} says its own branch, so `variant` is not given with one — nor with the
|
|
8587
|
-
* response iterator, which reads the branch off the wire
|
|
8757
|
+
* response iterator, which reads the branch off the wire, nor with a `CairoTypeOption`, which
|
|
8758
|
+
* is copied as it is. Anywhere else it is required.
|
|
8759
|
+
*
|
|
8760
|
+
* For the same reason, a `CairoOption` that holds a `CairoTypeOption` is refused: once it is
|
|
8761
|
+
* unwrapped, the variant comes with the `CairoTypeOption`. Accepted, it would lose one level:
|
|
8762
|
+
* `Some(Some(1))` would be sent as `Some(None)`. Write a nested value with `CairoOption`
|
|
8763
|
+
* only, or build one `CairoTypeOption` for the whole type.
|
|
8588
8764
|
*
|
|
8589
8765
|
* `subType` is what makes an option of options work. Handed a `CairoOption`, this constructor
|
|
8590
8766
|
* unwraps it and calls itself with what was inside, which for a nested option is another
|
|
@@ -8595,11 +8771,11 @@ var CairoTypeOption = class _CairoTypeOption {
|
|
|
8595
8771
|
* @param {string} optionCairoType the abi type, `core::option::Option::<T>`
|
|
8596
8772
|
* @param {AllowArray<CairoTypeStrategy>} parsingStrategy how to build the value
|
|
8597
8773
|
* @param {CairoOptionVariant | number} [variant] which branch, when the content does not say.
|
|
8598
|
-
* Must be omitted when `content` is the response iterator
|
|
8774
|
+
* Must be omitted when `content` is the response iterator or a `CairoTypeOption`.
|
|
8599
8775
|
* @param {boolean} [subType=false] true when called from the unwrapping of a nested
|
|
8600
8776
|
* `CairoOption`, which is the only caller that should set it
|
|
8601
|
-
* @throws {Error} when the type is not an option, when the variant is missing, absurd,
|
|
8602
|
-
* contradicts the content
|
|
8777
|
+
* @throws {Error} when the type is not an option, or when the variant is missing, absurd,
|
|
8778
|
+
* contradicts the content, or is given with a `CairoTypeOption`
|
|
8603
8779
|
* @example
|
|
8604
8780
|
* ```typescript
|
|
8605
8781
|
* const type = 'core::option::Option::<core::integer::u8>';
|
|
@@ -8644,6 +8820,10 @@ var CairoTypeOption = class _CairoTypeOption {
|
|
|
8644
8820
|
return;
|
|
8645
8821
|
}
|
|
8646
8822
|
if (content instanceof _CairoTypeOption) {
|
|
8823
|
+
assert(
|
|
8824
|
+
isUndefined(variant),
|
|
8825
|
+
'when "content" parameter is a CairoTypeOption, do not define "variant" parameter.'
|
|
8826
|
+
);
|
|
8647
8827
|
this.content = content.content;
|
|
8648
8828
|
this.isVariantSome = content.isVariantSome;
|
|
8649
8829
|
this.optionCairoType = content.optionCairoType;
|
|
@@ -11105,11 +11285,17 @@ function errorU512(key) {
|
|
|
11105
11285
|
`Your object includes the property : ${key}, containing an Uint512 object without the 'limb0' to 'limb3' keys.`
|
|
11106
11286
|
);
|
|
11107
11287
|
}
|
|
11288
|
+
function getVariantType(abiEnum, variantName) {
|
|
11289
|
+
return abiEnum.variants?.find((abiVariant) => abiVariant.name === variantName)?.type ?? "";
|
|
11290
|
+
}
|
|
11108
11291
|
function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
11109
11292
|
const orderInput = (unorderedItem, abiType) => {
|
|
11110
11293
|
if (CairoFixedArray.isTypeFixedArray(abiType)) {
|
|
11111
11294
|
return orderFixedArray(unorderedItem, abiType);
|
|
11112
11295
|
}
|
|
11296
|
+
if (isCairoType(unorderedItem)) {
|
|
11297
|
+
return unorderedItem;
|
|
11298
|
+
}
|
|
11113
11299
|
if (isTypeArray(abiType)) {
|
|
11114
11300
|
return orderArray(unorderedItem, abiType);
|
|
11115
11301
|
}
|
|
@@ -11222,14 +11408,8 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11222
11408
|
const orderEnum = (unorderedObject2, abiObject) => {
|
|
11223
11409
|
if (isTypeResult(abiObject.name)) {
|
|
11224
11410
|
const unorderedResult = unorderedObject2;
|
|
11225
|
-
const resultOkType = abiObject
|
|
11226
|
-
|
|
11227
|
-
abiObject.name.lastIndexOf(",")
|
|
11228
|
-
);
|
|
11229
|
-
const resultErrType = abiObject.name.substring(
|
|
11230
|
-
abiObject.name.indexOf(",") + 1,
|
|
11231
|
-
abiObject.name.lastIndexOf(">")
|
|
11232
|
-
);
|
|
11411
|
+
const resultOkType = getVariantType(abiObject, "Ok");
|
|
11412
|
+
const resultErrType = getVariantType(abiObject, "Err");
|
|
11233
11413
|
if (unorderedResult.isOk()) {
|
|
11234
11414
|
return new CairoResult(
|
|
11235
11415
|
CairoResultVariant.Ok,
|
|
@@ -11243,10 +11423,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11243
11423
|
}
|
|
11244
11424
|
if (isTypeOption(abiObject.name)) {
|
|
11245
11425
|
const unorderedOption = unorderedObject2;
|
|
11246
|
-
const resultSomeType = abiObject
|
|
11247
|
-
abiObject.name.indexOf("<") + 1,
|
|
11248
|
-
abiObject.name.lastIndexOf(">")
|
|
11249
|
-
);
|
|
11426
|
+
const resultSomeType = getVariantType(abiObject, "Some");
|
|
11250
11427
|
if (unorderedOption.isSome()) {
|
|
11251
11428
|
return new CairoOption(
|
|
11252
11429
|
CairoOptionVariant.Some,
|
|
@@ -11261,10 +11438,7 @@ function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
|
11261
11438
|
if (isUndefined(variant[1])) {
|
|
11262
11439
|
return variant;
|
|
11263
11440
|
}
|
|
11264
|
-
const variantType = abiObject
|
|
11265
|
-
abiObject.type.lastIndexOf("<") + 1,
|
|
11266
|
-
abiObject.type.lastIndexOf(">")
|
|
11267
|
-
);
|
|
11441
|
+
const variantType = getVariantType(abiObject, variant[0]);
|
|
11268
11442
|
if (variantType === "()") {
|
|
11269
11443
|
return variant;
|
|
11270
11444
|
}
|
|
@@ -13626,7 +13800,7 @@ function ethRandomPrivateKey() {
|
|
|
13626
13800
|
return sanitizeHex(buf2hex(import_secp256k1.secp256k1.utils.randomSecretKey()));
|
|
13627
13801
|
}
|
|
13628
13802
|
function validateAndParseEthAddress(address) {
|
|
13629
|
-
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address
|
|
13803
|
+
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address");
|
|
13630
13804
|
const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
|
|
13631
13805
|
assert(Boolean(result.match(/^(0x)?[0-9a-f]{40}$/)), "Invalid Ethereum Address Format");
|
|
13632
13806
|
return result;
|
|
@@ -17780,6 +17954,9 @@ function addAddressPadding(address) {
|
|
|
17780
17954
|
return addHexPrefix(padded);
|
|
17781
17955
|
}
|
|
17782
17956
|
function validateAndParseAddress(address) {
|
|
17957
|
+
if (isString(address) && !/^(0x)?[0-9a-f]+$/i.test(address)) {
|
|
17958
|
+
throw new Error("Invalid Address Format");
|
|
17959
|
+
}
|
|
17783
17960
|
const result = addAddressPadding(address);
|
|
17784
17961
|
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
17785
17962
|
throw new Error("Invalid Address Format");
|