starknet 10.1.0 → 10.3.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 +12 -0
- package/README.md +2 -2
- package/dist/index.d.ts +293 -212
- package/dist/index.global.js +154 -31
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +156 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +156 -33
- 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: () =>
|
|
5072
|
+
computeHashOnElements: () => computeHashOnElements2
|
|
5030
5073
|
});
|
|
5031
|
-
|
|
5032
|
-
// src/utils/ec.ts
|
|
5033
|
-
var ec_exports = {};
|
|
5034
|
-
__export(ec_exports, {
|
|
5035
|
-
starkCurve: () => starkCurve,
|
|
5036
|
-
weierstrass: () => weierstrass
|
|
5037
|
-
});
|
|
5038
|
-
var starkCurve = __toESM(require("@scure/starknet"));
|
|
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,
|
|
@@ -6599,6 +6624,12 @@ var RpcChannel = class {
|
|
|
6599
6624
|
});
|
|
6600
6625
|
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
6601
6626
|
}
|
|
6627
|
+
async invokeSignedTx(transaction) {
|
|
6628
|
+
const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
6629
|
+
invoke_transaction: transaction
|
|
6630
|
+
});
|
|
6631
|
+
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
6632
|
+
}
|
|
6602
6633
|
async declare(declareTransaction, details) {
|
|
6603
6634
|
const transaction = await this.buildTransaction(
|
|
6604
6635
|
{
|
|
@@ -7208,6 +7239,12 @@ var RpcChannel2 = class {
|
|
|
7208
7239
|
});
|
|
7209
7240
|
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
7210
7241
|
}
|
|
7242
|
+
async invokeSignedTx(transaction) {
|
|
7243
|
+
const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
7244
|
+
invoke_transaction: transaction
|
|
7245
|
+
});
|
|
7246
|
+
return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
|
|
7247
|
+
}
|
|
7211
7248
|
async declare(declareTransaction, details) {
|
|
7212
7249
|
const transaction = await this.buildTransaction(
|
|
7213
7250
|
{
|
|
@@ -9898,6 +9935,34 @@ var RpcProvider = class {
|
|
|
9898
9935
|
async invokeFunction(functionInvocation, details) {
|
|
9899
9936
|
return this.channel.invoke(functionInvocation, details);
|
|
9900
9937
|
}
|
|
9938
|
+
/**
|
|
9939
|
+
* Submit a pre-signed INVOKE_TXN_V3 transaction to the network.
|
|
9940
|
+
*
|
|
9941
|
+
* Broadcasts a transaction previously built and signed by `Account.getSignedTransaction()`.
|
|
9942
|
+
* Fees are already included in the signed transaction and will not be re-estimated.
|
|
9943
|
+
*
|
|
9944
|
+
* @param transaction - A fully signed `RPC.INVOKE_TXN_V3` object, as returned by `Account.getSignedTransaction()`
|
|
9945
|
+
*
|
|
9946
|
+
* @returns The transaction hash if `waitMode` is disabled (default), or the transaction receipt if `waitMode` is enabled.
|
|
9947
|
+
*
|
|
9948
|
+
* @remarks
|
|
9949
|
+
* - The transaction must be signed before calling this method ; use `Account.getSignedTransaction()` to produce it.
|
|
9950
|
+
* - Resubmitting the same signed transaction (same nonce) will be rejected by the network.
|
|
9951
|
+
* - If `waitMode` is enabled on the provider, this method waits for the transaction to be included in a block before returning.
|
|
9952
|
+
*
|
|
9953
|
+
* @example
|
|
9954
|
+
* ```typescript
|
|
9955
|
+
* const signedTx = await account.getSignedTransaction([
|
|
9956
|
+
* { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
|
|
9957
|
+
* ]);
|
|
9958
|
+
* // inspect or store signedTx, then submit when ready:
|
|
9959
|
+
* const { transaction_hash } = await provider.invokeSignedTx(signedTx);
|
|
9960
|
+
* await provider.waitForTransaction(transaction_hash);
|
|
9961
|
+
* ```
|
|
9962
|
+
*/
|
|
9963
|
+
async invokeSignedTx(transaction) {
|
|
9964
|
+
return this.channel.invokeSignedTx(transaction);
|
|
9965
|
+
}
|
|
9901
9966
|
async declareContract(transaction, details) {
|
|
9902
9967
|
return this.channel.declare(transaction, details);
|
|
9903
9968
|
}
|
|
@@ -11780,7 +11845,12 @@ var Account = class {
|
|
|
11780
11845
|
returnInitialReads
|
|
11781
11846
|
});
|
|
11782
11847
|
}
|
|
11783
|
-
|
|
11848
|
+
/**
|
|
11849
|
+
* Shared preparation logic for execute() and buildExecute().
|
|
11850
|
+
* Runs hooks, estimates fees, and builds accountInvocations.
|
|
11851
|
+
* @private
|
|
11852
|
+
*/
|
|
11853
|
+
async prepareInvoke(transactions, transactionsDetail = {}) {
|
|
11784
11854
|
const hookResult = this.accountPluginManager.runAccountHook("beforeExecute", {
|
|
11785
11855
|
calls: transactions,
|
|
11786
11856
|
details: transactionsDetail
|
|
@@ -11805,7 +11875,15 @@ var Account = class {
|
|
|
11805
11875
|
skipValidate: false
|
|
11806
11876
|
}
|
|
11807
11877
|
);
|
|
11808
|
-
|
|
11878
|
+
return {
|
|
11879
|
+
invocation: accountInvocations[0],
|
|
11880
|
+
hookedTransactions,
|
|
11881
|
+
hookedDetails,
|
|
11882
|
+
detailsWithTip
|
|
11883
|
+
};
|
|
11884
|
+
}
|
|
11885
|
+
async execute(transactions, transactionsDetail = {}) {
|
|
11886
|
+
const { invocation, hookedTransactions, hookedDetails, detailsWithTip } = await this.prepareInvoke(transactions, transactionsDetail);
|
|
11809
11887
|
const result = await this.provider.invokeFunction(
|
|
11810
11888
|
{
|
|
11811
11889
|
contractAddress: invocation.contractAddress,
|
|
@@ -11827,6 +11905,51 @@ var Account = class {
|
|
|
11827
11905
|
});
|
|
11828
11906
|
return result;
|
|
11829
11907
|
}
|
|
11908
|
+
/**
|
|
11909
|
+
* Build a signed INVOKE_TXN_V3 transaction without submitting it to the network.
|
|
11910
|
+
*
|
|
11911
|
+
* Produces a fully signed transaction object that can be inspected, stored,
|
|
11912
|
+
* or submitted later via `provider.channel.sendTransaction()`.
|
|
11913
|
+
* Main usage is to send a virtual transaction to a proof server.
|
|
11914
|
+
* Fees are estimated automatically if not provided.
|
|
11915
|
+
*
|
|
11916
|
+
* @param transactions - Single call or array of calls to include in the transaction
|
|
11917
|
+
* @param transactionsDetail - Transaction execution options
|
|
11918
|
+
* @returns A fully signed `RPC.INVOKE_TXN_V3` object, ready to broadcast
|
|
11919
|
+
*
|
|
11920
|
+
* @remarks
|
|
11921
|
+
* - Unlike `execute()`, this method does **not** submit the transaction ; the account nonce is unchanged after the call.
|
|
11922
|
+
* - The `afterExecute` plugin hook is intentionally **not** triggered.
|
|
11923
|
+
* - The returned object can be broadcast with `provider.channel.sendTransaction()`.
|
|
11924
|
+
*
|
|
11925
|
+
* @example
|
|
11926
|
+
* ```typescript
|
|
11927
|
+
* const signedTx = await account.getSignedTransaction(
|
|
11928
|
+
* { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
|
|
11929
|
+
* );
|
|
11930
|
+
* ```
|
|
11931
|
+
*/
|
|
11932
|
+
async getSignedTransaction(transactions, transactionsDetail = {}) {
|
|
11933
|
+
const { invocation, hookedDetails, detailsWithTip } = await this.prepareInvoke(
|
|
11934
|
+
transactions,
|
|
11935
|
+
transactionsDetail
|
|
11936
|
+
);
|
|
11937
|
+
return this.provider.channel.buildTransaction(
|
|
11938
|
+
{
|
|
11939
|
+
type: api_exports.ETransactionType.INVOKE,
|
|
11940
|
+
contractAddress: invocation.contractAddress,
|
|
11941
|
+
calldata: invocation.calldata,
|
|
11942
|
+
signature: invocation.signature,
|
|
11943
|
+
...hookedDetails.proofFacts && { proofFacts: hookedDetails.proofFacts },
|
|
11944
|
+
...hookedDetails.proof && { proof: hookedDetails.proof },
|
|
11945
|
+
...v3Details(detailsWithTip),
|
|
11946
|
+
resourceBounds: invocation.resourceBounds,
|
|
11947
|
+
nonce: invocation.nonce,
|
|
11948
|
+
version: invocation.version
|
|
11949
|
+
},
|
|
11950
|
+
"transaction"
|
|
11951
|
+
);
|
|
11952
|
+
}
|
|
11830
11953
|
/**
|
|
11831
11954
|
* First check if contract is already declared, if not declare it
|
|
11832
11955
|
* If contract already declared returned transaction_hash is ''.
|