@bcts/components 1.0.0-alpha.20 → 1.0.0-alpha.21

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/LICENSE CHANGED
@@ -1,5 +1,6 @@
1
1
  Copyright © 2023-2026 Blockchain Commons, LLC
2
- Copyright © 2025-2026 Leonardo Amoroso Custodio
2
+ Copyright © 2025-2026 Parity Technologies
3
+
3
4
 
4
5
  Redistribution and use in source and binary forms, with or without modification,
5
6
  are permitted provided that the following conditions are met:
@@ -0,0 +1,3 @@
1
+ import { t as Digest } from "./digest-DFW8lGqJ.mjs";
2
+
3
+ export { Digest };
@@ -0,0 +1,3 @@
1
+ const require_digest = require('./digest-DWA5qjpo.cjs');
2
+
3
+ exports.Digest = require_digest.Digest;
@@ -5,6 +5,10 @@ import { UR } from "@bcts/uniform-resources";
5
5
 
6
6
  //#region src/error.ts
7
7
  /**
8
+ * Copyright © 2023-2026 Blockchain Commons, LLC
9
+ * Copyright © 2025-2026 Parity Technologies
10
+ *
11
+ *
8
12
  * Error types for cryptographic and component operations
9
13
  *
10
14
  * Ported from bc-components-rust/src/error.rs
@@ -499,6 +503,10 @@ function isCryptoErrorKind(result, kind) {
499
503
  //#endregion
500
504
  //#region src/utils.ts
501
505
  /**
506
+ * Copyright © 2023-2026 Blockchain Commons, LLC
507
+ * Copyright © 2025-2026 Parity Technologies
508
+ *
509
+ *
502
510
  * Utility functions for byte array conversions and comparisons.
503
511
  *
504
512
  * These functions provide cross-platform support for common byte manipulation
@@ -619,6 +627,10 @@ function bytesEqual(a, b) {
619
627
  //#endregion
620
628
  //#region src/digest.ts
621
629
  /**
630
+ * Copyright © 2023-2026 Blockchain Commons, LLC
631
+ * Copyright © 2025-2026 Parity Technologies
632
+ *
633
+ *
622
634
  * SHA-256 cryptographic digest (32 bytes)
623
635
  *
624
636
  * Ported from bc-components-rust/src/digest.rs
@@ -918,4 +930,4 @@ var Digest = class Digest {
918
930
 
919
931
  //#endregion
920
932
  export { hexToBytes as a, ErrorKind as c, isError as d, fromBase64 as i, isCryptoError as l, bytesEqual as n, toBase64 as o, bytesToHex as r, CryptoError as s, Digest as t, isCryptoErrorKind as u };
921
- //# sourceMappingURL=digest-DGAZAt7R.mjs.map
933
+ //# sourceMappingURL=digest-DFW8lGqJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest-DFW8lGqJ.mjs","names":["TAG_DIGEST","cbor"],"sources":["../src/error.ts","../src/utils.ts","../src/digest.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Error types for cryptographic and component operations\n *\n * Ported from bc-components-rust/src/error.rs\n *\n * This module provides a unified error handling system that matches the Rust\n * implementation's error variants with full structural parity:\n *\n * - InvalidSize: Invalid data size for the specified type\n * - InvalidData: Invalid data format or content\n * - DataTooShort: Data too short for the expected type\n * - Crypto: Cryptographic operation failed\n * - Cbor: CBOR encoding or decoding error\n * - Sskr: SSKR error\n * - Ssh: SSH key operation failed\n * - Uri: URI parsing failed\n * - Compression: Data compression/decompression failed\n * - PostQuantum: Post-quantum cryptography library error\n * - LevelMismatch: Signature level mismatch\n * - SshAgent: SSH agent operation failed\n * - Hex: Hex decoding error\n * - Utf8: UTF-8 conversion error\n * - Env: Environment variable error\n * - SshAgentClient: SSH agent client error\n * - General: General error with custom message\n */\n\n/**\n * Error kind enum matching Rust's Error variants.\n *\n * This enum allows programmatic checking of error types, matching the\n * Rust enum variants exactly.\n */\nexport enum ErrorKind {\n /** Invalid data size for the specified type */\n InvalidSize = \"InvalidSize\",\n /** Invalid data format or content */\n InvalidData = \"InvalidData\",\n /** Data too short for the expected type */\n DataTooShort = \"DataTooShort\",\n /** Cryptographic operation failed */\n Crypto = \"Crypto\",\n /** CBOR encoding or decoding error */\n Cbor = \"Cbor\",\n /** SSKR error */\n Sskr = \"Sskr\",\n /** SSH key operation failed */\n Ssh = \"Ssh\",\n /** URI parsing failed */\n Uri = \"Uri\",\n /** Data compression/decompression failed */\n Compression = \"Compression\",\n /** Post-quantum cryptography library error */\n PostQuantum = \"PostQuantum\",\n /** Signature level mismatch */\n LevelMismatch = \"LevelMismatch\",\n /** SSH agent operation failed */\n SshAgent = \"SshAgent\",\n /** Hex decoding error */\n Hex = \"Hex\",\n /** UTF-8 conversion error */\n Utf8 = \"Utf8\",\n /** Environment variable error */\n Env = \"Env\",\n /** SSH agent client error */\n SshAgentClient = \"SshAgentClient\",\n /** General error with custom message */\n General = \"General\",\n}\n\n/**\n * Structured data for InvalidSize errors.\n */\nexport interface InvalidSizeData {\n dataType: string;\n expected: number;\n actual: number;\n}\n\n/**\n * Structured data for InvalidData errors.\n */\nexport interface InvalidDataData {\n dataType: string;\n reason: string;\n}\n\n/**\n * Structured data for DataTooShort errors.\n */\nexport interface DataTooShortData {\n dataType: string;\n minimum: number;\n actual: number;\n}\n\n/**\n * Union type for all possible error data.\n */\nexport type ErrorData =\n | ({ kind: ErrorKind.InvalidSize } & InvalidSizeData)\n | ({ kind: ErrorKind.InvalidData } & InvalidDataData)\n | ({ kind: ErrorKind.DataTooShort } & DataTooShortData)\n | { kind: ErrorKind.Crypto; message: string }\n | { kind: ErrorKind.Cbor; message: string }\n | { kind: ErrorKind.Sskr; message: string }\n | { kind: ErrorKind.Ssh; message: string }\n | { kind: ErrorKind.Uri; message: string }\n | { kind: ErrorKind.Compression; message: string }\n | { kind: ErrorKind.PostQuantum; message: string }\n | { kind: ErrorKind.LevelMismatch }\n | { kind: ErrorKind.SshAgent; message: string }\n | { kind: ErrorKind.Hex; message: string }\n | { kind: ErrorKind.Utf8; message: string }\n | { kind: ErrorKind.Env; message: string }\n | { kind: ErrorKind.SshAgentClient; message: string }\n | { kind: ErrorKind.General; message: string };\n\n/**\n * Error type for cryptographic and component operations.\n *\n * This class provides full structural parity with the Rust Error enum,\n * including:\n * - An `errorKind` property for programmatic error type checking\n * - Structured `errorData` for accessing error-specific fields\n * - Factory methods matching Rust's impl block\n */\nexport class CryptoError extends Error {\n /** The error kind for programmatic type checking */\n readonly errorKind: ErrorKind;\n\n /** Structured error data matching Rust's error variants */\n readonly errorData: ErrorData;\n\n private constructor(message: string, errorData: ErrorData) {\n super(message);\n this.name = \"CryptoError\";\n this.errorKind = errorData.kind;\n this.errorData = errorData;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithStackTrace = Error as {\n captureStackTrace?: (target: Error, ctor: unknown) => void;\n };\n if (typeof ErrorWithStackTrace.captureStackTrace === \"function\") {\n ErrorWithStackTrace.captureStackTrace(this, CryptoError);\n }\n }\n\n // ============================================================================\n // Size and Data Errors\n // ============================================================================\n\n /**\n * Create an invalid size error.\n *\n * Rust equivalent: `Error::InvalidSize { data_type, expected, actual }`\n *\n * @param expected - The expected size\n * @param actual - The actual size received\n */\n static invalidSize(expected: number, actual: number): CryptoError {\n return CryptoError.invalidSizeForType(\"data\", expected, actual);\n }\n\n /**\n * Create an invalid size error with a data type name.\n *\n * Rust equivalent: `Error::invalid_size(data_type, expected, actual)`\n *\n * @param dataType - The name of the data type\n * @param expected - The expected size\n * @param actual - The actual size received\n */\n static invalidSizeForType(dataType: string, expected: number, actual: number): CryptoError {\n return new CryptoError(`invalid ${dataType} size: expected ${expected}, got ${actual}`, {\n kind: ErrorKind.InvalidSize,\n dataType,\n expected,\n actual,\n });\n }\n\n /**\n * Create an invalid data error.\n *\n * @param message - Description of what's invalid\n */\n static invalidData(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"data\", message);\n }\n\n /**\n * Create an invalid data error with a data type name.\n *\n * Rust equivalent: `Error::invalid_data(data_type, reason)`\n *\n * @param dataType - The name of the data type\n * @param reason - The reason the data is invalid\n */\n static invalidDataForType(dataType: string, reason: string): CryptoError {\n return new CryptoError(`invalid ${dataType}: ${reason}`, {\n kind: ErrorKind.InvalidData,\n dataType,\n reason,\n });\n }\n\n /**\n * Create a data too short error.\n *\n * Rust equivalent: `Error::data_too_short(data_type, minimum, actual)`\n *\n * @param dataType - The name of the data type\n * @param minimum - The minimum required size\n * @param actual - The actual size received\n */\n static dataTooShort(dataType: string, minimum: number, actual: number): CryptoError {\n return new CryptoError(\n `data too short: ${dataType} expected at least ${minimum}, got ${actual}`,\n {\n kind: ErrorKind.DataTooShort,\n dataType,\n minimum,\n actual,\n },\n );\n }\n\n // ============================================================================\n // Format and Input Errors (convenience methods)\n // ============================================================================\n\n /**\n * Create an invalid format error.\n *\n * @param message - Description of the format error\n */\n static invalidFormat(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"format\", message);\n }\n\n /**\n * Create an invalid input error.\n *\n * @param message - Description of the invalid input\n */\n static invalidInput(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"input\", message);\n }\n\n // ============================================================================\n // Cryptographic Errors\n // ============================================================================\n\n /**\n * Create a cryptographic operation failed error.\n *\n * Rust equivalent: `Error::crypto(msg)`\n *\n * @param message - Description of the failure\n */\n static cryptoOperation(message: string): CryptoError {\n return CryptoError.crypto(message);\n }\n\n /**\n * Create a crypto error.\n *\n * Rust equivalent: `Error::Crypto(msg)`\n *\n * @param message - Description of the failure\n */\n static crypto(message: string): CryptoError {\n return new CryptoError(`cryptographic operation failed: ${message}`, {\n kind: ErrorKind.Crypto,\n message,\n });\n }\n\n /**\n * Create a post-quantum cryptography error.\n *\n * Rust equivalent: `Error::post_quantum(msg)`\n *\n * @param message - Description of the failure\n */\n static postQuantum(message: string): CryptoError {\n return new CryptoError(`post-quantum cryptography error: ${message}`, {\n kind: ErrorKind.PostQuantum,\n message,\n });\n }\n\n /**\n * Create a signature level mismatch error.\n *\n * Rust equivalent: `Error::LevelMismatch`\n */\n static levelMismatch(): CryptoError {\n return new CryptoError(\"signature level does not match key level\", {\n kind: ErrorKind.LevelMismatch,\n });\n }\n\n // ============================================================================\n // Encoding/Serialization Errors\n // ============================================================================\n\n /**\n * Create a CBOR error.\n *\n * Rust equivalent: `Error::Cbor(err)`\n *\n * @param message - Description of the CBOR error\n */\n static cbor(message: string): CryptoError {\n return new CryptoError(`CBOR error: ${message}`, {\n kind: ErrorKind.Cbor,\n message,\n });\n }\n\n /**\n * Create a hex decoding error.\n *\n * Rust equivalent: `Error::Hex(err)`\n *\n * @param message - Description of the hex error\n */\n static hex(message: string): CryptoError {\n return new CryptoError(`hex decoding error: ${message}`, {\n kind: ErrorKind.Hex,\n message,\n });\n }\n\n /**\n * Create a UTF-8 conversion error.\n *\n * Rust equivalent: `Error::Utf8(err)`\n *\n * @param message - Description of the UTF-8 error\n */\n static utf8(message: string): CryptoError {\n return new CryptoError(`UTF-8 conversion error: ${message}`, {\n kind: ErrorKind.Utf8,\n message,\n });\n }\n\n // ============================================================================\n // Compression Errors\n // ============================================================================\n\n /**\n * Create a compression error.\n *\n * Rust equivalent: `Error::compression(msg)`\n *\n * @param message - Description of the compression error\n */\n static compression(message: string): CryptoError {\n return new CryptoError(`compression error: ${message}`, {\n kind: ErrorKind.Compression,\n message,\n });\n }\n\n // ============================================================================\n // URI Errors\n // ============================================================================\n\n /**\n * Create a URI parsing error.\n *\n * Rust equivalent: `Error::Uri(err)`\n *\n * @param message - Description of the URI error\n */\n static uri(message: string): CryptoError {\n return new CryptoError(`invalid URI: ${message}`, {\n kind: ErrorKind.Uri,\n message,\n });\n }\n\n // ============================================================================\n // SSKR Errors\n // ============================================================================\n\n /**\n * Create an SSKR error.\n *\n * Rust equivalent: `Error::Sskr(err)`\n *\n * @param message - Description of the SSKR error\n */\n static sskr(message: string): CryptoError {\n return new CryptoError(`SSKR error: ${message}`, {\n kind: ErrorKind.Sskr,\n message,\n });\n }\n\n // ============================================================================\n // SSH Errors\n // ============================================================================\n\n /**\n * Create an SSH operation error.\n *\n * Rust equivalent: `Error::ssh(msg)`\n *\n * @param message - Description of the SSH error\n */\n static ssh(message: string): CryptoError {\n return new CryptoError(`SSH operation failed: ${message}`, {\n kind: ErrorKind.Ssh,\n message,\n });\n }\n\n /**\n * Create an SSH agent error.\n *\n * Rust equivalent: `Error::ssh_agent(msg)`\n *\n * @param message - Description of the SSH agent error\n */\n static sshAgent(message: string): CryptoError {\n return new CryptoError(`SSH agent error: ${message}`, {\n kind: ErrorKind.SshAgent,\n message,\n });\n }\n\n /**\n * Create an SSH agent client error.\n *\n * Rust equivalent: `Error::ssh_agent_client(msg)`\n *\n * @param message - Description of the SSH agent client error\n */\n static sshAgentClient(message: string): CryptoError {\n return new CryptoError(`SSH agent client error: ${message}`, {\n kind: ErrorKind.SshAgentClient,\n message,\n });\n }\n\n // ============================================================================\n // Environment Errors\n // ============================================================================\n\n /**\n * Create an environment variable error.\n *\n * Rust equivalent: `Error::Env(err)`\n *\n * @param message - Description of the environment error\n */\n static env(message: string): CryptoError {\n return new CryptoError(`environment variable error: ${message}`, {\n kind: ErrorKind.Env,\n message,\n });\n }\n\n // ============================================================================\n // General Errors\n // ============================================================================\n\n /**\n * Create a general error with a custom message.\n *\n * Rust equivalent: `Error::general(msg)` / `Error::General(msg)`\n *\n * @param message - The error message\n */\n static general(message: string): CryptoError {\n return new CryptoError(message, {\n kind: ErrorKind.General,\n message,\n });\n }\n\n // ============================================================================\n // Error Kind Checking Methods\n // ============================================================================\n\n /**\n * Check if this error is of a specific kind.\n *\n * @param kind - The error kind to check\n */\n isKind(kind: ErrorKind): boolean {\n return this.errorKind === kind;\n }\n\n /**\n * Check if this is an InvalidSize error.\n */\n isInvalidSize(): this is CryptoError & {\n errorData: InvalidSizeData & { kind: ErrorKind.InvalidSize };\n } {\n return this.errorKind === ErrorKind.InvalidSize;\n }\n\n /**\n * Check if this is an InvalidData error.\n */\n isInvalidData(): this is CryptoError & {\n errorData: InvalidDataData & { kind: ErrorKind.InvalidData };\n } {\n return this.errorKind === ErrorKind.InvalidData;\n }\n\n /**\n * Check if this is a DataTooShort error.\n */\n isDataTooShort(): this is CryptoError & {\n errorData: DataTooShortData & { kind: ErrorKind.DataTooShort };\n } {\n return this.errorKind === ErrorKind.DataTooShort;\n }\n\n /**\n * Check if this is a Crypto error.\n */\n isCrypto(): boolean {\n return this.errorKind === ErrorKind.Crypto;\n }\n\n /**\n * Check if this is a Cbor error.\n */\n isCbor(): boolean {\n return this.errorKind === ErrorKind.Cbor;\n }\n\n /**\n * Check if this is an Sskr error.\n */\n isSskr(): boolean {\n return this.errorKind === ErrorKind.Sskr;\n }\n\n /**\n * Check if this is an Ssh error.\n */\n isSsh(): boolean {\n return this.errorKind === ErrorKind.Ssh;\n }\n\n /**\n * Check if this is a Uri error.\n */\n isUri(): boolean {\n return this.errorKind === ErrorKind.Uri;\n }\n\n /**\n * Check if this is a Compression error.\n */\n isCompression(): boolean {\n return this.errorKind === ErrorKind.Compression;\n }\n\n /**\n * Check if this is a PostQuantum error.\n */\n isPostQuantum(): boolean {\n return this.errorKind === ErrorKind.PostQuantum;\n }\n\n /**\n * Check if this is a LevelMismatch error.\n */\n isLevelMismatch(): boolean {\n return this.errorKind === ErrorKind.LevelMismatch;\n }\n\n /**\n * Check if this is an SshAgent error.\n */\n isSshAgent(): boolean {\n return this.errorKind === ErrorKind.SshAgent;\n }\n\n /**\n * Check if this is a Hex error.\n */\n isHex(): boolean {\n return this.errorKind === ErrorKind.Hex;\n }\n\n /**\n * Check if this is a Utf8 error.\n */\n isUtf8(): boolean {\n return this.errorKind === ErrorKind.Utf8;\n }\n\n /**\n * Check if this is an Env error.\n */\n isEnv(): boolean {\n return this.errorKind === ErrorKind.Env;\n }\n\n /**\n * Check if this is an SshAgentClient error.\n */\n isSshAgentClient(): boolean {\n return this.errorKind === ErrorKind.SshAgentClient;\n }\n\n /**\n * Check if this is a General error.\n */\n isGeneral(): boolean {\n return this.errorKind === ErrorKind.General;\n }\n}\n\n/**\n * Result type that can be either a success value or an Error.\n */\nexport type Result<T> = T | Error;\n\n/**\n * Type guard to check if a result is an Error.\n */\nexport function isError(result: unknown): result is Error {\n return result instanceof Error;\n}\n\n/**\n * Type guard to check if a result is a CryptoError.\n */\nexport function isCryptoError(result: unknown): result is CryptoError {\n return result instanceof CryptoError;\n}\n\n/**\n * Type guard to check if an error is a CryptoError of a specific kind.\n */\nexport function isCryptoErrorKind(result: unknown, kind: ErrorKind): result is CryptoError {\n return isCryptoError(result) && result.errorKind === kind;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Utility functions for byte array conversions and comparisons.\n *\n * These functions provide cross-platform support for common byte manipulation\n * operations needed in cryptographic and encoding contexts.\n *\n * @packageDocumentation\n */\n\n/**\n * Convert a Uint8Array to a lowercase hexadecimal string.\n *\n * @param data - The byte array to convert\n * @returns A lowercase hex string representation (2 characters per byte)\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);\n * bytesToHex(bytes); // \"deadbeef\"\n * ```\n */\nexport function bytesToHex(data: Uint8Array): string {\n return Array.from(data)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Convert a hexadecimal string to a Uint8Array.\n *\n * @param hex - A hex string (must have even length, case-insensitive)\n * @returns The decoded byte array\n * @throws {Error} If the hex string has odd length or contains invalid characters\n *\n * @example\n * ```typescript\n * hexToBytes(\"deadbeef\"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])\n * hexToBytes(\"DEADBEEF\"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])\n * hexToBytes(\"xyz\"); // throws Error: Invalid hex string\n * ```\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) {\n throw new Error(`Hex string must have even length, got ${hex.length}`);\n }\n if (!/^[0-9A-Fa-f]*$/.test(hex)) {\n throw new Error(\"Invalid hex string: contains non-hexadecimal characters\");\n }\n const data = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n data[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n }\n return data;\n}\n\n/**\n * Convert a Uint8Array to a base64-encoded string.\n *\n * This function works in both browser and Node.js environments.\n * Uses btoa which is available in browsers and Node.js 16+.\n *\n * @param data - The byte array to encode\n * @returns A base64-encoded string\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([72, 101, 108, 108, 111]); // \"Hello\"\n * toBase64(bytes); // \"SGVsbG8=\"\n * ```\n */\nexport function toBase64(data: Uint8Array): string {\n // Convert bytes to binary string without spread operator to avoid\n // call stack limits for large arrays (spread would fail at ~65k bytes)\n let binary = \"\";\n for (const byte of data) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n}\n\n/**\n * Convert a base64-encoded string to a Uint8Array.\n *\n * This function works in both browser and Node.js environments.\n * Uses atob which is available in browsers and Node.js 16+.\n *\n * @param base64 - A base64-encoded string\n * @returns The decoded byte array\n *\n * @example\n * ```typescript\n * fromBase64(\"SGVsbG8=\"); // Uint8Array([72, 101, 108, 108, 111])\n * ```\n */\nexport function fromBase64(base64: string): Uint8Array {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\n/**\n * Compare two Uint8Arrays for equality using constant-time comparison.\n *\n * This function is designed to be resistant to timing attacks by always\n * comparing all bytes regardless of where a difference is found. The\n * comparison time depends only on the length of the arrays, not on where\n * they differ.\n *\n * **Security Note**: If the arrays have different lengths, this function\n * returns `false` immediately, which does leak length information. For\n * cryptographic uses where length should also be secret, ensure both\n * arrays are the same length before comparison.\n *\n * @param a - First byte array\n * @param b - Second byte array\n * @returns `true` if both arrays have the same length and identical contents\n *\n * @example\n * ```typescript\n * const key1 = new Uint8Array([1, 2, 3, 4]);\n * const key2 = new Uint8Array([1, 2, 3, 4]);\n * const key3 = new Uint8Array([1, 2, 3, 5]);\n *\n * bytesEqual(key1, key2); // true\n * bytesEqual(key1, key3); // false\n * ```\n */\nexport function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a[i] ^ b[i];\n }\n return result === 0;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * SHA-256 cryptographic digest (32 bytes)\n *\n * Ported from bc-components-rust/src/digest.rs\n *\n * A `Digest` represents the cryptographic hash of some data. In this\n * implementation, SHA-256 is used, which produces a 32-byte hash value.\n * Digests are used throughout the crate for data verification and as unique\n * identifiers derived from data.\n *\n * # CBOR Serialization\n *\n * `Digest` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with a specific tag (TAG_DIGEST = 40001).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `Digest` is represented as a\n * binary blob with the type \"digest\".\n *\n * @example\n * ```typescript\n * import { Digest } from '@bcts/components';\n *\n * // Create a digest from a string\n * const data = new TextEncoder().encode(\"hello world\");\n * const digest = Digest.fromImage(data);\n *\n * // Validate that the digest matches the original data\n * console.log(digest.validate(data)); // true\n *\n * // Create a digest from a hex string\n * const hexString = \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\";\n * const digest2 = Digest.fromHex(hexString);\n *\n * // Retrieve the digest as hex\n * console.log(digest2.hex()); // b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\n * ```\n */\n\nimport { sha256, SHA256_SIZE } from \"@bcts/crypto\";\nimport {\n type Cbor,\n type Tag,\n type CborTaggedEncodable,\n type CborTaggedDecodable,\n toByteString,\n expectBytes,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { DIGEST as TAG_DIGEST } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"./utils.js\";\nimport type { DigestProvider } from \"./digest-provider.js\";\n\nexport class Digest\n implements DigestProvider, CborTaggedEncodable, CborTaggedDecodable<Digest>, UREncodable\n{\n static readonly DIGEST_SIZE = SHA256_SIZE;\n\n private readonly _data: Uint8Array;\n\n private constructor(data: Uint8Array) {\n if (data.length !== Digest.DIGEST_SIZE) {\n throw CryptoError.invalidSize(Digest.DIGEST_SIZE, data.length);\n }\n this._data = new Uint8Array(data);\n }\n\n /**\n * Get the digest data.\n */\n data(): Uint8Array {\n return this._data;\n }\n\n // ============================================================================\n // Static Factory Methods\n // ============================================================================\n\n /**\n * Create a Digest from a 32-byte array.\n */\n static fromData(data: Uint8Array): Digest {\n return new Digest(new Uint8Array(data));\n }\n\n /**\n * Create a Digest from data, validating the length.\n * Alias for fromData for compatibility with Rust API.\n */\n static fromDataRef(data: Uint8Array): Digest {\n return Digest.fromData(data);\n }\n\n /**\n * Create a Digest from hex string.\n *\n * @throws Error if the hex string is not exactly 64 characters.\n */\n static fromHex(hex: string): Digest {\n return new Digest(hexToBytes(hex));\n }\n\n /**\n * Compute SHA-256 digest of data (called \"image\" in Rust).\n *\n * @param image - The data to hash\n */\n static fromImage(image: Uint8Array): Digest {\n const hashData = sha256(image);\n return new Digest(new Uint8Array(hashData));\n }\n\n /**\n * Compute SHA-256 digest from multiple data parts.\n *\n * The parts are concatenated and then hashed.\n *\n * @param imageParts - Array of byte arrays to concatenate and hash\n */\n static fromImageParts(imageParts: Uint8Array[]): Digest {\n const totalLength = imageParts.reduce((sum, part) => sum + part.length, 0);\n const buf = new Uint8Array(totalLength);\n let offset = 0;\n for (const part of imageParts) {\n buf.set(part, offset);\n offset += part.length;\n }\n return Digest.fromImage(buf);\n }\n\n /**\n * Compute SHA-256 digest from an array of Digests.\n *\n * The digest bytes are concatenated and then hashed.\n *\n * @param digests - Array of Digests to combine\n */\n static fromDigests(digests: Digest[]): Digest {\n const buf = new Uint8Array(digests.length * Digest.DIGEST_SIZE);\n let offset = 0;\n for (const digest of digests) {\n buf.set(digest._data, offset);\n offset += Digest.DIGEST_SIZE;\n }\n return Digest.fromImage(buf);\n }\n\n /**\n * Compute SHA-256 digest of data (legacy alias for fromImage).\n * @deprecated Use fromImage instead\n */\n static hash(data: Uint8Array): Digest {\n return Digest.fromImage(data);\n }\n\n // ============================================================================\n // Instance Methods\n // ============================================================================\n\n /**\n * Get the raw digest bytes as a copy.\n */\n toData(): Uint8Array {\n return new Uint8Array(this._data);\n }\n\n /**\n * Get a reference to the raw digest bytes.\n */\n asBytes(): Uint8Array {\n return this._data;\n }\n\n /**\n * Get hex string representation.\n */\n hex(): string {\n return bytesToHex(this._data);\n }\n\n /**\n * Get hex string representation (alias for hex()).\n */\n toHex(): string {\n return this.hex();\n }\n\n /**\n * Get base64 representation.\n */\n toBase64(): string {\n return toBase64(this._data);\n }\n\n /**\n * Get the first four bytes of the digest as a hexadecimal string.\n * Useful for short descriptions.\n */\n shortDescription(): string {\n return bytesToHex(this._data.slice(0, 4));\n }\n\n /**\n * Validate the digest against the given image.\n *\n * The image is hashed with SHA-256 and compared to this digest.\n * @returns `true` if the digest matches the image.\n */\n validate(image: Uint8Array): boolean {\n return this.equals(Digest.fromImage(image));\n }\n\n /**\n * Compare with another Digest.\n */\n equals(other: Digest): boolean {\n if (this._data.length !== other._data.length) return false;\n for (let i = 0; i < this._data.length; i++) {\n if (this._data[i] !== other._data[i]) return false;\n }\n return true;\n }\n\n /**\n * Compare digests lexicographically.\n */\n compare(other: Digest): number {\n for (let i = 0; i < this._data.length; i++) {\n const a = this._data[i];\n const b = other._data[i];\n if (a < b) return -1;\n if (a > b) return 1;\n }\n return 0;\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n return `Digest(${this.hex()})`;\n }\n\n // ============================================================================\n // DigestProvider Implementation\n // ============================================================================\n\n /**\n * A Digest is its own digest provider - returns itself.\n */\n digest(): Digest {\n return this;\n }\n\n // ============================================================================\n // CBOR Serialization (CborTaggedEncodable)\n // ============================================================================\n\n /**\n * Returns the CBOR tags associated with Digest.\n */\n cborTags(): Tag[] {\n return tagsForValues([TAG_DIGEST.value]);\n }\n\n /**\n * Returns the untagged CBOR encoding (as a byte string).\n */\n untaggedCbor(): Cbor {\n return toByteString(this._data);\n }\n\n /**\n * Returns the tagged CBOR encoding.\n */\n taggedCbor(): Cbor {\n return createTaggedCbor(this);\n }\n\n /**\n * Returns the tagged value in CBOR binary representation.\n */\n taggedCborData(): Uint8Array {\n return this.taggedCbor().toData();\n }\n\n // ============================================================================\n // CBOR Deserialization (CborTaggedDecodable)\n // ============================================================================\n\n /**\n * Creates a Digest by decoding it from untagged CBOR.\n */\n fromUntaggedCbor(cbor: Cbor): Digest {\n const data = expectBytes(cbor);\n return Digest.fromData(data);\n }\n\n /**\n * Creates a Digest by decoding it from tagged CBOR.\n */\n fromTaggedCbor(cbor: Cbor): Digest {\n validateTag(cbor, this.cborTags());\n const content = extractTaggedContent(cbor);\n return this.fromUntaggedCbor(content);\n }\n\n /**\n * Static method to decode from tagged CBOR.\n */\n static fromTaggedCbor(cbor: Cbor): Digest {\n const instance = new Digest(new Uint8Array(Digest.DIGEST_SIZE));\n return instance.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from tagged CBOR binary data.\n */\n static fromTaggedCborData(data: Uint8Array): Digest {\n const cbor = decodeCbor(data);\n return Digest.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from untagged CBOR binary data.\n */\n static fromUntaggedCborData(data: Uint8Array): Digest {\n const cbor = decodeCbor(data);\n const bytes = expectBytes(cbor);\n return Digest.fromData(bytes);\n }\n\n // ============================================================================\n // UR Serialization (UREncodable)\n // ============================================================================\n\n /**\n * Returns the UR representation of the Digest.\n * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n */\n ur(): UR {\n return UR.new(\"digest\", this.untaggedCbor());\n }\n\n /**\n * Returns the UR string representation.\n */\n urString(): string {\n return this.ur().string();\n }\n\n /**\n * Creates a Digest from a UR.\n */\n static fromUR(ur: UR): Digest {\n ur.checkType(\"digest\");\n const instance = new Digest(new Uint8Array(Digest.DIGEST_SIZE));\n return instance.fromUntaggedCbor(ur.cbor());\n }\n\n /**\n * Creates a Digest from a UR string.\n */\n static fromURString(urString: string): Digest {\n const ur = UR.fromURString(urString);\n return Digest.fromUR(ur);\n }\n\n // ============================================================================\n // Static Utility Methods\n // ============================================================================\n\n /**\n * Validate the given data against the digest, if any.\n *\n * Returns `true` if the digest is `undefined` or if the digest matches the\n * image's digest. Returns `false` if the digest does not match.\n */\n static validateOpt(image: Uint8Array, digest: Digest | undefined): boolean {\n if (digest === undefined) {\n return true;\n }\n return digest.validate(image);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAY,kDAAL;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;;;;;;;;;;;AA4DF,IAAa,cAAb,MAAa,oBAAoB,MAAM;;CAErC,AAAS;;CAGT,AAAS;CAET,AAAQ,YAAY,SAAiB,WAAsB;AACzD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,YAAY,UAAU;AAC3B,OAAK,YAAY;EAGjB,MAAM,sBAAsB;AAG5B,MAAI,OAAO,oBAAoB,sBAAsB,WACnD,qBAAoB,kBAAkB,MAAM,YAAY;;;;;;;;;;CAgB5D,OAAO,YAAY,UAAkB,QAA6B;AAChE,SAAO,YAAY,mBAAmB,QAAQ,UAAU,OAAO;;;;;;;;;;;CAYjE,OAAO,mBAAmB,UAAkB,UAAkB,QAA6B;AACzF,SAAO,IAAI,YAAY,WAAW,SAAS,kBAAkB,SAAS,QAAQ,UAAU;GACtF,MAAM,UAAU;GAChB;GACA;GACA;GACD,CAAC;;;;;;;CAQJ,OAAO,YAAY,SAA8B;AAC/C,SAAO,YAAY,mBAAmB,QAAQ,QAAQ;;;;;;;;;;CAWxD,OAAO,mBAAmB,UAAkB,QAA6B;AACvE,SAAO,IAAI,YAAY,WAAW,SAAS,IAAI,UAAU;GACvD,MAAM,UAAU;GAChB;GACA;GACD,CAAC;;;;;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W,OACb,QAAO;AAET,SAAO,OAAO,SAAS,MAAM"}
@@ -6,6 +6,10 @@ let _bcts_uniform_resources = require("@bcts/uniform-resources");
6
6
 
7
7
  //#region src/error.ts
8
8
  /**
9
+ * Copyright © 2023-2026 Blockchain Commons, LLC
10
+ * Copyright © 2025-2026 Parity Technologies
11
+ *
12
+ *
9
13
  * Error types for cryptographic and component operations
10
14
  *
11
15
  * Ported from bc-components-rust/src/error.rs
@@ -500,6 +504,10 @@ function isCryptoErrorKind(result, kind) {
500
504
  //#endregion
501
505
  //#region src/utils.ts
502
506
  /**
507
+ * Copyright © 2023-2026 Blockchain Commons, LLC
508
+ * Copyright © 2025-2026 Parity Technologies
509
+ *
510
+ *
503
511
  * Utility functions for byte array conversions and comparisons.
504
512
  *
505
513
  * These functions provide cross-platform support for common byte manipulation
@@ -620,6 +628,10 @@ function bytesEqual(a, b) {
620
628
  //#endregion
621
629
  //#region src/digest.ts
622
630
  /**
631
+ * Copyright © 2023-2026 Blockchain Commons, LLC
632
+ * Copyright © 2025-2026 Parity Technologies
633
+ *
634
+ *
623
635
  * SHA-256 cryptographic digest (32 bytes)
624
636
  *
625
637
  * Ported from bc-components-rust/src/digest.rs
@@ -984,4 +996,4 @@ Object.defineProperty(exports, 'toBase64', {
984
996
  return toBase64;
985
997
  }
986
998
  });
987
- //# sourceMappingURL=digest-DTBmqDcQ.cjs.map
999
+ //# sourceMappingURL=digest-DWA5qjpo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"digest-DWA5qjpo.cjs","names":["SHA256_SIZE","TAG_DIGEST","UR"],"sources":["../src/error.ts","../src/utils.ts","../src/digest.ts"],"sourcesContent":["/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Error types for cryptographic and component operations\n *\n * Ported from bc-components-rust/src/error.rs\n *\n * This module provides a unified error handling system that matches the Rust\n * implementation's error variants with full structural parity:\n *\n * - InvalidSize: Invalid data size for the specified type\n * - InvalidData: Invalid data format or content\n * - DataTooShort: Data too short for the expected type\n * - Crypto: Cryptographic operation failed\n * - Cbor: CBOR encoding or decoding error\n * - Sskr: SSKR error\n * - Ssh: SSH key operation failed\n * - Uri: URI parsing failed\n * - Compression: Data compression/decompression failed\n * - PostQuantum: Post-quantum cryptography library error\n * - LevelMismatch: Signature level mismatch\n * - SshAgent: SSH agent operation failed\n * - Hex: Hex decoding error\n * - Utf8: UTF-8 conversion error\n * - Env: Environment variable error\n * - SshAgentClient: SSH agent client error\n * - General: General error with custom message\n */\n\n/**\n * Error kind enum matching Rust's Error variants.\n *\n * This enum allows programmatic checking of error types, matching the\n * Rust enum variants exactly.\n */\nexport enum ErrorKind {\n /** Invalid data size for the specified type */\n InvalidSize = \"InvalidSize\",\n /** Invalid data format or content */\n InvalidData = \"InvalidData\",\n /** Data too short for the expected type */\n DataTooShort = \"DataTooShort\",\n /** Cryptographic operation failed */\n Crypto = \"Crypto\",\n /** CBOR encoding or decoding error */\n Cbor = \"Cbor\",\n /** SSKR error */\n Sskr = \"Sskr\",\n /** SSH key operation failed */\n Ssh = \"Ssh\",\n /** URI parsing failed */\n Uri = \"Uri\",\n /** Data compression/decompression failed */\n Compression = \"Compression\",\n /** Post-quantum cryptography library error */\n PostQuantum = \"PostQuantum\",\n /** Signature level mismatch */\n LevelMismatch = \"LevelMismatch\",\n /** SSH agent operation failed */\n SshAgent = \"SshAgent\",\n /** Hex decoding error */\n Hex = \"Hex\",\n /** UTF-8 conversion error */\n Utf8 = \"Utf8\",\n /** Environment variable error */\n Env = \"Env\",\n /** SSH agent client error */\n SshAgentClient = \"SshAgentClient\",\n /** General error with custom message */\n General = \"General\",\n}\n\n/**\n * Structured data for InvalidSize errors.\n */\nexport interface InvalidSizeData {\n dataType: string;\n expected: number;\n actual: number;\n}\n\n/**\n * Structured data for InvalidData errors.\n */\nexport interface InvalidDataData {\n dataType: string;\n reason: string;\n}\n\n/**\n * Structured data for DataTooShort errors.\n */\nexport interface DataTooShortData {\n dataType: string;\n minimum: number;\n actual: number;\n}\n\n/**\n * Union type for all possible error data.\n */\nexport type ErrorData =\n | ({ kind: ErrorKind.InvalidSize } & InvalidSizeData)\n | ({ kind: ErrorKind.InvalidData } & InvalidDataData)\n | ({ kind: ErrorKind.DataTooShort } & DataTooShortData)\n | { kind: ErrorKind.Crypto; message: string }\n | { kind: ErrorKind.Cbor; message: string }\n | { kind: ErrorKind.Sskr; message: string }\n | { kind: ErrorKind.Ssh; message: string }\n | { kind: ErrorKind.Uri; message: string }\n | { kind: ErrorKind.Compression; message: string }\n | { kind: ErrorKind.PostQuantum; message: string }\n | { kind: ErrorKind.LevelMismatch }\n | { kind: ErrorKind.SshAgent; message: string }\n | { kind: ErrorKind.Hex; message: string }\n | { kind: ErrorKind.Utf8; message: string }\n | { kind: ErrorKind.Env; message: string }\n | { kind: ErrorKind.SshAgentClient; message: string }\n | { kind: ErrorKind.General; message: string };\n\n/**\n * Error type for cryptographic and component operations.\n *\n * This class provides full structural parity with the Rust Error enum,\n * including:\n * - An `errorKind` property for programmatic error type checking\n * - Structured `errorData` for accessing error-specific fields\n * - Factory methods matching Rust's impl block\n */\nexport class CryptoError extends Error {\n /** The error kind for programmatic type checking */\n readonly errorKind: ErrorKind;\n\n /** Structured error data matching Rust's error variants */\n readonly errorData: ErrorData;\n\n private constructor(message: string, errorData: ErrorData) {\n super(message);\n this.name = \"CryptoError\";\n this.errorKind = errorData.kind;\n this.errorData = errorData;\n\n // Maintains proper stack trace in V8 environments\n const ErrorWithStackTrace = Error as {\n captureStackTrace?: (target: Error, ctor: unknown) => void;\n };\n if (typeof ErrorWithStackTrace.captureStackTrace === \"function\") {\n ErrorWithStackTrace.captureStackTrace(this, CryptoError);\n }\n }\n\n // ============================================================================\n // Size and Data Errors\n // ============================================================================\n\n /**\n * Create an invalid size error.\n *\n * Rust equivalent: `Error::InvalidSize { data_type, expected, actual }`\n *\n * @param expected - The expected size\n * @param actual - The actual size received\n */\n static invalidSize(expected: number, actual: number): CryptoError {\n return CryptoError.invalidSizeForType(\"data\", expected, actual);\n }\n\n /**\n * Create an invalid size error with a data type name.\n *\n * Rust equivalent: `Error::invalid_size(data_type, expected, actual)`\n *\n * @param dataType - The name of the data type\n * @param expected - The expected size\n * @param actual - The actual size received\n */\n static invalidSizeForType(dataType: string, expected: number, actual: number): CryptoError {\n return new CryptoError(`invalid ${dataType} size: expected ${expected}, got ${actual}`, {\n kind: ErrorKind.InvalidSize,\n dataType,\n expected,\n actual,\n });\n }\n\n /**\n * Create an invalid data error.\n *\n * @param message - Description of what's invalid\n */\n static invalidData(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"data\", message);\n }\n\n /**\n * Create an invalid data error with a data type name.\n *\n * Rust equivalent: `Error::invalid_data(data_type, reason)`\n *\n * @param dataType - The name of the data type\n * @param reason - The reason the data is invalid\n */\n static invalidDataForType(dataType: string, reason: string): CryptoError {\n return new CryptoError(`invalid ${dataType}: ${reason}`, {\n kind: ErrorKind.InvalidData,\n dataType,\n reason,\n });\n }\n\n /**\n * Create a data too short error.\n *\n * Rust equivalent: `Error::data_too_short(data_type, minimum, actual)`\n *\n * @param dataType - The name of the data type\n * @param minimum - The minimum required size\n * @param actual - The actual size received\n */\n static dataTooShort(dataType: string, minimum: number, actual: number): CryptoError {\n return new CryptoError(\n `data too short: ${dataType} expected at least ${minimum}, got ${actual}`,\n {\n kind: ErrorKind.DataTooShort,\n dataType,\n minimum,\n actual,\n },\n );\n }\n\n // ============================================================================\n // Format and Input Errors (convenience methods)\n // ============================================================================\n\n /**\n * Create an invalid format error.\n *\n * @param message - Description of the format error\n */\n static invalidFormat(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"format\", message);\n }\n\n /**\n * Create an invalid input error.\n *\n * @param message - Description of the invalid input\n */\n static invalidInput(message: string): CryptoError {\n return CryptoError.invalidDataForType(\"input\", message);\n }\n\n // ============================================================================\n // Cryptographic Errors\n // ============================================================================\n\n /**\n * Create a cryptographic operation failed error.\n *\n * Rust equivalent: `Error::crypto(msg)`\n *\n * @param message - Description of the failure\n */\n static cryptoOperation(message: string): CryptoError {\n return CryptoError.crypto(message);\n }\n\n /**\n * Create a crypto error.\n *\n * Rust equivalent: `Error::Crypto(msg)`\n *\n * @param message - Description of the failure\n */\n static crypto(message: string): CryptoError {\n return new CryptoError(`cryptographic operation failed: ${message}`, {\n kind: ErrorKind.Crypto,\n message,\n });\n }\n\n /**\n * Create a post-quantum cryptography error.\n *\n * Rust equivalent: `Error::post_quantum(msg)`\n *\n * @param message - Description of the failure\n */\n static postQuantum(message: string): CryptoError {\n return new CryptoError(`post-quantum cryptography error: ${message}`, {\n kind: ErrorKind.PostQuantum,\n message,\n });\n }\n\n /**\n * Create a signature level mismatch error.\n *\n * Rust equivalent: `Error::LevelMismatch`\n */\n static levelMismatch(): CryptoError {\n return new CryptoError(\"signature level does not match key level\", {\n kind: ErrorKind.LevelMismatch,\n });\n }\n\n // ============================================================================\n // Encoding/Serialization Errors\n // ============================================================================\n\n /**\n * Create a CBOR error.\n *\n * Rust equivalent: `Error::Cbor(err)`\n *\n * @param message - Description of the CBOR error\n */\n static cbor(message: string): CryptoError {\n return new CryptoError(`CBOR error: ${message}`, {\n kind: ErrorKind.Cbor,\n message,\n });\n }\n\n /**\n * Create a hex decoding error.\n *\n * Rust equivalent: `Error::Hex(err)`\n *\n * @param message - Description of the hex error\n */\n static hex(message: string): CryptoError {\n return new CryptoError(`hex decoding error: ${message}`, {\n kind: ErrorKind.Hex,\n message,\n });\n }\n\n /**\n * Create a UTF-8 conversion error.\n *\n * Rust equivalent: `Error::Utf8(err)`\n *\n * @param message - Description of the UTF-8 error\n */\n static utf8(message: string): CryptoError {\n return new CryptoError(`UTF-8 conversion error: ${message}`, {\n kind: ErrorKind.Utf8,\n message,\n });\n }\n\n // ============================================================================\n // Compression Errors\n // ============================================================================\n\n /**\n * Create a compression error.\n *\n * Rust equivalent: `Error::compression(msg)`\n *\n * @param message - Description of the compression error\n */\n static compression(message: string): CryptoError {\n return new CryptoError(`compression error: ${message}`, {\n kind: ErrorKind.Compression,\n message,\n });\n }\n\n // ============================================================================\n // URI Errors\n // ============================================================================\n\n /**\n * Create a URI parsing error.\n *\n * Rust equivalent: `Error::Uri(err)`\n *\n * @param message - Description of the URI error\n */\n static uri(message: string): CryptoError {\n return new CryptoError(`invalid URI: ${message}`, {\n kind: ErrorKind.Uri,\n message,\n });\n }\n\n // ============================================================================\n // SSKR Errors\n // ============================================================================\n\n /**\n * Create an SSKR error.\n *\n * Rust equivalent: `Error::Sskr(err)`\n *\n * @param message - Description of the SSKR error\n */\n static sskr(message: string): CryptoError {\n return new CryptoError(`SSKR error: ${message}`, {\n kind: ErrorKind.Sskr,\n message,\n });\n }\n\n // ============================================================================\n // SSH Errors\n // ============================================================================\n\n /**\n * Create an SSH operation error.\n *\n * Rust equivalent: `Error::ssh(msg)`\n *\n * @param message - Description of the SSH error\n */\n static ssh(message: string): CryptoError {\n return new CryptoError(`SSH operation failed: ${message}`, {\n kind: ErrorKind.Ssh,\n message,\n });\n }\n\n /**\n * Create an SSH agent error.\n *\n * Rust equivalent: `Error::ssh_agent(msg)`\n *\n * @param message - Description of the SSH agent error\n */\n static sshAgent(message: string): CryptoError {\n return new CryptoError(`SSH agent error: ${message}`, {\n kind: ErrorKind.SshAgent,\n message,\n });\n }\n\n /**\n * Create an SSH agent client error.\n *\n * Rust equivalent: `Error::ssh_agent_client(msg)`\n *\n * @param message - Description of the SSH agent client error\n */\n static sshAgentClient(message: string): CryptoError {\n return new CryptoError(`SSH agent client error: ${message}`, {\n kind: ErrorKind.SshAgentClient,\n message,\n });\n }\n\n // ============================================================================\n // Environment Errors\n // ============================================================================\n\n /**\n * Create an environment variable error.\n *\n * Rust equivalent: `Error::Env(err)`\n *\n * @param message - Description of the environment error\n */\n static env(message: string): CryptoError {\n return new CryptoError(`environment variable error: ${message}`, {\n kind: ErrorKind.Env,\n message,\n });\n }\n\n // ============================================================================\n // General Errors\n // ============================================================================\n\n /**\n * Create a general error with a custom message.\n *\n * Rust equivalent: `Error::general(msg)` / `Error::General(msg)`\n *\n * @param message - The error message\n */\n static general(message: string): CryptoError {\n return new CryptoError(message, {\n kind: ErrorKind.General,\n message,\n });\n }\n\n // ============================================================================\n // Error Kind Checking Methods\n // ============================================================================\n\n /**\n * Check if this error is of a specific kind.\n *\n * @param kind - The error kind to check\n */\n isKind(kind: ErrorKind): boolean {\n return this.errorKind === kind;\n }\n\n /**\n * Check if this is an InvalidSize error.\n */\n isInvalidSize(): this is CryptoError & {\n errorData: InvalidSizeData & { kind: ErrorKind.InvalidSize };\n } {\n return this.errorKind === ErrorKind.InvalidSize;\n }\n\n /**\n * Check if this is an InvalidData error.\n */\n isInvalidData(): this is CryptoError & {\n errorData: InvalidDataData & { kind: ErrorKind.InvalidData };\n } {\n return this.errorKind === ErrorKind.InvalidData;\n }\n\n /**\n * Check if this is a DataTooShort error.\n */\n isDataTooShort(): this is CryptoError & {\n errorData: DataTooShortData & { kind: ErrorKind.DataTooShort };\n } {\n return this.errorKind === ErrorKind.DataTooShort;\n }\n\n /**\n * Check if this is a Crypto error.\n */\n isCrypto(): boolean {\n return this.errorKind === ErrorKind.Crypto;\n }\n\n /**\n * Check if this is a Cbor error.\n */\n isCbor(): boolean {\n return this.errorKind === ErrorKind.Cbor;\n }\n\n /**\n * Check if this is an Sskr error.\n */\n isSskr(): boolean {\n return this.errorKind === ErrorKind.Sskr;\n }\n\n /**\n * Check if this is an Ssh error.\n */\n isSsh(): boolean {\n return this.errorKind === ErrorKind.Ssh;\n }\n\n /**\n * Check if this is a Uri error.\n */\n isUri(): boolean {\n return this.errorKind === ErrorKind.Uri;\n }\n\n /**\n * Check if this is a Compression error.\n */\n isCompression(): boolean {\n return this.errorKind === ErrorKind.Compression;\n }\n\n /**\n * Check if this is a PostQuantum error.\n */\n isPostQuantum(): boolean {\n return this.errorKind === ErrorKind.PostQuantum;\n }\n\n /**\n * Check if this is a LevelMismatch error.\n */\n isLevelMismatch(): boolean {\n return this.errorKind === ErrorKind.LevelMismatch;\n }\n\n /**\n * Check if this is an SshAgent error.\n */\n isSshAgent(): boolean {\n return this.errorKind === ErrorKind.SshAgent;\n }\n\n /**\n * Check if this is a Hex error.\n */\n isHex(): boolean {\n return this.errorKind === ErrorKind.Hex;\n }\n\n /**\n * Check if this is a Utf8 error.\n */\n isUtf8(): boolean {\n return this.errorKind === ErrorKind.Utf8;\n }\n\n /**\n * Check if this is an Env error.\n */\n isEnv(): boolean {\n return this.errorKind === ErrorKind.Env;\n }\n\n /**\n * Check if this is an SshAgentClient error.\n */\n isSshAgentClient(): boolean {\n return this.errorKind === ErrorKind.SshAgentClient;\n }\n\n /**\n * Check if this is a General error.\n */\n isGeneral(): boolean {\n return this.errorKind === ErrorKind.General;\n }\n}\n\n/**\n * Result type that can be either a success value or an Error.\n */\nexport type Result<T> = T | Error;\n\n/**\n * Type guard to check if a result is an Error.\n */\nexport function isError(result: unknown): result is Error {\n return result instanceof Error;\n}\n\n/**\n * Type guard to check if a result is a CryptoError.\n */\nexport function isCryptoError(result: unknown): result is CryptoError {\n return result instanceof CryptoError;\n}\n\n/**\n * Type guard to check if an error is a CryptoError of a specific kind.\n */\nexport function isCryptoErrorKind(result: unknown, kind: ErrorKind): result is CryptoError {\n return isCryptoError(result) && result.errorKind === kind;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Utility functions for byte array conversions and comparisons.\n *\n * These functions provide cross-platform support for common byte manipulation\n * operations needed in cryptographic and encoding contexts.\n *\n * @packageDocumentation\n */\n\n/**\n * Convert a Uint8Array to a lowercase hexadecimal string.\n *\n * @param data - The byte array to convert\n * @returns A lowercase hex string representation (2 characters per byte)\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef]);\n * bytesToHex(bytes); // \"deadbeef\"\n * ```\n */\nexport function bytesToHex(data: Uint8Array): string {\n return Array.from(data)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Convert a hexadecimal string to a Uint8Array.\n *\n * @param hex - A hex string (must have even length, case-insensitive)\n * @returns The decoded byte array\n * @throws {Error} If the hex string has odd length or contains invalid characters\n *\n * @example\n * ```typescript\n * hexToBytes(\"deadbeef\"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])\n * hexToBytes(\"DEADBEEF\"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])\n * hexToBytes(\"xyz\"); // throws Error: Invalid hex string\n * ```\n */\nexport function hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) {\n throw new Error(`Hex string must have even length, got ${hex.length}`);\n }\n if (!/^[0-9A-Fa-f]*$/.test(hex)) {\n throw new Error(\"Invalid hex string: contains non-hexadecimal characters\");\n }\n const data = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n data[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n }\n return data;\n}\n\n/**\n * Convert a Uint8Array to a base64-encoded string.\n *\n * This function works in both browser and Node.js environments.\n * Uses btoa which is available in browsers and Node.js 16+.\n *\n * @param data - The byte array to encode\n * @returns A base64-encoded string\n *\n * @example\n * ```typescript\n * const bytes = new Uint8Array([72, 101, 108, 108, 111]); // \"Hello\"\n * toBase64(bytes); // \"SGVsbG8=\"\n * ```\n */\nexport function toBase64(data: Uint8Array): string {\n // Convert bytes to binary string without spread operator to avoid\n // call stack limits for large arrays (spread would fail at ~65k bytes)\n let binary = \"\";\n for (const byte of data) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n}\n\n/**\n * Convert a base64-encoded string to a Uint8Array.\n *\n * This function works in both browser and Node.js environments.\n * Uses atob which is available in browsers and Node.js 16+.\n *\n * @param base64 - A base64-encoded string\n * @returns The decoded byte array\n *\n * @example\n * ```typescript\n * fromBase64(\"SGVsbG8=\"); // Uint8Array([72, 101, 108, 108, 111])\n * ```\n */\nexport function fromBase64(base64: string): Uint8Array {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\n/**\n * Compare two Uint8Arrays for equality using constant-time comparison.\n *\n * This function is designed to be resistant to timing attacks by always\n * comparing all bytes regardless of where a difference is found. The\n * comparison time depends only on the length of the arrays, not on where\n * they differ.\n *\n * **Security Note**: If the arrays have different lengths, this function\n * returns `false` immediately, which does leak length information. For\n * cryptographic uses where length should also be secret, ensure both\n * arrays are the same length before comparison.\n *\n * @param a - First byte array\n * @param b - Second byte array\n * @returns `true` if both arrays have the same length and identical contents\n *\n * @example\n * ```typescript\n * const key1 = new Uint8Array([1, 2, 3, 4]);\n * const key2 = new Uint8Array([1, 2, 3, 4]);\n * const key3 = new Uint8Array([1, 2, 3, 5]);\n *\n * bytesEqual(key1, key2); // true\n * bytesEqual(key1, key3); // false\n * ```\n */\nexport function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a[i] ^ b[i];\n }\n return result === 0;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * SHA-256 cryptographic digest (32 bytes)\n *\n * Ported from bc-components-rust/src/digest.rs\n *\n * A `Digest` represents the cryptographic hash of some data. In this\n * implementation, SHA-256 is used, which produces a 32-byte hash value.\n * Digests are used throughout the crate for data verification and as unique\n * identifiers derived from data.\n *\n * # CBOR Serialization\n *\n * `Digest` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with a specific tag (TAG_DIGEST = 40001).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `Digest` is represented as a\n * binary blob with the type \"digest\".\n *\n * @example\n * ```typescript\n * import { Digest } from '@bcts/components';\n *\n * // Create a digest from a string\n * const data = new TextEncoder().encode(\"hello world\");\n * const digest = Digest.fromImage(data);\n *\n * // Validate that the digest matches the original data\n * console.log(digest.validate(data)); // true\n *\n * // Create a digest from a hex string\n * const hexString = \"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\";\n * const digest2 = Digest.fromHex(hexString);\n *\n * // Retrieve the digest as hex\n * console.log(digest2.hex()); // b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9\n * ```\n */\n\nimport { sha256, SHA256_SIZE } from \"@bcts/crypto\";\nimport {\n type Cbor,\n type Tag,\n type CborTaggedEncodable,\n type CborTaggedDecodable,\n toByteString,\n expectBytes,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { DIGEST as TAG_DIGEST } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"./utils.js\";\nimport type { DigestProvider } from \"./digest-provider.js\";\n\nexport class Digest\n implements DigestProvider, CborTaggedEncodable, CborTaggedDecodable<Digest>, UREncodable\n{\n static readonly DIGEST_SIZE = SHA256_SIZE;\n\n private readonly _data: Uint8Array;\n\n private constructor(data: Uint8Array) {\n if (data.length !== Digest.DIGEST_SIZE) {\n throw CryptoError.invalidSize(Digest.DIGEST_SIZE, data.length);\n }\n this._data = new Uint8Array(data);\n }\n\n /**\n * Get the digest data.\n */\n data(): Uint8Array {\n return this._data;\n }\n\n // ============================================================================\n // Static Factory Methods\n // ============================================================================\n\n /**\n * Create a Digest from a 32-byte array.\n */\n static fromData(data: Uint8Array): Digest {\n return new Digest(new Uint8Array(data));\n }\n\n /**\n * Create a Digest from data, validating the length.\n * Alias for fromData for compatibility with Rust API.\n */\n static fromDataRef(data: Uint8Array): Digest {\n return Digest.fromData(data);\n }\n\n /**\n * Create a Digest from hex string.\n *\n * @throws Error if the hex string is not exactly 64 characters.\n */\n static fromHex(hex: string): Digest {\n return new Digest(hexToBytes(hex));\n }\n\n /**\n * Compute SHA-256 digest of data (called \"image\" in Rust).\n *\n * @param image - The data to hash\n */\n static fromImage(image: Uint8Array): Digest {\n const hashData = sha256(image);\n return new Digest(new Uint8Array(hashData));\n }\n\n /**\n * Compute SHA-256 digest from multiple data parts.\n *\n * The parts are concatenated and then hashed.\n *\n * @param imageParts - Array of byte arrays to concatenate and hash\n */\n static fromImageParts(imageParts: Uint8Array[]): Digest {\n const totalLength = imageParts.reduce((sum, part) => sum + part.length, 0);\n const buf = new Uint8Array(totalLength);\n let offset = 0;\n for (const part of imageParts) {\n buf.set(part, offset);\n offset += part.length;\n }\n return Digest.fromImage(buf);\n }\n\n /**\n * Compute SHA-256 digest from an array of Digests.\n *\n * The digest bytes are concatenated and then hashed.\n *\n * @param digests - Array of Digests to combine\n */\n static fromDigests(digests: Digest[]): Digest {\n const buf = new Uint8Array(digests.length * Digest.DIGEST_SIZE);\n let offset = 0;\n for (const digest of digests) {\n buf.set(digest._data, offset);\n offset += Digest.DIGEST_SIZE;\n }\n return Digest.fromImage(buf);\n }\n\n /**\n * Compute SHA-256 digest of data (legacy alias for fromImage).\n * @deprecated Use fromImage instead\n */\n static hash(data: Uint8Array): Digest {\n return Digest.fromImage(data);\n }\n\n // ============================================================================\n // Instance Methods\n // ============================================================================\n\n /**\n * Get the raw digest bytes as a copy.\n */\n toData(): Uint8Array {\n return new Uint8Array(this._data);\n }\n\n /**\n * Get a reference to the raw digest bytes.\n */\n asBytes(): Uint8Array {\n return this._data;\n }\n\n /**\n * Get hex string representation.\n */\n hex(): string {\n return bytesToHex(this._data);\n }\n\n /**\n * Get hex string representation (alias for hex()).\n */\n toHex(): string {\n return this.hex();\n }\n\n /**\n * Get base64 representation.\n */\n toBase64(): string {\n return toBase64(this._data);\n }\n\n /**\n * Get the first four bytes of the digest as a hexadecimal string.\n * Useful for short descriptions.\n */\n shortDescription(): string {\n return bytesToHex(this._data.slice(0, 4));\n }\n\n /**\n * Validate the digest against the given image.\n *\n * The image is hashed with SHA-256 and compared to this digest.\n * @returns `true` if the digest matches the image.\n */\n validate(image: Uint8Array): boolean {\n return this.equals(Digest.fromImage(image));\n }\n\n /**\n * Compare with another Digest.\n */\n equals(other: Digest): boolean {\n if (this._data.length !== other._data.length) return false;\n for (let i = 0; i < this._data.length; i++) {\n if (this._data[i] !== other._data[i]) return false;\n }\n return true;\n }\n\n /**\n * Compare digests lexicographically.\n */\n compare(other: Digest): number {\n for (let i = 0; i < this._data.length; i++) {\n const a = this._data[i];\n const b = other._data[i];\n if (a < b) return -1;\n if (a > b) return 1;\n }\n return 0;\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n return `Digest(${this.hex()})`;\n }\n\n // ============================================================================\n // DigestProvider Implementation\n // ============================================================================\n\n /**\n * A Digest is its own digest provider - returns itself.\n */\n digest(): Digest {\n return this;\n }\n\n // ============================================================================\n // CBOR Serialization (CborTaggedEncodable)\n // ============================================================================\n\n /**\n * Returns the CBOR tags associated with Digest.\n */\n cborTags(): Tag[] {\n return tagsForValues([TAG_DIGEST.value]);\n }\n\n /**\n * Returns the untagged CBOR encoding (as a byte string).\n */\n untaggedCbor(): Cbor {\n return toByteString(this._data);\n }\n\n /**\n * Returns the tagged CBOR encoding.\n */\n taggedCbor(): Cbor {\n return createTaggedCbor(this);\n }\n\n /**\n * Returns the tagged value in CBOR binary representation.\n */\n taggedCborData(): Uint8Array {\n return this.taggedCbor().toData();\n }\n\n // ============================================================================\n // CBOR Deserialization (CborTaggedDecodable)\n // ============================================================================\n\n /**\n * Creates a Digest by decoding it from untagged CBOR.\n */\n fromUntaggedCbor(cbor: Cbor): Digest {\n const data = expectBytes(cbor);\n return Digest.fromData(data);\n }\n\n /**\n * Creates a Digest by decoding it from tagged CBOR.\n */\n fromTaggedCbor(cbor: Cbor): Digest {\n validateTag(cbor, this.cborTags());\n const content = extractTaggedContent(cbor);\n return this.fromUntaggedCbor(content);\n }\n\n /**\n * Static method to decode from tagged CBOR.\n */\n static fromTaggedCbor(cbor: Cbor): Digest {\n const instance = new Digest(new Uint8Array(Digest.DIGEST_SIZE));\n return instance.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from tagged CBOR binary data.\n */\n static fromTaggedCborData(data: Uint8Array): Digest {\n const cbor = decodeCbor(data);\n return Digest.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from untagged CBOR binary data.\n */\n static fromUntaggedCborData(data: Uint8Array): Digest {\n const cbor = decodeCbor(data);\n const bytes = expectBytes(cbor);\n return Digest.fromData(bytes);\n }\n\n // ============================================================================\n // UR Serialization (UREncodable)\n // ============================================================================\n\n /**\n * Returns the UR representation of the Digest.\n * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n */\n ur(): UR {\n return UR.new(\"digest\", this.untaggedCbor());\n }\n\n /**\n * Returns the UR string representation.\n */\n urString(): string {\n return this.ur().string();\n }\n\n /**\n * Creates a Digest from a UR.\n */\n static fromUR(ur: UR): Digest {\n ur.checkType(\"digest\");\n const instance = new Digest(new Uint8Array(Digest.DIGEST_SIZE));\n return instance.fromUntaggedCbor(ur.cbor());\n }\n\n /**\n * Creates a Digest from a UR string.\n */\n static fromURString(urString: string): Digest {\n const ur = UR.fromURString(urString);\n return Digest.fromUR(ur);\n }\n\n // ============================================================================\n // Static Utility Methods\n // ============================================================================\n\n /**\n * Validate the given data against the digest, if any.\n *\n * Returns `true` if the digest is `undefined` or if the digest matches the\n * image's digest. Returns `false` if the digest does not match.\n */\n static validateOpt(image: Uint8Array, digest: Digest | undefined): boolean {\n if (digest === undefined) {\n return true;\n }\n return digest.validate(image);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAY,kDAAL;;AAEL;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;;;;;;;;;;;;AA4DF,IAAa,cAAb,MAAa,oBAAoB,M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