starknet 5.28.0 → 5.29.0

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,9 @@
1
+ # [5.29.0](https://github.com/starknet-io/starknet.js/compare/v5.28.0...v5.29.0) (2024-02-02)
2
+
3
+ ### Features
4
+
5
+ - add provider.decodeParameters ([39595f3](https://github.com/starknet-io/starknet.js/commit/39595f3303204b273fadd53764c59767ce6c5b36))
6
+
1
7
  # [5.28.0](https://github.com/starknet-io/starknet.js/compare/v5.27.0...v5.28.0) (2024-02-01)
2
8
 
3
9
  ### Features
package/dist/index.d.ts CHANGED
@@ -143,15 +143,15 @@ declare enum NetworkName {
143
143
  SN_SEPOLIA = "SN_SEPOLIA"
144
144
  }
145
145
  declare enum StarknetChainId {
146
- SN_MAIN = "0x534e5f4d41494e",
147
- SN_GOERLI = "0x534e5f474f45524c49",
146
+ SN_MAIN = "0x534e5f4d41494e",// encodeShortString('SN_MAIN'),
147
+ SN_GOERLI = "0x534e5f474f45524c49",// encodeShortString('SN_GOERLI')
148
148
  SN_SEPOLIA = "0x534e5f5345504f4c4941"
149
149
  }
150
150
  declare enum TransactionHashPrefix {
151
- DECLARE = "0x6465636c617265",
152
- DEPLOY = "0x6465706c6f79",
153
- DEPLOY_ACCOUNT = "0x6465706c6f795f6163636f756e74",
154
- INVOKE = "0x696e766f6b65",
151
+ DECLARE = "0x6465636c617265",// encodeShortString('declare'),
152
+ DEPLOY = "0x6465706c6f79",// encodeShortString('deploy'),
153
+ DEPLOY_ACCOUNT = "0x6465706c6f795f6163636f756e74",// encodeShortString('deploy_account'),
154
+ INVOKE = "0x696e766f6b65",// encodeShortString('invoke'),
155
155
  L1_HANDLER = "0x6c315f68616e646c6572"
156
156
  }
157
157
  declare const UDC: {
@@ -5404,6 +5404,17 @@ declare class CallData {
5404
5404
  * @returns HexCalldata
5405
5405
  */
5406
5406
  static toHex(raw?: RawArgs): HexCalldata;
5407
+ /**
5408
+ * Parse the elements of a contract response and structure them into one or several Result.
5409
+ * In Cairo 0, arrays are not supported.
5410
+ * @param typeCairo string or string[] - Cairo type name, ex : "hello::hello::UserData"
5411
+ * @param response string[] - serialized data corresponding to typeCairo.
5412
+ * @return Result or Result[] - parsed response corresponding to typeData.
5413
+ * @example
5414
+ * const res2=helloCallData.decodeParameters("hello::hello::UserData",["0x123456","0x1"]);
5415
+ * result = { address: 1193046n, is_claimed: true }
5416
+ */
5417
+ decodeParameters(typeCairo: AllowArray<string>, response: string[]): AllowArray<Result>;
5407
5418
  }
5408
5419
 
5409
5420
  declare function isSierra(contract: CairoContract | string): contract is SierraContractClass | CompiledSierra;
@@ -5366,6 +5366,29 @@ var starknet = (() => {
5366
5366
  const calldata = CallData.compile(raw);
5367
5367
  return calldata.map((it) => toHex(it));
5368
5368
  }
5369
+ /**
5370
+ * Parse the elements of a contract response and structure them into one or several Result.
5371
+ * In Cairo 0, arrays are not supported.
5372
+ * @param typeCairo string or string[] - Cairo type name, ex : "hello::hello::UserData"
5373
+ * @param response string[] - serialized data corresponding to typeCairo.
5374
+ * @return Result or Result[] - parsed response corresponding to typeData.
5375
+ * @example
5376
+ * const res2=helloCallData.decodeParameters("hello::hello::UserData",["0x123456","0x1"]);
5377
+ * result = { address: 1193046n, is_claimed: true }
5378
+ */
5379
+ decodeParameters(typeCairo, response) {
5380
+ const typeCairoArray = Array.isArray(typeCairo) ? typeCairo : [typeCairo];
5381
+ const responseIterator = response.flat()[Symbol.iterator]();
5382
+ const decodedArray = typeCairoArray.map(
5383
+ (typeParam) => responseParser(
5384
+ responseIterator,
5385
+ { name: "", type: typeParam },
5386
+ this.structs,
5387
+ this.enums
5388
+ )
5389
+ );
5390
+ return decodedArray.length === 1 ? decodedArray[0] : decodedArray;
5391
+ }
5369
5392
  };
5370
5393
 
5371
5394
  // src/utils/hash.ts