@hardkas/artifacts 0.8.5-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 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 = 3;
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
- 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 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, 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, 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 };
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.5-alpha",
4
+ version: "0.8.9-alpha",
5
5
  type: "module",
6
6
  license: "MIT",
7
7
  author: "Javier Rodriguez",
@@ -234,7 +234,44 @@ var SEMANTIC_EXCLUSIONS = /* @__PURE__ */ new Set([
234
234
  "workflowId",
235
235
  "signatureMetadata"
236
236
  ]);
237
- var CURRENT_HASH_VERSION = 3;
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;
238
275
  var STRICT_PATH_KEYS = /* @__PURE__ */ new Set([
239
276
  "file_path",
240
277
  "sandboxSnapshotPath",
@@ -288,8 +325,9 @@ function canonicalStringify(obj, version = CURRENT_HASH_VERSION, keyName, isRoot
288
325
  if (proto !== Object.prototype && proto !== null) {
289
326
  throw new Error("Non-plain object encountered in canonicalizer.");
290
327
  }
328
+ const exclusions = version >= 4 ? V4_SEMANTIC_EXCLUSIONS : SEMANTIC_EXCLUSIONS;
291
329
  const sortedKeys = Object.keys(obj).filter(
292
- (key) => !SEMANTIC_EXCLUSIONS.has(key) && obj[key] !== void 0
330
+ (key) => !exclusions.has(key) && obj[key] !== void 0
293
331
  ).sort(deterministicCompare);
294
332
  const result = sortedKeys.map((key) => {
295
333
  const value = obj[key];
@@ -405,7 +443,11 @@ var TxPlanSchema = BaseArtifactSchema.extend({
405
443
  transactionId: z.string(),
406
444
  index: z.number()
407
445
  }),
408
- 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()
409
451
  })
410
452
  ),
411
453
  outputs: z.array(
@@ -790,6 +832,13 @@ function verifyLineage(artifact, parent, options = {}) {
790
832
  const allowed = validTransitions[parent.schema] || [];
791
833
  isValidTransition = allowed.includes(artifact.schema);
792
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
+ }
793
842
  if (!isValidTransition) {
794
843
  addIssue(
795
844
  "INVALID_TRANSITION",
@@ -802,6 +851,18 @@ function verifyLineage(artifact, parent, options = {}) {
802
851
  issues
803
852
  };
804
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
+ }
805
866
 
806
867
  // src/verify.ts
807
868
  var defaultClock = {
@@ -822,7 +883,7 @@ function sortUtxosByOutpoint(utxos) {
822
883
  return deterministicCompare2(aId, bId);
823
884
  });
824
885
  }
825
- function verifyArtifactIntegritySync(artifactOrPath) {
886
+ function verifyArtifactIntegritySync(artifactOrPath, context = {}) {
826
887
  const result = {
827
888
  ok: false,
828
889
  errors: [],
@@ -881,6 +942,19 @@ function verifyArtifactIntegritySync(artifactOrPath) {
881
942
  "HASH_MISMATCH",
882
943
  `Hash mismatch: expected ${v.contentHash}, got ${actualHash}`
883
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
+ }
884
958
  }
885
959
  let schema;
886
960
  switch (v.schema) {
@@ -918,9 +992,19 @@ function verifyArtifactIntegritySync(artifactOrPath) {
918
992
  if (schema) {
919
993
  const validation = schema.safeParse(v);
920
994
  if (!validation.success) {
995
+ const zodSeverity = hashVersion < 4 && !context.strict ? "warning" : "error";
921
996
  validation.error.issues.forEach((e) => {
922
997
  const pathStr = e.path.join(".");
923
- addError("ARTIFACT_SCHEMA_INVALID", `${pathStr}: ${e.message}`, pathStr);
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
+ }
924
1008
  });
925
1009
  }
926
1010
  } else {
@@ -944,8 +1028,8 @@ function verifyArtifactIntegritySync(artifactOrPath) {
944
1028
  return result;
945
1029
  }
946
1030
  }
947
- async function verifyArtifactIntegrity(artifactOrPath) {
948
- return verifyArtifactIntegritySync(artifactOrPath);
1031
+ async function verifyArtifactIntegrity(artifactOrPath, context = {}) {
1032
+ return verifyArtifactIntegritySync(artifactOrPath, context);
949
1033
  }
950
1034
  function findFileByHash(hash, dirs) {
951
1035
  const shortHash = hash.startsWith("plan-") || hash.startsWith("signed-") ? hash : hash.slice(0, 16);
@@ -1039,7 +1123,7 @@ function verifyArtifactSemantics(artifact, context = {}) {
1039
1123
  });
1040
1124
  } else {
1041
1125
  try {
1042
- const integrity = verifyArtifactIntegritySync(refObj);
1126
+ const integrity = verifyArtifactIntegritySync(refObj, context);
1043
1127
  if (!integrity.ok) {
1044
1128
  addIssue({
1045
1129
  code: "REFERENCE_HASH_MISMATCH",
@@ -1106,7 +1190,7 @@ function verifyArtifactSemantics(artifact, context = {}) {
1106
1190
  });
1107
1191
  } else {
1108
1192
  try {
1109
- const integrity = verifyArtifactIntegritySync(refObj);
1193
+ const integrity = verifyArtifactIntegritySync(refObj, context);
1110
1194
  if (!integrity.ok) {
1111
1195
  addIssue({
1112
1196
  code: "REFERENCE_HASH_MISMATCH",
@@ -1149,7 +1233,7 @@ function verifyArtifactSemantics(artifact, context = {}) {
1149
1233
  });
1150
1234
  } else {
1151
1235
  try {
1152
- const integrity = verifyArtifactIntegritySync(refObj);
1236
+ const integrity = verifyArtifactIntegritySync(refObj, context);
1153
1237
  if (!integrity.ok) {
1154
1238
  addIssue({
1155
1239
  code: "REFERENCE_HASH_MISMATCH",
@@ -1307,11 +1391,11 @@ function verifyArtifactSemantics(artifact, context = {}) {
1307
1391
  if (addr && typeof addr === "string") {
1308
1392
  let mismatch = false;
1309
1393
  if (networkIdStr === "mainnet") {
1310
- mismatch = !addr.startsWith("kaspa:") || addr.startsWith("kaspa:sim_");
1394
+ mismatch = !addr.startsWith("kaspa:") || addr.startsWith("kaspasim:") || addr.startsWith("kaspa:sim_");
1311
1395
  } else if (networkIdStr.startsWith("testnet")) {
1312
1396
  mismatch = !addr.startsWith("kaspatest:");
1313
1397
  } else {
1314
- mismatch = !addr.startsWith("kaspa:sim_");
1398
+ mismatch = !addr.startsWith("kaspasim:") && !addr.startsWith("kaspa:sim_");
1315
1399
  }
1316
1400
  if (mismatch) {
1317
1401
  addIssue({
@@ -1689,10 +1773,18 @@ function migrateArtifactPayload(artifact, targetVersion = ARTIFACT_VERSION, opti
1689
1773
  const migratedLineage = current.lineage;
1690
1774
  if (migratedLineage && typeof migratedLineage === "object") {
1691
1775
  migratedLineage.rootArtifactId = originalLineage.rootArtifactId;
1776
+ if (originalContentHash) {
1777
+ migratedLineage.parentArtifactId = originalContentHash;
1778
+ }
1692
1779
  }
1693
1780
  }
1694
1781
  current.hashVersion = CURRENT_HASH_VERSION;
1695
- current.contentHash = calculateContentHash(current, CURRENT_HASH_VERSION);
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;
1696
1788
  return {
1697
1789
  artifact: current,
1698
1790
  migrated: true,
@@ -1734,18 +1826,6 @@ function generateMigrationReceipt(oldArtifact, newArtifact, migrationId) {
1734
1826
  };
1735
1827
  receipt.contentHash = calculateContentHash(receipt, CURRENT_HASH_VERSION);
1736
1828
  receipt.lineage.artifactId = receipt.contentHash;
1737
- if (!newArtifact.lineage) {
1738
- newArtifact.lineage = {
1739
- artifactId: newHash,
1740
- lineageId: receipt.lineage.lineageId,
1741
- parentArtifactId: receipt.contentHash,
1742
- rootArtifactId: receipt.lineage.rootArtifactId
1743
- };
1744
- } else {
1745
- newArtifact.lineage.parentArtifactId = receipt.contentHash;
1746
- }
1747
- newArtifact.contentHash = calculateContentHash(newArtifact, CURRENT_HASH_VERSION);
1748
- newArtifact.lineage.artifactId = newArtifact.contentHash;
1749
1829
  return receipt;
1750
1830
  }
1751
1831
 
@@ -1979,7 +2059,11 @@ function createTxPlanArtifact(options) {
1979
2059
  transactionId: i.outpoint.transactionId,
1980
2060
  index: i.outpoint.index
1981
2061
  },
1982
- 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 } : {}
1983
2067
  })),
1984
2068
  outputs: options.plan.outputs.map((o) => ({
1985
2069
  address: o.address,
@@ -2006,16 +2090,13 @@ function createTxPlanArtifact(options) {
2006
2090
  artifact.planId = `plan-${hash.slice(0, 16)}`;
2007
2091
  artifact.contentHash = hash;
2008
2092
  if (artifact.lineage) {
2009
- artifact.lineage.lineageId = artifact.contentHash;
2010
- artifact.lineage.artifactId = artifact.contentHash;
2011
- artifact.lineage.parentArtifactId = artifact.contentHash;
2012
- artifact.lineage.rootArtifactId = artifact.contentHash;
2093
+ artifact.lineage.lineageId = hash;
2094
+ artifact.lineage.parentArtifactId = hash;
2095
+ artifact.lineage.rootArtifactId = hash;
2013
2096
  const finalHash = calculateContentHash(artifact, CURRENT_HASH_VERSION);
2014
2097
  artifact.planId = `plan-${finalHash.slice(0, 16)}`;
2015
2098
  artifact.contentHash = finalHash;
2016
2099
  artifact.lineage.artifactId = finalHash;
2017
- artifact.lineage.parentArtifactId = finalHash;
2018
- artifact.lineage.rootArtifactId = finalHash;
2019
2100
  }
2020
2101
  return artifact;
2021
2102
  }
@@ -2041,13 +2122,7 @@ function createSimulatedSignedTxArtifact(plan, payload, ctx) {
2041
2122
  format: "simulated",
2042
2123
  payload
2043
2124
  },
2044
- lineage: {
2045
- artifactId: "",
2046
- lineageId: plan.lineage?.lineageId || plan.contentHash || "0".repeat(64),
2047
- parentArtifactId: plan.contentHash || "0".repeat(64),
2048
- rootArtifactId: plan.lineage?.rootArtifactId || plan.contentHash || "0".repeat(64),
2049
- sequence: (plan.lineage?.sequence || 0) + 1
2050
- },
2125
+ lineage: createLineageTransition(plan, "hardkas.signedTx"),
2051
2126
  ...plan.workflowId ? { workflowId: plan.workflowId } : {}
2052
2127
  };
2053
2128
  const hash = calculateContentHash(artifact, CURRENT_HASH_VERSION);
@@ -2081,21 +2156,16 @@ function createSimulatedTxReceipt(plan, txId, ctx, extra) {
2081
2156
  preStateHash: extra?.preStateHash,
2082
2157
  postStateHash: extra?.postStateHash,
2083
2158
  dagContext: extra?.dagContext,
2084
- lineage: {
2085
- artifactId: "",
2086
- lineageId: plan.lineage?.lineageId || plan.contentHash || "0".repeat(64),
2087
- parentArtifactId: "0".repeat(64),
2088
- // Will set to contentHash of signedTx later
2089
- rootArtifactId: plan.lineage?.rootArtifactId || plan.contentHash || "0".repeat(64),
2090
- sequence: (plan.lineage?.sequence || 1) + 1
2091
- },
2159
+ lineage: createLineageTransition(plan, "hardkas.txReceipt"),
2092
2160
  ...plan.workflowId ? { workflowId: plan.workflowId } : {}
2093
2161
  };
2162
+ if (artifact.lineage) {
2163
+ artifact.lineage.parentArtifactId = extra?.preStateHash || txId.replace("simulated-", "").replace("-tx", "").padEnd(64, "0").slice(0, 64);
2164
+ }
2094
2165
  const hash = calculateContentHash(artifact, CURRENT_HASH_VERSION);
2095
2166
  artifact.contentHash = hash;
2096
2167
  if (artifact.lineage) {
2097
2168
  artifact.lineage.artifactId = hash;
2098
- artifact.lineage.parentArtifactId = extra?.preStateHash || txId.replace("simulated-", "").replace("-tx", "").padEnd(64, "0").slice(0, 64);
2099
2169
  }
2100
2170
  return artifact;
2101
2171
  }
@@ -2579,6 +2649,7 @@ export {
2579
2649
  TxPlanSchema,
2580
2650
  TxReceiptSchema,
2581
2651
  TxTraceSchema,
2652
+ V4_SEMANTIC_EXCLUSIONS,
2582
2653
  WorkflowSchema,
2583
2654
  assertDecimalBigIntString,
2584
2655
  assertEvmAddress,
@@ -2598,6 +2669,7 @@ export {
2598
2669
  createIgraDeployPlanId,
2599
2670
  createIgraPlanId,
2600
2671
  createIgraSignedId,
2672
+ createLineageTransition,
2601
2673
  createSimulatedSignedTxArtifact,
2602
2674
  createSimulatedTxReceipt,
2603
2675
  createTxPlanArtifact,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardkas/artifacts",
3
- "version": "0.8.5-alpha",
3
+ "version": "0.8.9-alpha",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Javier Rodriguez",
@@ -28,8 +28,8 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "dependencies": {
30
30
  "zod": "^3.24.1",
31
- "@hardkas/core": "0.8.5-alpha",
32
- "@hardkas/tx-builder": "0.8.5-alpha"
31
+ "@hardkas/core": "0.8.9-alpha",
32
+ "@hardkas/tx-builder": "0.8.9-alpha"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "^8.3.5",