Skip to content

Commit

Permalink
feat: add key.thumbprint always returning the JWK Thumbprint (RFC7638)
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 4, 2019
1 parent 2dd7053 commit 65db7e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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].

- `<string>`

---

#### `key.type`

Returns the type of key. One of 'private', 'public' or 'secret'
Expand Down
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export namespace JWK {
alg?: string
use?: use
kid: string
thumbprint: string


algorithms(operation?: keyOperation): Set<string>
Expand Down
9 changes: 8 additions & 1 deletion lib/jwk/key/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
Expand Down

0 comments on commit 65db7e0

Please sign in to comment.