(key: CryptoKey)
| 307 | } |
| 308 | |
| 309 | function inferAlgorithm(key: CryptoKey): SignatureAlgorithm { |
| 310 | const alg = key.algorithm; |
| 311 | const name = alg.name; |
| 312 | if (name === "Ed25519") return "ed25519"; |
| 313 | if (name === "HMAC") { |
| 314 | const hash = (alg as HmacKeyAlgorithm).hash.name; |
| 315 | if (hash === "SHA-256") return "hmac-sha256"; |
| 316 | throw new TypeError(`Unsupported HMAC hash: "${hash}"`); |
| 317 | } |
| 318 | if (name === "RSA-PSS") { |
| 319 | const hash = (alg as RsaHashedKeyAlgorithm).hash.name; |
| 320 | if (hash === "SHA-512") return "rsa-pss-sha512"; |
| 321 | throw new TypeError(`Unsupported RSA-PSS hash: "${hash}"`); |
| 322 | } |
| 323 | if (name === "RSASSA-PKCS1-v1_5") { |
| 324 | const hash = (alg as RsaHashedKeyAlgorithm).hash.name; |
| 325 | if (hash === "SHA-256") return "rsa-v1_5-sha256"; |
| 326 | throw new TypeError(`Unsupported RSASSA-PKCS1-v1_5 hash: "${hash}"`); |
| 327 | } |
| 328 | if (name === "ECDSA") { |
| 329 | const curve = (alg as EcKeyAlgorithm).namedCurve; |
| 330 | if (curve === "P-256") return "ecdsa-p256-sha256"; |
| 331 | if (curve === "P-384") return "ecdsa-p384-sha384"; |
| 332 | throw new TypeError(`Unsupported ECDSA curve: "${curve}"`); |
| 333 | } |
| 334 | throw new TypeError(`Cannot infer signature algorithm from key: "${name}"`); |
| 335 | } |
| 336 | |
| 337 | // ============================================================================= |
| 338 | // Component Value Resolution |
no outgoing calls
no test coverage detected