starknet 9.3.0 → 9.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 +15 -0
- package/dist/index.d.ts +62 -1
- package/dist/index.global.js +191 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +168 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -133,6 +133,7 @@ __export(index_exports, {
|
|
|
133
133
|
config: () => config,
|
|
134
134
|
constants: () => constants_exports,
|
|
135
135
|
contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
|
|
136
|
+
contractLoader: () => contractLoader,
|
|
136
137
|
createAbiParser: () => createAbiParser,
|
|
137
138
|
createTransactionReceipt: () => createTransactionReceipt,
|
|
138
139
|
defaultDeployer: () => defaultDeployer,
|
|
@@ -154,6 +155,7 @@ __export(index_exports, {
|
|
|
154
155
|
hash: () => hash_exports,
|
|
155
156
|
hdParsingStrategy: () => hdParsingStrategy,
|
|
156
157
|
isAccount: () => isAccount,
|
|
158
|
+
isFileSystemAvailable: () => isFileSystemAvailable,
|
|
157
159
|
isNoConstructorValid: () => isNoConstructorValid,
|
|
158
160
|
isPreConfirmedBlock: () => isPreConfirmedBlock,
|
|
159
161
|
isPreConfirmedStateUpdate: () => isPreConfirmedStateUpdate,
|
|
@@ -5675,6 +5677,170 @@ function resourceBoundsToBigInt(resourceBounds) {
|
|
|
5675
5677
|
return convertStringToBigInt(resourceBounds);
|
|
5676
5678
|
}
|
|
5677
5679
|
|
|
5680
|
+
// src/utils/contractLoader.ts
|
|
5681
|
+
function isFileSystemAvailable() {
|
|
5682
|
+
try {
|
|
5683
|
+
return typeof require !== "undefined" && typeof require.resolve === "function";
|
|
5684
|
+
} catch {
|
|
5685
|
+
logger.info("isFileSystemAvailable: false");
|
|
5686
|
+
return false;
|
|
5687
|
+
}
|
|
5688
|
+
}
|
|
5689
|
+
function contractLoader(input, compiledClassHash) {
|
|
5690
|
+
if (typeof File !== "undefined" && (input instanceof File || Array.isArray(input))) {
|
|
5691
|
+
return loadFromFileAPI(input, compiledClassHash);
|
|
5692
|
+
}
|
|
5693
|
+
if (typeof input === "string") {
|
|
5694
|
+
if (!isFileSystemAvailable()) {
|
|
5695
|
+
throw new Error(
|
|
5696
|
+
'contractLoader with string paths is only available in Node.js environments. In browsers, please use File objects from <input type="file"> or drag-and-drop. Example: await contractLoader(fileInput.files[0])'
|
|
5697
|
+
);
|
|
5698
|
+
}
|
|
5699
|
+
return loadFromFileSystem(input, compiledClassHash);
|
|
5700
|
+
}
|
|
5701
|
+
throw new Error(
|
|
5702
|
+
"Invalid input type. Expected string (Node.js path) or File/File[] (browser File API)"
|
|
5703
|
+
);
|
|
5704
|
+
}
|
|
5705
|
+
function loadFromFileSystem(contractPath, compiledClassHash) {
|
|
5706
|
+
const fs = require("fs");
|
|
5707
|
+
const path = require("path");
|
|
5708
|
+
const resolvedPath = path.resolve(contractPath);
|
|
5709
|
+
let dirPath;
|
|
5710
|
+
let specifiedSierraFile;
|
|
5711
|
+
let specifiedCasmFile;
|
|
5712
|
+
const stats = fs.statSync(resolvedPath);
|
|
5713
|
+
if (stats.isFile()) {
|
|
5714
|
+
dirPath = path.dirname(resolvedPath);
|
|
5715
|
+
const fileName = path.basename(resolvedPath);
|
|
5716
|
+
if (fileName.endsWith(".sierra.json") || fileName.endsWith(".json") && !fileName.endsWith(".casm")) {
|
|
5717
|
+
specifiedSierraFile = fileName;
|
|
5718
|
+
} else if (fileName.endsWith(".casm")) {
|
|
5719
|
+
specifiedCasmFile = fileName;
|
|
5720
|
+
} else {
|
|
5721
|
+
throw new Error(
|
|
5722
|
+
`Invalid file type. Expected .json, .sierra.json, or .casm file, got: ${fileName}`
|
|
5723
|
+
);
|
|
5724
|
+
}
|
|
5725
|
+
} else if (stats.isDirectory()) {
|
|
5726
|
+
dirPath = resolvedPath;
|
|
5727
|
+
} else {
|
|
5728
|
+
throw new Error(`Path is neither a file nor a directory: ${contractPath}`);
|
|
5729
|
+
}
|
|
5730
|
+
const files = fs.readdirSync(dirPath);
|
|
5731
|
+
let sierraFile;
|
|
5732
|
+
let casmFile;
|
|
5733
|
+
if (specifiedSierraFile) {
|
|
5734
|
+
sierraFile = specifiedSierraFile;
|
|
5735
|
+
const baseName = sierraFile.replace(/\.sierra\.json$/, "").replace(/\.json$/, "");
|
|
5736
|
+
casmFile = files.find((f) => f === `${baseName}.casm`);
|
|
5737
|
+
} else if (specifiedCasmFile) {
|
|
5738
|
+
casmFile = specifiedCasmFile;
|
|
5739
|
+
const baseName = casmFile.replace(/\.casm$/, "");
|
|
5740
|
+
sierraFile = files.find((f) => f === `${baseName}.sierra.json`) || files.find((f) => f === `${baseName}.json`);
|
|
5741
|
+
} else {
|
|
5742
|
+
const sierraFiles = files.filter(
|
|
5743
|
+
(f) => f.endsWith(".sierra.json") || f.endsWith(".json") && !f.endsWith(".casm")
|
|
5744
|
+
);
|
|
5745
|
+
if (sierraFiles.length === 0) {
|
|
5746
|
+
throw new Error(`No .sierra.json file found in ${dirPath}. Sierra file is required.`);
|
|
5747
|
+
}
|
|
5748
|
+
if (sierraFiles.length > 1) {
|
|
5749
|
+
throw new Error(
|
|
5750
|
+
`Multiple .sierra.json files found in ${dirPath}: ${sierraFiles.join(", ")}. Please specify which file to use.`
|
|
5751
|
+
);
|
|
5752
|
+
}
|
|
5753
|
+
[sierraFile] = sierraFiles;
|
|
5754
|
+
const baseName = sierraFile.replace(/\.sierra\.json$/, "").replace(/\.json$/, "");
|
|
5755
|
+
casmFile = files.find((f) => f === `${baseName}.casm`);
|
|
5756
|
+
}
|
|
5757
|
+
if (!sierraFile) {
|
|
5758
|
+
throw new Error(`No .sierra.json file found in ${dirPath}. Sierra file is required.`);
|
|
5759
|
+
}
|
|
5760
|
+
const sierraPath = path.join(dirPath, sierraFile);
|
|
5761
|
+
const sierraContent = parse2(fs.readFileSync(sierraPath, "utf8"));
|
|
5762
|
+
if (casmFile) {
|
|
5763
|
+
const casmPath = path.join(dirPath, casmFile);
|
|
5764
|
+
const casmContent = parse2(fs.readFileSync(casmPath, "utf8"));
|
|
5765
|
+
return {
|
|
5766
|
+
sierra: sierraContent,
|
|
5767
|
+
casm: casmContent,
|
|
5768
|
+
compiler: casmContent.compiler_version
|
|
5769
|
+
};
|
|
5770
|
+
}
|
|
5771
|
+
if (!compiledClassHash) {
|
|
5772
|
+
throw new Error(
|
|
5773
|
+
`No .casm file found for ${sierraFile} and no compiledClassHash provided. Either provide a .casm file or pass compiledClassHash as second parameter.`
|
|
5774
|
+
);
|
|
5775
|
+
}
|
|
5776
|
+
return {
|
|
5777
|
+
sierra: sierraContent,
|
|
5778
|
+
compiledClassHash
|
|
5779
|
+
};
|
|
5780
|
+
}
|
|
5781
|
+
async function loadFromFileAPI(input, compiledClassHash) {
|
|
5782
|
+
const files = Array.isArray(input) ? input : [input];
|
|
5783
|
+
if (files.length === 0) {
|
|
5784
|
+
throw new Error("No files provided");
|
|
5785
|
+
}
|
|
5786
|
+
const sierraFiles = files.filter(
|
|
5787
|
+
(file) => file.name.endsWith(".sierra.json") || file.name.endsWith(".json") && !file.name.endsWith(".casm")
|
|
5788
|
+
);
|
|
5789
|
+
const casmFiles = files.filter((file) => file.name.endsWith(".casm"));
|
|
5790
|
+
if (sierraFiles.length > 1) {
|
|
5791
|
+
throw new Error(
|
|
5792
|
+
`Multiple .sierra.json files provided: ${sierraFiles.map((f) => f.name).join(", ")}. Please provide only one sierra file.`
|
|
5793
|
+
);
|
|
5794
|
+
}
|
|
5795
|
+
if (casmFiles.length > 1) {
|
|
5796
|
+
throw new Error(
|
|
5797
|
+
`Multiple .casm files provided: ${casmFiles.map((f) => f.name).join(", ")}. Please provide only one casm file.`
|
|
5798
|
+
);
|
|
5799
|
+
}
|
|
5800
|
+
const sierraFile = sierraFiles[0];
|
|
5801
|
+
const casmFile = casmFiles[0];
|
|
5802
|
+
if (!sierraFile) {
|
|
5803
|
+
throw new Error(
|
|
5804
|
+
`No .sierra.json file found in provided files. Sierra file is required. Provided files: ${files.map((f) => f.name).join(", ")}`
|
|
5805
|
+
);
|
|
5806
|
+
}
|
|
5807
|
+
const sierraContent = parse2(await readFileAsText(sierraFile));
|
|
5808
|
+
if (casmFile) {
|
|
5809
|
+
const casmContent = parse2(await readFileAsText(casmFile));
|
|
5810
|
+
return {
|
|
5811
|
+
sierra: sierraContent,
|
|
5812
|
+
casm: casmContent,
|
|
5813
|
+
compiler: casmContent.compiler_version
|
|
5814
|
+
};
|
|
5815
|
+
}
|
|
5816
|
+
if (!compiledClassHash) {
|
|
5817
|
+
throw new Error(
|
|
5818
|
+
"No .casm file found in provided files and no compiledClassHash provided. Either provide a .casm file or pass compiledClassHash as second parameter."
|
|
5819
|
+
);
|
|
5820
|
+
}
|
|
5821
|
+
return {
|
|
5822
|
+
sierra: sierraContent,
|
|
5823
|
+
compiledClassHash
|
|
5824
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
function readFileAsText(file) {
|
|
5827
|
+
return new Promise((resolve, reject) => {
|
|
5828
|
+
const reader = new FileReader();
|
|
5829
|
+
reader.onload = (event) => {
|
|
5830
|
+
const content = event.target?.result;
|
|
5831
|
+
if (typeof content === "string") {
|
|
5832
|
+
resolve(content);
|
|
5833
|
+
} else {
|
|
5834
|
+
reject(new Error(`Failed to read file ${file.name} as text`));
|
|
5835
|
+
}
|
|
5836
|
+
};
|
|
5837
|
+
reader.onerror = () => {
|
|
5838
|
+
reject(new Error(`Failed to read file ${file.name}: ${reader.error?.message}`));
|
|
5839
|
+
};
|
|
5840
|
+
reader.readAsText(file);
|
|
5841
|
+
});
|
|
5842
|
+
}
|
|
5843
|
+
|
|
5678
5844
|
// src/utils/contract.ts
|
|
5679
5845
|
function isSierra(contract) {
|
|
5680
5846
|
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
@@ -13071,6 +13237,7 @@ function units(amount, simbol = "fri") {
|
|
|
13071
13237
|
config,
|
|
13072
13238
|
constants,
|
|
13073
13239
|
contractClassResponseToLegacyCompiledContract,
|
|
13240
|
+
contractLoader,
|
|
13074
13241
|
createAbiParser,
|
|
13075
13242
|
createTransactionReceipt,
|
|
13076
13243
|
defaultDeployer,
|
|
@@ -13092,6 +13259,7 @@ function units(amount, simbol = "fri") {
|
|
|
13092
13259
|
hash,
|
|
13093
13260
|
hdParsingStrategy,
|
|
13094
13261
|
isAccount,
|
|
13262
|
+
isFileSystemAvailable,
|
|
13095
13263
|
isNoConstructorValid,
|
|
13096
13264
|
isPreConfirmedBlock,
|
|
13097
13265
|
isPreConfirmedStateUpdate,
|