mirror of
https://github.com/danbulant/jose
synced 2026-05-19 04:18:52 +00:00
refactor: rename calculateThumprint to calculateJwkThumbprint
BREAKING CHANGE: The `jose/jwk/thumbprint` named export
is renamed to `calculateJwkThumbprint`, now
`import { calculateJwkThumbprint } from 'jose'`
This commit is contained in:
parent
8d3cc3bb46
commit
5afb713fbb
8 changed files with 24 additions and 24 deletions
|
|
@ -43,7 +43,7 @@ If you or your business use `jose`, please consider becoming a [sponsor][support
|
|||
- Signing - [Compact](docs/classes/jws_compact_sign.CompactSign.md#readme), [Flattened](docs/classes/jws_flattened_sign.FlattenedSign.md#readme), [General](docs/classes/jws_general_sign.GeneralSign.md#readme)
|
||||
- Verification - [Compact](docs/functions/jws_compact_verify.compactVerify.md#readme), [Flattened](docs/functions/jws_flattened_verify.flattenedVerify.md#readme), [General](docs/functions/jws_general_verify.generalVerify.md#readme)
|
||||
- JSON Web Key (JWK)
|
||||
- [Thumbprints](docs/functions/jwk_thumbprint.calculateThumbprint.md#readme)
|
||||
- [Thumbprints](docs/functions/jwk_thumbprint.calculateJwkThumbprint.md#readme)
|
||||
- [EmbeddedJWK](docs/functions/jwk_embedded.EmbeddedJWK.md#readme)
|
||||
- JSON Web Key Set (JWKS)
|
||||
- [Verify using a remote JWKSet](docs/functions/jwks_remote.createRemoteJWKSet.md#readme)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ If you or your business use `jose`, please consider becoming a [sponsor][support
|
|||
- Signing - [Compact](classes/jws_compact_sign.CompactSign.md#readme), [Flattened](classes/jws_flattened_sign.FlattenedSign.md#readme), [General](classes/jws_general_sign.GeneralSign.md#readme)
|
||||
- Verification - [Compact](functions/jws_compact_verify.compactVerify.md#readme), [Flattened](functions/jws_flattened_verify.flattenedVerify.md#readme), [General](functions/jws_general_verify.generalVerify.md#readme)
|
||||
- JSON Web Key (JWK)
|
||||
- [Thumbprints](functions/jwk_thumbprint.calculateThumbprint.md#readme)
|
||||
- [Thumbprints](functions/jwk_thumbprint.calculateJwkThumbprint.md#readme)
|
||||
- [EmbeddedJWK](functions/jwk_embedded.EmbeddedJWK.md#readme)
|
||||
- JSON Web Key Set (JWKS)
|
||||
- [Verify using a remote JWKSet](functions/jwks_remote.createRemoteJWKSet.md#readme)
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
# Function: calculateThumbprint
|
||||
# Function: calculateJwkThumbprint
|
||||
|
||||
▸ **calculateThumbprint**(`jwk`, `digestAlgorithm?`): `Promise`<`string`\>
|
||||
▸ **calculateJwkThumbprint**(`jwk`, `digestAlgorithm?`): `Promise`<`string`\>
|
||||
|
||||
Calculates a base64url-encoded JSON Web Key (JWK) Thumbprint as per
|
||||
[RFC7638](https://tools.ietf.org/html/rfc7638).
|
||||
|
||||
**`example`** ESM import
|
||||
```js
|
||||
import { calculateThumbprint } from 'jose/jwk/thumbprint'
|
||||
import { calculateJwkThumbprint } from 'jose/jwk/thumbprint'
|
||||
```
|
||||
|
||||
**`example`** CJS import
|
||||
```js
|
||||
const { calculateThumbprint } = require('jose/jwk/thumbprint')
|
||||
const { calculateJwkThumbprint } = require('jose/jwk/thumbprint')
|
||||
```
|
||||
|
||||
**`example`** Deno import
|
||||
```js
|
||||
import { calculateThumbprint } from 'https://deno.land/x/jose@v3.20.3/jwk/thumbprint.ts'
|
||||
import { calculateJwkThumbprint } from 'https://deno.land/x/jose@v3.20.2/jwk/thumbprint.ts'
|
||||
```
|
||||
|
||||
**`example`** Usage
|
||||
```js
|
||||
const thumbprint = await calculateThumbprint({
|
||||
const thumbprint = await calculateJwkThumbprint({
|
||||
kty: 'RSA',
|
||||
e: 'AQAB',
|
||||
n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ'
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
### Functions
|
||||
|
||||
- [calculateThumbprint](../functions/jwk_thumbprint.calculateThumbprint.md)
|
||||
- [calculateJwkThumbprint](../functions/jwk_thumbprint.calculateJwkThumbprint.md)
|
||||
|
||||
## References
|
||||
|
||||
|
|
@ -21,4 +21,4 @@ ___
|
|||
|
||||
### default
|
||||
|
||||
Renames and exports: [calculateThumbprint](../functions/jwk_thumbprint.calculateThumbprint.md)
|
||||
Renames and exports: [calculateJwkThumbprint](../functions/jwk_thumbprint.calculateJwkThumbprint.md)
|
||||
|
|
|
|||
|
|
@ -22,22 +22,22 @@ const check = (value: unknown, description: string) => {
|
|||
*
|
||||
* @example ESM import
|
||||
* ```js
|
||||
* import { calculateThumbprint } from 'jose/jwk/thumbprint'
|
||||
* import { calculateJwkThumbprint } from 'jose/jwk/thumbprint'
|
||||
* ```
|
||||
*
|
||||
* @example CJS import
|
||||
* ```js
|
||||
* const { calculateThumbprint } = require('jose/jwk/thumbprint')
|
||||
* const { calculateJwkThumbprint } = require('jose/jwk/thumbprint')
|
||||
* ```
|
||||
*
|
||||
* @example Deno import
|
||||
* ```js
|
||||
* import { calculateThumbprint } from 'https://deno.land/x/jose@VERSION/jwk/thumbprint.ts'
|
||||
* import { calculateJwkThumbprint } from 'https://deno.land/x/jose@VERSION/jwk/thumbprint.ts'
|
||||
* ```
|
||||
*
|
||||
* @example Usage
|
||||
* ```js
|
||||
* const thumbprint = await calculateThumbprint({
|
||||
* const thumbprint = await calculateJwkThumbprint({
|
||||
* kty: 'RSA',
|
||||
* e: 'AQAB',
|
||||
* n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ'
|
||||
|
|
@ -46,7 +46,7 @@ const check = (value: unknown, description: string) => {
|
|||
* console.log(thumbprint)
|
||||
* ```
|
||||
*/
|
||||
async function calculateThumbprint(
|
||||
async function calculateJwkThumbprint(
|
||||
jwk: JWK,
|
||||
digestAlgorithm: 'sha256' | 'sha384' | 'sha512' = 'sha256',
|
||||
): Promise<string> {
|
||||
|
|
@ -84,6 +84,6 @@ async function calculateThumbprint(
|
|||
return base64url(await digest(digestAlgorithm, data))
|
||||
}
|
||||
|
||||
export { calculateThumbprint }
|
||||
export default calculateThumbprint
|
||||
export { calculateJwkThumbprint }
|
||||
export default calculateJwkThumbprint
|
||||
export type { JWK }
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@ import * as Bowser from 'bowser';
|
|||
|
||||
import { importJWK } from '../dist/browser/key/import.js';
|
||||
import { exportJWK } from '../dist/browser/key/export.js';
|
||||
import calculateThumbprint from '../dist/browser/jwk/thumbprint.js';
|
||||
import calculateJwkThumbprint from '../dist/browser/jwk/thumbprint.js';
|
||||
|
||||
const browser = Bowser.parse(window.navigator.userAgent);
|
||||
|
||||
const p521 = browser.engine.name !== 'WebKit';
|
||||
|
||||
async function test(jwk, alg, assert) {
|
||||
await calculateThumbprint(jwk);
|
||||
await calculateJwkThumbprint(jwk);
|
||||
const keyLike = await importJWK({ ...jwk, ext: true }, alg);
|
||||
assert.deepEqual(await exportJWK(keyLike), jwk);
|
||||
}
|
||||
|
||||
async function failing(jwk, alg, assert) {
|
||||
await calculateThumbprint(jwk);
|
||||
await calculateJwkThumbprint(jwk);
|
||||
await assert.rejects(test.bind(undefined, jwk, alg)(assert));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ Deno.test('imports EmbeddedJWK', async () => {
|
|||
await import('../dist/deno/jwk/embedded.ts');
|
||||
});
|
||||
|
||||
Deno.test('imports calculateThumbprint', async () => {
|
||||
Deno.test('imports calculateJwkThumbprint', async () => {
|
||||
await import('../dist/deno/jwk/thumbprint.ts');
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@ import { assertEquals, assertThrowsAsync } from 'https://deno.land/std@0.109.0/t
|
|||
|
||||
import { importJWK } from '../dist/deno/key/import.ts';
|
||||
import { exportJWK } from '../dist/deno/key/export.ts';
|
||||
import calculateThumbprint from '../dist/deno/jwk/thumbprint.ts';
|
||||
import calculateJwkThumbprint from '../dist/deno/jwk/thumbprint.ts';
|
||||
|
||||
async function test(jwk: { [key: string]: unknown }, alg: string) {
|
||||
await calculateThumbprint(jwk);
|
||||
await calculateJwkThumbprint(jwk);
|
||||
const keyLike = await importJWK({ ...jwk, ext: true }, alg);
|
||||
assertEquals(await exportJWK(keyLike), jwk);
|
||||
}
|
||||
|
||||
async function failing(jwk: { [key: string]: unknown }, alg: string) {
|
||||
await calculateThumbprint(jwk);
|
||||
await calculateJwkThumbprint(jwk);
|
||||
return assertThrowsAsync(() => test(jwk, alg));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue