@hardkas/core 0.2.2-alpha → 0.2.2-alpha.1

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
@@ -276,6 +276,16 @@ type UnknownEventPayload = {
276
276
  */
277
277
  type Branded<K, T> = Brand<T, K extends string ? K : string>;
278
278
 
279
+ /**
280
+ * Redacts sensitive information from strings and objects recursively.
281
+ * Masks Kaspa private keys (64 hex chars) and mnemonics.
282
+ */
283
+ declare function maskSecrets(data: any): any;
284
+ /**
285
+ * Legacy single-value redaction for backward compatibility.
286
+ */
287
+ declare function redactSecret(value: string): string;
288
+
279
289
  declare const SOMPI_PER_KAS = 100000000n;
280
290
  declare const kaspaNetworkIdSchema: z.ZodEnum<["mainnet", "testnet-10", "testnet-11", "testnet-12", "simnet", "simnet-1", "devnet"]>;
281
291
  type NetworkId = Brand<z.infer<typeof kaspaNetworkIdSchema>, "NetworkId">;
@@ -352,8 +362,18 @@ declare class HardkasError extends Error {
352
362
  cause?: unknown;
353
363
  });
354
364
  }
365
+ type InvariantDomain = "semantic" | "replay" | "provenance" | "structural" | "operational";
366
+ type InvariantSeverity = "warning" | "error" | "fatal";
367
+ declare class InvariantViolationError extends HardkasError {
368
+ readonly domain: InvariantDomain;
369
+ readonly severity: InvariantSeverity;
370
+ constructor(domain: InvariantDomain, message: string, options?: {
371
+ severity?: InvariantSeverity;
372
+ cause?: unknown;
373
+ });
374
+ }
355
375
  declare function parseHardkasConfig(input: unknown): HardkasConfig;
356
376
  declare function parseKasToSompi(input: string): bigint;
357
377
  declare function formatSompi(amountSompi: bigint): string;
358
378
 
359
- export { type ArtifactId, type ArtifactType, ArtifactTypeSchema, type Brand, type Branded, type ContentHash, type CoreEvent, type CoreEventListener, type CorrelationId, type DaaScore, type EventDomain, type EventEnvelope, type EventId, type EventKind, type EventPayloadByKind, type EventSequence, type ExecutionMode, ExecutionModeSchema, type HardkasConfig, HardkasError, type KaspaAddress, type LineageId, type NetworkId, NetworkIdSchema, type RpcEndpointId, SOMPI_PER_KAS, type StampedEvent, type TxId, type UnknownEventPayload, type WorkflowId, artifactTypeSchema, asArtifactId, asContentHash, asCorrelationId, asDaaScore, asEventId, asEventSequence, asKaspaAddress, asLineageId, asNetworkId, asRpcEndpointId, asTxId, asWorkflowId, coreEvents, createEventEnvelope, executionModeSchema, formatSompi, hardkasConfigSchema, kaspaNetworkIdSchema, parseHardkasConfig, parseKasToSompi, validateEventEnvelope };
379
+ export { type ArtifactId, type ArtifactType, ArtifactTypeSchema, type Brand, type Branded, type ContentHash, type CoreEvent, type CoreEventListener, type CorrelationId, type DaaScore, type EventDomain, type EventEnvelope, type EventId, type EventKind, type EventPayloadByKind, type EventSequence, type ExecutionMode, ExecutionModeSchema, type HardkasConfig, HardkasError, type InvariantDomain, type InvariantSeverity, InvariantViolationError, type KaspaAddress, type LineageId, type NetworkId, NetworkIdSchema, type RpcEndpointId, SOMPI_PER_KAS, type StampedEvent, type TxId, type UnknownEventPayload, type WorkflowId, artifactTypeSchema, asArtifactId, asContentHash, asCorrelationId, asDaaScore, asEventId, asEventSequence, asKaspaAddress, asLineageId, asNetworkId, asRpcEndpointId, asTxId, asWorkflowId, coreEvents, createEventEnvelope, executionModeSchema, formatSompi, hardkasConfigSchema, kaspaNetworkIdSchema, maskSecrets, parseHardkasConfig, parseKasToSompi, redactSecret, validateEventEnvelope };
package/dist/index.js CHANGED
@@ -77,6 +77,40 @@ var asNetworkId = (id) => id;
77
77
  var asEventSequence = (seq) => seq;
78
78
  var asDaaScore = (score) => score;
79
79
 
80
+ // src/security.ts
81
+ function maskSecrets(data) {
82
+ if (data === null || data === void 0) return data;
83
+ if (typeof data === "string") {
84
+ let redacted = data.replace(/\b[0-9a-fA-F]{64}\b/g, (match) => {
85
+ return `${match.slice(0, 6)}...${match.slice(-4)} [REDACTED]`;
86
+ });
87
+ redacted = redacted.replace(/\b([a-z]{3,10}\s+){11,23}[a-z]{3,10}\b/g, "[MNEMONIC REDACTED]");
88
+ return redacted;
89
+ }
90
+ if (Array.isArray(data)) {
91
+ return data.map((item) => maskSecrets(item));
92
+ }
93
+ if (typeof data === "object") {
94
+ const redactedObj = {};
95
+ for (const key in data) {
96
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
97
+ if (key.toLowerCase().includes("secret") || key.toLowerCase().includes("privatekey") || key.toLowerCase().includes("mnemonic") || key.toLowerCase().includes("password")) {
98
+ redactedObj[key] = "[REDACTED]";
99
+ } else {
100
+ redactedObj[key] = maskSecrets(data[key]);
101
+ }
102
+ }
103
+ }
104
+ return redactedObj;
105
+ }
106
+ return data;
107
+ }
108
+ function redactSecret(value) {
109
+ if (!value) return "";
110
+ if (value.length <= 10) return "***";
111
+ return `${value.slice(0, 6)}...${value.slice(-4)}`;
112
+ }
113
+
80
114
  // src/index.ts
81
115
  var SOMPI_PER_KAS = 100000000n;
82
116
  var kaspaNetworkIdSchema = z.enum([
@@ -127,6 +161,16 @@ var HardkasError = class extends Error {
127
161
  this.cause = options?.cause;
128
162
  }
129
163
  };
164
+ var InvariantViolationError = class extends HardkasError {
165
+ domain;
166
+ severity;
167
+ constructor(domain, message, options) {
168
+ super(`INVARIANT_VIOLATION_${domain.toUpperCase()}`, message, { cause: options?.cause });
169
+ this.name = "InvariantViolationError";
170
+ this.domain = domain;
171
+ this.severity = options?.severity || "fatal";
172
+ }
173
+ };
130
174
  function parseHardkasConfig(input) {
131
175
  const result = hardkasConfigSchema.safeParse(input);
132
176
  if (!result.success) {
@@ -160,6 +204,7 @@ export {
160
204
  ArtifactTypeSchema,
161
205
  ExecutionModeSchema,
162
206
  HardkasError,
207
+ InvariantViolationError,
163
208
  NetworkIdSchema,
164
209
  SOMPI_PER_KAS,
165
210
  artifactTypeSchema,
@@ -181,7 +226,9 @@ export {
181
226
  formatSompi,
182
227
  hardkasConfigSchema,
183
228
  kaspaNetworkIdSchema,
229
+ maskSecrets,
184
230
  parseHardkasConfig,
185
231
  parseKasToSompi,
232
+ redactSecret,
186
233
  validateEventEnvelope
187
234
  };
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@hardkas/core",
3
- "version": "0.2.2-alpha",
3
+ "version": "0.2.2-alpha.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
8
- ".": "./dist/index.js"
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
9
12
  },
10
13
  "dependencies": {
11
14
  "pino": "^9.5.0",