mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
refactor: move kid material to the key level
This commit is contained in:
parent
f901300b4c
commit
39a98e70ad
5 changed files with 18 additions and 18 deletions
|
|
@ -74,7 +74,7 @@ class Key {
|
|||
enumerable: true,
|
||||
...(kid ? { value: kid } : {
|
||||
get () {
|
||||
Object.defineProperty(this, 'kid', { value: thumbprint.kid(this), configurable: false })
|
||||
Object.defineProperty(this, 'kid', { value: thumbprint.kid(this.thumbprintMaterial()), configurable: false })
|
||||
return this.kid
|
||||
},
|
||||
configurable: true
|
||||
|
|
@ -86,6 +86,10 @@ class Key {
|
|||
defineLazyComponents(this)
|
||||
}
|
||||
}
|
||||
|
||||
thumbprintMaterial () {
|
||||
throw new Error('not implemented')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Key
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class ECKey extends Key {
|
|||
})
|
||||
}
|
||||
|
||||
thumbprintMaterial () {
|
||||
return { crv: this.crv, kty: 'EC', x: this.x, y: this.y }
|
||||
}
|
||||
|
||||
algorithms (operation) {
|
||||
// TODO: operation empty, return all supported or throw
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ class OctKey extends Key {
|
|||
})
|
||||
}
|
||||
|
||||
thumbprintMaterial () {
|
||||
return { k: this.k, kty: 'oct' }
|
||||
}
|
||||
|
||||
algorithms (operation) {
|
||||
// TODO: operation empty, return all supported or throw
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class RSAKey extends Key {
|
|||
})
|
||||
}
|
||||
|
||||
thumbprintMaterial () {
|
||||
return { e: this.e, kty: 'RSA', n: this.n }
|
||||
}
|
||||
|
||||
algorithms (operation) {
|
||||
// TODO: operation empty, return all supported or throw
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,4 @@ const { createHash } = require('crypto')
|
|||
|
||||
const base64url = require('../help/base64url')
|
||||
|
||||
module.exports.kid = (key) => {
|
||||
let json
|
||||
|
||||
switch (key.kty) {
|
||||
case 'RSA':
|
||||
json = JSON.stringify({ e: key.e, kty: 'RSA', n: key.n })
|
||||
break
|
||||
case 'EC':
|
||||
json = JSON.stringify({ crv: key.crv, kty: 'EC', x: key.x, y: key.y })
|
||||
break
|
||||
case 'oct':
|
||||
json = JSON.stringify({ k: key.k, kty: 'oct' })
|
||||
break
|
||||
}
|
||||
|
||||
return base64url.encode(createHash('sha256').update(json).digest())
|
||||
}
|
||||
module.exports.kid = components => base64url.encode(createHash('sha256').update(JSON.stringify(components)).digest())
|
||||
|
|
|
|||
Loading…
Reference in a new issue