starknet 5.5.0 → 5.6.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 CHANGED
@@ -1,3 +1,23 @@
1
+ ## [5.6.1](https://github.com/0xs34n/starknet.js/compare/v5.6.0...v5.6.1) (2023-04-21)
2
+
3
+ ### Bug Fixes
4
+
5
+ - uint256 struct ([4ce2d02](https://github.com/0xs34n/starknet.js/commit/4ce2d0255594831e7ad816368e3cfa14449feaa5))
6
+ - uint256, view bool, compiled in contract.call ([346cd51](https://github.com/0xs34n/starknet.js/commit/346cd5197d377966d148a8b218e6ee03af7170f2))
7
+
8
+ # [5.6.0](https://github.com/0xs34n/starknet.js/compare/v5.5.0...v5.6.0) (2023-04-19)
9
+
10
+ ### Bug Fixes
11
+
12
+ - optional param in contract invoke ([da094e4](https://github.com/0xs34n/starknet.js/commit/da094e4172ed43ce93604e92adbba2a5ecb1498e))
13
+
14
+ ### Features
15
+
16
+ - cairo 1 bool ([52fed30](https://github.com/0xs34n/starknet.js/commit/52fed30f04b70bcce80f829dba6975101f6f3644))
17
+ - cairo1 array, fix invoke response, hash separate test ([4637cd7](https://github.com/0xs34n/starknet.js/commit/4637cd74481ba85b3164ddb93c258b9ca8b9b949))
18
+ - felt252 implementation ([3d20ea4](https://github.com/0xs34n/starknet.js/commit/3d20ea44b49d1c7ba90d8a46a307f54e737c3285))
19
+ - uint validate and parsing supprot ([c1acd29](https://github.com/0xs34n/starknet.js/commit/c1acd298d63758ba27fc20bcb4b0c00cca82078f))
20
+
1
21
  # [5.5.0](https://github.com/0xs34n/starknet.js/compare/v5.4.2...v5.5.0) (2023-04-10)
2
22
 
3
23
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -462,7 +462,7 @@ declare type Overrides = {
462
462
  maxFee?: BigNumberish;
463
463
  nonce?: BigNumberish;
464
464
  signature?: Signature;
465
- parseRequest: Boolean;
465
+ parseRequest?: Boolean;
466
466
  };
467
467
 
468
468
  interface InvocationsSignerDetails extends Required<InvocationsDetails> {
@@ -487,7 +487,7 @@ declare type AsyncContractFunction<T = any> = (...args: Array<any>) => Promise<T
487
487
  declare type ContractFunction = (...args: Array<any>) => any;
488
488
  declare type Result = {
489
489
  [key: string]: any;
490
- };
490
+ } | Result[] | bigint | string | boolean;
491
491
 
492
492
  declare type BlockIdentifier = BlockNumber | BigNumberish;
493
493
 
@@ -511,8 +511,8 @@ declare type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJ
511
511
  declare type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER';
512
512
  declare type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
513
513
  declare enum BLOCK_TAG {
514
- 'latest' = 0,
515
- 'pending' = 1
514
+ latest = "latest",
515
+ pending = "pending"
516
516
  }
517
517
  declare type BLOCK_ID = {
518
518
  block_hash: BLOCK_HASH;
@@ -2727,14 +2727,16 @@ declare class Contract implements ContractInterface {
2727
2727
  };
2728
2728
  readonly [key: string]: AsyncContractFunction | any;
2729
2729
  private callData;
2730
+ private version;
2730
2731
  /**
2731
2732
  * Contract class to handle contract methods
2732
2733
  *
2733
2734
  * @param abi - Abi of the contract object
2734
2735
  * @param address (optional) - address to connect to
2735
2736
  * @param providerOrAccount (optional) - Provider or Account to attach to
2737
+ * @param cairoVersion (optional) - default '0', for Cairo 1 set '1'
2736
2738
  */
2737
- constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
2739
+ constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface, cairoVersion?: string);
2738
2740
  attach(address: string): void;
2739
2741
  connect(providerOrAccount: ProviderInterface | AccountInterface): void;
2740
2742
  deployed(): Promise<Contract>;
@@ -3013,20 +3015,20 @@ declare const UINT_256_MAX: bigint;
3013
3015
  declare function isUint256(bn: BigNumberish): boolean;
3014
3016
  declare function bnToUint256(bignumber: BigNumberish): Uint256;
3015
3017
 
3016
- type uint256_Uint256 = Uint256;
3017
- declare const uint256_uint256ToBN: typeof uint256ToBN;
3018
- declare const uint256_UINT_128_MAX: typeof UINT_128_MAX;
3019
- declare const uint256_UINT_256_MAX: typeof UINT_256_MAX;
3020
- declare const uint256_isUint256: typeof isUint256;
3021
- declare const uint256_bnToUint256: typeof bnToUint256;
3022
- declare namespace uint256 {
3018
+ type uint256$1_Uint256 = Uint256;
3019
+ declare const uint256$1_uint256ToBN: typeof uint256ToBN;
3020
+ declare const uint256$1_UINT_128_MAX: typeof UINT_128_MAX;
3021
+ declare const uint256$1_UINT_256_MAX: typeof UINT_256_MAX;
3022
+ declare const uint256$1_isUint256: typeof isUint256;
3023
+ declare const uint256$1_bnToUint256: typeof bnToUint256;
3024
+ declare namespace uint256$1 {
3023
3025
  export {
3024
- uint256_Uint256 as Uint256,
3025
- uint256_uint256ToBN as uint256ToBN,
3026
- uint256_UINT_128_MAX as UINT_128_MAX,
3027
- uint256_UINT_256_MAX as UINT_256_MAX,
3028
- uint256_isUint256 as isUint256,
3029
- uint256_bnToUint256 as bnToUint256,
3026
+ uint256$1_Uint256 as Uint256,
3027
+ uint256$1_uint256ToBN as uint256ToBN,
3028
+ uint256$1_UINT_128_MAX as UINT_128_MAX,
3029
+ uint256$1_UINT_256_MAX as UINT_256_MAX,
3030
+ uint256$1_isUint256 as isUint256,
3031
+ uint256$1_bnToUint256 as bnToUint256,
3030
3032
  };
3031
3033
  }
3032
3034
 
@@ -3104,6 +3106,136 @@ declare function validateChecksumAddress(address: string): boolean;
3104
3106
  declare function isUrl(s?: string): boolean;
3105
3107
  declare function buildUrl(baseUrl: string, defaultPath: string, urlOrPath?: string): string;
3106
3108
 
3109
+ declare enum Uint {
3110
+ u8 = "core::integer::u8",
3111
+ u16 = "core::integer::u16",
3112
+ u32 = "core::integer::u32",
3113
+ u64 = "core::integer::u64",
3114
+ u128 = "core::integer::u128",
3115
+ u256 = "core::integer::u256"
3116
+ }
3117
+ declare const isLen: (name: string) => boolean;
3118
+ declare const isTypeFelt: (type: string) => boolean;
3119
+ declare const isTypeArray: (type: string) => boolean;
3120
+ declare const isTypeTuple: (type: string) => boolean;
3121
+ declare const isTypeNamedTuple: (type: string) => boolean;
3122
+ declare const isTypeStruct: (type: string, structs: AbiStructs) => boolean;
3123
+ declare const isTypeUint: (type: string) => boolean;
3124
+ declare const isTypeUint256: (type: string) => boolean;
3125
+ declare const isTypeBool: (type: string) => boolean;
3126
+ declare const isTypeContractAddress: (type: string) => boolean;
3127
+ declare const isCairo1Type: (type: string) => boolean;
3128
+ declare const getArrayType: (type: string) => string;
3129
+ /**
3130
+ * named tuple are described as js object {}
3131
+ * struct types are described as js object {}
3132
+ * array types are described as js array []
3133
+ */
3134
+ /**
3135
+ * Uint256 cairo type (helper for common struct type)
3136
+ */
3137
+ declare const uint256: (it: BigNumberish) => Uint256;
3138
+ /**
3139
+ * unnamed tuple cairo type (helper same as common struct type)
3140
+ */
3141
+ declare const tuple: (...args: (BigNumberish | object)[]) => {
3142
+ [x: number]: object | BigNumberish;
3143
+ length: number;
3144
+ toString(): string;
3145
+ toLocaleString(): string;
3146
+ pop(): object | BigNumberish | undefined;
3147
+ push(...items: (object | BigNumberish)[]): number;
3148
+ concat(...items: ConcatArray<object | BigNumberish>[]): (object | BigNumberish)[];
3149
+ concat(...items: (object | BigNumberish | ConcatArray<object | BigNumberish>)[]): (object | BigNumberish)[];
3150
+ join(separator?: string | undefined): string;
3151
+ reverse(): (object | BigNumberish)[];
3152
+ shift(): object | BigNumberish | undefined;
3153
+ slice(start?: number | undefined, end?: number | undefined): (object | BigNumberish)[];
3154
+ sort(compareFn?: ((a: object | BigNumberish, b: object | BigNumberish) => number) | undefined): (object | BigNumberish)[];
3155
+ splice(start: number, deleteCount?: number | undefined): (object | BigNumberish)[];
3156
+ splice(start: number, deleteCount: number, ...items: (object | BigNumberish)[]): (object | BigNumberish)[];
3157
+ unshift(...items: (object | BigNumberish)[]): number;
3158
+ indexOf(searchElement: object | BigNumberish, fromIndex?: number | undefined): number;
3159
+ lastIndexOf(searchElement: object | BigNumberish, fromIndex?: number | undefined): number;
3160
+ every<S extends object | BigNumberish>(predicate: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => value is S, thisArg?: any): this is S[];
3161
+ every(predicate: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => unknown, thisArg?: any): boolean;
3162
+ some(predicate: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => unknown, thisArg?: any): boolean;
3163
+ forEach(callbackfn: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => void, thisArg?: any): void;
3164
+ map<U>(callbackfn: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => U, thisArg?: any): U[];
3165
+ filter<S_1 extends object | BigNumberish>(predicate: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => value is S_1, thisArg?: any): S_1[];
3166
+ filter(predicate: (value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => unknown, thisArg?: any): (object | BigNumberish)[];
3167
+ reduce(callbackfn: (previousValue: object | BigNumberish, currentValue: object | BigNumberish, currentIndex: number, array: (object | BigNumberish)[]) => object | BigNumberish): object | BigNumberish;
3168
+ reduce(callbackfn: (previousValue: object | BigNumberish, currentValue: object | BigNumberish, currentIndex: number, array: (object | BigNumberish)[]) => object | BigNumberish, initialValue: object | BigNumberish): object | BigNumberish;
3169
+ reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: object | BigNumberish, currentIndex: number, array: (object | BigNumberish)[]) => U_1, initialValue: U_1): U_1;
3170
+ reduceRight(callbackfn: (previousValue: object | BigNumberish, currentValue: object | BigNumberish, currentIndex: number, array: (object | BigNumberish)[]) => object | BigNumberish): object | BigNumberish;
3171
+ reduceRight(callbackfn: (previousValue: object | BigNumberish, currentValue: object | BigNumberish, currentIndex: number, array: (object | BigNumberish)[]) => object | BigNumberish, initialValue: object | BigNumberish): object | BigNumberish;
3172
+ reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: object | BigNumberish, currentIndex: number, array: (object | BigNumberish)[]) => U_2, initialValue: U_2): U_2;
3173
+ find<S_2 extends object | BigNumberish>(predicate: (this: void, value: object | BigNumberish, index: number, obj: (object | BigNumberish)[]) => value is S_2, thisArg?: any): S_2 | undefined;
3174
+ find(predicate: (value: object | BigNumberish, index: number, obj: (object | BigNumberish)[]) => unknown, thisArg?: any): object | BigNumberish | undefined;
3175
+ findIndex(predicate: (value: object | BigNumberish, index: number, obj: (object | BigNumberish)[]) => unknown, thisArg?: any): number;
3176
+ fill(value: object | BigNumberish, start?: number | undefined, end?: number | undefined): (object | BigNumberish)[];
3177
+ copyWithin(target: number, start: number, end?: number | undefined): (object | BigNumberish)[];
3178
+ entries(): IterableIterator<[number, object | BigNumberish]>;
3179
+ keys(): IterableIterator<number>;
3180
+ values(): IterableIterator<object | BigNumberish>;
3181
+ includes(searchElement: object | BigNumberish, fromIndex?: number | undefined): boolean;
3182
+ flatMap<U_3, This = undefined>(callback: (this: This, value: object | BigNumberish, index: number, array: (object | BigNumberish)[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
3183
+ flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
3184
+ [Symbol.iterator](): IterableIterator<object | BigNumberish>;
3185
+ [Symbol.unscopables](): {
3186
+ copyWithin: boolean;
3187
+ entries: boolean;
3188
+ fill: boolean;
3189
+ find: boolean;
3190
+ findIndex: boolean;
3191
+ keys: boolean;
3192
+ values: boolean;
3193
+ };
3194
+ at(index: number): object | BigNumberish | undefined;
3195
+ };
3196
+ /**
3197
+ * felt cairo type
3198
+ */
3199
+ declare function felt(it: BigNumberish): string;
3200
+
3201
+ type cairo_Uint = Uint;
3202
+ declare const cairo_Uint: typeof Uint;
3203
+ declare const cairo_isLen: typeof isLen;
3204
+ declare const cairo_isTypeFelt: typeof isTypeFelt;
3205
+ declare const cairo_isTypeArray: typeof isTypeArray;
3206
+ declare const cairo_isTypeTuple: typeof isTypeTuple;
3207
+ declare const cairo_isTypeNamedTuple: typeof isTypeNamedTuple;
3208
+ declare const cairo_isTypeStruct: typeof isTypeStruct;
3209
+ declare const cairo_isTypeUint: typeof isTypeUint;
3210
+ declare const cairo_isTypeUint256: typeof isTypeUint256;
3211
+ declare const cairo_isTypeBool: typeof isTypeBool;
3212
+ declare const cairo_isTypeContractAddress: typeof isTypeContractAddress;
3213
+ declare const cairo_isCairo1Type: typeof isCairo1Type;
3214
+ declare const cairo_getArrayType: typeof getArrayType;
3215
+ declare const cairo_uint256: typeof uint256;
3216
+ declare const cairo_tuple: typeof tuple;
3217
+ declare const cairo_felt: typeof felt;
3218
+ declare namespace cairo {
3219
+ export {
3220
+ cairo_Uint as Uint,
3221
+ cairo_isLen as isLen,
3222
+ cairo_isTypeFelt as isTypeFelt,
3223
+ cairo_isTypeArray as isTypeArray,
3224
+ cairo_isTypeTuple as isTypeTuple,
3225
+ cairo_isTypeNamedTuple as isTypeNamedTuple,
3226
+ cairo_isTypeStruct as isTypeStruct,
3227
+ cairo_isTypeUint as isTypeUint,
3228
+ cairo_isTypeUint256 as isTypeUint256,
3229
+ cairo_isTypeBool as isTypeBool,
3230
+ cairo_isTypeContractAddress as isTypeContractAddress,
3231
+ cairo_isCairo1Type as isCairo1Type,
3232
+ cairo_getArrayType as getArrayType,
3233
+ cairo_uint256 as uint256,
3234
+ cairo_tuple as tuple,
3235
+ cairo_felt as felt,
3236
+ };
3237
+ }
3238
+
3107
3239
  declare class CallData {
3108
3240
  abi: Abi;
3109
3241
  protected readonly structs: AbiStructs;
@@ -3136,7 +3268,7 @@ declare class CallData {
3136
3268
  * @param response - response from the method
3137
3269
  * @return - parsed response corresponding to the abi
3138
3270
  */
3139
- parse(method: string, response: string[]): object;
3271
+ parse(method: string, response: string[]): Result;
3140
3272
  /**
3141
3273
  * Format cairo method response data to native js values based on provided format schema
3142
3274
  * @param method - cairo method name
@@ -3156,4 +3288,4 @@ declare class CallData {
3156
3288
  /** @deprecated prefer the 'num' naming */
3157
3289
  declare const number: typeof num;
3158
3290
 
3159
- export { Abi, AbiEntry, AbiStructs, Account, AccountInterface, AllowArray, Args, ArraySignatureType, AsyncContractFunction, BlockNumber, BlockTag, Builtins, ByteCode, CairoAssembly, CairoContract, CairoVersion, Call, CallContractResponse, CallData, CallDetails, CallL1Handler, CallOptions, CallStruct, Calldata, CommonTransactionReceiptResponse, CommonTransactionResponse, CompiledContract, CompiledSierra, CompiledSierraCasm, CompleteDeclareContractPayload, CompressedProgram, Contract, ContractClass, ContractEntryPoint, ContractEntryPointFields, ContractFactory, ContractFunction, ContractInterface, CustomError, DeclareAndDeployContractPayload, DeclareContractPayload, DeclareContractResponse, DeclareContractTransaction, DeclareDeployUDCResponse, DeclareSignerDetails, DeclareTransactionReceiptResponse, DeclareTransactionResponse, DeployAccountContractPayload, DeployAccountContractTransaction, DeployAccountSignerDetails, DeployContractPayload, DeployContractResponse, DeployContractUDCResponse, DeployedContractItem, Details, EntryPointType, EntryPointsByType, EstimateFee, EstimateFeeAction, EstimateFeeBulk, EstimateFeeDetails, EstimateFeeResponse, EstimateFeeResponseBulk, Event, ExecutionResources, FunctionAbi, FunctionInvocation, GatewayError, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionReceiptResponse, GetTransactionResponse, GetTransactionStatusResponse, HttpError, Invocation, InvocationBulk, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeTransactionReceiptResponse, InvokeTransactionResponse, LegacyCompiledContract, LegacyContractClass, LibraryError, MessageToL1, MessageToL2, MultiDeployContractResponse, Nonce, Overrides, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, PythonicHints, RPC, RawArgs, RawCalldata, Result, RpcProvider, RpcProviderOptions, Sequencer, SequencerHttpMethod, SequencerIdentifier, SequencerProvider, SequencerProviderOptions, SierraContractClass, SierraContractEntryPointFields, SierraEntryPointsByType, SierraProgramDebugInfo, Signature, Signer, SignerInterface, StateUpdateResponse, Status, Storage, Struct, StructAbi, TransactionBulk, TransactionSimulation, TransactionSimulationResponse, TransactionStatus, TransactionTraceResponse, TransactionType, Tupled, UniversalDeployerContractPayload, WeierstrassSignatureType, addAddressPadding, buildUrl, constants, defaultProvider, ec, encode, fixProto, fixStack, getChecksumAddress, hash, isUrl, json, merkle, num, number, shortString, stark, transaction, index as typedData, uint256, validateAndParseAddress, validateChecksumAddress, waitForTransactionOptions };
3291
+ export { Abi, AbiEntry, AbiStructs, Account, AccountInterface, AllowArray, Args, ArraySignatureType, AsyncContractFunction, BlockNumber, BlockTag, Builtins, ByteCode, CairoAssembly, CairoContract, CairoVersion, Call, CallContractResponse, CallData, CallDetails, CallL1Handler, CallOptions, CallStruct, Calldata, CommonTransactionReceiptResponse, CommonTransactionResponse, CompiledContract, CompiledSierra, CompiledSierraCasm, CompleteDeclareContractPayload, CompressedProgram, Contract, ContractClass, ContractEntryPoint, ContractEntryPointFields, ContractFactory, ContractFunction, ContractInterface, CustomError, DeclareAndDeployContractPayload, DeclareContractPayload, DeclareContractResponse, DeclareContractTransaction, DeclareDeployUDCResponse, DeclareSignerDetails, DeclareTransactionReceiptResponse, DeclareTransactionResponse, DeployAccountContractPayload, DeployAccountContractTransaction, DeployAccountSignerDetails, DeployContractPayload, DeployContractResponse, DeployContractUDCResponse, DeployedContractItem, Details, EntryPointType, EntryPointsByType, EstimateFee, EstimateFeeAction, EstimateFeeBulk, EstimateFeeDetails, EstimateFeeResponse, EstimateFeeResponseBulk, Event, ExecutionResources, FunctionAbi, FunctionInvocation, GatewayError, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionReceiptResponse, GetTransactionResponse, GetTransactionStatusResponse, HttpError, Invocation, InvocationBulk, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeTransactionReceiptResponse, InvokeTransactionResponse, LegacyCompiledContract, LegacyContractClass, LibraryError, MessageToL1, MessageToL2, MultiDeployContractResponse, Nonce, Overrides, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, PythonicHints, RPC, RawArgs, RawCalldata, Result, RpcProvider, RpcProviderOptions, Sequencer, SequencerHttpMethod, SequencerIdentifier, SequencerProvider, SequencerProviderOptions, SierraContractClass, SierraContractEntryPointFields, SierraEntryPointsByType, SierraProgramDebugInfo, Signature, Signer, SignerInterface, StateUpdateResponse, Status, Storage, Struct, StructAbi, TransactionBulk, TransactionSimulation, TransactionSimulationResponse, TransactionStatus, TransactionTraceResponse, TransactionType, Tupled, UniversalDeployerContractPayload, WeierstrassSignatureType, addAddressPadding, buildUrl, cairo, constants, defaultProvider, ec, encode, fixProto, fixStack, getChecksumAddress, hash, isUrl, json, merkle, num, number, shortString, stark, transaction, index as typedData, uint256$1 as uint256, validateAndParseAddress, validateChecksumAddress, waitForTransactionOptions };
@@ -630,6 +630,7 @@ var starknet = (() => {
630
630
  TransactionType: () => TransactionType,
631
631
  addAddressPadding: () => addAddressPadding,
632
632
  buildUrl: () => buildUrl,
633
+ cairo: () => cairo_exports,
633
634
  constants: () => constants_exports,
634
635
  defaultProvider: () => defaultProvider,
635
636
  ec: () => ec_exports,
@@ -5309,6 +5310,27 @@ var starknet = (() => {
5309
5310
  ]
5310
5311
  ];
5311
5312
 
5313
+ // src/utils/calldata/cairo.ts
5314
+ var cairo_exports = {};
5315
+ __export(cairo_exports, {
5316
+ Uint: () => Uint,
5317
+ felt: () => felt,
5318
+ getArrayType: () => getArrayType,
5319
+ isCairo1Type: () => isCairo1Type,
5320
+ isLen: () => isLen,
5321
+ isTypeArray: () => isTypeArray,
5322
+ isTypeBool: () => isTypeBool,
5323
+ isTypeContractAddress: () => isTypeContractAddress,
5324
+ isTypeFelt: () => isTypeFelt,
5325
+ isTypeNamedTuple: () => isTypeNamedTuple,
5326
+ isTypeStruct: () => isTypeStruct,
5327
+ isTypeTuple: () => isTypeTuple,
5328
+ isTypeUint: () => isTypeUint,
5329
+ isTypeUint256: () => isTypeUint256,
5330
+ tuple: () => tuple,
5331
+ uint256: () => uint256
5332
+ });
5333
+
5312
5334
  // src/utils/num.ts
5313
5335
  var num_exports = {};
5314
5336
  __export(num_exports, {
@@ -5464,8 +5486,8 @@ var starknet = (() => {
5464
5486
  isUint256: () => isUint256,
5465
5487
  uint256ToBN: () => uint256ToBN
5466
5488
  });
5467
- function uint256ToBN(uint256) {
5468
- return (toBigInt(uint256.high) << 128n) + toBigInt(uint256.low);
5489
+ function uint256ToBN(uint2562) {
5490
+ return (toBigInt(uint2562.high) << 128n) + toBigInt(uint2562.low);
5469
5491
  }
5470
5492
  var UINT_128_MAX = (1n << 128n) - 1n;
5471
5493
  var UINT_256_MAX = (1n << 256n) - 1n;
@@ -5483,13 +5505,42 @@ var starknet = (() => {
5483
5505
  }
5484
5506
 
5485
5507
  // src/utils/calldata/cairo.ts
5508
+ var Uint = /* @__PURE__ */ ((Uint2) => {
5509
+ Uint2["u8"] = "core::integer::u8";
5510
+ Uint2["u16"] = "core::integer::u16";
5511
+ Uint2["u32"] = "core::integer::u32";
5512
+ Uint2["u64"] = "core::integer::u64";
5513
+ Uint2["u128"] = "core::integer::u128";
5514
+ Uint2["u256"] = "core::integer::u256";
5515
+ return Uint2;
5516
+ })(Uint || {});
5486
5517
  var isLen = (name) => /_len$/.test(name);
5487
- var isTypeFelt = (type) => type === "felt";
5488
- var isTypeFeltArray = (type) => type === "felt*";
5489
- var isTypeArray = (type) => /\*/.test(type);
5518
+ var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
5519
+ var isTypeArray = (type) => /\*/.test(type) || type.includes("core::array::Array::");
5490
5520
  var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
5491
5521
  var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
5492
5522
  var isTypeStruct = (type, structs) => type in structs;
5523
+ var isTypeUint = (type) => Object.values(Uint).includes(type);
5524
+ var isTypeUint256 = (type) => type === "core::integer::u256";
5525
+ var isTypeBool = (type) => type === "core::bool";
5526
+ var isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
5527
+ var isCairo1Type = (type) => type.includes("core::");
5528
+ var getArrayType = (type) => {
5529
+ if (isCairo1Type(type)) {
5530
+ return type.substring(type.indexOf("<") + 1, type.indexOf(">"));
5531
+ }
5532
+ return type.replace("*", "");
5533
+ };
5534
+ var uint256 = (it) => {
5535
+ const bn = BigInt(it);
5536
+ if (!isUint256(bn))
5537
+ throw new Error("Number is too large");
5538
+ return {
5539
+ low: (bn & UINT_128_MAX).toString(10),
5540
+ high: (bn >> 128n).toString(10)
5541
+ };
5542
+ };
5543
+ var tuple = (...args) => ({ ...args });
5493
5544
  function felt(it) {
5494
5545
  if (isBigInt(it) || typeof it === "number" && Number.isInteger(it)) {
5495
5546
  return it.toString();
@@ -11478,10 +11529,11 @@ var starknet = (() => {
11478
11529
  const url = buildUrl(this.baseUrl, "", endpoint);
11479
11530
  const method = (options == null ? void 0 : options.method) ?? "GET";
11480
11531
  const headers = this.getHeaders(method);
11532
+ const body = stringify2(options == null ? void 0 : options.body);
11481
11533
  try {
11482
11534
  const response = await fetchPonyfill_default(url, {
11483
11535
  method,
11484
- body: stringify2(options == null ? void 0 : options.body),
11536
+ body,
11485
11537
  headers
11486
11538
  });
11487
11539
  const textResponse = await response.text();
@@ -11998,7 +12050,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
11998
12050
  result
11999
12051
  };
12000
12052
  }
12001
- function extractTupleMemberTypes(type) {
12053
+ function extractCairo0Tuple(type) {
12002
12054
  const cleanType = type.replace(/\s/g, "").slice(1, -1);
12003
12055
  const { subTuple, result } = parseSubTuple(cleanType);
12004
12056
  let recomposed = result.split(",").map((it) => {
@@ -12011,6 +12063,16 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12011
12063
  }
12012
12064
  return recomposed;
12013
12065
  }
12066
+ function extractCairo1Tuple(type) {
12067
+ const cleanType = type.replace(/\s/g, "").slice(1, -1);
12068
+ return cleanType.split(",");
12069
+ }
12070
+ function extractTupleMemberTypes(type) {
12071
+ if (isCairo1Type(type)) {
12072
+ return extractCairo1Tuple(type);
12073
+ }
12074
+ return extractCairo0Tuple(type);
12075
+ }
12014
12076
 
12015
12077
  // src/utils/calldata/requestParser.ts
12016
12078
  function parseTuple(element, typeStr) {
@@ -12037,6 +12099,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12037
12099
  if (Array.isArray(element)) {
12038
12100
  throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
12039
12101
  }
12102
+ if (isTypeUint256(type)) {
12103
+ const el_uint256 = uint256(element);
12104
+ return [felt(el_uint256.low), felt(el_uint256.high)];
12105
+ }
12040
12106
  if (structs[type] && structs[type].members.length) {
12041
12107
  const { members } = structs[type];
12042
12108
  const subElement = element;
@@ -12069,16 +12135,21 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12069
12135
  }
12070
12136
  const result = [];
12071
12137
  result.push(felt(value.length));
12138
+ const arrayType = getArrayType(input.type);
12072
12139
  return value.reduce((acc, el) => {
12073
- if (isTypeFeltArray(type)) {
12140
+ if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
12074
12141
  acc.push(felt(el));
12142
+ } else if (isTypeBool(arrayType) && typeof el === "boolean") {
12143
+ acc.push(el.toString());
12075
12144
  } else {
12076
- acc.push(...parseCalldataValue(el, type.replace("*", ""), structs));
12145
+ acc.push(...parseCalldataValue(el, arrayType, structs));
12077
12146
  }
12078
12147
  return acc;
12079
12148
  }, result);
12080
- case (isTypeStruct(type, structs) || isTypeTuple(type)):
12149
+ case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
12081
12150
  return parseCalldataValue(value, type, structs);
12151
+ case isTypeBool(type):
12152
+ return `${+value}`;
12082
12153
  default:
12083
12154
  return felt(value);
12084
12155
  }
@@ -12111,8 +12182,24 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12111
12182
  case isLen(name):
12112
12183
  temp = responseIterator.next().value;
12113
12184
  return BigInt(temp);
12185
+ case isTypeBool(type):
12186
+ temp = responseIterator.next().value;
12187
+ return Boolean(BigInt(temp));
12188
+ case isTypeUint256(type):
12189
+ const low = responseIterator.next().value;
12190
+ const high = responseIterator.next().value;
12191
+ return uint256ToBN({ low, high });
12114
12192
  case isTypeArray(type):
12115
12193
  const parsedDataArr = [];
12194
+ if (isCairo1Type(type)) {
12195
+ responseIterator.next();
12196
+ let it = responseIterator.next();
12197
+ while (!it.done) {
12198
+ parsedDataArr.push(BigInt(it.value));
12199
+ it = responseIterator.next();
12200
+ }
12201
+ return parsedDataArr;
12202
+ }
12116
12203
  if (parsedResult && parsedResult[`${name}_len`]) {
12117
12204
  const arrLen = parsedResult[`${name}_len`];
12118
12205
  while (parsedDataArr.length < arrLen) {
@@ -12134,7 +12221,66 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12134
12221
  var validateFelt = (parameter, input) => {
12135
12222
  assert2(
12136
12223
  typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
12137
- `Validate: arg ${input.name} should be a felt (string, number, BigNumber)`
12224
+ `Validate: arg ${input.name} should be a felt typed as (String, Number or BigInt)`
12225
+ );
12226
+ };
12227
+ var validateUint = (parameter, input) => {
12228
+ if (typeof parameter === "number") {
12229
+ assert2(
12230
+ parameter <= Number.MAX_SAFE_INTEGER,
12231
+ `Validation: Parameter is to large to be typed as Number use (BigInt or String)`
12232
+ );
12233
+ }
12234
+ assert2(
12235
+ typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
12236
+ `Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
12237
+ );
12238
+ const param = toBigInt(parameter);
12239
+ switch (input.type) {
12240
+ case "core::integer::u8" /* u8 */:
12241
+ assert2(
12242
+ param >= 0n && param <= 255n,
12243
+ `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0 - 255]`
12244
+ );
12245
+ break;
12246
+ case "core::integer::u16" /* u16 */:
12247
+ assert2(
12248
+ param >= 0n && param <= 65535n,
12249
+ `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 65535]`
12250
+ );
12251
+ break;
12252
+ case "core::integer::u32" /* u32 */:
12253
+ assert2(
12254
+ param >= 0n && param <= 4294967295n,
12255
+ `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 4294967295]`
12256
+ );
12257
+ break;
12258
+ case "core::integer::u64" /* u64 */:
12259
+ assert2(
12260
+ param >= 0n && param <= 2n ** 64n - 1n,
12261
+ `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^64-1]`
12262
+ );
12263
+ break;
12264
+ case "core::integer::u128" /* u128 */:
12265
+ assert2(
12266
+ param >= 0n && param <= 2n ** 128n - 1n,
12267
+ `Validate: arg ${input.name} cairo typed ${input.type} should be in range [0, 2^128-1]`
12268
+ );
12269
+ break;
12270
+ case "core::integer::u256" /* u256 */:
12271
+ assert2(
12272
+ param >= 0n && param <= 2n ** 256n - 1n,
12273
+ `Validate: arg ${input.name} is ${input.type} 0 - 2^256-1`
12274
+ );
12275
+ break;
12276
+ default:
12277
+ break;
12278
+ }
12279
+ };
12280
+ var validateBool = (parameter, input) => {
12281
+ assert2(
12282
+ typeof parameter === "boolean",
12283
+ `Validate: arg ${input.name} of cairo type ${input.type} should be type (Boolean)`
12138
12284
  );
12139
12285
  };
12140
12286
  var validateStruct = (parameter, input, structs) => {
@@ -12156,7 +12302,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12156
12302
  );
12157
12303
  };
12158
12304
  var validateArray = (parameter, input, structs) => {
12159
- const baseType = input.type.replace("*", "");
12305
+ const baseType = getArrayType(input.type);
12160
12306
  if (isTypeFelt(baseType) && isLongText(parameter))
12161
12307
  return;
12162
12308
  assert2(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
@@ -12172,6 +12318,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12172
12318
  (it) => validateStruct(it, { name: input.name, type: baseType }, structs)
12173
12319
  );
12174
12320
  break;
12321
+ case isTypeUint(baseType):
12322
+ parameter.forEach((param) => validateUint(param, input));
12323
+ break;
12324
+ case isTypeBool(baseType):
12325
+ parameter.forEach((param) => validateBool(param, input));
12326
+ break;
12175
12327
  default:
12176
12328
  throw new Error(
12177
12329
  `Validate Unhandled: argument ${input.name}, type ${input.type}, value ${parameter}`
@@ -12187,6 +12339,14 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12187
12339
  case isTypeFelt(input.type):
12188
12340
  validateFelt(parameter, input);
12189
12341
  break;
12342
+ case isTypeUint(input.type):
12343
+ validateUint(parameter, input);
12344
+ break;
12345
+ case isTypeBool(input.type):
12346
+ validateBool(parameter, input);
12347
+ break;
12348
+ case isTypeContractAddress(input.type):
12349
+ break;
12190
12350
  case isTypeStruct(input.type, structs):
12191
12351
  validateStruct(parameter, input, structs);
12192
12352
  break;
@@ -12275,13 +12435,15 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12275
12435
  parse(method, response) {
12276
12436
  const { outputs } = this.abi.find((abi) => abi.name === method);
12277
12437
  const responseIterator = response.flat()[Symbol.iterator]();
12278
- return outputs.flat().reduce((acc, output2) => {
12279
- acc[output2.name] = responseParser(responseIterator, output2, this.structs, acc);
12280
- if (acc[output2.name] && acc[`${output2.name}_len`]) {
12281
- delete acc[`${output2.name}_len`];
12438
+ const parsed = outputs.flat().reduce((acc, output2, idx) => {
12439
+ const propName = output2.name ?? idx;
12440
+ acc[propName] = responseParser(responseIterator, output2, this.structs, acc);
12441
+ if (acc[propName] && acc[`${propName}_len`]) {
12442
+ delete acc[`${propName}_len`];
12282
12443
  }
12283
12444
  return acc;
12284
12445
  }, {});
12446
+ return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
12285
12447
  }
12286
12448
  format(method, response, format) {
12287
12449
  const parsed = this.parse(method, response);
@@ -12353,13 +12515,20 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12353
12515
  return contract.estimate(functionAbi.name, args);
12354
12516
  };
12355
12517
  }
12518
+ var detectCairoVersion = (abi) => {
12519
+ if (!abi)
12520
+ return "0";
12521
+ return abi.find((it) => "state_mutability" in it) ? "1" : "0";
12522
+ };
12356
12523
  var Contract = class {
12357
- constructor(abi, address, providerOrAccount = defaultProvider) {
12524
+ constructor(abi, address, providerOrAccount = defaultProvider, cairoVersion = detectCairoVersion(abi)) {
12525
+ this.version = "0";
12358
12526
  this.address = address && address.toLowerCase();
12359
12527
  this.providerOrAccount = providerOrAccount;
12360
12528
  this.callData = new CallData(abi);
12361
12529
  this.structs = CallData.getAbiStruct(abi);
12362
12530
  this.abi = abi;
12531
+ this.version = cairoVersion;
12363
12532
  const options = { enumerable: true, value: {}, writable: false };
12364
12533
  Object.defineProperties(this, {
12365
12534
  functions: { enumerable: true, value: {}, writable: false },
@@ -12417,11 +12586,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12417
12586
  return this;
12418
12587
  }
12419
12588
  async call(method, args = [], options = { parseRequest: true, parseResponse: true, formatResponse: void 0 }) {
12420
- var _a;
12421
12589
  assert2(this.address !== null, "contract is not connected to an address");
12422
12590
  const blockIdentifier = (options == null ? void 0 : options.blockIdentifier) || void 0;
12423
- let calldata = args[0];
12424
- if (options.parseRequest && !((_a = args[0]) == null ? void 0 : _a.compiled)) {
12591
+ let calldata = "compiled" in args ? args : args[0];
12592
+ if (options.parseRequest && !(calldata == null ? void 0 : calldata.compiled)) {
12425
12593
  const { inputs } = this.abi.find((abi) => abi.name === method);
12426
12594
  this.callData.validate("CALL", method, args);
12427
12595
  calldata = this.callData.compile(args, inputs);
@@ -12447,7 +12615,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12447
12615
  parseRequest: true
12448
12616
  }) {
12449
12617
  assert2(this.address !== null, "contract is not connected to an address");
12450
- let calldata = args == null ? void 0 : args[0];
12618
+ let calldata = "compiled" in args ? args : args[0];
12451
12619
  if (options.parseRequest && !(calldata == null ? void 0 : calldata.compiled)) {
12452
12620
  const { inputs } = this.abi.find((abi) => abi.name === method);
12453
12621
  this.callData.validate("INVOKE", method, args);