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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addAddressPadding = addAddressPadding;
|
|
7
|
+
exports.getChecksumAddress = getChecksumAddress;
|
|
8
|
+
exports.validateAndParseAddress = validateAndParseAddress;
|
|
9
|
+
exports.validateChecksumAddress = validateChecksumAddress;
|
|
10
|
+
var _utils = require("@noble/curves/abstract/utils");
|
|
11
|
+
var _constants = require("../constants.cjs");
|
|
12
|
+
var _encode = require("./encode.cjs");
|
|
13
|
+
var _hash = require("./hash/index.cjs");
|
|
14
|
+
var _num = require("./num.cjs");
|
|
15
|
+
function addAddressPadding(address) {
|
|
16
|
+
const hex = (0, _num.toHex)((0, _encode.addHexPrefix)(address.toString()));
|
|
17
|
+
const padded = (0, _encode.removeHexPrefix)(hex).padStart(64, "0");
|
|
18
|
+
return (0, _encode.addHexPrefix)(padded);
|
|
19
|
+
}
|
|
20
|
+
function validateAndParseAddress(address) {
|
|
21
|
+
const result = addAddressPadding(address);
|
|
22
|
+
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
23
|
+
throw new Error("Invalid Address Format");
|
|
24
|
+
}
|
|
25
|
+
(0, _num.assertInRange)(result, _constants.ZERO, _constants.ADDR_BOUND - 1n, "Starknet Address");
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
function getChecksumAddress(address) {
|
|
29
|
+
const chars = (0, _encode.removeHexPrefix)(validateAndParseAddress(address)).toLowerCase().split("");
|
|
30
|
+
const hex = (0, _encode.removeHexPrefix)((0, _hash.keccakBn)(address));
|
|
31
|
+
const hashed = (0, _utils.hexToBytes)(hex.padStart(64, "0"));
|
|
32
|
+
for (let i = 0; i < chars.length; i += 2) {
|
|
33
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
34
|
+
chars[i] = chars[i].toUpperCase();
|
|
35
|
+
}
|
|
36
|
+
if ((hashed[i >> 1] & 15) >= 8) {
|
|
37
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return (0, _encode.addHexPrefix)(chars.join(""));
|
|
41
|
+
}
|
|
42
|
+
function validateChecksumAddress(address) {
|
|
43
|
+
return getChecksumAddress(address) === address;
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BigNumberish } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Format a hex number to '0x' and 64 characters, adding leading zeros if necessary.
|
|
4
|
+
*
|
|
5
|
+
* @param {BigNumberish} address
|
|
6
|
+
* @returns {string} Hex string : 0x followed by 64 characters. No upper case characters in the response.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const address = "0x90591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf";
|
|
10
|
+
* const result = addAddressPadding(address);
|
|
11
|
+
* // result = "0x0000090591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function addAddressPadding(address: BigNumberish): string;
|
|
15
|
+
/**
|
|
16
|
+
* Check the validity of a Starknet address, and format it as a hex number : '0x' and 64 characters, adding leading zeros if necessary.
|
|
17
|
+
*
|
|
18
|
+
* @param {BigNumberish} address
|
|
19
|
+
* @returns {string} Hex string : 0x followed by 64 characters. No upper case characters in the response.
|
|
20
|
+
* @throws address argument must be a valid address inside the address range bound
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const address = "0x90591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf";
|
|
24
|
+
* const result = validateAndParseAddress(address);
|
|
25
|
+
* // result = "0x0000090591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf"
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateAndParseAddress(address: BigNumberish): string;
|
|
29
|
+
/**
|
|
30
|
+
* Convert an address to her checksum representation which uses a specific pattern of uppercase and lowercase letters within
|
|
31
|
+
* a given address to reduce the risk of errors introduced from typing an address or cut and paste issues.
|
|
32
|
+
* @param {BigNumberish} address
|
|
33
|
+
* @returns {string} Hex string : 0x followed by 64 characters. Mix of uppercase and lowercase
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const address = "0x90591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf";
|
|
37
|
+
* const result = getChecksumAddress(address);
|
|
38
|
+
* // result = "0x0000090591D9fA3EfC87067d95a643f8455E0b8190eb8Cb7bFd39e4fb7571fDF"
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function getChecksumAddress(address: BigNumberish): string;
|
|
42
|
+
/**
|
|
43
|
+
* If the casing of an address is mixed, it is a Checksum Address, which uses a specific pattern of uppercase and lowercase letters within
|
|
44
|
+
* a given address to reduce the risk of errors introduced from typing an address or cut and paste issues.
|
|
45
|
+
*
|
|
46
|
+
* @param address string
|
|
47
|
+
* @returns true if the ChecksumAddress is valid
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const address = "0x0000090591D9fA3EfC87067d95a643f8455E0b8190eb8Cb7bFd39e4fb7571fDF";
|
|
51
|
+
* const result = validateChecksumAddress(address);
|
|
52
|
+
* // result = true
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function validateChecksumAddress(address: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { hexToBytes } from "@noble/curves/abstract/utils";
|
|
2
|
+
import { ADDR_BOUND, ZERO } from "../constants.mjs";
|
|
3
|
+
import { addHexPrefix, removeHexPrefix } from "./encode.mjs";
|
|
4
|
+
import { keccakBn } from "./hash/index.mjs";
|
|
5
|
+
import { assertInRange, toHex } from "./num.mjs";
|
|
6
|
+
export function addAddressPadding(address) {
|
|
7
|
+
const hex = toHex(addHexPrefix(address.toString()));
|
|
8
|
+
const padded = removeHexPrefix(hex).padStart(64, "0");
|
|
9
|
+
return addHexPrefix(padded);
|
|
10
|
+
}
|
|
11
|
+
export function validateAndParseAddress(address) {
|
|
12
|
+
const result = addAddressPadding(address);
|
|
13
|
+
if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
|
|
14
|
+
throw new Error("Invalid Address Format");
|
|
15
|
+
}
|
|
16
|
+
assertInRange(result, ZERO, ADDR_BOUND - 1n, "Starknet Address");
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
export function getChecksumAddress(address) {
|
|
20
|
+
const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
|
|
21
|
+
const hex = removeHexPrefix(keccakBn(address));
|
|
22
|
+
const hashed = hexToBytes(hex.padStart(64, "0"));
|
|
23
|
+
for (let i = 0; i < chars.length; i += 2) {
|
|
24
|
+
if (hashed[i >> 1] >> 4 >= 8) {
|
|
25
|
+
chars[i] = chars[i].toUpperCase();
|
|
26
|
+
}
|
|
27
|
+
if ((hashed[i >> 1] & 15) >= 8) {
|
|
28
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return addHexPrefix(chars.join(""));
|
|
32
|
+
}
|
|
33
|
+
export function validateChecksumAddress(address) {
|
|
34
|
+
return getChecksumAddress(address) === address;
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that the given condition is true, otherwise throws an error with an optional message.
|
|
3
|
+
* @param {any} condition - The condition to check.
|
|
4
|
+
* @param {string} [message] - The optional message to include in the error.
|
|
5
|
+
* @throws {Error} Throws an error if the condition is false.
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const address = '0xa7ee790591d9fa3efc87067d95a643f8455e0b8190eb8cb7bfd39e4fb7571fdf';
|
|
9
|
+
* assert(/^(0x)?[0-9a-fA-F]{64}$/.test(address), 'Invalid address format');
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export default function assert(condition: boolean, message?: string): asserts condition;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CairoFelt = CairoFelt;
|
|
7
|
+
var _num = require("../num.cjs");
|
|
8
|
+
var _shortString = require("../shortString.cjs");
|
|
9
|
+
function CairoFelt(it) {
|
|
10
|
+
if ((0, _num.isBigInt)(it) || Number.isInteger(it)) {
|
|
11
|
+
return it.toString();
|
|
12
|
+
}
|
|
13
|
+
if ((0, _shortString.isString)(it)) {
|
|
14
|
+
if ((0, _num.isHex)(it)) {
|
|
15
|
+
return BigInt(it).toString();
|
|
16
|
+
}
|
|
17
|
+
if ((0, _shortString.isText)(it)) {
|
|
18
|
+
if (!(0, _shortString.isShortString)(it)) {
|
|
19
|
+
throw new Error(`${it} is a long string > 31 chars. Please split it into an array of short strings.`);
|
|
20
|
+
}
|
|
21
|
+
return BigInt((0, _shortString.encodeShortString)(it)).toString();
|
|
22
|
+
}
|
|
23
|
+
if ((0, _num.isStringWholeNumber)(it)) {
|
|
24
|
+
return it;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if ((0, _num.isBoolean)(it)) {
|
|
28
|
+
return `${+it}`;
|
|
29
|
+
}
|
|
30
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isBigInt, isBoolean, isHex, isStringWholeNumber } from "../num.mjs";
|
|
2
|
+
import { encodeShortString, isShortString, isString, isText } from "../shortString.mjs";
|
|
3
|
+
export function CairoFelt(it) {
|
|
4
|
+
if (isBigInt(it) || Number.isInteger(it)) {
|
|
5
|
+
return it.toString();
|
|
6
|
+
}
|
|
7
|
+
if (isString(it)) {
|
|
8
|
+
if (isHex(it)) {
|
|
9
|
+
return BigInt(it).toString();
|
|
10
|
+
}
|
|
11
|
+
if (isText(it)) {
|
|
12
|
+
if (!isShortString(it)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`${it} is a long string > 31 chars. Please split it into an array of short strings.`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return BigInt(encodeShortString(it)).toString();
|
|
18
|
+
}
|
|
19
|
+
if (isStringWholeNumber(it)) {
|
|
20
|
+
return it;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (isBoolean(it)) {
|
|
24
|
+
return `${+it}`;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`${it} can't be computed by felt()`);
|
|
27
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UINT_256_MIN = exports.UINT_256_MAX = exports.UINT_256_LOW_MIN = exports.UINT_256_LOW_MAX = exports.UINT_256_HIGH_MIN = exports.UINT_256_HIGH_MAX = exports.UINT_128_MAX = exports.CairoUint256 = void 0;
|
|
7
|
+
var _encode = require("../encode.cjs");
|
|
8
|
+
var _felt = require("./felt.cjs");
|
|
9
|
+
const UINT_128_MAX = exports.UINT_128_MAX = (1n << 128n) - 1n;
|
|
10
|
+
const UINT_256_MAX = exports.UINT_256_MAX = (1n << 256n) - 1n;
|
|
11
|
+
const UINT_256_MIN = exports.UINT_256_MIN = 0n;
|
|
12
|
+
const UINT_256_LOW_MAX = exports.UINT_256_LOW_MAX = 340282366920938463463374607431768211455n;
|
|
13
|
+
const UINT_256_HIGH_MAX = exports.UINT_256_HIGH_MAX = 340282366920938463463374607431768211455n;
|
|
14
|
+
const UINT_256_LOW_MIN = exports.UINT_256_LOW_MIN = 0n;
|
|
15
|
+
const UINT_256_HIGH_MIN = exports.UINT_256_HIGH_MIN = 0n;
|
|
16
|
+
class CairoUint256 {
|
|
17
|
+
low;
|
|
18
|
+
high;
|
|
19
|
+
static abiSelector = "core::integer::u256";
|
|
20
|
+
constructor(...arr) {
|
|
21
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "low" in arr[0] && "high" in arr[0]) {
|
|
22
|
+
const props = CairoUint256.validateProps(arr[0].low, arr[0].high);
|
|
23
|
+
this.low = props.low;
|
|
24
|
+
this.high = props.high;
|
|
25
|
+
} else if (arr.length === 1) {
|
|
26
|
+
const bigInt = CairoUint256.validate(arr[0]);
|
|
27
|
+
this.low = bigInt & UINT_128_MAX;
|
|
28
|
+
this.high = bigInt >> 128n;
|
|
29
|
+
} else if (arr.length === 2) {
|
|
30
|
+
const props = CairoUint256.validateProps(arr[0], arr[1]);
|
|
31
|
+
this.low = props.low;
|
|
32
|
+
this.high = props.high;
|
|
33
|
+
} else {
|
|
34
|
+
throw Error("Incorrect constructor parameters");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate if BigNumberish can be represented as Unit256
|
|
39
|
+
*/
|
|
40
|
+
static validate(bigNumberish) {
|
|
41
|
+
const bigInt = BigInt(bigNumberish);
|
|
42
|
+
if (bigInt < UINT_256_MIN) throw Error("bigNumberish is smaller than UINT_256_MIN");
|
|
43
|
+
if (bigInt > UINT_256_MAX) throw new Error("bigNumberish is bigger than UINT_256_MAX");
|
|
44
|
+
return bigInt;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate if low and high can be represented as Unit256
|
|
48
|
+
*/
|
|
49
|
+
static validateProps(low, high) {
|
|
50
|
+
const bigIntLow = BigInt(low);
|
|
51
|
+
const bigIntHigh = BigInt(high);
|
|
52
|
+
if (bigIntLow < UINT_256_LOW_MIN || bigIntLow > UINT_256_LOW_MAX) {
|
|
53
|
+
throw new Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX");
|
|
54
|
+
}
|
|
55
|
+
if (bigIntHigh < UINT_256_HIGH_MIN || bigIntHigh > UINT_256_HIGH_MAX) {
|
|
56
|
+
throw new Error("high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX");
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
low: bigIntLow,
|
|
60
|
+
high: bigIntHigh
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if BigNumberish can be represented as Unit256
|
|
65
|
+
*/
|
|
66
|
+
static is(bigNumberish) {
|
|
67
|
+
try {
|
|
68
|
+
CairoUint256.validate(bigNumberish);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check if provided abi type is this data type
|
|
76
|
+
*/
|
|
77
|
+
static isAbiType(abiType) {
|
|
78
|
+
return abiType === CairoUint256.abiSelector;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Return bigint representation
|
|
82
|
+
*/
|
|
83
|
+
toBigInt() {
|
|
84
|
+
return (this.high << 128n) + this.low;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Return Uint256 structure with HexString props
|
|
88
|
+
* {low: HexString, high: HexString}
|
|
89
|
+
*/
|
|
90
|
+
toUint256HexString() {
|
|
91
|
+
return {
|
|
92
|
+
low: (0, _encode.addHexPrefix)(this.low.toString(16)),
|
|
93
|
+
high: (0, _encode.addHexPrefix)(this.high.toString(16))
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Return Uint256 structure with DecimalString props
|
|
98
|
+
* {low: DecString, high: DecString}
|
|
99
|
+
*/
|
|
100
|
+
toUint256DecimalString() {
|
|
101
|
+
return {
|
|
102
|
+
low: this.low.toString(10),
|
|
103
|
+
high: this.high.toString(10)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Return api requests representation witch is felt array
|
|
108
|
+
*/
|
|
109
|
+
toApiRequest() {
|
|
110
|
+
return [(0, _felt.CairoFelt)(this.low), (0, _felt.CairoFelt)(this.high)];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.CairoUint256 = CairoUint256;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Singular class handling cairo u256 data type
|
|
3
|
+
*/
|
|
4
|
+
import { BigNumberish, Uint256 } from '../../types';
|
|
5
|
+
export declare const UINT_128_MAX: bigint;
|
|
6
|
+
export declare const UINT_256_MAX: bigint;
|
|
7
|
+
export declare const UINT_256_MIN = 0n;
|
|
8
|
+
export declare const UINT_256_LOW_MAX = 340282366920938463463374607431768211455n;
|
|
9
|
+
export declare const UINT_256_HIGH_MAX = 340282366920938463463374607431768211455n;
|
|
10
|
+
export declare const UINT_256_LOW_MIN = 0n;
|
|
11
|
+
export declare const UINT_256_HIGH_MIN = 0n;
|
|
12
|
+
export declare class CairoUint256 {
|
|
13
|
+
low: bigint;
|
|
14
|
+
high: bigint;
|
|
15
|
+
static abiSelector: string;
|
|
16
|
+
/**
|
|
17
|
+
* Default constructor (Lib usage)
|
|
18
|
+
* @param bigNumberish BigNumberish value representing uin256
|
|
19
|
+
*/
|
|
20
|
+
constructor(bigNumberish: BigNumberish);
|
|
21
|
+
/**
|
|
22
|
+
* Direct props initialization (Api response)
|
|
23
|
+
*/
|
|
24
|
+
constructor(low: BigNumberish, high: BigNumberish);
|
|
25
|
+
/**
|
|
26
|
+
* Initialization from Uint256 object
|
|
27
|
+
*/
|
|
28
|
+
constructor(uint256: Uint256);
|
|
29
|
+
/**
|
|
30
|
+
* Validate if BigNumberish can be represented as Unit256
|
|
31
|
+
*/
|
|
32
|
+
static validate(bigNumberish: BigNumberish): bigint;
|
|
33
|
+
/**
|
|
34
|
+
* Validate if low and high can be represented as Unit256
|
|
35
|
+
*/
|
|
36
|
+
static validateProps(low: BigNumberish, high: BigNumberish): {
|
|
37
|
+
low: bigint;
|
|
38
|
+
high: bigint;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Check if BigNumberish can be represented as Unit256
|
|
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 Uint256 structure with HexString props
|
|
54
|
+
* {low: HexString, high: HexString}
|
|
55
|
+
*/
|
|
56
|
+
toUint256HexString(): {
|
|
57
|
+
low: string;
|
|
58
|
+
high: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Return Uint256 structure with DecimalString props
|
|
62
|
+
* {low: DecString, high: DecString}
|
|
63
|
+
*/
|
|
64
|
+
toUint256DecimalString(): {
|
|
65
|
+
low: string;
|
|
66
|
+
high: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Return api requests representation witch is felt array
|
|
70
|
+
*/
|
|
71
|
+
toApiRequest(): string[];
|
|
72
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { addHexPrefix } from "../encode.mjs";
|
|
2
|
+
import { CairoFelt } from "./felt.mjs";
|
|
3
|
+
export const UINT_128_MAX = (1n << 128n) - 1n;
|
|
4
|
+
export const UINT_256_MAX = (1n << 256n) - 1n;
|
|
5
|
+
export const UINT_256_MIN = 0n;
|
|
6
|
+
export const UINT_256_LOW_MAX = 340282366920938463463374607431768211455n;
|
|
7
|
+
export const UINT_256_HIGH_MAX = 340282366920938463463374607431768211455n;
|
|
8
|
+
export const UINT_256_LOW_MIN = 0n;
|
|
9
|
+
export const UINT_256_HIGH_MIN = 0n;
|
|
10
|
+
export class CairoUint256 {
|
|
11
|
+
low;
|
|
12
|
+
high;
|
|
13
|
+
static abiSelector = "core::integer::u256";
|
|
14
|
+
constructor(...arr) {
|
|
15
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "low" in arr[0] && "high" in arr[0]) {
|
|
16
|
+
const props = CairoUint256.validateProps(arr[0].low, arr[0].high);
|
|
17
|
+
this.low = props.low;
|
|
18
|
+
this.high = props.high;
|
|
19
|
+
} else if (arr.length === 1) {
|
|
20
|
+
const bigInt = CairoUint256.validate(arr[0]);
|
|
21
|
+
this.low = bigInt & UINT_128_MAX;
|
|
22
|
+
this.high = bigInt >> 128n;
|
|
23
|
+
} else if (arr.length === 2) {
|
|
24
|
+
const props = CairoUint256.validateProps(arr[0], arr[1]);
|
|
25
|
+
this.low = props.low;
|
|
26
|
+
this.high = props.high;
|
|
27
|
+
} else {
|
|
28
|
+
throw Error("Incorrect constructor parameters");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validate if BigNumberish can be represented as Unit256
|
|
33
|
+
*/
|
|
34
|
+
static validate(bigNumberish) {
|
|
35
|
+
const bigInt = BigInt(bigNumberish);
|
|
36
|
+
if (bigInt < UINT_256_MIN) throw Error("bigNumberish is smaller than UINT_256_MIN");
|
|
37
|
+
if (bigInt > UINT_256_MAX) throw new Error("bigNumberish is bigger than UINT_256_MAX");
|
|
38
|
+
return bigInt;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate if low and high can be represented as Unit256
|
|
42
|
+
*/
|
|
43
|
+
static validateProps(low, high) {
|
|
44
|
+
const bigIntLow = BigInt(low);
|
|
45
|
+
const bigIntHigh = BigInt(high);
|
|
46
|
+
if (bigIntLow < UINT_256_LOW_MIN || bigIntLow > UINT_256_LOW_MAX) {
|
|
47
|
+
throw new Error("low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX");
|
|
48
|
+
}
|
|
49
|
+
if (bigIntHigh < UINT_256_HIGH_MIN || bigIntHigh > UINT_256_HIGH_MAX) {
|
|
50
|
+
throw new Error("high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX");
|
|
51
|
+
}
|
|
52
|
+
return { low: bigIntLow, high: bigIntHigh };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if BigNumberish can be represented as Unit256
|
|
56
|
+
*/
|
|
57
|
+
static is(bigNumberish) {
|
|
58
|
+
try {
|
|
59
|
+
CairoUint256.validate(bigNumberish);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if provided abi type is this data type
|
|
67
|
+
*/
|
|
68
|
+
static isAbiType(abiType) {
|
|
69
|
+
return abiType === CairoUint256.abiSelector;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Return bigint representation
|
|
73
|
+
*/
|
|
74
|
+
toBigInt() {
|
|
75
|
+
return (this.high << 128n) + this.low;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Return Uint256 structure with HexString props
|
|
79
|
+
* {low: HexString, high: HexString}
|
|
80
|
+
*/
|
|
81
|
+
toUint256HexString() {
|
|
82
|
+
return {
|
|
83
|
+
low: addHexPrefix(this.low.toString(16)),
|
|
84
|
+
high: addHexPrefix(this.high.toString(16))
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Return Uint256 structure with DecimalString props
|
|
89
|
+
* {low: DecString, high: DecString}
|
|
90
|
+
*/
|
|
91
|
+
toUint256DecimalString() {
|
|
92
|
+
return {
|
|
93
|
+
low: this.low.toString(10),
|
|
94
|
+
high: this.high.toString(10)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Return api requests representation witch is felt array
|
|
99
|
+
*/
|
|
100
|
+
toApiRequest() {
|
|
101
|
+
return [CairoFelt(this.low), CairoFelt(this.high)];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UINT_512_MIN = exports.UINT_512_MAX = exports.UINT_128_MIN = exports.CairoUint512 = void 0;
|
|
7
|
+
var _encode = require("../encode.cjs");
|
|
8
|
+
var _felt = require("./felt.cjs");
|
|
9
|
+
var _uint = require("./uint256.cjs");
|
|
10
|
+
const UINT_512_MAX = exports.UINT_512_MAX = (1n << 512n) - 1n;
|
|
11
|
+
const UINT_512_MIN = exports.UINT_512_MIN = 0n;
|
|
12
|
+
const UINT_128_MIN = exports.UINT_128_MIN = 0n;
|
|
13
|
+
class CairoUint512 {
|
|
14
|
+
limb0;
|
|
15
|
+
limb1;
|
|
16
|
+
limb2;
|
|
17
|
+
limb3;
|
|
18
|
+
static abiSelector = "core::integer::u512";
|
|
19
|
+
constructor(...arr) {
|
|
20
|
+
if (typeof arr[0] === "object" && arr.length === 1 && "limb0" in arr[0] && "limb1" in arr[0] && "limb2" in arr[0] && "limb3" in arr[0]) {
|
|
21
|
+
const props = CairoUint512.validateProps(arr[0].limb0, arr[0].limb1, arr[0].limb2, arr[0].limb3);
|
|
22
|
+
this.limb0 = props.limb0;
|
|
23
|
+
this.limb1 = props.limb1;
|
|
24
|
+
this.limb2 = props.limb2;
|
|
25
|
+
this.limb3 = props.limb3;
|
|
26
|
+
} else if (arr.length === 1) {
|
|
27
|
+
const bigInt = CairoUint512.validate(arr[0]);
|
|
28
|
+
this.limb0 = bigInt & _uint.UINT_128_MAX;
|
|
29
|
+
this.limb1 = (bigInt & _uint.UINT_128_MAX << 128n) >> 128n;
|
|
30
|
+
this.limb2 = (bigInt & _uint.UINT_128_MAX << 256n) >> 256n;
|
|
31
|
+
this.limb3 = bigInt >> 384n;
|
|
32
|
+
} else if (arr.length === 4) {
|
|
33
|
+
const props = CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
|
|
34
|
+
this.limb0 = props.limb0;
|
|
35
|
+
this.limb1 = props.limb1;
|
|
36
|
+
this.limb2 = props.limb2;
|
|
37
|
+
this.limb3 = props.limb3;
|
|
38
|
+
} else {
|
|
39
|
+
throw Error("Incorrect Uint512 constructor parameters");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validate if BigNumberish can be represented as Uint512
|
|
44
|
+
*/
|
|
45
|
+
static validate(bigNumberish) {
|
|
46
|
+
const bigInt = BigInt(bigNumberish);
|
|
47
|
+
if (bigInt < UINT_512_MIN) throw Error("bigNumberish is smaller than UINT_512_MIN.");
|
|
48
|
+
if (bigInt > UINT_512_MAX) throw Error("bigNumberish is bigger than UINT_512_MAX.");
|
|
49
|
+
return bigInt;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validate if limbs can be represented as Uint512
|
|
53
|
+
*/
|
|
54
|
+
static validateProps(limb0, limb1, limb2, limb3) {
|
|
55
|
+
const l0 = BigInt(limb0);
|
|
56
|
+
const l1 = BigInt(limb1);
|
|
57
|
+
const l2 = BigInt(limb2);
|
|
58
|
+
const l3 = BigInt(limb3);
|
|
59
|
+
[l0, l1, l2, l3].forEach((value, index) => {
|
|
60
|
+
if (value < UINT_128_MIN || value > _uint.UINT_128_MAX) {
|
|
61
|
+
throw Error(`limb${index} is not in the range of a u128 number`);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
limb0: l0,
|
|
66
|
+
limb1: l1,
|
|
67
|
+
limb2: l2,
|
|
68
|
+
limb3: l3
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if BigNumberish can be represented as Uint512
|
|
73
|
+
*/
|
|
74
|
+
static is(bigNumberish) {
|
|
75
|
+
try {
|
|
76
|
+
CairoUint512.validate(bigNumberish);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if provided abi type is this data type
|
|
84
|
+
*/
|
|
85
|
+
static isAbiType(abiType) {
|
|
86
|
+
return abiType === CairoUint512.abiSelector;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Return bigint representation
|
|
90
|
+
*/
|
|
91
|
+
toBigInt() {
|
|
92
|
+
return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Return Uint512 structure with HexString props
|
|
96
|
+
* limbx: HexString
|
|
97
|
+
*/
|
|
98
|
+
toUint512HexString() {
|
|
99
|
+
return {
|
|
100
|
+
limb0: (0, _encode.addHexPrefix)(this.limb0.toString(16)),
|
|
101
|
+
limb1: (0, _encode.addHexPrefix)(this.limb1.toString(16)),
|
|
102
|
+
limb2: (0, _encode.addHexPrefix)(this.limb2.toString(16)),
|
|
103
|
+
limb3: (0, _encode.addHexPrefix)(this.limb3.toString(16))
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Return Uint512 structure with DecimalString props
|
|
108
|
+
* limbx DecString
|
|
109
|
+
*/
|
|
110
|
+
toUint512DecimalString() {
|
|
111
|
+
return {
|
|
112
|
+
limb0: this.limb0.toString(10),
|
|
113
|
+
limb1: this.limb1.toString(10),
|
|
114
|
+
limb2: this.limb2.toString(10),
|
|
115
|
+
limb3: this.limb3.toString(10)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Return api requests representation witch is felt array
|
|
120
|
+
*/
|
|
121
|
+
toApiRequest() {
|
|
122
|
+
return [(0, _felt.CairoFelt)(this.limb0), (0, _felt.CairoFelt)(this.limb1), (0, _felt.CairoFelt)(this.limb2), (0, _felt.CairoFelt)(this.limb3)];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.CairoUint512 = CairoUint512;
|