JWSHeader class

The JWSHeader class is used to create a single JWS Signature. This class provides the APIs to set protected headers, unprotected headers, headers parameters, algorithm, and key.

JWSHeader.get()

Returns the shared JOSE Header or the value that is assigned to the named Header Parameter in the shared JOSE Header.

Syntax
JWSHeader.get([name])
Guidelines
If name is specified, the value of the name in the JOSE Header is returned. This JOSE Header object represents only shared parameters, which is a union of the shared Protected Header and shared Unprotected Header parameters.

JWSHeader.getJOSEHeader()

Returns the JOSE Header.

Syntax
JWSHeader.get()

JWSHeader.getKey()

Returns the value for a Key.

Syntax
JWSHeader.getKey()

JWSHeader.getProtected()

Returns the protected header as a JSON object.

Syntax
JWSHeader.getProtected([name])
Guidelines
If name is specified, the value of the named Header Parameter in the Protected Header is returned or 'undefined'. Otherwise, a JSON object that contains all the Header Parameter in the Protected Header is returned.

JWSHeader.getUnprotected()

Returns the shared unprotected header as a JSON object.

Syntax
JWSHeader.getUnprotected([name])
Guidelines
If name is specified, the value of the named Header Parameter in the Unprotected Header is returned or 'undefined'. Otherwise, a JSON object that contains all the Header Parameter in the Unprotected Header is returned.

JWSHeader.setKey()

Sets the value for a Key.

Syntax
JWSHeader.setKey([key])
Parameters
key
The shared secret key that is used by the algorithm to encrypt text. This parameter is mandatory.
The key must be.
  • A String object that refers to a configured object that also supports prefix usage in XSLT.
  • A Buffer or Buffers object that contains the base64 encoded data of the key.
  • An Object.
  • An RSA private key in JWK form or symmetric key in JWK form. For JWK requirements or limitations, see jwk.isJWK().
  • A JWK set. The 'kid' and 'alg' JOSE headers are used to find a proper JWK inside the JWK set. The 'kid' header is a string that the verifier can use to find the correct key to verify the signature.
For more information, see Key object usage.

JWSHeader.setProtected()

Sets the header parameters of the Protected Header object.

Syntax

JWSHeader.setProtected(name,value)

JWSHeader.setProtected(object)

Parameters
name
The name of the header parameter. This parameter is mandatory.
value
The value of the header parameter. This parameter is mandatory.
object
The object that contains the set of header parameters where each parameter is defined by its name and value. This parameter is mandatory.
Guidelines
The value is generally a string except for the following registered headers. Validation is done for specific headers.
  • b64 that is a Boolean.
  • exp that is a number.
  • http://openbanking.org.uk/iat that is a number.
  • iat that is a number.
  • nbf that is a number.
  • x5c that is an array.

The call fails if the name parameter is already set by the JWSHeader.setUnprotected() API.

JWSHeader.setUnprotected()

Sets the header parameters of the Unprotected Header object.

Syntax

JWSHeader.setUnprotected(name,value)

JWSHeader.setUnprotected(object)

Parameters
name
The name of the header parameter. This parameter is mandatory.
value
The value of the header parameter. This parameter is mandatory.
object
The object that contains the set of header parameters where each parameter is defined by its name and value. This parameter is mandatory.
Guidelines
The name can be a registered header parameter name, a public header parameter name, or a private header parameter name.

The call fails if the name parameter is already set by the JWSHeader.setProtected() API.