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,315 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Literal,
|
|
3
|
+
Uint
|
|
4
|
+
} from "../../types/index.mjs";
|
|
5
|
+
import assert from "../assert.mjs";
|
|
6
|
+
import { CairoUint256 } from "../cairoDataTypes/uint256.mjs";
|
|
7
|
+
import { CairoUint512 } from "../cairoDataTypes/uint512.mjs";
|
|
8
|
+
import { isBigInt, isBoolean, isHex, isNumber, toBigInt } from "../num.mjs";
|
|
9
|
+
import { isLongText, isString } from "../shortString.mjs";
|
|
10
|
+
import {
|
|
11
|
+
getArrayType,
|
|
12
|
+
isLen,
|
|
13
|
+
isTypeArray,
|
|
14
|
+
isTypeBool,
|
|
15
|
+
isTypeByteArray,
|
|
16
|
+
isTypeBytes31,
|
|
17
|
+
isTypeEnum,
|
|
18
|
+
isTypeFelt,
|
|
19
|
+
isTypeLiteral,
|
|
20
|
+
isTypeNonZero,
|
|
21
|
+
isTypeOption,
|
|
22
|
+
isTypeResult,
|
|
23
|
+
isTypeStruct,
|
|
24
|
+
isTypeTuple,
|
|
25
|
+
isTypeUint
|
|
26
|
+
} from "./cairo.mjs";
|
|
27
|
+
const validateFelt = (parameter, input) => {
|
|
28
|
+
assert(
|
|
29
|
+
isString(parameter) || isNumber(parameter) || isBigInt(parameter),
|
|
30
|
+
`Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
|
|
31
|
+
);
|
|
32
|
+
if (isString(parameter) && !isHex(parameter)) return;
|
|
33
|
+
const param = BigInt(parameter.toString(10));
|
|
34
|
+
assert(
|
|
35
|
+
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1266
|
|
36
|
+
param >= 0n && param <= 2n ** 252n - 1n,
|
|
37
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
const validateBytes31 = (parameter, input) => {
|
|
41
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
42
|
+
assert(
|
|
43
|
+
parameter.length < 32,
|
|
44
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be a string of less than 32 characters.`
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
const validateByteArray = (parameter, input) => {
|
|
48
|
+
assert(isString(parameter), `Validate: arg ${input.name} should be a string.`);
|
|
49
|
+
};
|
|
50
|
+
const validateUint = (parameter, input) => {
|
|
51
|
+
if (isNumber(parameter)) {
|
|
52
|
+
assert(
|
|
53
|
+
parameter <= Number.MAX_SAFE_INTEGER,
|
|
54
|
+
`Validation: Parameter is to large to be typed as Number use (BigInt or String)`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
assert(
|
|
58
|
+
isString(parameter) || isNumber(parameter) || isBigInt(parameter) || typeof parameter === "object" && "low" in parameter && "high" in parameter || typeof parameter === "object" && ["limb0", "limb1", "limb2", "limb3"].every((key) => key in parameter),
|
|
59
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt), but is ${typeof parameter} ${parameter}.`
|
|
60
|
+
);
|
|
61
|
+
let param;
|
|
62
|
+
switch (input.type) {
|
|
63
|
+
case Uint.u256:
|
|
64
|
+
param = new CairoUint256(parameter).toBigInt();
|
|
65
|
+
break;
|
|
66
|
+
case Uint.u512:
|
|
67
|
+
param = new CairoUint512(parameter).toBigInt();
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
param = toBigInt(parameter);
|
|
71
|
+
}
|
|
72
|
+
switch (input.type) {
|
|
73
|
+
case Uint.u8:
|
|
74
|
+
assert(
|
|
75
|
+
param >= 0n && param <= 255n,
|
|
76
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
|
|
77
|
+
);
|
|
78
|
+
break;
|
|
79
|
+
case Uint.u16:
|
|
80
|
+
assert(
|
|
81
|
+
param >= 0n && param <= 65535n,
|
|
82
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
|
|
83
|
+
);
|
|
84
|
+
break;
|
|
85
|
+
case Uint.u32:
|
|
86
|
+
assert(
|
|
87
|
+
param >= 0n && param <= 4294967295n,
|
|
88
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
|
|
89
|
+
);
|
|
90
|
+
break;
|
|
91
|
+
case Uint.u64:
|
|
92
|
+
assert(
|
|
93
|
+
param >= 0n && param <= 2n ** 64n - 1n,
|
|
94
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
|
|
95
|
+
);
|
|
96
|
+
break;
|
|
97
|
+
case Uint.u128:
|
|
98
|
+
assert(
|
|
99
|
+
param >= 0n && param <= 2n ** 128n - 1n,
|
|
100
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
|
|
101
|
+
);
|
|
102
|
+
break;
|
|
103
|
+
case Uint.u256:
|
|
104
|
+
assert(
|
|
105
|
+
param >= 0n && param <= 2n ** 256n - 1n,
|
|
106
|
+
`Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
|
|
107
|
+
);
|
|
108
|
+
break;
|
|
109
|
+
case Uint.u512:
|
|
110
|
+
assert(CairoUint512.is(param), `Validate: arg ${input.name} is ${input.type} 0 - 2^512-1`);
|
|
111
|
+
break;
|
|
112
|
+
case Literal.ClassHash:
|
|
113
|
+
assert(
|
|
114
|
+
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1670
|
|
115
|
+
param >= 0n && param <= 2n ** 252n - 1n,
|
|
116
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
117
|
+
);
|
|
118
|
+
break;
|
|
119
|
+
case Literal.ContractAddress:
|
|
120
|
+
assert(
|
|
121
|
+
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1245
|
|
122
|
+
param >= 0n && param <= 2n ** 252n - 1n,
|
|
123
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^252-1]`
|
|
124
|
+
);
|
|
125
|
+
break;
|
|
126
|
+
case Literal.Secp256k1Point: {
|
|
127
|
+
assert(
|
|
128
|
+
param >= 0n && param <= 2n ** 512n - 1n,
|
|
129
|
+
`Validate: arg ${input.name} must be ${input.type} : a 512 bits number.`
|
|
130
|
+
);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const validateBool = (parameter, input) => {
|
|
138
|
+
assert(
|
|
139
|
+
isBoolean(parameter),
|
|
140
|
+
`Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
const validateStruct = (parameter, input, structs) => {
|
|
144
|
+
if (input.type === Uint.u256 || input.type === Uint.u512) {
|
|
145
|
+
validateUint(parameter, input);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (input.type === "core::starknet::eth_address::EthAddress") {
|
|
149
|
+
assert(
|
|
150
|
+
typeof parameter !== "object",
|
|
151
|
+
`EthAddress type is waiting a BigNumberish. Got ${parameter}`
|
|
152
|
+
);
|
|
153
|
+
const param = BigInt(parameter.toString(10));
|
|
154
|
+
assert(
|
|
155
|
+
// from : https://github.com/starkware-libs/starknet-specs/blob/29bab650be6b1847c92d4461d4c33008b5e50b1a/api/starknet_api_openrpc.json#L1259
|
|
156
|
+
param >= 0n && param <= 2n ** 160n - 1n,
|
|
157
|
+
`Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^160-1]`
|
|
158
|
+
);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
assert(
|
|
162
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
163
|
+
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
164
|
+
);
|
|
165
|
+
structs[input.type].members.forEach(({ name }) => {
|
|
166
|
+
assert(
|
|
167
|
+
Object.keys(parameter).includes(name),
|
|
168
|
+
`Validate: arg ${input.name} should have a property ${name}`
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
const validateEnum = (parameter, input) => {
|
|
173
|
+
assert(
|
|
174
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
175
|
+
`Validate: arg ${input.name} is cairo type Enum (${input.type}), and should be defined as js object (not array)`
|
|
176
|
+
);
|
|
177
|
+
const methodsKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(parameter));
|
|
178
|
+
const keys = [...Object.getOwnPropertyNames(parameter), ...methodsKeys];
|
|
179
|
+
if (isTypeOption(input.type) && keys.includes("isSome") && keys.includes("isNone")) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (isTypeResult(input.type) && keys.includes("isOk") && keys.includes("isErr")) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (keys.includes("variant") && keys.includes("activeVariant")) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Validate Enum: argument ${input.name}, type ${input.type}, value received ${parameter}, is not an Enum.`
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
const validateTuple = (parameter, input) => {
|
|
193
|
+
assert(
|
|
194
|
+
typeof parameter === "object" && !Array.isArray(parameter),
|
|
195
|
+
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
const validateArray = (parameter, input, structs, enums) => {
|
|
199
|
+
const baseType = getArrayType(input.type);
|
|
200
|
+
if (isTypeFelt(baseType) && isLongText(parameter)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
204
|
+
switch (true) {
|
|
205
|
+
case isTypeFelt(baseType):
|
|
206
|
+
parameter.forEach((param) => validateFelt(param, input));
|
|
207
|
+
break;
|
|
208
|
+
case isTypeTuple(baseType):
|
|
209
|
+
parameter.forEach((it) => validateTuple(it, { name: input.name, type: baseType }));
|
|
210
|
+
break;
|
|
211
|
+
case isTypeArray(baseType):
|
|
212
|
+
parameter.forEach(
|
|
213
|
+
(param) => validateArray(param, { name: "", type: baseType }, structs, enums)
|
|
214
|
+
);
|
|
215
|
+
break;
|
|
216
|
+
case isTypeStruct(baseType, structs):
|
|
217
|
+
parameter.forEach(
|
|
218
|
+
(it) => validateStruct(it, { name: input.name, type: baseType }, structs)
|
|
219
|
+
);
|
|
220
|
+
break;
|
|
221
|
+
case isTypeEnum(baseType, enums):
|
|
222
|
+
parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
|
|
223
|
+
break;
|
|
224
|
+
case (isTypeUint(baseType) || isTypeLiteral(baseType)):
|
|
225
|
+
parameter.forEach((param) => validateUint(param, { name: "", type: baseType }));
|
|
226
|
+
break;
|
|
227
|
+
case isTypeBool(baseType):
|
|
228
|
+
parameter.forEach((param) => validateBool(param, input));
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
throw new Error(
|
|
232
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const validateNonZero = (parameter, input) => {
|
|
237
|
+
const baseType = getArrayType(input.type);
|
|
238
|
+
assert(
|
|
239
|
+
isTypeUint(baseType) && baseType !== CairoUint512.abiSelector || isTypeFelt(baseType),
|
|
240
|
+
`Validate: ${input.name} type is not authorized for NonZero type.`
|
|
241
|
+
);
|
|
242
|
+
switch (true) {
|
|
243
|
+
case isTypeFelt(baseType):
|
|
244
|
+
validateFelt(parameter, input);
|
|
245
|
+
assert(
|
|
246
|
+
BigInt(parameter.toString(10)) > 0,
|
|
247
|
+
"Validate: value 0 is not authorized in NonZero felt252 type."
|
|
248
|
+
);
|
|
249
|
+
break;
|
|
250
|
+
case isTypeUint(baseType):
|
|
251
|
+
validateUint(parameter, { name: "", type: baseType });
|
|
252
|
+
switch (input.type) {
|
|
253
|
+
case Uint.u256:
|
|
254
|
+
assert(
|
|
255
|
+
new CairoUint256(parameter).toBigInt() > 0,
|
|
256
|
+
"Validate: value 0 is not authorized in NonZero uint256 type."
|
|
257
|
+
);
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
assert(
|
|
261
|
+
toBigInt(parameter) > 0,
|
|
262
|
+
"Validate: value 0 is not authorized in NonZero uint type."
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
default:
|
|
267
|
+
throw new Error(
|
|
268
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
export default function validateFields(abiMethod, args, structs, enums) {
|
|
273
|
+
abiMethod.inputs.reduce((acc, input) => {
|
|
274
|
+
const parameter = args[acc];
|
|
275
|
+
switch (true) {
|
|
276
|
+
case isLen(input.name):
|
|
277
|
+
return acc;
|
|
278
|
+
case isTypeFelt(input.type):
|
|
279
|
+
validateFelt(parameter, input);
|
|
280
|
+
break;
|
|
281
|
+
case isTypeBytes31(input.type):
|
|
282
|
+
validateBytes31(parameter, input);
|
|
283
|
+
break;
|
|
284
|
+
case (isTypeUint(input.type) || isTypeLiteral(input.type)):
|
|
285
|
+
validateUint(parameter, input);
|
|
286
|
+
break;
|
|
287
|
+
case isTypeBool(input.type):
|
|
288
|
+
validateBool(parameter, input);
|
|
289
|
+
break;
|
|
290
|
+
case isTypeByteArray(input.type):
|
|
291
|
+
validateByteArray(parameter, input);
|
|
292
|
+
break;
|
|
293
|
+
case isTypeArray(input.type):
|
|
294
|
+
validateArray(parameter, input, structs, enums);
|
|
295
|
+
break;
|
|
296
|
+
case isTypeStruct(input.type, structs):
|
|
297
|
+
validateStruct(parameter, input, structs);
|
|
298
|
+
break;
|
|
299
|
+
case isTypeEnum(input.type, enums):
|
|
300
|
+
validateEnum(parameter, input);
|
|
301
|
+
break;
|
|
302
|
+
case isTypeTuple(input.type):
|
|
303
|
+
validateTuple(parameter, input);
|
|
304
|
+
break;
|
|
305
|
+
case isTypeNonZero(input.type):
|
|
306
|
+
validateNonZero(parameter, input);
|
|
307
|
+
break;
|
|
308
|
+
default:
|
|
309
|
+
throw new Error(
|
|
310
|
+
`Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return acc + 1;
|
|
314
|
+
}, 0);
|
|
315
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.contractClassResponseToLegacyCompiledContract = contractClassResponseToLegacyCompiledContract;
|
|
7
|
+
exports.extractContractHashes = extractContractHashes;
|
|
8
|
+
exports.isSierra = isSierra;
|
|
9
|
+
var _hash = require("./hash/index.cjs");
|
|
10
|
+
var _json = require("./json.cjs");
|
|
11
|
+
var _stark = require("./stark.cjs");
|
|
12
|
+
var _shortString = require("./shortString.cjs");
|
|
13
|
+
function isSierra(contract) {
|
|
14
|
+
const compiledContract = (0, _shortString.isString)(contract) ? (0, _json.parse)(contract) : contract;
|
|
15
|
+
return "sierra_program" in compiledContract;
|
|
16
|
+
}
|
|
17
|
+
function extractContractHashes(payload) {
|
|
18
|
+
const response = {
|
|
19
|
+
...payload
|
|
20
|
+
};
|
|
21
|
+
if (isSierra(payload.contract)) {
|
|
22
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
23
|
+
response.compiledClassHash = (0, _hash.computeCompiledClassHash)(payload.casm);
|
|
24
|
+
}
|
|
25
|
+
if (!response.compiledClassHash) throw new Error("Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash");
|
|
26
|
+
}
|
|
27
|
+
response.classHash = payload.classHash ?? (0, _hash.computeContractClassHash)(payload.contract);
|
|
28
|
+
if (!response.classHash) throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
32
|
+
if (isSierra(ccr)) {
|
|
33
|
+
throw Error("ContractClassResponse need to be LegacyContractClass (cairo0 response class)");
|
|
34
|
+
}
|
|
35
|
+
const contract = ccr;
|
|
36
|
+
return {
|
|
37
|
+
...contract,
|
|
38
|
+
program: (0, _stark.decompressProgram)(contract.program)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ContractClassResponse } from '../types';
|
|
2
|
+
import { CairoContract, CompiledSierra, LegacyCompiledContract, SierraContractClass } from '../types/lib/contract/index';
|
|
3
|
+
import { CompleteDeclareContractPayload, DeclareContractPayload } from '../types/lib/index';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given contract is in Sierra (Safe Intermediate Representation) format.
|
|
6
|
+
*
|
|
7
|
+
* @param {CairoContract | string} contract - The contract to check. Can be either a CairoContract object or a string representation of the contract.
|
|
8
|
+
* @return {boolean} - Returns true if the contract is a Sierra contract, otherwise false.
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const result = isSierra(contract);
|
|
12
|
+
* // result = true | false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSierra(contract: CairoContract | string): contract is SierraContractClass | CompiledSierra;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts contract hashes from `DeclareContractPayload`.
|
|
18
|
+
*
|
|
19
|
+
* @param {DeclareContractPayload} payload - The payload containing contract information.
|
|
20
|
+
* @return {CompleteDeclareContractPayload} - The `CompleteDeclareContractPayload` with extracted contract hashes.
|
|
21
|
+
* @throws {Error} - If extraction of compiledClassHash or classHash fails.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const result = extractContractHashes(contract);
|
|
25
|
+
* // result = {
|
|
26
|
+
* // contract: ...,
|
|
27
|
+
* // classHash: ...,
|
|
28
|
+
* // casm: ...,
|
|
29
|
+
* // compiledClassHash: ...,
|
|
30
|
+
* // }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function extractContractHashes(payload: DeclareContractPayload): CompleteDeclareContractPayload;
|
|
34
|
+
/**
|
|
35
|
+
* Helper to redeclare response Cairo0 contract
|
|
36
|
+
*/
|
|
37
|
+
export declare function contractClassResponseToLegacyCompiledContract(ccr: ContractClassResponse): LegacyCompiledContract;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { computeCompiledClassHash, computeContractClassHash } from "./hash/index.mjs";
|
|
2
|
+
import { parse } from "./json.mjs";
|
|
3
|
+
import { decompressProgram } from "./stark.mjs";
|
|
4
|
+
import { isString } from "./shortString.mjs";
|
|
5
|
+
export function isSierra(contract) {
|
|
6
|
+
const compiledContract = isString(contract) ? parse(contract) : contract;
|
|
7
|
+
return "sierra_program" in compiledContract;
|
|
8
|
+
}
|
|
9
|
+
export function extractContractHashes(payload) {
|
|
10
|
+
const response = { ...payload };
|
|
11
|
+
if (isSierra(payload.contract)) {
|
|
12
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
13
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
14
|
+
}
|
|
15
|
+
if (!response.compiledClassHash)
|
|
16
|
+
throw new Error(
|
|
17
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
21
|
+
if (!response.classHash)
|
|
22
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
23
|
+
return response;
|
|
24
|
+
}
|
|
25
|
+
export function contractClassResponseToLegacyCompiledContract(ccr) {
|
|
26
|
+
if (isSierra(ccr)) {
|
|
27
|
+
throw Error("ContractClassResponse need to be LegacyContractClass (cairo0 response class)");
|
|
28
|
+
}
|
|
29
|
+
const contract = ccr;
|
|
30
|
+
return { ...contract, program: decompressProgram(contract.program) };
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.weierstrass = exports.starkCurve = void 0;
|
|
7
|
+
var _starkCurve = _interopRequireWildcard(require("@scure/starknet"));
|
|
8
|
+
exports.starkCurve = _starkCurve;
|
|
9
|
+
var _weierstrass = _interopRequireWildcard(require("@noble/curves/abstract/weierstrass"));
|
|
10
|
+
exports.weierstrass = _weierstrass;
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.IS_BROWSER = void 0;
|
|
7
|
+
exports.addHexPrefix = addHexPrefix;
|
|
8
|
+
exports.arrayBufferToString = arrayBufferToString;
|
|
9
|
+
exports.atobUniversal = atobUniversal;
|
|
10
|
+
exports.btoaUniversal = btoaUniversal;
|
|
11
|
+
exports.buf2hex = buf2hex;
|
|
12
|
+
exports.calcByteLength = calcByteLength;
|
|
13
|
+
exports.padLeft = padLeft;
|
|
14
|
+
exports.pascalToSnake = void 0;
|
|
15
|
+
exports.removeHexPrefix = removeHexPrefix;
|
|
16
|
+
exports.sanitizeBytes = sanitizeBytes;
|
|
17
|
+
exports.sanitizeHex = sanitizeHex;
|
|
18
|
+
exports.stringToArrayBuffer = stringToArrayBuffer;
|
|
19
|
+
exports.utf8ToArray = utf8ToArray;
|
|
20
|
+
var _base = require("@scure/base");
|
|
21
|
+
const IS_BROWSER = exports.IS_BROWSER = typeof window !== "undefined";
|
|
22
|
+
const STRING_ZERO = "0";
|
|
23
|
+
function arrayBufferToString(array) {
|
|
24
|
+
return new Uint8Array(array).reduce((data, byte) => data + String.fromCharCode(byte), "");
|
|
25
|
+
}
|
|
26
|
+
function utf8ToArray(str) {
|
|
27
|
+
return new TextEncoder().encode(str);
|
|
28
|
+
}
|
|
29
|
+
function stringToArrayBuffer(str) {
|
|
30
|
+
return utf8ToArray(str);
|
|
31
|
+
}
|
|
32
|
+
function atobUniversal(a) {
|
|
33
|
+
return _base.base64.decode(a);
|
|
34
|
+
}
|
|
35
|
+
function btoaUniversal(b) {
|
|
36
|
+
return _base.base64.encode(new Uint8Array(b));
|
|
37
|
+
}
|
|
38
|
+
function buf2hex(buffer) {
|
|
39
|
+
return buffer.reduce((r, x) => r + x.toString(16).padStart(2, "0"), "");
|
|
40
|
+
}
|
|
41
|
+
function removeHexPrefix(hex) {
|
|
42
|
+
return hex.replace(/^0x/i, "");
|
|
43
|
+
}
|
|
44
|
+
function addHexPrefix(hex) {
|
|
45
|
+
return `0x${removeHexPrefix(hex)}`;
|
|
46
|
+
}
|
|
47
|
+
function padString(str, length, left, padding = STRING_ZERO) {
|
|
48
|
+
const diff = length - str.length;
|
|
49
|
+
let result = str;
|
|
50
|
+
if (diff > 0) {
|
|
51
|
+
const pad = padding.repeat(diff);
|
|
52
|
+
result = left ? pad + str : str + pad;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function padLeft(str, length, padding = STRING_ZERO) {
|
|
57
|
+
return padString(str, length, true, padding);
|
|
58
|
+
}
|
|
59
|
+
function calcByteLength(str, byteSize = 8) {
|
|
60
|
+
const {
|
|
61
|
+
length
|
|
62
|
+
} = str;
|
|
63
|
+
const remainder = length % byteSize;
|
|
64
|
+
return remainder ? (length - remainder) / byteSize * byteSize + byteSize : length;
|
|
65
|
+
}
|
|
66
|
+
function sanitizeBytes(str, byteSize = 8, padding = STRING_ZERO) {
|
|
67
|
+
return padLeft(str, calcByteLength(str, byteSize), padding);
|
|
68
|
+
}
|
|
69
|
+
function sanitizeHex(hex) {
|
|
70
|
+
hex = removeHexPrefix(hex);
|
|
71
|
+
hex = sanitizeBytes(hex, 2);
|
|
72
|
+
if (hex) {
|
|
73
|
+
hex = addHexPrefix(hex);
|
|
74
|
+
}
|
|
75
|
+
return hex;
|
|
76
|
+
}
|
|
77
|
+
const pascalToSnake = text => /[a-z]/.test(text) ? text.split(/(?=[A-Z])/).join("_").toUpperCase() : text;
|
|
78
|
+
exports.pascalToSnake = pascalToSnake;
|