diff --git a/docs/README.md b/docs/README.md index 86c42b5dab..664dce5c1e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,6 +29,7 @@ I can continue maintaining it and adding new features carefree. You may also don - [key.alg](#keyalg) - [key.use](#keyuse) - [key.kid](#keykid) + - [key.thumbprint](#keythumbprint) - [key.type](#keytype) - [key.public](#keypublic) - [key.private](#keyprivate) @@ -112,6 +113,14 @@ defined in [RFC7638][spec-thumbprint]. --- +#### `key.thumbprint` + +Returns the key's JWK Key thumbprint calculated using the method defined in [RFC7638][spec-thumbprint]. + +- `` + +--- + #### `key.type` Returns the type of key. One of 'private', 'public' or 'secret' diff --git a/lib/index.d.ts b/lib/index.d.ts index 18f1dce782..5a7dc710b1 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -25,6 +25,7 @@ export namespace JWK { alg?: string use?: use kid: string + thumbprint: string algorithms(operation?: keyOperation): Set diff --git a/lib/jwk/key/base.js b/lib/jwk/key/base.js index 11e38b844f..0c470528b9 100644 --- a/lib/jwk/key/base.js +++ b/lib/jwk/key/base.js @@ -38,11 +38,18 @@ class Key { enumerable: true, ...(kid ? { value: kid } : { get () { - Object.defineProperty(this, 'kid', { value: thumbprint.kid(this[THUMBPRINT_MATERIAL]()), configurable: false }) + Object.defineProperty(this, 'kid', { value: this.thumbprint, configurable: false }) return this.kid }, configurable: true }) + }, + thumbprint: { + get () { + Object.defineProperty(this, 'thumbprint', { value: thumbprint.kid(this[THUMBPRINT_MATERIAL]()), configurable: false }) + return this.thumbprint + }, + configurable: true } }) }