starknet 6.3.0 → 6.4.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,14 @@
1
+ # [6.4.0](https://github.com/starknet-io/starknet.js/compare/v6.3.0...v6.4.0) (2024-03-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ - expand encoding type for preset types ([b992446](https://github.com/starknet-io/starknet.js/commit/b9924465a1f01ac4273638f3fa258b36192d2101))
6
+
7
+ ### Features
8
+
9
+ - enable cairo 2.6.0 contract declaration ([0104c59](https://github.com/starknet-io/starknet.js/commit/0104c59739a9dbe70091e14372a73ca84550f639))
10
+ - skip signatures when skipValidate is true ([6f784ea](https://github.com/starknet-io/starknet.js/commit/6f784ea4e4edd298f1950dac956fd1c81b953497))
11
+
1
12
  # [6.3.0](https://github.com/starknet-io/starknet.js/compare/v6.2.1...v6.3.0) (2024-03-11)
2
13
 
3
14
  ### Features
package/dist/index.d.ts CHANGED
@@ -2703,6 +2703,7 @@ type CairoAssembly = {
2703
2703
  bytecode: ByteCode;
2704
2704
  hints: any[];
2705
2705
  pythonic_hints?: PythonicHints;
2706
+ bytecode_segment_lengths?: number[];
2706
2707
  entry_points_by_type: EntryPointsByType;
2707
2708
  };
2708
2709
  /** COMPILED CONTRACT */
@@ -3126,6 +3127,7 @@ type AccountInvocationsFactoryDetails = {
3126
3127
  versions: Array<`${ETransactionVersion}`>;
3127
3128
  nonce?: BigNumberish;
3128
3129
  blockIdentifier?: BlockIdentifier;
3130
+ skipValidate?: boolean;
3129
3131
  } & Partial<V3TransactionDetails>;
3130
3132
  interface UniversalDetails {
3131
3133
  nonce?: BigNumberish;
@@ -3245,6 +3247,7 @@ type ParsedEvents = Array<ParsedEvent>;
3245
3247
 
3246
3248
  type InvocationsSignerDetails = (V2InvocationsSignerDetails | V3InvocationsSignerDetails) & {
3247
3249
  version: `${ETransactionVersion}`;
3250
+ skipValidate?: boolean;
3248
3251
  };
3249
3252
  type V2InvocationsSignerDetails = {
3250
3253
  walletAddress: string;
@@ -6530,6 +6533,14 @@ declare function formatSpaces(json: string): string;
6530
6533
  * @returns format: hex-string
6531
6534
  */
6532
6535
  declare function computeLegacyContractClassHash(contract: LegacyCompiledContract | string): string;
6536
+ /**
6537
+ * Compute hash of the bytecode for Sierra v1.5.0 onwards (Cairo 2.6.0)
6538
+ * Each segment is Poseidon hashed.
6539
+ * The global hash is : 1 + PoseidonHash(len0, h0, len1, h1, ...)
6540
+ * @param casm compiled Sierra CASM file content.
6541
+ * @returns the bytecode hash as bigint.
6542
+ */
6543
+ declare function hashByteCodeSegments(casm: CompiledSierraCasm): bigint;
6533
6544
  /**
6534
6545
  * Compute compiled class hash for contract (Cairo 1)
6535
6546
  * @returns format: hex-string
@@ -6562,11 +6573,12 @@ declare const index$1_computeSierraContractClassHash: typeof computeSierraContra
6562
6573
  declare const index$1_formatSpaces: typeof formatSpaces;
6563
6574
  declare const index$1_getSelector: typeof getSelector;
6564
6575
  declare const index$1_getSelectorFromName: typeof getSelectorFromName;
6576
+ declare const index$1_hashByteCodeSegments: typeof hashByteCodeSegments;
6565
6577
  declare const index$1_keccakBn: typeof keccakBn;
6566
6578
  declare const index$1_poseidon: typeof poseidon;
6567
6579
  declare const index$1_starknetKeccak: typeof starknetKeccak;
6568
6580
  declare namespace index$1 {
6569
- export { index$1_calculateContractAddressFromHash as calculateContractAddressFromHash, calculateDeclareTransactionHash$2 as calculateDeclareTransactionHash, calculateDeployAccountTransactionHash$2 as calculateDeployAccountTransactionHash, calculateInvokeTransactionHash$1 as calculateInvokeTransactionHash, index$1_computeCompiledClassHash as computeCompiledClassHash, index$1_computeContractClassHash as computeContractClassHash, computeHashOnElements$1 as computeHashOnElements, index$1_computeLegacyContractClassHash as computeLegacyContractClassHash, index$1_computePedersenHash as computePedersenHash, index$1_computePedersenHashOnElements as computePedersenHashOnElements, index$1_computePoseidonHash as computePoseidonHash, index$1_computePoseidonHashOnElements as computePoseidonHashOnElements, index$1_computeSierraContractClassHash as computeSierraContractClassHash, index$1_formatSpaces as formatSpaces, index$1_getSelector as getSelector, index$1_getSelectorFromName as getSelectorFromName, index$1_keccakBn as keccakBn, index$1_poseidon as poseidon, index$1_starknetKeccak as starknetKeccak };
6581
+ export { index$1_calculateContractAddressFromHash as calculateContractAddressFromHash, calculateDeclareTransactionHash$2 as calculateDeclareTransactionHash, calculateDeployAccountTransactionHash$2 as calculateDeployAccountTransactionHash, calculateInvokeTransactionHash$1 as calculateInvokeTransactionHash, index$1_computeCompiledClassHash as computeCompiledClassHash, index$1_computeContractClassHash as computeContractClassHash, computeHashOnElements$1 as computeHashOnElements, index$1_computeLegacyContractClassHash as computeLegacyContractClassHash, index$1_computePedersenHash as computePedersenHash, index$1_computePedersenHashOnElements as computePedersenHashOnElements, index$1_computePoseidonHash as computePoseidonHash, index$1_computePoseidonHashOnElements as computePoseidonHashOnElements, index$1_computeSierraContractClassHash as computeSierraContractClassHash, index$1_formatSpaces as formatSpaces, index$1_getSelector as getSelector, index$1_getSelectorFromName as getSelectorFromName, index$1_hashByteCodeSegments as hashByteCodeSegments, index$1_keccakBn as keccakBn, index$1_poseidon as poseidon, index$1_starknetKeccak as starknetKeccak };
6570
6582
  }
6571
6583
 
6572
6584
  /**
@@ -17807,6 +17807,7 @@ var starknet = (() => {
17807
17807
  formatSpaces: () => formatSpaces,
17808
17808
  getSelector: () => getSelector,
17809
17809
  getSelectorFromName: () => getSelectorFromName,
17810
+ hashByteCodeSegments: () => hashByteCodeSegments,
17810
17811
  keccakBn: () => keccakBn,
17811
17812
  poseidon: () => poseidon_exports,
17812
17813
  starknetKeccak: () => starknetKeccak
@@ -18728,13 +18729,23 @@ var starknet = (() => {
18728
18729
  });
18729
18730
  return poseidonHashMany(base2);
18730
18731
  }
18732
+ function hashByteCodeSegments(casm) {
18733
+ const byteCode = casm.bytecode.map((n) => BigInt(n));
18734
+ const bytecodeSegmentLengths = casm.bytecode_segment_lengths ?? [];
18735
+ let segmentStart = 0;
18736
+ const hashLeaves = bytecodeSegmentLengths.flatMap((len) => {
18737
+ const segment = byteCode.slice(segmentStart, segmentStart += len);
18738
+ return [BigInt(len), poseidonHashMany(segment)];
18739
+ });
18740
+ return 1n + poseidonHashMany(hashLeaves);
18741
+ }
18731
18742
  function computeCompiledClassHash(casm) {
18732
18743
  const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
18733
18744
  const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
18734
18745
  const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
18735
18746
  const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
18736
18747
  const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
18737
- const bytecode = poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
18748
+ const bytecode = casm.bytecode_segment_lengths ? hashByteCodeSegments(casm) : poseidonHashMany(casm.bytecode.map((it) => BigInt(it)));
18738
18749
  return toHex(
18739
18750
  poseidonHashMany([
18740
18751
  compiledClassVersion,
@@ -25694,11 +25705,18 @@ var starknet = (() => {
25694
25705
  return "raw";
25695
25706
  }
25696
25707
  function encodeType(types, type, revision = "0" /* Legacy */) {
25697
- const [primary, ...dependencies] = getDependencies(types, type, void 0, void 0, revision);
25708
+ const allTypes = revision === "1" /* Active */ ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
25709
+ const [primary, ...dependencies] = getDependencies(
25710
+ allTypes,
25711
+ type,
25712
+ void 0,
25713
+ void 0,
25714
+ revision
25715
+ );
25698
25716
  const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
25699
25717
  const esc = revisionConfiguration[revision].escapeTypeString;
25700
25718
  return newTypes.map((dependency) => {
25701
- const dependencyElements = types[dependency].map((t) => {
25719
+ const dependencyElements = allTypes[dependency].map((t) => {
25702
25720
  const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
25703
25721
  const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
25704
25722
  return `${esc(t.name)}:${typeString}`;
@@ -26172,7 +26190,12 @@ var starknet = (() => {
26172
26190
  return this.estimateInvokeFee(calls, estimateFeeDetails);
26173
26191
  }
26174
26192
  async estimateInvokeFee(calls, details = {}) {
26175
- const { nonce: providedNonce, blockIdentifier, version: providedVersion } = details;
26193
+ const {
26194
+ nonce: providedNonce,
26195
+ blockIdentifier,
26196
+ version: providedVersion,
26197
+ skipValidate = true
26198
+ } = details;
26176
26199
  const transactions = Array.isArray(calls) ? calls : [calls];
26177
26200
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
26178
26201
  const version = toTransactionVersion(
@@ -26187,7 +26210,8 @@ var starknet = (() => {
26187
26210
  maxFee: ZERO,
26188
26211
  version,
26189
26212
  chainId,
26190
- cairoVersion: await this.getCairoVersion()
26213
+ cairoVersion: await this.getCairoVersion(),
26214
+ skipValidate
26191
26215
  };
26192
26216
  const invocation = await this.buildInvocation(transactions, signerDetails);
26193
26217
  return super.getInvokeEstimateFee(
@@ -26198,7 +26222,12 @@ var starknet = (() => {
26198
26222
  );
26199
26223
  }
26200
26224
  async estimateDeclareFee(payload, details = {}) {
26201
- const { blockIdentifier, nonce: providedNonce, version: providedVersion } = details;
26225
+ const {
26226
+ blockIdentifier,
26227
+ nonce: providedNonce,
26228
+ version: providedVersion,
26229
+ skipValidate = true
26230
+ } = details;
26202
26231
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
26203
26232
  const version = toTransactionVersion(
26204
26233
  !isSierra(payload.contract) ? "0x100000000000000000000000000000001" /* F1 */ : this.getPreferredVersion("0x100000000000000000000000000000002" /* F2 */, "0x100000000000000000000000000000003" /* F3 */),
@@ -26212,8 +26241,9 @@ var starknet = (() => {
26212
26241
  version,
26213
26242
  walletAddress: this.address,
26214
26243
  maxFee: ZERO,
26215
- cairoVersion: void 0
26244
+ cairoVersion: void 0,
26216
26245
  // unused parameter
26246
+ skipValidate
26217
26247
  });
26218
26248
  return super.getDeclareEstimateFee(
26219
26249
  declareContractTransaction,
@@ -26228,7 +26258,7 @@ var starknet = (() => {
26228
26258
  constructorCalldata = [],
26229
26259
  contractAddress
26230
26260
  }, details = {}) {
26231
- const { blockIdentifier, version: providedVersion } = details;
26261
+ const { blockIdentifier, version: providedVersion, skipValidate = true } = details;
26232
26262
  const version = toTransactionVersion(
26233
26263
  this.getPreferredVersion("0x100000000000000000000000000000001" /* F1 */, "0x100000000000000000000000000000003" /* F3 */),
26234
26264
  toFeeVersion(providedVersion)
@@ -26245,8 +26275,9 @@ var starknet = (() => {
26245
26275
  walletAddress: this.address,
26246
26276
  // unused parameter
26247
26277
  maxFee: ZERO,
26248
- cairoVersion: void 0
26278
+ cairoVersion: void 0,
26249
26279
  // unused parameter,
26280
+ skipValidate
26250
26281
  }
26251
26282
  );
26252
26283
  return super.getDeployAccountEstimateFee(
@@ -26282,7 +26313,7 @@ var starknet = (() => {
26282
26313
  });
26283
26314
  }
26284
26315
  async simulateTransaction(invocations, details = {}) {
26285
- const { nonce, blockIdentifier, skipValidate, skipExecute, version } = details;
26316
+ const { nonce, blockIdentifier, skipValidate = true, skipExecute, version } = details;
26286
26317
  const accountInvocations = await this.accountInvocationsFactory(invocations, {
26287
26318
  ...v3Details(details),
26288
26319
  versions: [
@@ -26294,7 +26325,8 @@ var starknet = (() => {
26294
26325
  )
26295
26326
  ],
26296
26327
  nonce,
26297
- blockIdentifier
26328
+ blockIdentifier,
26329
+ skipValidate
26298
26330
  });
26299
26331
  return super.getSimulateTransaction(accountInvocations, {
26300
26332
  blockIdentifier,
@@ -26580,7 +26612,7 @@ var starknet = (() => {
26580
26612
  }
26581
26613
  async buildInvocation(call, details) {
26582
26614
  const calldata = getExecuteCalldata(call, await this.getCairoVersion());
26583
- const signature = await this.signer.signTransaction(call, details);
26615
+ const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
26584
26616
  return {
26585
26617
  ...v3Details(details),
26586
26618
  contractAddress: this.address,
@@ -26594,14 +26626,14 @@ var starknet = (() => {
26594
26626
  if (typeof compiledClassHash === "undefined" && (details.version === "0x100000000000000000000000000000003" /* F3 */ || details.version === "0x3" /* V3 */)) {
26595
26627
  throw Error("V3 Transaction work with Cairo1 Contracts and require compiledClassHash");
26596
26628
  }
26597
- const signature = await this.signer.signDeclareTransaction({
26629
+ const signature = !details.skipValidate ? await this.signer.signDeclareTransaction({
26598
26630
  ...details,
26599
26631
  ...v3Details(details),
26600
26632
  classHash,
26601
26633
  compiledClassHash,
26602
- // TODO: TS Nekuzi da v2 nemora imat a v3 mora i da je throvano ako nije definiran
26634
+ // TODO: TS, cast because optional for v2 and required for v3, thrown if not present
26603
26635
  senderAddress: details.walletAddress
26604
- });
26636
+ }) : [];
26605
26637
  return {
26606
26638
  senderAddress: details.walletAddress,
26607
26639
  signature,
@@ -26617,14 +26649,14 @@ var starknet = (() => {
26617
26649
  }, details) {
26618
26650
  const compiledCalldata = CallData.compile(constructorCalldata);
26619
26651
  const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
26620
- const signature = await this.signer.signDeployAccountTransaction({
26652
+ const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
26621
26653
  ...details,
26622
26654
  ...v3Details(details),
26623
26655
  classHash,
26624
26656
  contractAddress,
26625
26657
  addressSalt,
26626
26658
  constructorCalldata: compiledCalldata
26627
- });
26659
+ }) : [];
26628
26660
  return {
26629
26661
  ...v3Details(details),
26630
26662
  classHash,
@@ -26657,7 +26689,7 @@ var starknet = (() => {
26657
26689
  return calls;
26658
26690
  }
26659
26691
  async accountInvocationsFactory(invocations, details) {
26660
- const { nonce, blockIdentifier } = details;
26692
+ const { nonce, blockIdentifier, skipValidate = true } = details;
26661
26693
  const safeNonce = await this.getNonceSafe(nonce);
26662
26694
  const chainId = await this.getChainId();
26663
26695
  const versions = details.versions.map((it) => toTransactionVersion(it));
@@ -26673,7 +26705,8 @@ var starknet = (() => {
26673
26705
  maxFee: ZERO,
26674
26706
  chainId,
26675
26707
  cairoVersion,
26676
- version: ""
26708
+ version: "",
26709
+ skipValidate
26677
26710
  };
26678
26711
  const common2 = {
26679
26712
  type: transaction.type,