{"version":3,"file":"index.mjs","names":["TAG_JSON","TAG_DIGEST","cryptoHash","TAG_COMPRESSED","TAG_NONCE","TAG_SALT","TAG_SEED","TAG_SEED_V1","TAG_REFERENCE","TAG_ARID","TAG_UUID","TAG_XID","TAG_URI","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_MLDSA_PUBLIC_KEY","TAG_MLDSA_SIGNATURE","TAG_MLDSA_PRIVATE_KEY","_exhaustive","decodeUtf8","sha256","bytesEqual","PEM_LABEL","PEM_LINE_WIDTH","MAGIC","bytesEqual","decodeUtf8","sha256","bytesEqual","_exhaustive","sha256","TAG_X25519_PUBLIC_KEY","TAG_ENCRYPTED","TAG_SYMMETRIC_KEY","TAG_X25519_PRIVATE_KEY","TAG_MLKEM_CIPHERTEXT","mlkemLevelToScheme","isMlkemScheme","TAG_X25519_PUBLIC_KEY","TAG_MLKEM_CIPHERTEXT","TAG_MLKEM_PUBLIC_KEY","mlkemLevelToScheme","isMlkemScheme","TAG_X25519_PUBLIC_KEY","TAG_MLKEM_PUBLIC_KEY","TAG_MLKEM_PRIVATE_KEY","TAG_X25519_PRIVATE_KEY","TAG_MLKEM_PRIVATE_KEY","TAG_PRIVATE_KEY_BASE","TAG_SIGNATURE","TAG_SSH_TEXT_SIGNATURE","TAG_MLDSA_SIGNATURE","TAG_SIGNING_PUBLIC_KEY","TAG_SSH_TEXT_PUBLIC_KEY","TAG_MLDSA_PUBLIC_KEY","TAG_SIGNING_PRIVATE_KEY","TAG_SSH_TEXT_PRIVATE_KEY","TAG_MLDSA_PRIVATE_KEY","TAG_PUBLIC_KEYS","TAG_PRIVATE_KEYS","createSigningKeypair","createSigningKeypairUsing","candidate","TAG_SEALED_MESSAGE","cryptoHash","cryptoHash","SALT_LEN","TAG_ENCRYPTED_KEY","TAG_SSKR_SHARE","TAG_SSKR_SHARE_V1","sha256"],"sources":["../src/error.ts","../src/private-key-data-provider.ts","../src/encrypter.ts","../src/utils.ts","../src/json.ts","../src/digest.ts","../src/compressed.ts","../src/hkdf-rng.ts","../src/digest-provider.ts","../src/nonce.ts","../src/salt.ts","../src/seed.ts","../src/reference.ts","../src/id/arid.ts","../src/id/uuid.ts","../src/id/xid.ts","../src/id/uri.ts","../src/ed25519/ed25519-public-key.ts","../src/ed25519/ed25519-private-key.ts","../src/sr25519/sr25519-public-key.ts","../src/sr25519/sr25519-private-key.ts","../src/ec-key/ec-uncompressed-public-key.ts","../src/ec-key/ec-public-key.ts","../src/ec-key/schnorr-public-key.ts","../src/ec-key/ec-private-key.ts","../src/mldsa/mldsa-level.ts","../src/mldsa/mldsa-public-key.ts","../src/mldsa/mldsa-signature.ts","../src/mldsa/mldsa-private-key.ts","../src/ssh/internal/ssh-buffer.ts","../src/ssh/internal/ssh-pem.ts","../src/ssh/internal/dsa.ts","../src/ssh/ssh-algorithm.ts","../src/ssh/ssh-public-key.ts","../src/ssh/ssh-signature.ts","../src/ssh/ssh-private-key.ts","../src/x25519/x25519-public-key.ts","../src/symmetric/authentication-tag.ts","../src/symmetric/encrypted-message.ts","../src/symmetric/symmetric-key.ts","../src/x25519/x25519-private-key.ts","../src/mlkem/mlkem-level.ts","../src/encapsulation/encapsulation-scheme.ts","../src/mlkem/mlkem-ciphertext.ts","../src/encapsulation/encapsulation-ciphertext.ts","../src/mlkem/mlkem-public-key.ts","../src/encapsulation/encapsulation-public-key.ts","../src/mlkem/mlkem-private-key.ts","../src/encapsulation/encapsulation-private-key.ts","../src/private-key-base.ts","../src/signing/signature-scheme.ts","../src/signing/signature.ts","../src/signing/signing-public-key.ts","../src/signing/signing-private-key.ts","../src/public-keys.ts","../src/private-keys.ts","../src/keypair.ts","../src/ec-key/ec-key-base.ts","../src/encapsulation/sealed-message.ts","../src/encrypted-key/hash-type.ts","../src/encrypted-key/key-derivation-method.ts","../src/encrypted-key/hkdf-params.ts","../src/encrypted-key/pbkdf2-params.ts","../src/encrypted-key/scrypt-params.ts","../src/encrypted-key/argon2id-params.ts","../src/encrypted-key/ssh-agent-params.ts","../src/encrypted-key/key-derivation-params.ts","../src/encrypted-key/encrypted-key.ts","../src/sskr.ts","../src/ssh/ssh-certificate.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 * A trait for types that can provide unique data for cryptographic key derivation.\n *\n * Ported from bc-components-rust/src/private_key_data_provider.rs\n *\n * Types implementing `PrivateKeyDataProvider` can be used as seed material for\n * cryptographic key derivation. The provided data should be sufficiently\n * random and unpredictable to ensure the security of the derived keys.\n *\n * This trait is particularly useful for:\n * - Deterministic key generation systems\n * - Key recovery mechanisms\n * - Key derivation hierarchies\n * - Hierarchical deterministic wallet implementations\n *\n * # Security Considerations\n *\n * Implementers of this trait should ensure that:\n * - The data they provide has sufficient entropy\n * - The data is properly protected in memory\n * - Any serialization or storage is done securely\n * - Appropriate zeroization occurs when data is no longer needed\n */\n\n/**\n * Interface for types that can provide unique data for cryptographic key derivation.\n *\n * The provided data should be sufficiently random and have enough entropy\n * to serve as the basis for secure cryptographic key derivation.\n */\nexport interface PrivateKeyDataProvider {\n  /**\n   * Returns unique data from which cryptographic keys can be derived.\n   *\n   * The returned data should be sufficiently random and have enough entropy\n   * to serve as the basis for secure cryptographic key derivation.\n   *\n   * @returns A Uint8Array containing the private key data.\n   */\n  privateKeyData(): Uint8Array;\n}\n\n/**\n * Type guard to check if an object implements PrivateKeyDataProvider\n */\nexport function isPrivateKeyDataProvider(obj: unknown): obj is PrivateKeyDataProvider {\n  return (\n    typeof obj === \"object\" &&\n    obj !== null &&\n    \"privateKeyData\" in obj &&\n    typeof (obj as PrivateKeyDataProvider).privateKeyData === \"function\"\n  );\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encrypter and Decrypter interfaces for public key encryption/decryption.\n *\n * Ported from bc-components-rust/src/encrypter.rs\n *\n * The `Encrypter` interface defines an interface for encapsulating a shared secret\n * using a public key. This is a key part of hybrid encryption schemes, where a\n * shared symmetric key is encapsulated with a public key, and the recipient\n * uses their private key to recover the symmetric key.\n *\n * The `Decrypter` interface defines an interface for decapsulating (recovering) a\n * shared secret using a private key. This is the counterpart to the\n * `Encrypter` interface and is used by the recipient of encapsulated messages.\n */\n\nimport type { EncapsulationCiphertext } from \"./encapsulation/encapsulation-ciphertext.js\";\nimport type { EncapsulationPrivateKey } from \"./encapsulation/encapsulation-private-key.js\";\nimport type { EncapsulationPublicKey } from \"./encapsulation/encapsulation-public-key.js\";\nimport type { SymmetricKey } from \"./symmetric/symmetric-key.js\";\n\n/**\n * A trait for types that can encapsulate shared secrets for public key encryption.\n *\n * The `Encrypter` interface defines an interface for encapsulating a shared secret\n * using a public key. This is a key part of hybrid encryption schemes, where a\n * shared symmetric key is encapsulated with a public key, and the recipient\n * uses their private key to recover the symmetric key.\n *\n * Types implementing this interface provide the ability to:\n * 1. Access their encapsulation public key\n * 2. Generate and encapsulate new shared secrets\n *\n * This interface is typically implemented by:\n * - Encapsulation public keys\n * - Higher-level types that contain or can generate encapsulation public keys\n *\n * @example\n * ```typescript\n * import { EncapsulationScheme, createEncapsulationKeypair } from '@bcts/components';\n *\n * // Generate a recipient keypair\n * const [recipientPrivateKey, recipientPublicKey] = createEncapsulationKeypair(EncapsulationScheme.X25519);\n *\n * // Encapsulate a new shared secret\n * const [sharedSecret, ciphertext] = recipientPublicKey.encapsulateNewSharedSecret();\n * ```\n */\nexport interface Encrypter {\n  /**\n   * Returns the encapsulation public key for this encrypter.\n   *\n   * @returns The encapsulation public key that should be used for encapsulation.\n   */\n  encapsulationPublicKey(): EncapsulationPublicKey;\n\n  /**\n   * Encapsulates a new shared secret for the recipient.\n   *\n   * This method generates a new shared secret and encapsulates it using\n   * the encapsulation public key from this encrypter.\n   *\n   * @returns A tuple containing:\n   * - The generated shared secret as a `SymmetricKey`\n   * - The encapsulation ciphertext that can be sent to the recipient\n   */\n  encapsulateNewSharedSecret(): [SymmetricKey, EncapsulationCiphertext];\n}\n\n/**\n * A trait for types that can decapsulate shared secrets for public key decryption.\n *\n * The `Decrypter` interface defines an interface for decapsulating (recovering) a\n * shared secret using a private key. This is the counterpart to the\n * `Encrypter` interface and is used by the recipient of encapsulated messages.\n *\n * Types implementing this interface provide the ability to:\n * 1. Access their encapsulation private key\n * 2. Decapsulate shared secrets from ciphertexts\n *\n * This interface is typically implemented by:\n * - Encapsulation private keys\n * - Higher-level types that contain or can access encapsulation private keys\n *\n * @example\n * ```typescript\n * import { EncapsulationScheme, createEncapsulationKeypair } from '@bcts/components';\n *\n * // Generate a keypair\n * const [privateKey, publicKey] = createEncapsulationKeypair(EncapsulationScheme.X25519);\n *\n * // Encapsulate a new shared secret\n * const [originalSecret, ciphertext] = publicKey.encapsulateNewSharedSecret();\n *\n * // Decapsulate the shared secret\n * const recoveredSecret = privateKey.decapsulateSharedSecret(ciphertext);\n *\n * // The original and recovered secrets should match\n * ```\n */\nexport interface Decrypter {\n  /**\n   * Returns the encapsulation private key for this decrypter.\n   *\n   * @returns The encapsulation private key that should be used for decapsulation.\n   */\n  encapsulationPrivateKey(): EncapsulationPrivateKey;\n\n  /**\n   * Decapsulates a shared secret from a ciphertext.\n   *\n   * This method recovers the shared secret that was encapsulated in the\n   * given ciphertext, using the private key from this decrypter.\n   *\n   * @param ciphertext - The encapsulation ciphertext containing the encapsulated shared secret\n   * @returns The decapsulated `SymmetricKey`\n   * @throws Error if the ciphertext type doesn't match the private key type or if decapsulation fails\n   */\n  decapsulateSharedSecret(ciphertext: EncapsulationCiphertext): SymmetricKey;\n}\n\n/**\n * Type guard to check if an object implements the Encrypter interface.\n */\nexport function isEncrypter(obj: unknown): obj is Encrypter {\n  return (\n    typeof obj === \"object\" &&\n    obj !== null &&\n    \"encapsulationPublicKey\" in obj &&\n    typeof (obj as Encrypter).encapsulationPublicKey === \"function\" &&\n    \"encapsulateNewSharedSecret\" in obj &&\n    typeof (obj as Encrypter).encapsulateNewSharedSecret === \"function\"\n  );\n}\n\n/**\n * Type guard to check if an object implements the Decrypter interface.\n */\nexport function isDecrypter(obj: unknown): obj is Decrypter {\n  return (\n    typeof obj === \"object\" &&\n    obj !== null &&\n    \"encapsulationPrivateKey\" in obj &&\n    typeof (obj as Decrypter).encapsulationPrivateKey === \"function\" &&\n    \"decapsulateSharedSecret\" in obj &&\n    typeof (obj as Decrypter).decapsulateSharedSecret === \"function\"\n  );\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 * A CBOR-tagged container for UTF-8 JSON text.\n *\n * Ported from bc-components-rust/src/json.rs\n *\n * The `JSON` type wraps UTF-8 JSON text as a CBOR byte string with tag 262.\n * This allows JSON data to be embedded within CBOR structures while\n * maintaining type information through the tag.\n *\n * This implementation does not validate that the contained data is well-formed\n * JSON. It simply provides a type-safe wrapper around byte data that is\n * intended to contain JSON text.\n *\n * # CBOR Serialization\n *\n * `JSON` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with tag 262 (`TAG_JSON`).\n *\n * @example\n * ```typescript\n * import { JSON } from '@bcts/components';\n *\n * // Create JSON from a string\n * const json = JSON.fromString('{\"key\": \"value\"}');\n * console.log(json.asStr()); // {\"key\": \"value\"}\n *\n * // Create JSON from bytes\n * const json2 = JSON.fromData(new TextEncoder().encode('[1, 2, 3]'));\n * console.log(json2.len()); // 9\n * ```\n */\n\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 { JSON as TAG_JSON } from \"@bcts/tags\";\nimport { bytesToHex, hexToBytes } from \"./utils.js\";\n\n/**\n * A CBOR-tagged container for UTF-8 JSON text.\n *\n * Wraps UTF-8 JSON text as a CBOR byte string with tag 262.\n * This allows JSON data to be embedded within CBOR structures while\n * maintaining type information through the tag.\n */\nexport class JSON implements CborTaggedEncodable, CborTaggedDecodable<JSON> {\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new JSON instance from byte data.\n   */\n  static fromData(data: Uint8Array): JSON {\n    return new JSON(data);\n  }\n\n  /**\n   * Create a new JSON instance from a string.\n   */\n  static fromString(s: string): JSON {\n    const encoder = new TextEncoder();\n    return new JSON(encoder.encode(s));\n  }\n\n  /**\n   * Create a new JSON instance from a hexadecimal string.\n   */\n  static fromHex(hex: string): JSON {\n    return new JSON(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Return the length of the JSON data in bytes.\n   */\n  len(): number {\n    return this._data.length;\n  }\n\n  /**\n   * Return true if the JSON data is empty.\n   */\n  isEmpty(): boolean {\n    return this._data.length === 0;\n  }\n\n  /**\n   * Return the data as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Return the data as a UTF-8 string slice.\n   *\n   * @throws Error if the data is not valid UTF-8.\n   */\n  asStr(): string {\n    const decoder = new TextDecoder(\"utf-8\", { fatal: true });\n    return decoder.decode(this._data);\n  }\n\n  /**\n   * Return the data as a hexadecimal string.\n   */\n  hex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Return a copy of the underlying data.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Compare with another JSON.\n   */\n  equals(other: JSON): 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   * Get string representation.\n   */\n  toString(): string {\n    return `JSON(${this.asStr()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with JSON.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_JSON.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 JSON by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): JSON {\n    const data = expectBytes(cborValue);\n    return JSON.fromData(data);\n  }\n\n  /**\n   * Creates a JSON by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): JSON {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): JSON {\n    const instance = JSON.fromString(\"\");\n    return instance.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): JSON {\n    const cborValue = decodeCbor(data);\n    return JSON.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): JSON {\n    const cborValue = decodeCbor(data);\n    const instance = JSON.fromString(\"\");\n    return instance.fromUntaggedCbor(cborValue);\n  }\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","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A compressed binary object with integrity verification.\n *\n * Ported from bc-components-rust/src/compressed.rs\n *\n * `Compressed` provides a way to efficiently store and transmit binary data\n * using the DEFLATE compression algorithm. It includes built-in integrity\n * verification through a CRC32 checksum and optional cryptographic digest.\n *\n * The compression is implemented using the raw DEFLATE format as described in\n * [IETF RFC 1951](https://www.ietf.org/rfc/rfc1951.txt).\n *\n * Features:\n * - Automatic compression with configurable compression level\n * - Integrity verification via CRC32 checksum\n * - Optional cryptographic digest for content identification\n * - Smart behavior for small data (stores decompressed if compression would\n *   increase size)\n * - CBOR serialization/deserialization support\n *\n * @example\n * ```typescript\n * import { Compressed } from '@bcts/components';\n *\n * // Compress a string\n * const data = new TextEncoder().encode(\n *   \"This is a longer string that should compress well with repeated patterns.\"\n * );\n * const compressed = Compressed.fromDecompressedData(data);\n *\n * // The compressed size should be smaller than the original\n * console.log(compressed.compressionRatio()); // < 1.0\n *\n * // We can recover the original data\n * const decompressed = compressed.decompress();\n * ```\n */\n\nimport { deflateRaw, inflateRaw } from \"pako\";\nimport { hash as cryptoHash } from \"@bcts/crypto\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborInput,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  expectArray,\n  expectInteger,\n  expectBytes,\n} from \"@bcts/dcbor\";\nimport { COMPRESSED as TAG_COMPRESSED } from \"@bcts/tags\";\nimport { Digest } from \"./digest.js\";\nimport type { DigestProvider } from \"./digest-provider.js\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex } from \"./utils.js\";\n\n/**\n * A compressed binary object with integrity verification.\n *\n * Uses DEFLATE compression with CRC32 checksums for integrity verification.\n * Optionally includes a cryptographic digest for content identification.\n */\nexport class Compressed\n  implements CborTaggedEncodable, CborTaggedDecodable<Compressed>, DigestProvider\n{\n  /** CRC32 checksum of the decompressed data for integrity verification */\n  private readonly _checksum: number;\n  /** Size of the original decompressed data in bytes */\n  private readonly _decompressedSize: number;\n  /** The compressed data (or original data if compression is ineffective) */\n  private readonly _compressedData: Uint8Array;\n  /** Optional cryptographic digest of the content */\n  private readonly _digest: Digest | undefined;\n\n  private constructor(\n    checksum: number,\n    decompressedSize: number,\n    compressedData: Uint8Array,\n    digest?: Digest,\n  ) {\n    if (compressedData.length > decompressedSize) {\n      throw CryptoError.cryptoOperation(\"compressed data is larger than decompressed size\");\n    }\n    this._checksum = checksum;\n    this._decompressedSize = decompressedSize;\n    this._compressedData = new Uint8Array(compressedData);\n    this._digest = digest;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Creates a new `Compressed` object with the specified parameters.\n   *\n   * This is a low-level constructor that allows direct creation of a\n   * `Compressed` object without performing compression. It's primarily\n   * intended for deserialization or when working with pre-compressed data.\n   *\n   * @param checksum - CRC32 checksum of the decompressed data\n   * @param decompressedSize - Size of the original decompressed data in bytes\n   * @param compressedData - The compressed data bytes\n   * @param digest - Optional cryptographic digest of the content\n   * @returns A new `Compressed` object\n   * @throws CryptoError if the compressed data is larger than the decompressed size\n   */\n  static new(\n    checksum: number,\n    decompressedSize: number,\n    compressedData: Uint8Array,\n    digest?: Digest,\n  ): Compressed {\n    return new Compressed(checksum, decompressedSize, compressedData, digest);\n  }\n\n  /**\n   * Creates a new `Compressed` object by compressing the provided data.\n   *\n   * This is the primary method for creating compressed data. It automatically\n   * handles compression using the DEFLATE algorithm with compression level 6.\n   *\n   * If the compressed data would be larger than the original data (which can\n   * happen with small or already compressed inputs), the original data is\n   * stored instead.\n   *\n   * @param decompressedData - The original data to compress\n   * @param digest - Optional cryptographic digest of the content\n   * @returns A new `Compressed` object containing the compressed (or original) data\n   */\n  static fromDecompressedData(decompressedData: Uint8Array, digest?: Digest): Compressed {\n    // Raw DEFLATE (RFC 1951, no zlib header/trailer) at level 6 — matches\n    // Rust `miniz_oxide::deflate::compress_to_vec(data, 6)`.\n    const compressedData = deflateRaw(decompressedData, { level: 6 });\n    const checksum = cryptoHash.crc32(decompressedData);\n    const decompressedSize = decompressedData.length;\n    const compressedSize = compressedData.length;\n\n    // If compression didn't help, store original data\n    if (compressedSize !== 0 && compressedSize < decompressedSize) {\n      return new Compressed(checksum, decompressedSize, compressedData, digest);\n    } else {\n      return new Compressed(checksum, decompressedSize, new Uint8Array(decompressedData), digest);\n    }\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Decompresses and returns the original decompressed data.\n   *\n   * This method performs the reverse of the compression process, restoring\n   * the original data. It also verifies the integrity of the data using the\n   * stored checksum.\n   *\n   * @returns The decompressed data\n   * @throws CryptoError if the compressed data is corrupt or checksum doesn't match\n   */\n  decompress(): Uint8Array {\n    const compressedSize = this._compressedData.length;\n\n    // If data wasn't actually compressed (sizes equal), return as-is\n    if (compressedSize >= this._decompressedSize) {\n      return new Uint8Array(this._compressedData);\n    }\n\n    try {\n      const decompressedData = inflateRaw(this._compressedData);\n\n      // Verify checksum\n      if (cryptoHash.crc32(decompressedData) !== this._checksum) {\n        throw CryptoError.cryptoOperation(\"compressed data checksum mismatch\");\n      }\n\n      return decompressedData;\n    } catch (e) {\n      if (e instanceof CryptoError) throw e;\n      throw CryptoError.cryptoOperation(\"corrupt compressed data\");\n    }\n  }\n\n  /**\n   * Returns the size of the compressed data in bytes.\n   */\n  compressedSize(): number {\n    return this._compressedData.length;\n  }\n\n  /**\n   * Returns the size of the decompressed data in bytes.\n   */\n  decompressedSize(): number {\n    return this._decompressedSize;\n  }\n\n  /**\n   * Returns the CRC32 checksum of the decompressed data.\n   */\n  checksum(): number {\n    return this._checksum;\n  }\n\n  /**\n   * Returns the compression ratio of the data.\n   *\n   * The compression ratio is calculated as (compressed size) / (decompressed size),\n   * so lower values indicate better compression.\n   *\n   * @returns A floating-point value representing the compression ratio.\n   * - Values less than 1.0 indicate effective compression\n   * - Values equal to 1.0 indicate no compression was applied\n   * - Values of NaN can occur if the decompressed size is zero\n   */\n  compressionRatio(): number {\n    return this._compressedData.length / this._decompressedSize;\n  }\n\n  /**\n   * Returns the digest of the compressed data, if available.\n   *\n   * @returns The `Digest` associated with this compressed data, or undefined if none.\n   */\n  digestOpt(): Digest | undefined {\n    return this._digest;\n  }\n\n  /**\n   * Returns whether this compressed data has an associated digest.\n   */\n  hasDigest(): boolean {\n    return this._digest !== undefined;\n  }\n\n  // ============================================================================\n  // DigestProvider implementation\n  // ============================================================================\n\n  /**\n   * Returns the cryptographic digest associated with this compressed data.\n   *\n   * @returns A `Digest`\n   * @throws Error if there is no digest associated with this compressed data\n   */\n  digest(): Digest {\n    if (this._digest === undefined) {\n      throw new Error(\"No digest associated with this compressed data\");\n    }\n    return this._digest;\n  }\n\n  // ============================================================================\n  // Comparison and String representation\n  // ============================================================================\n\n  /**\n   * Compare with another Compressed.\n   */\n  equals(other: Compressed): boolean {\n    if (this._checksum !== other._checksum) return false;\n    if (this._decompressedSize !== other._decompressedSize) return false;\n    if (this._compressedData.length !== other._compressedData.length) return false;\n    for (let i = 0; i < this._compressedData.length; i++) {\n      if (this._compressedData[i] !== other._compressedData[i]) return false;\n    }\n    // Don't compare digests for equality\n    return true;\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    const checksumHex = bytesToHex(\n      new Uint8Array([\n        (this._checksum >>> 24) & 0xff,\n        (this._checksum >>> 16) & 0xff,\n        (this._checksum >>> 8) & 0xff,\n        this._checksum & 0xff,\n      ]),\n    );\n    const digestStr = this._digest?.shortDescription() ?? \"None\";\n    return `Compressed(checksum: ${checksumHex}, size: ${this.compressedSize()}/${this._decompressedSize}, ratio: ${this.compressionRatio().toFixed(2)}, digest: ${digestStr})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with Compressed.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_COMPRESSED.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding (as an array).\n   *\n   * Format:\n   * ```\n   * [\n   *   checksum: uint,\n   *   decompressed_size: uint,\n   *   compressed_data: bytes,\n   *   digest?: Digest  // Optional\n   * ]\n   * ```\n   */\n  untaggedCbor(): Cbor {\n    const elements: CborInput[] = [\n      this._checksum >>> 0, // Ensure unsigned 32-bit\n      this._decompressedSize,\n      toByteString(this._compressedData),\n    ];\n    if (this._digest !== undefined) {\n      elements.push(this._digest.taggedCbor());\n    }\n    return cbor(elements);\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 Compressed by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): Compressed {\n    const elements = expectArray(cborValue);\n    if (elements.length < 3 || elements.length > 4) {\n      throw CryptoError.invalidData(\"invalid number of elements in compressed\");\n    }\n\n    const checksum = expectInteger(elements[0]);\n    const decompressedSize = expectInteger(elements[1]);\n    const compressedData = expectBytes(elements[2]);\n\n    let digest: Digest | undefined;\n    if (elements.length === 4) {\n      digest = Digest.fromTaggedCbor(elements[3]);\n    }\n\n    return Compressed.new(Number(checksum), Number(decompressedSize), compressedData, digest);\n  }\n\n  /**\n   * Creates a Compressed by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): Compressed {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): Compressed {\n    const instance = Compressed.fromDecompressedData(new Uint8Array(0));\n    return instance.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): Compressed {\n    const cborValue = decodeCbor(data);\n    return Compressed.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): Compressed {\n    const cborValue = decodeCbor(data);\n    const instance = Compressed.fromDecompressedData(new Uint8Array(0));\n    return instance.fromUntaggedCbor(cborValue);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A deterministic random number generator based on HKDF-HMAC-SHA256.\n *\n * Ported from bc-components-rust/src/hkdf_rng.rs\n *\n * `HKDFRng` uses the HMAC-based Key Derivation Function (HKDF) to generate\n * deterministic random numbers from a combination of key material and salt. It\n * serves as a key-stretching mechanism that can produce an arbitrary amount of\n * random-looking bytes from a single seed.\n *\n * Since it produces deterministic output based on the same inputs, it's useful\n * for situations where repeatable randomness is required, such as in testing\n * or when deterministically deriving keys from a master seed.\n *\n * Security considerations:\n * - The security of the generator depends on the entropy and secrecy of the\n *   key material\n * - The same key material and salt will always produce the same sequence\n * - Use a secure random seed for cryptographic applications\n * - Never reuse the same HKDFRng instance for different purposes\n *\n * The implementation automatically handles buffer management, fetching new\n * data using HKDF as needed with an incrementing counter to ensure unique\n * output for each request.\n *\n * @example\n * ```typescript\n * import { HKDFRng } from '@bcts/components';\n *\n * // Create an HKDF-based RNG\n * const rng = HKDFRng.new(new TextEncoder().encode(\"my secure seed\"), \"wallet-derivation\");\n *\n * // Generate two u32 values\n * const random1 = rng.nextU32();\n * const random2 = rng.nextU32();\n *\n * // The same seed and salt will always produce the same sequence\n * const rng2 = HKDFRng.new(new TextEncoder().encode(\"my secure seed\"), \"wallet-derivation\");\n * console.log(random1 === rng2.nextU32()); // true\n * console.log(random2 === rng2.nextU32()); // true\n * ```\n */\n\nimport { hkdfHmacSha256 } from \"@bcts/crypto\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\n\nconst DEFAULT_PAGE_LENGTH = 32;\n\n/**\n * A deterministic random number generator based on HKDF-HMAC-SHA256.\n *\n * Implements the RandomNumberGenerator interface from @bcts/rand.\n */\nexport class HKDFRng implements RandomNumberGenerator {\n  /** Internal buffer of generated bytes */\n  private _buffer: Uint8Array;\n  /** Current position in the buffer */\n  private _position: number;\n  /** Source key material (seed) */\n  private readonly _keyMaterial: Uint8Array;\n  /** Salt value to combine with the key material */\n  private readonly _salt: string;\n  /** Length of each \"page\" of generated data */\n  private readonly _pageLength: number;\n  /** Current page index */\n  private _pageIndex: number;\n\n  private constructor(keyMaterial: Uint8Array, salt: string, pageLength: number) {\n    this._buffer = new Uint8Array(0);\n    this._position = 0;\n    this._keyMaterial = new Uint8Array(keyMaterial);\n    this._salt = salt;\n    this._pageLength = pageLength;\n    this._pageIndex = 0;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Creates a new `HKDFRng` with a custom page length.\n   *\n   * @param keyMaterial - The seed material to derive random numbers from\n   * @param salt - A salt value to mix with the key material\n   * @param pageLength - The number of bytes to generate in each HKDF call\n   * @returns A new `HKDFRng` instance configured with the specified parameters\n   */\n  static newWithPageLength(keyMaterial: Uint8Array, salt: string, pageLength: number): HKDFRng {\n    return new HKDFRng(keyMaterial, salt, pageLength);\n  }\n\n  /**\n   * Creates a new `HKDFRng` with the default page length of 32 bytes.\n   *\n   * @param keyMaterial - The seed material to derive random numbers from\n   * @param salt - A salt value to mix with the key material\n   * @returns A new `HKDFRng` instance configured with the specified key material and salt\n   */\n  static new(keyMaterial: Uint8Array, salt: string): HKDFRng {\n    return HKDFRng.newWithPageLength(keyMaterial, salt, DEFAULT_PAGE_LENGTH);\n  }\n\n  // ============================================================================\n  // Private Methods\n  // ============================================================================\n\n  /**\n   * Refills the internal buffer with new deterministic random bytes.\n   *\n   * This method is called automatically when the internal buffer is exhausted.\n   * It uses HKDF-HMAC-SHA256 to generate a new page of random bytes using the\n   * key material, salt, and current page index.\n   */\n  private fillBuffer(): void {\n    const saltString = `${this._salt}-${this._pageIndex}`;\n    const encoder = new TextEncoder();\n    this._buffer = hkdfHmacSha256(this._keyMaterial, encoder.encode(saltString), this._pageLength);\n    this._position = 0;\n    this._pageIndex += 1;\n  }\n\n  /**\n   * Generates the specified number of deterministic random bytes.\n   *\n   * @param length - The number of bytes to generate\n   * @returns A Uint8Array containing the requested number of deterministic random bytes\n   */\n  private nextBytes(length: number): Uint8Array {\n    const result: number[] = [];\n    while (result.length < length) {\n      if (this._position >= this._buffer.length) {\n        this.fillBuffer();\n      }\n      const remaining = length - result.length;\n      const available = this._buffer.length - this._position;\n      const take = Math.min(remaining, available);\n      for (let i = 0; i < take; i++) {\n        result.push(this._buffer[this._position + i]);\n      }\n      this._position += take;\n    }\n    return new Uint8Array(result);\n  }\n\n  // ============================================================================\n  // RandomNumberGenerator Implementation\n  // ============================================================================\n\n  /**\n   * Generates deterministic random bytes.\n   *\n   * @param length - The number of bytes to generate\n   * @returns A Uint8Array of random bytes\n   */\n  randomData(length: number): Uint8Array {\n    return this.nextBytes(length);\n  }\n\n  /**\n   * Fills the provided buffer with deterministic random bytes.\n   *\n   * @param dest - The buffer to fill with random bytes\n   */\n  fillBytes(dest: Uint8Array): void {\n    const bytes = this.nextBytes(dest.length);\n    dest.set(bytes);\n  }\n\n  // ============================================================================\n  // Additional Methods (matching Rust RngCore interface)\n  // ============================================================================\n\n  /**\n   * Generates a random `u32` value.\n   *\n   * @returns A deterministic random 32-bit unsigned integer\n   */\n  nextU32(): number {\n    const bytes = this.nextBytes(4);\n    // Little-endian byte order. The `>>> 0` coerces JS's signed 32-bit\n    // bitwise OR result back into an unsigned u32, matching Rust.\n    return (bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24)) >>> 0;\n  }\n\n  /**\n   * Generates a random `u64` value.\n   *\n   * Note: JavaScript numbers can only safely represent integers up to 2^53 - 1,\n   * so this returns a BigInt for full 64-bit precision.\n   *\n   * @returns A deterministic random 64-bit unsigned integer as BigInt\n   */\n  nextU64(): bigint {\n    const bytes = this.nextBytes(8);\n    // Little-endian byte order\n    let result = BigInt(0);\n    for (let i = 7; i >= 0; i--) {\n      result = (result << BigInt(8)) | BigInt(bytes[i]);\n    }\n    return result;\n  }\n\n  /**\n   * Attempts to fill the provided buffer with random bytes.\n   * This implementation never fails.\n   *\n   * @param dest - The buffer to fill with random bytes\n   */\n  tryFillBytes(dest: Uint8Array): void {\n    this.fillBytes(dest);\n  }\n\n  /**\n   * Fills the provided buffer with deterministic random bytes.\n   * Alias for fillBytes for interface compatibility.\n   *\n   * @param data - The buffer to fill with random bytes\n   */\n  fillRandomData(data: Uint8Array): void {\n    this.fillBytes(data);\n  }\n\n  // ============================================================================\n  // Accessors (for testing)\n  // ============================================================================\n\n  /**\n   * Returns the key material (for testing purposes).\n   */\n  getKeyMaterial(): Uint8Array {\n    return new Uint8Array(this._keyMaterial);\n  }\n\n  /**\n   * Returns the salt (for testing purposes).\n   */\n  getSalt(): string {\n    return this._salt;\n  }\n\n  /**\n   * Returns the page length (for testing purposes).\n   */\n  getPageLength(): number {\n    return this._pageLength;\n  }\n\n  /**\n   * Returns the current page index (for testing purposes).\n   */\n  getPageIndex(): number {\n    return this._pageIndex;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * DigestProvider interface for types that can provide a cryptographic digest.\n *\n * Ported from bc-components-rust/src/digest_provider.rs\n *\n * A type that can provide a single unique digest that characterizes its contents.\n * This trait is used to define a common interface for objects that can produce\n * a cryptographic digest (hash) of their content.\n *\n * @example\n * ```typescript\n * import { DigestProvider, Digest } from '@bcts/components';\n *\n * class Document implements DigestProvider {\n *   private content: Uint8Array;\n *   private cachedDigest?: Digest;\n *\n *   constructor(content: Uint8Array) {\n *     this.content = content;\n *   }\n *\n *   digest(): Digest {\n *     if (!this.cachedDigest) {\n *       this.cachedDigest = Digest.fromImage(this.content);\n *     }\n *     return this.cachedDigest;\n *   }\n * }\n * ```\n */\nimport { Digest } from \"./digest.js\";\n\n/**\n * A type that can provide a single unique digest that characterizes its contents.\n *\n * Use Cases:\n * - Data integrity verification\n * - Unique identifier for an object based on its content\n * - Content-addressable storage implementation\n * - Comparing objects by their content rather than identity\n */\nexport interface DigestProvider {\n  /**\n   * Returns a digest that uniquely characterizes the content of the\n   * implementing type.\n   */\n  digest(): Digest;\n}\n\n/**\n * Helper function to get a digest from a byte array.\n * This provides DigestProvider-like functionality for raw bytes.\n *\n * @param data - The byte array to hash\n * @returns A Promise resolving to a Digest of the data\n */\nexport function digestFromBytes(data: Uint8Array): Promise<Digest> {\n  return Promise.resolve(Digest.fromImage(data));\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A random nonce (\"number used once\").\n *\n * Ported from bc-components-rust/src/nonce.rs\n *\n * A `Nonce` is a cryptographic primitive consisting of a random or\n * pseudo-random number that is used only once in a cryptographic\n * communication. Nonces are often used in authentication protocols, encryption\n * algorithms, and digital signatures to prevent replay attacks and ensure\n * the uniqueness of encrypted messages.\n *\n * In this implementation, a `Nonce` is a 12-byte random value. The size is\n * chosen to be sufficiently large to prevent collisions while remaining\n * efficient for storage and transmission.\n *\n * # CBOR Serialization\n *\n * `Nonce` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with a specific tag (TAG_NONCE = 40014).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `Nonce` is represented as a\n * binary blob with the type \"nonce\".\n *\n * # Common Uses\n *\n * - In authenticated encryption schemes like AES-GCM or ChaCha20-Poly1305\n * - For initializing counters in counter-mode block ciphers\n * - In challenge-response authentication protocols\n * - To prevent replay attacks in secure communications\n *\n * @example\n * ```typescript\n * import { Nonce } from '@bcts/components';\n *\n * // Generate a new random nonce\n * const nonce = Nonce.new();\n *\n * // Create a nonce from a byte array\n * const data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);\n * const nonce2 = Nonce.fromData(data);\n *\n * // Access the nonce data\n * const nonceData = nonce2.data();\n * ```\n */\n\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport { SYMMETRIC_NONCE_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 { NONCE as TAG_NONCE } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"./utils.js\";\n\nexport class Nonce implements CborTaggedEncodable, CborTaggedDecodable<Nonce>, UREncodable {\n  static readonly NONCE_SIZE = SYMMETRIC_NONCE_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== Nonce.NONCE_SIZE) {\n      throw CryptoError.invalidSize(Nonce.NONCE_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new random nonce.\n   */\n  static new(): Nonce {\n    const rng = new SecureRandomNumberGenerator();\n    return new Nonce(rng.randomData(Nonce.NONCE_SIZE));\n  }\n\n  /**\n   * Create a new random nonce (alias for compatibility).\n   */\n  static random(): Nonce {\n    return Nonce.new();\n  }\n\n  /**\n   * Restores a nonce from data.\n   */\n  static fromData(data: Uint8Array): Nonce {\n    return new Nonce(new Uint8Array(data));\n  }\n\n  /**\n   * Restores a nonce from data (validates length).\n   */\n  static fromDataRef(data: Uint8Array): Nonce {\n    if (data.length !== Nonce.NONCE_SIZE) {\n      throw CryptoError.invalidSize(Nonce.NONCE_SIZE, data.length);\n    }\n    return Nonce.fromData(data);\n  }\n\n  /**\n   * Create a Nonce from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): Nonce {\n    return Nonce.fromData(data);\n  }\n\n  /**\n   * Create a new nonce from the given hexadecimal string.\n   *\n   * @throws Error if the string is not exactly 24 hexadecimal digits.\n   */\n  static fromHex(hex: string): Nonce {\n    return new Nonce(hexToBytes(hex));\n  }\n\n  /**\n   * Generate a random nonce using provided RNG.\n   */\n  static randomUsing(rng: SecureRandomNumberGenerator): Nonce {\n    return new Nonce(rng.randomData(Nonce.NONCE_SIZE));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get the data of the nonce.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the nonce as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw nonce bytes as a copy.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * The data as a hexadecimal string.\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   * Compare with another Nonce.\n   */\n  equals(other: Nonce): 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   * Get string representation.\n   */\n  toString(): string {\n    return `Nonce(${this.hex()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with Nonce.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_NONCE.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 Nonce by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): Nonce {\n    const data = expectBytes(cbor);\n    return Nonce.fromDataRef(data);\n  }\n\n  /**\n   * Creates a Nonce by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): Nonce {\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): Nonce {\n    const instance = new Nonce(new Uint8Array(Nonce.NONCE_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): Nonce {\n    const cbor = decodeCbor(data);\n    return Nonce.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): Nonce {\n    const cbor = decodeCbor(data);\n    const bytes = expectBytes(cbor);\n    return Nonce.fromDataRef(bytes);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the Nonce.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"nonce\", 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 Nonce from a UR.\n   */\n  static fromUR(ur: UR): Nonce {\n    ur.checkType(\"nonce\");\n    const instance = new Nonce(new Uint8Array(Nonce.NONCE_SIZE));\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a Nonce from a UR string.\n   */\n  static fromURString(urString: string): Nonce {\n    const ur = UR.fromURString(urString);\n    return Nonce.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Random salt used to decorrelate other information.\n *\n * Ported from bc-components-rust/src/salt.rs\n *\n * A `Salt` is a cryptographic primitive consisting of random data that is used\n * to modify the output of a cryptographic function. Salts are primarily used\n * in password hashing to defend against dictionary attacks, rainbow table\n * attacks, and pre-computation attacks. They are also used in other\n * cryptographic contexts to ensure uniqueness and prevent correlation between\n * different parts of a cryptosystem.\n *\n * Unlike a `Nonce` which has a fixed size, a `Salt` in this implementation can\n * have a variable length (minimum 8 bytes). Different salt creation methods\n * are provided to generate salts of appropriate sizes for different use cases.\n *\n * # Minimum Size Requirement\n *\n * For security reasons, salts must be at least 8 bytes long. Attempting to\n * create a salt with fewer than 8 bytes will result in an error.\n *\n * # CBOR Serialization\n *\n * `Salt` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with a specific tag (TAG_SALT = 40018).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `Salt` is represented as a\n * binary blob with the type \"salt\".\n *\n * # Common Uses\n *\n * - Password hashing and key derivation functions\n * - Preventing correlation in cryptographic protocols\n * - Randomizing data before encryption to prevent pattern recognition\n * - Adding entropy to improve security in various cryptographic functions\n *\n * @example\n * ```typescript\n * import { Salt } from '@bcts/components';\n *\n * // Generate a salt with 16 bytes\n * const salt = Salt.newWithLen(16);\n * console.log(salt.len()); // 16\n *\n * // Generate a salt proportional to 100 bytes of data\n * const salt2 = Salt.newForSize(100);\n *\n * // Generate a salt with length between 16 and 32 bytes\n * const salt3 = Salt.newInRange(16, 32);\n * ```\n */\n\nimport {\n  SecureRandomNumberGenerator,\n  type RandomNumberGenerator,\n  rngNextInClosedRangeI32,\n} from \"@bcts/rand\";\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 { SALT as TAG_SALT } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"./utils.js\";\n\nconst MIN_SALT_SIZE = 8;\n\nexport class Salt implements CborTaggedEncodable, CborTaggedDecodable<Salt>, UREncodable {\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new salt from data.\n   * Note: Does not validate minimum size to allow for CBOR deserialization.\n   */\n  static fromData(data: Uint8Array): Salt {\n    return new Salt(new Uint8Array(data));\n  }\n\n  /**\n   * Create a Salt from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): Salt {\n    return Salt.fromData(data);\n  }\n\n  /**\n   * Create a new salt from the given hexadecimal string.\n   */\n  static fromHex(hex: string): Salt {\n    return Salt.fromData(hexToBytes(hex));\n  }\n\n  /**\n   * Create a specific number of bytes of salt.\n   *\n   * @throws Error if the number of bytes is less than 8.\n   */\n  static newWithLen(count: number): Salt {\n    const rng = new SecureRandomNumberGenerator();\n    return Salt.newWithLenUsing(count, rng);\n  }\n\n  /**\n   * Create a specific number of bytes of salt using provided RNG.\n   *\n   * @throws Error if the number of bytes is less than 8.\n   */\n  static newWithLenUsing(count: number, rng: RandomNumberGenerator): Salt {\n    if (count < MIN_SALT_SIZE) {\n      throw CryptoError.dataTooShort(\"salt\", MIN_SALT_SIZE, count);\n    }\n    return new Salt(rng.randomData(count));\n  }\n\n  /**\n   * Create a number of bytes of salt chosen randomly from the given range.\n   *\n   * @throws Error if the minimum number of bytes is less than 8.\n   */\n  static newInRange(minSize: number, maxSize: number): Salt {\n    if (minSize < MIN_SALT_SIZE) {\n      throw CryptoError.dataTooShort(\"salt\", MIN_SALT_SIZE, minSize);\n    }\n    const rng = new SecureRandomNumberGenerator();\n    return Salt.newInRangeUsing(minSize, maxSize, rng);\n  }\n\n  /**\n   * Create a number of bytes of salt chosen randomly from the given range using provided RNG.\n   *\n   * @throws Error if the minimum number of bytes is less than 8.\n   */\n  static newInRangeUsing(minSize: number, maxSize: number, rng: RandomNumberGenerator): Salt {\n    if (minSize < MIN_SALT_SIZE) {\n      throw CryptoError.dataTooShort(\"salt\", MIN_SALT_SIZE, minSize);\n    }\n    const count = rngNextInClosedRangeI32(rng, minSize, maxSize);\n    return Salt.newWithLenUsing(count, rng);\n  }\n\n  /**\n   * Create a number of bytes of salt generally proportionate to the size of\n   * the object being salted.\n   */\n  static newForSize(size: number): Salt {\n    const rng = new SecureRandomNumberGenerator();\n    return Salt.newForSizeUsing(size, rng);\n  }\n\n  /**\n   * Create a number of bytes of salt generally proportionate to the size of\n   * the object being salted using provided RNG.\n   */\n  static newForSizeUsing(size: number, rng: RandomNumberGenerator): Salt {\n    const count = size;\n    const minSize = Math.max(MIN_SALT_SIZE, Math.ceil(count * 0.05));\n    const maxSize = Math.max(minSize + 8, Math.ceil(count * 0.25));\n    return Salt.newInRangeUsing(minSize, maxSize, rng);\n  }\n\n  /**\n   * Generate a random salt with specified size (legacy alias for newWithLen).\n   */\n  static random(size = 16): Salt {\n    return Salt.newWithLen(size);\n  }\n\n  /**\n   * Generate a random salt with specified size using provided RNG (legacy alias).\n   */\n  static randomUsing(rng: RandomNumberGenerator, size = 16): Salt {\n    return Salt.newWithLenUsing(size, rng);\n  }\n\n  /**\n   * Generate a proportionally-sized salt (legacy alias for newForSize).\n   */\n  static proportional(dataSize: number): Salt {\n    return Salt.newForSize(dataSize);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Return the length of the salt.\n   */\n  len(): number {\n    return this._data.length;\n  }\n\n  /**\n   * Return the length of the salt (alias for len).\n   */\n  size(): number {\n    return this.len();\n  }\n\n  /**\n   * Return true if the salt is empty (this is not recommended).\n   */\n  isEmpty(): boolean {\n    return this._data.length === 0;\n  }\n\n  /**\n   * Return the data of the salt.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw salt bytes as a copy.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * The data as a hexadecimal string.\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   * Compare with another Salt.\n   */\n  equals(other: Salt): 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   * Get string representation showing the salt's length.\n   */\n  toString(): string {\n    return `Salt(${this.len()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with Salt.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SALT.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 Salt by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): Salt {\n    const data = expectBytes(cbor);\n    return Salt.fromData(data);\n  }\n\n  /**\n   * Creates a Salt by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): Salt {\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): Salt {\n    const instance = new Salt(new Uint8Array(0));\n    return instance.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): Salt {\n    const cbor = decodeCbor(data);\n    return Salt.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): Salt {\n    const cbor = decodeCbor(data);\n    const bytes = expectBytes(cbor);\n    return Salt.fromData(bytes);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the Salt.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"salt\", 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 Salt from a UR.\n   */\n  static fromUR(ur: UR): Salt {\n    ur.checkType(\"salt\");\n    const instance = new Salt(new Uint8Array(0));\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a Salt from a UR string.\n   */\n  static fromURString(urString: string): Salt {\n    const ur = UR.fromURString(urString);\n    return Salt.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Cryptographic seed with optional metadata (minimum 16 bytes)\n * Ported from bc-components-rust/src/seed.rs\n *\n * A `Seed` is a source of entropy used to generate cryptographic keys in a\n * deterministic manner. Unlike randomly generated keys, seed-derived keys can\n * be recreated if you have the original seed, making them useful for backup\n * and recovery scenarios.\n *\n * This implementation of `Seed` includes the random seed data as well as\n * optional metadata:\n * - A name (for identifying the seed)\n * - A note (for storing additional information)\n * - A creation date\n *\n * The minimum seed length is 16 bytes to ensure sufficient security and\n * entropy.\n *\n * # CBOR Serialization\n *\n * `Seed` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with specific tags. The tags used\n * are `TAG_SEED` (40300) and the older `TAG_SEED_V1` (300) for backward compatibility.\n *\n * When serialized to CBOR, a `Seed` is represented as a map with the following\n * keys:\n * - 1: The seed data (required)\n * - 2: The creation date (optional)\n * - 3: The name (optional, omitted if empty)\n * - 4: The note (optional, omitted if empty)\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `Seed` is represented with the\n * type \"seed\".\n */\n\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  CborMap,\n  CborDate,\n  toByteString,\n  expectMap,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SEED as TAG_SEED, SEED_V1 as TAG_SEED_V1 } 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 { PrivateKeyDataProvider } from \"./private-key-data-provider.js\";\n\nexport interface SeedMetadata {\n  name?: string;\n  note?: string;\n  createdAt?: Date;\n}\n\nexport class Seed\n  implements CborTaggedEncodable, CborTaggedDecodable<Seed>, UREncodable, PrivateKeyDataProvider\n{\n  /**\n   * Minimum seed length in bytes (matches Rust MIN_SEED_LENGTH).\n   */\n  static readonly MIN_SEED_LENGTH = 16;\n\n  // Defensive copy: internal data is never exposed directly to prevent external mutation\n  private readonly _data: Uint8Array;\n  private _name: string;\n  private _note: string;\n  private _creationDate: Date | undefined;\n\n  private constructor(data: Uint8Array, name?: string, note?: string, creationDate?: Date) {\n    if (data.length < Seed.MIN_SEED_LENGTH) {\n      throw CryptoError.dataTooShort(\"seed\", Seed.MIN_SEED_LENGTH, data.length);\n    }\n    // Defensive copy on construction to ensure immutability of internal state\n    this._data = new Uint8Array(data);\n    this._name = name ?? \"\";\n    this._note = note ?? \"\";\n    this._creationDate = creationDate;\n  }\n\n  // ============================================================================\n  // Static Factory Methods (Rust API Parity)\n  // ============================================================================\n\n  /**\n   * Create a new random seed with default length (16 bytes).\n   *\n   * Rust equivalent: `Seed::new()`\n   */\n  static new(): Seed {\n    return Seed.newWithLen(Seed.MIN_SEED_LENGTH);\n  }\n\n  /**\n   * Create a new random seed with a specified length.\n   *\n   * Rust equivalent: `Seed::new_with_len(count)`\n   *\n   * @param count - Number of bytes (must be >= 16)\n   * @throws CryptoError if count < 16\n   */\n  static newWithLen(count: number): Seed {\n    const rng = new SecureRandomNumberGenerator();\n    return Seed.newWithLenUsing(count, rng);\n  }\n\n  /**\n   * Create a new random seed with a specified length using provided RNG.\n   *\n   * Rust equivalent: `Seed::new_with_len_using(count, rng)`\n   *\n   * @param count - Number of bytes (must be >= 16)\n   * @param rng - Random number generator\n   * @throws CryptoError if count < 16\n   */\n  static newWithLenUsing(count: number, rng: { randomData: (size: number) => Uint8Array }): Seed {\n    const data = rng.randomData(count);\n    return Seed.newOpt(data, undefined, undefined, undefined);\n  }\n\n  /**\n   * Create a new seed from data and optional metadata.\n   *\n   * Rust equivalent: `Seed::new_opt(data, name, note, creation_date)`\n   *\n   * @param data - Seed bytes (must be >= 16 bytes)\n   * @param name - Optional name for the seed\n   * @param note - Optional note for the seed\n   * @param creationDate - Optional creation date\n   * @throws CryptoError if data < 16 bytes\n   */\n  static newOpt(\n    data: Uint8Array,\n    name: string | undefined,\n    note: string | undefined,\n    creationDate: Date | undefined,\n  ): Seed {\n    return new Seed(data, name, note, creationDate);\n  }\n\n  // ============================================================================\n  // Static Factory Methods (TypeScript Convenience)\n  // ============================================================================\n\n  /**\n   * Create a Seed from raw bytes with optional metadata.\n   *\n   * Note: The input data is copied to prevent external mutation of the seed's internal state.\n   *\n   * @param data - Seed bytes (must be >= 16 bytes)\n   * @param metadata - Optional metadata object\n   */\n  static from(data: Uint8Array, metadata?: SeedMetadata): Seed {\n    return new Seed(new Uint8Array(data), metadata?.name, metadata?.note, metadata?.createdAt);\n  }\n\n  /**\n   * Create a Seed from hex string with optional metadata.\n   *\n   * @param hex - Hex string representing seed bytes\n   * @param metadata - Optional metadata object\n   */\n  static fromHex(hex: string, metadata?: SeedMetadata): Seed {\n    return Seed.from(hexToBytes(hex), metadata);\n  }\n\n  /**\n   * Generate a random seed with specified size (default 32 bytes).\n   *\n   * Convenience method that wraps `newWithLen()`.\n   *\n   * @param size - Number of bytes (must be >= 16, default 32)\n   * @param metadata - Optional metadata object\n   */\n  static random(size = 32, metadata?: SeedMetadata): Seed {\n    const seed = Seed.newWithLen(size);\n    if (metadata?.name !== undefined) seed.setName(metadata.name);\n    if (metadata?.note !== undefined) seed.setNote(metadata.note);\n    if (metadata?.createdAt !== undefined) seed.setCreationDate(metadata.createdAt);\n    return seed;\n  }\n\n  /**\n   * Generate a random seed using provided RNG.\n   *\n   * Convenience method that wraps `newWithLenUsing()`.\n   *\n   * @param rng - Random number generator\n   * @param size - Number of bytes (must be >= 16, default 32)\n   * @param metadata - Optional metadata object\n   */\n  static randomUsing(\n    rng: { randomData: (size: number) => Uint8Array },\n    size = 32,\n    metadata?: SeedMetadata,\n  ): Seed {\n    const seed = Seed.newWithLenUsing(size, rng);\n    if (metadata?.name !== undefined) seed.setName(metadata.name);\n    if (metadata?.note !== undefined) seed.setNote(metadata.note);\n    if (metadata?.createdAt !== undefined) seed.setCreationDate(metadata.createdAt);\n    return seed;\n  }\n\n  // ============================================================================\n  // Instance Methods - Data Access (Rust API Parity)\n  // ============================================================================\n\n  /**\n   * Return the data of the seed as a reference to the internal bytes.\n   *\n   * Rust equivalent: `seed.as_bytes()`\n   *\n   * Note: Returns a reference to internal data. For a copy, use `toData()`.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw seed bytes (copy).\n   *\n   * Note: Returns a copy to prevent external mutation of the seed's internal state.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Get hex string representation.\n   */\n  toHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Get base64 representation.\n   */\n  toBase64(): string {\n    return toBase64(this._data);\n  }\n\n  /**\n   * Get seed size in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  // ============================================================================\n  // Instance Methods - Metadata Access (Rust API Parity)\n  // ============================================================================\n\n  /**\n   * Return the name of the seed.\n   *\n   * Rust equivalent: `seed.name()` - returns empty string if not set.\n   */\n  name(): string {\n    return this._name;\n  }\n\n  /**\n   * Set the name of the seed.\n   *\n   * Rust equivalent: `seed.set_name(name)`\n   */\n  setName(name: string): void {\n    this._name = name;\n  }\n\n  /**\n   * Return the note of the seed.\n   *\n   * Rust equivalent: `seed.note()` - returns empty string if not set.\n   */\n  note(): string {\n    return this._note;\n  }\n\n  /**\n   * Set the note of the seed.\n   *\n   * Rust equivalent: `seed.set_note(note)`\n   */\n  setNote(note: string): void {\n    this._note = note;\n  }\n\n  /**\n   * Return the creation date of the seed.\n   *\n   * Rust equivalent: `seed.creation_date()`\n   */\n  creationDate(): Date | undefined {\n    return this._creationDate;\n  }\n\n  /**\n   * Set the creation date of the seed.\n   *\n   * Rust equivalent: `seed.set_creation_date(date)`\n   */\n  setCreationDate(creationDate: Date | undefined): void {\n    this._creationDate = creationDate;\n  }\n\n  /**\n   * Return the creation date of the seed (alias for creationDate).\n   *\n   * @deprecated Use `creationDate()` for Rust API parity.\n   */\n  createdAt(): Date | undefined {\n    return this.creationDate();\n  }\n\n  /**\n   * Set the creation date of the seed (alias for setCreationDate).\n   *\n   * @deprecated Use `setCreationDate()` for Rust API parity.\n   */\n  setCreatedAt(date: Date): void {\n    this.setCreationDate(date);\n  }\n\n  /**\n   * Get metadata as an object.\n   *\n   * TypeScript convenience method - returns a snapshot of current metadata.\n   */\n  getMetadata(): SeedMetadata {\n    const metadata: SeedMetadata = {};\n    if (this._name.length > 0) {\n      metadata.name = this._name;\n    }\n    if (this._note.length > 0) {\n      metadata.note = this._note;\n    }\n    if (this._creationDate !== undefined) {\n      metadata.createdAt = this._creationDate;\n    }\n    return metadata;\n  }\n\n  // ============================================================================\n  // Instance Methods - Comparison and Display\n  // ============================================================================\n\n  /**\n   * Compare with another Seed.\n   */\n  equals(other: Seed): 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   * Get string representation.\n   */\n  toString(): string {\n    return `Seed(${this.toHex().substring(0, 16)}..., ${this.size()} bytes)`;\n  }\n\n  // ============================================================================\n  // PrivateKeyDataProvider Implementation\n  // ============================================================================\n\n  /**\n   * Returns unique data from which cryptographic keys can be derived.\n   *\n   * This implementation returns a copy of the seed data, which can be used\n   * as entropy for deriving private keys in various cryptographic schemes.\n   *\n   * @returns A Uint8Array containing the seed data\n   */\n  privateKeyData(): Uint8Array {\n    return this.toData();\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with Seed.\n   * Includes TAG_SEED (40300) and TAG_SEED_V1 (300) for backward compatibility.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SEED.value, TAG_SEED_V1.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding (as a map).\n   * Map keys:\n   * - 1: seed data (required)\n   * - 2: creation date (optional)\n   * - 3: name (optional, omitted if empty)\n   * - 4: note (optional, omitted if empty)\n   */\n  untaggedCbor(): Cbor {\n    const map = CborMap.new();\n    map.insert(1, toByteString(this._data));\n    if (this._creationDate !== undefined) {\n      const cborDate = CborDate.fromDatetime(this._creationDate);\n      map.insert(2, cborDate.taggedCbor());\n    }\n    if (this._name.length > 0) {\n      map.insert(3, this._name);\n    }\n    if (this._note.length > 0) {\n      map.insert(4, this._note);\n    }\n    return cbor(map);\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 Seed by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): Seed {\n    const map = expectMap(cborValue);\n\n    // Key 1: seed data (required)\n    // CborMap.extract() returns native types (Uint8Array for byte strings)\n    const data = map.extract<number, Uint8Array>(1);\n    if (data.length === 0) {\n      throw CryptoError.invalidData(\"Seed data is empty\");\n    }\n\n    // Key 2: creation date (optional)\n    // For tagged values (like dates), the extract returns the tagged Cbor object\n    let creationDate: Date | undefined;\n    const dateValue = map.get<number, Cbor>(2);\n    if (dateValue !== undefined) {\n      // The date is stored as a tagged CBOR value (tag 1)\n      const cborDate = CborDate.fromTaggedCbor(cbor(dateValue));\n      creationDate = cborDate.datetime();\n    }\n\n    // Key 3: name (optional)\n    const name = map.get<number, string>(3);\n\n    // Key 4: note (optional)\n    const note = map.get<number, string>(4);\n\n    return Seed.newOpt(new Uint8Array(data), name, note, creationDate);\n  }\n\n  /**\n   * Creates a Seed by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): Seed {\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(cborValue: Cbor): Seed {\n    const instance = Seed.new();\n    return instance.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): Seed {\n    const cborValue = decodeCbor(data);\n    return Seed.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): Seed {\n    const cborValue = decodeCbor(data);\n    const instance = Seed.new();\n    return instance.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the Seed.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"seed\", 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 Seed from a UR.\n   */\n  static fromUR(ur: UR): Seed {\n    ur.checkType(\"seed\");\n    const instance = Seed.new();\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a Seed from a UR string.\n   */\n  static fromURString(urString: string): Seed {\n    const ur = UR.fromURString(urString);\n    return Seed.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A globally unique reference to a globally unique object.\n *\n * Ported from bc-components-rust/src/reference.rs\n *\n * `Reference` is a 32-byte fixed-size identifier — typically derived from a\n * SHA-256 digest of an object's serialized form, but Rust also exposes\n * `Reference::from_data` for cases (like `XID`) where the underlying bytes\n * are themselves directly the reference identity.\n *\n * CDDL:\n * ```cddl\n * Reference = #6.40025(bytes .size 32)\n * ```\n */\n\nimport {\n  type Cbor,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  type Tag,\n  toByteString,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  expectBytes,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { REFERENCE as TAG_REFERENCE } from \"@bcts/tags\";\nimport { UR, encodeBytewordsIdentifier, encodeBytemojisIdentifier } from \"@bcts/uniform-resources\";\n\nimport { Digest } from \"./digest.js\";\nimport type { DigestProvider } from \"./digest-provider.js\";\nimport { CryptoError } from \"./error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"./utils.js\";\n\n/** Encoding format for short Reference identifiers. */\nexport type ReferenceEncodingFormat = \"hex\" | \"bytewords\" | \"bytemojis\";\n\n/**\n * Implementers of this interface provide a globally unique reference to themselves.\n *\n * Mirrors Rust's `ReferenceProvider` trait. The reference is derived from a\n * cryptographic digest of the object's serialized form, ensuring that it\n * uniquely identifies the object's contents.\n */\nexport interface ReferenceProvider {\n  /** Returns a cryptographic reference that uniquely identifies this object. */\n  reference(): Reference;\n}\n\n/**\n * Type guard to check if an object implements the ReferenceProvider interface.\n */\nexport function isReferenceProvider(obj: unknown): obj is ReferenceProvider {\n  return (\n    typeof obj === \"object\" &&\n    obj !== null &&\n    \"reference\" in obj &&\n    typeof (obj as ReferenceProvider).reference === \"function\"\n  );\n}\n\n/**\n * A globally unique reference to a globally unique object.\n *\n * Internally stores 32 raw bytes (matches Rust's `Reference([u8; 32])`).\n * Most callers obtain a `Reference` via `fromDigest`, but `XID` (and similar\n * content-addressable types whose bytes _are_ the reference) construct\n * via `fromData` directly.\n */\nexport class Reference\n  implements CborTaggedEncodable, CborTaggedDecodable<Reference>, DigestProvider, ReferenceProvider\n{\n  /** Reference data size in bytes — matches Rust `Reference::REFERENCE_SIZE`. */\n  static readonly REFERENCE_SIZE = 32;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    this._data = data;\n  }\n\n  // ============================================================================\n  // Factories\n  // ============================================================================\n\n  /** Create a Reference from exactly 32 bytes. Mirrors Rust `Reference::from_data`. */\n  static fromData(data: Uint8Array): Reference {\n    if (data.length !== Reference.REFERENCE_SIZE) {\n      throw CryptoError.invalidSize(Reference.REFERENCE_SIZE, data.length);\n    }\n    return new Reference(new Uint8Array(data));\n  }\n\n  /** Alias of `fromData` for parity with Rust `from_data_ref`. */\n  static fromDataRef(data: Uint8Array): Reference {\n    return Reference.fromData(data);\n  }\n\n  /** Create a Reference from a Digest's underlying bytes. */\n  static fromDigest(digest: Digest): Reference {\n    return new Reference(new Uint8Array(digest.toData()));\n  }\n\n  /** Backwards-compatible alias of `fromDigest`. */\n  static from(digest: Digest): Reference {\n    return Reference.fromDigest(digest);\n  }\n\n  /** Create a Reference from a 64-character hex string. */\n  static fromHex(hex: string): Reference {\n    return Reference.fromData(hexToBytes(hex));\n  }\n\n  /**\n   * Create a Reference whose bytes are the SHA-256 digest of the input.\n   *\n   * @deprecated Prefer `Reference.fromDigest(Digest.fromImage(data))` for\n   *   clarity, or `Reference.fromData(data)` if `data` is already 32 bytes\n   *   that should be wrapped without hashing (matches Rust `from_data`).\n   */\n  static hash(data: Uint8Array): Reference {\n    return Reference.fromDigest(Digest.fromImage(data));\n  }\n\n  // ============================================================================\n  // Accessors\n  // ============================================================================\n\n  /** Returns the 32 reference bytes (copy). */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /** Alias of `data()`. */\n  asBytes(): Uint8Array {\n    return this.data();\n  }\n\n  /** Returns a `Digest` constructed from these 32 bytes (no hashing). */\n  getDigest(): Digest {\n    return Digest.fromData(this._data);\n  }\n\n  /** The full 64-character lowercase hex of the reference. */\n  refHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /** The first 4 bytes of the reference. */\n  refDataShort(): Uint8Array {\n    return this._data.slice(0, 4);\n  }\n\n  /** The first 4 bytes of the reference, as 8 lowercase hex characters. */\n  refHexShort(): string {\n    return bytesToHex(this._data.slice(0, 4));\n  }\n\n  /**\n   * The first 4 bytes as upper-case bytewords identifier.\n   *\n   * @param prefix - Optional prefix prepended with a single space.\n   */\n  bytewordsIdentifier(prefix?: string): string {\n    const s = encodeBytewordsIdentifier(this.refDataShort()).toUpperCase();\n    return prefix !== undefined ? `${prefix} ${s}` : s;\n  }\n\n  /**\n   * The first 4 bytes as upper-case bytemojis identifier.\n   *\n   * @param prefix - Optional prefix prepended with a single space.\n   */\n  bytemojiIdentifier(prefix?: string): string {\n    const s = encodeBytemojisIdentifier(this.refDataShort()).toUpperCase();\n    return prefix !== undefined ? `${prefix} ${s}` : s;\n  }\n\n  // ============================================================================\n  // Backwards-compatible accessors\n  // ============================================================================\n\n  /** Backwards-compatible alias of `refHex()`. */\n  toHex(): string {\n    return this.refHex();\n  }\n\n  /** Backwards-compatible alias of `refHex()`. */\n  fullReference(): string {\n    return this.refHex();\n  }\n\n  /** Returns the 32 raw bytes encoded as base64. */\n  toBase64(): string {\n    return toBase64(this._data);\n  }\n\n  /**\n   * Returns a short representation of this reference in the requested format.\n   *\n   * Mirrors the legacy TS API; new code should prefer `refHexShort`,\n   * `bytewordsIdentifier`, or `bytemojiIdentifier` directly.\n   */\n  shortReference(format: ReferenceEncodingFormat = \"hex\"): string {\n    switch (format) {\n      case \"hex\":\n        return this.refHexShort();\n      case \"bytewords\":\n        return encodeBytewordsIdentifier(this.refDataShort());\n      case \"bytemojis\":\n        return encodeBytemojisIdentifier(this.refDataShort());\n      default: {\n        const _exhaustive: never = format;\n        throw CryptoError.invalidFormat(`Unknown reference format: ${String(_exhaustive)}`);\n      }\n    }\n  }\n\n  // ============================================================================\n  // ReferenceProvider / DigestProvider\n  // ============================================================================\n\n  /** A Reference to this Reference (matches Rust's blanket `ReferenceProvider` impl). */\n  reference(): Reference {\n    return Reference.fromDigest(this.digest());\n  }\n\n  /**\n   * SHA-256 of `taggedCbor().toCborData()`.\n   *\n   * Matches Rust's `DigestProvider for Reference` —\n   * `Digest::from_image(self.tagged_cbor().to_cbor_data())`.\n   */\n  digest(): Digest {\n    return Digest.fromImage(this.taggedCborData());\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_REFERENCE.value]);\n  }\n\n  /** Untagged CBOR — a single byte string of the 32 raw bytes. */\n  untaggedCbor(): Cbor {\n    return toByteString(this._data);\n  }\n\n  taggedCbor(): Cbor {\n    return createTaggedCbor(this);\n  }\n\n  taggedCborData(): Uint8Array {\n    return this.taggedCbor().toData();\n  }\n\n  // ============================================================================\n  // CBOR Deserialization (CborTaggedDecodable)\n  // ============================================================================\n\n  fromUntaggedCbor(cbor: Cbor): Reference {\n    return Reference.fromData(expectBytes(cbor));\n  }\n\n  fromTaggedCbor(cbor: Cbor): Reference {\n    validateTag(cbor, this.cborTags());\n    return this.fromUntaggedCbor(extractTaggedContent(cbor));\n  }\n\n  static fromTaggedCbor(cbor: Cbor): Reference {\n    const dummy = new Reference(new Uint8Array(Reference.REFERENCE_SIZE));\n    return dummy.fromTaggedCbor(cbor);\n  }\n\n  static fromTaggedCborData(data: Uint8Array): Reference {\n    return Reference.fromTaggedCbor(decodeCbor(data));\n  }\n\n  static fromUntaggedCborData(data: Uint8Array): Reference {\n    const dummy = new Reference(new Uint8Array(Reference.REFERENCE_SIZE));\n    return dummy.fromUntaggedCbor(decodeCbor(data));\n  }\n\n  // ============================================================================\n  // UR\n  // ============================================================================\n\n  static readonly UR_TYPE = \"reference\";\n\n  /** UR representation — `ur:reference/...`, untagged CBOR payload. */\n  ur(): UR {\n    return UR.new(Reference.UR_TYPE, this.untaggedCbor());\n  }\n\n  urString(): string {\n    return this.ur().string();\n  }\n\n  static fromUR(ur: UR): Reference {\n    ur.checkType(Reference.UR_TYPE);\n    const dummy = new Reference(new Uint8Array(Reference.REFERENCE_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  static fromURString(s: string): Reference {\n    return Reference.fromUR(UR.fromURString(s));\n  }\n\n  // ============================================================================\n  // Equality / display\n  // ============================================================================\n\n  equals(other: Reference): 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  /** Debug-style representation: `Reference(<8-hex-prefix>)`. */\n  toString(): string {\n    return `Reference(${this.refHexShort()})`;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * An \"Apparently Random Identifier\" (ARID)\n *\n * Ported from bc-components-rust/src/id/arid.rs\n *\n * An ARID is a cryptographically strong, universally unique identifier with\n * the following properties:\n * - Non-correlatability: The sequence of bits cannot be correlated with its\n *   referent or any other ARID\n * - Neutral semantics: Contains no inherent type information\n * - Open generation: Any method of generation is allowed as long as it\n *   produces statistically random bits\n * - Minimum strength: Must be 256 bits (32 bytes) in length\n * - Cryptographic suitability: Can be used as inputs to cryptographic\n *   constructs\n *\n * Unlike digests/hashes which identify a fixed, immutable state of data, ARIDs\n * can serve as stable identifiers for mutable data structures.\n *\n * ARIDs should not be confused with or cast to/from other identifier types\n * (like UUIDs), used as nonces, keys, or cryptographic seeds.\n *\n * As defined in [BCR-2022-002](https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2022-002-arid.md).\n *\n * # CBOR Serialization\n *\n * `ARID` implements the CBOR tagged encoding interfaces, which means it can be\n * serialized to and deserialized from CBOR with a specific tag (TAG_ARID = 40012).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), an `ARID` is represented as a\n * binary blob with the type \"arid\".\n *\n * @example\n * ```typescript\n * import { ARID } from '@bcts/components';\n *\n * // Create a new random ARID\n * const arid = ARID.new();\n *\n * // Create an ARID from a hex string\n * const arid2 = ARID.fromHex(\"...\");\n *\n * // Get the ARID as hex\n * console.log(arid.hex());\n * ```\n */\n\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\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 { ARID as TAG_ARID } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class ARID implements CborTaggedEncodable, CborTaggedDecodable<ARID>, UREncodable {\n  static readonly ARID_SIZE = 32;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== ARID.ARID_SIZE) {\n      throw CryptoError.invalidSize(ARID.ARID_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new random ARID.\n   */\n  static new(): ARID {\n    const rng = new SecureRandomNumberGenerator();\n    return new ARID(rng.randomData(ARID.ARID_SIZE));\n  }\n\n  /**\n   * Create a new random ARID (alias for new()).\n   */\n  static random(): ARID {\n    return ARID.new();\n  }\n\n  /**\n   * Restore an ARID from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): ARID {\n    return new ARID(new Uint8Array(data));\n  }\n\n  /**\n   * Create a new ARID from a reference to an array of bytes.\n   */\n  static fromDataRef(data: Uint8Array): ARID {\n    if (data.length !== ARID.ARID_SIZE) {\n      throw CryptoError.invalidSize(ARID.ARID_SIZE, data.length);\n    }\n    return ARID.fromData(data);\n  }\n\n  /**\n   * Create an ARID from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): ARID {\n    return ARID.fromData(data);\n  }\n\n  /**\n   * Create a new ARID from the given hexadecimal string.\n   *\n   * @throws Error if the string is not exactly 64 hexadecimal digits.\n   */\n  static fromHex(hex: string): ARID {\n    return new ARID(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get the data of the ARID as an array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the data of the ARID as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw ARID bytes as a copy.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * The data as a hexadecimal string.\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   * The first four bytes of the ARID as a hexadecimal string.\n   */\n  shortDescription(): string {\n    return bytesToHex(this._data.slice(0, 4));\n  }\n\n  /**\n   * Compare with another ARID.\n   */\n  equals(other: ARID): 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 ARIDs lexicographically.\n   */\n  compare(other: ARID): 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 `ARID(${this.hex()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with ARID.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_ARID.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 an ARID by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): ARID {\n    const data = expectBytes(cbor);\n    return ARID.fromDataRef(data);\n  }\n\n  /**\n   * Creates an ARID by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): ARID {\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): ARID {\n    const instance = new ARID(new Uint8Array(ARID.ARID_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): ARID {\n    const cbor = decodeCbor(data);\n    return ARID.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): ARID {\n    const cbor = decodeCbor(data);\n    const bytes = expectBytes(cbor);\n    return ARID.fromDataRef(bytes);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the ARID.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"arid\", 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 an ARID from a UR.\n   */\n  static fromUR(ur: UR): ARID {\n    ur.checkType(\"arid\");\n    const instance = new ARID(new Uint8Array(ARID.ARID_SIZE));\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an ARID from a UR string.\n   */\n  static fromURString(urString: string): ARID {\n    const ur = UR.fromURString(urString);\n    return ARID.fromUR(ur);\n  }\n\n  /**\n   * Alias for fromURString for Rust API compatibility.\n   */\n  static fromUrString(urString: string): ARID {\n    return ARID.fromURString(urString);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Universally Unique Identifier (UUID) - 16-byte identifier\n *\n * UUIDs are 128-bit (16-byte) identifiers that are designed to be unique\n * across space and time. This implementation creates type 4 (random) UUIDs,\n * following the UUID specification:\n *\n * - Version field (bits 48-51) is set to 4, indicating a random UUID\n * - Variant field (bits 64-65) is set to 2, indicating RFC 4122/DCE 1.1 UUID\n *   variant\n *\n * Unlike ARIDs, UUIDs:\n * - Are shorter (128 bits vs 256 bits)\n * - Contain version and variant metadata within the identifier\n * - Have a canonical string representation with 5 groups separated by hyphens\n *\n * The canonical textual representation of a UUID takes the form:\n * `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` where each `x` is a hexadecimal digit.\n *\n * # CBOR Serialization\n *\n * `UUID` is serialized to CBOR with tag 37 (standard UUID tag).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `UUID` is represented with the\n * type \"uuid\".\n */\n\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 { UUID as TAG_UUID } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, toBase64 } from \"../utils.js\";\n\nconst UUID_SIZE = 16;\n\nexport class UUID implements CborTaggedEncodable, CborTaggedDecodable<UUID>, UREncodable {\n  static readonly UUID_SIZE = UUID_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== UUID_SIZE) {\n      throw CryptoError.invalidSize(UUID_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new random UUID (v4).\n   */\n  static new(): UUID {\n    return UUID.random();\n  }\n\n  /**\n   * Create a UUID from raw bytes.\n   */\n  static fromData(data: Uint8Array): UUID {\n    return new UUID(new Uint8Array(data));\n  }\n\n  /**\n   * Restores a UUID from data (validates length).\n   */\n  static fromDataRef(data: Uint8Array): UUID {\n    if (data.length !== UUID_SIZE) {\n      throw CryptoError.invalidSize(UUID_SIZE, data.length);\n    }\n    return UUID.fromData(data);\n  }\n\n  /**\n   * Create a UUID from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): UUID {\n    return UUID.fromData(data);\n  }\n\n  /**\n   * Create a UUID from hex string (32 hex chars)\n   */\n  static fromHex(hex: string): UUID {\n    if (hex.length !== 32) {\n      throw CryptoError.invalidFormat(`UUID hex must be 32 characters, got ${hex.length}`);\n    }\n    const data = new Uint8Array(16);\n    for (let i = 0; i < 16; i++) {\n      data[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);\n    }\n    return new UUID(data);\n  }\n\n  /**\n   * Create a UUID from string representation (standard UUID format)\n   * Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n   */\n  static fromString(uuidString: string): UUID {\n    const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n    if (!uuidRegex.test(uuidString)) {\n      throw CryptoError.invalidFormat(`Invalid UUID format: ${uuidString}`);\n    }\n    const hex = uuidString.replace(/-/g, \"\");\n    return UUID.fromHex(hex);\n  }\n\n  /**\n   * Generate a random UUID (v4)\n   */\n  static random(): UUID {\n    const data = new Uint8Array(UUID_SIZE);\n    globalThis.crypto.getRandomValues(data);\n\n    // Set version to 4 (random)\n    data[6] = (data[6] & 0x0f) | 0x40;\n    // Set variant to RFC 4122\n    data[8] = (data[8] & 0x3f) | 0x80;\n\n    return new UUID(data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get the data of the UUID.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the UUID as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw UUID bytes as a copy.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Get hex string representation (lowercase, matching Rust implementation).\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 standard UUID string representation.\n   * Format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n   */\n  toString(): string {\n    const hex = this.toHex();\n    return `${hex.substring(0, 8)}-${hex.substring(8, 12)}-${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20)}`;\n  }\n\n  /**\n   * Get base64 representation.\n   */\n  toBase64(): string {\n    return toBase64(this._data);\n  }\n\n  /**\n   * Compare with another UUID.\n   */\n  equals(other: UUID): 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  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with UUID.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_UUID.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 UUID by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): UUID {\n    const data = expectBytes(cbor);\n    return UUID.fromDataRef(data);\n  }\n\n  /**\n   * Creates a UUID by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): UUID {\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): UUID {\n    const instance = new UUID(new Uint8Array(UUID_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): UUID {\n    const cbor = decodeCbor(data);\n    return UUID.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): UUID {\n    const cbor = decodeCbor(data);\n    const bytes = expectBytes(cbor);\n    return UUID.fromDataRef(bytes);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the UUID.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"uuid\", 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 UUID from a UR.\n   */\n  static fromUR(ur: UR): UUID {\n    ur.checkType(\"uuid\");\n    const instance = new UUID(new Uint8Array(UUID_SIZE));\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a UUID from a UR string.\n   */\n  static fromURString(urString: string): UUID {\n    const ur = UR.fromURString(urString);\n    return UUID.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * eXtensible Identifier (XID) - 32-byte identifier bound to a public key\n *\n * A XID is a unique 32-byte identifier for a subject entity (person,\n * organization, device, or any other entity). XIDs have the following\n * characteristics:\n *\n * - They're cryptographically tied to a public key at inception (the\n *   \"inception key\")\n * - They remain stable throughout their lifecycle even as their keys and\n *   permissions change\n * - They can be extended to XID documents containing keys, endpoints,\n *   permissions, and delegation info\n * - They support key rotation and multiple verification schemes\n * - They allow for delegation of specific permissions to other entities\n * - They can include resolution methods to locate and verify the XID document\n *\n * A XID is created by taking the SHA-256 hash of the CBOR encoding of a public\n * signing key. This ensures the XID is cryptographically tied to the key.\n *\n * As defined in [BCR-2024-010](https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2024-010-xid.md).\n *\n * # CBOR Serialization\n *\n * `XID` is serialized to CBOR with tag 40024 (standard XID tag).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `XID` is represented with the\n * type \"xid\".\n */\n\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 { XID as TAG_XID } from \"@bcts/tags\";\nimport {\n  UR,\n  type UREncodable,\n  encodeBytewordsIdentifier,\n  encodeBytemojisIdentifier,\n} from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, toBase64 } from \"../utils.js\";\nimport { Digest } from \"../digest.js\";\nimport { Reference, type ReferenceProvider } from \"../reference.js\";\nimport type { SigningPublicKey } from \"../signing/signing-public-key.js\";\nimport type { SigningPrivateKey } from \"../signing/signing-private-key.js\";\nimport type { PublicKeys } from \"../public-keys.js\";\nimport type { PrivateKeyBase } from \"../private-key-base.js\";\n\n/**\n * XID prefix glyph for the upper-case bytewords/bytemoji identifier.\n *\n * Exported as the single source of truth so dependent packages (`@bcts/xid`,\n * `@bcts/envelope`, etc.) don't redefine the literal `\"🅧\"`.\n */\nexport const XID_PREFIX = \"🅧\";\n\nconst XID_SIZE = 32;\n\n/**\n * Trait-style interface for objects that can produce a XID.\n *\n * Mirrors Rust's `XIDProvider` trait. `XID` itself implements this; any\n * other type that maps cleanly to a single XID (e.g. `SigningPublicKey`,\n * `PublicKeys`) may also implement it.\n */\nexport interface XIDProvider {\n  /** Returns the XID for this object. */\n  xid(): XID;\n}\n\n/**\n * Type guard for {@link XIDProvider}.\n */\nexport function isXIDProvider(obj: unknown): obj is XIDProvider {\n  return (\n    typeof obj === \"object\" &&\n    obj !== null &&\n    \"xid\" in obj &&\n    typeof (obj as XIDProvider).xid === \"function\"\n  );\n}\n\nexport class XID\n  implements\n    CborTaggedEncodable,\n    CborTaggedDecodable<XID>,\n    UREncodable,\n    XIDProvider,\n    ReferenceProvider\n{\n  static readonly XID_SIZE = XID_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== XID_SIZE) {\n      throw CryptoError.invalidSize(XID_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new XID from data.\n   */\n  static fromData(data: Uint8Array): XID {\n    return new XID(new Uint8Array(data));\n  }\n\n  /**\n   * Create a new XID from data (validates length).\n   *\n   * Returns error if the data is not the correct length.\n   */\n  static fromDataRef(data: Uint8Array): XID {\n    if (data.length !== XID_SIZE) {\n      throw CryptoError.invalidSize(XID_SIZE, data.length);\n    }\n    return XID.fromData(data);\n  }\n\n  /**\n   * Create an XID from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): XID {\n    return XID.fromData(data);\n  }\n\n  /**\n   * Create an XID from hex string (64 hex characters).\n   */\n  static fromHex(hex: string): XID {\n    if (hex.length !== 64) {\n      throw CryptoError.invalidFormat(`XID hex must be 64 characters, got ${hex.length}`);\n    }\n    const data = new Uint8Array(32);\n    for (let i = 0; i < 32; i++) {\n      data[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);\n    }\n    return new XID(data);\n  }\n\n  /**\n   * Generate a random XID (for testing purposes).\n   *\n   * Note: In practice, XIDs should be created from the SHA-256 hash of a\n   * public signing key's CBOR encoding.\n   */\n  static random(): XID {\n    const data = new Uint8Array(XID_SIZE);\n    const crypto = globalThis.crypto as Crypto | undefined;\n    if (crypto !== undefined && typeof crypto.getRandomValues === \"function\") {\n      crypto.getRandomValues(data);\n    } else {\n      // Fallback: fill with available random data\n      for (let i = 0; i < XID_SIZE; i++) {\n        data[i] = Math.floor(Math.random() * 256);\n      }\n    }\n    return new XID(data);\n  }\n\n  /**\n   * Create a new XID from the given public key (the \"genesis key\").\n   *\n   * The XID is the SHA-256 digest of the CBOR encoding of the public key.\n   * This matches Rust's `XID::new(genesis_key: impl AsRef<SigningPublicKey>)`.\n   */\n  static newFromSigningKey(signingPublicKey: SigningPublicKey): XID {\n    const keyCborData = signingPublicKey.taggedCborData();\n    const digest = Digest.fromImage(keyCborData);\n    return XID.fromData(digest.toData());\n  }\n\n  /**\n   * Mirror of Rust's `From<&SigningPublicKey> for XID`.\n   * Equivalent to {@link newFromSigningKey}; provided for API parity.\n   */\n  static fromSigningPublicKey(signingPublicKey: SigningPublicKey): XID {\n    return XID.newFromSigningKey(signingPublicKey);\n  }\n\n  /**\n   * Mirror of Rust's `From<&PublicKeys> for XID`.\n   * The XID is derived from the bundle's signing public key.\n   */\n  static fromPublicKeys(publicKeys: PublicKeys): XID {\n    return XID.newFromSigningKey(publicKeys.signingPublicKey());\n  }\n\n  /**\n   * Mirror of Rust's `From<&PrivateKeyBase> for XID` (secp256k1 feature).\n   * The XID is derived from the schnorr signing public key.\n   */\n  static fromPrivateKeyBase(base: PrivateKeyBase): XID {\n    return XID.newFromSigningKey(base.schnorrSigningPrivateKey().publicKey());\n  }\n\n  /**\n   * Mirror of Rust's `TryFrom<&SigningPrivateKey> for XID`.\n   * The XID is derived from the corresponding public key.\n   */\n  static tryFromSigningPrivateKey(signingPrivateKey: SigningPrivateKey): XID {\n    return XID.newFromSigningKey(signingPrivateKey.publicKey());\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Validate the XID against the given public key.\n   *\n   * Returns true if the SHA-256 hash of the key's CBOR encoding matches\n   * the XID data. This matches Rust's `XID::validate(&self, key: &SigningPublicKey)`.\n   */\n  validate(signingPublicKey: SigningPublicKey): boolean {\n    const keyData = signingPublicKey.taggedCborData();\n    const digest = Digest.fromImage(keyData);\n    return this.equals(XID.fromData(digest.toData()));\n  }\n\n  /**\n   * Return the data of the XID.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the data of the XID as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get a copy of the raw XID bytes.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Get hex string representation (lowercase, matching Rust implementation).\n   */\n  toHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Get base64 representation.\n   */\n  toBase64(): string {\n    return toBase64(this._data);\n  }\n\n  /**\n   * Get short description (first 4 bytes) as hex.\n   */\n  shortDescription(): string {\n    return bytesToHex(this._data.slice(0, 4));\n  }\n\n  /**\n   * Get short reference (first 4 bytes) as hex (alias for shortDescription).\n   */\n  shortReference(): string {\n    return this.shortDescription();\n  }\n\n  /**\n   * Get the first four bytes of the XID as upper-case ByteWords.\n   *\n   * @param prefix - If true, prepends the XID prefix \"🅧 \"\n   * @returns Space-separated uppercase bytewords, e.g., \"🅧 URGE DICE GURU IRIS\"\n   */\n  bytewordsIdentifier(prefix = false): string {\n    const words = encodeBytewordsIdentifier(this._data.slice(0, 4)).toUpperCase();\n    return prefix ? `${XID_PREFIX} ${words}` : words;\n  }\n\n  /**\n   * Get the first four bytes of the XID as Bytemoji.\n   *\n   * @param prefix - If true, prepends the XID prefix \"🅧 \"\n   * @returns Space-separated emojis, e.g., \"🅧 🐻 😻 🍞 💐\"\n   */\n  bytemojisIdentifier(prefix = false): string {\n    const emojis = encodeBytemojisIdentifier(this._data.slice(0, 4));\n    return prefix ? `${XID_PREFIX} ${emojis}` : emojis;\n  }\n\n  /**\n   * XIDProvider impl — returns this XID.\n   *\n   * Mirrors Rust's blanket `impl XIDProvider for XID`.\n   */\n  xid(): XID {\n    return this;\n  }\n\n  /**\n   * ReferenceProvider impl — produces a Reference whose 32 bytes are the\n   * raw XID data.\n   *\n   * Mirrors Rust's `impl ReferenceProvider for XID { fn reference(&self) ->\n   * Reference { Reference::from_data(*self.data()) } }` — note this is a\n   * direct wrap, not a SHA-256 hash of the XID.\n   */\n  reference(): Reference {\n    return Reference.fromData(this._data);\n  }\n\n  /**\n   * Compare with another XID.\n   */\n  equals(other: XID): 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   * Get string representation (short format, matching Rust Display).\n   * Uses first 4 bytes of the XID as hex, e.g., \"XID(71274df1)\".\n   */\n  toString(): string {\n    return `XID(${this.shortDescription()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with XID.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_XID.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 XID by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): XID {\n    const data = expectBytes(cbor);\n    return XID.fromDataRef(data);\n  }\n\n  /**\n   * Creates a XID by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): XID {\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): XID {\n    const instance = new XID(new Uint8Array(XID_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): XID {\n    const cbor = decodeCbor(data);\n    return XID.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): XID {\n    const cbor = decodeCbor(data);\n    const bytes = expectBytes(cbor);\n    return XID.fromDataRef(bytes);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the XID.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"xid\", 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 XID from a UR.\n   */\n  static fromUR(ur: UR): XID {\n    ur.checkType(\"xid\");\n    const instance = new XID(new Uint8Array(XID_SIZE));\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a XID from a UR string.\n   */\n  static fromURString(urString: string): XID {\n    const ur = UR.fromURString(urString);\n    return XID.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Uniform Resource Identifier (URI) - String-based identifier\n *\n * A URI is a string of characters that unambiguously identifies a particular\n * resource. This implementation validates URIs using the URL API to ensure\n * conformance to RFC 3986.\n *\n * URIs are commonly used for:\n * - Web addresses (URLs like \"https://example.com\")\n * - Resource identifiers in various protocols\n * - Namespace identifiers\n * - References to resources in distributed systems\n *\n * # CBOR Serialization\n *\n * `URI` is serialized to CBOR with tag 32 (standard URI tag).\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `URI` is represented with the\n * type \"url\".\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectText,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { URI as TAG_URI } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { toBase64 } from \"../utils.js\";\n\nexport class URI implements CborTaggedEncodable, CborTaggedDecodable<URI>, UREncodable {\n  private readonly _uri: string;\n\n  private constructor(uri: string) {\n    this._uri = uri;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Creates a new `URI` from a string with validation.\n   */\n  static new(uri: string): URI {\n    // Validate using URL API\n    try {\n      new URL(uri);\n      return new URI(uri);\n    } catch {\n      throw CryptoError.invalidData(\"URI: invalid URI format\");\n    }\n  }\n\n  /**\n   * Create a URI from string (legacy alias).\n   */\n  static from(uri: string): URI {\n    return URI.new(uri);\n  }\n\n  /**\n   * Parse a URI string (alias for new()).\n   */\n  static parse(uriString: string): URI {\n    return URI.new(uriString);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get the URI as a string reference.\n   */\n  asRef(): string {\n    return this._uri;\n  }\n\n  /**\n   * Get the URI string.\n   */\n  toString(): string {\n    return this._uri;\n  }\n\n  /**\n   * Get the URI string (alias).\n   */\n  toURI(): string {\n    return this._uri;\n  }\n\n  /**\n   * Get the raw URI string.\n   */\n  getRaw(): string {\n    return this._uri;\n  }\n\n  /**\n   * Get scheme (e.g., \"http\", \"https\", \"urn\").\n   */\n  scheme(): string | null {\n    const match = /^([a-z][a-z0-9+.-]*):\\/?\\/?/i.exec(this._uri);\n    return match !== null ? match[1] : null;\n  }\n\n  /**\n   * Get path component.\n   */\n  path(): string {\n    try {\n      const url = new URL(this._uri);\n      return url.pathname;\n    } catch {\n      // For non-URL URIs, try to extract path after scheme\n      const withoutScheme = this._uri.replace(/^[a-z][a-z0-9+.-]*:\\/?\\/?/i, \"\");\n      return withoutScheme;\n    }\n  }\n\n  /**\n   * Check if URI is absolute (has a scheme).\n   */\n  isAbsolute(): boolean {\n    return /^[a-z][a-z0-9+.-]*:/i.test(this._uri);\n  }\n\n  /**\n   * Check if URI is relative.\n   */\n  isRelative(): boolean {\n    return !this.isAbsolute();\n  }\n\n  /**\n   * Compare with another URI.\n   */\n  equals(other: URI): boolean {\n    return this._uri === other._uri;\n  }\n\n  /**\n   * Check if URI starts with given prefix.\n   */\n  startsWith(prefix: string): boolean {\n    return this._uri.startsWith(prefix);\n  }\n\n  /**\n   * Get base64 representation of the URI string.\n   */\n  toBase64(): string {\n    return toBase64(new TextEncoder().encode(this._uri));\n  }\n\n  /**\n   * Get the length of the URI string.\n   */\n  length(): number {\n    return this._uri.length;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with URI.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_URI.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding (as a text string).\n   */\n  untaggedCbor(): Cbor {\n    return cbor(this._uri);\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 URI by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): URI {\n    const text = expectText(cborValue);\n    return URI.new(text);\n  }\n\n  /**\n   * Creates a URI by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): URI {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): URI {\n    const instance = new URI(\"https://placeholder.invalid\");\n    return instance.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): URI {\n    const cborValue = decodeCbor(data);\n    return URI.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): URI {\n    const cborValue = decodeCbor(data);\n    const text = expectText(cborValue);\n    return URI.new(text);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the URI.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"url\", 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 URI from a UR.\n   */\n  static fromUR(ur: UR): URI {\n    ur.checkType(\"url\");\n    const instance = new URI(\"https://placeholder.invalid\");\n    return instance.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a URI from a UR string.\n   */\n  static fromURString(urString: string): URI {\n    const ur = UR.fromURString(urString);\n    return URI.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Ed25519 public key for EdDSA signature verification (32 bytes)\n * Ported from bc-components-rust/src/ed25519/ed25519_public_key.rs\n */\n\nimport { ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, ed25519Verify } from \"@bcts/crypto\";\nimport { Digest } from \"../digest.js\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class Ed25519PublicKey {\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== ED25519_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(ED25519_PUBLIC_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  /**\n   * Create an Ed25519PublicKey from raw bytes (32 bytes).\n   */\n  static from(data: Uint8Array): Ed25519PublicKey {\n    return new Ed25519PublicKey(data);\n  }\n\n  /**\n   * Mirror of Rust `Ed25519PublicKey::from_data` — exact-length copy.\n   */\n  static fromData(data: Uint8Array): Ed25519PublicKey {\n    return new Ed25519PublicKey(data);\n  }\n\n  /**\n   * Mirror of Rust `Ed25519PublicKey::from_data_ref` — validates length.\n   */\n  static fromDataRef(data: Uint8Array): Ed25519PublicKey {\n    if (data.length !== ED25519_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(ED25519_PUBLIC_KEY_SIZE, data.length);\n    }\n    return new Ed25519PublicKey(data);\n  }\n\n  /**\n   * Create an Ed25519PublicKey from hex string.\n   */\n  static fromHex(hex: string): Ed25519PublicKey {\n    return new Ed25519PublicKey(hexToBytes(hex));\n  }\n\n  /** Returns the 32 raw public key bytes (copy). */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /** Alias of {@link data}. */\n  asBytes(): Uint8Array {\n    return this.data();\n  }\n\n  /** Backwards-compatible alias of {@link data}. */\n  toData(): Uint8Array {\n    return this.data();\n  }\n\n  /**\n   * Get hex string representation\n   */\n  toHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Get base64 representation\n   */\n  toBase64(): string {\n    return toBase64(this._data);\n  }\n\n  /**\n   * Verify a signature using Ed25519\n   */\n  verify(message: Uint8Array, signature: Uint8Array): boolean {\n    try {\n      if (signature.length !== ED25519_SIGNATURE_SIZE) {\n        throw CryptoError.invalidSize(ED25519_SIGNATURE_SIZE, signature.length);\n      }\n      return ed25519Verify(this._data, message, signature);\n    } catch (e) {\n      throw CryptoError.cryptoOperation(`Ed25519 verification failed: ${String(e)}`);\n    }\n  }\n\n  /**\n   * Compare with another Ed25519PublicKey\n   */\n  equals(other: Ed25519PublicKey): 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   * Get string representation.\n   *\n   * Mirrors Rust `Display for Ed25519PublicKey`\n   * (`bc-components-rust/src/ed25519/ed25519_public_key.rs`):\n   *   `Ed25519PublicKey(<ref_hex_short>)`\n   * where the reference is computed from the **raw 32-byte data**\n   * (not tagged CBOR) — same pattern as SchnorrPublicKey.\n   */\n  toString(): string {\n    const digest = Digest.fromImage(this._data);\n    return `Ed25519PublicKey(${digest.shortDescription()})`;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Ed25519 private key for EdDSA signatures (32 bytes seed)\n * Ported from bc-components-rust/src/ed25519_private_key.rs\n */\n\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  ED25519_PRIVATE_KEY_SIZE,\n  ed25519PublicKeyFromPrivateKey,\n  ed25519Sign,\n  deriveSigningPrivateKey,\n} from \"@bcts/crypto\";\nimport { CryptoError } from \"../error.js\";\nimport { Ed25519PublicKey } from \"./ed25519-public-key.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class Ed25519PrivateKey {\n  private readonly seed: Uint8Array;\n  private _publicKey?: Ed25519PublicKey;\n\n  private constructor(seed: Uint8Array) {\n    if (seed.length !== ED25519_PRIVATE_KEY_SIZE) {\n      throw CryptoError.invalidSize(ED25519_PRIVATE_KEY_SIZE, seed.length);\n    }\n    this.seed = new Uint8Array(seed);\n  }\n\n  /**\n   * Create an Ed25519PrivateKey from seed (32 bytes)\n   */\n  static from(seed: Uint8Array): Ed25519PrivateKey {\n    return new Ed25519PrivateKey(new Uint8Array(seed));\n  }\n\n  /**\n   * Create an Ed25519PrivateKey from hex string (64 hex characters)\n   */\n  static fromHex(hex: string): Ed25519PrivateKey {\n    return new Ed25519PrivateKey(hexToBytes(hex));\n  }\n\n  /**\n   * Generate a random Ed25519PrivateKey\n   */\n  static random(): Ed25519PrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return new Ed25519PrivateKey(rng.randomData(ED25519_PRIVATE_KEY_SIZE));\n  }\n\n  /**\n   * Generate a random Ed25519PrivateKey using provided RNG\n   */\n  static randomUsing(rng: SecureRandomNumberGenerator): Ed25519PrivateKey {\n    return new Ed25519PrivateKey(rng.randomData(ED25519_PRIVATE_KEY_SIZE));\n  }\n\n  /**\n   * Derives an Ed25519 private key from the given key material via\n   * HKDF-SHA-256 with salt `\"signing\"` and empty info (matches Rust\n   * `bc_crypto::derive_signing_private_key`).\n   */\n  static deriveFromKeyMaterial(keyMaterial: Uint8Array): Ed25519PrivateKey {\n    return new Ed25519PrivateKey(deriveSigningPrivateKey(keyMaterial));\n  }\n\n  /**\n   * Get the raw seed bytes (32 bytes).\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this.seed);\n  }\n\n  /** Alias of {@link data}. */\n  asBytes(): Uint8Array {\n    return this.data();\n  }\n\n  /** Backwards-compatible alias of {@link data}. */\n  toData(): Uint8Array {\n    return this.data();\n  }\n\n  /**\n   * Get hex string representation of the seed\n   */\n  toHex(): string {\n    return bytesToHex(this.seed);\n  }\n\n  /**\n   * Get base64 representation of the seed\n   */\n  toBase64(): string {\n    return toBase64(this.seed);\n  }\n\n  /**\n   * Derive the corresponding public key\n   */\n  publicKey(): Ed25519PublicKey {\n    if (this._publicKey === undefined) {\n      const publicKeyBytes = ed25519PublicKeyFromPrivateKey(this.seed);\n      this._publicKey = Ed25519PublicKey.from(publicKeyBytes);\n    }\n    return this._publicKey;\n  }\n\n  /**\n   * Sign a message using Ed25519\n   */\n  sign(message: Uint8Array): Uint8Array {\n    try {\n      const signature = ed25519Sign(this.seed, message);\n      return new Uint8Array(signature);\n    } catch (e) {\n      throw CryptoError.cryptoOperation(`Ed25519 signing failed: ${String(e)}`);\n    }\n  }\n\n  /**\n   * Compare with another Ed25519PrivateKey\n   */\n  equals(other: Ed25519PrivateKey): boolean {\n    if (this.seed.length !== other.seed.length) return false;\n    for (let i = 0; i < this.seed.length; i++) {\n      if (this.seed[i] !== other.seed[i]) return false;\n    }\n    return true;\n  }\n\n  /**\n   * Get string representation\n   */\n  toString(): string {\n    return `Ed25519PrivateKey(${this.toHex().substring(0, 16)}...)`;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Sr25519PublicKey - Public key for Schnorr signatures over Ristretto25519\n *\n * SR25519 is the signature scheme used by Polkadot/Substrate.\n * It is based on Schnorr signatures over the Ristretto group.\n *\n * Note: SR25519 uses the SigningPublicKey CBOR tag (40022) with discriminator 3.\n *\n * Ported from bc-components-rust/src/sr25519/sr25519_public_key.rs\n */\n\nimport * as sr25519 from \"@scure/sr25519\";\nimport { SR25519_PUBLIC_KEY_SIZE, SR25519_DEFAULT_CONTEXT } from \"./sr25519-private-key.js\";\nimport { bytesToHex, bytesEqual } from \"../utils.js\";\nimport { CryptoError } from \"../error.js\";\n\n/**\n * Sr25519PublicKey - Public key for Schnorr signatures over Ristretto25519.\n *\n * This is the signature scheme used by Polkadot/Substrate.\n */\nexport class Sr25519PublicKey {\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== SR25519_PUBLIC_KEY_SIZE) {\n      throw new Error(\n        `Sr25519PublicKey must be ${SR25519_PUBLIC_KEY_SIZE} bytes, got ${data.length}`,\n      );\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an Sr25519 public key from raw bytes.\n   */\n  static from(data: Uint8Array): Sr25519PublicKey {\n    return new Sr25519PublicKey(data);\n  }\n\n  /**\n   * Create an Sr25519 public key from a hex string.\n   */\n  static fromHex(hex: string): Sr25519PublicKey {\n    const matches = hex.match(/.{1,2}/g);\n    if (matches === null) {\n      throw new Error(\"Invalid hex string\");\n    }\n    const data = new Uint8Array(matches.map((byte) => parseInt(byte, 16)));\n    return Sr25519PublicKey.from(data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the raw key bytes.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the raw key bytes (alias for toData).\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns the hex representation of the key.\n   */\n  toHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Verify a signature using the default \"substrate\" context.\n   *\n   * @param signature - The 64-byte signature\n   * @param message - The message that was signed\n   * @returns true if the signature is valid\n   */\n  verify(signature: Uint8Array, message: Uint8Array): boolean {\n    return this.verifyWithContext(signature, message, SR25519_DEFAULT_CONTEXT);\n  }\n\n  /**\n   * Verify a signature using a custom context.\n   *\n   * The underlying `@scure/sr25519` library hard-codes the `\"substrate\"`\n   * signing context. To avoid silently accepting/rejecting cross-platform\n   * signatures, this method throws when called with any other context —\n   * matching the symmetric guard in `Sr25519PrivateKey.signWithContext`.\n   *\n   * @param signature - The 64-byte signature\n   * @param message - The message that was signed\n   * @param context - The signing context (must equal `SR25519_DEFAULT_CONTEXT`)\n   * @returns true if the signature is valid\n   * @throws CryptoError if `context` is not the substrate default\n   */\n  verifyWithContext(signature: Uint8Array, message: Uint8Array, context: Uint8Array): boolean {\n    if (!bytesEqual(context, SR25519_DEFAULT_CONTEXT)) {\n      throw CryptoError.cryptoOperation(\n        \"Sr25519: only the default substrate context is supported by the underlying library\",\n      );\n    }\n    try {\n      return sr25519.verify(message, signature, this._data);\n    } catch {\n      return false;\n    }\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another Sr25519PublicKey.\n   */\n  equals(other: Sr25519PublicKey): 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   * Get string representation.\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `Sr25519PublicKey(${hex.substring(0, 16)}...)`;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Sr25519PrivateKey - Schnorr signatures over Ristretto25519\n *\n * SR25519 is the signature scheme used by Polkadot/Substrate.\n * It is based on Schnorr signatures over the Ristretto group.\n *\n * Key sizes:\n * - Private key (seed): 32 bytes\n * - Public key: 32 bytes\n * - Signature: 64 bytes\n *\n * Note: SR25519 uses the SigningPrivateKey CBOR tag (40021) with discriminator 3.\n *\n * Ported from bc-components-rust/src/sr25519/sr25519_private_key.rs\n */\n\nimport * as sr25519 from \"@scure/sr25519\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport { blake2b } from \"@noble/hashes/blake2.js\";\nimport { Sr25519PublicKey } from \"./sr25519-public-key.js\";\nimport { bytesToHex, bytesEqual } from \"../utils.js\";\nimport { CryptoError } from \"../error.js\";\n\n/** Size of SR25519 private key (seed) in bytes */\nexport const SR25519_PRIVATE_KEY_SIZE = 32;\n\n/** Size of SR25519 public key in bytes */\nexport const SR25519_PUBLIC_KEY_SIZE = 32;\n\n/** Size of SR25519 signature in bytes */\nexport const SR25519_SIGNATURE_SIZE = 64;\n\n/** Default signing context (Substrate/Polkadot compatible) */\nexport const SR25519_DEFAULT_CONTEXT = new TextEncoder().encode(\"substrate\");\n\n/**\n * Sr25519PrivateKey - Private key for Schnorr signatures over Ristretto25519.\n *\n * This is the signature scheme used by Polkadot/Substrate.\n */\nexport class Sr25519PrivateKey {\n  private readonly _seed: Uint8Array;\n  private _cachedPublicKey?: Sr25519PublicKey;\n\n  private constructor(seed: Uint8Array) {\n    if (seed.length !== SR25519_PRIVATE_KEY_SIZE) {\n      throw new Error(\n        `Sr25519PrivateKey seed must be ${SR25519_PRIVATE_KEY_SIZE} bytes, got ${seed.length}`,\n      );\n    }\n    this._seed = new Uint8Array(seed);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new random Sr25519 private key.\n   */\n  static random(): Sr25519PrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return Sr25519PrivateKey.randomUsing(rng);\n  }\n\n  /**\n   * Create a new random Sr25519 private key using the provided RNG.\n   */\n  static randomUsing(rng: RandomNumberGenerator): Sr25519PrivateKey {\n    const seed = rng.randomData(SR25519_PRIVATE_KEY_SIZE);\n    return new Sr25519PrivateKey(seed);\n  }\n\n  /**\n   * Create an Sr25519 private key from a 32-byte seed.\n   */\n  static fromSeed(seed: Uint8Array): Sr25519PrivateKey {\n    return new Sr25519PrivateKey(seed);\n  }\n\n  /**\n   * Create an Sr25519 private key from raw data.\n   * Alias for fromSeed.\n   */\n  static from(data: Uint8Array): Sr25519PrivateKey {\n    return Sr25519PrivateKey.fromSeed(data);\n  }\n\n  /**\n   * Create an Sr25519 private key from a hex string.\n   */\n  static fromHex(hex: string): Sr25519PrivateKey {\n    const matches = hex.match(/.{1,2}/g);\n    if (matches === null) {\n      throw new Error(\"Invalid hex string\");\n    }\n    const data = new Uint8Array(matches.map((byte) => parseInt(byte, 16)));\n    return Sr25519PrivateKey.fromSeed(data);\n  }\n\n  /**\n   * Derive an Sr25519 private key from arbitrary key material using BLAKE2b.\n   *\n   * @param keyMaterial - Arbitrary bytes to derive the key from\n   * @returns A new Sr25519 private key\n   */\n  static deriveFromKeyMaterial(keyMaterial: Uint8Array): Sr25519PrivateKey {\n    // Use BLAKE2b to derive a 32-byte seed from arbitrary key material\n    const seed = blake2b(keyMaterial, { dkLen: SR25519_PRIVATE_KEY_SIZE });\n    return new Sr25519PrivateKey(seed);\n  }\n\n  /**\n   * Generate a keypair and return both private and public keys.\n   *\n   * @returns Tuple of [privateKey, publicKey]\n   */\n  static keypair(): [Sr25519PrivateKey, Sr25519PublicKey] {\n    const privateKey = Sr25519PrivateKey.random();\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Generate a keypair using the provided RNG.\n   *\n   * @param rng - Random number generator\n   * @returns Tuple of [privateKey, publicKey]\n   */\n  static keypairUsing(rng: RandomNumberGenerator): [Sr25519PrivateKey, Sr25519PublicKey] {\n    const privateKey = Sr25519PrivateKey.randomUsing(rng);\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the raw seed bytes.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._seed);\n  }\n\n  /**\n   * Returns the raw seed bytes (alias for toData).\n   */\n  asBytes(): Uint8Array {\n    return this._seed;\n  }\n\n  /**\n   * Returns the hex representation of the seed.\n   */\n  toHex(): string {\n    return bytesToHex(this._seed);\n  }\n\n  /**\n   * Derives the corresponding public key.\n   */\n  publicKey(): Sr25519PublicKey {\n    if (this._cachedPublicKey === undefined) {\n      const secretKey = sr25519.secretFromSeed(this._seed);\n      const pubKeyBytes = sr25519.getPublicKey(secretKey);\n      this._cachedPublicKey = Sr25519PublicKey.from(pubKeyBytes);\n    }\n    return this._cachedPublicKey;\n  }\n\n  /**\n   * Sign a message using the default \"substrate\" context.\n   *\n   * @param message - The message to sign\n   * @returns 64-byte signature\n   */\n  sign(message: Uint8Array): Uint8Array {\n    return this.signWithContext(message, SR25519_DEFAULT_CONTEXT);\n  }\n\n  /**\n   * Sign a message using a custom context.\n   *\n   * The underlying `@scure/sr25519` library hard-codes the `\"substrate\"`\n   * signing context. Calling with any other context byte-slice would\n   * silently produce a non-cross-platform signature, so we fail loudly\n   * instead — callers must use the substrate default until a\n   * context-aware library is wired in.\n   *\n   * @param message - The message to sign\n   * @param context - The signing context (must equal `SR25519_DEFAULT_CONTEXT`)\n   * @returns 64-byte signature\n   * @throws CryptoError if `context` is not the substrate default\n   */\n  signWithContext(message: Uint8Array, context: Uint8Array): Uint8Array {\n    if (!bytesEqual(context, SR25519_DEFAULT_CONTEXT)) {\n      throw CryptoError.cryptoOperation(\n        \"Sr25519: only the default substrate context is supported by the underlying library\",\n      );\n    }\n    const secretKey = sr25519.secretFromSeed(this._seed);\n    return sr25519.sign(secretKey, message);\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another Sr25519PrivateKey.\n   */\n  equals(other: Sr25519PrivateKey): boolean {\n    if (this._seed.length !== other._seed.length) return false;\n    for (let i = 0; i < this._seed.length; i++) {\n      if (this._seed[i] !== other._seed[i]) return false;\n    }\n    return true;\n  }\n\n  /**\n   * Get string representation (truncated for security).\n   */\n  toString(): string {\n    const hex = bytesToHex(this._seed);\n    return `Sr25519PrivateKey(${hex.substring(0, 8)}...)`;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * EC uncompressed public key for ECDSA (secp256k1, 65 bytes)\n *\n * An `ECUncompressedPublicKey` is a 65-byte uncompressed representation of a\n * public key on the secp256k1 curve. The first byte is 0x04 (uncompressed prefix),\n * followed by the 32-byte x-coordinate and 32-byte y-coordinate.\n *\n * While compressed public keys (33 bytes) are preferred for space efficiency,\n * uncompressed keys are sometimes needed for compatibility with legacy systems.\n *\n * # CBOR Serialization\n *\n * `ECUncompressedPublicKey` is serialized to CBOR with tags 40306 (or legacy 306).\n *\n * The format is a map:\n * ```\n * #6.40306({\n *   3: h'<65-byte-uncompressed-public-key>' // key data\n * })\n * ```\n *\n * Ported from bc-components-rust/src/ec_key/ec_uncompressed_public_key.rs\n */\n\nimport { ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE, ecdsaCompressPublicKey } from \"@bcts/crypto\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  expectMap,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { EC_KEY as TAG_EC_KEY, EC_KEY_V1 as TAG_EC_KEY_V1 } from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\nimport type { ECKeyBase } from \"./ec-key-base.js\";\n\nexport class ECUncompressedPublicKey\n  implements\n    ECKeyBase,\n    CborTaggedEncodable,\n    CborTaggedDecodable<ECUncompressedPublicKey>,\n    UREncodable\n{\n  static readonly KEY_SIZE = ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Restore an ECUncompressedPublicKey from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): ECUncompressedPublicKey {\n    return new ECUncompressedPublicKey(new Uint8Array(data));\n  }\n\n  /**\n   * Restore an ECUncompressedPublicKey from a reference to an array of bytes.\n   * Validates the length.\n   */\n  static fromDataRef(data: Uint8Array): ECUncompressedPublicKey {\n    if (data.length !== ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE, data.length);\n    }\n    return ECUncompressedPublicKey.fromData(data);\n  }\n\n  /**\n   * Create an ECUncompressedPublicKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): ECUncompressedPublicKey {\n    return ECUncompressedPublicKey.fromData(data);\n  }\n\n  /**\n   * Restore an ECUncompressedPublicKey from a hex string.\n   */\n  static fromHex(hex: string): ECUncompressedPublicKey {\n    return ECUncompressedPublicKey.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw public key bytes (copy).\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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   * Convert to compressed public key format.\n   * Note: Returns the compressed bytes. To get ECPublicKey, use the ec-public-key module.\n   */\n  compressedData(): Uint8Array {\n    return ecdsaCompressPublicKey(this._data);\n  }\n\n  /**\n   * Compare with another ECUncompressedPublicKey.\n   */\n  equals(other: ECUncompressedPublicKey): 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   * Get string representation.\n   */\n  toString(): string {\n    return `ECUncompressedPublicKey(${this.toHex().substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with ECUncompressedPublicKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_EC_KEY.value, TAG_EC_KEY_V1.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: { 3: h'<65-byte-key>' }\n   */\n  untaggedCbor(): Cbor {\n    const map = new Map<number, unknown>();\n    map.set(3, toByteString(this._data));\n    return cbor(map);\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 an ECUncompressedPublicKey by decoding it from untagged CBOR.\n   *\n   * Format: { 3: h'<65-byte-key>' }\n   */\n  fromUntaggedCbor(cborValue: Cbor): ECUncompressedPublicKey {\n    const map = expectMap(cborValue);\n\n    // Check that key 2 is not present (would indicate private key)\n    const isPrivate = map.get<number, boolean>(2);\n    if (isPrivate === true) {\n      throw new Error(\"Expected ECUncompressedPublicKey but found private key\");\n    }\n\n    // Get key data from key 3\n    // CborMap.extract() returns native types (Uint8Array for byte strings)\n    const keyData = map.extract<number, Uint8Array>(3);\n    if (keyData === undefined || keyData.length === 0) {\n      throw new Error(\"ECUncompressedPublicKey CBOR must have key 3 (data)\");\n    }\n\n    return ECUncompressedPublicKey.fromDataRef(keyData);\n  }\n\n  /**\n   * Creates an ECUncompressedPublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): ECUncompressedPublicKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): ECUncompressedPublicKey {\n    const dummy = new ECUncompressedPublicKey(new Uint8Array(ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE));\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): ECUncompressedPublicKey {\n    const cborValue = decodeCbor(data);\n    return ECUncompressedPublicKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): ECUncompressedPublicKey {\n    const cborValue = decodeCbor(data);\n    const dummy = new ECUncompressedPublicKey(new Uint8Array(ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the ECUncompressedPublicKey.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    const name = TAG_EC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_EC_KEY.name is undefined\");\n    }\n    return UR.new(name, 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 an ECUncompressedPublicKey from a UR.\n   */\n  static fromUR(ur: UR): ECUncompressedPublicKey {\n    const name = TAG_EC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_EC_KEY.name is undefined\");\n    }\n    ur.checkType(name);\n    const dummy = new ECUncompressedPublicKey(new Uint8Array(ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an ECUncompressedPublicKey from a UR string.\n   */\n  static fromURString(urString: string): ECUncompressedPublicKey {\n    const ur = UR.fromURString(urString);\n    return ECUncompressedPublicKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * EC compressed public key for ECDSA verification (secp256k1, 33 bytes)\n *\n * An `ECPublicKey` is a 33-byte compressed representation of a public key on\n * the secp256k1 curve. The first byte is a prefix (0x02 or 0x03) that\n * indicates the parity of the y-coordinate, followed by the 32-byte\n * x-coordinate.\n *\n * These public keys are used to:\n * - Verify ECDSA signatures\n * - Identify the owner of a private key without revealing the private key\n *\n * # CBOR Serialization\n *\n * `ECPublicKey` is serialized to CBOR with tags 40306 (or legacy 306).\n *\n * The format is a map:\n * ```\n * #6.40306({\n *   3: h'<33-byte-public-key>' // key data (no key 2 means public key)\n * })\n * ```\n *\n * Ported from bc-components-rust/src/ec_key/ec_public_key.rs\n */\n\nimport { ECDSA_PUBLIC_KEY_SIZE, ecdsaVerify, ecdsaDecompressPublicKey } from \"@bcts/crypto\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  expectMap,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { EC_KEY as TAG_EC_KEY, EC_KEY_V1 as TAG_EC_KEY_V1 } from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { ECUncompressedPublicKey } from \"./ec-uncompressed-public-key.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\nimport type { ECPublicKeyBase } from \"./ec-key-base.js\";\n\nexport class ECPublicKey\n  implements ECPublicKeyBase, CborTaggedEncodable, CborTaggedDecodable<ECPublicKey>, UREncodable\n{\n  static readonly KEY_SIZE = ECDSA_PUBLIC_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== ECDSA_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_PUBLIC_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Restore an ECPublicKey from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): ECPublicKey {\n    return new ECPublicKey(new Uint8Array(data));\n  }\n\n  /**\n   * Restore an ECPublicKey from a reference to an array of bytes.\n   * Validates the length.\n   */\n  static fromDataRef(data: Uint8Array): ECPublicKey {\n    if (data.length !== ECDSA_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_PUBLIC_KEY_SIZE, data.length);\n    }\n    return ECPublicKey.fromData(data);\n  }\n\n  /**\n   * Create an ECPublicKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): ECPublicKey {\n    return ECPublicKey.fromData(data);\n  }\n\n  /**\n   * Restore an ECPublicKey from a hex string.\n   */\n  static fromHex(hex: string): ECPublicKey {\n    return ECPublicKey.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw public key bytes (copy).\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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   * Returns the compressed public key (self).\n   *\n   * This method implements the ECKey interface. Since ECPublicKey is already\n   * a compressed public key, this returns itself.\n   */\n  publicKey(): ECPublicKey {\n    return this;\n  }\n\n  /**\n   * Convert this compressed public key to uncompressed format.\n   */\n  uncompressedPublicKey(): ECUncompressedPublicKey {\n    const uncompressed = ecdsaDecompressPublicKey(this._data);\n    return ECUncompressedPublicKey.fromData(uncompressed);\n  }\n\n  /**\n   * Verify an ECDSA signature.\n   *\n   * @param signature - The 64-byte signature to verify\n   * @param message - The message that was signed\n   * @returns true if the signature is valid\n   */\n  verify(signature: Uint8Array, message: Uint8Array): boolean {\n    try {\n      return ecdsaVerify(this._data, signature, message);\n    } catch {\n      return false;\n    }\n  }\n\n  /**\n   * Compare with another ECPublicKey.\n   */\n  equals(other: ECPublicKey): 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   * Get string representation.\n   */\n  toString(): string {\n    return `ECPublicKey(${this.toHex().substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with ECPublicKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_EC_KEY.value, TAG_EC_KEY_V1.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: { 3: h'<33-byte-key>' }\n   * Note: No key 2 indicates this is a public key\n   */\n  untaggedCbor(): Cbor {\n    const map = new Map<number, unknown>();\n    map.set(3, toByteString(this._data));\n    return cbor(map);\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 an ECPublicKey by decoding it from untagged CBOR.\n   *\n   * Format: { 3: h'<33-byte-key>' }\n   */\n  fromUntaggedCbor(cborValue: Cbor): ECPublicKey {\n    const map = expectMap(cborValue);\n\n    // Check that key 2 is not present (would indicate private key)\n    const isPrivate = map.get<number, boolean>(2);\n    if (isPrivate === true) {\n      throw new Error(\"Expected ECPublicKey but found private key (key 2 is true)\");\n    }\n\n    // Get key data from key 3\n    // CborMap.extract() returns native types (Uint8Array for byte strings)\n    const keyData = map.extract<number, Uint8Array>(3);\n    if (keyData === undefined || keyData.length === 0) {\n      throw new Error(\"ECPublicKey CBOR must have key 3 (data)\");\n    }\n\n    return ECPublicKey.fromDataRef(keyData);\n  }\n\n  /**\n   * Creates an ECPublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): ECPublicKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): ECPublicKey {\n    const dummy = new ECPublicKey(new Uint8Array(ECDSA_PUBLIC_KEY_SIZE));\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): ECPublicKey {\n    const cborValue = decodeCbor(data);\n    return ECPublicKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): ECPublicKey {\n    const cborValue = decodeCbor(data);\n    const dummy = new ECPublicKey(new Uint8Array(ECDSA_PUBLIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the ECPublicKey.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    const name = TAG_EC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_EC_KEY.name is undefined\");\n    }\n    return UR.new(name, 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 an ECPublicKey from a UR.\n   */\n  static fromUR(ur: UR): ECPublicKey {\n    const name = TAG_EC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_EC_KEY.name is undefined\");\n    }\n    ur.checkType(name);\n    const dummy = new ECPublicKey(new Uint8Array(ECDSA_PUBLIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an ECPublicKey from a UR string.\n   */\n  static fromURString(urString: string): ECPublicKey {\n    const ur = UR.fromURString(urString);\n    return ECPublicKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Schnorr (x-only) public key for BIP-340 signatures (secp256k1, 32 bytes)\n *\n * A `SchnorrPublicKey` is a 32-byte \"x-only\" public key used with the BIP-340\n * Schnorr signature scheme. Unlike compressed ECDSA public keys (33 bytes)\n * that include a prefix byte indicating the parity of the y-coordinate,\n * Schnorr public keys only contain the x-coordinate of the elliptic curve\n * point.\n *\n * Schnorr signatures offer several advantages over traditional ECDSA\n * signatures:\n * - Linearity: Enables key and signature aggregation\n * - Non-malleability: Prevents third parties from modifying signatures\n * - Smaller size: Signatures are 64 bytes vs 70-72 bytes for ECDSA\n * - Better privacy: Makes different multisig policies indistinguishable\n *\n * Schnorr signatures were introduced to Bitcoin via the Taproot upgrade\n * (BIP-340).\n *\n * Note: SchnorrPublicKey does not have CBOR serialization in the Rust\n * implementation, so we keep it simple here.\n *\n * Ported from bc-components-rust/src/ec_key/schnorr_public_key.rs\n */\n\nimport { SCHNORR_PUBLIC_KEY_SIZE, schnorrVerify } from \"@bcts/crypto\";\nimport { Digest } from \"../digest.js\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\nimport type { ECKeyBase } from \"./ec-key-base.js\";\n\nexport class SchnorrPublicKey implements ECKeyBase {\n  static readonly KEY_SIZE = SCHNORR_PUBLIC_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== SCHNORR_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(SCHNORR_PUBLIC_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Restore a SchnorrPublicKey from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): SchnorrPublicKey {\n    return new SchnorrPublicKey(new Uint8Array(data));\n  }\n\n  /**\n   * Restore a SchnorrPublicKey from a reference to an array of bytes.\n   * Validates the length.\n   */\n  static fromDataRef(data: Uint8Array): SchnorrPublicKey {\n    if (data.length !== SCHNORR_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(SCHNORR_PUBLIC_KEY_SIZE, data.length);\n    }\n    return SchnorrPublicKey.fromData(data);\n  }\n\n  /**\n   * Create a SchnorrPublicKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): SchnorrPublicKey {\n    return SchnorrPublicKey.fromData(data);\n  }\n\n  /**\n   * Restore a SchnorrPublicKey from a hex string.\n   */\n  static fromHex(hex: string): SchnorrPublicKey {\n    return SchnorrPublicKey.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw public key bytes (copy).\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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   * Verify a Schnorr signature (BIP-340).\n   *\n   * @param signature - The 64-byte signature to verify\n   * @param message - The message that was signed\n   * @returns true if the signature is valid\n   */\n  schnorrVerify(signature: Uint8Array, message: Uint8Array): boolean {\n    try {\n      return schnorrVerify(this._data, signature, message);\n    } catch {\n      return false;\n    }\n  }\n\n  /**\n   * Compare with another SchnorrPublicKey.\n   */\n  equals(other: SchnorrPublicKey): 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   * Get string representation.\n   *\n   * Mirrors Rust `Display for SchnorrPublicKey`\n   * (`bc-components-rust/src/ec_key/schnorr_public_key.rs:116-120`)\n   * — the reference is computed from the **raw 32-byte key data**\n   * (not the tagged-CBOR form): `Reference::from_digest(Digest::from_image(self.data()))`.\n   * `ref_hex_short()` returns the first 8 hex chars of that\n   * reference's binary form (= SHA-256(data)[0..4]).\n   */\n  toString(): string {\n    const digest = Digest.fromImage(this._data);\n    return `SchnorrPublicKey(${digest.shortDescription()})`;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * EC private key for ECDSA and Schnorr signatures (secp256k1, 32 bytes)\n *\n * An `ECPrivateKey` is a 32-byte secret value that can be used to:\n * - Generate its corresponding public key\n * - Sign messages using the ECDSA signature scheme\n * - Sign messages using the Schnorr signature scheme (BIP-340)\n *\n * These keys use the secp256k1 curve, which is the same curve used in Bitcoin\n * and other cryptocurrencies.\n *\n * # CBOR Serialization\n *\n * `ECPrivateKey` is serialized to CBOR with tags 40306 (or legacy 306).\n *\n * The format is a map:\n * ```\n * #6.40306({\n *   2: true,                    // indicates private key\n *   3: h'<32-byte-private-key>' // key data\n * })\n * ```\n *\n * Ported from bc-components-rust/src/ec_key/ec_private_key.rs\n */\n\nimport { SecureRandomNumberGenerator, type RandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  ECDSA_PRIVATE_KEY_SIZE,\n  ecdsaPublicKeyFromPrivateKey,\n  ecdsaDerivePrivateKey,\n  ecdsaSign,\n  schnorrPublicKeyFromPrivateKey,\n  schnorrSign,\n  schnorrSignUsing,\n} from \"@bcts/crypto\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  expectMap,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { EC_KEY as TAG_EC_KEY, EC_KEY_V1 as TAG_EC_KEY_V1 } from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { ECPublicKey } from \"./ec-public-key.js\";\nimport { SchnorrPublicKey } from \"./schnorr-public-key.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\nimport type { ECKey } from \"./ec-key-base.js\";\n\nexport class ECPrivateKey\n  implements ECKey, CborTaggedEncodable, CborTaggedDecodable<ECPrivateKey>, UREncodable\n{\n  static readonly KEY_SIZE = ECDSA_PRIVATE_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n  private _publicKey?: ECPublicKey;\n  private _schnorrPublicKey?: SchnorrPublicKey;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== ECDSA_PRIVATE_KEY_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_PRIVATE_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Generate a new random ECPrivateKey.\n   */\n  static new(): ECPrivateKey {\n    return ECPrivateKey.random();\n  }\n\n  /**\n   * Generate a new random ECPrivateKey.\n   */\n  static random(): ECPrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return ECPrivateKey.newUsing(rng);\n  }\n\n  /**\n   * Generate a new random ECPrivateKey using provided RNG.\n   */\n  static newUsing(rng: RandomNumberGenerator): ECPrivateKey {\n    return new ECPrivateKey(rng.randomData(ECDSA_PRIVATE_KEY_SIZE));\n  }\n\n  /**\n   * Generate a new random ECPrivateKey and corresponding ECPublicKey.\n   */\n  static keypair(): [ECPrivateKey, ECPublicKey] {\n    const privateKey = ECPrivateKey.new();\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Generate a new random ECPrivateKey and corresponding ECPublicKey\n   * using the given random number generator.\n   */\n  static keypairUsing(rng: RandomNumberGenerator): [ECPrivateKey, ECPublicKey] {\n    const privateKey = ECPrivateKey.newUsing(rng);\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Derive an ECPrivateKey from the given key material.\n   *\n   * @param keyMaterial - The key material to derive from\n   * @returns A new ECPrivateKey derived from the key material\n   */\n  static deriveFromKeyMaterial(keyMaterial: Uint8Array): ECPrivateKey {\n    return new ECPrivateKey(ecdsaDerivePrivateKey(keyMaterial));\n  }\n\n  /**\n   * Restore an ECPrivateKey from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): ECPrivateKey {\n    return new ECPrivateKey(new Uint8Array(data));\n  }\n\n  /**\n   * Restore an ECPrivateKey from a reference to an array of bytes.\n   * Validates the length.\n   */\n  static fromDataRef(data: Uint8Array): ECPrivateKey {\n    if (data.length !== ECDSA_PRIVATE_KEY_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_PRIVATE_KEY_SIZE, data.length);\n    }\n    return ECPrivateKey.fromData(data);\n  }\n\n  /**\n   * Create an ECPrivateKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): ECPrivateKey {\n    return ECPrivateKey.fromData(data);\n  }\n\n  /**\n   * Restore an ECPrivateKey from a hex string.\n   */\n  static fromHex(hex: string): ECPrivateKey {\n    return ECPrivateKey.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw private key bytes (copy).\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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 ECPublicKey (compressed) corresponding to this ECPrivateKey.\n   */\n  publicKey(): ECPublicKey {\n    if (this._publicKey === undefined) {\n      const publicKeyBytes = ecdsaPublicKeyFromPrivateKey(this._data);\n      this._publicKey = ECPublicKey.fromData(publicKeyBytes);\n    }\n    return this._publicKey;\n  }\n\n  /**\n   * Get the SchnorrPublicKey (x-only) corresponding to this ECPrivateKey.\n   */\n  schnorrPublicKey(): SchnorrPublicKey {\n    if (this._schnorrPublicKey === undefined) {\n      const publicKeyBytes = schnorrPublicKeyFromPrivateKey(this._data);\n      this._schnorrPublicKey = SchnorrPublicKey.fromData(publicKeyBytes);\n    }\n    return this._schnorrPublicKey;\n  }\n\n  /**\n   * Sign a message using ECDSA.\n   *\n   * @param message - The message to sign\n   * @returns A 64-byte signature\n   */\n  ecdsaSign(message: Uint8Array): Uint8Array {\n    try {\n      return ecdsaSign(this._data, message);\n    } catch (e) {\n      throw CryptoError.cryptoOperation(`ECDSA signing failed: ${String(e)}`);\n    }\n  }\n\n  /**\n   * Sign a message using Schnorr signature (BIP-340).\n   *\n   * @param message - The message to sign\n   * @returns A 64-byte signature\n   */\n  schnorrSign(message: Uint8Array): Uint8Array {\n    try {\n      return schnorrSign(this._data, message);\n    } catch (e) {\n      throw CryptoError.cryptoOperation(`Schnorr signing failed: ${String(e)}`);\n    }\n  }\n\n  /**\n   * Sign a message using Schnorr signature with custom RNG.\n   *\n   * @param message - The message to sign\n   * @param rng - Random number generator for auxiliary randomness\n   * @returns A 64-byte signature\n   */\n  schnorrSignUsing(message: Uint8Array, rng: RandomNumberGenerator): Uint8Array {\n    try {\n      return schnorrSignUsing(this._data, message, rng);\n    } catch (e) {\n      throw CryptoError.cryptoOperation(`Schnorr signing failed: ${String(e)}`);\n    }\n  }\n\n  /**\n   * Compare with another ECPrivateKey.\n   */\n  equals(other: ECPrivateKey): 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   * Get string representation.\n   */\n  toString(): string {\n    return `ECPrivateKey(${this.toHex().substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with ECPrivateKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_EC_KEY.value, TAG_EC_KEY_V1.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: { 2: true, 3: h'<32-byte-key>' }\n   */\n  untaggedCbor(): Cbor {\n    const map = new Map<number, unknown>();\n    map.set(2, true);\n    map.set(3, toByteString(this._data));\n    return cbor(map);\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 an ECPrivateKey by decoding it from untagged CBOR.\n   *\n   * Format: { 2: true, 3: h'<32-byte-key>' }\n   */\n  fromUntaggedCbor(cborValue: Cbor): ECPrivateKey {\n    const map = expectMap(cborValue);\n\n    // Check for key 2 (isPrivate = true)\n    const isPrivate = map.get<number, boolean>(2);\n    if (isPrivate !== true) {\n      throw new Error(\"ECPrivateKey CBOR must have key 2 set to true\");\n    }\n\n    // Get key data from key 3\n    // CborMap.extract() returns native types (Uint8Array for byte strings)\n    const keyData = map.extract<number, Uint8Array>(3);\n    if (keyData === undefined || keyData.length === 0) {\n      throw new Error(\"ECPrivateKey CBOR must have key 3 (data)\");\n    }\n\n    return ECPrivateKey.fromDataRef(keyData);\n  }\n\n  /**\n   * Creates an ECPrivateKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): ECPrivateKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): ECPrivateKey {\n    const dummy = new ECPrivateKey(new Uint8Array(ECDSA_PRIVATE_KEY_SIZE));\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): ECPrivateKey {\n    const cborValue = decodeCbor(data);\n    return ECPrivateKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): ECPrivateKey {\n    const cborValue = decodeCbor(data);\n    const dummy = new ECPrivateKey(new Uint8Array(ECDSA_PRIVATE_KEY_SIZE));\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the ECPrivateKey.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    const name = TAG_EC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_EC_KEY.name is undefined\");\n    }\n    return UR.new(name, 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 an ECPrivateKey from a UR.\n   */\n  static fromUR(ur: UR): ECPrivateKey {\n    const name = TAG_EC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_EC_KEY.name is undefined\");\n    }\n    ur.checkType(name);\n    const dummy = new ECPrivateKey(new Uint8Array(ECDSA_PRIVATE_KEY_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an ECPrivateKey from a UR string.\n   */\n  static fromURString(urString: string): ECPrivateKey {\n    const ur = UR.fromURString(urString);\n    return ECPrivateKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLDSA Security Level - ML-DSA (Module-Lattice-Based Digital Signature Algorithm)\n *\n * ML-DSA is a post-quantum digital signature algorithm standardized by NIST.\n * It provides three security levels corresponding to different NIST security categories.\n *\n * Security levels:\n * - MLDSA44: NIST Level 2 (equivalent to AES-128)\n * - MLDSA65: NIST Level 3 (equivalent to AES-192)\n * - MLDSA87: NIST Level 5 (equivalent to AES-256)\n *\n * Ported from bc-components-rust/src/mldsa/mldsa_level.rs\n *\n * Naming note: Rust calls this enum `MLDSA`. TypeScript uses `MLDSALevel`\n * to avoid colliding with the keypair type names (`MLDSAPrivateKey` /\n * `MLDSAPublicKey` / `MLDSASignature`). The CBOR discriminator (the\n * numeric level) is identical in both languages — this is a TS-only\n * naming choice with no wire-format effect.\n */\n\nimport { ml_dsa44, ml_dsa65, ml_dsa87 } from \"@noble/post-quantum/ml-dsa.js\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\n\n/**\n * ML-DSA security levels.\n *\n * The numeric values correspond to NIST security levels:\n * - 2: NIST Level 2 (MLDSA44)\n * - 3: NIST Level 3 (MLDSA65)\n * - 5: NIST Level 5 (MLDSA87)\n */\nexport enum MLDSALevel {\n  /** NIST Level 2 - AES-128 equivalent security */\n  MLDSA44 = 2,\n  /** NIST Level 3 - AES-192 equivalent security */\n  MLDSA65 = 3,\n  /** NIST Level 5 - AES-256 equivalent security */\n  MLDSA87 = 5,\n}\n\n/**\n * Key sizes for each ML-DSA security level.\n */\nexport const MLDSA_KEY_SIZES = {\n  [MLDSALevel.MLDSA44]: {\n    privateKey: 2560,\n    publicKey: 1312,\n    signature: 2420,\n  },\n  [MLDSALevel.MLDSA65]: {\n    privateKey: 4032,\n    publicKey: 1952,\n    signature: 3309,\n  },\n  [MLDSALevel.MLDSA87]: {\n    privateKey: 4896,\n    publicKey: 2592,\n    signature: 4627,\n  },\n} as const;\n\n/**\n * Get the private key size for a given ML-DSA level.\n */\nexport function mldsaPrivateKeySize(level: MLDSALevel): number {\n  return MLDSA_KEY_SIZES[level].privateKey;\n}\n\n/**\n * Get the public key size for a given ML-DSA level.\n */\nexport function mldsaPublicKeySize(level: MLDSALevel): number {\n  return MLDSA_KEY_SIZES[level].publicKey;\n}\n\n/**\n * Get the signature size for a given ML-DSA level.\n */\nexport function mldsaSignatureSize(level: MLDSALevel): number {\n  return MLDSA_KEY_SIZES[level].signature;\n}\n\n/**\n * Convert an ML-DSA level to its string representation.\n */\nexport function mldsaLevelToString(level: MLDSALevel): string {\n  switch (level) {\n    case MLDSALevel.MLDSA44:\n      return \"MLDSA44\";\n    case MLDSALevel.MLDSA65:\n      return \"MLDSA65\";\n    case MLDSALevel.MLDSA87:\n      return \"MLDSA87\";\n  }\n}\n\n/**\n * Parse an ML-DSA level from its numeric value.\n */\nexport function mldsaLevelFromValue(value: number): MLDSALevel {\n  switch (value) {\n    case 2:\n      return MLDSALevel.MLDSA44;\n    case 3:\n      return MLDSALevel.MLDSA65;\n    case 5:\n      return MLDSALevel.MLDSA87;\n    default:\n      throw new Error(`Invalid MLDSA level value: ${value}`);\n  }\n}\n\n/**\n * Internal type for ML-DSA keypair generation result.\n */\nexport interface MLDSAKeypairData {\n  publicKey: Uint8Array;\n  secretKey: Uint8Array;\n}\n\n/**\n * Generate an ML-DSA keypair for the given security level.\n *\n * @param level - The ML-DSA security level\n * @returns Object containing publicKey and secretKey bytes\n */\nexport function mldsaGenerateKeypair(level: MLDSALevel): MLDSAKeypairData {\n  const rng = new SecureRandomNumberGenerator();\n  return mldsaGenerateKeypairUsing(level, rng);\n}\n\n/**\n * Generate an ML-DSA keypair using a provided RNG.\n *\n * @param level - The ML-DSA security level\n * @param rng - Random number generator\n * @returns Object containing publicKey and secretKey bytes\n */\nexport function mldsaGenerateKeypairUsing(\n  level: MLDSALevel,\n  rng: RandomNumberGenerator,\n): MLDSAKeypairData {\n  // Generate random seed for keypair generation\n  const seed = rng.randomData(32);\n\n  switch (level) {\n    case MLDSALevel.MLDSA44: {\n      const keypair = ml_dsa44.keygen(seed);\n      return { publicKey: keypair.publicKey, secretKey: keypair.secretKey };\n    }\n    case MLDSALevel.MLDSA65: {\n      const keypair = ml_dsa65.keygen(seed);\n      return { publicKey: keypair.publicKey, secretKey: keypair.secretKey };\n    }\n    case MLDSALevel.MLDSA87: {\n      const keypair = ml_dsa87.keygen(seed);\n      return { publicKey: keypair.publicKey, secretKey: keypair.secretKey };\n    }\n  }\n}\n\n/**\n * Sign a message using ML-DSA.\n *\n * @param level - The ML-DSA security level\n * @param secretKey - The secret key bytes\n * @param message - The message to sign\n * @returns The signature bytes\n */\nexport function mldsaSign(\n  level: MLDSALevel,\n  secretKey: Uint8Array,\n  message: Uint8Array,\n): Uint8Array {\n  switch (level) {\n    case MLDSALevel.MLDSA44:\n      return ml_dsa44.sign(message, secretKey);\n    case MLDSALevel.MLDSA65:\n      return ml_dsa65.sign(message, secretKey);\n    case MLDSALevel.MLDSA87:\n      return ml_dsa87.sign(message, secretKey);\n  }\n}\n\n/**\n * Verify a signature using ML-DSA.\n *\n * @param level - The ML-DSA security level\n * @param publicKey - The public key bytes\n * @param message - The message that was signed\n * @param signature - The signature to verify\n * @returns True if the signature is valid\n */\nexport function mldsaVerify(\n  level: MLDSALevel,\n  publicKey: Uint8Array,\n  message: Uint8Array,\n  signature: Uint8Array,\n): boolean {\n  try {\n    switch (level) {\n      case MLDSALevel.MLDSA44:\n        return ml_dsa44.verify(signature, message, publicKey);\n      case MLDSALevel.MLDSA65:\n        return ml_dsa65.verify(signature, message, publicKey);\n      case MLDSALevel.MLDSA87:\n        return ml_dsa87.verify(signature, message, publicKey);\n    }\n  } catch {\n    return false;\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLDSAPublicKey - ML-DSA Public Key for post-quantum signature verification\n *\n * MLDSAPublicKey wraps an ML-DSA public key for verifying signatures.\n * It supports all three security levels (MLDSA44, MLDSA65, MLDSA87).\n *\n * # CBOR Serialization\n *\n * MLDSAPublicKey is serialized with tag 40104:\n * ```\n * #6.40104([level, h'<public-key-bytes>'])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `mldsa-public-key`\n *\n * Ported from bc-components-rust/src/mldsa/mldsa_public_key.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  expectInteger,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { MLDSA_PUBLIC_KEY as TAG_MLDSA_PUBLIC_KEY } from \"@bcts/tags\";\n\nimport {\n  MLDSALevel,\n  mldsaLevelFromValue,\n  mldsaLevelToString,\n  mldsaPublicKeySize,\n  mldsaVerify,\n} from \"./mldsa-level.js\";\nimport type { MLDSASignature } from \"./mldsa-signature.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * MLDSAPublicKey - Post-quantum signature verification key using ML-DSA.\n */\nexport class MLDSAPublicKey\n  implements CborTaggedEncodable, CborTaggedDecodable<MLDSAPublicKey>, UREncodable\n{\n  private readonly _level: MLDSALevel;\n  private readonly _data: Uint8Array;\n\n  private constructor(level: MLDSALevel, data: Uint8Array) {\n    const expectedSize = mldsaPublicKeySize(level);\n    if (data.length !== expectedSize) {\n      throw new Error(\n        `MLDSAPublicKey (${mldsaLevelToString(level)}) must be ${expectedSize} bytes, got ${data.length}`,\n      );\n    }\n    this._level = level;\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an MLDSAPublicKey from raw bytes.\n   *\n   * @param level - The ML-DSA security level\n   * @param data - The public key bytes\n   */\n  static fromBytes(level: MLDSALevel, data: Uint8Array): MLDSAPublicKey {\n    return new MLDSAPublicKey(level, data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the security level of this key.\n   */\n  level(): MLDSALevel {\n    return this._level;\n  }\n\n  /**\n   * Returns the raw key bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw key bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the size of the key in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  /**\n   * Verify a signature against a message.\n   *\n   * @param signature - The ML-DSA signature to verify\n   * @param message - The message that was signed\n   * @returns True if the signature is valid\n   */\n  verify(signature: MLDSASignature, message: Uint8Array): boolean {\n    if (signature.level() !== this._level) {\n      return false;\n    }\n    return mldsaVerify(this._level, this._data, message, signature.asBytes());\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another MLDSAPublicKey.\n   */\n  equals(other: MLDSAPublicKey): boolean {\n    if (this._level !== other._level) return false;\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   * Get string representation.\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `MLDSAPublicKey(${mldsaLevelToString(this._level)}, ${hex.substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with MLDSAPublicKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_MLDSA_PUBLIC_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [level, key_bytes]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._level, 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 an MLDSAPublicKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): MLDSAPublicKey {\n    const elements = expectArray(cborValue);\n    if (elements.length !== 2) {\n      throw new Error(`MLDSAPublicKey CBOR must have 2 elements, got ${elements.length}`);\n    }\n    const levelValue = Number(expectInteger(elements[0]));\n    const level = mldsaLevelFromValue(levelValue);\n    const data = expectBytes(elements[1]);\n    return MLDSAPublicKey.fromBytes(level, data);\n  }\n\n  /**\n   * Creates an MLDSAPublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): MLDSAPublicKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): MLDSAPublicKey {\n    // Create a minimal dummy instance for decoding\n    const dummyData = new Uint8Array(mldsaPublicKeySize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSAPublicKey(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): MLDSAPublicKey {\n    const cborValue = decodeCbor(data);\n    return MLDSAPublicKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): MLDSAPublicKey {\n    const cborValue = decodeCbor(data);\n    const dummyData = new Uint8Array(mldsaPublicKeySize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSAPublicKey(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_MLDSA_PUBLIC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"MLDSA_PUBLIC_KEY tag name is undefined\");\n    }\n    return UR.new(name, 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 an MLDSAPublicKey from a UR.\n   */\n  static fromUR(ur: UR): MLDSAPublicKey {\n    if (ur.urTypeStr() !== TAG_MLDSA_PUBLIC_KEY.name) {\n      throw new Error(`Expected UR type ${TAG_MLDSA_PUBLIC_KEY.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummyData = new Uint8Array(mldsaPublicKeySize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSAPublicKey(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an MLDSAPublicKey from a UR string.\n   */\n  static fromURString(urString: string): MLDSAPublicKey {\n    const ur = UR.fromURString(urString);\n    return MLDSAPublicKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLDSASignature - ML-DSA Digital Signature\n *\n * MLDSASignature wraps an ML-DSA signature for serialization and verification.\n * It supports all three security levels (MLDSA44, MLDSA65, MLDSA87).\n *\n * # CBOR Serialization\n *\n * MLDSASignature is serialized with tag 40105:\n * ```\n * #6.40105([level, h'<signature-bytes>'])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `mldsa-signature`\n *\n * Ported from bc-components-rust/src/mldsa/mldsa_signature.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  expectInteger,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { MLDSA_SIGNATURE as TAG_MLDSA_SIGNATURE } from \"@bcts/tags\";\n\nimport {\n  MLDSALevel,\n  mldsaLevelFromValue,\n  mldsaLevelToString,\n  mldsaSignatureSize,\n} from \"./mldsa-level.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * MLDSASignature - Post-quantum digital signature using ML-DSA.\n */\nexport class MLDSASignature\n  implements CborTaggedEncodable, CborTaggedDecodable<MLDSASignature>, UREncodable\n{\n  private readonly _level: MLDSALevel;\n  private readonly _data: Uint8Array;\n\n  private constructor(level: MLDSALevel, data: Uint8Array) {\n    const expectedSize = mldsaSignatureSize(level);\n    if (data.length !== expectedSize) {\n      throw new Error(\n        `MLDSASignature (${mldsaLevelToString(level)}) must be ${expectedSize} bytes, got ${data.length}`,\n      );\n    }\n    this._level = level;\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an MLDSASignature from raw bytes.\n   *\n   * @param level - The ML-DSA security level\n   * @param data - The signature bytes\n   */\n  static fromBytes(level: MLDSALevel, data: Uint8Array): MLDSASignature {\n    return new MLDSASignature(level, data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the security level of this signature.\n   */\n  level(): MLDSALevel {\n    return this._level;\n  }\n\n  /**\n   * Returns the raw signature bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw signature bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the size of the signature in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another MLDSASignature.\n   */\n  equals(other: MLDSASignature): boolean {\n    if (this._level !== other._level) return false;\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   * Get string representation.\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `MLDSASignature(${mldsaLevelToString(this._level)}, ${hex.substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with MLDSASignature.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_MLDSA_SIGNATURE.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [level, signature_bytes]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._level, 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 an MLDSASignature by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): MLDSASignature {\n    const elements = expectArray(cborValue);\n    if (elements.length !== 2) {\n      throw new Error(`MLDSASignature CBOR must have 2 elements, got ${elements.length}`);\n    }\n    const levelValue = Number(expectInteger(elements[0]));\n    const level = mldsaLevelFromValue(levelValue);\n    const data = expectBytes(elements[1]);\n    return MLDSASignature.fromBytes(level, data);\n  }\n\n  /**\n   * Creates an MLDSASignature by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): MLDSASignature {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): MLDSASignature {\n    // Create a minimal dummy instance for decoding\n    const dummyData = new Uint8Array(mldsaSignatureSize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSASignature(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): MLDSASignature {\n    const cborValue = decodeCbor(data);\n    return MLDSASignature.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): MLDSASignature {\n    const cborValue = decodeCbor(data);\n    const dummyData = new Uint8Array(mldsaSignatureSize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSASignature(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_MLDSA_SIGNATURE.name;\n    if (name === undefined) {\n      throw new Error(\"MLDSA_SIGNATURE tag name is undefined\");\n    }\n    return UR.new(name, 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 an MLDSASignature from a UR.\n   */\n  static fromUR(ur: UR): MLDSASignature {\n    if (ur.urTypeStr() !== TAG_MLDSA_SIGNATURE.name) {\n      throw new Error(`Expected UR type ${TAG_MLDSA_SIGNATURE.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummyData = new Uint8Array(mldsaSignatureSize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSASignature(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an MLDSASignature from a UR string.\n   */\n  static fromURString(urString: string): MLDSASignature {\n    const ur = UR.fromURString(urString);\n    return MLDSASignature.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLDSAPrivateKey - ML-DSA Private Key for post-quantum digital signatures\n *\n * MLDSAPrivateKey wraps an ML-DSA secret key for signing messages.\n * It supports all three security levels (MLDSA44, MLDSA65, MLDSA87).\n *\n * # CBOR Serialization\n *\n * MLDSAPrivateKey is serialized with tag 40103:\n * ```\n * #6.40103([level, h'<private-key-bytes>'])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `mldsa-private-key`\n *\n * Ported from bc-components-rust/src/mldsa/mldsa_private_key.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  expectInteger,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { MLDSA_PRIVATE_KEY as TAG_MLDSA_PRIVATE_KEY } from \"@bcts/tags\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\n\nimport {\n  MLDSALevel,\n  mldsaLevelFromValue,\n  mldsaLevelToString,\n  mldsaPrivateKeySize,\n  mldsaGenerateKeypairUsing,\n  mldsaSign,\n} from \"./mldsa-level.js\";\nimport { MLDSAPublicKey } from \"./mldsa-public-key.js\";\nimport { MLDSASignature } from \"./mldsa-signature.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * MLDSAPrivateKey - Post-quantum signing private key using ML-DSA.\n */\nexport class MLDSAPrivateKey\n  implements CborTaggedEncodable, CborTaggedDecodable<MLDSAPrivateKey>, UREncodable\n{\n  private readonly _level: MLDSALevel;\n  private readonly _data: Uint8Array;\n\n  private constructor(level: MLDSALevel, data: Uint8Array) {\n    const expectedSize = mldsaPrivateKeySize(level);\n    if (data.length !== expectedSize) {\n      throw new Error(\n        `MLDSAPrivateKey (${mldsaLevelToString(level)}) must be ${expectedSize} bytes, got ${data.length}`,\n      );\n    }\n    this._level = level;\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Generate a new random MLDSAPrivateKey with the specified security level.\n   *\n   * @param level - The ML-DSA security level (default: MLDSA65)\n   */\n  static new(level: MLDSALevel = MLDSALevel.MLDSA65): MLDSAPrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return MLDSAPrivateKey.newUsing(level, rng);\n  }\n\n  /**\n   * Generate a new random MLDSAPrivateKey using the provided RNG.\n   *\n   * @param level - The ML-DSA security level\n   * @param rng - Random number generator\n   */\n  static newUsing(level: MLDSALevel, rng: RandomNumberGenerator): MLDSAPrivateKey {\n    const keypair = mldsaGenerateKeypairUsing(level, rng);\n    return new MLDSAPrivateKey(level, keypair.secretKey);\n  }\n\n  /**\n   * Create an MLDSAPrivateKey from raw bytes.\n   *\n   * @param level - The ML-DSA security level\n   * @param data - The private key bytes\n   */\n  static fromBytes(level: MLDSALevel, data: Uint8Array): MLDSAPrivateKey {\n    return new MLDSAPrivateKey(level, data);\n  }\n\n  /**\n   * Generate a keypair and return both private and public keys.\n   *\n   * @param level - The ML-DSA security level (default: MLDSA65)\n   * @returns Tuple of [privateKey, publicKey]\n   */\n  static keypair(level: MLDSALevel = MLDSALevel.MLDSA65): [MLDSAPrivateKey, MLDSAPublicKey] {\n    const rng = new SecureRandomNumberGenerator();\n    return MLDSAPrivateKey.keypairUsing(level, rng);\n  }\n\n  /**\n   * Generate a keypair using the provided RNG.\n   *\n   * @param level - The ML-DSA security level\n   * @param rng - Random number generator\n   * @returns Tuple of [privateKey, publicKey]\n   */\n  static keypairUsing(\n    level: MLDSALevel,\n    rng: RandomNumberGenerator,\n  ): [MLDSAPrivateKey, MLDSAPublicKey] {\n    const keypairData = mldsaGenerateKeypairUsing(level, rng);\n    const privateKey = new MLDSAPrivateKey(level, keypairData.secretKey);\n    const publicKey = MLDSAPublicKey.fromBytes(level, keypairData.publicKey);\n    return [privateKey, publicKey];\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the security level of this key.\n   */\n  level(): MLDSALevel {\n    return this._level;\n  }\n\n  /**\n   * Returns the raw key bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw key bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the size of the key in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  /**\n   * Sign a message with this private key.\n   *\n   * @param message - The message to sign\n   * @returns The ML-DSA signature\n   */\n  sign(message: Uint8Array): MLDSASignature {\n    const sigBytes = mldsaSign(this._level, this._data, message);\n    return MLDSASignature.fromBytes(this._level, sigBytes);\n  }\n\n  /**\n   * Derive the public key from this private key.\n   *\n   * Note: ML-DSA doesn't have a direct derivation method, so we need to\n   * regenerate the keypair from seed. For now, we extract from the secret key\n   * structure (the public key is embedded in the secret key for ML-DSA).\n   */\n  publicKey(): MLDSAPublicKey {\n    // In ML-DSA, the public key can be extracted from the secret key\n    // The noble library stores (secretKey, publicKey) concatenated\n    // For MLDSA44: secretKey = 2560 bytes, publicKey = 1312 bytes\n    // For MLDSA65: secretKey = 4032 bytes, publicKey = 1952 bytes\n    // For MLDSA87: secretKey = 4896 bytes, publicKey = 2592 bytes\n\n    // Actually, noble stores them separately in keygen(), and the secret key\n    // doesn't contain the public key. We need to regenerate or cache.\n    // For simplicity, we'll generate a new keypair with the same seed.\n    // But we don't have the seed... This is a limitation.\n\n    // The solution is to either:\n    // 1. Store the public key alongside the private key\n    // 2. Re-generate from seed (but we don't have it)\n    // 3. Use a deterministic derivation\n\n    // For now, we'll throw an error and require users to use keypair() instead.\n    // This matches the Rust implementation where public_key() uses the internal\n    // key structure which may have the public key embedded.\n\n    // Actually, looking at the noble implementation, we can't easily extract\n    // the public key. The keypair generation is what produces both.\n    // So we need to either:\n    // a) Store both keys together\n    // b) Require users to keep track of both\n\n    // For MVP, we'll throw an error suggesting to use keypair()\n    throw new Error(\n      \"MLDSAPrivateKey.publicKey() is not supported. Use MLDSAPrivateKey.keypair() to generate both keys together.\",\n    );\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another MLDSAPrivateKey.\n   */\n  equals(other: MLDSAPrivateKey): boolean {\n    if (this._level !== other._level) return false;\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   * Get string representation (truncated for security).\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `MLDSAPrivateKey(${mldsaLevelToString(this._level)}, ${hex.substring(0, 8)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with MLDSAPrivateKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_MLDSA_PRIVATE_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [level, key_bytes]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._level, 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 an MLDSAPrivateKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): MLDSAPrivateKey {\n    const elements = expectArray(cborValue);\n    if (elements.length !== 2) {\n      throw new Error(`MLDSAPrivateKey CBOR must have 2 elements, got ${elements.length}`);\n    }\n    const levelValue = Number(expectInteger(elements[0]));\n    const level = mldsaLevelFromValue(levelValue);\n    const data = expectBytes(elements[1]);\n    return MLDSAPrivateKey.fromBytes(level, data);\n  }\n\n  /**\n   * Creates an MLDSAPrivateKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): MLDSAPrivateKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): MLDSAPrivateKey {\n    // Create a minimal dummy instance for decoding\n    const dummyData = new Uint8Array(mldsaPrivateKeySize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSAPrivateKey(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): MLDSAPrivateKey {\n    const cborValue = decodeCbor(data);\n    return MLDSAPrivateKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): MLDSAPrivateKey {\n    const cborValue = decodeCbor(data);\n    const dummyData = new Uint8Array(mldsaPrivateKeySize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSAPrivateKey(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_MLDSA_PRIVATE_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"MLDSA_PRIVATE_KEY tag name is undefined\");\n    }\n    return UR.new(name, 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 an MLDSAPrivateKey from a UR.\n   */\n  static fromUR(ur: UR): MLDSAPrivateKey {\n    if (ur.urTypeStr() !== TAG_MLDSA_PRIVATE_KEY.name) {\n      throw new Error(`Expected UR type ${TAG_MLDSA_PRIVATE_KEY.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummyData = new Uint8Array(mldsaPrivateKeySize(MLDSALevel.MLDSA44));\n    const dummy = new MLDSAPrivateKey(MLDSALevel.MLDSA44, dummyData);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an MLDSAPrivateKey from a UR string.\n   */\n  static fromURString(urString: string): MLDSAPrivateKey {\n    const ur = UR.fromURString(urString);\n    return MLDSAPrivateKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * RFC 4251/4253 length-prefixed wire format primitives used by every OpenSSH\n * binary blob (key bodies, signature blobs, SSHSIG, etc.).\n *\n * Mirrors what Rust's `ssh-encoding` crate (transitive dep of `ssh-key`)\n * produces byte-for-byte, so encodes here round-trip with bytes Rust emits.\n *\n * Spec references:\n *  - RFC 4251 §5  (data types: byte, boolean, uint32, uint64, string, mpint,\n *    name-list)\n *  - RFC 4253 §6.6 (key/signature framing uses the same primitives)\n */\nconst MAX_UINT32 = 0xffffffff;\n\nexport class SshBufferReader {\n  private readonly view: DataView;\n  private offset: number;\n\n  constructor(public readonly bytes: Uint8Array) {\n    this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n    this.offset = 0;\n  }\n\n  position(): number {\n    return this.offset;\n  }\n\n  remaining(): number {\n    return this.bytes.length - this.offset;\n  }\n\n  isAtEnd(): boolean {\n    return this.offset >= this.bytes.length;\n  }\n\n  private requireBytes(n: number, what: string): void {\n    if (this.offset + n > this.bytes.length) {\n      throw new Error(\n        `SshBuffer: not enough bytes for ${what} (need ${n}, have ${this.bytes.length - this.offset})`,\n      );\n    }\n  }\n\n  readByte(): number {\n    this.requireBytes(1, \"byte\");\n    return this.bytes[this.offset++];\n  }\n\n  readBoolean(): boolean {\n    return this.readByte() !== 0;\n  }\n\n  readUint32(): number {\n    this.requireBytes(4, \"uint32\");\n    const v = this.view.getUint32(this.offset, false);\n    this.offset += 4;\n    return v;\n  }\n\n  /** Read a length-prefixed string as raw bytes (no UTF-8 decoding). */\n  readString(): Uint8Array {\n    const len = this.readUint32();\n    this.requireBytes(len, \"string body\");\n    const start = this.bytes.byteOffset + this.offset;\n    const slice = new Uint8Array(this.bytes.buffer.slice(start, start + len));\n    this.offset += len;\n    return slice;\n  }\n\n  /** Read a length-prefixed string as UTF-8 text. */\n  readStringUtf8(): string {\n    return new TextDecoder(\"utf-8\", { fatal: true }).decode(this.readString());\n  }\n\n  /**\n   * Read an `mpint` (RFC 4251 §5) — two's-complement big-endian integer with\n   * optional 0x00 sign byte. We surface the raw bytes verbatim so callers can\n   * decide how to strip the sign byte for unsigned coordinate values.\n   */\n  readMpint(): Uint8Array {\n    return this.readString();\n  }\n\n  /** Read a name-list (RFC 4251 §5) — a string of comma-separated US-ASCII names. */\n  readNameList(): string[] {\n    const text = this.readStringUtf8();\n    return text.length === 0 ? [] : text.split(\",\");\n  }\n}\n\nexport class SshBufferWriter {\n  private readonly chunks: Uint8Array[] = [];\n  private size = 0;\n\n  writeByte(b: number): this {\n    if (b < 0 || b > 0xff || !Number.isInteger(b)) {\n      throw new Error(`SshBuffer: byte out of range: ${b}`);\n    }\n    const buf = new Uint8Array(1);\n    buf[0] = b;\n    this.chunks.push(buf);\n    this.size += 1;\n    return this;\n  }\n\n  writeBoolean(v: boolean): this {\n    return this.writeByte(v ? 1 : 0);\n  }\n\n  writeUint32(v: number): this {\n    if (v < 0 || v > MAX_UINT32 || !Number.isInteger(v)) {\n      throw new Error(`SshBuffer: uint32 out of range: ${v}`);\n    }\n    const buf = new Uint8Array(4);\n    new DataView(buf.buffer).setUint32(0, v, false);\n    this.chunks.push(buf);\n    this.size += 4;\n    return this;\n  }\n\n  /** Write a length-prefixed byte string. */\n  writeString(bytes: Uint8Array): this {\n    this.writeUint32(bytes.length);\n    this.chunks.push(bytes);\n    this.size += bytes.length;\n    return this;\n  }\n\n  /** Write a length-prefixed UTF-8 string. */\n  writeStringUtf8(text: string): this {\n    return this.writeString(new TextEncoder().encode(text));\n  }\n\n  /**\n   * Write an `mpint` (RFC 4251 §5).\n   *\n   * Two's complement big-endian. For *positive* values (which is all we\n   * handle — EC coordinates, SSH public-key parameters), if the most\n   * significant byte has the high bit set, a leading 0x00 must be added so\n   * the value is not interpreted as negative. Leading zeros are otherwise\n   * stripped. Zero is encoded as an empty string (length 0).\n   */\n  writeMpintUnsigned(bytes: Uint8Array): this {\n    let start = 0;\n    while (start < bytes.length && bytes[start] === 0) start++;\n    if (start === bytes.length) {\n      // value is zero\n      return this.writeString(new Uint8Array(0));\n    }\n    const head = bytes[start];\n    const needsSignByte = (head & 0x80) !== 0;\n    const len = bytes.length - start + (needsSignByte ? 1 : 0);\n    const out = new Uint8Array(len);\n    if (needsSignByte) {\n      out[0] = 0x00;\n      out.set(bytes.subarray(start), 1);\n    } else {\n      out.set(bytes.subarray(start), 0);\n    }\n    return this.writeString(out);\n  }\n\n  writeNameList(names: string[]): this {\n    return this.writeStringUtf8(names.join(\",\"));\n  }\n\n  /** Append a raw blob without length-prefixing it. */\n  writeRaw(bytes: Uint8Array): this {\n    this.chunks.push(bytes);\n    this.size += bytes.length;\n    return this;\n  }\n\n  bytes(): Uint8Array {\n    const out = new Uint8Array(this.size);\n    let pos = 0;\n    for (const chunk of this.chunks) {\n      out.set(chunk, pos);\n      pos += chunk.length;\n    }\n    return out;\n  }\n}\n\n/**\n * Strip an optional leading 0x00 sign byte from an unsigned mpint.\n *\n * RFC 4251 §5 mpints are two's-complement, so positive values whose\n * MSB is set carry a leading 0x00. EC curve coordinate bytes never need\n * the sign byte once stripped.\n */\nexport function stripMpintSignByte(bytes: Uint8Array): Uint8Array {\n  if (bytes.length > 0 && bytes[0] === 0x00) {\n    return bytes.subarray(1);\n  }\n  return bytes;\n}\n\n/**\n * Pad an unsigned big-endian byte sequence to an exact length, throwing\n * if the input is longer than `len`. Used for fixed-width EC coordinates.\n */\nexport function padLeftToLength(bytes: Uint8Array, len: number): Uint8Array {\n  if (bytes.length === len) return bytes;\n  if (bytes.length > len) {\n    throw new Error(`padLeftToLength: input ${bytes.length} > target ${len}`);\n  }\n  const out = new Uint8Array(len);\n  out.set(bytes, len - bytes.length);\n  return out;\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * Minimal PEM (RFC 7468 §3) reader/writer with the byte-shape conventions\n * used by Rust `ssh-key` 0.6.7:\n *\n *   - Wrap base64 at **70 columns** for OpenSSH private keys\n *     (`pem-rfc7468` default for that format).\n *   - Wrap base64 at **76 columns** for SSHSIG (`PROTOCOL.sshsig` rubric).\n *   - LF newlines (matches `LineEnding::LF`, which is the rubric used for\n *     all parity fixtures in `bc-components-rust/src/lib.rs`).\n *   - Trailing newline after the END line.\n */\n\nimport { base64 } from \"@scure/base\";\n\nconst BEGIN = \"-----BEGIN \";\nconst END = \"-----END \";\nconst SUFFIX = \"-----\";\n\nexport interface PemBlock {\n  label: string;\n  data: Uint8Array;\n}\n\n/**\n * Parse a single PEM block. Tolerant of CRLF, trailing whitespace, leading\n * whitespace lines and `Proc-Type` / `DEK-Info` headers (the SSHSIG/OpenSSH\n * formats don't use those, but we ignore them to be robust).\n */\nexport function parsePem(text: string, expectedLabel?: string): PemBlock {\n  const lines = text.split(/\\r?\\n/);\n  let i = 0;\n  while (i < lines.length && lines[i].trim() === \"\") i++;\n  if (i >= lines.length) {\n    throw new Error(\"PEM: empty input\");\n  }\n  const beginLine = lines[i];\n  if (!beginLine.startsWith(BEGIN) || !beginLine.endsWith(SUFFIX)) {\n    throw new Error(`PEM: expected '-----BEGIN <label>-----' header, got '${beginLine}'`);\n  }\n  const label = beginLine.slice(BEGIN.length, beginLine.length - SUFFIX.length);\n  if (expectedLabel !== undefined && label !== expectedLabel) {\n    throw new Error(`PEM: expected label '${expectedLabel}', got '${label}'`);\n  }\n  i++;\n  // Skip any RFC 1421 headers (`Key:` lines before the blank-line separator).\n  while (i < lines.length && /^[A-Za-z][A-Za-z0-9-]*:/.test(lines[i].trim())) {\n    i++;\n  }\n  if (i < lines.length && lines[i].trim() === \"\") i++;\n\n  const bodyLines: string[] = [];\n  let endLine: string | undefined;\n  for (; i < lines.length; i++) {\n    const line = lines[i];\n    if (line.startsWith(END)) {\n      endLine = line;\n      break;\n    }\n    bodyLines.push(line);\n  }\n  if (endLine === undefined) {\n    throw new Error(\"PEM: missing '-----END <label>-----' footer\");\n  }\n  if (!endLine.endsWith(SUFFIX)) {\n    throw new Error(`PEM: malformed END line '${endLine}'`);\n  }\n  const endLabel = endLine.slice(END.length, endLine.length - SUFFIX.length);\n  if (endLabel !== label) {\n    throw new Error(`PEM: BEGIN/END label mismatch ('${label}' vs '${endLabel}')`);\n  }\n\n  const body = bodyLines.join(\"\").replace(/\\s+/g, \"\");\n  return { label, data: base64.decode(body) };\n}\n\n/**\n * Encode a PEM block. `width` is the base64 column width (70 for OpenSSH\n * private keys; 76 for SSHSIG signatures). Trailing newline is included\n * to match the Rust fixtures.\n */\nexport function encodePem(label: string, data: Uint8Array, width: number): string {\n  const b64 = base64.encode(data);\n  const lines: string[] = [];\n  lines.push(`${BEGIN}${label}${SUFFIX}`);\n  for (let i = 0; i < b64.length; i += width) {\n    lines.push(b64.slice(i, i + width));\n  }\n  lines.push(`${END}${label}${SUFFIX}`);\n  return `${lines.join(\"\\n\")}\\n`;\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * SSH-DSA digital signature algorithm (FIPS 186-4 §4) with RFC 6979\n * deterministic k generation.\n *\n * Mirrors the Rust `dsa` crate (RustCrypto, used by `ssh-key` 0.6.7) so\n * signatures are byte-identical given the same key + message + hash.\n *\n * Used only for SSH-DSA (`ssh-dss`):\n *   - q is 160 bits\n *   - hash is SHA-1 (also used as HMAC hash for RFC 6979)\n *   - signature is fixed 40 bytes: r (20) || s (20)\n *\n * Note: DSA with q=160 / SHA-1 is cryptographically deprecated. We\n * support it only for parity with Rust's `bc-components-rust` SSH\n * keygen path, which itself is feature-gated and primarily used in\n * legacy-interop tests. Do NOT use this module for new keys.\n */\n\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport { hmac } from \"@noble/hashes/hmac.js\";\n\n// ----------------------------------------------------------------------------\n// Modular-arithmetic helpers (BigInt — not constant-time, matches Rust `dsa`)\n// ----------------------------------------------------------------------------\n\nfunction modpow(base: bigint, exp: bigint, mod: bigint): bigint {\n  if (mod === 1n) return 0n;\n  let result = 1n;\n  let b = base % mod;\n  if (b < 0n) b += mod;\n  let e = exp;\n  while (e > 0n) {\n    if ((e & 1n) !== 0n) result = (result * b) % mod;\n    e >>= 1n;\n    b = (b * b) % mod;\n  }\n  return result;\n}\n\nfunction modinv(a: bigint, m: bigint): bigint {\n  // Extended Euclidean. Assumes gcd(a, m) = 1.\n  let oldR = ((a % m) + m) % m;\n  let r = m;\n  let oldS = 1n;\n  let s = 0n;\n  while (r !== 0n) {\n    const q = oldR / r;\n    [oldR, r] = [r, oldR - q * r];\n    [oldS, s] = [s, oldS - q * s];\n  }\n  if (oldR !== 1n) {\n    throw new Error(\"dsa: modular inverse does not exist\");\n  }\n  return ((oldS % m) + m) % m;\n}\n\nfunction bytesToBigint(bytes: Uint8Array): bigint {\n  let v = 0n;\n  for (const b of bytes) v = (v << 8n) | BigInt(b);\n  return v;\n}\n\nfunction bigintToBytesFixed(v: bigint, len: number): Uint8Array {\n  const out = new Uint8Array(len);\n  let n = v;\n  for (let i = len - 1; i >= 0; i--) {\n    out[i] = Number(n & 0xffn);\n    n >>= 8n;\n  }\n  if (n !== 0n) {\n    throw new Error(`dsa: integer does not fit in ${len} bytes`);\n  }\n  return out;\n}\n\nfunction concatBytes(...arrs: Uint8Array[]): Uint8Array {\n  let total = 0;\n  for (const a of arrs) total += a.length;\n  const out = new Uint8Array(total);\n  let pos = 0;\n  for (const a of arrs) {\n    out.set(a, pos);\n    pos += a.length;\n  }\n  return out;\n}\n\n// ----------------------------------------------------------------------------\n// RFC 6979 §3.2 — deterministic k generation\n// ----------------------------------------------------------------------------\n\n/**\n * `bits2int` per RFC 6979 §2.3.2: interpret the input bits as a big-endian\n * integer, truncating the rightmost bits if the bit length exceeds qlen.\n */\nfunction bits2int(input: Uint8Array, qlenBits: number): bigint {\n  let v = bytesToBigint(input);\n  const inputBits = input.length * 8;\n  if (inputBits > qlenBits) {\n    v >>= BigInt(inputBits - qlenBits);\n  }\n  return v;\n}\n\n/**\n * `int2octets` per RFC 6979 §2.3.3: integer → fixed-length bytes (qlen/8).\n */\nfunction int2octets(v: bigint, rolen: number): Uint8Array {\n  return bigintToBytesFixed(v, rolen);\n}\n\n/**\n * `bits2octets` per RFC 6979 §2.3.4: bits2int reduced mod q, then int2octets.\n */\nfunction bits2octets(input: Uint8Array, q: bigint, qlenBits: number, rolen: number): Uint8Array {\n  const z1 = bits2int(input, qlenBits);\n  let z2 = z1 - q;\n  if (z2 < 0n) z2 = z1;\n  return int2octets(z2 % q, rolen);\n}\n\n/**\n * Derive a deterministic per-signature nonce `k` per RFC 6979 §3.2 using\n * HMAC-SHA-1 (the hash paired with DSA-1024/q-160).\n */\nfunction rfc6979Nonce(q: bigint, x: Uint8Array, hashedMessage: Uint8Array): bigint {\n  const qlenBits = q.toString(2).length;\n  const rolen = Math.ceil(qlenBits / 8);\n  const hlen = 20; // SHA-1 output length\n\n  const xOct = int2octets(bytesToBigint(x), rolen);\n  const h1Oct = bits2octets(hashedMessage, q, qlenBits, rolen);\n\n  // Step a-b: V = 0x01..., K = 0x00...\n  let V = new Uint8Array(hlen).fill(0x01);\n  let K = new Uint8Array(hlen).fill(0x00);\n\n  // Step c: K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1))\n  K = hmac(sha1, K, concatBytes(V, new Uint8Array([0x00]), xOct, h1Oct));\n  // Step d: V = HMAC_K(V)\n  V = hmac(sha1, K, V);\n  // Step e: K = HMAC_K(V || 0x01 || int2octets(x) || bits2octets(h1))\n  K = hmac(sha1, K, concatBytes(V, new Uint8Array([0x01]), xOct, h1Oct));\n  // Step f: V = HMAC_K(V)\n  V = hmac(sha1, K, V);\n\n  // Step g: loop until a valid k is found\n  for (let iter = 0; iter < 1024; iter++) {\n    let T: Uint8Array = new Uint8Array(0);\n    while (T.length < rolen) {\n      V = hmac(sha1, K, V);\n      T = concatBytes(T, V);\n    }\n    const k = bits2int(T, qlenBits);\n    if (k >= 1n && k < q) return k;\n    K = hmac(sha1, K, concatBytes(V, new Uint8Array([0x00])));\n    V = hmac(sha1, K, V);\n  }\n  throw new Error(\"dsa: RFC 6979 failed to produce a valid k after 1024 iterations\");\n}\n\n// ----------------------------------------------------------------------------\n// Public API\n// ----------------------------------------------------------------------------\n\nexport interface DsaPublicParams {\n  p: Uint8Array;\n  q: Uint8Array;\n  g: Uint8Array;\n  y: Uint8Array;\n}\n\nexport interface DsaSignParams extends DsaPublicParams {\n  /** Private exponent (canonical positive bytes, no sign byte). */\n  x: Uint8Array;\n  /** Hash digest of the message (SHA-1 for SSH-DSA). */\n  messageDigest: Uint8Array;\n}\n\nexport interface DsaVerifyParams extends DsaPublicParams {\n  messageDigest: Uint8Array;\n  /** 40-byte signature (r || s), each 20 bytes for q=160. */\n  signature: Uint8Array;\n}\n\n/**\n * Sign `messageDigest` with the DSA private key, returning a fixed-length\n * `r || s` signature. Uses RFC 6979 deterministic `k` so signatures match\n * Rust's `dsa` crate byte-for-byte.\n *\n * Output length is `2 * (qlen / 8)` = 40 bytes for SSH-DSA-1024.\n */\nexport function dsaSign(params: DsaSignParams): Uint8Array {\n  const p = bytesToBigint(params.p);\n  const q = bytesToBigint(params.q);\n  const g = bytesToBigint(params.g);\n  const x = bytesToBigint(params.x);\n  const qlenBits = q.toString(2).length;\n  const rolen = Math.ceil(qlenBits / 8);\n\n  // Loop in case (r, s) hits the (rare) degenerate case where r=0 or s=0.\n  // RFC 6979 §3.2 defines the next-k recovery as continuing the HMAC\n  // chain — but for q=160 + SHA-1 the probability of this is ~2^-160, so\n  // we treat it as fatal here (matching Rust `dsa` crate behaviour).\n  const k = rfc6979Nonce(q, params.x, params.messageDigest);\n  const r = modpow(g, k, p) % q;\n  if (r === 0n) {\n    throw new Error(\"dsa: degenerate signature with r=0\");\n  }\n  const z = bits2int(params.messageDigest, qlenBits);\n  const kInv = modinv(k, q);\n  const s = (kInv * (z + x * r)) % q;\n  if (s === 0n) {\n    throw new Error(\"dsa: degenerate signature with s=0\");\n  }\n\n  const out = new Uint8Array(rolen * 2);\n  out.set(bigintToBytesFixed(r, rolen), 0);\n  out.set(bigintToBytesFixed(s, rolen), rolen);\n  return out;\n}\n\n/**\n * Verify a DSA `r || s` signature against the message digest and public key.\n * Returns `true` iff the signature is valid; never throws on bad input.\n */\nexport function dsaVerify(params: DsaVerifyParams): boolean {\n  try {\n    const p = bytesToBigint(params.p);\n    const q = bytesToBigint(params.q);\n    const g = bytesToBigint(params.g);\n    const y = bytesToBigint(params.y);\n    const qlenBits = q.toString(2).length;\n    const rolen = Math.ceil(qlenBits / 8);\n    if (params.signature.length !== rolen * 2) return false;\n    const r = bytesToBigint(params.signature.subarray(0, rolen));\n    const s = bytesToBigint(params.signature.subarray(rolen));\n    if (r <= 0n || r >= q) return false;\n    if (s <= 0n || s >= q) return false;\n    const w = modinv(s, q);\n    const z = bits2int(params.messageDigest, qlenBits);\n    const u1 = (z * w) % q;\n    const u2 = (r * w) % q;\n    const v = ((modpow(g, u1, p) * modpow(y, u2, p)) % p) % q;\n    return v === r;\n  } catch {\n    return false;\n  }\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * SSH key algorithm identifiers.\n *\n * Mirrors the relevant subset of `ssh_key::Algorithm` (Rust crate\n * `ssh-key` v0.6.7). v1.1 supports the four algorithms `bc-components-rust`\n * actually wires through `SignatureScheme`:\n *\n *   - Ed25519 (`ssh-ed25519`)\n *   - DSA (`ssh-dss`) — 1024-bit p, 160-bit q, SHA-1\n *   - ECDSA P-256 (`ecdsa-sha2-nistp256`) — SHA-256\n *   - ECDSA P-384 (`ecdsa-sha2-nistp384`) — SHA-384\n *\n * Deferred (rust upstream blockers): RSA (commented out in\n * `signature_scheme.rs:80-81`), P-521 (`ssh-key` upstream bug\n * https://github.com/RustCrypto/SSH/issues/232), encrypted private\n * keys, `cert-v01@openssh.com`. See `SSH_PLAN.md` V2.A-V2.D.\n */\n\nexport type SshAlgorithm =\n  { kind: \"ed25519\" } | { kind: \"dsa\" } | { kind: \"ecdsa\"; curve: SshEcdsaCurve };\n\nexport type SshEcdsaCurve = \"nistp256\" | \"nistp384\";\n\n/** Wire-format algorithm name as it appears in OpenSSH text and in the key blob. */\nexport const SSH_ALGO_ED25519 = \"ssh-ed25519\";\nexport const SSH_ALGO_DSA = \"ssh-dss\";\nexport const SSH_ALGO_ECDSA_NISTP256 = \"ecdsa-sha2-nistp256\";\nexport const SSH_ALGO_ECDSA_NISTP384 = \"ecdsa-sha2-nistp384\";\n\n/** OpenSSH curve identifier embedded inside ECDSA key blobs. */\nexport const SSH_CURVE_NISTP256 = \"nistp256\";\nexport const SSH_CURVE_NISTP384 = \"nistp384\";\n\nexport function sshAlgorithmName(algo: SshAlgorithm): string {\n  switch (algo.kind) {\n    case \"ed25519\":\n      return SSH_ALGO_ED25519;\n    case \"dsa\":\n      return SSH_ALGO_DSA;\n    case \"ecdsa\":\n      switch (algo.curve) {\n        case \"nistp256\":\n          return SSH_ALGO_ECDSA_NISTP256;\n        case \"nistp384\":\n          return SSH_ALGO_ECDSA_NISTP384;\n      }\n  }\n}\n\nexport function parseSshAlgorithm(name: string): SshAlgorithm {\n  switch (name) {\n    case SSH_ALGO_ED25519:\n      return { kind: \"ed25519\" };\n    case SSH_ALGO_DSA:\n      return { kind: \"dsa\" };\n    case SSH_ALGO_ECDSA_NISTP256:\n      return { kind: \"ecdsa\", curve: \"nistp256\" };\n    case SSH_ALGO_ECDSA_NISTP384:\n      return { kind: \"ecdsa\", curve: \"nistp384\" };\n    default:\n      throw new Error(\n        `Unsupported SSH algorithm '${name}'. v1.1 supports ${SSH_ALGO_ED25519}, ${SSH_ALGO_DSA}, ${SSH_ALGO_ECDSA_NISTP256}, ${SSH_ALGO_ECDSA_NISTP384} (see SSH_PLAN.md V2 for RSA / P-521).`,\n      );\n  }\n}\n\n/**\n * Wire-format curve name corresponding to a `SshEcdsaCurve`.\n */\nexport function sshCurveName(curve: SshEcdsaCurve): string {\n  switch (curve) {\n    case \"nistp256\":\n      return SSH_CURVE_NISTP256;\n    case \"nistp384\":\n      return SSH_CURVE_NISTP384;\n  }\n}\n\n/**\n * Byte length of an uncompressed SEC1 point (`0x04 || X || Y`) for the curve.\n */\nexport function sshEcdsaPointLen(curve: SshEcdsaCurve): number {\n  switch (curve) {\n    case \"nistp256\":\n      return 65;\n    case \"nistp384\":\n      return 97;\n  }\n}\n\n/**\n * Byte length of the canonical (no sign byte) private scalar for the curve.\n */\nexport function sshEcdsaScalarLen(curve: SshEcdsaCurve): number {\n  switch (curve) {\n    case \"nistp256\":\n      return 32;\n    case \"nistp384\":\n      return 48;\n  }\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * SSH public-key parser/serializer covering Ed25519, DSA, ECDSA P-256,\n * and ECDSA P-384.\n *\n * Mirrors `ssh_key::PublicKey` (crate `ssh-key` v0.6.7) — same OpenSSH\n * single-line text format, same SSH wire-format blob layout (RFC 4253 §6.6),\n * so byte-for-byte round-trips with bytes Rust emits.\n *\n * OpenSSH single-line public key format:\n *\n *     <algorithm> <base64-encoded-blob> [<comment>]\n *\n * Per-algorithm blob layouts (RFC 4253 §6.6 + extensions):\n *\n *   ssh-ed25519:\n *     string  \"ssh-ed25519\"\n *     string  <32-byte raw public key>\n *\n *   ssh-dss:\n *     string  \"ssh-dss\"\n *     mpint   p   (1024-bit prime)\n *     mpint   q   (160-bit prime divisor of p-1)\n *     mpint   g   (generator)\n *     mpint   y   (public)\n *\n *   ecdsa-sha2-nistp256:\n *     string  \"ecdsa-sha2-nistp256\"\n *     string  \"nistp256\"\n *     string  <0x04 || X (32 bytes) || Y (32 bytes)>   (SEC1 uncompressed)\n *\n *   ecdsa-sha2-nistp384:\n *     string  \"ecdsa-sha2-nistp384\"\n *     string  \"nistp384\"\n *     string  <0x04 || X (48 bytes) || Y (48 bytes)>   (SEC1 uncompressed)\n */\n\nimport { base64 } from \"@scure/base\";\nimport { sha256, sha512 } from \"@noble/hashes/sha2.js\";\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { p256, p384 } from \"@noble/curves/nist.js\";\nimport { SshBufferReader, SshBufferWriter } from \"./internal/ssh-buffer.js\";\nimport { dsaVerify } from \"./internal/dsa.js\";\nimport {\n  parseSshAlgorithm,\n  sshAlgorithmName,\n  sshCurveName,\n  sshEcdsaPointLen,\n  type SshAlgorithm,\n  type SshEcdsaCurve,\n} from \"./ssh-algorithm.js\";\n\nconst ED25519_PUBLIC_KEY_LEN = 32;\n\n/**\n * Internal discriminated union for the algorithm-specific public-key data.\n *\n *   - ed25519: the 32-byte raw public key.\n *   - ecdsa:   curve + 65/97-byte SEC1 uncompressed point.\n *   - dsa:     four canonical-positive mpint bytes (p, q, g, y) — sign\n *              byte already stripped on parse, re-added by the writer.\n */\nexport type SshPublicKeyData =\n  | { kind: \"ed25519\"; pubBytes: Uint8Array }\n  | { kind: \"ecdsa\"; curve: SshEcdsaCurve; point: Uint8Array }\n  | { kind: \"dsa\"; p: Uint8Array; q: Uint8Array; g: Uint8Array; y: Uint8Array };\n\nexport class SSHPublicKey {\n  readonly data: SshPublicKeyData;\n  readonly comment: string;\n\n  private constructor(data: SshPublicKeyData, comment: string) {\n    this.data = data;\n    this.comment = comment;\n  }\n\n  /** Algorithm tag for this key. */\n  get algorithm(): SshAlgorithm {\n    const data = this.data;\n    switch (data.kind) {\n      case \"ed25519\":\n        return { kind: \"ed25519\" };\n      case \"dsa\":\n        return { kind: \"dsa\" };\n      case \"ecdsa\":\n        return { kind: \"ecdsa\", curve: data.curve };\n      default: {\n        const _exhaustive: never = data;\n        throw new Error(`SSHPublicKey: unreachable kind ${String(_exhaustive)}`);\n      }\n    }\n  }\n\n  // --------------------------------------------------------------------------\n  // Constructors\n  // --------------------------------------------------------------------------\n\n  static ed25519(keyBytes: Uint8Array, comment = \"\"): SSHPublicKey {\n    if (keyBytes.length !== ED25519_PUBLIC_KEY_LEN) {\n      throw new Error(\n        `SSHPublicKey ed25519: expected ${ED25519_PUBLIC_KEY_LEN} bytes, got ${keyBytes.length}`,\n      );\n    }\n    return new SSHPublicKey({ kind: \"ed25519\", pubBytes: new Uint8Array(keyBytes) }, comment);\n  }\n\n  static ecdsaP256(uncompressedPoint: Uint8Array, comment = \"\"): SSHPublicKey {\n    return SSHPublicKey.ecdsa(\"nistp256\", uncompressedPoint, comment);\n  }\n\n  static ecdsaP384(uncompressedPoint: Uint8Array, comment = \"\"): SSHPublicKey {\n    return SSHPublicKey.ecdsa(\"nistp384\", uncompressedPoint, comment);\n  }\n\n  static ecdsa(curve: SshEcdsaCurve, uncompressedPoint: Uint8Array, comment = \"\"): SSHPublicKey {\n    const expected = sshEcdsaPointLen(curve);\n    if (uncompressedPoint.length !== expected || uncompressedPoint[0] !== 0x04) {\n      throw new Error(\n        `SSHPublicKey ecdsa-${curve}: expected ${expected}-byte uncompressed SEC1 point (0x04 prefix), got ${uncompressedPoint.length} bytes prefix=0x${uncompressedPoint[0]?.toString(16) ?? \"?\"}`,\n      );\n    }\n    return new SSHPublicKey(\n      { kind: \"ecdsa\", curve, point: new Uint8Array(uncompressedPoint) },\n      comment,\n    );\n  }\n\n  /** DSA public key. p/q/g/y must already be canonical positive bytes (no sign byte). */\n  static dsa(\n    p: Uint8Array,\n    q: Uint8Array,\n    g: Uint8Array,\n    y: Uint8Array,\n    comment = \"\",\n  ): SSHPublicKey {\n    return new SSHPublicKey(\n      {\n        kind: \"dsa\",\n        p: new Uint8Array(p),\n        q: new Uint8Array(q),\n        g: new Uint8Array(g),\n        y: new Uint8Array(y),\n      },\n      comment,\n    );\n  }\n\n  /**\n   * Returns a copy of this SSH public key with the comment replaced.\n   *\n   * Mirrors `ssh_key::PublicKey::set_comment` (mutating in Rust; we\n   * return a new instance to keep the type immutable).\n   */\n  withComment(comment: string): SSHPublicKey {\n    return new SSHPublicKey(this.data, comment);\n  }\n\n  // --------------------------------------------------------------------------\n  // OpenSSH text format\n  // --------------------------------------------------------------------------\n\n  static fromOpenssh(text: string): SSHPublicKey {\n    const trimmed = text.trim();\n    if (trimmed.length === 0) {\n      throw new Error(\"SSHPublicKey.fromOpenssh: empty input\");\n    }\n    const firstSpace = trimmed.indexOf(\" \");\n    if (firstSpace < 0) {\n      throw new Error(\n        `SSHPublicKey.fromOpenssh: expected '<algo> <base64> [comment]', got '${trimmed}'`,\n      );\n    }\n    const algoName = trimmed.slice(0, firstSpace);\n    const rest = trimmed.slice(firstSpace + 1);\n\n    const secondSpace = rest.indexOf(\" \");\n    let blobB64: string;\n    let comment: string;\n    if (secondSpace < 0) {\n      blobB64 = rest;\n      comment = \"\";\n    } else {\n      blobB64 = rest.slice(0, secondSpace);\n      comment = rest.slice(secondSpace + 1);\n    }\n\n    parseSshAlgorithm(algoName); // validate early — throws on unsupported\n    const blob = base64.decode(blobB64);\n    const parsed = SSHPublicKey.fromBlob(blob, comment);\n    if (sshAlgorithmName(parsed.algorithm) !== algoName) {\n      throw new Error(\n        `SSHPublicKey.fromOpenssh: outer algorithm '${algoName}' does not match inner '${sshAlgorithmName(parsed.algorithm)}'`,\n      );\n    }\n    return parsed;\n  }\n\n  toOpenssh(): string {\n    const algoName = sshAlgorithmName(this.algorithm);\n    const blobB64 = base64.encode(this.toBlob());\n    return this.comment.length === 0\n      ? `${algoName} ${blobB64}`\n      : `${algoName} ${blobB64} ${this.comment}`;\n  }\n\n  // --------------------------------------------------------------------------\n  // SSH wire-format blob\n  // --------------------------------------------------------------------------\n\n  static fromBlob(blob: Uint8Array, comment = \"\"): SSHPublicKey {\n    const reader = new SshBufferReader(blob);\n    const algoName = decodeUtf8(reader.readString());\n    const algorithm = parseSshAlgorithm(algoName);\n    switch (algorithm.kind) {\n      case \"ed25519\": {\n        const pub = reader.readString();\n        if (!reader.isAtEnd()) {\n          throw new Error(\"SSHPublicKey.fromBlob ed25519: trailing bytes after public key\");\n        }\n        return SSHPublicKey.ed25519(pub, comment);\n      }\n      case \"dsa\": {\n        const p = stripDsaMpint(reader.readMpint());\n        const q = stripDsaMpint(reader.readMpint());\n        const g = stripDsaMpint(reader.readMpint());\n        const y = stripDsaMpint(reader.readMpint());\n        if (!reader.isAtEnd()) {\n          throw new Error(\"SSHPublicKey.fromBlob dsa: trailing bytes after y\");\n        }\n        return SSHPublicKey.dsa(p, q, g, y, comment);\n      }\n      case \"ecdsa\": {\n        const curveName = decodeUtf8(reader.readString());\n        if (curveName !== sshCurveName(algorithm.curve)) {\n          throw new Error(\n            `SSHPublicKey.fromBlob ecdsa: blob curve '${curveName}' does not match algorithm '${sshCurveName(algorithm.curve)}'`,\n          );\n        }\n        const point = reader.readString();\n        if (!reader.isAtEnd()) {\n          throw new Error(\"SSHPublicKey.fromBlob ecdsa: trailing bytes after public point\");\n        }\n        return SSHPublicKey.ecdsa(algorithm.curve, point, comment);\n      }\n    }\n  }\n\n  toBlob(): Uint8Array {\n    const writer = new SshBufferWriter();\n    writer.writeStringUtf8(sshAlgorithmName(this.algorithm));\n    switch (this.data.kind) {\n      case \"ed25519\":\n        writer.writeString(this.data.pubBytes);\n        break;\n      case \"dsa\":\n        writer.writeMpintUnsigned(this.data.p);\n        writer.writeMpintUnsigned(this.data.q);\n        writer.writeMpintUnsigned(this.data.g);\n        writer.writeMpintUnsigned(this.data.y);\n        break;\n      case \"ecdsa\":\n        writer.writeStringUtf8(sshCurveName(this.data.curve));\n        writer.writeString(this.data.point);\n        break;\n    }\n    return writer.bytes();\n  }\n\n  // --------------------------------------------------------------------------\n  // Reference / display\n  // --------------------------------------------------------------------------\n\n  digest(): Uint8Array {\n    return sha256(new TextEncoder().encode(this.toOpenssh()));\n  }\n\n  refHexShort(): string {\n    const d = this.digest();\n    let s = \"\";\n    for (let i = 0; i < 4; i++) s += d[i].toString(16).padStart(2, \"0\");\n    return s;\n  }\n\n  toString(): string {\n    return `SSHPublicKey(${this.refHexShort()})`;\n  }\n\n  equals(other: SSHPublicKey): boolean {\n    return this.toOpenssh() === other.toOpenssh();\n  }\n\n  /**\n   * Comment-insensitive equality: matches when algorithm and key data\n   * agree, ignoring the comment. Used by verify paths since SSH\n   * wire-format pubkey blobs carry the key but not the comment.\n   */\n  keyEquals(other: SSHPublicKey): boolean {\n    return bytesEqual(this.toBlob(), other.toBlob());\n  }\n\n  // --------------------------------------------------------------------------\n  // Legacy accessors retained for backward compatibility / direct callers\n  // --------------------------------------------------------------------------\n\n  /**\n   * Algorithm-specific raw payload bytes. Throws for DSA — DSA needs structured\n   * access via `data.p/q/g/y`.\n   */\n  get keyBytes(): Uint8Array {\n    const data = this.data;\n    switch (data.kind) {\n      case \"ed25519\":\n        return data.pubBytes;\n      case \"ecdsa\":\n        return data.point;\n      case \"dsa\":\n        throw new Error(\n          \"SSHPublicKey.keyBytes is not defined for DSA — use `data.p/q/g/y` instead\",\n        );\n      default: {\n        const _exhaustive: never = data;\n        throw new Error(`SSHPublicKey: unreachable kind ${String(_exhaustive)}`);\n      }\n    }\n  }\n\n  // --------------------------------------------------------------------------\n  // SSHSIG verify (PROTOCOL.sshsig §3.1)\n  // --------------------------------------------------------------------------\n\n  verifySshSignature(\n    namespace: string,\n    message: Uint8Array,\n    signature: {\n      publicKey: SSHPublicKey;\n      namespace: string;\n      hashAlgorithm: \"sha256\" | \"sha512\";\n      signatureBytes: Uint8Array;\n    },\n  ): boolean {\n    if (!this.keyEquals(signature.publicKey)) return false;\n    if (signature.namespace !== namespace) return false;\n    const messageDigest = signature.hashAlgorithm === \"sha256\" ? sha256(message) : sha512(message);\n    const signedData = signedDataBlobInline(namespace, signature.hashAlgorithm, messageDigest);\n    try {\n      switch (this.data.kind) {\n        case \"ed25519\":\n          return ed25519.verify(signature.signatureBytes, signedData, this.data.pubBytes);\n        case \"ecdsa\":\n          switch (this.data.curve) {\n            case \"nistp256\":\n              return p256.verify(signature.signatureBytes, signedData, this.data.point, {\n                format: \"compact\",\n              });\n            case \"nistp384\":\n              return p384.verify(signature.signatureBytes, signedData, this.data.point, {\n                format: \"compact\",\n              });\n          }\n          return false;\n        case \"dsa\": {\n          // SSH-DSA always hashes the signed-data with SHA-1 before signing.\n          const innerDigest = sha1(signedData);\n          return dsaVerify({\n            p: this.data.p,\n            q: this.data.q,\n            g: this.data.g,\n            y: this.data.y,\n            messageDigest: innerDigest,\n            signature: signature.signatureBytes,\n          });\n        }\n      }\n    } catch {\n      return false;\n    }\n  }\n}\n\n// ----------------------------------------------------------------------------\n// Helpers\n// ----------------------------------------------------------------------------\n\nfunction decodeUtf8(bytes: Uint8Array): string {\n  return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n  if (a.length !== b.length) return false;\n  for (let i = 0; i < a.length; i++) {\n    if (a[i] !== b[i]) return false;\n  }\n  return true;\n}\n\n/**\n * Strip the optional 0x00 sign byte from a positive `mpint` and return the\n * canonical (unsigned) bytes. Used for DSA p/q/g/y components.\n */\nfunction stripDsaMpint(mpint: Uint8Array): Uint8Array {\n  if (mpint.length > 0 && mpint[0] === 0x00) {\n    return new Uint8Array(mpint.subarray(1));\n  }\n  return new Uint8Array(mpint);\n}\n\n// Re-create the SSHSIG signed-data layout inline to avoid a circular import\n// from `ssh-signature.ts`. Keep in sync with `SSHSignature.signedDataBlob`.\nconst SSHSIG_MAGIC = new TextEncoder().encode(\"SSHSIG\");\n\nfunction signedDataBlobInline(\n  namespace: string,\n  hashAlg: \"sha256\" | \"sha512\",\n  messageDigest: Uint8Array,\n): Uint8Array {\n  const w = new SshBufferWriter();\n  w.writeRaw(SSHSIG_MAGIC);\n  w.writeStringUtf8(namespace);\n  w.writeString(new Uint8Array(0));\n  w.writeStringUtf8(hashAlg);\n  w.writeString(messageDigest);\n  return w.bytes();\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * SSHSIG (PROTOCOL.sshsig) parser/serializer — the OpenSSH armored\n * signature format used by `ssh-keygen -Y sign`.\n *\n * Mirrors `ssh_key::SshSig` (crate `ssh-key` v0.6.7), so blobs round-trip\n * byte-identically with bytes Rust emits.\n *\n * Outer PEM:\n *\n *     -----BEGIN SSH SIGNATURE-----\n *     <base64, 76-char wrap, LF newlines>\n *     -----END SSH SIGNATURE-----\n *\n * Inner blob (`PROTOCOL.sshsig` §2):\n *\n *     6 bytes \"SSHSIG\" magic\n *     uint32  version          (must be 1)\n *     string  publickey         (SSH wire-format pubkey blob)\n *     string  namespace         (UTF-8)\n *     string  reserved          (currently empty)\n *     string  hash_algorithm    (\"sha256\" | \"sha512\")\n *     string  signature         (algorithm-specific signature blob):\n *\n *   ssh-ed25519 signature blob:\n *     string  algorithm \"ssh-ed25519\"\n *     string  raw 64-byte signature\n *\n *   ecdsa-sha2-nistp256 / ecdsa-sha2-nistp384 signature blob:\n *     string  algorithm \"ecdsa-sha2-nistp256\" | \"ecdsa-sha2-nistp384\"\n *     string  inner-blob:\n *         mpint r\n *         mpint s\n *\n *   ssh-dss signature blob:\n *     string  algorithm \"ssh-dss\"\n *     string  raw 40-byte signature  (r || s, 20 bytes each, q = 160 bits)\n */\n\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { SshBufferReader, SshBufferWriter } from \"./internal/ssh-buffer.js\";\nimport { encodePem, parsePem } from \"./internal/ssh-pem.js\";\nimport {\n  parseSshAlgorithm,\n  sshAlgorithmName,\n  sshEcdsaScalarLen,\n  type SshAlgorithm,\n} from \"./ssh-algorithm.js\";\nimport { SSHPublicKey } from \"./ssh-public-key.js\";\n\nconst PEM_LABEL = \"SSH SIGNATURE\";\nconst PEM_LINE_WIDTH = 76;\nconst MAGIC = new TextEncoder().encode(\"SSHSIG\");\nconst SUPPORTED_VERSION = 1;\nexport type SshHashAlgorithm = \"sha256\" | \"sha512\";\n\nconst ED25519_SIGNATURE_LEN = 64;\nconst DSA_SIGNATURE_LEN = 40; // r (20) || s (20), q = 160 bits\n\nexport class SSHSignature {\n  readonly publicKey: SSHPublicKey;\n  readonly namespace: string;\n  readonly reserved: Uint8Array;\n  readonly hashAlgorithm: SshHashAlgorithm;\n  /**\n   * Raw signature bytes specific to the algorithm:\n   *   ed25519 → 64-byte concatenation `r || s`\n   *   ecdsa-p256 → 64-byte concatenation `r || s` (we strip the SSH\n   *     mpint sign bytes on parse and re-add them on serialize, so this\n   *     stays a fixed 64-byte canonical form internally)\n   */\n  readonly signatureBytes: Uint8Array;\n\n  private constructor(\n    publicKey: SSHPublicKey,\n    namespace: string,\n    reserved: Uint8Array,\n    hashAlgorithm: SshHashAlgorithm,\n    signatureBytes: Uint8Array,\n  ) {\n    this.publicKey = publicKey;\n    this.namespace = namespace;\n    this.reserved = reserved;\n    this.hashAlgorithm = hashAlgorithm;\n    this.signatureBytes = signatureBytes;\n  }\n\n  static fromPem(text: string): SSHSignature {\n    const { data } = parsePem(text, PEM_LABEL);\n    return SSHSignature.fromBlob(data);\n  }\n\n  static fromBlob(blob: Uint8Array): SSHSignature {\n    if (blob.length < MAGIC.length || !bytesEqual(blob.subarray(0, MAGIC.length), MAGIC)) {\n      throw new Error(\"SSHSignature: missing 'SSHSIG' magic\");\n    }\n    const reader = new SshBufferReader(blob.subarray(MAGIC.length));\n    const version = reader.readUint32();\n    if (version !== SUPPORTED_VERSION) {\n      throw new Error(\n        `SSHSignature: unsupported SSHSIG version ${version} (expected ${SUPPORTED_VERSION})`,\n      );\n    }\n    const publicKeyBlob = reader.readString();\n    const publicKey = SSHPublicKey.fromBlob(publicKeyBlob);\n    const namespace = decodeUtf8(reader.readString());\n    const reserved = reader.readString();\n    const hashAlgRaw = decodeUtf8(reader.readString());\n    if (hashAlgRaw !== \"sha256\" && hashAlgRaw !== \"sha512\") {\n      throw new Error(`SSHSignature: unsupported hash algorithm '${hashAlgRaw}'`);\n    }\n    const sigBlob = reader.readString();\n    if (!reader.isAtEnd()) {\n      throw new Error(\"SSHSignature: trailing bytes after signature blob\");\n    }\n    const signatureBytes = decodeAlgorithmSignature(publicKey.algorithm, sigBlob);\n    return new SSHSignature(publicKey, namespace, reserved, hashAlgRaw, signatureBytes);\n  }\n\n  toPem(): string {\n    return encodePem(PEM_LABEL, this.toBlob(), PEM_LINE_WIDTH);\n  }\n\n  toBlob(): Uint8Array {\n    const writer = new SshBufferWriter();\n    writer.writeRaw(MAGIC);\n    writer.writeUint32(SUPPORTED_VERSION);\n    writer.writeString(this.publicKey.toBlob());\n    writer.writeStringUtf8(this.namespace);\n    writer.writeString(this.reserved);\n    writer.writeStringUtf8(this.hashAlgorithm);\n    writer.writeString(encodeAlgorithmSignature(this.publicKey.algorithm, this.signatureBytes));\n    return writer.bytes();\n  }\n\n  /**\n   * Build the message that gets signed/verified: the **signed-data** blob\n   * defined by `PROTOCOL.sshsig` §3.1.\n   *\n   *     \"SSHSIG\" magic\n   *     string  namespace\n   *     string  reserved\n   *     string  hash_algorithm\n   *     string  H(message)        ← *digest*, not the raw message\n   */\n  static signedDataBlob(\n    namespace: string,\n    hashAlgorithm: SshHashAlgorithm,\n    messageDigest: Uint8Array,\n  ): Uint8Array {\n    const w = new SshBufferWriter();\n    w.writeRaw(MAGIC);\n    w.writeStringUtf8(namespace);\n    w.writeString(new Uint8Array(0));\n    w.writeStringUtf8(hashAlgorithm);\n    w.writeString(messageDigest);\n    return w.bytes();\n  }\n\n  /** Construct from already-decoded parts (used by Phase 7 sign path). */\n  static fromParts(\n    publicKey: SSHPublicKey,\n    namespace: string,\n    hashAlgorithm: SshHashAlgorithm,\n    signatureBytes: Uint8Array,\n  ): SSHSignature {\n    return new SSHSignature(\n      publicKey,\n      namespace,\n      new Uint8Array(0),\n      hashAlgorithm,\n      new Uint8Array(signatureBytes),\n    );\n  }\n\n  /** Fixed-string mirror of Rust summarizer for `TAG_SSH_TEXT_SIGNATURE`. */\n  toString(): string {\n    return \"SSHSignature\";\n  }\n\n  /** SHA-256 digest of canonical PEM bytes — kept for parity with key types. */\n  digest(): Uint8Array {\n    return sha256(new TextEncoder().encode(this.toPem()));\n  }\n}\n\n// ---- helpers ---------------------------------------------------------------\n\nfunction decodeUtf8(bytes: Uint8Array): string {\n  return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n  if (a.length !== b.length) return false;\n  for (let i = 0; i < a.length; i++) {\n    if (a[i] !== b[i]) return false;\n  }\n  return true;\n}\n\n/**\n * Strip the algorithm wrapping from a signature blob and return the raw\n * algorithm-specific bytes (concatenation form):\n *   ed25519 → 64 bytes raw\n *   ecdsa   → `r || s`, fixed-width per curve (32 for P-256, 48 for P-384)\n *   dsa     → 40 bytes raw `r || s` (q = 160 bits)\n */\nfunction decodeAlgorithmSignature(algorithm: SshAlgorithm, sigBlob: Uint8Array): Uint8Array {\n  const r = new SshBufferReader(sigBlob);\n  const algoName = decodeUtf8(r.readString());\n  const expected = sshAlgorithmName(algorithm);\n  if (algoName !== expected) {\n    throw new Error(\n      `SSHSignature: signature algorithm '${algoName}' does not match key algorithm '${expected}'`,\n    );\n  }\n  switch (algorithm.kind) {\n    case \"ed25519\": {\n      const sig = r.readString();\n      if (!r.isAtEnd()) {\n        throw new Error(\"SSHSignature ed25519: trailing bytes after raw signature\");\n      }\n      if (sig.length !== ED25519_SIGNATURE_LEN) {\n        throw new Error(\n          `SSHSignature ed25519: expected ${ED25519_SIGNATURE_LEN}-byte signature, got ${sig.length}`,\n        );\n      }\n      return new Uint8Array(sig);\n    }\n    case \"ecdsa\": {\n      const inner = r.readString();\n      if (!r.isAtEnd()) {\n        throw new Error(\"SSHSignature ecdsa: trailing bytes after inner signature blob\");\n      }\n      const innerR = new SshBufferReader(inner);\n      const scalarLen = sshEcdsaScalarLen(algorithm.curve);\n      const rBytes = stripAndPad(innerR.readMpint(), scalarLen, \"ecdsa\");\n      const sBytes = stripAndPad(innerR.readMpint(), scalarLen, \"ecdsa\");\n      if (!innerR.isAtEnd()) {\n        throw new Error(\"SSHSignature ecdsa: trailing bytes after r,s\");\n      }\n      const out = new Uint8Array(scalarLen * 2);\n      out.set(rBytes, 0);\n      out.set(sBytes, scalarLen);\n      return out;\n    }\n    case \"dsa\": {\n      const sig = r.readString();\n      if (!r.isAtEnd()) {\n        throw new Error(\"SSHSignature dsa: trailing bytes after raw signature\");\n      }\n      if (sig.length !== DSA_SIGNATURE_LEN) {\n        throw new Error(\n          `SSHSignature dsa: expected ${DSA_SIGNATURE_LEN}-byte signature, got ${sig.length}`,\n        );\n      }\n      return new Uint8Array(sig);\n    }\n  }\n}\n\nfunction encodeAlgorithmSignature(algorithm: SshAlgorithm, signatureBytes: Uint8Array): Uint8Array {\n  const w = new SshBufferWriter();\n  w.writeStringUtf8(sshAlgorithmName(algorithm));\n  switch (algorithm.kind) {\n    case \"ed25519\": {\n      if (signatureBytes.length !== ED25519_SIGNATURE_LEN) {\n        throw new Error(\n          `SSHSignature ed25519: signatureBytes length ${signatureBytes.length} != ${ED25519_SIGNATURE_LEN}`,\n        );\n      }\n      w.writeString(signatureBytes);\n      break;\n    }\n    case \"ecdsa\": {\n      const scalarLen = sshEcdsaScalarLen(algorithm.curve);\n      const expectedLen = scalarLen * 2;\n      if (signatureBytes.length !== expectedLen) {\n        throw new Error(\n          `SSHSignature ecdsa: signatureBytes length ${signatureBytes.length} != ${expectedLen} (r||s)`,\n        );\n      }\n      const inner = new SshBufferWriter();\n      inner.writeMpintUnsigned(signatureBytes.subarray(0, scalarLen));\n      inner.writeMpintUnsigned(signatureBytes.subarray(scalarLen));\n      w.writeString(inner.bytes());\n      break;\n    }\n    case \"dsa\": {\n      if (signatureBytes.length !== DSA_SIGNATURE_LEN) {\n        throw new Error(\n          `SSHSignature dsa: signatureBytes length ${signatureBytes.length} != ${DSA_SIGNATURE_LEN} (r||s)`,\n        );\n      }\n      w.writeString(signatureBytes);\n      break;\n    }\n  }\n  return w.bytes();\n}\n\nfunction stripAndPad(mpint: Uint8Array, len: number, label: string): Uint8Array {\n  // EC signature components (r, s) are < curve order, so they fit in `len` bytes.\n  const stripped = mpint[0] === 0x00 ? mpint.subarray(1) : mpint;\n  if (stripped.length > len) {\n    throw new Error(`SSHSignature ${label}: r/s component too large (${stripped.length} bytes)`);\n  }\n  if (stripped.length === len) return new Uint8Array(stripped);\n  const out = new Uint8Array(len);\n  out.set(stripped, len - stripped.length);\n  return out;\n}\n\n// `parseSshAlgorithm` is exported by ssh-algorithm.js; we re-export here so that\n// callers wanting to feed raw algorithm strings into SSHSignature builders can\n// import a single module. (Kept as a re-export to avoid a long import path.)\nexport { parseSshAlgorithm };\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * SSH private-key parser/serializer for the OpenSSH binary key format\n * (`-----BEGIN OPENSSH PRIVATE KEY-----`), spec: PROTOCOL.key in\n * https://github.com/openssh/openssh-portable.\n *\n * Mirrors `ssh_key::PrivateKey` (crate `ssh-key` v0.6.7) byte-for-byte for\n * unencrypted Ed25519, DSA, ECDSA P-256, and ECDSA P-384 keys. Encrypted\n * keys (bcrypt-pbkdf + AES-256-CTR), RSA, and P-521 are deferred to v2 —\n * see `SSH_PLAN.md` V2.A-V2.D.\n *\n * Wire-format summary (after base64-decoding the PEM body):\n *\n *     \"openssh-key-v1\\0\"                  (15 bytes magic)\n *     string  ciphername                  (must be \"none\" in v1)\n *     string  kdfname                     (must be \"none\" in v1)\n *     string  kdfoptions                  (empty when ciphername = \"none\")\n *     uint32  nkeys                       (must be 1 in v1)\n *     string  publickey-blob              (`SSHPublicKey.toBlob` payload)\n *     string  encrypted-section:\n *                 uint32  checkint\n *                 uint32  checkint        (must equal first checkint)\n *                 algorithm-specific keypair fields\n *                 string  comment\n *                 padding 0x01, 0x02, ... up to 8-byte block boundary\n *\n *   ed25519 keypair fields:\n *     string  algorithm  (\"ssh-ed25519\")\n *     string  public_key (32 bytes)\n *     string  private_key (64 bytes — seed (32) || public (32))\n *\n *   ecdsa-sha2-nistp{256,384} keypair fields:\n *     string  algorithm  (\"ecdsa-sha2-nistp{256,384}\")\n *     string  curve      (\"nistp{256,384}\")\n *     string  public_point (65 / 97 bytes — 0x04 || X || Y)\n *     mpint   private_scalar (canonical: 32/48 bytes, with 0x00 sign byte if MSB set)\n *\n *   ssh-dss keypair fields:\n *     string  algorithm  (\"ssh-dss\")\n *     mpint   p (re-stated)\n *     mpint   q (re-stated)\n *     mpint   g (re-stated)\n *     mpint   y (re-stated)\n *     mpint   x (private)\n */\n\nimport { sha256, sha512 } from \"@noble/hashes/sha2.js\";\nimport { sha1 } from \"@noble/hashes/legacy.js\";\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { p256, p384 } from \"@noble/curves/nist.js\";\nimport {\n  SshBufferReader,\n  SshBufferWriter,\n  stripMpintSignByte,\n  padLeftToLength,\n} from \"./internal/ssh-buffer.js\";\nimport { encodePem, parsePem } from \"./internal/ssh-pem.js\";\nimport { dsaSign } from \"./internal/dsa.js\";\nimport {\n  parseSshAlgorithm,\n  sshAlgorithmName,\n  sshCurveName,\n  sshEcdsaPointLen,\n  sshEcdsaScalarLen,\n  type SshAlgorithm,\n  type SshEcdsaCurve,\n} from \"./ssh-algorithm.js\";\nimport { SSHPublicKey } from \"./ssh-public-key.js\";\nimport { SSHSignature, type SshHashAlgorithm } from \"./ssh-signature.js\";\n\nconst PEM_LABEL = \"OPENSSH PRIVATE KEY\";\nconst PEM_LINE_WIDTH = 70;\nconst MAGIC = new TextEncoder().encode(\"openssh-key-v1\\0\");\nconst CIPHER_NONE = \"none\";\nconst KDF_NONE = \"none\";\nconst NKEYS = 1;\nconst BLOCK_SIZE_NONE = 8;\nconst ED25519_SEED_LEN = 32;\nconst ED25519_PUBLIC_LEN = 32;\n\n/**\n * Algorithm-specific private-key data.\n *\n *   - ed25519: 32-byte seed.\n *   - ecdsa:   curve + canonical scalar (32 / 48 bytes, no sign byte).\n *   - dsa:     canonical positive p, q, g, y (re-stated from the public\n *              key blob), plus the secret exponent x.\n */\nexport type SshPrivateKeyData =\n  | { kind: \"ed25519\"; seed: Uint8Array; pubBytes: Uint8Array }\n  | { kind: \"ecdsa\"; curve: SshEcdsaCurve; scalar: Uint8Array; point: Uint8Array }\n  | {\n      kind: \"dsa\";\n      p: Uint8Array;\n      q: Uint8Array;\n      g: Uint8Array;\n      y: Uint8Array;\n      x: Uint8Array;\n    };\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n  if (a.length !== b.length) return false;\n  for (let i = 0; i < a.length; i++) {\n    if (a[i] !== b[i]) return false;\n  }\n  return true;\n}\n\nfunction decodeUtf8(bytes: Uint8Array): string {\n  return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n}\n\nfunction stripPositiveMpint(mpint: Uint8Array): Uint8Array {\n  if (mpint.length > 0 && mpint[0] === 0x00) {\n    return new Uint8Array(mpint.subarray(1));\n  }\n  return new Uint8Array(mpint);\n}\n\nexport class SSHPrivateKey {\n  readonly data: SshPrivateKeyData;\n  readonly comment: string;\n  /**\n   * 32-bit checkint preserved on round-trip — `ssh-key` retains the parsed\n   * value, so to round-trip byte-identically we do too.\n   */\n  readonly checkint: number;\n\n  private constructor(data: SshPrivateKeyData, comment: string, checkint: number) {\n    this.data = data;\n    this.comment = comment;\n    this.checkint = checkint >>> 0;\n  }\n\n  /**\n   * Construct an `SSHPrivateKey` from already-decoded parts. Used by\n   * `PrivateKeyBase.sshSigningPrivateKey` after generating key material\n   * from an HKDF-seeded RNG. The `checkint` should be derived\n   * deterministically from the private bytes (matching Rust's\n   * `ssh-key` 0.6.7 `KeypairData::checkint`).\n   */\n  static fromParts(data: SshPrivateKeyData, comment: string, checkint: number): SSHPrivateKey {\n    return new SSHPrivateKey(data, comment, checkint);\n  }\n\n  /** Algorithm tag for this key. */\n  get algorithm(): SshAlgorithm {\n    const data = this.data;\n    switch (data.kind) {\n      case \"ed25519\":\n        return { kind: \"ed25519\" };\n      case \"dsa\":\n        return { kind: \"dsa\" };\n      case \"ecdsa\":\n        return { kind: \"ecdsa\", curve: data.curve };\n      default: {\n        const _exhaustive: never = data;\n        throw new Error(`SSHPrivateKey: unreachable kind ${String(_exhaustive)}`);\n      }\n    }\n  }\n\n  // --------------------------------------------------------------------------\n  // Legacy accessors (kept for compatibility with earlier SSH suite tests\n  // that read `publicBytes` / `privateBytes` directly).\n  // --------------------------------------------------------------------------\n\n  get publicBytes(): Uint8Array {\n    const data = this.data;\n    switch (data.kind) {\n      case \"ed25519\":\n        return data.pubBytes;\n      case \"ecdsa\":\n        return data.point;\n      case \"dsa\":\n        throw new Error(\n          \"SSHPrivateKey.publicBytes is not defined for DSA — use `data.p/q/g/y` instead\",\n        );\n      default: {\n        const _exhaustive: never = data;\n        throw new Error(`SSHPrivateKey: unreachable kind ${String(_exhaustive)}`);\n      }\n    }\n  }\n\n  get privateBytes(): Uint8Array {\n    const data = this.data;\n    switch (data.kind) {\n      case \"ed25519\":\n        return data.seed;\n      case \"ecdsa\":\n        return data.scalar;\n      case \"dsa\":\n        throw new Error(\"SSHPrivateKey.privateBytes is not defined for DSA — use `data.x` instead\");\n      default: {\n        const _exhaustive: never = data;\n        throw new Error(`SSHPrivateKey: unreachable kind ${String(_exhaustive)}`);\n      }\n    }\n  }\n\n  // --------------------------------------------------------------------------\n  // OpenSSH armored format (PEM)\n  // --------------------------------------------------------------------------\n\n  static fromOpenssh(text: string): SSHPrivateKey {\n    const { data } = parsePem(text, PEM_LABEL);\n    return SSHPrivateKey.fromBlob(data);\n  }\n\n  static fromBlob(blob: Uint8Array): SSHPrivateKey {\n    if (blob.length < MAGIC.length || !bytesEqual(blob.subarray(0, MAGIC.length), MAGIC)) {\n      throw new Error(\"SSHPrivateKey: missing 'openssh-key-v1' magic\");\n    }\n    const reader = new SshBufferReader(blob.subarray(MAGIC.length));\n\n    const ciphername = decodeUtf8(reader.readString());\n    const kdfname = decodeUtf8(reader.readString());\n    if (ciphername !== CIPHER_NONE || kdfname !== KDF_NONE) {\n      throw new Error(\n        `SSHPrivateKey: encrypted keys are not supported in v1 (ciphername='${ciphername}', kdfname='${kdfname}'). See SSH_PLAN.md V2.B.`,\n      );\n    }\n    const kdfoptions = reader.readString();\n    if (kdfoptions.length !== 0) {\n      throw new Error(\n        `SSHPrivateKey: expected empty kdfoptions for ciphername='none', got ${kdfoptions.length} bytes`,\n      );\n    }\n    const nkeys = reader.readUint32();\n    if (nkeys !== NKEYS) {\n      throw new Error(`SSHPrivateKey: expected exactly ${NKEYS} key, got ${nkeys}`);\n    }\n    const publicKeyBlob = reader.readString();\n    const publicKey = SSHPublicKey.fromBlob(publicKeyBlob);\n\n    const encryptedBlob = reader.readString();\n    if (!reader.isAtEnd()) {\n      throw new Error(\"SSHPrivateKey: trailing bytes after encrypted section\");\n    }\n    if (encryptedBlob.length % BLOCK_SIZE_NONE !== 0) {\n      throw new Error(\n        `SSHPrivateKey: encrypted section length ${encryptedBlob.length} is not a multiple of ${BLOCK_SIZE_NONE}`,\n      );\n    }\n\n    const innerReader = new SshBufferReader(encryptedBlob);\n    const checkint1 = innerReader.readUint32();\n    const checkint2 = innerReader.readUint32();\n    if (checkint1 !== checkint2) {\n      throw new Error(\n        `SSHPrivateKey: checkint mismatch (0x${checkint1.toString(16)} vs 0x${checkint2.toString(16)}) — file is corrupted or encrypted`,\n      );\n    }\n\n    const algoName = decodeUtf8(innerReader.readString());\n    const algorithm = parseSshAlgorithm(algoName);\n    if (sshAlgorithmName(publicKey.algorithm) !== algoName) {\n      throw new Error(\n        `SSHPrivateKey: outer/inner algorithm mismatch ('${sshAlgorithmName(publicKey.algorithm)}' vs '${algoName}')`,\n      );\n    }\n\n    let data: SshPrivateKeyData;\n    switch (algorithm.kind) {\n      case \"ed25519\": {\n        const pubBytes = innerReader.readString();\n        if (pubBytes.length !== ED25519_PUBLIC_LEN) {\n          throw new Error(\n            `SSHPrivateKey ed25519: public key length ${pubBytes.length} != ${ED25519_PUBLIC_LEN}`,\n          );\n        }\n        if (publicKey.data.kind !== \"ed25519\" || !bytesEqual(pubBytes, publicKey.data.pubBytes)) {\n          throw new Error(\"SSHPrivateKey ed25519: outer/inner public-key mismatch\");\n        }\n        const combined = innerReader.readString();\n        if (combined.length !== ED25519_SEED_LEN + ED25519_PUBLIC_LEN) {\n          throw new Error(\n            `SSHPrivateKey ed25519: combined seed||public length ${combined.length} != ${ED25519_SEED_LEN + ED25519_PUBLIC_LEN}`,\n          );\n        }\n        const tail = combined.subarray(ED25519_SEED_LEN);\n        if (!bytesEqual(tail, pubBytes)) {\n          throw new Error(\n            \"SSHPrivateKey ed25519: combined-blob public tail does not match public field\",\n          );\n        }\n        data = {\n          kind: \"ed25519\",\n          seed: new Uint8Array(combined.subarray(0, ED25519_SEED_LEN)),\n          pubBytes: new Uint8Array(pubBytes),\n        };\n        break;\n      }\n      case \"ecdsa\": {\n        const expectedCurve = sshCurveName(algorithm.curve);\n        const curveName = decodeUtf8(innerReader.readString());\n        if (curveName !== expectedCurve) {\n          throw new Error(\n            `SSHPrivateKey ecdsa: blob curve '${curveName}' does not match algorithm '${expectedCurve}'`,\n          );\n        }\n        const point = innerReader.readString();\n        const expectedPointLen = sshEcdsaPointLen(algorithm.curve);\n        if (point.length !== expectedPointLen || point[0] !== 0x04) {\n          throw new Error(\n            `SSHPrivateKey ecdsa: expected ${expectedPointLen}-byte uncompressed point (0x04 prefix), got ${point.length} bytes prefix=0x${point[0]?.toString(16) ?? \"?\"}`,\n          );\n        }\n        if (publicKey.data.kind !== \"ecdsa\" || !bytesEqual(point, publicKey.data.point)) {\n          throw new Error(\"SSHPrivateKey ecdsa: outer/inner public-key mismatch\");\n        }\n        const mpint = innerReader.readMpint();\n        const stripped = stripMpintSignByte(mpint);\n        const scalar = padLeftToLength(stripped, sshEcdsaScalarLen(algorithm.curve));\n        data = {\n          kind: \"ecdsa\",\n          curve: algorithm.curve,\n          point: new Uint8Array(point),\n          scalar,\n        };\n        break;\n      }\n      case \"dsa\": {\n        const p = stripPositiveMpint(innerReader.readMpint());\n        const q = stripPositiveMpint(innerReader.readMpint());\n        const g = stripPositiveMpint(innerReader.readMpint());\n        const y = stripPositiveMpint(innerReader.readMpint());\n        const x = stripPositiveMpint(innerReader.readMpint());\n        if (publicKey.data.kind !== \"dsa\") {\n          throw new Error(\"SSHPrivateKey dsa: outer key is not DSA\");\n        }\n        // Re-stated public params must match the outer pubkey blob.\n        if (\n          !bytesEqual(p, publicKey.data.p) ||\n          !bytesEqual(q, publicKey.data.q) ||\n          !bytesEqual(g, publicKey.data.g) ||\n          !bytesEqual(y, publicKey.data.y)\n        ) {\n          throw new Error(\"SSHPrivateKey dsa: outer/inner public-parameter mismatch\");\n        }\n        data = { kind: \"dsa\", p, q, g, y, x };\n        break;\n      }\n    }\n\n    const comment = decodeUtf8(innerReader.readString());\n\n    // Validate padding 0x01, 0x02, ... up to block-size boundary.\n    let pad = 1;\n    while (!innerReader.isAtEnd()) {\n      const b = innerReader.readByte();\n      if (b !== pad) {\n        throw new Error(\n          `SSHPrivateKey: bad padding byte at offset ${innerReader.position()} (expected 0x${pad.toString(16)}, got 0x${b.toString(16)})`,\n        );\n      }\n      pad++;\n    }\n\n    return new SSHPrivateKey(data, comment, checkint1);\n  }\n\n  /**\n   * Re-serialize to the canonical OpenSSH armored format.\n   *\n   * Matches Rust `ssh_key::PrivateKey::to_openssh(LineEnding::LF)`.\n   */\n  toOpenssh(): string {\n    return encodePem(PEM_LABEL, this.toBlob(), PEM_LINE_WIDTH);\n  }\n\n  toBlob(): Uint8Array {\n    const writer = new SshBufferWriter();\n    writer.writeRaw(MAGIC);\n    writer.writeStringUtf8(CIPHER_NONE);\n    writer.writeStringUtf8(KDF_NONE);\n    writer.writeString(new Uint8Array(0));\n    writer.writeUint32(NKEYS);\n    writer.writeString(this.publicBlob());\n    writer.writeString(this.encryptedSection());\n    return writer.bytes();\n  }\n\n  publicKey(): SSHPublicKey {\n    switch (this.data.kind) {\n      case \"ed25519\":\n        return SSHPublicKey.ed25519(this.data.pubBytes, this.comment);\n      case \"ecdsa\":\n        return SSHPublicKey.ecdsa(this.data.curve, this.data.point, this.comment);\n      case \"dsa\":\n        return SSHPublicKey.dsa(this.data.p, this.data.q, this.data.g, this.data.y, this.comment);\n    }\n  }\n\n  private publicBlob(): Uint8Array {\n    return this.publicKey().toBlob();\n  }\n\n  private encryptedSection(): Uint8Array {\n    const w = new SshBufferWriter();\n    w.writeUint32(this.checkint);\n    w.writeUint32(this.checkint);\n    w.writeStringUtf8(sshAlgorithmName(this.algorithm));\n    switch (this.data.kind) {\n      case \"ed25519\": {\n        w.writeString(this.data.pubBytes);\n        const combined = new Uint8Array(ED25519_SEED_LEN + ED25519_PUBLIC_LEN);\n        combined.set(this.data.seed, 0);\n        combined.set(this.data.pubBytes, ED25519_SEED_LEN);\n        w.writeString(combined);\n        break;\n      }\n      case \"ecdsa\": {\n        w.writeStringUtf8(sshCurveName(this.data.curve));\n        w.writeString(this.data.point);\n        w.writeMpintUnsigned(this.data.scalar);\n        break;\n      }\n      case \"dsa\": {\n        w.writeMpintUnsigned(this.data.p);\n        w.writeMpintUnsigned(this.data.q);\n        w.writeMpintUnsigned(this.data.g);\n        w.writeMpintUnsigned(this.data.y);\n        w.writeMpintUnsigned(this.data.x);\n        break;\n      }\n    }\n    w.writeStringUtf8(this.comment);\n    const body = w.bytes();\n    const padLen = (BLOCK_SIZE_NONE - (body.length % BLOCK_SIZE_NONE)) % BLOCK_SIZE_NONE;\n    if (padLen === 0) return body;\n    const out = new Uint8Array(body.length + padLen);\n    out.set(body, 0);\n    for (let i = 0; i < padLen; i++) out[body.length + i] = i + 1;\n    return out;\n  }\n\n  // --------------------------------------------------------------------------\n  // Reference / display\n  // --------------------------------------------------------------------------\n\n  digest(): Uint8Array {\n    return sha256(new TextEncoder().encode(this.toOpenssh()));\n  }\n\n  refHexShort(): string {\n    const d = this.digest();\n    let s = \"\";\n    for (let i = 0; i < 4; i++) s += d[i].toString(16).padStart(2, \"0\");\n    return s;\n  }\n\n  toString(): string {\n    return `SSHPrivateKey(${this.refHexShort()})`;\n  }\n\n  // --------------------------------------------------------------------------\n  // SSHSIG sign (PROTOCOL.sshsig §3.1)\n  // --------------------------------------------------------------------------\n\n  sign(namespace: string, hashAlgorithm: SshHashAlgorithm, message: Uint8Array): SSHSignature {\n    const messageDigest = digestForHash(hashAlgorithm, message);\n    const signedData = SSHSignature.signedDataBlob(namespace, hashAlgorithm, messageDigest);\n    let signatureBytes: Uint8Array;\n    switch (this.data.kind) {\n      case \"ed25519\":\n        signatureBytes = ed25519.sign(signedData, this.data.seed);\n        break;\n      case \"ecdsa\": {\n        switch (this.data.curve) {\n          case \"nistp256\":\n            // p256 default: prehash=true (SHA-256), format='compact' (r||s as 64 bytes).\n            signatureBytes = p256.sign(signedData, this.data.scalar, { format: \"compact\" });\n            break;\n          case \"nistp384\":\n            signatureBytes = p384.sign(signedData, this.data.scalar, { format: \"compact\" });\n            break;\n        }\n        break;\n      }\n      case \"dsa\": {\n        // SSH-DSA always inner-hashes with SHA-1 regardless of the SSHSIG\n        // hash_algorithm. Matches Rust `ssh-key`/`dsa` 0.6.7.\n        const innerDigest = sha1(signedData);\n        signatureBytes = dsaSign({\n          p: this.data.p,\n          q: this.data.q,\n          g: this.data.g,\n          y: this.data.y,\n          x: this.data.x,\n          messageDigest: innerDigest,\n        });\n        break;\n      }\n    }\n    return SSHSignature.fromParts(this.publicKey(), namespace, hashAlgorithm, signatureBytes);\n  }\n}\n\nfunction digestForHash(alg: SshHashAlgorithm, message: Uint8Array): Uint8Array {\n  switch (alg) {\n    case \"sha256\":\n      return sha256(message);\n    case \"sha512\":\n      return sha512(message);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * X25519 public key for ECDH key exchange (32 bytes)\n *\n * X25519 is an elliptic-curve Diffie-Hellman key exchange protocol based on\n * Curve25519 as defined in RFC 7748. It allows two parties to establish a\n * shared secret key over an insecure channel.\n *\n * The X25519 public key is generated from a corresponding private key and is\n * designed to be:\n * - Compact (32 bytes)\n * - Fast to use in key agreement operations\n * - Resistant to various cryptographic attacks\n *\n * # CBOR Serialization\n *\n * `X25519PublicKey` is serialized to CBOR with tag 40011.\n *\n * ```\n * #6.40011(h'<32-byte-public-key>')\n * ```\n *\n * Ported from bc-components-rust/src/x25519/x25519_public_key.rs\n */\n\nimport { X25519_PUBLIC_KEY_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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY } from \"@bcts/tags\";\nimport { Digest } from \"../digest.js\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class X25519PublicKey\n  implements CborTaggedEncodable, CborTaggedDecodable<X25519PublicKey>, UREncodable\n{\n  static readonly KEY_SIZE = X25519_PUBLIC_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== X25519_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(X25519_PUBLIC_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Restore an X25519PublicKey from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): X25519PublicKey {\n    return new X25519PublicKey(new Uint8Array(data));\n  }\n\n  /**\n   * Restore an X25519PublicKey from a reference to an array of bytes.\n   * Validates the length.\n   */\n  static fromDataRef(data: Uint8Array): X25519PublicKey {\n    if (data.length !== X25519_PUBLIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(X25519_PUBLIC_KEY_SIZE, data.length);\n    }\n    return X25519PublicKey.fromData(data);\n  }\n\n  /**\n   * Create an X25519PublicKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): X25519PublicKey {\n    return X25519PublicKey.fromData(data);\n  }\n\n  /**\n   * Restore an X25519PublicKey from a hex string.\n   */\n  static fromHex(hex: string): X25519PublicKey {\n    return X25519PublicKey.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw public key bytes (copy).\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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   * Compare with another X25519PublicKey.\n   */\n  equals(other: X25519PublicKey): 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   * Get string representation.\n   *\n   * Mirrors Rust `Display for X25519PublicKey`\n   * (`bc-components-rust/src/x25519/x25519_public_key.rs:166-168`):\n   *   `X25519PublicKey(<ref_hex_short>)` where the reference is\n   *   computed from the **tagged-CBOR** form of the key.\n   */\n  toString(): string {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return `X25519PublicKey(${digest.shortDescription()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with X25519PublicKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_X25519_PUBLIC_KEY.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 an X25519PublicKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): X25519PublicKey {\n    const data = expectBytes(cbor);\n    return X25519PublicKey.fromDataRef(data);\n  }\n\n  /**\n   * Creates an X25519PublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): X25519PublicKey {\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): X25519PublicKey {\n    const dummy = new X25519PublicKey(new Uint8Array(X25519_PUBLIC_KEY_SIZE));\n    return dummy.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): X25519PublicKey {\n    const cbor = decodeCbor(data);\n    return X25519PublicKey.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): X25519PublicKey {\n    const cbor = decodeCbor(data);\n    const dummy = new X25519PublicKey(new Uint8Array(X25519_PUBLIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(cbor);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the X25519PublicKey.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    const name = TAG_X25519_PUBLIC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"X25519_PUBLIC_KEY tag name is undefined\");\n    }\n    return UR.new(name, 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 an X25519PublicKey from a UR.\n   */\n  static fromUR(ur: UR): X25519PublicKey {\n    const name = TAG_X25519_PUBLIC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"X25519_PUBLIC_KEY tag name is undefined\");\n    }\n    ur.checkType(name);\n    const dummy = new X25519PublicKey(new Uint8Array(X25519_PUBLIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an X25519PublicKey from a UR string.\n   */\n  static fromURString(urString: string): X25519PublicKey {\n    const ur = UR.fromURString(urString);\n    return X25519PublicKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Authentication tag for AEAD encryption (16 bytes)\n *\n * An `AuthenticationTag` is a 16-byte value generated during ChaCha20-Poly1305\n * authenticated encryption. It serves as a message authentication code (MAC)\n * that verifies both the authenticity and integrity of the encrypted message.\n *\n * During decryption, the tag is verified to ensure:\n * - The message has not been tampered with (integrity)\n * - The message was encrypted by someone who possesses the encryption key\n *   (authenticity)\n *\n * This implementation follows the Poly1305 MAC algorithm as specified in\n * [RFC-8439](https://datatracker.ietf.org/doc/html/rfc8439).\n *\n * Ported from bc-components-rust/src/symmetric/authentication_tag.rs\n */\n\nimport { type Cbor, toByteString, expectBytes, decodeCbor } from \"@bcts/dcbor\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nconst AUTHENTICATION_TAG_SIZE = 16;\n\nexport class AuthenticationTag {\n  static readonly AUTHENTICATION_TAG_SIZE = AUTHENTICATION_TAG_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== AUTHENTICATION_TAG_SIZE) {\n      throw CryptoError.invalidSize(AUTHENTICATION_TAG_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Restore an AuthenticationTag from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): AuthenticationTag {\n    return new AuthenticationTag(new Uint8Array(data));\n  }\n\n  /**\n   * Restore an AuthenticationTag from a reference to an array of bytes.\n   */\n  static fromDataRef(data: Uint8Array): AuthenticationTag {\n    if (data.length !== AUTHENTICATION_TAG_SIZE) {\n      throw CryptoError.invalidSize(AUTHENTICATION_TAG_SIZE, data.length);\n    }\n    return AuthenticationTag.fromData(data);\n  }\n\n  /**\n   * Create an AuthenticationTag from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): AuthenticationTag {\n    return AuthenticationTag.fromData(data);\n  }\n\n  /**\n   * Create an AuthenticationTag from hex string.\n   */\n  static fromHex(hex: string): AuthenticationTag {\n    return AuthenticationTag.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the reference as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw tag bytes as a copy.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Get hex string representation.\n   */\n  toHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Get base64 representation.\n   */\n  toBase64(): string {\n    return toBase64(this._data);\n  }\n\n  /**\n   * Compare with another AuthenticationTag.\n   */\n  equals(other: AuthenticationTag): 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   * Get string representation.\n   */\n  toString(): string {\n    return `AuthenticationTag(${this.toHex()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (untagged - no CBOR tag for AuthenticationTag)\n  // ============================================================================\n\n  /**\n   * Returns the untagged CBOR encoding (as a byte string).\n   * AuthenticationTag has no CBOR tag - it's serialized as a plain byte string.\n   */\n  toCbor(): Cbor {\n    return toByteString(this._data);\n  }\n\n  /**\n   * Returns the CBOR binary representation.\n   */\n  toCborData(): Uint8Array {\n    return this.toCbor().toData();\n  }\n\n  /**\n   * Creates an AuthenticationTag from CBOR.\n   */\n  static fromCbor(cbor: Cbor): AuthenticationTag {\n    const data = expectBytes(cbor);\n    return AuthenticationTag.fromDataRef(data);\n  }\n\n  /**\n   * Creates an AuthenticationTag from CBOR binary data.\n   */\n  static fromCborData(data: Uint8Array): AuthenticationTag {\n    const cbor = decodeCbor(data);\n    return AuthenticationTag.fromCbor(cbor);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encrypted message with ChaCha20-Poly1305 AEAD\n *\n * A secure encrypted message using IETF ChaCha20-Poly1305 authenticated\n * encryption.\n *\n * `EncryptedMessage` represents data that has been encrypted using a symmetric\n * key with the ChaCha20-Poly1305 AEAD (Authenticated Encryption with\n * Associated Data) construction as specified in [RFC-8439](https://datatracker.ietf.org/doc/html/rfc8439).\n *\n * An `EncryptedMessage` contains:\n * - `ciphertext`: The encrypted data (same length as the original plaintext)\n * - `aad`: Additional Authenticated Data that is not encrypted but is\n *   authenticated (optional)\n * - `nonce`: A 12-byte number used once for this specific encryption operation\n * - `auth`: A 16-byte authentication tag that verifies the integrity of the\n *   message\n *\n * The `aad` field is often used to include the `Digest` of the plaintext,\n * which allows verification of the plaintext after decryption and preserves\n * the unique identity of the data when used with structures like Gordian\n * Envelope.\n *\n * # CBOR Serialization\n *\n * `EncryptedMessage` is serialized to CBOR with tag 40002.\n *\n * CDDL:\n * ```cddl\n * EncryptedMessage =\n *     #6.40002([ ciphertext: bstr, nonce: bstr, auth: bstr, ? aad: bstr ])\n * ```\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), an `EncryptedMessage` is\n * represented with the type \"encrypted\".\n *\n * Ported from bc-components-rust/src/symmetric/encrypted_message.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  expectArray,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { ENCRYPTED as TAG_ENCRYPTED } from \"@bcts/tags\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { Nonce } from \"../nonce.js\";\nimport { Digest } from \"../digest.js\";\nimport { AuthenticationTag } from \"./authentication-tag.js\";\nimport { bytesToHex } from \"../utils.js\";\n\nexport class EncryptedMessage\n  implements CborTaggedEncodable, CborTaggedDecodable<EncryptedMessage>, UREncodable\n{\n  private readonly _ciphertext: Uint8Array;\n  private readonly _aad: Uint8Array;\n  private readonly _nonce: Nonce;\n  private readonly _auth: AuthenticationTag;\n\n  private constructor(\n    ciphertext: Uint8Array,\n    aad: Uint8Array,\n    nonce: Nonce,\n    auth: AuthenticationTag,\n  ) {\n    this._ciphertext = new Uint8Array(ciphertext);\n    this._aad = new Uint8Array(aad);\n    this._nonce = nonce;\n    this._auth = auth;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Restores an EncryptedMessage from its components.\n   */\n  static new(\n    ciphertext: Uint8Array,\n    aad: Uint8Array,\n    nonce: Nonce,\n    auth: Uint8Array | AuthenticationTag,\n  ): EncryptedMessage {\n    const authTag = auth instanceof AuthenticationTag ? auth : AuthenticationTag.fromData(auth);\n    return new EncryptedMessage(ciphertext, aad, nonce, authTag);\n  }\n\n  /**\n   * Create an EncryptedMessage from components (legacy alias).\n   */\n  static from(\n    nonce: Nonce,\n    ciphertext: Uint8Array,\n    tag: AuthenticationTag,\n    aad?: Uint8Array,\n  ): EncryptedMessage {\n    return new EncryptedMessage(ciphertext, aad ?? new Uint8Array(0), nonce, tag);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns a reference to the ciphertext data.\n   */\n  ciphertext(): Uint8Array {\n    return this._ciphertext;\n  }\n\n  /**\n   * Returns a reference to the additional authenticated data (AAD).\n   */\n  aad(): Uint8Array {\n    return this._aad;\n  }\n\n  /**\n   * Returns a reference to the nonce value used for encryption.\n   */\n  nonce(): Nonce {\n    return this._nonce;\n  }\n\n  /**\n   * Returns a reference to the authentication tag value used for encryption.\n   */\n  authenticationTag(): AuthenticationTag {\n    return this._auth;\n  }\n\n  /**\n   * Returns a CBOR representation in the AAD field, if it exists.\n   */\n  aadCbor(): Cbor | null {\n    if (this._aad.length === 0) {\n      return null;\n    }\n    try {\n      return decodeCbor(this._aad);\n    } catch {\n      return null;\n    }\n  }\n\n  /**\n   * Returns a Digest instance if the AAD data can be parsed as CBOR.\n   */\n  aadDigest(): Digest | null {\n    const aadCbor = this.aadCbor();\n    if (aadCbor === null) {\n      return null;\n    }\n    try {\n      return Digest.fromTaggedCbor(aadCbor);\n    } catch {\n      return null;\n    }\n  }\n\n  /**\n   * Returns true if the AAD data can be parsed as a Digest.\n   */\n  hasDigest(): boolean {\n    return this.aadDigest() !== null;\n  }\n\n  /**\n   * Compare with another EncryptedMessage.\n   */\n  equals(other: EncryptedMessage): boolean {\n    if (this._ciphertext.length !== other._ciphertext.length) return false;\n    for (let i = 0; i < this._ciphertext.length; i++) {\n      if (this._ciphertext[i] !== other._ciphertext[i]) return false;\n    }\n    if (this._aad.length !== other._aad.length) return false;\n    for (let i = 0; i < this._aad.length; i++) {\n      if (this._aad[i] !== other._aad[i]) return false;\n    }\n    return this._nonce.equals(other._nonce) && this._auth.equals(other._auth);\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return `EncryptedMessage(ciphertext: ${bytesToHex(this._ciphertext).substring(0, 16)}..., nonce: ${this._nonce.toHex()}, auth: ${this._auth.toHex()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with EncryptedMessage.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_ENCRYPTED.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding (as an array).\n   * Array format: [ciphertext, nonce, auth, ?aad]\n   */\n  untaggedCbor(): Cbor {\n    const elements: Cbor[] = [\n      toByteString(this._ciphertext),\n      toByteString(this._nonce.data()),\n      toByteString(this._auth.data()),\n    ];\n\n    if (this._aad.length > 0) {\n      elements.push(toByteString(this._aad));\n    }\n\n    return cbor(elements);\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 an EncryptedMessage by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): EncryptedMessage {\n    const elements = expectArray(cborValue);\n\n    if (elements.length < 3) {\n      throw new Error(\"EncryptedMessage must have at least 3 elements\");\n    }\n\n    const ciphertext = expectBytes(elements[0]);\n    const nonceData = expectBytes(elements[1]);\n    const nonce = Nonce.fromDataRef(nonceData);\n    const authData = expectBytes(elements[2]);\n    const auth = AuthenticationTag.fromDataRef(authData);\n    const aad = elements.length > 3 ? expectBytes(elements[3]) : new Uint8Array(0);\n\n    return EncryptedMessage.new(ciphertext, aad, nonce, auth);\n  }\n\n  /**\n   * Creates an EncryptedMessage by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): EncryptedMessage {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): EncryptedMessage {\n    // Create a dummy instance for accessing instance methods\n    const dummy = new EncryptedMessage(\n      new Uint8Array(0),\n      new Uint8Array(0),\n      Nonce.new(),\n      AuthenticationTag.fromData(new Uint8Array(16)),\n    );\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): EncryptedMessage {\n    const cborValue = decodeCbor(data);\n    return EncryptedMessage.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): EncryptedMessage {\n    const cborValue = decodeCbor(data);\n    const dummy = new EncryptedMessage(\n      new Uint8Array(0),\n      new Uint8Array(0),\n      Nonce.new(),\n      AuthenticationTag.fromData(new Uint8Array(16)),\n    );\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the EncryptedMessage.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    return UR.new(\"encrypted\", 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 an EncryptedMessage from a UR.\n   */\n  static fromUR(ur: UR): EncryptedMessage {\n    ur.checkType(\"encrypted\");\n    const dummy = new EncryptedMessage(\n      new Uint8Array(0),\n      new Uint8Array(0),\n      Nonce.new(),\n      AuthenticationTag.fromData(new Uint8Array(16)),\n    );\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an EncryptedMessage from a UR string.\n   */\n  static fromURString(urString: string): EncryptedMessage {\n    const ur = UR.fromURString(urString);\n    return EncryptedMessage.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Symmetric key for ChaCha20-Poly1305 AEAD encryption (32 bytes)\n *\n * A symmetric encryption key used for both encryption and decryption.\n *\n * `SymmetricKey` is a 32-byte cryptographic key used with ChaCha20-Poly1305\n * AEAD (Authenticated Encryption with Associated Data) encryption. This\n * implementation follows the IETF ChaCha20-Poly1305 specification as defined\n * in [RFC-8439](https://datatracker.ietf.org/doc/html/rfc8439).\n *\n * Symmetric encryption uses the same key for both encryption and decryption,\n * unlike asymmetric encryption where different keys are used for each\n * operation.\n *\n * # CBOR Serialization\n *\n * `SymmetricKey` is serialized to CBOR with tag 40023.\n *\n * Ported from bc-components-rust/src/symmetric/symmetric_key.rs\n */\n\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  aeadChaCha20Poly1305EncryptWithAad,\n  aeadChaCha20Poly1305DecryptWithAad,\n} 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 { SYMMETRIC_KEY as TAG_SYMMETRIC_KEY } from \"@bcts/tags\";\nimport { UR } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\nimport { Nonce } from \"../nonce.js\";\nimport { EncryptedMessage } from \"./encrypted-message.js\";\n\nconst SYMMETRIC_KEY_SIZE = 32;\n\nexport class SymmetricKey implements CborTaggedEncodable, CborTaggedDecodable<SymmetricKey> {\n  static readonly SYMMETRIC_KEY_SIZE = SYMMETRIC_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== SYMMETRIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(SYMMETRIC_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new random symmetric key.\n   */\n  static new(): SymmetricKey {\n    return SymmetricKey.random();\n  }\n\n  /**\n   * Create a new symmetric key from data.\n   */\n  static fromData(data: Uint8Array): SymmetricKey {\n    return new SymmetricKey(new Uint8Array(data));\n  }\n\n  /**\n   * Create a new symmetric key from data (validates length).\n   */\n  static fromDataRef(data: Uint8Array): SymmetricKey {\n    if (data.length !== SYMMETRIC_KEY_SIZE) {\n      throw CryptoError.invalidSize(SYMMETRIC_KEY_SIZE, data.length);\n    }\n    return SymmetricKey.fromData(data);\n  }\n\n  /**\n   * Create a SymmetricKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): SymmetricKey {\n    return SymmetricKey.fromData(data);\n  }\n\n  /**\n   * Create a SymmetricKey from hex string.\n   */\n  static fromHex(hex: string): SymmetricKey {\n    return SymmetricKey.fromData(hexToBytes(hex));\n  }\n\n  /**\n   * Generate a random symmetric key.\n   */\n  static random(): SymmetricKey {\n    const rng = new SecureRandomNumberGenerator();\n    return SymmetricKey.randomUsing(rng);\n  }\n\n  /**\n   * Generate a random symmetric key using provided RNG.\n   */\n  static randomUsing(rng: SecureRandomNumberGenerator): SymmetricKey {\n    return new SymmetricKey(rng.randomData(SYMMETRIC_KEY_SIZE));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get the data of the symmetric key.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the data of the symmetric key as a byte slice.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get a copy of the raw key bytes.\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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   * Compare with another SymmetricKey.\n   */\n  equals(other: SymmetricKey): 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   * Get string representation.\n   */\n  toString(): string {\n    return `SymmetricKey(${this.hex().substring(0, 8)}...)`;\n  }\n\n  // ============================================================================\n  // Encryption/Decryption\n  // ============================================================================\n\n  /**\n   * Encrypt the given plaintext with this key, and the given additional\n   * authenticated data and nonce.\n   */\n  encrypt(plaintext: Uint8Array, aad?: Uint8Array, nonce?: Nonce): EncryptedMessage {\n    const effectiveNonce = nonce ?? Nonce.new();\n    const effectiveAad = aad ?? new Uint8Array(0);\n\n    const [ciphertext, authTag] = aeadChaCha20Poly1305EncryptWithAad(\n      plaintext,\n      this._data,\n      effectiveNonce.data(),\n      effectiveAad,\n    );\n\n    return EncryptedMessage.new(ciphertext, effectiveAad, effectiveNonce, authTag);\n  }\n\n  /**\n   * Decrypt the given encrypted message with this key.\n   */\n  decrypt(message: EncryptedMessage): Uint8Array {\n    return aeadChaCha20Poly1305DecryptWithAad(\n      message.ciphertext(),\n      this._data,\n      message.nonce().data(),\n      message.aad(),\n      message.authenticationTag().data(),\n    );\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with SymmetricKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SYMMETRIC_KEY.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 SymmetricKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): SymmetricKey {\n    const data = expectBytes(cbor);\n    return SymmetricKey.fromDataRef(data);\n  }\n\n  /**\n   * Creates a SymmetricKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): SymmetricKey {\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): SymmetricKey {\n    const instance = new SymmetricKey(new Uint8Array(SYMMETRIC_KEY_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): SymmetricKey {\n    const cbor = decodeCbor(data);\n    return SymmetricKey.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): SymmetricKey {\n    const cbor = decodeCbor(data);\n    const bytes = expectBytes(cbor);\n    return SymmetricKey.fromDataRef(bytes);\n  }\n\n  // ============================================================================\n  // UR (Uniform Resource) Serialization\n  // ============================================================================\n\n  /**\n   * Get the UR type for symmetric keys.\n   */\n  static readonly UR_TYPE = \"crypto-key\";\n\n  /**\n   * Returns the UR representation of the symmetric key.\n   *\n   * The UR type prefix (`ur:crypto-key/...`) carries the CBOR tag, so the\n   * inner CBOR must be untagged — matches Rust's `UREncodable` blanket impl.\n   */\n  ur(): UR {\n    return UR.new(SymmetricKey.UR_TYPE, this.untaggedCbor());\n  }\n\n  /**\n   * Returns the UR string representation of the symmetric key.\n   */\n  urString(): string {\n    return this.ur().string();\n  }\n\n  /**\n   * Creates a SymmetricKey from a UR.\n   */\n  static fromUR(ur: UR): SymmetricKey {\n    ur.checkType(SymmetricKey.UR_TYPE);\n    const dummy = SymmetricKey.fromData(new Uint8Array(SymmetricKey.SYMMETRIC_KEY_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a SymmetricKey from a UR string.\n   */\n  static fromURString(urString: string): SymmetricKey {\n    const ur = UR.fromURString(urString);\n    return SymmetricKey.fromUR(ur);\n  }\n\n  /**\n   * Alias for fromURString for Rust API compatibility.\n   */\n  static fromUrString(urString: string): SymmetricKey {\n    return SymmetricKey.fromURString(urString);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * X25519 private key for ECDH key exchange (32 bytes seed)\n *\n * X25519 is an elliptic-curve Diffie-Hellman key exchange protocol based on\n * Curve25519 as defined in RFC 7748. It allows two parties to establish a\n * shared secret key over an insecure channel.\n *\n * Key features of X25519:\n * - High security (128-bit security level)\n * - High performance\n * - Small key sizes (32 bytes)\n * - Protection against various side-channel attacks\n *\n * # CBOR Serialization\n *\n * `X25519PrivateKey` is serialized to CBOR with tag 40010.\n *\n * ```\n * #6.40010(h'<32-byte-private-key>')\n * ```\n *\n * Ported from bc-components-rust/src/x25519/x25519_private_key.rs\n */\n\nimport { SecureRandomNumberGenerator, type RandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  X25519_PRIVATE_KEY_SIZE,\n  x25519PublicKeyFromPrivateKey,\n  x25519SharedKey,\n  deriveAgreementPrivateKey,\n} 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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { X25519_PRIVATE_KEY as TAG_X25519_PRIVATE_KEY } from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { X25519PublicKey } from \"./x25519-public-key.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class X25519PrivateKey\n  implements CborTaggedEncodable, CborTaggedDecodable<X25519PrivateKey>, UREncodable\n{\n  static readonly KEY_SIZE = X25519_PRIVATE_KEY_SIZE;\n\n  private readonly _data: Uint8Array;\n  private _publicKey?: X25519PublicKey;\n\n  private constructor(data: Uint8Array) {\n    if (data.length !== X25519_PRIVATE_KEY_SIZE) {\n      throw CryptoError.invalidSize(X25519_PRIVATE_KEY_SIZE, data.length);\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Generate a new random X25519PrivateKey.\n   */\n  static new(): X25519PrivateKey {\n    return X25519PrivateKey.random();\n  }\n\n  /**\n   * Generate a new random X25519PrivateKey.\n   */\n  static random(): X25519PrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return X25519PrivateKey.newUsing(rng);\n  }\n\n  /**\n   * Generate a new random X25519PrivateKey using provided RNG.\n   */\n  static newUsing(rng: RandomNumberGenerator): X25519PrivateKey {\n    return new X25519PrivateKey(rng.randomData(X25519_PRIVATE_KEY_SIZE));\n  }\n\n  /**\n   * Generate a new random X25519PrivateKey and corresponding X25519PublicKey.\n   */\n  static keypair(): [X25519PrivateKey, X25519PublicKey] {\n    const privateKey = X25519PrivateKey.new();\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Generate a new random X25519PrivateKey and corresponding X25519PublicKey\n   * using the given random number generator.\n   */\n  static keypairUsing(rng: RandomNumberGenerator): [X25519PrivateKey, X25519PublicKey] {\n    const privateKey = X25519PrivateKey.newUsing(rng);\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Derive an X25519PrivateKey from the given key material.\n   *\n   * @param keyMaterial - The key material to derive from\n   * @returns A new X25519PrivateKey derived from the key material\n   */\n  static deriveFromKeyMaterial(keyMaterial: Uint8Array): X25519PrivateKey {\n    return new X25519PrivateKey(deriveAgreementPrivateKey(keyMaterial));\n  }\n\n  /**\n   * Restore an X25519PrivateKey from a fixed-size array of bytes.\n   */\n  static fromData(data: Uint8Array): X25519PrivateKey {\n    return new X25519PrivateKey(new Uint8Array(data));\n  }\n\n  /**\n   * Restore an X25519PrivateKey from a reference to an array of bytes.\n   * Validates the length.\n   */\n  static fromDataRef(data: Uint8Array): X25519PrivateKey {\n    if (data.length !== X25519_PRIVATE_KEY_SIZE) {\n      throw CryptoError.invalidSize(X25519_PRIVATE_KEY_SIZE, data.length);\n    }\n    return X25519PrivateKey.fromData(data);\n  }\n\n  /**\n   * Create an X25519PrivateKey from raw bytes (legacy alias).\n   */\n  static from(data: Uint8Array): X25519PrivateKey {\n    return X25519PrivateKey.fromData(data);\n  }\n\n  /**\n   * Restore an X25519PrivateKey from a hex string.\n   */\n  static fromHex(hex: string): X25519PrivateKey {\n    return X25519PrivateKey.fromData(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Get a reference to the fixed-size array of bytes.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Get the raw private key bytes (copy).\n   */\n  toData(): Uint8Array {\n    return new Uint8Array(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 X25519PublicKey corresponding to this X25519PrivateKey.\n   */\n  publicKey(): X25519PublicKey {\n    if (this._publicKey === undefined) {\n      const publicKeyBytes = x25519PublicKeyFromPrivateKey(this._data);\n      this._publicKey = X25519PublicKey.fromData(publicKeyBytes);\n    }\n    return this._publicKey;\n  }\n\n  /**\n   * Derive a shared symmetric key from this X25519PrivateKey and the given\n   * X25519PublicKey.\n   *\n   * @param publicKey - The other party's public key\n   * @returns A SymmetricKey derived from the shared secret\n   */\n  sharedKeyWith(publicKey: X25519PublicKey): SymmetricKey {\n    const shared = x25519SharedKey(this._data, publicKey.data());\n    return SymmetricKey.fromData(shared);\n  }\n\n  /**\n   * Perform ECDH key agreement with a public key (legacy method).\n   *\n   * @deprecated Use sharedKeyWith() instead which returns a SymmetricKey\n   */\n  sharedSecret(publicKey: X25519PublicKey): Uint8Array {\n    try {\n      const shared = x25519SharedKey(this._data, publicKey.data());\n      return new Uint8Array(shared);\n    } catch (e: unknown) {\n      throw CryptoError.cryptoOperation(`ECDH key agreement failed: ${String(e)}`);\n    }\n  }\n\n  /**\n   * Compare with another X25519PrivateKey.\n   */\n  equals(other: X25519PrivateKey): 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   * Get string representation.\n   */\n  toString(): string {\n    return `X25519PrivateKey(${this.toHex().substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with X25519PrivateKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_X25519_PRIVATE_KEY.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 an X25519PrivateKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cbor: Cbor): X25519PrivateKey {\n    const data = expectBytes(cbor);\n    return X25519PrivateKey.fromDataRef(data);\n  }\n\n  /**\n   * Creates an X25519PrivateKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cbor: Cbor): X25519PrivateKey {\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): X25519PrivateKey {\n    const dummy = new X25519PrivateKey(new Uint8Array(X25519_PRIVATE_KEY_SIZE));\n    return dummy.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): X25519PrivateKey {\n    const cbor = decodeCbor(data);\n    return X25519PrivateKey.fromTaggedCbor(cbor);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): X25519PrivateKey {\n    const cbor = decodeCbor(data);\n    const dummy = new X25519PrivateKey(new Uint8Array(X25519_PRIVATE_KEY_SIZE));\n    return dummy.fromUntaggedCbor(cbor);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the X25519PrivateKey.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    const name = TAG_X25519_PRIVATE_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"X25519_PRIVATE_KEY tag name is undefined\");\n    }\n    return UR.new(name, 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 an X25519PrivateKey from a UR.\n   */\n  static fromUR(ur: UR): X25519PrivateKey {\n    const name = TAG_X25519_PRIVATE_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"X25519_PRIVATE_KEY tag name is undefined\");\n    }\n    ur.checkType(name);\n    const dummy = new X25519PrivateKey(new Uint8Array(X25519_PRIVATE_KEY_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an X25519PrivateKey from a UR string.\n   */\n  static fromURString(urString: string): X25519PrivateKey {\n    const ur = UR.fromURString(urString);\n    return X25519PrivateKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLKEM Security Level - ML-KEM (Module-Lattice-Based Key Encapsulation Mechanism)\n *\n * ML-KEM is a post-quantum key encapsulation mechanism standardized by NIST.\n * It provides three security levels corresponding to different NIST security categories.\n *\n * Security levels:\n * - MLKEM512: NIST Level 1 (equivalent to AES-128)\n * - MLKEM768: NIST Level 3 (equivalent to AES-192)\n * - MLKEM1024: NIST Level 5 (equivalent to AES-256)\n *\n * Ported from bc-components-rust/src/mlkem/mlkem_level.rs\n *\n * Naming note: Rust calls this enum `MLKEM`. TypeScript uses `MLKEMLevel`\n * to avoid colliding with the keypair type names (`MLKEMPrivateKey` /\n * `MLKEMPublicKey` / `MLKEMCiphertext`). The CBOR discriminator (the\n * numeric level) is identical in both languages — this is a TS-only\n * naming choice with no wire-format effect.\n */\n\nimport { ml_kem512, ml_kem768, ml_kem1024 } from \"@noble/post-quantum/ml-kem.js\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\n\n/**\n * ML-KEM security levels.\n *\n * The numeric values correspond to the ML-KEM parameter set:\n * - 512: ML-KEM-512 (NIST Level 1)\n * - 768: ML-KEM-768 (NIST Level 3)\n * - 1024: ML-KEM-1024 (NIST Level 5)\n */\nexport enum MLKEMLevel {\n  /** NIST Level 1 - AES-128 equivalent security */\n  MLKEM512 = 512,\n  /** NIST Level 3 - AES-192 equivalent security */\n  MLKEM768 = 768,\n  /** NIST Level 5 - AES-256 equivalent security */\n  MLKEM1024 = 1024,\n}\n\n/**\n * Key sizes for each ML-KEM security level.\n */\nexport const MLKEM_KEY_SIZES = {\n  [MLKEMLevel.MLKEM512]: {\n    privateKey: 1632,\n    publicKey: 800,\n    ciphertext: 768,\n    sharedSecret: 32,\n  },\n  [MLKEMLevel.MLKEM768]: {\n    privateKey: 2400,\n    publicKey: 1184,\n    ciphertext: 1088,\n    sharedSecret: 32,\n  },\n  [MLKEMLevel.MLKEM1024]: {\n    privateKey: 3168,\n    publicKey: 1568,\n    ciphertext: 1568,\n    sharedSecret: 32,\n  },\n} as const;\n\n/**\n * Get the private key size for a given ML-KEM level.\n */\nexport function mlkemPrivateKeySize(level: MLKEMLevel): number {\n  return MLKEM_KEY_SIZES[level].privateKey;\n}\n\n/**\n * Get the public key size for a given ML-KEM level.\n */\nexport function mlkemPublicKeySize(level: MLKEMLevel): number {\n  return MLKEM_KEY_SIZES[level].publicKey;\n}\n\n/**\n * Get the ciphertext size for a given ML-KEM level.\n */\nexport function mlkemCiphertextSize(level: MLKEMLevel): number {\n  return MLKEM_KEY_SIZES[level].ciphertext;\n}\n\n/**\n * Get the shared secret size for a given ML-KEM level.\n * Note: This is always 32 bytes for all ML-KEM levels.\n */\nexport function mlkemSharedSecretSize(level: MLKEMLevel): number {\n  return MLKEM_KEY_SIZES[level].sharedSecret;\n}\n\n/**\n * Convert an ML-KEM level to its string representation.\n */\nexport function mlkemLevelToString(level: MLKEMLevel): string {\n  switch (level) {\n    case MLKEMLevel.MLKEM512:\n      return \"MLKEM512\";\n    case MLKEMLevel.MLKEM768:\n      return \"MLKEM768\";\n    case MLKEMLevel.MLKEM1024:\n      return \"MLKEM1024\";\n  }\n}\n\n/**\n * Parse an ML-KEM level from its numeric value.\n */\nexport function mlkemLevelFromValue(value: number): MLKEMLevel {\n  switch (value) {\n    case 512:\n      return MLKEMLevel.MLKEM512;\n    case 768:\n      return MLKEMLevel.MLKEM768;\n    case 1024:\n      return MLKEMLevel.MLKEM1024;\n    default:\n      throw new Error(`Invalid MLKEM level value: ${value}`);\n  }\n}\n\n/**\n * Internal type for ML-KEM keypair generation result.\n */\nexport interface MLKEMKeypairData {\n  publicKey: Uint8Array;\n  secretKey: Uint8Array;\n}\n\n/**\n * Internal type for ML-KEM encapsulation result.\n */\nexport interface MLKEMEncapsulationResult {\n  sharedSecret: Uint8Array;\n  ciphertext: Uint8Array;\n}\n\n/**\n * Generate an ML-KEM keypair for the given security level.\n *\n * @param level - The ML-KEM security level\n * @returns Object containing publicKey and secretKey bytes\n */\nexport function mlkemGenerateKeypair(level: MLKEMLevel): MLKEMKeypairData {\n  const rng = new SecureRandomNumberGenerator();\n  return mlkemGenerateKeypairUsing(level, rng);\n}\n\n/**\n * Generate an ML-KEM keypair using a provided RNG.\n *\n * @param level - The ML-KEM security level\n * @param rng - Random number generator\n * @returns Object containing publicKey and secretKey bytes\n */\nexport function mlkemGenerateKeypairUsing(\n  level: MLKEMLevel,\n  rng: RandomNumberGenerator,\n): MLKEMKeypairData {\n  // Generate random seed for keypair generation\n  const seed = rng.randomData(64);\n\n  switch (level) {\n    case MLKEMLevel.MLKEM512: {\n      const keypair = ml_kem512.keygen(seed);\n      return { publicKey: keypair.publicKey, secretKey: keypair.secretKey };\n    }\n    case MLKEMLevel.MLKEM768: {\n      const keypair = ml_kem768.keygen(seed);\n      return { publicKey: keypair.publicKey, secretKey: keypair.secretKey };\n    }\n    case MLKEMLevel.MLKEM1024: {\n      const keypair = ml_kem1024.keygen(seed);\n      return { publicKey: keypair.publicKey, secretKey: keypair.secretKey };\n    }\n  }\n}\n\n/**\n * Encapsulate a new shared secret using a public key.\n *\n * @param level - The ML-KEM security level\n * @param publicKey - The public key bytes\n * @returns Object containing sharedSecret and ciphertext bytes\n */\nexport function mlkemEncapsulate(\n  level: MLKEMLevel,\n  publicKey: Uint8Array,\n): MLKEMEncapsulationResult {\n  switch (level) {\n    case MLKEMLevel.MLKEM512: {\n      const result = ml_kem512.encapsulate(publicKey);\n      return { sharedSecret: result.sharedSecret, ciphertext: result.cipherText };\n    }\n    case MLKEMLevel.MLKEM768: {\n      const result = ml_kem768.encapsulate(publicKey);\n      return { sharedSecret: result.sharedSecret, ciphertext: result.cipherText };\n    }\n    case MLKEMLevel.MLKEM1024: {\n      const result = ml_kem1024.encapsulate(publicKey);\n      return { sharedSecret: result.sharedSecret, ciphertext: result.cipherText };\n    }\n  }\n}\n\n/**\n * Decapsulate a shared secret using a private key and ciphertext.\n *\n * @param level - The ML-KEM security level\n * @param secretKey - The secret key bytes\n * @param ciphertext - The ciphertext bytes\n * @returns The shared secret bytes\n */\nexport function mlkemDecapsulate(\n  level: MLKEMLevel,\n  secretKey: Uint8Array,\n  ciphertext: Uint8Array,\n): Uint8Array {\n  switch (level) {\n    case MLKEMLevel.MLKEM512:\n      return ml_kem512.decapsulate(ciphertext, secretKey);\n    case MLKEMLevel.MLKEM768:\n      return ml_kem768.decapsulate(ciphertext, secretKey);\n    case MLKEMLevel.MLKEM1024:\n      return ml_kem1024.decapsulate(ciphertext, secretKey);\n  }\n}\n\n/**\n * Private key portion sizes for each ML-KEM level.\n * The decapsulation key structure is: dk = (dk_pke || ek_pke || H(ek) || z)\n * where dk_pke is the private portion before the public key.\n */\nconst MLKEM_DK_PKE_SIZES = {\n  [MLKEMLevel.MLKEM512]: 768, // 12 * 64\n  [MLKEMLevel.MLKEM768]: 1152, // 12 * 96\n  [MLKEMLevel.MLKEM1024]: 1536, // 12 * 128\n} as const;\n\n/**\n * Extract the public key from a secret key.\n *\n * In ML-KEM (FIPS 203), the decapsulation key contains the encapsulation key (public key)\n * embedded within it. The structure is: dk = (dk_pke || ek_pke || H(ek) || z)\n *\n * @param level - The ML-KEM security level\n * @param secretKey - The secret key bytes\n * @returns The public key bytes extracted from the secret key\n */\nexport function mlkemExtractPublicKey(level: MLKEMLevel, secretKey: Uint8Array): Uint8Array {\n  const dkPkeSize = MLKEM_DK_PKE_SIZES[level];\n  const publicKeySize = MLKEM_KEY_SIZES[level].publicKey;\n  const offset = dkPkeSize;\n  return secretKey.slice(offset, offset + publicKeySize);\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encapsulation scheme enum for key encapsulation mechanisms\n *\n * This enum represents the available key encapsulation mechanisms (KEMs)\n * for establishing shared secrets between parties.\n *\n * Supported schemes:\n * - X25519: Curve25519-based Diffie-Hellman key exchange (default)\n * - MLKEM512, MLKEM768, MLKEM1024: ML-KEM at various security levels\n *\n * Ported from bc-components-rust/src/encapsulation/encapsulation_scheme.rs\n */\n\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { EncapsulationPrivateKey } from \"./encapsulation-private-key.js\";\nimport type { EncapsulationPublicKey } from \"./encapsulation-public-key.js\";\nimport { MLKEMLevel } from \"../mlkem/mlkem-level.js\";\n\n/**\n * Available key encapsulation schemes.\n */\nexport enum EncapsulationScheme {\n  /**\n   * X25519 Diffie-Hellman key exchange (default).\n   * Based on Curve25519 as defined in RFC 7748.\n   */\n  X25519 = \"x25519\",\n\n  /**\n   * ML-KEM-512 post-quantum key encapsulation (NIST security level 1).\n   */\n  MLKEM512 = \"mlkem512\",\n\n  /**\n   * ML-KEM-768 post-quantum key encapsulation (NIST security level 3).\n   */\n  MLKEM768 = \"mlkem768\",\n\n  /**\n   * ML-KEM-1024 post-quantum key encapsulation (NIST security level 5).\n   */\n  MLKEM1024 = \"mlkem1024\",\n}\n\n/**\n * Returns the default encapsulation scheme (X25519).\n */\nexport function defaultEncapsulationScheme(): EncapsulationScheme {\n  return EncapsulationScheme.X25519;\n}\n\n/**\n * Check if a scheme is an MLKEM scheme.\n */\nexport function isMlkemScheme(scheme: EncapsulationScheme): boolean {\n  return (\n    scheme === EncapsulationScheme.MLKEM512 ||\n    scheme === EncapsulationScheme.MLKEM768 ||\n    scheme === EncapsulationScheme.MLKEM1024\n  );\n}\n\n/**\n * Convert EncapsulationScheme to MLKEMLevel.\n * @throws Error if scheme is not an MLKEM scheme\n */\nexport function schemeToMlkemLevel(scheme: EncapsulationScheme): MLKEMLevel {\n  switch (scheme) {\n    case EncapsulationScheme.X25519:\n      throw new Error(`Not an MLKEM scheme: ${String(scheme)}`);\n    case EncapsulationScheme.MLKEM512:\n      return MLKEMLevel.MLKEM512;\n    case EncapsulationScheme.MLKEM768:\n      return MLKEMLevel.MLKEM768;\n    case EncapsulationScheme.MLKEM1024:\n      return MLKEMLevel.MLKEM1024;\n  }\n}\n\n/**\n * Convert MLKEMLevel to EncapsulationScheme.\n */\nexport function mlkemLevelToScheme(level: MLKEMLevel): EncapsulationScheme {\n  switch (level) {\n    case MLKEMLevel.MLKEM512:\n      return EncapsulationScheme.MLKEM512;\n    case MLKEMLevel.MLKEM768:\n      return EncapsulationScheme.MLKEM768;\n    case MLKEMLevel.MLKEM1024:\n      return EncapsulationScheme.MLKEM1024;\n  }\n}\n\n/**\n * Generate a new keypair for the given encapsulation scheme.\n *\n * @param scheme - The encapsulation scheme to use (defaults to X25519)\n * @returns A tuple of [privateKey, publicKey]\n */\nexport function createEncapsulationKeypair(\n  scheme: EncapsulationScheme = EncapsulationScheme.X25519,\n): [EncapsulationPrivateKey, EncapsulationPublicKey] {\n  switch (scheme) {\n    case EncapsulationScheme.X25519:\n      return EncapsulationPrivateKey.keypair();\n    case EncapsulationScheme.MLKEM512:\n      return EncapsulationPrivateKey.mlkemKeypair(MLKEMLevel.MLKEM512);\n    case EncapsulationScheme.MLKEM768:\n      return EncapsulationPrivateKey.mlkemKeypair(MLKEMLevel.MLKEM768);\n    case EncapsulationScheme.MLKEM1024:\n      return EncapsulationPrivateKey.mlkemKeypair(MLKEMLevel.MLKEM1024);\n  }\n}\n\n/**\n * Generate a new keypair for the given encapsulation scheme using a specific RNG.\n *\n * Note: Only X25519 supports deterministic keypair generation.\n * MLKEM schemes do not support deterministic generation (matching Rust behavior).\n *\n * @param rng - The random number generator to use\n * @param scheme - The encapsulation scheme to use (defaults to X25519)\n * @returns A tuple of [privateKey, publicKey]\n * @throws Error if the scheme doesn't support deterministic generation\n */\nexport function createEncapsulationKeypairUsing(\n  rng: RandomNumberGenerator,\n  scheme: EncapsulationScheme = EncapsulationScheme.X25519,\n): [EncapsulationPrivateKey, EncapsulationPublicKey] {\n  switch (scheme) {\n    case EncapsulationScheme.X25519:\n      return EncapsulationPrivateKey.keypairUsing(rng);\n    case EncapsulationScheme.MLKEM512:\n    case EncapsulationScheme.MLKEM768:\n    case EncapsulationScheme.MLKEM1024:\n      // MLKEM doesn't support deterministic keypair generation (matching Rust behavior)\n      throw new Error(\n        \"Deterministic keypair generation not supported for this encapsulation scheme\",\n      );\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLKEMCiphertext - ML-KEM Ciphertext for post-quantum key encapsulation\n *\n * MLKEMCiphertext wraps an ML-KEM ciphertext for transmission and decapsulation.\n * It supports all three security levels (MLKEM512, MLKEM768, MLKEM1024).\n *\n * # CBOR Serialization\n *\n * MLKEMCiphertext is serialized with tag 40102:\n * ```\n * #6.40102([level, h'<ciphertext-bytes>'])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `mlkem-ciphertext`\n *\n * Ported from bc-components-rust/src/mlkem/mlkem_ciphertext.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  expectInteger,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { MLKEM_CIPHERTEXT as TAG_MLKEM_CIPHERTEXT } from \"@bcts/tags\";\n\nimport {\n  MLKEMLevel,\n  mlkemLevelFromValue,\n  mlkemLevelToString,\n  mlkemCiphertextSize,\n} from \"./mlkem-level.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * MLKEMCiphertext - Post-quantum key encapsulation ciphertext using ML-KEM.\n */\nexport class MLKEMCiphertext\n  implements CborTaggedEncodable, CborTaggedDecodable<MLKEMCiphertext>, UREncodable\n{\n  private readonly _level: MLKEMLevel;\n  private readonly _data: Uint8Array;\n\n  private constructor(level: MLKEMLevel, data: Uint8Array) {\n    const expectedSize = mlkemCiphertextSize(level);\n    if (data.length !== expectedSize) {\n      throw new Error(\n        `MLKEMCiphertext (${mlkemLevelToString(level)}) must be ${expectedSize} bytes, got ${data.length}`,\n      );\n    }\n    this._level = level;\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an MLKEMCiphertext from raw bytes.\n   *\n   * @param level - The ML-KEM security level\n   * @param data - The ciphertext bytes\n   */\n  static fromBytes(level: MLKEMLevel, data: Uint8Array): MLKEMCiphertext {\n    return new MLKEMCiphertext(level, data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the security level of this ciphertext.\n   */\n  level(): MLKEMLevel {\n    return this._level;\n  }\n\n  /**\n   * Returns the raw ciphertext bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw ciphertext bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the size of the ciphertext in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another MLKEMCiphertext.\n   */\n  equals(other: MLKEMCiphertext): boolean {\n    if (this._level !== other._level) return false;\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   * Get string representation.\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `MLKEMCiphertext(${mlkemLevelToString(this._level)}, ${hex.substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with MLKEMCiphertext.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_MLKEM_CIPHERTEXT.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [level, ciphertext_bytes]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._level, 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 an MLKEMCiphertext by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): MLKEMCiphertext {\n    const elements = expectArray(cborValue);\n    if (elements.length !== 2) {\n      throw new Error(`MLKEMCiphertext CBOR must have 2 elements, got ${elements.length}`);\n    }\n    const levelValue = Number(expectInteger(elements[0]));\n    const level = mlkemLevelFromValue(levelValue);\n    const data = expectBytes(elements[1]);\n    return MLKEMCiphertext.fromBytes(level, data);\n  }\n\n  /**\n   * Creates an MLKEMCiphertext by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): MLKEMCiphertext {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): MLKEMCiphertext {\n    // Create a minimal dummy instance for decoding\n    const dummyData = new Uint8Array(mlkemCiphertextSize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMCiphertext(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): MLKEMCiphertext {\n    const cborValue = decodeCbor(data);\n    return MLKEMCiphertext.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): MLKEMCiphertext {\n    const cborValue = decodeCbor(data);\n    const dummyData = new Uint8Array(mlkemCiphertextSize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMCiphertext(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_MLKEM_CIPHERTEXT.name;\n    if (name === undefined) {\n      throw new Error(\"MLKEM_CIPHERTEXT tag name is undefined\");\n    }\n    return UR.new(name, 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 an MLKEMCiphertext from a UR.\n   */\n  static fromUR(ur: UR): MLKEMCiphertext {\n    if (ur.urTypeStr() !== TAG_MLKEM_CIPHERTEXT.name) {\n      throw new Error(`Expected UR type ${TAG_MLKEM_CIPHERTEXT.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummyData = new Uint8Array(mlkemCiphertextSize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMCiphertext(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an MLKEMCiphertext from a UR string.\n   */\n  static fromURString(urString: string): MLKEMCiphertext {\n    const ur = UR.fromURString(urString);\n    return MLKEMCiphertext.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encapsulation ciphertext for key encapsulation mechanisms\n *\n * This type represents the ciphertext produced during key encapsulation.\n * For X25519, this is actually an ephemeral public key used in ECDH.\n * For MLKEM, this is the ciphertext from the ML-KEM encapsulation.\n *\n * # CBOR Serialization\n *\n * For X25519, the ciphertext is serialized with the X25519 public key tag (40011).\n * For MLKEM, the ciphertext is serialized with tag 40102.\n *\n * Ported from bc-components-rust/src/encapsulation/encapsulation_ciphertext.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  toByteString,\n  expectBytes,\n  createTaggedCbor,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  tagValue,\n} from \"@bcts/dcbor\";\nimport {\n  X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY,\n  MLKEM_CIPHERTEXT as TAG_MLKEM_CIPHERTEXT,\n} from \"@bcts/tags\";\nimport { X25519PublicKey } from \"../x25519/x25519-public-key.js\";\nimport { EncapsulationScheme } from \"./encapsulation-scheme.js\";\nimport { MLKEMCiphertext } from \"../mlkem/mlkem-ciphertext.js\";\nimport { MLKEMLevel } from \"../mlkem/mlkem-level.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * Convert MLKEMLevel to EncapsulationScheme\n */\nfunction mlkemLevelToScheme(level: MLKEMLevel): EncapsulationScheme {\n  switch (level) {\n    case MLKEMLevel.MLKEM512:\n      return EncapsulationScheme.MLKEM512;\n    case MLKEMLevel.MLKEM768:\n      return EncapsulationScheme.MLKEM768;\n    case MLKEMLevel.MLKEM1024:\n      return EncapsulationScheme.MLKEM1024;\n  }\n}\n\n/**\n * Check if a scheme is an MLKEM scheme\n */\nfunction isMlkemScheme(scheme: EncapsulationScheme): boolean {\n  return (\n    scheme === EncapsulationScheme.MLKEM512 ||\n    scheme === EncapsulationScheme.MLKEM768 ||\n    scheme === EncapsulationScheme.MLKEM1024\n  );\n}\n\n/**\n * Represents the ciphertext from a key encapsulation operation.\n *\n * For X25519, this wraps an ephemeral public key.\n * For MLKEM, this wraps an MLKEMCiphertext.\n */\nexport class EncapsulationCiphertext\n  implements CborTaggedEncodable, CborTaggedDecodable<EncapsulationCiphertext>\n{\n  private readonly _scheme: EncapsulationScheme;\n  private readonly _x25519PublicKey: X25519PublicKey | undefined;\n  private readonly _mlkemCiphertext: MLKEMCiphertext | undefined;\n\n  private constructor(\n    scheme: EncapsulationScheme,\n    x25519PublicKey?: X25519PublicKey,\n    mlkemCiphertext?: MLKEMCiphertext,\n  ) {\n    this._scheme = scheme;\n    this._x25519PublicKey = x25519PublicKey;\n    this._mlkemCiphertext = mlkemCiphertext;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an EncapsulationCiphertext from an X25519PublicKey.\n   */\n  static fromX25519PublicKey(publicKey: X25519PublicKey): EncapsulationCiphertext {\n    return new EncapsulationCiphertext(EncapsulationScheme.X25519, publicKey, undefined);\n  }\n\n  /**\n   * Create an EncapsulationCiphertext from raw X25519 data.\n   */\n  static fromX25519Data(data: Uint8Array): EncapsulationCiphertext {\n    const publicKey = X25519PublicKey.fromDataRef(data);\n    return EncapsulationCiphertext.fromX25519PublicKey(publicKey);\n  }\n\n  /**\n   * Create an EncapsulationCiphertext from an MLKEMCiphertext.\n   */\n  static fromMlkem(ciphertext: MLKEMCiphertext): EncapsulationCiphertext {\n    const scheme = mlkemLevelToScheme(ciphertext.level());\n    return new EncapsulationCiphertext(scheme, undefined, ciphertext);\n  }\n\n  /**\n   * Create an EncapsulationCiphertext from raw MLKEM ciphertext bytes.\n   */\n  static fromMlkemData(level: MLKEMLevel, data: Uint8Array): EncapsulationCiphertext {\n    const ciphertext = MLKEMCiphertext.fromBytes(level, data);\n    return EncapsulationCiphertext.fromMlkem(ciphertext);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the encapsulation scheme.\n   */\n  encapsulationScheme(): EncapsulationScheme {\n    return this._scheme;\n  }\n\n  /**\n   * Returns true if this is an X25519 ciphertext.\n   */\n  isX25519(): boolean {\n    return this._scheme === EncapsulationScheme.X25519;\n  }\n\n  /**\n   * Returns true if this is an MLKEM ciphertext.\n   */\n  isMlkem(): boolean {\n    return isMlkemScheme(this._scheme);\n  }\n\n  /**\n   * Returns the X25519 public key if this is an X25519 ciphertext.\n   * @throws Error if this is not an X25519 ciphertext\n   */\n  x25519PublicKey(): X25519PublicKey {\n    if (this._x25519PublicKey === undefined) {\n      throw new Error(\"Not an X25519 ciphertext\");\n    }\n    return this._x25519PublicKey;\n  }\n\n  /**\n   * Returns the MLKEM ciphertext if this is an MLKEM ciphertext.\n   * @throws Error if this is not an MLKEM ciphertext\n   */\n  mlkemCiphertext(): MLKEMCiphertext {\n    if (this._mlkemCiphertext === undefined) {\n      throw new Error(\"Not an MLKEM ciphertext\");\n    }\n    return this._mlkemCiphertext;\n  }\n\n  /**\n   * Returns the X25519 public key if available, or null.\n   */\n  toX25519(): X25519PublicKey | null {\n    return this._x25519PublicKey ?? null;\n  }\n\n  /**\n   * Returns the MLKEM ciphertext if available, or null.\n   */\n  toMlkem(): MLKEMCiphertext | null {\n    return this._mlkemCiphertext ?? null;\n  }\n\n  /**\n   * Returns the raw ciphertext data.\n   */\n  data(): Uint8Array {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PublicKey;\n      if (pk === undefined) throw new Error(\"X25519 public key not set\");\n      return pk.data();\n    } else if (isMlkemScheme(this._scheme)) {\n      const ct = this._mlkemCiphertext;\n      if (ct === undefined) throw new Error(\"MLKEM ciphertext not set\");\n      return ct.data();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Compare with another EncapsulationCiphertext.\n   */\n  equals(other: EncapsulationCiphertext): boolean {\n    if (this._scheme !== other._scheme) return false;\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const thisPk = this._x25519PublicKey;\n      const otherPk = other._x25519PublicKey;\n      if (thisPk === undefined || otherPk === undefined) return false;\n      return thisPk.equals(otherPk);\n    } else if (isMlkemScheme(this._scheme)) {\n      const thisCt = this._mlkemCiphertext;\n      const otherCt = other._mlkemCiphertext;\n      if (thisCt === undefined || otherCt === undefined) return false;\n      return thisCt.equals(otherCt);\n    }\n    return false;\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      return `EncapsulationCiphertext(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n    } else if (isMlkemScheme(this._scheme)) {\n      return `EncapsulationCiphertext(${String(this._scheme)}, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n    }\n    return `EncapsulationCiphertext(${String(this._scheme)})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with this ciphertext.\n   */\n  cborTags(): Tag[] {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      return tagsForValues([TAG_X25519_PUBLIC_KEY.value]);\n    } else if (isMlkemScheme(this._scheme)) {\n      return tagsForValues([TAG_MLKEM_CIPHERTEXT.value]);\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   */\n  untaggedCbor(): Cbor {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PublicKey;\n      if (pk === undefined) throw new Error(\"X25519 public key not set\");\n      return toByteString(pk.data());\n    } else if (isMlkemScheme(this._scheme)) {\n      const ct = this._mlkemCiphertext;\n      if (ct === undefined) throw new Error(\"MLKEM ciphertext not set\");\n      return ct.untaggedCbor();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 an EncapsulationCiphertext by decoding it from untagged CBOR.\n   * Note: Without tags, we assume X25519 scheme.\n   */\n  fromUntaggedCbor(cborValue: Cbor): EncapsulationCiphertext {\n    const data = expectBytes(cborValue);\n    const publicKey = X25519PublicKey.fromDataRef(data);\n    return EncapsulationCiphertext.fromX25519PublicKey(publicKey);\n  }\n\n  /**\n   * Creates an EncapsulationCiphertext by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): EncapsulationCiphertext {\n    const tag = tagValue(cborValue);\n\n    if (tag === TAG_X25519_PUBLIC_KEY.value) {\n      const content = extractTaggedContent(cborValue);\n      const data = expectBytes(content);\n      const publicKey = X25519PublicKey.fromDataRef(data);\n      return EncapsulationCiphertext.fromX25519PublicKey(publicKey);\n    }\n\n    if (tag === TAG_MLKEM_CIPHERTEXT.value) {\n      const mlkemCiphertext = MLKEMCiphertext.fromTaggedCbor(cborValue);\n      return EncapsulationCiphertext.fromMlkem(mlkemCiphertext);\n    }\n\n    throw new Error(`Unknown ciphertext tag: ${tag}`);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): EncapsulationCiphertext {\n    const dummy = EncapsulationCiphertext.fromX25519PublicKey(\n      X25519PublicKey.fromData(new Uint8Array(32)),\n    );\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): EncapsulationCiphertext {\n    const cborValue = decodeCbor(data);\n    return EncapsulationCiphertext.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): EncapsulationCiphertext {\n    const cborValue = decodeCbor(data);\n    const dummy = EncapsulationCiphertext.fromX25519PublicKey(\n      X25519PublicKey.fromData(new Uint8Array(32)),\n    );\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLKEMPublicKey - ML-KEM Public Key for post-quantum key encapsulation\n *\n * MLKEMPublicKey wraps an ML-KEM public key for encapsulating shared secrets.\n * It supports all three security levels (MLKEM512, MLKEM768, MLKEM1024).\n *\n * # CBOR Serialization\n *\n * MLKEMPublicKey is serialized with tag 40101:\n * ```\n * #6.40101([level, h'<public-key-bytes>'])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `mlkem-public-key`\n *\n * Ported from bc-components-rust/src/mlkem/mlkem_public_key.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  expectInteger,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { MLKEM_PUBLIC_KEY as TAG_MLKEM_PUBLIC_KEY } from \"@bcts/tags\";\n\nimport {\n  MLKEMLevel,\n  mlkemLevelFromValue,\n  mlkemLevelToString,\n  mlkemPublicKeySize,\n  mlkemEncapsulate,\n} from \"./mlkem-level.js\";\nimport { MLKEMCiphertext } from \"./mlkem-ciphertext.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * Result of encapsulation operation.\n */\nexport interface MLKEMEncapsulationPair {\n  /** The shared secret as a SymmetricKey */\n  sharedSecret: SymmetricKey;\n  /** The ciphertext to send to the private key holder */\n  ciphertext: MLKEMCiphertext;\n}\n\n/**\n * MLKEMPublicKey - Post-quantum key encapsulation public key using ML-KEM.\n */\nexport class MLKEMPublicKey\n  implements CborTaggedEncodable, CborTaggedDecodable<MLKEMPublicKey>, UREncodable\n{\n  private readonly _level: MLKEMLevel;\n  private readonly _data: Uint8Array;\n\n  private constructor(level: MLKEMLevel, data: Uint8Array) {\n    const expectedSize = mlkemPublicKeySize(level);\n    if (data.length !== expectedSize) {\n      throw new Error(\n        `MLKEMPublicKey (${mlkemLevelToString(level)}) must be ${expectedSize} bytes, got ${data.length}`,\n      );\n    }\n    this._level = level;\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an MLKEMPublicKey from raw bytes.\n   *\n   * @param level - The ML-KEM security level\n   * @param data - The public key bytes\n   */\n  static fromBytes(level: MLKEMLevel, data: Uint8Array): MLKEMPublicKey {\n    return new MLKEMPublicKey(level, data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the security level of this key.\n   */\n  level(): MLKEMLevel {\n    return this._level;\n  }\n\n  /**\n   * Returns the raw key bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw key bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the size of the key in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  /**\n   * Encapsulate a new shared secret.\n   *\n   * This creates a random shared secret and encapsulates it, returning both\n   * the shared secret (to be used as a symmetric key) and the ciphertext\n   * (to be sent to the private key holder for decapsulation).\n   *\n   * @returns Object containing sharedSecret and ciphertext\n   */\n  encapsulate(): MLKEMEncapsulationPair {\n    const result = mlkemEncapsulate(this._level, this._data);\n    const sharedSecret = SymmetricKey.fromData(result.sharedSecret);\n    const ciphertext = MLKEMCiphertext.fromBytes(this._level, result.ciphertext);\n    return { sharedSecret, ciphertext };\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another MLKEMPublicKey.\n   */\n  equals(other: MLKEMPublicKey): boolean {\n    if (this._level !== other._level) return false;\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   * Get string representation.\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `MLKEMPublicKey(${mlkemLevelToString(this._level)}, ${hex.substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with MLKEMPublicKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_MLKEM_PUBLIC_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [level, key_bytes]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._level, 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 an MLKEMPublicKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): MLKEMPublicKey {\n    const elements = expectArray(cborValue);\n    if (elements.length !== 2) {\n      throw new Error(`MLKEMPublicKey CBOR must have 2 elements, got ${elements.length}`);\n    }\n    const levelValue = Number(expectInteger(elements[0]));\n    const level = mlkemLevelFromValue(levelValue);\n    const data = expectBytes(elements[1]);\n    return MLKEMPublicKey.fromBytes(level, data);\n  }\n\n  /**\n   * Creates an MLKEMPublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): MLKEMPublicKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): MLKEMPublicKey {\n    // Create a minimal dummy instance for decoding\n    const dummyData = new Uint8Array(mlkemPublicKeySize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMPublicKey(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): MLKEMPublicKey {\n    const cborValue = decodeCbor(data);\n    return MLKEMPublicKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): MLKEMPublicKey {\n    const cborValue = decodeCbor(data);\n    const dummyData = new Uint8Array(mlkemPublicKeySize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMPublicKey(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_MLKEM_PUBLIC_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"MLKEM_PUBLIC_KEY tag name is undefined\");\n    }\n    return UR.new(name, 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 an MLKEMPublicKey from a UR.\n   */\n  static fromUR(ur: UR): MLKEMPublicKey {\n    if (ur.urTypeStr() !== TAG_MLKEM_PUBLIC_KEY.name) {\n      throw new Error(`Expected UR type ${TAG_MLKEM_PUBLIC_KEY.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummyData = new Uint8Array(mlkemPublicKeySize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMPublicKey(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an MLKEMPublicKey from a UR string.\n   */\n  static fromURString(urString: string): MLKEMPublicKey {\n    const ur = UR.fromURString(urString);\n    return MLKEMPublicKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encapsulation public key for key encapsulation mechanisms\n *\n * This type represents a public key that can be used to encapsulate (encrypt)\n * a shared secret. The recipient can then use their corresponding private key\n * to decapsulate (decrypt) the shared secret.\n *\n * For X25519, encapsulation works by:\n * 1. Generating an ephemeral key pair\n * 2. Performing ECDH with the ephemeral private key and the recipient's public key\n * 3. Returning the shared secret and the ephemeral public key as \"ciphertext\"\n *\n * For MLKEM, encapsulation uses the ML-KEM algorithm to generate a shared secret\n * and ciphertext.\n *\n * # CBOR Serialization\n *\n * For X25519, the public key is serialized with tag 40011.\n * For MLKEM, the public key is serialized with tag 40101.\n *\n * Ported from bc-components-rust/src/encapsulation/encapsulation_public_key.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  toByteString,\n  expectBytes,\n  createTaggedCbor,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  tagValue,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport {\n  X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY,\n  MLKEM_PUBLIC_KEY as TAG_MLKEM_PUBLIC_KEY,\n} from \"@bcts/tags\";\nimport { X25519PrivateKey } from \"../x25519/x25519-private-key.js\";\nimport { X25519PublicKey } from \"../x25519/x25519-public-key.js\";\nimport { type SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { EncapsulationScheme } from \"./encapsulation-scheme.js\";\nimport { EncapsulationCiphertext } from \"./encapsulation-ciphertext.js\";\nimport { MLKEMPublicKey } from \"../mlkem/mlkem-public-key.js\";\nimport { MLKEMLevel } from \"../mlkem/mlkem-level.js\";\nimport { Reference, type ReferenceProvider } from \"../reference.js\";\nimport { Digest } from \"../digest.js\";\n\n/**\n * Convert MLKEMLevel to EncapsulationScheme\n */\nfunction mlkemLevelToScheme(level: MLKEMLevel): EncapsulationScheme {\n  switch (level) {\n    case MLKEMLevel.MLKEM512:\n      return EncapsulationScheme.MLKEM512;\n    case MLKEMLevel.MLKEM768:\n      return EncapsulationScheme.MLKEM768;\n    case MLKEMLevel.MLKEM1024:\n      return EncapsulationScheme.MLKEM1024;\n  }\n}\n\n/**\n * Check if a scheme is an MLKEM scheme\n */\nfunction isMlkemScheme(scheme: EncapsulationScheme): boolean {\n  return (\n    scheme === EncapsulationScheme.MLKEM512 ||\n    scheme === EncapsulationScheme.MLKEM768 ||\n    scheme === EncapsulationScheme.MLKEM1024\n  );\n}\n\n/**\n * Represents a public key for key encapsulation.\n *\n * Use this to encapsulate a shared secret for a recipient.\n */\nexport class EncapsulationPublicKey\n  implements\n    ReferenceProvider,\n    CborTaggedEncodable,\n    CborTaggedDecodable<EncapsulationPublicKey>,\n    UREncodable\n{\n  private readonly _scheme: EncapsulationScheme;\n  private readonly _x25519PublicKey: X25519PublicKey | undefined;\n  private readonly _mlkemPublicKey: MLKEMPublicKey | undefined;\n\n  private constructor(\n    scheme: EncapsulationScheme,\n    x25519PublicKey?: X25519PublicKey,\n    mlkemPublicKey?: MLKEMPublicKey,\n  ) {\n    this._scheme = scheme;\n    this._x25519PublicKey = x25519PublicKey;\n    this._mlkemPublicKey = mlkemPublicKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an EncapsulationPublicKey from an X25519PublicKey.\n   */\n  static fromX25519PublicKey(publicKey: X25519PublicKey): EncapsulationPublicKey {\n    return new EncapsulationPublicKey(EncapsulationScheme.X25519, publicKey, undefined);\n  }\n\n  /**\n   * Create an EncapsulationPublicKey from raw X25519 public key bytes.\n   */\n  static fromX25519Data(data: Uint8Array): EncapsulationPublicKey {\n    const publicKey = X25519PublicKey.fromDataRef(data);\n    return EncapsulationPublicKey.fromX25519PublicKey(publicKey);\n  }\n\n  /**\n   * Create an EncapsulationPublicKey from an MLKEMPublicKey.\n   */\n  static fromMlkem(publicKey: MLKEMPublicKey): EncapsulationPublicKey {\n    const scheme = mlkemLevelToScheme(publicKey.level());\n    return new EncapsulationPublicKey(scheme, undefined, publicKey);\n  }\n\n  /**\n   * Create an EncapsulationPublicKey from raw MLKEM public key bytes.\n   */\n  static fromMlkemData(level: MLKEMLevel, data: Uint8Array): EncapsulationPublicKey {\n    const publicKey = MLKEMPublicKey.fromBytes(level, data);\n    return EncapsulationPublicKey.fromMlkem(publicKey);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the encapsulation scheme.\n   */\n  encapsulationScheme(): EncapsulationScheme {\n    return this._scheme;\n  }\n\n  /**\n   * Returns true if this is an X25519 public key.\n   */\n  isX25519(): boolean {\n    return this._scheme === EncapsulationScheme.X25519;\n  }\n\n  /**\n   * Returns true if this is an MLKEM public key.\n   */\n  isMlkem(): boolean {\n    return isMlkemScheme(this._scheme);\n  }\n\n  /**\n   * Returns the X25519 public key if this is an X25519 encapsulation key.\n   * @throws Error if this is not an X25519 key\n   */\n  x25519PublicKey(): X25519PublicKey {\n    if (this._x25519PublicKey === undefined) {\n      throw new Error(\"Not an X25519 public key\");\n    }\n    return this._x25519PublicKey;\n  }\n\n  /**\n   * Returns the MLKEM public key if this is an MLKEM encapsulation key.\n   * @throws Error if this is not an MLKEM key\n   */\n  mlkemPublicKey(): MLKEMPublicKey {\n    if (this._mlkemPublicKey === undefined) {\n      throw new Error(\"Not an MLKEM public key\");\n    }\n    return this._mlkemPublicKey;\n  }\n\n  /**\n   * Returns the X25519 public key if available, or null.\n   */\n  toX25519(): X25519PublicKey | null {\n    return this._x25519PublicKey ?? null;\n  }\n\n  /**\n   * Returns the MLKEM public key if available, or null.\n   */\n  toMlkem(): MLKEMPublicKey | null {\n    return this._mlkemPublicKey ?? null;\n  }\n\n  /**\n   * Returns the raw public key data.\n   */\n  data(): Uint8Array {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PublicKey;\n      if (pk === undefined) throw new Error(\"X25519 public key not set\");\n      return pk.data();\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPublicKey;\n      if (pk === undefined) throw new Error(\"MLKEM public key not set\");\n      return pk.data();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Returns this object as an EncapsulationPublicKey.\n   *\n   * This method allows EncapsulationPublicKey to implement the Encrypter interface.\n   * Since this class is itself an encapsulation public key, it returns `this`.\n   *\n   * @returns This encapsulation public key\n   */\n  encapsulationPublicKey(): EncapsulationPublicKey {\n    return this;\n  }\n\n  /**\n   * Encapsulate a new shared secret for this public key.\n   *\n   * This generates a random shared secret and encapsulates it so that only\n   * the holder of the corresponding private key can recover it.\n   *\n   * @returns A tuple of [sharedSecret, ciphertext]\n   */\n  encapsulateNewSharedSecret(): [SymmetricKey, EncapsulationCiphertext] {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PublicKey;\n      if (pk === undefined) throw new Error(\"X25519 public key not set\");\n      // Generate ephemeral key pair\n      const [ephemeralPrivate, ephemeralPublic] = X25519PrivateKey.keypair();\n\n      // Perform ECDH to get shared secret\n      const sharedSecret = ephemeralPrivate.sharedKeyWith(pk);\n\n      // The \"ciphertext\" is the ephemeral public key\n      const ciphertext = EncapsulationCiphertext.fromX25519PublicKey(ephemeralPublic);\n\n      return [sharedSecret, ciphertext];\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPublicKey;\n      if (pk === undefined) throw new Error(\"MLKEM public key not set\");\n\n      // Encapsulate using MLKEM\n      const { sharedSecret, ciphertext: mlkemCiphertext } = pk.encapsulate();\n\n      // Wrap in EncapsulationCiphertext\n      const ciphertext = EncapsulationCiphertext.fromMlkem(mlkemCiphertext);\n\n      return [sharedSecret, ciphertext];\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Compare with another EncapsulationPublicKey.\n   */\n  equals(other: EncapsulationPublicKey): boolean {\n    if (this._scheme !== other._scheme) return false;\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const thisPk = this._x25519PublicKey;\n      const otherPk = other._x25519PublicKey;\n      if (thisPk === undefined || otherPk === undefined) return false;\n      return thisPk.equals(otherPk);\n    } else if (isMlkemScheme(this._scheme)) {\n      const thisPk = this._mlkemPublicKey;\n      const otherPk = other._mlkemPublicKey;\n      if (thisPk === undefined || otherPk === undefined) return false;\n      return thisPk.equals(otherPk);\n    }\n    return false;\n  }\n\n  /**\n   * Get string representation.\n   *\n   * Mirrors Rust `Display for EncapsulationPublicKey`\n   * (`bc-components-rust/src/encapsulation/encapsulation_public_key.rs:191-205`):\n   *   `EncapsulationPublicKey(<ref_hex_short>, <inner_key_display>)`\n   * where ref_hex_short is computed from the tagged-CBOR form.\n   */\n  toString(): string {\n    const refShort = this.reference().shortReference(\"hex\");\n    let innerDisplay: string;\n    if (this._scheme === EncapsulationScheme.X25519 && this._x25519PublicKey !== undefined) {\n      innerDisplay = this._x25519PublicKey.toString();\n    } else if (isMlkemScheme(this._scheme) && this._mlkemPublicKey !== undefined) {\n      innerDisplay = this._mlkemPublicKey.toString();\n    } else {\n      innerDisplay = String(this._scheme);\n    }\n    return `EncapsulationPublicKey(${refShort}, ${innerDisplay})`;\n  }\n\n  // ============================================================================\n  // ReferenceProvider Interface\n  // ============================================================================\n\n  /**\n   * Returns a unique reference to this EncapsulationPublicKey instance.\n   *\n   * The reference is derived from the SHA-256 hash of the tagged CBOR\n   * representation, providing a unique, content-addressable identifier.\n   */\n  reference(): Reference {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return Reference.from(digest);\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with this public key.\n   */\n  cborTags(): Tag[] {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      return tagsForValues([TAG_X25519_PUBLIC_KEY.value]);\n    } else if (isMlkemScheme(this._scheme)) {\n      return tagsForValues([TAG_MLKEM_PUBLIC_KEY.value]);\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   */\n  untaggedCbor(): Cbor {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PublicKey;\n      if (pk === undefined) throw new Error(\"X25519 public key not set\");\n      return toByteString(pk.data());\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPublicKey;\n      if (pk === undefined) throw new Error(\"MLKEM public key not set\");\n      return pk.untaggedCbor();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 an EncapsulationPublicKey by decoding it from untagged CBOR.\n   * Note: Without tags, we assume X25519 scheme.\n   */\n  fromUntaggedCbor(cborValue: Cbor): EncapsulationPublicKey {\n    const data = expectBytes(cborValue);\n    const publicKey = X25519PublicKey.fromDataRef(data);\n    return EncapsulationPublicKey.fromX25519PublicKey(publicKey);\n  }\n\n  /**\n   * Creates an EncapsulationPublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): EncapsulationPublicKey {\n    const tag = tagValue(cborValue);\n\n    if (tag === TAG_X25519_PUBLIC_KEY.value) {\n      const content = extractTaggedContent(cborValue);\n      const data = expectBytes(content);\n      const publicKey = X25519PublicKey.fromDataRef(data);\n      return EncapsulationPublicKey.fromX25519PublicKey(publicKey);\n    }\n\n    if (tag === TAG_MLKEM_PUBLIC_KEY.value) {\n      const mlkemPublic = MLKEMPublicKey.fromTaggedCbor(cborValue);\n      return EncapsulationPublicKey.fromMlkem(mlkemPublic);\n    }\n\n    throw new Error(`Unknown public key tag: ${tag}`);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): EncapsulationPublicKey {\n    const dummy = EncapsulationPublicKey.fromX25519PublicKey(\n      X25519PublicKey.fromData(new Uint8Array(32)),\n    );\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): EncapsulationPublicKey {\n    const cborValue = decodeCbor(data);\n    return EncapsulationPublicKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): EncapsulationPublicKey {\n    const cborValue = decodeCbor(data);\n    const dummy = EncapsulationPublicKey.fromX25519PublicKey(\n      X25519PublicKey.fromData(new Uint8Array(32)),\n    );\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const name = TAG_X25519_PUBLIC_KEY.name;\n      if (name === undefined) throw new Error(\"TAG_X25519_PUBLIC_KEY.name is undefined\");\n      return UR.new(name, this.untaggedCbor());\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPublicKey;\n      if (pk === undefined) throw new Error(\"MLKEM public key not set\");\n      return pk.ur();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Returns the UR string representation.\n   */\n  urString(): string {\n    return this.ur().string();\n  }\n\n  /**\n   * Creates an EncapsulationPublicKey from a UR.\n   */\n  static fromUR(ur: UR): EncapsulationPublicKey {\n    // Check for known UR types\n    if (ur.urTypeStr() === TAG_X25519_PUBLIC_KEY.name) {\n      const dummy = EncapsulationPublicKey.fromX25519PublicKey(\n        X25519PublicKey.fromData(new Uint8Array(32)),\n      );\n      return dummy.fromUntaggedCbor(ur.cbor());\n    }\n\n    if (ur.urTypeStr() === TAG_MLKEM_PUBLIC_KEY.name) {\n      const mlkemPublic = MLKEMPublicKey.fromUR(ur);\n      return EncapsulationPublicKey.fromMlkem(mlkemPublic);\n    }\n\n    throw new Error(`Unknown UR type for EncapsulationPublicKey: ${ur.urTypeStr()}`);\n  }\n\n  /**\n   * Creates an EncapsulationPublicKey from a UR string.\n   */\n  static fromURString(urString: string): EncapsulationPublicKey {\n    const ur = UR.fromURString(urString);\n    return EncapsulationPublicKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * MLKEMPrivateKey - ML-KEM Private Key for post-quantum key decapsulation\n *\n * MLKEMPrivateKey wraps an ML-KEM secret key for decapsulating shared secrets.\n * It supports all three security levels (MLKEM512, MLKEM768, MLKEM1024).\n *\n * # CBOR Serialization\n *\n * MLKEMPrivateKey is serialized with tag 40100:\n * ```\n * #6.40100([level, h'<private-key-bytes>'])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `mlkem-private-key`\n *\n * Ported from bc-components-rust/src/mlkem/mlkem_private_key.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  expectInteger,\n  expectBytes,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { MLKEM_PRIVATE_KEY as TAG_MLKEM_PRIVATE_KEY } from \"@bcts/tags\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\n\nimport {\n  MLKEMLevel,\n  mlkemLevelFromValue,\n  mlkemLevelToString,\n  mlkemPrivateKeySize,\n  mlkemGenerateKeypairUsing,\n  mlkemDecapsulate,\n  mlkemExtractPublicKey,\n} from \"./mlkem-level.js\";\nimport { MLKEMPublicKey } from \"./mlkem-public-key.js\";\nimport type { MLKEMCiphertext } from \"./mlkem-ciphertext.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * MLKEMPrivateKey - Post-quantum key decapsulation private key using ML-KEM.\n */\nexport class MLKEMPrivateKey\n  implements CborTaggedEncodable, CborTaggedDecodable<MLKEMPrivateKey>, UREncodable\n{\n  private readonly _level: MLKEMLevel;\n  private readonly _data: Uint8Array;\n\n  private constructor(level: MLKEMLevel, data: Uint8Array) {\n    const expectedSize = mlkemPrivateKeySize(level);\n    if (data.length !== expectedSize) {\n      throw new Error(\n        `MLKEMPrivateKey (${mlkemLevelToString(level)}) must be ${expectedSize} bytes, got ${data.length}`,\n      );\n    }\n    this._level = level;\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Generate a new random MLKEMPrivateKey with the specified security level.\n   *\n   * @param level - The ML-KEM security level (default: MLKEM768)\n   */\n  static new(level: MLKEMLevel = MLKEMLevel.MLKEM768): MLKEMPrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return MLKEMPrivateKey.newUsing(level, rng);\n  }\n\n  /**\n   * Generate a new random MLKEMPrivateKey using the provided RNG.\n   *\n   * @param level - The ML-KEM security level\n   * @param rng - Random number generator\n   */\n  static newUsing(level: MLKEMLevel, rng: RandomNumberGenerator): MLKEMPrivateKey {\n    const keypair = mlkemGenerateKeypairUsing(level, rng);\n    return new MLKEMPrivateKey(level, keypair.secretKey);\n  }\n\n  /**\n   * Create an MLKEMPrivateKey from raw bytes.\n   *\n   * @param level - The ML-KEM security level\n   * @param data - The private key bytes\n   */\n  static fromBytes(level: MLKEMLevel, data: Uint8Array): MLKEMPrivateKey {\n    return new MLKEMPrivateKey(level, data);\n  }\n\n  /**\n   * Generate a keypair and return both private and public keys.\n   *\n   * @param level - The ML-KEM security level (default: MLKEM768)\n   * @returns Tuple of [privateKey, publicKey]\n   */\n  static keypair(level: MLKEMLevel = MLKEMLevel.MLKEM768): [MLKEMPrivateKey, MLKEMPublicKey] {\n    const rng = new SecureRandomNumberGenerator();\n    return MLKEMPrivateKey.keypairUsing(level, rng);\n  }\n\n  /**\n   * Generate a keypair using the provided RNG.\n   *\n   * @param level - The ML-KEM security level\n   * @param rng - Random number generator\n   * @returns Tuple of [privateKey, publicKey]\n   */\n  static keypairUsing(\n    level: MLKEMLevel,\n    rng: RandomNumberGenerator,\n  ): [MLKEMPrivateKey, MLKEMPublicKey] {\n    const keypairData = mlkemGenerateKeypairUsing(level, rng);\n    const privateKey = new MLKEMPrivateKey(level, keypairData.secretKey);\n    const publicKey = MLKEMPublicKey.fromBytes(level, keypairData.publicKey);\n    return [privateKey, publicKey];\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the security level of this key.\n   */\n  level(): MLKEMLevel {\n    return this._level;\n  }\n\n  /**\n   * Returns the raw key bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw key bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the size of the key in bytes.\n   */\n  size(): number {\n    return this._data.length;\n  }\n\n  /**\n   * Decapsulate a shared secret from a ciphertext.\n   *\n   * @param ciphertext - The ML-KEM ciphertext\n   * @returns The decapsulated shared secret as a SymmetricKey\n   */\n  decapsulate(ciphertext: MLKEMCiphertext): SymmetricKey {\n    if (ciphertext.level() !== this._level) {\n      throw new Error(\n        `Ciphertext level (${mlkemLevelToString(ciphertext.level())}) does not match key level (${mlkemLevelToString(this._level)})`,\n      );\n    }\n    const sharedSecret = mlkemDecapsulate(this._level, this._data, ciphertext.asBytes());\n    return SymmetricKey.fromData(sharedSecret);\n  }\n\n  /**\n   * Derives and returns the corresponding public key.\n   *\n   * In ML-KEM (FIPS 203), the decapsulation key contains the encapsulation key (public key)\n   * embedded within it. This method extracts that public key.\n   *\n   * @returns The corresponding MLKEMPublicKey\n   */\n  publicKey(): MLKEMPublicKey {\n    const publicKeyData = mlkemExtractPublicKey(this._level, this._data);\n    return MLKEMPublicKey.fromBytes(this._level, publicKeyData);\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another MLKEMPrivateKey.\n   */\n  equals(other: MLKEMPrivateKey): boolean {\n    if (this._level !== other._level) return false;\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   * Get string representation (truncated for security).\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `MLKEMPrivateKey(${mlkemLevelToString(this._level)}, ${hex.substring(0, 8)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with MLKEMPrivateKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_MLKEM_PRIVATE_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [level, key_bytes]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._level, 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 an MLKEMPrivateKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): MLKEMPrivateKey {\n    const elements = expectArray(cborValue);\n    if (elements.length !== 2) {\n      throw new Error(`MLKEMPrivateKey CBOR must have 2 elements, got ${elements.length}`);\n    }\n    const levelValue = Number(expectInteger(elements[0]));\n    const level = mlkemLevelFromValue(levelValue);\n    const data = expectBytes(elements[1]);\n    return MLKEMPrivateKey.fromBytes(level, data);\n  }\n\n  /**\n   * Creates an MLKEMPrivateKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): MLKEMPrivateKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): MLKEMPrivateKey {\n    // Create a minimal dummy instance for decoding\n    const dummyData = new Uint8Array(mlkemPrivateKeySize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMPrivateKey(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): MLKEMPrivateKey {\n    const cborValue = decodeCbor(data);\n    return MLKEMPrivateKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): MLKEMPrivateKey {\n    const cborValue = decodeCbor(data);\n    const dummyData = new Uint8Array(mlkemPrivateKeySize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMPrivateKey(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_MLKEM_PRIVATE_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"MLKEM_PRIVATE_KEY tag name is undefined\");\n    }\n    return UR.new(name, 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 an MLKEMPrivateKey from a UR.\n   */\n  static fromUR(ur: UR): MLKEMPrivateKey {\n    if (ur.urTypeStr() !== TAG_MLKEM_PRIVATE_KEY.name) {\n      throw new Error(`Expected UR type ${TAG_MLKEM_PRIVATE_KEY.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummyData = new Uint8Array(mlkemPrivateKeySize(MLKEMLevel.MLKEM512));\n    const dummy = new MLKEMPrivateKey(MLKEMLevel.MLKEM512, dummyData);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates an MLKEMPrivateKey from a UR string.\n   */\n  static fromURString(urString: string): MLKEMPrivateKey {\n    const ur = UR.fromURString(urString);\n    return MLKEMPrivateKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encapsulation private key for key encapsulation mechanisms\n *\n * This type represents a private key that can be used to decapsulate (decrypt)\n * a shared secret that was encapsulated using the corresponding public key.\n *\n * For X25519, decapsulation works by:\n * 1. Receiving the ephemeral public key (ciphertext)\n * 2. Performing ECDH with the private key and the ephemeral public key\n * 3. Returning the shared secret\n *\n * For MLKEM, decapsulation uses the ML-KEM algorithm to recover the shared secret.\n *\n * # CBOR Serialization\n *\n * For X25519, the private key is serialized with tag 40010.\n * For MLKEM, the private key is serialized with tag 40100.\n *\n * Ported from bc-components-rust/src/encapsulation/encapsulation_private_key.rs\n */\n\nimport { SecureRandomNumberGenerator, type RandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  toByteString,\n  expectBytes,\n  createTaggedCbor,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  tagValue,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport {\n  X25519_PRIVATE_KEY as TAG_X25519_PRIVATE_KEY,\n  MLKEM_PRIVATE_KEY as TAG_MLKEM_PRIVATE_KEY,\n} from \"@bcts/tags\";\nimport { X25519PrivateKey } from \"../x25519/x25519-private-key.js\";\nimport { type SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { EncapsulationScheme } from \"./encapsulation-scheme.js\";\nimport { type EncapsulationCiphertext } from \"./encapsulation-ciphertext.js\";\nimport { EncapsulationPublicKey } from \"./encapsulation-public-key.js\";\nimport { MLKEMPrivateKey } from \"../mlkem/mlkem-private-key.js\";\nimport { MLKEMLevel } from \"../mlkem/mlkem-level.js\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex } from \"../utils.js\";\nimport { Reference, type ReferenceProvider } from \"../reference.js\";\nimport { Digest } from \"../digest.js\";\n\n/**\n * Convert MLKEMLevel to EncapsulationScheme\n */\nfunction mlkemLevelToScheme(level: MLKEMLevel): EncapsulationScheme {\n  switch (level) {\n    case MLKEMLevel.MLKEM512:\n      return EncapsulationScheme.MLKEM512;\n    case MLKEMLevel.MLKEM768:\n      return EncapsulationScheme.MLKEM768;\n    case MLKEMLevel.MLKEM1024:\n      return EncapsulationScheme.MLKEM1024;\n  }\n}\n\n/**\n * Check if a scheme is an MLKEM scheme\n */\nfunction isMlkemScheme(scheme: EncapsulationScheme): boolean {\n  return (\n    scheme === EncapsulationScheme.MLKEM512 ||\n    scheme === EncapsulationScheme.MLKEM768 ||\n    scheme === EncapsulationScheme.MLKEM1024\n  );\n}\n\n/**\n * Represents a private key for key encapsulation.\n *\n * Use this to decapsulate a shared secret from ciphertext.\n */\nexport class EncapsulationPrivateKey\n  implements\n    ReferenceProvider,\n    CborTaggedEncodable,\n    CborTaggedDecodable<EncapsulationPrivateKey>,\n    UREncodable\n{\n  private readonly _scheme: EncapsulationScheme;\n  private readonly _x25519PrivateKey: X25519PrivateKey | undefined;\n  private readonly _mlkemPrivateKey: MLKEMPrivateKey | undefined;\n\n  private constructor(\n    scheme: EncapsulationScheme,\n    x25519PrivateKey?: X25519PrivateKey,\n    mlkemPrivateKey?: MLKEMPrivateKey,\n  ) {\n    this._scheme = scheme;\n    this._x25519PrivateKey = x25519PrivateKey;\n    this._mlkemPrivateKey = mlkemPrivateKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an EncapsulationPrivateKey from an X25519PrivateKey.\n   */\n  static fromX25519PrivateKey(privateKey: X25519PrivateKey): EncapsulationPrivateKey {\n    return new EncapsulationPrivateKey(EncapsulationScheme.X25519, privateKey, undefined);\n  }\n\n  /**\n   * Create an EncapsulationPrivateKey from raw X25519 private key bytes.\n   */\n  static fromX25519Data(data: Uint8Array): EncapsulationPrivateKey {\n    const privateKey = X25519PrivateKey.fromDataRef(data);\n    return EncapsulationPrivateKey.fromX25519PrivateKey(privateKey);\n  }\n\n  /**\n   * Create an EncapsulationPrivateKey from an MLKEMPrivateKey.\n   */\n  static fromMlkem(privateKey: MLKEMPrivateKey): EncapsulationPrivateKey {\n    const scheme = mlkemLevelToScheme(privateKey.level());\n    return new EncapsulationPrivateKey(scheme, undefined, privateKey);\n  }\n\n  /**\n   * Create an EncapsulationPrivateKey from raw MLKEM private key bytes.\n   */\n  static fromMlkemData(level: MLKEMLevel, data: Uint8Array): EncapsulationPrivateKey {\n    const privateKey = MLKEMPrivateKey.fromBytes(level, data);\n    return EncapsulationPrivateKey.fromMlkem(privateKey);\n  }\n\n  /**\n   * Generate a new random X25519 encapsulation private key.\n   */\n  static new(): EncapsulationPrivateKey {\n    return EncapsulationPrivateKey.random();\n  }\n\n  /**\n   * Generate a new random X25519 encapsulation private key.\n   */\n  static random(): EncapsulationPrivateKey {\n    const rng = new SecureRandomNumberGenerator();\n    return EncapsulationPrivateKey.newUsing(rng);\n  }\n\n  /**\n   * Generate a new random X25519 encapsulation private key using provided RNG.\n   */\n  static newUsing(rng: RandomNumberGenerator): EncapsulationPrivateKey {\n    const x25519Private = X25519PrivateKey.newUsing(rng);\n    return EncapsulationPrivateKey.fromX25519PrivateKey(x25519Private);\n  }\n\n  /**\n   * Generate a new MLKEM encapsulation private key.\n   */\n  static newMlkem(level: MLKEMLevel = MLKEMLevel.MLKEM768): EncapsulationPrivateKey {\n    const mlkemPrivate = MLKEMPrivateKey.new(level);\n    return EncapsulationPrivateKey.fromMlkem(mlkemPrivate);\n  }\n\n  /**\n   * Generate a new MLKEM encapsulation private key using provided RNG.\n   */\n  static newMlkemUsing(level: MLKEMLevel, rng: RandomNumberGenerator): EncapsulationPrivateKey {\n    const mlkemPrivate = MLKEMPrivateKey.newUsing(level, rng);\n    return EncapsulationPrivateKey.fromMlkem(mlkemPrivate);\n  }\n\n  /**\n   * Generate a new keypair for X25519.\n   */\n  static keypair(): [EncapsulationPrivateKey, EncapsulationPublicKey] {\n    const privateKey = EncapsulationPrivateKey.new();\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Generate a new keypair using the given RNG (X25519).\n   */\n  static keypairUsing(\n    rng: RandomNumberGenerator,\n  ): [EncapsulationPrivateKey, EncapsulationPublicKey] {\n    const privateKey = EncapsulationPrivateKey.newUsing(rng);\n    const publicKey = privateKey.publicKey();\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Generate a new MLKEM keypair.\n   */\n  static mlkemKeypair(\n    level: MLKEMLevel = MLKEMLevel.MLKEM768,\n  ): [EncapsulationPrivateKey, EncapsulationPublicKey] {\n    const [mlkemPrivate, mlkemPublic] = MLKEMPrivateKey.keypair(level);\n    const privateKey = EncapsulationPrivateKey.fromMlkem(mlkemPrivate);\n    const publicKey = EncapsulationPublicKey.fromMlkem(mlkemPublic);\n    return [privateKey, publicKey];\n  }\n\n  /**\n   * Generate a new MLKEM keypair using the given RNG.\n   */\n  static mlkemKeypairUsing(\n    level: MLKEMLevel,\n    rng: RandomNumberGenerator,\n  ): [EncapsulationPrivateKey, EncapsulationPublicKey] {\n    const [mlkemPrivate, mlkemPublic] = MLKEMPrivateKey.keypairUsing(level, rng);\n    const privateKey = EncapsulationPrivateKey.fromMlkem(mlkemPrivate);\n    const publicKey = EncapsulationPublicKey.fromMlkem(mlkemPublic);\n    return [privateKey, publicKey];\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the encapsulation scheme.\n   */\n  encapsulationScheme(): EncapsulationScheme {\n    return this._scheme;\n  }\n\n  /**\n   * Returns true if this is an X25519 private key.\n   */\n  isX25519(): boolean {\n    return this._scheme === EncapsulationScheme.X25519;\n  }\n\n  /**\n   * Returns true if this is an MLKEM private key.\n   */\n  isMlkem(): boolean {\n    return isMlkemScheme(this._scheme);\n  }\n\n  /**\n   * Returns the X25519 private key if this is an X25519 encapsulation key.\n   * @throws Error if this is not an X25519 key\n   */\n  x25519PrivateKey(): X25519PrivateKey {\n    if (this._x25519PrivateKey === undefined) {\n      throw new Error(\"Not an X25519 private key\");\n    }\n    return this._x25519PrivateKey;\n  }\n\n  /**\n   * Returns the MLKEM private key if this is an MLKEM encapsulation key.\n   * @throws Error if this is not an MLKEM key\n   */\n  mlkemPrivateKey(): MLKEMPrivateKey {\n    if (this._mlkemPrivateKey === undefined) {\n      throw new Error(\"Not an MLKEM private key\");\n    }\n    return this._mlkemPrivateKey;\n  }\n\n  /**\n   * Returns the X25519 private key if available, or null.\n   */\n  toX25519(): X25519PrivateKey | null {\n    return this._x25519PrivateKey ?? null;\n  }\n\n  /**\n   * Returns the MLKEM private key if available, or null.\n   */\n  toMlkem(): MLKEMPrivateKey | null {\n    return this._mlkemPrivateKey ?? null;\n  }\n\n  /**\n   * Returns the raw private key data.\n   */\n  data(): Uint8Array {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PrivateKey;\n      if (pk === undefined) throw new Error(\"X25519 private key not set\");\n      return pk.data();\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPrivateKey;\n      if (pk === undefined) throw new Error(\"MLKEM private key not set\");\n      return pk.data();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Get the public key corresponding to this private key.\n   */\n  publicKey(): EncapsulationPublicKey {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PrivateKey;\n      if (pk === undefined) throw new Error(\"X25519 private key not set\");\n      const x25519Public = pk.publicKey();\n      return EncapsulationPublicKey.fromX25519PublicKey(x25519Public);\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPrivateKey;\n      if (pk === undefined) throw new Error(\"MLKEM private key not set\");\n      const mlkemPublic = pk.publicKey();\n      return EncapsulationPublicKey.fromMlkem(mlkemPublic);\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Decapsulate a shared secret from ciphertext.\n   *\n   * @param ciphertext - The ciphertext from encapsulation\n   * @returns The decapsulated shared secret\n   * @throws CryptoError if the scheme doesn't match\n   */\n  decapsulateSharedSecret(ciphertext: EncapsulationCiphertext): SymmetricKey {\n    // Verify scheme matches\n    if (ciphertext.encapsulationScheme() !== this._scheme) {\n      throw CryptoError.invalidData(\n        `Scheme mismatch: expected ${String(this._scheme)}, got ${String(ciphertext.encapsulationScheme())}`,\n      );\n    }\n\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PrivateKey;\n      if (pk === undefined) throw new Error(\"X25519 private key not set\");\n      // Get the ephemeral public key from ciphertext\n      const ephemeralPublic = ciphertext.x25519PublicKey();\n\n      // Perform ECDH to recover shared secret\n      return pk.sharedKeyWith(ephemeralPublic);\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPrivateKey;\n      if (pk === undefined) throw new Error(\"MLKEM private key not set\");\n      // Get the MLKEM ciphertext and decapsulate\n      const mlkemCiphertext = ciphertext.mlkemCiphertext();\n      return pk.decapsulate(mlkemCiphertext);\n    }\n\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Compare with another EncapsulationPrivateKey.\n   */\n  equals(other: EncapsulationPrivateKey): boolean {\n    if (this._scheme !== other._scheme) return false;\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const thisPk = this._x25519PrivateKey;\n      const otherPk = other._x25519PrivateKey;\n      if (thisPk === undefined || otherPk === undefined) return false;\n      return thisPk.equals(otherPk);\n    } else if (isMlkemScheme(this._scheme)) {\n      const thisPk = this._mlkemPrivateKey;\n      const otherPk = other._mlkemPrivateKey;\n      if (thisPk === undefined || otherPk === undefined) return false;\n      return thisPk.equals(otherPk);\n    }\n    return false;\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      return `EncapsulationPrivateKey(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n    } else if (isMlkemScheme(this._scheme)) {\n      return `EncapsulationPrivateKey(${String(this._scheme)}, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n    }\n    return `EncapsulationPrivateKey(${String(this._scheme)})`;\n  }\n\n  // ============================================================================\n  // ReferenceProvider Interface\n  // ============================================================================\n\n  /**\n   * Returns a unique reference to this EncapsulationPrivateKey instance.\n   *\n   * The reference is derived from the SHA-256 hash of the tagged CBOR\n   * representation, providing a unique, content-addressable identifier.\n   */\n  reference(): Reference {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return Reference.from(digest);\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with this private key.\n   */\n  cborTags(): Tag[] {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      return tagsForValues([TAG_X25519_PRIVATE_KEY.value]);\n    } else if (isMlkemScheme(this._scheme)) {\n      return tagsForValues([TAG_MLKEM_PRIVATE_KEY.value]);\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   */\n  untaggedCbor(): Cbor {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const pk = this._x25519PrivateKey;\n      if (pk === undefined) throw new Error(\"X25519 private key not set\");\n      return toByteString(pk.data());\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPrivateKey;\n      if (pk === undefined) throw new Error(\"MLKEM private key not set\");\n      return pk.untaggedCbor();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 an EncapsulationPrivateKey by decoding it from untagged CBOR.\n   * Note: Without tags, we assume X25519 scheme.\n   */\n  fromUntaggedCbor(cborValue: Cbor): EncapsulationPrivateKey {\n    const data = expectBytes(cborValue);\n    const privateKey = X25519PrivateKey.fromDataRef(data);\n    return EncapsulationPrivateKey.fromX25519PrivateKey(privateKey);\n  }\n\n  /**\n   * Creates an EncapsulationPrivateKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): EncapsulationPrivateKey {\n    const tag = tagValue(cborValue);\n\n    if (tag === TAG_X25519_PRIVATE_KEY.value) {\n      const content = extractTaggedContent(cborValue);\n      const data = expectBytes(content);\n      const privateKey = X25519PrivateKey.fromDataRef(data);\n      return EncapsulationPrivateKey.fromX25519PrivateKey(privateKey);\n    }\n\n    if (tag === TAG_MLKEM_PRIVATE_KEY.value) {\n      const mlkemPrivate = MLKEMPrivateKey.fromTaggedCbor(cborValue);\n      return EncapsulationPrivateKey.fromMlkem(mlkemPrivate);\n    }\n\n    throw new Error(`Unknown private key tag: ${tag}`);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): EncapsulationPrivateKey {\n    const dummy = EncapsulationPrivateKey.fromX25519PrivateKey(\n      X25519PrivateKey.fromData(new Uint8Array(32)),\n    );\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): EncapsulationPrivateKey {\n    const cborValue = decodeCbor(data);\n    return EncapsulationPrivateKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): EncapsulationPrivateKey {\n    const cborValue = decodeCbor(data);\n    const dummy = EncapsulationPrivateKey.fromX25519PrivateKey(\n      X25519PrivateKey.fromData(new Uint8Array(32)),\n    );\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    if (this._scheme === EncapsulationScheme.X25519) {\n      const name = TAG_X25519_PRIVATE_KEY.name;\n      if (name === undefined) throw new Error(\"TAG_X25519_PRIVATE_KEY.name is undefined\");\n      return UR.new(name, this.untaggedCbor());\n    } else if (isMlkemScheme(this._scheme)) {\n      const pk = this._mlkemPrivateKey;\n      if (pk === undefined) throw new Error(\"MLKEM private key not set\");\n      return pk.ur();\n    }\n    throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n  }\n\n  /**\n   * Returns the UR string representation.\n   */\n  urString(): string {\n    return this.ur().string();\n  }\n\n  /**\n   * Creates an EncapsulationPrivateKey from a UR.\n   */\n  static fromUR(ur: UR): EncapsulationPrivateKey {\n    // Check for known UR types\n    if (ur.urTypeStr() === TAG_X25519_PRIVATE_KEY.name) {\n      const dummy = EncapsulationPrivateKey.fromX25519PrivateKey(\n        X25519PrivateKey.fromData(new Uint8Array(32)),\n      );\n      return dummy.fromUntaggedCbor(ur.cbor());\n    }\n\n    if (ur.urTypeStr() === TAG_MLKEM_PRIVATE_KEY.name) {\n      const mlkemPrivate = MLKEMPrivateKey.fromUR(ur);\n      return EncapsulationPrivateKey.fromMlkem(mlkemPrivate);\n    }\n\n    throw new Error(`Unknown UR type for EncapsulationPrivateKey: ${ur.urTypeStr()}`);\n  }\n\n  /**\n   * Creates an EncapsulationPrivateKey from a UR string.\n   */\n  static fromURString(urString: string): EncapsulationPrivateKey {\n    const ur = UR.fromURString(urString);\n    return EncapsulationPrivateKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * PrivateKeyBase - Root cryptographic material for deterministic key derivation\n *\n * PrivateKeyBase is a 32-byte value that serves as the root of cryptographic\n * material from which various keys can be deterministically derived.\n *\n * # CBOR Serialization\n *\n * PrivateKeyBase is serialized with tag 40016:\n * ```\n * #6.40016(h'<32-byte-key-material>')\n * ```\n *\n * # UR Serialization\n *\n * UR type: `crypto-prvkey-base`\n *\n * Ported from bc-components-rust/src/private_key_base.rs\n */\n\nimport { SecureRandomNumberGenerator, type RandomNumberGenerator } from \"@bcts/rand\";\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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { PRIVATE_KEY_BASE as TAG_PRIVATE_KEY_BASE } from \"@bcts/tags\";\nimport { hkdfHmacSha256 } from \"@bcts/crypto\";\n\nimport { X25519PrivateKey } from \"./x25519/x25519-private-key.js\";\nimport { Ed25519PrivateKey } from \"./ed25519/ed25519-private-key.js\";\nimport { ECPrivateKey } from \"./ec-key/ec-private-key.js\";\nimport { SigningPrivateKey } from \"./signing/signing-private-key.js\";\nimport { EncapsulationPrivateKey } from \"./encapsulation/encapsulation-private-key.js\";\nimport { bytesToHex } from \"./utils.js\";\nimport { PrivateKeys } from \"./private-keys.js\";\nimport type { PublicKeys } from \"./public-keys.js\";\nimport type { Decrypter } from \"./encrypter.js\";\nimport type { SymmetricKey } from \"./symmetric/symmetric-key.js\";\nimport type { EncapsulationCiphertext } from \"./encapsulation/encapsulation-ciphertext.js\";\nimport { HKDFRng } from \"./hkdf-rng.js\";\nimport { SSHPrivateKey, type SshPrivateKeyData } from \"./ssh/ssh-private-key.js\";\nimport {\n  sshAlgorithmName,\n  sshEcdsaPointLen,\n  sshEcdsaScalarLen,\n  type SshAlgorithm,\n} from \"./ssh/ssh-algorithm.js\";\nimport { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { p256, p384 } from \"@noble/curves/nist.js\";\n\n/** Default size of PrivateKeyBase key material in bytes (used for random generation) */\nconst PRIVATE_KEY_BASE_DEFAULT_SIZE = 32;\n\n/** Key derivation salt string - must match Rust's bc-crypto derive functions */\nconst SALT_SIGNING = \"signing\";\n\n/**\n * PrivateKeyBase - Root cryptographic material for deterministic key derivation.\n *\n * This is the foundation from which signing keys and agreement keys can be\n * deterministically derived using HKDF.\n */\nexport class PrivateKeyBase\n  implements CborTaggedEncodable, CborTaggedDecodable<PrivateKeyBase>, UREncodable, Decrypter\n{\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length === 0) {\n      throw new Error(\"PrivateKeyBase must have non-zero length\");\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new random PrivateKeyBase.\n   */\n  static new(): PrivateKeyBase {\n    const rng = new SecureRandomNumberGenerator();\n    return PrivateKeyBase.newUsing(rng);\n  }\n\n  /**\n   * Create a new random PrivateKeyBase using the provided RNG.\n   */\n  static newUsing(rng: RandomNumberGenerator): PrivateKeyBase {\n    const data = rng.randomData(PRIVATE_KEY_BASE_DEFAULT_SIZE);\n    return new PrivateKeyBase(data);\n  }\n\n  /**\n   * Create a PrivateKeyBase from raw bytes.\n   *\n   * @param data - 32 bytes of key material\n   */\n  static fromData(data: Uint8Array): PrivateKeyBase {\n    return new PrivateKeyBase(data);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the raw key material.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw key material.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  // ============================================================================\n  // Key Derivation Methods\n  // ============================================================================\n\n  /**\n   * Derive an Ed25519 signing private key.\n   *\n   * Uses HKDF with salt \"signing\", matching Rust's derive_signing_private_key().\n   */\n  ed25519SigningPrivateKey(): SigningPrivateKey {\n    const derivedKey = this._deriveKey(SALT_SIGNING);\n    const ed25519Key = Ed25519PrivateKey.from(derivedKey);\n    return SigningPrivateKey.newEd25519(ed25519Key);\n  }\n\n  /**\n   * Derive an X25519 agreement private key.\n   *\n   * Uses HKDF with salt \"agreement\", matching Rust's derive_agreement_private_key().\n   */\n  x25519PrivateKey(): X25519PrivateKey {\n    return X25519PrivateKey.deriveFromKeyMaterial(this._data);\n  }\n\n  /**\n   * Get EncapsulationPrivateKey for decryption.\n   *\n   * Returns the derived X25519 private key wrapped as EncapsulationPrivateKey.\n   */\n  encapsulationPrivateKey(): EncapsulationPrivateKey {\n    return EncapsulationPrivateKey.fromX25519PrivateKey(this.x25519PrivateKey());\n  }\n\n  /**\n   * Decapsulate a shared secret from a ciphertext.\n   *\n   * Implements the `Decrypter` interface so a `PrivateKeyBase` can be used\n   * directly as a recipient key, mirroring Rust `impl Decrypter for\n   * PrivateKeyBase`.\n   */\n  decapsulateSharedSecret(ciphertext: EncapsulationCiphertext): SymmetricKey {\n    return this.encapsulationPrivateKey().decapsulateSharedSecret(ciphertext);\n  }\n\n  /**\n   * Derive a PrivateKeys container with Ed25519 signing and X25519 agreement keys.\n   *\n   * @returns PrivateKeys containing the derived signing and encapsulation keys\n   */\n  ed25519PrivateKeys(): PrivateKeys {\n    return PrivateKeys.withKeys(this.ed25519SigningPrivateKey(), this.encapsulationPrivateKey());\n  }\n\n  /**\n   * Derive a PublicKeys container from the derived keys.\n   *\n   * @returns PublicKeys containing the derived public keys\n   */\n  ed25519PublicKeys(): PublicKeys {\n    const privateKeys = this.ed25519PrivateKeys();\n    return privateKeys.publicKeys();\n  }\n\n  /**\n   * Derive a Schnorr signing private key.\n   *\n   * Uses ECPrivateKey.deriveFromKeyMaterial() matching Rust's\n   * PrivateKeyBase::schnorr_signing_private_key().\n   */\n  schnorrSigningPrivateKey(): SigningPrivateKey {\n    const ecKey = ECPrivateKey.deriveFromKeyMaterial(this._data);\n    return SigningPrivateKey.newSchnorr(ecKey);\n  }\n\n  /**\n   * Derive a PrivateKeys container with Schnorr signing and X25519 agreement keys.\n   *\n   * Matches Rust's PrivateKeyBase::schnorr_private_keys().\n   */\n  schnorrPrivateKeys(): PrivateKeys {\n    return PrivateKeys.withKeys(this.schnorrSigningPrivateKey(), this.encapsulationPrivateKey());\n  }\n\n  /**\n   * Derive a PublicKeys container from Schnorr derived keys.\n   */\n  schnorrPublicKeys(): PublicKeys {\n    return this.schnorrPrivateKeys().publicKeys();\n  }\n\n  /**\n   * Derive an ECDSA signing private key.\n   *\n   * Uses ECPrivateKey.deriveFromKeyMaterial() matching Rust's\n   * PrivateKeyBase::ecdsa_signing_private_key().\n   */\n  ecdsaSigningPrivateKey(): SigningPrivateKey {\n    const ecKey = ECPrivateKey.deriveFromKeyMaterial(this._data);\n    return SigningPrivateKey.newEcdsa(ecKey);\n  }\n\n  /**\n   * Derive a PrivateKeys container with ECDSA signing and X25519 agreement keys.\n   *\n   * Matches Rust's PrivateKeyBase::ecdsa_private_keys().\n   */\n  ecdsaPrivateKeys(): PrivateKeys {\n    return PrivateKeys.withKeys(this.ecdsaSigningPrivateKey(), this.encapsulationPrivateKey());\n  }\n\n  /**\n   * Derive a PublicKeys container from ECDSA derived keys.\n   */\n  ecdsaPublicKeys(): PublicKeys {\n    return this.ecdsaPrivateKeys().publicKeys();\n  }\n\n  /**\n   * Derive an SSH `SigningPrivateKey` from this `PrivateKeyBase`.\n   *\n   * Mirrors Rust `PrivateKeyBase::ssh_signing_private_key`\n   * (`bc-components-rust/src/private_key_base.rs:179-207`):\n   * builds an `HKDFRng` seeded by `this._data` with salt\n   * `sshAlgorithmName(algorithm)`, then dispatches to the matching\n   * `*Keypair::random` constructor.\n   *\n   * Supported algorithms (matching the four `SignatureScheme.SshXxx`\n   * variants Rust ships in `signature_scheme.rs`):\n   *   - Ed25519 (`ssh-ed25519`)\n   *   - DSA (`ssh-dss`) — **throws**: byte-deterministic DSA-1024 prime\n   *     generation requires porting the upstream `dsa` crate's\n   *     FIPS 186-4 prime search, which is not yet implemented in TS.\n   *   - ECDSA P-256 (`ecdsa-sha2-nistp256`)\n   *   - ECDSA P-384 (`ecdsa-sha2-nistp384`)\n   *\n   * @param algorithm - The SSH key algorithm to derive\n   * @param comment   - Optional comment carried through the OpenSSH PEM\n   */\n  sshSigningPrivateKey(algorithm: SshAlgorithm, comment = \"\"): SigningPrivateKey {\n    const rng = HKDFRng.new(this._data, sshAlgorithmName(algorithm));\n    let data: SshPrivateKeyData;\n    switch (algorithm.kind) {\n      case \"ed25519\": {\n        // Mirror `ssh-key` 0.6.7 `Ed25519PrivateKey::random`:\n        // `rng.fill_bytes(&mut [0u8; 32])`. The 32 bytes are the seed.\n        const seed = rng.randomData(32);\n        const pubBytes = ed25519.getPublicKey(seed);\n        data = { kind: \"ed25519\", seed, pubBytes: new Uint8Array(pubBytes) };\n        break;\n      }\n      case \"ecdsa\": {\n        const scalarLen = sshEcdsaScalarLen(algorithm.curve);\n        const pointLen = sshEcdsaPointLen(algorithm.curve);\n        const curve = algorithm.curve === \"nistp256\" ? p256 : p384;\n        // Mirror `p{256,384}::SecretKey::random` rejection sampling:\n        // read `scalarLen` bytes; if the big-endian scalar is zero or\n        // ≥ n, retry. We delegate the bounds check to noble's\n        // `utils.isValidSecretKey` which performs exactly the same\n        // `0 < scalar < n` predicate as Rust.\n        let scalar: Uint8Array;\n        for (;;) {\n          const bytes = rng.randomData(scalarLen);\n          if (curve.utils.isValidSecretKey(bytes)) {\n            scalar = bytes;\n            break;\n          }\n        }\n        const point = curve.getPublicKey(scalar, false);\n        if (point.length !== pointLen || point[0] !== 0x04) {\n          throw new Error(\n            `sshSigningPrivateKey ecdsa-${algorithm.curve}: noble returned non-uncompressed point`,\n          );\n        }\n        data = {\n          kind: \"ecdsa\",\n          curve: algorithm.curve,\n          point: new Uint8Array(point),\n          scalar,\n        };\n        break;\n      }\n      case \"dsa\":\n        throw new Error(\n          \"SSH DSA key generation is not yet implemented in TS. Rust's \" +\n            \"`bc-components-rust` ships byte-deterministic DSA-1024 keygen \" +\n            \"via the `dsa` crate's FIPS 186-4 prime search, which has not \" +\n            \"been ported. See SSH_V2_PLAN.md A.1 for status. Sign/verify \" +\n            \"and PEM round-trip work for DSA keys parsed from existing \" +\n            \"Rust-generated PEM input.\",\n        );\n    }\n    const checkint = sshCheckintFromPrivateBytes(data);\n    const sshKey = SSHPrivateKey.fromParts(data, comment, checkint);\n    return SigningPrivateKey.fromSsh(sshKey);\n  }\n\n  /**\n   * Derive a `PrivateKeys` container with an SSH signing key and an X25519\n   * agreement key. Mirrors Rust `PrivateKeyBase::ssh_private_keys`\n   * (`bc-components-rust/src/private_key_base.rs:273-283`).\n   */\n  sshPrivateKeys(algorithm: SshAlgorithm, comment = \"\"): PrivateKeys {\n    return PrivateKeys.withKeys(\n      this.sshSigningPrivateKey(algorithm, comment),\n      this.encapsulationPrivateKey(),\n    );\n  }\n\n  /**\n   * Derive a `PublicKeys` container from `sshPrivateKeys`. Mirrors Rust\n   * `PrivateKeyBase::ssh_public_keys`\n   * (`bc-components-rust/src/private_key_base.rs:289-300`).\n   */\n  sshPublicKeys(algorithm: SshAlgorithm, comment = \"\"): PublicKeys {\n    return this.sshPrivateKeys(algorithm, comment).publicKeys();\n  }\n\n  /**\n   * Internal key derivation using HKDF-SHA256.\n   * Matches Rust's hkdf_hmac_sha256(key_material, salt, key_len) with empty info.\n   */\n  private _deriveKey(salt: string): Uint8Array {\n    return hkdfHmacSha256(this._data, new TextEncoder().encode(salt), 32);\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another PrivateKeyBase.\n   */\n  equals(other: PrivateKeyBase): 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   * Get string representation (truncated for security).\n   */\n  toString(): string {\n    const hex = bytesToHex(this._data);\n    return `PrivateKeyBase(${hex.substring(0, 8)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with PrivateKeyBase.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_PRIVATE_KEY_BASE.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\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 PrivateKeyBase by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): PrivateKeyBase {\n    const data = expectBytes(cborValue);\n    return PrivateKeyBase.fromData(data);\n  }\n\n  /**\n   * Creates a PrivateKeyBase by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): PrivateKeyBase {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): PrivateKeyBase {\n    const dummy = new PrivateKeyBase(new Uint8Array(PRIVATE_KEY_BASE_DEFAULT_SIZE));\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): PrivateKeyBase {\n    const cborValue = decodeCbor(data);\n    return PrivateKeyBase.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): PrivateKeyBase {\n    const cborValue = decodeCbor(data);\n    const dummy = new PrivateKeyBase(new Uint8Array(PRIVATE_KEY_BASE_DEFAULT_SIZE));\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_PRIVATE_KEY_BASE.name;\n    if (name === undefined) {\n      throw new Error(\"PRIVATE_KEY_BASE tag name is undefined\");\n    }\n    return UR.new(name, 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 PrivateKeyBase from a UR.\n   */\n  static fromUR(ur: UR): PrivateKeyBase {\n    if (ur.urTypeStr() !== TAG_PRIVATE_KEY_BASE.name) {\n      throw new Error(`Expected UR type ${TAG_PRIVATE_KEY_BASE.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummy = new PrivateKeyBase(new Uint8Array(PRIVATE_KEY_BASE_DEFAULT_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a PrivateKeyBase from a UR string.\n   */\n  static fromURString(urString: string): PrivateKeyBase {\n    const ur = UR.fromURString(urString);\n    return PrivateKeyBase.fromUR(ur);\n  }\n}\n\n/**\n * Mirror of `ssh-key` 0.6.7 `KeypairData::checkint`\n * (`ssh-key/src/private/keypair.rs:215-241`): XOR successive 4-byte\n * big-endian chunks of the algorithm-specific private bytes.\n *\n *   - Ed25519 → seed (32 bytes)\n *   - ECDSA   → canonical scalar (32 / 48 bytes)\n *   - DSA     → secret exponent x bytes\n *\n * The `chunks_exact(4)` rule discards any trailing bytes whose count\n * is not a multiple of 4 — match it here.\n */\nfunction sshCheckintFromPrivateBytes(data: SshPrivateKeyData): number {\n  let bytes: Uint8Array;\n  switch (data.kind) {\n    case \"ed25519\":\n      bytes = data.seed;\n      break;\n    case \"ecdsa\":\n      bytes = data.scalar;\n      break;\n    case \"dsa\":\n      bytes = data.x;\n      break;\n  }\n  let n = 0;\n  const fullChunks = Math.floor(bytes.length / 4);\n  for (let i = 0; i < fullChunks; i++) {\n    const off = i * 4;\n    const chunk =\n      ((bytes[off] << 24) | (bytes[off + 1] << 16) | (bytes[off + 2] << 8) | bytes[off + 3]) >>> 0;\n    n = (n ^ chunk) >>> 0;\n  }\n  return n;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Supported digital signature schemes.\n *\n * This enum represents the various signature schemes supported in this crate,\n * including Ed25519, SR25519, ECDSA, Schnorr, post-quantum ML-DSA, and SSH-based signatures.\n *\n * Ported from bc-components-rust/src/signing/signature_scheme.rs\n */\n\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { Ed25519PrivateKey } from \"../ed25519/ed25519-private-key.js\";\nimport { Sr25519PrivateKey } from \"../sr25519/sr25519-private-key.js\";\nimport { ECPrivateKey } from \"../ec-key/ec-private-key.js\";\nimport { MLDSAPrivateKey } from \"../mldsa/mldsa-private-key.js\";\nimport { MLDSALevel } from \"../mldsa/mldsa-level.js\";\nimport { PrivateKeyBase } from \"../private-key-base.js\";\nimport type { SshAlgorithm } from \"../ssh/ssh-algorithm.js\";\nimport { SigningPrivateKey } from \"./signing-private-key.js\";\nimport type { SigningPublicKey } from \"./signing-public-key.js\";\nimport { CryptoError } from \"../error.js\";\n\n/**\n * Supported digital signature schemes.\n *\n * This enum represents the various signature schemes supported in this package.\n * - Schnorr: BIP-340 Schnorr signature scheme (secp256k1) - DEFAULT\n * - ECDSA: ECDSA signature scheme (secp256k1)\n * - Ed25519: RFC 8032 signatures\n * - Sr25519: Schnorr over Ristretto25519, used by Polkadot/Substrate\n * - MLDSA44: ML-DSA44 post-quantum signature scheme (NIST level 2)\n * - MLDSA65: ML-DSA65 post-quantum signature scheme (NIST level 3)\n * - MLDSA87: ML-DSA87 post-quantum signature scheme (NIST level 5)\n * - SshEd25519: Ed25519 via SSH agent\n * - SshDsa: DSA via SSH agent\n * - SshEcdsaP256: ECDSA P-256 via SSH agent\n * - SshEcdsaP384: ECDSA P-384 via SSH agent\n *\n * Wire format note: Rust models `SignatureScheme` as a unit-only enum;\n * TypeScript uses string-typed values for ergonomic `switch`/`equals`\n * checks. The CBOR/UR wire format never includes the scheme name —\n * only the scheme's integer/byte-string discriminator on `Signature`,\n * `SigningPrivateKey`, `SigningPublicKey` — so this is a stylistic\n * difference, not a parity gap.\n */\nexport enum SignatureScheme {\n  /**\n   * BIP-340 Schnorr signature scheme (secp256k1)\n   * Default scheme (matching Rust bc-components default when secp256k1 is enabled)\n   */\n  Schnorr = \"Schnorr\",\n\n  /**\n   * ECDSA signature scheme (secp256k1)\n   */\n  Ecdsa = \"Ecdsa\",\n\n  /**\n   * Ed25519 signature scheme (RFC 8032)\n   */\n  Ed25519 = \"Ed25519\",\n\n  /**\n   * SR25519 signature scheme (Schnorr over Ristretto25519)\n   * Used by Polkadot/Substrate\n   */\n  Sr25519 = \"Sr25519\",\n\n  /**\n   * ML-DSA44 post-quantum signature scheme (NIST level 2)\n   */\n  MLDSA44 = \"MLDSA44\",\n\n  /**\n   * ML-DSA65 post-quantum signature scheme (NIST level 3)\n   */\n  MLDSA65 = \"MLDSA65\",\n\n  /**\n   * ML-DSA87 post-quantum signature scheme (NIST level 5)\n   */\n  MLDSA87 = \"MLDSA87\",\n\n  /**\n   * Ed25519 signature via SSH agent.\n   * Requires SSH agent daemon support.\n   */\n  SshEd25519 = \"SshEd25519\",\n\n  /**\n   * DSA signature via SSH agent.\n   * Requires SSH agent daemon support.\n   */\n  SshDsa = \"SshDsa\",\n\n  /**\n   * ECDSA P-256 signature via SSH agent.\n   * Requires SSH agent daemon support.\n   */\n  SshEcdsaP256 = \"SshEcdsaP256\",\n\n  /**\n   * ECDSA P-384 signature via SSH agent.\n   * Requires SSH agent daemon support.\n   */\n  SshEcdsaP384 = \"SshEcdsaP384\",\n}\n\n/**\n * Get the default signature scheme.\n * Defaults to Schnorr (matching Rust bc-components default when secp256k1 is enabled).\n */\nexport function defaultSignatureScheme(): SignatureScheme {\n  return SignatureScheme.Schnorr;\n}\n\n/**\n * Check if a signature scheme requires SSH agent support.\n *\n * @param scheme - The signature scheme to check\n * @returns true if the scheme requires SSH agent\n */\nexport function isSshScheme(scheme: SignatureScheme): boolean {\n  return (\n    scheme === SignatureScheme.SshEd25519 ||\n    scheme === SignatureScheme.SshDsa ||\n    scheme === SignatureScheme.SshEcdsaP256 ||\n    scheme === SignatureScheme.SshEcdsaP384\n  );\n}\n\n/**\n * Check if a signature scheme is a post-quantum ML-DSA scheme.\n *\n * @param scheme - The signature scheme to check\n * @returns true if the scheme is an ML-DSA scheme\n */\nexport function isMldsaScheme(scheme: SignatureScheme): boolean {\n  return (\n    scheme === SignatureScheme.MLDSA44 ||\n    scheme === SignatureScheme.MLDSA65 ||\n    scheme === SignatureScheme.MLDSA87\n  );\n}\n\n/**\n * Options for configuring signature creation.\n *\n * Different signature schemes may require specific options:\n * - Schnorr: Optionally accepts a custom random number generator\n * - Ssh: Requires a namespace and hash algorithm\n *\n * Other signature types like ECDSA, Ed25519, Sr25519, and ML-DSA don't require options.\n */\nexport type SigningOptions =\n  | {\n      type: \"Schnorr\";\n      /** Custom random number generator for signature creation */\n      rng: RandomNumberGenerator;\n    }\n  | {\n      type: \"Ssh\";\n      /** The namespace used for SSH signatures */\n      namespace: string;\n      /** The hash algorithm used for SSH signatures */\n      hashAlg: \"sha256\" | \"sha512\";\n    };\n\n/**\n * Map an `SshXxx` `SignatureScheme` value to its underlying\n * `SshAlgorithm`. Helper for `createKeypair`/`createKeypairUsing`.\n */\nfunction sshSchemeToAlgorithm(scheme: SignatureScheme): SshAlgorithm {\n  switch (scheme) {\n    case SignatureScheme.SshEd25519:\n      return { kind: \"ed25519\" };\n    case SignatureScheme.SshDsa:\n      return { kind: \"dsa\" };\n    case SignatureScheme.SshEcdsaP256:\n      return { kind: \"ecdsa\", curve: \"nistp256\" };\n    case SignatureScheme.SshEcdsaP384:\n      return { kind: \"ecdsa\", curve: \"nistp384\" };\n    case SignatureScheme.Schnorr:\n    case SignatureScheme.Ecdsa:\n    case SignatureScheme.Ed25519:\n    case SignatureScheme.Sr25519:\n    case SignatureScheme.MLDSA44:\n    case SignatureScheme.MLDSA65:\n    case SignatureScheme.MLDSA87:\n      throw new Error(`Not an SSH SignatureScheme: ${scheme}`);\n  }\n}\n\n/**\n * Creates a new key pair for the signature scheme.\n *\n * @param scheme  - The signature scheme to use\n * @param comment - Optional comment for SSH keys (ignored for non-SSH schemes;\n *                  mirrors Rust `SignatureScheme::keypair_opt(comment)` at\n *                  `signature_scheme.rs:152`)\n * @returns A tuple containing a signing private key and its corresponding public key\n */\nexport function createKeypair(\n  scheme: SignatureScheme,\n  comment = \"\",\n): [SigningPrivateKey, SigningPublicKey] {\n  switch (scheme) {\n    case SignatureScheme.Schnorr: {\n      const ecKey = ECPrivateKey.random();\n      const privateKey = SigningPrivateKey.newSchnorr(ecKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.Ecdsa: {\n      const ecKey = ECPrivateKey.random();\n      const privateKey = SigningPrivateKey.newEcdsa(ecKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.Ed25519: {\n      const ed25519Key = Ed25519PrivateKey.random();\n      const privateKey = SigningPrivateKey.newEd25519(ed25519Key);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.Sr25519: {\n      const sr25519Key = Sr25519PrivateKey.random();\n      const privateKey = SigningPrivateKey.newSr25519(sr25519Key);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.MLDSA44: {\n      const mldsaKey = MLDSAPrivateKey.new(MLDSALevel.MLDSA44);\n      const privateKey = SigningPrivateKey.newMldsa(mldsaKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.MLDSA65: {\n      const mldsaKey = MLDSAPrivateKey.new(MLDSALevel.MLDSA65);\n      const privateKey = SigningPrivateKey.newMldsa(mldsaKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.MLDSA87: {\n      const mldsaKey = MLDSAPrivateKey.new(MLDSALevel.MLDSA87);\n      const privateKey = SigningPrivateKey.newMldsa(mldsaKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.SshEd25519:\n    case SignatureScheme.SshDsa:\n    case SignatureScheme.SshEcdsaP256:\n    case SignatureScheme.SshEcdsaP384: {\n      // Mirror Rust `signature_scheme.rs:209-276`: build an empty\n      // `PrivateKeyBase` and derive an SSH keypair from it.\n      const base = PrivateKeyBase.new();\n      const privateKey = base.sshSigningPrivateKey(sshSchemeToAlgorithm(scheme), comment);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n  }\n}\n\n/**\n * Creates a new key pair for the signature scheme using a provided RNG.\n *\n * @param scheme  - The signature scheme to use\n * @param rng     - The random number generator to use\n * @param comment - Optional comment for SSH keys (ignored for non-SSH schemes;\n *                  mirrors Rust `SignatureScheme::keypair_using(rng, comment)`\n *                  at `signature_scheme.rs:316`)\n * @returns A tuple containing a signing private key and its corresponding public key\n * @throws CryptoError for MLDSA (which doesn't support deterministic generation)\n */\nexport function createKeypairUsing(\n  scheme: SignatureScheme,\n  rng: RandomNumberGenerator,\n  comment = \"\",\n): [SigningPrivateKey, SigningPublicKey] {\n  switch (scheme) {\n    case SignatureScheme.Schnorr: {\n      const ecKey = ECPrivateKey.newUsing(rng);\n      const privateKey = SigningPrivateKey.newSchnorr(ecKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.Ecdsa: {\n      const ecKey = ECPrivateKey.newUsing(rng);\n      const privateKey = SigningPrivateKey.newEcdsa(ecKey);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.Ed25519: {\n      const ed25519Key = Ed25519PrivateKey.randomUsing(rng);\n      const privateKey = SigningPrivateKey.newEd25519(ed25519Key);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.Sr25519: {\n      const sr25519Key = Sr25519PrivateKey.randomUsing(rng);\n      const privateKey = SigningPrivateKey.newSr25519(sr25519Key);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n    case SignatureScheme.MLDSA44:\n    case SignatureScheme.MLDSA65:\n    case SignatureScheme.MLDSA87:\n      // ML-DSA doesn't support deterministic generation with custom RNG (matching Rust behavior)\n      throw CryptoError.general(\n        `Deterministic keypair generation not supported for ${scheme}. Use createKeypair() instead.`,\n      );\n    case SignatureScheme.SshEd25519:\n    case SignatureScheme.SshDsa:\n    case SignatureScheme.SshEcdsaP256:\n    case SignatureScheme.SshEcdsaP384: {\n      // Mirror Rust `signature_scheme.rs:316-413`: build a\n      // `PrivateKeyBase::new_using(rng)` and derive an SSH keypair.\n      const base = PrivateKeyBase.newUsing(rng);\n      const privateKey = base.sshSigningPrivateKey(sshSchemeToAlgorithm(scheme), comment);\n      const publicKey = privateKey.publicKey();\n      return [privateKey, publicKey];\n    }\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A digital signature created with various signature algorithms.\n *\n * `Signature` represents different types of digital signatures.\n * Supports Schnorr, ECDSA, Ed25519, and Sr25519 signatures.\n *\n * Signatures can be serialized to and from CBOR with tag 40020.\n *\n * # CBOR Serialization\n *\n * The CBOR encoding (matching Rust bc-components):\n * - Schnorr: `#6.40020(h'<64-byte-signature>')` (bare byte string)\n * - ECDSA:   `#6.40020([1, h'<64-byte-signature>'])`\n * - Ed25519: `#6.40020([2, h'<64-byte-signature>'])`\n * - Sr25519: `#6.40020([3, h'<64-byte-signature>'])`\n *\n * Ported from bc-components-rust/src/signing/signature.rs\n */\n\nimport { ED25519_SIGNATURE_SIZE, ECDSA_SIGNATURE_SIZE, SCHNORR_SIGNATURE_SIZE } from \"@bcts/crypto\";\nimport { SR25519_SIGNATURE_SIZE } from \"../sr25519/sr25519-private-key.js\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  toTaggedValue,\n  expectArray,\n  expectBytes,\n  expectText,\n  expectUnsigned,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  isBytes,\n  isArray,\n  isTagged,\n} from \"@bcts/dcbor\";\nimport {\n  SIGNATURE as TAG_SIGNATURE,\n  MLDSA_SIGNATURE as TAG_MLDSA_SIGNATURE,\n  SSH_TEXT_SIGNATURE as TAG_SSH_TEXT_SIGNATURE,\n} from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes } from \"../utils.js\";\nimport { SignatureScheme, isMldsaScheme } from \"./signature-scheme.js\";\nimport { MLDSASignature } from \"../mldsa/mldsa-signature.js\";\nimport { MLDSALevel } from \"../mldsa/mldsa-level.js\";\nimport { SSHSignature } from \"../ssh/ssh-signature.js\";\nimport { UR } from \"@bcts/uniform-resources\";\n\n/**\n * A digital signature created with various signature algorithms.\n *\n * Currently supports:\n * - Schnorr signatures (64 bytes) - bare byte string in CBOR\n * - ECDSA signatures (64 bytes) - discriminator 1\n * - Ed25519 signatures (64 bytes) - discriminator 2\n * - Sr25519 signatures (64 bytes) - discriminator 3\n * - MLDSA signatures (post-quantum) - tagged CBOR delegating to MLDSASignature\n */\nexport class Signature implements CborTaggedEncodable, CborTaggedDecodable<Signature> {\n  private readonly _type: SignatureScheme;\n  private readonly _data: Uint8Array;\n  private readonly _mldsaSignature: MLDSASignature | undefined;\n  private readonly _sshSig: SSHSignature | undefined;\n\n  private constructor(\n    type: SignatureScheme,\n    data: Uint8Array,\n    mldsaSignature?: MLDSASignature,\n    sshSig?: SSHSignature,\n  ) {\n    this._type = type;\n    this._data = new Uint8Array(data);\n    this._mldsaSignature = mldsaSignature;\n    this._sshSig = sshSig;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Creates a Schnorr signature from a 64-byte array.\n   *\n   * @param data - The 64-byte signature data\n   * @returns A new Schnorr signature\n   */\n  static schnorrFromData(data: Uint8Array): Signature {\n    if (data.length !== SCHNORR_SIGNATURE_SIZE) {\n      throw CryptoError.invalidSize(SCHNORR_SIGNATURE_SIZE, data.length);\n    }\n    return new Signature(SignatureScheme.Schnorr, data);\n  }\n\n  /**\n   * Creates a Schnorr signature from a hex string.\n   *\n   * @param hex - The hex-encoded signature data\n   * @returns A new Schnorr signature\n   */\n  static schnorrFromHex(hex: string): Signature {\n    return Signature.schnorrFromData(hexToBytes(hex));\n  }\n\n  /**\n   * Creates an ECDSA signature from a 64-byte array.\n   *\n   * @param data - The 64-byte signature data\n   * @returns A new ECDSA signature\n   */\n  static ecdsaFromData(data: Uint8Array): Signature {\n    if (data.length !== ECDSA_SIGNATURE_SIZE) {\n      throw CryptoError.invalidSize(ECDSA_SIGNATURE_SIZE, data.length);\n    }\n    return new Signature(SignatureScheme.Ecdsa, data);\n  }\n\n  /**\n   * Creates an ECDSA signature from a hex string.\n   *\n   * @param hex - The hex-encoded signature data\n   * @returns A new ECDSA signature\n   */\n  static ecdsaFromHex(hex: string): Signature {\n    return Signature.ecdsaFromData(hexToBytes(hex));\n  }\n\n  /**\n   * Creates an Ed25519 signature from a 64-byte array.\n   *\n   * @param data - The 64-byte signature data\n   * @returns A new Ed25519 signature\n   */\n  static ed25519FromData(data: Uint8Array): Signature {\n    if (data.length !== ED25519_SIGNATURE_SIZE) {\n      throw CryptoError.invalidSize(ED25519_SIGNATURE_SIZE, data.length);\n    }\n    return new Signature(SignatureScheme.Ed25519, data);\n  }\n\n  /**\n   * Creates an Ed25519 signature from a hex string.\n   *\n   * @param hex - The hex-encoded signature data\n   * @returns A new Ed25519 signature\n   */\n  static ed25519FromHex(hex: string): Signature {\n    return Signature.ed25519FromData(hexToBytes(hex));\n  }\n\n  /**\n   * Creates an Sr25519 signature from a 64-byte array.\n   *\n   * @param data - The 64-byte signature data\n   * @returns A new Sr25519 signature\n   */\n  static sr25519FromData(data: Uint8Array): Signature {\n    if (data.length !== SR25519_SIGNATURE_SIZE) {\n      throw CryptoError.invalidSize(SR25519_SIGNATURE_SIZE, data.length);\n    }\n    return new Signature(SignatureScheme.Sr25519, data);\n  }\n\n  /**\n   * Creates an Sr25519 signature from a hex string.\n   *\n   * @param hex - The hex-encoded signature data\n   * @returns A new Sr25519 signature\n   */\n  static sr25519FromHex(hex: string): Signature {\n    return Signature.sr25519FromData(hexToBytes(hex));\n  }\n\n  /**\n   * Creates a Signature from an MLDSASignature.\n   *\n   * @param sig - The MLDSASignature\n   * @returns A new Signature wrapping the MLDSA signature\n   */\n  static mldsaFromSignature(sig: MLDSASignature): Signature {\n    // Determine the SignatureScheme based on the MLDSA level\n    let scheme: SignatureScheme;\n    switch (sig.level()) {\n      case MLDSALevel.MLDSA44:\n        scheme = SignatureScheme.MLDSA44;\n        break;\n      case MLDSALevel.MLDSA65:\n        scheme = SignatureScheme.MLDSA65;\n        break;\n      case MLDSALevel.MLDSA87:\n        scheme = SignatureScheme.MLDSA87;\n        break;\n      default:\n        throw new Error(`Unknown MLDSA level: ${sig.level()}`);\n    }\n    return new Signature(scheme, sig.data(), sig);\n  }\n\n  /**\n   * Creates a Signature from an SSHSignature.\n   *\n   * Mirrors Rust `Signature::from_ssh`\n   * (`bc-components-rust/src/signing/signature.rs:398`).\n   *\n   * The signature scheme is derived from the inner public-key algorithm,\n   * matching Rust `Signature::scheme()` at lines 506-519.\n   *\n   * @param sig - The SSHSignature\n   * @returns A new SSH Signature\n   */\n  static fromSsh(sig: SSHSignature): Signature {\n    let scheme: SignatureScheme;\n    switch (sig.publicKey.data.kind) {\n      case \"ed25519\":\n        scheme = SignatureScheme.SshEd25519;\n        break;\n      case \"dsa\":\n        scheme = SignatureScheme.SshDsa;\n        break;\n      case \"ecdsa\":\n        switch (sig.publicKey.data.curve) {\n          case \"nistp256\":\n            scheme = SignatureScheme.SshEcdsaP256;\n            break;\n          case \"nistp384\":\n            scheme = SignatureScheme.SshEcdsaP384;\n            break;\n        }\n        break;\n    }\n    return new Signature(scheme, sig.signatureBytes, undefined, sig);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the signature scheme used to create this signature.\n   */\n  scheme(): SignatureScheme {\n    return this._type;\n  }\n\n  /**\n   * Returns a human-readable string identifying the signature type.\n   * @returns A string like \"Ed25519\", \"Schnorr\", \"ECDSA\", \"Sr25519\", \"MLDSA-44\", etc.\n   */\n  signatureType(): string {\n    switch (this._type) {\n      case SignatureScheme.Ed25519:\n        return \"Ed25519\";\n      case SignatureScheme.Schnorr:\n        return \"Schnorr\";\n      case SignatureScheme.Ecdsa:\n        return \"Ecdsa\";\n      case SignatureScheme.Sr25519:\n        return \"Sr25519\";\n      case SignatureScheme.MLDSA44:\n        return \"MLDSA-44\";\n      case SignatureScheme.MLDSA65:\n        return \"MLDSA-65\";\n      case SignatureScheme.MLDSA87:\n        return \"MLDSA-87\";\n      case SignatureScheme.SshEd25519:\n        return \"SshEd25519\";\n      case SignatureScheme.SshDsa:\n        return \"SshDsa\";\n      case SignatureScheme.SshEcdsaP256:\n        return \"SshEcdsaP256\";\n      case SignatureScheme.SshEcdsaP384:\n        return \"SshEcdsaP384\";\n      default:\n        return this._type;\n    }\n  }\n\n  /**\n   * Returns the raw signature data.\n   */\n  data(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns the Schnorr signature data if this is a Schnorr signature.\n   *\n   * @returns The 64-byte signature data if this is a Schnorr signature, null otherwise\n   */\n  toSchnorr(): Uint8Array | null {\n    if (this._type === SignatureScheme.Schnorr) {\n      return this._data;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is a Schnorr signature.\n   */\n  isSchnorr(): boolean {\n    return this._type === SignatureScheme.Schnorr;\n  }\n\n  /**\n   * Returns the ECDSA signature data if this is an ECDSA signature.\n   *\n   * @returns The 64-byte signature data if this is an ECDSA signature, null otherwise\n   */\n  toEcdsa(): Uint8Array | null {\n    if (this._type === SignatureScheme.Ecdsa) {\n      return this._data;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is an ECDSA signature.\n   */\n  isEcdsa(): boolean {\n    return this._type === SignatureScheme.Ecdsa;\n  }\n\n  /**\n   * Returns the Ed25519 signature data if this is an Ed25519 signature.\n   *\n   * @returns The 64-byte signature data if this is an Ed25519 signature, null otherwise\n   */\n  toEd25519(): Uint8Array | null {\n    if (this._type === SignatureScheme.Ed25519) {\n      return this._data;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is an Ed25519 signature.\n   */\n  isEd25519(): boolean {\n    return this._type === SignatureScheme.Ed25519;\n  }\n\n  /**\n   * Returns the Sr25519 signature data if this is an Sr25519 signature.\n   *\n   * @returns The 64-byte signature data if this is an Sr25519 signature, null otherwise\n   */\n  toSr25519(): Uint8Array | null {\n    if (this._type === SignatureScheme.Sr25519) {\n      return this._data;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is an Sr25519 signature.\n   */\n  isSr25519(): boolean {\n    return this._type === SignatureScheme.Sr25519;\n  }\n\n  /**\n   * Returns the MLDSASignature if this is an MLDSA signature.\n   *\n   * @returns The MLDSASignature if this is an MLDSA signature, null otherwise\n   */\n  toMldsa(): MLDSASignature | null {\n    if (isMldsaScheme(this._type) && this._mldsaSignature !== undefined) {\n      return this._mldsaSignature;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is an MLDSA signature.\n   */\n  isMldsa(): boolean {\n    return isMldsaScheme(this._type);\n  }\n\n  /**\n   * Returns the underlying SSHSignature if this is an SSH signature.\n   *\n   * Mirrors Rust `Signature::to_ssh`\n   * (`bc-components-rust/src/signing/signature.rs:459`).\n   *\n   * @returns The SSHSignature if this is an SSH signature, null otherwise\n   */\n  toSsh(): SSHSignature | null {\n    return this._sshSig ?? null;\n  }\n\n  /**\n   * Checks if this is an SSH signature.\n   */\n  isSsh(): boolean {\n    return this._sshSig !== undefined;\n  }\n\n  /**\n   * Get hex string representation of the signature data.\n   */\n  toHex(): string {\n    return bytesToHex(this._data);\n  }\n\n  /**\n   * Compare with another Signature.\n   */\n  equals(other: Signature): boolean {\n    if (this._type !== other._type) return false;\n    if (this._sshSig !== undefined || other._sshSig !== undefined) {\n      if (this._sshSig === undefined || other._sshSig === undefined) return false;\n      return this._sshSig.toPem() === other._sshSig.toPem();\n    }\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   * Get string representation.\n   */\n  toString(): string {\n    return `Signature(${this._type}, ${this.toHex().substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with Signature.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SIGNATURE.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format (matching Rust bc-components):\n   * - Schnorr: h'<64-byte-signature>' (bare byte string)\n   * - ECDSA:   [1, h'<64-byte-signature>']\n   * - Ed25519: [2, h'<64-byte-signature>']\n   * - Sr25519: [3, h'<64-byte-signature>']\n   */\n  untaggedCbor(): Cbor {\n    switch (this._type) {\n      case SignatureScheme.Schnorr:\n        // Rust: CBOR::to_byte_string(data) - bare byte string\n        return toByteString(this._data);\n      case SignatureScheme.Ecdsa:\n        return cbor([1, toByteString(this._data)]);\n      case SignatureScheme.Ed25519:\n        return cbor([2, toByteString(this._data)]);\n      case SignatureScheme.Sr25519:\n        return cbor([3, toByteString(this._data)]);\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87: {\n        if (this._mldsaSignature === undefined) {\n          throw new Error(\"MLDSA signature is missing\");\n        }\n        // Rust: delegates to MLDSASignature (which produces tagged CBOR)\n        return this._mldsaSignature.taggedCbor();\n      }\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshSig === undefined) {\n          throw new Error(\"SSH signature is missing\");\n        }\n        // Mirror Rust `Signature::SSH(sig) => to_tagged_value(TAG_SSH_TEXT_SIGNATURE, pem)`\n        // (`signature.rs:643-646`).\n        return toTaggedValue(TAG_SSH_TEXT_SIGNATURE, this._sshSig.toPem());\n      }\n    }\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 Signature by decoding it from untagged CBOR.\n   *\n   * Format (matching Rust bc-components):\n   * - h'<64-byte-signature>' (bare byte string) for Schnorr\n   * - [1, h'<64-byte-signature>'] for ECDSA\n   * - [2, h'<64-byte-signature>'] for Ed25519\n   * - [3, h'<64-byte-signature>'] for Sr25519\n   */\n  fromUntaggedCbor(cborValue: Cbor): Signature {\n    // Rust format: Schnorr is a bare byte string\n    if (isBytes(cborValue)) {\n      const signatureData = expectBytes(cborValue);\n      return Signature.schnorrFromData(signatureData);\n    }\n\n    // Array format for ECDSA, Ed25519, Sr25519\n    if (isArray(cborValue)) {\n      const elements = expectArray(cborValue);\n\n      if (elements.length !== 2) {\n        throw new Error(\"Signature array must have 2 elements\");\n      }\n\n      const discriminator = expectUnsigned(elements[0]);\n      const signatureData = expectBytes(elements[1]);\n\n      switch (Number(discriminator)) {\n        case 1: // ECDSA\n          return Signature.ecdsaFromData(signatureData);\n        case 2: // Ed25519\n          return Signature.ed25519FromData(signatureData);\n        case 3: // Sr25519\n          return Signature.sr25519FromData(signatureData);\n        default:\n          throw new Error(`Unknown signature discriminator: ${discriminator}`);\n      }\n    }\n\n    // Tagged format for MLDSA / SSH\n    if (isTagged(cborValue)) {\n      const tagged = cborValue.asTagged();\n      if (tagged?.[0].value === TAG_MLDSA_SIGNATURE.value) {\n        const mldsaSig = MLDSASignature.fromTaggedCbor(cborValue);\n        return Signature.mldsaFromSignature(mldsaSig);\n      }\n      if (tagged?.[0].value === TAG_SSH_TEXT_SIGNATURE.value) {\n        const text = expectText(tagged[1]);\n        const sshSig = SSHSignature.fromPem(text);\n        return Signature.fromSsh(sshSig);\n      }\n    }\n\n    throw new Error(\n      \"Signature must be a byte string (Schnorr), array (ECDSA/Ed25519/Sr25519), tagged MLDSA, or tagged SSH\",\n    );\n  }\n\n  /**\n   * Creates a Signature by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): Signature {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): Signature {\n    // Create a dummy instance for accessing instance methods\n    const dummy = new Signature(SignatureScheme.Ed25519, new Uint8Array(ED25519_SIGNATURE_SIZE));\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): Signature {\n    const cborValue = decodeCbor(data);\n    return Signature.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): Signature {\n    const cborValue = decodeCbor(data);\n    const dummy = new Signature(SignatureScheme.Ed25519, new Uint8Array(ED25519_SIGNATURE_SIZE));\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR (Uniform Resource) Serialization\n  // ============================================================================\n\n  /**\n   * Get the UR type for signatures.\n   */\n  static readonly UR_TYPE = \"signature\";\n\n  /**\n   * Returns the UR representation of the signature.\n   *\n   * The UR type prefix (`ur:signature/...`) carries the CBOR tag, so the\n   * inner CBOR must be untagged — matches Rust's `UREncodable` blanket impl.\n   */\n  ur(): UR {\n    return UR.new(Signature.UR_TYPE, this.untaggedCbor());\n  }\n\n  /**\n   * Returns the UR string representation of the signature.\n   */\n  urString(): string {\n    return this.ur().string();\n  }\n\n  /**\n   * Creates a Signature from a UR.\n   */\n  static fromUR(ur: UR): Signature {\n    ur.checkType(Signature.UR_TYPE);\n    const dummy = Signature.schnorrFromData(new Uint8Array(SCHNORR_SIGNATURE_SIZE));\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a Signature from a UR string.\n   */\n  static fromURString(urString: string): Signature {\n    const ur = UR.fromURString(urString);\n    return Signature.fromUR(ur);\n  }\n\n  /**\n   * Alias for fromURString for Rust API compatibility.\n   */\n  static fromUrString(urString: string): Signature {\n    return Signature.fromURString(urString);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A public key used for verifying digital signatures.\n *\n * `SigningPublicKey` is a type representing different types of signing public\n * keys. Supports Schnorr, ECDSA, Ed25519, and SR25519.\n *\n * This type implements the `Verifier` interface, allowing it to verify signatures.\n *\n * # CBOR Serialization\n *\n * `SigningPublicKey` is serialized to CBOR with tag 40022.\n *\n * The CBOR encoding (matching Rust bc-components):\n * - Schnorr: `#6.40022(h'<32-byte-x-only-public-key>')` (bare byte string)\n * - ECDSA:   `#6.40022([1, h'<33-byte-compressed-public-key>'])`\n * - Ed25519: `#6.40022([2, h'<32-byte-public-key>'])`\n * - Sr25519: `#6.40022([3, h'<32-byte-public-key>'])`\n *\n * Ported from bc-components-rust/src/signing/signing_public_key.rs\n */\n\nimport { ED25519_PUBLIC_KEY_SIZE } from \"@bcts/crypto\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  toTaggedValue,\n  expectArray,\n  expectBytes,\n  expectText,\n  expectUnsigned,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  isBytes,\n  isArray,\n  isTagged,\n} from \"@bcts/dcbor\";\nimport {\n  SIGNING_PUBLIC_KEY as TAG_SIGNING_PUBLIC_KEY,\n  MLDSA_PUBLIC_KEY as TAG_MLDSA_PUBLIC_KEY,\n  SSH_TEXT_PUBLIC_KEY as TAG_SSH_TEXT_PUBLIC_KEY,\n} from \"@bcts/tags\";\nimport { Ed25519PublicKey } from \"../ed25519/ed25519-public-key.js\";\nimport { Sr25519PublicKey } from \"../sr25519/sr25519-public-key.js\";\nimport { ECPublicKey } from \"../ec-key/ec-public-key.js\";\nimport { SchnorrPublicKey } from \"../ec-key/schnorr-public-key.js\";\nimport { MLDSAPublicKey } from \"../mldsa/mldsa-public-key.js\";\nimport { MLDSALevel } from \"../mldsa/mldsa-level.js\";\nimport { SSHPublicKey } from \"../ssh/ssh-public-key.js\";\nimport { SignatureScheme, isMldsaScheme } from \"./signature-scheme.js\";\nimport type { Signature } from \"./signature.js\";\nimport type { Verifier } from \"./signer.js\";\nimport { Reference, type ReferenceProvider } from \"../reference.js\";\nimport { Digest } from \"../digest.js\";\nimport { UR } from \"@bcts/uniform-resources\";\n\n/**\n * A public key used for verifying digital signatures.\n *\n * Currently supports:\n * - Schnorr public keys (32 bytes, x-only) - bare byte string in CBOR\n * - ECDSA public keys (33 bytes, compressed) - discriminator 1\n * - Ed25519 public keys (32 bytes) - discriminator 2\n * - Sr25519 public keys (32 bytes) - discriminator 3\n * - MLDSA public keys (post-quantum) - tagged CBOR delegating to MLDSAPublicKey\n */\nexport class SigningPublicKey\n  implements Verifier, ReferenceProvider, CborTaggedEncodable, CborTaggedDecodable<SigningPublicKey>\n{\n  private readonly _type: SignatureScheme;\n  private readonly _schnorrKey: SchnorrPublicKey | undefined;\n  private readonly _ecdsaKey: ECPublicKey | undefined;\n  private readonly _ed25519Key: Ed25519PublicKey | undefined;\n  private readonly _sr25519Key: Sr25519PublicKey | undefined;\n  private readonly _mldsaKey: MLDSAPublicKey | undefined;\n  private readonly _sshKey: SSHPublicKey | undefined;\n\n  private constructor(\n    type: SignatureScheme,\n    schnorrKey?: SchnorrPublicKey,\n    ecdsaKey?: ECPublicKey,\n    ed25519Key?: Ed25519PublicKey,\n    sr25519Key?: Sr25519PublicKey,\n    mldsaKey?: MLDSAPublicKey,\n    sshKey?: SSHPublicKey,\n  ) {\n    this._type = type;\n    this._schnorrKey = schnorrKey;\n    this._ecdsaKey = ecdsaKey;\n    this._ed25519Key = ed25519Key;\n    this._sr25519Key = sr25519Key;\n    this._mldsaKey = mldsaKey;\n    this._sshKey = sshKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Creates a new signing public key from a Schnorr (x-only) public key.\n   *\n   * @param key - A SchnorrPublicKey\n   * @returns A new signing public key containing the Schnorr key\n   */\n  static fromSchnorr(key: SchnorrPublicKey): SigningPublicKey {\n    return new SigningPublicKey(\n      SignatureScheme.Schnorr,\n      key,\n      undefined,\n      undefined,\n      undefined,\n      undefined,\n    );\n  }\n\n  /**\n   * Creates a new signing public key from an ECDSA (compressed) public key.\n   *\n   * @param key - An ECPublicKey\n   * @returns A new signing public key containing the ECDSA key\n   */\n  static fromEcdsa(key: ECPublicKey): SigningPublicKey {\n    return new SigningPublicKey(\n      SignatureScheme.Ecdsa,\n      undefined,\n      key,\n      undefined,\n      undefined,\n      undefined,\n    );\n  }\n\n  /**\n   * Creates a new signing public key from an Ed25519 public key.\n   *\n   * @param key - An Ed25519 public key\n   * @returns A new signing public key containing the Ed25519 key\n   */\n  static fromEd25519(key: Ed25519PublicKey): SigningPublicKey {\n    return new SigningPublicKey(\n      SignatureScheme.Ed25519,\n      undefined,\n      undefined,\n      key,\n      undefined,\n      undefined,\n    );\n  }\n\n  /**\n   * Creates a new signing public key from an Sr25519 public key.\n   *\n   * @param key - An Sr25519 public key\n   * @returns A new signing public key containing the Sr25519 key\n   */\n  static fromSr25519(key: Sr25519PublicKey): SigningPublicKey {\n    return new SigningPublicKey(\n      SignatureScheme.Sr25519,\n      undefined,\n      undefined,\n      undefined,\n      key,\n      undefined,\n    );\n  }\n\n  /**\n   * Creates a new signing public key from an MLDSAPublicKey.\n   *\n   * @param key - An MLDSAPublicKey\n   * @returns A new signing public key containing the MLDSA key\n   */\n  static fromMldsa(key: MLDSAPublicKey): SigningPublicKey {\n    // Determine the SignatureScheme based on the MLDSA level\n    let scheme: SignatureScheme;\n    switch (key.level()) {\n      case MLDSALevel.MLDSA44:\n        scheme = SignatureScheme.MLDSA44;\n        break;\n      case MLDSALevel.MLDSA65:\n        scheme = SignatureScheme.MLDSA65;\n        break;\n      case MLDSALevel.MLDSA87:\n        scheme = SignatureScheme.MLDSA87;\n        break;\n      default:\n        throw new Error(`Unknown MLDSA level: ${key.level()}`);\n    }\n    return new SigningPublicKey(scheme, undefined, undefined, undefined, undefined, key);\n  }\n\n  /**\n   * Creates a new signing public key from an SSHPublicKey.\n   *\n   * Mirrors Rust `SigningPublicKey::from_ssh`\n   * (`bc-components-rust/src/signing/signing_public_key.rs:214`).\n   *\n   * @param key - An SSHPublicKey\n   * @returns A new signing public key wrapping the SSH public key\n   */\n  static fromSsh(key: SSHPublicKey): SigningPublicKey {\n    let scheme: SignatureScheme;\n    switch (key.data.kind) {\n      case \"ed25519\":\n        scheme = SignatureScheme.SshEd25519;\n        break;\n      case \"dsa\":\n        scheme = SignatureScheme.SshDsa;\n        break;\n      case \"ecdsa\":\n        switch (key.data.curve) {\n          case \"nistp256\":\n            scheme = SignatureScheme.SshEcdsaP256;\n            break;\n          case \"nistp384\":\n            scheme = SignatureScheme.SshEcdsaP384;\n            break;\n        }\n        break;\n    }\n    return new SigningPublicKey(scheme, undefined, undefined, undefined, undefined, undefined, key);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the signature scheme of this key.\n   */\n  scheme(): SignatureScheme {\n    return this._type;\n  }\n\n  /**\n   * Returns a human-readable string identifying the key type.\n   * @returns A string like \"Ed25519\", \"Schnorr\", \"ECDSA\", \"Sr25519\", \"MLDSA-44\", etc.\n   */\n  keyType(): string {\n    switch (this._type) {\n      case SignatureScheme.Ed25519:\n        return \"Ed25519\";\n      case SignatureScheme.Schnorr:\n        return \"Schnorr\";\n      case SignatureScheme.Ecdsa:\n        return \"ECDSA\";\n      case SignatureScheme.Sr25519:\n        return \"Sr25519\";\n      case SignatureScheme.MLDSA44:\n        return \"MLDSA-44\";\n      case SignatureScheme.MLDSA65:\n        return \"MLDSA-65\";\n      case SignatureScheme.MLDSA87:\n        return \"MLDSA-87\";\n      case SignatureScheme.SshEd25519:\n        return \"SSH-Ed25519\";\n      case SignatureScheme.SshDsa:\n        return \"SSH-DSA\";\n      case SignatureScheme.SshEcdsaP256:\n        return \"SSH-ECDSA-P256\";\n      case SignatureScheme.SshEcdsaP384:\n        return \"SSH-ECDSA-P384\";\n      default:\n        return this._type;\n    }\n  }\n\n  /**\n   * Returns the underlying Schnorr public key if this is a Schnorr key.\n   *\n   * @returns The SchnorrPublicKey if this is a Schnorr key, null otherwise\n   */\n  toSchnorr(): SchnorrPublicKey | null {\n    if (this._type === SignatureScheme.Schnorr && this._schnorrKey !== undefined) {\n      return this._schnorrKey;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying ECDSA public key if this is an ECDSA key.\n   *\n   * @returns The ECPublicKey if this is an ECDSA key, null otherwise\n   */\n  toEcdsa(): ECPublicKey | null {\n    if (this._type === SignatureScheme.Ecdsa && this._ecdsaKey !== undefined) {\n      return this._ecdsaKey;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying Ed25519 public key if this is an Ed25519 key.\n   *\n   * @returns The Ed25519 public key if this is an Ed25519 key, null otherwise\n   */\n  toEd25519(): Ed25519PublicKey | null {\n    if (this._type === SignatureScheme.Ed25519 && this._ed25519Key !== undefined) {\n      return this._ed25519Key;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying Sr25519 public key if this is an Sr25519 key.\n   *\n   * @returns The Sr25519 public key if this is an Sr25519 key, null otherwise\n   */\n  toSr25519(): Sr25519PublicKey | null {\n    if (this._type === SignatureScheme.Sr25519 && this._sr25519Key !== undefined) {\n      return this._sr25519Key;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is a Schnorr signing key.\n   */\n  isSchnorr(): boolean {\n    return this._type === SignatureScheme.Schnorr;\n  }\n\n  /**\n   * Checks if this is an ECDSA signing key.\n   */\n  isEcdsa(): boolean {\n    return this._type === SignatureScheme.Ecdsa;\n  }\n\n  /**\n   * Checks if this is an Ed25519 signing key.\n   */\n  isEd25519(): boolean {\n    return this._type === SignatureScheme.Ed25519;\n  }\n\n  /**\n   * Checks if this is an Sr25519 signing key.\n   */\n  isSr25519(): boolean {\n    return this._type === SignatureScheme.Sr25519;\n  }\n\n  /**\n   * Returns the underlying MLDSA public key if this is an MLDSA key.\n   *\n   * @returns The MLDSAPublicKey if this is an MLDSA key, null otherwise\n   */\n  toMldsa(): MLDSAPublicKey | null {\n    if (isMldsaScheme(this._type) && this._mldsaKey !== undefined) {\n      return this._mldsaKey;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is an MLDSA signing key.\n   */\n  isMldsa(): boolean {\n    return isMldsaScheme(this._type);\n  }\n\n  /**\n   * Returns the underlying SSH public key if this is an SSH key.\n   *\n   * Mirrors Rust `SigningPublicKey::to_ssh`\n   * (`bc-components-rust/src/signing/signing_public_key.rs:272`).\n   *\n   * @returns The SSHPublicKey if this is an SSH key, null otherwise\n   */\n  toSsh(): SSHPublicKey | null {\n    return this._sshKey ?? null;\n  }\n\n  /**\n   * Checks if this is an SSH signing key.\n   */\n  isSsh(): boolean {\n    return this._sshKey !== undefined;\n  }\n\n  /**\n   * Returns a copy of this SSH public key with its comment replaced.\n   * Throws if this is not an SSH key — mirrors Rust's `set_comment`\n   * which is only callable on `SigningPublicKey::SSH` variants.\n   */\n  withSshComment(comment: string): SigningPublicKey {\n    if (this._sshKey === undefined) {\n      throw new Error(`SigningPublicKey.withSshComment: not an SSH key (scheme: ${this._type})`);\n    }\n    return SigningPublicKey.fromSsh(this._sshKey.withComment(comment));\n  }\n\n  /**\n   * Compare with another SigningPublicKey.\n   */\n  equals(other: SigningPublicKey): boolean {\n    if (this._type !== other._type) return false;\n    switch (this._type) {\n      case SignatureScheme.Schnorr:\n        if (this._schnorrKey === undefined || other._schnorrKey === undefined) return false;\n        return this._schnorrKey.equals(other._schnorrKey);\n      case SignatureScheme.Ecdsa:\n        if (this._ecdsaKey === undefined || other._ecdsaKey === undefined) return false;\n        return this._ecdsaKey.equals(other._ecdsaKey);\n      case SignatureScheme.Ed25519:\n        if (this._ed25519Key === undefined || other._ed25519Key === undefined) return false;\n        return this._ed25519Key.equals(other._ed25519Key);\n      case SignatureScheme.Sr25519:\n        if (this._sr25519Key === undefined || other._sr25519Key === undefined) return false;\n        return this._sr25519Key.equals(other._sr25519Key);\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87:\n        if (this._mldsaKey === undefined || other._mldsaKey === undefined) return false;\n        return this._mldsaKey.equals(other._mldsaKey);\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined || other._sshKey === undefined) return false;\n        return this._sshKey.equals(other._sshKey);\n      }\n    }\n  }\n\n  /**\n   * Get string representation.\n   *\n   * Mirrors Rust `Display for SigningPublicKey`\n   * (`bc-components-rust/src/signing/signing_public_key.rs:573-606`):\n   *   `SigningPublicKey(<ref_hex_short>, <inner_key_display>)`\n   * The reference is computed from the tagged-CBOR form.\n   */\n  toString(): string {\n    const refShort = this.reference().shortReference(\"hex\");\n    let innerDisplay: string;\n    switch (this._type) {\n      case SignatureScheme.Schnorr:\n        innerDisplay = this._schnorrKey?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.Ecdsa:\n        innerDisplay = this._ecdsaKey?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.Ed25519:\n        innerDisplay = this._ed25519Key?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.Sr25519:\n        innerDisplay = this._sr25519Key?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87:\n        innerDisplay = this._mldsaKey?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384:\n        // Mirror Rust `SigningPublicKey::SSH(key) => format!(\"SSHPublicKey({})\", key.ref_hex_short())`\n        // (`signing_public_key.rs:592-594`).\n        innerDisplay = this._sshKey?.toString() ?? `SSHPublicKey(${refShort})`;\n        break;\n    }\n    return `SigningPublicKey(${refShort}, ${innerDisplay})`;\n  }\n\n  // ============================================================================\n  // ReferenceProvider Interface\n  // ============================================================================\n\n  /**\n   * Returns a unique reference to this SigningPublicKey instance.\n   *\n   * The reference is derived from the SHA-256 hash of the tagged CBOR\n   * representation, providing a unique, content-addressable identifier.\n   */\n  reference(): Reference {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return Reference.from(digest);\n  }\n\n  // ============================================================================\n  // Verifier Interface\n  // ============================================================================\n\n  /**\n   * Verifies a signature against a message.\n   *\n   * @param signature - The signature to verify\n   * @param message - The message that was allegedly signed\n   * @returns `true` if the signature is valid, `false` otherwise\n   */\n  verify(signature: Signature, message: Uint8Array): boolean {\n    // Check that signature scheme matches\n    if (signature.scheme() !== this._type) {\n      return false;\n    }\n\n    switch (this._type) {\n      case SignatureScheme.Schnorr: {\n        if (this._schnorrKey === undefined) {\n          return false;\n        }\n        const sigData = signature.toSchnorr();\n        if (sigData === null) {\n          return false;\n        }\n        try {\n          return this._schnorrKey.schnorrVerify(sigData, message);\n        } catch {\n          return false;\n        }\n      }\n      case SignatureScheme.Ecdsa: {\n        if (this._ecdsaKey === undefined) {\n          return false;\n        }\n        const sigData = signature.toEcdsa();\n        if (sigData === null) {\n          return false;\n        }\n        try {\n          return this._ecdsaKey.verify(sigData, message);\n        } catch {\n          return false;\n        }\n      }\n      case SignatureScheme.Ed25519: {\n        if (this._ed25519Key === undefined) {\n          return false;\n        }\n        const sigData = signature.toEd25519();\n        if (sigData === null) {\n          return false;\n        }\n        try {\n          return this._ed25519Key.verify(message, sigData);\n        } catch {\n          return false;\n        }\n      }\n      case SignatureScheme.Sr25519: {\n        if (this._sr25519Key === undefined) {\n          return false;\n        }\n        const sigData = signature.toSr25519();\n        if (sigData === null) {\n          return false;\n        }\n        try {\n          return this._sr25519Key.verify(sigData, message);\n        } catch {\n          return false;\n        }\n      }\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87: {\n        if (this._mldsaKey === undefined) {\n          return false;\n        }\n        const mldsaSig = signature.toMldsa();\n        if (mldsaSig === null) {\n          return false;\n        }\n        try {\n          return this._mldsaKey.verify(mldsaSig, message);\n        } catch {\n          return false;\n        }\n      }\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined) return false;\n        const sshSig = signature.toSsh();\n        if (sshSig === null) return false;\n        // Mirror Rust `SigningPublicKey::SSH(key) => key.verify(sig.namespace(), msg, sig).is_ok()`\n        // (`signing_public_key.rs:362-364`).\n        try {\n          return this._sshKey.verifySshSignature(sshSig.namespace, message, sshSig);\n        } catch {\n          return false;\n        }\n      }\n    }\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with SigningPublicKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SIGNING_PUBLIC_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format (matching Rust bc-components):\n   * - Schnorr: h'<32-byte-x-only-public-key>' (bare byte string)\n   * - ECDSA:   [1, h'<33-byte-compressed-public-key>']\n   * - Ed25519: [2, h'<32-byte-public-key>']\n   * - Sr25519: [3, h'<32-byte-public-key>']\n   */\n  untaggedCbor(): Cbor {\n    switch (this._type) {\n      case SignatureScheme.Schnorr: {\n        if (this._schnorrKey === undefined) {\n          throw new Error(\"Schnorr public key is missing\");\n        }\n        // Rust: CBOR::to_byte_string(key.data()) - bare byte string\n        return toByteString(this._schnorrKey.toData());\n      }\n      case SignatureScheme.Ecdsa: {\n        if (this._ecdsaKey === undefined) {\n          throw new Error(\"ECDSA public key is missing\");\n        }\n        return cbor([1, toByteString(this._ecdsaKey.toData())]);\n      }\n      case SignatureScheme.Ed25519: {\n        if (this._ed25519Key === undefined) {\n          throw new Error(\"Ed25519 public key is missing\");\n        }\n        return cbor([2, toByteString(this._ed25519Key.toData())]);\n      }\n      case SignatureScheme.Sr25519: {\n        if (this._sr25519Key === undefined) {\n          throw new Error(\"Sr25519 public key is missing\");\n        }\n        return cbor([3, toByteString(this._sr25519Key.toData())]);\n      }\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87: {\n        if (this._mldsaKey === undefined) {\n          throw new Error(\"MLDSA public key is missing\");\n        }\n        // Rust: delegates to MLDSAPublicKey (which produces tagged CBOR)\n        return this._mldsaKey.taggedCbor();\n      }\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined) {\n          throw new Error(\"SSH public key is missing\");\n        }\n        // Mirror Rust `SigningPublicKey::SSH(key) => to_tagged_value(TAG_SSH_TEXT_PUBLIC_KEY, openssh)`\n        // (`signing_public_key.rs:441-443`).\n        return toTaggedValue(TAG_SSH_TEXT_PUBLIC_KEY, this._sshKey.toOpenssh());\n      }\n    }\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 SigningPublicKey by decoding it from untagged CBOR.\n   *\n   * Format (matching Rust bc-components):\n   * - h'<32-byte-key>' (bare byte string) for Schnorr\n   * - [1, h'<33-byte-key>'] for ECDSA\n   * - [2, h'<32-byte-key>'] for Ed25519\n   * - [3, h'<32-byte-key>'] for Sr25519\n   */\n  fromUntaggedCbor(cborValue: Cbor): SigningPublicKey {\n    // Rust format: Schnorr is a bare byte string\n    if (isBytes(cborValue)) {\n      const keyData = expectBytes(cborValue);\n      return SigningPublicKey.fromSchnorr(SchnorrPublicKey.from(keyData));\n    }\n\n    // Array format for ECDSA, Ed25519, Sr25519\n    if (isArray(cborValue)) {\n      const elements = expectArray(cborValue);\n\n      if (elements.length !== 2) {\n        throw new Error(\"SigningPublicKey array must have 2 elements\");\n      }\n\n      const discriminator = expectUnsigned(elements[0]);\n      const keyData = expectBytes(elements[1]);\n\n      switch (Number(discriminator)) {\n        case 1: // ECDSA\n          return SigningPublicKey.fromEcdsa(ECPublicKey.from(keyData));\n        case 2: // Ed25519\n          return SigningPublicKey.fromEd25519(Ed25519PublicKey.from(keyData));\n        case 3: // Sr25519\n          return SigningPublicKey.fromSr25519(Sr25519PublicKey.from(keyData));\n        default:\n          throw new Error(`Unknown SigningPublicKey discriminator: ${discriminator}`);\n      }\n    }\n\n    // Tagged format for MLDSA / SSH\n    if (isTagged(cborValue)) {\n      const tagged = cborValue.asTagged();\n      if (tagged?.[0].value === TAG_MLDSA_PUBLIC_KEY.value) {\n        const mldsaKey = MLDSAPublicKey.fromTaggedCbor(cborValue);\n        return SigningPublicKey.fromMldsa(mldsaKey);\n      }\n      if (tagged?.[0].value === TAG_SSH_TEXT_PUBLIC_KEY.value) {\n        const text = expectText(tagged[1]);\n        const sshKey = SSHPublicKey.fromOpenssh(text);\n        return SigningPublicKey.fromSsh(sshKey);\n      }\n    }\n\n    throw new Error(\n      \"SigningPublicKey must be a byte string (Schnorr), array (ECDSA/Ed25519/Sr25519), tagged MLDSA, or tagged SSH\",\n    );\n  }\n\n  /**\n   * Creates a SigningPublicKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): SigningPublicKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): SigningPublicKey {\n    // Create a dummy instance for accessing instance methods\n    const dummy = new SigningPublicKey(\n      SignatureScheme.Ed25519,\n      undefined, // schnorrKey\n      undefined, // ecdsaKey\n      Ed25519PublicKey.from(new Uint8Array(ED25519_PUBLIC_KEY_SIZE)), // ed25519Key\n    );\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): SigningPublicKey {\n    const cborValue = decodeCbor(data);\n    return SigningPublicKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): SigningPublicKey {\n    const cborValue = decodeCbor(data);\n    return SigningPublicKey.fromUntaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR.\n   */\n  static fromUntaggedCbor(cborValue: Cbor): SigningPublicKey {\n    // Create a dummy instance for accessing instance methods\n    const dummy = new SigningPublicKey(\n      SignatureScheme.Ed25519,\n      undefined, // schnorrKey\n      undefined, // ecdsaKey\n      Ed25519PublicKey.from(new Uint8Array(ED25519_PUBLIC_KEY_SIZE)), // ed25519Key\n    );\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR (Uniform Resource) Serialization\n  // ============================================================================\n\n  /**\n   * Get the UR type for signing public keys.\n   */\n  static readonly UR_TYPE = \"signing-public-key\";\n\n  /**\n   * Returns the UR representation of the signing public key.\n   */\n  ur(): UR {\n    // A UR's content is the *untagged* CBOR; the `signing-public-key` type\n    // string already implies tag 40022. Using `taggedCbor()` here would\n    // double-tag the content (`tag(40022, …)` inside the UR), diverging from\n    // Rust and breaking interop. Mirrors the canonical `toUR` pattern\n    // (`ur-encodable.ts`).\n    return UR.new(SigningPublicKey.UR_TYPE, this.untaggedCbor());\n  }\n\n  /**\n   * Returns the UR string representation of the signing public key.\n   */\n  urString(): string {\n    return this.ur().string();\n  }\n\n  /**\n   * Creates a SigningPublicKey from a UR.\n   */\n  static fromUR(ur: UR): SigningPublicKey {\n    ur.checkType(SigningPublicKey.UR_TYPE);\n    // The UR content is untagged (the type implies tag 40022), so decode it\n    // directly as untagged CBOR. Mirrors the canonical `fromUR` pattern\n    // (`ur-decodable.ts`).\n    return SigningPublicKey.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a SigningPublicKey from a UR string.\n   */\n  static fromURString(urString: string): SigningPublicKey {\n    const ur = UR.fromURString(urString);\n    return SigningPublicKey.fromUR(ur);\n  }\n\n  /**\n   * Alias for fromURString for Rust API compatibility.\n   */\n  static fromUrString(urString: string): SigningPublicKey {\n    return SigningPublicKey.fromURString(urString);\n  }\n\n  // ============================================================================\n  // SSH Format\n  // ============================================================================\n\n  /**\n   * Returns the OpenSSH single-line public-key text for an SSH public key.\n   *\n   * Only valid when this `SigningPublicKey` wraps an `SSHPublicKey`\n   * (i.e. one of the four `SignatureScheme.SshXxx` variants). Mirrors\n   * Rust's `SigningPublicKey::SSH(key) => key.to_openssh()` usage at\n   * `signing_public_key.rs:442`.\n   */\n  toSshOpenssh(): string {\n    if (this._sshKey === undefined) {\n      throw new Error(`SigningPublicKey is not an SSH key (scheme: ${this._type})`);\n    }\n    return this._sshKey.toOpenssh();\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * A private key used for creating digital signatures.\n *\n * `SigningPrivateKey` is a type representing different types of signing\n * private keys. Supports Schnorr, ECDSA, Ed25519, and SR25519.\n *\n * This type implements the `Signer` interface, allowing it to create signatures.\n *\n * # CBOR Serialization\n *\n * `SigningPrivateKey` is serialized to CBOR with tag 40021.\n *\n * The CBOR encoding (matching Rust bc-components):\n * - Schnorr: `#6.40021(h'<32-byte-private-key>')` (bare byte string)\n * - ECDSA:   `#6.40021([1, h'<32-byte-private-key>'])`\n * - Ed25519: `#6.40021([2, h'<32-byte-private-key>'])`\n * - SR25519: `#6.40021([3, h'<32-byte-seed>'])`\n *\n * Ported from bc-components-rust/src/signing/signing_private_key.rs\n */\n\nimport { ED25519_PRIVATE_KEY_SIZE } from \"@bcts/crypto\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  toByteString,\n  toTaggedValue,\n  expectArray,\n  expectBytes,\n  expectText,\n  expectUnsigned,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  isBytes,\n  isArray,\n  isTagged,\n} from \"@bcts/dcbor\";\nimport {\n  SIGNING_PRIVATE_KEY as TAG_SIGNING_PRIVATE_KEY,\n  MLDSA_PRIVATE_KEY as TAG_MLDSA_PRIVATE_KEY,\n  SSH_TEXT_PRIVATE_KEY as TAG_SSH_TEXT_PRIVATE_KEY,\n} from \"@bcts/tags\";\nimport { Ed25519PrivateKey } from \"../ed25519/ed25519-private-key.js\";\nimport { Sr25519PrivateKey } from \"../sr25519/sr25519-private-key.js\";\nimport { ECPrivateKey } from \"../ec-key/ec-private-key.js\";\nimport { MLDSAPrivateKey } from \"../mldsa/mldsa-private-key.js\";\nimport { MLDSALevel } from \"../mldsa/mldsa-level.js\";\nimport { SSHPrivateKey } from \"../ssh/ssh-private-key.js\";\nimport { SignatureScheme, isMldsaScheme, type SigningOptions } from \"./signature-scheme.js\";\nimport { Signature } from \"./signature.js\";\nimport { SigningPublicKey } from \"./signing-public-key.js\";\nimport type { Signer, Verifier } from \"./signer.js\";\nimport { Reference, type ReferenceProvider } from \"../reference.js\";\nimport { Digest } from \"../digest.js\";\nimport { UR } from \"@bcts/uniform-resources\";\n\n/**\n * A private key used for creating digital signatures.\n *\n * Currently supports:\n * - Schnorr private keys (32 bytes, secp256k1) - bare byte string in CBOR\n * - ECDSA private keys (32 bytes, secp256k1) - discriminator 1\n * - Ed25519 private keys (32 bytes) - discriminator 2\n * - SR25519 private keys (32-byte seed) - discriminator 3\n * - MLDSA private keys (post-quantum) - tagged CBOR delegating to MLDSAPrivateKey\n */\nexport class SigningPrivateKey\n  implements\n    Signer,\n    Verifier,\n    ReferenceProvider,\n    CborTaggedEncodable,\n    CborTaggedDecodable<SigningPrivateKey>\n{\n  private readonly _type: SignatureScheme;\n  private readonly _ecKey: ECPrivateKey | undefined;\n  private readonly _ed25519Key: Ed25519PrivateKey | undefined;\n  private readonly _sr25519Key: Sr25519PrivateKey | undefined;\n  private readonly _mldsaKey: MLDSAPrivateKey | undefined;\n  private readonly _sshKey: SSHPrivateKey | undefined;\n\n  private constructor(\n    type: SignatureScheme,\n    ecKey?: ECPrivateKey,\n    ed25519Key?: Ed25519PrivateKey,\n    sr25519Key?: Sr25519PrivateKey,\n    mldsaKey?: MLDSAPrivateKey,\n    sshKey?: SSHPrivateKey,\n  ) {\n    this._type = type;\n    this._ecKey = ecKey;\n    this._ed25519Key = ed25519Key;\n    this._sr25519Key = sr25519Key;\n    this._mldsaKey = mldsaKey;\n    this._sshKey = sshKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Creates a new Schnorr signing private key from an ECPrivateKey.\n   *\n   * @param key - The EC private key to use for Schnorr signing\n   * @returns A new Schnorr signing private key\n   */\n  static newSchnorr(key: ECPrivateKey): SigningPrivateKey {\n    return new SigningPrivateKey(SignatureScheme.Schnorr, key, undefined, undefined, undefined);\n  }\n\n  /**\n   * Creates a new ECDSA signing private key from an ECPrivateKey.\n   *\n   * @param key - The EC private key to use for ECDSA signing\n   * @returns A new ECDSA signing private key\n   */\n  static newEcdsa(key: ECPrivateKey): SigningPrivateKey {\n    return new SigningPrivateKey(SignatureScheme.Ecdsa, key, undefined, undefined, undefined);\n  }\n\n  /**\n   * Creates a new Ed25519 signing private key from an Ed25519PrivateKey.\n   *\n   * @param key - The Ed25519 private key to use\n   * @returns A new Ed25519 signing private key\n   */\n  static newEd25519(key: Ed25519PrivateKey): SigningPrivateKey {\n    return new SigningPrivateKey(SignatureScheme.Ed25519, undefined, key, undefined, undefined);\n  }\n\n  /**\n   * Creates a new SR25519 signing private key from an Sr25519PrivateKey.\n   *\n   * @param key - The SR25519 private key to use\n   * @returns A new SR25519 signing private key\n   */\n  static newSr25519(key: Sr25519PrivateKey): SigningPrivateKey {\n    return new SigningPrivateKey(SignatureScheme.Sr25519, undefined, undefined, key, undefined);\n  }\n\n  /**\n   * Creates a new MLDSA signing private key from an MLDSAPrivateKey.\n   *\n   * @param key - The MLDSA private key to use\n   * @returns A new MLDSA signing private key\n   */\n  static newMldsa(key: MLDSAPrivateKey): SigningPrivateKey {\n    // Determine the SignatureScheme based on the MLDSA level\n    let scheme: SignatureScheme;\n    switch (key.level()) {\n      case MLDSALevel.MLDSA44:\n        scheme = SignatureScheme.MLDSA44;\n        break;\n      case MLDSALevel.MLDSA65:\n        scheme = SignatureScheme.MLDSA65;\n        break;\n      case MLDSALevel.MLDSA87:\n        scheme = SignatureScheme.MLDSA87;\n        break;\n      default:\n        throw new Error(`Unknown MLDSA level: ${key.level()}`);\n    }\n    return new SigningPrivateKey(scheme, undefined, undefined, undefined, key);\n  }\n\n  /**\n   * Creates a new SSH signing private key from an SSHPrivateKey.\n   *\n   * Mirrors Rust `SigningPrivateKey::new_ssh`\n   * (`bc-components-rust/src/signing/signing_private_key.rs:317`).\n   *\n   * @param key - The SSH private key to wrap\n   * @returns A new SSH signing private key\n   */\n  static fromSsh(key: SSHPrivateKey): SigningPrivateKey {\n    let scheme: SignatureScheme;\n    switch (key.data.kind) {\n      case \"ed25519\":\n        scheme = SignatureScheme.SshEd25519;\n        break;\n      case \"dsa\":\n        scheme = SignatureScheme.SshDsa;\n        break;\n      case \"ecdsa\":\n        switch (key.data.curve) {\n          case \"nistp256\":\n            scheme = SignatureScheme.SshEcdsaP256;\n            break;\n          case \"nistp384\":\n            scheme = SignatureScheme.SshEcdsaP384;\n            break;\n        }\n        break;\n    }\n    return new SigningPrivateKey(scheme, undefined, undefined, undefined, undefined, key);\n  }\n\n  /**\n   * Creates a new random Ed25519 signing private key.\n   *\n   * @returns A new random Ed25519 signing private key\n   */\n  static random(): SigningPrivateKey {\n    return SigningPrivateKey.newEd25519(Ed25519PrivateKey.random());\n  }\n\n  /**\n   * Creates a new random Schnorr signing private key.\n   *\n   * @returns A new random Schnorr signing private key\n   */\n  static randomSchnorr(): SigningPrivateKey {\n    return SigningPrivateKey.newSchnorr(ECPrivateKey.random());\n  }\n\n  /**\n   * Creates a new random ECDSA signing private key.\n   *\n   * @returns A new random ECDSA signing private key\n   */\n  static randomEcdsa(): SigningPrivateKey {\n    return SigningPrivateKey.newEcdsa(ECPrivateKey.random());\n  }\n\n  /**\n   * Creates a new random SR25519 signing private key.\n   *\n   * @returns A new random SR25519 signing private key\n   */\n  static randomSr25519(): SigningPrivateKey {\n    return SigningPrivateKey.newSr25519(Sr25519PrivateKey.random());\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the signature scheme of this key.\n   */\n  scheme(): SignatureScheme {\n    return this._type;\n  }\n\n  /**\n   * Returns a human-readable string identifying the key type.\n   * @returns A string like \"Ed25519\", \"Schnorr\", \"ECDSA\", \"Sr25519\", \"MLDSA-44\", etc.\n   */\n  keyType(): string {\n    switch (this._type) {\n      case SignatureScheme.Ed25519:\n        return \"Ed25519\";\n      case SignatureScheme.Schnorr:\n        return \"Schnorr\";\n      case SignatureScheme.Ecdsa:\n        return \"ECDSA\";\n      case SignatureScheme.Sr25519:\n        return \"Sr25519\";\n      case SignatureScheme.MLDSA44:\n        return \"MLDSA-44\";\n      case SignatureScheme.MLDSA65:\n        return \"MLDSA-65\";\n      case SignatureScheme.MLDSA87:\n        return \"MLDSA-87\";\n      case SignatureScheme.SshEd25519:\n        return \"SSH-Ed25519\";\n      case SignatureScheme.SshDsa:\n        return \"SSH-DSA\";\n      case SignatureScheme.SshEcdsaP256:\n        return \"SSH-ECDSA-P256\";\n      case SignatureScheme.SshEcdsaP384:\n        return \"SSH-ECDSA-P384\";\n      default:\n        return this._type;\n    }\n  }\n\n  /**\n   * Returns the underlying EC private key if this is a Schnorr or ECDSA key.\n   *\n   * @returns The EC private key if this is a Schnorr or ECDSA key, null otherwise\n   */\n  toEc(): ECPrivateKey | null {\n    if (\n      (this._type === SignatureScheme.Schnorr || this._type === SignatureScheme.Ecdsa) &&\n      this._ecKey !== undefined\n    ) {\n      return this._ecKey;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying Schnorr private key if this is a Schnorr key.\n   *\n   * @returns The EC private key if this is a Schnorr key, null otherwise\n   */\n  toSchnorr(): ECPrivateKey | null {\n    if (this._type === SignatureScheme.Schnorr && this._ecKey !== undefined) {\n      return this._ecKey;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying ECDSA private key if this is an ECDSA key.\n   *\n   * @returns The EC private key if this is an ECDSA key, null otherwise\n   */\n  toEcdsa(): ECPrivateKey | null {\n    if (this._type === SignatureScheme.Ecdsa && this._ecKey !== undefined) {\n      return this._ecKey;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying Ed25519 private key if this is an Ed25519 key.\n   *\n   * @returns The Ed25519 private key if this is an Ed25519 key, null otherwise\n   */\n  toEd25519(): Ed25519PrivateKey | null {\n    if (this._type === SignatureScheme.Ed25519 && this._ed25519Key !== undefined) {\n      return this._ed25519Key;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying Sr25519 private key if this is an Sr25519 key.\n   *\n   * @returns The Sr25519 private key if this is an Sr25519 key, null otherwise\n   */\n  toSr25519(): Sr25519PrivateKey | null {\n    if (this._type === SignatureScheme.Sr25519 && this._sr25519Key !== undefined) {\n      return this._sr25519Key;\n    }\n    return null;\n  }\n\n  /**\n   * Returns the underlying MLDSA private key if this is an MLDSA key.\n   *\n   * @returns The MLDSA private key if this is an MLDSA key, null otherwise\n   */\n  toMldsa(): MLDSAPrivateKey | null {\n    if (isMldsaScheme(this._type) && this._mldsaKey !== undefined) {\n      return this._mldsaKey;\n    }\n    return null;\n  }\n\n  /**\n   * Checks if this is a Schnorr signing key.\n   */\n  isSchnorr(): boolean {\n    return this._type === SignatureScheme.Schnorr;\n  }\n\n  /**\n   * Checks if this is an ECDSA signing key.\n   */\n  isEcdsa(): boolean {\n    return this._type === SignatureScheme.Ecdsa;\n  }\n\n  /**\n   * Checks if this is an Ed25519 signing key.\n   */\n  isEd25519(): boolean {\n    return this._type === SignatureScheme.Ed25519;\n  }\n\n  /**\n   * Checks if this is an Sr25519 signing key.\n   */\n  isSr25519(): boolean {\n    return this._type === SignatureScheme.Sr25519;\n  }\n\n  /**\n   * Checks if this is an MLDSA signing key.\n   */\n  isMldsa(): boolean {\n    return isMldsaScheme(this._type);\n  }\n\n  /**\n   * Derives the corresponding public key for this private key.\n   *\n   * @returns The public key corresponding to this private key\n   */\n  publicKey(): SigningPublicKey {\n    switch (this._type) {\n      case SignatureScheme.Schnorr: {\n        if (this._ecKey === undefined) {\n          throw new Error(\"EC private key is missing\");\n        }\n        return SigningPublicKey.fromSchnorr(this._ecKey.schnorrPublicKey());\n      }\n      case SignatureScheme.Ecdsa: {\n        if (this._ecKey === undefined) {\n          throw new Error(\"EC private key is missing\");\n        }\n        return SigningPublicKey.fromEcdsa(this._ecKey.publicKey());\n      }\n      case SignatureScheme.Ed25519: {\n        if (this._ed25519Key === undefined) {\n          throw new Error(\"Ed25519 private key is missing\");\n        }\n        return SigningPublicKey.fromEd25519(this._ed25519Key.publicKey());\n      }\n      case SignatureScheme.Sr25519: {\n        if (this._sr25519Key === undefined) {\n          throw new Error(\"Sr25519 private key is missing\");\n        }\n        return SigningPublicKey.fromSr25519(this._sr25519Key.publicKey());\n      }\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87: {\n        if (this._mldsaKey === undefined) {\n          throw new Error(\"MLDSA private key is missing\");\n        }\n        return SigningPublicKey.fromMldsa(this._mldsaKey.publicKey());\n      }\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined) {\n          throw new Error(\"SSH private key is missing\");\n        }\n        return SigningPublicKey.fromSsh(this._sshKey.publicKey());\n      }\n    }\n  }\n\n  /**\n   * Returns the underlying SSH private key if this is an SSH key.\n   *\n   * Mirrors Rust `SigningPrivateKey::to_ssh`\n   * (`bc-components-rust/src/signing/signing_private_key.rs:387`).\n   *\n   * @returns The SSHPrivateKey if this is an SSH key, null otherwise\n   */\n  toSsh(): SSHPrivateKey | null {\n    return this._sshKey ?? null;\n  }\n\n  /**\n   * Checks if this is an SSH signing key.\n   */\n  isSsh(): boolean {\n    return this._sshKey !== undefined;\n  }\n\n  /**\n   * Compare with another SigningPrivateKey.\n   */\n  equals(other: SigningPrivateKey): boolean {\n    if (this._type !== other._type) return false;\n    switch (this._type) {\n      case SignatureScheme.Schnorr:\n      case SignatureScheme.Ecdsa:\n        if (this._ecKey === undefined || other._ecKey === undefined) return false;\n        return this._ecKey.equals(other._ecKey);\n      case SignatureScheme.Ed25519:\n        if (this._ed25519Key === undefined || other._ed25519Key === undefined) return false;\n        return this._ed25519Key.equals(other._ed25519Key);\n      case SignatureScheme.Sr25519:\n        if (this._sr25519Key === undefined || other._sr25519Key === undefined) return false;\n        return this._sr25519Key.equals(other._sr25519Key);\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87:\n        if (this._mldsaKey === undefined || other._mldsaKey === undefined) return false;\n        return this._mldsaKey.equals(other._mldsaKey);\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined || other._sshKey === undefined) return false;\n        return this._sshKey.toOpenssh() === other._sshKey.toOpenssh();\n      }\n    }\n  }\n\n  /**\n   * Mirror of Rust `Display for SigningPrivateKey`\n   * (`bc-components-rust/src/signing/signing_private_key.rs:1048-1095`):\n   *   `SigningPrivateKey(<refHexShort>, <inner>)`\n   * where `<inner>` is:\n   *   - `SchnorrPrivateKey(<refHexShort>)` / `ECDSAPrivateKey(<refHexShort>)`\n   *     for the secp256k1 variants (Rust formats them inline by tag rather\n   *     than delegating to the inner key's Display)\n   *   - the inner key's Display for Ed25519 and MLDSA\n   *   - `SSHPrivateKey(<refHexShort>)` for SSH\n   * The previous abbreviated form (`SigningPrivateKey(<type>)` only) was\n   * a parity drift caught by the E1a summarizer audit.\n   */\n  toString(): string {\n    const refShort = this.reference().shortReference(\"hex\");\n    let innerDisplay: string;\n    switch (this._type) {\n      case SignatureScheme.Schnorr:\n        innerDisplay = `SchnorrPrivateKey(${refShort})`;\n        break;\n      case SignatureScheme.Ecdsa:\n        innerDisplay = `ECDSAPrivateKey(${refShort})`;\n        break;\n      case SignatureScheme.Ed25519:\n        innerDisplay = this._ed25519Key?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.Sr25519:\n        innerDisplay = this._sr25519Key?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87:\n        innerDisplay = this._mldsaKey?.toString() ?? String(this._type);\n        break;\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384:\n        innerDisplay = this._sshKey?.toString() ?? `SSHPrivateKey(${refShort})`;\n        break;\n    }\n    return `SigningPrivateKey(${refShort}, ${innerDisplay})`;\n  }\n\n  // ============================================================================\n  // ReferenceProvider Interface\n  // ============================================================================\n\n  /**\n   * Returns a unique reference to this SigningPrivateKey instance.\n   *\n   * The reference is derived from the SHA-256 hash of the tagged CBOR\n   * representation, providing a unique, content-addressable identifier.\n   */\n  reference(): Reference {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return Reference.from(digest);\n  }\n\n  // ============================================================================\n  // Signer Interface\n  // ============================================================================\n\n  /**\n   * Signs a message with optional signing options.\n   *\n   * Different signature schemes may use the options differently:\n   * - Schnorr: Can accept a custom random number generator via SigningOptions.Schnorr\n   * - SSH: Would require namespace and hash algorithm (not yet implemented)\n   * - Other schemes (ECDSA, Ed25519, Sr25519, MLDSA): Options are ignored\n   *\n   * @param message - The message to sign\n   * @param options - Optional signing options\n   * @returns The digital signature\n   */\n  signWithOptions(message: Uint8Array, options?: SigningOptions): Signature {\n    switch (this._type) {\n      case SignatureScheme.Schnorr: {\n        if (this._ecKey === undefined) {\n          throw new Error(\"EC private key is missing\");\n        }\n        // If Schnorr options with custom RNG are provided, use them\n        if (options?.type === \"Schnorr\") {\n          const sigData = this._ecKey.schnorrSignUsing(message, options.rng);\n          return Signature.schnorrFromData(sigData);\n        }\n        // Otherwise use default RNG\n        const sigData = this._ecKey.schnorrSign(message);\n        return Signature.schnorrFromData(sigData);\n      }\n      case SignatureScheme.Ecdsa: {\n        if (this._ecKey === undefined) {\n          throw new Error(\"EC private key is missing\");\n        }\n        const sigData = this._ecKey.ecdsaSign(message);\n        return Signature.ecdsaFromData(sigData);\n      }\n      case SignatureScheme.Ed25519: {\n        if (this._ed25519Key === undefined) {\n          throw new Error(\"Ed25519 private key is missing\");\n        }\n        const sigData = this._ed25519Key.sign(message);\n        return Signature.ed25519FromData(sigData);\n      }\n      case SignatureScheme.Sr25519: {\n        if (this._sr25519Key === undefined) {\n          throw new Error(\"Sr25519 private key is missing\");\n        }\n        const sigData = this._sr25519Key.sign(message);\n        return Signature.sr25519FromData(sigData);\n      }\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87: {\n        if (this._mldsaKey === undefined) {\n          throw new Error(\"MLDSA private key is missing\");\n        }\n        const mldsaSig = this._mldsaKey.sign(message);\n        return Signature.mldsaFromSignature(mldsaSig);\n      }\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined) {\n          throw new Error(\"SSH private key is missing\");\n        }\n        if (options?.type !== \"Ssh\") {\n          // Mirror Rust error message verbatim\n          // (`signing_private_key.rs:796`).\n          throw new Error(\"Missing namespace and hash algorithm for SSH signing\");\n        }\n        const sshSig = this._sshKey.sign(options.namespace, options.hashAlg, message);\n        return Signature.fromSsh(sshSig);\n      }\n    }\n  }\n\n  /**\n   * Signs a message using default options.\n   *\n   * This is a convenience method that calls `signWithOptions` with no options.\n   *\n   * @param message - The message to sign\n   * @returns The digital signature\n   */\n  sign(message: Uint8Array): Signature {\n    return this.signWithOptions(message);\n  }\n\n  // ============================================================================\n  // Verifier Interface (Schnorr-only — matches Rust)\n  // ============================================================================\n\n  /**\n   * Verifies a signature against a message using the derived public key.\n   *\n   * Mirrors Rust's `Verifier for SigningPrivateKey`: only Schnorr keys\n   * actually verify; every other scheme returns `false`. Callers needing\n   * verification for Ed25519 / ECDSA / Sr25519 / MLDSA should derive the\n   * public key first via `publicKey().verify(...)`.\n   *\n   * @param signature - The signature to verify\n   * @param message - The message that was allegedly signed\n   * @returns `true` if the signature is a valid Schnorr signature\n   */\n  verify(signature: Signature, message: Uint8Array): boolean {\n    if (this._type !== SignatureScheme.Schnorr || this._ecKey === undefined) {\n      return false;\n    }\n    const sigData = signature.toSchnorr();\n    if (sigData === null) {\n      return false;\n    }\n    return this._ecKey.schnorrPublicKey().schnorrVerify(sigData, message);\n  }\n\n  // ============================================================================\n  // Scheme-Specific Sign Methods\n  // ============================================================================\n\n  /**\n   * Signs a message using Schnorr with the provided random number generator.\n   *\n   * This method is only valid for Schnorr keys.\n   *\n   * @param message - The message to sign\n   * @param rng - The random number generator to use for signature creation\n   * @returns The Schnorr signature\n   * @throws Error if this is not a Schnorr key\n   */\n  schnorrSign(message: Uint8Array, rng: RandomNumberGenerator): Signature {\n    const privateKey = this.toSchnorr();\n    if (privateKey === null) {\n      throw new Error(\"Invalid key type for Schnorr signing\");\n    }\n    const sigData = privateKey.schnorrSignUsing(message, rng);\n    return Signature.schnorrFromData(sigData);\n  }\n\n  /**\n   * Signs a message using ECDSA.\n   *\n   * This method is only valid for ECDSA keys.\n   *\n   * @param message - The message to sign\n   * @returns The ECDSA signature\n   * @throws Error if this is not an ECDSA key\n   */\n  ecdsaSign(message: Uint8Array): Signature {\n    const privateKey = this.toEcdsa();\n    if (privateKey === null) {\n      throw new Error(\"Invalid key type for ECDSA signing\");\n    }\n    const sigData = privateKey.ecdsaSign(message);\n    return Signature.ecdsaFromData(sigData);\n  }\n\n  /**\n   * Signs a message using Ed25519.\n   *\n   * This method is only valid for Ed25519 keys.\n   *\n   * @param message - The message to sign\n   * @returns The Ed25519 signature\n   * @throws Error if this is not an Ed25519 key\n   */\n  ed25519Sign(message: Uint8Array): Signature {\n    const privateKey = this.toEd25519();\n    if (privateKey === null) {\n      throw new Error(\"Invalid key type for Ed25519 signing\");\n    }\n    const sigData = privateKey.sign(message);\n    return Signature.ed25519FromData(sigData);\n  }\n\n  /**\n   * Signs a message using SR25519.\n   *\n   * This method is only valid for SR25519 keys.\n   *\n   * @param message - The message to sign\n   * @returns The SR25519 signature\n   * @throws Error if this is not an SR25519 key\n   */\n  sr25519Sign(message: Uint8Array): Signature {\n    const privateKey = this.toSr25519();\n    if (privateKey === null) {\n      throw new Error(\"Invalid key type for SR25519 signing\");\n    }\n    const sigData = privateKey.sign(message);\n    return Signature.sr25519FromData(sigData);\n  }\n\n  /**\n   * Signs a message using ML-DSA.\n   *\n   * This method is only valid for MLDSA keys.\n   *\n   * @param message - The message to sign\n   * @returns The ML-DSA signature\n   * @throws Error if this is not an MLDSA key\n   */\n  mldsaSign(message: Uint8Array): Signature {\n    const privateKey = this.toMldsa();\n    if (privateKey === null) {\n      throw new Error(\"Invalid key type for MLDSA signing\");\n    }\n    const mldsaSig = privateKey.sign(message);\n    return Signature.mldsaFromSignature(mldsaSig);\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with SigningPrivateKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SIGNING_PRIVATE_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format (matching Rust bc-components):\n   * - Schnorr: h'<32-byte-private-key>' (bare byte string)\n   * - ECDSA:   [1, h'<32-byte-private-key>']\n   * - Ed25519: [2, h'<32-byte-private-key>']\n   * - Sr25519: [3, h'<32-byte-seed>']\n   * - MLDSA:   delegates to MLDSAPrivateKey (tagged)\n   */\n  untaggedCbor(): Cbor {\n    switch (this._type) {\n      case SignatureScheme.Schnorr: {\n        if (this._ecKey === undefined) {\n          throw new Error(\"EC private key is missing\");\n        }\n        // Rust: CBOR::to_byte_string(key.data()) - bare byte string\n        return toByteString(this._ecKey.toData());\n      }\n      case SignatureScheme.Ecdsa: {\n        if (this._ecKey === undefined) {\n          throw new Error(\"EC private key is missing\");\n        }\n        return cbor([1, toByteString(this._ecKey.toData())]);\n      }\n      case SignatureScheme.Ed25519: {\n        if (this._ed25519Key === undefined) {\n          throw new Error(\"Ed25519 private key is missing\");\n        }\n        return cbor([2, toByteString(this._ed25519Key.toData())]);\n      }\n      case SignatureScheme.Sr25519: {\n        if (this._sr25519Key === undefined) {\n          throw new Error(\"Sr25519 private key is missing\");\n        }\n        return cbor([3, toByteString(this._sr25519Key.toData())]);\n      }\n      case SignatureScheme.MLDSA44:\n      case SignatureScheme.MLDSA65:\n      case SignatureScheme.MLDSA87: {\n        if (this._mldsaKey === undefined) {\n          throw new Error(\"MLDSA private key is missing\");\n        }\n        // Rust: delegates to MLDSAPrivateKey (which produces tagged CBOR)\n        return this._mldsaKey.taggedCbor();\n      }\n      case SignatureScheme.SshEd25519:\n      case SignatureScheme.SshDsa:\n      case SignatureScheme.SshEcdsaP256:\n      case SignatureScheme.SshEcdsaP384: {\n        if (this._sshKey === undefined) {\n          throw new Error(\"SSH private key is missing\");\n        }\n        // Mirror Rust `SigningPrivateKey::SSH` untagged CBOR encoding:\n        // `CBOR::to_tagged_value(TAG_SSH_TEXT_PRIVATE_KEY, key.to_openssh())`.\n        return toTaggedValue(TAG_SSH_TEXT_PRIVATE_KEY, this._sshKey.toOpenssh());\n      }\n    }\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 SigningPrivateKey by decoding it from untagged CBOR.\n   *\n   * Format (matching Rust bc-components):\n   * - h'<32-byte-key>' (bare byte string) for Schnorr\n   * - [1, h'<32-byte-key>'] for ECDSA\n   * - [2, h'<32-byte-key>'] for Ed25519\n   * - [3, h'<32-byte-seed>'] for Sr25519\n   * - tagged MLDSA private key for MLDSA variants\n   */\n  fromUntaggedCbor(cborValue: Cbor): SigningPrivateKey {\n    // Rust format: Schnorr is a bare byte string\n    if (isBytes(cborValue)) {\n      const keyData = expectBytes(cborValue);\n      return SigningPrivateKey.newSchnorr(ECPrivateKey.from(keyData));\n    }\n\n    // Array format for ECDSA, Ed25519, Sr25519\n    if (isArray(cborValue)) {\n      const elements = expectArray(cborValue);\n\n      if (elements.length !== 2) {\n        throw new Error(\"SigningPrivateKey array must have 2 elements\");\n      }\n\n      const discriminator = expectUnsigned(elements[0]);\n      const keyData = expectBytes(elements[1]);\n\n      switch (Number(discriminator)) {\n        case 1: // ECDSA\n          return SigningPrivateKey.newEcdsa(ECPrivateKey.from(keyData));\n        case 2: // Ed25519\n          return SigningPrivateKey.newEd25519(Ed25519PrivateKey.from(keyData));\n        case 3: // Sr25519\n          return SigningPrivateKey.newSr25519(Sr25519PrivateKey.from(keyData));\n        default:\n          throw new Error(`Unknown SigningPrivateKey discriminator: ${discriminator}`);\n      }\n    }\n\n    // Tagged format for MLDSA / SSH\n    if (isTagged(cborValue)) {\n      const tagged = cborValue.asTagged();\n      if (tagged?.[0].value === TAG_MLDSA_PRIVATE_KEY.value) {\n        const mldsaKey = MLDSAPrivateKey.fromTaggedCbor(cborValue);\n        return SigningPrivateKey.newMldsa(mldsaKey);\n      }\n      if (tagged?.[0].value === TAG_SSH_TEXT_PRIVATE_KEY.value) {\n        const text = expectText(tagged[1]);\n        const sshKey = SSHPrivateKey.fromOpenssh(text);\n        return SigningPrivateKey.fromSsh(sshKey);\n      }\n    }\n\n    throw new Error(\n      \"SigningPrivateKey must be a byte string (Schnorr), array (ECDSA/Ed25519/Sr25519), tagged MLDSA, or tagged SSH\",\n    );\n  }\n\n  /**\n   * Creates a SigningPrivateKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): SigningPrivateKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): SigningPrivateKey {\n    // Create a dummy instance for accessing instance methods\n    const dummy = new SigningPrivateKey(\n      SignatureScheme.Ed25519,\n      undefined, // ecKey\n      Ed25519PrivateKey.from(new Uint8Array(ED25519_PRIVATE_KEY_SIZE)), // ed25519Key\n    );\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): SigningPrivateKey {\n    const cborValue = decodeCbor(data);\n    return SigningPrivateKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): SigningPrivateKey {\n    const cborValue = decodeCbor(data);\n    return SigningPrivateKey.fromUntaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR.\n   */\n  static fromUntaggedCbor(cborValue: Cbor): SigningPrivateKey {\n    const dummy = new SigningPrivateKey(\n      SignatureScheme.Ed25519,\n      undefined, // ecKey\n      Ed25519PrivateKey.from(new Uint8Array(ED25519_PRIVATE_KEY_SIZE)), // ed25519Key\n    );\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR (Uniform Resource) Serialization\n  // ============================================================================\n\n  /**\n   * Get the UR type for signing private keys.\n   */\n  static readonly UR_TYPE = \"signing-private-key\";\n\n  /**\n   * Returns the UR representation of the signing private key.\n   */\n  ur(): UR {\n    // A UR's content is the *untagged* CBOR; the `signing-private-key` type\n    // string already implies the tag. Using `taggedCbor()` here would\n    // double-tag the content, diverging from Rust and breaking interop.\n    // Mirrors the canonical `toUR` pattern (`ur-encodable.ts`).\n    return UR.new(SigningPrivateKey.UR_TYPE, this.untaggedCbor());\n  }\n\n  /**\n   * Returns the UR string representation of the signing private key.\n   */\n  urString(): string {\n    return this.ur().string();\n  }\n\n  /**\n   * Creates a SigningPrivateKey from a UR.\n   */\n  static fromUR(ur: UR): SigningPrivateKey {\n    ur.checkType(SigningPrivateKey.UR_TYPE);\n    // The UR content is untagged (the type implies the tag), so decode it\n    // directly as untagged CBOR. Mirrors the canonical `fromUR` pattern\n    // (`ur-decodable.ts`).\n    return SigningPrivateKey.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a SigningPrivateKey from a UR string.\n   */\n  static fromURString(urString: string): SigningPrivateKey {\n    const ur = UR.fromURString(urString);\n    return SigningPrivateKey.fromUR(ur);\n  }\n\n  /**\n   * Alias for fromURString for Rust API compatibility.\n   */\n  static fromUrString(urString: string): SigningPrivateKey {\n    return SigningPrivateKey.fromURString(urString);\n  }\n\n  // ============================================================================\n  // SSH Format\n  // ============================================================================\n\n  /**\n   * Returns the canonical OpenSSH armored PEM for an SSH private key.\n   *\n   * Only valid when this `SigningPrivateKey` wraps an `SSHPrivateKey`\n   * (i.e. one of the four `SignatureScheme.SshXxx` variants). Mirrors\n   * Rust's `SigningPrivateKey::SSH(key) => key.to_openssh(LineEnding::LF)`\n   * usage at `signing_private_key.rs:896`.\n   */\n  toSshOpenssh(): string {\n    if (this._sshKey === undefined) {\n      throw new Error(`SigningPrivateKey is not an SSH key (scheme: ${this._type})`);\n    }\n    return this._sshKey.toOpenssh();\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * PublicKeys - Container for signing and encapsulation public keys\n *\n * PublicKeys combines a SigningPublicKey (for signature verification) and an\n * EncapsulationPublicKey (for key agreement/encryption) into a single unit.\n *\n * This is the public counterpart to PrivateKeys.\n *\n * # CBOR Serialization\n *\n * PublicKeys is serialized with tag 40017:\n * ```\n * #6.40017([<SigningPublicKey>, <EncapsulationPublicKey>])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `crypto-pubkeys`\n *\n * Ported from bc-components-rust/src/public_keys.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { PUBLIC_KEYS as TAG_PUBLIC_KEYS } from \"@bcts/tags\";\n\nimport { SigningPublicKey } from \"./signing/signing-public-key.js\";\nimport { EncapsulationPublicKey } from \"./encapsulation/encapsulation-public-key.js\";\nimport type { EncapsulationCiphertext } from \"./encapsulation/encapsulation-ciphertext.js\";\nimport type { SymmetricKey } from \"./symmetric/symmetric-key.js\";\nimport type { Signature } from \"./signing/signature.js\";\nimport type { Verifier } from \"./signing/signer.js\";\nimport type { Encrypter } from \"./encrypter.js\";\nimport { Reference, type ReferenceProvider } from \"./reference.js\";\nimport { Digest } from \"./digest.js\";\n\n/**\n * Trait for types that provide access to a PublicKeys container.\n *\n * This is useful for types that wrap or contain public keys and need\n * to provide access to the underlying key material.\n */\nexport interface PublicKeysProvider {\n  /**\n   * Returns the PublicKeys container.\n   */\n  publicKeys(): PublicKeys;\n}\n\n/**\n * PublicKeys - Container for a signing public key and an encapsulation public key.\n *\n * This type provides a convenient way to share public keys for both\n * signature verification and encryption operations.\n */\nexport class PublicKeys\n  implements\n    Verifier,\n    Encrypter,\n    ReferenceProvider,\n    CborTaggedEncodable,\n    CborTaggedDecodable<PublicKeys>,\n    UREncodable\n{\n  private readonly _signingPublicKey: SigningPublicKey;\n  private readonly _encapsulationPublicKey: EncapsulationPublicKey;\n\n  private constructor(\n    signingPublicKey: SigningPublicKey,\n    encapsulationPublicKey: EncapsulationPublicKey,\n  ) {\n    this._signingPublicKey = signingPublicKey;\n    this._encapsulationPublicKey = encapsulationPublicKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new PublicKeys container with the given keys.\n   */\n  static new(\n    signingPublicKey: SigningPublicKey,\n    encapsulationPublicKey: EncapsulationPublicKey,\n  ): PublicKeys {\n    return new PublicKeys(signingPublicKey, encapsulationPublicKey);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the signing public key.\n   */\n  signingPublicKey(): SigningPublicKey {\n    return this._signingPublicKey;\n  }\n\n  /**\n   * Returns the encapsulation public key.\n   *\n   * Note: Named to match Rust's API (which has a typo but we maintain compatibility)\n   */\n  encapsulationPublicKey(): EncapsulationPublicKey {\n    return this._encapsulationPublicKey;\n  }\n\n  // ============================================================================\n  // Verifier Interface\n  // ============================================================================\n\n  /**\n   * Verify a signature against a message.\n   */\n  verify(signature: Signature, message: Uint8Array): boolean {\n    return this._signingPublicKey.verify(signature, message);\n  }\n\n  // ============================================================================\n  // Encrypter Interface\n  // ============================================================================\n\n  /**\n   * Encapsulate a new shared secret using the encapsulation public key.\n   *\n   * This implements the Encrypter interface, allowing PublicKeys to be used\n   * in encryption contexts where a shared secret needs to be generated.\n   *\n   * @returns A tuple of [SymmetricKey, EncapsulationCiphertext]\n   */\n  encapsulateNewSharedSecret(): [SymmetricKey, EncapsulationCiphertext] {\n    return this._encapsulationPublicKey.encapsulateNewSharedSecret();\n  }\n\n  // ============================================================================\n  // ReferenceProvider Interface\n  // ============================================================================\n\n  /**\n   * Returns a unique reference to this PublicKeys instance.\n   *\n   * The reference is derived from the SHA-256 hash of the tagged CBOR\n   * representation, providing a unique, content-addressable identifier.\n   */\n  reference(): Reference {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return Reference.from(digest);\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another PublicKeys.\n   */\n  equals(other: PublicKeys): boolean {\n    return (\n      this._signingPublicKey.equals(other._signingPublicKey) &&\n      this._encapsulationPublicKey.equals(other._encapsulationPublicKey)\n    );\n  }\n\n  /**\n   * Get string representation.\n   *\n   * Mirrors Rust `Display for PublicKeys`\n   * (`bc-components-rust/src/public_keys.rs:216-225`):\n   *   `PublicKeys(<short_reference>, <signing_public_key>, <encapsulation_public_key>)`\n   *\n   * The earlier short form (`PublicKeys(<short_reference>)`) was\n   * observable in envelope notation as a missing key fingerprint\n   * trail in the GSTP `'sender': XID(...) [ 'key': PublicKeys(...) ]`\n   * format-pin (G1 in `PARITY_OUTSTANDING.md`).\n   */\n  toString(): string {\n    return `PublicKeys(${this.reference().shortReference(\n      \"hex\",\n    )}, ${this._signingPublicKey.toString()}, ${this._encapsulationPublicKey.toString()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with PublicKeys.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_PUBLIC_KEYS.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [<SigningPublicKey>, <EncapsulationPublicKey>]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._signingPublicKey.taggedCbor(), this._encapsulationPublicKey.taggedCbor()]);\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 PublicKeys by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): PublicKeys {\n    const elements = expectArray(cborValue);\n\n    if (elements.length !== 2) {\n      throw new Error(`PublicKeys must have 2 elements, got ${elements.length}`);\n    }\n\n    const signingPublicKey = SigningPublicKey.fromTaggedCbor(elements[0]);\n    const encapsulationPublicKey = EncapsulationPublicKey.fromTaggedCbor(elements[1]);\n\n    return new PublicKeys(signingPublicKey, encapsulationPublicKey);\n  }\n\n  /**\n   * Creates a PublicKeys by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): PublicKeys {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): PublicKeys {\n    // We need a dummy instance to call instance methods\n    // Create minimal valid keys for this purpose\n    const signingKeyPrefix = new Uint8Array([0x82, 0x02, 0x58, 0x20]);\n    const signingKeyData = new Uint8Array(36);\n    signingKeyData.set(signingKeyPrefix, 0);\n    const signingKey = SigningPublicKey.fromUntaggedCborData(signingKeyData);\n\n    const encapsulationKeyPrefix = new Uint8Array([0x58, 0x20]);\n    const encapsulationKeyData = new Uint8Array(34);\n    encapsulationKeyData.set(encapsulationKeyPrefix, 0);\n    const encapsulationKey = EncapsulationPublicKey.fromUntaggedCborData(encapsulationKeyData);\n\n    const dummy = new PublicKeys(signingKey, encapsulationKey);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): PublicKeys {\n    const cborValue = decodeCbor(data);\n    return PublicKeys.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): PublicKeys {\n    const cborValue = decodeCbor(data);\n    // We need a dummy instance to call instance methods\n    const signingKeyPrefix = new Uint8Array([0x82, 0x02, 0x58, 0x20]);\n    const signingKeyData = new Uint8Array(36);\n    signingKeyData.set(signingKeyPrefix, 0);\n    const signingKey = SigningPublicKey.fromUntaggedCborData(signingKeyData);\n\n    const encapsulationKeyPrefix = new Uint8Array([0x58, 0x20]);\n    const encapsulationKeyData = new Uint8Array(34);\n    encapsulationKeyData.set(encapsulationKeyPrefix, 0);\n    const encapsulationKey = EncapsulationPublicKey.fromUntaggedCborData(encapsulationKeyData);\n\n    const dummy = new PublicKeys(signingKey, encapsulationKey);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_PUBLIC_KEYS.name;\n    if (name === undefined) {\n      throw new Error(\"PUBLIC_KEYS tag name is undefined\");\n    }\n    return UR.new(name, 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 PublicKeys from a UR.\n   */\n  static fromUR(ur: UR): PublicKeys {\n    if (ur.urTypeStr() !== TAG_PUBLIC_KEYS.name) {\n      throw new Error(`Expected UR type ${TAG_PUBLIC_KEYS.name}, got ${ur.urTypeStr()}`);\n    }\n    // We need a dummy instance to call instance methods\n    const signingKeyPrefix = new Uint8Array([0x82, 0x02, 0x58, 0x20]);\n    const signingKeyData = new Uint8Array(36);\n    signingKeyData.set(signingKeyPrefix, 0);\n    const signingKey = SigningPublicKey.fromUntaggedCborData(signingKeyData);\n\n    const encapsulationKeyPrefix = new Uint8Array([0x58, 0x20]);\n    const encapsulationKeyData = new Uint8Array(34);\n    encapsulationKeyData.set(encapsulationKeyPrefix, 0);\n    const encapsulationKey = EncapsulationPublicKey.fromUntaggedCborData(encapsulationKeyData);\n\n    const dummy = new PublicKeys(signingKey, encapsulationKey);\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a PublicKeys from a UR string.\n   */\n  static fromURString(urString: string): PublicKeys {\n    const ur = UR.fromURString(urString);\n    return PublicKeys.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * PrivateKeys - Container for signing and encapsulation private keys\n *\n * PrivateKeys combines a SigningPrivateKey (for digital signatures) and an\n * EncapsulationPrivateKey (for key agreement/encryption) into a single unit.\n *\n * # CBOR Serialization\n *\n * PrivateKeys is serialized with tag 40013:\n * ```\n * #6.40013([<SigningPrivateKey>, <EncapsulationPrivateKey>])\n * ```\n *\n * # UR Serialization\n *\n * UR type: `crypto-prvkeys`\n *\n * Ported from bc-components-rust/src/private_keys.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { PRIVATE_KEYS as TAG_PRIVATE_KEYS } from \"@bcts/tags\";\n\nimport { SigningPrivateKey } from \"./signing/signing-private-key.js\";\nimport { EncapsulationPrivateKey } from \"./encapsulation/encapsulation-private-key.js\";\nimport { PublicKeys } from \"./public-keys.js\";\nimport type { SymmetricKey } from \"./symmetric/symmetric-key.js\";\nimport type { EncapsulationCiphertext } from \"./encapsulation/encapsulation-ciphertext.js\";\nimport type { Signature } from \"./signing/signature.js\";\nimport type { Signer } from \"./signing/signer.js\";\nimport type { SigningOptions } from \"./signing/signature-scheme.js\";\nimport type { Decrypter } from \"./encrypter.js\";\nimport { Reference, type ReferenceProvider } from \"./reference.js\";\nimport { Digest } from \"./digest.js\";\n\n/**\n * Trait for types that provide access to a PrivateKeys container.\n *\n * This is useful for types that wrap or contain private keys and need\n * to provide access to the underlying key material.\n */\nexport interface PrivateKeysProvider {\n  /**\n   * Returns the PrivateKeys container.\n   */\n  privateKeys(): PrivateKeys;\n}\n\n/**\n * PrivateKeys - Container for a signing key and an encapsulation key.\n *\n * This type provides a convenient way to manage a pair of private keys\n * for both signing and encryption operations.\n */\nexport class PrivateKeys\n  implements\n    Signer,\n    Decrypter,\n    ReferenceProvider,\n    CborTaggedEncodable,\n    CborTaggedDecodable<PrivateKeys>,\n    UREncodable\n{\n  private readonly _signingPrivateKey: SigningPrivateKey;\n  private readonly _encapsulationPrivateKey: EncapsulationPrivateKey;\n\n  private constructor(\n    signingPrivateKey: SigningPrivateKey,\n    encapsulationPrivateKey: EncapsulationPrivateKey,\n  ) {\n    this._signingPrivateKey = signingPrivateKey;\n    this._encapsulationPrivateKey = encapsulationPrivateKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a new PrivateKeys container with the given keys.\n   */\n  static withKeys(\n    signingPrivateKey: SigningPrivateKey,\n    encapsulationPrivateKey: EncapsulationPrivateKey,\n  ): PrivateKeys {\n    return new PrivateKeys(signingPrivateKey, encapsulationPrivateKey);\n  }\n\n  /**\n   * Create a new PrivateKeys container with random Ed25519/X25519 keys.\n   */\n  static new(): PrivateKeys {\n    const signingKey = SigningPrivateKey.random();\n    const encapsulationKey = EncapsulationPrivateKey.random();\n    return new PrivateKeys(signingKey, encapsulationKey);\n  }\n\n  /**\n   * Generate a new PrivateKeys container with random Ed25519/X25519 keys.\n   * This is an alias for new() for API compatibility.\n   */\n  static generate(): PrivateKeys {\n    return PrivateKeys.new();\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the signing private key.\n   */\n  signingPrivateKey(): SigningPrivateKey {\n    return this._signingPrivateKey;\n  }\n\n  /**\n   * Returns the encapsulation private key.\n   *\n   * Note: Named to match Rust's API (which has a typo but we maintain compatibility)\n   */\n  encapsulationPrivateKey(): EncapsulationPrivateKey {\n    return this._encapsulationPrivateKey;\n  }\n\n  /**\n   * Derive the corresponding public keys.\n   */\n  publicKeys(): PublicKeys {\n    const signingPublicKey = this._signingPrivateKey.publicKey();\n    const encapsulationPublicKey = this._encapsulationPrivateKey.publicKey();\n    return PublicKeys.new(signingPublicKey, encapsulationPublicKey);\n  }\n\n  // ============================================================================\n  // Signer Interface\n  // ============================================================================\n\n  /**\n   * Sign a message with optional signing options using the signing private key.\n   */\n  signWithOptions(message: Uint8Array, options?: SigningOptions): Signature {\n    return this._signingPrivateKey.signWithOptions(message, options);\n  }\n\n  /**\n   * Sign a message using the signing private key.\n   */\n  sign(message: Uint8Array): Signature {\n    return this._signingPrivateKey.sign(message);\n  }\n\n  // ============================================================================\n  // Decrypter Interface\n  // ============================================================================\n\n  /**\n   * Decapsulate a shared secret from a ciphertext.\n   *\n   * This implements the Decrypter interface, allowing PrivateKeys to be used\n   * in encryption contexts where a shared secret needs to be recovered.\n   */\n  decapsulateSharedSecret(ciphertext: EncapsulationCiphertext): SymmetricKey {\n    return this._encapsulationPrivateKey.decapsulateSharedSecret(ciphertext);\n  }\n\n  // ============================================================================\n  // ReferenceProvider Interface\n  // ============================================================================\n\n  /**\n   * Returns a unique reference to this PrivateKeys instance.\n   *\n   * The reference is derived from the SHA-256 hash of the tagged CBOR\n   * representation, providing a unique, content-addressable identifier.\n   */\n  reference(): Reference {\n    const digest = Digest.fromImage(this.taggedCborData());\n    return Reference.from(digest);\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another PrivateKeys.\n   */\n  equals(other: PrivateKeys): boolean {\n    return (\n      this._signingPrivateKey.equals(other._signingPrivateKey) &&\n      this._encapsulationPrivateKey.equals(other._encapsulationPrivateKey)\n    );\n  }\n\n  /**\n   * Mirror of Rust `Display for PrivateKeys`\n   * (`bc-components-rust/src/private_keys.rs:229-238`):\n   *   `PrivateKeys(<refHexShort>, <signingPrivateKey>, <encapsulationPrivateKey>)`\n   * The previous abbreviated form (`PrivateKeys(<short>)` only) was a\n   * parity drift caught by the E1a summarizer audit.\n   */\n  toString(): string {\n    return `PrivateKeys(${this.reference().shortReference(\n      \"hex\",\n    )}, ${this._signingPrivateKey.toString()}, ${this._encapsulationPrivateKey.toString()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with PrivateKeys.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_PRIVATE_KEYS.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   *\n   * Format: [<SigningPrivateKey>, <EncapsulationPrivateKey>]\n   */\n  untaggedCbor(): Cbor {\n    return cbor([this._signingPrivateKey.taggedCbor(), this._encapsulationPrivateKey.taggedCbor()]);\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 PrivateKeys by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): PrivateKeys {\n    const elements = expectArray(cborValue);\n\n    if (elements.length !== 2) {\n      throw new Error(`PrivateKeys must have 2 elements, got ${elements.length}`);\n    }\n\n    const signingPrivateKey = SigningPrivateKey.fromTaggedCbor(elements[0]);\n    const encapsulationPrivateKey = EncapsulationPrivateKey.fromTaggedCbor(elements[1]);\n\n    return new PrivateKeys(signingPrivateKey, encapsulationPrivateKey);\n  }\n\n  /**\n   * Creates a PrivateKeys by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): PrivateKeys {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): PrivateKeys {\n    // Create a dummy instance for accessing instance methods\n    const dummy = PrivateKeys.new();\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): PrivateKeys {\n    const cborValue = decodeCbor(data);\n    return PrivateKeys.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): PrivateKeys {\n    const cborValue = decodeCbor(data);\n    const dummy = PrivateKeys.new();\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_PRIVATE_KEYS.name;\n    if (name === undefined) {\n      throw new Error(\"PRIVATE_KEYS tag name is undefined\");\n    }\n    return UR.new(name, 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 PrivateKeys from a UR.\n   */\n  static fromUR(ur: UR): PrivateKeys {\n    if (ur.urTypeStr() !== TAG_PRIVATE_KEYS.name) {\n      throw new Error(`Expected UR type ${TAG_PRIVATE_KEYS.name}, got ${ur.urTypeStr()}`);\n    }\n    const dummy = PrivateKeys.new();\n    return dummy.fromUntaggedCbor(ur.cbor());\n  }\n\n  /**\n   * Creates a PrivateKeys from a UR string.\n   */\n  static fromURString(urString: string): PrivateKeys {\n    const ur = UR.fromURString(urString);\n    return PrivateKeys.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Top-level keypair helpers — produce a `(PrivateKeys, PublicKeys)` bundle\n * spanning both signing and encapsulation schemes in one call.\n *\n * Ported from bc-components-rust/src/keypair.rs\n */\n\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { PrivateKeys } from \"./private-keys.js\";\nimport { PublicKeys } from \"./public-keys.js\";\nimport {\n  defaultSignatureScheme,\n  createKeypair as createSigningKeypair,\n  createKeypairUsing as createSigningKeypairUsing,\n} from \"./signing/signature-scheme.js\";\nimport type { SignatureScheme } from \"./signing/signature-scheme.js\";\nimport {\n  defaultEncapsulationScheme,\n  createEncapsulationKeypair,\n  createEncapsulationKeypairUsing,\n} from \"./encapsulation/encapsulation-scheme.js\";\nimport type { EncapsulationScheme } from \"./encapsulation/encapsulation-scheme.js\";\n\n/**\n * Generates a key pair using the default signature and encapsulation schemes\n * (Schnorr + X25519).\n *\n * Mirrors Rust `pub fn keypair() -> (PrivateKeys, PublicKeys)`.\n */\nexport function keypair(): [PrivateKeys, PublicKeys] {\n  return keypairOpt(defaultSignatureScheme(), defaultEncapsulationScheme());\n}\n\n/**\n * Generates a key pair using the default schemes and a provided RNG.\n *\n * Mirrors Rust `pub fn keypair_using(rng) -> Result<(PrivateKeys, PublicKeys)>`.\n *\n * Note: ML-KEM does not support deterministic generation. This helper uses\n * the default encapsulation scheme (X25519), which does.\n */\nexport function keypairUsing(rng: RandomNumberGenerator): [PrivateKeys, PublicKeys] {\n  return keypairOptUsing(defaultSignatureScheme(), defaultEncapsulationScheme(), rng);\n}\n\n/**\n * Generates a key pair with explicit signature and encapsulation schemes.\n *\n * Mirrors Rust `pub fn keypair_opt(sig, enc) -> (PrivateKeys, PublicKeys)`.\n */\nexport function keypairOpt(\n  signatureScheme: SignatureScheme,\n  encapsulationScheme: EncapsulationScheme,\n): [PrivateKeys, PublicKeys] {\n  const [signingPrivateKey, signingPublicKey] = createSigningKeypair(signatureScheme);\n  const [encapsulationPrivateKey, encapsulationPublicKey] =\n    createEncapsulationKeypair(encapsulationScheme);\n  const privateKeys = PrivateKeys.withKeys(signingPrivateKey, encapsulationPrivateKey);\n  const publicKeys = PublicKeys.new(signingPublicKey, encapsulationPublicKey);\n  return [privateKeys, publicKeys];\n}\n\n/**\n * Generates a key pair with explicit schemes and a provided RNG.\n *\n * Mirrors Rust `pub fn keypair_opt_using(sig, enc, rng) ->\n *   Result<(PrivateKeys, PublicKeys)>`.\n *\n * Throws if either scheme does not support deterministic generation\n * (e.g. ML-DSA / ML-KEM, or any SSH-based signing scheme).\n */\nexport function keypairOptUsing(\n  signatureScheme: SignatureScheme,\n  encapsulationScheme: EncapsulationScheme,\n  rng: RandomNumberGenerator,\n): [PrivateKeys, PublicKeys] {\n  const [signingPrivateKey, signingPublicKey] = createSigningKeypairUsing(signatureScheme, rng);\n  const [encapsulationPrivateKey, encapsulationPublicKey] = createEncapsulationKeypairUsing(\n    rng,\n    encapsulationScheme,\n  );\n  const privateKeys = PrivateKeys.withKeys(signingPrivateKey, encapsulationPrivateKey);\n  const publicKeys = PublicKeys.new(signingPublicKey, encapsulationPublicKey);\n  return [privateKeys, publicKeys];\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Base traits for elliptic curve keys\n *\n * This module defines the base interfaces for all elliptic curve keys,\n * matching the Rust trait hierarchy:\n * - `ECKeyBase` - Base trait for all EC keys (data, hex, fromHex, fromDataRef)\n * - `ECKey` - Keys that can derive a public key (publicKey)\n * - `ECPublicKeyBase` - Public keys that can provide uncompressed form\n *\n * Ported from bc-components-rust/src/ec_key/ec_key_base.rs\n * and bc-components-rust/src/ec_key/ec_public_key_base.rs\n */\n\nimport type { ECPublicKey } from \"./ec-public-key.js\";\nimport type { ECUncompressedPublicKey } from \"./ec-uncompressed-public-key.js\";\n\n/**\n * A base interface for all elliptic curve keys.\n *\n * This interface defines common functionality for all elliptic curve keys,\n * including both private and public keys. It provides methods for key\n * construction from binary data and hexadecimal strings, as well as conversion\n * to hexadecimal format.\n *\n * All EC key types have a fixed size depending on their specific type:\n * - EC private keys: 32 bytes\n * - EC compressed public keys: 33 bytes\n * - EC uncompressed public keys: 65 bytes\n * - Schnorr public keys: 32 bytes\n */\nexport interface ECKeyBase {\n  /**\n   * Returns the key's binary data.\n   */\n  data(): Uint8Array;\n\n  /**\n   * Returns the key as a hexadecimal string.\n   */\n  hex(): string;\n}\n\n/**\n * Type guard to check if an object implements ECKeyBase.\n */\nexport function isECKeyBase(obj: unknown): obj is ECKeyBase {\n  if (obj === null || typeof obj !== \"object\") return false;\n  const candidate = obj as ECKeyBase;\n  return typeof candidate.data === \"function\" && typeof candidate.hex === \"function\";\n}\n\n/**\n * An interface for elliptic curve keys that can derive a public key.\n *\n * This interface extends `ECKeyBase` to provide a method for deriving\n * the corresponding compressed public key. It is implemented by both\n * private keys (where it generates the public key) and public keys\n * (where it may return self or convert between formats).\n */\nexport interface ECKey extends ECKeyBase {\n  /**\n   * Returns the compressed public key corresponding to this key.\n   */\n  publicKey(): ECPublicKey;\n}\n\n/**\n * Type guard to check if an object implements ECKey.\n */\nexport function isECKey(obj: unknown): obj is ECKey {\n  if (!isECKeyBase(obj)) return false;\n  const candidate = obj as ECKey;\n  return typeof candidate.publicKey === \"function\";\n}\n\n/**\n * An interface for elliptic curve public keys that can provide their\n * uncompressed form.\n *\n * This interface extends `ECKey` to provide a method for obtaining the\n * uncompressed representation of a public key. Elliptic curve public keys can\n * be represented in both compressed (33 bytes) and uncompressed (65 bytes)\n * formats:\n *\n * - Compressed format: Uses a single byte prefix (0x02 or 0x03) followed by\n *   the x-coordinate (32 bytes), with the prefix indicating the parity of the\n *   y-coordinate.\n *\n * - Uncompressed format: Uses a byte prefix (0x04) followed by both x and y\n *   coordinates (32 bytes each), for a total of 65 bytes.\n *\n * The compressed format is more space-efficient and is recommended for most\n * applications, but some legacy systems require the uncompressed format.\n */\nexport interface ECPublicKeyBase extends ECKey {\n  /**\n   * Returns the uncompressed public key representation.\n   */\n  uncompressedPublicKey(): ECUncompressedPublicKey;\n}\n\n/**\n * Type guard to check if an object implements ECPublicKeyBase.\n */\nexport function isECPublicKeyBase(obj: unknown): obj is ECPublicKeyBase {\n  if (!isECKey(obj)) return false;\n  const candidate = obj as ECPublicKeyBase;\n  return typeof candidate.uncompressedPublicKey === \"function\";\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Sealed message for anonymous authenticated encryption\n *\n * A `SealedMessage` combines key encapsulation with symmetric encryption to\n * provide anonymous authenticated encryption. The sender's identity is not\n * revealed, and only the intended recipient can decrypt the message.\n *\n * The sealing process:\n * 1. Encapsulate a new shared secret using the recipient's public key\n * 2. Use the shared secret to encrypt the plaintext with ChaCha20-Poly1305\n * 3. Return the encrypted message and the encapsulation ciphertext\n *\n * The unsealing process:\n * 1. Decapsulate the shared secret using the recipient's private key\n * 2. Use the shared secret to decrypt the ciphertext\n * 3. Return the plaintext\n *\n * Features:\n * - Anonymous sender (sender identity not revealed)\n * - Authenticated encryption\n * - Forward secrecy (each message uses different ephemeral key)\n *\n * # CBOR Serialization\n *\n * `SealedMessage` is serialized as a 2-element array with tag 40019:\n *\n * ```cddl\n * SealedMessage = #6.40019([\n *   message: EncryptedMessage,\n *   encapsulated_key: EncapsulationCiphertext\n * ])\n * ```\n *\n * # UR Serialization\n *\n * When serialized as a Uniform Resource (UR), a `SealedMessage` is\n * represented with the type \"crypto-sealed\".\n *\n * Ported from bc-components-rust/src/encapsulation/sealed_message.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  cbor,\n  expectArray,\n  createTaggedCbor,\n  validateTag,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { SEALED_MESSAGE as TAG_SEALED_MESSAGE } from \"@bcts/tags\";\nimport { Nonce } from \"../nonce.js\";\nimport { EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { type EncapsulationScheme } from \"./encapsulation-scheme.js\";\nimport { EncapsulationCiphertext } from \"./encapsulation-ciphertext.js\";\nimport { type EncapsulationPublicKey } from \"./encapsulation-public-key.js\";\nimport { type EncapsulationPrivateKey } from \"./encapsulation-private-key.js\";\nimport { X25519PublicKey } from \"../x25519/x25519-public-key.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * A sealed message providing anonymous authenticated encryption.\n */\nexport class SealedMessage\n  implements CborTaggedEncodable, CborTaggedDecodable<SealedMessage>, UREncodable\n{\n  private readonly _message: EncryptedMessage;\n  private readonly _encapsulatedKey: EncapsulationCiphertext;\n\n  private constructor(message: EncryptedMessage, encapsulatedKey: EncapsulationCiphertext) {\n    this._message = message;\n    this._encapsulatedKey = encapsulatedKey;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create a SealedMessage from its components.\n   */\n  static from(message: EncryptedMessage, encapsulatedKey: EncapsulationCiphertext): SealedMessage {\n    return new SealedMessage(message, encapsulatedKey);\n  }\n\n  /**\n   * Seal a message for a recipient (no additional authenticated data).\n   *\n   * @param plaintext - The message to encrypt\n   * @param recipient - The recipient's public key\n   * @returns A sealed message that only the recipient can decrypt\n   */\n  static new(plaintext: Uint8Array, recipient: EncapsulationPublicKey): SealedMessage {\n    return SealedMessage.newWithAad(plaintext, recipient, new Uint8Array(0));\n  }\n\n  /**\n   * Seal a message for a recipient with additional authenticated data.\n   *\n   * @param plaintext - The message to encrypt\n   * @param recipient - The recipient's public key\n   * @param aad - Additional authenticated data (not encrypted but authenticated)\n   * @returns A sealed message that only the recipient can decrypt\n   */\n  static newWithAad(\n    plaintext: Uint8Array,\n    recipient: EncapsulationPublicKey,\n    aad: Uint8Array,\n  ): SealedMessage {\n    return SealedMessage.newOpt(plaintext, recipient, aad, undefined);\n  }\n\n  /**\n   * Seal a message with optional test nonce (for deterministic testing).\n   *\n   * @param plaintext - The message to encrypt\n   * @param recipient - The recipient's public key\n   * @param aad - Additional authenticated data\n   * @param testNonce - Optional fixed nonce for testing (DO NOT use in production)\n   * @returns A sealed message\n   */\n  static newOpt(\n    plaintext: Uint8Array,\n    recipient: EncapsulationPublicKey,\n    aad: Uint8Array,\n    testNonce?: Nonce,\n  ): SealedMessage {\n    // Encapsulate a new shared secret\n    const [sharedSecret, ciphertext] = recipient.encapsulateNewSharedSecret();\n\n    // Use the nonce or generate a random one\n    const nonce = testNonce ?? Nonce.new();\n\n    // Encrypt the plaintext using the shared secret\n    const encryptedMessage = sharedSecret.encrypt(plaintext, aad, nonce);\n\n    return new SealedMessage(encryptedMessage, ciphertext);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the encrypted message.\n   */\n  message(): EncryptedMessage {\n    return this._message;\n  }\n\n  /**\n   * Returns the encapsulation ciphertext (ephemeral public key for X25519).\n   */\n  encapsulatedKey(): EncapsulationCiphertext {\n    return this._encapsulatedKey;\n  }\n\n  /**\n   * Returns the encapsulation scheme used.\n   */\n  encapsulationScheme(): EncapsulationScheme {\n    return this._encapsulatedKey.encapsulationScheme();\n  }\n\n  /**\n   * Decrypt the sealed message using the recipient's private key.\n   *\n   * @param privateKey - The recipient's private key\n   * @returns The decrypted plaintext\n   * @throws Error if decryption fails\n   */\n  decrypt(privateKey: EncapsulationPrivateKey): Uint8Array {\n    // Decapsulate the shared secret\n    const sharedSecret = privateKey.decapsulateSharedSecret(this._encapsulatedKey);\n\n    // Decrypt the message\n    return sharedSecret.decrypt(this._message);\n  }\n\n  /**\n   * Compare with another SealedMessage.\n   */\n  equals(other: SealedMessage): boolean {\n    return (\n      this._message.equals(other._message) && this._encapsulatedKey.equals(other._encapsulatedKey)\n    );\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return `SealedMessage(${this._encapsulatedKey.encapsulationScheme()}, ciphertext: ${bytesToHex(this._message.ciphertext()).substring(0, 16)}...)`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with SealedMessage.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SEALED_MESSAGE.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   * Format: [EncryptedMessage (tagged), EncapsulationCiphertext (tagged)]\n   */\n  untaggedCbor(): Cbor {\n    const elements: Cbor[] = [this._message.taggedCbor(), this._encapsulatedKey.taggedCbor()];\n    return cbor(elements);\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 SealedMessage by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): SealedMessage {\n    const elements = expectArray(cborValue);\n\n    if (elements.length !== 2) {\n      throw new Error(`SealedMessage must have 2 elements, got ${elements.length}`);\n    }\n\n    // Decode the encrypted message (tagged)\n    const message = EncryptedMessage.fromTaggedCbor(elements[0]);\n\n    // Decode the encapsulation ciphertext (tagged)\n    const encapsulatedKey = EncapsulationCiphertext.fromTaggedCbor(elements[1]);\n\n    return new SealedMessage(message, encapsulatedKey);\n  }\n\n  /**\n   * Creates a SealedMessage by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): SealedMessage {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): SealedMessage {\n    const dummyMessage = EncryptedMessage.new(\n      new Uint8Array(0),\n      new Uint8Array(0),\n      Nonce.new(),\n      new Uint8Array(16),\n    );\n    const dummyCiphertext = EncapsulationCiphertext.fromX25519PublicKey(\n      X25519PublicKey.fromData(new Uint8Array(32)),\n    );\n    const dummy = new SealedMessage(dummyMessage, dummyCiphertext);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): SealedMessage {\n    const cborValue = decodeCbor(data);\n    return SealedMessage.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): SealedMessage {\n    const cborValue = decodeCbor(data);\n    const dummyMessage = EncryptedMessage.new(\n      new Uint8Array(0),\n      new Uint8Array(0),\n      Nonce.new(),\n      new Uint8Array(16),\n    );\n    const dummyCiphertext = EncapsulationCiphertext.fromX25519PublicKey(\n      X25519PublicKey.fromData(new Uint8Array(32)),\n    );\n    const dummy = new SealedMessage(dummyMessage, dummyCiphertext);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation of the SealedMessage.\n   * Note: URs use untagged CBOR since the type is conveyed by the UR type itself.\n   */\n  ur(): UR {\n    const name = TAG_SEALED_MESSAGE.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_SEALED_MESSAGE.name is undefined\");\n    }\n    return UR.new(name, 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 SealedMessage from a UR.\n   */\n  static fromUR(ur: UR): SealedMessage {\n    const name = TAG_SEALED_MESSAGE.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_SEALED_MESSAGE.name is undefined\");\n    }\n    ur.checkType(name);\n    return SealedMessage.fromUntaggedCborData(ur.cbor().toData());\n  }\n\n  /**\n   * Creates a SealedMessage from a UR string.\n   */\n  static fromURString(urString: string): SealedMessage {\n    const ur = UR.fromURString(urString);\n    return SealedMessage.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Hash type enum for key derivation functions\n *\n * This enum represents the supported hash algorithms for HKDF and PBKDF2.\n *\n * CDDL:\n * ```cddl\n * HashType = SHA256 / SHA512\n * SHA256 = 0\n * SHA512 = 1\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/hash_type.rs\n */\n\nimport { type Cbor, cbor, expectNumber } from \"@bcts/dcbor\";\n\n/**\n * Enum representing supported hash types for key derivation.\n */\nexport enum HashType {\n  /** SHA-256 hash algorithm */\n  SHA256 = 0,\n  /** SHA-512 hash algorithm */\n  SHA512 = 1,\n}\n\n/**\n * Convert HashType to its string representation.\n */\nexport function hashTypeToString(hashType: HashType): string {\n  switch (hashType) {\n    case HashType.SHA256:\n      return \"SHA256\";\n    case HashType.SHA512:\n      return \"SHA512\";\n    default:\n      throw new Error(`Unknown HashType: ${String(hashType)}`);\n  }\n}\n\n/**\n * Convert HashType to CBOR.\n */\nexport function hashTypeToCbor(hashType: HashType): Cbor {\n  return cbor(hashType);\n}\n\n/**\n * Parse HashType from CBOR.\n */\nexport function hashTypeFromCbor(cborValue: Cbor): HashType {\n  const value = expectNumber(cborValue);\n  switch (value) {\n    case 0:\n      return HashType.SHA256;\n    case 1:\n      return HashType.SHA512;\n    default:\n      throw new Error(`Invalid HashType: ${value}`);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Key derivation method enum\n *\n * This enum represents the supported key derivation methods for encrypting keys.\n *\n * CDDL:\n * ```cddl\n * KeyDerivationMethod = HKDF / PBKDF2 / Scrypt / Argon2id / SSHAgent\n * HKDF = 0\n * PBKDF2 = 1\n * Scrypt = 2\n * Argon2id = 3\n * SSHAgent = 4\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/key_derivation_method.rs\n */\n\nimport { type Cbor, expectNumber } from \"@bcts/dcbor\";\n\n/**\n * Enum representing supported key derivation methods.\n */\nexport enum KeyDerivationMethod {\n  /** HKDF (HMAC-based Key Derivation Function) - RFC 5869 */\n  HKDF = 0,\n  /** PBKDF2 (Password-Based Key Derivation Function 2) - RFC 8018 */\n  PBKDF2 = 1,\n  /** Scrypt - RFC 7914 */\n  Scrypt = 2,\n  /** Argon2id - RFC 9106 (default, most secure for passwords) */\n  Argon2id = 3,\n  /** SSH Agent - Uses SSH agent for key derivation */\n  SSHAgent = 4,\n}\n\n/**\n * Returns the default key derivation method (Argon2id).\n */\nexport function defaultKeyDerivationMethod(): KeyDerivationMethod {\n  return KeyDerivationMethod.Argon2id;\n}\n\n/**\n * Returns the zero-based index of the key derivation method.\n */\nexport function keyDerivationMethodIndex(method: KeyDerivationMethod): number {\n  return method;\n}\n\n/**\n * Attempts to create a KeyDerivationMethod from a zero-based index.\n */\nexport function keyDerivationMethodFromIndex(index: number): KeyDerivationMethod | undefined {\n  switch (index) {\n    case 0:\n      return KeyDerivationMethod.HKDF;\n    case 1:\n      return KeyDerivationMethod.PBKDF2;\n    case 2:\n      return KeyDerivationMethod.Scrypt;\n    case 3:\n      return KeyDerivationMethod.Argon2id;\n    case 4:\n      return KeyDerivationMethod.SSHAgent;\n    default:\n      return undefined;\n  }\n}\n\n/**\n * Convert KeyDerivationMethod to its string representation.\n */\nexport function keyDerivationMethodToString(method: KeyDerivationMethod): string {\n  switch (method) {\n    case KeyDerivationMethod.HKDF:\n      return \"HKDF\";\n    case KeyDerivationMethod.PBKDF2:\n      return \"PBKDF2\";\n    case KeyDerivationMethod.Scrypt:\n      return \"Scrypt\";\n    case KeyDerivationMethod.Argon2id:\n      return \"Argon2id\";\n    case KeyDerivationMethod.SSHAgent:\n      return \"SSHAgent\";\n    default:\n      throw new Error(`Unknown KeyDerivationMethod: ${String(method)}`);\n  }\n}\n\n/**\n * Parse KeyDerivationMethod from CBOR.\n */\nexport function keyDerivationMethodFromCbor(cborValue: Cbor): KeyDerivationMethod {\n  const value = expectNumber(cborValue);\n  const method = keyDerivationMethodFromIndex(Number(value));\n  if (method === undefined) {\n    throw new Error(`Invalid KeyDerivationMethod index: ${value}`);\n  }\n  return method;\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * HKDF (HMAC-based Key Derivation Function) parameters\n *\n * HKDF is a key derivation function based on HMAC, defined in RFC 5869.\n * It is NOT suitable for password-based key derivation (use PBKDF2, Scrypt,\n * or Argon2id instead).\n *\n * CDDL:\n * ```cddl\n * HKDFParams = [0, Salt, HashType]\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/hkdf_params.rs\n */\n\nimport { type Cbor, cbor, expectArray, expectNumber } from \"@bcts/dcbor\";\nimport { hkdfHmacSha256, hash as cryptoHash } from \"@bcts/crypto\";\n\nimport { Salt } from \"../salt.js\";\nimport { Nonce } from \"../nonce.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { type EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { HashType, hashTypeToCbor, hashTypeFromCbor, hashTypeToString } from \"./hash-type.js\";\nimport { KeyDerivationMethod } from \"./key-derivation-method.js\";\nimport type { KeyDerivation } from \"./key-derivation.js\";\n\n/** Default salt length for key derivation */\nexport const SALT_LEN = 16;\n\n/**\n * HKDF parameters for key derivation.\n *\n * HKDF is suitable for deriving keys from high-entropy inputs (like other keys),\n * but NOT for password-based key derivation.\n */\nexport class HKDFParams implements KeyDerivation {\n  static readonly INDEX = KeyDerivationMethod.HKDF;\n\n  private readonly _salt: Salt;\n  private readonly _hashType: HashType;\n\n  private constructor(salt: Salt, hashType: HashType) {\n    this._salt = salt;\n    this._hashType = hashType;\n  }\n\n  /**\n   * Create new HKDF parameters with default settings.\n   * Uses a random 16-byte salt and SHA-256.\n   */\n  static new(): HKDFParams {\n    return HKDFParams.newOpt(Salt.newWithLen(SALT_LEN), HashType.SHA256);\n  }\n\n  /**\n   * Create HKDF parameters with custom settings.\n   */\n  static newOpt(salt: Salt, hashType: HashType): HKDFParams {\n    return new HKDFParams(salt, hashType);\n  }\n\n  /** Returns the salt. */\n  salt(): Salt {\n    return this._salt;\n  }\n\n  /** Returns the hash type. */\n  hashType(): HashType {\n    return this._hashType;\n  }\n\n  /** Returns the method index for CBOR encoding. */\n  index(): number {\n    return HKDFParams.INDEX;\n  }\n\n  /**\n   * Derive a key from the secret and encrypt the content key.\n   */\n  lock(contentKey: SymmetricKey, secret: Uint8Array): EncryptedMessage {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Encode the method parameters as AAD\n    const encodedMethod = this.toCbor().toData();\n\n    // Encrypt the content key using the derived key\n    return derivedKey.encrypt(contentKey.data(), encodedMethod, Nonce.new());\n  }\n\n  /**\n   * Derive a key from the secret and decrypt the content key.\n   */\n  unlock(encryptedMessage: EncryptedMessage, secret: Uint8Array): SymmetricKey {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Decrypt to get the content key\n    const contentKeyData = derivedKey.decrypt(encryptedMessage);\n    return SymmetricKey.fromData(contentKeyData);\n  }\n\n  private _deriveKey(secret: Uint8Array): Uint8Array {\n    switch (this._hashType) {\n      case HashType.SHA256:\n        return hkdfHmacSha256(secret, this._salt.asBytes(), 32);\n      case HashType.SHA512:\n        return cryptoHash.hkdfHmacSha512(secret, this._salt.asBytes(), 32);\n      default:\n        throw new Error(`Unknown hash type: ${String(this._hashType)}`);\n    }\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return `HKDF(${hashTypeToString(this._hashType)})`;\n  }\n\n  /**\n   * Check equality with another HKDFParams.\n   */\n  equals(other: HKDFParams): boolean {\n    return this._salt.equals(other._salt) && this._hashType === other._hashType;\n  }\n\n  // ============================================================================\n  // CBOR Serialization\n  // ============================================================================\n\n  /**\n   * Convert to CBOR.\n   * Format: [0, Salt, HashType]   (Salt is encoded as a tagged value — `#6.40018(bytes)`)\n   */\n  toCbor(): Cbor {\n    return cbor([cbor(HKDFParams.INDEX), this._salt.taggedCbor(), hashTypeToCbor(this._hashType)]);\n  }\n\n  /**\n   * Convert to CBOR binary data.\n   */\n  toCborData(): Uint8Array {\n    return this.toCbor().toData();\n  }\n\n  /**\n   * Parse from CBOR.\n   */\n  static fromCbor(cborValue: Cbor): HKDFParams {\n    const array = expectArray(cborValue);\n\n    if (array.length !== 3) {\n      throw new Error(`Invalid HKDFParams: expected 3 elements, got ${array.length}`);\n    }\n\n    const index = expectNumber(array[0]);\n    if (index !== HKDFParams.INDEX) {\n      throw new Error(`Invalid HKDFParams index: expected ${HKDFParams.INDEX}, got ${index}`);\n    }\n\n    const salt = Salt.fromTaggedCbor(array[1]);\n    const hashType = hashTypeFromCbor(array[2]);\n\n    return new HKDFParams(salt, hashType);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * PBKDF2 (Password-Based Key Derivation Function 2) parameters\n *\n * PBKDF2 is a key derivation function defined in RFC 8018 (PKCS #5 v2.1).\n * It is suitable for password-based key derivation.\n *\n * CDDL:\n * ```cddl\n * PBKDF2Params = [1, Salt, iterations: uint, HashType]\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/pbkdf2_params.rs\n */\n\nimport { type Cbor, cbor, expectArray, expectNumber } from \"@bcts/dcbor\";\nimport { pbkdf2HmacSha256, hash as cryptoHash } from \"@bcts/crypto\";\n\nimport { Salt } from \"../salt.js\";\nimport { Nonce } from \"../nonce.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { type EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { HashType, hashTypeToCbor, hashTypeFromCbor, hashTypeToString } from \"./hash-type.js\";\nimport { KeyDerivationMethod } from \"./key-derivation-method.js\";\nimport { SALT_LEN } from \"./hkdf-params.js\";\nimport type { KeyDerivation } from \"./key-derivation.js\";\n\n/** Default number of iterations for PBKDF2 */\nexport const DEFAULT_PBKDF2_ITERATIONS = 100_000;\n\n/**\n * PBKDF2 parameters for password-based key derivation.\n */\nexport class PBKDF2Params implements KeyDerivation {\n  static readonly INDEX = KeyDerivationMethod.PBKDF2;\n\n  private readonly _salt: Salt;\n  private readonly _iterations: number;\n  private readonly _hashType: HashType;\n\n  private constructor(salt: Salt, iterations: number, hashType: HashType) {\n    this._salt = salt;\n    this._iterations = iterations;\n    this._hashType = hashType;\n  }\n\n  /**\n   * Create new PBKDF2 parameters with default settings.\n   * Uses a random 16-byte salt, 100,000 iterations, and SHA-256.\n   */\n  static new(): PBKDF2Params {\n    return PBKDF2Params.newOpt(\n      Salt.newWithLen(SALT_LEN),\n      DEFAULT_PBKDF2_ITERATIONS,\n      HashType.SHA256,\n    );\n  }\n\n  /**\n   * Create PBKDF2 parameters with custom settings.\n   */\n  static newOpt(salt: Salt, iterations: number, hashType: HashType): PBKDF2Params {\n    return new PBKDF2Params(salt, iterations, hashType);\n  }\n\n  /** Returns the salt. */\n  salt(): Salt {\n    return this._salt;\n  }\n\n  /** Returns the number of iterations. */\n  iterations(): number {\n    return this._iterations;\n  }\n\n  /** Returns the hash type. */\n  hashType(): HashType {\n    return this._hashType;\n  }\n\n  /** Returns the method index for CBOR encoding. */\n  index(): number {\n    return PBKDF2Params.INDEX;\n  }\n\n  /**\n   * Derive a key from the secret and encrypt the content key.\n   */\n  lock(contentKey: SymmetricKey, secret: Uint8Array): EncryptedMessage {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Encode the method parameters as AAD\n    const encodedMethod = this.toCbor().toData();\n\n    // Encrypt the content key using the derived key\n    return derivedKey.encrypt(contentKey.data(), encodedMethod, Nonce.new());\n  }\n\n  /**\n   * Derive a key from the secret and decrypt the content key.\n   */\n  unlock(encryptedMessage: EncryptedMessage, secret: Uint8Array): SymmetricKey {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Decrypt to get the content key\n    const contentKeyData = derivedKey.decrypt(encryptedMessage);\n    return SymmetricKey.fromData(contentKeyData);\n  }\n\n  private _deriveKey(secret: Uint8Array): Uint8Array {\n    switch (this._hashType) {\n      case HashType.SHA256:\n        return pbkdf2HmacSha256(secret, this._salt.asBytes(), this._iterations, 32);\n      case HashType.SHA512:\n        return cryptoHash.pbkdf2HmacSha512(secret, this._salt.asBytes(), this._iterations, 32);\n      default:\n        throw new Error(`Unknown hash type: ${String(this._hashType)}`);\n    }\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return `PBKDF2(${hashTypeToString(this._hashType)})`;\n  }\n\n  /**\n   * Check equality with another PBKDF2Params.\n   */\n  equals(other: PBKDF2Params): boolean {\n    return (\n      this._salt.equals(other._salt) &&\n      this._iterations === other._iterations &&\n      this._hashType === other._hashType\n    );\n  }\n\n  // ============================================================================\n  // CBOR Serialization\n  // ============================================================================\n\n  /**\n   * Convert to CBOR.\n   * Format: [1, Salt, iterations, HashType]   (Salt is encoded as a tagged value — `#6.40018(bytes)`)\n   */\n  toCbor(): Cbor {\n    return cbor([\n      cbor(PBKDF2Params.INDEX),\n      this._salt.taggedCbor(),\n      cbor(this._iterations),\n      hashTypeToCbor(this._hashType),\n    ]);\n  }\n\n  /**\n   * Convert to CBOR binary data.\n   */\n  toCborData(): Uint8Array {\n    return this.toCbor().toData();\n  }\n\n  /**\n   * Parse from CBOR.\n   */\n  static fromCbor(cborValue: Cbor): PBKDF2Params {\n    const array = expectArray(cborValue);\n\n    if (array.length !== 4) {\n      throw new Error(`Invalid PBKDF2Params: expected 4 elements, got ${array.length}`);\n    }\n\n    const index = expectNumber(array[0]);\n    if (index !== PBKDF2Params.INDEX) {\n      throw new Error(`Invalid PBKDF2Params index: expected ${PBKDF2Params.INDEX}, got ${index}`);\n    }\n\n    const salt = Salt.fromTaggedCbor(array[1]);\n    const iterations = Number(expectNumber(array[2]));\n    const hashType = hashTypeFromCbor(array[3]);\n\n    return new PBKDF2Params(salt, iterations, hashType);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Scrypt parameters for password-based key derivation\n *\n * Scrypt is a memory-hard key derivation function defined in RFC 7914.\n * It is suitable for password-based key derivation and is more resistant\n * to hardware brute-force attacks than PBKDF2.\n *\n * CDDL:\n * ```cddl\n * ScryptParams = [2, Salt, log_n: uint, r: uint, p: uint]\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/scrypt_params.rs\n */\n\nimport { type Cbor, cbor, expectArray, expectNumber } from \"@bcts/dcbor\";\nimport { scryptOpt } from \"@bcts/crypto\";\n\nimport { Salt } from \"../salt.js\";\nimport { Nonce } from \"../nonce.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { type EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { KeyDerivationMethod } from \"./key-derivation-method.js\";\nimport { SALT_LEN } from \"./hkdf-params.js\";\nimport type { KeyDerivation } from \"./key-derivation.js\";\n\n// Defaults match Rust `ScryptParams::new()` in bc-components-rust v0.34.x\n// (`log_n = 15, r = 8, p = 1`). Distinct from Rust's `bc_crypto::scrypt()`\n// helper, which uses the heavier `scrypt::Params::recommended()` defaults\n// (`log_n = 17`).\n/** Default log_n parameter (2^15 = 32768 iterations) */\nexport const DEFAULT_SCRYPT_LOG_N = 15;\n/** Default r parameter (block size) */\nexport const DEFAULT_SCRYPT_R = 8;\n/** Default p parameter (parallelism) */\nexport const DEFAULT_SCRYPT_P = 1;\n\n/**\n * Scrypt parameters for password-based key derivation.\n *\n * Parameters:\n * - log_n: CPU/memory cost parameter (N = 2^log_n)\n * - r: Block size parameter\n * - p: Parallelization parameter\n */\nexport class ScryptParams implements KeyDerivation {\n  static readonly INDEX = KeyDerivationMethod.Scrypt;\n\n  private readonly _salt: Salt;\n  private readonly _logN: number;\n  private readonly _r: number;\n  private readonly _p: number;\n\n  private constructor(salt: Salt, logN: number, r: number, p: number) {\n    this._salt = salt;\n    this._logN = logN;\n    this._r = r;\n    this._p = p;\n  }\n\n  /**\n   * Create new Scrypt parameters with default settings.\n   * Uses a random 16-byte salt, log_n=15, r=8, p=1.\n   */\n  static new(): ScryptParams {\n    return ScryptParams.newOpt(\n      Salt.newWithLen(SALT_LEN),\n      DEFAULT_SCRYPT_LOG_N,\n      DEFAULT_SCRYPT_R,\n      DEFAULT_SCRYPT_P,\n    );\n  }\n\n  /**\n   * Create Scrypt parameters with custom settings.\n   */\n  static newOpt(salt: Salt, logN: number, r: number, p: number): ScryptParams {\n    return new ScryptParams(salt, logN, r, p);\n  }\n\n  /** Returns the salt. */\n  salt(): Salt {\n    return this._salt;\n  }\n\n  /** Returns the log_n parameter. */\n  logN(): number {\n    return this._logN;\n  }\n\n  /** Returns the r parameter (block size). */\n  r(): number {\n    return this._r;\n  }\n\n  /** Returns the p parameter (parallelism). */\n  p(): number {\n    return this._p;\n  }\n\n  /** Returns the method index for CBOR encoding. */\n  index(): number {\n    return ScryptParams.INDEX;\n  }\n\n  /**\n   * Derive a key from the secret and encrypt the content key.\n   */\n  lock(contentKey: SymmetricKey, secret: Uint8Array): EncryptedMessage {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Encode the method parameters as AAD\n    const encodedMethod = this.toCbor().toData();\n\n    // Encrypt the content key using the derived key\n    return derivedKey.encrypt(contentKey.data(), encodedMethod, Nonce.new());\n  }\n\n  /**\n   * Derive a key from the secret and decrypt the content key.\n   */\n  unlock(encryptedMessage: EncryptedMessage, secret: Uint8Array): SymmetricKey {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Decrypt to get the content key\n    const contentKeyData = derivedKey.decrypt(encryptedMessage);\n    return SymmetricKey.fromData(contentKeyData);\n  }\n\n  private _deriveKey(secret: Uint8Array): Uint8Array {\n    return scryptOpt(secret, this._salt.asBytes(), 32, this._logN, this._r, this._p);\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return \"Scrypt\";\n  }\n\n  /**\n   * Check equality with another ScryptParams.\n   */\n  equals(other: ScryptParams): boolean {\n    return (\n      this._salt.equals(other._salt) &&\n      this._logN === other._logN &&\n      this._r === other._r &&\n      this._p === other._p\n    );\n  }\n\n  // ============================================================================\n  // CBOR Serialization\n  // ============================================================================\n\n  /**\n   * Convert to CBOR.\n   * Format: [2, Salt, log_n, r, p]   (Salt is encoded as a tagged value — `#6.40018(bytes)`)\n   */\n  toCbor(): Cbor {\n    return cbor([\n      cbor(ScryptParams.INDEX),\n      this._salt.taggedCbor(),\n      cbor(this._logN),\n      cbor(this._r),\n      cbor(this._p),\n    ]);\n  }\n\n  /**\n   * Convert to CBOR binary data.\n   */\n  toCborData(): Uint8Array {\n    return this.toCbor().toData();\n  }\n\n  /**\n   * Parse from CBOR.\n   */\n  static fromCbor(cborValue: Cbor): ScryptParams {\n    const array = expectArray(cborValue);\n\n    if (array.length !== 5) {\n      throw new Error(`Invalid ScryptParams: expected 5 elements, got ${array.length}`);\n    }\n\n    const index = expectNumber(array[0]);\n    if (index !== ScryptParams.INDEX) {\n      throw new Error(`Invalid ScryptParams index: expected ${ScryptParams.INDEX}, got ${index}`);\n    }\n\n    const salt = Salt.fromTaggedCbor(array[1]);\n    const logN = Number(expectNumber(array[2]));\n    const r = Number(expectNumber(array[3]));\n    const p = Number(expectNumber(array[4]));\n\n    return new ScryptParams(salt, logN, r, p);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Argon2id parameters for password-based key derivation\n *\n * Argon2id is a memory-hard key derivation function defined in RFC 9106.\n * It combines Argon2i (resistant to side-channel attacks) and Argon2d\n * (resistant to GPU cracking attacks). It is the recommended choice for\n * password-based key derivation.\n *\n * CDDL:\n * ```cddl\n * Argon2idParams = [3, Salt]\n * ```\n *\n * Note: Argon2id uses sensible defaults for memory, iterations, and parallelism.\n * Only the salt is configurable in the CBOR encoding for simplicity.\n *\n * Ported from bc-components-rust/src/encrypted_key/argon2id_params.rs\n */\n\nimport { type Cbor, cbor, expectArray, expectNumber } from \"@bcts/dcbor\";\nimport { argon2id } from \"@bcts/crypto\";\n\nimport { Salt } from \"../salt.js\";\nimport { Nonce } from \"../nonce.js\";\nimport { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { type EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { KeyDerivationMethod } from \"./key-derivation-method.js\";\nimport { SALT_LEN } from \"./hkdf-params.js\";\nimport type { KeyDerivation } from \"./key-derivation.js\";\n\n/**\n * Argon2id parameters for password-based key derivation.\n *\n * This is the recommended method for password-based key derivation as it\n * provides the best protection against both GPU cracking and side-channel\n * attacks.\n */\nexport class Argon2idParams implements KeyDerivation {\n  static readonly INDEX = KeyDerivationMethod.Argon2id;\n\n  private readonly _salt: Salt;\n\n  private constructor(salt: Salt) {\n    this._salt = salt;\n  }\n\n  /**\n   * Create new Argon2id parameters with default settings.\n   * Uses a random 16-byte salt.\n   */\n  static new(): Argon2idParams {\n    return Argon2idParams.newOpt(Salt.newWithLen(SALT_LEN));\n  }\n\n  /**\n   * Create Argon2id parameters with a custom salt.\n   */\n  static newOpt(salt: Salt): Argon2idParams {\n    return new Argon2idParams(salt);\n  }\n\n  /** Returns the salt. */\n  salt(): Salt {\n    return this._salt;\n  }\n\n  /** Returns the method index for CBOR encoding. */\n  index(): number {\n    return Argon2idParams.INDEX;\n  }\n\n  /**\n   * Derive a key from the secret and encrypt the content key.\n   */\n  lock(contentKey: SymmetricKey, secret: Uint8Array): EncryptedMessage {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Encode the method parameters as AAD\n    const encodedMethod = this.toCbor().toData();\n\n    // Encrypt the content key using the derived key\n    return derivedKey.encrypt(contentKey.data(), encodedMethod, Nonce.new());\n  }\n\n  /**\n   * Derive a key from the secret and decrypt the content key.\n   */\n  unlock(encryptedMessage: EncryptedMessage, secret: Uint8Array): SymmetricKey {\n    const derivedKeyData = this._deriveKey(secret);\n    const derivedKey = SymmetricKey.fromData(derivedKeyData);\n\n    // Decrypt to get the content key\n    const contentKeyData = derivedKey.decrypt(encryptedMessage);\n    return SymmetricKey.fromData(contentKeyData);\n  }\n\n  private _deriveKey(secret: Uint8Array): Uint8Array {\n    return argon2id(secret, this._salt.asBytes(), 32);\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return \"Argon2id\";\n  }\n\n  /**\n   * Check equality with another Argon2idParams.\n   */\n  equals(other: Argon2idParams): boolean {\n    return this._salt.equals(other._salt);\n  }\n\n  // ============================================================================\n  // CBOR Serialization\n  // ============================================================================\n\n  /**\n   * Convert to CBOR.\n   * Format: [3, Salt]   (Salt is encoded as a tagged value — `#6.40018(bytes)`)\n   */\n  toCbor(): Cbor {\n    return cbor([cbor(Argon2idParams.INDEX), this._salt.taggedCbor()]);\n  }\n\n  /**\n   * Convert to CBOR binary data.\n   */\n  toCborData(): Uint8Array {\n    return this.toCbor().toData();\n  }\n\n  /**\n   * Parse from CBOR.\n   */\n  static fromCbor(cborValue: Cbor): Argon2idParams {\n    const array = expectArray(cborValue);\n\n    if (array.length !== 2) {\n      throw new Error(`Invalid Argon2idParams: expected 2 elements, got ${array.length}`);\n    }\n\n    const index = expectNumber(array[0]);\n    if (index !== Argon2idParams.INDEX) {\n      throw new Error(\n        `Invalid Argon2idParams index: expected ${Argon2idParams.INDEX}, got ${index}`,\n      );\n    }\n\n    const salt = Salt.fromTaggedCbor(array[1]);\n\n    return new Argon2idParams(salt);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * SSH Agent key derivation parameters\n *\n * SSH Agent uses an SSH agent daemon for key derivation. The agent signs\n * a challenge derived from the salt to produce the encryption key.\n *\n * CDDL:\n * ```cddl\n * SSHAgentParams = [4, Salt, id: tstr]\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/ssh_agent_params.rs\n */\n\nimport { type Cbor, cbor, expectArray, expectNumber, expectText } from \"@bcts/dcbor\";\n\nimport { Salt } from \"../salt.js\";\nimport type { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport type { EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { KeyDerivationMethod } from \"./key-derivation-method.js\";\nimport type { KeyDerivation } from \"./key-derivation.js\";\nimport { CryptoError } from \"../error.js\";\n\n/** Default salt length for SSH agent key derivation */\nexport const SALT_LEN = 16;\n\n/**\n * SSH Agent parameters for key derivation.\n *\n * This method uses an SSH agent daemon to derive encryption keys.\n * The agent signs a challenge derived from the salt using the specified\n * SSH key identity, and the signature is used to derive the encryption key.\n *\n * **Note:** SSH agent communication requires platform-specific support and\n * may not be available in all JavaScript environments. The lock/unlock\n * methods will throw an error if SSH agent support is not available.\n *\n * **Parity / portability note:** Rust gates SSH-agent support behind the\n * `ssh-agent` feature flag and links to OS-native libraries\n * (`ssh-agent-client-rs`). The TS port deliberately stubs the lock/unlock\n * paths because no portable browser-friendly SSH-agent transport exists.\n * The CBOR encoding of `SSHAgentParams` is still byte-identical, so a\n * payload produced in Rust can be inspected and parsed in TS — only the\n * actual key-derivation operation is unavailable.\n */\nexport class SSHAgentParams implements KeyDerivation {\n  static readonly INDEX = KeyDerivationMethod.SSHAgent;\n\n  private readonly _salt: Salt;\n  private readonly _id: string;\n\n  private constructor(salt: Salt, id: string) {\n    this._salt = salt;\n    this._id = id;\n  }\n\n  /**\n   * Create new SSH agent parameters with default salt and specified key ID.\n   *\n   * @param id - The SSH key identity (usually the key comment or public key fingerprint)\n   */\n  static new(id: string): SSHAgentParams {\n    return SSHAgentParams.newOpt(Salt.newWithLen(SALT_LEN), id);\n  }\n\n  /**\n   * Create SSH agent parameters with custom salt and key ID.\n   *\n   * @param salt - The salt for key derivation\n   * @param id - The SSH key identity\n   */\n  static newOpt(salt: Salt, id: string): SSHAgentParams {\n    return new SSHAgentParams(salt, id);\n  }\n\n  /** Returns the salt. */\n  salt(): Salt {\n    return this._salt;\n  }\n\n  /** Returns the SSH key identity. */\n  id(): string {\n    return this._id;\n  }\n\n  /** Returns the method index for CBOR encoding. */\n  index(): number {\n    return SSHAgentParams.INDEX;\n  }\n\n  /**\n   * Derive a key using SSH agent and encrypt the content key.\n   *\n   * **Note:** This method requires SSH agent support which is not yet\n   * implemented in this TypeScript port. Use an alternative key derivation\n   * method or implement SSH agent communication for your environment.\n   *\n   * @throws CryptoError - SSH agent support is not available\n   */\n  lock(_contentKey: SymmetricKey, _secret: Uint8Array): EncryptedMessage {\n    throw CryptoError.sshAgent(\n      \"SSH agent key derivation is not yet implemented in this TypeScript port. \" +\n        \"Use HKDF, PBKDF2, Scrypt, or Argon2id instead.\",\n    );\n  }\n\n  /**\n   * Derive a key using SSH agent and decrypt the content key.\n   *\n   * **Note:** This method requires SSH agent support which is not yet\n   * implemented in this TypeScript port. Use an alternative key derivation\n   * method or implement SSH agent communication for your environment.\n   *\n   * @throws CryptoError - SSH agent support is not available\n   */\n  unlock(_encryptedMessage: EncryptedMessage, _secret: Uint8Array): SymmetricKey {\n    throw CryptoError.sshAgent(\n      \"SSH agent key derivation is not yet implemented in this TypeScript port. \" +\n        \"Use HKDF, PBKDF2, Scrypt, or Argon2id instead.\",\n    );\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return `SSHAgent(id: \"${this._id}\")`;\n  }\n\n  /**\n   * Check equality with another SSHAgentParams.\n   */\n  equals(other: SSHAgentParams): boolean {\n    return this._salt.equals(other._salt) && this._id === other._id;\n  }\n\n  // ============================================================================\n  // CBOR Serialization\n  // ============================================================================\n\n  /**\n   * Convert to CBOR.\n   * Format: [4, Salt, id: tstr]   (Salt is encoded as a tagged value — `#6.40018(bytes)`)\n   */\n  toCbor(): Cbor {\n    return cbor([cbor(SSHAgentParams.INDEX), this._salt.taggedCbor(), cbor(this._id)]);\n  }\n\n  /**\n   * Convert to CBOR binary data.\n   */\n  toCborData(): Uint8Array {\n    return this.toCbor().toData();\n  }\n\n  /**\n   * Parse from CBOR.\n   */\n  static fromCbor(cborValue: Cbor): SSHAgentParams {\n    const array = expectArray(cborValue);\n\n    if (array.length !== 3) {\n      throw new Error(`Invalid SSHAgentParams: expected 3 elements, got ${array.length}`);\n    }\n\n    const index = expectNumber(array[0]);\n    if (index !== SSHAgentParams.INDEX) {\n      throw new Error(\n        `Invalid SSHAgentParams index: expected ${SSHAgentParams.INDEX}, got ${index}`,\n      );\n    }\n\n    const salt = Salt.fromTaggedCbor(array[1]);\n    const id = expectText(array[2]);\n\n    return new SSHAgentParams(salt, id);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Key derivation parameters union type\n *\n * This type represents the derivation parameters for all supported methods.\n * It provides a unified interface for locking and unlocking keys regardless\n * of the underlying derivation method.\n *\n * Ported from bc-components-rust/src/encrypted_key/key_derivation_params.rs\n */\n\nimport { type Cbor, expectArray, expectNumber } from \"@bcts/dcbor\";\n\nimport type { SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport type { EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { KeyDerivationMethod, keyDerivationMethodFromIndex } from \"./key-derivation-method.js\";\nimport { HKDFParams } from \"./hkdf-params.js\";\nimport { PBKDF2Params } from \"./pbkdf2-params.js\";\nimport { ScryptParams } from \"./scrypt-params.js\";\nimport { Argon2idParams } from \"./argon2id-params.js\";\nimport { SSHAgentParams } from \"./ssh-agent-params.js\";\n\n/**\n * Union type representing key derivation parameters.\n *\n * Use the `method()` function to get the derivation method, and\n * `lock()`/`unlock()` for key operations.\n */\nexport type KeyDerivationParams =\n  | { type: \"hkdf\"; params: HKDFParams }\n  | { type: \"pbkdf2\"; params: PBKDF2Params }\n  | { type: \"scrypt\"; params: ScryptParams }\n  | { type: \"argon2id\"; params: Argon2idParams }\n  | { type: \"sshagent\"; params: SSHAgentParams };\n\n/**\n * Create HKDF derivation parameters.\n */\nexport function hkdfParams(params?: HKDFParams): KeyDerivationParams {\n  return { type: \"hkdf\", params: params ?? HKDFParams.new() };\n}\n\n/**\n * Create PBKDF2 derivation parameters.\n */\nexport function pbkdf2Params(params?: PBKDF2Params): KeyDerivationParams {\n  return { type: \"pbkdf2\", params: params ?? PBKDF2Params.new() };\n}\n\n/**\n * Create Scrypt derivation parameters.\n */\nexport function scryptParams(params?: ScryptParams): KeyDerivationParams {\n  return { type: \"scrypt\", params: params ?? ScryptParams.new() };\n}\n\n/**\n * Create Argon2id derivation parameters.\n */\nexport function argon2idParams(params?: Argon2idParams): KeyDerivationParams {\n  return { type: \"argon2id\", params: params ?? Argon2idParams.new() };\n}\n\n/**\n * Create SSH agent derivation parameters.\n *\n * @param idOrParams - Either an SSH key identity string or SSHAgentParams instance\n */\nexport function sshAgentParams(idOrParams: string | SSHAgentParams): KeyDerivationParams {\n  if (typeof idOrParams === \"string\") {\n    return { type: \"sshagent\", params: SSHAgentParams.new(idOrParams) };\n  }\n  return { type: \"sshagent\", params: idOrParams };\n}\n\n/**\n * Create default key derivation parameters (Argon2id).\n */\nexport function defaultKeyDerivationParams(): KeyDerivationParams {\n  return argon2idParams();\n}\n\n/**\n * Get the key derivation method for the given parameters.\n */\nexport function keyDerivationParamsMethod(kdp: KeyDerivationParams): KeyDerivationMethod {\n  switch (kdp.type) {\n    case \"hkdf\":\n      return KeyDerivationMethod.HKDF;\n    case \"pbkdf2\":\n      return KeyDerivationMethod.PBKDF2;\n    case \"scrypt\":\n      return KeyDerivationMethod.Scrypt;\n    case \"argon2id\":\n      return KeyDerivationMethod.Argon2id;\n    case \"sshagent\":\n      return KeyDerivationMethod.SSHAgent;\n  }\n}\n\n/**\n * Check if the parameters use a password-based method.\n * Password-based methods (PBKDF2, Scrypt, Argon2id) are designed for\n * low-entropy secrets like passwords.\n */\nexport function isPasswordBased(kdp: KeyDerivationParams): boolean {\n  return kdp.type === \"pbkdf2\" || kdp.type === \"scrypt\" || kdp.type === \"argon2id\";\n}\n\n/**\n * Check if the parameters use SSH Agent for key derivation.\n *\n * Note: SSH Agent key derivation is not yet functional in TypeScript.\n * This function is useful for detecting envelopes locked by other\n * implementations (e.g., Rust).\n */\nexport function isSshAgent(kdp: KeyDerivationParams): boolean {\n  return kdp.type === \"sshagent\";\n}\n\n/**\n * Lock (encrypt) a content key using the derived key.\n */\nexport function lockWithParams(\n  kdp: KeyDerivationParams,\n  contentKey: SymmetricKey,\n  secret: Uint8Array,\n): EncryptedMessage {\n  switch (kdp.type) {\n    case \"hkdf\":\n      return kdp.params.lock(contentKey, secret);\n    case \"pbkdf2\":\n      return kdp.params.lock(contentKey, secret);\n    case \"scrypt\":\n      return kdp.params.lock(contentKey, secret);\n    case \"argon2id\":\n      return kdp.params.lock(contentKey, secret);\n    case \"sshagent\":\n      return kdp.params.lock(contentKey, secret);\n  }\n}\n\n/**\n * Convert KeyDerivationParams to CBOR.\n */\nexport function keyDerivationParamsToCbor(kdp: KeyDerivationParams): Cbor {\n  switch (kdp.type) {\n    case \"hkdf\":\n      return kdp.params.toCbor();\n    case \"pbkdf2\":\n      return kdp.params.toCbor();\n    case \"scrypt\":\n      return kdp.params.toCbor();\n    case \"argon2id\":\n      return kdp.params.toCbor();\n    case \"sshagent\":\n      return kdp.params.toCbor();\n  }\n}\n\n/**\n * Convert KeyDerivationParams to CBOR binary data.\n */\nexport function keyDerivationParamsToCborData(kdp: KeyDerivationParams): Uint8Array {\n  return keyDerivationParamsToCbor(kdp).toData();\n}\n\n/**\n * Get string representation of KeyDerivationParams.\n */\nexport function keyDerivationParamsToString(kdp: KeyDerivationParams): string {\n  switch (kdp.type) {\n    case \"hkdf\":\n      return kdp.params.toString();\n    case \"pbkdf2\":\n      return kdp.params.toString();\n    case \"scrypt\":\n      return kdp.params.toString();\n    case \"argon2id\":\n      return kdp.params.toString();\n    case \"sshagent\":\n      return kdp.params.toString();\n  }\n}\n\n/**\n * Parse KeyDerivationParams from CBOR.\n */\nexport function keyDerivationParamsFromCbor(cborValue: Cbor): KeyDerivationParams {\n  const array = expectArray(cborValue);\n  if (array.length === 0) {\n    throw new Error(\"Invalid KeyDerivationParams: empty array\");\n  }\n\n  const index = expectNumber(array[0]);\n  const method = keyDerivationMethodFromIndex(Number(index));\n\n  if (method === undefined) {\n    throw new Error(`Invalid KeyDerivationMethod index: ${index}`);\n  }\n\n  switch (method) {\n    case KeyDerivationMethod.HKDF:\n      return { type: \"hkdf\", params: HKDFParams.fromCbor(cborValue) };\n    case KeyDerivationMethod.PBKDF2:\n      return { type: \"pbkdf2\", params: PBKDF2Params.fromCbor(cborValue) };\n    case KeyDerivationMethod.Scrypt:\n      return { type: \"scrypt\", params: ScryptParams.fromCbor(cborValue) };\n    case KeyDerivationMethod.Argon2id:\n      return { type: \"argon2id\", params: Argon2idParams.fromCbor(cborValue) };\n    case KeyDerivationMethod.SSHAgent:\n      return { type: \"sshagent\", params: SSHAgentParams.fromCbor(cborValue) };\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * Encrypted key for secure symmetric key storage\n *\n * `EncryptedKey` provides symmetric encryption and decryption of content keys\n * using various key derivation methods (HKDF, PBKDF2, Scrypt, Argon2id).\n *\n * The form of an `EncryptedKey` is an `EncryptedMessage` that contains the\n * encrypted content key, with its Additional Authenticated Data (AAD) being\n * the CBOR encoding of the key derivation method and parameters.\n *\n * CDDL:\n * ```cddl\n * EncryptedKey = #6.40027(EncryptedMessage)\n *\n * EncryptedMessage =\n *     #6.40002([ ciphertext: bstr, nonce: bstr, auth: bstr, aad: bstr .cbor KeyDerivation ])\n *\n * KeyDerivation = HKDFParams / PBKDF2Params / ScryptParams / Argon2idParams\n * ```\n *\n * Ported from bc-components-rust/src/encrypted_key/encrypted_key_impl.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  createTaggedCbor,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  validateTag,\n} from \"@bcts/dcbor\";\nimport { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { ENCRYPTED_KEY as TAG_ENCRYPTED_KEY } from \"@bcts/tags\";\n\nimport { type SymmetricKey } from \"../symmetric/symmetric-key.js\";\nimport { EncryptedMessage } from \"../symmetric/encrypted-message.js\";\nimport { CryptoError } from \"../error.js\";\nimport { KeyDerivationMethod } from \"./key-derivation-method.js\";\nimport {\n  type KeyDerivationParams,\n  hkdfParams,\n  pbkdf2Params,\n  scryptParams,\n  argon2idParams,\n  keyDerivationParamsMethod,\n  keyDerivationParamsToString,\n  keyDerivationParamsFromCbor,\n  lockWithParams,\n  isPasswordBased,\n  isSshAgent,\n} from \"./key-derivation-params.js\";\n\n/**\n * Encrypted key providing secure storage of symmetric keys.\n *\n * Use `lock()` to encrypt a content key with a password or secret,\n * and `unlock()` to decrypt it.\n */\nexport class EncryptedKey\n  implements CborTaggedEncodable, CborTaggedDecodable<EncryptedKey>, UREncodable\n{\n  private readonly _params: KeyDerivationParams;\n  private readonly _encryptedMessage: EncryptedMessage;\n\n  private constructor(params: KeyDerivationParams, encryptedMessage: EncryptedMessage) {\n    this._params = params;\n    this._encryptedMessage = encryptedMessage;\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Lock (encrypt) a content key using custom derivation parameters.\n   *\n   * @param params - The key derivation parameters to use\n   * @param secret - The secret (password or key material) to derive from\n   * @param contentKey - The symmetric key to encrypt\n   * @returns The encrypted key\n   */\n  static lockOpt(\n    params: KeyDerivationParams,\n    secret: Uint8Array,\n    contentKey: SymmetricKey,\n  ): EncryptedKey {\n    const encryptedMessage = lockWithParams(params, contentKey, secret);\n    return new EncryptedKey(params, encryptedMessage);\n  }\n\n  /**\n   * Lock (encrypt) a content key using a specific derivation method with defaults.\n   *\n   * @param method - The key derivation method to use\n   * @param secret - The secret (password or key material) to derive from\n   * @param contentKey - The symmetric key to encrypt\n   * @returns The encrypted key\n   */\n  static lock(\n    method: KeyDerivationMethod,\n    secret: Uint8Array,\n    contentKey: SymmetricKey,\n  ): EncryptedKey {\n    let params: KeyDerivationParams;\n\n    switch (method) {\n      case KeyDerivationMethod.HKDF:\n        params = hkdfParams();\n        break;\n      case KeyDerivationMethod.PBKDF2:\n        params = pbkdf2Params();\n        break;\n      case KeyDerivationMethod.Scrypt:\n        params = scryptParams();\n        break;\n      case KeyDerivationMethod.Argon2id:\n        params = argon2idParams();\n        break;\n      case KeyDerivationMethod.SSHAgent:\n        throw new Error(\n          \"SSH Agent key derivation cannot be used with lock() - use lockOpt() with sshAgentParams() instead\",\n        );\n    }\n\n    return EncryptedKey.lockOpt(params, secret, contentKey);\n  }\n\n  // ============================================================================\n  // Instance Methods\n  // ============================================================================\n\n  /**\n   * Returns the encrypted message.\n   */\n  encryptedMessage(): EncryptedMessage {\n    return this._encryptedMessage;\n  }\n\n  /**\n   * Returns the key derivation parameters.\n   */\n  params(): KeyDerivationParams {\n    return this._params;\n  }\n\n  /**\n   * Returns the key derivation method.\n   */\n  method(): KeyDerivationMethod {\n    return keyDerivationParamsMethod(this._params);\n  }\n\n  /**\n   * Check if this uses a password-based key derivation method.\n   */\n  isPasswordBased(): boolean {\n    return isPasswordBased(this._params);\n  }\n\n  /**\n   * Check if this uses SSH Agent for key derivation.\n   *\n   * Note: SSH Agent key derivation is not yet functional in TypeScript.\n   * This method is useful for detecting envelopes locked by other\n   * implementations (e.g., Rust).\n   */\n  isSshAgent(): boolean {\n    return isSshAgent(this._params);\n  }\n\n  /**\n   * Unlock (decrypt) the content key.\n   *\n   * @param secret - The secret (password or key material) used to lock\n   * @returns The decrypted symmetric key\n   * @throws CryptoError if decryption fails (wrong password, tampered data, etc.)\n   */\n  unlock(secret: Uint8Array): SymmetricKey {\n    // Get the AAD from the encrypted message, which contains the derivation params\n    const aad = this._encryptedMessage.aad();\n    if (aad.length === 0) {\n      throw CryptoError.invalidData(\"Missing AAD in EncryptedKey\");\n    }\n\n    // Parse the derivation parameters from AAD\n    const paramsCbor = decodeCbor(aad);\n    const params = keyDerivationParamsFromCbor(paramsCbor);\n\n    // Unlock using the parsed parameters\n    switch (params.type) {\n      case \"hkdf\":\n        return params.params.unlock(this._encryptedMessage, secret);\n      case \"pbkdf2\":\n        return params.params.unlock(this._encryptedMessage, secret);\n      case \"scrypt\":\n        return params.params.unlock(this._encryptedMessage, secret);\n      case \"argon2id\":\n        return params.params.unlock(this._encryptedMessage, secret);\n      case \"sshagent\":\n        return params.params.unlock(this._encryptedMessage, secret);\n    }\n  }\n\n  /**\n   * Check equality with another EncryptedKey.\n   */\n  equals(other: EncryptedKey): boolean {\n    return this._encryptedMessage.equals(other._encryptedMessage);\n  }\n\n  /**\n   * Get string representation.\n   */\n  toString(): string {\n    return `EncryptedKey(${keyDerivationParamsToString(this._params)})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with EncryptedKey.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_ENCRYPTED_KEY.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\n   * The EncryptedMessage is encoded with its own tag (40002).\n   */\n  untaggedCbor(): Cbor {\n    return this._encryptedMessage.taggedCbor();\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 an EncryptedKey by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): EncryptedKey {\n    // The untagged content is a tagged EncryptedMessage\n    const encryptedMessage = EncryptedMessage.fromTaggedCbor(cborValue);\n\n    // Parse the derivation parameters from AAD\n    const aad = encryptedMessage.aad();\n    if (aad.length === 0) {\n      throw CryptoError.invalidData(\"Missing AAD in EncryptedKey\");\n    }\n    const paramsCbor = decodeCbor(aad);\n    const params = keyDerivationParamsFromCbor(paramsCbor);\n\n    return new EncryptedKey(params, encryptedMessage);\n  }\n\n  /**\n   * Creates an EncryptedKey by decoding it from tagged CBOR.\n   */\n  fromTaggedCbor(cborValue: Cbor): EncryptedKey {\n    validateTag(cborValue, this.cborTags());\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): EncryptedKey {\n    // Create a dummy instance for the method\n    const dummyParams = hkdfParams();\n    const dummyMessage = EncryptedMessage.new(\n      new Uint8Array(32),\n      new Uint8Array(0),\n      // @ts-expect-error - Using internal method for dummy\n      { data: () => new Uint8Array(12) },\n      new Uint8Array(16),\n    );\n    const dummy = new EncryptedKey(dummyParams, dummyMessage);\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): EncryptedKey {\n    const cborValue = decodeCbor(data);\n    return EncryptedKey.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): EncryptedKey {\n    const cborValue = decodeCbor(data);\n    const dummyParams = hkdfParams();\n    const dummyMessage = EncryptedMessage.new(\n      new Uint8Array(32),\n      new Uint8Array(0),\n      // @ts-expect-error - Using internal method for dummy\n      { data: () => new Uint8Array(12) },\n      new Uint8Array(16),\n    );\n    const dummy = new EncryptedKey(dummyParams, dummyMessage);\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n\n  // ============================================================================\n  // UR Serialization (UREncodable)\n  // ============================================================================\n\n  /**\n   * Returns the UR representation.\n   */\n  ur(): UR {\n    const name = TAG_ENCRYPTED_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_ENCRYPTED_KEY.name is undefined\");\n    }\n    return UR.new(name, 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 an EncryptedKey from a UR.\n   */\n  static fromUR(ur: UR): EncryptedKey {\n    const name = TAG_ENCRYPTED_KEY.name;\n    if (name === undefined) {\n      throw new Error(\"TAG_ENCRYPTED_KEY.name is undefined\");\n    }\n    ur.checkType(name);\n    return EncryptedKey.fromUntaggedCborData(ur.cbor().toData());\n  }\n\n  /**\n   * Creates an EncryptedKey from a UR string.\n   */\n  static fromURString(urString: string): EncryptedKey {\n    const ur = UR.fromURString(urString);\n    return EncryptedKey.fromUR(ur);\n  }\n}\n","/**\n * Copyright © 2023-2026 Blockchain Commons, LLC\n * Copyright © 2025-2026 Parity Technologies\n *\n *\n * SSKR Integration - CBOR wrappers for SSKR shares\n *\n * This module provides CBOR serialization for SSKR (Sharded Secret Key\n * Reconstruction) shares. It wraps the core SSKR functionality from\n * @bcts/sskr with CBOR tags.\n *\n * # CBOR Serialization\n *\n * SSKRShare is serialized with tag 40309:\n * ```\n * #6.40309(h'<share-bytes>')\n * ```\n *\n * Legacy tag 309 is also supported for reading.\n *\n * Ported from bc-components-rust/src/sskr_mod.rs\n */\n\nimport {\n  type Cbor,\n  type Tag,\n  type CborTaggedEncodable,\n  type CborTaggedDecodable,\n  toByteString,\n  expectBytes,\n  createTaggedCbor,\n  extractTaggedContent,\n  decodeCbor,\n  tagsForValues,\n  tagValue,\n} from \"@bcts/dcbor\";\nimport { SSKR_SHARE as TAG_SSKR_SHARE, SSKR_SHARE_V1 as TAG_SSKR_SHARE_V1 } from \"@bcts/tags\";\n\nimport { bytesToHex, hexToBytes } from \"./utils.js\";\nimport {\n  sskrGenerate,\n  sskrGenerateUsing,\n  sskrCombine,\n  Secret as SSKRSecret,\n  GroupSpec as SSKRGroupSpec,\n  Spec as SSKRSpec,\n} from \"@bcts/sskr\";\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\n\n// Re-export from sskr package\nexport { sskrGenerate, sskrGenerateUsing, sskrCombine, SSKRSecret, SSKRGroupSpec, SSKRSpec };\n\n/** Metadata size in bytes (identifier + thresholds + indices) */\nconst METADATA_SIZE_BYTES = 5;\n\n/**\n * SSKRShareCbor - CBOR/UR wrapper for an SSKR share.\n *\n * An SSKR share is a binary encoding of:\n * - Identifier (2 bytes)\n * - Group metadata (1 byte): group_threshold-1 (4 bits) + group_count-1 (4 bits)\n * - Member metadata (1 byte): group_index (4 bits) + member_threshold-1 (4 bits)\n * - Member index (1 byte): reserved (4 bits, must be 0) + member_index (4 bits)\n * - Share value (variable length)\n */\nexport class SSKRShareCbor implements CborTaggedEncodable, CborTaggedDecodable<SSKRShareCbor> {\n  private readonly _data: Uint8Array;\n\n  private constructor(data: Uint8Array) {\n    if (data.length < METADATA_SIZE_BYTES) {\n      throw new Error(\n        `SSKRShare must be at least ${METADATA_SIZE_BYTES} bytes, got ${data.length}`,\n      );\n    }\n    this._data = new Uint8Array(data);\n  }\n\n  // ============================================================================\n  // Static Factory Methods\n  // ============================================================================\n\n  /**\n   * Create an SSKRShareCbor from raw share bytes.\n   *\n   * @param data - The share bytes (5+ bytes)\n   */\n  static fromData(data: Uint8Array): SSKRShareCbor {\n    return new SSKRShareCbor(data);\n  }\n\n  /**\n   * Create an SSKRShareCbor from a hex string.\n   *\n   * @param hex - The share as a hex string\n   */\n  static fromHex(hex: string): SSKRShareCbor {\n    return new SSKRShareCbor(hexToBytes(hex));\n  }\n\n  // ============================================================================\n  // Instance Methods - Data Access\n  // ============================================================================\n\n  /**\n   * Returns the raw share bytes.\n   */\n  asBytes(): Uint8Array {\n    return this._data;\n  }\n\n  /**\n   * Returns a copy of the raw share bytes.\n   */\n  data(): Uint8Array {\n    return new Uint8Array(this._data);\n  }\n\n  /**\n   * Returns the share as a hex string.\n   */\n  hex(): string {\n    return bytesToHex(this._data);\n  }\n\n  // ============================================================================\n  // Instance Methods - Metadata Access\n  // ============================================================================\n\n  /**\n   * Returns the identifier (2 bytes) as a number.\n   */\n  identifier(): number {\n    return (this._data[0] << 8) | this._data[1];\n  }\n\n  /**\n   * Returns the identifier as a hex string.\n   */\n  identifierHex(): string {\n    return bytesToHex(this._data.subarray(0, 2));\n  }\n\n  /**\n   * Returns the group threshold (minimum number of groups needed).\n   */\n  groupThreshold(): number {\n    return (this._data[2] >> 4) + 1;\n  }\n\n  /**\n   * Returns the total number of groups.\n   */\n  groupCount(): number {\n    return (this._data[2] & 0x0f) + 1;\n  }\n\n  /**\n   * Returns this share's group index (0-based).\n   */\n  groupIndex(): number {\n    return this._data[3] >> 4;\n  }\n\n  /**\n   * Returns the member threshold for this share's group.\n   */\n  memberThreshold(): number {\n    return (this._data[3] & 0x0f) + 1;\n  }\n\n  /**\n   * Returns this share's member index within its group (0-based).\n   */\n  memberIndex(): number {\n    return this._data[4] & 0x0f;\n  }\n\n  /**\n   * Returns the share value (the actual secret share data).\n   */\n  shareValue(): Uint8Array {\n    return this._data.subarray(METADATA_SIZE_BYTES);\n  }\n\n  // ============================================================================\n  // Equality and String Representation\n  // ============================================================================\n\n  /**\n   * Compare with another SSKRShareCbor.\n   */\n  equals(other: SSKRShareCbor): 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   * Get string representation.\n   */\n  toString(): string {\n    return `SSKRShare(${this.identifierHex()}, group ${this.groupIndex() + 1}/${this.groupCount()}, member ${this.memberIndex() + 1}/${this.memberThreshold()})`;\n  }\n\n  // ============================================================================\n  // CBOR Serialization (CborTaggedEncodable)\n  // ============================================================================\n\n  /**\n   * Returns the CBOR tags associated with SSKRShare.\n   * Includes both current tag (40309) and legacy tag (309) for compatibility.\n   */\n  cborTags(): Tag[] {\n    return tagsForValues([TAG_SSKR_SHARE.value, TAG_SSKR_SHARE_V1.value]);\n  }\n\n  /**\n   * Returns the untagged CBOR encoding.\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 an SSKRShareCbor by decoding it from untagged CBOR.\n   */\n  fromUntaggedCbor(cborValue: Cbor): SSKRShareCbor {\n    const data = expectBytes(cborValue);\n    return SSKRShareCbor.fromData(data);\n  }\n\n  /**\n   * Creates an SSKRShareCbor by decoding it from tagged CBOR.\n   * Accepts both tag 40309 and legacy tag 309.\n   */\n  fromTaggedCbor(cborValue: Cbor): SSKRShareCbor {\n    const tag = tagValue(cborValue);\n\n    // Accept both current and legacy tags\n    if (tag !== TAG_SSKR_SHARE.value && tag !== TAG_SSKR_SHARE_V1.value) {\n      throw new Error(\n        `Invalid SSKRShare tag: expected ${TAG_SSKR_SHARE.value} or ${TAG_SSKR_SHARE_V1.value}, got ${tag}`,\n      );\n    }\n\n    const content = extractTaggedContent(cborValue);\n    return this.fromUntaggedCbor(content);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR.\n   */\n  static fromTaggedCbor(cborValue: Cbor): SSKRShareCbor {\n    const dummy = new SSKRShareCbor(new Uint8Array(METADATA_SIZE_BYTES + 16));\n    return dummy.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from tagged CBOR binary data.\n   */\n  static fromTaggedCborData(data: Uint8Array): SSKRShareCbor {\n    const cborValue = decodeCbor(data);\n    return SSKRShareCbor.fromTaggedCbor(cborValue);\n  }\n\n  /**\n   * Static method to decode from untagged CBOR binary data.\n   */\n  static fromUntaggedCborData(data: Uint8Array): SSKRShareCbor {\n    const cborValue = decodeCbor(data);\n    const dummy = new SSKRShareCbor(new Uint8Array(METADATA_SIZE_BYTES + 16));\n    return dummy.fromUntaggedCbor(cborValue);\n  }\n}\n\n// ============================================================================\n// Type Alias for Rust Parity\n// ============================================================================\n\n/**\n * SSKRShare - Alias for SSKRShareCbor to match Rust API naming.\n *\n * In Rust, this type is called `SSKRShare`. The TypeScript implementation\n * uses `SSKRShareCbor` to distinguish it from raw share data, but we provide\n * this alias for API parity with bc-components-rust.\n */\nexport type SSKRShare = SSKRShareCbor;\n\n/**\n * Create an SSKRShare from raw data.\n * This is a convenience function that matches the Rust constructor pattern.\n */\n// eslint-disable-next-line no-redeclare -- Intentional: TypeScript allows type/value with same name\nexport const SSKRShare = {\n  fromData: (data: Uint8Array): SSKRShareCbor => SSKRShareCbor.fromData(data),\n  fromHex: (hex: string): SSKRShareCbor => SSKRShareCbor.fromHex(hex),\n  fromTaggedCbor: (cborValue: Cbor): SSKRShareCbor => SSKRShareCbor.fromTaggedCbor(cborValue),\n  fromTaggedCborData: (data: Uint8Array): SSKRShareCbor => SSKRShareCbor.fromTaggedCborData(data),\n  fromUntaggedCborData: (data: Uint8Array): SSKRShareCbor =>\n    SSKRShareCbor.fromUntaggedCborData(data),\n};\n\n// ============================================================================\n// Wrapper Functions (Rust API Parity)\n// ============================================================================\n\n/**\n * Generates SSKR shares for the given spec and secret.\n *\n * This function matches the Rust `sskr_generate` API by returning wrapped\n * SSKRShare objects instead of raw byte arrays.\n *\n * @param spec - The SSKRSpec instance defining group/member thresholds\n * @param masterSecret - The SSKRSecret to be split into shares\n * @returns Nested array of SSKRShare instances (groups × members)\n *\n * @example\n * ```typescript\n * import { SSKRSecret, SSKRSpec, SSKRGroupSpec, sskrGenerateShares } from '@bcts/components';\n *\n * const secret = SSKRSecret.new(new Uint8Array(16).fill(0x42));\n * const group = SSKRGroupSpec.new(2, 3); // 2 of 3\n * const spec = SSKRSpec.new(1, [group]); // 1 group required\n *\n * const shares = sskrGenerateShares(spec, secret);\n * // shares[0] contains 3 SSKRShare instances\n * ```\n */\nexport function sskrGenerateShares(spec: SSKRSpec, masterSecret: SSKRSecret): SSKRShare[][] {\n  const rawGroups = sskrGenerate(spec, masterSecret);\n  return rawGroups.map((group) => group.map((shareData) => SSKRShareCbor.fromData(shareData)));\n}\n\n/**\n * Interface for RNG that only requires fillRandomData method.\n * This is a subset of the full RandomNumberGenerator interface.\n */\nexport interface SimpleRng {\n  fillRandomData(data: Uint8Array): void;\n}\n\n/**\n * Generates SSKR shares using a custom random number generator.\n *\n * This function matches the Rust `sskr_generate_using` API by returning\n * wrapped SSKRShare objects and allowing a custom RNG for deterministic\n * testing.\n *\n * @param spec - The SSKRSpec instance defining group/member thresholds\n * @param masterSecret - The SSKRSecret to be split into shares\n * @param rng - Random number generator (must have fillRandomData method)\n * @returns Nested array of SSKRShare instances (groups × members)\n */\nexport function sskrGenerateSharesUsing(\n  spec: SSKRSpec,\n  masterSecret: SSKRSecret,\n  rng: SimpleRng,\n): SSKRShare[][] {\n  // Cast to RandomNumberGenerator - sskrGenerateUsing only uses fillRandomData internally\n  const rawGroups = sskrGenerateUsing(spec, masterSecret, rng as unknown as RandomNumberGenerator);\n  return rawGroups.map((group) => group.map((shareData) => SSKRShareCbor.fromData(shareData)));\n}\n\n/**\n * Combines SSKR shares to reconstruct the original secret.\n *\n * This function matches the Rust `sskr_combine` API by accepting\n * wrapped SSKRShare objects.\n *\n * @param shares - Array of SSKRShare instances to combine\n * @returns The reconstructed SSKRSecret\n * @throws Error if shares cannot be combined (insufficient shares, mismatched IDs, etc.)\n *\n * @example\n * ```typescript\n * import { sskrGenerateShares, sskrCombineShares } from '@bcts/components';\n *\n * // Generate shares\n * const shares = sskrGenerateShares(spec, secret);\n *\n * // Combine 2 shares from the first group\n * const recoveredSecret = sskrCombineShares([shares[0][0], shares[0][1]]);\n * ```\n */\nexport function sskrCombineShares(shares: SSKRShare[]): SSKRSecret {\n  const rawShares = shares.map((share) => share.data());\n  return sskrCombine(rawShares);\n}\n","/**\n * Copyright © 2025-2026 Parity Technologies\n *\n * SSH certificate (`cert-v01@openssh.com`) placeholder — parity with\n * Rust's `bc-components-rust/src/tags_registry.rs:231-238`, which\n * registers a fixed `\"SSHCertificate\"` summarizer for\n * `TAG_SSH_TEXT_CERTIFICATE` (40803) with a `// todo: validation`\n * comment. The Rust side does *not* parse certificate fields either —\n * it only round-trips the text.\n *\n * This class therefore stores the OpenSSH certificate text verbatim\n * and defers real `cert-v01@openssh.com` parsing to v2 (`SSH_PLAN.md`\n * V2.D), only contingent on Rust gaining a real parser upstream.\n */\n\nimport { sha256 } from \"@noble/hashes/sha2.js\";\n\nexport class SSHCertificate {\n  /** The full single-line OpenSSH cert text, e.g.\n   *  `ssh-ed25519-cert-v01@openssh.com AAAAI...== user@host`. */\n  readonly text: string;\n\n  private constructor(text: string) {\n    this.text = text;\n  }\n\n  /** Construct from the canonical OpenSSH certificate text. */\n  static fromText(text: string): SSHCertificate {\n    const trimmed = text.trim();\n    if (trimmed.length === 0) {\n      throw new Error(\"SSHCertificate: empty input\");\n    }\n    return new SSHCertificate(trimmed);\n  }\n\n  /** The canonical OpenSSH text — round-trips byte-identically. */\n  toText(): string {\n    return this.text;\n  }\n\n  /** Fixed summarizer string — matches Rust `tags_registry.rs:236`. */\n  toString(): string {\n    return \"SSHCertificate\";\n  }\n\n  digest(): Uint8Array {\n    return sha256(new TextEncoder().encode(this.text));\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAY,YAAL,yBAAA,WAAA;;CAEL,UAAA,iBAAA;;CAEA,UAAA,iBAAA;;CAEA,UAAA,kBAAA;;CAEA,UAAA,YAAA;;CAEA,UAAA,UAAA;;CAEA,UAAA,UAAA;;CAEA,UAAA,SAAA;;CAEA,UAAA,SAAA;;CAEA,UAAA,iBAAA;;CAEA,UAAA,iBAAA;;CAEA,UAAA,mBAAA;;CAEA,UAAA,cAAA;;CAEA,UAAA,SAAA;;CAEA,UAAA,UAAA;;CAEA,UAAA,SAAA;;CAEA,UAAA,oBAAA;;CAEA,UAAA,aAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;;;AA2DA,IAAa,cAAb,MAAa,oBAAoB,MAAM;;CAErC;;CAGA;CAEA,YAAoB,SAAiB,WAAsB;EACzD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,YAAY,UAAU;EAC3B,KAAK,YAAY;EAGjB,MAAM,sBAAsB;EAG5B,IAAI,OAAO,oBAAoB,sBAAsB,YACnD,oBAAoB,kBAAkB,MAAM,WAAW;CAE3D;;;;;;;;;CAcA,OAAO,YAAY,UAAkB,QAA6B;EAChE,OAAO,YAAY,mBAAmB,QAAQ,UAAU,MAAM;CAChE;;;;;;;;;;CAWA,OAAO,mBAAmB,UAAkB,UAAkB,QAA6B;EACzF,OAAO,IAAI,YAAY,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