Skip to content

Commit cf2092a

Browse files
committed
feat: support AKP JWKs in calculateJwkThumbprint and calculateJwkThumbprintUri
1 parent 2c519cc commit cf2092a

File tree

7 files changed

+270
-7
lines changed

7 files changed

+270
-7
lines changed

docs/types/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
- [JWEHeaderParameters](interfaces/JWEHeaderParameters.md)
2828
- [JWEKeyManagementHeaderParameters](interfaces/JWEKeyManagementHeaderParameters.md)
2929
- [JWK](interfaces/JWK.md)
30+
- [JWK\_AKP\_Private](interfaces/JWK_AKP_Private.md)
31+
- [JWK\_AKP\_Public](interfaces/JWK_AKP_Public.md)
3032
- [JWK\_EC\_Private](interfaces/JWK_EC_Private.md)
3133
- [JWK\_EC\_Public](interfaces/JWK_EC_Public.md)
3234
- [JWK\_oct](interfaces/JWK_oct.md)

docs/types/interfaces/JWK.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva).
66

7-
JSON Web Key ([JWK](https://www.rfc-editor.org/rfc/rfc7517)). "RSA", "EC", "OKP", and "oct"
8-
key types are supported.
7+
JSON Web Key ([JWK](https://www.rfc-editor.org/rfc/rfc7517)). "RSA", "EC", "OKP", "AKP", and
8+
"oct" key types are supported.
99

1010
## See
1111

12+
- [JWK_AKP_Public](JWK_AKP_Public.md)
13+
- [JWK_AKP_Private](JWK_AKP_Private.md)
1214
- [JWK_OKP_Public](JWK_OKP_Public.md)
1315
- [JWK_OKP_Private](JWK_OKP_Private.md)
1416
- [JWK_EC_Public](JWK_EC_Public.md)
@@ -130,6 +132,22 @@ Private RSA JWK "p" (First Prime Factor) Parameter
130132

131133
***
132134

135+
### priv?
136+
137+
`optional` **priv**: `string`
138+
139+
AKP JWK "priv" (Private key) Parameter
140+
141+
***
142+
143+
### pub?
144+
145+
`optional` **pub**: `string`
146+
147+
AKP JWK "pub" (Public Key) Parameter
148+
149+
***
150+
133151
### q?
134152

135153
`optional` **q**: `string`
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Interface: JWK\_AKP\_Private
2+
3+
## [💗 Help the project](https://github.com/sponsors/panva)
4+
5+
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva).
6+
7+
Convenience interface for Private AKP JSON Web Keys
8+
9+
## Properties
10+
11+
### alg
12+
13+
**alg**: `string`
14+
15+
JWK "alg" (Algorithm) Parameter
16+
17+
***
18+
19+
### priv
20+
21+
**priv**: `string`
22+
23+
AKP JWK "priv" (The Private Key) Parameter
24+
25+
***
26+
27+
### pub
28+
29+
**pub**: `string`
30+
31+
AKP JWK "pub" (The Public key) Parameter
32+
33+
***
34+
35+
### ext?
36+
37+
`optional` **ext**: `boolean`
38+
39+
JWK "ext" (Extractable) Parameter
40+
41+
***
42+
43+
### key\_ops?
44+
45+
`optional` **key\_ops**: `string`[]
46+
47+
JWK "key_ops" (Key Operations) Parameter
48+
49+
***
50+
51+
### kid?
52+
53+
`optional` **kid**: `string`
54+
55+
JWK "kid" (Key ID) Parameter
56+
57+
***
58+
59+
### kty?
60+
61+
`optional` **kty**: `string`
62+
63+
JWK "kty" (Key Type) Parameter
64+
65+
***
66+
67+
### use?
68+
69+
`optional` **use**: `string`
70+
71+
JWK "use" (Public Key Use) Parameter
72+
73+
***
74+
75+
### x5c?
76+
77+
`optional` **x5c**: `string`[]
78+
79+
JWK "x5c" (X.509 Certificate Chain) Parameter
80+
81+
***
82+
83+
### x5t?
84+
85+
`optional` **x5t**: `string`
86+
87+
JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter
88+
89+
***
90+
91+
### x5t#S256?
92+
93+
`optional` **x5t#S256**: `string`
94+
95+
JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter
96+
97+
***
98+
99+
### x5u?
100+
101+
`optional` **x5u**: `string`
102+
103+
JWK "x5u" (X.509 URL) Parameter
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Interface: JWK\_AKP\_Public
2+
3+
## [💗 Help the project](https://github.com/sponsors/panva)
4+
5+
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva).
6+
7+
Convenience interface for Public AKP JSON Web Keys
8+
9+
## Properties
10+
11+
### alg
12+
13+
**alg**: `string`
14+
15+
JWK "alg" (Algorithm) Parameter
16+
17+
***
18+
19+
### pub
20+
21+
**pub**: `string`
22+
23+
AKP JWK "pub" (The Public key) Parameter
24+
25+
***
26+
27+
### ext?
28+
29+
`optional` **ext**: `boolean`
30+
31+
JWK "ext" (Extractable) Parameter
32+
33+
***
34+
35+
### key\_ops?
36+
37+
`optional` **key\_ops**: `string`[]
38+
39+
JWK "key_ops" (Key Operations) Parameter
40+
41+
***
42+
43+
### kid?
44+
45+
`optional` **kid**: `string`
46+
47+
JWK "kid" (Key ID) Parameter
48+
49+
***
50+
51+
### kty?
52+
53+
`optional` **kty**: `string`
54+
55+
JWK "kty" (Key Type) Parameter
56+
57+
***
58+
59+
### use?
60+
61+
`optional` **use**: `string`
62+
63+
JWK "use" (Public Key Use) Parameter
64+
65+
***
66+
67+
### x5c?
68+
69+
`optional` **x5c**: `string`[]
70+
71+
JWK "x5c" (X.509 Certificate Chain) Parameter
72+
73+
***
74+
75+
### x5t?
76+
77+
`optional` **x5t**: `string`
78+
79+
JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter
80+
81+
***
82+
83+
### x5t#S256?
84+
85+
`optional` **x5t#S256**: `string`
86+
87+
JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter
88+
89+
***
90+
91+
### x5u?
92+
93+
`optional` **x5u**: `string`
94+
95+
JWK "x5u" (X.509 URL) Parameter

src/jwk/thumbprint.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export async function calculateJwkThumbprint(
7272

7373
let components: types.JWK
7474
switch (jwk.kty) {
75+
case 'AKP':
76+
check(jwk.alg, '"alg" (Algorithm) Parameter')
77+
check(jwk.pub, '"pub" (Public key) Parameter')
78+
components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub }
79+
break
7580
case 'EC':
7681
check(jwk.crv, '"crv" (Curve) Parameter')
7782
check(jwk.x, '"x" (X Coordinate) Parameter')

src/types.d.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,25 @@ export interface JWK_OKP_Public extends JWKParameters {
3535
}
3636

3737
/** Convenience interface for Private OKP JSON Web Keys */
38-
export interface JWK_OKP_Private extends JWK_OKP_Public, JWKParameters {
38+
export interface JWK_OKP_Private extends JWK_OKP_Public {
3939
/** OKP JWK "d" (The Private Key) Parameter */
4040
d: string
4141
}
4242

43+
/** Convenience interface for Public AKP JSON Web Keys */
44+
export interface JWK_AKP_Public extends JWKParameters {
45+
/** JWK "alg" (Algorithm) Parameter */
46+
alg: string
47+
/** AKP JWK "pub" (The Public key) Parameter */
48+
pub: string
49+
}
50+
51+
/** Convenience interface for Private AKP JSON Web Keys */
52+
export interface JWK_AKP_Private extends JWK_AKP_Public {
53+
/** AKP JWK "priv" (The Private Key) Parameter */
54+
priv: string
55+
}
56+
4357
/** Convenience interface for Public EC JSON Web Keys */
4458
export interface JWK_EC_Public extends JWKParameters {
4559
/** EC JWK "crv" (Curve) Parameter */
@@ -51,7 +65,7 @@ export interface JWK_EC_Public extends JWKParameters {
5165
}
5266

5367
/** Convenience interface for Private EC JSON Web Keys */
54-
export interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
68+
export interface JWK_EC_Private extends JWK_EC_Public {
5569
/** EC JWK "d" (ECC Private Key) Parameter */
5670
d: string
5771
}
@@ -65,7 +79,7 @@ export interface JWK_RSA_Public extends JWKParameters {
6579
}
6680

6781
/** Convenience interface for Private RSA JSON Web Keys */
68-
export interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
82+
export interface JWK_RSA_Private extends JWK_RSA_Public {
6983
/** RSA JWK "d" (Private Exponent) Parameter */
7084
d: string
7185
/** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
@@ -87,9 +101,11 @@ export interface JWK_oct extends JWKParameters {
87101
}
88102

89103
/**
90-
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", and "oct"
91-
* key types are supported.
104+
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", "AKP", and
105+
* "oct" key types are supported.
92106
*
107+
* @see {@link JWK_AKP_Public}
108+
* @see {@link JWK_AKP_Private}
93109
* @see {@link JWK_OKP_Public}
94110
* @see {@link JWK_OKP_Private}
95111
* @see {@link JWK_EC_Public}
@@ -133,6 +149,10 @@ export interface JWK extends JWKParameters {
133149
x?: string
134150
/** EC JWK "y" (Y Coordinate) Parameter */
135151
y?: string
152+
/** AKP JWK "pub" (Public Key) Parameter */
153+
pub?: string
154+
/** AKP JWK "priv" (Private key) Parameter */
155+
priv?: string
136156
}
137157

138158
/**

test/jwk/thumbprint.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,23 @@ test('oct JWK', async (t) => {
148148
})
149149
t.is(await calculateJwkThumbprint(oct), 'prDKy90VJzrDTpm8-W2Q_pv_kzrX_zyZ7ANjRAasDxc')
150150
})
151+
152+
test('AKP JWK', async (t) => {
153+
const akp = {
154+
kty: 'AKP',
155+
alg: 'ML-DSA-44',
156+
pub: 'unH59k4RuutY-pxvu24U5h8YZD2rSVtHU5qRZsoBmBMcRPgmu9VuNOVdteXi1zNIXjnqJg_GAAxepLqA00Vc3lO0bzRIKu39VFD8Lhuk8l0V-cFEJC-zm7UihxiQMMUEmOF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X8ZoToxFSpLBDbtdWcenxj-zBf6IGWfZnmaetjKEBYJWC7QDQx1A91pJVJCEgieCkoIfTqkeQuePpIyu48g2FG3P1zjRF-kumhUTfSjo5qS0YiZQy0E1BMs6M11EvuxXRsHClLHoy5nLYI2Sj4zjVjYyxSHyPRPGGo9hwB34yWxzYNtPPGiqXS_dNCpi_zRZwRY4lCGrQ-hYTEWIK1Dm5OlttvC4_eiQ1dv63NiGkLRJ5kJA3bICN0fzCDY-MBqnd1cWn8YVBijVkgtaoascjL9EywDgJdeHnXK0eeOvUxHHhXJVkNqcibn8O4RQdpVU60TSA-uiu675ytIjcBHC6kTv8A8pmkj_4oypPd-F92YIJC741swkYQoeIHj8rE-ThcMUkF7KqC5VORbZTRp8HsZSqgiJcIPaouuxd1-8Rxrid3fXkE6p8bkrysPYoxWEJgh7ZFsRCPDWX-yTeJwFN0PKFP1j0F6YtlLfK5wv-c4F8ZQHA_-yc_gODicy7KmWDZgbTP07e7gEWzw4MFRrndjbDQ',
157+
}
158+
159+
await t.throwsAsync(calculateJwkThumbprint({ ...akp, alg: undefined }), {
160+
code: 'ERR_JWK_INVALID',
161+
message: '"alg" (Algorithm) Parameter missing or invalid',
162+
})
163+
164+
await t.throwsAsync(calculateJwkThumbprint({ ...akp, pub: undefined }), {
165+
code: 'ERR_JWK_INVALID',
166+
message: '"pub" (Public key) Parameter missing or invalid',
167+
})
168+
169+
t.is(await calculateJwkThumbprint(akp), 'T4xl70S7MT6Zeq6r9V9fPJGVn76wfnXJ21-gyo0Gu6o')
170+
})

0 commit comments

Comments
 (0)