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,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _fetchCookie = _interopRequireDefault(require("fetch-cookie"));
|
|
8
|
+
var _isomorphicFetch = _interopRequireDefault(require("isomorphic-fetch"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
module.exports = typeof window !== "undefined" && window.fetch ||
|
|
11
|
+
// use buildin fetch in browser if available
|
|
12
|
+
typeof global !== "undefined" && (0, _fetchCookie.default)(global.fetch) ||
|
|
13
|
+
// use buildin fetch in node, react-native and service worker if available
|
|
14
|
+
_isomorphicFetch.default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import makeFetchCookie from "fetch-cookie";
|
|
2
|
+
import isomorphicFetch from "isomorphic-fetch";
|
|
3
|
+
export default typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
|
|
4
|
+
typeof global !== "undefined" && makeFetchCookie(global.fetch) || // use buildin fetch in node, react-native and service worker if available
|
|
5
|
+
isomorphicFetch;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calculateContractAddressFromHash = calculateContractAddressFromHash;
|
|
7
|
+
exports.computeCompiledClassHash = computeCompiledClassHash;
|
|
8
|
+
exports.computeContractClassHash = computeContractClassHash;
|
|
9
|
+
exports.computeHashOnElements = computeHashOnElements;
|
|
10
|
+
exports.computeHintedClassHash = computeHintedClassHash;
|
|
11
|
+
exports.computeLegacyContractClassHash = computeLegacyContractClassHash;
|
|
12
|
+
exports.computePedersenHash = computePedersenHash;
|
|
13
|
+
exports.computePedersenHashOnElements = void 0;
|
|
14
|
+
exports.computePoseidonHash = computePoseidonHash;
|
|
15
|
+
exports.computePoseidonHashOnElements = computePoseidonHashOnElements;
|
|
16
|
+
exports.computeSierraContractClassHash = computeSierraContractClassHash;
|
|
17
|
+
exports.formatSpaces = formatSpaces;
|
|
18
|
+
exports.hashByteCodeSegments = hashByteCodeSegments;
|
|
19
|
+
var _starknet = require("@scure/starknet");
|
|
20
|
+
var _constants = require("../../constants.cjs");
|
|
21
|
+
var _calldata = require("../calldata/index.cjs");
|
|
22
|
+
var _cairo = require("../calldata/cairo.cjs");
|
|
23
|
+
var _ec = require("../ec.cjs");
|
|
24
|
+
var _encode = require("../encode.cjs");
|
|
25
|
+
var _json = require("../json.cjs");
|
|
26
|
+
var _num = require("../num.cjs");
|
|
27
|
+
var _shortString = require("../shortString.cjs");
|
|
28
|
+
function computePedersenHash(a, b) {
|
|
29
|
+
return _ec.starkCurve.pedersen(BigInt(a), BigInt(b));
|
|
30
|
+
}
|
|
31
|
+
function computePoseidonHash(a, b) {
|
|
32
|
+
return (0, _num.toHex)(_ec.starkCurve.poseidonHash(BigInt(a), BigInt(b)));
|
|
33
|
+
}
|
|
34
|
+
function computeHashOnElements(data) {
|
|
35
|
+
return [...data, data.length].reduce((x, y) => _ec.starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
|
|
36
|
+
}
|
|
37
|
+
const computePedersenHashOnElements = exports.computePedersenHashOnElements = computeHashOnElements;
|
|
38
|
+
function computePoseidonHashOnElements(data) {
|
|
39
|
+
return (0, _num.toHex)((0, _starknet.poseidonHashMany)(data.map(x => BigInt(x))));
|
|
40
|
+
}
|
|
41
|
+
function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
42
|
+
const compiledCalldata = _calldata.CallData.compile(constructorCalldata);
|
|
43
|
+
const constructorCalldataHash = computeHashOnElements(compiledCalldata);
|
|
44
|
+
const CONTRACT_ADDRESS_PREFIX = (0, _cairo.felt)("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
45
|
+
const hash = computeHashOnElements([CONTRACT_ADDRESS_PREFIX, deployerAddress, salt, classHash, constructorCalldataHash]);
|
|
46
|
+
return (0, _num.toHex)(BigInt(hash) % _constants.ADDR_BOUND);
|
|
47
|
+
}
|
|
48
|
+
function nullSkipReplacer(key, value) {
|
|
49
|
+
if (key === "attributes" || key === "accessible_scopes") {
|
|
50
|
+
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
51
|
+
}
|
|
52
|
+
if (key === "debug_info") {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return value === null ? void 0 : value;
|
|
56
|
+
}
|
|
57
|
+
function formatSpaces(json) {
|
|
58
|
+
let insideQuotes = false;
|
|
59
|
+
const newString = [];
|
|
60
|
+
for (const char of json) {
|
|
61
|
+
if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
|
|
62
|
+
insideQuotes = !insideQuotes;
|
|
63
|
+
}
|
|
64
|
+
if (insideQuotes) {
|
|
65
|
+
newString.push(char);
|
|
66
|
+
} else {
|
|
67
|
+
newString.push(char === ":" ? ": " : char === "," ? ", " : char);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return newString.join("");
|
|
71
|
+
}
|
|
72
|
+
function computeHintedClassHash(compiledContract) {
|
|
73
|
+
const {
|
|
74
|
+
abi,
|
|
75
|
+
program
|
|
76
|
+
} = compiledContract;
|
|
77
|
+
const contractClass = {
|
|
78
|
+
abi,
|
|
79
|
+
program
|
|
80
|
+
};
|
|
81
|
+
const serializedJson = formatSpaces((0, _json.stringify)(contractClass, nullSkipReplacer));
|
|
82
|
+
return (0, _encode.addHexPrefix)(_ec.starkCurve.keccak((0, _encode.utf8ToArray)(serializedJson)).toString(16));
|
|
83
|
+
}
|
|
84
|
+
function computeLegacyContractClassHash(contract) {
|
|
85
|
+
const compiledContract = (0, _shortString.isString)(contract) ? (0, _json.parse)(contract) : contract;
|
|
86
|
+
const apiVersion = (0, _num.toHex)(_constants.API_VERSION);
|
|
87
|
+
const externalEntryPointsHash = computeHashOnElements(compiledContract.entry_points_by_type.EXTERNAL.flatMap(e => [e.selector, e.offset]));
|
|
88
|
+
const l1HandlerEntryPointsHash = computeHashOnElements(compiledContract.entry_points_by_type.L1_HANDLER.flatMap(e => [e.selector, e.offset]));
|
|
89
|
+
const constructorEntryPointHash = computeHashOnElements(compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap(e => [e.selector, e.offset]));
|
|
90
|
+
const builtinsHash = computeHashOnElements(compiledContract.program.builtins.map(s => (0, _shortString.encodeShortString)(s)));
|
|
91
|
+
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
92
|
+
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
93
|
+
return computeHashOnElements([apiVersion, externalEntryPointsHash, l1HandlerEntryPointsHash, constructorEntryPointHash, builtinsHash, hintedClassHash, dataHash]);
|
|
94
|
+
}
|
|
95
|
+
function hashBuiltins(builtins) {
|
|
96
|
+
return (0, _starknet.poseidonHashMany)(builtins.flatMap(it => {
|
|
97
|
+
return BigInt((0, _shortString.encodeShortString)(it));
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
function hashEntryPoint(data) {
|
|
101
|
+
const base = data.flatMap(it => {
|
|
102
|
+
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
103
|
+
});
|
|
104
|
+
return (0, _starknet.poseidonHashMany)(base);
|
|
105
|
+
}
|
|
106
|
+
function hashByteCodeSegments(casm) {
|
|
107
|
+
const byteCode = casm.bytecode.map(n => BigInt(n));
|
|
108
|
+
const bytecodeSegmentLengths = casm.bytecode_segment_lengths ?? [];
|
|
109
|
+
let segmentStart = 0;
|
|
110
|
+
const hashLeaves = bytecodeSegmentLengths.flatMap(len => {
|
|
111
|
+
const segment = byteCode.slice(segmentStart, segmentStart += len);
|
|
112
|
+
return [BigInt(len), (0, _starknet.poseidonHashMany)(segment)];
|
|
113
|
+
});
|
|
114
|
+
return 1n + (0, _starknet.poseidonHashMany)(hashLeaves);
|
|
115
|
+
}
|
|
116
|
+
function computeCompiledClassHash(casm) {
|
|
117
|
+
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
118
|
+
const compiledClassVersion = BigInt((0, _shortString.encodeShortString)(COMPILED_CLASS_VERSION));
|
|
119
|
+
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
120
|
+
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
121
|
+
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
122
|
+
const bytecode = casm.bytecode_segment_lengths ? hashByteCodeSegments(casm) : (0, _starknet.poseidonHashMany)(casm.bytecode.map(it => BigInt(it)));
|
|
123
|
+
return (0, _num.toHex)((0, _starknet.poseidonHashMany)([compiledClassVersion, externalEntryPointsHash, l1Handlers, constructor, bytecode]));
|
|
124
|
+
}
|
|
125
|
+
function hashEntryPointSierra(data) {
|
|
126
|
+
const base = data.flatMap(it => {
|
|
127
|
+
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
128
|
+
});
|
|
129
|
+
return (0, _starknet.poseidonHashMany)(base);
|
|
130
|
+
}
|
|
131
|
+
function hashAbi(sierra) {
|
|
132
|
+
const indentString = formatSpaces((0, _json.stringify)(sierra.abi, null));
|
|
133
|
+
return BigInt((0, _encode.addHexPrefix)(_ec.starkCurve.keccak((0, _encode.utf8ToArray)(indentString)).toString(16)));
|
|
134
|
+
}
|
|
135
|
+
function computeSierraContractClassHash(sierra) {
|
|
136
|
+
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
137
|
+
const compiledClassVersion = BigInt((0, _shortString.encodeShortString)(CONTRACT_CLASS_VERSION));
|
|
138
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
139
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
140
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
141
|
+
const abiHash = hashAbi(sierra);
|
|
142
|
+
const sierraProgram = (0, _starknet.poseidonHashMany)(sierra.sierra_program.map(it => BigInt(it)));
|
|
143
|
+
return (0, _num.toHex)((0, _starknet.poseidonHashMany)([compiledClassVersion, externalEntryPointsHash, l1Handlers, constructor, abiHash, sierraProgram]));
|
|
144
|
+
}
|
|
145
|
+
function computeContractClassHash(contract) {
|
|
146
|
+
const compiledContract = (0, _shortString.isString)(contract) ? (0, _json.parse)(contract) : contract;
|
|
147
|
+
if ("sierra_program" in compiledContract) {
|
|
148
|
+
return computeSierraContractClassHash(compiledContract);
|
|
149
|
+
}
|
|
150
|
+
return computeLegacyContractClassHash(compiledContract);
|
|
151
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class Hash
|
|
3
|
+
*/
|
|
4
|
+
import { BigNumberish, CompiledContract, CompiledSierra, CompiledSierraCasm, LegacyCompiledContract, RawArgs } from '../../types';
|
|
5
|
+
export declare function computePedersenHash(a: BigNumberish, b: BigNumberish): string;
|
|
6
|
+
export declare function computePoseidonHash(a: BigNumberish, b: BigNumberish): string;
|
|
7
|
+
/**
|
|
8
|
+
* Compute Pedersen hash from data
|
|
9
|
+
*
|
|
10
|
+
* @param {BigNumberish[]} data Array of data to compute Pedersen hash on
|
|
11
|
+
* @returns {string} hex-string of Pedersen hash
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const result = hash.computeHashOnElements(['0xabc', '0x123', '0xabc123'])
|
|
16
|
+
* // result = 0x148141e8f7db29d005a0187669a56f0790d7e8c2c5b2d780e4d8b9e436a5521
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function computeHashOnElements(data: BigNumberish[]): string;
|
|
20
|
+
export declare const computePedersenHashOnElements: typeof computeHashOnElements;
|
|
21
|
+
export declare function computePoseidonHashOnElements(data: BigNumberish[]): string;
|
|
22
|
+
/**
|
|
23
|
+
* Calculate contract address from class hash
|
|
24
|
+
*
|
|
25
|
+
* @param {BigNumberish} salt Salt to be used for hashing
|
|
26
|
+
* @param {BigNumberish} classHash Class hash of contract to generate address for
|
|
27
|
+
* @param {RawArgs} constructorCalldata Call data for contract constructor
|
|
28
|
+
* @param {BigNumberish} deployerAddress Address of contract deployer
|
|
29
|
+
* @returns {string} hex-string
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const result = hash.calculateContractAddressFromHash(1234, 0x1cf4fe5d37868d25524cdacb89518d88bf217a9240a1e6fde71cc22c429e0e3, [1234, true, false], 0x052fb1a9ab0db3c4f81d70fea6a2f6e55f57c709a46089b25eeec0e959db3695);
|
|
33
|
+
* // result = 0x5fb03d3a88d8e474976932f927ff6a9e332e06ed36642ea3e8c7e38bf010f76
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function calculateContractAddressFromHash(salt: BigNumberish, classHash: BigNumberish, constructorCalldata: RawArgs, deployerAddress: BigNumberish): string;
|
|
37
|
+
/**
|
|
38
|
+
* Format json-string without spaces to conform starknet json-string
|
|
39
|
+
* @param {string} json json-string without spaces
|
|
40
|
+
* @returns {string} json-string with additional spaces after `:` and `,`
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const result = hash.formatSpaces("{'onchain':true,'isStarknet':true}");
|
|
44
|
+
* // result = "{'onchain': true, 'isStarknet': true}"
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function formatSpaces(json: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Compute hinted class hash for legacy compiled contract (Cairo 0)
|
|
50
|
+
* @param {LegacyCompiledContract} compiledContract
|
|
51
|
+
* @returns {string} hex-string
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const compiledCairo0 = json.parse(fs.readFileSync("./cairo0contract.json").toString("ascii"));
|
|
55
|
+
* const result=hash.computeHintedClassHash(compiledCairo0);
|
|
56
|
+
* // result = "0x293eabb06955c0a1e55557014675aa4e7a1fd69896147382b29b2b6b166a2ac"
|
|
57
|
+
* ``` */
|
|
58
|
+
export declare function computeHintedClassHash(compiledContract: LegacyCompiledContract): string;
|
|
59
|
+
/**
|
|
60
|
+
* Computes the class hash for legacy compiled contract (Cairo 0)
|
|
61
|
+
* @param {LegacyCompiledContract | string} contract legacy compiled contract content
|
|
62
|
+
* @returns {string} hex-string of class hash
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const compiledCairo0 = json.parse(fs.readFileSync("./cairo0contract.json").toString("ascii"));
|
|
66
|
+
* const result=hash.computeLegacyContractClassHash(compiledCairo0);
|
|
67
|
+
* // result = "0x4a5cae61fa8312b0a3d0c44658b403d3e4197be80027fd5020ffcdf0c803331"
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function computeLegacyContractClassHash(contract: LegacyCompiledContract | string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Compute hash of the bytecode for Sierra v1.5.0 onwards (Cairo 2.6.0)
|
|
73
|
+
* Each segment is Poseidon hashed.
|
|
74
|
+
* The global hash is : 1 + PoseidonHash(len0, h0, len1, h1, ...)
|
|
75
|
+
* @param {CompiledSierraCasm} casm compiled Sierra CASM file content.
|
|
76
|
+
* @returns {bigint} the bytecode hash as bigint.
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const compiledCasm = json.parse(fs.readFileSync("./contractC260.casm.json").toString("ascii"));
|
|
80
|
+
* const result = hash.hashByteCodeSegments(compiledCasm);
|
|
81
|
+
* // result = 80499149343908132326491548897246987792410240503053732367044713070598981699n
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function hashByteCodeSegments(casm: CompiledSierraCasm): bigint;
|
|
85
|
+
/**
|
|
86
|
+
* Compute compiled class hash for contract (Cairo 1)
|
|
87
|
+
* @param {CompiledSierraCasm} casm Cairo 1 compiled contract content
|
|
88
|
+
* @returns {string} hex-string of class hash
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const compiledCasm = json.parse(fs.readFileSync("./cairo260.casm.json").toString("ascii"));
|
|
92
|
+
* const result = hash.computeCompiledClassHash(compiledCasm);
|
|
93
|
+
* // result = "0x4087905743b4fa2b3affc1fc71333f1390c8c5d1e8ea47d6ba70786de3fc01a"
|
|
94
|
+
```
|
|
95
|
+
*/
|
|
96
|
+
export declare function computeCompiledClassHash(casm: CompiledSierraCasm): string;
|
|
97
|
+
/**
|
|
98
|
+
* Compute sierra contract class hash (Cairo 1)
|
|
99
|
+
* @param {CompiledSierra} sierra Cairo 1 Sierra contract content
|
|
100
|
+
* @returns {string} hex-string of class hash
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const compiledSierra = json.parse(fs.readFileSync("./cairo260.sierra.json").toString("ascii"));
|
|
104
|
+
* const result = hash.computeSierraContractClassHash(compiledSierra);
|
|
105
|
+
* // result = "0x67b6b4f02baded46f02feeed58c4f78e26c55364e59874d8abfd3532d85f1ba"
|
|
106
|
+
```
|
|
107
|
+
*/
|
|
108
|
+
export declare function computeSierraContractClassHash(sierra: CompiledSierra): string;
|
|
109
|
+
/**
|
|
110
|
+
* Compute ClassHash (sierra or legacy) based on provided contract
|
|
111
|
+
* @param {CompiledContract | string} contract Cairo 1 contract content
|
|
112
|
+
* @returns {string} hex-string of class hash
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const compiledSierra = json.parse(fs.readFileSync("./cairo260.sierra.json").toString("ascii"));
|
|
116
|
+
* const result = hash.computeContractClassHash(compiledSierra);
|
|
117
|
+
* // result = "0x67b6b4f02baded46f02feeed58c4f78e26c55364e59874d8abfd3532d85f1ba"
|
|
118
|
+
```
|
|
119
|
+
*/
|
|
120
|
+
export declare function computeContractClassHash(contract: CompiledContract | string): string;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { poseidonHashMany } from "@scure/starknet";
|
|
2
|
+
import { ADDR_BOUND, API_VERSION } from "../../constants.mjs";
|
|
3
|
+
import { CallData } from "../calldata/index.mjs";
|
|
4
|
+
import { felt } from "../calldata/cairo.mjs";
|
|
5
|
+
import { starkCurve } from "../ec.mjs";
|
|
6
|
+
import { addHexPrefix, utf8ToArray } from "../encode.mjs";
|
|
7
|
+
import { parse, stringify } from "../json.mjs";
|
|
8
|
+
import { toHex } from "../num.mjs";
|
|
9
|
+
import { encodeShortString, isString } from "../shortString.mjs";
|
|
10
|
+
export function computePedersenHash(a, b) {
|
|
11
|
+
return starkCurve.pedersen(BigInt(a), BigInt(b));
|
|
12
|
+
}
|
|
13
|
+
export function computePoseidonHash(a, b) {
|
|
14
|
+
return toHex(starkCurve.poseidonHash(BigInt(a), BigInt(b)));
|
|
15
|
+
}
|
|
16
|
+
export function computeHashOnElements(data) {
|
|
17
|
+
return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
|
|
18
|
+
}
|
|
19
|
+
export const computePedersenHashOnElements = computeHashOnElements;
|
|
20
|
+
export function computePoseidonHashOnElements(data) {
|
|
21
|
+
return toHex(poseidonHashMany(data.map((x) => BigInt(x))));
|
|
22
|
+
}
|
|
23
|
+
export function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
|
|
24
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
25
|
+
const constructorCalldataHash = computeHashOnElements(compiledCalldata);
|
|
26
|
+
const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
|
|
27
|
+
const hash = computeHashOnElements([
|
|
28
|
+
CONTRACT_ADDRESS_PREFIX,
|
|
29
|
+
deployerAddress,
|
|
30
|
+
salt,
|
|
31
|
+
classHash,
|
|
32
|
+
constructorCalldataHash
|
|
33
|
+
]);
|
|
34
|
+
return toHex(BigInt(hash) % ADDR_BOUND);
|
|
35
|
+
}
|
|
36
|
+
function nullSkipReplacer(key, value) {
|
|
37
|
+
if (key === "attributes" || key === "accessible_scopes") {
|
|
38
|
+
return Array.isArray(value) && value.length === 0 ? void 0 : value;
|
|
39
|
+
}
|
|
40
|
+
if (key === "debug_info") {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return value === null ? void 0 : value;
|
|
44
|
+
}
|
|
45
|
+
export function formatSpaces(json) {
|
|
46
|
+
let insideQuotes = false;
|
|
47
|
+
const newString = [];
|
|
48
|
+
for (const char of json) {
|
|
49
|
+
if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
|
|
50
|
+
insideQuotes = !insideQuotes;
|
|
51
|
+
}
|
|
52
|
+
if (insideQuotes) {
|
|
53
|
+
newString.push(char);
|
|
54
|
+
} else {
|
|
55
|
+
newString.push(char === ":" ? ": " : char === "," ? ", " : char);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return newString.join("");
|
|
59
|
+
}
|
|
60
|
+
export function computeHintedClassHash(compiledContract) {
|
|
61
|
+
const { abi, program } = compiledContract;
|
|
62
|
+
const contractClass = { abi, program };
|
|
63
|
+
const serializedJson = formatSpaces(stringify(contractClass, nullSkipReplacer));
|
|
64
|
+
return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
|
|
65
|
+
}
|
|
66
|
+
export function computeLegacyContractClassHash(contract) {
|
|
67
|
+
const compiledContract = isString(contract) ? parse(contract) : contract;
|
|
68
|
+
const apiVersion = toHex(API_VERSION);
|
|
69
|
+
const externalEntryPointsHash = computeHashOnElements(
|
|
70
|
+
compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
|
|
71
|
+
);
|
|
72
|
+
const l1HandlerEntryPointsHash = computeHashOnElements(
|
|
73
|
+
compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
|
|
74
|
+
);
|
|
75
|
+
const constructorEntryPointHash = computeHashOnElements(
|
|
76
|
+
compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
|
|
77
|
+
);
|
|
78
|
+
const builtinsHash = computeHashOnElements(
|
|
79
|
+
compiledContract.program.builtins.map((s) => encodeShortString(s))
|
|
80
|
+
);
|
|
81
|
+
const hintedClassHash = computeHintedClassHash(compiledContract);
|
|
82
|
+
const dataHash = computeHashOnElements(compiledContract.program.data);
|
|
83
|
+
return computeHashOnElements([
|
|
84
|
+
apiVersion,
|
|
85
|
+
externalEntryPointsHash,
|
|
86
|
+
l1HandlerEntryPointsHash,
|
|
87
|
+
constructorEntryPointHash,
|
|
88
|
+
builtinsHash,
|
|
89
|
+
hintedClassHash,
|
|
90
|
+
dataHash
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
function hashBuiltins(builtins) {
|
|
94
|
+
return poseidonHashMany(
|
|
95
|
+
builtins.flatMap((it) => {
|
|
96
|
+
return BigInt(encodeShortString(it));
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
function hashEntryPoint(data) {
|
|
101
|
+
const base = data.flatMap((it) => {
|
|
102
|
+
return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
|
|
103
|
+
});
|
|
104
|
+
return poseidonHashMany(base);
|
|
105
|
+
}
|
|
106
|
+
export function hashByteCodeSegments(casm) {
|
|
107
|
+
const byteCode = casm.bytecode.map((n) => BigInt(n));
|
|
108
|
+
const bytecodeSegmentLengths = casm.bytecode_segment_lengths ?? [];
|
|
109
|
+
let segmentStart = 0;
|
|
110
|
+
const hashLeaves = bytecodeSegmentLengths.flatMap((len) => {
|
|
111
|
+
const segment = byteCode.slice(segmentStart, segmentStart += len);
|
|
112
|
+
return [BigInt(len), poseidonHashMany(segment)];
|
|
113
|
+
});
|
|
114
|
+
return 1n + poseidonHashMany(hashLeaves);
|
|
115
|
+
}
|
|
116
|
+
export function computeCompiledClassHash(casm) {
|
|
117
|
+
const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
|
|
118
|
+
const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
|
|
119
|
+
const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
|
|
120
|
+
const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
|
|
121
|
+
const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
|
|
122
|
+
const bytecode = casm.bytecode_segment_lengths ? hashByteCodeSegments(casm) : poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
|
|
123
|
+
return toHex(
|
|
124
|
+
poseidonHashMany([
|
|
125
|
+
compiledClassVersion,
|
|
126
|
+
externalEntryPointsHash,
|
|
127
|
+
l1Handlers,
|
|
128
|
+
constructor,
|
|
129
|
+
bytecode
|
|
130
|
+
])
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function hashEntryPointSierra(data) {
|
|
134
|
+
const base = data.flatMap((it) => {
|
|
135
|
+
return [BigInt(it.selector), BigInt(it.function_idx)];
|
|
136
|
+
});
|
|
137
|
+
return poseidonHashMany(base);
|
|
138
|
+
}
|
|
139
|
+
function hashAbi(sierra) {
|
|
140
|
+
const indentString = formatSpaces(stringify(sierra.abi, null));
|
|
141
|
+
return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
|
|
142
|
+
}
|
|
143
|
+
export function computeSierraContractClassHash(sierra) {
|
|
144
|
+
const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
|
|
145
|
+
const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
|
|
146
|
+
const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
|
|
147
|
+
const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
|
|
148
|
+
const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
|
|
149
|
+
const abiHash = hashAbi(sierra);
|
|
150
|
+
const sierraProgram = poseidonHashMany(sierra.sierra_program.map((it) => BigInt(it)));
|
|
151
|
+
return toHex(
|
|
152
|
+
poseidonHashMany([
|
|
153
|
+
compiledClassVersion,
|
|
154
|
+
externalEntryPointsHash,
|
|
155
|
+
l1Handlers,
|
|
156
|
+
constructor,
|
|
157
|
+
abiHash,
|
|
158
|
+
sierraProgram
|
|
159
|
+
])
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
export function computeContractClassHash(contract) {
|
|
163
|
+
const compiledContract = isString(contract) ? parse(contract) : contract;
|
|
164
|
+
if ("sierra_program" in compiledContract) {
|
|
165
|
+
return computeSierraContractClassHash(compiledContract);
|
|
166
|
+
}
|
|
167
|
+
return computeLegacyContractClassHash(compiledContract);
|
|
168
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
poseidon: true
|
|
8
|
+
};
|
|
9
|
+
exports.poseidon = void 0;
|
|
10
|
+
var _poseidon = _interopRequireWildcard(require("@noble/curves/abstract/poseidon"));
|
|
11
|
+
exports.poseidon = _poseidon;
|
|
12
|
+
var _selector = require("./selector.cjs");
|
|
13
|
+
Object.keys(_selector).forEach(function (key) {
|
|
14
|
+
if (key === "default" || key === "__esModule") return;
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
16
|
+
if (key in exports && exports[key] === _selector[key]) return;
|
|
17
|
+
Object.defineProperty(exports, key, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return _selector[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
var _transactionHash = require("./transactionHash/index.cjs");
|
|
25
|
+
Object.keys(_transactionHash).forEach(function (key) {
|
|
26
|
+
if (key === "default" || key === "__esModule") return;
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
28
|
+
if (key in exports && exports[key] === _transactionHash[key]) return;
|
|
29
|
+
Object.defineProperty(exports, key, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return _transactionHash[key];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
var _classHash = require("./classHash.cjs");
|
|
37
|
+
Object.keys(_classHash).forEach(function (key) {
|
|
38
|
+
if (key === "default" || key === "__esModule") return;
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
40
|
+
if (key in exports && exports[key] === _classHash[key]) return;
|
|
41
|
+
Object.defineProperty(exports, key, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return _classHash[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
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); }
|
|
49
|
+
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; }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelector = getSelector;
|
|
7
|
+
exports.getSelectorFromName = getSelectorFromName;
|
|
8
|
+
exports.keccakBn = keccakBn;
|
|
9
|
+
exports.starknetKeccak = starknetKeccak;
|
|
10
|
+
var _starknet = require("@scure/starknet");
|
|
11
|
+
var _constants = require("../../constants.cjs");
|
|
12
|
+
var _encode = require("../encode.cjs");
|
|
13
|
+
var _num = require("../num.cjs");
|
|
14
|
+
function keccakBn(value) {
|
|
15
|
+
const hexWithoutPrefix = (0, _encode.removeHexPrefix)((0, _num.toHex)(BigInt(value)));
|
|
16
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
17
|
+
return (0, _encode.addHexPrefix)((0, _starknet.keccak)((0, _num.hexToBytes)((0, _encode.addHexPrefix)(evenHex))).toString(16));
|
|
18
|
+
}
|
|
19
|
+
function keccakHex(str) {
|
|
20
|
+
return (0, _encode.addHexPrefix)((0, _starknet.keccak)((0, _encode.utf8ToArray)(str)).toString(16));
|
|
21
|
+
}
|
|
22
|
+
function starknetKeccak(str) {
|
|
23
|
+
const hash = BigInt(keccakHex(str));
|
|
24
|
+
return hash & _constants.MASK_250;
|
|
25
|
+
}
|
|
26
|
+
function getSelectorFromName(funcName) {
|
|
27
|
+
return (0, _num.toHex)(starknetKeccak(funcName));
|
|
28
|
+
}
|
|
29
|
+
function getSelector(value) {
|
|
30
|
+
if ((0, _num.isHex)(value)) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
if ((0, _num.isStringWholeNumber)(value)) {
|
|
34
|
+
return (0, _num.toHexString)(value);
|
|
35
|
+
}
|
|
36
|
+
return getSelectorFromName(value);
|
|
37
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BigNumberish } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the hex-string Keccak hash for a given BigNumberish
|
|
4
|
+
*
|
|
5
|
+
* @param value value to hash
|
|
6
|
+
* @returns hex-string Keccak hash
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const result = keccakBn('0xabc');
|
|
10
|
+
* // result = '0x11cf08aac85935e32397f410e48217a127b6855d41b1e3877eb4179c0904b77'
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function keccakBn(value: BigNumberish): string;
|
|
14
|
+
/**
|
|
15
|
+
* Calculate the BigInt Starknet Keccak hash for a given string
|
|
16
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L38)
|
|
17
|
+
*
|
|
18
|
+
* @param str value to hash
|
|
19
|
+
* @returns BigInt Keccak hash
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = starknetKeccak('test').toString();
|
|
23
|
+
* // result = '61835310290161785288773114225739080147441215596947647498723774891619563096'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function starknetKeccak(str: string): bigint;
|
|
27
|
+
/**
|
|
28
|
+
* Calculate the hex-string selector for a given abi function name
|
|
29
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L46)
|
|
30
|
+
*
|
|
31
|
+
* @param funcName abi function name
|
|
32
|
+
* @returns hex-string selector
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const result = getSelectorFromName('myFunction');
|
|
36
|
+
* // result = '0xc14cfe23f3fa7ce7b1f8db7d7682305b1692293f71a61cc06637f0d8d8b6c8'
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function getSelectorFromName(funcName: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Calculate the hex-string selector from a given abi function name, decimal string or hex string
|
|
42
|
+
*
|
|
43
|
+
* @param value hex-string | dec-string | ascii-string
|
|
44
|
+
* @returns hex-string selector
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const selector1: string = getSelector("myFunction");
|
|
48
|
+
* // selector1 = "0xc14cfe23f3fa7ce7b1f8db7d7682305b1692293f71a61cc06637f0d8d8b6c8"
|
|
49
|
+
*
|
|
50
|
+
* const selector2: string = getSelector("0x123abc");
|
|
51
|
+
* // selector2 = "0x123abc"
|
|
52
|
+
*
|
|
53
|
+
* const selector3: string = getSelector("123456");
|
|
54
|
+
* // selector3 = "0x1e240"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function getSelector(value: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { keccak } from "@scure/starknet";
|
|
2
|
+
import { MASK_250 } from "../../constants.mjs";
|
|
3
|
+
import { addHexPrefix, removeHexPrefix, utf8ToArray } from "../encode.mjs";
|
|
4
|
+
import { hexToBytes, isHex, isStringWholeNumber, toHex, toHexString } from "../num.mjs";
|
|
5
|
+
export function keccakBn(value) {
|
|
6
|
+
const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
|
|
7
|
+
const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
|
|
8
|
+
return addHexPrefix(keccak(hexToBytes(addHexPrefix(evenHex))).toString(16));
|
|
9
|
+
}
|
|
10
|
+
function keccakHex(str) {
|
|
11
|
+
return addHexPrefix(keccak(utf8ToArray(str)).toString(16));
|
|
12
|
+
}
|
|
13
|
+
export function starknetKeccak(str) {
|
|
14
|
+
const hash = BigInt(keccakHex(str));
|
|
15
|
+
return hash & MASK_250;
|
|
16
|
+
}
|
|
17
|
+
export function getSelectorFromName(funcName) {
|
|
18
|
+
return toHex(starknetKeccak(funcName));
|
|
19
|
+
}
|
|
20
|
+
export function getSelector(value) {
|
|
21
|
+
if (isHex(value)) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (isStringWholeNumber(value)) {
|
|
25
|
+
return toHexString(value);
|
|
26
|
+
}
|
|
27
|
+
return getSelectorFromName(value);
|
|
28
|
+
}
|