@hardkas/sdk 0.7.5-alpha → 0.7.6-alpha
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.js +147 -42
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -378,7 +378,10 @@ var HardkasTx = class {
|
|
|
378
378
|
endpoint: "simulated://local"
|
|
379
379
|
});
|
|
380
380
|
events.push({ type: "phase.completed", phase: "send", timestamp: Date.now() });
|
|
381
|
-
await saveLocalnetState(
|
|
381
|
+
await saveLocalnetState(
|
|
382
|
+
simResult.state,
|
|
383
|
+
getDefaultLocalnetStatePath(this.sdk.workspace.root)
|
|
384
|
+
);
|
|
382
385
|
const receiptPath = await saveSimulatedReceipt(
|
|
383
386
|
simResult.receipt,
|
|
384
387
|
{ cwd: this.sdk.workspace.root }
|
|
@@ -431,11 +434,14 @@ var HardkasTx = class {
|
|
|
431
434
|
steps: traceSteps
|
|
432
435
|
};
|
|
433
436
|
traceBase.contentHash = calculateContentHash(traceBase, CURRENT_HASH_VERSION);
|
|
434
|
-
await saveSimulatedTrace(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
437
|
+
await saveSimulatedTrace(
|
|
438
|
+
{
|
|
439
|
+
...traceBase,
|
|
440
|
+
events,
|
|
441
|
+
receiptPath
|
|
442
|
+
},
|
|
443
|
+
{ cwd: this.sdk.workspace.root }
|
|
444
|
+
);
|
|
439
445
|
coreEvents.normalizeAndEmit({
|
|
440
446
|
kind: "artifact.created",
|
|
441
447
|
schema: receipt.schema,
|
|
@@ -588,6 +594,124 @@ import {
|
|
|
588
594
|
verifyArtifactIntegrity,
|
|
589
595
|
writeArtifact as writeArtifact2
|
|
590
596
|
} from "@hardkas/artifacts";
|
|
597
|
+
function resolveReplayTargets(cwd, options) {
|
|
598
|
+
if (options.path) {
|
|
599
|
+
const fullPath = path.resolve(cwd, options.path);
|
|
600
|
+
if (!fs.existsSync(fullPath)) {
|
|
601
|
+
throw new Error(`Path not found: ${options.path}`);
|
|
602
|
+
}
|
|
603
|
+
if (fs.statSync(fullPath).isFile()) {
|
|
604
|
+
const dir = path.dirname(fullPath);
|
|
605
|
+
let planId = "";
|
|
606
|
+
try {
|
|
607
|
+
const data = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
|
|
608
|
+
planId = data.planId || "";
|
|
609
|
+
} catch {
|
|
610
|
+
}
|
|
611
|
+
let receiptPath = "";
|
|
612
|
+
if (planId) {
|
|
613
|
+
receiptPath = findReceiptByPlanId(dir, planId);
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
planPath: fullPath,
|
|
617
|
+
receiptPath,
|
|
618
|
+
artifactDir: dir,
|
|
619
|
+
source: "explicit-file"
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
return resolveFromDirectory(fullPath, "explicit-dir");
|
|
623
|
+
}
|
|
624
|
+
if (options.workflowId) {
|
|
625
|
+
return {
|
|
626
|
+
planPath: path.join(cwd, "tx-plan.json"),
|
|
627
|
+
receiptPath: path.join(cwd, "tx-receipt.json"),
|
|
628
|
+
artifactDir: cwd,
|
|
629
|
+
source: "workflow-id"
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
const artifactsDir = path.join(cwd, ".hardkas", "artifacts");
|
|
633
|
+
if (!fs.existsSync(artifactsDir) || !fs.statSync(artifactsDir).isDirectory()) {
|
|
634
|
+
throw new Error(
|
|
635
|
+
`No .hardkas/artifacts/ directory found.
|
|
636
|
+
Hint: Run 'hardkas init' first, then execute a transaction.`
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
return resolveFromDirectory(artifactsDir, "artifact-scan");
|
|
640
|
+
}
|
|
641
|
+
function resolveFromDirectory(dir, source) {
|
|
642
|
+
const allFiles = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
643
|
+
const plans = [];
|
|
644
|
+
const receipts = [];
|
|
645
|
+
for (const f of allFiles) {
|
|
646
|
+
try {
|
|
647
|
+
const raw = fs.readFileSync(path.join(dir, f), "utf-8");
|
|
648
|
+
const data = JSON.parse(raw);
|
|
649
|
+
if (!data || !data.schema) continue;
|
|
650
|
+
if (data.schema === "hardkas.txPlan") {
|
|
651
|
+
plans.push({
|
|
652
|
+
file: f,
|
|
653
|
+
planId: data.planId || "",
|
|
654
|
+
createdAt: data.createdAt || ""
|
|
655
|
+
});
|
|
656
|
+
} else if (data.schema === "hardkas.txReceipt") {
|
|
657
|
+
receipts.push({
|
|
658
|
+
file: f,
|
|
659
|
+
sourcePlanId: data.sourcePlanId || data.lineage?.parentArtifactId || data.lineage?.rootArtifactId || "",
|
|
660
|
+
txId: data.txId || "",
|
|
661
|
+
createdAt: data.createdAt || ""
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
} catch {
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (plans.length === 0) {
|
|
668
|
+
throw new Error(
|
|
669
|
+
`No plan artifacts found in ${dir}.
|
|
670
|
+
Hint: Run a transaction first: hardkas tx send --from alice --to bob --amount 10 --network simulated --yes`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
plans.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
674
|
+
for (const plan of plans) {
|
|
675
|
+
const matchingReceipt = receipts.find(
|
|
676
|
+
(r) => (
|
|
677
|
+
// Direct sourcePlanId match
|
|
678
|
+
r.sourcePlanId && r.sourcePlanId === plan.planId || // txId derived from planId (e.g., "simulated-plan-xxx-tx" contains "plan-xxx")
|
|
679
|
+
r.txId && plan.planId && r.txId.includes(plan.planId)
|
|
680
|
+
)
|
|
681
|
+
);
|
|
682
|
+
if (matchingReceipt) {
|
|
683
|
+
return {
|
|
684
|
+
planPath: path.join(dir, plan.file),
|
|
685
|
+
receiptPath: path.join(dir, matchingReceipt.file),
|
|
686
|
+
artifactDir: dir,
|
|
687
|
+
source
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
const bestPlan = plans[0];
|
|
692
|
+
return {
|
|
693
|
+
planPath: path.join(dir, bestPlan.file),
|
|
694
|
+
receiptPath: "",
|
|
695
|
+
// Will trigger actionable error downstream
|
|
696
|
+
artifactDir: dir,
|
|
697
|
+
source
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
function findReceiptByPlanId(dir, planId) {
|
|
701
|
+
if (!fs.existsSync(dir)) return "";
|
|
702
|
+
const files = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
703
|
+
for (const f of files) {
|
|
704
|
+
try {
|
|
705
|
+
const raw = fs.readFileSync(path.join(dir, f), "utf-8");
|
|
706
|
+
const data = JSON.parse(raw);
|
|
707
|
+
if (data && data.schema === "hardkas.txReceipt" && (data.sourcePlanId && data.sourcePlanId === planId || data.lineage?.parentArtifactId && data.lineage.parentArtifactId === planId || data.lineage?.rootArtifactId && data.lineage.rootArtifactId === planId || data.txId && data.txId.includes(planId))) {
|
|
708
|
+
return path.join(dir, f);
|
|
709
|
+
}
|
|
710
|
+
} catch {
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return "";
|
|
714
|
+
}
|
|
591
715
|
var HardkasReplay = class {
|
|
592
716
|
constructor(sdk) {
|
|
593
717
|
this.sdk = sdk;
|
|
@@ -598,36 +722,8 @@ var HardkasReplay = class {
|
|
|
598
722
|
* against the mathematically reconstructed localnet state.
|
|
599
723
|
*/
|
|
600
724
|
async verify(options) {
|
|
601
|
-
|
|
602
|
-
let planPath
|
|
603
|
-
let receiptPath = path.join(artifactDir, "tx-receipt.json");
|
|
604
|
-
if (options.path) {
|
|
605
|
-
const fullPath = path.resolve(this.sdk.config.cwd, options.path);
|
|
606
|
-
if (fs.existsSync(fullPath)) {
|
|
607
|
-
if (fs.statSync(fullPath).isFile()) {
|
|
608
|
-
planPath = fullPath;
|
|
609
|
-
artifactDir = path.dirname(fullPath);
|
|
610
|
-
receiptPath = fullPath.replace("tx-plan", "tx-receipt");
|
|
611
|
-
try {
|
|
612
|
-
let content = fs.readFileSync(fullPath, "utf-8");
|
|
613
|
-
if (content.charCodeAt(0) === 65279) {
|
|
614
|
-
content = content.slice(1);
|
|
615
|
-
}
|
|
616
|
-
const json = JSON.parse(content);
|
|
617
|
-
if (json && json.schema === "hardkas.workflow.v1" && json.workflowId) {
|
|
618
|
-
options.workflowId = json.workflowId;
|
|
619
|
-
}
|
|
620
|
-
} catch (e) {
|
|
621
|
-
}
|
|
622
|
-
} else {
|
|
623
|
-
artifactDir = fullPath;
|
|
624
|
-
planPath = path.join(artifactDir, "tx-plan.json");
|
|
625
|
-
receiptPath = path.join(artifactDir, "tx-receipt.json");
|
|
626
|
-
}
|
|
627
|
-
} else {
|
|
628
|
-
throw new Error(`Path not found: ${options.path}`);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
725
|
+
const targets = resolveReplayTargets(this.sdk.config.cwd, options);
|
|
726
|
+
let { planPath, receiptPath, artifactDir } = targets;
|
|
631
727
|
if (!fs.existsSync(path.join(this.sdk.config.cwd, "hardkas.config.ts"))) {
|
|
632
728
|
throw new Error(`Workspace not found at ${this.sdk.config.cwd}`);
|
|
633
729
|
}
|
|
@@ -737,12 +833,15 @@ var HardkasReplay = class {
|
|
|
737
833
|
lineageOk = false;
|
|
738
834
|
determinismOk = false;
|
|
739
835
|
}
|
|
740
|
-
} else if (
|
|
836
|
+
} else if (targets.source !== "none") {
|
|
741
837
|
try {
|
|
742
838
|
if (!fs.existsSync(planPath))
|
|
743
839
|
throw new Error(`Transaction plan artifact is missing at: ${planPath}`);
|
|
744
|
-
if (!fs.existsSync(receiptPath))
|
|
745
|
-
throw new Error(
|
|
840
|
+
if (!receiptPath || !fs.existsSync(receiptPath))
|
|
841
|
+
throw new Error(
|
|
842
|
+
`No matching receipt artifact found for plan at: ${planPath}
|
|
843
|
+
Hint: Run 'hardkas tx send --from alice --to bob --amount 10 --network simulated --yes' to create a complete plan\u2192sign\u2192send chain.`
|
|
844
|
+
);
|
|
746
845
|
plan = await readTxPlanArtifact(planPath);
|
|
747
846
|
receipt = await readTxReceiptArtifact2(receiptPath);
|
|
748
847
|
} catch (err) {
|
|
@@ -1003,7 +1102,9 @@ var HardkasWorkflow = class {
|
|
|
1003
1102
|
},
|
|
1004
1103
|
sign: async (plan, account) => {
|
|
1005
1104
|
const signed = await this.sdk.tx.sign(plan, account);
|
|
1006
|
-
await this.sdk.artifacts.write(signed, {
|
|
1105
|
+
await this.sdk.artifacts.write(signed, {
|
|
1106
|
+
dryRun: options.dryRun ?? false
|
|
1107
|
+
});
|
|
1007
1108
|
const signedRecord = signed;
|
|
1008
1109
|
const id = signedRecord.contentHash || signedRecord.artifactId || signed.signedId;
|
|
1009
1110
|
if (id) producedArtifacts.push(id);
|
|
@@ -1016,7 +1117,9 @@ var HardkasWorkflow = class {
|
|
|
1016
1117
|
"Workflow script requested real broadcast"
|
|
1017
1118
|
);
|
|
1018
1119
|
const res = this.sdk.network === "simulated" ? await this.sdk.tx.simulate(signed) : await this.sdk.tx.send(signed);
|
|
1019
|
-
await this.sdk.artifacts.write(res.receipt, {
|
|
1120
|
+
await this.sdk.artifacts.write(res.receipt, {
|
|
1121
|
+
dryRun: options.dryRun ?? false
|
|
1122
|
+
});
|
|
1020
1123
|
const receiptRecord = res.receipt;
|
|
1021
1124
|
const id = receiptRecord.contentHash || receiptRecord.artifactId || receiptRecord.txId;
|
|
1022
1125
|
if (id) producedArtifacts.push(id);
|
|
@@ -1024,7 +1127,9 @@ var HardkasWorkflow = class {
|
|
|
1024
1127
|
},
|
|
1025
1128
|
simulate: async (signed) => {
|
|
1026
1129
|
const res = await this.sdk.tx.simulate(signed);
|
|
1027
|
-
await this.sdk.artifacts.write(res.receipt, {
|
|
1130
|
+
await this.sdk.artifacts.write(res.receipt, {
|
|
1131
|
+
dryRun: options.dryRun ?? false
|
|
1132
|
+
});
|
|
1028
1133
|
const receiptRecord = res.receipt;
|
|
1029
1134
|
const id = receiptRecord.contentHash || receiptRecord.artifactId || receiptRecord.txId;
|
|
1030
1135
|
if (id) producedArtifacts.push(id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -23,23 +23,23 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@hardkas/
|
|
27
|
-
"@hardkas/artifacts": "0.7.
|
|
28
|
-
"@hardkas/
|
|
29
|
-
"@hardkas/core": "0.7.
|
|
30
|
-
"@hardkas/
|
|
31
|
-
"@hardkas/
|
|
32
|
-
"@hardkas/
|
|
33
|
-
"@hardkas/
|
|
34
|
-
"@hardkas/tx-builder": "0.7.
|
|
35
|
-
"@hardkas/
|
|
36
|
-
"@hardkas/
|
|
26
|
+
"@hardkas/config": "0.7.6-alpha",
|
|
27
|
+
"@hardkas/artifacts": "0.7.6-alpha",
|
|
28
|
+
"@hardkas/accounts": "0.7.6-alpha",
|
|
29
|
+
"@hardkas/core": "0.7.6-alpha",
|
|
30
|
+
"@hardkas/l2": "0.7.6-alpha",
|
|
31
|
+
"@hardkas/simulator": "0.7.6-alpha",
|
|
32
|
+
"@hardkas/localnet": "0.7.6-alpha",
|
|
33
|
+
"@hardkas/query": "0.7.6-alpha",
|
|
34
|
+
"@hardkas/tx-builder": "0.7.6-alpha",
|
|
35
|
+
"@hardkas/wallet-adapter": "0.7.6-alpha",
|
|
36
|
+
"@hardkas/kaspa-rpc": "0.7.6-alpha"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^8.3.5",
|
|
40
40
|
"typescript": "^5.7.2",
|
|
41
41
|
"vitest": "^2.1.8",
|
|
42
|
-
"@hardkas/query-store": "0.7.
|
|
42
|
+
"@hardkas/query-store": "0.7.6-alpha"
|
|
43
43
|
},
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"author": "Javier Rodriguez",
|