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,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test if string contains only ASCII characters (string can be ascii text)
|
|
3
|
+
* @param {string} str The string to test
|
|
4
|
+
* @returns {boolean} Returns true if the string contains only ASCII characters, otherwise false
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const result = shortString.isASCII("Hello, world!");
|
|
8
|
+
* // result = true
|
|
9
|
+
* const result = shortString.isASCII("Hello, 世界!");
|
|
10
|
+
* // result = false
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare function isASCII(str: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Test if a string is a Cairo short string (string with less or equal 31 characters)
|
|
16
|
+
* @param {string} str the string to test
|
|
17
|
+
* @returns {boolean} Returns true if the string has less than or equal to 31 characters, otherwise false.
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const result = shortString.isShortString("Hello, world!");
|
|
21
|
+
* // result = true
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function isShortString(str: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Test if string contains only numbers (string can be converted to decimal integer number)
|
|
27
|
+
* @param {string} str the string to test.
|
|
28
|
+
* @returns {boolean} Returns true if the string contains only numbers, otherwise false.
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const result = shortString.isDecimalString("12345");
|
|
32
|
+
* // result = true
|
|
33
|
+
* const result = shortString.isDecimalString("12a45");
|
|
34
|
+
* // result = false
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function isDecimalString(str: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a given value is a string.
|
|
40
|
+
* @param {unknown} value the value to be checked.
|
|
41
|
+
* @return {boolean} returns true if the value is a string, false otherwise.
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const result = shortString.isString("12345");
|
|
45
|
+
* // result = true
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function isString(value: unknown): value is string;
|
|
49
|
+
/**
|
|
50
|
+
* Test if value is a pure string text, and not a hex string or number string
|
|
51
|
+
* @param {any} val the value to test
|
|
52
|
+
* @returns {boolean} returns true if the value is a free-form string text, otherwise false
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const result = shortString.isText("Hello, world!");
|
|
56
|
+
* // result = true
|
|
57
|
+
* const result = shortString.isText("0x7aec92f706");
|
|
58
|
+
* // result = false
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function isText(val: any): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Test if value is short text
|
|
64
|
+
* @param {any} val - The item to test
|
|
65
|
+
* @returns {boolean} Returns true if the value is a short text (string has less or equal 31 characters), otherwise false
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const result = shortString.isShortText("Hello, world!");
|
|
69
|
+
* // result = true
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const isShortText: (val: any) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Test if value is long text
|
|
75
|
+
* @param {any} val the value to test
|
|
76
|
+
* @returns {boolean} returns true if the value is a long text(string has more than 31 characters), otherwise false.
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const result = shortString.isLongText("Hello, world! this is some random long string to enable you test isLongText function.");
|
|
80
|
+
* // result = true
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare const isLongText: (val: any) => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Split long text (string greater than 31 characters) into short strings (string lesser or equal 31 characters)
|
|
86
|
+
* @param {string} longStr the long text (string greater than 31 characters) to split
|
|
87
|
+
* @returns {string[]} an array of short strings (string lesser or equal 31 characters).
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const result = shortString.splitLongString("Hello, world! we just testing splitLongString function.");
|
|
91
|
+
* // result = [ 'Hello, world! we just testing s', 'plitLongString function.' ]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function splitLongString(longStr: string): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Convert an ASCII short string to a hexadecimal string.
|
|
97
|
+
* @param {string} str short string (ASCII string, 31 characters max)
|
|
98
|
+
* @returns {string} hex-string with 248 bits max
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const result = shortString.encodeShortString("uri/pict/t38.jpg");
|
|
102
|
+
* // result = "0x7572692f706963742f7433382e6a7067"
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function encodeShortString(str: string): string;
|
|
106
|
+
/**
|
|
107
|
+
* Convert a hexadecimal or decimal string to an ASCII string.
|
|
108
|
+
* @param {string} str representing a 248 bit max number (ex. "0x1A4F64EA56" or "236942575435676423")
|
|
109
|
+
* @returns {string} short string; 31 characters max
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const result = shortString.decodeShortString("0x7572692f706963742f7433382e6a7067");
|
|
113
|
+
* // result = "uri/pict/t38.jpg"
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare function decodeShortString(str: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TEXT_TO_FELT_MAX_LEN } from "../constants.mjs";
|
|
2
|
+
import { addHexPrefix, removeHexPrefix } from "./encode.mjs";
|
|
3
|
+
import { isHex, isStringWholeNumber } from "./num.mjs";
|
|
4
|
+
export function isASCII(str) {
|
|
5
|
+
return /^[\x00-\x7F]*$/.test(str);
|
|
6
|
+
}
|
|
7
|
+
export function isShortString(str) {
|
|
8
|
+
return str.length <= TEXT_TO_FELT_MAX_LEN;
|
|
9
|
+
}
|
|
10
|
+
export function isDecimalString(str) {
|
|
11
|
+
return /^[0-9]*$/i.test(str);
|
|
12
|
+
}
|
|
13
|
+
export function isString(value) {
|
|
14
|
+
return typeof value === "string";
|
|
15
|
+
}
|
|
16
|
+
export function isText(val) {
|
|
17
|
+
return isString(val) && !isHex(val) && !isStringWholeNumber(val);
|
|
18
|
+
}
|
|
19
|
+
export const isShortText = (val) => isText(val) && isShortString(val);
|
|
20
|
+
export const isLongText = (val) => isText(val) && !isShortString(val);
|
|
21
|
+
export function splitLongString(longStr) {
|
|
22
|
+
const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, "g");
|
|
23
|
+
return longStr.match(regex) || [];
|
|
24
|
+
}
|
|
25
|
+
export function encodeShortString(str) {
|
|
26
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
27
|
+
if (!isShortString(str)) throw new Error(`${str} is too long`);
|
|
28
|
+
return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
|
|
29
|
+
}
|
|
30
|
+
export function decodeShortString(str) {
|
|
31
|
+
if (!isASCII(str)) throw new Error(`${str} is not an ASCII string`);
|
|
32
|
+
if (isHex(str)) {
|
|
33
|
+
return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
34
|
+
}
|
|
35
|
+
if (isDecimalString(str)) {
|
|
36
|
+
return decodeShortString("0X".concat(BigInt(str).toString(16)));
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`${str} is not Hex or decimal`);
|
|
39
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.compressProgram = compressProgram;
|
|
7
|
+
exports.decompressProgram = decompressProgram;
|
|
8
|
+
exports.estimateFeeToBounds = estimateFeeToBounds;
|
|
9
|
+
exports.estimatedFeeToMaxFee = estimatedFeeToMaxFee;
|
|
10
|
+
exports.formatSignature = formatSignature;
|
|
11
|
+
exports.intDAM = intDAM;
|
|
12
|
+
exports.makeAddress = makeAddress;
|
|
13
|
+
exports.randomAddress = randomAddress;
|
|
14
|
+
exports.reduceV2 = reduceV2;
|
|
15
|
+
exports.signatureToDecimalArray = signatureToDecimalArray;
|
|
16
|
+
exports.signatureToHexArray = signatureToHexArray;
|
|
17
|
+
exports.toFeeVersion = toFeeVersion;
|
|
18
|
+
exports.toTransactionVersion = toTransactionVersion;
|
|
19
|
+
exports.v3Details = v3Details;
|
|
20
|
+
var _starknet = require("@scure/starknet");
|
|
21
|
+
var _pako = require("pako");
|
|
22
|
+
var _constants = require("../constants.cjs");
|
|
23
|
+
var _api = require("../types/api/index.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 compressProgram(jsonProgram) {
|
|
29
|
+
const stringified = (0, _shortString.isString)(jsonProgram) ? jsonProgram : (0, _json.stringify)(jsonProgram);
|
|
30
|
+
const compressedProgram = (0, _pako.gzip)(stringified);
|
|
31
|
+
return (0, _encode.btoaUniversal)(compressedProgram);
|
|
32
|
+
}
|
|
33
|
+
function decompressProgram(base64) {
|
|
34
|
+
if (Array.isArray(base64)) return base64;
|
|
35
|
+
const decompressed = (0, _encode.arrayBufferToString)((0, _pako.ungzip)((0, _encode.atobUniversal)(base64)));
|
|
36
|
+
return (0, _json.parse)(decompressed);
|
|
37
|
+
}
|
|
38
|
+
function randomAddress() {
|
|
39
|
+
const randomKeyPair = _starknet.utils.randomPrivateKey();
|
|
40
|
+
return (0, _starknet.getStarkKey)(randomKeyPair);
|
|
41
|
+
}
|
|
42
|
+
function makeAddress(input) {
|
|
43
|
+
return (0, _encode.addHexPrefix)(input).toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
function formatSignature(sig) {
|
|
46
|
+
if (!sig) throw Error("formatSignature: provided signature is undefined");
|
|
47
|
+
if (Array.isArray(sig)) {
|
|
48
|
+
return sig.map(it => (0, _num.toHex)(it));
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const {
|
|
52
|
+
r,
|
|
53
|
+
s
|
|
54
|
+
} = sig;
|
|
55
|
+
return [(0, _num.toHex)(r), (0, _num.toHex)(s)];
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function signatureToDecimalArray(sig) {
|
|
61
|
+
return (0, _num.bigNumberishArrayToDecimalStringArray)(formatSignature(sig));
|
|
62
|
+
}
|
|
63
|
+
function signatureToHexArray(sig) {
|
|
64
|
+
return (0, _num.bigNumberishArrayToHexadecimalStringArray)(formatSignature(sig));
|
|
65
|
+
}
|
|
66
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead = _constants.FeeMarginPercentage.MAX_FEE) {
|
|
67
|
+
return (0, _num.addPercent)(estimatedFee, overhead);
|
|
68
|
+
}
|
|
69
|
+
function estimateFeeToBounds(estimate, amountOverhead = _constants.FeeMarginPercentage.L1_BOUND_MAX_AMOUNT, priceOverhead = _constants.FeeMarginPercentage.L1_BOUND_MAX_PRICE_PER_UNIT) {
|
|
70
|
+
if ((0, _num.isBigInt)(estimate)) {
|
|
71
|
+
return {
|
|
72
|
+
l2_gas: {
|
|
73
|
+
max_amount: "0x0",
|
|
74
|
+
max_price_per_unit: "0x0"
|
|
75
|
+
},
|
|
76
|
+
l1_gas: {
|
|
77
|
+
max_amount: "0x0",
|
|
78
|
+
max_price_per_unit: "0x0"
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (typeof estimate.gas_consumed === "undefined" || typeof estimate.gas_price === "undefined") {
|
|
83
|
+
throw Error("estimateFeeToBounds: estimate is undefined");
|
|
84
|
+
}
|
|
85
|
+
const maxUnits = estimate.data_gas_consumed !== void 0 && estimate.data_gas_price !== void 0 ? (0, _num.toHex)((0, _num.addPercent)(BigInt(estimate.overall_fee) / BigInt(estimate.gas_price), amountOverhead)) : (0, _num.toHex)((0, _num.addPercent)(estimate.gas_consumed, amountOverhead));
|
|
86
|
+
const maxUnitPrice = (0, _num.toHex)((0, _num.addPercent)(estimate.gas_price, priceOverhead));
|
|
87
|
+
return {
|
|
88
|
+
l2_gas: {
|
|
89
|
+
max_amount: "0x0",
|
|
90
|
+
max_price_per_unit: "0x0"
|
|
91
|
+
},
|
|
92
|
+
l1_gas: {
|
|
93
|
+
max_amount: maxUnits,
|
|
94
|
+
max_price_per_unit: maxUnitPrice
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function intDAM(dam) {
|
|
99
|
+
if (dam === _api.EDataAvailabilityMode.L1) return _api.EDAMode.L1;
|
|
100
|
+
if (dam === _api.EDataAvailabilityMode.L2) return _api.EDAMode.L2;
|
|
101
|
+
throw Error("EDAM conversion");
|
|
102
|
+
}
|
|
103
|
+
function toTransactionVersion(defaultVersion, providedVersion) {
|
|
104
|
+
const providedVersion0xs = providedVersion ? (0, _num.toHex)(providedVersion) : void 0;
|
|
105
|
+
const defaultVersion0xs = (0, _num.toHex)(defaultVersion);
|
|
106
|
+
if (providedVersion && !Object.values(_api.ETransactionVersion).includes(providedVersion0xs)) {
|
|
107
|
+
throw Error(`providedVersion ${providedVersion} is not ETransactionVersion`);
|
|
108
|
+
}
|
|
109
|
+
if (!Object.values(_api.ETransactionVersion).includes(defaultVersion0xs)) {
|
|
110
|
+
throw Error(`defaultVersion ${defaultVersion} is not ETransactionVersion`);
|
|
111
|
+
}
|
|
112
|
+
return providedVersion ? providedVersion0xs : defaultVersion0xs;
|
|
113
|
+
}
|
|
114
|
+
function toFeeVersion(providedVersion) {
|
|
115
|
+
if (!providedVersion) return void 0;
|
|
116
|
+
const version = (0, _num.toHex)(providedVersion);
|
|
117
|
+
if (version === _api.ETransactionVersion.V0) return _api.ETransactionVersion.F0;
|
|
118
|
+
if (version === _api.ETransactionVersion.V1) return _api.ETransactionVersion.F1;
|
|
119
|
+
if (version === _api.ETransactionVersion.V2) return _api.ETransactionVersion.F2;
|
|
120
|
+
if (version === _api.ETransactionVersion.V3) return _api.ETransactionVersion.F3;
|
|
121
|
+
throw Error(`toFeeVersion: ${version} is not supported`);
|
|
122
|
+
}
|
|
123
|
+
function v3Details(details) {
|
|
124
|
+
return {
|
|
125
|
+
tip: details.tip || 0,
|
|
126
|
+
paymasterData: details.paymasterData || [],
|
|
127
|
+
accountDeploymentData: details.accountDeploymentData || [],
|
|
128
|
+
nonceDataAvailabilityMode: details.nonceDataAvailabilityMode || _api.EDataAvailabilityMode.L1,
|
|
129
|
+
feeDataAvailabilityMode: details.feeDataAvailabilityMode || _api.EDataAvailabilityMode.L1,
|
|
130
|
+
resourceBounds: details.resourceBounds ?? estimateFeeToBounds(_constants.ZERO)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function reduceV2(providedVersion) {
|
|
134
|
+
if (providedVersion === _api.ETransactionVersion.F2) return _api.ETransactionVersion.F1;
|
|
135
|
+
if (providedVersion === _api.ETransactionVersion.V2) return _api.ETransactionVersion.V1;
|
|
136
|
+
return providedVersion;
|
|
137
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { SPEC } from 'starknet-types-07';
|
|
2
|
+
import { ArraySignatureType, BigNumberish, CompressedProgram, Program, Signature, UniversalDetails } from '../types';
|
|
3
|
+
import { EDAMode, EDataAvailabilityMode, ETransactionVersion, ResourceBounds } from '../types/api';
|
|
4
|
+
import { FeeEstimate } from '../types/provider';
|
|
5
|
+
/**
|
|
6
|
+
* Compress compiled Cairo 0 program
|
|
7
|
+
*
|
|
8
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/gateway/transaction.py#L54-L58)
|
|
9
|
+
* @param {Program | string} jsonProgram Representing the compiled Cairo 0 program
|
|
10
|
+
* @return {CompressedProgram} Compressed Cairo 0 program
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const contractCairo0 = json.parse(fs.readFileSync("./cairo0contract.json").toString("ascii"));
|
|
14
|
+
* const result = stark.compressProgram(contractCairo0);
|
|
15
|
+
* // result = "H4sIAAAAAAAAA+1dC4/bOJL+K4aBu01me7r5EEUyixzQk/TuB..."
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function compressProgram(jsonProgram: Program | string): CompressedProgram;
|
|
19
|
+
/**
|
|
20
|
+
* Decompress compressed compiled Cairo 0 program
|
|
21
|
+
* @param {CompressedProgram} base64 Compressed Cairo 0 program
|
|
22
|
+
* @returns {Object | CompressedProgram} Parsed decompressed compiled Cairo 0 program
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const contractCairo0 = json.parse(fs.readFileSync("./cairo0contract.json").toString("ascii"));
|
|
26
|
+
* const compressedCairo0 = stark.compressProgram(contractCairo0);
|
|
27
|
+
* const result = stark.decompressProgram(compressedCairo0);
|
|
28
|
+
* // result = {
|
|
29
|
+
* // abi: [
|
|
30
|
+
* // {
|
|
31
|
+
* // inputs: [Array],
|
|
32
|
+
* // name: 'increase_balance',
|
|
33
|
+
* // outputs: [],
|
|
34
|
+
* // type: 'function'
|
|
35
|
+
* // }
|
|
36
|
+
* // ],
|
|
37
|
+
* // entry_points_by_type: { CONSTRUCTOR: [], EXTERNAL: [ [Object], [Object] ], L1_HANDLER: [] },
|
|
38
|
+
* // program: {
|
|
39
|
+
* // attributes: [],
|
|
40
|
+
* // builtins: [ 'pedersen', 'range_check' ],
|
|
41
|
+
* // compiler_version: '0.10.2',
|
|
42
|
+
* // data: [
|
|
43
|
+
* // '0x480680017fff8000',
|
|
44
|
+
* // ...
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function decompressProgram(base64: CompressedProgram): any;
|
|
48
|
+
/**
|
|
49
|
+
* Random Address based on random keyPair
|
|
50
|
+
* @returns {string} an hex string of a random Starknet address
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const result = stark.randomAddress();
|
|
54
|
+
* // result = "0x51fc8126a13cd5ddb29a71ca399cb1e814f086f5af1b502d7151c14929554f"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function randomAddress(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Lowercase and hex prefix string
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Not used internally, naming is confusing based on functionality
|
|
62
|
+
*/
|
|
63
|
+
export declare function makeAddress(input: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Format Signature to standard type (hex array)
|
|
66
|
+
* @param {Signature} [sig]
|
|
67
|
+
* @returns {ArraySignatureType} Custom hex string array
|
|
68
|
+
* @throws {Error} if sig not defined, or wrong format
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const signature = ec.starkCurve.sign("0x12de34", "0x3487123eac");
|
|
72
|
+
* const result = stark.formatSignature(signature);
|
|
73
|
+
* // result = ['0xba8eecee2d69c417e8c6a20cf331c821f716b58ba9e47166c7476afdb38997',
|
|
74
|
+
* // '0x69ef7438c94104839a6e2aa2385482a77399d2f46e894ae4f50ab6d69239d1c']
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function formatSignature(sig?: Signature): ArraySignatureType;
|
|
78
|
+
/**
|
|
79
|
+
* Format Signature to decimal string array
|
|
80
|
+
* @param {Signature} [sig]
|
|
81
|
+
* @returns {ArraySignatureType} Custom hex string array
|
|
82
|
+
* @throws {Error} if sig not defined, or wrong format
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const signature = ec.starkCurve.sign("0x12de34", "0x3487123eac");
|
|
86
|
+
* const result = stark.signatureToDecimalArray(signature);
|
|
87
|
+
* // result = ['329619989660444495690615805546674399714973829707166906185976654753023887767',
|
|
88
|
+
* // '2994745480203297689255012826403147585778741462125743754529207781488706428188']
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function signatureToDecimalArray(sig?: Signature): ArraySignatureType;
|
|
92
|
+
/**
|
|
93
|
+
* Format Signature to hex string array
|
|
94
|
+
* @param {Signature} [sig]
|
|
95
|
+
* @returns {ArraySignatureType} Custom hex string array
|
|
96
|
+
* @throws {Error} if sig not defined, or wrong format
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const signature = ec.starkCurve.sign("0x12de34", "0x3487123eac");
|
|
100
|
+
* const result = stark.signatureToHexArray(signature);
|
|
101
|
+
* // result = ['0xba8eecee2d69c417e8c6a20cf331c821f716b58ba9e47166c7476afdb38997',
|
|
102
|
+
* // '0x69ef7438c94104839a6e2aa2385482a77399d2f46e894ae4f50ab6d69239d1c']
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function signatureToHexArray(sig?: Signature): ArraySignatureType;
|
|
106
|
+
/**
|
|
107
|
+
* Convert estimated fee to max fee including a margin
|
|
108
|
+
* @param {BigNumberish} estimatedFee - The estimated fee
|
|
109
|
+
* @param {number} [overhead = feeMarginPercentage.MAX_FEE] - The overhead added to the gas
|
|
110
|
+
* @returns {bigint} The maximum fee with the margin
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const result = stark.estimatedFeeToMaxFee("8982300000000", 50);
|
|
114
|
+
* // result = "13473450000000n"
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function estimatedFeeToMaxFee(estimatedFee: BigNumberish, overhead?: number): bigint;
|
|
118
|
+
/**
|
|
119
|
+
* Calculates the maximum resource bounds for fee estimation.
|
|
120
|
+
*
|
|
121
|
+
* @param {FeeEstimate | 0n} estimate The estimate for the fee. If a BigInt is provided, the returned bounds will be set to '0x0'.
|
|
122
|
+
* @param {number} [amountOverhead = feeMarginPercentage.L1_BOUND_MAX_AMOUNT] - The percentage overhead added to the gas consumed or overall fee amount.
|
|
123
|
+
* @param {number} [priceOverhead = feeMarginPercentage.L1_BOUND_MAX_PRICE_PER_UNIT] The percentage overhead added to the gas price per unit.
|
|
124
|
+
* @returns {ResourceBounds} The maximum resource bounds for fee estimation.
|
|
125
|
+
* @throws {Error} If the estimate object is undefined or does not have the required properties.
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const feeEstimated: FeeEstimate = {
|
|
129
|
+
gas_consumed: "0x3456a",
|
|
130
|
+
gas_price: "0xa45567567567ae4",
|
|
131
|
+
overall_fee: "0x2198F463A77A899A5668",
|
|
132
|
+
unit: "WEI"
|
|
133
|
+
};
|
|
134
|
+
const result = stark.estimateFeeToBounds(feeEstimated, 70, 50);
|
|
135
|
+
* // result = {
|
|
136
|
+
* // l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
137
|
+
* // l1_gas: { max_amount: '0x58f9a', max_price_per_unit: '0xf6801b01b01b856' }
|
|
138
|
+
* // }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function estimateFeeToBounds(estimate: FeeEstimate | 0n, amountOverhead?: number, priceOverhead?: number): ResourceBounds;
|
|
142
|
+
/**
|
|
143
|
+
* Converts the data availability mode from EDataAvailabilityMode to EDAMode.
|
|
144
|
+
*
|
|
145
|
+
* @param {EDataAvailabilityMode} dam The data availability mode to be converted.
|
|
146
|
+
* @return {EDAMode} The converted data availability mode.
|
|
147
|
+
* @throws {Error} If the data availability mode is not a valid value.
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const result = stark.intDAM(RPC.EDataAvailabilityMode.L1);
|
|
151
|
+
* // result = 0
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function intDAM(dam: EDataAvailabilityMode): EDAMode;
|
|
155
|
+
/**
|
|
156
|
+
* Convert to ETransactionVersion or throw an error.
|
|
157
|
+
* Return providedVersion is specified else return defaultVersion
|
|
158
|
+
* @param {BigNumberish} defaultVersion default estimate transaction version
|
|
159
|
+
* @param {BigNumberish} [providedVersion] estimate transaction version
|
|
160
|
+
* @returns {ETransactionVersion} if providedVersion is not provided, returns the default estimate version, else return the provided version
|
|
161
|
+
* @throws {Error} if estimate transaction version or default estimate transaction version is unknown
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const result = stark.toTransactionVersion("0x100000000000000000000000000000003", stark.toFeeVersion(2));
|
|
165
|
+
* // result = "0x100000000000000000000000000000002"
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function toTransactionVersion(defaultVersion: BigNumberish, providedVersion?: BigNumberish): ETransactionVersion;
|
|
169
|
+
/**
|
|
170
|
+
* Convert Transaction version to Fee version or throw an error
|
|
171
|
+
* @param {BigNumberish} [providedVersion] 0..3 number representing the transaction version
|
|
172
|
+
* @returns {ETransactionVersion} the fee estimation version corresponding to the transaction version provided
|
|
173
|
+
* @throws {Error} if the transaction version is unknown
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const result = stark.toFeeVersion(2);
|
|
177
|
+
* // result = "0x100000000000000000000000000000002"
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare function toFeeVersion(providedVersion?: BigNumberish): "0x100000000000000000000000000000000" | "0x100000000000000000000000000000001" | "0x100000000000000000000000000000002" | "0x100000000000000000000000000000003" | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Return provided or default v3 tx details
|
|
183
|
+
* @param {UniversalDetails} details details of the transaction
|
|
184
|
+
* @return {} an object including the V3 transaction details.
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const detail: UniversalDetails = { tip: 3456n };
|
|
188
|
+
* const result = stark.v3Details(detail);
|
|
189
|
+
* // result = {
|
|
190
|
+
* // tip: 3456n,
|
|
191
|
+
* // paymasterData: [],
|
|
192
|
+
* // accountDeploymentData: [],
|
|
193
|
+
* // nonceDataAvailabilityMode: 'L1',
|
|
194
|
+
* // feeDataAvailabilityMode: 'L1',
|
|
195
|
+
* // resourceBounds: {
|
|
196
|
+
* // l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
|
|
197
|
+
* // l1_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }
|
|
198
|
+
* // }
|
|
199
|
+
* // }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export declare function v3Details(details: UniversalDetails): {
|
|
203
|
+
tip: BigNumberish;
|
|
204
|
+
paymasterData: BigNumberish[];
|
|
205
|
+
accountDeploymentData: BigNumberish[];
|
|
206
|
+
nonceDataAvailabilityMode: EDataAvailabilityMode;
|
|
207
|
+
feeDataAvailabilityMode: EDataAvailabilityMode;
|
|
208
|
+
resourceBounds: SPEC.RESOURCE_BOUNDS_MAPPING;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* It will reduce V2 to V1, else (V3) stay the same
|
|
212
|
+
* F2 -> F1
|
|
213
|
+
* V2 -> V1
|
|
214
|
+
* F3 -> F3
|
|
215
|
+
* V3 -> V3
|
|
216
|
+
* @param {ETransactionVersion} providedVersion
|
|
217
|
+
* @returns {ETransactionVersion} if v2 then returns v1. if v3 then return v3
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const result = stark.reduceV2(constants.TRANSACTION_VERSION.V2);
|
|
221
|
+
* // result = "0x1"
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export declare function reduceV2(providedVersion: ETransactionVersion): ETransactionVersion;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getStarkKey, utils } from "@scure/starknet";
|
|
2
|
+
import { gzip, ungzip } from "pako";
|
|
3
|
+
import { ZERO, FeeMarginPercentage } from "../constants.mjs";
|
|
4
|
+
import { EDAMode, EDataAvailabilityMode, ETransactionVersion } from "../types/api/index.mjs";
|
|
5
|
+
import { addHexPrefix, arrayBufferToString, atobUniversal, btoaUniversal } from "./encode.mjs";
|
|
6
|
+
import { parse, stringify } from "./json.mjs";
|
|
7
|
+
import {
|
|
8
|
+
addPercent,
|
|
9
|
+
bigNumberishArrayToDecimalStringArray,
|
|
10
|
+
bigNumberishArrayToHexadecimalStringArray,
|
|
11
|
+
isBigInt,
|
|
12
|
+
toHex
|
|
13
|
+
} from "./num.mjs";
|
|
14
|
+
import { isString } from "./shortString.mjs";
|
|
15
|
+
export function compressProgram(jsonProgram) {
|
|
16
|
+
const stringified = isString(jsonProgram) ? jsonProgram : stringify(jsonProgram);
|
|
17
|
+
const compressedProgram = gzip(stringified);
|
|
18
|
+
return btoaUniversal(compressedProgram);
|
|
19
|
+
}
|
|
20
|
+
export function decompressProgram(base64) {
|
|
21
|
+
if (Array.isArray(base64)) return base64;
|
|
22
|
+
const decompressed = arrayBufferToString(ungzip(atobUniversal(base64)));
|
|
23
|
+
return parse(decompressed);
|
|
24
|
+
}
|
|
25
|
+
export function randomAddress() {
|
|
26
|
+
const randomKeyPair = utils.randomPrivateKey();
|
|
27
|
+
return getStarkKey(randomKeyPair);
|
|
28
|
+
}
|
|
29
|
+
export function makeAddress(input) {
|
|
30
|
+
return addHexPrefix(input).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
export function formatSignature(sig) {
|
|
33
|
+
if (!sig) throw Error("formatSignature: provided signature is undefined");
|
|
34
|
+
if (Array.isArray(sig)) {
|
|
35
|
+
return sig.map((it) => toHex(it));
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const { r, s } = sig;
|
|
39
|
+
return [toHex(r), toHex(s)];
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function signatureToDecimalArray(sig) {
|
|
45
|
+
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
46
|
+
}
|
|
47
|
+
export function signatureToHexArray(sig) {
|
|
48
|
+
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
49
|
+
}
|
|
50
|
+
export function estimatedFeeToMaxFee(estimatedFee, overhead = FeeMarginPercentage.MAX_FEE) {
|
|
51
|
+
return addPercent(estimatedFee, overhead);
|
|
52
|
+
}
|
|
53
|
+
export function estimateFeeToBounds(estimate, amountOverhead = FeeMarginPercentage.L1_BOUND_MAX_AMOUNT, priceOverhead = FeeMarginPercentage.L1_BOUND_MAX_PRICE_PER_UNIT) {
|
|
54
|
+
if (isBigInt(estimate)) {
|
|
55
|
+
return {
|
|
56
|
+
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
57
|
+
l1_gas: { max_amount: "0x0", max_price_per_unit: "0x0" }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (typeof estimate.gas_consumed === "undefined" || typeof estimate.gas_price === "undefined") {
|
|
61
|
+
throw Error("estimateFeeToBounds: estimate is undefined");
|
|
62
|
+
}
|
|
63
|
+
const maxUnits = estimate.data_gas_consumed !== void 0 && estimate.data_gas_price !== void 0 ? toHex(addPercent(BigInt(estimate.overall_fee) / BigInt(estimate.gas_price), amountOverhead)) : toHex(addPercent(estimate.gas_consumed, amountOverhead));
|
|
64
|
+
const maxUnitPrice = toHex(addPercent(estimate.gas_price, priceOverhead));
|
|
65
|
+
return {
|
|
66
|
+
l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
|
|
67
|
+
l1_gas: { max_amount: maxUnits, max_price_per_unit: maxUnitPrice }
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function intDAM(dam) {
|
|
71
|
+
if (dam === EDataAvailabilityMode.L1) return EDAMode.L1;
|
|
72
|
+
if (dam === EDataAvailabilityMode.L2) return EDAMode.L2;
|
|
73
|
+
throw Error("EDAM conversion");
|
|
74
|
+
}
|
|
75
|
+
export function toTransactionVersion(defaultVersion, providedVersion) {
|
|
76
|
+
const providedVersion0xs = providedVersion ? toHex(providedVersion) : void 0;
|
|
77
|
+
const defaultVersion0xs = toHex(defaultVersion);
|
|
78
|
+
if (providedVersion && !Object.values(ETransactionVersion).includes(providedVersion0xs)) {
|
|
79
|
+
throw Error(`providedVersion ${providedVersion} is not ETransactionVersion`);
|
|
80
|
+
}
|
|
81
|
+
if (!Object.values(ETransactionVersion).includes(defaultVersion0xs)) {
|
|
82
|
+
throw Error(`defaultVersion ${defaultVersion} is not ETransactionVersion`);
|
|
83
|
+
}
|
|
84
|
+
return providedVersion ? providedVersion0xs : defaultVersion0xs;
|
|
85
|
+
}
|
|
86
|
+
export function toFeeVersion(providedVersion) {
|
|
87
|
+
if (!providedVersion) return void 0;
|
|
88
|
+
const version = toHex(providedVersion);
|
|
89
|
+
if (version === ETransactionVersion.V0) return ETransactionVersion.F0;
|
|
90
|
+
if (version === ETransactionVersion.V1) return ETransactionVersion.F1;
|
|
91
|
+
if (version === ETransactionVersion.V2) return ETransactionVersion.F2;
|
|
92
|
+
if (version === ETransactionVersion.V3) return ETransactionVersion.F3;
|
|
93
|
+
throw Error(`toFeeVersion: ${version} is not supported`);
|
|
94
|
+
}
|
|
95
|
+
export function v3Details(details) {
|
|
96
|
+
return {
|
|
97
|
+
tip: details.tip || 0,
|
|
98
|
+
paymasterData: details.paymasterData || [],
|
|
99
|
+
accountDeploymentData: details.accountDeploymentData || [],
|
|
100
|
+
nonceDataAvailabilityMode: details.nonceDataAvailabilityMode || EDataAvailabilityMode.L1,
|
|
101
|
+
feeDataAvailabilityMode: details.feeDataAvailabilityMode || EDataAvailabilityMode.L1,
|
|
102
|
+
resourceBounds: details.resourceBounds ?? estimateFeeToBounds(ZERO)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function reduceV2(providedVersion) {
|
|
106
|
+
if (providedVersion === ETransactionVersion.F2) return ETransactionVersion.F1;
|
|
107
|
+
if (providedVersion === ETransactionVersion.V2) return ETransactionVersion.V1;
|
|
108
|
+
return providedVersion;
|
|
109
|
+
}
|