starknet 11.0.0 → 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 +12 -0
- package/dist/index.d.ts +344 -115
- package/dist/index.global.js +304 -115
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +304 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +304 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -7
package/dist/index.mjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(constants_exports, {
|
|
|
39
39
|
OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
|
|
40
40
|
PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
|
|
41
41
|
PRIME: () => PRIME,
|
|
42
|
+
RANGE_CLASS_HASH: () => RANGE_CLASS_HASH,
|
|
42
43
|
RANGE_CONTRACT_ADDRESS: () => RANGE_CONTRACT_ADDRESS,
|
|
43
44
|
RANGE_ETH_ADDRESS: () => RANGE_ETH_ADDRESS,
|
|
44
45
|
RANGE_FELT: () => RANGE_FELT,
|
|
@@ -278,6 +279,7 @@ var RANGE_I64 = range(-(2n ** 63n), 2n ** 63n - 1n);
|
|
|
278
279
|
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
279
280
|
var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
|
|
280
281
|
var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
|
|
282
|
+
var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
|
|
281
283
|
var LegacyUDC = {
|
|
282
284
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
283
285
|
ENTRYPOINT: "deployContract"
|
|
@@ -755,6 +757,7 @@ __export(num_exports, {
|
|
|
755
757
|
hexToBytes: () => hexToBytes,
|
|
756
758
|
hexToDecimalString: () => hexToDecimalString,
|
|
757
759
|
isBigNumberish: () => isBigNumberish,
|
|
760
|
+
isEmptyHex: () => isEmptyHex,
|
|
758
761
|
isHex: () => isHex,
|
|
759
762
|
isHexString: () => isHexString2,
|
|
760
763
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
@@ -810,6 +813,7 @@ function isHex(hex) {
|
|
|
810
813
|
}
|
|
811
814
|
var isHexString2 = isHex;
|
|
812
815
|
function toBigInt(value) {
|
|
816
|
+
assert(!isEmptyHex(value), "Invalid input: '0x' holds no hexadecimal digit");
|
|
813
817
|
return BigInt(value);
|
|
814
818
|
}
|
|
815
819
|
function tryToBigInt(value) {
|
|
@@ -834,13 +838,13 @@ function hexToDecimalString(hex) {
|
|
|
834
838
|
return BigInt(addHexPrefix(hex)).toString(10);
|
|
835
839
|
}
|
|
836
840
|
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
837
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
838
841
|
const inputBigInt = BigInt(input);
|
|
839
842
|
const lowerBoundBigInt = BigInt(lowerBound);
|
|
840
843
|
const upperBoundBigInt = BigInt(upperBound);
|
|
844
|
+
const rangeName = inputName === "" ? "range" : `${inputName} range`;
|
|
841
845
|
assert(
|
|
842
846
|
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
843
|
-
`
|
|
847
|
+
`Value is out of ${rangeName} [${lowerBoundBigInt}, ${upperBoundBigInt}]`
|
|
844
848
|
);
|
|
845
849
|
}
|
|
846
850
|
function bigNumberishArrayToDecimalStringArray(data) {
|
|
@@ -893,8 +897,11 @@ function stringToSha256ToArrayBuff4(str) {
|
|
|
893
897
|
const result = int31(BigInt(addHexPrefix(buf2hex(sha256(utf8ToBytes(str))))));
|
|
894
898
|
return hexToBytes(toHex(result));
|
|
895
899
|
}
|
|
900
|
+
function isEmptyHex(value) {
|
|
901
|
+
return isString(value) && /^0x$/i.test(value);
|
|
902
|
+
}
|
|
896
903
|
function isBigNumberish(input) {
|
|
897
|
-
return isNumber(input) || isBigInt(input) || isString(input) && (isHex(input) || isStringWholeNumber(input));
|
|
904
|
+
return isNumber(input) || isBigInt(input) || isString(input) && (isHex(input) && !isEmptyHex(input) || isStringWholeNumber(input));
|
|
898
905
|
}
|
|
899
906
|
function getNext(iterator) {
|
|
900
907
|
const it = iterator.next();
|
|
@@ -1478,16 +1485,18 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1478
1485
|
/**
|
|
1479
1486
|
* Throw unless the value can be carried by a felt252.
|
|
1480
1487
|
*
|
|
1481
|
-
* Null, undefined
|
|
1482
|
-
* message, then the value is converted and its range checked. A negative number does not
|
|
1483
|
-
* that range check : converting it fails earlier, and the message comes from the conversion.
|
|
1488
|
+
* Null, undefined, any type this class does not read, and `'0x'` are refused first, each with its
|
|
1489
|
+
* own message, then the value is converted and its range checked. A negative number does not
|
|
1490
|
+
* reach that range check : converting it fails earlier, and the message comes from the conversion.
|
|
1484
1491
|
* @param {BigNumberish | boolean} data the value to check
|
|
1485
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, P)
|
|
1492
|
+
* @throws {Error} when the value is null, undefined, of an unread type, `'0x'`, or outside [0, P)
|
|
1486
1493
|
* @example
|
|
1487
1494
|
* ```typescript
|
|
1488
1495
|
* CairoFelt252.validate('Hello'); // passes
|
|
1489
1496
|
* CairoFelt252.validate({});
|
|
1490
1497
|
* // throws Error("Unsupported data type 'object' for felt252. Expected string, number, bigint, or boolean")
|
|
1498
|
+
* CairoFelt252.validate('0x');
|
|
1499
|
+
* // throws Error("Invalid input: '0x' holds no hexadecimal digit")
|
|
1491
1500
|
* CairoFelt252.validate(-1);
|
|
1492
1501
|
* // throws Error("Cannot convert negative bigint -1 to Uint8Array")
|
|
1493
1502
|
* ```
|
|
@@ -1499,6 +1508,7 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1499
1508
|
isString(data) || isNumber(data) || isBigInt(data) || isBoolean(data),
|
|
1500
1509
|
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
1501
1510
|
);
|
|
1511
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
1502
1512
|
const value = _CairoFelt252.__processData(data);
|
|
1503
1513
|
const bn = uint8ArrayToBigInt(value);
|
|
1504
1514
|
_CairoFelt252.assertRange(bn);
|
|
@@ -2315,7 +2325,7 @@ var CairoUint32 = class _CairoUint32 {
|
|
|
2315
2325
|
* otherwise. Text therefore only fits here up to 4 ASCII characters : one more already
|
|
2316
2326
|
* makes a number past 4294967295.
|
|
2317
2327
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 4294967295]
|
|
2318
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
2328
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
2319
2329
|
* @example
|
|
2320
2330
|
* ```typescript
|
|
2321
2331
|
* const result = new CairoUint32('abcd').toApiRequest();
|
|
@@ -2403,11 +2413,11 @@ var CairoUint32 = class _CairoUint32 {
|
|
|
2403
2413
|
/**
|
|
2404
2414
|
* Throw unless the value can be carried by a u32.
|
|
2405
2415
|
*
|
|
2406
|
-
*
|
|
2407
|
-
* an array, a number with a decimal part, and a value outside [0, 4294967295]. A text string reaches
|
|
2416
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
2417
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 4294967295]. A text string reaches
|
|
2408
2418
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
2409
2419
|
* @param {BigNumberish | boolean} data the value to check
|
|
2410
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
2420
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
2411
2421
|
* @example
|
|
2412
2422
|
* ```typescript
|
|
2413
2423
|
* CairoUint32.validate(70000); // passes
|
|
@@ -2422,6 +2432,7 @@ var CairoUint32 = class _CairoUint32 {
|
|
|
2422
2432
|
!isNumber(data) || Number.isInteger(data),
|
|
2423
2433
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
2424
2434
|
);
|
|
2435
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
2425
2436
|
const value = _CairoUint32.__processData(data);
|
|
2426
2437
|
assert(
|
|
2427
2438
|
value >= RANGE_U32.min && value <= RANGE_U32.max,
|
|
@@ -3053,25 +3064,37 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3053
3064
|
* Throw unless a whole value can be represented as a u256, and give back its number.
|
|
3054
3065
|
*
|
|
3055
3066
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
3056
|
-
* refused
|
|
3067
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint256`
|
|
3068
|
+
* one included : its two halves are checked by {@link CairoUint256.validateProps}, which is what
|
|
3069
|
+
* the constructor calls for it.
|
|
3057
3070
|
* @param {BigNumberish} bigNumberish the value to check
|
|
3058
3071
|
* @returns {bigint} the value as a number, once accepted
|
|
3059
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or out of range
|
|
3072
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
3060
3073
|
* @example
|
|
3061
3074
|
* ```typescript
|
|
3062
3075
|
* const result = CairoUint256.validate(255);
|
|
3063
3076
|
* // result = 255n
|
|
3064
3077
|
* CairoUint256.validate(-1);
|
|
3065
3078
|
* // throws Error("bigNumberish is smaller than UINT_256_MIN")
|
|
3079
|
+
* CairoUint256.validate('abc');
|
|
3080
|
+
* // throws Error("Invalid input: a u256 cannot be built from text")
|
|
3081
|
+
* CairoUint256.validate(1.5);
|
|
3082
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
3066
3083
|
* ```
|
|
3067
3084
|
*/
|
|
3068
3085
|
static validate(bigNumberish) {
|
|
3069
3086
|
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
3070
3087
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
3088
|
+
assert(!isText(bigNumberish), "Invalid input: a u256 cannot be built from text");
|
|
3089
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3071
3090
|
assert(
|
|
3072
|
-
isBigNumberish(bigNumberish)
|
|
3091
|
+
isBigNumberish(bigNumberish),
|
|
3073
3092
|
`Unsupported data type '${typeof bigNumberish}' for u256. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint256 object`
|
|
3074
3093
|
);
|
|
3094
|
+
assert(
|
|
3095
|
+
!isNumber(bigNumberish) || Number.isInteger(bigNumberish),
|
|
3096
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
3097
|
+
);
|
|
3075
3098
|
const bigInt = BigInt(bigNumberish);
|
|
3076
3099
|
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
3077
3100
|
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
@@ -3085,18 +3108,31 @@ var CairoUint256 = class _CairoUint256 {
|
|
|
3085
3108
|
* @param {BigNumberish} low the bottom 128 bits
|
|
3086
3109
|
* @param {BigNumberish} high the top 128 bits
|
|
3087
3110
|
* @returns {{low: bigint, high: bigint}} the two halves as numbers
|
|
3088
|
-
* @throws {Error} when either half is outside the u128 range
|
|
3111
|
+
* @throws {Error} when either half is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
3089
3112
|
* @example
|
|
3090
3113
|
* ```typescript
|
|
3091
3114
|
* const result = CairoUint256.validateProps(5, 4);
|
|
3092
3115
|
* // result = { low: 5n, high: 4n }
|
|
3093
3116
|
* CairoUint256.validateProps(-1, 4);
|
|
3094
3117
|
* // throws Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX")
|
|
3118
|
+
* CairoUint256.validateProps(1.5, 4);
|
|
3119
|
+
* // throws Error("low must be an integer")
|
|
3120
|
+
* CairoUint256.validateProps('abc', 4);
|
|
3121
|
+
* // throws Error("low cannot be built from text")
|
|
3095
3122
|
* ```
|
|
3096
3123
|
*/
|
|
3097
3124
|
static validateProps(low, high) {
|
|
3098
|
-
const
|
|
3099
|
-
|
|
3125
|
+
const validateHalf = (half, name) => {
|
|
3126
|
+
assert(half !== null, `${name} cannot be null`);
|
|
3127
|
+
assert(half !== void 0, `${name} cannot be undefined`);
|
|
3128
|
+
assert(!isText(half), `${name} cannot be built from text`);
|
|
3129
|
+
assert(!isEmptyHex(half), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
3130
|
+
assert(isBigNumberish(half), `${name} must be a BigNumberish`);
|
|
3131
|
+
assert(!isNumber(half) || Number.isInteger(half), `${name} must be an integer`);
|
|
3132
|
+
return BigInt(half);
|
|
3133
|
+
};
|
|
3134
|
+
const bigIntLow = validateHalf(low, "low");
|
|
3135
|
+
const bigIntHigh = validateHalf(high, "high");
|
|
3100
3136
|
assert(
|
|
3101
3137
|
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
3102
3138
|
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
@@ -3305,25 +3341,37 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3305
3341
|
* Throw unless a whole value can be represented as a u512, and give back its number.
|
|
3306
3342
|
*
|
|
3307
3343
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
3308
|
-
* refused
|
|
3344
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint512`
|
|
3345
|
+
* one included : its four limbs are checked by {@link CairoUint512.validateProps}, which is what
|
|
3346
|
+
* the constructor calls for it.
|
|
3309
3347
|
* @param {BigNumberish} bigNumberish the value to check
|
|
3310
3348
|
* @returns {bigint} the value as a number, once accepted
|
|
3311
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or out of range
|
|
3349
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
3312
3350
|
* @example
|
|
3313
3351
|
* ```typescript
|
|
3314
3352
|
* const result = CairoUint512.validate(255);
|
|
3315
3353
|
* // result = 255n
|
|
3316
3354
|
* CairoUint512.validate(-1);
|
|
3317
3355
|
* // throws Error("bigNumberish is smaller than UINT_512_MIN.")
|
|
3356
|
+
* CairoUint512.validate('abc');
|
|
3357
|
+
* // throws Error("Invalid input: a u512 cannot be built from text")
|
|
3358
|
+
* CairoUint512.validate(1.5);
|
|
3359
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
3318
3360
|
* ```
|
|
3319
3361
|
*/
|
|
3320
3362
|
static validate(bigNumberish) {
|
|
3321
3363
|
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
3322
3364
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
3365
|
+
assert(!isText(bigNumberish), "Invalid input: a u512 cannot be built from text");
|
|
3366
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3323
3367
|
assert(
|
|
3324
|
-
isBigNumberish(bigNumberish)
|
|
3368
|
+
isBigNumberish(bigNumberish),
|
|
3325
3369
|
`Unsupported data type '${typeof bigNumberish}' for u512. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint512 object`
|
|
3326
3370
|
);
|
|
3371
|
+
assert(
|
|
3372
|
+
!isNumber(bigNumberish) || Number.isInteger(bigNumberish),
|
|
3373
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
3374
|
+
);
|
|
3327
3375
|
const bigInt = BigInt(bigNumberish);
|
|
3328
3376
|
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
3329
3377
|
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
@@ -3339,20 +3387,33 @@ var CairoUint512 = class _CairoUint512 {
|
|
|
3339
3387
|
* @param {BigNumberish} limb2 bits 256 to 383
|
|
3340
3388
|
* @param {BigNumberish} limb3 bits 384 to 511
|
|
3341
3389
|
* @returns {{limb0: bigint, limb1: bigint, limb2: bigint, limb3: bigint}} the four limbs as numbers
|
|
3342
|
-
* @throws {Error} when any limb is outside the u128 range
|
|
3390
|
+
* @throws {Error} when any limb is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
3343
3391
|
* @example
|
|
3344
3392
|
* ```typescript
|
|
3345
3393
|
* const result = CairoUint512.validateProps(7, 0, 0, 64);
|
|
3346
3394
|
* // result = { limb0: 7n, limb1: 0n, limb2: 0n, limb3: 64n }
|
|
3347
3395
|
* CairoUint512.validateProps(-1, 0, 0, 0);
|
|
3348
3396
|
* // throws Error("limb0 is not in the range of a u128 number")
|
|
3397
|
+
* CairoUint512.validateProps(1.5, 0, 0, 0);
|
|
3398
|
+
* // throws Error("limb0 must be an integer")
|
|
3399
|
+
* CairoUint512.validateProps('abc', 0, 0, 0);
|
|
3400
|
+
* // throws Error("limb0 cannot be built from text")
|
|
3349
3401
|
* ```
|
|
3350
3402
|
*/
|
|
3351
3403
|
static validateProps(limb0, limb1, limb2, limb3) {
|
|
3352
|
-
const
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3404
|
+
const validateLimb = (limb, name) => {
|
|
3405
|
+
assert(limb !== null, `${name} cannot be null`);
|
|
3406
|
+
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
3407
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
3408
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
3409
|
+
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
3410
|
+
assert(!isNumber(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
3411
|
+
return BigInt(limb);
|
|
3412
|
+
};
|
|
3413
|
+
const l0 = validateLimb(limb0, "limb0");
|
|
3414
|
+
const l1 = validateLimb(limb1, "limb1");
|
|
3415
|
+
const l2 = validateLimb(limb2, "limb2");
|
|
3416
|
+
const l3 = validateLimb(limb3, "limb3");
|
|
3356
3417
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
3357
3418
|
assert(
|
|
3358
3419
|
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
@@ -3524,7 +3585,7 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3524
3585
|
* otherwise. Text therefore only fits here up to 12 ASCII characters : one more already
|
|
3525
3586
|
* makes a number past 79228162514264337593543950335.
|
|
3526
3587
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 79228162514264337593543950335]
|
|
3527
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
3588
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
3528
3589
|
* @example
|
|
3529
3590
|
* ```typescript
|
|
3530
3591
|
* const result = new CairoUint96('abcdefghijkl').toApiRequest();
|
|
@@ -3612,11 +3673,11 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3612
3673
|
/**
|
|
3613
3674
|
* Throw unless the value can be carried by a u96.
|
|
3614
3675
|
*
|
|
3615
|
-
*
|
|
3616
|
-
* an array, a number with a decimal part, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
3676
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
3677
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
3617
3678
|
* that last check as the number its bytes spell, so `'abcdefghijklm'` is refused for being out of range.
|
|
3618
3679
|
* @param {BigNumberish | boolean} data the value to check
|
|
3619
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
3680
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
3620
3681
|
* @example
|
|
3621
3682
|
* ```typescript
|
|
3622
3683
|
* CairoUint96.validate(5000000000); // passes
|
|
@@ -3631,6 +3692,7 @@ var CairoUint96 = class _CairoUint96 {
|
|
|
3631
3692
|
!isNumber(data) || Number.isInteger(data),
|
|
3632
3693
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
3633
3694
|
);
|
|
3695
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3634
3696
|
const value = _CairoUint96.__processData(data);
|
|
3635
3697
|
assert(
|
|
3636
3698
|
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
@@ -4017,7 +4079,7 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4017
4079
|
* otherwise. Text therefore only fits here while it is a single ASCII character : two characters
|
|
4018
4080
|
* already make a number past 255.
|
|
4019
4081
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 255]
|
|
4020
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4082
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4021
4083
|
* @example
|
|
4022
4084
|
* ```typescript
|
|
4023
4085
|
* const result = new CairoUint8('a').toApiRequest();
|
|
@@ -4107,11 +4169,11 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4107
4169
|
/**
|
|
4108
4170
|
* Throw unless the value can be carried by a u8.
|
|
4109
4171
|
*
|
|
4110
|
-
*
|
|
4111
|
-
* an array, a number with a decimal part, and a value outside [0, 255]. A text string reaches
|
|
4172
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4173
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 255]. A text string reaches
|
|
4112
4174
|
* that last check as the number its bytes spell, so `'ab'` is refused for being out of range.
|
|
4113
4175
|
* @param {BigNumberish | boolean} data the value to check
|
|
4114
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4176
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4115
4177
|
* @example
|
|
4116
4178
|
* ```typescript
|
|
4117
4179
|
* CairoUint8.validate(44); // passes
|
|
@@ -4126,6 +4188,7 @@ var CairoUint8 = class _CairoUint8 {
|
|
|
4126
4188
|
!isNumber(data) || Number.isInteger(data),
|
|
4127
4189
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4128
4190
|
);
|
|
4191
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4129
4192
|
const value = _CairoUint8.__processData(data);
|
|
4130
4193
|
assert(
|
|
4131
4194
|
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
@@ -4216,7 +4279,7 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4216
4279
|
* otherwise. Text therefore only fits here up to 2 ASCII characters : one more already
|
|
4217
4280
|
* makes a number past 65535.
|
|
4218
4281
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 65535]
|
|
4219
|
-
* @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
|
|
4220
4283
|
* @example
|
|
4221
4284
|
* ```typescript
|
|
4222
4285
|
* const result = new CairoUint16('ab').toApiRequest();
|
|
@@ -4304,11 +4367,11 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4304
4367
|
/**
|
|
4305
4368
|
* Throw unless the value can be carried by a u16.
|
|
4306
4369
|
*
|
|
4307
|
-
*
|
|
4308
|
-
* an array, a number with a decimal part, and a value outside [0, 65535]. A text string reaches
|
|
4370
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4371
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 65535]. A text string reaches
|
|
4309
4372
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
4310
4373
|
* @param {BigNumberish | boolean} data the value to check
|
|
4311
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4374
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4312
4375
|
* @example
|
|
4313
4376
|
* ```typescript
|
|
4314
4377
|
* CairoUint16.validate(300); // passes
|
|
@@ -4323,6 +4386,7 @@ var CairoUint16 = class _CairoUint16 {
|
|
|
4323
4386
|
!isNumber(data) || Number.isInteger(data),
|
|
4324
4387
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4325
4388
|
);
|
|
4389
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4326
4390
|
const value = _CairoUint16.__processData(data);
|
|
4327
4391
|
assert(
|
|
4328
4392
|
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
@@ -4413,7 +4477,7 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4413
4477
|
* otherwise. Text therefore only fits here up to 8 ASCII characters : one more already
|
|
4414
4478
|
* makes a number past 18446744073709551615.
|
|
4415
4479
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 18446744073709551615]
|
|
4416
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4480
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4417
4481
|
* @example
|
|
4418
4482
|
* ```typescript
|
|
4419
4483
|
* const result = new CairoUint64('abcdefgh').toApiRequest();
|
|
@@ -4501,11 +4565,11 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4501
4565
|
/**
|
|
4502
4566
|
* Throw unless the value can be carried by a u64.
|
|
4503
4567
|
*
|
|
4504
|
-
*
|
|
4505
|
-
* an array, a number with a decimal part, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
4568
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4569
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
4506
4570
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
4507
4571
|
* @param {BigNumberish | boolean} data the value to check
|
|
4508
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4572
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4509
4573
|
* @example
|
|
4510
4574
|
* ```typescript
|
|
4511
4575
|
* CairoUint64.validate(5000000000); // passes
|
|
@@ -4520,6 +4584,7 @@ var CairoUint64 = class _CairoUint64 {
|
|
|
4520
4584
|
!isNumber(data) || Number.isInteger(data),
|
|
4521
4585
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4522
4586
|
);
|
|
4587
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4523
4588
|
const value = _CairoUint64.__processData(data);
|
|
4524
4589
|
assert(
|
|
4525
4590
|
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
@@ -4610,7 +4675,7 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4610
4675
|
* otherwise. Text therefore only fits here up to 16 ASCII characters : one more already
|
|
4611
4676
|
* makes a number past 340282366920938463463374607431768211455.
|
|
4612
4677
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 340282366920938463463374607431768211455]
|
|
4613
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4678
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4614
4679
|
* @example
|
|
4615
4680
|
* ```typescript
|
|
4616
4681
|
* const result = new CairoUint128('abcdefghijklmnop').toApiRequest();
|
|
@@ -4698,11 +4763,11 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4698
4763
|
/**
|
|
4699
4764
|
* Throw unless the value can be carried by a u128.
|
|
4700
4765
|
*
|
|
4701
|
-
*
|
|
4702
|
-
* an array, a number with a decimal part, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
4766
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4767
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
4703
4768
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
4704
4769
|
* @param {BigNumberish | boolean} data the value to check
|
|
4705
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4770
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4706
4771
|
* @example
|
|
4707
4772
|
* ```typescript
|
|
4708
4773
|
* CairoUint128.validate(5000000000); // passes
|
|
@@ -4717,6 +4782,7 @@ var CairoUint128 = class _CairoUint128 {
|
|
|
4717
4782
|
!isNumber(data) || Number.isInteger(data),
|
|
4718
4783
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4719
4784
|
);
|
|
4785
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4720
4786
|
const value = _CairoUint128.__processData(data);
|
|
4721
4787
|
assert(
|
|
4722
4788
|
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
@@ -4803,15 +4869,17 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
4803
4869
|
/**
|
|
4804
4870
|
* Build from a number, a string or a boolean, refusing anything out of the i8 range.
|
|
4805
4871
|
*
|
|
4806
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
4807
|
-
* otherwise. Text therefore only fits here up to a single
|
|
4808
|
-
* makes a number past 127.
|
|
4872
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
4873
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to a single
|
|
4874
|
+
* ASCII character : one more already makes a number past 127.
|
|
4809
4875
|
* @param {BigNumberish | boolean} data the value to carry, within [-128, 127]
|
|
4810
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4876
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4811
4877
|
* @example
|
|
4812
4878
|
* ```typescript
|
|
4813
4879
|
* const result = new CairoInt8('a').toApiRequest();
|
|
4814
4880
|
* // result = ["97"]
|
|
4881
|
+
* const result2 = new CairoInt8('-5').toApiRequest();
|
|
4882
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
4815
4883
|
* ```
|
|
4816
4884
|
*/
|
|
4817
4885
|
constructor(data) {
|
|
@@ -4823,6 +4891,9 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
4823
4891
|
*
|
|
4824
4892
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
4825
4893
|
* far outside the i8 range comes back untouched rather than raising.
|
|
4894
|
+
*
|
|
4895
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
4896
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
4826
4897
|
* @param {BigNumberish | boolean} data the value to convert
|
|
4827
4898
|
* @returns {bigint} the number the input spells, of whatever size
|
|
4828
4899
|
* @example
|
|
@@ -4831,9 +4902,14 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
4831
4902
|
* // result = 97n
|
|
4832
4903
|
* const result2 = CairoInt8.__processData('ab');
|
|
4833
4904
|
* // result2 = 24930n (past the i8 range, and returned all the same)
|
|
4905
|
+
* const result3 = CairoInt8.__processData('-0x5');
|
|
4906
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
4834
4907
|
* ```
|
|
4835
4908
|
*/
|
|
4836
4909
|
static __processData(data) {
|
|
4910
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
4911
|
+
return -BigInt(data.slice(1));
|
|
4912
|
+
}
|
|
4837
4913
|
if (isString(data) && isText(data)) {
|
|
4838
4914
|
return utf8ToBigInt(data);
|
|
4839
4915
|
}
|
|
@@ -4912,11 +4988,12 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
4912
4988
|
/**
|
|
4913
4989
|
* Throw unless the value can be carried by an i8.
|
|
4914
4990
|
*
|
|
4915
|
-
*
|
|
4916
|
-
* an array, a number with a decimal part, and a value outside [-128, 127]. A text string
|
|
4917
|
-
* that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
4991
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
4992
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-128, 127]. A text string
|
|
4993
|
+
* reaches that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
4994
|
+
* range.
|
|
4918
4995
|
* @param {BigNumberish | boolean} data the value to check
|
|
4919
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
4996
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
4920
4997
|
* @example
|
|
4921
4998
|
* ```typescript
|
|
4922
4999
|
* CairoInt8.validate(5); // passes
|
|
@@ -4931,6 +5008,7 @@ var CairoInt8 = class _CairoInt8 {
|
|
|
4931
5008
|
!isNumber(data) || Number.isInteger(data),
|
|
4932
5009
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
4933
5010
|
);
|
|
5011
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
4934
5012
|
const value = _CairoInt8.__processData(data);
|
|
4935
5013
|
assert(
|
|
4936
5014
|
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
@@ -5021,15 +5099,17 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5021
5099
|
/**
|
|
5022
5100
|
* Build from a number, a string or a boolean, refusing anything out of the i16 range.
|
|
5023
5101
|
*
|
|
5024
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5025
|
-
* otherwise. Text therefore only fits here up to 2 ASCII
|
|
5026
|
-
* makes a number past 32767.
|
|
5102
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5103
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 2 ASCII
|
|
5104
|
+
* characters : one more already makes a number past 32767.
|
|
5027
5105
|
* @param {BigNumberish | boolean} data the value to carry, within [-32768, 32767]
|
|
5028
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5106
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5029
5107
|
* @example
|
|
5030
5108
|
* ```typescript
|
|
5031
5109
|
* const result = new CairoInt16('ab').toApiRequest();
|
|
5032
5110
|
* // result = ["24930"]
|
|
5111
|
+
* const result2 = new CairoInt16('-5').toApiRequest();
|
|
5112
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5033
5113
|
* ```
|
|
5034
5114
|
*/
|
|
5035
5115
|
constructor(data) {
|
|
@@ -5041,6 +5121,9 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5041
5121
|
*
|
|
5042
5122
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5043
5123
|
* far outside the i16 range comes back untouched rather than raising.
|
|
5124
|
+
*
|
|
5125
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5126
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5044
5127
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5045
5128
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5046
5129
|
* @example
|
|
@@ -5049,9 +5132,14 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5049
5132
|
* // result = 24930n
|
|
5050
5133
|
* const result2 = CairoInt16.__processData('abc');
|
|
5051
5134
|
* // result2 = 6382179n (past the i16 range, and returned all the same)
|
|
5135
|
+
* const result3 = CairoInt16.__processData('-0x5');
|
|
5136
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5052
5137
|
* ```
|
|
5053
5138
|
*/
|
|
5054
5139
|
static __processData(data) {
|
|
5140
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5141
|
+
return -BigInt(data.slice(1));
|
|
5142
|
+
}
|
|
5055
5143
|
if (isString(data) && isText(data)) {
|
|
5056
5144
|
return utf8ToBigInt(data);
|
|
5057
5145
|
}
|
|
@@ -5130,11 +5218,11 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5130
5218
|
/**
|
|
5131
5219
|
* Throw unless the value can be carried by an i16.
|
|
5132
5220
|
*
|
|
5133
|
-
*
|
|
5134
|
-
* an array, a number with a decimal part, and a value outside [-32768, 32767]. A text string reaches
|
|
5221
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5222
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-32768, 32767]. A text string reaches
|
|
5135
5223
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
5136
5224
|
* @param {BigNumberish | boolean} data the value to check
|
|
5137
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5225
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5138
5226
|
* @example
|
|
5139
5227
|
* ```typescript
|
|
5140
5228
|
* CairoInt16.validate(300); // passes
|
|
@@ -5149,6 +5237,7 @@ var CairoInt16 = class _CairoInt16 {
|
|
|
5149
5237
|
!isNumber(data) || Number.isInteger(data),
|
|
5150
5238
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5151
5239
|
);
|
|
5240
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5152
5241
|
const value = _CairoInt16.__processData(data);
|
|
5153
5242
|
assert(
|
|
5154
5243
|
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
@@ -5239,15 +5328,17 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5239
5328
|
/**
|
|
5240
5329
|
* Build from a number, a string or a boolean, refusing anything out of the i32 range.
|
|
5241
5330
|
*
|
|
5242
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5243
|
-
* otherwise. Text therefore only fits here up to 4 ASCII
|
|
5244
|
-
* makes a number past 2147483647.
|
|
5331
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5332
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 4 ASCII
|
|
5333
|
+
* characters : one more already makes a number past 2147483647.
|
|
5245
5334
|
* @param {BigNumberish | boolean} data the value to carry, within [-2147483648, 2147483647]
|
|
5246
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5335
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5247
5336
|
* @example
|
|
5248
5337
|
* ```typescript
|
|
5249
5338
|
* const result = new CairoInt32('abcd').toApiRequest();
|
|
5250
5339
|
* // result = ["1633837924"]
|
|
5340
|
+
* const result2 = new CairoInt32('-5').toApiRequest();
|
|
5341
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5251
5342
|
* ```
|
|
5252
5343
|
*/
|
|
5253
5344
|
constructor(data) {
|
|
@@ -5259,6 +5350,9 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5259
5350
|
*
|
|
5260
5351
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5261
5352
|
* far outside the i32 range comes back untouched rather than raising.
|
|
5353
|
+
*
|
|
5354
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5355
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5262
5356
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5263
5357
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5264
5358
|
* @example
|
|
@@ -5267,9 +5361,14 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5267
5361
|
* // result = 1633837924n
|
|
5268
5362
|
* const result2 = CairoInt32.__processData('abcde');
|
|
5269
5363
|
* // result2 = 418262508645n (past the i32 range, and returned all the same)
|
|
5364
|
+
* const result3 = CairoInt32.__processData('-0x5');
|
|
5365
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5270
5366
|
* ```
|
|
5271
5367
|
*/
|
|
5272
5368
|
static __processData(data) {
|
|
5369
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5370
|
+
return -BigInt(data.slice(1));
|
|
5371
|
+
}
|
|
5273
5372
|
if (isString(data) && isText(data)) {
|
|
5274
5373
|
return utf8ToBigInt(data);
|
|
5275
5374
|
}
|
|
@@ -5348,11 +5447,11 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5348
5447
|
/**
|
|
5349
5448
|
* Throw unless the value can be carried by an i32.
|
|
5350
5449
|
*
|
|
5351
|
-
*
|
|
5352
|
-
* an array, a number with a decimal part, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
5450
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5451
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
5353
5452
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
5354
5453
|
* @param {BigNumberish | boolean} data the value to check
|
|
5355
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5454
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5356
5455
|
* @example
|
|
5357
5456
|
* ```typescript
|
|
5358
5457
|
* CairoInt32.validate(70000); // passes
|
|
@@ -5367,6 +5466,7 @@ var CairoInt32 = class _CairoInt32 {
|
|
|
5367
5466
|
!isNumber(data) || Number.isInteger(data),
|
|
5368
5467
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5369
5468
|
);
|
|
5469
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5370
5470
|
const value = _CairoInt32.__processData(data);
|
|
5371
5471
|
assert(
|
|
5372
5472
|
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
@@ -5457,15 +5557,17 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5457
5557
|
/**
|
|
5458
5558
|
* Build from a number, a string or a boolean, refusing anything out of the i64 range.
|
|
5459
5559
|
*
|
|
5460
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5461
|
-
* otherwise. Text therefore only fits here up to 8 ASCII
|
|
5462
|
-
* makes a number past 9223372036854775807.
|
|
5560
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5561
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 8 ASCII
|
|
5562
|
+
* characters : one more already makes a number past 9223372036854775807.
|
|
5463
5563
|
* @param {BigNumberish | boolean} data the value to carry, within [-9223372036854775808, 9223372036854775807]
|
|
5464
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5564
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5465
5565
|
* @example
|
|
5466
5566
|
* ```typescript
|
|
5467
5567
|
* const result = new CairoInt64('abcdefgh').toApiRequest();
|
|
5468
5568
|
* // result = ["7017280452245743464"]
|
|
5569
|
+
* const result2 = new CairoInt64('-5').toApiRequest();
|
|
5570
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5469
5571
|
* ```
|
|
5470
5572
|
*/
|
|
5471
5573
|
constructor(data) {
|
|
@@ -5477,6 +5579,9 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5477
5579
|
*
|
|
5478
5580
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5479
5581
|
* far outside the i64 range comes back untouched rather than raising.
|
|
5582
|
+
*
|
|
5583
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5584
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5480
5585
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5481
5586
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5482
5587
|
* @example
|
|
@@ -5485,9 +5590,14 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5485
5590
|
* // result = 7017280452245743464n
|
|
5486
5591
|
* const result2 = CairoInt64.__processData('abcdefghi');
|
|
5487
5592
|
* // result2 = 1796423795774910326889n (past the i64 range, and returned all the same)
|
|
5593
|
+
* const result3 = CairoInt64.__processData('-0x5');
|
|
5594
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5488
5595
|
* ```
|
|
5489
5596
|
*/
|
|
5490
5597
|
static __processData(data) {
|
|
5598
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5599
|
+
return -BigInt(data.slice(1));
|
|
5600
|
+
}
|
|
5491
5601
|
if (isString(data) && isText(data)) {
|
|
5492
5602
|
return utf8ToBigInt(data);
|
|
5493
5603
|
}
|
|
@@ -5566,11 +5676,11 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5566
5676
|
/**
|
|
5567
5677
|
* Throw unless the value can be carried by an i64.
|
|
5568
5678
|
*
|
|
5569
|
-
*
|
|
5570
|
-
* an array, a number with a decimal part, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
5679
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5680
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
5571
5681
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
5572
5682
|
* @param {BigNumberish | boolean} data the value to check
|
|
5573
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5683
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5574
5684
|
* @example
|
|
5575
5685
|
* ```typescript
|
|
5576
5686
|
* CairoInt64.validate(5000000000); // passes
|
|
@@ -5585,6 +5695,7 @@ var CairoInt64 = class _CairoInt64 {
|
|
|
5585
5695
|
!isNumber(data) || Number.isInteger(data),
|
|
5586
5696
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5587
5697
|
);
|
|
5698
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5588
5699
|
const value = _CairoInt64.__processData(data);
|
|
5589
5700
|
assert(
|
|
5590
5701
|
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
@@ -5675,15 +5786,17 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5675
5786
|
/**
|
|
5676
5787
|
* Build from a number, a string or a boolean, refusing anything out of the i128 range.
|
|
5677
5788
|
*
|
|
5678
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
5679
|
-
* otherwise. Text therefore only fits here up to 16 ASCII
|
|
5680
|
-
* makes a number past 170141183460469231731687303715884105727.
|
|
5789
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
5790
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 16 ASCII
|
|
5791
|
+
* characters : one more already makes a number past 170141183460469231731687303715884105727.
|
|
5681
5792
|
* @param {BigNumberish | boolean} data the value to carry, within [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]
|
|
5682
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5793
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5683
5794
|
* @example
|
|
5684
5795
|
* ```typescript
|
|
5685
5796
|
* const result = new CairoInt128('abcdefghijklmnop').toApiRequest();
|
|
5686
5797
|
* // result = ["129445976596022050476432668810952994672"]
|
|
5798
|
+
* const result2 = new CairoInt128('-5').toApiRequest();
|
|
5799
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
5687
5800
|
* ```
|
|
5688
5801
|
*/
|
|
5689
5802
|
constructor(data) {
|
|
@@ -5695,6 +5808,9 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5695
5808
|
*
|
|
5696
5809
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
5697
5810
|
* far outside the i128 range comes back untouched rather than raising.
|
|
5811
|
+
*
|
|
5812
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
5813
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
5698
5814
|
* @param {BigNumberish | boolean} data the value to convert
|
|
5699
5815
|
* @returns {bigint} the number the input spells, of whatever size
|
|
5700
5816
|
* @example
|
|
@@ -5703,9 +5819,14 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5703
5819
|
* // result = 129445976596022050476432668810952994672n
|
|
5704
5820
|
* const result2 = CairoInt128.__processData('abcdefghijklmnopq');
|
|
5705
5821
|
* // result2 = 33138170008581644921966763215603966636145n (past the i128 range, and returned all the same)
|
|
5822
|
+
* const result3 = CairoInt128.__processData('-0x5');
|
|
5823
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
5706
5824
|
* ```
|
|
5707
5825
|
*/
|
|
5708
5826
|
static __processData(data) {
|
|
5827
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
5828
|
+
return -BigInt(data.slice(1));
|
|
5829
|
+
}
|
|
5709
5830
|
if (isString(data) && isText(data)) {
|
|
5710
5831
|
return utf8ToBigInt(data);
|
|
5711
5832
|
}
|
|
@@ -5784,11 +5905,11 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5784
5905
|
/**
|
|
5785
5906
|
* Throw unless the value can be carried by an i128.
|
|
5786
5907
|
*
|
|
5787
|
-
*
|
|
5788
|
-
* an array, a number with a decimal part, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
5908
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
5909
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
5789
5910
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
5790
5911
|
* @param {BigNumberish | boolean} data the value to check
|
|
5791
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
5912
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
5792
5913
|
* @example
|
|
5793
5914
|
* ```typescript
|
|
5794
5915
|
* CairoInt128.validate(5000000000); // passes
|
|
@@ -5803,6 +5924,7 @@ var CairoInt128 = class _CairoInt128 {
|
|
|
5803
5924
|
!isNumber(data) || Number.isInteger(data),
|
|
5804
5925
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
5805
5926
|
);
|
|
5927
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
5806
5928
|
const value = _CairoInt128.__processData(data);
|
|
5807
5929
|
assert(
|
|
5808
5930
|
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
@@ -5893,7 +6015,7 @@ var CairoBool = class _CairoBool {
|
|
|
5893
6015
|
/**
|
|
5894
6016
|
* Build from a boolean, or from the numbers 0 and 1.
|
|
5895
6017
|
* @param {BigNumberish | boolean} data the value to carry : a boolean, 0 or 1
|
|
5896
|
-
* @throws {Error} when the value is text,
|
|
6018
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
5897
6019
|
* @example
|
|
5898
6020
|
* ```typescript
|
|
5899
6021
|
* const result = new CairoBool(false).toApiRequest();
|
|
@@ -5966,21 +6088,28 @@ var CairoBool = class _CairoBool {
|
|
|
5966
6088
|
/**
|
|
5967
6089
|
* Throw unless the value can be carried by a bool.
|
|
5968
6090
|
*
|
|
5969
|
-
* Text is refused first, then
|
|
5970
|
-
*
|
|
5971
|
-
*
|
|
6091
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
6092
|
+
* is, so that a negative one reaches the last check. Anything else is read as a felt252 — which
|
|
6093
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked to be
|
|
6094
|
+
* one of the only two numbers a bool can hold.
|
|
5972
6095
|
* @param {BigNumberish | boolean} data the value to check
|
|
5973
|
-
* @throws {Error} when the value is text,
|
|
6096
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
5974
6097
|
* @example
|
|
5975
6098
|
* ```typescript
|
|
5976
6099
|
* CairoBool.validate(true); // passes
|
|
5977
6100
|
* CairoBool.validate(2);
|
|
5978
6101
|
* // throws Error("Only values 0 or 1 are possible in a core::bool, received 2")
|
|
6102
|
+
* CairoBool.validate(-1);
|
|
6103
|
+
* // throws Error("Only values 0 or 1 are possible in a core::bool, received -1")
|
|
5979
6104
|
* ```
|
|
5980
6105
|
*/
|
|
5981
6106
|
static validate(data) {
|
|
5982
6107
|
assert(!isText(data), "Invalid input: a core::bool cannot be built from text");
|
|
5983
|
-
|
|
6108
|
+
assert(
|
|
6109
|
+
!isNumber(data) || Number.isInteger(data),
|
|
6110
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6111
|
+
);
|
|
6112
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
5984
6113
|
assert(
|
|
5985
6114
|
value === 0n || value === 1n,
|
|
5986
6115
|
`Only values 0 or 1 are possible in a core::bool, received ${value}`
|
|
@@ -6095,7 +6224,9 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6095
6224
|
/**
|
|
6096
6225
|
* @param {any[]} arr either one value — a 512-bit number or a {@link Secp256k1PointStruct} — or
|
|
6097
6226
|
* the four limbs
|
|
6098
|
-
* @throws {Error} when a value is
|
|
6227
|
+
* @throws {Error} when a value is null, undefined, of an unread type, text, a decimal number, or out
|
|
6228
|
+
* of range — see {@link CairoSecp256k1Point.validate} and {@link CairoSecp256k1Point.validateProps}
|
|
6229
|
+
* — or when the argument count is neither 1 nor 4
|
|
6099
6230
|
* @example
|
|
6100
6231
|
* ```typescript
|
|
6101
6232
|
* const result = new CairoSecp256k1Point(1n).toApiRequest();
|
|
@@ -6142,22 +6273,32 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6142
6273
|
* the constructor needs it, and computing it twice would mean splitting a 512-bit value twice.
|
|
6143
6274
|
* @param {BigNumberish} input the 512-bit value to check
|
|
6144
6275
|
* @returns {bigint} the value, once checked
|
|
6145
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, 2^512 - 1]
|
|
6276
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or outside [0, 2^512 - 1]
|
|
6146
6277
|
* @example
|
|
6147
6278
|
* ```typescript
|
|
6148
6279
|
* const result = CairoSecp256k1Point.validate('0x1234');
|
|
6149
6280
|
* // result = 4660n
|
|
6150
6281
|
* CairoSecp256k1Point.validate(SECP256K1_POINT_MAX + 1n);
|
|
6151
6282
|
* // throws Error("input is bigger than SECP256K1_POINT_MAX")
|
|
6283
|
+
* CairoSecp256k1Point.validate('abc');
|
|
6284
|
+
* // throws Error("Invalid input: a Secp256k1Point cannot be built from text")
|
|
6285
|
+
* CairoSecp256k1Point.validate(1.5);
|
|
6286
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
6152
6287
|
* ```
|
|
6153
6288
|
*/
|
|
6154
6289
|
static validate(input) {
|
|
6155
6290
|
assert(input !== null, "null value is not allowed for Secp256k1Point");
|
|
6156
6291
|
assert(input !== void 0, "undefined value is not allowed for Secp256k1Point");
|
|
6292
|
+
assert(!isText(input), "Invalid input: a Secp256k1Point cannot be built from text");
|
|
6293
|
+
assert(!isEmptyHex(input), "Invalid input: '0x' holds no hexadecimal digit");
|
|
6157
6294
|
assert(
|
|
6158
6295
|
isBigNumberish(input),
|
|
6159
6296
|
`Unsupported input for Secp256k1Point. Expected a number, a bigint, or a string spelling one, received '${typeof input}'`
|
|
6160
6297
|
);
|
|
6298
|
+
assert(
|
|
6299
|
+
!isNumber(input) || Number.isInteger(input),
|
|
6300
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
6301
|
+
);
|
|
6161
6302
|
const bigInt = BigInt(input);
|
|
6162
6303
|
assert(bigInt >= SECP256K1_POINT_MIN, "input is smaller than SECP256K1_POINT_MIN");
|
|
6163
6304
|
assert(bigInt <= SECP256K1_POINT_MAX, "input is bigger than SECP256K1_POINT_MAX");
|
|
@@ -6170,20 +6311,27 @@ var CairoSecp256k1Point = class _CairoSecp256k1Point {
|
|
|
6170
6311
|
* @param {BigNumberish} yLow the low 128 bits of y
|
|
6171
6312
|
* @param {BigNumberish} yHigh the high 128 bits of y
|
|
6172
6313
|
* @returns {{xLow: bigint, xHigh: bigint, yLow: bigint, yHigh: bigint}} the four limbs, checked
|
|
6173
|
-
* @throws {Error} when a limb is null, undefined, not a number, negative, or wider than 128 bits
|
|
6314
|
+
* @throws {Error} when a limb is null, undefined, text, `'0x'`, not a number, a decimal number, negative, or wider than 128 bits
|
|
6174
6315
|
* @example
|
|
6175
6316
|
* ```typescript
|
|
6176
6317
|
* const result = CairoSecp256k1Point.validateProps(1, 2, 3, 4);
|
|
6177
6318
|
* // result = { xLow: 1n, xHigh: 2n, yLow: 3n, yHigh: 4n }
|
|
6178
6319
|
* CairoSecp256k1Point.validateProps(1, 2, 3, 2n ** 128n);
|
|
6179
6320
|
* // throws Error("yHigh must fit in 128 bits")
|
|
6321
|
+
* CairoSecp256k1Point.validateProps(1.5, 2, 3, 4);
|
|
6322
|
+
* // throws Error("xLow must be an integer")
|
|
6323
|
+
* CairoSecp256k1Point.validateProps('abc', 2, 3, 4);
|
|
6324
|
+
* // throws Error("xLow cannot be built from text")
|
|
6180
6325
|
* ```
|
|
6181
6326
|
*/
|
|
6182
6327
|
static validateProps(xLow, xHigh, yLow, yHigh) {
|
|
6183
6328
|
const validateLimb = (limb, name) => {
|
|
6184
6329
|
assert(limb !== null, `${name} cannot be null`);
|
|
6185
6330
|
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
6331
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
6332
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
6186
6333
|
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
6334
|
+
assert(!isNumber(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
6187
6335
|
const bigInt = BigInt(limb);
|
|
6188
6336
|
assert(bigInt >= 0n, `${name} must be non-negative`);
|
|
6189
6337
|
assert(bigInt <= UINT_128_MAX, `${name} must fit in 128 bits`);
|
|
@@ -7326,9 +7474,9 @@ var CairoClassHash = class _CairoClassHash {
|
|
|
7326
7474
|
*/
|
|
7327
7475
|
static abiSelector = Literal.ClassHash;
|
|
7328
7476
|
/**
|
|
7329
|
-
* Build from a number or a numeric string, refusing text and anything
|
|
7330
|
-
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^
|
|
7331
|
-
* @throws {Error} when the value is text,
|
|
7477
|
+
* Build from a number or a numeric string, refusing text and anything outside the ClassHash range.
|
|
7478
|
+
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^251 - 1]
|
|
7479
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
7332
7480
|
* @example
|
|
7333
7481
|
* ```typescript
|
|
7334
7482
|
* const result = new CairoClassHash('0x1234').toApiRequest();
|
|
@@ -7383,21 +7531,34 @@ var CairoClassHash = class _CairoClassHash {
|
|
|
7383
7531
|
/**
|
|
7384
7532
|
* Throw unless the value can be carried by a ClassHash.
|
|
7385
7533
|
*
|
|
7386
|
-
* Text is refused first, then
|
|
7387
|
-
*
|
|
7388
|
-
* a
|
|
7534
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
7535
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
7536
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
7537
|
+
* the range of the Cairo `ClassHash` type, [0, 2^251), which is narrower than the field.
|
|
7389
7538
|
* @param {BigNumberish | boolean} data the value to check
|
|
7390
|
-
* @throws {Error} when the value is text,
|
|
7539
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
7391
7540
|
* @example
|
|
7392
7541
|
* ```typescript
|
|
7393
7542
|
* CairoClassHash.validate('0x1234'); // passes
|
|
7394
7543
|
* CairoClassHash.validate('abc');
|
|
7395
7544
|
* // throws Error("Invalid input: a ClassHash cannot be built from text")
|
|
7545
|
+
* CairoClassHash.validate(2n ** 251n);
|
|
7546
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
7547
|
+
* CairoClassHash.validate(-1);
|
|
7548
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
7396
7549
|
* ```
|
|
7397
7550
|
*/
|
|
7398
7551
|
static validate(data) {
|
|
7399
7552
|
assert(!isText(data), "Invalid input: a ClassHash cannot be built from text");
|
|
7400
|
-
|
|
7553
|
+
assert(
|
|
7554
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7555
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7556
|
+
);
|
|
7557
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7558
|
+
assert(
|
|
7559
|
+
value >= RANGE_CLASS_HASH.min && value <= RANGE_CLASS_HASH.max,
|
|
7560
|
+
`Value is out of ClassHash range [${RANGE_CLASS_HASH.min}, ${RANGE_CLASS_HASH.max}]`
|
|
7561
|
+
);
|
|
7401
7562
|
}
|
|
7402
7563
|
/**
|
|
7403
7564
|
* Can this value be carried by a ClassHash?
|
|
@@ -7476,7 +7637,7 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7476
7637
|
/**
|
|
7477
7638
|
* Build from a number or a numeric string, refusing text and anything wider than 252 bits.
|
|
7478
7639
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^252 - 1]
|
|
7479
|
-
* @throws {Error} when the value is text,
|
|
7640
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
7480
7641
|
* @example
|
|
7481
7642
|
* ```typescript
|
|
7482
7643
|
* const result = new CairoContractAddress('0x1234').toApiRequest();
|
|
@@ -7531,11 +7692,12 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7531
7692
|
/**
|
|
7532
7693
|
* Throw unless the value can be carried by a ContractAddress.
|
|
7533
7694
|
*
|
|
7534
|
-
* Text is refused first, then
|
|
7535
|
-
*
|
|
7536
|
-
* is
|
|
7695
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
7696
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
7697
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
7698
|
+
* the bound an address has, which is narrower than the field.
|
|
7537
7699
|
* @param {BigNumberish | boolean} data the value to check
|
|
7538
|
-
* @throws {Error} when the value is text,
|
|
7700
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
7539
7701
|
* @example
|
|
7540
7702
|
* ```typescript
|
|
7541
7703
|
* CairoContractAddress.validate('0x1234'); // passes
|
|
@@ -7543,11 +7705,17 @@ var CairoContractAddress = class _CairoContractAddress {
|
|
|
7543
7705
|
* // throws Error("Invalid input: a ContractAddress cannot be built from text")
|
|
7544
7706
|
* CairoContractAddress.validate(2n ** 251n);
|
|
7545
7707
|
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
7708
|
+
* CairoContractAddress.validate(-1);
|
|
7709
|
+
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
7546
7710
|
* ```
|
|
7547
7711
|
*/
|
|
7548
7712
|
static validate(data) {
|
|
7549
7713
|
assert(!isText(data), "Invalid input: a ContractAddress cannot be built from text");
|
|
7550
|
-
|
|
7714
|
+
assert(
|
|
7715
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7716
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7717
|
+
);
|
|
7718
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7551
7719
|
assert(
|
|
7552
7720
|
value >= RANGE_CONTRACT_ADDRESS.min && value <= RANGE_CONTRACT_ADDRESS.max,
|
|
7553
7721
|
`Value is out of ContractAddress range [${RANGE_CONTRACT_ADDRESS.min}, ${RANGE_CONTRACT_ADDRESS.max}]`
|
|
@@ -7632,7 +7800,7 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7632
7800
|
/**
|
|
7633
7801
|
* Build from a number or a numeric string, refusing text and anything wider than 160 bits.
|
|
7634
7802
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^160 - 1]
|
|
7635
|
-
* @throws {Error} when the value is text,
|
|
7803
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
7636
7804
|
* @example
|
|
7637
7805
|
* ```typescript
|
|
7638
7806
|
* const result = new CairoEthAddress('0x1234').toApiRequest();
|
|
@@ -7688,10 +7856,12 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7688
7856
|
* Throw unless the value can be carried by an EthAddress.
|
|
7689
7857
|
*
|
|
7690
7858
|
* Text is refused first, since an address spelled as words is a mistake rather than a value to
|
|
7691
|
-
* encode
|
|
7692
|
-
*
|
|
7859
|
+
* encode, then a number with a decimal part. A number or a bigint is read as it is, so that a
|
|
7860
|
+
* negative one reaches the range check below. Anything else is read as a felt252 — which is what
|
|
7861
|
+
* refuses a null, an object or an unsupported type. The value is finally checked against the 160
|
|
7862
|
+
* bits an Ethereum address occupies.
|
|
7693
7863
|
* @param {BigNumberish | boolean} data the value to check
|
|
7694
|
-
* @throws {Error} when the value is text,
|
|
7864
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
7695
7865
|
* @example
|
|
7696
7866
|
* ```typescript
|
|
7697
7867
|
* CairoEthAddress.validate('0x1234'); // passes
|
|
@@ -7699,11 +7869,17 @@ var CairoEthAddress = class _CairoEthAddress {
|
|
|
7699
7869
|
* // throws Error("Invalid input: an EthAddress cannot be built from text")
|
|
7700
7870
|
* CairoEthAddress.validate(2n ** 160n);
|
|
7701
7871
|
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
7872
|
+
* CairoEthAddress.validate(-1);
|
|
7873
|
+
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
7702
7874
|
* ```
|
|
7703
7875
|
*/
|
|
7704
7876
|
static validate(data) {
|
|
7705
7877
|
assert(!isText(data), "Invalid input: an EthAddress cannot be built from text");
|
|
7706
|
-
|
|
7878
|
+
assert(
|
|
7879
|
+
!isNumber(data) || Number.isInteger(data),
|
|
7880
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
7881
|
+
);
|
|
7882
|
+
const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
7707
7883
|
assert(
|
|
7708
7884
|
value >= RANGE_ETH_ADDRESS.min && value <= RANGE_ETH_ADDRESS.max,
|
|
7709
7885
|
`Value is out of EthAddress range [${RANGE_ETH_ADDRESS.min}, ${RANGE_ETH_ADDRESS.max}]`
|
|
@@ -13420,7 +13596,7 @@ function ethRandomPrivateKey() {
|
|
|
13420
13596
|
return sanitizeHex(buf2hex(secp256k1.utils.randomSecretKey()));
|
|
13421
13597
|
}
|
|
13422
13598
|
function validateAndParseEthAddress(address) {
|
|
13423
|
-
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address
|
|
13599
|
+
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address");
|
|
13424
13600
|
const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
|
|
13425
13601
|
assert(Boolean(result.match(/^(0x)?[0-9a-f]{40}$/)), "Invalid Ethereum Address Format");
|
|
13426
13602
|
return result;
|
|
@@ -17574,6 +17750,9 @@ function addAddressPadding(address) {
|
|
|
17574
17750
|
return addHexPrefix(padded);
|
|
17575
17751
|
}
|
|
17576
17752
|
function validateAndParseAddress(address) {
|
|
17753
|
+
if (isString(address) && !/^(0x)?[0-9a-f]+$/i.test(address)) {
|
|
17754
|
+
throw new Error("Invalid Address Format");
|
|
17755
|
+
}
|
|
17577
17756
|
const result = addAddressPadding(address);
|
|
17578
17757
|
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
17579
17758
|
throw new Error("Invalid Address Format");
|
|
@@ -20068,10 +20247,10 @@ function supportedWalletApi3(walletWSF) {
|
|
|
20068
20247
|
function subscribeWalletEvent2(walletWSF, callback) {
|
|
20069
20248
|
return walletWSF.features["standard:events"].on("change", callback);
|
|
20070
20249
|
}
|
|
20071
|
-
function strk20Balances(walletWSF, tokens) {
|
|
20250
|
+
function strk20Balances(walletWSF, tokens, valid_until) {
|
|
20072
20251
|
return walletWSF.features["starknet:walletApi"].request({
|
|
20073
20252
|
type: "wallet_strk20Balances",
|
|
20074
|
-
params: { tokens }
|
|
20253
|
+
params: { tokens, valid_until }
|
|
20075
20254
|
});
|
|
20076
20255
|
}
|
|
20077
20256
|
function strk20PrepareInvoke(walletWSF, actions, simulate) {
|
|
@@ -20124,16 +20303,26 @@ var WalletAccountV6 = class _WalletAccountV6 extends WalletAccountV5 {
|
|
|
20124
20303
|
}
|
|
20125
20304
|
/**
|
|
20126
20305
|
* Get the private balances held by the user inside the STRK20 privacy pool.
|
|
20306
|
+
*
|
|
20307
|
+
* Reading a shielded balance requires the user approval, and this approval is time
|
|
20308
|
+
* limited : `validUntil` requests when it expires. When it is omitted, the wallet applies
|
|
20309
|
+
* its own default window.
|
|
20127
20310
|
* @param {Address[]} tokens - The tokens to get the private balance of. An empty array returns every shielded token.
|
|
20311
|
+
* @param {number} [validUntil] - Requested expiry of the balance read authorization, as a Unix timestamp in seconds. Omit it to let the wallet apply its default window.
|
|
20128
20312
|
* @returns {Promise<STRK20_BALANCE_ENTRY[]>} One entry per token.
|
|
20129
20313
|
* @example
|
|
20130
20314
|
* ```typescript
|
|
20131
20315
|
* const balances = await myWalletAccount.strk20Balances([strkAddress]);
|
|
20132
|
-
* // balances = [{ token: '0x4718...',
|
|
20316
|
+
* // balances = [{ token: '0x4718...', balance: '0x2386f26fc10000' }]
|
|
20317
|
+
*
|
|
20318
|
+
* // Asking for a 5 minutes authorization window :
|
|
20319
|
+
* const expiry = Math.floor(Date.now() / 1000) + 300;
|
|
20320
|
+
* const fresh = await myWalletAccount.strk20Balances([strkAddress], expiry);
|
|
20321
|
+
* // fresh = [{ token: '0x4718...', balance: '0x2386f26fc10000' }]
|
|
20133
20322
|
* ```
|
|
20134
20323
|
*/
|
|
20135
|
-
strk20Balances(tokens) {
|
|
20136
|
-
return strk20Balances(this.v6Provider, tokens);
|
|
20324
|
+
strk20Balances(tokens, validUntil) {
|
|
20325
|
+
return strk20Balances(this.v6Provider, tokens, validUntil);
|
|
20137
20326
|
}
|
|
20138
20327
|
/**
|
|
20139
20328
|
* Build the Starknet call and the SNIP-36 zero-knowledge proof of a STRK20 transaction,
|