starknet 6.9.0 → 6.10.1
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/LICENSE +1 -1
- package/README.md +5 -9
- package/dist/account/default.cjs +655 -0
- package/dist/account/default.d.ts +67 -0
- package/dist/account/default.mjs +652 -0
- package/dist/account/index.cjs +27 -0
- package/dist/account/index.d.ts +2 -0
- package/dist/account/index.mjs +2 -0
- package/dist/account/interface.cjs +9 -0
- package/dist/account/interface.d.ts +301 -0
- package/dist/account/interface.mjs +3 -0
- package/dist/channel/index.cjs +27 -0
- package/dist/channel/index.d.ts +3 -0
- package/dist/channel/index.mjs +3 -0
- package/dist/channel/rpc_0_6.cjs +607 -0
- package/dist/channel/rpc_0_6.d.ts +78 -0
- package/dist/channel/rpc_0_6.mjs +543 -0
- package/dist/channel/rpc_0_7.cjs +619 -0
- package/dist/channel/rpc_0_7.d.ts +81 -0
- package/dist/channel/rpc_0_7.mjs +561 -0
- package/dist/constants.cjs +76 -0
- package/dist/constants.d.ts +70 -0
- package/dist/constants.mjs +60 -0
- package/dist/contract/contractFactory.cjs +93 -0
- package/dist/contract/contractFactory.d.ts +46 -0
- package/dist/contract/contractFactory.mjs +83 -0
- package/dist/contract/default.cjs +269 -0
- package/dist/contract/default.d.ts +58 -0
- package/dist/contract/default.mjs +254 -0
- package/dist/contract/index.cjs +38 -0
- package/dist/contract/index.d.ts +3 -0
- package/dist/contract/index.mjs +3 -0
- package/dist/contract/interface.cjs +13 -0
- package/dist/contract/interface.d.ts +128 -0
- package/dist/contract/interface.mjs +6 -0
- package/dist/index.cjs +267 -0
- package/dist/index.d.ts +45 -5991
- package/dist/index.global.js +728 -609
- package/dist/index.global.js.map +1 -1
- package/dist/index.mjs +39 -7320
- package/dist/provider/errors.cjs +50 -0
- package/dist/provider/errors.d.ts +16 -0
- package/dist/provider/errors.mjs +35 -0
- package/dist/provider/extensions/default.cjs +11 -0
- package/dist/provider/extensions/default.d.ts +6 -0
- package/dist/provider/extensions/default.mjs +5 -0
- package/dist/provider/extensions/starknetId.cjs +174 -0
- package/dist/provider/extensions/starknetId.d.ts +10 -0
- package/dist/provider/extensions/starknetId.mjs +230 -0
- package/dist/provider/index.cjs +56 -0
- package/dist/provider/index.d.ts +6 -0
- package/dist/provider/index.mjs +6 -0
- package/dist/provider/interface.cjs +8 -0
- package/dist/provider/interface.d.ts +261 -0
- package/dist/provider/interface.mjs +2 -0
- package/dist/provider/rpc.cjs +301 -0
- package/dist/provider/rpc.d.ts +115 -0
- package/dist/provider/rpc.mjs +302 -0
- package/dist/service/types.cjs +1 -0
- package/dist/service/types.d.ts +5 -0
- package/dist/service/types.mjs +0 -0
- package/dist/signer/default.cjs +105 -0
- package/dist/signer/default.d.ts +12 -0
- package/dist/signer/default.mjs +102 -0
- package/dist/signer/ethSigner.cjs +123 -0
- package/dist/signer/ethSigner.d.ts +25 -0
- package/dist/signer/ethSigner.mjs +140 -0
- package/dist/signer/index.cjs +38 -0
- package/dist/signer/index.d.ts +3 -0
- package/dist/signer/index.mjs +3 -0
- package/dist/signer/interface.cjs +8 -0
- package/dist/signer/interface.d.ts +115 -0
- package/dist/signer/interface.mjs +2 -0
- package/dist/types/account.cjs +1 -0
- package/dist/types/account.d.ts +79 -0
- package/dist/types/account.mjs +0 -0
- package/dist/types/api/index.cjs +30 -0
- package/dist/types/api/index.d.ts +4 -0
- package/dist/types/api/index.mjs +4 -0
- package/dist/types/api/jsonrpc/index.cjs +1 -0
- package/dist/types/api/jsonrpc/index.d.ts +21 -0
- package/dist/types/api/jsonrpc/index.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/components.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/components.d.ts +541 -0
- package/dist/types/api/rpcspec_0_6/components.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/contract.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/contract.d.ts +85 -0
- package/dist/types/api/rpcspec_0_6/contract.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/errors.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/errors.d.ts +128 -0
- package/dist/types/api/rpcspec_0_6/errors.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/index.cjs +45 -0
- package/dist/types/api/rpcspec_0_6/index.d.ts +8 -0
- package/dist/types/api/rpcspec_0_6/index.mjs +5 -0
- package/dist/types/api/rpcspec_0_6/methods.cjs +1 -0
- package/dist/types/api/rpcspec_0_6/methods.d.ts +207 -0
- package/dist/types/api/rpcspec_0_6/methods.mjs +0 -0
- package/dist/types/api/rpcspec_0_6/nonspec.cjs +65 -0
- package/dist/types/api/rpcspec_0_6/nonspec.d.ts +147 -0
- package/dist/types/api/rpcspec_0_6/nonspec.mjs +59 -0
- package/dist/types/cairoEnum.cjs +1 -0
- package/dist/types/cairoEnum.d.ts +2 -0
- package/dist/types/cairoEnum.mjs +0 -0
- package/dist/types/calldata.cjs +27 -0
- package/dist/types/calldata.d.ts +23 -0
- package/dist/types/calldata.mjs +21 -0
- package/dist/types/contract.cjs +1 -0
- package/dist/types/contract.d.ts +27 -0
- package/dist/types/contract.mjs +0 -0
- package/dist/types/helpers/valuesType.cjs +1 -0
- package/dist/types/helpers/valuesType.d.ts +1 -0
- package/dist/types/helpers/valuesType.mjs +0 -0
- package/dist/types/index.cjs +121 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.mjs +10 -0
- package/dist/types/lib/contract/abi.cjs +1 -0
- package/dist/types/lib/contract/abi.d.ts +71 -0
- package/dist/types/lib/contract/abi.mjs +0 -0
- package/dist/types/lib/contract/index.cjs +50 -0
- package/dist/types/lib/contract/index.d.ts +26 -0
- package/dist/types/lib/contract/index.mjs +8 -0
- package/dist/types/lib/contract/legacy.cjs +1 -0
- package/dist/types/lib/contract/legacy.d.ts +33 -0
- package/dist/types/lib/contract/legacy.mjs +0 -0
- package/dist/types/lib/contract/sierra.cjs +1 -0
- package/dist/types/lib/contract/sierra.d.ts +52 -0
- package/dist/types/lib/contract/sierra.mjs +0 -0
- package/dist/types/lib/index.cjs +61 -0
- package/dist/types/lib/index.d.ts +259 -0
- package/dist/types/lib/index.mjs +36 -0
- package/dist/types/provider/configuration.cjs +1 -0
- package/dist/types/provider/configuration.d.ts +20 -0
- package/dist/types/provider/configuration.mjs +0 -0
- package/dist/types/provider/index.cjs +27 -0
- package/dist/types/provider/index.d.ts +2 -0
- package/dist/types/provider/index.mjs +2 -0
- package/dist/types/provider/response.cjs +30 -0
- package/dist/types/provider/response.d.ts +98 -0
- package/dist/types/provider/response.mjs +1 -0
- package/dist/types/provider/spec.cjs +1 -0
- package/dist/types/provider/spec.d.ts +49 -0
- package/dist/types/provider/spec.mjs +0 -0
- package/dist/types/signer.cjs +1 -0
- package/dist/types/signer.d.ts +49 -0
- package/dist/types/signer.mjs +0 -0
- package/dist/types/transactionReceipt.cjs +1 -0
- package/dist/types/transactionReceipt.d.ts +23 -0
- package/dist/types/transactionReceipt.mjs +0 -0
- package/dist/types/typedData.cjs +12 -0
- package/dist/types/typedData.d.ts +1 -0
- package/dist/types/typedData.mjs +3 -0
- package/dist/utils/address.cjs +44 -0
- package/dist/utils/address.d.ts +55 -0
- package/dist/utils/address.mjs +35 -0
- package/dist/utils/assert.cjs +11 -0
- package/dist/utils/assert.d.ts +12 -0
- package/dist/utils/assert.mjs +5 -0
- package/dist/utils/cairoDataTypes/felt.cjs +31 -0
- package/dist/utils/cairoDataTypes/felt.d.ts +6 -0
- package/dist/utils/cairoDataTypes/felt.mjs +27 -0
- package/dist/utils/cairoDataTypes/uint256.cjs +113 -0
- package/dist/utils/cairoDataTypes/uint256.d.ts +72 -0
- package/dist/utils/cairoDataTypes/uint256.mjs +103 -0
- package/dist/utils/cairoDataTypes/uint512.cjs +125 -0
- package/dist/utils/cairoDataTypes/uint512.d.ts +76 -0
- package/dist/utils/cairoDataTypes/uint512.mjs +123 -0
- package/dist/utils/calldata/byteArray.cjs +27 -0
- package/dist/utils/calldata/byteArray.d.ts +32 -0
- package/dist/utils/calldata/byteArray.mjs +20 -0
- package/dist/utils/calldata/cairo.cjs +114 -0
- package/dist/utils/calldata/cairo.d.ts +196 -0
- package/dist/utils/calldata/cairo.mjs +68 -0
- package/dist/utils/calldata/enum/CairoCustomEnum.cjs +55 -0
- package/dist/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
- package/dist/utils/calldata/enum/CairoCustomEnum.mjs +50 -0
- package/dist/utils/calldata/enum/CairoOption.cjs +55 -0
- package/dist/utils/calldata/enum/CairoOption.d.ts +37 -0
- package/dist/utils/calldata/enum/CairoOption.mjs +50 -0
- package/dist/utils/calldata/enum/CairoResult.cjs +54 -0
- package/dist/utils/calldata/enum/CairoResult.d.ts +36 -0
- package/dist/utils/calldata/enum/CairoResult.mjs +47 -0
- package/dist/utils/calldata/enum/index.cjs +38 -0
- package/dist/utils/calldata/enum/index.d.ts +3 -0
- package/dist/utils/calldata/enum/index.mjs +3 -0
- package/dist/utils/calldata/formatter.cjs +55 -0
- package/dist/utils/calldata/formatter.d.ts +9 -0
- package/dist/utils/calldata/formatter.mjs +58 -0
- package/dist/utils/calldata/index.cjs +272 -0
- package/dist/utils/calldata/index.d.ts +90 -0
- package/dist/utils/calldata/index.mjs +276 -0
- package/dist/utils/calldata/parser/index.cjs +29 -0
- package/dist/utils/calldata/parser/index.d.ts +5 -0
- package/dist/utils/calldata/parser/index.mjs +21 -0
- package/dist/utils/calldata/parser/interface.cjs +8 -0
- package/dist/utils/calldata/parser/interface.d.ts +20 -0
- package/dist/utils/calldata/parser/interface.mjs +2 -0
- package/dist/utils/calldata/parser/parser-0-1.1.0.cjs +38 -0
- package/dist/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
- package/dist/utils/calldata/parser/parser-0-1.1.0.mjs +31 -0
- package/dist/utils/calldata/parser/parser-2.0.0.cjs +42 -0
- package/dist/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
- package/dist/utils/calldata/parser/parser-2.0.0.mjs +37 -0
- package/dist/utils/calldata/propertyOrder.cjs +159 -0
- package/dist/utils/calldata/propertyOrder.d.ts +2 -0
- package/dist/utils/calldata/propertyOrder.mjs +189 -0
- package/dist/utils/calldata/requestParser.cjs +204 -0
- package/dist/utils/calldata/requestParser.d.ts +11 -0
- package/dist/utils/calldata/requestParser.mjs +231 -0
- package/dist/utils/calldata/responseParser.cjs +200 -0
- package/dist/utils/calldata/responseParser.d.ts +11 -0
- package/dist/utils/calldata/responseParser.mjs +201 -0
- package/dist/utils/calldata/tuple.cjs +106 -0
- package/dist/utils/calldata/tuple.d.ts +6 -0
- package/dist/utils/calldata/tuple.mjs +88 -0
- package/dist/utils/calldata/validate.cjs +241 -0
- package/dist/utils/calldata/validate.d.ts +6 -0
- package/dist/utils/calldata/validate.mjs +315 -0
- package/dist/utils/contract.cjs +40 -0
- package/dist/utils/contract.d.ts +37 -0
- package/dist/utils/contract.mjs +31 -0
- package/dist/utils/ec.cjs +12 -0
- package/dist/utils/ec.d.ts +2 -0
- package/dist/utils/ec.mjs +2 -0
- package/dist/utils/encode.cjs +78 -0
- package/dist/utils/encode.d.ts +207 -0
- package/dist/utils/encode.mjs +56 -0
- package/dist/utils/eth.cjs +22 -0
- package/dist/utils/eth.d.ts +22 -0
- package/dist/utils/eth.mjs +14 -0
- package/dist/utils/events/index.cjs +144 -0
- package/dist/utils/events/index.d.ts +84 -0
- package/dist/utils/events/index.mjs +136 -0
- package/dist/utils/fetchPonyfill.cjs +14 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.mjs +5 -0
- package/dist/utils/hash/classHash.cjs +151 -0
- package/dist/utils/hash/classHash.d.ts +120 -0
- package/dist/utils/hash/classHash.mjs +168 -0
- package/dist/utils/hash/index.cjs +49 -0
- package/dist/utils/hash/index.d.ts +7 -0
- package/dist/utils/hash/index.mjs +4 -0
- package/dist/utils/hash/selector.cjs +37 -0
- package/dist/utils/hash/selector.d.ts +57 -0
- package/dist/utils/hash/selector.mjs +28 -0
- package/dist/utils/hash/transactionHash/index.cjs +38 -0
- package/dist/utils/hash/transactionHash/index.d.ts +81 -0
- package/dist/utils/hash/transactionHash/index.mjs +102 -0
- package/dist/utils/hash/transactionHash/v2.cjs +31 -0
- package/dist/utils/hash/transactionHash/v2.d.ts +34 -0
- package/dist/utils/hash/transactionHash/v2.mjs +57 -0
- package/dist/utils/hash/transactionHash/v3.cjs +45 -0
- package/dist/utils/hash/transactionHash/v3.d.ts +24 -0
- package/dist/utils/hash/transactionHash/v3.mjs +80 -0
- package/dist/utils/json.cjs +21 -0
- package/dist/utils/json.d.ts +50 -0
- package/dist/utils/json.mjs +10 -0
- package/dist/utils/merkle.cjs +118 -0
- package/dist/utils/merkle.d.ts +87 -0
- package/dist/utils/merkle.mjs +114 -0
- package/dist/utils/num.cjs +109 -0
- package/dist/utils/num.d.ts +283 -0
- package/dist/utils/num.mjs +86 -0
- package/dist/utils/provider.cjs +182 -0
- package/dist/utils/provider.d.ts +217 -0
- package/dist/utils/provider.mjs +158 -0
- package/dist/utils/responseParser/index.cjs +27 -0
- package/dist/utils/responseParser/index.d.ts +2 -0
- package/dist/utils/responseParser/index.mjs +2 -0
- package/dist/utils/responseParser/interface.cjs +8 -0
- package/dist/utils/responseParser/interface.d.ts +13 -0
- package/dist/utils/responseParser/interface.mjs +2 -0
- package/dist/utils/responseParser/rpc.cjs +83 -0
- package/dist/utils/responseParser/rpc.d.ts +19 -0
- package/dist/utils/responseParser/rpc.mjs +77 -0
- package/dist/utils/shortString.cjs +56 -0
- package/dist/utils/shortString.d.ts +116 -0
- package/dist/utils/shortString.mjs +39 -0
- package/dist/utils/stark.cjs +137 -0
- package/dist/utils/stark.d.ts +224 -0
- package/dist/utils/stark.mjs +109 -0
- package/dist/utils/starknetId.cjs +196 -0
- package/dist/utils/starknetId.d.ts +182 -0
- package/dist/utils/starknetId.mjs +185 -0
- package/dist/utils/transaction.cjs +115 -0
- package/dist/utils/transaction.d.ts +185 -0
- package/dist/utils/transaction.mjs +98 -0
- package/dist/utils/transactionReceipt.cjs +54 -0
- package/dist/utils/transactionReceipt.d.ts +33 -0
- package/dist/utils/transactionReceipt.mjs +49 -0
- package/dist/utils/typedData.cjs +285 -0
- package/dist/utils/typedData.d.ts +54 -0
- package/dist/utils/typedData.mjs +286 -0
- package/dist/utils/uint256.cjs +30 -0
- package/dist/utils/uint256.d.ts +45 -0
- package/dist/utils/uint256.mjs +11 -0
- package/dist/utils/url.cjs +35 -0
- package/dist/utils/url.d.ts +29 -0
- package/dist/utils/url.mjs +27 -0
- package/dist/wallet/account.cjs +115 -0
- package/dist/wallet/account.d.ts +31 -0
- package/dist/wallet/account.mjs +112 -0
- package/dist/wallet/connect.cjs +90 -0
- package/dist/wallet/connect.d.ts +82 -0
- package/dist/wallet/connect.mjs +64 -0
- package/dist/wallet/index.cjs +16 -0
- package/dist/wallet/index.d.ts +1 -0
- package/dist/wallet/index.mjs +1 -0
- package/dist/wallet/types.cjs +1 -0
- package/dist/wallet/types.d.ts +4 -0
- package/dist/wallet/types.mjs +0 -0
- package/package.json +13 -13
- package/dist/index.js +0 -7426
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateDeclareTransactionHash = calculateDeclareTransactionHash;
|
|
7
|
+
exports.calculateDeployAccountTransactionHash = calculateDeployAccountTransactionHash;
|
|
8
|
+
exports.calculateInvokeTransactionHash = calculateInvokeTransactionHash;
|
|
9
|
+
var _api = require("../../../types/api/index.cjs");
|
|
10
|
+
var _v = require("./v2.cjs");
|
|
11
|
+
var _v2 = require("./v3.cjs");
|
|
12
|
+
function isV3InvokeTx(args) {
|
|
13
|
+
return [_api.ETransactionVersion.V3, _api.ETransactionVersion.F3].includes(args.version);
|
|
14
|
+
}
|
|
15
|
+
function calculateInvokeTransactionHash(args) {
|
|
16
|
+
if (isV3InvokeTx(args)) {
|
|
17
|
+
return (0, _v2.calculateInvokeTransactionHash)(args.senderAddress, args.version, args.compiledCalldata, args.chainId, args.nonce, args.accountDeploymentData, args.nonceDataAvailabilityMode, args.feeDataAvailabilityMode, args.resourceBounds, args.tip, args.paymasterData);
|
|
18
|
+
}
|
|
19
|
+
return (0, _v.calculateTransactionHash)(args.senderAddress, args.version, args.compiledCalldata, args.maxFee, args.chainId, args.nonce);
|
|
20
|
+
}
|
|
21
|
+
function isV3DeclareTx(args) {
|
|
22
|
+
return [_api.ETransactionVersion.V3, _api.ETransactionVersion.F3].includes(args.version);
|
|
23
|
+
}
|
|
24
|
+
function calculateDeclareTransactionHash(args) {
|
|
25
|
+
if (isV3DeclareTx(args)) {
|
|
26
|
+
return (0, _v2.calculateDeclareTransactionHash)(args.classHash, args.compiledClassHash, args.senderAddress, args.version, args.chainId, args.nonce, args.accountDeploymentData, args.nonceDataAvailabilityMode, args.feeDataAvailabilityMode, args.resourceBounds, args.tip, args.paymasterData);
|
|
27
|
+
}
|
|
28
|
+
return (0, _v.calculateDeclareTransactionHash)(args.classHash, args.senderAddress, args.version, args.maxFee, args.chainId, args.nonce, args.compiledClassHash);
|
|
29
|
+
}
|
|
30
|
+
function isV3DeployAccountTx(args) {
|
|
31
|
+
return [_api.ETransactionVersion.V3, _api.ETransactionVersion.F3].includes(args.version);
|
|
32
|
+
}
|
|
33
|
+
function calculateDeployAccountTransactionHash(args) {
|
|
34
|
+
if (isV3DeployAccountTx(args)) {
|
|
35
|
+
return (0, _v2.calculateDeployAccountTransactionHash)(args.contractAddress, args.classHash, args.compiledConstructorCalldata, args.salt, args.version, args.chainId, args.nonce, args.nonceDataAvailabilityMode, args.feeDataAvailabilityMode, args.resourceBounds, args.tip, args.paymasterData);
|
|
36
|
+
}
|
|
37
|
+
return (0, _v.calculateDeployAccountTransactionHash)(args.contractAddress, args.classHash, args.constructorCalldata, args.salt, args.version, args.maxFee, args.chainId, args.nonce);
|
|
38
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Hash based on Transaction Version
|
|
3
|
+
*/
|
|
4
|
+
import { StarknetChainId } from '../../../constants';
|
|
5
|
+
import { BigNumberish, Calldata } from '../../../types';
|
|
6
|
+
import { EDAMode, ETransactionVersion2, ETransactionVersion3, ResourceBounds } from '../../../types/api';
|
|
7
|
+
type CalcV2InvokeTxHashArgs = {
|
|
8
|
+
senderAddress: BigNumberish;
|
|
9
|
+
version: `${ETransactionVersion2}`;
|
|
10
|
+
compiledCalldata: Calldata;
|
|
11
|
+
maxFee: BigNumberish;
|
|
12
|
+
chainId: StarknetChainId;
|
|
13
|
+
nonce: BigNumberish;
|
|
14
|
+
};
|
|
15
|
+
type CalcV3InvokeTxHashArgs = {
|
|
16
|
+
senderAddress: BigNumberish;
|
|
17
|
+
version: `${ETransactionVersion3}`;
|
|
18
|
+
compiledCalldata: Calldata;
|
|
19
|
+
chainId: StarknetChainId;
|
|
20
|
+
nonce: BigNumberish;
|
|
21
|
+
accountDeploymentData: BigNumberish[];
|
|
22
|
+
nonceDataAvailabilityMode: EDAMode;
|
|
23
|
+
feeDataAvailabilityMode: EDAMode;
|
|
24
|
+
resourceBounds: ResourceBounds;
|
|
25
|
+
tip: BigNumberish;
|
|
26
|
+
paymasterData: BigNumberish[];
|
|
27
|
+
};
|
|
28
|
+
type CalcInvokeTxHashArgs = CalcV2InvokeTxHashArgs | CalcV3InvokeTxHashArgs;
|
|
29
|
+
export declare function calculateInvokeTransactionHash(args: CalcInvokeTxHashArgs): string;
|
|
30
|
+
type CalcV2DeclareTxHashArgs = {
|
|
31
|
+
classHash: string;
|
|
32
|
+
senderAddress: BigNumberish;
|
|
33
|
+
version: `${ETransactionVersion2}`;
|
|
34
|
+
maxFee: BigNumberish;
|
|
35
|
+
chainId: StarknetChainId;
|
|
36
|
+
nonce: BigNumberish;
|
|
37
|
+
compiledClassHash?: string;
|
|
38
|
+
};
|
|
39
|
+
type CalcV3DeclareTxHashArgs = {
|
|
40
|
+
classHash: string;
|
|
41
|
+
compiledClassHash: string;
|
|
42
|
+
senderAddress: BigNumberish;
|
|
43
|
+
version: `${ETransactionVersion3}`;
|
|
44
|
+
chainId: StarknetChainId;
|
|
45
|
+
nonce: BigNumberish;
|
|
46
|
+
accountDeploymentData: BigNumberish[];
|
|
47
|
+
nonceDataAvailabilityMode: EDAMode;
|
|
48
|
+
feeDataAvailabilityMode: EDAMode;
|
|
49
|
+
resourceBounds: ResourceBounds;
|
|
50
|
+
tip: BigNumberish;
|
|
51
|
+
paymasterData: BigNumberish[];
|
|
52
|
+
};
|
|
53
|
+
type CalcDeclareTxHashArgs = CalcV2DeclareTxHashArgs | CalcV3DeclareTxHashArgs;
|
|
54
|
+
export declare function calculateDeclareTransactionHash(args: CalcDeclareTxHashArgs): string;
|
|
55
|
+
type CalcV2DeployAccountTxHashArgs = {
|
|
56
|
+
contractAddress: BigNumberish;
|
|
57
|
+
classHash: BigNumberish;
|
|
58
|
+
constructorCalldata: Calldata;
|
|
59
|
+
salt: BigNumberish;
|
|
60
|
+
version: `${ETransactionVersion2}`;
|
|
61
|
+
maxFee: BigNumberish;
|
|
62
|
+
chainId: StarknetChainId;
|
|
63
|
+
nonce: BigNumberish;
|
|
64
|
+
};
|
|
65
|
+
type CalcV3DeployAccountTxHashArgs = {
|
|
66
|
+
contractAddress: BigNumberish;
|
|
67
|
+
classHash: BigNumberish;
|
|
68
|
+
compiledConstructorCalldata: Calldata;
|
|
69
|
+
salt: BigNumberish;
|
|
70
|
+
version: `${ETransactionVersion3}`;
|
|
71
|
+
chainId: StarknetChainId;
|
|
72
|
+
nonce: BigNumberish;
|
|
73
|
+
nonceDataAvailabilityMode: EDAMode;
|
|
74
|
+
feeDataAvailabilityMode: EDAMode;
|
|
75
|
+
resourceBounds: ResourceBounds;
|
|
76
|
+
tip: BigNumberish;
|
|
77
|
+
paymasterData: BigNumberish[];
|
|
78
|
+
};
|
|
79
|
+
type CalcDeployAccountTxHashArgs = CalcV2DeployAccountTxHashArgs | CalcV3DeployAccountTxHashArgs;
|
|
80
|
+
export declare function calculateDeployAccountTransactionHash(args: CalcDeployAccountTxHashArgs): string;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ETransactionVersion
|
|
3
|
+
} from "../../../types/api/index.mjs";
|
|
4
|
+
import {
|
|
5
|
+
calculateDeclareTransactionHash as v2calculateDeclareTransactionHash,
|
|
6
|
+
calculateDeployAccountTransactionHash as v2calculateDeployAccountTransactionHash,
|
|
7
|
+
calculateTransactionHash as v2calculateInvokeTransactionHash
|
|
8
|
+
} from "./v2.mjs";
|
|
9
|
+
import {
|
|
10
|
+
calculateDeclareTransactionHash as v3calculateDeclareTransactionHash,
|
|
11
|
+
calculateDeployAccountTransactionHash as v3calculateDeployAccountTransactionHash,
|
|
12
|
+
calculateInvokeTransactionHash as v3calculateInvokeTransactionHash
|
|
13
|
+
} from "./v3.mjs";
|
|
14
|
+
function isV3InvokeTx(args) {
|
|
15
|
+
return [ETransactionVersion.V3, ETransactionVersion.F3].includes(args.version);
|
|
16
|
+
}
|
|
17
|
+
export function calculateInvokeTransactionHash(args) {
|
|
18
|
+
if (isV3InvokeTx(args)) {
|
|
19
|
+
return v3calculateInvokeTransactionHash(
|
|
20
|
+
args.senderAddress,
|
|
21
|
+
args.version,
|
|
22
|
+
args.compiledCalldata,
|
|
23
|
+
args.chainId,
|
|
24
|
+
args.nonce,
|
|
25
|
+
args.accountDeploymentData,
|
|
26
|
+
args.nonceDataAvailabilityMode,
|
|
27
|
+
args.feeDataAvailabilityMode,
|
|
28
|
+
args.resourceBounds,
|
|
29
|
+
args.tip,
|
|
30
|
+
args.paymasterData
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return v2calculateInvokeTransactionHash(
|
|
34
|
+
args.senderAddress,
|
|
35
|
+
args.version,
|
|
36
|
+
args.compiledCalldata,
|
|
37
|
+
args.maxFee,
|
|
38
|
+
args.chainId,
|
|
39
|
+
args.nonce
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function isV3DeclareTx(args) {
|
|
43
|
+
return [ETransactionVersion.V3, ETransactionVersion.F3].includes(args.version);
|
|
44
|
+
}
|
|
45
|
+
export function calculateDeclareTransactionHash(args) {
|
|
46
|
+
if (isV3DeclareTx(args)) {
|
|
47
|
+
return v3calculateDeclareTransactionHash(
|
|
48
|
+
args.classHash,
|
|
49
|
+
args.compiledClassHash,
|
|
50
|
+
args.senderAddress,
|
|
51
|
+
args.version,
|
|
52
|
+
args.chainId,
|
|
53
|
+
args.nonce,
|
|
54
|
+
args.accountDeploymentData,
|
|
55
|
+
args.nonceDataAvailabilityMode,
|
|
56
|
+
args.feeDataAvailabilityMode,
|
|
57
|
+
args.resourceBounds,
|
|
58
|
+
args.tip,
|
|
59
|
+
args.paymasterData
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return v2calculateDeclareTransactionHash(
|
|
63
|
+
args.classHash,
|
|
64
|
+
args.senderAddress,
|
|
65
|
+
args.version,
|
|
66
|
+
args.maxFee,
|
|
67
|
+
args.chainId,
|
|
68
|
+
args.nonce,
|
|
69
|
+
args.compiledClassHash
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
function isV3DeployAccountTx(args) {
|
|
73
|
+
return [ETransactionVersion.V3, ETransactionVersion.F3].includes(args.version);
|
|
74
|
+
}
|
|
75
|
+
export function calculateDeployAccountTransactionHash(args) {
|
|
76
|
+
if (isV3DeployAccountTx(args)) {
|
|
77
|
+
return v3calculateDeployAccountTransactionHash(
|
|
78
|
+
args.contractAddress,
|
|
79
|
+
args.classHash,
|
|
80
|
+
args.compiledConstructorCalldata,
|
|
81
|
+
args.salt,
|
|
82
|
+
args.version,
|
|
83
|
+
args.chainId,
|
|
84
|
+
args.nonce,
|
|
85
|
+
args.nonceDataAvailabilityMode,
|
|
86
|
+
args.feeDataAvailabilityMode,
|
|
87
|
+
args.resourceBounds,
|
|
88
|
+
args.tip,
|
|
89
|
+
args.paymasterData
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return v2calculateDeployAccountTransactionHash(
|
|
93
|
+
args.contractAddress,
|
|
94
|
+
args.classHash,
|
|
95
|
+
args.constructorCalldata,
|
|
96
|
+
args.salt,
|
|
97
|
+
args.version,
|
|
98
|
+
args.maxFee,
|
|
99
|
+
args.chainId,
|
|
100
|
+
args.nonce
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateDeclareTransactionHash = calculateDeclareTransactionHash;
|
|
7
|
+
exports.calculateDeployAccountTransactionHash = calculateDeployAccountTransactionHash;
|
|
8
|
+
exports.calculateTransactionHash = calculateTransactionHash;
|
|
9
|
+
exports.calculateTransactionHashCommon = calculateTransactionHashCommon;
|
|
10
|
+
exports.computeHashOnElements = computeHashOnElements;
|
|
11
|
+
var _constants = require("../../../constants.cjs");
|
|
12
|
+
var _ec = require("../../ec.cjs");
|
|
13
|
+
var _num = require("../../num.cjs");
|
|
14
|
+
function computeHashOnElements(data) {
|
|
15
|
+
return [...data, data.length].reduce((x, y) => _ec.starkCurve.pedersen((0, _num.toBigInt)(x), (0, _num.toBigInt)(y)), 0).toString();
|
|
16
|
+
}
|
|
17
|
+
function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
18
|
+
const calldataHash = computeHashOnElements(calldata);
|
|
19
|
+
const dataToHash = [txHashPrefix, version, contractAddress, entryPointSelector, calldataHash, maxFee, chainId, ...additionalData];
|
|
20
|
+
return computeHashOnElements(dataToHash);
|
|
21
|
+
}
|
|
22
|
+
function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
23
|
+
return calculateTransactionHashCommon(_constants.TransactionHashPrefix.DECLARE, version, senderAddress, 0, [classHash], maxFee, chainId, [nonce, ...(compiledClassHash ? [compiledClassHash] : [])]);
|
|
24
|
+
}
|
|
25
|
+
function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
26
|
+
const calldata = [classHash, salt, ...constructorCalldata];
|
|
27
|
+
return calculateTransactionHashCommon(_constants.TransactionHashPrefix.DEPLOY_ACCOUNT, version, contractAddress, 0, calldata, maxFee, chainId, [nonce]);
|
|
28
|
+
}
|
|
29
|
+
function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
30
|
+
return calculateTransactionHashCommon(_constants.TransactionHashPrefix.INVOKE, version, contractAddress, 0, calldata, maxFee, chainId, [nonce]);
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate Hashes for v0 - v2 transactions
|
|
3
|
+
*/
|
|
4
|
+
import { StarknetChainId, TransactionHashPrefix } from '../../../constants';
|
|
5
|
+
import { BigNumberish, RawCalldata } from '../../../types';
|
|
6
|
+
/**
|
|
7
|
+
* Compute pedersen hash from data
|
|
8
|
+
* @returns format: hex-string - pedersen hash
|
|
9
|
+
*/
|
|
10
|
+
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate transaction pedersen hash for common properties
|
|
13
|
+
*
|
|
14
|
+
* Following implementation is based on this python [implementation #](https://github.com/starkware-libs/cairo-lang/blob/b614d1867c64f3fb2cf4a4879348cfcf87c3a5a7/src/starkware/starknet/core/os/transaction_hash/transaction_hash.py)
|
|
15
|
+
* @returns format: hex-string
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, contractAddress: BigNumberish, entryPointSelector: BigNumberish, calldata: RawCalldata, maxFee: BigNumberish, chainId: StarknetChainId, additionalData?: BigNumberish[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate declare transaction hash
|
|
20
|
+
* @param classHash hex-string
|
|
21
|
+
* @param compiledClassHash hex-string
|
|
22
|
+
* @returns format: hex-string
|
|
23
|
+
*/
|
|
24
|
+
export declare function calculateDeclareTransactionHash(classHash: string, senderAddress: BigNumberish, version: BigNumberish, maxFee: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish, compiledClassHash?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Calculate deploy_account transaction hash
|
|
27
|
+
* @returns format: hex-string
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateDeployAccountTransactionHash(contractAddress: BigNumberish, classHash: BigNumberish, constructorCalldata: RawCalldata, salt: BigNumberish, version: BigNumberish, maxFee: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish): string;
|
|
30
|
+
/**
|
|
31
|
+
* Calculate invoke transaction hash
|
|
32
|
+
* @returns format: hex-string
|
|
33
|
+
*/
|
|
34
|
+
export declare function calculateTransactionHash(contractAddress: BigNumberish, version: BigNumberish, calldata: RawCalldata, maxFee: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TransactionHashPrefix } from "../../../constants.mjs";
|
|
2
|
+
import { starkCurve } from "../../ec.mjs";
|
|
3
|
+
import { toBigInt } from "../../num.mjs";
|
|
4
|
+
export function computeHashOnElements(data) {
|
|
5
|
+
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
|
|
6
|
+
}
|
|
7
|
+
export function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
|
|
8
|
+
const calldataHash = computeHashOnElements(calldata);
|
|
9
|
+
const dataToHash = [
|
|
10
|
+
txHashPrefix,
|
|
11
|
+
version,
|
|
12
|
+
contractAddress,
|
|
13
|
+
entryPointSelector,
|
|
14
|
+
calldataHash,
|
|
15
|
+
maxFee,
|
|
16
|
+
chainId,
|
|
17
|
+
...additionalData
|
|
18
|
+
];
|
|
19
|
+
return computeHashOnElements(dataToHash);
|
|
20
|
+
}
|
|
21
|
+
export function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
|
|
22
|
+
return calculateTransactionHashCommon(
|
|
23
|
+
TransactionHashPrefix.DECLARE,
|
|
24
|
+
version,
|
|
25
|
+
senderAddress,
|
|
26
|
+
0,
|
|
27
|
+
[classHash],
|
|
28
|
+
maxFee,
|
|
29
|
+
chainId,
|
|
30
|
+
[nonce, ...compiledClassHash ? [compiledClassHash] : []]
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
export function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
|
|
34
|
+
const calldata = [classHash, salt, ...constructorCalldata];
|
|
35
|
+
return calculateTransactionHashCommon(
|
|
36
|
+
TransactionHashPrefix.DEPLOY_ACCOUNT,
|
|
37
|
+
version,
|
|
38
|
+
contractAddress,
|
|
39
|
+
0,
|
|
40
|
+
calldata,
|
|
41
|
+
maxFee,
|
|
42
|
+
chainId,
|
|
43
|
+
[nonce]
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
export function calculateTransactionHash(contractAddress, version, calldata, maxFee, chainId, nonce) {
|
|
47
|
+
return calculateTransactionHashCommon(
|
|
48
|
+
TransactionHashPrefix.INVOKE,
|
|
49
|
+
version,
|
|
50
|
+
contractAddress,
|
|
51
|
+
0,
|
|
52
|
+
calldata,
|
|
53
|
+
maxFee,
|
|
54
|
+
chainId,
|
|
55
|
+
[nonce]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateDeclareTransactionHash = calculateDeclareTransactionHash;
|
|
7
|
+
exports.calculateDeployAccountTransactionHash = calculateDeployAccountTransactionHash;
|
|
8
|
+
exports.calculateInvokeTransactionHash = calculateInvokeTransactionHash;
|
|
9
|
+
exports.calculateTransactionHashCommon = calculateTransactionHashCommon;
|
|
10
|
+
exports.hashDAMode = hashDAMode;
|
|
11
|
+
exports.hashFeeField = hashFeeField;
|
|
12
|
+
var _starknet = require("@scure/starknet");
|
|
13
|
+
var _constants = require("../../../constants.cjs");
|
|
14
|
+
var _num = require("../../num.cjs");
|
|
15
|
+
var _shortString = require("../../shortString.cjs");
|
|
16
|
+
const AToBI = array => array.map(it => BigInt(it));
|
|
17
|
+
const DATA_AVAILABILITY_MODE_BITS = 32n;
|
|
18
|
+
const MAX_AMOUNT_BITS = 64n;
|
|
19
|
+
const MAX_PRICE_PER_UNIT_BITS = 128n;
|
|
20
|
+
const RESOURCE_VALUE_OFFSET = MAX_AMOUNT_BITS + MAX_PRICE_PER_UNIT_BITS;
|
|
21
|
+
const L1_GAS_NAME = BigInt((0, _shortString.encodeShortString)("L1_GAS"));
|
|
22
|
+
const L2_GAS_NAME = BigInt((0, _shortString.encodeShortString)("L2_GAS"));
|
|
23
|
+
function hashDAMode(nonceDAMode, feeDAMode) {
|
|
24
|
+
return (BigInt(nonceDAMode) << DATA_AVAILABILITY_MODE_BITS) + BigInt(feeDAMode);
|
|
25
|
+
}
|
|
26
|
+
function hashFeeField(tip, bounds) {
|
|
27
|
+
const L1Bound = (L1_GAS_NAME << RESOURCE_VALUE_OFFSET) + (BigInt(bounds.l1_gas.max_amount) << MAX_PRICE_PER_UNIT_BITS) + BigInt(bounds.l1_gas.max_price_per_unit);
|
|
28
|
+
const L2Bound = (L2_GAS_NAME << RESOURCE_VALUE_OFFSET) + (BigInt(bounds.l2_gas.max_amount) << MAX_PRICE_PER_UNIT_BITS) + BigInt(bounds.l2_gas.max_price_per_unit);
|
|
29
|
+
return (0, _starknet.poseidonHashMany)([BigInt(tip), L1Bound, L2Bound]);
|
|
30
|
+
}
|
|
31
|
+
function calculateTransactionHashCommon(txHashPrefix, version, senderAddress, chainId, nonce, tip, paymasterData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, additionalData = []) {
|
|
32
|
+
const feeFieldHash = hashFeeField(tip, resourceBounds);
|
|
33
|
+
const dAModeHash = hashDAMode(nonceDataAvailabilityMode, feeDataAvailabilityMode);
|
|
34
|
+
const dataToHash = AToBI([txHashPrefix, version, senderAddress, feeFieldHash, (0, _starknet.poseidonHashMany)(AToBI(paymasterData)), chainId, nonce, dAModeHash, ...AToBI(additionalData)]);
|
|
35
|
+
return (0, _num.toHex)((0, _starknet.poseidonHashMany)(dataToHash));
|
|
36
|
+
}
|
|
37
|
+
function calculateDeployAccountTransactionHash(contractAddress, classHash, compiledConstructorCalldata, salt, version, chainId, nonce, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, tip, paymasterData) {
|
|
38
|
+
return calculateTransactionHashCommon(_constants.TransactionHashPrefix.DEPLOY_ACCOUNT, version, contractAddress, chainId, nonce, tip, paymasterData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, [(0, _starknet.poseidonHashMany)(AToBI(compiledConstructorCalldata)), classHash, salt]);
|
|
39
|
+
}
|
|
40
|
+
function calculateDeclareTransactionHash(classHash, compiledClassHash, senderAddress, version, chainId, nonce, accountDeploymentData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, tip, paymasterData) {
|
|
41
|
+
return calculateTransactionHashCommon(_constants.TransactionHashPrefix.DECLARE, version, senderAddress, chainId, nonce, tip, AToBI(paymasterData), nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, [(0, _starknet.poseidonHashMany)(AToBI(accountDeploymentData)), classHash, compiledClassHash]);
|
|
42
|
+
}
|
|
43
|
+
function calculateInvokeTransactionHash(senderAddress, version, compiledCalldata, chainId, nonce, accountDeploymentData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, tip, paymasterData) {
|
|
44
|
+
return calculateTransactionHashCommon(_constants.TransactionHashPrefix.INVOKE, version, senderAddress, chainId, nonce, tip, paymasterData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, [(0, _starknet.poseidonHashMany)(AToBI(accountDeploymentData)), (0, _starknet.poseidonHashMany)(AToBI(compiledCalldata))]);
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate Hashes for v3 transactions
|
|
3
|
+
*/
|
|
4
|
+
import { StarknetChainId, TransactionHashPrefix } from '../../../constants';
|
|
5
|
+
import { BigNumberish, Calldata } from '../../../types';
|
|
6
|
+
import { EDAMode, ResourceBounds } from '../../../types/api';
|
|
7
|
+
export declare function hashDAMode(nonceDAMode: BigNumberish, feeDAMode: BigNumberish): bigint;
|
|
8
|
+
export declare function hashFeeField(tip: BigNumberish, bounds: ResourceBounds): bigint;
|
|
9
|
+
export declare function calculateTransactionHashCommon(txHashPrefix: TransactionHashPrefix, version: BigNumberish, senderAddress: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish, tip: BigNumberish, paymasterData: BigNumberish[], nonceDataAvailabilityMode: EDAMode, feeDataAvailabilityMode: EDAMode, resourceBounds: ResourceBounds, additionalData?: BigNumberish[]): string;
|
|
10
|
+
/**
|
|
11
|
+
* Calculate v3 deploy_account transaction hash
|
|
12
|
+
* @returns format: hex-string
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateDeployAccountTransactionHash(contractAddress: BigNumberish, classHash: BigNumberish, compiledConstructorCalldata: Calldata, salt: BigNumberish, version: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish, nonceDataAvailabilityMode: EDAMode, feeDataAvailabilityMode: EDAMode, resourceBounds: ResourceBounds, tip: BigNumberish, paymasterData: BigNumberish[]): string;
|
|
15
|
+
/**
|
|
16
|
+
* Calculate v3 declare transaction hash
|
|
17
|
+
* @returns format: hex-string
|
|
18
|
+
*/
|
|
19
|
+
export declare function calculateDeclareTransactionHash(classHash: string, compiledClassHash: string, senderAddress: BigNumberish, version: BigNumberish, chainId: StarknetChainId, nonce: BigNumberish, accountDeploymentData: BigNumberish[], nonceDataAvailabilityMode: EDAMode, feeDataAvailabilityMode: EDAMode, resourceBounds: ResourceBounds, tip: BigNumberish, paymasterData: BigNumberish[]): string;
|
|
20
|
+
/**
|
|
21
|
+
* Calculate v3 invoke transaction hash
|
|
22
|
+
* @returns format: hex-string
|
|
23
|
+
*/
|
|
24
|
+
export declare function calculateInvokeTransactionHash(senderAddress: BigNumberish, version: BigNumberish, compiledCalldata: Calldata, chainId: StarknetChainId, nonce: BigNumberish, accountDeploymentData: BigNumberish[], nonceDataAvailabilityMode: EDAMode, feeDataAvailabilityMode: EDAMode, resourceBounds: ResourceBounds, tip: BigNumberish, paymasterData: BigNumberish[]): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { poseidonHashMany } from "@scure/starknet";
|
|
2
|
+
import { TransactionHashPrefix } from "../../../constants.mjs";
|
|
3
|
+
import { toHex } from "../../num.mjs";
|
|
4
|
+
import { encodeShortString } from "../../shortString.mjs";
|
|
5
|
+
const AToBI = (array) => array.map((it) => BigInt(it));
|
|
6
|
+
const DATA_AVAILABILITY_MODE_BITS = 32n;
|
|
7
|
+
const MAX_AMOUNT_BITS = 64n;
|
|
8
|
+
const MAX_PRICE_PER_UNIT_BITS = 128n;
|
|
9
|
+
const RESOURCE_VALUE_OFFSET = MAX_AMOUNT_BITS + MAX_PRICE_PER_UNIT_BITS;
|
|
10
|
+
const L1_GAS_NAME = BigInt(encodeShortString("L1_GAS"));
|
|
11
|
+
const L2_GAS_NAME = BigInt(encodeShortString("L2_GAS"));
|
|
12
|
+
export function hashDAMode(nonceDAMode, feeDAMode) {
|
|
13
|
+
return (BigInt(nonceDAMode) << DATA_AVAILABILITY_MODE_BITS) + BigInt(feeDAMode);
|
|
14
|
+
}
|
|
15
|
+
export function hashFeeField(tip, bounds) {
|
|
16
|
+
const L1Bound = (L1_GAS_NAME << RESOURCE_VALUE_OFFSET) + (BigInt(bounds.l1_gas.max_amount) << MAX_PRICE_PER_UNIT_BITS) + BigInt(bounds.l1_gas.max_price_per_unit);
|
|
17
|
+
const L2Bound = (L2_GAS_NAME << RESOURCE_VALUE_OFFSET) + (BigInt(bounds.l2_gas.max_amount) << MAX_PRICE_PER_UNIT_BITS) + BigInt(bounds.l2_gas.max_price_per_unit);
|
|
18
|
+
return poseidonHashMany([BigInt(tip), L1Bound, L2Bound]);
|
|
19
|
+
}
|
|
20
|
+
export function calculateTransactionHashCommon(txHashPrefix, version, senderAddress, chainId, nonce, tip, paymasterData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, additionalData = []) {
|
|
21
|
+
const feeFieldHash = hashFeeField(tip, resourceBounds);
|
|
22
|
+
const dAModeHash = hashDAMode(nonceDataAvailabilityMode, feeDataAvailabilityMode);
|
|
23
|
+
const dataToHash = AToBI([
|
|
24
|
+
txHashPrefix,
|
|
25
|
+
version,
|
|
26
|
+
senderAddress,
|
|
27
|
+
feeFieldHash,
|
|
28
|
+
poseidonHashMany(AToBI(paymasterData)),
|
|
29
|
+
chainId,
|
|
30
|
+
nonce,
|
|
31
|
+
dAModeHash,
|
|
32
|
+
...AToBI(additionalData)
|
|
33
|
+
]);
|
|
34
|
+
return toHex(poseidonHashMany(dataToHash));
|
|
35
|
+
}
|
|
36
|
+
export function calculateDeployAccountTransactionHash(contractAddress, classHash, compiledConstructorCalldata, salt, version, chainId, nonce, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, tip, paymasterData) {
|
|
37
|
+
return calculateTransactionHashCommon(
|
|
38
|
+
TransactionHashPrefix.DEPLOY_ACCOUNT,
|
|
39
|
+
version,
|
|
40
|
+
contractAddress,
|
|
41
|
+
chainId,
|
|
42
|
+
nonce,
|
|
43
|
+
tip,
|
|
44
|
+
paymasterData,
|
|
45
|
+
nonceDataAvailabilityMode,
|
|
46
|
+
feeDataAvailabilityMode,
|
|
47
|
+
resourceBounds,
|
|
48
|
+
[poseidonHashMany(AToBI(compiledConstructorCalldata)), classHash, salt]
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
export function calculateDeclareTransactionHash(classHash, compiledClassHash, senderAddress, version, chainId, nonce, accountDeploymentData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, tip, paymasterData) {
|
|
52
|
+
return calculateTransactionHashCommon(
|
|
53
|
+
TransactionHashPrefix.DECLARE,
|
|
54
|
+
version,
|
|
55
|
+
senderAddress,
|
|
56
|
+
chainId,
|
|
57
|
+
nonce,
|
|
58
|
+
tip,
|
|
59
|
+
AToBI(paymasterData),
|
|
60
|
+
nonceDataAvailabilityMode,
|
|
61
|
+
feeDataAvailabilityMode,
|
|
62
|
+
resourceBounds,
|
|
63
|
+
[poseidonHashMany(AToBI(accountDeploymentData)), classHash, compiledClassHash]
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
export function calculateInvokeTransactionHash(senderAddress, version, compiledCalldata, chainId, nonce, accountDeploymentData, nonceDataAvailabilityMode, feeDataAvailabilityMode, resourceBounds, tip, paymasterData) {
|
|
67
|
+
return calculateTransactionHashCommon(
|
|
68
|
+
TransactionHashPrefix.INVOKE,
|
|
69
|
+
version,
|
|
70
|
+
senderAddress,
|
|
71
|
+
chainId,
|
|
72
|
+
nonce,
|
|
73
|
+
tip,
|
|
74
|
+
paymasterData,
|
|
75
|
+
nonceDataAvailabilityMode,
|
|
76
|
+
feeDataAvailabilityMode,
|
|
77
|
+
resourceBounds,
|
|
78
|
+
[poseidonHashMany(AToBI(accountDeploymentData)), poseidonHashMany(AToBI(compiledCalldata))]
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stringifyAlwaysAsBig = exports.stringify = exports.parseAlwaysAsBig = exports.parse = void 0;
|
|
7
|
+
var json = _interopRequireWildcard(require("lossless-json"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
const parseIntAsNumberOrBigInt = str => {
|
|
11
|
+
if (!json.isInteger(str)) return parseFloat(str);
|
|
12
|
+
const num = parseInt(str, 10);
|
|
13
|
+
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
14
|
+
};
|
|
15
|
+
const parse = str => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
16
|
+
exports.parse = parse;
|
|
17
|
+
const parseAlwaysAsBig = str => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
18
|
+
exports.parseAlwaysAsBig = parseAlwaysAsBig;
|
|
19
|
+
const stringify = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
20
|
+
exports.stringify = stringify;
|
|
21
|
+
const stringifyAlwaysAsBig = exports.stringifyAlwaysAsBig = stringify;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as json from 'lossless-json';
|
|
2
|
+
/**
|
|
3
|
+
* Convert JSON string to JSON object
|
|
4
|
+
*
|
|
5
|
+
* NOTE: the String() wrapping is used so the behavior conforms to JSON.parse()
|
|
6
|
+
* which can accept simple data types but is not represented in the default typing
|
|
7
|
+
*
|
|
8
|
+
* @param str JSON string
|
|
9
|
+
* @return {object} Parsed json object
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const str = '[123, 12.3, 11223344556677889900]';
|
|
13
|
+
* const result = parse(str);
|
|
14
|
+
* // result = [123, 12.3, 11223344556677890048n]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const parse: (str: string) => any;
|
|
18
|
+
/**
|
|
19
|
+
* Convert JSON string to JSON object with all numbers as bigint
|
|
20
|
+
* @param str JSON string
|
|
21
|
+
* @return {object} Parsed json object
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const str = '[123, 12.3, 1234567890]';
|
|
25
|
+
* const result = parseAlwaysAsBig(str);
|
|
26
|
+
* // result = [123n, 12.3, 1234567890n]
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const parseAlwaysAsBig: (str: string) => any;
|
|
30
|
+
/**
|
|
31
|
+
* Convert JSON object to JSON string
|
|
32
|
+
*
|
|
33
|
+
* NOTE: the not-null assertion is used so the return type conforms to JSON.stringify()
|
|
34
|
+
* which can also return undefined but is not represented in the default typing
|
|
35
|
+
*
|
|
36
|
+
* @param value JSON object
|
|
37
|
+
* @param [replacer] Function that alters the behavior of the stringification process
|
|
38
|
+
* @param [space] Used to insert white space into the output JSON string
|
|
39
|
+
* @param [numberStringifiers] Function used to stringify numbers (returning undefined will delete the property from the object)
|
|
40
|
+
* @return {string} JSON string
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const value = [123, 12.3, 1234567890];
|
|
44
|
+
* const result = stringify(value);
|
|
45
|
+
* // result = '[123,12.3,1234567890]'
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const stringify: (value: unknown, replacer?: any, space?: string | number | undefined, numberStringifiers?: json.NumberStringifier[] | undefined) => string;
|
|
49
|
+
/** @deprecated equivalent to 'stringify', alias will be removed */
|
|
50
|
+
export declare const stringifyAlwaysAsBig: (value: unknown, replacer?: any, space?: string | number | undefined, numberStringifiers?: json.NumberStringifier[] | undefined) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as json from "lossless-json";
|
|
2
|
+
const parseIntAsNumberOrBigInt = (str) => {
|
|
3
|
+
if (!json.isInteger(str)) return parseFloat(str);
|
|
4
|
+
const num = parseInt(str, 10);
|
|
5
|
+
return Number.isSafeInteger(num) ? num : BigInt(str);
|
|
6
|
+
};
|
|
7
|
+
export const parse = (str) => json.parse(String(str), void 0, parseIntAsNumberOrBigInt);
|
|
8
|
+
export const parseAlwaysAsBig = (str) => json.parse(String(str), void 0, json.parseNumberAndBigInt);
|
|
9
|
+
export const stringify = (value, replacer, space, numberStringifiers) => json.stringify(value, replacer, space, numberStringifiers);
|
|
10
|
+
export const stringifyAlwaysAsBig = stringify;
|