starknet 5.6.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,10 @@
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
+
1
8
  # [5.6.0](https://github.com/0xs34n/starknet.js/compare/v5.5.0...v5.6.0) (2023-04-19)
2
9
 
3
10
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -3121,6 +3121,7 @@ declare const isTypeTuple: (type: string) => boolean;
3121
3121
  declare const isTypeNamedTuple: (type: string) => boolean;
3122
3122
  declare const isTypeStruct: (type: string, structs: AbiStructs) => boolean;
3123
3123
  declare const isTypeUint: (type: string) => boolean;
3124
+ declare const isTypeUint256: (type: string) => boolean;
3124
3125
  declare const isTypeBool: (type: string) => boolean;
3125
3126
  declare const isTypeContractAddress: (type: string) => boolean;
3126
3127
  declare const isCairo1Type: (type: string) => boolean;
@@ -3206,6 +3207,7 @@ declare const cairo_isTypeTuple: typeof isTypeTuple;
3206
3207
  declare const cairo_isTypeNamedTuple: typeof isTypeNamedTuple;
3207
3208
  declare const cairo_isTypeStruct: typeof isTypeStruct;
3208
3209
  declare const cairo_isTypeUint: typeof isTypeUint;
3210
+ declare const cairo_isTypeUint256: typeof isTypeUint256;
3209
3211
  declare const cairo_isTypeBool: typeof isTypeBool;
3210
3212
  declare const cairo_isTypeContractAddress: typeof isTypeContractAddress;
3211
3213
  declare const cairo_isCairo1Type: typeof isCairo1Type;
@@ -3223,6 +3225,7 @@ declare namespace cairo {
3223
3225
  cairo_isTypeNamedTuple as isTypeNamedTuple,
3224
3226
  cairo_isTypeStruct as isTypeStruct,
3225
3227
  cairo_isTypeUint as isTypeUint,
3228
+ cairo_isTypeUint256 as isTypeUint256,
3226
3229
  cairo_isTypeBool as isTypeBool,
3227
3230
  cairo_isTypeContractAddress as isTypeContractAddress,
3228
3231
  cairo_isCairo1Type as isCairo1Type,
@@ -5326,6 +5326,7 @@ var starknet = (() => {
5326
5326
  isTypeStruct: () => isTypeStruct,
5327
5327
  isTypeTuple: () => isTypeTuple,
5328
5328
  isTypeUint: () => isTypeUint,
5329
+ isTypeUint256: () => isTypeUint256,
5329
5330
  tuple: () => tuple,
5330
5331
  uint256: () => uint256
5331
5332
  });
@@ -5520,6 +5521,7 @@ var starknet = (() => {
5520
5521
  var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
5521
5522
  var isTypeStruct = (type, structs) => type in structs;
5522
5523
  var isTypeUint = (type) => Object.values(Uint).includes(type);
5524
+ var isTypeUint256 = (type) => type === "core::integer::u256";
5523
5525
  var isTypeBool = (type) => type === "core::bool";
5524
5526
  var isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
5525
5527
  var isCairo1Type = (type) => type.includes("core::");
@@ -11527,10 +11529,11 @@ var starknet = (() => {
11527
11529
  const url = buildUrl(this.baseUrl, "", endpoint);
11528
11530
  const method = (options == null ? void 0 : options.method) ?? "GET";
11529
11531
  const headers = this.getHeaders(method);
11532
+ const body = stringify2(options == null ? void 0 : options.body);
11530
11533
  try {
11531
11534
  const response = await fetchPonyfill_default(url, {
11532
11535
  method,
11533
- body: stringify2(options == null ? void 0 : options.body),
11536
+ body,
11534
11537
  headers
11535
11538
  });
11536
11539
  const textResponse = await response.text();
@@ -12096,6 +12099,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12096
12099
  if (Array.isArray(element)) {
12097
12100
  throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
12098
12101
  }
12102
+ if (isTypeUint256(type)) {
12103
+ const el_uint256 = uint256(element);
12104
+ return [felt(el_uint256.low), felt(el_uint256.high)];
12105
+ }
12099
12106
  if (structs[type] && structs[type].members.length) {
12100
12107
  const { members } = structs[type];
12101
12108
  const subElement = element;
@@ -12139,10 +12146,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12139
12146
  }
12140
12147
  return acc;
12141
12148
  }, result);
12142
- case (isTypeStruct(type, structs) || isTypeTuple(type)):
12149
+ case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
12143
12150
  return parseCalldataValue(value, type, structs);
12144
12151
  case isTypeBool(type):
12145
- return value;
12152
+ return `${+value}`;
12146
12153
  default:
12147
12154
  return felt(value);
12148
12155
  }
@@ -12178,6 +12185,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12178
12185
  case isTypeBool(type):
12179
12186
  temp = responseIterator.next().value;
12180
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 });
12181
12192
  case isTypeArray(type):
12182
12193
  const parsedDataArr = [];
12183
12194
  if (isCairo1Type(type)) {
@@ -12575,11 +12586,10 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12575
12586
  return this;
12576
12587
  }
12577
12588
  async call(method, args = [], options = { parseRequest: true, parseResponse: true, formatResponse: void 0 }) {
12578
- var _a;
12579
12589
  assert2(this.address !== null, "contract is not connected to an address");
12580
12590
  const blockIdentifier = (options == null ? void 0 : options.blockIdentifier) || void 0;
12581
- let calldata = args[0];
12582
- 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)) {
12583
12593
  const { inputs } = this.abi.find((abi) => abi.name === method);
12584
12594
  this.callData.validate("CALL", method, args);
12585
12595
  calldata = this.callData.compile(args, inputs);
@@ -12605,7 +12615,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12605
12615
  parseRequest: true
12606
12616
  }) {
12607
12617
  assert2(this.address !== null, "contract is not connected to an address");
12608
- let calldata = args == null ? void 0 : args[0];
12618
+ let calldata = "compiled" in args ? args : args[0];
12609
12619
  if (options.parseRequest && !(calldata == null ? void 0 : calldata.compiled)) {
12610
12620
  const { inputs } = this.abi.find((abi) => abi.name === method);
12611
12621
  this.callData.validate("INVOKE", method, args);