@hardkas/sdk 0.6.0-alpha → 0.7.0-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/chunk-RCCELGL3.js +102 -0
- package/dist/client.d.ts +84 -0
- package/dist/client.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +35 -12
- package/package.json +19 -13
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
function createHardkasClient(options = {}) {
|
|
3
|
+
const baseUrl = options.baseUrl || "http://127.0.0.1:7420";
|
|
4
|
+
const defaultHeaders = {
|
|
5
|
+
"Content-Type": "application/json",
|
|
6
|
+
"X-Hardkas-Request": "true"
|
|
7
|
+
};
|
|
8
|
+
async function fetchApi(path, init) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(`${baseUrl}${path}`, {
|
|
11
|
+
...init,
|
|
12
|
+
headers: { ...defaultHeaders, ...init?.headers }
|
|
13
|
+
});
|
|
14
|
+
const data = await response.json();
|
|
15
|
+
return data;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
error: { code: "FETCH_FAILED", message: e.message },
|
|
20
|
+
warnings: [],
|
|
21
|
+
meta: { workspace: "unknown", network: options.network || "simulated", mode: "unknown" }
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
accounts: {
|
|
27
|
+
list: () => fetchApi("/api/accounts")
|
|
28
|
+
},
|
|
29
|
+
tx: {
|
|
30
|
+
plan: (params) => fetchApi("/api/tx/plan", { method: "POST", body: JSON.stringify(params) }),
|
|
31
|
+
sign: (params) => fetchApi("/api/tx/sign", { method: "POST", body: JSON.stringify(params) }),
|
|
32
|
+
send: (params) => fetchApi("/api/tx/send", { method: "POST", body: JSON.stringify(params) }),
|
|
33
|
+
receipt: (id) => fetchApi(`/api/tx/receipt/${id}`)
|
|
34
|
+
},
|
|
35
|
+
artifacts: {
|
|
36
|
+
explain: (id) => fetchApi(`/api/artifacts/${id}/explain`),
|
|
37
|
+
replay: (id) => fetchApi(`/api/artifacts/${id}/replay`, { method: "POST" }),
|
|
38
|
+
watch: (callback, options2) => {
|
|
39
|
+
const transport = options2?.transport || "sse";
|
|
40
|
+
const intervalMs = options2?.intervalMs || 2e3;
|
|
41
|
+
let active = true;
|
|
42
|
+
let cleanup = () => {
|
|
43
|
+
active = false;
|
|
44
|
+
};
|
|
45
|
+
if (transport === "sse" && typeof EventSource !== "undefined") {
|
|
46
|
+
try {
|
|
47
|
+
let queryParams = "";
|
|
48
|
+
const queryParts = [];
|
|
49
|
+
if (options2?.type) queryParts.push(`type=${options2.type}`);
|
|
50
|
+
if (options2?.lineage) queryParts.push(`lineage=true`);
|
|
51
|
+
if (options2?.replay) queryParts.push(`replay=true`);
|
|
52
|
+
if (queryParts.length > 0) queryParams = `?${queryParts.join("&")}`;
|
|
53
|
+
const es = new EventSource(`${baseUrl}/api/artifacts/stream${queryParams}`);
|
|
54
|
+
es.onmessage = (e) => {
|
|
55
|
+
try {
|
|
56
|
+
callback(JSON.parse(e.data));
|
|
57
|
+
} catch (err) {
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
cleanup = () => {
|
|
61
|
+
active = false;
|
|
62
|
+
es.close();
|
|
63
|
+
};
|
|
64
|
+
return cleanup;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const poll = async () => {
|
|
69
|
+
while (active) {
|
|
70
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
poll();
|
|
74
|
+
return cleanup;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
workflow: {
|
|
78
|
+
transfer: (params) => {
|
|
79
|
+
return fetchApi("/api/tx/send", { method: "POST", body: JSON.stringify(params) });
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
localnet: {
|
|
83
|
+
status: () => fetchApi("/api/localnet/status")
|
|
84
|
+
},
|
|
85
|
+
dev: {
|
|
86
|
+
status: () => fetchApi("/api/dev/status")
|
|
87
|
+
},
|
|
88
|
+
session: {
|
|
89
|
+
start: () => fetchApi("/api/session/start", { method: "POST" }),
|
|
90
|
+
snapshot: () => fetchApi("/api/session/snapshot", { method: "POST" }),
|
|
91
|
+
replay: (options2) => fetchApi("/api/session/replay", { method: "POST", body: JSON.stringify(options2 || {}) }),
|
|
92
|
+
diffReplay: (artifactId) => fetchApi(`/api/session/diff-replay/${artifactId}`, { method: "POST" }),
|
|
93
|
+
timeTravel: (artifactId) => fetchApi("/api/session/time-travel", { method: "POST", body: JSON.stringify({ artifactId }) }),
|
|
94
|
+
export: () => fetchApi("/api/session/export"),
|
|
95
|
+
import: (data, force) => fetchApi("/api/session/import", { method: "POST", body: JSON.stringify({ data, force }) })
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
createHardkasClient
|
|
102
|
+
};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
interface HardkasClientOptions {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
network?: string;
|
|
4
|
+
}
|
|
5
|
+
interface ClientEnvelope<T> {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
data?: T;
|
|
8
|
+
error?: {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
warnings: string[];
|
|
13
|
+
meta: {
|
|
14
|
+
workspace: string;
|
|
15
|
+
network: string;
|
|
16
|
+
mode?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
declare function createHardkasClient(options?: HardkasClientOptions): {
|
|
20
|
+
accounts: {
|
|
21
|
+
list: () => Promise<ClientEnvelope<any[]>>;
|
|
22
|
+
};
|
|
23
|
+
tx: {
|
|
24
|
+
plan: (params: {
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
amountSompi: string;
|
|
28
|
+
feeRate?: string;
|
|
29
|
+
}) => Promise<ClientEnvelope<any>>;
|
|
30
|
+
sign: (params: {
|
|
31
|
+
planId: string;
|
|
32
|
+
account: string;
|
|
33
|
+
}) => Promise<ClientEnvelope<any>>;
|
|
34
|
+
send: (params: {
|
|
35
|
+
signedTxId?: string;
|
|
36
|
+
from?: string;
|
|
37
|
+
to?: string;
|
|
38
|
+
amountSompi?: string;
|
|
39
|
+
feeRate?: string;
|
|
40
|
+
allowDevAutoSign?: boolean;
|
|
41
|
+
}) => Promise<ClientEnvelope<any>>;
|
|
42
|
+
receipt: (id: string) => Promise<ClientEnvelope<any>>;
|
|
43
|
+
};
|
|
44
|
+
artifacts: {
|
|
45
|
+
explain: (id: string) => Promise<ClientEnvelope<any>>;
|
|
46
|
+
replay: (id: string) => Promise<ClientEnvelope<any>>;
|
|
47
|
+
watch: (callback: (artifact: any) => void, options?: {
|
|
48
|
+
type?: string;
|
|
49
|
+
lineage?: boolean;
|
|
50
|
+
replay?: boolean;
|
|
51
|
+
transport?: "sse" | "poll";
|
|
52
|
+
intervalMs?: number;
|
|
53
|
+
}) => () => void;
|
|
54
|
+
};
|
|
55
|
+
workflow: {
|
|
56
|
+
transfer: (params: {
|
|
57
|
+
from: string;
|
|
58
|
+
to: string;
|
|
59
|
+
amountSompi: string;
|
|
60
|
+
feeRate?: string;
|
|
61
|
+
allowDevAutoSign?: boolean;
|
|
62
|
+
}) => Promise<ClientEnvelope<any>>;
|
|
63
|
+
};
|
|
64
|
+
localnet: {
|
|
65
|
+
status: () => Promise<ClientEnvelope<any>>;
|
|
66
|
+
};
|
|
67
|
+
dev: {
|
|
68
|
+
status: () => Promise<ClientEnvelope<any>>;
|
|
69
|
+
};
|
|
70
|
+
session: {
|
|
71
|
+
start: () => Promise<ClientEnvelope<any>>;
|
|
72
|
+
snapshot: () => Promise<ClientEnvelope<any>>;
|
|
73
|
+
replay: (options?: {
|
|
74
|
+
untilArtifact?: string;
|
|
75
|
+
strict?: boolean;
|
|
76
|
+
}) => Promise<ClientEnvelope<any>>;
|
|
77
|
+
diffReplay: (artifactId: string) => Promise<ClientEnvelope<any>>;
|
|
78
|
+
timeTravel: (artifactId: string) => Promise<ClientEnvelope<any>>;
|
|
79
|
+
export: () => Promise<ClientEnvelope<any>>;
|
|
80
|
+
import: (data: any, force?: boolean) => Promise<ClientEnvelope<any>>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { type ClientEnvelope, type HardkasClientOptions, createHardkasClient };
|
package/dist/client.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { HardkasAccount } from '@hardkas/accounts';
|
|
|
10
10
|
export { signTxPlanArtifact } from '@hardkas/accounts';
|
|
11
11
|
import { L2NetworkProfile } from '@hardkas/l2';
|
|
12
12
|
export { buildPaymentPlan } from '@hardkas/tx-builder';
|
|
13
|
+
export { ClientEnvelope, HardkasClientOptions, createHardkasClient } from './client.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* HardKAS Accounts Module
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHardkasClient
|
|
3
|
+
} from "./chunk-RCCELGL3.js";
|
|
4
|
+
|
|
1
5
|
// src/index.ts
|
|
2
6
|
import { loadHardkasConfig as loadConfig } from "@hardkas/config";
|
|
3
7
|
import { JsonWrpcKaspaClient } from "@hardkas/kaspa-rpc";
|
|
@@ -40,7 +44,8 @@ var HardkasAccounts = class {
|
|
|
40
44
|
// src/tx.ts
|
|
41
45
|
import { systemRuntimeContext } from "@hardkas/core";
|
|
42
46
|
import {
|
|
43
|
-
buildPaymentPlan
|
|
47
|
+
buildPaymentPlan,
|
|
48
|
+
verifySignedTxSemantics
|
|
44
49
|
} from "@hardkas/tx-builder";
|
|
45
50
|
import {
|
|
46
51
|
HARDKAS_VERSION,
|
|
@@ -156,6 +161,7 @@ var HardkasTx = class {
|
|
|
156
161
|
events.push({ type: "phase.completed", phase: "send", timestamp: Date.now() });
|
|
157
162
|
await saveLocalnetState(simResult.state);
|
|
158
163
|
const receiptPath = await saveSimulatedReceipt(simResult.receipt);
|
|
164
|
+
const tracePath = receiptPath.replace(".json", ".trace.json");
|
|
159
165
|
const receiptBase = {
|
|
160
166
|
schema: ARTIFACT_SCHEMAS.TX_RECEIPT,
|
|
161
167
|
hardkasVersion: HARDKAS_VERSION,
|
|
@@ -179,10 +185,11 @@ var HardkasTx = class {
|
|
|
179
185
|
postStateHash: simResult.receipt.postStateHash,
|
|
180
186
|
submittedAt: simResult.receipt.createdAt,
|
|
181
187
|
confirmedAt: simResult.receipt.createdAt,
|
|
182
|
-
rpcUrl: "simulated://local"
|
|
188
|
+
rpcUrl: "simulated://local",
|
|
189
|
+
tracePath
|
|
183
190
|
};
|
|
184
191
|
receiptBase.contentHash = calculateContentHash(receiptBase, CURRENT_HASH_VERSION);
|
|
185
|
-
const receipt = receiptBase;
|
|
192
|
+
const receipt = Object.freeze(receiptBase);
|
|
186
193
|
const traceSteps = events.map((ev) => ({
|
|
187
194
|
phase: ev.phase || ev.message || "unknown",
|
|
188
195
|
status: ev.type.includes("completed") ? "completed" : ev.type.includes("failed") ? "failed" : "started",
|
|
@@ -201,12 +208,11 @@ var HardkasTx = class {
|
|
|
201
208
|
steps: traceSteps
|
|
202
209
|
};
|
|
203
210
|
traceBase.contentHash = calculateContentHash(traceBase, CURRENT_HASH_VERSION);
|
|
204
|
-
|
|
211
|
+
await saveSimulatedTrace({
|
|
205
212
|
...traceBase,
|
|
206
213
|
events,
|
|
207
214
|
receiptPath
|
|
208
215
|
});
|
|
209
|
-
receipt.tracePath = tracePath;
|
|
210
216
|
return {
|
|
211
217
|
receipt,
|
|
212
218
|
receiptPath,
|
|
@@ -217,6 +223,10 @@ var HardkasTx = class {
|
|
|
217
223
|
* Sends a signed transaction to the real RPC network.
|
|
218
224
|
*/
|
|
219
225
|
async send(signedArtifact, url) {
|
|
226
|
+
const verification = verifySignedTxSemantics(signedArtifact);
|
|
227
|
+
if (!verification.ok) {
|
|
228
|
+
throw new Error(`Pre-broadcast semantic verification failed: ${verification.issues.map((i) => i.message).join(", ")}`);
|
|
229
|
+
}
|
|
220
230
|
const broadcastable = getBroadcastableSignedTransaction(signedArtifact);
|
|
221
231
|
const broadcastRecord = broadcastable.rawTransaction;
|
|
222
232
|
const txId = broadcastRecord.id || "unknown";
|
|
@@ -563,7 +573,15 @@ var HardkasArtifactsManager = class {
|
|
|
563
573
|
const absolutePath = path3.join(outputDir, fileName);
|
|
564
574
|
const { writeArtifact: writeArtifact4 } = await import("@hardkas/artifacts");
|
|
565
575
|
await writeArtifact4(absolutePath, artifact);
|
|
566
|
-
const {
|
|
576
|
+
const {
|
|
577
|
+
coreEvents: coreEvents2,
|
|
578
|
+
createEventEnvelope,
|
|
579
|
+
asWorkflowId,
|
|
580
|
+
asCorrelationId,
|
|
581
|
+
asNetworkId,
|
|
582
|
+
asArtifactId,
|
|
583
|
+
asEventSequence
|
|
584
|
+
} = await import("@hardkas/core");
|
|
567
585
|
const wId = options.workflowId || "wf_unknown_standalone";
|
|
568
586
|
const cId = options.correlationId || wId;
|
|
569
587
|
const netId = options.networkId || record.networkId || "unknown";
|
|
@@ -571,14 +589,14 @@ var HardkasArtifactsManager = class {
|
|
|
571
589
|
coreEvents2.emit(createEventEnvelope({
|
|
572
590
|
kind: "artifact.written",
|
|
573
591
|
domain: "integrity",
|
|
574
|
-
workflowId: wId,
|
|
575
|
-
correlationId: cId,
|
|
576
|
-
networkId: netId,
|
|
577
|
-
payload: { artifactId, path: absolutePath },
|
|
578
|
-
sequenceNumber: 1,
|
|
592
|
+
workflowId: asWorkflowId(wId),
|
|
593
|
+
correlationId: asCorrelationId(cId),
|
|
594
|
+
networkId: asNetworkId(netId),
|
|
595
|
+
payload: { artifactId: asArtifactId(artifactId), path: absolutePath },
|
|
596
|
+
sequenceNumber: asEventSequence(1),
|
|
579
597
|
globalOffset: 0,
|
|
580
598
|
sourceSubsystem: "sdk:artifacts-manager",
|
|
581
|
-
artifactId
|
|
599
|
+
artifactId: asArtifactId(artifactId)
|
|
582
600
|
}));
|
|
583
601
|
return {
|
|
584
602
|
absolutePath,
|
|
@@ -714,6 +732,7 @@ var HardkasWorkflow = class {
|
|
|
714
732
|
status: "success",
|
|
715
733
|
startedAt,
|
|
716
734
|
completedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
735
|
+
// hardkas-determinism-allow: step completion timestamp
|
|
717
736
|
};
|
|
718
737
|
if (producedArtifactId) stepRecord.producedArtifactId = producedArtifactId;
|
|
719
738
|
artifactSteps.push(stepRecord);
|
|
@@ -730,6 +749,7 @@ var HardkasWorkflow = class {
|
|
|
730
749
|
status: "failed",
|
|
731
750
|
startedAt,
|
|
732
751
|
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
752
|
+
// hardkas-determinism-allow: step failed timestamp
|
|
733
753
|
error: e.message
|
|
734
754
|
});
|
|
735
755
|
break;
|
|
@@ -743,6 +763,7 @@ var HardkasWorkflow = class {
|
|
|
743
763
|
networkId: this.sdk.network,
|
|
744
764
|
mode: executionMode,
|
|
745
765
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
766
|
+
// hardkas-determinism-allow: workflow artifact creation timestamp
|
|
746
767
|
workflowId,
|
|
747
768
|
artifactId: workflowId,
|
|
748
769
|
status,
|
|
@@ -752,6 +773,7 @@ var HardkasWorkflow = class {
|
|
|
752
773
|
generationRange: {
|
|
753
774
|
start: generationStart,
|
|
754
775
|
end: Date.now().toString()
|
|
776
|
+
// hardkas-determinism-allow: ambient end generation clock
|
|
755
777
|
},
|
|
756
778
|
policy: {
|
|
757
779
|
allowNetwork: this.sdk.policy.allowNetwork,
|
|
@@ -926,6 +948,7 @@ export {
|
|
|
926
948
|
HardkasWorkspace,
|
|
927
949
|
SOMPI_PER_KAS,
|
|
928
950
|
buildPaymentPlan2 as buildPaymentPlan,
|
|
951
|
+
createHardkasClient,
|
|
929
952
|
createTxPlanArtifact2 as createTxPlanArtifact,
|
|
930
953
|
defineHardkasConfig2 as defineHardkasConfig,
|
|
931
954
|
defineTask,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -9,25 +9,31 @@
|
|
|
9
9
|
],
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
+
"sideEffects": false,
|
|
12
13
|
"exports": {
|
|
13
14
|
".": {
|
|
14
15
|
"types": "./dist/index.d.ts",
|
|
15
16
|
"import": "./dist/index.js",
|
|
16
17
|
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./client": {
|
|
20
|
+
"types": "./dist/client.d.ts",
|
|
21
|
+
"import": "./dist/client.js",
|
|
22
|
+
"default": "./dist/client.js"
|
|
17
23
|
}
|
|
18
24
|
},
|
|
19
25
|
"dependencies": {
|
|
20
|
-
"@hardkas/
|
|
21
|
-
"@hardkas/
|
|
22
|
-
"@hardkas/
|
|
23
|
-
"@hardkas/
|
|
24
|
-
"@hardkas/
|
|
25
|
-
"@hardkas/
|
|
26
|
-
"@hardkas/
|
|
27
|
-
"@hardkas/
|
|
28
|
-
"@hardkas/tx-builder": "0.
|
|
29
|
-
"@hardkas/wallet-adapter": "0.
|
|
30
|
-
"@hardkas/
|
|
26
|
+
"@hardkas/config": "0.7.0-alpha",
|
|
27
|
+
"@hardkas/core": "0.7.0-alpha",
|
|
28
|
+
"@hardkas/l2": "0.7.0-alpha",
|
|
29
|
+
"@hardkas/accounts": "0.7.0-alpha",
|
|
30
|
+
"@hardkas/artifacts": "0.7.0-alpha",
|
|
31
|
+
"@hardkas/query": "0.7.0-alpha",
|
|
32
|
+
"@hardkas/kaspa-rpc": "0.7.0-alpha",
|
|
33
|
+
"@hardkas/localnet": "0.7.0-alpha",
|
|
34
|
+
"@hardkas/tx-builder": "0.7.0-alpha",
|
|
35
|
+
"@hardkas/wallet-adapter": "0.7.0-alpha",
|
|
36
|
+
"@hardkas/simulator": "0.7.0-alpha"
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"tsup": "^8.3.5",
|
|
@@ -46,7 +52,7 @@
|
|
|
46
52
|
},
|
|
47
53
|
"homepage": "https://github.com/KasLabDevs/HardKas/tree/main/packages/sdk#readme",
|
|
48
54
|
"scripts": {
|
|
49
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
55
|
+
"build": "tsup src/index.ts src/client.ts --format esm --dts --clean",
|
|
50
56
|
"test": "vitest run --passWithNoTests",
|
|
51
57
|
"typecheck": "tsc --noEmit",
|
|
52
58
|
"lint": "eslint ."
|