@hardkas/artifacts 0.8.4-alpha → 0.8.9-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 +56 -4
- package/dist/index.js +128 -51
- package/package.json +9 -4
package/dist/index.d.ts
CHANGED
|
@@ -807,18 +807,30 @@ declare const TxPlanSchema: z.ZodObject<{
|
|
|
807
807
|
index: number;
|
|
808
808
|
}>;
|
|
809
809
|
amountSompi: z.ZodString;
|
|
810
|
+
address: z.ZodOptional<z.ZodString>;
|
|
811
|
+
scriptPublicKey: z.ZodOptional<z.ZodString>;
|
|
812
|
+
blockDaaScore: z.ZodOptional<z.ZodString>;
|
|
813
|
+
isCoinbase: z.ZodOptional<z.ZodBoolean>;
|
|
810
814
|
}, "strip", z.ZodTypeAny, {
|
|
811
815
|
amountSompi: string;
|
|
812
816
|
outpoint: {
|
|
813
817
|
transactionId: string;
|
|
814
818
|
index: number;
|
|
815
819
|
};
|
|
820
|
+
address?: string | undefined;
|
|
821
|
+
scriptPublicKey?: string | undefined;
|
|
822
|
+
blockDaaScore?: string | undefined;
|
|
823
|
+
isCoinbase?: boolean | undefined;
|
|
816
824
|
}, {
|
|
817
825
|
amountSompi: string;
|
|
818
826
|
outpoint: {
|
|
819
827
|
transactionId: string;
|
|
820
828
|
index: number;
|
|
821
829
|
};
|
|
830
|
+
address?: string | undefined;
|
|
831
|
+
scriptPublicKey?: string | undefined;
|
|
832
|
+
blockDaaScore?: string | undefined;
|
|
833
|
+
isCoinbase?: boolean | undefined;
|
|
822
834
|
}>, "many">;
|
|
823
835
|
outputs: z.ZodArray<z.ZodObject<{
|
|
824
836
|
address: z.ZodString;
|
|
@@ -872,6 +884,10 @@ declare const TxPlanSchema: z.ZodObject<{
|
|
|
872
884
|
transactionId: string;
|
|
873
885
|
index: number;
|
|
874
886
|
};
|
|
887
|
+
address?: string | undefined;
|
|
888
|
+
scriptPublicKey?: string | undefined;
|
|
889
|
+
blockDaaScore?: string | undefined;
|
|
890
|
+
isCoinbase?: boolean | undefined;
|
|
875
891
|
}[];
|
|
876
892
|
outputs: {
|
|
877
893
|
address: string;
|
|
@@ -935,6 +951,10 @@ declare const TxPlanSchema: z.ZodObject<{
|
|
|
935
951
|
transactionId: string;
|
|
936
952
|
index: number;
|
|
937
953
|
};
|
|
954
|
+
address?: string | undefined;
|
|
955
|
+
scriptPublicKey?: string | undefined;
|
|
956
|
+
blockDaaScore?: string | undefined;
|
|
957
|
+
isCoinbase?: boolean | undefined;
|
|
938
958
|
}[];
|
|
939
959
|
outputs: {
|
|
940
960
|
address: string;
|
|
@@ -2868,13 +2888,15 @@ interface DeploymentSummary {
|
|
|
2868
2888
|
}
|
|
2869
2889
|
|
|
2870
2890
|
declare const SEMANTIC_EXCLUSIONS: Set<string>;
|
|
2891
|
+
declare const V4_SEMANTIC_EXCLUSIONS: Set<string>;
|
|
2871
2892
|
/**
|
|
2872
2893
|
* Current canonicalization version.
|
|
2873
2894
|
* v1: BigInt(123) -> "123" (Collision with String "123")
|
|
2874
2895
|
* v2: BigInt(123) -> "n:123" (Distinguishable)
|
|
2875
2896
|
* v3: String normalization (\r\n -> \n, NFC) for cross-platform stability.
|
|
2897
|
+
* v4: Strict Metadata Integrity (includes lineage, parentArtifactId, signatureMetadata, etc in the hash).
|
|
2876
2898
|
*/
|
|
2877
|
-
declare const CURRENT_HASH_VERSION =
|
|
2899
|
+
declare const CURRENT_HASH_VERSION = 4;
|
|
2878
2900
|
declare const STRICT_PATH_KEYS: Set<string>;
|
|
2879
2901
|
/**
|
|
2880
2902
|
* Deterministically stringifies an object by sorting keys recursively.
|
|
@@ -2928,12 +2950,12 @@ declare function sortUtxosByOutpoint<T>(utxos: T[]): T[];
|
|
|
2928
2950
|
* Verifies an artifact's integrity synchronously.
|
|
2929
2951
|
* Can take a raw object or a file path.
|
|
2930
2952
|
*/
|
|
2931
|
-
declare function verifyArtifactIntegritySync(artifactOrPath: unknown): ArtifactVerificationResult;
|
|
2953
|
+
declare function verifyArtifactIntegritySync(artifactOrPath: unknown, context?: VerificationContext): ArtifactVerificationResult;
|
|
2932
2954
|
/**
|
|
2933
2955
|
* Verifies an artifact's integrity asynchronously.
|
|
2934
2956
|
* Can take a raw object or a file path.
|
|
2935
2957
|
*/
|
|
2936
|
-
declare function verifyArtifactIntegrity(artifactOrPath: unknown): Promise<ArtifactVerificationResult>;
|
|
2958
|
+
declare function verifyArtifactIntegrity(artifactOrPath: unknown, context?: VerificationContext): Promise<ArtifactVerificationResult>;
|
|
2937
2959
|
/**
|
|
2938
2960
|
* Verifies an artifact's semantic and economic validity.
|
|
2939
2961
|
*/
|
|
@@ -3383,6 +3405,17 @@ interface LineageOptions {
|
|
|
3383
3405
|
* Validates the lineage relationship between an artifact and its parent.
|
|
3384
3406
|
*/
|
|
3385
3407
|
declare function verifyLineage(artifact: any, parent?: any, options?: LineageOptions): LineageValidationResult;
|
|
3408
|
+
/**
|
|
3409
|
+
* Creates a valid lineage transition object for a new child artifact based on its parent.
|
|
3410
|
+
* This should be attached to the child artifact before calculating its final hash.
|
|
3411
|
+
*/
|
|
3412
|
+
declare function createLineageTransition(parent: any, childType: string): {
|
|
3413
|
+
artifactId: string;
|
|
3414
|
+
lineageId: string;
|
|
3415
|
+
parentArtifactId: string;
|
|
3416
|
+
rootArtifactId: string;
|
|
3417
|
+
sequence: number;
|
|
3418
|
+
};
|
|
3386
3419
|
|
|
3387
3420
|
interface DiffEntry {
|
|
3388
3421
|
path: string;
|
|
@@ -3425,4 +3458,23 @@ declare function listDeployments(rootDir: string, networkId?: string): Promise<D
|
|
|
3425
3458
|
declare function updateDeployment(rootDir: string, networkId: string, label: string, update: Partial<DeploymentRecord>): Promise<DeploymentRecord>;
|
|
3426
3459
|
declare function deleteDeployment(rootDir: string, networkId: string, label: string): Promise<boolean>;
|
|
3427
3460
|
|
|
3428
|
-
|
|
3461
|
+
/**
|
|
3462
|
+
* Interface for external wallets and signers.
|
|
3463
|
+
* HardKAS uses this to delegate transaction signing to secure enclaves,
|
|
3464
|
+
* hardware wallets, or official Kaspa SDK backends, ensuring it does not
|
|
3465
|
+
* need to hold or manage private keys natively.
|
|
3466
|
+
*/
|
|
3467
|
+
interface ExternalHardkasSigner {
|
|
3468
|
+
/**
|
|
3469
|
+
* Retrieves the public Kaspa address managed by this signer.
|
|
3470
|
+
*/
|
|
3471
|
+
getAddress(): Promise<string>;
|
|
3472
|
+
/**
|
|
3473
|
+
* Signs a prepared transaction plan.
|
|
3474
|
+
* @param txPlan The transaction plan artifact to sign.
|
|
3475
|
+
* @returns A signed transaction artifact.
|
|
3476
|
+
*/
|
|
3477
|
+
signTransaction(txPlan: TxPlanArtifact): Promise<SignedTxArtifact>;
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
export { ARTIFACT_SCHEMAS, ARTIFACT_VERSION, AccountRefSchema, type ArtifactDiff, type ArtifactExplanation, ArtifactLineageSchema, type ArtifactLookup, type ArtifactPayload, type ArtifactValidationResult, type ArtifactVerificationResult, type Assumption, type AssumptionArtifact, type AssumptionLevel, AssumptionSchema, type BaseArtifact, BaseArtifactSchema, BasicCorrelationInvariant, BasicLineageInvariant, CURRENT_HASH_VERSION, type Clock, type CreateTxPlanArtifactOptions, type DagContext, DagContextSchema, type DeploymentIndex, type DeploymentRecord, type DeploymentSummary, type DiffEntry, type DraftArtifact, type ExternalHardkasSigner, type FeeAuditResult, HARDKAS_VERSION, type HardkasArtifactBase, type HardkasArtifactMode, type HardkasArtifactSchema, HashInvariant, type IgraSignedTxArtifact, type IgraTxPlanArtifact, type IgraTxReceiptArtifact, type IgraTxRequestArtifact, type Invariant, type InvariantContext, type InvariantViolation, InvariantWatcher, LifecycleInvariant, type LineageOptions, type LineageValidationResult, LocalnetUtxoSchemaV2, type MigrationReceipt, type MigrationReceiptArtifact, MigrationReceiptSchema, MigrationRequiredError, type MigrationResult, type MigrationStep, NetworkInvariant, type NetworkProfile, type NetworkProfileArtifact, NetworkProfileSchema, type Policy, type PolicyArtifact, PolicySchema, ReplayInvariant, type RuntimeSession, RuntimeSessionSchema, SEMANTIC_EXCLUSIONS, STRICT_PATH_KEYS, SchemaInvariant, type ScriptCapability, ScriptCapabilitySchema, ScriptMetadataSchema, SignatureEntrySchema, SignatureMetadataEntrySchema, type SignedTx, type SignedTxArtifact, type SignedTxArtifactV1, SignedTxSchema, type Snapshot, type SnapshotArtifact, SnapshotSchema, type TxOutputArtifact, type TxPlan, type TxPlanArtifact, type TxPlanArtifactV1, TxPlanSchema, type TxReceipt, type TxReceiptArtifact, type TxReceiptArtifactV1, TxReceiptSchema, type TxTrace, type TxTraceArtifact, type TxTraceArtifactV1, TxTraceSchema, type UtxoArtifact, V4_SEMANTIC_EXCLUSIONS, type VerificationContext, type VerificationIssue, type VerificationSeverity, type WatcherOptions, type Workflow, type WorkflowArtifact, WorkflowSchema, assertDecimalBigIntString, assertEvmAddress, assertEvmTxHash, assertHexData, assertValidIgraSignedTxArtifact, assertValidIgraTxPlanArtifact, assertValidIgraTxReceiptArtifact, assertValidSignedTxArtifact, assertValidTxPlanArtifact, assertValidTxReceiptArtifact, bigIntReplacer, calculateContentHash, canMigrate, canonicalStringify, createDeploymentRecord, createIgraDeployPlanId, createIgraPlanId, createIgraSignedId, createLineageTransition, createSimulatedSignedTxArtifact, createSimulatedTxReceipt, createTxPlanArtifact, defaultClock, deleteDeployment, detectArtifactVersion, diffArtifacts, explainArtifact, formatSignedTxArtifact, formatTxPlanArtifact, formatTxReceiptArtifact, generateMigrationReceipt, getBroadcastableSignedTransaction, getDefaultL2ReceiptsDir, getDefaultReceiptPath, getL2ReceiptPath, getMigrationPath, getRegisteredMigrationSteps, isIgraTxPlanArtifact, listDeployments, listIgraTxReceiptArtifacts, loadDeployment, loadIgraTxReceiptArtifact, migrateArtifactPayload, migrateToCanonical, readArtifact, readSignedTxArtifact, readTxPlanArtifact, readTxReceiptArtifact, recomputeMass, registerMigrationStep, saveDeployment, saveIgraTxReceiptArtifact, sortUtxosByOutpoint, txOutputFromArtifact, txOutputToArtifact, updateDeployment, updateDeploymentStatus, utxoFromArtifact, utxoToArtifact, validateArtifact, validateIgraSignedTxArtifact, validateIgraTxPlanArtifact, validateIgraTxReceiptArtifact, validateSignedTxArtifact, validateTxPlanArtifact, validateTxReceiptArtifact, verifyArtifact, verifyArtifactFile, verifyArtifactIntegrity, verifyArtifactIntegritySync, verifyArtifactReplay, verifyArtifactSemantics, verifyFeeSemantics, verifyLineage, writeArtifact };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// package.json
|
|
2
2
|
var package_default = {
|
|
3
3
|
name: "@hardkas/artifacts",
|
|
4
|
-
version: "0.8.
|
|
4
|
+
version: "0.8.9-alpha",
|
|
5
5
|
type: "module",
|
|
6
6
|
license: "MIT",
|
|
7
7
|
author: "Javier Rodriguez",
|
|
@@ -20,7 +20,11 @@ var package_default = {
|
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
22
22
|
exports: {
|
|
23
|
-
".":
|
|
23
|
+
".": {
|
|
24
|
+
types: "./dist/index.d.ts",
|
|
25
|
+
import: "./dist/index.js",
|
|
26
|
+
default: "./dist/index.js"
|
|
27
|
+
}
|
|
24
28
|
},
|
|
25
29
|
types: "./dist/index.d.ts",
|
|
26
30
|
scripts: {
|
|
@@ -38,7 +42,8 @@ var package_default = {
|
|
|
38
42
|
tsup: "^8.3.5",
|
|
39
43
|
typescript: "^5.6.3",
|
|
40
44
|
vitest: "^2.1.4"
|
|
41
|
-
}
|
|
45
|
+
},
|
|
46
|
+
main: "./dist/index.js"
|
|
42
47
|
};
|
|
43
48
|
|
|
44
49
|
// src/constants.ts
|
|
@@ -229,7 +234,44 @@ var SEMANTIC_EXCLUSIONS = /* @__PURE__ */ new Set([
|
|
|
229
234
|
"workflowId",
|
|
230
235
|
"signatureMetadata"
|
|
231
236
|
]);
|
|
232
|
-
var
|
|
237
|
+
var V4_SEMANTIC_EXCLUSIONS = /* @__PURE__ */ new Set([
|
|
238
|
+
// Core Hash Identity
|
|
239
|
+
"contentHash",
|
|
240
|
+
"artifactId",
|
|
241
|
+
"planId",
|
|
242
|
+
"signedId",
|
|
243
|
+
"hashVersion",
|
|
244
|
+
// Runtime/Display fields (user requested)
|
|
245
|
+
"filePath",
|
|
246
|
+
"file_path",
|
|
247
|
+
"workspacePath",
|
|
248
|
+
"debug",
|
|
249
|
+
"logs",
|
|
250
|
+
"uiHints",
|
|
251
|
+
"cache",
|
|
252
|
+
"lastViewedAt",
|
|
253
|
+
// Other runtime fields that must not break hash
|
|
254
|
+
"createdAt",
|
|
255
|
+
"events",
|
|
256
|
+
"status",
|
|
257
|
+
"submittedAt",
|
|
258
|
+
"confirmedAt",
|
|
259
|
+
"dagContext",
|
|
260
|
+
"executionId",
|
|
261
|
+
"deployedAt",
|
|
262
|
+
"tracePath",
|
|
263
|
+
"receiptPath",
|
|
264
|
+
"sourceSignedId",
|
|
265
|
+
"workflowId",
|
|
266
|
+
"signatureMetadata",
|
|
267
|
+
"rpcHost",
|
|
268
|
+
"rpcUrl",
|
|
269
|
+
"latencyMs",
|
|
270
|
+
"indexedAt",
|
|
271
|
+
"file_mtime_ms",
|
|
272
|
+
"hardkasVersion"
|
|
273
|
+
]);
|
|
274
|
+
var CURRENT_HASH_VERSION = 4;
|
|
233
275
|
var STRICT_PATH_KEYS = /* @__PURE__ */ new Set([
|
|
234
276
|
"file_path",
|
|
235
277
|
"sandboxSnapshotPath",
|
|
@@ -283,8 +325,9 @@ function canonicalStringify(obj, version = CURRENT_HASH_VERSION, keyName, isRoot
|
|
|
283
325
|
if (proto !== Object.prototype && proto !== null) {
|
|
284
326
|
throw new Error("Non-plain object encountered in canonicalizer.");
|
|
285
327
|
}
|
|
328
|
+
const exclusions = version >= 4 ? V4_SEMANTIC_EXCLUSIONS : SEMANTIC_EXCLUSIONS;
|
|
286
329
|
const sortedKeys = Object.keys(obj).filter(
|
|
287
|
-
(key) => !
|
|
330
|
+
(key) => !exclusions.has(key) && obj[key] !== void 0
|
|
288
331
|
).sort(deterministicCompare);
|
|
289
332
|
const result = sortedKeys.map((key) => {
|
|
290
333
|
const value = obj[key];
|
|
@@ -400,7 +443,11 @@ var TxPlanSchema = BaseArtifactSchema.extend({
|
|
|
400
443
|
transactionId: z.string(),
|
|
401
444
|
index: z.number()
|
|
402
445
|
}),
|
|
403
|
-
amountSompi: z.string()
|
|
446
|
+
amountSompi: z.string(),
|
|
447
|
+
address: z.string().optional(),
|
|
448
|
+
scriptPublicKey: z.string().optional(),
|
|
449
|
+
blockDaaScore: z.string().optional(),
|
|
450
|
+
isCoinbase: z.boolean().optional()
|
|
404
451
|
})
|
|
405
452
|
),
|
|
406
453
|
outputs: z.array(
|
|
@@ -785,6 +832,13 @@ function verifyLineage(artifact, parent, options = {}) {
|
|
|
785
832
|
const allowed = validTransitions[parent.schema] || [];
|
|
786
833
|
isValidTransition = allowed.includes(artifact.schema);
|
|
787
834
|
}
|
|
835
|
+
if (!isValidTransition) {
|
|
836
|
+
const parentBase = parent.schema?.replace(/\.v1$/, "");
|
|
837
|
+
const childBase = artifact.schema?.replace(/\.v1$/, "");
|
|
838
|
+
if (parentBase && childBase && parentBase === childBase) {
|
|
839
|
+
isValidTransition = true;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
788
842
|
if (!isValidTransition) {
|
|
789
843
|
addIssue(
|
|
790
844
|
"INVALID_TRANSITION",
|
|
@@ -797,6 +851,18 @@ function verifyLineage(artifact, parent, options = {}) {
|
|
|
797
851
|
issues
|
|
798
852
|
};
|
|
799
853
|
}
|
|
854
|
+
function createLineageTransition(parent, childType) {
|
|
855
|
+
const parentLineage = parent.lineage || {};
|
|
856
|
+
const parentId = parent.contentHash || parent.artifactId || parent.planId || parent.signedId || "0".repeat(64);
|
|
857
|
+
return {
|
|
858
|
+
artifactId: "",
|
|
859
|
+
// To be computed after the rest of the artifact is hashed
|
|
860
|
+
lineageId: parentLineage.lineageId || parentId,
|
|
861
|
+
parentArtifactId: parentId,
|
|
862
|
+
rootArtifactId: parentLineage.rootArtifactId || parentId,
|
|
863
|
+
sequence: (parentLineage.sequence || 0) + 1
|
|
864
|
+
};
|
|
865
|
+
}
|
|
800
866
|
|
|
801
867
|
// src/verify.ts
|
|
802
868
|
var defaultClock = {
|
|
@@ -817,7 +883,7 @@ function sortUtxosByOutpoint(utxos) {
|
|
|
817
883
|
return deterministicCompare2(aId, bId);
|
|
818
884
|
});
|
|
819
885
|
}
|
|
820
|
-
function verifyArtifactIntegritySync(artifactOrPath) {
|
|
886
|
+
function verifyArtifactIntegritySync(artifactOrPath, context = {}) {
|
|
821
887
|
const result = {
|
|
822
888
|
ok: false,
|
|
823
889
|
errors: [],
|
|
@@ -876,6 +942,19 @@ function verifyArtifactIntegritySync(artifactOrPath) {
|
|
|
876
942
|
"HASH_MISMATCH",
|
|
877
943
|
`Hash mismatch: expected ${v.contentHash}, got ${actualHash}`
|
|
878
944
|
);
|
|
945
|
+
} else if (hashVersion < 4) {
|
|
946
|
+
if (context.strict) {
|
|
947
|
+
addError(
|
|
948
|
+
"LEGACY_HASH_VERSION_UNSAFE",
|
|
949
|
+
`Artifact uses legacy hash version ${hashVersion}. Migration to v4 is required for strict pipelines.`
|
|
950
|
+
);
|
|
951
|
+
} else {
|
|
952
|
+
result.issues.push({
|
|
953
|
+
code: "LEGACY_VALID",
|
|
954
|
+
severity: "info",
|
|
955
|
+
message: `Artifact uses legacy hash version ${hashVersion} (valid but unsafe for strict mode).`
|
|
956
|
+
});
|
|
957
|
+
}
|
|
879
958
|
}
|
|
880
959
|
let schema;
|
|
881
960
|
switch (v.schema) {
|
|
@@ -913,9 +992,19 @@ function verifyArtifactIntegritySync(artifactOrPath) {
|
|
|
913
992
|
if (schema) {
|
|
914
993
|
const validation = schema.safeParse(v);
|
|
915
994
|
if (!validation.success) {
|
|
995
|
+
const zodSeverity = hashVersion < 4 && !context.strict ? "warning" : "error";
|
|
916
996
|
validation.error.issues.forEach((e) => {
|
|
917
997
|
const pathStr = e.path.join(".");
|
|
918
|
-
|
|
998
|
+
if (zodSeverity === "warning") {
|
|
999
|
+
result.issues.push({
|
|
1000
|
+
code: "ARTIFACT_SCHEMA_INVALID",
|
|
1001
|
+
severity: zodSeverity,
|
|
1002
|
+
message: `${pathStr}: ${e.message}`,
|
|
1003
|
+
...pathStr ? { path: pathStr } : {}
|
|
1004
|
+
});
|
|
1005
|
+
} else {
|
|
1006
|
+
addError("ARTIFACT_SCHEMA_INVALID", `${pathStr}: ${e.message}`, pathStr);
|
|
1007
|
+
}
|
|
919
1008
|
});
|
|
920
1009
|
}
|
|
921
1010
|
} else {
|
|
@@ -939,8 +1028,8 @@ function verifyArtifactIntegritySync(artifactOrPath) {
|
|
|
939
1028
|
return result;
|
|
940
1029
|
}
|
|
941
1030
|
}
|
|
942
|
-
async function verifyArtifactIntegrity(artifactOrPath) {
|
|
943
|
-
return verifyArtifactIntegritySync(artifactOrPath);
|
|
1031
|
+
async function verifyArtifactIntegrity(artifactOrPath, context = {}) {
|
|
1032
|
+
return verifyArtifactIntegritySync(artifactOrPath, context);
|
|
944
1033
|
}
|
|
945
1034
|
function findFileByHash(hash, dirs) {
|
|
946
1035
|
const shortHash = hash.startsWith("plan-") || hash.startsWith("signed-") ? hash : hash.slice(0, 16);
|
|
@@ -1034,7 +1123,7 @@ function verifyArtifactSemantics(artifact, context = {}) {
|
|
|
1034
1123
|
});
|
|
1035
1124
|
} else {
|
|
1036
1125
|
try {
|
|
1037
|
-
const integrity = verifyArtifactIntegritySync(refObj);
|
|
1126
|
+
const integrity = verifyArtifactIntegritySync(refObj, context);
|
|
1038
1127
|
if (!integrity.ok) {
|
|
1039
1128
|
addIssue({
|
|
1040
1129
|
code: "REFERENCE_HASH_MISMATCH",
|
|
@@ -1101,7 +1190,7 @@ function verifyArtifactSemantics(artifact, context = {}) {
|
|
|
1101
1190
|
});
|
|
1102
1191
|
} else {
|
|
1103
1192
|
try {
|
|
1104
|
-
const integrity = verifyArtifactIntegritySync(refObj);
|
|
1193
|
+
const integrity = verifyArtifactIntegritySync(refObj, context);
|
|
1105
1194
|
if (!integrity.ok) {
|
|
1106
1195
|
addIssue({
|
|
1107
1196
|
code: "REFERENCE_HASH_MISMATCH",
|
|
@@ -1144,7 +1233,7 @@ function verifyArtifactSemantics(artifact, context = {}) {
|
|
|
1144
1233
|
});
|
|
1145
1234
|
} else {
|
|
1146
1235
|
try {
|
|
1147
|
-
const integrity = verifyArtifactIntegritySync(refObj);
|
|
1236
|
+
const integrity = verifyArtifactIntegritySync(refObj, context);
|
|
1148
1237
|
if (!integrity.ok) {
|
|
1149
1238
|
addIssue({
|
|
1150
1239
|
code: "REFERENCE_HASH_MISMATCH",
|
|
@@ -1302,11 +1391,11 @@ function verifyArtifactSemantics(artifact, context = {}) {
|
|
|
1302
1391
|
if (addr && typeof addr === "string") {
|
|
1303
1392
|
let mismatch = false;
|
|
1304
1393
|
if (networkIdStr === "mainnet") {
|
|
1305
|
-
mismatch = !addr.startsWith("kaspa:") || addr.startsWith("kaspa:sim_");
|
|
1394
|
+
mismatch = !addr.startsWith("kaspa:") || addr.startsWith("kaspasim:") || addr.startsWith("kaspa:sim_");
|
|
1306
1395
|
} else if (networkIdStr.startsWith("testnet")) {
|
|
1307
1396
|
mismatch = !addr.startsWith("kaspatest:");
|
|
1308
1397
|
} else {
|
|
1309
|
-
mismatch = !addr.startsWith("kaspa:sim_");
|
|
1398
|
+
mismatch = !addr.startsWith("kaspasim:") && !addr.startsWith("kaspa:sim_");
|
|
1310
1399
|
}
|
|
1311
1400
|
if (mismatch) {
|
|
1312
1401
|
addIssue({
|
|
@@ -1684,10 +1773,18 @@ function migrateArtifactPayload(artifact, targetVersion = ARTIFACT_VERSION, opti
|
|
|
1684
1773
|
const migratedLineage = current.lineage;
|
|
1685
1774
|
if (migratedLineage && typeof migratedLineage === "object") {
|
|
1686
1775
|
migratedLineage.rootArtifactId = originalLineage.rootArtifactId;
|
|
1776
|
+
if (originalContentHash) {
|
|
1777
|
+
migratedLineage.parentArtifactId = originalContentHash;
|
|
1778
|
+
}
|
|
1687
1779
|
}
|
|
1688
1780
|
}
|
|
1689
1781
|
current.hashVersion = CURRENT_HASH_VERSION;
|
|
1690
|
-
|
|
1782
|
+
let hash = calculateContentHash(current, CURRENT_HASH_VERSION);
|
|
1783
|
+
if (current.lineage && typeof current.lineage === "object") {
|
|
1784
|
+
current.lineage.artifactId = hash;
|
|
1785
|
+
hash = calculateContentHash(current, CURRENT_HASH_VERSION);
|
|
1786
|
+
}
|
|
1787
|
+
current.contentHash = hash;
|
|
1691
1788
|
return {
|
|
1692
1789
|
artifact: current,
|
|
1693
1790
|
migrated: true,
|
|
@@ -1729,18 +1826,6 @@ function generateMigrationReceipt(oldArtifact, newArtifact, migrationId) {
|
|
|
1729
1826
|
};
|
|
1730
1827
|
receipt.contentHash = calculateContentHash(receipt, CURRENT_HASH_VERSION);
|
|
1731
1828
|
receipt.lineage.artifactId = receipt.contentHash;
|
|
1732
|
-
if (!newArtifact.lineage) {
|
|
1733
|
-
newArtifact.lineage = {
|
|
1734
|
-
artifactId: newHash,
|
|
1735
|
-
lineageId: receipt.lineage.lineageId,
|
|
1736
|
-
parentArtifactId: receipt.contentHash,
|
|
1737
|
-
rootArtifactId: receipt.lineage.rootArtifactId
|
|
1738
|
-
};
|
|
1739
|
-
} else {
|
|
1740
|
-
newArtifact.lineage.parentArtifactId = receipt.contentHash;
|
|
1741
|
-
}
|
|
1742
|
-
newArtifact.contentHash = calculateContentHash(newArtifact, CURRENT_HASH_VERSION);
|
|
1743
|
-
newArtifact.lineage.artifactId = newArtifact.contentHash;
|
|
1744
1829
|
return receipt;
|
|
1745
1830
|
}
|
|
1746
1831
|
|
|
@@ -1974,7 +2059,11 @@ function createTxPlanArtifact(options) {
|
|
|
1974
2059
|
transactionId: i.outpoint.transactionId,
|
|
1975
2060
|
index: i.outpoint.index
|
|
1976
2061
|
},
|
|
1977
|
-
amountSompi: i.amountSompi.toString()
|
|
2062
|
+
amountSompi: i.amountSompi.toString(),
|
|
2063
|
+
address: i.address,
|
|
2064
|
+
scriptPublicKey: i.scriptPublicKey,
|
|
2065
|
+
...i.blockDaaScore !== void 0 ? { blockDaaScore: i.blockDaaScore.toString() } : {},
|
|
2066
|
+
...i.isCoinbase !== void 0 ? { isCoinbase: i.isCoinbase } : {}
|
|
1978
2067
|
})),
|
|
1979
2068
|
outputs: options.plan.outputs.map((o) => ({
|
|
1980
2069
|
address: o.address,
|
|
@@ -2001,16 +2090,13 @@ function createTxPlanArtifact(options) {
|
|
|
2001
2090
|
artifact.planId = `plan-${hash.slice(0, 16)}`;
|
|
2002
2091
|
artifact.contentHash = hash;
|
|
2003
2092
|
if (artifact.lineage) {
|
|
2004
|
-
artifact.lineage.lineageId =
|
|
2005
|
-
artifact.lineage.
|
|
2006
|
-
artifact.lineage.
|
|
2007
|
-
artifact.lineage.rootArtifactId = artifact.contentHash;
|
|
2093
|
+
artifact.lineage.lineageId = hash;
|
|
2094
|
+
artifact.lineage.parentArtifactId = hash;
|
|
2095
|
+
artifact.lineage.rootArtifactId = hash;
|
|
2008
2096
|
const finalHash = calculateContentHash(artifact, CURRENT_HASH_VERSION);
|
|
2009
2097
|
artifact.planId = `plan-${finalHash.slice(0, 16)}`;
|
|
2010
2098
|
artifact.contentHash = finalHash;
|
|
2011
2099
|
artifact.lineage.artifactId = finalHash;
|
|
2012
|
-
artifact.lineage.parentArtifactId = finalHash;
|
|
2013
|
-
artifact.lineage.rootArtifactId = finalHash;
|
|
2014
2100
|
}
|
|
2015
2101
|
return artifact;
|
|
2016
2102
|
}
|
|
@@ -2036,13 +2122,7 @@ function createSimulatedSignedTxArtifact(plan, payload, ctx) {
|
|
|
2036
2122
|
format: "simulated",
|
|
2037
2123
|
payload
|
|
2038
2124
|
},
|
|
2039
|
-
lineage:
|
|
2040
|
-
artifactId: "",
|
|
2041
|
-
lineageId: plan.lineage?.lineageId || plan.contentHash || "0".repeat(64),
|
|
2042
|
-
parentArtifactId: plan.contentHash || "0".repeat(64),
|
|
2043
|
-
rootArtifactId: plan.lineage?.rootArtifactId || plan.contentHash || "0".repeat(64),
|
|
2044
|
-
sequence: (plan.lineage?.sequence || 0) + 1
|
|
2045
|
-
},
|
|
2125
|
+
lineage: createLineageTransition(plan, "hardkas.signedTx"),
|
|
2046
2126
|
...plan.workflowId ? { workflowId: plan.workflowId } : {}
|
|
2047
2127
|
};
|
|
2048
2128
|
const hash = calculateContentHash(artifact, CURRENT_HASH_VERSION);
|
|
@@ -2076,21 +2156,16 @@ function createSimulatedTxReceipt(plan, txId, ctx, extra) {
|
|
|
2076
2156
|
preStateHash: extra?.preStateHash,
|
|
2077
2157
|
postStateHash: extra?.postStateHash,
|
|
2078
2158
|
dagContext: extra?.dagContext,
|
|
2079
|
-
lineage:
|
|
2080
|
-
artifactId: "",
|
|
2081
|
-
lineageId: plan.lineage?.lineageId || plan.contentHash || "0".repeat(64),
|
|
2082
|
-
parentArtifactId: "0".repeat(64),
|
|
2083
|
-
// Will set to contentHash of signedTx later
|
|
2084
|
-
rootArtifactId: plan.lineage?.rootArtifactId || plan.contentHash || "0".repeat(64),
|
|
2085
|
-
sequence: (plan.lineage?.sequence || 1) + 1
|
|
2086
|
-
},
|
|
2159
|
+
lineage: createLineageTransition(plan, "hardkas.txReceipt"),
|
|
2087
2160
|
...plan.workflowId ? { workflowId: plan.workflowId } : {}
|
|
2088
2161
|
};
|
|
2162
|
+
if (artifact.lineage) {
|
|
2163
|
+
artifact.lineage.parentArtifactId = extra?.preStateHash || txId.replace("simulated-", "").replace("-tx", "").padEnd(64, "0").slice(0, 64);
|
|
2164
|
+
}
|
|
2089
2165
|
const hash = calculateContentHash(artifact, CURRENT_HASH_VERSION);
|
|
2090
2166
|
artifact.contentHash = hash;
|
|
2091
2167
|
if (artifact.lineage) {
|
|
2092
2168
|
artifact.lineage.artifactId = hash;
|
|
2093
|
-
artifact.lineage.parentArtifactId = extra?.preStateHash || txId.replace("simulated-", "").replace("-tx", "").padEnd(64, "0").slice(0, 64);
|
|
2094
2169
|
}
|
|
2095
2170
|
return artifact;
|
|
2096
2171
|
}
|
|
@@ -2574,6 +2649,7 @@ export {
|
|
|
2574
2649
|
TxPlanSchema,
|
|
2575
2650
|
TxReceiptSchema,
|
|
2576
2651
|
TxTraceSchema,
|
|
2652
|
+
V4_SEMANTIC_EXCLUSIONS,
|
|
2577
2653
|
WorkflowSchema,
|
|
2578
2654
|
assertDecimalBigIntString,
|
|
2579
2655
|
assertEvmAddress,
|
|
@@ -2593,6 +2669,7 @@ export {
|
|
|
2593
2669
|
createIgraDeployPlanId,
|
|
2594
2670
|
createIgraPlanId,
|
|
2595
2671
|
createIgraSignedId,
|
|
2672
|
+
createLineageTransition,
|
|
2596
2673
|
createSimulatedSignedTxArtifact,
|
|
2597
2674
|
createSimulatedTxReceipt,
|
|
2598
2675
|
createTxPlanArtifact,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/artifacts",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Javier Rodriguez",
|
|
@@ -19,19 +19,24 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"exports": {
|
|
22
|
-
".":
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
}
|
|
23
27
|
},
|
|
24
28
|
"types": "./dist/index.d.ts",
|
|
25
29
|
"dependencies": {
|
|
26
30
|
"zod": "^3.24.1",
|
|
27
|
-
"@hardkas/core": "0.8.
|
|
28
|
-
"@hardkas/tx-builder": "0.8.
|
|
31
|
+
"@hardkas/core": "0.8.9-alpha",
|
|
32
|
+
"@hardkas/tx-builder": "0.8.9-alpha"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"tsup": "^8.3.5",
|
|
32
36
|
"typescript": "^5.6.3",
|
|
33
37
|
"vitest": "^2.1.4"
|
|
34
38
|
},
|
|
39
|
+
"main": "./dist/index.js",
|
|
35
40
|
"scripts": {
|
|
36
41
|
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
37
42
|
"dev": "tsup src/index.ts --format esm --watch --dts",
|