jsonwebkey-thumbprint
Version:
JWK Thumbprint defined by RFC 7638
62 lines (40 loc) • 1.8 kB
Markdown

[][npm]
[]: https://www.npmjs.com/package/jsonwebkey-thumbprint
Variable-Length Integer Encoding defined by [RFC 7638](https://www.rfc-editor.org/rfc/rfc7638.html).
- [Features](
- [Usage](
- [Security Considerations](
- [License](
- JWK Thumbprint pre-compute
- JWK Thumbprint when passing a hash and encoding function
- TypeScript types
```typescript
import { jwkThumbprint } from "jsonwebkey-thumbprint";
// A public key exported as a JWK
const keypair = await crypto.subtle.generateKey("Ed25519", true, [
"sign",
"verify",
]);
const jwk = await crypto.subtle.exportKey("jwk", keypair.publicKey);
// Using sha-256 as a hash function and base64url as encoding
const hash = (b: BufferSource) => crypto.subtle.digest("SHA-256", b);
const decode = (u: ArrayBuffer) =>
b64ToB64URL(b64ToB64NoPadding(u8ToB64(new Uint8Array(u))));
// Compute the JWK Thumbprint for the public key
console.log(await jwkThumbprint(jwk));
// Helper functions
const u8ToB64 = (u: Uint8Array) => btoa(String.fromCharCode(...u));
const b64ToB64URL = (s: string) => s.replace(/\+/g, "-").replace(/\//g, "_");
const b64ToB64NoPadding = (s: string) => s.replace(/=/g, "");
```
This software has not been audited. Please use at your sole discretion.
This project is under the Apache-2.0 license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be Apache-2.0 licensed as above, without any additional terms or conditions.