starknet 10.1.0 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.global.js +54 -29
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +56 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2032,6 +2032,24 @@ var CairoBytes31 = class _CairoBytes31 {
|
|
|
2032
2032
|
}
|
|
2033
2033
|
};
|
|
2034
2034
|
|
|
2035
|
+
// src/utils/ec.ts
|
|
2036
|
+
var ec_exports = {};
|
|
2037
|
+
__export(ec_exports, {
|
|
2038
|
+
starkCurve: () => starkCurve,
|
|
2039
|
+
weierstrass: () => weierstrass
|
|
2040
|
+
});
|
|
2041
|
+
var starkCurve = __toESM(require("@scure/starknet"));
|
|
2042
|
+
var weierstrass = __toESM(require("@noble/curves/abstract/weierstrass"));
|
|
2043
|
+
|
|
2044
|
+
// src/utils/hash/pedersenCore.ts
|
|
2045
|
+
function computePedersenHash(a, b) {
|
|
2046
|
+
return starkCurve.pedersen(BigInt(a), BigInt(b));
|
|
2047
|
+
}
|
|
2048
|
+
function computeHashOnElements(data) {
|
|
2049
|
+
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
|
|
2050
|
+
}
|
|
2051
|
+
var computePedersenHashOnElements = computeHashOnElements;
|
|
2052
|
+
|
|
2035
2053
|
// src/utils/errors/rpc.ts
|
|
2036
2054
|
var errorCodes = {
|
|
2037
2055
|
FAILED_TO_RECEIVE_TXN: 1,
|
|
@@ -2326,6 +2344,31 @@ var CairoByteArray = class _CairoByteArray {
|
|
|
2326
2344
|
const allBytes = concatenateArrayBuffer(this.toElements());
|
|
2327
2345
|
return buffer_default.from(allBytes);
|
|
2328
2346
|
}
|
|
2347
|
+
/**
|
|
2348
|
+
* Compute the Pedersen hash of this ByteArray, following OpenZeppelin's `hash_byte_array` algorithm.
|
|
2349
|
+
*
|
|
2350
|
+
* Serializes the ByteArray to its felt252 components (data array length, each data chunk,
|
|
2351
|
+
* pending_word, pending_word_len), then chains Pedersen hash over all elements starting
|
|
2352
|
+
* from 0, and finalizes with the total element count.
|
|
2353
|
+
*
|
|
2354
|
+
* @returns {string} hex-string felt252 Pedersen hash of the ByteArray
|
|
2355
|
+
* @example
|
|
2356
|
+
* ```typescript
|
|
2357
|
+
* const ba = new CairoByteArray('Hello');
|
|
2358
|
+
* const result = ba.hash();
|
|
2359
|
+
* // result = 0x15d19ad651ffaf8e90a13938db2081fa3ff01de0712e00cbe69891bace66c51
|
|
2360
|
+
* ```
|
|
2361
|
+
*/
|
|
2362
|
+
hash() {
|
|
2363
|
+
this.assertInitialized();
|
|
2364
|
+
const serialized = [
|
|
2365
|
+
addHexPrefix(this.data.length.toString(16)),
|
|
2366
|
+
...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
|
|
2367
|
+
...this.pending_word.toApiRequest(),
|
|
2368
|
+
...this.pending_word_len.toApiRequest()
|
|
2369
|
+
];
|
|
2370
|
+
return computeHashOnElements(serialized);
|
|
2371
|
+
}
|
|
2329
2372
|
/**
|
|
2330
2373
|
* returns an array of all the data chunks and the pending word
|
|
2331
2374
|
* when concatenated, represents the original bytes sequence
|
|
@@ -4886,7 +4929,7 @@ __export(hash_exports, {
|
|
|
4886
4929
|
computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
|
|
4887
4930
|
computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
|
|
4888
4931
|
computeContractClassHash: () => computeContractClassHash,
|
|
4889
|
-
computeHashOnElements: () =>
|
|
4932
|
+
computeHashOnElements: () => computeHashOnElements,
|
|
4890
4933
|
computeHintedClassHash: () => computeHintedClassHash,
|
|
4891
4934
|
computeLegacyContractClassHash: () => computeLegacyContractClassHash,
|
|
4892
4935
|
computePedersenHash: () => computePedersenHash,
|
|
@@ -5026,24 +5069,13 @@ __export(v2_exports, {
|
|
|
5026
5069
|
calculateL2MessageTxHash: () => calculateL2MessageTxHash,
|
|
5027
5070
|
calculateTransactionHash: () => calculateTransactionHash,
|
|
5028
5071
|
calculateTransactionHashCommon: () => calculateTransactionHashCommon2,
|
|
5029
|
-
computeHashOnElements: () =>
|
|
5030
|
-
});
|
|
5031
|
-
|
|
5032
|
-
// src/utils/ec.ts
|
|
5033
|
-
var ec_exports = {};
|
|
5034
|
-
__export(ec_exports, {
|
|
5035
|
-
starkCurve: () => starkCurve,
|
|
5036
|
-
weierstrass: () => weierstrass
|
|
5072
|
+
computeHashOnElements: () => computeHashOnElements2
|
|
5037
5073
|
});
|
|
5038
|
-
|
|
5039
|
-
var weierstrass = __toESM(require("@noble/curves/abstract/weierstrass"));
|
|
5040
|
-
|
|
5041
|
-
// src/utils/hash/transactionHash/v2.ts
|
|
5042
|
-
function computeHashOnElements(data) {
|
|
5074
|
+
function computeHashOnElements2(data) {
|
|
5043
5075
|
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
5044
5076
|
}
|
|
5045
5077
|
function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
5046
|
-
const calldataHash =
|
|
5078
|
+
const calldataHash = computeHashOnElements2(calldata);
|
|
5047
5079
|
const dataToHash = [
|
|
5048
5080
|
txHashPrefix,
|
|
5049
5081
|
version,
|
|
@@ -5054,7 +5086,7 @@ function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress,
|
|
|
5054
5086
|
chainId,
|
|
5055
5087
|
...additionalData
|
|
5056
5088
|
];
|
|
5057
|
-
return
|
|
5089
|
+
return computeHashOnElements2(dataToHash);
|
|
5058
5090
|
}
|
|
5059
5091
|
function calculateDeclareTransactionHash2(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
5060
5092
|
return calculateTransactionHashCommon2(
|
|
@@ -5213,18 +5245,11 @@ function flattenEntryPointData(data, encodedBuiltinsArray) {
|
|
|
5213
5245
|
}
|
|
5214
5246
|
|
|
5215
5247
|
// src/utils/hash/classHash/pedersen.ts
|
|
5216
|
-
function computePedersenHash(a, b) {
|
|
5217
|
-
return starkCurve.pedersen(BigInt(a), BigInt(b));
|
|
5218
|
-
}
|
|
5219
|
-
function computeHashOnElements2(data) {
|
|
5220
|
-
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
|
|
5221
|
-
}
|
|
5222
|
-
var computePedersenHashOnElements = computeHashOnElements2;
|
|
5223
5248
|
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
5224
5249
|
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5225
|
-
const constructorCalldataHash =
|
|
5250
|
+
const constructorCalldataHash = computeHashOnElements(compiledCalldata);
|
|
5226
5251
|
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
5227
|
-
const hash =
|
|
5252
|
+
const hash = computeHashOnElements([
|
|
5228
5253
|
CONTRACT_ADDRESS_PREFIX,
|
|
5229
5254
|
deployerAddress,
|
|
5230
5255
|
salt,
|
|
@@ -5242,21 +5267,21 @@ function computeHintedClassHash(compiledContract) {
|
|
|
5242
5267
|
function computeLegacyContractClassHash(contract) {
|
|
5243
5268
|
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
5244
5269
|
const apiVersion = toHex(API_VERSION);
|
|
5245
|
-
const externalEntryPointsHash =
|
|
5270
|
+
const externalEntryPointsHash = computeHashOnElements(
|
|
5246
5271
|
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
5247
5272
|
);
|
|
5248
|
-
const l1HandlerEntryPointsHash =
|
|
5273
|
+
const l1HandlerEntryPointsHash = computeHashOnElements(
|
|
5249
5274
|
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
5250
5275
|
);
|
|
5251
|
-
const constructorEntryPointHash =
|
|
5276
|
+
const constructorEntryPointHash = computeHashOnElements(
|
|
5252
5277
|
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
5253
5278
|
);
|
|
5254
|
-
const builtinsHash =
|
|
5279
|
+
const builtinsHash = computeHashOnElements(
|
|
5255
5280
|
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
5256
5281
|
);
|
|
5257
5282
|
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
5258
|
-
const dataHash =
|
|
5259
|
-
return
|
|
5283
|
+
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
5284
|
+
return computeHashOnElements([
|
|
5260
5285
|
apiVersion,
|
|
5261
5286
|
externalEntryPointsHash,
|
|
5262
5287
|
l1HandlerEntryPointsHash,
|