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,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CairoCustomEnum = void 0;
|
|
7
|
+
class CairoCustomEnum {
|
|
8
|
+
/**
|
|
9
|
+
* direct readonly access to variants of the Cairo Custom Enum.
|
|
10
|
+
* @returns a value of type any
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const successValue = myCairoEnum.variant.Success;
|
|
14
|
+
*/
|
|
15
|
+
variant;
|
|
16
|
+
/**
|
|
17
|
+
* @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
|
|
18
|
+
*/
|
|
19
|
+
constructor(enumContent) {
|
|
20
|
+
const variantsList = Object.values(enumContent);
|
|
21
|
+
if (variantsList.length === 0) {
|
|
22
|
+
throw new Error("This Enum must have at least 1 variant");
|
|
23
|
+
}
|
|
24
|
+
const nbActiveVariants = variantsList.filter(content => typeof content !== "undefined").length;
|
|
25
|
+
if (nbActiveVariants !== 1) {
|
|
26
|
+
throw new Error("This Enum must have exactly one active variant");
|
|
27
|
+
}
|
|
28
|
+
this.variant = enumContent;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @returns the content of the valid variant of a Cairo custom Enum.
|
|
33
|
+
*/
|
|
34
|
+
unwrap() {
|
|
35
|
+
const variants = Object.entries(this.variant);
|
|
36
|
+
const activeVariant = variants.find(item => typeof item[1] !== "undefined");
|
|
37
|
+
if (typeof activeVariant === "undefined") {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
return activeVariant[1];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @returns the name of the valid variant of a Cairo custom Enum.
|
|
45
|
+
*/
|
|
46
|
+
activeVariant() {
|
|
47
|
+
const variants = Object.entries(this.variant);
|
|
48
|
+
const activeVariant = variants.find(item => typeof item[1] !== "undefined");
|
|
49
|
+
if (typeof activeVariant === "undefined") {
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
return activeVariant[0];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.CairoCustomEnum = CairoCustomEnum;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type CairoEnumRaw = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Class to handle Cairo custom Enum
|
|
6
|
+
* @param enumContent object containing the variants and its content. Example :
|
|
7
|
+
* {Success: 234, Warning: undefined, Error: undefined}.
|
|
8
|
+
* Only one variant with a value, object, array.
|
|
9
|
+
* @returns an instance representing a Cairo custom Enum.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const myCairoEnum = new CairoCustomEnum( {Success: undefined, Warning: "0x7f32ea", Error: undefined})
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class CairoCustomEnum {
|
|
16
|
+
/**
|
|
17
|
+
* direct readonly access to variants of the Cairo Custom Enum.
|
|
18
|
+
* @returns a value of type any
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const successValue = myCairoEnum.variant.Success;
|
|
22
|
+
*/
|
|
23
|
+
readonly variant: CairoEnumRaw;
|
|
24
|
+
/**
|
|
25
|
+
* @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
|
|
26
|
+
*/
|
|
27
|
+
constructor(enumContent: CairoEnumRaw);
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @returns the content of the valid variant of a Cairo custom Enum.
|
|
31
|
+
*/
|
|
32
|
+
unwrap(): any;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @returns the name of the valid variant of a Cairo custom Enum.
|
|
36
|
+
*/
|
|
37
|
+
activeVariant(): string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class CairoCustomEnum {
|
|
2
|
+
/**
|
|
3
|
+
* direct readonly access to variants of the Cairo Custom Enum.
|
|
4
|
+
* @returns a value of type any
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const successValue = myCairoEnum.variant.Success;
|
|
8
|
+
*/
|
|
9
|
+
variant;
|
|
10
|
+
/**
|
|
11
|
+
* @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
|
|
12
|
+
*/
|
|
13
|
+
constructor(enumContent) {
|
|
14
|
+
const variantsList = Object.values(enumContent);
|
|
15
|
+
if (variantsList.length === 0) {
|
|
16
|
+
throw new Error("This Enum must have at least 1 variant");
|
|
17
|
+
}
|
|
18
|
+
const nbActiveVariants = variantsList.filter(
|
|
19
|
+
(content) => typeof content !== "undefined"
|
|
20
|
+
).length;
|
|
21
|
+
if (nbActiveVariants !== 1) {
|
|
22
|
+
throw new Error("This Enum must have exactly one active variant");
|
|
23
|
+
}
|
|
24
|
+
this.variant = enumContent;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @returns the content of the valid variant of a Cairo custom Enum.
|
|
29
|
+
*/
|
|
30
|
+
unwrap() {
|
|
31
|
+
const variants = Object.entries(this.variant);
|
|
32
|
+
const activeVariant = variants.find((item) => typeof item[1] !== "undefined");
|
|
33
|
+
if (typeof activeVariant === "undefined") {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
return activeVariant[1];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @returns the name of the valid variant of a Cairo custom Enum.
|
|
41
|
+
*/
|
|
42
|
+
activeVariant() {
|
|
43
|
+
const variants = Object.entries(this.variant);
|
|
44
|
+
const activeVariant = variants.find((item) => typeof item[1] !== "undefined");
|
|
45
|
+
if (typeof activeVariant === "undefined") {
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
return activeVariant[0];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CairoOptionVariant = exports.CairoOption = void 0;
|
|
7
|
+
const CairoOptionVariant = exports.CairoOptionVariant = {
|
|
8
|
+
Some: 0,
|
|
9
|
+
None: 1
|
|
10
|
+
};
|
|
11
|
+
class CairoOption {
|
|
12
|
+
Some;
|
|
13
|
+
None;
|
|
14
|
+
constructor(variant, someContent) {
|
|
15
|
+
if (!(variant in Object.values(CairoOptionVariant))) {
|
|
16
|
+
throw new Error("Wrong variant : should be CairoOptionVariant.Some or .None.");
|
|
17
|
+
}
|
|
18
|
+
if (variant === CairoOptionVariant.Some) {
|
|
19
|
+
if (typeof someContent === "undefined") {
|
|
20
|
+
throw new Error('The creation of a Cairo Option with "Some" variant needs a content as input.');
|
|
21
|
+
}
|
|
22
|
+
this.Some = someContent;
|
|
23
|
+
this.None = void 0;
|
|
24
|
+
} else {
|
|
25
|
+
this.Some = void 0;
|
|
26
|
+
this.None = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @returns the content of the valid variant of a Cairo custom Enum.
|
|
32
|
+
* If None, returns 'undefined'.
|
|
33
|
+
*/
|
|
34
|
+
unwrap() {
|
|
35
|
+
if (this.None) {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
return this.Some;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @returns true if the valid variant is 'isSome'.
|
|
43
|
+
*/
|
|
44
|
+
isSome() {
|
|
45
|
+
return !(typeof this.Some === "undefined");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @returns true if the valid variant is 'isNone'.
|
|
50
|
+
*/
|
|
51
|
+
isNone() {
|
|
52
|
+
return this.None === true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.CairoOption = CairoOption;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ValuesType } from '../../../types/helpers/valuesType';
|
|
2
|
+
export declare const CairoOptionVariant: {
|
|
3
|
+
readonly Some: 0;
|
|
4
|
+
readonly None: 1;
|
|
5
|
+
};
|
|
6
|
+
export type CairoOptionVariant = ValuesType<typeof CairoOptionVariant>;
|
|
7
|
+
/**
|
|
8
|
+
* Class to handle Cairo Option
|
|
9
|
+
* @param variant CairoOptionVariant.Some or CairoOptionVariant.None
|
|
10
|
+
* @param someContent value of type T.
|
|
11
|
+
* @returns an instance representing a Cairo Option.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const myOption = new CairoOption<BigNumberish>(CairoOptionVariant.Some, "0x54dda8");
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class CairoOption<T> {
|
|
18
|
+
readonly Some?: T;
|
|
19
|
+
readonly None?: boolean;
|
|
20
|
+
constructor(variant: CairoOptionVariant | number, someContent?: T);
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @returns the content of the valid variant of a Cairo custom Enum.
|
|
24
|
+
* If None, returns 'undefined'.
|
|
25
|
+
*/
|
|
26
|
+
unwrap(): T | undefined;
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @returns true if the valid variant is 'isSome'.
|
|
30
|
+
*/
|
|
31
|
+
isSome(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @returns true if the valid variant is 'isNone'.
|
|
35
|
+
*/
|
|
36
|
+
isNone(): boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const CairoOptionVariant = {
|
|
2
|
+
Some: 0,
|
|
3
|
+
None: 1
|
|
4
|
+
};
|
|
5
|
+
export class CairoOption {
|
|
6
|
+
Some;
|
|
7
|
+
None;
|
|
8
|
+
constructor(variant, someContent) {
|
|
9
|
+
if (!(variant in Object.values(CairoOptionVariant))) {
|
|
10
|
+
throw new Error("Wrong variant : should be CairoOptionVariant.Some or .None.");
|
|
11
|
+
}
|
|
12
|
+
if (variant === CairoOptionVariant.Some) {
|
|
13
|
+
if (typeof someContent === "undefined") {
|
|
14
|
+
throw new Error(
|
|
15
|
+
'The creation of a Cairo Option with "Some" variant needs a content as input.'
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
this.Some = someContent;
|
|
19
|
+
this.None = void 0;
|
|
20
|
+
} else {
|
|
21
|
+
this.Some = void 0;
|
|
22
|
+
this.None = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns the content of the valid variant of a Cairo custom Enum.
|
|
28
|
+
* If None, returns 'undefined'.
|
|
29
|
+
*/
|
|
30
|
+
unwrap() {
|
|
31
|
+
if (this.None) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
return this.Some;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @returns true if the valid variant is 'isSome'.
|
|
39
|
+
*/
|
|
40
|
+
isSome() {
|
|
41
|
+
return !(typeof this.Some === "undefined");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @returns true if the valid variant is 'isNone'.
|
|
46
|
+
*/
|
|
47
|
+
isNone() {
|
|
48
|
+
return this.None === true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CairoResultVariant = exports.CairoResult = void 0;
|
|
7
|
+
const CairoResultVariant = exports.CairoResultVariant = {
|
|
8
|
+
Ok: 0,
|
|
9
|
+
Err: 1
|
|
10
|
+
};
|
|
11
|
+
class CairoResult {
|
|
12
|
+
Ok;
|
|
13
|
+
Err;
|
|
14
|
+
constructor(variant, resultContent) {
|
|
15
|
+
if (!(variant in Object.values(CairoResultVariant))) {
|
|
16
|
+
throw new Error("Wrong variant : should be CairoResultVariant.Ok or .Err.");
|
|
17
|
+
}
|
|
18
|
+
if (variant === CairoResultVariant.Ok) {
|
|
19
|
+
this.Ok = resultContent;
|
|
20
|
+
this.Err = void 0;
|
|
21
|
+
} else {
|
|
22
|
+
this.Ok = void 0;
|
|
23
|
+
this.Err = resultContent;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @returns the content of the valid variant of a Cairo Result.
|
|
29
|
+
*/
|
|
30
|
+
unwrap() {
|
|
31
|
+
if (typeof this.Ok !== "undefined") {
|
|
32
|
+
return this.Ok;
|
|
33
|
+
}
|
|
34
|
+
if (typeof this.Err !== "undefined") {
|
|
35
|
+
return this.Err;
|
|
36
|
+
}
|
|
37
|
+
throw new Error("Both Result.Ok and .Err are undefined. Not authorized.");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @returns true if the valid variant is 'Ok'.
|
|
42
|
+
*/
|
|
43
|
+
isOk() {
|
|
44
|
+
return !(typeof this.Ok === "undefined");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @returns true if the valid variant is 'isErr'.
|
|
49
|
+
*/
|
|
50
|
+
isErr() {
|
|
51
|
+
return !(typeof this.Err === "undefined");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.CairoResult = CairoResult;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ValuesType } from '../../../types/helpers/valuesType';
|
|
2
|
+
export declare const CairoResultVariant: {
|
|
3
|
+
readonly Ok: 0;
|
|
4
|
+
readonly Err: 1;
|
|
5
|
+
};
|
|
6
|
+
export type CairoResultVariant = ValuesType<typeof CairoResultVariant>;
|
|
7
|
+
/**
|
|
8
|
+
* Class to handle Cairo Result
|
|
9
|
+
* @param variant CairoResultVariant.Ok or CairoResultVariant.Err
|
|
10
|
+
* @param resultContent value of type T or U.
|
|
11
|
+
* @returns an instance representing a Cairo Result.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const myOption = new CairoResult<BigNumberish, CustomError>(CairoResultVariant.Ok, "0x54dda8");
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class CairoResult<T, U> {
|
|
18
|
+
readonly Ok?: T;
|
|
19
|
+
readonly Err?: U;
|
|
20
|
+
constructor(variant: CairoResultVariant | number, resultContent: T | U);
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @returns the content of the valid variant of a Cairo Result.
|
|
24
|
+
*/
|
|
25
|
+
unwrap(): T | U;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @returns true if the valid variant is 'Ok'.
|
|
29
|
+
*/
|
|
30
|
+
isOk(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @returns true if the valid variant is 'isErr'.
|
|
34
|
+
*/
|
|
35
|
+
isErr(): boolean;
|
|
36
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const CairoResultVariant = {
|
|
2
|
+
Ok: 0,
|
|
3
|
+
Err: 1
|
|
4
|
+
};
|
|
5
|
+
export class CairoResult {
|
|
6
|
+
Ok;
|
|
7
|
+
Err;
|
|
8
|
+
constructor(variant, resultContent) {
|
|
9
|
+
if (!(variant in Object.values(CairoResultVariant))) {
|
|
10
|
+
throw new Error("Wrong variant : should be CairoResultVariant.Ok or .Err.");
|
|
11
|
+
}
|
|
12
|
+
if (variant === CairoResultVariant.Ok) {
|
|
13
|
+
this.Ok = resultContent;
|
|
14
|
+
this.Err = void 0;
|
|
15
|
+
} else {
|
|
16
|
+
this.Ok = void 0;
|
|
17
|
+
this.Err = resultContent;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @returns the content of the valid variant of a Cairo Result.
|
|
23
|
+
*/
|
|
24
|
+
unwrap() {
|
|
25
|
+
if (typeof this.Ok !== "undefined") {
|
|
26
|
+
return this.Ok;
|
|
27
|
+
}
|
|
28
|
+
if (typeof this.Err !== "undefined") {
|
|
29
|
+
return this.Err;
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Both Result.Ok and .Err are undefined. Not authorized.");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @returns true if the valid variant is 'Ok'.
|
|
36
|
+
*/
|
|
37
|
+
isOk() {
|
|
38
|
+
return !(typeof this.Ok === "undefined");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @returns true if the valid variant is 'isErr'.
|
|
43
|
+
*/
|
|
44
|
+
isErr() {
|
|
45
|
+
return !(typeof this.Err === "undefined");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _CairoCustomEnum = require("./CairoCustomEnum.cjs");
|
|
7
|
+
Object.keys(_CairoCustomEnum).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _CairoCustomEnum[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _CairoCustomEnum[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _CairoOption = require("./CairoOption.cjs");
|
|
18
|
+
Object.keys(_CairoOption).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _CairoOption[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _CairoOption[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _CairoResult = require("./CairoResult.cjs");
|
|
29
|
+
Object.keys(_CairoResult).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _CairoResult[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _CairoResult[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = formatter;
|
|
7
|
+
var _num = require("../num.cjs");
|
|
8
|
+
var _shortString = require("../shortString.cjs");
|
|
9
|
+
const guard = {
|
|
10
|
+
isBN: (data, type, key) => {
|
|
11
|
+
if (!(0, _num.isBigInt)(data[key])) throw new Error(`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`);
|
|
12
|
+
},
|
|
13
|
+
unknown: (data, type, key) => {
|
|
14
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function formatter(data, type, sameType) {
|
|
18
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
19
|
+
const elType = sameType ?? type[key];
|
|
20
|
+
if (!(key in type) && !sameType) {
|
|
21
|
+
acc[key] = value;
|
|
22
|
+
return acc;
|
|
23
|
+
}
|
|
24
|
+
if (elType === "string") {
|
|
25
|
+
if (Array.isArray(data[key])) {
|
|
26
|
+
const arrayStr = formatter(data[key], data[key].map(_ => elType));
|
|
27
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
28
|
+
return acc;
|
|
29
|
+
}
|
|
30
|
+
guard.isBN(data, type, key);
|
|
31
|
+
acc[key] = (0, _shortString.decodeShortString)(value);
|
|
32
|
+
return acc;
|
|
33
|
+
}
|
|
34
|
+
if (elType === "number") {
|
|
35
|
+
guard.isBN(data, type, key);
|
|
36
|
+
acc[key] = Number(value);
|
|
37
|
+
return acc;
|
|
38
|
+
}
|
|
39
|
+
if (typeof elType === "function") {
|
|
40
|
+
acc[key] = elType(value);
|
|
41
|
+
return acc;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(elType)) {
|
|
44
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
45
|
+
acc[key] = Object.values(arrayObj);
|
|
46
|
+
return acc;
|
|
47
|
+
}
|
|
48
|
+
if (typeof elType === "object") {
|
|
49
|
+
acc[key] = formatter(data[key], elType);
|
|
50
|
+
return acc;
|
|
51
|
+
}
|
|
52
|
+
guard.unknown(data, type, key);
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats the given data based on the provided type definition.
|
|
3
|
+
*
|
|
4
|
+
* @param {any} data - The data to be formatted.
|
|
5
|
+
* @param {any} type - The type definition for the data.
|
|
6
|
+
* @param {any} [sameType] - The same type definition to be used (optional).
|
|
7
|
+
* @returns - The formatted data.
|
|
8
|
+
*/
|
|
9
|
+
export default function formatter(data: Record<string, any>, type: Record<string, any>, sameType?: any): Record<string, any>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isBigInt } from "../num.mjs";
|
|
2
|
+
import { decodeShortString } from "../shortString.mjs";
|
|
3
|
+
const guard = {
|
|
4
|
+
isBN: (data, type, key) => {
|
|
5
|
+
if (!isBigInt(data[key]))
|
|
6
|
+
throw new Error(
|
|
7
|
+
`Data and formatter mismatch on ${key}:${type[key]}, expected response data ${key}:${data[key]} to be BN instead it is ${typeof data[key]}`
|
|
8
|
+
);
|
|
9
|
+
},
|
|
10
|
+
unknown: (data, type, key) => {
|
|
11
|
+
throw new Error(`Unhandled formatter type on ${key}:${type[key]} for data ${key}:${data[key]}`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export default function formatter(data, type, sameType) {
|
|
15
|
+
return Object.entries(data).reduce(
|
|
16
|
+
(acc, [key, value]) => {
|
|
17
|
+
const elType = sameType ?? type[key];
|
|
18
|
+
if (!(key in type) && !sameType) {
|
|
19
|
+
acc[key] = value;
|
|
20
|
+
return acc;
|
|
21
|
+
}
|
|
22
|
+
if (elType === "string") {
|
|
23
|
+
if (Array.isArray(data[key])) {
|
|
24
|
+
const arrayStr = formatter(
|
|
25
|
+
data[key],
|
|
26
|
+
data[key].map((_) => elType)
|
|
27
|
+
);
|
|
28
|
+
acc[key] = Object.values(arrayStr).join("");
|
|
29
|
+
return acc;
|
|
30
|
+
}
|
|
31
|
+
guard.isBN(data, type, key);
|
|
32
|
+
acc[key] = decodeShortString(value);
|
|
33
|
+
return acc;
|
|
34
|
+
}
|
|
35
|
+
if (elType === "number") {
|
|
36
|
+
guard.isBN(data, type, key);
|
|
37
|
+
acc[key] = Number(value);
|
|
38
|
+
return acc;
|
|
39
|
+
}
|
|
40
|
+
if (typeof elType === "function") {
|
|
41
|
+
acc[key] = elType(value);
|
|
42
|
+
return acc;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(elType)) {
|
|
45
|
+
const arrayObj = formatter(data[key], elType, elType[0]);
|
|
46
|
+
acc[key] = Object.values(arrayObj);
|
|
47
|
+
return acc;
|
|
48
|
+
}
|
|
49
|
+
if (typeof elType === "object") {
|
|
50
|
+
acc[key] = formatter(data[key], elType);
|
|
51
|
+
return acc;
|
|
52
|
+
}
|
|
53
|
+
guard.unknown(data, type, key);
|
|
54
|
+
return acc;
|
|
55
|
+
},
|
|
56
|
+
{}
|
|
57
|
+
);
|
|
58
|
+
}
|