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.global.js
CHANGED
|
@@ -260,6 +260,7 @@ var starknet = (() => {
|
|
|
260
260
|
OutsideExecutionCallerAny: () => OutsideExecutionCallerAny,
|
|
261
261
|
PAYMASTER_RPC_NODES: () => PAYMASTER_RPC_NODES,
|
|
262
262
|
PRIME: () => PRIME,
|
|
263
|
+
RANGE_CLASS_HASH: () => RANGE_CLASS_HASH,
|
|
263
264
|
RANGE_CONTRACT_ADDRESS: () => RANGE_CONTRACT_ADDRESS,
|
|
264
265
|
RANGE_ETH_ADDRESS: () => RANGE_ETH_ADDRESS,
|
|
265
266
|
RANGE_FELT: () => RANGE_FELT,
|
|
@@ -1234,6 +1235,7 @@ var starknet = (() => {
|
|
|
1234
1235
|
var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
|
|
1235
1236
|
var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
|
|
1236
1237
|
var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
|
|
1238
|
+
var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
|
|
1237
1239
|
var LegacyUDC = {
|
|
1238
1240
|
ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
|
|
1239
1241
|
ENTRYPOINT: "deployContract"
|
|
@@ -2306,6 +2308,7 @@ ${indent}}` : "}";
|
|
|
2306
2308
|
hexToBytes: () => hexToBytes3,
|
|
2307
2309
|
hexToDecimalString: () => hexToDecimalString,
|
|
2308
2310
|
isBigNumberish: () => isBigNumberish,
|
|
2311
|
+
isEmptyHex: () => isEmptyHex,
|
|
2309
2312
|
isHex: () => isHex2,
|
|
2310
2313
|
isHexString: () => isHexString2,
|
|
2311
2314
|
isStringWholeNumber: () => isStringWholeNumber,
|
|
@@ -3052,6 +3055,7 @@ ${indent}}` : "}";
|
|
|
3052
3055
|
}
|
|
3053
3056
|
var isHexString2 = isHex2;
|
|
3054
3057
|
function toBigInt(value) {
|
|
3058
|
+
assert(!isEmptyHex(value), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3055
3059
|
return BigInt(value);
|
|
3056
3060
|
}
|
|
3057
3061
|
function tryToBigInt(value) {
|
|
@@ -3076,13 +3080,13 @@ ${indent}}` : "}";
|
|
|
3076
3080
|
return BigInt(addHexPrefix(hex)).toString(10);
|
|
3077
3081
|
}
|
|
3078
3082
|
function assertInRange(input, lowerBound, upperBound, inputName = "") {
|
|
3079
|
-
const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
|
|
3080
3083
|
const inputBigInt = BigInt(input);
|
|
3081
3084
|
const lowerBoundBigInt = BigInt(lowerBound);
|
|
3082
3085
|
const upperBoundBigInt = BigInt(upperBound);
|
|
3086
|
+
const rangeName = inputName === "" ? "range" : `${inputName} range`;
|
|
3083
3087
|
assert(
|
|
3084
3088
|
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
3085
|
-
`
|
|
3089
|
+
`Value is out of ${rangeName} [${lowerBoundBigInt}, ${upperBoundBigInt}]`
|
|
3086
3090
|
);
|
|
3087
3091
|
}
|
|
3088
3092
|
function bigNumberishArrayToDecimalStringArray(data) {
|
|
@@ -3135,8 +3139,11 @@ ${indent}}` : "}";
|
|
|
3135
3139
|
const result = int312(BigInt(addHexPrefix(buf2hex(sha256(utf8ToBytes(str))))));
|
|
3136
3140
|
return hexToBytes3(toHex(result));
|
|
3137
3141
|
}
|
|
3142
|
+
function isEmptyHex(value) {
|
|
3143
|
+
return isString(value) && /^0x$/i.test(value);
|
|
3144
|
+
}
|
|
3138
3145
|
function isBigNumberish(input) {
|
|
3139
|
-
return isNumber2(input) || isBigInt(input) || isString(input) && (isHex2(input) || isStringWholeNumber(input));
|
|
3146
|
+
return isNumber2(input) || isBigInt(input) || isString(input) && (isHex2(input) && !isEmptyHex(input) || isStringWholeNumber(input));
|
|
3140
3147
|
}
|
|
3141
3148
|
function getNext(iterator) {
|
|
3142
3149
|
const it = iterator.next();
|
|
@@ -6625,16 +6632,18 @@ ${indent}}` : "}";
|
|
|
6625
6632
|
/**
|
|
6626
6633
|
* Throw unless the value can be carried by a felt252.
|
|
6627
6634
|
*
|
|
6628
|
-
* Null, undefined
|
|
6629
|
-
* message, then the value is converted and its range checked. A negative number does not
|
|
6630
|
-
* that range check : converting it fails earlier, and the message comes from the conversion.
|
|
6635
|
+
* Null, undefined, any type this class does not read, and `'0x'` are refused first, each with its
|
|
6636
|
+
* own message, then the value is converted and its range checked. A negative number does not
|
|
6637
|
+
* reach that range check : converting it fails earlier, and the message comes from the conversion.
|
|
6631
6638
|
* @param {BigNumberish | boolean} data the value to check
|
|
6632
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, P)
|
|
6639
|
+
* @throws {Error} when the value is null, undefined, of an unread type, `'0x'`, or outside [0, P)
|
|
6633
6640
|
* @example
|
|
6634
6641
|
* ```typescript
|
|
6635
6642
|
* CairoFelt252.validate('Hello'); // passes
|
|
6636
6643
|
* CairoFelt252.validate({});
|
|
6637
6644
|
* // throws Error("Unsupported data type 'object' for felt252. Expected string, number, bigint, or boolean")
|
|
6645
|
+
* CairoFelt252.validate('0x');
|
|
6646
|
+
* // throws Error("Invalid input: '0x' holds no hexadecimal digit")
|
|
6638
6647
|
* CairoFelt252.validate(-1);
|
|
6639
6648
|
* // throws Error("Cannot convert negative bigint -1 to Uint8Array")
|
|
6640
6649
|
* ```
|
|
@@ -6646,6 +6655,7 @@ ${indent}}` : "}";
|
|
|
6646
6655
|
isString(data) || isNumber2(data) || isBigInt(data) || isBoolean(data),
|
|
6647
6656
|
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
6648
6657
|
);
|
|
6658
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
6649
6659
|
const value = _CairoFelt252.__processData(data);
|
|
6650
6660
|
const bn = uint8ArrayToBigInt(value);
|
|
6651
6661
|
_CairoFelt252.assertRange(bn);
|
|
@@ -7462,7 +7472,7 @@ ${indent}}` : "}";
|
|
|
7462
7472
|
* otherwise. Text therefore only fits here up to 4 ASCII characters : one more already
|
|
7463
7473
|
* makes a number past 4294967295.
|
|
7464
7474
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 4294967295]
|
|
7465
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
7475
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
7466
7476
|
* @example
|
|
7467
7477
|
* ```typescript
|
|
7468
7478
|
* const result = new CairoUint32('abcd').toApiRequest();
|
|
@@ -7550,11 +7560,11 @@ ${indent}}` : "}";
|
|
|
7550
7560
|
/**
|
|
7551
7561
|
* Throw unless the value can be carried by a u32.
|
|
7552
7562
|
*
|
|
7553
|
-
*
|
|
7554
|
-
* an array, a number with a decimal part, and a value outside [0, 4294967295]. A text string reaches
|
|
7563
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
7564
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 4294967295]. A text string reaches
|
|
7555
7565
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
7556
7566
|
* @param {BigNumberish | boolean} data the value to check
|
|
7557
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
7567
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
7558
7568
|
* @example
|
|
7559
7569
|
* ```typescript
|
|
7560
7570
|
* CairoUint32.validate(70000); // passes
|
|
@@ -7569,6 +7579,7 @@ ${indent}}` : "}";
|
|
|
7569
7579
|
!isNumber2(data) || Number.isInteger(data),
|
|
7570
7580
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
7571
7581
|
);
|
|
7582
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
7572
7583
|
const value = _CairoUint32.__processData(data);
|
|
7573
7584
|
assert(
|
|
7574
7585
|
value >= RANGE_U32.min && value <= RANGE_U32.max,
|
|
@@ -8156,7 +8167,6 @@ ${indent}}` : "}";
|
|
|
8156
8167
|
* ```
|
|
8157
8168
|
*/
|
|
8158
8169
|
low;
|
|
8159
|
-
// TODO should be u128
|
|
8160
8170
|
/**
|
|
8161
8171
|
* The top 128 bits of the value.
|
|
8162
8172
|
* @example
|
|
@@ -8166,7 +8176,6 @@ ${indent}}` : "}";
|
|
|
8166
8176
|
* ```
|
|
8167
8177
|
*/
|
|
8168
8178
|
high;
|
|
8169
|
-
// TODO should be u128
|
|
8170
8179
|
/**
|
|
8171
8180
|
* The abi type this class serializes.
|
|
8172
8181
|
* @example
|
|
@@ -8200,25 +8209,37 @@ ${indent}}` : "}";
|
|
|
8200
8209
|
* Throw unless a whole value can be represented as a u256, and give back its number.
|
|
8201
8210
|
*
|
|
8202
8211
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
8203
|
-
* refused
|
|
8212
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint256`
|
|
8213
|
+
* one included : its two halves are checked by {@link CairoUint256.validateProps}, which is what
|
|
8214
|
+
* the constructor calls for it.
|
|
8204
8215
|
* @param {BigNumberish} bigNumberish the value to check
|
|
8205
8216
|
* @returns {bigint} the value as a number, once accepted
|
|
8206
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or out of range
|
|
8217
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
8207
8218
|
* @example
|
|
8208
8219
|
* ```typescript
|
|
8209
8220
|
* const result = CairoUint256.validate(255);
|
|
8210
8221
|
* // result = 255n
|
|
8211
8222
|
* CairoUint256.validate(-1);
|
|
8212
8223
|
* // throws Error("bigNumberish is smaller than UINT_256_MIN")
|
|
8224
|
+
* CairoUint256.validate('abc');
|
|
8225
|
+
* // throws Error("Invalid input: a u256 cannot be built from text")
|
|
8226
|
+
* CairoUint256.validate(1.5);
|
|
8227
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
8213
8228
|
* ```
|
|
8214
8229
|
*/
|
|
8215
8230
|
static validate(bigNumberish) {
|
|
8216
8231
|
assert(bigNumberish !== null, "null value is not allowed for u256");
|
|
8217
8232
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u256");
|
|
8233
|
+
assert(!isText(bigNumberish), "Invalid input: a u256 cannot be built from text");
|
|
8234
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
8218
8235
|
assert(
|
|
8219
|
-
isBigNumberish(bigNumberish)
|
|
8236
|
+
isBigNumberish(bigNumberish),
|
|
8220
8237
|
`Unsupported data type '${typeof bigNumberish}' for u256. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint256 object`
|
|
8221
8238
|
);
|
|
8239
|
+
assert(
|
|
8240
|
+
!isNumber2(bigNumberish) || Number.isInteger(bigNumberish),
|
|
8241
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
8242
|
+
);
|
|
8222
8243
|
const bigInt = BigInt(bigNumberish);
|
|
8223
8244
|
assert(bigInt >= UINT_256_MIN, "bigNumberish is smaller than UINT_256_MIN");
|
|
8224
8245
|
assert(bigInt <= UINT_256_MAX, "bigNumberish is bigger than UINT_256_MAX");
|
|
@@ -8232,18 +8253,31 @@ ${indent}}` : "}";
|
|
|
8232
8253
|
* @param {BigNumberish} low the bottom 128 bits
|
|
8233
8254
|
* @param {BigNumberish} high the top 128 bits
|
|
8234
8255
|
* @returns {{low: bigint, high: bigint}} the two halves as numbers
|
|
8235
|
-
* @throws {Error} when either half is outside the u128 range
|
|
8256
|
+
* @throws {Error} when either half is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
8236
8257
|
* @example
|
|
8237
8258
|
* ```typescript
|
|
8238
8259
|
* const result = CairoUint256.validateProps(5, 4);
|
|
8239
8260
|
* // result = { low: 5n, high: 4n }
|
|
8240
8261
|
* CairoUint256.validateProps(-1, 4);
|
|
8241
8262
|
* // throws Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX")
|
|
8263
|
+
* CairoUint256.validateProps(1.5, 4);
|
|
8264
|
+
* // throws Error("low must be an integer")
|
|
8265
|
+
* CairoUint256.validateProps('abc', 4);
|
|
8266
|
+
* // throws Error("low cannot be built from text")
|
|
8242
8267
|
* ```
|
|
8243
8268
|
*/
|
|
8244
8269
|
static validateProps(low, high) {
|
|
8245
|
-
const
|
|
8246
|
-
|
|
8270
|
+
const validateHalf = (half, name) => {
|
|
8271
|
+
assert(half !== null, `${name} cannot be null`);
|
|
8272
|
+
assert(half !== void 0, `${name} cannot be undefined`);
|
|
8273
|
+
assert(!isText(half), `${name} cannot be built from text`);
|
|
8274
|
+
assert(!isEmptyHex(half), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
8275
|
+
assert(isBigNumberish(half), `${name} must be a BigNumberish`);
|
|
8276
|
+
assert(!isNumber2(half) || Number.isInteger(half), `${name} must be an integer`);
|
|
8277
|
+
return BigInt(half);
|
|
8278
|
+
};
|
|
8279
|
+
const bigIntLow = validateHalf(low, "low");
|
|
8280
|
+
const bigIntHigh = validateHalf(high, "high");
|
|
8247
8281
|
assert(
|
|
8248
8282
|
bigIntLow >= UINT_256_LOW_MIN && bigIntLow <= UINT_256_LOW_MAX,
|
|
8249
8283
|
"low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX"
|
|
@@ -8380,7 +8414,6 @@ ${indent}}` : "}";
|
|
|
8380
8414
|
* ```
|
|
8381
8415
|
*/
|
|
8382
8416
|
limb0;
|
|
8383
|
-
// TODO should be u128
|
|
8384
8417
|
/**
|
|
8385
8418
|
* Bits 128 to 255 of the value.
|
|
8386
8419
|
* @example
|
|
@@ -8390,7 +8423,6 @@ ${indent}}` : "}";
|
|
|
8390
8423
|
* ```
|
|
8391
8424
|
*/
|
|
8392
8425
|
limb1;
|
|
8393
|
-
// TODO should be u128
|
|
8394
8426
|
/**
|
|
8395
8427
|
* Bits 256 to 383 of the value.
|
|
8396
8428
|
* @example
|
|
@@ -8400,7 +8432,6 @@ ${indent}}` : "}";
|
|
|
8400
8432
|
* ```
|
|
8401
8433
|
*/
|
|
8402
8434
|
limb2;
|
|
8403
|
-
// TODO should be u128
|
|
8404
8435
|
/**
|
|
8405
8436
|
* Bits 384 to 511 of the value.
|
|
8406
8437
|
* @example
|
|
@@ -8410,7 +8441,6 @@ ${indent}}` : "}";
|
|
|
8410
8441
|
* ```
|
|
8411
8442
|
*/
|
|
8412
8443
|
limb3;
|
|
8413
|
-
// TODO should be u128
|
|
8414
8444
|
/**
|
|
8415
8445
|
* The abi type this class serializes.
|
|
8416
8446
|
* @example
|
|
@@ -8452,25 +8482,37 @@ ${indent}}` : "}";
|
|
|
8452
8482
|
* Throw unless a whole value can be represented as a u512, and give back its number.
|
|
8453
8483
|
*
|
|
8454
8484
|
* A string is only accepted while it spells a number, in base 10 or 16 : one that does not is
|
|
8455
|
-
* refused
|
|
8485
|
+
* refused as text, and `'0x'`, which holds no digit, is refused too. So is an object, a `Uint512`
|
|
8486
|
+
* one included : its four limbs are checked by {@link CairoUint512.validateProps}, which is what
|
|
8487
|
+
* the constructor calls for it.
|
|
8456
8488
|
* @param {BigNumberish} bigNumberish the value to check
|
|
8457
8489
|
* @returns {bigint} the value as a number, once accepted
|
|
8458
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or out of range
|
|
8490
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or out of range
|
|
8459
8491
|
* @example
|
|
8460
8492
|
* ```typescript
|
|
8461
8493
|
* const result = CairoUint512.validate(255);
|
|
8462
8494
|
* // result = 255n
|
|
8463
8495
|
* CairoUint512.validate(-1);
|
|
8464
8496
|
* // throws Error("bigNumberish is smaller than UINT_512_MIN.")
|
|
8497
|
+
* CairoUint512.validate('abc');
|
|
8498
|
+
* // throws Error("Invalid input: a u512 cannot be built from text")
|
|
8499
|
+
* CairoUint512.validate(1.5);
|
|
8500
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
8465
8501
|
* ```
|
|
8466
8502
|
*/
|
|
8467
8503
|
static validate(bigNumberish) {
|
|
8468
8504
|
assert(bigNumberish !== null, "null value is not allowed for u512");
|
|
8469
8505
|
assert(bigNumberish !== void 0, "undefined value is not allowed for u512");
|
|
8506
|
+
assert(!isText(bigNumberish), "Invalid input: a u512 cannot be built from text");
|
|
8507
|
+
assert(!isEmptyHex(bigNumberish), "Invalid input: '0x' holds no hexadecimal digit");
|
|
8470
8508
|
assert(
|
|
8471
|
-
isBigNumberish(bigNumberish)
|
|
8509
|
+
isBigNumberish(bigNumberish),
|
|
8472
8510
|
`Unsupported data type '${typeof bigNumberish}' for u512. Expected a numeric string (decimal or hexadecimal), number, bigint, or Uint512 object`
|
|
8473
8511
|
);
|
|
8512
|
+
assert(
|
|
8513
|
+
!isNumber2(bigNumberish) || Number.isInteger(bigNumberish),
|
|
8514
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
8515
|
+
);
|
|
8474
8516
|
const bigInt = BigInt(bigNumberish);
|
|
8475
8517
|
assert(bigInt >= UINT_512_MIN, "bigNumberish is smaller than UINT_512_MIN.");
|
|
8476
8518
|
assert(bigInt <= UINT_512_MAX, "bigNumberish is bigger than UINT_512_MAX.");
|
|
@@ -8486,20 +8528,33 @@ ${indent}}` : "}";
|
|
|
8486
8528
|
* @param {BigNumberish} limb2 bits 256 to 383
|
|
8487
8529
|
* @param {BigNumberish} limb3 bits 384 to 511
|
|
8488
8530
|
* @returns {{limb0: bigint, limb1: bigint, limb2: bigint, limb3: bigint}} the four limbs as numbers
|
|
8489
|
-
* @throws {Error} when any limb is outside the u128 range
|
|
8531
|
+
* @throws {Error} when any limb is null, undefined, text, `'0x'`, not a number, a decimal number, or outside the u128 range
|
|
8490
8532
|
* @example
|
|
8491
8533
|
* ```typescript
|
|
8492
8534
|
* const result = CairoUint512.validateProps(7, 0, 0, 64);
|
|
8493
8535
|
* // result = { limb0: 7n, limb1: 0n, limb2: 0n, limb3: 64n }
|
|
8494
8536
|
* CairoUint512.validateProps(-1, 0, 0, 0);
|
|
8495
8537
|
* // throws Error("limb0 is not in the range of a u128 number")
|
|
8538
|
+
* CairoUint512.validateProps(1.5, 0, 0, 0);
|
|
8539
|
+
* // throws Error("limb0 must be an integer")
|
|
8540
|
+
* CairoUint512.validateProps('abc', 0, 0, 0);
|
|
8541
|
+
* // throws Error("limb0 cannot be built from text")
|
|
8496
8542
|
* ```
|
|
8497
8543
|
*/
|
|
8498
8544
|
static validateProps(limb0, limb1, limb2, limb3) {
|
|
8499
|
-
const
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8545
|
+
const validateLimb = (limb, name) => {
|
|
8546
|
+
assert(limb !== null, `${name} cannot be null`);
|
|
8547
|
+
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
8548
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
8549
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
8550
|
+
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
8551
|
+
assert(!isNumber2(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
8552
|
+
return BigInt(limb);
|
|
8553
|
+
};
|
|
8554
|
+
const l0 = validateLimb(limb0, "limb0");
|
|
8555
|
+
const l1 = validateLimb(limb1, "limb1");
|
|
8556
|
+
const l2 = validateLimb(limb2, "limb2");
|
|
8557
|
+
const l3 = validateLimb(limb3, "limb3");
|
|
8503
8558
|
[l0, l1, l2, l3].forEach((value, index) => {
|
|
8504
8559
|
assert(
|
|
8505
8560
|
value >= UINT_128_MIN && value <= UINT_128_MAX,
|
|
@@ -8671,7 +8726,7 @@ ${indent}}` : "}";
|
|
|
8671
8726
|
* otherwise. Text therefore only fits here up to 12 ASCII characters : one more already
|
|
8672
8727
|
* makes a number past 79228162514264337593543950335.
|
|
8673
8728
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 79228162514264337593543950335]
|
|
8674
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
8729
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
8675
8730
|
* @example
|
|
8676
8731
|
* ```typescript
|
|
8677
8732
|
* const result = new CairoUint96('abcdefghijkl').toApiRequest();
|
|
@@ -8759,11 +8814,11 @@ ${indent}}` : "}";
|
|
|
8759
8814
|
/**
|
|
8760
8815
|
* Throw unless the value can be carried by a u96.
|
|
8761
8816
|
*
|
|
8762
|
-
*
|
|
8763
|
-
* an array, a number with a decimal part, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
8817
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
8818
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 79228162514264337593543950335]. A text string reaches
|
|
8764
8819
|
* that last check as the number its bytes spell, so `'abcdefghijklm'` is refused for being out of range.
|
|
8765
8820
|
* @param {BigNumberish | boolean} data the value to check
|
|
8766
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
8821
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
8767
8822
|
* @example
|
|
8768
8823
|
* ```typescript
|
|
8769
8824
|
* CairoUint96.validate(5000000000); // passes
|
|
@@ -8778,6 +8833,7 @@ ${indent}}` : "}";
|
|
|
8778
8833
|
!isNumber2(data) || Number.isInteger(data),
|
|
8779
8834
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
8780
8835
|
);
|
|
8836
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
8781
8837
|
const value = _CairoUint96.__processData(data);
|
|
8782
8838
|
assert(
|
|
8783
8839
|
value >= RANGE_U96.min && value <= RANGE_U96.max,
|
|
@@ -9164,7 +9220,7 @@ ${indent}}` : "}";
|
|
|
9164
9220
|
* otherwise. Text therefore only fits here while it is a single ASCII character : two characters
|
|
9165
9221
|
* already make a number past 255.
|
|
9166
9222
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 255]
|
|
9167
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9223
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9168
9224
|
* @example
|
|
9169
9225
|
* ```typescript
|
|
9170
9226
|
* const result = new CairoUint8('a').toApiRequest();
|
|
@@ -9254,11 +9310,11 @@ ${indent}}` : "}";
|
|
|
9254
9310
|
/**
|
|
9255
9311
|
* Throw unless the value can be carried by a u8.
|
|
9256
9312
|
*
|
|
9257
|
-
*
|
|
9258
|
-
* an array, a number with a decimal part, and a value outside [0, 255]. A text string reaches
|
|
9313
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
9314
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 255]. A text string reaches
|
|
9259
9315
|
* that last check as the number its bytes spell, so `'ab'` is refused for being out of range.
|
|
9260
9316
|
* @param {BigNumberish | boolean} data the value to check
|
|
9261
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9317
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9262
9318
|
* @example
|
|
9263
9319
|
* ```typescript
|
|
9264
9320
|
* CairoUint8.validate(44); // passes
|
|
@@ -9273,6 +9329,7 @@ ${indent}}` : "}";
|
|
|
9273
9329
|
!isNumber2(data) || Number.isInteger(data),
|
|
9274
9330
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
9275
9331
|
);
|
|
9332
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
9276
9333
|
const value = _CairoUint8.__processData(data);
|
|
9277
9334
|
assert(
|
|
9278
9335
|
value >= RANGE_U8.min && value <= RANGE_U8.max,
|
|
@@ -9363,7 +9420,7 @@ ${indent}}` : "}";
|
|
|
9363
9420
|
* otherwise. Text therefore only fits here up to 2 ASCII characters : one more already
|
|
9364
9421
|
* makes a number past 65535.
|
|
9365
9422
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 65535]
|
|
9366
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9423
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9367
9424
|
* @example
|
|
9368
9425
|
* ```typescript
|
|
9369
9426
|
* const result = new CairoUint16('ab').toApiRequest();
|
|
@@ -9451,11 +9508,11 @@ ${indent}}` : "}";
|
|
|
9451
9508
|
/**
|
|
9452
9509
|
* Throw unless the value can be carried by a u16.
|
|
9453
9510
|
*
|
|
9454
|
-
*
|
|
9455
|
-
* an array, a number with a decimal part, and a value outside [0, 65535]. A text string reaches
|
|
9511
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
9512
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 65535]. A text string reaches
|
|
9456
9513
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
9457
9514
|
* @param {BigNumberish | boolean} data the value to check
|
|
9458
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9515
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9459
9516
|
* @example
|
|
9460
9517
|
* ```typescript
|
|
9461
9518
|
* CairoUint16.validate(300); // passes
|
|
@@ -9470,6 +9527,7 @@ ${indent}}` : "}";
|
|
|
9470
9527
|
!isNumber2(data) || Number.isInteger(data),
|
|
9471
9528
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
9472
9529
|
);
|
|
9530
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
9473
9531
|
const value = _CairoUint16.__processData(data);
|
|
9474
9532
|
assert(
|
|
9475
9533
|
value >= RANGE_U16.min && value <= RANGE_U16.max,
|
|
@@ -9560,7 +9618,7 @@ ${indent}}` : "}";
|
|
|
9560
9618
|
* otherwise. Text therefore only fits here up to 8 ASCII characters : one more already
|
|
9561
9619
|
* makes a number past 18446744073709551615.
|
|
9562
9620
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 18446744073709551615]
|
|
9563
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9621
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9564
9622
|
* @example
|
|
9565
9623
|
* ```typescript
|
|
9566
9624
|
* const result = new CairoUint64('abcdefgh').toApiRequest();
|
|
@@ -9648,11 +9706,11 @@ ${indent}}` : "}";
|
|
|
9648
9706
|
/**
|
|
9649
9707
|
* Throw unless the value can be carried by a u64.
|
|
9650
9708
|
*
|
|
9651
|
-
*
|
|
9652
|
-
* an array, a number with a decimal part, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
9709
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
9710
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 18446744073709551615]. A text string reaches
|
|
9653
9711
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
9654
9712
|
* @param {BigNumberish | boolean} data the value to check
|
|
9655
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9713
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9656
9714
|
* @example
|
|
9657
9715
|
* ```typescript
|
|
9658
9716
|
* CairoUint64.validate(5000000000); // passes
|
|
@@ -9667,6 +9725,7 @@ ${indent}}` : "}";
|
|
|
9667
9725
|
!isNumber2(data) || Number.isInteger(data),
|
|
9668
9726
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
9669
9727
|
);
|
|
9728
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
9670
9729
|
const value = _CairoUint64.__processData(data);
|
|
9671
9730
|
assert(
|
|
9672
9731
|
value >= RANGE_U64.min && value <= RANGE_U64.max,
|
|
@@ -9757,7 +9816,7 @@ ${indent}}` : "}";
|
|
|
9757
9816
|
* otherwise. Text therefore only fits here up to 16 ASCII characters : one more already
|
|
9758
9817
|
* makes a number past 340282366920938463463374607431768211455.
|
|
9759
9818
|
* @param {BigNumberish | boolean} data the value to carry, within [0, 340282366920938463463374607431768211455]
|
|
9760
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9819
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9761
9820
|
* @example
|
|
9762
9821
|
* ```typescript
|
|
9763
9822
|
* const result = new CairoUint128('abcdefghijklmnop').toApiRequest();
|
|
@@ -9845,11 +9904,11 @@ ${indent}}` : "}";
|
|
|
9845
9904
|
/**
|
|
9846
9905
|
* Throw unless the value can be carried by a u128.
|
|
9847
9906
|
*
|
|
9848
|
-
*
|
|
9849
|
-
* an array, a number with a decimal part, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
9907
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
9908
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [0, 340282366920938463463374607431768211455]. A text string reaches
|
|
9850
9909
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
9851
9910
|
* @param {BigNumberish | boolean} data the value to check
|
|
9852
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
9911
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9853
9912
|
* @example
|
|
9854
9913
|
* ```typescript
|
|
9855
9914
|
* CairoUint128.validate(5000000000); // passes
|
|
@@ -9864,6 +9923,7 @@ ${indent}}` : "}";
|
|
|
9864
9923
|
!isNumber2(data) || Number.isInteger(data),
|
|
9865
9924
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
9866
9925
|
);
|
|
9926
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
9867
9927
|
const value = _CairoUint128.__processData(data);
|
|
9868
9928
|
assert(
|
|
9869
9929
|
value >= RANGE_U128.min && value <= RANGE_U128.max,
|
|
@@ -9950,15 +10010,17 @@ ${indent}}` : "}";
|
|
|
9950
10010
|
/**
|
|
9951
10011
|
* Build from a number, a string or a boolean, refusing anything out of the i8 range.
|
|
9952
10012
|
*
|
|
9953
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
9954
|
-
* otherwise. Text therefore only fits here up to a single
|
|
9955
|
-
* makes a number past 127.
|
|
10013
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
10014
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to a single
|
|
10015
|
+
* ASCII character : one more already makes a number past 127.
|
|
9956
10016
|
* @param {BigNumberish | boolean} data the value to carry, within [-128, 127]
|
|
9957
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10017
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
9958
10018
|
* @example
|
|
9959
10019
|
* ```typescript
|
|
9960
10020
|
* const result = new CairoInt8('a').toApiRequest();
|
|
9961
10021
|
* // result = ["97"]
|
|
10022
|
+
* const result2 = new CairoInt8('-5').toApiRequest();
|
|
10023
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
9962
10024
|
* ```
|
|
9963
10025
|
*/
|
|
9964
10026
|
constructor(data) {
|
|
@@ -9970,6 +10032,9 @@ ${indent}}` : "}";
|
|
|
9970
10032
|
*
|
|
9971
10033
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
9972
10034
|
* far outside the i8 range comes back untouched rather than raising.
|
|
10035
|
+
*
|
|
10036
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
10037
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
9973
10038
|
* @param {BigNumberish | boolean} data the value to convert
|
|
9974
10039
|
* @returns {bigint} the number the input spells, of whatever size
|
|
9975
10040
|
* @example
|
|
@@ -9978,9 +10043,14 @@ ${indent}}` : "}";
|
|
|
9978
10043
|
* // result = 97n
|
|
9979
10044
|
* const result2 = CairoInt8.__processData('ab');
|
|
9980
10045
|
* // result2 = 24930n (past the i8 range, and returned all the same)
|
|
10046
|
+
* const result3 = CairoInt8.__processData('-0x5');
|
|
10047
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
9981
10048
|
* ```
|
|
9982
10049
|
*/
|
|
9983
10050
|
static __processData(data) {
|
|
10051
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
10052
|
+
return -BigInt(data.slice(1));
|
|
10053
|
+
}
|
|
9984
10054
|
if (isString(data) && isText(data)) {
|
|
9985
10055
|
return utf8ToBigInt(data);
|
|
9986
10056
|
}
|
|
@@ -10059,11 +10129,12 @@ ${indent}}` : "}";
|
|
|
10059
10129
|
/**
|
|
10060
10130
|
* Throw unless the value can be carried by an i8.
|
|
10061
10131
|
*
|
|
10062
|
-
*
|
|
10063
|
-
* an array, a number with a decimal part, and a value outside [-128, 127]. A text string
|
|
10064
|
-
* that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
10132
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
10133
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-128, 127]. A text string
|
|
10134
|
+
* reaches that last check as the number its bytes spell, so `'ab'` is refused for being out of
|
|
10135
|
+
* range.
|
|
10065
10136
|
* @param {BigNumberish | boolean} data the value to check
|
|
10066
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10137
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10067
10138
|
* @example
|
|
10068
10139
|
* ```typescript
|
|
10069
10140
|
* CairoInt8.validate(5); // passes
|
|
@@ -10078,6 +10149,7 @@ ${indent}}` : "}";
|
|
|
10078
10149
|
!isNumber2(data) || Number.isInteger(data),
|
|
10079
10150
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
10080
10151
|
);
|
|
10152
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
10081
10153
|
const value = _CairoInt8.__processData(data);
|
|
10082
10154
|
assert(
|
|
10083
10155
|
value >= RANGE_I8.min && value <= RANGE_I8.max,
|
|
@@ -10168,15 +10240,17 @@ ${indent}}` : "}";
|
|
|
10168
10240
|
/**
|
|
10169
10241
|
* Build from a number, a string or a boolean, refusing anything out of the i16 range.
|
|
10170
10242
|
*
|
|
10171
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
10172
|
-
* otherwise. Text therefore only fits here up to 2 ASCII
|
|
10173
|
-
* makes a number past 32767.
|
|
10243
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
10244
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 2 ASCII
|
|
10245
|
+
* characters : one more already makes a number past 32767.
|
|
10174
10246
|
* @param {BigNumberish | boolean} data the value to carry, within [-32768, 32767]
|
|
10175
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10247
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10176
10248
|
* @example
|
|
10177
10249
|
* ```typescript
|
|
10178
10250
|
* const result = new CairoInt16('ab').toApiRequest();
|
|
10179
10251
|
* // result = ["24930"]
|
|
10252
|
+
* const result2 = new CairoInt16('-5').toApiRequest();
|
|
10253
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
10180
10254
|
* ```
|
|
10181
10255
|
*/
|
|
10182
10256
|
constructor(data) {
|
|
@@ -10188,6 +10262,9 @@ ${indent}}` : "}";
|
|
|
10188
10262
|
*
|
|
10189
10263
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
10190
10264
|
* far outside the i16 range comes back untouched rather than raising.
|
|
10265
|
+
*
|
|
10266
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
10267
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
10191
10268
|
* @param {BigNumberish | boolean} data the value to convert
|
|
10192
10269
|
* @returns {bigint} the number the input spells, of whatever size
|
|
10193
10270
|
* @example
|
|
@@ -10196,9 +10273,14 @@ ${indent}}` : "}";
|
|
|
10196
10273
|
* // result = 24930n
|
|
10197
10274
|
* const result2 = CairoInt16.__processData('abc');
|
|
10198
10275
|
* // result2 = 6382179n (past the i16 range, and returned all the same)
|
|
10276
|
+
* const result3 = CairoInt16.__processData('-0x5');
|
|
10277
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
10199
10278
|
* ```
|
|
10200
10279
|
*/
|
|
10201
10280
|
static __processData(data) {
|
|
10281
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
10282
|
+
return -BigInt(data.slice(1));
|
|
10283
|
+
}
|
|
10202
10284
|
if (isString(data) && isText(data)) {
|
|
10203
10285
|
return utf8ToBigInt(data);
|
|
10204
10286
|
}
|
|
@@ -10277,11 +10359,11 @@ ${indent}}` : "}";
|
|
|
10277
10359
|
/**
|
|
10278
10360
|
* Throw unless the value can be carried by an i16.
|
|
10279
10361
|
*
|
|
10280
|
-
*
|
|
10281
|
-
* an array, a number with a decimal part, and a value outside [-32768, 32767]. A text string reaches
|
|
10362
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
10363
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-32768, 32767]. A text string reaches
|
|
10282
10364
|
* that last check as the number its bytes spell, so `'abc'` is refused for being out of range.
|
|
10283
10365
|
* @param {BigNumberish | boolean} data the value to check
|
|
10284
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10366
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10285
10367
|
* @example
|
|
10286
10368
|
* ```typescript
|
|
10287
10369
|
* CairoInt16.validate(300); // passes
|
|
@@ -10296,6 +10378,7 @@ ${indent}}` : "}";
|
|
|
10296
10378
|
!isNumber2(data) || Number.isInteger(data),
|
|
10297
10379
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
10298
10380
|
);
|
|
10381
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
10299
10382
|
const value = _CairoInt16.__processData(data);
|
|
10300
10383
|
assert(
|
|
10301
10384
|
value >= RANGE_I16.min && value <= RANGE_I16.max,
|
|
@@ -10386,15 +10469,17 @@ ${indent}}` : "}";
|
|
|
10386
10469
|
/**
|
|
10387
10470
|
* Build from a number, a string or a boolean, refusing anything out of the i32 range.
|
|
10388
10471
|
*
|
|
10389
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
10390
|
-
* otherwise. Text therefore only fits here up to 4 ASCII
|
|
10391
|
-
* makes a number past 2147483647.
|
|
10472
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
10473
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 4 ASCII
|
|
10474
|
+
* characters : one more already makes a number past 2147483647.
|
|
10392
10475
|
* @param {BigNumberish | boolean} data the value to carry, within [-2147483648, 2147483647]
|
|
10393
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10476
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10394
10477
|
* @example
|
|
10395
10478
|
* ```typescript
|
|
10396
10479
|
* const result = new CairoInt32('abcd').toApiRequest();
|
|
10397
10480
|
* // result = ["1633837924"]
|
|
10481
|
+
* const result2 = new CairoInt32('-5').toApiRequest();
|
|
10482
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
10398
10483
|
* ```
|
|
10399
10484
|
*/
|
|
10400
10485
|
constructor(data) {
|
|
@@ -10406,6 +10491,9 @@ ${indent}}` : "}";
|
|
|
10406
10491
|
*
|
|
10407
10492
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
10408
10493
|
* far outside the i32 range comes back untouched rather than raising.
|
|
10494
|
+
*
|
|
10495
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
10496
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
10409
10497
|
* @param {BigNumberish | boolean} data the value to convert
|
|
10410
10498
|
* @returns {bigint} the number the input spells, of whatever size
|
|
10411
10499
|
* @example
|
|
@@ -10414,9 +10502,14 @@ ${indent}}` : "}";
|
|
|
10414
10502
|
* // result = 1633837924n
|
|
10415
10503
|
* const result2 = CairoInt32.__processData('abcde');
|
|
10416
10504
|
* // result2 = 418262508645n (past the i32 range, and returned all the same)
|
|
10505
|
+
* const result3 = CairoInt32.__processData('-0x5');
|
|
10506
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
10417
10507
|
* ```
|
|
10418
10508
|
*/
|
|
10419
10509
|
static __processData(data) {
|
|
10510
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
10511
|
+
return -BigInt(data.slice(1));
|
|
10512
|
+
}
|
|
10420
10513
|
if (isString(data) && isText(data)) {
|
|
10421
10514
|
return utf8ToBigInt(data);
|
|
10422
10515
|
}
|
|
@@ -10495,11 +10588,11 @@ ${indent}}` : "}";
|
|
|
10495
10588
|
/**
|
|
10496
10589
|
* Throw unless the value can be carried by an i32.
|
|
10497
10590
|
*
|
|
10498
|
-
*
|
|
10499
|
-
* an array, a number with a decimal part, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
10591
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
10592
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-2147483648, 2147483647]. A text string reaches
|
|
10500
10593
|
* that last check as the number its bytes spell, so `'abcde'` is refused for being out of range.
|
|
10501
10594
|
* @param {BigNumberish | boolean} data the value to check
|
|
10502
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10595
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10503
10596
|
* @example
|
|
10504
10597
|
* ```typescript
|
|
10505
10598
|
* CairoInt32.validate(70000); // passes
|
|
@@ -10514,6 +10607,7 @@ ${indent}}` : "}";
|
|
|
10514
10607
|
!isNumber2(data) || Number.isInteger(data),
|
|
10515
10608
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
10516
10609
|
);
|
|
10610
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
10517
10611
|
const value = _CairoInt32.__processData(data);
|
|
10518
10612
|
assert(
|
|
10519
10613
|
value >= RANGE_I32.min && value <= RANGE_I32.max,
|
|
@@ -10604,15 +10698,17 @@ ${indent}}` : "}";
|
|
|
10604
10698
|
/**
|
|
10605
10699
|
* Build from a number, a string or a boolean, refusing anything out of the i64 range.
|
|
10606
10700
|
*
|
|
10607
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
10608
|
-
* otherwise. Text therefore only fits here up to 8 ASCII
|
|
10609
|
-
* makes a number past 9223372036854775807.
|
|
10701
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
10702
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 8 ASCII
|
|
10703
|
+
* characters : one more already makes a number past 9223372036854775807.
|
|
10610
10704
|
* @param {BigNumberish | boolean} data the value to carry, within [-9223372036854775808, 9223372036854775807]
|
|
10611
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10705
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10612
10706
|
* @example
|
|
10613
10707
|
* ```typescript
|
|
10614
10708
|
* const result = new CairoInt64('abcdefgh').toApiRequest();
|
|
10615
10709
|
* // result = ["7017280452245743464"]
|
|
10710
|
+
* const result2 = new CairoInt64('-5').toApiRequest();
|
|
10711
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
10616
10712
|
* ```
|
|
10617
10713
|
*/
|
|
10618
10714
|
constructor(data) {
|
|
@@ -10624,6 +10720,9 @@ ${indent}}` : "}";
|
|
|
10624
10720
|
*
|
|
10625
10721
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
10626
10722
|
* far outside the i64 range comes back untouched rather than raising.
|
|
10723
|
+
*
|
|
10724
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
10725
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
10627
10726
|
* @param {BigNumberish | boolean} data the value to convert
|
|
10628
10727
|
* @returns {bigint} the number the input spells, of whatever size
|
|
10629
10728
|
* @example
|
|
@@ -10632,9 +10731,14 @@ ${indent}}` : "}";
|
|
|
10632
10731
|
* // result = 7017280452245743464n
|
|
10633
10732
|
* const result2 = CairoInt64.__processData('abcdefghi');
|
|
10634
10733
|
* // result2 = 1796423795774910326889n (past the i64 range, and returned all the same)
|
|
10734
|
+
* const result3 = CairoInt64.__processData('-0x5');
|
|
10735
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
10635
10736
|
* ```
|
|
10636
10737
|
*/
|
|
10637
10738
|
static __processData(data) {
|
|
10739
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
10740
|
+
return -BigInt(data.slice(1));
|
|
10741
|
+
}
|
|
10638
10742
|
if (isString(data) && isText(data)) {
|
|
10639
10743
|
return utf8ToBigInt(data);
|
|
10640
10744
|
}
|
|
@@ -10713,11 +10817,11 @@ ${indent}}` : "}";
|
|
|
10713
10817
|
/**
|
|
10714
10818
|
* Throw unless the value can be carried by an i64.
|
|
10715
10819
|
*
|
|
10716
|
-
*
|
|
10717
|
-
* an array, a number with a decimal part, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
10820
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
10821
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-9223372036854775808, 9223372036854775807]. A text string reaches
|
|
10718
10822
|
* that last check as the number its bytes spell, so `'abcdefghi'` is refused for being out of range.
|
|
10719
10823
|
* @param {BigNumberish | boolean} data the value to check
|
|
10720
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10824
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10721
10825
|
* @example
|
|
10722
10826
|
* ```typescript
|
|
10723
10827
|
* CairoInt64.validate(5000000000); // passes
|
|
@@ -10732,6 +10836,7 @@ ${indent}}` : "}";
|
|
|
10732
10836
|
!isNumber2(data) || Number.isInteger(data),
|
|
10733
10837
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
10734
10838
|
);
|
|
10839
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
10735
10840
|
const value = _CairoInt64.__processData(data);
|
|
10736
10841
|
assert(
|
|
10737
10842
|
value >= RANGE_I64.min && value <= RANGE_I64.max,
|
|
@@ -10822,15 +10927,17 @@ ${indent}}` : "}";
|
|
|
10822
10927
|
/**
|
|
10823
10928
|
* Build from a number, a string or a boolean, refusing anything out of the i128 range.
|
|
10824
10929
|
*
|
|
10825
|
-
* A string is read as a number when it spells one — decimal or hexadecimal
|
|
10826
|
-
* otherwise. Text therefore only fits here up to 16 ASCII
|
|
10827
|
-
* makes a number past 170141183460469231731687303715884105727.
|
|
10930
|
+
* A string is read as a number when it spells one — decimal or hexadecimal, with or without a
|
|
10931
|
+
* leading minus sign — and as UTF-8 text otherwise. Text therefore only fits here up to 16 ASCII
|
|
10932
|
+
* characters : one more already makes a number past 170141183460469231731687303715884105727.
|
|
10828
10933
|
* @param {BigNumberish | boolean} data the value to carry, within [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]
|
|
10829
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
10934
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10830
10935
|
* @example
|
|
10831
10936
|
* ```typescript
|
|
10832
10937
|
* const result = new CairoInt128('abcdefghijklmnop').toApiRequest();
|
|
10833
10938
|
* // result = ["129445976596022050476432668810952994672"]
|
|
10939
|
+
* const result2 = new CairoInt128('-5').toApiRequest();
|
|
10940
|
+
* // result2 = ["3618502788666131213697322783095070105623107215331596699973092056135872020476"]
|
|
10834
10941
|
* ```
|
|
10835
10942
|
*/
|
|
10836
10943
|
constructor(data) {
|
|
@@ -10842,6 +10949,9 @@ ${indent}}` : "}";
|
|
|
10842
10949
|
*
|
|
10843
10950
|
* Nothing here refuses a value : `validate` is what reads this number and decides. So an input
|
|
10844
10951
|
* far outside the i128 range comes back untouched rather than raising.
|
|
10952
|
+
*
|
|
10953
|
+
* A minus sign in front of a number makes it negative rather than text : `'-5'` and `'-0x5'` are
|
|
10954
|
+
* both -5. This holds for the signed integers only — for any other type, such a string is text.
|
|
10845
10955
|
* @param {BigNumberish | boolean} data the value to convert
|
|
10846
10956
|
* @returns {bigint} the number the input spells, of whatever size
|
|
10847
10957
|
* @example
|
|
@@ -10850,9 +10960,14 @@ ${indent}}` : "}";
|
|
|
10850
10960
|
* // result = 129445976596022050476432668810952994672n
|
|
10851
10961
|
* const result2 = CairoInt128.__processData('abcdefghijklmnopq');
|
|
10852
10962
|
* // result2 = 33138170008581644921966763215603966636145n (past the i128 range, and returned all the same)
|
|
10963
|
+
* const result3 = CairoInt128.__processData('-0x5');
|
|
10964
|
+
* // result3 = -5n (a negative number, not the text "-0x5")
|
|
10853
10965
|
* ```
|
|
10854
10966
|
*/
|
|
10855
10967
|
static __processData(data) {
|
|
10968
|
+
if (isString(data) && data.startsWith("-") && isBigNumberish(data.slice(1))) {
|
|
10969
|
+
return -BigInt(data.slice(1));
|
|
10970
|
+
}
|
|
10856
10971
|
if (isString(data) && isText(data)) {
|
|
10857
10972
|
return utf8ToBigInt(data);
|
|
10858
10973
|
}
|
|
@@ -10931,11 +11046,11 @@ ${indent}}` : "}";
|
|
|
10931
11046
|
/**
|
|
10932
11047
|
* Throw unless the value can be carried by an i128.
|
|
10933
11048
|
*
|
|
10934
|
-
*
|
|
10935
|
-
* an array, a number with a decimal part, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
11049
|
+
* Five things are refused, each with its own message : a null or undefined value, an object or
|
|
11050
|
+
* an array, a number with a decimal part, `'0x'`, and a value outside [-170141183460469231731687303715884105728, 170141183460469231731687303715884105727]. A text string reaches
|
|
10936
11051
|
* that last check as the number its bytes spell, so `'abcdefghijklmnopq'` is refused for being out of range.
|
|
10937
11052
|
* @param {BigNumberish | boolean} data the value to check
|
|
10938
|
-
* @throws {Error} when the value is null, undefined, an object, a decimal number, or out of range
|
|
11053
|
+
* @throws {Error} when the value is null, undefined, an object, a decimal number, `'0x'`, or out of range
|
|
10939
11054
|
* @example
|
|
10940
11055
|
* ```typescript
|
|
10941
11056
|
* CairoInt128.validate(5000000000); // passes
|
|
@@ -10950,6 +11065,7 @@ ${indent}}` : "}";
|
|
|
10950
11065
|
!isNumber2(data) || Number.isInteger(data),
|
|
10951
11066
|
"Invalid input: decimal numbers are not supported, only integers"
|
|
10952
11067
|
);
|
|
11068
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
10953
11069
|
const value = _CairoInt128.__processData(data);
|
|
10954
11070
|
assert(
|
|
10955
11071
|
value >= RANGE_I128.min && value <= RANGE_I128.max,
|
|
@@ -11040,7 +11156,7 @@ ${indent}}` : "}";
|
|
|
11040
11156
|
/**
|
|
11041
11157
|
* Build from a boolean, or from the numbers 0 and 1.
|
|
11042
11158
|
* @param {BigNumberish | boolean} data the value to carry : a boolean, 0 or 1
|
|
11043
|
-
* @throws {Error} when the value is text,
|
|
11159
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
11044
11160
|
* @example
|
|
11045
11161
|
* ```typescript
|
|
11046
11162
|
* const result = new CairoBool(false).toApiRequest();
|
|
@@ -11113,21 +11229,28 @@ ${indent}}` : "}";
|
|
|
11113
11229
|
/**
|
|
11114
11230
|
* Throw unless the value can be carried by a bool.
|
|
11115
11231
|
*
|
|
11116
|
-
* Text is refused first, then
|
|
11117
|
-
*
|
|
11118
|
-
*
|
|
11232
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
11233
|
+
* is, so that a negative one reaches the last check. Anything else is read as a felt252 — which
|
|
11234
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked to be
|
|
11235
|
+
* one of the only two numbers a bool can hold.
|
|
11119
11236
|
* @param {BigNumberish | boolean} data the value to check
|
|
11120
|
-
* @throws {Error} when the value is text,
|
|
11237
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or a number other than 0 or 1
|
|
11121
11238
|
* @example
|
|
11122
11239
|
* ```typescript
|
|
11123
11240
|
* CairoBool.validate(true); // passes
|
|
11124
11241
|
* CairoBool.validate(2);
|
|
11125
11242
|
* // throws Error("Only values 0 or 1 are possible in a core::bool, received 2")
|
|
11243
|
+
* CairoBool.validate(-1);
|
|
11244
|
+
* // throws Error("Only values 0 or 1 are possible in a core::bool, received -1")
|
|
11126
11245
|
* ```
|
|
11127
11246
|
*/
|
|
11128
11247
|
static validate(data) {
|
|
11129
11248
|
assert(!isText(data), "Invalid input: a core::bool cannot be built from text");
|
|
11130
|
-
|
|
11249
|
+
assert(
|
|
11250
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
11251
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
11252
|
+
);
|
|
11253
|
+
const value = isNumber2(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
11131
11254
|
assert(
|
|
11132
11255
|
value === 0n || value === 1n,
|
|
11133
11256
|
`Only values 0 or 1 are possible in a core::bool, received ${value}`
|
|
@@ -11242,7 +11365,9 @@ ${indent}}` : "}";
|
|
|
11242
11365
|
/**
|
|
11243
11366
|
* @param {any[]} arr either one value — a 512-bit number or a {@link Secp256k1PointStruct} — or
|
|
11244
11367
|
* the four limbs
|
|
11245
|
-
* @throws {Error} when a value is
|
|
11368
|
+
* @throws {Error} when a value is null, undefined, of an unread type, text, a decimal number, or out
|
|
11369
|
+
* of range — see {@link CairoSecp256k1Point.validate} and {@link CairoSecp256k1Point.validateProps}
|
|
11370
|
+
* — or when the argument count is neither 1 nor 4
|
|
11246
11371
|
* @example
|
|
11247
11372
|
* ```typescript
|
|
11248
11373
|
* const result = new CairoSecp256k1Point(1n).toApiRequest();
|
|
@@ -11289,22 +11414,32 @@ ${indent}}` : "}";
|
|
|
11289
11414
|
* the constructor needs it, and computing it twice would mean splitting a 512-bit value twice.
|
|
11290
11415
|
* @param {BigNumberish} input the 512-bit value to check
|
|
11291
11416
|
* @returns {bigint} the value, once checked
|
|
11292
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, 2^512 - 1]
|
|
11417
|
+
* @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or outside [0, 2^512 - 1]
|
|
11293
11418
|
* @example
|
|
11294
11419
|
* ```typescript
|
|
11295
11420
|
* const result = CairoSecp256k1Point.validate('0x1234');
|
|
11296
11421
|
* // result = 4660n
|
|
11297
11422
|
* CairoSecp256k1Point.validate(SECP256K1_POINT_MAX + 1n);
|
|
11298
11423
|
* // throws Error("input is bigger than SECP256K1_POINT_MAX")
|
|
11424
|
+
* CairoSecp256k1Point.validate('abc');
|
|
11425
|
+
* // throws Error("Invalid input: a Secp256k1Point cannot be built from text")
|
|
11426
|
+
* CairoSecp256k1Point.validate(1.5);
|
|
11427
|
+
* // throws Error("Invalid input: decimal numbers are not supported, only integers")
|
|
11299
11428
|
* ```
|
|
11300
11429
|
*/
|
|
11301
11430
|
static validate(input) {
|
|
11302
11431
|
assert(input !== null, "null value is not allowed for Secp256k1Point");
|
|
11303
11432
|
assert(input !== void 0, "undefined value is not allowed for Secp256k1Point");
|
|
11433
|
+
assert(!isText(input), "Invalid input: a Secp256k1Point cannot be built from text");
|
|
11434
|
+
assert(!isEmptyHex(input), "Invalid input: '0x' holds no hexadecimal digit");
|
|
11304
11435
|
assert(
|
|
11305
11436
|
isBigNumberish(input),
|
|
11306
11437
|
`Unsupported input for Secp256k1Point. Expected a number, a bigint, or a string spelling one, received '${typeof input}'`
|
|
11307
11438
|
);
|
|
11439
|
+
assert(
|
|
11440
|
+
!isNumber2(input) || Number.isInteger(input),
|
|
11441
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
11442
|
+
);
|
|
11308
11443
|
const bigInt = BigInt(input);
|
|
11309
11444
|
assert(bigInt >= SECP256K1_POINT_MIN, "input is smaller than SECP256K1_POINT_MIN");
|
|
11310
11445
|
assert(bigInt <= SECP256K1_POINT_MAX, "input is bigger than SECP256K1_POINT_MAX");
|
|
@@ -11317,20 +11452,27 @@ ${indent}}` : "}";
|
|
|
11317
11452
|
* @param {BigNumberish} yLow the low 128 bits of y
|
|
11318
11453
|
* @param {BigNumberish} yHigh the high 128 bits of y
|
|
11319
11454
|
* @returns {{xLow: bigint, xHigh: bigint, yLow: bigint, yHigh: bigint}} the four limbs, checked
|
|
11320
|
-
* @throws {Error} when a limb is null, undefined, not a number, negative, or wider than 128 bits
|
|
11455
|
+
* @throws {Error} when a limb is null, undefined, text, `'0x'`, not a number, a decimal number, negative, or wider than 128 bits
|
|
11321
11456
|
* @example
|
|
11322
11457
|
* ```typescript
|
|
11323
11458
|
* const result = CairoSecp256k1Point.validateProps(1, 2, 3, 4);
|
|
11324
11459
|
* // result = { xLow: 1n, xHigh: 2n, yLow: 3n, yHigh: 4n }
|
|
11325
11460
|
* CairoSecp256k1Point.validateProps(1, 2, 3, 2n ** 128n);
|
|
11326
11461
|
* // throws Error("yHigh must fit in 128 bits")
|
|
11462
|
+
* CairoSecp256k1Point.validateProps(1.5, 2, 3, 4);
|
|
11463
|
+
* // throws Error("xLow must be an integer")
|
|
11464
|
+
* CairoSecp256k1Point.validateProps('abc', 2, 3, 4);
|
|
11465
|
+
* // throws Error("xLow cannot be built from text")
|
|
11327
11466
|
* ```
|
|
11328
11467
|
*/
|
|
11329
11468
|
static validateProps(xLow, xHigh, yLow, yHigh) {
|
|
11330
11469
|
const validateLimb = (limb, name) => {
|
|
11331
11470
|
assert(limb !== null, `${name} cannot be null`);
|
|
11332
11471
|
assert(limb !== void 0, `${name} cannot be undefined`);
|
|
11472
|
+
assert(!isText(limb), `${name} cannot be built from text`);
|
|
11473
|
+
assert(!isEmptyHex(limb), `${name} cannot be '0x', which holds no hexadecimal digit`);
|
|
11333
11474
|
assert(isBigNumberish(limb), `${name} must be a BigNumberish`);
|
|
11475
|
+
assert(!isNumber2(limb) || Number.isInteger(limb), `${name} must be an integer`);
|
|
11334
11476
|
const bigInt = BigInt(limb);
|
|
11335
11477
|
assert(bigInt >= 0n, `${name} must be non-negative`);
|
|
11336
11478
|
assert(bigInt <= UINT_128_MAX, `${name} must fit in 128 bits`);
|
|
@@ -12473,9 +12615,9 @@ ${indent}}` : "}";
|
|
|
12473
12615
|
*/
|
|
12474
12616
|
static abiSelector = Literal.ClassHash;
|
|
12475
12617
|
/**
|
|
12476
|
-
* Build from a number or a numeric string, refusing text and anything
|
|
12477
|
-
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^
|
|
12478
|
-
* @throws {Error} when the value is text,
|
|
12618
|
+
* Build from a number or a numeric string, refusing text and anything outside the ClassHash range.
|
|
12619
|
+
* @param {BigNumberish | boolean} data the hash to carry, within [0, 2^251 - 1]
|
|
12620
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
12479
12621
|
* @example
|
|
12480
12622
|
* ```typescript
|
|
12481
12623
|
* const result = new CairoClassHash('0x1234').toApiRequest();
|
|
@@ -12530,21 +12672,34 @@ ${indent}}` : "}";
|
|
|
12530
12672
|
/**
|
|
12531
12673
|
* Throw unless the value can be carried by a ClassHash.
|
|
12532
12674
|
*
|
|
12533
|
-
* Text is refused first, then
|
|
12534
|
-
*
|
|
12535
|
-
* a
|
|
12675
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
12676
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
12677
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
12678
|
+
* the range of the Cairo `ClassHash` type, [0, 2^251), which is narrower than the field.
|
|
12536
12679
|
* @param {BigNumberish | boolean} data the value to check
|
|
12537
|
-
* @throws {Error} when the value is text,
|
|
12680
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the ClassHash range
|
|
12538
12681
|
* @example
|
|
12539
12682
|
* ```typescript
|
|
12540
12683
|
* CairoClassHash.validate('0x1234'); // passes
|
|
12541
12684
|
* CairoClassHash.validate('abc');
|
|
12542
12685
|
* // throws Error("Invalid input: a ClassHash cannot be built from text")
|
|
12686
|
+
* CairoClassHash.validate(2n ** 251n);
|
|
12687
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
12688
|
+
* CairoClassHash.validate(-1);
|
|
12689
|
+
* // throws Error("Value is out of ClassHash range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
|
|
12543
12690
|
* ```
|
|
12544
12691
|
*/
|
|
12545
12692
|
static validate(data) {
|
|
12546
12693
|
assert(!isText(data), "Invalid input: a ClassHash cannot be built from text");
|
|
12547
|
-
|
|
12694
|
+
assert(
|
|
12695
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
12696
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
12697
|
+
);
|
|
12698
|
+
const value = isNumber2(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
12699
|
+
assert(
|
|
12700
|
+
value >= RANGE_CLASS_HASH.min && value <= RANGE_CLASS_HASH.max,
|
|
12701
|
+
`Value is out of ClassHash range [${RANGE_CLASS_HASH.min}, ${RANGE_CLASS_HASH.max}]`
|
|
12702
|
+
);
|
|
12548
12703
|
}
|
|
12549
12704
|
/**
|
|
12550
12705
|
* Can this value be carried by a ClassHash?
|
|
@@ -12623,7 +12778,7 @@ ${indent}}` : "}";
|
|
|
12623
12778
|
/**
|
|
12624
12779
|
* Build from a number or a numeric string, refusing text and anything wider than 252 bits.
|
|
12625
12780
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^252 - 1]
|
|
12626
|
-
* @throws {Error} when the value is text,
|
|
12781
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
12627
12782
|
* @example
|
|
12628
12783
|
* ```typescript
|
|
12629
12784
|
* const result = new CairoContractAddress('0x1234').toApiRequest();
|
|
@@ -12678,11 +12833,12 @@ ${indent}}` : "}";
|
|
|
12678
12833
|
/**
|
|
12679
12834
|
* Throw unless the value can be carried by a ContractAddress.
|
|
12680
12835
|
*
|
|
12681
|
-
* Text is refused first, then
|
|
12682
|
-
*
|
|
12683
|
-
* is
|
|
12836
|
+
* Text is refused first, then a number with a decimal part. A number or a bigint is read as it
|
|
12837
|
+
* is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
|
|
12838
|
+
* is what refuses a null, an object or an unsupported type. The value is finally checked against
|
|
12839
|
+
* the bound an address has, which is narrower than the field.
|
|
12684
12840
|
* @param {BigNumberish | boolean} data the value to check
|
|
12685
|
-
* @throws {Error} when the value is text,
|
|
12841
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of range
|
|
12686
12842
|
* @example
|
|
12687
12843
|
* ```typescript
|
|
12688
12844
|
* CairoContractAddress.validate('0x1234'); // passes
|
|
@@ -12690,11 +12846,17 @@ ${indent}}` : "}";
|
|
|
12690
12846
|
* // throws Error("Invalid input: a ContractAddress cannot be built from text")
|
|
12691
12847
|
* CairoContractAddress.validate(2n ** 251n);
|
|
12692
12848
|
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
12849
|
+
* CairoContractAddress.validate(-1);
|
|
12850
|
+
* // throws Error("Value is out of ContractAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285300991]")
|
|
12693
12851
|
* ```
|
|
12694
12852
|
*/
|
|
12695
12853
|
static validate(data) {
|
|
12696
12854
|
assert(!isText(data), "Invalid input: a ContractAddress cannot be built from text");
|
|
12697
|
-
|
|
12855
|
+
assert(
|
|
12856
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
12857
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
12858
|
+
);
|
|
12859
|
+
const value = isNumber2(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
12698
12860
|
assert(
|
|
12699
12861
|
value >= RANGE_CONTRACT_ADDRESS.min && value <= RANGE_CONTRACT_ADDRESS.max,
|
|
12700
12862
|
`Value is out of ContractAddress range [${RANGE_CONTRACT_ADDRESS.min}, ${RANGE_CONTRACT_ADDRESS.max}]`
|
|
@@ -12779,7 +12941,7 @@ ${indent}}` : "}";
|
|
|
12779
12941
|
/**
|
|
12780
12942
|
* Build from a number or a numeric string, refusing text and anything wider than 160 bits.
|
|
12781
12943
|
* @param {BigNumberish | boolean} data the address to carry, within [0, 2^160 - 1]
|
|
12782
|
-
* @throws {Error} when the value is text,
|
|
12944
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
12783
12945
|
* @example
|
|
12784
12946
|
* ```typescript
|
|
12785
12947
|
* const result = new CairoEthAddress('0x1234').toApiRequest();
|
|
@@ -12835,10 +12997,12 @@ ${indent}}` : "}";
|
|
|
12835
12997
|
* Throw unless the value can be carried by an EthAddress.
|
|
12836
12998
|
*
|
|
12837
12999
|
* Text is refused first, since an address spelled as words is a mistake rather than a value to
|
|
12838
|
-
* encode
|
|
12839
|
-
*
|
|
13000
|
+
* encode, then a number with a decimal part. A number or a bigint is read as it is, so that a
|
|
13001
|
+
* negative one reaches the range check below. Anything else is read as a felt252 — which is what
|
|
13002
|
+
* refuses a null, an object or an unsupported type. The value is finally checked against the 160
|
|
13003
|
+
* bits an Ethereum address occupies.
|
|
12840
13004
|
* @param {BigNumberish | boolean} data the value to check
|
|
12841
|
-
* @throws {Error} when the value is text,
|
|
13005
|
+
* @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the EthAddress range
|
|
12842
13006
|
* @example
|
|
12843
13007
|
* ```typescript
|
|
12844
13008
|
* CairoEthAddress.validate('0x1234'); // passes
|
|
@@ -12846,11 +13010,17 @@ ${indent}}` : "}";
|
|
|
12846
13010
|
* // throws Error("Invalid input: an EthAddress cannot be built from text")
|
|
12847
13011
|
* CairoEthAddress.validate(2n ** 160n);
|
|
12848
13012
|
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
13013
|
+
* CairoEthAddress.validate(-1);
|
|
13014
|
+
* // throws Error("Value is out of EthAddress range [0, 1461501637330902918203684832716283019655932542975]")
|
|
12849
13015
|
* ```
|
|
12850
13016
|
*/
|
|
12851
13017
|
static validate(data) {
|
|
12852
13018
|
assert(!isText(data), "Invalid input: an EthAddress cannot be built from text");
|
|
12853
|
-
|
|
13019
|
+
assert(
|
|
13020
|
+
!isNumber2(data) || Number.isInteger(data),
|
|
13021
|
+
"Invalid input: decimal numbers are not supported, only integers"
|
|
13022
|
+
);
|
|
13023
|
+
const value = isNumber2(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
|
|
12854
13024
|
assert(
|
|
12855
13025
|
value >= RANGE_ETH_ADDRESS.min && value <= RANGE_ETH_ADDRESS.max,
|
|
12856
13026
|
`Value is out of EthAddress range [${RANGE_ETH_ADDRESS.min}, ${RANGE_ETH_ADDRESS.max}]`
|
|
@@ -13525,7 +13695,13 @@ ${indent}}` : "}";
|
|
|
13525
13695
|
* Build an option, from a value a caller passed or from the felts of a response.
|
|
13526
13696
|
*
|
|
13527
13697
|
* A {@link CairoOption} says its own branch, so `variant` is not given with one — nor with the
|
|
13528
|
-
* response iterator, which reads the branch off the wire
|
|
13698
|
+
* response iterator, which reads the branch off the wire, nor with a `CairoTypeOption`, which
|
|
13699
|
+
* is copied as it is. Anywhere else it is required.
|
|
13700
|
+
*
|
|
13701
|
+
* For the same reason, a `CairoOption` that holds a `CairoTypeOption` is refused: once it is
|
|
13702
|
+
* unwrapped, the variant comes with the `CairoTypeOption`. Accepted, it would lose one level:
|
|
13703
|
+
* `Some(Some(1))` would be sent as `Some(None)`. Write a nested value with `CairoOption`
|
|
13704
|
+
* only, or build one `CairoTypeOption` for the whole type.
|
|
13529
13705
|
*
|
|
13530
13706
|
* `subType` is what makes an option of options work. Handed a `CairoOption`, this constructor
|
|
13531
13707
|
* unwraps it and calls itself with what was inside, which for a nested option is another
|
|
@@ -13536,11 +13712,11 @@ ${indent}}` : "}";
|
|
|
13536
13712
|
* @param {string} optionCairoType the abi type, `core::option::Option::<T>`
|
|
13537
13713
|
* @param {AllowArray<CairoTypeStrategy>} parsingStrategy how to build the value
|
|
13538
13714
|
* @param {CairoOptionVariant | number} [variant] which branch, when the content does not say.
|
|
13539
|
-
* Must be omitted when `content` is the response iterator
|
|
13715
|
+
* Must be omitted when `content` is the response iterator or a `CairoTypeOption`.
|
|
13540
13716
|
* @param {boolean} [subType=false] true when called from the unwrapping of a nested
|
|
13541
13717
|
* `CairoOption`, which is the only caller that should set it
|
|
13542
|
-
* @throws {Error} when the type is not an option, when the variant is missing, absurd,
|
|
13543
|
-
* contradicts the content
|
|
13718
|
+
* @throws {Error} when the type is not an option, or when the variant is missing, absurd,
|
|
13719
|
+
* contradicts the content, or is given with a `CairoTypeOption`
|
|
13544
13720
|
* @example
|
|
13545
13721
|
* ```typescript
|
|
13546
13722
|
* const type = 'core::option::Option::<core::integer::u8>';
|
|
@@ -13585,6 +13761,10 @@ ${indent}}` : "}";
|
|
|
13585
13761
|
return;
|
|
13586
13762
|
}
|
|
13587
13763
|
if (content instanceof _CairoTypeOption) {
|
|
13764
|
+
assert(
|
|
13765
|
+
isUndefined(variant),
|
|
13766
|
+
'when "content" parameter is a CairoTypeOption, do not define "variant" parameter.'
|
|
13767
|
+
);
|
|
13588
13768
|
this.content = content.content;
|
|
13589
13769
|
this.isVariantSome = content.isVariantSome;
|
|
13590
13770
|
this.optionCairoType = content.optionCairoType;
|
|
@@ -16046,11 +16226,17 @@ ${indent}}` : "}";
|
|
|
16046
16226
|
`Your object includes the property : ${key}, containing an Uint512 object without the 'limb0' to 'limb3' keys.`
|
|
16047
16227
|
);
|
|
16048
16228
|
}
|
|
16229
|
+
function getVariantType(abiEnum, variantName) {
|
|
16230
|
+
return abiEnum.variants?.find((abiVariant) => abiVariant.name === variantName)?.type ?? "";
|
|
16231
|
+
}
|
|
16049
16232
|
function orderPropsByAbi(unorderedObject, abiOfObject, structs, enums) {
|
|
16050
16233
|
const orderInput = (unorderedItem, abiType) => {
|
|
16051
16234
|
if (CairoFixedArray.isTypeFixedArray(abiType)) {
|
|
16052
16235
|
return orderFixedArray(unorderedItem, abiType);
|
|
16053
16236
|
}
|
|
16237
|
+
if (isCairoType(unorderedItem)) {
|
|
16238
|
+
return unorderedItem;
|
|
16239
|
+
}
|
|
16054
16240
|
if (isTypeArray(abiType)) {
|
|
16055
16241
|
return orderArray(unorderedItem, abiType);
|
|
16056
16242
|
}
|
|
@@ -16163,14 +16349,8 @@ ${indent}}` : "}";
|
|
|
16163
16349
|
const orderEnum = (unorderedObject2, abiObject) => {
|
|
16164
16350
|
if (isTypeResult(abiObject.name)) {
|
|
16165
16351
|
const unorderedResult = unorderedObject2;
|
|
16166
|
-
const resultOkType = abiObject
|
|
16167
|
-
|
|
16168
|
-
abiObject.name.lastIndexOf(",")
|
|
16169
|
-
);
|
|
16170
|
-
const resultErrType = abiObject.name.substring(
|
|
16171
|
-
abiObject.name.indexOf(",") + 1,
|
|
16172
|
-
abiObject.name.lastIndexOf(">")
|
|
16173
|
-
);
|
|
16352
|
+
const resultOkType = getVariantType(abiObject, "Ok");
|
|
16353
|
+
const resultErrType = getVariantType(abiObject, "Err");
|
|
16174
16354
|
if (unorderedResult.isOk()) {
|
|
16175
16355
|
return new CairoResult(
|
|
16176
16356
|
CairoResultVariant.Ok,
|
|
@@ -16184,10 +16364,7 @@ ${indent}}` : "}";
|
|
|
16184
16364
|
}
|
|
16185
16365
|
if (isTypeOption(abiObject.name)) {
|
|
16186
16366
|
const unorderedOption = unorderedObject2;
|
|
16187
|
-
const resultSomeType = abiObject
|
|
16188
|
-
abiObject.name.indexOf("<") + 1,
|
|
16189
|
-
abiObject.name.lastIndexOf(">")
|
|
16190
|
-
);
|
|
16367
|
+
const resultSomeType = getVariantType(abiObject, "Some");
|
|
16191
16368
|
if (unorderedOption.isSome()) {
|
|
16192
16369
|
return new CairoOption(
|
|
16193
16370
|
CairoOptionVariant.Some,
|
|
@@ -16202,10 +16379,7 @@ ${indent}}` : "}";
|
|
|
16202
16379
|
if (isUndefined(variant[1])) {
|
|
16203
16380
|
return variant;
|
|
16204
16381
|
}
|
|
16205
|
-
const variantType = abiObject
|
|
16206
|
-
abiObject.type.lastIndexOf("<") + 1,
|
|
16207
|
-
abiObject.type.lastIndexOf(">")
|
|
16208
|
-
);
|
|
16382
|
+
const variantType = getVariantType(abiObject, variant[0]);
|
|
16209
16383
|
if (variantType === "()") {
|
|
16210
16384
|
return variant;
|
|
16211
16385
|
}
|
|
@@ -19097,7 +19271,7 @@ ${indent}}` : "}";
|
|
|
19097
19271
|
return sanitizeHex(buf2hex(secp256k1.utils.randomSecretKey()));
|
|
19098
19272
|
}
|
|
19099
19273
|
function validateAndParseEthAddress(address) {
|
|
19100
|
-
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address
|
|
19274
|
+
assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address");
|
|
19101
19275
|
const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
|
|
19102
19276
|
assert(Boolean(result.match(/^(0x)?[0-9a-f]{40}$/)), "Invalid Ethereum Address Format");
|
|
19103
19277
|
return result;
|
|
@@ -23329,6 +23503,9 @@ ${indent}}` : "}";
|
|
|
23329
23503
|
return addHexPrefix(padded);
|
|
23330
23504
|
}
|
|
23331
23505
|
function validateAndParseAddress(address) {
|
|
23506
|
+
if (isString(address) && !/^(0x)?[0-9a-f]+$/i.test(address)) {
|
|
23507
|
+
throw new Error("Invalid Address Format");
|
|
23508
|
+
}
|
|
23332
23509
|
const result = addAddressPadding(address);
|
|
23333
23510
|
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
23334
23511
|
throw new Error("Invalid Address Format");
|