Back to Jose

Class: CompactSign

docs/jws/compact/sign/classes/CompactSign.md

6.2.122.1 KB
Original Source

Class: CompactSign

πŸ’— Help the project

Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.

Builds and signs Compact JWS strings.

This class is exported (as a named export) from the main 'jose' module entry point as well as from its subpath export 'jose/jws/compact/sign'.

Example

js
const jws = await new jose.CompactSign(
  new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
)
  .setProtectedHeader({ alg: 'ES256' })
  .sign(privateKey)

console.log(jws)

Constructors

Constructor

β–Έ new CompactSign(payload): CompactSign

Creates a Compact JWS signer.

Parameters

ParameterTypeDescription
payloadUint8ArrayBinary representation of the payload to sign.

Returns

CompactSign

Methods

setProtectedHeader()

β–Έ setProtectedHeader(protectedHeader): this

Sets the JWS Protected Header. May only be called once.

Parameters

ParameterTypeDescription
protectedHeaderCompactJWSHeaderParametersJWS Protected Header.

Returns

this


sign()

β–Έ sign(key, options?): Promise<string>

Signs the payload as a Compact JWS.

Parameters

ParameterTypeDescription
keyKeyInputPrivate key or shared secret. See Algorithm Key Requirements.
options?SignOptionsJWS Sign options.

Returns

Promise<string>