algorithm-details.ts88 lines · main
| 1 | export interface AlgorithmDetail { |
| 2 | name: string |
| 3 | description: string |
| 4 | pros: string[] |
| 5 | cons: string[] |
| 6 | label: string |
| 7 | shortDescription: string |
| 8 | links: { url: string; label: string }[] |
| 9 | } |
| 10 | |
| 11 | export const algorithmDetails: Record<string, AlgorithmDetail> = { |
| 12 | HS256: { |
| 13 | label: 'HS256 (Shared Secret)', |
| 14 | name: 'HMAC with SHA-256', |
| 15 | description: 'JWT signatures are produced by a shared secret.', |
| 16 | pros: ['Simple to use', 'Verifying and creating JWTs is very fast and not resource intensive'], |
| 17 | cons: [ |
| 18 | 'Usually not compatible with SOC2 and other security compliance frameworks', |
| 19 | 'Requires secure key exchange', |
| 20 | "Not suitable when the verifier shouldn't be able to sign tokens", |
| 21 | 'Key needs to be kept secret on both sides', |
| 22 | ], |
| 23 | shortDescription: 'HMAC with SHA-256: Fast, simple, requires secure key exchange', |
| 24 | links: [ |
| 25 | { |
| 26 | url: 'https://datatracker.ietf.org/doc/html/rfc7518#section-3.2', |
| 27 | label: 'RFC 7518 Specification Section 3.2', |
| 28 | }, |
| 29 | ], |
| 30 | }, |
| 31 | RS256: { |
| 32 | label: 'RSA 2048', |
| 33 | name: 'RSA with SHA-256', |
| 34 | description: 'JWT is signed with a private and verified with a public RSA key.', |
| 35 | pros: [ |
| 36 | 'Compatible with SOC2 and other security compliance frameworks', |
| 37 | 'RSA is widely adopted and easier to work with', |
| 38 | 'Public key does not need to be kept secret', |
| 39 | ], |
| 40 | cons: [ |
| 41 | 'Larger JWT sizes than other choices', |
| 42 | 'Slower to create and verify JWT than other choices', |
| 43 | ], |
| 44 | shortDescription: 'RSA with SHA-256: Widely adopted, has public key, slower', |
| 45 | links: [ |
| 46 | { |
| 47 | url: 'https://datatracker.ietf.org/doc/html/rfc7518#section-3.3', |
| 48 | label: 'RFC 7518 Specification Section 3.3', |
| 49 | }, |
| 50 | ], |
| 51 | }, |
| 52 | ES256: { |
| 53 | label: 'ECC (P-256)', |
| 54 | name: 'ECDSA with SHA-256', |
| 55 | description: |
| 56 | 'JWT is signed with a private and verified with a public ECC key using the NIST P-256 curve.', |
| 57 | pros: [ |
| 58 | 'Compatible with SOC2 and other security compliance frameworks', |
| 59 | 'Faster to create and verify signatures than RSA', |
| 60 | 'Ideal tradeoff between JWT size and efficiency', |
| 61 | 'Public key does not need to be kept secret', |
| 62 | ], |
| 63 | cons: ['Wide support but some libraries might make it harder to work with than RSA'], |
| 64 | shortDescription: 'ECDSA with SHA-256: Faster, more efficient alternative to RSA', |
| 65 | links: [ |
| 66 | { |
| 67 | url: 'https://datatracker.ietf.org/doc/html/rfc7518#section-3.4', |
| 68 | label: 'RFC 7518 Specification Section 3.4', |
| 69 | }, |
| 70 | ], |
| 71 | }, |
| 72 | } |
| 73 | |
| 74 | export const algorithmLabels = Object.keys(algorithmDetails).reduce( |
| 75 | (a, i) => { |
| 76 | a[i] = algorithmDetails[i].label |
| 77 | return a |
| 78 | }, |
| 79 | {} as { [name: keyof typeof algorithmDetails]: string } |
| 80 | ) |
| 81 | |
| 82 | export const algorithmDescriptions = Object.keys(algorithmDetails).reduce( |
| 83 | (a, i) => { |
| 84 | a[i] = algorithmDetails[i].shortDescription |
| 85 | return a |
| 86 | }, |
| 87 | {} as { [name: keyof typeof algorithmDetails]: string } |
| 88 | ) |