starknet 5.14.0 → 5.14.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.14.1](https://github.com/0xs34n/starknet.js/compare/v5.14.0...v5.14.1) (2023-06-26)
2
+
3
+ ### Bug Fixes
4
+
5
+ - export utils provider,selector, contract, events. Simulate dev import on tests ([00b7bdf](https://github.com/0xs34n/starknet.js/commit/00b7bdf756c516a1905ce1ecc9036472800989af))
6
+ - redeclare contract ([10da77e](https://github.com/0xs34n/starknet.js/commit/10da77efc6a5e1896af089508e4c403726e9cbf4))
7
+
1
8
  # [5.14.0](https://github.com/0xs34n/starknet.js/compare/v5.13.2...v5.14.0) (2023-06-21)
2
9
 
3
10
  ### Features
package/dist/index.d.ts CHANGED
@@ -228,7 +228,7 @@ type CairoAssembly = {
228
228
  */
229
229
  type CompiledSierra = {
230
230
  sierra_program: ByteCode;
231
- sierra_program_debug_info: SierraProgramDebugInfo;
231
+ sierra_program_debug_info?: SierraProgramDebugInfo;
232
232
  contract_class_version: string;
233
233
  entry_points_by_type: SierraEntryPointsByType;
234
234
  abi: Abi;
@@ -269,6 +269,9 @@ type ContractClass = LegacyContractClass | SierraContractClass;
269
269
  * format produced after compile .cairo to .json
270
270
  */
271
271
  type CompiledContract = LegacyCompiledContract | CompiledSierra;
272
+ /**
273
+ * Compressed or decompressed Cairo0 or Cairo1 Contract
274
+ */
272
275
  type CairoContract = ContractClass | CompiledContract;
273
276
  declare enum EntryPointType {
274
277
  EXTERNAL = "EXTERNAL",
@@ -1738,9 +1741,13 @@ interface StateUpdateResponse {
1738
1741
  deprecated_declared_classes?: RPC.DeprecatedDeclaredClasses;
1739
1742
  };
1740
1743
  }
1741
- type ContractClassResponse = Omit<ContractClass, 'abi'> & {
1742
- abi?: Abi;
1743
- };
1744
+ /**
1745
+ * Standardized type
1746
+ * Cairo0 program compressed and Cairo1 sierra_program decompressed
1747
+ * abi Abi
1748
+ * CompiledSierra without '.sierra_program_debug_info'
1749
+ */
1750
+ type ContractClassResponse = LegacyContractClass | Omit<CompiledSierra, 'sierra_program_debug_info'>;
1744
1751
 
1745
1752
  interface EstimateFee extends EstimateFeeResponse {
1746
1753
  suggestedMaxFee: bigint;
@@ -3140,6 +3147,19 @@ declare function getSelectorFromName(funcName: string): string;
3140
3147
  */
3141
3148
  declare function getSelector(value: string): string;
3142
3149
 
3150
+ declare const selector_getSelector: typeof getSelector;
3151
+ declare const selector_getSelectorFromName: typeof getSelectorFromName;
3152
+ declare const selector_keccakBn: typeof keccakBn;
3153
+ declare const selector_starknetKeccak: typeof starknetKeccak;
3154
+ declare namespace selector {
3155
+ export {
3156
+ selector_getSelector as getSelector,
3157
+ selector_getSelectorFromName as getSelectorFromName,
3158
+ selector_keccakBn as keccakBn,
3159
+ selector_starknetKeccak as starknetKeccak,
3160
+ };
3161
+ }
3162
+
3143
3163
  declare const transactionVersion = 1n;
3144
3164
  declare const transactionVersion_2 = 2n;
3145
3165
  declare const feeTransactionVersion: bigint;
@@ -3643,6 +3663,21 @@ declare namespace starknetId {
3643
3663
  };
3644
3664
  }
3645
3665
 
3666
+ declare function wait(delay: number): Promise<unknown>;
3667
+ declare function createSierraContractClass(contract: CompiledSierra): SierraContractClass;
3668
+ declare function parseContract(contract: CompiledContract | string): ContractClass;
3669
+
3670
+ declare const provider_createSierraContractClass: typeof createSierraContractClass;
3671
+ declare const provider_parseContract: typeof parseContract;
3672
+ declare const provider_wait: typeof wait;
3673
+ declare namespace provider {
3674
+ export {
3675
+ provider_createSierraContractClass as createSierraContractClass,
3676
+ provider_parseContract as parseContract,
3677
+ provider_wait as wait,
3678
+ };
3679
+ }
3680
+
3646
3681
  declare function addAddressPadding(address: BigNumberish): string;
3647
3682
  declare function validateAndParseAddress(address: BigNumberish): string;
3648
3683
  declare function getChecksumAddress(address: BigNumberish): string;
@@ -3818,6 +3853,34 @@ declare class CallData {
3818
3853
  static toHex(raw?: RawArgs): HexCalldata;
3819
3854
  }
3820
3855
 
3856
+ declare function isSierra(contract: CairoContract | string): contract is SierraContractClass | CompiledSierra;
3857
+ declare function extractContractHashes(payload: DeclareContractPayload): CompleteDeclareContractPayload;
3858
+ /**
3859
+ * Helper to redeclare response Cairo0 contract
3860
+ * @param ccr ContractClassResponse
3861
+ * @returns LegacyCompiledContract
3862
+ */
3863
+ declare function contractClassResponseToLegacyCompiledContract(ccr: ContractClassResponse): LegacyCompiledContract;
3864
+
3865
+ /**
3866
+ * Parse Transaction Receipt Event from UDC invoke transaction and
3867
+ * create DeployContractResponse compatibile response with adition of UDC Event data
3868
+ *
3869
+ * @param txReceipt
3870
+ * @returns DeployContractResponse | UDC Event Response data
3871
+ */
3872
+ declare function parseUDCEvent(txReceipt: InvokeTransactionReceiptResponse): {
3873
+ transaction_hash: string;
3874
+ contract_address: string;
3875
+ address: string;
3876
+ deployer: string;
3877
+ unique: string;
3878
+ classHash: string;
3879
+ calldata_len: string;
3880
+ calldata: string[];
3881
+ salt: string;
3882
+ };
3883
+
3821
3884
  /**
3822
3885
  * Main
3823
3886
  */
@@ -3825,4 +3888,4 @@ declare class CallData {
3825
3888
  /** @deprecated prefer the 'num' naming */
3826
3889
  declare const number: typeof num;
3827
3890
 
3828
- export { Abi, AbiEntry, AbiStructs, Account, AccountInterface, AccountInvocationItem, AccountInvocations, AccountInvocationsFactoryDetails, AllowArray, Args, ArgsOrCalldata, ArgsOrCalldataWithOptions, ArraySignatureType, AsyncContractFunction, BigNumberish, BlockIdentifier, BlockNumber, BlockTag, Builtins, ByteCode, CairoAssembly, CairoContract, CairoVersion, Call, CallContractResponse, CallData, CallDetails, CallL1Handler, CallOptions, CallStruct, Calldata, CommonTransactionReceiptResponse, CommonTransactionResponse, CompiledContract, CompiledSierra, CompiledSierraCasm, CompleteDeclareContractPayload, CompressedProgram, Contract, ContractClass, ContractClassResponse, ContractEntryPoint, ContractEntryPointFields, ContractFactory, ContractFunction, ContractInterface, ContractOptions, 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, HexCalldata, HttpError, Invocation, Invocations, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeOptions, InvokeTransactionReceiptResponse, InvokeTransactionResponse, LegacyCompiledContract, LegacyContractClass, LibraryError, MessageToL1, MessageToL2, MultiDeployContractResponse, MultiType, Nonce, OptionalPayload, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, PythonicHints, RPC, RawArgs, RawArgsArray, RawArgsObject, RawCalldata, Result, RpcProvider, RpcProviderOptions, SIMULATION_FLAG, Sequencer, SequencerHttpMethod, SequencerIdentifier, SequencerProvider, SequencerProviderOptions, SierraContractClass, SierraContractEntryPointFields, SierraEntryPointsByType, SierraProgramDebugInfo, Signature, Signer, SignerInterface, SimulateTransactionDetails, SimulateTransactionResponse, SimulatedTransaction, SimulationFlags, StarkNetDomain, StarkNetMerkleType, StarkNetType, StateUpdateResponse, Status, Storage, Struct, StructAbi, TransactionStatus, TransactionType, Tupled, TypedData, Uint256, UniversalDeployerContractPayload, WeierstrassSignatureType, addAddressPadding, buildUrl, cairo, constants, defaultProvider, ec, encode, fixProto, fixStack, getCalldata, getChecksumAddress, getEstimateFeeBulkOptions, getSimulateTransactionOptions, hash, isUrl, json, merkle, num, number, shortString, splitArgsAndOptions, stark, starknetId, transaction, typedData, index as types, uint256$1 as uint256, validateAndParseAddress, validateChecksumAddress, waitForTransactionOptions };
3891
+ export { Abi, AbiEntry, AbiStructs, Account, AccountInterface, AccountInvocationItem, AccountInvocations, AccountInvocationsFactoryDetails, AllowArray, Args, ArgsOrCalldata, ArgsOrCalldataWithOptions, ArraySignatureType, AsyncContractFunction, BigNumberish, BlockIdentifier, BlockNumber, BlockTag, Builtins, ByteCode, CairoAssembly, CairoContract, CairoVersion, Call, CallContractResponse, CallData, CallDetails, CallL1Handler, CallOptions, CallStruct, Calldata, CommonTransactionReceiptResponse, CommonTransactionResponse, CompiledContract, CompiledSierra, CompiledSierraCasm, CompleteDeclareContractPayload, CompressedProgram, Contract, ContractClass, ContractClassResponse, ContractEntryPoint, ContractEntryPointFields, ContractFactory, ContractFunction, ContractInterface, ContractOptions, 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, HexCalldata, HttpError, Invocation, Invocations, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeOptions, InvokeTransactionReceiptResponse, InvokeTransactionResponse, LegacyCompiledContract, LegacyContractClass, LibraryError, MessageToL1, MessageToL2, MultiDeployContractResponse, MultiType, Nonce, OptionalPayload, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, PythonicHints, RPC, RawArgs, RawArgsArray, RawArgsObject, RawCalldata, Result, RpcProvider, RpcProviderOptions, SIMULATION_FLAG, Sequencer, SequencerHttpMethod, SequencerIdentifier, SequencerProvider, SequencerProviderOptions, SierraContractClass, SierraContractEntryPointFields, SierraEntryPointsByType, SierraProgramDebugInfo, Signature, Signer, SignerInterface, SimulateTransactionDetails, SimulateTransactionResponse, SimulatedTransaction, SimulationFlags, StarkNetDomain, StarkNetMerkleType, StarkNetType, StateUpdateResponse, Status, Storage, Struct, StructAbi, TransactionStatus, TransactionType, Tupled, TypedData, Uint256, UniversalDeployerContractPayload, WeierstrassSignatureType, addAddressPadding, buildUrl, cairo, constants, contractClassResponseToLegacyCompiledContract, defaultProvider, ec, encode, extractContractHashes, fixProto, fixStack, getCalldata, getChecksumAddress, getEstimateFeeBulkOptions, getSimulateTransactionOptions, hash, isSierra, isUrl, json, merkle, num, number, parseUDCEvent, provider, selector, shortString, splitArgsAndOptions, stark, starknetId, transaction, typedData, index as types, uint256$1 as uint256, validateAndParseAddress, validateChecksumAddress, waitForTransactionOptions };
@@ -637,19 +637,25 @@ var starknet = (() => {
637
637
  buildUrl: () => buildUrl,
638
638
  cairo: () => cairo_exports,
639
639
  constants: () => constants_exports,
640
+ contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
640
641
  defaultProvider: () => defaultProvider,
641
642
  ec: () => ec_exports,
642
643
  encode: () => encode_exports,
644
+ extractContractHashes: () => extractContractHashes,
643
645
  fixProto: () => fixProto,
644
646
  fixStack: () => fixStack,
645
647
  getCalldata: () => getCalldata,
646
648
  getChecksumAddress: () => getChecksumAddress,
647
649
  hash: () => hash_exports,
650
+ isSierra: () => isSierra,
648
651
  isUrl: () => isUrl,
649
652
  json: () => json_exports,
650
653
  merkle: () => merkle_exports,
651
654
  num: () => num_exports,
652
655
  number: () => number2,
656
+ parseUDCEvent: () => parseUDCEvent,
657
+ provider: () => provider_exports,
658
+ selector: () => selector_exports,
653
659
  shortString: () => shortString_exports,
654
660
  splitArgsAndOptions: () => splitArgsAndOptions,
655
661
  stark: () => stark_exports,
@@ -3185,6 +3191,15 @@ var starknet = (() => {
3185
3191
  return hexToBytes(adaptedValue);
3186
3192
  }
3187
3193
 
3194
+ // src/utils/selector.ts
3195
+ var selector_exports = {};
3196
+ __export(selector_exports, {
3197
+ getSelector: () => getSelector,
3198
+ getSelectorFromName: () => getSelectorFromName,
3199
+ keccakBn: () => keccakBn,
3200
+ starknetKeccak: () => starknetKeccak
3201
+ });
3202
+
3188
3203
  // node_modules/micro-starknet/lib/esm/index.js
3189
3204
  var esm_exports = {};
3190
3205
  __export(esm_exports, {
@@ -7401,34 +7416,6 @@ var starknet = (() => {
7401
7416
  return computeLegacyContractClassHash(compiledContract);
7402
7417
  }
7403
7418
 
7404
- // src/utils/contract.ts
7405
- function isSierra(contract) {
7406
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
7407
- return "sierra_program" in compiledContract;
7408
- }
7409
- function extractContractHashes(payload) {
7410
- const response = { ...payload };
7411
- if (isSierra(payload.contract)) {
7412
- if (!payload.compiledClassHash && payload.casm) {
7413
- response.compiledClassHash = computeCompiledClassHash(payload.casm);
7414
- }
7415
- if (!response.compiledClassHash)
7416
- throw new Error(
7417
- "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
7418
- );
7419
- }
7420
- response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
7421
- if (!response.classHash)
7422
- throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
7423
- return response;
7424
- }
7425
-
7426
- // src/utils/fetchPonyfill.ts
7427
- var import_isomorphic_fetch = __toESM(require_fetch_npm_browserify());
7428
- var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
7429
- typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
7430
- import_isomorphic_fetch.default;
7431
-
7432
7419
  // src/utils/stark.ts
7433
7420
  var stark_exports = {};
7434
7421
  __export(stark_exports, {
@@ -11648,7 +11635,48 @@ var starknet = (() => {
11648
11635
  return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
11649
11636
  }
11650
11637
 
11638
+ // src/utils/contract.ts
11639
+ function isSierra(contract) {
11640
+ const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
11641
+ return "sierra_program" in compiledContract;
11642
+ }
11643
+ function extractContractHashes(payload) {
11644
+ const response = { ...payload };
11645
+ if (isSierra(payload.contract)) {
11646
+ if (!payload.compiledClassHash && payload.casm) {
11647
+ response.compiledClassHash = computeCompiledClassHash(payload.casm);
11648
+ }
11649
+ if (!response.compiledClassHash)
11650
+ throw new Error(
11651
+ "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
11652
+ );
11653
+ }
11654
+ response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
11655
+ if (!response.classHash)
11656
+ throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
11657
+ return response;
11658
+ }
11659
+ function contractClassResponseToLegacyCompiledContract(ccr) {
11660
+ if (isSierra(ccr)) {
11661
+ throw Error("ContractClassResponse need to be LegacyContractClass (cairo0 response class)");
11662
+ }
11663
+ const contract = ccr;
11664
+ return { ...contract, program: decompressProgram(contract.program) };
11665
+ }
11666
+
11667
+ // src/utils/fetchPonyfill.ts
11668
+ var import_isomorphic_fetch = __toESM(require_fetch_npm_browserify());
11669
+ var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
11670
+ typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
11671
+ import_isomorphic_fetch.default;
11672
+
11651
11673
  // src/utils/provider.ts
11674
+ var provider_exports = {};
11675
+ __export(provider_exports, {
11676
+ createSierraContractClass: () => createSierraContractClass,
11677
+ parseContract: () => parseContract,
11678
+ wait: () => wait
11679
+ });
11652
11680
  function wait(delay) {
11653
11681
  return new Promise((res) => {
11654
11682
  setTimeout(res, delay);
@@ -11667,7 +11695,6 @@ var starknet = (() => {
11667
11695
  if (!isSierra(contract)) {
11668
11696
  return {
11669
11697
  ...parsedContract,
11670
- // TODO: Why do we gzip program object?
11671
11698
  ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
11672
11699
  };
11673
11700
  }
@@ -12159,14 +12186,13 @@ var starknet = (() => {
12159
12186
  }
12160
12187
  async declareContract({ contract, signature, senderAddress, compiledClassHash }, details) {
12161
12188
  if (!isSierra(contract)) {
12162
- const legacyContract = contract;
12163
12189
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
12164
12190
  declare_transaction: {
12165
12191
  type: RPC.TransactionType.DECLARE,
12166
12192
  contract_class: {
12167
- program: legacyContract.program,
12168
- entry_points_by_type: legacyContract.entry_points_by_type,
12169
- abi: legacyContract.abi
12193
+ program: contract.program,
12194
+ entry_points_by_type: contract.entry_points_by_type,
12195
+ abi: contract.abi
12170
12196
  },
12171
12197
  version: toHex(transactionVersion),
12172
12198
  max_fee: toHex(details.maxFee || 0),
@@ -12176,15 +12202,14 @@ var starknet = (() => {
12176
12202
  }
12177
12203
  });
12178
12204
  }
12179
- const sierraContract = contract;
12180
12205
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
12181
12206
  declare_transaction: {
12182
12207
  type: RPC.TransactionType.DECLARE,
12183
12208
  contract_class: {
12184
- sierra_program: decompressProgram(sierraContract.sierra_program),
12185
- contract_class_version: sierraContract.contract_class_version,
12186
- entry_points_by_type: sierraContract.entry_points_by_type,
12187
- abi: sierraContract.abi
12209
+ sierra_program: decompressProgram(contract.sierra_program),
12210
+ contract_class_version: contract.contract_class_version,
12211
+ entry_points_by_type: contract.entry_points_by_type,
12212
+ abi: contract.abi
12188
12213
  },
12189
12214
  compiled_class_hash: compiledClassHash || "",
12190
12215
  version: toHex(transactionVersion_2),