@fuel-ts/account 0.94.8 → 0.94.9

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/dist/index.mjs CHANGED
@@ -10707,7 +10707,7 @@ var StorageAbstract = class {
10707
10707
  import { Interface as Interface4 } from "@fuel-ts/abi-coder";
10708
10708
  import { Address as Address9 } from "@fuel-ts/address";
10709
10709
  import { ErrorCode as ErrorCode25, FuelError as FuelError27 } from "@fuel-ts/errors";
10710
- import { arrayify as arrayify21, hexlify as hexlify23 } from "@fuel-ts/utils";
10710
+ import { arrayify as arrayify21, hexlify as hexlify23, concat as concat7 } from "@fuel-ts/utils";
10711
10711
 
10712
10712
  // src/predicate/utils/getPredicateRoot.ts
10713
10713
  import { hash as hash3 } from "@fuel-ts/hasher";
@@ -10723,10 +10723,17 @@ var getPredicateRoot = (bytecode) => {
10723
10723
  };
10724
10724
 
10725
10725
  // src/predicate/predicate.ts
10726
+ function getDataOffset(binary) {
10727
+ const buffer = binary.buffer.slice(binary.byteOffset + 8, binary.byteOffset + 16);
10728
+ const dataView = new DataView(buffer);
10729
+ const dataOffset = dataView.getBigUint64(0, false);
10730
+ return Number(dataOffset);
10731
+ }
10726
10732
  var Predicate = class extends Account {
10727
10733
  bytes;
10728
10734
  predicateData = [];
10729
10735
  interface;
10736
+ loaderBytecode = "";
10730
10737
  /**
10731
10738
  * Creates an instance of the Predicate class.
10732
10739
  *
@@ -10741,7 +10748,13 @@ var Predicate = class extends Account {
10741
10748
  abi,
10742
10749
  provider,
10743
10750
  data,
10744
- configurableConstants
10751
+ configurableConstants,
10752
+ /**
10753
+ * TODO: Implement a getBytes method within the Predicate class. This method should return the loaderBytecode if it is set.
10754
+ * The getBytes method should be used in all places where we use this.bytes.
10755
+ * Note: Do not set loaderBytecode to a default string here; it should remain undefined when not provided.
10756
+ */
10757
+ loaderBytecode = ""
10745
10758
  }) {
10746
10759
  const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
10747
10760
  bytecode,
@@ -10752,6 +10765,7 @@ var Predicate = class extends Account {
10752
10765
  super(address, provider);
10753
10766
  this.bytes = predicateBytes;
10754
10767
  this.interface = predicateInterface;
10768
+ this.loaderBytecode = loaderBytecode;
10755
10769
  if (data !== void 0 && data.length > 0) {
10756
10770
  this.predicateData = data;
10757
10771
  }
@@ -10876,7 +10890,7 @@ var Predicate = class extends Account {
10876
10890
  * @param abiInterface - The ABI interface of the predicate.
10877
10891
  * @returns The mutated bytes with the configurable constants set.
10878
10892
  */
10879
- static setConfigurableConstants(bytes, configurableConstants, abiInterface) {
10893
+ static setConfigurableConstants(bytes, configurableConstants, abiInterface, loaderBytecode) {
10880
10894
  const mutatedBytes = bytes;
10881
10895
  try {
10882
10896
  if (!abiInterface) {
@@ -10902,6 +10916,15 @@ var Predicate = class extends Account {
10902
10916
  const encoded = abiInterface.encodeConfigurable(key, value);
10903
10917
  mutatedBytes.set(encoded, offset);
10904
10918
  });
10919
+ if (loaderBytecode) {
10920
+ const offset = getDataOffset(bytes);
10921
+ const dataSection = mutatedBytes.slice(offset);
10922
+ const dataSectionLen = dataSection.length;
10923
+ const dataSectionLenBytes = new Uint8Array(8);
10924
+ const dataSectionLenDataView = new DataView(dataSectionLenBytes.buffer);
10925
+ dataSectionLenDataView.setBigUint64(0, BigInt(dataSectionLen), false);
10926
+ mutatedBytes.set(concat7([loaderBytecode, dataSectionLenBytes, dataSection]));
10927
+ }
10905
10928
  } catch (err) {
10906
10929
  throw new FuelError27(
10907
10930
  ErrorCode25.INVALID_CONFIGURABLE_CONSTANTS,