@hardkas/sdk 0.8.0-alpha → 0.8.2-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.d.ts +2 -6
- package/dist/index.js +36 -12
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ declare class HardkasTx {
|
|
|
63
63
|
plan(options: {
|
|
64
64
|
from: string | HardkasAccount;
|
|
65
65
|
to: string | HardkasAccount;
|
|
66
|
-
amount: string | bigint;
|
|
66
|
+
amount: string | number | bigint;
|
|
67
67
|
feeRate?: bigint;
|
|
68
68
|
workflowId?: string;
|
|
69
69
|
}): Promise<TxPlanArtifact>;
|
|
@@ -304,11 +304,7 @@ declare class HardkasArtifactsManager {
|
|
|
304
304
|
* Cryptographically verifies the determinism and integrity of an artifact.
|
|
305
305
|
* Throws an error with details if corruption or mismatch is found.
|
|
306
306
|
*/
|
|
307
|
-
verify(target:
|
|
308
|
-
schema?: string;
|
|
309
|
-
artifactId?: string;
|
|
310
|
-
contentHash?: string;
|
|
311
|
-
}, options?: {
|
|
307
|
+
verify(target: any, options?: {
|
|
312
308
|
throwOnInvalid?: boolean;
|
|
313
309
|
}): Promise<any>;
|
|
314
310
|
}
|
package/dist/index.js
CHANGED
|
@@ -153,7 +153,7 @@ var HardkasTx = class {
|
|
|
153
153
|
throw new Error(`From account ${fromAccount.name} has no address.`);
|
|
154
154
|
if (!toAccount.address)
|
|
155
155
|
throw new Error(`To account ${toAccount.name} has no address.`);
|
|
156
|
-
const amountSompi = typeof options.amount === "string" ? parseKasToSompi(options.amount) : typeof options.amount === "number" ?
|
|
156
|
+
const amountSompi = typeof options.amount === "string" ? parseKasToSompi(options.amount) : typeof options.amount === "number" ? parseKasToSompi(options.amount.toString()) : options.amount;
|
|
157
157
|
if (amountSompi === 0n) {
|
|
158
158
|
throw new Error("Kaspa value-transfer outputs require amount > 0.\nFor metadata/notary/DID marker transactions use --amount 1.\nFuture: hardkas tx anchor.");
|
|
159
159
|
}
|
|
@@ -221,6 +221,9 @@ var HardkasTx = class {
|
|
|
221
221
|
* Signs a transaction plan.
|
|
222
222
|
*/
|
|
223
223
|
async sign(plan, account, options) {
|
|
224
|
+
if (typeof plan === "object" && plan !== null && plan.contentHash) {
|
|
225
|
+
await this.sdk.artifacts.verify(plan, { throwOnInvalid: true });
|
|
226
|
+
}
|
|
224
227
|
let resolvedAccount;
|
|
225
228
|
if (typeof account === "string") {
|
|
226
229
|
resolvedAccount = await this.sdk.accounts.resolve(account);
|
|
@@ -401,6 +404,9 @@ var HardkasTx = class {
|
|
|
401
404
|
if (draft.lineage) draft.lineage.artifactId = draft.signedId;
|
|
402
405
|
signedArtifact = draft;
|
|
403
406
|
} else {
|
|
407
|
+
if (resolvedAccount.address !== plan.from.address) {
|
|
408
|
+
throw new Error(`Signer account '${resolvedAccount.address}' is not authorized to sign for '${plan.from.address}'.`);
|
|
409
|
+
}
|
|
404
410
|
signedArtifact = await signTxPlanArtifact({
|
|
405
411
|
planArtifact: plan,
|
|
406
412
|
account: resolvedAccount,
|
|
@@ -437,6 +443,9 @@ var HardkasTx = class {
|
|
|
437
443
|
* Modifies the local deterministic state and outputs receipt/trace artifacts.
|
|
438
444
|
*/
|
|
439
445
|
async simulate(target, options = {}) {
|
|
446
|
+
if (typeof target === "object" && target !== null && target.contentHash) {
|
|
447
|
+
await this.sdk.artifacts.verify(target, { throwOnInvalid: true });
|
|
448
|
+
}
|
|
440
449
|
const persist = options.persist ?? true;
|
|
441
450
|
const {
|
|
442
451
|
loadOrCreateLocalnetState,
|
|
@@ -596,6 +605,9 @@ var HardkasTx = class {
|
|
|
596
605
|
* Sends a signed transaction to the real RPC network.
|
|
597
606
|
*/
|
|
598
607
|
async send(signedArtifact, urlOrOptions) {
|
|
608
|
+
if (typeof signedArtifact === "object" && signedArtifact !== null && signedArtifact.contentHash) {
|
|
609
|
+
await this.sdk.artifacts.verify(signedArtifact, { throwOnInvalid: true });
|
|
610
|
+
}
|
|
599
611
|
const verification = verifySignedTxSemantics(signedArtifact);
|
|
600
612
|
if (!verification.ok) {
|
|
601
613
|
throw new Error(
|
|
@@ -985,6 +997,9 @@ var HardkasReplay = class {
|
|
|
985
997
|
* against the mathematically reconstructed localnet state.
|
|
986
998
|
*/
|
|
987
999
|
async verify(targetOrOptions, options) {
|
|
1000
|
+
if (typeof targetOrOptions === "object" && targetOrOptions !== null && targetOrOptions.contentHash) {
|
|
1001
|
+
await this.sdk.artifacts.verify(targetOrOptions, { throwOnInvalid: true });
|
|
1002
|
+
}
|
|
988
1003
|
let opts = options || {};
|
|
989
1004
|
if (typeof targetOrOptions === "string") {
|
|
990
1005
|
opts.path = targetOrOptions;
|
|
@@ -1368,29 +1383,38 @@ var HardkasArtifactsManager = class {
|
|
|
1368
1383
|
*/
|
|
1369
1384
|
async verify(target, options = {}) {
|
|
1370
1385
|
const throwOnInvalid = options.throwOnInvalid ?? true;
|
|
1371
|
-
const id = typeof target === "string" ? target : target.artifactId || target.contentHash || "";
|
|
1372
|
-
if (!id) {
|
|
1373
|
-
if (throwOnInvalid) throw new Error("No artifact target provided for verification.");
|
|
1374
|
-
return { valid: false, reason: "unknown", message: "No artifact target provided for verification." };
|
|
1375
|
-
}
|
|
1376
1386
|
let artifact;
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
if (
|
|
1381
|
-
|
|
1387
|
+
let id;
|
|
1388
|
+
if (typeof target === "string") {
|
|
1389
|
+
id = target;
|
|
1390
|
+
if (!id) {
|
|
1391
|
+
if (throwOnInvalid) throw new Error("No artifact target provided for verification.");
|
|
1392
|
+
return { valid: false, reason: "unknown", message: "No artifact target provided for verification." };
|
|
1393
|
+
}
|
|
1394
|
+
try {
|
|
1395
|
+
artifact = await this.read(id);
|
|
1396
|
+
} catch (e) {
|
|
1397
|
+
if (throwOnInvalid) throw e;
|
|
1398
|
+
return { valid: false, reason: "missing_artifact", message: e.message, artifactId: id };
|
|
1399
|
+
}
|
|
1400
|
+
} else {
|
|
1401
|
+
artifact = target;
|
|
1402
|
+
id = artifact.artifactId || artifact.contentHash || "";
|
|
1382
1403
|
}
|
|
1383
1404
|
const { verifyArtifactIntegrity: verifyArtifactIntegrity2 } = await import("@hardkas/artifacts");
|
|
1384
1405
|
const result = await verifyArtifactIntegrity2(artifact);
|
|
1385
1406
|
if (!result.ok) {
|
|
1407
|
+
const mappedReason = result.issues[0]?.code === "HASH_MISMATCH" ? "content_hash_mismatch" : result.issues[0]?.code === "MISSING_CONTENT_HASH" ? "missing_content_hash" : result.issues[0]?.code === "MISSING_SIGNATURE" ? "missing_signature" : "schema_invalid";
|
|
1386
1408
|
if (throwOnInvalid) {
|
|
1387
1409
|
throw new Error(`Artifact ${id} corrupted or invalid: ` + JSON.stringify(result.issues, null, 2));
|
|
1388
1410
|
}
|
|
1389
1411
|
return {
|
|
1390
1412
|
valid: false,
|
|
1391
|
-
reason:
|
|
1413
|
+
reason: mappedReason,
|
|
1392
1414
|
message: result.issues.map((i) => i.message).join(", "),
|
|
1393
1415
|
artifactId: id,
|
|
1416
|
+
expected: result.expectedHash,
|
|
1417
|
+
actual: result.actualHash,
|
|
1394
1418
|
details: result.issues
|
|
1395
1419
|
};
|
|
1396
1420
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2-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/
|
|
33
|
-
"@hardkas/
|
|
34
|
-
"@hardkas/
|
|
35
|
-
"@hardkas/
|
|
36
|
-
"@hardkas/
|
|
37
|
-
"@hardkas/
|
|
26
|
+
"@hardkas/artifacts": "0.8.2-alpha",
|
|
27
|
+
"@hardkas/config": "0.8.2-alpha",
|
|
28
|
+
"@hardkas/kaspa-rpc": "0.8.2-alpha",
|
|
29
|
+
"@hardkas/core": "0.8.2-alpha",
|
|
30
|
+
"@hardkas/l2": "0.8.2-alpha",
|
|
31
|
+
"@hardkas/accounts": "0.8.2-alpha",
|
|
32
|
+
"@hardkas/localnet": "0.8.2-alpha",
|
|
33
|
+
"@hardkas/query": "0.8.2-alpha",
|
|
34
|
+
"@hardkas/simulator": "0.8.2-alpha",
|
|
35
|
+
"@hardkas/tx-builder": "0.8.2-alpha",
|
|
36
|
+
"@hardkas/wallet-adapter": "0.8.2-alpha",
|
|
37
|
+
"@hardkas/query-store": "0.8.2-alpha"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"tsup": "^8.3.5",
|