starknet 5.4.1 → 5.5.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,19 @@
1
+ # [5.5.0](https://github.com/0xs34n/starknet.js/compare/v5.4.2...v5.5.0) (2023-04-10)
2
+
3
+ ### Bug Fixes
4
+
5
+ - update DeclareAndDeploy with cairo 1 declare ([71072cf](https://github.com/0xs34n/starknet.js/commit/71072cffadb8ac118780cec21cb8c4f83e74d7ae))
6
+
7
+ ### Features
8
+
9
+ - response parsing and types ([09a46af](https://github.com/0xs34n/starknet.js/commit/09a46af02e88376dc49e0aa39468fded99b94ee2))
10
+
11
+ ## [5.4.2](https://github.com/0xs34n/starknet.js/compare/v5.4.1...v5.4.2) (2023-04-04)
12
+
13
+ ### Bug Fixes
14
+
15
+ - implement custom ts error localy ([fa90a3e](https://github.com/0xs34n/starknet.js/commit/fa90a3e7dcbe8c0952b0681be903dffb4b4c74c6))
16
+
1
17
  ## [5.4.1](https://github.com/0xs34n/starknet.js/compare/v5.4.0...v5.4.1) (2023-04-03)
2
18
 
3
19
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as _noble_curves_abstract_weierstrass from '@noble/curves/abstract/weierstrass';
2
2
  import * as poseidon from '@noble/curves/abstract/poseidon';
3
3
  import * as microStarknet from 'micro-starknet';
4
- import { CustomError } from 'ts-custom-error/dist/custom-error';
5
4
 
6
5
  declare const IS_BROWSER: boolean;
7
6
  declare function arrayBufferToString(array: ArrayBuffer): string;
@@ -223,6 +222,7 @@ declare type FunctionAbi = {
223
222
  name: string;
224
223
  outputs: AbiEntry[];
225
224
  stateMutability?: 'view';
225
+ state_mutability?: string;
226
226
  type: FunctionAbiType;
227
227
  };
228
228
  declare type AbiStructs = {
@@ -270,7 +270,8 @@ declare type CairoAssembly = {
270
270
  prime: string;
271
271
  compiler_version: string;
272
272
  bytecode: ByteCode;
273
- hints: Hints;
273
+ hints: any[];
274
+ pythonic_hints: PythonicHints;
274
275
  entry_points_by_type: EntryPointsByType;
275
276
  };
276
277
  declare type SierraContractClass = {
@@ -285,7 +286,7 @@ declare type CompiledSierra = SierraContractClass;
285
286
  declare type CompiledSierraCasm = CairoAssembly;
286
287
  /** SUBTYPES */
287
288
  declare type ByteCode = string[];
288
- declare type Hints = [number, string[]][];
289
+ declare type PythonicHints = [number, string[]][];
289
290
  declare type SierraProgramDebugInfo = {
290
291
  type_names: [number, string][];
291
292
  libfunc_names: [number, string][];
@@ -1893,7 +1894,9 @@ declare abstract class ProviderInterface {
1893
1894
  /**
1894
1895
  * Wait for the transaction to be accepted
1895
1896
  * @param txHash - transaction hash
1896
- * @param retryInterval - retry interval
1897
+ * @param options
1898
+ * - (optional) retryInterval: number | undefined;
1899
+ * - (optional) successStates: TransactionStatus[] | undefined;
1897
1900
  * @return GetTransactionReceiptResponse
1898
1901
  */
1899
1902
  abstract waitForTransaction(txHash: BigNumberish, options?: waitForTransactionOptions): Promise<GetTransactionReceiptResponse>;
@@ -2123,6 +2126,12 @@ declare class Provider implements ProviderInterface {
2123
2126
  getAddressFromStarkName(name: string, StarknetIdContract?: string): Promise<string>;
2124
2127
  }
2125
2128
 
2129
+ declare function fixStack(target: Error, fn?: Function): void;
2130
+ declare function fixProto(target: Error, prototype: {}): void;
2131
+ declare class CustomError extends Error {
2132
+ name: string;
2133
+ constructor(message?: string);
2134
+ }
2126
2135
  declare class LibraryError extends CustomError {
2127
2136
  }
2128
2137
  declare class GatewayError extends LibraryError {
@@ -3147,4 +3156,4 @@ declare class CallData {
3147
3156
  /** @deprecated prefer the 'num' naming */
3148
3157
  declare const number: typeof num;
3149
3158
 
3150
- 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, 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, Hints, HttpError, Invocation, InvocationBulk, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeTransactionReceiptResponse, InvokeTransactionResponse, LegacyCompiledContract, LegacyContractClass, LibraryError, MessageToL1, MessageToL2, MultiDeployContractResponse, Nonce, Overrides, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, 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, getChecksumAddress, hash, isUrl, json, merkle, num, number, shortString, stark, transaction, index as typedData, uint256, validateAndParseAddress, validateChecksumAddress, waitForTransactionOptions };
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 };
@@ -540,108 +540,6 @@ var starknet = (() => {
540
540
  }
541
541
  });
542
542
 
543
- // node_modules/ts-custom-error/dist/custom-error.js
544
- var require_custom_error = __commonJS({
545
- "node_modules/ts-custom-error/dist/custom-error.js"(exports) {
546
- function fixProto(target, prototype) {
547
- var setPrototypeOf = Object.setPrototypeOf;
548
- setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
549
- }
550
- function fixStack(target, fn) {
551
- if (fn === void 0) {
552
- fn = target.constructor;
553
- }
554
- var captureStackTrace = Error.captureStackTrace;
555
- captureStackTrace && captureStackTrace(target, fn);
556
- }
557
- var __extends = function() {
558
- var _extendStatics = function extendStatics(d, b) {
559
- _extendStatics = Object.setPrototypeOf || {
560
- __proto__: []
561
- } instanceof Array && function(d2, b2) {
562
- d2.__proto__ = b2;
563
- } || function(d2, b2) {
564
- for (var p in b2) {
565
- if (Object.prototype.hasOwnProperty.call(b2, p))
566
- d2[p] = b2[p];
567
- }
568
- };
569
- return _extendStatics(d, b);
570
- };
571
- return function(d, b) {
572
- if (typeof b !== "function" && b !== null)
573
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
574
- _extendStatics(d, b);
575
- function __() {
576
- this.constructor = d;
577
- }
578
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
579
- };
580
- }();
581
- var CustomError2 = function(_super) {
582
- __extends(CustomError3, _super);
583
- function CustomError3(message, options) {
584
- var _newTarget = this.constructor;
585
- var _this = _super.call(this, message, options) || this;
586
- Object.defineProperty(_this, "name", {
587
- value: _newTarget.name,
588
- enumerable: false,
589
- configurable: true
590
- });
591
- fixProto(_this, _newTarget.prototype);
592
- fixStack(_this);
593
- return _this;
594
- }
595
- return CustomError3;
596
- }(Error);
597
- var __spreadArray = function(to, from, pack) {
598
- if (pack || arguments.length === 2)
599
- for (var i = 0, l = from.length, ar; i < l; i++) {
600
- if (ar || !(i in from)) {
601
- if (!ar)
602
- ar = Array.prototype.slice.call(from, 0, i);
603
- ar[i] = from[i];
604
- }
605
- }
606
- return to.concat(ar || Array.prototype.slice.call(from));
607
- };
608
- function customErrorFactory(fn, parent) {
609
- if (parent === void 0) {
610
- parent = Error;
611
- }
612
- function CustomError3() {
613
- var args = [];
614
- for (var _i = 0; _i < arguments.length; _i++) {
615
- args[_i] = arguments[_i];
616
- }
617
- if (!(this instanceof CustomError3))
618
- return new (CustomError3.bind.apply(CustomError3, __spreadArray([void 0], args, false)))();
619
- parent.apply(this, args);
620
- Object.defineProperty(this, "name", {
621
- value: fn.name || parent.name,
622
- enumerable: false,
623
- configurable: true
624
- });
625
- fn.apply(this, args);
626
- fixStack(this, CustomError3);
627
- }
628
- return Object.defineProperties(CustomError3, {
629
- prototype: {
630
- value: Object.create(parent.prototype, {
631
- constructor: {
632
- value: CustomError3,
633
- writable: true,
634
- configurable: true
635
- }
636
- })
637
- }
638
- });
639
- }
640
- exports.CustomError = CustomError2;
641
- exports.customErrorFactory = customErrorFactory;
642
- }
643
- });
644
-
645
543
  // node_modules/url-join/lib/url-join.js
646
544
  var require_url_join = __commonJS({
647
545
  "node_modules/url-join/lib/url-join.js"(exports, module) {
@@ -716,6 +614,7 @@ var starknet = (() => {
716
614
  Contract: () => Contract,
717
615
  ContractFactory: () => ContractFactory,
718
616
  ContractInterface: () => ContractInterface,
617
+ CustomError: () => CustomError,
719
618
  EntryPointType: () => EntryPointType,
720
619
  GatewayError: () => GatewayError,
721
620
  HttpError: () => HttpError,
@@ -735,6 +634,8 @@ var starknet = (() => {
735
634
  defaultProvider: () => defaultProvider,
736
635
  ec: () => ec_exports,
737
636
  encode: () => encode_exports,
637
+ fixProto: () => fixProto,
638
+ fixStack: () => fixStack,
738
639
  getChecksumAddress: () => getChecksumAddress,
739
640
  hash: () => hash_exports,
740
641
  isUrl: () => isUrl,
@@ -10746,8 +10647,27 @@ var starknet = (() => {
10746
10647
  };
10747
10648
 
10748
10649
  // src/provider/errors.ts
10749
- var import_custom_error = __toESM(require_custom_error());
10750
- var LibraryError = class extends import_custom_error.CustomError {
10650
+ function fixStack(target, fn = target.constructor) {
10651
+ const { captureStackTrace } = Error;
10652
+ captureStackTrace && captureStackTrace(target, fn);
10653
+ }
10654
+ function fixProto(target, prototype) {
10655
+ const { setPrototypeOf } = Object;
10656
+ setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
10657
+ }
10658
+ var CustomError = class extends Error {
10659
+ constructor(message) {
10660
+ super(message);
10661
+ Object.defineProperty(this, "name", {
10662
+ value: new.target.name,
10663
+ enumerable: false,
10664
+ configurable: true
10665
+ });
10666
+ fixProto(this, new.target.prototype);
10667
+ fixStack(this);
10668
+ }
10669
+ };
10670
+ var LibraryError = class extends CustomError {
10751
10671
  };
10752
10672
  var GatewayError = class extends LibraryError {
10753
10673
  constructor(message, errorCode) {
@@ -11415,6 +11335,12 @@ var starknet = (() => {
11415
11335
  }
11416
11336
  };
11417
11337
  }
11338
+ parseSierraContractClassResponse(res) {
11339
+ return {
11340
+ ...res,
11341
+ abi: JSON.parse(res.abi)
11342
+ };
11343
+ }
11418
11344
  };
11419
11345
 
11420
11346
  // src/utils/url.ts
@@ -11622,16 +11548,24 @@ var starknet = (() => {
11622
11548
  }
11623
11549
  async getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
11624
11550
  return this.fetchEndpoint("get_full_contract", { blockIdentifier, contractAddress }).then(
11625
- parseContract
11551
+ (res) => {
11552
+ if (isSierra(res)) {
11553
+ return this.responseParser.parseSierraContractClassResponse(res);
11554
+ }
11555
+ return parseContract(res);
11556
+ }
11626
11557
  );
11627
11558
  }
11628
11559
  async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
11629
11560
  return this.fetchEndpoint("get_class_hash_at", { blockIdentifier, contractAddress });
11630
11561
  }
11631
11562
  async getClassByHash(classHash, blockIdentifier = this.blockIdentifier) {
11632
- return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then(
11633
- parseContract
11634
- );
11563
+ return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then((res) => {
11564
+ if (isSierra(res)) {
11565
+ return this.responseParser.parseSierraContractClassResponse(res);
11566
+ }
11567
+ return parseContract(res);
11568
+ });
11635
11569
  }
11636
11570
  async getCompiledClassByClassHash(classHash, blockIdentifier = this.blockIdentifier) {
11637
11571
  return this.fetchEndpoint("get_compiled_class_by_class_hash", { classHash, blockIdentifier });
@@ -12282,7 +12216,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12282
12216
  const invocableFunctionNames = this.abi.filter((abi) => {
12283
12217
  if (abi.type !== "function")
12284
12218
  return false;
12285
- const isView = abi.stateMutability === "view";
12219
+ const isView = abi.stateMutability === "view" || abi.state_mutability === "view";
12286
12220
  return type === "INVOKE" ? !isView : isView;
12287
12221
  }).map((abi) => abi.name);
12288
12222
  assert2(
@@ -12404,7 +12338,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
12404
12338
  };
12405
12339
  }
12406
12340
  function buildDefault(contract, functionAbi) {
12407
- if (functionAbi.stateMutability === "view") {
12341
+ if (functionAbi.stateMutability === "view" || functionAbi.state_mutability === "view") {
12408
12342
  return buildCall(contract, functionAbi);
12409
12343
  }
12410
12344
  return buildInvoke(contract, functionAbi);
@@ -13274,8 +13208,8 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
13274
13208
  return parseUDCEvent(txReceipt);
13275
13209
  }
13276
13210
  async declareAndDeploy(payload, details) {
13277
- const { contract, constructorCalldata, salt, unique } = payload;
13278
- const { transaction_hash, class_hash } = await this.declare({ contract }, details);
13211
+ const { constructorCalldata, salt, unique } = payload;
13212
+ const { transaction_hash, class_hash } = await this.declare(payload, details);
13279
13213
  const declare = await this.waitForTransaction(transaction_hash, {
13280
13214
  successStates: ["ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */]
13281
13215
  });