@hardkas/sdk 0.7.10-alpha → 0.7.12-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/README.md +40 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +70 -2
- package/package.json +13 -13
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# `@hardkas/sdk`
|
|
2
|
+
|
|
3
|
+
The HardKAS SDK acts as the programmatic boundary between developer scripts and the isolated HardKAS runtime engine.
|
|
4
|
+
|
|
5
|
+
## 1. Bootstrapping Variants
|
|
6
|
+
|
|
7
|
+
The SDK injects dependencies via a `RuntimeContext` container. This container abstracts the filesystem, logging, and RPC configurations.
|
|
8
|
+
|
|
9
|
+
### Flow: Auto-Bootstrap
|
|
10
|
+
```typescript
|
|
11
|
+
const sdk = await Hardkas.create({ autoBootstrap: true });
|
|
12
|
+
```
|
|
13
|
+
1. The engine scans upward from `process.cwd()` to find `.hardkas/`.
|
|
14
|
+
2. It acquires necessary read/write workspace locks.
|
|
15
|
+
3. If the workspace does not exist, it automatically creates it, generating a new developer identity and local configuration.
|
|
16
|
+
|
|
17
|
+
### Variant: Manual Policy Engine
|
|
18
|
+
When running inside an AI agent (like KI) or CI environment, `autoBootstrap` is disabled.
|
|
19
|
+
1. The SDK enforces the 4 Policy Dimensions (Local isolation, Determinism, Replayability, Mainnet Guards).
|
|
20
|
+
2. It calls `hardkas doctor --json` internally before initializing.
|
|
21
|
+
3. If the environment fails policy checks (e.g., trying to write to mainnet without the explicit `--unsafe-mainnet` flag), the instantiation throws synchronously.
|
|
22
|
+
|
|
23
|
+
## 2. Transaction Flow & Dry-Runs
|
|
24
|
+
|
|
25
|
+
All SDK transaction methods follow the Plan -> Sign -> Broadcast pipeline.
|
|
26
|
+
|
|
27
|
+
### Flow: `sdk.tx.plan`
|
|
28
|
+
1. The SDK calculates the deterministic payload size.
|
|
29
|
+
2. It interacts with the `Query Store` to fetch available UXTOs (for L1) or Nonces (for L2).
|
|
30
|
+
3. It emits a `PlanCreated` event to the `events.jsonl` ledger.
|
|
31
|
+
4. It persists a `TxPlan` artifact in `.hardkas/artifacts/`.
|
|
32
|
+
|
|
33
|
+
### Variant: Dry-Run Execution
|
|
34
|
+
```typescript
|
|
35
|
+
const plan = await sdk.tx.plan({ to, amount, dryRun: true });
|
|
36
|
+
```
|
|
37
|
+
1. The SDK skips steps 3 and 4.
|
|
38
|
+
2. No locks are acquired.
|
|
39
|
+
3. No events are emitted to the append-only ledger.
|
|
40
|
+
4. The plan is returned purely in-memory as a preview object, which throws an exception if you attempt to pass it into `sdk.tx.sign`.
|
package/dist/index.d.ts
CHANGED
|
@@ -89,9 +89,16 @@ declare class HardkasTx {
|
|
|
89
89
|
/**
|
|
90
90
|
* Sends a signed transaction to the real RPC network.
|
|
91
91
|
*/
|
|
92
|
-
send(signedArtifact: SignedTxArtifact,
|
|
92
|
+
send(signedArtifact: SignedTxArtifact, urlOrOptions?: string | {
|
|
93
|
+
persist?: boolean;
|
|
94
|
+
}): Promise<{
|
|
93
95
|
receipt: TxReceiptArtifact;
|
|
94
|
-
receiptPath
|
|
96
|
+
receiptPath?: string;
|
|
97
|
+
artifactId?: string;
|
|
98
|
+
mode?: string;
|
|
99
|
+
simulated?: boolean;
|
|
100
|
+
submitted?: boolean;
|
|
101
|
+
txId?: string;
|
|
95
102
|
}>;
|
|
96
103
|
/**
|
|
97
104
|
* Explicitly appends a signature to a partially signed transaction.
|
package/dist/index.js
CHANGED
|
@@ -440,7 +440,28 @@ var HardkasTx = class {
|
|
|
440
440
|
try {
|
|
441
441
|
planArtifact = await this.sdk.artifacts.read(sourcePlanId);
|
|
442
442
|
} catch (e) {
|
|
443
|
-
|
|
443
|
+
if (targetObj.from && targetObj.to && targetObj.amountSompi) {
|
|
444
|
+
planArtifact = {
|
|
445
|
+
schema: "hardkas.txPlan",
|
|
446
|
+
planId: sourcePlanId,
|
|
447
|
+
from: targetObj.from,
|
|
448
|
+
to: targetObj.to,
|
|
449
|
+
amountSompi: targetObj.amountSompi,
|
|
450
|
+
estimatedFeeSompi: "0",
|
|
451
|
+
estimatedMass: "0",
|
|
452
|
+
inputs: [],
|
|
453
|
+
outputs: [{ address: targetObj.to.address, amountSompi: targetObj.amountSompi || "0" }],
|
|
454
|
+
plan: {
|
|
455
|
+
inputs: [],
|
|
456
|
+
outputs: [{ address: targetObj.to.address, amountSompi: BigInt(targetObj.amountSompi || 0) }],
|
|
457
|
+
feeSompi: 0n,
|
|
458
|
+
mass: 0n,
|
|
459
|
+
changeSompi: 0n
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
} else {
|
|
463
|
+
throw new Error(`Cannot simulate signed artifact: source plan '${sourcePlanId}' not found in workspace and artifact lacks details.`);
|
|
464
|
+
}
|
|
444
465
|
}
|
|
445
466
|
} else {
|
|
446
467
|
planArtifact = targetObj;
|
|
@@ -563,13 +584,60 @@ var HardkasTx = class {
|
|
|
563
584
|
/**
|
|
564
585
|
* Sends a signed transaction to the real RPC network.
|
|
565
586
|
*/
|
|
566
|
-
async send(signedArtifact,
|
|
587
|
+
async send(signedArtifact, urlOrOptions) {
|
|
567
588
|
const verification = verifySignedTxSemantics(signedArtifact);
|
|
568
589
|
if (!verification.ok) {
|
|
569
590
|
throw new Error(
|
|
570
591
|
`Pre-broadcast semantic verification failed: ${verification.issues.map((i) => i.message).join(", ")}`
|
|
571
592
|
);
|
|
572
593
|
}
|
|
594
|
+
const activeNetwork = this.sdk.config.config.defaultNetwork || "simnet";
|
|
595
|
+
const isSimulated = activeNetwork === "simulated" || this.sdk.config.config.networks?.[activeNetwork]?.kind === "simulated";
|
|
596
|
+
if (isSimulated) {
|
|
597
|
+
const persistOpt = typeof urlOrOptions === "object" ? urlOrOptions.persist : true;
|
|
598
|
+
const simOpts = persistOpt !== void 0 ? { persist: persistOpt } : {};
|
|
599
|
+
let simResult;
|
|
600
|
+
try {
|
|
601
|
+
simResult = await this.simulate(signedArtifact, simOpts);
|
|
602
|
+
} catch (e) {
|
|
603
|
+
if (e.message && e.message.includes("invalid simulated input")) {
|
|
604
|
+
try {
|
|
605
|
+
const { loadSimulatedReceipt, getReceiptPath } = await import("@hardkas/localnet");
|
|
606
|
+
const txIdToLoad = signedArtifact.txId || `simulated-${signedArtifact.sourcePlanId}-tx`;
|
|
607
|
+
const existingReceipt = await loadSimulatedReceipt(txIdToLoad, { cwd: this.sdk.workspace.root });
|
|
608
|
+
if (existingReceipt) {
|
|
609
|
+
if (existingReceipt.schema === ARTIFACT_SCHEMAS.TX_RECEIPT && (existingReceipt.status === "confirmed" || existingReceipt.status === "accepted")) {
|
|
610
|
+
return {
|
|
611
|
+
mode: "simulated",
|
|
612
|
+
simulated: true,
|
|
613
|
+
submitted: false,
|
|
614
|
+
txId: existingReceipt.txId,
|
|
615
|
+
artifactId: existingReceipt.txId,
|
|
616
|
+
// simulated receipts use txId as artifactId
|
|
617
|
+
receipt: existingReceipt,
|
|
618
|
+
receiptPath: getReceiptPath(existingReceipt.txId, this.sdk.workspace.root)
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
} catch (err) {
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
throw e;
|
|
626
|
+
}
|
|
627
|
+
const result2 = {
|
|
628
|
+
mode: "simulated",
|
|
629
|
+
simulated: true,
|
|
630
|
+
submitted: false,
|
|
631
|
+
txId: simResult.receipt.txId,
|
|
632
|
+
artifactId: simResult.receipt.artifactId ?? simResult.artifactId ?? simResult.receipt.contentHash,
|
|
633
|
+
receipt: simResult.receipt
|
|
634
|
+
};
|
|
635
|
+
if (simResult.receiptPath !== void 0) {
|
|
636
|
+
result2.receiptPath = simResult.receiptPath;
|
|
637
|
+
}
|
|
638
|
+
return result2;
|
|
639
|
+
}
|
|
640
|
+
const url = typeof urlOrOptions === "string" ? urlOrOptions : void 0;
|
|
573
641
|
const broadcastable = getBroadcastableSignedTransaction(signedArtifact);
|
|
574
642
|
const broadcastRecord = broadcastable.rawTransaction;
|
|
575
643
|
const txId = broadcastRecord.id || "unknown";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@hardkas/
|
|
27
|
-
"@hardkas/
|
|
28
|
-
"@hardkas/
|
|
29
|
-
"@hardkas/
|
|
30
|
-
"@hardkas/
|
|
31
|
-
"@hardkas/
|
|
32
|
-
"@hardkas/localnet": "0.7.
|
|
33
|
-
"@hardkas/
|
|
34
|
-
"@hardkas/
|
|
35
|
-
"@hardkas/tx-builder": "0.7.
|
|
36
|
-
"@hardkas/
|
|
37
|
-
"@hardkas/
|
|
26
|
+
"@hardkas/accounts": "0.7.12-alpha",
|
|
27
|
+
"@hardkas/config": "0.7.12-alpha",
|
|
28
|
+
"@hardkas/core": "0.7.12-alpha",
|
|
29
|
+
"@hardkas/artifacts": "0.7.12-alpha",
|
|
30
|
+
"@hardkas/l2": "0.7.12-alpha",
|
|
31
|
+
"@hardkas/kaspa-rpc": "0.7.12-alpha",
|
|
32
|
+
"@hardkas/localnet": "0.7.12-alpha",
|
|
33
|
+
"@hardkas/query": "0.7.12-alpha",
|
|
34
|
+
"@hardkas/simulator": "0.7.12-alpha",
|
|
35
|
+
"@hardkas/tx-builder": "0.7.12-alpha",
|
|
36
|
+
"@hardkas/wallet-adapter": "0.7.12-alpha",
|
|
37
|
+
"@hardkas/query-store": "0.7.12-alpha"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsup": "^8.3.5",
|