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.mjs
CHANGED
|
@@ -2,6 +2,12 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
|
+
}) : x)(function(x) {
|
|
8
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
5
11
|
var __export = (target, all) => {
|
|
6
12
|
for (var name in all)
|
|
7
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -5498,6 +5504,170 @@ function resourceBoundsToBigInt(resourceBounds) {
|
|
|
5498
5504
|
return convertStringToBigInt(resourceBounds);
|
|
5499
5505
|
}
|
|
5500
5506
|
|
|
5507
|
+
// src/utils/contractLoader.ts
|
|
5508
|
+
function isFileSystemAvailable() {
|
|
5509
|
+
try {
|
|
5510
|
+
return typeof __require !== "undefined" && typeof __require.resolve === "function";
|
|
5511
|
+
} catch {
|
|
5512
|
+
logger.info("isFileSystemAvailable: false");
|
|
5513
|
+
return false;
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
function contractLoader(input, compiledClassHash) {
|
|
5517
|
+
if (typeof File !== "undefined" && (input instanceof File || Array.isArray(input))) {
|
|
5518
|
+
return loadFromFileAPI(input, compiledClassHash);
|
|
5519
|
+
}
|
|
5520
|
+
if (typeof input === "string") {
|
|
5521
|
+
if (!isFileSystemAvailable()) {
|
|
5522
|
+
throw new Error(
|
|
5523
|
+
'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])'
|
|
5524
|
+
);
|
|
5525
|
+
}
|
|
5526
|
+
return loadFromFileSystem(input, compiledClassHash);
|
|
5527
|
+
}
|
|
5528
|
+
throw new Error(
|
|
5529
|
+
"Invalid input type. Expected string (Node.js path) or File/File[] (browser File API)"
|
|
5530
|
+
);
|
|
5531
|
+
}
|
|
5532
|
+
function loadFromFileSystem(contractPath, compiledClassHash) {
|
|
5533
|
+
const fs = __require("fs");
|
|
5534
|
+
const path = __require("path");
|
|
5535
|
+
const resolvedPath = path.resolve(contractPath);
|
|
5536
|
+
let dirPath;
|
|
5537
|
+
let specifiedSierraFile;
|
|
5538
|
+
let specifiedCasmFile;
|
|
5539
|
+
const stats = fs.statSync(resolvedPath);
|
|
5540
|
+
if (stats.isFile()) {
|
|
5541
|
+
dirPath = path.dirname(resolvedPath);
|
|
5542
|
+
const fileName = path.basename(resolvedPath);
|
|
5543
|
+
if (fileName.endsWith(".sierra.json") || fileName.endsWith(".json") && !fileName.endsWith(".casm")) {
|
|
5544
|
+
specifiedSierraFile = fileName;
|
|
5545
|
+
} else if (fileName.endsWith(".casm")) {
|
|
5546
|
+
specifiedCasmFile = fileName;
|
|
5547
|
+
} else {
|
|
5548
|
+
throw new Error(
|
|
5549
|
+
`Invalid file type. Expected .json, .sierra.json, or .casm file, got: ${fileName}`
|
|
5550
|
+
);
|
|
5551
|
+
}
|
|
5552
|
+
} else if (stats.isDirectory()) {
|
|
5553
|
+
dirPath = resolvedPath;
|
|
5554
|
+
} else {
|
|
5555
|
+
throw new Error(`Path is neither a file nor a directory: ${contractPath}`);
|
|
5556
|
+
}
|
|
5557
|
+
const files = fs.readdirSync(dirPath);
|
|
5558
|
+
let sierraFile;
|
|
5559
|
+
let casmFile;
|
|
5560
|
+
if (specifiedSierraFile) {
|
|
5561
|
+
sierraFile = specifiedSierraFile;
|
|
5562
|
+
const baseName = sierraFile.replace(/\.sierra\.json$/, "").replace(/\.json$/, "");
|
|
5563
|
+
casmFile = files.find((f) => f === `${baseName}.casm`);
|
|
5564
|
+
} else if (specifiedCasmFile) {
|
|
5565
|
+
casmFile = specifiedCasmFile;
|
|
5566
|
+
const baseName = casmFile.replace(/\.casm$/, "");
|
|
5567
|
+
sierraFile = files.find((f) => f === `${baseName}.sierra.json`) || files.find((f) => f === `${baseName}.json`);
|
|
5568
|
+
} else {
|
|
5569
|
+
const sierraFiles = files.filter(
|
|
5570
|
+
(f) => f.endsWith(".sierra.json") || f.endsWith(".json") && !f.endsWith(".casm")
|
|
5571
|
+
);
|
|
5572
|
+
if (sierraFiles.length === 0) {
|
|
5573
|
+
throw new Error(`No .sierra.json file found in ${dirPath}. Sierra file is required.`);
|
|
5574
|
+
}
|
|
5575
|
+
if (sierraFiles.length > 1) {
|
|
5576
|
+
throw new Error(
|
|
5577
|
+
`Multiple .sierra.json files found in ${dirPath}: ${sierraFiles.join(", ")}. Please specify which file to use.`
|
|
5578
|
+
);
|
|
5579
|
+
}
|
|
5580
|
+
[sierraFile] = sierraFiles;
|
|
5581
|
+
const baseName = sierraFile.replace(/\.sierra\.json$/, "").replace(/\.json$/, "");
|
|
5582
|
+
casmFile = files.find((f) => f === `${baseName}.casm`);
|
|
5583
|
+
}
|
|
5584
|
+
if (!sierraFile) {
|
|
5585
|
+
throw new Error(`No .sierra.json file found in ${dirPath}. Sierra file is required.`);
|
|
5586
|
+
}
|
|
5587
|
+
const sierraPath = path.join(dirPath, sierraFile);
|
|
5588
|
+
const sierraContent = parse2(fs.readFileSync(sierraPath, "utf8"));
|
|
5589
|
+
if (casmFile) {
|
|
5590
|
+
const casmPath = path.join(dirPath, casmFile);
|
|
5591
|
+
const casmContent = parse2(fs.readFileSync(casmPath, "utf8"));
|
|
5592
|
+
return {
|
|
5593
|
+
sierra: sierraContent,
|
|
5594
|
+
casm: casmContent,
|
|
5595
|
+
compiler: casmContent.compiler_version
|
|
5596
|
+
};
|
|
5597
|
+
}
|
|
5598
|
+
if (!compiledClassHash) {
|
|
5599
|
+
throw new Error(
|
|
5600
|
+
`No .casm file found for ${sierraFile} and no compiledClassHash provided. Either provide a .casm file or pass compiledClassHash as second parameter.`
|
|
5601
|
+
);
|
|
5602
|
+
}
|
|
5603
|
+
return {
|
|
5604
|
+
sierra: sierraContent,
|
|
5605
|
+
compiledClassHash
|
|
5606
|
+
};
|
|
5607
|
+
}
|
|
5608
|
+
async function loadFromFileAPI(input, compiledClassHash) {
|
|
5609
|
+
const files = Array.isArray(input) ? input : [input];
|
|
5610
|
+
if (files.length === 0) {
|
|
5611
|
+
throw new Error("No files provided");
|
|
5612
|
+
}
|
|
5613
|
+
const sierraFiles = files.filter(
|
|
5614
|
+
(file) => file.name.endsWith(".sierra.json") || file.name.endsWith(".json") && !file.name.endsWith(".casm")
|
|
5615
|
+
);
|
|
5616
|
+
const casmFiles = files.filter((file) => file.name.endsWith(".casm"));
|
|
5617
|
+
if (sierraFiles.length > 1) {
|
|
5618
|
+
throw new Error(
|
|
5619
|
+
`Multiple .sierra.json files provided: ${sierraFiles.map((f) => f.name).join(", ")}. Please provide only one sierra file.`
|
|
5620
|
+
);
|
|
5621
|
+
}
|
|
5622
|
+
if (casmFiles.length > 1) {
|
|
5623
|
+
throw new Error(
|
|
5624
|
+
`Multiple .casm files provided: ${casmFiles.map((f) => f.name).join(", ")}. Please provide only one casm file.`
|
|
5625
|
+
);
|
|
5626
|
+
}
|
|
5627
|
+
const sierraFile = sierraFiles[0];
|
|
5628
|
+
const casmFile = casmFiles[0];
|
|
5629
|
+
if (!sierraFile) {
|
|
5630
|
+
throw new Error(
|
|
5631
|
+
`No .sierra.json file found in provided files. Sierra file is required. Provided files: ${files.map((f) => f.name).join(", ")}`
|
|
5632
|
+
);
|
|
5633
|
+
}
|
|
5634
|
+
const sierraContent = parse2(await readFileAsText(sierraFile));
|
|
5635
|
+
if (casmFile) {
|
|
5636
|
+
const casmContent = parse2(await readFileAsText(casmFile));
|
|
5637
|
+
return {
|
|
5638
|
+
sierra: sierraContent,
|
|
5639
|
+
casm: casmContent,
|
|
5640
|
+
compiler: casmContent.compiler_version
|
|
5641
|
+
};
|
|
5642
|
+
}
|
|
5643
|
+
if (!compiledClassHash) {
|
|
5644
|
+
throw new Error(
|
|
5645
|
+
"No .casm file found in provided files and no compiledClassHash provided. Either provide a .casm file or pass compiledClassHash as second parameter."
|
|
5646
|
+
);
|
|
5647
|
+
}
|
|
5648
|
+
return {
|
|
5649
|
+
sierra: sierraContent,
|
|
5650
|
+
compiledClassHash
|
|
5651
|
+
};
|
|
5652
|
+
}
|
|
5653
|
+
function readFileAsText(file) {
|
|
5654
|
+
return new Promise((resolve, reject) => {
|
|
5655
|
+
const reader = new FileReader();
|
|
5656
|
+
reader.onload = (event) => {
|
|
5657
|
+
const content = event.target?.result;
|
|
5658
|
+
if (typeof content === "string") {
|
|
5659
|
+
resolve(content);
|
|
5660
|
+
} else {
|
|
5661
|
+
reject(new Error(`Failed to read file ${file.name} as text`));
|
|
5662
|
+
}
|
|
5663
|
+
};
|
|
5664
|
+
reader.onerror = () => {
|
|
5665
|
+
reject(new Error(`Failed to read file ${file.name}: ${reader.error?.message}`));
|
|
5666
|
+
};
|
|
5667
|
+
reader.readAsText(file);
|
|
5668
|
+
});
|
|
5669
|
+
}
|
|
5670
|
+
|
|
5501
5671
|
// src/utils/contract.ts
|
|
5502
5672
|
function isSierra(contract) {
|
|
5503
5673
|
const compiledContract = isString(contract) ? parse2(contract) : contract;
|
|
@@ -12894,6 +13064,7 @@ export {
|
|
|
12894
13064
|
config,
|
|
12895
13065
|
constants_exports as constants,
|
|
12896
13066
|
contractClassResponseToLegacyCompiledContract,
|
|
13067
|
+
contractLoader,
|
|
12897
13068
|
createAbiParser,
|
|
12898
13069
|
createTransactionReceipt,
|
|
12899
13070
|
defaultDeployer,
|
|
@@ -12915,6 +13086,7 @@ export {
|
|
|
12915
13086
|
hash_exports as hash,
|
|
12916
13087
|
hdParsingStrategy,
|
|
12917
13088
|
isAccount,
|
|
13089
|
+
isFileSystemAvailable,
|
|
12918
13090
|
isNoConstructorValid,
|
|
12919
13091
|
isPreConfirmedBlock,
|
|
12920
13092
|
isPreConfirmedStateUpdate,
|