Skip to content

Commit 15b41af

Browse files
authored
type: define IANA hash algorithm list once (#268)
Signed-off-by: Sami Rosendahl <sami.rosendahl@reaktor.com>
1 parent 06e3319 commit 15b41af

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

packages/core/src/index.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
type SDJWTConfig,
1818
type JwtPayload,
1919
type Signer,
20+
IANA_HASH_ALGORITHMS,
2021
type HashAlgorithm,
2122
} from '@sd-jwt/types';
2223
import { getSDAlgAndPayload } from '@sd-jwt/decode';
@@ -32,26 +33,6 @@ export * from './generalJSON';
3233

3334
export type SdJwtPayload = Record<string, unknown>;
3435

35-
const IANA_HASH_ALGORITHMS: HashAlgorithm[] = [
36-
'sha-256',
37-
'sha-256-128',
38-
'sha-256-120',
39-
'sha-256-96',
40-
'sha-256-64',
41-
'sha-256-32',
42-
'sha-384',
43-
'sha-512',
44-
'sha3-224',
45-
'sha3-256',
46-
'sha3-384',
47-
'sha3-512',
48-
'blake2s-256',
49-
'blake2b-256',
50-
'blake2b-512',
51-
'k12-256',
52-
'k12-512',
53-
];
54-
5536
export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
5637
//header type
5738
protected type?: string;

packages/types/src/type.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@ export type Base64urlString = string;
1010
export type DisclosureData<T> = [string, string, T] | [string, T];
1111

1212
// based on https://www.iana.org/assignments/named-information/named-information.xhtml
13-
export type HashAlgorithm =
14-
| 'sha-256'
15-
| 'sha-256-128'
16-
| 'sha-256-120'
17-
| 'sha-256-96'
18-
| 'sha-256-64'
19-
| 'sha-256-32'
20-
| 'sha-384'
21-
| 'sha-512'
22-
| 'sha3-224'
23-
| 'sha3-256'
24-
| 'sha3-384'
25-
| 'sha3-512'
26-
| 'blake2s-256'
27-
| 'blake2b-256'
28-
| 'blake2b-512'
29-
| 'k12-256'
30-
| 'k12-512';
13+
export const IANA_HASH_ALGORITHMS = [
14+
'sha-256',
15+
'sha-256-128',
16+
'sha-256-120',
17+
'sha-256-96',
18+
'sha-256-64',
19+
'sha-256-32',
20+
'sha-384',
21+
'sha-512',
22+
'sha3-224',
23+
'sha3-256',
24+
'sha3-384',
25+
'sha3-512',
26+
'blake2s-256',
27+
'blake2b-256',
28+
'blake2b-512',
29+
'k12-256',
30+
'k12-512',
31+
] as const;
32+
33+
export type HashAlgorithm = (typeof IANA_HASH_ALGORITHMS)[number];
34+
3135

3236
export type SDJWTConfig = {
3337
omitTyp?: boolean;

0 commit comments

Comments
 (0)