@bcts/components 1.0.0-alpha.5 → 1.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -709
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.iife.js +3 -711
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +1 -708
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Digest","TAG_NONCE","cbor","TAG_SALT","cbor","TAG_SEED","TAG_SEED_V1","createdAt: Date | undefined","metadata: SeedMetadata | undefined","cbor","_exhaustive: never","TAG_ARID","cbor","TAG_UUID","cbor","TAG_XID","cbor","TAG_URI","TAG_X25519_PUBLIC_KEY","cbor","cbor","TAG_ENCRYPTED","elements: Cbor[]","TAG_SYMMETRIC_KEY","cbor","e: unknown","TAG_X25519_PRIVATE_KEY","cbor","u64.add3L","u64.add3H","u64.rotr32H","u64.rotr32L","u64.add","u64.rotrSH","u64.rotrSL","u64.rotrBH","u64.rotrBL","u64.fromBig","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_SIGNATURE","TAG_SIGNING_PUBLIC_KEY","TAG_SIGNING_PRIVATE_KEY","TAG_X25519_PUBLIC_KEY","TAG_X25519_PUBLIC_KEY","TAG_X25519_PRIVATE_KEY","TAG_SEALED_MESSAGE","params: KeyDerivationParams","TAG_ENCRYPTED_KEY","TAG_PUBLIC_KEYS","TAG_PRIVATE_KEYS","TAG_PRIVATE_KEY_BASE","TAG_SSKR_SHARE","TAG_SSKR_SHARE_V1","TAG_MLDSA_PUBLIC_KEY","TAG_MLDSA_SIGNATURE","TAG_MLDSA_PRIVATE_KEY","TAG_MLKEM_CIPHERTEXT","TAG_MLKEM_PUBLIC_KEY","TAG_MLKEM_PRIVATE_KEY"],"sources":["../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/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/ed25519/ed25519-public-key.ts","../src/ed25519/ed25519-private-key.ts","../../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js","../../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/_blake.js","../../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js","../../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/blake2.js","../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/signing/signature.ts","../src/signing/signing-public-key.ts","../src/signing/signing-private-key.ts","../src/signing/signature-scheme.ts","../src/encapsulation/encapsulation-ciphertext.ts","../src/encapsulation/encapsulation-public-key.ts","../src/encapsulation/encapsulation-private-key.ts","../src/encapsulation/encapsulation-scheme.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/key-derivation-params.ts","../src/encrypted-key/encrypted-key.ts","../src/public-keys.ts","../src/private-keys.ts","../src/private-key-base.ts","../src/sskr.ts","../src/mldsa/mldsa-level.ts","../src/mldsa/mldsa-public-key.ts","../src/mldsa/mldsa-signature.ts","../src/mldsa/mldsa-private-key.ts","../src/mlkem/mlkem-level.ts","../src/mlkem/mlkem-ciphertext.ts","../src/mlkem/mlkem-public-key.ts","../src/mlkem/mlkem-private-key.ts"],"sourcesContent":["/**\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 type { 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 async function digestFromBytes(data: Uint8Array): Promise<Digest> {\n // Dynamic import to avoid circular dependency\n const { Digest } = await import(\"./digest.js\");\n return Digest.fromImage(data);\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 * 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 * 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\";\n\nconst MIN_SEED_SIZE = 16;\n\nexport interface SeedMetadata {\n name?: string;\n note?: string;\n createdAt?: Date;\n}\n\nexport class Seed implements CborTaggedEncodable, CborTaggedDecodable<Seed>, UREncodable {\n // Defensive copy: internal data is never exposed directly to prevent external mutation\n private readonly data: Uint8Array;\n private metadata: SeedMetadata | undefined;\n\n private constructor(data: Uint8Array, metadata?: SeedMetadata) {\n if (data.length < MIN_SEED_SIZE) {\n throw CryptoError.invalidSize(MIN_SEED_SIZE, data.length);\n }\n // Defensive copy on construction to ensure immutability of internal state\n this.data = new Uint8Array(data);\n this.metadata = metadata;\n }\n\n /**\n * Create a Seed from raw bytes.\n *\n * Note: The input data is copied to prevent external mutation of the seed's internal state.\n */\n static from(data: Uint8Array, metadata?: SeedMetadata): Seed {\n return new Seed(new Uint8Array(data), metadata);\n }\n\n /**\n * Create a Seed from hex string\n */\n static fromHex(hex: string, metadata?: SeedMetadata): Seed {\n return new Seed(hexToBytes(hex), metadata);\n }\n\n /**\n * Generate a random seed with specified size\n */\n static random(size = 32, metadata?: SeedMetadata): Seed {\n if (size < MIN_SEED_SIZE) {\n throw CryptoError.invalidSize(MIN_SEED_SIZE, size);\n }\n const rng = new SecureRandomNumberGenerator();\n return new Seed(rng.randomData(size), metadata);\n }\n\n /**\n * Generate a random seed using provided RNG\n */\n static randomUsing(rng: SecureRandomNumberGenerator, size = 32, metadata?: SeedMetadata): Seed {\n if (size < MIN_SEED_SIZE) {\n throw CryptoError.invalidSize(MIN_SEED_SIZE, size);\n }\n return new Seed(rng.randomData(size), metadata);\n }\n\n /**\n * Get the raw seed bytes.\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 * Get name\n */\n name(): string | undefined {\n return this.metadata?.name;\n }\n\n /**\n * Set name\n */\n setName(name: string): void {\n this.metadata ??= {};\n this.metadata.name = name;\n }\n\n /**\n * Get note\n */\n note(): string | undefined {\n return this.metadata?.note;\n }\n\n /**\n * Set note\n */\n setNote(note: string): void {\n this.metadata ??= {};\n this.metadata.note = note;\n }\n\n /**\n * Get creation date\n */\n createdAt(): Date | undefined {\n return this.metadata?.createdAt;\n }\n\n /**\n * Set creation date\n */\n setCreatedAt(date: Date): void {\n this.metadata ??= {};\n this.metadata.createdAt = date;\n }\n\n /**\n * Get metadata\n */\n getMetadata(): SeedMetadata | undefined {\n return this.metadata !== undefined ? { ...this.metadata } : undefined;\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 // 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.metadata?.createdAt !== undefined) {\n const cborDate = CborDate.fromDatetime(this.metadata.createdAt);\n map.insert(2, cborDate.taggedCbor());\n }\n if (this.metadata?.name !== undefined && this.metadata.name.length > 0) {\n map.insert(3, this.metadata.name);\n }\n if (this.metadata?.note !== undefined && this.metadata.note.length > 0) {\n map.insert(4, this.metadata.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 createdAt: 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 createdAt = 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 let metadata: SeedMetadata | undefined;\n if (name !== undefined || note !== undefined || createdAt !== undefined) {\n metadata = {};\n if (name !== undefined) metadata.name = name;\n if (note !== undefined) metadata.note = note;\n if (createdAt !== undefined) metadata.createdAt = createdAt;\n }\n\n return Seed.from(new Uint8Array(data), metadata);\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(cbor: Cbor): Seed {\n const instance = Seed.random(MIN_SEED_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): Seed {\n const cbor = decodeCbor(data);\n return Seed.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from untagged CBOR binary data.\n */\n static fromUntaggedCborData(data: Uint8Array): Seed {\n const cbor = decodeCbor(data);\n const instance = Seed.random(MIN_SEED_SIZE);\n return instance.fromUntaggedCbor(cbor);\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.random(MIN_SEED_SIZE);\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 * Content-addressable reference - SHA-256 digest with short reference encoding\n */\n\nimport { Digest } from \"./digest.js\";\nimport { CryptoError } from \"./error.js\";\n\nexport type ReferenceEncodingFormat = \"hex\" | \"bytewords\" | \"bytemojis\";\n\n// Bytewords mapping (256 words)\nconst BYTEWORDS = [\n \"abled\",\n \"ache\",\n \"acid\",\n \"acme\",\n \"acre\",\n \"aged\",\n \"aide\",\n \"airy\",\n \"ajar\",\n \"akin\",\n \"alas\",\n \"alba\",\n \"alee\",\n \"alms\",\n \"aloe\",\n \"also\",\n \"ante\",\n \"anti\",\n \"ants\",\n \"anus\",\n \"anus\",\n \"apes\",\n \"apex\",\n \"apse\",\n \"arch\",\n \"area\",\n \"ares\",\n \"aria\",\n \"arid\",\n \"ark\",\n \"arms\",\n \"army\",\n // ... (256 total - abbreviated for space)\n];\n\n// Bytemojis mapping (256 emojis)\nconst BYTEMOJIS = [\n \"😀\",\n \"😂\",\n \"😆\",\n \"😉\",\n \"😊\",\n \"😌\",\n \"😎\",\n \"😏\",\n \"😑\",\n \"😒\",\n \"😓\",\n \"😔\",\n \"😕\",\n \"😖\",\n \"😗\",\n \"😘\",\n // ... (256 total - abbreviated for space)\n];\n\nexport class Reference {\n private readonly digest: Digest;\n\n private constructor(digest: Digest) {\n this.digest = digest;\n }\n\n /**\n * Create a Reference from a Digest\n */\n static from(digest: Digest): Reference {\n return new Reference(digest);\n }\n\n /**\n * Create a Reference from hex string\n */\n static fromHex(hex: string): Reference {\n const digest = Digest.fromHex(hex);\n return new Reference(digest);\n }\n\n /**\n * Generate a Reference from data\n */\n static hash(data: Uint8Array): Reference {\n const digest = Digest.hash(data);\n return new Reference(digest);\n }\n\n /**\n * Get the underlying Digest\n */\n getDigest(): Digest {\n return this.digest;\n }\n\n /**\n * Get full reference as hex string\n */\n toHex(): string {\n return this.digest.toHex();\n }\n\n /**\n * Get short reference (first 4 bytes) in various formats\n */\n shortReference(format: ReferenceEncodingFormat = \"hex\"): string {\n const data = this.digest.toData();\n const shortData = data.slice(0, 4);\n\n switch (format) {\n case \"hex\":\n // Lowercase hex, matching Rust implementation\n return Array.from(shortData)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n\n case \"bytewords\":\n return Array.from(shortData)\n .map((b) => BYTEWORDS[b] ?? `word${b}`)\n .join(\" \");\n\n case \"bytemojis\":\n return Array.from(shortData)\n .map((b) => BYTEMOJIS[b] ?? \"❓\")\n .join(\" \");\n\n default: {\n const _exhaustive: never = format;\n throw CryptoError.invalidFormat(`Unknown reference format: ${String(_exhaustive)}`);\n }\n }\n }\n\n /**\n * Get full reference as hex string (alias for toHex)\n */\n fullReference(): string {\n return this.toHex();\n }\n\n /**\n * Get base64 representation\n */\n toBase64(): string {\n return this.digest.toBase64();\n }\n\n /**\n * Compare with another Reference\n */\n equals(other: Reference): boolean {\n return this.digest.equals(other.digest);\n }\n\n /**\n * Get string representation\n */\n toString(): string {\n return `Reference(${this.shortReference(\"hex\")})`;\n }\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 * 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 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 < UUID_SIZE; i++) {\n data[i] = Math.floor(Math.random() * 256);\n }\n }\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 * 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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, toBase64 } from \"../utils.js\";\n\nconst XID_SIZE = 32;\n\nexport class XID implements CborTaggedEncodable, CborTaggedDecodable<XID>, UREncodable {\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 // Instance Methods\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 * 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.\n */\n toString(): string {\n return `XID(${this.toHex()})`;\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 * 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 * 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 { 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 toString(): string {\n return `X25519PublicKey(${this.toHex().substring(0, 16)}...)`;\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 * 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 * 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 * 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 { 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 * 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 * Ed25519 public key for EdDSA signature verification (32 bytes)\n * Ported from bc-components-rust/src/ed25519_public_key.rs\n */\n\nimport { ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, ed25519Verify } from \"@bcts/crypto\";\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\n */\n static from(data: Uint8Array): Ed25519PublicKey {\n return new Ed25519PublicKey(new Uint8Array(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 /**\n * Get the raw public key bytes\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 * 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 toString(): string {\n return `Ed25519PublicKey(${this.toHex().substring(0, 16)}...)`;\n }\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} 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 * Get the raw seed bytes (32 bytes)\n */\n toData(): Uint8Array {\n return new Uint8Array(this.seed);\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 * Utilities for hex, bytes, CSPRNG.\n * @module\n */\n/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */\n/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */\nexport function isBytes(a) {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n/** Asserts something is positive integer. */\nexport function anumber(n, title = '') {\n if (!Number.isSafeInteger(n) || n < 0) {\n const prefix = title && `\"${title}\" `;\n throw new Error(`${prefix}expected integer >= 0, got ${n}`);\n }\n}\n/** Asserts something is Uint8Array. */\nexport function abytes(value, length, title = '') {\n const bytes = isBytes(value);\n const len = value?.length;\n const needsLen = length !== undefined;\n if (!bytes || (needsLen && len !== length)) {\n const prefix = title && `\"${title}\" `;\n const ofLen = needsLen ? ` of length ${length}` : '';\n const got = bytes ? `length=${len}` : `type=${typeof value}`;\n throw new Error(prefix + 'expected Uint8Array' + ofLen + ', got ' + got);\n }\n return value;\n}\n/** Asserts something is hash */\nexport function ahash(h) {\n if (typeof h !== 'function' || typeof h.create !== 'function')\n throw new Error('Hash must wrapped by utils.createHasher');\n anumber(h.outputLen);\n anumber(h.blockLen);\n}\n/** Asserts a hash instance has not been destroyed / finished */\nexport function aexists(instance, checkFinished = true) {\n if (instance.destroyed)\n throw new Error('Hash instance has been destroyed');\n if (checkFinished && instance.finished)\n throw new Error('Hash#digest() has already been called');\n}\n/** Asserts output is properly-sized byte array */\nexport function aoutput(out, instance) {\n abytes(out, undefined, 'digestInto() output');\n const min = instance.outputLen;\n if (out.length < min) {\n throw new Error('\"digestInto() output\" expected to be of length >=' + min);\n }\n}\n/** Cast u8 / u16 / u32 to u8. */\nexport function u8(arr) {\n return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n/** Cast u8 / u16 / u32 to u32. */\nexport function u32(arr) {\n return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));\n}\n/** Zeroize a byte array. Warning: JS provides no guarantees. */\nexport function clean(...arrays) {\n for (let i = 0; i < arrays.length; i++) {\n arrays[i].fill(0);\n }\n}\n/** Create DataView of an array for easy byte-level manipulation. */\nexport function createView(arr) {\n return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);\n}\n/** The rotate right (circular right shift) operation for uint32 */\nexport function rotr(word, shift) {\n return (word << (32 - shift)) | (word >>> shift);\n}\n/** The rotate left (circular left shift) operation for uint32 */\nexport function rotl(word, shift) {\n return (word << shift) | ((word >>> (32 - shift)) >>> 0);\n}\n/** Is current platform little-endian? Most are. Big-Endian platform: IBM */\nexport const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();\n/** The byte swap operation for uint32 */\nexport function byteSwap(word) {\n return (((word << 24) & 0xff000000) |\n ((word << 8) & 0xff0000) |\n ((word >>> 8) & 0xff00) |\n ((word >>> 24) & 0xff));\n}\n/** Conditionally byte swap if on a big-endian platform */\nexport const swap8IfBE = isLE\n ? (n) => n\n : (n) => byteSwap(n);\n/** In place byte swap for Uint32Array */\nexport function byteSwap32(arr) {\n for (let i = 0; i < arr.length; i++) {\n arr[i] = byteSwap(arr[i]);\n }\n return arr;\n}\nexport const swap32IfBE = isLE\n ? (u) => u\n : byteSwap32;\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\nconst hasHexBuiltin = /* @__PURE__ */ (() => \n// @ts-ignore\ntypeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();\n// Array where index 0xf0 (240) is mapped to string 'f0'\nconst hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));\n/**\n * Convert byte array to hex string. Uses built-in function, when available.\n * @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'\n */\nexport function bytesToHex(bytes) {\n abytes(bytes);\n // @ts-ignore\n if (hasHexBuiltin)\n return bytes.toHex();\n // pre-caching improves the speed 6x\n let hex = '';\n for (let i = 0; i < bytes.length; i++) {\n hex += hexes[bytes[i]];\n }\n return hex;\n}\n// We use optimized technique to convert hex string to byte array\nconst asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };\nfunction asciiToBase16(ch) {\n if (ch >= asciis._0 && ch <= asciis._9)\n return ch - asciis._0; // '2' => 50-48\n if (ch >= asciis.A && ch <= asciis.F)\n return ch - (asciis.A - 10); // 'B' => 66-(65-10)\n if (ch >= asciis.a && ch <= asciis.f)\n return ch - (asciis.a - 10); // 'b' => 98-(97-10)\n return;\n}\n/**\n * Convert hex string to byte array. Uses built-in function, when available.\n * @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])\n */\nexport function hexToBytes(hex) {\n if (typeof hex !== 'string')\n throw new Error('hex string expected, got ' + typeof hex);\n // @ts-ignore\n if (hasHexBuiltin)\n return Uint8Array.fromHex(hex);\n const hl = hex.length;\n const al = hl / 2;\n if (hl % 2)\n throw new Error('hex string expected, got unpadded hex of length ' + hl);\n const array = new Uint8Array(al);\n for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {\n const n1 = asciiToBase16(hex.charCodeAt(hi));\n const n2 = asciiToBase16(hex.charCodeAt(hi + 1));\n if (n1 === undefined || n2 === undefined) {\n const char = hex[hi] + hex[hi + 1];\n throw new Error('hex string expected, got non-hex character \"' + char + '\" at index ' + hi);\n }\n array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163\n }\n return array;\n}\n/**\n * There is no setImmediate in browser and setTimeout is slow.\n * Call of async fn will return Promise, which will be fullfiled only on\n * next scheduler queue processing step and this is exactly what we need.\n */\nexport const nextTick = async () => { };\n/** Returns control to thread each 'tick' ms to avoid blocking. */\nexport async function asyncLoop(iters, tick, cb) {\n let ts = Date.now();\n for (let i = 0; i < iters; i++) {\n cb(i);\n // Date.now() is not monotonic, so in case if clock goes backwards we return return control too\n const diff = Date.now() - ts;\n if (diff >= 0 && diff < tick)\n continue;\n await nextTick();\n ts += diff;\n }\n}\n/**\n * Converts string to bytes using UTF8 encoding.\n * Built-in doesn't validate input to be string: we do the check.\n * @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])\n */\nexport function utf8ToBytes(str) {\n if (typeof str !== 'string')\n throw new Error('string expected');\n return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809\n}\n/**\n * Helper for KDFs: consumes uint8array or string.\n * When string is passed, does utf8 decoding, using TextDecoder.\n */\nexport function kdfInputToBytes(data, errorTitle = '') {\n if (typeof data === 'string')\n return utf8ToBytes(data);\n return abytes(data, undefined, errorTitle);\n}\n/** Copies several Uint8Arrays into one. */\nexport function concatBytes(...arrays) {\n let sum = 0;\n for (let i = 0; i < arrays.length; i++) {\n const a = arrays[i];\n abytes(a);\n sum += a.length;\n }\n const res = new Uint8Array(sum);\n for (let i = 0, pad = 0; i < arrays.length; i++) {\n const a = arrays[i];\n res.set(a, pad);\n pad += a.length;\n }\n return res;\n}\n/** Merges default options and passed options. */\nexport function checkOpts(defaults, opts) {\n if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')\n throw new Error('options must be object or undefined');\n const merged = Object.assign(defaults, opts);\n return merged;\n}\n/** Creates function with outputLen, blockLen, create properties from a class constructor. */\nexport function createHasher(hashCons, info = {}) {\n const hashC = (msg, opts) => hashCons(opts).update(msg).digest();\n const tmp = hashCons(undefined);\n hashC.outputLen = tmp.outputLen;\n hashC.blockLen = tmp.blockLen;\n hashC.create = (opts) => hashCons(opts);\n Object.assign(hashC, info);\n return Object.freeze(hashC);\n}\n/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */\nexport function randomBytes(bytesLength = 32) {\n const cr = typeof globalThis === 'object' ? globalThis.crypto : null;\n if (typeof cr?.getRandomValues !== 'function')\n throw new Error('crypto.getRandomValues must be defined');\n return cr.getRandomValues(new Uint8Array(bytesLength));\n}\n/** Creates OID opts for NIST hashes, with prefix 06 09 60 86 48 01 65 03 04 02. */\nexport const oidNist = (suffix) => ({\n oid: Uint8Array.from([0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, suffix]),\n});\n//# sourceMappingURL=utils.js.map","/**\n * Internal helpers for blake hash.\n * @module\n */\nimport { rotr } from \"./utils.js\";\n/**\n * Internal blake variable.\n * For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].\n */\n// prettier-ignore\nexport const BSIGMA = /* @__PURE__ */ Uint8Array.from([\n 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\n 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,\n 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,\n 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,\n 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,\n 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,\n 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,\n 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,\n 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,\n 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,\n 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,\n 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,\n // Blake1, unused in others\n 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,\n 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,\n 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,\n 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,\n]);\n// Mixing function G splitted in two halfs\nexport function G1s(a, b, c, d, x) {\n a = (a + b + x) | 0;\n d = rotr(d ^ a, 16);\n c = (c + d) | 0;\n b = rotr(b ^ c, 12);\n return { a, b, c, d };\n}\nexport function G2s(a, b, c, d, x) {\n a = (a + b + x) | 0;\n d = rotr(d ^ a, 8);\n c = (c + d) | 0;\n b = rotr(b ^ c, 7);\n return { a, b, c, d };\n}\n//# sourceMappingURL=_blake.js.map","/**\n * Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.\n * @todo re-check https://issues.chromium.org/issues/42212588\n * @module\n */\nconst U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);\nconst _32n = /* @__PURE__ */ BigInt(32);\nfunction fromBig(n, le = false) {\n if (le)\n return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };\n return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };\n}\nfunction split(lst, le = false) {\n const len = lst.length;\n let Ah = new Uint32Array(len);\n let Al = new Uint32Array(len);\n for (let i = 0; i < len; i++) {\n const { h, l } = fromBig(lst[i], le);\n [Ah[i], Al[i]] = [h, l];\n }\n return [Ah, Al];\n}\nconst toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);\n// for Shift in [0, 32)\nconst shrSH = (h, _l, s) => h >>> s;\nconst shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in [1, 32)\nconst rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));\nconst rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);\n// Right rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));\nconst rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));\n// Right rotate for shift===32 (just swaps l&h)\nconst rotr32H = (_h, l) => l;\nconst rotr32L = (h, _l) => h;\n// Left rotate for Shift in [1, 32)\nconst rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));\nconst rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));\n// Left rotate for Shift in (32, 64), NOTE: 32 is special case.\nconst rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));\nconst rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));\n// JS uses 32-bit signed integers for bitwise operations which means we cannot\n// simple take carry out of low bit sum by shift, we need to use division.\nfunction add(Ah, Al, Bh, Bl) {\n const l = (Al >>> 0) + (Bl >>> 0);\n return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };\n}\n// Addition with more than 2 elements\nconst add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);\nconst add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;\nconst add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);\nconst add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;\nconst add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);\nconst add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;\n// prettier-ignore\nexport { add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, rotlBH, rotlBL, rotlSH, rotlSL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, shrSH, shrSL, split, toBig };\n// prettier-ignore\nconst u64 = {\n fromBig, split, toBig,\n shrSH, shrSL,\n rotrSH, rotrSL, rotrBH, rotrBL,\n rotr32H, rotr32L,\n rotlSH, rotlSL, rotlBH, rotlBL,\n add, add3L, add3H, add4L, add4H, add5H, add5L,\n};\nexport default u64;\n//# sourceMappingURL=_u64.js.map","/**\n * blake2b (64-bit) & blake2s (8 to 32-bit) hash functions.\n * b could have been faster, but there is no fast u64 in js, so s is 1.5x faster.\n * @module\n */\nimport { BSIGMA, G1s, G2s } from \"./_blake.js\";\nimport { SHA256_IV } from \"./_md.js\";\nimport * as u64 from \"./_u64.js\";\n// prettier-ignore\nimport { abytes, aexists, anumber, aoutput, clean, createHasher, swap32IfBE, swap8IfBE, u32 } from \"./utils.js\";\n// Same as SHA512_IV, but swapped endianness: LE instead of BE. iv[1] is iv[0], etc.\nconst B2B_IV = /* @__PURE__ */ Uint32Array.from([\n 0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85, 0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,\n 0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c, 0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19,\n]);\n// Temporary buffer\nconst BBUF = /* @__PURE__ */ new Uint32Array(32);\n// Mixing function G splitted in two halfs\nfunction G1b(a, b, c, d, msg, x) {\n // NOTE: V is LE here\n const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore\n let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1]; // prettier-ignore\n let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1]; // prettier-ignore\n let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1]; // prettier-ignore\n let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1]; // prettier-ignore\n // v[a] = (v[a] + v[b] + x) | 0;\n let ll = u64.add3L(Al, Bl, Xl);\n Ah = u64.add3H(ll, Ah, Bh, Xh);\n Al = ll | 0;\n // v[d] = rotr(v[d] ^ v[a], 32)\n ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });\n ({ Dh, Dl } = { Dh: u64.rotr32H(Dh, Dl), Dl: u64.rotr32L(Dh, Dl) });\n // v[c] = (v[c] + v[d]) | 0;\n ({ h: Ch, l: Cl } = u64.add(Ch, Cl, Dh, Dl));\n // v[b] = rotr(v[b] ^ v[c], 24)\n ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });\n ({ Bh, Bl } = { Bh: u64.rotrSH(Bh, Bl, 24), Bl: u64.rotrSL(Bh, Bl, 24) });\n ((BBUF[2 * a] = Al), (BBUF[2 * a + 1] = Ah));\n ((BBUF[2 * b] = Bl), (BBUF[2 * b + 1] = Bh));\n ((BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch));\n ((BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh));\n}\nfunction G2b(a, b, c, d, msg, x) {\n // NOTE: V is LE here\n const Xl = msg[x], Xh = msg[x + 1]; // prettier-ignore\n let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1]; // prettier-ignore\n let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1]; // prettier-ignore\n let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1]; // prettier-ignore\n let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1]; // prettier-ignore\n // v[a] = (v[a] + v[b] + x) | 0;\n let ll = u64.add3L(Al, Bl, Xl);\n Ah = u64.add3H(ll, Ah, Bh, Xh);\n Al = ll | 0;\n // v[d] = rotr(v[d] ^ v[a], 16)\n ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });\n ({ Dh, Dl } = { Dh: u64.rotrSH(Dh, Dl, 16), Dl: u64.rotrSL(Dh, Dl, 16) });\n // v[c] = (v[c] + v[d]) | 0;\n ({ h: Ch, l: Cl } = u64.add(Ch, Cl, Dh, Dl));\n // v[b] = rotr(v[b] ^ v[c], 63)\n ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });\n ({ Bh, Bl } = { Bh: u64.rotrBH(Bh, Bl, 63), Bl: u64.rotrBL(Bh, Bl, 63) });\n ((BBUF[2 * a] = Al), (BBUF[2 * a + 1] = Ah));\n ((BBUF[2 * b] = Bl), (BBUF[2 * b + 1] = Bh));\n ((BBUF[2 * c] = Cl), (BBUF[2 * c + 1] = Ch));\n ((BBUF[2 * d] = Dl), (BBUF[2 * d + 1] = Dh));\n}\nfunction checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {\n anumber(keyLen);\n if (outputLen < 0 || outputLen > keyLen)\n throw new Error('outputLen bigger than keyLen');\n const { key, salt, personalization } = opts;\n if (key !== undefined && (key.length < 1 || key.length > keyLen))\n throw new Error('\"key\" expected to be undefined or of length=1..' + keyLen);\n if (salt !== undefined)\n abytes(salt, saltLen, 'salt');\n if (personalization !== undefined)\n abytes(personalization, persLen, 'personalization');\n}\n/** Internal base class for BLAKE2. */\nexport class _BLAKE2 {\n buffer;\n buffer32;\n finished = false;\n destroyed = false;\n length = 0;\n pos = 0;\n blockLen;\n outputLen;\n constructor(blockLen, outputLen) {\n anumber(blockLen);\n anumber(outputLen);\n this.blockLen = blockLen;\n this.outputLen = outputLen;\n this.buffer = new Uint8Array(blockLen);\n this.buffer32 = u32(this.buffer);\n }\n update(data) {\n aexists(this);\n abytes(data);\n // Main difference with other hashes: there is flag for last block,\n // so we cannot process current block before we know that there\n // is the next one. This significantly complicates logic and reduces ability\n // to do zero-copy processing\n const { blockLen, buffer, buffer32 } = this;\n const len = data.length;\n const offset = data.byteOffset;\n const buf = data.buffer;\n for (let pos = 0; pos < len;) {\n // If buffer is full and we still have input (don't process last block, same as blake2s)\n if (this.pos === blockLen) {\n swap32IfBE(buffer32);\n this.compress(buffer32, 0, false);\n swap32IfBE(buffer32);\n this.pos = 0;\n }\n const take = Math.min(blockLen - this.pos, len - pos);\n const dataOffset = offset + pos;\n // full block && aligned to 4 bytes && not last in input\n if (take === blockLen && !(dataOffset % 4) && pos + take < len) {\n const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));\n swap32IfBE(data32);\n for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {\n this.length += blockLen;\n this.compress(data32, pos32, false);\n }\n swap32IfBE(data32);\n continue;\n }\n buffer.set(data.subarray(pos, pos + take), this.pos);\n this.pos += take;\n this.length += take;\n pos += take;\n }\n return this;\n }\n digestInto(out) {\n aexists(this);\n aoutput(out, this);\n const { pos, buffer32 } = this;\n this.finished = true;\n // Padding\n clean(this.buffer.subarray(pos));\n swap32IfBE(buffer32);\n this.compress(buffer32, 0, true);\n swap32IfBE(buffer32);\n const out32 = u32(out);\n this.get().forEach((v, i) => (out32[i] = swap8IfBE(v)));\n }\n digest() {\n const { buffer, outputLen } = this;\n this.digestInto(buffer);\n const res = buffer.slice(0, outputLen);\n this.destroy();\n return res;\n }\n _cloneInto(to) {\n const { buffer, length, finished, destroyed, outputLen, pos } = this;\n to ||= new this.constructor({ dkLen: outputLen });\n to.set(...this.get());\n to.buffer.set(buffer);\n to.destroyed = destroyed;\n to.finished = finished;\n to.length = length;\n to.pos = pos;\n // @ts-ignore\n to.outputLen = outputLen;\n return to;\n }\n clone() {\n return this._cloneInto();\n }\n}\n/** Internal blake2b hash class. */\nexport class _BLAKE2b extends _BLAKE2 {\n // Same as SHA-512, but LE\n v0l = B2B_IV[0] | 0;\n v0h = B2B_IV[1] | 0;\n v1l = B2B_IV[2] | 0;\n v1h = B2B_IV[3] | 0;\n v2l = B2B_IV[4] | 0;\n v2h = B2B_IV[5] | 0;\n v3l = B2B_IV[6] | 0;\n v3h = B2B_IV[7] | 0;\n v4l = B2B_IV[8] | 0;\n v4h = B2B_IV[9] | 0;\n v5l = B2B_IV[10] | 0;\n v5h = B2B_IV[11] | 0;\n v6l = B2B_IV[12] | 0;\n v6h = B2B_IV[13] | 0;\n v7l = B2B_IV[14] | 0;\n v7h = B2B_IV[15] | 0;\n constructor(opts = {}) {\n const olen = opts.dkLen === undefined ? 64 : opts.dkLen;\n super(128, olen);\n checkBlake2Opts(olen, opts, 64, 16, 16);\n let { key, personalization, salt } = opts;\n let keyLength = 0;\n if (key !== undefined) {\n abytes(key, undefined, 'key');\n keyLength = key.length;\n }\n this.v0l ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);\n if (salt !== undefined) {\n abytes(salt, undefined, 'salt');\n const slt = u32(salt);\n this.v4l ^= swap8IfBE(slt[0]);\n this.v4h ^= swap8IfBE(slt[1]);\n this.v5l ^= swap8IfBE(slt[2]);\n this.v5h ^= swap8IfBE(slt[3]);\n }\n if (personalization !== undefined) {\n abytes(personalization, undefined, 'personalization');\n const pers = u32(personalization);\n this.v6l ^= swap8IfBE(pers[0]);\n this.v6h ^= swap8IfBE(pers[1]);\n this.v7l ^= swap8IfBE(pers[2]);\n this.v7h ^= swap8IfBE(pers[3]);\n }\n if (key !== undefined) {\n // Pad to blockLen and update\n const tmp = new Uint8Array(this.blockLen);\n tmp.set(key);\n this.update(tmp);\n }\n }\n // prettier-ignore\n get() {\n let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;\n return [v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h];\n }\n // prettier-ignore\n set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {\n this.v0l = v0l | 0;\n this.v0h = v0h | 0;\n this.v1l = v1l | 0;\n this.v1h = v1h | 0;\n this.v2l = v2l | 0;\n this.v2h = v2h | 0;\n this.v3l = v3l | 0;\n this.v3h = v3h | 0;\n this.v4l = v4l | 0;\n this.v4h = v4h | 0;\n this.v5l = v5l | 0;\n this.v5h = v5h | 0;\n this.v6l = v6l | 0;\n this.v6h = v6h | 0;\n this.v7l = v7l | 0;\n this.v7h = v7h | 0;\n }\n compress(msg, offset, isLast) {\n this.get().forEach((v, i) => (BBUF[i] = v)); // First half from state.\n BBUF.set(B2B_IV, 16); // Second half from IV.\n let { h, l } = u64.fromBig(BigInt(this.length));\n BBUF[24] = B2B_IV[8] ^ l; // Low word of the offset.\n BBUF[25] = B2B_IV[9] ^ h; // High word.\n // Invert all bits for last block\n if (isLast) {\n BBUF[28] = ~BBUF[28];\n BBUF[29] = ~BBUF[29];\n }\n let j = 0;\n const s = BSIGMA;\n for (let i = 0; i < 12; i++) {\n G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);\n G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);\n G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);\n G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);\n G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);\n G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);\n G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);\n G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);\n G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);\n G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);\n G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);\n G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);\n G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);\n G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);\n G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);\n G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);\n }\n this.v0l ^= BBUF[0] ^ BBUF[16];\n this.v0h ^= BBUF[1] ^ BBUF[17];\n this.v1l ^= BBUF[2] ^ BBUF[18];\n this.v1h ^= BBUF[3] ^ BBUF[19];\n this.v2l ^= BBUF[4] ^ BBUF[20];\n this.v2h ^= BBUF[5] ^ BBUF[21];\n this.v3l ^= BBUF[6] ^ BBUF[22];\n this.v3h ^= BBUF[7] ^ BBUF[23];\n this.v4l ^= BBUF[8] ^ BBUF[24];\n this.v4h ^= BBUF[9] ^ BBUF[25];\n this.v5l ^= BBUF[10] ^ BBUF[26];\n this.v5h ^= BBUF[11] ^ BBUF[27];\n this.v6l ^= BBUF[12] ^ BBUF[28];\n this.v6h ^= BBUF[13] ^ BBUF[29];\n this.v7l ^= BBUF[14] ^ BBUF[30];\n this.v7h ^= BBUF[15] ^ BBUF[31];\n clean(BBUF);\n }\n destroy() {\n this.destroyed = true;\n clean(this.buffer32);\n this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);\n }\n}\n/**\n * Blake2b hash function. 64-bit. 1.5x slower than blake2s in JS.\n * @param msg - message that would be hashed\n * @param opts - dkLen output length, key for MAC mode, salt, personalization\n */\nexport const blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));\n/** BLAKE2-compress core method. */\n// prettier-ignore\nexport function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {\n let j = 0;\n for (let i = 0; i < rounds; i++) {\n ({ a: v0, b: v4, c: v8, d: v12 } = G1s(v0, v4, v8, v12, msg[offset + s[j++]]));\n ({ a: v0, b: v4, c: v8, d: v12 } = G2s(v0, v4, v8, v12, msg[offset + s[j++]]));\n ({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));\n ({ a: v1, b: v5, c: v9, d: v13 } = G2s(v1, v5, v9, v13, msg[offset + s[j++]]));\n ({ a: v2, b: v6, c: v10, d: v14 } = G1s(v2, v6, v10, v14, msg[offset + s[j++]]));\n ({ a: v2, b: v6, c: v10, d: v14 } = G2s(v2, v6, v10, v14, msg[offset + s[j++]]));\n ({ a: v3, b: v7, c: v11, d: v15 } = G1s(v3, v7, v11, v15, msg[offset + s[j++]]));\n ({ a: v3, b: v7, c: v11, d: v15 } = G2s(v3, v7, v11, v15, msg[offset + s[j++]]));\n ({ a: v0, b: v5, c: v10, d: v15 } = G1s(v0, v5, v10, v15, msg[offset + s[j++]]));\n ({ a: v0, b: v5, c: v10, d: v15 } = G2s(v0, v5, v10, v15, msg[offset + s[j++]]));\n ({ a: v1, b: v6, c: v11, d: v12 } = G1s(v1, v6, v11, v12, msg[offset + s[j++]]));\n ({ a: v1, b: v6, c: v11, d: v12 } = G2s(v1, v6, v11, v12, msg[offset + s[j++]]));\n ({ a: v2, b: v7, c: v8, d: v13 } = G1s(v2, v7, v8, v13, msg[offset + s[j++]]));\n ({ a: v2, b: v7, c: v8, d: v13 } = G2s(v2, v7, v8, v13, msg[offset + s[j++]]));\n ({ a: v3, b: v4, c: v9, d: v14 } = G1s(v3, v4, v9, v14, msg[offset + s[j++]]));\n ({ a: v3, b: v4, c: v9, d: v14 } = G2s(v3, v4, v9, v14, msg[offset + s[j++]]));\n }\n return { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 };\n}\nconst B2S_IV = /* @__PURE__ */ SHA256_IV.slice();\n/** Internal blake2s hash class. */\nexport class _BLAKE2s extends _BLAKE2 {\n // Internal state, same as SHA-256\n v0 = B2S_IV[0] | 0;\n v1 = B2S_IV[1] | 0;\n v2 = B2S_IV[2] | 0;\n v3 = B2S_IV[3] | 0;\n v4 = B2S_IV[4] | 0;\n v5 = B2S_IV[5] | 0;\n v6 = B2S_IV[6] | 0;\n v7 = B2S_IV[7] | 0;\n constructor(opts = {}) {\n const olen = opts.dkLen === undefined ? 32 : opts.dkLen;\n super(64, olen);\n checkBlake2Opts(olen, opts, 32, 8, 8);\n let { key, personalization, salt } = opts;\n let keyLength = 0;\n if (key !== undefined) {\n abytes(key, undefined, 'key');\n keyLength = key.length;\n }\n this.v0 ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);\n if (salt !== undefined) {\n abytes(salt, undefined, 'salt');\n const slt = u32(salt);\n this.v4 ^= swap8IfBE(slt[0]);\n this.v5 ^= swap8IfBE(slt[1]);\n }\n if (personalization !== undefined) {\n abytes(personalization, undefined, 'personalization');\n const pers = u32(personalization);\n this.v6 ^= swap8IfBE(pers[0]);\n this.v7 ^= swap8IfBE(pers[1]);\n }\n if (key !== undefined) {\n // Pad to blockLen and update\n const tmp = new Uint8Array(this.blockLen);\n tmp.set(key);\n this.update(tmp);\n }\n }\n get() {\n const { v0, v1, v2, v3, v4, v5, v6, v7 } = this;\n return [v0, v1, v2, v3, v4, v5, v6, v7];\n }\n // prettier-ignore\n set(v0, v1, v2, v3, v4, v5, v6, v7) {\n this.v0 = v0 | 0;\n this.v1 = v1 | 0;\n this.v2 = v2 | 0;\n this.v3 = v3 | 0;\n this.v4 = v4 | 0;\n this.v5 = v5 | 0;\n this.v6 = v6 | 0;\n this.v7 = v7 | 0;\n }\n compress(msg, offset, isLast) {\n const { h, l } = u64.fromBig(BigInt(this.length));\n // prettier-ignore\n const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(BSIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, B2S_IV[0], B2S_IV[1], B2S_IV[2], B2S_IV[3], l ^ B2S_IV[4], h ^ B2S_IV[5], isLast ? ~B2S_IV[6] : B2S_IV[6], B2S_IV[7]);\n this.v0 ^= v0 ^ v8;\n this.v1 ^= v1 ^ v9;\n this.v2 ^= v2 ^ v10;\n this.v3 ^= v3 ^ v11;\n this.v4 ^= v4 ^ v12;\n this.v5 ^= v5 ^ v13;\n this.v6 ^= v6 ^ v14;\n this.v7 ^= v7 ^ v15;\n }\n destroy() {\n this.destroyed = true;\n clean(this.buffer32);\n this.set(0, 0, 0, 0, 0, 0, 0, 0);\n }\n}\n/**\n * Blake2s hash function. Focuses on 8-bit to 32-bit platforms. 1.5x faster than blake2b in JS.\n * @param msg - message that would be hashed\n * @param opts - dkLen output length, key for MAC mode, salt, personalization\n */\nexport const blake2s = /* @__PURE__ */ createHasher((opts) => new _BLAKE2s(opts));\n//# sourceMappingURL=blake2.js.map","/**\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 } from \"../utils.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 * Note: The @scure/sr25519 library uses a hardcoded \"substrate\" context.\n * Custom context is accepted for API compatibility but only signatures created\n * with \"substrate\" context will verify correctly.\n *\n * @param signature - The 64-byte signature\n * @param message - The message that was signed\n * @param context - The signing context (only \"substrate\" is supported)\n * @returns true if the signature is valid\n */\n verifyWithContext(signature: Uint8Array, message: Uint8Array, _context: Uint8Array): boolean {\n try {\n // Note: @scure/sr25519 verify() uses hardcoded \"substrate\" context\n // Arguments: verify(message, signature, publicKey)\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 * 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 } from \"../utils.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 * Note: The @scure/sr25519 library uses a hardcoded \"substrate\" context.\n * Custom context is accepted for API compatibility but only \"substrate\" context\n * will produce signatures verifiable by this library.\n *\n * @param message - The message to sign\n * @param context - The signing context (only \"substrate\" is supported)\n * @returns 64-byte signature\n */\n signWithContext(message: Uint8Array, _context: Uint8Array): Uint8Array {\n const secretKey = sr25519.secretFromSeed(this._seed);\n // Note: @scure/sr25519 sign() uses hardcoded \"substrate\" context\n // Arguments: sign(secretKey, message, random?)\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 * 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\";\n\n// Note: ECPublicKey type is used in JSDoc comments but not directly imported\n// to avoid circular dependency issues\n\nexport class ECUncompressedPublicKey\n implements CborTaggedEncodable, CborTaggedDecodable<ECUncompressedPublicKey>, 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 * 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\";\n\nexport class ECPublicKey\n implements 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 * 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 * 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 { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class SchnorrPublicKey {\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 toString(): string {\n return `SchnorrPublicKey(${this.toHex().substring(0, 16)}...)`;\n }\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\";\n\nexport class ECPrivateKey\n implements 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 * A digital signature created with various signature algorithms.\n *\n * `Signature` represents different types of digital signatures.\n * Currently, only Ed25519 signatures are implemented (64 bytes).\n *\n * Signatures can be serialized to and from CBOR with tag 40020.\n *\n * # CBOR Serialization\n *\n * The CBOR encoding for Ed25519 signatures is:\n * ```\n * #6.40020([2, h'<64-byte-signature>'])\n * ```\n *\n * Ported from bc-components-rust/src/signing/signature.rs\n */\n\nimport { ED25519_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 expectArray,\n expectBytes,\n expectUnsigned,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SIGNATURE as TAG_SIGNATURE } from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes } from \"../utils.js\";\nimport { SignatureScheme } from \"./signature-scheme.js\";\n\n/**\n * A digital signature created with various signature algorithms.\n *\n * Currently supports:\n * - Ed25519 signatures (64 bytes)\n * - Sr25519 signatures (64 bytes)\n */\nexport class Signature implements CborTaggedEncodable, CborTaggedDecodable<Signature> {\n private readonly _type: SignatureScheme;\n private readonly _data: Uint8Array;\n\n private constructor(type: SignatureScheme, data: Uint8Array) {\n this._type = type;\n this._data = new Uint8Array(data);\n }\n\n // ============================================================================\n // Static Factory Methods\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 // 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 the raw signature data.\n */\n data(): Uint8Array {\n return this._data;\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 * 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._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 for Ed25519: [2, h'<64-byte-signature>']\n * Format for Sr25519: [3, h'<64-byte-signature>']\n */\n untaggedCbor(): Cbor {\n switch (this._type) {\n case SignatureScheme.Ed25519:\n return cbor([2, toByteString(this._data)]);\n case SignatureScheme.Sr25519:\n return cbor([3, toByteString(this._data)]);\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:\n * - [2, h'<64-byte-signature>'] for Ed25519\n * - [3, h'<64-byte-signature>'] for Sr25519\n */\n fromUntaggedCbor(cborValue: Cbor): Signature {\n const elements = expectArray(cborValue);\n\n if (elements.length !== 2) {\n throw new Error(\"Signature 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 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 /**\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 * A public key used for verifying digital signatures.\n *\n * `SigningPublicKey` is a type representing different types of signing public\n * keys. Currently, only Ed25519 is implemented.\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 for Ed25519:\n * ```\n * #6.40022([2, h'<32-byte-public-key>'])\n * ```\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 expectArray,\n expectBytes,\n expectUnsigned,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SIGNING_PUBLIC_KEY as TAG_SIGNING_PUBLIC_KEY } from \"@bcts/tags\";\nimport { Ed25519PublicKey } from \"../ed25519/ed25519-public-key.js\";\nimport { Sr25519PublicKey } from \"../sr25519/sr25519-public-key.js\";\nimport { SignatureScheme } from \"./signature-scheme.js\";\nimport type { Signature } from \"./signature.js\";\nimport type { Verifier } from \"./signer.js\";\n\n/**\n * A public key used for verifying digital signatures.\n *\n * Currently supports:\n * - Ed25519 public keys (32 bytes)\n * - Sr25519 public keys (32 bytes)\n */\nexport class SigningPublicKey\n implements Verifier, CborTaggedEncodable, CborTaggedDecodable<SigningPublicKey>\n{\n private readonly _type: SignatureScheme;\n private readonly _ed25519Key: Ed25519PublicKey | undefined;\n private readonly _sr25519Key: Sr25519PublicKey | undefined;\n\n private constructor(\n type: SignatureScheme,\n ed25519Key?: Ed25519PublicKey,\n sr25519Key?: Sr25519PublicKey,\n ) {\n this._type = type;\n this._ed25519Key = ed25519Key;\n this._sr25519Key = sr25519Key;\n }\n\n // ============================================================================\n // Static Factory Methods\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(SignatureScheme.Ed25519, key, undefined);\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(SignatureScheme.Sr25519, 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 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 * Checks if this is an Ed25519 signing key.\n */\n isEd25519(): boolean {\n return this._type === SignatureScheme.Ed25519;\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 an Sr25519 signing key.\n */\n isSr25519(): boolean {\n return this._type === SignatureScheme.Sr25519;\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.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 }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._type) {\n case SignatureScheme.Ed25519:\n return `SigningPublicKey(${this._type}, ${this._ed25519Key?.toHex().substring(0, 16)}...)`;\n case SignatureScheme.Sr25519:\n return `SigningPublicKey(${this._type}, ${this._sr25519Key?.toHex().substring(0, 16)}...)`;\n }\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.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 }\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 for Ed25519: [2, h'<32-byte-public-key>']\n * Format for Sr25519: [3, h'<32-byte-public-key>']\n */\n untaggedCbor(): Cbor {\n switch (this._type) {\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 }\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:\n * - [2, h'<32-byte-key>'] for Ed25519\n * - [3, h'<32-byte-key>'] for Sr25519\n */\n fromUntaggedCbor(cborValue: Cbor): SigningPublicKey {\n const elements = expectArray(cborValue);\n\n if (elements.length !== 2) {\n throw new Error(\"SigningPublicKey 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 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 /**\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 Ed25519PublicKey.from(new Uint8Array(ED25519_PUBLIC_KEY_SIZE)),\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 const dummy = new SigningPublicKey(\n SignatureScheme.Ed25519,\n Ed25519PublicKey.from(new Uint8Array(ED25519_PUBLIC_KEY_SIZE)),\n );\n return dummy.fromUntaggedCbor(cborValue);\n }\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 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:\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 {\n type Cbor,\n type Tag,\n type CborTaggedEncodable,\n type CborTaggedDecodable,\n cbor,\n toByteString,\n expectArray,\n expectBytes,\n expectUnsigned,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SIGNING_PRIVATE_KEY as TAG_SIGNING_PRIVATE_KEY } from \"@bcts/tags\";\nimport { Ed25519PrivateKey } from \"../ed25519/ed25519-private-key.js\";\nimport { Sr25519PrivateKey } from \"../sr25519/sr25519-private-key.js\";\nimport { SignatureScheme } from \"./signature-scheme.js\";\nimport { Signature } from \"./signature.js\";\nimport { SigningPublicKey } from \"./signing-public-key.js\";\nimport type { Signer, Verifier } from \"./signer.js\";\n\n/**\n * A private key used for creating digital signatures.\n *\n * Currently supports:\n * - Ed25519 private keys (32 bytes) - discriminator 2\n * - SR25519 private keys (32-byte seed) - discriminator 3\n */\nexport class SigningPrivateKey\n implements Signer, Verifier, CborTaggedEncodable, CborTaggedDecodable<SigningPrivateKey>\n{\n private readonly _type: SignatureScheme;\n private readonly _ed25519Key: Ed25519PrivateKey | undefined;\n private readonly _sr25519Key: Sr25519PrivateKey | undefined;\n\n private constructor(\n type: SignatureScheme,\n ed25519Key?: Ed25519PrivateKey,\n sr25519Key?: Sr25519PrivateKey,\n ) {\n this._type = type;\n this._ed25519Key = ed25519Key;\n this._sr25519Key = sr25519Key;\n }\n\n // ============================================================================\n // Static Factory Methods\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, key, 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, 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 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 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 * Checks if this is an Ed25519 signing key.\n */\n isEd25519(): boolean {\n return this._type === SignatureScheme.Ed25519;\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.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 }\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.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 }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n return `SigningPrivateKey(${this._type})`;\n }\n\n // ============================================================================\n // Signer Interface\n // ============================================================================\n\n /**\n * Signs a message using the appropriate algorithm based on the key type.\n *\n * @param message - The message to sign\n * @returns The digital signature\n */\n sign(message: Uint8Array): Signature {\n switch (this._type) {\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 }\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 return this.publicKey().verify(signature, message);\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 for Ed25519: [2, h'<32-byte-private-key>']\n * Format for Sr25519: [3, h'<32-byte-seed>']\n */\n untaggedCbor(): Cbor {\n switch (this._type) {\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 }\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:\n * - [2, h'<32-byte-key>'] for Ed25519\n * - [3, h'<32-byte-seed>'] for Sr25519\n */\n fromUntaggedCbor(cborValue: Cbor): SigningPrivateKey {\n const elements = expectArray(cborValue);\n\n if (elements.length !== 2) {\n throw new Error(\"SigningPrivateKey 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 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 /**\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 Ed25519PrivateKey.from(new Uint8Array(ED25519_PRIVATE_KEY_SIZE)),\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 const dummy = new SigningPrivateKey(\n SignatureScheme.Ed25519,\n Ed25519PrivateKey.from(new Uint8Array(ED25519_PRIVATE_KEY_SIZE)),\n );\n return dummy.fromUntaggedCbor(cborValue);\n }\n}\n","/**\n * Supported digital signature schemes.\n *\n * This enum represents the various signature schemes supported in this crate,\n * including Ed25519 and SR25519 signatures.\n *\n * Ported from bc-components-rust/src/signing/signature_scheme.rs\n */\n\nimport { type SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport { Ed25519PrivateKey } from \"../ed25519/ed25519-private-key.js\";\nimport { Sr25519PrivateKey } from \"../sr25519/sr25519-private-key.js\";\nimport { SigningPrivateKey } from \"./signing-private-key.js\";\nimport type { SigningPublicKey } from \"./signing-public-key.js\";\n\n/**\n * Supported digital signature schemes.\n *\n * This enum represents the various signature schemes supported in this package.\n * - Ed25519: RFC 8032 signatures (discriminator 2)\n * - Sr25519: Schnorr over Ristretto25519, used by Polkadot/Substrate (discriminator 3)\n */\nexport enum SignatureScheme {\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/**\n * Get the default signature scheme.\n */\nexport function defaultSignatureScheme(): SignatureScheme {\n return SignatureScheme.Ed25519;\n}\n\n/**\n * Creates a new key pair for the signature scheme.\n *\n * @param scheme - The signature scheme to use\n * @returns A tuple containing a signing private key and its corresponding public key\n */\nexport function createKeypair(scheme: SignatureScheme): [SigningPrivateKey, SigningPublicKey] {\n switch (scheme) {\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 }\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 * @returns A tuple containing a signing private key and its corresponding public key\n */\nexport function createKeypairUsing(\n scheme: SignatureScheme,\n rng: SecureRandomNumberGenerator,\n): [SigningPrivateKey, SigningPublicKey] {\n switch (scheme) {\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 }\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 *\n * # CBOR Serialization\n *\n * For X25519, the ciphertext is serialized with the X25519 public key tag (40011).\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 { X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY } from \"@bcts/tags\";\nimport { X25519PublicKey } from \"../x25519/x25519-public-key.js\";\nimport { EncapsulationScheme } from \"./encapsulation-scheme.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * Represents the ciphertext from a key encapsulation operation.\n *\n * For X25519, this wraps an ephemeral public key.\n */\nexport class EncapsulationCiphertext\n implements CborTaggedEncodable, CborTaggedDecodable<EncapsulationCiphertext>\n{\n private readonly _scheme: EncapsulationScheme;\n private readonly _x25519PublicKey: X25519PublicKey | undefined;\n\n private constructor(scheme: EncapsulationScheme, x25519PublicKey?: X25519PublicKey) {\n this._scheme = scheme;\n this._x25519PublicKey = x25519PublicKey;\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);\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 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 raw ciphertext data.\n */\n data(): Uint8Array {\n switch (this._scheme) {\n case EncapsulationScheme.X25519: {\n const pk = this._x25519PublicKey;\n if (pk === undefined) throw new Error(\"X25519 public key not set\");\n return pk.data();\n }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Compare with another EncapsulationCiphertext.\n */\n equals(other: EncapsulationCiphertext): boolean {\n if (this._scheme !== other._scheme) return false;\n switch (this._scheme) {\n case 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 }\n default:\n return false;\n }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return `EncapsulationCiphertext(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n default:\n return `EncapsulationCiphertext(${String(this._scheme)})`;\n }\n }\n\n // ============================================================================\n // CBOR Serialization (CborTaggedEncodable)\n // ============================================================================\n\n /**\n * Returns the CBOR tags associated with this ciphertext.\n */\n cborTags(): Tag[] {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return tagsForValues([TAG_X25519_PUBLIC_KEY.value]);\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Returns the untagged CBOR encoding.\n */\n untaggedCbor(): Cbor {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 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 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 * 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 * # CBOR Serialization\n *\n * For X25519, the public key is serialized with tag 40011.\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 { X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY } 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 { bytesToHex } from \"../utils.js\";\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 CborTaggedEncodable, CborTaggedDecodable<EncapsulationPublicKey>, UREncodable\n{\n private readonly _scheme: EncapsulationScheme;\n private readonly _x25519PublicKey: X25519PublicKey | undefined;\n\n private constructor(scheme: EncapsulationScheme, x25519PublicKey?: X25519PublicKey) {\n this._scheme = scheme;\n this._x25519PublicKey = x25519PublicKey;\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);\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 // 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 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 raw public key data.\n */\n data(): Uint8Array {\n switch (this._scheme) {\n case EncapsulationScheme.X25519: {\n const pk = this._x25519PublicKey;\n if (pk === undefined) throw new Error(\"X25519 public key not set\");\n return pk.data();\n }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Compare with another EncapsulationPublicKey.\n */\n equals(other: EncapsulationPublicKey): boolean {\n if (this._scheme !== other._scheme) return false;\n switch (this._scheme) {\n case 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 }\n default:\n return false;\n }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return `EncapsulationPublicKey(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n default:\n return `EncapsulationPublicKey(${String(this._scheme)})`;\n }\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 switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return tagsForValues([TAG_X25519_PUBLIC_KEY.value]);\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Returns the untagged CBOR encoding.\n */\n untaggedCbor(): Cbor {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 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 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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 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 * 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 * # CBOR Serialization\n *\n * For X25519, the private key is serialized with tag 40010.\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 { X25519_PRIVATE_KEY as TAG_X25519_PRIVATE_KEY } 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 { CryptoError } from \"../error.js\";\nimport { bytesToHex } from \"../utils.js\";\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 CborTaggedEncodable, CborTaggedDecodable<EncapsulationPrivateKey>, UREncodable\n{\n private readonly _scheme: EncapsulationScheme;\n private readonly _x25519PrivateKey: X25519PrivateKey | undefined;\n\n private constructor(scheme: EncapsulationScheme, x25519PrivateKey?: X25519PrivateKey) {\n this._scheme = scheme;\n this._x25519PrivateKey = x25519PrivateKey;\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);\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 * 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 keypair.\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.\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 // 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 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 raw private key data.\n */\n data(): Uint8Array {\n switch (this._scheme) {\n case EncapsulationScheme.X25519: {\n const pk = this._x25519PrivateKey;\n if (pk === undefined) throw new Error(\"X25519 private key not set\");\n return pk.data();\n }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Get the public key corresponding to this private key.\n */\n publicKey(): EncapsulationPublicKey {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Compare with another EncapsulationPrivateKey.\n */\n equals(other: EncapsulationPrivateKey): boolean {\n if (this._scheme !== other._scheme) return false;\n switch (this._scheme) {\n case 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 }\n default:\n return false;\n }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return `EncapsulationPrivateKey(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n default:\n return `EncapsulationPrivateKey(${String(this._scheme)})`;\n }\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 switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return tagsForValues([TAG_X25519_PRIVATE_KEY.value]);\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Returns the untagged CBOR encoding.\n */\n untaggedCbor(): Cbor {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 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 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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 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 * 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 * Currently supported:\n * - X25519: Curve25519-based Diffie-Hellman key exchange (default)\n *\n * Future support (post-quantum):\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\";\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 // Future: ML-KEM post-quantum schemes\n // MLKEM512 = \"mlkem512\",\n // MLKEM768 = \"mlkem768\",\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 * 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 default:\n throw new Error(`Unsupported encapsulation scheme: ${String(scheme)}`);\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 *\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 */\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 default:\n throw new Error(\n `Deterministic keypair generation not supported for scheme: ${String(scheme)}`,\n );\n }\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 * 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 * 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\n * HKDF = 0\n * PBKDF2 = 1\n * Scrypt = 2\n * Argon2id = 3\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}\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 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 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 * 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, expectBytes } from \"@bcts/dcbor\";\nimport { hkdfHmacSha256, hkdfHmacSha512 } 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 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]\n */\n toCbor(): Cbor {\n return cbor([\n cbor(HKDFParams.INDEX),\n this._salt.untaggedCbor(),\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): 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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\n const hashType = hashTypeFromCbor(array[2]);\n\n return new HKDFParams(salt, hashType);\n }\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, expectBytes } from \"@bcts/dcbor\";\nimport { pbkdf2HmacSha256, pbkdf2HmacSha512 } 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 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]\n */\n toCbor(): Cbor {\n return cbor([\n cbor(PBKDF2Params.INDEX),\n this._salt.untaggedCbor(),\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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\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 * 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, expectBytes } 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/** 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]\n */\n toCbor(): Cbor {\n return cbor([\n cbor(ScryptParams.INDEX),\n this._salt.untaggedCbor(),\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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\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 * 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, expectBytes } from \"@bcts/dcbor\";\nimport { argon2idHash } 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 argon2idHash(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]\n */\n toCbor(): Cbor {\n return cbor([cbor(Argon2idParams.INDEX), this._salt.untaggedCbor()]);\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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\n\n return new Argon2idParams(salt);\n }\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\";\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\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 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 }\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 * 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 }\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 }\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 }\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 }\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} 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 default:\n throw new Error(`Unknown key derivation method: ${String(method)}`);\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 * 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 }\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 * 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 { Signature } from \"./signing/signature.js\";\nimport type { Verifier } from \"./signing/signer.js\";\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 Verifier, CborTaggedEncodable, CborTaggedDecodable<PublicKeys>, 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 // 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 toString(): string {\n return `PublicKeys(${String(this._signingPublicKey)}, ${String(this._encapsulationPublicKey)})`;\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 * 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 { Signature } from \"./signing/signature.js\";\nimport type { Signer } from \"./signing/signer.js\";\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 Signer, CborTaggedEncodable, CborTaggedDecodable<PrivateKeys>, 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 // 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 using the signing private key.\n */\n sign(message: Uint8Array): Signature {\n return this._signingPrivateKey.sign(message);\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 * Get string representation.\n */\n toString(): string {\n return `PrivateKeys(${String(this._signingPrivateKey)}, ${String(this._encapsulationPrivateKey)})`;\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 * 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 { 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\";\n\n/** Size of PrivateKeyBase key material in bytes */\nconst PRIVATE_KEY_BASE_SIZE = 32;\n\n/** Key derivation info strings */\nconst INFO_SIGNING_ED25519 = \"signing-ed25519\";\nconst INFO_AGREEMENT_X25519 = \"agreement-x25519\";\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\n{\n private readonly _data: Uint8Array;\n\n private constructor(data: Uint8Array) {\n if (data.length !== PRIVATE_KEY_BASE_SIZE) {\n throw new Error(`PrivateKeyBase must be ${PRIVATE_KEY_BASE_SIZE} bytes, got ${data.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_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 info string \"signing-ed25519\".\n */\n ed25519SigningPrivateKey(): SigningPrivateKey {\n const derivedKey = this._deriveKey(INFO_SIGNING_ED25519);\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 info string \"agreement-x25519\".\n */\n x25519PrivateKey(): X25519PrivateKey {\n const derivedKey = this._deriveKey(INFO_AGREEMENT_X25519);\n return X25519PrivateKey.fromData(derivedKey);\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 * 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 * Internal key derivation using HKDF-SHA256.\n * Uses the info string as salt for domain separation.\n */\n private _deriveKey(info: string): Uint8Array {\n // Use info as salt for domain separation (crypto package's HKDF doesn't have info param)\n const salt = new TextEncoder().encode(info);\n return hkdfHmacSha256(this._data, 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_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_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_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 * SSKR Integration - CBOR/UR wrappers for SSKR shares\n *\n * This module provides CBOR and UR serialization for SSKR (Sharded Secret Key\n * Reconstruction) shares. It wraps the core SSKR functionality from\n * @bcts/sskr with CBOR tags and UR encoding.\n *\n * # CBOR Serialization\n *\n * SSKRShareCbor 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 * # UR Serialization\n *\n * UR type: `sskr`\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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\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\";\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\n implements CborTaggedEncodable, CborTaggedDecodable<SSKRShareCbor>, UREncodable\n{\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 SSKRShareCbor.\n */\n cborTags(): Tag[] {\n return tagsForValues([TAG_SSKR_SHARE.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 // UR Serialization (UREncodable)\n // ============================================================================\n\n /**\n * Returns the UR representation.\n */\n ur(): UR {\n const name = TAG_SSKR_SHARE.name;\n if (name === undefined) {\n throw new Error(\"SSKR_SHARE 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 SSKRShareCbor from a UR.\n */\n static fromUR(ur: UR): SSKRShareCbor {\n // Accept both current and legacy UR types\n if (ur.urTypeStr() !== TAG_SSKR_SHARE.name && ur.urTypeStr() !== TAG_SSKR_SHARE_V1.name) {\n throw new Error(\n `Expected UR type ${TAG_SSKR_SHARE.name} or ${TAG_SSKR_SHARE_V1.name}, got ${ur.urTypeStr()}`,\n );\n }\n const dummy = new SSKRShareCbor(new Uint8Array(METADATA_SIZE_BYTES + 16));\n return dummy.fromUntaggedCbor(ur.cbor());\n }\n\n /**\n * Creates an SSKRShareCbor from a UR string.\n */\n static fromURString(urString: string): SSKRShareCbor {\n const ur = UR.fromURString(urString);\n return SSKRShareCbor.fromUR(ur);\n }\n}\n\n// ============================================================================\n// Helper Functions for generating/combining shares with CBOR wrappers\n// ============================================================================\n\n/**\n * Generate SSKR shares with CBOR wrappers.\n *\n * @param spec - The SSKR specification\n * @param secret - The secret to split\n * @returns Groups of SSKRShareCbor instances\n */\nexport function generateSSKRSharesCbor(spec: SSKRSpec, secret: SSKRSecret): SSKRShareCbor[][] {\n const rawGroups = sskrGenerate(spec, secret);\n return rawGroups.map((group) => group.map((shareData) => SSKRShareCbor.fromData(shareData)));\n}\n\n/**\n * Combine SSKR shares from CBOR wrappers.\n *\n * @param shares - The shares to combine\n * @returns The recovered secret\n */\nexport function combineSSKRSharesCbor(shares: SSKRShareCbor[]): SSKRSecret {\n const rawShares = shares.map((share) => share.data());\n return sskrCombine(rawShares);\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\nimport { ml_dsa44, ml_dsa65, ml_dsa87 } from \"@noble/post-quantum/ml-dsa\";\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(secretKey, message);\n case MLDSALevel.MLDSA65:\n return ml_dsa65.sign(secretKey, message);\n case MLDSALevel.MLDSA87:\n return ml_dsa87.sign(secretKey, message);\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(publicKey, message, signature);\n case MLDSALevel.MLDSA65:\n return ml_dsa65.verify(publicKey, message, signature);\n case MLDSALevel.MLDSA87:\n return ml_dsa87.verify(publicKey, message, signature);\n }\n } catch {\n return false;\n }\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 * 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 * 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 * 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\nimport { ml_kem512, ml_kem768, ml_kem1024 } from \"@noble/post-quantum/ml-kem\";\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 * 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 * 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 * 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} 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 // 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"],"x_google_ignoreList":[16,17,18,19],"mappings":";;;;;;;;;;;;;;;;;;;AAwDA,eAAsB,gBAAgB,MAAmC;CAEvE,MAAM,EAAE,qBAAW,MAAM,OAAO;AAChC,QAAOA,SAAO,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACS/B,IAAa,QAAb,MAAa,MAA8E;CACzF,OAAgB,aAAa;CAE7B,AAAiB;CAEjB,AAAQ,YAAY,MAAkB;AACpC,MAAI,KAAK,WAAW,MAAM,WACxB,OAAM,YAAY,YAAY,MAAM,YAAY,KAAK,OAAO;AAE9D,OAAK,QAAQ,IAAI,WAAW,KAAK;;;;;CAUnC,OAAO,MAAa;AAElB,SAAO,IAAI,MADC,IAAI,6BAA6B,CACxB,WAAW,MAAM,WAAW,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AAc,CAAC;;;;;CAM1C,WAAmB;AACjB,SAAO,KAAK,IAAI,CAAC,QAAQ;;;;;CAM3B,OAAO,OAAO,IAAyB;AACrC,MAAI,GAAG,WAAW,KAAKA,kBAAsB,KAC3C,OAAM,IAAI,MAAM,oBAAoBA,kBAAsB,KAAK,QAAQ,GAAG,WAAW,GAAG;EAE1F,MAAM,YAAY,IAAI,WAAW,oBAAoB,WAAW,SAAS,CAAC;AAE1E,SADc,IAAI,gBAAgB,WAAW,UAAU,UAAU,CACpD,iBAAiB,GAAG,MAAM,CAAC;;;;;CAM1C,OAAO,aAAa,UAAmC;EACrD,MAAM,KAAK,GAAG,aAAa,SAAS;AACpC,SAAO,gBAAgB,OAAO,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Digest","TAG_NONCE","cbor","TAG_SALT","cbor","TAG_SEED","TAG_SEED_V1","createdAt: Date | undefined","metadata: SeedMetadata | undefined","cbor","_exhaustive: never","TAG_ARID","cbor","TAG_UUID","cbor","TAG_XID","cbor","TAG_URI","TAG_X25519_PUBLIC_KEY","cbor","cbor","TAG_ENCRYPTED","elements: Cbor[]","TAG_SYMMETRIC_KEY","cbor","e: unknown","TAG_X25519_PRIVATE_KEY","cbor","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_EC_KEY","TAG_EC_KEY_V1","TAG_SIGNATURE","TAG_SIGNING_PUBLIC_KEY","TAG_SIGNING_PRIVATE_KEY","TAG_X25519_PUBLIC_KEY","TAG_X25519_PUBLIC_KEY","TAG_X25519_PRIVATE_KEY","TAG_SEALED_MESSAGE","params: KeyDerivationParams","TAG_ENCRYPTED_KEY","TAG_PUBLIC_KEYS","TAG_PRIVATE_KEYS","TAG_PRIVATE_KEY_BASE","TAG_SSKR_SHARE","TAG_SSKR_SHARE_V1","TAG_MLDSA_PUBLIC_KEY","TAG_MLDSA_SIGNATURE","TAG_MLDSA_PRIVATE_KEY","TAG_MLKEM_CIPHERTEXT","TAG_MLKEM_PUBLIC_KEY","TAG_MLKEM_PRIVATE_KEY"],"sources":["../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/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/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/signing/signature.ts","../src/signing/signing-public-key.ts","../src/signing/signing-private-key.ts","../src/signing/signature-scheme.ts","../src/encapsulation/encapsulation-ciphertext.ts","../src/encapsulation/encapsulation-public-key.ts","../src/encapsulation/encapsulation-private-key.ts","../src/encapsulation/encapsulation-scheme.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/key-derivation-params.ts","../src/encrypted-key/encrypted-key.ts","../src/public-keys.ts","../src/private-keys.ts","../src/private-key-base.ts","../src/sskr.ts","../src/mldsa/mldsa-level.ts","../src/mldsa/mldsa-public-key.ts","../src/mldsa/mldsa-signature.ts","../src/mldsa/mldsa-private-key.ts","../src/mlkem/mlkem-level.ts","../src/mlkem/mlkem-ciphertext.ts","../src/mlkem/mlkem-public-key.ts","../src/mlkem/mlkem-private-key.ts"],"sourcesContent":["/**\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 type { 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 async function digestFromBytes(data: Uint8Array): Promise<Digest> {\n // Dynamic import to avoid circular dependency\n const { Digest } = await import(\"./digest.js\");\n return Digest.fromImage(data);\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 * 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 * 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\";\n\nconst MIN_SEED_SIZE = 16;\n\nexport interface SeedMetadata {\n name?: string;\n note?: string;\n createdAt?: Date;\n}\n\nexport class Seed implements CborTaggedEncodable, CborTaggedDecodable<Seed>, UREncodable {\n // Defensive copy: internal data is never exposed directly to prevent external mutation\n private readonly data: Uint8Array;\n private metadata: SeedMetadata | undefined;\n\n private constructor(data: Uint8Array, metadata?: SeedMetadata) {\n if (data.length < MIN_SEED_SIZE) {\n throw CryptoError.invalidSize(MIN_SEED_SIZE, data.length);\n }\n // Defensive copy on construction to ensure immutability of internal state\n this.data = new Uint8Array(data);\n this.metadata = metadata;\n }\n\n /**\n * Create a Seed from raw bytes.\n *\n * Note: The input data is copied to prevent external mutation of the seed's internal state.\n */\n static from(data: Uint8Array, metadata?: SeedMetadata): Seed {\n return new Seed(new Uint8Array(data), metadata);\n }\n\n /**\n * Create a Seed from hex string\n */\n static fromHex(hex: string, metadata?: SeedMetadata): Seed {\n return new Seed(hexToBytes(hex), metadata);\n }\n\n /**\n * Generate a random seed with specified size\n */\n static random(size = 32, metadata?: SeedMetadata): Seed {\n if (size < MIN_SEED_SIZE) {\n throw CryptoError.invalidSize(MIN_SEED_SIZE, size);\n }\n const rng = new SecureRandomNumberGenerator();\n return new Seed(rng.randomData(size), metadata);\n }\n\n /**\n * Generate a random seed using provided RNG\n */\n static randomUsing(rng: SecureRandomNumberGenerator, size = 32, metadata?: SeedMetadata): Seed {\n if (size < MIN_SEED_SIZE) {\n throw CryptoError.invalidSize(MIN_SEED_SIZE, size);\n }\n return new Seed(rng.randomData(size), metadata);\n }\n\n /**\n * Get the raw seed bytes.\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 * Get name\n */\n name(): string | undefined {\n return this.metadata?.name;\n }\n\n /**\n * Set name\n */\n setName(name: string): void {\n this.metadata ??= {};\n this.metadata.name = name;\n }\n\n /**\n * Get note\n */\n note(): string | undefined {\n return this.metadata?.note;\n }\n\n /**\n * Set note\n */\n setNote(note: string): void {\n this.metadata ??= {};\n this.metadata.note = note;\n }\n\n /**\n * Get creation date\n */\n createdAt(): Date | undefined {\n return this.metadata?.createdAt;\n }\n\n /**\n * Set creation date\n */\n setCreatedAt(date: Date): void {\n this.metadata ??= {};\n this.metadata.createdAt = date;\n }\n\n /**\n * Get metadata\n */\n getMetadata(): SeedMetadata | undefined {\n return this.metadata !== undefined ? { ...this.metadata } : undefined;\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 // 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.metadata?.createdAt !== undefined) {\n const cborDate = CborDate.fromDatetime(this.metadata.createdAt);\n map.insert(2, cborDate.taggedCbor());\n }\n if (this.metadata?.name !== undefined && this.metadata.name.length > 0) {\n map.insert(3, this.metadata.name);\n }\n if (this.metadata?.note !== undefined && this.metadata.note.length > 0) {\n map.insert(4, this.metadata.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 createdAt: 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 createdAt = 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 let metadata: SeedMetadata | undefined;\n if (name !== undefined || note !== undefined || createdAt !== undefined) {\n metadata = {};\n if (name !== undefined) metadata.name = name;\n if (note !== undefined) metadata.note = note;\n if (createdAt !== undefined) metadata.createdAt = createdAt;\n }\n\n return Seed.from(new Uint8Array(data), metadata);\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(cbor: Cbor): Seed {\n const instance = Seed.random(MIN_SEED_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): Seed {\n const cbor = decodeCbor(data);\n return Seed.fromTaggedCbor(cbor);\n }\n\n /**\n * Static method to decode from untagged CBOR binary data.\n */\n static fromUntaggedCborData(data: Uint8Array): Seed {\n const cbor = decodeCbor(data);\n const instance = Seed.random(MIN_SEED_SIZE);\n return instance.fromUntaggedCbor(cbor);\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.random(MIN_SEED_SIZE);\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 * Content-addressable reference - SHA-256 digest with short reference encoding\n */\n\nimport { Digest } from \"./digest.js\";\nimport { CryptoError } from \"./error.js\";\n\nexport type ReferenceEncodingFormat = \"hex\" | \"bytewords\" | \"bytemojis\";\n\n// Bytewords mapping (256 words)\nconst BYTEWORDS = [\n \"abled\",\n \"ache\",\n \"acid\",\n \"acme\",\n \"acre\",\n \"aged\",\n \"aide\",\n \"airy\",\n \"ajar\",\n \"akin\",\n \"alas\",\n \"alba\",\n \"alee\",\n \"alms\",\n \"aloe\",\n \"also\",\n \"ante\",\n \"anti\",\n \"ants\",\n \"anus\",\n \"anus\",\n \"apes\",\n \"apex\",\n \"apse\",\n \"arch\",\n \"area\",\n \"ares\",\n \"aria\",\n \"arid\",\n \"ark\",\n \"arms\",\n \"army\",\n // ... (256 total - abbreviated for space)\n];\n\n// Bytemojis mapping (256 emojis)\nconst BYTEMOJIS = [\n \"😀\",\n \"😂\",\n \"😆\",\n \"😉\",\n \"😊\",\n \"😌\",\n \"😎\",\n \"😏\",\n \"😑\",\n \"😒\",\n \"😓\",\n \"😔\",\n \"😕\",\n \"😖\",\n \"😗\",\n \"😘\",\n // ... (256 total - abbreviated for space)\n];\n\nexport class Reference {\n private readonly digest: Digest;\n\n private constructor(digest: Digest) {\n this.digest = digest;\n }\n\n /**\n * Create a Reference from a Digest\n */\n static from(digest: Digest): Reference {\n return new Reference(digest);\n }\n\n /**\n * Create a Reference from hex string\n */\n static fromHex(hex: string): Reference {\n const digest = Digest.fromHex(hex);\n return new Reference(digest);\n }\n\n /**\n * Generate a Reference from data\n */\n static hash(data: Uint8Array): Reference {\n const digest = Digest.hash(data);\n return new Reference(digest);\n }\n\n /**\n * Get the underlying Digest\n */\n getDigest(): Digest {\n return this.digest;\n }\n\n /**\n * Get full reference as hex string\n */\n toHex(): string {\n return this.digest.toHex();\n }\n\n /**\n * Get short reference (first 4 bytes) in various formats\n */\n shortReference(format: ReferenceEncodingFormat = \"hex\"): string {\n const data = this.digest.toData();\n const shortData = data.slice(0, 4);\n\n switch (format) {\n case \"hex\":\n // Lowercase hex, matching Rust implementation\n return Array.from(shortData)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n\n case \"bytewords\":\n return Array.from(shortData)\n .map((b) => BYTEWORDS[b] ?? `word${b}`)\n .join(\" \");\n\n case \"bytemojis\":\n return Array.from(shortData)\n .map((b) => BYTEMOJIS[b] ?? \"❓\")\n .join(\" \");\n\n default: {\n const _exhaustive: never = format;\n throw CryptoError.invalidFormat(`Unknown reference format: ${String(_exhaustive)}`);\n }\n }\n }\n\n /**\n * Get full reference as hex string (alias for toHex)\n */\n fullReference(): string {\n return this.toHex();\n }\n\n /**\n * Get base64 representation\n */\n toBase64(): string {\n return this.digest.toBase64();\n }\n\n /**\n * Compare with another Reference\n */\n equals(other: Reference): boolean {\n return this.digest.equals(other.digest);\n }\n\n /**\n * Get string representation\n */\n toString(): string {\n return `Reference(${this.shortReference(\"hex\")})`;\n }\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 * 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 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 < UUID_SIZE; i++) {\n data[i] = Math.floor(Math.random() * 256);\n }\n }\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 * 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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, toBase64 } from \"../utils.js\";\n\nconst XID_SIZE = 32;\n\nexport class XID implements CborTaggedEncodable, CborTaggedDecodable<XID>, UREncodable {\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 // Instance Methods\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 * 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.\n */\n toString(): string {\n return `XID(${this.toHex()})`;\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 * 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 * 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 { 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 toString(): string {\n return `X25519PublicKey(${this.toHex().substring(0, 16)}...)`;\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 * 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 * 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 * 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 { 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 * 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 * Ed25519 public key for EdDSA signature verification (32 bytes)\n * Ported from bc-components-rust/src/ed25519_public_key.rs\n */\n\nimport { ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, ed25519Verify } from \"@bcts/crypto\";\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\n */\n static from(data: Uint8Array): Ed25519PublicKey {\n return new Ed25519PublicKey(new Uint8Array(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 /**\n * Get the raw public key bytes\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 * 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 toString(): string {\n return `Ed25519PublicKey(${this.toHex().substring(0, 16)}...)`;\n }\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} 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 * Get the raw seed bytes (32 bytes)\n */\n toData(): Uint8Array {\n return new Uint8Array(this.seed);\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 * 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 } from \"../utils.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 * Note: The @scure/sr25519 library uses a hardcoded \"substrate\" context.\n * Custom context is accepted for API compatibility but only signatures created\n * with \"substrate\" context will verify correctly.\n *\n * @param signature - The 64-byte signature\n * @param message - The message that was signed\n * @param context - The signing context (only \"substrate\" is supported)\n * @returns true if the signature is valid\n */\n verifyWithContext(signature: Uint8Array, message: Uint8Array, _context: Uint8Array): boolean {\n try {\n // Note: @scure/sr25519 verify() uses hardcoded \"substrate\" context\n // Arguments: verify(message, signature, publicKey)\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 * 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/blake2b\";\nimport { Sr25519PublicKey } from \"./sr25519-public-key.js\";\nimport { bytesToHex } from \"../utils.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 * Note: The @scure/sr25519 library uses a hardcoded \"substrate\" context.\n * Custom context is accepted for API compatibility but only \"substrate\" context\n * will produce signatures verifiable by this library.\n *\n * @param message - The message to sign\n * @param context - The signing context (only \"substrate\" is supported)\n * @returns 64-byte signature\n */\n signWithContext(message: Uint8Array, _context: Uint8Array): Uint8Array {\n const secretKey = sr25519.secretFromSeed(this._seed);\n // Note: @scure/sr25519 sign() uses hardcoded \"substrate\" context\n // Arguments: sign(secretKey, message, random?)\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 * 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\";\n\n// Note: ECPublicKey type is used in JSDoc comments but not directly imported\n// to avoid circular dependency issues\n\nexport class ECUncompressedPublicKey\n implements CborTaggedEncodable, CborTaggedDecodable<ECUncompressedPublicKey>, 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 * 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\";\n\nexport class ECPublicKey\n implements 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 * 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 * 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 { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes, toBase64 } from \"../utils.js\";\n\nexport class SchnorrPublicKey {\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 toString(): string {\n return `SchnorrPublicKey(${this.toHex().substring(0, 16)}...)`;\n }\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\";\n\nexport class ECPrivateKey\n implements 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 * A digital signature created with various signature algorithms.\n *\n * `Signature` represents different types of digital signatures.\n * Currently, only Ed25519 signatures are implemented (64 bytes).\n *\n * Signatures can be serialized to and from CBOR with tag 40020.\n *\n * # CBOR Serialization\n *\n * The CBOR encoding for Ed25519 signatures is:\n * ```\n * #6.40020([2, h'<64-byte-signature>'])\n * ```\n *\n * Ported from bc-components-rust/src/signing/signature.rs\n */\n\nimport { ED25519_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 expectArray,\n expectBytes,\n expectUnsigned,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SIGNATURE as TAG_SIGNATURE } from \"@bcts/tags\";\nimport { CryptoError } from \"../error.js\";\nimport { bytesToHex, hexToBytes } from \"../utils.js\";\nimport { SignatureScheme } from \"./signature-scheme.js\";\n\n/**\n * A digital signature created with various signature algorithms.\n *\n * Currently supports:\n * - Ed25519 signatures (64 bytes)\n * - Sr25519 signatures (64 bytes)\n */\nexport class Signature implements CborTaggedEncodable, CborTaggedDecodable<Signature> {\n private readonly _type: SignatureScheme;\n private readonly _data: Uint8Array;\n\n private constructor(type: SignatureScheme, data: Uint8Array) {\n this._type = type;\n this._data = new Uint8Array(data);\n }\n\n // ============================================================================\n // Static Factory Methods\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 // 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 the raw signature data.\n */\n data(): Uint8Array {\n return this._data;\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 * 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._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 for Ed25519: [2, h'<64-byte-signature>']\n * Format for Sr25519: [3, h'<64-byte-signature>']\n */\n untaggedCbor(): Cbor {\n switch (this._type) {\n case SignatureScheme.Ed25519:\n return cbor([2, toByteString(this._data)]);\n case SignatureScheme.Sr25519:\n return cbor([3, toByteString(this._data)]);\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:\n * - [2, h'<64-byte-signature>'] for Ed25519\n * - [3, h'<64-byte-signature>'] for Sr25519\n */\n fromUntaggedCbor(cborValue: Cbor): Signature {\n const elements = expectArray(cborValue);\n\n if (elements.length !== 2) {\n throw new Error(\"Signature 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 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 /**\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 * A public key used for verifying digital signatures.\n *\n * `SigningPublicKey` is a type representing different types of signing public\n * keys. Currently, only Ed25519 is implemented.\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 for Ed25519:\n * ```\n * #6.40022([2, h'<32-byte-public-key>'])\n * ```\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 expectArray,\n expectBytes,\n expectUnsigned,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SIGNING_PUBLIC_KEY as TAG_SIGNING_PUBLIC_KEY } from \"@bcts/tags\";\nimport { Ed25519PublicKey } from \"../ed25519/ed25519-public-key.js\";\nimport { Sr25519PublicKey } from \"../sr25519/sr25519-public-key.js\";\nimport { SignatureScheme } from \"./signature-scheme.js\";\nimport type { Signature } from \"./signature.js\";\nimport type { Verifier } from \"./signer.js\";\n\n/**\n * A public key used for verifying digital signatures.\n *\n * Currently supports:\n * - Ed25519 public keys (32 bytes)\n * - Sr25519 public keys (32 bytes)\n */\nexport class SigningPublicKey\n implements Verifier, CborTaggedEncodable, CborTaggedDecodable<SigningPublicKey>\n{\n private readonly _type: SignatureScheme;\n private readonly _ed25519Key: Ed25519PublicKey | undefined;\n private readonly _sr25519Key: Sr25519PublicKey | undefined;\n\n private constructor(\n type: SignatureScheme,\n ed25519Key?: Ed25519PublicKey,\n sr25519Key?: Sr25519PublicKey,\n ) {\n this._type = type;\n this._ed25519Key = ed25519Key;\n this._sr25519Key = sr25519Key;\n }\n\n // ============================================================================\n // Static Factory Methods\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(SignatureScheme.Ed25519, key, undefined);\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(SignatureScheme.Sr25519, 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 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 * Checks if this is an Ed25519 signing key.\n */\n isEd25519(): boolean {\n return this._type === SignatureScheme.Ed25519;\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 an Sr25519 signing key.\n */\n isSr25519(): boolean {\n return this._type === SignatureScheme.Sr25519;\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.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 }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._type) {\n case SignatureScheme.Ed25519:\n return `SigningPublicKey(${this._type}, ${this._ed25519Key?.toHex().substring(0, 16)}...)`;\n case SignatureScheme.Sr25519:\n return `SigningPublicKey(${this._type}, ${this._sr25519Key?.toHex().substring(0, 16)}...)`;\n }\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.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 }\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 for Ed25519: [2, h'<32-byte-public-key>']\n * Format for Sr25519: [3, h'<32-byte-public-key>']\n */\n untaggedCbor(): Cbor {\n switch (this._type) {\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 }\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:\n * - [2, h'<32-byte-key>'] for Ed25519\n * - [3, h'<32-byte-key>'] for Sr25519\n */\n fromUntaggedCbor(cborValue: Cbor): SigningPublicKey {\n const elements = expectArray(cborValue);\n\n if (elements.length !== 2) {\n throw new Error(\"SigningPublicKey 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 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 /**\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 Ed25519PublicKey.from(new Uint8Array(ED25519_PUBLIC_KEY_SIZE)),\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 const dummy = new SigningPublicKey(\n SignatureScheme.Ed25519,\n Ed25519PublicKey.from(new Uint8Array(ED25519_PUBLIC_KEY_SIZE)),\n );\n return dummy.fromUntaggedCbor(cborValue);\n }\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 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:\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 {\n type Cbor,\n type Tag,\n type CborTaggedEncodable,\n type CborTaggedDecodable,\n cbor,\n toByteString,\n expectArray,\n expectBytes,\n expectUnsigned,\n createTaggedCbor,\n validateTag,\n extractTaggedContent,\n decodeCbor,\n tagsForValues,\n} from \"@bcts/dcbor\";\nimport { SIGNING_PRIVATE_KEY as TAG_SIGNING_PRIVATE_KEY } from \"@bcts/tags\";\nimport { Ed25519PrivateKey } from \"../ed25519/ed25519-private-key.js\";\nimport { Sr25519PrivateKey } from \"../sr25519/sr25519-private-key.js\";\nimport { SignatureScheme } from \"./signature-scheme.js\";\nimport { Signature } from \"./signature.js\";\nimport { SigningPublicKey } from \"./signing-public-key.js\";\nimport type { Signer, Verifier } from \"./signer.js\";\n\n/**\n * A private key used for creating digital signatures.\n *\n * Currently supports:\n * - Ed25519 private keys (32 bytes) - discriminator 2\n * - SR25519 private keys (32-byte seed) - discriminator 3\n */\nexport class SigningPrivateKey\n implements Signer, Verifier, CborTaggedEncodable, CborTaggedDecodable<SigningPrivateKey>\n{\n private readonly _type: SignatureScheme;\n private readonly _ed25519Key: Ed25519PrivateKey | undefined;\n private readonly _sr25519Key: Sr25519PrivateKey | undefined;\n\n private constructor(\n type: SignatureScheme,\n ed25519Key?: Ed25519PrivateKey,\n sr25519Key?: Sr25519PrivateKey,\n ) {\n this._type = type;\n this._ed25519Key = ed25519Key;\n this._sr25519Key = sr25519Key;\n }\n\n // ============================================================================\n // Static Factory Methods\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, key, 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, 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 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 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 * Checks if this is an Ed25519 signing key.\n */\n isEd25519(): boolean {\n return this._type === SignatureScheme.Ed25519;\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.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 }\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.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 }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n return `SigningPrivateKey(${this._type})`;\n }\n\n // ============================================================================\n // Signer Interface\n // ============================================================================\n\n /**\n * Signs a message using the appropriate algorithm based on the key type.\n *\n * @param message - The message to sign\n * @returns The digital signature\n */\n sign(message: Uint8Array): Signature {\n switch (this._type) {\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 }\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 return this.publicKey().verify(signature, message);\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 for Ed25519: [2, h'<32-byte-private-key>']\n * Format for Sr25519: [3, h'<32-byte-seed>']\n */\n untaggedCbor(): Cbor {\n switch (this._type) {\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 }\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:\n * - [2, h'<32-byte-key>'] for Ed25519\n * - [3, h'<32-byte-seed>'] for Sr25519\n */\n fromUntaggedCbor(cborValue: Cbor): SigningPrivateKey {\n const elements = expectArray(cborValue);\n\n if (elements.length !== 2) {\n throw new Error(\"SigningPrivateKey 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 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 /**\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 Ed25519PrivateKey.from(new Uint8Array(ED25519_PRIVATE_KEY_SIZE)),\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 const dummy = new SigningPrivateKey(\n SignatureScheme.Ed25519,\n Ed25519PrivateKey.from(new Uint8Array(ED25519_PRIVATE_KEY_SIZE)),\n );\n return dummy.fromUntaggedCbor(cborValue);\n }\n}\n","/**\n * Supported digital signature schemes.\n *\n * This enum represents the various signature schemes supported in this crate,\n * including Ed25519 and SR25519 signatures.\n *\n * Ported from bc-components-rust/src/signing/signature_scheme.rs\n */\n\nimport { type SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport { Ed25519PrivateKey } from \"../ed25519/ed25519-private-key.js\";\nimport { Sr25519PrivateKey } from \"../sr25519/sr25519-private-key.js\";\nimport { SigningPrivateKey } from \"./signing-private-key.js\";\nimport type { SigningPublicKey } from \"./signing-public-key.js\";\n\n/**\n * Supported digital signature schemes.\n *\n * This enum represents the various signature schemes supported in this package.\n * - Ed25519: RFC 8032 signatures (discriminator 2)\n * - Sr25519: Schnorr over Ristretto25519, used by Polkadot/Substrate (discriminator 3)\n */\nexport enum SignatureScheme {\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/**\n * Get the default signature scheme.\n */\nexport function defaultSignatureScheme(): SignatureScheme {\n return SignatureScheme.Ed25519;\n}\n\n/**\n * Creates a new key pair for the signature scheme.\n *\n * @param scheme - The signature scheme to use\n * @returns A tuple containing a signing private key and its corresponding public key\n */\nexport function createKeypair(scheme: SignatureScheme): [SigningPrivateKey, SigningPublicKey] {\n switch (scheme) {\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 }\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 * @returns A tuple containing a signing private key and its corresponding public key\n */\nexport function createKeypairUsing(\n scheme: SignatureScheme,\n rng: SecureRandomNumberGenerator,\n): [SigningPrivateKey, SigningPublicKey] {\n switch (scheme) {\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 }\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 *\n * # CBOR Serialization\n *\n * For X25519, the ciphertext is serialized with the X25519 public key tag (40011).\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 { X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY } from \"@bcts/tags\";\nimport { X25519PublicKey } from \"../x25519/x25519-public-key.js\";\nimport { EncapsulationScheme } from \"./encapsulation-scheme.js\";\nimport { bytesToHex } from \"../utils.js\";\n\n/**\n * Represents the ciphertext from a key encapsulation operation.\n *\n * For X25519, this wraps an ephemeral public key.\n */\nexport class EncapsulationCiphertext\n implements CborTaggedEncodable, CborTaggedDecodable<EncapsulationCiphertext>\n{\n private readonly _scheme: EncapsulationScheme;\n private readonly _x25519PublicKey: X25519PublicKey | undefined;\n\n private constructor(scheme: EncapsulationScheme, x25519PublicKey?: X25519PublicKey) {\n this._scheme = scheme;\n this._x25519PublicKey = x25519PublicKey;\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);\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 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 raw ciphertext data.\n */\n data(): Uint8Array {\n switch (this._scheme) {\n case EncapsulationScheme.X25519: {\n const pk = this._x25519PublicKey;\n if (pk === undefined) throw new Error(\"X25519 public key not set\");\n return pk.data();\n }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Compare with another EncapsulationCiphertext.\n */\n equals(other: EncapsulationCiphertext): boolean {\n if (this._scheme !== other._scheme) return false;\n switch (this._scheme) {\n case 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 }\n default:\n return false;\n }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return `EncapsulationCiphertext(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n default:\n return `EncapsulationCiphertext(${String(this._scheme)})`;\n }\n }\n\n // ============================================================================\n // CBOR Serialization (CborTaggedEncodable)\n // ============================================================================\n\n /**\n * Returns the CBOR tags associated with this ciphertext.\n */\n cborTags(): Tag[] {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return tagsForValues([TAG_X25519_PUBLIC_KEY.value]);\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Returns the untagged CBOR encoding.\n */\n untaggedCbor(): Cbor {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 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 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 * 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 * # CBOR Serialization\n *\n * For X25519, the public key is serialized with tag 40011.\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 { X25519_PUBLIC_KEY as TAG_X25519_PUBLIC_KEY } 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 { bytesToHex } from \"../utils.js\";\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 CborTaggedEncodable, CborTaggedDecodable<EncapsulationPublicKey>, UREncodable\n{\n private readonly _scheme: EncapsulationScheme;\n private readonly _x25519PublicKey: X25519PublicKey | undefined;\n\n private constructor(scheme: EncapsulationScheme, x25519PublicKey?: X25519PublicKey) {\n this._scheme = scheme;\n this._x25519PublicKey = x25519PublicKey;\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);\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 // 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 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 raw public key data.\n */\n data(): Uint8Array {\n switch (this._scheme) {\n case EncapsulationScheme.X25519: {\n const pk = this._x25519PublicKey;\n if (pk === undefined) throw new Error(\"X25519 public key not set\");\n return pk.data();\n }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Compare with another EncapsulationPublicKey.\n */\n equals(other: EncapsulationPublicKey): boolean {\n if (this._scheme !== other._scheme) return false;\n switch (this._scheme) {\n case 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 }\n default:\n return false;\n }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return `EncapsulationPublicKey(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n default:\n return `EncapsulationPublicKey(${String(this._scheme)})`;\n }\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 switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return tagsForValues([TAG_X25519_PUBLIC_KEY.value]);\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Returns the untagged CBOR encoding.\n */\n untaggedCbor(): Cbor {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 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 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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 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 * 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 * # CBOR Serialization\n *\n * For X25519, the private key is serialized with tag 40010.\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 { X25519_PRIVATE_KEY as TAG_X25519_PRIVATE_KEY } 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 { CryptoError } from \"../error.js\";\nimport { bytesToHex } from \"../utils.js\";\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 CborTaggedEncodable, CborTaggedDecodable<EncapsulationPrivateKey>, UREncodable\n{\n private readonly _scheme: EncapsulationScheme;\n private readonly _x25519PrivateKey: X25519PrivateKey | undefined;\n\n private constructor(scheme: EncapsulationScheme, x25519PrivateKey?: X25519PrivateKey) {\n this._scheme = scheme;\n this._x25519PrivateKey = x25519PrivateKey;\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);\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 * 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 keypair.\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.\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 // 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 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 raw private key data.\n */\n data(): Uint8Array {\n switch (this._scheme) {\n case EncapsulationScheme.X25519: {\n const pk = this._x25519PrivateKey;\n if (pk === undefined) throw new Error(\"X25519 private key not set\");\n return pk.data();\n }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Get the public key corresponding to this private key.\n */\n publicKey(): EncapsulationPublicKey {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Compare with another EncapsulationPrivateKey.\n */\n equals(other: EncapsulationPrivateKey): boolean {\n if (this._scheme !== other._scheme) return false;\n switch (this._scheme) {\n case 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 }\n default:\n return false;\n }\n }\n\n /**\n * Get string representation.\n */\n toString(): string {\n switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return `EncapsulationPrivateKey(X25519, ${bytesToHex(this.data()).substring(0, 16)}...)`;\n default:\n return `EncapsulationPrivateKey(${String(this._scheme)})`;\n }\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 switch (this._scheme) {\n case EncapsulationScheme.X25519:\n return tagsForValues([TAG_X25519_PRIVATE_KEY.value]);\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\n }\n\n /**\n * Returns the untagged CBOR encoding.\n */\n untaggedCbor(): Cbor {\n switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\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 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 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 switch (this._scheme) {\n case 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 }\n default:\n throw new Error(`Unsupported scheme: ${String(this._scheme)}`);\n }\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 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 * 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 * Currently supported:\n * - X25519: Curve25519-based Diffie-Hellman key exchange (default)\n *\n * Future support (post-quantum):\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\";\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 // Future: ML-KEM post-quantum schemes\n // MLKEM512 = \"mlkem512\",\n // MLKEM768 = \"mlkem768\",\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 * 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 default:\n throw new Error(`Unsupported encapsulation scheme: ${String(scheme)}`);\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 *\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 */\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 default:\n throw new Error(\n `Deterministic keypair generation not supported for scheme: ${String(scheme)}`,\n );\n }\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 * 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 * 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\n * HKDF = 0\n * PBKDF2 = 1\n * Scrypt = 2\n * Argon2id = 3\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}\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 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 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 * 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, expectBytes } from \"@bcts/dcbor\";\nimport { hkdfHmacSha256, hkdfHmacSha512 } 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 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]\n */\n toCbor(): Cbor {\n return cbor([\n cbor(HKDFParams.INDEX),\n this._salt.untaggedCbor(),\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): 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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\n const hashType = hashTypeFromCbor(array[2]);\n\n return new HKDFParams(salt, hashType);\n }\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, expectBytes } from \"@bcts/dcbor\";\nimport { pbkdf2HmacSha256, pbkdf2HmacSha512 } 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 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]\n */\n toCbor(): Cbor {\n return cbor([\n cbor(PBKDF2Params.INDEX),\n this._salt.untaggedCbor(),\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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\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 * 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, expectBytes } 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/** 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]\n */\n toCbor(): Cbor {\n return cbor([\n cbor(ScryptParams.INDEX),\n this._salt.untaggedCbor(),\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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\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 * 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, expectBytes } from \"@bcts/dcbor\";\nimport { argon2idHash } 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 argon2idHash(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]\n */\n toCbor(): Cbor {\n return cbor([cbor(Argon2idParams.INDEX), this._salt.untaggedCbor()]);\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 saltData = expectBytes(array[1]);\n const salt = Salt.fromData(saltData);\n\n return new Argon2idParams(salt);\n }\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\";\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\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 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 }\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 * 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 }\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 }\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 }\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 }\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} 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 default:\n throw new Error(`Unknown key derivation method: ${String(method)}`);\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 * 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 }\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 * 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 { Signature } from \"./signing/signature.js\";\nimport type { Verifier } from \"./signing/signer.js\";\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 Verifier, CborTaggedEncodable, CborTaggedDecodable<PublicKeys>, 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 // 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 toString(): string {\n return `PublicKeys(${String(this._signingPublicKey)}, ${String(this._encapsulationPublicKey)})`;\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 * 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 { Signature } from \"./signing/signature.js\";\nimport type { Signer } from \"./signing/signer.js\";\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 Signer, CborTaggedEncodable, CborTaggedDecodable<PrivateKeys>, 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 // 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 using the signing private key.\n */\n sign(message: Uint8Array): Signature {\n return this._signingPrivateKey.sign(message);\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 * Get string representation.\n */\n toString(): string {\n return `PrivateKeys(${String(this._signingPrivateKey)}, ${String(this._encapsulationPrivateKey)})`;\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 * 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 { 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\";\n\n/** Size of PrivateKeyBase key material in bytes */\nconst PRIVATE_KEY_BASE_SIZE = 32;\n\n/** Key derivation info strings */\nconst INFO_SIGNING_ED25519 = \"signing-ed25519\";\nconst INFO_AGREEMENT_X25519 = \"agreement-x25519\";\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\n{\n private readonly _data: Uint8Array;\n\n private constructor(data: Uint8Array) {\n if (data.length !== PRIVATE_KEY_BASE_SIZE) {\n throw new Error(`PrivateKeyBase must be ${PRIVATE_KEY_BASE_SIZE} bytes, got ${data.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_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 info string \"signing-ed25519\".\n */\n ed25519SigningPrivateKey(): SigningPrivateKey {\n const derivedKey = this._deriveKey(INFO_SIGNING_ED25519);\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 info string \"agreement-x25519\".\n */\n x25519PrivateKey(): X25519PrivateKey {\n const derivedKey = this._deriveKey(INFO_AGREEMENT_X25519);\n return X25519PrivateKey.fromData(derivedKey);\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 * 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 * Internal key derivation using HKDF-SHA256.\n * Uses the info string as salt for domain separation.\n */\n private _deriveKey(info: string): Uint8Array {\n // Use info as salt for domain separation (crypto package's HKDF doesn't have info param)\n const salt = new TextEncoder().encode(info);\n return hkdfHmacSha256(this._data, 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_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_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_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 * SSKR Integration - CBOR/UR wrappers for SSKR shares\n *\n * This module provides CBOR and UR serialization for SSKR (Sharded Secret Key\n * Reconstruction) shares. It wraps the core SSKR functionality from\n * @bcts/sskr with CBOR tags and UR encoding.\n *\n * # CBOR Serialization\n *\n * SSKRShareCbor 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 * # UR Serialization\n *\n * UR type: `sskr`\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 { UR, type UREncodable } from \"@bcts/uniform-resources\";\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\";\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\n implements CborTaggedEncodable, CborTaggedDecodable<SSKRShareCbor>, UREncodable\n{\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 SSKRShareCbor.\n */\n cborTags(): Tag[] {\n return tagsForValues([TAG_SSKR_SHARE.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 // UR Serialization (UREncodable)\n // ============================================================================\n\n /**\n * Returns the UR representation.\n */\n ur(): UR {\n const name = TAG_SSKR_SHARE.name;\n if (name === undefined) {\n throw new Error(\"SSKR_SHARE 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 SSKRShareCbor from a UR.\n */\n static fromUR(ur: UR): SSKRShareCbor {\n // Accept both current and legacy UR types\n if (ur.urTypeStr() !== TAG_SSKR_SHARE.name && ur.urTypeStr() !== TAG_SSKR_SHARE_V1.name) {\n throw new Error(\n `Expected UR type ${TAG_SSKR_SHARE.name} or ${TAG_SSKR_SHARE_V1.name}, got ${ur.urTypeStr()}`,\n );\n }\n const dummy = new SSKRShareCbor(new Uint8Array(METADATA_SIZE_BYTES + 16));\n return dummy.fromUntaggedCbor(ur.cbor());\n }\n\n /**\n * Creates an SSKRShareCbor from a UR string.\n */\n static fromURString(urString: string): SSKRShareCbor {\n const ur = UR.fromURString(urString);\n return SSKRShareCbor.fromUR(ur);\n }\n}\n\n// ============================================================================\n// Helper Functions for generating/combining shares with CBOR wrappers\n// ============================================================================\n\n/**\n * Generate SSKR shares with CBOR wrappers.\n *\n * @param spec - The SSKR specification\n * @param secret - The secret to split\n * @returns Groups of SSKRShareCbor instances\n */\nexport function generateSSKRSharesCbor(spec: SSKRSpec, secret: SSKRSecret): SSKRShareCbor[][] {\n const rawGroups = sskrGenerate(spec, secret);\n return rawGroups.map((group) => group.map((shareData) => SSKRShareCbor.fromData(shareData)));\n}\n\n/**\n * Combine SSKR shares from CBOR wrappers.\n *\n * @param shares - The shares to combine\n * @returns The recovered secret\n */\nexport function combineSSKRSharesCbor(shares: SSKRShareCbor[]): SSKRSecret {\n const rawShares = shares.map((share) => share.data());\n return sskrCombine(rawShares);\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\nimport { ml_dsa44, ml_dsa65, ml_dsa87 } from \"@noble/post-quantum/ml-dsa\";\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(secretKey, message);\n case MLDSALevel.MLDSA65:\n return ml_dsa65.sign(secretKey, message);\n case MLDSALevel.MLDSA87:\n return ml_dsa87.sign(secretKey, message);\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(publicKey, message, signature);\n case MLDSALevel.MLDSA65:\n return ml_dsa65.verify(publicKey, message, signature);\n case MLDSALevel.MLDSA87:\n return ml_dsa87.verify(publicKey, message, signature);\n }\n } catch {\n return false;\n }\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 * 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 * 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 * 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\nimport { ml_kem512, ml_kem768, ml_kem1024 } from \"@noble/post-quantum/ml-kem\";\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 * 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 * 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 * 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} 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 // 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwDA,eAAsB,gBAAgB,MAAmC;CAEvE,MAAM,EAAE,qBAAW,MAAM,OAAO;AAChC,QAAOA,SAAO,UAAU,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACS/B,IAAa,QAAb,MAAa,MAA8E;CACzF,OAAgB,aAAa;CAE7B,AAAiB;CAEjB,AAAQ,YAAY,MAAkB;AACpC,MAAI,KAAK,WAAW,MAAM,WACxB,OAAM,YAAY,YAAY,MAAM,YAAY,KAAK,OAAO;AAE9D,OAAK,QAAQ,IAAI,WAAW,KAAK;;;;;CAUnC,OAAO,MAAa;AAElB,SAAO,IAAI,MADC,IAAI,6BAA6B,CACxB,WAAW,MAAM,WAAW,CAAC;;;;;CAMpD,OAAO,SAAgB;AACrB,SAAO,MAAM,KAAK;;;;;CAMpB,OAAO,SAAS,MAAyB;AACvC,SAAO,IAAI,MAAM,IAAI,WAAW,KAAK,CAAC;;;;;CAMxC,OA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