starknet 11.10.4 → 11.10.6
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 +67 -61
- package/dist/index.global.js +418 -426
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +435 -443
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +435 -443
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.global.js
CHANGED
|
@@ -3295,6 +3295,250 @@ ${indent}}` : "}";
|
|
|
3295
3295
|
V2: "2"
|
|
3296
3296
|
};
|
|
3297
3297
|
|
|
3298
|
+
// src/utils/helpers.ts
|
|
3299
|
+
function addCompiledFlag(compiled) {
|
|
3300
|
+
Object.defineProperty(compiled, "__compiled__", {
|
|
3301
|
+
enumerable: false,
|
|
3302
|
+
writable: false,
|
|
3303
|
+
value: true
|
|
3304
|
+
});
|
|
3305
|
+
return compiled;
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
// src/utils/cairoDataTypes/felt.ts
|
|
3309
|
+
var CairoFelt252 = class _CairoFelt252 {
|
|
3310
|
+
/**
|
|
3311
|
+
* The bytes of the value, big-endian and without leading zeros.
|
|
3312
|
+
*
|
|
3313
|
+
* The length is that of the value, not a fixed width : a felt252 holding 0 is one byte, and one
|
|
3314
|
+
* holding `'Hello'` is five. Nothing here records how wide the input was written.
|
|
3315
|
+
* @example
|
|
3316
|
+
* ```typescript
|
|
3317
|
+
* const result = new CairoFelt252('Hello').data.length;
|
|
3318
|
+
* // result = 5
|
|
3319
|
+
* const result2 = new CairoFelt252(0).data.length;
|
|
3320
|
+
* // result2 = 1 (the single byte 0x00)
|
|
3321
|
+
* ```
|
|
3322
|
+
*/
|
|
3323
|
+
data;
|
|
3324
|
+
/**
|
|
3325
|
+
* The abi type this class serializes.
|
|
3326
|
+
* @example
|
|
3327
|
+
* ```typescript
|
|
3328
|
+
* const result = CairoFelt252.abiSelector;
|
|
3329
|
+
* // result = "core::felt252"
|
|
3330
|
+
* ```
|
|
3331
|
+
*/
|
|
3332
|
+
static abiSelector = "core::felt252";
|
|
3333
|
+
/**
|
|
3334
|
+
* Build from a number, a string or a boolean, refusing anything outside [0, P).
|
|
3335
|
+
*
|
|
3336
|
+
* The bytes are stored without their leading zeros, so `'0x0041'` and `'0x41'` give the same
|
|
3337
|
+
* felt252. A boolean is carried as 1 or 0.
|
|
3338
|
+
* @param {BigNumberish | boolean} data the value to carry, within [0, P)
|
|
3339
|
+
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, P)
|
|
3340
|
+
* @example
|
|
3341
|
+
* ```typescript
|
|
3342
|
+
* const result = new CairoFelt252('Hello').toApiRequest();
|
|
3343
|
+
* // result = ["310939249775"]
|
|
3344
|
+
* ```
|
|
3345
|
+
*/
|
|
3346
|
+
constructor(data) {
|
|
3347
|
+
_CairoFelt252.validate(data);
|
|
3348
|
+
const processedData = _CairoFelt252.__processData(data);
|
|
3349
|
+
this.data = processedData.subarray(processedData.findIndex((x) => x > 0));
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3352
|
+
* Turn an accepted input into its bytes, before the constructor strips their leading zeros.
|
|
3353
|
+
*
|
|
3354
|
+
* The range is not checked here : `validate` is what reads these bytes and decides. Only the
|
|
3355
|
+
* type is, and an input this class does not read raises rather than coming back.
|
|
3356
|
+
* @param {BigNumberish | boolean} data the value to convert
|
|
3357
|
+
* @returns {Uint8Array} the bytes of the value, of whatever length it implies
|
|
3358
|
+
* @throws {Error} when the input is neither a string, an integer, a bigint nor a boolean
|
|
3359
|
+
* @example
|
|
3360
|
+
* ```typescript
|
|
3361
|
+
* const result = CairoFelt252.__processData('Hello').length;
|
|
3362
|
+
* // result = 5
|
|
3363
|
+
* CairoFelt252.__processData(1.5);
|
|
3364
|
+
* // throws Error("1.5 can't be computed by felt()")
|
|
3365
|
+
* ```
|
|
3366
|
+
*/
|
|
3367
|
+
static __processData(data) {
|
|
3368
|
+
if (isString(data)) {
|
|
3369
|
+
return stringToUint8Array(data);
|
|
3370
|
+
}
|
|
3371
|
+
if (isBigInt(data)) {
|
|
3372
|
+
return bigIntToUint8Array(data);
|
|
3373
|
+
}
|
|
3374
|
+
if (Number.isInteger(data)) {
|
|
3375
|
+
return bigIntToUint8Array(BigInt(data));
|
|
3376
|
+
}
|
|
3377
|
+
if (isBoolean(data)) {
|
|
3378
|
+
return bigIntToUint8Array(BigInt(data ? 1 : 0));
|
|
3379
|
+
}
|
|
3380
|
+
throw new Error(`${data} can't be computed by felt()`);
|
|
3381
|
+
}
|
|
3382
|
+
/**
|
|
3383
|
+
* The bytes read as one big-endian number.
|
|
3384
|
+
* @returns {bigint} the value this felt252 holds
|
|
3385
|
+
* @example
|
|
3386
|
+
* ```typescript
|
|
3387
|
+
* const result = new CairoFelt252('Hello').toBigInt();
|
|
3388
|
+
* // result = 310939249775n
|
|
3389
|
+
* ```
|
|
3390
|
+
*/
|
|
3391
|
+
toBigInt() {
|
|
3392
|
+
return uint8ArrayToBigInt(this.data);
|
|
3393
|
+
}
|
|
3394
|
+
/**
|
|
3395
|
+
* Read the bytes back as UTF-8 text.
|
|
3396
|
+
*
|
|
3397
|
+
* Only a value that was text to begin with comes back as readable text : the bytes of a number
|
|
3398
|
+
* are decoded all the same, and what they spell is rarely what was meant.
|
|
3399
|
+
* @returns {string} the bytes decoded as UTF-8
|
|
3400
|
+
* @example
|
|
3401
|
+
* ```typescript
|
|
3402
|
+
* const result = new CairoFelt252('Hello').decodeUtf8();
|
|
3403
|
+
* // result = "Hello"
|
|
3404
|
+
* const result2 = new CairoFelt252('12345').decodeUtf8();
|
|
3405
|
+
* // result2 = "09" (the number 12345 is the two bytes 0x30 0x39)
|
|
3406
|
+
* ```
|
|
3407
|
+
*/
|
|
3408
|
+
decodeUtf8() {
|
|
3409
|
+
return new TextDecoder().decode(this.data);
|
|
3410
|
+
}
|
|
3411
|
+
/**
|
|
3412
|
+
* The value in hexadecimal, without padding.
|
|
3413
|
+
* @returns {string} the value as a 0x-prefixed hex string
|
|
3414
|
+
* @example
|
|
3415
|
+
* ```typescript
|
|
3416
|
+
* const result = new CairoFelt252('Hello').toHexString();
|
|
3417
|
+
* // result = "0x48656c6c6f"
|
|
3418
|
+
* const result2 = new CairoFelt252(0).toHexString();
|
|
3419
|
+
* // result2 = "0x0" (one digit, not "0x00")
|
|
3420
|
+
* ```
|
|
3421
|
+
*/
|
|
3422
|
+
toHexString() {
|
|
3423
|
+
return addHexPrefix(this.toBigInt().toString(16));
|
|
3424
|
+
}
|
|
3425
|
+
/**
|
|
3426
|
+
* Serialize to the single felt a contract call carries.
|
|
3427
|
+
* @returns {string[]} one decimal-string felt, flagged as compiled
|
|
3428
|
+
* @example
|
|
3429
|
+
* ```typescript
|
|
3430
|
+
* const result = new CairoFelt252('Hello').toApiRequest();
|
|
3431
|
+
* // result = ["310939249775"]
|
|
3432
|
+
* ```
|
|
3433
|
+
*/
|
|
3434
|
+
toApiRequest() {
|
|
3435
|
+
return addCompiledFlag([BigInt(this.toHexString()).toString()]);
|
|
3436
|
+
}
|
|
3437
|
+
/**
|
|
3438
|
+
* Throw unless a number falls in the felt252 range [0, P).
|
|
3439
|
+
*
|
|
3440
|
+
* This takes the number itself, where {@link CairoFelt252.validate} takes whatever a caller
|
|
3441
|
+
* hands over. P is excluded : the largest felt252 is P - 1.
|
|
3442
|
+
* @param {bigint} val the number to check
|
|
3443
|
+
* @throws {Error} when the number is negative or greater than or equal to P
|
|
3444
|
+
* @example
|
|
3445
|
+
* ```typescript
|
|
3446
|
+
* CairoFelt252.assertRange(0n); // passes
|
|
3447
|
+
* CairoFelt252.assertRange(-1n);
|
|
3448
|
+
* // throws Error("Value -1 is out of felt252 range [0, 3618502788666131213697322783095070105623107215331596699973092056135872020481)")
|
|
3449
|
+
* ```
|
|
3450
|
+
*/
|
|
3451
|
+
static assertRange(val) {
|
|
3452
|
+
assert(val >= 0n && val < PRIME, `Value ${val} is out of felt252 range [0, ${PRIME})`);
|
|
3453
|
+
}
|
|
3454
|
+
/**
|
|
3455
|
+
* Throw unless the value can be carried by a felt252.
|
|
3456
|
+
*
|
|
3457
|
+
* Null, undefined, any type this class does not read, and `'0x'` are refused first, each with its
|
|
3458
|
+
* own message, then the value is converted and its range checked. A negative number does not
|
|
3459
|
+
* reach that range check : converting it fails earlier, and the message comes from the conversion.
|
|
3460
|
+
* @param {BigNumberish | boolean} data the value to check
|
|
3461
|
+
* @throws {Error} when the value is null, undefined, of an unread type, `'0x'`, or outside [0, P)
|
|
3462
|
+
* @example
|
|
3463
|
+
* ```typescript
|
|
3464
|
+
* CairoFelt252.validate('Hello'); // passes
|
|
3465
|
+
* CairoFelt252.validate({});
|
|
3466
|
+
* // throws Error("Unsupported data type 'object' for felt252. Expected string, number, bigint, or boolean")
|
|
3467
|
+
* CairoFelt252.validate('0x');
|
|
3468
|
+
* // throws Error("Invalid input: '0x' holds no hexadecimal digit")
|
|
3469
|
+
* CairoFelt252.validate(-1);
|
|
3470
|
+
* // throws Error("Cannot convert negative bigint -1 to Uint8Array")
|
|
3471
|
+
* ```
|
|
3472
|
+
*/
|
|
3473
|
+
static validate(data) {
|
|
3474
|
+
assert(data !== null, "null value is not allowed for felt252");
|
|
3475
|
+
assert(data !== void 0, "undefined value is not allowed for felt252");
|
|
3476
|
+
assert(
|
|
3477
|
+
isString(data) || isNumber2(data) || isBigInt(data) || isBoolean(data),
|
|
3478
|
+
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
3479
|
+
);
|
|
3480
|
+
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
3481
|
+
const value = _CairoFelt252.__processData(data);
|
|
3482
|
+
const bn = uint8ArrayToBigInt(value);
|
|
3483
|
+
_CairoFelt252.assertRange(bn);
|
|
3484
|
+
}
|
|
3485
|
+
/**
|
|
3486
|
+
* Can this value be carried by a felt252?
|
|
3487
|
+
*
|
|
3488
|
+
* The non-throwing form of {@link CairoFelt252.validate}, so it answers false for every input
|
|
3489
|
+
* that one refuses, whatever the reason.
|
|
3490
|
+
* @param {BigNumberish | boolean} data the value to test
|
|
3491
|
+
* @returns {boolean} true when the value fits in a felt252
|
|
3492
|
+
* @example
|
|
3493
|
+
* ```typescript
|
|
3494
|
+
* const result = CairoFelt252.is('Hello');
|
|
3495
|
+
* // result = true
|
|
3496
|
+
* const result2 = CairoFelt252.is(-1);
|
|
3497
|
+
* // result2 = false
|
|
3498
|
+
* ```
|
|
3499
|
+
*/
|
|
3500
|
+
static is(data) {
|
|
3501
|
+
try {
|
|
3502
|
+
_CairoFelt252.validate(data);
|
|
3503
|
+
return true;
|
|
3504
|
+
} catch {
|
|
3505
|
+
return false;
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
/**
|
|
3509
|
+
* Is this abi type the one this class serializes?
|
|
3510
|
+
* @param {string} abiType the abi type to test
|
|
3511
|
+
* @returns {boolean} true for `core::felt252`
|
|
3512
|
+
* @example
|
|
3513
|
+
* ```typescript
|
|
3514
|
+
* const result = CairoFelt252.isAbiType('core::felt252');
|
|
3515
|
+
* // result = true
|
|
3516
|
+
* const result2 = CairoFelt252.isAbiType('core::integer::u8');
|
|
3517
|
+
* // result2 = false
|
|
3518
|
+
* ```
|
|
3519
|
+
*/
|
|
3520
|
+
static isAbiType(abiType) {
|
|
3521
|
+
return abiType === _CairoFelt252.abiSelector;
|
|
3522
|
+
}
|
|
3523
|
+
/**
|
|
3524
|
+
* Read one felt252 off a contract response, advancing the iterator past it.
|
|
3525
|
+
*
|
|
3526
|
+
* The felts a node returns are hex strings, and one is consumed per call, so successive calls
|
|
3527
|
+
* read successive return values.
|
|
3528
|
+
* @param {Iterator<string>} responseIterator the response felts, positioned on this felt252
|
|
3529
|
+
* @returns {CairoFelt252} the felt252 that was read
|
|
3530
|
+
* @example
|
|
3531
|
+
* ```typescript
|
|
3532
|
+
* const response = ['0x48656c6c6f'];
|
|
3533
|
+
* const result = CairoFelt252.factoryFromApiResponse(response.values()).decodeUtf8();
|
|
3534
|
+
* // result = "Hello"
|
|
3535
|
+
* ```
|
|
3536
|
+
*/
|
|
3537
|
+
static factoryFromApiResponse(responseIterator) {
|
|
3538
|
+
return new _CairoFelt252(getNext(responseIterator));
|
|
3539
|
+
}
|
|
3540
|
+
};
|
|
3541
|
+
|
|
3298
3542
|
// src/utils/hash/index.ts
|
|
3299
3543
|
var hash_exports = {};
|
|
3300
3544
|
__export(hash_exports, {
|
|
@@ -7172,372 +7416,128 @@ ${indent}}` : "}";
|
|
|
7172
7416
|
const word3 = feltView.getUint32(12, false);
|
|
7173
7417
|
const word4 = feltView.getUint32(16, false);
|
|
7174
7418
|
const word5 = feltView.getUint32(20, false);
|
|
7175
|
-
const word6 = feltView.getUint32(24, false);
|
|
7176
|
-
const word7 = feltView.getUint32(28, false);
|
|
7177
|
-
u32Words.push(word0, word1, word2, word3, word4, word5, word6, word7);
|
|
7178
|
-
}
|
|
7179
|
-
}
|
|
7180
|
-
const bytes = new ArrayBuffer(u32Words.length * 4);
|
|
7181
|
-
const bytesView = new DataView(bytes);
|
|
7182
|
-
for (let i = 0; i < u32Words.length; i++) {
|
|
7183
|
-
bytesView.setUint32(i * 4, u32Words[i], true);
|
|
7184
|
-
}
|
|
7185
|
-
const hash = blakeHash(new Uint8Array(bytes));
|
|
7186
|
-
let hashBigInt = 0n;
|
|
7187
|
-
for (let i = 0; i < 32; i++) {
|
|
7188
|
-
hashBigInt |= BigInt(hash[i]) << BigInt(i * 8);
|
|
7189
|
-
}
|
|
7190
|
-
return hashBigInt % PRIME;
|
|
7191
|
-
}
|
|
7192
|
-
function hashBuiltinsBlake(builtins) {
|
|
7193
|
-
return blake2sHashMany(encodeBuiltins(builtins));
|
|
7194
|
-
}
|
|
7195
|
-
function hashEntryPointBlake(data) {
|
|
7196
|
-
const base = data.flatMap((it) => {
|
|
7197
|
-
return [BigInt(it.selector), BigInt(it.offset), hashBuiltinsBlake(it.builtins)];
|
|
7198
|
-
});
|
|
7199
|
-
return blake2sHashMany(base);
|
|
7200
|
-
}
|
|
7201
|
-
function bytecodeHashNodeBlake(iter, node) {
|
|
7202
|
-
if (typeof node === "number") {
|
|
7203
|
-
const data = [];
|
|
7204
|
-
for (let i = 0; i < node; i++) {
|
|
7205
|
-
const next = iter.next();
|
|
7206
|
-
if (next.done) throw new Error("Bytecode length mismatch");
|
|
7207
|
-
data.push(next.value);
|
|
7208
|
-
}
|
|
7209
|
-
return [node, blake2sHashMany(data)];
|
|
7210
|
-
}
|
|
7211
|
-
const innerNodes = node.map((child) => bytecodeHashNodeBlake(iter, child));
|
|
7212
|
-
const flatData = innerNodes.flatMap(([len, hash2]) => [BigInt(len), hash2]);
|
|
7213
|
-
const hash = blake2sHashMany(flatData) + 1n;
|
|
7214
|
-
const totalLen = innerNodes.reduce((sum, [len]) => sum + len, 0);
|
|
7215
|
-
return [totalLen, hash];
|
|
7216
|
-
}
|
|
7217
|
-
function hashByteCodeSegmentsBlake(casm) {
|
|
7218
|
-
const byteCode = casm.bytecode.map((n) => BigInt(n));
|
|
7219
|
-
const bytecodeSegmentLengths = casm.bytecode_segment_lengths;
|
|
7220
|
-
if (!bytecodeSegmentLengths) {
|
|
7221
|
-
return blake2sHashMany(byteCode);
|
|
7222
|
-
}
|
|
7223
|
-
const iter = byteCode[Symbol.iterator]();
|
|
7224
|
-
const [len, hash] = bytecodeHashNodeBlake(iter, bytecodeSegmentLengths);
|
|
7225
|
-
if (len !== byteCode.length) {
|
|
7226
|
-
throw new Error(`Bytecode length mismatch: expected ${byteCode.length}, got ${len}`);
|
|
7227
|
-
}
|
|
7228
|
-
return hash;
|
|
7229
|
-
}
|
|
7230
|
-
function computeCompiledClassHashBlake(casm) {
|
|
7231
|
-
const compiledClassVersion = utf8ToBigInt(COMPILED_CLASS_VERSION);
|
|
7232
|
-
const externalEntryPointsHash = hashEntryPointBlake(casm.entry_points_by_type.EXTERNAL);
|
|
7233
|
-
const l1Handlers = hashEntryPointBlake(casm.entry_points_by_type.L1_HANDLER);
|
|
7234
|
-
const constructor = hashEntryPointBlake(casm.entry_points_by_type.CONSTRUCTOR);
|
|
7235
|
-
const bytecode = hashByteCodeSegmentsBlake(casm);
|
|
7236
|
-
return toHex(
|
|
7237
|
-
blake2sHashMany([
|
|
7238
|
-
compiledClassVersion,
|
|
7239
|
-
externalEntryPointsHash,
|
|
7240
|
-
l1Handlers,
|
|
7241
|
-
constructor,
|
|
7242
|
-
bytecode
|
|
7243
|
-
])
|
|
7244
|
-
);
|
|
7245
|
-
}
|
|
7246
|
-
|
|
7247
|
-
// src/utils/resolve.ts
|
|
7248
|
-
function isV3Tx(details) {
|
|
7249
|
-
const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
|
|
7250
|
-
return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
|
|
7251
|
-
}
|
|
7252
|
-
function isVersion(expected, provided) {
|
|
7253
|
-
const expectedParts = expected.split(".");
|
|
7254
|
-
const providedParts = provided.split(".");
|
|
7255
|
-
return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
|
|
7256
|
-
}
|
|
7257
|
-
function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
|
|
7258
|
-
return Object.values(_SupportedRpcVersion).some(
|
|
7259
|
-
(v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
|
|
7260
|
-
);
|
|
7261
|
-
}
|
|
7262
|
-
function toAnyPatchVersion(version) {
|
|
7263
|
-
const parts = version.split(".");
|
|
7264
|
-
if (parts.length < 3) {
|
|
7265
|
-
return version;
|
|
7266
|
-
}
|
|
7267
|
-
return `${parts[0]}.${parts[1]}.*`;
|
|
7268
|
-
}
|
|
7269
|
-
function toReleaseVersion(version) {
|
|
7270
|
-
return version.split(/[-+]/)[0];
|
|
7271
|
-
}
|
|
7272
|
-
function toApiVersion(version) {
|
|
7273
|
-
const [major, minor] = version.replace(/^v/, "").split(".");
|
|
7274
|
-
return `v${major}_${minor}`;
|
|
7275
|
-
}
|
|
7276
|
-
function compareVersions(a, b) {
|
|
7277
|
-
const aParts = toReleaseVersion(a).split(".").map(Number);
|
|
7278
|
-
const bParts = toReleaseVersion(b).split(".").map(Number);
|
|
7279
|
-
const maxLen = Math.max(aParts.length, bParts.length);
|
|
7280
|
-
for (let i = 0; i < maxLen; i += 1) {
|
|
7281
|
-
const aNum = aParts[i] || 0;
|
|
7282
|
-
const bNum = bParts[i] || 0;
|
|
7283
|
-
if (aNum > bNum) return 1;
|
|
7284
|
-
if (aNum < bNum) return -1;
|
|
7285
|
-
}
|
|
7286
|
-
return 0;
|
|
7287
|
-
}
|
|
7288
|
-
function isPreConfirmedBlock(response) {
|
|
7289
|
-
return response.status === EBlockStatus2.PRE_CONFIRMED;
|
|
7290
|
-
}
|
|
7291
|
-
function isPreConfirmedTransaction(response) {
|
|
7292
|
-
return !("block_hash" in response);
|
|
7293
|
-
}
|
|
7294
|
-
function isPreConfirmedStateUpdate(response) {
|
|
7295
|
-
return !("block_hash" in response);
|
|
7296
|
-
}
|
|
7297
|
-
|
|
7298
|
-
// src/utils/helpers.ts
|
|
7299
|
-
function addCompiledFlag(compiled) {
|
|
7300
|
-
Object.defineProperty(compiled, "__compiled__", {
|
|
7301
|
-
enumerable: false,
|
|
7302
|
-
writable: false,
|
|
7303
|
-
value: true
|
|
7304
|
-
});
|
|
7305
|
-
return compiled;
|
|
7306
|
-
}
|
|
7307
|
-
|
|
7308
|
-
// src/utils/cairoDataTypes/felt.ts
|
|
7309
|
-
var CairoFelt252 = class _CairoFelt252 {
|
|
7310
|
-
/**
|
|
7311
|
-
* The bytes of the value, big-endian and without leading zeros.
|
|
7312
|
-
*
|
|
7313
|
-
* The length is that of the value, not a fixed width : a felt252 holding 0 is one byte, and one
|
|
7314
|
-
* holding `'Hello'` is five. Nothing here records how wide the input was written.
|
|
7315
|
-
* @example
|
|
7316
|
-
* ```typescript
|
|
7317
|
-
* const result = new CairoFelt252('Hello').data.length;
|
|
7318
|
-
* // result = 5
|
|
7319
|
-
* const result2 = new CairoFelt252(0).data.length;
|
|
7320
|
-
* // result2 = 1 (the single byte 0x00)
|
|
7321
|
-
* ```
|
|
7322
|
-
*/
|
|
7323
|
-
data;
|
|
7324
|
-
/**
|
|
7325
|
-
* The abi type this class serializes.
|
|
7326
|
-
* @example
|
|
7327
|
-
* ```typescript
|
|
7328
|
-
* const result = CairoFelt252.abiSelector;
|
|
7329
|
-
* // result = "core::felt252"
|
|
7330
|
-
* ```
|
|
7331
|
-
*/
|
|
7332
|
-
static abiSelector = "core::felt252";
|
|
7333
|
-
/**
|
|
7334
|
-
* Build from a number, a string or a boolean, refusing anything outside [0, P).
|
|
7335
|
-
*
|
|
7336
|
-
* The bytes are stored without their leading zeros, so `'0x0041'` and `'0x41'` give the same
|
|
7337
|
-
* felt252. A boolean is carried as 1 or 0.
|
|
7338
|
-
* @param {BigNumberish | boolean} data the value to carry, within [0, P)
|
|
7339
|
-
* @throws {Error} when the value is null, undefined, of an unread type, or outside [0, P)
|
|
7340
|
-
* @example
|
|
7341
|
-
* ```typescript
|
|
7342
|
-
* const result = new CairoFelt252('Hello').toApiRequest();
|
|
7343
|
-
* // result = ["310939249775"]
|
|
7344
|
-
* ```
|
|
7345
|
-
*/
|
|
7346
|
-
constructor(data) {
|
|
7347
|
-
_CairoFelt252.validate(data);
|
|
7348
|
-
const processedData = _CairoFelt252.__processData(data);
|
|
7349
|
-
this.data = processedData.subarray(processedData.findIndex((x) => x > 0));
|
|
7350
|
-
}
|
|
7351
|
-
/**
|
|
7352
|
-
* Turn an accepted input into its bytes, before the constructor strips their leading zeros.
|
|
7353
|
-
*
|
|
7354
|
-
* The range is not checked here : `validate` is what reads these bytes and decides. Only the
|
|
7355
|
-
* type is, and an input this class does not read raises rather than coming back.
|
|
7356
|
-
* @param {BigNumberish | boolean} data the value to convert
|
|
7357
|
-
* @returns {Uint8Array} the bytes of the value, of whatever length it implies
|
|
7358
|
-
* @throws {Error} when the input is neither a string, an integer, a bigint nor a boolean
|
|
7359
|
-
* @example
|
|
7360
|
-
* ```typescript
|
|
7361
|
-
* const result = CairoFelt252.__processData('Hello').length;
|
|
7362
|
-
* // result = 5
|
|
7363
|
-
* CairoFelt252.__processData(1.5);
|
|
7364
|
-
* // throws Error("1.5 can't be computed by felt()")
|
|
7365
|
-
* ```
|
|
7366
|
-
*/
|
|
7367
|
-
static __processData(data) {
|
|
7368
|
-
if (isString(data)) {
|
|
7369
|
-
return stringToUint8Array(data);
|
|
7370
|
-
}
|
|
7371
|
-
if (isBigInt(data)) {
|
|
7372
|
-
return bigIntToUint8Array(data);
|
|
7373
|
-
}
|
|
7374
|
-
if (Number.isInteger(data)) {
|
|
7375
|
-
return bigIntToUint8Array(BigInt(data));
|
|
7376
|
-
}
|
|
7377
|
-
if (isBoolean(data)) {
|
|
7378
|
-
return bigIntToUint8Array(BigInt(data ? 1 : 0));
|
|
7379
|
-
}
|
|
7380
|
-
throw new Error(`${data} can't be computed by felt()`);
|
|
7381
|
-
}
|
|
7382
|
-
/**
|
|
7383
|
-
* The bytes read as one big-endian number.
|
|
7384
|
-
* @returns {bigint} the value this felt252 holds
|
|
7385
|
-
* @example
|
|
7386
|
-
* ```typescript
|
|
7387
|
-
* const result = new CairoFelt252('Hello').toBigInt();
|
|
7388
|
-
* // result = 310939249775n
|
|
7389
|
-
* ```
|
|
7390
|
-
*/
|
|
7391
|
-
toBigInt() {
|
|
7392
|
-
return uint8ArrayToBigInt(this.data);
|
|
7393
|
-
}
|
|
7394
|
-
/**
|
|
7395
|
-
* Read the bytes back as UTF-8 text.
|
|
7396
|
-
*
|
|
7397
|
-
* Only a value that was text to begin with comes back as readable text : the bytes of a number
|
|
7398
|
-
* are decoded all the same, and what they spell is rarely what was meant.
|
|
7399
|
-
* @returns {string} the bytes decoded as UTF-8
|
|
7400
|
-
* @example
|
|
7401
|
-
* ```typescript
|
|
7402
|
-
* const result = new CairoFelt252('Hello').decodeUtf8();
|
|
7403
|
-
* // result = "Hello"
|
|
7404
|
-
* const result2 = new CairoFelt252('12345').decodeUtf8();
|
|
7405
|
-
* // result2 = "09" (the number 12345 is the two bytes 0x30 0x39)
|
|
7406
|
-
* ```
|
|
7407
|
-
*/
|
|
7408
|
-
decodeUtf8() {
|
|
7409
|
-
return new TextDecoder().decode(this.data);
|
|
7410
|
-
}
|
|
7411
|
-
/**
|
|
7412
|
-
* The value in hexadecimal, without padding.
|
|
7413
|
-
* @returns {string} the value as a 0x-prefixed hex string
|
|
7414
|
-
* @example
|
|
7415
|
-
* ```typescript
|
|
7416
|
-
* const result = new CairoFelt252('Hello').toHexString();
|
|
7417
|
-
* // result = "0x48656c6c6f"
|
|
7418
|
-
* const result2 = new CairoFelt252(0).toHexString();
|
|
7419
|
-
* // result2 = "0x0" (one digit, not "0x00")
|
|
7420
|
-
* ```
|
|
7421
|
-
*/
|
|
7422
|
-
toHexString() {
|
|
7423
|
-
return addHexPrefix(this.toBigInt().toString(16));
|
|
7424
|
-
}
|
|
7425
|
-
/**
|
|
7426
|
-
* Serialize to the single felt a contract call carries.
|
|
7427
|
-
* @returns {string[]} one decimal-string felt, flagged as compiled
|
|
7428
|
-
* @example
|
|
7429
|
-
* ```typescript
|
|
7430
|
-
* const result = new CairoFelt252('Hello').toApiRequest();
|
|
7431
|
-
* // result = ["310939249775"]
|
|
7432
|
-
* ```
|
|
7433
|
-
*/
|
|
7434
|
-
toApiRequest() {
|
|
7435
|
-
return addCompiledFlag([BigInt(this.toHexString()).toString()]);
|
|
7419
|
+
const word6 = feltView.getUint32(24, false);
|
|
7420
|
+
const word7 = feltView.getUint32(28, false);
|
|
7421
|
+
u32Words.push(word0, word1, word2, word3, word4, word5, word6, word7);
|
|
7422
|
+
}
|
|
7436
7423
|
}
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
* hands over. P is excluded : the largest felt252 is P - 1.
|
|
7442
|
-
* @param {bigint} val the number to check
|
|
7443
|
-
* @throws {Error} when the number is negative or greater than or equal to P
|
|
7444
|
-
* @example
|
|
7445
|
-
* ```typescript
|
|
7446
|
-
* CairoFelt252.assertRange(0n); // passes
|
|
7447
|
-
* CairoFelt252.assertRange(-1n);
|
|
7448
|
-
* // throws Error("Value -1 is out of felt252 range [0, 3618502788666131213697322783095070105623107215331596699973092056135872020481)")
|
|
7449
|
-
* ```
|
|
7450
|
-
*/
|
|
7451
|
-
static assertRange(val) {
|
|
7452
|
-
assert(val >= 0n && val < PRIME, `Value ${val} is out of felt252 range [0, ${PRIME})`);
|
|
7424
|
+
const bytes = new ArrayBuffer(u32Words.length * 4);
|
|
7425
|
+
const bytesView = new DataView(bytes);
|
|
7426
|
+
for (let i = 0; i < u32Words.length; i++) {
|
|
7427
|
+
bytesView.setUint32(i * 4, u32Words[i], true);
|
|
7453
7428
|
}
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
* own message, then the value is converted and its range checked. A negative number does not
|
|
7459
|
-
* reach that range check : converting it fails earlier, and the message comes from the conversion.
|
|
7460
|
-
* @param {BigNumberish | boolean} data the value to check
|
|
7461
|
-
* @throws {Error} when the value is null, undefined, of an unread type, `'0x'`, or outside [0, P)
|
|
7462
|
-
* @example
|
|
7463
|
-
* ```typescript
|
|
7464
|
-
* CairoFelt252.validate('Hello'); // passes
|
|
7465
|
-
* CairoFelt252.validate({});
|
|
7466
|
-
* // throws Error("Unsupported data type 'object' for felt252. Expected string, number, bigint, or boolean")
|
|
7467
|
-
* CairoFelt252.validate('0x');
|
|
7468
|
-
* // throws Error("Invalid input: '0x' holds no hexadecimal digit")
|
|
7469
|
-
* CairoFelt252.validate(-1);
|
|
7470
|
-
* // throws Error("Cannot convert negative bigint -1 to Uint8Array")
|
|
7471
|
-
* ```
|
|
7472
|
-
*/
|
|
7473
|
-
static validate(data) {
|
|
7474
|
-
assert(data !== null, "null value is not allowed for felt252");
|
|
7475
|
-
assert(data !== void 0, "undefined value is not allowed for felt252");
|
|
7476
|
-
assert(
|
|
7477
|
-
isString(data) || isNumber2(data) || isBigInt(data) || isBoolean(data),
|
|
7478
|
-
`Unsupported data type '${typeof data}' for felt252. Expected string, number, bigint, or boolean`
|
|
7479
|
-
);
|
|
7480
|
-
assert(!isEmptyHex(data), "Invalid input: '0x' holds no hexadecimal digit");
|
|
7481
|
-
const value = _CairoFelt252.__processData(data);
|
|
7482
|
-
const bn = uint8ArrayToBigInt(value);
|
|
7483
|
-
_CairoFelt252.assertRange(bn);
|
|
7429
|
+
const hash = blakeHash(new Uint8Array(bytes));
|
|
7430
|
+
let hashBigInt = 0n;
|
|
7431
|
+
for (let i = 0; i < 32; i++) {
|
|
7432
|
+
hashBigInt |= BigInt(hash[i]) << BigInt(i * 8);
|
|
7484
7433
|
}
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
return true;
|
|
7504
|
-
} catch {
|
|
7505
|
-
return false;
|
|
7434
|
+
return hashBigInt % PRIME;
|
|
7435
|
+
}
|
|
7436
|
+
function hashBuiltinsBlake(builtins) {
|
|
7437
|
+
return blake2sHashMany(encodeBuiltins(builtins));
|
|
7438
|
+
}
|
|
7439
|
+
function hashEntryPointBlake(data) {
|
|
7440
|
+
const base = data.flatMap((it) => {
|
|
7441
|
+
return [BigInt(it.selector), BigInt(it.offset), hashBuiltinsBlake(it.builtins)];
|
|
7442
|
+
});
|
|
7443
|
+
return blake2sHashMany(base);
|
|
7444
|
+
}
|
|
7445
|
+
function bytecodeHashNodeBlake(iter, node) {
|
|
7446
|
+
if (typeof node === "number") {
|
|
7447
|
+
const data = [];
|
|
7448
|
+
for (let i = 0; i < node; i++) {
|
|
7449
|
+
const next = iter.next();
|
|
7450
|
+
if (next.done) throw new Error("Bytecode length mismatch");
|
|
7451
|
+
data.push(next.value);
|
|
7506
7452
|
}
|
|
7453
|
+
return [node, blake2sHashMany(data)];
|
|
7507
7454
|
}
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
*/
|
|
7520
|
-
static isAbiType(abiType) {
|
|
7521
|
-
return abiType === _CairoFelt252.abiSelector;
|
|
7455
|
+
const innerNodes = node.map((child) => bytecodeHashNodeBlake(iter, child));
|
|
7456
|
+
const flatData = innerNodes.flatMap(([len, hash2]) => [BigInt(len), hash2]);
|
|
7457
|
+
const hash = blake2sHashMany(flatData) + 1n;
|
|
7458
|
+
const totalLen = innerNodes.reduce((sum, [len]) => sum + len, 0);
|
|
7459
|
+
return [totalLen, hash];
|
|
7460
|
+
}
|
|
7461
|
+
function hashByteCodeSegmentsBlake(casm) {
|
|
7462
|
+
const byteCode = casm.bytecode.map((n) => BigInt(n));
|
|
7463
|
+
const bytecodeSegmentLengths = casm.bytecode_segment_lengths;
|
|
7464
|
+
if (!bytecodeSegmentLengths) {
|
|
7465
|
+
return blake2sHashMany(byteCode);
|
|
7522
7466
|
}
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
* read successive return values.
|
|
7528
|
-
* @param {Iterator<string>} responseIterator the response felts, positioned on this felt252
|
|
7529
|
-
* @returns {CairoFelt252} the felt252 that was read
|
|
7530
|
-
* @example
|
|
7531
|
-
* ```typescript
|
|
7532
|
-
* const response = ['0x48656c6c6f'];
|
|
7533
|
-
* const result = CairoFelt252.factoryFromApiResponse(response.values()).decodeUtf8();
|
|
7534
|
-
* // result = "Hello"
|
|
7535
|
-
* ```
|
|
7536
|
-
*/
|
|
7537
|
-
static factoryFromApiResponse(responseIterator) {
|
|
7538
|
-
return new _CairoFelt252(getNext(responseIterator));
|
|
7467
|
+
const iter = byteCode[Symbol.iterator]();
|
|
7468
|
+
const [len, hash] = bytecodeHashNodeBlake(iter, bytecodeSegmentLengths);
|
|
7469
|
+
if (len !== byteCode.length) {
|
|
7470
|
+
throw new Error(`Bytecode length mismatch: expected ${byteCode.length}, got ${len}`);
|
|
7539
7471
|
}
|
|
7540
|
-
|
|
7472
|
+
return hash;
|
|
7473
|
+
}
|
|
7474
|
+
function computeCompiledClassHashBlake(casm) {
|
|
7475
|
+
const compiledClassVersion = utf8ToBigInt(COMPILED_CLASS_VERSION);
|
|
7476
|
+
const externalEntryPointsHash = hashEntryPointBlake(casm.entry_points_by_type.EXTERNAL);
|
|
7477
|
+
const l1Handlers = hashEntryPointBlake(casm.entry_points_by_type.L1_HANDLER);
|
|
7478
|
+
const constructor = hashEntryPointBlake(casm.entry_points_by_type.CONSTRUCTOR);
|
|
7479
|
+
const bytecode = hashByteCodeSegmentsBlake(casm);
|
|
7480
|
+
return toHex(
|
|
7481
|
+
blake2sHashMany([
|
|
7482
|
+
compiledClassVersion,
|
|
7483
|
+
externalEntryPointsHash,
|
|
7484
|
+
l1Handlers,
|
|
7485
|
+
constructor,
|
|
7486
|
+
bytecode
|
|
7487
|
+
])
|
|
7488
|
+
);
|
|
7489
|
+
}
|
|
7490
|
+
|
|
7491
|
+
// src/utils/resolve.ts
|
|
7492
|
+
function isV3Tx(details) {
|
|
7493
|
+
const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
|
|
7494
|
+
return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
|
|
7495
|
+
}
|
|
7496
|
+
function isVersion(expected, provided) {
|
|
7497
|
+
const expectedParts = expected.split(".");
|
|
7498
|
+
const providedParts = provided.split(".");
|
|
7499
|
+
return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
|
|
7500
|
+
}
|
|
7501
|
+
function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
|
|
7502
|
+
return Object.values(_SupportedRpcVersion).some(
|
|
7503
|
+
(v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
|
|
7504
|
+
);
|
|
7505
|
+
}
|
|
7506
|
+
function toAnyPatchVersion(version) {
|
|
7507
|
+
const parts = version.split(".");
|
|
7508
|
+
if (parts.length < 3) {
|
|
7509
|
+
return version;
|
|
7510
|
+
}
|
|
7511
|
+
return `${parts[0]}.${parts[1]}.*`;
|
|
7512
|
+
}
|
|
7513
|
+
function toReleaseVersion(version) {
|
|
7514
|
+
return version.split(/[-+]/)[0];
|
|
7515
|
+
}
|
|
7516
|
+
function toApiVersion(version) {
|
|
7517
|
+
const [major, minor] = version.replace(/^v/, "").split(".");
|
|
7518
|
+
return `v${major}_${minor}`;
|
|
7519
|
+
}
|
|
7520
|
+
function compareVersions(a, b) {
|
|
7521
|
+
const aParts = toReleaseVersion(a).split(".").map(Number);
|
|
7522
|
+
const bParts = toReleaseVersion(b).split(".").map(Number);
|
|
7523
|
+
const maxLen = Math.max(aParts.length, bParts.length);
|
|
7524
|
+
for (let i = 0; i < maxLen; i += 1) {
|
|
7525
|
+
const aNum = aParts[i] || 0;
|
|
7526
|
+
const bNum = bParts[i] || 0;
|
|
7527
|
+
if (aNum > bNum) return 1;
|
|
7528
|
+
if (aNum < bNum) return -1;
|
|
7529
|
+
}
|
|
7530
|
+
return 0;
|
|
7531
|
+
}
|
|
7532
|
+
function isPreConfirmedBlock(response) {
|
|
7533
|
+
return response.status === EBlockStatus2.PRE_CONFIRMED;
|
|
7534
|
+
}
|
|
7535
|
+
function isPreConfirmedTransaction(response) {
|
|
7536
|
+
return !("block_hash" in response);
|
|
7537
|
+
}
|
|
7538
|
+
function isPreConfirmedStateUpdate(response) {
|
|
7539
|
+
return !("block_hash" in response);
|
|
7540
|
+
}
|
|
7541
7541
|
|
|
7542
7542
|
// src/utils/cairoDataTypes/cairoType.interface.ts
|
|
7543
7543
|
function isCairoType(value) {
|
|
@@ -18214,71 +18214,62 @@ ${indent}}` : "}";
|
|
|
18214
18214
|
}
|
|
18215
18215
|
var validBlockTags = Object.values(BlockTag);
|
|
18216
18216
|
var Block = class {
|
|
18217
|
-
/**
|
|
18218
|
-
* @param {BlockIdentifier} hash if not null, contains the block hash
|
|
18219
|
-
*/
|
|
18217
|
+
/** It holds the block hash when the block is given by its hash. Otherwise, it is null. */
|
|
18220
18218
|
hash = null;
|
|
18221
|
-
/**
|
|
18222
|
-
* @param {BlockIdentifier} number if not null, contains the block number
|
|
18223
|
-
*/
|
|
18219
|
+
/** It holds the block number when the block is given by its number. Otherwise, it is null. */
|
|
18224
18220
|
number = null;
|
|
18221
|
+
/** It holds the block tag when the block is given by a tag. Otherwise, it is null. */
|
|
18222
|
+
tag = null;
|
|
18225
18223
|
/**
|
|
18226
|
-
*
|
|
18224
|
+
* Create a Block.
|
|
18225
|
+
* @param {BlockIdentifier} _identifier the block number, the block hash or the block tag.
|
|
18226
|
+
* `null` and `undefined` mean `'latest'`.
|
|
18227
|
+
* @throws {Error} The identifier names no block. It is an empty string, a text that is not a
|
|
18228
|
+
* block tag, a hash that is not a felt (`'0x'`, a negative bigint, or a value larger than the
|
|
18229
|
+
* largest felt), a number that is not an integer, a negative number, a number larger than
|
|
18230
|
+
* `Number.MAX_SAFE_INTEGER`, or a value that is not a string, a number or a bigint.
|
|
18231
|
+
* @example
|
|
18232
|
+
* ```typescript
|
|
18233
|
+
* const result = new provider.Block('0X0abc').identifier;
|
|
18234
|
+
* // result = { block_hash: '0xabc' }
|
|
18235
|
+
*
|
|
18236
|
+
* new provider.Block(1.5);
|
|
18237
|
+
* // throws Error: Block number (1.5) must be an integer
|
|
18238
|
+
* ```
|
|
18227
18239
|
*/
|
|
18228
|
-
|
|
18229
|
-
|
|
18230
|
-
|
|
18231
|
-
|
|
18232
|
-
|
|
18233
|
-
|
|
18234
|
-
this.hash = __identifier;
|
|
18235
|
-
} else if (validBlockTags.includes(__identifier)) {
|
|
18236
|
-
this.tag = __identifier;
|
|
18240
|
+
constructor(_identifier) {
|
|
18241
|
+
if (isString(_identifier)) {
|
|
18242
|
+
if (isStringWholeNumber(_identifier)) {
|
|
18243
|
+
this.number = parseInt(_identifier, 10);
|
|
18244
|
+
} else if (isHex2(_identifier)) {
|
|
18245
|
+
this.hash = new CairoFelt252(_identifier).toHexString();
|
|
18237
18246
|
} else {
|
|
18238
|
-
|
|
18247
|
+
assert(
|
|
18248
|
+
validBlockTags.includes(_identifier),
|
|
18249
|
+
`Block identifier unmanaged: '${_identifier}'`
|
|
18250
|
+
);
|
|
18251
|
+
this.tag = _identifier;
|
|
18239
18252
|
}
|
|
18240
|
-
} else if (isBigInt(
|
|
18241
|
-
this.hash =
|
|
18242
|
-
} else if (isNumber2(
|
|
18243
|
-
this.number =
|
|
18253
|
+
} else if (isBigInt(_identifier)) {
|
|
18254
|
+
this.hash = new CairoFelt252(_identifier).toHexString();
|
|
18255
|
+
} else if (isNumber2(_identifier)) {
|
|
18256
|
+
this.number = _identifier;
|
|
18244
18257
|
} else {
|
|
18258
|
+
assert(
|
|
18259
|
+
_identifier === null || _identifier === void 0,
|
|
18260
|
+
`Block identifier unmanaged: ${_identifier}`
|
|
18261
|
+
);
|
|
18245
18262
|
this.tag = BlockTag.LATEST;
|
|
18246
18263
|
}
|
|
18247
|
-
if (isNumber2(this.number) && this.number < 0) {
|
|
18248
|
-
throw TypeError(`Block number (${this.number}) can't be negative`);
|
|
18249
|
-
}
|
|
18250
|
-
}
|
|
18251
|
-
/**
|
|
18252
|
-
* Create a Block instance
|
|
18253
|
-
* @param {BlockIdentifier} _identifier hex string and BigInt are detected as block hashes.
|
|
18254
|
-
* decimal string and number are detected as block numbers.
|
|
18255
|
-
* text string are detected as block tag.
|
|
18256
|
-
* null is considered as a 'latest' block tag.
|
|
18257
|
-
*/
|
|
18258
|
-
constructor(_identifier) {
|
|
18259
|
-
this.setIdentifier(_identifier);
|
|
18260
|
-
}
|
|
18261
|
-
// TODO: fix any
|
|
18262
|
-
/**
|
|
18263
|
-
* @returns {any} the identifier as a string
|
|
18264
|
-
* @example
|
|
18265
|
-
* ```typescript
|
|
18266
|
-
* const result = new provider.Block(123456n).queryIdentifier;
|
|
18267
|
-
* // result = "blockHash=0x1e240"
|
|
18268
|
-
* ```
|
|
18269
|
-
*/
|
|
18270
|
-
get queryIdentifier() {
|
|
18271
18264
|
if (this.number !== null) {
|
|
18272
|
-
|
|
18273
|
-
|
|
18274
|
-
if (this.hash !== null) {
|
|
18275
|
-
return `blockHash=${this.hash}`;
|
|
18265
|
+
assert(isInteger2(this.number), `Block number (${_identifier}) must be an integer`);
|
|
18266
|
+
assertInRange(this.number, 0, Number.MAX_SAFE_INTEGER, "block number");
|
|
18276
18267
|
}
|
|
18277
|
-
|
|
18268
|
+
Object.freeze(this);
|
|
18278
18269
|
}
|
|
18279
|
-
// TODO: fix any
|
|
18280
18270
|
/**
|
|
18281
|
-
* @returns {
|
|
18271
|
+
* @returns {RPC.BLOCK_ID} the block in the form of the `block_id` of an RPC request:
|
|
18272
|
+
* `{ block_number: number }`, `{ block_hash: string }` or a block tag.
|
|
18282
18273
|
* @example
|
|
18283
18274
|
* ```typescript
|
|
18284
18275
|
* const result = new provider.Block(56789).identifier;
|
|
@@ -18294,21 +18285,6 @@ ${indent}}` : "}";
|
|
|
18294
18285
|
}
|
|
18295
18286
|
return this.tag;
|
|
18296
18287
|
}
|
|
18297
|
-
/**
|
|
18298
|
-
* change the identifier of an existing Block instance
|
|
18299
|
-
* @example
|
|
18300
|
-
* ```typescript
|
|
18301
|
-
* const myBlock = new provider.Block("latest");
|
|
18302
|
-
* myBlock.identifier ="0x3456789abc";
|
|
18303
|
-
* const result = myBlock.identifier;
|
|
18304
|
-
* // result = { block_hash: '0x3456789abc' }
|
|
18305
|
-
* ```
|
|
18306
|
-
*/
|
|
18307
|
-
set identifier(_identifier) {
|
|
18308
|
-
this.setIdentifier(_identifier);
|
|
18309
|
-
}
|
|
18310
|
-
valueOf = () => this.number;
|
|
18311
|
-
toString = () => this.hash;
|
|
18312
18288
|
};
|
|
18313
18289
|
|
|
18314
18290
|
// src/utils/eventEmitter.ts
|
|
@@ -19806,6 +19782,10 @@ ${indent}}` : "}";
|
|
|
19806
19782
|
}
|
|
19807
19783
|
getStorageProof(classHashes = [], contractAddresses = [], contractsStorageKeys = [], blockIdentifier = this.blockIdentifier) {
|
|
19808
19784
|
const block_id = new Block(blockIdentifier).identifier;
|
|
19785
|
+
assert(
|
|
19786
|
+
block_id !== "pre_confirmed",
|
|
19787
|
+
"starknet_getStorageProof does not accept the block tag 'pre_confirmed'"
|
|
19788
|
+
);
|
|
19809
19789
|
const class_hashes = bigNumberishArrayToHexadecimalStringArray(classHashes);
|
|
19810
19790
|
const contract_addresses = bigNumberishArrayToHexadecimalStringArray(contractAddresses);
|
|
19811
19791
|
return this.fetchEndpoint("starknet_getStorageProof", {
|
|
@@ -19869,6 +19849,10 @@ ${indent}}` : "}";
|
|
|
19869
19849
|
}
|
|
19870
19850
|
getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
|
|
19871
19851
|
const block_id = new Block(blockIdentifier).identifier;
|
|
19852
|
+
assert(
|
|
19853
|
+
block_id !== "pre_confirmed",
|
|
19854
|
+
"starknet_traceBlockTransactions does not accept the block tag 'pre_confirmed'"
|
|
19855
|
+
);
|
|
19872
19856
|
return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
|
|
19873
19857
|
}
|
|
19874
19858
|
getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
|
|
@@ -20480,6 +20464,10 @@ ${indent}}` : "}";
|
|
|
20480
20464
|
// TODO: New Method add test
|
|
20481
20465
|
getStorageProof(classHashes = [], contractAddresses = [], contractsStorageKeys = [], blockIdentifier = this.blockIdentifier) {
|
|
20482
20466
|
const block_id = new Block(blockIdentifier).identifier;
|
|
20467
|
+
assert(
|
|
20468
|
+
block_id !== "pre_confirmed",
|
|
20469
|
+
"starknet_getStorageProof does not accept the block tag 'pre_confirmed'"
|
|
20470
|
+
);
|
|
20483
20471
|
const class_hashes = bigNumberishArrayToHexadecimalStringArray(classHashes);
|
|
20484
20472
|
const contract_addresses = bigNumberishArrayToHexadecimalStringArray(contractAddresses);
|
|
20485
20473
|
return this.fetchEndpoint("starknet_getStorageProof", {
|
|
@@ -20575,6 +20563,10 @@ ${indent}}` : "}";
|
|
|
20575
20563
|
*/
|
|
20576
20564
|
getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier, options) {
|
|
20577
20565
|
const block_id = new Block(blockIdentifier).identifier;
|
|
20566
|
+
assert(
|
|
20567
|
+
block_id !== "pre_confirmed",
|
|
20568
|
+
"starknet_traceBlockTransactions does not accept the block tag 'pre_confirmed'"
|
|
20569
|
+
);
|
|
20578
20570
|
const trace_flags = options?.returnInitialReads ? [ETraceFlag3.RETURN_INITIAL_READS] : void 0;
|
|
20579
20571
|
return this.fetchEndpoint("starknet_traceBlockTransactions", {
|
|
20580
20572
|
block_id,
|