| 13 | } |
| 14 | |
| 15 | function subtleAlgorithm(alg: string, algorithm: KeyAlgorithm | EcKeyAlgorithm) { |
| 16 | const hash = `SHA-${alg.slice(-3)}` |
| 17 | switch (alg) { |
| 18 | case 'HS256': |
| 19 | case 'HS384': |
| 20 | case 'HS512': |
| 21 | return { hash, name: 'HMAC' } |
| 22 | case 'PS256': |
| 23 | case 'PS384': |
| 24 | case 'PS512': |
| 25 | return { hash, name: 'RSA-PSS', saltLength: parseInt(alg.slice(-3), 10) >> 3 } |
| 26 | case 'RS256': |
| 27 | case 'RS384': |
| 28 | case 'RS512': |
| 29 | return { hash, name: 'RSASSA-PKCS1-v1_5' } |
| 30 | case 'ES256': |
| 31 | case 'ES384': |
| 32 | case 'ES512': |
| 33 | return { hash, name: 'ECDSA', namedCurve: (algorithm as EcKeyAlgorithm).namedCurve } |
| 34 | case 'Ed25519': // Fall through |
| 35 | case 'EdDSA': |
| 36 | return { name: 'Ed25519' } |
| 37 | case 'ML-DSA-44': |
| 38 | case 'ML-DSA-65': |
| 39 | case 'ML-DSA-87': |
| 40 | return { name: alg } |
| 41 | default: |
| 42 | throw new JOSENotSupported( |
| 43 | `alg ${alg} is not supported either by JOSE or your javascript runtime`, |
| 44 | ) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | async function getSigKey(alg: string, key: types.CryptoKey | Uint8Array, usage: KeyUsage) { |
| 49 | if (key instanceof Uint8Array) { |