starknet 6.10.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 +6 -0
- package/LICENSE +1 -1
- package/README.md +4 -8
- 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 -6945
- package/dist/index.mjs +39 -7452
- 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 +11 -12
- package/dist/index.js +0 -7559
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [6.10.1](https://github.com/starknet-io/starknet.js/compare/v6.10.0...v6.10.1) (2024-06-28)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- change build cjs and mjs to unbuild ([#1163](https://github.com/starknet-io/starknet.js/issues/1163)) ([bb4a93d](https://github.com/starknet-io/starknet.js/commit/bb4a93d6639cf90298e0b1003fb31a79f11691f0))
|
|
6
|
+
|
|
1
7
|
# [6.10.0](https://github.com/starknet-io/starknet.js/compare/v6.9.0...v6.10.0) (2024-06-18)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -34,9 +34,7 @@
|
|
|
34
34
|
</a>
|
|
35
35
|
</p>
|
|
36
36
|
|
|
37
|
-
##
|
|
38
|
-
|
|
39
|
-
Install starknet with `npm`
|
|
37
|
+
## Installation
|
|
40
38
|
|
|
41
39
|
```bash
|
|
42
40
|
# latest official release (main branch)
|
|
@@ -51,13 +49,11 @@ $ npm install starknet@beta
|
|
|
51
49
|
|
|
52
50
|
Import `starknet` and use the [API](https://www.starknetjs.com/docs/API/).
|
|
53
51
|
|
|
54
|
-
## 🌐
|
|
55
|
-
|
|
56
|
-
[Click Here](https://www.starknetjs.com/docs/API/)
|
|
52
|
+
## 🌐 Documentation
|
|
57
53
|
|
|
58
|
-
|
|
54
|
+
How to [Guides](https://www.starknetjs.com/docs/guides/intro) :book: & [API](https://www.starknetjs.com/docs/API/) 💻
|
|
59
55
|
|
|
60
|
-
|
|
56
|
+
Play with [Code Examples](https://github.com/PhilippeR26/starknet.js-workshop-typescript) :video_game:
|
|
61
57
|
|
|
62
58
|
## ✏️ Contributing
|
|
63
59
|
|
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Account = void 0;
|
|
7
|
+
var _constants = require("../constants.cjs");
|
|
8
|
+
var _provider = require("../provider/index.cjs");
|
|
9
|
+
var _signer = require("../signer/index.cjs");
|
|
10
|
+
var _types = require("../types/index.cjs");
|
|
11
|
+
var _api = require("../types/api/index.cjs");
|
|
12
|
+
var _calldata = require("../utils/calldata/index.cjs");
|
|
13
|
+
var _contract = require("../utils/contract.cjs");
|
|
14
|
+
var _events = require("../utils/events/index.cjs");
|
|
15
|
+
var _hash = require("../utils/hash/index.cjs");
|
|
16
|
+
var _num = require("../utils/num.cjs");
|
|
17
|
+
var _provider2 = require("../utils/provider.cjs");
|
|
18
|
+
var _shortString = require("../utils/shortString.cjs");
|
|
19
|
+
var _stark = require("../utils/stark.cjs");
|
|
20
|
+
var _transaction = require("../utils/transaction.cjs");
|
|
21
|
+
var _typedData = require("../utils/typedData.cjs");
|
|
22
|
+
class Account extends _provider.Provider {
|
|
23
|
+
signer;
|
|
24
|
+
address;
|
|
25
|
+
cairoVersion;
|
|
26
|
+
transactionVersion;
|
|
27
|
+
constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = _api.ETransactionVersion.V2) {
|
|
28
|
+
super(providerOrOptions);
|
|
29
|
+
this.address = address.toLowerCase();
|
|
30
|
+
this.signer = (0, _shortString.isString)(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new _signer.Signer(pkOrSigner) : pkOrSigner;
|
|
31
|
+
if (cairoVersion) {
|
|
32
|
+
this.cairoVersion = cairoVersion.toString();
|
|
33
|
+
}
|
|
34
|
+
this.transactionVersion = transactionVersion;
|
|
35
|
+
}
|
|
36
|
+
// provided version or contract based preferred transactionVersion
|
|
37
|
+
getPreferredVersion(type12, type3) {
|
|
38
|
+
if (this.transactionVersion === _api.ETransactionVersion.V3) return type3;
|
|
39
|
+
if (this.transactionVersion === _api.ETransactionVersion.V2) return type12;
|
|
40
|
+
return _api.ETransactionVersion.V3;
|
|
41
|
+
}
|
|
42
|
+
async getNonce(blockIdentifier) {
|
|
43
|
+
return super.getNonceForAddress(this.address, blockIdentifier);
|
|
44
|
+
}
|
|
45
|
+
async getNonceSafe(nonce) {
|
|
46
|
+
try {
|
|
47
|
+
return (0, _num.toBigInt)(nonce ?? (await this.getNonce()));
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return 0n;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the Cairo version from the network and sets `cairoVersion` if not already set in the constructor.
|
|
54
|
+
* @param classHash if provided detects Cairo version from classHash, otherwise from the account address
|
|
55
|
+
*/
|
|
56
|
+
async getCairoVersion(classHash) {
|
|
57
|
+
if (!this.cairoVersion) {
|
|
58
|
+
const {
|
|
59
|
+
cairo
|
|
60
|
+
} = classHash ? await super.getContractVersion(void 0, classHash) : await super.getContractVersion(this.address);
|
|
61
|
+
this.cairoVersion = cairo;
|
|
62
|
+
}
|
|
63
|
+
return this.cairoVersion;
|
|
64
|
+
}
|
|
65
|
+
async estimateFee(calls, estimateFeeDetails = {}) {
|
|
66
|
+
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
67
|
+
}
|
|
68
|
+
async estimateInvokeFee(calls, details = {}) {
|
|
69
|
+
const {
|
|
70
|
+
nonce: providedNonce,
|
|
71
|
+
blockIdentifier,
|
|
72
|
+
version: providedVersion,
|
|
73
|
+
skipValidate = true
|
|
74
|
+
} = details;
|
|
75
|
+
const transactions = Array.isArray(calls) ? calls : [calls];
|
|
76
|
+
const nonce = (0, _num.toBigInt)(providedNonce ?? (await this.getNonce()));
|
|
77
|
+
const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.F1, _api.ETransactionVersion.F3), (0, _stark.toFeeVersion)(providedVersion));
|
|
78
|
+
const chainId = await this.getChainId();
|
|
79
|
+
const signerDetails = {
|
|
80
|
+
...(0, _stark.v3Details)(details),
|
|
81
|
+
walletAddress: this.address,
|
|
82
|
+
nonce,
|
|
83
|
+
maxFee: _constants.ZERO,
|
|
84
|
+
version,
|
|
85
|
+
chainId,
|
|
86
|
+
cairoVersion: await this.getCairoVersion(),
|
|
87
|
+
skipValidate
|
|
88
|
+
};
|
|
89
|
+
const invocation = await this.buildInvocation(transactions, signerDetails);
|
|
90
|
+
return super.getInvokeEstimateFee({
|
|
91
|
+
...invocation
|
|
92
|
+
}, {
|
|
93
|
+
...(0, _stark.v3Details)(details),
|
|
94
|
+
version,
|
|
95
|
+
nonce
|
|
96
|
+
}, blockIdentifier, details.skipValidate);
|
|
97
|
+
}
|
|
98
|
+
async estimateDeclareFee(payload, details = {}) {
|
|
99
|
+
const {
|
|
100
|
+
blockIdentifier,
|
|
101
|
+
nonce: providedNonce,
|
|
102
|
+
version: providedVersion,
|
|
103
|
+
skipValidate = true
|
|
104
|
+
} = details;
|
|
105
|
+
const nonce = (0, _num.toBigInt)(providedNonce ?? (await this.getNonce()));
|
|
106
|
+
const version = (0, _stark.toTransactionVersion)(!(0, _contract.isSierra)(payload.contract) ? _api.ETransactionVersion.F1 : this.getPreferredVersion(_api.ETransactionVersion.F2, _api.ETransactionVersion.F3), (0, _stark.toFeeVersion)(providedVersion));
|
|
107
|
+
const chainId = await this.getChainId();
|
|
108
|
+
const declareContractTransaction = await this.buildDeclarePayload(payload, {
|
|
109
|
+
...(0, _stark.v3Details)(details),
|
|
110
|
+
nonce,
|
|
111
|
+
chainId,
|
|
112
|
+
version,
|
|
113
|
+
walletAddress: this.address,
|
|
114
|
+
maxFee: _constants.ZERO,
|
|
115
|
+
cairoVersion: void 0,
|
|
116
|
+
// unused parameter
|
|
117
|
+
skipValidate
|
|
118
|
+
});
|
|
119
|
+
return super.getDeclareEstimateFee(declareContractTransaction, {
|
|
120
|
+
...(0, _stark.v3Details)(details),
|
|
121
|
+
version,
|
|
122
|
+
nonce
|
|
123
|
+
}, blockIdentifier, details.skipValidate);
|
|
124
|
+
}
|
|
125
|
+
async estimateAccountDeployFee({
|
|
126
|
+
classHash,
|
|
127
|
+
addressSalt = 0,
|
|
128
|
+
constructorCalldata = [],
|
|
129
|
+
contractAddress
|
|
130
|
+
}, details = {}) {
|
|
131
|
+
const {
|
|
132
|
+
blockIdentifier,
|
|
133
|
+
version: providedVersion,
|
|
134
|
+
skipValidate = true
|
|
135
|
+
} = details;
|
|
136
|
+
const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.F1, _api.ETransactionVersion.F3), (0, _stark.toFeeVersion)(providedVersion));
|
|
137
|
+
const nonce = _constants.ZERO;
|
|
138
|
+
const chainId = await this.getChainId();
|
|
139
|
+
const payload = await this.buildAccountDeployPayload({
|
|
140
|
+
classHash,
|
|
141
|
+
addressSalt,
|
|
142
|
+
constructorCalldata,
|
|
143
|
+
contractAddress
|
|
144
|
+
}, {
|
|
145
|
+
...(0, _stark.v3Details)(details),
|
|
146
|
+
nonce,
|
|
147
|
+
chainId,
|
|
148
|
+
version,
|
|
149
|
+
walletAddress: this.address,
|
|
150
|
+
// unused parameter
|
|
151
|
+
maxFee: _constants.ZERO,
|
|
152
|
+
cairoVersion: void 0,
|
|
153
|
+
// unused parameter,
|
|
154
|
+
skipValidate
|
|
155
|
+
});
|
|
156
|
+
return super.getDeployAccountEstimateFee({
|
|
157
|
+
...payload
|
|
158
|
+
}, {
|
|
159
|
+
...(0, _stark.v3Details)(details),
|
|
160
|
+
version,
|
|
161
|
+
nonce
|
|
162
|
+
}, blockIdentifier, details.skipValidate);
|
|
163
|
+
}
|
|
164
|
+
async estimateDeployFee(payload, details = {}) {
|
|
165
|
+
const calls = this.buildUDCContractPayload(payload);
|
|
166
|
+
return this.estimateInvokeFee(calls, details);
|
|
167
|
+
}
|
|
168
|
+
async estimateFeeBulk(invocations, details = {}) {
|
|
169
|
+
const {
|
|
170
|
+
nonce,
|
|
171
|
+
blockIdentifier,
|
|
172
|
+
version,
|
|
173
|
+
skipValidate
|
|
174
|
+
} = details;
|
|
175
|
+
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
176
|
+
...(0, _stark.v3Details)(details),
|
|
177
|
+
versions: [_api.ETransactionVersion.F1,
|
|
178
|
+
// non-sierra
|
|
179
|
+
(0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.F2, _api.ETransactionVersion.F3), version)
|
|
180
|
+
// sierra
|
|
181
|
+
],
|
|
182
|
+
nonce,
|
|
183
|
+
blockIdentifier,
|
|
184
|
+
skipValidate
|
|
185
|
+
});
|
|
186
|
+
return super.getEstimateFeeBulk(accountInvocations, {
|
|
187
|
+
blockIdentifier,
|
|
188
|
+
skipValidate
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async simulateTransaction(invocations, details = {}) {
|
|
192
|
+
const {
|
|
193
|
+
nonce,
|
|
194
|
+
blockIdentifier,
|
|
195
|
+
skipValidate = true,
|
|
196
|
+
skipExecute,
|
|
197
|
+
version
|
|
198
|
+
} = details;
|
|
199
|
+
const accountInvocations = await this.accountInvocationsFactory(invocations, {
|
|
200
|
+
...(0, _stark.v3Details)(details),
|
|
201
|
+
versions: [_api.ETransactionVersion.V1,
|
|
202
|
+
// non-sierra
|
|
203
|
+
(0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.V2, _api.ETransactionVersion.V3), version)],
|
|
204
|
+
nonce,
|
|
205
|
+
blockIdentifier,
|
|
206
|
+
skipValidate
|
|
207
|
+
});
|
|
208
|
+
return super.getSimulateTransaction(accountInvocations, {
|
|
209
|
+
blockIdentifier,
|
|
210
|
+
skipValidate,
|
|
211
|
+
skipExecute
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async execute(transactions, arg2, transactionsDetail = {}) {
|
|
215
|
+
const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
|
|
216
|
+
const calls = Array.isArray(transactions) ? transactions : [transactions];
|
|
217
|
+
const nonce = (0, _num.toBigInt)(details.nonce ?? (await this.getNonce()));
|
|
218
|
+
const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.V1, _api.ETransactionVersion.V3),
|
|
219
|
+
// TODO: does this depend on cairo version ?
|
|
220
|
+
details.version);
|
|
221
|
+
const estimate = await this.getUniversalSuggestedFee(version, {
|
|
222
|
+
type: _types.TransactionType.INVOKE,
|
|
223
|
+
payload: transactions
|
|
224
|
+
}, {
|
|
225
|
+
...details,
|
|
226
|
+
version
|
|
227
|
+
});
|
|
228
|
+
const chainId = await this.getChainId();
|
|
229
|
+
const signerDetails = {
|
|
230
|
+
...(0, _stark.v3Details)(details),
|
|
231
|
+
resourceBounds: estimate.resourceBounds,
|
|
232
|
+
walletAddress: this.address,
|
|
233
|
+
nonce,
|
|
234
|
+
maxFee: estimate.maxFee,
|
|
235
|
+
version,
|
|
236
|
+
chainId,
|
|
237
|
+
cairoVersion: await this.getCairoVersion()
|
|
238
|
+
};
|
|
239
|
+
const signature = await this.signer.signTransaction(calls, signerDetails);
|
|
240
|
+
const calldata = (0, _transaction.getExecuteCalldata)(calls, await this.getCairoVersion());
|
|
241
|
+
return this.invokeFunction({
|
|
242
|
+
contractAddress: this.address,
|
|
243
|
+
calldata,
|
|
244
|
+
signature
|
|
245
|
+
}, {
|
|
246
|
+
...(0, _stark.v3Details)(details),
|
|
247
|
+
resourceBounds: estimate.resourceBounds,
|
|
248
|
+
nonce,
|
|
249
|
+
maxFee: estimate.maxFee,
|
|
250
|
+
version
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* First check if contract is already declared, if not declare it
|
|
255
|
+
* If contract already declared returned transaction_hash is ''.
|
|
256
|
+
* Method will pass even if contract is already declared
|
|
257
|
+
* @param transactionsDetail (optional)
|
|
258
|
+
*/
|
|
259
|
+
async declareIfNot(payload, transactionsDetail = {}) {
|
|
260
|
+
const declareContractPayload = (0, _contract.extractContractHashes)(payload);
|
|
261
|
+
try {
|
|
262
|
+
await this.getClassByHash(declareContractPayload.classHash);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
return this.declare(payload, transactionsDetail);
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
transaction_hash: "",
|
|
268
|
+
class_hash: declareContractPayload.classHash
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async declare(payload, details = {}) {
|
|
272
|
+
const declareContractPayload = (0, _contract.extractContractHashes)(payload);
|
|
273
|
+
const {
|
|
274
|
+
nonce,
|
|
275
|
+
version: providedVersion
|
|
276
|
+
} = details;
|
|
277
|
+
const version = (0, _stark.toTransactionVersion)(!(0, _contract.isSierra)(payload.contract) ? _api.ETransactionVersion.V1 : this.getPreferredVersion(_api.ETransactionVersion.V2, _api.ETransactionVersion.V3), providedVersion);
|
|
278
|
+
const estimate = await this.getUniversalSuggestedFee(version, {
|
|
279
|
+
type: _types.TransactionType.DECLARE,
|
|
280
|
+
payload: declareContractPayload
|
|
281
|
+
}, {
|
|
282
|
+
...details,
|
|
283
|
+
version
|
|
284
|
+
});
|
|
285
|
+
const declareDetails = {
|
|
286
|
+
...(0, _stark.v3Details)(details),
|
|
287
|
+
resourceBounds: estimate.resourceBounds,
|
|
288
|
+
maxFee: estimate.maxFee,
|
|
289
|
+
nonce: (0, _num.toBigInt)(nonce ?? (await this.getNonce())),
|
|
290
|
+
version,
|
|
291
|
+
chainId: await this.getChainId(),
|
|
292
|
+
walletAddress: this.address,
|
|
293
|
+
cairoVersion: void 0
|
|
294
|
+
};
|
|
295
|
+
const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, declareDetails);
|
|
296
|
+
return this.declareContract(declareContractTransaction, declareDetails);
|
|
297
|
+
}
|
|
298
|
+
async deploy(payload, details = {}) {
|
|
299
|
+
const {
|
|
300
|
+
calls,
|
|
301
|
+
addresses
|
|
302
|
+
} = (0, _transaction.buildUDCCall)(payload, this.address);
|
|
303
|
+
const invokeResponse = await this.execute(calls, void 0, details);
|
|
304
|
+
return {
|
|
305
|
+
...invokeResponse,
|
|
306
|
+
contract_address: addresses
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
async deployContract(payload, details = {}) {
|
|
310
|
+
const deployTx = await this.deploy(payload, details);
|
|
311
|
+
const txReceipt = await this.waitForTransaction(deployTx.transaction_hash);
|
|
312
|
+
return (0, _events.parseUDCEvent)(txReceipt);
|
|
313
|
+
}
|
|
314
|
+
async declareAndDeploy(payload, details = {}) {
|
|
315
|
+
const {
|
|
316
|
+
constructorCalldata,
|
|
317
|
+
salt,
|
|
318
|
+
unique
|
|
319
|
+
} = payload;
|
|
320
|
+
let declare = await this.declareIfNot(payload, details);
|
|
321
|
+
if (declare.transaction_hash !== "") {
|
|
322
|
+
const tx = await this.waitForTransaction(declare.transaction_hash);
|
|
323
|
+
declare = {
|
|
324
|
+
...declare,
|
|
325
|
+
...tx
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
const deploy = await this.deployContract({
|
|
329
|
+
classHash: declare.class_hash,
|
|
330
|
+
salt,
|
|
331
|
+
unique,
|
|
332
|
+
constructorCalldata
|
|
333
|
+
}, details);
|
|
334
|
+
return {
|
|
335
|
+
declare: {
|
|
336
|
+
...declare
|
|
337
|
+
},
|
|
338
|
+
deploy
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
deploySelf = this.deployAccount;
|
|
342
|
+
async deployAccount({
|
|
343
|
+
classHash,
|
|
344
|
+
constructorCalldata = [],
|
|
345
|
+
addressSalt = 0,
|
|
346
|
+
contractAddress: providedContractAddress
|
|
347
|
+
}, details = {}) {
|
|
348
|
+
const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.V1, _api.ETransactionVersion.V3), details.version);
|
|
349
|
+
const nonce = _constants.ZERO;
|
|
350
|
+
const chainId = await this.getChainId();
|
|
351
|
+
const compiledCalldata = _calldata.CallData.compile(constructorCalldata);
|
|
352
|
+
const contractAddress = providedContractAddress ?? (0, _hash.calculateContractAddressFromHash)(addressSalt, classHash, compiledCalldata, 0);
|
|
353
|
+
const estimate = await this.getUniversalSuggestedFee(version, {
|
|
354
|
+
type: _types.TransactionType.DEPLOY_ACCOUNT,
|
|
355
|
+
payload: {
|
|
356
|
+
classHash,
|
|
357
|
+
constructorCalldata: compiledCalldata,
|
|
358
|
+
addressSalt,
|
|
359
|
+
contractAddress
|
|
360
|
+
}
|
|
361
|
+
}, details);
|
|
362
|
+
const signature = await this.signer.signDeployAccountTransaction({
|
|
363
|
+
...(0, _stark.v3Details)(details),
|
|
364
|
+
classHash,
|
|
365
|
+
constructorCalldata: compiledCalldata,
|
|
366
|
+
contractAddress,
|
|
367
|
+
addressSalt,
|
|
368
|
+
chainId,
|
|
369
|
+
resourceBounds: estimate.resourceBounds,
|
|
370
|
+
maxFee: estimate.maxFee,
|
|
371
|
+
version,
|
|
372
|
+
nonce
|
|
373
|
+
});
|
|
374
|
+
return this.deployAccountContract({
|
|
375
|
+
classHash,
|
|
376
|
+
addressSalt,
|
|
377
|
+
constructorCalldata,
|
|
378
|
+
signature
|
|
379
|
+
}, {
|
|
380
|
+
...(0, _stark.v3Details)(details),
|
|
381
|
+
nonce,
|
|
382
|
+
resourceBounds: estimate.resourceBounds,
|
|
383
|
+
maxFee: estimate.maxFee,
|
|
384
|
+
version
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async signMessage(typedData) {
|
|
388
|
+
return this.signer.signMessage(typedData, this.address);
|
|
389
|
+
}
|
|
390
|
+
async hashMessage(typedData) {
|
|
391
|
+
return (0, _typedData.getMessageHash)(typedData, this.address);
|
|
392
|
+
}
|
|
393
|
+
async verifyMessageHash(hash, signature, signatureVerificationFunctionName, signatureVerificationResponse) {
|
|
394
|
+
const knownSigVerificationFName = signatureVerificationFunctionName ? [signatureVerificationFunctionName] : ["isValidSignature", "is_valid_signature"];
|
|
395
|
+
const knownSignatureResponse = signatureVerificationResponse || {
|
|
396
|
+
okResponse: [
|
|
397
|
+
// any non-nok response is true
|
|
398
|
+
],
|
|
399
|
+
nokResponse: ["0x0",
|
|
400
|
+
// Devnet
|
|
401
|
+
"0x00"
|
|
402
|
+
// OpenZeppelin 0.7.0 to 0.9.0 invalid signature
|
|
403
|
+
],
|
|
404
|
+
error: ["argent/invalid-signature",
|
|
405
|
+
// ArgentX 0.3.0 to 0.3.1
|
|
406
|
+
"is invalid, with respect to the public key",
|
|
407
|
+
// OpenZeppelin until 0.6.1, Braavos 0.0.11
|
|
408
|
+
"INVALID_SIG"
|
|
409
|
+
// Braavos 1.0.0
|
|
410
|
+
]
|
|
411
|
+
};
|
|
412
|
+
let error;
|
|
413
|
+
for (const SigVerificationFName of knownSigVerificationFName) {
|
|
414
|
+
try {
|
|
415
|
+
const resp = await this.callContract({
|
|
416
|
+
contractAddress: this.address,
|
|
417
|
+
entrypoint: SigVerificationFName,
|
|
418
|
+
calldata: _calldata.CallData.compile({
|
|
419
|
+
hash: (0, _num.toBigInt)(hash).toString(),
|
|
420
|
+
signature: (0, _stark.formatSignature)(signature)
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
if (knownSignatureResponse.nokResponse.includes(resp[0].toString())) {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
if (knownSignatureResponse.okResponse.length === 0 || knownSignatureResponse.okResponse.includes(resp[0].toString())) {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
throw Error("signatureVerificationResponse Error: response is not part of known responses");
|
|
430
|
+
} catch (err) {
|
|
431
|
+
if (knownSignatureResponse.error.some(errMessage => err.message.includes(errMessage))) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
error = err;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
throw Error(`Signature verification Error: ${error}`);
|
|
438
|
+
}
|
|
439
|
+
async verifyMessage(typedData, signature, signatureVerificationFunctionName, signatureVerificationResponse) {
|
|
440
|
+
const hash = await this.hashMessage(typedData);
|
|
441
|
+
return this.verifyMessageHash(hash, signature, signatureVerificationFunctionName, signatureVerificationResponse);
|
|
442
|
+
}
|
|
443
|
+
/*
|
|
444
|
+
* Support methods
|
|
445
|
+
*/
|
|
446
|
+
async getUniversalSuggestedFee(version, {
|
|
447
|
+
type,
|
|
448
|
+
payload
|
|
449
|
+
}, details) {
|
|
450
|
+
let maxFee = 0;
|
|
451
|
+
let resourceBounds = (0, _stark.estimateFeeToBounds)(_constants.ZERO);
|
|
452
|
+
if (version === _api.ETransactionVersion.V3) {
|
|
453
|
+
resourceBounds = details.resourceBounds ?? (await this.getSuggestedFee({
|
|
454
|
+
type,
|
|
455
|
+
payload
|
|
456
|
+
}, details)).resourceBounds;
|
|
457
|
+
} else {
|
|
458
|
+
maxFee = details.maxFee ?? (await this.getSuggestedFee({
|
|
459
|
+
type,
|
|
460
|
+
payload
|
|
461
|
+
}, details)).suggestedMaxFee;
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
maxFee,
|
|
465
|
+
resourceBounds
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
async getSuggestedFee({
|
|
469
|
+
type,
|
|
470
|
+
payload
|
|
471
|
+
}, details) {
|
|
472
|
+
let feeEstimate;
|
|
473
|
+
switch (type) {
|
|
474
|
+
case _types.TransactionType.INVOKE:
|
|
475
|
+
feeEstimate = await this.estimateInvokeFee(payload, details);
|
|
476
|
+
break;
|
|
477
|
+
case _types.TransactionType.DECLARE:
|
|
478
|
+
feeEstimate = await this.estimateDeclareFee(payload, details);
|
|
479
|
+
break;
|
|
480
|
+
case _types.TransactionType.DEPLOY_ACCOUNT:
|
|
481
|
+
feeEstimate = await this.estimateAccountDeployFee(payload, details);
|
|
482
|
+
break;
|
|
483
|
+
case _types.TransactionType.DEPLOY:
|
|
484
|
+
feeEstimate = await this.estimateDeployFee(payload, details);
|
|
485
|
+
break;
|
|
486
|
+
default:
|
|
487
|
+
feeEstimate = {
|
|
488
|
+
gas_consumed: 0n,
|
|
489
|
+
gas_price: 0n,
|
|
490
|
+
overall_fee: _constants.ZERO,
|
|
491
|
+
unit: "FRI",
|
|
492
|
+
suggestedMaxFee: _constants.ZERO,
|
|
493
|
+
resourceBounds: (0, _stark.estimateFeeToBounds)(_constants.ZERO),
|
|
494
|
+
data_gas_consumed: 0n,
|
|
495
|
+
data_gas_price: 0n
|
|
496
|
+
};
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
return feeEstimate;
|
|
500
|
+
}
|
|
501
|
+
async buildInvocation(call, details) {
|
|
502
|
+
const calldata = (0, _transaction.getExecuteCalldata)(call, await this.getCairoVersion());
|
|
503
|
+
const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
|
|
504
|
+
return {
|
|
505
|
+
...(0, _stark.v3Details)(details),
|
|
506
|
+
contractAddress: this.address,
|
|
507
|
+
calldata,
|
|
508
|
+
signature
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
async buildDeclarePayload(payload, details) {
|
|
512
|
+
const {
|
|
513
|
+
classHash,
|
|
514
|
+
contract,
|
|
515
|
+
compiledClassHash
|
|
516
|
+
} = (0, _contract.extractContractHashes)(payload);
|
|
517
|
+
const compressedCompiledContract = (0, _provider2.parseContract)(contract);
|
|
518
|
+
if (typeof compiledClassHash === "undefined" && (details.version === _api.ETransactionVersion3.F3 || details.version === _api.ETransactionVersion3.V3)) {
|
|
519
|
+
throw Error("V3 Transaction work with Cairo1 Contracts and require compiledClassHash");
|
|
520
|
+
}
|
|
521
|
+
const signature = !details.skipValidate ? await this.signer.signDeclareTransaction({
|
|
522
|
+
...details,
|
|
523
|
+
...(0, _stark.v3Details)(details),
|
|
524
|
+
classHash,
|
|
525
|
+
compiledClassHash,
|
|
526
|
+
// TODO: TS, cast because optional for v2 and required for v3, thrown if not present
|
|
527
|
+
senderAddress: details.walletAddress
|
|
528
|
+
}) : [];
|
|
529
|
+
return {
|
|
530
|
+
senderAddress: details.walletAddress,
|
|
531
|
+
signature,
|
|
532
|
+
contract: compressedCompiledContract,
|
|
533
|
+
compiledClassHash
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
async buildAccountDeployPayload({
|
|
537
|
+
classHash,
|
|
538
|
+
addressSalt = 0,
|
|
539
|
+
constructorCalldata = [],
|
|
540
|
+
contractAddress: providedContractAddress
|
|
541
|
+
}, details) {
|
|
542
|
+
const compiledCalldata = _calldata.CallData.compile(constructorCalldata);
|
|
543
|
+
const contractAddress = providedContractAddress ?? (0, _hash.calculateContractAddressFromHash)(addressSalt, classHash, compiledCalldata, 0);
|
|
544
|
+
const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
|
|
545
|
+
...details,
|
|
546
|
+
...(0, _stark.v3Details)(details),
|
|
547
|
+
classHash,
|
|
548
|
+
contractAddress,
|
|
549
|
+
addressSalt,
|
|
550
|
+
constructorCalldata: compiledCalldata
|
|
551
|
+
}) : [];
|
|
552
|
+
return {
|
|
553
|
+
...(0, _stark.v3Details)(details),
|
|
554
|
+
classHash,
|
|
555
|
+
addressSalt,
|
|
556
|
+
constructorCalldata: compiledCalldata,
|
|
557
|
+
signature
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
buildUDCContractPayload(payload) {
|
|
561
|
+
const calls = [].concat(payload).map(it => {
|
|
562
|
+
const {
|
|
563
|
+
classHash,
|
|
564
|
+
salt = "0",
|
|
565
|
+
unique = true,
|
|
566
|
+
constructorCalldata = []
|
|
567
|
+
} = it;
|
|
568
|
+
const compiledConstructorCallData = _calldata.CallData.compile(constructorCalldata);
|
|
569
|
+
return {
|
|
570
|
+
contractAddress: _constants.UDC.ADDRESS,
|
|
571
|
+
entrypoint: _constants.UDC.ENTRYPOINT,
|
|
572
|
+
calldata: [classHash, salt, (0, _num.toCairoBool)(unique), compiledConstructorCallData.length, ...compiledConstructorCallData]
|
|
573
|
+
};
|
|
574
|
+
});
|
|
575
|
+
return calls;
|
|
576
|
+
}
|
|
577
|
+
async accountInvocationsFactory(invocations, details) {
|
|
578
|
+
const {
|
|
579
|
+
nonce,
|
|
580
|
+
blockIdentifier,
|
|
581
|
+
skipValidate = true
|
|
582
|
+
} = details;
|
|
583
|
+
const safeNonce = await this.getNonceSafe(nonce);
|
|
584
|
+
const chainId = await this.getChainId();
|
|
585
|
+
const versions = details.versions.map(it => (0, _stark.toTransactionVersion)(it));
|
|
586
|
+
const tx0Payload = "payload" in invocations[0] ? invocations[0].payload : invocations[0];
|
|
587
|
+
const cairoVersion = invocations[0].type === _types.TransactionType.DEPLOY_ACCOUNT ? await this.getCairoVersion(tx0Payload.classHash) : await this.getCairoVersion();
|
|
588
|
+
return Promise.all([].concat(invocations).map(async (transaction, index) => {
|
|
589
|
+
const txPayload = "payload" in transaction ? transaction.payload : transaction;
|
|
590
|
+
const signerDetails = {
|
|
591
|
+
...(0, _stark.v3Details)(details),
|
|
592
|
+
walletAddress: this.address,
|
|
593
|
+
nonce: (0, _num.toBigInt)(Number(safeNonce) + index),
|
|
594
|
+
maxFee: _constants.ZERO,
|
|
595
|
+
chainId,
|
|
596
|
+
cairoVersion,
|
|
597
|
+
version: "",
|
|
598
|
+
skipValidate
|
|
599
|
+
};
|
|
600
|
+
const common = {
|
|
601
|
+
type: transaction.type,
|
|
602
|
+
nonce: (0, _num.toBigInt)(Number(safeNonce) + index),
|
|
603
|
+
blockIdentifier,
|
|
604
|
+
version: ""
|
|
605
|
+
};
|
|
606
|
+
if (transaction.type === _types.TransactionType.INVOKE) {
|
|
607
|
+
const versionX = (0, _stark.reduceV2)(versions[1]);
|
|
608
|
+
signerDetails.version = versionX;
|
|
609
|
+
common.version = versionX;
|
|
610
|
+
const payload = await this.buildInvocation([].concat(txPayload), signerDetails);
|
|
611
|
+
return {
|
|
612
|
+
...common,
|
|
613
|
+
...payload
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
if (transaction.type === _types.TransactionType.DEPLOY) {
|
|
617
|
+
const versionX = (0, _stark.reduceV2)(versions[1]);
|
|
618
|
+
signerDetails.version = versionX;
|
|
619
|
+
common.version = versionX;
|
|
620
|
+
const calls = this.buildUDCContractPayload(txPayload);
|
|
621
|
+
const payload = await this.buildInvocation(calls, signerDetails);
|
|
622
|
+
return {
|
|
623
|
+
...common,
|
|
624
|
+
...payload,
|
|
625
|
+
type: _types.TransactionType.INVOKE
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
if (transaction.type === _types.TransactionType.DECLARE) {
|
|
629
|
+
const versionX = !(0, _contract.isSierra)(txPayload.contract) ? versions[0] : versions[1];
|
|
630
|
+
signerDetails.version = versionX;
|
|
631
|
+
common.version = versionX;
|
|
632
|
+
const payload = await this.buildDeclarePayload(txPayload, signerDetails);
|
|
633
|
+
return {
|
|
634
|
+
...common,
|
|
635
|
+
...payload
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (transaction.type === _types.TransactionType.DEPLOY_ACCOUNT) {
|
|
639
|
+
const versionX = (0, _stark.reduceV2)(versions[1]);
|
|
640
|
+
signerDetails.version = versionX;
|
|
641
|
+
common.version = versionX;
|
|
642
|
+
const payload = await this.buildAccountDeployPayload(txPayload, signerDetails);
|
|
643
|
+
return {
|
|
644
|
+
...common,
|
|
645
|
+
...payload
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
throw Error(`accountInvocationsFactory: unsupported transaction type: ${transaction}`);
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
async getStarkName(address = this.address, StarknetIdContract) {
|
|
652
|
+
return super.getStarkName(address, StarknetIdContract);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
exports.Account = Account;
|