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,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Singular class handling cairo u512 data type
|
|
3
|
+
*/
|
|
4
|
+
import { BigNumberish, type Uint512 } from '../../types';
|
|
5
|
+
export declare const UINT_512_MAX: bigint;
|
|
6
|
+
export declare const UINT_512_MIN = 0n;
|
|
7
|
+
export declare const UINT_128_MIN = 0n;
|
|
8
|
+
export declare class CairoUint512 {
|
|
9
|
+
limb0: bigint;
|
|
10
|
+
limb1: bigint;
|
|
11
|
+
limb2: bigint;
|
|
12
|
+
limb3: bigint;
|
|
13
|
+
static abiSelector: string;
|
|
14
|
+
/**
|
|
15
|
+
* Default constructor (Lib usage)
|
|
16
|
+
* @param bigNumberish BigNumberish value representing u512
|
|
17
|
+
*/
|
|
18
|
+
constructor(bigNumberish: BigNumberish);
|
|
19
|
+
/**
|
|
20
|
+
* Direct props initialization (Api response)
|
|
21
|
+
*/
|
|
22
|
+
constructor(limb0: BigNumberish, limb1: BigNumberish, limb2: BigNumberish, limb3: BigNumberish);
|
|
23
|
+
/**
|
|
24
|
+
* Initialization from Uint512 object
|
|
25
|
+
*/
|
|
26
|
+
constructor(uint512: Uint512);
|
|
27
|
+
/**
|
|
28
|
+
* Validate if BigNumberish can be represented as Uint512
|
|
29
|
+
*/
|
|
30
|
+
static validate(bigNumberish: BigNumberish): bigint;
|
|
31
|
+
/**
|
|
32
|
+
* Validate if limbs can be represented as Uint512
|
|
33
|
+
*/
|
|
34
|
+
static validateProps(limb0: BigNumberish, limb1: BigNumberish, limb2: BigNumberish, limb3: BigNumberish): {
|
|
35
|
+
limb0: bigint;
|
|
36
|
+
limb1: bigint;
|
|
37
|
+
limb2: bigint;
|
|
38
|
+
limb3: bigint;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Check if BigNumberish can be represented as Uint512
|
|
42
|
+
*/
|
|
43
|
+
static is(bigNumberish: BigNumberish): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Check if provided abi type is this data type
|
|
46
|
+
*/
|
|
47
|
+
static isAbiType(abiType: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Return bigint representation
|
|
50
|
+
*/
|
|
51
|
+
toBigInt(): bigint;
|
|
52
|
+
/**
|
|
53
|
+
* Return Uint512 structure with HexString props
|
|
54
|
+
* limbx: HexString
|
|
55
|
+
*/
|
|
56
|
+
toUint512HexString(): {
|
|
57
|
+
limb0: string;
|
|
58
|
+
limb1: string;
|
|
59
|
+
limb2: string;
|
|
60
|
+
limb3: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Return Uint512 structure with DecimalString props
|
|
64
|
+
* limbx DecString
|
|
65
|
+
*/
|
|
66
|
+
toUint512DecimalString(): {
|
|
67
|
+
limb0: string;
|
|
68
|
+
limb1: string;
|
|
69
|
+
limb2: string;
|
|
70
|
+
limb3: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Return api requests representation witch is felt array
|
|
74
|
+
*/
|
|
75
|
+
toApiRequest(): string[];
|
|
76
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { addHexPrefix } from "../encode.mjs";
|
|
2
|
+
import { CairoFelt } from "./felt.mjs";
|
|
3
|
+
import { UINT_128_MAX } from "./uint256.mjs";
|
|
4
|
+
export const UINT_512_MAX = (1n << 512n) - 1n;
|
|
5
|
+
export const UINT_512_MIN = 0n;
|
|
6
|
+
export const UINT_128_MIN = 0n;
|
|
7
|
+
export class CairoUint512 {
|
|
8
|
+
limb0;
|
|
9
|
+
limb1;
|
|
10
|
+
limb2;
|
|
11
|
+
limb3;
|
|
12
|
+
static abiSelector = "core::integer::u512";
|
|
13
|
+
constructor(...arr) {
|
|
14
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
15
|
+
const props = CairoUint512.validateProps(
|
|
16
|
+
arr[0].limb0,
|
|
17
|
+
arr[0].limb1,
|
|
18
|
+
arr[0].limb2,
|
|
19
|
+
arr[0].limb3
|
|
20
|
+
);
|
|
21
|
+
this.limb0 = props.limb0;
|
|
22
|
+
this.limb1 = props.limb1;
|
|
23
|
+
this.limb2 = props.limb2;
|
|
24
|
+
this.limb3 = props.limb3;
|
|
25
|
+
} else if (arr.length === 1) {
|
|
26
|
+
const bigInt = CairoUint512.validate(arr[0]);
|
|
27
|
+
this.limb0 = bigInt & UINT_128_MAX;
|
|
28
|
+
this.limb1 = (bigInt & UINT_128_MAX << 128n) >> 128n;
|
|
29
|
+
this.limb2 = (bigInt & UINT_128_MAX << 256n) >> 256n;
|
|
30
|
+
this.limb3 = bigInt >> 384n;
|
|
31
|
+
} else if (arr.length === 4) {
|
|
32
|
+
const props = CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
|
|
33
|
+
this.limb0 = props.limb0;
|
|
34
|
+
this.limb1 = props.limb1;
|
|
35
|
+
this.limb2 = props.limb2;
|
|
36
|
+
this.limb3 = props.limb3;
|
|
37
|
+
} else {
|
|
38
|
+
throw Error("Incorrect Uint512 constructor parameters");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate if BigNumberish can be represented as Uint512
|
|
43
|
+
*/
|
|
44
|
+
static validate(bigNumberish) {
|
|
45
|
+
const bigInt = BigInt(bigNumberish);
|
|
46
|
+
if (bigInt < UINT_512_MIN) throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
47
|
+
if (bigInt > UINT_512_MAX) throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
48
|
+
return bigInt;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate if limbs can be represented as Uint512
|
|
52
|
+
*/
|
|
53
|
+
static validateProps(limb0, limb1, limb2, limb3) {
|
|
54
|
+
const l0 = BigInt(limb0);
|
|
55
|
+
const l1 = BigInt(limb1);
|
|
56
|
+
const l2 = BigInt(limb2);
|
|
57
|
+
const l3 = BigInt(limb3);
|
|
58
|
+
[l0, l1, l2, l3].forEach((value, index) => {
|
|
59
|
+
if (value < UINT_128_MIN || value > UINT_128_MAX) {
|
|
60
|
+
throw Error(`limb${index} is not in the range of a u128 number`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if BigNumberish can be represented as Uint512
|
|
67
|
+
*/
|
|
68
|
+
static is(bigNumberish) {
|
|
69
|
+
try {
|
|
70
|
+
CairoUint512.validate(bigNumberish);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if provided abi type is this data type
|
|
78
|
+
*/
|
|
79
|
+
static isAbiType(abiType) {
|
|
80
|
+
return abiType === CairoUint512.abiSelector;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Return bigint representation
|
|
84
|
+
*/
|
|
85
|
+
toBigInt() {
|
|
86
|
+
return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Return Uint512 structure with HexString props
|
|
90
|
+
* limbx: HexString
|
|
91
|
+
*/
|
|
92
|
+
toUint512HexString() {
|
|
93
|
+
return {
|
|
94
|
+
limb0: addHexPrefix(this.limb0.toString(16)),
|
|
95
|
+
limb1: addHexPrefix(this.limb1.toString(16)),
|
|
96
|
+
limb2: addHexPrefix(this.limb2.toString(16)),
|
|
97
|
+
limb3: addHexPrefix(this.limb3.toString(16))
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Return Uint512 structure with DecimalString props
|
|
102
|
+
* limbx DecString
|
|
103
|
+
*/
|
|
104
|
+
toUint512DecimalString() {
|
|
105
|
+
return {
|
|
106
|
+
limb0: this.limb0.toString(10),
|
|
107
|
+
limb1: this.limb1.toString(10),
|
|
108
|
+
limb2: this.limb2.toString(10),
|
|
109
|
+
limb3: this.limb3.toString(10)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Return api requests representation witch is felt array
|
|
114
|
+
*/
|
|
115
|
+
toApiRequest() {
|
|
116
|
+
return [
|
|
117
|
+
CairoFelt(this.limb0),
|
|
118
|
+
CairoFelt(this.limb1),
|
|
119
|
+
CairoFelt(this.limb2),
|
|
120
|
+
CairoFelt(this.limb3)
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.byteArrayFromString = byteArrayFromString;
|
|
7
|
+
exports.stringFromByteArray = stringFromByteArray;
|
|
8
|
+
var _num = require("../num.cjs");
|
|
9
|
+
var _shortString = require("../shortString.cjs");
|
|
10
|
+
function stringFromByteArray(myByteArray) {
|
|
11
|
+
const pending_word = BigInt(myByteArray.pending_word) === 0n ? "" : (0, _shortString.decodeShortString)((0, _num.toHex)(myByteArray.pending_word));
|
|
12
|
+
return myByteArray.data.reduce((cumuledString, encodedString) => {
|
|
13
|
+
const add = BigInt(encodedString) === 0n ? "" : (0, _shortString.decodeShortString)((0, _num.toHex)(encodedString));
|
|
14
|
+
return cumuledString + add;
|
|
15
|
+
}, "") + pending_word;
|
|
16
|
+
}
|
|
17
|
+
function byteArrayFromString(targetString) {
|
|
18
|
+
const shortStrings = (0, _shortString.splitLongString)(targetString);
|
|
19
|
+
const remainder = shortStrings[shortStrings.length - 1];
|
|
20
|
+
const shortStringsEncoded = shortStrings.map(_shortString.encodeShortString);
|
|
21
|
+
const [pendingWord, pendingWordLength] = remainder === void 0 || remainder.length === 31 ? ["0x00", 0] : [shortStringsEncoded.pop(), remainder.length];
|
|
22
|
+
return {
|
|
23
|
+
data: shortStringsEncoded.length === 0 ? [] : shortStringsEncoded,
|
|
24
|
+
pending_word: pendingWord,
|
|
25
|
+
pending_word_len: pendingWordLength
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ByteArray } from '../../types/lib';
|
|
2
|
+
/**
|
|
3
|
+
* convert a Cairo ByteArray to a JS string
|
|
4
|
+
* @param myByteArray Cairo representation of a LongString
|
|
5
|
+
* @returns a JS string
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const myByteArray = {
|
|
9
|
+
* data: [],
|
|
10
|
+
* pending_word: '0x414243444546474849',
|
|
11
|
+
* pending_word_len: 9
|
|
12
|
+
* }
|
|
13
|
+
* const result: String = stringFromByteArray(myByteArray); // ABCDEFGHI
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function stringFromByteArray(myByteArray: ByteArray): string;
|
|
17
|
+
/**
|
|
18
|
+
* convert a JS string to a Cairo ByteArray
|
|
19
|
+
* @param targetString a JS string
|
|
20
|
+
* @returns Cairo representation of a LongString
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const myByteArray: ByteArray = byteArrayFromString("ABCDEFGHI");
|
|
24
|
+
* ```
|
|
25
|
+
* Result is :
|
|
26
|
+
* {
|
|
27
|
+
* data: [],
|
|
28
|
+
* pending_word: '0x414243444546474849',
|
|
29
|
+
* pending_word_len: 9
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
export declare function byteArrayFromString(targetString: string): ByteArray;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { toHex } from "../num.mjs";
|
|
2
|
+
import { decodeShortString, encodeShortString, splitLongString } from "../shortString.mjs";
|
|
3
|
+
export function stringFromByteArray(myByteArray) {
|
|
4
|
+
const pending_word = BigInt(myByteArray.pending_word) === 0n ? "" : decodeShortString(toHex(myByteArray.pending_word));
|
|
5
|
+
return myByteArray.data.reduce((cumuledString, encodedString) => {
|
|
6
|
+
const add = BigInt(encodedString) === 0n ? "" : decodeShortString(toHex(encodedString));
|
|
7
|
+
return cumuledString + add;
|
|
8
|
+
}, "") + pending_word;
|
|
9
|
+
}
|
|
10
|
+
export function byteArrayFromString(targetString) {
|
|
11
|
+
const shortStrings = splitLongString(targetString);
|
|
12
|
+
const remainder = shortStrings[shortStrings.length - 1];
|
|
13
|
+
const shortStringsEncoded = shortStrings.map(encodeShortString);
|
|
14
|
+
const [pendingWord, pendingWordLength] = remainder === void 0 || remainder.length === 31 ? ["0x00", 0] : [shortStringsEncoded.pop(), remainder.length];
|
|
15
|
+
return {
|
|
16
|
+
data: shortStringsEncoded.length === 0 ? [] : shortStringsEncoded,
|
|
17
|
+
pending_word: pendingWord,
|
|
18
|
+
pending_word_len: pendingWordLength
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.felt = felt;
|
|
7
|
+
exports.getAbiContractVersion = getAbiContractVersion;
|
|
8
|
+
exports.getArrayType = void 0;
|
|
9
|
+
exports.isCairo1Abi = isCairo1Abi;
|
|
10
|
+
exports.isTypeNamedTuple = exports.isTypeLiteral = exports.isTypeFelt = exports.isTypeEthAddress = exports.isTypeEnum = exports.isTypeContractAddress = exports.isTypeBytes31 = exports.isTypeByteArray = exports.isTypeBool = exports.isTypeArray = exports.isLen = exports.isCairo1Type = void 0;
|
|
11
|
+
exports.isTypeNonZero = isTypeNonZero;
|
|
12
|
+
exports.uint512 = exports.uint256 = exports.tuple = exports.isTypeUint256 = exports.isTypeUint = exports.isTypeTuple = exports.isTypeStruct = exports.isTypeSecp256k1Point = exports.isTypeResult = exports.isTypeOption = void 0;
|
|
13
|
+
var _types = require("../../types/index.cjs");
|
|
14
|
+
var _felt = require("../cairoDataTypes/felt.cjs");
|
|
15
|
+
var _uint = require("../cairoDataTypes/uint256.cjs");
|
|
16
|
+
var _uint2 = require("../cairoDataTypes/uint512.cjs");
|
|
17
|
+
const isLen = name => /_len$/.test(name);
|
|
18
|
+
exports.isLen = isLen;
|
|
19
|
+
const isTypeFelt = type => type === "felt" || type === "core::felt252";
|
|
20
|
+
exports.isTypeFelt = isTypeFelt;
|
|
21
|
+
const isTypeArray = type => /\*/.test(type) || type.startsWith("core::array::Array::") || type.startsWith("core::array::Span::");
|
|
22
|
+
exports.isTypeArray = isTypeArray;
|
|
23
|
+
const isTypeTuple = type => /^\(.*\)$/i.test(type);
|
|
24
|
+
exports.isTypeTuple = isTypeTuple;
|
|
25
|
+
const isTypeNamedTuple = type => /\(.*\)/i.test(type) && type.includes(":");
|
|
26
|
+
exports.isTypeNamedTuple = isTypeNamedTuple;
|
|
27
|
+
const isTypeStruct = (type, structs) => type in structs;
|
|
28
|
+
exports.isTypeStruct = isTypeStruct;
|
|
29
|
+
const isTypeEnum = (type, enums) => type in enums;
|
|
30
|
+
exports.isTypeEnum = isTypeEnum;
|
|
31
|
+
const isTypeOption = type => type.startsWith("core::option::Option::");
|
|
32
|
+
exports.isTypeOption = isTypeOption;
|
|
33
|
+
const isTypeResult = type => type.startsWith("core::result::Result::");
|
|
34
|
+
exports.isTypeResult = isTypeResult;
|
|
35
|
+
const isTypeUint = type => Object.values(_types.Uint).includes(type);
|
|
36
|
+
exports.isTypeUint = isTypeUint;
|
|
37
|
+
const isTypeUint256 = type => _uint.CairoUint256.isAbiType(type);
|
|
38
|
+
exports.isTypeUint256 = isTypeUint256;
|
|
39
|
+
const isTypeLiteral = type => Object.values(_types.Literal).includes(type);
|
|
40
|
+
exports.isTypeLiteral = isTypeLiteral;
|
|
41
|
+
const isTypeBool = type => type === "core::bool";
|
|
42
|
+
exports.isTypeBool = isTypeBool;
|
|
43
|
+
const isTypeContractAddress = type => type === "core::starknet::contract_address::ContractAddress";
|
|
44
|
+
exports.isTypeContractAddress = isTypeContractAddress;
|
|
45
|
+
const isTypeEthAddress = type => type === "core::starknet::eth_address::EthAddress";
|
|
46
|
+
exports.isTypeEthAddress = isTypeEthAddress;
|
|
47
|
+
const isTypeBytes31 = type => type === "core::bytes_31::bytes31";
|
|
48
|
+
exports.isTypeBytes31 = isTypeBytes31;
|
|
49
|
+
const isTypeByteArray = type => type === "core::byte_array::ByteArray";
|
|
50
|
+
exports.isTypeByteArray = isTypeByteArray;
|
|
51
|
+
const isTypeSecp256k1Point = type => type === "core::starknet::secp256k1::Secp256k1Point";
|
|
52
|
+
exports.isTypeSecp256k1Point = isTypeSecp256k1Point;
|
|
53
|
+
const isCairo1Type = type => type.includes("::");
|
|
54
|
+
exports.isCairo1Type = isCairo1Type;
|
|
55
|
+
const getArrayType = type => {
|
|
56
|
+
if (isCairo1Type(type)) {
|
|
57
|
+
return type.substring(type.indexOf("<") + 1, type.lastIndexOf(">"));
|
|
58
|
+
}
|
|
59
|
+
return type.replace("*", "");
|
|
60
|
+
};
|
|
61
|
+
exports.getArrayType = getArrayType;
|
|
62
|
+
function isCairo1Abi(abi) {
|
|
63
|
+
const {
|
|
64
|
+
cairo
|
|
65
|
+
} = getAbiContractVersion(abi);
|
|
66
|
+
if (cairo === void 0) {
|
|
67
|
+
throw Error("Unable to determine Cairo version");
|
|
68
|
+
}
|
|
69
|
+
return cairo === "1";
|
|
70
|
+
}
|
|
71
|
+
function isTypeNonZero(type) {
|
|
72
|
+
return type.startsWith("core::zeroable::NonZero::");
|
|
73
|
+
}
|
|
74
|
+
function getAbiContractVersion(abi) {
|
|
75
|
+
if (abi.find(it => it.type === "interface")) {
|
|
76
|
+
return {
|
|
77
|
+
cairo: "1",
|
|
78
|
+
compiler: "2"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const testFunction = abi.find(it => it.type === "function" && (it.inputs.length || it.outputs.length));
|
|
82
|
+
if (!testFunction) {
|
|
83
|
+
return {
|
|
84
|
+
cairo: void 0,
|
|
85
|
+
compiler: void 0
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const io = testFunction.inputs.length ? testFunction.inputs : testFunction.outputs;
|
|
89
|
+
if (isCairo1Type(io[0].type)) {
|
|
90
|
+
return {
|
|
91
|
+
cairo: "1",
|
|
92
|
+
compiler: "1"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
cairo: "0",
|
|
97
|
+
compiler: "0"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const uint256 = it => {
|
|
101
|
+
return new _uint.CairoUint256(it).toUint256DecimalString();
|
|
102
|
+
};
|
|
103
|
+
exports.uint256 = uint256;
|
|
104
|
+
const uint512 = it => {
|
|
105
|
+
return new _uint2.CairoUint512(it).toUint512DecimalString();
|
|
106
|
+
};
|
|
107
|
+
exports.uint512 = uint512;
|
|
108
|
+
const tuple = (...args) => ({
|
|
109
|
+
...args
|
|
110
|
+
});
|
|
111
|
+
exports.tuple = tuple;
|
|
112
|
+
function felt(it) {
|
|
113
|
+
return (0, _felt.CairoFelt)(it);
|
|
114
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Abi, AbiEnums, AbiStructs, BigNumberish, ContractVersion, Uint256, Uint512 } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given name ends with "_len".
|
|
4
|
+
*
|
|
5
|
+
* @param {string} name - The name to be checked.
|
|
6
|
+
* @returns - True if the name ends with "_len", false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isLen: (name: string) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a given type is felt.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} type - The type to check.
|
|
13
|
+
* @returns - True if the type is felt, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare const isTypeFelt: (type: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the given type is an array type.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} type - The type to check.
|
|
20
|
+
* @returns - `true` if the type is an array type, `false` otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export declare const isTypeArray: (type: string) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given type is a tuple type.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} type - The type to be checked.
|
|
27
|
+
* @returns - `true` if the type is a tuple type, otherwise `false`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const isTypeTuple: (type: string) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether a given type is a named tuple.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} type - The type to be checked.
|
|
34
|
+
* @returns - True if the type is a named tuple, false otherwise.
|
|
35
|
+
*/
|
|
36
|
+
export declare const isTypeNamedTuple: (type: string) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a given type is a struct.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} type - The type to check for existence.
|
|
41
|
+
* @param {AbiStructs} structs - The collection of structs to search in.
|
|
42
|
+
* @returns - True if the type exists in the structs, false otherwise.
|
|
43
|
+
*/
|
|
44
|
+
export declare const isTypeStruct: (type: string, structs: AbiStructs) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a given type is an enum.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} type - The type to check.
|
|
49
|
+
* @param {AbiEnums} enums - The enumeration to search in.
|
|
50
|
+
* @returns - True if the type exists in the enumeration, otherwise false.
|
|
51
|
+
*/
|
|
52
|
+
export declare const isTypeEnum: (type: string, enums: AbiEnums) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Determines if the given type is an Option type.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} type - The type to check.
|
|
57
|
+
* @returns - True if the type is an Option type, false otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export declare const isTypeOption: (type: string) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Checks whether a given type starts with 'core::result::Result::'.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} type - The type to check.
|
|
64
|
+
* @returns - True if the type starts with 'core::result::Result::', false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
export declare const isTypeResult: (type: string) => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the given value is a valid Uint type.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} type - The value to check.
|
|
71
|
+
* @returns - Returns true if the value is a valid Uint type, otherwise false.
|
|
72
|
+
*/
|
|
73
|
+
export declare const isTypeUint: (type: string) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the given type is `uint256`.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} type - The type to be checked.
|
|
78
|
+
* @returns - Returns true if the type is `uint256`, otherwise false.
|
|
79
|
+
*/
|
|
80
|
+
export declare const isTypeUint256: (type: string) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if the given type is a literal type.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} type - The type to check.
|
|
85
|
+
* @returns - True if the type is a literal type, false otherwise.
|
|
86
|
+
*/
|
|
87
|
+
export declare const isTypeLiteral: (type: string) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the given type is a boolean type.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} type - The type to be checked.
|
|
92
|
+
* @returns - Returns true if the type is a boolean type, otherwise false.
|
|
93
|
+
*/
|
|
94
|
+
export declare const isTypeBool: (type: string) => boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Checks if the provided type is equal to 'core::starknet::contract_address::ContractAddress'.
|
|
97
|
+
* @param {string} type - The type to be checked.
|
|
98
|
+
* @returns - true if the type matches 'core::starknet::contract_address::ContractAddress', false otherwise.
|
|
99
|
+
*/
|
|
100
|
+
export declare const isTypeContractAddress: (type: string) => boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Determines if the given type is an Ethereum address type.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} type - The type to check.
|
|
105
|
+
* @returns - Returns true if the given type is 'core::starknet::eth_address::EthAddress', otherwise false.
|
|
106
|
+
*/
|
|
107
|
+
export declare const isTypeEthAddress: (type: string) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Checks if the given type is 'core::bytes_31::bytes31'.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} type - The type to check.
|
|
112
|
+
* @returns - True if the type is 'core::bytes_31::bytes31', false otherwise.
|
|
113
|
+
*/
|
|
114
|
+
export declare const isTypeBytes31: (type: string) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the given type is equal to the 'core::byte_array::ByteArray'.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} type - The type to check.
|
|
119
|
+
* @returns - True if the given type is equal to 'core::byte_array::ByteArray', false otherwise.
|
|
120
|
+
*/
|
|
121
|
+
export declare const isTypeByteArray: (type: string) => boolean;
|
|
122
|
+
export declare const isTypeSecp256k1Point: (type: string) => boolean;
|
|
123
|
+
export declare const isCairo1Type: (type: string) => boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves the array type from the given type string.
|
|
126
|
+
*
|
|
127
|
+
* Works also for core::zeroable::NonZero type.
|
|
128
|
+
* @param {string} type - The type string.
|
|
129
|
+
* @returns - The array type.
|
|
130
|
+
*/
|
|
131
|
+
export declare const getArrayType: (type: string) => string;
|
|
132
|
+
/**
|
|
133
|
+
* Test if an ABI comes from a Cairo 1 contract
|
|
134
|
+
* @param abi representing the interface of a Cairo contract
|
|
135
|
+
* @returns TRUE if it is an ABI from a Cairo1 contract
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const isCairo1: boolean = isCairo1Abi(myAbi: Abi);
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare function isCairo1Abi(abi: Abi): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Checks if the given type is a NonZero type.
|
|
144
|
+
*
|
|
145
|
+
* @param {string} type The type to check.
|
|
146
|
+
* @returns `true` if the type is NonZero type, `false` otherwise.
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const result = cairo.isTypeNonZero("core::zeroable::NonZero::<u8>");
|
|
150
|
+
* //result = true
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function isTypeNonZero(type: string): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Return ContractVersion (Abi version) based on Abi
|
|
156
|
+
* or undefined for unknown version
|
|
157
|
+
* @param abi
|
|
158
|
+
* @returns string
|
|
159
|
+
*/
|
|
160
|
+
export declare function getAbiContractVersion(abi: Abi): ContractVersion;
|
|
161
|
+
/**
|
|
162
|
+
* named tuple cairo type is described as js object {}
|
|
163
|
+
* struct cairo type are described as js object {}
|
|
164
|
+
* array cairo type are described as js array []
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* Create Uint256 Cairo type (helper for common struct type)
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* uint256('892349863487563453485768723498');
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare const uint256: (it: BigNumberish) => Uint256;
|
|
174
|
+
/**
|
|
175
|
+
* Create Uint512 Cairo type (helper for common struct type)
|
|
176
|
+
* @param it BigNumberish representation of a 512 bits unsigned number
|
|
177
|
+
* @returns Uint512 struct
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* uint512('345745685892349863487563453485768723498');
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare const uint512: (it: BigNumberish) => Uint512;
|
|
184
|
+
/**
|
|
185
|
+
* Create unnamed tuple Cairo type (helper same as common struct type)
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* tuple(1, '0x101', 16);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare const tuple: (...args: (BigNumberish | object | boolean)[]) => Record<number, BigNumberish | object | boolean>;
|
|
192
|
+
/**
|
|
193
|
+
* Create felt Cairo type (cairo type helper)
|
|
194
|
+
* @returns format: felt-string
|
|
195
|
+
*/
|
|
196
|
+
export declare function felt(it: BigNumberish): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Literal,
|
|
3
|
+
Uint
|
|
4
|
+
} from "../../types/index.mjs";
|
|
5
|
+
import { CairoFelt } from "../cairoDataTypes/felt.mjs";
|
|
6
|
+
import { CairoUint256 } from "../cairoDataTypes/uint256.mjs";
|
|
7
|
+
import { CairoUint512 } from "../cairoDataTypes/uint512.mjs";
|
|
8
|
+
export const isLen = (name) => /_len$/.test(name);
|
|
9
|
+
export const isTypeFelt = (type) => type === "felt" || type === "core::felt252";
|
|
10
|
+
export const isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::") || type.startsWith("core::array::Span::");
|
|
11
|
+
export const isTypeTuple = (type) => /^\(.*\)$/i.test(type);
|
|
12
|
+
export const isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
|
|
13
|
+
export const isTypeStruct = (type, structs) => type in structs;
|
|
14
|
+
export const isTypeEnum = (type, enums) => type in enums;
|
|
15
|
+
export const isTypeOption = (type) => type.startsWith("core::option::Option::");
|
|
16
|
+
export const isTypeResult = (type) => type.startsWith("core::result::Result::");
|
|
17
|
+
export const isTypeUint = (type) => Object.values(Uint).includes(type);
|
|
18
|
+
export const isTypeUint256 = (type) => CairoUint256.isAbiType(type);
|
|
19
|
+
export const isTypeLiteral = (type) => Object.values(Literal).includes(type);
|
|
20
|
+
export const isTypeBool = (type) => type === "core::bool";
|
|
21
|
+
export const isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
|
|
22
|
+
export const isTypeEthAddress = (type) => type === "core::starknet::eth_address::EthAddress";
|
|
23
|
+
export const isTypeBytes31 = (type) => type === "core::bytes_31::bytes31";
|
|
24
|
+
export const isTypeByteArray = (type) => type === "core::byte_array::ByteArray";
|
|
25
|
+
export const isTypeSecp256k1Point = (type) => type === "core::starknet::secp256k1::Secp256k1Point";
|
|
26
|
+
export const isCairo1Type = (type) => type.includes("::");
|
|
27
|
+
export const getArrayType = (type) => {
|
|
28
|
+
if (isCairo1Type(type)) {
|
|
29
|
+
return type.substring(type.indexOf("<") + 1, type.lastIndexOf(">"));
|
|
30
|
+
}
|
|
31
|
+
return type.replace("*", "");
|
|
32
|
+
};
|
|
33
|
+
export function isCairo1Abi(abi) {
|
|
34
|
+
const { cairo } = getAbiContractVersion(abi);
|
|
35
|
+
if (cairo === void 0) {
|
|
36
|
+
throw Error("Unable to determine Cairo version");
|
|
37
|
+
}
|
|
38
|
+
return cairo === "1";
|
|
39
|
+
}
|
|
40
|
+
export function isTypeNonZero(type) {
|
|
41
|
+
return type.startsWith("core::zeroable::NonZero::");
|
|
42
|
+
}
|
|
43
|
+
export function getAbiContractVersion(abi) {
|
|
44
|
+
if (abi.find((it) => it.type === "interface")) {
|
|
45
|
+
return { cairo: "1", compiler: "2" };
|
|
46
|
+
}
|
|
47
|
+
const testFunction = abi.find(
|
|
48
|
+
(it) => it.type === "function" && (it.inputs.length || it.outputs.length)
|
|
49
|
+
);
|
|
50
|
+
if (!testFunction) {
|
|
51
|
+
return { cairo: void 0, compiler: void 0 };
|
|
52
|
+
}
|
|
53
|
+
const io = testFunction.inputs.length ? testFunction.inputs : testFunction.outputs;
|
|
54
|
+
if (isCairo1Type(io[0].type)) {
|
|
55
|
+
return { cairo: "1", compiler: "1" };
|
|
56
|
+
}
|
|
57
|
+
return { cairo: "0", compiler: "0" };
|
|
58
|
+
}
|
|
59
|
+
export const uint256 = (it) => {
|
|
60
|
+
return new CairoUint256(it).toUint256DecimalString();
|
|
61
|
+
};
|
|
62
|
+
export const uint512 = (it) => {
|
|
63
|
+
return new CairoUint512(it).toUint512DecimalString();
|
|
64
|
+
};
|
|
65
|
+
export const tuple = (...args) => ({ ...args });
|
|
66
|
+
export function felt(it) {
|
|
67
|
+
return CairoFelt(it);
|
|
68
|
+
}
|