New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

jsonwebkey-thumbprint

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonwebkey-thumbprint

JWK Thumbprint defined by RFC 7638

Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
206K
-22.24%
Maintainers
1
Weekly downloads
 
Created
Source

jsonwebkey-thumbprint

License crates.io

Variable-Length Integer Encoding defined by RFC 7638.

Tables of Content

Features

  • JWK Thumbprint pre-compute
  • JWK Thumbprint when passing a hash and encoding function
  • TypeScript types

Usage

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, '')

Security Considerations

This software has not been audited. Please use at your sole discretion.

License

This project is under the Apache-2.0 license.

Contribution

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.

Keywords

jsonwebkey-thumbprint

FAQs

Package last updated on 14 Apr 2025

Related posts